2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2010-2012 Adrian Chadd, Xenion Pty Ltd
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14 * redistribution must be conditioned upon including a substantially
15 * similar Disclaimer requirement for further binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGES.
31 #include <sys/cdefs.h>
34 * Driver for the Atheros Wireless LAN controller.
36 * This software is derived from work of Atsushi Onoe; his contribution
37 * is greatly appreciated.
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/sysctl.h>
48 #include <sys/malloc.h>
50 #include <sys/mutex.h>
51 #include <sys/kernel.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/errno.h>
55 #include <sys/callout.h>
57 #include <sys/endian.h>
58 #include <sys/kthread.h>
59 #include <sys/taskqueue.h>
64 #include <net/if_var.h>
65 #include <net/if_dl.h>
66 #include <net/if_media.h>
67 #include <net/if_types.h>
68 #include <net/if_arp.h>
69 #include <net/ethernet.h>
70 #include <net/if_llc.h>
72 #include <netproto/802_11/ieee80211_var.h>
73 #include <netproto/802_11/ieee80211_regdomain.h>
74 #ifdef IEEE80211_SUPPORT_SUPERG
75 #include <netproto/802_11/ieee80211_superg.h>
77 #ifdef IEEE80211_SUPPORT_TDMA
78 #include <netproto/802_11/ieee80211_tdma.h>
80 #include <netproto/802_11/ieee80211_ht.h>
85 #include <netinet/in.h>
86 #include <netinet/if_ether.h>
89 #include <dev/netif/ath/ath/if_athvar.h>
90 #include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
91 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
93 #include <dev/netif/ath/ath/if_ath_debug.h>
96 #include <dev/netif/ath/ath_tx99/ath_tx99.h>
99 #include <dev/netif/ath/ath/if_ath_misc.h>
100 #include <dev/netif/ath/ath/if_ath_tx.h>
101 #include <dev/netif/ath/ath/if_ath_tx_ht.h>
104 #include <dev/netif/ath/ath/if_ath_alq.h>
108 * How many retries to perform in software
110 #define SWMAX_RETRIES 10
113 * What queue to throw the non-QoS TID traffic into
115 #define ATH_NONQOS_TID_AC WME_AC_VO
118 static int ath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an);
120 static int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an,
122 static int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an,
124 static ieee80211_seq ath_tx_tid_seqno_assign(struct ath_softc *sc,
125 struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0);
126 static int ath_tx_action_frame_override_queue(struct ath_softc *sc,
127 struct ieee80211_node *ni, struct mbuf *m0, int *tid);
128 static struct ath_buf *
129 ath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an,
130 struct ath_tid *tid, struct ath_buf *bf);
134 ath_tx_alq_post(struct ath_softc *sc, struct ath_buf *bf_first)
140 /* XXX we should skip out early if debugging isn't enabled! */
144 /* XXX should ensure bf_nseg > 0! */
145 if (bf->bf_nseg == 0)
147 n = ((bf->bf_nseg - 1) / sc->sc_tx_nmaps) + 1;
148 for (i = 0, ds = (const char *) bf->bf_desc;
150 i++, ds += sc->sc_tx_desclen) {
151 if_ath_alq_post(&sc->sc_alq,
159 #endif /* ATH_DEBUG_ALQ */
162 * Whether to use the 11n rate scenario functions or not
165 ath_tx_is_11n(struct ath_softc *sc)
167 return ((sc->sc_ah->ah_magic == 0x20065416) ||
168 (sc->sc_ah->ah_magic == 0x19741014));
172 * Obtain the current TID from the given frame.
174 * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.)
175 * This has implications for which AC/priority the packet is placed
179 ath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0)
181 const struct ieee80211_frame *wh;
182 int pri = M_WME_GETAC(m0);
184 wh = mtod(m0, const struct ieee80211_frame *);
185 if (! IEEE80211_QOS_HAS_SEQ(wh))
186 return IEEE80211_NONQOS_TID;
188 return WME_AC_TO_TID(pri);
192 ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
194 struct ieee80211_frame *wh;
196 wh = mtod(bf->bf_m, struct ieee80211_frame *);
197 /* Only update/resync if needed */
198 if (bf->bf_state.bfs_isretried == 0) {
199 wh->i_fc[1] |= IEEE80211_FC1_RETRY;
200 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
201 BUS_DMASYNC_PREWRITE);
203 bf->bf_state.bfs_isretried = 1;
204 bf->bf_state.bfs_retries ++;
208 * Determine what the correct AC queue for the given frame
211 * This code assumes that the TIDs map consistently to
212 * the underlying hardware (or software) ath_txq.
213 * Since the sender may try to set an AC which is
214 * arbitrary, non-QoS TIDs may end up being put on
215 * completely different ACs. There's no way to put a
216 * TID into multiple ath_txq's for scheduling, so
217 * for now we override the AC/TXQ selection and set
218 * non-QOS TID frames into the BE queue.
220 * This may be completely incorrect - specifically,
221 * some management frames may end up out of order
222 * compared to the QoS traffic they're controlling.
223 * I'll look into this later.
226 ath_tx_getac(struct ath_softc *sc, const struct mbuf *m0)
228 const struct ieee80211_frame *wh;
229 int pri = M_WME_GETAC(m0);
230 wh = mtod(m0, const struct ieee80211_frame *);
231 if (IEEE80211_QOS_HAS_SEQ(wh))
234 return ATH_NONQOS_TID_AC;
238 ath_txfrag_cleanup(struct ath_softc *sc,
239 ath_bufhead *frags, struct ieee80211_node *ni)
243 ATH_TXBUF_LOCK_ASSERT(sc);
245 while ((bf = TAILQ_FIRST(frags)) != NULL) {
246 /* NB: bf assumed clean */
247 TAILQ_REMOVE(frags, bf, bf_list);
248 ath_returnbuf_head(sc, bf);
249 ieee80211_node_decref(ni);
254 * Setup xmit of a fragmented frame. Allocate a buffer
255 * for each frag and bump the node reference count to
256 * reflect the held reference to be setup by ath_tx_start.
259 ath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags,
260 struct mbuf *m0, struct ieee80211_node *ni)
266 for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) {
267 /* XXX non-management? */
268 bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL);
269 if (bf == NULL) { /* out of buffers, cleanup */
270 DPRINTF(sc, ATH_DEBUG_XMIT, "%s: no buffer?\n",
272 ath_txfrag_cleanup(sc, frags, ni);
275 ieee80211_node_incref(ni);
276 TAILQ_INSERT_TAIL(frags, bf, bf_list);
278 ATH_TXBUF_UNLOCK(sc);
280 return !TAILQ_EMPTY(frags);
284 * Reclaim mbuf resources. For fragmented frames we
285 * need to claim each frag chained with m_nextpkt.
288 ath_freetx(struct mbuf *m)
296 } while ((m = next) != NULL);
300 ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0)
306 * Load the DMA map so any coalescing is done. This
307 * also calculates the number of descriptors we need.
309 error = bus_dmamap_load_mbuf_segment(sc->sc_dmat, bf->bf_dmamap, m0,
310 bf->bf_segs, 1, &bf->bf_nseg,
312 if (error == EFBIG) {
313 /* XXX packet requires too many descriptors */
314 bf->bf_nseg = ATH_MAX_SCATTER + 1;
315 } else if (error != 0) {
316 sc->sc_stats.ast_tx_busdma++;
321 * Discard null packets and check for packets that
322 * require too many TX descriptors. We try to convert
323 * the latter to a cluster.
325 if (bf->bf_nseg > ATH_MAX_SCATTER) { /* too many desc's, linearize */
326 sc->sc_stats.ast_tx_linear++;
330 m = m_collapse(m0, M_NOWAIT, ATH_MAX_SCATTER);
337 sc->sc_stats.ast_tx_nombuf++;
341 error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
343 bf->bf_segs, 1, &bf->bf_nseg,
346 sc->sc_stats.ast_tx_busdma++;
350 KASSERT(bf->bf_nseg <= ATH_MAX_SCATTER,
351 ("too many segments after defrag; nseg %u", bf->bf_nseg));
352 } else if (bf->bf_nseg == 0) { /* null packet, discard */
353 sc->sc_stats.ast_tx_nodata++;
357 DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n",
358 __func__, m0, m0->m_pkthdr.len);
359 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE);
366 * Chain together segments+descriptors for a frame - 11n or otherwise.
368 * For aggregates, this is called on each frame in the aggregate.
371 ath_tx_chaindesclist(struct ath_softc *sc, struct ath_desc *ds0,
372 struct ath_buf *bf, int is_aggr, int is_first_subframe,
373 int is_last_subframe)
375 struct ath_hal *ah = sc->sc_ah;
378 HAL_DMA_ADDR bufAddrList[4];
379 uint32_t segLenList[4];
384 * XXX There's txdma and txdma_mgmt; the descriptor
387 struct ath_descdma *dd = &sc->sc_txdma;
390 * Fillin the remainder of the descriptor info.
394 * We need the number of TX data pointers in each descriptor.
395 * EDMA and later chips support 4 TX buffers per descriptor;
396 * previous chips just support one.
398 numTxMaps = sc->sc_tx_nmaps;
401 * For EDMA and later chips ensure the TX map is fully populated
402 * before advancing to the next descriptor.
404 ds = (char *) bf->bf_desc;
406 bzero(bufAddrList, sizeof(bufAddrList));
407 bzero(segLenList, sizeof(segLenList));
408 for (i = 0; i < bf->bf_nseg; i++) {
409 bufAddrList[bp] = bf->bf_segs[i].ds_addr;
410 segLenList[bp] = bf->bf_segs[i].ds_len;
414 * Go to the next segment if this isn't the last segment
415 * and there's space in the current TX map.
417 if ((i != bf->bf_nseg - 1) && (bp < numTxMaps))
421 * Last segment or we're out of buffer pointers.
425 if (i == bf->bf_nseg - 1)
426 ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 0);
428 ath_hal_settxdesclink(ah, (struct ath_desc *) ds,
429 bf->bf_daddr + dd->dd_descsize * (dsp + 1));
432 * XXX This assumes that bfs_txq is the actual destination
433 * hardware queue at this point. It may not have been
434 * assigned, it may actually be pointing to the multicast
435 * software TXQ id. These must be fixed!
437 ath_hal_filltxdesc(ah, (struct ath_desc *) ds
440 , bf->bf_descid /* XXX desc id */
441 , bf->bf_state.bfs_tx_queue
442 , isFirstDesc /* first segment */
443 , i == bf->bf_nseg - 1 /* last segment */
444 , (struct ath_desc *) ds0 /* first descriptor */
448 * Make sure the 11n aggregate fields are cleared.
450 * XXX TODO: this doesn't need to be called for
451 * aggregate frames; as it'll be called on all
452 * sub-frames. Since the descriptors are in
453 * non-cacheable memory, this leads to some
454 * rather slow writes on MIPS/ARM platforms.
456 if (ath_tx_is_11n(sc))
457 ath_hal_clr11n_aggr(sc->sc_ah, (struct ath_desc *) ds);
460 * If 11n is enabled, set it up as if it's an aggregate
463 if (is_last_subframe) {
464 ath_hal_set11n_aggr_last(sc->sc_ah,
465 (struct ath_desc *) ds);
466 } else if (is_aggr) {
468 * This clears the aggrlen field; so
469 * the caller needs to call set_aggr_first()!
471 * XXX TODO: don't call this for the first
472 * descriptor in the first frame in an
475 ath_hal_set11n_aggr_middle(sc->sc_ah,
476 (struct ath_desc *) ds,
477 bf->bf_state.bfs_ndelim);
480 bf->bf_lastds = (struct ath_desc *) ds;
483 * Don't forget to skip to the next descriptor.
485 ds += sc->sc_tx_desclen;
489 * .. and don't forget to blank these out!
491 bzero(bufAddrList, sizeof(bufAddrList));
492 bzero(segLenList, sizeof(segLenList));
494 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE);
498 * Set the rate control fields in the given descriptor based on
499 * the bf_state fields and node state.
501 * The bfs fields should already be set with the relevant rate
502 * control information, including whether MRR is to be enabled.
504 * Since the FreeBSD HAL currently sets up the first TX rate
505 * in ath_hal_setuptxdesc(), this will setup the MRR
506 * conditionally for the pre-11n chips, and call ath_buf_set_rate
507 * unconditionally for 11n chips. These require the 11n rate
508 * scenario to be set if MCS rates are enabled, so it's easier
509 * to just always call it. The caller can then only set rates 2, 3
510 * and 4 if multi-rate retry is needed.
513 ath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni,
516 struct ath_rc_series *rc = bf->bf_state.bfs_rc;
518 /* If mrr is disabled, blank tries 1, 2, 3 */
519 if (! bf->bf_state.bfs_ismrr)
520 rc[1].tries = rc[2].tries = rc[3].tries = 0;
524 * If NOACK is set, just set ntries=1.
526 else if (bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) {
527 rc[1].tries = rc[2].tries = rc[3].tries = 0;
533 * Always call - that way a retried descriptor will
534 * have the MRR fields overwritten.
536 * XXX TODO: see if this is really needed - setting up
537 * the first descriptor should set the MRR fields to 0
540 if (ath_tx_is_11n(sc)) {
541 ath_buf_set_rate(sc, ni, bf);
543 ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc
544 , rc[1].ratecode, rc[1].tries
545 , rc[2].ratecode, rc[2].tries
546 , rc[3].ratecode, rc[3].tries
552 * Setup segments+descriptors for an 11n aggregate.
553 * bf_first is the first buffer in the aggregate.
554 * The descriptor list must already been linked together using
558 ath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first)
560 struct ath_buf *bf, *bf_prev = NULL;
561 struct ath_desc *ds0 = bf_first->bf_desc;
563 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n",
564 __func__, bf_first->bf_state.bfs_nframes,
565 bf_first->bf_state.bfs_al);
569 if (bf->bf_state.bfs_txrate0 == 0)
570 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: bf=%p, txrate0=%d\n",
572 if (bf->bf_state.bfs_rc[0].ratecode == 0)
573 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: bf=%p, rix0=%d\n",
577 * Setup all descriptors of all subframes - this will
578 * call ath_hal_set11naggrmiddle() on every frame.
581 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
582 "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n",
583 __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen,
584 SEQNO(bf->bf_state.bfs_seqno));
587 * Setup the initial fields for the first descriptor - all
588 * the non-11n specific stuff.
590 ath_hal_setuptxdesc(sc->sc_ah, bf->bf_desc
591 , bf->bf_state.bfs_pktlen /* packet length */
592 , bf->bf_state.bfs_hdrlen /* header length */
593 , bf->bf_state.bfs_atype /* Atheros packet type */
594 , bf->bf_state.bfs_txpower /* txpower */
595 , bf->bf_state.bfs_txrate0
596 , bf->bf_state.bfs_try0 /* series 0 rate/tries */
597 , bf->bf_state.bfs_keyix /* key cache index */
598 , bf->bf_state.bfs_txantenna /* antenna mode */
599 , bf->bf_state.bfs_txflags | HAL_TXDESC_INTREQ /* flags */
600 , bf->bf_state.bfs_ctsrate /* rts/cts rate */
601 , bf->bf_state.bfs_ctsduration /* rts/cts duration */
605 * First descriptor? Setup the rate control and initial
606 * aggregate header information.
608 if (bf == bf_first) {
610 * setup first desc with rate and aggr info
612 ath_tx_set_ratectrl(sc, bf->bf_node, bf);
616 * Setup the descriptors for a multi-descriptor frame.
617 * This is both aggregate and non-aggregate aware.
619 ath_tx_chaindesclist(sc, ds0, bf,
621 !! (bf == bf_first), /* is_first_subframe */
622 !! (bf->bf_next == NULL) /* is_last_subframe */
625 if (bf == bf_first) {
627 * Initialise the first 11n aggregate with the
628 * aggregate length and aggregate enable bits.
630 ath_hal_set11n_aggr_first(sc->sc_ah,
633 bf->bf_state.bfs_ndelim);
637 * Link the last descriptor of the previous frame
638 * to the beginning descriptor of this frame.
641 ath_hal_settxdesclink(sc->sc_ah, bf_prev->bf_lastds,
644 /* Save a copy so we can link the next descriptor in */
650 * Set the first descriptor bf_lastds field to point to
651 * the last descriptor in the last subframe, that's where
652 * the status update will occur.
654 bf_first->bf_lastds = bf_prev->bf_lastds;
657 * And bf_last in the first descriptor points to the end of
658 * the aggregate list.
660 bf_first->bf_last = bf_prev;
663 * For non-AR9300 NICs, which require the rate control
664 * in the final descriptor - let's set that up now.
666 * This is because the filltxdesc() HAL call doesn't
667 * populate the last segment with rate control information
668 * if firstSeg is also true. For non-aggregate frames
669 * that is fine, as the first frame already has rate control
670 * info. But if the last frame in an aggregate has one
671 * descriptor, both firstseg and lastseg will be true and
672 * the rate info isn't copied.
674 * This is inefficient on MIPS/ARM platforms that have
675 * non-cachable memory for TX descriptors, but we'll just
678 * As to why the rate table is stashed in the last descriptor
679 * rather than the first descriptor? Because proctxdesc()
680 * is called on the final descriptor in an MPDU or A-MPDU -
681 * ie, the one that gets updated by the hardware upon
682 * completion. That way proctxdesc() doesn't need to know
683 * about the first _and_ last TX descriptor.
685 ath_hal_setuplasttxdesc(sc->sc_ah, bf_prev->bf_lastds, ds0);
687 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__);
691 * Hand-off a frame to the multicast TX queue.
693 * This is a software TXQ which will be appended to the CAB queue
694 * during the beacon setup code.
696 * XXX TODO: since the AR9300 EDMA TX queue support wants the QCU ID
697 * as part of the TX descriptor, bf_state.bfs_tx_queue must be updated
698 * with the actual hardware txq, or all of this will fall apart.
700 * XXX It may not be a bad idea to just stuff the QCU ID into bf_state
701 * and retire bfs_tx_queue; then make sure the CABQ QCU ID is populated
705 ath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq,
708 ATH_TX_LOCK_ASSERT(sc);
710 KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
711 ("%s: busy status 0x%x", __func__, bf->bf_flags));
714 * Ensure that the tx queue is the cabq, so things get
717 if (bf->bf_state.bfs_tx_queue != sc->sc_cabq->axq_qnum) {
718 DPRINTF(sc, ATH_DEBUG_XMIT,
719 "%s: bf=%p, bfs_tx_queue=%d, axq_qnum=%d\n",
720 __func__, bf, bf->bf_state.bfs_tx_queue,
725 if (ATH_TXQ_LAST(txq, axq_q_s) != NULL) {
726 struct ath_buf *bf_last = ATH_TXQ_LAST(txq, axq_q_s);
727 struct ieee80211_frame *wh;
729 /* mark previous frame */
730 wh = mtod(bf_last->bf_m, struct ieee80211_frame *);
731 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
732 bus_dmamap_sync(sc->sc_dmat, bf_last->bf_dmamap,
733 BUS_DMASYNC_PREWRITE);
735 /* link descriptor */
736 ath_hal_settxdesclink(sc->sc_ah,
740 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
745 * Hand-off packet to a hardware queue.
748 ath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq,
751 struct ath_hal *ah = sc->sc_ah;
752 struct ath_buf *bf_first;
755 * Insert the frame on the outbound list and pass it on
756 * to the hardware. Multicast frames buffered for power
757 * save stations and transmit from the CAB queue are stored
758 * on a s/w only queue and loaded on to the CAB queue in
759 * the SWBA handler since frames only go out on DTIM and
760 * to avoid possible races.
762 ATH_TX_LOCK_ASSERT(sc);
763 KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
764 ("%s: busy status 0x%x", __func__, bf->bf_flags));
765 KASSERT(txq->axq_qnum != ATH_TXQ_SWQ,
766 ("ath_tx_handoff_hw called for mcast queue"));
769 * XXX racy, should hold the PCU lock when checking this,
770 * and also should ensure that the TX counter is >0!
772 KASSERT((sc->sc_inreset_cnt == 0),
773 ("%s: TX during reset?\n", __func__));
777 * This causes a LOR. Find out where the PCU lock is being
778 * held whilst the TXQ lock is grabbed - that shouldn't
782 if (sc->sc_inreset_cnt) {
784 DPRINTF(sc, ATH_DEBUG_RESET,
785 "%s: called with sc_in_reset != 0\n",
787 DPRINTF(sc, ATH_DEBUG_XMIT,
788 "%s: queued: TXDP[%u] = %p (%p) depth %d\n",
789 __func__, txq->axq_qnum,
790 (caddr_t)bf->bf_daddr, bf->bf_desc,
792 /* XXX axq_link needs to be set and updated! */
793 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
794 if (bf->bf_state.bfs_aggr)
795 txq->axq_aggr_depth++;
804 * XXX TODO: if there's a holdingbf, then
805 * ATH_TXQ_PUTRUNNING should be clear.
807 * If there is a holdingbf and the list is empty,
808 * then axq_link should be pointing to the holdingbf.
810 * Otherwise it should point to the last descriptor
811 * in the last ath_buf.
813 * In any case, we should really ensure that we
814 * update the previous descriptor link pointer to
815 * this descriptor, regardless of all of the above state.
817 * For now this is captured by having axq_link point
818 * to either the holdingbf (if the TXQ list is empty)
819 * or the end of the list (if the TXQ list isn't empty.)
820 * I'd rather just kill axq_link here and do it as above.
824 * Append the frame to the TX queue.
826 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
827 ATH_KTR(sc, ATH_KTR_TX, 3,
828 "ath_tx_handoff: non-tdma: txq=%u, add bf=%p "
835 * If there's a link pointer, update it.
837 * XXX we should replace this with the above logic, just
838 * to kill axq_link with fire.
840 if (txq->axq_link != NULL) {
841 *txq->axq_link = bf->bf_daddr;
842 DPRINTF(sc, ATH_DEBUG_XMIT,
843 "%s: link[%u](%p)=%p (%p) depth %d\n", __func__,
844 txq->axq_qnum, txq->axq_link,
845 (caddr_t)bf->bf_daddr, bf->bf_desc,
847 ATH_KTR(sc, ATH_KTR_TX, 5,
848 "ath_tx_handoff: non-tdma: link[%u](%p)=%p (%p) "
850 txq->axq_qnum, txq->axq_link,
851 (caddr_t)bf->bf_daddr, bf->bf_desc,
856 * If we've not pushed anything into the hardware yet,
857 * push the head of the queue into the TxDP.
859 * Once we've started DMA, there's no guarantee that
860 * updating the TxDP with a new value will actually work.
861 * So we just don't do that - if we hit the end of the list,
862 * we keep that buffer around (the "holding buffer") and
863 * re-start DMA by updating the link pointer of _that_
864 * descriptor and then restart DMA.
866 if (! (txq->axq_flags & ATH_TXQ_PUTRUNNING)) {
867 bf_first = TAILQ_FIRST(&txq->axq_q);
868 txq->axq_flags |= ATH_TXQ_PUTRUNNING;
869 ath_hal_puttxbuf(ah, txq->axq_qnum, bf_first->bf_daddr);
870 DPRINTF(sc, ATH_DEBUG_XMIT,
871 "%s: TXDP[%u] = %p (%p) depth %d\n",
872 __func__, txq->axq_qnum,
873 (caddr_t)bf_first->bf_daddr, bf_first->bf_desc,
875 ATH_KTR(sc, ATH_KTR_TX, 5,
876 "ath_tx_handoff: TXDP[%u] = %p (%p) "
877 "lastds=%p depth %d",
879 (caddr_t)bf_first->bf_daddr, bf_first->bf_desc,
885 * Ensure that the bf TXQ matches this TXQ, so later
886 * checking and holding buffer manipulation is sane.
888 if (bf->bf_state.bfs_tx_queue != txq->axq_qnum) {
889 DPRINTF(sc, ATH_DEBUG_XMIT,
890 "%s: bf=%p, bfs_tx_queue=%d, axq_qnum=%d\n",
891 __func__, bf, bf->bf_state.bfs_tx_queue,
896 * Track aggregate queue depth.
898 if (bf->bf_state.bfs_aggr)
899 txq->axq_aggr_depth++;
902 * Update the link pointer.
904 ath_hal_gettxdesclinkptr(ah, bf->bf_lastds, &txq->axq_link);
909 * If we wrote a TxDP above, DMA will start from here.
911 * If DMA is running, it'll do nothing.
913 * If the DMA engine hit the end of the QCU list (ie LINK=NULL,
914 * or VEOL) then it stops at the last transmitted write.
915 * We then append a new frame by updating the link pointer
916 * in that descriptor and then kick TxE here; it will re-read
917 * that last descriptor and find the new descriptor to transmit.
919 * This is why we keep the holding descriptor around.
921 ath_hal_txstart(ah, txq->axq_qnum);
923 ATH_KTR(sc, ATH_KTR_TX, 1,
924 "ath_tx_handoff: txq=%u, txstart", txq->axq_qnum);
928 * Restart TX DMA for the given TXQ.
930 * This must be called whether the queue is empty or not.
933 ath_legacy_tx_dma_restart(struct ath_softc *sc, struct ath_txq *txq)
935 struct ath_buf *bf, *bf_last;
937 ATH_TXQ_LOCK_ASSERT(txq);
939 /* XXX make this ATH_TXQ_FIRST */
940 bf = TAILQ_FIRST(&txq->axq_q);
941 bf_last = ATH_TXQ_LAST(txq, axq_q_s);
946 DPRINTF(sc, ATH_DEBUG_RESET,
947 "%s: Q%d: bf=%p, bf_last=%p, daddr=0x%08x\n",
952 (uint32_t) bf->bf_daddr);
955 if (sc->sc_debug & ATH_DEBUG_RESET)
956 ath_tx_dump(sc, txq);
960 * This is called from a restart, so DMA is known to be
961 * completely stopped.
963 KASSERT((!(txq->axq_flags & ATH_TXQ_PUTRUNNING)),
964 ("%s: Q%d: called with PUTRUNNING=1\n",
968 ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
969 txq->axq_flags |= ATH_TXQ_PUTRUNNING;
971 ath_hal_gettxdesclinkptr(sc->sc_ah, bf_last->bf_lastds,
973 ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
977 * Hand off a packet to the hardware (or mcast queue.)
979 * The relevant hardware txq should be locked.
982 ath_legacy_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq,
985 ATH_TX_LOCK_ASSERT(sc);
988 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
989 ath_tx_alq_post(sc, bf);
992 if (txq->axq_qnum == ATH_TXQ_SWQ)
993 ath_tx_handoff_mcast(sc, txq, bf);
995 ath_tx_handoff_hw(sc, txq, bf);
999 ath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni,
1000 struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen,
1003 DPRINTF(sc, ATH_DEBUG_XMIT,
1004 "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n",
1013 const struct ieee80211_cipher *cip;
1014 struct ieee80211_key *k;
1017 * Construct the 802.11 header+trailer for an encrypted
1018 * frame. The only reason this can fail is because of an
1019 * unknown or unsupported cipher/key type.
1021 k = ieee80211_crypto_encap(ni, m0);
1024 * This can happen when the key is yanked after the
1025 * frame was queued. Just discard the frame; the
1026 * 802.11 layer counts failures and provides
1027 * debugging/diagnostics.
1032 * Adjust the packet + header lengths for the crypto
1033 * additions and calculate the h/w key index. When
1034 * a s/w mic is done the frame will have had any mic
1035 * added to it prior to entry so m0->m_pkthdr.len will
1036 * account for it. Otherwise we need to add it to the
1040 (*hdrlen) += cip->ic_header;
1041 (*pktlen) += cip->ic_header + cip->ic_trailer;
1042 /* NB: frags always have any TKIP MIC done in s/w */
1043 if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag)
1044 (*pktlen) += cip->ic_miclen;
1045 (*keyix) = k->wk_keyix;
1046 } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) {
1048 * Use station key cache slot, if assigned.
1050 (*keyix) = ni->ni_ucastkey.wk_keyix;
1051 if ((*keyix) == IEEE80211_KEYIX_NONE)
1052 (*keyix) = HAL_TXKEYIX_INVALID;
1054 (*keyix) = HAL_TXKEYIX_INVALID;
1060 * Calculate whether interoperability protection is required for
1063 * This requires the rate control information be filled in,
1064 * as the protection requirement depends upon the current
1065 * operating mode / PHY.
1068 ath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf)
1070 struct ieee80211_frame *wh;
1074 const HAL_RATE_TABLE *rt = sc->sc_currates;
1075 struct ifnet *ifp = sc->sc_ifp;
1076 struct ieee80211com *ic = ifp->if_l2com;
1078 flags = bf->bf_state.bfs_txflags;
1079 rix = bf->bf_state.bfs_rc[0].rix;
1080 shortPreamble = bf->bf_state.bfs_shpream;
1081 wh = mtod(bf->bf_m, struct ieee80211_frame *);
1084 * If 802.11g protection is enabled, determine whether
1085 * to use RTS/CTS or just CTS. Note that this is only
1086 * done for OFDM unicast frames.
1088 if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
1089 rt->info[rix].phy == IEEE80211_T_OFDM &&
1090 (flags & HAL_TXDESC_NOACK) == 0) {
1091 bf->bf_state.bfs_doprot = 1;
1092 /* XXX fragments must use CCK rates w/ protection */
1093 if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) {
1094 flags |= HAL_TXDESC_RTSENA;
1095 } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) {
1096 flags |= HAL_TXDESC_CTSENA;
1099 * For frags it would be desirable to use the
1100 * highest CCK rate for RTS/CTS. But stations
1101 * farther away may detect it at a lower CCK rate
1102 * so use the configured protection rate instead
1105 sc->sc_stats.ast_tx_protect++;
1109 * If 11n protection is enabled and it's a HT frame,
1112 * XXX ic_htprotmode or ic_curhtprotmode?
1113 * XXX should it_htprotmode only matter if ic_curhtprotmode
1114 * XXX indicates it's not a HT pure environment?
1116 if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) &&
1117 rt->info[rix].phy == IEEE80211_T_HT &&
1118 (flags & HAL_TXDESC_NOACK) == 0) {
1119 flags |= HAL_TXDESC_RTSENA;
1120 sc->sc_stats.ast_tx_htprotect++;
1122 bf->bf_state.bfs_txflags = flags;
1126 * Update the frame duration given the currently selected rate.
1128 * This also updates the frame duration value, so it will require
1132 ath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf)
1134 struct ieee80211_frame *wh;
1138 struct ath_hal *ah = sc->sc_ah;
1139 const HAL_RATE_TABLE *rt = sc->sc_currates;
1140 int isfrag = bf->bf_m->m_flags & M_FRAG;
1142 flags = bf->bf_state.bfs_txflags;
1143 rix = bf->bf_state.bfs_rc[0].rix;
1144 shortPreamble = bf->bf_state.bfs_shpream;
1145 wh = mtod(bf->bf_m, struct ieee80211_frame *);
1148 * Calculate duration. This logically belongs in the 802.11
1149 * layer but it lacks sufficient information to calculate it.
1151 if ((flags & HAL_TXDESC_NOACK) == 0 &&
1152 (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) {
1155 dur = rt->info[rix].spAckDuration;
1157 dur = rt->info[rix].lpAckDuration;
1158 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) {
1159 dur += dur; /* additional SIFS+ACK */
1161 * Include the size of next fragment so NAV is
1162 * updated properly. The last fragment uses only
1165 * XXX TODO: ensure that the rate lookup for each
1166 * fragment is the same as the rate used by the
1169 dur += ath_hal_computetxtime(ah,
1172 rix, shortPreamble);
1176 * Force hardware to use computed duration for next
1177 * fragment by disabling multi-rate retry which updates
1178 * duration based on the multi-rate duration table.
1180 bf->bf_state.bfs_ismrr = 0;
1181 bf->bf_state.bfs_try0 = ATH_TXMGTTRY;
1182 /* XXX update bfs_rc[0].try? */
1185 /* Update the duration field itself */
1186 *(u_int16_t *)wh->i_dur = htole16(dur);
1191 ath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt,
1192 int cix, int shortPreamble)
1197 * CTS transmit rate is derived from the transmit rate
1198 * by looking in the h/w rate table. We must also factor
1199 * in whether or not a short preamble is to be used.
1201 /* NB: cix is set above where RTS/CTS is enabled */
1202 KASSERT(cix != 0xff, ("cix not setup"));
1203 ctsrate = rt->info[cix].rateCode;
1205 /* XXX this should only matter for legacy rates */
1207 ctsrate |= rt->info[cix].shortPreamble;
1213 * Calculate the RTS/CTS duration for legacy frames.
1216 ath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix,
1217 int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt,
1220 int ctsduration = 0;
1222 /* This mustn't be called for HT modes */
1223 if (rt->info[cix].phy == IEEE80211_T_HT) {
1224 kprintf("%s: HT rate where it shouldn't be (0x%x)\n",
1225 __func__, rt->info[cix].rateCode);
1230 * Compute the transmit duration based on the frame
1231 * size and the size of an ACK frame. We call into the
1232 * HAL to do the computation since it depends on the
1233 * characteristics of the actual PHY being used.
1235 * NB: CTS is assumed the same size as an ACK so we can
1236 * use the precalculated ACK durations.
1238 if (shortPreamble) {
1239 if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */
1240 ctsduration += rt->info[cix].spAckDuration;
1241 ctsduration += ath_hal_computetxtime(ah,
1242 rt, pktlen, rix, AH_TRUE);
1243 if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */
1244 ctsduration += rt->info[rix].spAckDuration;
1246 if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */
1247 ctsduration += rt->info[cix].lpAckDuration;
1248 ctsduration += ath_hal_computetxtime(ah,
1249 rt, pktlen, rix, AH_FALSE);
1250 if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */
1251 ctsduration += rt->info[rix].lpAckDuration;
1254 return (ctsduration);
1258 * Update the given ath_buf with updated rts/cts setup and duration
1261 * To support rate lookups for each software retry, the rts/cts rate
1262 * and cts duration must be re-calculated.
1264 * This function assumes the RTS/CTS flags have been set as needed;
1265 * mrr has been disabled; and the rate control lookup has been done.
1267 * XXX TODO: MRR need only be disabled for the pre-11n NICs.
1268 * XXX The 11n NICs support per-rate RTS/CTS configuration.
1271 ath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf)
1273 uint16_t ctsduration = 0;
1274 uint8_t ctsrate = 0;
1275 uint8_t rix = bf->bf_state.bfs_rc[0].rix;
1277 const HAL_RATE_TABLE *rt = sc->sc_currates;
1280 * No RTS/CTS enabled? Don't bother.
1282 if ((bf->bf_state.bfs_txflags &
1283 (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) {
1284 /* XXX is this really needed? */
1285 bf->bf_state.bfs_ctsrate = 0;
1286 bf->bf_state.bfs_ctsduration = 0;
1291 * If protection is enabled, use the protection rix control
1292 * rate. Otherwise use the rate0 control rate.
1294 if (bf->bf_state.bfs_doprot)
1295 rix = sc->sc_protrix;
1297 rix = bf->bf_state.bfs_rc[0].rix;
1300 * If the raw path has hard-coded ctsrate0 to something,
1303 if (bf->bf_state.bfs_ctsrate0 != 0)
1304 cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0);
1306 /* Control rate from above */
1307 cix = rt->info[rix].controlRate;
1309 /* Calculate the rtscts rate for the given cix */
1310 ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix,
1311 bf->bf_state.bfs_shpream);
1313 /* The 11n chipsets do ctsduration calculations for you */
1314 if (! ath_tx_is_11n(sc))
1315 ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix,
1316 bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen,
1317 rt, bf->bf_state.bfs_txflags);
1319 /* Squirrel away in ath_buf */
1320 bf->bf_state.bfs_ctsrate = ctsrate;
1321 bf->bf_state.bfs_ctsduration = ctsduration;
1324 * Must disable multi-rate retry when using RTS/CTS.
1326 if (!sc->sc_mrrprot) {
1327 bf->bf_state.bfs_ismrr = 0;
1328 bf->bf_state.bfs_try0 =
1329 bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */
1334 * Setup the descriptor chain for a normal or fast-frame
1337 * XXX TODO: extend to include the destination hardware QCU ID.
1338 * Make sure that is correct. Make sure that when being added
1339 * to the mcastq, the CABQ QCUID is set or things will get a bit
1343 ath_tx_setds(struct ath_softc *sc, struct ath_buf *bf)
1345 struct ath_desc *ds = bf->bf_desc;
1346 struct ath_hal *ah = sc->sc_ah;
1348 if (bf->bf_state.bfs_txrate0 == 0)
1349 DPRINTF(sc, ATH_DEBUG_XMIT,
1350 "%s: bf=%p, txrate0=%d\n", __func__, bf, 0);
1352 ath_hal_setuptxdesc(ah, ds
1353 , bf->bf_state.bfs_pktlen /* packet length */
1354 , bf->bf_state.bfs_hdrlen /* header length */
1355 , bf->bf_state.bfs_atype /* Atheros packet type */
1356 , bf->bf_state.bfs_txpower /* txpower */
1357 , bf->bf_state.bfs_txrate0
1358 , bf->bf_state.bfs_try0 /* series 0 rate/tries */
1359 , bf->bf_state.bfs_keyix /* key cache index */
1360 , bf->bf_state.bfs_txantenna /* antenna mode */
1361 , bf->bf_state.bfs_txflags /* flags */
1362 , bf->bf_state.bfs_ctsrate /* rts/cts rate */
1363 , bf->bf_state.bfs_ctsduration /* rts/cts duration */
1367 * This will be overriden when the descriptor chain is written.
1372 /* Set rate control and descriptor chain for this frame */
1373 ath_tx_set_ratectrl(sc, bf->bf_node, bf);
1374 ath_tx_chaindesclist(sc, ds, bf, 0, 0, 0);
1380 * This performs a rate lookup for the given ath_buf only if it's required.
1381 * Non-data frames and raw frames don't require it.
1383 * This populates the primary and MRR entries; MRR values are
1384 * then disabled later on if something requires it (eg RTS/CTS on
1387 * This needs to be done before the RTS/CTS fields are calculated
1388 * as they may depend upon the rate chosen.
1391 ath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf)
1396 if (! bf->bf_state.bfs_doratelookup)
1399 /* Get rid of any previous state */
1400 bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc));
1402 ATH_NODE_LOCK(ATH_NODE(bf->bf_node));
1403 ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream,
1404 bf->bf_state.bfs_pktlen, &rix, &try0, &rate);
1406 /* In case MRR is disabled, make sure rc[0] is setup correctly */
1407 bf->bf_state.bfs_rc[0].rix = rix;
1408 bf->bf_state.bfs_rc[0].ratecode = rate;
1409 bf->bf_state.bfs_rc[0].tries = try0;
1411 if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY)
1412 ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix,
1413 bf->bf_state.bfs_rc);
1414 ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node));
1416 sc->sc_txrix = rix; /* for LED blinking */
1417 sc->sc_lastdatarix = rix; /* for fast frames */
1418 bf->bf_state.bfs_try0 = try0;
1419 bf->bf_state.bfs_txrate0 = rate;
1423 * Update the CLRDMASK bit in the ath_buf if it needs to be set.
1426 ath_tx_update_clrdmask(struct ath_softc *sc, struct ath_tid *tid,
1429 struct ath_node *an = ATH_NODE(bf->bf_node);
1431 ATH_TX_LOCK_ASSERT(sc);
1433 if (an->clrdmask == 1) {
1434 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
1440 * Return whether this frame should be software queued or
1441 * direct dispatched.
1443 * When doing powersave, BAR frames should be queued but other management
1444 * frames should be directly sent.
1446 * When not doing powersave, stick BAR frames into the hardware queue
1447 * so it goes out even though the queue is paused.
1449 * For now, management frames are also software queued by default.
1452 ath_tx_should_swq_frame(struct ath_softc *sc, struct ath_node *an,
1453 struct mbuf *m0, int *queue_to_head)
1455 struct ieee80211_node *ni = &an->an_node;
1456 struct ieee80211_frame *wh;
1457 uint8_t type, subtype;
1459 wh = mtod(m0, struct ieee80211_frame *);
1460 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
1461 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1463 (*queue_to_head) = 0;
1465 /* If it's not in powersave - direct-dispatch BAR */
1466 if ((ATH_NODE(ni)->an_is_powersave == 0)
1467 && type == IEEE80211_FC0_TYPE_CTL &&
1468 subtype == IEEE80211_FC0_SUBTYPE_BAR) {
1469 DPRINTF(sc, ATH_DEBUG_SW_TX,
1470 "%s: BAR: TX'ing direct\n", __func__);
1472 } else if ((ATH_NODE(ni)->an_is_powersave == 1)
1473 && type == IEEE80211_FC0_TYPE_CTL &&
1474 subtype == IEEE80211_FC0_SUBTYPE_BAR) {
1475 /* BAR TX whilst asleep; queue */
1476 DPRINTF(sc, ATH_DEBUG_SW_TX,
1477 "%s: swq: TX'ing\n", __func__);
1478 (*queue_to_head) = 1;
1480 } else if ((ATH_NODE(ni)->an_is_powersave == 1)
1481 && (type == IEEE80211_FC0_TYPE_MGT ||
1482 type == IEEE80211_FC0_TYPE_CTL)) {
1484 * Other control/mgmt frame; bypass software queuing
1487 DPRINTF(sc, ATH_DEBUG_XMIT,
1488 "%s: %6D: Node is asleep; sending mgmt "
1489 "(type=%d, subtype=%d)\n",
1490 __func__, ni->ni_macaddr, ":", type, subtype);
1499 * Transmit the given frame to the hardware.
1501 * The frame must already be setup; rate control must already have
1504 * XXX since the TXQ lock is being held here (and I dislike holding
1505 * it for this long when not doing software aggregation), later on
1506 * break this function into "setup_normal" and "xmit_normal". The
1507 * lock only needs to be held for the ath_tx_handoff call.
1509 * XXX we don't update the leak count here - if we're doing
1510 * direct frame dispatch, we need to be able to do it without
1511 * decrementing the leak count (eg multicast queue frames.)
1514 ath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq,
1517 struct ath_node *an = ATH_NODE(bf->bf_node);
1518 struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid];
1520 ATH_TX_LOCK_ASSERT(sc);
1523 * For now, just enable CLRDMASK. ath_tx_xmit_normal() does
1524 * set a completion handler however it doesn't (yet) properly
1525 * handle the strict ordering requirements needed for normal,
1526 * non-aggregate session frames.
1528 * Once this is implemented, only set CLRDMASK like this for
1529 * frames that must go out - eg management/raw frames.
1531 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
1533 /* Setup the descriptor before handoff */
1534 ath_tx_do_ratelookup(sc, bf);
1535 ath_tx_calc_duration(sc, bf);
1536 ath_tx_calc_protection(sc, bf);
1537 ath_tx_set_rtscts(sc, bf);
1538 ath_tx_rate_fill_rcflags(sc, bf);
1539 ath_tx_setds(sc, bf);
1541 /* Track per-TID hardware queue depth correctly */
1544 /* Assign the completion handler */
1545 bf->bf_comp = ath_tx_normal_comp;
1547 /* Hand off to hardware */
1548 ath_tx_handoff(sc, txq, bf);
1552 * Do the basic frame setup stuff that's required before the frame
1553 * is added to a software queue.
1555 * All frames get mostly the same treatment and it's done once.
1556 * Retransmits fiddle with things like the rate control setup,
1557 * setting the retransmit bit in the packet; doing relevant DMA/bus
1558 * syncing and relinking it (back) into the hardware TX queue.
1560 * Note that this may cause the mbuf to be reallocated, so
1561 * m0 may not be valid.
1564 ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni,
1565 struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq)
1567 struct ieee80211vap *vap = ni->ni_vap;
1568 struct ath_hal *ah = sc->sc_ah;
1569 struct ifnet *ifp = sc->sc_ifp;
1570 struct ieee80211com *ic = ifp->if_l2com;
1571 const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams;
1572 int error, iswep, ismcast, isfrag, ismrr;
1573 int keyix, hdrlen, pktlen, try0 = 0;
1574 u_int8_t rix = 0, txrate = 0;
1575 struct ath_desc *ds;
1576 struct ieee80211_frame *wh;
1577 u_int subtype, flags;
1579 const HAL_RATE_TABLE *rt;
1580 HAL_BOOL shortPreamble;
1581 struct ath_node *an;
1585 * To ensure that both sequence numbers and the CCMP PN handling
1586 * is "correct", make sure that the relevant TID queue is locked.
1587 * Otherwise the CCMP PN and seqno may appear out of order, causing
1588 * re-ordered frames to have out of order CCMP PN's, resulting
1589 * in many, many frame drops.
1591 ATH_TX_LOCK_ASSERT(sc);
1593 wh = mtod(m0, struct ieee80211_frame *);
1594 iswep = wh->i_fc[1] & IEEE80211_FC1_WEP;
1595 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
1596 isfrag = m0->m_flags & M_FRAG;
1597 hdrlen = ieee80211_anyhdrsize(wh);
1599 * Packet length must not include any
1600 * pad bytes; deduct them here.
1602 pktlen = m0->m_pkthdr.len - (hdrlen & 3);
1604 /* Handle encryption twiddling if needed */
1605 if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen,
1611 /* packet header may have moved, reset our local pointer */
1612 wh = mtod(m0, struct ieee80211_frame *);
1614 pktlen += IEEE80211_CRC_LEN;
1617 * Load the DMA map so any coalescing is done. This
1618 * also calculates the number of descriptors we need.
1620 error = ath_tx_dmasetup(sc, bf, m0);
1623 bf->bf_node = ni; /* NB: held reference */
1624 m0 = bf->bf_m; /* NB: may have changed */
1625 wh = mtod(m0, struct ieee80211_frame *);
1627 /* setup descriptors */
1629 rt = sc->sc_currates;
1630 KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
1633 * NB: the 802.11 layer marks whether or not we should
1634 * use short preamble based on the current mode and
1635 * negotiated parameters.
1637 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
1638 (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) {
1639 shortPreamble = AH_TRUE;
1640 sc->sc_stats.ast_tx_shortpre++;
1642 shortPreamble = AH_FALSE;
1646 //flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */
1648 ismrr = 0; /* default no multi-rate retry*/
1649 pri = M_WME_GETAC(m0); /* honor classification */
1650 /* XXX use txparams instead of fixed values */
1652 * Calculate Atheros packet type from IEEE80211 packet header,
1653 * setup for rate calculations, and select h/w transmit queue.
1655 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1656 case IEEE80211_FC0_TYPE_MGT:
1657 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1658 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON)
1659 atype = HAL_PKT_TYPE_BEACON;
1660 else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
1661 atype = HAL_PKT_TYPE_PROBE_RESP;
1662 else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM)
1663 atype = HAL_PKT_TYPE_ATIM;
1665 atype = HAL_PKT_TYPE_NORMAL; /* XXX */
1666 rix = an->an_mgmtrix;
1667 txrate = rt->info[rix].rateCode;
1669 txrate |= rt->info[rix].shortPreamble;
1670 try0 = ATH_TXMGTTRY;
1671 flags |= HAL_TXDESC_INTREQ; /* force interrupt */
1673 case IEEE80211_FC0_TYPE_CTL:
1674 atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */
1675 rix = an->an_mgmtrix;
1676 txrate = rt->info[rix].rateCode;
1678 txrate |= rt->info[rix].shortPreamble;
1679 try0 = ATH_TXMGTTRY;
1680 flags |= HAL_TXDESC_INTREQ; /* force interrupt */
1682 case IEEE80211_FC0_TYPE_DATA:
1683 atype = HAL_PKT_TYPE_NORMAL; /* default */
1685 * Data frames: multicast frames go out at a fixed rate,
1686 * EAPOL frames use the mgmt frame rate; otherwise consult
1687 * the rate control module for the rate to use.
1690 rix = an->an_mcastrix;
1691 txrate = rt->info[rix].rateCode;
1693 txrate |= rt->info[rix].shortPreamble;
1695 } else if (m0->m_flags & M_EAPOL) {
1696 /* XXX? maybe always use long preamble? */
1697 rix = an->an_mgmtrix;
1698 txrate = rt->info[rix].rateCode;
1700 txrate |= rt->info[rix].shortPreamble;
1701 try0 = ATH_TXMAXTRY; /* XXX?too many? */
1704 * Do rate lookup on each TX, rather than using
1705 * the hard-coded TX information decided here.
1708 bf->bf_state.bfs_doratelookup = 1;
1710 if (cap->cap_wmeParams[pri].wmep_noackPolicy)
1711 flags |= HAL_TXDESC_NOACK;
1714 if_printf(ifp, "bogus frame type 0x%x (%s)\n",
1715 wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__);
1717 /* XXX free tx dmamap */
1723 * There are two known scenarios where the frame AC doesn't match
1724 * what the destination TXQ is.
1726 * + non-QoS frames (eg management?) that the net80211 stack has
1727 * assigned a higher AC to, but since it's a non-QoS TID, it's
1728 * being thrown into TID 16. TID 16 gets the AC_BE queue.
1729 * It's quite possible that management frames should just be
1730 * direct dispatched to hardware rather than go via the software
1731 * queue; that should be investigated in the future. There are
1732 * some specific scenarios where this doesn't make sense, mostly
1733 * surrounding ADDBA request/response - hence why that is special
1736 * + Multicast frames going into the VAP mcast queue. That shows up
1739 * This driver should eventually support separate TID and TXQ locking,
1740 * allowing for arbitrary AC frames to appear on arbitrary software
1741 * queues, being queued to the "correct" hardware queue when needed.
1744 if (txq != sc->sc_ac2q[pri]) {
1745 DPRINTF(sc, ATH_DEBUG_XMIT,
1746 "%s: txq=%p (%d), pri=%d, pri txq=%p (%d)\n",
1752 sc->sc_ac2q[pri]->axq_qnum);
1757 * Calculate miscellaneous flags.
1760 flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */
1761 } else if (pktlen > vap->iv_rtsthreshold &&
1762 (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) {
1763 flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */
1764 sc->sc_stats.ast_tx_rts++;
1766 if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */
1767 sc->sc_stats.ast_tx_noack++;
1768 #ifdef IEEE80211_SUPPORT_TDMA
1769 if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) {
1770 DPRINTF(sc, ATH_DEBUG_TDMA,
1771 "%s: discard frame, ACK required w/ TDMA\n", __func__);
1772 sc->sc_stats.ast_tdma_ack++;
1773 /* XXX free tx dmamap */
1780 * Determine if a tx interrupt should be generated for
1781 * this descriptor. We take a tx interrupt to reap
1782 * descriptors when the h/w hits an EOL condition or
1783 * when the descriptor is specifically marked to generate
1784 * an interrupt. We periodically mark descriptors in this
1785 * way to insure timely replenishing of the supply needed
1786 * for sending frames. Defering interrupts reduces system
1787 * load and potentially allows more concurrent work to be
1788 * done but if done to aggressively can cause senders to
1791 * NB: use >= to deal with sc_txintrperiod changing
1792 * dynamically through sysctl.
1794 if (flags & HAL_TXDESC_INTREQ) {
1795 txq->axq_intrcnt = 0;
1796 } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) {
1797 flags |= HAL_TXDESC_INTREQ;
1798 txq->axq_intrcnt = 0;
1801 /* This point forward is actual TX bits */
1804 * At this point we are committed to sending the frame
1805 * and we don't need to look at m_nextpkt; clear it in
1806 * case this frame is part of frag chain.
1808 m0->m_nextpkt = NULL;
1810 if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT))
1811 ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len,
1812 sc->sc_hwmap[rix].ieeerate, -1);
1814 if (ieee80211_radiotap_active_vap(vap)) {
1815 u_int64_t tsf = ath_hal_gettsf64(ah);
1817 sc->sc_tx_th.wt_tsf = htole64(tsf);
1818 sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags;
1820 sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP;
1822 sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
1823 sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate;
1824 sc->sc_tx_th.wt_txpower = ieee80211_get_node_txpower(ni);
1825 sc->sc_tx_th.wt_antenna = sc->sc_txantenna;
1827 ieee80211_radiotap_tx(vap, m0);
1830 /* Blank the legacy rate array */
1831 bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc));
1834 * ath_buf_set_rate needs at least one rate/try to setup
1835 * the rate scenario.
1837 bf->bf_state.bfs_rc[0].rix = rix;
1838 bf->bf_state.bfs_rc[0].tries = try0;
1839 bf->bf_state.bfs_rc[0].ratecode = txrate;
1841 /* Store the decided rate index values away */
1842 bf->bf_state.bfs_pktlen = pktlen;
1843 bf->bf_state.bfs_hdrlen = hdrlen;
1844 bf->bf_state.bfs_atype = atype;
1845 bf->bf_state.bfs_txpower = ieee80211_get_node_txpower(ni);
1846 bf->bf_state.bfs_txrate0 = txrate;
1847 bf->bf_state.bfs_try0 = try0;
1848 bf->bf_state.bfs_keyix = keyix;
1849 bf->bf_state.bfs_txantenna = sc->sc_txantenna;
1850 bf->bf_state.bfs_txflags = flags;
1851 bf->bf_state.bfs_shpream = shortPreamble;
1853 /* XXX this should be done in ath_tx_setrate() */
1854 bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */
1855 bf->bf_state.bfs_ctsrate = 0; /* calculated later */
1856 bf->bf_state.bfs_ctsduration = 0;
1857 bf->bf_state.bfs_ismrr = ismrr;
1863 * Queue a frame to the hardware or software queue.
1865 * This can be called by the net80211 code.
1867 * XXX what about locking? Or, push the seqno assign into the
1868 * XXX aggregate scheduler so its serialised?
1870 * XXX When sending management frames via ath_raw_xmit(),
1871 * should CLRDMASK be set unconditionally?
1874 ath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni,
1875 struct ath_buf *bf, struct mbuf *m0)
1877 struct ieee80211vap *vap = ni->ni_vap;
1878 struct ath_vap *avp = ATH_VAP(vap);
1882 struct ath_txq *txq;
1884 const struct ieee80211_frame *wh;
1885 int is_ampdu, is_ampdu_tx, is_ampdu_pending;
1886 ieee80211_seq seqno;
1887 uint8_t type, subtype;
1890 ATH_TX_LOCK_ASSERT(sc);
1893 * Determine the target hardware queue.
1895 * For multicast frames, the txq gets overridden appropriately
1896 * depending upon the state of PS.
1898 * For any other frame, we do a TID/QoS lookup inside the frame
1899 * to see what the TID should be. If it's a non-QoS frame, the
1900 * AC and TID are overridden. The TID/TXQ code assumes the
1901 * TID is on a predictable hardware TXQ, so we don't support
1902 * having a node TID queued to multiple hardware TXQs.
1903 * This may change in the future but would require some locking
1906 pri = ath_tx_getac(sc, m0);
1907 tid = ath_tx_gettid(sc, m0);
1909 txq = sc->sc_ac2q[pri];
1910 wh = mtod(m0, struct ieee80211_frame *);
1911 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
1912 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
1913 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1916 * Enforce how deep the multicast queue can grow.
1918 * XXX duplicated in ath_raw_xmit().
1920 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1921 if (sc->sc_cabq->axq_depth + sc->sc_cabq->fifo.axq_depth
1922 > sc->sc_txq_mcastq_maxdepth) {
1923 sc->sc_stats.ast_tx_mcastq_overflow++;
1930 * Enforce how deep the unicast queue can grow.
1932 * If the node is in power save then we don't want
1933 * the software queue to grow too deep, or a node may
1934 * end up consuming all of the ath_buf entries.
1936 * For now, only do this for DATA frames.
1938 * We will want to cap how many management/control
1939 * frames get punted to the software queue so it doesn't
1940 * fill up. But the correct solution isn't yet obvious.
1941 * In any case, this check should at least let frames pass
1942 * that we are direct-dispatching.
1944 * XXX TODO: duplicate this to the raw xmit path!
1946 if (type == IEEE80211_FC0_TYPE_DATA &&
1947 ATH_NODE(ni)->an_is_powersave &&
1948 ATH_NODE(ni)->an_swq_depth >
1949 sc->sc_txq_node_psq_maxdepth) {
1950 sc->sc_stats.ast_tx_node_psq_overflow++;
1956 is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid);
1957 is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid);
1958 is_ampdu = is_ampdu_tx | is_ampdu_pending;
1960 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ac=%d, is_ampdu=%d\n",
1961 __func__, tid, pri, is_ampdu);
1963 /* Set local packet state, used to queue packets to hardware */
1964 bf->bf_state.bfs_tid = tid;
1965 bf->bf_state.bfs_tx_queue = txq->axq_qnum;
1966 bf->bf_state.bfs_pri = pri;
1970 * When servicing one or more stations in power-save mode
1971 * (or) if there is some mcast data waiting on the mcast
1972 * queue (to prevent out of order delivery) multicast frames
1973 * must be bufferd until after the beacon.
1975 * TODO: we should lock the mcastq before we check the length.
1977 if (sc->sc_cabq_enable && ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) {
1978 txq = &avp->av_mcastq;
1980 * Mark the frame as eventually belonging on the CAB
1981 * queue, so the descriptor setup functions will
1982 * correctly initialise the descriptor 'qcuId' field.
1984 bf->bf_state.bfs_tx_queue = sc->sc_cabq->axq_qnum;
1988 /* Do the generic frame setup */
1989 /* XXX should just bzero the bf_state? */
1990 bf->bf_state.bfs_dobaw = 0;
1992 /* A-MPDU TX? Manually set sequence number */
1994 * Don't do it whilst pending; the net80211 layer still
1999 * Always call; this function will
2000 * handle making sure that null data frames
2001 * don't get a sequence number from the current
2002 * TID and thus mess with the BAW.
2004 seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0);
2007 * Don't add QoS NULL frames to the BAW.
2009 if (IEEE80211_QOS_HAS_SEQ(wh) &&
2010 subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL) {
2011 bf->bf_state.bfs_dobaw = 1;
2016 * If needed, the sequence number has been assigned.
2017 * Squirrel it away somewhere easy to get to.
2019 bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT;
2021 /* Is ampdu pending? fetch the seqno and print it out */
2022 if (is_ampdu_pending)
2023 DPRINTF(sc, ATH_DEBUG_SW_TX,
2024 "%s: tid %d: ampdu pending, seqno %d\n",
2025 __func__, tid, M_SEQNO_GET(m0));
2027 /* This also sets up the DMA map */
2028 r = ath_tx_normal_setup(sc, ni, bf, m0, txq);
2033 /* At this point m0 could have changed! */
2038 * If it's a multicast frame, do a direct-dispatch to the
2039 * destination hardware queue. Don't bother software
2043 * If it's a BAR frame, do a direct dispatch to the
2044 * destination hardware queue. Don't bother software
2045 * queuing it, as the TID will now be paused.
2046 * Sending a BAR frame can occur from the net80211 txa timer
2047 * (ie, retries) or from the ath txtask (completion call.)
2048 * It queues directly to hardware because the TID is paused
2049 * at this point (and won't be unpaused until the BAR has
2050 * either been TXed successfully or max retries has been
2054 * Until things are better debugged - if this node is asleep
2055 * and we're sending it a non-BAR frame, direct dispatch it.
2056 * Why? Because we need to figure out what's actually being
2057 * sent - eg, during reassociation/reauthentication after
2058 * the node (last) disappeared whilst asleep, the driver should
2059 * have unpaused/unsleep'ed the node. So until that is
2060 * sorted out, use this workaround.
2062 if (txq == &avp->av_mcastq) {
2063 DPRINTF(sc, ATH_DEBUG_SW_TX,
2064 "%s: bf=%p: mcastq: TX'ing\n", __func__, bf);
2065 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2066 ath_tx_xmit_normal(sc, txq, bf);
2067 } else if (ath_tx_should_swq_frame(sc, ATH_NODE(ni), m0,
2069 ath_tx_swq(sc, ni, txq, queue_to_head, bf);
2071 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2072 ath_tx_xmit_normal(sc, txq, bf);
2076 * For now, since there's no software queue,
2077 * direct-dispatch to the hardware.
2079 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2081 * Update the current leak count if
2082 * we're leaking frames; and set the
2083 * MORE flag as appropriate.
2085 ath_tx_leak_count_update(sc, tid, bf);
2086 ath_tx_xmit_normal(sc, txq, bf);
2093 ath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni,
2094 struct ath_buf *bf, struct mbuf *m0,
2095 const struct ieee80211_bpf_params *params)
2097 struct ifnet *ifp = sc->sc_ifp;
2098 struct ieee80211com *ic = ifp->if_l2com;
2099 struct ath_hal *ah = sc->sc_ah;
2100 struct ieee80211vap *vap = ni->ni_vap;
2101 int error, ismcast, ismrr;
2102 int keyix, hdrlen, pktlen, try0, txantenna;
2103 u_int8_t rix, txrate;
2104 struct ieee80211_frame *wh;
2107 const HAL_RATE_TABLE *rt;
2108 struct ath_desc *ds;
2112 uint8_t type, subtype;
2115 ATH_TX_LOCK_ASSERT(sc);
2117 wh = mtod(m0, struct ieee80211_frame *);
2118 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2119 hdrlen = ieee80211_anyhdrsize(wh);
2121 * Packet length must not include any
2122 * pad bytes; deduct them here.
2124 /* XXX honor IEEE80211_BPF_DATAPAD */
2125 pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN;
2127 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2128 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2130 ATH_KTR(sc, ATH_KTR_TX, 2,
2131 "ath_tx_raw_start: ni=%p, bf=%p, raw", ni, bf);
2133 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n",
2136 pri = params->ibp_pri & 3;
2137 /* Override pri if the frame isn't a QoS one */
2138 if (! IEEE80211_QOS_HAS_SEQ(wh))
2139 pri = ath_tx_getac(sc, m0);
2141 /* XXX If it's an ADDBA, override the correct queue */
2142 do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid);
2144 /* Map ADDBA to the correct priority */
2147 DPRINTF(sc, ATH_DEBUG_XMIT,
2148 "%s: overriding tid %d pri %d -> %d\n",
2149 __func__, o_tid, pri, TID_TO_WME_AC(o_tid));
2151 pri = TID_TO_WME_AC(o_tid);
2154 /* Handle encryption twiddling if needed */
2155 if (! ath_tx_tag_crypto(sc, ni,
2156 m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0,
2157 &hdrlen, &pktlen, &keyix)) {
2161 /* packet header may have moved, reset our local pointer */
2162 wh = mtod(m0, struct ieee80211_frame *);
2164 /* Do the generic frame setup */
2165 /* XXX should just bzero the bf_state? */
2166 bf->bf_state.bfs_dobaw = 0;
2168 error = ath_tx_dmasetup(sc, bf, m0);
2171 m0 = bf->bf_m; /* NB: may have changed */
2172 wh = mtod(m0, struct ieee80211_frame *);
2173 bf->bf_node = ni; /* NB: held reference */
2175 /* Always enable CLRDMASK for raw frames for now.. */
2176 flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */
2177 flags |= HAL_TXDESC_INTREQ; /* force interrupt */
2178 if (params->ibp_flags & IEEE80211_BPF_RTS)
2179 flags |= HAL_TXDESC_RTSENA;
2180 else if (params->ibp_flags & IEEE80211_BPF_CTS) {
2181 /* XXX assume 11g/11n protection? */
2182 bf->bf_state.bfs_doprot = 1;
2183 flags |= HAL_TXDESC_CTSENA;
2185 /* XXX leave ismcast to injector? */
2186 if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast)
2187 flags |= HAL_TXDESC_NOACK;
2189 rt = sc->sc_currates;
2190 KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
2191 rix = ath_tx_findrix(sc, params->ibp_rate0);
2192 txrate = rt->info[rix].rateCode;
2193 if (params->ibp_flags & IEEE80211_BPF_SHORTPRE)
2194 txrate |= rt->info[rix].shortPreamble;
2196 try0 = params->ibp_try0;
2197 ismrr = (params->ibp_try1 != 0);
2198 txantenna = params->ibp_pri >> 2;
2199 if (txantenna == 0) /* XXX? */
2200 txantenna = sc->sc_txantenna;
2203 * Since ctsrate is fixed, store it away for later
2204 * use when the descriptor fields are being set.
2206 if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA))
2207 bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate;
2210 * NB: we mark all packets as type PSPOLL so the h/w won't
2211 * set the sequence number, duration, etc.
2213 atype = HAL_PKT_TYPE_PSPOLL;
2215 if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT))
2216 ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len,
2217 sc->sc_hwmap[rix].ieeerate, -1);
2219 if (ieee80211_radiotap_active_vap(vap)) {
2220 u_int64_t tsf = ath_hal_gettsf64(ah);
2222 sc->sc_tx_th.wt_tsf = htole64(tsf);
2223 sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags;
2224 if (wh->i_fc[1] & IEEE80211_FC1_WEP)
2225 sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2226 if (m0->m_flags & M_FRAG)
2227 sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
2228 sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate;
2229 sc->sc_tx_th.wt_txpower = MIN(params->ibp_power,
2230 ieee80211_get_node_txpower(ni));
2231 sc->sc_tx_th.wt_antenna = sc->sc_txantenna;
2233 ieee80211_radiotap_tx(vap, m0);
2237 * Formulate first tx descriptor with tx controls.
2240 /* XXX check return value? */
2242 /* Store the decided rate index values away */
2243 bf->bf_state.bfs_pktlen = pktlen;
2244 bf->bf_state.bfs_hdrlen = hdrlen;
2245 bf->bf_state.bfs_atype = atype;
2246 bf->bf_state.bfs_txpower = MIN(params->ibp_power,
2247 ieee80211_get_node_txpower(ni));
2248 bf->bf_state.bfs_txrate0 = txrate;
2249 bf->bf_state.bfs_try0 = try0;
2250 bf->bf_state.bfs_keyix = keyix;
2251 bf->bf_state.bfs_txantenna = txantenna;
2252 bf->bf_state.bfs_txflags = flags;
2253 bf->bf_state.bfs_shpream =
2254 !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE);
2256 /* Set local packet state, used to queue packets to hardware */
2257 bf->bf_state.bfs_tid = WME_AC_TO_TID(pri);
2258 bf->bf_state.bfs_tx_queue = sc->sc_ac2q[pri]->axq_qnum;
2259 bf->bf_state.bfs_pri = pri;
2261 /* XXX this should be done in ath_tx_setrate() */
2262 bf->bf_state.bfs_ctsrate = 0;
2263 bf->bf_state.bfs_ctsduration = 0;
2264 bf->bf_state.bfs_ismrr = ismrr;
2266 /* Blank the legacy rate array */
2267 bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc));
2269 bf->bf_state.bfs_rc[0].rix =
2270 ath_tx_findrix(sc, params->ibp_rate0);
2271 bf->bf_state.bfs_rc[0].tries = try0;
2272 bf->bf_state.bfs_rc[0].ratecode = txrate;
2277 rix = ath_tx_findrix(sc, params->ibp_rate1);
2278 bf->bf_state.bfs_rc[1].rix = rix;
2279 bf->bf_state.bfs_rc[1].tries = params->ibp_try1;
2281 rix = ath_tx_findrix(sc, params->ibp_rate2);
2282 bf->bf_state.bfs_rc[2].rix = rix;
2283 bf->bf_state.bfs_rc[2].tries = params->ibp_try2;
2285 rix = ath_tx_findrix(sc, params->ibp_rate3);
2286 bf->bf_state.bfs_rc[3].rix = rix;
2287 bf->bf_state.bfs_rc[3].tries = params->ibp_try3;
2290 * All the required rate control decisions have been made;
2291 * fill in the rc flags.
2293 ath_tx_rate_fill_rcflags(sc, bf);
2295 /* NB: no buffered multicast in power save support */
2298 * If we're overiding the ADDBA destination, dump directly
2299 * into the hardware queue, right after any pending
2300 * frames to that node are.
2302 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n",
2303 __func__, do_override);
2307 * Put addba frames in the right place in the right TID/HWQ.
2310 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2312 * XXX if it's addba frames, should we be leaking
2313 * them out via the frame leak method?
2314 * XXX for now let's not risk it; but we may wish
2315 * to investigate this later.
2317 ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf);
2318 } else if (ath_tx_should_swq_frame(sc, ATH_NODE(ni), m0,
2320 /* Queue to software queue */
2321 ath_tx_swq(sc, ni, sc->sc_ac2q[pri], queue_to_head, bf);
2323 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2324 ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf);
2327 /* Direct-dispatch to the hardware */
2328 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
2330 * Update the current leak count if
2331 * we're leaking frames; and set the
2332 * MORE flag as appropriate.
2334 ath_tx_leak_count_update(sc, tid, bf);
2335 ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf);
2343 * This can be called by net80211.
2346 ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
2347 const struct ieee80211_bpf_params *params)
2349 struct ieee80211com *ic = ni->ni_ic;
2350 struct ifnet *ifp = ic->ic_ifp;
2351 struct ath_softc *sc = ifp->if_softc;
2353 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
2357 if (sc->sc_inreset_cnt > 0) {
2358 DPRINTF(sc, ATH_DEBUG_XMIT,
2359 "%s: sc_inreset_cnt > 0; bailing\n", __func__);
2364 sc->sc_txstart_cnt++;
2369 if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) {
2370 DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__,
2371 (ifp->if_flags & IFF_RUNNING) == 0 ?
2372 "!running" : "invalid");
2379 * Enforce how deep the multicast queue can grow.
2381 * XXX duplicated in ath_tx_start().
2383 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2384 if (sc->sc_cabq->axq_depth + sc->sc_cabq->fifo.axq_depth
2385 > sc->sc_txq_mcastq_maxdepth) {
2386 sc->sc_stats.ast_tx_mcastq_overflow++;
2397 * Grab a TX buffer and associated resources.
2399 bf = ath_getbuf(sc, ATH_BUFTYPE_MGMT);
2401 sc->sc_stats.ast_tx_nobuf++;
2406 ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: m=%p, params=%p, bf=%p\n",
2409 if (params == NULL) {
2411 * Legacy path; interpret frame contents to decide
2412 * precisely how to send the frame.
2414 if (ath_tx_start(sc, ni, bf, m)) {
2415 error = EIO; /* XXX */
2420 * Caller supplied explicit parameters to use in
2421 * sending the frame.
2423 if (ath_tx_raw_start(sc, ni, bf, m, params)) {
2424 error = EIO; /* XXX */
2428 sc->sc_wd_timer = 5;
2430 sc->sc_stats.ast_tx_raw++;
2433 * Update the TIM - if there's anything queued to the
2434 * software queue and power save is enabled, we should
2437 ath_tx_update_tim(sc, ni, 1);
2442 sc->sc_txstart_cnt--;
2447 ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: bad2: m=%p, params=%p, "
2453 ath_returnbuf_head(sc, bf);
2454 ATH_TXBUF_UNLOCK(sc);
2460 sc->sc_txstart_cnt--;
2463 ATH_KTR(sc, ATH_KTR_TX, 2, "ath_raw_xmit: bad0: m=%p, params=%p",
2466 sc->sc_stats.ast_tx_raw_fail++;
2467 ieee80211_free_node(ni);
2472 /* Some helper functions */
2475 * ADDBA (and potentially others) need to be placed in the same
2476 * hardware queue as the TID/node it's relating to. This is so
2477 * it goes out after any pending non-aggregate frames to the
2480 * If this isn't done, the ADDBA can go out before the frames
2481 * queued in hardware. Even though these frames have a sequence
2482 * number -earlier- than the ADDBA can be transmitted (but
2483 * no frames whose sequence numbers are after the ADDBA should
2484 * be!) they'll arrive after the ADDBA - and the receiving end
2485 * will simply drop them as being out of the BAW.
2487 * The frames can't be appended to the TID software queue - it'll
2488 * never be sent out. So these frames have to be directly
2489 * dispatched to the hardware, rather than queued in software.
2490 * So if this function returns true, the TXQ has to be
2491 * overridden and it has to be directly dispatched.
2493 * It's a dirty hack, but someone's gotta do it.
2497 * XXX doesn't belong here!
2500 ieee80211_is_action(struct ieee80211_frame *wh)
2502 /* Type: Management frame? */
2503 if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
2504 IEEE80211_FC0_TYPE_MGT)
2507 /* Subtype: Action frame? */
2508 if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) !=
2509 IEEE80211_FC0_SUBTYPE_ACTION)
2515 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2517 * Return an alternate TID for ADDBA request frames.
2519 * Yes, this likely should be done in the net80211 layer.
2522 ath_tx_action_frame_override_queue(struct ath_softc *sc,
2523 struct ieee80211_node *ni,
2524 struct mbuf *m0, int *tid)
2526 struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *);
2527 struct ieee80211_action_ba_addbarequest *ia;
2529 uint16_t baparamset;
2531 /* Not action frame? Bail */
2532 if (! ieee80211_is_action(wh))
2535 /* XXX Not needed for frames we send? */
2537 /* Correct length? */
2538 if (! ieee80211_parse_action(ni, m))
2542 /* Extract out action frame */
2543 frm = (u_int8_t *)&wh[1];
2544 ia = (struct ieee80211_action_ba_addbarequest *) frm;
2546 /* Not ADDBA? Bail */
2547 if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA)
2549 if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST)
2552 /* Extract TID, return it */
2553 baparamset = le16toh(ia->rq_baparamset);
2554 *tid = (int) MS(baparamset, IEEE80211_BAPS_TID);
2560 /* Per-node software queue operations */
2563 * Add the current packet to the given BAW.
2564 * It is assumed that the current packet
2566 * + fits inside the BAW;
2567 * + already has had a sequence number allocated.
2569 * Since the BAW status may be modified by both the ath task and
2570 * the net80211/ifnet contexts, the TID must be locked.
2573 ath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an,
2574 struct ath_tid *tid, struct ath_buf *bf)
2577 struct ieee80211_tx_ampdu *tap;
2579 ATH_TX_LOCK_ASSERT(sc);
2581 if (bf->bf_state.bfs_isretried)
2584 tap = ath_tx_get_tx_tid(an, tid->tid);
2586 if (! bf->bf_state.bfs_dobaw) {
2587 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2588 "%s: dobaw=0, seqno=%d, window %d:%d\n",
2589 __func__, SEQNO(bf->bf_state.bfs_seqno),
2590 tap->txa_start, tap->txa_wnd);
2593 if (bf->bf_state.bfs_addedbaw)
2594 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2595 "%s: re-added? tid=%d, seqno %d; window %d:%d; "
2596 "baw head=%d tail=%d\n",
2597 __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno),
2598 tap->txa_start, tap->txa_wnd, tid->baw_head,
2602 * Verify that the given sequence number is not outside of the
2603 * BAW. Complain loudly if that's the case.
2605 if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd,
2606 SEQNO(bf->bf_state.bfs_seqno))) {
2607 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2608 "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; "
2609 "baw head=%d tail=%d\n",
2610 __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno),
2611 tap->txa_start, tap->txa_wnd, tid->baw_head,
2616 * ni->ni_txseqs[] is the currently allocated seqno.
2617 * the txa state contains the current baw start.
2619 index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno));
2620 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
2621 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2622 "%s: tid=%d, seqno %d; window %d:%d; index=%d cindex=%d "
2623 "baw head=%d tail=%d\n",
2624 __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno),
2625 tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head,
2630 assert(tid->tx_buf[cindex] == NULL);
2632 if (tid->tx_buf[cindex] != NULL) {
2633 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2634 "%s: ba packet dup (index=%d, cindex=%d, "
2635 "head=%d, tail=%d)\n",
2636 __func__, index, cindex, tid->baw_head, tid->baw_tail);
2637 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2638 "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n",
2640 tid->tx_buf[cindex],
2641 SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno),
2643 SEQNO(bf->bf_state.bfs_seqno)
2646 tid->tx_buf[cindex] = bf;
2648 if (index >= ((tid->baw_tail - tid->baw_head) &
2649 (ATH_TID_MAX_BUFS - 1))) {
2650 tid->baw_tail = cindex;
2651 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
2656 * Flip the BAW buffer entry over from the existing one to the new one.
2658 * When software retransmitting a (sub-)frame, it is entirely possible that
2659 * the frame ath_buf is marked as BUSY and can't be immediately reused.
2660 * In that instance the buffer is cloned and the new buffer is used for
2661 * retransmit. We thus need to update the ath_buf slot in the BAW buf
2662 * tracking array to maintain consistency.
2665 ath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an,
2666 struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf)
2669 struct ieee80211_tx_ampdu *tap;
2670 int seqno = SEQNO(old_bf->bf_state.bfs_seqno);
2672 ATH_TX_LOCK_ASSERT(sc);
2674 tap = ath_tx_get_tx_tid(an, tid->tid);
2675 index = ATH_BA_INDEX(tap->txa_start, seqno);
2676 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
2679 * Just warn for now; if it happens then we should find out
2680 * about it. It's highly likely the aggregation session will
2683 if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) {
2684 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2685 "%s: retransmitted buffer"
2686 " has mismatching seqno's, BA session may hang.\n",
2688 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2689 "%s: old seqno=%d, new_seqno=%d\n", __func__,
2690 old_bf->bf_state.bfs_seqno, new_bf->bf_state.bfs_seqno);
2693 if (tid->tx_buf[cindex] != old_bf) {
2694 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2695 "%s: ath_buf pointer incorrect; "
2696 " has m BA session may hang.\n", __func__);
2697 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2698 "%s: old bf=%p, new bf=%p\n", __func__, old_bf, new_bf);
2701 tid->tx_buf[cindex] = new_bf;
2705 * seq_start - left edge of BAW
2706 * seq_next - current/next sequence number to allocate
2708 * Since the BAW status may be modified by both the ath task and
2709 * the net80211/ifnet contexts, the TID must be locked.
2712 ath_tx_update_baw(struct ath_softc *sc, struct ath_node *an,
2713 struct ath_tid *tid, const struct ath_buf *bf)
2716 struct ieee80211_tx_ampdu *tap;
2717 int seqno = SEQNO(bf->bf_state.bfs_seqno);
2719 ATH_TX_LOCK_ASSERT(sc);
2721 tap = ath_tx_get_tx_tid(an, tid->tid);
2722 index = ATH_BA_INDEX(tap->txa_start, seqno);
2723 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
2725 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2726 "%s: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, "
2727 "baw head=%d, tail=%d\n",
2728 __func__, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index,
2729 cindex, tid->baw_head, tid->baw_tail);
2732 * If this occurs then we have a big problem - something else
2733 * has slid tap->txa_start along without updating the BAW
2734 * tracking start/end pointers. Thus the TX BAW state is now
2735 * completely busted.
2737 * But for now, since I haven't yet fixed TDMA and buffer cloning,
2738 * it's quite possible that a cloned buffer is making its way
2739 * here and causing it to fire off. Disable TDMA for now.
2741 if (tid->tx_buf[cindex] != bf) {
2742 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2743 "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n",
2744 __func__, bf, SEQNO(bf->bf_state.bfs_seqno),
2745 tid->tx_buf[cindex],
2746 (tid->tx_buf[cindex] != NULL) ?
2747 SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno) : -1);
2750 tid->tx_buf[cindex] = NULL;
2752 while (tid->baw_head != tid->baw_tail &&
2753 !tid->tx_buf[tid->baw_head]) {
2754 INCR(tap->txa_start, IEEE80211_SEQ_RANGE);
2755 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
2757 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
2758 "%s: baw is now %d:%d, baw head=%d\n",
2759 __func__, tap->txa_start, tap->txa_wnd, tid->baw_head);
2763 ath_tx_leak_count_update(struct ath_softc *sc, struct ath_tid *tid,
2766 struct ieee80211_frame *wh;
2768 ATH_TX_LOCK_ASSERT(sc);
2770 if (tid->an->an_leak_count > 0) {
2771 wh = mtod(bf->bf_m, struct ieee80211_frame *);
2774 * Update MORE based on the software/net80211 queue states.
2776 if ((tid->an->an_stack_psq > 0)
2777 || (tid->an->an_swq_depth > 0))
2778 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
2780 wh->i_fc[1] &= ~IEEE80211_FC1_MORE_DATA;
2782 DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
2783 "%s: %6D: leak count = %d, psq=%d, swq=%d, MORE=%d\n",
2785 tid->an->an_node.ni_macaddr,
2787 tid->an->an_leak_count,
2788 tid->an->an_stack_psq,
2789 tid->an->an_swq_depth,
2790 !! (wh->i_fc[1] & IEEE80211_FC1_MORE_DATA));
2793 * Re-sync the underlying buffer.
2795 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
2796 BUS_DMASYNC_PREWRITE);
2798 tid->an->an_leak_count --;
2803 ath_tx_tid_can_tx_or_sched(struct ath_softc *sc, struct ath_tid *tid)
2806 ATH_TX_LOCK_ASSERT(sc);
2808 if (tid->an->an_leak_count > 0) {
2817 * Mark the current node/TID as ready to TX.
2819 * This is done to make it easy for the software scheduler to
2820 * find which nodes have data to send.
2822 * The TXQ lock must be held.
2825 ath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid)
2827 struct ath_txq *txq = sc->sc_ac2q[tid->ac];
2829 ATH_TX_LOCK_ASSERT(sc);
2832 * If we are leaking out a frame to this destination
2833 * for PS-POLL, ensure that we allow scheduling to
2836 if (! ath_tx_tid_can_tx_or_sched(sc, tid))
2837 return; /* paused, can't schedule yet */
2840 return; /* already scheduled */
2846 * If this is a sleeping node we're leaking to, given
2847 * it a higher priority. This is so bad for QoS it hurts.
2849 if (tid->an->an_leak_count) {
2850 TAILQ_INSERT_HEAD(&txq->axq_tidq, tid, axq_qelem);
2852 TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem);
2857 * We can't do the above - it'll confuse the TXQ software
2858 * scheduler which will keep checking the _head_ TID
2859 * in the list to see if it has traffic. If we queue
2860 * a TID to the head of the list and it doesn't transmit,
2861 * we'll check it again.
2863 * So, get the rest of this leaking frames support working
2864 * and reliable first and _then_ optimise it so they're
2865 * pushed out in front of any other pending software
2868 TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem);
2872 * Mark the current node as no longer needing to be polled for
2875 * The TXQ lock must be held.
2878 ath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid)
2880 struct ath_txq *txq = sc->sc_ac2q[tid->ac];
2882 ATH_TX_LOCK_ASSERT(sc);
2884 if (tid->sched == 0)
2888 TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem);
2892 * Assign a sequence number manually to the given frame.
2894 * This should only be called for A-MPDU TX frames.
2896 static ieee80211_seq
2897 ath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni,
2898 struct ath_buf *bf, struct mbuf *m0)
2900 struct ieee80211_frame *wh;
2902 ieee80211_seq seqno;
2906 wh = mtod(m0, struct ieee80211_frame *);
2907 pri = M_WME_GETAC(m0); /* honor classification */
2908 tid = WME_AC_TO_TID(pri);
2909 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pri=%d, tid=%d, qos has seq=%d\n",
2910 __func__, pri, tid, IEEE80211_QOS_HAS_SEQ(wh));
2912 /* XXX Is it a control frame? Ignore */
2914 /* Does the packet require a sequence number? */
2915 if (! IEEE80211_QOS_HAS_SEQ(wh))
2918 ATH_TX_LOCK_ASSERT(sc);
2921 * Is it a QOS NULL Data frame? Give it a sequence number from
2922 * the default TID (IEEE80211_NONQOS_TID.)
2924 * The RX path of everything I've looked at doesn't include the NULL
2925 * data frame sequence number in the aggregation state updates, so
2926 * assigning it a sequence number there will cause a BAW hole on the
2929 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2930 if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) {
2931 /* XXX no locking for this TID? This is a bit of a problem. */
2932 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID];
2933 INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE);
2935 /* Manually assign sequence number */
2936 seqno = ni->ni_txseqs[tid];
2937 INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE);
2939 *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
2940 M_SEQNO_SET(m0, seqno);
2942 /* Return so caller can do something with it if needed */
2943 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: -> seqno=%d\n", __func__, seqno);
2948 * Attempt to direct dispatch an aggregate frame to hardware.
2949 * If the frame is out of BAW, queue.
2950 * Otherwise, schedule it as a single frame.
2953 ath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an,
2954 struct ath_txq *txq, struct ath_buf *bf)
2956 struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid];
2957 struct ieee80211_tx_ampdu *tap;
2959 ATH_TX_LOCK_ASSERT(sc);
2961 tap = ath_tx_get_tx_tid(an, tid->tid);
2964 if (! ath_tx_tid_can_tx_or_sched(sc, tid)) {
2965 ATH_TID_INSERT_HEAD(tid, bf, bf_list);
2966 /* XXX don't sched - we're paused! */
2970 /* outside baw? queue */
2971 if (bf->bf_state.bfs_dobaw &&
2972 (! BAW_WITHIN(tap->txa_start, tap->txa_wnd,
2973 SEQNO(bf->bf_state.bfs_seqno)))) {
2974 ATH_TID_INSERT_HEAD(tid, bf, bf_list);
2975 ath_tx_tid_sched(sc, tid);
2980 * This is a temporary check and should be removed once
2981 * all the relevant code paths have been fixed.
2983 * During aggregate retries, it's possible that the head
2984 * frame will fail (which has the bfs_aggr and bfs_nframes
2985 * fields set for said aggregate) and will be retried as
2986 * a single frame. In this instance, the values should
2987 * be reset or the completion code will get upset with you.
2989 if (bf->bf_state.bfs_aggr != 0 || bf->bf_state.bfs_nframes > 1) {
2990 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
2991 "%s: bfs_aggr=%d, bfs_nframes=%d\n", __func__,
2992 bf->bf_state.bfs_aggr, bf->bf_state.bfs_nframes);
2993 bf->bf_state.bfs_aggr = 0;
2994 bf->bf_state.bfs_nframes = 1;
2997 /* Update CLRDMASK just before this frame is queued */
2998 ath_tx_update_clrdmask(sc, tid, bf);
3000 /* Direct dispatch to hardware */
3001 ath_tx_do_ratelookup(sc, bf);
3002 ath_tx_calc_duration(sc, bf);
3003 ath_tx_calc_protection(sc, bf);
3004 ath_tx_set_rtscts(sc, bf);
3005 ath_tx_rate_fill_rcflags(sc, bf);
3006 ath_tx_setds(sc, bf);
3009 sc->sc_aggr_stats.aggr_low_hwq_single_pkt++;
3011 /* Track per-TID hardware queue depth correctly */
3015 if (bf->bf_state.bfs_dobaw) {
3016 ath_tx_addto_baw(sc, an, tid, bf);
3017 bf->bf_state.bfs_addedbaw = 1;
3020 /* Set completion handler, multi-frame aggregate or not */
3021 bf->bf_comp = ath_tx_aggr_comp;
3024 * Update the current leak count if
3025 * we're leaking frames; and set the
3026 * MORE flag as appropriate.
3028 ath_tx_leak_count_update(sc, tid, bf);
3030 /* Hand off to hardware */
3031 ath_tx_handoff(sc, txq, bf);
3035 * Attempt to send the packet.
3036 * If the queue isn't busy, direct-dispatch.
3037 * If the queue is busy enough, queue the given packet on the
3038 * relevant software queue.
3041 ath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni,
3042 struct ath_txq *txq, int queue_to_head, struct ath_buf *bf)
3044 struct ath_node *an = ATH_NODE(ni);
3045 struct ieee80211_frame *wh;
3046 struct ath_tid *atid;
3048 struct mbuf *m0 = bf->bf_m;
3050 ATH_TX_LOCK_ASSERT(sc);
3052 /* Fetch the TID - non-QoS frames get assigned to TID 16 */
3053 wh = mtod(m0, struct ieee80211_frame *);
3054 pri = ath_tx_getac(sc, m0);
3055 tid = ath_tx_gettid(sc, m0);
3056 atid = &an->an_tid[tid];
3058 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d\n",
3059 __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh));
3061 /* Set local packet state, used to queue packets to hardware */
3062 /* XXX potentially duplicate info, re-check */
3063 bf->bf_state.bfs_tid = tid;
3064 bf->bf_state.bfs_tx_queue = txq->axq_qnum;
3065 bf->bf_state.bfs_pri = pri;
3068 * If the hardware queue isn't busy, queue it directly.
3069 * If the hardware queue is busy, queue it.
3070 * If the TID is paused or the traffic it outside BAW, software
3073 * If the node is in power-save and we're leaking a frame,
3074 * leak a single frame.
3076 if (! ath_tx_tid_can_tx_or_sched(sc, atid)) {
3077 /* TID is paused, queue */
3078 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: paused\n", __func__);
3080 * If the caller requested that it be sent at a high
3081 * priority, queue it at the head of the list.
3084 ATH_TID_INSERT_HEAD(atid, bf, bf_list);
3086 ATH_TID_INSERT_TAIL(atid, bf, bf_list);
3087 } else if (ath_tx_ampdu_pending(sc, an, tid)) {
3088 /* AMPDU pending; queue */
3089 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pending\n", __func__);
3090 ATH_TID_INSERT_TAIL(atid, bf, bf_list);
3092 } else if (ath_tx_ampdu_running(sc, an, tid)) {
3093 /* AMPDU running, attempt direct dispatch if possible */
3096 * Always queue the frame to the tail of the list.
3098 ATH_TID_INSERT_TAIL(atid, bf, bf_list);
3101 * If the hardware queue isn't busy, direct dispatch
3102 * the head frame in the list. Don't schedule the
3103 * TID - let it build some more frames first?
3105 * When running A-MPDU, always just check the hardware
3106 * queue depth against the aggregate frame limit.
3107 * We don't want to burst a large number of single frames
3108 * out to the hardware; we want to aggressively hold back.
3110 * Otherwise, schedule the TID.
3112 /* XXX TXQ locking */
3113 if (txq->axq_depth + txq->fifo.axq_depth < sc->sc_hwq_limit_aggr) {
3114 bf = ATH_TID_FIRST(atid);
3115 ATH_TID_REMOVE(atid, bf, bf_list);
3118 * Ensure it's definitely treated as a non-AMPDU
3119 * frame - this information may have been left
3120 * over from a previous attempt.
3122 bf->bf_state.bfs_aggr = 0;
3123 bf->bf_state.bfs_nframes = 1;
3125 /* Queue to the hardware */
3126 ath_tx_xmit_aggr(sc, an, txq, bf);
3127 DPRINTF(sc, ATH_DEBUG_SW_TX,
3131 DPRINTF(sc, ATH_DEBUG_SW_TX,
3132 "%s: ampdu; swq'ing\n",
3135 ath_tx_tid_sched(sc, atid);
3138 * If we're not doing A-MPDU, be prepared to direct dispatch
3139 * up to both limits if possible. This particular corner
3140 * case may end up with packet starvation between aggregate
3141 * traffic and non-aggregate traffic: we wnat to ensure
3142 * that non-aggregate stations get a few frames queued to the
3143 * hardware before the aggregate station(s) get their chance.
3145 * So if you only ever see a couple of frames direct dispatched
3146 * to the hardware from a non-AMPDU client, check both here
3147 * and in the software queue dispatcher to ensure that those
3148 * non-AMPDU stations get a fair chance to transmit.
3150 /* XXX TXQ locking */
3151 } else if ((txq->axq_depth + txq->fifo.axq_depth < sc->sc_hwq_limit_nonaggr) &&
3152 (txq->axq_aggr_depth < sc->sc_hwq_limit_aggr)) {
3153 /* AMPDU not running, attempt direct dispatch */
3154 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: xmit_normal\n", __func__);
3155 /* See if clrdmask needs to be set */
3156 ath_tx_update_clrdmask(sc, atid, bf);
3159 * Update the current leak count if
3160 * we're leaking frames; and set the
3161 * MORE flag as appropriate.
3163 ath_tx_leak_count_update(sc, atid, bf);
3166 * Dispatch the frame.
3168 ath_tx_xmit_normal(sc, txq, bf);
3171 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: swq'ing\n", __func__);
3172 ATH_TID_INSERT_TAIL(atid, bf, bf_list);
3173 ath_tx_tid_sched(sc, atid);
3178 * Only set the clrdmask bit if none of the nodes are currently
3181 * XXX TODO: go through all the callers and check to see
3182 * which are being called in the context of looping over all
3183 * TIDs (eg, if all tids are being paused, resumed, etc.)
3184 * That'll avoid O(n^2) complexity here.
3187 ath_tx_set_clrdmask(struct ath_softc *sc, struct ath_node *an)
3191 ATH_TX_LOCK_ASSERT(sc);
3193 for (i = 0; i < IEEE80211_TID_SIZE; i++) {
3194 if (an->an_tid[i].isfiltered == 1)
3201 * Configure the per-TID node state.
3203 * This likely belongs in if_ath_node.c but I can't think of anywhere
3204 * else to put it just yet.
3206 * This sets up the SLISTs and the mutex as appropriate.
3209 ath_tx_tid_init(struct ath_softc *sc, struct ath_node *an)
3212 struct ath_tid *atid;
3214 for (i = 0; i < IEEE80211_TID_SIZE; i++) {
3215 atid = &an->an_tid[i];
3217 /* XXX now with this bzer(), is the field 0'ing needed? */
3218 bzero(atid, sizeof(*atid));
3220 TAILQ_INIT(&atid->tid_q);
3221 TAILQ_INIT(&atid->filtq.tid_q);
3224 for (j = 0; j < ATH_TID_MAX_BUFS; j++)
3225 atid->tx_buf[j] = NULL;
3226 atid->baw_head = atid->baw_tail = 0;
3229 atid->hwq_depth = 0;
3230 atid->cleanup_inprogress = 0;
3231 if (i == IEEE80211_NONQOS_TID)
3232 atid->ac = ATH_NONQOS_TID_AC;
3234 atid->ac = TID_TO_WME_AC(i);
3236 an->clrdmask = 1; /* Always start by setting this bit */
3240 * Pause the current TID. This stops packets from being transmitted
3243 * Since this is also called from upper layers as well as the driver,
3244 * it will get the TID lock.
3247 ath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid)
3250 ATH_TX_LOCK_ASSERT(sc);
3252 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n",
3253 __func__, tid->paused);
3257 * Unpause the current TID, and schedule it if needed.
3260 ath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid)
3262 ATH_TX_LOCK_ASSERT(sc);
3265 * There's some odd places where ath_tx_tid_resume() is called
3266 * when it shouldn't be; this works around that particular issue
3267 * until it's actually resolved.
3269 if (tid->paused == 0) {
3270 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
3271 "%s: %6D: paused=0?\n", __func__,
3272 tid->an->an_node.ni_macaddr, ":");
3277 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n",
3278 __func__, tid->paused);
3284 * Override the clrdmask configuration for the next frame
3285 * from this TID, just to get the ball rolling.
3287 ath_tx_set_clrdmask(sc, tid->an);
3289 if (tid->axq_depth == 0)
3292 /* XXX isfiltered shouldn't ever be 0 at this point */
3293 if (tid->isfiltered == 1) {
3294 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: filtered?!\n",
3299 ath_tx_tid_sched(sc, tid);
3302 * Queue the software TX scheduler.
3304 ath_tx_swq_kick(sc);
3308 * Add the given ath_buf to the TID filtered frame list.
3309 * This requires the TID be filtered.
3312 ath_tx_tid_filt_addbuf(struct ath_softc *sc, struct ath_tid *tid,
3316 ATH_TX_LOCK_ASSERT(sc);
3318 if (!tid->isfiltered)
3319 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: not filtered?!\n",
3322 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: bf=%p\n", __func__, bf);
3324 /* Set the retry bit and bump the retry counter */
3325 ath_tx_set_retry(sc, bf);
3326 sc->sc_stats.ast_tx_swfiltered++;
3328 ATH_TID_FILT_INSERT_TAIL(tid, bf, bf_list);
3332 * Handle a completed filtered frame from the given TID.
3333 * This just enables/pauses the filtered frame state if required
3334 * and appends the filtered frame to the filtered queue.
3337 ath_tx_tid_filt_comp_buf(struct ath_softc *sc, struct ath_tid *tid,
3341 ATH_TX_LOCK_ASSERT(sc);
3343 if (! tid->isfiltered) {
3344 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: filter transition\n",
3346 tid->isfiltered = 1;
3347 ath_tx_tid_pause(sc, tid);
3350 /* Add the frame to the filter queue */
3351 ath_tx_tid_filt_addbuf(sc, tid, bf);
3355 * Complete the filtered frame TX completion.
3357 * If there are no more frames in the hardware queue, unpause/unfilter
3358 * the TID if applicable. Otherwise we will wait for a node PS transition
3362 ath_tx_tid_filt_comp_complete(struct ath_softc *sc, struct ath_tid *tid)
3366 ATH_TX_LOCK_ASSERT(sc);
3368 if (tid->hwq_depth != 0)
3371 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: hwq=0, transition back\n",
3373 tid->isfiltered = 0;
3374 /* XXX ath_tx_tid_resume() also calls ath_tx_set_clrdmask()! */
3375 ath_tx_set_clrdmask(sc, tid->an);
3377 /* XXX this is really quite inefficient */
3378 while ((bf = ATH_TID_FILT_LAST(tid, ath_bufhead_s)) != NULL) {
3379 ATH_TID_FILT_REMOVE(tid, bf, bf_list);
3380 ATH_TID_INSERT_HEAD(tid, bf, bf_list);
3383 ath_tx_tid_resume(sc, tid);
3387 * Called when a single (aggregate or otherwise) frame is completed.
3389 * Returns 1 if the buffer could be added to the filtered list
3390 * (cloned or otherwise), 0 if the buffer couldn't be added to the
3391 * filtered list (failed clone; expired retry) and the caller should
3392 * free it and handle it like a failure (eg by sending a BAR.)
3395 ath_tx_tid_filt_comp_single(struct ath_softc *sc, struct ath_tid *tid,
3398 struct ath_buf *nbf;
3401 ATH_TX_LOCK_ASSERT(sc);
3404 * Don't allow a filtered frame to live forever.
3406 if (bf->bf_state.bfs_retries > SWMAX_RETRIES) {
3407 sc->sc_stats.ast_tx_swretrymax++;
3408 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3409 "%s: bf=%p, seqno=%d, exceeded retries\n",
3412 bf->bf_state.bfs_seqno);
3417 * A busy buffer can't be added to the retry list.
3418 * It needs to be cloned.
3420 if (bf->bf_flags & ATH_BUF_BUSY) {
3421 nbf = ath_tx_retry_clone(sc, tid->an, tid, bf);
3422 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3423 "%s: busy buffer clone: %p -> %p\n",
3430 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3431 "%s: busy buffer couldn't be cloned (%p)!\n",
3435 ath_tx_tid_filt_comp_buf(sc, tid, nbf);
3438 ath_tx_tid_filt_comp_complete(sc, tid);
3444 ath_tx_tid_filt_comp_aggr(struct ath_softc *sc, struct ath_tid *tid,
3445 struct ath_buf *bf_first, ath_bufhead *bf_q)
3447 struct ath_buf *bf, *bf_next, *nbf;
3449 ATH_TX_LOCK_ASSERT(sc);
3453 bf_next = bf->bf_next;
3454 bf->bf_next = NULL; /* Remove it from the aggr list */
3457 * Don't allow a filtered frame to live forever.
3459 if (bf->bf_state.bfs_retries > SWMAX_RETRIES) {
3460 sc->sc_stats.ast_tx_swretrymax++;
3461 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3462 "%s: bf=%p, seqno=%d, exceeded retries\n",
3465 bf->bf_state.bfs_seqno);
3466 TAILQ_INSERT_TAIL(bf_q, bf, bf_list);
3470 if (bf->bf_flags & ATH_BUF_BUSY) {
3471 nbf = ath_tx_retry_clone(sc, tid->an, tid, bf);
3472 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3473 "%s: busy buffer cloned: %p -> %p",
3480 * If the buffer couldn't be cloned, add it to bf_q;
3481 * the caller will free the buffer(s) as required.
3484 DPRINTF(sc, ATH_DEBUG_SW_TX_FILT,
3485 "%s: buffer couldn't be cloned! (%p)\n",
3487 TAILQ_INSERT_TAIL(bf_q, bf, bf_list);
3489 ath_tx_tid_filt_comp_buf(sc, tid, nbf);
3495 ath_tx_tid_filt_comp_complete(sc, tid);
3499 * Suspend the queue because we need to TX a BAR.
3502 ath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid)
3505 ATH_TX_LOCK_ASSERT(sc);
3507 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3508 "%s: tid=%d, bar_wait=%d, bar_tx=%d, called\n",
3514 /* We shouldn't be called when bar_tx is 1 */
3516 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3517 "%s: bar_tx is 1?!\n", __func__);
3520 /* If we've already been called, just be patient. */
3527 /* Only one pause, no matter how many frames fail */
3528 ath_tx_tid_pause(sc, tid);
3532 * We've finished with BAR handling - either we succeeded or
3533 * failed. Either way, unsuspend TX.
3536 ath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid)
3539 ATH_TX_LOCK_ASSERT(sc);
3541 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3542 "%s: %6D: TID=%d, called\n",
3544 tid->an->an_node.ni_macaddr,
3548 if (tid->bar_tx == 0 || tid->bar_wait == 0) {
3549 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3550 "%s: %6D: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
3551 __func__, tid->an->an_node.ni_macaddr, ":",
3552 tid->tid, tid->bar_tx, tid->bar_wait);
3555 tid->bar_tx = tid->bar_wait = 0;
3556 ath_tx_tid_resume(sc, tid);
3560 * Return whether we're ready to TX a BAR frame.
3562 * Requires the TID lock be held.
3565 ath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid)
3568 ATH_TX_LOCK_ASSERT(sc);
3570 if (tid->bar_wait == 0 || tid->hwq_depth > 0)
3573 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3574 "%s: %6D: TID=%d, bar ready\n",
3576 tid->an->an_node.ni_macaddr,
3584 * Check whether the current TID is ready to have a BAR
3585 * TXed and if so, do the TX.
3587 * Since the TID/TXQ lock can't be held during a call to
3588 * ieee80211_send_bar(), we have to do the dirty thing of unlocking it,
3589 * sending the BAR and locking it again.
3591 * Eventually, the code to send the BAR should be broken out
3592 * from this routine so the lock doesn't have to be reacquired
3593 * just to be immediately dropped by the caller.
3596 ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
3598 struct ieee80211_tx_ampdu *tap;
3600 ATH_TX_LOCK_ASSERT(sc);
3602 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3603 "%s: %6D: TID=%d, called\n",
3605 tid->an->an_node.ni_macaddr,
3609 tap = ath_tx_get_tx_tid(tid->an, tid->tid);
3612 * This is an error condition!
3614 if (tid->bar_wait == 0 || tid->bar_tx == 1) {
3615 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3616 "%s: %6D: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
3617 __func__, tid->an->an_node.ni_macaddr, ":",
3618 tid->tid, tid->bar_tx, tid->bar_wait);
3622 /* Don't do anything if we still have pending frames */
3623 if (tid->hwq_depth > 0) {
3624 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3625 "%s: %6D: TID=%d, hwq_depth=%d, waiting\n",
3627 tid->an->an_node.ni_macaddr,
3634 /* We're now about to TX */
3638 * Override the clrdmask configuration for the next frame,
3639 * just to get the ball rolling.
3641 ath_tx_set_clrdmask(sc, tid->an);
3644 * Calculate new BAW left edge, now that all frames have either
3645 * succeeded or failed.
3647 * XXX verify this is _actually_ the valid value to begin at!
3649 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3650 "%s: %6D: TID=%d, new BAW left edge=%d\n",
3652 tid->an->an_node.ni_macaddr,
3657 /* Try sending the BAR frame */
3658 /* We can't hold the lock here! */
3661 if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) {
3662 /* Success? Now we wait for notification that it's done */
3667 /* Failure? For now, warn loudly and continue */
3669 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
3670 "%s: %6D: TID=%d, failed to TX BAR, continue!\n",
3671 __func__, tid->an->an_node.ni_macaddr, ":",
3673 ath_tx_tid_bar_unsuspend(sc, tid);
3677 ath_tx_tid_drain_pkt(struct ath_softc *sc, struct ath_node *an,
3678 struct ath_tid *tid, ath_bufhead *bf_cq, struct ath_buf *bf)
3681 ATH_TX_LOCK_ASSERT(sc);
3684 * If the current TID is running AMPDU, update
3687 if (ath_tx_ampdu_running(sc, an, tid->tid) &&
3688 bf->bf_state.bfs_dobaw) {
3690 * Only remove the frame from the BAW if it's
3691 * been transmitted at least once; this means
3692 * the frame was in the BAW to begin with.
3694 if (bf->bf_state.bfs_retries > 0) {
3695 ath_tx_update_baw(sc, an, tid, bf);
3696 bf->bf_state.bfs_dobaw = 0;
3700 * This has become a non-fatal error now
3702 if (! bf->bf_state.bfs_addedbaw)
3703 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW
3704 "%s: wasn't added: seqno %d\n",
3705 __func__, SEQNO(bf->bf_state.bfs_seqno));
3709 /* Strip it out of an aggregate list if it was in one */
3712 /* Insert on the free queue to be freed by the caller */
3713 TAILQ_INSERT_TAIL(bf_cq, bf, bf_list);
3717 ath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an,
3718 const char *pfx, struct ath_tid *tid, struct ath_buf *bf)
3720 struct ieee80211_node *ni = &an->an_node;
3721 struct ath_txq *txq;
3722 struct ieee80211_tx_ampdu *tap;
3724 txq = sc->sc_ac2q[tid->ac];
3725 tap = ath_tx_get_tx_tid(an, tid->tid);
3727 DPRINTF(sc, ATH_DEBUG_SW_TX,
3728 "%s: %s: %6D: bf=%p: addbaw=%d, dobaw=%d, "
3729 "seqno=%d, retry=%d\n",
3735 bf->bf_state.bfs_addedbaw,
3736 bf->bf_state.bfs_dobaw,
3737 SEQNO(bf->bf_state.bfs_seqno),
3738 bf->bf_state.bfs_retries);
3739 DPRINTF(sc, ATH_DEBUG_SW_TX,
3740 "%s: %s: %6D: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n",
3748 txq->axq_aggr_depth);
3749 DPRINTF(sc, ATH_DEBUG_SW_TX,
3750 "%s: %s: %6D: bf=%p: tid txq_depth=%d hwq_depth=%d, bar_wait=%d, "
3761 DPRINTF(sc, ATH_DEBUG_SW_TX,
3762 "%s: %s: %6D: tid %d: "
3763 "sched=%d, paused=%d, "
3764 "incomp=%d, baw_head=%d, "
3765 "baw_tail=%d txa_start=%d, ni_txseqs=%d\n",
3771 tid->sched, tid->paused,
3772 tid->incomp, tid->baw_head,
3773 tid->baw_tail, tap == NULL ? -1 : tap->txa_start,
3774 ni->ni_txseqs[tid->tid]);
3776 /* XXX Dump the frame, see what it is? */
3777 ieee80211_dump_pkt(ni->ni_ic,
3778 mtod(bf->bf_m, const uint8_t *),
3779 bf->bf_m->m_len, 0, -1);
3783 * Free any packets currently pending in the software TX queue.
3785 * This will be called when a node is being deleted.
3787 * It can also be called on an active node during an interface
3788 * reset or state transition.
3790 * (From Linux/reference):
3792 * TODO: For frame(s) that are in the retry state, we will reuse the
3793 * sequence number(s) without setting the retry bit. The
3794 * alternative is to give up on these and BAR the receiver's window
3798 ath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an,
3799 struct ath_tid *tid, ath_bufhead *bf_cq)
3802 struct ieee80211_tx_ampdu *tap;
3803 struct ieee80211_node *ni = &an->an_node;
3806 tap = ath_tx_get_tx_tid(an, tid->tid);
3808 ATH_TX_LOCK_ASSERT(sc);
3810 /* Walk the queue, free frames */
3813 bf = ATH_TID_FIRST(tid);
3819 ath_tx_tid_drain_print(sc, an, "norm", tid, bf);
3823 ATH_TID_REMOVE(tid, bf, bf_list);
3824 ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf);
3827 /* And now, drain the filtered frame queue */
3830 bf = ATH_TID_FILT_FIRST(tid);
3835 ath_tx_tid_drain_print(sc, an, "filt", tid, bf);
3839 ATH_TID_FILT_REMOVE(tid, bf, bf_list);
3840 ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf);
3844 * Override the clrdmask configuration for the next frame
3845 * in case there is some future transmission, just to get
3848 * This won't hurt things if the TID is about to be freed.
3850 ath_tx_set_clrdmask(sc, tid->an);
3853 * Now that it's completed, grab the TID lock and update
3854 * the sequence number and BAW window.
3855 * Because sequence numbers have been assigned to frames
3856 * that haven't been sent yet, it's entirely possible
3857 * we'll be called with some pending frames that have not
3860 * The cleaner solution is to do the sequence number allocation
3861 * when the packet is first transmitted - and thus the "retries"
3862 * check above would be enough to update the BAW/seqno.
3865 /* But don't do it for non-QoS TIDs */
3868 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
3869 "%s: %6D: node %p: TID %d: sliding BAW left edge to %d\n",
3877 ni->ni_txseqs[tid->tid] = tap->txa_start;
3878 tid->baw_tail = tid->baw_head;
3883 * Reset the TID state. This must be only called once the node has
3884 * had its frames flushed from this TID, to ensure that no other
3885 * pause / unpause logic can kick in.
3888 ath_tx_tid_reset(struct ath_softc *sc, struct ath_tid *tid)
3892 tid->bar_wait = tid->bar_tx = tid->isfiltered = 0;
3893 tid->paused = tid->sched = tid->addba_tx_pending = 0;
3894 tid->incomp = tid->cleanup_inprogress = 0;
3898 * If we have a bar_wait set, we need to unpause the TID
3899 * here. Otherwise once cleanup has finished, the TID won't
3900 * have the right paused counter.
3902 * XXX I'm not going through resume here - I don't want the
3903 * node to be rescheuled just yet. This however should be
3906 if (tid->bar_wait) {
3907 if (tid->paused > 0) {
3913 * XXX same with a currently filtered TID.
3915 * Since this is being called during a flush, we assume that
3916 * the filtered frame list is actually empty.
3918 * XXX TODO: add in a check to ensure that the filtered queue
3919 * depth is actually 0!
3921 if (tid->isfiltered) {
3922 if (tid->paused > 0) {
3928 * Clear BAR, filtered frames, scheduled and ADDBA pending.
3929 * The TID may be going through cleanup from the last association
3930 * where things in the BAW are still in the hardware queue.
3934 tid->isfiltered = 0;
3936 tid->addba_tx_pending = 0;
3939 * XXX TODO: it may just be enough to walk the HWQs and mark
3940 * frames for that node as non-aggregate; or mark the ath_node
3941 * with something that indicates that aggregation is no longer
3942 * occuring. Then we can just toss the BAW complaints and
3943 * do a complete hard reset of state here - no pause, no
3944 * complete counter, etc.
3950 * Flush all software queued packets for the given node.
3952 * This occurs when a completion handler frees the last buffer
3953 * for a node, and the node is thus freed. This causes the node
3954 * to be cleaned up, which ends up calling ath_tx_node_flush.
3957 ath_tx_node_flush(struct ath_softc *sc, struct ath_node *an)
3965 ATH_KTR(sc, ATH_KTR_NODE, 1, "ath_tx_node_flush: flush node; ni=%p",
3969 DPRINTF(sc, ATH_DEBUG_NODE,
3970 "%s: %6D: flush; is_powersave=%d, stack_psq=%d, tim=%d, "
3971 "swq_depth=%d, clrdmask=%d, leak_count=%d\n",
3973 an->an_node.ni_macaddr,
3975 an->an_is_powersave,
3982 for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) {
3983 struct ath_tid *atid = &an->an_tid[tid];
3986 ath_tx_tid_drain(sc, an, atid, &bf_cq);
3988 /* Remove this tid from the list of active tids */
3989 ath_tx_tid_unsched(sc, atid);
3991 /* Reset the per-TID pause, BAR, etc state */
3992 ath_tx_tid_reset(sc, atid);
3996 * Clear global leak count
3998 an->an_leak_count = 0;
4001 /* Handle completed frames */
4002 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
4003 TAILQ_REMOVE(&bf_cq, bf, bf_list);
4004 ath_tx_default_comp(sc, bf, 0);
4009 * Drain all the software TXQs currently with traffic queued.
4012 ath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq)
4014 struct ath_tid *tid;
4022 * Iterate over all active tids for the given txq,
4023 * flushing and unsched'ing them
4025 while (! TAILQ_EMPTY(&txq->axq_tidq)) {
4026 tid = TAILQ_FIRST(&txq->axq_tidq);
4027 ath_tx_tid_drain(sc, tid->an, tid, &bf_cq);
4028 ath_tx_tid_unsched(sc, tid);
4033 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
4034 TAILQ_REMOVE(&bf_cq, bf, bf_list);
4035 ath_tx_default_comp(sc, bf, 0);
4040 * Handle completion of non-aggregate session frames.
4042 * This (currently) doesn't implement software retransmission of
4043 * non-aggregate frames!
4045 * Software retransmission of non-aggregate frames needs to obey
4046 * the strict sequence number ordering, and drop any frames that
4049 * For now, filtered frames and frame transmission will cause
4050 * all kinds of issues. So we don't support them.
4052 * So anyone queuing frames via ath_tx_normal_xmit() or
4053 * ath_tx_hw_queue_norm() must override and set CLRDMASK.
4056 ath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail)
4058 struct ieee80211_node *ni = bf->bf_node;
4059 struct ath_node *an = ATH_NODE(ni);
4060 int tid = bf->bf_state.bfs_tid;
4061 struct ath_tid *atid = &an->an_tid[tid];
4062 struct ath_tx_status *ts = &bf->bf_status.ds_txstat;
4064 /* The TID state is protected behind the TXQ lock */
4067 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n",
4068 __func__, bf, fail, atid->hwq_depth - 1);
4074 * If the frame was filtered, stick it on the filter frame
4075 * queue and complain about it. It shouldn't happen!
4077 if ((ts->ts_status & HAL_TXERR_FILT) ||
4078 (ts->ts_status != 0 && atid->isfiltered)) {
4079 DPRINTF(sc, ATH_DEBUG_SW_TX,
4080 "%s: isfiltered=%d, ts_status=%d: huh?\n",
4084 ath_tx_tid_filt_comp_buf(sc, atid, bf);
4087 if (atid->isfiltered)
4088 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: filtered?!\n", __func__);
4089 if (atid->hwq_depth < 0)
4090 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: hwq_depth < 0: %d\n",
4091 __func__, atid->hwq_depth);
4094 * If the queue is filtered, potentially mark it as complete
4095 * and reschedule it as needed.
4097 * This is required as there may be a subsequent TX descriptor
4098 * for this end-node that has CLRDMASK set, so it's quite possible
4099 * that a filtered frame will be followed by a non-filtered
4100 * (complete or otherwise) frame.
4102 * XXX should we do this before we complete the frame?
4104 if (atid->isfiltered)
4105 ath_tx_tid_filt_comp_complete(sc, atid);
4109 * punt to rate control if we're not being cleaned up
4110 * during a hw queue drain and the frame wanted an ACK.
4112 if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0))
4113 ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc,
4114 ts, bf->bf_state.bfs_pktlen,
4115 1, (ts->ts_status == 0) ? 0 : 1);
4117 ath_tx_default_comp(sc, bf, fail);
4121 * Handle cleanup of aggregate session packets that aren't
4124 * There's no need to update the BAW here - the session is being
4128 ath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf)
4130 struct ieee80211_node *ni = bf->bf_node;
4131 struct ath_node *an = ATH_NODE(ni);
4132 int tid = bf->bf_state.bfs_tid;
4133 struct ath_tid *atid = &an->an_tid[tid];
4135 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n",
4136 __func__, tid, atid->incomp);
4140 if (atid->incomp == 0) {
4141 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
4142 "%s: TID %d: cleaned up! resume!\n",
4144 atid->cleanup_inprogress = 0;
4145 ath_tx_tid_resume(sc, atid);
4149 ath_tx_default_comp(sc, bf, 0);
4153 * Performs transmit side cleanup when TID changes from aggregated to
4156 * - Discard all retry frames from the s/w queue.
4157 * - Fix the tx completion function for all buffers in s/w queue.
4158 * - Count the number of unacked frames, and let transmit completion
4161 * The caller is responsible for pausing the TID and unpausing the
4162 * TID if no cleanup was required. Otherwise the cleanup path will
4163 * unpause the TID once the last hardware queued frame is completed.
4166 ath_tx_tid_cleanup(struct ath_softc *sc, struct ath_node *an, int tid,
4169 struct ath_tid *atid = &an->an_tid[tid];
4170 struct ieee80211_tx_ampdu *tap;
4171 struct ath_buf *bf, *bf_next;
4173 ATH_TX_LOCK_ASSERT(sc);
4175 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
4176 "%s: TID %d: called\n", __func__, tid);
4179 * Move the filtered frames to the TX queue, before
4180 * we run off and discard/process things.
4182 /* XXX this is really quite inefficient */
4183 while ((bf = ATH_TID_FILT_LAST(atid, ath_bufhead_s)) != NULL) {
4184 ATH_TID_FILT_REMOVE(atid, bf, bf_list);
4185 ATH_TID_INSERT_HEAD(atid, bf, bf_list);
4189 * Update the frames in the software TX queue:
4191 * + Discard retry frames in the queue
4192 * + Fix the completion function to be non-aggregate
4194 bf = ATH_TID_FIRST(atid);
4196 if (bf->bf_state.bfs_isretried) {
4197 bf_next = TAILQ_NEXT(bf, bf_list);
4198 ATH_TID_REMOVE(atid, bf, bf_list);
4199 if (bf->bf_state.bfs_dobaw) {
4200 ath_tx_update_baw(sc, an, atid, bf);
4201 if (!bf->bf_state.bfs_addedbaw)
4202 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
4203 "%s: wasn't added: seqno %d\n",
4205 SEQNO(bf->bf_state.bfs_seqno));
4207 bf->bf_state.bfs_dobaw = 0;
4209 * Call the default completion handler with "fail" just
4210 * so upper levels are suitably notified about this.
4212 TAILQ_INSERT_TAIL(bf_cq, bf, bf_list);
4216 /* Give these the default completion handler */
4217 bf->bf_comp = ath_tx_normal_comp;
4218 bf = TAILQ_NEXT(bf, bf_list);
4222 * Calculate what hardware-queued frames exist based
4223 * on the current BAW size. Ie, what frames have been
4224 * added to the TX hardware queue for this TID but
4227 tap = ath_tx_get_tx_tid(an, tid);
4228 /* Need the lock - fiddling with BAW */
4229 while (atid->baw_head != atid->baw_tail) {
4230 if (atid->tx_buf[atid->baw_head]) {
4232 atid->cleanup_inprogress = 1;
4233 atid->tx_buf[atid->baw_head] = NULL;
4235 INCR(atid->baw_head, ATH_TID_MAX_BUFS);
4236 INCR(tap->txa_start, IEEE80211_SEQ_RANGE);
4239 if (atid->cleanup_inprogress)
4240 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
4241 "%s: TID %d: cleanup needed: %d packets\n",
4242 __func__, tid, atid->incomp);
4244 /* Owner now must free completed frames */
4247 static struct ath_buf *
4248 ath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an,
4249 struct ath_tid *tid, struct ath_buf *bf)
4251 struct ath_buf *nbf;
4255 * Clone the buffer. This will handle the dma unmap and
4256 * copy the node reference to the new buffer. If this
4257 * works out, 'bf' will have no DMA mapping, no mbuf
4258 * pointer and no node reference.
4260 nbf = ath_buf_clone(sc, bf);
4263 DPRINTF(sc, ATH_DEBUG_XMIT, "%s: ATH_BUF_BUSY; cloning\n",
4268 /* Failed to clone */
4269 DPRINTF(sc, ATH_DEBUG_XMIT,
4270 "%s: failed to clone a busy buffer\n",
4275 /* Setup the dma for the new buffer */
4276 error = ath_tx_dmasetup(sc, nbf, nbf->bf_m);
4278 DPRINTF(sc, ATH_DEBUG_XMIT,
4279 "%s: failed to setup dma for clone\n",
4282 * Put this at the head of the list, not tail;
4283 * that way it doesn't interfere with the
4284 * busy buffer logic (which uses the tail of
4288 ath_returnbuf_head(sc, nbf);
4289 ATH_TXBUF_UNLOCK(sc);
4293 /* Update BAW if required, before we free the original buf */
4294 if (bf->bf_state.bfs_dobaw)
4295 ath_tx_switch_baw_buf(sc, an, tid, bf, nbf);
4297 /* Free original buffer; return new buffer */
4298 ath_freebuf(sc, bf);
4304 * Handle retrying an unaggregate frame in an aggregate
4307 * If too many retries occur, pause the TID, wait for
4308 * any further retransmits (as there's no reason why
4309 * non-aggregate frames in an aggregate session are
4310 * transmitted in-order; they just have to be in-BAW)
4311 * and then queue a BAR.
4314 ath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf)
4316 struct ieee80211_node *ni = bf->bf_node;
4317 struct ath_node *an = ATH_NODE(ni);
4318 int tid = bf->bf_state.bfs_tid;
4319 struct ath_tid *atid = &an->an_tid[tid];
4320 struct ieee80211_tx_ampdu *tap;
4324 tap = ath_tx_get_tx_tid(an, tid);
4327 * If the buffer is marked as busy, we can't directly
4328 * reuse it. Instead, try to clone the buffer.
4329 * If the clone is successful, recycle the old buffer.
4330 * If the clone is unsuccessful, set bfs_retries to max
4331 * to force the next bit of code to free the buffer
4334 if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) &&
4335 (bf->bf_flags & ATH_BUF_BUSY)) {
4336 struct ath_buf *nbf;
4337 nbf = ath_tx_retry_clone(sc, an, atid, bf);
4339 /* bf has been freed at this point */
4342 bf->bf_state.bfs_retries = SWMAX_RETRIES + 1;
4345 if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) {
4346 DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES,
4347 "%s: exceeded retries; seqno %d\n",
4348 __func__, SEQNO(bf->bf_state.bfs_seqno));
4349 sc->sc_stats.ast_tx_swretrymax++;
4351 /* Update BAW anyway */
4352 if (bf->bf_state.bfs_dobaw) {
4353 ath_tx_update_baw(sc, an, atid, bf);
4354 if (! bf->bf_state.bfs_addedbaw)
4355 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
4356 "%s: wasn't added: seqno %d\n",
4357 __func__, SEQNO(bf->bf_state.bfs_seqno));
4359 bf->bf_state.bfs_dobaw = 0;
4361 /* Suspend the TX queue and get ready to send the BAR */
4362 ath_tx_tid_bar_suspend(sc, atid);
4364 /* Send the BAR if there are no other frames waiting */
4365 if (ath_tx_tid_bar_tx_ready(sc, atid))
4366 ath_tx_tid_bar_tx(sc, atid);
4370 /* Free buffer, bf is free after this call */
4371 ath_tx_default_comp(sc, bf, 0);
4376 * This increments the retry counter as well as
4377 * sets the retry flag in the ath_buf and packet
4380 ath_tx_set_retry(sc, bf);
4381 sc->sc_stats.ast_tx_swretries++;
4384 * Insert this at the head of the queue, so it's
4385 * retried before any current/subsequent frames.
4387 ATH_TID_INSERT_HEAD(atid, bf, bf_list);
4388 ath_tx_tid_sched(sc, atid);
4389 /* Send the BAR if there are no other frames waiting */
4390 if (ath_tx_tid_bar_tx_ready(sc, atid))
4391 ath_tx_tid_bar_tx(sc, atid);
4397 * Common code for aggregate excessive retry/subframe retry.
4398 * If retrying, queues buffers to bf_q. If not, frees the
4401 * XXX should unify this with ath_tx_aggr_retry_unaggr()
4404 ath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf,
4407 struct ieee80211_node *ni = bf->bf_node;
4408 struct ath_node *an = ATH_NODE(ni);
4409 int tid = bf->bf_state.bfs_tid;
4410 struct ath_tid *atid = &an->an_tid[tid];
4412 ATH_TX_LOCK_ASSERT(sc);
4414 /* XXX clr11naggr should be done for all subframes */
4415 ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc);
4416 ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0);
4418 /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */
4421 * If the buffer is marked as busy, we can't directly
4422 * reuse it. Instead, try to clone the buffer.
4423 * If the clone is successful, recycle the old buffer.
4424 * If the clone is unsuccessful, set bfs_retries to max
4425 * to force the next bit of code to free the buffer
4428 if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) &&
4429 (bf->bf_flags & ATH_BUF_BUSY)) {
4430 struct ath_buf *nbf;
4431 nbf = ath_tx_retry_clone(sc, an, atid, bf);
4433 /* bf has been freed at this point */
4436 bf->bf_state.bfs_retries = SWMAX_RETRIES + 1;
4439 if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) {
4440 sc->sc_stats.ast_tx_swretrymax++;
4441 DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES,
4442 "%s: max retries: seqno %d\n",
4443 __func__, SEQNO(bf->bf_state.bfs_seqno));
4444 ath_tx_update_baw(sc, an, atid, bf);
4445 if (!bf->bf_state.bfs_addedbaw)
4446 DPRINTF(sc, ATH_DEBUG_SW_TX_BAW,
4447 "%s: wasn't added: seqno %d\n",
4448 __func__, SEQNO(bf->bf_state.bfs_seqno));
4449 bf->bf_state.bfs_dobaw = 0;
4453 ath_tx_set_retry(sc, bf);
4454 sc->sc_stats.ast_tx_swretries++;
4455 bf->bf_next = NULL; /* Just to make sure */
4457 /* Clear the aggregate state */
4458 bf->bf_state.bfs_aggr = 0;
4459 bf->bf_state.bfs_ndelim = 0; /* ??? needed? */
4460 bf->bf_state.bfs_nframes = 1;
4462 TAILQ_INSERT_TAIL(bf_q, bf, bf_list);
4467 * error pkt completion for an aggregate destination
4470 ath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first,
4471 struct ath_tid *tid)
4473 struct ieee80211_node *ni = bf_first->bf_node;
4474 struct ath_node *an = ATH_NODE(ni);
4475 struct ath_buf *bf_next, *bf;
4478 struct ieee80211_tx_ampdu *tap;
4485 * Update rate control - all frames have failed.
4487 * XXX use the length in the first frame in the series;
4488 * XXX just so things are consistent for now.
4490 ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc,
4491 &bf_first->bf_status.ds_txstat,
4492 bf_first->bf_state.bfs_pktlen,
4493 bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes);
4496 tap = ath_tx_get_tx_tid(an, tid->tid);
4497 sc->sc_stats.ast_tx_aggr_failall++;
4499 /* Retry all subframes */
4502 bf_next = bf->bf_next;
4503 bf->bf_next = NULL; /* Remove it from the aggr list */
4504 sc->sc_stats.ast_tx_aggr_fail++;
4505 if (ath_tx_retry_subframe(sc, bf, &bf_q)) {
4508 TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list);
4513 /* Prepend all frames to the beginning of the queue */
4514 while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) {
4515 TAILQ_REMOVE(&bf_q, bf, bf_list);
4516 ATH_TID_INSERT_HEAD(tid, bf, bf_list);
4520 * Schedule the TID to be re-tried.
4522 ath_tx_tid_sched(sc, tid);
4525 * send bar if we dropped any frames
4527 * Keep the txq lock held for now, as we need to ensure
4528 * that ni_txseqs[] is consistent (as it's being updated
4529 * in the ifnet TX context or raw TX context.)
4532 /* Suspend the TX queue and get ready to send the BAR */
4533 ath_tx_tid_bar_suspend(sc, tid);
4537 * Send BAR if required
4539 if (ath_tx_tid_bar_tx_ready(sc, tid))
4540 ath_tx_tid_bar_tx(sc, tid);
4544 /* Complete frames which errored out */
4545 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
4546 TAILQ_REMOVE(&bf_cq, bf, bf_list);
4547 ath_tx_default_comp(sc, bf, 0);
4552 * Handle clean-up of packets from an aggregate list.
4554 * There's no need to update the BAW here - the session is being
4558 ath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first)
4560 struct ath_buf *bf, *bf_next;
4561 struct ieee80211_node *ni = bf_first->bf_node;
4562 struct ath_node *an = ATH_NODE(ni);
4563 int tid = bf_first->bf_state.bfs_tid;
4564 struct ath_tid *atid = &an->an_tid[tid];
4575 if (atid->incomp == 0) {
4576 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
4577 "%s: TID %d: cleaned up! resume!\n",
4579 atid->cleanup_inprogress = 0;
4580 ath_tx_tid_resume(sc, atid);
4583 /* Send BAR if required */
4584 /* XXX why would we send a BAR when transitioning to non-aggregation? */
4586 * XXX TODO: we should likely just tear down the BAR state here,
4587 * rather than sending a BAR.
4589 if (ath_tx_tid_bar_tx_ready(sc, atid))
4590 ath_tx_tid_bar_tx(sc, atid);
4594 /* Handle frame completion */
4597 bf_next = bf->bf_next;
4598 ath_tx_default_comp(sc, bf, 1);
4604 * Handle completion of an set of aggregate frames.
4606 * Note: the completion handler is the last descriptor in the aggregate,
4607 * not the last descriptor in the first frame.
4610 ath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first,
4613 //struct ath_desc *ds = bf->bf_lastds;
4614 struct ieee80211_node *ni = bf_first->bf_node;
4615 struct ath_node *an = ATH_NODE(ni);
4616 int tid = bf_first->bf_state.bfs_tid;
4617 struct ath_tid *atid = &an->an_tid[tid];
4618 struct ath_tx_status ts;
4619 struct ieee80211_tx_ampdu *tap;
4625 struct ath_buf *bf, *bf_next;
4628 int nframes = 0, nbad = 0, nf;
4630 /* XXX there's too much on the stack? */
4631 struct ath_rc_series rc[ATH_RC_NUM];
4634 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n",
4635 __func__, atid->hwq_depth);
4638 * Take a copy; this may be needed -after- bf_first
4639 * has been completed and freed.
4641 ts = bf_first->bf_status.ds_txstat;
4646 /* The TID state is kept behind the TXQ lock */
4650 if (atid->hwq_depth < 0)
4651 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: hwq_depth < 0: %d\n",
4652 __func__, atid->hwq_depth);
4655 * If the TID is filtered, handle completing the filter
4656 * transition before potentially kicking it to the cleanup
4659 * XXX this is duplicate work, ew.
4661 if (atid->isfiltered)
4662 ath_tx_tid_filt_comp_complete(sc, atid);
4665 * Punt cleanup to the relevant function, not our problem now
4667 if (atid->cleanup_inprogress) {
4668 if (atid->isfiltered)
4669 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4670 "%s: isfiltered=1, normal_comp?\n",
4673 ath_tx_comp_cleanup_aggr(sc, bf_first);
4678 * If the frame is filtered, transition to filtered frame
4679 * mode and add this to the filtered frame list.
4681 * XXX TODO: figure out how this interoperates with
4682 * BAR, pause and cleanup states.
4684 if ((ts.ts_status & HAL_TXERR_FILT) ||
4685 (ts.ts_status != 0 && atid->isfiltered)) {
4687 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4688 "%s: isfiltered=1, fail=%d\n", __func__, fail);
4689 ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq);
4691 /* Remove from BAW */
4692 TAILQ_FOREACH(bf, &bf_cq, bf_list) {
4693 if (bf->bf_state.bfs_addedbaw)
4695 if (bf->bf_state.bfs_dobaw) {
4696 ath_tx_update_baw(sc, an, atid, bf);
4697 if (!bf->bf_state.bfs_addedbaw)
4698 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4699 "%s: wasn't added: seqno %d\n",
4701 SEQNO(bf->bf_state.bfs_seqno));
4703 bf->bf_state.bfs_dobaw = 0;
4706 * If any intermediate frames in the BAW were dropped when
4707 * handling filtering things, send a BAR.
4710 ath_tx_tid_bar_suspend(sc, atid);
4713 * Finish up by sending a BAR if required and freeing
4714 * the frames outside of the TX lock.
4716 goto finish_send_bar;
4720 * XXX for now, use the first frame in the aggregate for
4721 * XXX rate control completion; it's at least consistent.
4723 pktlen = bf_first->bf_state.bfs_pktlen;
4726 * Handle errors first!
4728 * Here, handle _any_ error as a "exceeded retries" error.
4729 * Later on (when filtered frames are to be specially handled)
4730 * it'll have to be expanded.
4733 if (ts.ts_status & HAL_TXERR_XRETRY) {
4735 if (ts.ts_status != 0) {
4737 ath_tx_comp_aggr_error(sc, bf_first, atid);
4741 tap = ath_tx_get_tx_tid(an, tid);
4744 * extract starting sequence and block-ack bitmap
4746 /* XXX endian-ness of seq_st, ba? */
4747 seq_st = ts.ts_seqnum;
4748 hasba = !! (ts.ts_flags & HAL_TX_BA);
4749 tx_ok = (ts.ts_status == 0);
4750 isaggr = bf_first->bf_state.bfs_aggr;
4751 ba[0] = ts.ts_ba_low;
4752 ba[1] = ts.ts_ba_high;
4755 * Copy the TX completion status and the rate control
4756 * series from the first descriptor, as it may be freed
4757 * before the rate control code can get its grubby fingers
4760 memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc));
4762 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4763 "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, "
4764 "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n",
4765 __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags,
4766 isaggr, seq_st, hasba, ba[0], ba[1]);
4769 * The reference driver doesn't do this; it simply ignores
4770 * this check in its entirety.
4772 * I've seen this occur when using iperf to send traffic
4773 * out tid 1 - the aggregate frames are all marked as TID 1,
4774 * but the TXSTATUS has TID=0. So, let's just ignore this
4778 /* Occasionally, the MAC sends a tx status for the wrong TID. */
4779 if (tid != ts.ts_tid) {
4780 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: tid %d != hw tid %d\n",
4781 __func__, tid, ts.ts_tid);
4786 /* AR5416 BA bug; this requires an interface reset */
4787 if (isaggr && tx_ok && (! hasba)) {
4788 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4789 "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, "
4791 __func__, hasba, tx_ok, isaggr, seq_st);
4792 /* XXX TODO: schedule an interface reset */
4794 ath_printtxbuf(sc, bf_first,
4795 sc->sc_ac2q[atid->ac]->axq_qnum, 0, 0);
4800 * Walk the list of frames, figure out which ones were correctly
4801 * sent and which weren't.
4804 nf = bf_first->bf_state.bfs_nframes;
4806 /* bf_first is going to be invalid once this list is walked */
4810 * Walk the list of completed frames and determine
4811 * which need to be completed and which need to be
4814 * For completed frames, the completion functions need
4815 * to be called at the end of this function as the last
4816 * node reference may free the node.
4818 * Finally, since the TXQ lock can't be held during the
4819 * completion callback (to avoid lock recursion),
4820 * the completion calls have to be done outside of the
4825 ba_index = ATH_BA_INDEX(seq_st,
4826 SEQNO(bf->bf_state.bfs_seqno));
4827 bf_next = bf->bf_next;
4828 bf->bf_next = NULL; /* Remove it from the aggr list */
4830 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4831 "%s: checking bf=%p seqno=%d; ack=%d\n",
4832 __func__, bf, SEQNO(bf->bf_state.bfs_seqno),
4833 ATH_BA_ISSET(ba, ba_index));
4835 if (tx_ok && ATH_BA_ISSET(ba, ba_index)) {
4836 sc->sc_stats.ast_tx_aggr_ok++;
4837 ath_tx_update_baw(sc, an, atid, bf);
4838 bf->bf_state.bfs_dobaw = 0;
4839 if (!bf->bf_state.bfs_addedbaw)
4840 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4841 "%s: wasn't added: seqno %d\n",
4842 __func__, SEQNO(bf->bf_state.bfs_seqno));
4844 TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list);
4846 sc->sc_stats.ast_tx_aggr_fail++;
4847 if (ath_tx_retry_subframe(sc, bf, &bf_q)) {
4850 TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list);
4858 * Now that the BAW updates have been done, unlock
4860 * txseq is grabbed before the lock is released so we
4861 * have a consistent view of what -was- in the BAW.
4862 * Anything after this point will not yet have been
4865 txseq = tap->txa_start;
4869 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4870 "%s: num frames seen=%d; bf nframes=%d\n",
4871 __func__, nframes, nf);
4874 * Now we know how many frames were bad, call the rate
4878 ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes,
4882 * send bar if we dropped any frames
4885 /* Suspend the TX queue and get ready to send the BAR */
4887 ath_tx_tid_bar_suspend(sc, atid);
4891 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
4892 "%s: txa_start now %d\n", __func__, tap->txa_start);
4896 /* Prepend all frames to the beginning of the queue */
4897 while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) {
4898 TAILQ_REMOVE(&bf_q, bf, bf_list);
4899 ATH_TID_INSERT_HEAD(atid, bf, bf_list);
4903 * Reschedule to grab some further frames.
4905 ath_tx_tid_sched(sc, atid);
4908 * If the queue is filtered, re-schedule as required.
4910 * This is required as there may be a subsequent TX descriptor
4911 * for this end-node that has CLRDMASK set, so it's quite possible
4912 * that a filtered frame will be followed by a non-filtered
4913 * (complete or otherwise) frame.
4915 * XXX should we do this before we complete the frame?
4917 if (atid->isfiltered)
4918 ath_tx_tid_filt_comp_complete(sc, atid);
4923 * Send BAR if required
4925 if (ath_tx_tid_bar_tx_ready(sc, atid))
4926 ath_tx_tid_bar_tx(sc, atid);
4930 /* Do deferred completion */
4931 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
4932 TAILQ_REMOVE(&bf_cq, bf, bf_list);
4933 ath_tx_default_comp(sc, bf, 0);
4938 * Handle completion of unaggregated frames in an ADDBA
4941 * Fail is set to 1 if the entry is being freed via a call to
4942 * ath_tx_draintxq().
4945 ath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail)
4947 struct ieee80211_node *ni = bf->bf_node;
4948 struct ath_node *an = ATH_NODE(ni);
4949 int tid = bf->bf_state.bfs_tid;
4950 struct ath_tid *atid = &an->an_tid[tid];
4951 struct ath_tx_status ts;
4955 * Take a copy of this; filtering/cloning the frame may free the
4958 ts = bf->bf_status.ds_txstat;
4961 * Update rate control status here, before we possibly
4962 * punt to retry or cleanup.
4964 * Do it outside of the TXQ lock.
4966 if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0))
4967 ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc,
4968 &bf->bf_status.ds_txstat,
4969 bf->bf_state.bfs_pktlen,
4970 1, (ts.ts_status == 0) ? 0 : 1);
4973 * This is called early so atid->hwq_depth can be tracked.
4974 * This unfortunately means that it's released and regrabbed
4975 * during retry and cleanup. That's rather inefficient.
4979 if (tid == IEEE80211_NONQOS_TID)
4980 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=16!\n", __func__);
4982 DPRINTF(sc, ATH_DEBUG_SW_TX,
4983 "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n",
4984 __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth,
4985 SEQNO(bf->bf_state.bfs_seqno));
4988 if (atid->hwq_depth < 0)
4989 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: hwq_depth < 0: %d\n",
4990 __func__, atid->hwq_depth);
4993 * If the TID is filtered, handle completing the filter
4994 * transition before potentially kicking it to the cleanup
4997 if (atid->isfiltered)
4998 ath_tx_tid_filt_comp_complete(sc, atid);
5001 * If a cleanup is in progress, punt to comp_cleanup;
5002 * rather than handling it here. It's thus their
5003 * responsibility to clean up, call the completion
5004 * function in net80211, etc.
5006 if (atid->cleanup_inprogress) {
5007 if (atid->isfiltered)
5008 DPRINTF(sc, ATH_DEBUG_SW_TX,
5009 "%s: isfiltered=1, normal_comp?\n",
5012 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n",
5014 ath_tx_comp_cleanup_unaggr(sc, bf);
5019 * XXX TODO: how does cleanup, BAR and filtered frame handling
5022 * If the frame is filtered OR if it's any failure but
5023 * the TID is filtered, the frame must be added to the
5024 * filtered frame list.
5026 * However - a busy buffer can't be added to the filtered
5027 * list as it will end up being recycled without having
5028 * been made available for the hardware.
5030 if ((ts.ts_status & HAL_TXERR_FILT) ||
5031 (ts.ts_status != 0 && atid->isfiltered)) {
5035 DPRINTF(sc, ATH_DEBUG_SW_TX,
5036 "%s: isfiltered=1, fail=%d\n",
5038 freeframe = ath_tx_tid_filt_comp_single(sc, atid, bf);
5040 /* Remove from BAW */
5041 if (bf->bf_state.bfs_addedbaw)
5043 if (bf->bf_state.bfs_dobaw) {
5044 ath_tx_update_baw(sc, an, atid, bf);
5045 if (!bf->bf_state.bfs_addedbaw)
5046 DPRINTF(sc, ATH_DEBUG_SW_TX,
5047 "%s: wasn't added: seqno %d\n",
5048 __func__, SEQNO(bf->bf_state.bfs_seqno));
5050 bf->bf_state.bfs_dobaw = 0;
5054 * If the frame couldn't be filtered, treat it as a drop and
5055 * prepare to send a BAR.
5057 if (freeframe && drops)
5058 ath_tx_tid_bar_suspend(sc, atid);
5061 * Send BAR if required
5063 if (ath_tx_tid_bar_tx_ready(sc, atid))
5064 ath_tx_tid_bar_tx(sc, atid);
5068 * If freeframe is set, then the frame couldn't be
5069 * cloned and bf is still valid. Just complete/free it.
5072 ath_tx_default_comp(sc, bf, fail);
5078 * Don't bother with the retry check if all frames
5079 * are being failed (eg during queue deletion.)
5082 if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) {
5084 if (fail == 0 && ts.ts_status != 0) {
5086 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n",
5088 ath_tx_aggr_retry_unaggr(sc, bf);
5092 /* Success? Complete */
5093 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n",
5094 __func__, tid, SEQNO(bf->bf_state.bfs_seqno));
5095 if (bf->bf_state.bfs_dobaw) {
5096 ath_tx_update_baw(sc, an, atid, bf);
5097 bf->bf_state.bfs_dobaw = 0;
5098 if (!bf->bf_state.bfs_addedbaw)
5099 DPRINTF(sc, ATH_DEBUG_SW_TX,
5100 "%s: wasn't added: seqno %d\n",
5101 __func__, SEQNO(bf->bf_state.bfs_seqno));
5105 * If the queue is filtered, re-schedule as required.
5107 * This is required as there may be a subsequent TX descriptor
5108 * for this end-node that has CLRDMASK set, so it's quite possible
5109 * that a filtered frame will be followed by a non-filtered
5110 * (complete or otherwise) frame.
5112 * XXX should we do this before we complete the frame?
5114 if (atid->isfiltered)
5115 ath_tx_tid_filt_comp_complete(sc, atid);
5118 * Send BAR if required
5120 if (ath_tx_tid_bar_tx_ready(sc, atid))
5121 ath_tx_tid_bar_tx(sc, atid);
5125 ath_tx_default_comp(sc, bf, fail);
5126 /* bf is freed at this point */
5130 ath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail)
5132 if (bf->bf_state.bfs_aggr)
5133 ath_tx_aggr_comp_aggr(sc, bf, fail);
5135 ath_tx_aggr_comp_unaggr(sc, bf, fail);
5139 * Schedule some packets from the given node/TID to the hardware.
5141 * This is the aggregate version.
5144 ath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an,
5145 struct ath_tid *tid)
5148 struct ath_txq *txq = sc->sc_ac2q[tid->ac];
5149 struct ieee80211_tx_ampdu *tap;
5150 ATH_AGGR_STATUS status;
5153 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid);
5154 ATH_TX_LOCK_ASSERT(sc);
5157 * XXX TODO: If we're called for a queue that we're leaking frames to,
5158 * ensure we only leak one.
5161 tap = ath_tx_get_tx_tid(an, tid->tid);
5163 if (tid->tid == IEEE80211_NONQOS_TID)
5164 DPRINTF(sc, ATH_DEBUG_SW_TX,
5165 "%s: called for TID=NONQOS_TID?\n", __func__);
5168 status = ATH_AGGR_DONE;
5171 * If the upper layer has paused the TID, don't
5172 * queue any further packets.
5174 * This can also occur from the completion task because
5175 * of packet loss; but as its serialised with this code,
5176 * it won't "appear" half way through queuing packets.
5178 if (! ath_tx_tid_can_tx_or_sched(sc, tid))
5181 bf = ATH_TID_FIRST(tid);
5187 * If the packet doesn't fall within the BAW (eg a NULL
5188 * data frame), schedule it directly; continue.
5190 if (! bf->bf_state.bfs_dobaw) {
5191 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
5192 "%s: non-baw packet\n",
5194 ATH_TID_REMOVE(tid, bf, bf_list);
5196 if (bf->bf_state.bfs_nframes > 1)
5197 DPRINTF(sc, ATH_DEBUG_SW_TX,
5198 "%s: aggr=%d, nframes=%d\n",
5200 bf->bf_state.bfs_aggr,
5201 bf->bf_state.bfs_nframes);
5204 * This shouldn't happen - such frames shouldn't
5205 * ever have been queued as an aggregate in the
5206 * first place. However, make sure the fields
5207 * are correctly setup just to be totally sure.
5209 bf->bf_state.bfs_aggr = 0;
5210 bf->bf_state.bfs_nframes = 1;
5212 /* Update CLRDMASK just before this frame is queued */
5213 ath_tx_update_clrdmask(sc, tid, bf);
5215 ath_tx_do_ratelookup(sc, bf);
5216 ath_tx_calc_duration(sc, bf);
5217 ath_tx_calc_protection(sc, bf);
5218 ath_tx_set_rtscts(sc, bf);
5219 ath_tx_rate_fill_rcflags(sc, bf);
5220 ath_tx_setds(sc, bf);
5221 ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc);
5223 sc->sc_aggr_stats.aggr_nonbaw_pkt++;
5225 /* Queue the packet; continue */
5232 * Do a rate control lookup on the first frame in the
5233 * list. The rate control code needs that to occur
5234 * before it can determine whether to TX.
5235 * It's inaccurate because the rate control code doesn't
5236 * really "do" aggregate lookups, so it only considers
5237 * the size of the first frame.
5239 ath_tx_do_ratelookup(sc, bf);
5240 bf->bf_state.bfs_rc[3].rix = 0;
5241 bf->bf_state.bfs_rc[3].tries = 0;
5243 ath_tx_calc_duration(sc, bf);
5244 ath_tx_calc_protection(sc, bf);
5246 ath_tx_set_rtscts(sc, bf);
5247 ath_tx_rate_fill_rcflags(sc, bf);
5249 status = ath_tx_form_aggr(sc, an, tid, &bf_q);
5251 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
5252 "%s: ath_tx_form_aggr() status=%d\n", __func__, status);
5255 * No frames to be picked up - out of BAW
5257 if (TAILQ_EMPTY(&bf_q))
5261 * This assumes that the descriptor list in the ath_bufhead
5262 * are already linked together via bf_next pointers.
5264 bf = TAILQ_FIRST(&bf_q);
5266 if (status == ATH_AGGR_8K_LIMITED)
5267 sc->sc_aggr_stats.aggr_rts_aggr_limited++;
5270 * If it's the only frame send as non-aggregate
5271 * assume that ath_tx_form_aggr() has checked
5272 * whether it's in the BAW and added it appropriately.
5274 if (bf->bf_state.bfs_nframes == 1) {
5275 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
5276 "%s: single-frame aggregate\n", __func__);
5278 /* Update CLRDMASK just before this frame is queued */
5279 ath_tx_update_clrdmask(sc, tid, bf);
5281 bf->bf_state.bfs_aggr = 0;
5282 bf->bf_state.bfs_ndelim = 0;
5283 ath_tx_setds(sc, bf);
5284 ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc);
5285 if (status == ATH_AGGR_BAW_CLOSED)
5286 sc->sc_aggr_stats.aggr_baw_closed_single_pkt++;
5288 sc->sc_aggr_stats.aggr_single_pkt++;
5290 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
5291 "%s: multi-frame aggregate: %d frames, "
5293 __func__, bf->bf_state.bfs_nframes,
5294 bf->bf_state.bfs_al);
5295 bf->bf_state.bfs_aggr = 1;
5296 sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++;
5297 sc->sc_aggr_stats.aggr_aggr_pkt++;
5299 /* Update CLRDMASK just before this frame is queued */
5300 ath_tx_update_clrdmask(sc, tid, bf);
5303 * Calculate the duration/protection as required.
5305 ath_tx_calc_duration(sc, bf);
5306 ath_tx_calc_protection(sc, bf);
5309 * Update the rate and rtscts information based on the
5310 * rate decision made by the rate control code;
5311 * the first frame in the aggregate needs it.
5313 ath_tx_set_rtscts(sc, bf);
5316 * Setup the relevant descriptor fields
5317 * for aggregation. The first descriptor
5318 * already points to the rest in the chain.
5320 ath_tx_setds_11n(sc, bf);
5324 /* Set completion handler, multi-frame aggregate or not */
5325 bf->bf_comp = ath_tx_aggr_comp;
5327 if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID)
5328 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=16?\n", __func__);
5331 * Update leak count and frame config if were leaking frames.
5333 * XXX TODO: it should update all frames in an aggregate
5336 ath_tx_leak_count_update(sc, tid, bf);
5339 ath_tx_handoff(sc, txq, bf);
5341 /* Track outstanding buffer count to hardware */
5342 /* aggregates are "one" buffer */
5346 * Break out if ath_tx_form_aggr() indicated
5347 * there can't be any further progress (eg BAW is full.)
5348 * Checking for an empty txq is done above.
5350 * XXX locking on txq here?
5352 /* XXX TXQ locking */
5353 if (txq->axq_aggr_depth >= sc->sc_hwq_limit_aggr ||
5354 (status == ATH_AGGR_BAW_CLOSED ||
5355 status == ATH_AGGR_LEAK_CLOSED))
5361 * Schedule some packets from the given node/TID to the hardware.
5363 * XXX TODO: this routine doesn't enforce the maximum TXQ depth.
5364 * It just dumps frames into the TXQ. We should limit how deep
5365 * the transmit queue can grow for frames dispatched to the given
5368 * To avoid locking issues, either we need to own the TXQ lock
5369 * at this point, or we need to pass in the maximum frame count
5373 ath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an,
5374 struct ath_tid *tid)
5377 struct ath_txq *txq = sc->sc_ac2q[tid->ac];
5379 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n",
5380 __func__, an, tid->tid);
5382 ATH_TX_LOCK_ASSERT(sc);
5384 /* Check - is AMPDU pending or running? then print out something */
5385 if (ath_tx_ampdu_pending(sc, an, tid->tid))
5386 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ampdu pending?\n",
5387 __func__, tid->tid);
5388 if (ath_tx_ampdu_running(sc, an, tid->tid))
5389 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ampdu running?\n",
5390 __func__, tid->tid);
5395 * If the upper layers have paused the TID, don't
5396 * queue any further packets.
5398 * XXX if we are leaking frames, make sure we decrement
5399 * that counter _and_ we continue here.
5401 if (! ath_tx_tid_can_tx_or_sched(sc, tid))
5404 bf = ATH_TID_FIRST(tid);
5409 ATH_TID_REMOVE(tid, bf, bf_list);
5412 if (tid->tid != bf->bf_state.bfs_tid) {
5413 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bfs_tid %d !="
5414 " tid %d\n", __func__, bf->bf_state.bfs_tid,
5417 /* Normal completion handler */
5418 bf->bf_comp = ath_tx_normal_comp;
5421 * Override this for now, until the non-aggregate
5422 * completion handler correctly handles software retransmits.
5424 bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK;
5426 /* Update CLRDMASK just before this frame is queued */
5427 ath_tx_update_clrdmask(sc, tid, bf);
5429 /* Program descriptors + rate control */
5430 ath_tx_do_ratelookup(sc, bf);
5431 ath_tx_calc_duration(sc, bf);
5432 ath_tx_calc_protection(sc, bf);
5433 ath_tx_set_rtscts(sc, bf);
5434 ath_tx_rate_fill_rcflags(sc, bf);
5435 ath_tx_setds(sc, bf);
5438 * Update the current leak count if
5439 * we're leaking frames; and set the
5440 * MORE flag as appropriate.
5442 ath_tx_leak_count_update(sc, tid, bf);
5444 /* Track outstanding buffer count to hardware */
5445 /* aggregates are "one" buffer */
5448 /* Punt to hardware or software txq */
5449 ath_tx_handoff(sc, txq, bf);
5454 * Schedule some packets to the given hardware queue.
5456 * This function walks the list of TIDs (ie, ath_node TIDs
5457 * with queued traffic) and attempts to schedule traffic
5460 * TID scheduling is implemented as a FIFO, with TIDs being
5461 * added to the end of the queue after some frames have been
5465 ath_txq_sched(struct ath_softc *sc, struct ath_txq *txq)
5467 struct ath_tid *tid, *last;
5469 ATH_TX_LOCK_ASSERT(sc);
5472 * Don't schedule if the hardware queue is busy.
5473 * This (hopefully) gives some more time to aggregate
5474 * some packets in the aggregation queue.
5476 * XXX It doesn't stop a parallel sender from sneaking
5477 * in transmitting a frame!
5479 /* XXX TXQ locking */
5480 if (txq->axq_aggr_depth + txq->fifo.axq_depth >= sc->sc_hwq_limit_aggr) {
5481 sc->sc_aggr_stats.aggr_sched_nopkt++;
5484 if (txq->axq_depth >= sc->sc_hwq_limit_nonaggr) {
5485 sc->sc_aggr_stats.aggr_sched_nopkt++;
5489 last = TAILQ_LAST(&txq->axq_tidq, axq_t_s);
5491 while ((tid = TAILQ_FIRST(&txq->axq_tidq)) != NULL) {
5493 * Suspend paused queues here; they'll be resumed
5494 * once the addba completes or times out.
5496 DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n",
5497 __func__, tid->tid, tid->paused);
5498 ath_tx_tid_unsched(sc, tid);
5500 * This node may be in power-save and we're leaking
5501 * a frame; be careful.
5503 if (! ath_tx_tid_can_tx_or_sched(sc, tid)) {
5506 if (ath_tx_ampdu_running(sc, tid->an, tid->tid))
5507 ath_tx_tid_hw_queue_aggr(sc, tid->an, tid);
5509 ath_tx_tid_hw_queue_norm(sc, tid->an, tid);
5511 /* Not empty? Re-schedule */
5512 if (tid->axq_depth != 0)
5513 ath_tx_tid_sched(sc, tid);
5516 * Give the software queue time to aggregate more
5517 * packets. If we aren't running aggregation then
5518 * we should still limit the hardware queue depth.
5520 /* XXX TXQ locking */
5521 if (txq->axq_aggr_depth + txq->fifo.axq_depth >= sc->sc_hwq_limit_aggr) {
5524 if (txq->axq_depth >= sc->sc_hwq_limit_nonaggr) {
5529 * If this was the last entry on the original list, stop.
5530 * Otherwise nodes that have been rescheduled onto the end
5531 * of the TID FIFO list will just keep being rescheduled.
5533 * XXX What should we do about nodes that were paused
5534 * but are pending a leaking frame in response to a ps-poll?
5535 * They'll be put at the front of the list; so they'll
5536 * prematurely trigger this condition! Ew.
5548 * Return net80211 TID struct pointer, or NULL for none
5550 struct ieee80211_tx_ampdu *
5551 ath_tx_get_tx_tid(struct ath_node *an, int tid)
5553 struct ieee80211_node *ni = &an->an_node;
5554 struct ieee80211_tx_ampdu *tap;
5556 if (tid == IEEE80211_NONQOS_TID)
5559 tap = &ni->ni_tx_ampdu[tid];
5564 * Is AMPDU-TX running?
5567 ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid)
5569 struct ieee80211_tx_ampdu *tap;
5571 if (tid == IEEE80211_NONQOS_TID)
5574 tap = ath_tx_get_tx_tid(an, tid);
5576 return 0; /* Not valid; default to not running */
5578 return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING);
5582 * Is AMPDU-TX negotiation pending?
5585 ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid)
5587 struct ieee80211_tx_ampdu *tap;
5589 if (tid == IEEE80211_NONQOS_TID)
5592 tap = ath_tx_get_tx_tid(an, tid);
5594 return 0; /* Not valid; default to not pending */
5596 return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND);
5600 * Is AMPDU-TX pending for the given TID?
5605 * Method to handle sending an ADDBA request.
5607 * We tap this so the relevant flags can be set to pause the TID
5608 * whilst waiting for the response.
5610 * XXX there's no timeout handler we can override?
5613 ath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
5614 int dialogtoken, int baparamset, int batimeout)
5616 struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
5617 int tid = tap->txa_ac;
5618 struct ath_node *an = ATH_NODE(ni);
5619 struct ath_tid *atid = &an->an_tid[tid];
5622 * XXX danger Will Robinson!
5624 * Although the taskqueue may be running and scheduling some more
5625 * packets, these should all be _before_ the addba sequence number.
5626 * However, net80211 will keep self-assigning sequence numbers
5627 * until addba has been negotiated.
5629 * In the past, these packets would be "paused" (which still works
5630 * fine, as they're being scheduled to the driver in the same
5631 * serialised method which is calling the addba request routine)
5632 * and when the aggregation session begins, they'll be dequeued
5633 * as aggregate packets and added to the BAW. However, now there's
5634 * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these
5635 * packets. Thus they never get included in the BAW tracking and
5636 * this can cause the initial burst of packets after the addba
5637 * negotiation to "hang", as they quickly fall outside the BAW.
5639 * The "eventual" solution should be to tag these packets with
5640 * dobaw. Although net80211 has given us a sequence number,
5641 * it'll be "after" the left edge of the BAW and thus it'll
5646 * This is a bit annoying. Until net80211 HT code inherits some
5647 * (any) locking, we may have this called in parallel BUT only
5648 * one response/timeout will be called. Grr.
5650 if (atid->addba_tx_pending == 0) {
5651 ath_tx_tid_pause(sc, atid);
5652 atid->addba_tx_pending = 1;
5656 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
5657 "%s: %6D: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n",
5661 dialogtoken, baparamset, batimeout);
5662 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
5663 "%s: txa_start=%d, ni_txseqs=%d\n",
5664 __func__, tap->txa_start, ni->ni_txseqs[tid]);
5666 return sc->sc_addba_request(ni, tap, dialogtoken, baparamset,
5671 * Handle an ADDBA response.
5673 * We unpause the queue so TX'ing can resume.
5675 * Any packets TX'ed from this point should be "aggregate" (whether
5676 * aggregate or not) so the BAW is updated.
5678 * Note! net80211 keeps self-assigning sequence numbers until
5679 * ampdu is negotiated. This means the initially-negotiated BAW left
5680 * edge won't match the ni->ni_txseq.
5682 * So, being very dirty, the BAW left edge is "slid" here to match
5685 * What likely SHOULD happen is that all packets subsequent to the
5686 * addba request should be tagged as aggregate and queued as non-aggregate
5687 * frames; thus updating the BAW. For now though, I'll just slide the
5691 ath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
5692 int status, int code, int batimeout)
5694 struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
5695 int tid = tap->txa_ac;
5696 struct ath_node *an = ATH_NODE(ni);
5697 struct ath_tid *atid = &an->an_tid[tid];
5700 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
5701 "%s: %6D: called; status=%d, code=%d, batimeout=%d\n", __func__,
5704 status, code, batimeout);
5706 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
5707 "%s: txa_start=%d, ni_txseqs=%d\n",
5708 __func__, tap->txa_start, ni->ni_txseqs[tid]);
5711 * Call this first, so the interface flags get updated
5712 * before the TID is unpaused. Otherwise a race condition
5713 * exists where the unpaused TID still doesn't yet have
5714 * IEEE80211_AGGR_RUNNING set.
5716 r = sc->sc_addba_response(ni, tap, status, code, batimeout);
5719 atid->addba_tx_pending = 0;
5722 * Slide the BAW left edge to wherever net80211 left it for us.
5723 * Read above for more information.
5725 tap->txa_start = ni->ni_txseqs[tid];
5726 ath_tx_tid_resume(sc, atid);
5733 * Stop ADDBA on a queue.
5735 * This can be called whilst BAR TX is currently active on the queue,
5736 * so make sure this is unblocked before continuing.
5739 ath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
5741 struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
5742 int tid = tap->txa_ac;
5743 struct ath_node *an = ATH_NODE(ni);
5744 struct ath_tid *atid = &an->an_tid[tid];
5748 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: %6D: called\n",
5754 * Pause TID traffic early, so there aren't any races
5755 * Unblock the pending BAR held traffic, if it's currently paused.
5758 ath_tx_tid_pause(sc, atid);
5759 if (atid->bar_wait) {
5761 * bar_unsuspend() expects bar_tx == 1, as it should be
5762 * called from the TX completion path. This quietens
5763 * the warning. It's cleared for us anyway.
5766 ath_tx_tid_bar_unsuspend(sc, atid);
5770 /* There's no need to hold the TXQ lock here */
5771 sc->sc_addba_stop(ni, tap);
5774 * ath_tx_tid_cleanup will resume the TID if possible, otherwise
5775 * it'll set the cleanup flag, and it'll be unpaused once
5776 * things have been cleaned up.
5780 ath_tx_tid_cleanup(sc, an, tid, &bf_cq);
5782 * Unpause the TID if no cleanup is required.
5784 if (! atid->cleanup_inprogress)
5785 ath_tx_tid_resume(sc, atid);
5788 /* Handle completing frames and fail them */
5789 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
5790 TAILQ_REMOVE(&bf_cq, bf, bf_list);
5791 ath_tx_default_comp(sc, bf, 1);
5797 * Handle a node reassociation.
5799 * We may have a bunch of frames queued to the hardware; those need
5800 * to be marked as cleanup.
5803 ath_tx_node_reassoc(struct ath_softc *sc, struct ath_node *an)
5805 struct ath_tid *tid;
5812 ATH_TX_UNLOCK_ASSERT(sc);
5815 for (i = 0; i < IEEE80211_TID_SIZE; i++) {
5816 tid = &an->an_tid[i];
5817 if (tid->hwq_depth == 0)
5819 ath_tx_tid_pause(sc, tid);
5820 DPRINTF(sc, ATH_DEBUG_NODE,
5821 "%s: %6D: TID %d: cleaning up TID\n",
5823 an->an_node.ni_macaddr,
5826 ath_tx_tid_cleanup(sc, an, i, &bf_cq);
5828 * Unpause the TID if no cleanup is required.
5830 if (! tid->cleanup_inprogress)
5831 ath_tx_tid_resume(sc, tid);
5835 /* Handle completing frames and fail them */
5836 while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) {
5837 TAILQ_REMOVE(&bf_cq, bf, bf_list);
5838 ath_tx_default_comp(sc, bf, 1);
5843 * Note: net80211 bar_timeout() doesn't call this function on BAR failure;
5844 * it simply tears down the aggregation session. Ew.
5846 * It however will call ieee80211_ampdu_stop() which will call
5847 * ic->ic_addba_stop().
5849 * XXX This uses a hard-coded max BAR count value; the whole
5850 * XXX BAR TX success or failure should be better handled!
5853 ath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
5856 struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
5857 int tid = tap->txa_ac;
5858 struct ath_node *an = ATH_NODE(ni);
5859 struct ath_tid *atid = &an->an_tid[tid];
5860 int attempts = tap->txa_attempts;
5862 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
5863 "%s: %6D: called; txa_tid=%d, atid->tid=%d, status=%d, attempts=%d\n",
5872 /* Note: This may update the BAW details */
5873 sc->sc_bar_response(ni, tap, status);
5875 /* Unpause the TID */
5877 * XXX if this is attempt=50, the TID will be downgraded
5878 * XXX to a non-aggregate session. So we must unpause the
5879 * XXX TID here or it'll never be done.
5881 * Also, don't call it if bar_tx/bar_wait are 0; something
5882 * has beaten us to the punch? (XXX figure out what?)
5884 if (status == 0 || attempts == 50) {
5886 if (atid->bar_tx == 0 || atid->bar_wait == 0)
5887 DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
5888 "%s: huh? bar_tx=%d, bar_wait=%d\n",
5890 atid->bar_tx, atid->bar_wait);
5892 ath_tx_tid_bar_unsuspend(sc, atid);
5898 * This is called whenever the pending ADDBA request times out.
5899 * Unpause and reschedule the TID.
5902 ath_addba_response_timeout(struct ieee80211_node *ni,
5903 struct ieee80211_tx_ampdu *tap)
5905 struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
5906 int tid = tap->txa_ac;
5907 struct ath_node *an = ATH_NODE(ni);
5908 struct ath_tid *atid = &an->an_tid[tid];
5910 DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
5911 "%s: %6D: TID=%d, called; resuming\n",
5918 atid->addba_tx_pending = 0;
5921 /* Note: This updates the aggregate state to (again) pending */
5922 sc->sc_addba_response_timeout(ni, tap);
5924 /* Unpause the TID; which reschedules it */
5926 ath_tx_tid_resume(sc, atid);
5931 * Check if a node is asleep or not.
5934 ath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an)
5937 ATH_TX_LOCK_ASSERT(sc);
5939 return (an->an_is_powersave);
5943 * Mark a node as currently "in powersaving."
5944 * This suspends all traffic on the node.
5946 * This must be called with the node/tx locks free.
5948 * XXX TODO: the locking silliness below is due to how the node
5949 * locking currently works. Right now, the node lock is grabbed
5950 * to do rate control lookups and these are done with the TX
5951 * queue lock held. This means the node lock can't be grabbed
5952 * first here or a LOR will occur.
5954 * Eventually (hopefully!) the TX path code will only grab
5955 * the TXQ lock when transmitting and the ath_node lock when
5956 * doing node/TID operations. There are other complications -
5957 * the sched/unsched operations involve walking the per-txq
5958 * 'active tid' list and this requires both locks to be held.
5961 ath_tx_node_sleep(struct ath_softc *sc, struct ath_node *an)
5963 struct ath_tid *atid;
5964 struct ath_txq *txq;
5967 ATH_TX_UNLOCK_ASSERT(sc);
5969 /* Suspend all traffic on the node */
5972 if (an->an_is_powersave) {
5973 DPRINTF(sc, ATH_DEBUG_XMIT,
5974 "%s: %6D: node was already asleep!\n",
5975 __func__, an->an_node.ni_macaddr, ":");
5980 for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) {
5981 atid = &an->an_tid[tid];
5982 txq = sc->sc_ac2q[atid->ac];
5984 ath_tx_tid_pause(sc, atid);
5987 /* Mark node as in powersaving */
5988 an->an_is_powersave = 1;
5994 * Mark a node as currently "awake."
5995 * This resumes all traffic to the node.
5998 ath_tx_node_wakeup(struct ath_softc *sc, struct ath_node *an)
6000 struct ath_tid *atid;
6001 struct ath_txq *txq;
6004 ATH_TX_UNLOCK_ASSERT(sc);
6009 if (an->an_is_powersave == 0) {
6011 DPRINTF(sc, ATH_DEBUG_XMIT,
6012 "%s: an=%p: node was already awake\n",
6017 /* Mark node as awake */
6018 an->an_is_powersave = 0;
6020 * Clear any pending leaked frame requests
6022 an->an_leak_count = 0;
6024 for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) {
6025 atid = &an->an_tid[tid];
6026 txq = sc->sc_ac2q[atid->ac];
6028 ath_tx_tid_resume(sc, atid);
6034 ath_legacy_dma_txsetup(struct ath_softc *sc)
6037 /* nothing new needed */
6042 ath_legacy_dma_txteardown(struct ath_softc *sc)
6045 /* nothing new needed */
6050 ath_xmit_setup_legacy(struct ath_softc *sc)
6053 * For now, just set the descriptor length to sizeof(ath_desc);
6054 * worry about extracting the real length out of the HAL later.
6056 sc->sc_tx_desclen = sizeof(struct ath_desc);
6057 sc->sc_tx_statuslen = sizeof(struct ath_desc);
6058 sc->sc_tx_nmaps = 1; /* only one buffer per TX desc */
6060 sc->sc_tx.xmit_setup = ath_legacy_dma_txsetup;
6061 sc->sc_tx.xmit_teardown = ath_legacy_dma_txteardown;
6062 sc->sc_tx.xmit_attach_comp_func = ath_legacy_attach_comp_func;
6064 sc->sc_tx.xmit_dma_restart = ath_legacy_tx_dma_restart;
6065 sc->sc_tx.xmit_handoff = ath_legacy_xmit_handoff;
6067 sc->sc_tx.xmit_drain = ath_legacy_tx_drain;