o convert mutex calls to #defines for portability, etc.
o destroy mutex's on detach (was missing)
This commit is contained in:
parent
846b8315a2
commit
f0b2a0beb6
@ -231,10 +231,8 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
|
|||||||
callout_init(&sc->sc_scan_ch, CALLOUT_MPSAFE);
|
callout_init(&sc->sc_scan_ch, CALLOUT_MPSAFE);
|
||||||
callout_init(&sc->sc_cal_ch, CALLOUT_MPSAFE);
|
callout_init(&sc->sc_cal_ch, CALLOUT_MPSAFE);
|
||||||
|
|
||||||
mtx_init(&sc->sc_txbuflock,
|
ATH_TXBUF_LOCK_INIT(sc);
|
||||||
device_get_nameunit(sc->sc_dev), "xmit buf q", MTX_DEF);
|
ATH_TXQ_LOCK_INIT(sc);
|
||||||
mtx_init(&sc->sc_txqlock,
|
|
||||||
device_get_nameunit(sc->sc_dev), "xmit q", MTX_DEF);
|
|
||||||
|
|
||||||
TASK_INIT(&sc->sc_txtask, 0, ath_tx_proc, sc);
|
TASK_INIT(&sc->sc_txtask, 0, ath_tx_proc, sc);
|
||||||
TASK_INIT(&sc->sc_rxtask, 0, ath_rx_proc, sc);
|
TASK_INIT(&sc->sc_rxtask, 0, ath_rx_proc, sc);
|
||||||
@ -335,6 +333,10 @@ ath_detach(struct ath_softc *sc)
|
|||||||
ath_desc_free(sc);
|
ath_desc_free(sc);
|
||||||
ath_hal_detach(sc->sc_ah);
|
ath_hal_detach(sc->sc_ah);
|
||||||
ieee80211_ifdetach(ifp);
|
ieee80211_ifdetach(ifp);
|
||||||
|
|
||||||
|
ATH_TXBUF_LOCK_DESTROY(sc);
|
||||||
|
ATH_TXQ_LOCK_DESTROY(sc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +501,7 @@ ath_init(void *arg)
|
|||||||
|
|
||||||
DPRINTF(("ath_init: if_flags 0x%x\n", ifp->if_flags));
|
DPRINTF(("ath_init: if_flags 0x%x\n", ifp->if_flags));
|
||||||
|
|
||||||
mtx_lock(&sc->sc_mtx);
|
ATH_LOCK(sc);
|
||||||
/*
|
/*
|
||||||
* Stop anything previously setup. This is safe
|
* Stop anything previously setup. This is safe
|
||||||
* whether this is the first time through or not.
|
* whether this is the first time through or not.
|
||||||
@ -561,7 +563,7 @@ ath_init(void *arg)
|
|||||||
else
|
else
|
||||||
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
|
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
|
||||||
done:
|
done:
|
||||||
mtx_unlock(&sc->sc_mtx);
|
ATH_UNLOCK(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -574,7 +576,7 @@ ath_stop(struct ifnet *ifp)
|
|||||||
DPRINTF(("ath_stop: invalid %u if_flags 0x%x\n",
|
DPRINTF(("ath_stop: invalid %u if_flags 0x%x\n",
|
||||||
sc->sc_invalid, ifp->if_flags));
|
sc->sc_invalid, ifp->if_flags));
|
||||||
|
|
||||||
mtx_lock(&sc->sc_mtx);
|
ATH_LOCK(sc);
|
||||||
if (ifp->if_flags & IFF_RUNNING) {
|
if (ifp->if_flags & IFF_RUNNING) {
|
||||||
/*
|
/*
|
||||||
* Shutdown the hardware and driver:
|
* Shutdown the hardware and driver:
|
||||||
@ -605,7 +607,7 @@ ath_stop(struct ifnet *ifp)
|
|||||||
if (!sc->sc_invalid)
|
if (!sc->sc_invalid)
|
||||||
ath_hal_setpower(ah, HAL_PM_FULL_SLEEP, 0);
|
ath_hal_setpower(ah, HAL_PM_FULL_SLEEP, 0);
|
||||||
}
|
}
|
||||||
mtx_unlock(&sc->sc_mtx);
|
ATH_UNLOCK(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -665,11 +667,11 @@ ath_start(struct ifnet *ifp)
|
|||||||
/*
|
/*
|
||||||
* Grab a TX buffer and associated resources.
|
* Grab a TX buffer and associated resources.
|
||||||
*/
|
*/
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
bf = TAILQ_FIRST(&sc->sc_txbuf);
|
bf = TAILQ_FIRST(&sc->sc_txbuf);
|
||||||
if (bf != NULL)
|
if (bf != NULL)
|
||||||
TAILQ_REMOVE(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_REMOVE(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
if (bf == NULL) {
|
if (bf == NULL) {
|
||||||
DPRINTF(("ath_start: out of xmit buffers\n"));
|
DPRINTF(("ath_start: out of xmit buffers\n"));
|
||||||
sc->sc_stats.ast_tx_qstop++;
|
sc->sc_stats.ast_tx_qstop++;
|
||||||
@ -689,16 +691,16 @@ ath_start(struct ifnet *ifp)
|
|||||||
DPRINTF(("ath_start: ignore data packet, "
|
DPRINTF(("ath_start: ignore data packet, "
|
||||||
"state %u\n", ic->ic_state));
|
"state %u\n", ic->ic_state));
|
||||||
sc->sc_stats.ast_tx_discard++;
|
sc->sc_stats.ast_tx_discard++;
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
IF_DEQUEUE(&ifp->if_snd, m);
|
IF_DEQUEUE(&ifp->if_snd, m);
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ifp->if_opackets++;
|
ifp->if_opackets++;
|
||||||
@ -766,9 +768,9 @@ ath_start(struct ifnet *ifp)
|
|||||||
|
|
||||||
if (ath_tx_start(sc, ni, bf, m)) {
|
if (ath_tx_start(sc, ni, bf, m)) {
|
||||||
bad:
|
bad:
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
ifp->if_oerrors++;
|
ifp->if_oerrors++;
|
||||||
if (ni && ni != ic->ic_bss)
|
if (ni && ni != ic->ic_bss)
|
||||||
ieee80211_free_node(ic, ni);
|
ieee80211_free_node(ic, ni);
|
||||||
@ -838,7 +840,7 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|||||||
struct ifreq *ifr = (struct ifreq *)data;
|
struct ifreq *ifr = (struct ifreq *)data;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
mtx_lock(&sc->sc_mtx);
|
ATH_LOCK(sc);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case SIOCSIFFLAGS:
|
case SIOCSIFFLAGS:
|
||||||
if (ifp->if_flags & IFF_UP) {
|
if (ifp->if_flags & IFF_UP) {
|
||||||
@ -888,7 +890,7 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mtx_unlock(&sc->sc_mtx);
|
ATH_UNLOCK(sc);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1988,7 +1990,7 @@ ath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_buf *bf
|
|||||||
* Insert the frame on the outbound list and
|
* Insert the frame on the outbound list and
|
||||||
* pass it on to the hardware.
|
* pass it on to the hardware.
|
||||||
*/
|
*/
|
||||||
mtx_lock(&sc->sc_txqlock);
|
ATH_TXQ_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txq, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txq, bf, bf_list);
|
||||||
if (sc->sc_txlink == NULL) {
|
if (sc->sc_txlink == NULL) {
|
||||||
ath_hal_puttxbuf(ah, sc->sc_txhalq, bf->bf_daddr);
|
ath_hal_puttxbuf(ah, sc->sc_txhalq, bf->bf_daddr);
|
||||||
@ -2000,7 +2002,7 @@ ath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_buf *bf
|
|||||||
sc->sc_txlink, (caddr_t)bf->bf_daddr, bf->bf_desc));
|
sc->sc_txlink, (caddr_t)bf->bf_daddr, bf->bf_desc));
|
||||||
}
|
}
|
||||||
sc->sc_txlink = &bf->bf_desc[bf->bf_nseg - 1].ds_link;
|
sc->sc_txlink = &bf->bf_desc[bf->bf_nseg - 1].ds_link;
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
|
|
||||||
ath_hal_txstart(ah, sc->sc_txhalq);
|
ath_hal_txstart(ah, sc->sc_txhalq);
|
||||||
return 0;
|
return 0;
|
||||||
@ -2024,11 +2026,11 @@ ath_tx_proc(void *arg, int npending)
|
|||||||
npending, (caddr_t) ath_hal_gettxbuf(sc->sc_ah, sc->sc_txhalq),
|
npending, (caddr_t) ath_hal_gettxbuf(sc->sc_ah, sc->sc_txhalq),
|
||||||
sc->sc_txlink));
|
sc->sc_txlink));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mtx_lock(&sc->sc_txqlock);
|
ATH_TXQ_LOCK(sc);
|
||||||
bf = TAILQ_FIRST(&sc->sc_txq);
|
bf = TAILQ_FIRST(&sc->sc_txq);
|
||||||
if (bf == NULL) {
|
if (bf == NULL) {
|
||||||
sc->sc_txlink = NULL;
|
sc->sc_txlink = NULL;
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* only the last descriptor is needed */
|
/* only the last descriptor is needed */
|
||||||
@ -2039,11 +2041,11 @@ ath_tx_proc(void *arg, int npending)
|
|||||||
ath_printtxbuf(bf, status == HAL_OK);
|
ath_printtxbuf(bf, status == HAL_OK);
|
||||||
#endif
|
#endif
|
||||||
if (status == HAL_EINPROGRESS) {
|
if (status == HAL_EINPROGRESS) {
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TAILQ_REMOVE(&sc->sc_txq, bf, bf_list);
|
TAILQ_REMOVE(&sc->sc_txq, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
|
|
||||||
ni = bf->bf_node;
|
ni = bf->bf_node;
|
||||||
if (ni != NULL) {
|
if (ni != NULL) {
|
||||||
@ -2085,9 +2087,9 @@ ath_tx_proc(void *arg, int npending)
|
|||||||
bf->bf_m = NULL;
|
bf->bf_m = NULL;
|
||||||
bf->bf_node = NULL;
|
bf->bf_node = NULL;
|
||||||
|
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
}
|
}
|
||||||
ifp->if_flags &= ~IFF_OACTIVE;
|
ifp->if_flags &= ~IFF_OACTIVE;
|
||||||
sc->sc_tx_timer = 0;
|
sc->sc_tx_timer = 0;
|
||||||
@ -2117,15 +2119,15 @@ ath_draintxq(struct ath_softc *sc)
|
|||||||
(caddr_t) ath_hal_gettxbuf(ah, sc->sc_bhalq)));
|
(caddr_t) ath_hal_gettxbuf(ah, sc->sc_bhalq)));
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mtx_lock(&sc->sc_txqlock);
|
ATH_TXQ_LOCK(sc);
|
||||||
bf = TAILQ_FIRST(&sc->sc_txq);
|
bf = TAILQ_FIRST(&sc->sc_txq);
|
||||||
if (bf == NULL) {
|
if (bf == NULL) {
|
||||||
sc->sc_txlink = NULL;
|
sc->sc_txlink = NULL;
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TAILQ_REMOVE(&sc->sc_txq, bf, bf_list);
|
TAILQ_REMOVE(&sc->sc_txq, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txqlock);
|
ATH_TXQ_UNLOCK(sc);
|
||||||
#ifdef AR_DEBUG
|
#ifdef AR_DEBUG
|
||||||
if (ath_debug)
|
if (ath_debug)
|
||||||
ath_printtxbuf(bf,
|
ath_printtxbuf(bf,
|
||||||
@ -2135,9 +2137,9 @@ ath_draintxq(struct ath_softc *sc)
|
|||||||
m_freem(bf->bf_m);
|
m_freem(bf->bf_m);
|
||||||
bf->bf_m = NULL;
|
bf->bf_m = NULL;
|
||||||
bf->bf_node = NULL;
|
bf->bf_node = NULL;
|
||||||
mtx_lock(&sc->sc_txbuflock);
|
ATH_TXBUF_LOCK(sc);
|
||||||
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list);
|
||||||
mtx_unlock(&sc->sc_txbuflock);
|
ATH_TXBUF_UNLOCK(sc);
|
||||||
}
|
}
|
||||||
ifp->if_flags &= ~IFF_OACTIVE;
|
ifp->if_flags &= ~IFF_OACTIVE;
|
||||||
sc->sc_tx_timer = 0;
|
sc->sc_tx_timer = 0;
|
||||||
|
@ -194,14 +194,13 @@ ath_pci_attach(device_t dev)
|
|||||||
goto bad3;
|
goto bad3;
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx_init(&sc->sc_mtx, device_get_nameunit(dev),
|
ATH_LOCK_INIT(sc);
|
||||||
MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE);
|
|
||||||
|
|
||||||
error = ath_attach(pci_get_device(dev), sc);
|
error = ath_attach(pci_get_device(dev), sc);
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
mtx_destroy(&sc->sc_mtx);
|
ATH_LOCK_DESTROY(sc);
|
||||||
bus_dma_tag_destroy(sc->sc_dmat);
|
bus_dma_tag_destroy(sc->sc_dmat);
|
||||||
bad3:
|
bad3:
|
||||||
bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
|
bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
|
||||||
@ -231,7 +230,7 @@ ath_pci_detach(device_t dev)
|
|||||||
bus_dma_tag_destroy(sc->sc_dmat);
|
bus_dma_tag_destroy(sc->sc_dmat);
|
||||||
bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
|
bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
|
||||||
|
|
||||||
mtx_destroy(&sc->sc_mtx);
|
ATH_LOCK_DESTROY(sc);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,31 @@ struct ath_softc {
|
|||||||
#define sc_tx_th u_tx_rt.th
|
#define sc_tx_th u_tx_rt.th
|
||||||
#define sc_rx_th u_rx_rt.th
|
#define sc_rx_th u_rx_rt.th
|
||||||
|
|
||||||
|
#define ATH_LOCK_INIT(_sc) \
|
||||||
|
mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
|
||||||
|
MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE)
|
||||||
|
#define ATH_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
|
||||||
|
#define ATH_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
|
||||||
|
#define ATH_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
|
||||||
|
#define ATH_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
|
||||||
|
|
||||||
|
#define ATH_TXBUF_LOCK_INIT(_sc) \
|
||||||
|
mtx_init(&(_sc)->sc_txbuflock, \
|
||||||
|
device_get_nameunit((_sc)->sc_dev), "xmit buf q", MTX_DEF)
|
||||||
|
#define ATH_TXBUF_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_txbuflock)
|
||||||
|
#define ATH_TXBUF_LOCK(_sc) mtx_lock(&(_sc)->sc_txbuflock)
|
||||||
|
#define ATH_TXBUF_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_txbuflock)
|
||||||
|
#define ATH_TXBUF_LOCK_ASSERT(_sc) \
|
||||||
|
mtx_assert(&(_sc)->sc_txbuflock, MA_OWNED)
|
||||||
|
|
||||||
|
#define ATH_TXQ_LOCK_INIT(_sc) \
|
||||||
|
mtx_init(&(_sc)->sc_txqlock, \
|
||||||
|
device_get_nameunit((_sc)->sc_dev), "xmit q", MTX_DEF)
|
||||||
|
#define ATH_TXQ_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_txqlock)
|
||||||
|
#define ATH_TXQ_LOCK(_sc) mtx_lock(&(_sc)->sc_txqlock)
|
||||||
|
#define ATH_TXQ_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_txqlock)
|
||||||
|
#define ATH_TXQ_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_txqlock, MA_OWNED)
|
||||||
|
|
||||||
int ath_attach(u_int16_t, struct ath_softc *);
|
int ath_attach(u_int16_t, struct ath_softc *);
|
||||||
int ath_detach(struct ath_softc *);
|
int ath_detach(struct ath_softc *);
|
||||||
void ath_resume(struct ath_softc *);
|
void ath_resume(struct ath_softc *);
|
||||||
|
Loading…
Reference in New Issue
Block a user