if_ath_tx.c revision 240724
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 240724 2012-09-20 03:13:20Z 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 104218154Sadrian/* 105227364Sadrian * How many retries to perform in software 106227364Sadrian */ 107227364Sadrian#define SWMAX_RETRIES 10 108227364Sadrian 109227364Sadrianstatic int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, 110227364Sadrian int tid); 111227364Sadrianstatic int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, 112227364Sadrian int tid); 113236872Sadrianstatic ieee80211_seq ath_tx_tid_seqno_assign(struct ath_softc *sc, 114236872Sadrian struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0); 115227364Sadrianstatic int ath_tx_action_frame_override_queue(struct ath_softc *sc, 116227364Sadrian struct ieee80211_node *ni, struct mbuf *m0, int *tid); 117240639Sadrianstatic struct ath_buf * 118240639Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 119240639Sadrian struct ath_tid *tid, struct ath_buf *bf); 120227364Sadrian 121227364Sadrian/* 122218154Sadrian * Whether to use the 11n rate scenario functions or not 123218154Sadrian */ 124218154Sadrianstatic inline int 125218154Sadrianath_tx_is_11n(struct ath_softc *sc) 126218154Sadrian{ 127239198Sadrian return ((sc->sc_ah->ah_magic == 0x20065416) || 128239198Sadrian (sc->sc_ah->ah_magic == 0x19741014)); 129218154Sadrian} 130218154Sadrian 131227364Sadrian/* 132227364Sadrian * Obtain the current TID from the given frame. 133227364Sadrian * 134227364Sadrian * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.) 135227364Sadrian * This has implications for which AC/priority the packet is placed 136227364Sadrian * in. 137227364Sadrian */ 138227364Sadrianstatic int 139227364Sadrianath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0) 140227364Sadrian{ 141227364Sadrian const struct ieee80211_frame *wh; 142227364Sadrian int pri = M_WME_GETAC(m0); 143227364Sadrian 144227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 145227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 146227364Sadrian return IEEE80211_NONQOS_TID; 147227364Sadrian else 148227364Sadrian return WME_AC_TO_TID(pri); 149227364Sadrian} 150227364Sadrian 151240639Sadrianstatic void 152240639Sadrianath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) 153240639Sadrian{ 154240639Sadrian struct ieee80211_frame *wh; 155240639Sadrian 156240639Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 157240639Sadrian /* Only update/resync if needed */ 158240639Sadrian if (bf->bf_state.bfs_isretried == 0) { 159240639Sadrian wh->i_fc[1] |= IEEE80211_FC1_RETRY; 160240639Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 161240639Sadrian BUS_DMASYNC_PREWRITE); 162240639Sadrian } 163240639Sadrian bf->bf_state.bfs_isretried = 1; 164240639Sadrian bf->bf_state.bfs_retries ++; 165240639Sadrian} 166240639Sadrian 167227364Sadrian/* 168227364Sadrian * Determine what the correct AC queue for the given frame 169227364Sadrian * should be. 170227364Sadrian * 171227364Sadrian * This code assumes that the TIDs map consistently to 172227364Sadrian * the underlying hardware (or software) ath_txq. 173227364Sadrian * Since the sender may try to set an AC which is 174227364Sadrian * arbitrary, non-QoS TIDs may end up being put on 175227364Sadrian * completely different ACs. There's no way to put a 176227364Sadrian * TID into multiple ath_txq's for scheduling, so 177227364Sadrian * for now we override the AC/TXQ selection and set 178227364Sadrian * non-QOS TID frames into the BE queue. 179227364Sadrian * 180227364Sadrian * This may be completely incorrect - specifically, 181227364Sadrian * some management frames may end up out of order 182227364Sadrian * compared to the QoS traffic they're controlling. 183227364Sadrian * I'll look into this later. 184227364Sadrian */ 185227364Sadrianstatic int 186227364Sadrianath_tx_getac(struct ath_softc *sc, const struct mbuf *m0) 187227364Sadrian{ 188227364Sadrian const struct ieee80211_frame *wh; 189227364Sadrian int pri = M_WME_GETAC(m0); 190227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 191227364Sadrian if (IEEE80211_QOS_HAS_SEQ(wh)) 192227364Sadrian return pri; 193227364Sadrian 194227364Sadrian return WME_AC_BE; 195227364Sadrian} 196227364Sadrian 197218065Sadrianvoid 198218065Sadrianath_txfrag_cleanup(struct ath_softc *sc, 199218065Sadrian ath_bufhead *frags, struct ieee80211_node *ni) 200218065Sadrian{ 201218065Sadrian struct ath_buf *bf, *next; 202218065Sadrian 203218065Sadrian ATH_TXBUF_LOCK_ASSERT(sc); 204218065Sadrian 205227344Sadrian TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) { 206218065Sadrian /* NB: bf assumed clean */ 207227344Sadrian TAILQ_REMOVE(frags, bf, bf_list); 208236993Sadrian ath_returnbuf_head(sc, bf); 209218065Sadrian ieee80211_node_decref(ni); 210218065Sadrian } 211218065Sadrian} 212218065Sadrian 213218065Sadrian/* 214218065Sadrian * Setup xmit of a fragmented frame. Allocate a buffer 215218065Sadrian * for each frag and bump the node reference count to 216218065Sadrian * reflect the held reference to be setup by ath_tx_start. 217218065Sadrian */ 218218065Sadrianint 219218065Sadrianath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags, 220218065Sadrian struct mbuf *m0, struct ieee80211_node *ni) 221218065Sadrian{ 222218065Sadrian struct mbuf *m; 223218065Sadrian struct ath_buf *bf; 224218065Sadrian 225218065Sadrian ATH_TXBUF_LOCK(sc); 226218065Sadrian for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) { 227237000Sadrian /* XXX non-management? */ 228237000Sadrian bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL); 229218065Sadrian if (bf == NULL) { /* out of buffers, cleanup */ 230234009Sadrian device_printf(sc->sc_dev, "%s: no buffer?\n", 231234009Sadrian __func__); 232218065Sadrian ath_txfrag_cleanup(sc, frags, ni); 233218065Sadrian break; 234218065Sadrian } 235218065Sadrian ieee80211_node_incref(ni); 236227344Sadrian TAILQ_INSERT_TAIL(frags, bf, bf_list); 237218065Sadrian } 238218065Sadrian ATH_TXBUF_UNLOCK(sc); 239218065Sadrian 240227344Sadrian return !TAILQ_EMPTY(frags); 241218065Sadrian} 242218065Sadrian 243218065Sadrian/* 244218065Sadrian * Reclaim mbuf resources. For fragmented frames we 245218065Sadrian * need to claim each frag chained with m_nextpkt. 246218065Sadrian */ 247218065Sadrianvoid 248218065Sadrianath_freetx(struct mbuf *m) 249218065Sadrian{ 250218065Sadrian struct mbuf *next; 251218065Sadrian 252218065Sadrian do { 253218065Sadrian next = m->m_nextpkt; 254218065Sadrian m->m_nextpkt = NULL; 255218065Sadrian m_freem(m); 256218065Sadrian } while ((m = next) != NULL); 257218065Sadrian} 258218065Sadrian 259218065Sadrianstatic int 260218065Sadrianath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0) 261218065Sadrian{ 262218065Sadrian struct mbuf *m; 263218065Sadrian int error; 264218065Sadrian 265218065Sadrian /* 266218065Sadrian * Load the DMA map so any coalescing is done. This 267218065Sadrian * also calculates the number of descriptors we need. 268218065Sadrian */ 269218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 270218065Sadrian bf->bf_segs, &bf->bf_nseg, 271218065Sadrian BUS_DMA_NOWAIT); 272218065Sadrian if (error == EFBIG) { 273218065Sadrian /* XXX packet requires too many descriptors */ 274218065Sadrian bf->bf_nseg = ATH_TXDESC+1; 275218065Sadrian } else if (error != 0) { 276218065Sadrian sc->sc_stats.ast_tx_busdma++; 277218065Sadrian ath_freetx(m0); 278218065Sadrian return error; 279218065Sadrian } 280218065Sadrian /* 281218065Sadrian * Discard null packets and check for packets that 282218065Sadrian * require too many TX descriptors. We try to convert 283218065Sadrian * the latter to a cluster. 284218065Sadrian */ 285218065Sadrian if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ 286218065Sadrian sc->sc_stats.ast_tx_linear++; 287218065Sadrian m = m_collapse(m0, M_DONTWAIT, ATH_TXDESC); 288218065Sadrian if (m == NULL) { 289218065Sadrian ath_freetx(m0); 290218065Sadrian sc->sc_stats.ast_tx_nombuf++; 291218065Sadrian return ENOMEM; 292218065Sadrian } 293218065Sadrian m0 = m; 294218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 295218065Sadrian bf->bf_segs, &bf->bf_nseg, 296218065Sadrian BUS_DMA_NOWAIT); 297218065Sadrian if (error != 0) { 298218065Sadrian sc->sc_stats.ast_tx_busdma++; 299218065Sadrian ath_freetx(m0); 300218065Sadrian return error; 301218065Sadrian } 302218065Sadrian KASSERT(bf->bf_nseg <= ATH_TXDESC, 303218065Sadrian ("too many segments after defrag; nseg %u", bf->bf_nseg)); 304218065Sadrian } else if (bf->bf_nseg == 0) { /* null packet, discard */ 305218065Sadrian sc->sc_stats.ast_tx_nodata++; 306218065Sadrian ath_freetx(m0); 307218065Sadrian return EIO; 308218065Sadrian } 309218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n", 310218065Sadrian __func__, m0, m0->m_pkthdr.len); 311218065Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 312218065Sadrian bf->bf_m = m0; 313218065Sadrian 314218065Sadrian return 0; 315218065Sadrian} 316218065Sadrian 317227360Sadrian/* 318227360Sadrian * Chain together segments+descriptors for a non-11n frame. 319227360Sadrian */ 320218065Sadrianstatic void 321227364Sadrianath_tx_chaindesclist(struct ath_softc *sc, struct ath_buf *bf) 322218065Sadrian{ 323218065Sadrian struct ath_hal *ah = sc->sc_ah; 324239409Sadrian char *ds, *ds0; 325239290Sadrian int i, bp, dsp; 326239051Sadrian HAL_DMA_ADDR bufAddrList[4]; 327239051Sadrian uint32_t segLenList[4]; 328239290Sadrian int numTxMaps = 1; 329239380Sadrian int isFirstDesc = 1; 330239465Sadrian int qnum; 331239051Sadrian 332238708Sadrian /* 333238708Sadrian * XXX There's txdma and txdma_mgmt; the descriptor 334238708Sadrian * sizes must match. 335238708Sadrian */ 336238708Sadrian struct ath_descdma *dd = &sc->sc_txdma; 337218065Sadrian 338218065Sadrian /* 339218065Sadrian * Fillin the remainder of the descriptor info. 340218065Sadrian */ 341239290Sadrian 342239290Sadrian /* 343239290Sadrian * For now the HAL doesn't implement halNumTxMaps for non-EDMA 344239290Sadrian * (ie it's 0.) So just work around it. 345239290Sadrian * 346239290Sadrian * XXX TODO: populate halNumTxMaps for each HAL chip and 347239290Sadrian * then undo this hack. 348239290Sadrian */ 349239290Sadrian if (sc->sc_ah->ah_magic == 0x19741014) 350239290Sadrian numTxMaps = 4; 351239290Sadrian 352239290Sadrian /* 353239290Sadrian * For EDMA and later chips ensure the TX map is fully populated 354239290Sadrian * before advancing to the next descriptor. 355239290Sadrian */ 356239409Sadrian ds0 = ds = (char *) bf->bf_desc; 357239290Sadrian bp = dsp = 0; 358239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 359239290Sadrian bzero(segLenList, sizeof(segLenList)); 360239290Sadrian for (i = 0; i < bf->bf_nseg; i++) { 361239290Sadrian bufAddrList[bp] = bf->bf_segs[i].ds_addr; 362239290Sadrian segLenList[bp] = bf->bf_segs[i].ds_len; 363239290Sadrian bp++; 364239051Sadrian 365239290Sadrian /* 366239290Sadrian * Go to the next segment if this isn't the last segment 367239290Sadrian * and there's space in the current TX map. 368239290Sadrian */ 369239290Sadrian if ((i != bf->bf_nseg - 1) && (bp < numTxMaps)) 370239290Sadrian continue; 371239051Sadrian 372239290Sadrian /* 373239290Sadrian * Last segment or we're out of buffer pointers. 374239290Sadrian */ 375239290Sadrian bp = 0; 376239290Sadrian 377218065Sadrian if (i == bf->bf_nseg - 1) 378239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 0); 379218065Sadrian else 380239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 381239290Sadrian bf->bf_daddr + dd->dd_descsize * (dsp + 1)); 382239051Sadrian 383239051Sadrian /* 384239051Sadrian * XXX this assumes that bfs_txq is the actual destination 385239051Sadrian * hardware queue at this point. It may not have been assigned, 386239051Sadrian * it may actually be pointing to the multicast software 387239051Sadrian * TXQ id. These must be fixed! 388239051Sadrian */ 389239465Sadrian qnum = bf->bf_state.bfs_txq->axq_qnum; 390239465Sadrian 391239409Sadrian ath_hal_filltxdesc(ah, (struct ath_desc *) ds 392239051Sadrian , bufAddrList 393239051Sadrian , segLenList 394239290Sadrian , bf->bf_descid /* XXX desc id */ 395239465Sadrian , qnum 396239380Sadrian , isFirstDesc /* first segment */ 397218065Sadrian , i == bf->bf_nseg - 1 /* last segment */ 398239409Sadrian , (struct ath_desc *) ds0 /* first descriptor */ 399218065Sadrian ); 400240255Sadrian 401240255Sadrian /* Make sure the 11n aggregate fields are cleared */ 402240255Sadrian if (ath_tx_is_11n(sc)) 403240333Sadrian ath_hal_clr11n_aggr(sc->sc_ah, (struct ath_desc *) ds); 404240255Sadrian 405239380Sadrian isFirstDesc = 0; 406239438Sadrian#ifdef ATH_DEBUG 407239409Sadrian if (sc->sc_debug & ATH_DEBUG_XMIT) 408239409Sadrian ath_printtxbuf(sc, bf, qnum, 0, 0); 409239438Sadrian#endif 410239409Sadrian bf->bf_lastds = (struct ath_desc *) ds; 411239290Sadrian 412239290Sadrian /* 413239290Sadrian * Don't forget to skip to the next descriptor. 414239290Sadrian */ 415239409Sadrian ds += sc->sc_tx_desclen; 416239290Sadrian dsp++; 417239290Sadrian 418239290Sadrian /* 419239290Sadrian * .. and don't forget to blank these out! 420239290Sadrian */ 421239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 422239290Sadrian bzero(segLenList, sizeof(segLenList)); 423218065Sadrian } 424233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 425218154Sadrian} 426218154Sadrian 427227364Sadrian/* 428227364Sadrian * Fill in the descriptor list for a aggregate subframe. 429227364Sadrian * 430227364Sadrian * The subframe is returned with the ds_link field in the last subframe 431227364Sadrian * pointing to 0. 432227364Sadrian */ 433218154Sadrianstatic void 434227364Sadrianath_tx_chaindesclist_subframe(struct ath_softc *sc, struct ath_buf *bf) 435218154Sadrian{ 436218154Sadrian struct ath_hal *ah = sc->sc_ah; 437227364Sadrian struct ath_desc *ds, *ds0; 438227364Sadrian int i; 439239053Sadrian HAL_DMA_ADDR bufAddrList[4]; 440239053Sadrian uint32_t segLenList[4]; 441239053Sadrian 442238708Sadrian /* 443238708Sadrian * XXX There's txdma and txdma_mgmt; the descriptor 444238708Sadrian * sizes must match. 445238708Sadrian */ 446238708Sadrian struct ath_descdma *dd = &sc->sc_txdma; 447218154Sadrian 448227364Sadrian ds0 = ds = bf->bf_desc; 449218154Sadrian 450218065Sadrian /* 451227364Sadrian * There's no need to call ath_hal_setupfirsttxdesc here; 452227364Sadrian * That's only going to occur for the first frame in an aggregate. 453227364Sadrian */ 454227364Sadrian for (i = 0; i < bf->bf_nseg; i++, ds++) { 455239053Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 456239053Sadrian bzero(segLenList, sizeof(segLenList)); 457227364Sadrian if (i == bf->bf_nseg - 1) 458238609Sadrian ath_hal_settxdesclink(ah, ds, 0); 459227364Sadrian else 460238609Sadrian ath_hal_settxdesclink(ah, ds, 461238708Sadrian bf->bf_daddr + dd->dd_descsize * (i + 1)); 462227364Sadrian 463239053Sadrian bufAddrList[0] = bf->bf_segs[i].ds_addr; 464239053Sadrian segLenList[0] = bf->bf_segs[i].ds_len; 465239053Sadrian 466227364Sadrian /* 467227364Sadrian * This performs the setup for an aggregate frame. 468227364Sadrian * This includes enabling the aggregate flags if needed. 469227364Sadrian */ 470227364Sadrian ath_hal_chaintxdesc(ah, ds, 471239053Sadrian bufAddrList, 472239053Sadrian segLenList, 473227364Sadrian bf->bf_state.bfs_pktlen, 474227364Sadrian bf->bf_state.bfs_hdrlen, 475227364Sadrian HAL_PKT_TYPE_AMPDU, /* forces aggregate bits to be set */ 476227364Sadrian bf->bf_state.bfs_keyix, 477227364Sadrian 0, /* cipher, calculated from keyix */ 478227364Sadrian bf->bf_state.bfs_ndelim, 479227364Sadrian i == 0, /* first segment */ 480233895Sadrian i == bf->bf_nseg - 1, /* last segment */ 481233895Sadrian bf->bf_next == NULL /* last sub-frame in aggr */ 482227364Sadrian ); 483227364Sadrian 484227364Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 485227364Sadrian "%s: %d: %08x %08x %08x %08x %08x %08x\n", 486227364Sadrian __func__, i, ds->ds_link, ds->ds_data, 487227364Sadrian ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1]); 488227364Sadrian bf->bf_lastds = ds; 489233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 490233990Sadrian BUS_DMASYNC_PREWRITE); 491227364Sadrian } 492227364Sadrian} 493227364Sadrian 494227364Sadrian/* 495238947Sadrian * Set the rate control fields in the given descriptor based on 496238947Sadrian * the bf_state fields and node state. 497238947Sadrian * 498238947Sadrian * The bfs fields should already be set with the relevant rate 499238947Sadrian * control information, including whether MRR is to be enabled. 500238947Sadrian * 501238947Sadrian * Since the FreeBSD HAL currently sets up the first TX rate 502238947Sadrian * in ath_hal_setuptxdesc(), this will setup the MRR 503238947Sadrian * conditionally for the pre-11n chips, and call ath_buf_set_rate 504238947Sadrian * unconditionally for 11n chips. These require the 11n rate 505238947Sadrian * scenario to be set if MCS rates are enabled, so it's easier 506238947Sadrian * to just always call it. The caller can then only set rates 2, 3 507238947Sadrian * and 4 if multi-rate retry is needed. 508238947Sadrian */ 509238947Sadrianstatic void 510238947Sadrianath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni, 511238947Sadrian struct ath_buf *bf) 512238947Sadrian{ 513238947Sadrian struct ath_rc_series *rc = bf->bf_state.bfs_rc; 514238947Sadrian 515238947Sadrian /* If mrr is disabled, blank tries 1, 2, 3 */ 516238947Sadrian if (! bf->bf_state.bfs_ismrr) 517238947Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 518238947Sadrian 519238947Sadrian /* 520238947Sadrian * Always call - that way a retried descriptor will 521238947Sadrian * have the MRR fields overwritten. 522238947Sadrian * 523238947Sadrian * XXX TODO: see if this is really needed - setting up 524238947Sadrian * the first descriptor should set the MRR fields to 0 525238947Sadrian * for us anyway. 526238947Sadrian */ 527238947Sadrian if (ath_tx_is_11n(sc)) { 528238947Sadrian ath_buf_set_rate(sc, ni, bf); 529238947Sadrian } else { 530238947Sadrian ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc 531238947Sadrian , rc[1].ratecode, rc[1].tries 532238947Sadrian , rc[2].ratecode, rc[2].tries 533238947Sadrian , rc[3].ratecode, rc[3].tries 534238947Sadrian ); 535238947Sadrian } 536238947Sadrian} 537238947Sadrian 538238947Sadrian/* 539227364Sadrian * Setup segments+descriptors for an 11n aggregate. 540227364Sadrian * bf_first is the first buffer in the aggregate. 541227364Sadrian * The descriptor list must already been linked together using 542227364Sadrian * bf->bf_next. 543227364Sadrian */ 544227364Sadrianstatic void 545227364Sadrianath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first) 546227364Sadrian{ 547227364Sadrian struct ath_buf *bf, *bf_prev = NULL; 548227364Sadrian 549227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n", 550227364Sadrian __func__, bf_first->bf_state.bfs_nframes, 551227364Sadrian bf_first->bf_state.bfs_al); 552227364Sadrian 553227364Sadrian /* 554227364Sadrian * Setup all descriptors of all subframes. 555227364Sadrian */ 556227364Sadrian bf = bf_first; 557227364Sadrian while (bf != NULL) { 558227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 559227364Sadrian "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n", 560227364Sadrian __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen, 561227364Sadrian SEQNO(bf->bf_state.bfs_seqno)); 562227364Sadrian 563227364Sadrian /* Sub-frame setup */ 564227364Sadrian ath_tx_chaindesclist_subframe(sc, bf); 565227364Sadrian 566227364Sadrian /* 567227364Sadrian * Link the last descriptor of the previous frame 568227364Sadrian * to the beginning descriptor of this frame. 569227364Sadrian */ 570227364Sadrian if (bf_prev != NULL) 571238609Sadrian ath_hal_settxdesclink(sc->sc_ah, bf_prev->bf_lastds, 572238609Sadrian bf->bf_daddr); 573227364Sadrian 574227364Sadrian /* Save a copy so we can link the next descriptor in */ 575227364Sadrian bf_prev = bf; 576227364Sadrian bf = bf->bf_next; 577227364Sadrian } 578227364Sadrian 579227364Sadrian /* 580227364Sadrian * Setup first descriptor of first frame. 581227364Sadrian * chaintxdesc() overwrites the descriptor entries; 582227364Sadrian * setupfirsttxdesc() merges in things. 583227364Sadrian * Otherwise various fields aren't set correctly (eg flags). 584227364Sadrian */ 585227364Sadrian ath_hal_setupfirsttxdesc(sc->sc_ah, 586227364Sadrian bf_first->bf_desc, 587227364Sadrian bf_first->bf_state.bfs_al, 588233966Sadrian bf_first->bf_state.bfs_txflags | HAL_TXDESC_INTREQ, 589227364Sadrian bf_first->bf_state.bfs_txpower, 590227364Sadrian bf_first->bf_state.bfs_txrate0, 591227364Sadrian bf_first->bf_state.bfs_try0, 592227364Sadrian bf_first->bf_state.bfs_txantenna, 593227364Sadrian bf_first->bf_state.bfs_ctsrate, 594227364Sadrian bf_first->bf_state.bfs_ctsduration); 595227364Sadrian 596227364Sadrian /* 597227364Sadrian * Set the first descriptor bf_lastds field to point to 598227364Sadrian * the last descriptor in the last subframe, that's where 599227364Sadrian * the status update will occur. 600227364Sadrian */ 601227364Sadrian bf_first->bf_lastds = bf_prev->bf_lastds; 602227364Sadrian 603227364Sadrian /* 604227364Sadrian * And bf_last in the first descriptor points to the end of 605227364Sadrian * the aggregate list. 606227364Sadrian */ 607227364Sadrian bf_first->bf_last = bf_prev; 608227364Sadrian 609238947Sadrian /* 610238947Sadrian * setup first desc with rate and aggr info 611238947Sadrian */ 612238947Sadrian ath_tx_set_ratectrl(sc, bf_first->bf_node, bf_first); 613238947Sadrian 614238949Sadrian /* 615238949Sadrian * Setup the last descriptor in the list. 616238993Sadrian * 617238993Sadrian * bf_first->bf_lastds already points to it; the rate 618238993Sadrian * control information needs to be squirreled away here 619238993Sadrian * as well ans clearing the moreaggr/paddelim fields. 620238949Sadrian */ 621238993Sadrian ath_hal_setuplasttxdesc(sc->sc_ah, bf_first->bf_lastds, 622238949Sadrian bf_first->bf_desc); 623238949Sadrian 624227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__); 625227364Sadrian} 626227364Sadrian 627239051Sadrian/* 628239051Sadrian * Hand-off a frame to the multicast TX queue. 629239051Sadrian * 630239051Sadrian * This is a software TXQ which will be appended to the CAB queue 631239051Sadrian * during the beacon setup code. 632239051Sadrian * 633239051Sadrian * XXX TODO: since the AR9300 EDMA TX queue support wants the QCU ID 634239051Sadrian * as part of the TX descriptor, bf_state.bfs_txq must be updated 635239051Sadrian * with the actual hardware txq, or all of this will fall apart. 636239051Sadrian * 637239051Sadrian * XXX It may not be a bad idea to just stuff the QCU ID into bf_state 638239051Sadrian * and retire bfs_txq; then make sure the CABQ QCU ID is populated 639239051Sadrian * correctly. 640239051Sadrian */ 641227364Sadrianstatic void 642227364Sadrianath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq, 643227364Sadrian struct ath_buf *bf) 644227364Sadrian{ 645227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 646227364Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 647227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 648227364Sadrian if (txq->axq_link != NULL) { 649227364Sadrian struct ath_buf *last = ATH_TXQ_LAST(txq, axq_q_s); 650227364Sadrian struct ieee80211_frame *wh; 651227364Sadrian 652227364Sadrian /* mark previous frame */ 653227364Sadrian wh = mtod(last->bf_m, struct ieee80211_frame *); 654227364Sadrian wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; 655227364Sadrian bus_dmamap_sync(sc->sc_dmat, last->bf_dmamap, 656227364Sadrian BUS_DMASYNC_PREWRITE); 657227364Sadrian 658227364Sadrian /* link descriptor */ 659227364Sadrian *txq->axq_link = bf->bf_daddr; 660227364Sadrian } 661227364Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 662238609Sadrian ath_hal_gettxdesclinkptr(sc->sc_ah, bf->bf_lastds, &txq->axq_link); 663227364Sadrian} 664227364Sadrian 665227364Sadrian/* 666227364Sadrian * Hand-off packet to a hardware queue. 667227364Sadrian */ 668227364Sadrianstatic void 669229949Sadrianath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq, 670229949Sadrian struct ath_buf *bf) 671227364Sadrian{ 672227364Sadrian struct ath_hal *ah = sc->sc_ah; 673227364Sadrian 674227364Sadrian /* 675218065Sadrian * Insert the frame on the outbound list and pass it on 676218065Sadrian * to the hardware. Multicast frames buffered for power 677218065Sadrian * save stations and transmit from the CAB queue are stored 678218065Sadrian * on a s/w only queue and loaded on to the CAB queue in 679218065Sadrian * the SWBA handler since frames only go out on DTIM and 680218065Sadrian * to avoid possible races. 681218065Sadrian */ 682227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 683218065Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 684227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 685227364Sadrian KASSERT(txq->axq_qnum != ATH_TXQ_SWQ, 686227364Sadrian ("ath_tx_handoff_hw called for mcast queue")); 687227364Sadrian 688227651Sadrian#if 0 689227651Sadrian /* 690227651Sadrian * This causes a LOR. Find out where the PCU lock is being 691227651Sadrian * held whilst the TXQ lock is grabbed - that shouldn't 692227651Sadrian * be occuring. 693227651Sadrian */ 694227651Sadrian ATH_PCU_LOCK(sc); 695227651Sadrian if (sc->sc_inreset_cnt) { 696227651Sadrian ATH_PCU_UNLOCK(sc); 697227651Sadrian DPRINTF(sc, ATH_DEBUG_RESET, 698227651Sadrian "%s: called with sc_in_reset != 0\n", 699227651Sadrian __func__); 700227651Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 701227651Sadrian "%s: queued: TXDP[%u] = %p (%p) depth %d\n", 702227651Sadrian __func__, txq->axq_qnum, 703227651Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 704227651Sadrian txq->axq_depth); 705227651Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 706227651Sadrian if (bf->bf_state.bfs_aggr) 707227651Sadrian txq->axq_aggr_depth++; 708227651Sadrian /* 709227651Sadrian * There's no need to update axq_link; the hardware 710227651Sadrian * is in reset and once the reset is complete, any 711227651Sadrian * non-empty queues will simply have DMA restarted. 712227651Sadrian */ 713227651Sadrian return; 714227651Sadrian } 715227651Sadrian ATH_PCU_UNLOCK(sc); 716227651Sadrian#endif 717227651Sadrian 718227364Sadrian /* For now, so not to generate whitespace diffs */ 719227364Sadrian if (1) { 720218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 721218065Sadrian int qbusy; 722218065Sadrian 723218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 724218065Sadrian qbusy = ath_hal_txqenabled(ah, txq->axq_qnum); 725218065Sadrian if (txq->axq_link == NULL) { 726218065Sadrian /* 727218065Sadrian * Be careful writing the address to TXDP. If 728218065Sadrian * the tx q is enabled then this write will be 729218065Sadrian * ignored. Normally this is not an issue but 730218065Sadrian * when tdma is in use and the q is beacon gated 731218065Sadrian * this race can occur. If the q is busy then 732218065Sadrian * defer the work to later--either when another 733218065Sadrian * packet comes along or when we prepare a beacon 734218065Sadrian * frame at SWBA. 735218065Sadrian */ 736218065Sadrian if (!qbusy) { 737229949Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 738229949Sadrian bf->bf_daddr); 739218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 740218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 741218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 742218065Sadrian __func__, txq->axq_qnum, 743218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 744218065Sadrian txq->axq_depth); 745218065Sadrian } else { 746218065Sadrian txq->axq_flags |= ATH_TXQ_PUTPENDING; 747218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 748218065Sadrian "%s: Q%u busy, defer enable\n", __func__, 749218065Sadrian txq->axq_qnum); 750218065Sadrian } 751218065Sadrian } else { 752218065Sadrian *txq->axq_link = bf->bf_daddr; 753218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 754218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 755218065Sadrian txq->axq_qnum, txq->axq_link, 756229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 757229949Sadrian txq->axq_depth); 758218065Sadrian if ((txq->axq_flags & ATH_TXQ_PUTPENDING) && !qbusy) { 759218065Sadrian /* 760218065Sadrian * The q was busy when we previously tried 761218065Sadrian * to write the address of the first buffer 762218065Sadrian * in the chain. Since it's not busy now 763218065Sadrian * handle this chore. We are certain the 764218065Sadrian * buffer at the front is the right one since 765218065Sadrian * axq_link is NULL only when the buffer list 766218065Sadrian * is/was empty. 767218065Sadrian */ 768218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 769227344Sadrian TAILQ_FIRST(&txq->axq_q)->bf_daddr); 770218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 771218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 772218065Sadrian "%s: Q%u restarted\n", __func__, 773218065Sadrian txq->axq_qnum); 774218065Sadrian } 775218065Sadrian } 776218065Sadrian#else 777218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 778218065Sadrian if (txq->axq_link == NULL) { 779218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 780218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 781218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 782218065Sadrian __func__, txq->axq_qnum, 783218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 784218065Sadrian txq->axq_depth); 785218065Sadrian } else { 786218065Sadrian *txq->axq_link = bf->bf_daddr; 787218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 788218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 789218065Sadrian txq->axq_qnum, txq->axq_link, 790229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 791229949Sadrian txq->axq_depth); 792218065Sadrian } 793218065Sadrian#endif /* IEEE80211_SUPPORT_TDMA */ 794227360Sadrian if (bf->bf_state.bfs_aggr) 795227360Sadrian txq->axq_aggr_depth++; 796238609Sadrian ath_hal_gettxdesclinkptr(ah, bf->bf_lastds, &txq->axq_link); 797218065Sadrian ath_hal_txstart(ah, txq->axq_qnum); 798227364Sadrian } 799227364Sadrian} 800218065Sadrian 801227364Sadrian/* 802227364Sadrian * Restart TX DMA for the given TXQ. 803227364Sadrian * 804227364Sadrian * This must be called whether the queue is empty or not. 805227364Sadrian */ 806238930Sadrianstatic void 807238930Sadrianath_legacy_tx_dma_restart(struct ath_softc *sc, struct ath_txq *txq) 808227364Sadrian{ 809227364Sadrian struct ath_hal *ah = sc->sc_ah; 810232707Sadrian struct ath_buf *bf, *bf_last; 811218065Sadrian 812227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 813227364Sadrian 814227364Sadrian /* This is always going to be cleared, empty or not */ 815227364Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 816227364Sadrian 817232707Sadrian /* XXX make this ATH_TXQ_FIRST */ 818227364Sadrian bf = TAILQ_FIRST(&txq->axq_q); 819232707Sadrian bf_last = ATH_TXQ_LAST(txq, axq_q_s); 820232707Sadrian 821227364Sadrian if (bf == NULL) 822227364Sadrian return; 823227364Sadrian 824227364Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 825239120Sadrian ath_hal_gettxdesclinkptr(ah, bf_last->bf_lastds, &txq->axq_link); 826227364Sadrian ath_hal_txstart(ah, txq->axq_qnum); 827218065Sadrian} 828218065Sadrian 829227364Sadrian/* 830227364Sadrian * Hand off a packet to the hardware (or mcast queue.) 831227364Sadrian * 832227364Sadrian * The relevant hardware txq should be locked. 833227364Sadrian */ 834227364Sadrianstatic void 835238930Sadrianath_legacy_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq, 836238930Sadrian struct ath_buf *bf) 837227364Sadrian{ 838227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 839227364Sadrian 840227364Sadrian if (txq->axq_qnum == ATH_TXQ_SWQ) 841227364Sadrian ath_tx_handoff_mcast(sc, txq, bf); 842227364Sadrian else 843227364Sadrian ath_tx_handoff_hw(sc, txq, bf); 844227364Sadrian} 845227364Sadrian 846218154Sadrianstatic int 847218154Sadrianath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni, 848229949Sadrian struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen, 849229949Sadrian int *keyix) 850218154Sadrian{ 851233330Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 852233330Sadrian "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n", 853233330Sadrian __func__, 854233330Sadrian *hdrlen, 855233330Sadrian *pktlen, 856233330Sadrian isfrag, 857233330Sadrian iswep, 858233330Sadrian m0); 859233330Sadrian 860218154Sadrian if (iswep) { 861218154Sadrian const struct ieee80211_cipher *cip; 862218154Sadrian struct ieee80211_key *k; 863218154Sadrian 864218154Sadrian /* 865218154Sadrian * Construct the 802.11 header+trailer for an encrypted 866218154Sadrian * frame. The only reason this can fail is because of an 867218154Sadrian * unknown or unsupported cipher/key type. 868218154Sadrian */ 869218154Sadrian k = ieee80211_crypto_encap(ni, m0); 870218154Sadrian if (k == NULL) { 871218154Sadrian /* 872218154Sadrian * This can happen when the key is yanked after the 873218154Sadrian * frame was queued. Just discard the frame; the 874218154Sadrian * 802.11 layer counts failures and provides 875218154Sadrian * debugging/diagnostics. 876218154Sadrian */ 877229949Sadrian return (0); 878218154Sadrian } 879218154Sadrian /* 880218154Sadrian * Adjust the packet + header lengths for the crypto 881218154Sadrian * additions and calculate the h/w key index. When 882218154Sadrian * a s/w mic is done the frame will have had any mic 883218154Sadrian * added to it prior to entry so m0->m_pkthdr.len will 884218154Sadrian * account for it. Otherwise we need to add it to the 885218154Sadrian * packet length. 886218154Sadrian */ 887218154Sadrian cip = k->wk_cipher; 888218154Sadrian (*hdrlen) += cip->ic_header; 889218154Sadrian (*pktlen) += cip->ic_header + cip->ic_trailer; 890218154Sadrian /* NB: frags always have any TKIP MIC done in s/w */ 891218154Sadrian if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag) 892218154Sadrian (*pktlen) += cip->ic_miclen; 893218154Sadrian (*keyix) = k->wk_keyix; 894218154Sadrian } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { 895218154Sadrian /* 896218154Sadrian * Use station key cache slot, if assigned. 897218154Sadrian */ 898218154Sadrian (*keyix) = ni->ni_ucastkey.wk_keyix; 899218154Sadrian if ((*keyix) == IEEE80211_KEYIX_NONE) 900218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 901218154Sadrian } else 902218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 903218154Sadrian 904229949Sadrian return (1); 905218154Sadrian} 906218154Sadrian 907233989Sadrian/* 908233989Sadrian * Calculate whether interoperability protection is required for 909233989Sadrian * this frame. 910233989Sadrian * 911233989Sadrian * This requires the rate control information be filled in, 912233989Sadrian * as the protection requirement depends upon the current 913233989Sadrian * operating mode / PHY. 914233989Sadrian */ 915233989Sadrianstatic void 916233989Sadrianath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf) 917233989Sadrian{ 918233989Sadrian struct ieee80211_frame *wh; 919233989Sadrian uint8_t rix; 920233989Sadrian uint16_t flags; 921233989Sadrian int shortPreamble; 922233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 923233989Sadrian struct ifnet *ifp = sc->sc_ifp; 924233989Sadrian struct ieee80211com *ic = ifp->if_l2com; 925233989Sadrian 926233989Sadrian flags = bf->bf_state.bfs_txflags; 927233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 928233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 929233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 930233989Sadrian 931233989Sadrian /* 932233989Sadrian * If 802.11g protection is enabled, determine whether 933233989Sadrian * to use RTS/CTS or just CTS. Note that this is only 934233989Sadrian * done for OFDM unicast frames. 935233989Sadrian */ 936233989Sadrian if ((ic->ic_flags & IEEE80211_F_USEPROT) && 937233989Sadrian rt->info[rix].phy == IEEE80211_T_OFDM && 938233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 939233989Sadrian bf->bf_state.bfs_doprot = 1; 940233989Sadrian /* XXX fragments must use CCK rates w/ protection */ 941233989Sadrian if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) { 942233989Sadrian flags |= HAL_TXDESC_RTSENA; 943233989Sadrian } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) { 944233989Sadrian flags |= HAL_TXDESC_CTSENA; 945233989Sadrian } 946233989Sadrian /* 947233989Sadrian * For frags it would be desirable to use the 948233989Sadrian * highest CCK rate for RTS/CTS. But stations 949233989Sadrian * farther away may detect it at a lower CCK rate 950233989Sadrian * so use the configured protection rate instead 951233989Sadrian * (for now). 952233989Sadrian */ 953233989Sadrian sc->sc_stats.ast_tx_protect++; 954233989Sadrian } 955233989Sadrian 956233989Sadrian /* 957233989Sadrian * If 11n protection is enabled and it's a HT frame, 958233989Sadrian * enable RTS. 959233989Sadrian * 960233989Sadrian * XXX ic_htprotmode or ic_curhtprotmode? 961233989Sadrian * XXX should it_htprotmode only matter if ic_curhtprotmode 962233989Sadrian * XXX indicates it's not a HT pure environment? 963233989Sadrian */ 964233989Sadrian if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && 965233989Sadrian rt->info[rix].phy == IEEE80211_T_HT && 966233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 967233989Sadrian flags |= HAL_TXDESC_RTSENA; 968233989Sadrian sc->sc_stats.ast_tx_htprotect++; 969233989Sadrian } 970233989Sadrian bf->bf_state.bfs_txflags = flags; 971233989Sadrian} 972233989Sadrian 973233989Sadrian/* 974233989Sadrian * Update the frame duration given the currently selected rate. 975233989Sadrian * 976233989Sadrian * This also updates the frame duration value, so it will require 977233989Sadrian * a DMA flush. 978233989Sadrian */ 979233989Sadrianstatic void 980233989Sadrianath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf) 981233989Sadrian{ 982233989Sadrian struct ieee80211_frame *wh; 983233989Sadrian uint8_t rix; 984233989Sadrian uint16_t flags; 985233989Sadrian int shortPreamble; 986233989Sadrian struct ath_hal *ah = sc->sc_ah; 987233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 988233989Sadrian int isfrag = bf->bf_m->m_flags & M_FRAG; 989233989Sadrian 990233989Sadrian flags = bf->bf_state.bfs_txflags; 991233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 992233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 993233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 994233989Sadrian 995233989Sadrian /* 996233989Sadrian * Calculate duration. This logically belongs in the 802.11 997233989Sadrian * layer but it lacks sufficient information to calculate it. 998233989Sadrian */ 999233989Sadrian if ((flags & HAL_TXDESC_NOACK) == 0 && 1000233989Sadrian (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) { 1001233989Sadrian u_int16_t dur; 1002233989Sadrian if (shortPreamble) 1003233989Sadrian dur = rt->info[rix].spAckDuration; 1004233989Sadrian else 1005233989Sadrian dur = rt->info[rix].lpAckDuration; 1006233989Sadrian if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { 1007233989Sadrian dur += dur; /* additional SIFS+ACK */ 1008233989Sadrian KASSERT(bf->bf_m->m_nextpkt != NULL, ("no fragment")); 1009233989Sadrian /* 1010233989Sadrian * Include the size of next fragment so NAV is 1011233989Sadrian * updated properly. The last fragment uses only 1012233989Sadrian * the ACK duration 1013233989Sadrian */ 1014233989Sadrian dur += ath_hal_computetxtime(ah, rt, 1015233989Sadrian bf->bf_m->m_nextpkt->m_pkthdr.len, 1016233989Sadrian rix, shortPreamble); 1017233989Sadrian } 1018233989Sadrian if (isfrag) { 1019233989Sadrian /* 1020233989Sadrian * Force hardware to use computed duration for next 1021233989Sadrian * fragment by disabling multi-rate retry which updates 1022233989Sadrian * duration based on the multi-rate duration table. 1023233989Sadrian */ 1024233989Sadrian bf->bf_state.bfs_ismrr = 0; 1025233989Sadrian bf->bf_state.bfs_try0 = ATH_TXMGTTRY; 1026233989Sadrian /* XXX update bfs_rc[0].try? */ 1027233989Sadrian } 1028233989Sadrian 1029233989Sadrian /* Update the duration field itself */ 1030233989Sadrian *(u_int16_t *)wh->i_dur = htole16(dur); 1031233989Sadrian } 1032233989Sadrian} 1033233989Sadrian 1034218932Sadrianstatic uint8_t 1035218932Sadrianath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt, 1036227364Sadrian int cix, int shortPreamble) 1037218157Sadrian{ 1038218932Sadrian uint8_t ctsrate; 1039218932Sadrian 1040218157Sadrian /* 1041218157Sadrian * CTS transmit rate is derived from the transmit rate 1042218157Sadrian * by looking in the h/w rate table. We must also factor 1043218157Sadrian * in whether or not a short preamble is to be used. 1044218157Sadrian */ 1045218157Sadrian /* NB: cix is set above where RTS/CTS is enabled */ 1046218157Sadrian KASSERT(cix != 0xff, ("cix not setup")); 1047218932Sadrian ctsrate = rt->info[cix].rateCode; 1048218932Sadrian 1049218932Sadrian /* XXX this should only matter for legacy rates */ 1050218932Sadrian if (shortPreamble) 1051218932Sadrian ctsrate |= rt->info[cix].shortPreamble; 1052218932Sadrian 1053229949Sadrian return (ctsrate); 1054218932Sadrian} 1055218932Sadrian 1056218932Sadrian/* 1057218932Sadrian * Calculate the RTS/CTS duration for legacy frames. 1058218932Sadrian */ 1059218932Sadrianstatic int 1060218932Sadrianath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix, 1061218932Sadrian int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt, 1062218932Sadrian int flags) 1063218932Sadrian{ 1064218932Sadrian int ctsduration = 0; 1065218932Sadrian 1066218932Sadrian /* This mustn't be called for HT modes */ 1067218932Sadrian if (rt->info[cix].phy == IEEE80211_T_HT) { 1068218932Sadrian printf("%s: HT rate where it shouldn't be (0x%x)\n", 1069218932Sadrian __func__, rt->info[cix].rateCode); 1070229949Sadrian return (-1); 1071218932Sadrian } 1072218932Sadrian 1073218157Sadrian /* 1074218157Sadrian * Compute the transmit duration based on the frame 1075218157Sadrian * size and the size of an ACK frame. We call into the 1076218157Sadrian * HAL to do the computation since it depends on the 1077218157Sadrian * characteristics of the actual PHY being used. 1078218157Sadrian * 1079218157Sadrian * NB: CTS is assumed the same size as an ACK so we can 1080218157Sadrian * use the precalculated ACK durations. 1081218157Sadrian */ 1082218157Sadrian if (shortPreamble) { 1083218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1084218932Sadrian ctsduration += rt->info[cix].spAckDuration; 1085218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1086218157Sadrian rt, pktlen, rix, AH_TRUE); 1087218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1088218932Sadrian ctsduration += rt->info[rix].spAckDuration; 1089218157Sadrian } else { 1090218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1091218932Sadrian ctsduration += rt->info[cix].lpAckDuration; 1092218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1093218157Sadrian rt, pktlen, rix, AH_FALSE); 1094218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1095218932Sadrian ctsduration += rt->info[rix].lpAckDuration; 1096218157Sadrian } 1097218932Sadrian 1098229949Sadrian return (ctsduration); 1099218157Sadrian} 1100218157Sadrian 1101227364Sadrian/* 1102227364Sadrian * Update the given ath_buf with updated rts/cts setup and duration 1103227364Sadrian * values. 1104227364Sadrian * 1105227364Sadrian * To support rate lookups for each software retry, the rts/cts rate 1106227364Sadrian * and cts duration must be re-calculated. 1107227364Sadrian * 1108227364Sadrian * This function assumes the RTS/CTS flags have been set as needed; 1109227364Sadrian * mrr has been disabled; and the rate control lookup has been done. 1110227364Sadrian * 1111227364Sadrian * XXX TODO: MRR need only be disabled for the pre-11n NICs. 1112227364Sadrian * XXX The 11n NICs support per-rate RTS/CTS configuration. 1113227364Sadrian */ 1114227364Sadrianstatic void 1115227364Sadrianath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf) 1116218065Sadrian{ 1117227364Sadrian uint16_t ctsduration = 0; 1118227364Sadrian uint8_t ctsrate = 0; 1119227364Sadrian uint8_t rix = bf->bf_state.bfs_rc[0].rix; 1120227364Sadrian uint8_t cix = 0; 1121227364Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1122227364Sadrian 1123227364Sadrian /* 1124227364Sadrian * No RTS/CTS enabled? Don't bother. 1125227364Sadrian */ 1126233966Sadrian if ((bf->bf_state.bfs_txflags & 1127227364Sadrian (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) { 1128227364Sadrian /* XXX is this really needed? */ 1129227364Sadrian bf->bf_state.bfs_ctsrate = 0; 1130227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1131227364Sadrian return; 1132227364Sadrian } 1133227364Sadrian 1134227364Sadrian /* 1135227364Sadrian * If protection is enabled, use the protection rix control 1136227364Sadrian * rate. Otherwise use the rate0 control rate. 1137227364Sadrian */ 1138227364Sadrian if (bf->bf_state.bfs_doprot) 1139227364Sadrian rix = sc->sc_protrix; 1140227364Sadrian else 1141227364Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1142227364Sadrian 1143227364Sadrian /* 1144227364Sadrian * If the raw path has hard-coded ctsrate0 to something, 1145227364Sadrian * use it. 1146227364Sadrian */ 1147227364Sadrian if (bf->bf_state.bfs_ctsrate0 != 0) 1148227364Sadrian cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0); 1149227364Sadrian else 1150227364Sadrian /* Control rate from above */ 1151227364Sadrian cix = rt->info[rix].controlRate; 1152227364Sadrian 1153227364Sadrian /* Calculate the rtscts rate for the given cix */ 1154227364Sadrian ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix, 1155227364Sadrian bf->bf_state.bfs_shpream); 1156227364Sadrian 1157227364Sadrian /* The 11n chipsets do ctsduration calculations for you */ 1158227364Sadrian if (! ath_tx_is_11n(sc)) 1159227364Sadrian ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix, 1160227364Sadrian bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen, 1161233966Sadrian rt, bf->bf_state.bfs_txflags); 1162227364Sadrian 1163227364Sadrian /* Squirrel away in ath_buf */ 1164227364Sadrian bf->bf_state.bfs_ctsrate = ctsrate; 1165227364Sadrian bf->bf_state.bfs_ctsduration = ctsduration; 1166227364Sadrian 1167227364Sadrian /* 1168227364Sadrian * Must disable multi-rate retry when using RTS/CTS. 1169227364Sadrian */ 1170238961Sadrian if (!sc->sc_mrrprot) { 1171238961Sadrian bf->bf_state.bfs_ismrr = 0; 1172238961Sadrian bf->bf_state.bfs_try0 = 1173238961Sadrian bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */ 1174238961Sadrian } 1175227364Sadrian} 1176227364Sadrian 1177227364Sadrian/* 1178227364Sadrian * Setup the descriptor chain for a normal or fast-frame 1179227364Sadrian * frame. 1180239051Sadrian * 1181239051Sadrian * XXX TODO: extend to include the destination hardware QCU ID. 1182239051Sadrian * Make sure that is correct. Make sure that when being added 1183239051Sadrian * to the mcastq, the CABQ QCUID is set or things will get a bit 1184239051Sadrian * odd. 1185227364Sadrian */ 1186227364Sadrianstatic void 1187227364Sadrianath_tx_setds(struct ath_softc *sc, struct ath_buf *bf) 1188227364Sadrian{ 1189227364Sadrian struct ath_desc *ds = bf->bf_desc; 1190227364Sadrian struct ath_hal *ah = sc->sc_ah; 1191227364Sadrian 1192227364Sadrian ath_hal_setuptxdesc(ah, ds 1193227364Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 1194227364Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 1195227364Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 1196227364Sadrian , bf->bf_state.bfs_txpower /* txpower */ 1197227364Sadrian , bf->bf_state.bfs_txrate0 1198227364Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 1199227364Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 1200227364Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 1201233966Sadrian , bf->bf_state.bfs_txflags /* flags */ 1202227364Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 1203227364Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 1204227364Sadrian ); 1205227364Sadrian 1206227364Sadrian /* 1207227364Sadrian * This will be overriden when the descriptor chain is written. 1208227364Sadrian */ 1209227364Sadrian bf->bf_lastds = ds; 1210227364Sadrian bf->bf_last = bf; 1211227364Sadrian 1212238947Sadrian /* Set rate control and descriptor chain for this frame */ 1213238947Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 1214238947Sadrian ath_tx_chaindesclist(sc, bf); 1215227364Sadrian} 1216227364Sadrian 1217227364Sadrian/* 1218227364Sadrian * Do a rate lookup. 1219227364Sadrian * 1220227364Sadrian * This performs a rate lookup for the given ath_buf only if it's required. 1221227364Sadrian * Non-data frames and raw frames don't require it. 1222227364Sadrian * 1223227364Sadrian * This populates the primary and MRR entries; MRR values are 1224227364Sadrian * then disabled later on if something requires it (eg RTS/CTS on 1225227364Sadrian * pre-11n chipsets. 1226227364Sadrian * 1227227364Sadrian * This needs to be done before the RTS/CTS fields are calculated 1228227364Sadrian * as they may depend upon the rate chosen. 1229227364Sadrian */ 1230227364Sadrianstatic void 1231227364Sadrianath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf) 1232227364Sadrian{ 1233227364Sadrian uint8_t rate, rix; 1234227364Sadrian int try0; 1235227364Sadrian 1236227364Sadrian if (! bf->bf_state.bfs_doratelookup) 1237227364Sadrian return; 1238227364Sadrian 1239227364Sadrian /* Get rid of any previous state */ 1240227364Sadrian bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1241227364Sadrian 1242227364Sadrian ATH_NODE_LOCK(ATH_NODE(bf->bf_node)); 1243227364Sadrian ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream, 1244227364Sadrian bf->bf_state.bfs_pktlen, &rix, &try0, &rate); 1245227364Sadrian 1246227364Sadrian /* In case MRR is disabled, make sure rc[0] is setup correctly */ 1247227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1248227364Sadrian bf->bf_state.bfs_rc[0].ratecode = rate; 1249227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1250227364Sadrian 1251227364Sadrian if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY) 1252227364Sadrian ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix, 1253227364Sadrian bf->bf_state.bfs_rc); 1254227364Sadrian ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node)); 1255227364Sadrian 1256227364Sadrian sc->sc_txrix = rix; /* for LED blinking */ 1257227364Sadrian sc->sc_lastdatarix = rix; /* for fast frames */ 1258227364Sadrian bf->bf_state.bfs_try0 = try0; 1259227364Sadrian bf->bf_state.bfs_txrate0 = rate; 1260227364Sadrian} 1261227364Sadrian 1262227364Sadrian/* 1263227364Sadrian * Transmit the given frame to the hardware. 1264227364Sadrian * 1265227364Sadrian * The frame must already be setup; rate control must already have 1266227364Sadrian * been done. 1267227364Sadrian * 1268227364Sadrian * XXX since the TXQ lock is being held here (and I dislike holding 1269227364Sadrian * it for this long when not doing software aggregation), later on 1270227364Sadrian * break this function into "setup_normal" and "xmit_normal". The 1271227364Sadrian * lock only needs to be held for the ath_tx_handoff call. 1272227364Sadrian */ 1273227364Sadrianstatic void 1274227364Sadrianath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq, 1275227364Sadrian struct ath_buf *bf) 1276227364Sadrian{ 1277227364Sadrian 1278227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 1279227364Sadrian 1280227364Sadrian /* Setup the descriptor before handoff */ 1281227364Sadrian ath_tx_do_ratelookup(sc, bf); 1282233989Sadrian ath_tx_calc_duration(sc, bf); 1283233989Sadrian ath_tx_calc_protection(sc, bf); 1284233989Sadrian ath_tx_set_rtscts(sc, bf); 1285227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 1286227364Sadrian ath_tx_setds(sc, bf); 1287227364Sadrian 1288240724Sadrian /* XXX Bump TID HWQ counter */ 1289240724Sadrian /* XXX Assign a completion handler */ 1290240724Sadrian 1291227364Sadrian /* Hand off to hardware */ 1292227364Sadrian ath_tx_handoff(sc, txq, bf); 1293227364Sadrian} 1294227364Sadrian 1295240722Sadrian/* 1296240722Sadrian * Do the basic frame setup stuff that's required before the frame 1297240722Sadrian * is added to a software queue. 1298240722Sadrian * 1299240722Sadrian * All frames get mostly the same treatment and it's done once. 1300240722Sadrian * Retransmits fiddle with things like the rate control setup, 1301240722Sadrian * setting the retransmit bit in the packet; doing relevant DMA/bus 1302240722Sadrian * syncing and relinking it (back) into the hardware TX queue. 1303240722Sadrian * 1304240722Sadrian * Note that this may cause the mbuf to be reallocated, so 1305240722Sadrian * m0 may not be valid. 1306240722Sadrian */ 1307227364Sadrianstatic int 1308227364Sadrianath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni, 1309234009Sadrian struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq) 1310227364Sadrian{ 1311218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1312218065Sadrian struct ath_hal *ah = sc->sc_ah; 1313218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1314218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1315218065Sadrian const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; 1316218065Sadrian int error, iswep, ismcast, isfrag, ismrr; 1317227364Sadrian int keyix, hdrlen, pktlen, try0 = 0; 1318227364Sadrian u_int8_t rix = 0, txrate = 0; 1319218065Sadrian struct ath_desc *ds; 1320218065Sadrian struct ieee80211_frame *wh; 1321227364Sadrian u_int subtype, flags; 1322218065Sadrian HAL_PKT_TYPE atype; 1323218065Sadrian const HAL_RATE_TABLE *rt; 1324218065Sadrian HAL_BOOL shortPreamble; 1325218065Sadrian struct ath_node *an; 1326218065Sadrian u_int pri; 1327218065Sadrian 1328236880Sadrian /* 1329236880Sadrian * To ensure that both sequence numbers and the CCMP PN handling 1330236880Sadrian * is "correct", make sure that the relevant TID queue is locked. 1331236880Sadrian * Otherwise the CCMP PN and seqno may appear out of order, causing 1332236880Sadrian * re-ordered frames to have out of order CCMP PN's, resulting 1333236880Sadrian * in many, many frame drops. 1334236880Sadrian */ 1335236880Sadrian ATH_TXQ_LOCK_ASSERT(txq); 1336236880Sadrian 1337218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1338218065Sadrian iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; 1339218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1340218065Sadrian isfrag = m0->m_flags & M_FRAG; 1341218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1342218065Sadrian /* 1343218065Sadrian * Packet length must not include any 1344218065Sadrian * pad bytes; deduct them here. 1345218065Sadrian */ 1346218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3); 1347218065Sadrian 1348218154Sadrian /* Handle encryption twiddling if needed */ 1349227364Sadrian if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen, 1350227364Sadrian &pktlen, &keyix)) { 1351218154Sadrian ath_freetx(m0); 1352218154Sadrian return EIO; 1353218154Sadrian } 1354218065Sadrian 1355218154Sadrian /* packet header may have moved, reset our local pointer */ 1356218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1357218065Sadrian 1358218065Sadrian pktlen += IEEE80211_CRC_LEN; 1359218065Sadrian 1360218065Sadrian /* 1361218065Sadrian * Load the DMA map so any coalescing is done. This 1362218065Sadrian * also calculates the number of descriptors we need. 1363218065Sadrian */ 1364218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1365218065Sadrian if (error != 0) 1366218065Sadrian return error; 1367218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1368218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1369218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1370218065Sadrian 1371218065Sadrian /* setup descriptors */ 1372218065Sadrian ds = bf->bf_desc; 1373218065Sadrian rt = sc->sc_currates; 1374218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1375218065Sadrian 1376218065Sadrian /* 1377218065Sadrian * NB: the 802.11 layer marks whether or not we should 1378218065Sadrian * use short preamble based on the current mode and 1379218065Sadrian * negotiated parameters. 1380218065Sadrian */ 1381218065Sadrian if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 1382218065Sadrian (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) { 1383218065Sadrian shortPreamble = AH_TRUE; 1384218065Sadrian sc->sc_stats.ast_tx_shortpre++; 1385218065Sadrian } else { 1386218065Sadrian shortPreamble = AH_FALSE; 1387218065Sadrian } 1388218065Sadrian 1389218065Sadrian an = ATH_NODE(ni); 1390240724Sadrian //flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1391240724Sadrian flags = 0; 1392218065Sadrian ismrr = 0; /* default no multi-rate retry*/ 1393218065Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 1394218065Sadrian /* XXX use txparams instead of fixed values */ 1395218065Sadrian /* 1396218065Sadrian * Calculate Atheros packet type from IEEE80211 packet header, 1397218065Sadrian * setup for rate calculations, and select h/w transmit queue. 1398218065Sadrian */ 1399218065Sadrian switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1400218065Sadrian case IEEE80211_FC0_TYPE_MGT: 1401218065Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1402218065Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) 1403218065Sadrian atype = HAL_PKT_TYPE_BEACON; 1404218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) 1405218065Sadrian atype = HAL_PKT_TYPE_PROBE_RESP; 1406218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) 1407218065Sadrian atype = HAL_PKT_TYPE_ATIM; 1408218065Sadrian else 1409218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* XXX */ 1410218065Sadrian rix = an->an_mgmtrix; 1411218065Sadrian txrate = rt->info[rix].rateCode; 1412218065Sadrian if (shortPreamble) 1413218065Sadrian txrate |= rt->info[rix].shortPreamble; 1414218065Sadrian try0 = ATH_TXMGTTRY; 1415218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1416218065Sadrian break; 1417218065Sadrian case IEEE80211_FC0_TYPE_CTL: 1418218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */ 1419218065Sadrian rix = an->an_mgmtrix; 1420218065Sadrian txrate = rt->info[rix].rateCode; 1421218065Sadrian if (shortPreamble) 1422218065Sadrian txrate |= rt->info[rix].shortPreamble; 1423218065Sadrian try0 = ATH_TXMGTTRY; 1424218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1425218065Sadrian break; 1426218065Sadrian case IEEE80211_FC0_TYPE_DATA: 1427218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* default */ 1428218065Sadrian /* 1429218065Sadrian * Data frames: multicast frames go out at a fixed rate, 1430218065Sadrian * EAPOL frames use the mgmt frame rate; otherwise consult 1431218065Sadrian * the rate control module for the rate to use. 1432218065Sadrian */ 1433218065Sadrian if (ismcast) { 1434218065Sadrian rix = an->an_mcastrix; 1435218065Sadrian txrate = rt->info[rix].rateCode; 1436218065Sadrian if (shortPreamble) 1437218065Sadrian txrate |= rt->info[rix].shortPreamble; 1438218065Sadrian try0 = 1; 1439218065Sadrian } else if (m0->m_flags & M_EAPOL) { 1440218065Sadrian /* XXX? maybe always use long preamble? */ 1441218065Sadrian rix = an->an_mgmtrix; 1442218065Sadrian txrate = rt->info[rix].rateCode; 1443218065Sadrian if (shortPreamble) 1444218065Sadrian txrate |= rt->info[rix].shortPreamble; 1445218065Sadrian try0 = ATH_TXMAXTRY; /* XXX?too many? */ 1446218065Sadrian } else { 1447227364Sadrian /* 1448227364Sadrian * Do rate lookup on each TX, rather than using 1449227364Sadrian * the hard-coded TX information decided here. 1450227364Sadrian */ 1451227364Sadrian ismrr = 1; 1452227364Sadrian bf->bf_state.bfs_doratelookup = 1; 1453218065Sadrian } 1454218065Sadrian if (cap->cap_wmeParams[pri].wmep_noackPolicy) 1455218065Sadrian flags |= HAL_TXDESC_NOACK; 1456218065Sadrian break; 1457218065Sadrian default: 1458218065Sadrian if_printf(ifp, "bogus frame type 0x%x (%s)\n", 1459218065Sadrian wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__); 1460218065Sadrian /* XXX statistic */ 1461218065Sadrian ath_freetx(m0); 1462218065Sadrian return EIO; 1463218065Sadrian } 1464218065Sadrian 1465237041Sadrian /* 1466237041Sadrian * There are two known scenarios where the frame AC doesn't match 1467237041Sadrian * what the destination TXQ is. 1468237041Sadrian * 1469237041Sadrian * + non-QoS frames (eg management?) that the net80211 stack has 1470237041Sadrian * assigned a higher AC to, but since it's a non-QoS TID, it's 1471237041Sadrian * being thrown into TID 16. TID 16 gets the AC_BE queue. 1472237041Sadrian * It's quite possible that management frames should just be 1473237041Sadrian * direct dispatched to hardware rather than go via the software 1474237041Sadrian * queue; that should be investigated in the future. There are 1475237041Sadrian * some specific scenarios where this doesn't make sense, mostly 1476237041Sadrian * surrounding ADDBA request/response - hence why that is special 1477237041Sadrian * cased. 1478237041Sadrian * 1479237041Sadrian * + Multicast frames going into the VAP mcast queue. That shows up 1480237041Sadrian * as "TXQ 11". 1481237041Sadrian * 1482237041Sadrian * This driver should eventually support separate TID and TXQ locking, 1483237041Sadrian * allowing for arbitrary AC frames to appear on arbitrary software 1484237041Sadrian * queues, being queued to the "correct" hardware queue when needed. 1485237041Sadrian */ 1486237041Sadrian#if 0 1487235750Sadrian if (txq != sc->sc_ac2q[pri]) { 1488235750Sadrian device_printf(sc->sc_dev, 1489235750Sadrian "%s: txq=%p (%d), pri=%d, pri txq=%p (%d)\n", 1490235750Sadrian __func__, 1491235750Sadrian txq, 1492235750Sadrian txq->axq_qnum, 1493235750Sadrian pri, 1494235750Sadrian sc->sc_ac2q[pri], 1495235750Sadrian sc->sc_ac2q[pri]->axq_qnum); 1496235750Sadrian } 1497237041Sadrian#endif 1498235750Sadrian 1499218065Sadrian /* 1500218065Sadrian * Calculate miscellaneous flags. 1501218065Sadrian */ 1502218065Sadrian if (ismcast) { 1503218065Sadrian flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ 1504218065Sadrian } else if (pktlen > vap->iv_rtsthreshold && 1505218065Sadrian (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) { 1506218065Sadrian flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ 1507218065Sadrian sc->sc_stats.ast_tx_rts++; 1508218065Sadrian } 1509218065Sadrian if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */ 1510218065Sadrian sc->sc_stats.ast_tx_noack++; 1511218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 1512218065Sadrian if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) { 1513218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA, 1514218065Sadrian "%s: discard frame, ACK required w/ TDMA\n", __func__); 1515218065Sadrian sc->sc_stats.ast_tdma_ack++; 1516218065Sadrian ath_freetx(m0); 1517218065Sadrian return EIO; 1518218065Sadrian } 1519218065Sadrian#endif 1520218065Sadrian 1521218065Sadrian /* 1522227364Sadrian * Determine if a tx interrupt should be generated for 1523227364Sadrian * this descriptor. We take a tx interrupt to reap 1524227364Sadrian * descriptors when the h/w hits an EOL condition or 1525227364Sadrian * when the descriptor is specifically marked to generate 1526227364Sadrian * an interrupt. We periodically mark descriptors in this 1527227364Sadrian * way to insure timely replenishing of the supply needed 1528227364Sadrian * for sending frames. Defering interrupts reduces system 1529227364Sadrian * load and potentially allows more concurrent work to be 1530227364Sadrian * done but if done to aggressively can cause senders to 1531227364Sadrian * backup. 1532227364Sadrian * 1533227364Sadrian * NB: use >= to deal with sc_txintrperiod changing 1534227364Sadrian * dynamically through sysctl. 1535218065Sadrian */ 1536227364Sadrian if (flags & HAL_TXDESC_INTREQ) { 1537227364Sadrian txq->axq_intrcnt = 0; 1538227364Sadrian } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) { 1539227364Sadrian flags |= HAL_TXDESC_INTREQ; 1540227364Sadrian txq->axq_intrcnt = 0; 1541227364Sadrian } 1542218932Sadrian 1543227364Sadrian /* This point forward is actual TX bits */ 1544218065Sadrian 1545218065Sadrian /* 1546218065Sadrian * At this point we are committed to sending the frame 1547218065Sadrian * and we don't need to look at m_nextpkt; clear it in 1548218065Sadrian * case this frame is part of frag chain. 1549218065Sadrian */ 1550218065Sadrian m0->m_nextpkt = NULL; 1551218065Sadrian 1552218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1553218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len, 1554218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1555218065Sadrian 1556218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1557218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1558218065Sadrian 1559218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1560218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1561218065Sadrian if (iswep) 1562218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1563218065Sadrian if (isfrag) 1564218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1565218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1566218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1567218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1568218065Sadrian 1569218065Sadrian ieee80211_radiotap_tx(vap, m0); 1570218065Sadrian } 1571218065Sadrian 1572227364Sadrian /* Blank the legacy rate array */ 1573227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1574227364Sadrian 1575218065Sadrian /* 1576227364Sadrian * ath_buf_set_rate needs at least one rate/try to setup 1577227364Sadrian * the rate scenario. 1578227364Sadrian */ 1579227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1580227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1581227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1582227364Sadrian 1583227364Sadrian /* Store the decided rate index values away */ 1584227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1585227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1586227364Sadrian bf->bf_state.bfs_atype = atype; 1587227364Sadrian bf->bf_state.bfs_txpower = ni->ni_txpower; 1588227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1589227364Sadrian bf->bf_state.bfs_try0 = try0; 1590227364Sadrian bf->bf_state.bfs_keyix = keyix; 1591227364Sadrian bf->bf_state.bfs_txantenna = sc->sc_txantenna; 1592233966Sadrian bf->bf_state.bfs_txflags = flags; 1593227364Sadrian bf->bf_state.bfs_shpream = shortPreamble; 1594227364Sadrian 1595227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1596227364Sadrian bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */ 1597227364Sadrian bf->bf_state.bfs_ctsrate = 0; /* calculated later */ 1598227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1599227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1600227364Sadrian 1601227364Sadrian return 0; 1602227364Sadrian} 1603227364Sadrian 1604227364Sadrian/* 1605240724Sadrian * Queue a frame to the hardware or software queue. 1606227364Sadrian * 1607227364Sadrian * This can be called by the net80211 code. 1608227364Sadrian * 1609227364Sadrian * XXX what about locking? Or, push the seqno assign into the 1610227364Sadrian * XXX aggregate scheduler so its serialised? 1611240724Sadrian * 1612240724Sadrian * XXX When sending management frames via ath_raw_xmit(), 1613240724Sadrian * should CLRDMASK be set unconditionally? 1614227364Sadrian */ 1615227364Sadrianint 1616227364Sadrianath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, 1617227364Sadrian struct ath_buf *bf, struct mbuf *m0) 1618227364Sadrian{ 1619227364Sadrian struct ieee80211vap *vap = ni->ni_vap; 1620227364Sadrian struct ath_vap *avp = ATH_VAP(vap); 1621232764Sadrian int r = 0; 1622227364Sadrian u_int pri; 1623227364Sadrian int tid; 1624227364Sadrian struct ath_txq *txq; 1625227364Sadrian int ismcast; 1626227364Sadrian const struct ieee80211_frame *wh; 1627227364Sadrian int is_ampdu, is_ampdu_tx, is_ampdu_pending; 1628236872Sadrian ieee80211_seq seqno; 1629227364Sadrian uint8_t type, subtype; 1630227364Sadrian 1631227364Sadrian /* 1632227364Sadrian * Determine the target hardware queue. 1633218065Sadrian * 1634234009Sadrian * For multicast frames, the txq gets overridden appropriately 1635234009Sadrian * depending upon the state of PS. 1636227364Sadrian * 1637227364Sadrian * For any other frame, we do a TID/QoS lookup inside the frame 1638227364Sadrian * to see what the TID should be. If it's a non-QoS frame, the 1639227364Sadrian * AC and TID are overridden. The TID/TXQ code assumes the 1640227364Sadrian * TID is on a predictable hardware TXQ, so we don't support 1641227364Sadrian * having a node TID queued to multiple hardware TXQs. 1642227364Sadrian * This may change in the future but would require some locking 1643227364Sadrian * fudgery. 1644218065Sadrian */ 1645227364Sadrian pri = ath_tx_getac(sc, m0); 1646227364Sadrian tid = ath_tx_gettid(sc, m0); 1647218065Sadrian 1648227364Sadrian txq = sc->sc_ac2q[pri]; 1649227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 1650227364Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1651227364Sadrian type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 1652227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1653227364Sadrian 1654232764Sadrian /* 1655232764Sadrian * Enforce how deep the multicast queue can grow. 1656232764Sadrian * 1657232764Sadrian * XXX duplicated in ath_raw_xmit(). 1658232764Sadrian */ 1659232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1660232764Sadrian ATH_TXQ_LOCK(sc->sc_cabq); 1661232764Sadrian 1662232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 1663232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 1664232764Sadrian r = ENOBUFS; 1665232764Sadrian } 1666232764Sadrian 1667232764Sadrian ATH_TXQ_UNLOCK(sc->sc_cabq); 1668232764Sadrian 1669232764Sadrian if (r != 0) { 1670232764Sadrian m_freem(m0); 1671232764Sadrian return r; 1672232764Sadrian } 1673232764Sadrian } 1674232764Sadrian 1675227364Sadrian /* A-MPDU TX */ 1676227364Sadrian is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid); 1677227364Sadrian is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid); 1678227364Sadrian is_ampdu = is_ampdu_tx | is_ampdu_pending; 1679227364Sadrian 1680236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ac=%d, is_ampdu=%d\n", 1681236872Sadrian __func__, tid, pri, is_ampdu); 1682227364Sadrian 1683239051Sadrian /* Set local packet state, used to queue packets to hardware */ 1684239051Sadrian bf->bf_state.bfs_tid = tid; 1685239051Sadrian bf->bf_state.bfs_txq = txq; 1686239051Sadrian bf->bf_state.bfs_pri = pri; 1687239051Sadrian 1688232753Sadrian /* 1689234009Sadrian * When servicing one or more stations in power-save mode 1690234009Sadrian * (or) if there is some mcast data waiting on the mcast 1691234009Sadrian * queue (to prevent out of order delivery) multicast frames 1692234009Sadrian * must be bufferd until after the beacon. 1693234009Sadrian * 1694234009Sadrian * TODO: we should lock the mcastq before we check the length. 1695232753Sadrian */ 1696239051Sadrian if (ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) { 1697227364Sadrian txq = &avp->av_mcastq; 1698239051Sadrian /* 1699239051Sadrian * Mark the frame as eventually belonging on the CAB 1700239051Sadrian * queue, so the descriptor setup functions will 1701239051Sadrian * correctly initialise the descriptor 'qcuId' field. 1702239051Sadrian */ 1703239051Sadrian bf->bf_state.bfs_txq = sc->sc_cabq; 1704239051Sadrian } 1705227364Sadrian 1706227364Sadrian /* Do the generic frame setup */ 1707227364Sadrian /* XXX should just bzero the bf_state? */ 1708227364Sadrian bf->bf_state.bfs_dobaw = 0; 1709227364Sadrian 1710236880Sadrian /* 1711236880Sadrian * Acquire the TXQ lock early, so both the encap and seqno 1712236880Sadrian * are allocated together. 1713239051Sadrian * 1714239051Sadrian * XXX should TXQ for CABQ traffic be the multicast queue, 1715239051Sadrian * or the TXQ the given PRI would allocate from? (eg for 1716239051Sadrian * sequence number allocation locking.) 1717236880Sadrian */ 1718236880Sadrian ATH_TXQ_LOCK(txq); 1719236880Sadrian 1720227364Sadrian /* A-MPDU TX? Manually set sequence number */ 1721236880Sadrian /* 1722236880Sadrian * Don't do it whilst pending; the net80211 layer still 1723236880Sadrian * assigns them. 1724236880Sadrian */ 1725227364Sadrian if (is_ampdu_tx) { 1726227364Sadrian /* 1727227364Sadrian * Always call; this function will 1728227364Sadrian * handle making sure that null data frames 1729227364Sadrian * don't get a sequence number from the current 1730227364Sadrian * TID and thus mess with the BAW. 1731227364Sadrian */ 1732236872Sadrian seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0); 1733236874Sadrian 1734236874Sadrian /* 1735236874Sadrian * Don't add QoS NULL frames to the BAW. 1736236874Sadrian */ 1737236872Sadrian if (IEEE80211_QOS_HAS_SEQ(wh) && 1738236872Sadrian subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL) { 1739227364Sadrian bf->bf_state.bfs_dobaw = 1; 1740227364Sadrian } 1741218240Sadrian } 1742218240Sadrian 1743218065Sadrian /* 1744227364Sadrian * If needed, the sequence number has been assigned. 1745227364Sadrian * Squirrel it away somewhere easy to get to. 1746218065Sadrian */ 1747236872Sadrian bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1748227364Sadrian 1749227364Sadrian /* Is ampdu pending? fetch the seqno and print it out */ 1750227364Sadrian if (is_ampdu_pending) 1751227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1752227364Sadrian "%s: tid %d: ampdu pending, seqno %d\n", 1753227364Sadrian __func__, tid, M_SEQNO_GET(m0)); 1754227364Sadrian 1755227364Sadrian /* This also sets up the DMA map */ 1756234009Sadrian r = ath_tx_normal_setup(sc, ni, bf, m0, txq); 1757227364Sadrian 1758227364Sadrian if (r != 0) 1759236880Sadrian goto done; 1760227364Sadrian 1761227364Sadrian /* At this point m0 could have changed! */ 1762227364Sadrian m0 = bf->bf_m; 1763227364Sadrian 1764227364Sadrian#if 1 1765218065Sadrian /* 1766227364Sadrian * If it's a multicast frame, do a direct-dispatch to the 1767227364Sadrian * destination hardware queue. Don't bother software 1768227364Sadrian * queuing it. 1769218065Sadrian */ 1770227364Sadrian /* 1771227364Sadrian * If it's a BAR frame, do a direct dispatch to the 1772227364Sadrian * destination hardware queue. Don't bother software 1773227364Sadrian * queuing it, as the TID will now be paused. 1774227364Sadrian * Sending a BAR frame can occur from the net80211 txa timer 1775227364Sadrian * (ie, retries) or from the ath txtask (completion call.) 1776227364Sadrian * It queues directly to hardware because the TID is paused 1777227364Sadrian * at this point (and won't be unpaused until the BAR has 1778227364Sadrian * either been TXed successfully or max retries has been 1779227364Sadrian * reached.) 1780227364Sadrian */ 1781227364Sadrian if (txq == &avp->av_mcastq) { 1782235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1783233227Sadrian "%s: bf=%p: mcastq: TX'ing\n", __func__, bf); 1784240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1785227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1786227364Sadrian } else if (type == IEEE80211_FC0_TYPE_CTL && 1787227364Sadrian subtype == IEEE80211_FC0_SUBTYPE_BAR) { 1788235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1789227364Sadrian "%s: BAR: TX'ing direct\n", __func__); 1790240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1791227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1792227364Sadrian } else { 1793227364Sadrian /* add to software queue */ 1794235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1795233227Sadrian "%s: bf=%p: swq: TX'ing\n", __func__, bf); 1796227364Sadrian ath_tx_swq(sc, ni, txq, bf); 1797227364Sadrian } 1798227364Sadrian#else 1799227364Sadrian /* 1800227364Sadrian * For now, since there's no software queue, 1801227364Sadrian * direct-dispatch to the hardware. 1802227364Sadrian */ 1803240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1804227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1805236880Sadrian#endif 1806236880Sadriandone: 1807227364Sadrian ATH_TXQ_UNLOCK(txq); 1808218065Sadrian 1809218065Sadrian return 0; 1810218065Sadrian} 1811218065Sadrian 1812218065Sadrianstatic int 1813218065Sadrianath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni, 1814218065Sadrian struct ath_buf *bf, struct mbuf *m0, 1815218065Sadrian const struct ieee80211_bpf_params *params) 1816218065Sadrian{ 1817218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1818218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1819218065Sadrian struct ath_hal *ah = sc->sc_ah; 1820218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1821218065Sadrian int error, ismcast, ismrr; 1822218065Sadrian int keyix, hdrlen, pktlen, try0, txantenna; 1823227364Sadrian u_int8_t rix, txrate; 1824218065Sadrian struct ieee80211_frame *wh; 1825227364Sadrian u_int flags; 1826218065Sadrian HAL_PKT_TYPE atype; 1827218065Sadrian const HAL_RATE_TABLE *rt; 1828218065Sadrian struct ath_desc *ds; 1829218065Sadrian u_int pri; 1830227364Sadrian int o_tid = -1; 1831227364Sadrian int do_override; 1832218065Sadrian 1833218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1834218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1835218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1836218065Sadrian /* 1837218065Sadrian * Packet length must not include any 1838218065Sadrian * pad bytes; deduct them here. 1839218065Sadrian */ 1840218065Sadrian /* XXX honor IEEE80211_BPF_DATAPAD */ 1841218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; 1842218065Sadrian 1843227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n", 1844227364Sadrian __func__, ismcast); 1845227364Sadrian 1846236880Sadrian pri = params->ibp_pri & 3; 1847236880Sadrian /* Override pri if the frame isn't a QoS one */ 1848236880Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 1849236880Sadrian pri = ath_tx_getac(sc, m0); 1850236880Sadrian 1851236880Sadrian /* XXX If it's an ADDBA, override the correct queue */ 1852236880Sadrian do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid); 1853236880Sadrian 1854236880Sadrian /* Map ADDBA to the correct priority */ 1855236880Sadrian if (do_override) { 1856236880Sadrian#if 0 1857236880Sadrian device_printf(sc->sc_dev, 1858236880Sadrian "%s: overriding tid %d pri %d -> %d\n", 1859236880Sadrian __func__, o_tid, pri, TID_TO_WME_AC(o_tid)); 1860236880Sadrian#endif 1861236880Sadrian pri = TID_TO_WME_AC(o_tid); 1862236880Sadrian } 1863236880Sadrian 1864236880Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[pri]); 1865236880Sadrian 1866218154Sadrian /* Handle encryption twiddling if needed */ 1867227364Sadrian if (! ath_tx_tag_crypto(sc, ni, 1868227364Sadrian m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0, 1869227364Sadrian &hdrlen, &pktlen, &keyix)) { 1870218154Sadrian ath_freetx(m0); 1871218154Sadrian return EIO; 1872218154Sadrian } 1873218154Sadrian /* packet header may have moved, reset our local pointer */ 1874218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1875218065Sadrian 1876227364Sadrian /* Do the generic frame setup */ 1877227364Sadrian /* XXX should just bzero the bf_state? */ 1878227364Sadrian bf->bf_state.bfs_dobaw = 0; 1879227364Sadrian 1880218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1881218065Sadrian if (error != 0) 1882218065Sadrian return error; 1883218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1884218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1885218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1886218065Sadrian 1887240724Sadrian /* Always enable CLRDMASK for raw frames for now.. */ 1888218065Sadrian flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1889218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1890218065Sadrian if (params->ibp_flags & IEEE80211_BPF_RTS) 1891218065Sadrian flags |= HAL_TXDESC_RTSENA; 1892227364Sadrian else if (params->ibp_flags & IEEE80211_BPF_CTS) { 1893227364Sadrian /* XXX assume 11g/11n protection? */ 1894227364Sadrian bf->bf_state.bfs_doprot = 1; 1895218065Sadrian flags |= HAL_TXDESC_CTSENA; 1896227364Sadrian } 1897218065Sadrian /* XXX leave ismcast to injector? */ 1898218065Sadrian if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast) 1899218065Sadrian flags |= HAL_TXDESC_NOACK; 1900218065Sadrian 1901218065Sadrian rt = sc->sc_currates; 1902218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1903218065Sadrian rix = ath_tx_findrix(sc, params->ibp_rate0); 1904218065Sadrian txrate = rt->info[rix].rateCode; 1905218065Sadrian if (params->ibp_flags & IEEE80211_BPF_SHORTPRE) 1906218065Sadrian txrate |= rt->info[rix].shortPreamble; 1907218065Sadrian sc->sc_txrix = rix; 1908218065Sadrian try0 = params->ibp_try0; 1909218065Sadrian ismrr = (params->ibp_try1 != 0); 1910218065Sadrian txantenna = params->ibp_pri >> 2; 1911218065Sadrian if (txantenna == 0) /* XXX? */ 1912218065Sadrian txantenna = sc->sc_txantenna; 1913218157Sadrian 1914227364Sadrian /* 1915227364Sadrian * Since ctsrate is fixed, store it away for later 1916227364Sadrian * use when the descriptor fields are being set. 1917227364Sadrian */ 1918227364Sadrian if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) 1919227364Sadrian bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate; 1920218157Sadrian 1921218065Sadrian /* 1922218065Sadrian * NB: we mark all packets as type PSPOLL so the h/w won't 1923218065Sadrian * set the sequence number, duration, etc. 1924218065Sadrian */ 1925218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; 1926218065Sadrian 1927218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1928218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len, 1929218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1930218065Sadrian 1931218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1932218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1933218065Sadrian 1934218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1935218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1936218065Sadrian if (wh->i_fc[1] & IEEE80211_FC1_WEP) 1937218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1938218065Sadrian if (m0->m_flags & M_FRAG) 1939218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1940218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1941218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1942218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1943218065Sadrian 1944218065Sadrian ieee80211_radiotap_tx(vap, m0); 1945218065Sadrian } 1946218065Sadrian 1947218065Sadrian /* 1948218065Sadrian * Formulate first tx descriptor with tx controls. 1949218065Sadrian */ 1950218065Sadrian ds = bf->bf_desc; 1951218065Sadrian /* XXX check return value? */ 1952227364Sadrian 1953227364Sadrian /* Store the decided rate index values away */ 1954227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1955227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1956227364Sadrian bf->bf_state.bfs_atype = atype; 1957227364Sadrian bf->bf_state.bfs_txpower = params->ibp_power; 1958227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1959227364Sadrian bf->bf_state.bfs_try0 = try0; 1960227364Sadrian bf->bf_state.bfs_keyix = keyix; 1961227364Sadrian bf->bf_state.bfs_txantenna = txantenna; 1962233966Sadrian bf->bf_state.bfs_txflags = flags; 1963227364Sadrian bf->bf_state.bfs_shpream = 1964227364Sadrian !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE); 1965218065Sadrian 1966239051Sadrian /* Set local packet state, used to queue packets to hardware */ 1967239051Sadrian bf->bf_state.bfs_tid = WME_AC_TO_TID(pri); 1968239051Sadrian bf->bf_state.bfs_txq = sc->sc_ac2q[pri]; 1969239051Sadrian bf->bf_state.bfs_pri = pri; 1970239051Sadrian 1971227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1972227364Sadrian bf->bf_state.bfs_ctsrate = 0; 1973227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1974227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1975218240Sadrian 1976227364Sadrian /* Blank the legacy rate array */ 1977227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1978218240Sadrian 1979227364Sadrian bf->bf_state.bfs_rc[0].rix = 1980227364Sadrian ath_tx_findrix(sc, params->ibp_rate0); 1981227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1982227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1983227364Sadrian 1984227364Sadrian if (ismrr) { 1985227364Sadrian int rix; 1986227364Sadrian 1987227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate1); 1988227364Sadrian bf->bf_state.bfs_rc[1].rix = rix; 1989227364Sadrian bf->bf_state.bfs_rc[1].tries = params->ibp_try1; 1990227364Sadrian 1991227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate2); 1992227364Sadrian bf->bf_state.bfs_rc[2].rix = rix; 1993227364Sadrian bf->bf_state.bfs_rc[2].tries = params->ibp_try2; 1994227364Sadrian 1995227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate3); 1996227364Sadrian bf->bf_state.bfs_rc[3].rix = rix; 1997227364Sadrian bf->bf_state.bfs_rc[3].tries = params->ibp_try3; 1998218065Sadrian } 1999227364Sadrian /* 2000227364Sadrian * All the required rate control decisions have been made; 2001227364Sadrian * fill in the rc flags. 2002227364Sadrian */ 2003227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2004218065Sadrian 2005227364Sadrian /* NB: no buffered multicast in power save support */ 2006227364Sadrian 2007227364Sadrian /* 2008227364Sadrian * If we're overiding the ADDBA destination, dump directly 2009227364Sadrian * into the hardware queue, right after any pending 2010227364Sadrian * frames to that node are. 2011227364Sadrian */ 2012227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n", 2013227364Sadrian __func__, do_override); 2014227364Sadrian 2015227364Sadrian if (do_override) { 2016240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2017227364Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2018227364Sadrian } else { 2019227364Sadrian /* Queue to software queue */ 2020227364Sadrian ath_tx_swq(sc, ni, sc->sc_ac2q[pri], bf); 2021227364Sadrian } 2022236880Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[pri]); 2023227364Sadrian 2024218065Sadrian return 0; 2025218065Sadrian} 2026218065Sadrian 2027227364Sadrian/* 2028227364Sadrian * Send a raw frame. 2029227364Sadrian * 2030227364Sadrian * This can be called by net80211. 2031227364Sadrian */ 2032218065Sadrianint 2033218065Sadrianath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 2034218065Sadrian const struct ieee80211_bpf_params *params) 2035218065Sadrian{ 2036218065Sadrian struct ieee80211com *ic = ni->ni_ic; 2037218065Sadrian struct ifnet *ifp = ic->ic_ifp; 2038218065Sadrian struct ath_softc *sc = ifp->if_softc; 2039218065Sadrian struct ath_buf *bf; 2040232764Sadrian struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 2041232764Sadrian int error = 0; 2042218065Sadrian 2043227651Sadrian ATH_PCU_LOCK(sc); 2044227651Sadrian if (sc->sc_inreset_cnt > 0) { 2045227651Sadrian device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; bailing\n", 2046227651Sadrian __func__); 2047227651Sadrian error = EIO; 2048227651Sadrian ATH_PCU_UNLOCK(sc); 2049227651Sadrian goto bad0; 2050227651Sadrian } 2051227651Sadrian sc->sc_txstart_cnt++; 2052227651Sadrian ATH_PCU_UNLOCK(sc); 2053227651Sadrian 2054218065Sadrian if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) { 2055218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__, 2056218065Sadrian (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ? 2057218065Sadrian "!running" : "invalid"); 2058218065Sadrian m_freem(m); 2059218065Sadrian error = ENETDOWN; 2060218065Sadrian goto bad; 2061218065Sadrian } 2062232764Sadrian 2063218065Sadrian /* 2064232764Sadrian * Enforce how deep the multicast queue can grow. 2065232764Sadrian * 2066232764Sadrian * XXX duplicated in ath_tx_start(). 2067232764Sadrian */ 2068232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 2069232764Sadrian ATH_TXQ_LOCK(sc->sc_cabq); 2070232764Sadrian 2071232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 2072232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 2073232764Sadrian error = ENOBUFS; 2074232764Sadrian } 2075232764Sadrian 2076232764Sadrian ATH_TXQ_UNLOCK(sc->sc_cabq); 2077232764Sadrian 2078232764Sadrian if (error != 0) { 2079232764Sadrian m_freem(m); 2080232764Sadrian goto bad; 2081232764Sadrian } 2082232764Sadrian } 2083232764Sadrian 2084232764Sadrian /* 2085218065Sadrian * Grab a TX buffer and associated resources. 2086218065Sadrian */ 2087237000Sadrian bf = ath_getbuf(sc, ATH_BUFTYPE_MGMT); 2088218065Sadrian if (bf == NULL) { 2089218065Sadrian sc->sc_stats.ast_tx_nobuf++; 2090218065Sadrian m_freem(m); 2091218065Sadrian error = ENOBUFS; 2092218065Sadrian goto bad; 2093218065Sadrian } 2094218065Sadrian 2095218065Sadrian if (params == NULL) { 2096218065Sadrian /* 2097218065Sadrian * Legacy path; interpret frame contents to decide 2098218065Sadrian * precisely how to send the frame. 2099218065Sadrian */ 2100218065Sadrian if (ath_tx_start(sc, ni, bf, m)) { 2101218065Sadrian error = EIO; /* XXX */ 2102218065Sadrian goto bad2; 2103218065Sadrian } 2104218065Sadrian } else { 2105218065Sadrian /* 2106218065Sadrian * Caller supplied explicit parameters to use in 2107218065Sadrian * sending the frame. 2108218065Sadrian */ 2109218065Sadrian if (ath_tx_raw_start(sc, ni, bf, m, params)) { 2110218065Sadrian error = EIO; /* XXX */ 2111218065Sadrian goto bad2; 2112218065Sadrian } 2113218065Sadrian } 2114218065Sadrian sc->sc_wd_timer = 5; 2115218065Sadrian ifp->if_opackets++; 2116218065Sadrian sc->sc_stats.ast_tx_raw++; 2117218065Sadrian 2118227651Sadrian ATH_PCU_LOCK(sc); 2119227651Sadrian sc->sc_txstart_cnt--; 2120227651Sadrian ATH_PCU_UNLOCK(sc); 2121227651Sadrian 2122218065Sadrian return 0; 2123218065Sadrianbad2: 2124218065Sadrian ATH_TXBUF_LOCK(sc); 2125236993Sadrian ath_returnbuf_head(sc, bf); 2126218065Sadrian ATH_TXBUF_UNLOCK(sc); 2127218065Sadrianbad: 2128227651Sadrian ATH_PCU_LOCK(sc); 2129227651Sadrian sc->sc_txstart_cnt--; 2130227651Sadrian ATH_PCU_UNLOCK(sc); 2131227651Sadrianbad0: 2132218065Sadrian ifp->if_oerrors++; 2133218065Sadrian sc->sc_stats.ast_tx_raw_fail++; 2134218065Sadrian ieee80211_free_node(ni); 2135227651Sadrian 2136218065Sadrian return error; 2137218065Sadrian} 2138227364Sadrian 2139227364Sadrian/* Some helper functions */ 2140227364Sadrian 2141227364Sadrian/* 2142227364Sadrian * ADDBA (and potentially others) need to be placed in the same 2143227364Sadrian * hardware queue as the TID/node it's relating to. This is so 2144227364Sadrian * it goes out after any pending non-aggregate frames to the 2145227364Sadrian * same node/TID. 2146227364Sadrian * 2147227364Sadrian * If this isn't done, the ADDBA can go out before the frames 2148227364Sadrian * queued in hardware. Even though these frames have a sequence 2149227364Sadrian * number -earlier- than the ADDBA can be transmitted (but 2150227364Sadrian * no frames whose sequence numbers are after the ADDBA should 2151227364Sadrian * be!) they'll arrive after the ADDBA - and the receiving end 2152227364Sadrian * will simply drop them as being out of the BAW. 2153227364Sadrian * 2154227364Sadrian * The frames can't be appended to the TID software queue - it'll 2155227364Sadrian * never be sent out. So these frames have to be directly 2156227364Sadrian * dispatched to the hardware, rather than queued in software. 2157227364Sadrian * So if this function returns true, the TXQ has to be 2158227364Sadrian * overridden and it has to be directly dispatched. 2159227364Sadrian * 2160227364Sadrian * It's a dirty hack, but someone's gotta do it. 2161227364Sadrian */ 2162227364Sadrian 2163227364Sadrian/* 2164227364Sadrian * XXX doesn't belong here! 2165227364Sadrian */ 2166227364Sadrianstatic int 2167227364Sadrianieee80211_is_action(struct ieee80211_frame *wh) 2168227364Sadrian{ 2169227364Sadrian /* Type: Management frame? */ 2170227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != 2171227364Sadrian IEEE80211_FC0_TYPE_MGT) 2172227364Sadrian return 0; 2173227364Sadrian 2174227364Sadrian /* Subtype: Action frame? */ 2175227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) != 2176227364Sadrian IEEE80211_FC0_SUBTYPE_ACTION) 2177227364Sadrian return 0; 2178227364Sadrian 2179227364Sadrian return 1; 2180227364Sadrian} 2181227364Sadrian 2182227364Sadrian#define MS(_v, _f) (((_v) & _f) >> _f##_S) 2183227364Sadrian/* 2184227364Sadrian * Return an alternate TID for ADDBA request frames. 2185227364Sadrian * 2186227364Sadrian * Yes, this likely should be done in the net80211 layer. 2187227364Sadrian */ 2188227364Sadrianstatic int 2189227364Sadrianath_tx_action_frame_override_queue(struct ath_softc *sc, 2190227364Sadrian struct ieee80211_node *ni, 2191227364Sadrian struct mbuf *m0, int *tid) 2192227364Sadrian{ 2193227364Sadrian struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *); 2194227364Sadrian struct ieee80211_action_ba_addbarequest *ia; 2195227364Sadrian uint8_t *frm; 2196227364Sadrian uint16_t baparamset; 2197227364Sadrian 2198227364Sadrian /* Not action frame? Bail */ 2199227364Sadrian if (! ieee80211_is_action(wh)) 2200227364Sadrian return 0; 2201227364Sadrian 2202227364Sadrian /* XXX Not needed for frames we send? */ 2203227364Sadrian#if 0 2204227364Sadrian /* Correct length? */ 2205227364Sadrian if (! ieee80211_parse_action(ni, m)) 2206227364Sadrian return 0; 2207227364Sadrian#endif 2208227364Sadrian 2209227364Sadrian /* Extract out action frame */ 2210227364Sadrian frm = (u_int8_t *)&wh[1]; 2211227364Sadrian ia = (struct ieee80211_action_ba_addbarequest *) frm; 2212227364Sadrian 2213227364Sadrian /* Not ADDBA? Bail */ 2214227364Sadrian if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA) 2215227364Sadrian return 0; 2216227364Sadrian if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST) 2217227364Sadrian return 0; 2218227364Sadrian 2219227364Sadrian /* Extract TID, return it */ 2220227364Sadrian baparamset = le16toh(ia->rq_baparamset); 2221227364Sadrian *tid = (int) MS(baparamset, IEEE80211_BAPS_TID); 2222227364Sadrian 2223227364Sadrian return 1; 2224227364Sadrian} 2225227364Sadrian#undef MS 2226227364Sadrian 2227227364Sadrian/* Per-node software queue operations */ 2228227364Sadrian 2229227364Sadrian/* 2230227364Sadrian * Add the current packet to the given BAW. 2231227364Sadrian * It is assumed that the current packet 2232227364Sadrian * 2233227364Sadrian * + fits inside the BAW; 2234227364Sadrian * + already has had a sequence number allocated. 2235227364Sadrian * 2236227364Sadrian * Since the BAW status may be modified by both the ath task and 2237227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2238227364Sadrian */ 2239227364Sadrianvoid 2240227364Sadrianath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an, 2241227364Sadrian struct ath_tid *tid, struct ath_buf *bf) 2242227364Sadrian{ 2243227364Sadrian int index, cindex; 2244227364Sadrian struct ieee80211_tx_ampdu *tap; 2245227364Sadrian 2246227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2247236873Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2248227364Sadrian 2249227364Sadrian if (bf->bf_state.bfs_isretried) 2250227364Sadrian return; 2251227364Sadrian 2252236886Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2253236886Sadrian 2254236880Sadrian if (! bf->bf_state.bfs_dobaw) { 2255236880Sadrian device_printf(sc->sc_dev, 2256236880Sadrian "%s: dobaw=0, seqno=%d, window %d:%d\n", 2257236880Sadrian __func__, 2258236880Sadrian SEQNO(bf->bf_state.bfs_seqno), 2259236880Sadrian tap->txa_start, 2260236880Sadrian tap->txa_wnd); 2261236880Sadrian } 2262236880Sadrian 2263227364Sadrian if (bf->bf_state.bfs_addedbaw) 2264227364Sadrian device_printf(sc->sc_dev, 2265236872Sadrian "%s: re-added? tid=%d, seqno %d; window %d:%d; " 2266229949Sadrian "baw head=%d tail=%d\n", 2267236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2268229949Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2269229949Sadrian tid->baw_tail); 2270227364Sadrian 2271227364Sadrian /* 2272236880Sadrian * Verify that the given sequence number is not outside of the 2273236880Sadrian * BAW. Complain loudly if that's the case. 2274236880Sadrian */ 2275236880Sadrian if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2276236880Sadrian SEQNO(bf->bf_state.bfs_seqno))) { 2277236880Sadrian device_printf(sc->sc_dev, 2278236880Sadrian "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; " 2279236880Sadrian "baw head=%d tail=%d\n", 2280236880Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2281236880Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2282236880Sadrian tid->baw_tail); 2283236880Sadrian } 2284236880Sadrian 2285236880Sadrian /* 2286227364Sadrian * ni->ni_txseqs[] is the currently allocated seqno. 2287227364Sadrian * the txa state contains the current baw start. 2288227364Sadrian */ 2289227364Sadrian index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno)); 2290227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2291227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2292236872Sadrian "%s: tid=%d, seqno %d; window %d:%d; index=%d cindex=%d " 2293229949Sadrian "baw head=%d tail=%d\n", 2294236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2295229949Sadrian tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head, 2296229949Sadrian tid->baw_tail); 2297227364Sadrian 2298227364Sadrian 2299227364Sadrian#if 0 2300227364Sadrian assert(tid->tx_buf[cindex] == NULL); 2301227364Sadrian#endif 2302227364Sadrian if (tid->tx_buf[cindex] != NULL) { 2303227364Sadrian device_printf(sc->sc_dev, 2304227364Sadrian "%s: ba packet dup (index=%d, cindex=%d, " 2305227364Sadrian "head=%d, tail=%d)\n", 2306227364Sadrian __func__, index, cindex, tid->baw_head, tid->baw_tail); 2307227364Sadrian device_printf(sc->sc_dev, 2308227364Sadrian "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n", 2309227364Sadrian __func__, 2310227364Sadrian tid->tx_buf[cindex], 2311227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno), 2312227364Sadrian bf, 2313227364Sadrian SEQNO(bf->bf_state.bfs_seqno) 2314227364Sadrian ); 2315227364Sadrian } 2316227364Sadrian tid->tx_buf[cindex] = bf; 2317227364Sadrian 2318229949Sadrian if (index >= ((tid->baw_tail - tid->baw_head) & 2319229949Sadrian (ATH_TID_MAX_BUFS - 1))) { 2320227364Sadrian tid->baw_tail = cindex; 2321227364Sadrian INCR(tid->baw_tail, ATH_TID_MAX_BUFS); 2322227364Sadrian } 2323227364Sadrian} 2324227364Sadrian 2325227364Sadrian/* 2326227398Sadrian * Flip the BAW buffer entry over from the existing one to the new one. 2327227398Sadrian * 2328227398Sadrian * When software retransmitting a (sub-)frame, it is entirely possible that 2329227398Sadrian * the frame ath_buf is marked as BUSY and can't be immediately reused. 2330227398Sadrian * In that instance the buffer is cloned and the new buffer is used for 2331227398Sadrian * retransmit. We thus need to update the ath_buf slot in the BAW buf 2332227398Sadrian * tracking array to maintain consistency. 2333227398Sadrian */ 2334227398Sadrianstatic void 2335227398Sadrianath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an, 2336227398Sadrian struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf) 2337227398Sadrian{ 2338227398Sadrian int index, cindex; 2339227398Sadrian struct ieee80211_tx_ampdu *tap; 2340227398Sadrian int seqno = SEQNO(old_bf->bf_state.bfs_seqno); 2341227398Sadrian 2342227398Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2343236873Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2344227398Sadrian 2345227398Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2346227398Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2347227398Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2348227398Sadrian 2349227398Sadrian /* 2350227398Sadrian * Just warn for now; if it happens then we should find out 2351227398Sadrian * about it. It's highly likely the aggregation session will 2352227398Sadrian * soon hang. 2353227398Sadrian */ 2354227398Sadrian if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) { 2355227398Sadrian device_printf(sc->sc_dev, "%s: retransmitted buffer" 2356227398Sadrian " has mismatching seqno's, BA session may hang.\n", 2357227398Sadrian __func__); 2358227398Sadrian device_printf(sc->sc_dev, "%s: old seqno=%d, new_seqno=%d\n", 2359227398Sadrian __func__, 2360227398Sadrian old_bf->bf_state.bfs_seqno, 2361227398Sadrian new_bf->bf_state.bfs_seqno); 2362227398Sadrian } 2363227398Sadrian 2364227398Sadrian if (tid->tx_buf[cindex] != old_bf) { 2365227398Sadrian device_printf(sc->sc_dev, "%s: ath_buf pointer incorrect; " 2366227398Sadrian " has m BA session may hang.\n", 2367227398Sadrian __func__); 2368227398Sadrian device_printf(sc->sc_dev, "%s: old bf=%p, new bf=%p\n", 2369227398Sadrian __func__, 2370227398Sadrian old_bf, new_bf); 2371227398Sadrian } 2372227398Sadrian 2373227398Sadrian tid->tx_buf[cindex] = new_bf; 2374227398Sadrian} 2375227398Sadrian 2376227398Sadrian/* 2377227364Sadrian * seq_start - left edge of BAW 2378227364Sadrian * seq_next - current/next sequence number to allocate 2379227364Sadrian * 2380227364Sadrian * Since the BAW status may be modified by both the ath task and 2381227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2382227364Sadrian */ 2383227364Sadrianstatic void 2384227364Sadrianath_tx_update_baw(struct ath_softc *sc, struct ath_node *an, 2385227364Sadrian struct ath_tid *tid, const struct ath_buf *bf) 2386227364Sadrian{ 2387227364Sadrian int index, cindex; 2388227364Sadrian struct ieee80211_tx_ampdu *tap; 2389227364Sadrian int seqno = SEQNO(bf->bf_state.bfs_seqno); 2390227364Sadrian 2391227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2392236879Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2393227364Sadrian 2394227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2395227364Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2396227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2397227364Sadrian 2398227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2399236872Sadrian "%s: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, " 2400229949Sadrian "baw head=%d, tail=%d\n", 2401236872Sadrian __func__, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index, 2402227364Sadrian cindex, tid->baw_head, tid->baw_tail); 2403227364Sadrian 2404227364Sadrian /* 2405227364Sadrian * If this occurs then we have a big problem - something else 2406227364Sadrian * has slid tap->txa_start along without updating the BAW 2407227364Sadrian * tracking start/end pointers. Thus the TX BAW state is now 2408227364Sadrian * completely busted. 2409227364Sadrian * 2410227364Sadrian * But for now, since I haven't yet fixed TDMA and buffer cloning, 2411227364Sadrian * it's quite possible that a cloned buffer is making its way 2412227364Sadrian * here and causing it to fire off. Disable TDMA for now. 2413227364Sadrian */ 2414227364Sadrian if (tid->tx_buf[cindex] != bf) { 2415227364Sadrian device_printf(sc->sc_dev, 2416227364Sadrian "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n", 2417227364Sadrian __func__, 2418227364Sadrian bf, SEQNO(bf->bf_state.bfs_seqno), 2419227364Sadrian tid->tx_buf[cindex], 2420227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno)); 2421227364Sadrian } 2422227364Sadrian 2423227364Sadrian tid->tx_buf[cindex] = NULL; 2424227364Sadrian 2425229949Sadrian while (tid->baw_head != tid->baw_tail && 2426229949Sadrian !tid->tx_buf[tid->baw_head]) { 2427227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 2428227364Sadrian INCR(tid->baw_head, ATH_TID_MAX_BUFS); 2429227364Sadrian } 2430229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2431229949Sadrian "%s: baw is now %d:%d, baw head=%d\n", 2432227364Sadrian __func__, tap->txa_start, tap->txa_wnd, tid->baw_head); 2433227364Sadrian} 2434227364Sadrian 2435227364Sadrian/* 2436227364Sadrian * Mark the current node/TID as ready to TX. 2437227364Sadrian * 2438227364Sadrian * This is done to make it easy for the software scheduler to 2439227364Sadrian * find which nodes have data to send. 2440227364Sadrian * 2441227364Sadrian * The TXQ lock must be held. 2442227364Sadrian */ 2443227364Sadrianstatic void 2444227364Sadrianath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid) 2445227364Sadrian{ 2446227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2447227364Sadrian 2448227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2449227364Sadrian 2450227364Sadrian if (tid->paused) 2451227364Sadrian return; /* paused, can't schedule yet */ 2452227364Sadrian 2453227364Sadrian if (tid->sched) 2454227364Sadrian return; /* already scheduled */ 2455227364Sadrian 2456227364Sadrian tid->sched = 1; 2457227364Sadrian 2458227364Sadrian TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem); 2459227364Sadrian} 2460227364Sadrian 2461227364Sadrian/* 2462227364Sadrian * Mark the current node as no longer needing to be polled for 2463227364Sadrian * TX packets. 2464227364Sadrian * 2465227364Sadrian * The TXQ lock must be held. 2466227364Sadrian */ 2467227364Sadrianstatic void 2468227364Sadrianath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid) 2469227364Sadrian{ 2470227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2471227364Sadrian 2472227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2473227364Sadrian 2474227364Sadrian if (tid->sched == 0) 2475227364Sadrian return; 2476227364Sadrian 2477227364Sadrian tid->sched = 0; 2478227364Sadrian TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem); 2479227364Sadrian} 2480227364Sadrian 2481227364Sadrian/* 2482240724Sadrian * Update the CLRDMASK bit in the ath_buf if it needs to be set. 2483240724Sadrian */ 2484240724Sadrianstatic void 2485240724Sadrianath_tx_update_clrdmask(struct ath_softc *sc, struct ath_tid *tid, 2486240724Sadrian struct ath_buf *bf) 2487240724Sadrian{ 2488240724Sadrian 2489240724Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2490240724Sadrian 2491240724Sadrian if (tid->clrdmask == 1) { 2492240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2493240724Sadrian tid->clrdmask = 0; 2494240724Sadrian } 2495240724Sadrian} 2496240724Sadrian 2497240724Sadrian/* 2498227364Sadrian * Assign a sequence number manually to the given frame. 2499227364Sadrian * 2500227364Sadrian * This should only be called for A-MPDU TX frames. 2501227364Sadrian */ 2502236872Sadrianstatic ieee80211_seq 2503227364Sadrianath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni, 2504227364Sadrian struct ath_buf *bf, struct mbuf *m0) 2505227364Sadrian{ 2506227364Sadrian struct ieee80211_frame *wh; 2507227364Sadrian int tid, pri; 2508227364Sadrian ieee80211_seq seqno; 2509227364Sadrian uint8_t subtype; 2510227364Sadrian 2511227364Sadrian /* TID lookup */ 2512227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2513227364Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 2514227364Sadrian tid = WME_AC_TO_TID(pri); 2515236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pri=%d, tid=%d, qos has seq=%d\n", 2516236872Sadrian __func__, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2517227364Sadrian 2518227364Sadrian /* XXX Is it a control frame? Ignore */ 2519227364Sadrian 2520227364Sadrian /* Does the packet require a sequence number? */ 2521227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 2522227364Sadrian return -1; 2523227364Sadrian 2524236880Sadrian ATH_TID_LOCK_ASSERT(sc, &(ATH_NODE(ni)->an_tid[tid])); 2525236880Sadrian 2526227364Sadrian /* 2527227364Sadrian * Is it a QOS NULL Data frame? Give it a sequence number from 2528227364Sadrian * the default TID (IEEE80211_NONQOS_TID.) 2529227364Sadrian * 2530227364Sadrian * The RX path of everything I've looked at doesn't include the NULL 2531227364Sadrian * data frame sequence number in the aggregation state updates, so 2532227364Sadrian * assigning it a sequence number there will cause a BAW hole on the 2533227364Sadrian * RX side. 2534227364Sadrian */ 2535227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2536227364Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) { 2537236880Sadrian /* XXX no locking for this TID? This is a bit of a problem. */ 2538227364Sadrian seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 2539227364Sadrian INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE); 2540227364Sadrian } else { 2541227364Sadrian /* Manually assign sequence number */ 2542227364Sadrian seqno = ni->ni_txseqs[tid]; 2543227364Sadrian INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE); 2544227364Sadrian } 2545227364Sadrian *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); 2546227364Sadrian M_SEQNO_SET(m0, seqno); 2547227364Sadrian 2548227364Sadrian /* Return so caller can do something with it if needed */ 2549236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: -> seqno=%d\n", __func__, seqno); 2550227364Sadrian return seqno; 2551227364Sadrian} 2552227364Sadrian 2553227364Sadrian/* 2554227364Sadrian * Attempt to direct dispatch an aggregate frame to hardware. 2555227364Sadrian * If the frame is out of BAW, queue. 2556227364Sadrian * Otherwise, schedule it as a single frame. 2557227364Sadrian */ 2558227364Sadrianstatic void 2559239051Sadrianath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an, 2560239051Sadrian struct ath_txq *txq, struct ath_buf *bf) 2561227364Sadrian{ 2562227364Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 2563239051Sadrian// struct ath_txq *txq = bf->bf_state.bfs_txq; 2564227364Sadrian struct ieee80211_tx_ampdu *tap; 2565227364Sadrian 2566239051Sadrian if (txq != bf->bf_state.bfs_txq) { 2567239051Sadrian device_printf(sc->sc_dev, "%s: txq %d != bfs_txq %d!\n", 2568239051Sadrian __func__, 2569239051Sadrian txq->axq_qnum, 2570239051Sadrian bf->bf_state.bfs_txq->axq_qnum); 2571239051Sadrian } 2572239051Sadrian 2573227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2574236873Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2575227364Sadrian 2576227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2577227364Sadrian 2578227364Sadrian /* paused? queue */ 2579227364Sadrian if (tid->paused) { 2580236876Sadrian ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 2581233480Sadrian /* XXX don't sched - we're paused! */ 2582227364Sadrian return; 2583227364Sadrian } 2584227364Sadrian 2585227364Sadrian /* outside baw? queue */ 2586227364Sadrian if (bf->bf_state.bfs_dobaw && 2587227364Sadrian (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2588227364Sadrian SEQNO(bf->bf_state.bfs_seqno)))) { 2589236878Sadrian ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 2590227364Sadrian ath_tx_tid_sched(sc, tid); 2591227364Sadrian return; 2592227364Sadrian } 2593227364Sadrian 2594240180Sadrian /* 2595240180Sadrian * This is a temporary check and should be removed once 2596240180Sadrian * all the relevant code paths have been fixed. 2597240180Sadrian * 2598240180Sadrian * During aggregate retries, it's possible that the head 2599240180Sadrian * frame will fail (which has the bfs_aggr and bfs_nframes 2600240180Sadrian * fields set for said aggregate) and will be retried as 2601240180Sadrian * a single frame. In this instance, the values should 2602240180Sadrian * be reset or the completion code will get upset with you. 2603240180Sadrian */ 2604240180Sadrian if (bf->bf_state.bfs_aggr != 0 || bf->bf_state.bfs_nframes > 1) { 2605240180Sadrian device_printf(sc->sc_dev, "%s: bfs_aggr=%d, bfs_nframes=%d\n", 2606240180Sadrian __func__, 2607240180Sadrian bf->bf_state.bfs_aggr, 2608240180Sadrian bf->bf_state.bfs_nframes); 2609240180Sadrian bf->bf_state.bfs_aggr = 0; 2610240180Sadrian bf->bf_state.bfs_nframes = 1; 2611240180Sadrian } 2612240180Sadrian 2613240724Sadrian /* Update CLRDMASK just before this frame is queued */ 2614240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 2615240724Sadrian 2616227364Sadrian /* Direct dispatch to hardware */ 2617227364Sadrian ath_tx_do_ratelookup(sc, bf); 2618233989Sadrian ath_tx_calc_duration(sc, bf); 2619233989Sadrian ath_tx_calc_protection(sc, bf); 2620233989Sadrian ath_tx_set_rtscts(sc, bf); 2621227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2622227364Sadrian ath_tx_setds(sc, bf); 2623227364Sadrian 2624227364Sadrian /* Statistics */ 2625227364Sadrian sc->sc_aggr_stats.aggr_low_hwq_single_pkt++; 2626227364Sadrian 2627227364Sadrian /* Track per-TID hardware queue depth correctly */ 2628227364Sadrian tid->hwq_depth++; 2629227364Sadrian 2630227364Sadrian /* Add to BAW */ 2631227364Sadrian if (bf->bf_state.bfs_dobaw) { 2632227364Sadrian ath_tx_addto_baw(sc, an, tid, bf); 2633227364Sadrian bf->bf_state.bfs_addedbaw = 1; 2634227364Sadrian } 2635227364Sadrian 2636227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 2637227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 2638227364Sadrian 2639227364Sadrian /* Hand off to hardware */ 2640227364Sadrian ath_tx_handoff(sc, txq, bf); 2641227364Sadrian} 2642227364Sadrian 2643227364Sadrian/* 2644227364Sadrian * Attempt to send the packet. 2645227364Sadrian * If the queue isn't busy, direct-dispatch. 2646227364Sadrian * If the queue is busy enough, queue the given packet on the 2647227364Sadrian * relevant software queue. 2648227364Sadrian */ 2649227364Sadrianvoid 2650227364Sadrianath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_txq *txq, 2651227364Sadrian struct ath_buf *bf) 2652227364Sadrian{ 2653227364Sadrian struct ath_node *an = ATH_NODE(ni); 2654227364Sadrian struct ieee80211_frame *wh; 2655227364Sadrian struct ath_tid *atid; 2656227364Sadrian int pri, tid; 2657227364Sadrian struct mbuf *m0 = bf->bf_m; 2658227364Sadrian 2659236880Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2660236880Sadrian 2661227364Sadrian /* Fetch the TID - non-QoS frames get assigned to TID 16 */ 2662227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2663227364Sadrian pri = ath_tx_getac(sc, m0); 2664227364Sadrian tid = ath_tx_gettid(sc, m0); 2665227364Sadrian atid = &an->an_tid[tid]; 2666227364Sadrian 2667236873Sadrian ATH_TID_LOCK_ASSERT(sc, atid); 2668236873Sadrian 2669236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d\n", 2670236872Sadrian __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2671227364Sadrian 2672227364Sadrian /* Set local packet state, used to queue packets to hardware */ 2673239051Sadrian /* XXX potentially duplicate info, re-check */ 2674239051Sadrian /* XXX remember, txq must be the hardware queue, not the av_mcastq */ 2675227364Sadrian bf->bf_state.bfs_tid = tid; 2676227364Sadrian bf->bf_state.bfs_txq = txq; 2677227364Sadrian bf->bf_state.bfs_pri = pri; 2678227364Sadrian 2679227364Sadrian /* 2680227364Sadrian * If the hardware queue isn't busy, queue it directly. 2681227364Sadrian * If the hardware queue is busy, queue it. 2682227364Sadrian * If the TID is paused or the traffic it outside BAW, software 2683227364Sadrian * queue it. 2684227364Sadrian */ 2685227364Sadrian if (atid->paused) { 2686227364Sadrian /* TID is paused, queue */ 2687236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: paused\n", __func__); 2688227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2689227364Sadrian } else if (ath_tx_ampdu_pending(sc, an, tid)) { 2690227364Sadrian /* AMPDU pending; queue */ 2691236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pending\n", __func__); 2692227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2693227364Sadrian /* XXX sched? */ 2694227364Sadrian } else if (ath_tx_ampdu_running(sc, an, tid)) { 2695227364Sadrian /* AMPDU running, attempt direct dispatch if possible */ 2696236877Sadrian 2697236877Sadrian /* 2698236877Sadrian * Always queue the frame to the tail of the list. 2699236877Sadrian */ 2700236877Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2701236877Sadrian 2702236877Sadrian /* 2703236877Sadrian * If the hardware queue isn't busy, direct dispatch 2704236877Sadrian * the head frame in the list. Don't schedule the 2705236877Sadrian * TID - let it build some more frames first? 2706236877Sadrian * 2707236877Sadrian * Otherwise, schedule the TID. 2708236877Sadrian */ 2709229949Sadrian if (txq->axq_depth < sc->sc_hwq_limit) { 2710236877Sadrian bf = TAILQ_FIRST(&atid->axq_q); 2711236877Sadrian ATH_TXQ_REMOVE(atid, bf, bf_list); 2712240180Sadrian 2713240180Sadrian /* 2714240180Sadrian * Ensure it's definitely treated as a non-AMPDU 2715240180Sadrian * frame - this information may have been left 2716240180Sadrian * over from a previous attempt. 2717240180Sadrian */ 2718240180Sadrian bf->bf_state.bfs_aggr = 0; 2719240180Sadrian bf->bf_state.bfs_nframes = 1; 2720240180Sadrian 2721240180Sadrian /* Queue to the hardware */ 2722239051Sadrian ath_tx_xmit_aggr(sc, an, txq, bf); 2723233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2724236872Sadrian "%s: xmit_aggr\n", 2725236872Sadrian __func__); 2726229949Sadrian } else { 2727229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2728236872Sadrian "%s: ampdu; swq'ing\n", 2729236872Sadrian __func__); 2730227364Sadrian ath_tx_tid_sched(sc, atid); 2731227364Sadrian } 2732227364Sadrian } else if (txq->axq_depth < sc->sc_hwq_limit) { 2733227364Sadrian /* AMPDU not running, attempt direct dispatch */ 2734236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: xmit_normal\n", __func__); 2735240724Sadrian ath_tx_update_clrdmask(sc, atid, bf); 2736227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 2737227364Sadrian } else { 2738227364Sadrian /* Busy; queue */ 2739236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: swq'ing\n", __func__); 2740227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2741227364Sadrian ath_tx_tid_sched(sc, atid); 2742227364Sadrian } 2743227364Sadrian} 2744227364Sadrian 2745227364Sadrian/* 2746227364Sadrian * Configure the per-TID node state. 2747227364Sadrian * 2748227364Sadrian * This likely belongs in if_ath_node.c but I can't think of anywhere 2749227364Sadrian * else to put it just yet. 2750227364Sadrian * 2751227364Sadrian * This sets up the SLISTs and the mutex as appropriate. 2752227364Sadrian */ 2753227364Sadrianvoid 2754227364Sadrianath_tx_tid_init(struct ath_softc *sc, struct ath_node *an) 2755227364Sadrian{ 2756227364Sadrian int i, j; 2757227364Sadrian struct ath_tid *atid; 2758227364Sadrian 2759227364Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2760227364Sadrian atid = &an->an_tid[i]; 2761240639Sadrian 2762240639Sadrian /* XXX now with this bzer(), is the field 0'ing needed? */ 2763240639Sadrian bzero(atid, sizeof(*atid)); 2764240639Sadrian 2765227364Sadrian TAILQ_INIT(&atid->axq_q); 2766240639Sadrian TAILQ_INIT(&atid->filtq.axq_q); 2767227364Sadrian atid->tid = i; 2768227364Sadrian atid->an = an; 2769227364Sadrian for (j = 0; j < ATH_TID_MAX_BUFS; j++) 2770227364Sadrian atid->tx_buf[j] = NULL; 2771227364Sadrian atid->baw_head = atid->baw_tail = 0; 2772227364Sadrian atid->paused = 0; 2773227364Sadrian atid->sched = 0; 2774227364Sadrian atid->hwq_depth = 0; 2775227364Sadrian atid->cleanup_inprogress = 0; 2776240639Sadrian atid->clrdmask = 1; /* Always start by setting this bit */ 2777227364Sadrian if (i == IEEE80211_NONQOS_TID) 2778227364Sadrian atid->ac = WME_AC_BE; 2779227364Sadrian else 2780227364Sadrian atid->ac = TID_TO_WME_AC(i); 2781227364Sadrian } 2782227364Sadrian} 2783227364Sadrian 2784227364Sadrian/* 2785227364Sadrian * Pause the current TID. This stops packets from being transmitted 2786227364Sadrian * on it. 2787227364Sadrian * 2788227364Sadrian * Since this is also called from upper layers as well as the driver, 2789227364Sadrian * it will get the TID lock. 2790227364Sadrian */ 2791227364Sadrianstatic void 2792227364Sadrianath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid) 2793227364Sadrian{ 2794233908Sadrian 2795233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2796227364Sadrian tid->paused++; 2797227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n", 2798227364Sadrian __func__, tid->paused); 2799227364Sadrian} 2800227364Sadrian 2801227364Sadrian/* 2802227364Sadrian * Unpause the current TID, and schedule it if needed. 2803227364Sadrian */ 2804227364Sadrianstatic void 2805227364Sadrianath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid) 2806227364Sadrian{ 2807227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2808227364Sadrian 2809227364Sadrian tid->paused--; 2810227364Sadrian 2811227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n", 2812227364Sadrian __func__, tid->paused); 2813227364Sadrian 2814227364Sadrian if (tid->paused || tid->axq_depth == 0) { 2815227364Sadrian return; 2816227364Sadrian } 2817227364Sadrian 2818240639Sadrian /* XXX isfiltered shouldn't ever be 0 at this point */ 2819240639Sadrian if (tid->isfiltered == 1) { 2820240639Sadrian device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 2821240639Sadrian return; 2822240639Sadrian } 2823240639Sadrian 2824240724Sadrian /* 2825240724Sadrian * Override the clrdmask configuration for the next frame, 2826240724Sadrian * just to get the ball rolling. 2827240724Sadrian */ 2828240724Sadrian tid->clrdmask = 1; 2829240724Sadrian 2830227364Sadrian ath_tx_tid_sched(sc, tid); 2831227364Sadrian /* Punt some frames to the hardware if needed */ 2832233673Sadrian //ath_txq_sched(sc, sc->sc_ac2q[tid->ac]); 2833233673Sadrian taskqueue_enqueue(sc->sc_tq, &sc->sc_txqtask); 2834227364Sadrian} 2835227364Sadrian 2836227364Sadrian/* 2837240639Sadrian * Add the given ath_buf to the TID filtered frame list. 2838240639Sadrian * This requires the TID be filtered. 2839240639Sadrian */ 2840240639Sadrianstatic void 2841240639Sadrianath_tx_tid_filt_addbuf(struct ath_softc *sc, struct ath_tid *tid, 2842240639Sadrian struct ath_buf *bf) 2843240639Sadrian{ 2844240639Sadrian 2845240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2846240639Sadrian if (! tid->isfiltered) 2847240639Sadrian device_printf(sc->sc_dev, "%s: not filtered?!\n", __func__); 2848240639Sadrian 2849240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: bf=%p\n", __func__, bf); 2850240639Sadrian 2851240639Sadrian /* Set the retry bit and bump the retry counter */ 2852240639Sadrian ath_tx_set_retry(sc, bf); 2853240639Sadrian sc->sc_stats.ast_tx_swfiltered++; 2854240639Sadrian 2855240639Sadrian ATH_TXQ_INSERT_TAIL(&tid->filtq, bf, bf_list); 2856240639Sadrian} 2857240639Sadrian 2858240639Sadrian/* 2859240639Sadrian * Handle a completed filtered frame from the given TID. 2860240639Sadrian * This just enables/pauses the filtered frame state if required 2861240639Sadrian * and appends the filtered frame to the filtered queue. 2862240639Sadrian */ 2863240639Sadrianstatic void 2864240639Sadrianath_tx_tid_filt_comp_buf(struct ath_softc *sc, struct ath_tid *tid, 2865240639Sadrian struct ath_buf *bf) 2866240639Sadrian{ 2867240639Sadrian 2868240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2869240639Sadrian 2870240639Sadrian if (! tid->isfiltered) { 2871240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: filter transition\n", 2872240639Sadrian __func__); 2873240639Sadrian tid->isfiltered = 1; 2874240639Sadrian ath_tx_tid_pause(sc, tid); 2875240639Sadrian } 2876240639Sadrian 2877240639Sadrian /* Add the frame to the filter queue */ 2878240639Sadrian ath_tx_tid_filt_addbuf(sc, tid, bf); 2879240639Sadrian} 2880240639Sadrian 2881240639Sadrian/* 2882240639Sadrian * Complete the filtered frame TX completion. 2883240639Sadrian * 2884240639Sadrian * If there are no more frames in the hardware queue, unpause/unfilter 2885240639Sadrian * the TID if applicable. Otherwise we will wait for a node PS transition 2886240639Sadrian * to unfilter. 2887240639Sadrian */ 2888240639Sadrianstatic void 2889240639Sadrianath_tx_tid_filt_comp_complete(struct ath_softc *sc, struct ath_tid *tid) 2890240639Sadrian{ 2891240639Sadrian struct ath_buf *bf; 2892240639Sadrian 2893240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2894240639Sadrian 2895240639Sadrian if (tid->hwq_depth != 0) 2896240639Sadrian return; 2897240639Sadrian 2898240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: hwq=0, transition back\n", 2899240639Sadrian __func__); 2900240639Sadrian tid->isfiltered = 0; 2901240639Sadrian tid->clrdmask = 1; 2902240639Sadrian 2903240639Sadrian /* XXX this is really quite inefficient */ 2904240639Sadrian while ((bf = TAILQ_LAST(&tid->filtq.axq_q, ath_bufhead_s)) != NULL) { 2905240639Sadrian ATH_TXQ_REMOVE(&tid->filtq, bf, bf_list); 2906240639Sadrian ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 2907240639Sadrian } 2908240639Sadrian 2909240639Sadrian ath_tx_tid_resume(sc, tid); 2910240639Sadrian} 2911240639Sadrian 2912240639Sadrian/* 2913240639Sadrian * Called when a single (aggregate or otherwise) frame is completed. 2914240639Sadrian * 2915240639Sadrian * Returns 1 if the buffer could be added to the filtered list 2916240639Sadrian * (cloned or otherwise), 0 if the buffer couldn't be added to the 2917240639Sadrian * filtered list (failed clone; expired retry) and the caller should 2918240639Sadrian * free it and handle it like a failure (eg by sending a BAR.) 2919240639Sadrian */ 2920240639Sadrianstatic int 2921240639Sadrianath_tx_tid_filt_comp_single(struct ath_softc *sc, struct ath_tid *tid, 2922240639Sadrian struct ath_buf *bf) 2923240639Sadrian{ 2924240639Sadrian struct ath_buf *nbf; 2925240639Sadrian int retval; 2926240639Sadrian 2927240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2928240639Sadrian 2929240639Sadrian /* 2930240639Sadrian * Don't allow a filtered frame to live forever. 2931240639Sadrian */ 2932240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 2933240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 2934240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 2935240639Sadrian __func__, 2936240639Sadrian bf, 2937240639Sadrian bf->bf_state.bfs_seqno); 2938240639Sadrian return (0); 2939240639Sadrian } 2940240639Sadrian 2941240639Sadrian /* 2942240639Sadrian * A busy buffer can't be added to the retry list. 2943240639Sadrian * It needs to be cloned. 2944240639Sadrian */ 2945240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 2946240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 2947240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 2948240639Sadrian "%s: busy buffer clone: %p -> %p\n", 2949240639Sadrian __func__, bf, nbf); 2950240639Sadrian } else { 2951240639Sadrian nbf = bf; 2952240639Sadrian } 2953240639Sadrian 2954240639Sadrian if (nbf == NULL) { 2955240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 2956240639Sadrian "%s: busy buffer couldn't be cloned (%p)!\n", 2957240639Sadrian __func__, bf); 2958240639Sadrian retval = 1; 2959240639Sadrian } else { 2960240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 2961240639Sadrian retval = 0; 2962240639Sadrian } 2963240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 2964240639Sadrian 2965240639Sadrian return (retval); 2966240639Sadrian} 2967240639Sadrian 2968240639Sadrianstatic void 2969240639Sadrianath_tx_tid_filt_comp_aggr(struct ath_softc *sc, struct ath_tid *tid, 2970240639Sadrian struct ath_buf *bf_first, ath_bufhead *bf_q) 2971240639Sadrian{ 2972240639Sadrian struct ath_buf *bf, *bf_next, *nbf; 2973240639Sadrian 2974240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 2975240639Sadrian 2976240639Sadrian bf = bf_first; 2977240639Sadrian while (bf) { 2978240639Sadrian bf_next = bf->bf_next; 2979240639Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 2980240639Sadrian 2981240639Sadrian /* 2982240639Sadrian * Don't allow a filtered frame to live forever. 2983240639Sadrian */ 2984240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 2985240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 2986240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 2987240639Sadrian __func__, 2988240639Sadrian bf, 2989240639Sadrian bf->bf_state.bfs_seqno); 2990240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 2991240639Sadrian goto next; 2992240639Sadrian } 2993240639Sadrian 2994240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 2995240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 2996240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 2997240639Sadrian "%s: busy buffer cloned: %p -> %p", 2998240639Sadrian __func__, bf, nbf); 2999240639Sadrian } else { 3000240639Sadrian nbf = bf; 3001240639Sadrian } 3002240639Sadrian 3003240639Sadrian /* 3004240639Sadrian * If the buffer couldn't be cloned, add it to bf_q; 3005240639Sadrian * the caller will free the buffer(s) as required. 3006240639Sadrian */ 3007240639Sadrian if (nbf == NULL) { 3008240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3009240639Sadrian "%s: buffer couldn't be cloned! (%p)\n", 3010240639Sadrian __func__, bf); 3011240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3012240639Sadrian } else { 3013240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3014240639Sadrian } 3015240639Sadriannext: 3016240639Sadrian bf = bf_next; 3017240639Sadrian } 3018240639Sadrian 3019240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 3020240639Sadrian} 3021240639Sadrian 3022240639Sadrian/* 3023233908Sadrian * Suspend the queue because we need to TX a BAR. 3024233908Sadrian */ 3025233908Sadrianstatic void 3026233908Sadrianath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid) 3027233908Sadrian{ 3028233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 3029233908Sadrian 3030235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3031235676Sadrian "%s: tid=%p, bar_wait=%d, bar_tx=%d, called\n", 3032233908Sadrian __func__, 3033235676Sadrian tid, 3034235676Sadrian tid->bar_wait, 3035235676Sadrian tid->bar_tx); 3036233908Sadrian 3037233908Sadrian /* We shouldn't be called when bar_tx is 1 */ 3038233908Sadrian if (tid->bar_tx) { 3039233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx is 1?!\n", 3040233908Sadrian __func__); 3041233908Sadrian } 3042233908Sadrian 3043233908Sadrian /* If we've already been called, just be patient. */ 3044233908Sadrian if (tid->bar_wait) 3045233908Sadrian return; 3046233908Sadrian 3047233908Sadrian /* Wait! */ 3048233908Sadrian tid->bar_wait = 1; 3049233908Sadrian 3050233908Sadrian /* Only one pause, no matter how many frames fail */ 3051233908Sadrian ath_tx_tid_pause(sc, tid); 3052233908Sadrian} 3053233908Sadrian 3054233908Sadrian/* 3055233908Sadrian * We've finished with BAR handling - either we succeeded or 3056233908Sadrian * failed. Either way, unsuspend TX. 3057233908Sadrian */ 3058233908Sadrianstatic void 3059233908Sadrianath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid) 3060233908Sadrian{ 3061233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 3062233908Sadrian 3063235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3064233908Sadrian "%s: tid=%p, called\n", 3065233908Sadrian __func__, 3066233908Sadrian tid); 3067233908Sadrian 3068233908Sadrian if (tid->bar_tx == 0 || tid->bar_wait == 0) { 3069233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx=%d, bar_wait=%d: ?\n", 3070233908Sadrian __func__, tid->bar_tx, tid->bar_wait); 3071233908Sadrian } 3072233908Sadrian 3073233908Sadrian tid->bar_tx = tid->bar_wait = 0; 3074233908Sadrian ath_tx_tid_resume(sc, tid); 3075233908Sadrian} 3076233908Sadrian 3077233908Sadrian/* 3078233908Sadrian * Return whether we're ready to TX a BAR frame. 3079233908Sadrian * 3080233908Sadrian * Requires the TID lock be held. 3081233908Sadrian */ 3082233908Sadrianstatic int 3083233908Sadrianath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid) 3084233908Sadrian{ 3085233908Sadrian 3086233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 3087233908Sadrian 3088233908Sadrian if (tid->bar_wait == 0 || tid->hwq_depth > 0) 3089233908Sadrian return (0); 3090233908Sadrian 3091235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, "%s: tid=%p (%d), bar ready\n", 3092235491Sadrian __func__, tid, tid->tid); 3093235491Sadrian 3094233908Sadrian return (1); 3095233908Sadrian} 3096233908Sadrian 3097233908Sadrian/* 3098233908Sadrian * Check whether the current TID is ready to have a BAR 3099233908Sadrian * TXed and if so, do the TX. 3100233908Sadrian * 3101233908Sadrian * Since the TID/TXQ lock can't be held during a call to 3102233908Sadrian * ieee80211_send_bar(), we have to do the dirty thing of unlocking it, 3103233908Sadrian * sending the BAR and locking it again. 3104233908Sadrian * 3105233908Sadrian * Eventually, the code to send the BAR should be broken out 3106233908Sadrian * from this routine so the lock doesn't have to be reacquired 3107233908Sadrian * just to be immediately dropped by the caller. 3108233908Sadrian */ 3109233908Sadrianstatic void 3110233908Sadrianath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid) 3111233908Sadrian{ 3112233908Sadrian struct ieee80211_tx_ampdu *tap; 3113233908Sadrian 3114233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 3115233908Sadrian 3116235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3117233908Sadrian "%s: tid=%p, called\n", 3118233908Sadrian __func__, 3119233908Sadrian tid); 3120233908Sadrian 3121233908Sadrian tap = ath_tx_get_tx_tid(tid->an, tid->tid); 3122233908Sadrian 3123233908Sadrian /* 3124233908Sadrian * This is an error condition! 3125233908Sadrian */ 3126233908Sadrian if (tid->bar_wait == 0 || tid->bar_tx == 1) { 3127233908Sadrian device_printf(sc->sc_dev, 3128233908Sadrian "%s: tid=%p, bar_tx=%d, bar_wait=%d: ?\n", 3129233908Sadrian __func__, 3130233908Sadrian tid, 3131233908Sadrian tid->bar_tx, 3132233908Sadrian tid->bar_wait); 3133233908Sadrian return; 3134233908Sadrian } 3135233908Sadrian 3136233908Sadrian /* Don't do anything if we still have pending frames */ 3137233908Sadrian if (tid->hwq_depth > 0) { 3138235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3139233908Sadrian "%s: tid=%p, hwq_depth=%d, waiting\n", 3140233908Sadrian __func__, 3141233908Sadrian tid, 3142233908Sadrian tid->hwq_depth); 3143233908Sadrian return; 3144233908Sadrian } 3145233908Sadrian 3146233908Sadrian /* We're now about to TX */ 3147233908Sadrian tid->bar_tx = 1; 3148233908Sadrian 3149233908Sadrian /* 3150240724Sadrian * Override the clrdmask configuration for the next frame, 3151240724Sadrian * just to get the ball rolling. 3152240724Sadrian */ 3153240724Sadrian tid->clrdmask = 1; 3154240724Sadrian 3155240724Sadrian /* 3156233908Sadrian * Calculate new BAW left edge, now that all frames have either 3157233908Sadrian * succeeded or failed. 3158233908Sadrian * 3159233908Sadrian * XXX verify this is _actually_ the valid value to begin at! 3160233908Sadrian */ 3161235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3162233908Sadrian "%s: tid=%p, new BAW left edge=%d\n", 3163233908Sadrian __func__, 3164233908Sadrian tid, 3165233908Sadrian tap->txa_start); 3166233908Sadrian 3167233908Sadrian /* Try sending the BAR frame */ 3168233908Sadrian /* We can't hold the lock here! */ 3169233908Sadrian 3170233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 3171233908Sadrian if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) { 3172233908Sadrian /* Success? Now we wait for notification that it's done */ 3173233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 3174233908Sadrian return; 3175233908Sadrian } 3176233908Sadrian 3177233908Sadrian /* Failure? For now, warn loudly and continue */ 3178233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 3179233908Sadrian device_printf(sc->sc_dev, "%s: tid=%p, failed to TX BAR, continue!\n", 3180233908Sadrian __func__, tid); 3181233908Sadrian ath_tx_tid_bar_unsuspend(sc, tid); 3182233908Sadrian} 3183233908Sadrian 3184240639Sadrianstatic void 3185240639Sadrianath_tx_tid_drain_pkt(struct ath_softc *sc, struct ath_node *an, 3186240639Sadrian struct ath_tid *tid, ath_bufhead *bf_cq, struct ath_buf *bf) 3187240639Sadrian{ 3188233908Sadrian 3189240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 3190240639Sadrian 3191240639Sadrian /* 3192240639Sadrian * If the current TID is running AMPDU, update 3193240639Sadrian * the BAW. 3194240639Sadrian */ 3195240639Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid) && 3196240639Sadrian bf->bf_state.bfs_dobaw) { 3197240639Sadrian /* 3198240639Sadrian * Only remove the frame from the BAW if it's 3199240639Sadrian * been transmitted at least once; this means 3200240639Sadrian * the frame was in the BAW to begin with. 3201240639Sadrian */ 3202240639Sadrian if (bf->bf_state.bfs_retries > 0) { 3203240639Sadrian ath_tx_update_baw(sc, an, tid, bf); 3204240639Sadrian bf->bf_state.bfs_dobaw = 0; 3205240639Sadrian } 3206240639Sadrian /* 3207240639Sadrian * This has become a non-fatal error now 3208240639Sadrian */ 3209240639Sadrian if (! bf->bf_state.bfs_addedbaw) 3210240639Sadrian device_printf(sc->sc_dev, 3211240639Sadrian "%s: wasn't added: seqno %d\n", 3212240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3213240639Sadrian } 3214240639Sadrian TAILQ_INSERT_TAIL(bf_cq, bf, bf_list); 3215240639Sadrian} 3216240639Sadrian 3217240639Sadrianstatic void 3218240639Sadrianath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an, 3219240639Sadrian struct ath_tid *tid, struct ath_buf *bf) 3220240639Sadrian{ 3221240639Sadrian struct ieee80211_node *ni = &an->an_node; 3222240639Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 3223240639Sadrian struct ieee80211_tx_ampdu *tap; 3224240639Sadrian 3225240639Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3226240639Sadrian 3227240639Sadrian device_printf(sc->sc_dev, 3228240639Sadrian "%s: node %p: bf=%p: addbaw=%d, dobaw=%d, " 3229240639Sadrian "seqno=%d, retry=%d\n", 3230240639Sadrian __func__, ni, bf, 3231240639Sadrian bf->bf_state.bfs_addedbaw, 3232240639Sadrian bf->bf_state.bfs_dobaw, 3233240639Sadrian SEQNO(bf->bf_state.bfs_seqno), 3234240639Sadrian bf->bf_state.bfs_retries); 3235240639Sadrian device_printf(sc->sc_dev, 3236240724Sadrian "%s: node %p: bf=%p: txq axq_depth=%d, axq_aggr_depth=%d\n", 3237240724Sadrian __func__, ni, bf, 3238240724Sadrian txq->axq_depth, 3239240724Sadrian txq->axq_aggr_depth); 3240240724Sadrian 3241240724Sadrian device_printf(sc->sc_dev, 3242240639Sadrian "%s: node %p: bf=%p: tid txq_depth=%d hwq_depth=%d, bar_wait=%d, isfiltered=%d\n", 3243240639Sadrian __func__, ni, bf, 3244240639Sadrian tid->axq_depth, 3245240639Sadrian tid->hwq_depth, 3246240639Sadrian tid->bar_wait, 3247240639Sadrian tid->isfiltered); 3248240639Sadrian device_printf(sc->sc_dev, 3249240724Sadrian "%s: node %p: tid %d: " 3250240724Sadrian "sched=%d, paused=%d, " 3251240724Sadrian "incomp=%d, baw_head=%d, " 3252240639Sadrian "baw_tail=%d txa_start=%d, ni_txseqs=%d\n", 3253240724Sadrian __func__, ni, tid->tid, 3254240724Sadrian tid->sched, tid->paused, 3255240724Sadrian tid->incomp, tid->baw_head, 3256240639Sadrian tid->baw_tail, tap == NULL ? -1 : tap->txa_start, 3257240639Sadrian ni->ni_txseqs[tid->tid]); 3258240639Sadrian 3259240639Sadrian /* XXX Dump the frame, see what it is? */ 3260240639Sadrian ieee80211_dump_pkt(ni->ni_ic, 3261240639Sadrian mtod(bf->bf_m, const uint8_t *), 3262240639Sadrian bf->bf_m->m_len, 0, -1); 3263240639Sadrian} 3264240639Sadrian 3265233908Sadrian/* 3266227364Sadrian * Free any packets currently pending in the software TX queue. 3267227364Sadrian * 3268227364Sadrian * This will be called when a node is being deleted. 3269227364Sadrian * 3270227364Sadrian * It can also be called on an active node during an interface 3271227364Sadrian * reset or state transition. 3272227364Sadrian * 3273227364Sadrian * (From Linux/reference): 3274227364Sadrian * 3275227364Sadrian * TODO: For frame(s) that are in the retry state, we will reuse the 3276227364Sadrian * sequence number(s) without setting the retry bit. The 3277227364Sadrian * alternative is to give up on these and BAR the receiver's window 3278227364Sadrian * forward. 3279227364Sadrian */ 3280227364Sadrianstatic void 3281229949Sadrianath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an, 3282229949Sadrian struct ath_tid *tid, ath_bufhead *bf_cq) 3283227364Sadrian{ 3284227364Sadrian struct ath_buf *bf; 3285227364Sadrian struct ieee80211_tx_ampdu *tap; 3286227364Sadrian struct ieee80211_node *ni = &an->an_node; 3287240639Sadrian int t; 3288227364Sadrian 3289227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3290227364Sadrian 3291240639Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 3292227364Sadrian 3293227364Sadrian /* Walk the queue, free frames */ 3294240639Sadrian t = 0; 3295227364Sadrian for (;;) { 3296227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 3297227364Sadrian if (bf == NULL) { 3298227364Sadrian break; 3299227364Sadrian } 3300227364Sadrian 3301227364Sadrian if (t == 0) { 3302240639Sadrian ath_tx_tid_drain_print(sc, an, tid, bf); 3303240639Sadrian t = 1; 3304240639Sadrian } 3305229165Sadrian 3306240639Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 3307240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3308240639Sadrian } 3309229165Sadrian 3310240639Sadrian /* And now, drain the filtered frame queue */ 3311240639Sadrian t = 0; 3312240639Sadrian for (;;) { 3313240639Sadrian bf = TAILQ_FIRST(&tid->filtq.axq_q); 3314240639Sadrian if (bf == NULL) 3315240639Sadrian break; 3316240639Sadrian 3317240639Sadrian if (t == 0) { 3318240639Sadrian ath_tx_tid_drain_print(sc, an, tid, bf); 3319233897Sadrian t = 1; 3320227364Sadrian } 3321227364Sadrian 3322240639Sadrian ATH_TXQ_REMOVE(&tid->filtq, bf, bf_list); 3323240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3324227364Sadrian } 3325227364Sadrian 3326227364Sadrian /* 3327240724Sadrian * Override the clrdmask configuration for the next frame 3328240724Sadrian * in case there is some future transmission, just to get 3329240724Sadrian * the ball rolling. 3330240724Sadrian * 3331240724Sadrian * This won't hurt things if the TID is about to be freed. 3332240724Sadrian */ 3333240724Sadrian tid->clrdmask = 1; 3334240724Sadrian 3335240724Sadrian /* 3336227364Sadrian * Now that it's completed, grab the TID lock and update 3337227364Sadrian * the sequence number and BAW window. 3338227364Sadrian * Because sequence numbers have been assigned to frames 3339227364Sadrian * that haven't been sent yet, it's entirely possible 3340227364Sadrian * we'll be called with some pending frames that have not 3341227364Sadrian * been transmitted. 3342227364Sadrian * 3343227364Sadrian * The cleaner solution is to do the sequence number allocation 3344227364Sadrian * when the packet is first transmitted - and thus the "retries" 3345227364Sadrian * check above would be enough to update the BAW/seqno. 3346227364Sadrian */ 3347227364Sadrian 3348227364Sadrian /* But don't do it for non-QoS TIDs */ 3349227364Sadrian if (tap) { 3350227364Sadrian#if 0 3351227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3352227364Sadrian "%s: node %p: TID %d: sliding BAW left edge to %d\n", 3353227364Sadrian __func__, an, tid->tid, tap->txa_start); 3354227364Sadrian#endif 3355227364Sadrian ni->ni_txseqs[tid->tid] = tap->txa_start; 3356227364Sadrian tid->baw_tail = tid->baw_head; 3357227364Sadrian } 3358227364Sadrian} 3359227364Sadrian 3360227364Sadrian/* 3361227364Sadrian * Flush all software queued packets for the given node. 3362227364Sadrian * 3363227364Sadrian * This occurs when a completion handler frees the last buffer 3364227364Sadrian * for a node, and the node is thus freed. This causes the node 3365227364Sadrian * to be cleaned up, which ends up calling ath_tx_node_flush. 3366227364Sadrian */ 3367227364Sadrianvoid 3368227364Sadrianath_tx_node_flush(struct ath_softc *sc, struct ath_node *an) 3369227364Sadrian{ 3370227364Sadrian int tid; 3371227364Sadrian ath_bufhead bf_cq; 3372227364Sadrian struct ath_buf *bf; 3373227364Sadrian 3374227364Sadrian TAILQ_INIT(&bf_cq); 3375227364Sadrian 3376227364Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 3377227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3378227364Sadrian struct ath_txq *txq = sc->sc_ac2q[atid->ac]; 3379227364Sadrian 3380227364Sadrian /* Remove this tid from the list of active tids */ 3381227364Sadrian ATH_TXQ_LOCK(txq); 3382227364Sadrian ath_tx_tid_unsched(sc, atid); 3383227364Sadrian 3384227364Sadrian /* Free packets */ 3385227364Sadrian ath_tx_tid_drain(sc, an, atid, &bf_cq); 3386227364Sadrian ATH_TXQ_UNLOCK(txq); 3387227364Sadrian } 3388227364Sadrian 3389227364Sadrian /* Handle completed frames */ 3390227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3391227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3392227364Sadrian ath_tx_default_comp(sc, bf, 0); 3393227364Sadrian } 3394227364Sadrian} 3395227364Sadrian 3396227364Sadrian/* 3397227364Sadrian * Drain all the software TXQs currently with traffic queued. 3398227364Sadrian */ 3399227364Sadrianvoid 3400227364Sadrianath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq) 3401227364Sadrian{ 3402227364Sadrian struct ath_tid *tid; 3403227364Sadrian ath_bufhead bf_cq; 3404227364Sadrian struct ath_buf *bf; 3405227364Sadrian 3406227364Sadrian TAILQ_INIT(&bf_cq); 3407227364Sadrian ATH_TXQ_LOCK(txq); 3408227364Sadrian 3409227364Sadrian /* 3410227364Sadrian * Iterate over all active tids for the given txq, 3411227364Sadrian * flushing and unsched'ing them 3412227364Sadrian */ 3413227364Sadrian while (! TAILQ_EMPTY(&txq->axq_tidq)) { 3414227364Sadrian tid = TAILQ_FIRST(&txq->axq_tidq); 3415227364Sadrian ath_tx_tid_drain(sc, tid->an, tid, &bf_cq); 3416227364Sadrian ath_tx_tid_unsched(sc, tid); 3417227364Sadrian } 3418227364Sadrian 3419227364Sadrian ATH_TXQ_UNLOCK(txq); 3420227364Sadrian 3421227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3422227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3423227364Sadrian ath_tx_default_comp(sc, bf, 0); 3424227364Sadrian } 3425227364Sadrian} 3426227364Sadrian 3427227364Sadrian/* 3428227364Sadrian * Handle completion of non-aggregate session frames. 3429227364Sadrian */ 3430227364Sadrianvoid 3431227364Sadrianath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3432227364Sadrian{ 3433227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3434227364Sadrian struct ath_node *an = ATH_NODE(ni); 3435227364Sadrian int tid = bf->bf_state.bfs_tid; 3436227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3437227364Sadrian struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3438227364Sadrian 3439227364Sadrian /* The TID state is protected behind the TXQ lock */ 3440227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3441227364Sadrian 3442227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n", 3443227364Sadrian __func__, bf, fail, atid->hwq_depth - 1); 3444227364Sadrian 3445227364Sadrian atid->hwq_depth--; 3446240639Sadrian 3447240639Sadrian if (atid->isfiltered) 3448240639Sadrian device_printf(sc->sc_dev, "%s: isfiltered=1, normal_comp?\n", 3449240639Sadrian __func__); 3450240639Sadrian 3451227364Sadrian if (atid->hwq_depth < 0) 3452227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3453227364Sadrian __func__, atid->hwq_depth); 3454240639Sadrian 3455240639Sadrian /* 3456240639Sadrian * If the queue is filtered, potentially mark it as complete 3457240639Sadrian * and reschedule it as needed. 3458240639Sadrian * 3459240639Sadrian * This is required as there may be a subsequent TX descriptor 3460240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 3461240639Sadrian * that a filtered frame will be followed by a non-filtered 3462240639Sadrian * (complete or otherwise) frame. 3463240639Sadrian * 3464240639Sadrian * XXX should we do this before we complete the frame? 3465240639Sadrian */ 3466240639Sadrian if (atid->isfiltered) 3467240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 3468240639Sadrian 3469227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3470227364Sadrian 3471227364Sadrian /* 3472227364Sadrian * punt to rate control if we're not being cleaned up 3473227364Sadrian * during a hw queue drain and the frame wanted an ACK. 3474227364Sadrian */ 3475233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3476227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3477227364Sadrian ts, bf->bf_state.bfs_pktlen, 3478227364Sadrian 1, (ts->ts_status == 0) ? 0 : 1); 3479227364Sadrian 3480227364Sadrian ath_tx_default_comp(sc, bf, fail); 3481227364Sadrian} 3482227364Sadrian 3483227364Sadrian/* 3484227364Sadrian * Handle cleanup of aggregate session packets that aren't 3485227364Sadrian * an A-MPDU. 3486227364Sadrian * 3487227364Sadrian * There's no need to update the BAW here - the session is being 3488227364Sadrian * torn down. 3489227364Sadrian */ 3490227364Sadrianstatic void 3491227364Sadrianath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3492227364Sadrian{ 3493227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3494227364Sadrian struct ath_node *an = ATH_NODE(ni); 3495227364Sadrian int tid = bf->bf_state.bfs_tid; 3496227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3497227364Sadrian 3498227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n", 3499227364Sadrian __func__, tid, atid->incomp); 3500227364Sadrian 3501227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3502227364Sadrian atid->incomp--; 3503227364Sadrian if (atid->incomp == 0) { 3504227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3505227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3506227364Sadrian __func__, tid); 3507227364Sadrian atid->cleanup_inprogress = 0; 3508227364Sadrian ath_tx_tid_resume(sc, atid); 3509227364Sadrian } 3510227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3511227364Sadrian 3512227364Sadrian ath_tx_default_comp(sc, bf, 0); 3513227364Sadrian} 3514227364Sadrian 3515227364Sadrian/* 3516227364Sadrian * Performs transmit side cleanup when TID changes from aggregated to 3517227364Sadrian * unaggregated. 3518227364Sadrian * 3519227364Sadrian * - Discard all retry frames from the s/w queue. 3520227364Sadrian * - Fix the tx completion function for all buffers in s/w queue. 3521227364Sadrian * - Count the number of unacked frames, and let transmit completion 3522227364Sadrian * handle it later. 3523227364Sadrian * 3524227364Sadrian * The caller is responsible for pausing the TID. 3525227364Sadrian */ 3526227364Sadrianstatic void 3527235749Sadrianath_tx_tid_cleanup(struct ath_softc *sc, struct ath_node *an, int tid) 3528227364Sadrian{ 3529227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3530227364Sadrian struct ieee80211_tx_ampdu *tap; 3531227364Sadrian struct ath_buf *bf, *bf_next; 3532227364Sadrian ath_bufhead bf_cq; 3533227364Sadrian 3534235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 3535227364Sadrian "%s: TID %d: called\n", __func__, tid); 3536227364Sadrian 3537227364Sadrian TAILQ_INIT(&bf_cq); 3538227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3539227364Sadrian 3540227364Sadrian /* 3541240639Sadrian * Move the filtered frames to the TX queue, before 3542240639Sadrian * we run off and discard/process things. 3543240639Sadrian */ 3544240639Sadrian /* XXX this is really quite inefficient */ 3545240639Sadrian while ((bf = TAILQ_LAST(&atid->filtq.axq_q, ath_bufhead_s)) != NULL) { 3546240639Sadrian ATH_TXQ_REMOVE(&atid->filtq, bf, bf_list); 3547240639Sadrian ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3548240639Sadrian } 3549240639Sadrian 3550240639Sadrian /* 3551227364Sadrian * Update the frames in the software TX queue: 3552227364Sadrian * 3553227364Sadrian * + Discard retry frames in the queue 3554227364Sadrian * + Fix the completion function to be non-aggregate 3555227364Sadrian */ 3556227364Sadrian bf = TAILQ_FIRST(&atid->axq_q); 3557227364Sadrian while (bf) { 3558227364Sadrian if (bf->bf_state.bfs_isretried) { 3559227364Sadrian bf_next = TAILQ_NEXT(bf, bf_list); 3560227364Sadrian TAILQ_REMOVE(&atid->axq_q, bf, bf_list); 3561227364Sadrian atid->axq_depth--; 3562227364Sadrian if (bf->bf_state.bfs_dobaw) { 3563227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3564227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3565227364Sadrian device_printf(sc->sc_dev, 3566227364Sadrian "%s: wasn't added: seqno %d\n", 3567229949Sadrian __func__, 3568229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3569227364Sadrian } 3570227364Sadrian bf->bf_state.bfs_dobaw = 0; 3571227364Sadrian /* 3572227364Sadrian * Call the default completion handler with "fail" just 3573227364Sadrian * so upper levels are suitably notified about this. 3574227364Sadrian */ 3575227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3576227364Sadrian bf = bf_next; 3577227364Sadrian continue; 3578227364Sadrian } 3579227364Sadrian /* Give these the default completion handler */ 3580227364Sadrian bf->bf_comp = ath_tx_normal_comp; 3581227364Sadrian bf = TAILQ_NEXT(bf, bf_list); 3582227364Sadrian } 3583227364Sadrian 3584227364Sadrian /* The caller is required to pause the TID */ 3585227364Sadrian#if 0 3586227364Sadrian /* Pause the TID */ 3587227364Sadrian ath_tx_tid_pause(sc, atid); 3588227364Sadrian#endif 3589227364Sadrian 3590227364Sadrian /* 3591227364Sadrian * Calculate what hardware-queued frames exist based 3592227364Sadrian * on the current BAW size. Ie, what frames have been 3593227364Sadrian * added to the TX hardware queue for this TID but 3594227364Sadrian * not yet ACKed. 3595227364Sadrian */ 3596227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3597227364Sadrian /* Need the lock - fiddling with BAW */ 3598227364Sadrian while (atid->baw_head != atid->baw_tail) { 3599227364Sadrian if (atid->tx_buf[atid->baw_head]) { 3600227364Sadrian atid->incomp++; 3601227364Sadrian atid->cleanup_inprogress = 1; 3602227364Sadrian atid->tx_buf[atid->baw_head] = NULL; 3603227364Sadrian } 3604227364Sadrian INCR(atid->baw_head, ATH_TID_MAX_BUFS); 3605227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 3606227364Sadrian } 3607227364Sadrian 3608227364Sadrian /* 3609227364Sadrian * If cleanup is required, defer TID scheduling 3610227364Sadrian * until all the HW queued packets have been 3611227364Sadrian * sent. 3612227364Sadrian */ 3613227364Sadrian if (! atid->cleanup_inprogress) 3614227364Sadrian ath_tx_tid_resume(sc, atid); 3615227364Sadrian 3616227364Sadrian if (atid->cleanup_inprogress) 3617227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3618227364Sadrian "%s: TID %d: cleanup needed: %d packets\n", 3619227364Sadrian __func__, tid, atid->incomp); 3620227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3621227364Sadrian 3622227364Sadrian /* Handle completing frames and fail them */ 3623227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3624227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3625227364Sadrian ath_tx_default_comp(sc, bf, 1); 3626227364Sadrian } 3627227364Sadrian} 3628227364Sadrian 3629227364Sadrianstatic struct ath_buf * 3630227398Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 3631227398Sadrian struct ath_tid *tid, struct ath_buf *bf) 3632227364Sadrian{ 3633227364Sadrian struct ath_buf *nbf; 3634227364Sadrian int error; 3635227364Sadrian 3636227364Sadrian nbf = ath_buf_clone(sc, bf); 3637227364Sadrian 3638227364Sadrian#if 0 3639227364Sadrian device_printf(sc->sc_dev, "%s: ATH_BUF_BUSY; cloning\n", 3640227364Sadrian __func__); 3641227364Sadrian#endif 3642227364Sadrian 3643227364Sadrian if (nbf == NULL) { 3644227364Sadrian /* Failed to clone */ 3645227364Sadrian device_printf(sc->sc_dev, 3646227364Sadrian "%s: failed to clone a busy buffer\n", 3647227364Sadrian __func__); 3648227364Sadrian return NULL; 3649227364Sadrian } 3650227364Sadrian 3651227364Sadrian /* Setup the dma for the new buffer */ 3652227364Sadrian error = ath_tx_dmasetup(sc, nbf, nbf->bf_m); 3653227364Sadrian if (error != 0) { 3654227364Sadrian device_printf(sc->sc_dev, 3655227364Sadrian "%s: failed to setup dma for clone\n", 3656227364Sadrian __func__); 3657227364Sadrian /* 3658227364Sadrian * Put this at the head of the list, not tail; 3659227364Sadrian * that way it doesn't interfere with the 3660227364Sadrian * busy buffer logic (which uses the tail of 3661227364Sadrian * the list.) 3662227364Sadrian */ 3663227364Sadrian ATH_TXBUF_LOCK(sc); 3664236994Sadrian ath_returnbuf_head(sc, nbf); 3665227364Sadrian ATH_TXBUF_UNLOCK(sc); 3666227364Sadrian return NULL; 3667227364Sadrian } 3668227364Sadrian 3669227398Sadrian /* Update BAW if required, before we free the original buf */ 3670227398Sadrian if (bf->bf_state.bfs_dobaw) 3671227398Sadrian ath_tx_switch_baw_buf(sc, an, tid, bf, nbf); 3672227398Sadrian 3673227364Sadrian /* Free current buffer; return the older buffer */ 3674227364Sadrian bf->bf_m = NULL; 3675227364Sadrian bf->bf_node = NULL; 3676227364Sadrian ath_freebuf(sc, bf); 3677240639Sadrian 3678227364Sadrian return nbf; 3679227364Sadrian} 3680227364Sadrian 3681227364Sadrian/* 3682227364Sadrian * Handle retrying an unaggregate frame in an aggregate 3683227364Sadrian * session. 3684227364Sadrian * 3685227364Sadrian * If too many retries occur, pause the TID, wait for 3686227364Sadrian * any further retransmits (as there's no reason why 3687227364Sadrian * non-aggregate frames in an aggregate session are 3688227364Sadrian * transmitted in-order; they just have to be in-BAW) 3689227364Sadrian * and then queue a BAR. 3690227364Sadrian */ 3691227364Sadrianstatic void 3692227364Sadrianath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3693227364Sadrian{ 3694227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3695227364Sadrian struct ath_node *an = ATH_NODE(ni); 3696227364Sadrian int tid = bf->bf_state.bfs_tid; 3697227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3698227364Sadrian struct ieee80211_tx_ampdu *tap; 3699227364Sadrian 3700227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3701227364Sadrian 3702227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3703227364Sadrian 3704227364Sadrian /* 3705227364Sadrian * If the buffer is marked as busy, we can't directly 3706227364Sadrian * reuse it. Instead, try to clone the buffer. 3707227364Sadrian * If the clone is successful, recycle the old buffer. 3708227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3709227364Sadrian * to force the next bit of code to free the buffer 3710227364Sadrian * for us. 3711227364Sadrian */ 3712227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3713227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3714227364Sadrian struct ath_buf *nbf; 3715227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3716227364Sadrian if (nbf) 3717227364Sadrian /* bf has been freed at this point */ 3718227364Sadrian bf = nbf; 3719227364Sadrian else 3720227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3721227364Sadrian } 3722227364Sadrian 3723227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3724227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3725227364Sadrian "%s: exceeded retries; seqno %d\n", 3726227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3727227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3728227364Sadrian 3729227364Sadrian /* Update BAW anyway */ 3730227364Sadrian if (bf->bf_state.bfs_dobaw) { 3731227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3732227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3733227364Sadrian device_printf(sc->sc_dev, 3734227364Sadrian "%s: wasn't added: seqno %d\n", 3735227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3736227364Sadrian } 3737227364Sadrian bf->bf_state.bfs_dobaw = 0; 3738227364Sadrian 3739233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3740233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 3741227364Sadrian 3742233908Sadrian /* Send the BAR if there are no other frames waiting */ 3743233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3744233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3745227364Sadrian 3746233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3747227364Sadrian 3748227364Sadrian /* Free buffer, bf is free after this call */ 3749227364Sadrian ath_tx_default_comp(sc, bf, 0); 3750227364Sadrian return; 3751227364Sadrian } 3752227364Sadrian 3753227364Sadrian /* 3754227364Sadrian * This increments the retry counter as well as 3755227364Sadrian * sets the retry flag in the ath_buf and packet 3756227364Sadrian * body. 3757227364Sadrian */ 3758227364Sadrian ath_tx_set_retry(sc, bf); 3759240639Sadrian sc->sc_stats.ast_tx_swretries++; 3760227364Sadrian 3761227364Sadrian /* 3762227364Sadrian * Insert this at the head of the queue, so it's 3763227364Sadrian * retried before any current/subsequent frames. 3764227364Sadrian */ 3765227364Sadrian ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3766227364Sadrian ath_tx_tid_sched(sc, atid); 3767233908Sadrian /* Send the BAR if there are no other frames waiting */ 3768233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3769233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3770227364Sadrian 3771227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3772227364Sadrian} 3773227364Sadrian 3774227364Sadrian/* 3775227364Sadrian * Common code for aggregate excessive retry/subframe retry. 3776227364Sadrian * If retrying, queues buffers to bf_q. If not, frees the 3777227364Sadrian * buffers. 3778227364Sadrian * 3779227364Sadrian * XXX should unify this with ath_tx_aggr_retry_unaggr() 3780227364Sadrian */ 3781227364Sadrianstatic int 3782227364Sadrianath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf, 3783227364Sadrian ath_bufhead *bf_q) 3784227364Sadrian{ 3785227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3786227364Sadrian struct ath_node *an = ATH_NODE(ni); 3787227364Sadrian int tid = bf->bf_state.bfs_tid; 3788227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3789227364Sadrian 3790227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[atid->ac]); 3791227364Sadrian 3792240255Sadrian /* XXX clr11naggr should be done for all subframes */ 3793227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 3794227364Sadrian ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0); 3795240639Sadrian 3796227364Sadrian /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */ 3797227364Sadrian 3798227364Sadrian /* 3799227364Sadrian * If the buffer is marked as busy, we can't directly 3800227364Sadrian * reuse it. Instead, try to clone the buffer. 3801227364Sadrian * If the clone is successful, recycle the old buffer. 3802227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3803227364Sadrian * to force the next bit of code to free the buffer 3804227364Sadrian * for us. 3805227364Sadrian */ 3806227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3807227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3808227364Sadrian struct ath_buf *nbf; 3809227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3810227364Sadrian if (nbf) 3811227364Sadrian /* bf has been freed at this point */ 3812227364Sadrian bf = nbf; 3813227364Sadrian else 3814227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3815227364Sadrian } 3816227364Sadrian 3817227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3818227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3819227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3820227364Sadrian "%s: max retries: seqno %d\n", 3821227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3822227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3823227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3824227364Sadrian device_printf(sc->sc_dev, 3825227364Sadrian "%s: wasn't added: seqno %d\n", 3826227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3827227364Sadrian bf->bf_state.bfs_dobaw = 0; 3828227364Sadrian return 1; 3829227364Sadrian } 3830227364Sadrian 3831227364Sadrian ath_tx_set_retry(sc, bf); 3832240639Sadrian sc->sc_stats.ast_tx_swretries++; 3833227364Sadrian bf->bf_next = NULL; /* Just to make sure */ 3834227364Sadrian 3835240255Sadrian /* Clear the aggregate state */ 3836240255Sadrian bf->bf_state.bfs_aggr = 0; 3837240255Sadrian bf->bf_state.bfs_ndelim = 0; /* ??? needed? */ 3838240255Sadrian bf->bf_state.bfs_nframes = 1; 3839240255Sadrian 3840227364Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3841227364Sadrian return 0; 3842227364Sadrian} 3843227364Sadrian 3844227364Sadrian/* 3845227364Sadrian * error pkt completion for an aggregate destination 3846227364Sadrian */ 3847227364Sadrianstatic void 3848227364Sadrianath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first, 3849227364Sadrian struct ath_tid *tid) 3850227364Sadrian{ 3851227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3852227364Sadrian struct ath_node *an = ATH_NODE(ni); 3853227364Sadrian struct ath_buf *bf_next, *bf; 3854227364Sadrian ath_bufhead bf_q; 3855227364Sadrian int drops = 0; 3856227364Sadrian struct ieee80211_tx_ampdu *tap; 3857227364Sadrian ath_bufhead bf_cq; 3858227364Sadrian 3859227364Sadrian TAILQ_INIT(&bf_q); 3860227364Sadrian TAILQ_INIT(&bf_cq); 3861227364Sadrian 3862227364Sadrian /* 3863227364Sadrian * Update rate control - all frames have failed. 3864227364Sadrian * 3865227364Sadrian * XXX use the length in the first frame in the series; 3866227364Sadrian * XXX just so things are consistent for now. 3867227364Sadrian */ 3868227364Sadrian ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc, 3869227364Sadrian &bf_first->bf_status.ds_txstat, 3870227364Sadrian bf_first->bf_state.bfs_pktlen, 3871227364Sadrian bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes); 3872227364Sadrian 3873227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 3874227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3875227868Sadrian sc->sc_stats.ast_tx_aggr_failall++; 3876227364Sadrian 3877227364Sadrian /* Retry all subframes */ 3878227364Sadrian bf = bf_first; 3879227364Sadrian while (bf) { 3880227364Sadrian bf_next = bf->bf_next; 3881227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 3882227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 3883227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 3884227364Sadrian drops++; 3885227364Sadrian bf->bf_next = NULL; 3886227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3887227364Sadrian } 3888227364Sadrian bf = bf_next; 3889227364Sadrian } 3890227364Sadrian 3891227364Sadrian /* Prepend all frames to the beginning of the queue */ 3892227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 3893227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 3894227364Sadrian ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 3895227364Sadrian } 3896227364Sadrian 3897234725Sadrian /* 3898234725Sadrian * Schedule the TID to be re-tried. 3899234725Sadrian */ 3900227364Sadrian ath_tx_tid_sched(sc, tid); 3901227364Sadrian 3902227364Sadrian /* 3903227364Sadrian * send bar if we dropped any frames 3904227364Sadrian * 3905227364Sadrian * Keep the txq lock held for now, as we need to ensure 3906227364Sadrian * that ni_txseqs[] is consistent (as it's being updated 3907227364Sadrian * in the ifnet TX context or raw TX context.) 3908227364Sadrian */ 3909227364Sadrian if (drops) { 3910233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3911233908Sadrian ath_tx_tid_bar_suspend(sc, tid); 3912227364Sadrian } 3913227364Sadrian 3914233908Sadrian /* 3915233908Sadrian * Send BAR if required 3916233908Sadrian */ 3917233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, tid)) 3918233908Sadrian ath_tx_tid_bar_tx(sc, tid); 3919240639Sadrian 3920233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 3921233908Sadrian 3922227364Sadrian /* Complete frames which errored out */ 3923227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3924227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3925227364Sadrian ath_tx_default_comp(sc, bf, 0); 3926227364Sadrian } 3927227364Sadrian} 3928227364Sadrian 3929227364Sadrian/* 3930227364Sadrian * Handle clean-up of packets from an aggregate list. 3931227364Sadrian * 3932227364Sadrian * There's no need to update the BAW here - the session is being 3933227364Sadrian * torn down. 3934227364Sadrian */ 3935227364Sadrianstatic void 3936227364Sadrianath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first) 3937227364Sadrian{ 3938227364Sadrian struct ath_buf *bf, *bf_next; 3939227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3940227364Sadrian struct ath_node *an = ATH_NODE(ni); 3941227364Sadrian int tid = bf_first->bf_state.bfs_tid; 3942227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3943227364Sadrian 3944227364Sadrian bf = bf_first; 3945227364Sadrian 3946227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3947227364Sadrian 3948227364Sadrian /* update incomp */ 3949227364Sadrian while (bf) { 3950227364Sadrian atid->incomp--; 3951227364Sadrian bf = bf->bf_next; 3952227364Sadrian } 3953227364Sadrian 3954227364Sadrian if (atid->incomp == 0) { 3955227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3956227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3957227364Sadrian __func__, tid); 3958227364Sadrian atid->cleanup_inprogress = 0; 3959227364Sadrian ath_tx_tid_resume(sc, atid); 3960227364Sadrian } 3961233908Sadrian 3962233908Sadrian /* Send BAR if required */ 3963240639Sadrian /* XXX why would we send a BAR when transitioning to non-aggregation? */ 3964233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3965233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3966240639Sadrian 3967227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3968227364Sadrian 3969227364Sadrian /* Handle frame completion */ 3970227364Sadrian while (bf) { 3971227364Sadrian bf_next = bf->bf_next; 3972227364Sadrian ath_tx_default_comp(sc, bf, 1); 3973227364Sadrian bf = bf_next; 3974227364Sadrian } 3975227364Sadrian} 3976227364Sadrian 3977227364Sadrian/* 3978227364Sadrian * Handle completion of an set of aggregate frames. 3979227364Sadrian * 3980227364Sadrian * XXX for now, simply complete each sub-frame. 3981227364Sadrian * 3982227364Sadrian * Note: the completion handler is the last descriptor in the aggregate, 3983227364Sadrian * not the last descriptor in the first frame. 3984227364Sadrian */ 3985227364Sadrianstatic void 3986229949Sadrianath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first, 3987229949Sadrian int fail) 3988227364Sadrian{ 3989227364Sadrian //struct ath_desc *ds = bf->bf_lastds; 3990227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3991227364Sadrian struct ath_node *an = ATH_NODE(ni); 3992227364Sadrian int tid = bf_first->bf_state.bfs_tid; 3993227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3994227364Sadrian struct ath_tx_status ts; 3995227364Sadrian struct ieee80211_tx_ampdu *tap; 3996227364Sadrian ath_bufhead bf_q; 3997227364Sadrian ath_bufhead bf_cq; 3998227364Sadrian int seq_st, tx_ok; 3999227364Sadrian int hasba, isaggr; 4000227364Sadrian uint32_t ba[2]; 4001227364Sadrian struct ath_buf *bf, *bf_next; 4002227364Sadrian int ba_index; 4003227364Sadrian int drops = 0; 4004227364Sadrian int nframes = 0, nbad = 0, nf; 4005227364Sadrian int pktlen; 4006227364Sadrian /* XXX there's too much on the stack? */ 4007236038Sadrian struct ath_rc_series rc[ATH_RC_NUM]; 4008227364Sadrian int txseq; 4009227364Sadrian 4010227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n", 4011227364Sadrian __func__, atid->hwq_depth); 4012227364Sadrian 4013240677Sadrian /* 4014240677Sadrian * Take a copy; this may be needed -after- bf_first 4015240677Sadrian * has been completed and freed. 4016240677Sadrian */ 4017240677Sadrian ts = bf_first->bf_status.ds_txstat; 4018240677Sadrian 4019240639Sadrian TAILQ_INIT(&bf_q); 4020240639Sadrian TAILQ_INIT(&bf_cq); 4021240639Sadrian 4022227364Sadrian /* The TID state is kept behind the TXQ lock */ 4023227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4024227364Sadrian 4025227364Sadrian atid->hwq_depth--; 4026227364Sadrian if (atid->hwq_depth < 0) 4027227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4028227364Sadrian __func__, atid->hwq_depth); 4029227364Sadrian 4030227364Sadrian /* 4031240639Sadrian * If the TID is filtered, handle completing the filter 4032240639Sadrian * transition before potentially kicking it to the cleanup 4033240639Sadrian * function. 4034240677Sadrian * 4035240677Sadrian * XXX this is duplicate work, ew. 4036240639Sadrian */ 4037240639Sadrian if (atid->isfiltered) 4038240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4039240639Sadrian 4040240639Sadrian /* 4041227364Sadrian * Punt cleanup to the relevant function, not our problem now 4042227364Sadrian */ 4043227364Sadrian if (atid->cleanup_inprogress) { 4044240639Sadrian if (atid->isfiltered) 4045240639Sadrian device_printf(sc->sc_dev, 4046240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4047240639Sadrian __func__); 4048227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4049227364Sadrian ath_tx_comp_cleanup_aggr(sc, bf_first); 4050227364Sadrian return; 4051227364Sadrian } 4052227364Sadrian 4053227364Sadrian /* 4054240639Sadrian * If the frame is filtered, transition to filtered frame 4055240639Sadrian * mode and add this to the filtered frame list. 4056240639Sadrian * 4057240639Sadrian * XXX TODO: figure out how this interoperates with 4058240639Sadrian * BAR, pause and cleanup states. 4059240639Sadrian */ 4060240639Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4061240639Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4062240639Sadrian if (fail != 0) 4063240639Sadrian device_printf(sc->sc_dev, 4064240639Sadrian "%s: isfiltered=1, fail=%d\n", __func__, fail); 4065240639Sadrian ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq); 4066240639Sadrian 4067240639Sadrian /* Remove from BAW */ 4068240639Sadrian TAILQ_FOREACH_SAFE(bf, &bf_cq, bf_list, bf_next) { 4069240639Sadrian if (bf->bf_state.bfs_addedbaw) 4070240639Sadrian drops++; 4071240639Sadrian if (bf->bf_state.bfs_dobaw) { 4072240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4073240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4074240639Sadrian device_printf(sc->sc_dev, 4075240639Sadrian "%s: wasn't added: seqno %d\n", 4076240639Sadrian __func__, 4077240639Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4078240639Sadrian } 4079240639Sadrian bf->bf_state.bfs_dobaw = 0; 4080240639Sadrian } 4081240639Sadrian /* 4082240639Sadrian * If any intermediate frames in the BAW were dropped when 4083240639Sadrian * handling filtering things, send a BAR. 4084240639Sadrian */ 4085240639Sadrian if (drops) 4086240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4087240639Sadrian 4088240639Sadrian /* 4089240639Sadrian * Finish up by sending a BAR if required and freeing 4090240639Sadrian * the frames outside of the TX lock. 4091240639Sadrian */ 4092240639Sadrian goto finish_send_bar; 4093240639Sadrian } 4094240639Sadrian 4095240639Sadrian /* 4096227364Sadrian * XXX for now, use the first frame in the aggregate for 4097227364Sadrian * XXX rate control completion; it's at least consistent. 4098227364Sadrian */ 4099227364Sadrian pktlen = bf_first->bf_state.bfs_pktlen; 4100227364Sadrian 4101227364Sadrian /* 4102235461Sadrian * Handle errors first! 4103235461Sadrian * 4104235461Sadrian * Here, handle _any_ error as a "exceeded retries" error. 4105235461Sadrian * Later on (when filtered frames are to be specially handled) 4106235461Sadrian * it'll have to be expanded. 4107227364Sadrian */ 4108235461Sadrian#if 0 4109227364Sadrian if (ts.ts_status & HAL_TXERR_XRETRY) { 4110235461Sadrian#endif 4111235461Sadrian if (ts.ts_status != 0) { 4112227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4113227364Sadrian ath_tx_comp_aggr_error(sc, bf_first, atid); 4114227364Sadrian return; 4115227364Sadrian } 4116227364Sadrian 4117227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4118227364Sadrian 4119227364Sadrian /* 4120227364Sadrian * extract starting sequence and block-ack bitmap 4121227364Sadrian */ 4122227364Sadrian /* XXX endian-ness of seq_st, ba? */ 4123227364Sadrian seq_st = ts.ts_seqnum; 4124227364Sadrian hasba = !! (ts.ts_flags & HAL_TX_BA); 4125227364Sadrian tx_ok = (ts.ts_status == 0); 4126227364Sadrian isaggr = bf_first->bf_state.bfs_aggr; 4127227364Sadrian ba[0] = ts.ts_ba_low; 4128227364Sadrian ba[1] = ts.ts_ba_high; 4129227364Sadrian 4130227364Sadrian /* 4131227364Sadrian * Copy the TX completion status and the rate control 4132227364Sadrian * series from the first descriptor, as it may be freed 4133227364Sadrian * before the rate control code can get its grubby fingers 4134227364Sadrian * into things. 4135227364Sadrian */ 4136227364Sadrian memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc)); 4137227364Sadrian 4138227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4139229949Sadrian "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, " 4140229949Sadrian "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n", 4141227364Sadrian __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags, 4142227364Sadrian isaggr, seq_st, hasba, ba[0], ba[1]); 4143227364Sadrian 4144227364Sadrian /* Occasionally, the MAC sends a tx status for the wrong TID. */ 4145227364Sadrian if (tid != ts.ts_tid) { 4146227364Sadrian device_printf(sc->sc_dev, "%s: tid %d != hw tid %d\n", 4147227364Sadrian __func__, tid, ts.ts_tid); 4148227364Sadrian tx_ok = 0; 4149227364Sadrian } 4150227364Sadrian 4151227364Sadrian /* AR5416 BA bug; this requires an interface reset */ 4152227364Sadrian if (isaggr && tx_ok && (! hasba)) { 4153227364Sadrian device_printf(sc->sc_dev, 4154229949Sadrian "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, " 4155229949Sadrian "seq_st=%d\n", 4156227364Sadrian __func__, hasba, tx_ok, isaggr, seq_st); 4157227364Sadrian /* XXX TODO: schedule an interface reset */ 4158238350Sjhb#ifdef ATH_DEBUG 4159238338Sadrian ath_printtxbuf(sc, bf_first, 4160238338Sadrian sc->sc_ac2q[atid->ac]->axq_qnum, 0, 0); 4161238350Sjhb#endif 4162227364Sadrian } 4163227364Sadrian 4164227364Sadrian /* 4165227364Sadrian * Walk the list of frames, figure out which ones were correctly 4166227364Sadrian * sent and which weren't. 4167227364Sadrian */ 4168227364Sadrian bf = bf_first; 4169227364Sadrian nf = bf_first->bf_state.bfs_nframes; 4170227364Sadrian 4171227364Sadrian /* bf_first is going to be invalid once this list is walked */ 4172227364Sadrian bf_first = NULL; 4173227364Sadrian 4174227364Sadrian /* 4175227364Sadrian * Walk the list of completed frames and determine 4176227364Sadrian * which need to be completed and which need to be 4177227364Sadrian * retransmitted. 4178227364Sadrian * 4179227364Sadrian * For completed frames, the completion functions need 4180227364Sadrian * to be called at the end of this function as the last 4181227364Sadrian * node reference may free the node. 4182227364Sadrian * 4183227364Sadrian * Finally, since the TXQ lock can't be held during the 4184227364Sadrian * completion callback (to avoid lock recursion), 4185227364Sadrian * the completion calls have to be done outside of the 4186227364Sadrian * lock. 4187227364Sadrian */ 4188227364Sadrian while (bf) { 4189227364Sadrian nframes++; 4190229949Sadrian ba_index = ATH_BA_INDEX(seq_st, 4191229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4192227364Sadrian bf_next = bf->bf_next; 4193227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 4194227364Sadrian 4195227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4196227364Sadrian "%s: checking bf=%p seqno=%d; ack=%d\n", 4197227364Sadrian __func__, bf, SEQNO(bf->bf_state.bfs_seqno), 4198227364Sadrian ATH_BA_ISSET(ba, ba_index)); 4199227364Sadrian 4200227364Sadrian if (tx_ok && ATH_BA_ISSET(ba, ba_index)) { 4201227868Sadrian sc->sc_stats.ast_tx_aggr_ok++; 4202227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4203227364Sadrian bf->bf_state.bfs_dobaw = 0; 4204227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4205227364Sadrian device_printf(sc->sc_dev, 4206227364Sadrian "%s: wasn't added: seqno %d\n", 4207227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4208227364Sadrian bf->bf_next = NULL; 4209227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4210227364Sadrian } else { 4211227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 4212227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4213227364Sadrian drops++; 4214227364Sadrian bf->bf_next = NULL; 4215227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4216227364Sadrian } 4217227364Sadrian nbad++; 4218227364Sadrian } 4219227364Sadrian bf = bf_next; 4220227364Sadrian } 4221227364Sadrian 4222227364Sadrian /* 4223227364Sadrian * Now that the BAW updates have been done, unlock 4224227364Sadrian * 4225227364Sadrian * txseq is grabbed before the lock is released so we 4226227364Sadrian * have a consistent view of what -was- in the BAW. 4227227364Sadrian * Anything after this point will not yet have been 4228227364Sadrian * TXed. 4229227364Sadrian */ 4230227364Sadrian txseq = tap->txa_start; 4231227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4232227364Sadrian 4233227364Sadrian if (nframes != nf) 4234227364Sadrian device_printf(sc->sc_dev, 4235227364Sadrian "%s: num frames seen=%d; bf nframes=%d\n", 4236227364Sadrian __func__, nframes, nf); 4237227364Sadrian 4238227364Sadrian /* 4239227364Sadrian * Now we know how many frames were bad, call the rate 4240227364Sadrian * control code. 4241227364Sadrian */ 4242227364Sadrian if (fail == 0) 4243229949Sadrian ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes, 4244229949Sadrian nbad); 4245227364Sadrian 4246227364Sadrian /* 4247227364Sadrian * send bar if we dropped any frames 4248227364Sadrian */ 4249227364Sadrian if (drops) { 4250233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 4251233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4252233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 4253233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4254227364Sadrian } 4255227364Sadrian 4256234725Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4257234725Sadrian "%s: txa_start now %d\n", __func__, tap->txa_start); 4258234725Sadrian 4259234725Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4260234725Sadrian 4261227364Sadrian /* Prepend all frames to the beginning of the queue */ 4262227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4263227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 4264227364Sadrian ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 4265227364Sadrian } 4266234725Sadrian 4267234725Sadrian /* 4268234725Sadrian * Reschedule to grab some further frames. 4269234725Sadrian */ 4270227364Sadrian ath_tx_tid_sched(sc, atid); 4271227364Sadrian 4272233908Sadrian /* 4273240639Sadrian * If the queue is filtered, re-schedule as required. 4274240639Sadrian * 4275240639Sadrian * This is required as there may be a subsequent TX descriptor 4276240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4277240639Sadrian * that a filtered frame will be followed by a non-filtered 4278240639Sadrian * (complete or otherwise) frame. 4279240639Sadrian * 4280240639Sadrian * XXX should we do this before we complete the frame? 4281240639Sadrian */ 4282240639Sadrian if (atid->isfiltered) 4283240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4284240639Sadrian 4285240639Sadrianfinish_send_bar: 4286240639Sadrian 4287240639Sadrian /* 4288233908Sadrian * Send BAR if required 4289233908Sadrian */ 4290233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4291233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4292234725Sadrian 4293233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4294233908Sadrian 4295227364Sadrian /* Do deferred completion */ 4296227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4297227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 4298227364Sadrian ath_tx_default_comp(sc, bf, 0); 4299227364Sadrian } 4300227364Sadrian} 4301227364Sadrian 4302227364Sadrian/* 4303227364Sadrian * Handle completion of unaggregated frames in an ADDBA 4304227364Sadrian * session. 4305227364Sadrian * 4306227364Sadrian * Fail is set to 1 if the entry is being freed via a call to 4307227364Sadrian * ath_tx_draintxq(). 4308227364Sadrian */ 4309227364Sadrianstatic void 4310227364Sadrianath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail) 4311227364Sadrian{ 4312227364Sadrian struct ieee80211_node *ni = bf->bf_node; 4313227364Sadrian struct ath_node *an = ATH_NODE(ni); 4314227364Sadrian int tid = bf->bf_state.bfs_tid; 4315227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4316240677Sadrian struct ath_tx_status ts; 4317240639Sadrian int drops = 0; 4318227364Sadrian 4319227364Sadrian /* 4320240677Sadrian * Take a copy of this; filtering/cloning the frame may free the 4321240677Sadrian * bf pointer. 4322240677Sadrian */ 4323240677Sadrian ts = bf->bf_status.ds_txstat; 4324240677Sadrian 4325240677Sadrian /* 4326227364Sadrian * Update rate control status here, before we possibly 4327227364Sadrian * punt to retry or cleanup. 4328227364Sadrian * 4329227364Sadrian * Do it outside of the TXQ lock. 4330227364Sadrian */ 4331233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 4332227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 4333227364Sadrian &bf->bf_status.ds_txstat, 4334227364Sadrian bf->bf_state.bfs_pktlen, 4335240677Sadrian 1, (ts.ts_status == 0) ? 0 : 1); 4336227364Sadrian 4337227364Sadrian /* 4338227364Sadrian * This is called early so atid->hwq_depth can be tracked. 4339227364Sadrian * This unfortunately means that it's released and regrabbed 4340227364Sadrian * during retry and cleanup. That's rather inefficient. 4341227364Sadrian */ 4342227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4343227364Sadrian 4344227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4345227364Sadrian device_printf(sc->sc_dev, "%s: TID=16!\n", __func__); 4346227364Sadrian 4347229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 4348229949Sadrian "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n", 4349229949Sadrian __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth, 4350229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4351227364Sadrian 4352227364Sadrian atid->hwq_depth--; 4353227364Sadrian if (atid->hwq_depth < 0) 4354227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4355227364Sadrian __func__, atid->hwq_depth); 4356227364Sadrian 4357227364Sadrian /* 4358240639Sadrian * If the TID is filtered, handle completing the filter 4359240639Sadrian * transition before potentially kicking it to the cleanup 4360240639Sadrian * function. 4361240639Sadrian */ 4362240639Sadrian if (atid->isfiltered) 4363240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4364240639Sadrian 4365240639Sadrian /* 4366227364Sadrian * If a cleanup is in progress, punt to comp_cleanup; 4367227364Sadrian * rather than handling it here. It's thus their 4368227364Sadrian * responsibility to clean up, call the completion 4369227364Sadrian * function in net80211, etc. 4370227364Sadrian */ 4371227364Sadrian if (atid->cleanup_inprogress) { 4372240639Sadrian if (atid->isfiltered) 4373240639Sadrian device_printf(sc->sc_dev, 4374240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4375240639Sadrian __func__); 4376227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4377229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n", 4378229949Sadrian __func__); 4379227364Sadrian ath_tx_comp_cleanup_unaggr(sc, bf); 4380227364Sadrian return; 4381227364Sadrian } 4382227364Sadrian 4383227364Sadrian /* 4384240639Sadrian * XXX TODO: how does cleanup, BAR and filtered frame handling 4385240639Sadrian * overlap? 4386240639Sadrian * 4387240639Sadrian * If the frame is filtered OR if it's any failure but 4388240639Sadrian * the TID is filtered, the frame must be added to the 4389240639Sadrian * filtered frame list. 4390240639Sadrian * 4391240639Sadrian * However - a busy buffer can't be added to the filtered 4392240639Sadrian * list as it will end up being recycled without having 4393240639Sadrian * been made available for the hardware. 4394240639Sadrian */ 4395240677Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4396240677Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4397240639Sadrian int freeframe; 4398240639Sadrian 4399240639Sadrian if (fail != 0) 4400240639Sadrian device_printf(sc->sc_dev, 4401240639Sadrian "%s: isfiltered=1, fail=%d\n", 4402240639Sadrian __func__, 4403240639Sadrian fail); 4404240639Sadrian freeframe = ath_tx_tid_filt_comp_single(sc, atid, bf); 4405240639Sadrian if (freeframe) { 4406240639Sadrian /* Remove from BAW */ 4407240639Sadrian if (bf->bf_state.bfs_addedbaw) 4408240639Sadrian drops++; 4409240639Sadrian if (bf->bf_state.bfs_dobaw) { 4410240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4411240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4412240639Sadrian device_printf(sc->sc_dev, 4413240639Sadrian "%s: wasn't added: seqno %d\n", 4414240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4415240639Sadrian } 4416240639Sadrian bf->bf_state.bfs_dobaw = 0; 4417240639Sadrian } 4418240639Sadrian 4419240639Sadrian /* 4420240639Sadrian * If the frame couldn't be filtered, treat it as a drop and 4421240639Sadrian * prepare to send a BAR. 4422240639Sadrian */ 4423240639Sadrian if (freeframe && drops) 4424240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4425240639Sadrian 4426240639Sadrian /* 4427240639Sadrian * Send BAR if required 4428240639Sadrian */ 4429240639Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4430240639Sadrian ath_tx_tid_bar_tx(sc, atid); 4431240639Sadrian 4432240639Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4433240639Sadrian /* 4434240639Sadrian * If freeframe is set, then the frame couldn't be 4435240639Sadrian * cloned and bf is still valid. Just complete/free it. 4436240639Sadrian */ 4437240639Sadrian if (freeframe) 4438240639Sadrian ath_tx_default_comp(sc, bf, fail); 4439240639Sadrian 4440240639Sadrian 4441240639Sadrian return; 4442240639Sadrian } 4443240639Sadrian /* 4444227364Sadrian * Don't bother with the retry check if all frames 4445227364Sadrian * are being failed (eg during queue deletion.) 4446227364Sadrian */ 4447235461Sadrian#if 0 4448227364Sadrian if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) { 4449235461Sadrian#endif 4450240677Sadrian if (fail == 0 && ts.ts_status != 0) { 4451227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4452229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n", 4453229949Sadrian __func__); 4454227364Sadrian ath_tx_aggr_retry_unaggr(sc, bf); 4455227364Sadrian return; 4456227364Sadrian } 4457227364Sadrian 4458227364Sadrian /* Success? Complete */ 4459227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n", 4460227364Sadrian __func__, tid, SEQNO(bf->bf_state.bfs_seqno)); 4461227364Sadrian if (bf->bf_state.bfs_dobaw) { 4462227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4463227364Sadrian bf->bf_state.bfs_dobaw = 0; 4464227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4465227364Sadrian device_printf(sc->sc_dev, 4466227364Sadrian "%s: wasn't added: seqno %d\n", 4467227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4468227364Sadrian } 4469227364Sadrian 4470233908Sadrian /* 4471240639Sadrian * If the queue is filtered, re-schedule as required. 4472240639Sadrian * 4473240639Sadrian * This is required as there may be a subsequent TX descriptor 4474240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4475240639Sadrian * that a filtered frame will be followed by a non-filtered 4476240639Sadrian * (complete or otherwise) frame. 4477240639Sadrian * 4478240639Sadrian * XXX should we do this before we complete the frame? 4479240639Sadrian */ 4480240639Sadrian if (atid->isfiltered) 4481240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4482240639Sadrian 4483240639Sadrian /* 4484233908Sadrian * Send BAR if required 4485233908Sadrian */ 4486233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4487233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4488233908Sadrian 4489227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4490227364Sadrian 4491227364Sadrian ath_tx_default_comp(sc, bf, fail); 4492227364Sadrian /* bf is freed at this point */ 4493227364Sadrian} 4494227364Sadrian 4495227364Sadrianvoid 4496227364Sadrianath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 4497227364Sadrian{ 4498227364Sadrian if (bf->bf_state.bfs_aggr) 4499227364Sadrian ath_tx_aggr_comp_aggr(sc, bf, fail); 4500227364Sadrian else 4501227364Sadrian ath_tx_aggr_comp_unaggr(sc, bf, fail); 4502227364Sadrian} 4503227364Sadrian 4504227364Sadrian/* 4505227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4506227364Sadrian * 4507227364Sadrian * This is the aggregate version. 4508227364Sadrian */ 4509227364Sadrianvoid 4510227364Sadrianath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an, 4511227364Sadrian struct ath_tid *tid) 4512227364Sadrian{ 4513227364Sadrian struct ath_buf *bf; 4514227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4515227364Sadrian struct ieee80211_tx_ampdu *tap; 4516227364Sadrian ATH_AGGR_STATUS status; 4517227364Sadrian ath_bufhead bf_q; 4518227364Sadrian 4519227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid); 4520227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 4521227364Sadrian 4522227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 4523227364Sadrian 4524227364Sadrian if (tid->tid == IEEE80211_NONQOS_TID) 4525227364Sadrian device_printf(sc->sc_dev, "%s: called for TID=NONQOS_TID?\n", 4526227364Sadrian __func__); 4527227364Sadrian 4528227364Sadrian for (;;) { 4529227364Sadrian status = ATH_AGGR_DONE; 4530227364Sadrian 4531227364Sadrian /* 4532227364Sadrian * If the upper layer has paused the TID, don't 4533227364Sadrian * queue any further packets. 4534227364Sadrian * 4535227364Sadrian * This can also occur from the completion task because 4536227364Sadrian * of packet loss; but as its serialised with this code, 4537227364Sadrian * it won't "appear" half way through queuing packets. 4538227364Sadrian */ 4539227364Sadrian if (tid->paused) 4540227364Sadrian break; 4541227364Sadrian 4542227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 4543227364Sadrian if (bf == NULL) { 4544227364Sadrian break; 4545227364Sadrian } 4546227364Sadrian 4547227364Sadrian /* 4548227364Sadrian * If the packet doesn't fall within the BAW (eg a NULL 4549227364Sadrian * data frame), schedule it directly; continue. 4550227364Sadrian */ 4551227364Sadrian if (! bf->bf_state.bfs_dobaw) { 4552229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4553229949Sadrian "%s: non-baw packet\n", 4554227364Sadrian __func__); 4555227364Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 4556240180Sadrian 4557240180Sadrian if (bf->bf_state.bfs_nframes > 1) 4558240180Sadrian device_printf(sc->sc_dev, 4559240180Sadrian "%s: aggr=%d, nframes=%d\n", 4560240180Sadrian __func__, 4561240180Sadrian bf->bf_state.bfs_aggr, 4562240180Sadrian bf->bf_state.bfs_nframes); 4563240180Sadrian 4564240180Sadrian /* 4565240180Sadrian * This shouldn't happen - such frames shouldn't 4566240180Sadrian * ever have been queued as an aggregate in the 4567240180Sadrian * first place. However, make sure the fields 4568240180Sadrian * are correctly setup just to be totally sure. 4569240180Sadrian */ 4570227364Sadrian bf->bf_state.bfs_aggr = 0; 4571240180Sadrian bf->bf_state.bfs_nframes = 1; 4572240180Sadrian 4573240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4574240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4575240724Sadrian 4576227364Sadrian ath_tx_do_ratelookup(sc, bf); 4577233989Sadrian ath_tx_calc_duration(sc, bf); 4578233989Sadrian ath_tx_calc_protection(sc, bf); 4579233989Sadrian ath_tx_set_rtscts(sc, bf); 4580227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4581227364Sadrian ath_tx_setds(sc, bf); 4582227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4583227364Sadrian 4584227364Sadrian sc->sc_aggr_stats.aggr_nonbaw_pkt++; 4585227364Sadrian 4586227364Sadrian /* Queue the packet; continue */ 4587227364Sadrian goto queuepkt; 4588227364Sadrian } 4589227364Sadrian 4590227364Sadrian TAILQ_INIT(&bf_q); 4591227364Sadrian 4592227364Sadrian /* 4593227364Sadrian * Do a rate control lookup on the first frame in the 4594227364Sadrian * list. The rate control code needs that to occur 4595227364Sadrian * before it can determine whether to TX. 4596227364Sadrian * It's inaccurate because the rate control code doesn't 4597227364Sadrian * really "do" aggregate lookups, so it only considers 4598227364Sadrian * the size of the first frame. 4599227364Sadrian */ 4600227364Sadrian ath_tx_do_ratelookup(sc, bf); 4601227364Sadrian bf->bf_state.bfs_rc[3].rix = 0; 4602227364Sadrian bf->bf_state.bfs_rc[3].tries = 0; 4603233989Sadrian 4604233989Sadrian ath_tx_calc_duration(sc, bf); 4605233989Sadrian ath_tx_calc_protection(sc, bf); 4606233989Sadrian 4607233989Sadrian ath_tx_set_rtscts(sc, bf); 4608227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4609227364Sadrian 4610227364Sadrian status = ath_tx_form_aggr(sc, an, tid, &bf_q); 4611227364Sadrian 4612227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4613227364Sadrian "%s: ath_tx_form_aggr() status=%d\n", __func__, status); 4614227364Sadrian 4615227364Sadrian /* 4616227364Sadrian * No frames to be picked up - out of BAW 4617227364Sadrian */ 4618227364Sadrian if (TAILQ_EMPTY(&bf_q)) 4619227364Sadrian break; 4620227364Sadrian 4621227364Sadrian /* 4622227364Sadrian * This assumes that the descriptor list in the ath_bufhead 4623227364Sadrian * are already linked together via bf_next pointers. 4624227364Sadrian */ 4625227364Sadrian bf = TAILQ_FIRST(&bf_q); 4626227364Sadrian 4627233989Sadrian if (status == ATH_AGGR_8K_LIMITED) 4628233989Sadrian sc->sc_aggr_stats.aggr_rts_aggr_limited++; 4629233989Sadrian 4630227364Sadrian /* 4631227364Sadrian * If it's the only frame send as non-aggregate 4632227364Sadrian * assume that ath_tx_form_aggr() has checked 4633227364Sadrian * whether it's in the BAW and added it appropriately. 4634227364Sadrian */ 4635227364Sadrian if (bf->bf_state.bfs_nframes == 1) { 4636227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4637227364Sadrian "%s: single-frame aggregate\n", __func__); 4638240724Sadrian 4639240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4640240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4641240724Sadrian 4642227364Sadrian bf->bf_state.bfs_aggr = 0; 4643240255Sadrian bf->bf_state.bfs_ndelim = 0; 4644227364Sadrian ath_tx_setds(sc, bf); 4645227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4646227364Sadrian if (status == ATH_AGGR_BAW_CLOSED) 4647227364Sadrian sc->sc_aggr_stats.aggr_baw_closed_single_pkt++; 4648227364Sadrian else 4649227364Sadrian sc->sc_aggr_stats.aggr_single_pkt++; 4650227364Sadrian } else { 4651227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4652229949Sadrian "%s: multi-frame aggregate: %d frames, " 4653229949Sadrian "length %d\n", 4654227364Sadrian __func__, bf->bf_state.bfs_nframes, 4655227364Sadrian bf->bf_state.bfs_al); 4656227364Sadrian bf->bf_state.bfs_aggr = 1; 4657227364Sadrian sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++; 4658227364Sadrian sc->sc_aggr_stats.aggr_aggr_pkt++; 4659227364Sadrian 4660240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4661240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4662240724Sadrian 4663227364Sadrian /* 4664233989Sadrian * Calculate the duration/protection as required. 4665233989Sadrian */ 4666233989Sadrian ath_tx_calc_duration(sc, bf); 4667233989Sadrian ath_tx_calc_protection(sc, bf); 4668233989Sadrian 4669233989Sadrian /* 4670227364Sadrian * Update the rate and rtscts information based on the 4671227364Sadrian * rate decision made by the rate control code; 4672227364Sadrian * the first frame in the aggregate needs it. 4673227364Sadrian */ 4674227364Sadrian ath_tx_set_rtscts(sc, bf); 4675227364Sadrian 4676227364Sadrian /* 4677227364Sadrian * Setup the relevant descriptor fields 4678227364Sadrian * for aggregation. The first descriptor 4679227364Sadrian * already points to the rest in the chain. 4680227364Sadrian */ 4681227364Sadrian ath_tx_setds_11n(sc, bf); 4682227364Sadrian 4683227364Sadrian } 4684227364Sadrian queuepkt: 4685227364Sadrian //txq = bf->bf_state.bfs_txq; 4686227364Sadrian 4687227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 4688227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 4689227364Sadrian 4690227364Sadrian if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID) 4691227364Sadrian device_printf(sc->sc_dev, "%s: TID=16?\n", __func__); 4692227364Sadrian 4693227364Sadrian /* Punt to txq */ 4694227364Sadrian ath_tx_handoff(sc, txq, bf); 4695227364Sadrian 4696227364Sadrian /* Track outstanding buffer count to hardware */ 4697227364Sadrian /* aggregates are "one" buffer */ 4698227364Sadrian tid->hwq_depth++; 4699227364Sadrian 4700227364Sadrian /* 4701227364Sadrian * Break out if ath_tx_form_aggr() indicated 4702227364Sadrian * there can't be any further progress (eg BAW is full.) 4703227364Sadrian * Checking for an empty txq is done above. 4704227364Sadrian * 4705227364Sadrian * XXX locking on txq here? 4706227364Sadrian */ 4707227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit || 4708227364Sadrian status == ATH_AGGR_BAW_CLOSED) 4709227364Sadrian break; 4710227364Sadrian } 4711227364Sadrian} 4712227364Sadrian 4713227364Sadrian/* 4714227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4715227364Sadrian */ 4716227364Sadrianvoid 4717227364Sadrianath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an, 4718227364Sadrian struct ath_tid *tid) 4719227364Sadrian{ 4720227364Sadrian struct ath_buf *bf; 4721227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4722227364Sadrian 4723227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n", 4724227364Sadrian __func__, an, tid->tid); 4725227364Sadrian 4726240724Sadrian ATH_TID_LOCK_ASSERT(sc, tid); 4727227364Sadrian 4728227364Sadrian /* Check - is AMPDU pending or running? then print out something */ 4729227364Sadrian if (ath_tx_ampdu_pending(sc, an, tid->tid)) 4730227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu pending?\n", 4731227364Sadrian __func__, tid->tid); 4732227364Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid)) 4733227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu running?\n", 4734227364Sadrian __func__, tid->tid); 4735227364Sadrian 4736227364Sadrian for (;;) { 4737227364Sadrian 4738227364Sadrian /* 4739227364Sadrian * If the upper layers have paused the TID, don't 4740227364Sadrian * queue any further packets. 4741227364Sadrian */ 4742227364Sadrian if (tid->paused) 4743227364Sadrian break; 4744227364Sadrian 4745227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 4746227364Sadrian if (bf == NULL) { 4747227364Sadrian break; 4748227364Sadrian } 4749227364Sadrian 4750227364Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 4751227364Sadrian 4752227364Sadrian KASSERT(txq == bf->bf_state.bfs_txq, ("txqs not equal!\n")); 4753227364Sadrian 4754227364Sadrian /* Sanity check! */ 4755227364Sadrian if (tid->tid != bf->bf_state.bfs_tid) { 4756227364Sadrian device_printf(sc->sc_dev, "%s: bfs_tid %d !=" 4757227364Sadrian " tid %d\n", 4758227364Sadrian __func__, bf->bf_state.bfs_tid, tid->tid); 4759227364Sadrian } 4760227364Sadrian /* Normal completion handler */ 4761227364Sadrian bf->bf_comp = ath_tx_normal_comp; 4762227364Sadrian 4763240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4764240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4765240724Sadrian 4766227364Sadrian /* Program descriptors + rate control */ 4767227364Sadrian ath_tx_do_ratelookup(sc, bf); 4768233989Sadrian ath_tx_calc_duration(sc, bf); 4769233989Sadrian ath_tx_calc_protection(sc, bf); 4770233989Sadrian ath_tx_set_rtscts(sc, bf); 4771227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4772227364Sadrian ath_tx_setds(sc, bf); 4773227364Sadrian 4774227364Sadrian /* Track outstanding buffer count to hardware */ 4775227364Sadrian /* aggregates are "one" buffer */ 4776227364Sadrian tid->hwq_depth++; 4777227364Sadrian 4778227364Sadrian /* Punt to hardware or software txq */ 4779227364Sadrian ath_tx_handoff(sc, txq, bf); 4780227364Sadrian } 4781227364Sadrian} 4782227364Sadrian 4783227364Sadrian/* 4784227364Sadrian * Schedule some packets to the given hardware queue. 4785227364Sadrian * 4786227364Sadrian * This function walks the list of TIDs (ie, ath_node TIDs 4787227364Sadrian * with queued traffic) and attempts to schedule traffic 4788227364Sadrian * from them. 4789227364Sadrian * 4790227364Sadrian * TID scheduling is implemented as a FIFO, with TIDs being 4791227364Sadrian * added to the end of the queue after some frames have been 4792227364Sadrian * scheduled. 4793227364Sadrian */ 4794227364Sadrianvoid 4795227364Sadrianath_txq_sched(struct ath_softc *sc, struct ath_txq *txq) 4796227364Sadrian{ 4797227364Sadrian struct ath_tid *tid, *next, *last; 4798227364Sadrian 4799227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 4800227364Sadrian 4801227364Sadrian /* 4802227364Sadrian * Don't schedule if the hardware queue is busy. 4803227364Sadrian * This (hopefully) gives some more time to aggregate 4804227364Sadrian * some packets in the aggregation queue. 4805227364Sadrian */ 4806227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4807227364Sadrian sc->sc_aggr_stats.aggr_sched_nopkt++; 4808227364Sadrian return; 4809227364Sadrian } 4810227364Sadrian 4811227364Sadrian last = TAILQ_LAST(&txq->axq_tidq, axq_t_s); 4812227364Sadrian 4813227364Sadrian TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) { 4814227364Sadrian /* 4815227364Sadrian * Suspend paused queues here; they'll be resumed 4816227364Sadrian * once the addba completes or times out. 4817227364Sadrian */ 4818227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n", 4819227364Sadrian __func__, tid->tid, tid->paused); 4820227364Sadrian ath_tx_tid_unsched(sc, tid); 4821227364Sadrian if (tid->paused) { 4822227364Sadrian continue; 4823227364Sadrian } 4824227364Sadrian if (ath_tx_ampdu_running(sc, tid->an, tid->tid)) 4825227364Sadrian ath_tx_tid_hw_queue_aggr(sc, tid->an, tid); 4826227364Sadrian else 4827227364Sadrian ath_tx_tid_hw_queue_norm(sc, tid->an, tid); 4828227364Sadrian 4829227364Sadrian /* Not empty? Re-schedule */ 4830227364Sadrian if (tid->axq_depth != 0) 4831227364Sadrian ath_tx_tid_sched(sc, tid); 4832227364Sadrian 4833227364Sadrian /* Give the software queue time to aggregate more packets */ 4834227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4835227364Sadrian break; 4836227364Sadrian } 4837227364Sadrian 4838227364Sadrian /* 4839227364Sadrian * If this was the last entry on the original list, stop. 4840227364Sadrian * Otherwise nodes that have been rescheduled onto the end 4841227364Sadrian * of the TID FIFO list will just keep being rescheduled. 4842227364Sadrian */ 4843227364Sadrian if (tid == last) 4844227364Sadrian break; 4845227364Sadrian } 4846227364Sadrian} 4847227364Sadrian 4848227364Sadrian/* 4849227364Sadrian * TX addba handling 4850227364Sadrian */ 4851227364Sadrian 4852227364Sadrian/* 4853227364Sadrian * Return net80211 TID struct pointer, or NULL for none 4854227364Sadrian */ 4855227364Sadrianstruct ieee80211_tx_ampdu * 4856227364Sadrianath_tx_get_tx_tid(struct ath_node *an, int tid) 4857227364Sadrian{ 4858227364Sadrian struct ieee80211_node *ni = &an->an_node; 4859227364Sadrian struct ieee80211_tx_ampdu *tap; 4860227364Sadrian 4861227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4862227364Sadrian return NULL; 4863227364Sadrian 4864234324Sadrian tap = &ni->ni_tx_ampdu[tid]; 4865227364Sadrian return tap; 4866227364Sadrian} 4867227364Sadrian 4868227364Sadrian/* 4869227364Sadrian * Is AMPDU-TX running? 4870227364Sadrian */ 4871227364Sadrianstatic int 4872227364Sadrianath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid) 4873227364Sadrian{ 4874227364Sadrian struct ieee80211_tx_ampdu *tap; 4875227364Sadrian 4876227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4877227364Sadrian return 0; 4878227364Sadrian 4879227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4880227364Sadrian if (tap == NULL) 4881227364Sadrian return 0; /* Not valid; default to not running */ 4882227364Sadrian 4883227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING); 4884227364Sadrian} 4885227364Sadrian 4886227364Sadrian/* 4887227364Sadrian * Is AMPDU-TX negotiation pending? 4888227364Sadrian */ 4889227364Sadrianstatic int 4890227364Sadrianath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid) 4891227364Sadrian{ 4892227364Sadrian struct ieee80211_tx_ampdu *tap; 4893227364Sadrian 4894227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4895227364Sadrian return 0; 4896227364Sadrian 4897227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4898227364Sadrian if (tap == NULL) 4899227364Sadrian return 0; /* Not valid; default to not pending */ 4900227364Sadrian 4901227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND); 4902227364Sadrian} 4903227364Sadrian 4904227364Sadrian/* 4905227364Sadrian * Is AMPDU-TX pending for the given TID? 4906227364Sadrian */ 4907227364Sadrian 4908227364Sadrian 4909227364Sadrian/* 4910227364Sadrian * Method to handle sending an ADDBA request. 4911227364Sadrian * 4912227364Sadrian * We tap this so the relevant flags can be set to pause the TID 4913227364Sadrian * whilst waiting for the response. 4914227364Sadrian * 4915227364Sadrian * XXX there's no timeout handler we can override? 4916227364Sadrian */ 4917227364Sadrianint 4918227364Sadrianath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 4919227364Sadrian int dialogtoken, int baparamset, int batimeout) 4920227364Sadrian{ 4921227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4922234324Sadrian int tid = tap->txa_tid; 4923227364Sadrian struct ath_node *an = ATH_NODE(ni); 4924227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4925227364Sadrian 4926227364Sadrian /* 4927227364Sadrian * XXX danger Will Robinson! 4928227364Sadrian * 4929227364Sadrian * Although the taskqueue may be running and scheduling some more 4930227364Sadrian * packets, these should all be _before_ the addba sequence number. 4931227364Sadrian * However, net80211 will keep self-assigning sequence numbers 4932227364Sadrian * until addba has been negotiated. 4933227364Sadrian * 4934227364Sadrian * In the past, these packets would be "paused" (which still works 4935227364Sadrian * fine, as they're being scheduled to the driver in the same 4936227364Sadrian * serialised method which is calling the addba request routine) 4937227364Sadrian * and when the aggregation session begins, they'll be dequeued 4938227364Sadrian * as aggregate packets and added to the BAW. However, now there's 4939227364Sadrian * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these 4940227364Sadrian * packets. Thus they never get included in the BAW tracking and 4941227364Sadrian * this can cause the initial burst of packets after the addba 4942227364Sadrian * negotiation to "hang", as they quickly fall outside the BAW. 4943227364Sadrian * 4944227364Sadrian * The "eventual" solution should be to tag these packets with 4945227364Sadrian * dobaw. Although net80211 has given us a sequence number, 4946227364Sadrian * it'll be "after" the left edge of the BAW and thus it'll 4947227364Sadrian * fall within it. 4948227364Sadrian */ 4949235034Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4950235774Sadrian /* 4951235774Sadrian * This is a bit annoying. Until net80211 HT code inherits some 4952235774Sadrian * (any) locking, we may have this called in parallel BUT only 4953235774Sadrian * one response/timeout will be called. Grr. 4954235774Sadrian */ 4955235774Sadrian if (atid->addba_tx_pending == 0) { 4956235774Sadrian ath_tx_tid_pause(sc, atid); 4957235774Sadrian atid->addba_tx_pending = 1; 4958235774Sadrian } 4959235034Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4960227364Sadrian 4961227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4962227364Sadrian "%s: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n", 4963227364Sadrian __func__, dialogtoken, baparamset, batimeout); 4964227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4965227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 4966227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 4967227364Sadrian 4968227364Sadrian return sc->sc_addba_request(ni, tap, dialogtoken, baparamset, 4969227364Sadrian batimeout); 4970227364Sadrian} 4971227364Sadrian 4972227364Sadrian/* 4973227364Sadrian * Handle an ADDBA response. 4974227364Sadrian * 4975227364Sadrian * We unpause the queue so TX'ing can resume. 4976227364Sadrian * 4977227364Sadrian * Any packets TX'ed from this point should be "aggregate" (whether 4978227364Sadrian * aggregate or not) so the BAW is updated. 4979227364Sadrian * 4980227364Sadrian * Note! net80211 keeps self-assigning sequence numbers until 4981227364Sadrian * ampdu is negotiated. This means the initially-negotiated BAW left 4982227364Sadrian * edge won't match the ni->ni_txseq. 4983227364Sadrian * 4984227364Sadrian * So, being very dirty, the BAW left edge is "slid" here to match 4985227364Sadrian * ni->ni_txseq. 4986227364Sadrian * 4987227364Sadrian * What likely SHOULD happen is that all packets subsequent to the 4988227364Sadrian * addba request should be tagged as aggregate and queued as non-aggregate 4989227364Sadrian * frames; thus updating the BAW. For now though, I'll just slide the 4990227364Sadrian * window. 4991227364Sadrian */ 4992227364Sadrianint 4993227364Sadrianath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 4994227364Sadrian int status, int code, int batimeout) 4995227364Sadrian{ 4996227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4997234324Sadrian int tid = tap->txa_tid; 4998227364Sadrian struct ath_node *an = ATH_NODE(ni); 4999227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5000227364Sadrian int r; 5001227364Sadrian 5002227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5003227364Sadrian "%s: called; status=%d, code=%d, batimeout=%d\n", __func__, 5004227364Sadrian status, code, batimeout); 5005227364Sadrian 5006227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5007227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 5008227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 5009227364Sadrian 5010227364Sadrian /* 5011227364Sadrian * Call this first, so the interface flags get updated 5012227364Sadrian * before the TID is unpaused. Otherwise a race condition 5013227364Sadrian * exists where the unpaused TID still doesn't yet have 5014227364Sadrian * IEEE80211_AGGR_RUNNING set. 5015227364Sadrian */ 5016227364Sadrian r = sc->sc_addba_response(ni, tap, status, code, batimeout); 5017227364Sadrian 5018227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5019235774Sadrian atid->addba_tx_pending = 0; 5020227364Sadrian /* 5021227364Sadrian * XXX dirty! 5022227364Sadrian * Slide the BAW left edge to wherever net80211 left it for us. 5023227364Sadrian * Read above for more information. 5024227364Sadrian */ 5025227364Sadrian tap->txa_start = ni->ni_txseqs[tid]; 5026227364Sadrian ath_tx_tid_resume(sc, atid); 5027227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5028227364Sadrian return r; 5029227364Sadrian} 5030227364Sadrian 5031227364Sadrian 5032227364Sadrian/* 5033227364Sadrian * Stop ADDBA on a queue. 5034237593Sadrian * 5035237593Sadrian * This can be called whilst BAR TX is currently active on the queue, 5036237593Sadrian * so make sure this is unblocked before continuing. 5037227364Sadrian */ 5038227364Sadrianvoid 5039227364Sadrianath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 5040227364Sadrian{ 5041227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5042234324Sadrian int tid = tap->txa_tid; 5043227364Sadrian struct ath_node *an = ATH_NODE(ni); 5044227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5045227364Sadrian 5046227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: called\n", __func__); 5047227364Sadrian 5048237593Sadrian /* 5049237593Sadrian * Pause TID traffic early, so there aren't any races 5050237593Sadrian * Unblock the pending BAR held traffic, if it's currently paused. 5051237593Sadrian */ 5052235034Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5053227364Sadrian ath_tx_tid_pause(sc, atid); 5054237593Sadrian if (atid->bar_wait) { 5055237593Sadrian /* 5056237593Sadrian * bar_unsuspend() expects bar_tx == 1, as it should be 5057237593Sadrian * called from the TX completion path. This quietens 5058237593Sadrian * the warning. It's cleared for us anyway. 5059237593Sadrian */ 5060237593Sadrian atid->bar_tx = 1; 5061237593Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5062237593Sadrian } 5063235034Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5064227364Sadrian 5065227364Sadrian /* There's no need to hold the TXQ lock here */ 5066227364Sadrian sc->sc_addba_stop(ni, tap); 5067227364Sadrian 5068227364Sadrian /* 5069235749Sadrian * ath_tx_tid_cleanup will resume the TID if possible, otherwise 5070227364Sadrian * it'll set the cleanup flag, and it'll be unpaused once 5071227364Sadrian * things have been cleaned up. 5072227364Sadrian */ 5073235749Sadrian ath_tx_tid_cleanup(sc, an, tid); 5074227364Sadrian} 5075227364Sadrian 5076227364Sadrian/* 5077227364Sadrian * Note: net80211 bar_timeout() doesn't call this function on BAR failure; 5078227364Sadrian * it simply tears down the aggregation session. Ew. 5079227364Sadrian * 5080227364Sadrian * It however will call ieee80211_ampdu_stop() which will call 5081227364Sadrian * ic->ic_addba_stop(). 5082227364Sadrian * 5083227364Sadrian * XXX This uses a hard-coded max BAR count value; the whole 5084227364Sadrian * XXX BAR TX success or failure should be better handled! 5085227364Sadrian */ 5086227364Sadrianvoid 5087227364Sadrianath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5088227364Sadrian int status) 5089227364Sadrian{ 5090227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5091234324Sadrian int tid = tap->txa_tid; 5092227364Sadrian struct ath_node *an = ATH_NODE(ni); 5093227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5094227364Sadrian int attempts = tap->txa_attempts; 5095227364Sadrian 5096235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 5097235676Sadrian "%s: called; tap=%p, atid=%p, txa_tid=%d, atid->tid=%d, status=%d, attempts=%d\n", 5098235491Sadrian __func__, 5099235676Sadrian tap, 5100235676Sadrian atid, 5101235676Sadrian tap->txa_tid, 5102235676Sadrian atid->tid, 5103235491Sadrian status, 5104235491Sadrian attempts); 5105227364Sadrian 5106227364Sadrian /* Note: This may update the BAW details */ 5107227364Sadrian sc->sc_bar_response(ni, tap, status); 5108227364Sadrian 5109227364Sadrian /* Unpause the TID */ 5110227364Sadrian /* 5111227364Sadrian * XXX if this is attempt=50, the TID will be downgraded 5112227364Sadrian * XXX to a non-aggregate session. So we must unpause the 5113227364Sadrian * XXX TID here or it'll never be done. 5114240721Sadrian * 5115240721Sadrian * Also, don't call it if bar_tx/bar_wait are 0; something 5116240721Sadrian * has beaten us to the punch? (XXX figure out what?) 5117227364Sadrian */ 5118227364Sadrian if (status == 0 || attempts == 50) { 5119227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5120240721Sadrian if (atid->bar_tx == 0 || atid->bar_wait == 0) 5121240721Sadrian device_printf(sc->sc_dev, 5122240721Sadrian "%s: huh? bar_tx=%d, bar_wait=%d\n", 5123240721Sadrian __func__, 5124240721Sadrian atid->bar_tx, atid->bar_wait); 5125240721Sadrian else 5126240721Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5127227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5128227364Sadrian } 5129227364Sadrian} 5130227364Sadrian 5131227364Sadrian/* 5132227364Sadrian * This is called whenever the pending ADDBA request times out. 5133227364Sadrian * Unpause and reschedule the TID. 5134227364Sadrian */ 5135227364Sadrianvoid 5136227364Sadrianath_addba_response_timeout(struct ieee80211_node *ni, 5137227364Sadrian struct ieee80211_tx_ampdu *tap) 5138227364Sadrian{ 5139227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5140234324Sadrian int tid = tap->txa_tid; 5141227364Sadrian struct ath_node *an = ATH_NODE(ni); 5142227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5143227364Sadrian 5144227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5145227364Sadrian "%s: called; resuming\n", __func__); 5146227364Sadrian 5147235774Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5148235774Sadrian atid->addba_tx_pending = 0; 5149235774Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5150235774Sadrian 5151227364Sadrian /* Note: This updates the aggregate state to (again) pending */ 5152227364Sadrian sc->sc_addba_response_timeout(ni, tap); 5153227364Sadrian 5154227364Sadrian /* Unpause the TID; which reschedules it */ 5155227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 5156227364Sadrian ath_tx_tid_resume(sc, atid); 5157227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 5158227364Sadrian} 5159238710Sadrian 5160238710Sadrianstatic int 5161238710Sadrianath_legacy_dma_txsetup(struct ath_softc *sc) 5162238710Sadrian{ 5163238710Sadrian 5164238710Sadrian /* nothing new needed */ 5165238710Sadrian return (0); 5166238710Sadrian} 5167238710Sadrian 5168238710Sadrianstatic int 5169238710Sadrianath_legacy_dma_txteardown(struct ath_softc *sc) 5170238710Sadrian{ 5171238710Sadrian 5172238710Sadrian /* nothing new needed */ 5173238710Sadrian return (0); 5174238710Sadrian} 5175238710Sadrian 5176238710Sadrianvoid 5177238710Sadrianath_xmit_setup_legacy(struct ath_softc *sc) 5178238710Sadrian{ 5179238729Sadrian /* 5180238729Sadrian * For now, just set the descriptor length to sizeof(ath_desc); 5181238729Sadrian * worry about extracting the real length out of the HAL later. 5182238729Sadrian */ 5183238729Sadrian sc->sc_tx_desclen = sizeof(struct ath_desc); 5184238729Sadrian sc->sc_tx_statuslen = 0; 5185238729Sadrian sc->sc_tx_nmaps = 1; /* only one buffer per TX desc */ 5186238710Sadrian 5187238710Sadrian sc->sc_tx.xmit_setup = ath_legacy_dma_txsetup; 5188238710Sadrian sc->sc_tx.xmit_teardown = ath_legacy_dma_txteardown; 5189238931Sadrian sc->sc_tx.xmit_attach_comp_func = ath_legacy_attach_comp_func; 5190238930Sadrian 5191238930Sadrian sc->sc_tx.xmit_dma_restart = ath_legacy_tx_dma_restart; 5192238930Sadrian sc->sc_tx.xmit_handoff = ath_legacy_xmit_handoff; 5193239204Sadrian 5194239204Sadrian sc->sc_tx.xmit_drain = ath_legacy_tx_drain; 5195238710Sadrian} 5196