From 2fe91baa922adc50b9f2aaf452190f385cd9ee44 Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Sat, 14 Jul 2012 02:22:17 +0000 Subject: [PATCH] Create an RX queue lock. Ideally these locks would go away and there'd be a single driver lock, like what iwn(4) does. I'll worry about that later. --- sys/dev/ath/if_ath_ahb.c | 3 +++ sys/dev/ath/if_ath_pci.c | 3 +++ sys/dev/ath/if_athvar.h | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/sys/dev/ath/if_ath_ahb.c b/sys/dev/ath/if_ath_ahb.c index a5bb413727e..ec94ba80bde 100644 --- a/sys/dev/ath/if_ath_ahb.c +++ b/sys/dev/ath/if_ath_ahb.c @@ -193,11 +193,13 @@ ath_ahb_attach(device_t dev) ATH_LOCK_INIT(sc); ATH_PCU_LOCK_INIT(sc); + ATH_RX_LOCK_INIT(sc); error = ath_attach(AR9130_DEVID, sc); if (error == 0) /* success */ return 0; + ATH_RX_LOCK_DESTROY(sc); ATH_PCU_LOCK_DESTROY(sc); ATH_LOCK_DESTROY(sc); bus_dma_tag_destroy(sc->sc_dmat); @@ -238,6 +240,7 @@ ath_ahb_detach(device_t dev) if (sc->sc_eepromdata) free(sc->sc_eepromdata, M_TEMP); + ATH_RX_LOCK_DESTROY(sc); ATH_PCU_LOCK_DESTROY(sc); ATH_LOCK_DESTROY(sc); diff --git a/sys/dev/ath/if_ath_pci.c b/sys/dev/ath/if_ath_pci.c index 773b79d72fc..6b4c9bde5e9 100644 --- a/sys/dev/ath/if_ath_pci.c +++ b/sys/dev/ath/if_ath_pci.c @@ -249,12 +249,14 @@ ath_pci_attach(device_t dev) ATH_LOCK_INIT(sc); ATH_PCU_LOCK_INIT(sc); + ATH_RX_LOCK_INIT(sc); error = ath_attach(pci_get_device(dev), sc); if (error == 0) /* success */ return 0; ATH_PCU_LOCK_DESTROY(sc); + ATH_RX_LOCK_DESTROY(sc); ATH_LOCK_DESTROY(sc); bus_dma_tag_destroy(sc->sc_dmat); bad3: @@ -294,6 +296,7 @@ ath_pci_detach(device_t dev) free(sc->sc_eepromdata, M_TEMP); ATH_PCU_LOCK_DESTROY(sc); + ATH_RX_LOCK_DESTROY(sc); ATH_LOCK_DESTROY(sc); return (0); diff --git a/sys/dev/ath/if_athvar.h b/sys/dev/ath/if_athvar.h index 7370e017d45..63bf3d413b7 100644 --- a/sys/dev/ath/if_athvar.h +++ b/sys/dev/ath/if_athvar.h @@ -425,6 +425,8 @@ struct ath_softc { struct mtx sc_mtx; /* master lock (recursive) */ struct mtx sc_pcu_mtx; /* PCU access mutex */ char sc_pcu_mtx_name[32]; + struct mtx sc_rx_mtx; /* RX access mutex */ + char sc_rx_mtx_name[32]; struct taskqueue *sc_tq; /* private task queue */ struct ath_hal *sc_ah; /* Atheros HAL */ struct ath_ratectrl *sc_rc; /* tx rate control support */ @@ -696,6 +698,28 @@ struct ath_softc { #define ATH_PCU_UNLOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_pcu_mtx, \ MA_NOTOWNED) +/* + * The RX lock is primarily a(nother) workaround to ensure that the + * RX FIFO/list isn't modified by various execution paths. + * Even though RX occurs in a single context (the ath taskqueue), the + * RX path can be executed via various reset/channel change paths. + */ +#define ATH_RX_LOCK_INIT(_sc) do {\ + snprintf((_sc)->sc_rx_mtx_name, \ + sizeof((_sc)->sc_rx_mtx_name), \ + "%s RX lock", \ + device_get_nameunit((_sc)->sc_dev)); \ + mtx_init(&(_sc)->sc_rx_mtx, (_sc)->sc_rx_mtx_name, \ + NULL, MTX_DEF); \ + } while (0) +#define ATH_RX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_rx_mtx) +#define ATH_RX_LOCK(_sc) mtx_lock(&(_sc)->sc_rx_mtx) +#define ATH_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_rx_mtx) +#define ATH_RX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_rx_mtx, \ + MA_OWNED) +#define ATH_RX_UNLOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_rx_mtx, \ + MA_NOTOWNED) + #define ATH_TXQ_SETUP(sc, i) ((sc)->sc_txqsetup & (1<