Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci separete TX, RX queue mutex from wm_softc and re...



details:   https://anonhg.NetBSD.org/src/rev/49ada8f4079a
branches:  trunk
changeset: 340967:49ada8f4079a
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Tue Oct 13 08:11:31 2015 +0000

description:
separete TX, RX queue mutex from wm_softc and rearrange WM_BOTH_LOCK.

ok by msaitoh@n.o

diffstat:

 sys/dev/pci/if_wm.c |  208 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 124 insertions(+), 84 deletions(-)

diffs (truncated from 712 to 300 lines):

diff -r d059c53b5281 -r 49ada8f4079a sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Tue Oct 13 08:08:03 2015 +0000
+++ b/sys/dev/pci/if_wm.c       Tue Oct 13 08:11:31 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.356 2015/10/13 08:08:03 knakahara Exp $    */
+/*     $NetBSD: if_wm.c,v 1.357 2015/10/13 08:11:31 knakahara Exp $    */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.356 2015/10/13 08:08:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.357 2015/10/13 08:11:31 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -265,7 +265,7 @@
 struct wm_softc;
 
 struct wm_txqueue {
-       /* XXX should move tx_lock here. */
+       kmutex_t *txq_lock;             /* lock for tx operations */
 
        struct wm_softc *txq_sc;
 
@@ -303,7 +303,7 @@
 };
 
 struct wm_rxqueue {
-       /* XXX should move rx_lock here. */
+       kmutex_t *rxq_lock;             /* lock for rx operations */
 
        struct wm_softc *rxq_sc;
 
@@ -449,19 +449,18 @@
 
        krndsource_t rnd_source;        /* random source */
 
-       kmutex_t *sc_tx_lock;           /* lock for tx operations */
-       kmutex_t *sc_rx_lock;           /* lock for rx operations */
+       kmutex_t *sc_core_lock;         /* lock for softc operations */
 };
 
-#define WM_TX_LOCK(_sc)                if ((_sc)->sc_tx_lock) mutex_enter((_sc)->sc_tx_lock)
-#define WM_TX_UNLOCK(_sc)      if ((_sc)->sc_tx_lock) mutex_exit((_sc)->sc_tx_lock)
-#define WM_TX_LOCKED(_sc)      (!(_sc)->sc_tx_lock || mutex_owned((_sc)->sc_tx_lock))
-#define WM_RX_LOCK(_sc)                if ((_sc)->sc_rx_lock) mutex_enter((_sc)->sc_rx_lock)
-#define WM_RX_UNLOCK(_sc)      if ((_sc)->sc_rx_lock) mutex_exit((_sc)->sc_rx_lock)
-#define WM_RX_LOCKED(_sc)      (!(_sc)->sc_rx_lock || mutex_owned((_sc)->sc_rx_lock))
-#define WM_BOTH_LOCK(_sc)      do {WM_TX_LOCK(_sc); WM_RX_LOCK(_sc);} while (0)
-#define WM_BOTH_UNLOCK(_sc)    do {WM_RX_UNLOCK(_sc); WM_TX_UNLOCK(_sc);} while (0)
-#define WM_BOTH_LOCKED(_sc)    (WM_TX_LOCKED(_sc) && WM_RX_LOCKED(_sc))
+#define WM_TX_LOCK(_txq)       if ((_txq)->txq_lock) mutex_enter((_txq)->txq_lock)
+#define WM_TX_UNLOCK(_txq)     if ((_txq)->txq_lock) mutex_exit((_txq)->txq_lock)
+#define WM_TX_LOCKED(_txq)     (!(_txq)->txq_lock || mutex_owned((_txq)->txq_lock))
+#define WM_RX_LOCK(_rxq)       if ((_rxq)->rxq_lock) mutex_enter((_rxq)->rxq_lock)
+#define WM_RX_UNLOCK(_rxq)     if ((_rxq)->rxq_lock) mutex_exit((_rxq)->rxq_lock)
+#define WM_RX_LOCKED(_rxq)     (!(_rxq)->rxq_lock || mutex_owned((_rxq)->rxq_lock))
+#define WM_CORE_LOCK(_sc)      if ((_sc)->sc_core_lock) mutex_enter((_sc)->sc_core_lock)
+#define WM_CORE_UNLOCK(_sc)    if ((_sc)->sc_core_lock) mutex_exit((_sc)->sc_core_lock)
+#define WM_CORE_LOCKED(_sc)    (!(_sc)->sc_core_lock || mutex_owned((_sc)->sc_core_lock))
 
 #ifdef WM_MPSAFE
 #define CALLOUT_FLAGS  CALLOUT_MPSAFE
@@ -2546,11 +2545,9 @@
        }
 
 #ifdef WM_MPSAFE
-       sc->sc_tx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
-       sc->sc_rx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
+       sc->sc_core_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
 #else
-       sc->sc_tx_lock = NULL;
-       sc->sc_rx_lock = NULL;
+       sc->sc_core_lock = NULL;
 #endif
 
        /* Attach the interface. */
@@ -2635,6 +2632,7 @@
 wm_detach(device_t self, int flags __unused)
 {
        struct wm_softc *sc = device_private(self);
+       struct wm_rxqueue *rxq = sc->sc_rxq;
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
        int i;
 #ifndef WM_MPSAFE
@@ -2657,10 +2655,10 @@
        pmf_device_deregister(self);
 
        /* Tell the firmware about the release */
-       WM_BOTH_LOCK(sc);
+       WM_CORE_LOCK(sc);
        wm_release_manageability(sc);
        wm_release_hw_control(sc);
-       WM_BOTH_UNLOCK(sc);
+       WM_CORE_UNLOCK(sc);
 
        mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
 
@@ -2672,9 +2670,9 @@
 
 
        /* Unload RX dmamaps and free mbufs */
-       WM_RX_LOCK(sc);
+       WM_RX_LOCK(rxq);
        wm_rxdrain(sc);
-       WM_RX_UNLOCK(sc);
+       WM_RX_UNLOCK(rxq);
        /* Must unlock here */
 
        wm_free_txrx_queues(sc);
@@ -2704,10 +2702,8 @@
                sc->sc_flashs = 0;
        }
 
-       if (sc->sc_tx_lock)
-               mutex_obj_free(sc->sc_tx_lock);
-       if (sc->sc_rx_lock)
-               mutex_obj_free(sc->sc_rx_lock);
+       if (sc->sc_core_lock)
+               mutex_obj_free(sc->sc_core_lock);
 
        return 0;
 }
@@ -2751,9 +2747,9 @@
         * Since we're using delayed interrupts, sweep up
         * before we report an error.
         */
-       WM_TX_LOCK(sc);
+       WM_TX_LOCK(txq);
        wm_txeof(sc);
-       WM_TX_UNLOCK(sc);
+       WM_TX_UNLOCK(txq);
 
        if (txq->txq_free != WM_NTXDESC(txq)) {
 #ifdef WM_DEBUG
@@ -2808,7 +2804,7 @@
        s = splnet();
 #endif
 
-       WM_TX_LOCK(sc);
+       WM_CORE_LOCK(sc);
 
        if (sc->sc_stopping)
                goto out;
@@ -2841,7 +2837,7 @@
                wm_tbi_tick(sc);
 
 out:
-       WM_TX_UNLOCK(sc);
+       WM_CORE_UNLOCK(sc);
 #ifndef WM_MPSAFE
        splx(s);
 #endif
@@ -2858,7 +2854,7 @@
        int change = ifp->if_flags ^ sc->sc_if_flags;
        int rc = 0;
 
-       WM_BOTH_LOCK(sc);
+       WM_CORE_LOCK(sc);
 
        if (change != 0)
                sc->sc_if_flags = ifp->if_flags;
@@ -2874,7 +2870,7 @@
        wm_set_vlan(sc);
 
 out:
-       WM_BOTH_UNLOCK(sc);
+       WM_CORE_UNLOCK(sc);
 
        return rc;
 }
@@ -2899,7 +2895,7 @@
        switch (cmd) {
        case SIOCSIFMEDIA:
        case SIOCGIFMEDIA:
-               WM_BOTH_LOCK(sc);
+               WM_CORE_LOCK(sc);
                /* Flow control requires full-duplex mode. */
                if (IFM_SUBTYPE(ifr->ifr_media) == IFM_AUTO ||
                    (ifr->ifr_media & IFM_FDX) == 0)
@@ -2912,7 +2908,7 @@
                        }
                        sc->sc_flowflags = ifr->ifr_media & IFM_ETH_FMASK;
                }
-               WM_BOTH_UNLOCK(sc);
+               WM_CORE_UNLOCK(sc);
 #ifdef WM_MPSAFE
                s = splnet();
 #endif
@@ -2922,7 +2918,7 @@
 #endif
                break;
        case SIOCINITIFADDR:
-               WM_BOTH_LOCK(sc);
+               WM_CORE_LOCK(sc);
                if (ifa->ifa_addr->sa_family == AF_LINK) {
                        sdl = satosdl(ifp->if_dl->ifa_addr);
                        (void)sockaddr_dl_setaddr(sdl, sdl->sdl_len,
@@ -2930,10 +2926,10 @@
                        /* unicast address is first multicast entry */
                        wm_set_filter(sc);
                        error = 0;
-                       WM_BOTH_UNLOCK(sc);
+                       WM_CORE_UNLOCK(sc);
                        break;
                }
-               WM_BOTH_UNLOCK(sc);
+               WM_CORE_UNLOCK(sc);
                /*FALLTHROUGH*/
        default:
 #ifdef WM_MPSAFE
@@ -2958,9 +2954,9 @@
                         * Multicast list has changed; set the hardware filter
                         * accordingly.
                         */
-                       WM_BOTH_LOCK(sc);
+                       WM_CORE_LOCK(sc);
                        wm_set_filter(sc);
-                       WM_BOTH_UNLOCK(sc);
+                       WM_CORE_UNLOCK(sc);
                }
                break;
        }
@@ -4043,7 +4039,7 @@
        struct mbuf *m;
        int error;
 
-       KASSERT(WM_RX_LOCKED(sc));
+       KASSERT(WM_RX_LOCKED(rxq));
 
        MGETHDR(m, M_DONTWAIT, MT_DATA);
        if (m == NULL)
@@ -4095,7 +4091,7 @@
        struct wm_rxsoft *rxs;
        int i;
 
-       KASSERT(WM_RX_LOCKED(sc));
+       KASSERT(WM_RX_LOCKED(rxq));
 
        for (i = 0; i < WM_NRXDESC; i++) {
                rxs = &rxq->rxq_soft[i];
@@ -4118,9 +4114,9 @@
        struct wm_softc *sc = ifp->if_softc;
        int ret;
 
-       WM_BOTH_LOCK(sc);
+       WM_CORE_LOCK(sc);
        ret = wm_init_locked(ifp);
-       WM_BOTH_UNLOCK(sc);
+       WM_CORE_UNLOCK(sc);
 
        return ret;
 }
@@ -4132,7 +4128,7 @@
        int i, j, trynum, error = 0;
        uint32_t reg;
 
-       KASSERT(WM_BOTH_LOCKED(sc));
+       KASSERT(WM_CORE_LOCKED(sc));
        /*
         * *_HDR_ALIGNED_P is constant 1 if __NO_STRICT_ALIGMENT is set.
         * There is a small but measurable benefit to avoiding the adjusment
@@ -4612,9 +4608,9 @@
 {
        struct wm_softc *sc = ifp->if_softc;
 
-       WM_BOTH_LOCK(sc);
+       WM_CORE_LOCK(sc);
        wm_stop_locked(ifp, disable);
-       WM_BOTH_UNLOCK(sc);
+       WM_CORE_UNLOCK(sc);
 }
 
 static void
@@ -4622,10 +4618,11 @@
 {
        struct wm_softc *sc = ifp->if_softc;
        struct wm_txqueue *txq = sc->sc_txq;
+       struct wm_rxqueue *rxq = sc->sc_rxq;
        struct wm_txsoft *txs;
        int i;
 
-       KASSERT(WM_BOTH_LOCKED(sc));
+       KASSERT(WM_CORE_LOCKED(sc));
 
        sc->sc_stopping = true;
 
@@ -4668,6 +4665,7 @@
        }
 
        /* Release any queued transmit buffers. */
+       WM_TX_LOCK(txq);
        for (i = 0; i < WM_TXQUEUELEN(txq); i++) {
                txs = &txq->txq_soft[i];
                if (txs->txs_mbuf != NULL) {
@@ -4676,13 +4674,17 @@
                        txs->txs_mbuf = NULL;



Home | Main Index | Thread Index | Old Index