ifnet serializer split: Whack ifnet.if_serializer if driver supplies
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 12 Apr 2009 06:15:51 +0000 (14:15 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 12 Apr 2009 07:57:34 +0000 (15:57 +0800)
serialize functions; mainly to catch invalid reference of if_serializer.

sys/dev/netif/emx/if_emx.c
sys/dev/netif/emx/if_emx.h
sys/net/if.c

index 6ff8d77..ea2aaed 100644 (file)
@@ -404,9 +404,6 @@ emx_attach(device_t dev)
        for (i = 0; i < EMX_NRX_RING; ++i)
                lwkt_serialize_init(&sc->rx_data[i].rx_serialize);
 
-       lwkt_serialize_init(&sc->panic_serialize);
-       lwkt_serialize_enter(&sc->panic_serialize);
-
        i = 0;
        sc->serializes[i++] = &sc->main_serialize;
        sc->serializes[i++] = &sc->tx_serialize;
@@ -1828,7 +1825,7 @@ emx_setup_ifp(struct emx_softc *sc)
        ifq_set_maxlen(&ifp->if_snd, sc->num_tx_desc - 1);
        ifq_set_ready(&ifp->if_snd);
 
-       ether_ifattach(ifp, sc->hw.mac.addr, &sc->panic_serialize);
+       ether_ifattach(ifp, sc->hw.mac.addr, NULL);
 
        ifp->if_capabilities = IFCAP_HWCSUM |
                               IFCAP_VLAN_HWTAGGING |
index 0254efa..fb8959f 100644 (file)
@@ -369,8 +369,6 @@ struct emx_softc {
        int                     rss_debug;
 
        struct e1000_hw_stats   stats;
-
-       struct lwkt_serialize   panic_serialize;
 };
 
 struct emx_txbuf {
index 5d2dd6c..f04f771 100644 (file)
@@ -459,23 +459,21 @@ if_attach(struct ifnet *ifp, lwkt_serialize_t serializer)
 
        static int if_indexlim = 8;
 
-       /*
-        * The serializer can be passed in from the device, allowing the
-        * same serializer to be used for both the interrupt interlock and
-        * the device queue.  If not specified, the netif structure will
-        * use an embedded serializer.
-        */
-       if (serializer == NULL) {
-               serializer = &ifp->if_default_serializer;
-               lwkt_serialize_init(serializer);
-       }
-       ifp->if_serializer = serializer;
-
        if (ifp->if_serialize != NULL) {
                KASSERT(ifp->if_deserialize != NULL &&
                        ifp->if_tryserialize != NULL &&
                        ifp->if_serialize_assert != NULL,
                        ("serialize functions are partially setup\n"));
+
+               /*
+                * If the device supplies serialize functions,
+                * then clear if_serializer to catch any invalid
+                * usage of this field.
+                */
+               KASSERT(serializer == NULL,
+                       ("both serialize functions and default serializer "
+                        "are supplied\n"));
+               ifp->if_serializer = NULL;
        } else {
                KASSERT(ifp->if_deserialize == NULL &&
                        ifp->if_tryserialize == NULL &&
@@ -487,6 +485,19 @@ if_attach(struct ifnet *ifp, lwkt_serialize_t serializer)
 #ifdef INVARIANTS
                ifp->if_serialize_assert = if_default_serialize_assert;
 #endif
+
+               /*
+                * The serializer can be passed in from the device,
+                * allowing the same serializer to be used for both
+                * the interrupt interlock and the device queue.
+                * If not specified, the netif structure will use an
+                * embedded serializer.
+                */
+               if (serializer == NULL) {
+                       serializer = &ifp->if_default_serializer;
+                       lwkt_serialize_init(serializer);
+               }
+               ifp->if_serializer = serializer;
        }
 
        ifp->if_start_cpuid = if_start_cpuid;