if_ath_tx.c revision 247029
1218065Sadrian/*- 2218065Sadrian * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3240592Sadrian * Copyright (c) 2010-2012 Adrian Chadd, Xenion Pty Ltd 4218065Sadrian * All rights reserved. 5218065Sadrian * 6218065Sadrian * Redistribution and use in source and binary forms, with or without 7218065Sadrian * modification, are permitted provided that the following conditions 8218065Sadrian * are met: 9218065Sadrian * 1. Redistributions of source code must retain the above copyright 10218065Sadrian * notice, this list of conditions and the following disclaimer, 11218065Sadrian * without modification. 12218065Sadrian * 2. Redistributions in binary form must reproduce at minimum a disclaimer 13218065Sadrian * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 14218065Sadrian * redistribution must be conditioned upon including a substantially 15218065Sadrian * similar Disclaimer requirement for further binary redistribution. 16218065Sadrian * 17218065Sadrian * NO WARRANTY 18218065Sadrian * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19218065Sadrian * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20218065Sadrian * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 21218065Sadrian * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22218065Sadrian * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 23218065Sadrian * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24218065Sadrian * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25218065Sadrian * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26218065Sadrian * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27218065Sadrian * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28218065Sadrian * THE POSSIBILITY OF SUCH DAMAGES. 29218065Sadrian */ 30218065Sadrian 31218065Sadrian#include <sys/cdefs.h> 32218065Sadrian__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath_tx.c 247029 2013-02-20 11:22:44Z adrian $"); 33218065Sadrian 34218065Sadrian/* 35218065Sadrian * Driver for the Atheros Wireless LAN controller. 36218065Sadrian * 37218065Sadrian * This software is derived from work of Atsushi Onoe; his contribution 38218065Sadrian * is greatly appreciated. 39218065Sadrian */ 40218065Sadrian 41218065Sadrian#include "opt_inet.h" 42218065Sadrian#include "opt_ath.h" 43218065Sadrian#include "opt_wlan.h" 44218065Sadrian 45218065Sadrian#include <sys/param.h> 46218065Sadrian#include <sys/systm.h> 47218065Sadrian#include <sys/sysctl.h> 48218065Sadrian#include <sys/mbuf.h> 49218065Sadrian#include <sys/malloc.h> 50218065Sadrian#include <sys/lock.h> 51218065Sadrian#include <sys/mutex.h> 52218065Sadrian#include <sys/kernel.h> 53218065Sadrian#include <sys/socket.h> 54218065Sadrian#include <sys/sockio.h> 55218065Sadrian#include <sys/errno.h> 56218065Sadrian#include <sys/callout.h> 57218065Sadrian#include <sys/bus.h> 58218065Sadrian#include <sys/endian.h> 59218065Sadrian#include <sys/kthread.h> 60218065Sadrian#include <sys/taskqueue.h> 61218065Sadrian#include <sys/priv.h> 62218065Sadrian 63218065Sadrian#include <machine/bus.h> 64218065Sadrian 65218065Sadrian#include <net/if.h> 66218065Sadrian#include <net/if_dl.h> 67218065Sadrian#include <net/if_media.h> 68218065Sadrian#include <net/if_types.h> 69218065Sadrian#include <net/if_arp.h> 70218065Sadrian#include <net/ethernet.h> 71218065Sadrian#include <net/if_llc.h> 72218065Sadrian 73218065Sadrian#include <net80211/ieee80211_var.h> 74218065Sadrian#include <net80211/ieee80211_regdomain.h> 75218065Sadrian#ifdef IEEE80211_SUPPORT_SUPERG 76218065Sadrian#include <net80211/ieee80211_superg.h> 77218065Sadrian#endif 78218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 79218065Sadrian#include <net80211/ieee80211_tdma.h> 80218065Sadrian#endif 81227364Sadrian#include <net80211/ieee80211_ht.h> 82218065Sadrian 83218065Sadrian#include <net/bpf.h> 84218065Sadrian 85218065Sadrian#ifdef INET 86218065Sadrian#include <netinet/in.h> 87218065Sadrian#include <netinet/if_ether.h> 88218065Sadrian#endif 89218065Sadrian 90218065Sadrian#include <dev/ath/if_athvar.h> 91218065Sadrian#include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */ 92218065Sadrian#include <dev/ath/ath_hal/ah_diagcodes.h> 93218065Sadrian 94218065Sadrian#include <dev/ath/if_ath_debug.h> 95218065Sadrian 96218065Sadrian#ifdef ATH_TX99_DIAG 97218065Sadrian#include <dev/ath/ath_tx99/ath_tx99.h> 98218065Sadrian#endif 99218065Sadrian 100218065Sadrian#include <dev/ath/if_ath_misc.h> 101218065Sadrian#include <dev/ath/if_ath_tx.h> 102218240Sadrian#include <dev/ath/if_ath_tx_ht.h> 103218065Sadrian 104242782Sadrian#ifdef ATH_DEBUG_ALQ 105242782Sadrian#include <dev/ath/if_ath_alq.h> 106242782Sadrian#endif 107242782Sadrian 108218154Sadrian/* 109227364Sadrian * How many retries to perform in software 110227364Sadrian */ 111227364Sadrian#define SWMAX_RETRIES 10 112227364Sadrian 113240946Sadrian/* 114240946Sadrian * What queue to throw the non-QoS TID traffic into 115240946Sadrian */ 116240946Sadrian#define ATH_NONQOS_TID_AC WME_AC_VO 117240946Sadrian 118241170Sadrian#if 0 119241170Sadrianstatic int ath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an); 120241170Sadrian#endif 121227364Sadrianstatic int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, 122227364Sadrian int tid); 123227364Sadrianstatic int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, 124227364Sadrian int tid); 125236872Sadrianstatic ieee80211_seq ath_tx_tid_seqno_assign(struct ath_softc *sc, 126236872Sadrian struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0); 127227364Sadrianstatic int ath_tx_action_frame_override_queue(struct ath_softc *sc, 128227364Sadrian struct ieee80211_node *ni, struct mbuf *m0, int *tid); 129240639Sadrianstatic struct ath_buf * 130240639Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 131240639Sadrian struct ath_tid *tid, struct ath_buf *bf); 132227364Sadrian 133243162Sadrian#ifdef ATH_DEBUG_ALQ 134243162Sadrianvoid 135243162Sadrianath_tx_alq_post(struct ath_softc *sc, struct ath_buf *bf_first) 136243162Sadrian{ 137243162Sadrian struct ath_buf *bf; 138243162Sadrian int i, n; 139243162Sadrian const char *ds; 140243162Sadrian 141243162Sadrian /* XXX we should skip out early if debugging isn't enabled! */ 142243162Sadrian bf = bf_first; 143243162Sadrian 144243162Sadrian while (bf != NULL) { 145243162Sadrian /* XXX should ensure bf_nseg > 0! */ 146243162Sadrian if (bf->bf_nseg == 0) 147243162Sadrian break; 148243162Sadrian n = ((bf->bf_nseg - 1) / sc->sc_tx_nmaps) + 1; 149243162Sadrian for (i = 0, ds = (const char *) bf->bf_desc; 150243162Sadrian i < n; 151243162Sadrian i++, ds += sc->sc_tx_desclen) { 152243162Sadrian if_ath_alq_post(&sc->sc_alq, 153243162Sadrian ATH_ALQ_EDMA_TXDESC, 154243162Sadrian sc->sc_tx_desclen, 155243162Sadrian ds); 156243162Sadrian } 157243162Sadrian bf = bf->bf_next; 158243162Sadrian } 159243162Sadrian} 160243162Sadrian#endif /* ATH_DEBUG_ALQ */ 161243162Sadrian 162227364Sadrian/* 163218154Sadrian * Whether to use the 11n rate scenario functions or not 164218154Sadrian */ 165218154Sadrianstatic inline int 166218154Sadrianath_tx_is_11n(struct ath_softc *sc) 167218154Sadrian{ 168239198Sadrian return ((sc->sc_ah->ah_magic == 0x20065416) || 169239198Sadrian (sc->sc_ah->ah_magic == 0x19741014)); 170218154Sadrian} 171218154Sadrian 172227364Sadrian/* 173227364Sadrian * Obtain the current TID from the given frame. 174227364Sadrian * 175227364Sadrian * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.) 176227364Sadrian * This has implications for which AC/priority the packet is placed 177227364Sadrian * in. 178227364Sadrian */ 179227364Sadrianstatic int 180227364Sadrianath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0) 181227364Sadrian{ 182227364Sadrian const struct ieee80211_frame *wh; 183227364Sadrian int pri = M_WME_GETAC(m0); 184227364Sadrian 185227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 186227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 187227364Sadrian return IEEE80211_NONQOS_TID; 188227364Sadrian else 189227364Sadrian return WME_AC_TO_TID(pri); 190227364Sadrian} 191227364Sadrian 192240639Sadrianstatic void 193240639Sadrianath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) 194240639Sadrian{ 195240639Sadrian struct ieee80211_frame *wh; 196240639Sadrian 197240639Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 198240639Sadrian /* Only update/resync if needed */ 199240639Sadrian if (bf->bf_state.bfs_isretried == 0) { 200240639Sadrian wh->i_fc[1] |= IEEE80211_FC1_RETRY; 201240639Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 202240639Sadrian BUS_DMASYNC_PREWRITE); 203240639Sadrian } 204240639Sadrian bf->bf_state.bfs_isretried = 1; 205240639Sadrian bf->bf_state.bfs_retries ++; 206240639Sadrian} 207240639Sadrian 208227364Sadrian/* 209227364Sadrian * Determine what the correct AC queue for the given frame 210227364Sadrian * should be. 211227364Sadrian * 212227364Sadrian * This code assumes that the TIDs map consistently to 213227364Sadrian * the underlying hardware (or software) ath_txq. 214227364Sadrian * Since the sender may try to set an AC which is 215227364Sadrian * arbitrary, non-QoS TIDs may end up being put on 216227364Sadrian * completely different ACs. There's no way to put a 217227364Sadrian * TID into multiple ath_txq's for scheduling, so 218227364Sadrian * for now we override the AC/TXQ selection and set 219227364Sadrian * non-QOS TID frames into the BE queue. 220227364Sadrian * 221227364Sadrian * This may be completely incorrect - specifically, 222227364Sadrian * some management frames may end up out of order 223227364Sadrian * compared to the QoS traffic they're controlling. 224227364Sadrian * I'll look into this later. 225227364Sadrian */ 226227364Sadrianstatic int 227227364Sadrianath_tx_getac(struct ath_softc *sc, const struct mbuf *m0) 228227364Sadrian{ 229227364Sadrian const struct ieee80211_frame *wh; 230227364Sadrian int pri = M_WME_GETAC(m0); 231227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 232227364Sadrian if (IEEE80211_QOS_HAS_SEQ(wh)) 233227364Sadrian return pri; 234227364Sadrian 235240946Sadrian return ATH_NONQOS_TID_AC; 236227364Sadrian} 237227364Sadrian 238218065Sadrianvoid 239218065Sadrianath_txfrag_cleanup(struct ath_softc *sc, 240218065Sadrian ath_bufhead *frags, struct ieee80211_node *ni) 241218065Sadrian{ 242218065Sadrian struct ath_buf *bf, *next; 243218065Sadrian 244218065Sadrian ATH_TXBUF_LOCK_ASSERT(sc); 245218065Sadrian 246227344Sadrian TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) { 247218065Sadrian /* NB: bf assumed clean */ 248227344Sadrian TAILQ_REMOVE(frags, bf, bf_list); 249236993Sadrian ath_returnbuf_head(sc, bf); 250218065Sadrian ieee80211_node_decref(ni); 251218065Sadrian } 252218065Sadrian} 253218065Sadrian 254218065Sadrian/* 255218065Sadrian * Setup xmit of a fragmented frame. Allocate a buffer 256218065Sadrian * for each frag and bump the node reference count to 257218065Sadrian * reflect the held reference to be setup by ath_tx_start. 258218065Sadrian */ 259218065Sadrianint 260218065Sadrianath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags, 261218065Sadrian struct mbuf *m0, struct ieee80211_node *ni) 262218065Sadrian{ 263218065Sadrian struct mbuf *m; 264218065Sadrian struct ath_buf *bf; 265218065Sadrian 266218065Sadrian ATH_TXBUF_LOCK(sc); 267218065Sadrian for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) { 268237000Sadrian /* XXX non-management? */ 269237000Sadrian bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL); 270218065Sadrian if (bf == NULL) { /* out of buffers, cleanup */ 271234009Sadrian device_printf(sc->sc_dev, "%s: no buffer?\n", 272234009Sadrian __func__); 273218065Sadrian ath_txfrag_cleanup(sc, frags, ni); 274218065Sadrian break; 275218065Sadrian } 276218065Sadrian ieee80211_node_incref(ni); 277227344Sadrian TAILQ_INSERT_TAIL(frags, bf, bf_list); 278218065Sadrian } 279218065Sadrian ATH_TXBUF_UNLOCK(sc); 280218065Sadrian 281227344Sadrian return !TAILQ_EMPTY(frags); 282218065Sadrian} 283218065Sadrian 284218065Sadrian/* 285218065Sadrian * Reclaim mbuf resources. For fragmented frames we 286218065Sadrian * need to claim each frag chained with m_nextpkt. 287218065Sadrian */ 288218065Sadrianvoid 289218065Sadrianath_freetx(struct mbuf *m) 290218065Sadrian{ 291218065Sadrian struct mbuf *next; 292218065Sadrian 293218065Sadrian do { 294218065Sadrian next = m->m_nextpkt; 295218065Sadrian m->m_nextpkt = NULL; 296218065Sadrian m_freem(m); 297218065Sadrian } while ((m = next) != NULL); 298218065Sadrian} 299218065Sadrian 300218065Sadrianstatic int 301218065Sadrianath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0) 302218065Sadrian{ 303218065Sadrian struct mbuf *m; 304218065Sadrian int error; 305218065Sadrian 306218065Sadrian /* 307218065Sadrian * Load the DMA map so any coalescing is done. This 308218065Sadrian * also calculates the number of descriptors we need. 309218065Sadrian */ 310218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 311218065Sadrian bf->bf_segs, &bf->bf_nseg, 312218065Sadrian BUS_DMA_NOWAIT); 313218065Sadrian if (error == EFBIG) { 314218065Sadrian /* XXX packet requires too many descriptors */ 315218065Sadrian bf->bf_nseg = ATH_TXDESC+1; 316218065Sadrian } else if (error != 0) { 317218065Sadrian sc->sc_stats.ast_tx_busdma++; 318218065Sadrian ath_freetx(m0); 319218065Sadrian return error; 320218065Sadrian } 321218065Sadrian /* 322218065Sadrian * Discard null packets and check for packets that 323218065Sadrian * require too many TX descriptors. We try to convert 324218065Sadrian * the latter to a cluster. 325218065Sadrian */ 326218065Sadrian if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ 327218065Sadrian sc->sc_stats.ast_tx_linear++; 328243857Sglebius m = m_collapse(m0, M_NOWAIT, ATH_TXDESC); 329218065Sadrian if (m == NULL) { 330218065Sadrian ath_freetx(m0); 331218065Sadrian sc->sc_stats.ast_tx_nombuf++; 332218065Sadrian return ENOMEM; 333218065Sadrian } 334218065Sadrian m0 = m; 335218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 336218065Sadrian bf->bf_segs, &bf->bf_nseg, 337218065Sadrian BUS_DMA_NOWAIT); 338218065Sadrian if (error != 0) { 339218065Sadrian sc->sc_stats.ast_tx_busdma++; 340218065Sadrian ath_freetx(m0); 341218065Sadrian return error; 342218065Sadrian } 343218065Sadrian KASSERT(bf->bf_nseg <= ATH_TXDESC, 344218065Sadrian ("too many segments after defrag; nseg %u", bf->bf_nseg)); 345218065Sadrian } else if (bf->bf_nseg == 0) { /* null packet, discard */ 346218065Sadrian sc->sc_stats.ast_tx_nodata++; 347218065Sadrian ath_freetx(m0); 348218065Sadrian return EIO; 349218065Sadrian } 350218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n", 351218065Sadrian __func__, m0, m0->m_pkthdr.len); 352218065Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 353218065Sadrian bf->bf_m = m0; 354218065Sadrian 355218065Sadrian return 0; 356218065Sadrian} 357218065Sadrian 358227360Sadrian/* 359242656Sadrian * Chain together segments+descriptors for a frame - 11n or otherwise. 360242656Sadrian * 361242656Sadrian * For aggregates, this is called on each frame in the aggregate. 362227360Sadrian */ 363218065Sadrianstatic void 364242656Sadrianath_tx_chaindesclist(struct ath_softc *sc, struct ath_desc *ds0, 365242656Sadrian struct ath_buf *bf, int is_aggr, int is_first_subframe, 366242656Sadrian int is_last_subframe) 367218065Sadrian{ 368218065Sadrian struct ath_hal *ah = sc->sc_ah; 369242656Sadrian char *ds; 370239290Sadrian int i, bp, dsp; 371239051Sadrian HAL_DMA_ADDR bufAddrList[4]; 372239051Sadrian uint32_t segLenList[4]; 373239290Sadrian int numTxMaps = 1; 374239380Sadrian int isFirstDesc = 1; 375239051Sadrian 376238708Sadrian /* 377238708Sadrian * XXX There's txdma and txdma_mgmt; the descriptor 378238708Sadrian * sizes must match. 379238708Sadrian */ 380238708Sadrian struct ath_descdma *dd = &sc->sc_txdma; 381218065Sadrian 382218065Sadrian /* 383218065Sadrian * Fillin the remainder of the descriptor info. 384218065Sadrian */ 385239290Sadrian 386239290Sadrian /* 387239290Sadrian * For now the HAL doesn't implement halNumTxMaps for non-EDMA 388239290Sadrian * (ie it's 0.) So just work around it. 389239290Sadrian * 390239290Sadrian * XXX TODO: populate halNumTxMaps for each HAL chip and 391239290Sadrian * then undo this hack. 392239290Sadrian */ 393239290Sadrian if (sc->sc_ah->ah_magic == 0x19741014) 394239290Sadrian numTxMaps = 4; 395239290Sadrian 396239290Sadrian /* 397239290Sadrian * For EDMA and later chips ensure the TX map is fully populated 398239290Sadrian * before advancing to the next descriptor. 399239290Sadrian */ 400242656Sadrian ds = (char *) bf->bf_desc; 401239290Sadrian bp = dsp = 0; 402239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 403239290Sadrian bzero(segLenList, sizeof(segLenList)); 404239290Sadrian for (i = 0; i < bf->bf_nseg; i++) { 405239290Sadrian bufAddrList[bp] = bf->bf_segs[i].ds_addr; 406239290Sadrian segLenList[bp] = bf->bf_segs[i].ds_len; 407239290Sadrian bp++; 408239051Sadrian 409239290Sadrian /* 410239290Sadrian * Go to the next segment if this isn't the last segment 411239290Sadrian * and there's space in the current TX map. 412239290Sadrian */ 413239290Sadrian if ((i != bf->bf_nseg - 1) && (bp < numTxMaps)) 414239290Sadrian continue; 415239051Sadrian 416239290Sadrian /* 417239290Sadrian * Last segment or we're out of buffer pointers. 418239290Sadrian */ 419239290Sadrian bp = 0; 420239290Sadrian 421218065Sadrian if (i == bf->bf_nseg - 1) 422239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 0); 423218065Sadrian else 424239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 425239290Sadrian bf->bf_daddr + dd->dd_descsize * (dsp + 1)); 426239051Sadrian 427239051Sadrian /* 428244109Sadrian * XXX This assumes that bfs_txq is the actual destination 429244109Sadrian * hardware queue at this point. It may not have been 430244109Sadrian * assigned, it may actually be pointing to the multicast 431244109Sadrian * software TXQ id. These must be fixed! 432239051Sadrian */ 433239409Sadrian ath_hal_filltxdesc(ah, (struct ath_desc *) ds 434239051Sadrian , bufAddrList 435239051Sadrian , segLenList 436239290Sadrian , bf->bf_descid /* XXX desc id */ 437244109Sadrian , bf->bf_state.bfs_tx_queue 438239380Sadrian , isFirstDesc /* first segment */ 439218065Sadrian , i == bf->bf_nseg - 1 /* last segment */ 440239409Sadrian , (struct ath_desc *) ds0 /* first descriptor */ 441218065Sadrian ); 442240255Sadrian 443242656Sadrian /* 444242656Sadrian * Make sure the 11n aggregate fields are cleared. 445242656Sadrian * 446242656Sadrian * XXX TODO: this doesn't need to be called for 447242656Sadrian * aggregate frames; as it'll be called on all 448242656Sadrian * sub-frames. Since the descriptors are in 449242656Sadrian * non-cacheable memory, this leads to some 450242656Sadrian * rather slow writes on MIPS/ARM platforms. 451242656Sadrian */ 452240255Sadrian if (ath_tx_is_11n(sc)) 453240333Sadrian ath_hal_clr11n_aggr(sc->sc_ah, (struct ath_desc *) ds); 454240255Sadrian 455242656Sadrian /* 456242656Sadrian * If 11n is enabled, set it up as if it's an aggregate 457242656Sadrian * frame. 458242656Sadrian */ 459242656Sadrian if (is_last_subframe) { 460242656Sadrian ath_hal_set11n_aggr_last(sc->sc_ah, 461242656Sadrian (struct ath_desc *) ds); 462242656Sadrian } else if (is_aggr) { 463242656Sadrian /* 464242656Sadrian * This clears the aggrlen field; so 465242656Sadrian * the caller needs to call set_aggr_first()! 466242656Sadrian * 467242656Sadrian * XXX TODO: don't call this for the first 468242656Sadrian * descriptor in the first frame in an 469242656Sadrian * aggregate! 470242656Sadrian */ 471242656Sadrian ath_hal_set11n_aggr_middle(sc->sc_ah, 472242656Sadrian (struct ath_desc *) ds, 473242656Sadrian bf->bf_state.bfs_ndelim); 474242656Sadrian } 475239380Sadrian isFirstDesc = 0; 476239409Sadrian bf->bf_lastds = (struct ath_desc *) ds; 477239290Sadrian 478239290Sadrian /* 479239290Sadrian * Don't forget to skip to the next descriptor. 480239290Sadrian */ 481239409Sadrian ds += sc->sc_tx_desclen; 482239290Sadrian dsp++; 483239290Sadrian 484239290Sadrian /* 485239290Sadrian * .. and don't forget to blank these out! 486239290Sadrian */ 487239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 488239290Sadrian bzero(segLenList, sizeof(segLenList)); 489218065Sadrian } 490233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 491218154Sadrian} 492218154Sadrian 493227364Sadrian/* 494238947Sadrian * Set the rate control fields in the given descriptor based on 495238947Sadrian * the bf_state fields and node state. 496238947Sadrian * 497238947Sadrian * The bfs fields should already be set with the relevant rate 498238947Sadrian * control information, including whether MRR is to be enabled. 499238947Sadrian * 500238947Sadrian * Since the FreeBSD HAL currently sets up the first TX rate 501238947Sadrian * in ath_hal_setuptxdesc(), this will setup the MRR 502238947Sadrian * conditionally for the pre-11n chips, and call ath_buf_set_rate 503238947Sadrian * unconditionally for 11n chips. These require the 11n rate 504238947Sadrian * scenario to be set if MCS rates are enabled, so it's easier 505238947Sadrian * to just always call it. The caller can then only set rates 2, 3 506238947Sadrian * and 4 if multi-rate retry is needed. 507238947Sadrian */ 508238947Sadrianstatic void 509238947Sadrianath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni, 510238947Sadrian struct ath_buf *bf) 511238947Sadrian{ 512238947Sadrian struct ath_rc_series *rc = bf->bf_state.bfs_rc; 513238947Sadrian 514238947Sadrian /* If mrr is disabled, blank tries 1, 2, 3 */ 515238947Sadrian if (! bf->bf_state.bfs_ismrr) 516238947Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 517238947Sadrian 518243647Sadrian#if 0 519238947Sadrian /* 520243647Sadrian * If NOACK is set, just set ntries=1. 521243647Sadrian */ 522243647Sadrian else if (bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) { 523243647Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 524243647Sadrian rc[0].tries = 1; 525243647Sadrian } 526243647Sadrian#endif 527243647Sadrian 528243647Sadrian /* 529238947Sadrian * Always call - that way a retried descriptor will 530238947Sadrian * have the MRR fields overwritten. 531238947Sadrian * 532238947Sadrian * XXX TODO: see if this is really needed - setting up 533238947Sadrian * the first descriptor should set the MRR fields to 0 534238947Sadrian * for us anyway. 535238947Sadrian */ 536238947Sadrian if (ath_tx_is_11n(sc)) { 537238947Sadrian ath_buf_set_rate(sc, ni, bf); 538238947Sadrian } else { 539238947Sadrian ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc 540238947Sadrian , rc[1].ratecode, rc[1].tries 541238947Sadrian , rc[2].ratecode, rc[2].tries 542238947Sadrian , rc[3].ratecode, rc[3].tries 543238947Sadrian ); 544238947Sadrian } 545238947Sadrian} 546238947Sadrian 547238947Sadrian/* 548227364Sadrian * Setup segments+descriptors for an 11n aggregate. 549227364Sadrian * bf_first is the first buffer in the aggregate. 550227364Sadrian * The descriptor list must already been linked together using 551227364Sadrian * bf->bf_next. 552227364Sadrian */ 553227364Sadrianstatic void 554227364Sadrianath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first) 555227364Sadrian{ 556227364Sadrian struct ath_buf *bf, *bf_prev = NULL; 557242656Sadrian struct ath_desc *ds0 = bf_first->bf_desc; 558227364Sadrian 559227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n", 560227364Sadrian __func__, bf_first->bf_state.bfs_nframes, 561227364Sadrian bf_first->bf_state.bfs_al); 562227364Sadrian 563242951Sadrian bf = bf_first; 564242951Sadrian 565242951Sadrian if (bf->bf_state.bfs_txrate0 == 0) 566242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, txrate0=%d\n", 567242951Sadrian __func__, bf, 0); 568242951Sadrian if (bf->bf_state.bfs_rc[0].ratecode == 0) 569242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, rix0=%d\n", 570242951Sadrian __func__, bf, 0); 571242951Sadrian 572227364Sadrian /* 573242656Sadrian * Setup all descriptors of all subframes - this will 574242656Sadrian * call ath_hal_set11naggrmiddle() on every frame. 575227364Sadrian */ 576227364Sadrian while (bf != NULL) { 577227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 578227364Sadrian "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n", 579227364Sadrian __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen, 580227364Sadrian SEQNO(bf->bf_state.bfs_seqno)); 581227364Sadrian 582242656Sadrian /* 583242656Sadrian * Setup the initial fields for the first descriptor - all 584242656Sadrian * the non-11n specific stuff. 585242656Sadrian */ 586242656Sadrian ath_hal_setuptxdesc(sc->sc_ah, bf->bf_desc 587242656Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 588242656Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 589242656Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 590242656Sadrian , bf->bf_state.bfs_txpower /* txpower */ 591242656Sadrian , bf->bf_state.bfs_txrate0 592242656Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 593242656Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 594242656Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 595242656Sadrian , bf->bf_state.bfs_txflags | HAL_TXDESC_INTREQ /* flags */ 596242656Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 597242656Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 598242656Sadrian ); 599227364Sadrian 600227364Sadrian /* 601242656Sadrian * First descriptor? Setup the rate control and initial 602242656Sadrian * aggregate header information. 603242656Sadrian */ 604242656Sadrian if (bf == bf_first) { 605242656Sadrian /* 606242656Sadrian * setup first desc with rate and aggr info 607242656Sadrian */ 608242656Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 609242656Sadrian } 610242656Sadrian 611242656Sadrian /* 612242656Sadrian * Setup the descriptors for a multi-descriptor frame. 613242656Sadrian * This is both aggregate and non-aggregate aware. 614242656Sadrian */ 615242656Sadrian ath_tx_chaindesclist(sc, ds0, bf, 616242656Sadrian 1, /* is_aggr */ 617242656Sadrian !! (bf == bf_first), /* is_first_subframe */ 618242656Sadrian !! (bf->bf_next == NULL) /* is_last_subframe */ 619242656Sadrian ); 620242656Sadrian 621242656Sadrian if (bf == bf_first) { 622242656Sadrian /* 623242656Sadrian * Initialise the first 11n aggregate with the 624242656Sadrian * aggregate length and aggregate enable bits. 625242656Sadrian */ 626242656Sadrian ath_hal_set11n_aggr_first(sc->sc_ah, 627242656Sadrian ds0, 628242656Sadrian bf->bf_state.bfs_al, 629242656Sadrian bf->bf_state.bfs_ndelim); 630242656Sadrian } 631242656Sadrian 632242656Sadrian /* 633227364Sadrian * Link the last descriptor of the previous frame 634227364Sadrian * to the beginning descriptor of this frame. 635227364Sadrian */ 636227364Sadrian if (bf_prev != NULL) 637238609Sadrian ath_hal_settxdesclink(sc->sc_ah, bf_prev->bf_lastds, 638238609Sadrian bf->bf_daddr); 639227364Sadrian 640227364Sadrian /* Save a copy so we can link the next descriptor in */ 641227364Sadrian bf_prev = bf; 642227364Sadrian bf = bf->bf_next; 643227364Sadrian } 644227364Sadrian 645227364Sadrian /* 646227364Sadrian * Set the first descriptor bf_lastds field to point to 647227364Sadrian * the last descriptor in the last subframe, that's where 648227364Sadrian * the status update will occur. 649227364Sadrian */ 650227364Sadrian bf_first->bf_lastds = bf_prev->bf_lastds; 651227364Sadrian 652227364Sadrian /* 653227364Sadrian * And bf_last in the first descriptor points to the end of 654227364Sadrian * the aggregate list. 655227364Sadrian */ 656227364Sadrian bf_first->bf_last = bf_prev; 657227364Sadrian 658243047Sadrian /* 659243047Sadrian * For non-AR9300 NICs, which require the rate control 660243047Sadrian * in the final descriptor - let's set that up now. 661243047Sadrian * 662243047Sadrian * This is because the filltxdesc() HAL call doesn't 663243047Sadrian * populate the last segment with rate control information 664243047Sadrian * if firstSeg is also true. For non-aggregate frames 665243047Sadrian * that is fine, as the first frame already has rate control 666243047Sadrian * info. But if the last frame in an aggregate has one 667243047Sadrian * descriptor, both firstseg and lastseg will be true and 668243047Sadrian * the rate info isn't copied. 669243047Sadrian * 670243047Sadrian * This is inefficient on MIPS/ARM platforms that have 671243047Sadrian * non-cachable memory for TX descriptors, but we'll just 672243047Sadrian * make do for now. 673243047Sadrian * 674243047Sadrian * As to why the rate table is stashed in the last descriptor 675243047Sadrian * rather than the first descriptor? Because proctxdesc() 676243047Sadrian * is called on the final descriptor in an MPDU or A-MPDU - 677243047Sadrian * ie, the one that gets updated by the hardware upon 678243047Sadrian * completion. That way proctxdesc() doesn't need to know 679243047Sadrian * about the first _and_ last TX descriptor. 680243047Sadrian */ 681243047Sadrian ath_hal_setuplasttxdesc(sc->sc_ah, bf_prev->bf_lastds, ds0); 682243047Sadrian 683227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__); 684227364Sadrian} 685227364Sadrian 686239051Sadrian/* 687239051Sadrian * Hand-off a frame to the multicast TX queue. 688239051Sadrian * 689239051Sadrian * This is a software TXQ which will be appended to the CAB queue 690239051Sadrian * during the beacon setup code. 691239051Sadrian * 692239051Sadrian * XXX TODO: since the AR9300 EDMA TX queue support wants the QCU ID 693244109Sadrian * as part of the TX descriptor, bf_state.bfs_tx_queue must be updated 694239051Sadrian * with the actual hardware txq, or all of this will fall apart. 695239051Sadrian * 696239051Sadrian * XXX It may not be a bad idea to just stuff the QCU ID into bf_state 697244109Sadrian * and retire bfs_tx_queue; then make sure the CABQ QCU ID is populated 698239051Sadrian * correctly. 699239051Sadrian */ 700227364Sadrianstatic void 701227364Sadrianath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq, 702227364Sadrian struct ath_buf *bf) 703227364Sadrian{ 704243786Sadrian ATH_TX_LOCK_ASSERT(sc); 705243786Sadrian 706227364Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 707227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 708227364Sadrian if (txq->axq_link != NULL) { 709227364Sadrian struct ath_buf *last = ATH_TXQ_LAST(txq, axq_q_s); 710227364Sadrian struct ieee80211_frame *wh; 711227364Sadrian 712227364Sadrian /* mark previous frame */ 713227364Sadrian wh = mtod(last->bf_m, struct ieee80211_frame *); 714227364Sadrian wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; 715227364Sadrian bus_dmamap_sync(sc->sc_dmat, last->bf_dmamap, 716227364Sadrian BUS_DMASYNC_PREWRITE); 717227364Sadrian 718227364Sadrian /* link descriptor */ 719227364Sadrian *txq->axq_link = bf->bf_daddr; 720227364Sadrian } 721227364Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 722238609Sadrian ath_hal_gettxdesclinkptr(sc->sc_ah, bf->bf_lastds, &txq->axq_link); 723227364Sadrian} 724227364Sadrian 725227364Sadrian/* 726227364Sadrian * Hand-off packet to a hardware queue. 727227364Sadrian */ 728227364Sadrianstatic void 729229949Sadrianath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq, 730229949Sadrian struct ath_buf *bf) 731227364Sadrian{ 732227364Sadrian struct ath_hal *ah = sc->sc_ah; 733227364Sadrian 734227364Sadrian /* 735218065Sadrian * Insert the frame on the outbound list and pass it on 736218065Sadrian * to the hardware. Multicast frames buffered for power 737218065Sadrian * save stations and transmit from the CAB queue are stored 738218065Sadrian * on a s/w only queue and loaded on to the CAB queue in 739218065Sadrian * the SWBA handler since frames only go out on DTIM and 740218065Sadrian * to avoid possible races. 741218065Sadrian */ 742243786Sadrian ATH_TX_LOCK_ASSERT(sc); 743218065Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 744227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 745227364Sadrian KASSERT(txq->axq_qnum != ATH_TXQ_SWQ, 746227364Sadrian ("ath_tx_handoff_hw called for mcast queue")); 747227364Sadrian 748227651Sadrian#if 0 749227651Sadrian /* 750227651Sadrian * This causes a LOR. Find out where the PCU lock is being 751227651Sadrian * held whilst the TXQ lock is grabbed - that shouldn't 752227651Sadrian * be occuring. 753227651Sadrian */ 754227651Sadrian ATH_PCU_LOCK(sc); 755227651Sadrian if (sc->sc_inreset_cnt) { 756227651Sadrian ATH_PCU_UNLOCK(sc); 757227651Sadrian DPRINTF(sc, ATH_DEBUG_RESET, 758227651Sadrian "%s: called with sc_in_reset != 0\n", 759227651Sadrian __func__); 760227651Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 761227651Sadrian "%s: queued: TXDP[%u] = %p (%p) depth %d\n", 762227651Sadrian __func__, txq->axq_qnum, 763227651Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 764227651Sadrian txq->axq_depth); 765227651Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 766227651Sadrian if (bf->bf_state.bfs_aggr) 767227651Sadrian txq->axq_aggr_depth++; 768227651Sadrian /* 769227651Sadrian * There's no need to update axq_link; the hardware 770227651Sadrian * is in reset and once the reset is complete, any 771227651Sadrian * non-empty queues will simply have DMA restarted. 772227651Sadrian */ 773227651Sadrian return; 774227651Sadrian } 775227651Sadrian ATH_PCU_UNLOCK(sc); 776227651Sadrian#endif 777227651Sadrian 778227364Sadrian /* For now, so not to generate whitespace diffs */ 779227364Sadrian if (1) { 780218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 781218065Sadrian int qbusy; 782218065Sadrian 783218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 784218065Sadrian qbusy = ath_hal_txqenabled(ah, txq->axq_qnum); 785240899Sadrian 786240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 4, 787240899Sadrian "ath_tx_handoff: txq=%u, add bf=%p, qbusy=%d, depth=%d", 788240899Sadrian txq->axq_qnum, bf, qbusy, txq->axq_depth); 789218065Sadrian if (txq->axq_link == NULL) { 790218065Sadrian /* 791218065Sadrian * Be careful writing the address to TXDP. If 792218065Sadrian * the tx q is enabled then this write will be 793218065Sadrian * ignored. Normally this is not an issue but 794218065Sadrian * when tdma is in use and the q is beacon gated 795218065Sadrian * this race can occur. If the q is busy then 796218065Sadrian * defer the work to later--either when another 797218065Sadrian * packet comes along or when we prepare a beacon 798218065Sadrian * frame at SWBA. 799218065Sadrian */ 800218065Sadrian if (!qbusy) { 801229949Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 802229949Sadrian bf->bf_daddr); 803218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 804218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 805240899Sadrian "%s: TXDP[%u] = %p (%p) lastds=%p depth %d\n", 806218065Sadrian __func__, txq->axq_qnum, 807218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 808240899Sadrian bf->bf_lastds, 809218065Sadrian txq->axq_depth); 810240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 811240899Sadrian "ath_tx_handoff: TXDP[%u] = %p (%p) " 812240899Sadrian "lastds=%p depth %d", 813240899Sadrian txq->axq_qnum, 814240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 815240899Sadrian bf->bf_lastds, 816240899Sadrian txq->axq_depth); 817218065Sadrian } else { 818218065Sadrian txq->axq_flags |= ATH_TXQ_PUTPENDING; 819218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 820218065Sadrian "%s: Q%u busy, defer enable\n", __func__, 821218065Sadrian txq->axq_qnum); 822240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 0, "defer enable"); 823218065Sadrian } 824218065Sadrian } else { 825218065Sadrian *txq->axq_link = bf->bf_daddr; 826218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 827218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 828218065Sadrian txq->axq_qnum, txq->axq_link, 829229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 830229949Sadrian txq->axq_depth); 831240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 832240899Sadrian "ath_tx_handoff: link[%u](%p)=%p (%p) lastds=%p", 833240899Sadrian txq->axq_qnum, txq->axq_link, 834240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 835240899Sadrian bf->bf_lastds); 836240899Sadrian 837218065Sadrian if ((txq->axq_flags & ATH_TXQ_PUTPENDING) && !qbusy) { 838218065Sadrian /* 839218065Sadrian * The q was busy when we previously tried 840218065Sadrian * to write the address of the first buffer 841218065Sadrian * in the chain. Since it's not busy now 842218065Sadrian * handle this chore. We are certain the 843218065Sadrian * buffer at the front is the right one since 844218065Sadrian * axq_link is NULL only when the buffer list 845218065Sadrian * is/was empty. 846218065Sadrian */ 847218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 848227344Sadrian TAILQ_FIRST(&txq->axq_q)->bf_daddr); 849218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 850218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 851218065Sadrian "%s: Q%u restarted\n", __func__, 852218065Sadrian txq->axq_qnum); 853240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 4, 854240899Sadrian "ath_tx_handoff: txq[%d] restarted, bf=%p " 855240899Sadrian "daddr=%p ds=%p", 856240899Sadrian txq->axq_qnum, 857240899Sadrian bf, 858240899Sadrian (caddr_t)bf->bf_daddr, 859240899Sadrian bf->bf_desc); 860218065Sadrian } 861218065Sadrian } 862218065Sadrian#else 863218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 864241500Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, 865241500Sadrian "ath_tx_handoff: non-tdma: txq=%u, add bf=%p " 866240899Sadrian "depth=%d", 867240899Sadrian txq->axq_qnum, 868240899Sadrian bf, 869240899Sadrian txq->axq_depth); 870218065Sadrian if (txq->axq_link == NULL) { 871218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 872218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 873218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 874218065Sadrian __func__, txq->axq_qnum, 875218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 876218065Sadrian txq->axq_depth); 877240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 878240899Sadrian "ath_tx_handoff: non-tdma: TXDP[%u] = %p (%p) " 879240899Sadrian "lastds=%p depth %d", 880240899Sadrian txq->axq_qnum, 881240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 882240899Sadrian bf->bf_lastds, 883240899Sadrian txq->axq_depth); 884240899Sadrian 885218065Sadrian } else { 886218065Sadrian *txq->axq_link = bf->bf_daddr; 887218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 888218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 889218065Sadrian txq->axq_qnum, txq->axq_link, 890229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 891229949Sadrian txq->axq_depth); 892240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 893240899Sadrian "ath_tx_handoff: non-tdma: link[%u](%p)=%p (%p) " 894240899Sadrian "lastds=%d", 895240899Sadrian txq->axq_qnum, txq->axq_link, 896240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 897240899Sadrian bf->bf_lastds); 898240899Sadrian 899218065Sadrian } 900218065Sadrian#endif /* IEEE80211_SUPPORT_TDMA */ 901227360Sadrian if (bf->bf_state.bfs_aggr) 902227360Sadrian txq->axq_aggr_depth++; 903238609Sadrian ath_hal_gettxdesclinkptr(ah, bf->bf_lastds, &txq->axq_link); 904218065Sadrian ath_hal_txstart(ah, txq->axq_qnum); 905240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 1, 906240899Sadrian "ath_tx_handoff: txq=%u, txstart", txq->axq_qnum); 907227364Sadrian } 908227364Sadrian} 909218065Sadrian 910227364Sadrian/* 911227364Sadrian * Restart TX DMA for the given TXQ. 912227364Sadrian * 913227364Sadrian * This must be called whether the queue is empty or not. 914227364Sadrian */ 915238930Sadrianstatic void 916238930Sadrianath_legacy_tx_dma_restart(struct ath_softc *sc, struct ath_txq *txq) 917227364Sadrian{ 918227364Sadrian struct ath_hal *ah = sc->sc_ah; 919232707Sadrian struct ath_buf *bf, *bf_last; 920218065Sadrian 921243786Sadrian ATH_TX_LOCK_ASSERT(sc); 922227364Sadrian 923227364Sadrian /* This is always going to be cleared, empty or not */ 924227364Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 925227364Sadrian 926232707Sadrian /* XXX make this ATH_TXQ_FIRST */ 927227364Sadrian bf = TAILQ_FIRST(&txq->axq_q); 928232707Sadrian bf_last = ATH_TXQ_LAST(txq, axq_q_s); 929232707Sadrian 930227364Sadrian if (bf == NULL) 931227364Sadrian return; 932227364Sadrian 933227364Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 934239120Sadrian ath_hal_gettxdesclinkptr(ah, bf_last->bf_lastds, &txq->axq_link); 935227364Sadrian ath_hal_txstart(ah, txq->axq_qnum); 936218065Sadrian} 937218065Sadrian 938227364Sadrian/* 939227364Sadrian * Hand off a packet to the hardware (or mcast queue.) 940227364Sadrian * 941227364Sadrian * The relevant hardware txq should be locked. 942227364Sadrian */ 943227364Sadrianstatic void 944238930Sadrianath_legacy_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq, 945238930Sadrian struct ath_buf *bf) 946227364Sadrian{ 947243786Sadrian ATH_TX_LOCK_ASSERT(sc); 948227364Sadrian 949243162Sadrian#ifdef ATH_DEBUG_ALQ 950243162Sadrian if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC)) 951243162Sadrian ath_tx_alq_post(sc, bf); 952243162Sadrian#endif 953243162Sadrian 954227364Sadrian if (txq->axq_qnum == ATH_TXQ_SWQ) 955227364Sadrian ath_tx_handoff_mcast(sc, txq, bf); 956227364Sadrian else 957227364Sadrian ath_tx_handoff_hw(sc, txq, bf); 958227364Sadrian} 959227364Sadrian 960218154Sadrianstatic int 961218154Sadrianath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni, 962229949Sadrian struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen, 963229949Sadrian int *keyix) 964218154Sadrian{ 965233330Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 966233330Sadrian "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n", 967233330Sadrian __func__, 968233330Sadrian *hdrlen, 969233330Sadrian *pktlen, 970233330Sadrian isfrag, 971233330Sadrian iswep, 972233330Sadrian m0); 973233330Sadrian 974218154Sadrian if (iswep) { 975218154Sadrian const struct ieee80211_cipher *cip; 976218154Sadrian struct ieee80211_key *k; 977218154Sadrian 978218154Sadrian /* 979218154Sadrian * Construct the 802.11 header+trailer for an encrypted 980218154Sadrian * frame. The only reason this can fail is because of an 981218154Sadrian * unknown or unsupported cipher/key type. 982218154Sadrian */ 983218154Sadrian k = ieee80211_crypto_encap(ni, m0); 984218154Sadrian if (k == NULL) { 985218154Sadrian /* 986218154Sadrian * This can happen when the key is yanked after the 987218154Sadrian * frame was queued. Just discard the frame; the 988218154Sadrian * 802.11 layer counts failures and provides 989218154Sadrian * debugging/diagnostics. 990218154Sadrian */ 991229949Sadrian return (0); 992218154Sadrian } 993218154Sadrian /* 994218154Sadrian * Adjust the packet + header lengths for the crypto 995218154Sadrian * additions and calculate the h/w key index. When 996218154Sadrian * a s/w mic is done the frame will have had any mic 997218154Sadrian * added to it prior to entry so m0->m_pkthdr.len will 998218154Sadrian * account for it. Otherwise we need to add it to the 999218154Sadrian * packet length. 1000218154Sadrian */ 1001218154Sadrian cip = k->wk_cipher; 1002218154Sadrian (*hdrlen) += cip->ic_header; 1003218154Sadrian (*pktlen) += cip->ic_header + cip->ic_trailer; 1004218154Sadrian /* NB: frags always have any TKIP MIC done in s/w */ 1005218154Sadrian if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag) 1006218154Sadrian (*pktlen) += cip->ic_miclen; 1007218154Sadrian (*keyix) = k->wk_keyix; 1008218154Sadrian } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { 1009218154Sadrian /* 1010218154Sadrian * Use station key cache slot, if assigned. 1011218154Sadrian */ 1012218154Sadrian (*keyix) = ni->ni_ucastkey.wk_keyix; 1013218154Sadrian if ((*keyix) == IEEE80211_KEYIX_NONE) 1014218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 1015218154Sadrian } else 1016218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 1017218154Sadrian 1018229949Sadrian return (1); 1019218154Sadrian} 1020218154Sadrian 1021233989Sadrian/* 1022233989Sadrian * Calculate whether interoperability protection is required for 1023233989Sadrian * this frame. 1024233989Sadrian * 1025233989Sadrian * This requires the rate control information be filled in, 1026233989Sadrian * as the protection requirement depends upon the current 1027233989Sadrian * operating mode / PHY. 1028233989Sadrian */ 1029233989Sadrianstatic void 1030233989Sadrianath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf) 1031233989Sadrian{ 1032233989Sadrian struct ieee80211_frame *wh; 1033233989Sadrian uint8_t rix; 1034233989Sadrian uint16_t flags; 1035233989Sadrian int shortPreamble; 1036233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1037233989Sadrian struct ifnet *ifp = sc->sc_ifp; 1038233989Sadrian struct ieee80211com *ic = ifp->if_l2com; 1039233989Sadrian 1040233989Sadrian flags = bf->bf_state.bfs_txflags; 1041233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1042233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 1043233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 1044233989Sadrian 1045233989Sadrian /* 1046233989Sadrian * If 802.11g protection is enabled, determine whether 1047233989Sadrian * to use RTS/CTS or just CTS. Note that this is only 1048233989Sadrian * done for OFDM unicast frames. 1049233989Sadrian */ 1050233989Sadrian if ((ic->ic_flags & IEEE80211_F_USEPROT) && 1051233989Sadrian rt->info[rix].phy == IEEE80211_T_OFDM && 1052233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 1053233989Sadrian bf->bf_state.bfs_doprot = 1; 1054233989Sadrian /* XXX fragments must use CCK rates w/ protection */ 1055233989Sadrian if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) { 1056233989Sadrian flags |= HAL_TXDESC_RTSENA; 1057233989Sadrian } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) { 1058233989Sadrian flags |= HAL_TXDESC_CTSENA; 1059233989Sadrian } 1060233989Sadrian /* 1061233989Sadrian * For frags it would be desirable to use the 1062233989Sadrian * highest CCK rate for RTS/CTS. But stations 1063233989Sadrian * farther away may detect it at a lower CCK rate 1064233989Sadrian * so use the configured protection rate instead 1065233989Sadrian * (for now). 1066233989Sadrian */ 1067233989Sadrian sc->sc_stats.ast_tx_protect++; 1068233989Sadrian } 1069233989Sadrian 1070233989Sadrian /* 1071233989Sadrian * If 11n protection is enabled and it's a HT frame, 1072233989Sadrian * enable RTS. 1073233989Sadrian * 1074233989Sadrian * XXX ic_htprotmode or ic_curhtprotmode? 1075233989Sadrian * XXX should it_htprotmode only matter if ic_curhtprotmode 1076233989Sadrian * XXX indicates it's not a HT pure environment? 1077233989Sadrian */ 1078233989Sadrian if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && 1079233989Sadrian rt->info[rix].phy == IEEE80211_T_HT && 1080233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 1081233989Sadrian flags |= HAL_TXDESC_RTSENA; 1082233989Sadrian sc->sc_stats.ast_tx_htprotect++; 1083233989Sadrian } 1084233989Sadrian bf->bf_state.bfs_txflags = flags; 1085233989Sadrian} 1086233989Sadrian 1087233989Sadrian/* 1088233989Sadrian * Update the frame duration given the currently selected rate. 1089233989Sadrian * 1090233989Sadrian * This also updates the frame duration value, so it will require 1091233989Sadrian * a DMA flush. 1092233989Sadrian */ 1093233989Sadrianstatic void 1094233989Sadrianath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf) 1095233989Sadrian{ 1096233989Sadrian struct ieee80211_frame *wh; 1097233989Sadrian uint8_t rix; 1098233989Sadrian uint16_t flags; 1099233989Sadrian int shortPreamble; 1100233989Sadrian struct ath_hal *ah = sc->sc_ah; 1101233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1102233989Sadrian int isfrag = bf->bf_m->m_flags & M_FRAG; 1103233989Sadrian 1104233989Sadrian flags = bf->bf_state.bfs_txflags; 1105233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1106233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 1107233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 1108233989Sadrian 1109233989Sadrian /* 1110233989Sadrian * Calculate duration. This logically belongs in the 802.11 1111233989Sadrian * layer but it lacks sufficient information to calculate it. 1112233989Sadrian */ 1113233989Sadrian if ((flags & HAL_TXDESC_NOACK) == 0 && 1114233989Sadrian (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) { 1115233989Sadrian u_int16_t dur; 1116233989Sadrian if (shortPreamble) 1117233989Sadrian dur = rt->info[rix].spAckDuration; 1118233989Sadrian else 1119233989Sadrian dur = rt->info[rix].lpAckDuration; 1120233989Sadrian if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { 1121233989Sadrian dur += dur; /* additional SIFS+ACK */ 1122246745Sadrian KASSERT(bf->bf_m->m_nextpkt != NULL, ("no fragment")); 1123233989Sadrian /* 1124233989Sadrian * Include the size of next fragment so NAV is 1125233989Sadrian * updated properly. The last fragment uses only 1126233989Sadrian * the ACK duration 1127242144Sadrian * 1128242144Sadrian * XXX TODO: ensure that the rate lookup for each 1129242144Sadrian * fragment is the same as the rate used by the 1130242144Sadrian * first fragment! 1131233989Sadrian */ 1132233989Sadrian dur += ath_hal_computetxtime(ah, rt, 1133246745Sadrian bf->bf_m->m_nextpkt->m_pkthdr.len, 1134233989Sadrian rix, shortPreamble); 1135233989Sadrian } 1136233989Sadrian if (isfrag) { 1137233989Sadrian /* 1138233989Sadrian * Force hardware to use computed duration for next 1139233989Sadrian * fragment by disabling multi-rate retry which updates 1140233989Sadrian * duration based on the multi-rate duration table. 1141233989Sadrian */ 1142233989Sadrian bf->bf_state.bfs_ismrr = 0; 1143233989Sadrian bf->bf_state.bfs_try0 = ATH_TXMGTTRY; 1144233989Sadrian /* XXX update bfs_rc[0].try? */ 1145233989Sadrian } 1146233989Sadrian 1147233989Sadrian /* Update the duration field itself */ 1148233989Sadrian *(u_int16_t *)wh->i_dur = htole16(dur); 1149233989Sadrian } 1150233989Sadrian} 1151233989Sadrian 1152218932Sadrianstatic uint8_t 1153218932Sadrianath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt, 1154227364Sadrian int cix, int shortPreamble) 1155218157Sadrian{ 1156218932Sadrian uint8_t ctsrate; 1157218932Sadrian 1158218157Sadrian /* 1159218157Sadrian * CTS transmit rate is derived from the transmit rate 1160218157Sadrian * by looking in the h/w rate table. We must also factor 1161218157Sadrian * in whether or not a short preamble is to be used. 1162218157Sadrian */ 1163218157Sadrian /* NB: cix is set above where RTS/CTS is enabled */ 1164218157Sadrian KASSERT(cix != 0xff, ("cix not setup")); 1165218932Sadrian ctsrate = rt->info[cix].rateCode; 1166218932Sadrian 1167218932Sadrian /* XXX this should only matter for legacy rates */ 1168218932Sadrian if (shortPreamble) 1169218932Sadrian ctsrate |= rt->info[cix].shortPreamble; 1170218932Sadrian 1171229949Sadrian return (ctsrate); 1172218932Sadrian} 1173218932Sadrian 1174218932Sadrian/* 1175218932Sadrian * Calculate the RTS/CTS duration for legacy frames. 1176218932Sadrian */ 1177218932Sadrianstatic int 1178218932Sadrianath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix, 1179218932Sadrian int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt, 1180218932Sadrian int flags) 1181218932Sadrian{ 1182218932Sadrian int ctsduration = 0; 1183218932Sadrian 1184218932Sadrian /* This mustn't be called for HT modes */ 1185218932Sadrian if (rt->info[cix].phy == IEEE80211_T_HT) { 1186218932Sadrian printf("%s: HT rate where it shouldn't be (0x%x)\n", 1187218932Sadrian __func__, rt->info[cix].rateCode); 1188229949Sadrian return (-1); 1189218932Sadrian } 1190218932Sadrian 1191218157Sadrian /* 1192218157Sadrian * Compute the transmit duration based on the frame 1193218157Sadrian * size and the size of an ACK frame. We call into the 1194218157Sadrian * HAL to do the computation since it depends on the 1195218157Sadrian * characteristics of the actual PHY being used. 1196218157Sadrian * 1197218157Sadrian * NB: CTS is assumed the same size as an ACK so we can 1198218157Sadrian * use the precalculated ACK durations. 1199218157Sadrian */ 1200218157Sadrian if (shortPreamble) { 1201218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1202218932Sadrian ctsduration += rt->info[cix].spAckDuration; 1203218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1204218157Sadrian rt, pktlen, rix, AH_TRUE); 1205218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1206218932Sadrian ctsduration += rt->info[rix].spAckDuration; 1207218157Sadrian } else { 1208218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1209218932Sadrian ctsduration += rt->info[cix].lpAckDuration; 1210218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1211218157Sadrian rt, pktlen, rix, AH_FALSE); 1212218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1213218932Sadrian ctsduration += rt->info[rix].lpAckDuration; 1214218157Sadrian } 1215218932Sadrian 1216229949Sadrian return (ctsduration); 1217218157Sadrian} 1218218157Sadrian 1219227364Sadrian/* 1220227364Sadrian * Update the given ath_buf with updated rts/cts setup and duration 1221227364Sadrian * values. 1222227364Sadrian * 1223227364Sadrian * To support rate lookups for each software retry, the rts/cts rate 1224227364Sadrian * and cts duration must be re-calculated. 1225227364Sadrian * 1226227364Sadrian * This function assumes the RTS/CTS flags have been set as needed; 1227227364Sadrian * mrr has been disabled; and the rate control lookup has been done. 1228227364Sadrian * 1229227364Sadrian * XXX TODO: MRR need only be disabled for the pre-11n NICs. 1230227364Sadrian * XXX The 11n NICs support per-rate RTS/CTS configuration. 1231227364Sadrian */ 1232227364Sadrianstatic void 1233227364Sadrianath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf) 1234218065Sadrian{ 1235227364Sadrian uint16_t ctsduration = 0; 1236227364Sadrian uint8_t ctsrate = 0; 1237227364Sadrian uint8_t rix = bf->bf_state.bfs_rc[0].rix; 1238227364Sadrian uint8_t cix = 0; 1239227364Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1240227364Sadrian 1241227364Sadrian /* 1242227364Sadrian * No RTS/CTS enabled? Don't bother. 1243227364Sadrian */ 1244233966Sadrian if ((bf->bf_state.bfs_txflags & 1245227364Sadrian (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) { 1246227364Sadrian /* XXX is this really needed? */ 1247227364Sadrian bf->bf_state.bfs_ctsrate = 0; 1248227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1249227364Sadrian return; 1250227364Sadrian } 1251227364Sadrian 1252227364Sadrian /* 1253227364Sadrian * If protection is enabled, use the protection rix control 1254227364Sadrian * rate. Otherwise use the rate0 control rate. 1255227364Sadrian */ 1256227364Sadrian if (bf->bf_state.bfs_doprot) 1257227364Sadrian rix = sc->sc_protrix; 1258227364Sadrian else 1259227364Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1260227364Sadrian 1261227364Sadrian /* 1262227364Sadrian * If the raw path has hard-coded ctsrate0 to something, 1263227364Sadrian * use it. 1264227364Sadrian */ 1265227364Sadrian if (bf->bf_state.bfs_ctsrate0 != 0) 1266227364Sadrian cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0); 1267227364Sadrian else 1268227364Sadrian /* Control rate from above */ 1269227364Sadrian cix = rt->info[rix].controlRate; 1270227364Sadrian 1271227364Sadrian /* Calculate the rtscts rate for the given cix */ 1272227364Sadrian ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix, 1273227364Sadrian bf->bf_state.bfs_shpream); 1274227364Sadrian 1275227364Sadrian /* The 11n chipsets do ctsduration calculations for you */ 1276227364Sadrian if (! ath_tx_is_11n(sc)) 1277227364Sadrian ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix, 1278227364Sadrian bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen, 1279233966Sadrian rt, bf->bf_state.bfs_txflags); 1280227364Sadrian 1281227364Sadrian /* Squirrel away in ath_buf */ 1282227364Sadrian bf->bf_state.bfs_ctsrate = ctsrate; 1283227364Sadrian bf->bf_state.bfs_ctsduration = ctsduration; 1284227364Sadrian 1285227364Sadrian /* 1286227364Sadrian * Must disable multi-rate retry when using RTS/CTS. 1287227364Sadrian */ 1288238961Sadrian if (!sc->sc_mrrprot) { 1289238961Sadrian bf->bf_state.bfs_ismrr = 0; 1290238961Sadrian bf->bf_state.bfs_try0 = 1291238961Sadrian bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */ 1292238961Sadrian } 1293227364Sadrian} 1294227364Sadrian 1295227364Sadrian/* 1296227364Sadrian * Setup the descriptor chain for a normal or fast-frame 1297227364Sadrian * frame. 1298239051Sadrian * 1299239051Sadrian * XXX TODO: extend to include the destination hardware QCU ID. 1300239051Sadrian * Make sure that is correct. Make sure that when being added 1301239051Sadrian * to the mcastq, the CABQ QCUID is set or things will get a bit 1302239051Sadrian * odd. 1303227364Sadrian */ 1304227364Sadrianstatic void 1305227364Sadrianath_tx_setds(struct ath_softc *sc, struct ath_buf *bf) 1306227364Sadrian{ 1307227364Sadrian struct ath_desc *ds = bf->bf_desc; 1308227364Sadrian struct ath_hal *ah = sc->sc_ah; 1309227364Sadrian 1310242951Sadrian if (bf->bf_state.bfs_txrate0 == 0) 1311242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, txrate0=%d\n", 1312242951Sadrian __func__, bf, 0); 1313242951Sadrian 1314227364Sadrian ath_hal_setuptxdesc(ah, ds 1315227364Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 1316227364Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 1317227364Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 1318227364Sadrian , bf->bf_state.bfs_txpower /* txpower */ 1319227364Sadrian , bf->bf_state.bfs_txrate0 1320227364Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 1321227364Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 1322227364Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 1323233966Sadrian , bf->bf_state.bfs_txflags /* flags */ 1324227364Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 1325227364Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 1326227364Sadrian ); 1327227364Sadrian 1328227364Sadrian /* 1329227364Sadrian * This will be overriden when the descriptor chain is written. 1330227364Sadrian */ 1331227364Sadrian bf->bf_lastds = ds; 1332227364Sadrian bf->bf_last = bf; 1333227364Sadrian 1334238947Sadrian /* Set rate control and descriptor chain for this frame */ 1335238947Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 1336242656Sadrian ath_tx_chaindesclist(sc, ds, bf, 0, 0, 0); 1337227364Sadrian} 1338227364Sadrian 1339227364Sadrian/* 1340227364Sadrian * Do a rate lookup. 1341227364Sadrian * 1342227364Sadrian * This performs a rate lookup for the given ath_buf only if it's required. 1343227364Sadrian * Non-data frames and raw frames don't require it. 1344227364Sadrian * 1345227364Sadrian * This populates the primary and MRR entries; MRR values are 1346227364Sadrian * then disabled later on if something requires it (eg RTS/CTS on 1347227364Sadrian * pre-11n chipsets. 1348227364Sadrian * 1349227364Sadrian * This needs to be done before the RTS/CTS fields are calculated 1350227364Sadrian * as they may depend upon the rate chosen. 1351227364Sadrian */ 1352227364Sadrianstatic void 1353227364Sadrianath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf) 1354227364Sadrian{ 1355227364Sadrian uint8_t rate, rix; 1356227364Sadrian int try0; 1357227364Sadrian 1358227364Sadrian if (! bf->bf_state.bfs_doratelookup) 1359227364Sadrian return; 1360227364Sadrian 1361227364Sadrian /* Get rid of any previous state */ 1362227364Sadrian bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1363227364Sadrian 1364227364Sadrian ATH_NODE_LOCK(ATH_NODE(bf->bf_node)); 1365227364Sadrian ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream, 1366227364Sadrian bf->bf_state.bfs_pktlen, &rix, &try0, &rate); 1367227364Sadrian 1368227364Sadrian /* In case MRR is disabled, make sure rc[0] is setup correctly */ 1369227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1370227364Sadrian bf->bf_state.bfs_rc[0].ratecode = rate; 1371227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1372227364Sadrian 1373227364Sadrian if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY) 1374227364Sadrian ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix, 1375227364Sadrian bf->bf_state.bfs_rc); 1376227364Sadrian ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node)); 1377227364Sadrian 1378227364Sadrian sc->sc_txrix = rix; /* for LED blinking */ 1379227364Sadrian sc->sc_lastdatarix = rix; /* for fast frames */ 1380227364Sadrian bf->bf_state.bfs_try0 = try0; 1381227364Sadrian bf->bf_state.bfs_txrate0 = rate; 1382227364Sadrian} 1383227364Sadrian 1384227364Sadrian/* 1385240883Sadrian * Update the CLRDMASK bit in the ath_buf if it needs to be set. 1386240883Sadrian */ 1387240883Sadrianstatic void 1388240883Sadrianath_tx_update_clrdmask(struct ath_softc *sc, struct ath_tid *tid, 1389240883Sadrian struct ath_buf *bf) 1390240883Sadrian{ 1391245708Sadrian struct ath_node *an = ATH_NODE(bf->bf_node); 1392240883Sadrian 1393243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1394240883Sadrian 1395245708Sadrian if (an->clrdmask == 1) { 1396240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1397245708Sadrian an->clrdmask = 0; 1398240883Sadrian } 1399240883Sadrian} 1400240883Sadrian 1401240883Sadrian/* 1402227364Sadrian * Transmit the given frame to the hardware. 1403227364Sadrian * 1404227364Sadrian * The frame must already be setup; rate control must already have 1405227364Sadrian * been done. 1406227364Sadrian * 1407227364Sadrian * XXX since the TXQ lock is being held here (and I dislike holding 1408227364Sadrian * it for this long when not doing software aggregation), later on 1409227364Sadrian * break this function into "setup_normal" and "xmit_normal". The 1410227364Sadrian * lock only needs to be held for the ath_tx_handoff call. 1411227364Sadrian */ 1412227364Sadrianstatic void 1413227364Sadrianath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq, 1414227364Sadrian struct ath_buf *bf) 1415227364Sadrian{ 1416240883Sadrian struct ath_node *an = ATH_NODE(bf->bf_node); 1417240883Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 1418227364Sadrian 1419243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1420227364Sadrian 1421240883Sadrian /* 1422240883Sadrian * For now, just enable CLRDMASK. ath_tx_xmit_normal() does 1423240883Sadrian * set a completion handler however it doesn't (yet) properly 1424240883Sadrian * handle the strict ordering requirements needed for normal, 1425240883Sadrian * non-aggregate session frames. 1426240883Sadrian * 1427240883Sadrian * Once this is implemented, only set CLRDMASK like this for 1428240883Sadrian * frames that must go out - eg management/raw frames. 1429240883Sadrian */ 1430240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1431240883Sadrian 1432227364Sadrian /* Setup the descriptor before handoff */ 1433227364Sadrian ath_tx_do_ratelookup(sc, bf); 1434233989Sadrian ath_tx_calc_duration(sc, bf); 1435233989Sadrian ath_tx_calc_protection(sc, bf); 1436233989Sadrian ath_tx_set_rtscts(sc, bf); 1437227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 1438227364Sadrian ath_tx_setds(sc, bf); 1439227364Sadrian 1440240883Sadrian /* Track per-TID hardware queue depth correctly */ 1441240883Sadrian tid->hwq_depth++; 1442240724Sadrian 1443240883Sadrian /* Assign the completion handler */ 1444240883Sadrian bf->bf_comp = ath_tx_normal_comp; 1445240883Sadrian 1446227364Sadrian /* Hand off to hardware */ 1447227364Sadrian ath_tx_handoff(sc, txq, bf); 1448227364Sadrian} 1449227364Sadrian 1450240722Sadrian/* 1451240722Sadrian * Do the basic frame setup stuff that's required before the frame 1452240722Sadrian * is added to a software queue. 1453240722Sadrian * 1454240722Sadrian * All frames get mostly the same treatment and it's done once. 1455240722Sadrian * Retransmits fiddle with things like the rate control setup, 1456240722Sadrian * setting the retransmit bit in the packet; doing relevant DMA/bus 1457240722Sadrian * syncing and relinking it (back) into the hardware TX queue. 1458240722Sadrian * 1459240722Sadrian * Note that this may cause the mbuf to be reallocated, so 1460240722Sadrian * m0 may not be valid. 1461240722Sadrian */ 1462227364Sadrianstatic int 1463227364Sadrianath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni, 1464234009Sadrian struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq) 1465227364Sadrian{ 1466218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1467218065Sadrian struct ath_hal *ah = sc->sc_ah; 1468218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1469218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1470218065Sadrian const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; 1471218065Sadrian int error, iswep, ismcast, isfrag, ismrr; 1472227364Sadrian int keyix, hdrlen, pktlen, try0 = 0; 1473227364Sadrian u_int8_t rix = 0, txrate = 0; 1474218065Sadrian struct ath_desc *ds; 1475218065Sadrian struct ieee80211_frame *wh; 1476227364Sadrian u_int subtype, flags; 1477218065Sadrian HAL_PKT_TYPE atype; 1478218065Sadrian const HAL_RATE_TABLE *rt; 1479218065Sadrian HAL_BOOL shortPreamble; 1480218065Sadrian struct ath_node *an; 1481218065Sadrian u_int pri; 1482218065Sadrian 1483236880Sadrian /* 1484236880Sadrian * To ensure that both sequence numbers and the CCMP PN handling 1485236880Sadrian * is "correct", make sure that the relevant TID queue is locked. 1486236880Sadrian * Otherwise the CCMP PN and seqno may appear out of order, causing 1487236880Sadrian * re-ordered frames to have out of order CCMP PN's, resulting 1488236880Sadrian * in many, many frame drops. 1489236880Sadrian */ 1490243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1491236880Sadrian 1492218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1493218065Sadrian iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; 1494218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1495218065Sadrian isfrag = m0->m_flags & M_FRAG; 1496218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1497218065Sadrian /* 1498218065Sadrian * Packet length must not include any 1499218065Sadrian * pad bytes; deduct them here. 1500218065Sadrian */ 1501218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3); 1502218065Sadrian 1503218154Sadrian /* Handle encryption twiddling if needed */ 1504227364Sadrian if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen, 1505227364Sadrian &pktlen, &keyix)) { 1506218154Sadrian ath_freetx(m0); 1507218154Sadrian return EIO; 1508218154Sadrian } 1509218065Sadrian 1510218154Sadrian /* packet header may have moved, reset our local pointer */ 1511218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1512218065Sadrian 1513218065Sadrian pktlen += IEEE80211_CRC_LEN; 1514218065Sadrian 1515218065Sadrian /* 1516218065Sadrian * Load the DMA map so any coalescing is done. This 1517218065Sadrian * also calculates the number of descriptors we need. 1518218065Sadrian */ 1519218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1520218065Sadrian if (error != 0) 1521218065Sadrian return error; 1522218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1523218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1524218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1525218065Sadrian 1526218065Sadrian /* setup descriptors */ 1527218065Sadrian ds = bf->bf_desc; 1528218065Sadrian rt = sc->sc_currates; 1529218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1530218065Sadrian 1531218065Sadrian /* 1532218065Sadrian * NB: the 802.11 layer marks whether or not we should 1533218065Sadrian * use short preamble based on the current mode and 1534218065Sadrian * negotiated parameters. 1535218065Sadrian */ 1536218065Sadrian if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 1537218065Sadrian (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) { 1538218065Sadrian shortPreamble = AH_TRUE; 1539218065Sadrian sc->sc_stats.ast_tx_shortpre++; 1540218065Sadrian } else { 1541218065Sadrian shortPreamble = AH_FALSE; 1542218065Sadrian } 1543218065Sadrian 1544218065Sadrian an = ATH_NODE(ni); 1545240724Sadrian //flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1546240724Sadrian flags = 0; 1547218065Sadrian ismrr = 0; /* default no multi-rate retry*/ 1548218065Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 1549218065Sadrian /* XXX use txparams instead of fixed values */ 1550218065Sadrian /* 1551218065Sadrian * Calculate Atheros packet type from IEEE80211 packet header, 1552218065Sadrian * setup for rate calculations, and select h/w transmit queue. 1553218065Sadrian */ 1554218065Sadrian switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1555218065Sadrian case IEEE80211_FC0_TYPE_MGT: 1556218065Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1557218065Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) 1558218065Sadrian atype = HAL_PKT_TYPE_BEACON; 1559218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) 1560218065Sadrian atype = HAL_PKT_TYPE_PROBE_RESP; 1561218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) 1562218065Sadrian atype = HAL_PKT_TYPE_ATIM; 1563218065Sadrian else 1564218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* XXX */ 1565218065Sadrian rix = an->an_mgmtrix; 1566218065Sadrian txrate = rt->info[rix].rateCode; 1567218065Sadrian if (shortPreamble) 1568218065Sadrian txrate |= rt->info[rix].shortPreamble; 1569218065Sadrian try0 = ATH_TXMGTTRY; 1570218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1571218065Sadrian break; 1572218065Sadrian case IEEE80211_FC0_TYPE_CTL: 1573218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */ 1574218065Sadrian rix = an->an_mgmtrix; 1575218065Sadrian txrate = rt->info[rix].rateCode; 1576218065Sadrian if (shortPreamble) 1577218065Sadrian txrate |= rt->info[rix].shortPreamble; 1578218065Sadrian try0 = ATH_TXMGTTRY; 1579218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1580218065Sadrian break; 1581218065Sadrian case IEEE80211_FC0_TYPE_DATA: 1582218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* default */ 1583218065Sadrian /* 1584218065Sadrian * Data frames: multicast frames go out at a fixed rate, 1585218065Sadrian * EAPOL frames use the mgmt frame rate; otherwise consult 1586218065Sadrian * the rate control module for the rate to use. 1587218065Sadrian */ 1588218065Sadrian if (ismcast) { 1589218065Sadrian rix = an->an_mcastrix; 1590218065Sadrian txrate = rt->info[rix].rateCode; 1591218065Sadrian if (shortPreamble) 1592218065Sadrian txrate |= rt->info[rix].shortPreamble; 1593218065Sadrian try0 = 1; 1594218065Sadrian } else if (m0->m_flags & M_EAPOL) { 1595218065Sadrian /* XXX? maybe always use long preamble? */ 1596218065Sadrian rix = an->an_mgmtrix; 1597218065Sadrian txrate = rt->info[rix].rateCode; 1598218065Sadrian if (shortPreamble) 1599218065Sadrian txrate |= rt->info[rix].shortPreamble; 1600218065Sadrian try0 = ATH_TXMAXTRY; /* XXX?too many? */ 1601218065Sadrian } else { 1602227364Sadrian /* 1603227364Sadrian * Do rate lookup on each TX, rather than using 1604227364Sadrian * the hard-coded TX information decided here. 1605227364Sadrian */ 1606227364Sadrian ismrr = 1; 1607227364Sadrian bf->bf_state.bfs_doratelookup = 1; 1608218065Sadrian } 1609218065Sadrian if (cap->cap_wmeParams[pri].wmep_noackPolicy) 1610218065Sadrian flags |= HAL_TXDESC_NOACK; 1611218065Sadrian break; 1612218065Sadrian default: 1613218065Sadrian if_printf(ifp, "bogus frame type 0x%x (%s)\n", 1614218065Sadrian wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__); 1615218065Sadrian /* XXX statistic */ 1616218065Sadrian ath_freetx(m0); 1617218065Sadrian return EIO; 1618218065Sadrian } 1619218065Sadrian 1620237041Sadrian /* 1621237041Sadrian * There are two known scenarios where the frame AC doesn't match 1622237041Sadrian * what the destination TXQ is. 1623237041Sadrian * 1624237041Sadrian * + non-QoS frames (eg management?) that the net80211 stack has 1625237041Sadrian * assigned a higher AC to, but since it's a non-QoS TID, it's 1626237041Sadrian * being thrown into TID 16. TID 16 gets the AC_BE queue. 1627237041Sadrian * It's quite possible that management frames should just be 1628237041Sadrian * direct dispatched to hardware rather than go via the software 1629237041Sadrian * queue; that should be investigated in the future. There are 1630237041Sadrian * some specific scenarios where this doesn't make sense, mostly 1631237041Sadrian * surrounding ADDBA request/response - hence why that is special 1632237041Sadrian * cased. 1633237041Sadrian * 1634237041Sadrian * + Multicast frames going into the VAP mcast queue. That shows up 1635237041Sadrian * as "TXQ 11". 1636237041Sadrian * 1637237041Sadrian * This driver should eventually support separate TID and TXQ locking, 1638237041Sadrian * allowing for arbitrary AC frames to appear on arbitrary software 1639237041Sadrian * queues, being queued to the "correct" hardware queue when needed. 1640237041Sadrian */ 1641237041Sadrian#if 0 1642235750Sadrian if (txq != sc->sc_ac2q[pri]) { 1643235750Sadrian device_printf(sc->sc_dev, 1644235750Sadrian "%s: txq=%p (%d), pri=%d, pri txq=%p (%d)\n", 1645235750Sadrian __func__, 1646235750Sadrian txq, 1647235750Sadrian txq->axq_qnum, 1648235750Sadrian pri, 1649235750Sadrian sc->sc_ac2q[pri], 1650235750Sadrian sc->sc_ac2q[pri]->axq_qnum); 1651235750Sadrian } 1652237041Sadrian#endif 1653235750Sadrian 1654218065Sadrian /* 1655218065Sadrian * Calculate miscellaneous flags. 1656218065Sadrian */ 1657218065Sadrian if (ismcast) { 1658218065Sadrian flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ 1659218065Sadrian } else if (pktlen > vap->iv_rtsthreshold && 1660218065Sadrian (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) { 1661218065Sadrian flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ 1662218065Sadrian sc->sc_stats.ast_tx_rts++; 1663218065Sadrian } 1664218065Sadrian if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */ 1665218065Sadrian sc->sc_stats.ast_tx_noack++; 1666218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 1667218065Sadrian if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) { 1668218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA, 1669218065Sadrian "%s: discard frame, ACK required w/ TDMA\n", __func__); 1670218065Sadrian sc->sc_stats.ast_tdma_ack++; 1671218065Sadrian ath_freetx(m0); 1672218065Sadrian return EIO; 1673218065Sadrian } 1674218065Sadrian#endif 1675218065Sadrian 1676218065Sadrian /* 1677227364Sadrian * Determine if a tx interrupt should be generated for 1678227364Sadrian * this descriptor. We take a tx interrupt to reap 1679227364Sadrian * descriptors when the h/w hits an EOL condition or 1680227364Sadrian * when the descriptor is specifically marked to generate 1681227364Sadrian * an interrupt. We periodically mark descriptors in this 1682227364Sadrian * way to insure timely replenishing of the supply needed 1683227364Sadrian * for sending frames. Defering interrupts reduces system 1684227364Sadrian * load and potentially allows more concurrent work to be 1685227364Sadrian * done but if done to aggressively can cause senders to 1686227364Sadrian * backup. 1687227364Sadrian * 1688227364Sadrian * NB: use >= to deal with sc_txintrperiod changing 1689227364Sadrian * dynamically through sysctl. 1690218065Sadrian */ 1691227364Sadrian if (flags & HAL_TXDESC_INTREQ) { 1692227364Sadrian txq->axq_intrcnt = 0; 1693227364Sadrian } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) { 1694227364Sadrian flags |= HAL_TXDESC_INTREQ; 1695227364Sadrian txq->axq_intrcnt = 0; 1696227364Sadrian } 1697218932Sadrian 1698227364Sadrian /* This point forward is actual TX bits */ 1699218065Sadrian 1700218065Sadrian /* 1701218065Sadrian * At this point we are committed to sending the frame 1702218065Sadrian * and we don't need to look at m_nextpkt; clear it in 1703218065Sadrian * case this frame is part of frag chain. 1704218065Sadrian */ 1705218065Sadrian m0->m_nextpkt = NULL; 1706218065Sadrian 1707218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1708218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len, 1709218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1710218065Sadrian 1711218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1712218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1713218065Sadrian 1714218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1715218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1716218065Sadrian if (iswep) 1717218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1718218065Sadrian if (isfrag) 1719218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1720218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1721218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1722218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1723218065Sadrian 1724218065Sadrian ieee80211_radiotap_tx(vap, m0); 1725218065Sadrian } 1726218065Sadrian 1727227364Sadrian /* Blank the legacy rate array */ 1728227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1729227364Sadrian 1730218065Sadrian /* 1731227364Sadrian * ath_buf_set_rate needs at least one rate/try to setup 1732227364Sadrian * the rate scenario. 1733227364Sadrian */ 1734227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1735227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1736227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1737227364Sadrian 1738227364Sadrian /* Store the decided rate index values away */ 1739227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1740227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1741227364Sadrian bf->bf_state.bfs_atype = atype; 1742227364Sadrian bf->bf_state.bfs_txpower = ni->ni_txpower; 1743227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1744227364Sadrian bf->bf_state.bfs_try0 = try0; 1745227364Sadrian bf->bf_state.bfs_keyix = keyix; 1746227364Sadrian bf->bf_state.bfs_txantenna = sc->sc_txantenna; 1747233966Sadrian bf->bf_state.bfs_txflags = flags; 1748227364Sadrian bf->bf_state.bfs_shpream = shortPreamble; 1749227364Sadrian 1750227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1751227364Sadrian bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */ 1752227364Sadrian bf->bf_state.bfs_ctsrate = 0; /* calculated later */ 1753227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1754227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1755227364Sadrian 1756227364Sadrian return 0; 1757227364Sadrian} 1758227364Sadrian 1759227364Sadrian/* 1760240724Sadrian * Queue a frame to the hardware or software queue. 1761227364Sadrian * 1762227364Sadrian * This can be called by the net80211 code. 1763227364Sadrian * 1764227364Sadrian * XXX what about locking? Or, push the seqno assign into the 1765227364Sadrian * XXX aggregate scheduler so its serialised? 1766240724Sadrian * 1767240724Sadrian * XXX When sending management frames via ath_raw_xmit(), 1768240724Sadrian * should CLRDMASK be set unconditionally? 1769227364Sadrian */ 1770227364Sadrianint 1771227364Sadrianath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, 1772227364Sadrian struct ath_buf *bf, struct mbuf *m0) 1773227364Sadrian{ 1774227364Sadrian struct ieee80211vap *vap = ni->ni_vap; 1775227364Sadrian struct ath_vap *avp = ATH_VAP(vap); 1776232764Sadrian int r = 0; 1777227364Sadrian u_int pri; 1778227364Sadrian int tid; 1779227364Sadrian struct ath_txq *txq; 1780227364Sadrian int ismcast; 1781227364Sadrian const struct ieee80211_frame *wh; 1782227364Sadrian int is_ampdu, is_ampdu_tx, is_ampdu_pending; 1783236872Sadrian ieee80211_seq seqno; 1784227364Sadrian uint8_t type, subtype; 1785227364Sadrian 1786243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1787243786Sadrian 1788227364Sadrian /* 1789227364Sadrian * Determine the target hardware queue. 1790218065Sadrian * 1791234009Sadrian * For multicast frames, the txq gets overridden appropriately 1792234009Sadrian * depending upon the state of PS. 1793227364Sadrian * 1794227364Sadrian * For any other frame, we do a TID/QoS lookup inside the frame 1795227364Sadrian * to see what the TID should be. If it's a non-QoS frame, the 1796227364Sadrian * AC and TID are overridden. The TID/TXQ code assumes the 1797227364Sadrian * TID is on a predictable hardware TXQ, so we don't support 1798227364Sadrian * having a node TID queued to multiple hardware TXQs. 1799227364Sadrian * This may change in the future but would require some locking 1800227364Sadrian * fudgery. 1801218065Sadrian */ 1802227364Sadrian pri = ath_tx_getac(sc, m0); 1803227364Sadrian tid = ath_tx_gettid(sc, m0); 1804218065Sadrian 1805227364Sadrian txq = sc->sc_ac2q[pri]; 1806227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 1807227364Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1808227364Sadrian type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 1809227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1810227364Sadrian 1811232764Sadrian /* 1812232764Sadrian * Enforce how deep the multicast queue can grow. 1813232764Sadrian * 1814232764Sadrian * XXX duplicated in ath_raw_xmit(). 1815232764Sadrian */ 1816232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1817232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 1818232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 1819232764Sadrian r = ENOBUFS; 1820232764Sadrian } 1821232764Sadrian if (r != 0) { 1822232764Sadrian m_freem(m0); 1823232764Sadrian return r; 1824232764Sadrian } 1825232764Sadrian } 1826232764Sadrian 1827227364Sadrian /* A-MPDU TX */ 1828227364Sadrian is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid); 1829227364Sadrian is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid); 1830227364Sadrian is_ampdu = is_ampdu_tx | is_ampdu_pending; 1831227364Sadrian 1832236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ac=%d, is_ampdu=%d\n", 1833236872Sadrian __func__, tid, pri, is_ampdu); 1834227364Sadrian 1835239051Sadrian /* Set local packet state, used to queue packets to hardware */ 1836239051Sadrian bf->bf_state.bfs_tid = tid; 1837244109Sadrian bf->bf_state.bfs_tx_queue = txq->axq_qnum; 1838239051Sadrian bf->bf_state.bfs_pri = pri; 1839239051Sadrian 1840232753Sadrian /* 1841234009Sadrian * When servicing one or more stations in power-save mode 1842234009Sadrian * (or) if there is some mcast data waiting on the mcast 1843234009Sadrian * queue (to prevent out of order delivery) multicast frames 1844234009Sadrian * must be bufferd until after the beacon. 1845234009Sadrian * 1846234009Sadrian * TODO: we should lock the mcastq before we check the length. 1847232753Sadrian */ 1848239051Sadrian if (ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) { 1849227364Sadrian txq = &avp->av_mcastq; 1850239051Sadrian /* 1851239051Sadrian * Mark the frame as eventually belonging on the CAB 1852239051Sadrian * queue, so the descriptor setup functions will 1853239051Sadrian * correctly initialise the descriptor 'qcuId' field. 1854239051Sadrian */ 1855244109Sadrian bf->bf_state.bfs_tx_queue = sc->sc_cabq->axq_qnum; 1856239051Sadrian } 1857227364Sadrian 1858227364Sadrian /* Do the generic frame setup */ 1859227364Sadrian /* XXX should just bzero the bf_state? */ 1860227364Sadrian bf->bf_state.bfs_dobaw = 0; 1861227364Sadrian 1862227364Sadrian /* A-MPDU TX? Manually set sequence number */ 1863236880Sadrian /* 1864236880Sadrian * Don't do it whilst pending; the net80211 layer still 1865236880Sadrian * assigns them. 1866236880Sadrian */ 1867227364Sadrian if (is_ampdu_tx) { 1868227364Sadrian /* 1869227364Sadrian * Always call; this function will 1870227364Sadrian * handle making sure that null data frames 1871227364Sadrian * don't get a sequence number from the current 1872227364Sadrian * TID and thus mess with the BAW. 1873227364Sadrian */ 1874236872Sadrian seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0); 1875236874Sadrian 1876236874Sadrian /* 1877236874Sadrian * Don't add QoS NULL frames to the BAW. 1878236874Sadrian */ 1879236872Sadrian if (IEEE80211_QOS_HAS_SEQ(wh) && 1880236872Sadrian subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL) { 1881227364Sadrian bf->bf_state.bfs_dobaw = 1; 1882227364Sadrian } 1883218240Sadrian } 1884218240Sadrian 1885218065Sadrian /* 1886227364Sadrian * If needed, the sequence number has been assigned. 1887227364Sadrian * Squirrel it away somewhere easy to get to. 1888218065Sadrian */ 1889236872Sadrian bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1890227364Sadrian 1891227364Sadrian /* Is ampdu pending? fetch the seqno and print it out */ 1892227364Sadrian if (is_ampdu_pending) 1893227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1894227364Sadrian "%s: tid %d: ampdu pending, seqno %d\n", 1895227364Sadrian __func__, tid, M_SEQNO_GET(m0)); 1896227364Sadrian 1897227364Sadrian /* This also sets up the DMA map */ 1898234009Sadrian r = ath_tx_normal_setup(sc, ni, bf, m0, txq); 1899227364Sadrian 1900227364Sadrian if (r != 0) 1901236880Sadrian goto done; 1902227364Sadrian 1903227364Sadrian /* At this point m0 could have changed! */ 1904227364Sadrian m0 = bf->bf_m; 1905227364Sadrian 1906227364Sadrian#if 1 1907218065Sadrian /* 1908227364Sadrian * If it's a multicast frame, do a direct-dispatch to the 1909227364Sadrian * destination hardware queue. Don't bother software 1910227364Sadrian * queuing it. 1911218065Sadrian */ 1912227364Sadrian /* 1913227364Sadrian * If it's a BAR frame, do a direct dispatch to the 1914227364Sadrian * destination hardware queue. Don't bother software 1915227364Sadrian * queuing it, as the TID will now be paused. 1916227364Sadrian * Sending a BAR frame can occur from the net80211 txa timer 1917227364Sadrian * (ie, retries) or from the ath txtask (completion call.) 1918227364Sadrian * It queues directly to hardware because the TID is paused 1919227364Sadrian * at this point (and won't be unpaused until the BAR has 1920227364Sadrian * either been TXed successfully or max retries has been 1921227364Sadrian * reached.) 1922227364Sadrian */ 1923227364Sadrian if (txq == &avp->av_mcastq) { 1924235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1925233227Sadrian "%s: bf=%p: mcastq: TX'ing\n", __func__, bf); 1926240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1927227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1928227364Sadrian } else if (type == IEEE80211_FC0_TYPE_CTL && 1929227364Sadrian subtype == IEEE80211_FC0_SUBTYPE_BAR) { 1930235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1931227364Sadrian "%s: BAR: TX'ing direct\n", __func__); 1932240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1933227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1934227364Sadrian } else { 1935227364Sadrian /* add to software queue */ 1936235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1937233227Sadrian "%s: bf=%p: swq: TX'ing\n", __func__, bf); 1938227364Sadrian ath_tx_swq(sc, ni, txq, bf); 1939227364Sadrian } 1940227364Sadrian#else 1941227364Sadrian /* 1942227364Sadrian * For now, since there's no software queue, 1943227364Sadrian * direct-dispatch to the hardware. 1944227364Sadrian */ 1945240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1946227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1947236880Sadrian#endif 1948236880Sadriandone: 1949218065Sadrian return 0; 1950218065Sadrian} 1951218065Sadrian 1952218065Sadrianstatic int 1953218065Sadrianath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni, 1954218065Sadrian struct ath_buf *bf, struct mbuf *m0, 1955218065Sadrian const struct ieee80211_bpf_params *params) 1956218065Sadrian{ 1957218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1958218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1959218065Sadrian struct ath_hal *ah = sc->sc_ah; 1960218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1961218065Sadrian int error, ismcast, ismrr; 1962218065Sadrian int keyix, hdrlen, pktlen, try0, txantenna; 1963227364Sadrian u_int8_t rix, txrate; 1964218065Sadrian struct ieee80211_frame *wh; 1965227364Sadrian u_int flags; 1966218065Sadrian HAL_PKT_TYPE atype; 1967218065Sadrian const HAL_RATE_TABLE *rt; 1968218065Sadrian struct ath_desc *ds; 1969218065Sadrian u_int pri; 1970227364Sadrian int o_tid = -1; 1971227364Sadrian int do_override; 1972218065Sadrian 1973243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1974243786Sadrian 1975218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1976218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1977218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1978218065Sadrian /* 1979218065Sadrian * Packet length must not include any 1980218065Sadrian * pad bytes; deduct them here. 1981218065Sadrian */ 1982218065Sadrian /* XXX honor IEEE80211_BPF_DATAPAD */ 1983218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; 1984218065Sadrian 1985240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 2, 1986240899Sadrian "ath_tx_raw_start: ni=%p, bf=%p, raw", ni, bf); 1987240899Sadrian 1988227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n", 1989227364Sadrian __func__, ismcast); 1990227364Sadrian 1991236880Sadrian pri = params->ibp_pri & 3; 1992236880Sadrian /* Override pri if the frame isn't a QoS one */ 1993236880Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 1994236880Sadrian pri = ath_tx_getac(sc, m0); 1995236880Sadrian 1996236880Sadrian /* XXX If it's an ADDBA, override the correct queue */ 1997236880Sadrian do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid); 1998236880Sadrian 1999236880Sadrian /* Map ADDBA to the correct priority */ 2000236880Sadrian if (do_override) { 2001236880Sadrian#if 0 2002236880Sadrian device_printf(sc->sc_dev, 2003236880Sadrian "%s: overriding tid %d pri %d -> %d\n", 2004236880Sadrian __func__, o_tid, pri, TID_TO_WME_AC(o_tid)); 2005236880Sadrian#endif 2006236880Sadrian pri = TID_TO_WME_AC(o_tid); 2007236880Sadrian } 2008236880Sadrian 2009218154Sadrian /* Handle encryption twiddling if needed */ 2010227364Sadrian if (! ath_tx_tag_crypto(sc, ni, 2011227364Sadrian m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0, 2012227364Sadrian &hdrlen, &pktlen, &keyix)) { 2013218154Sadrian ath_freetx(m0); 2014218154Sadrian return EIO; 2015218154Sadrian } 2016218154Sadrian /* packet header may have moved, reset our local pointer */ 2017218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 2018218065Sadrian 2019227364Sadrian /* Do the generic frame setup */ 2020227364Sadrian /* XXX should just bzero the bf_state? */ 2021227364Sadrian bf->bf_state.bfs_dobaw = 0; 2022227364Sadrian 2023218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 2024218065Sadrian if (error != 0) 2025218065Sadrian return error; 2026218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 2027218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 2028218065Sadrian bf->bf_node = ni; /* NB: held reference */ 2029218065Sadrian 2030240724Sadrian /* Always enable CLRDMASK for raw frames for now.. */ 2031218065Sadrian flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 2032218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 2033218065Sadrian if (params->ibp_flags & IEEE80211_BPF_RTS) 2034218065Sadrian flags |= HAL_TXDESC_RTSENA; 2035227364Sadrian else if (params->ibp_flags & IEEE80211_BPF_CTS) { 2036227364Sadrian /* XXX assume 11g/11n protection? */ 2037227364Sadrian bf->bf_state.bfs_doprot = 1; 2038218065Sadrian flags |= HAL_TXDESC_CTSENA; 2039227364Sadrian } 2040218065Sadrian /* XXX leave ismcast to injector? */ 2041218065Sadrian if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast) 2042218065Sadrian flags |= HAL_TXDESC_NOACK; 2043218065Sadrian 2044218065Sadrian rt = sc->sc_currates; 2045218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 2046218065Sadrian rix = ath_tx_findrix(sc, params->ibp_rate0); 2047218065Sadrian txrate = rt->info[rix].rateCode; 2048218065Sadrian if (params->ibp_flags & IEEE80211_BPF_SHORTPRE) 2049218065Sadrian txrate |= rt->info[rix].shortPreamble; 2050218065Sadrian sc->sc_txrix = rix; 2051218065Sadrian try0 = params->ibp_try0; 2052218065Sadrian ismrr = (params->ibp_try1 != 0); 2053218065Sadrian txantenna = params->ibp_pri >> 2; 2054218065Sadrian if (txantenna == 0) /* XXX? */ 2055218065Sadrian txantenna = sc->sc_txantenna; 2056218157Sadrian 2057227364Sadrian /* 2058227364Sadrian * Since ctsrate is fixed, store it away for later 2059227364Sadrian * use when the descriptor fields are being set. 2060227364Sadrian */ 2061227364Sadrian if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) 2062227364Sadrian bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate; 2063218157Sadrian 2064218065Sadrian /* 2065218065Sadrian * NB: we mark all packets as type PSPOLL so the h/w won't 2066218065Sadrian * set the sequence number, duration, etc. 2067218065Sadrian */ 2068218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; 2069218065Sadrian 2070218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 2071218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len, 2072218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 2073218065Sadrian 2074218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 2075218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 2076218065Sadrian 2077218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 2078218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 2079218065Sadrian if (wh->i_fc[1] & IEEE80211_FC1_WEP) 2080218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 2081218065Sadrian if (m0->m_flags & M_FRAG) 2082218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 2083218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 2084218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 2085218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 2086218065Sadrian 2087218065Sadrian ieee80211_radiotap_tx(vap, m0); 2088218065Sadrian } 2089218065Sadrian 2090218065Sadrian /* 2091218065Sadrian * Formulate first tx descriptor with tx controls. 2092218065Sadrian */ 2093218065Sadrian ds = bf->bf_desc; 2094218065Sadrian /* XXX check return value? */ 2095227364Sadrian 2096227364Sadrian /* Store the decided rate index values away */ 2097227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 2098227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 2099227364Sadrian bf->bf_state.bfs_atype = atype; 2100227364Sadrian bf->bf_state.bfs_txpower = params->ibp_power; 2101227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 2102227364Sadrian bf->bf_state.bfs_try0 = try0; 2103227364Sadrian bf->bf_state.bfs_keyix = keyix; 2104227364Sadrian bf->bf_state.bfs_txantenna = txantenna; 2105233966Sadrian bf->bf_state.bfs_txflags = flags; 2106227364Sadrian bf->bf_state.bfs_shpream = 2107227364Sadrian !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE); 2108218065Sadrian 2109239051Sadrian /* Set local packet state, used to queue packets to hardware */ 2110239051Sadrian bf->bf_state.bfs_tid = WME_AC_TO_TID(pri); 2111244109Sadrian bf->bf_state.bfs_tx_queue = sc->sc_ac2q[pri]->axq_qnum; 2112239051Sadrian bf->bf_state.bfs_pri = pri; 2113239051Sadrian 2114227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 2115227364Sadrian bf->bf_state.bfs_ctsrate = 0; 2116227364Sadrian bf->bf_state.bfs_ctsduration = 0; 2117227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 2118218240Sadrian 2119227364Sadrian /* Blank the legacy rate array */ 2120227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 2121218240Sadrian 2122227364Sadrian bf->bf_state.bfs_rc[0].rix = 2123227364Sadrian ath_tx_findrix(sc, params->ibp_rate0); 2124227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 2125227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 2126227364Sadrian 2127227364Sadrian if (ismrr) { 2128227364Sadrian int rix; 2129227364Sadrian 2130227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate1); 2131227364Sadrian bf->bf_state.bfs_rc[1].rix = rix; 2132227364Sadrian bf->bf_state.bfs_rc[1].tries = params->ibp_try1; 2133227364Sadrian 2134227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate2); 2135227364Sadrian bf->bf_state.bfs_rc[2].rix = rix; 2136227364Sadrian bf->bf_state.bfs_rc[2].tries = params->ibp_try2; 2137227364Sadrian 2138227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate3); 2139227364Sadrian bf->bf_state.bfs_rc[3].rix = rix; 2140227364Sadrian bf->bf_state.bfs_rc[3].tries = params->ibp_try3; 2141218065Sadrian } 2142227364Sadrian /* 2143227364Sadrian * All the required rate control decisions have been made; 2144227364Sadrian * fill in the rc flags. 2145227364Sadrian */ 2146227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2147218065Sadrian 2148227364Sadrian /* NB: no buffered multicast in power save support */ 2149227364Sadrian 2150227364Sadrian /* 2151227364Sadrian * If we're overiding the ADDBA destination, dump directly 2152227364Sadrian * into the hardware queue, right after any pending 2153227364Sadrian * frames to that node are. 2154227364Sadrian */ 2155227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n", 2156227364Sadrian __func__, do_override); 2157227364Sadrian 2158240882Sadrian#if 1 2159227364Sadrian if (do_override) { 2160240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2161227364Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2162227364Sadrian } else { 2163227364Sadrian /* Queue to software queue */ 2164227364Sadrian ath_tx_swq(sc, ni, sc->sc_ac2q[pri], bf); 2165227364Sadrian } 2166240882Sadrian#else 2167240882Sadrian /* Direct-dispatch to the hardware */ 2168240882Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2169240882Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2170240882Sadrian#endif 2171218065Sadrian return 0; 2172218065Sadrian} 2173218065Sadrian 2174227364Sadrian/* 2175227364Sadrian * Send a raw frame. 2176227364Sadrian * 2177227364Sadrian * This can be called by net80211. 2178227364Sadrian */ 2179218065Sadrianint 2180218065Sadrianath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 2181218065Sadrian const struct ieee80211_bpf_params *params) 2182218065Sadrian{ 2183218065Sadrian struct ieee80211com *ic = ni->ni_ic; 2184218065Sadrian struct ifnet *ifp = ic->ic_ifp; 2185218065Sadrian struct ath_softc *sc = ifp->if_softc; 2186218065Sadrian struct ath_buf *bf; 2187232764Sadrian struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 2188232764Sadrian int error = 0; 2189218065Sadrian 2190227651Sadrian ATH_PCU_LOCK(sc); 2191227651Sadrian if (sc->sc_inreset_cnt > 0) { 2192227651Sadrian device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; bailing\n", 2193227651Sadrian __func__); 2194227651Sadrian error = EIO; 2195227651Sadrian ATH_PCU_UNLOCK(sc); 2196227651Sadrian goto bad0; 2197227651Sadrian } 2198227651Sadrian sc->sc_txstart_cnt++; 2199227651Sadrian ATH_PCU_UNLOCK(sc); 2200227651Sadrian 2201242391Sadrian ATH_TX_LOCK(sc); 2202242391Sadrian 2203218065Sadrian if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) { 2204218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__, 2205218065Sadrian (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ? 2206218065Sadrian "!running" : "invalid"); 2207218065Sadrian m_freem(m); 2208218065Sadrian error = ENETDOWN; 2209218065Sadrian goto bad; 2210218065Sadrian } 2211232764Sadrian 2212218065Sadrian /* 2213232764Sadrian * Enforce how deep the multicast queue can grow. 2214232764Sadrian * 2215232764Sadrian * XXX duplicated in ath_tx_start(). 2216232764Sadrian */ 2217232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 2218232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 2219232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 2220232764Sadrian error = ENOBUFS; 2221232764Sadrian } 2222232764Sadrian 2223232764Sadrian if (error != 0) { 2224232764Sadrian m_freem(m); 2225232764Sadrian goto bad; 2226232764Sadrian } 2227232764Sadrian } 2228232764Sadrian 2229232764Sadrian /* 2230218065Sadrian * Grab a TX buffer and associated resources. 2231218065Sadrian */ 2232237000Sadrian bf = ath_getbuf(sc, ATH_BUFTYPE_MGMT); 2233218065Sadrian if (bf == NULL) { 2234218065Sadrian sc->sc_stats.ast_tx_nobuf++; 2235218065Sadrian m_freem(m); 2236218065Sadrian error = ENOBUFS; 2237218065Sadrian goto bad; 2238218065Sadrian } 2239240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: m=%p, params=%p, bf=%p\n", 2240240899Sadrian m, params, bf); 2241218065Sadrian 2242218065Sadrian if (params == NULL) { 2243218065Sadrian /* 2244218065Sadrian * Legacy path; interpret frame contents to decide 2245218065Sadrian * precisely how to send the frame. 2246218065Sadrian */ 2247218065Sadrian if (ath_tx_start(sc, ni, bf, m)) { 2248218065Sadrian error = EIO; /* XXX */ 2249218065Sadrian goto bad2; 2250218065Sadrian } 2251218065Sadrian } else { 2252218065Sadrian /* 2253218065Sadrian * Caller supplied explicit parameters to use in 2254218065Sadrian * sending the frame. 2255218065Sadrian */ 2256218065Sadrian if (ath_tx_raw_start(sc, ni, bf, m, params)) { 2257218065Sadrian error = EIO; /* XXX */ 2258218065Sadrian goto bad2; 2259218065Sadrian } 2260218065Sadrian } 2261218065Sadrian sc->sc_wd_timer = 5; 2262218065Sadrian ifp->if_opackets++; 2263218065Sadrian sc->sc_stats.ast_tx_raw++; 2264218065Sadrian 2265242271Sadrian /* 2266242271Sadrian * Update the TIM - if there's anything queued to the 2267242271Sadrian * software queue and power save is enabled, we should 2268242271Sadrian * set the TIM. 2269242271Sadrian */ 2270242271Sadrian ath_tx_update_tim(sc, ni, 1); 2271242271Sadrian 2272243787Sadrian ATH_TX_UNLOCK(sc); 2273243787Sadrian 2274227651Sadrian ATH_PCU_LOCK(sc); 2275227651Sadrian sc->sc_txstart_cnt--; 2276227651Sadrian ATH_PCU_UNLOCK(sc); 2277227651Sadrian 2278218065Sadrian return 0; 2279218065Sadrianbad2: 2280240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: bad2: m=%p, params=%p, " 2281240899Sadrian "bf=%p", 2282240899Sadrian m, 2283240899Sadrian params, 2284240899Sadrian bf); 2285218065Sadrian ATH_TXBUF_LOCK(sc); 2286236993Sadrian ath_returnbuf_head(sc, bf); 2287218065Sadrian ATH_TXBUF_UNLOCK(sc); 2288218065Sadrianbad: 2289242391Sadrian 2290242391Sadrian ATH_TX_UNLOCK(sc); 2291242391Sadrian 2292227651Sadrian ATH_PCU_LOCK(sc); 2293227651Sadrian sc->sc_txstart_cnt--; 2294227651Sadrian ATH_PCU_UNLOCK(sc); 2295227651Sadrianbad0: 2296240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 2, "ath_raw_xmit: bad0: m=%p, params=%p", 2297240899Sadrian m, params); 2298218065Sadrian ifp->if_oerrors++; 2299218065Sadrian sc->sc_stats.ast_tx_raw_fail++; 2300218065Sadrian ieee80211_free_node(ni); 2301227651Sadrian 2302218065Sadrian return error; 2303218065Sadrian} 2304227364Sadrian 2305227364Sadrian/* Some helper functions */ 2306227364Sadrian 2307227364Sadrian/* 2308227364Sadrian * ADDBA (and potentially others) need to be placed in the same 2309227364Sadrian * hardware queue as the TID/node it's relating to. This is so 2310227364Sadrian * it goes out after any pending non-aggregate frames to the 2311227364Sadrian * same node/TID. 2312227364Sadrian * 2313227364Sadrian * If this isn't done, the ADDBA can go out before the frames 2314227364Sadrian * queued in hardware. Even though these frames have a sequence 2315227364Sadrian * number -earlier- than the ADDBA can be transmitted (but 2316227364Sadrian * no frames whose sequence numbers are after the ADDBA should 2317227364Sadrian * be!) they'll arrive after the ADDBA - and the receiving end 2318227364Sadrian * will simply drop them as being out of the BAW. 2319227364Sadrian * 2320227364Sadrian * The frames can't be appended to the TID software queue - it'll 2321227364Sadrian * never be sent out. So these frames have to be directly 2322227364Sadrian * dispatched to the hardware, rather than queued in software. 2323227364Sadrian * So if this function returns true, the TXQ has to be 2324227364Sadrian * overridden and it has to be directly dispatched. 2325227364Sadrian * 2326227364Sadrian * It's a dirty hack, but someone's gotta do it. 2327227364Sadrian */ 2328227364Sadrian 2329227364Sadrian/* 2330227364Sadrian * XXX doesn't belong here! 2331227364Sadrian */ 2332227364Sadrianstatic int 2333227364Sadrianieee80211_is_action(struct ieee80211_frame *wh) 2334227364Sadrian{ 2335227364Sadrian /* Type: Management frame? */ 2336227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != 2337227364Sadrian IEEE80211_FC0_TYPE_MGT) 2338227364Sadrian return 0; 2339227364Sadrian 2340227364Sadrian /* Subtype: Action frame? */ 2341227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) != 2342227364Sadrian IEEE80211_FC0_SUBTYPE_ACTION) 2343227364Sadrian return 0; 2344227364Sadrian 2345227364Sadrian return 1; 2346227364Sadrian} 2347227364Sadrian 2348227364Sadrian#define MS(_v, _f) (((_v) & _f) >> _f##_S) 2349227364Sadrian/* 2350227364Sadrian * Return an alternate TID for ADDBA request frames. 2351227364Sadrian * 2352227364Sadrian * Yes, this likely should be done in the net80211 layer. 2353227364Sadrian */ 2354227364Sadrianstatic int 2355227364Sadrianath_tx_action_frame_override_queue(struct ath_softc *sc, 2356227364Sadrian struct ieee80211_node *ni, 2357227364Sadrian struct mbuf *m0, int *tid) 2358227364Sadrian{ 2359227364Sadrian struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *); 2360227364Sadrian struct ieee80211_action_ba_addbarequest *ia; 2361227364Sadrian uint8_t *frm; 2362227364Sadrian uint16_t baparamset; 2363227364Sadrian 2364227364Sadrian /* Not action frame? Bail */ 2365227364Sadrian if (! ieee80211_is_action(wh)) 2366227364Sadrian return 0; 2367227364Sadrian 2368227364Sadrian /* XXX Not needed for frames we send? */ 2369227364Sadrian#if 0 2370227364Sadrian /* Correct length? */ 2371227364Sadrian if (! ieee80211_parse_action(ni, m)) 2372227364Sadrian return 0; 2373227364Sadrian#endif 2374227364Sadrian 2375227364Sadrian /* Extract out action frame */ 2376227364Sadrian frm = (u_int8_t *)&wh[1]; 2377227364Sadrian ia = (struct ieee80211_action_ba_addbarequest *) frm; 2378227364Sadrian 2379227364Sadrian /* Not ADDBA? Bail */ 2380227364Sadrian if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA) 2381227364Sadrian return 0; 2382227364Sadrian if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST) 2383227364Sadrian return 0; 2384227364Sadrian 2385227364Sadrian /* Extract TID, return it */ 2386227364Sadrian baparamset = le16toh(ia->rq_baparamset); 2387227364Sadrian *tid = (int) MS(baparamset, IEEE80211_BAPS_TID); 2388227364Sadrian 2389227364Sadrian return 1; 2390227364Sadrian} 2391227364Sadrian#undef MS 2392227364Sadrian 2393227364Sadrian/* Per-node software queue operations */ 2394227364Sadrian 2395227364Sadrian/* 2396227364Sadrian * Add the current packet to the given BAW. 2397227364Sadrian * It is assumed that the current packet 2398227364Sadrian * 2399227364Sadrian * + fits inside the BAW; 2400227364Sadrian * + already has had a sequence number allocated. 2401227364Sadrian * 2402227364Sadrian * Since the BAW status may be modified by both the ath task and 2403227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2404227364Sadrian */ 2405227364Sadrianvoid 2406227364Sadrianath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an, 2407227364Sadrian struct ath_tid *tid, struct ath_buf *bf) 2408227364Sadrian{ 2409227364Sadrian int index, cindex; 2410227364Sadrian struct ieee80211_tx_ampdu *tap; 2411227364Sadrian 2412243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2413227364Sadrian 2414227364Sadrian if (bf->bf_state.bfs_isretried) 2415227364Sadrian return; 2416227364Sadrian 2417236886Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2418236886Sadrian 2419236880Sadrian if (! bf->bf_state.bfs_dobaw) { 2420236880Sadrian device_printf(sc->sc_dev, 2421236880Sadrian "%s: dobaw=0, seqno=%d, window %d:%d\n", 2422236880Sadrian __func__, 2423236880Sadrian SEQNO(bf->bf_state.bfs_seqno), 2424236880Sadrian tap->txa_start, 2425236880Sadrian tap->txa_wnd); 2426236880Sadrian } 2427236880Sadrian 2428227364Sadrian if (bf->bf_state.bfs_addedbaw) 2429227364Sadrian device_printf(sc->sc_dev, 2430236872Sadrian "%s: re-added? tid=%d, seqno %d; window %d:%d; " 2431229949Sadrian "baw head=%d tail=%d\n", 2432236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2433229949Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2434229949Sadrian tid->baw_tail); 2435227364Sadrian 2436227364Sadrian /* 2437236880Sadrian * Verify that the given sequence number is not outside of the 2438236880Sadrian * BAW. Complain loudly if that's the case. 2439236880Sadrian */ 2440236880Sadrian if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2441236880Sadrian SEQNO(bf->bf_state.bfs_seqno))) { 2442236880Sadrian device_printf(sc->sc_dev, 2443236880Sadrian "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; " 2444236880Sadrian "baw head=%d tail=%d\n", 2445236880Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2446236880Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2447236880Sadrian tid->baw_tail); 2448236880Sadrian } 2449236880Sadrian 2450236880Sadrian /* 2451227364Sadrian * ni->ni_txseqs[] is the currently allocated seqno. 2452227364Sadrian * the txa state contains the current baw start. 2453227364Sadrian */ 2454227364Sadrian index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno)); 2455227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2456227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2457236872Sadrian "%s: tid=%d, seqno %d; window %d:%d; index=%d cindex=%d " 2458229949Sadrian "baw head=%d tail=%d\n", 2459236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2460229949Sadrian tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head, 2461229949Sadrian tid->baw_tail); 2462227364Sadrian 2463227364Sadrian 2464227364Sadrian#if 0 2465227364Sadrian assert(tid->tx_buf[cindex] == NULL); 2466227364Sadrian#endif 2467227364Sadrian if (tid->tx_buf[cindex] != NULL) { 2468227364Sadrian device_printf(sc->sc_dev, 2469227364Sadrian "%s: ba packet dup (index=%d, cindex=%d, " 2470227364Sadrian "head=%d, tail=%d)\n", 2471227364Sadrian __func__, index, cindex, tid->baw_head, tid->baw_tail); 2472227364Sadrian device_printf(sc->sc_dev, 2473227364Sadrian "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n", 2474227364Sadrian __func__, 2475227364Sadrian tid->tx_buf[cindex], 2476227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno), 2477227364Sadrian bf, 2478227364Sadrian SEQNO(bf->bf_state.bfs_seqno) 2479227364Sadrian ); 2480227364Sadrian } 2481227364Sadrian tid->tx_buf[cindex] = bf; 2482227364Sadrian 2483229949Sadrian if (index >= ((tid->baw_tail - tid->baw_head) & 2484229949Sadrian (ATH_TID_MAX_BUFS - 1))) { 2485227364Sadrian tid->baw_tail = cindex; 2486227364Sadrian INCR(tid->baw_tail, ATH_TID_MAX_BUFS); 2487227364Sadrian } 2488227364Sadrian} 2489227364Sadrian 2490227364Sadrian/* 2491227398Sadrian * Flip the BAW buffer entry over from the existing one to the new one. 2492227398Sadrian * 2493227398Sadrian * When software retransmitting a (sub-)frame, it is entirely possible that 2494227398Sadrian * the frame ath_buf is marked as BUSY and can't be immediately reused. 2495227398Sadrian * In that instance the buffer is cloned and the new buffer is used for 2496227398Sadrian * retransmit. We thus need to update the ath_buf slot in the BAW buf 2497227398Sadrian * tracking array to maintain consistency. 2498227398Sadrian */ 2499227398Sadrianstatic void 2500227398Sadrianath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an, 2501227398Sadrian struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf) 2502227398Sadrian{ 2503227398Sadrian int index, cindex; 2504227398Sadrian struct ieee80211_tx_ampdu *tap; 2505227398Sadrian int seqno = SEQNO(old_bf->bf_state.bfs_seqno); 2506227398Sadrian 2507243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2508227398Sadrian 2509227398Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2510227398Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2511227398Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2512227398Sadrian 2513227398Sadrian /* 2514227398Sadrian * Just warn for now; if it happens then we should find out 2515227398Sadrian * about it. It's highly likely the aggregation session will 2516227398Sadrian * soon hang. 2517227398Sadrian */ 2518227398Sadrian if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) { 2519227398Sadrian device_printf(sc->sc_dev, "%s: retransmitted buffer" 2520227398Sadrian " has mismatching seqno's, BA session may hang.\n", 2521227398Sadrian __func__); 2522227398Sadrian device_printf(sc->sc_dev, "%s: old seqno=%d, new_seqno=%d\n", 2523227398Sadrian __func__, 2524227398Sadrian old_bf->bf_state.bfs_seqno, 2525227398Sadrian new_bf->bf_state.bfs_seqno); 2526227398Sadrian } 2527227398Sadrian 2528227398Sadrian if (tid->tx_buf[cindex] != old_bf) { 2529227398Sadrian device_printf(sc->sc_dev, "%s: ath_buf pointer incorrect; " 2530227398Sadrian " has m BA session may hang.\n", 2531227398Sadrian __func__); 2532227398Sadrian device_printf(sc->sc_dev, "%s: old bf=%p, new bf=%p\n", 2533227398Sadrian __func__, 2534227398Sadrian old_bf, new_bf); 2535227398Sadrian } 2536227398Sadrian 2537227398Sadrian tid->tx_buf[cindex] = new_bf; 2538227398Sadrian} 2539227398Sadrian 2540227398Sadrian/* 2541227364Sadrian * seq_start - left edge of BAW 2542227364Sadrian * seq_next - current/next sequence number to allocate 2543227364Sadrian * 2544227364Sadrian * Since the BAW status may be modified by both the ath task and 2545227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2546227364Sadrian */ 2547227364Sadrianstatic void 2548227364Sadrianath_tx_update_baw(struct ath_softc *sc, struct ath_node *an, 2549227364Sadrian struct ath_tid *tid, const struct ath_buf *bf) 2550227364Sadrian{ 2551227364Sadrian int index, cindex; 2552227364Sadrian struct ieee80211_tx_ampdu *tap; 2553227364Sadrian int seqno = SEQNO(bf->bf_state.bfs_seqno); 2554227364Sadrian 2555243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2556227364Sadrian 2557227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2558227364Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2559227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2560227364Sadrian 2561227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2562236872Sadrian "%s: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, " 2563229949Sadrian "baw head=%d, tail=%d\n", 2564236872Sadrian __func__, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index, 2565227364Sadrian cindex, tid->baw_head, tid->baw_tail); 2566227364Sadrian 2567227364Sadrian /* 2568227364Sadrian * If this occurs then we have a big problem - something else 2569227364Sadrian * has slid tap->txa_start along without updating the BAW 2570227364Sadrian * tracking start/end pointers. Thus the TX BAW state is now 2571227364Sadrian * completely busted. 2572227364Sadrian * 2573227364Sadrian * But for now, since I haven't yet fixed TDMA and buffer cloning, 2574227364Sadrian * it's quite possible that a cloned buffer is making its way 2575227364Sadrian * here and causing it to fire off. Disable TDMA for now. 2576227364Sadrian */ 2577227364Sadrian if (tid->tx_buf[cindex] != bf) { 2578227364Sadrian device_printf(sc->sc_dev, 2579227364Sadrian "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n", 2580227364Sadrian __func__, 2581227364Sadrian bf, SEQNO(bf->bf_state.bfs_seqno), 2582227364Sadrian tid->tx_buf[cindex], 2583227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno)); 2584227364Sadrian } 2585227364Sadrian 2586227364Sadrian tid->tx_buf[cindex] = NULL; 2587227364Sadrian 2588229949Sadrian while (tid->baw_head != tid->baw_tail && 2589229949Sadrian !tid->tx_buf[tid->baw_head]) { 2590227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 2591227364Sadrian INCR(tid->baw_head, ATH_TID_MAX_BUFS); 2592227364Sadrian } 2593229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2594229949Sadrian "%s: baw is now %d:%d, baw head=%d\n", 2595227364Sadrian __func__, tap->txa_start, tap->txa_wnd, tid->baw_head); 2596227364Sadrian} 2597227364Sadrian 2598227364Sadrian/* 2599227364Sadrian * Mark the current node/TID as ready to TX. 2600227364Sadrian * 2601227364Sadrian * This is done to make it easy for the software scheduler to 2602227364Sadrian * find which nodes have data to send. 2603227364Sadrian * 2604227364Sadrian * The TXQ lock must be held. 2605227364Sadrian */ 2606227364Sadrianstatic void 2607227364Sadrianath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid) 2608227364Sadrian{ 2609227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2610227364Sadrian 2611243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2612227364Sadrian 2613227364Sadrian if (tid->paused) 2614227364Sadrian return; /* paused, can't schedule yet */ 2615227364Sadrian 2616227364Sadrian if (tid->sched) 2617227364Sadrian return; /* already scheduled */ 2618227364Sadrian 2619227364Sadrian tid->sched = 1; 2620227364Sadrian 2621227364Sadrian TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem); 2622227364Sadrian} 2623227364Sadrian 2624227364Sadrian/* 2625227364Sadrian * Mark the current node as no longer needing to be polled for 2626227364Sadrian * TX packets. 2627227364Sadrian * 2628227364Sadrian * The TXQ lock must be held. 2629227364Sadrian */ 2630227364Sadrianstatic void 2631227364Sadrianath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid) 2632227364Sadrian{ 2633227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2634227364Sadrian 2635243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2636227364Sadrian 2637227364Sadrian if (tid->sched == 0) 2638227364Sadrian return; 2639227364Sadrian 2640227364Sadrian tid->sched = 0; 2641227364Sadrian TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem); 2642227364Sadrian} 2643227364Sadrian 2644227364Sadrian/* 2645227364Sadrian * Assign a sequence number manually to the given frame. 2646227364Sadrian * 2647227364Sadrian * This should only be called for A-MPDU TX frames. 2648227364Sadrian */ 2649236872Sadrianstatic ieee80211_seq 2650227364Sadrianath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni, 2651227364Sadrian struct ath_buf *bf, struct mbuf *m0) 2652227364Sadrian{ 2653227364Sadrian struct ieee80211_frame *wh; 2654227364Sadrian int tid, pri; 2655227364Sadrian ieee80211_seq seqno; 2656227364Sadrian uint8_t subtype; 2657227364Sadrian 2658227364Sadrian /* TID lookup */ 2659227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2660227364Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 2661227364Sadrian tid = WME_AC_TO_TID(pri); 2662236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pri=%d, tid=%d, qos has seq=%d\n", 2663236872Sadrian __func__, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2664227364Sadrian 2665227364Sadrian /* XXX Is it a control frame? Ignore */ 2666227364Sadrian 2667227364Sadrian /* Does the packet require a sequence number? */ 2668227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 2669227364Sadrian return -1; 2670227364Sadrian 2671243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2672236880Sadrian 2673227364Sadrian /* 2674227364Sadrian * Is it a QOS NULL Data frame? Give it a sequence number from 2675227364Sadrian * the default TID (IEEE80211_NONQOS_TID.) 2676227364Sadrian * 2677227364Sadrian * The RX path of everything I've looked at doesn't include the NULL 2678227364Sadrian * data frame sequence number in the aggregation state updates, so 2679227364Sadrian * assigning it a sequence number there will cause a BAW hole on the 2680227364Sadrian * RX side. 2681227364Sadrian */ 2682227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2683227364Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) { 2684236880Sadrian /* XXX no locking for this TID? This is a bit of a problem. */ 2685227364Sadrian seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 2686227364Sadrian INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE); 2687227364Sadrian } else { 2688227364Sadrian /* Manually assign sequence number */ 2689227364Sadrian seqno = ni->ni_txseqs[tid]; 2690227364Sadrian INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE); 2691227364Sadrian } 2692227364Sadrian *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); 2693227364Sadrian M_SEQNO_SET(m0, seqno); 2694227364Sadrian 2695227364Sadrian /* Return so caller can do something with it if needed */ 2696236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: -> seqno=%d\n", __func__, seqno); 2697227364Sadrian return seqno; 2698227364Sadrian} 2699227364Sadrian 2700227364Sadrian/* 2701227364Sadrian * Attempt to direct dispatch an aggregate frame to hardware. 2702227364Sadrian * If the frame is out of BAW, queue. 2703227364Sadrian * Otherwise, schedule it as a single frame. 2704227364Sadrian */ 2705227364Sadrianstatic void 2706239051Sadrianath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an, 2707239051Sadrian struct ath_txq *txq, struct ath_buf *bf) 2708227364Sadrian{ 2709227364Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 2710227364Sadrian struct ieee80211_tx_ampdu *tap; 2711227364Sadrian 2712243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2713227364Sadrian 2714227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2715227364Sadrian 2716227364Sadrian /* paused? queue */ 2717227364Sadrian if (tid->paused) { 2718241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 2719233480Sadrian /* XXX don't sched - we're paused! */ 2720227364Sadrian return; 2721227364Sadrian } 2722227364Sadrian 2723227364Sadrian /* outside baw? queue */ 2724227364Sadrian if (bf->bf_state.bfs_dobaw && 2725227364Sadrian (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2726227364Sadrian SEQNO(bf->bf_state.bfs_seqno)))) { 2727241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 2728227364Sadrian ath_tx_tid_sched(sc, tid); 2729227364Sadrian return; 2730227364Sadrian } 2731227364Sadrian 2732240180Sadrian /* 2733240180Sadrian * This is a temporary check and should be removed once 2734240180Sadrian * all the relevant code paths have been fixed. 2735240180Sadrian * 2736240180Sadrian * During aggregate retries, it's possible that the head 2737240180Sadrian * frame will fail (which has the bfs_aggr and bfs_nframes 2738240180Sadrian * fields set for said aggregate) and will be retried as 2739240180Sadrian * a single frame. In this instance, the values should 2740240180Sadrian * be reset or the completion code will get upset with you. 2741240180Sadrian */ 2742240180Sadrian if (bf->bf_state.bfs_aggr != 0 || bf->bf_state.bfs_nframes > 1) { 2743240180Sadrian device_printf(sc->sc_dev, "%s: bfs_aggr=%d, bfs_nframes=%d\n", 2744240180Sadrian __func__, 2745240180Sadrian bf->bf_state.bfs_aggr, 2746240180Sadrian bf->bf_state.bfs_nframes); 2747240180Sadrian bf->bf_state.bfs_aggr = 0; 2748240180Sadrian bf->bf_state.bfs_nframes = 1; 2749240180Sadrian } 2750240180Sadrian 2751240724Sadrian /* Update CLRDMASK just before this frame is queued */ 2752240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 2753240724Sadrian 2754227364Sadrian /* Direct dispatch to hardware */ 2755227364Sadrian ath_tx_do_ratelookup(sc, bf); 2756233989Sadrian ath_tx_calc_duration(sc, bf); 2757233989Sadrian ath_tx_calc_protection(sc, bf); 2758233989Sadrian ath_tx_set_rtscts(sc, bf); 2759227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2760227364Sadrian ath_tx_setds(sc, bf); 2761227364Sadrian 2762227364Sadrian /* Statistics */ 2763227364Sadrian sc->sc_aggr_stats.aggr_low_hwq_single_pkt++; 2764227364Sadrian 2765227364Sadrian /* Track per-TID hardware queue depth correctly */ 2766227364Sadrian tid->hwq_depth++; 2767227364Sadrian 2768227364Sadrian /* Add to BAW */ 2769227364Sadrian if (bf->bf_state.bfs_dobaw) { 2770227364Sadrian ath_tx_addto_baw(sc, an, tid, bf); 2771227364Sadrian bf->bf_state.bfs_addedbaw = 1; 2772227364Sadrian } 2773227364Sadrian 2774227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 2775227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 2776227364Sadrian 2777227364Sadrian /* Hand off to hardware */ 2778227364Sadrian ath_tx_handoff(sc, txq, bf); 2779227364Sadrian} 2780227364Sadrian 2781227364Sadrian/* 2782227364Sadrian * Attempt to send the packet. 2783227364Sadrian * If the queue isn't busy, direct-dispatch. 2784227364Sadrian * If the queue is busy enough, queue the given packet on the 2785227364Sadrian * relevant software queue. 2786227364Sadrian */ 2787227364Sadrianvoid 2788227364Sadrianath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_txq *txq, 2789227364Sadrian struct ath_buf *bf) 2790227364Sadrian{ 2791227364Sadrian struct ath_node *an = ATH_NODE(ni); 2792227364Sadrian struct ieee80211_frame *wh; 2793227364Sadrian struct ath_tid *atid; 2794227364Sadrian int pri, tid; 2795227364Sadrian struct mbuf *m0 = bf->bf_m; 2796227364Sadrian 2797243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2798236880Sadrian 2799227364Sadrian /* Fetch the TID - non-QoS frames get assigned to TID 16 */ 2800227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2801227364Sadrian pri = ath_tx_getac(sc, m0); 2802227364Sadrian tid = ath_tx_gettid(sc, m0); 2803227364Sadrian atid = &an->an_tid[tid]; 2804227364Sadrian 2805236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d\n", 2806236872Sadrian __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2807227364Sadrian 2808227364Sadrian /* Set local packet state, used to queue packets to hardware */ 2809239051Sadrian /* XXX potentially duplicate info, re-check */ 2810227364Sadrian bf->bf_state.bfs_tid = tid; 2811244109Sadrian bf->bf_state.bfs_tx_queue = txq->axq_qnum; 2812227364Sadrian bf->bf_state.bfs_pri = pri; 2813227364Sadrian 2814227364Sadrian /* 2815227364Sadrian * If the hardware queue isn't busy, queue it directly. 2816227364Sadrian * If the hardware queue is busy, queue it. 2817227364Sadrian * If the TID is paused or the traffic it outside BAW, software 2818227364Sadrian * queue it. 2819227364Sadrian */ 2820227364Sadrian if (atid->paused) { 2821227364Sadrian /* TID is paused, queue */ 2822236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: paused\n", __func__); 2823241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2824227364Sadrian } else if (ath_tx_ampdu_pending(sc, an, tid)) { 2825227364Sadrian /* AMPDU pending; queue */ 2826236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pending\n", __func__); 2827241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2828227364Sadrian /* XXX sched? */ 2829227364Sadrian } else if (ath_tx_ampdu_running(sc, an, tid)) { 2830227364Sadrian /* AMPDU running, attempt direct dispatch if possible */ 2831236877Sadrian 2832236877Sadrian /* 2833236877Sadrian * Always queue the frame to the tail of the list. 2834236877Sadrian */ 2835241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2836236877Sadrian 2837236877Sadrian /* 2838236877Sadrian * If the hardware queue isn't busy, direct dispatch 2839236877Sadrian * the head frame in the list. Don't schedule the 2840236877Sadrian * TID - let it build some more frames first? 2841236877Sadrian * 2842236877Sadrian * Otherwise, schedule the TID. 2843236877Sadrian */ 2844229949Sadrian if (txq->axq_depth < sc->sc_hwq_limit) { 2845241336Sadrian bf = ATH_TID_FIRST(atid); 2846241336Sadrian ATH_TID_REMOVE(atid, bf, bf_list); 2847240180Sadrian 2848240180Sadrian /* 2849240180Sadrian * Ensure it's definitely treated as a non-AMPDU 2850240180Sadrian * frame - this information may have been left 2851240180Sadrian * over from a previous attempt. 2852240180Sadrian */ 2853240180Sadrian bf->bf_state.bfs_aggr = 0; 2854240180Sadrian bf->bf_state.bfs_nframes = 1; 2855240180Sadrian 2856240180Sadrian /* Queue to the hardware */ 2857239051Sadrian ath_tx_xmit_aggr(sc, an, txq, bf); 2858233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2859236872Sadrian "%s: xmit_aggr\n", 2860236872Sadrian __func__); 2861229949Sadrian } else { 2862229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2863236872Sadrian "%s: ampdu; swq'ing\n", 2864236872Sadrian __func__); 2865240899Sadrian 2866227364Sadrian ath_tx_tid_sched(sc, atid); 2867227364Sadrian } 2868227364Sadrian } else if (txq->axq_depth < sc->sc_hwq_limit) { 2869227364Sadrian /* AMPDU not running, attempt direct dispatch */ 2870236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: xmit_normal\n", __func__); 2871240926Sadrian /* See if clrdmask needs to be set */ 2872240926Sadrian ath_tx_update_clrdmask(sc, atid, bf); 2873227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 2874227364Sadrian } else { 2875227364Sadrian /* Busy; queue */ 2876236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: swq'ing\n", __func__); 2877241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2878227364Sadrian ath_tx_tid_sched(sc, atid); 2879227364Sadrian } 2880227364Sadrian} 2881227364Sadrian 2882227364Sadrian/* 2883245708Sadrian * Only set the clrdmask bit if none of the nodes are currently 2884245708Sadrian * filtered. 2885245708Sadrian * 2886245708Sadrian * XXX TODO: go through all the callers and check to see 2887245708Sadrian * which are being called in the context of looping over all 2888245708Sadrian * TIDs (eg, if all tids are being paused, resumed, etc.) 2889245708Sadrian * That'll avoid O(n^2) complexity here. 2890245708Sadrian */ 2891245708Sadrianstatic void 2892245708Sadrianath_tx_set_clrdmask(struct ath_softc *sc, struct ath_node *an) 2893245708Sadrian{ 2894245708Sadrian int i; 2895245708Sadrian 2896245708Sadrian ATH_TX_LOCK_ASSERT(sc); 2897245708Sadrian 2898245708Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2899245708Sadrian if (an->an_tid[i].isfiltered == 1) 2900245739Sadrian return; 2901245708Sadrian } 2902245708Sadrian an->clrdmask = 1; 2903245708Sadrian} 2904245708Sadrian 2905245708Sadrian/* 2906227364Sadrian * Configure the per-TID node state. 2907227364Sadrian * 2908227364Sadrian * This likely belongs in if_ath_node.c but I can't think of anywhere 2909227364Sadrian * else to put it just yet. 2910227364Sadrian * 2911227364Sadrian * This sets up the SLISTs and the mutex as appropriate. 2912227364Sadrian */ 2913227364Sadrianvoid 2914227364Sadrianath_tx_tid_init(struct ath_softc *sc, struct ath_node *an) 2915227364Sadrian{ 2916227364Sadrian int i, j; 2917227364Sadrian struct ath_tid *atid; 2918227364Sadrian 2919227364Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2920227364Sadrian atid = &an->an_tid[i]; 2921240639Sadrian 2922240639Sadrian /* XXX now with this bzer(), is the field 0'ing needed? */ 2923240639Sadrian bzero(atid, sizeof(*atid)); 2924240639Sadrian 2925241336Sadrian TAILQ_INIT(&atid->tid_q); 2926241336Sadrian TAILQ_INIT(&atid->filtq.tid_q); 2927227364Sadrian atid->tid = i; 2928227364Sadrian atid->an = an; 2929227364Sadrian for (j = 0; j < ATH_TID_MAX_BUFS; j++) 2930227364Sadrian atid->tx_buf[j] = NULL; 2931227364Sadrian atid->baw_head = atid->baw_tail = 0; 2932227364Sadrian atid->paused = 0; 2933227364Sadrian atid->sched = 0; 2934227364Sadrian atid->hwq_depth = 0; 2935227364Sadrian atid->cleanup_inprogress = 0; 2936227364Sadrian if (i == IEEE80211_NONQOS_TID) 2937240946Sadrian atid->ac = ATH_NONQOS_TID_AC; 2938227364Sadrian else 2939227364Sadrian atid->ac = TID_TO_WME_AC(i); 2940227364Sadrian } 2941245708Sadrian an->clrdmask = 1; /* Always start by setting this bit */ 2942227364Sadrian} 2943227364Sadrian 2944227364Sadrian/* 2945227364Sadrian * Pause the current TID. This stops packets from being transmitted 2946227364Sadrian * on it. 2947227364Sadrian * 2948227364Sadrian * Since this is also called from upper layers as well as the driver, 2949227364Sadrian * it will get the TID lock. 2950227364Sadrian */ 2951227364Sadrianstatic void 2952227364Sadrianath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid) 2953227364Sadrian{ 2954233908Sadrian 2955243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2956227364Sadrian tid->paused++; 2957227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n", 2958227364Sadrian __func__, tid->paused); 2959227364Sadrian} 2960227364Sadrian 2961227364Sadrian/* 2962227364Sadrian * Unpause the current TID, and schedule it if needed. 2963227364Sadrian */ 2964227364Sadrianstatic void 2965227364Sadrianath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid) 2966227364Sadrian{ 2967243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2968243786Sadrian 2969227364Sadrian tid->paused--; 2970227364Sadrian 2971227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n", 2972227364Sadrian __func__, tid->paused); 2973227364Sadrian 2974241170Sadrian if (tid->paused) 2975227364Sadrian return; 2976227364Sadrian 2977241170Sadrian /* 2978241170Sadrian * Override the clrdmask configuration for the next frame 2979241170Sadrian * from this TID, just to get the ball rolling. 2980241170Sadrian */ 2981245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 2982241170Sadrian 2983241170Sadrian if (tid->axq_depth == 0) 2984241170Sadrian return; 2985241170Sadrian 2986240639Sadrian /* XXX isfiltered shouldn't ever be 0 at this point */ 2987240639Sadrian if (tid->isfiltered == 1) { 2988240639Sadrian device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 2989240639Sadrian return; 2990240639Sadrian } 2991240639Sadrian 2992227364Sadrian ath_tx_tid_sched(sc, tid); 2993246450Sadrian 2994246450Sadrian /* 2995246450Sadrian * Queue the software TX scheduler. 2996246450Sadrian */ 2997246450Sadrian ath_tx_swq_kick(sc); 2998227364Sadrian} 2999227364Sadrian 3000227364Sadrian/* 3001240639Sadrian * Add the given ath_buf to the TID filtered frame list. 3002240639Sadrian * This requires the TID be filtered. 3003240639Sadrian */ 3004240639Sadrianstatic void 3005240639Sadrianath_tx_tid_filt_addbuf(struct ath_softc *sc, struct ath_tid *tid, 3006240639Sadrian struct ath_buf *bf) 3007240639Sadrian{ 3008240639Sadrian 3009243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3010243786Sadrian 3011240639Sadrian if (! tid->isfiltered) 3012240639Sadrian device_printf(sc->sc_dev, "%s: not filtered?!\n", __func__); 3013240639Sadrian 3014240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: bf=%p\n", __func__, bf); 3015240639Sadrian 3016240639Sadrian /* Set the retry bit and bump the retry counter */ 3017240639Sadrian ath_tx_set_retry(sc, bf); 3018240639Sadrian sc->sc_stats.ast_tx_swfiltered++; 3019240639Sadrian 3020241566Sadrian ATH_TID_FILT_INSERT_TAIL(tid, bf, bf_list); 3021240639Sadrian} 3022240639Sadrian 3023240639Sadrian/* 3024240639Sadrian * Handle a completed filtered frame from the given TID. 3025240639Sadrian * This just enables/pauses the filtered frame state if required 3026240639Sadrian * and appends the filtered frame to the filtered queue. 3027240639Sadrian */ 3028240639Sadrianstatic void 3029240639Sadrianath_tx_tid_filt_comp_buf(struct ath_softc *sc, struct ath_tid *tid, 3030240639Sadrian struct ath_buf *bf) 3031240639Sadrian{ 3032240639Sadrian 3033243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3034240639Sadrian 3035240639Sadrian if (! tid->isfiltered) { 3036240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: filter transition\n", 3037240639Sadrian __func__); 3038240639Sadrian tid->isfiltered = 1; 3039240639Sadrian ath_tx_tid_pause(sc, tid); 3040240639Sadrian } 3041240639Sadrian 3042240639Sadrian /* Add the frame to the filter queue */ 3043240639Sadrian ath_tx_tid_filt_addbuf(sc, tid, bf); 3044240639Sadrian} 3045240639Sadrian 3046240639Sadrian/* 3047240639Sadrian * Complete the filtered frame TX completion. 3048240639Sadrian * 3049240639Sadrian * If there are no more frames in the hardware queue, unpause/unfilter 3050240639Sadrian * the TID if applicable. Otherwise we will wait for a node PS transition 3051240639Sadrian * to unfilter. 3052240639Sadrian */ 3053240639Sadrianstatic void 3054240639Sadrianath_tx_tid_filt_comp_complete(struct ath_softc *sc, struct ath_tid *tid) 3055240639Sadrian{ 3056240639Sadrian struct ath_buf *bf; 3057240639Sadrian 3058243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3059240639Sadrian 3060240639Sadrian if (tid->hwq_depth != 0) 3061240639Sadrian return; 3062240639Sadrian 3063240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: hwq=0, transition back\n", 3064240639Sadrian __func__); 3065240639Sadrian tid->isfiltered = 0; 3066245708Sadrian /* XXX ath_tx_tid_resume() also calls ath_tx_set_clrdmask()! */ 3067245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3068240639Sadrian 3069240639Sadrian /* XXX this is really quite inefficient */ 3070241566Sadrian while ((bf = ATH_TID_FILT_LAST(tid, ath_bufhead_s)) != NULL) { 3071241566Sadrian ATH_TID_FILT_REMOVE(tid, bf, bf_list); 3072241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 3073240639Sadrian } 3074240639Sadrian 3075240639Sadrian ath_tx_tid_resume(sc, tid); 3076240639Sadrian} 3077240639Sadrian 3078240639Sadrian/* 3079240639Sadrian * Called when a single (aggregate or otherwise) frame is completed. 3080240639Sadrian * 3081240639Sadrian * Returns 1 if the buffer could be added to the filtered list 3082240639Sadrian * (cloned or otherwise), 0 if the buffer couldn't be added to the 3083240639Sadrian * filtered list (failed clone; expired retry) and the caller should 3084240639Sadrian * free it and handle it like a failure (eg by sending a BAR.) 3085240639Sadrian */ 3086240639Sadrianstatic int 3087240639Sadrianath_tx_tid_filt_comp_single(struct ath_softc *sc, struct ath_tid *tid, 3088240639Sadrian struct ath_buf *bf) 3089240639Sadrian{ 3090240639Sadrian struct ath_buf *nbf; 3091240639Sadrian int retval; 3092240639Sadrian 3093243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3094240639Sadrian 3095240639Sadrian /* 3096240639Sadrian * Don't allow a filtered frame to live forever. 3097240639Sadrian */ 3098240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3099241170Sadrian sc->sc_stats.ast_tx_swretrymax++; 3100240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3101240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 3102240639Sadrian __func__, 3103240639Sadrian bf, 3104240639Sadrian bf->bf_state.bfs_seqno); 3105240639Sadrian return (0); 3106240639Sadrian } 3107240639Sadrian 3108240639Sadrian /* 3109240639Sadrian * A busy buffer can't be added to the retry list. 3110240639Sadrian * It needs to be cloned. 3111240639Sadrian */ 3112240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 3113240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3114240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3115240639Sadrian "%s: busy buffer clone: %p -> %p\n", 3116240639Sadrian __func__, bf, nbf); 3117240639Sadrian } else { 3118240639Sadrian nbf = bf; 3119240639Sadrian } 3120240639Sadrian 3121240639Sadrian if (nbf == NULL) { 3122240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3123240639Sadrian "%s: busy buffer couldn't be cloned (%p)!\n", 3124240639Sadrian __func__, bf); 3125240639Sadrian retval = 1; 3126240639Sadrian } else { 3127240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3128240639Sadrian retval = 0; 3129240639Sadrian } 3130240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 3131240639Sadrian 3132240639Sadrian return (retval); 3133240639Sadrian} 3134240639Sadrian 3135240639Sadrianstatic void 3136240639Sadrianath_tx_tid_filt_comp_aggr(struct ath_softc *sc, struct ath_tid *tid, 3137240639Sadrian struct ath_buf *bf_first, ath_bufhead *bf_q) 3138240639Sadrian{ 3139240639Sadrian struct ath_buf *bf, *bf_next, *nbf; 3140240639Sadrian 3141243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3142240639Sadrian 3143240639Sadrian bf = bf_first; 3144240639Sadrian while (bf) { 3145240639Sadrian bf_next = bf->bf_next; 3146240639Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 3147240639Sadrian 3148240639Sadrian /* 3149240639Sadrian * Don't allow a filtered frame to live forever. 3150240639Sadrian */ 3151240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3152247029Sadrian sc->sc_stats.ast_tx_swretrymax++; 3153240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3154240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 3155240639Sadrian __func__, 3156240639Sadrian bf, 3157240639Sadrian bf->bf_state.bfs_seqno); 3158240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3159240639Sadrian goto next; 3160240639Sadrian } 3161240639Sadrian 3162240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 3163240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3164240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3165240639Sadrian "%s: busy buffer cloned: %p -> %p", 3166240639Sadrian __func__, bf, nbf); 3167240639Sadrian } else { 3168240639Sadrian nbf = bf; 3169240639Sadrian } 3170240639Sadrian 3171240639Sadrian /* 3172240639Sadrian * If the buffer couldn't be cloned, add it to bf_q; 3173240639Sadrian * the caller will free the buffer(s) as required. 3174240639Sadrian */ 3175240639Sadrian if (nbf == NULL) { 3176240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3177240639Sadrian "%s: buffer couldn't be cloned! (%p)\n", 3178240639Sadrian __func__, bf); 3179240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3180240639Sadrian } else { 3181240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3182240639Sadrian } 3183240639Sadriannext: 3184240639Sadrian bf = bf_next; 3185240639Sadrian } 3186240639Sadrian 3187240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 3188240639Sadrian} 3189240639Sadrian 3190240639Sadrian/* 3191233908Sadrian * Suspend the queue because we need to TX a BAR. 3192233908Sadrian */ 3193233908Sadrianstatic void 3194233908Sadrianath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid) 3195233908Sadrian{ 3196233908Sadrian 3197243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3198243786Sadrian 3199235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3200235676Sadrian "%s: tid=%p, bar_wait=%d, bar_tx=%d, called\n", 3201233908Sadrian __func__, 3202235676Sadrian tid, 3203235676Sadrian tid->bar_wait, 3204235676Sadrian tid->bar_tx); 3205233908Sadrian 3206233908Sadrian /* We shouldn't be called when bar_tx is 1 */ 3207233908Sadrian if (tid->bar_tx) { 3208233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx is 1?!\n", 3209233908Sadrian __func__); 3210233908Sadrian } 3211233908Sadrian 3212233908Sadrian /* If we've already been called, just be patient. */ 3213233908Sadrian if (tid->bar_wait) 3214233908Sadrian return; 3215233908Sadrian 3216233908Sadrian /* Wait! */ 3217233908Sadrian tid->bar_wait = 1; 3218233908Sadrian 3219233908Sadrian /* Only one pause, no matter how many frames fail */ 3220233908Sadrian ath_tx_tid_pause(sc, tid); 3221233908Sadrian} 3222233908Sadrian 3223233908Sadrian/* 3224233908Sadrian * We've finished with BAR handling - either we succeeded or 3225233908Sadrian * failed. Either way, unsuspend TX. 3226233908Sadrian */ 3227233908Sadrianstatic void 3228233908Sadrianath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid) 3229233908Sadrian{ 3230233908Sadrian 3231243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3232243786Sadrian 3233235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3234233908Sadrian "%s: tid=%p, called\n", 3235233908Sadrian __func__, 3236233908Sadrian tid); 3237233908Sadrian 3238233908Sadrian if (tid->bar_tx == 0 || tid->bar_wait == 0) { 3239233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx=%d, bar_wait=%d: ?\n", 3240233908Sadrian __func__, tid->bar_tx, tid->bar_wait); 3241233908Sadrian } 3242233908Sadrian 3243233908Sadrian tid->bar_tx = tid->bar_wait = 0; 3244233908Sadrian ath_tx_tid_resume(sc, tid); 3245233908Sadrian} 3246233908Sadrian 3247233908Sadrian/* 3248233908Sadrian * Return whether we're ready to TX a BAR frame. 3249233908Sadrian * 3250233908Sadrian * Requires the TID lock be held. 3251233908Sadrian */ 3252233908Sadrianstatic int 3253233908Sadrianath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid) 3254233908Sadrian{ 3255233908Sadrian 3256243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3257233908Sadrian 3258233908Sadrian if (tid->bar_wait == 0 || tid->hwq_depth > 0) 3259233908Sadrian return (0); 3260233908Sadrian 3261235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, "%s: tid=%p (%d), bar ready\n", 3262235491Sadrian __func__, tid, tid->tid); 3263235491Sadrian 3264233908Sadrian return (1); 3265233908Sadrian} 3266233908Sadrian 3267233908Sadrian/* 3268233908Sadrian * Check whether the current TID is ready to have a BAR 3269233908Sadrian * TXed and if so, do the TX. 3270233908Sadrian * 3271233908Sadrian * Since the TID/TXQ lock can't be held during a call to 3272233908Sadrian * ieee80211_send_bar(), we have to do the dirty thing of unlocking it, 3273233908Sadrian * sending the BAR and locking it again. 3274233908Sadrian * 3275233908Sadrian * Eventually, the code to send the BAR should be broken out 3276233908Sadrian * from this routine so the lock doesn't have to be reacquired 3277233908Sadrian * just to be immediately dropped by the caller. 3278233908Sadrian */ 3279233908Sadrianstatic void 3280233908Sadrianath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid) 3281233908Sadrian{ 3282233908Sadrian struct ieee80211_tx_ampdu *tap; 3283233908Sadrian 3284243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3285233908Sadrian 3286235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3287233908Sadrian "%s: tid=%p, called\n", 3288233908Sadrian __func__, 3289233908Sadrian tid); 3290233908Sadrian 3291233908Sadrian tap = ath_tx_get_tx_tid(tid->an, tid->tid); 3292233908Sadrian 3293233908Sadrian /* 3294233908Sadrian * This is an error condition! 3295233908Sadrian */ 3296233908Sadrian if (tid->bar_wait == 0 || tid->bar_tx == 1) { 3297233908Sadrian device_printf(sc->sc_dev, 3298233908Sadrian "%s: tid=%p, bar_tx=%d, bar_wait=%d: ?\n", 3299233908Sadrian __func__, 3300233908Sadrian tid, 3301233908Sadrian tid->bar_tx, 3302233908Sadrian tid->bar_wait); 3303233908Sadrian return; 3304233908Sadrian } 3305233908Sadrian 3306233908Sadrian /* Don't do anything if we still have pending frames */ 3307233908Sadrian if (tid->hwq_depth > 0) { 3308235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3309233908Sadrian "%s: tid=%p, hwq_depth=%d, waiting\n", 3310233908Sadrian __func__, 3311233908Sadrian tid, 3312233908Sadrian tid->hwq_depth); 3313233908Sadrian return; 3314233908Sadrian } 3315233908Sadrian 3316233908Sadrian /* We're now about to TX */ 3317233908Sadrian tid->bar_tx = 1; 3318233908Sadrian 3319233908Sadrian /* 3320240724Sadrian * Override the clrdmask configuration for the next frame, 3321240724Sadrian * just to get the ball rolling. 3322240724Sadrian */ 3323245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3324240724Sadrian 3325240724Sadrian /* 3326233908Sadrian * Calculate new BAW left edge, now that all frames have either 3327233908Sadrian * succeeded or failed. 3328233908Sadrian * 3329233908Sadrian * XXX verify this is _actually_ the valid value to begin at! 3330233908Sadrian */ 3331235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3332233908Sadrian "%s: tid=%p, new BAW left edge=%d\n", 3333233908Sadrian __func__, 3334233908Sadrian tid, 3335233908Sadrian tap->txa_start); 3336233908Sadrian 3337233908Sadrian /* Try sending the BAR frame */ 3338233908Sadrian /* We can't hold the lock here! */ 3339233908Sadrian 3340243786Sadrian ATH_TX_UNLOCK(sc); 3341233908Sadrian if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) { 3342233908Sadrian /* Success? Now we wait for notification that it's done */ 3343243786Sadrian ATH_TX_LOCK(sc); 3344233908Sadrian return; 3345233908Sadrian } 3346233908Sadrian 3347233908Sadrian /* Failure? For now, warn loudly and continue */ 3348243786Sadrian ATH_TX_LOCK(sc); 3349233908Sadrian device_printf(sc->sc_dev, "%s: tid=%p, failed to TX BAR, continue!\n", 3350233908Sadrian __func__, tid); 3351233908Sadrian ath_tx_tid_bar_unsuspend(sc, tid); 3352233908Sadrian} 3353233908Sadrian 3354240639Sadrianstatic void 3355240639Sadrianath_tx_tid_drain_pkt(struct ath_softc *sc, struct ath_node *an, 3356240639Sadrian struct ath_tid *tid, ath_bufhead *bf_cq, struct ath_buf *bf) 3357240639Sadrian{ 3358233908Sadrian 3359243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3360240639Sadrian 3361240639Sadrian /* 3362240639Sadrian * If the current TID is running AMPDU, update 3363240639Sadrian * the BAW. 3364240639Sadrian */ 3365240639Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid) && 3366240639Sadrian bf->bf_state.bfs_dobaw) { 3367240639Sadrian /* 3368240639Sadrian * Only remove the frame from the BAW if it's 3369240639Sadrian * been transmitted at least once; this means 3370240639Sadrian * the frame was in the BAW to begin with. 3371240639Sadrian */ 3372240639Sadrian if (bf->bf_state.bfs_retries > 0) { 3373240639Sadrian ath_tx_update_baw(sc, an, tid, bf); 3374240639Sadrian bf->bf_state.bfs_dobaw = 0; 3375240639Sadrian } 3376240639Sadrian /* 3377240639Sadrian * This has become a non-fatal error now 3378240639Sadrian */ 3379240639Sadrian if (! bf->bf_state.bfs_addedbaw) 3380240639Sadrian device_printf(sc->sc_dev, 3381240639Sadrian "%s: wasn't added: seqno %d\n", 3382240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3383240639Sadrian } 3384240639Sadrian TAILQ_INSERT_TAIL(bf_cq, bf, bf_list); 3385240639Sadrian} 3386240639Sadrian 3387240639Sadrianstatic void 3388240639Sadrianath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an, 3389240899Sadrian const char *pfx, struct ath_tid *tid, struct ath_buf *bf) 3390240639Sadrian{ 3391240639Sadrian struct ieee80211_node *ni = &an->an_node; 3392240639Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 3393240639Sadrian struct ieee80211_tx_ampdu *tap; 3394240639Sadrian 3395240639Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3396240639Sadrian 3397240639Sadrian device_printf(sc->sc_dev, 3398240899Sadrian "%s: %s: node %p: bf=%p: addbaw=%d, dobaw=%d, " 3399240639Sadrian "seqno=%d, retry=%d\n", 3400240899Sadrian __func__, pfx, ni, bf, 3401240639Sadrian bf->bf_state.bfs_addedbaw, 3402240639Sadrian bf->bf_state.bfs_dobaw, 3403240639Sadrian SEQNO(bf->bf_state.bfs_seqno), 3404240639Sadrian bf->bf_state.bfs_retries); 3405240639Sadrian device_printf(sc->sc_dev, 3406240899Sadrian "%s: node %p: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n", 3407240724Sadrian __func__, ni, bf, 3408240899Sadrian txq->axq_qnum, 3409240899Sadrian txq->axq_depth, 3410240899Sadrian txq->axq_aggr_depth); 3411240724Sadrian 3412240724Sadrian device_printf(sc->sc_dev, 3413240639Sadrian "%s: node %p: bf=%p: tid txq_depth=%d hwq_depth=%d, bar_wait=%d, isfiltered=%d\n", 3414240639Sadrian __func__, ni, bf, 3415240639Sadrian tid->axq_depth, 3416240639Sadrian tid->hwq_depth, 3417240639Sadrian tid->bar_wait, 3418240639Sadrian tid->isfiltered); 3419240639Sadrian device_printf(sc->sc_dev, 3420240724Sadrian "%s: node %p: tid %d: " 3421240724Sadrian "sched=%d, paused=%d, " 3422240724Sadrian "incomp=%d, baw_head=%d, " 3423240639Sadrian "baw_tail=%d txa_start=%d, ni_txseqs=%d\n", 3424240724Sadrian __func__, ni, tid->tid, 3425240724Sadrian tid->sched, tid->paused, 3426240724Sadrian tid->incomp, tid->baw_head, 3427240639Sadrian tid->baw_tail, tap == NULL ? -1 : tap->txa_start, 3428240639Sadrian ni->ni_txseqs[tid->tid]); 3429240639Sadrian 3430240639Sadrian /* XXX Dump the frame, see what it is? */ 3431240639Sadrian ieee80211_dump_pkt(ni->ni_ic, 3432240639Sadrian mtod(bf->bf_m, const uint8_t *), 3433240639Sadrian bf->bf_m->m_len, 0, -1); 3434240639Sadrian} 3435240639Sadrian 3436233908Sadrian/* 3437227364Sadrian * Free any packets currently pending in the software TX queue. 3438227364Sadrian * 3439227364Sadrian * This will be called when a node is being deleted. 3440227364Sadrian * 3441227364Sadrian * It can also be called on an active node during an interface 3442227364Sadrian * reset or state transition. 3443227364Sadrian * 3444227364Sadrian * (From Linux/reference): 3445227364Sadrian * 3446227364Sadrian * TODO: For frame(s) that are in the retry state, we will reuse the 3447227364Sadrian * sequence number(s) without setting the retry bit. The 3448227364Sadrian * alternative is to give up on these and BAR the receiver's window 3449227364Sadrian * forward. 3450227364Sadrian */ 3451227364Sadrianstatic void 3452229949Sadrianath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an, 3453229949Sadrian struct ath_tid *tid, ath_bufhead *bf_cq) 3454227364Sadrian{ 3455227364Sadrian struct ath_buf *bf; 3456227364Sadrian struct ieee80211_tx_ampdu *tap; 3457227364Sadrian struct ieee80211_node *ni = &an->an_node; 3458240639Sadrian int t; 3459227364Sadrian 3460227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3461227364Sadrian 3462243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3463227364Sadrian 3464227364Sadrian /* Walk the queue, free frames */ 3465240639Sadrian t = 0; 3466227364Sadrian for (;;) { 3467241336Sadrian bf = ATH_TID_FIRST(tid); 3468227364Sadrian if (bf == NULL) { 3469227364Sadrian break; 3470227364Sadrian } 3471227364Sadrian 3472227364Sadrian if (t == 0) { 3473240899Sadrian ath_tx_tid_drain_print(sc, an, "norm", tid, bf); 3474240639Sadrian t = 1; 3475240639Sadrian } 3476229165Sadrian 3477241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 3478240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3479240639Sadrian } 3480229165Sadrian 3481240639Sadrian /* And now, drain the filtered frame queue */ 3482240639Sadrian t = 0; 3483240639Sadrian for (;;) { 3484241566Sadrian bf = ATH_TID_FILT_FIRST(tid); 3485240639Sadrian if (bf == NULL) 3486240639Sadrian break; 3487240639Sadrian 3488240639Sadrian if (t == 0) { 3489240899Sadrian ath_tx_tid_drain_print(sc, an, "filt", tid, bf); 3490233897Sadrian t = 1; 3491227364Sadrian } 3492227364Sadrian 3493241566Sadrian ATH_TID_FILT_REMOVE(tid, bf, bf_list); 3494240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3495227364Sadrian } 3496227364Sadrian 3497227364Sadrian /* 3498240724Sadrian * Override the clrdmask configuration for the next frame 3499240724Sadrian * in case there is some future transmission, just to get 3500240724Sadrian * the ball rolling. 3501240724Sadrian * 3502240724Sadrian * This won't hurt things if the TID is about to be freed. 3503240724Sadrian */ 3504245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3505240724Sadrian 3506240724Sadrian /* 3507227364Sadrian * Now that it's completed, grab the TID lock and update 3508227364Sadrian * the sequence number and BAW window. 3509227364Sadrian * Because sequence numbers have been assigned to frames 3510227364Sadrian * that haven't been sent yet, it's entirely possible 3511227364Sadrian * we'll be called with some pending frames that have not 3512227364Sadrian * been transmitted. 3513227364Sadrian * 3514227364Sadrian * The cleaner solution is to do the sequence number allocation 3515227364Sadrian * when the packet is first transmitted - and thus the "retries" 3516227364Sadrian * check above would be enough to update the BAW/seqno. 3517227364Sadrian */ 3518227364Sadrian 3519227364Sadrian /* But don't do it for non-QoS TIDs */ 3520227364Sadrian if (tap) { 3521227364Sadrian#if 0 3522227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3523227364Sadrian "%s: node %p: TID %d: sliding BAW left edge to %d\n", 3524227364Sadrian __func__, an, tid->tid, tap->txa_start); 3525227364Sadrian#endif 3526227364Sadrian ni->ni_txseqs[tid->tid] = tap->txa_start; 3527227364Sadrian tid->baw_tail = tid->baw_head; 3528227364Sadrian } 3529227364Sadrian} 3530227364Sadrian 3531227364Sadrian/* 3532227364Sadrian * Flush all software queued packets for the given node. 3533227364Sadrian * 3534227364Sadrian * This occurs when a completion handler frees the last buffer 3535227364Sadrian * for a node, and the node is thus freed. This causes the node 3536227364Sadrian * to be cleaned up, which ends up calling ath_tx_node_flush. 3537227364Sadrian */ 3538227364Sadrianvoid 3539227364Sadrianath_tx_node_flush(struct ath_softc *sc, struct ath_node *an) 3540227364Sadrian{ 3541227364Sadrian int tid; 3542227364Sadrian ath_bufhead bf_cq; 3543227364Sadrian struct ath_buf *bf; 3544227364Sadrian 3545227364Sadrian TAILQ_INIT(&bf_cq); 3546227364Sadrian 3547240899Sadrian ATH_KTR(sc, ATH_KTR_NODE, 1, "ath_tx_node_flush: flush node; ni=%p", 3548240899Sadrian &an->an_node); 3549240899Sadrian 3550243786Sadrian ATH_TX_LOCK(sc); 3551227364Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 3552227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3553227364Sadrian 3554227364Sadrian /* Free packets */ 3555227364Sadrian ath_tx_tid_drain(sc, an, atid, &bf_cq); 3556240914Sadrian /* Remove this tid from the list of active tids */ 3557240914Sadrian ath_tx_tid_unsched(sc, atid); 3558227364Sadrian } 3559243786Sadrian ATH_TX_UNLOCK(sc); 3560227364Sadrian 3561227364Sadrian /* Handle completed frames */ 3562227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3563227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3564227364Sadrian ath_tx_default_comp(sc, bf, 0); 3565227364Sadrian } 3566227364Sadrian} 3567227364Sadrian 3568227364Sadrian/* 3569227364Sadrian * Drain all the software TXQs currently with traffic queued. 3570227364Sadrian */ 3571227364Sadrianvoid 3572227364Sadrianath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq) 3573227364Sadrian{ 3574227364Sadrian struct ath_tid *tid; 3575227364Sadrian ath_bufhead bf_cq; 3576227364Sadrian struct ath_buf *bf; 3577227364Sadrian 3578227364Sadrian TAILQ_INIT(&bf_cq); 3579243786Sadrian ATH_TX_LOCK(sc); 3580227364Sadrian 3581227364Sadrian /* 3582227364Sadrian * Iterate over all active tids for the given txq, 3583227364Sadrian * flushing and unsched'ing them 3584227364Sadrian */ 3585227364Sadrian while (! TAILQ_EMPTY(&txq->axq_tidq)) { 3586227364Sadrian tid = TAILQ_FIRST(&txq->axq_tidq); 3587227364Sadrian ath_tx_tid_drain(sc, tid->an, tid, &bf_cq); 3588227364Sadrian ath_tx_tid_unsched(sc, tid); 3589227364Sadrian } 3590227364Sadrian 3591243786Sadrian ATH_TX_UNLOCK(sc); 3592227364Sadrian 3593227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3594227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3595227364Sadrian ath_tx_default_comp(sc, bf, 0); 3596227364Sadrian } 3597227364Sadrian} 3598227364Sadrian 3599227364Sadrian/* 3600227364Sadrian * Handle completion of non-aggregate session frames. 3601240883Sadrian * 3602240883Sadrian * This (currently) doesn't implement software retransmission of 3603240883Sadrian * non-aggregate frames! 3604240883Sadrian * 3605240883Sadrian * Software retransmission of non-aggregate frames needs to obey 3606240883Sadrian * the strict sequence number ordering, and drop any frames that 3607240883Sadrian * will fail this. 3608240883Sadrian * 3609240883Sadrian * For now, filtered frames and frame transmission will cause 3610240883Sadrian * all kinds of issues. So we don't support them. 3611240883Sadrian * 3612240883Sadrian * So anyone queuing frames via ath_tx_normal_xmit() or 3613240883Sadrian * ath_tx_hw_queue_norm() must override and set CLRDMASK. 3614227364Sadrian */ 3615227364Sadrianvoid 3616227364Sadrianath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3617227364Sadrian{ 3618227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3619227364Sadrian struct ath_node *an = ATH_NODE(ni); 3620227364Sadrian int tid = bf->bf_state.bfs_tid; 3621227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3622227364Sadrian struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3623227364Sadrian 3624227364Sadrian /* The TID state is protected behind the TXQ lock */ 3625243786Sadrian ATH_TX_LOCK(sc); 3626227364Sadrian 3627227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n", 3628227364Sadrian __func__, bf, fail, atid->hwq_depth - 1); 3629227364Sadrian 3630227364Sadrian atid->hwq_depth--; 3631240639Sadrian 3632240883Sadrian#if 0 3633240883Sadrian /* 3634240883Sadrian * If the frame was filtered, stick it on the filter frame 3635240883Sadrian * queue and complain about it. It shouldn't happen! 3636240883Sadrian */ 3637240883Sadrian if ((ts->ts_status & HAL_TXERR_FILT) || 3638240883Sadrian (ts->ts_status != 0 && atid->isfiltered)) { 3639240883Sadrian device_printf(sc->sc_dev, 3640240883Sadrian "%s: isfiltered=%d, ts_status=%d: huh?\n", 3641240883Sadrian __func__, 3642240883Sadrian atid->isfiltered, 3643240883Sadrian ts->ts_status); 3644240883Sadrian ath_tx_tid_filt_comp_buf(sc, atid, bf); 3645240883Sadrian } 3646240883Sadrian#endif 3647240639Sadrian if (atid->isfiltered) 3648240883Sadrian device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 3649227364Sadrian if (atid->hwq_depth < 0) 3650227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3651227364Sadrian __func__, atid->hwq_depth); 3652240639Sadrian 3653240639Sadrian /* 3654240639Sadrian * If the queue is filtered, potentially mark it as complete 3655240639Sadrian * and reschedule it as needed. 3656240639Sadrian * 3657240639Sadrian * This is required as there may be a subsequent TX descriptor 3658240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 3659240639Sadrian * that a filtered frame will be followed by a non-filtered 3660240639Sadrian * (complete or otherwise) frame. 3661240639Sadrian * 3662240639Sadrian * XXX should we do this before we complete the frame? 3663240639Sadrian */ 3664240639Sadrian if (atid->isfiltered) 3665240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 3666243786Sadrian ATH_TX_UNLOCK(sc); 3667227364Sadrian 3668227364Sadrian /* 3669227364Sadrian * punt to rate control if we're not being cleaned up 3670227364Sadrian * during a hw queue drain and the frame wanted an ACK. 3671227364Sadrian */ 3672233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3673227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3674227364Sadrian ts, bf->bf_state.bfs_pktlen, 3675227364Sadrian 1, (ts->ts_status == 0) ? 0 : 1); 3676227364Sadrian 3677227364Sadrian ath_tx_default_comp(sc, bf, fail); 3678227364Sadrian} 3679227364Sadrian 3680227364Sadrian/* 3681227364Sadrian * Handle cleanup of aggregate session packets that aren't 3682227364Sadrian * an A-MPDU. 3683227364Sadrian * 3684227364Sadrian * There's no need to update the BAW here - the session is being 3685227364Sadrian * torn down. 3686227364Sadrian */ 3687227364Sadrianstatic void 3688227364Sadrianath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3689227364Sadrian{ 3690227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3691227364Sadrian struct ath_node *an = ATH_NODE(ni); 3692227364Sadrian int tid = bf->bf_state.bfs_tid; 3693227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3694227364Sadrian 3695227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n", 3696227364Sadrian __func__, tid, atid->incomp); 3697227364Sadrian 3698243786Sadrian ATH_TX_LOCK(sc); 3699227364Sadrian atid->incomp--; 3700227364Sadrian if (atid->incomp == 0) { 3701227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3702227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3703227364Sadrian __func__, tid); 3704227364Sadrian atid->cleanup_inprogress = 0; 3705227364Sadrian ath_tx_tid_resume(sc, atid); 3706227364Sadrian } 3707243786Sadrian ATH_TX_UNLOCK(sc); 3708227364Sadrian 3709227364Sadrian ath_tx_default_comp(sc, bf, 0); 3710227364Sadrian} 3711227364Sadrian 3712227364Sadrian/* 3713227364Sadrian * Performs transmit side cleanup when TID changes from aggregated to 3714227364Sadrian * unaggregated. 3715227364Sadrian * 3716227364Sadrian * - Discard all retry frames from the s/w queue. 3717227364Sadrian * - Fix the tx completion function for all buffers in s/w queue. 3718227364Sadrian * - Count the number of unacked frames, and let transmit completion 3719227364Sadrian * handle it later. 3720227364Sadrian * 3721227364Sadrian * The caller is responsible for pausing the TID. 3722227364Sadrian */ 3723227364Sadrianstatic void 3724235749Sadrianath_tx_tid_cleanup(struct ath_softc *sc, struct ath_node *an, int tid) 3725227364Sadrian{ 3726227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3727227364Sadrian struct ieee80211_tx_ampdu *tap; 3728227364Sadrian struct ath_buf *bf, *bf_next; 3729227364Sadrian ath_bufhead bf_cq; 3730227364Sadrian 3731235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 3732227364Sadrian "%s: TID %d: called\n", __func__, tid); 3733227364Sadrian 3734227364Sadrian TAILQ_INIT(&bf_cq); 3735243786Sadrian ATH_TX_LOCK(sc); 3736227364Sadrian 3737227364Sadrian /* 3738240639Sadrian * Move the filtered frames to the TX queue, before 3739240639Sadrian * we run off and discard/process things. 3740240639Sadrian */ 3741240639Sadrian /* XXX this is really quite inefficient */ 3742241566Sadrian while ((bf = ATH_TID_FILT_LAST(atid, ath_bufhead_s)) != NULL) { 3743241566Sadrian ATH_TID_FILT_REMOVE(atid, bf, bf_list); 3744241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 3745240639Sadrian } 3746240639Sadrian 3747240639Sadrian /* 3748227364Sadrian * Update the frames in the software TX queue: 3749227364Sadrian * 3750227364Sadrian * + Discard retry frames in the queue 3751227364Sadrian * + Fix the completion function to be non-aggregate 3752227364Sadrian */ 3753241336Sadrian bf = ATH_TID_FIRST(atid); 3754227364Sadrian while (bf) { 3755227364Sadrian if (bf->bf_state.bfs_isretried) { 3756227364Sadrian bf_next = TAILQ_NEXT(bf, bf_list); 3757241336Sadrian ATH_TID_REMOVE(atid, bf, bf_list); 3758227364Sadrian atid->axq_depth--; 3759227364Sadrian if (bf->bf_state.bfs_dobaw) { 3760227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3761227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3762227364Sadrian device_printf(sc->sc_dev, 3763227364Sadrian "%s: wasn't added: seqno %d\n", 3764229949Sadrian __func__, 3765229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3766227364Sadrian } 3767227364Sadrian bf->bf_state.bfs_dobaw = 0; 3768227364Sadrian /* 3769227364Sadrian * Call the default completion handler with "fail" just 3770227364Sadrian * so upper levels are suitably notified about this. 3771227364Sadrian */ 3772227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3773227364Sadrian bf = bf_next; 3774227364Sadrian continue; 3775227364Sadrian } 3776227364Sadrian /* Give these the default completion handler */ 3777227364Sadrian bf->bf_comp = ath_tx_normal_comp; 3778227364Sadrian bf = TAILQ_NEXT(bf, bf_list); 3779227364Sadrian } 3780227364Sadrian 3781227364Sadrian /* The caller is required to pause the TID */ 3782227364Sadrian#if 0 3783227364Sadrian /* Pause the TID */ 3784227364Sadrian ath_tx_tid_pause(sc, atid); 3785227364Sadrian#endif 3786227364Sadrian 3787227364Sadrian /* 3788227364Sadrian * Calculate what hardware-queued frames exist based 3789227364Sadrian * on the current BAW size. Ie, what frames have been 3790227364Sadrian * added to the TX hardware queue for this TID but 3791227364Sadrian * not yet ACKed. 3792227364Sadrian */ 3793227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3794227364Sadrian /* Need the lock - fiddling with BAW */ 3795227364Sadrian while (atid->baw_head != atid->baw_tail) { 3796227364Sadrian if (atid->tx_buf[atid->baw_head]) { 3797227364Sadrian atid->incomp++; 3798227364Sadrian atid->cleanup_inprogress = 1; 3799227364Sadrian atid->tx_buf[atid->baw_head] = NULL; 3800227364Sadrian } 3801227364Sadrian INCR(atid->baw_head, ATH_TID_MAX_BUFS); 3802227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 3803227364Sadrian } 3804227364Sadrian 3805227364Sadrian /* 3806227364Sadrian * If cleanup is required, defer TID scheduling 3807227364Sadrian * until all the HW queued packets have been 3808227364Sadrian * sent. 3809227364Sadrian */ 3810227364Sadrian if (! atid->cleanup_inprogress) 3811227364Sadrian ath_tx_tid_resume(sc, atid); 3812227364Sadrian 3813227364Sadrian if (atid->cleanup_inprogress) 3814227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3815227364Sadrian "%s: TID %d: cleanup needed: %d packets\n", 3816227364Sadrian __func__, tid, atid->incomp); 3817243786Sadrian ATH_TX_UNLOCK(sc); 3818227364Sadrian 3819227364Sadrian /* Handle completing frames and fail them */ 3820227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3821227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3822227364Sadrian ath_tx_default_comp(sc, bf, 1); 3823227364Sadrian } 3824227364Sadrian} 3825227364Sadrian 3826227364Sadrianstatic struct ath_buf * 3827227398Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 3828227398Sadrian struct ath_tid *tid, struct ath_buf *bf) 3829227364Sadrian{ 3830227364Sadrian struct ath_buf *nbf; 3831227364Sadrian int error; 3832227364Sadrian 3833227364Sadrian nbf = ath_buf_clone(sc, bf); 3834227364Sadrian 3835227364Sadrian#if 0 3836227364Sadrian device_printf(sc->sc_dev, "%s: ATH_BUF_BUSY; cloning\n", 3837227364Sadrian __func__); 3838227364Sadrian#endif 3839227364Sadrian 3840227364Sadrian if (nbf == NULL) { 3841227364Sadrian /* Failed to clone */ 3842227364Sadrian device_printf(sc->sc_dev, 3843227364Sadrian "%s: failed to clone a busy buffer\n", 3844227364Sadrian __func__); 3845227364Sadrian return NULL; 3846227364Sadrian } 3847227364Sadrian 3848227364Sadrian /* Setup the dma for the new buffer */ 3849227364Sadrian error = ath_tx_dmasetup(sc, nbf, nbf->bf_m); 3850227364Sadrian if (error != 0) { 3851227364Sadrian device_printf(sc->sc_dev, 3852227364Sadrian "%s: failed to setup dma for clone\n", 3853227364Sadrian __func__); 3854227364Sadrian /* 3855227364Sadrian * Put this at the head of the list, not tail; 3856227364Sadrian * that way it doesn't interfere with the 3857227364Sadrian * busy buffer logic (which uses the tail of 3858227364Sadrian * the list.) 3859227364Sadrian */ 3860227364Sadrian ATH_TXBUF_LOCK(sc); 3861236994Sadrian ath_returnbuf_head(sc, nbf); 3862227364Sadrian ATH_TXBUF_UNLOCK(sc); 3863227364Sadrian return NULL; 3864227364Sadrian } 3865227364Sadrian 3866227398Sadrian /* Update BAW if required, before we free the original buf */ 3867227398Sadrian if (bf->bf_state.bfs_dobaw) 3868227398Sadrian ath_tx_switch_baw_buf(sc, an, tid, bf, nbf); 3869227398Sadrian 3870227364Sadrian /* Free current buffer; return the older buffer */ 3871227364Sadrian bf->bf_m = NULL; 3872227364Sadrian bf->bf_node = NULL; 3873227364Sadrian ath_freebuf(sc, bf); 3874240639Sadrian 3875227364Sadrian return nbf; 3876227364Sadrian} 3877227364Sadrian 3878227364Sadrian/* 3879227364Sadrian * Handle retrying an unaggregate frame in an aggregate 3880227364Sadrian * session. 3881227364Sadrian * 3882227364Sadrian * If too many retries occur, pause the TID, wait for 3883227364Sadrian * any further retransmits (as there's no reason why 3884227364Sadrian * non-aggregate frames in an aggregate session are 3885227364Sadrian * transmitted in-order; they just have to be in-BAW) 3886227364Sadrian * and then queue a BAR. 3887227364Sadrian */ 3888227364Sadrianstatic void 3889227364Sadrianath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3890227364Sadrian{ 3891227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3892227364Sadrian struct ath_node *an = ATH_NODE(ni); 3893227364Sadrian int tid = bf->bf_state.bfs_tid; 3894227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3895227364Sadrian struct ieee80211_tx_ampdu *tap; 3896227364Sadrian 3897243786Sadrian ATH_TX_LOCK(sc); 3898227364Sadrian 3899227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3900227364Sadrian 3901227364Sadrian /* 3902227364Sadrian * If the buffer is marked as busy, we can't directly 3903227364Sadrian * reuse it. Instead, try to clone the buffer. 3904227364Sadrian * If the clone is successful, recycle the old buffer. 3905227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3906227364Sadrian * to force the next bit of code to free the buffer 3907227364Sadrian * for us. 3908227364Sadrian */ 3909227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3910227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3911227364Sadrian struct ath_buf *nbf; 3912227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3913227364Sadrian if (nbf) 3914227364Sadrian /* bf has been freed at this point */ 3915227364Sadrian bf = nbf; 3916227364Sadrian else 3917227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3918227364Sadrian } 3919227364Sadrian 3920227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3921227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3922227364Sadrian "%s: exceeded retries; seqno %d\n", 3923227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3924227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3925227364Sadrian 3926227364Sadrian /* Update BAW anyway */ 3927227364Sadrian if (bf->bf_state.bfs_dobaw) { 3928227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3929227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3930227364Sadrian device_printf(sc->sc_dev, 3931227364Sadrian "%s: wasn't added: seqno %d\n", 3932227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3933227364Sadrian } 3934227364Sadrian bf->bf_state.bfs_dobaw = 0; 3935227364Sadrian 3936233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3937233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 3938227364Sadrian 3939233908Sadrian /* Send the BAR if there are no other frames waiting */ 3940233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3941233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3942227364Sadrian 3943243786Sadrian ATH_TX_UNLOCK(sc); 3944227364Sadrian 3945227364Sadrian /* Free buffer, bf is free after this call */ 3946227364Sadrian ath_tx_default_comp(sc, bf, 0); 3947227364Sadrian return; 3948227364Sadrian } 3949227364Sadrian 3950227364Sadrian /* 3951227364Sadrian * This increments the retry counter as well as 3952227364Sadrian * sets the retry flag in the ath_buf and packet 3953227364Sadrian * body. 3954227364Sadrian */ 3955227364Sadrian ath_tx_set_retry(sc, bf); 3956240639Sadrian sc->sc_stats.ast_tx_swretries++; 3957227364Sadrian 3958227364Sadrian /* 3959227364Sadrian * Insert this at the head of the queue, so it's 3960227364Sadrian * retried before any current/subsequent frames. 3961227364Sadrian */ 3962241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 3963227364Sadrian ath_tx_tid_sched(sc, atid); 3964233908Sadrian /* Send the BAR if there are no other frames waiting */ 3965233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3966233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3967227364Sadrian 3968243786Sadrian ATH_TX_UNLOCK(sc); 3969227364Sadrian} 3970227364Sadrian 3971227364Sadrian/* 3972227364Sadrian * Common code for aggregate excessive retry/subframe retry. 3973227364Sadrian * If retrying, queues buffers to bf_q. If not, frees the 3974227364Sadrian * buffers. 3975227364Sadrian * 3976227364Sadrian * XXX should unify this with ath_tx_aggr_retry_unaggr() 3977227364Sadrian */ 3978227364Sadrianstatic int 3979227364Sadrianath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf, 3980227364Sadrian ath_bufhead *bf_q) 3981227364Sadrian{ 3982227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3983227364Sadrian struct ath_node *an = ATH_NODE(ni); 3984227364Sadrian int tid = bf->bf_state.bfs_tid; 3985227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3986227364Sadrian 3987243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3988227364Sadrian 3989240255Sadrian /* XXX clr11naggr should be done for all subframes */ 3990227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 3991227364Sadrian ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0); 3992240639Sadrian 3993227364Sadrian /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */ 3994227364Sadrian 3995227364Sadrian /* 3996227364Sadrian * If the buffer is marked as busy, we can't directly 3997227364Sadrian * reuse it. Instead, try to clone the buffer. 3998227364Sadrian * If the clone is successful, recycle the old buffer. 3999227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 4000227364Sadrian * to force the next bit of code to free the buffer 4001227364Sadrian * for us. 4002227364Sadrian */ 4003227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 4004227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 4005227364Sadrian struct ath_buf *nbf; 4006227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 4007227364Sadrian if (nbf) 4008227364Sadrian /* bf has been freed at this point */ 4009227364Sadrian bf = nbf; 4010227364Sadrian else 4011227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 4012227364Sadrian } 4013227364Sadrian 4014227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 4015227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 4016227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 4017227364Sadrian "%s: max retries: seqno %d\n", 4018227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4019227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4020227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4021227364Sadrian device_printf(sc->sc_dev, 4022227364Sadrian "%s: wasn't added: seqno %d\n", 4023227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4024227364Sadrian bf->bf_state.bfs_dobaw = 0; 4025227364Sadrian return 1; 4026227364Sadrian } 4027227364Sadrian 4028227364Sadrian ath_tx_set_retry(sc, bf); 4029240639Sadrian sc->sc_stats.ast_tx_swretries++; 4030227364Sadrian bf->bf_next = NULL; /* Just to make sure */ 4031227364Sadrian 4032240255Sadrian /* Clear the aggregate state */ 4033240255Sadrian bf->bf_state.bfs_aggr = 0; 4034240255Sadrian bf->bf_state.bfs_ndelim = 0; /* ??? needed? */ 4035240255Sadrian bf->bf_state.bfs_nframes = 1; 4036240255Sadrian 4037227364Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 4038227364Sadrian return 0; 4039227364Sadrian} 4040227364Sadrian 4041227364Sadrian/* 4042227364Sadrian * error pkt completion for an aggregate destination 4043227364Sadrian */ 4044227364Sadrianstatic void 4045227364Sadrianath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first, 4046227364Sadrian struct ath_tid *tid) 4047227364Sadrian{ 4048227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4049227364Sadrian struct ath_node *an = ATH_NODE(ni); 4050227364Sadrian struct ath_buf *bf_next, *bf; 4051227364Sadrian ath_bufhead bf_q; 4052227364Sadrian int drops = 0; 4053227364Sadrian struct ieee80211_tx_ampdu *tap; 4054227364Sadrian ath_bufhead bf_cq; 4055227364Sadrian 4056227364Sadrian TAILQ_INIT(&bf_q); 4057227364Sadrian TAILQ_INIT(&bf_cq); 4058227364Sadrian 4059227364Sadrian /* 4060227364Sadrian * Update rate control - all frames have failed. 4061227364Sadrian * 4062227364Sadrian * XXX use the length in the first frame in the series; 4063227364Sadrian * XXX just so things are consistent for now. 4064227364Sadrian */ 4065227364Sadrian ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc, 4066227364Sadrian &bf_first->bf_status.ds_txstat, 4067227364Sadrian bf_first->bf_state.bfs_pktlen, 4068227364Sadrian bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes); 4069227364Sadrian 4070243786Sadrian ATH_TX_LOCK(sc); 4071227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 4072227868Sadrian sc->sc_stats.ast_tx_aggr_failall++; 4073227364Sadrian 4074227364Sadrian /* Retry all subframes */ 4075227364Sadrian bf = bf_first; 4076227364Sadrian while (bf) { 4077227364Sadrian bf_next = bf->bf_next; 4078227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 4079227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 4080227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4081227364Sadrian drops++; 4082227364Sadrian bf->bf_next = NULL; 4083227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4084227364Sadrian } 4085227364Sadrian bf = bf_next; 4086227364Sadrian } 4087227364Sadrian 4088227364Sadrian /* Prepend all frames to the beginning of the queue */ 4089227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4090227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 4091241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 4092227364Sadrian } 4093227364Sadrian 4094234725Sadrian /* 4095234725Sadrian * Schedule the TID to be re-tried. 4096234725Sadrian */ 4097227364Sadrian ath_tx_tid_sched(sc, tid); 4098227364Sadrian 4099227364Sadrian /* 4100227364Sadrian * send bar if we dropped any frames 4101227364Sadrian * 4102227364Sadrian * Keep the txq lock held for now, as we need to ensure 4103227364Sadrian * that ni_txseqs[] is consistent (as it's being updated 4104227364Sadrian * in the ifnet TX context or raw TX context.) 4105227364Sadrian */ 4106227364Sadrian if (drops) { 4107233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 4108233908Sadrian ath_tx_tid_bar_suspend(sc, tid); 4109227364Sadrian } 4110227364Sadrian 4111233908Sadrian /* 4112233908Sadrian * Send BAR if required 4113233908Sadrian */ 4114233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, tid)) 4115233908Sadrian ath_tx_tid_bar_tx(sc, tid); 4116240639Sadrian 4117243786Sadrian ATH_TX_UNLOCK(sc); 4118233908Sadrian 4119227364Sadrian /* Complete frames which errored out */ 4120227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4121227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 4122227364Sadrian ath_tx_default_comp(sc, bf, 0); 4123227364Sadrian } 4124227364Sadrian} 4125227364Sadrian 4126227364Sadrian/* 4127227364Sadrian * Handle clean-up of packets from an aggregate list. 4128227364Sadrian * 4129227364Sadrian * There's no need to update the BAW here - the session is being 4130227364Sadrian * torn down. 4131227364Sadrian */ 4132227364Sadrianstatic void 4133227364Sadrianath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first) 4134227364Sadrian{ 4135227364Sadrian struct ath_buf *bf, *bf_next; 4136227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4137227364Sadrian struct ath_node *an = ATH_NODE(ni); 4138227364Sadrian int tid = bf_first->bf_state.bfs_tid; 4139227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4140227364Sadrian 4141227364Sadrian bf = bf_first; 4142227364Sadrian 4143243786Sadrian ATH_TX_LOCK(sc); 4144227364Sadrian 4145227364Sadrian /* update incomp */ 4146227364Sadrian while (bf) { 4147227364Sadrian atid->incomp--; 4148227364Sadrian bf = bf->bf_next; 4149227364Sadrian } 4150227364Sadrian 4151227364Sadrian if (atid->incomp == 0) { 4152227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4153227364Sadrian "%s: TID %d: cleaned up! resume!\n", 4154227364Sadrian __func__, tid); 4155227364Sadrian atid->cleanup_inprogress = 0; 4156227364Sadrian ath_tx_tid_resume(sc, atid); 4157227364Sadrian } 4158233908Sadrian 4159233908Sadrian /* Send BAR if required */ 4160240639Sadrian /* XXX why would we send a BAR when transitioning to non-aggregation? */ 4161233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4162233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4163240639Sadrian 4164243786Sadrian ATH_TX_UNLOCK(sc); 4165227364Sadrian 4166227364Sadrian /* Handle frame completion */ 4167227364Sadrian while (bf) { 4168227364Sadrian bf_next = bf->bf_next; 4169227364Sadrian ath_tx_default_comp(sc, bf, 1); 4170227364Sadrian bf = bf_next; 4171227364Sadrian } 4172227364Sadrian} 4173227364Sadrian 4174227364Sadrian/* 4175227364Sadrian * Handle completion of an set of aggregate frames. 4176227364Sadrian * 4177227364Sadrian * XXX for now, simply complete each sub-frame. 4178227364Sadrian * 4179227364Sadrian * Note: the completion handler is the last descriptor in the aggregate, 4180227364Sadrian * not the last descriptor in the first frame. 4181227364Sadrian */ 4182227364Sadrianstatic void 4183229949Sadrianath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first, 4184229949Sadrian int fail) 4185227364Sadrian{ 4186227364Sadrian //struct ath_desc *ds = bf->bf_lastds; 4187227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4188227364Sadrian struct ath_node *an = ATH_NODE(ni); 4189227364Sadrian int tid = bf_first->bf_state.bfs_tid; 4190227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4191227364Sadrian struct ath_tx_status ts; 4192227364Sadrian struct ieee80211_tx_ampdu *tap; 4193227364Sadrian ath_bufhead bf_q; 4194227364Sadrian ath_bufhead bf_cq; 4195227364Sadrian int seq_st, tx_ok; 4196227364Sadrian int hasba, isaggr; 4197227364Sadrian uint32_t ba[2]; 4198227364Sadrian struct ath_buf *bf, *bf_next; 4199227364Sadrian int ba_index; 4200227364Sadrian int drops = 0; 4201227364Sadrian int nframes = 0, nbad = 0, nf; 4202227364Sadrian int pktlen; 4203227364Sadrian /* XXX there's too much on the stack? */ 4204236038Sadrian struct ath_rc_series rc[ATH_RC_NUM]; 4205227364Sadrian int txseq; 4206227364Sadrian 4207227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n", 4208227364Sadrian __func__, atid->hwq_depth); 4209227364Sadrian 4210240677Sadrian /* 4211240677Sadrian * Take a copy; this may be needed -after- bf_first 4212240677Sadrian * has been completed and freed. 4213240677Sadrian */ 4214240677Sadrian ts = bf_first->bf_status.ds_txstat; 4215240677Sadrian 4216240639Sadrian TAILQ_INIT(&bf_q); 4217240639Sadrian TAILQ_INIT(&bf_cq); 4218240639Sadrian 4219227364Sadrian /* The TID state is kept behind the TXQ lock */ 4220243786Sadrian ATH_TX_LOCK(sc); 4221227364Sadrian 4222227364Sadrian atid->hwq_depth--; 4223227364Sadrian if (atid->hwq_depth < 0) 4224227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4225227364Sadrian __func__, atid->hwq_depth); 4226227364Sadrian 4227227364Sadrian /* 4228240639Sadrian * If the TID is filtered, handle completing the filter 4229240639Sadrian * transition before potentially kicking it to the cleanup 4230240639Sadrian * function. 4231240677Sadrian * 4232240677Sadrian * XXX this is duplicate work, ew. 4233240639Sadrian */ 4234240639Sadrian if (atid->isfiltered) 4235240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4236240639Sadrian 4237240639Sadrian /* 4238227364Sadrian * Punt cleanup to the relevant function, not our problem now 4239227364Sadrian */ 4240227364Sadrian if (atid->cleanup_inprogress) { 4241240639Sadrian if (atid->isfiltered) 4242240639Sadrian device_printf(sc->sc_dev, 4243240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4244240639Sadrian __func__); 4245243786Sadrian ATH_TX_UNLOCK(sc); 4246227364Sadrian ath_tx_comp_cleanup_aggr(sc, bf_first); 4247227364Sadrian return; 4248227364Sadrian } 4249227364Sadrian 4250227364Sadrian /* 4251240639Sadrian * If the frame is filtered, transition to filtered frame 4252240639Sadrian * mode and add this to the filtered frame list. 4253240639Sadrian * 4254240639Sadrian * XXX TODO: figure out how this interoperates with 4255240639Sadrian * BAR, pause and cleanup states. 4256240639Sadrian */ 4257240639Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4258240639Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4259240639Sadrian if (fail != 0) 4260240639Sadrian device_printf(sc->sc_dev, 4261240639Sadrian "%s: isfiltered=1, fail=%d\n", __func__, fail); 4262240639Sadrian ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq); 4263240639Sadrian 4264240639Sadrian /* Remove from BAW */ 4265240639Sadrian TAILQ_FOREACH_SAFE(bf, &bf_cq, bf_list, bf_next) { 4266240639Sadrian if (bf->bf_state.bfs_addedbaw) 4267240639Sadrian drops++; 4268240639Sadrian if (bf->bf_state.bfs_dobaw) { 4269240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4270240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4271240639Sadrian device_printf(sc->sc_dev, 4272240639Sadrian "%s: wasn't added: seqno %d\n", 4273240639Sadrian __func__, 4274240639Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4275240639Sadrian } 4276240639Sadrian bf->bf_state.bfs_dobaw = 0; 4277240639Sadrian } 4278240639Sadrian /* 4279240639Sadrian * If any intermediate frames in the BAW were dropped when 4280240639Sadrian * handling filtering things, send a BAR. 4281240639Sadrian */ 4282240639Sadrian if (drops) 4283240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4284240639Sadrian 4285240639Sadrian /* 4286240639Sadrian * Finish up by sending a BAR if required and freeing 4287240639Sadrian * the frames outside of the TX lock. 4288240639Sadrian */ 4289240639Sadrian goto finish_send_bar; 4290240639Sadrian } 4291240639Sadrian 4292240639Sadrian /* 4293227364Sadrian * XXX for now, use the first frame in the aggregate for 4294227364Sadrian * XXX rate control completion; it's at least consistent. 4295227364Sadrian */ 4296227364Sadrian pktlen = bf_first->bf_state.bfs_pktlen; 4297227364Sadrian 4298227364Sadrian /* 4299235461Sadrian * Handle errors first! 4300235461Sadrian * 4301235461Sadrian * Here, handle _any_ error as a "exceeded retries" error. 4302235461Sadrian * Later on (when filtered frames are to be specially handled) 4303235461Sadrian * it'll have to be expanded. 4304227364Sadrian */ 4305235461Sadrian#if 0 4306227364Sadrian if (ts.ts_status & HAL_TXERR_XRETRY) { 4307235461Sadrian#endif 4308235461Sadrian if (ts.ts_status != 0) { 4309243786Sadrian ATH_TX_UNLOCK(sc); 4310227364Sadrian ath_tx_comp_aggr_error(sc, bf_first, atid); 4311227364Sadrian return; 4312227364Sadrian } 4313227364Sadrian 4314227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4315227364Sadrian 4316227364Sadrian /* 4317227364Sadrian * extract starting sequence and block-ack bitmap 4318227364Sadrian */ 4319227364Sadrian /* XXX endian-ness of seq_st, ba? */ 4320227364Sadrian seq_st = ts.ts_seqnum; 4321227364Sadrian hasba = !! (ts.ts_flags & HAL_TX_BA); 4322227364Sadrian tx_ok = (ts.ts_status == 0); 4323227364Sadrian isaggr = bf_first->bf_state.bfs_aggr; 4324227364Sadrian ba[0] = ts.ts_ba_low; 4325227364Sadrian ba[1] = ts.ts_ba_high; 4326227364Sadrian 4327227364Sadrian /* 4328227364Sadrian * Copy the TX completion status and the rate control 4329227364Sadrian * series from the first descriptor, as it may be freed 4330227364Sadrian * before the rate control code can get its grubby fingers 4331227364Sadrian * into things. 4332227364Sadrian */ 4333227364Sadrian memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc)); 4334227364Sadrian 4335227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4336229949Sadrian "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, " 4337229949Sadrian "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n", 4338227364Sadrian __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags, 4339227364Sadrian isaggr, seq_st, hasba, ba[0], ba[1]); 4340227364Sadrian 4341227364Sadrian /* Occasionally, the MAC sends a tx status for the wrong TID. */ 4342227364Sadrian if (tid != ts.ts_tid) { 4343227364Sadrian device_printf(sc->sc_dev, "%s: tid %d != hw tid %d\n", 4344227364Sadrian __func__, tid, ts.ts_tid); 4345227364Sadrian tx_ok = 0; 4346227364Sadrian } 4347227364Sadrian 4348227364Sadrian /* AR5416 BA bug; this requires an interface reset */ 4349227364Sadrian if (isaggr && tx_ok && (! hasba)) { 4350227364Sadrian device_printf(sc->sc_dev, 4351229949Sadrian "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, " 4352229949Sadrian "seq_st=%d\n", 4353227364Sadrian __func__, hasba, tx_ok, isaggr, seq_st); 4354227364Sadrian /* XXX TODO: schedule an interface reset */ 4355238350Sjhb#ifdef ATH_DEBUG 4356238338Sadrian ath_printtxbuf(sc, bf_first, 4357238338Sadrian sc->sc_ac2q[atid->ac]->axq_qnum, 0, 0); 4358238350Sjhb#endif 4359227364Sadrian } 4360227364Sadrian 4361227364Sadrian /* 4362227364Sadrian * Walk the list of frames, figure out which ones were correctly 4363227364Sadrian * sent and which weren't. 4364227364Sadrian */ 4365227364Sadrian bf = bf_first; 4366227364Sadrian nf = bf_first->bf_state.bfs_nframes; 4367227364Sadrian 4368227364Sadrian /* bf_first is going to be invalid once this list is walked */ 4369227364Sadrian bf_first = NULL; 4370227364Sadrian 4371227364Sadrian /* 4372227364Sadrian * Walk the list of completed frames and determine 4373227364Sadrian * which need to be completed and which need to be 4374227364Sadrian * retransmitted. 4375227364Sadrian * 4376227364Sadrian * For completed frames, the completion functions need 4377227364Sadrian * to be called at the end of this function as the last 4378227364Sadrian * node reference may free the node. 4379227364Sadrian * 4380227364Sadrian * Finally, since the TXQ lock can't be held during the 4381227364Sadrian * completion callback (to avoid lock recursion), 4382227364Sadrian * the completion calls have to be done outside of the 4383227364Sadrian * lock. 4384227364Sadrian */ 4385227364Sadrian while (bf) { 4386227364Sadrian nframes++; 4387229949Sadrian ba_index = ATH_BA_INDEX(seq_st, 4388229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4389227364Sadrian bf_next = bf->bf_next; 4390227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 4391227364Sadrian 4392227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4393227364Sadrian "%s: checking bf=%p seqno=%d; ack=%d\n", 4394227364Sadrian __func__, bf, SEQNO(bf->bf_state.bfs_seqno), 4395227364Sadrian ATH_BA_ISSET(ba, ba_index)); 4396227364Sadrian 4397227364Sadrian if (tx_ok && ATH_BA_ISSET(ba, ba_index)) { 4398227868Sadrian sc->sc_stats.ast_tx_aggr_ok++; 4399227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4400227364Sadrian bf->bf_state.bfs_dobaw = 0; 4401227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4402227364Sadrian device_printf(sc->sc_dev, 4403227364Sadrian "%s: wasn't added: seqno %d\n", 4404227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4405227364Sadrian bf->bf_next = NULL; 4406227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4407227364Sadrian } else { 4408227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 4409227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4410227364Sadrian drops++; 4411227364Sadrian bf->bf_next = NULL; 4412227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4413227364Sadrian } 4414227364Sadrian nbad++; 4415227364Sadrian } 4416227364Sadrian bf = bf_next; 4417227364Sadrian } 4418227364Sadrian 4419227364Sadrian /* 4420227364Sadrian * Now that the BAW updates have been done, unlock 4421227364Sadrian * 4422227364Sadrian * txseq is grabbed before the lock is released so we 4423227364Sadrian * have a consistent view of what -was- in the BAW. 4424227364Sadrian * Anything after this point will not yet have been 4425227364Sadrian * TXed. 4426227364Sadrian */ 4427227364Sadrian txseq = tap->txa_start; 4428243786Sadrian ATH_TX_UNLOCK(sc); 4429227364Sadrian 4430227364Sadrian if (nframes != nf) 4431227364Sadrian device_printf(sc->sc_dev, 4432227364Sadrian "%s: num frames seen=%d; bf nframes=%d\n", 4433227364Sadrian __func__, nframes, nf); 4434227364Sadrian 4435227364Sadrian /* 4436227364Sadrian * Now we know how many frames were bad, call the rate 4437227364Sadrian * control code. 4438227364Sadrian */ 4439227364Sadrian if (fail == 0) 4440229949Sadrian ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes, 4441229949Sadrian nbad); 4442227364Sadrian 4443227364Sadrian /* 4444227364Sadrian * send bar if we dropped any frames 4445227364Sadrian */ 4446227364Sadrian if (drops) { 4447233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 4448243786Sadrian ATH_TX_LOCK(sc); 4449233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 4450243786Sadrian ATH_TX_UNLOCK(sc); 4451227364Sadrian } 4452227364Sadrian 4453234725Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4454234725Sadrian "%s: txa_start now %d\n", __func__, tap->txa_start); 4455234725Sadrian 4456243786Sadrian ATH_TX_LOCK(sc); 4457234725Sadrian 4458227364Sadrian /* Prepend all frames to the beginning of the queue */ 4459227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4460227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 4461241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 4462227364Sadrian } 4463234725Sadrian 4464234725Sadrian /* 4465234725Sadrian * Reschedule to grab some further frames. 4466234725Sadrian */ 4467227364Sadrian ath_tx_tid_sched(sc, atid); 4468227364Sadrian 4469233908Sadrian /* 4470240639Sadrian * If the queue is filtered, re-schedule as required. 4471240639Sadrian * 4472240639Sadrian * This is required as there may be a subsequent TX descriptor 4473240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4474240639Sadrian * that a filtered frame will be followed by a non-filtered 4475240639Sadrian * (complete or otherwise) frame. 4476240639Sadrian * 4477240639Sadrian * XXX should we do this before we complete the frame? 4478240639Sadrian */ 4479240639Sadrian if (atid->isfiltered) 4480240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4481240639Sadrian 4482240639Sadrianfinish_send_bar: 4483240639Sadrian 4484240639Sadrian /* 4485233908Sadrian * Send BAR if required 4486233908Sadrian */ 4487233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4488233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4489234725Sadrian 4490243786Sadrian ATH_TX_UNLOCK(sc); 4491233908Sadrian 4492227364Sadrian /* Do deferred completion */ 4493227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4494227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 4495227364Sadrian ath_tx_default_comp(sc, bf, 0); 4496227364Sadrian } 4497227364Sadrian} 4498227364Sadrian 4499227364Sadrian/* 4500227364Sadrian * Handle completion of unaggregated frames in an ADDBA 4501227364Sadrian * session. 4502227364Sadrian * 4503227364Sadrian * Fail is set to 1 if the entry is being freed via a call to 4504227364Sadrian * ath_tx_draintxq(). 4505227364Sadrian */ 4506227364Sadrianstatic void 4507227364Sadrianath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail) 4508227364Sadrian{ 4509227364Sadrian struct ieee80211_node *ni = bf->bf_node; 4510227364Sadrian struct ath_node *an = ATH_NODE(ni); 4511227364Sadrian int tid = bf->bf_state.bfs_tid; 4512227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4513240677Sadrian struct ath_tx_status ts; 4514240639Sadrian int drops = 0; 4515227364Sadrian 4516227364Sadrian /* 4517240677Sadrian * Take a copy of this; filtering/cloning the frame may free the 4518240677Sadrian * bf pointer. 4519240677Sadrian */ 4520240677Sadrian ts = bf->bf_status.ds_txstat; 4521240677Sadrian 4522240677Sadrian /* 4523227364Sadrian * Update rate control status here, before we possibly 4524227364Sadrian * punt to retry or cleanup. 4525227364Sadrian * 4526227364Sadrian * Do it outside of the TXQ lock. 4527227364Sadrian */ 4528233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 4529227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 4530227364Sadrian &bf->bf_status.ds_txstat, 4531227364Sadrian bf->bf_state.bfs_pktlen, 4532240677Sadrian 1, (ts.ts_status == 0) ? 0 : 1); 4533227364Sadrian 4534227364Sadrian /* 4535227364Sadrian * This is called early so atid->hwq_depth can be tracked. 4536227364Sadrian * This unfortunately means that it's released and regrabbed 4537227364Sadrian * during retry and cleanup. That's rather inefficient. 4538227364Sadrian */ 4539243786Sadrian ATH_TX_LOCK(sc); 4540227364Sadrian 4541227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4542227364Sadrian device_printf(sc->sc_dev, "%s: TID=16!\n", __func__); 4543227364Sadrian 4544229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 4545229949Sadrian "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n", 4546229949Sadrian __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth, 4547229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4548227364Sadrian 4549227364Sadrian atid->hwq_depth--; 4550227364Sadrian if (atid->hwq_depth < 0) 4551227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4552227364Sadrian __func__, atid->hwq_depth); 4553227364Sadrian 4554227364Sadrian /* 4555240639Sadrian * If the TID is filtered, handle completing the filter 4556240639Sadrian * transition before potentially kicking it to the cleanup 4557240639Sadrian * function. 4558240639Sadrian */ 4559240639Sadrian if (atid->isfiltered) 4560240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4561240639Sadrian 4562240639Sadrian /* 4563227364Sadrian * If a cleanup is in progress, punt to comp_cleanup; 4564227364Sadrian * rather than handling it here. It's thus their 4565227364Sadrian * responsibility to clean up, call the completion 4566227364Sadrian * function in net80211, etc. 4567227364Sadrian */ 4568227364Sadrian if (atid->cleanup_inprogress) { 4569240639Sadrian if (atid->isfiltered) 4570240639Sadrian device_printf(sc->sc_dev, 4571240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4572240639Sadrian __func__); 4573243786Sadrian ATH_TX_UNLOCK(sc); 4574229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n", 4575229949Sadrian __func__); 4576227364Sadrian ath_tx_comp_cleanup_unaggr(sc, bf); 4577227364Sadrian return; 4578227364Sadrian } 4579227364Sadrian 4580227364Sadrian /* 4581240639Sadrian * XXX TODO: how does cleanup, BAR and filtered frame handling 4582240639Sadrian * overlap? 4583240639Sadrian * 4584240639Sadrian * If the frame is filtered OR if it's any failure but 4585240639Sadrian * the TID is filtered, the frame must be added to the 4586240639Sadrian * filtered frame list. 4587240639Sadrian * 4588240639Sadrian * However - a busy buffer can't be added to the filtered 4589240639Sadrian * list as it will end up being recycled without having 4590240639Sadrian * been made available for the hardware. 4591240639Sadrian */ 4592240677Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4593240677Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4594240639Sadrian int freeframe; 4595240639Sadrian 4596240639Sadrian if (fail != 0) 4597240639Sadrian device_printf(sc->sc_dev, 4598240639Sadrian "%s: isfiltered=1, fail=%d\n", 4599240639Sadrian __func__, 4600240639Sadrian fail); 4601240639Sadrian freeframe = ath_tx_tid_filt_comp_single(sc, atid, bf); 4602240639Sadrian if (freeframe) { 4603240639Sadrian /* Remove from BAW */ 4604240639Sadrian if (bf->bf_state.bfs_addedbaw) 4605240639Sadrian drops++; 4606240639Sadrian if (bf->bf_state.bfs_dobaw) { 4607240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4608240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4609240639Sadrian device_printf(sc->sc_dev, 4610240639Sadrian "%s: wasn't added: seqno %d\n", 4611240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4612240639Sadrian } 4613240639Sadrian bf->bf_state.bfs_dobaw = 0; 4614240639Sadrian } 4615240639Sadrian 4616240639Sadrian /* 4617240639Sadrian * If the frame couldn't be filtered, treat it as a drop and 4618240639Sadrian * prepare to send a BAR. 4619240639Sadrian */ 4620240639Sadrian if (freeframe && drops) 4621240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4622240639Sadrian 4623240639Sadrian /* 4624240639Sadrian * Send BAR if required 4625240639Sadrian */ 4626240639Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4627240639Sadrian ath_tx_tid_bar_tx(sc, atid); 4628240639Sadrian 4629243786Sadrian ATH_TX_UNLOCK(sc); 4630240639Sadrian /* 4631240639Sadrian * If freeframe is set, then the frame couldn't be 4632240639Sadrian * cloned and bf is still valid. Just complete/free it. 4633240639Sadrian */ 4634240639Sadrian if (freeframe) 4635240639Sadrian ath_tx_default_comp(sc, bf, fail); 4636240639Sadrian 4637240639Sadrian 4638240639Sadrian return; 4639240639Sadrian } 4640240639Sadrian /* 4641227364Sadrian * Don't bother with the retry check if all frames 4642227364Sadrian * are being failed (eg during queue deletion.) 4643227364Sadrian */ 4644235461Sadrian#if 0 4645227364Sadrian if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) { 4646235461Sadrian#endif 4647240677Sadrian if (fail == 0 && ts.ts_status != 0) { 4648243786Sadrian ATH_TX_UNLOCK(sc); 4649229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n", 4650229949Sadrian __func__); 4651227364Sadrian ath_tx_aggr_retry_unaggr(sc, bf); 4652227364Sadrian return; 4653227364Sadrian } 4654227364Sadrian 4655227364Sadrian /* Success? Complete */ 4656227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n", 4657227364Sadrian __func__, tid, SEQNO(bf->bf_state.bfs_seqno)); 4658227364Sadrian if (bf->bf_state.bfs_dobaw) { 4659227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4660227364Sadrian bf->bf_state.bfs_dobaw = 0; 4661227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4662227364Sadrian device_printf(sc->sc_dev, 4663227364Sadrian "%s: wasn't added: seqno %d\n", 4664227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4665227364Sadrian } 4666227364Sadrian 4667233908Sadrian /* 4668240639Sadrian * If the queue is filtered, re-schedule as required. 4669240639Sadrian * 4670240639Sadrian * This is required as there may be a subsequent TX descriptor 4671240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4672240639Sadrian * that a filtered frame will be followed by a non-filtered 4673240639Sadrian * (complete or otherwise) frame. 4674240639Sadrian * 4675240639Sadrian * XXX should we do this before we complete the frame? 4676240639Sadrian */ 4677240639Sadrian if (atid->isfiltered) 4678240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4679240639Sadrian 4680240639Sadrian /* 4681233908Sadrian * Send BAR if required 4682233908Sadrian */ 4683233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4684233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4685233908Sadrian 4686243786Sadrian ATH_TX_UNLOCK(sc); 4687227364Sadrian 4688227364Sadrian ath_tx_default_comp(sc, bf, fail); 4689227364Sadrian /* bf is freed at this point */ 4690227364Sadrian} 4691227364Sadrian 4692227364Sadrianvoid 4693227364Sadrianath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 4694227364Sadrian{ 4695227364Sadrian if (bf->bf_state.bfs_aggr) 4696227364Sadrian ath_tx_aggr_comp_aggr(sc, bf, fail); 4697227364Sadrian else 4698227364Sadrian ath_tx_aggr_comp_unaggr(sc, bf, fail); 4699227364Sadrian} 4700227364Sadrian 4701227364Sadrian/* 4702227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4703227364Sadrian * 4704227364Sadrian * This is the aggregate version. 4705227364Sadrian */ 4706227364Sadrianvoid 4707227364Sadrianath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an, 4708227364Sadrian struct ath_tid *tid) 4709227364Sadrian{ 4710227364Sadrian struct ath_buf *bf; 4711227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4712227364Sadrian struct ieee80211_tx_ampdu *tap; 4713227364Sadrian ATH_AGGR_STATUS status; 4714227364Sadrian ath_bufhead bf_q; 4715227364Sadrian 4716227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid); 4717243786Sadrian ATH_TX_LOCK_ASSERT(sc); 4718227364Sadrian 4719227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 4720227364Sadrian 4721227364Sadrian if (tid->tid == IEEE80211_NONQOS_TID) 4722227364Sadrian device_printf(sc->sc_dev, "%s: called for TID=NONQOS_TID?\n", 4723227364Sadrian __func__); 4724227364Sadrian 4725227364Sadrian for (;;) { 4726227364Sadrian status = ATH_AGGR_DONE; 4727227364Sadrian 4728227364Sadrian /* 4729227364Sadrian * If the upper layer has paused the TID, don't 4730227364Sadrian * queue any further packets. 4731227364Sadrian * 4732227364Sadrian * This can also occur from the completion task because 4733227364Sadrian * of packet loss; but as its serialised with this code, 4734227364Sadrian * it won't "appear" half way through queuing packets. 4735227364Sadrian */ 4736227364Sadrian if (tid->paused) 4737227364Sadrian break; 4738227364Sadrian 4739241336Sadrian bf = ATH_TID_FIRST(tid); 4740227364Sadrian if (bf == NULL) { 4741227364Sadrian break; 4742227364Sadrian } 4743227364Sadrian 4744227364Sadrian /* 4745227364Sadrian * If the packet doesn't fall within the BAW (eg a NULL 4746227364Sadrian * data frame), schedule it directly; continue. 4747227364Sadrian */ 4748227364Sadrian if (! bf->bf_state.bfs_dobaw) { 4749229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4750229949Sadrian "%s: non-baw packet\n", 4751227364Sadrian __func__); 4752241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 4753240180Sadrian 4754240180Sadrian if (bf->bf_state.bfs_nframes > 1) 4755240180Sadrian device_printf(sc->sc_dev, 4756240180Sadrian "%s: aggr=%d, nframes=%d\n", 4757240180Sadrian __func__, 4758240180Sadrian bf->bf_state.bfs_aggr, 4759240180Sadrian bf->bf_state.bfs_nframes); 4760240180Sadrian 4761240180Sadrian /* 4762240180Sadrian * This shouldn't happen - such frames shouldn't 4763240180Sadrian * ever have been queued as an aggregate in the 4764240180Sadrian * first place. However, make sure the fields 4765240180Sadrian * are correctly setup just to be totally sure. 4766240180Sadrian */ 4767227364Sadrian bf->bf_state.bfs_aggr = 0; 4768240180Sadrian bf->bf_state.bfs_nframes = 1; 4769240180Sadrian 4770240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4771240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4772240724Sadrian 4773227364Sadrian ath_tx_do_ratelookup(sc, bf); 4774233989Sadrian ath_tx_calc_duration(sc, bf); 4775233989Sadrian ath_tx_calc_protection(sc, bf); 4776233989Sadrian ath_tx_set_rtscts(sc, bf); 4777227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4778227364Sadrian ath_tx_setds(sc, bf); 4779227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4780227364Sadrian 4781227364Sadrian sc->sc_aggr_stats.aggr_nonbaw_pkt++; 4782227364Sadrian 4783227364Sadrian /* Queue the packet; continue */ 4784227364Sadrian goto queuepkt; 4785227364Sadrian } 4786227364Sadrian 4787227364Sadrian TAILQ_INIT(&bf_q); 4788227364Sadrian 4789227364Sadrian /* 4790227364Sadrian * Do a rate control lookup on the first frame in the 4791227364Sadrian * list. The rate control code needs that to occur 4792227364Sadrian * before it can determine whether to TX. 4793227364Sadrian * It's inaccurate because the rate control code doesn't 4794227364Sadrian * really "do" aggregate lookups, so it only considers 4795227364Sadrian * the size of the first frame. 4796227364Sadrian */ 4797227364Sadrian ath_tx_do_ratelookup(sc, bf); 4798227364Sadrian bf->bf_state.bfs_rc[3].rix = 0; 4799227364Sadrian bf->bf_state.bfs_rc[3].tries = 0; 4800233989Sadrian 4801233989Sadrian ath_tx_calc_duration(sc, bf); 4802233989Sadrian ath_tx_calc_protection(sc, bf); 4803233989Sadrian 4804233989Sadrian ath_tx_set_rtscts(sc, bf); 4805227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4806227364Sadrian 4807227364Sadrian status = ath_tx_form_aggr(sc, an, tid, &bf_q); 4808227364Sadrian 4809227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4810227364Sadrian "%s: ath_tx_form_aggr() status=%d\n", __func__, status); 4811227364Sadrian 4812227364Sadrian /* 4813227364Sadrian * No frames to be picked up - out of BAW 4814227364Sadrian */ 4815227364Sadrian if (TAILQ_EMPTY(&bf_q)) 4816227364Sadrian break; 4817227364Sadrian 4818227364Sadrian /* 4819227364Sadrian * This assumes that the descriptor list in the ath_bufhead 4820227364Sadrian * are already linked together via bf_next pointers. 4821227364Sadrian */ 4822227364Sadrian bf = TAILQ_FIRST(&bf_q); 4823227364Sadrian 4824233989Sadrian if (status == ATH_AGGR_8K_LIMITED) 4825233989Sadrian sc->sc_aggr_stats.aggr_rts_aggr_limited++; 4826233989Sadrian 4827227364Sadrian /* 4828227364Sadrian * If it's the only frame send as non-aggregate 4829227364Sadrian * assume that ath_tx_form_aggr() has checked 4830227364Sadrian * whether it's in the BAW and added it appropriately. 4831227364Sadrian */ 4832227364Sadrian if (bf->bf_state.bfs_nframes == 1) { 4833227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4834227364Sadrian "%s: single-frame aggregate\n", __func__); 4835240724Sadrian 4836240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4837240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4838240724Sadrian 4839227364Sadrian bf->bf_state.bfs_aggr = 0; 4840240255Sadrian bf->bf_state.bfs_ndelim = 0; 4841227364Sadrian ath_tx_setds(sc, bf); 4842227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4843227364Sadrian if (status == ATH_AGGR_BAW_CLOSED) 4844227364Sadrian sc->sc_aggr_stats.aggr_baw_closed_single_pkt++; 4845227364Sadrian else 4846227364Sadrian sc->sc_aggr_stats.aggr_single_pkt++; 4847227364Sadrian } else { 4848227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4849229949Sadrian "%s: multi-frame aggregate: %d frames, " 4850229949Sadrian "length %d\n", 4851227364Sadrian __func__, bf->bf_state.bfs_nframes, 4852227364Sadrian bf->bf_state.bfs_al); 4853227364Sadrian bf->bf_state.bfs_aggr = 1; 4854227364Sadrian sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++; 4855227364Sadrian sc->sc_aggr_stats.aggr_aggr_pkt++; 4856227364Sadrian 4857240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4858240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4859240724Sadrian 4860227364Sadrian /* 4861233989Sadrian * Calculate the duration/protection as required. 4862233989Sadrian */ 4863233989Sadrian ath_tx_calc_duration(sc, bf); 4864233989Sadrian ath_tx_calc_protection(sc, bf); 4865233989Sadrian 4866233989Sadrian /* 4867227364Sadrian * Update the rate and rtscts information based on the 4868227364Sadrian * rate decision made by the rate control code; 4869227364Sadrian * the first frame in the aggregate needs it. 4870227364Sadrian */ 4871227364Sadrian ath_tx_set_rtscts(sc, bf); 4872227364Sadrian 4873227364Sadrian /* 4874227364Sadrian * Setup the relevant descriptor fields 4875227364Sadrian * for aggregation. The first descriptor 4876227364Sadrian * already points to the rest in the chain. 4877227364Sadrian */ 4878227364Sadrian ath_tx_setds_11n(sc, bf); 4879227364Sadrian 4880227364Sadrian } 4881227364Sadrian queuepkt: 4882227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 4883227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 4884227364Sadrian 4885227364Sadrian if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID) 4886227364Sadrian device_printf(sc->sc_dev, "%s: TID=16?\n", __func__); 4887227364Sadrian 4888227364Sadrian /* Punt to txq */ 4889227364Sadrian ath_tx_handoff(sc, txq, bf); 4890227364Sadrian 4891227364Sadrian /* Track outstanding buffer count to hardware */ 4892227364Sadrian /* aggregates are "one" buffer */ 4893227364Sadrian tid->hwq_depth++; 4894227364Sadrian 4895227364Sadrian /* 4896227364Sadrian * Break out if ath_tx_form_aggr() indicated 4897227364Sadrian * there can't be any further progress (eg BAW is full.) 4898227364Sadrian * Checking for an empty txq is done above. 4899227364Sadrian * 4900227364Sadrian * XXX locking on txq here? 4901227364Sadrian */ 4902227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit || 4903227364Sadrian status == ATH_AGGR_BAW_CLOSED) 4904227364Sadrian break; 4905227364Sadrian } 4906227364Sadrian} 4907227364Sadrian 4908227364Sadrian/* 4909227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4910227364Sadrian */ 4911227364Sadrianvoid 4912227364Sadrianath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an, 4913227364Sadrian struct ath_tid *tid) 4914227364Sadrian{ 4915227364Sadrian struct ath_buf *bf; 4916227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4917227364Sadrian 4918227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n", 4919227364Sadrian __func__, an, tid->tid); 4920227364Sadrian 4921243786Sadrian ATH_TX_LOCK_ASSERT(sc); 4922227364Sadrian 4923227364Sadrian /* Check - is AMPDU pending or running? then print out something */ 4924227364Sadrian if (ath_tx_ampdu_pending(sc, an, tid->tid)) 4925227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu pending?\n", 4926227364Sadrian __func__, tid->tid); 4927227364Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid)) 4928227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu running?\n", 4929227364Sadrian __func__, tid->tid); 4930227364Sadrian 4931227364Sadrian for (;;) { 4932227364Sadrian 4933227364Sadrian /* 4934227364Sadrian * If the upper layers have paused the TID, don't 4935227364Sadrian * queue any further packets. 4936227364Sadrian */ 4937227364Sadrian if (tid->paused) 4938227364Sadrian break; 4939227364Sadrian 4940241336Sadrian bf = ATH_TID_FIRST(tid); 4941227364Sadrian if (bf == NULL) { 4942227364Sadrian break; 4943227364Sadrian } 4944227364Sadrian 4945241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 4946227364Sadrian 4947227364Sadrian /* Sanity check! */ 4948227364Sadrian if (tid->tid != bf->bf_state.bfs_tid) { 4949227364Sadrian device_printf(sc->sc_dev, "%s: bfs_tid %d !=" 4950227364Sadrian " tid %d\n", 4951227364Sadrian __func__, bf->bf_state.bfs_tid, tid->tid); 4952227364Sadrian } 4953227364Sadrian /* Normal completion handler */ 4954227364Sadrian bf->bf_comp = ath_tx_normal_comp; 4955227364Sadrian 4956240883Sadrian /* 4957240883Sadrian * Override this for now, until the non-aggregate 4958240883Sadrian * completion handler correctly handles software retransmits. 4959240883Sadrian */ 4960240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 4961240883Sadrian 4962240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4963240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4964240724Sadrian 4965227364Sadrian /* Program descriptors + rate control */ 4966227364Sadrian ath_tx_do_ratelookup(sc, bf); 4967233989Sadrian ath_tx_calc_duration(sc, bf); 4968233989Sadrian ath_tx_calc_protection(sc, bf); 4969233989Sadrian ath_tx_set_rtscts(sc, bf); 4970227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4971227364Sadrian ath_tx_setds(sc, bf); 4972227364Sadrian 4973227364Sadrian /* Track outstanding buffer count to hardware */ 4974227364Sadrian /* aggregates are "one" buffer */ 4975227364Sadrian tid->hwq_depth++; 4976227364Sadrian 4977227364Sadrian /* Punt to hardware or software txq */ 4978227364Sadrian ath_tx_handoff(sc, txq, bf); 4979227364Sadrian } 4980227364Sadrian} 4981227364Sadrian 4982227364Sadrian/* 4983227364Sadrian * Schedule some packets to the given hardware queue. 4984227364Sadrian * 4985227364Sadrian * This function walks the list of TIDs (ie, ath_node TIDs 4986227364Sadrian * with queued traffic) and attempts to schedule traffic 4987227364Sadrian * from them. 4988227364Sadrian * 4989227364Sadrian * TID scheduling is implemented as a FIFO, with TIDs being 4990227364Sadrian * added to the end of the queue after some frames have been 4991227364Sadrian * scheduled. 4992227364Sadrian */ 4993227364Sadrianvoid 4994227364Sadrianath_txq_sched(struct ath_softc *sc, struct ath_txq *txq) 4995227364Sadrian{ 4996227364Sadrian struct ath_tid *tid, *next, *last; 4997227364Sadrian 4998243786Sadrian ATH_TX_LOCK_ASSERT(sc); 4999227364Sadrian 5000227364Sadrian /* 5001227364Sadrian * Don't schedule if the hardware queue is busy. 5002227364Sadrian * This (hopefully) gives some more time to aggregate 5003227364Sadrian * some packets in the aggregation queue. 5004227364Sadrian */ 5005227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 5006227364Sadrian sc->sc_aggr_stats.aggr_sched_nopkt++; 5007227364Sadrian return; 5008227364Sadrian } 5009227364Sadrian 5010227364Sadrian last = TAILQ_LAST(&txq->axq_tidq, axq_t_s); 5011227364Sadrian 5012227364Sadrian TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) { 5013227364Sadrian /* 5014227364Sadrian * Suspend paused queues here; they'll be resumed 5015227364Sadrian * once the addba completes or times out. 5016227364Sadrian */ 5017227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n", 5018227364Sadrian __func__, tid->tid, tid->paused); 5019227364Sadrian ath_tx_tid_unsched(sc, tid); 5020227364Sadrian if (tid->paused) { 5021227364Sadrian continue; 5022227364Sadrian } 5023227364Sadrian if (ath_tx_ampdu_running(sc, tid->an, tid->tid)) 5024227364Sadrian ath_tx_tid_hw_queue_aggr(sc, tid->an, tid); 5025227364Sadrian else 5026227364Sadrian ath_tx_tid_hw_queue_norm(sc, tid->an, tid); 5027227364Sadrian 5028227364Sadrian /* Not empty? Re-schedule */ 5029227364Sadrian if (tid->axq_depth != 0) 5030227364Sadrian ath_tx_tid_sched(sc, tid); 5031227364Sadrian 5032227364Sadrian /* Give the software queue time to aggregate more packets */ 5033227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 5034227364Sadrian break; 5035227364Sadrian } 5036227364Sadrian 5037227364Sadrian /* 5038227364Sadrian * If this was the last entry on the original list, stop. 5039227364Sadrian * Otherwise nodes that have been rescheduled onto the end 5040227364Sadrian * of the TID FIFO list will just keep being rescheduled. 5041227364Sadrian */ 5042227364Sadrian if (tid == last) 5043227364Sadrian break; 5044227364Sadrian } 5045227364Sadrian} 5046227364Sadrian 5047227364Sadrian/* 5048227364Sadrian * TX addba handling 5049227364Sadrian */ 5050227364Sadrian 5051227364Sadrian/* 5052227364Sadrian * Return net80211 TID struct pointer, or NULL for none 5053227364Sadrian */ 5054227364Sadrianstruct ieee80211_tx_ampdu * 5055227364Sadrianath_tx_get_tx_tid(struct ath_node *an, int tid) 5056227364Sadrian{ 5057227364Sadrian struct ieee80211_node *ni = &an->an_node; 5058227364Sadrian struct ieee80211_tx_ampdu *tap; 5059227364Sadrian 5060227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5061227364Sadrian return NULL; 5062227364Sadrian 5063234324Sadrian tap = &ni->ni_tx_ampdu[tid]; 5064227364Sadrian return tap; 5065227364Sadrian} 5066227364Sadrian 5067227364Sadrian/* 5068227364Sadrian * Is AMPDU-TX running? 5069227364Sadrian */ 5070227364Sadrianstatic int 5071227364Sadrianath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid) 5072227364Sadrian{ 5073227364Sadrian struct ieee80211_tx_ampdu *tap; 5074227364Sadrian 5075227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5076227364Sadrian return 0; 5077227364Sadrian 5078227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 5079227364Sadrian if (tap == NULL) 5080227364Sadrian return 0; /* Not valid; default to not running */ 5081227364Sadrian 5082227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING); 5083227364Sadrian} 5084227364Sadrian 5085227364Sadrian/* 5086227364Sadrian * Is AMPDU-TX negotiation pending? 5087227364Sadrian */ 5088227364Sadrianstatic int 5089227364Sadrianath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid) 5090227364Sadrian{ 5091227364Sadrian struct ieee80211_tx_ampdu *tap; 5092227364Sadrian 5093227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5094227364Sadrian return 0; 5095227364Sadrian 5096227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 5097227364Sadrian if (tap == NULL) 5098227364Sadrian return 0; /* Not valid; default to not pending */ 5099227364Sadrian 5100227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND); 5101227364Sadrian} 5102227364Sadrian 5103227364Sadrian/* 5104227364Sadrian * Is AMPDU-TX pending for the given TID? 5105227364Sadrian */ 5106227364Sadrian 5107227364Sadrian 5108227364Sadrian/* 5109227364Sadrian * Method to handle sending an ADDBA request. 5110227364Sadrian * 5111227364Sadrian * We tap this so the relevant flags can be set to pause the TID 5112227364Sadrian * whilst waiting for the response. 5113227364Sadrian * 5114227364Sadrian * XXX there's no timeout handler we can override? 5115227364Sadrian */ 5116227364Sadrianint 5117227364Sadrianath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5118227364Sadrian int dialogtoken, int baparamset, int batimeout) 5119227364Sadrian{ 5120227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5121234324Sadrian int tid = tap->txa_tid; 5122227364Sadrian struct ath_node *an = ATH_NODE(ni); 5123227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5124227364Sadrian 5125227364Sadrian /* 5126227364Sadrian * XXX danger Will Robinson! 5127227364Sadrian * 5128227364Sadrian * Although the taskqueue may be running and scheduling some more 5129227364Sadrian * packets, these should all be _before_ the addba sequence number. 5130227364Sadrian * However, net80211 will keep self-assigning sequence numbers 5131227364Sadrian * until addba has been negotiated. 5132227364Sadrian * 5133227364Sadrian * In the past, these packets would be "paused" (which still works 5134227364Sadrian * fine, as they're being scheduled to the driver in the same 5135227364Sadrian * serialised method which is calling the addba request routine) 5136227364Sadrian * and when the aggregation session begins, they'll be dequeued 5137227364Sadrian * as aggregate packets and added to the BAW. However, now there's 5138227364Sadrian * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these 5139227364Sadrian * packets. Thus they never get included in the BAW tracking and 5140227364Sadrian * this can cause the initial burst of packets after the addba 5141227364Sadrian * negotiation to "hang", as they quickly fall outside the BAW. 5142227364Sadrian * 5143227364Sadrian * The "eventual" solution should be to tag these packets with 5144227364Sadrian * dobaw. Although net80211 has given us a sequence number, 5145227364Sadrian * it'll be "after" the left edge of the BAW and thus it'll 5146227364Sadrian * fall within it. 5147227364Sadrian */ 5148243786Sadrian ATH_TX_LOCK(sc); 5149235774Sadrian /* 5150235774Sadrian * This is a bit annoying. Until net80211 HT code inherits some 5151235774Sadrian * (any) locking, we may have this called in parallel BUT only 5152235774Sadrian * one response/timeout will be called. Grr. 5153235774Sadrian */ 5154235774Sadrian if (atid->addba_tx_pending == 0) { 5155235774Sadrian ath_tx_tid_pause(sc, atid); 5156235774Sadrian atid->addba_tx_pending = 1; 5157235774Sadrian } 5158243786Sadrian ATH_TX_UNLOCK(sc); 5159227364Sadrian 5160227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5161227364Sadrian "%s: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n", 5162227364Sadrian __func__, dialogtoken, baparamset, batimeout); 5163227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5164227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 5165227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 5166227364Sadrian 5167227364Sadrian return sc->sc_addba_request(ni, tap, dialogtoken, baparamset, 5168227364Sadrian batimeout); 5169227364Sadrian} 5170227364Sadrian 5171227364Sadrian/* 5172227364Sadrian * Handle an ADDBA response. 5173227364Sadrian * 5174227364Sadrian * We unpause the queue so TX'ing can resume. 5175227364Sadrian * 5176227364Sadrian * Any packets TX'ed from this point should be "aggregate" (whether 5177227364Sadrian * aggregate or not) so the BAW is updated. 5178227364Sadrian * 5179227364Sadrian * Note! net80211 keeps self-assigning sequence numbers until 5180227364Sadrian * ampdu is negotiated. This means the initially-negotiated BAW left 5181227364Sadrian * edge won't match the ni->ni_txseq. 5182227364Sadrian * 5183227364Sadrian * So, being very dirty, the BAW left edge is "slid" here to match 5184227364Sadrian * ni->ni_txseq. 5185227364Sadrian * 5186227364Sadrian * What likely SHOULD happen is that all packets subsequent to the 5187227364Sadrian * addba request should be tagged as aggregate and queued as non-aggregate 5188227364Sadrian * frames; thus updating the BAW. For now though, I'll just slide the 5189227364Sadrian * window. 5190227364Sadrian */ 5191227364Sadrianint 5192227364Sadrianath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5193227364Sadrian int status, int code, int batimeout) 5194227364Sadrian{ 5195227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5196234324Sadrian int tid = tap->txa_tid; 5197227364Sadrian struct ath_node *an = ATH_NODE(ni); 5198227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5199227364Sadrian int r; 5200227364Sadrian 5201227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5202227364Sadrian "%s: called; status=%d, code=%d, batimeout=%d\n", __func__, 5203227364Sadrian status, code, batimeout); 5204227364Sadrian 5205227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5206227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 5207227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 5208227364Sadrian 5209227364Sadrian /* 5210227364Sadrian * Call this first, so the interface flags get updated 5211227364Sadrian * before the TID is unpaused. Otherwise a race condition 5212227364Sadrian * exists where the unpaused TID still doesn't yet have 5213227364Sadrian * IEEE80211_AGGR_RUNNING set. 5214227364Sadrian */ 5215227364Sadrian r = sc->sc_addba_response(ni, tap, status, code, batimeout); 5216227364Sadrian 5217243786Sadrian ATH_TX_LOCK(sc); 5218235774Sadrian atid->addba_tx_pending = 0; 5219227364Sadrian /* 5220227364Sadrian * XXX dirty! 5221227364Sadrian * Slide the BAW left edge to wherever net80211 left it for us. 5222227364Sadrian * Read above for more information. 5223227364Sadrian */ 5224227364Sadrian tap->txa_start = ni->ni_txseqs[tid]; 5225227364Sadrian ath_tx_tid_resume(sc, atid); 5226243786Sadrian ATH_TX_UNLOCK(sc); 5227227364Sadrian return r; 5228227364Sadrian} 5229227364Sadrian 5230227364Sadrian 5231227364Sadrian/* 5232227364Sadrian * Stop ADDBA on a queue. 5233237593Sadrian * 5234237593Sadrian * This can be called whilst BAR TX is currently active on the queue, 5235237593Sadrian * so make sure this is unblocked before continuing. 5236227364Sadrian */ 5237227364Sadrianvoid 5238227364Sadrianath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 5239227364Sadrian{ 5240227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5241234324Sadrian int tid = tap->txa_tid; 5242227364Sadrian struct ath_node *an = ATH_NODE(ni); 5243227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5244227364Sadrian 5245227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: called\n", __func__); 5246227364Sadrian 5247237593Sadrian /* 5248237593Sadrian * Pause TID traffic early, so there aren't any races 5249237593Sadrian * Unblock the pending BAR held traffic, if it's currently paused. 5250237593Sadrian */ 5251243786Sadrian ATH_TX_LOCK(sc); 5252227364Sadrian ath_tx_tid_pause(sc, atid); 5253237593Sadrian if (atid->bar_wait) { 5254237593Sadrian /* 5255237593Sadrian * bar_unsuspend() expects bar_tx == 1, as it should be 5256237593Sadrian * called from the TX completion path. This quietens 5257237593Sadrian * the warning. It's cleared for us anyway. 5258237593Sadrian */ 5259237593Sadrian atid->bar_tx = 1; 5260237593Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5261237593Sadrian } 5262243786Sadrian ATH_TX_UNLOCK(sc); 5263227364Sadrian 5264227364Sadrian /* There's no need to hold the TXQ lock here */ 5265227364Sadrian sc->sc_addba_stop(ni, tap); 5266227364Sadrian 5267227364Sadrian /* 5268235749Sadrian * ath_tx_tid_cleanup will resume the TID if possible, otherwise 5269227364Sadrian * it'll set the cleanup flag, and it'll be unpaused once 5270227364Sadrian * things have been cleaned up. 5271227364Sadrian */ 5272235749Sadrian ath_tx_tid_cleanup(sc, an, tid); 5273227364Sadrian} 5274227364Sadrian 5275227364Sadrian/* 5276227364Sadrian * Note: net80211 bar_timeout() doesn't call this function on BAR failure; 5277227364Sadrian * it simply tears down the aggregation session. Ew. 5278227364Sadrian * 5279227364Sadrian * It however will call ieee80211_ampdu_stop() which will call 5280227364Sadrian * ic->ic_addba_stop(). 5281227364Sadrian * 5282227364Sadrian * XXX This uses a hard-coded max BAR count value; the whole 5283227364Sadrian * XXX BAR TX success or failure should be better handled! 5284227364Sadrian */ 5285227364Sadrianvoid 5286227364Sadrianath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5287227364Sadrian int status) 5288227364Sadrian{ 5289227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5290234324Sadrian int tid = tap->txa_tid; 5291227364Sadrian struct ath_node *an = ATH_NODE(ni); 5292227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5293227364Sadrian int attempts = tap->txa_attempts; 5294227364Sadrian 5295235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 5296235676Sadrian "%s: called; tap=%p, atid=%p, txa_tid=%d, atid->tid=%d, status=%d, attempts=%d\n", 5297235491Sadrian __func__, 5298235676Sadrian tap, 5299235676Sadrian atid, 5300235676Sadrian tap->txa_tid, 5301235676Sadrian atid->tid, 5302235491Sadrian status, 5303235491Sadrian attempts); 5304227364Sadrian 5305227364Sadrian /* Note: This may update the BAW details */ 5306227364Sadrian sc->sc_bar_response(ni, tap, status); 5307227364Sadrian 5308227364Sadrian /* Unpause the TID */ 5309227364Sadrian /* 5310227364Sadrian * XXX if this is attempt=50, the TID will be downgraded 5311227364Sadrian * XXX to a non-aggregate session. So we must unpause the 5312227364Sadrian * XXX TID here or it'll never be done. 5313240721Sadrian * 5314240721Sadrian * Also, don't call it if bar_tx/bar_wait are 0; something 5315240721Sadrian * has beaten us to the punch? (XXX figure out what?) 5316227364Sadrian */ 5317227364Sadrian if (status == 0 || attempts == 50) { 5318243786Sadrian ATH_TX_LOCK(sc); 5319240721Sadrian if (atid->bar_tx == 0 || atid->bar_wait == 0) 5320240721Sadrian device_printf(sc->sc_dev, 5321240721Sadrian "%s: huh? bar_tx=%d, bar_wait=%d\n", 5322240721Sadrian __func__, 5323240721Sadrian atid->bar_tx, atid->bar_wait); 5324240721Sadrian else 5325240721Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5326243786Sadrian ATH_TX_UNLOCK(sc); 5327227364Sadrian } 5328227364Sadrian} 5329227364Sadrian 5330227364Sadrian/* 5331227364Sadrian * This is called whenever the pending ADDBA request times out. 5332227364Sadrian * Unpause and reschedule the TID. 5333227364Sadrian */ 5334227364Sadrianvoid 5335227364Sadrianath_addba_response_timeout(struct ieee80211_node *ni, 5336227364Sadrian struct ieee80211_tx_ampdu *tap) 5337227364Sadrian{ 5338227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5339234324Sadrian int tid = tap->txa_tid; 5340227364Sadrian struct ath_node *an = ATH_NODE(ni); 5341227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5342227364Sadrian 5343227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5344227364Sadrian "%s: called; resuming\n", __func__); 5345227364Sadrian 5346243786Sadrian ATH_TX_LOCK(sc); 5347235774Sadrian atid->addba_tx_pending = 0; 5348243786Sadrian ATH_TX_UNLOCK(sc); 5349235774Sadrian 5350227364Sadrian /* Note: This updates the aggregate state to (again) pending */ 5351227364Sadrian sc->sc_addba_response_timeout(ni, tap); 5352227364Sadrian 5353227364Sadrian /* Unpause the TID; which reschedules it */ 5354243786Sadrian ATH_TX_LOCK(sc); 5355227364Sadrian ath_tx_tid_resume(sc, atid); 5356243786Sadrian ATH_TX_UNLOCK(sc); 5357227364Sadrian} 5358238710Sadrian 5359241170Sadrian/* 5360241170Sadrian * Check if a node is asleep or not. 5361241170Sadrian */ 5362242271Sadrianint 5363241170Sadrianath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an) 5364241170Sadrian{ 5365241170Sadrian 5366241170Sadrian ATH_NODE_LOCK_ASSERT(an); 5367241170Sadrian 5368241170Sadrian return (an->an_is_powersave); 5369241170Sadrian} 5370241170Sadrian 5371241170Sadrian/* 5372241170Sadrian * Mark a node as currently "in powersaving." 5373241170Sadrian * This suspends all traffic on the node. 5374241170Sadrian * 5375241170Sadrian * This must be called with the node/tx locks free. 5376241170Sadrian * 5377241170Sadrian * XXX TODO: the locking silliness below is due to how the node 5378241170Sadrian * locking currently works. Right now, the node lock is grabbed 5379241170Sadrian * to do rate control lookups and these are done with the TX 5380241170Sadrian * queue lock held. This means the node lock can't be grabbed 5381241170Sadrian * first here or a LOR will occur. 5382241170Sadrian * 5383241170Sadrian * Eventually (hopefully!) the TX path code will only grab 5384241170Sadrian * the TXQ lock when transmitting and the ath_node lock when 5385241170Sadrian * doing node/TID operations. There are other complications - 5386241170Sadrian * the sched/unsched operations involve walking the per-txq 5387241170Sadrian * 'active tid' list and this requires both locks to be held. 5388241170Sadrian */ 5389241170Sadrianvoid 5390241170Sadrianath_tx_node_sleep(struct ath_softc *sc, struct ath_node *an) 5391241170Sadrian{ 5392241170Sadrian struct ath_tid *atid; 5393241170Sadrian struct ath_txq *txq; 5394241170Sadrian int tid; 5395241170Sadrian 5396241170Sadrian ATH_NODE_UNLOCK_ASSERT(an); 5397241170Sadrian 5398241170Sadrian /* 5399241170Sadrian * It's possible that a parallel call to ath_tx_node_wakeup() 5400241170Sadrian * will unpause these queues. 5401241170Sadrian * 5402241170Sadrian * The node lock can't just be grabbed here, as there's places 5403241170Sadrian * in the driver where the node lock is grabbed _within_ a 5404241170Sadrian * TXQ lock. 5405241170Sadrian * So, we do this delicately and unwind state if needed. 5406241170Sadrian * 5407241170Sadrian * + Pause all the queues 5408241170Sadrian * + Grab the node lock 5409241170Sadrian * + If the queue is already asleep, unpause and quit 5410241170Sadrian * + else just mark as asleep. 5411241170Sadrian * 5412241170Sadrian * A parallel sleep() call will just pause and then 5413241170Sadrian * find they're already paused, so undo it. 5414241170Sadrian * 5415241170Sadrian * A parallel wakeup() call will check if asleep is 1 5416241170Sadrian * and if it's not (ie, it's 0), it'll treat it as already 5417241170Sadrian * being awake. If it's 1, it'll mark it as 0 and then 5418241170Sadrian * unpause everything. 5419241170Sadrian * 5420241170Sadrian * (Talk about a delicate hack.) 5421241170Sadrian */ 5422241170Sadrian 5423241170Sadrian /* Suspend all traffic on the node */ 5424243786Sadrian ATH_TX_LOCK(sc); 5425241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5426241170Sadrian atid = &an->an_tid[tid]; 5427241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5428241170Sadrian 5429241170Sadrian ath_tx_tid_pause(sc, atid); 5430241170Sadrian } 5431243786Sadrian ATH_TX_UNLOCK(sc); 5432241170Sadrian 5433241170Sadrian ATH_NODE_LOCK(an); 5434241170Sadrian 5435241170Sadrian /* In case of concurrency races from net80211.. */ 5436241170Sadrian if (an->an_is_powersave == 1) { 5437241170Sadrian ATH_NODE_UNLOCK(an); 5438241170Sadrian device_printf(sc->sc_dev, 5439241170Sadrian "%s: an=%p: node was already asleep\n", 5440241170Sadrian __func__, an); 5441243786Sadrian ATH_TX_LOCK(sc); 5442241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5443241170Sadrian atid = &an->an_tid[tid]; 5444241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5445241170Sadrian 5446241170Sadrian ath_tx_tid_resume(sc, atid); 5447241170Sadrian } 5448243786Sadrian ATH_TX_UNLOCK(sc); 5449241170Sadrian return; 5450241170Sadrian } 5451241170Sadrian 5452241170Sadrian /* Mark node as in powersaving */ 5453241170Sadrian an->an_is_powersave = 1; 5454241170Sadrian 5455241170Sadrian ATH_NODE_UNLOCK(an); 5456241170Sadrian} 5457241170Sadrian 5458241170Sadrian/* 5459241170Sadrian * Mark a node as currently "awake." 5460241170Sadrian * This resumes all traffic to the node. 5461241170Sadrian */ 5462241170Sadrianvoid 5463241170Sadrianath_tx_node_wakeup(struct ath_softc *sc, struct ath_node *an) 5464241170Sadrian{ 5465241170Sadrian struct ath_tid *atid; 5466241170Sadrian struct ath_txq *txq; 5467241170Sadrian int tid; 5468241170Sadrian 5469241170Sadrian ATH_NODE_UNLOCK_ASSERT(an); 5470241170Sadrian ATH_NODE_LOCK(an); 5471241170Sadrian 5472241170Sadrian /* In case of concurrency races from net80211.. */ 5473241170Sadrian if (an->an_is_powersave == 0) { 5474241170Sadrian ATH_NODE_UNLOCK(an); 5475241170Sadrian device_printf(sc->sc_dev, 5476241170Sadrian "%s: an=%p: node was already awake\n", 5477241170Sadrian __func__, an); 5478241170Sadrian return; 5479241170Sadrian } 5480241170Sadrian 5481241170Sadrian /* Mark node as awake */ 5482241170Sadrian an->an_is_powersave = 0; 5483241170Sadrian 5484241170Sadrian ATH_NODE_UNLOCK(an); 5485241170Sadrian 5486243786Sadrian ATH_TX_LOCK(sc); 5487241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5488241170Sadrian atid = &an->an_tid[tid]; 5489241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5490241170Sadrian 5491241170Sadrian ath_tx_tid_resume(sc, atid); 5492241170Sadrian } 5493243786Sadrian ATH_TX_UNLOCK(sc); 5494241170Sadrian} 5495241170Sadrian 5496241170Sadrianstatic int 5497238710Sadrianath_legacy_dma_txsetup(struct ath_softc *sc) 5498238710Sadrian{ 5499238710Sadrian 5500238710Sadrian /* nothing new needed */ 5501238710Sadrian return (0); 5502238710Sadrian} 5503238710Sadrian 5504238710Sadrianstatic int 5505238710Sadrianath_legacy_dma_txteardown(struct ath_softc *sc) 5506238710Sadrian{ 5507238710Sadrian 5508238710Sadrian /* nothing new needed */ 5509238710Sadrian return (0); 5510238710Sadrian} 5511238710Sadrian 5512238710Sadrianvoid 5513238710Sadrianath_xmit_setup_legacy(struct ath_softc *sc) 5514238710Sadrian{ 5515238729Sadrian /* 5516238729Sadrian * For now, just set the descriptor length to sizeof(ath_desc); 5517238729Sadrian * worry about extracting the real length out of the HAL later. 5518238729Sadrian */ 5519238729Sadrian sc->sc_tx_desclen = sizeof(struct ath_desc); 5520243162Sadrian sc->sc_tx_statuslen = sizeof(struct ath_desc); 5521238729Sadrian sc->sc_tx_nmaps = 1; /* only one buffer per TX desc */ 5522238710Sadrian 5523238710Sadrian sc->sc_tx.xmit_setup = ath_legacy_dma_txsetup; 5524238710Sadrian sc->sc_tx.xmit_teardown = ath_legacy_dma_txteardown; 5525238931Sadrian sc->sc_tx.xmit_attach_comp_func = ath_legacy_attach_comp_func; 5526238930Sadrian 5527238930Sadrian sc->sc_tx.xmit_dma_restart = ath_legacy_tx_dma_restart; 5528238930Sadrian sc->sc_tx.xmit_handoff = ath_legacy_xmit_handoff; 5529239204Sadrian 5530239204Sadrian sc->sc_tx.xmit_drain = ath_legacy_tx_drain; 5531238710Sadrian} 5532