if_ath.c (242258) | if_ath.c (242271) |
---|---|
1/*- 2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath.c 242258 2012-10-28 18:46:06Z adrian $"); | 31__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath.c 242271 2012-10-28 21:13:12Z adrian $"); |
32 33/* 34 * Driver for the Atheros Wireless LAN controller. 35 * 36 * This software is derived from work of Atsushi Onoe; his contribution 37 * is greatly appreciated. 38 */ 39 --- 156 unchanged lines hidden (view full) --- 196 197static int ath_rate_setup(struct ath_softc *, u_int mode); 198static void ath_setcurmode(struct ath_softc *, enum ieee80211_phymode); 199 200static void ath_announce(struct ath_softc *); 201 202static void ath_dfs_tasklet(void *, int); 203static void ath_node_powersave(struct ieee80211_node *, int); | 32 33/* 34 * Driver for the Atheros Wireless LAN controller. 35 * 36 * This software is derived from work of Atsushi Onoe; his contribution 37 * is greatly appreciated. 38 */ 39 --- 156 unchanged lines hidden (view full) --- 196 197static int ath_rate_setup(struct ath_softc *, u_int mode); 198static void ath_setcurmode(struct ath_softc *, enum ieee80211_phymode); 199 200static void ath_announce(struct ath_softc *); 201 202static void ath_dfs_tasklet(void *, int); 203static void ath_node_powersave(struct ieee80211_node *, int); |
204static int ath_node_set_tim(struct ieee80211_node *, int); |
|
204 205#ifdef IEEE80211_SUPPORT_TDMA 206#include <dev/ath/if_ath_tdma.h> 207#endif 208 209SYSCTL_DECL(_hw_ath); 210 211/* XXX validate sysctl values */ --- 935 unchanged lines hidden (view full) --- 1147 avp->av_newstate = vap->iv_newstate; 1148 vap->iv_newstate = ath_newstate; 1149 avp->av_bmiss = vap->iv_bmiss; 1150 vap->iv_bmiss = ath_bmiss_vap; 1151 1152 avp->av_node_ps = vap->iv_node_ps; 1153 vap->iv_node_ps = ath_node_powersave; 1154 | 205 206#ifdef IEEE80211_SUPPORT_TDMA 207#include <dev/ath/if_ath_tdma.h> 208#endif 209 210SYSCTL_DECL(_hw_ath); 211 212/* XXX validate sysctl values */ --- 935 unchanged lines hidden (view full) --- 1148 avp->av_newstate = vap->iv_newstate; 1149 vap->iv_newstate = ath_newstate; 1150 avp->av_bmiss = vap->iv_bmiss; 1151 vap->iv_bmiss = ath_bmiss_vap; 1152 1153 avp->av_node_ps = vap->iv_node_ps; 1154 vap->iv_node_ps = ath_node_powersave; 1155 |
1156 avp->av_set_tim = vap->iv_set_tim; 1157 vap->iv_set_tim = ath_node_set_tim; 1158 |
|
1155 /* Set default parameters */ 1156 1157 /* 1158 * Anything earlier than some AR9300 series MACs don't 1159 * support a smaller MPDU density. 1160 */ 1161 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_8; 1162 /* --- 1390 unchanged lines hidden (view full) --- 2553 ATH_TXBUF_LOCK(sc); 2554 ath_returnbuf_head(sc, bf); 2555 ath_txfrag_cleanup(sc, &frags, ni); 2556 ATH_TXBUF_UNLOCK(sc); 2557 if (ni != NULL) 2558 ieee80211_free_node(ni); 2559 continue; 2560 } | 1159 /* Set default parameters */ 1160 1161 /* 1162 * Anything earlier than some AR9300 series MACs don't 1163 * support a smaller MPDU density. 1164 */ 1165 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_8; 1166 /* --- 1390 unchanged lines hidden (view full) --- 2557 ATH_TXBUF_LOCK(sc); 2558 ath_returnbuf_head(sc, bf); 2559 ath_txfrag_cleanup(sc, &frags, ni); 2560 ATH_TXBUF_UNLOCK(sc); 2561 if (ni != NULL) 2562 ieee80211_free_node(ni); 2563 continue; 2564 } |
2565 2566 /* 2567 * Check here if the node is in power save state. 2568 */ 2569 ath_tx_update_tim(sc, ni, 1); 2570 |
|
2561 if (next != NULL) { 2562 /* 2563 * Beware of state changing between frags. 2564 * XXX check sta power-save state? 2565 */ 2566 if (ni->ni_vap->iv_state != IEEE80211_S_RUN) { 2567 DPRINTF(sc, ATH_DEBUG_XMIT, 2568 "%s: flush fragmented packet, state %s\n", --- 962 unchanged lines hidden (view full) --- 3531 if (bf->bf_next != NULL) 3532 device_printf(sc->sc_dev, 3533 "%s: bf %p: seqno %d: bf_next not NULL!\n", 3534 __func__, 3535 bf, 3536 SEQNO(bf->bf_state.bfs_seqno)); 3537 3538 /* | 2571 if (next != NULL) { 2572 /* 2573 * Beware of state changing between frags. 2574 * XXX check sta power-save state? 2575 */ 2576 if (ni->ni_vap->iv_state != IEEE80211_S_RUN) { 2577 DPRINTF(sc, ATH_DEBUG_XMIT, 2578 "%s: flush fragmented packet, state %s\n", --- 962 unchanged lines hidden (view full) --- 3541 if (bf->bf_next != NULL) 3542 device_printf(sc->sc_dev, 3543 "%s: bf %p: seqno %d: bf_next not NULL!\n", 3544 __func__, 3545 bf, 3546 SEQNO(bf->bf_state.bfs_seqno)); 3547 3548 /* |
3549 * Check if the node software queue is empty; if so 3550 * then clear the TIM. 3551 * 3552 * This needs to be done before the buffer is freed as 3553 * otherwise the node reference will have been released 3554 * and the node may not actually exist any longer. 3555 * 3556 * XXX I don't like this belonging here, but it's cleaner 3557 * to do it here right now then all the other places 3558 * where ath_tx_default_comp() is called. 3559 * 3560 * XXX TODO: during drain, ensure that the callback is 3561 * being called so we get a chance to update the TIM. 3562 */ 3563 if (bf->bf_node) 3564 ath_tx_update_tim(sc, bf->bf_node, 0); 3565 3566 /* |
|
3539 * Do any tx complete callback. Note this must 3540 * be done before releasing the node reference. 3541 * This will free the mbuf, release the net80211 3542 * node and recycle the ath_buf. 3543 */ 3544 ath_tx_freebuf(sc, bf, st); 3545} 3546 --- 7 unchanged lines hidden (view full) --- 3554{ 3555 struct ath_node *an; 3556 3557 /* Only for unicast frames */ 3558 if (ni == NULL) 3559 return; 3560 3561 an = ATH_NODE(ni); | 3567 * Do any tx complete callback. Note this must 3568 * be done before releasing the node reference. 3569 * This will free the mbuf, release the net80211 3570 * node and recycle the ath_buf. 3571 */ 3572 ath_tx_freebuf(sc, bf, st); 3573} 3574 --- 7 unchanged lines hidden (view full) --- 3582{ 3583 struct ath_node *an; 3584 3585 /* Only for unicast frames */ 3586 if (ni == NULL) 3587 return; 3588 3589 an = ATH_NODE(ni); |
3590 ATH_NODE_UNLOCK_ASSERT(an); |
|
3562 3563 if ((ts->ts_status & HAL_TXERR_FILT) == 0) { 3564 ATH_NODE_LOCK(an); 3565 ath_rate_tx_complete(sc, an, rc, ts, frmlen, nframes, nbad); 3566 ATH_NODE_UNLOCK(an); 3567 } 3568} 3569 --- 179 unchanged lines hidden (view full) --- 3749 ts->ts_rssi); 3750 } 3751 ATH_TXQ_UNLOCK(txq); 3752 3753 /* 3754 * Update statistics and call completion 3755 */ 3756 ath_tx_process_buf_completion(sc, txq, ts, bf); | 3591 3592 if ((ts->ts_status & HAL_TXERR_FILT) == 0) { 3593 ATH_NODE_LOCK(an); 3594 ath_rate_tx_complete(sc, an, rc, ts, frmlen, nframes, nbad); 3595 ATH_NODE_UNLOCK(an); 3596 } 3597} 3598 --- 179 unchanged lines hidden (view full) --- 3778 ts->ts_rssi); 3779 } 3780 ATH_TXQ_UNLOCK(txq); 3781 3782 /* 3783 * Update statistics and call completion 3784 */ 3785 ath_tx_process_buf_completion(sc, txq, ts, bf); |
3786 3787 /* XXX at this point, bf and ni may be totally invalid */ |
|
3757 } 3758#ifdef IEEE80211_SUPPORT_SUPERG 3759 /* 3760 * Flush fast-frame staging queue when traffic slows. 3761 */ 3762 if (txq->axq_depth <= 1) 3763 ieee80211_ff_flush(ic, txq->axq_ac); 3764#endif --- 1627 unchanged lines hidden (view full) --- 5392 ath_tx_node_sleep(sc, an); 5393 else 5394 ath_tx_node_wakeup(sc, an); 5395 5396 /* Update net80211 state */ 5397 avp->av_node_ps(ni, enable); 5398} 5399 | 3788 } 3789#ifdef IEEE80211_SUPPORT_SUPERG 3790 /* 3791 * Flush fast-frame staging queue when traffic slows. 3792 */ 3793 if (txq->axq_depth <= 1) 3794 ieee80211_ff_flush(ic, txq->axq_ac); 3795#endif --- 1627 unchanged lines hidden (view full) --- 5423 ath_tx_node_sleep(sc, an); 5424 else 5425 ath_tx_node_wakeup(sc, an); 5426 5427 /* Update net80211 state */ 5428 avp->av_node_ps(ni, enable); 5429} 5430 |
5431/* 5432 * Notification from net80211 that the powersave queue state has 5433 * changed. 5434 * 5435 * Since the software queue also may have some frames: 5436 * 5437 * + if the node software queue has frames and the TID state 5438 * is 0, we set the TIM; 5439 * + if the node and the stack are both empty, we clear the TIM bit. 5440 * + If the stack tries to set the bit, always set it. 5441 * + If the stack tries to clear the bit, only clear it if the 5442 * software queue in question is also cleared. 5443 * 5444 * TODO: this is called during node teardown; so let's ensure this 5445 * is all correctly handled and that the TIM bit is cleared. 5446 * It may be that the node flush is called _AFTER_ the net80211 5447 * stack clears the TIM. 5448 * 5449 * Here is the racy part. Since it's possible >1 concurrent, 5450 * overlapping TXes will appear complete with a TX completion in 5451 * another thread, it's possible that the concurrent TIM calls will 5452 * clash. We can't hold the node lock here because setting the 5453 * TIM grabs the net80211 comlock and this may cause a LOR. 5454 * The solution is either to totally serialise _everything_ at 5455 * this point (ie, all TX, completion and any reset/flush go into 5456 * one taskqueue) or a new "ath TIM lock" needs to be created that 5457 * just wraps the driver state change and this call to avp->av_set_tim(). 5458 * 5459 * The same race exists in the net80211 power save queue handling 5460 * as well. Since multiple transmitting threads may queue frames 5461 * into the driver, as well as ps-poll and the driver transmitting 5462 * frames (and thus clearing the psq), it's quite possible that 5463 * a packet entering the PSQ and a ps-poll being handled will 5464 * race, causing the TIM to be cleared and not re-set. 5465 */ 5466static int 5467ath_node_set_tim(struct ieee80211_node *ni, int enable) 5468{ 5469 struct ieee80211com *ic = ni->ni_ic; 5470 struct ath_softc *sc = ic->ic_ifp->if_softc; 5471 struct ath_node *an = ATH_NODE(ni); 5472 struct ath_vap *avp = ATH_VAP(ni->ni_vap); 5473 int changed = 0; |
|
5400 | 5474 |
5475 ATH_NODE_UNLOCK_ASSERT(an); 5476 5477 /* 5478 * For now, just track and then update the TIM. 5479 */ 5480 ATH_NODE_LOCK(an); 5481 an->an_stack_psq = enable; 5482 5483 /* 5484 * This will get called for all operating modes, 5485 * even if avp->av_set_tim is unset. 5486 * It's currently set for hostap/ibss modes; but 5487 * the same infrastructure is used for both STA 5488 * and AP/IBSS node power save. 5489 */ 5490 if (avp->av_set_tim == NULL) { 5491 ATH_NODE_UNLOCK(an); 5492 return (0); 5493 } 5494 5495 /* 5496 * If setting the bit, always set it here. 5497 * If clearing the bit, only clear it if the 5498 * software queue is also empty. 5499 * 5500 * If the node has left power save, just clear the TIM 5501 * bit regardless of the state of the power save queue. 5502 * 5503 * XXX TODO: although atomics are used, it's quite possible 5504 * that a race will occur between this and setting/clearing 5505 * in another thread. TX completion will occur always in 5506 * one thread, however setting/clearing the TIM bit can come 5507 * from a variety of different process contexts! 5508 */ 5509 if (enable && an->an_tim_set == 1) { 5510 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5511 "%s: an=%p, enable=%d, tim_set=1, ignoring\n", 5512 __func__, an, enable); 5513 ATH_NODE_UNLOCK(an); 5514 } else if (enable) { 5515 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5516 "%s: an=%p, enable=%d, enabling TIM\n", 5517 __func__, an, enable); 5518 an->an_tim_set = 1; 5519 ATH_NODE_UNLOCK(an); 5520 changed = avp->av_set_tim(ni, enable); 5521 } else if (atomic_load_acq_int(&an->an_swq_depth) == 0) { 5522 /* disable */ 5523 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5524 "%s: an=%p, enable=%d, an_swq_depth == 0, disabling\n", 5525 __func__, an, enable); 5526 an->an_tim_set = 0; 5527 ATH_NODE_UNLOCK(an); 5528 changed = avp->av_set_tim(ni, enable); 5529 } else if (! an->an_is_powersave) { 5530 /* 5531 * disable regardless; the node isn't in powersave now 5532 */ 5533 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5534 "%s: an=%p, enable=%d, an_pwrsave=0, disabling\n", 5535 __func__, an, enable); 5536 an->an_tim_set = 0; 5537 ATH_NODE_UNLOCK(an); 5538 changed = avp->av_set_tim(ni, enable); 5539 } else { 5540 /* 5541 * psq disable, node is currently in powersave, node 5542 * software queue isn't empty, so don't clear the TIM bit 5543 * for now. 5544 */ 5545 ATH_NODE_UNLOCK(an); 5546 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5547 "%s: enable=%d, an_swq_depth > 0, ignoring\n", 5548 __func__, enable); 5549 changed = 0; 5550 } 5551 5552 return (changed); 5553} 5554 5555/* 5556 * Set or update the TIM from the software queue. 5557 * 5558 * Check the software queue depth before attempting to do lock 5559 * anything; that avoids trying to obtain the lock. Then, 5560 * re-check afterwards to ensure nothing has changed in the 5561 * meantime. 5562 * 5563 * set: This is designed to be called from the TX path, after 5564 * a frame has been queued; to see if the swq > 0. 5565 * 5566 * clear: This is designed to be called from the buffer completion point 5567 * (right now it's ath_tx_default_comp()) where the state of 5568 * a software queue has changed. 5569 * 5570 * It makes sense to place it at buffer free / completion rather 5571 * than after each software queue operation, as there's no real 5572 * point in churning the TIM bit as the last frames in the software 5573 * queue are transmitted. If they fail and we retry them, we'd 5574 * just be setting the TIM bit again anyway. 5575 */ 5576void 5577ath_tx_update_tim(struct ath_softc *sc, struct ieee80211_node *ni, 5578 int enable) 5579{ 5580 struct ath_node *an; 5581 struct ath_vap *avp; 5582 5583 /* Don't do this for broadcast/etc frames */ 5584 if (ni == NULL) 5585 return; 5586 5587 an = ATH_NODE(ni); 5588 avp = ATH_VAP(ni->ni_vap); 5589 5590 /* 5591 * And for operating modes without the TIM handler set, let's 5592 * just skip those. 5593 */ 5594 if (avp->av_set_tim == NULL) 5595 return; 5596 5597 ATH_NODE_UNLOCK_ASSERT(an); 5598 5599 if (enable) { 5600 /* 5601 * Don't bother grabbing the lock unless the queue is not 5602 * empty. 5603 */ 5604 if (atomic_load_acq_int(&an->an_swq_depth) == 0) 5605 return; 5606 5607 ATH_NODE_LOCK(an); 5608 if (an->an_is_powersave && 5609 an->an_tim_set == 0 && 5610 atomic_load_acq_int(&an->an_swq_depth) != 0) { 5611 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5612 "%s: an=%p, swq_depth>0, tim_set=0, set!\n", 5613 __func__, an); 5614 an->an_tim_set = 1; 5615 ATH_NODE_UNLOCK(an); 5616 (void) avp->av_set_tim(ni, 1); 5617 } else { 5618 ATH_NODE_UNLOCK(an); 5619 } 5620 } else { 5621 /* 5622 * Don't bother grabbing the lock unless the queue is empty. 5623 */ 5624 if (atomic_load_acq_int(&an->an_swq_depth) != 0) 5625 return; 5626 5627 ATH_NODE_LOCK(an); 5628 if (an->an_is_powersave && 5629 an->an_stack_psq == 0 && 5630 an->an_tim_set == 1 && 5631 atomic_load_acq_int(&an->an_swq_depth) == 0) { 5632 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, 5633 "%s: an=%p, swq_depth=0, tim_set=1, psq_set=0," 5634 " clear!\n", 5635 __func__, an); 5636 an->an_tim_set = 0; 5637 ATH_NODE_UNLOCK(an); 5638 (void) avp->av_set_tim(ni, 0); 5639 } else { 5640 ATH_NODE_UNLOCK(an); 5641 } 5642 } 5643} 5644 |
|
5401MODULE_VERSION(if_ath, 1); 5402MODULE_DEPEND(if_ath, wlan, 1, 1, 1); /* 802.11 media layer */ 5403#if defined(IEEE80211_ALQ) || defined(AH_DEBUG_ALQ) 5404MODULE_DEPEND(if_ath, alq, 1, 1, 1); 5405#endif | 5645MODULE_VERSION(if_ath, 1); 5646MODULE_DEPEND(if_ath, wlan, 1, 1, 1); /* 802.11 media layer */ 5647#if defined(IEEE80211_ALQ) || defined(AH_DEBUG_ALQ) 5648MODULE_DEPEND(if_ath, alq, 1, 1, 1); 5649#endif |