commit 5efc5fb8dba9be0ec63437a20e2f6a082c08430c Author: Ryota Ozaki Date: Thu Nov 9 10:39:28 2017 +0900 Unify IFEF_*_MPSAFE into IFEF_MPSAFE There are already two flags for if_output and if_start, however, it seems such MPSAFE flags are eventually needed for all if_XXX operations. Having discrete flags for each operation is wasteful of if_extflags bits. So let's unify the flags into one: IFEF_MPSAFE. Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so we can change them without breaking backward compatibility of the releases (though the kernel version of -current should be bumped). Note that if an interface have both MP-safe and non-MP-safe operations at a time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe opeartions take the kernel lock. diff --git a/sys/arch/arm/sunxi/sunxi_emac.c b/sys/arch/arm/sunxi/sunxi_emac.c index 8f5a63af768..b076e62b559 100644 --- a/sys/arch/arm/sunxi/sunxi_emac.c +++ b/sys/arch/arm/sunxi/sunxi_emac.c @@ -1381,7 +1381,7 @@ sunxi_emac_attach(device_t parent, device_t self, void *aux) snprintf(ifp->if_xname, IFNAMSIZ, EMAC_IFNAME, device_unit(self)); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; #ifdef EMAC_MPSAFE - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; #endif ifp->if_start = sunxi_emac_start; ifp->if_ioctl = sunxi_emac_ioctl; diff --git a/sys/dev/ic/dwc_gmac.c b/sys/dev/ic/dwc_gmac.c index 285b97c2f25..4d7836b1276 100644 --- a/sys/dev/ic/dwc_gmac.c +++ b/sys/dev/ic/dwc_gmac.c @@ -223,7 +223,7 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, uint32_t mii_clk) ifp->if_softc = sc; strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; ifp->if_ioctl = dwc_gmac_ioctl; ifp->if_start = dwc_gmac_start; ifp->if_init = dwc_gmac_init; @@ -836,7 +836,7 @@ static void dwc_gmac_start(struct ifnet *ifp) { struct dwc_gmac_softc *sc = ifp->if_softc; - KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); + KASSERT(if_is_mpsafe(ifp)); mutex_enter(sc->sc_lock); if (!sc->sc_stopping) { diff --git a/sys/dev/pci/if_wm.c b/sys/dev/pci/if_wm.c index 8bd163bc73e..b5ba23c44c8 100644 --- a/sys/dev/pci/if_wm.c +++ b/sys/dev/pci/if_wm.c @@ -2630,7 +2630,7 @@ alloc_retry: ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; #ifdef WM_MPSAFE - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; #endif ifp->if_ioctl = wm_ioctl; if ((sc->sc_flags & WM_F_NEWQUEUE) != 0) { @@ -6990,7 +6990,7 @@ wm_start(struct ifnet *ifp) struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; #ifdef WM_MPSAFE - KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); + KASSERT(if_is_mpsafe(ifp)); #endif /* * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. @@ -7583,7 +7583,7 @@ wm_nq_start(struct ifnet *ifp) struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; #ifdef WM_MPSAFE - KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); + KASSERT(if_is_mpsafe(ifp)); #endif /* * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. diff --git a/sys/dev/pci/ixgbe/ixgbe.c b/sys/dev/pci/ixgbe/ixgbe.c index ef7e7868051..da8bb418e4b 100644 --- a/sys/dev/pci/ixgbe/ixgbe.c +++ b/sys/dev/pci/ixgbe/ixgbe.c @@ -1210,7 +1210,7 @@ ixgbe_setup_interface(device_t dev, struct adapter *adapter) ifp->if_softc = adapter; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; #ifdef IXGBE_MPSAFE - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; #endif ifp->if_ioctl = ixgbe_ioctl; #if __FreeBSD_version >= 1100045 diff --git a/sys/dev/pci/ixgbe/ixv.c b/sys/dev/pci/ixgbe/ixv.c index ef128a0d2a0..070561107e4 100644 --- a/sys/dev/pci/ixgbe/ixv.c +++ b/sys/dev/pci/ixgbe/ixv.c @@ -1391,7 +1391,7 @@ ixv_setup_interface(device_t dev, struct adapter *adapter) ifp->if_softc = adapter; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; #ifdef IXGBE_MPSAFE - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; #endif ifp->if_ioctl = ixv_ioctl; if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) { diff --git a/sys/net/if.h b/sys/net/if.h index b341e0d13cf..c09303b76f2 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -387,16 +387,17 @@ typedef struct ifnet { #define IFF_LINK2 0x4000 /* per link layer defined bit */ #define IFF_MULTICAST 0x8000 /* supports multicast */ -#define IFEF_OUTPUT_MPSAFE __BIT(0) /* if_output() can run parallel */ -#define IFEF_START_MPSAFE __BIT(1) /* if_start() can run parallel */ -#define IFEF_NO_LINK_STATE_CHANGE __BIT(2) /* doesn't use link state interrupts */ +#define IFEF_MPSAFE __BIT(0) /* handlers can run in parallel */ +#define IFEF_NO_LINK_STATE_CHANGE __BIT(1) /* doesn't use link state interrupts */ #ifdef _KERNEL +#include + static inline bool -if_output_is_mpsafe(struct ifnet *ifp) +if_is_mpsafe(struct ifnet *ifp) { - return ((ifp->if_extflags & IFEF_OUTPUT_MPSAFE) != 0); + return ((ifp->if_extflags & IFEF_MPSAFE) != 0); } static inline int @@ -404,7 +405,7 @@ if_output_lock(struct ifnet *cifp, struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, const struct rtentry *rt) { - if (if_output_is_mpsafe(cifp)) { + if (if_is_mpsafe(cifp)) { return (*cifp->if_output)(ifp, m, dst, rt); } else { int ret; @@ -416,18 +417,11 @@ if_output_lock(struct ifnet *cifp, struct ifnet *ifp, struct mbuf *m, } } -static inline bool -if_start_is_mpsafe(struct ifnet *ifp) -{ - - return ((ifp->if_extflags & IFEF_START_MPSAFE) != 0); -} - static inline void if_start_lock(struct ifnet *ifp) { - if (if_start_is_mpsafe(ifp)) { + if (if_is_mpsafe(ifp)) { (*ifp->if_start)(ifp); } else { KERNEL_LOCK(1, NULL); diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index ca6fa9ffe15..28c63ae501a 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -424,7 +424,7 @@ bridge_clone_create(struct if_clone *ifc, int unit) if_initname(ifp, ifc->ifc_name, unit); ifp->if_softc = sc; - ifp->if_extflags = IFEF_OUTPUT_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; ifp->if_mtu = ETHERMTU; ifp->if_ioctl = bridge_ioctl; ifp->if_output = bridge_output; @@ -1440,7 +1440,7 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, /* * bridge_output() is called from ether_output(), furthermore * ifp argument doesn't point to bridge(4). So, don't assert - * IFEF_OUTPUT_MPSAFE here. + * IFEF_MPSAFE here. */ if (m->m_len < ETHER_HDR_LEN) { diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index f0fcae746ba..b99ce9c7d32 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -204,13 +204,6 @@ ether_output(struct ifnet * const ifp0, struct mbuf * const m0, struct at_ifaddr *aa; #endif /* NETATALK */ - /* - * some paths such as carp_output() call ethr_output() with "ifp" - * argument as other than ether ifnet. - */ - KASSERT(ifp->if_output != ether_output - || ifp->if_extflags & IFEF_OUTPUT_MPSAFE); - #ifdef MBUFTRACE m_claimm(m, ifp->if_mowner); #endif @@ -951,7 +944,6 @@ ether_ifattach(struct ifnet *ifp, const uint8_t *lla) { struct ethercom *ec = (struct ethercom *)ifp; - ifp->if_extflags |= IFEF_OUTPUT_MPSAFE; ifp->if_type = IFT_ETHER; ifp->if_hdrlen = ETHER_HDR_LEN; ifp->if_dlt = DLT_EN10MB; diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index 13f74d59fac..03cd54395f5 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -275,7 +275,7 @@ gifattach0(struct gif_softc *sc) sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; sc->gif_if.if_extflags = IFEF_NO_LINK_STATE_CHANGE; #ifdef GIF_MPSAFE - sc->gif_if.if_extflags |= IFEF_OUTPUT_MPSAFE; + sc->gif_if.if_extflags |= IFEF_MPSAFE; #endif sc->gif_if.if_ioctl = gif_ioctl; sc->gif_if.if_output = gif_output; diff --git a/sys/net/if_l2tp.c b/sys/net/if_l2tp.c index 19ccc692b0f..096d4bb443d 100644 --- a/sys/net/if_l2tp.c +++ b/sys/net/if_l2tp.c @@ -265,8 +265,7 @@ l2tpattach0(struct l2tp_softc *sc) sc->l2tp_ec.ec_if.if_addrlen = 0; sc->l2tp_ec.ec_if.if_mtu = L2TP_MTU; sc->l2tp_ec.ec_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX; - sc->l2tp_ec.ec_if.if_extflags = IFEF_OUTPUT_MPSAFE | - IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; + sc->l2tp_ec.ec_if.if_extflags = IFEF_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; sc->l2tp_ec.ec_if.if_ioctl = l2tp_ioctl; sc->l2tp_ec.ec_if.if_output = l2tp_output; sc->l2tp_ec.ec_if.if_type = IFT_L2TP; diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index e1d2cb2d75b..91e2ded5ee3 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -183,7 +183,7 @@ loop_clone_create(struct if_clone *ifc, int unit) ifp->if_mtu = LOMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST | IFF_RUNNING; - ifp->if_extflags = IFEF_OUTPUT_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; ifp->if_ioctl = loioctl; ifp->if_output = looutput; #ifdef ALTQ diff --git a/sys/net/if_pppoe.c b/sys/net/if_pppoe.c index 71180fbf8e1..7d1cb68161a 100644 --- a/sys/net/if_pppoe.c +++ b/sys/net/if_pppoe.c @@ -303,7 +303,7 @@ pppoe_clone_create(struct if_clone *ifc, int unit) sc->sc_sppp.pp_if.if_mtu = PPPOE_MAXMTU; sc->sc_sppp.pp_if.if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST; #ifdef PPPOE_MPSAFE - sc->sc_sppp.pp_if.if_extflags = IFEF_OUTPUT_MPSAFE; + sc->sc_sppp.pp_if.if_extflags = IFEF_MPSAFE; #endif sc->sc_sppp.pp_if.if_type = IFT_PPP; sc->sc_sppp.pp_if.if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN; diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 9816a4d6ac1..b69bd1b4370 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -338,7 +338,7 @@ vlan_clone_create(struct if_clone *ifc, int unit) if_initname(ifp, ifc->ifc_name, unit); ifp->if_softc = ifv; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_extflags = IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; + ifp->if_extflags = IFEF_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; ifp->if_start = vlan_start; ifp->if_transmit = vlan_transmit; ifp->if_ioctl = vlan_ioctl; diff --git a/sys/netcan/if_canloop.c b/sys/netcan/if_canloop.c index 2fd367ff0c8..afe23647715 100644 --- a/sys/netcan/if_canloop.c +++ b/sys/netcan/if_canloop.c @@ -112,7 +112,7 @@ canloop_clone_create(struct if_clone *ifc, int unit) if_initname(ifp, ifc->ifc_name, unit); ifp->if_flags = IFF_LOOPBACK | IFF_RUNNING; - ifp->if_extflags = IFEF_OUTPUT_MPSAFE; + ifp->if_extflags = IFEF_MPSAFE; ifp->if_ioctl = canloop_ioctl; ifp->if_start = canloop_ifstart; can_ifattach(ifp); diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 21fd499ab31..feb2f94d727 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -880,7 +880,6 @@ carp_clone_create(struct if_clone *ifc, int unit) /* Overwrite ethernet defaults */ ifp->if_type = IFT_CARP; ifp->if_output = carp_output; - ifp->if_extflags &= ~IFEF_OUTPUT_MPSAFE; if_register(ifp); return (0);