1b8e788a5SAdrian Chadd /*- 2b8e788a5SAdrian Chadd * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3c6e9cee2SAdrian Chadd * Copyright (c) 2010-2012 Adrian Chadd, Xenion Pty Ltd 4b8e788a5SAdrian Chadd * All rights reserved. 5b8e788a5SAdrian Chadd * 6b8e788a5SAdrian Chadd * Redistribution and use in source and binary forms, with or without 7b8e788a5SAdrian Chadd * modification, are permitted provided that the following conditions 8b8e788a5SAdrian Chadd * are met: 9b8e788a5SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 10b8e788a5SAdrian Chadd * notice, this list of conditions and the following disclaimer, 11b8e788a5SAdrian Chadd * without modification. 12b8e788a5SAdrian Chadd * 2. Redistributions in binary form must reproduce at minimum a disclaimer 13b8e788a5SAdrian Chadd * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 14b8e788a5SAdrian Chadd * redistribution must be conditioned upon including a substantially 15b8e788a5SAdrian Chadd * similar Disclaimer requirement for further binary redistribution. 16b8e788a5SAdrian Chadd * 17b8e788a5SAdrian Chadd * NO WARRANTY 18b8e788a5SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19b8e788a5SAdrian Chadd * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20b8e788a5SAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 21b8e788a5SAdrian Chadd * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22b8e788a5SAdrian Chadd * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 23b8e788a5SAdrian Chadd * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24b8e788a5SAdrian Chadd * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25b8e788a5SAdrian Chadd * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26b8e788a5SAdrian Chadd * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27b8e788a5SAdrian Chadd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28b8e788a5SAdrian Chadd * THE POSSIBILITY OF SUCH DAMAGES. 29b8e788a5SAdrian Chadd */ 30b8e788a5SAdrian Chadd 31b8e788a5SAdrian Chadd #include <sys/cdefs.h> 32b8e788a5SAdrian Chadd __FBSDID("$FreeBSD$"); 33b8e788a5SAdrian Chadd 34b8e788a5SAdrian Chadd /* 35b8e788a5SAdrian Chadd * Driver for the Atheros Wireless LAN controller. 36b8e788a5SAdrian Chadd * 37b8e788a5SAdrian Chadd * This software is derived from work of Atsushi Onoe; his contribution 38b8e788a5SAdrian Chadd * is greatly appreciated. 39b8e788a5SAdrian Chadd */ 40b8e788a5SAdrian Chadd 41b8e788a5SAdrian Chadd #include "opt_inet.h" 42b8e788a5SAdrian Chadd #include "opt_ath.h" 43b8e788a5SAdrian Chadd #include "opt_wlan.h" 44b8e788a5SAdrian Chadd 45b8e788a5SAdrian Chadd #include <sys/param.h> 46b8e788a5SAdrian Chadd #include <sys/systm.h> 47b8e788a5SAdrian Chadd #include <sys/sysctl.h> 48b8e788a5SAdrian Chadd #include <sys/mbuf.h> 49b8e788a5SAdrian Chadd #include <sys/malloc.h> 50b8e788a5SAdrian Chadd #include <sys/lock.h> 51b8e788a5SAdrian Chadd #include <sys/mutex.h> 52b8e788a5SAdrian Chadd #include <sys/kernel.h> 53b8e788a5SAdrian Chadd #include <sys/socket.h> 54b8e788a5SAdrian Chadd #include <sys/sockio.h> 55b8e788a5SAdrian Chadd #include <sys/errno.h> 56b8e788a5SAdrian Chadd #include <sys/callout.h> 57b8e788a5SAdrian Chadd #include <sys/bus.h> 58b8e788a5SAdrian Chadd #include <sys/endian.h> 59b8e788a5SAdrian Chadd #include <sys/kthread.h> 60b8e788a5SAdrian Chadd #include <sys/taskqueue.h> 61b8e788a5SAdrian Chadd #include <sys/priv.h> 62b8e788a5SAdrian Chadd 63b8e788a5SAdrian Chadd #include <machine/bus.h> 64b8e788a5SAdrian Chadd 65b8e788a5SAdrian Chadd #include <net/if.h> 66b8e788a5SAdrian Chadd #include <net/if_dl.h> 67b8e788a5SAdrian Chadd #include <net/if_media.h> 68b8e788a5SAdrian Chadd #include <net/if_types.h> 69b8e788a5SAdrian Chadd #include <net/if_arp.h> 70b8e788a5SAdrian Chadd #include <net/ethernet.h> 71b8e788a5SAdrian Chadd #include <net/if_llc.h> 72b8e788a5SAdrian Chadd 73b8e788a5SAdrian Chadd #include <net80211/ieee80211_var.h> 74b8e788a5SAdrian Chadd #include <net80211/ieee80211_regdomain.h> 75b8e788a5SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG 76b8e788a5SAdrian Chadd #include <net80211/ieee80211_superg.h> 77b8e788a5SAdrian Chadd #endif 78b8e788a5SAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA 79b8e788a5SAdrian Chadd #include <net80211/ieee80211_tdma.h> 80b8e788a5SAdrian Chadd #endif 81eb6f0de0SAdrian Chadd #include <net80211/ieee80211_ht.h> 82b8e788a5SAdrian Chadd 83b8e788a5SAdrian Chadd #include <net/bpf.h> 84b8e788a5SAdrian Chadd 85b8e788a5SAdrian Chadd #ifdef INET 86b8e788a5SAdrian Chadd #include <netinet/in.h> 87b8e788a5SAdrian Chadd #include <netinet/if_ether.h> 88b8e788a5SAdrian Chadd #endif 89b8e788a5SAdrian Chadd 90b8e788a5SAdrian Chadd #include <dev/ath/if_athvar.h> 91b8e788a5SAdrian Chadd #include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */ 92b8e788a5SAdrian Chadd #include <dev/ath/ath_hal/ah_diagcodes.h> 93b8e788a5SAdrian Chadd 94b8e788a5SAdrian Chadd #include <dev/ath/if_ath_debug.h> 95b8e788a5SAdrian Chadd 96b8e788a5SAdrian Chadd #ifdef ATH_TX99_DIAG 97b8e788a5SAdrian Chadd #include <dev/ath/ath_tx99/ath_tx99.h> 98b8e788a5SAdrian Chadd #endif 99b8e788a5SAdrian Chadd 100b8e788a5SAdrian Chadd #include <dev/ath/if_ath_misc.h> 101b8e788a5SAdrian Chadd #include <dev/ath/if_ath_tx.h> 102c1782ce0SAdrian Chadd #include <dev/ath/if_ath_tx_ht.h> 103b8e788a5SAdrian Chadd 10481a82688SAdrian Chadd /* 105eb6f0de0SAdrian Chadd * How many retries to perform in software 106eb6f0de0SAdrian Chadd */ 107eb6f0de0SAdrian Chadd #define SWMAX_RETRIES 10 108eb6f0de0SAdrian Chadd 109*7403d1b9SAdrian Chadd /* 110*7403d1b9SAdrian Chadd * What queue to throw the non-QoS TID traffic into 111*7403d1b9SAdrian Chadd */ 112*7403d1b9SAdrian Chadd #define ATH_NONQOS_TID_AC WME_AC_VO 113*7403d1b9SAdrian Chadd 114eb6f0de0SAdrian Chadd static int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, 115eb6f0de0SAdrian Chadd int tid); 116eb6f0de0SAdrian Chadd static int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, 117eb6f0de0SAdrian Chadd int tid); 118a108d2d6SAdrian Chadd static ieee80211_seq ath_tx_tid_seqno_assign(struct ath_softc *sc, 119a108d2d6SAdrian Chadd struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0); 120eb6f0de0SAdrian Chadd static int ath_tx_action_frame_override_queue(struct ath_softc *sc, 121eb6f0de0SAdrian Chadd struct ieee80211_node *ni, struct mbuf *m0, int *tid); 122f1bc738eSAdrian Chadd static struct ath_buf * 123f1bc738eSAdrian Chadd ath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 124f1bc738eSAdrian Chadd struct ath_tid *tid, struct ath_buf *bf); 125eb6f0de0SAdrian Chadd 126eb6f0de0SAdrian Chadd /* 12781a82688SAdrian Chadd * Whether to use the 11n rate scenario functions or not 12881a82688SAdrian Chadd */ 12981a82688SAdrian Chadd static inline int 13081a82688SAdrian Chadd ath_tx_is_11n(struct ath_softc *sc) 13181a82688SAdrian Chadd { 1324ddf2cc3SAdrian Chadd return ((sc->sc_ah->ah_magic == 0x20065416) || 1334ddf2cc3SAdrian Chadd (sc->sc_ah->ah_magic == 0x19741014)); 13481a82688SAdrian Chadd } 13581a82688SAdrian Chadd 136eb6f0de0SAdrian Chadd /* 137eb6f0de0SAdrian Chadd * Obtain the current TID from the given frame. 138eb6f0de0SAdrian Chadd * 139eb6f0de0SAdrian Chadd * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.) 140eb6f0de0SAdrian Chadd * This has implications for which AC/priority the packet is placed 141eb6f0de0SAdrian Chadd * in. 142eb6f0de0SAdrian Chadd */ 143eb6f0de0SAdrian Chadd static int 144eb6f0de0SAdrian Chadd ath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0) 145eb6f0de0SAdrian Chadd { 146eb6f0de0SAdrian Chadd const struct ieee80211_frame *wh; 147eb6f0de0SAdrian Chadd int pri = M_WME_GETAC(m0); 148eb6f0de0SAdrian Chadd 149eb6f0de0SAdrian Chadd wh = mtod(m0, const struct ieee80211_frame *); 150eb6f0de0SAdrian Chadd if (! IEEE80211_QOS_HAS_SEQ(wh)) 151eb6f0de0SAdrian Chadd return IEEE80211_NONQOS_TID; 152eb6f0de0SAdrian Chadd else 153eb6f0de0SAdrian Chadd return WME_AC_TO_TID(pri); 154eb6f0de0SAdrian Chadd } 155eb6f0de0SAdrian Chadd 156f1bc738eSAdrian Chadd static void 157f1bc738eSAdrian Chadd ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) 158f1bc738eSAdrian Chadd { 159f1bc738eSAdrian Chadd struct ieee80211_frame *wh; 160f1bc738eSAdrian Chadd 161f1bc738eSAdrian Chadd wh = mtod(bf->bf_m, struct ieee80211_frame *); 162f1bc738eSAdrian Chadd /* Only update/resync if needed */ 163f1bc738eSAdrian Chadd if (bf->bf_state.bfs_isretried == 0) { 164f1bc738eSAdrian Chadd wh->i_fc[1] |= IEEE80211_FC1_RETRY; 165f1bc738eSAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 166f1bc738eSAdrian Chadd BUS_DMASYNC_PREWRITE); 167f1bc738eSAdrian Chadd } 168f1bc738eSAdrian Chadd bf->bf_state.bfs_isretried = 1; 169f1bc738eSAdrian Chadd bf->bf_state.bfs_retries ++; 170f1bc738eSAdrian Chadd } 171f1bc738eSAdrian Chadd 172eb6f0de0SAdrian Chadd /* 173eb6f0de0SAdrian Chadd * Determine what the correct AC queue for the given frame 174eb6f0de0SAdrian Chadd * should be. 175eb6f0de0SAdrian Chadd * 176eb6f0de0SAdrian Chadd * This code assumes that the TIDs map consistently to 177eb6f0de0SAdrian Chadd * the underlying hardware (or software) ath_txq. 178eb6f0de0SAdrian Chadd * Since the sender may try to set an AC which is 179eb6f0de0SAdrian Chadd * arbitrary, non-QoS TIDs may end up being put on 180eb6f0de0SAdrian Chadd * completely different ACs. There's no way to put a 181eb6f0de0SAdrian Chadd * TID into multiple ath_txq's for scheduling, so 182eb6f0de0SAdrian Chadd * for now we override the AC/TXQ selection and set 183eb6f0de0SAdrian Chadd * non-QOS TID frames into the BE queue. 184eb6f0de0SAdrian Chadd * 185eb6f0de0SAdrian Chadd * This may be completely incorrect - specifically, 186eb6f0de0SAdrian Chadd * some management frames may end up out of order 187eb6f0de0SAdrian Chadd * compared to the QoS traffic they're controlling. 188eb6f0de0SAdrian Chadd * I'll look into this later. 189eb6f0de0SAdrian Chadd */ 190eb6f0de0SAdrian Chadd static int 191eb6f0de0SAdrian Chadd ath_tx_getac(struct ath_softc *sc, const struct mbuf *m0) 192eb6f0de0SAdrian Chadd { 193eb6f0de0SAdrian Chadd const struct ieee80211_frame *wh; 194eb6f0de0SAdrian Chadd int pri = M_WME_GETAC(m0); 195eb6f0de0SAdrian Chadd wh = mtod(m0, const struct ieee80211_frame *); 196eb6f0de0SAdrian Chadd if (IEEE80211_QOS_HAS_SEQ(wh)) 197eb6f0de0SAdrian Chadd return pri; 198eb6f0de0SAdrian Chadd 199*7403d1b9SAdrian Chadd return ATH_NONQOS_TID_AC; 200eb6f0de0SAdrian Chadd } 201eb6f0de0SAdrian Chadd 202b8e788a5SAdrian Chadd void 203b8e788a5SAdrian Chadd ath_txfrag_cleanup(struct ath_softc *sc, 204b8e788a5SAdrian Chadd ath_bufhead *frags, struct ieee80211_node *ni) 205b8e788a5SAdrian Chadd { 206b8e788a5SAdrian Chadd struct ath_buf *bf, *next; 207b8e788a5SAdrian Chadd 208b8e788a5SAdrian Chadd ATH_TXBUF_LOCK_ASSERT(sc); 209b8e788a5SAdrian Chadd 2106b349e5aSAdrian Chadd TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) { 211b8e788a5SAdrian Chadd /* NB: bf assumed clean */ 2126b349e5aSAdrian Chadd TAILQ_REMOVE(frags, bf, bf_list); 213e1a50456SAdrian Chadd ath_returnbuf_head(sc, bf); 214b8e788a5SAdrian Chadd ieee80211_node_decref(ni); 215b8e788a5SAdrian Chadd } 216b8e788a5SAdrian Chadd } 217b8e788a5SAdrian Chadd 218b8e788a5SAdrian Chadd /* 219b8e788a5SAdrian Chadd * Setup xmit of a fragmented frame. Allocate a buffer 220b8e788a5SAdrian Chadd * for each frag and bump the node reference count to 221b8e788a5SAdrian Chadd * reflect the held reference to be setup by ath_tx_start. 222b8e788a5SAdrian Chadd */ 223b8e788a5SAdrian Chadd int 224b8e788a5SAdrian Chadd ath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags, 225b8e788a5SAdrian Chadd struct mbuf *m0, struct ieee80211_node *ni) 226b8e788a5SAdrian Chadd { 227b8e788a5SAdrian Chadd struct mbuf *m; 228b8e788a5SAdrian Chadd struct ath_buf *bf; 229b8e788a5SAdrian Chadd 230b8e788a5SAdrian Chadd ATH_TXBUF_LOCK(sc); 231b8e788a5SAdrian Chadd for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) { 232af33d486SAdrian Chadd /* XXX non-management? */ 233af33d486SAdrian Chadd bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL); 234b8e788a5SAdrian Chadd if (bf == NULL) { /* out of buffers, cleanup */ 235b43facbfSAdrian Chadd device_printf(sc->sc_dev, "%s: no buffer?\n", 236b43facbfSAdrian Chadd __func__); 237b8e788a5SAdrian Chadd ath_txfrag_cleanup(sc, frags, ni); 238b8e788a5SAdrian Chadd break; 239b8e788a5SAdrian Chadd } 240b8e788a5SAdrian Chadd ieee80211_node_incref(ni); 2416b349e5aSAdrian Chadd TAILQ_INSERT_TAIL(frags, bf, bf_list); 242b8e788a5SAdrian Chadd } 243b8e788a5SAdrian Chadd ATH_TXBUF_UNLOCK(sc); 244b8e788a5SAdrian Chadd 2456b349e5aSAdrian Chadd return !TAILQ_EMPTY(frags); 246b8e788a5SAdrian Chadd } 247b8e788a5SAdrian Chadd 248b8e788a5SAdrian Chadd /* 249b8e788a5SAdrian Chadd * Reclaim mbuf resources. For fragmented frames we 250b8e788a5SAdrian Chadd * need to claim each frag chained with m_nextpkt. 251b8e788a5SAdrian Chadd */ 252b8e788a5SAdrian Chadd void 253b8e788a5SAdrian Chadd ath_freetx(struct mbuf *m) 254b8e788a5SAdrian Chadd { 255b8e788a5SAdrian Chadd struct mbuf *next; 256b8e788a5SAdrian Chadd 257b8e788a5SAdrian Chadd do { 258b8e788a5SAdrian Chadd next = m->m_nextpkt; 259b8e788a5SAdrian Chadd m->m_nextpkt = NULL; 260b8e788a5SAdrian Chadd m_freem(m); 261b8e788a5SAdrian Chadd } while ((m = next) != NULL); 262b8e788a5SAdrian Chadd } 263b8e788a5SAdrian Chadd 264b8e788a5SAdrian Chadd static int 265b8e788a5SAdrian Chadd ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0) 266b8e788a5SAdrian Chadd { 267b8e788a5SAdrian Chadd struct mbuf *m; 268b8e788a5SAdrian Chadd int error; 269b8e788a5SAdrian Chadd 270b8e788a5SAdrian Chadd /* 271b8e788a5SAdrian Chadd * Load the DMA map so any coalescing is done. This 272b8e788a5SAdrian Chadd * also calculates the number of descriptors we need. 273b8e788a5SAdrian Chadd */ 274b8e788a5SAdrian Chadd error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 275b8e788a5SAdrian Chadd bf->bf_segs, &bf->bf_nseg, 276b8e788a5SAdrian Chadd BUS_DMA_NOWAIT); 277b8e788a5SAdrian Chadd if (error == EFBIG) { 278b8e788a5SAdrian Chadd /* XXX packet requires too many descriptors */ 279b8e788a5SAdrian Chadd bf->bf_nseg = ATH_TXDESC+1; 280b8e788a5SAdrian Chadd } else if (error != 0) { 281b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_busdma++; 282b8e788a5SAdrian Chadd ath_freetx(m0); 283b8e788a5SAdrian Chadd return error; 284b8e788a5SAdrian Chadd } 285b8e788a5SAdrian Chadd /* 286b8e788a5SAdrian Chadd * Discard null packets and check for packets that 287b8e788a5SAdrian Chadd * require too many TX descriptors. We try to convert 288b8e788a5SAdrian Chadd * the latter to a cluster. 289b8e788a5SAdrian Chadd */ 290b8e788a5SAdrian Chadd if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ 291b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_linear++; 292b8e788a5SAdrian Chadd m = m_collapse(m0, M_DONTWAIT, ATH_TXDESC); 293b8e788a5SAdrian Chadd if (m == NULL) { 294b8e788a5SAdrian Chadd ath_freetx(m0); 295b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_nombuf++; 296b8e788a5SAdrian Chadd return ENOMEM; 297b8e788a5SAdrian Chadd } 298b8e788a5SAdrian Chadd m0 = m; 299b8e788a5SAdrian Chadd error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 300b8e788a5SAdrian Chadd bf->bf_segs, &bf->bf_nseg, 301b8e788a5SAdrian Chadd BUS_DMA_NOWAIT); 302b8e788a5SAdrian Chadd if (error != 0) { 303b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_busdma++; 304b8e788a5SAdrian Chadd ath_freetx(m0); 305b8e788a5SAdrian Chadd return error; 306b8e788a5SAdrian Chadd } 307b8e788a5SAdrian Chadd KASSERT(bf->bf_nseg <= ATH_TXDESC, 308b8e788a5SAdrian Chadd ("too many segments after defrag; nseg %u", bf->bf_nseg)); 309b8e788a5SAdrian Chadd } else if (bf->bf_nseg == 0) { /* null packet, discard */ 310b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_nodata++; 311b8e788a5SAdrian Chadd ath_freetx(m0); 312b8e788a5SAdrian Chadd return EIO; 313b8e788a5SAdrian Chadd } 314b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n", 315b8e788a5SAdrian Chadd __func__, m0, m0->m_pkthdr.len); 316b8e788a5SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 317b8e788a5SAdrian Chadd bf->bf_m = m0; 318b8e788a5SAdrian Chadd 319b8e788a5SAdrian Chadd return 0; 320b8e788a5SAdrian Chadd } 321b8e788a5SAdrian Chadd 3226edf1dc7SAdrian Chadd /* 3236edf1dc7SAdrian Chadd * Chain together segments+descriptors for a non-11n frame. 3246edf1dc7SAdrian Chadd */ 325b8e788a5SAdrian Chadd static void 326eb6f0de0SAdrian Chadd ath_tx_chaindesclist(struct ath_softc *sc, struct ath_buf *bf) 327b8e788a5SAdrian Chadd { 328b8e788a5SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 32942083b3dSAdrian Chadd char *ds, *ds0; 3302b200bb4SAdrian Chadd int i, bp, dsp; 33146634305SAdrian Chadd HAL_DMA_ADDR bufAddrList[4]; 33246634305SAdrian Chadd uint32_t segLenList[4]; 3332b200bb4SAdrian Chadd int numTxMaps = 1; 334e2137b86SAdrian Chadd int isFirstDesc = 1; 33579b52356SAdrian Chadd int qnum; 33646634305SAdrian Chadd 3373d9b1596SAdrian Chadd /* 3383d9b1596SAdrian Chadd * XXX There's txdma and txdma_mgmt; the descriptor 3393d9b1596SAdrian Chadd * sizes must match. 3403d9b1596SAdrian Chadd */ 3413d9b1596SAdrian Chadd struct ath_descdma *dd = &sc->sc_txdma; 342b8e788a5SAdrian Chadd 343b8e788a5SAdrian Chadd /* 344b8e788a5SAdrian Chadd * Fillin the remainder of the descriptor info. 345b8e788a5SAdrian Chadd */ 34646634305SAdrian Chadd 3472b200bb4SAdrian Chadd /* 3482b200bb4SAdrian Chadd * For now the HAL doesn't implement halNumTxMaps for non-EDMA 3492b200bb4SAdrian Chadd * (ie it's 0.) So just work around it. 3502b200bb4SAdrian Chadd * 3512b200bb4SAdrian Chadd * XXX TODO: populate halNumTxMaps for each HAL chip and 3522b200bb4SAdrian Chadd * then undo this hack. 3532b200bb4SAdrian Chadd */ 3542b200bb4SAdrian Chadd if (sc->sc_ah->ah_magic == 0x19741014) 3552b200bb4SAdrian Chadd numTxMaps = 4; 3562b200bb4SAdrian Chadd 3572b200bb4SAdrian Chadd /* 3582b200bb4SAdrian Chadd * For EDMA and later chips ensure the TX map is fully populated 3592b200bb4SAdrian Chadd * before advancing to the next descriptor. 3602b200bb4SAdrian Chadd */ 36142083b3dSAdrian Chadd ds0 = ds = (char *) bf->bf_desc; 3622b200bb4SAdrian Chadd bp = dsp = 0; 3632b200bb4SAdrian Chadd bzero(bufAddrList, sizeof(bufAddrList)); 3642b200bb4SAdrian Chadd bzero(segLenList, sizeof(segLenList)); 3652b200bb4SAdrian Chadd for (i = 0; i < bf->bf_nseg; i++) { 3662b200bb4SAdrian Chadd bufAddrList[bp] = bf->bf_segs[i].ds_addr; 3672b200bb4SAdrian Chadd segLenList[bp] = bf->bf_segs[i].ds_len; 3682b200bb4SAdrian Chadd bp++; 3692b200bb4SAdrian Chadd 3702b200bb4SAdrian Chadd /* 3712b200bb4SAdrian Chadd * Go to the next segment if this isn't the last segment 3722b200bb4SAdrian Chadd * and there's space in the current TX map. 3732b200bb4SAdrian Chadd */ 3742b200bb4SAdrian Chadd if ((i != bf->bf_nseg - 1) && (bp < numTxMaps)) 3752b200bb4SAdrian Chadd continue; 3762b200bb4SAdrian Chadd 3772b200bb4SAdrian Chadd /* 3782b200bb4SAdrian Chadd * Last segment or we're out of buffer pointers. 3792b200bb4SAdrian Chadd */ 3802b200bb4SAdrian Chadd bp = 0; 38146634305SAdrian Chadd 382b8e788a5SAdrian Chadd if (i == bf->bf_nseg - 1) 38342083b3dSAdrian Chadd ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 0); 384b8e788a5SAdrian Chadd else 38542083b3dSAdrian Chadd ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 3862b200bb4SAdrian Chadd bf->bf_daddr + dd->dd_descsize * (dsp + 1)); 38746634305SAdrian Chadd 38846634305SAdrian Chadd /* 38946634305SAdrian Chadd * XXX this assumes that bfs_txq is the actual destination 39046634305SAdrian Chadd * hardware queue at this point. It may not have been assigned, 39146634305SAdrian Chadd * it may actually be pointing to the multicast software 39246634305SAdrian Chadd * TXQ id. These must be fixed! 39346634305SAdrian Chadd */ 39479b52356SAdrian Chadd qnum = bf->bf_state.bfs_txq->axq_qnum; 39579b52356SAdrian Chadd 39642083b3dSAdrian Chadd ath_hal_filltxdesc(ah, (struct ath_desc *) ds 39746634305SAdrian Chadd , bufAddrList 39846634305SAdrian Chadd , segLenList 3992b200bb4SAdrian Chadd , bf->bf_descid /* XXX desc id */ 40079b52356SAdrian Chadd , qnum 401e2137b86SAdrian Chadd , isFirstDesc /* first segment */ 402b8e788a5SAdrian Chadd , i == bf->bf_nseg - 1 /* last segment */ 40342083b3dSAdrian Chadd , (struct ath_desc *) ds0 /* first descriptor */ 404b8e788a5SAdrian Chadd ); 40521840808SAdrian Chadd 40621840808SAdrian Chadd /* Make sure the 11n aggregate fields are cleared */ 40721840808SAdrian Chadd if (ath_tx_is_11n(sc)) 4085d9b19f7SAdrian Chadd ath_hal_clr11n_aggr(sc->sc_ah, (struct ath_desc *) ds); 40921840808SAdrian Chadd 410e2137b86SAdrian Chadd isFirstDesc = 0; 4110f8423a2SAdrian Chadd #ifdef ATH_DEBUG 41242083b3dSAdrian Chadd if (sc->sc_debug & ATH_DEBUG_XMIT) 41342083b3dSAdrian Chadd ath_printtxbuf(sc, bf, qnum, 0, 0); 4140f8423a2SAdrian Chadd #endif 41542083b3dSAdrian Chadd bf->bf_lastds = (struct ath_desc *) ds; 4162b200bb4SAdrian Chadd 4172b200bb4SAdrian Chadd /* 4182b200bb4SAdrian Chadd * Don't forget to skip to the next descriptor. 4192b200bb4SAdrian Chadd */ 42042083b3dSAdrian Chadd ds += sc->sc_tx_desclen; 4212b200bb4SAdrian Chadd dsp++; 4222b200bb4SAdrian Chadd 4232b200bb4SAdrian Chadd /* 4242b200bb4SAdrian Chadd * .. and don't forget to blank these out! 4252b200bb4SAdrian Chadd */ 4262b200bb4SAdrian Chadd bzero(bufAddrList, sizeof(bufAddrList)); 4272b200bb4SAdrian Chadd bzero(segLenList, sizeof(segLenList)); 428b8e788a5SAdrian Chadd } 4294d7f8837SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 43081a82688SAdrian Chadd } 43181a82688SAdrian Chadd 432eb6f0de0SAdrian Chadd /* 433eb6f0de0SAdrian Chadd * Fill in the descriptor list for a aggregate subframe. 434eb6f0de0SAdrian Chadd * 435eb6f0de0SAdrian Chadd * The subframe is returned with the ds_link field in the last subframe 436eb6f0de0SAdrian Chadd * pointing to 0. 437eb6f0de0SAdrian Chadd */ 43881a82688SAdrian Chadd static void 439eb6f0de0SAdrian Chadd ath_tx_chaindesclist_subframe(struct ath_softc *sc, struct ath_buf *bf) 44081a82688SAdrian Chadd { 44181a82688SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 442eb6f0de0SAdrian Chadd struct ath_desc *ds, *ds0; 443eb6f0de0SAdrian Chadd int i; 444fffbec86SAdrian Chadd HAL_DMA_ADDR bufAddrList[4]; 445fffbec86SAdrian Chadd uint32_t segLenList[4]; 446fffbec86SAdrian Chadd 4473d9b1596SAdrian Chadd /* 4483d9b1596SAdrian Chadd * XXX There's txdma and txdma_mgmt; the descriptor 4493d9b1596SAdrian Chadd * sizes must match. 4503d9b1596SAdrian Chadd */ 4513d9b1596SAdrian Chadd struct ath_descdma *dd = &sc->sc_txdma; 45281a82688SAdrian Chadd 453eb6f0de0SAdrian Chadd ds0 = ds = bf->bf_desc; 454eb6f0de0SAdrian Chadd 455eb6f0de0SAdrian Chadd /* 456eb6f0de0SAdrian Chadd * There's no need to call ath_hal_setupfirsttxdesc here; 457eb6f0de0SAdrian Chadd * That's only going to occur for the first frame in an aggregate. 458eb6f0de0SAdrian Chadd */ 459eb6f0de0SAdrian Chadd for (i = 0; i < bf->bf_nseg; i++, ds++) { 460fffbec86SAdrian Chadd bzero(bufAddrList, sizeof(bufAddrList)); 461fffbec86SAdrian Chadd bzero(segLenList, sizeof(segLenList)); 462eb6f0de0SAdrian Chadd if (i == bf->bf_nseg - 1) 463bb069955SAdrian Chadd ath_hal_settxdesclink(ah, ds, 0); 464eb6f0de0SAdrian Chadd else 465bb069955SAdrian Chadd ath_hal_settxdesclink(ah, ds, 4663d9b1596SAdrian Chadd bf->bf_daddr + dd->dd_descsize * (i + 1)); 467eb6f0de0SAdrian Chadd 468fffbec86SAdrian Chadd bufAddrList[0] = bf->bf_segs[i].ds_addr; 469fffbec86SAdrian Chadd segLenList[0] = bf->bf_segs[i].ds_len; 470fffbec86SAdrian Chadd 471eb6f0de0SAdrian Chadd /* 472eb6f0de0SAdrian Chadd * This performs the setup for an aggregate frame. 473eb6f0de0SAdrian Chadd * This includes enabling the aggregate flags if needed. 474eb6f0de0SAdrian Chadd */ 475eb6f0de0SAdrian Chadd ath_hal_chaintxdesc(ah, ds, 476fffbec86SAdrian Chadd bufAddrList, 477fffbec86SAdrian Chadd segLenList, 478eb6f0de0SAdrian Chadd bf->bf_state.bfs_pktlen, 479eb6f0de0SAdrian Chadd bf->bf_state.bfs_hdrlen, 480eb6f0de0SAdrian Chadd HAL_PKT_TYPE_AMPDU, /* forces aggregate bits to be set */ 481eb6f0de0SAdrian Chadd bf->bf_state.bfs_keyix, 482eb6f0de0SAdrian Chadd 0, /* cipher, calculated from keyix */ 483eb6f0de0SAdrian Chadd bf->bf_state.bfs_ndelim, 484eb6f0de0SAdrian Chadd i == 0, /* first segment */ 48533d34032SAdrian Chadd i == bf->bf_nseg - 1, /* last segment */ 48633d34032SAdrian Chadd bf->bf_next == NULL /* last sub-frame in aggr */ 487eb6f0de0SAdrian Chadd ); 488eb6f0de0SAdrian Chadd 489eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 490eb6f0de0SAdrian Chadd "%s: %d: %08x %08x %08x %08x %08x %08x\n", 491eb6f0de0SAdrian Chadd __func__, i, ds->ds_link, ds->ds_data, 492eb6f0de0SAdrian Chadd ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1]); 493eb6f0de0SAdrian Chadd bf->bf_lastds = ds; 4944d7f8837SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 4954d7f8837SAdrian Chadd BUS_DMASYNC_PREWRITE); 496eb6f0de0SAdrian Chadd } 497eb6f0de0SAdrian Chadd } 498eb6f0de0SAdrian Chadd 499eb6f0de0SAdrian Chadd /* 500d34a7347SAdrian Chadd * Set the rate control fields in the given descriptor based on 501d34a7347SAdrian Chadd * the bf_state fields and node state. 502d34a7347SAdrian Chadd * 503d34a7347SAdrian Chadd * The bfs fields should already be set with the relevant rate 504d34a7347SAdrian Chadd * control information, including whether MRR is to be enabled. 505d34a7347SAdrian Chadd * 506d34a7347SAdrian Chadd * Since the FreeBSD HAL currently sets up the first TX rate 507d34a7347SAdrian Chadd * in ath_hal_setuptxdesc(), this will setup the MRR 508d34a7347SAdrian Chadd * conditionally for the pre-11n chips, and call ath_buf_set_rate 509d34a7347SAdrian Chadd * unconditionally for 11n chips. These require the 11n rate 510d34a7347SAdrian Chadd * scenario to be set if MCS rates are enabled, so it's easier 511d34a7347SAdrian Chadd * to just always call it. The caller can then only set rates 2, 3 512d34a7347SAdrian Chadd * and 4 if multi-rate retry is needed. 513d34a7347SAdrian Chadd */ 514d34a7347SAdrian Chadd static void 515d34a7347SAdrian Chadd ath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni, 516d34a7347SAdrian Chadd struct ath_buf *bf) 517d34a7347SAdrian Chadd { 518d34a7347SAdrian Chadd struct ath_rc_series *rc = bf->bf_state.bfs_rc; 519d34a7347SAdrian Chadd 520d34a7347SAdrian Chadd /* If mrr is disabled, blank tries 1, 2, 3 */ 521d34a7347SAdrian Chadd if (! bf->bf_state.bfs_ismrr) 522d34a7347SAdrian Chadd rc[1].tries = rc[2].tries = rc[3].tries = 0; 523d34a7347SAdrian Chadd 524d34a7347SAdrian Chadd /* 525d34a7347SAdrian Chadd * Always call - that way a retried descriptor will 526d34a7347SAdrian Chadd * have the MRR fields overwritten. 527d34a7347SAdrian Chadd * 528d34a7347SAdrian Chadd * XXX TODO: see if this is really needed - setting up 529d34a7347SAdrian Chadd * the first descriptor should set the MRR fields to 0 530d34a7347SAdrian Chadd * for us anyway. 531d34a7347SAdrian Chadd */ 532d34a7347SAdrian Chadd if (ath_tx_is_11n(sc)) { 533d34a7347SAdrian Chadd ath_buf_set_rate(sc, ni, bf); 534d34a7347SAdrian Chadd } else { 535d34a7347SAdrian Chadd ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc 536d34a7347SAdrian Chadd , rc[1].ratecode, rc[1].tries 537d34a7347SAdrian Chadd , rc[2].ratecode, rc[2].tries 538d34a7347SAdrian Chadd , rc[3].ratecode, rc[3].tries 539d34a7347SAdrian Chadd ); 540d34a7347SAdrian Chadd } 541d34a7347SAdrian Chadd } 542d34a7347SAdrian Chadd 543d34a7347SAdrian Chadd /* 544eb6f0de0SAdrian Chadd * Setup segments+descriptors for an 11n aggregate. 545eb6f0de0SAdrian Chadd * bf_first is the first buffer in the aggregate. 546eb6f0de0SAdrian Chadd * The descriptor list must already been linked together using 547eb6f0de0SAdrian Chadd * bf->bf_next. 548eb6f0de0SAdrian Chadd */ 549eb6f0de0SAdrian Chadd static void 550eb6f0de0SAdrian Chadd ath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first) 551eb6f0de0SAdrian Chadd { 552eb6f0de0SAdrian Chadd struct ath_buf *bf, *bf_prev = NULL; 553eb6f0de0SAdrian Chadd 554eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n", 555eb6f0de0SAdrian Chadd __func__, bf_first->bf_state.bfs_nframes, 556eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_al); 557eb6f0de0SAdrian Chadd 558eb6f0de0SAdrian Chadd /* 559eb6f0de0SAdrian Chadd * Setup all descriptors of all subframes. 560eb6f0de0SAdrian Chadd */ 561eb6f0de0SAdrian Chadd bf = bf_first; 562eb6f0de0SAdrian Chadd while (bf != NULL) { 563eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 564eb6f0de0SAdrian Chadd "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n", 565eb6f0de0SAdrian Chadd __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen, 566eb6f0de0SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)); 567eb6f0de0SAdrian Chadd 568eb6f0de0SAdrian Chadd /* Sub-frame setup */ 569eb6f0de0SAdrian Chadd ath_tx_chaindesclist_subframe(sc, bf); 570eb6f0de0SAdrian Chadd 571eb6f0de0SAdrian Chadd /* 572eb6f0de0SAdrian Chadd * Link the last descriptor of the previous frame 573eb6f0de0SAdrian Chadd * to the beginning descriptor of this frame. 574eb6f0de0SAdrian Chadd */ 575eb6f0de0SAdrian Chadd if (bf_prev != NULL) 576bb069955SAdrian Chadd ath_hal_settxdesclink(sc->sc_ah, bf_prev->bf_lastds, 577bb069955SAdrian Chadd bf->bf_daddr); 578eb6f0de0SAdrian Chadd 579eb6f0de0SAdrian Chadd /* Save a copy so we can link the next descriptor in */ 580eb6f0de0SAdrian Chadd bf_prev = bf; 581eb6f0de0SAdrian Chadd bf = bf->bf_next; 582eb6f0de0SAdrian Chadd } 583eb6f0de0SAdrian Chadd 584eb6f0de0SAdrian Chadd /* 585eb6f0de0SAdrian Chadd * Setup first descriptor of first frame. 586eb6f0de0SAdrian Chadd * chaintxdesc() overwrites the descriptor entries; 587eb6f0de0SAdrian Chadd * setupfirsttxdesc() merges in things. 588eb6f0de0SAdrian Chadd * Otherwise various fields aren't set correctly (eg flags). 589eb6f0de0SAdrian Chadd */ 590eb6f0de0SAdrian Chadd ath_hal_setupfirsttxdesc(sc->sc_ah, 591eb6f0de0SAdrian Chadd bf_first->bf_desc, 592eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_al, 593875a9451SAdrian Chadd bf_first->bf_state.bfs_txflags | HAL_TXDESC_INTREQ, 594eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_txpower, 595eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_txrate0, 596eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_try0, 597eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_txantenna, 598eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_ctsrate, 599eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_ctsduration); 600eb6f0de0SAdrian Chadd 601eb6f0de0SAdrian Chadd /* 602eb6f0de0SAdrian Chadd * Set the first descriptor bf_lastds field to point to 603eb6f0de0SAdrian Chadd * the last descriptor in the last subframe, that's where 604eb6f0de0SAdrian Chadd * the status update will occur. 605eb6f0de0SAdrian Chadd */ 606eb6f0de0SAdrian Chadd bf_first->bf_lastds = bf_prev->bf_lastds; 607eb6f0de0SAdrian Chadd 608eb6f0de0SAdrian Chadd /* 609eb6f0de0SAdrian Chadd * And bf_last in the first descriptor points to the end of 610eb6f0de0SAdrian Chadd * the aggregate list. 611eb6f0de0SAdrian Chadd */ 612eb6f0de0SAdrian Chadd bf_first->bf_last = bf_prev; 613eb6f0de0SAdrian Chadd 614d34a7347SAdrian Chadd /* 615d34a7347SAdrian Chadd * setup first desc with rate and aggr info 616d34a7347SAdrian Chadd */ 617d34a7347SAdrian Chadd ath_tx_set_ratectrl(sc, bf_first->bf_node, bf_first); 618d34a7347SAdrian Chadd 6198c08c07aSAdrian Chadd /* 6208c08c07aSAdrian Chadd * Setup the last descriptor in the list. 621a6e82959SAdrian Chadd * 622a6e82959SAdrian Chadd * bf_first->bf_lastds already points to it; the rate 623a6e82959SAdrian Chadd * control information needs to be squirreled away here 624a6e82959SAdrian Chadd * as well ans clearing the moreaggr/paddelim fields. 6258c08c07aSAdrian Chadd */ 626a6e82959SAdrian Chadd ath_hal_setuplasttxdesc(sc->sc_ah, bf_first->bf_lastds, 6278c08c07aSAdrian Chadd bf_first->bf_desc); 6288c08c07aSAdrian Chadd 629eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__); 630eb6f0de0SAdrian Chadd } 631eb6f0de0SAdrian Chadd 63246634305SAdrian Chadd /* 63346634305SAdrian Chadd * Hand-off a frame to the multicast TX queue. 63446634305SAdrian Chadd * 63546634305SAdrian Chadd * This is a software TXQ which will be appended to the CAB queue 63646634305SAdrian Chadd * during the beacon setup code. 63746634305SAdrian Chadd * 63846634305SAdrian Chadd * XXX TODO: since the AR9300 EDMA TX queue support wants the QCU ID 63946634305SAdrian Chadd * as part of the TX descriptor, bf_state.bfs_txq must be updated 64046634305SAdrian Chadd * with the actual hardware txq, or all of this will fall apart. 64146634305SAdrian Chadd * 64246634305SAdrian Chadd * XXX It may not be a bad idea to just stuff the QCU ID into bf_state 64346634305SAdrian Chadd * and retire bfs_txq; then make sure the CABQ QCU ID is populated 64446634305SAdrian Chadd * correctly. 64546634305SAdrian Chadd */ 646eb6f0de0SAdrian Chadd static void 647eb6f0de0SAdrian Chadd ath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq, 648eb6f0de0SAdrian Chadd struct ath_buf *bf) 649eb6f0de0SAdrian Chadd { 650eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 651eb6f0de0SAdrian Chadd KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 652eb6f0de0SAdrian Chadd ("%s: busy status 0x%x", __func__, bf->bf_flags)); 653eb6f0de0SAdrian Chadd if (txq->axq_link != NULL) { 654eb6f0de0SAdrian Chadd struct ath_buf *last = ATH_TXQ_LAST(txq, axq_q_s); 655eb6f0de0SAdrian Chadd struct ieee80211_frame *wh; 656eb6f0de0SAdrian Chadd 657eb6f0de0SAdrian Chadd /* mark previous frame */ 658eb6f0de0SAdrian Chadd wh = mtod(last->bf_m, struct ieee80211_frame *); 659eb6f0de0SAdrian Chadd wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; 660eb6f0de0SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, last->bf_dmamap, 661eb6f0de0SAdrian Chadd BUS_DMASYNC_PREWRITE); 662eb6f0de0SAdrian Chadd 663eb6f0de0SAdrian Chadd /* link descriptor */ 664eb6f0de0SAdrian Chadd *txq->axq_link = bf->bf_daddr; 665eb6f0de0SAdrian Chadd } 666eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 667bb069955SAdrian Chadd ath_hal_gettxdesclinkptr(sc->sc_ah, bf->bf_lastds, &txq->axq_link); 668eb6f0de0SAdrian Chadd } 669eb6f0de0SAdrian Chadd 670eb6f0de0SAdrian Chadd /* 671eb6f0de0SAdrian Chadd * Hand-off packet to a hardware queue. 672eb6f0de0SAdrian Chadd */ 673eb6f0de0SAdrian Chadd static void 674d4365d16SAdrian Chadd ath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq, 675d4365d16SAdrian Chadd struct ath_buf *bf) 676eb6f0de0SAdrian Chadd { 677eb6f0de0SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 67881a82688SAdrian Chadd 679b8e788a5SAdrian Chadd /* 680b8e788a5SAdrian Chadd * Insert the frame on the outbound list and pass it on 681b8e788a5SAdrian Chadd * to the hardware. Multicast frames buffered for power 682b8e788a5SAdrian Chadd * save stations and transmit from the CAB queue are stored 683b8e788a5SAdrian Chadd * on a s/w only queue and loaded on to the CAB queue in 684b8e788a5SAdrian Chadd * the SWBA handler since frames only go out on DTIM and 685b8e788a5SAdrian Chadd * to avoid possible races. 686b8e788a5SAdrian Chadd */ 687eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 688b8e788a5SAdrian Chadd KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 689eb6f0de0SAdrian Chadd ("%s: busy status 0x%x", __func__, bf->bf_flags)); 690eb6f0de0SAdrian Chadd KASSERT(txq->axq_qnum != ATH_TXQ_SWQ, 691eb6f0de0SAdrian Chadd ("ath_tx_handoff_hw called for mcast queue")); 692eb6f0de0SAdrian Chadd 693ef27340cSAdrian Chadd #if 0 694ef27340cSAdrian Chadd /* 695ef27340cSAdrian Chadd * This causes a LOR. Find out where the PCU lock is being 696ef27340cSAdrian Chadd * held whilst the TXQ lock is grabbed - that shouldn't 697ef27340cSAdrian Chadd * be occuring. 698ef27340cSAdrian Chadd */ 699ef27340cSAdrian Chadd ATH_PCU_LOCK(sc); 700ef27340cSAdrian Chadd if (sc->sc_inreset_cnt) { 701ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 702ef27340cSAdrian Chadd DPRINTF(sc, ATH_DEBUG_RESET, 703ef27340cSAdrian Chadd "%s: called with sc_in_reset != 0\n", 704ef27340cSAdrian Chadd __func__); 705ef27340cSAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 706ef27340cSAdrian Chadd "%s: queued: TXDP[%u] = %p (%p) depth %d\n", 707ef27340cSAdrian Chadd __func__, txq->axq_qnum, 708ef27340cSAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 709ef27340cSAdrian Chadd txq->axq_depth); 710ef27340cSAdrian Chadd ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 711ef27340cSAdrian Chadd if (bf->bf_state.bfs_aggr) 712ef27340cSAdrian Chadd txq->axq_aggr_depth++; 713ef27340cSAdrian Chadd /* 714ef27340cSAdrian Chadd * There's no need to update axq_link; the hardware 715ef27340cSAdrian Chadd * is in reset and once the reset is complete, any 716ef27340cSAdrian Chadd * non-empty queues will simply have DMA restarted. 717ef27340cSAdrian Chadd */ 718ef27340cSAdrian Chadd return; 719ef27340cSAdrian Chadd } 720ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 721ef27340cSAdrian Chadd #endif 722ef27340cSAdrian Chadd 723eb6f0de0SAdrian Chadd /* For now, so not to generate whitespace diffs */ 724eb6f0de0SAdrian Chadd if (1) { 725b8e788a5SAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA 726b8e788a5SAdrian Chadd int qbusy; 727b8e788a5SAdrian Chadd 728b8e788a5SAdrian Chadd ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 729b8e788a5SAdrian Chadd qbusy = ath_hal_txqenabled(ah, txq->axq_qnum); 73003682514SAdrian Chadd 73103682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 4, 73203682514SAdrian Chadd "ath_tx_handoff: txq=%u, add bf=%p, qbusy=%d, depth=%d", 73303682514SAdrian Chadd txq->axq_qnum, bf, qbusy, txq->axq_depth); 734b8e788a5SAdrian Chadd if (txq->axq_link == NULL) { 735b8e788a5SAdrian Chadd /* 736b8e788a5SAdrian Chadd * Be careful writing the address to TXDP. If 737b8e788a5SAdrian Chadd * the tx q is enabled then this write will be 738b8e788a5SAdrian Chadd * ignored. Normally this is not an issue but 739b8e788a5SAdrian Chadd * when tdma is in use and the q is beacon gated 740b8e788a5SAdrian Chadd * this race can occur. If the q is busy then 741b8e788a5SAdrian Chadd * defer the work to later--either when another 742b8e788a5SAdrian Chadd * packet comes along or when we prepare a beacon 743b8e788a5SAdrian Chadd * frame at SWBA. 744b8e788a5SAdrian Chadd */ 745b8e788a5SAdrian Chadd if (!qbusy) { 746d4365d16SAdrian Chadd ath_hal_puttxbuf(ah, txq->axq_qnum, 747d4365d16SAdrian Chadd bf->bf_daddr); 748b8e788a5SAdrian Chadd txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 749b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 75003682514SAdrian Chadd "%s: TXDP[%u] = %p (%p) lastds=%p depth %d\n", 751b8e788a5SAdrian Chadd __func__, txq->axq_qnum, 752b8e788a5SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 75303682514SAdrian Chadd bf->bf_lastds, 75403682514SAdrian Chadd txq->axq_depth); 75503682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 5, 75603682514SAdrian Chadd "ath_tx_handoff: TXDP[%u] = %p (%p) " 75703682514SAdrian Chadd "lastds=%p depth %d", 75803682514SAdrian Chadd txq->axq_qnum, 75903682514SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 76003682514SAdrian Chadd bf->bf_lastds, 761b8e788a5SAdrian Chadd txq->axq_depth); 762b8e788a5SAdrian Chadd } else { 763b8e788a5SAdrian Chadd txq->axq_flags |= ATH_TXQ_PUTPENDING; 764b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 765b8e788a5SAdrian Chadd "%s: Q%u busy, defer enable\n", __func__, 766b8e788a5SAdrian Chadd txq->axq_qnum); 76703682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 0, "defer enable"); 768b8e788a5SAdrian Chadd } 769b8e788a5SAdrian Chadd } else { 770b8e788a5SAdrian Chadd *txq->axq_link = bf->bf_daddr; 771b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 772b8e788a5SAdrian Chadd "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 773b8e788a5SAdrian Chadd txq->axq_qnum, txq->axq_link, 774d4365d16SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 775d4365d16SAdrian Chadd txq->axq_depth); 77603682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 5, 77703682514SAdrian Chadd "ath_tx_handoff: link[%u](%p)=%p (%p) lastds=%p", 77803682514SAdrian Chadd txq->axq_qnum, txq->axq_link, 77903682514SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 78003682514SAdrian Chadd bf->bf_lastds); 78103682514SAdrian Chadd 782b8e788a5SAdrian Chadd if ((txq->axq_flags & ATH_TXQ_PUTPENDING) && !qbusy) { 783b8e788a5SAdrian Chadd /* 784b8e788a5SAdrian Chadd * The q was busy when we previously tried 785b8e788a5SAdrian Chadd * to write the address of the first buffer 786b8e788a5SAdrian Chadd * in the chain. Since it's not busy now 787b8e788a5SAdrian Chadd * handle this chore. We are certain the 788b8e788a5SAdrian Chadd * buffer at the front is the right one since 789b8e788a5SAdrian Chadd * axq_link is NULL only when the buffer list 790b8e788a5SAdrian Chadd * is/was empty. 791b8e788a5SAdrian Chadd */ 792b8e788a5SAdrian Chadd ath_hal_puttxbuf(ah, txq->axq_qnum, 7936b349e5aSAdrian Chadd TAILQ_FIRST(&txq->axq_q)->bf_daddr); 794b8e788a5SAdrian Chadd txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 795b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 796b8e788a5SAdrian Chadd "%s: Q%u restarted\n", __func__, 797b8e788a5SAdrian Chadd txq->axq_qnum); 79803682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 4, 79903682514SAdrian Chadd "ath_tx_handoff: txq[%d] restarted, bf=%p " 80003682514SAdrian Chadd "daddr=%p ds=%p", 80103682514SAdrian Chadd txq->axq_qnum, 80203682514SAdrian Chadd bf, 80303682514SAdrian Chadd (caddr_t)bf->bf_daddr, 80403682514SAdrian Chadd bf->bf_desc); 805b8e788a5SAdrian Chadd } 806b8e788a5SAdrian Chadd } 807b8e788a5SAdrian Chadd #else 808b8e788a5SAdrian Chadd ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 80903682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 4, 81003682514SAdrian Chadd "ath_tx_handoff: non-tdma: txq=%u, add bf=%p, qbusy=%d, " 81103682514SAdrian Chadd "depth=%d", 81203682514SAdrian Chadd txq->axq_qnum, 81303682514SAdrian Chadd bf, 81403682514SAdrian Chadd qbusy, 81503682514SAdrian Chadd txq->axq_depth); 816b8e788a5SAdrian Chadd if (txq->axq_link == NULL) { 817b8e788a5SAdrian Chadd ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 818b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 819b8e788a5SAdrian Chadd "%s: TXDP[%u] = %p (%p) depth %d\n", 820b8e788a5SAdrian Chadd __func__, txq->axq_qnum, 821b8e788a5SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 822b8e788a5SAdrian Chadd txq->axq_depth); 82303682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 5, 82403682514SAdrian Chadd "ath_tx_handoff: non-tdma: TXDP[%u] = %p (%p) " 82503682514SAdrian Chadd "lastds=%p depth %d", 82603682514SAdrian Chadd txq->axq_qnum, 82703682514SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 82803682514SAdrian Chadd bf->bf_lastds, 82903682514SAdrian Chadd txq->axq_depth); 83003682514SAdrian Chadd 831b8e788a5SAdrian Chadd } else { 832b8e788a5SAdrian Chadd *txq->axq_link = bf->bf_daddr; 833b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 834b8e788a5SAdrian Chadd "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 835b8e788a5SAdrian Chadd txq->axq_qnum, txq->axq_link, 836d4365d16SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 837d4365d16SAdrian Chadd txq->axq_depth); 83803682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 5, 83903682514SAdrian Chadd "ath_tx_handoff: non-tdma: link[%u](%p)=%p (%p) " 84003682514SAdrian Chadd "lastds=%d", 84103682514SAdrian Chadd txq->axq_qnum, txq->axq_link, 84203682514SAdrian Chadd (caddr_t)bf->bf_daddr, bf->bf_desc, 84303682514SAdrian Chadd bf->bf_lastds); 84403682514SAdrian Chadd 845b8e788a5SAdrian Chadd } 846b8e788a5SAdrian Chadd #endif /* IEEE80211_SUPPORT_TDMA */ 8476edf1dc7SAdrian Chadd if (bf->bf_state.bfs_aggr) 8486edf1dc7SAdrian Chadd txq->axq_aggr_depth++; 849bb069955SAdrian Chadd ath_hal_gettxdesclinkptr(ah, bf->bf_lastds, &txq->axq_link); 850b8e788a5SAdrian Chadd ath_hal_txstart(ah, txq->axq_qnum); 85103682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 1, 85203682514SAdrian Chadd "ath_tx_handoff: txq=%u, txstart", txq->axq_qnum); 853b8e788a5SAdrian Chadd } 854b8e788a5SAdrian Chadd } 855eb6f0de0SAdrian Chadd 856eb6f0de0SAdrian Chadd /* 857eb6f0de0SAdrian Chadd * Restart TX DMA for the given TXQ. 858eb6f0de0SAdrian Chadd * 859eb6f0de0SAdrian Chadd * This must be called whether the queue is empty or not. 860eb6f0de0SAdrian Chadd */ 861746bab5bSAdrian Chadd static void 862746bab5bSAdrian Chadd ath_legacy_tx_dma_restart(struct ath_softc *sc, struct ath_txq *txq) 863eb6f0de0SAdrian Chadd { 864eb6f0de0SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 865b1f3262cSAdrian Chadd struct ath_buf *bf, *bf_last; 866eb6f0de0SAdrian Chadd 867eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 868eb6f0de0SAdrian Chadd 869eb6f0de0SAdrian Chadd /* This is always going to be cleared, empty or not */ 870eb6f0de0SAdrian Chadd txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 871eb6f0de0SAdrian Chadd 872b1f3262cSAdrian Chadd /* XXX make this ATH_TXQ_FIRST */ 873eb6f0de0SAdrian Chadd bf = TAILQ_FIRST(&txq->axq_q); 874b1f3262cSAdrian Chadd bf_last = ATH_TXQ_LAST(txq, axq_q_s); 875b1f3262cSAdrian Chadd 876eb6f0de0SAdrian Chadd if (bf == NULL) 877eb6f0de0SAdrian Chadd return; 878eb6f0de0SAdrian Chadd 879eb6f0de0SAdrian Chadd ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 880d2da5544SAdrian Chadd ath_hal_gettxdesclinkptr(ah, bf_last->bf_lastds, &txq->axq_link); 881eb6f0de0SAdrian Chadd ath_hal_txstart(ah, txq->axq_qnum); 882eb6f0de0SAdrian Chadd } 883eb6f0de0SAdrian Chadd 884eb6f0de0SAdrian Chadd /* 885eb6f0de0SAdrian Chadd * Hand off a packet to the hardware (or mcast queue.) 886eb6f0de0SAdrian Chadd * 887eb6f0de0SAdrian Chadd * The relevant hardware txq should be locked. 888eb6f0de0SAdrian Chadd */ 889eb6f0de0SAdrian Chadd static void 890746bab5bSAdrian Chadd ath_legacy_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq, 891746bab5bSAdrian Chadd struct ath_buf *bf) 892eb6f0de0SAdrian Chadd { 893eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 894eb6f0de0SAdrian Chadd 895eb6f0de0SAdrian Chadd if (txq->axq_qnum == ATH_TXQ_SWQ) 896eb6f0de0SAdrian Chadd ath_tx_handoff_mcast(sc, txq, bf); 897eb6f0de0SAdrian Chadd else 898eb6f0de0SAdrian Chadd ath_tx_handoff_hw(sc, txq, bf); 899b8e788a5SAdrian Chadd } 900b8e788a5SAdrian Chadd 90181a82688SAdrian Chadd static int 90281a82688SAdrian Chadd ath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni, 903d4365d16SAdrian Chadd struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen, 904d4365d16SAdrian Chadd int *keyix) 90581a82688SAdrian Chadd { 90612be5b9cSAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, 90712be5b9cSAdrian Chadd "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n", 90812be5b9cSAdrian Chadd __func__, 90912be5b9cSAdrian Chadd *hdrlen, 91012be5b9cSAdrian Chadd *pktlen, 91112be5b9cSAdrian Chadd isfrag, 91212be5b9cSAdrian Chadd iswep, 91312be5b9cSAdrian Chadd m0); 91412be5b9cSAdrian Chadd 91581a82688SAdrian Chadd if (iswep) { 91681a82688SAdrian Chadd const struct ieee80211_cipher *cip; 91781a82688SAdrian Chadd struct ieee80211_key *k; 91881a82688SAdrian Chadd 91981a82688SAdrian Chadd /* 92081a82688SAdrian Chadd * Construct the 802.11 header+trailer for an encrypted 92181a82688SAdrian Chadd * frame. The only reason this can fail is because of an 92281a82688SAdrian Chadd * unknown or unsupported cipher/key type. 92381a82688SAdrian Chadd */ 92481a82688SAdrian Chadd k = ieee80211_crypto_encap(ni, m0); 92581a82688SAdrian Chadd if (k == NULL) { 92681a82688SAdrian Chadd /* 92781a82688SAdrian Chadd * This can happen when the key is yanked after the 92881a82688SAdrian Chadd * frame was queued. Just discard the frame; the 92981a82688SAdrian Chadd * 802.11 layer counts failures and provides 93081a82688SAdrian Chadd * debugging/diagnostics. 93181a82688SAdrian Chadd */ 932d4365d16SAdrian Chadd return (0); 93381a82688SAdrian Chadd } 93481a82688SAdrian Chadd /* 93581a82688SAdrian Chadd * Adjust the packet + header lengths for the crypto 93681a82688SAdrian Chadd * additions and calculate the h/w key index. When 93781a82688SAdrian Chadd * a s/w mic is done the frame will have had any mic 93881a82688SAdrian Chadd * added to it prior to entry so m0->m_pkthdr.len will 93981a82688SAdrian Chadd * account for it. Otherwise we need to add it to the 94081a82688SAdrian Chadd * packet length. 94181a82688SAdrian Chadd */ 94281a82688SAdrian Chadd cip = k->wk_cipher; 94381a82688SAdrian Chadd (*hdrlen) += cip->ic_header; 94481a82688SAdrian Chadd (*pktlen) += cip->ic_header + cip->ic_trailer; 94581a82688SAdrian Chadd /* NB: frags always have any TKIP MIC done in s/w */ 94681a82688SAdrian Chadd if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag) 94781a82688SAdrian Chadd (*pktlen) += cip->ic_miclen; 94881a82688SAdrian Chadd (*keyix) = k->wk_keyix; 94981a82688SAdrian Chadd } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { 95081a82688SAdrian Chadd /* 95181a82688SAdrian Chadd * Use station key cache slot, if assigned. 95281a82688SAdrian Chadd */ 95381a82688SAdrian Chadd (*keyix) = ni->ni_ucastkey.wk_keyix; 95481a82688SAdrian Chadd if ((*keyix) == IEEE80211_KEYIX_NONE) 95581a82688SAdrian Chadd (*keyix) = HAL_TXKEYIX_INVALID; 95681a82688SAdrian Chadd } else 95781a82688SAdrian Chadd (*keyix) = HAL_TXKEYIX_INVALID; 95881a82688SAdrian Chadd 959d4365d16SAdrian Chadd return (1); 96081a82688SAdrian Chadd } 96181a82688SAdrian Chadd 962e2e4a2c2SAdrian Chadd /* 963e2e4a2c2SAdrian Chadd * Calculate whether interoperability protection is required for 964e2e4a2c2SAdrian Chadd * this frame. 965e2e4a2c2SAdrian Chadd * 966e2e4a2c2SAdrian Chadd * This requires the rate control information be filled in, 967e2e4a2c2SAdrian Chadd * as the protection requirement depends upon the current 968e2e4a2c2SAdrian Chadd * operating mode / PHY. 969e2e4a2c2SAdrian Chadd */ 970e2e4a2c2SAdrian Chadd static void 971e2e4a2c2SAdrian Chadd ath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf) 972e2e4a2c2SAdrian Chadd { 973e2e4a2c2SAdrian Chadd struct ieee80211_frame *wh; 974e2e4a2c2SAdrian Chadd uint8_t rix; 975e2e4a2c2SAdrian Chadd uint16_t flags; 976e2e4a2c2SAdrian Chadd int shortPreamble; 977e2e4a2c2SAdrian Chadd const HAL_RATE_TABLE *rt = sc->sc_currates; 978e2e4a2c2SAdrian Chadd struct ifnet *ifp = sc->sc_ifp; 979e2e4a2c2SAdrian Chadd struct ieee80211com *ic = ifp->if_l2com; 980e2e4a2c2SAdrian Chadd 981e2e4a2c2SAdrian Chadd flags = bf->bf_state.bfs_txflags; 982e2e4a2c2SAdrian Chadd rix = bf->bf_state.bfs_rc[0].rix; 983e2e4a2c2SAdrian Chadd shortPreamble = bf->bf_state.bfs_shpream; 984e2e4a2c2SAdrian Chadd wh = mtod(bf->bf_m, struct ieee80211_frame *); 985e2e4a2c2SAdrian Chadd 986e2e4a2c2SAdrian Chadd /* 987e2e4a2c2SAdrian Chadd * If 802.11g protection is enabled, determine whether 988e2e4a2c2SAdrian Chadd * to use RTS/CTS or just CTS. Note that this is only 989e2e4a2c2SAdrian Chadd * done for OFDM unicast frames. 990e2e4a2c2SAdrian Chadd */ 991e2e4a2c2SAdrian Chadd if ((ic->ic_flags & IEEE80211_F_USEPROT) && 992e2e4a2c2SAdrian Chadd rt->info[rix].phy == IEEE80211_T_OFDM && 993e2e4a2c2SAdrian Chadd (flags & HAL_TXDESC_NOACK) == 0) { 994e2e4a2c2SAdrian Chadd bf->bf_state.bfs_doprot = 1; 995e2e4a2c2SAdrian Chadd /* XXX fragments must use CCK rates w/ protection */ 996e2e4a2c2SAdrian Chadd if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) { 997e2e4a2c2SAdrian Chadd flags |= HAL_TXDESC_RTSENA; 998e2e4a2c2SAdrian Chadd } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) { 999e2e4a2c2SAdrian Chadd flags |= HAL_TXDESC_CTSENA; 1000e2e4a2c2SAdrian Chadd } 1001e2e4a2c2SAdrian Chadd /* 1002e2e4a2c2SAdrian Chadd * For frags it would be desirable to use the 1003e2e4a2c2SAdrian Chadd * highest CCK rate for RTS/CTS. But stations 1004e2e4a2c2SAdrian Chadd * farther away may detect it at a lower CCK rate 1005e2e4a2c2SAdrian Chadd * so use the configured protection rate instead 1006e2e4a2c2SAdrian Chadd * (for now). 1007e2e4a2c2SAdrian Chadd */ 1008e2e4a2c2SAdrian Chadd sc->sc_stats.ast_tx_protect++; 1009e2e4a2c2SAdrian Chadd } 1010e2e4a2c2SAdrian Chadd 1011e2e4a2c2SAdrian Chadd /* 1012e2e4a2c2SAdrian Chadd * If 11n protection is enabled and it's a HT frame, 1013e2e4a2c2SAdrian Chadd * enable RTS. 1014e2e4a2c2SAdrian Chadd * 1015e2e4a2c2SAdrian Chadd * XXX ic_htprotmode or ic_curhtprotmode? 1016e2e4a2c2SAdrian Chadd * XXX should it_htprotmode only matter if ic_curhtprotmode 1017e2e4a2c2SAdrian Chadd * XXX indicates it's not a HT pure environment? 1018e2e4a2c2SAdrian Chadd */ 1019e2e4a2c2SAdrian Chadd if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && 1020e2e4a2c2SAdrian Chadd rt->info[rix].phy == IEEE80211_T_HT && 1021e2e4a2c2SAdrian Chadd (flags & HAL_TXDESC_NOACK) == 0) { 1022e2e4a2c2SAdrian Chadd flags |= HAL_TXDESC_RTSENA; 1023e2e4a2c2SAdrian Chadd sc->sc_stats.ast_tx_htprotect++; 1024e2e4a2c2SAdrian Chadd } 1025e2e4a2c2SAdrian Chadd bf->bf_state.bfs_txflags = flags; 1026e2e4a2c2SAdrian Chadd } 1027e2e4a2c2SAdrian Chadd 1028e2e4a2c2SAdrian Chadd /* 1029e2e4a2c2SAdrian Chadd * Update the frame duration given the currently selected rate. 1030e2e4a2c2SAdrian Chadd * 1031e2e4a2c2SAdrian Chadd * This also updates the frame duration value, so it will require 1032e2e4a2c2SAdrian Chadd * a DMA flush. 1033e2e4a2c2SAdrian Chadd */ 1034e2e4a2c2SAdrian Chadd static void 1035e2e4a2c2SAdrian Chadd ath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf) 1036e2e4a2c2SAdrian Chadd { 1037e2e4a2c2SAdrian Chadd struct ieee80211_frame *wh; 1038e2e4a2c2SAdrian Chadd uint8_t rix; 1039e2e4a2c2SAdrian Chadd uint16_t flags; 1040e2e4a2c2SAdrian Chadd int shortPreamble; 1041e2e4a2c2SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1042e2e4a2c2SAdrian Chadd const HAL_RATE_TABLE *rt = sc->sc_currates; 1043e2e4a2c2SAdrian Chadd int isfrag = bf->bf_m->m_flags & M_FRAG; 1044e2e4a2c2SAdrian Chadd 1045e2e4a2c2SAdrian Chadd flags = bf->bf_state.bfs_txflags; 1046e2e4a2c2SAdrian Chadd rix = bf->bf_state.bfs_rc[0].rix; 1047e2e4a2c2SAdrian Chadd shortPreamble = bf->bf_state.bfs_shpream; 1048e2e4a2c2SAdrian Chadd wh = mtod(bf->bf_m, struct ieee80211_frame *); 1049e2e4a2c2SAdrian Chadd 1050e2e4a2c2SAdrian Chadd /* 1051e2e4a2c2SAdrian Chadd * Calculate duration. This logically belongs in the 802.11 1052e2e4a2c2SAdrian Chadd * layer but it lacks sufficient information to calculate it. 1053e2e4a2c2SAdrian Chadd */ 1054e2e4a2c2SAdrian Chadd if ((flags & HAL_TXDESC_NOACK) == 0 && 1055e2e4a2c2SAdrian Chadd (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) { 1056e2e4a2c2SAdrian Chadd u_int16_t dur; 1057e2e4a2c2SAdrian Chadd if (shortPreamble) 1058e2e4a2c2SAdrian Chadd dur = rt->info[rix].spAckDuration; 1059e2e4a2c2SAdrian Chadd else 1060e2e4a2c2SAdrian Chadd dur = rt->info[rix].lpAckDuration; 1061e2e4a2c2SAdrian Chadd if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { 1062e2e4a2c2SAdrian Chadd dur += dur; /* additional SIFS+ACK */ 1063e2e4a2c2SAdrian Chadd KASSERT(bf->bf_m->m_nextpkt != NULL, ("no fragment")); 1064e2e4a2c2SAdrian Chadd /* 1065e2e4a2c2SAdrian Chadd * Include the size of next fragment so NAV is 1066e2e4a2c2SAdrian Chadd * updated properly. The last fragment uses only 1067e2e4a2c2SAdrian Chadd * the ACK duration 1068e2e4a2c2SAdrian Chadd */ 1069e2e4a2c2SAdrian Chadd dur += ath_hal_computetxtime(ah, rt, 1070e2e4a2c2SAdrian Chadd bf->bf_m->m_nextpkt->m_pkthdr.len, 1071e2e4a2c2SAdrian Chadd rix, shortPreamble); 1072e2e4a2c2SAdrian Chadd } 1073e2e4a2c2SAdrian Chadd if (isfrag) { 1074e2e4a2c2SAdrian Chadd /* 1075e2e4a2c2SAdrian Chadd * Force hardware to use computed duration for next 1076e2e4a2c2SAdrian Chadd * fragment by disabling multi-rate retry which updates 1077e2e4a2c2SAdrian Chadd * duration based on the multi-rate duration table. 1078e2e4a2c2SAdrian Chadd */ 1079e2e4a2c2SAdrian Chadd bf->bf_state.bfs_ismrr = 0; 1080e2e4a2c2SAdrian Chadd bf->bf_state.bfs_try0 = ATH_TXMGTTRY; 1081e2e4a2c2SAdrian Chadd /* XXX update bfs_rc[0].try? */ 1082e2e4a2c2SAdrian Chadd } 1083e2e4a2c2SAdrian Chadd 1084e2e4a2c2SAdrian Chadd /* Update the duration field itself */ 1085e2e4a2c2SAdrian Chadd *(u_int16_t *)wh->i_dur = htole16(dur); 1086e2e4a2c2SAdrian Chadd } 1087e2e4a2c2SAdrian Chadd } 1088e2e4a2c2SAdrian Chadd 1089e42b5dbaSAdrian Chadd static uint8_t 1090e42b5dbaSAdrian Chadd ath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt, 1091eb6f0de0SAdrian Chadd int cix, int shortPreamble) 109279f02dbfSAdrian Chadd { 1093e42b5dbaSAdrian Chadd uint8_t ctsrate; 1094e42b5dbaSAdrian Chadd 109579f02dbfSAdrian Chadd /* 109679f02dbfSAdrian Chadd * CTS transmit rate is derived from the transmit rate 109779f02dbfSAdrian Chadd * by looking in the h/w rate table. We must also factor 109879f02dbfSAdrian Chadd * in whether or not a short preamble is to be used. 109979f02dbfSAdrian Chadd */ 110079f02dbfSAdrian Chadd /* NB: cix is set above where RTS/CTS is enabled */ 110179f02dbfSAdrian Chadd KASSERT(cix != 0xff, ("cix not setup")); 1102e42b5dbaSAdrian Chadd ctsrate = rt->info[cix].rateCode; 1103e42b5dbaSAdrian Chadd 1104e42b5dbaSAdrian Chadd /* XXX this should only matter for legacy rates */ 1105e42b5dbaSAdrian Chadd if (shortPreamble) 1106e42b5dbaSAdrian Chadd ctsrate |= rt->info[cix].shortPreamble; 1107e42b5dbaSAdrian Chadd 1108d4365d16SAdrian Chadd return (ctsrate); 1109e42b5dbaSAdrian Chadd } 1110e42b5dbaSAdrian Chadd 1111e42b5dbaSAdrian Chadd /* 1112e42b5dbaSAdrian Chadd * Calculate the RTS/CTS duration for legacy frames. 1113e42b5dbaSAdrian Chadd */ 1114e42b5dbaSAdrian Chadd static int 1115e42b5dbaSAdrian Chadd ath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix, 1116e42b5dbaSAdrian Chadd int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt, 1117e42b5dbaSAdrian Chadd int flags) 1118e42b5dbaSAdrian Chadd { 1119e42b5dbaSAdrian Chadd int ctsduration = 0; 1120e42b5dbaSAdrian Chadd 1121e42b5dbaSAdrian Chadd /* This mustn't be called for HT modes */ 1122e42b5dbaSAdrian Chadd if (rt->info[cix].phy == IEEE80211_T_HT) { 1123e42b5dbaSAdrian Chadd printf("%s: HT rate where it shouldn't be (0x%x)\n", 1124e42b5dbaSAdrian Chadd __func__, rt->info[cix].rateCode); 1125d4365d16SAdrian Chadd return (-1); 1126e42b5dbaSAdrian Chadd } 1127e42b5dbaSAdrian Chadd 112879f02dbfSAdrian Chadd /* 112979f02dbfSAdrian Chadd * Compute the transmit duration based on the frame 113079f02dbfSAdrian Chadd * size and the size of an ACK frame. We call into the 113179f02dbfSAdrian Chadd * HAL to do the computation since it depends on the 113279f02dbfSAdrian Chadd * characteristics of the actual PHY being used. 113379f02dbfSAdrian Chadd * 113479f02dbfSAdrian Chadd * NB: CTS is assumed the same size as an ACK so we can 113579f02dbfSAdrian Chadd * use the precalculated ACK durations. 113679f02dbfSAdrian Chadd */ 113779f02dbfSAdrian Chadd if (shortPreamble) { 113879f02dbfSAdrian Chadd if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1139e42b5dbaSAdrian Chadd ctsduration += rt->info[cix].spAckDuration; 1140e42b5dbaSAdrian Chadd ctsduration += ath_hal_computetxtime(ah, 114179f02dbfSAdrian Chadd rt, pktlen, rix, AH_TRUE); 114279f02dbfSAdrian Chadd if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1143e42b5dbaSAdrian Chadd ctsduration += rt->info[rix].spAckDuration; 114479f02dbfSAdrian Chadd } else { 114579f02dbfSAdrian Chadd if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1146e42b5dbaSAdrian Chadd ctsduration += rt->info[cix].lpAckDuration; 1147e42b5dbaSAdrian Chadd ctsduration += ath_hal_computetxtime(ah, 114879f02dbfSAdrian Chadd rt, pktlen, rix, AH_FALSE); 114979f02dbfSAdrian Chadd if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1150e42b5dbaSAdrian Chadd ctsduration += rt->info[rix].lpAckDuration; 115179f02dbfSAdrian Chadd } 1152e42b5dbaSAdrian Chadd 1153d4365d16SAdrian Chadd return (ctsduration); 115479f02dbfSAdrian Chadd } 115579f02dbfSAdrian Chadd 1156eb6f0de0SAdrian Chadd /* 1157eb6f0de0SAdrian Chadd * Update the given ath_buf with updated rts/cts setup and duration 1158eb6f0de0SAdrian Chadd * values. 1159eb6f0de0SAdrian Chadd * 1160eb6f0de0SAdrian Chadd * To support rate lookups for each software retry, the rts/cts rate 1161eb6f0de0SAdrian Chadd * and cts duration must be re-calculated. 1162eb6f0de0SAdrian Chadd * 1163eb6f0de0SAdrian Chadd * This function assumes the RTS/CTS flags have been set as needed; 1164eb6f0de0SAdrian Chadd * mrr has been disabled; and the rate control lookup has been done. 1165eb6f0de0SAdrian Chadd * 1166eb6f0de0SAdrian Chadd * XXX TODO: MRR need only be disabled for the pre-11n NICs. 1167eb6f0de0SAdrian Chadd * XXX The 11n NICs support per-rate RTS/CTS configuration. 1168eb6f0de0SAdrian Chadd */ 1169eb6f0de0SAdrian Chadd static void 1170eb6f0de0SAdrian Chadd ath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf) 1171eb6f0de0SAdrian Chadd { 1172eb6f0de0SAdrian Chadd uint16_t ctsduration = 0; 1173eb6f0de0SAdrian Chadd uint8_t ctsrate = 0; 1174eb6f0de0SAdrian Chadd uint8_t rix = bf->bf_state.bfs_rc[0].rix; 1175eb6f0de0SAdrian Chadd uint8_t cix = 0; 1176eb6f0de0SAdrian Chadd const HAL_RATE_TABLE *rt = sc->sc_currates; 1177eb6f0de0SAdrian Chadd 1178eb6f0de0SAdrian Chadd /* 1179eb6f0de0SAdrian Chadd * No RTS/CTS enabled? Don't bother. 1180eb6f0de0SAdrian Chadd */ 1181875a9451SAdrian Chadd if ((bf->bf_state.bfs_txflags & 1182eb6f0de0SAdrian Chadd (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) { 1183eb6f0de0SAdrian Chadd /* XXX is this really needed? */ 1184eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate = 0; 1185eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsduration = 0; 1186eb6f0de0SAdrian Chadd return; 1187eb6f0de0SAdrian Chadd } 1188eb6f0de0SAdrian Chadd 1189eb6f0de0SAdrian Chadd /* 1190eb6f0de0SAdrian Chadd * If protection is enabled, use the protection rix control 1191eb6f0de0SAdrian Chadd * rate. Otherwise use the rate0 control rate. 1192eb6f0de0SAdrian Chadd */ 1193eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_doprot) 1194eb6f0de0SAdrian Chadd rix = sc->sc_protrix; 1195eb6f0de0SAdrian Chadd else 1196eb6f0de0SAdrian Chadd rix = bf->bf_state.bfs_rc[0].rix; 1197eb6f0de0SAdrian Chadd 1198eb6f0de0SAdrian Chadd /* 1199eb6f0de0SAdrian Chadd * If the raw path has hard-coded ctsrate0 to something, 1200eb6f0de0SAdrian Chadd * use it. 1201eb6f0de0SAdrian Chadd */ 1202eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_ctsrate0 != 0) 1203eb6f0de0SAdrian Chadd cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0); 1204eb6f0de0SAdrian Chadd else 1205eb6f0de0SAdrian Chadd /* Control rate from above */ 1206eb6f0de0SAdrian Chadd cix = rt->info[rix].controlRate; 1207eb6f0de0SAdrian Chadd 1208eb6f0de0SAdrian Chadd /* Calculate the rtscts rate for the given cix */ 1209eb6f0de0SAdrian Chadd ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix, 1210eb6f0de0SAdrian Chadd bf->bf_state.bfs_shpream); 1211eb6f0de0SAdrian Chadd 1212eb6f0de0SAdrian Chadd /* The 11n chipsets do ctsduration calculations for you */ 1213eb6f0de0SAdrian Chadd if (! ath_tx_is_11n(sc)) 1214eb6f0de0SAdrian Chadd ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix, 1215eb6f0de0SAdrian Chadd bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen, 1216875a9451SAdrian Chadd rt, bf->bf_state.bfs_txflags); 1217eb6f0de0SAdrian Chadd 1218eb6f0de0SAdrian Chadd /* Squirrel away in ath_buf */ 1219eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate = ctsrate; 1220eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsduration = ctsduration; 1221eb6f0de0SAdrian Chadd 1222eb6f0de0SAdrian Chadd /* 1223eb6f0de0SAdrian Chadd * Must disable multi-rate retry when using RTS/CTS. 1224eb6f0de0SAdrian Chadd */ 1225af017101SAdrian Chadd if (!sc->sc_mrrprot) { 1226eb6f0de0SAdrian Chadd bf->bf_state.bfs_ismrr = 0; 1227eb6f0de0SAdrian Chadd bf->bf_state.bfs_try0 = 1228eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */ 1229eb6f0de0SAdrian Chadd } 1230af017101SAdrian Chadd } 1231eb6f0de0SAdrian Chadd 1232eb6f0de0SAdrian Chadd /* 1233eb6f0de0SAdrian Chadd * Setup the descriptor chain for a normal or fast-frame 1234eb6f0de0SAdrian Chadd * frame. 123546634305SAdrian Chadd * 123646634305SAdrian Chadd * XXX TODO: extend to include the destination hardware QCU ID. 123746634305SAdrian Chadd * Make sure that is correct. Make sure that when being added 123846634305SAdrian Chadd * to the mcastq, the CABQ QCUID is set or things will get a bit 123946634305SAdrian Chadd * odd. 1240eb6f0de0SAdrian Chadd */ 1241eb6f0de0SAdrian Chadd static void 1242eb6f0de0SAdrian Chadd ath_tx_setds(struct ath_softc *sc, struct ath_buf *bf) 1243eb6f0de0SAdrian Chadd { 1244eb6f0de0SAdrian Chadd struct ath_desc *ds = bf->bf_desc; 1245eb6f0de0SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1246eb6f0de0SAdrian Chadd 1247eb6f0de0SAdrian Chadd ath_hal_setuptxdesc(ah, ds 1248eb6f0de0SAdrian Chadd , bf->bf_state.bfs_pktlen /* packet length */ 1249eb6f0de0SAdrian Chadd , bf->bf_state.bfs_hdrlen /* header length */ 1250eb6f0de0SAdrian Chadd , bf->bf_state.bfs_atype /* Atheros packet type */ 1251eb6f0de0SAdrian Chadd , bf->bf_state.bfs_txpower /* txpower */ 1252eb6f0de0SAdrian Chadd , bf->bf_state.bfs_txrate0 1253eb6f0de0SAdrian Chadd , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 1254eb6f0de0SAdrian Chadd , bf->bf_state.bfs_keyix /* key cache index */ 1255eb6f0de0SAdrian Chadd , bf->bf_state.bfs_txantenna /* antenna mode */ 1256875a9451SAdrian Chadd , bf->bf_state.bfs_txflags /* flags */ 1257eb6f0de0SAdrian Chadd , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 1258eb6f0de0SAdrian Chadd , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 1259eb6f0de0SAdrian Chadd ); 1260eb6f0de0SAdrian Chadd 1261eb6f0de0SAdrian Chadd /* 1262eb6f0de0SAdrian Chadd * This will be overriden when the descriptor chain is written. 1263eb6f0de0SAdrian Chadd */ 1264eb6f0de0SAdrian Chadd bf->bf_lastds = ds; 1265eb6f0de0SAdrian Chadd bf->bf_last = bf; 1266eb6f0de0SAdrian Chadd 1267d34a7347SAdrian Chadd /* Set rate control and descriptor chain for this frame */ 1268d34a7347SAdrian Chadd ath_tx_set_ratectrl(sc, bf->bf_node, bf); 1269d34a7347SAdrian Chadd ath_tx_chaindesclist(sc, bf); 1270eb6f0de0SAdrian Chadd } 1271eb6f0de0SAdrian Chadd 1272eb6f0de0SAdrian Chadd /* 1273eb6f0de0SAdrian Chadd * Do a rate lookup. 1274eb6f0de0SAdrian Chadd * 1275eb6f0de0SAdrian Chadd * This performs a rate lookup for the given ath_buf only if it's required. 1276eb6f0de0SAdrian Chadd * Non-data frames and raw frames don't require it. 1277eb6f0de0SAdrian Chadd * 1278eb6f0de0SAdrian Chadd * This populates the primary and MRR entries; MRR values are 1279eb6f0de0SAdrian Chadd * then disabled later on if something requires it (eg RTS/CTS on 1280eb6f0de0SAdrian Chadd * pre-11n chipsets. 1281eb6f0de0SAdrian Chadd * 1282eb6f0de0SAdrian Chadd * This needs to be done before the RTS/CTS fields are calculated 1283eb6f0de0SAdrian Chadd * as they may depend upon the rate chosen. 1284eb6f0de0SAdrian Chadd */ 1285eb6f0de0SAdrian Chadd static void 1286eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf) 1287eb6f0de0SAdrian Chadd { 1288eb6f0de0SAdrian Chadd uint8_t rate, rix; 1289eb6f0de0SAdrian Chadd int try0; 1290eb6f0de0SAdrian Chadd 1291eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_doratelookup) 1292eb6f0de0SAdrian Chadd return; 1293eb6f0de0SAdrian Chadd 1294eb6f0de0SAdrian Chadd /* Get rid of any previous state */ 1295eb6f0de0SAdrian Chadd bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1296eb6f0de0SAdrian Chadd 1297eb6f0de0SAdrian Chadd ATH_NODE_LOCK(ATH_NODE(bf->bf_node)); 1298eb6f0de0SAdrian Chadd ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream, 1299eb6f0de0SAdrian Chadd bf->bf_state.bfs_pktlen, &rix, &try0, &rate); 1300eb6f0de0SAdrian Chadd 1301eb6f0de0SAdrian Chadd /* In case MRR is disabled, make sure rc[0] is setup correctly */ 1302eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].rix = rix; 1303eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].ratecode = rate; 1304eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].tries = try0; 1305eb6f0de0SAdrian Chadd 1306eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY) 1307eb6f0de0SAdrian Chadd ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix, 1308eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc); 1309eb6f0de0SAdrian Chadd ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node)); 1310eb6f0de0SAdrian Chadd 1311eb6f0de0SAdrian Chadd sc->sc_txrix = rix; /* for LED blinking */ 1312eb6f0de0SAdrian Chadd sc->sc_lastdatarix = rix; /* for fast frames */ 1313eb6f0de0SAdrian Chadd bf->bf_state.bfs_try0 = try0; 1314eb6f0de0SAdrian Chadd bf->bf_state.bfs_txrate0 = rate; 1315eb6f0de0SAdrian Chadd } 1316eb6f0de0SAdrian Chadd 1317eb6f0de0SAdrian Chadd /* 13180c54de88SAdrian Chadd * Update the CLRDMASK bit in the ath_buf if it needs to be set. 13190c54de88SAdrian Chadd */ 13200c54de88SAdrian Chadd static void 13210c54de88SAdrian Chadd ath_tx_update_clrdmask(struct ath_softc *sc, struct ath_tid *tid, 13220c54de88SAdrian Chadd struct ath_buf *bf) 13230c54de88SAdrian Chadd { 13240c54de88SAdrian Chadd 13250c54de88SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 13260c54de88SAdrian Chadd 13270c54de88SAdrian Chadd if (tid->clrdmask == 1) { 13280c54de88SAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 13290c54de88SAdrian Chadd tid->clrdmask = 0; 13300c54de88SAdrian Chadd } 13310c54de88SAdrian Chadd } 13320c54de88SAdrian Chadd 13330c54de88SAdrian Chadd /* 1334eb6f0de0SAdrian Chadd * Transmit the given frame to the hardware. 1335eb6f0de0SAdrian Chadd * 1336eb6f0de0SAdrian Chadd * The frame must already be setup; rate control must already have 1337eb6f0de0SAdrian Chadd * been done. 1338eb6f0de0SAdrian Chadd * 1339eb6f0de0SAdrian Chadd * XXX since the TXQ lock is being held here (and I dislike holding 1340eb6f0de0SAdrian Chadd * it for this long when not doing software aggregation), later on 1341eb6f0de0SAdrian Chadd * break this function into "setup_normal" and "xmit_normal". The 1342eb6f0de0SAdrian Chadd * lock only needs to be held for the ath_tx_handoff call. 1343eb6f0de0SAdrian Chadd */ 1344eb6f0de0SAdrian Chadd static void 1345eb6f0de0SAdrian Chadd ath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq, 1346eb6f0de0SAdrian Chadd struct ath_buf *bf) 1347eb6f0de0SAdrian Chadd { 13480c54de88SAdrian Chadd struct ath_node *an = ATH_NODE(bf->bf_node); 13490c54de88SAdrian Chadd struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 1350eb6f0de0SAdrian Chadd 1351eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 1352eb6f0de0SAdrian Chadd 13530c54de88SAdrian Chadd /* 13540c54de88SAdrian Chadd * For now, just enable CLRDMASK. ath_tx_xmit_normal() does 13550c54de88SAdrian Chadd * set a completion handler however it doesn't (yet) properly 13560c54de88SAdrian Chadd * handle the strict ordering requirements needed for normal, 13570c54de88SAdrian Chadd * non-aggregate session frames. 13580c54de88SAdrian Chadd * 13590c54de88SAdrian Chadd * Once this is implemented, only set CLRDMASK like this for 13600c54de88SAdrian Chadd * frames that must go out - eg management/raw frames. 13610c54de88SAdrian Chadd */ 13620c54de88SAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 13630c54de88SAdrian Chadd 1364eb6f0de0SAdrian Chadd /* Setup the descriptor before handoff */ 1365eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(sc, bf); 1366e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 1367e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 1368eb6f0de0SAdrian Chadd ath_tx_set_rtscts(sc, bf); 1369e2e4a2c2SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 1370eb6f0de0SAdrian Chadd ath_tx_setds(sc, bf); 1371eb6f0de0SAdrian Chadd 13720c54de88SAdrian Chadd /* Track per-TID hardware queue depth correctly */ 13730c54de88SAdrian Chadd tid->hwq_depth++; 13740c54de88SAdrian Chadd 13750c54de88SAdrian Chadd /* Assign the completion handler */ 13760c54de88SAdrian Chadd bf->bf_comp = ath_tx_normal_comp; 13774e81f27cSAdrian Chadd 1378eb6f0de0SAdrian Chadd /* Hand off to hardware */ 1379eb6f0de0SAdrian Chadd ath_tx_handoff(sc, txq, bf); 1380eb6f0de0SAdrian Chadd } 1381eb6f0de0SAdrian Chadd 1382d05b576dSAdrian Chadd /* 1383d05b576dSAdrian Chadd * Do the basic frame setup stuff that's required before the frame 1384d05b576dSAdrian Chadd * is added to a software queue. 1385d05b576dSAdrian Chadd * 1386d05b576dSAdrian Chadd * All frames get mostly the same treatment and it's done once. 1387d05b576dSAdrian Chadd * Retransmits fiddle with things like the rate control setup, 1388d05b576dSAdrian Chadd * setting the retransmit bit in the packet; doing relevant DMA/bus 1389d05b576dSAdrian Chadd * syncing and relinking it (back) into the hardware TX queue. 1390d05b576dSAdrian Chadd * 1391d05b576dSAdrian Chadd * Note that this may cause the mbuf to be reallocated, so 1392d05b576dSAdrian Chadd * m0 may not be valid. 1393d05b576dSAdrian Chadd */ 1394eb6f0de0SAdrian Chadd static int 1395eb6f0de0SAdrian Chadd ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni, 1396b43facbfSAdrian Chadd struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq) 1397b8e788a5SAdrian Chadd { 1398b8e788a5SAdrian Chadd struct ieee80211vap *vap = ni->ni_vap; 1399b8e788a5SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1400b8e788a5SAdrian Chadd struct ifnet *ifp = sc->sc_ifp; 1401b8e788a5SAdrian Chadd struct ieee80211com *ic = ifp->if_l2com; 1402b8e788a5SAdrian Chadd const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; 1403b8e788a5SAdrian Chadd int error, iswep, ismcast, isfrag, ismrr; 1404eb6f0de0SAdrian Chadd int keyix, hdrlen, pktlen, try0 = 0; 1405eb6f0de0SAdrian Chadd u_int8_t rix = 0, txrate = 0; 1406b8e788a5SAdrian Chadd struct ath_desc *ds; 1407b8e788a5SAdrian Chadd struct ieee80211_frame *wh; 1408eb6f0de0SAdrian Chadd u_int subtype, flags; 1409b8e788a5SAdrian Chadd HAL_PKT_TYPE atype; 1410b8e788a5SAdrian Chadd const HAL_RATE_TABLE *rt; 1411b8e788a5SAdrian Chadd HAL_BOOL shortPreamble; 1412b8e788a5SAdrian Chadd struct ath_node *an; 1413b8e788a5SAdrian Chadd u_int pri; 1414b8e788a5SAdrian Chadd 14157561cb5cSAdrian Chadd /* 14167561cb5cSAdrian Chadd * To ensure that both sequence numbers and the CCMP PN handling 14177561cb5cSAdrian Chadd * is "correct", make sure that the relevant TID queue is locked. 14187561cb5cSAdrian Chadd * Otherwise the CCMP PN and seqno may appear out of order, causing 14197561cb5cSAdrian Chadd * re-ordered frames to have out of order CCMP PN's, resulting 14207561cb5cSAdrian Chadd * in many, many frame drops. 14217561cb5cSAdrian Chadd */ 14227561cb5cSAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 14237561cb5cSAdrian Chadd 1424b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1425b8e788a5SAdrian Chadd iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; 1426b8e788a5SAdrian Chadd ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1427b8e788a5SAdrian Chadd isfrag = m0->m_flags & M_FRAG; 1428b8e788a5SAdrian Chadd hdrlen = ieee80211_anyhdrsize(wh); 1429b8e788a5SAdrian Chadd /* 1430b8e788a5SAdrian Chadd * Packet length must not include any 1431b8e788a5SAdrian Chadd * pad bytes; deduct them here. 1432b8e788a5SAdrian Chadd */ 1433b8e788a5SAdrian Chadd pktlen = m0->m_pkthdr.len - (hdrlen & 3); 1434b8e788a5SAdrian Chadd 143581a82688SAdrian Chadd /* Handle encryption twiddling if needed */ 1436eb6f0de0SAdrian Chadd if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen, 1437eb6f0de0SAdrian Chadd &pktlen, &keyix)) { 1438b8e788a5SAdrian Chadd ath_freetx(m0); 1439b8e788a5SAdrian Chadd return EIO; 1440b8e788a5SAdrian Chadd } 1441b8e788a5SAdrian Chadd 1442b8e788a5SAdrian Chadd /* packet header may have moved, reset our local pointer */ 1443b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1444b8e788a5SAdrian Chadd 1445b8e788a5SAdrian Chadd pktlen += IEEE80211_CRC_LEN; 1446b8e788a5SAdrian Chadd 1447b8e788a5SAdrian Chadd /* 1448b8e788a5SAdrian Chadd * Load the DMA map so any coalescing is done. This 1449b8e788a5SAdrian Chadd * also calculates the number of descriptors we need. 1450b8e788a5SAdrian Chadd */ 1451b8e788a5SAdrian Chadd error = ath_tx_dmasetup(sc, bf, m0); 1452b8e788a5SAdrian Chadd if (error != 0) 1453b8e788a5SAdrian Chadd return error; 1454b8e788a5SAdrian Chadd bf->bf_node = ni; /* NB: held reference */ 1455b8e788a5SAdrian Chadd m0 = bf->bf_m; /* NB: may have changed */ 1456b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1457b8e788a5SAdrian Chadd 1458b8e788a5SAdrian Chadd /* setup descriptors */ 1459b8e788a5SAdrian Chadd ds = bf->bf_desc; 1460b8e788a5SAdrian Chadd rt = sc->sc_currates; 1461b8e788a5SAdrian Chadd KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1462b8e788a5SAdrian Chadd 1463b8e788a5SAdrian Chadd /* 1464b8e788a5SAdrian Chadd * NB: the 802.11 layer marks whether or not we should 1465b8e788a5SAdrian Chadd * use short preamble based on the current mode and 1466b8e788a5SAdrian Chadd * negotiated parameters. 1467b8e788a5SAdrian Chadd */ 1468b8e788a5SAdrian Chadd if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 1469b8e788a5SAdrian Chadd (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) { 1470b8e788a5SAdrian Chadd shortPreamble = AH_TRUE; 1471b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_shortpre++; 1472b8e788a5SAdrian Chadd } else { 1473b8e788a5SAdrian Chadd shortPreamble = AH_FALSE; 1474b8e788a5SAdrian Chadd } 1475b8e788a5SAdrian Chadd 1476b8e788a5SAdrian Chadd an = ATH_NODE(ni); 14774e81f27cSAdrian Chadd //flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 14784e81f27cSAdrian Chadd flags = 0; 1479b8e788a5SAdrian Chadd ismrr = 0; /* default no multi-rate retry*/ 1480b8e788a5SAdrian Chadd pri = M_WME_GETAC(m0); /* honor classification */ 1481b8e788a5SAdrian Chadd /* XXX use txparams instead of fixed values */ 1482b8e788a5SAdrian Chadd /* 1483b8e788a5SAdrian Chadd * Calculate Atheros packet type from IEEE80211 packet header, 1484b8e788a5SAdrian Chadd * setup for rate calculations, and select h/w transmit queue. 1485b8e788a5SAdrian Chadd */ 1486b8e788a5SAdrian Chadd switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1487b8e788a5SAdrian Chadd case IEEE80211_FC0_TYPE_MGT: 1488b8e788a5SAdrian Chadd subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1489b8e788a5SAdrian Chadd if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) 1490b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_BEACON; 1491b8e788a5SAdrian Chadd else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) 1492b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_PROBE_RESP; 1493b8e788a5SAdrian Chadd else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) 1494b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_ATIM; 1495b8e788a5SAdrian Chadd else 1496b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_NORMAL; /* XXX */ 1497b8e788a5SAdrian Chadd rix = an->an_mgmtrix; 1498b8e788a5SAdrian Chadd txrate = rt->info[rix].rateCode; 1499b8e788a5SAdrian Chadd if (shortPreamble) 1500b8e788a5SAdrian Chadd txrate |= rt->info[rix].shortPreamble; 1501b8e788a5SAdrian Chadd try0 = ATH_TXMGTTRY; 1502b8e788a5SAdrian Chadd flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1503b8e788a5SAdrian Chadd break; 1504b8e788a5SAdrian Chadd case IEEE80211_FC0_TYPE_CTL: 1505b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */ 1506b8e788a5SAdrian Chadd rix = an->an_mgmtrix; 1507b8e788a5SAdrian Chadd txrate = rt->info[rix].rateCode; 1508b8e788a5SAdrian Chadd if (shortPreamble) 1509b8e788a5SAdrian Chadd txrate |= rt->info[rix].shortPreamble; 1510b8e788a5SAdrian Chadd try0 = ATH_TXMGTTRY; 1511b8e788a5SAdrian Chadd flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1512b8e788a5SAdrian Chadd break; 1513b8e788a5SAdrian Chadd case IEEE80211_FC0_TYPE_DATA: 1514b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_NORMAL; /* default */ 1515b8e788a5SAdrian Chadd /* 1516b8e788a5SAdrian Chadd * Data frames: multicast frames go out at a fixed rate, 1517b8e788a5SAdrian Chadd * EAPOL frames use the mgmt frame rate; otherwise consult 1518b8e788a5SAdrian Chadd * the rate control module for the rate to use. 1519b8e788a5SAdrian Chadd */ 1520b8e788a5SAdrian Chadd if (ismcast) { 1521b8e788a5SAdrian Chadd rix = an->an_mcastrix; 1522b8e788a5SAdrian Chadd txrate = rt->info[rix].rateCode; 1523b8e788a5SAdrian Chadd if (shortPreamble) 1524b8e788a5SAdrian Chadd txrate |= rt->info[rix].shortPreamble; 1525b8e788a5SAdrian Chadd try0 = 1; 1526b8e788a5SAdrian Chadd } else if (m0->m_flags & M_EAPOL) { 1527b8e788a5SAdrian Chadd /* XXX? maybe always use long preamble? */ 1528b8e788a5SAdrian Chadd rix = an->an_mgmtrix; 1529b8e788a5SAdrian Chadd txrate = rt->info[rix].rateCode; 1530b8e788a5SAdrian Chadd if (shortPreamble) 1531b8e788a5SAdrian Chadd txrate |= rt->info[rix].shortPreamble; 1532b8e788a5SAdrian Chadd try0 = ATH_TXMAXTRY; /* XXX?too many? */ 1533b8e788a5SAdrian Chadd } else { 1534eb6f0de0SAdrian Chadd /* 1535eb6f0de0SAdrian Chadd * Do rate lookup on each TX, rather than using 1536eb6f0de0SAdrian Chadd * the hard-coded TX information decided here. 1537eb6f0de0SAdrian Chadd */ 1538b8e788a5SAdrian Chadd ismrr = 1; 1539eb6f0de0SAdrian Chadd bf->bf_state.bfs_doratelookup = 1; 1540b8e788a5SAdrian Chadd } 1541b8e788a5SAdrian Chadd if (cap->cap_wmeParams[pri].wmep_noackPolicy) 1542b8e788a5SAdrian Chadd flags |= HAL_TXDESC_NOACK; 1543b8e788a5SAdrian Chadd break; 1544b8e788a5SAdrian Chadd default: 1545b8e788a5SAdrian Chadd if_printf(ifp, "bogus frame type 0x%x (%s)\n", 1546b8e788a5SAdrian Chadd wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__); 1547b8e788a5SAdrian Chadd /* XXX statistic */ 1548b8e788a5SAdrian Chadd ath_freetx(m0); 1549b8e788a5SAdrian Chadd return EIO; 1550b8e788a5SAdrian Chadd } 1551b8e788a5SAdrian Chadd 1552447fd44aSAdrian Chadd /* 1553447fd44aSAdrian Chadd * There are two known scenarios where the frame AC doesn't match 1554447fd44aSAdrian Chadd * what the destination TXQ is. 1555447fd44aSAdrian Chadd * 1556447fd44aSAdrian Chadd * + non-QoS frames (eg management?) that the net80211 stack has 1557447fd44aSAdrian Chadd * assigned a higher AC to, but since it's a non-QoS TID, it's 1558447fd44aSAdrian Chadd * being thrown into TID 16. TID 16 gets the AC_BE queue. 1559447fd44aSAdrian Chadd * It's quite possible that management frames should just be 1560447fd44aSAdrian Chadd * direct dispatched to hardware rather than go via the software 1561447fd44aSAdrian Chadd * queue; that should be investigated in the future. There are 1562447fd44aSAdrian Chadd * some specific scenarios where this doesn't make sense, mostly 1563447fd44aSAdrian Chadd * surrounding ADDBA request/response - hence why that is special 1564447fd44aSAdrian Chadd * cased. 1565447fd44aSAdrian Chadd * 1566447fd44aSAdrian Chadd * + Multicast frames going into the VAP mcast queue. That shows up 1567447fd44aSAdrian Chadd * as "TXQ 11". 1568447fd44aSAdrian Chadd * 1569447fd44aSAdrian Chadd * This driver should eventually support separate TID and TXQ locking, 1570447fd44aSAdrian Chadd * allowing for arbitrary AC frames to appear on arbitrary software 1571447fd44aSAdrian Chadd * queues, being queued to the "correct" hardware queue when needed. 1572447fd44aSAdrian Chadd */ 1573447fd44aSAdrian Chadd #if 0 15746deb7f32SAdrian Chadd if (txq != sc->sc_ac2q[pri]) { 15756deb7f32SAdrian Chadd device_printf(sc->sc_dev, 15766deb7f32SAdrian Chadd "%s: txq=%p (%d), pri=%d, pri txq=%p (%d)\n", 15776deb7f32SAdrian Chadd __func__, 15786deb7f32SAdrian Chadd txq, 15796deb7f32SAdrian Chadd txq->axq_qnum, 15806deb7f32SAdrian Chadd pri, 15816deb7f32SAdrian Chadd sc->sc_ac2q[pri], 15826deb7f32SAdrian Chadd sc->sc_ac2q[pri]->axq_qnum); 15836deb7f32SAdrian Chadd } 1584447fd44aSAdrian Chadd #endif 15856deb7f32SAdrian Chadd 1586b8e788a5SAdrian Chadd /* 1587b8e788a5SAdrian Chadd * Calculate miscellaneous flags. 1588b8e788a5SAdrian Chadd */ 1589b8e788a5SAdrian Chadd if (ismcast) { 1590b8e788a5SAdrian Chadd flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ 1591b8e788a5SAdrian Chadd } else if (pktlen > vap->iv_rtsthreshold && 1592b8e788a5SAdrian Chadd (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) { 1593b8e788a5SAdrian Chadd flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ 1594b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_rts++; 1595b8e788a5SAdrian Chadd } 1596b8e788a5SAdrian Chadd if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */ 1597b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_noack++; 1598b8e788a5SAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA 1599b8e788a5SAdrian Chadd if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) { 1600b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_TDMA, 1601b8e788a5SAdrian Chadd "%s: discard frame, ACK required w/ TDMA\n", __func__); 1602b8e788a5SAdrian Chadd sc->sc_stats.ast_tdma_ack++; 1603b8e788a5SAdrian Chadd ath_freetx(m0); 1604b8e788a5SAdrian Chadd return EIO; 1605b8e788a5SAdrian Chadd } 1606b8e788a5SAdrian Chadd #endif 1607b8e788a5SAdrian Chadd 1608b8e788a5SAdrian Chadd /* 1609eb6f0de0SAdrian Chadd * Determine if a tx interrupt should be generated for 1610eb6f0de0SAdrian Chadd * this descriptor. We take a tx interrupt to reap 1611eb6f0de0SAdrian Chadd * descriptors when the h/w hits an EOL condition or 1612eb6f0de0SAdrian Chadd * when the descriptor is specifically marked to generate 1613eb6f0de0SAdrian Chadd * an interrupt. We periodically mark descriptors in this 1614eb6f0de0SAdrian Chadd * way to insure timely replenishing of the supply needed 1615eb6f0de0SAdrian Chadd * for sending frames. Defering interrupts reduces system 1616eb6f0de0SAdrian Chadd * load and potentially allows more concurrent work to be 1617eb6f0de0SAdrian Chadd * done but if done to aggressively can cause senders to 1618eb6f0de0SAdrian Chadd * backup. 1619eb6f0de0SAdrian Chadd * 1620eb6f0de0SAdrian Chadd * NB: use >= to deal with sc_txintrperiod changing 1621eb6f0de0SAdrian Chadd * dynamically through sysctl. 1622b8e788a5SAdrian Chadd */ 1623eb6f0de0SAdrian Chadd if (flags & HAL_TXDESC_INTREQ) { 1624eb6f0de0SAdrian Chadd txq->axq_intrcnt = 0; 1625eb6f0de0SAdrian Chadd } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) { 1626eb6f0de0SAdrian Chadd flags |= HAL_TXDESC_INTREQ; 1627eb6f0de0SAdrian Chadd txq->axq_intrcnt = 0; 1628eb6f0de0SAdrian Chadd } 1629e42b5dbaSAdrian Chadd 1630eb6f0de0SAdrian Chadd /* This point forward is actual TX bits */ 1631b8e788a5SAdrian Chadd 1632b8e788a5SAdrian Chadd /* 1633b8e788a5SAdrian Chadd * At this point we are committed to sending the frame 1634b8e788a5SAdrian Chadd * and we don't need to look at m_nextpkt; clear it in 1635b8e788a5SAdrian Chadd * case this frame is part of frag chain. 1636b8e788a5SAdrian Chadd */ 1637b8e788a5SAdrian Chadd m0->m_nextpkt = NULL; 1638b8e788a5SAdrian Chadd 1639b8e788a5SAdrian Chadd if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1640b8e788a5SAdrian Chadd ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len, 1641b8e788a5SAdrian Chadd sc->sc_hwmap[rix].ieeerate, -1); 1642b8e788a5SAdrian Chadd 1643b8e788a5SAdrian Chadd if (ieee80211_radiotap_active_vap(vap)) { 1644b8e788a5SAdrian Chadd u_int64_t tsf = ath_hal_gettsf64(ah); 1645b8e788a5SAdrian Chadd 1646b8e788a5SAdrian Chadd sc->sc_tx_th.wt_tsf = htole64(tsf); 1647b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1648b8e788a5SAdrian Chadd if (iswep) 1649b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1650b8e788a5SAdrian Chadd if (isfrag) 1651b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1652b8e788a5SAdrian Chadd sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1653b8e788a5SAdrian Chadd sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1654b8e788a5SAdrian Chadd sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1655b8e788a5SAdrian Chadd 1656b8e788a5SAdrian Chadd ieee80211_radiotap_tx(vap, m0); 1657b8e788a5SAdrian Chadd } 1658b8e788a5SAdrian Chadd 1659eb6f0de0SAdrian Chadd /* Blank the legacy rate array */ 1660eb6f0de0SAdrian Chadd bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1661c1782ce0SAdrian Chadd 1662b8e788a5SAdrian Chadd /* 1663eb6f0de0SAdrian Chadd * ath_buf_set_rate needs at least one rate/try to setup 1664eb6f0de0SAdrian Chadd * the rate scenario. 1665b8e788a5SAdrian Chadd */ 1666eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].rix = rix; 1667eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].tries = try0; 1668eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].ratecode = txrate; 1669eb6f0de0SAdrian Chadd 1670eb6f0de0SAdrian Chadd /* Store the decided rate index values away */ 1671eb6f0de0SAdrian Chadd bf->bf_state.bfs_pktlen = pktlen; 1672eb6f0de0SAdrian Chadd bf->bf_state.bfs_hdrlen = hdrlen; 1673eb6f0de0SAdrian Chadd bf->bf_state.bfs_atype = atype; 1674eb6f0de0SAdrian Chadd bf->bf_state.bfs_txpower = ni->ni_txpower; 1675eb6f0de0SAdrian Chadd bf->bf_state.bfs_txrate0 = txrate; 1676eb6f0de0SAdrian Chadd bf->bf_state.bfs_try0 = try0; 1677eb6f0de0SAdrian Chadd bf->bf_state.bfs_keyix = keyix; 1678eb6f0de0SAdrian Chadd bf->bf_state.bfs_txantenna = sc->sc_txantenna; 1679875a9451SAdrian Chadd bf->bf_state.bfs_txflags = flags; 1680eb6f0de0SAdrian Chadd bf->bf_state.bfs_shpream = shortPreamble; 1681eb6f0de0SAdrian Chadd 1682eb6f0de0SAdrian Chadd /* XXX this should be done in ath_tx_setrate() */ 1683eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */ 1684eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate = 0; /* calculated later */ 1685eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsduration = 0; 1686eb6f0de0SAdrian Chadd bf->bf_state.bfs_ismrr = ismrr; 1687eb6f0de0SAdrian Chadd 1688eb6f0de0SAdrian Chadd return 0; 1689eb6f0de0SAdrian Chadd } 1690eb6f0de0SAdrian Chadd 1691b8e788a5SAdrian Chadd /* 16924e81f27cSAdrian Chadd * Queue a frame to the hardware or software queue. 1693eb6f0de0SAdrian Chadd * 1694eb6f0de0SAdrian Chadd * This can be called by the net80211 code. 1695eb6f0de0SAdrian Chadd * 1696eb6f0de0SAdrian Chadd * XXX what about locking? Or, push the seqno assign into the 1697eb6f0de0SAdrian Chadd * XXX aggregate scheduler so its serialised? 16984e81f27cSAdrian Chadd * 16994e81f27cSAdrian Chadd * XXX When sending management frames via ath_raw_xmit(), 17004e81f27cSAdrian Chadd * should CLRDMASK be set unconditionally? 1701b8e788a5SAdrian Chadd */ 1702eb6f0de0SAdrian Chadd int 1703eb6f0de0SAdrian Chadd ath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, 1704eb6f0de0SAdrian Chadd struct ath_buf *bf, struct mbuf *m0) 1705eb6f0de0SAdrian Chadd { 1706eb6f0de0SAdrian Chadd struct ieee80211vap *vap = ni->ni_vap; 1707eb6f0de0SAdrian Chadd struct ath_vap *avp = ATH_VAP(vap); 17089c85ff91SAdrian Chadd int r = 0; 1709eb6f0de0SAdrian Chadd u_int pri; 1710eb6f0de0SAdrian Chadd int tid; 1711eb6f0de0SAdrian Chadd struct ath_txq *txq; 1712eb6f0de0SAdrian Chadd int ismcast; 1713eb6f0de0SAdrian Chadd const struct ieee80211_frame *wh; 1714eb6f0de0SAdrian Chadd int is_ampdu, is_ampdu_tx, is_ampdu_pending; 1715a108d2d6SAdrian Chadd ieee80211_seq seqno; 1716eb6f0de0SAdrian Chadd uint8_t type, subtype; 1717eb6f0de0SAdrian Chadd 1718eb6f0de0SAdrian Chadd /* 1719eb6f0de0SAdrian Chadd * Determine the target hardware queue. 1720eb6f0de0SAdrian Chadd * 1721b43facbfSAdrian Chadd * For multicast frames, the txq gets overridden appropriately 1722b43facbfSAdrian Chadd * depending upon the state of PS. 1723eb6f0de0SAdrian Chadd * 1724eb6f0de0SAdrian Chadd * For any other frame, we do a TID/QoS lookup inside the frame 1725eb6f0de0SAdrian Chadd * to see what the TID should be. If it's a non-QoS frame, the 1726eb6f0de0SAdrian Chadd * AC and TID are overridden. The TID/TXQ code assumes the 1727eb6f0de0SAdrian Chadd * TID is on a predictable hardware TXQ, so we don't support 1728eb6f0de0SAdrian Chadd * having a node TID queued to multiple hardware TXQs. 1729eb6f0de0SAdrian Chadd * This may change in the future but would require some locking 1730eb6f0de0SAdrian Chadd * fudgery. 1731eb6f0de0SAdrian Chadd */ 1732eb6f0de0SAdrian Chadd pri = ath_tx_getac(sc, m0); 1733eb6f0de0SAdrian Chadd tid = ath_tx_gettid(sc, m0); 1734eb6f0de0SAdrian Chadd 1735eb6f0de0SAdrian Chadd txq = sc->sc_ac2q[pri]; 1736eb6f0de0SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1737eb6f0de0SAdrian Chadd ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1738eb6f0de0SAdrian Chadd type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 1739eb6f0de0SAdrian Chadd subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1740eb6f0de0SAdrian Chadd 17419c85ff91SAdrian Chadd /* 17429c85ff91SAdrian Chadd * Enforce how deep the multicast queue can grow. 17439c85ff91SAdrian Chadd * 17449c85ff91SAdrian Chadd * XXX duplicated in ath_raw_xmit(). 17459c85ff91SAdrian Chadd */ 17469c85ff91SAdrian Chadd if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 17479c85ff91SAdrian Chadd ATH_TXQ_LOCK(sc->sc_cabq); 17489c85ff91SAdrian Chadd 1749b09e37a1SAdrian Chadd if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 17509c85ff91SAdrian Chadd sc->sc_stats.ast_tx_mcastq_overflow++; 17519c85ff91SAdrian Chadd r = ENOBUFS; 17529c85ff91SAdrian Chadd } 17539c85ff91SAdrian Chadd 17549c85ff91SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_cabq); 17559c85ff91SAdrian Chadd 17569c85ff91SAdrian Chadd if (r != 0) { 17579c85ff91SAdrian Chadd m_freem(m0); 17589c85ff91SAdrian Chadd return r; 17599c85ff91SAdrian Chadd } 17609c85ff91SAdrian Chadd } 17619c85ff91SAdrian Chadd 1762eb6f0de0SAdrian Chadd /* A-MPDU TX */ 1763eb6f0de0SAdrian Chadd is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid); 1764eb6f0de0SAdrian Chadd is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid); 1765eb6f0de0SAdrian Chadd is_ampdu = is_ampdu_tx | is_ampdu_pending; 1766eb6f0de0SAdrian Chadd 1767a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ac=%d, is_ampdu=%d\n", 1768a108d2d6SAdrian Chadd __func__, tid, pri, is_ampdu); 1769eb6f0de0SAdrian Chadd 177046634305SAdrian Chadd /* Set local packet state, used to queue packets to hardware */ 177146634305SAdrian Chadd bf->bf_state.bfs_tid = tid; 177246634305SAdrian Chadd bf->bf_state.bfs_txq = txq; 177346634305SAdrian Chadd bf->bf_state.bfs_pri = pri; 177446634305SAdrian Chadd 1775c5940c30SAdrian Chadd /* 1776b43facbfSAdrian Chadd * When servicing one or more stations in power-save mode 1777b43facbfSAdrian Chadd * (or) if there is some mcast data waiting on the mcast 1778b43facbfSAdrian Chadd * queue (to prevent out of order delivery) multicast frames 1779b43facbfSAdrian Chadd * must be bufferd until after the beacon. 1780b43facbfSAdrian Chadd * 1781b43facbfSAdrian Chadd * TODO: we should lock the mcastq before we check the length. 1782c5940c30SAdrian Chadd */ 178346634305SAdrian Chadd if (ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) { 1784eb6f0de0SAdrian Chadd txq = &avp->av_mcastq; 178546634305SAdrian Chadd /* 178646634305SAdrian Chadd * Mark the frame as eventually belonging on the CAB 178746634305SAdrian Chadd * queue, so the descriptor setup functions will 178846634305SAdrian Chadd * correctly initialise the descriptor 'qcuId' field. 178946634305SAdrian Chadd */ 179046634305SAdrian Chadd bf->bf_state.bfs_txq = sc->sc_cabq; 179146634305SAdrian Chadd } 1792eb6f0de0SAdrian Chadd 1793eb6f0de0SAdrian Chadd /* Do the generic frame setup */ 1794eb6f0de0SAdrian Chadd /* XXX should just bzero the bf_state? */ 1795eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 1796eb6f0de0SAdrian Chadd 17977561cb5cSAdrian Chadd /* 17987561cb5cSAdrian Chadd * Acquire the TXQ lock early, so both the encap and seqno 17997561cb5cSAdrian Chadd * are allocated together. 180046634305SAdrian Chadd * 180146634305SAdrian Chadd * XXX should TXQ for CABQ traffic be the multicast queue, 180246634305SAdrian Chadd * or the TXQ the given PRI would allocate from? (eg for 180346634305SAdrian Chadd * sequence number allocation locking.) 18047561cb5cSAdrian Chadd */ 1805eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(txq); 18067561cb5cSAdrian Chadd 18077561cb5cSAdrian Chadd /* A-MPDU TX? Manually set sequence number */ 18087561cb5cSAdrian Chadd /* 18097561cb5cSAdrian Chadd * Don't do it whilst pending; the net80211 layer still 18107561cb5cSAdrian Chadd * assigns them. 18117561cb5cSAdrian Chadd */ 18127561cb5cSAdrian Chadd if (is_ampdu_tx) { 1813eb6f0de0SAdrian Chadd /* 1814eb6f0de0SAdrian Chadd * Always call; this function will 1815eb6f0de0SAdrian Chadd * handle making sure that null data frames 1816eb6f0de0SAdrian Chadd * don't get a sequence number from the current 1817eb6f0de0SAdrian Chadd * TID and thus mess with the BAW. 1818eb6f0de0SAdrian Chadd */ 1819a108d2d6SAdrian Chadd seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0); 182042f4d061SAdrian Chadd 182142f4d061SAdrian Chadd /* 182242f4d061SAdrian Chadd * Don't add QoS NULL frames to the BAW. 182342f4d061SAdrian Chadd */ 1824a108d2d6SAdrian Chadd if (IEEE80211_QOS_HAS_SEQ(wh) && 1825a108d2d6SAdrian Chadd subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL) { 1826eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 1; 1827eb6f0de0SAdrian Chadd } 1828c1782ce0SAdrian Chadd } 1829c1782ce0SAdrian Chadd 1830eb6f0de0SAdrian Chadd /* 1831eb6f0de0SAdrian Chadd * If needed, the sequence number has been assigned. 1832eb6f0de0SAdrian Chadd * Squirrel it away somewhere easy to get to. 1833eb6f0de0SAdrian Chadd */ 1834a108d2d6SAdrian Chadd bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1835b8e788a5SAdrian Chadd 1836eb6f0de0SAdrian Chadd /* Is ampdu pending? fetch the seqno and print it out */ 1837eb6f0de0SAdrian Chadd if (is_ampdu_pending) 1838eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 1839eb6f0de0SAdrian Chadd "%s: tid %d: ampdu pending, seqno %d\n", 1840eb6f0de0SAdrian Chadd __func__, tid, M_SEQNO_GET(m0)); 1841eb6f0de0SAdrian Chadd 1842eb6f0de0SAdrian Chadd /* This also sets up the DMA map */ 1843b43facbfSAdrian Chadd r = ath_tx_normal_setup(sc, ni, bf, m0, txq); 1844eb6f0de0SAdrian Chadd 1845eb6f0de0SAdrian Chadd if (r != 0) 18467561cb5cSAdrian Chadd goto done; 1847eb6f0de0SAdrian Chadd 1848eb6f0de0SAdrian Chadd /* At this point m0 could have changed! */ 1849eb6f0de0SAdrian Chadd m0 = bf->bf_m; 1850eb6f0de0SAdrian Chadd 1851eb6f0de0SAdrian Chadd #if 1 1852eb6f0de0SAdrian Chadd /* 1853eb6f0de0SAdrian Chadd * If it's a multicast frame, do a direct-dispatch to the 1854eb6f0de0SAdrian Chadd * destination hardware queue. Don't bother software 1855eb6f0de0SAdrian Chadd * queuing it. 1856eb6f0de0SAdrian Chadd */ 1857eb6f0de0SAdrian Chadd /* 1858eb6f0de0SAdrian Chadd * If it's a BAR frame, do a direct dispatch to the 1859eb6f0de0SAdrian Chadd * destination hardware queue. Don't bother software 1860eb6f0de0SAdrian Chadd * queuing it, as the TID will now be paused. 1861eb6f0de0SAdrian Chadd * Sending a BAR frame can occur from the net80211 txa timer 1862eb6f0de0SAdrian Chadd * (ie, retries) or from the ath txtask (completion call.) 1863eb6f0de0SAdrian Chadd * It queues directly to hardware because the TID is paused 1864eb6f0de0SAdrian Chadd * at this point (and won't be unpaused until the BAR has 1865eb6f0de0SAdrian Chadd * either been TXed successfully or max retries has been 1866eb6f0de0SAdrian Chadd * reached.) 1867eb6f0de0SAdrian Chadd */ 1868eb6f0de0SAdrian Chadd if (txq == &avp->av_mcastq) { 1869d3a6425bSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 18700b96ef63SAdrian Chadd "%s: bf=%p: mcastq: TX'ing\n", __func__, bf); 18714e81f27cSAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1872eb6f0de0SAdrian Chadd ath_tx_xmit_normal(sc, txq, bf); 1873eb6f0de0SAdrian Chadd } else if (type == IEEE80211_FC0_TYPE_CTL && 1874eb6f0de0SAdrian Chadd subtype == IEEE80211_FC0_SUBTYPE_BAR) { 1875d3a6425bSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 1876eb6f0de0SAdrian Chadd "%s: BAR: TX'ing direct\n", __func__); 18774e81f27cSAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1878eb6f0de0SAdrian Chadd ath_tx_xmit_normal(sc, txq, bf); 1879eb6f0de0SAdrian Chadd } else { 1880eb6f0de0SAdrian Chadd /* add to software queue */ 1881d3a6425bSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 18820b96ef63SAdrian Chadd "%s: bf=%p: swq: TX'ing\n", __func__, bf); 1883eb6f0de0SAdrian Chadd ath_tx_swq(sc, ni, txq, bf); 1884eb6f0de0SAdrian Chadd } 1885eb6f0de0SAdrian Chadd #else 1886eb6f0de0SAdrian Chadd /* 1887eb6f0de0SAdrian Chadd * For now, since there's no software queue, 1888eb6f0de0SAdrian Chadd * direct-dispatch to the hardware. 1889eb6f0de0SAdrian Chadd */ 18904e81f27cSAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1891eb6f0de0SAdrian Chadd ath_tx_xmit_normal(sc, txq, bf); 1892eb6f0de0SAdrian Chadd #endif 18937561cb5cSAdrian Chadd done: 18947561cb5cSAdrian Chadd ATH_TXQ_UNLOCK(txq); 1895eb6f0de0SAdrian Chadd 1896b8e788a5SAdrian Chadd return 0; 1897b8e788a5SAdrian Chadd } 1898b8e788a5SAdrian Chadd 1899b8e788a5SAdrian Chadd static int 1900b8e788a5SAdrian Chadd ath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni, 1901b8e788a5SAdrian Chadd struct ath_buf *bf, struct mbuf *m0, 1902b8e788a5SAdrian Chadd const struct ieee80211_bpf_params *params) 1903b8e788a5SAdrian Chadd { 1904b8e788a5SAdrian Chadd struct ifnet *ifp = sc->sc_ifp; 1905b8e788a5SAdrian Chadd struct ieee80211com *ic = ifp->if_l2com; 1906b8e788a5SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1907b8e788a5SAdrian Chadd struct ieee80211vap *vap = ni->ni_vap; 1908b8e788a5SAdrian Chadd int error, ismcast, ismrr; 1909b8e788a5SAdrian Chadd int keyix, hdrlen, pktlen, try0, txantenna; 1910eb6f0de0SAdrian Chadd u_int8_t rix, txrate; 1911b8e788a5SAdrian Chadd struct ieee80211_frame *wh; 1912eb6f0de0SAdrian Chadd u_int flags; 1913b8e788a5SAdrian Chadd HAL_PKT_TYPE atype; 1914b8e788a5SAdrian Chadd const HAL_RATE_TABLE *rt; 1915b8e788a5SAdrian Chadd struct ath_desc *ds; 1916b8e788a5SAdrian Chadd u_int pri; 1917eb6f0de0SAdrian Chadd int o_tid = -1; 1918eb6f0de0SAdrian Chadd int do_override; 1919b8e788a5SAdrian Chadd 1920b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1921b8e788a5SAdrian Chadd ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1922b8e788a5SAdrian Chadd hdrlen = ieee80211_anyhdrsize(wh); 1923b8e788a5SAdrian Chadd /* 1924b8e788a5SAdrian Chadd * Packet length must not include any 1925b8e788a5SAdrian Chadd * pad bytes; deduct them here. 1926b8e788a5SAdrian Chadd */ 1927b8e788a5SAdrian Chadd /* XXX honor IEEE80211_BPF_DATAPAD */ 1928b8e788a5SAdrian Chadd pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; 1929b8e788a5SAdrian Chadd 193003682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 2, 193103682514SAdrian Chadd "ath_tx_raw_start: ni=%p, bf=%p, raw", ni, bf); 193203682514SAdrian Chadd 1933eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n", 1934eb6f0de0SAdrian Chadd __func__, ismcast); 1935eb6f0de0SAdrian Chadd 19367561cb5cSAdrian Chadd pri = params->ibp_pri & 3; 19377561cb5cSAdrian Chadd /* Override pri if the frame isn't a QoS one */ 19387561cb5cSAdrian Chadd if (! IEEE80211_QOS_HAS_SEQ(wh)) 19397561cb5cSAdrian Chadd pri = ath_tx_getac(sc, m0); 19407561cb5cSAdrian Chadd 19417561cb5cSAdrian Chadd /* XXX If it's an ADDBA, override the correct queue */ 19427561cb5cSAdrian Chadd do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid); 19437561cb5cSAdrian Chadd 19447561cb5cSAdrian Chadd /* Map ADDBA to the correct priority */ 19457561cb5cSAdrian Chadd if (do_override) { 19467561cb5cSAdrian Chadd #if 0 19477561cb5cSAdrian Chadd device_printf(sc->sc_dev, 19487561cb5cSAdrian Chadd "%s: overriding tid %d pri %d -> %d\n", 19497561cb5cSAdrian Chadd __func__, o_tid, pri, TID_TO_WME_AC(o_tid)); 19507561cb5cSAdrian Chadd #endif 19517561cb5cSAdrian Chadd pri = TID_TO_WME_AC(o_tid); 19527561cb5cSAdrian Chadd } 19537561cb5cSAdrian Chadd 19547561cb5cSAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[pri]); 19557561cb5cSAdrian Chadd 195681a82688SAdrian Chadd /* Handle encryption twiddling if needed */ 1957eb6f0de0SAdrian Chadd if (! ath_tx_tag_crypto(sc, ni, 1958eb6f0de0SAdrian Chadd m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0, 1959eb6f0de0SAdrian Chadd &hdrlen, &pktlen, &keyix)) { 1960b8e788a5SAdrian Chadd ath_freetx(m0); 1961b8e788a5SAdrian Chadd return EIO; 1962b8e788a5SAdrian Chadd } 1963b8e788a5SAdrian Chadd /* packet header may have moved, reset our local pointer */ 1964b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1965b8e788a5SAdrian Chadd 1966eb6f0de0SAdrian Chadd /* Do the generic frame setup */ 1967eb6f0de0SAdrian Chadd /* XXX should just bzero the bf_state? */ 1968eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 1969eb6f0de0SAdrian Chadd 1970b8e788a5SAdrian Chadd error = ath_tx_dmasetup(sc, bf, m0); 1971b8e788a5SAdrian Chadd if (error != 0) 1972b8e788a5SAdrian Chadd return error; 1973b8e788a5SAdrian Chadd m0 = bf->bf_m; /* NB: may have changed */ 1974b8e788a5SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 1975b8e788a5SAdrian Chadd bf->bf_node = ni; /* NB: held reference */ 1976b8e788a5SAdrian Chadd 19774e81f27cSAdrian Chadd /* Always enable CLRDMASK for raw frames for now.. */ 1978b8e788a5SAdrian Chadd flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1979b8e788a5SAdrian Chadd flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1980b8e788a5SAdrian Chadd if (params->ibp_flags & IEEE80211_BPF_RTS) 1981b8e788a5SAdrian Chadd flags |= HAL_TXDESC_RTSENA; 1982eb6f0de0SAdrian Chadd else if (params->ibp_flags & IEEE80211_BPF_CTS) { 1983eb6f0de0SAdrian Chadd /* XXX assume 11g/11n protection? */ 1984eb6f0de0SAdrian Chadd bf->bf_state.bfs_doprot = 1; 1985b8e788a5SAdrian Chadd flags |= HAL_TXDESC_CTSENA; 1986eb6f0de0SAdrian Chadd } 1987b8e788a5SAdrian Chadd /* XXX leave ismcast to injector? */ 1988b8e788a5SAdrian Chadd if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast) 1989b8e788a5SAdrian Chadd flags |= HAL_TXDESC_NOACK; 1990b8e788a5SAdrian Chadd 1991b8e788a5SAdrian Chadd rt = sc->sc_currates; 1992b8e788a5SAdrian Chadd KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1993b8e788a5SAdrian Chadd rix = ath_tx_findrix(sc, params->ibp_rate0); 1994b8e788a5SAdrian Chadd txrate = rt->info[rix].rateCode; 1995b8e788a5SAdrian Chadd if (params->ibp_flags & IEEE80211_BPF_SHORTPRE) 1996b8e788a5SAdrian Chadd txrate |= rt->info[rix].shortPreamble; 1997b8e788a5SAdrian Chadd sc->sc_txrix = rix; 1998b8e788a5SAdrian Chadd try0 = params->ibp_try0; 1999b8e788a5SAdrian Chadd ismrr = (params->ibp_try1 != 0); 2000b8e788a5SAdrian Chadd txantenna = params->ibp_pri >> 2; 2001b8e788a5SAdrian Chadd if (txantenna == 0) /* XXX? */ 2002b8e788a5SAdrian Chadd txantenna = sc->sc_txantenna; 200379f02dbfSAdrian Chadd 200479f02dbfSAdrian Chadd /* 2005eb6f0de0SAdrian Chadd * Since ctsrate is fixed, store it away for later 2006eb6f0de0SAdrian Chadd * use when the descriptor fields are being set. 200779f02dbfSAdrian Chadd */ 2008eb6f0de0SAdrian Chadd if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) 2009eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate; 201079f02dbfSAdrian Chadd 2011b8e788a5SAdrian Chadd /* 2012b8e788a5SAdrian Chadd * NB: we mark all packets as type PSPOLL so the h/w won't 2013b8e788a5SAdrian Chadd * set the sequence number, duration, etc. 2014b8e788a5SAdrian Chadd */ 2015b8e788a5SAdrian Chadd atype = HAL_PKT_TYPE_PSPOLL; 2016b8e788a5SAdrian Chadd 2017b8e788a5SAdrian Chadd if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 2018b8e788a5SAdrian Chadd ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len, 2019b8e788a5SAdrian Chadd sc->sc_hwmap[rix].ieeerate, -1); 2020b8e788a5SAdrian Chadd 2021b8e788a5SAdrian Chadd if (ieee80211_radiotap_active_vap(vap)) { 2022b8e788a5SAdrian Chadd u_int64_t tsf = ath_hal_gettsf64(ah); 2023b8e788a5SAdrian Chadd 2024b8e788a5SAdrian Chadd sc->sc_tx_th.wt_tsf = htole64(tsf); 2025b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 2026b8e788a5SAdrian Chadd if (wh->i_fc[1] & IEEE80211_FC1_WEP) 2027b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 2028b8e788a5SAdrian Chadd if (m0->m_flags & M_FRAG) 2029b8e788a5SAdrian Chadd sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 2030b8e788a5SAdrian Chadd sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 2031b8e788a5SAdrian Chadd sc->sc_tx_th.wt_txpower = ni->ni_txpower; 2032b8e788a5SAdrian Chadd sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 2033b8e788a5SAdrian Chadd 2034b8e788a5SAdrian Chadd ieee80211_radiotap_tx(vap, m0); 2035b8e788a5SAdrian Chadd } 2036b8e788a5SAdrian Chadd 2037b8e788a5SAdrian Chadd /* 2038b8e788a5SAdrian Chadd * Formulate first tx descriptor with tx controls. 2039b8e788a5SAdrian Chadd */ 2040b8e788a5SAdrian Chadd ds = bf->bf_desc; 2041b8e788a5SAdrian Chadd /* XXX check return value? */ 2042eb6f0de0SAdrian Chadd 2043eb6f0de0SAdrian Chadd /* Store the decided rate index values away */ 2044eb6f0de0SAdrian Chadd bf->bf_state.bfs_pktlen = pktlen; 2045eb6f0de0SAdrian Chadd bf->bf_state.bfs_hdrlen = hdrlen; 2046eb6f0de0SAdrian Chadd bf->bf_state.bfs_atype = atype; 2047eb6f0de0SAdrian Chadd bf->bf_state.bfs_txpower = params->ibp_power; 2048eb6f0de0SAdrian Chadd bf->bf_state.bfs_txrate0 = txrate; 2049eb6f0de0SAdrian Chadd bf->bf_state.bfs_try0 = try0; 2050eb6f0de0SAdrian Chadd bf->bf_state.bfs_keyix = keyix; 2051eb6f0de0SAdrian Chadd bf->bf_state.bfs_txantenna = txantenna; 2052875a9451SAdrian Chadd bf->bf_state.bfs_txflags = flags; 2053eb6f0de0SAdrian Chadd bf->bf_state.bfs_shpream = 2054eb6f0de0SAdrian Chadd !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE); 2055b8e788a5SAdrian Chadd 205646634305SAdrian Chadd /* Set local packet state, used to queue packets to hardware */ 205746634305SAdrian Chadd bf->bf_state.bfs_tid = WME_AC_TO_TID(pri); 205846634305SAdrian Chadd bf->bf_state.bfs_txq = sc->sc_ac2q[pri]; 205946634305SAdrian Chadd bf->bf_state.bfs_pri = pri; 206046634305SAdrian Chadd 2061eb6f0de0SAdrian Chadd /* XXX this should be done in ath_tx_setrate() */ 2062eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsrate = 0; 2063eb6f0de0SAdrian Chadd bf->bf_state.bfs_ctsduration = 0; 2064eb6f0de0SAdrian Chadd bf->bf_state.bfs_ismrr = ismrr; 2065eb6f0de0SAdrian Chadd 2066eb6f0de0SAdrian Chadd /* Blank the legacy rate array */ 2067eb6f0de0SAdrian Chadd bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 2068eb6f0de0SAdrian Chadd 2069eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].rix = 2070eb6f0de0SAdrian Chadd ath_tx_findrix(sc, params->ibp_rate0); 2071eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].tries = try0; 2072eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[0].ratecode = txrate; 2073c1782ce0SAdrian Chadd 2074c1782ce0SAdrian Chadd if (ismrr) { 2075eb6f0de0SAdrian Chadd int rix; 2076c1782ce0SAdrian Chadd 2077b8e788a5SAdrian Chadd rix = ath_tx_findrix(sc, params->ibp_rate1); 2078eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[1].rix = rix; 2079eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[1].tries = params->ibp_try1; 2080c1782ce0SAdrian Chadd 2081eb6f0de0SAdrian Chadd rix = ath_tx_findrix(sc, params->ibp_rate2); 2082eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[2].rix = rix; 2083eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[2].tries = params->ibp_try2; 2084eb6f0de0SAdrian Chadd 2085eb6f0de0SAdrian Chadd rix = ath_tx_findrix(sc, params->ibp_rate3); 2086eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[3].rix = rix; 2087eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[3].tries = params->ibp_try3; 2088c1782ce0SAdrian Chadd } 2089eb6f0de0SAdrian Chadd /* 2090eb6f0de0SAdrian Chadd * All the required rate control decisions have been made; 2091eb6f0de0SAdrian Chadd * fill in the rc flags. 2092eb6f0de0SAdrian Chadd */ 2093eb6f0de0SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 2094b8e788a5SAdrian Chadd 2095b8e788a5SAdrian Chadd /* NB: no buffered multicast in power save support */ 2096eb6f0de0SAdrian Chadd 2097eb6f0de0SAdrian Chadd /* 2098eb6f0de0SAdrian Chadd * If we're overiding the ADDBA destination, dump directly 2099eb6f0de0SAdrian Chadd * into the hardware queue, right after any pending 2100eb6f0de0SAdrian Chadd * frames to that node are. 2101eb6f0de0SAdrian Chadd */ 2102eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n", 2103eb6f0de0SAdrian Chadd __func__, do_override); 2104eb6f0de0SAdrian Chadd 210594eefcf1SAdrian Chadd #if 1 2106eb6f0de0SAdrian Chadd if (do_override) { 21074e81f27cSAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2108eb6f0de0SAdrian Chadd ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2109eb6f0de0SAdrian Chadd } else { 2110eb6f0de0SAdrian Chadd /* Queue to software queue */ 2111eb6f0de0SAdrian Chadd ath_tx_swq(sc, ni, sc->sc_ac2q[pri], bf); 2112eb6f0de0SAdrian Chadd } 211394eefcf1SAdrian Chadd #else 211494eefcf1SAdrian Chadd /* Direct-dispatch to the hardware */ 211594eefcf1SAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 211694eefcf1SAdrian Chadd ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 211794eefcf1SAdrian Chadd #endif 21187561cb5cSAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[pri]); 2119eb6f0de0SAdrian Chadd 2120b8e788a5SAdrian Chadd return 0; 2121b8e788a5SAdrian Chadd } 2122b8e788a5SAdrian Chadd 2123eb6f0de0SAdrian Chadd /* 2124eb6f0de0SAdrian Chadd * Send a raw frame. 2125eb6f0de0SAdrian Chadd * 2126eb6f0de0SAdrian Chadd * This can be called by net80211. 2127eb6f0de0SAdrian Chadd */ 2128b8e788a5SAdrian Chadd int 2129b8e788a5SAdrian Chadd ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 2130b8e788a5SAdrian Chadd const struct ieee80211_bpf_params *params) 2131b8e788a5SAdrian Chadd { 2132b8e788a5SAdrian Chadd struct ieee80211com *ic = ni->ni_ic; 2133b8e788a5SAdrian Chadd struct ifnet *ifp = ic->ic_ifp; 2134b8e788a5SAdrian Chadd struct ath_softc *sc = ifp->if_softc; 2135b8e788a5SAdrian Chadd struct ath_buf *bf; 21369c85ff91SAdrian Chadd struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 21379c85ff91SAdrian Chadd int error = 0; 2138b8e788a5SAdrian Chadd 2139ef27340cSAdrian Chadd ATH_PCU_LOCK(sc); 2140ef27340cSAdrian Chadd if (sc->sc_inreset_cnt > 0) { 2141ef27340cSAdrian Chadd device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; bailing\n", 2142ef27340cSAdrian Chadd __func__); 2143ef27340cSAdrian Chadd error = EIO; 2144ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 2145ef27340cSAdrian Chadd goto bad0; 2146ef27340cSAdrian Chadd } 2147ef27340cSAdrian Chadd sc->sc_txstart_cnt++; 2148ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 2149ef27340cSAdrian Chadd 2150b8e788a5SAdrian Chadd if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) { 2151b8e788a5SAdrian Chadd DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__, 2152b8e788a5SAdrian Chadd (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ? 2153b8e788a5SAdrian Chadd "!running" : "invalid"); 2154b8e788a5SAdrian Chadd m_freem(m); 2155b8e788a5SAdrian Chadd error = ENETDOWN; 2156b8e788a5SAdrian Chadd goto bad; 2157b8e788a5SAdrian Chadd } 21589c85ff91SAdrian Chadd 21599c85ff91SAdrian Chadd /* 21609c85ff91SAdrian Chadd * Enforce how deep the multicast queue can grow. 21619c85ff91SAdrian Chadd * 21629c85ff91SAdrian Chadd * XXX duplicated in ath_tx_start(). 21639c85ff91SAdrian Chadd */ 21649c85ff91SAdrian Chadd if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 21659c85ff91SAdrian Chadd ATH_TXQ_LOCK(sc->sc_cabq); 21669c85ff91SAdrian Chadd 2167b09e37a1SAdrian Chadd if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 21689c85ff91SAdrian Chadd sc->sc_stats.ast_tx_mcastq_overflow++; 21699c85ff91SAdrian Chadd error = ENOBUFS; 21709c85ff91SAdrian Chadd } 21719c85ff91SAdrian Chadd 21729c85ff91SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_cabq); 21739c85ff91SAdrian Chadd 21749c85ff91SAdrian Chadd if (error != 0) { 21759c85ff91SAdrian Chadd m_freem(m); 21769c85ff91SAdrian Chadd goto bad; 21779c85ff91SAdrian Chadd } 21789c85ff91SAdrian Chadd } 21799c85ff91SAdrian Chadd 2180b8e788a5SAdrian Chadd /* 2181b8e788a5SAdrian Chadd * Grab a TX buffer and associated resources. 2182b8e788a5SAdrian Chadd */ 2183af33d486SAdrian Chadd bf = ath_getbuf(sc, ATH_BUFTYPE_MGMT); 2184b8e788a5SAdrian Chadd if (bf == NULL) { 2185b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_nobuf++; 2186b8e788a5SAdrian Chadd m_freem(m); 2187b8e788a5SAdrian Chadd error = ENOBUFS; 2188b8e788a5SAdrian Chadd goto bad; 2189b8e788a5SAdrian Chadd } 219003682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: m=%p, params=%p, bf=%p\n", 219103682514SAdrian Chadd m, params, bf); 2192b8e788a5SAdrian Chadd 2193b8e788a5SAdrian Chadd if (params == NULL) { 2194b8e788a5SAdrian Chadd /* 2195b8e788a5SAdrian Chadd * Legacy path; interpret frame contents to decide 2196b8e788a5SAdrian Chadd * precisely how to send the frame. 2197b8e788a5SAdrian Chadd */ 2198b8e788a5SAdrian Chadd if (ath_tx_start(sc, ni, bf, m)) { 2199b8e788a5SAdrian Chadd error = EIO; /* XXX */ 2200b8e788a5SAdrian Chadd goto bad2; 2201b8e788a5SAdrian Chadd } 2202b8e788a5SAdrian Chadd } else { 2203b8e788a5SAdrian Chadd /* 2204b8e788a5SAdrian Chadd * Caller supplied explicit parameters to use in 2205b8e788a5SAdrian Chadd * sending the frame. 2206b8e788a5SAdrian Chadd */ 2207b8e788a5SAdrian Chadd if (ath_tx_raw_start(sc, ni, bf, m, params)) { 2208b8e788a5SAdrian Chadd error = EIO; /* XXX */ 2209b8e788a5SAdrian Chadd goto bad2; 2210b8e788a5SAdrian Chadd } 2211b8e788a5SAdrian Chadd } 2212b8e788a5SAdrian Chadd sc->sc_wd_timer = 5; 2213b8e788a5SAdrian Chadd ifp->if_opackets++; 2214b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_raw++; 2215b8e788a5SAdrian Chadd 2216ef27340cSAdrian Chadd ATH_PCU_LOCK(sc); 2217ef27340cSAdrian Chadd sc->sc_txstart_cnt--; 2218ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 2219ef27340cSAdrian Chadd 2220b8e788a5SAdrian Chadd return 0; 2221b8e788a5SAdrian Chadd bad2: 222203682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: bad2: m=%p, params=%p, " 222303682514SAdrian Chadd "bf=%p", 222403682514SAdrian Chadd m, 222503682514SAdrian Chadd params, 222603682514SAdrian Chadd bf); 2227b8e788a5SAdrian Chadd ATH_TXBUF_LOCK(sc); 2228e1a50456SAdrian Chadd ath_returnbuf_head(sc, bf); 2229b8e788a5SAdrian Chadd ATH_TXBUF_UNLOCK(sc); 2230b8e788a5SAdrian Chadd bad: 2231ef27340cSAdrian Chadd ATH_PCU_LOCK(sc); 2232ef27340cSAdrian Chadd sc->sc_txstart_cnt--; 2233ef27340cSAdrian Chadd ATH_PCU_UNLOCK(sc); 2234ef27340cSAdrian Chadd bad0: 223503682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_TX, 2, "ath_raw_xmit: bad0: m=%p, params=%p", 223603682514SAdrian Chadd m, params); 2237b8e788a5SAdrian Chadd ifp->if_oerrors++; 2238b8e788a5SAdrian Chadd sc->sc_stats.ast_tx_raw_fail++; 2239b8e788a5SAdrian Chadd ieee80211_free_node(ni); 2240ef27340cSAdrian Chadd 2241b8e788a5SAdrian Chadd return error; 2242b8e788a5SAdrian Chadd } 2243eb6f0de0SAdrian Chadd 2244eb6f0de0SAdrian Chadd /* Some helper functions */ 2245eb6f0de0SAdrian Chadd 2246eb6f0de0SAdrian Chadd /* 2247eb6f0de0SAdrian Chadd * ADDBA (and potentially others) need to be placed in the same 2248eb6f0de0SAdrian Chadd * hardware queue as the TID/node it's relating to. This is so 2249eb6f0de0SAdrian Chadd * it goes out after any pending non-aggregate frames to the 2250eb6f0de0SAdrian Chadd * same node/TID. 2251eb6f0de0SAdrian Chadd * 2252eb6f0de0SAdrian Chadd * If this isn't done, the ADDBA can go out before the frames 2253eb6f0de0SAdrian Chadd * queued in hardware. Even though these frames have a sequence 2254eb6f0de0SAdrian Chadd * number -earlier- than the ADDBA can be transmitted (but 2255eb6f0de0SAdrian Chadd * no frames whose sequence numbers are after the ADDBA should 2256eb6f0de0SAdrian Chadd * be!) they'll arrive after the ADDBA - and the receiving end 2257eb6f0de0SAdrian Chadd * will simply drop them as being out of the BAW. 2258eb6f0de0SAdrian Chadd * 2259eb6f0de0SAdrian Chadd * The frames can't be appended to the TID software queue - it'll 2260eb6f0de0SAdrian Chadd * never be sent out. So these frames have to be directly 2261eb6f0de0SAdrian Chadd * dispatched to the hardware, rather than queued in software. 2262eb6f0de0SAdrian Chadd * So if this function returns true, the TXQ has to be 2263eb6f0de0SAdrian Chadd * overridden and it has to be directly dispatched. 2264eb6f0de0SAdrian Chadd * 2265eb6f0de0SAdrian Chadd * It's a dirty hack, but someone's gotta do it. 2266eb6f0de0SAdrian Chadd */ 2267eb6f0de0SAdrian Chadd 2268eb6f0de0SAdrian Chadd /* 2269eb6f0de0SAdrian Chadd * XXX doesn't belong here! 2270eb6f0de0SAdrian Chadd */ 2271eb6f0de0SAdrian Chadd static int 2272eb6f0de0SAdrian Chadd ieee80211_is_action(struct ieee80211_frame *wh) 2273eb6f0de0SAdrian Chadd { 2274eb6f0de0SAdrian Chadd /* Type: Management frame? */ 2275eb6f0de0SAdrian Chadd if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != 2276eb6f0de0SAdrian Chadd IEEE80211_FC0_TYPE_MGT) 2277eb6f0de0SAdrian Chadd return 0; 2278eb6f0de0SAdrian Chadd 2279eb6f0de0SAdrian Chadd /* Subtype: Action frame? */ 2280eb6f0de0SAdrian Chadd if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) != 2281eb6f0de0SAdrian Chadd IEEE80211_FC0_SUBTYPE_ACTION) 2282eb6f0de0SAdrian Chadd return 0; 2283eb6f0de0SAdrian Chadd 2284eb6f0de0SAdrian Chadd return 1; 2285eb6f0de0SAdrian Chadd } 2286eb6f0de0SAdrian Chadd 2287eb6f0de0SAdrian Chadd #define MS(_v, _f) (((_v) & _f) >> _f##_S) 2288eb6f0de0SAdrian Chadd /* 2289eb6f0de0SAdrian Chadd * Return an alternate TID for ADDBA request frames. 2290eb6f0de0SAdrian Chadd * 2291eb6f0de0SAdrian Chadd * Yes, this likely should be done in the net80211 layer. 2292eb6f0de0SAdrian Chadd */ 2293eb6f0de0SAdrian Chadd static int 2294eb6f0de0SAdrian Chadd ath_tx_action_frame_override_queue(struct ath_softc *sc, 2295eb6f0de0SAdrian Chadd struct ieee80211_node *ni, 2296eb6f0de0SAdrian Chadd struct mbuf *m0, int *tid) 2297eb6f0de0SAdrian Chadd { 2298eb6f0de0SAdrian Chadd struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *); 2299eb6f0de0SAdrian Chadd struct ieee80211_action_ba_addbarequest *ia; 2300eb6f0de0SAdrian Chadd uint8_t *frm; 2301eb6f0de0SAdrian Chadd uint16_t baparamset; 2302eb6f0de0SAdrian Chadd 2303eb6f0de0SAdrian Chadd /* Not action frame? Bail */ 2304eb6f0de0SAdrian Chadd if (! ieee80211_is_action(wh)) 2305eb6f0de0SAdrian Chadd return 0; 2306eb6f0de0SAdrian Chadd 2307eb6f0de0SAdrian Chadd /* XXX Not needed for frames we send? */ 2308eb6f0de0SAdrian Chadd #if 0 2309eb6f0de0SAdrian Chadd /* Correct length? */ 2310eb6f0de0SAdrian Chadd if (! ieee80211_parse_action(ni, m)) 2311eb6f0de0SAdrian Chadd return 0; 2312eb6f0de0SAdrian Chadd #endif 2313eb6f0de0SAdrian Chadd 2314eb6f0de0SAdrian Chadd /* Extract out action frame */ 2315eb6f0de0SAdrian Chadd frm = (u_int8_t *)&wh[1]; 2316eb6f0de0SAdrian Chadd ia = (struct ieee80211_action_ba_addbarequest *) frm; 2317eb6f0de0SAdrian Chadd 2318eb6f0de0SAdrian Chadd /* Not ADDBA? Bail */ 2319eb6f0de0SAdrian Chadd if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA) 2320eb6f0de0SAdrian Chadd return 0; 2321eb6f0de0SAdrian Chadd if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST) 2322eb6f0de0SAdrian Chadd return 0; 2323eb6f0de0SAdrian Chadd 2324eb6f0de0SAdrian Chadd /* Extract TID, return it */ 2325eb6f0de0SAdrian Chadd baparamset = le16toh(ia->rq_baparamset); 2326eb6f0de0SAdrian Chadd *tid = (int) MS(baparamset, IEEE80211_BAPS_TID); 2327eb6f0de0SAdrian Chadd 2328eb6f0de0SAdrian Chadd return 1; 2329eb6f0de0SAdrian Chadd } 2330eb6f0de0SAdrian Chadd #undef MS 2331eb6f0de0SAdrian Chadd 2332eb6f0de0SAdrian Chadd /* Per-node software queue operations */ 2333eb6f0de0SAdrian Chadd 2334eb6f0de0SAdrian Chadd /* 2335eb6f0de0SAdrian Chadd * Add the current packet to the given BAW. 2336eb6f0de0SAdrian Chadd * It is assumed that the current packet 2337eb6f0de0SAdrian Chadd * 2338eb6f0de0SAdrian Chadd * + fits inside the BAW; 2339eb6f0de0SAdrian Chadd * + already has had a sequence number allocated. 2340eb6f0de0SAdrian Chadd * 2341eb6f0de0SAdrian Chadd * Since the BAW status may be modified by both the ath task and 2342eb6f0de0SAdrian Chadd * the net80211/ifnet contexts, the TID must be locked. 2343eb6f0de0SAdrian Chadd */ 2344eb6f0de0SAdrian Chadd void 2345eb6f0de0SAdrian Chadd ath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an, 2346eb6f0de0SAdrian Chadd struct ath_tid *tid, struct ath_buf *bf) 2347eb6f0de0SAdrian Chadd { 2348eb6f0de0SAdrian Chadd int index, cindex; 2349eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 2350eb6f0de0SAdrian Chadd 2351eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2352c2ac9655SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2353eb6f0de0SAdrian Chadd 2354eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_isretried) 2355eb6f0de0SAdrian Chadd return; 2356eb6f0de0SAdrian Chadd 2357c7c07341SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 2358c7c07341SAdrian Chadd 23597561cb5cSAdrian Chadd if (! bf->bf_state.bfs_dobaw) { 23607561cb5cSAdrian Chadd device_printf(sc->sc_dev, 23617561cb5cSAdrian Chadd "%s: dobaw=0, seqno=%d, window %d:%d\n", 23627561cb5cSAdrian Chadd __func__, 23637561cb5cSAdrian Chadd SEQNO(bf->bf_state.bfs_seqno), 23647561cb5cSAdrian Chadd tap->txa_start, 23657561cb5cSAdrian Chadd tap->txa_wnd); 23667561cb5cSAdrian Chadd } 23677561cb5cSAdrian Chadd 2368eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_addedbaw) 2369eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 2370a108d2d6SAdrian Chadd "%s: re-added? tid=%d, seqno %d; window %d:%d; " 2371d4365d16SAdrian Chadd "baw head=%d tail=%d\n", 2372a108d2d6SAdrian Chadd __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2373d4365d16SAdrian Chadd tap->txa_start, tap->txa_wnd, tid->baw_head, 2374d4365d16SAdrian Chadd tid->baw_tail); 2375eb6f0de0SAdrian Chadd 2376eb6f0de0SAdrian Chadd /* 23777561cb5cSAdrian Chadd * Verify that the given sequence number is not outside of the 23787561cb5cSAdrian Chadd * BAW. Complain loudly if that's the case. 23797561cb5cSAdrian Chadd */ 23807561cb5cSAdrian Chadd if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 23817561cb5cSAdrian Chadd SEQNO(bf->bf_state.bfs_seqno))) { 23827561cb5cSAdrian Chadd device_printf(sc->sc_dev, 23837561cb5cSAdrian Chadd "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; " 23847561cb5cSAdrian Chadd "baw head=%d tail=%d\n", 23857561cb5cSAdrian Chadd __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 23867561cb5cSAdrian Chadd tap->txa_start, tap->txa_wnd, tid->baw_head, 23877561cb5cSAdrian Chadd tid->baw_tail); 23887561cb5cSAdrian Chadd } 23897561cb5cSAdrian Chadd 23907561cb5cSAdrian Chadd /* 2391eb6f0de0SAdrian Chadd * ni->ni_txseqs[] is the currently allocated seqno. 2392eb6f0de0SAdrian Chadd * the txa state contains the current baw start. 2393eb6f0de0SAdrian Chadd */ 2394eb6f0de0SAdrian Chadd index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno)); 2395eb6f0de0SAdrian Chadd cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2396eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2397a108d2d6SAdrian Chadd "%s: tid=%d, seqno %d; window %d:%d; index=%d cindex=%d " 2398d4365d16SAdrian Chadd "baw head=%d tail=%d\n", 2399a108d2d6SAdrian Chadd __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2400d4365d16SAdrian Chadd tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head, 2401d4365d16SAdrian Chadd tid->baw_tail); 2402eb6f0de0SAdrian Chadd 2403eb6f0de0SAdrian Chadd 2404eb6f0de0SAdrian Chadd #if 0 2405eb6f0de0SAdrian Chadd assert(tid->tx_buf[cindex] == NULL); 2406eb6f0de0SAdrian Chadd #endif 2407eb6f0de0SAdrian Chadd if (tid->tx_buf[cindex] != NULL) { 2408eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 2409eb6f0de0SAdrian Chadd "%s: ba packet dup (index=%d, cindex=%d, " 2410eb6f0de0SAdrian Chadd "head=%d, tail=%d)\n", 2411eb6f0de0SAdrian Chadd __func__, index, cindex, tid->baw_head, tid->baw_tail); 2412eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 2413eb6f0de0SAdrian Chadd "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n", 2414eb6f0de0SAdrian Chadd __func__, 2415eb6f0de0SAdrian Chadd tid->tx_buf[cindex], 2416eb6f0de0SAdrian Chadd SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno), 2417eb6f0de0SAdrian Chadd bf, 2418eb6f0de0SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno) 2419eb6f0de0SAdrian Chadd ); 2420eb6f0de0SAdrian Chadd } 2421eb6f0de0SAdrian Chadd tid->tx_buf[cindex] = bf; 2422eb6f0de0SAdrian Chadd 2423d4365d16SAdrian Chadd if (index >= ((tid->baw_tail - tid->baw_head) & 2424d4365d16SAdrian Chadd (ATH_TID_MAX_BUFS - 1))) { 2425eb6f0de0SAdrian Chadd tid->baw_tail = cindex; 2426eb6f0de0SAdrian Chadd INCR(tid->baw_tail, ATH_TID_MAX_BUFS); 2427eb6f0de0SAdrian Chadd } 2428eb6f0de0SAdrian Chadd } 2429eb6f0de0SAdrian Chadd 2430eb6f0de0SAdrian Chadd /* 243138962489SAdrian Chadd * Flip the BAW buffer entry over from the existing one to the new one. 243238962489SAdrian Chadd * 243338962489SAdrian Chadd * When software retransmitting a (sub-)frame, it is entirely possible that 243438962489SAdrian Chadd * the frame ath_buf is marked as BUSY and can't be immediately reused. 243538962489SAdrian Chadd * In that instance the buffer is cloned and the new buffer is used for 243638962489SAdrian Chadd * retransmit. We thus need to update the ath_buf slot in the BAW buf 243738962489SAdrian Chadd * tracking array to maintain consistency. 243838962489SAdrian Chadd */ 243938962489SAdrian Chadd static void 244038962489SAdrian Chadd ath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an, 244138962489SAdrian Chadd struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf) 244238962489SAdrian Chadd { 244338962489SAdrian Chadd int index, cindex; 244438962489SAdrian Chadd struct ieee80211_tx_ampdu *tap; 244538962489SAdrian Chadd int seqno = SEQNO(old_bf->bf_state.bfs_seqno); 244638962489SAdrian Chadd 244738962489SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2448c2ac9655SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 244938962489SAdrian Chadd 245038962489SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 245138962489SAdrian Chadd index = ATH_BA_INDEX(tap->txa_start, seqno); 245238962489SAdrian Chadd cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 245338962489SAdrian Chadd 245438962489SAdrian Chadd /* 245538962489SAdrian Chadd * Just warn for now; if it happens then we should find out 245638962489SAdrian Chadd * about it. It's highly likely the aggregation session will 245738962489SAdrian Chadd * soon hang. 245838962489SAdrian Chadd */ 245938962489SAdrian Chadd if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) { 246038962489SAdrian Chadd device_printf(sc->sc_dev, "%s: retransmitted buffer" 246138962489SAdrian Chadd " has mismatching seqno's, BA session may hang.\n", 246238962489SAdrian Chadd __func__); 246338962489SAdrian Chadd device_printf(sc->sc_dev, "%s: old seqno=%d, new_seqno=%d\n", 246438962489SAdrian Chadd __func__, 246538962489SAdrian Chadd old_bf->bf_state.bfs_seqno, 246638962489SAdrian Chadd new_bf->bf_state.bfs_seqno); 246738962489SAdrian Chadd } 246838962489SAdrian Chadd 246938962489SAdrian Chadd if (tid->tx_buf[cindex] != old_bf) { 247038962489SAdrian Chadd device_printf(sc->sc_dev, "%s: ath_buf pointer incorrect; " 247138962489SAdrian Chadd " has m BA session may hang.\n", 247238962489SAdrian Chadd __func__); 247338962489SAdrian Chadd device_printf(sc->sc_dev, "%s: old bf=%p, new bf=%p\n", 247438962489SAdrian Chadd __func__, 247538962489SAdrian Chadd old_bf, new_bf); 247638962489SAdrian Chadd } 247738962489SAdrian Chadd 247838962489SAdrian Chadd tid->tx_buf[cindex] = new_bf; 247938962489SAdrian Chadd } 248038962489SAdrian Chadd 248138962489SAdrian Chadd /* 2482eb6f0de0SAdrian Chadd * seq_start - left edge of BAW 2483eb6f0de0SAdrian Chadd * seq_next - current/next sequence number to allocate 2484eb6f0de0SAdrian Chadd * 2485eb6f0de0SAdrian Chadd * Since the BAW status may be modified by both the ath task and 2486eb6f0de0SAdrian Chadd * the net80211/ifnet contexts, the TID must be locked. 2487eb6f0de0SAdrian Chadd */ 2488eb6f0de0SAdrian Chadd static void 2489eb6f0de0SAdrian Chadd ath_tx_update_baw(struct ath_softc *sc, struct ath_node *an, 2490eb6f0de0SAdrian Chadd struct ath_tid *tid, const struct ath_buf *bf) 2491eb6f0de0SAdrian Chadd { 2492eb6f0de0SAdrian Chadd int index, cindex; 2493eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 2494eb6f0de0SAdrian Chadd int seqno = SEQNO(bf->bf_state.bfs_seqno); 2495eb6f0de0SAdrian Chadd 2496eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 24974b6db404SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2498eb6f0de0SAdrian Chadd 2499eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 2500eb6f0de0SAdrian Chadd index = ATH_BA_INDEX(tap->txa_start, seqno); 2501eb6f0de0SAdrian Chadd cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2502eb6f0de0SAdrian Chadd 2503eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2504a108d2d6SAdrian Chadd "%s: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, " 2505d4365d16SAdrian Chadd "baw head=%d, tail=%d\n", 2506a108d2d6SAdrian Chadd __func__, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index, 2507eb6f0de0SAdrian Chadd cindex, tid->baw_head, tid->baw_tail); 2508eb6f0de0SAdrian Chadd 2509eb6f0de0SAdrian Chadd /* 2510eb6f0de0SAdrian Chadd * If this occurs then we have a big problem - something else 2511eb6f0de0SAdrian Chadd * has slid tap->txa_start along without updating the BAW 2512eb6f0de0SAdrian Chadd * tracking start/end pointers. Thus the TX BAW state is now 2513eb6f0de0SAdrian Chadd * completely busted. 2514eb6f0de0SAdrian Chadd * 2515eb6f0de0SAdrian Chadd * But for now, since I haven't yet fixed TDMA and buffer cloning, 2516eb6f0de0SAdrian Chadd * it's quite possible that a cloned buffer is making its way 2517eb6f0de0SAdrian Chadd * here and causing it to fire off. Disable TDMA for now. 2518eb6f0de0SAdrian Chadd */ 2519eb6f0de0SAdrian Chadd if (tid->tx_buf[cindex] != bf) { 2520eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 2521eb6f0de0SAdrian Chadd "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n", 2522eb6f0de0SAdrian Chadd __func__, 2523eb6f0de0SAdrian Chadd bf, SEQNO(bf->bf_state.bfs_seqno), 2524eb6f0de0SAdrian Chadd tid->tx_buf[cindex], 2525eb6f0de0SAdrian Chadd SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno)); 2526eb6f0de0SAdrian Chadd } 2527eb6f0de0SAdrian Chadd 2528eb6f0de0SAdrian Chadd tid->tx_buf[cindex] = NULL; 2529eb6f0de0SAdrian Chadd 2530d4365d16SAdrian Chadd while (tid->baw_head != tid->baw_tail && 2531d4365d16SAdrian Chadd !tid->tx_buf[tid->baw_head]) { 2532eb6f0de0SAdrian Chadd INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 2533eb6f0de0SAdrian Chadd INCR(tid->baw_head, ATH_TID_MAX_BUFS); 2534eb6f0de0SAdrian Chadd } 2535d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2536d4365d16SAdrian Chadd "%s: baw is now %d:%d, baw head=%d\n", 2537eb6f0de0SAdrian Chadd __func__, tap->txa_start, tap->txa_wnd, tid->baw_head); 2538eb6f0de0SAdrian Chadd } 2539eb6f0de0SAdrian Chadd 2540eb6f0de0SAdrian Chadd /* 2541eb6f0de0SAdrian Chadd * Mark the current node/TID as ready to TX. 2542eb6f0de0SAdrian Chadd * 2543eb6f0de0SAdrian Chadd * This is done to make it easy for the software scheduler to 2544eb6f0de0SAdrian Chadd * find which nodes have data to send. 2545eb6f0de0SAdrian Chadd * 2546eb6f0de0SAdrian Chadd * The TXQ lock must be held. 2547eb6f0de0SAdrian Chadd */ 2548eb6f0de0SAdrian Chadd static void 2549eb6f0de0SAdrian Chadd ath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid) 2550eb6f0de0SAdrian Chadd { 2551eb6f0de0SAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2552eb6f0de0SAdrian Chadd 2553eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 2554eb6f0de0SAdrian Chadd 2555eb6f0de0SAdrian Chadd if (tid->paused) 2556eb6f0de0SAdrian Chadd return; /* paused, can't schedule yet */ 2557eb6f0de0SAdrian Chadd 2558eb6f0de0SAdrian Chadd if (tid->sched) 2559eb6f0de0SAdrian Chadd return; /* already scheduled */ 2560eb6f0de0SAdrian Chadd 2561eb6f0de0SAdrian Chadd tid->sched = 1; 2562eb6f0de0SAdrian Chadd 2563eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem); 2564eb6f0de0SAdrian Chadd } 2565eb6f0de0SAdrian Chadd 2566eb6f0de0SAdrian Chadd /* 2567eb6f0de0SAdrian Chadd * Mark the current node as no longer needing to be polled for 2568eb6f0de0SAdrian Chadd * TX packets. 2569eb6f0de0SAdrian Chadd * 2570eb6f0de0SAdrian Chadd * The TXQ lock must be held. 2571eb6f0de0SAdrian Chadd */ 2572eb6f0de0SAdrian Chadd static void 2573eb6f0de0SAdrian Chadd ath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid) 2574eb6f0de0SAdrian Chadd { 2575eb6f0de0SAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2576eb6f0de0SAdrian Chadd 2577eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 2578eb6f0de0SAdrian Chadd 2579eb6f0de0SAdrian Chadd if (tid->sched == 0) 2580eb6f0de0SAdrian Chadd return; 2581eb6f0de0SAdrian Chadd 2582eb6f0de0SAdrian Chadd tid->sched = 0; 2583eb6f0de0SAdrian Chadd TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem); 2584eb6f0de0SAdrian Chadd } 2585eb6f0de0SAdrian Chadd 2586eb6f0de0SAdrian Chadd /* 2587eb6f0de0SAdrian Chadd * Assign a sequence number manually to the given frame. 2588eb6f0de0SAdrian Chadd * 2589eb6f0de0SAdrian Chadd * This should only be called for A-MPDU TX frames. 2590eb6f0de0SAdrian Chadd */ 2591a108d2d6SAdrian Chadd static ieee80211_seq 2592eb6f0de0SAdrian Chadd ath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni, 2593eb6f0de0SAdrian Chadd struct ath_buf *bf, struct mbuf *m0) 2594eb6f0de0SAdrian Chadd { 2595eb6f0de0SAdrian Chadd struct ieee80211_frame *wh; 2596eb6f0de0SAdrian Chadd int tid, pri; 2597eb6f0de0SAdrian Chadd ieee80211_seq seqno; 2598eb6f0de0SAdrian Chadd uint8_t subtype; 2599eb6f0de0SAdrian Chadd 2600eb6f0de0SAdrian Chadd /* TID lookup */ 2601eb6f0de0SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 2602eb6f0de0SAdrian Chadd pri = M_WME_GETAC(m0); /* honor classification */ 2603eb6f0de0SAdrian Chadd tid = WME_AC_TO_TID(pri); 2604a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pri=%d, tid=%d, qos has seq=%d\n", 2605a108d2d6SAdrian Chadd __func__, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2606eb6f0de0SAdrian Chadd 2607eb6f0de0SAdrian Chadd /* XXX Is it a control frame? Ignore */ 2608eb6f0de0SAdrian Chadd 2609eb6f0de0SAdrian Chadd /* Does the packet require a sequence number? */ 2610eb6f0de0SAdrian Chadd if (! IEEE80211_QOS_HAS_SEQ(wh)) 2611eb6f0de0SAdrian Chadd return -1; 2612eb6f0de0SAdrian Chadd 26137561cb5cSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, &(ATH_NODE(ni)->an_tid[tid])); 26147561cb5cSAdrian Chadd 2615eb6f0de0SAdrian Chadd /* 2616eb6f0de0SAdrian Chadd * Is it a QOS NULL Data frame? Give it a sequence number from 2617eb6f0de0SAdrian Chadd * the default TID (IEEE80211_NONQOS_TID.) 2618eb6f0de0SAdrian Chadd * 2619eb6f0de0SAdrian Chadd * The RX path of everything I've looked at doesn't include the NULL 2620eb6f0de0SAdrian Chadd * data frame sequence number in the aggregation state updates, so 2621eb6f0de0SAdrian Chadd * assigning it a sequence number there will cause a BAW hole on the 2622eb6f0de0SAdrian Chadd * RX side. 2623eb6f0de0SAdrian Chadd */ 2624eb6f0de0SAdrian Chadd subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2625eb6f0de0SAdrian Chadd if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) { 26267561cb5cSAdrian Chadd /* XXX no locking for this TID? This is a bit of a problem. */ 2627eb6f0de0SAdrian Chadd seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 2628eb6f0de0SAdrian Chadd INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE); 2629eb6f0de0SAdrian Chadd } else { 2630eb6f0de0SAdrian Chadd /* Manually assign sequence number */ 2631eb6f0de0SAdrian Chadd seqno = ni->ni_txseqs[tid]; 2632eb6f0de0SAdrian Chadd INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE); 2633eb6f0de0SAdrian Chadd } 2634eb6f0de0SAdrian Chadd *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); 2635eb6f0de0SAdrian Chadd M_SEQNO_SET(m0, seqno); 2636eb6f0de0SAdrian Chadd 2637eb6f0de0SAdrian Chadd /* Return so caller can do something with it if needed */ 2638a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: -> seqno=%d\n", __func__, seqno); 2639eb6f0de0SAdrian Chadd return seqno; 2640eb6f0de0SAdrian Chadd } 2641eb6f0de0SAdrian Chadd 2642eb6f0de0SAdrian Chadd /* 2643eb6f0de0SAdrian Chadd * Attempt to direct dispatch an aggregate frame to hardware. 2644eb6f0de0SAdrian Chadd * If the frame is out of BAW, queue. 2645eb6f0de0SAdrian Chadd * Otherwise, schedule it as a single frame. 2646eb6f0de0SAdrian Chadd */ 2647eb6f0de0SAdrian Chadd static void 264846634305SAdrian Chadd ath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an, 264946634305SAdrian Chadd struct ath_txq *txq, struct ath_buf *bf) 2650eb6f0de0SAdrian Chadd { 2651eb6f0de0SAdrian Chadd struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 265246634305SAdrian Chadd // struct ath_txq *txq = bf->bf_state.bfs_txq; 2653eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 2654eb6f0de0SAdrian Chadd 265546634305SAdrian Chadd if (txq != bf->bf_state.bfs_txq) { 265646634305SAdrian Chadd device_printf(sc->sc_dev, "%s: txq %d != bfs_txq %d!\n", 265746634305SAdrian Chadd __func__, 265846634305SAdrian Chadd txq->axq_qnum, 265946634305SAdrian Chadd bf->bf_state.bfs_txq->axq_qnum); 266046634305SAdrian Chadd } 266146634305SAdrian Chadd 2662eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 2663c2ac9655SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2664eb6f0de0SAdrian Chadd 2665eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 2666eb6f0de0SAdrian Chadd 2667eb6f0de0SAdrian Chadd /* paused? queue */ 2668eb6f0de0SAdrian Chadd if (tid->paused) { 26694547f047SAdrian Chadd ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 26700f04c5a2SAdrian Chadd /* XXX don't sched - we're paused! */ 2671eb6f0de0SAdrian Chadd return; 2672eb6f0de0SAdrian Chadd } 2673eb6f0de0SAdrian Chadd 2674eb6f0de0SAdrian Chadd /* outside baw? queue */ 2675eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_dobaw && 2676eb6f0de0SAdrian Chadd (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2677eb6f0de0SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)))) { 2678ba0e58f4SAdrian Chadd ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 2679eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, tid); 2680eb6f0de0SAdrian Chadd return; 2681eb6f0de0SAdrian Chadd } 2682eb6f0de0SAdrian Chadd 26832a9f83afSAdrian Chadd /* 26842a9f83afSAdrian Chadd * This is a temporary check and should be removed once 26852a9f83afSAdrian Chadd * all the relevant code paths have been fixed. 26862a9f83afSAdrian Chadd * 26872a9f83afSAdrian Chadd * During aggregate retries, it's possible that the head 26882a9f83afSAdrian Chadd * frame will fail (which has the bfs_aggr and bfs_nframes 26892a9f83afSAdrian Chadd * fields set for said aggregate) and will be retried as 26902a9f83afSAdrian Chadd * a single frame. In this instance, the values should 26912a9f83afSAdrian Chadd * be reset or the completion code will get upset with you. 26922a9f83afSAdrian Chadd */ 26932a9f83afSAdrian Chadd if (bf->bf_state.bfs_aggr != 0 || bf->bf_state.bfs_nframes > 1) { 26942a9f83afSAdrian Chadd device_printf(sc->sc_dev, "%s: bfs_aggr=%d, bfs_nframes=%d\n", 26952a9f83afSAdrian Chadd __func__, 26962a9f83afSAdrian Chadd bf->bf_state.bfs_aggr, 26972a9f83afSAdrian Chadd bf->bf_state.bfs_nframes); 26982a9f83afSAdrian Chadd bf->bf_state.bfs_aggr = 0; 26992a9f83afSAdrian Chadd bf->bf_state.bfs_nframes = 1; 27002a9f83afSAdrian Chadd } 27012a9f83afSAdrian Chadd 27024e81f27cSAdrian Chadd /* Update CLRDMASK just before this frame is queued */ 27034e81f27cSAdrian Chadd ath_tx_update_clrdmask(sc, tid, bf); 27044e81f27cSAdrian Chadd 2705eb6f0de0SAdrian Chadd /* Direct dispatch to hardware */ 2706eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(sc, bf); 2707e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 2708e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 2709eb6f0de0SAdrian Chadd ath_tx_set_rtscts(sc, bf); 2710e2e4a2c2SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 2711eb6f0de0SAdrian Chadd ath_tx_setds(sc, bf); 2712eb6f0de0SAdrian Chadd 2713eb6f0de0SAdrian Chadd /* Statistics */ 2714eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_low_hwq_single_pkt++; 2715eb6f0de0SAdrian Chadd 2716eb6f0de0SAdrian Chadd /* Track per-TID hardware queue depth correctly */ 2717eb6f0de0SAdrian Chadd tid->hwq_depth++; 2718eb6f0de0SAdrian Chadd 2719eb6f0de0SAdrian Chadd /* Add to BAW */ 2720eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_dobaw) { 2721eb6f0de0SAdrian Chadd ath_tx_addto_baw(sc, an, tid, bf); 2722eb6f0de0SAdrian Chadd bf->bf_state.bfs_addedbaw = 1; 2723eb6f0de0SAdrian Chadd } 2724eb6f0de0SAdrian Chadd 2725eb6f0de0SAdrian Chadd /* Set completion handler, multi-frame aggregate or not */ 2726eb6f0de0SAdrian Chadd bf->bf_comp = ath_tx_aggr_comp; 2727eb6f0de0SAdrian Chadd 2728eb6f0de0SAdrian Chadd /* Hand off to hardware */ 2729eb6f0de0SAdrian Chadd ath_tx_handoff(sc, txq, bf); 2730eb6f0de0SAdrian Chadd } 2731eb6f0de0SAdrian Chadd 2732eb6f0de0SAdrian Chadd /* 2733eb6f0de0SAdrian Chadd * Attempt to send the packet. 2734eb6f0de0SAdrian Chadd * If the queue isn't busy, direct-dispatch. 2735eb6f0de0SAdrian Chadd * If the queue is busy enough, queue the given packet on the 2736eb6f0de0SAdrian Chadd * relevant software queue. 2737eb6f0de0SAdrian Chadd */ 2738eb6f0de0SAdrian Chadd void 2739eb6f0de0SAdrian Chadd ath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_txq *txq, 2740eb6f0de0SAdrian Chadd struct ath_buf *bf) 2741eb6f0de0SAdrian Chadd { 2742eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 2743eb6f0de0SAdrian Chadd struct ieee80211_frame *wh; 2744eb6f0de0SAdrian Chadd struct ath_tid *atid; 2745eb6f0de0SAdrian Chadd int pri, tid; 2746eb6f0de0SAdrian Chadd struct mbuf *m0 = bf->bf_m; 2747eb6f0de0SAdrian Chadd 27487561cb5cSAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 27497561cb5cSAdrian Chadd 2750eb6f0de0SAdrian Chadd /* Fetch the TID - non-QoS frames get assigned to TID 16 */ 2751eb6f0de0SAdrian Chadd wh = mtod(m0, struct ieee80211_frame *); 2752eb6f0de0SAdrian Chadd pri = ath_tx_getac(sc, m0); 2753eb6f0de0SAdrian Chadd tid = ath_tx_gettid(sc, m0); 2754eb6f0de0SAdrian Chadd atid = &an->an_tid[tid]; 2755eb6f0de0SAdrian Chadd 2756c2ac9655SAdrian Chadd ATH_TID_LOCK_ASSERT(sc, atid); 2757c2ac9655SAdrian Chadd 2758a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d\n", 2759a108d2d6SAdrian Chadd __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2760eb6f0de0SAdrian Chadd 2761eb6f0de0SAdrian Chadd /* Set local packet state, used to queue packets to hardware */ 276246634305SAdrian Chadd /* XXX potentially duplicate info, re-check */ 276346634305SAdrian Chadd /* XXX remember, txq must be the hardware queue, not the av_mcastq */ 2764eb6f0de0SAdrian Chadd bf->bf_state.bfs_tid = tid; 2765eb6f0de0SAdrian Chadd bf->bf_state.bfs_txq = txq; 2766eb6f0de0SAdrian Chadd bf->bf_state.bfs_pri = pri; 2767eb6f0de0SAdrian Chadd 2768eb6f0de0SAdrian Chadd /* 2769eb6f0de0SAdrian Chadd * If the hardware queue isn't busy, queue it directly. 2770eb6f0de0SAdrian Chadd * If the hardware queue is busy, queue it. 2771eb6f0de0SAdrian Chadd * If the TID is paused or the traffic it outside BAW, software 2772eb6f0de0SAdrian Chadd * queue it. 2773eb6f0de0SAdrian Chadd */ 2774eb6f0de0SAdrian Chadd if (atid->paused) { 2775eb6f0de0SAdrian Chadd /* TID is paused, queue */ 2776a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: paused\n", __func__); 2777eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2778eb6f0de0SAdrian Chadd } else if (ath_tx_ampdu_pending(sc, an, tid)) { 2779eb6f0de0SAdrian Chadd /* AMPDU pending; queue */ 2780a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pending\n", __func__); 2781eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2782eb6f0de0SAdrian Chadd /* XXX sched? */ 2783eb6f0de0SAdrian Chadd } else if (ath_tx_ampdu_running(sc, an, tid)) { 2784eb6f0de0SAdrian Chadd /* AMPDU running, attempt direct dispatch if possible */ 278539f24578SAdrian Chadd 278639f24578SAdrian Chadd /* 278739f24578SAdrian Chadd * Always queue the frame to the tail of the list. 278839f24578SAdrian Chadd */ 278939f24578SAdrian Chadd ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 279039f24578SAdrian Chadd 279139f24578SAdrian Chadd /* 279239f24578SAdrian Chadd * If the hardware queue isn't busy, direct dispatch 279339f24578SAdrian Chadd * the head frame in the list. Don't schedule the 279439f24578SAdrian Chadd * TID - let it build some more frames first? 279539f24578SAdrian Chadd * 279639f24578SAdrian Chadd * Otherwise, schedule the TID. 279739f24578SAdrian Chadd */ 2798d4365d16SAdrian Chadd if (txq->axq_depth < sc->sc_hwq_limit) { 279939f24578SAdrian Chadd bf = TAILQ_FIRST(&atid->axq_q); 280039f24578SAdrian Chadd ATH_TXQ_REMOVE(atid, bf, bf_list); 28012a9f83afSAdrian Chadd 28022a9f83afSAdrian Chadd /* 28032a9f83afSAdrian Chadd * Ensure it's definitely treated as a non-AMPDU 28042a9f83afSAdrian Chadd * frame - this information may have been left 28052a9f83afSAdrian Chadd * over from a previous attempt. 28062a9f83afSAdrian Chadd */ 28072a9f83afSAdrian Chadd bf->bf_state.bfs_aggr = 0; 28082a9f83afSAdrian Chadd bf->bf_state.bfs_nframes = 1; 28092a9f83afSAdrian Chadd 28102a9f83afSAdrian Chadd /* Queue to the hardware */ 281146634305SAdrian Chadd ath_tx_xmit_aggr(sc, an, txq, bf); 2812a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 2813a108d2d6SAdrian Chadd "%s: xmit_aggr\n", 2814a108d2d6SAdrian Chadd __func__); 2815d4365d16SAdrian Chadd } else { 2816d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 2817a108d2d6SAdrian Chadd "%s: ampdu; swq'ing\n", 2818a108d2d6SAdrian Chadd __func__); 281903682514SAdrian Chadd 2820eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, atid); 2821eb6f0de0SAdrian Chadd } 2822eb6f0de0SAdrian Chadd } else if (txq->axq_depth < sc->sc_hwq_limit) { 2823eb6f0de0SAdrian Chadd /* AMPDU not running, attempt direct dispatch */ 2824a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: xmit_normal\n", __func__); 28250a544719SAdrian Chadd /* See if clrdmask needs to be set */ 28260a544719SAdrian Chadd ath_tx_update_clrdmask(sc, atid, bf); 2827eb6f0de0SAdrian Chadd ath_tx_xmit_normal(sc, txq, bf); 2828eb6f0de0SAdrian Chadd } else { 2829eb6f0de0SAdrian Chadd /* Busy; queue */ 2830a108d2d6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: swq'ing\n", __func__); 2831eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2832eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, atid); 2833eb6f0de0SAdrian Chadd } 2834eb6f0de0SAdrian Chadd } 2835eb6f0de0SAdrian Chadd 2836eb6f0de0SAdrian Chadd /* 2837eb6f0de0SAdrian Chadd * Configure the per-TID node state. 2838eb6f0de0SAdrian Chadd * 2839eb6f0de0SAdrian Chadd * This likely belongs in if_ath_node.c but I can't think of anywhere 2840eb6f0de0SAdrian Chadd * else to put it just yet. 2841eb6f0de0SAdrian Chadd * 2842eb6f0de0SAdrian Chadd * This sets up the SLISTs and the mutex as appropriate. 2843eb6f0de0SAdrian Chadd */ 2844eb6f0de0SAdrian Chadd void 2845eb6f0de0SAdrian Chadd ath_tx_tid_init(struct ath_softc *sc, struct ath_node *an) 2846eb6f0de0SAdrian Chadd { 2847eb6f0de0SAdrian Chadd int i, j; 2848eb6f0de0SAdrian Chadd struct ath_tid *atid; 2849eb6f0de0SAdrian Chadd 2850eb6f0de0SAdrian Chadd for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2851eb6f0de0SAdrian Chadd atid = &an->an_tid[i]; 2852f1bc738eSAdrian Chadd 2853f1bc738eSAdrian Chadd /* XXX now with this bzer(), is the field 0'ing needed? */ 2854f1bc738eSAdrian Chadd bzero(atid, sizeof(*atid)); 2855f1bc738eSAdrian Chadd 2856eb6f0de0SAdrian Chadd TAILQ_INIT(&atid->axq_q); 2857f1bc738eSAdrian Chadd TAILQ_INIT(&atid->filtq.axq_q); 2858eb6f0de0SAdrian Chadd atid->tid = i; 2859eb6f0de0SAdrian Chadd atid->an = an; 2860eb6f0de0SAdrian Chadd for (j = 0; j < ATH_TID_MAX_BUFS; j++) 2861eb6f0de0SAdrian Chadd atid->tx_buf[j] = NULL; 2862eb6f0de0SAdrian Chadd atid->baw_head = atid->baw_tail = 0; 2863eb6f0de0SAdrian Chadd atid->paused = 0; 2864eb6f0de0SAdrian Chadd atid->sched = 0; 2865eb6f0de0SAdrian Chadd atid->hwq_depth = 0; 2866eb6f0de0SAdrian Chadd atid->cleanup_inprogress = 0; 2867f1bc738eSAdrian Chadd atid->clrdmask = 1; /* Always start by setting this bit */ 2868eb6f0de0SAdrian Chadd if (i == IEEE80211_NONQOS_TID) 2869*7403d1b9SAdrian Chadd atid->ac = ATH_NONQOS_TID_AC; 2870eb6f0de0SAdrian Chadd else 2871eb6f0de0SAdrian Chadd atid->ac = TID_TO_WME_AC(i); 2872eb6f0de0SAdrian Chadd } 2873eb6f0de0SAdrian Chadd } 2874eb6f0de0SAdrian Chadd 2875eb6f0de0SAdrian Chadd /* 2876eb6f0de0SAdrian Chadd * Pause the current TID. This stops packets from being transmitted 2877eb6f0de0SAdrian Chadd * on it. 2878eb6f0de0SAdrian Chadd * 2879eb6f0de0SAdrian Chadd * Since this is also called from upper layers as well as the driver, 2880eb6f0de0SAdrian Chadd * it will get the TID lock. 2881eb6f0de0SAdrian Chadd */ 2882eb6f0de0SAdrian Chadd static void 2883eb6f0de0SAdrian Chadd ath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid) 2884eb6f0de0SAdrian Chadd { 288588b3d483SAdrian Chadd 288688b3d483SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2887eb6f0de0SAdrian Chadd tid->paused++; 2888eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n", 2889eb6f0de0SAdrian Chadd __func__, tid->paused); 2890eb6f0de0SAdrian Chadd } 2891eb6f0de0SAdrian Chadd 2892eb6f0de0SAdrian Chadd /* 2893eb6f0de0SAdrian Chadd * Unpause the current TID, and schedule it if needed. 2894eb6f0de0SAdrian Chadd */ 2895eb6f0de0SAdrian Chadd static void 2896eb6f0de0SAdrian Chadd ath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid) 2897eb6f0de0SAdrian Chadd { 2898eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2899eb6f0de0SAdrian Chadd 2900eb6f0de0SAdrian Chadd tid->paused--; 2901eb6f0de0SAdrian Chadd 2902eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n", 2903eb6f0de0SAdrian Chadd __func__, tid->paused); 2904eb6f0de0SAdrian Chadd 2905eb6f0de0SAdrian Chadd if (tid->paused || tid->axq_depth == 0) { 2906eb6f0de0SAdrian Chadd return; 2907eb6f0de0SAdrian Chadd } 2908eb6f0de0SAdrian Chadd 2909f1bc738eSAdrian Chadd /* XXX isfiltered shouldn't ever be 0 at this point */ 2910f1bc738eSAdrian Chadd if (tid->isfiltered == 1) { 2911f1bc738eSAdrian Chadd device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 2912f1bc738eSAdrian Chadd return; 2913f1bc738eSAdrian Chadd } 2914f1bc738eSAdrian Chadd 29154e81f27cSAdrian Chadd /* 29164e81f27cSAdrian Chadd * Override the clrdmask configuration for the next frame, 29174e81f27cSAdrian Chadd * just to get the ball rolling. 29184e81f27cSAdrian Chadd */ 29194e81f27cSAdrian Chadd tid->clrdmask = 1; 29204e81f27cSAdrian Chadd 2921eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, tid); 2922eb6f0de0SAdrian Chadd /* Punt some frames to the hardware if needed */ 292303e9308fSAdrian Chadd //ath_txq_sched(sc, sc->sc_ac2q[tid->ac]); 292403e9308fSAdrian Chadd taskqueue_enqueue(sc->sc_tq, &sc->sc_txqtask); 2925eb6f0de0SAdrian Chadd } 2926eb6f0de0SAdrian Chadd 2927eb6f0de0SAdrian Chadd /* 2928f1bc738eSAdrian Chadd * Add the given ath_buf to the TID filtered frame list. 2929f1bc738eSAdrian Chadd * This requires the TID be filtered. 2930f1bc738eSAdrian Chadd */ 2931f1bc738eSAdrian Chadd static void 2932f1bc738eSAdrian Chadd ath_tx_tid_filt_addbuf(struct ath_softc *sc, struct ath_tid *tid, 2933f1bc738eSAdrian Chadd struct ath_buf *bf) 2934f1bc738eSAdrian Chadd { 2935f1bc738eSAdrian Chadd 2936f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2937f1bc738eSAdrian Chadd if (! tid->isfiltered) 2938f1bc738eSAdrian Chadd device_printf(sc->sc_dev, "%s: not filtered?!\n", __func__); 2939f1bc738eSAdrian Chadd 2940f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: bf=%p\n", __func__, bf); 2941f1bc738eSAdrian Chadd 2942f1bc738eSAdrian Chadd /* Set the retry bit and bump the retry counter */ 2943f1bc738eSAdrian Chadd ath_tx_set_retry(sc, bf); 2944f1bc738eSAdrian Chadd sc->sc_stats.ast_tx_swfiltered++; 2945f1bc738eSAdrian Chadd 2946f1bc738eSAdrian Chadd ATH_TXQ_INSERT_TAIL(&tid->filtq, bf, bf_list); 2947f1bc738eSAdrian Chadd } 2948f1bc738eSAdrian Chadd 2949f1bc738eSAdrian Chadd /* 2950f1bc738eSAdrian Chadd * Handle a completed filtered frame from the given TID. 2951f1bc738eSAdrian Chadd * This just enables/pauses the filtered frame state if required 2952f1bc738eSAdrian Chadd * and appends the filtered frame to the filtered queue. 2953f1bc738eSAdrian Chadd */ 2954f1bc738eSAdrian Chadd static void 2955f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_buf(struct ath_softc *sc, struct ath_tid *tid, 2956f1bc738eSAdrian Chadd struct ath_buf *bf) 2957f1bc738eSAdrian Chadd { 2958f1bc738eSAdrian Chadd 2959f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2960f1bc738eSAdrian Chadd 2961f1bc738eSAdrian Chadd if (! tid->isfiltered) { 2962f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: filter transition\n", 2963f1bc738eSAdrian Chadd __func__); 2964f1bc738eSAdrian Chadd tid->isfiltered = 1; 2965f1bc738eSAdrian Chadd ath_tx_tid_pause(sc, tid); 2966f1bc738eSAdrian Chadd } 2967f1bc738eSAdrian Chadd 2968f1bc738eSAdrian Chadd /* Add the frame to the filter queue */ 2969f1bc738eSAdrian Chadd ath_tx_tid_filt_addbuf(sc, tid, bf); 2970f1bc738eSAdrian Chadd } 2971f1bc738eSAdrian Chadd 2972f1bc738eSAdrian Chadd /* 2973f1bc738eSAdrian Chadd * Complete the filtered frame TX completion. 2974f1bc738eSAdrian Chadd * 2975f1bc738eSAdrian Chadd * If there are no more frames in the hardware queue, unpause/unfilter 2976f1bc738eSAdrian Chadd * the TID if applicable. Otherwise we will wait for a node PS transition 2977f1bc738eSAdrian Chadd * to unfilter. 2978f1bc738eSAdrian Chadd */ 2979f1bc738eSAdrian Chadd static void 2980f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(struct ath_softc *sc, struct ath_tid *tid) 2981f1bc738eSAdrian Chadd { 2982f1bc738eSAdrian Chadd struct ath_buf *bf; 2983f1bc738eSAdrian Chadd 2984f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 2985f1bc738eSAdrian Chadd 2986f1bc738eSAdrian Chadd if (tid->hwq_depth != 0) 2987f1bc738eSAdrian Chadd return; 2988f1bc738eSAdrian Chadd 2989f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: hwq=0, transition back\n", 2990f1bc738eSAdrian Chadd __func__); 2991f1bc738eSAdrian Chadd tid->isfiltered = 0; 2992f1bc738eSAdrian Chadd tid->clrdmask = 1; 2993f1bc738eSAdrian Chadd 2994f1bc738eSAdrian Chadd /* XXX this is really quite inefficient */ 2995f1bc738eSAdrian Chadd while ((bf = TAILQ_LAST(&tid->filtq.axq_q, ath_bufhead_s)) != NULL) { 2996f1bc738eSAdrian Chadd ATH_TXQ_REMOVE(&tid->filtq, bf, bf_list); 2997f1bc738eSAdrian Chadd ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 2998f1bc738eSAdrian Chadd } 2999f1bc738eSAdrian Chadd 3000f1bc738eSAdrian Chadd ath_tx_tid_resume(sc, tid); 3001f1bc738eSAdrian Chadd } 3002f1bc738eSAdrian Chadd 3003f1bc738eSAdrian Chadd /* 3004f1bc738eSAdrian Chadd * Called when a single (aggregate or otherwise) frame is completed. 3005f1bc738eSAdrian Chadd * 3006f1bc738eSAdrian Chadd * Returns 1 if the buffer could be added to the filtered list 3007f1bc738eSAdrian Chadd * (cloned or otherwise), 0 if the buffer couldn't be added to the 3008f1bc738eSAdrian Chadd * filtered list (failed clone; expired retry) and the caller should 3009f1bc738eSAdrian Chadd * free it and handle it like a failure (eg by sending a BAR.) 3010f1bc738eSAdrian Chadd */ 3011f1bc738eSAdrian Chadd static int 3012f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_single(struct ath_softc *sc, struct ath_tid *tid, 3013f1bc738eSAdrian Chadd struct ath_buf *bf) 3014f1bc738eSAdrian Chadd { 3015f1bc738eSAdrian Chadd struct ath_buf *nbf; 3016f1bc738eSAdrian Chadd int retval; 3017f1bc738eSAdrian Chadd 3018f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 3019f1bc738eSAdrian Chadd 3020f1bc738eSAdrian Chadd /* 3021f1bc738eSAdrian Chadd * Don't allow a filtered frame to live forever. 3022f1bc738eSAdrian Chadd */ 3023f1bc738eSAdrian Chadd if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3024f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3025f1bc738eSAdrian Chadd "%s: bf=%p, seqno=%d, exceeded retries\n", 3026f1bc738eSAdrian Chadd __func__, 3027f1bc738eSAdrian Chadd bf, 3028f1bc738eSAdrian Chadd bf->bf_state.bfs_seqno); 3029f1bc738eSAdrian Chadd return (0); 3030f1bc738eSAdrian Chadd } 3031f1bc738eSAdrian Chadd 3032f1bc738eSAdrian Chadd /* 3033f1bc738eSAdrian Chadd * A busy buffer can't be added to the retry list. 3034f1bc738eSAdrian Chadd * It needs to be cloned. 3035f1bc738eSAdrian Chadd */ 3036f1bc738eSAdrian Chadd if (bf->bf_flags & ATH_BUF_BUSY) { 3037f1bc738eSAdrian Chadd nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3038f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3039f1bc738eSAdrian Chadd "%s: busy buffer clone: %p -> %p\n", 3040f1bc738eSAdrian Chadd __func__, bf, nbf); 3041f1bc738eSAdrian Chadd } else { 3042f1bc738eSAdrian Chadd nbf = bf; 3043f1bc738eSAdrian Chadd } 3044f1bc738eSAdrian Chadd 3045f1bc738eSAdrian Chadd if (nbf == NULL) { 3046f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3047f1bc738eSAdrian Chadd "%s: busy buffer couldn't be cloned (%p)!\n", 3048f1bc738eSAdrian Chadd __func__, bf); 3049f1bc738eSAdrian Chadd retval = 1; 3050f1bc738eSAdrian Chadd } else { 3051f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3052f1bc738eSAdrian Chadd retval = 0; 3053f1bc738eSAdrian Chadd } 3054f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, tid); 3055f1bc738eSAdrian Chadd 3056f1bc738eSAdrian Chadd return (retval); 3057f1bc738eSAdrian Chadd } 3058f1bc738eSAdrian Chadd 3059f1bc738eSAdrian Chadd static void 3060f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_aggr(struct ath_softc *sc, struct ath_tid *tid, 3061f1bc738eSAdrian Chadd struct ath_buf *bf_first, ath_bufhead *bf_q) 3062f1bc738eSAdrian Chadd { 3063f1bc738eSAdrian Chadd struct ath_buf *bf, *bf_next, *nbf; 3064f1bc738eSAdrian Chadd 3065f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 3066f1bc738eSAdrian Chadd 3067f1bc738eSAdrian Chadd bf = bf_first; 3068f1bc738eSAdrian Chadd while (bf) { 3069f1bc738eSAdrian Chadd bf_next = bf->bf_next; 3070f1bc738eSAdrian Chadd bf->bf_next = NULL; /* Remove it from the aggr list */ 3071f1bc738eSAdrian Chadd 3072f1bc738eSAdrian Chadd /* 3073f1bc738eSAdrian Chadd * Don't allow a filtered frame to live forever. 3074f1bc738eSAdrian Chadd */ 3075f1bc738eSAdrian Chadd if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3076f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3077f1bc738eSAdrian Chadd "%s: bf=%p, seqno=%d, exceeded retries\n", 3078f1bc738eSAdrian Chadd __func__, 3079f1bc738eSAdrian Chadd bf, 3080f1bc738eSAdrian Chadd bf->bf_state.bfs_seqno); 3081f1bc738eSAdrian Chadd TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3082f1bc738eSAdrian Chadd goto next; 3083f1bc738eSAdrian Chadd } 3084f1bc738eSAdrian Chadd 3085f1bc738eSAdrian Chadd if (bf->bf_flags & ATH_BUF_BUSY) { 3086f1bc738eSAdrian Chadd nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3087f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3088f1bc738eSAdrian Chadd "%s: busy buffer cloned: %p -> %p", 3089f1bc738eSAdrian Chadd __func__, bf, nbf); 3090f1bc738eSAdrian Chadd } else { 3091f1bc738eSAdrian Chadd nbf = bf; 3092f1bc738eSAdrian Chadd } 3093f1bc738eSAdrian Chadd 3094f1bc738eSAdrian Chadd /* 3095f1bc738eSAdrian Chadd * If the buffer couldn't be cloned, add it to bf_q; 3096f1bc738eSAdrian Chadd * the caller will free the buffer(s) as required. 3097f1bc738eSAdrian Chadd */ 3098f1bc738eSAdrian Chadd if (nbf == NULL) { 3099f1bc738eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3100f1bc738eSAdrian Chadd "%s: buffer couldn't be cloned! (%p)\n", 3101f1bc738eSAdrian Chadd __func__, bf); 3102f1bc738eSAdrian Chadd TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3103f1bc738eSAdrian Chadd } else { 3104f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3105f1bc738eSAdrian Chadd } 3106f1bc738eSAdrian Chadd next: 3107f1bc738eSAdrian Chadd bf = bf_next; 3108f1bc738eSAdrian Chadd } 3109f1bc738eSAdrian Chadd 3110f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, tid); 3111f1bc738eSAdrian Chadd } 3112f1bc738eSAdrian Chadd 3113f1bc738eSAdrian Chadd /* 311488b3d483SAdrian Chadd * Suspend the queue because we need to TX a BAR. 311588b3d483SAdrian Chadd */ 311688b3d483SAdrian Chadd static void 311788b3d483SAdrian Chadd ath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid) 311888b3d483SAdrian Chadd { 311988b3d483SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 312088b3d483SAdrian Chadd 31210e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3122e60c4fc2SAdrian Chadd "%s: tid=%p, bar_wait=%d, bar_tx=%d, called\n", 312388b3d483SAdrian Chadd __func__, 3124e60c4fc2SAdrian Chadd tid, 3125e60c4fc2SAdrian Chadd tid->bar_wait, 3126e60c4fc2SAdrian Chadd tid->bar_tx); 312788b3d483SAdrian Chadd 312888b3d483SAdrian Chadd /* We shouldn't be called when bar_tx is 1 */ 312988b3d483SAdrian Chadd if (tid->bar_tx) { 313088b3d483SAdrian Chadd device_printf(sc->sc_dev, "%s: bar_tx is 1?!\n", 313188b3d483SAdrian Chadd __func__); 313288b3d483SAdrian Chadd } 313388b3d483SAdrian Chadd 313488b3d483SAdrian Chadd /* If we've already been called, just be patient. */ 313588b3d483SAdrian Chadd if (tid->bar_wait) 313688b3d483SAdrian Chadd return; 313788b3d483SAdrian Chadd 313888b3d483SAdrian Chadd /* Wait! */ 313988b3d483SAdrian Chadd tid->bar_wait = 1; 314088b3d483SAdrian Chadd 314188b3d483SAdrian Chadd /* Only one pause, no matter how many frames fail */ 314288b3d483SAdrian Chadd ath_tx_tid_pause(sc, tid); 314388b3d483SAdrian Chadd } 314488b3d483SAdrian Chadd 314588b3d483SAdrian Chadd /* 314688b3d483SAdrian Chadd * We've finished with BAR handling - either we succeeded or 314788b3d483SAdrian Chadd * failed. Either way, unsuspend TX. 314888b3d483SAdrian Chadd */ 314988b3d483SAdrian Chadd static void 315088b3d483SAdrian Chadd ath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid) 315188b3d483SAdrian Chadd { 315288b3d483SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 315388b3d483SAdrian Chadd 31540e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 315588b3d483SAdrian Chadd "%s: tid=%p, called\n", 315688b3d483SAdrian Chadd __func__, 315788b3d483SAdrian Chadd tid); 315888b3d483SAdrian Chadd 315988b3d483SAdrian Chadd if (tid->bar_tx == 0 || tid->bar_wait == 0) { 316088b3d483SAdrian Chadd device_printf(sc->sc_dev, "%s: bar_tx=%d, bar_wait=%d: ?\n", 316188b3d483SAdrian Chadd __func__, tid->bar_tx, tid->bar_wait); 316288b3d483SAdrian Chadd } 316388b3d483SAdrian Chadd 316488b3d483SAdrian Chadd tid->bar_tx = tid->bar_wait = 0; 316588b3d483SAdrian Chadd ath_tx_tid_resume(sc, tid); 316688b3d483SAdrian Chadd } 316788b3d483SAdrian Chadd 316888b3d483SAdrian Chadd /* 316988b3d483SAdrian Chadd * Return whether we're ready to TX a BAR frame. 317088b3d483SAdrian Chadd * 317188b3d483SAdrian Chadd * Requires the TID lock be held. 317288b3d483SAdrian Chadd */ 317388b3d483SAdrian Chadd static int 317488b3d483SAdrian Chadd ath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid) 317588b3d483SAdrian Chadd { 317688b3d483SAdrian Chadd 317788b3d483SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 317888b3d483SAdrian Chadd 317988b3d483SAdrian Chadd if (tid->bar_wait == 0 || tid->hwq_depth > 0) 318088b3d483SAdrian Chadd return (0); 318188b3d483SAdrian Chadd 31820e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, "%s: tid=%p (%d), bar ready\n", 31830e22ed0eSAdrian Chadd __func__, tid, tid->tid); 31840e22ed0eSAdrian Chadd 318588b3d483SAdrian Chadd return (1); 318688b3d483SAdrian Chadd } 318788b3d483SAdrian Chadd 318888b3d483SAdrian Chadd /* 318988b3d483SAdrian Chadd * Check whether the current TID is ready to have a BAR 319088b3d483SAdrian Chadd * TXed and if so, do the TX. 319188b3d483SAdrian Chadd * 319288b3d483SAdrian Chadd * Since the TID/TXQ lock can't be held during a call to 319388b3d483SAdrian Chadd * ieee80211_send_bar(), we have to do the dirty thing of unlocking it, 319488b3d483SAdrian Chadd * sending the BAR and locking it again. 319588b3d483SAdrian Chadd * 319688b3d483SAdrian Chadd * Eventually, the code to send the BAR should be broken out 319788b3d483SAdrian Chadd * from this routine so the lock doesn't have to be reacquired 319888b3d483SAdrian Chadd * just to be immediately dropped by the caller. 319988b3d483SAdrian Chadd */ 320088b3d483SAdrian Chadd static void 320188b3d483SAdrian Chadd ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid) 320288b3d483SAdrian Chadd { 320388b3d483SAdrian Chadd struct ieee80211_tx_ampdu *tap; 320488b3d483SAdrian Chadd 320588b3d483SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 320688b3d483SAdrian Chadd 32070e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 320888b3d483SAdrian Chadd "%s: tid=%p, called\n", 320988b3d483SAdrian Chadd __func__, 321088b3d483SAdrian Chadd tid); 321188b3d483SAdrian Chadd 321288b3d483SAdrian Chadd tap = ath_tx_get_tx_tid(tid->an, tid->tid); 321388b3d483SAdrian Chadd 321488b3d483SAdrian Chadd /* 321588b3d483SAdrian Chadd * This is an error condition! 321688b3d483SAdrian Chadd */ 321788b3d483SAdrian Chadd if (tid->bar_wait == 0 || tid->bar_tx == 1) { 321888b3d483SAdrian Chadd device_printf(sc->sc_dev, 321988b3d483SAdrian Chadd "%s: tid=%p, bar_tx=%d, bar_wait=%d: ?\n", 322088b3d483SAdrian Chadd __func__, 322188b3d483SAdrian Chadd tid, 322288b3d483SAdrian Chadd tid->bar_tx, 322388b3d483SAdrian Chadd tid->bar_wait); 322488b3d483SAdrian Chadd return; 322588b3d483SAdrian Chadd } 322688b3d483SAdrian Chadd 322788b3d483SAdrian Chadd /* Don't do anything if we still have pending frames */ 322888b3d483SAdrian Chadd if (tid->hwq_depth > 0) { 32290e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 323088b3d483SAdrian Chadd "%s: tid=%p, hwq_depth=%d, waiting\n", 323188b3d483SAdrian Chadd __func__, 323288b3d483SAdrian Chadd tid, 323388b3d483SAdrian Chadd tid->hwq_depth); 323488b3d483SAdrian Chadd return; 323588b3d483SAdrian Chadd } 323688b3d483SAdrian Chadd 323788b3d483SAdrian Chadd /* We're now about to TX */ 323888b3d483SAdrian Chadd tid->bar_tx = 1; 323988b3d483SAdrian Chadd 324088b3d483SAdrian Chadd /* 32414e81f27cSAdrian Chadd * Override the clrdmask configuration for the next frame, 32424e81f27cSAdrian Chadd * just to get the ball rolling. 32434e81f27cSAdrian Chadd */ 32444e81f27cSAdrian Chadd tid->clrdmask = 1; 32454e81f27cSAdrian Chadd 32464e81f27cSAdrian Chadd /* 324788b3d483SAdrian Chadd * Calculate new BAW left edge, now that all frames have either 324888b3d483SAdrian Chadd * succeeded or failed. 324988b3d483SAdrian Chadd * 325088b3d483SAdrian Chadd * XXX verify this is _actually_ the valid value to begin at! 325188b3d483SAdrian Chadd */ 32520e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 325388b3d483SAdrian Chadd "%s: tid=%p, new BAW left edge=%d\n", 325488b3d483SAdrian Chadd __func__, 325588b3d483SAdrian Chadd tid, 325688b3d483SAdrian Chadd tap->txa_start); 325788b3d483SAdrian Chadd 325888b3d483SAdrian Chadd /* Try sending the BAR frame */ 325988b3d483SAdrian Chadd /* We can't hold the lock here! */ 326088b3d483SAdrian Chadd 326188b3d483SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 326288b3d483SAdrian Chadd if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) { 326388b3d483SAdrian Chadd /* Success? Now we wait for notification that it's done */ 326488b3d483SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 326588b3d483SAdrian Chadd return; 326688b3d483SAdrian Chadd } 326788b3d483SAdrian Chadd 326888b3d483SAdrian Chadd /* Failure? For now, warn loudly and continue */ 326988b3d483SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 327088b3d483SAdrian Chadd device_printf(sc->sc_dev, "%s: tid=%p, failed to TX BAR, continue!\n", 327188b3d483SAdrian Chadd __func__, tid); 327288b3d483SAdrian Chadd ath_tx_tid_bar_unsuspend(sc, tid); 327388b3d483SAdrian Chadd } 327488b3d483SAdrian Chadd 3275eb6f0de0SAdrian Chadd static void 3276f1bc738eSAdrian Chadd ath_tx_tid_drain_pkt(struct ath_softc *sc, struct ath_node *an, 3277f1bc738eSAdrian Chadd struct ath_tid *tid, ath_bufhead *bf_cq, struct ath_buf *bf) 3278eb6f0de0SAdrian Chadd { 3279eb6f0de0SAdrian Chadd 3280f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 3281eb6f0de0SAdrian Chadd 3282eb6f0de0SAdrian Chadd /* 3283eb6f0de0SAdrian Chadd * If the current TID is running AMPDU, update 3284eb6f0de0SAdrian Chadd * the BAW. 3285eb6f0de0SAdrian Chadd */ 3286eb6f0de0SAdrian Chadd if (ath_tx_ampdu_running(sc, an, tid->tid) && 3287eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw) { 3288eb6f0de0SAdrian Chadd /* 3289eb6f0de0SAdrian Chadd * Only remove the frame from the BAW if it's 3290eb6f0de0SAdrian Chadd * been transmitted at least once; this means 3291eb6f0de0SAdrian Chadd * the frame was in the BAW to begin with. 3292eb6f0de0SAdrian Chadd */ 3293eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_retries > 0) { 3294eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, tid, bf); 3295eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 3296eb6f0de0SAdrian Chadd } 3297eb6f0de0SAdrian Chadd /* 3298eb6f0de0SAdrian Chadd * This has become a non-fatal error now 3299eb6f0de0SAdrian Chadd */ 3300eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 3301eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3302eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 3303eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 3304eb6f0de0SAdrian Chadd } 3305eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(bf_cq, bf, bf_list); 3306eb6f0de0SAdrian Chadd } 3307eb6f0de0SAdrian Chadd 3308f1bc738eSAdrian Chadd static void 3309f1bc738eSAdrian Chadd ath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an, 331003682514SAdrian Chadd const char *pfx, struct ath_tid *tid, struct ath_buf *bf) 3311f1bc738eSAdrian Chadd { 3312f1bc738eSAdrian Chadd struct ieee80211_node *ni = &an->an_node; 3313f1bc738eSAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 3314f1bc738eSAdrian Chadd struct ieee80211_tx_ampdu *tap; 3315f1bc738eSAdrian Chadd 3316f1bc738eSAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 3317f1bc738eSAdrian Chadd 3318f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 331903682514SAdrian Chadd "%s: %s: node %p: bf=%p: addbaw=%d, dobaw=%d, " 3320f1bc738eSAdrian Chadd "seqno=%d, retry=%d\n", 332103682514SAdrian Chadd __func__, pfx, ni, bf, 3322f1bc738eSAdrian Chadd bf->bf_state.bfs_addedbaw, 3323f1bc738eSAdrian Chadd bf->bf_state.bfs_dobaw, 3324f1bc738eSAdrian Chadd SEQNO(bf->bf_state.bfs_seqno), 3325f1bc738eSAdrian Chadd bf->bf_state.bfs_retries); 3326f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 332703682514SAdrian Chadd "%s: node %p: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n", 33284e81f27cSAdrian Chadd __func__, ni, bf, 332903682514SAdrian Chadd txq->axq_qnum, 33304e81f27cSAdrian Chadd txq->axq_depth, 33314e81f27cSAdrian Chadd txq->axq_aggr_depth); 33324e81f27cSAdrian Chadd 33334e81f27cSAdrian Chadd device_printf(sc->sc_dev, 3334f1bc738eSAdrian Chadd "%s: node %p: bf=%p: tid txq_depth=%d hwq_depth=%d, bar_wait=%d, isfiltered=%d\n", 3335f1bc738eSAdrian Chadd __func__, ni, bf, 3336f1bc738eSAdrian Chadd tid->axq_depth, 3337f1bc738eSAdrian Chadd tid->hwq_depth, 3338f1bc738eSAdrian Chadd tid->bar_wait, 3339f1bc738eSAdrian Chadd tid->isfiltered); 3340f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 33414e81f27cSAdrian Chadd "%s: node %p: tid %d: " 33424e81f27cSAdrian Chadd "sched=%d, paused=%d, " 33434e81f27cSAdrian Chadd "incomp=%d, baw_head=%d, " 3344f1bc738eSAdrian Chadd "baw_tail=%d txa_start=%d, ni_txseqs=%d\n", 33454e81f27cSAdrian Chadd __func__, ni, tid->tid, 33464e81f27cSAdrian Chadd tid->sched, tid->paused, 33474e81f27cSAdrian Chadd tid->incomp, tid->baw_head, 3348f1bc738eSAdrian Chadd tid->baw_tail, tap == NULL ? -1 : tap->txa_start, 3349f1bc738eSAdrian Chadd ni->ni_txseqs[tid->tid]); 3350f1bc738eSAdrian Chadd 3351f1bc738eSAdrian Chadd /* XXX Dump the frame, see what it is? */ 3352f1bc738eSAdrian Chadd ieee80211_dump_pkt(ni->ni_ic, 3353f1bc738eSAdrian Chadd mtod(bf->bf_m, const uint8_t *), 3354f1bc738eSAdrian Chadd bf->bf_m->m_len, 0, -1); 3355f1bc738eSAdrian Chadd } 3356f1bc738eSAdrian Chadd 3357f1bc738eSAdrian Chadd /* 3358f1bc738eSAdrian Chadd * Free any packets currently pending in the software TX queue. 3359f1bc738eSAdrian Chadd * 3360f1bc738eSAdrian Chadd * This will be called when a node is being deleted. 3361f1bc738eSAdrian Chadd * 3362f1bc738eSAdrian Chadd * It can also be called on an active node during an interface 3363f1bc738eSAdrian Chadd * reset or state transition. 3364f1bc738eSAdrian Chadd * 3365f1bc738eSAdrian Chadd * (From Linux/reference): 3366f1bc738eSAdrian Chadd * 3367f1bc738eSAdrian Chadd * TODO: For frame(s) that are in the retry state, we will reuse the 3368f1bc738eSAdrian Chadd * sequence number(s) without setting the retry bit. The 3369f1bc738eSAdrian Chadd * alternative is to give up on these and BAR the receiver's window 3370f1bc738eSAdrian Chadd * forward. 3371f1bc738eSAdrian Chadd */ 3372f1bc738eSAdrian Chadd static void 3373f1bc738eSAdrian Chadd ath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an, 3374f1bc738eSAdrian Chadd struct ath_tid *tid, ath_bufhead *bf_cq) 3375f1bc738eSAdrian Chadd { 3376f1bc738eSAdrian Chadd struct ath_buf *bf; 3377f1bc738eSAdrian Chadd struct ieee80211_tx_ampdu *tap; 3378f1bc738eSAdrian Chadd struct ieee80211_node *ni = &an->an_node; 3379f1bc738eSAdrian Chadd int t; 3380f1bc738eSAdrian Chadd 3381f1bc738eSAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 3382f1bc738eSAdrian Chadd 3383f1bc738eSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 3384f1bc738eSAdrian Chadd 3385f1bc738eSAdrian Chadd /* Walk the queue, free frames */ 3386f1bc738eSAdrian Chadd t = 0; 3387f1bc738eSAdrian Chadd for (;;) { 3388f1bc738eSAdrian Chadd bf = TAILQ_FIRST(&tid->axq_q); 3389f1bc738eSAdrian Chadd if (bf == NULL) { 3390f1bc738eSAdrian Chadd break; 3391f1bc738eSAdrian Chadd } 3392f1bc738eSAdrian Chadd 3393f1bc738eSAdrian Chadd if (t == 0) { 339403682514SAdrian Chadd ath_tx_tid_drain_print(sc, an, "norm", tid, bf); 3395f1bc738eSAdrian Chadd t = 1; 3396f1bc738eSAdrian Chadd } 3397f1bc738eSAdrian Chadd 3398f1bc738eSAdrian Chadd ATH_TXQ_REMOVE(tid, bf, bf_list); 3399f1bc738eSAdrian Chadd ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3400f1bc738eSAdrian Chadd } 3401f1bc738eSAdrian Chadd 3402f1bc738eSAdrian Chadd /* And now, drain the filtered frame queue */ 3403f1bc738eSAdrian Chadd t = 0; 3404f1bc738eSAdrian Chadd for (;;) { 3405f1bc738eSAdrian Chadd bf = TAILQ_FIRST(&tid->filtq.axq_q); 3406f1bc738eSAdrian Chadd if (bf == NULL) 3407f1bc738eSAdrian Chadd break; 3408f1bc738eSAdrian Chadd 3409f1bc738eSAdrian Chadd if (t == 0) { 341003682514SAdrian Chadd ath_tx_tid_drain_print(sc, an, "filt", tid, bf); 3411f1bc738eSAdrian Chadd t = 1; 3412f1bc738eSAdrian Chadd } 3413f1bc738eSAdrian Chadd 3414f1bc738eSAdrian Chadd ATH_TXQ_REMOVE(&tid->filtq, bf, bf_list); 3415f1bc738eSAdrian Chadd ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3416f1bc738eSAdrian Chadd } 3417f1bc738eSAdrian Chadd 3418eb6f0de0SAdrian Chadd /* 34194e81f27cSAdrian Chadd * Override the clrdmask configuration for the next frame 34204e81f27cSAdrian Chadd * in case there is some future transmission, just to get 34214e81f27cSAdrian Chadd * the ball rolling. 34224e81f27cSAdrian Chadd * 34234e81f27cSAdrian Chadd * This won't hurt things if the TID is about to be freed. 34244e81f27cSAdrian Chadd */ 34254e81f27cSAdrian Chadd tid->clrdmask = 1; 34264e81f27cSAdrian Chadd 34274e81f27cSAdrian Chadd /* 3428eb6f0de0SAdrian Chadd * Now that it's completed, grab the TID lock and update 3429eb6f0de0SAdrian Chadd * the sequence number and BAW window. 3430eb6f0de0SAdrian Chadd * Because sequence numbers have been assigned to frames 3431eb6f0de0SAdrian Chadd * that haven't been sent yet, it's entirely possible 3432eb6f0de0SAdrian Chadd * we'll be called with some pending frames that have not 3433eb6f0de0SAdrian Chadd * been transmitted. 3434eb6f0de0SAdrian Chadd * 3435eb6f0de0SAdrian Chadd * The cleaner solution is to do the sequence number allocation 3436eb6f0de0SAdrian Chadd * when the packet is first transmitted - and thus the "retries" 3437eb6f0de0SAdrian Chadd * check above would be enough to update the BAW/seqno. 3438eb6f0de0SAdrian Chadd */ 3439eb6f0de0SAdrian Chadd 3440eb6f0de0SAdrian Chadd /* But don't do it for non-QoS TIDs */ 3441eb6f0de0SAdrian Chadd if (tap) { 3442eb6f0de0SAdrian Chadd #if 0 3443eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3444eb6f0de0SAdrian Chadd "%s: node %p: TID %d: sliding BAW left edge to %d\n", 3445eb6f0de0SAdrian Chadd __func__, an, tid->tid, tap->txa_start); 3446eb6f0de0SAdrian Chadd #endif 3447eb6f0de0SAdrian Chadd ni->ni_txseqs[tid->tid] = tap->txa_start; 3448eb6f0de0SAdrian Chadd tid->baw_tail = tid->baw_head; 3449eb6f0de0SAdrian Chadd } 3450eb6f0de0SAdrian Chadd } 3451eb6f0de0SAdrian Chadd 3452eb6f0de0SAdrian Chadd /* 3453eb6f0de0SAdrian Chadd * Flush all software queued packets for the given node. 3454eb6f0de0SAdrian Chadd * 3455eb6f0de0SAdrian Chadd * This occurs when a completion handler frees the last buffer 3456eb6f0de0SAdrian Chadd * for a node, and the node is thus freed. This causes the node 3457eb6f0de0SAdrian Chadd * to be cleaned up, which ends up calling ath_tx_node_flush. 3458eb6f0de0SAdrian Chadd */ 3459eb6f0de0SAdrian Chadd void 3460eb6f0de0SAdrian Chadd ath_tx_node_flush(struct ath_softc *sc, struct ath_node *an) 3461eb6f0de0SAdrian Chadd { 3462eb6f0de0SAdrian Chadd int tid; 3463eb6f0de0SAdrian Chadd ath_bufhead bf_cq; 3464eb6f0de0SAdrian Chadd struct ath_buf *bf; 3465eb6f0de0SAdrian Chadd 3466eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_cq); 3467eb6f0de0SAdrian Chadd 346803682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_NODE, 1, "ath_tx_node_flush: flush node; ni=%p", 346903682514SAdrian Chadd &an->an_node); 347003682514SAdrian Chadd 3471eb6f0de0SAdrian Chadd for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 3472eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3473eb6f0de0SAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[atid->ac]; 3474eb6f0de0SAdrian Chadd 3475eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(txq); 3476eb6f0de0SAdrian Chadd /* Free packets */ 3477eb6f0de0SAdrian Chadd ath_tx_tid_drain(sc, an, atid, &bf_cq); 347823f44d2bSAdrian Chadd /* Remove this tid from the list of active tids */ 347923f44d2bSAdrian Chadd ath_tx_tid_unsched(sc, atid); 3480eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(txq); 3481eb6f0de0SAdrian Chadd } 3482eb6f0de0SAdrian Chadd 3483eb6f0de0SAdrian Chadd /* Handle completed frames */ 3484eb6f0de0SAdrian Chadd while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3485eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_cq, bf, bf_list); 3486eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 3487eb6f0de0SAdrian Chadd } 3488eb6f0de0SAdrian Chadd } 3489eb6f0de0SAdrian Chadd 3490eb6f0de0SAdrian Chadd /* 3491eb6f0de0SAdrian Chadd * Drain all the software TXQs currently with traffic queued. 3492eb6f0de0SAdrian Chadd */ 3493eb6f0de0SAdrian Chadd void 3494eb6f0de0SAdrian Chadd ath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq) 3495eb6f0de0SAdrian Chadd { 3496eb6f0de0SAdrian Chadd struct ath_tid *tid; 3497eb6f0de0SAdrian Chadd ath_bufhead bf_cq; 3498eb6f0de0SAdrian Chadd struct ath_buf *bf; 3499eb6f0de0SAdrian Chadd 3500eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_cq); 3501eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(txq); 3502eb6f0de0SAdrian Chadd 3503eb6f0de0SAdrian Chadd /* 3504eb6f0de0SAdrian Chadd * Iterate over all active tids for the given txq, 3505eb6f0de0SAdrian Chadd * flushing and unsched'ing them 3506eb6f0de0SAdrian Chadd */ 3507eb6f0de0SAdrian Chadd while (! TAILQ_EMPTY(&txq->axq_tidq)) { 3508eb6f0de0SAdrian Chadd tid = TAILQ_FIRST(&txq->axq_tidq); 3509eb6f0de0SAdrian Chadd ath_tx_tid_drain(sc, tid->an, tid, &bf_cq); 3510eb6f0de0SAdrian Chadd ath_tx_tid_unsched(sc, tid); 3511eb6f0de0SAdrian Chadd } 3512eb6f0de0SAdrian Chadd 3513eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(txq); 3514eb6f0de0SAdrian Chadd 3515eb6f0de0SAdrian Chadd while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3516eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_cq, bf, bf_list); 3517eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 3518eb6f0de0SAdrian Chadd } 3519eb6f0de0SAdrian Chadd } 3520eb6f0de0SAdrian Chadd 3521eb6f0de0SAdrian Chadd /* 3522eb6f0de0SAdrian Chadd * Handle completion of non-aggregate session frames. 35230c54de88SAdrian Chadd * 35240c54de88SAdrian Chadd * This (currently) doesn't implement software retransmission of 35250c54de88SAdrian Chadd * non-aggregate frames! 35260c54de88SAdrian Chadd * 35270c54de88SAdrian Chadd * Software retransmission of non-aggregate frames needs to obey 35280c54de88SAdrian Chadd * the strict sequence number ordering, and drop any frames that 35290c54de88SAdrian Chadd * will fail this. 35300c54de88SAdrian Chadd * 35310c54de88SAdrian Chadd * For now, filtered frames and frame transmission will cause 35320c54de88SAdrian Chadd * all kinds of issues. So we don't support them. 35330c54de88SAdrian Chadd * 35340c54de88SAdrian Chadd * So anyone queuing frames via ath_tx_normal_xmit() or 35350c54de88SAdrian Chadd * ath_tx_hw_queue_norm() must override and set CLRDMASK. 3536eb6f0de0SAdrian Chadd */ 3537eb6f0de0SAdrian Chadd void 3538eb6f0de0SAdrian Chadd ath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3539eb6f0de0SAdrian Chadd { 3540eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf->bf_node; 3541eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 3542eb6f0de0SAdrian Chadd int tid = bf->bf_state.bfs_tid; 3543eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3544eb6f0de0SAdrian Chadd struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3545eb6f0de0SAdrian Chadd 3546eb6f0de0SAdrian Chadd /* The TID state is protected behind the TXQ lock */ 3547eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3548eb6f0de0SAdrian Chadd 3549eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n", 3550eb6f0de0SAdrian Chadd __func__, bf, fail, atid->hwq_depth - 1); 3551eb6f0de0SAdrian Chadd 3552eb6f0de0SAdrian Chadd atid->hwq_depth--; 3553f1bc738eSAdrian Chadd 35540c54de88SAdrian Chadd #if 0 35550c54de88SAdrian Chadd /* 35560c54de88SAdrian Chadd * If the frame was filtered, stick it on the filter frame 35570c54de88SAdrian Chadd * queue and complain about it. It shouldn't happen! 35580c54de88SAdrian Chadd */ 35590c54de88SAdrian Chadd if ((ts->ts_status & HAL_TXERR_FILT) || 35600c54de88SAdrian Chadd (ts->ts_status != 0 && atid->isfiltered)) { 35610c54de88SAdrian Chadd device_printf(sc->sc_dev, 35620c54de88SAdrian Chadd "%s: isfiltered=%d, ts_status=%d: huh?\n", 35630c54de88SAdrian Chadd __func__, 35640c54de88SAdrian Chadd atid->isfiltered, 35650c54de88SAdrian Chadd ts->ts_status); 35660c54de88SAdrian Chadd ath_tx_tid_filt_comp_buf(sc, atid, bf); 35670c54de88SAdrian Chadd } 35680c54de88SAdrian Chadd #endif 3569f1bc738eSAdrian Chadd if (atid->isfiltered) 35700c54de88SAdrian Chadd device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 3571eb6f0de0SAdrian Chadd if (atid->hwq_depth < 0) 3572eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3573eb6f0de0SAdrian Chadd __func__, atid->hwq_depth); 3574f1bc738eSAdrian Chadd 3575f1bc738eSAdrian Chadd /* 3576f1bc738eSAdrian Chadd * If the queue is filtered, potentially mark it as complete 3577f1bc738eSAdrian Chadd * and reschedule it as needed. 3578f1bc738eSAdrian Chadd * 3579f1bc738eSAdrian Chadd * This is required as there may be a subsequent TX descriptor 3580f1bc738eSAdrian Chadd * for this end-node that has CLRDMASK set, so it's quite possible 3581f1bc738eSAdrian Chadd * that a filtered frame will be followed by a non-filtered 3582f1bc738eSAdrian Chadd * (complete or otherwise) frame. 3583f1bc738eSAdrian Chadd * 3584f1bc738eSAdrian Chadd * XXX should we do this before we complete the frame? 3585f1bc738eSAdrian Chadd */ 3586f1bc738eSAdrian Chadd if (atid->isfiltered) 3587f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, atid); 3588eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3589eb6f0de0SAdrian Chadd 3590eb6f0de0SAdrian Chadd /* 3591eb6f0de0SAdrian Chadd * punt to rate control if we're not being cleaned up 3592eb6f0de0SAdrian Chadd * during a hw queue drain and the frame wanted an ACK. 3593eb6f0de0SAdrian Chadd */ 3594875a9451SAdrian Chadd if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3595eb6f0de0SAdrian Chadd ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3596eb6f0de0SAdrian Chadd ts, bf->bf_state.bfs_pktlen, 3597eb6f0de0SAdrian Chadd 1, (ts->ts_status == 0) ? 0 : 1); 3598eb6f0de0SAdrian Chadd 3599eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, fail); 3600eb6f0de0SAdrian Chadd } 3601eb6f0de0SAdrian Chadd 3602eb6f0de0SAdrian Chadd /* 3603eb6f0de0SAdrian Chadd * Handle cleanup of aggregate session packets that aren't 3604eb6f0de0SAdrian Chadd * an A-MPDU. 3605eb6f0de0SAdrian Chadd * 3606eb6f0de0SAdrian Chadd * There's no need to update the BAW here - the session is being 3607eb6f0de0SAdrian Chadd * torn down. 3608eb6f0de0SAdrian Chadd */ 3609eb6f0de0SAdrian Chadd static void 3610eb6f0de0SAdrian Chadd ath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3611eb6f0de0SAdrian Chadd { 3612eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf->bf_node; 3613eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 3614eb6f0de0SAdrian Chadd int tid = bf->bf_state.bfs_tid; 3615eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3616eb6f0de0SAdrian Chadd 3617eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n", 3618eb6f0de0SAdrian Chadd __func__, tid, atid->incomp); 3619eb6f0de0SAdrian Chadd 3620eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3621eb6f0de0SAdrian Chadd atid->incomp--; 3622eb6f0de0SAdrian Chadd if (atid->incomp == 0) { 3623eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3624eb6f0de0SAdrian Chadd "%s: TID %d: cleaned up! resume!\n", 3625eb6f0de0SAdrian Chadd __func__, tid); 3626eb6f0de0SAdrian Chadd atid->cleanup_inprogress = 0; 3627eb6f0de0SAdrian Chadd ath_tx_tid_resume(sc, atid); 3628eb6f0de0SAdrian Chadd } 3629eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3630eb6f0de0SAdrian Chadd 3631eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 3632eb6f0de0SAdrian Chadd } 3633eb6f0de0SAdrian Chadd 3634eb6f0de0SAdrian Chadd /* 3635eb6f0de0SAdrian Chadd * Performs transmit side cleanup when TID changes from aggregated to 3636eb6f0de0SAdrian Chadd * unaggregated. 3637eb6f0de0SAdrian Chadd * 3638eb6f0de0SAdrian Chadd * - Discard all retry frames from the s/w queue. 3639eb6f0de0SAdrian Chadd * - Fix the tx completion function for all buffers in s/w queue. 3640eb6f0de0SAdrian Chadd * - Count the number of unacked frames, and let transmit completion 3641eb6f0de0SAdrian Chadd * handle it later. 3642eb6f0de0SAdrian Chadd * 3643eb6f0de0SAdrian Chadd * The caller is responsible for pausing the TID. 3644eb6f0de0SAdrian Chadd */ 3645eb6f0de0SAdrian Chadd static void 36464dfd4507SAdrian Chadd ath_tx_tid_cleanup(struct ath_softc *sc, struct ath_node *an, int tid) 3647eb6f0de0SAdrian Chadd { 3648eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3649eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 3650eb6f0de0SAdrian Chadd struct ath_buf *bf, *bf_next; 3651eb6f0de0SAdrian Chadd ath_bufhead bf_cq; 3652eb6f0de0SAdrian Chadd 3653d3a6425bSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 3654eb6f0de0SAdrian Chadd "%s: TID %d: called\n", __func__, tid); 3655eb6f0de0SAdrian Chadd 3656eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_cq); 3657eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3658eb6f0de0SAdrian Chadd 3659eb6f0de0SAdrian Chadd /* 3660f1bc738eSAdrian Chadd * Move the filtered frames to the TX queue, before 3661f1bc738eSAdrian Chadd * we run off and discard/process things. 3662f1bc738eSAdrian Chadd */ 3663f1bc738eSAdrian Chadd /* XXX this is really quite inefficient */ 3664f1bc738eSAdrian Chadd while ((bf = TAILQ_LAST(&atid->filtq.axq_q, ath_bufhead_s)) != NULL) { 3665f1bc738eSAdrian Chadd ATH_TXQ_REMOVE(&atid->filtq, bf, bf_list); 3666f1bc738eSAdrian Chadd ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3667f1bc738eSAdrian Chadd } 3668f1bc738eSAdrian Chadd 3669f1bc738eSAdrian Chadd /* 3670eb6f0de0SAdrian Chadd * Update the frames in the software TX queue: 3671eb6f0de0SAdrian Chadd * 3672eb6f0de0SAdrian Chadd * + Discard retry frames in the queue 3673eb6f0de0SAdrian Chadd * + Fix the completion function to be non-aggregate 3674eb6f0de0SAdrian Chadd */ 3675eb6f0de0SAdrian Chadd bf = TAILQ_FIRST(&atid->axq_q); 3676eb6f0de0SAdrian Chadd while (bf) { 3677eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_isretried) { 3678eb6f0de0SAdrian Chadd bf_next = TAILQ_NEXT(bf, bf_list); 3679eb6f0de0SAdrian Chadd TAILQ_REMOVE(&atid->axq_q, bf, bf_list); 3680eb6f0de0SAdrian Chadd atid->axq_depth--; 3681eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_dobaw) { 3682eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 3683eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 3684eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3685eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 3686d4365d16SAdrian Chadd __func__, 3687d4365d16SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)); 3688eb6f0de0SAdrian Chadd } 3689eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 3690eb6f0de0SAdrian Chadd /* 3691eb6f0de0SAdrian Chadd * Call the default completion handler with "fail" just 3692eb6f0de0SAdrian Chadd * so upper levels are suitably notified about this. 3693eb6f0de0SAdrian Chadd */ 3694eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3695eb6f0de0SAdrian Chadd bf = bf_next; 3696eb6f0de0SAdrian Chadd continue; 3697eb6f0de0SAdrian Chadd } 3698eb6f0de0SAdrian Chadd /* Give these the default completion handler */ 3699eb6f0de0SAdrian Chadd bf->bf_comp = ath_tx_normal_comp; 3700eb6f0de0SAdrian Chadd bf = TAILQ_NEXT(bf, bf_list); 3701eb6f0de0SAdrian Chadd } 3702eb6f0de0SAdrian Chadd 3703eb6f0de0SAdrian Chadd /* The caller is required to pause the TID */ 3704eb6f0de0SAdrian Chadd #if 0 3705eb6f0de0SAdrian Chadd /* Pause the TID */ 3706eb6f0de0SAdrian Chadd ath_tx_tid_pause(sc, atid); 3707eb6f0de0SAdrian Chadd #endif 3708eb6f0de0SAdrian Chadd 3709eb6f0de0SAdrian Chadd /* 3710eb6f0de0SAdrian Chadd * Calculate what hardware-queued frames exist based 3711eb6f0de0SAdrian Chadd * on the current BAW size. Ie, what frames have been 3712eb6f0de0SAdrian Chadd * added to the TX hardware queue for this TID but 3713eb6f0de0SAdrian Chadd * not yet ACKed. 3714eb6f0de0SAdrian Chadd */ 3715eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid); 3716eb6f0de0SAdrian Chadd /* Need the lock - fiddling with BAW */ 3717eb6f0de0SAdrian Chadd while (atid->baw_head != atid->baw_tail) { 3718eb6f0de0SAdrian Chadd if (atid->tx_buf[atid->baw_head]) { 3719eb6f0de0SAdrian Chadd atid->incomp++; 3720eb6f0de0SAdrian Chadd atid->cleanup_inprogress = 1; 3721eb6f0de0SAdrian Chadd atid->tx_buf[atid->baw_head] = NULL; 3722eb6f0de0SAdrian Chadd } 3723eb6f0de0SAdrian Chadd INCR(atid->baw_head, ATH_TID_MAX_BUFS); 3724eb6f0de0SAdrian Chadd INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 3725eb6f0de0SAdrian Chadd } 3726eb6f0de0SAdrian Chadd 3727eb6f0de0SAdrian Chadd /* 3728eb6f0de0SAdrian Chadd * If cleanup is required, defer TID scheduling 3729eb6f0de0SAdrian Chadd * until all the HW queued packets have been 3730eb6f0de0SAdrian Chadd * sent. 3731eb6f0de0SAdrian Chadd */ 3732eb6f0de0SAdrian Chadd if (! atid->cleanup_inprogress) 3733eb6f0de0SAdrian Chadd ath_tx_tid_resume(sc, atid); 3734eb6f0de0SAdrian Chadd 3735eb6f0de0SAdrian Chadd if (atid->cleanup_inprogress) 3736eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3737eb6f0de0SAdrian Chadd "%s: TID %d: cleanup needed: %d packets\n", 3738eb6f0de0SAdrian Chadd __func__, tid, atid->incomp); 3739eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3740eb6f0de0SAdrian Chadd 3741eb6f0de0SAdrian Chadd /* Handle completing frames and fail them */ 3742eb6f0de0SAdrian Chadd while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3743eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_cq, bf, bf_list); 3744eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 1); 3745eb6f0de0SAdrian Chadd } 3746eb6f0de0SAdrian Chadd } 3747eb6f0de0SAdrian Chadd 3748eb6f0de0SAdrian Chadd static struct ath_buf * 374938962489SAdrian Chadd ath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 375038962489SAdrian Chadd struct ath_tid *tid, struct ath_buf *bf) 3751eb6f0de0SAdrian Chadd { 3752eb6f0de0SAdrian Chadd struct ath_buf *nbf; 3753eb6f0de0SAdrian Chadd int error; 3754eb6f0de0SAdrian Chadd 3755eb6f0de0SAdrian Chadd nbf = ath_buf_clone(sc, bf); 3756eb6f0de0SAdrian Chadd 3757eb6f0de0SAdrian Chadd #if 0 3758eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: ATH_BUF_BUSY; cloning\n", 3759eb6f0de0SAdrian Chadd __func__); 3760eb6f0de0SAdrian Chadd #endif 3761eb6f0de0SAdrian Chadd 3762eb6f0de0SAdrian Chadd if (nbf == NULL) { 3763eb6f0de0SAdrian Chadd /* Failed to clone */ 3764eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3765eb6f0de0SAdrian Chadd "%s: failed to clone a busy buffer\n", 3766eb6f0de0SAdrian Chadd __func__); 3767eb6f0de0SAdrian Chadd return NULL; 3768eb6f0de0SAdrian Chadd } 3769eb6f0de0SAdrian Chadd 3770eb6f0de0SAdrian Chadd /* Setup the dma for the new buffer */ 3771eb6f0de0SAdrian Chadd error = ath_tx_dmasetup(sc, nbf, nbf->bf_m); 3772eb6f0de0SAdrian Chadd if (error != 0) { 3773eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3774eb6f0de0SAdrian Chadd "%s: failed to setup dma for clone\n", 3775eb6f0de0SAdrian Chadd __func__); 3776eb6f0de0SAdrian Chadd /* 3777eb6f0de0SAdrian Chadd * Put this at the head of the list, not tail; 3778eb6f0de0SAdrian Chadd * that way it doesn't interfere with the 3779eb6f0de0SAdrian Chadd * busy buffer logic (which uses the tail of 3780eb6f0de0SAdrian Chadd * the list.) 3781eb6f0de0SAdrian Chadd */ 3782eb6f0de0SAdrian Chadd ATH_TXBUF_LOCK(sc); 378332c387f7SAdrian Chadd ath_returnbuf_head(sc, nbf); 3784eb6f0de0SAdrian Chadd ATH_TXBUF_UNLOCK(sc); 3785eb6f0de0SAdrian Chadd return NULL; 3786eb6f0de0SAdrian Chadd } 3787eb6f0de0SAdrian Chadd 378838962489SAdrian Chadd /* Update BAW if required, before we free the original buf */ 378938962489SAdrian Chadd if (bf->bf_state.bfs_dobaw) 379038962489SAdrian Chadd ath_tx_switch_baw_buf(sc, an, tid, bf, nbf); 379138962489SAdrian Chadd 3792eb6f0de0SAdrian Chadd /* Free current buffer; return the older buffer */ 3793eb6f0de0SAdrian Chadd bf->bf_m = NULL; 3794eb6f0de0SAdrian Chadd bf->bf_node = NULL; 3795eb6f0de0SAdrian Chadd ath_freebuf(sc, bf); 3796f1bc738eSAdrian Chadd 3797eb6f0de0SAdrian Chadd return nbf; 3798eb6f0de0SAdrian Chadd } 3799eb6f0de0SAdrian Chadd 3800eb6f0de0SAdrian Chadd /* 3801eb6f0de0SAdrian Chadd * Handle retrying an unaggregate frame in an aggregate 3802eb6f0de0SAdrian Chadd * session. 3803eb6f0de0SAdrian Chadd * 3804eb6f0de0SAdrian Chadd * If too many retries occur, pause the TID, wait for 3805eb6f0de0SAdrian Chadd * any further retransmits (as there's no reason why 3806eb6f0de0SAdrian Chadd * non-aggregate frames in an aggregate session are 3807eb6f0de0SAdrian Chadd * transmitted in-order; they just have to be in-BAW) 3808eb6f0de0SAdrian Chadd * and then queue a BAR. 3809eb6f0de0SAdrian Chadd */ 3810eb6f0de0SAdrian Chadd static void 3811eb6f0de0SAdrian Chadd ath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3812eb6f0de0SAdrian Chadd { 3813eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf->bf_node; 3814eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 3815eb6f0de0SAdrian Chadd int tid = bf->bf_state.bfs_tid; 3816eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3817eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 3818eb6f0de0SAdrian Chadd 3819eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3820eb6f0de0SAdrian Chadd 3821eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid); 3822eb6f0de0SAdrian Chadd 3823eb6f0de0SAdrian Chadd /* 3824eb6f0de0SAdrian Chadd * If the buffer is marked as busy, we can't directly 3825eb6f0de0SAdrian Chadd * reuse it. Instead, try to clone the buffer. 3826eb6f0de0SAdrian Chadd * If the clone is successful, recycle the old buffer. 3827eb6f0de0SAdrian Chadd * If the clone is unsuccessful, set bfs_retries to max 3828eb6f0de0SAdrian Chadd * to force the next bit of code to free the buffer 3829eb6f0de0SAdrian Chadd * for us. 3830eb6f0de0SAdrian Chadd */ 3831eb6f0de0SAdrian Chadd if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3832eb6f0de0SAdrian Chadd (bf->bf_flags & ATH_BUF_BUSY)) { 3833eb6f0de0SAdrian Chadd struct ath_buf *nbf; 383438962489SAdrian Chadd nbf = ath_tx_retry_clone(sc, an, atid, bf); 3835eb6f0de0SAdrian Chadd if (nbf) 3836eb6f0de0SAdrian Chadd /* bf has been freed at this point */ 3837eb6f0de0SAdrian Chadd bf = nbf; 3838eb6f0de0SAdrian Chadd else 3839eb6f0de0SAdrian Chadd bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3840eb6f0de0SAdrian Chadd } 3841eb6f0de0SAdrian Chadd 3842eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3843eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3844eb6f0de0SAdrian Chadd "%s: exceeded retries; seqno %d\n", 3845eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 3846eb6f0de0SAdrian Chadd sc->sc_stats.ast_tx_swretrymax++; 3847eb6f0de0SAdrian Chadd 3848eb6f0de0SAdrian Chadd /* Update BAW anyway */ 3849eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_dobaw) { 3850eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 3851eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 3852eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3853eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 3854eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 3855eb6f0de0SAdrian Chadd } 3856eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 3857eb6f0de0SAdrian Chadd 385888b3d483SAdrian Chadd /* Suspend the TX queue and get ready to send the BAR */ 385988b3d483SAdrian Chadd ath_tx_tid_bar_suspend(sc, atid); 386088b3d483SAdrian Chadd 386188b3d483SAdrian Chadd /* Send the BAR if there are no other frames waiting */ 386288b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 386388b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 386488b3d483SAdrian Chadd 3865eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3866eb6f0de0SAdrian Chadd 3867eb6f0de0SAdrian Chadd /* Free buffer, bf is free after this call */ 3868eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 3869eb6f0de0SAdrian Chadd return; 3870eb6f0de0SAdrian Chadd } 3871eb6f0de0SAdrian Chadd 3872eb6f0de0SAdrian Chadd /* 3873eb6f0de0SAdrian Chadd * This increments the retry counter as well as 3874eb6f0de0SAdrian Chadd * sets the retry flag in the ath_buf and packet 3875eb6f0de0SAdrian Chadd * body. 3876eb6f0de0SAdrian Chadd */ 3877eb6f0de0SAdrian Chadd ath_tx_set_retry(sc, bf); 3878f1bc738eSAdrian Chadd sc->sc_stats.ast_tx_swretries++; 3879eb6f0de0SAdrian Chadd 3880eb6f0de0SAdrian Chadd /* 3881eb6f0de0SAdrian Chadd * Insert this at the head of the queue, so it's 3882eb6f0de0SAdrian Chadd * retried before any current/subsequent frames. 3883eb6f0de0SAdrian Chadd */ 3884eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3885eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, atid); 388688b3d483SAdrian Chadd /* Send the BAR if there are no other frames waiting */ 388788b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 388888b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 3889eb6f0de0SAdrian Chadd 3890eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3891eb6f0de0SAdrian Chadd } 3892eb6f0de0SAdrian Chadd 3893eb6f0de0SAdrian Chadd /* 3894eb6f0de0SAdrian Chadd * Common code for aggregate excessive retry/subframe retry. 3895eb6f0de0SAdrian Chadd * If retrying, queues buffers to bf_q. If not, frees the 3896eb6f0de0SAdrian Chadd * buffers. 3897eb6f0de0SAdrian Chadd * 3898eb6f0de0SAdrian Chadd * XXX should unify this with ath_tx_aggr_retry_unaggr() 3899eb6f0de0SAdrian Chadd */ 3900eb6f0de0SAdrian Chadd static int 3901eb6f0de0SAdrian Chadd ath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf, 3902eb6f0de0SAdrian Chadd ath_bufhead *bf_q) 3903eb6f0de0SAdrian Chadd { 3904eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf->bf_node; 3905eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 3906eb6f0de0SAdrian Chadd int tid = bf->bf_state.bfs_tid; 3907eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 3908eb6f0de0SAdrian Chadd 3909eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[atid->ac]); 3910eb6f0de0SAdrian Chadd 391121840808SAdrian Chadd /* XXX clr11naggr should be done for all subframes */ 3912eb6f0de0SAdrian Chadd ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 3913eb6f0de0SAdrian Chadd ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0); 3914f1bc738eSAdrian Chadd 3915eb6f0de0SAdrian Chadd /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */ 3916eb6f0de0SAdrian Chadd 3917eb6f0de0SAdrian Chadd /* 3918eb6f0de0SAdrian Chadd * If the buffer is marked as busy, we can't directly 3919eb6f0de0SAdrian Chadd * reuse it. Instead, try to clone the buffer. 3920eb6f0de0SAdrian Chadd * If the clone is successful, recycle the old buffer. 3921eb6f0de0SAdrian Chadd * If the clone is unsuccessful, set bfs_retries to max 3922eb6f0de0SAdrian Chadd * to force the next bit of code to free the buffer 3923eb6f0de0SAdrian Chadd * for us. 3924eb6f0de0SAdrian Chadd */ 3925eb6f0de0SAdrian Chadd if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3926eb6f0de0SAdrian Chadd (bf->bf_flags & ATH_BUF_BUSY)) { 3927eb6f0de0SAdrian Chadd struct ath_buf *nbf; 392838962489SAdrian Chadd nbf = ath_tx_retry_clone(sc, an, atid, bf); 3929eb6f0de0SAdrian Chadd if (nbf) 3930eb6f0de0SAdrian Chadd /* bf has been freed at this point */ 3931eb6f0de0SAdrian Chadd bf = nbf; 3932eb6f0de0SAdrian Chadd else 3933eb6f0de0SAdrian Chadd bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3934eb6f0de0SAdrian Chadd } 3935eb6f0de0SAdrian Chadd 3936eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3937eb6f0de0SAdrian Chadd sc->sc_stats.ast_tx_swretrymax++; 3938eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3939eb6f0de0SAdrian Chadd "%s: max retries: seqno %d\n", 3940eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 3941eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 3942eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 3943eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 3944eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 3945eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 3946eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 3947eb6f0de0SAdrian Chadd return 1; 3948eb6f0de0SAdrian Chadd } 3949eb6f0de0SAdrian Chadd 3950eb6f0de0SAdrian Chadd ath_tx_set_retry(sc, bf); 3951f1bc738eSAdrian Chadd sc->sc_stats.ast_tx_swretries++; 3952eb6f0de0SAdrian Chadd bf->bf_next = NULL; /* Just to make sure */ 3953eb6f0de0SAdrian Chadd 395421840808SAdrian Chadd /* Clear the aggregate state */ 395521840808SAdrian Chadd bf->bf_state.bfs_aggr = 0; 395621840808SAdrian Chadd bf->bf_state.bfs_ndelim = 0; /* ??? needed? */ 395721840808SAdrian Chadd bf->bf_state.bfs_nframes = 1; 395821840808SAdrian Chadd 3959eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3960eb6f0de0SAdrian Chadd return 0; 3961eb6f0de0SAdrian Chadd } 3962eb6f0de0SAdrian Chadd 3963eb6f0de0SAdrian Chadd /* 3964eb6f0de0SAdrian Chadd * error pkt completion for an aggregate destination 3965eb6f0de0SAdrian Chadd */ 3966eb6f0de0SAdrian Chadd static void 3967eb6f0de0SAdrian Chadd ath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first, 3968eb6f0de0SAdrian Chadd struct ath_tid *tid) 3969eb6f0de0SAdrian Chadd { 3970eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf_first->bf_node; 3971eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 3972eb6f0de0SAdrian Chadd struct ath_buf *bf_next, *bf; 3973eb6f0de0SAdrian Chadd ath_bufhead bf_q; 3974eb6f0de0SAdrian Chadd int drops = 0; 3975eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 3976eb6f0de0SAdrian Chadd ath_bufhead bf_cq; 3977eb6f0de0SAdrian Chadd 3978eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_q); 3979eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_cq); 3980eb6f0de0SAdrian Chadd 3981eb6f0de0SAdrian Chadd /* 3982eb6f0de0SAdrian Chadd * Update rate control - all frames have failed. 3983eb6f0de0SAdrian Chadd * 3984eb6f0de0SAdrian Chadd * XXX use the length in the first frame in the series; 3985eb6f0de0SAdrian Chadd * XXX just so things are consistent for now. 3986eb6f0de0SAdrian Chadd */ 3987eb6f0de0SAdrian Chadd ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc, 3988eb6f0de0SAdrian Chadd &bf_first->bf_status.ds_txstat, 3989eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_pktlen, 3990eb6f0de0SAdrian Chadd bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes); 3991eb6f0de0SAdrian Chadd 3992eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 3993eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 39942d3d4776SAdrian Chadd sc->sc_stats.ast_tx_aggr_failall++; 3995eb6f0de0SAdrian Chadd 3996eb6f0de0SAdrian Chadd /* Retry all subframes */ 3997eb6f0de0SAdrian Chadd bf = bf_first; 3998eb6f0de0SAdrian Chadd while (bf) { 3999eb6f0de0SAdrian Chadd bf_next = bf->bf_next; 4000eb6f0de0SAdrian Chadd bf->bf_next = NULL; /* Remove it from the aggr list */ 40012d3d4776SAdrian Chadd sc->sc_stats.ast_tx_aggr_fail++; 4002eb6f0de0SAdrian Chadd if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4003eb6f0de0SAdrian Chadd drops++; 4004eb6f0de0SAdrian Chadd bf->bf_next = NULL; 4005eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4006eb6f0de0SAdrian Chadd } 4007eb6f0de0SAdrian Chadd bf = bf_next; 4008eb6f0de0SAdrian Chadd } 4009eb6f0de0SAdrian Chadd 4010eb6f0de0SAdrian Chadd /* Prepend all frames to the beginning of the queue */ 4011eb6f0de0SAdrian Chadd while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4012eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_q, bf, bf_list); 4013eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 4014eb6f0de0SAdrian Chadd } 4015eb6f0de0SAdrian Chadd 401639da9d42SAdrian Chadd /* 401739da9d42SAdrian Chadd * Schedule the TID to be re-tried. 401839da9d42SAdrian Chadd */ 4019eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, tid); 4020eb6f0de0SAdrian Chadd 4021eb6f0de0SAdrian Chadd /* 4022eb6f0de0SAdrian Chadd * send bar if we dropped any frames 4023eb6f0de0SAdrian Chadd * 4024eb6f0de0SAdrian Chadd * Keep the txq lock held for now, as we need to ensure 4025eb6f0de0SAdrian Chadd * that ni_txseqs[] is consistent (as it's being updated 4026eb6f0de0SAdrian Chadd * in the ifnet TX context or raw TX context.) 4027eb6f0de0SAdrian Chadd */ 4028eb6f0de0SAdrian Chadd if (drops) { 402988b3d483SAdrian Chadd /* Suspend the TX queue and get ready to send the BAR */ 403088b3d483SAdrian Chadd ath_tx_tid_bar_suspend(sc, tid); 4031eb6f0de0SAdrian Chadd } 4032eb6f0de0SAdrian Chadd 403388b3d483SAdrian Chadd /* 403488b3d483SAdrian Chadd * Send BAR if required 403588b3d483SAdrian Chadd */ 403688b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, tid)) 403788b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, tid); 4038f1bc738eSAdrian Chadd 403988b3d483SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 404088b3d483SAdrian Chadd 4041eb6f0de0SAdrian Chadd /* Complete frames which errored out */ 4042eb6f0de0SAdrian Chadd while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4043eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_cq, bf, bf_list); 4044eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 4045eb6f0de0SAdrian Chadd } 4046eb6f0de0SAdrian Chadd } 4047eb6f0de0SAdrian Chadd 4048eb6f0de0SAdrian Chadd /* 4049eb6f0de0SAdrian Chadd * Handle clean-up of packets from an aggregate list. 4050eb6f0de0SAdrian Chadd * 4051eb6f0de0SAdrian Chadd * There's no need to update the BAW here - the session is being 4052eb6f0de0SAdrian Chadd * torn down. 4053eb6f0de0SAdrian Chadd */ 4054eb6f0de0SAdrian Chadd static void 4055eb6f0de0SAdrian Chadd ath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first) 4056eb6f0de0SAdrian Chadd { 4057eb6f0de0SAdrian Chadd struct ath_buf *bf, *bf_next; 4058eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf_first->bf_node; 4059eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 4060eb6f0de0SAdrian Chadd int tid = bf_first->bf_state.bfs_tid; 4061eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 4062eb6f0de0SAdrian Chadd 4063eb6f0de0SAdrian Chadd bf = bf_first; 4064eb6f0de0SAdrian Chadd 4065eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4066eb6f0de0SAdrian Chadd 4067eb6f0de0SAdrian Chadd /* update incomp */ 4068eb6f0de0SAdrian Chadd while (bf) { 4069eb6f0de0SAdrian Chadd atid->incomp--; 4070eb6f0de0SAdrian Chadd bf = bf->bf_next; 4071eb6f0de0SAdrian Chadd } 4072eb6f0de0SAdrian Chadd 4073eb6f0de0SAdrian Chadd if (atid->incomp == 0) { 4074eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4075eb6f0de0SAdrian Chadd "%s: TID %d: cleaned up! resume!\n", 4076eb6f0de0SAdrian Chadd __func__, tid); 4077eb6f0de0SAdrian Chadd atid->cleanup_inprogress = 0; 4078eb6f0de0SAdrian Chadd ath_tx_tid_resume(sc, atid); 4079eb6f0de0SAdrian Chadd } 408088b3d483SAdrian Chadd 408188b3d483SAdrian Chadd /* Send BAR if required */ 4082f1bc738eSAdrian Chadd /* XXX why would we send a BAR when transitioning to non-aggregation? */ 408388b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 408488b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 4085f1bc738eSAdrian Chadd 4086eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4087eb6f0de0SAdrian Chadd 4088eb6f0de0SAdrian Chadd /* Handle frame completion */ 4089eb6f0de0SAdrian Chadd while (bf) { 4090eb6f0de0SAdrian Chadd bf_next = bf->bf_next; 4091eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 1); 4092eb6f0de0SAdrian Chadd bf = bf_next; 4093eb6f0de0SAdrian Chadd } 4094eb6f0de0SAdrian Chadd } 4095eb6f0de0SAdrian Chadd 4096eb6f0de0SAdrian Chadd /* 4097eb6f0de0SAdrian Chadd * Handle completion of an set of aggregate frames. 4098eb6f0de0SAdrian Chadd * 4099eb6f0de0SAdrian Chadd * XXX for now, simply complete each sub-frame. 4100eb6f0de0SAdrian Chadd * 4101eb6f0de0SAdrian Chadd * Note: the completion handler is the last descriptor in the aggregate, 4102eb6f0de0SAdrian Chadd * not the last descriptor in the first frame. 4103eb6f0de0SAdrian Chadd */ 4104eb6f0de0SAdrian Chadd static void 4105d4365d16SAdrian Chadd ath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first, 4106d4365d16SAdrian Chadd int fail) 4107eb6f0de0SAdrian Chadd { 4108eb6f0de0SAdrian Chadd //struct ath_desc *ds = bf->bf_lastds; 4109eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf_first->bf_node; 4110eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 4111eb6f0de0SAdrian Chadd int tid = bf_first->bf_state.bfs_tid; 4112eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 4113eb6f0de0SAdrian Chadd struct ath_tx_status ts; 4114eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 4115eb6f0de0SAdrian Chadd ath_bufhead bf_q; 4116eb6f0de0SAdrian Chadd ath_bufhead bf_cq; 4117eb6f0de0SAdrian Chadd int seq_st, tx_ok; 4118eb6f0de0SAdrian Chadd int hasba, isaggr; 4119eb6f0de0SAdrian Chadd uint32_t ba[2]; 4120eb6f0de0SAdrian Chadd struct ath_buf *bf, *bf_next; 4121eb6f0de0SAdrian Chadd int ba_index; 4122eb6f0de0SAdrian Chadd int drops = 0; 4123eb6f0de0SAdrian Chadd int nframes = 0, nbad = 0, nf; 4124eb6f0de0SAdrian Chadd int pktlen; 4125eb6f0de0SAdrian Chadd /* XXX there's too much on the stack? */ 4126b815538dSAdrian Chadd struct ath_rc_series rc[ATH_RC_NUM]; 4127eb6f0de0SAdrian Chadd int txseq; 4128eb6f0de0SAdrian Chadd 4129eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n", 4130eb6f0de0SAdrian Chadd __func__, atid->hwq_depth); 4131eb6f0de0SAdrian Chadd 41320aa5c1bbSAdrian Chadd /* 41330aa5c1bbSAdrian Chadd * Take a copy; this may be needed -after- bf_first 41340aa5c1bbSAdrian Chadd * has been completed and freed. 41350aa5c1bbSAdrian Chadd */ 41360aa5c1bbSAdrian Chadd ts = bf_first->bf_status.ds_txstat; 41370aa5c1bbSAdrian Chadd 4138f1bc738eSAdrian Chadd TAILQ_INIT(&bf_q); 4139f1bc738eSAdrian Chadd TAILQ_INIT(&bf_cq); 4140f1bc738eSAdrian Chadd 4141eb6f0de0SAdrian Chadd /* The TID state is kept behind the TXQ lock */ 4142eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4143eb6f0de0SAdrian Chadd 4144eb6f0de0SAdrian Chadd atid->hwq_depth--; 4145eb6f0de0SAdrian Chadd if (atid->hwq_depth < 0) 4146eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4147eb6f0de0SAdrian Chadd __func__, atid->hwq_depth); 4148eb6f0de0SAdrian Chadd 4149eb6f0de0SAdrian Chadd /* 4150f1bc738eSAdrian Chadd * If the TID is filtered, handle completing the filter 4151f1bc738eSAdrian Chadd * transition before potentially kicking it to the cleanup 4152f1bc738eSAdrian Chadd * function. 41530aa5c1bbSAdrian Chadd * 41540aa5c1bbSAdrian Chadd * XXX this is duplicate work, ew. 4155f1bc738eSAdrian Chadd */ 4156f1bc738eSAdrian Chadd if (atid->isfiltered) 4157f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, atid); 4158f1bc738eSAdrian Chadd 4159f1bc738eSAdrian Chadd /* 4160eb6f0de0SAdrian Chadd * Punt cleanup to the relevant function, not our problem now 4161eb6f0de0SAdrian Chadd */ 4162eb6f0de0SAdrian Chadd if (atid->cleanup_inprogress) { 4163f1bc738eSAdrian Chadd if (atid->isfiltered) 4164f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4165f1bc738eSAdrian Chadd "%s: isfiltered=1, normal_comp?\n", 4166f1bc738eSAdrian Chadd __func__); 4167eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4168eb6f0de0SAdrian Chadd ath_tx_comp_cleanup_aggr(sc, bf_first); 4169eb6f0de0SAdrian Chadd return; 4170eb6f0de0SAdrian Chadd } 4171eb6f0de0SAdrian Chadd 4172eb6f0de0SAdrian Chadd /* 4173f1bc738eSAdrian Chadd * If the frame is filtered, transition to filtered frame 4174f1bc738eSAdrian Chadd * mode and add this to the filtered frame list. 4175f1bc738eSAdrian Chadd * 4176f1bc738eSAdrian Chadd * XXX TODO: figure out how this interoperates with 4177f1bc738eSAdrian Chadd * BAR, pause and cleanup states. 4178f1bc738eSAdrian Chadd */ 4179f1bc738eSAdrian Chadd if ((ts.ts_status & HAL_TXERR_FILT) || 4180f1bc738eSAdrian Chadd (ts.ts_status != 0 && atid->isfiltered)) { 4181f1bc738eSAdrian Chadd if (fail != 0) 4182f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4183f1bc738eSAdrian Chadd "%s: isfiltered=1, fail=%d\n", __func__, fail); 4184f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq); 4185f1bc738eSAdrian Chadd 4186f1bc738eSAdrian Chadd /* Remove from BAW */ 4187f1bc738eSAdrian Chadd TAILQ_FOREACH_SAFE(bf, &bf_cq, bf_list, bf_next) { 4188f1bc738eSAdrian Chadd if (bf->bf_state.bfs_addedbaw) 4189f1bc738eSAdrian Chadd drops++; 4190f1bc738eSAdrian Chadd if (bf->bf_state.bfs_dobaw) { 4191f1bc738eSAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 4192f1bc738eSAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 4193f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4194f1bc738eSAdrian Chadd "%s: wasn't added: seqno %d\n", 4195f1bc738eSAdrian Chadd __func__, 4196f1bc738eSAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)); 4197f1bc738eSAdrian Chadd } 4198f1bc738eSAdrian Chadd bf->bf_state.bfs_dobaw = 0; 4199f1bc738eSAdrian Chadd } 4200f1bc738eSAdrian Chadd /* 4201f1bc738eSAdrian Chadd * If any intermediate frames in the BAW were dropped when 4202f1bc738eSAdrian Chadd * handling filtering things, send a BAR. 4203f1bc738eSAdrian Chadd */ 4204f1bc738eSAdrian Chadd if (drops) 4205f1bc738eSAdrian Chadd ath_tx_tid_bar_suspend(sc, atid); 4206f1bc738eSAdrian Chadd 4207f1bc738eSAdrian Chadd /* 4208f1bc738eSAdrian Chadd * Finish up by sending a BAR if required and freeing 4209f1bc738eSAdrian Chadd * the frames outside of the TX lock. 4210f1bc738eSAdrian Chadd */ 4211f1bc738eSAdrian Chadd goto finish_send_bar; 4212f1bc738eSAdrian Chadd } 4213f1bc738eSAdrian Chadd 4214f1bc738eSAdrian Chadd /* 4215eb6f0de0SAdrian Chadd * XXX for now, use the first frame in the aggregate for 4216eb6f0de0SAdrian Chadd * XXX rate control completion; it's at least consistent. 4217eb6f0de0SAdrian Chadd */ 4218eb6f0de0SAdrian Chadd pktlen = bf_first->bf_state.bfs_pktlen; 4219eb6f0de0SAdrian Chadd 4220eb6f0de0SAdrian Chadd /* 4221e9a6408eSAdrian Chadd * Handle errors first! 4222e9a6408eSAdrian Chadd * 4223e9a6408eSAdrian Chadd * Here, handle _any_ error as a "exceeded retries" error. 4224e9a6408eSAdrian Chadd * Later on (when filtered frames are to be specially handled) 4225e9a6408eSAdrian Chadd * it'll have to be expanded. 4226eb6f0de0SAdrian Chadd */ 4227e9a6408eSAdrian Chadd #if 0 4228eb6f0de0SAdrian Chadd if (ts.ts_status & HAL_TXERR_XRETRY) { 4229e9a6408eSAdrian Chadd #endif 4230e9a6408eSAdrian Chadd if (ts.ts_status != 0) { 4231eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4232eb6f0de0SAdrian Chadd ath_tx_comp_aggr_error(sc, bf_first, atid); 4233eb6f0de0SAdrian Chadd return; 4234eb6f0de0SAdrian Chadd } 4235eb6f0de0SAdrian Chadd 4236eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid); 4237eb6f0de0SAdrian Chadd 4238eb6f0de0SAdrian Chadd /* 4239eb6f0de0SAdrian Chadd * extract starting sequence and block-ack bitmap 4240eb6f0de0SAdrian Chadd */ 4241eb6f0de0SAdrian Chadd /* XXX endian-ness of seq_st, ba? */ 4242eb6f0de0SAdrian Chadd seq_st = ts.ts_seqnum; 4243eb6f0de0SAdrian Chadd hasba = !! (ts.ts_flags & HAL_TX_BA); 4244eb6f0de0SAdrian Chadd tx_ok = (ts.ts_status == 0); 4245eb6f0de0SAdrian Chadd isaggr = bf_first->bf_state.bfs_aggr; 4246eb6f0de0SAdrian Chadd ba[0] = ts.ts_ba_low; 4247eb6f0de0SAdrian Chadd ba[1] = ts.ts_ba_high; 4248eb6f0de0SAdrian Chadd 4249eb6f0de0SAdrian Chadd /* 4250eb6f0de0SAdrian Chadd * Copy the TX completion status and the rate control 4251eb6f0de0SAdrian Chadd * series from the first descriptor, as it may be freed 4252eb6f0de0SAdrian Chadd * before the rate control code can get its grubby fingers 4253eb6f0de0SAdrian Chadd * into things. 4254eb6f0de0SAdrian Chadd */ 4255eb6f0de0SAdrian Chadd memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc)); 4256eb6f0de0SAdrian Chadd 4257eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4258d4365d16SAdrian Chadd "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, " 4259d4365d16SAdrian Chadd "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n", 4260eb6f0de0SAdrian Chadd __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags, 4261eb6f0de0SAdrian Chadd isaggr, seq_st, hasba, ba[0], ba[1]); 4262eb6f0de0SAdrian Chadd 4263eb6f0de0SAdrian Chadd /* Occasionally, the MAC sends a tx status for the wrong TID. */ 4264eb6f0de0SAdrian Chadd if (tid != ts.ts_tid) { 4265eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: tid %d != hw tid %d\n", 4266eb6f0de0SAdrian Chadd __func__, tid, ts.ts_tid); 4267eb6f0de0SAdrian Chadd tx_ok = 0; 4268eb6f0de0SAdrian Chadd } 4269eb6f0de0SAdrian Chadd 4270eb6f0de0SAdrian Chadd /* AR5416 BA bug; this requires an interface reset */ 4271eb6f0de0SAdrian Chadd if (isaggr && tx_ok && (! hasba)) { 4272eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 4273d4365d16SAdrian Chadd "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, " 4274d4365d16SAdrian Chadd "seq_st=%d\n", 4275eb6f0de0SAdrian Chadd __func__, hasba, tx_ok, isaggr, seq_st); 4276eb6f0de0SAdrian Chadd /* XXX TODO: schedule an interface reset */ 42770f078d63SJohn Baldwin #ifdef ATH_DEBUG 42786abbbae5SAdrian Chadd ath_printtxbuf(sc, bf_first, 42796abbbae5SAdrian Chadd sc->sc_ac2q[atid->ac]->axq_qnum, 0, 0); 42800f078d63SJohn Baldwin #endif 4281eb6f0de0SAdrian Chadd } 4282eb6f0de0SAdrian Chadd 4283eb6f0de0SAdrian Chadd /* 4284eb6f0de0SAdrian Chadd * Walk the list of frames, figure out which ones were correctly 4285eb6f0de0SAdrian Chadd * sent and which weren't. 4286eb6f0de0SAdrian Chadd */ 4287eb6f0de0SAdrian Chadd bf = bf_first; 4288eb6f0de0SAdrian Chadd nf = bf_first->bf_state.bfs_nframes; 4289eb6f0de0SAdrian Chadd 4290eb6f0de0SAdrian Chadd /* bf_first is going to be invalid once this list is walked */ 4291eb6f0de0SAdrian Chadd bf_first = NULL; 4292eb6f0de0SAdrian Chadd 4293eb6f0de0SAdrian Chadd /* 4294eb6f0de0SAdrian Chadd * Walk the list of completed frames and determine 4295eb6f0de0SAdrian Chadd * which need to be completed and which need to be 4296eb6f0de0SAdrian Chadd * retransmitted. 4297eb6f0de0SAdrian Chadd * 4298eb6f0de0SAdrian Chadd * For completed frames, the completion functions need 4299eb6f0de0SAdrian Chadd * to be called at the end of this function as the last 4300eb6f0de0SAdrian Chadd * node reference may free the node. 4301eb6f0de0SAdrian Chadd * 4302eb6f0de0SAdrian Chadd * Finally, since the TXQ lock can't be held during the 4303eb6f0de0SAdrian Chadd * completion callback (to avoid lock recursion), 4304eb6f0de0SAdrian Chadd * the completion calls have to be done outside of the 4305eb6f0de0SAdrian Chadd * lock. 4306eb6f0de0SAdrian Chadd */ 4307eb6f0de0SAdrian Chadd while (bf) { 4308eb6f0de0SAdrian Chadd nframes++; 4309d4365d16SAdrian Chadd ba_index = ATH_BA_INDEX(seq_st, 4310d4365d16SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)); 4311eb6f0de0SAdrian Chadd bf_next = bf->bf_next; 4312eb6f0de0SAdrian Chadd bf->bf_next = NULL; /* Remove it from the aggr list */ 4313eb6f0de0SAdrian Chadd 4314eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4315eb6f0de0SAdrian Chadd "%s: checking bf=%p seqno=%d; ack=%d\n", 4316eb6f0de0SAdrian Chadd __func__, bf, SEQNO(bf->bf_state.bfs_seqno), 4317eb6f0de0SAdrian Chadd ATH_BA_ISSET(ba, ba_index)); 4318eb6f0de0SAdrian Chadd 4319eb6f0de0SAdrian Chadd if (tx_ok && ATH_BA_ISSET(ba, ba_index)) { 43202d3d4776SAdrian Chadd sc->sc_stats.ast_tx_aggr_ok++; 4321eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 4322eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 4323eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 4324eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 4325eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 4326eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 4327eb6f0de0SAdrian Chadd bf->bf_next = NULL; 4328eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4329eb6f0de0SAdrian Chadd } else { 43302d3d4776SAdrian Chadd sc->sc_stats.ast_tx_aggr_fail++; 4331eb6f0de0SAdrian Chadd if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4332eb6f0de0SAdrian Chadd drops++; 4333eb6f0de0SAdrian Chadd bf->bf_next = NULL; 4334eb6f0de0SAdrian Chadd TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4335eb6f0de0SAdrian Chadd } 4336eb6f0de0SAdrian Chadd nbad++; 4337eb6f0de0SAdrian Chadd } 4338eb6f0de0SAdrian Chadd bf = bf_next; 4339eb6f0de0SAdrian Chadd } 4340eb6f0de0SAdrian Chadd 4341eb6f0de0SAdrian Chadd /* 4342eb6f0de0SAdrian Chadd * Now that the BAW updates have been done, unlock 4343eb6f0de0SAdrian Chadd * 4344eb6f0de0SAdrian Chadd * txseq is grabbed before the lock is released so we 4345eb6f0de0SAdrian Chadd * have a consistent view of what -was- in the BAW. 4346eb6f0de0SAdrian Chadd * Anything after this point will not yet have been 4347eb6f0de0SAdrian Chadd * TXed. 4348eb6f0de0SAdrian Chadd */ 4349eb6f0de0SAdrian Chadd txseq = tap->txa_start; 4350eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4351eb6f0de0SAdrian Chadd 4352eb6f0de0SAdrian Chadd if (nframes != nf) 4353eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 4354eb6f0de0SAdrian Chadd "%s: num frames seen=%d; bf nframes=%d\n", 4355eb6f0de0SAdrian Chadd __func__, nframes, nf); 4356eb6f0de0SAdrian Chadd 4357eb6f0de0SAdrian Chadd /* 4358eb6f0de0SAdrian Chadd * Now we know how many frames were bad, call the rate 4359eb6f0de0SAdrian Chadd * control code. 4360eb6f0de0SAdrian Chadd */ 4361eb6f0de0SAdrian Chadd if (fail == 0) 4362d4365d16SAdrian Chadd ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes, 4363d4365d16SAdrian Chadd nbad); 4364eb6f0de0SAdrian Chadd 4365eb6f0de0SAdrian Chadd /* 4366eb6f0de0SAdrian Chadd * send bar if we dropped any frames 4367eb6f0de0SAdrian Chadd */ 4368eb6f0de0SAdrian Chadd if (drops) { 436988b3d483SAdrian Chadd /* Suspend the TX queue and get ready to send the BAR */ 437088b3d483SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 437188b3d483SAdrian Chadd ath_tx_tid_bar_suspend(sc, atid); 437288b3d483SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4373eb6f0de0SAdrian Chadd } 4374eb6f0de0SAdrian Chadd 437539da9d42SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 437639da9d42SAdrian Chadd "%s: txa_start now %d\n", __func__, tap->txa_start); 437739da9d42SAdrian Chadd 4378eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 437939da9d42SAdrian Chadd 438039da9d42SAdrian Chadd /* Prepend all frames to the beginning of the queue */ 4381eb6f0de0SAdrian Chadd while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4382eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_q, bf, bf_list); 4383eb6f0de0SAdrian Chadd ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 4384eb6f0de0SAdrian Chadd } 4385eb6f0de0SAdrian Chadd 438639da9d42SAdrian Chadd /* 438739da9d42SAdrian Chadd * Reschedule to grab some further frames. 438839da9d42SAdrian Chadd */ 438939da9d42SAdrian Chadd ath_tx_tid_sched(sc, atid); 4390eb6f0de0SAdrian Chadd 439188b3d483SAdrian Chadd /* 4392f1bc738eSAdrian Chadd * If the queue is filtered, re-schedule as required. 4393f1bc738eSAdrian Chadd * 4394f1bc738eSAdrian Chadd * This is required as there may be a subsequent TX descriptor 4395f1bc738eSAdrian Chadd * for this end-node that has CLRDMASK set, so it's quite possible 4396f1bc738eSAdrian Chadd * that a filtered frame will be followed by a non-filtered 4397f1bc738eSAdrian Chadd * (complete or otherwise) frame. 4398f1bc738eSAdrian Chadd * 4399f1bc738eSAdrian Chadd * XXX should we do this before we complete the frame? 4400f1bc738eSAdrian Chadd */ 4401f1bc738eSAdrian Chadd if (atid->isfiltered) 4402f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, atid); 4403f1bc738eSAdrian Chadd 4404f1bc738eSAdrian Chadd finish_send_bar: 4405f1bc738eSAdrian Chadd 4406f1bc738eSAdrian Chadd /* 440788b3d483SAdrian Chadd * Send BAR if required 440888b3d483SAdrian Chadd */ 440988b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 441088b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 441139da9d42SAdrian Chadd 441288b3d483SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 441388b3d483SAdrian Chadd 4414eb6f0de0SAdrian Chadd /* Do deferred completion */ 4415eb6f0de0SAdrian Chadd while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4416eb6f0de0SAdrian Chadd TAILQ_REMOVE(&bf_cq, bf, bf_list); 4417eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, 0); 4418eb6f0de0SAdrian Chadd } 4419eb6f0de0SAdrian Chadd } 4420eb6f0de0SAdrian Chadd 4421eb6f0de0SAdrian Chadd /* 4422eb6f0de0SAdrian Chadd * Handle completion of unaggregated frames in an ADDBA 4423eb6f0de0SAdrian Chadd * session. 4424eb6f0de0SAdrian Chadd * 4425eb6f0de0SAdrian Chadd * Fail is set to 1 if the entry is being freed via a call to 4426eb6f0de0SAdrian Chadd * ath_tx_draintxq(). 4427eb6f0de0SAdrian Chadd */ 4428eb6f0de0SAdrian Chadd static void 4429eb6f0de0SAdrian Chadd ath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail) 4430eb6f0de0SAdrian Chadd { 4431eb6f0de0SAdrian Chadd struct ieee80211_node *ni = bf->bf_node; 4432eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 4433eb6f0de0SAdrian Chadd int tid = bf->bf_state.bfs_tid; 4434eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 44350aa5c1bbSAdrian Chadd struct ath_tx_status ts; 4436f1bc738eSAdrian Chadd int drops = 0; 4437eb6f0de0SAdrian Chadd 4438eb6f0de0SAdrian Chadd /* 44390aa5c1bbSAdrian Chadd * Take a copy of this; filtering/cloning the frame may free the 44400aa5c1bbSAdrian Chadd * bf pointer. 44410aa5c1bbSAdrian Chadd */ 44420aa5c1bbSAdrian Chadd ts = bf->bf_status.ds_txstat; 44430aa5c1bbSAdrian Chadd 44440aa5c1bbSAdrian Chadd /* 4445eb6f0de0SAdrian Chadd * Update rate control status here, before we possibly 4446eb6f0de0SAdrian Chadd * punt to retry or cleanup. 4447eb6f0de0SAdrian Chadd * 4448eb6f0de0SAdrian Chadd * Do it outside of the TXQ lock. 4449eb6f0de0SAdrian Chadd */ 4450875a9451SAdrian Chadd if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 4451eb6f0de0SAdrian Chadd ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 4452eb6f0de0SAdrian Chadd &bf->bf_status.ds_txstat, 4453eb6f0de0SAdrian Chadd bf->bf_state.bfs_pktlen, 44540aa5c1bbSAdrian Chadd 1, (ts.ts_status == 0) ? 0 : 1); 4455eb6f0de0SAdrian Chadd 4456eb6f0de0SAdrian Chadd /* 4457eb6f0de0SAdrian Chadd * This is called early so atid->hwq_depth can be tracked. 4458eb6f0de0SAdrian Chadd * This unfortunately means that it's released and regrabbed 4459eb6f0de0SAdrian Chadd * during retry and cleanup. That's rather inefficient. 4460eb6f0de0SAdrian Chadd */ 4461eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4462eb6f0de0SAdrian Chadd 4463eb6f0de0SAdrian Chadd if (tid == IEEE80211_NONQOS_TID) 4464eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: TID=16!\n", __func__); 4465eb6f0de0SAdrian Chadd 4466d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, 4467d4365d16SAdrian Chadd "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n", 4468d4365d16SAdrian Chadd __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth, 4469d4365d16SAdrian Chadd SEQNO(bf->bf_state.bfs_seqno)); 4470eb6f0de0SAdrian Chadd 4471eb6f0de0SAdrian Chadd atid->hwq_depth--; 4472eb6f0de0SAdrian Chadd if (atid->hwq_depth < 0) 4473eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4474eb6f0de0SAdrian Chadd __func__, atid->hwq_depth); 4475eb6f0de0SAdrian Chadd 4476eb6f0de0SAdrian Chadd /* 4477f1bc738eSAdrian Chadd * If the TID is filtered, handle completing the filter 4478f1bc738eSAdrian Chadd * transition before potentially kicking it to the cleanup 4479f1bc738eSAdrian Chadd * function. 4480f1bc738eSAdrian Chadd */ 4481f1bc738eSAdrian Chadd if (atid->isfiltered) 4482f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, atid); 4483f1bc738eSAdrian Chadd 4484f1bc738eSAdrian Chadd /* 4485eb6f0de0SAdrian Chadd * If a cleanup is in progress, punt to comp_cleanup; 4486eb6f0de0SAdrian Chadd * rather than handling it here. It's thus their 4487eb6f0de0SAdrian Chadd * responsibility to clean up, call the completion 4488eb6f0de0SAdrian Chadd * function in net80211, etc. 4489eb6f0de0SAdrian Chadd */ 4490eb6f0de0SAdrian Chadd if (atid->cleanup_inprogress) { 4491f1bc738eSAdrian Chadd if (atid->isfiltered) 4492f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4493f1bc738eSAdrian Chadd "%s: isfiltered=1, normal_comp?\n", 4494f1bc738eSAdrian Chadd __func__); 4495eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4496d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n", 4497d4365d16SAdrian Chadd __func__); 4498eb6f0de0SAdrian Chadd ath_tx_comp_cleanup_unaggr(sc, bf); 4499eb6f0de0SAdrian Chadd return; 4500eb6f0de0SAdrian Chadd } 4501eb6f0de0SAdrian Chadd 4502eb6f0de0SAdrian Chadd /* 4503f1bc738eSAdrian Chadd * XXX TODO: how does cleanup, BAR and filtered frame handling 4504f1bc738eSAdrian Chadd * overlap? 4505f1bc738eSAdrian Chadd * 4506f1bc738eSAdrian Chadd * If the frame is filtered OR if it's any failure but 4507f1bc738eSAdrian Chadd * the TID is filtered, the frame must be added to the 4508f1bc738eSAdrian Chadd * filtered frame list. 4509f1bc738eSAdrian Chadd * 4510f1bc738eSAdrian Chadd * However - a busy buffer can't be added to the filtered 4511f1bc738eSAdrian Chadd * list as it will end up being recycled without having 4512f1bc738eSAdrian Chadd * been made available for the hardware. 4513f1bc738eSAdrian Chadd */ 45140aa5c1bbSAdrian Chadd if ((ts.ts_status & HAL_TXERR_FILT) || 45150aa5c1bbSAdrian Chadd (ts.ts_status != 0 && atid->isfiltered)) { 4516f1bc738eSAdrian Chadd int freeframe; 4517f1bc738eSAdrian Chadd 4518f1bc738eSAdrian Chadd if (fail != 0) 4519f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4520f1bc738eSAdrian Chadd "%s: isfiltered=1, fail=%d\n", 4521f1bc738eSAdrian Chadd __func__, 4522f1bc738eSAdrian Chadd fail); 4523f1bc738eSAdrian Chadd freeframe = ath_tx_tid_filt_comp_single(sc, atid, bf); 4524f1bc738eSAdrian Chadd if (freeframe) { 4525f1bc738eSAdrian Chadd /* Remove from BAW */ 4526f1bc738eSAdrian Chadd if (bf->bf_state.bfs_addedbaw) 4527f1bc738eSAdrian Chadd drops++; 4528f1bc738eSAdrian Chadd if (bf->bf_state.bfs_dobaw) { 4529f1bc738eSAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 4530f1bc738eSAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 4531f1bc738eSAdrian Chadd device_printf(sc->sc_dev, 4532f1bc738eSAdrian Chadd "%s: wasn't added: seqno %d\n", 4533f1bc738eSAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 4534f1bc738eSAdrian Chadd } 4535f1bc738eSAdrian Chadd bf->bf_state.bfs_dobaw = 0; 4536f1bc738eSAdrian Chadd } 4537f1bc738eSAdrian Chadd 4538f1bc738eSAdrian Chadd /* 4539f1bc738eSAdrian Chadd * If the frame couldn't be filtered, treat it as a drop and 4540f1bc738eSAdrian Chadd * prepare to send a BAR. 4541f1bc738eSAdrian Chadd */ 4542f1bc738eSAdrian Chadd if (freeframe && drops) 4543f1bc738eSAdrian Chadd ath_tx_tid_bar_suspend(sc, atid); 4544f1bc738eSAdrian Chadd 4545f1bc738eSAdrian Chadd /* 4546f1bc738eSAdrian Chadd * Send BAR if required 4547f1bc738eSAdrian Chadd */ 4548f1bc738eSAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 4549f1bc738eSAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 4550f1bc738eSAdrian Chadd 4551f1bc738eSAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4552f1bc738eSAdrian Chadd /* 4553f1bc738eSAdrian Chadd * If freeframe is set, then the frame couldn't be 4554f1bc738eSAdrian Chadd * cloned and bf is still valid. Just complete/free it. 4555f1bc738eSAdrian Chadd */ 4556f1bc738eSAdrian Chadd if (freeframe) 4557f1bc738eSAdrian Chadd ath_tx_default_comp(sc, bf, fail); 4558f1bc738eSAdrian Chadd 4559f1bc738eSAdrian Chadd 4560f1bc738eSAdrian Chadd return; 4561f1bc738eSAdrian Chadd } 4562f1bc738eSAdrian Chadd /* 4563eb6f0de0SAdrian Chadd * Don't bother with the retry check if all frames 4564eb6f0de0SAdrian Chadd * are being failed (eg during queue deletion.) 4565eb6f0de0SAdrian Chadd */ 4566e9a6408eSAdrian Chadd #if 0 4567eb6f0de0SAdrian Chadd if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) { 4568e9a6408eSAdrian Chadd #endif 45690aa5c1bbSAdrian Chadd if (fail == 0 && ts.ts_status != 0) { 4570eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4571d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n", 4572d4365d16SAdrian Chadd __func__); 4573eb6f0de0SAdrian Chadd ath_tx_aggr_retry_unaggr(sc, bf); 4574eb6f0de0SAdrian Chadd return; 4575eb6f0de0SAdrian Chadd } 4576eb6f0de0SAdrian Chadd 4577eb6f0de0SAdrian Chadd /* Success? Complete */ 4578eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n", 4579eb6f0de0SAdrian Chadd __func__, tid, SEQNO(bf->bf_state.bfs_seqno)); 4580eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_dobaw) { 4581eb6f0de0SAdrian Chadd ath_tx_update_baw(sc, an, atid, bf); 4582eb6f0de0SAdrian Chadd bf->bf_state.bfs_dobaw = 0; 4583eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_addedbaw) 4584eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, 4585eb6f0de0SAdrian Chadd "%s: wasn't added: seqno %d\n", 4586eb6f0de0SAdrian Chadd __func__, SEQNO(bf->bf_state.bfs_seqno)); 4587eb6f0de0SAdrian Chadd } 4588eb6f0de0SAdrian Chadd 458988b3d483SAdrian Chadd /* 4590f1bc738eSAdrian Chadd * If the queue is filtered, re-schedule as required. 4591f1bc738eSAdrian Chadd * 4592f1bc738eSAdrian Chadd * This is required as there may be a subsequent TX descriptor 4593f1bc738eSAdrian Chadd * for this end-node that has CLRDMASK set, so it's quite possible 4594f1bc738eSAdrian Chadd * that a filtered frame will be followed by a non-filtered 4595f1bc738eSAdrian Chadd * (complete or otherwise) frame. 4596f1bc738eSAdrian Chadd * 4597f1bc738eSAdrian Chadd * XXX should we do this before we complete the frame? 4598f1bc738eSAdrian Chadd */ 4599f1bc738eSAdrian Chadd if (atid->isfiltered) 4600f1bc738eSAdrian Chadd ath_tx_tid_filt_comp_complete(sc, atid); 4601f1bc738eSAdrian Chadd 4602f1bc738eSAdrian Chadd /* 460388b3d483SAdrian Chadd * Send BAR if required 460488b3d483SAdrian Chadd */ 460588b3d483SAdrian Chadd if (ath_tx_tid_bar_tx_ready(sc, atid)) 460688b3d483SAdrian Chadd ath_tx_tid_bar_tx(sc, atid); 460788b3d483SAdrian Chadd 4608eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4609eb6f0de0SAdrian Chadd 4610eb6f0de0SAdrian Chadd ath_tx_default_comp(sc, bf, fail); 4611eb6f0de0SAdrian Chadd /* bf is freed at this point */ 4612eb6f0de0SAdrian Chadd } 4613eb6f0de0SAdrian Chadd 4614eb6f0de0SAdrian Chadd void 4615eb6f0de0SAdrian Chadd ath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 4616eb6f0de0SAdrian Chadd { 4617eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_aggr) 4618eb6f0de0SAdrian Chadd ath_tx_aggr_comp_aggr(sc, bf, fail); 4619eb6f0de0SAdrian Chadd else 4620eb6f0de0SAdrian Chadd ath_tx_aggr_comp_unaggr(sc, bf, fail); 4621eb6f0de0SAdrian Chadd } 4622eb6f0de0SAdrian Chadd 4623eb6f0de0SAdrian Chadd /* 4624eb6f0de0SAdrian Chadd * Schedule some packets from the given node/TID to the hardware. 4625eb6f0de0SAdrian Chadd * 4626eb6f0de0SAdrian Chadd * This is the aggregate version. 4627eb6f0de0SAdrian Chadd */ 4628eb6f0de0SAdrian Chadd void 4629eb6f0de0SAdrian Chadd ath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an, 4630eb6f0de0SAdrian Chadd struct ath_tid *tid) 4631eb6f0de0SAdrian Chadd { 4632eb6f0de0SAdrian Chadd struct ath_buf *bf; 4633eb6f0de0SAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4634eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 4635eb6f0de0SAdrian Chadd ATH_AGGR_STATUS status; 4636eb6f0de0SAdrian Chadd ath_bufhead bf_q; 4637eb6f0de0SAdrian Chadd 4638eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid); 4639eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 4640eb6f0de0SAdrian Chadd 4641eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid->tid); 4642eb6f0de0SAdrian Chadd 4643eb6f0de0SAdrian Chadd if (tid->tid == IEEE80211_NONQOS_TID) 4644eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: called for TID=NONQOS_TID?\n", 4645eb6f0de0SAdrian Chadd __func__); 4646eb6f0de0SAdrian Chadd 4647eb6f0de0SAdrian Chadd for (;;) { 4648eb6f0de0SAdrian Chadd status = ATH_AGGR_DONE; 4649eb6f0de0SAdrian Chadd 4650eb6f0de0SAdrian Chadd /* 4651eb6f0de0SAdrian Chadd * If the upper layer has paused the TID, don't 4652eb6f0de0SAdrian Chadd * queue any further packets. 4653eb6f0de0SAdrian Chadd * 4654eb6f0de0SAdrian Chadd * This can also occur from the completion task because 4655eb6f0de0SAdrian Chadd * of packet loss; but as its serialised with this code, 4656eb6f0de0SAdrian Chadd * it won't "appear" half way through queuing packets. 4657eb6f0de0SAdrian Chadd */ 4658eb6f0de0SAdrian Chadd if (tid->paused) 4659eb6f0de0SAdrian Chadd break; 4660eb6f0de0SAdrian Chadd 4661eb6f0de0SAdrian Chadd bf = TAILQ_FIRST(&tid->axq_q); 4662eb6f0de0SAdrian Chadd if (bf == NULL) { 4663eb6f0de0SAdrian Chadd break; 4664eb6f0de0SAdrian Chadd } 4665eb6f0de0SAdrian Chadd 4666eb6f0de0SAdrian Chadd /* 4667eb6f0de0SAdrian Chadd * If the packet doesn't fall within the BAW (eg a NULL 4668eb6f0de0SAdrian Chadd * data frame), schedule it directly; continue. 4669eb6f0de0SAdrian Chadd */ 4670eb6f0de0SAdrian Chadd if (! bf->bf_state.bfs_dobaw) { 4671d4365d16SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4672d4365d16SAdrian Chadd "%s: non-baw packet\n", 4673eb6f0de0SAdrian Chadd __func__); 4674eb6f0de0SAdrian Chadd ATH_TXQ_REMOVE(tid, bf, bf_list); 46752a9f83afSAdrian Chadd 46762a9f83afSAdrian Chadd if (bf->bf_state.bfs_nframes > 1) 46772a9f83afSAdrian Chadd device_printf(sc->sc_dev, 46782a9f83afSAdrian Chadd "%s: aggr=%d, nframes=%d\n", 46792a9f83afSAdrian Chadd __func__, 46802a9f83afSAdrian Chadd bf->bf_state.bfs_aggr, 46812a9f83afSAdrian Chadd bf->bf_state.bfs_nframes); 46822a9f83afSAdrian Chadd 46832a9f83afSAdrian Chadd /* 46842a9f83afSAdrian Chadd * This shouldn't happen - such frames shouldn't 46852a9f83afSAdrian Chadd * ever have been queued as an aggregate in the 46862a9f83afSAdrian Chadd * first place. However, make sure the fields 46872a9f83afSAdrian Chadd * are correctly setup just to be totally sure. 46882a9f83afSAdrian Chadd */ 4689eb6f0de0SAdrian Chadd bf->bf_state.bfs_aggr = 0; 46902a9f83afSAdrian Chadd bf->bf_state.bfs_nframes = 1; 46912a9f83afSAdrian Chadd 46924e81f27cSAdrian Chadd /* Update CLRDMASK just before this frame is queued */ 46934e81f27cSAdrian Chadd ath_tx_update_clrdmask(sc, tid, bf); 46944e81f27cSAdrian Chadd 4695eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(sc, bf); 4696e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 4697e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 4698eb6f0de0SAdrian Chadd ath_tx_set_rtscts(sc, bf); 4699e2e4a2c2SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 4700eb6f0de0SAdrian Chadd ath_tx_setds(sc, bf); 4701eb6f0de0SAdrian Chadd ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4702eb6f0de0SAdrian Chadd 4703eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_nonbaw_pkt++; 4704eb6f0de0SAdrian Chadd 4705eb6f0de0SAdrian Chadd /* Queue the packet; continue */ 4706eb6f0de0SAdrian Chadd goto queuepkt; 4707eb6f0de0SAdrian Chadd } 4708eb6f0de0SAdrian Chadd 4709eb6f0de0SAdrian Chadd TAILQ_INIT(&bf_q); 4710eb6f0de0SAdrian Chadd 4711eb6f0de0SAdrian Chadd /* 4712eb6f0de0SAdrian Chadd * Do a rate control lookup on the first frame in the 4713eb6f0de0SAdrian Chadd * list. The rate control code needs that to occur 4714eb6f0de0SAdrian Chadd * before it can determine whether to TX. 4715eb6f0de0SAdrian Chadd * It's inaccurate because the rate control code doesn't 4716eb6f0de0SAdrian Chadd * really "do" aggregate lookups, so it only considers 4717eb6f0de0SAdrian Chadd * the size of the first frame. 4718eb6f0de0SAdrian Chadd */ 4719eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(sc, bf); 4720eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[3].rix = 0; 4721eb6f0de0SAdrian Chadd bf->bf_state.bfs_rc[3].tries = 0; 4722e2e4a2c2SAdrian Chadd 4723e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 4724e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 4725e2e4a2c2SAdrian Chadd 4726e2e4a2c2SAdrian Chadd ath_tx_set_rtscts(sc, bf); 4727eb6f0de0SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 4728eb6f0de0SAdrian Chadd 4729eb6f0de0SAdrian Chadd status = ath_tx_form_aggr(sc, an, tid, &bf_q); 4730eb6f0de0SAdrian Chadd 4731eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4732eb6f0de0SAdrian Chadd "%s: ath_tx_form_aggr() status=%d\n", __func__, status); 4733eb6f0de0SAdrian Chadd 4734eb6f0de0SAdrian Chadd /* 4735eb6f0de0SAdrian Chadd * No frames to be picked up - out of BAW 4736eb6f0de0SAdrian Chadd */ 4737eb6f0de0SAdrian Chadd if (TAILQ_EMPTY(&bf_q)) 4738eb6f0de0SAdrian Chadd break; 4739eb6f0de0SAdrian Chadd 4740eb6f0de0SAdrian Chadd /* 4741eb6f0de0SAdrian Chadd * This assumes that the descriptor list in the ath_bufhead 4742eb6f0de0SAdrian Chadd * are already linked together via bf_next pointers. 4743eb6f0de0SAdrian Chadd */ 4744eb6f0de0SAdrian Chadd bf = TAILQ_FIRST(&bf_q); 4745eb6f0de0SAdrian Chadd 4746e2e4a2c2SAdrian Chadd if (status == ATH_AGGR_8K_LIMITED) 4747e2e4a2c2SAdrian Chadd sc->sc_aggr_stats.aggr_rts_aggr_limited++; 4748e2e4a2c2SAdrian Chadd 4749eb6f0de0SAdrian Chadd /* 4750eb6f0de0SAdrian Chadd * If it's the only frame send as non-aggregate 4751eb6f0de0SAdrian Chadd * assume that ath_tx_form_aggr() has checked 4752eb6f0de0SAdrian Chadd * whether it's in the BAW and added it appropriately. 4753eb6f0de0SAdrian Chadd */ 4754eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_nframes == 1) { 4755eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4756eb6f0de0SAdrian Chadd "%s: single-frame aggregate\n", __func__); 47574e81f27cSAdrian Chadd 47584e81f27cSAdrian Chadd /* Update CLRDMASK just before this frame is queued */ 47594e81f27cSAdrian Chadd ath_tx_update_clrdmask(sc, tid, bf); 47604e81f27cSAdrian Chadd 4761eb6f0de0SAdrian Chadd bf->bf_state.bfs_aggr = 0; 476221840808SAdrian Chadd bf->bf_state.bfs_ndelim = 0; 4763eb6f0de0SAdrian Chadd ath_tx_setds(sc, bf); 4764eb6f0de0SAdrian Chadd ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4765eb6f0de0SAdrian Chadd if (status == ATH_AGGR_BAW_CLOSED) 4766eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_baw_closed_single_pkt++; 4767eb6f0de0SAdrian Chadd else 4768eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_single_pkt++; 4769eb6f0de0SAdrian Chadd } else { 4770eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4771d4365d16SAdrian Chadd "%s: multi-frame aggregate: %d frames, " 4772d4365d16SAdrian Chadd "length %d\n", 4773eb6f0de0SAdrian Chadd __func__, bf->bf_state.bfs_nframes, 4774eb6f0de0SAdrian Chadd bf->bf_state.bfs_al); 4775eb6f0de0SAdrian Chadd bf->bf_state.bfs_aggr = 1; 4776eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++; 4777eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_aggr_pkt++; 4778eb6f0de0SAdrian Chadd 47794e81f27cSAdrian Chadd /* Update CLRDMASK just before this frame is queued */ 47804e81f27cSAdrian Chadd ath_tx_update_clrdmask(sc, tid, bf); 47814e81f27cSAdrian Chadd 4782eb6f0de0SAdrian Chadd /* 4783e2e4a2c2SAdrian Chadd * Calculate the duration/protection as required. 4784e2e4a2c2SAdrian Chadd */ 4785e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 4786e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 4787e2e4a2c2SAdrian Chadd 4788e2e4a2c2SAdrian Chadd /* 4789eb6f0de0SAdrian Chadd * Update the rate and rtscts information based on the 4790eb6f0de0SAdrian Chadd * rate decision made by the rate control code; 4791eb6f0de0SAdrian Chadd * the first frame in the aggregate needs it. 4792eb6f0de0SAdrian Chadd */ 4793eb6f0de0SAdrian Chadd ath_tx_set_rtscts(sc, bf); 4794eb6f0de0SAdrian Chadd 4795eb6f0de0SAdrian Chadd /* 4796eb6f0de0SAdrian Chadd * Setup the relevant descriptor fields 4797eb6f0de0SAdrian Chadd * for aggregation. The first descriptor 4798eb6f0de0SAdrian Chadd * already points to the rest in the chain. 4799eb6f0de0SAdrian Chadd */ 4800eb6f0de0SAdrian Chadd ath_tx_setds_11n(sc, bf); 4801eb6f0de0SAdrian Chadd 4802eb6f0de0SAdrian Chadd } 4803eb6f0de0SAdrian Chadd queuepkt: 4804eb6f0de0SAdrian Chadd //txq = bf->bf_state.bfs_txq; 4805eb6f0de0SAdrian Chadd 4806eb6f0de0SAdrian Chadd /* Set completion handler, multi-frame aggregate or not */ 4807eb6f0de0SAdrian Chadd bf->bf_comp = ath_tx_aggr_comp; 4808eb6f0de0SAdrian Chadd 4809eb6f0de0SAdrian Chadd if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID) 4810eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: TID=16?\n", __func__); 4811eb6f0de0SAdrian Chadd 4812eb6f0de0SAdrian Chadd /* Punt to txq */ 4813eb6f0de0SAdrian Chadd ath_tx_handoff(sc, txq, bf); 4814eb6f0de0SAdrian Chadd 4815eb6f0de0SAdrian Chadd /* Track outstanding buffer count to hardware */ 4816eb6f0de0SAdrian Chadd /* aggregates are "one" buffer */ 4817eb6f0de0SAdrian Chadd tid->hwq_depth++; 4818eb6f0de0SAdrian Chadd 4819eb6f0de0SAdrian Chadd /* 4820eb6f0de0SAdrian Chadd * Break out if ath_tx_form_aggr() indicated 4821eb6f0de0SAdrian Chadd * there can't be any further progress (eg BAW is full.) 4822eb6f0de0SAdrian Chadd * Checking for an empty txq is done above. 4823eb6f0de0SAdrian Chadd * 4824eb6f0de0SAdrian Chadd * XXX locking on txq here? 4825eb6f0de0SAdrian Chadd */ 4826eb6f0de0SAdrian Chadd if (txq->axq_aggr_depth >= sc->sc_hwq_limit || 4827eb6f0de0SAdrian Chadd status == ATH_AGGR_BAW_CLOSED) 4828eb6f0de0SAdrian Chadd break; 4829eb6f0de0SAdrian Chadd } 4830eb6f0de0SAdrian Chadd } 4831eb6f0de0SAdrian Chadd 4832eb6f0de0SAdrian Chadd /* 4833eb6f0de0SAdrian Chadd * Schedule some packets from the given node/TID to the hardware. 4834eb6f0de0SAdrian Chadd */ 4835eb6f0de0SAdrian Chadd void 4836eb6f0de0SAdrian Chadd ath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an, 4837eb6f0de0SAdrian Chadd struct ath_tid *tid) 4838eb6f0de0SAdrian Chadd { 4839eb6f0de0SAdrian Chadd struct ath_buf *bf; 4840eb6f0de0SAdrian Chadd struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4841eb6f0de0SAdrian Chadd 4842eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n", 4843eb6f0de0SAdrian Chadd __func__, an, tid->tid); 4844eb6f0de0SAdrian Chadd 48454e81f27cSAdrian Chadd ATH_TID_LOCK_ASSERT(sc, tid); 4846eb6f0de0SAdrian Chadd 4847eb6f0de0SAdrian Chadd /* Check - is AMPDU pending or running? then print out something */ 4848eb6f0de0SAdrian Chadd if (ath_tx_ampdu_pending(sc, an, tid->tid)) 4849eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: tid=%d, ampdu pending?\n", 4850eb6f0de0SAdrian Chadd __func__, tid->tid); 4851eb6f0de0SAdrian Chadd if (ath_tx_ampdu_running(sc, an, tid->tid)) 4852eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: tid=%d, ampdu running?\n", 4853eb6f0de0SAdrian Chadd __func__, tid->tid); 4854eb6f0de0SAdrian Chadd 4855eb6f0de0SAdrian Chadd for (;;) { 4856eb6f0de0SAdrian Chadd 4857eb6f0de0SAdrian Chadd /* 4858eb6f0de0SAdrian Chadd * If the upper layers have paused the TID, don't 4859eb6f0de0SAdrian Chadd * queue any further packets. 4860eb6f0de0SAdrian Chadd */ 4861eb6f0de0SAdrian Chadd if (tid->paused) 4862eb6f0de0SAdrian Chadd break; 4863eb6f0de0SAdrian Chadd 4864eb6f0de0SAdrian Chadd bf = TAILQ_FIRST(&tid->axq_q); 4865eb6f0de0SAdrian Chadd if (bf == NULL) { 4866eb6f0de0SAdrian Chadd break; 4867eb6f0de0SAdrian Chadd } 4868eb6f0de0SAdrian Chadd 4869eb6f0de0SAdrian Chadd ATH_TXQ_REMOVE(tid, bf, bf_list); 4870eb6f0de0SAdrian Chadd 4871eb6f0de0SAdrian Chadd KASSERT(txq == bf->bf_state.bfs_txq, ("txqs not equal!\n")); 4872eb6f0de0SAdrian Chadd 4873eb6f0de0SAdrian Chadd /* Sanity check! */ 4874eb6f0de0SAdrian Chadd if (tid->tid != bf->bf_state.bfs_tid) { 4875eb6f0de0SAdrian Chadd device_printf(sc->sc_dev, "%s: bfs_tid %d !=" 4876eb6f0de0SAdrian Chadd " tid %d\n", 4877eb6f0de0SAdrian Chadd __func__, bf->bf_state.bfs_tid, tid->tid); 4878eb6f0de0SAdrian Chadd } 4879eb6f0de0SAdrian Chadd /* Normal completion handler */ 4880eb6f0de0SAdrian Chadd bf->bf_comp = ath_tx_normal_comp; 4881eb6f0de0SAdrian Chadd 48820c54de88SAdrian Chadd /* 48830c54de88SAdrian Chadd * Override this for now, until the non-aggregate 48840c54de88SAdrian Chadd * completion handler correctly handles software retransmits. 48850c54de88SAdrian Chadd */ 48860c54de88SAdrian Chadd bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 48870c54de88SAdrian Chadd 48884e81f27cSAdrian Chadd /* Update CLRDMASK just before this frame is queued */ 48894e81f27cSAdrian Chadd ath_tx_update_clrdmask(sc, tid, bf); 48904e81f27cSAdrian Chadd 4891eb6f0de0SAdrian Chadd /* Program descriptors + rate control */ 4892eb6f0de0SAdrian Chadd ath_tx_do_ratelookup(sc, bf); 4893e2e4a2c2SAdrian Chadd ath_tx_calc_duration(sc, bf); 4894e2e4a2c2SAdrian Chadd ath_tx_calc_protection(sc, bf); 4895eb6f0de0SAdrian Chadd ath_tx_set_rtscts(sc, bf); 4896e2e4a2c2SAdrian Chadd ath_tx_rate_fill_rcflags(sc, bf); 4897eb6f0de0SAdrian Chadd ath_tx_setds(sc, bf); 4898eb6f0de0SAdrian Chadd 4899eb6f0de0SAdrian Chadd /* Track outstanding buffer count to hardware */ 4900eb6f0de0SAdrian Chadd /* aggregates are "one" buffer */ 4901eb6f0de0SAdrian Chadd tid->hwq_depth++; 4902eb6f0de0SAdrian Chadd 4903eb6f0de0SAdrian Chadd /* Punt to hardware or software txq */ 4904eb6f0de0SAdrian Chadd ath_tx_handoff(sc, txq, bf); 4905eb6f0de0SAdrian Chadd } 4906eb6f0de0SAdrian Chadd } 4907eb6f0de0SAdrian Chadd 4908eb6f0de0SAdrian Chadd /* 4909eb6f0de0SAdrian Chadd * Schedule some packets to the given hardware queue. 4910eb6f0de0SAdrian Chadd * 4911eb6f0de0SAdrian Chadd * This function walks the list of TIDs (ie, ath_node TIDs 4912eb6f0de0SAdrian Chadd * with queued traffic) and attempts to schedule traffic 4913eb6f0de0SAdrian Chadd * from them. 4914eb6f0de0SAdrian Chadd * 4915eb6f0de0SAdrian Chadd * TID scheduling is implemented as a FIFO, with TIDs being 4916eb6f0de0SAdrian Chadd * added to the end of the queue after some frames have been 4917eb6f0de0SAdrian Chadd * scheduled. 4918eb6f0de0SAdrian Chadd */ 4919eb6f0de0SAdrian Chadd void 4920eb6f0de0SAdrian Chadd ath_txq_sched(struct ath_softc *sc, struct ath_txq *txq) 4921eb6f0de0SAdrian Chadd { 4922eb6f0de0SAdrian Chadd struct ath_tid *tid, *next, *last; 4923eb6f0de0SAdrian Chadd 4924eb6f0de0SAdrian Chadd ATH_TXQ_LOCK_ASSERT(txq); 4925eb6f0de0SAdrian Chadd 4926eb6f0de0SAdrian Chadd /* 4927eb6f0de0SAdrian Chadd * Don't schedule if the hardware queue is busy. 4928eb6f0de0SAdrian Chadd * This (hopefully) gives some more time to aggregate 4929eb6f0de0SAdrian Chadd * some packets in the aggregation queue. 4930eb6f0de0SAdrian Chadd */ 4931eb6f0de0SAdrian Chadd if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4932eb6f0de0SAdrian Chadd sc->sc_aggr_stats.aggr_sched_nopkt++; 4933eb6f0de0SAdrian Chadd return; 4934eb6f0de0SAdrian Chadd } 4935eb6f0de0SAdrian Chadd 4936eb6f0de0SAdrian Chadd last = TAILQ_LAST(&txq->axq_tidq, axq_t_s); 4937eb6f0de0SAdrian Chadd 4938eb6f0de0SAdrian Chadd TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) { 4939eb6f0de0SAdrian Chadd /* 4940eb6f0de0SAdrian Chadd * Suspend paused queues here; they'll be resumed 4941eb6f0de0SAdrian Chadd * once the addba completes or times out. 4942eb6f0de0SAdrian Chadd */ 4943eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n", 4944eb6f0de0SAdrian Chadd __func__, tid->tid, tid->paused); 4945eb6f0de0SAdrian Chadd ath_tx_tid_unsched(sc, tid); 4946eb6f0de0SAdrian Chadd if (tid->paused) { 4947eb6f0de0SAdrian Chadd continue; 4948eb6f0de0SAdrian Chadd } 4949eb6f0de0SAdrian Chadd if (ath_tx_ampdu_running(sc, tid->an, tid->tid)) 4950eb6f0de0SAdrian Chadd ath_tx_tid_hw_queue_aggr(sc, tid->an, tid); 4951eb6f0de0SAdrian Chadd else 4952eb6f0de0SAdrian Chadd ath_tx_tid_hw_queue_norm(sc, tid->an, tid); 4953eb6f0de0SAdrian Chadd 4954eb6f0de0SAdrian Chadd /* Not empty? Re-schedule */ 4955eb6f0de0SAdrian Chadd if (tid->axq_depth != 0) 4956eb6f0de0SAdrian Chadd ath_tx_tid_sched(sc, tid); 4957eb6f0de0SAdrian Chadd 4958eb6f0de0SAdrian Chadd /* Give the software queue time to aggregate more packets */ 4959eb6f0de0SAdrian Chadd if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4960eb6f0de0SAdrian Chadd break; 4961eb6f0de0SAdrian Chadd } 4962eb6f0de0SAdrian Chadd 4963eb6f0de0SAdrian Chadd /* 4964eb6f0de0SAdrian Chadd * If this was the last entry on the original list, stop. 4965eb6f0de0SAdrian Chadd * Otherwise nodes that have been rescheduled onto the end 4966eb6f0de0SAdrian Chadd * of the TID FIFO list will just keep being rescheduled. 4967eb6f0de0SAdrian Chadd */ 4968eb6f0de0SAdrian Chadd if (tid == last) 4969eb6f0de0SAdrian Chadd break; 4970eb6f0de0SAdrian Chadd } 4971eb6f0de0SAdrian Chadd } 4972eb6f0de0SAdrian Chadd 4973eb6f0de0SAdrian Chadd /* 4974eb6f0de0SAdrian Chadd * TX addba handling 4975eb6f0de0SAdrian Chadd */ 4976eb6f0de0SAdrian Chadd 4977eb6f0de0SAdrian Chadd /* 4978eb6f0de0SAdrian Chadd * Return net80211 TID struct pointer, or NULL for none 4979eb6f0de0SAdrian Chadd */ 4980eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu * 4981eb6f0de0SAdrian Chadd ath_tx_get_tx_tid(struct ath_node *an, int tid) 4982eb6f0de0SAdrian Chadd { 4983eb6f0de0SAdrian Chadd struct ieee80211_node *ni = &an->an_node; 4984eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 4985eb6f0de0SAdrian Chadd 4986eb6f0de0SAdrian Chadd if (tid == IEEE80211_NONQOS_TID) 4987eb6f0de0SAdrian Chadd return NULL; 4988eb6f0de0SAdrian Chadd 49892aa563dfSAdrian Chadd tap = &ni->ni_tx_ampdu[tid]; 4990eb6f0de0SAdrian Chadd return tap; 4991eb6f0de0SAdrian Chadd } 4992eb6f0de0SAdrian Chadd 4993eb6f0de0SAdrian Chadd /* 4994eb6f0de0SAdrian Chadd * Is AMPDU-TX running? 4995eb6f0de0SAdrian Chadd */ 4996eb6f0de0SAdrian Chadd static int 4997eb6f0de0SAdrian Chadd ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid) 4998eb6f0de0SAdrian Chadd { 4999eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 5000eb6f0de0SAdrian Chadd 5001eb6f0de0SAdrian Chadd if (tid == IEEE80211_NONQOS_TID) 5002eb6f0de0SAdrian Chadd return 0; 5003eb6f0de0SAdrian Chadd 5004eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid); 5005eb6f0de0SAdrian Chadd if (tap == NULL) 5006eb6f0de0SAdrian Chadd return 0; /* Not valid; default to not running */ 5007eb6f0de0SAdrian Chadd 5008eb6f0de0SAdrian Chadd return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING); 5009eb6f0de0SAdrian Chadd } 5010eb6f0de0SAdrian Chadd 5011eb6f0de0SAdrian Chadd /* 5012eb6f0de0SAdrian Chadd * Is AMPDU-TX negotiation pending? 5013eb6f0de0SAdrian Chadd */ 5014eb6f0de0SAdrian Chadd static int 5015eb6f0de0SAdrian Chadd ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid) 5016eb6f0de0SAdrian Chadd { 5017eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap; 5018eb6f0de0SAdrian Chadd 5019eb6f0de0SAdrian Chadd if (tid == IEEE80211_NONQOS_TID) 5020eb6f0de0SAdrian Chadd return 0; 5021eb6f0de0SAdrian Chadd 5022eb6f0de0SAdrian Chadd tap = ath_tx_get_tx_tid(an, tid); 5023eb6f0de0SAdrian Chadd if (tap == NULL) 5024eb6f0de0SAdrian Chadd return 0; /* Not valid; default to not pending */ 5025eb6f0de0SAdrian Chadd 5026eb6f0de0SAdrian Chadd return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND); 5027eb6f0de0SAdrian Chadd } 5028eb6f0de0SAdrian Chadd 5029eb6f0de0SAdrian Chadd /* 5030eb6f0de0SAdrian Chadd * Is AMPDU-TX pending for the given TID? 5031eb6f0de0SAdrian Chadd */ 5032eb6f0de0SAdrian Chadd 5033eb6f0de0SAdrian Chadd 5034eb6f0de0SAdrian Chadd /* 5035eb6f0de0SAdrian Chadd * Method to handle sending an ADDBA request. 5036eb6f0de0SAdrian Chadd * 5037eb6f0de0SAdrian Chadd * We tap this so the relevant flags can be set to pause the TID 5038eb6f0de0SAdrian Chadd * whilst waiting for the response. 5039eb6f0de0SAdrian Chadd * 5040eb6f0de0SAdrian Chadd * XXX there's no timeout handler we can override? 5041eb6f0de0SAdrian Chadd */ 5042eb6f0de0SAdrian Chadd int 5043eb6f0de0SAdrian Chadd ath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5044eb6f0de0SAdrian Chadd int dialogtoken, int baparamset, int batimeout) 5045eb6f0de0SAdrian Chadd { 5046eb6f0de0SAdrian Chadd struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 50472aa563dfSAdrian Chadd int tid = tap->txa_tid; 5048eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 5049eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 5050eb6f0de0SAdrian Chadd 5051eb6f0de0SAdrian Chadd /* 5052eb6f0de0SAdrian Chadd * XXX danger Will Robinson! 5053eb6f0de0SAdrian Chadd * 5054eb6f0de0SAdrian Chadd * Although the taskqueue may be running and scheduling some more 5055eb6f0de0SAdrian Chadd * packets, these should all be _before_ the addba sequence number. 5056eb6f0de0SAdrian Chadd * However, net80211 will keep self-assigning sequence numbers 5057eb6f0de0SAdrian Chadd * until addba has been negotiated. 5058eb6f0de0SAdrian Chadd * 5059eb6f0de0SAdrian Chadd * In the past, these packets would be "paused" (which still works 5060eb6f0de0SAdrian Chadd * fine, as they're being scheduled to the driver in the same 5061eb6f0de0SAdrian Chadd * serialised method which is calling the addba request routine) 5062eb6f0de0SAdrian Chadd * and when the aggregation session begins, they'll be dequeued 5063eb6f0de0SAdrian Chadd * as aggregate packets and added to the BAW. However, now there's 5064eb6f0de0SAdrian Chadd * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these 5065eb6f0de0SAdrian Chadd * packets. Thus they never get included in the BAW tracking and 5066eb6f0de0SAdrian Chadd * this can cause the initial burst of packets after the addba 5067eb6f0de0SAdrian Chadd * negotiation to "hang", as they quickly fall outside the BAW. 5068eb6f0de0SAdrian Chadd * 5069eb6f0de0SAdrian Chadd * The "eventual" solution should be to tag these packets with 5070eb6f0de0SAdrian Chadd * dobaw. Although net80211 has given us a sequence number, 5071eb6f0de0SAdrian Chadd * it'll be "after" the left edge of the BAW and thus it'll 5072eb6f0de0SAdrian Chadd * fall within it. 5073eb6f0de0SAdrian Chadd */ 507496ff26ffSAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5075d3a6425bSAdrian Chadd /* 5076d3a6425bSAdrian Chadd * This is a bit annoying. Until net80211 HT code inherits some 5077d3a6425bSAdrian Chadd * (any) locking, we may have this called in parallel BUT only 5078d3a6425bSAdrian Chadd * one response/timeout will be called. Grr. 5079d3a6425bSAdrian Chadd */ 5080d3a6425bSAdrian Chadd if (atid->addba_tx_pending == 0) { 5081eb6f0de0SAdrian Chadd ath_tx_tid_pause(sc, atid); 5082d3a6425bSAdrian Chadd atid->addba_tx_pending = 1; 5083d3a6425bSAdrian Chadd } 508496ff26ffSAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5085eb6f0de0SAdrian Chadd 5086eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5087eb6f0de0SAdrian Chadd "%s: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n", 5088eb6f0de0SAdrian Chadd __func__, dialogtoken, baparamset, batimeout); 5089eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5090eb6f0de0SAdrian Chadd "%s: txa_start=%d, ni_txseqs=%d\n", 5091eb6f0de0SAdrian Chadd __func__, tap->txa_start, ni->ni_txseqs[tid]); 5092eb6f0de0SAdrian Chadd 5093eb6f0de0SAdrian Chadd return sc->sc_addba_request(ni, tap, dialogtoken, baparamset, 5094eb6f0de0SAdrian Chadd batimeout); 5095eb6f0de0SAdrian Chadd } 5096eb6f0de0SAdrian Chadd 5097eb6f0de0SAdrian Chadd /* 5098eb6f0de0SAdrian Chadd * Handle an ADDBA response. 5099eb6f0de0SAdrian Chadd * 5100eb6f0de0SAdrian Chadd * We unpause the queue so TX'ing can resume. 5101eb6f0de0SAdrian Chadd * 5102eb6f0de0SAdrian Chadd * Any packets TX'ed from this point should be "aggregate" (whether 5103eb6f0de0SAdrian Chadd * aggregate or not) so the BAW is updated. 5104eb6f0de0SAdrian Chadd * 5105eb6f0de0SAdrian Chadd * Note! net80211 keeps self-assigning sequence numbers until 5106eb6f0de0SAdrian Chadd * ampdu is negotiated. This means the initially-negotiated BAW left 5107eb6f0de0SAdrian Chadd * edge won't match the ni->ni_txseq. 5108eb6f0de0SAdrian Chadd * 5109eb6f0de0SAdrian Chadd * So, being very dirty, the BAW left edge is "slid" here to match 5110eb6f0de0SAdrian Chadd * ni->ni_txseq. 5111eb6f0de0SAdrian Chadd * 5112eb6f0de0SAdrian Chadd * What likely SHOULD happen is that all packets subsequent to the 5113eb6f0de0SAdrian Chadd * addba request should be tagged as aggregate and queued as non-aggregate 5114eb6f0de0SAdrian Chadd * frames; thus updating the BAW. For now though, I'll just slide the 5115eb6f0de0SAdrian Chadd * window. 5116eb6f0de0SAdrian Chadd */ 5117eb6f0de0SAdrian Chadd int 5118eb6f0de0SAdrian Chadd ath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5119eb6f0de0SAdrian Chadd int status, int code, int batimeout) 5120eb6f0de0SAdrian Chadd { 5121eb6f0de0SAdrian Chadd struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 51222aa563dfSAdrian Chadd int tid = tap->txa_tid; 5123eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 5124eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 5125eb6f0de0SAdrian Chadd int r; 5126eb6f0de0SAdrian Chadd 5127eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5128eb6f0de0SAdrian Chadd "%s: called; status=%d, code=%d, batimeout=%d\n", __func__, 5129eb6f0de0SAdrian Chadd status, code, batimeout); 5130eb6f0de0SAdrian Chadd 5131eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5132eb6f0de0SAdrian Chadd "%s: txa_start=%d, ni_txseqs=%d\n", 5133eb6f0de0SAdrian Chadd __func__, tap->txa_start, ni->ni_txseqs[tid]); 5134eb6f0de0SAdrian Chadd 5135eb6f0de0SAdrian Chadd /* 5136eb6f0de0SAdrian Chadd * Call this first, so the interface flags get updated 5137eb6f0de0SAdrian Chadd * before the TID is unpaused. Otherwise a race condition 5138eb6f0de0SAdrian Chadd * exists where the unpaused TID still doesn't yet have 5139eb6f0de0SAdrian Chadd * IEEE80211_AGGR_RUNNING set. 5140eb6f0de0SAdrian Chadd */ 5141eb6f0de0SAdrian Chadd r = sc->sc_addba_response(ni, tap, status, code, batimeout); 5142eb6f0de0SAdrian Chadd 5143eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5144d3a6425bSAdrian Chadd atid->addba_tx_pending = 0; 5145eb6f0de0SAdrian Chadd /* 5146eb6f0de0SAdrian Chadd * XXX dirty! 5147eb6f0de0SAdrian Chadd * Slide the BAW left edge to wherever net80211 left it for us. 5148eb6f0de0SAdrian Chadd * Read above for more information. 5149eb6f0de0SAdrian Chadd */ 5150eb6f0de0SAdrian Chadd tap->txa_start = ni->ni_txseqs[tid]; 5151eb6f0de0SAdrian Chadd ath_tx_tid_resume(sc, atid); 5152eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5153eb6f0de0SAdrian Chadd return r; 5154eb6f0de0SAdrian Chadd } 5155eb6f0de0SAdrian Chadd 5156eb6f0de0SAdrian Chadd 5157eb6f0de0SAdrian Chadd /* 5158eb6f0de0SAdrian Chadd * Stop ADDBA on a queue. 51598405fe86SAdrian Chadd * 51608405fe86SAdrian Chadd * This can be called whilst BAR TX is currently active on the queue, 51618405fe86SAdrian Chadd * so make sure this is unblocked before continuing. 5162eb6f0de0SAdrian Chadd */ 5163eb6f0de0SAdrian Chadd void 5164eb6f0de0SAdrian Chadd ath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 5165eb6f0de0SAdrian Chadd { 5166eb6f0de0SAdrian Chadd struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 51672aa563dfSAdrian Chadd int tid = tap->txa_tid; 5168eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 5169eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 5170eb6f0de0SAdrian Chadd 5171eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: called\n", __func__); 5172eb6f0de0SAdrian Chadd 51738405fe86SAdrian Chadd /* 51748405fe86SAdrian Chadd * Pause TID traffic early, so there aren't any races 51758405fe86SAdrian Chadd * Unblock the pending BAR held traffic, if it's currently paused. 51768405fe86SAdrian Chadd */ 517796ff26ffSAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5178eb6f0de0SAdrian Chadd ath_tx_tid_pause(sc, atid); 51798405fe86SAdrian Chadd if (atid->bar_wait) { 51808405fe86SAdrian Chadd /* 51818405fe86SAdrian Chadd * bar_unsuspend() expects bar_tx == 1, as it should be 51828405fe86SAdrian Chadd * called from the TX completion path. This quietens 51838405fe86SAdrian Chadd * the warning. It's cleared for us anyway. 51848405fe86SAdrian Chadd */ 51858405fe86SAdrian Chadd atid->bar_tx = 1; 51868405fe86SAdrian Chadd ath_tx_tid_bar_unsuspend(sc, atid); 51878405fe86SAdrian Chadd } 518896ff26ffSAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5189eb6f0de0SAdrian Chadd 5190eb6f0de0SAdrian Chadd /* There's no need to hold the TXQ lock here */ 5191eb6f0de0SAdrian Chadd sc->sc_addba_stop(ni, tap); 5192eb6f0de0SAdrian Chadd 5193eb6f0de0SAdrian Chadd /* 51944dfd4507SAdrian Chadd * ath_tx_tid_cleanup will resume the TID if possible, otherwise 5195eb6f0de0SAdrian Chadd * it'll set the cleanup flag, and it'll be unpaused once 5196eb6f0de0SAdrian Chadd * things have been cleaned up. 5197eb6f0de0SAdrian Chadd */ 51984dfd4507SAdrian Chadd ath_tx_tid_cleanup(sc, an, tid); 5199eb6f0de0SAdrian Chadd } 5200eb6f0de0SAdrian Chadd 5201eb6f0de0SAdrian Chadd /* 5202eb6f0de0SAdrian Chadd * Note: net80211 bar_timeout() doesn't call this function on BAR failure; 5203eb6f0de0SAdrian Chadd * it simply tears down the aggregation session. Ew. 5204eb6f0de0SAdrian Chadd * 5205eb6f0de0SAdrian Chadd * It however will call ieee80211_ampdu_stop() which will call 5206eb6f0de0SAdrian Chadd * ic->ic_addba_stop(). 5207eb6f0de0SAdrian Chadd * 5208eb6f0de0SAdrian Chadd * XXX This uses a hard-coded max BAR count value; the whole 5209eb6f0de0SAdrian Chadd * XXX BAR TX success or failure should be better handled! 5210eb6f0de0SAdrian Chadd */ 5211eb6f0de0SAdrian Chadd void 5212eb6f0de0SAdrian Chadd ath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5213eb6f0de0SAdrian Chadd int status) 5214eb6f0de0SAdrian Chadd { 5215eb6f0de0SAdrian Chadd struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 52162aa563dfSAdrian Chadd int tid = tap->txa_tid; 5217eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 5218eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 5219eb6f0de0SAdrian Chadd int attempts = tap->txa_attempts; 5220eb6f0de0SAdrian Chadd 52210e22ed0eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 5222e60c4fc2SAdrian Chadd "%s: called; tap=%p, atid=%p, txa_tid=%d, atid->tid=%d, status=%d, attempts=%d\n", 52230e22ed0eSAdrian Chadd __func__, 5224e60c4fc2SAdrian Chadd tap, 5225e60c4fc2SAdrian Chadd atid, 5226e60c4fc2SAdrian Chadd tap->txa_tid, 5227e60c4fc2SAdrian Chadd atid->tid, 52280e22ed0eSAdrian Chadd status, 52290e22ed0eSAdrian Chadd attempts); 5230eb6f0de0SAdrian Chadd 5231eb6f0de0SAdrian Chadd /* Note: This may update the BAW details */ 5232eb6f0de0SAdrian Chadd sc->sc_bar_response(ni, tap, status); 5233eb6f0de0SAdrian Chadd 5234eb6f0de0SAdrian Chadd /* Unpause the TID */ 5235eb6f0de0SAdrian Chadd /* 5236eb6f0de0SAdrian Chadd * XXX if this is attempt=50, the TID will be downgraded 5237eb6f0de0SAdrian Chadd * XXX to a non-aggregate session. So we must unpause the 5238eb6f0de0SAdrian Chadd * XXX TID here or it'll never be done. 5239088d8b81SAdrian Chadd * 5240088d8b81SAdrian Chadd * Also, don't call it if bar_tx/bar_wait are 0; something 5241088d8b81SAdrian Chadd * has beaten us to the punch? (XXX figure out what?) 5242eb6f0de0SAdrian Chadd */ 5243eb6f0de0SAdrian Chadd if (status == 0 || attempts == 50) { 5244eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5245088d8b81SAdrian Chadd if (atid->bar_tx == 0 || atid->bar_wait == 0) 5246088d8b81SAdrian Chadd device_printf(sc->sc_dev, 5247088d8b81SAdrian Chadd "%s: huh? bar_tx=%d, bar_wait=%d\n", 5248088d8b81SAdrian Chadd __func__, 5249088d8b81SAdrian Chadd atid->bar_tx, atid->bar_wait); 5250088d8b81SAdrian Chadd else 525188b3d483SAdrian Chadd ath_tx_tid_bar_unsuspend(sc, atid); 5252eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5253eb6f0de0SAdrian Chadd } 5254eb6f0de0SAdrian Chadd } 5255eb6f0de0SAdrian Chadd 5256eb6f0de0SAdrian Chadd /* 5257eb6f0de0SAdrian Chadd * This is called whenever the pending ADDBA request times out. 5258eb6f0de0SAdrian Chadd * Unpause and reschedule the TID. 5259eb6f0de0SAdrian Chadd */ 5260eb6f0de0SAdrian Chadd void 5261eb6f0de0SAdrian Chadd ath_addba_response_timeout(struct ieee80211_node *ni, 5262eb6f0de0SAdrian Chadd struct ieee80211_tx_ampdu *tap) 5263eb6f0de0SAdrian Chadd { 5264eb6f0de0SAdrian Chadd struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 52652aa563dfSAdrian Chadd int tid = tap->txa_tid; 5266eb6f0de0SAdrian Chadd struct ath_node *an = ATH_NODE(ni); 5267eb6f0de0SAdrian Chadd struct ath_tid *atid = &an->an_tid[tid]; 5268eb6f0de0SAdrian Chadd 5269eb6f0de0SAdrian Chadd DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5270eb6f0de0SAdrian Chadd "%s: called; resuming\n", __func__); 5271eb6f0de0SAdrian Chadd 5272d3a6425bSAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5273d3a6425bSAdrian Chadd atid->addba_tx_pending = 0; 5274d3a6425bSAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5275d3a6425bSAdrian Chadd 5276eb6f0de0SAdrian Chadd /* Note: This updates the aggregate state to (again) pending */ 5277eb6f0de0SAdrian Chadd sc->sc_addba_response_timeout(ni, tap); 5278eb6f0de0SAdrian Chadd 5279eb6f0de0SAdrian Chadd /* Unpause the TID; which reschedules it */ 5280eb6f0de0SAdrian Chadd ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5281eb6f0de0SAdrian Chadd ath_tx_tid_resume(sc, atid); 5282eb6f0de0SAdrian Chadd ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5283eb6f0de0SAdrian Chadd } 52843fdfc330SAdrian Chadd 52853fdfc330SAdrian Chadd static int 52863fdfc330SAdrian Chadd ath_legacy_dma_txsetup(struct ath_softc *sc) 52873fdfc330SAdrian Chadd { 52883fdfc330SAdrian Chadd 52893fdfc330SAdrian Chadd /* nothing new needed */ 52903fdfc330SAdrian Chadd return (0); 52913fdfc330SAdrian Chadd } 52923fdfc330SAdrian Chadd 52933fdfc330SAdrian Chadd static int 52943fdfc330SAdrian Chadd ath_legacy_dma_txteardown(struct ath_softc *sc) 52953fdfc330SAdrian Chadd { 52963fdfc330SAdrian Chadd 52973fdfc330SAdrian Chadd /* nothing new needed */ 52983fdfc330SAdrian Chadd return (0); 52993fdfc330SAdrian Chadd } 53003fdfc330SAdrian Chadd 53013fdfc330SAdrian Chadd void 53023fdfc330SAdrian Chadd ath_xmit_setup_legacy(struct ath_softc *sc) 53033fdfc330SAdrian Chadd { 53041006fc0cSAdrian Chadd /* 53051006fc0cSAdrian Chadd * For now, just set the descriptor length to sizeof(ath_desc); 53061006fc0cSAdrian Chadd * worry about extracting the real length out of the HAL later. 53071006fc0cSAdrian Chadd */ 53081006fc0cSAdrian Chadd sc->sc_tx_desclen = sizeof(struct ath_desc); 53091006fc0cSAdrian Chadd sc->sc_tx_statuslen = 0; 53101006fc0cSAdrian Chadd sc->sc_tx_nmaps = 1; /* only one buffer per TX desc */ 53113fdfc330SAdrian Chadd 53123fdfc330SAdrian Chadd sc->sc_tx.xmit_setup = ath_legacy_dma_txsetup; 53133fdfc330SAdrian Chadd sc->sc_tx.xmit_teardown = ath_legacy_dma_txteardown; 5314f8418db5SAdrian Chadd sc->sc_tx.xmit_attach_comp_func = ath_legacy_attach_comp_func; 5315746bab5bSAdrian Chadd 5316746bab5bSAdrian Chadd sc->sc_tx.xmit_dma_restart = ath_legacy_tx_dma_restart; 5317746bab5bSAdrian Chadd sc->sc_tx.xmit_handoff = ath_legacy_xmit_handoff; 5318788e6aa9SAdrian Chadd 5319788e6aa9SAdrian Chadd sc->sc_tx.xmit_drain = ath_legacy_tx_drain; 53203fdfc330SAdrian Chadd } 5321