if_ath_tx.c revision 248713
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 248713 2013-03-26 04:47:40Z adrian $"); 33218065Sadrian 34218065Sadrian/* 35218065Sadrian * Driver for the Atheros Wireless LAN controller. 36218065Sadrian * 37218065Sadrian * This software is derived from work of Atsushi Onoe; his contribution 38218065Sadrian * is greatly appreciated. 39218065Sadrian */ 40218065Sadrian 41218065Sadrian#include "opt_inet.h" 42218065Sadrian#include "opt_ath.h" 43218065Sadrian#include "opt_wlan.h" 44218065Sadrian 45218065Sadrian#include <sys/param.h> 46218065Sadrian#include <sys/systm.h> 47218065Sadrian#include <sys/sysctl.h> 48218065Sadrian#include <sys/mbuf.h> 49218065Sadrian#include <sys/malloc.h> 50218065Sadrian#include <sys/lock.h> 51218065Sadrian#include <sys/mutex.h> 52218065Sadrian#include <sys/kernel.h> 53218065Sadrian#include <sys/socket.h> 54218065Sadrian#include <sys/sockio.h> 55218065Sadrian#include <sys/errno.h> 56218065Sadrian#include <sys/callout.h> 57218065Sadrian#include <sys/bus.h> 58218065Sadrian#include <sys/endian.h> 59218065Sadrian#include <sys/kthread.h> 60218065Sadrian#include <sys/taskqueue.h> 61218065Sadrian#include <sys/priv.h> 62218065Sadrian 63218065Sadrian#include <machine/bus.h> 64218065Sadrian 65218065Sadrian#include <net/if.h> 66218065Sadrian#include <net/if_dl.h> 67218065Sadrian#include <net/if_media.h> 68218065Sadrian#include <net/if_types.h> 69218065Sadrian#include <net/if_arp.h> 70218065Sadrian#include <net/ethernet.h> 71218065Sadrian#include <net/if_llc.h> 72218065Sadrian 73218065Sadrian#include <net80211/ieee80211_var.h> 74218065Sadrian#include <net80211/ieee80211_regdomain.h> 75218065Sadrian#ifdef IEEE80211_SUPPORT_SUPERG 76218065Sadrian#include <net80211/ieee80211_superg.h> 77218065Sadrian#endif 78218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 79218065Sadrian#include <net80211/ieee80211_tdma.h> 80218065Sadrian#endif 81227364Sadrian#include <net80211/ieee80211_ht.h> 82218065Sadrian 83218065Sadrian#include <net/bpf.h> 84218065Sadrian 85218065Sadrian#ifdef INET 86218065Sadrian#include <netinet/in.h> 87218065Sadrian#include <netinet/if_ether.h> 88218065Sadrian#endif 89218065Sadrian 90218065Sadrian#include <dev/ath/if_athvar.h> 91218065Sadrian#include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */ 92218065Sadrian#include <dev/ath/ath_hal/ah_diagcodes.h> 93218065Sadrian 94218065Sadrian#include <dev/ath/if_ath_debug.h> 95218065Sadrian 96218065Sadrian#ifdef ATH_TX99_DIAG 97218065Sadrian#include <dev/ath/ath_tx99/ath_tx99.h> 98218065Sadrian#endif 99218065Sadrian 100218065Sadrian#include <dev/ath/if_ath_misc.h> 101218065Sadrian#include <dev/ath/if_ath_tx.h> 102218240Sadrian#include <dev/ath/if_ath_tx_ht.h> 103218065Sadrian 104242782Sadrian#ifdef ATH_DEBUG_ALQ 105242782Sadrian#include <dev/ath/if_ath_alq.h> 106242782Sadrian#endif 107242782Sadrian 108218154Sadrian/* 109227364Sadrian * How many retries to perform in software 110227364Sadrian */ 111227364Sadrian#define SWMAX_RETRIES 10 112227364Sadrian 113240946Sadrian/* 114240946Sadrian * What queue to throw the non-QoS TID traffic into 115240946Sadrian */ 116240946Sadrian#define ATH_NONQOS_TID_AC WME_AC_VO 117240946Sadrian 118241170Sadrian#if 0 119241170Sadrianstatic int ath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an); 120241170Sadrian#endif 121227364Sadrianstatic int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, 122227364Sadrian int tid); 123227364Sadrianstatic int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, 124227364Sadrian int tid); 125236872Sadrianstatic ieee80211_seq ath_tx_tid_seqno_assign(struct ath_softc *sc, 126236872Sadrian struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0); 127227364Sadrianstatic int ath_tx_action_frame_override_queue(struct ath_softc *sc, 128227364Sadrian struct ieee80211_node *ni, struct mbuf *m0, int *tid); 129240639Sadrianstatic struct ath_buf * 130240639Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 131240639Sadrian struct ath_tid *tid, struct ath_buf *bf); 132227364Sadrian 133243162Sadrian#ifdef ATH_DEBUG_ALQ 134243162Sadrianvoid 135243162Sadrianath_tx_alq_post(struct ath_softc *sc, struct ath_buf *bf_first) 136243162Sadrian{ 137243162Sadrian struct ath_buf *bf; 138243162Sadrian int i, n; 139243162Sadrian const char *ds; 140243162Sadrian 141243162Sadrian /* XXX we should skip out early if debugging isn't enabled! */ 142243162Sadrian bf = bf_first; 143243162Sadrian 144243162Sadrian while (bf != NULL) { 145243162Sadrian /* XXX should ensure bf_nseg > 0! */ 146243162Sadrian if (bf->bf_nseg == 0) 147243162Sadrian break; 148243162Sadrian n = ((bf->bf_nseg - 1) / sc->sc_tx_nmaps) + 1; 149243162Sadrian for (i = 0, ds = (const char *) bf->bf_desc; 150243162Sadrian i < n; 151243162Sadrian i++, ds += sc->sc_tx_desclen) { 152243162Sadrian if_ath_alq_post(&sc->sc_alq, 153243162Sadrian ATH_ALQ_EDMA_TXDESC, 154243162Sadrian sc->sc_tx_desclen, 155243162Sadrian ds); 156243162Sadrian } 157243162Sadrian bf = bf->bf_next; 158243162Sadrian } 159243162Sadrian} 160243162Sadrian#endif /* ATH_DEBUG_ALQ */ 161243162Sadrian 162227364Sadrian/* 163218154Sadrian * Whether to use the 11n rate scenario functions or not 164218154Sadrian */ 165218154Sadrianstatic inline int 166218154Sadrianath_tx_is_11n(struct ath_softc *sc) 167218154Sadrian{ 168239198Sadrian return ((sc->sc_ah->ah_magic == 0x20065416) || 169239198Sadrian (sc->sc_ah->ah_magic == 0x19741014)); 170218154Sadrian} 171218154Sadrian 172227364Sadrian/* 173227364Sadrian * Obtain the current TID from the given frame. 174227364Sadrian * 175227364Sadrian * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.) 176227364Sadrian * This has implications for which AC/priority the packet is placed 177227364Sadrian * in. 178227364Sadrian */ 179227364Sadrianstatic int 180227364Sadrianath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0) 181227364Sadrian{ 182227364Sadrian const struct ieee80211_frame *wh; 183227364Sadrian int pri = M_WME_GETAC(m0); 184227364Sadrian 185227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 186227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 187227364Sadrian return IEEE80211_NONQOS_TID; 188227364Sadrian else 189227364Sadrian return WME_AC_TO_TID(pri); 190227364Sadrian} 191227364Sadrian 192240639Sadrianstatic void 193240639Sadrianath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) 194240639Sadrian{ 195240639Sadrian struct ieee80211_frame *wh; 196240639Sadrian 197240639Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 198240639Sadrian /* Only update/resync if needed */ 199240639Sadrian if (bf->bf_state.bfs_isretried == 0) { 200240639Sadrian wh->i_fc[1] |= IEEE80211_FC1_RETRY; 201240639Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 202240639Sadrian BUS_DMASYNC_PREWRITE); 203240639Sadrian } 204240639Sadrian bf->bf_state.bfs_isretried = 1; 205240639Sadrian bf->bf_state.bfs_retries ++; 206240639Sadrian} 207240639Sadrian 208227364Sadrian/* 209227364Sadrian * Determine what the correct AC queue for the given frame 210227364Sadrian * should be. 211227364Sadrian * 212227364Sadrian * This code assumes that the TIDs map consistently to 213227364Sadrian * the underlying hardware (or software) ath_txq. 214227364Sadrian * Since the sender may try to set an AC which is 215227364Sadrian * arbitrary, non-QoS TIDs may end up being put on 216227364Sadrian * completely different ACs. There's no way to put a 217227364Sadrian * TID into multiple ath_txq's for scheduling, so 218227364Sadrian * for now we override the AC/TXQ selection and set 219227364Sadrian * non-QOS TID frames into the BE queue. 220227364Sadrian * 221227364Sadrian * This may be completely incorrect - specifically, 222227364Sadrian * some management frames may end up out of order 223227364Sadrian * compared to the QoS traffic they're controlling. 224227364Sadrian * I'll look into this later. 225227364Sadrian */ 226227364Sadrianstatic int 227227364Sadrianath_tx_getac(struct ath_softc *sc, const struct mbuf *m0) 228227364Sadrian{ 229227364Sadrian const struct ieee80211_frame *wh; 230227364Sadrian int pri = M_WME_GETAC(m0); 231227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 232227364Sadrian if (IEEE80211_QOS_HAS_SEQ(wh)) 233227364Sadrian return pri; 234227364Sadrian 235240946Sadrian return ATH_NONQOS_TID_AC; 236227364Sadrian} 237227364Sadrian 238218065Sadrianvoid 239218065Sadrianath_txfrag_cleanup(struct ath_softc *sc, 240218065Sadrian ath_bufhead *frags, struct ieee80211_node *ni) 241218065Sadrian{ 242218065Sadrian struct ath_buf *bf, *next; 243218065Sadrian 244218065Sadrian ATH_TXBUF_LOCK_ASSERT(sc); 245218065Sadrian 246227344Sadrian TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) { 247218065Sadrian /* NB: bf assumed clean */ 248227344Sadrian TAILQ_REMOVE(frags, bf, bf_list); 249236993Sadrian ath_returnbuf_head(sc, bf); 250218065Sadrian ieee80211_node_decref(ni); 251218065Sadrian } 252218065Sadrian} 253218065Sadrian 254218065Sadrian/* 255218065Sadrian * Setup xmit of a fragmented frame. Allocate a buffer 256218065Sadrian * for each frag and bump the node reference count to 257218065Sadrian * reflect the held reference to be setup by ath_tx_start. 258218065Sadrian */ 259218065Sadrianint 260218065Sadrianath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags, 261218065Sadrian struct mbuf *m0, struct ieee80211_node *ni) 262218065Sadrian{ 263218065Sadrian struct mbuf *m; 264218065Sadrian struct ath_buf *bf; 265218065Sadrian 266218065Sadrian ATH_TXBUF_LOCK(sc); 267218065Sadrian for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) { 268237000Sadrian /* XXX non-management? */ 269237000Sadrian bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL); 270218065Sadrian if (bf == NULL) { /* out of buffers, cleanup */ 271234009Sadrian device_printf(sc->sc_dev, "%s: no buffer?\n", 272234009Sadrian __func__); 273218065Sadrian ath_txfrag_cleanup(sc, frags, ni); 274218065Sadrian break; 275218065Sadrian } 276218065Sadrian ieee80211_node_incref(ni); 277227344Sadrian TAILQ_INSERT_TAIL(frags, bf, bf_list); 278218065Sadrian } 279218065Sadrian ATH_TXBUF_UNLOCK(sc); 280218065Sadrian 281227344Sadrian return !TAILQ_EMPTY(frags); 282218065Sadrian} 283218065Sadrian 284218065Sadrian/* 285218065Sadrian * Reclaim mbuf resources. For fragmented frames we 286218065Sadrian * need to claim each frag chained with m_nextpkt. 287218065Sadrian */ 288218065Sadrianvoid 289218065Sadrianath_freetx(struct mbuf *m) 290218065Sadrian{ 291218065Sadrian struct mbuf *next; 292218065Sadrian 293218065Sadrian do { 294218065Sadrian next = m->m_nextpkt; 295218065Sadrian m->m_nextpkt = NULL; 296218065Sadrian m_freem(m); 297218065Sadrian } while ((m = next) != NULL); 298218065Sadrian} 299218065Sadrian 300218065Sadrianstatic int 301218065Sadrianath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0) 302218065Sadrian{ 303218065Sadrian struct mbuf *m; 304218065Sadrian int error; 305218065Sadrian 306218065Sadrian /* 307218065Sadrian * Load the DMA map so any coalescing is done. This 308218065Sadrian * also calculates the number of descriptors we need. 309218065Sadrian */ 310218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 311218065Sadrian bf->bf_segs, &bf->bf_nseg, 312218065Sadrian BUS_DMA_NOWAIT); 313218065Sadrian if (error == EFBIG) { 314218065Sadrian /* XXX packet requires too many descriptors */ 315218065Sadrian bf->bf_nseg = ATH_TXDESC+1; 316218065Sadrian } else if (error != 0) { 317218065Sadrian sc->sc_stats.ast_tx_busdma++; 318218065Sadrian ath_freetx(m0); 319218065Sadrian return error; 320218065Sadrian } 321218065Sadrian /* 322218065Sadrian * Discard null packets and check for packets that 323218065Sadrian * require too many TX descriptors. We try to convert 324218065Sadrian * the latter to a cluster. 325218065Sadrian */ 326218065Sadrian if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ 327218065Sadrian sc->sc_stats.ast_tx_linear++; 328243857Sglebius m = m_collapse(m0, M_NOWAIT, ATH_TXDESC); 329218065Sadrian if (m == NULL) { 330218065Sadrian ath_freetx(m0); 331218065Sadrian sc->sc_stats.ast_tx_nombuf++; 332218065Sadrian return ENOMEM; 333218065Sadrian } 334218065Sadrian m0 = m; 335218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 336218065Sadrian bf->bf_segs, &bf->bf_nseg, 337218065Sadrian BUS_DMA_NOWAIT); 338218065Sadrian if (error != 0) { 339218065Sadrian sc->sc_stats.ast_tx_busdma++; 340218065Sadrian ath_freetx(m0); 341218065Sadrian return error; 342218065Sadrian } 343218065Sadrian KASSERT(bf->bf_nseg <= ATH_TXDESC, 344218065Sadrian ("too many segments after defrag; nseg %u", bf->bf_nseg)); 345218065Sadrian } else if (bf->bf_nseg == 0) { /* null packet, discard */ 346218065Sadrian sc->sc_stats.ast_tx_nodata++; 347218065Sadrian ath_freetx(m0); 348218065Sadrian return EIO; 349218065Sadrian } 350218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n", 351218065Sadrian __func__, m0, m0->m_pkthdr.len); 352218065Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 353218065Sadrian bf->bf_m = m0; 354218065Sadrian 355218065Sadrian return 0; 356218065Sadrian} 357218065Sadrian 358227360Sadrian/* 359242656Sadrian * Chain together segments+descriptors for a frame - 11n or otherwise. 360242656Sadrian * 361242656Sadrian * For aggregates, this is called on each frame in the aggregate. 362227360Sadrian */ 363218065Sadrianstatic void 364242656Sadrianath_tx_chaindesclist(struct ath_softc *sc, struct ath_desc *ds0, 365242656Sadrian struct ath_buf *bf, int is_aggr, int is_first_subframe, 366242656Sadrian int is_last_subframe) 367218065Sadrian{ 368218065Sadrian struct ath_hal *ah = sc->sc_ah; 369242656Sadrian char *ds; 370239290Sadrian int i, bp, dsp; 371239051Sadrian HAL_DMA_ADDR bufAddrList[4]; 372239051Sadrian uint32_t segLenList[4]; 373239290Sadrian int numTxMaps = 1; 374239380Sadrian int isFirstDesc = 1; 375239051Sadrian 376238708Sadrian /* 377238708Sadrian * XXX There's txdma and txdma_mgmt; the descriptor 378238708Sadrian * sizes must match. 379238708Sadrian */ 380238708Sadrian struct ath_descdma *dd = &sc->sc_txdma; 381218065Sadrian 382218065Sadrian /* 383218065Sadrian * Fillin the remainder of the descriptor info. 384218065Sadrian */ 385239290Sadrian 386239290Sadrian /* 387248527Sadrian * We need the number of TX data pointers in each descriptor. 388248527Sadrian * EDMA and later chips support 4 TX buffers per descriptor; 389248527Sadrian * previous chips just support one. 390239290Sadrian */ 391248527Sadrian numTxMaps = sc->sc_tx_nmaps; 392239290Sadrian 393239290Sadrian /* 394239290Sadrian * For EDMA and later chips ensure the TX map is fully populated 395239290Sadrian * before advancing to the next descriptor. 396239290Sadrian */ 397242656Sadrian ds = (char *) bf->bf_desc; 398239290Sadrian bp = dsp = 0; 399239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 400239290Sadrian bzero(segLenList, sizeof(segLenList)); 401239290Sadrian for (i = 0; i < bf->bf_nseg; i++) { 402239290Sadrian bufAddrList[bp] = bf->bf_segs[i].ds_addr; 403239290Sadrian segLenList[bp] = bf->bf_segs[i].ds_len; 404239290Sadrian bp++; 405239051Sadrian 406239290Sadrian /* 407239290Sadrian * Go to the next segment if this isn't the last segment 408239290Sadrian * and there's space in the current TX map. 409239290Sadrian */ 410239290Sadrian if ((i != bf->bf_nseg - 1) && (bp < numTxMaps)) 411239290Sadrian continue; 412239051Sadrian 413239290Sadrian /* 414239290Sadrian * Last segment or we're out of buffer pointers. 415239290Sadrian */ 416239290Sadrian bp = 0; 417239290Sadrian 418218065Sadrian if (i == bf->bf_nseg - 1) 419239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 0); 420218065Sadrian else 421239409Sadrian ath_hal_settxdesclink(ah, (struct ath_desc *) ds, 422239290Sadrian bf->bf_daddr + dd->dd_descsize * (dsp + 1)); 423239051Sadrian 424239051Sadrian /* 425244109Sadrian * XXX This assumes that bfs_txq is the actual destination 426244109Sadrian * hardware queue at this point. It may not have been 427244109Sadrian * assigned, it may actually be pointing to the multicast 428244109Sadrian * software TXQ id. These must be fixed! 429239051Sadrian */ 430239409Sadrian ath_hal_filltxdesc(ah, (struct ath_desc *) ds 431239051Sadrian , bufAddrList 432239051Sadrian , segLenList 433239290Sadrian , bf->bf_descid /* XXX desc id */ 434244109Sadrian , bf->bf_state.bfs_tx_queue 435239380Sadrian , isFirstDesc /* first segment */ 436218065Sadrian , i == bf->bf_nseg - 1 /* last segment */ 437239409Sadrian , (struct ath_desc *) ds0 /* first descriptor */ 438218065Sadrian ); 439240255Sadrian 440242656Sadrian /* 441242656Sadrian * Make sure the 11n aggregate fields are cleared. 442242656Sadrian * 443242656Sadrian * XXX TODO: this doesn't need to be called for 444242656Sadrian * aggregate frames; as it'll be called on all 445242656Sadrian * sub-frames. Since the descriptors are in 446242656Sadrian * non-cacheable memory, this leads to some 447242656Sadrian * rather slow writes on MIPS/ARM platforms. 448242656Sadrian */ 449240255Sadrian if (ath_tx_is_11n(sc)) 450240333Sadrian ath_hal_clr11n_aggr(sc->sc_ah, (struct ath_desc *) ds); 451240255Sadrian 452242656Sadrian /* 453242656Sadrian * If 11n is enabled, set it up as if it's an aggregate 454242656Sadrian * frame. 455242656Sadrian */ 456242656Sadrian if (is_last_subframe) { 457242656Sadrian ath_hal_set11n_aggr_last(sc->sc_ah, 458242656Sadrian (struct ath_desc *) ds); 459242656Sadrian } else if (is_aggr) { 460242656Sadrian /* 461242656Sadrian * This clears the aggrlen field; so 462242656Sadrian * the caller needs to call set_aggr_first()! 463242656Sadrian * 464242656Sadrian * XXX TODO: don't call this for the first 465242656Sadrian * descriptor in the first frame in an 466242656Sadrian * aggregate! 467242656Sadrian */ 468242656Sadrian ath_hal_set11n_aggr_middle(sc->sc_ah, 469242656Sadrian (struct ath_desc *) ds, 470242656Sadrian bf->bf_state.bfs_ndelim); 471242656Sadrian } 472239380Sadrian isFirstDesc = 0; 473239409Sadrian bf->bf_lastds = (struct ath_desc *) ds; 474239290Sadrian 475239290Sadrian /* 476239290Sadrian * Don't forget to skip to the next descriptor. 477239290Sadrian */ 478239409Sadrian ds += sc->sc_tx_desclen; 479239290Sadrian dsp++; 480239290Sadrian 481239290Sadrian /* 482239290Sadrian * .. and don't forget to blank these out! 483239290Sadrian */ 484239290Sadrian bzero(bufAddrList, sizeof(bufAddrList)); 485239290Sadrian bzero(segLenList, sizeof(segLenList)); 486218065Sadrian } 487233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 488218154Sadrian} 489218154Sadrian 490227364Sadrian/* 491238947Sadrian * Set the rate control fields in the given descriptor based on 492238947Sadrian * the bf_state fields and node state. 493238947Sadrian * 494238947Sadrian * The bfs fields should already be set with the relevant rate 495238947Sadrian * control information, including whether MRR is to be enabled. 496238947Sadrian * 497238947Sadrian * Since the FreeBSD HAL currently sets up the first TX rate 498238947Sadrian * in ath_hal_setuptxdesc(), this will setup the MRR 499238947Sadrian * conditionally for the pre-11n chips, and call ath_buf_set_rate 500238947Sadrian * unconditionally for 11n chips. These require the 11n rate 501238947Sadrian * scenario to be set if MCS rates are enabled, so it's easier 502238947Sadrian * to just always call it. The caller can then only set rates 2, 3 503238947Sadrian * and 4 if multi-rate retry is needed. 504238947Sadrian */ 505238947Sadrianstatic void 506238947Sadrianath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni, 507238947Sadrian struct ath_buf *bf) 508238947Sadrian{ 509238947Sadrian struct ath_rc_series *rc = bf->bf_state.bfs_rc; 510238947Sadrian 511238947Sadrian /* If mrr is disabled, blank tries 1, 2, 3 */ 512238947Sadrian if (! bf->bf_state.bfs_ismrr) 513238947Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 514238947Sadrian 515243647Sadrian#if 0 516238947Sadrian /* 517243647Sadrian * If NOACK is set, just set ntries=1. 518243647Sadrian */ 519243647Sadrian else if (bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) { 520243647Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 521243647Sadrian rc[0].tries = 1; 522243647Sadrian } 523243647Sadrian#endif 524243647Sadrian 525243647Sadrian /* 526238947Sadrian * Always call - that way a retried descriptor will 527238947Sadrian * have the MRR fields overwritten. 528238947Sadrian * 529238947Sadrian * XXX TODO: see if this is really needed - setting up 530238947Sadrian * the first descriptor should set the MRR fields to 0 531238947Sadrian * for us anyway. 532238947Sadrian */ 533238947Sadrian if (ath_tx_is_11n(sc)) { 534238947Sadrian ath_buf_set_rate(sc, ni, bf); 535238947Sadrian } else { 536238947Sadrian ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc 537238947Sadrian , rc[1].ratecode, rc[1].tries 538238947Sadrian , rc[2].ratecode, rc[2].tries 539238947Sadrian , rc[3].ratecode, rc[3].tries 540238947Sadrian ); 541238947Sadrian } 542238947Sadrian} 543238947Sadrian 544238947Sadrian/* 545227364Sadrian * Setup segments+descriptors for an 11n aggregate. 546227364Sadrian * bf_first is the first buffer in the aggregate. 547227364Sadrian * The descriptor list must already been linked together using 548227364Sadrian * bf->bf_next. 549227364Sadrian */ 550227364Sadrianstatic void 551227364Sadrianath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first) 552227364Sadrian{ 553227364Sadrian struct ath_buf *bf, *bf_prev = NULL; 554242656Sadrian struct ath_desc *ds0 = bf_first->bf_desc; 555227364Sadrian 556227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n", 557227364Sadrian __func__, bf_first->bf_state.bfs_nframes, 558227364Sadrian bf_first->bf_state.bfs_al); 559227364Sadrian 560242951Sadrian bf = bf_first; 561242951Sadrian 562242951Sadrian if (bf->bf_state.bfs_txrate0 == 0) 563242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, txrate0=%d\n", 564242951Sadrian __func__, bf, 0); 565242951Sadrian if (bf->bf_state.bfs_rc[0].ratecode == 0) 566242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, rix0=%d\n", 567242951Sadrian __func__, bf, 0); 568242951Sadrian 569227364Sadrian /* 570242656Sadrian * Setup all descriptors of all subframes - this will 571242656Sadrian * call ath_hal_set11naggrmiddle() on every frame. 572227364Sadrian */ 573227364Sadrian while (bf != NULL) { 574227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 575227364Sadrian "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n", 576227364Sadrian __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen, 577227364Sadrian SEQNO(bf->bf_state.bfs_seqno)); 578227364Sadrian 579242656Sadrian /* 580242656Sadrian * Setup the initial fields for the first descriptor - all 581242656Sadrian * the non-11n specific stuff. 582242656Sadrian */ 583242656Sadrian ath_hal_setuptxdesc(sc->sc_ah, bf->bf_desc 584242656Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 585242656Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 586242656Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 587242656Sadrian , bf->bf_state.bfs_txpower /* txpower */ 588242656Sadrian , bf->bf_state.bfs_txrate0 589242656Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 590242656Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 591242656Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 592242656Sadrian , bf->bf_state.bfs_txflags | HAL_TXDESC_INTREQ /* flags */ 593242656Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 594242656Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 595242656Sadrian ); 596227364Sadrian 597227364Sadrian /* 598242656Sadrian * First descriptor? Setup the rate control and initial 599242656Sadrian * aggregate header information. 600242656Sadrian */ 601242656Sadrian if (bf == bf_first) { 602242656Sadrian /* 603242656Sadrian * setup first desc with rate and aggr info 604242656Sadrian */ 605242656Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 606242656Sadrian } 607242656Sadrian 608242656Sadrian /* 609242656Sadrian * Setup the descriptors for a multi-descriptor frame. 610242656Sadrian * This is both aggregate and non-aggregate aware. 611242656Sadrian */ 612242656Sadrian ath_tx_chaindesclist(sc, ds0, bf, 613242656Sadrian 1, /* is_aggr */ 614242656Sadrian !! (bf == bf_first), /* is_first_subframe */ 615242656Sadrian !! (bf->bf_next == NULL) /* is_last_subframe */ 616242656Sadrian ); 617242656Sadrian 618242656Sadrian if (bf == bf_first) { 619242656Sadrian /* 620242656Sadrian * Initialise the first 11n aggregate with the 621242656Sadrian * aggregate length and aggregate enable bits. 622242656Sadrian */ 623242656Sadrian ath_hal_set11n_aggr_first(sc->sc_ah, 624242656Sadrian ds0, 625242656Sadrian bf->bf_state.bfs_al, 626242656Sadrian bf->bf_state.bfs_ndelim); 627242656Sadrian } 628242656Sadrian 629242656Sadrian /* 630227364Sadrian * Link the last descriptor of the previous frame 631227364Sadrian * to the beginning descriptor of this frame. 632227364Sadrian */ 633227364Sadrian if (bf_prev != NULL) 634238609Sadrian ath_hal_settxdesclink(sc->sc_ah, bf_prev->bf_lastds, 635238609Sadrian bf->bf_daddr); 636227364Sadrian 637227364Sadrian /* Save a copy so we can link the next descriptor in */ 638227364Sadrian bf_prev = bf; 639227364Sadrian bf = bf->bf_next; 640227364Sadrian } 641227364Sadrian 642227364Sadrian /* 643227364Sadrian * Set the first descriptor bf_lastds field to point to 644227364Sadrian * the last descriptor in the last subframe, that's where 645227364Sadrian * the status update will occur. 646227364Sadrian */ 647227364Sadrian bf_first->bf_lastds = bf_prev->bf_lastds; 648227364Sadrian 649227364Sadrian /* 650227364Sadrian * And bf_last in the first descriptor points to the end of 651227364Sadrian * the aggregate list. 652227364Sadrian */ 653227364Sadrian bf_first->bf_last = bf_prev; 654227364Sadrian 655243047Sadrian /* 656243047Sadrian * For non-AR9300 NICs, which require the rate control 657243047Sadrian * in the final descriptor - let's set that up now. 658243047Sadrian * 659243047Sadrian * This is because the filltxdesc() HAL call doesn't 660243047Sadrian * populate the last segment with rate control information 661243047Sadrian * if firstSeg is also true. For non-aggregate frames 662243047Sadrian * that is fine, as the first frame already has rate control 663243047Sadrian * info. But if the last frame in an aggregate has one 664243047Sadrian * descriptor, both firstseg and lastseg will be true and 665243047Sadrian * the rate info isn't copied. 666243047Sadrian * 667243047Sadrian * This is inefficient on MIPS/ARM platforms that have 668243047Sadrian * non-cachable memory for TX descriptors, but we'll just 669243047Sadrian * make do for now. 670243047Sadrian * 671243047Sadrian * As to why the rate table is stashed in the last descriptor 672243047Sadrian * rather than the first descriptor? Because proctxdesc() 673243047Sadrian * is called on the final descriptor in an MPDU or A-MPDU - 674243047Sadrian * ie, the one that gets updated by the hardware upon 675243047Sadrian * completion. That way proctxdesc() doesn't need to know 676243047Sadrian * about the first _and_ last TX descriptor. 677243047Sadrian */ 678243047Sadrian ath_hal_setuplasttxdesc(sc->sc_ah, bf_prev->bf_lastds, ds0); 679243047Sadrian 680227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__); 681227364Sadrian} 682227364Sadrian 683239051Sadrian/* 684239051Sadrian * Hand-off a frame to the multicast TX queue. 685239051Sadrian * 686239051Sadrian * This is a software TXQ which will be appended to the CAB queue 687239051Sadrian * during the beacon setup code. 688239051Sadrian * 689239051Sadrian * XXX TODO: since the AR9300 EDMA TX queue support wants the QCU ID 690244109Sadrian * as part of the TX descriptor, bf_state.bfs_tx_queue must be updated 691239051Sadrian * with the actual hardware txq, or all of this will fall apart. 692239051Sadrian * 693239051Sadrian * XXX It may not be a bad idea to just stuff the QCU ID into bf_state 694244109Sadrian * and retire bfs_tx_queue; then make sure the CABQ QCU ID is populated 695239051Sadrian * correctly. 696239051Sadrian */ 697227364Sadrianstatic void 698227364Sadrianath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq, 699227364Sadrian struct ath_buf *bf) 700227364Sadrian{ 701243786Sadrian ATH_TX_LOCK_ASSERT(sc); 702243786Sadrian 703227364Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 704227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 705248676Sadrian 706248676Sadrian ATH_TXQ_LOCK(txq); 707248713Sadrian if (ATH_TXQ_LAST(txq, axq_q_s) != NULL) { 708248713Sadrian struct ath_buf *bf_last = ATH_TXQ_LAST(txq, axq_q_s); 709227364Sadrian struct ieee80211_frame *wh; 710227364Sadrian 711227364Sadrian /* mark previous frame */ 712248713Sadrian wh = mtod(bf_last->bf_m, struct ieee80211_frame *); 713227364Sadrian wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; 714248713Sadrian bus_dmamap_sync(sc->sc_dmat, bf_last->bf_dmamap, 715227364Sadrian BUS_DMASYNC_PREWRITE); 716227364Sadrian 717227364Sadrian /* link descriptor */ 718248713Sadrian ath_hal_settxdesclink(sc->sc_ah, 719248713Sadrian bf_last->bf_lastds, 720248713Sadrian bf->bf_daddr); 721227364Sadrian } 722227364Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 723238609Sadrian ath_hal_gettxdesclinkptr(sc->sc_ah, bf->bf_lastds, &txq->axq_link); 724248671Sadrian ATH_TXQ_UNLOCK(txq); 725227364Sadrian} 726227364Sadrian 727227364Sadrian/* 728227364Sadrian * Hand-off packet to a hardware queue. 729227364Sadrian */ 730227364Sadrianstatic void 731229949Sadrianath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq, 732229949Sadrian struct ath_buf *bf) 733227364Sadrian{ 734227364Sadrian struct ath_hal *ah = sc->sc_ah; 735227364Sadrian 736227364Sadrian /* 737218065Sadrian * Insert the frame on the outbound list and pass it on 738218065Sadrian * to the hardware. Multicast frames buffered for power 739218065Sadrian * save stations and transmit from the CAB queue are stored 740218065Sadrian * on a s/w only queue and loaded on to the CAB queue in 741218065Sadrian * the SWBA handler since frames only go out on DTIM and 742218065Sadrian * to avoid possible races. 743218065Sadrian */ 744243786Sadrian ATH_TX_LOCK_ASSERT(sc); 745218065Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 746227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 747227364Sadrian KASSERT(txq->axq_qnum != ATH_TXQ_SWQ, 748227364Sadrian ("ath_tx_handoff_hw called for mcast queue")); 749227364Sadrian 750227651Sadrian#if 0 751227651Sadrian /* 752227651Sadrian * This causes a LOR. Find out where the PCU lock is being 753227651Sadrian * held whilst the TXQ lock is grabbed - that shouldn't 754227651Sadrian * be occuring. 755227651Sadrian */ 756227651Sadrian ATH_PCU_LOCK(sc); 757227651Sadrian if (sc->sc_inreset_cnt) { 758227651Sadrian ATH_PCU_UNLOCK(sc); 759227651Sadrian DPRINTF(sc, ATH_DEBUG_RESET, 760227651Sadrian "%s: called with sc_in_reset != 0\n", 761227651Sadrian __func__); 762227651Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 763227651Sadrian "%s: queued: TXDP[%u] = %p (%p) depth %d\n", 764227651Sadrian __func__, txq->axq_qnum, 765227651Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 766227651Sadrian txq->axq_depth); 767227651Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 768227651Sadrian if (bf->bf_state.bfs_aggr) 769227651Sadrian txq->axq_aggr_depth++; 770227651Sadrian /* 771227651Sadrian * There's no need to update axq_link; the hardware 772227651Sadrian * is in reset and once the reset is complete, any 773227651Sadrian * non-empty queues will simply have DMA restarted. 774227651Sadrian */ 775227651Sadrian return; 776227651Sadrian } 777227651Sadrian ATH_PCU_UNLOCK(sc); 778227651Sadrian#endif 779227651Sadrian 780227364Sadrian /* For now, so not to generate whitespace diffs */ 781227364Sadrian if (1) { 782248671Sadrian ATH_TXQ_LOCK(txq); 783218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 784218065Sadrian int qbusy; 785218065Sadrian 786218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 787218065Sadrian qbusy = ath_hal_txqenabled(ah, txq->axq_qnum); 788240899Sadrian 789240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 4, 790240899Sadrian "ath_tx_handoff: txq=%u, add bf=%p, qbusy=%d, depth=%d", 791240899Sadrian txq->axq_qnum, bf, qbusy, txq->axq_depth); 792218065Sadrian if (txq->axq_link == NULL) { 793218065Sadrian /* 794218065Sadrian * Be careful writing the address to TXDP. If 795218065Sadrian * the tx q is enabled then this write will be 796218065Sadrian * ignored. Normally this is not an issue but 797218065Sadrian * when tdma is in use and the q is beacon gated 798218065Sadrian * this race can occur. If the q is busy then 799218065Sadrian * defer the work to later--either when another 800218065Sadrian * packet comes along or when we prepare a beacon 801218065Sadrian * frame at SWBA. 802218065Sadrian */ 803218065Sadrian if (!qbusy) { 804229949Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 805229949Sadrian bf->bf_daddr); 806218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 807218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 808240899Sadrian "%s: TXDP[%u] = %p (%p) lastds=%p depth %d\n", 809218065Sadrian __func__, txq->axq_qnum, 810218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 811240899Sadrian bf->bf_lastds, 812218065Sadrian txq->axq_depth); 813240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 814240899Sadrian "ath_tx_handoff: TXDP[%u] = %p (%p) " 815240899Sadrian "lastds=%p depth %d", 816240899Sadrian txq->axq_qnum, 817240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 818240899Sadrian bf->bf_lastds, 819240899Sadrian txq->axq_depth); 820218065Sadrian } else { 821218065Sadrian txq->axq_flags |= ATH_TXQ_PUTPENDING; 822218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 823218065Sadrian "%s: Q%u busy, defer enable\n", __func__, 824218065Sadrian txq->axq_qnum); 825240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 0, "defer enable"); 826218065Sadrian } 827218065Sadrian } else { 828218065Sadrian *txq->axq_link = bf->bf_daddr; 829218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 830218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 831218065Sadrian txq->axq_qnum, txq->axq_link, 832229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 833229949Sadrian txq->axq_depth); 834240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 835240899Sadrian "ath_tx_handoff: link[%u](%p)=%p (%p) lastds=%p", 836240899Sadrian txq->axq_qnum, txq->axq_link, 837240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 838240899Sadrian bf->bf_lastds); 839240899Sadrian 840218065Sadrian if ((txq->axq_flags & ATH_TXQ_PUTPENDING) && !qbusy) { 841218065Sadrian /* 842218065Sadrian * The q was busy when we previously tried 843218065Sadrian * to write the address of the first buffer 844218065Sadrian * in the chain. Since it's not busy now 845218065Sadrian * handle this chore. We are certain the 846218065Sadrian * buffer at the front is the right one since 847218065Sadrian * axq_link is NULL only when the buffer list 848218065Sadrian * is/was empty. 849218065Sadrian */ 850218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 851227344Sadrian TAILQ_FIRST(&txq->axq_q)->bf_daddr); 852218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 853218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 854218065Sadrian "%s: Q%u restarted\n", __func__, 855218065Sadrian txq->axq_qnum); 856240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 4, 857240899Sadrian "ath_tx_handoff: txq[%d] restarted, bf=%p " 858240899Sadrian "daddr=%p ds=%p", 859240899Sadrian txq->axq_qnum, 860240899Sadrian bf, 861240899Sadrian (caddr_t)bf->bf_daddr, 862240899Sadrian bf->bf_desc); 863218065Sadrian } 864218065Sadrian } 865218065Sadrian#else 866218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 867241500Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, 868241500Sadrian "ath_tx_handoff: non-tdma: txq=%u, add bf=%p " 869240899Sadrian "depth=%d", 870240899Sadrian txq->axq_qnum, 871240899Sadrian bf, 872240899Sadrian txq->axq_depth); 873218065Sadrian if (txq->axq_link == NULL) { 874218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 875218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 876218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 877218065Sadrian __func__, txq->axq_qnum, 878218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 879218065Sadrian txq->axq_depth); 880240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 881240899Sadrian "ath_tx_handoff: non-tdma: TXDP[%u] = %p (%p) " 882240899Sadrian "lastds=%p depth %d", 883240899Sadrian txq->axq_qnum, 884240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 885240899Sadrian bf->bf_lastds, 886240899Sadrian txq->axq_depth); 887240899Sadrian 888218065Sadrian } else { 889218065Sadrian *txq->axq_link = bf->bf_daddr; 890218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 891218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 892218065Sadrian txq->axq_qnum, txq->axq_link, 893229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 894229949Sadrian txq->axq_depth); 895240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 5, 896240899Sadrian "ath_tx_handoff: non-tdma: link[%u](%p)=%p (%p) " 897240899Sadrian "lastds=%d", 898240899Sadrian txq->axq_qnum, txq->axq_link, 899240899Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 900240899Sadrian bf->bf_lastds); 901240899Sadrian 902218065Sadrian } 903218065Sadrian#endif /* IEEE80211_SUPPORT_TDMA */ 904227360Sadrian if (bf->bf_state.bfs_aggr) 905227360Sadrian txq->axq_aggr_depth++; 906238609Sadrian ath_hal_gettxdesclinkptr(ah, bf->bf_lastds, &txq->axq_link); 907218065Sadrian ath_hal_txstart(ah, txq->axq_qnum); 908248671Sadrian ATH_TXQ_UNLOCK(txq); 909240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 1, 910240899Sadrian "ath_tx_handoff: txq=%u, txstart", txq->axq_qnum); 911227364Sadrian } 912227364Sadrian} 913218065Sadrian 914227364Sadrian/* 915227364Sadrian * Restart TX DMA for the given TXQ. 916227364Sadrian * 917227364Sadrian * This must be called whether the queue is empty or not. 918227364Sadrian */ 919238930Sadrianstatic void 920238930Sadrianath_legacy_tx_dma_restart(struct ath_softc *sc, struct ath_txq *txq) 921227364Sadrian{ 922227364Sadrian struct ath_hal *ah = sc->sc_ah; 923232707Sadrian struct ath_buf *bf, *bf_last; 924218065Sadrian 925248671Sadrian ATH_TXQ_LOCK_ASSERT(txq); 926227364Sadrian /* This is always going to be cleared, empty or not */ 927227364Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 928227364Sadrian 929232707Sadrian /* XXX make this ATH_TXQ_FIRST */ 930227364Sadrian bf = TAILQ_FIRST(&txq->axq_q); 931232707Sadrian bf_last = ATH_TXQ_LAST(txq, axq_q_s); 932232707Sadrian 933227364Sadrian if (bf == NULL) 934227364Sadrian return; 935227364Sadrian 936227364Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 937239120Sadrian ath_hal_gettxdesclinkptr(ah, bf_last->bf_lastds, &txq->axq_link); 938227364Sadrian ath_hal_txstart(ah, txq->axq_qnum); 939218065Sadrian} 940218065Sadrian 941227364Sadrian/* 942227364Sadrian * Hand off a packet to the hardware (or mcast queue.) 943227364Sadrian * 944227364Sadrian * The relevant hardware txq should be locked. 945227364Sadrian */ 946227364Sadrianstatic void 947238930Sadrianath_legacy_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq, 948238930Sadrian struct ath_buf *bf) 949227364Sadrian{ 950243786Sadrian ATH_TX_LOCK_ASSERT(sc); 951227364Sadrian 952243162Sadrian#ifdef ATH_DEBUG_ALQ 953243162Sadrian if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC)) 954243162Sadrian ath_tx_alq_post(sc, bf); 955243162Sadrian#endif 956243162Sadrian 957227364Sadrian if (txq->axq_qnum == ATH_TXQ_SWQ) 958227364Sadrian ath_tx_handoff_mcast(sc, txq, bf); 959227364Sadrian else 960227364Sadrian ath_tx_handoff_hw(sc, txq, bf); 961227364Sadrian} 962227364Sadrian 963218154Sadrianstatic int 964218154Sadrianath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni, 965229949Sadrian struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen, 966229949Sadrian int *keyix) 967218154Sadrian{ 968233330Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 969233330Sadrian "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n", 970233330Sadrian __func__, 971233330Sadrian *hdrlen, 972233330Sadrian *pktlen, 973233330Sadrian isfrag, 974233330Sadrian iswep, 975233330Sadrian m0); 976233330Sadrian 977218154Sadrian if (iswep) { 978218154Sadrian const struct ieee80211_cipher *cip; 979218154Sadrian struct ieee80211_key *k; 980218154Sadrian 981218154Sadrian /* 982218154Sadrian * Construct the 802.11 header+trailer for an encrypted 983218154Sadrian * frame. The only reason this can fail is because of an 984218154Sadrian * unknown or unsupported cipher/key type. 985218154Sadrian */ 986218154Sadrian k = ieee80211_crypto_encap(ni, m0); 987218154Sadrian if (k == NULL) { 988218154Sadrian /* 989218154Sadrian * This can happen when the key is yanked after the 990218154Sadrian * frame was queued. Just discard the frame; the 991218154Sadrian * 802.11 layer counts failures and provides 992218154Sadrian * debugging/diagnostics. 993218154Sadrian */ 994229949Sadrian return (0); 995218154Sadrian } 996218154Sadrian /* 997218154Sadrian * Adjust the packet + header lengths for the crypto 998218154Sadrian * additions and calculate the h/w key index. When 999218154Sadrian * a s/w mic is done the frame will have had any mic 1000218154Sadrian * added to it prior to entry so m0->m_pkthdr.len will 1001218154Sadrian * account for it. Otherwise we need to add it to the 1002218154Sadrian * packet length. 1003218154Sadrian */ 1004218154Sadrian cip = k->wk_cipher; 1005218154Sadrian (*hdrlen) += cip->ic_header; 1006218154Sadrian (*pktlen) += cip->ic_header + cip->ic_trailer; 1007218154Sadrian /* NB: frags always have any TKIP MIC done in s/w */ 1008218154Sadrian if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag) 1009218154Sadrian (*pktlen) += cip->ic_miclen; 1010218154Sadrian (*keyix) = k->wk_keyix; 1011218154Sadrian } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { 1012218154Sadrian /* 1013218154Sadrian * Use station key cache slot, if assigned. 1014218154Sadrian */ 1015218154Sadrian (*keyix) = ni->ni_ucastkey.wk_keyix; 1016218154Sadrian if ((*keyix) == IEEE80211_KEYIX_NONE) 1017218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 1018218154Sadrian } else 1019218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 1020218154Sadrian 1021229949Sadrian return (1); 1022218154Sadrian} 1023218154Sadrian 1024233989Sadrian/* 1025233989Sadrian * Calculate whether interoperability protection is required for 1026233989Sadrian * this frame. 1027233989Sadrian * 1028233989Sadrian * This requires the rate control information be filled in, 1029233989Sadrian * as the protection requirement depends upon the current 1030233989Sadrian * operating mode / PHY. 1031233989Sadrian */ 1032233989Sadrianstatic void 1033233989Sadrianath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf) 1034233989Sadrian{ 1035233989Sadrian struct ieee80211_frame *wh; 1036233989Sadrian uint8_t rix; 1037233989Sadrian uint16_t flags; 1038233989Sadrian int shortPreamble; 1039233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1040233989Sadrian struct ifnet *ifp = sc->sc_ifp; 1041233989Sadrian struct ieee80211com *ic = ifp->if_l2com; 1042233989Sadrian 1043233989Sadrian flags = bf->bf_state.bfs_txflags; 1044233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1045233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 1046233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 1047233989Sadrian 1048233989Sadrian /* 1049233989Sadrian * If 802.11g protection is enabled, determine whether 1050233989Sadrian * to use RTS/CTS or just CTS. Note that this is only 1051233989Sadrian * done for OFDM unicast frames. 1052233989Sadrian */ 1053233989Sadrian if ((ic->ic_flags & IEEE80211_F_USEPROT) && 1054233989Sadrian rt->info[rix].phy == IEEE80211_T_OFDM && 1055233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 1056233989Sadrian bf->bf_state.bfs_doprot = 1; 1057233989Sadrian /* XXX fragments must use CCK rates w/ protection */ 1058233989Sadrian if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) { 1059233989Sadrian flags |= HAL_TXDESC_RTSENA; 1060233989Sadrian } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) { 1061233989Sadrian flags |= HAL_TXDESC_CTSENA; 1062233989Sadrian } 1063233989Sadrian /* 1064233989Sadrian * For frags it would be desirable to use the 1065233989Sadrian * highest CCK rate for RTS/CTS. But stations 1066233989Sadrian * farther away may detect it at a lower CCK rate 1067233989Sadrian * so use the configured protection rate instead 1068233989Sadrian * (for now). 1069233989Sadrian */ 1070233989Sadrian sc->sc_stats.ast_tx_protect++; 1071233989Sadrian } 1072233989Sadrian 1073233989Sadrian /* 1074233989Sadrian * If 11n protection is enabled and it's a HT frame, 1075233989Sadrian * enable RTS. 1076233989Sadrian * 1077233989Sadrian * XXX ic_htprotmode or ic_curhtprotmode? 1078233989Sadrian * XXX should it_htprotmode only matter if ic_curhtprotmode 1079233989Sadrian * XXX indicates it's not a HT pure environment? 1080233989Sadrian */ 1081233989Sadrian if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && 1082233989Sadrian rt->info[rix].phy == IEEE80211_T_HT && 1083233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 1084233989Sadrian flags |= HAL_TXDESC_RTSENA; 1085233989Sadrian sc->sc_stats.ast_tx_htprotect++; 1086233989Sadrian } 1087233989Sadrian bf->bf_state.bfs_txflags = flags; 1088233989Sadrian} 1089233989Sadrian 1090233989Sadrian/* 1091233989Sadrian * Update the frame duration given the currently selected rate. 1092233989Sadrian * 1093233989Sadrian * This also updates the frame duration value, so it will require 1094233989Sadrian * a DMA flush. 1095233989Sadrian */ 1096233989Sadrianstatic void 1097233989Sadrianath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf) 1098233989Sadrian{ 1099233989Sadrian struct ieee80211_frame *wh; 1100233989Sadrian uint8_t rix; 1101233989Sadrian uint16_t flags; 1102233989Sadrian int shortPreamble; 1103233989Sadrian struct ath_hal *ah = sc->sc_ah; 1104233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1105233989Sadrian int isfrag = bf->bf_m->m_flags & M_FRAG; 1106233989Sadrian 1107233989Sadrian flags = bf->bf_state.bfs_txflags; 1108233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1109233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 1110233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 1111233989Sadrian 1112233989Sadrian /* 1113233989Sadrian * Calculate duration. This logically belongs in the 802.11 1114233989Sadrian * layer but it lacks sufficient information to calculate it. 1115233989Sadrian */ 1116233989Sadrian if ((flags & HAL_TXDESC_NOACK) == 0 && 1117233989Sadrian (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) { 1118233989Sadrian u_int16_t dur; 1119233989Sadrian if (shortPreamble) 1120233989Sadrian dur = rt->info[rix].spAckDuration; 1121233989Sadrian else 1122233989Sadrian dur = rt->info[rix].lpAckDuration; 1123233989Sadrian if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { 1124233989Sadrian dur += dur; /* additional SIFS+ACK */ 1125246745Sadrian KASSERT(bf->bf_m->m_nextpkt != NULL, ("no fragment")); 1126233989Sadrian /* 1127233989Sadrian * Include the size of next fragment so NAV is 1128233989Sadrian * updated properly. The last fragment uses only 1129233989Sadrian * the ACK duration 1130242144Sadrian * 1131242144Sadrian * XXX TODO: ensure that the rate lookup for each 1132242144Sadrian * fragment is the same as the rate used by the 1133242144Sadrian * first fragment! 1134233989Sadrian */ 1135233989Sadrian dur += ath_hal_computetxtime(ah, rt, 1136246745Sadrian bf->bf_m->m_nextpkt->m_pkthdr.len, 1137233989Sadrian rix, shortPreamble); 1138233989Sadrian } 1139233989Sadrian if (isfrag) { 1140233989Sadrian /* 1141233989Sadrian * Force hardware to use computed duration for next 1142233989Sadrian * fragment by disabling multi-rate retry which updates 1143233989Sadrian * duration based on the multi-rate duration table. 1144233989Sadrian */ 1145233989Sadrian bf->bf_state.bfs_ismrr = 0; 1146233989Sadrian bf->bf_state.bfs_try0 = ATH_TXMGTTRY; 1147233989Sadrian /* XXX update bfs_rc[0].try? */ 1148233989Sadrian } 1149233989Sadrian 1150233989Sadrian /* Update the duration field itself */ 1151233989Sadrian *(u_int16_t *)wh->i_dur = htole16(dur); 1152233989Sadrian } 1153233989Sadrian} 1154233989Sadrian 1155218932Sadrianstatic uint8_t 1156218932Sadrianath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt, 1157227364Sadrian int cix, int shortPreamble) 1158218157Sadrian{ 1159218932Sadrian uint8_t ctsrate; 1160218932Sadrian 1161218157Sadrian /* 1162218157Sadrian * CTS transmit rate is derived from the transmit rate 1163218157Sadrian * by looking in the h/w rate table. We must also factor 1164218157Sadrian * in whether or not a short preamble is to be used. 1165218157Sadrian */ 1166218157Sadrian /* NB: cix is set above where RTS/CTS is enabled */ 1167218157Sadrian KASSERT(cix != 0xff, ("cix not setup")); 1168218932Sadrian ctsrate = rt->info[cix].rateCode; 1169218932Sadrian 1170218932Sadrian /* XXX this should only matter for legacy rates */ 1171218932Sadrian if (shortPreamble) 1172218932Sadrian ctsrate |= rt->info[cix].shortPreamble; 1173218932Sadrian 1174229949Sadrian return (ctsrate); 1175218932Sadrian} 1176218932Sadrian 1177218932Sadrian/* 1178218932Sadrian * Calculate the RTS/CTS duration for legacy frames. 1179218932Sadrian */ 1180218932Sadrianstatic int 1181218932Sadrianath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix, 1182218932Sadrian int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt, 1183218932Sadrian int flags) 1184218932Sadrian{ 1185218932Sadrian int ctsduration = 0; 1186218932Sadrian 1187218932Sadrian /* This mustn't be called for HT modes */ 1188218932Sadrian if (rt->info[cix].phy == IEEE80211_T_HT) { 1189218932Sadrian printf("%s: HT rate where it shouldn't be (0x%x)\n", 1190218932Sadrian __func__, rt->info[cix].rateCode); 1191229949Sadrian return (-1); 1192218932Sadrian } 1193218932Sadrian 1194218157Sadrian /* 1195218157Sadrian * Compute the transmit duration based on the frame 1196218157Sadrian * size and the size of an ACK frame. We call into the 1197218157Sadrian * HAL to do the computation since it depends on the 1198218157Sadrian * characteristics of the actual PHY being used. 1199218157Sadrian * 1200218157Sadrian * NB: CTS is assumed the same size as an ACK so we can 1201218157Sadrian * use the precalculated ACK durations. 1202218157Sadrian */ 1203218157Sadrian if (shortPreamble) { 1204218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1205218932Sadrian ctsduration += rt->info[cix].spAckDuration; 1206218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1207218157Sadrian rt, pktlen, rix, AH_TRUE); 1208218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1209218932Sadrian ctsduration += rt->info[rix].spAckDuration; 1210218157Sadrian } else { 1211218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 1212218932Sadrian ctsduration += rt->info[cix].lpAckDuration; 1213218932Sadrian ctsduration += ath_hal_computetxtime(ah, 1214218157Sadrian rt, pktlen, rix, AH_FALSE); 1215218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 1216218932Sadrian ctsduration += rt->info[rix].lpAckDuration; 1217218157Sadrian } 1218218932Sadrian 1219229949Sadrian return (ctsduration); 1220218157Sadrian} 1221218157Sadrian 1222227364Sadrian/* 1223227364Sadrian * Update the given ath_buf with updated rts/cts setup and duration 1224227364Sadrian * values. 1225227364Sadrian * 1226227364Sadrian * To support rate lookups for each software retry, the rts/cts rate 1227227364Sadrian * and cts duration must be re-calculated. 1228227364Sadrian * 1229227364Sadrian * This function assumes the RTS/CTS flags have been set as needed; 1230227364Sadrian * mrr has been disabled; and the rate control lookup has been done. 1231227364Sadrian * 1232227364Sadrian * XXX TODO: MRR need only be disabled for the pre-11n NICs. 1233227364Sadrian * XXX The 11n NICs support per-rate RTS/CTS configuration. 1234227364Sadrian */ 1235227364Sadrianstatic void 1236227364Sadrianath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf) 1237218065Sadrian{ 1238227364Sadrian uint16_t ctsduration = 0; 1239227364Sadrian uint8_t ctsrate = 0; 1240227364Sadrian uint8_t rix = bf->bf_state.bfs_rc[0].rix; 1241227364Sadrian uint8_t cix = 0; 1242227364Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 1243227364Sadrian 1244227364Sadrian /* 1245227364Sadrian * No RTS/CTS enabled? Don't bother. 1246227364Sadrian */ 1247233966Sadrian if ((bf->bf_state.bfs_txflags & 1248227364Sadrian (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) { 1249227364Sadrian /* XXX is this really needed? */ 1250227364Sadrian bf->bf_state.bfs_ctsrate = 0; 1251227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1252227364Sadrian return; 1253227364Sadrian } 1254227364Sadrian 1255227364Sadrian /* 1256227364Sadrian * If protection is enabled, use the protection rix control 1257227364Sadrian * rate. Otherwise use the rate0 control rate. 1258227364Sadrian */ 1259227364Sadrian if (bf->bf_state.bfs_doprot) 1260227364Sadrian rix = sc->sc_protrix; 1261227364Sadrian else 1262227364Sadrian rix = bf->bf_state.bfs_rc[0].rix; 1263227364Sadrian 1264227364Sadrian /* 1265227364Sadrian * If the raw path has hard-coded ctsrate0 to something, 1266227364Sadrian * use it. 1267227364Sadrian */ 1268227364Sadrian if (bf->bf_state.bfs_ctsrate0 != 0) 1269227364Sadrian cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0); 1270227364Sadrian else 1271227364Sadrian /* Control rate from above */ 1272227364Sadrian cix = rt->info[rix].controlRate; 1273227364Sadrian 1274227364Sadrian /* Calculate the rtscts rate for the given cix */ 1275227364Sadrian ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix, 1276227364Sadrian bf->bf_state.bfs_shpream); 1277227364Sadrian 1278227364Sadrian /* The 11n chipsets do ctsduration calculations for you */ 1279227364Sadrian if (! ath_tx_is_11n(sc)) 1280227364Sadrian ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix, 1281227364Sadrian bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen, 1282233966Sadrian rt, bf->bf_state.bfs_txflags); 1283227364Sadrian 1284227364Sadrian /* Squirrel away in ath_buf */ 1285227364Sadrian bf->bf_state.bfs_ctsrate = ctsrate; 1286227364Sadrian bf->bf_state.bfs_ctsduration = ctsduration; 1287227364Sadrian 1288227364Sadrian /* 1289227364Sadrian * Must disable multi-rate retry when using RTS/CTS. 1290227364Sadrian */ 1291238961Sadrian if (!sc->sc_mrrprot) { 1292238961Sadrian bf->bf_state.bfs_ismrr = 0; 1293238961Sadrian bf->bf_state.bfs_try0 = 1294238961Sadrian bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */ 1295238961Sadrian } 1296227364Sadrian} 1297227364Sadrian 1298227364Sadrian/* 1299227364Sadrian * Setup the descriptor chain for a normal or fast-frame 1300227364Sadrian * frame. 1301239051Sadrian * 1302239051Sadrian * XXX TODO: extend to include the destination hardware QCU ID. 1303239051Sadrian * Make sure that is correct. Make sure that when being added 1304239051Sadrian * to the mcastq, the CABQ QCUID is set or things will get a bit 1305239051Sadrian * odd. 1306227364Sadrian */ 1307227364Sadrianstatic void 1308227364Sadrianath_tx_setds(struct ath_softc *sc, struct ath_buf *bf) 1309227364Sadrian{ 1310227364Sadrian struct ath_desc *ds = bf->bf_desc; 1311227364Sadrian struct ath_hal *ah = sc->sc_ah; 1312227364Sadrian 1313242951Sadrian if (bf->bf_state.bfs_txrate0 == 0) 1314242951Sadrian device_printf(sc->sc_dev, "%s: bf=%p, txrate0=%d\n", 1315242951Sadrian __func__, bf, 0); 1316242951Sadrian 1317227364Sadrian ath_hal_setuptxdesc(ah, ds 1318227364Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 1319227364Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 1320227364Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 1321227364Sadrian , bf->bf_state.bfs_txpower /* txpower */ 1322227364Sadrian , bf->bf_state.bfs_txrate0 1323227364Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 1324227364Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 1325227364Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 1326233966Sadrian , bf->bf_state.bfs_txflags /* flags */ 1327227364Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 1328227364Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 1329227364Sadrian ); 1330227364Sadrian 1331227364Sadrian /* 1332227364Sadrian * This will be overriden when the descriptor chain is written. 1333227364Sadrian */ 1334227364Sadrian bf->bf_lastds = ds; 1335227364Sadrian bf->bf_last = bf; 1336227364Sadrian 1337238947Sadrian /* Set rate control and descriptor chain for this frame */ 1338238947Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 1339242656Sadrian ath_tx_chaindesclist(sc, ds, bf, 0, 0, 0); 1340227364Sadrian} 1341227364Sadrian 1342227364Sadrian/* 1343227364Sadrian * Do a rate lookup. 1344227364Sadrian * 1345227364Sadrian * This performs a rate lookup for the given ath_buf only if it's required. 1346227364Sadrian * Non-data frames and raw frames don't require it. 1347227364Sadrian * 1348227364Sadrian * This populates the primary and MRR entries; MRR values are 1349227364Sadrian * then disabled later on if something requires it (eg RTS/CTS on 1350227364Sadrian * pre-11n chipsets. 1351227364Sadrian * 1352227364Sadrian * This needs to be done before the RTS/CTS fields are calculated 1353227364Sadrian * as they may depend upon the rate chosen. 1354227364Sadrian */ 1355227364Sadrianstatic void 1356227364Sadrianath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf) 1357227364Sadrian{ 1358227364Sadrian uint8_t rate, rix; 1359227364Sadrian int try0; 1360227364Sadrian 1361227364Sadrian if (! bf->bf_state.bfs_doratelookup) 1362227364Sadrian return; 1363227364Sadrian 1364227364Sadrian /* Get rid of any previous state */ 1365227364Sadrian bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1366227364Sadrian 1367227364Sadrian ATH_NODE_LOCK(ATH_NODE(bf->bf_node)); 1368227364Sadrian ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream, 1369227364Sadrian bf->bf_state.bfs_pktlen, &rix, &try0, &rate); 1370227364Sadrian 1371227364Sadrian /* In case MRR is disabled, make sure rc[0] is setup correctly */ 1372227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1373227364Sadrian bf->bf_state.bfs_rc[0].ratecode = rate; 1374227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1375227364Sadrian 1376227364Sadrian if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY) 1377227364Sadrian ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix, 1378227364Sadrian bf->bf_state.bfs_rc); 1379227364Sadrian ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node)); 1380227364Sadrian 1381227364Sadrian sc->sc_txrix = rix; /* for LED blinking */ 1382227364Sadrian sc->sc_lastdatarix = rix; /* for fast frames */ 1383227364Sadrian bf->bf_state.bfs_try0 = try0; 1384227364Sadrian bf->bf_state.bfs_txrate0 = rate; 1385227364Sadrian} 1386227364Sadrian 1387227364Sadrian/* 1388240883Sadrian * Update the CLRDMASK bit in the ath_buf if it needs to be set. 1389240883Sadrian */ 1390240883Sadrianstatic void 1391240883Sadrianath_tx_update_clrdmask(struct ath_softc *sc, struct ath_tid *tid, 1392240883Sadrian struct ath_buf *bf) 1393240883Sadrian{ 1394245708Sadrian struct ath_node *an = ATH_NODE(bf->bf_node); 1395240883Sadrian 1396243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1397240883Sadrian 1398245708Sadrian if (an->clrdmask == 1) { 1399240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1400245708Sadrian an->clrdmask = 0; 1401240883Sadrian } 1402240883Sadrian} 1403240883Sadrian 1404240883Sadrian/* 1405227364Sadrian * Transmit the given frame to the hardware. 1406227364Sadrian * 1407227364Sadrian * The frame must already be setup; rate control must already have 1408227364Sadrian * been done. 1409227364Sadrian * 1410227364Sadrian * XXX since the TXQ lock is being held here (and I dislike holding 1411227364Sadrian * it for this long when not doing software aggregation), later on 1412227364Sadrian * break this function into "setup_normal" and "xmit_normal". The 1413227364Sadrian * lock only needs to be held for the ath_tx_handoff call. 1414227364Sadrian */ 1415227364Sadrianstatic void 1416227364Sadrianath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq, 1417227364Sadrian struct ath_buf *bf) 1418227364Sadrian{ 1419240883Sadrian struct ath_node *an = ATH_NODE(bf->bf_node); 1420240883Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 1421227364Sadrian 1422243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1423227364Sadrian 1424240883Sadrian /* 1425240883Sadrian * For now, just enable CLRDMASK. ath_tx_xmit_normal() does 1426240883Sadrian * set a completion handler however it doesn't (yet) properly 1427240883Sadrian * handle the strict ordering requirements needed for normal, 1428240883Sadrian * non-aggregate session frames. 1429240883Sadrian * 1430240883Sadrian * Once this is implemented, only set CLRDMASK like this for 1431240883Sadrian * frames that must go out - eg management/raw frames. 1432240883Sadrian */ 1433240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1434240883Sadrian 1435227364Sadrian /* Setup the descriptor before handoff */ 1436227364Sadrian ath_tx_do_ratelookup(sc, bf); 1437233989Sadrian ath_tx_calc_duration(sc, bf); 1438233989Sadrian ath_tx_calc_protection(sc, bf); 1439233989Sadrian ath_tx_set_rtscts(sc, bf); 1440227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 1441227364Sadrian ath_tx_setds(sc, bf); 1442227364Sadrian 1443240883Sadrian /* Track per-TID hardware queue depth correctly */ 1444240883Sadrian tid->hwq_depth++; 1445240724Sadrian 1446240883Sadrian /* Assign the completion handler */ 1447240883Sadrian bf->bf_comp = ath_tx_normal_comp; 1448240883Sadrian 1449227364Sadrian /* Hand off to hardware */ 1450227364Sadrian ath_tx_handoff(sc, txq, bf); 1451227364Sadrian} 1452227364Sadrian 1453240722Sadrian/* 1454240722Sadrian * Do the basic frame setup stuff that's required before the frame 1455240722Sadrian * is added to a software queue. 1456240722Sadrian * 1457240722Sadrian * All frames get mostly the same treatment and it's done once. 1458240722Sadrian * Retransmits fiddle with things like the rate control setup, 1459240722Sadrian * setting the retransmit bit in the packet; doing relevant DMA/bus 1460240722Sadrian * syncing and relinking it (back) into the hardware TX queue. 1461240722Sadrian * 1462240722Sadrian * Note that this may cause the mbuf to be reallocated, so 1463240722Sadrian * m0 may not be valid. 1464240722Sadrian */ 1465227364Sadrianstatic int 1466227364Sadrianath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni, 1467234009Sadrian struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq) 1468227364Sadrian{ 1469218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1470218065Sadrian struct ath_hal *ah = sc->sc_ah; 1471218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1472218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1473218065Sadrian const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; 1474218065Sadrian int error, iswep, ismcast, isfrag, ismrr; 1475227364Sadrian int keyix, hdrlen, pktlen, try0 = 0; 1476227364Sadrian u_int8_t rix = 0, txrate = 0; 1477218065Sadrian struct ath_desc *ds; 1478218065Sadrian struct ieee80211_frame *wh; 1479227364Sadrian u_int subtype, flags; 1480218065Sadrian HAL_PKT_TYPE atype; 1481218065Sadrian const HAL_RATE_TABLE *rt; 1482218065Sadrian HAL_BOOL shortPreamble; 1483218065Sadrian struct ath_node *an; 1484218065Sadrian u_int pri; 1485218065Sadrian 1486236880Sadrian /* 1487236880Sadrian * To ensure that both sequence numbers and the CCMP PN handling 1488236880Sadrian * is "correct", make sure that the relevant TID queue is locked. 1489236880Sadrian * Otherwise the CCMP PN and seqno may appear out of order, causing 1490236880Sadrian * re-ordered frames to have out of order CCMP PN's, resulting 1491236880Sadrian * in many, many frame drops. 1492236880Sadrian */ 1493243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1494236880Sadrian 1495218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1496218065Sadrian iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; 1497218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1498218065Sadrian isfrag = m0->m_flags & M_FRAG; 1499218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1500218065Sadrian /* 1501218065Sadrian * Packet length must not include any 1502218065Sadrian * pad bytes; deduct them here. 1503218065Sadrian */ 1504218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3); 1505218065Sadrian 1506218154Sadrian /* Handle encryption twiddling if needed */ 1507227364Sadrian if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen, 1508227364Sadrian &pktlen, &keyix)) { 1509218154Sadrian ath_freetx(m0); 1510218154Sadrian return EIO; 1511218154Sadrian } 1512218065Sadrian 1513218154Sadrian /* packet header may have moved, reset our local pointer */ 1514218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1515218065Sadrian 1516218065Sadrian pktlen += IEEE80211_CRC_LEN; 1517218065Sadrian 1518218065Sadrian /* 1519218065Sadrian * Load the DMA map so any coalescing is done. This 1520218065Sadrian * also calculates the number of descriptors we need. 1521218065Sadrian */ 1522218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1523218065Sadrian if (error != 0) 1524218065Sadrian return error; 1525218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1526218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1527218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1528218065Sadrian 1529218065Sadrian /* setup descriptors */ 1530218065Sadrian ds = bf->bf_desc; 1531218065Sadrian rt = sc->sc_currates; 1532218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1533218065Sadrian 1534218065Sadrian /* 1535218065Sadrian * NB: the 802.11 layer marks whether or not we should 1536218065Sadrian * use short preamble based on the current mode and 1537218065Sadrian * negotiated parameters. 1538218065Sadrian */ 1539218065Sadrian if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 1540218065Sadrian (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) { 1541218065Sadrian shortPreamble = AH_TRUE; 1542218065Sadrian sc->sc_stats.ast_tx_shortpre++; 1543218065Sadrian } else { 1544218065Sadrian shortPreamble = AH_FALSE; 1545218065Sadrian } 1546218065Sadrian 1547218065Sadrian an = ATH_NODE(ni); 1548240724Sadrian //flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1549240724Sadrian flags = 0; 1550218065Sadrian ismrr = 0; /* default no multi-rate retry*/ 1551218065Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 1552218065Sadrian /* XXX use txparams instead of fixed values */ 1553218065Sadrian /* 1554218065Sadrian * Calculate Atheros packet type from IEEE80211 packet header, 1555218065Sadrian * setup for rate calculations, and select h/w transmit queue. 1556218065Sadrian */ 1557218065Sadrian switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1558218065Sadrian case IEEE80211_FC0_TYPE_MGT: 1559218065Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1560218065Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) 1561218065Sadrian atype = HAL_PKT_TYPE_BEACON; 1562218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) 1563218065Sadrian atype = HAL_PKT_TYPE_PROBE_RESP; 1564218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) 1565218065Sadrian atype = HAL_PKT_TYPE_ATIM; 1566218065Sadrian else 1567218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* XXX */ 1568218065Sadrian rix = an->an_mgmtrix; 1569218065Sadrian txrate = rt->info[rix].rateCode; 1570218065Sadrian if (shortPreamble) 1571218065Sadrian txrate |= rt->info[rix].shortPreamble; 1572218065Sadrian try0 = ATH_TXMGTTRY; 1573218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1574218065Sadrian break; 1575218065Sadrian case IEEE80211_FC0_TYPE_CTL: 1576218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */ 1577218065Sadrian rix = an->an_mgmtrix; 1578218065Sadrian txrate = rt->info[rix].rateCode; 1579218065Sadrian if (shortPreamble) 1580218065Sadrian txrate |= rt->info[rix].shortPreamble; 1581218065Sadrian try0 = ATH_TXMGTTRY; 1582218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1583218065Sadrian break; 1584218065Sadrian case IEEE80211_FC0_TYPE_DATA: 1585218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* default */ 1586218065Sadrian /* 1587218065Sadrian * Data frames: multicast frames go out at a fixed rate, 1588218065Sadrian * EAPOL frames use the mgmt frame rate; otherwise consult 1589218065Sadrian * the rate control module for the rate to use. 1590218065Sadrian */ 1591218065Sadrian if (ismcast) { 1592218065Sadrian rix = an->an_mcastrix; 1593218065Sadrian txrate = rt->info[rix].rateCode; 1594218065Sadrian if (shortPreamble) 1595218065Sadrian txrate |= rt->info[rix].shortPreamble; 1596218065Sadrian try0 = 1; 1597218065Sadrian } else if (m0->m_flags & M_EAPOL) { 1598218065Sadrian /* XXX? maybe always use long preamble? */ 1599218065Sadrian rix = an->an_mgmtrix; 1600218065Sadrian txrate = rt->info[rix].rateCode; 1601218065Sadrian if (shortPreamble) 1602218065Sadrian txrate |= rt->info[rix].shortPreamble; 1603218065Sadrian try0 = ATH_TXMAXTRY; /* XXX?too many? */ 1604218065Sadrian } else { 1605227364Sadrian /* 1606227364Sadrian * Do rate lookup on each TX, rather than using 1607227364Sadrian * the hard-coded TX information decided here. 1608227364Sadrian */ 1609227364Sadrian ismrr = 1; 1610227364Sadrian bf->bf_state.bfs_doratelookup = 1; 1611218065Sadrian } 1612218065Sadrian if (cap->cap_wmeParams[pri].wmep_noackPolicy) 1613218065Sadrian flags |= HAL_TXDESC_NOACK; 1614218065Sadrian break; 1615218065Sadrian default: 1616218065Sadrian if_printf(ifp, "bogus frame type 0x%x (%s)\n", 1617218065Sadrian wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__); 1618218065Sadrian /* XXX statistic */ 1619218065Sadrian ath_freetx(m0); 1620218065Sadrian return EIO; 1621218065Sadrian } 1622218065Sadrian 1623237041Sadrian /* 1624237041Sadrian * There are two known scenarios where the frame AC doesn't match 1625237041Sadrian * what the destination TXQ is. 1626237041Sadrian * 1627237041Sadrian * + non-QoS frames (eg management?) that the net80211 stack has 1628237041Sadrian * assigned a higher AC to, but since it's a non-QoS TID, it's 1629237041Sadrian * being thrown into TID 16. TID 16 gets the AC_BE queue. 1630237041Sadrian * It's quite possible that management frames should just be 1631237041Sadrian * direct dispatched to hardware rather than go via the software 1632237041Sadrian * queue; that should be investigated in the future. There are 1633237041Sadrian * some specific scenarios where this doesn't make sense, mostly 1634237041Sadrian * surrounding ADDBA request/response - hence why that is special 1635237041Sadrian * cased. 1636237041Sadrian * 1637237041Sadrian * + Multicast frames going into the VAP mcast queue. That shows up 1638237041Sadrian * as "TXQ 11". 1639237041Sadrian * 1640237041Sadrian * This driver should eventually support separate TID and TXQ locking, 1641237041Sadrian * allowing for arbitrary AC frames to appear on arbitrary software 1642237041Sadrian * queues, being queued to the "correct" hardware queue when needed. 1643237041Sadrian */ 1644237041Sadrian#if 0 1645235750Sadrian if (txq != sc->sc_ac2q[pri]) { 1646235750Sadrian device_printf(sc->sc_dev, 1647235750Sadrian "%s: txq=%p (%d), pri=%d, pri txq=%p (%d)\n", 1648235750Sadrian __func__, 1649235750Sadrian txq, 1650235750Sadrian txq->axq_qnum, 1651235750Sadrian pri, 1652235750Sadrian sc->sc_ac2q[pri], 1653235750Sadrian sc->sc_ac2q[pri]->axq_qnum); 1654235750Sadrian } 1655237041Sadrian#endif 1656235750Sadrian 1657218065Sadrian /* 1658218065Sadrian * Calculate miscellaneous flags. 1659218065Sadrian */ 1660218065Sadrian if (ismcast) { 1661218065Sadrian flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ 1662218065Sadrian } else if (pktlen > vap->iv_rtsthreshold && 1663218065Sadrian (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) { 1664218065Sadrian flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ 1665218065Sadrian sc->sc_stats.ast_tx_rts++; 1666218065Sadrian } 1667218065Sadrian if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */ 1668218065Sadrian sc->sc_stats.ast_tx_noack++; 1669218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 1670218065Sadrian if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) { 1671218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA, 1672218065Sadrian "%s: discard frame, ACK required w/ TDMA\n", __func__); 1673218065Sadrian sc->sc_stats.ast_tdma_ack++; 1674218065Sadrian ath_freetx(m0); 1675218065Sadrian return EIO; 1676218065Sadrian } 1677218065Sadrian#endif 1678218065Sadrian 1679218065Sadrian /* 1680227364Sadrian * Determine if a tx interrupt should be generated for 1681227364Sadrian * this descriptor. We take a tx interrupt to reap 1682227364Sadrian * descriptors when the h/w hits an EOL condition or 1683227364Sadrian * when the descriptor is specifically marked to generate 1684227364Sadrian * an interrupt. We periodically mark descriptors in this 1685227364Sadrian * way to insure timely replenishing of the supply needed 1686227364Sadrian * for sending frames. Defering interrupts reduces system 1687227364Sadrian * load and potentially allows more concurrent work to be 1688227364Sadrian * done but if done to aggressively can cause senders to 1689227364Sadrian * backup. 1690227364Sadrian * 1691227364Sadrian * NB: use >= to deal with sc_txintrperiod changing 1692227364Sadrian * dynamically through sysctl. 1693218065Sadrian */ 1694227364Sadrian if (flags & HAL_TXDESC_INTREQ) { 1695227364Sadrian txq->axq_intrcnt = 0; 1696227364Sadrian } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) { 1697227364Sadrian flags |= HAL_TXDESC_INTREQ; 1698227364Sadrian txq->axq_intrcnt = 0; 1699227364Sadrian } 1700218932Sadrian 1701227364Sadrian /* This point forward is actual TX bits */ 1702218065Sadrian 1703218065Sadrian /* 1704218065Sadrian * At this point we are committed to sending the frame 1705218065Sadrian * and we don't need to look at m_nextpkt; clear it in 1706218065Sadrian * case this frame is part of frag chain. 1707218065Sadrian */ 1708218065Sadrian m0->m_nextpkt = NULL; 1709218065Sadrian 1710218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1711218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len, 1712218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1713218065Sadrian 1714218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1715218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1716218065Sadrian 1717218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1718218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1719218065Sadrian if (iswep) 1720218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1721218065Sadrian if (isfrag) 1722218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1723218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1724218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1725218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1726218065Sadrian 1727218065Sadrian ieee80211_radiotap_tx(vap, m0); 1728218065Sadrian } 1729218065Sadrian 1730227364Sadrian /* Blank the legacy rate array */ 1731227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1732227364Sadrian 1733218065Sadrian /* 1734227364Sadrian * ath_buf_set_rate needs at least one rate/try to setup 1735227364Sadrian * the rate scenario. 1736227364Sadrian */ 1737227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1738227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1739227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1740227364Sadrian 1741227364Sadrian /* Store the decided rate index values away */ 1742227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1743227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1744227364Sadrian bf->bf_state.bfs_atype = atype; 1745227364Sadrian bf->bf_state.bfs_txpower = ni->ni_txpower; 1746227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1747227364Sadrian bf->bf_state.bfs_try0 = try0; 1748227364Sadrian bf->bf_state.bfs_keyix = keyix; 1749227364Sadrian bf->bf_state.bfs_txantenna = sc->sc_txantenna; 1750233966Sadrian bf->bf_state.bfs_txflags = flags; 1751227364Sadrian bf->bf_state.bfs_shpream = shortPreamble; 1752227364Sadrian 1753227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1754227364Sadrian bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */ 1755227364Sadrian bf->bf_state.bfs_ctsrate = 0; /* calculated later */ 1756227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1757227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1758227364Sadrian 1759227364Sadrian return 0; 1760227364Sadrian} 1761227364Sadrian 1762227364Sadrian/* 1763240724Sadrian * Queue a frame to the hardware or software queue. 1764227364Sadrian * 1765227364Sadrian * This can be called by the net80211 code. 1766227364Sadrian * 1767227364Sadrian * XXX what about locking? Or, push the seqno assign into the 1768227364Sadrian * XXX aggregate scheduler so its serialised? 1769240724Sadrian * 1770240724Sadrian * XXX When sending management frames via ath_raw_xmit(), 1771240724Sadrian * should CLRDMASK be set unconditionally? 1772227364Sadrian */ 1773227364Sadrianint 1774227364Sadrianath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, 1775227364Sadrian struct ath_buf *bf, struct mbuf *m0) 1776227364Sadrian{ 1777227364Sadrian struct ieee80211vap *vap = ni->ni_vap; 1778227364Sadrian struct ath_vap *avp = ATH_VAP(vap); 1779232764Sadrian int r = 0; 1780227364Sadrian u_int pri; 1781227364Sadrian int tid; 1782227364Sadrian struct ath_txq *txq; 1783227364Sadrian int ismcast; 1784227364Sadrian const struct ieee80211_frame *wh; 1785227364Sadrian int is_ampdu, is_ampdu_tx, is_ampdu_pending; 1786236872Sadrian ieee80211_seq seqno; 1787227364Sadrian uint8_t type, subtype; 1788227364Sadrian 1789243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1790243786Sadrian 1791227364Sadrian /* 1792227364Sadrian * Determine the target hardware queue. 1793218065Sadrian * 1794234009Sadrian * For multicast frames, the txq gets overridden appropriately 1795234009Sadrian * depending upon the state of PS. 1796227364Sadrian * 1797227364Sadrian * For any other frame, we do a TID/QoS lookup inside the frame 1798227364Sadrian * to see what the TID should be. If it's a non-QoS frame, the 1799227364Sadrian * AC and TID are overridden. The TID/TXQ code assumes the 1800227364Sadrian * TID is on a predictable hardware TXQ, so we don't support 1801227364Sadrian * having a node TID queued to multiple hardware TXQs. 1802227364Sadrian * This may change in the future but would require some locking 1803227364Sadrian * fudgery. 1804218065Sadrian */ 1805227364Sadrian pri = ath_tx_getac(sc, m0); 1806227364Sadrian tid = ath_tx_gettid(sc, m0); 1807218065Sadrian 1808227364Sadrian txq = sc->sc_ac2q[pri]; 1809227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 1810227364Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1811227364Sadrian type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 1812227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1813227364Sadrian 1814232764Sadrian /* 1815232764Sadrian * Enforce how deep the multicast queue can grow. 1816232764Sadrian * 1817232764Sadrian * XXX duplicated in ath_raw_xmit(). 1818232764Sadrian */ 1819232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1820232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 1821232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 1822232764Sadrian r = ENOBUFS; 1823232764Sadrian } 1824232764Sadrian if (r != 0) { 1825232764Sadrian m_freem(m0); 1826232764Sadrian return r; 1827232764Sadrian } 1828232764Sadrian } 1829232764Sadrian 1830227364Sadrian /* A-MPDU TX */ 1831227364Sadrian is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid); 1832227364Sadrian is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid); 1833227364Sadrian is_ampdu = is_ampdu_tx | is_ampdu_pending; 1834227364Sadrian 1835236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, ac=%d, is_ampdu=%d\n", 1836236872Sadrian __func__, tid, pri, is_ampdu); 1837227364Sadrian 1838239051Sadrian /* Set local packet state, used to queue packets to hardware */ 1839239051Sadrian bf->bf_state.bfs_tid = tid; 1840244109Sadrian bf->bf_state.bfs_tx_queue = txq->axq_qnum; 1841239051Sadrian bf->bf_state.bfs_pri = pri; 1842239051Sadrian 1843248671Sadrian#if 1 1844232753Sadrian /* 1845234009Sadrian * When servicing one or more stations in power-save mode 1846234009Sadrian * (or) if there is some mcast data waiting on the mcast 1847234009Sadrian * queue (to prevent out of order delivery) multicast frames 1848234009Sadrian * must be bufferd until after the beacon. 1849234009Sadrian * 1850234009Sadrian * TODO: we should lock the mcastq before we check the length. 1851232753Sadrian */ 1852248671Sadrian if (sc->sc_cabq_enable && ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) { 1853227364Sadrian txq = &avp->av_mcastq; 1854239051Sadrian /* 1855239051Sadrian * Mark the frame as eventually belonging on the CAB 1856239051Sadrian * queue, so the descriptor setup functions will 1857239051Sadrian * correctly initialise the descriptor 'qcuId' field. 1858239051Sadrian */ 1859244109Sadrian bf->bf_state.bfs_tx_queue = sc->sc_cabq->axq_qnum; 1860239051Sadrian } 1861248671Sadrian#endif 1862227364Sadrian 1863227364Sadrian /* Do the generic frame setup */ 1864227364Sadrian /* XXX should just bzero the bf_state? */ 1865227364Sadrian bf->bf_state.bfs_dobaw = 0; 1866227364Sadrian 1867227364Sadrian /* A-MPDU TX? Manually set sequence number */ 1868236880Sadrian /* 1869236880Sadrian * Don't do it whilst pending; the net80211 layer still 1870236880Sadrian * assigns them. 1871236880Sadrian */ 1872227364Sadrian if (is_ampdu_tx) { 1873227364Sadrian /* 1874227364Sadrian * Always call; this function will 1875227364Sadrian * handle making sure that null data frames 1876227364Sadrian * don't get a sequence number from the current 1877227364Sadrian * TID and thus mess with the BAW. 1878227364Sadrian */ 1879236872Sadrian seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0); 1880236874Sadrian 1881236874Sadrian /* 1882236874Sadrian * Don't add QoS NULL frames to the BAW. 1883236874Sadrian */ 1884236872Sadrian if (IEEE80211_QOS_HAS_SEQ(wh) && 1885236872Sadrian subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL) { 1886227364Sadrian bf->bf_state.bfs_dobaw = 1; 1887227364Sadrian } 1888218240Sadrian } 1889218240Sadrian 1890218065Sadrian /* 1891227364Sadrian * If needed, the sequence number has been assigned. 1892227364Sadrian * Squirrel it away somewhere easy to get to. 1893218065Sadrian */ 1894236872Sadrian bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1895227364Sadrian 1896227364Sadrian /* Is ampdu pending? fetch the seqno and print it out */ 1897227364Sadrian if (is_ampdu_pending) 1898227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1899227364Sadrian "%s: tid %d: ampdu pending, seqno %d\n", 1900227364Sadrian __func__, tid, M_SEQNO_GET(m0)); 1901227364Sadrian 1902227364Sadrian /* This also sets up the DMA map */ 1903234009Sadrian r = ath_tx_normal_setup(sc, ni, bf, m0, txq); 1904227364Sadrian 1905227364Sadrian if (r != 0) 1906236880Sadrian goto done; 1907227364Sadrian 1908227364Sadrian /* At this point m0 could have changed! */ 1909227364Sadrian m0 = bf->bf_m; 1910227364Sadrian 1911227364Sadrian#if 1 1912218065Sadrian /* 1913227364Sadrian * If it's a multicast frame, do a direct-dispatch to the 1914227364Sadrian * destination hardware queue. Don't bother software 1915227364Sadrian * queuing it. 1916218065Sadrian */ 1917227364Sadrian /* 1918227364Sadrian * If it's a BAR frame, do a direct dispatch to the 1919227364Sadrian * destination hardware queue. Don't bother software 1920227364Sadrian * queuing it, as the TID will now be paused. 1921227364Sadrian * Sending a BAR frame can occur from the net80211 txa timer 1922227364Sadrian * (ie, retries) or from the ath txtask (completion call.) 1923227364Sadrian * It queues directly to hardware because the TID is paused 1924227364Sadrian * at this point (and won't be unpaused until the BAR has 1925227364Sadrian * either been TXed successfully or max retries has been 1926227364Sadrian * reached.) 1927227364Sadrian */ 1928227364Sadrian if (txq == &avp->av_mcastq) { 1929235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1930233227Sadrian "%s: bf=%p: mcastq: TX'ing\n", __func__, bf); 1931240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1932227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1933227364Sadrian } else if (type == IEEE80211_FC0_TYPE_CTL && 1934227364Sadrian subtype == IEEE80211_FC0_SUBTYPE_BAR) { 1935235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1936227364Sadrian "%s: BAR: TX'ing direct\n", __func__); 1937240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1938227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1939227364Sadrian } else { 1940227364Sadrian /* add to software queue */ 1941235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1942233227Sadrian "%s: bf=%p: swq: TX'ing\n", __func__, bf); 1943227364Sadrian ath_tx_swq(sc, ni, txq, bf); 1944227364Sadrian } 1945227364Sadrian#else 1946227364Sadrian /* 1947227364Sadrian * For now, since there's no software queue, 1948227364Sadrian * direct-dispatch to the hardware. 1949227364Sadrian */ 1950240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 1951227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1952236880Sadrian#endif 1953236880Sadriandone: 1954218065Sadrian return 0; 1955218065Sadrian} 1956218065Sadrian 1957218065Sadrianstatic int 1958218065Sadrianath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni, 1959218065Sadrian struct ath_buf *bf, struct mbuf *m0, 1960218065Sadrian const struct ieee80211_bpf_params *params) 1961218065Sadrian{ 1962218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1963218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1964218065Sadrian struct ath_hal *ah = sc->sc_ah; 1965218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1966218065Sadrian int error, ismcast, ismrr; 1967218065Sadrian int keyix, hdrlen, pktlen, try0, txantenna; 1968227364Sadrian u_int8_t rix, txrate; 1969218065Sadrian struct ieee80211_frame *wh; 1970227364Sadrian u_int flags; 1971218065Sadrian HAL_PKT_TYPE atype; 1972218065Sadrian const HAL_RATE_TABLE *rt; 1973218065Sadrian struct ath_desc *ds; 1974218065Sadrian u_int pri; 1975227364Sadrian int o_tid = -1; 1976227364Sadrian int do_override; 1977218065Sadrian 1978243786Sadrian ATH_TX_LOCK_ASSERT(sc); 1979243786Sadrian 1980218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1981218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1982218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1983218065Sadrian /* 1984218065Sadrian * Packet length must not include any 1985218065Sadrian * pad bytes; deduct them here. 1986218065Sadrian */ 1987218065Sadrian /* XXX honor IEEE80211_BPF_DATAPAD */ 1988218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; 1989218065Sadrian 1990240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 2, 1991240899Sadrian "ath_tx_raw_start: ni=%p, bf=%p, raw", ni, bf); 1992240899Sadrian 1993227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n", 1994227364Sadrian __func__, ismcast); 1995227364Sadrian 1996236880Sadrian pri = params->ibp_pri & 3; 1997236880Sadrian /* Override pri if the frame isn't a QoS one */ 1998236880Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 1999236880Sadrian pri = ath_tx_getac(sc, m0); 2000236880Sadrian 2001236880Sadrian /* XXX If it's an ADDBA, override the correct queue */ 2002236880Sadrian do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid); 2003236880Sadrian 2004236880Sadrian /* Map ADDBA to the correct priority */ 2005236880Sadrian if (do_override) { 2006236880Sadrian#if 0 2007236880Sadrian device_printf(sc->sc_dev, 2008236880Sadrian "%s: overriding tid %d pri %d -> %d\n", 2009236880Sadrian __func__, o_tid, pri, TID_TO_WME_AC(o_tid)); 2010236880Sadrian#endif 2011236880Sadrian pri = TID_TO_WME_AC(o_tid); 2012236880Sadrian } 2013236880Sadrian 2014218154Sadrian /* Handle encryption twiddling if needed */ 2015227364Sadrian if (! ath_tx_tag_crypto(sc, ni, 2016227364Sadrian m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0, 2017227364Sadrian &hdrlen, &pktlen, &keyix)) { 2018218154Sadrian ath_freetx(m0); 2019218154Sadrian return EIO; 2020218154Sadrian } 2021218154Sadrian /* packet header may have moved, reset our local pointer */ 2022218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 2023218065Sadrian 2024227364Sadrian /* Do the generic frame setup */ 2025227364Sadrian /* XXX should just bzero the bf_state? */ 2026227364Sadrian bf->bf_state.bfs_dobaw = 0; 2027227364Sadrian 2028218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 2029218065Sadrian if (error != 0) 2030218065Sadrian return error; 2031218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 2032218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 2033218065Sadrian bf->bf_node = ni; /* NB: held reference */ 2034218065Sadrian 2035240724Sadrian /* Always enable CLRDMASK for raw frames for now.. */ 2036218065Sadrian flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 2037218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 2038218065Sadrian if (params->ibp_flags & IEEE80211_BPF_RTS) 2039218065Sadrian flags |= HAL_TXDESC_RTSENA; 2040227364Sadrian else if (params->ibp_flags & IEEE80211_BPF_CTS) { 2041227364Sadrian /* XXX assume 11g/11n protection? */ 2042227364Sadrian bf->bf_state.bfs_doprot = 1; 2043218065Sadrian flags |= HAL_TXDESC_CTSENA; 2044227364Sadrian } 2045218065Sadrian /* XXX leave ismcast to injector? */ 2046218065Sadrian if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast) 2047218065Sadrian flags |= HAL_TXDESC_NOACK; 2048218065Sadrian 2049218065Sadrian rt = sc->sc_currates; 2050218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 2051218065Sadrian rix = ath_tx_findrix(sc, params->ibp_rate0); 2052218065Sadrian txrate = rt->info[rix].rateCode; 2053218065Sadrian if (params->ibp_flags & IEEE80211_BPF_SHORTPRE) 2054218065Sadrian txrate |= rt->info[rix].shortPreamble; 2055218065Sadrian sc->sc_txrix = rix; 2056218065Sadrian try0 = params->ibp_try0; 2057218065Sadrian ismrr = (params->ibp_try1 != 0); 2058218065Sadrian txantenna = params->ibp_pri >> 2; 2059218065Sadrian if (txantenna == 0) /* XXX? */ 2060218065Sadrian txantenna = sc->sc_txantenna; 2061218157Sadrian 2062227364Sadrian /* 2063227364Sadrian * Since ctsrate is fixed, store it away for later 2064227364Sadrian * use when the descriptor fields are being set. 2065227364Sadrian */ 2066227364Sadrian if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) 2067227364Sadrian bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate; 2068218157Sadrian 2069218065Sadrian /* 2070218065Sadrian * NB: we mark all packets as type PSPOLL so the h/w won't 2071218065Sadrian * set the sequence number, duration, etc. 2072218065Sadrian */ 2073218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; 2074218065Sadrian 2075218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 2076218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len, 2077218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 2078218065Sadrian 2079218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 2080218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 2081218065Sadrian 2082218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 2083218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 2084218065Sadrian if (wh->i_fc[1] & IEEE80211_FC1_WEP) 2085218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 2086218065Sadrian if (m0->m_flags & M_FRAG) 2087218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 2088218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 2089218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 2090218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 2091218065Sadrian 2092218065Sadrian ieee80211_radiotap_tx(vap, m0); 2093218065Sadrian } 2094218065Sadrian 2095218065Sadrian /* 2096218065Sadrian * Formulate first tx descriptor with tx controls. 2097218065Sadrian */ 2098218065Sadrian ds = bf->bf_desc; 2099218065Sadrian /* XXX check return value? */ 2100227364Sadrian 2101227364Sadrian /* Store the decided rate index values away */ 2102227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 2103227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 2104227364Sadrian bf->bf_state.bfs_atype = atype; 2105227364Sadrian bf->bf_state.bfs_txpower = params->ibp_power; 2106227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 2107227364Sadrian bf->bf_state.bfs_try0 = try0; 2108227364Sadrian bf->bf_state.bfs_keyix = keyix; 2109227364Sadrian bf->bf_state.bfs_txantenna = txantenna; 2110233966Sadrian bf->bf_state.bfs_txflags = flags; 2111227364Sadrian bf->bf_state.bfs_shpream = 2112227364Sadrian !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE); 2113218065Sadrian 2114239051Sadrian /* Set local packet state, used to queue packets to hardware */ 2115239051Sadrian bf->bf_state.bfs_tid = WME_AC_TO_TID(pri); 2116244109Sadrian bf->bf_state.bfs_tx_queue = sc->sc_ac2q[pri]->axq_qnum; 2117239051Sadrian bf->bf_state.bfs_pri = pri; 2118239051Sadrian 2119227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 2120227364Sadrian bf->bf_state.bfs_ctsrate = 0; 2121227364Sadrian bf->bf_state.bfs_ctsduration = 0; 2122227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 2123218240Sadrian 2124227364Sadrian /* Blank the legacy rate array */ 2125227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 2126218240Sadrian 2127227364Sadrian bf->bf_state.bfs_rc[0].rix = 2128227364Sadrian ath_tx_findrix(sc, params->ibp_rate0); 2129227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 2130227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 2131227364Sadrian 2132227364Sadrian if (ismrr) { 2133227364Sadrian int rix; 2134227364Sadrian 2135227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate1); 2136227364Sadrian bf->bf_state.bfs_rc[1].rix = rix; 2137227364Sadrian bf->bf_state.bfs_rc[1].tries = params->ibp_try1; 2138227364Sadrian 2139227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate2); 2140227364Sadrian bf->bf_state.bfs_rc[2].rix = rix; 2141227364Sadrian bf->bf_state.bfs_rc[2].tries = params->ibp_try2; 2142227364Sadrian 2143227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate3); 2144227364Sadrian bf->bf_state.bfs_rc[3].rix = rix; 2145227364Sadrian bf->bf_state.bfs_rc[3].tries = params->ibp_try3; 2146218065Sadrian } 2147227364Sadrian /* 2148227364Sadrian * All the required rate control decisions have been made; 2149227364Sadrian * fill in the rc flags. 2150227364Sadrian */ 2151227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2152218065Sadrian 2153227364Sadrian /* NB: no buffered multicast in power save support */ 2154227364Sadrian 2155227364Sadrian /* 2156227364Sadrian * If we're overiding the ADDBA destination, dump directly 2157227364Sadrian * into the hardware queue, right after any pending 2158227364Sadrian * frames to that node are. 2159227364Sadrian */ 2160227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n", 2161227364Sadrian __func__, do_override); 2162227364Sadrian 2163240882Sadrian#if 1 2164227364Sadrian if (do_override) { 2165240724Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2166227364Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2167227364Sadrian } else { 2168227364Sadrian /* Queue to software queue */ 2169227364Sadrian ath_tx_swq(sc, ni, sc->sc_ac2q[pri], bf); 2170227364Sadrian } 2171240882Sadrian#else 2172240882Sadrian /* Direct-dispatch to the hardware */ 2173240882Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 2174240882Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 2175240882Sadrian#endif 2176218065Sadrian return 0; 2177218065Sadrian} 2178218065Sadrian 2179227364Sadrian/* 2180227364Sadrian * Send a raw frame. 2181227364Sadrian * 2182227364Sadrian * This can be called by net80211. 2183227364Sadrian */ 2184218065Sadrianint 2185218065Sadrianath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 2186218065Sadrian const struct ieee80211_bpf_params *params) 2187218065Sadrian{ 2188218065Sadrian struct ieee80211com *ic = ni->ni_ic; 2189218065Sadrian struct ifnet *ifp = ic->ic_ifp; 2190218065Sadrian struct ath_softc *sc = ifp->if_softc; 2191218065Sadrian struct ath_buf *bf; 2192232764Sadrian struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 2193232764Sadrian int error = 0; 2194218065Sadrian 2195227651Sadrian ATH_PCU_LOCK(sc); 2196227651Sadrian if (sc->sc_inreset_cnt > 0) { 2197227651Sadrian device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; bailing\n", 2198227651Sadrian __func__); 2199227651Sadrian error = EIO; 2200227651Sadrian ATH_PCU_UNLOCK(sc); 2201227651Sadrian goto bad0; 2202227651Sadrian } 2203227651Sadrian sc->sc_txstart_cnt++; 2204227651Sadrian ATH_PCU_UNLOCK(sc); 2205227651Sadrian 2206242391Sadrian ATH_TX_LOCK(sc); 2207242391Sadrian 2208218065Sadrian if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) { 2209218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__, 2210218065Sadrian (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ? 2211218065Sadrian "!running" : "invalid"); 2212218065Sadrian m_freem(m); 2213218065Sadrian error = ENETDOWN; 2214218065Sadrian goto bad; 2215218065Sadrian } 2216232764Sadrian 2217218065Sadrian /* 2218232764Sadrian * Enforce how deep the multicast queue can grow. 2219232764Sadrian * 2220232764Sadrian * XXX duplicated in ath_tx_start(). 2221232764Sadrian */ 2222232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 2223232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 2224232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 2225232764Sadrian error = ENOBUFS; 2226232764Sadrian } 2227232764Sadrian 2228232764Sadrian if (error != 0) { 2229232764Sadrian m_freem(m); 2230232764Sadrian goto bad; 2231232764Sadrian } 2232232764Sadrian } 2233232764Sadrian 2234232764Sadrian /* 2235218065Sadrian * Grab a TX buffer and associated resources. 2236218065Sadrian */ 2237237000Sadrian bf = ath_getbuf(sc, ATH_BUFTYPE_MGMT); 2238218065Sadrian if (bf == NULL) { 2239218065Sadrian sc->sc_stats.ast_tx_nobuf++; 2240218065Sadrian m_freem(m); 2241218065Sadrian error = ENOBUFS; 2242218065Sadrian goto bad; 2243218065Sadrian } 2244240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: m=%p, params=%p, bf=%p\n", 2245240899Sadrian m, params, bf); 2246218065Sadrian 2247218065Sadrian if (params == NULL) { 2248218065Sadrian /* 2249218065Sadrian * Legacy path; interpret frame contents to decide 2250218065Sadrian * precisely how to send the frame. 2251218065Sadrian */ 2252218065Sadrian if (ath_tx_start(sc, ni, bf, m)) { 2253218065Sadrian error = EIO; /* XXX */ 2254218065Sadrian goto bad2; 2255218065Sadrian } 2256218065Sadrian } else { 2257218065Sadrian /* 2258218065Sadrian * Caller supplied explicit parameters to use in 2259218065Sadrian * sending the frame. 2260218065Sadrian */ 2261218065Sadrian if (ath_tx_raw_start(sc, ni, bf, m, params)) { 2262218065Sadrian error = EIO; /* XXX */ 2263218065Sadrian goto bad2; 2264218065Sadrian } 2265218065Sadrian } 2266218065Sadrian sc->sc_wd_timer = 5; 2267218065Sadrian ifp->if_opackets++; 2268218065Sadrian sc->sc_stats.ast_tx_raw++; 2269218065Sadrian 2270242271Sadrian /* 2271242271Sadrian * Update the TIM - if there's anything queued to the 2272242271Sadrian * software queue and power save is enabled, we should 2273242271Sadrian * set the TIM. 2274242271Sadrian */ 2275242271Sadrian ath_tx_update_tim(sc, ni, 1); 2276242271Sadrian 2277243787Sadrian ATH_TX_UNLOCK(sc); 2278243787Sadrian 2279227651Sadrian ATH_PCU_LOCK(sc); 2280227651Sadrian sc->sc_txstart_cnt--; 2281227651Sadrian ATH_PCU_UNLOCK(sc); 2282227651Sadrian 2283218065Sadrian return 0; 2284218065Sadrianbad2: 2285240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 3, "ath_raw_xmit: bad2: m=%p, params=%p, " 2286240899Sadrian "bf=%p", 2287240899Sadrian m, 2288240899Sadrian params, 2289240899Sadrian bf); 2290218065Sadrian ATH_TXBUF_LOCK(sc); 2291236993Sadrian ath_returnbuf_head(sc, bf); 2292218065Sadrian ATH_TXBUF_UNLOCK(sc); 2293218065Sadrianbad: 2294242391Sadrian 2295242391Sadrian ATH_TX_UNLOCK(sc); 2296242391Sadrian 2297227651Sadrian ATH_PCU_LOCK(sc); 2298227651Sadrian sc->sc_txstart_cnt--; 2299227651Sadrian ATH_PCU_UNLOCK(sc); 2300227651Sadrianbad0: 2301240899Sadrian ATH_KTR(sc, ATH_KTR_TX, 2, "ath_raw_xmit: bad0: m=%p, params=%p", 2302240899Sadrian m, params); 2303218065Sadrian ifp->if_oerrors++; 2304218065Sadrian sc->sc_stats.ast_tx_raw_fail++; 2305218065Sadrian ieee80211_free_node(ni); 2306227651Sadrian 2307218065Sadrian return error; 2308218065Sadrian} 2309227364Sadrian 2310227364Sadrian/* Some helper functions */ 2311227364Sadrian 2312227364Sadrian/* 2313227364Sadrian * ADDBA (and potentially others) need to be placed in the same 2314227364Sadrian * hardware queue as the TID/node it's relating to. This is so 2315227364Sadrian * it goes out after any pending non-aggregate frames to the 2316227364Sadrian * same node/TID. 2317227364Sadrian * 2318227364Sadrian * If this isn't done, the ADDBA can go out before the frames 2319227364Sadrian * queued in hardware. Even though these frames have a sequence 2320227364Sadrian * number -earlier- than the ADDBA can be transmitted (but 2321227364Sadrian * no frames whose sequence numbers are after the ADDBA should 2322227364Sadrian * be!) they'll arrive after the ADDBA - and the receiving end 2323227364Sadrian * will simply drop them as being out of the BAW. 2324227364Sadrian * 2325227364Sadrian * The frames can't be appended to the TID software queue - it'll 2326227364Sadrian * never be sent out. So these frames have to be directly 2327227364Sadrian * dispatched to the hardware, rather than queued in software. 2328227364Sadrian * So if this function returns true, the TXQ has to be 2329227364Sadrian * overridden and it has to be directly dispatched. 2330227364Sadrian * 2331227364Sadrian * It's a dirty hack, but someone's gotta do it. 2332227364Sadrian */ 2333227364Sadrian 2334227364Sadrian/* 2335227364Sadrian * XXX doesn't belong here! 2336227364Sadrian */ 2337227364Sadrianstatic int 2338227364Sadrianieee80211_is_action(struct ieee80211_frame *wh) 2339227364Sadrian{ 2340227364Sadrian /* Type: Management frame? */ 2341227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != 2342227364Sadrian IEEE80211_FC0_TYPE_MGT) 2343227364Sadrian return 0; 2344227364Sadrian 2345227364Sadrian /* Subtype: Action frame? */ 2346227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) != 2347227364Sadrian IEEE80211_FC0_SUBTYPE_ACTION) 2348227364Sadrian return 0; 2349227364Sadrian 2350227364Sadrian return 1; 2351227364Sadrian} 2352227364Sadrian 2353227364Sadrian#define MS(_v, _f) (((_v) & _f) >> _f##_S) 2354227364Sadrian/* 2355227364Sadrian * Return an alternate TID for ADDBA request frames. 2356227364Sadrian * 2357227364Sadrian * Yes, this likely should be done in the net80211 layer. 2358227364Sadrian */ 2359227364Sadrianstatic int 2360227364Sadrianath_tx_action_frame_override_queue(struct ath_softc *sc, 2361227364Sadrian struct ieee80211_node *ni, 2362227364Sadrian struct mbuf *m0, int *tid) 2363227364Sadrian{ 2364227364Sadrian struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *); 2365227364Sadrian struct ieee80211_action_ba_addbarequest *ia; 2366227364Sadrian uint8_t *frm; 2367227364Sadrian uint16_t baparamset; 2368227364Sadrian 2369227364Sadrian /* Not action frame? Bail */ 2370227364Sadrian if (! ieee80211_is_action(wh)) 2371227364Sadrian return 0; 2372227364Sadrian 2373227364Sadrian /* XXX Not needed for frames we send? */ 2374227364Sadrian#if 0 2375227364Sadrian /* Correct length? */ 2376227364Sadrian if (! ieee80211_parse_action(ni, m)) 2377227364Sadrian return 0; 2378227364Sadrian#endif 2379227364Sadrian 2380227364Sadrian /* Extract out action frame */ 2381227364Sadrian frm = (u_int8_t *)&wh[1]; 2382227364Sadrian ia = (struct ieee80211_action_ba_addbarequest *) frm; 2383227364Sadrian 2384227364Sadrian /* Not ADDBA? Bail */ 2385227364Sadrian if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA) 2386227364Sadrian return 0; 2387227364Sadrian if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST) 2388227364Sadrian return 0; 2389227364Sadrian 2390227364Sadrian /* Extract TID, return it */ 2391227364Sadrian baparamset = le16toh(ia->rq_baparamset); 2392227364Sadrian *tid = (int) MS(baparamset, IEEE80211_BAPS_TID); 2393227364Sadrian 2394227364Sadrian return 1; 2395227364Sadrian} 2396227364Sadrian#undef MS 2397227364Sadrian 2398227364Sadrian/* Per-node software queue operations */ 2399227364Sadrian 2400227364Sadrian/* 2401227364Sadrian * Add the current packet to the given BAW. 2402227364Sadrian * It is assumed that the current packet 2403227364Sadrian * 2404227364Sadrian * + fits inside the BAW; 2405227364Sadrian * + already has had a sequence number allocated. 2406227364Sadrian * 2407227364Sadrian * Since the BAW status may be modified by both the ath task and 2408227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2409227364Sadrian */ 2410227364Sadrianvoid 2411227364Sadrianath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an, 2412227364Sadrian struct ath_tid *tid, struct ath_buf *bf) 2413227364Sadrian{ 2414227364Sadrian int index, cindex; 2415227364Sadrian struct ieee80211_tx_ampdu *tap; 2416227364Sadrian 2417243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2418227364Sadrian 2419227364Sadrian if (bf->bf_state.bfs_isretried) 2420227364Sadrian return; 2421227364Sadrian 2422236886Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2423236886Sadrian 2424236880Sadrian if (! bf->bf_state.bfs_dobaw) { 2425236880Sadrian device_printf(sc->sc_dev, 2426236880Sadrian "%s: dobaw=0, seqno=%d, window %d:%d\n", 2427236880Sadrian __func__, 2428236880Sadrian SEQNO(bf->bf_state.bfs_seqno), 2429236880Sadrian tap->txa_start, 2430236880Sadrian tap->txa_wnd); 2431236880Sadrian } 2432236880Sadrian 2433227364Sadrian if (bf->bf_state.bfs_addedbaw) 2434227364Sadrian device_printf(sc->sc_dev, 2435236872Sadrian "%s: re-added? tid=%d, seqno %d; window %d:%d; " 2436229949Sadrian "baw head=%d tail=%d\n", 2437236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2438229949Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2439229949Sadrian tid->baw_tail); 2440227364Sadrian 2441227364Sadrian /* 2442236880Sadrian * Verify that the given sequence number is not outside of the 2443236880Sadrian * BAW. Complain loudly if that's the case. 2444236880Sadrian */ 2445236880Sadrian if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2446236880Sadrian SEQNO(bf->bf_state.bfs_seqno))) { 2447236880Sadrian device_printf(sc->sc_dev, 2448236880Sadrian "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; " 2449236880Sadrian "baw head=%d tail=%d\n", 2450236880Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2451236880Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2452236880Sadrian tid->baw_tail); 2453236880Sadrian } 2454236880Sadrian 2455236880Sadrian /* 2456227364Sadrian * ni->ni_txseqs[] is the currently allocated seqno. 2457227364Sadrian * the txa state contains the current baw start. 2458227364Sadrian */ 2459227364Sadrian index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno)); 2460227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2461227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2462236872Sadrian "%s: tid=%d, seqno %d; window %d:%d; index=%d cindex=%d " 2463229949Sadrian "baw head=%d tail=%d\n", 2464236872Sadrian __func__, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2465229949Sadrian tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head, 2466229949Sadrian tid->baw_tail); 2467227364Sadrian 2468227364Sadrian 2469227364Sadrian#if 0 2470227364Sadrian assert(tid->tx_buf[cindex] == NULL); 2471227364Sadrian#endif 2472227364Sadrian if (tid->tx_buf[cindex] != NULL) { 2473227364Sadrian device_printf(sc->sc_dev, 2474227364Sadrian "%s: ba packet dup (index=%d, cindex=%d, " 2475227364Sadrian "head=%d, tail=%d)\n", 2476227364Sadrian __func__, index, cindex, tid->baw_head, tid->baw_tail); 2477227364Sadrian device_printf(sc->sc_dev, 2478227364Sadrian "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n", 2479227364Sadrian __func__, 2480227364Sadrian tid->tx_buf[cindex], 2481227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno), 2482227364Sadrian bf, 2483227364Sadrian SEQNO(bf->bf_state.bfs_seqno) 2484227364Sadrian ); 2485227364Sadrian } 2486227364Sadrian tid->tx_buf[cindex] = bf; 2487227364Sadrian 2488229949Sadrian if (index >= ((tid->baw_tail - tid->baw_head) & 2489229949Sadrian (ATH_TID_MAX_BUFS - 1))) { 2490227364Sadrian tid->baw_tail = cindex; 2491227364Sadrian INCR(tid->baw_tail, ATH_TID_MAX_BUFS); 2492227364Sadrian } 2493227364Sadrian} 2494227364Sadrian 2495227364Sadrian/* 2496227398Sadrian * Flip the BAW buffer entry over from the existing one to the new one. 2497227398Sadrian * 2498227398Sadrian * When software retransmitting a (sub-)frame, it is entirely possible that 2499227398Sadrian * the frame ath_buf is marked as BUSY and can't be immediately reused. 2500227398Sadrian * In that instance the buffer is cloned and the new buffer is used for 2501227398Sadrian * retransmit. We thus need to update the ath_buf slot in the BAW buf 2502227398Sadrian * tracking array to maintain consistency. 2503227398Sadrian */ 2504227398Sadrianstatic void 2505227398Sadrianath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an, 2506227398Sadrian struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf) 2507227398Sadrian{ 2508227398Sadrian int index, cindex; 2509227398Sadrian struct ieee80211_tx_ampdu *tap; 2510227398Sadrian int seqno = SEQNO(old_bf->bf_state.bfs_seqno); 2511227398Sadrian 2512243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2513227398Sadrian 2514227398Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2515227398Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2516227398Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2517227398Sadrian 2518227398Sadrian /* 2519227398Sadrian * Just warn for now; if it happens then we should find out 2520227398Sadrian * about it. It's highly likely the aggregation session will 2521227398Sadrian * soon hang. 2522227398Sadrian */ 2523227398Sadrian if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) { 2524227398Sadrian device_printf(sc->sc_dev, "%s: retransmitted buffer" 2525227398Sadrian " has mismatching seqno's, BA session may hang.\n", 2526227398Sadrian __func__); 2527227398Sadrian device_printf(sc->sc_dev, "%s: old seqno=%d, new_seqno=%d\n", 2528227398Sadrian __func__, 2529227398Sadrian old_bf->bf_state.bfs_seqno, 2530227398Sadrian new_bf->bf_state.bfs_seqno); 2531227398Sadrian } 2532227398Sadrian 2533227398Sadrian if (tid->tx_buf[cindex] != old_bf) { 2534227398Sadrian device_printf(sc->sc_dev, "%s: ath_buf pointer incorrect; " 2535227398Sadrian " has m BA session may hang.\n", 2536227398Sadrian __func__); 2537227398Sadrian device_printf(sc->sc_dev, "%s: old bf=%p, new bf=%p\n", 2538227398Sadrian __func__, 2539227398Sadrian old_bf, new_bf); 2540227398Sadrian } 2541227398Sadrian 2542227398Sadrian tid->tx_buf[cindex] = new_bf; 2543227398Sadrian} 2544227398Sadrian 2545227398Sadrian/* 2546227364Sadrian * seq_start - left edge of BAW 2547227364Sadrian * seq_next - current/next sequence number to allocate 2548227364Sadrian * 2549227364Sadrian * Since the BAW status may be modified by both the ath task and 2550227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2551227364Sadrian */ 2552227364Sadrianstatic void 2553227364Sadrianath_tx_update_baw(struct ath_softc *sc, struct ath_node *an, 2554227364Sadrian struct ath_tid *tid, const struct ath_buf *bf) 2555227364Sadrian{ 2556227364Sadrian int index, cindex; 2557227364Sadrian struct ieee80211_tx_ampdu *tap; 2558227364Sadrian int seqno = SEQNO(bf->bf_state.bfs_seqno); 2559227364Sadrian 2560243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2561227364Sadrian 2562227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2563227364Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2564227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2565227364Sadrian 2566227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2567236872Sadrian "%s: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, " 2568229949Sadrian "baw head=%d, tail=%d\n", 2569236872Sadrian __func__, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index, 2570227364Sadrian cindex, tid->baw_head, tid->baw_tail); 2571227364Sadrian 2572227364Sadrian /* 2573227364Sadrian * If this occurs then we have a big problem - something else 2574227364Sadrian * has slid tap->txa_start along without updating the BAW 2575227364Sadrian * tracking start/end pointers. Thus the TX BAW state is now 2576227364Sadrian * completely busted. 2577227364Sadrian * 2578227364Sadrian * But for now, since I haven't yet fixed TDMA and buffer cloning, 2579227364Sadrian * it's quite possible that a cloned buffer is making its way 2580227364Sadrian * here and causing it to fire off. Disable TDMA for now. 2581227364Sadrian */ 2582227364Sadrian if (tid->tx_buf[cindex] != bf) { 2583227364Sadrian device_printf(sc->sc_dev, 2584227364Sadrian "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n", 2585227364Sadrian __func__, 2586227364Sadrian bf, SEQNO(bf->bf_state.bfs_seqno), 2587227364Sadrian tid->tx_buf[cindex], 2588227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno)); 2589227364Sadrian } 2590227364Sadrian 2591227364Sadrian tid->tx_buf[cindex] = NULL; 2592227364Sadrian 2593229949Sadrian while (tid->baw_head != tid->baw_tail && 2594229949Sadrian !tid->tx_buf[tid->baw_head]) { 2595227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 2596227364Sadrian INCR(tid->baw_head, ATH_TID_MAX_BUFS); 2597227364Sadrian } 2598229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2599229949Sadrian "%s: baw is now %d:%d, baw head=%d\n", 2600227364Sadrian __func__, tap->txa_start, tap->txa_wnd, tid->baw_head); 2601227364Sadrian} 2602227364Sadrian 2603227364Sadrian/* 2604227364Sadrian * Mark the current node/TID as ready to TX. 2605227364Sadrian * 2606227364Sadrian * This is done to make it easy for the software scheduler to 2607227364Sadrian * find which nodes have data to send. 2608227364Sadrian * 2609227364Sadrian * The TXQ lock must be held. 2610227364Sadrian */ 2611227364Sadrianstatic void 2612227364Sadrianath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid) 2613227364Sadrian{ 2614227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2615227364Sadrian 2616243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2617227364Sadrian 2618227364Sadrian if (tid->paused) 2619227364Sadrian return; /* paused, can't schedule yet */ 2620227364Sadrian 2621227364Sadrian if (tid->sched) 2622227364Sadrian return; /* already scheduled */ 2623227364Sadrian 2624227364Sadrian tid->sched = 1; 2625227364Sadrian 2626227364Sadrian TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem); 2627227364Sadrian} 2628227364Sadrian 2629227364Sadrian/* 2630227364Sadrian * Mark the current node as no longer needing to be polled for 2631227364Sadrian * TX packets. 2632227364Sadrian * 2633227364Sadrian * The TXQ lock must be held. 2634227364Sadrian */ 2635227364Sadrianstatic void 2636227364Sadrianath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid) 2637227364Sadrian{ 2638227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2639227364Sadrian 2640243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2641227364Sadrian 2642227364Sadrian if (tid->sched == 0) 2643227364Sadrian return; 2644227364Sadrian 2645227364Sadrian tid->sched = 0; 2646227364Sadrian TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem); 2647227364Sadrian} 2648227364Sadrian 2649227364Sadrian/* 2650227364Sadrian * Assign a sequence number manually to the given frame. 2651227364Sadrian * 2652227364Sadrian * This should only be called for A-MPDU TX frames. 2653227364Sadrian */ 2654236872Sadrianstatic ieee80211_seq 2655227364Sadrianath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni, 2656227364Sadrian struct ath_buf *bf, struct mbuf *m0) 2657227364Sadrian{ 2658227364Sadrian struct ieee80211_frame *wh; 2659227364Sadrian int tid, pri; 2660227364Sadrian ieee80211_seq seqno; 2661227364Sadrian uint8_t subtype; 2662227364Sadrian 2663227364Sadrian /* TID lookup */ 2664227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2665227364Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 2666227364Sadrian tid = WME_AC_TO_TID(pri); 2667236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pri=%d, tid=%d, qos has seq=%d\n", 2668236872Sadrian __func__, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2669227364Sadrian 2670227364Sadrian /* XXX Is it a control frame? Ignore */ 2671227364Sadrian 2672227364Sadrian /* Does the packet require a sequence number? */ 2673227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 2674227364Sadrian return -1; 2675227364Sadrian 2676243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2677236880Sadrian 2678227364Sadrian /* 2679227364Sadrian * Is it a QOS NULL Data frame? Give it a sequence number from 2680227364Sadrian * the default TID (IEEE80211_NONQOS_TID.) 2681227364Sadrian * 2682227364Sadrian * The RX path of everything I've looked at doesn't include the NULL 2683227364Sadrian * data frame sequence number in the aggregation state updates, so 2684227364Sadrian * assigning it a sequence number there will cause a BAW hole on the 2685227364Sadrian * RX side. 2686227364Sadrian */ 2687227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2688227364Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) { 2689236880Sadrian /* XXX no locking for this TID? This is a bit of a problem. */ 2690227364Sadrian seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 2691227364Sadrian INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE); 2692227364Sadrian } else { 2693227364Sadrian /* Manually assign sequence number */ 2694227364Sadrian seqno = ni->ni_txseqs[tid]; 2695227364Sadrian INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE); 2696227364Sadrian } 2697227364Sadrian *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); 2698227364Sadrian M_SEQNO_SET(m0, seqno); 2699227364Sadrian 2700227364Sadrian /* Return so caller can do something with it if needed */ 2701236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: -> seqno=%d\n", __func__, seqno); 2702227364Sadrian return seqno; 2703227364Sadrian} 2704227364Sadrian 2705227364Sadrian/* 2706227364Sadrian * Attempt to direct dispatch an aggregate frame to hardware. 2707227364Sadrian * If the frame is out of BAW, queue. 2708227364Sadrian * Otherwise, schedule it as a single frame. 2709227364Sadrian */ 2710227364Sadrianstatic void 2711239051Sadrianath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an, 2712239051Sadrian struct ath_txq *txq, struct ath_buf *bf) 2713227364Sadrian{ 2714227364Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 2715227364Sadrian struct ieee80211_tx_ampdu *tap; 2716227364Sadrian 2717243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2718227364Sadrian 2719227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2720227364Sadrian 2721227364Sadrian /* paused? queue */ 2722227364Sadrian if (tid->paused) { 2723241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 2724233480Sadrian /* XXX don't sched - we're paused! */ 2725227364Sadrian return; 2726227364Sadrian } 2727227364Sadrian 2728227364Sadrian /* outside baw? queue */ 2729227364Sadrian if (bf->bf_state.bfs_dobaw && 2730227364Sadrian (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2731227364Sadrian SEQNO(bf->bf_state.bfs_seqno)))) { 2732241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 2733227364Sadrian ath_tx_tid_sched(sc, tid); 2734227364Sadrian return; 2735227364Sadrian } 2736227364Sadrian 2737240180Sadrian /* 2738240180Sadrian * This is a temporary check and should be removed once 2739240180Sadrian * all the relevant code paths have been fixed. 2740240180Sadrian * 2741240180Sadrian * During aggregate retries, it's possible that the head 2742240180Sadrian * frame will fail (which has the bfs_aggr and bfs_nframes 2743240180Sadrian * fields set for said aggregate) and will be retried as 2744240180Sadrian * a single frame. In this instance, the values should 2745240180Sadrian * be reset or the completion code will get upset with you. 2746240180Sadrian */ 2747240180Sadrian if (bf->bf_state.bfs_aggr != 0 || bf->bf_state.bfs_nframes > 1) { 2748240180Sadrian device_printf(sc->sc_dev, "%s: bfs_aggr=%d, bfs_nframes=%d\n", 2749240180Sadrian __func__, 2750240180Sadrian bf->bf_state.bfs_aggr, 2751240180Sadrian bf->bf_state.bfs_nframes); 2752240180Sadrian bf->bf_state.bfs_aggr = 0; 2753240180Sadrian bf->bf_state.bfs_nframes = 1; 2754240180Sadrian } 2755240180Sadrian 2756240724Sadrian /* Update CLRDMASK just before this frame is queued */ 2757240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 2758240724Sadrian 2759227364Sadrian /* Direct dispatch to hardware */ 2760227364Sadrian ath_tx_do_ratelookup(sc, bf); 2761233989Sadrian ath_tx_calc_duration(sc, bf); 2762233989Sadrian ath_tx_calc_protection(sc, bf); 2763233989Sadrian ath_tx_set_rtscts(sc, bf); 2764227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2765227364Sadrian ath_tx_setds(sc, bf); 2766227364Sadrian 2767227364Sadrian /* Statistics */ 2768227364Sadrian sc->sc_aggr_stats.aggr_low_hwq_single_pkt++; 2769227364Sadrian 2770227364Sadrian /* Track per-TID hardware queue depth correctly */ 2771227364Sadrian tid->hwq_depth++; 2772227364Sadrian 2773227364Sadrian /* Add to BAW */ 2774227364Sadrian if (bf->bf_state.bfs_dobaw) { 2775227364Sadrian ath_tx_addto_baw(sc, an, tid, bf); 2776227364Sadrian bf->bf_state.bfs_addedbaw = 1; 2777227364Sadrian } 2778227364Sadrian 2779227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 2780227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 2781227364Sadrian 2782227364Sadrian /* Hand off to hardware */ 2783227364Sadrian ath_tx_handoff(sc, txq, bf); 2784227364Sadrian} 2785227364Sadrian 2786227364Sadrian/* 2787227364Sadrian * Attempt to send the packet. 2788227364Sadrian * If the queue isn't busy, direct-dispatch. 2789227364Sadrian * If the queue is busy enough, queue the given packet on the 2790227364Sadrian * relevant software queue. 2791227364Sadrian */ 2792227364Sadrianvoid 2793227364Sadrianath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_txq *txq, 2794227364Sadrian struct ath_buf *bf) 2795227364Sadrian{ 2796227364Sadrian struct ath_node *an = ATH_NODE(ni); 2797227364Sadrian struct ieee80211_frame *wh; 2798227364Sadrian struct ath_tid *atid; 2799227364Sadrian int pri, tid; 2800227364Sadrian struct mbuf *m0 = bf->bf_m; 2801227364Sadrian 2802243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2803236880Sadrian 2804227364Sadrian /* Fetch the TID - non-QoS frames get assigned to TID 16 */ 2805227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2806227364Sadrian pri = ath_tx_getac(sc, m0); 2807227364Sadrian tid = ath_tx_gettid(sc, m0); 2808227364Sadrian atid = &an->an_tid[tid]; 2809227364Sadrian 2810236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d\n", 2811236872Sadrian __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2812227364Sadrian 2813227364Sadrian /* Set local packet state, used to queue packets to hardware */ 2814239051Sadrian /* XXX potentially duplicate info, re-check */ 2815227364Sadrian bf->bf_state.bfs_tid = tid; 2816244109Sadrian bf->bf_state.bfs_tx_queue = txq->axq_qnum; 2817227364Sadrian bf->bf_state.bfs_pri = pri; 2818227364Sadrian 2819227364Sadrian /* 2820227364Sadrian * If the hardware queue isn't busy, queue it directly. 2821227364Sadrian * If the hardware queue is busy, queue it. 2822227364Sadrian * If the TID is paused or the traffic it outside BAW, software 2823227364Sadrian * queue it. 2824227364Sadrian */ 2825227364Sadrian if (atid->paused) { 2826227364Sadrian /* TID is paused, queue */ 2827236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: paused\n", __func__); 2828241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2829227364Sadrian } else if (ath_tx_ampdu_pending(sc, an, tid)) { 2830227364Sadrian /* AMPDU pending; queue */ 2831236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: pending\n", __func__); 2832241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2833227364Sadrian /* XXX sched? */ 2834227364Sadrian } else if (ath_tx_ampdu_running(sc, an, tid)) { 2835227364Sadrian /* AMPDU running, attempt direct dispatch if possible */ 2836236877Sadrian 2837236877Sadrian /* 2838236877Sadrian * Always queue the frame to the tail of the list. 2839236877Sadrian */ 2840241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2841236877Sadrian 2842236877Sadrian /* 2843236877Sadrian * If the hardware queue isn't busy, direct dispatch 2844236877Sadrian * the head frame in the list. Don't schedule the 2845236877Sadrian * TID - let it build some more frames first? 2846236877Sadrian * 2847236877Sadrian * Otherwise, schedule the TID. 2848236877Sadrian */ 2849229949Sadrian if (txq->axq_depth < sc->sc_hwq_limit) { 2850241336Sadrian bf = ATH_TID_FIRST(atid); 2851241336Sadrian ATH_TID_REMOVE(atid, bf, bf_list); 2852240180Sadrian 2853240180Sadrian /* 2854240180Sadrian * Ensure it's definitely treated as a non-AMPDU 2855240180Sadrian * frame - this information may have been left 2856240180Sadrian * over from a previous attempt. 2857240180Sadrian */ 2858240180Sadrian bf->bf_state.bfs_aggr = 0; 2859240180Sadrian bf->bf_state.bfs_nframes = 1; 2860240180Sadrian 2861240180Sadrian /* Queue to the hardware */ 2862239051Sadrian ath_tx_xmit_aggr(sc, an, txq, bf); 2863233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2864236872Sadrian "%s: xmit_aggr\n", 2865236872Sadrian __func__); 2866229949Sadrian } else { 2867229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2868236872Sadrian "%s: ampdu; swq'ing\n", 2869236872Sadrian __func__); 2870240899Sadrian 2871227364Sadrian ath_tx_tid_sched(sc, atid); 2872227364Sadrian } 2873227364Sadrian } else if (txq->axq_depth < sc->sc_hwq_limit) { 2874227364Sadrian /* AMPDU not running, attempt direct dispatch */ 2875236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: xmit_normal\n", __func__); 2876240926Sadrian /* See if clrdmask needs to be set */ 2877240926Sadrian ath_tx_update_clrdmask(sc, atid, bf); 2878227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 2879227364Sadrian } else { 2880227364Sadrian /* Busy; queue */ 2881236872Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: swq'ing\n", __func__); 2882241336Sadrian ATH_TID_INSERT_TAIL(atid, bf, bf_list); 2883227364Sadrian ath_tx_tid_sched(sc, atid); 2884227364Sadrian } 2885227364Sadrian} 2886227364Sadrian 2887227364Sadrian/* 2888245708Sadrian * Only set the clrdmask bit if none of the nodes are currently 2889245708Sadrian * filtered. 2890245708Sadrian * 2891245708Sadrian * XXX TODO: go through all the callers and check to see 2892245708Sadrian * which are being called in the context of looping over all 2893245708Sadrian * TIDs (eg, if all tids are being paused, resumed, etc.) 2894245708Sadrian * That'll avoid O(n^2) complexity here. 2895245708Sadrian */ 2896245708Sadrianstatic void 2897245708Sadrianath_tx_set_clrdmask(struct ath_softc *sc, struct ath_node *an) 2898245708Sadrian{ 2899245708Sadrian int i; 2900245708Sadrian 2901245708Sadrian ATH_TX_LOCK_ASSERT(sc); 2902245708Sadrian 2903245708Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2904245708Sadrian if (an->an_tid[i].isfiltered == 1) 2905245739Sadrian return; 2906245708Sadrian } 2907245708Sadrian an->clrdmask = 1; 2908245708Sadrian} 2909245708Sadrian 2910245708Sadrian/* 2911227364Sadrian * Configure the per-TID node state. 2912227364Sadrian * 2913227364Sadrian * This likely belongs in if_ath_node.c but I can't think of anywhere 2914227364Sadrian * else to put it just yet. 2915227364Sadrian * 2916227364Sadrian * This sets up the SLISTs and the mutex as appropriate. 2917227364Sadrian */ 2918227364Sadrianvoid 2919227364Sadrianath_tx_tid_init(struct ath_softc *sc, struct ath_node *an) 2920227364Sadrian{ 2921227364Sadrian int i, j; 2922227364Sadrian struct ath_tid *atid; 2923227364Sadrian 2924227364Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2925227364Sadrian atid = &an->an_tid[i]; 2926240639Sadrian 2927240639Sadrian /* XXX now with this bzer(), is the field 0'ing needed? */ 2928240639Sadrian bzero(atid, sizeof(*atid)); 2929240639Sadrian 2930241336Sadrian TAILQ_INIT(&atid->tid_q); 2931241336Sadrian TAILQ_INIT(&atid->filtq.tid_q); 2932227364Sadrian atid->tid = i; 2933227364Sadrian atid->an = an; 2934227364Sadrian for (j = 0; j < ATH_TID_MAX_BUFS; j++) 2935227364Sadrian atid->tx_buf[j] = NULL; 2936227364Sadrian atid->baw_head = atid->baw_tail = 0; 2937227364Sadrian atid->paused = 0; 2938227364Sadrian atid->sched = 0; 2939227364Sadrian atid->hwq_depth = 0; 2940227364Sadrian atid->cleanup_inprogress = 0; 2941227364Sadrian if (i == IEEE80211_NONQOS_TID) 2942240946Sadrian atid->ac = ATH_NONQOS_TID_AC; 2943227364Sadrian else 2944227364Sadrian atid->ac = TID_TO_WME_AC(i); 2945227364Sadrian } 2946245708Sadrian an->clrdmask = 1; /* Always start by setting this bit */ 2947227364Sadrian} 2948227364Sadrian 2949227364Sadrian/* 2950227364Sadrian * Pause the current TID. This stops packets from being transmitted 2951227364Sadrian * on it. 2952227364Sadrian * 2953227364Sadrian * Since this is also called from upper layers as well as the driver, 2954227364Sadrian * it will get the TID lock. 2955227364Sadrian */ 2956227364Sadrianstatic void 2957227364Sadrianath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid) 2958227364Sadrian{ 2959233908Sadrian 2960243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2961227364Sadrian tid->paused++; 2962227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n", 2963227364Sadrian __func__, tid->paused); 2964227364Sadrian} 2965227364Sadrian 2966227364Sadrian/* 2967227364Sadrian * Unpause the current TID, and schedule it if needed. 2968227364Sadrian */ 2969227364Sadrianstatic void 2970227364Sadrianath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid) 2971227364Sadrian{ 2972243786Sadrian ATH_TX_LOCK_ASSERT(sc); 2973243786Sadrian 2974227364Sadrian tid->paused--; 2975227364Sadrian 2976227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n", 2977227364Sadrian __func__, tid->paused); 2978227364Sadrian 2979241170Sadrian if (tid->paused) 2980227364Sadrian return; 2981227364Sadrian 2982241170Sadrian /* 2983241170Sadrian * Override the clrdmask configuration for the next frame 2984241170Sadrian * from this TID, just to get the ball rolling. 2985241170Sadrian */ 2986245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 2987241170Sadrian 2988241170Sadrian if (tid->axq_depth == 0) 2989241170Sadrian return; 2990241170Sadrian 2991240639Sadrian /* XXX isfiltered shouldn't ever be 0 at this point */ 2992240639Sadrian if (tid->isfiltered == 1) { 2993240639Sadrian device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 2994240639Sadrian return; 2995240639Sadrian } 2996240639Sadrian 2997227364Sadrian ath_tx_tid_sched(sc, tid); 2998246450Sadrian 2999246450Sadrian /* 3000246450Sadrian * Queue the software TX scheduler. 3001246450Sadrian */ 3002246450Sadrian ath_tx_swq_kick(sc); 3003227364Sadrian} 3004227364Sadrian 3005227364Sadrian/* 3006240639Sadrian * Add the given ath_buf to the TID filtered frame list. 3007240639Sadrian * This requires the TID be filtered. 3008240639Sadrian */ 3009240639Sadrianstatic void 3010240639Sadrianath_tx_tid_filt_addbuf(struct ath_softc *sc, struct ath_tid *tid, 3011240639Sadrian struct ath_buf *bf) 3012240639Sadrian{ 3013240639Sadrian 3014243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3015243786Sadrian 3016240639Sadrian if (! tid->isfiltered) 3017240639Sadrian device_printf(sc->sc_dev, "%s: not filtered?!\n", __func__); 3018240639Sadrian 3019240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: bf=%p\n", __func__, bf); 3020240639Sadrian 3021240639Sadrian /* Set the retry bit and bump the retry counter */ 3022240639Sadrian ath_tx_set_retry(sc, bf); 3023240639Sadrian sc->sc_stats.ast_tx_swfiltered++; 3024240639Sadrian 3025241566Sadrian ATH_TID_FILT_INSERT_TAIL(tid, bf, bf_list); 3026240639Sadrian} 3027240639Sadrian 3028240639Sadrian/* 3029240639Sadrian * Handle a completed filtered frame from the given TID. 3030240639Sadrian * This just enables/pauses the filtered frame state if required 3031240639Sadrian * and appends the filtered frame to the filtered queue. 3032240639Sadrian */ 3033240639Sadrianstatic void 3034240639Sadrianath_tx_tid_filt_comp_buf(struct ath_softc *sc, struct ath_tid *tid, 3035240639Sadrian struct ath_buf *bf) 3036240639Sadrian{ 3037240639Sadrian 3038243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3039240639Sadrian 3040240639Sadrian if (! tid->isfiltered) { 3041240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: filter transition\n", 3042240639Sadrian __func__); 3043240639Sadrian tid->isfiltered = 1; 3044240639Sadrian ath_tx_tid_pause(sc, tid); 3045240639Sadrian } 3046240639Sadrian 3047240639Sadrian /* Add the frame to the filter queue */ 3048240639Sadrian ath_tx_tid_filt_addbuf(sc, tid, bf); 3049240639Sadrian} 3050240639Sadrian 3051240639Sadrian/* 3052240639Sadrian * Complete the filtered frame TX completion. 3053240639Sadrian * 3054240639Sadrian * If there are no more frames in the hardware queue, unpause/unfilter 3055240639Sadrian * the TID if applicable. Otherwise we will wait for a node PS transition 3056240639Sadrian * to unfilter. 3057240639Sadrian */ 3058240639Sadrianstatic void 3059240639Sadrianath_tx_tid_filt_comp_complete(struct ath_softc *sc, struct ath_tid *tid) 3060240639Sadrian{ 3061240639Sadrian struct ath_buf *bf; 3062240639Sadrian 3063243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3064240639Sadrian 3065240639Sadrian if (tid->hwq_depth != 0) 3066240639Sadrian return; 3067240639Sadrian 3068240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, "%s: hwq=0, transition back\n", 3069240639Sadrian __func__); 3070240639Sadrian tid->isfiltered = 0; 3071245708Sadrian /* XXX ath_tx_tid_resume() also calls ath_tx_set_clrdmask()! */ 3072245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3073240639Sadrian 3074240639Sadrian /* XXX this is really quite inefficient */ 3075241566Sadrian while ((bf = ATH_TID_FILT_LAST(tid, ath_bufhead_s)) != NULL) { 3076241566Sadrian ATH_TID_FILT_REMOVE(tid, bf, bf_list); 3077241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 3078240639Sadrian } 3079240639Sadrian 3080240639Sadrian ath_tx_tid_resume(sc, tid); 3081240639Sadrian} 3082240639Sadrian 3083240639Sadrian/* 3084240639Sadrian * Called when a single (aggregate or otherwise) frame is completed. 3085240639Sadrian * 3086240639Sadrian * Returns 1 if the buffer could be added to the filtered list 3087240639Sadrian * (cloned or otherwise), 0 if the buffer couldn't be added to the 3088240639Sadrian * filtered list (failed clone; expired retry) and the caller should 3089240639Sadrian * free it and handle it like a failure (eg by sending a BAR.) 3090240639Sadrian */ 3091240639Sadrianstatic int 3092240639Sadrianath_tx_tid_filt_comp_single(struct ath_softc *sc, struct ath_tid *tid, 3093240639Sadrian struct ath_buf *bf) 3094240639Sadrian{ 3095240639Sadrian struct ath_buf *nbf; 3096240639Sadrian int retval; 3097240639Sadrian 3098243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3099240639Sadrian 3100240639Sadrian /* 3101240639Sadrian * Don't allow a filtered frame to live forever. 3102240639Sadrian */ 3103240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3104241170Sadrian sc->sc_stats.ast_tx_swretrymax++; 3105240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3106240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 3107240639Sadrian __func__, 3108240639Sadrian bf, 3109240639Sadrian bf->bf_state.bfs_seqno); 3110240639Sadrian return (0); 3111240639Sadrian } 3112240639Sadrian 3113240639Sadrian /* 3114240639Sadrian * A busy buffer can't be added to the retry list. 3115240639Sadrian * It needs to be cloned. 3116240639Sadrian */ 3117240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 3118240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3119240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3120240639Sadrian "%s: busy buffer clone: %p -> %p\n", 3121240639Sadrian __func__, bf, nbf); 3122240639Sadrian } else { 3123240639Sadrian nbf = bf; 3124240639Sadrian } 3125240639Sadrian 3126240639Sadrian if (nbf == NULL) { 3127240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3128240639Sadrian "%s: busy buffer couldn't be cloned (%p)!\n", 3129240639Sadrian __func__, bf); 3130240639Sadrian retval = 1; 3131240639Sadrian } else { 3132240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3133240639Sadrian retval = 0; 3134240639Sadrian } 3135240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 3136240639Sadrian 3137240639Sadrian return (retval); 3138240639Sadrian} 3139240639Sadrian 3140240639Sadrianstatic void 3141240639Sadrianath_tx_tid_filt_comp_aggr(struct ath_softc *sc, struct ath_tid *tid, 3142240639Sadrian struct ath_buf *bf_first, ath_bufhead *bf_q) 3143240639Sadrian{ 3144240639Sadrian struct ath_buf *bf, *bf_next, *nbf; 3145240639Sadrian 3146243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3147240639Sadrian 3148240639Sadrian bf = bf_first; 3149240639Sadrian while (bf) { 3150240639Sadrian bf_next = bf->bf_next; 3151240639Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 3152240639Sadrian 3153240639Sadrian /* 3154240639Sadrian * Don't allow a filtered frame to live forever. 3155240639Sadrian */ 3156240639Sadrian if (bf->bf_state.bfs_retries > SWMAX_RETRIES) { 3157247029Sadrian sc->sc_stats.ast_tx_swretrymax++; 3158240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3159240639Sadrian "%s: bf=%p, seqno=%d, exceeded retries\n", 3160240639Sadrian __func__, 3161240639Sadrian bf, 3162240639Sadrian bf->bf_state.bfs_seqno); 3163240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3164240639Sadrian goto next; 3165240639Sadrian } 3166240639Sadrian 3167240639Sadrian if (bf->bf_flags & ATH_BUF_BUSY) { 3168240639Sadrian nbf = ath_tx_retry_clone(sc, tid->an, tid, bf); 3169240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3170240639Sadrian "%s: busy buffer cloned: %p -> %p", 3171240639Sadrian __func__, bf, nbf); 3172240639Sadrian } else { 3173240639Sadrian nbf = bf; 3174240639Sadrian } 3175240639Sadrian 3176240639Sadrian /* 3177240639Sadrian * If the buffer couldn't be cloned, add it to bf_q; 3178240639Sadrian * the caller will free the buffer(s) as required. 3179240639Sadrian */ 3180240639Sadrian if (nbf == NULL) { 3181240639Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_FILT, 3182240639Sadrian "%s: buffer couldn't be cloned! (%p)\n", 3183240639Sadrian __func__, bf); 3184240639Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3185240639Sadrian } else { 3186240639Sadrian ath_tx_tid_filt_comp_buf(sc, tid, nbf); 3187240639Sadrian } 3188240639Sadriannext: 3189240639Sadrian bf = bf_next; 3190240639Sadrian } 3191240639Sadrian 3192240639Sadrian ath_tx_tid_filt_comp_complete(sc, tid); 3193240639Sadrian} 3194240639Sadrian 3195240639Sadrian/* 3196233908Sadrian * Suspend the queue because we need to TX a BAR. 3197233908Sadrian */ 3198233908Sadrianstatic void 3199233908Sadrianath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid) 3200233908Sadrian{ 3201233908Sadrian 3202243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3203243786Sadrian 3204235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3205235676Sadrian "%s: tid=%p, bar_wait=%d, bar_tx=%d, called\n", 3206233908Sadrian __func__, 3207235676Sadrian tid, 3208235676Sadrian tid->bar_wait, 3209235676Sadrian tid->bar_tx); 3210233908Sadrian 3211233908Sadrian /* We shouldn't be called when bar_tx is 1 */ 3212233908Sadrian if (tid->bar_tx) { 3213233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx is 1?!\n", 3214233908Sadrian __func__); 3215233908Sadrian } 3216233908Sadrian 3217233908Sadrian /* If we've already been called, just be patient. */ 3218233908Sadrian if (tid->bar_wait) 3219233908Sadrian return; 3220233908Sadrian 3221233908Sadrian /* Wait! */ 3222233908Sadrian tid->bar_wait = 1; 3223233908Sadrian 3224233908Sadrian /* Only one pause, no matter how many frames fail */ 3225233908Sadrian ath_tx_tid_pause(sc, tid); 3226233908Sadrian} 3227233908Sadrian 3228233908Sadrian/* 3229233908Sadrian * We've finished with BAR handling - either we succeeded or 3230233908Sadrian * failed. Either way, unsuspend TX. 3231233908Sadrian */ 3232233908Sadrianstatic void 3233233908Sadrianath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid) 3234233908Sadrian{ 3235233908Sadrian 3236243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3237243786Sadrian 3238235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3239233908Sadrian "%s: tid=%p, called\n", 3240233908Sadrian __func__, 3241233908Sadrian tid); 3242233908Sadrian 3243233908Sadrian if (tid->bar_tx == 0 || tid->bar_wait == 0) { 3244233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx=%d, bar_wait=%d: ?\n", 3245233908Sadrian __func__, tid->bar_tx, tid->bar_wait); 3246233908Sadrian } 3247233908Sadrian 3248233908Sadrian tid->bar_tx = tid->bar_wait = 0; 3249233908Sadrian ath_tx_tid_resume(sc, tid); 3250233908Sadrian} 3251233908Sadrian 3252233908Sadrian/* 3253233908Sadrian * Return whether we're ready to TX a BAR frame. 3254233908Sadrian * 3255233908Sadrian * Requires the TID lock be held. 3256233908Sadrian */ 3257233908Sadrianstatic int 3258233908Sadrianath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid) 3259233908Sadrian{ 3260233908Sadrian 3261243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3262233908Sadrian 3263233908Sadrian if (tid->bar_wait == 0 || tid->hwq_depth > 0) 3264233908Sadrian return (0); 3265233908Sadrian 3266235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, "%s: tid=%p (%d), bar ready\n", 3267235491Sadrian __func__, tid, tid->tid); 3268235491Sadrian 3269233908Sadrian return (1); 3270233908Sadrian} 3271233908Sadrian 3272233908Sadrian/* 3273233908Sadrian * Check whether the current TID is ready to have a BAR 3274233908Sadrian * TXed and if so, do the TX. 3275233908Sadrian * 3276233908Sadrian * Since the TID/TXQ lock can't be held during a call to 3277233908Sadrian * ieee80211_send_bar(), we have to do the dirty thing of unlocking it, 3278233908Sadrian * sending the BAR and locking it again. 3279233908Sadrian * 3280233908Sadrian * Eventually, the code to send the BAR should be broken out 3281233908Sadrian * from this routine so the lock doesn't have to be reacquired 3282233908Sadrian * just to be immediately dropped by the caller. 3283233908Sadrian */ 3284233908Sadrianstatic void 3285233908Sadrianath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid) 3286233908Sadrian{ 3287233908Sadrian struct ieee80211_tx_ampdu *tap; 3288233908Sadrian 3289243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3290233908Sadrian 3291235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3292233908Sadrian "%s: tid=%p, called\n", 3293233908Sadrian __func__, 3294233908Sadrian tid); 3295233908Sadrian 3296233908Sadrian tap = ath_tx_get_tx_tid(tid->an, tid->tid); 3297233908Sadrian 3298233908Sadrian /* 3299233908Sadrian * This is an error condition! 3300233908Sadrian */ 3301233908Sadrian if (tid->bar_wait == 0 || tid->bar_tx == 1) { 3302233908Sadrian device_printf(sc->sc_dev, 3303233908Sadrian "%s: tid=%p, bar_tx=%d, bar_wait=%d: ?\n", 3304233908Sadrian __func__, 3305233908Sadrian tid, 3306233908Sadrian tid->bar_tx, 3307233908Sadrian tid->bar_wait); 3308233908Sadrian return; 3309233908Sadrian } 3310233908Sadrian 3311233908Sadrian /* Don't do anything if we still have pending frames */ 3312233908Sadrian if (tid->hwq_depth > 0) { 3313235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3314233908Sadrian "%s: tid=%p, hwq_depth=%d, waiting\n", 3315233908Sadrian __func__, 3316233908Sadrian tid, 3317233908Sadrian tid->hwq_depth); 3318233908Sadrian return; 3319233908Sadrian } 3320233908Sadrian 3321233908Sadrian /* We're now about to TX */ 3322233908Sadrian tid->bar_tx = 1; 3323233908Sadrian 3324233908Sadrian /* 3325240724Sadrian * Override the clrdmask configuration for the next frame, 3326240724Sadrian * just to get the ball rolling. 3327240724Sadrian */ 3328245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3329240724Sadrian 3330240724Sadrian /* 3331233908Sadrian * Calculate new BAW left edge, now that all frames have either 3332233908Sadrian * succeeded or failed. 3333233908Sadrian * 3334233908Sadrian * XXX verify this is _actually_ the valid value to begin at! 3335233908Sadrian */ 3336235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 3337233908Sadrian "%s: tid=%p, new BAW left edge=%d\n", 3338233908Sadrian __func__, 3339233908Sadrian tid, 3340233908Sadrian tap->txa_start); 3341233908Sadrian 3342233908Sadrian /* Try sending the BAR frame */ 3343233908Sadrian /* We can't hold the lock here! */ 3344233908Sadrian 3345243786Sadrian ATH_TX_UNLOCK(sc); 3346233908Sadrian if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) { 3347233908Sadrian /* Success? Now we wait for notification that it's done */ 3348243786Sadrian ATH_TX_LOCK(sc); 3349233908Sadrian return; 3350233908Sadrian } 3351233908Sadrian 3352233908Sadrian /* Failure? For now, warn loudly and continue */ 3353243786Sadrian ATH_TX_LOCK(sc); 3354233908Sadrian device_printf(sc->sc_dev, "%s: tid=%p, failed to TX BAR, continue!\n", 3355233908Sadrian __func__, tid); 3356233908Sadrian ath_tx_tid_bar_unsuspend(sc, tid); 3357233908Sadrian} 3358233908Sadrian 3359240639Sadrianstatic void 3360240639Sadrianath_tx_tid_drain_pkt(struct ath_softc *sc, struct ath_node *an, 3361240639Sadrian struct ath_tid *tid, ath_bufhead *bf_cq, struct ath_buf *bf) 3362240639Sadrian{ 3363233908Sadrian 3364243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3365240639Sadrian 3366240639Sadrian /* 3367240639Sadrian * If the current TID is running AMPDU, update 3368240639Sadrian * the BAW. 3369240639Sadrian */ 3370240639Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid) && 3371240639Sadrian bf->bf_state.bfs_dobaw) { 3372240639Sadrian /* 3373240639Sadrian * Only remove the frame from the BAW if it's 3374240639Sadrian * been transmitted at least once; this means 3375240639Sadrian * the frame was in the BAW to begin with. 3376240639Sadrian */ 3377240639Sadrian if (bf->bf_state.bfs_retries > 0) { 3378240639Sadrian ath_tx_update_baw(sc, an, tid, bf); 3379240639Sadrian bf->bf_state.bfs_dobaw = 0; 3380240639Sadrian } 3381247135Sadrian#if 0 3382240639Sadrian /* 3383240639Sadrian * This has become a non-fatal error now 3384240639Sadrian */ 3385240639Sadrian if (! bf->bf_state.bfs_addedbaw) 3386240639Sadrian device_printf(sc->sc_dev, 3387240639Sadrian "%s: wasn't added: seqno %d\n", 3388240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3389247135Sadrian#endif 3390240639Sadrian } 3391248671Sadrian 3392248671Sadrian /* Strip it out of an aggregate list if it was in one */ 3393248671Sadrian bf->bf_next = NULL; 3394248671Sadrian 3395248671Sadrian /* Insert on the free queue to be freed by the caller */ 3396240639Sadrian TAILQ_INSERT_TAIL(bf_cq, bf, bf_list); 3397240639Sadrian} 3398240639Sadrian 3399240639Sadrianstatic void 3400240639Sadrianath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an, 3401240899Sadrian const char *pfx, struct ath_tid *tid, struct ath_buf *bf) 3402240639Sadrian{ 3403240639Sadrian struct ieee80211_node *ni = &an->an_node; 3404240639Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 3405240639Sadrian struct ieee80211_tx_ampdu *tap; 3406240639Sadrian 3407240639Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3408240639Sadrian 3409240639Sadrian device_printf(sc->sc_dev, 3410240899Sadrian "%s: %s: node %p: bf=%p: addbaw=%d, dobaw=%d, " 3411240639Sadrian "seqno=%d, retry=%d\n", 3412240899Sadrian __func__, pfx, ni, bf, 3413240639Sadrian bf->bf_state.bfs_addedbaw, 3414240639Sadrian bf->bf_state.bfs_dobaw, 3415240639Sadrian SEQNO(bf->bf_state.bfs_seqno), 3416240639Sadrian bf->bf_state.bfs_retries); 3417240639Sadrian device_printf(sc->sc_dev, 3418240899Sadrian "%s: node %p: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n", 3419240724Sadrian __func__, ni, bf, 3420240899Sadrian txq->axq_qnum, 3421240899Sadrian txq->axq_depth, 3422240899Sadrian txq->axq_aggr_depth); 3423240724Sadrian 3424240724Sadrian device_printf(sc->sc_dev, 3425240639Sadrian "%s: node %p: bf=%p: tid txq_depth=%d hwq_depth=%d, bar_wait=%d, isfiltered=%d\n", 3426240639Sadrian __func__, ni, bf, 3427240639Sadrian tid->axq_depth, 3428240639Sadrian tid->hwq_depth, 3429240639Sadrian tid->bar_wait, 3430240639Sadrian tid->isfiltered); 3431240639Sadrian device_printf(sc->sc_dev, 3432240724Sadrian "%s: node %p: tid %d: " 3433240724Sadrian "sched=%d, paused=%d, " 3434240724Sadrian "incomp=%d, baw_head=%d, " 3435240639Sadrian "baw_tail=%d txa_start=%d, ni_txseqs=%d\n", 3436240724Sadrian __func__, ni, tid->tid, 3437240724Sadrian tid->sched, tid->paused, 3438240724Sadrian tid->incomp, tid->baw_head, 3439240639Sadrian tid->baw_tail, tap == NULL ? -1 : tap->txa_start, 3440240639Sadrian ni->ni_txseqs[tid->tid]); 3441240639Sadrian 3442240639Sadrian /* XXX Dump the frame, see what it is? */ 3443240639Sadrian ieee80211_dump_pkt(ni->ni_ic, 3444240639Sadrian mtod(bf->bf_m, const uint8_t *), 3445240639Sadrian bf->bf_m->m_len, 0, -1); 3446240639Sadrian} 3447240639Sadrian 3448233908Sadrian/* 3449227364Sadrian * Free any packets currently pending in the software TX queue. 3450227364Sadrian * 3451227364Sadrian * This will be called when a node is being deleted. 3452227364Sadrian * 3453227364Sadrian * It can also be called on an active node during an interface 3454227364Sadrian * reset or state transition. 3455227364Sadrian * 3456227364Sadrian * (From Linux/reference): 3457227364Sadrian * 3458227364Sadrian * TODO: For frame(s) that are in the retry state, we will reuse the 3459227364Sadrian * sequence number(s) without setting the retry bit. The 3460227364Sadrian * alternative is to give up on these and BAR the receiver's window 3461227364Sadrian * forward. 3462227364Sadrian */ 3463227364Sadrianstatic void 3464229949Sadrianath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an, 3465229949Sadrian struct ath_tid *tid, ath_bufhead *bf_cq) 3466227364Sadrian{ 3467227364Sadrian struct ath_buf *bf; 3468227364Sadrian struct ieee80211_tx_ampdu *tap; 3469227364Sadrian struct ieee80211_node *ni = &an->an_node; 3470240639Sadrian int t; 3471227364Sadrian 3472227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3473227364Sadrian 3474243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3475227364Sadrian 3476227364Sadrian /* Walk the queue, free frames */ 3477240639Sadrian t = 0; 3478227364Sadrian for (;;) { 3479241336Sadrian bf = ATH_TID_FIRST(tid); 3480227364Sadrian if (bf == NULL) { 3481227364Sadrian break; 3482227364Sadrian } 3483227364Sadrian 3484227364Sadrian if (t == 0) { 3485240899Sadrian ath_tx_tid_drain_print(sc, an, "norm", tid, bf); 3486240639Sadrian t = 1; 3487240639Sadrian } 3488229165Sadrian 3489241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 3490240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3491240639Sadrian } 3492229165Sadrian 3493240639Sadrian /* And now, drain the filtered frame queue */ 3494240639Sadrian t = 0; 3495240639Sadrian for (;;) { 3496241566Sadrian bf = ATH_TID_FILT_FIRST(tid); 3497240639Sadrian if (bf == NULL) 3498240639Sadrian break; 3499240639Sadrian 3500240639Sadrian if (t == 0) { 3501240899Sadrian ath_tx_tid_drain_print(sc, an, "filt", tid, bf); 3502233897Sadrian t = 1; 3503227364Sadrian } 3504227364Sadrian 3505241566Sadrian ATH_TID_FILT_REMOVE(tid, bf, bf_list); 3506240639Sadrian ath_tx_tid_drain_pkt(sc, an, tid, bf_cq, bf); 3507227364Sadrian } 3508227364Sadrian 3509227364Sadrian /* 3510240724Sadrian * Override the clrdmask configuration for the next frame 3511240724Sadrian * in case there is some future transmission, just to get 3512240724Sadrian * the ball rolling. 3513240724Sadrian * 3514240724Sadrian * This won't hurt things if the TID is about to be freed. 3515240724Sadrian */ 3516245708Sadrian ath_tx_set_clrdmask(sc, tid->an); 3517240724Sadrian 3518240724Sadrian /* 3519227364Sadrian * Now that it's completed, grab the TID lock and update 3520227364Sadrian * the sequence number and BAW window. 3521227364Sadrian * Because sequence numbers have been assigned to frames 3522227364Sadrian * that haven't been sent yet, it's entirely possible 3523227364Sadrian * we'll be called with some pending frames that have not 3524227364Sadrian * been transmitted. 3525227364Sadrian * 3526227364Sadrian * The cleaner solution is to do the sequence number allocation 3527227364Sadrian * when the packet is first transmitted - and thus the "retries" 3528227364Sadrian * check above would be enough to update the BAW/seqno. 3529227364Sadrian */ 3530227364Sadrian 3531227364Sadrian /* But don't do it for non-QoS TIDs */ 3532227364Sadrian if (tap) { 3533227364Sadrian#if 0 3534227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3535227364Sadrian "%s: node %p: TID %d: sliding BAW left edge to %d\n", 3536227364Sadrian __func__, an, tid->tid, tap->txa_start); 3537227364Sadrian#endif 3538227364Sadrian ni->ni_txseqs[tid->tid] = tap->txa_start; 3539227364Sadrian tid->baw_tail = tid->baw_head; 3540227364Sadrian } 3541227364Sadrian} 3542227364Sadrian 3543227364Sadrian/* 3544227364Sadrian * Flush all software queued packets for the given node. 3545227364Sadrian * 3546227364Sadrian * This occurs when a completion handler frees the last buffer 3547227364Sadrian * for a node, and the node is thus freed. This causes the node 3548227364Sadrian * to be cleaned up, which ends up calling ath_tx_node_flush. 3549227364Sadrian */ 3550227364Sadrianvoid 3551227364Sadrianath_tx_node_flush(struct ath_softc *sc, struct ath_node *an) 3552227364Sadrian{ 3553227364Sadrian int tid; 3554227364Sadrian ath_bufhead bf_cq; 3555227364Sadrian struct ath_buf *bf; 3556227364Sadrian 3557227364Sadrian TAILQ_INIT(&bf_cq); 3558227364Sadrian 3559240899Sadrian ATH_KTR(sc, ATH_KTR_NODE, 1, "ath_tx_node_flush: flush node; ni=%p", 3560240899Sadrian &an->an_node); 3561240899Sadrian 3562243786Sadrian ATH_TX_LOCK(sc); 3563227364Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 3564227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3565227364Sadrian 3566227364Sadrian /* Free packets */ 3567227364Sadrian ath_tx_tid_drain(sc, an, atid, &bf_cq); 3568240914Sadrian /* Remove this tid from the list of active tids */ 3569240914Sadrian ath_tx_tid_unsched(sc, atid); 3570227364Sadrian } 3571243786Sadrian ATH_TX_UNLOCK(sc); 3572227364Sadrian 3573227364Sadrian /* Handle completed frames */ 3574227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3575227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3576227364Sadrian ath_tx_default_comp(sc, bf, 0); 3577227364Sadrian } 3578227364Sadrian} 3579227364Sadrian 3580227364Sadrian/* 3581227364Sadrian * Drain all the software TXQs currently with traffic queued. 3582227364Sadrian */ 3583227364Sadrianvoid 3584227364Sadrianath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq) 3585227364Sadrian{ 3586227364Sadrian struct ath_tid *tid; 3587227364Sadrian ath_bufhead bf_cq; 3588227364Sadrian struct ath_buf *bf; 3589227364Sadrian 3590227364Sadrian TAILQ_INIT(&bf_cq); 3591243786Sadrian ATH_TX_LOCK(sc); 3592227364Sadrian 3593227364Sadrian /* 3594227364Sadrian * Iterate over all active tids for the given txq, 3595227364Sadrian * flushing and unsched'ing them 3596227364Sadrian */ 3597227364Sadrian while (! TAILQ_EMPTY(&txq->axq_tidq)) { 3598227364Sadrian tid = TAILQ_FIRST(&txq->axq_tidq); 3599227364Sadrian ath_tx_tid_drain(sc, tid->an, tid, &bf_cq); 3600227364Sadrian ath_tx_tid_unsched(sc, tid); 3601227364Sadrian } 3602227364Sadrian 3603243786Sadrian ATH_TX_UNLOCK(sc); 3604227364Sadrian 3605227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3606227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3607227364Sadrian ath_tx_default_comp(sc, bf, 0); 3608227364Sadrian } 3609227364Sadrian} 3610227364Sadrian 3611227364Sadrian/* 3612227364Sadrian * Handle completion of non-aggregate session frames. 3613240883Sadrian * 3614240883Sadrian * This (currently) doesn't implement software retransmission of 3615240883Sadrian * non-aggregate frames! 3616240883Sadrian * 3617240883Sadrian * Software retransmission of non-aggregate frames needs to obey 3618240883Sadrian * the strict sequence number ordering, and drop any frames that 3619240883Sadrian * will fail this. 3620240883Sadrian * 3621240883Sadrian * For now, filtered frames and frame transmission will cause 3622240883Sadrian * all kinds of issues. So we don't support them. 3623240883Sadrian * 3624240883Sadrian * So anyone queuing frames via ath_tx_normal_xmit() or 3625240883Sadrian * ath_tx_hw_queue_norm() must override and set CLRDMASK. 3626227364Sadrian */ 3627227364Sadrianvoid 3628227364Sadrianath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3629227364Sadrian{ 3630227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3631227364Sadrian struct ath_node *an = ATH_NODE(ni); 3632227364Sadrian int tid = bf->bf_state.bfs_tid; 3633227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3634227364Sadrian struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3635227364Sadrian 3636227364Sadrian /* The TID state is protected behind the TXQ lock */ 3637243786Sadrian ATH_TX_LOCK(sc); 3638227364Sadrian 3639227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n", 3640227364Sadrian __func__, bf, fail, atid->hwq_depth - 1); 3641227364Sadrian 3642227364Sadrian atid->hwq_depth--; 3643240639Sadrian 3644240883Sadrian#if 0 3645240883Sadrian /* 3646240883Sadrian * If the frame was filtered, stick it on the filter frame 3647240883Sadrian * queue and complain about it. It shouldn't happen! 3648240883Sadrian */ 3649240883Sadrian if ((ts->ts_status & HAL_TXERR_FILT) || 3650240883Sadrian (ts->ts_status != 0 && atid->isfiltered)) { 3651240883Sadrian device_printf(sc->sc_dev, 3652240883Sadrian "%s: isfiltered=%d, ts_status=%d: huh?\n", 3653240883Sadrian __func__, 3654240883Sadrian atid->isfiltered, 3655240883Sadrian ts->ts_status); 3656240883Sadrian ath_tx_tid_filt_comp_buf(sc, atid, bf); 3657240883Sadrian } 3658240883Sadrian#endif 3659240639Sadrian if (atid->isfiltered) 3660240883Sadrian device_printf(sc->sc_dev, "%s: filtered?!\n", __func__); 3661227364Sadrian if (atid->hwq_depth < 0) 3662227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3663227364Sadrian __func__, atid->hwq_depth); 3664240639Sadrian 3665240639Sadrian /* 3666240639Sadrian * If the queue is filtered, potentially mark it as complete 3667240639Sadrian * and reschedule it as needed. 3668240639Sadrian * 3669240639Sadrian * This is required as there may be a subsequent TX descriptor 3670240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 3671240639Sadrian * that a filtered frame will be followed by a non-filtered 3672240639Sadrian * (complete or otherwise) frame. 3673240639Sadrian * 3674240639Sadrian * XXX should we do this before we complete the frame? 3675240639Sadrian */ 3676240639Sadrian if (atid->isfiltered) 3677240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 3678243786Sadrian ATH_TX_UNLOCK(sc); 3679227364Sadrian 3680227364Sadrian /* 3681227364Sadrian * punt to rate control if we're not being cleaned up 3682227364Sadrian * during a hw queue drain and the frame wanted an ACK. 3683227364Sadrian */ 3684233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3685227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3686227364Sadrian ts, bf->bf_state.bfs_pktlen, 3687227364Sadrian 1, (ts->ts_status == 0) ? 0 : 1); 3688227364Sadrian 3689227364Sadrian ath_tx_default_comp(sc, bf, fail); 3690227364Sadrian} 3691227364Sadrian 3692227364Sadrian/* 3693227364Sadrian * Handle cleanup of aggregate session packets that aren't 3694227364Sadrian * an A-MPDU. 3695227364Sadrian * 3696227364Sadrian * There's no need to update the BAW here - the session is being 3697227364Sadrian * torn down. 3698227364Sadrian */ 3699227364Sadrianstatic void 3700227364Sadrianath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3701227364Sadrian{ 3702227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3703227364Sadrian struct ath_node *an = ATH_NODE(ni); 3704227364Sadrian int tid = bf->bf_state.bfs_tid; 3705227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3706227364Sadrian 3707227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n", 3708227364Sadrian __func__, tid, atid->incomp); 3709227364Sadrian 3710243786Sadrian ATH_TX_LOCK(sc); 3711227364Sadrian atid->incomp--; 3712227364Sadrian if (atid->incomp == 0) { 3713227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3714227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3715227364Sadrian __func__, tid); 3716227364Sadrian atid->cleanup_inprogress = 0; 3717227364Sadrian ath_tx_tid_resume(sc, atid); 3718227364Sadrian } 3719243786Sadrian ATH_TX_UNLOCK(sc); 3720227364Sadrian 3721227364Sadrian ath_tx_default_comp(sc, bf, 0); 3722227364Sadrian} 3723227364Sadrian 3724227364Sadrian/* 3725227364Sadrian * Performs transmit side cleanup when TID changes from aggregated to 3726227364Sadrian * unaggregated. 3727227364Sadrian * 3728227364Sadrian * - Discard all retry frames from the s/w queue. 3729227364Sadrian * - Fix the tx completion function for all buffers in s/w queue. 3730227364Sadrian * - Count the number of unacked frames, and let transmit completion 3731227364Sadrian * handle it later. 3732227364Sadrian * 3733227364Sadrian * The caller is responsible for pausing the TID. 3734227364Sadrian */ 3735227364Sadrianstatic void 3736235749Sadrianath_tx_tid_cleanup(struct ath_softc *sc, struct ath_node *an, int tid) 3737227364Sadrian{ 3738227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3739227364Sadrian struct ieee80211_tx_ampdu *tap; 3740227364Sadrian struct ath_buf *bf, *bf_next; 3741227364Sadrian ath_bufhead bf_cq; 3742227364Sadrian 3743235774Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 3744227364Sadrian "%s: TID %d: called\n", __func__, tid); 3745227364Sadrian 3746227364Sadrian TAILQ_INIT(&bf_cq); 3747243786Sadrian ATH_TX_LOCK(sc); 3748227364Sadrian 3749227364Sadrian /* 3750240639Sadrian * Move the filtered frames to the TX queue, before 3751240639Sadrian * we run off and discard/process things. 3752240639Sadrian */ 3753240639Sadrian /* XXX this is really quite inefficient */ 3754241566Sadrian while ((bf = ATH_TID_FILT_LAST(atid, ath_bufhead_s)) != NULL) { 3755241566Sadrian ATH_TID_FILT_REMOVE(atid, bf, bf_list); 3756241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 3757240639Sadrian } 3758240639Sadrian 3759240639Sadrian /* 3760227364Sadrian * Update the frames in the software TX queue: 3761227364Sadrian * 3762227364Sadrian * + Discard retry frames in the queue 3763227364Sadrian * + Fix the completion function to be non-aggregate 3764227364Sadrian */ 3765241336Sadrian bf = ATH_TID_FIRST(atid); 3766227364Sadrian while (bf) { 3767227364Sadrian if (bf->bf_state.bfs_isretried) { 3768227364Sadrian bf_next = TAILQ_NEXT(bf, bf_list); 3769241336Sadrian ATH_TID_REMOVE(atid, bf, bf_list); 3770227364Sadrian if (bf->bf_state.bfs_dobaw) { 3771227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3772227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3773227364Sadrian device_printf(sc->sc_dev, 3774227364Sadrian "%s: wasn't added: seqno %d\n", 3775229949Sadrian __func__, 3776229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3777227364Sadrian } 3778227364Sadrian bf->bf_state.bfs_dobaw = 0; 3779227364Sadrian /* 3780227364Sadrian * Call the default completion handler with "fail" just 3781227364Sadrian * so upper levels are suitably notified about this. 3782227364Sadrian */ 3783227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3784227364Sadrian bf = bf_next; 3785227364Sadrian continue; 3786227364Sadrian } 3787227364Sadrian /* Give these the default completion handler */ 3788227364Sadrian bf->bf_comp = ath_tx_normal_comp; 3789227364Sadrian bf = TAILQ_NEXT(bf, bf_list); 3790227364Sadrian } 3791227364Sadrian 3792227364Sadrian /* The caller is required to pause the TID */ 3793227364Sadrian#if 0 3794227364Sadrian /* Pause the TID */ 3795227364Sadrian ath_tx_tid_pause(sc, atid); 3796227364Sadrian#endif 3797227364Sadrian 3798227364Sadrian /* 3799227364Sadrian * Calculate what hardware-queued frames exist based 3800227364Sadrian * on the current BAW size. Ie, what frames have been 3801227364Sadrian * added to the TX hardware queue for this TID but 3802227364Sadrian * not yet ACKed. 3803227364Sadrian */ 3804227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3805227364Sadrian /* Need the lock - fiddling with BAW */ 3806227364Sadrian while (atid->baw_head != atid->baw_tail) { 3807227364Sadrian if (atid->tx_buf[atid->baw_head]) { 3808227364Sadrian atid->incomp++; 3809227364Sadrian atid->cleanup_inprogress = 1; 3810227364Sadrian atid->tx_buf[atid->baw_head] = NULL; 3811227364Sadrian } 3812227364Sadrian INCR(atid->baw_head, ATH_TID_MAX_BUFS); 3813227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 3814227364Sadrian } 3815227364Sadrian 3816227364Sadrian /* 3817227364Sadrian * If cleanup is required, defer TID scheduling 3818227364Sadrian * until all the HW queued packets have been 3819227364Sadrian * sent. 3820227364Sadrian */ 3821227364Sadrian if (! atid->cleanup_inprogress) 3822227364Sadrian ath_tx_tid_resume(sc, atid); 3823227364Sadrian 3824227364Sadrian if (atid->cleanup_inprogress) 3825227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3826227364Sadrian "%s: TID %d: cleanup needed: %d packets\n", 3827227364Sadrian __func__, tid, atid->incomp); 3828243786Sadrian ATH_TX_UNLOCK(sc); 3829227364Sadrian 3830227364Sadrian /* Handle completing frames and fail them */ 3831227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3832227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3833227364Sadrian ath_tx_default_comp(sc, bf, 1); 3834227364Sadrian } 3835227364Sadrian} 3836227364Sadrian 3837227364Sadrianstatic struct ath_buf * 3838227398Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 3839227398Sadrian struct ath_tid *tid, struct ath_buf *bf) 3840227364Sadrian{ 3841227364Sadrian struct ath_buf *nbf; 3842227364Sadrian int error; 3843227364Sadrian 3844227364Sadrian nbf = ath_buf_clone(sc, bf); 3845227364Sadrian 3846227364Sadrian#if 0 3847227364Sadrian device_printf(sc->sc_dev, "%s: ATH_BUF_BUSY; cloning\n", 3848227364Sadrian __func__); 3849227364Sadrian#endif 3850227364Sadrian 3851227364Sadrian if (nbf == NULL) { 3852227364Sadrian /* Failed to clone */ 3853227364Sadrian device_printf(sc->sc_dev, 3854227364Sadrian "%s: failed to clone a busy buffer\n", 3855227364Sadrian __func__); 3856227364Sadrian return NULL; 3857227364Sadrian } 3858227364Sadrian 3859227364Sadrian /* Setup the dma for the new buffer */ 3860227364Sadrian error = ath_tx_dmasetup(sc, nbf, nbf->bf_m); 3861227364Sadrian if (error != 0) { 3862227364Sadrian device_printf(sc->sc_dev, 3863227364Sadrian "%s: failed to setup dma for clone\n", 3864227364Sadrian __func__); 3865227364Sadrian /* 3866227364Sadrian * Put this at the head of the list, not tail; 3867227364Sadrian * that way it doesn't interfere with the 3868227364Sadrian * busy buffer logic (which uses the tail of 3869227364Sadrian * the list.) 3870227364Sadrian */ 3871227364Sadrian ATH_TXBUF_LOCK(sc); 3872236994Sadrian ath_returnbuf_head(sc, nbf); 3873227364Sadrian ATH_TXBUF_UNLOCK(sc); 3874227364Sadrian return NULL; 3875227364Sadrian } 3876227364Sadrian 3877227398Sadrian /* Update BAW if required, before we free the original buf */ 3878227398Sadrian if (bf->bf_state.bfs_dobaw) 3879227398Sadrian ath_tx_switch_baw_buf(sc, an, tid, bf, nbf); 3880227398Sadrian 3881227364Sadrian /* Free current buffer; return the older buffer */ 3882227364Sadrian bf->bf_m = NULL; 3883227364Sadrian bf->bf_node = NULL; 3884227364Sadrian ath_freebuf(sc, bf); 3885240639Sadrian 3886227364Sadrian return nbf; 3887227364Sadrian} 3888227364Sadrian 3889227364Sadrian/* 3890227364Sadrian * Handle retrying an unaggregate frame in an aggregate 3891227364Sadrian * session. 3892227364Sadrian * 3893227364Sadrian * If too many retries occur, pause the TID, wait for 3894227364Sadrian * any further retransmits (as there's no reason why 3895227364Sadrian * non-aggregate frames in an aggregate session are 3896227364Sadrian * transmitted in-order; they just have to be in-BAW) 3897227364Sadrian * and then queue a BAR. 3898227364Sadrian */ 3899227364Sadrianstatic void 3900227364Sadrianath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3901227364Sadrian{ 3902227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3903227364Sadrian struct ath_node *an = ATH_NODE(ni); 3904227364Sadrian int tid = bf->bf_state.bfs_tid; 3905227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3906227364Sadrian struct ieee80211_tx_ampdu *tap; 3907227364Sadrian 3908243786Sadrian ATH_TX_LOCK(sc); 3909227364Sadrian 3910227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3911227364Sadrian 3912227364Sadrian /* 3913227364Sadrian * If the buffer is marked as busy, we can't directly 3914227364Sadrian * reuse it. Instead, try to clone the buffer. 3915227364Sadrian * If the clone is successful, recycle the old buffer. 3916227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3917227364Sadrian * to force the next bit of code to free the buffer 3918227364Sadrian * for us. 3919227364Sadrian */ 3920227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3921227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3922227364Sadrian struct ath_buf *nbf; 3923227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3924227364Sadrian if (nbf) 3925227364Sadrian /* bf has been freed at this point */ 3926227364Sadrian bf = nbf; 3927227364Sadrian else 3928227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3929227364Sadrian } 3930227364Sadrian 3931227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3932227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3933227364Sadrian "%s: exceeded retries; seqno %d\n", 3934227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3935227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3936227364Sadrian 3937227364Sadrian /* Update BAW anyway */ 3938227364Sadrian if (bf->bf_state.bfs_dobaw) { 3939227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3940227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3941227364Sadrian device_printf(sc->sc_dev, 3942227364Sadrian "%s: wasn't added: seqno %d\n", 3943227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3944227364Sadrian } 3945227364Sadrian bf->bf_state.bfs_dobaw = 0; 3946227364Sadrian 3947233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3948233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 3949227364Sadrian 3950233908Sadrian /* Send the BAR if there are no other frames waiting */ 3951233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3952233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3953227364Sadrian 3954243786Sadrian ATH_TX_UNLOCK(sc); 3955227364Sadrian 3956227364Sadrian /* Free buffer, bf is free after this call */ 3957227364Sadrian ath_tx_default_comp(sc, bf, 0); 3958227364Sadrian return; 3959227364Sadrian } 3960227364Sadrian 3961227364Sadrian /* 3962227364Sadrian * This increments the retry counter as well as 3963227364Sadrian * sets the retry flag in the ath_buf and packet 3964227364Sadrian * body. 3965227364Sadrian */ 3966227364Sadrian ath_tx_set_retry(sc, bf); 3967240639Sadrian sc->sc_stats.ast_tx_swretries++; 3968227364Sadrian 3969227364Sadrian /* 3970227364Sadrian * Insert this at the head of the queue, so it's 3971227364Sadrian * retried before any current/subsequent frames. 3972227364Sadrian */ 3973241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 3974227364Sadrian ath_tx_tid_sched(sc, atid); 3975233908Sadrian /* Send the BAR if there are no other frames waiting */ 3976233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3977233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3978227364Sadrian 3979243786Sadrian ATH_TX_UNLOCK(sc); 3980227364Sadrian} 3981227364Sadrian 3982227364Sadrian/* 3983227364Sadrian * Common code for aggregate excessive retry/subframe retry. 3984227364Sadrian * If retrying, queues buffers to bf_q. If not, frees the 3985227364Sadrian * buffers. 3986227364Sadrian * 3987227364Sadrian * XXX should unify this with ath_tx_aggr_retry_unaggr() 3988227364Sadrian */ 3989227364Sadrianstatic int 3990227364Sadrianath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf, 3991227364Sadrian ath_bufhead *bf_q) 3992227364Sadrian{ 3993227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3994227364Sadrian struct ath_node *an = ATH_NODE(ni); 3995227364Sadrian int tid = bf->bf_state.bfs_tid; 3996227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3997227364Sadrian 3998243786Sadrian ATH_TX_LOCK_ASSERT(sc); 3999227364Sadrian 4000240255Sadrian /* XXX clr11naggr should be done for all subframes */ 4001227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4002227364Sadrian ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0); 4003240639Sadrian 4004227364Sadrian /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */ 4005227364Sadrian 4006227364Sadrian /* 4007227364Sadrian * If the buffer is marked as busy, we can't directly 4008227364Sadrian * reuse it. Instead, try to clone the buffer. 4009227364Sadrian * If the clone is successful, recycle the old buffer. 4010227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 4011227364Sadrian * to force the next bit of code to free the buffer 4012227364Sadrian * for us. 4013227364Sadrian */ 4014227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 4015227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 4016227364Sadrian struct ath_buf *nbf; 4017227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 4018227364Sadrian if (nbf) 4019227364Sadrian /* bf has been freed at this point */ 4020227364Sadrian bf = nbf; 4021227364Sadrian else 4022227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 4023227364Sadrian } 4024227364Sadrian 4025227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 4026227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 4027227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 4028227364Sadrian "%s: max retries: seqno %d\n", 4029227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4030227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4031227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4032227364Sadrian device_printf(sc->sc_dev, 4033227364Sadrian "%s: wasn't added: seqno %d\n", 4034227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4035227364Sadrian bf->bf_state.bfs_dobaw = 0; 4036227364Sadrian return 1; 4037227364Sadrian } 4038227364Sadrian 4039227364Sadrian ath_tx_set_retry(sc, bf); 4040240639Sadrian sc->sc_stats.ast_tx_swretries++; 4041227364Sadrian bf->bf_next = NULL; /* Just to make sure */ 4042227364Sadrian 4043240255Sadrian /* Clear the aggregate state */ 4044240255Sadrian bf->bf_state.bfs_aggr = 0; 4045240255Sadrian bf->bf_state.bfs_ndelim = 0; /* ??? needed? */ 4046240255Sadrian bf->bf_state.bfs_nframes = 1; 4047240255Sadrian 4048227364Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 4049227364Sadrian return 0; 4050227364Sadrian} 4051227364Sadrian 4052227364Sadrian/* 4053227364Sadrian * error pkt completion for an aggregate destination 4054227364Sadrian */ 4055227364Sadrianstatic void 4056227364Sadrianath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first, 4057227364Sadrian struct ath_tid *tid) 4058227364Sadrian{ 4059227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4060227364Sadrian struct ath_node *an = ATH_NODE(ni); 4061227364Sadrian struct ath_buf *bf_next, *bf; 4062227364Sadrian ath_bufhead bf_q; 4063227364Sadrian int drops = 0; 4064227364Sadrian struct ieee80211_tx_ampdu *tap; 4065227364Sadrian ath_bufhead bf_cq; 4066227364Sadrian 4067227364Sadrian TAILQ_INIT(&bf_q); 4068227364Sadrian TAILQ_INIT(&bf_cq); 4069227364Sadrian 4070227364Sadrian /* 4071227364Sadrian * Update rate control - all frames have failed. 4072227364Sadrian * 4073227364Sadrian * XXX use the length in the first frame in the series; 4074227364Sadrian * XXX just so things are consistent for now. 4075227364Sadrian */ 4076227364Sadrian ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc, 4077227364Sadrian &bf_first->bf_status.ds_txstat, 4078227364Sadrian bf_first->bf_state.bfs_pktlen, 4079227364Sadrian bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes); 4080227364Sadrian 4081243786Sadrian ATH_TX_LOCK(sc); 4082227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 4083227868Sadrian sc->sc_stats.ast_tx_aggr_failall++; 4084227364Sadrian 4085227364Sadrian /* Retry all subframes */ 4086227364Sadrian bf = bf_first; 4087227364Sadrian while (bf) { 4088227364Sadrian bf_next = bf->bf_next; 4089227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 4090227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 4091227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4092227364Sadrian drops++; 4093227364Sadrian bf->bf_next = NULL; 4094227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4095227364Sadrian } 4096227364Sadrian bf = bf_next; 4097227364Sadrian } 4098227364Sadrian 4099227364Sadrian /* Prepend all frames to the beginning of the queue */ 4100227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4101227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 4102241336Sadrian ATH_TID_INSERT_HEAD(tid, bf, bf_list); 4103227364Sadrian } 4104227364Sadrian 4105234725Sadrian /* 4106234725Sadrian * Schedule the TID to be re-tried. 4107234725Sadrian */ 4108227364Sadrian ath_tx_tid_sched(sc, tid); 4109227364Sadrian 4110227364Sadrian /* 4111227364Sadrian * send bar if we dropped any frames 4112227364Sadrian * 4113227364Sadrian * Keep the txq lock held for now, as we need to ensure 4114227364Sadrian * that ni_txseqs[] is consistent (as it's being updated 4115227364Sadrian * in the ifnet TX context or raw TX context.) 4116227364Sadrian */ 4117227364Sadrian if (drops) { 4118233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 4119233908Sadrian ath_tx_tid_bar_suspend(sc, tid); 4120227364Sadrian } 4121227364Sadrian 4122233908Sadrian /* 4123233908Sadrian * Send BAR if required 4124233908Sadrian */ 4125233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, tid)) 4126233908Sadrian ath_tx_tid_bar_tx(sc, tid); 4127240639Sadrian 4128243786Sadrian ATH_TX_UNLOCK(sc); 4129233908Sadrian 4130227364Sadrian /* Complete frames which errored out */ 4131227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4132227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 4133227364Sadrian ath_tx_default_comp(sc, bf, 0); 4134227364Sadrian } 4135227364Sadrian} 4136227364Sadrian 4137227364Sadrian/* 4138227364Sadrian * Handle clean-up of packets from an aggregate list. 4139227364Sadrian * 4140227364Sadrian * There's no need to update the BAW here - the session is being 4141227364Sadrian * torn down. 4142227364Sadrian */ 4143227364Sadrianstatic void 4144227364Sadrianath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first) 4145227364Sadrian{ 4146227364Sadrian struct ath_buf *bf, *bf_next; 4147227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4148227364Sadrian struct ath_node *an = ATH_NODE(ni); 4149227364Sadrian int tid = bf_first->bf_state.bfs_tid; 4150227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4151227364Sadrian 4152243786Sadrian ATH_TX_LOCK(sc); 4153227364Sadrian 4154227364Sadrian /* update incomp */ 4155248341Sadrian bf = bf_first; 4156227364Sadrian while (bf) { 4157227364Sadrian atid->incomp--; 4158227364Sadrian bf = bf->bf_next; 4159227364Sadrian } 4160227364Sadrian 4161227364Sadrian if (atid->incomp == 0) { 4162227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4163227364Sadrian "%s: TID %d: cleaned up! resume!\n", 4164227364Sadrian __func__, tid); 4165227364Sadrian atid->cleanup_inprogress = 0; 4166227364Sadrian ath_tx_tid_resume(sc, atid); 4167227364Sadrian } 4168233908Sadrian 4169233908Sadrian /* Send BAR if required */ 4170240639Sadrian /* XXX why would we send a BAR when transitioning to non-aggregation? */ 4171248341Sadrian /* 4172248341Sadrian * XXX TODO: we should likely just tear down the BAR state here, 4173248341Sadrian * rather than sending a BAR. 4174248341Sadrian */ 4175233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4176233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4177240639Sadrian 4178243786Sadrian ATH_TX_UNLOCK(sc); 4179227364Sadrian 4180227364Sadrian /* Handle frame completion */ 4181248341Sadrian bf = bf_first; 4182227364Sadrian while (bf) { 4183227364Sadrian bf_next = bf->bf_next; 4184227364Sadrian ath_tx_default_comp(sc, bf, 1); 4185227364Sadrian bf = bf_next; 4186227364Sadrian } 4187227364Sadrian} 4188227364Sadrian 4189227364Sadrian/* 4190227364Sadrian * Handle completion of an set of aggregate frames. 4191227364Sadrian * 4192227364Sadrian * Note: the completion handler is the last descriptor in the aggregate, 4193227364Sadrian * not the last descriptor in the first frame. 4194227364Sadrian */ 4195227364Sadrianstatic void 4196229949Sadrianath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first, 4197229949Sadrian int fail) 4198227364Sadrian{ 4199227364Sadrian //struct ath_desc *ds = bf->bf_lastds; 4200227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 4201227364Sadrian struct ath_node *an = ATH_NODE(ni); 4202227364Sadrian int tid = bf_first->bf_state.bfs_tid; 4203227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4204227364Sadrian struct ath_tx_status ts; 4205227364Sadrian struct ieee80211_tx_ampdu *tap; 4206227364Sadrian ath_bufhead bf_q; 4207227364Sadrian ath_bufhead bf_cq; 4208227364Sadrian int seq_st, tx_ok; 4209227364Sadrian int hasba, isaggr; 4210227364Sadrian uint32_t ba[2]; 4211227364Sadrian struct ath_buf *bf, *bf_next; 4212227364Sadrian int ba_index; 4213227364Sadrian int drops = 0; 4214227364Sadrian int nframes = 0, nbad = 0, nf; 4215227364Sadrian int pktlen; 4216227364Sadrian /* XXX there's too much on the stack? */ 4217236038Sadrian struct ath_rc_series rc[ATH_RC_NUM]; 4218227364Sadrian int txseq; 4219227364Sadrian 4220227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n", 4221227364Sadrian __func__, atid->hwq_depth); 4222227364Sadrian 4223240677Sadrian /* 4224240677Sadrian * Take a copy; this may be needed -after- bf_first 4225240677Sadrian * has been completed and freed. 4226240677Sadrian */ 4227240677Sadrian ts = bf_first->bf_status.ds_txstat; 4228240677Sadrian 4229240639Sadrian TAILQ_INIT(&bf_q); 4230240639Sadrian TAILQ_INIT(&bf_cq); 4231240639Sadrian 4232227364Sadrian /* The TID state is kept behind the TXQ lock */ 4233243786Sadrian ATH_TX_LOCK(sc); 4234227364Sadrian 4235227364Sadrian atid->hwq_depth--; 4236227364Sadrian if (atid->hwq_depth < 0) 4237227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4238227364Sadrian __func__, atid->hwq_depth); 4239227364Sadrian 4240227364Sadrian /* 4241240639Sadrian * If the TID is filtered, handle completing the filter 4242240639Sadrian * transition before potentially kicking it to the cleanup 4243240639Sadrian * function. 4244240677Sadrian * 4245240677Sadrian * XXX this is duplicate work, ew. 4246240639Sadrian */ 4247240639Sadrian if (atid->isfiltered) 4248240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4249240639Sadrian 4250240639Sadrian /* 4251227364Sadrian * Punt cleanup to the relevant function, not our problem now 4252227364Sadrian */ 4253227364Sadrian if (atid->cleanup_inprogress) { 4254240639Sadrian if (atid->isfiltered) 4255240639Sadrian device_printf(sc->sc_dev, 4256240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4257240639Sadrian __func__); 4258243786Sadrian ATH_TX_UNLOCK(sc); 4259227364Sadrian ath_tx_comp_cleanup_aggr(sc, bf_first); 4260227364Sadrian return; 4261227364Sadrian } 4262227364Sadrian 4263227364Sadrian /* 4264240639Sadrian * If the frame is filtered, transition to filtered frame 4265240639Sadrian * mode and add this to the filtered frame list. 4266240639Sadrian * 4267240639Sadrian * XXX TODO: figure out how this interoperates with 4268240639Sadrian * BAR, pause and cleanup states. 4269240639Sadrian */ 4270240639Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4271240639Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4272240639Sadrian if (fail != 0) 4273240639Sadrian device_printf(sc->sc_dev, 4274240639Sadrian "%s: isfiltered=1, fail=%d\n", __func__, fail); 4275240639Sadrian ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq); 4276240639Sadrian 4277240639Sadrian /* Remove from BAW */ 4278240639Sadrian TAILQ_FOREACH_SAFE(bf, &bf_cq, bf_list, bf_next) { 4279240639Sadrian if (bf->bf_state.bfs_addedbaw) 4280240639Sadrian drops++; 4281240639Sadrian if (bf->bf_state.bfs_dobaw) { 4282240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4283240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4284240639Sadrian device_printf(sc->sc_dev, 4285240639Sadrian "%s: wasn't added: seqno %d\n", 4286240639Sadrian __func__, 4287240639Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4288240639Sadrian } 4289240639Sadrian bf->bf_state.bfs_dobaw = 0; 4290240639Sadrian } 4291240639Sadrian /* 4292240639Sadrian * If any intermediate frames in the BAW were dropped when 4293240639Sadrian * handling filtering things, send a BAR. 4294240639Sadrian */ 4295240639Sadrian if (drops) 4296240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4297240639Sadrian 4298240639Sadrian /* 4299240639Sadrian * Finish up by sending a BAR if required and freeing 4300240639Sadrian * the frames outside of the TX lock. 4301240639Sadrian */ 4302240639Sadrian goto finish_send_bar; 4303240639Sadrian } 4304240639Sadrian 4305240639Sadrian /* 4306227364Sadrian * XXX for now, use the first frame in the aggregate for 4307227364Sadrian * XXX rate control completion; it's at least consistent. 4308227364Sadrian */ 4309227364Sadrian pktlen = bf_first->bf_state.bfs_pktlen; 4310227364Sadrian 4311227364Sadrian /* 4312235461Sadrian * Handle errors first! 4313235461Sadrian * 4314235461Sadrian * Here, handle _any_ error as a "exceeded retries" error. 4315235461Sadrian * Later on (when filtered frames are to be specially handled) 4316235461Sadrian * it'll have to be expanded. 4317227364Sadrian */ 4318235461Sadrian#if 0 4319227364Sadrian if (ts.ts_status & HAL_TXERR_XRETRY) { 4320235461Sadrian#endif 4321235461Sadrian if (ts.ts_status != 0) { 4322243786Sadrian ATH_TX_UNLOCK(sc); 4323227364Sadrian ath_tx_comp_aggr_error(sc, bf_first, atid); 4324227364Sadrian return; 4325227364Sadrian } 4326227364Sadrian 4327227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4328227364Sadrian 4329227364Sadrian /* 4330227364Sadrian * extract starting sequence and block-ack bitmap 4331227364Sadrian */ 4332227364Sadrian /* XXX endian-ness of seq_st, ba? */ 4333227364Sadrian seq_st = ts.ts_seqnum; 4334227364Sadrian hasba = !! (ts.ts_flags & HAL_TX_BA); 4335227364Sadrian tx_ok = (ts.ts_status == 0); 4336227364Sadrian isaggr = bf_first->bf_state.bfs_aggr; 4337227364Sadrian ba[0] = ts.ts_ba_low; 4338227364Sadrian ba[1] = ts.ts_ba_high; 4339227364Sadrian 4340227364Sadrian /* 4341227364Sadrian * Copy the TX completion status and the rate control 4342227364Sadrian * series from the first descriptor, as it may be freed 4343227364Sadrian * before the rate control code can get its grubby fingers 4344227364Sadrian * into things. 4345227364Sadrian */ 4346227364Sadrian memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc)); 4347227364Sadrian 4348227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4349229949Sadrian "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, " 4350229949Sadrian "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n", 4351227364Sadrian __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags, 4352227364Sadrian isaggr, seq_st, hasba, ba[0], ba[1]); 4353227364Sadrian 4354248091Sadrian /* 4355248091Sadrian * The reference driver doesn't do this; it simply ignores 4356248091Sadrian * this check in its entirety. 4357248091Sadrian * 4358248091Sadrian * I've seen this occur when using iperf to send traffic 4359248091Sadrian * out tid 1 - the aggregate frames are all marked as TID 1, 4360248091Sadrian * but the TXSTATUS has TID=0. So, let's just ignore this 4361248091Sadrian * check. 4362248091Sadrian */ 4363248091Sadrian#if 0 4364227364Sadrian /* Occasionally, the MAC sends a tx status for the wrong TID. */ 4365227364Sadrian if (tid != ts.ts_tid) { 4366227364Sadrian device_printf(sc->sc_dev, "%s: tid %d != hw tid %d\n", 4367227364Sadrian __func__, tid, ts.ts_tid); 4368227364Sadrian tx_ok = 0; 4369227364Sadrian } 4370248091Sadrian#endif 4371227364Sadrian 4372227364Sadrian /* AR5416 BA bug; this requires an interface reset */ 4373227364Sadrian if (isaggr && tx_ok && (! hasba)) { 4374227364Sadrian device_printf(sc->sc_dev, 4375229949Sadrian "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, " 4376229949Sadrian "seq_st=%d\n", 4377227364Sadrian __func__, hasba, tx_ok, isaggr, seq_st); 4378227364Sadrian /* XXX TODO: schedule an interface reset */ 4379238350Sjhb#ifdef ATH_DEBUG 4380238338Sadrian ath_printtxbuf(sc, bf_first, 4381238338Sadrian sc->sc_ac2q[atid->ac]->axq_qnum, 0, 0); 4382238350Sjhb#endif 4383227364Sadrian } 4384227364Sadrian 4385227364Sadrian /* 4386227364Sadrian * Walk the list of frames, figure out which ones were correctly 4387227364Sadrian * sent and which weren't. 4388227364Sadrian */ 4389227364Sadrian bf = bf_first; 4390227364Sadrian nf = bf_first->bf_state.bfs_nframes; 4391227364Sadrian 4392227364Sadrian /* bf_first is going to be invalid once this list is walked */ 4393227364Sadrian bf_first = NULL; 4394227364Sadrian 4395227364Sadrian /* 4396227364Sadrian * Walk the list of completed frames and determine 4397227364Sadrian * which need to be completed and which need to be 4398227364Sadrian * retransmitted. 4399227364Sadrian * 4400227364Sadrian * For completed frames, the completion functions need 4401227364Sadrian * to be called at the end of this function as the last 4402227364Sadrian * node reference may free the node. 4403227364Sadrian * 4404227364Sadrian * Finally, since the TXQ lock can't be held during the 4405227364Sadrian * completion callback (to avoid lock recursion), 4406227364Sadrian * the completion calls have to be done outside of the 4407227364Sadrian * lock. 4408227364Sadrian */ 4409227364Sadrian while (bf) { 4410227364Sadrian nframes++; 4411229949Sadrian ba_index = ATH_BA_INDEX(seq_st, 4412229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4413227364Sadrian bf_next = bf->bf_next; 4414227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 4415227364Sadrian 4416227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4417227364Sadrian "%s: checking bf=%p seqno=%d; ack=%d\n", 4418227364Sadrian __func__, bf, SEQNO(bf->bf_state.bfs_seqno), 4419227364Sadrian ATH_BA_ISSET(ba, ba_index)); 4420227364Sadrian 4421227364Sadrian if (tx_ok && ATH_BA_ISSET(ba, ba_index)) { 4422227868Sadrian sc->sc_stats.ast_tx_aggr_ok++; 4423227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4424227364Sadrian bf->bf_state.bfs_dobaw = 0; 4425227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4426227364Sadrian device_printf(sc->sc_dev, 4427227364Sadrian "%s: wasn't added: seqno %d\n", 4428227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4429227364Sadrian bf->bf_next = NULL; 4430227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4431227364Sadrian } else { 4432227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 4433227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 4434227364Sadrian drops++; 4435227364Sadrian bf->bf_next = NULL; 4436227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 4437227364Sadrian } 4438227364Sadrian nbad++; 4439227364Sadrian } 4440227364Sadrian bf = bf_next; 4441227364Sadrian } 4442227364Sadrian 4443227364Sadrian /* 4444227364Sadrian * Now that the BAW updates have been done, unlock 4445227364Sadrian * 4446227364Sadrian * txseq is grabbed before the lock is released so we 4447227364Sadrian * have a consistent view of what -was- in the BAW. 4448227364Sadrian * Anything after this point will not yet have been 4449227364Sadrian * TXed. 4450227364Sadrian */ 4451227364Sadrian txseq = tap->txa_start; 4452243786Sadrian ATH_TX_UNLOCK(sc); 4453227364Sadrian 4454227364Sadrian if (nframes != nf) 4455227364Sadrian device_printf(sc->sc_dev, 4456227364Sadrian "%s: num frames seen=%d; bf nframes=%d\n", 4457227364Sadrian __func__, nframes, nf); 4458227364Sadrian 4459227364Sadrian /* 4460227364Sadrian * Now we know how many frames were bad, call the rate 4461227364Sadrian * control code. 4462227364Sadrian */ 4463227364Sadrian if (fail == 0) 4464229949Sadrian ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes, 4465229949Sadrian nbad); 4466227364Sadrian 4467227364Sadrian /* 4468227364Sadrian * send bar if we dropped any frames 4469227364Sadrian */ 4470227364Sadrian if (drops) { 4471233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 4472243786Sadrian ATH_TX_LOCK(sc); 4473233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 4474243786Sadrian ATH_TX_UNLOCK(sc); 4475227364Sadrian } 4476227364Sadrian 4477234725Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4478234725Sadrian "%s: txa_start now %d\n", __func__, tap->txa_start); 4479234725Sadrian 4480243786Sadrian ATH_TX_LOCK(sc); 4481234725Sadrian 4482227364Sadrian /* Prepend all frames to the beginning of the queue */ 4483227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 4484227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 4485241336Sadrian ATH_TID_INSERT_HEAD(atid, bf, bf_list); 4486227364Sadrian } 4487234725Sadrian 4488234725Sadrian /* 4489234725Sadrian * Reschedule to grab some further frames. 4490234725Sadrian */ 4491227364Sadrian ath_tx_tid_sched(sc, atid); 4492227364Sadrian 4493233908Sadrian /* 4494240639Sadrian * If the queue is filtered, re-schedule as required. 4495240639Sadrian * 4496240639Sadrian * This is required as there may be a subsequent TX descriptor 4497240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4498240639Sadrian * that a filtered frame will be followed by a non-filtered 4499240639Sadrian * (complete or otherwise) frame. 4500240639Sadrian * 4501240639Sadrian * XXX should we do this before we complete the frame? 4502240639Sadrian */ 4503240639Sadrian if (atid->isfiltered) 4504240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4505240639Sadrian 4506240639Sadrianfinish_send_bar: 4507240639Sadrian 4508240639Sadrian /* 4509233908Sadrian * Send BAR if required 4510233908Sadrian */ 4511233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4512233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4513234725Sadrian 4514243786Sadrian ATH_TX_UNLOCK(sc); 4515233908Sadrian 4516227364Sadrian /* Do deferred completion */ 4517227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 4518227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 4519227364Sadrian ath_tx_default_comp(sc, bf, 0); 4520227364Sadrian } 4521227364Sadrian} 4522227364Sadrian 4523227364Sadrian/* 4524227364Sadrian * Handle completion of unaggregated frames in an ADDBA 4525227364Sadrian * session. 4526227364Sadrian * 4527227364Sadrian * Fail is set to 1 if the entry is being freed via a call to 4528227364Sadrian * ath_tx_draintxq(). 4529227364Sadrian */ 4530227364Sadrianstatic void 4531227364Sadrianath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail) 4532227364Sadrian{ 4533227364Sadrian struct ieee80211_node *ni = bf->bf_node; 4534227364Sadrian struct ath_node *an = ATH_NODE(ni); 4535227364Sadrian int tid = bf->bf_state.bfs_tid; 4536227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4537240677Sadrian struct ath_tx_status ts; 4538240639Sadrian int drops = 0; 4539227364Sadrian 4540227364Sadrian /* 4541240677Sadrian * Take a copy of this; filtering/cloning the frame may free the 4542240677Sadrian * bf pointer. 4543240677Sadrian */ 4544240677Sadrian ts = bf->bf_status.ds_txstat; 4545240677Sadrian 4546240677Sadrian /* 4547227364Sadrian * Update rate control status here, before we possibly 4548227364Sadrian * punt to retry or cleanup. 4549227364Sadrian * 4550227364Sadrian * Do it outside of the TXQ lock. 4551227364Sadrian */ 4552233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 4553227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 4554227364Sadrian &bf->bf_status.ds_txstat, 4555227364Sadrian bf->bf_state.bfs_pktlen, 4556240677Sadrian 1, (ts.ts_status == 0) ? 0 : 1); 4557227364Sadrian 4558227364Sadrian /* 4559227364Sadrian * This is called early so atid->hwq_depth can be tracked. 4560227364Sadrian * This unfortunately means that it's released and regrabbed 4561227364Sadrian * during retry and cleanup. That's rather inefficient. 4562227364Sadrian */ 4563243786Sadrian ATH_TX_LOCK(sc); 4564227364Sadrian 4565227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4566227364Sadrian device_printf(sc->sc_dev, "%s: TID=16!\n", __func__); 4567227364Sadrian 4568229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 4569229949Sadrian "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n", 4570229949Sadrian __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth, 4571229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 4572227364Sadrian 4573227364Sadrian atid->hwq_depth--; 4574227364Sadrian if (atid->hwq_depth < 0) 4575227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 4576227364Sadrian __func__, atid->hwq_depth); 4577227364Sadrian 4578227364Sadrian /* 4579240639Sadrian * If the TID is filtered, handle completing the filter 4580240639Sadrian * transition before potentially kicking it to the cleanup 4581240639Sadrian * function. 4582240639Sadrian */ 4583240639Sadrian if (atid->isfiltered) 4584240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4585240639Sadrian 4586240639Sadrian /* 4587227364Sadrian * If a cleanup is in progress, punt to comp_cleanup; 4588227364Sadrian * rather than handling it here. It's thus their 4589227364Sadrian * responsibility to clean up, call the completion 4590227364Sadrian * function in net80211, etc. 4591227364Sadrian */ 4592227364Sadrian if (atid->cleanup_inprogress) { 4593240639Sadrian if (atid->isfiltered) 4594240639Sadrian device_printf(sc->sc_dev, 4595240639Sadrian "%s: isfiltered=1, normal_comp?\n", 4596240639Sadrian __func__); 4597243786Sadrian ATH_TX_UNLOCK(sc); 4598229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n", 4599229949Sadrian __func__); 4600227364Sadrian ath_tx_comp_cleanup_unaggr(sc, bf); 4601227364Sadrian return; 4602227364Sadrian } 4603227364Sadrian 4604227364Sadrian /* 4605240639Sadrian * XXX TODO: how does cleanup, BAR and filtered frame handling 4606240639Sadrian * overlap? 4607240639Sadrian * 4608240639Sadrian * If the frame is filtered OR if it's any failure but 4609240639Sadrian * the TID is filtered, the frame must be added to the 4610240639Sadrian * filtered frame list. 4611240639Sadrian * 4612240639Sadrian * However - a busy buffer can't be added to the filtered 4613240639Sadrian * list as it will end up being recycled without having 4614240639Sadrian * been made available for the hardware. 4615240639Sadrian */ 4616240677Sadrian if ((ts.ts_status & HAL_TXERR_FILT) || 4617240677Sadrian (ts.ts_status != 0 && atid->isfiltered)) { 4618240639Sadrian int freeframe; 4619240639Sadrian 4620240639Sadrian if (fail != 0) 4621240639Sadrian device_printf(sc->sc_dev, 4622240639Sadrian "%s: isfiltered=1, fail=%d\n", 4623240639Sadrian __func__, 4624240639Sadrian fail); 4625240639Sadrian freeframe = ath_tx_tid_filt_comp_single(sc, atid, bf); 4626240639Sadrian if (freeframe) { 4627240639Sadrian /* Remove from BAW */ 4628240639Sadrian if (bf->bf_state.bfs_addedbaw) 4629240639Sadrian drops++; 4630240639Sadrian if (bf->bf_state.bfs_dobaw) { 4631240639Sadrian ath_tx_update_baw(sc, an, atid, bf); 4632240639Sadrian if (! bf->bf_state.bfs_addedbaw) 4633240639Sadrian device_printf(sc->sc_dev, 4634240639Sadrian "%s: wasn't added: seqno %d\n", 4635240639Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4636240639Sadrian } 4637240639Sadrian bf->bf_state.bfs_dobaw = 0; 4638240639Sadrian } 4639240639Sadrian 4640240639Sadrian /* 4641240639Sadrian * If the frame couldn't be filtered, treat it as a drop and 4642240639Sadrian * prepare to send a BAR. 4643240639Sadrian */ 4644240639Sadrian if (freeframe && drops) 4645240639Sadrian ath_tx_tid_bar_suspend(sc, atid); 4646240639Sadrian 4647240639Sadrian /* 4648240639Sadrian * Send BAR if required 4649240639Sadrian */ 4650240639Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4651240639Sadrian ath_tx_tid_bar_tx(sc, atid); 4652240639Sadrian 4653243786Sadrian ATH_TX_UNLOCK(sc); 4654240639Sadrian /* 4655240639Sadrian * If freeframe is set, then the frame couldn't be 4656240639Sadrian * cloned and bf is still valid. Just complete/free it. 4657240639Sadrian */ 4658240639Sadrian if (freeframe) 4659240639Sadrian ath_tx_default_comp(sc, bf, fail); 4660240639Sadrian 4661240639Sadrian 4662240639Sadrian return; 4663240639Sadrian } 4664240639Sadrian /* 4665227364Sadrian * Don't bother with the retry check if all frames 4666227364Sadrian * are being failed (eg during queue deletion.) 4667227364Sadrian */ 4668235461Sadrian#if 0 4669227364Sadrian if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) { 4670235461Sadrian#endif 4671240677Sadrian if (fail == 0 && ts.ts_status != 0) { 4672243786Sadrian ATH_TX_UNLOCK(sc); 4673229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n", 4674229949Sadrian __func__); 4675227364Sadrian ath_tx_aggr_retry_unaggr(sc, bf); 4676227364Sadrian return; 4677227364Sadrian } 4678227364Sadrian 4679227364Sadrian /* Success? Complete */ 4680227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n", 4681227364Sadrian __func__, tid, SEQNO(bf->bf_state.bfs_seqno)); 4682227364Sadrian if (bf->bf_state.bfs_dobaw) { 4683227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 4684227364Sadrian bf->bf_state.bfs_dobaw = 0; 4685227364Sadrian if (! bf->bf_state.bfs_addedbaw) 4686227364Sadrian device_printf(sc->sc_dev, 4687227364Sadrian "%s: wasn't added: seqno %d\n", 4688227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 4689227364Sadrian } 4690227364Sadrian 4691233908Sadrian /* 4692240639Sadrian * If the queue is filtered, re-schedule as required. 4693240639Sadrian * 4694240639Sadrian * This is required as there may be a subsequent TX descriptor 4695240639Sadrian * for this end-node that has CLRDMASK set, so it's quite possible 4696240639Sadrian * that a filtered frame will be followed by a non-filtered 4697240639Sadrian * (complete or otherwise) frame. 4698240639Sadrian * 4699240639Sadrian * XXX should we do this before we complete the frame? 4700240639Sadrian */ 4701240639Sadrian if (atid->isfiltered) 4702240639Sadrian ath_tx_tid_filt_comp_complete(sc, atid); 4703240639Sadrian 4704240639Sadrian /* 4705233908Sadrian * Send BAR if required 4706233908Sadrian */ 4707233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 4708233908Sadrian ath_tx_tid_bar_tx(sc, atid); 4709233908Sadrian 4710243786Sadrian ATH_TX_UNLOCK(sc); 4711227364Sadrian 4712227364Sadrian ath_tx_default_comp(sc, bf, fail); 4713227364Sadrian /* bf is freed at this point */ 4714227364Sadrian} 4715227364Sadrian 4716227364Sadrianvoid 4717227364Sadrianath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 4718227364Sadrian{ 4719227364Sadrian if (bf->bf_state.bfs_aggr) 4720227364Sadrian ath_tx_aggr_comp_aggr(sc, bf, fail); 4721227364Sadrian else 4722227364Sadrian ath_tx_aggr_comp_unaggr(sc, bf, fail); 4723227364Sadrian} 4724227364Sadrian 4725227364Sadrian/* 4726227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4727227364Sadrian * 4728227364Sadrian * This is the aggregate version. 4729227364Sadrian */ 4730227364Sadrianvoid 4731227364Sadrianath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an, 4732227364Sadrian struct ath_tid *tid) 4733227364Sadrian{ 4734227364Sadrian struct ath_buf *bf; 4735227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4736227364Sadrian struct ieee80211_tx_ampdu *tap; 4737227364Sadrian ATH_AGGR_STATUS status; 4738227364Sadrian ath_bufhead bf_q; 4739227364Sadrian 4740227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid); 4741243786Sadrian ATH_TX_LOCK_ASSERT(sc); 4742227364Sadrian 4743227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 4744227364Sadrian 4745227364Sadrian if (tid->tid == IEEE80211_NONQOS_TID) 4746227364Sadrian device_printf(sc->sc_dev, "%s: called for TID=NONQOS_TID?\n", 4747227364Sadrian __func__); 4748227364Sadrian 4749227364Sadrian for (;;) { 4750227364Sadrian status = ATH_AGGR_DONE; 4751227364Sadrian 4752227364Sadrian /* 4753227364Sadrian * If the upper layer has paused the TID, don't 4754227364Sadrian * queue any further packets. 4755227364Sadrian * 4756227364Sadrian * This can also occur from the completion task because 4757227364Sadrian * of packet loss; but as its serialised with this code, 4758227364Sadrian * it won't "appear" half way through queuing packets. 4759227364Sadrian */ 4760227364Sadrian if (tid->paused) 4761227364Sadrian break; 4762227364Sadrian 4763241336Sadrian bf = ATH_TID_FIRST(tid); 4764227364Sadrian if (bf == NULL) { 4765227364Sadrian break; 4766227364Sadrian } 4767227364Sadrian 4768227364Sadrian /* 4769227364Sadrian * If the packet doesn't fall within the BAW (eg a NULL 4770227364Sadrian * data frame), schedule it directly; continue. 4771227364Sadrian */ 4772227364Sadrian if (! bf->bf_state.bfs_dobaw) { 4773229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4774229949Sadrian "%s: non-baw packet\n", 4775227364Sadrian __func__); 4776241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 4777240180Sadrian 4778240180Sadrian if (bf->bf_state.bfs_nframes > 1) 4779240180Sadrian device_printf(sc->sc_dev, 4780240180Sadrian "%s: aggr=%d, nframes=%d\n", 4781240180Sadrian __func__, 4782240180Sadrian bf->bf_state.bfs_aggr, 4783240180Sadrian bf->bf_state.bfs_nframes); 4784240180Sadrian 4785240180Sadrian /* 4786240180Sadrian * This shouldn't happen - such frames shouldn't 4787240180Sadrian * ever have been queued as an aggregate in the 4788240180Sadrian * first place. However, make sure the fields 4789240180Sadrian * are correctly setup just to be totally sure. 4790240180Sadrian */ 4791227364Sadrian bf->bf_state.bfs_aggr = 0; 4792240180Sadrian bf->bf_state.bfs_nframes = 1; 4793240180Sadrian 4794240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4795240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4796240724Sadrian 4797227364Sadrian ath_tx_do_ratelookup(sc, bf); 4798233989Sadrian ath_tx_calc_duration(sc, bf); 4799233989Sadrian ath_tx_calc_protection(sc, bf); 4800233989Sadrian ath_tx_set_rtscts(sc, bf); 4801227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4802227364Sadrian ath_tx_setds(sc, bf); 4803227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4804227364Sadrian 4805227364Sadrian sc->sc_aggr_stats.aggr_nonbaw_pkt++; 4806227364Sadrian 4807227364Sadrian /* Queue the packet; continue */ 4808227364Sadrian goto queuepkt; 4809227364Sadrian } 4810227364Sadrian 4811227364Sadrian TAILQ_INIT(&bf_q); 4812227364Sadrian 4813227364Sadrian /* 4814227364Sadrian * Do a rate control lookup on the first frame in the 4815227364Sadrian * list. The rate control code needs that to occur 4816227364Sadrian * before it can determine whether to TX. 4817227364Sadrian * It's inaccurate because the rate control code doesn't 4818227364Sadrian * really "do" aggregate lookups, so it only considers 4819227364Sadrian * the size of the first frame. 4820227364Sadrian */ 4821227364Sadrian ath_tx_do_ratelookup(sc, bf); 4822227364Sadrian bf->bf_state.bfs_rc[3].rix = 0; 4823227364Sadrian bf->bf_state.bfs_rc[3].tries = 0; 4824233989Sadrian 4825233989Sadrian ath_tx_calc_duration(sc, bf); 4826233989Sadrian ath_tx_calc_protection(sc, bf); 4827233989Sadrian 4828233989Sadrian ath_tx_set_rtscts(sc, bf); 4829227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4830227364Sadrian 4831227364Sadrian status = ath_tx_form_aggr(sc, an, tid, &bf_q); 4832227364Sadrian 4833227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4834227364Sadrian "%s: ath_tx_form_aggr() status=%d\n", __func__, status); 4835227364Sadrian 4836227364Sadrian /* 4837227364Sadrian * No frames to be picked up - out of BAW 4838227364Sadrian */ 4839227364Sadrian if (TAILQ_EMPTY(&bf_q)) 4840227364Sadrian break; 4841227364Sadrian 4842227364Sadrian /* 4843227364Sadrian * This assumes that the descriptor list in the ath_bufhead 4844227364Sadrian * are already linked together via bf_next pointers. 4845227364Sadrian */ 4846227364Sadrian bf = TAILQ_FIRST(&bf_q); 4847227364Sadrian 4848233989Sadrian if (status == ATH_AGGR_8K_LIMITED) 4849233989Sadrian sc->sc_aggr_stats.aggr_rts_aggr_limited++; 4850233989Sadrian 4851227364Sadrian /* 4852227364Sadrian * If it's the only frame send as non-aggregate 4853227364Sadrian * assume that ath_tx_form_aggr() has checked 4854227364Sadrian * whether it's in the BAW and added it appropriately. 4855227364Sadrian */ 4856227364Sadrian if (bf->bf_state.bfs_nframes == 1) { 4857227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4858227364Sadrian "%s: single-frame aggregate\n", __func__); 4859240724Sadrian 4860240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4861240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4862240724Sadrian 4863227364Sadrian bf->bf_state.bfs_aggr = 0; 4864240255Sadrian bf->bf_state.bfs_ndelim = 0; 4865227364Sadrian ath_tx_setds(sc, bf); 4866227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4867227364Sadrian if (status == ATH_AGGR_BAW_CLOSED) 4868227364Sadrian sc->sc_aggr_stats.aggr_baw_closed_single_pkt++; 4869227364Sadrian else 4870227364Sadrian sc->sc_aggr_stats.aggr_single_pkt++; 4871227364Sadrian } else { 4872227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4873229949Sadrian "%s: multi-frame aggregate: %d frames, " 4874229949Sadrian "length %d\n", 4875227364Sadrian __func__, bf->bf_state.bfs_nframes, 4876227364Sadrian bf->bf_state.bfs_al); 4877227364Sadrian bf->bf_state.bfs_aggr = 1; 4878227364Sadrian sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++; 4879227364Sadrian sc->sc_aggr_stats.aggr_aggr_pkt++; 4880227364Sadrian 4881240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4882240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4883240724Sadrian 4884227364Sadrian /* 4885233989Sadrian * Calculate the duration/protection as required. 4886233989Sadrian */ 4887233989Sadrian ath_tx_calc_duration(sc, bf); 4888233989Sadrian ath_tx_calc_protection(sc, bf); 4889233989Sadrian 4890233989Sadrian /* 4891227364Sadrian * Update the rate and rtscts information based on the 4892227364Sadrian * rate decision made by the rate control code; 4893227364Sadrian * the first frame in the aggregate needs it. 4894227364Sadrian */ 4895227364Sadrian ath_tx_set_rtscts(sc, bf); 4896227364Sadrian 4897227364Sadrian /* 4898227364Sadrian * Setup the relevant descriptor fields 4899227364Sadrian * for aggregation. The first descriptor 4900227364Sadrian * already points to the rest in the chain. 4901227364Sadrian */ 4902227364Sadrian ath_tx_setds_11n(sc, bf); 4903227364Sadrian 4904227364Sadrian } 4905227364Sadrian queuepkt: 4906227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 4907227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 4908227364Sadrian 4909227364Sadrian if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID) 4910227364Sadrian device_printf(sc->sc_dev, "%s: TID=16?\n", __func__); 4911227364Sadrian 4912227364Sadrian /* Punt to txq */ 4913227364Sadrian ath_tx_handoff(sc, txq, bf); 4914227364Sadrian 4915227364Sadrian /* Track outstanding buffer count to hardware */ 4916227364Sadrian /* aggregates are "one" buffer */ 4917227364Sadrian tid->hwq_depth++; 4918227364Sadrian 4919227364Sadrian /* 4920227364Sadrian * Break out if ath_tx_form_aggr() indicated 4921227364Sadrian * there can't be any further progress (eg BAW is full.) 4922227364Sadrian * Checking for an empty txq is done above. 4923227364Sadrian * 4924227364Sadrian * XXX locking on txq here? 4925227364Sadrian */ 4926227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit || 4927227364Sadrian status == ATH_AGGR_BAW_CLOSED) 4928227364Sadrian break; 4929227364Sadrian } 4930227364Sadrian} 4931227364Sadrian 4932227364Sadrian/* 4933227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4934227364Sadrian */ 4935227364Sadrianvoid 4936227364Sadrianath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an, 4937227364Sadrian struct ath_tid *tid) 4938227364Sadrian{ 4939227364Sadrian struct ath_buf *bf; 4940227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4941227364Sadrian 4942227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n", 4943227364Sadrian __func__, an, tid->tid); 4944227364Sadrian 4945243786Sadrian ATH_TX_LOCK_ASSERT(sc); 4946227364Sadrian 4947227364Sadrian /* Check - is AMPDU pending or running? then print out something */ 4948227364Sadrian if (ath_tx_ampdu_pending(sc, an, tid->tid)) 4949227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu pending?\n", 4950227364Sadrian __func__, tid->tid); 4951227364Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid)) 4952227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu running?\n", 4953227364Sadrian __func__, tid->tid); 4954227364Sadrian 4955227364Sadrian for (;;) { 4956227364Sadrian 4957227364Sadrian /* 4958227364Sadrian * If the upper layers have paused the TID, don't 4959227364Sadrian * queue any further packets. 4960227364Sadrian */ 4961227364Sadrian if (tid->paused) 4962227364Sadrian break; 4963227364Sadrian 4964241336Sadrian bf = ATH_TID_FIRST(tid); 4965227364Sadrian if (bf == NULL) { 4966227364Sadrian break; 4967227364Sadrian } 4968227364Sadrian 4969241336Sadrian ATH_TID_REMOVE(tid, bf, bf_list); 4970227364Sadrian 4971227364Sadrian /* Sanity check! */ 4972227364Sadrian if (tid->tid != bf->bf_state.bfs_tid) { 4973227364Sadrian device_printf(sc->sc_dev, "%s: bfs_tid %d !=" 4974227364Sadrian " tid %d\n", 4975227364Sadrian __func__, bf->bf_state.bfs_tid, tid->tid); 4976227364Sadrian } 4977227364Sadrian /* Normal completion handler */ 4978227364Sadrian bf->bf_comp = ath_tx_normal_comp; 4979227364Sadrian 4980240883Sadrian /* 4981240883Sadrian * Override this for now, until the non-aggregate 4982240883Sadrian * completion handler correctly handles software retransmits. 4983240883Sadrian */ 4984240883Sadrian bf->bf_state.bfs_txflags |= HAL_TXDESC_CLRDMASK; 4985240883Sadrian 4986240724Sadrian /* Update CLRDMASK just before this frame is queued */ 4987240724Sadrian ath_tx_update_clrdmask(sc, tid, bf); 4988240724Sadrian 4989227364Sadrian /* Program descriptors + rate control */ 4990227364Sadrian ath_tx_do_ratelookup(sc, bf); 4991233989Sadrian ath_tx_calc_duration(sc, bf); 4992233989Sadrian ath_tx_calc_protection(sc, bf); 4993233989Sadrian ath_tx_set_rtscts(sc, bf); 4994227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4995227364Sadrian ath_tx_setds(sc, bf); 4996227364Sadrian 4997227364Sadrian /* Track outstanding buffer count to hardware */ 4998227364Sadrian /* aggregates are "one" buffer */ 4999227364Sadrian tid->hwq_depth++; 5000227364Sadrian 5001227364Sadrian /* Punt to hardware or software txq */ 5002227364Sadrian ath_tx_handoff(sc, txq, bf); 5003227364Sadrian } 5004227364Sadrian} 5005227364Sadrian 5006227364Sadrian/* 5007227364Sadrian * Schedule some packets to the given hardware queue. 5008227364Sadrian * 5009227364Sadrian * This function walks the list of TIDs (ie, ath_node TIDs 5010227364Sadrian * with queued traffic) and attempts to schedule traffic 5011227364Sadrian * from them. 5012227364Sadrian * 5013227364Sadrian * TID scheduling is implemented as a FIFO, with TIDs being 5014227364Sadrian * added to the end of the queue after some frames have been 5015227364Sadrian * scheduled. 5016227364Sadrian */ 5017227364Sadrianvoid 5018227364Sadrianath_txq_sched(struct ath_softc *sc, struct ath_txq *txq) 5019227364Sadrian{ 5020227364Sadrian struct ath_tid *tid, *next, *last; 5021227364Sadrian 5022243786Sadrian ATH_TX_LOCK_ASSERT(sc); 5023227364Sadrian 5024227364Sadrian /* 5025227364Sadrian * Don't schedule if the hardware queue is busy. 5026227364Sadrian * This (hopefully) gives some more time to aggregate 5027227364Sadrian * some packets in the aggregation queue. 5028227364Sadrian */ 5029227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 5030227364Sadrian sc->sc_aggr_stats.aggr_sched_nopkt++; 5031227364Sadrian return; 5032227364Sadrian } 5033227364Sadrian 5034227364Sadrian last = TAILQ_LAST(&txq->axq_tidq, axq_t_s); 5035227364Sadrian 5036227364Sadrian TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) { 5037227364Sadrian /* 5038227364Sadrian * Suspend paused queues here; they'll be resumed 5039227364Sadrian * once the addba completes or times out. 5040227364Sadrian */ 5041227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n", 5042227364Sadrian __func__, tid->tid, tid->paused); 5043227364Sadrian ath_tx_tid_unsched(sc, tid); 5044227364Sadrian if (tid->paused) { 5045227364Sadrian continue; 5046227364Sadrian } 5047227364Sadrian if (ath_tx_ampdu_running(sc, tid->an, tid->tid)) 5048227364Sadrian ath_tx_tid_hw_queue_aggr(sc, tid->an, tid); 5049227364Sadrian else 5050227364Sadrian ath_tx_tid_hw_queue_norm(sc, tid->an, tid); 5051227364Sadrian 5052227364Sadrian /* Not empty? Re-schedule */ 5053227364Sadrian if (tid->axq_depth != 0) 5054227364Sadrian ath_tx_tid_sched(sc, tid); 5055227364Sadrian 5056227364Sadrian /* Give the software queue time to aggregate more packets */ 5057227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 5058227364Sadrian break; 5059227364Sadrian } 5060227364Sadrian 5061227364Sadrian /* 5062227364Sadrian * If this was the last entry on the original list, stop. 5063227364Sadrian * Otherwise nodes that have been rescheduled onto the end 5064227364Sadrian * of the TID FIFO list will just keep being rescheduled. 5065227364Sadrian */ 5066227364Sadrian if (tid == last) 5067227364Sadrian break; 5068227364Sadrian } 5069227364Sadrian} 5070227364Sadrian 5071227364Sadrian/* 5072227364Sadrian * TX addba handling 5073227364Sadrian */ 5074227364Sadrian 5075227364Sadrian/* 5076227364Sadrian * Return net80211 TID struct pointer, or NULL for none 5077227364Sadrian */ 5078227364Sadrianstruct ieee80211_tx_ampdu * 5079227364Sadrianath_tx_get_tx_tid(struct ath_node *an, int tid) 5080227364Sadrian{ 5081227364Sadrian struct ieee80211_node *ni = &an->an_node; 5082227364Sadrian struct ieee80211_tx_ampdu *tap; 5083227364Sadrian 5084227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5085227364Sadrian return NULL; 5086227364Sadrian 5087234324Sadrian tap = &ni->ni_tx_ampdu[tid]; 5088227364Sadrian return tap; 5089227364Sadrian} 5090227364Sadrian 5091227364Sadrian/* 5092227364Sadrian * Is AMPDU-TX running? 5093227364Sadrian */ 5094227364Sadrianstatic int 5095227364Sadrianath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid) 5096227364Sadrian{ 5097227364Sadrian struct ieee80211_tx_ampdu *tap; 5098227364Sadrian 5099227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5100227364Sadrian return 0; 5101227364Sadrian 5102227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 5103227364Sadrian if (tap == NULL) 5104227364Sadrian return 0; /* Not valid; default to not running */ 5105227364Sadrian 5106227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING); 5107227364Sadrian} 5108227364Sadrian 5109227364Sadrian/* 5110227364Sadrian * Is AMPDU-TX negotiation pending? 5111227364Sadrian */ 5112227364Sadrianstatic int 5113227364Sadrianath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid) 5114227364Sadrian{ 5115227364Sadrian struct ieee80211_tx_ampdu *tap; 5116227364Sadrian 5117227364Sadrian if (tid == IEEE80211_NONQOS_TID) 5118227364Sadrian return 0; 5119227364Sadrian 5120227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 5121227364Sadrian if (tap == NULL) 5122227364Sadrian return 0; /* Not valid; default to not pending */ 5123227364Sadrian 5124227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND); 5125227364Sadrian} 5126227364Sadrian 5127227364Sadrian/* 5128227364Sadrian * Is AMPDU-TX pending for the given TID? 5129227364Sadrian */ 5130227364Sadrian 5131227364Sadrian 5132227364Sadrian/* 5133227364Sadrian * Method to handle sending an ADDBA request. 5134227364Sadrian * 5135227364Sadrian * We tap this so the relevant flags can be set to pause the TID 5136227364Sadrian * whilst waiting for the response. 5137227364Sadrian * 5138227364Sadrian * XXX there's no timeout handler we can override? 5139227364Sadrian */ 5140227364Sadrianint 5141227364Sadrianath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5142227364Sadrian int dialogtoken, int baparamset, int batimeout) 5143227364Sadrian{ 5144227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5145234324Sadrian int tid = tap->txa_tid; 5146227364Sadrian struct ath_node *an = ATH_NODE(ni); 5147227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5148227364Sadrian 5149227364Sadrian /* 5150227364Sadrian * XXX danger Will Robinson! 5151227364Sadrian * 5152227364Sadrian * Although the taskqueue may be running and scheduling some more 5153227364Sadrian * packets, these should all be _before_ the addba sequence number. 5154227364Sadrian * However, net80211 will keep self-assigning sequence numbers 5155227364Sadrian * until addba has been negotiated. 5156227364Sadrian * 5157227364Sadrian * In the past, these packets would be "paused" (which still works 5158227364Sadrian * fine, as they're being scheduled to the driver in the same 5159227364Sadrian * serialised method which is calling the addba request routine) 5160227364Sadrian * and when the aggregation session begins, they'll be dequeued 5161227364Sadrian * as aggregate packets and added to the BAW. However, now there's 5162227364Sadrian * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these 5163227364Sadrian * packets. Thus they never get included in the BAW tracking and 5164227364Sadrian * this can cause the initial burst of packets after the addba 5165227364Sadrian * negotiation to "hang", as they quickly fall outside the BAW. 5166227364Sadrian * 5167227364Sadrian * The "eventual" solution should be to tag these packets with 5168227364Sadrian * dobaw. Although net80211 has given us a sequence number, 5169227364Sadrian * it'll be "after" the left edge of the BAW and thus it'll 5170227364Sadrian * fall within it. 5171227364Sadrian */ 5172243786Sadrian ATH_TX_LOCK(sc); 5173235774Sadrian /* 5174235774Sadrian * This is a bit annoying. Until net80211 HT code inherits some 5175235774Sadrian * (any) locking, we may have this called in parallel BUT only 5176235774Sadrian * one response/timeout will be called. Grr. 5177235774Sadrian */ 5178235774Sadrian if (atid->addba_tx_pending == 0) { 5179235774Sadrian ath_tx_tid_pause(sc, atid); 5180235774Sadrian atid->addba_tx_pending = 1; 5181235774Sadrian } 5182243786Sadrian ATH_TX_UNLOCK(sc); 5183227364Sadrian 5184227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5185227364Sadrian "%s: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n", 5186227364Sadrian __func__, dialogtoken, baparamset, batimeout); 5187227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5188227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 5189227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 5190227364Sadrian 5191227364Sadrian return sc->sc_addba_request(ni, tap, dialogtoken, baparamset, 5192227364Sadrian batimeout); 5193227364Sadrian} 5194227364Sadrian 5195227364Sadrian/* 5196227364Sadrian * Handle an ADDBA response. 5197227364Sadrian * 5198227364Sadrian * We unpause the queue so TX'ing can resume. 5199227364Sadrian * 5200227364Sadrian * Any packets TX'ed from this point should be "aggregate" (whether 5201227364Sadrian * aggregate or not) so the BAW is updated. 5202227364Sadrian * 5203227364Sadrian * Note! net80211 keeps self-assigning sequence numbers until 5204227364Sadrian * ampdu is negotiated. This means the initially-negotiated BAW left 5205227364Sadrian * edge won't match the ni->ni_txseq. 5206227364Sadrian * 5207227364Sadrian * So, being very dirty, the BAW left edge is "slid" here to match 5208227364Sadrian * ni->ni_txseq. 5209227364Sadrian * 5210227364Sadrian * What likely SHOULD happen is that all packets subsequent to the 5211227364Sadrian * addba request should be tagged as aggregate and queued as non-aggregate 5212227364Sadrian * frames; thus updating the BAW. For now though, I'll just slide the 5213227364Sadrian * window. 5214227364Sadrian */ 5215227364Sadrianint 5216227364Sadrianath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5217227364Sadrian int status, int code, int batimeout) 5218227364Sadrian{ 5219227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5220234324Sadrian int tid = tap->txa_tid; 5221227364Sadrian struct ath_node *an = ATH_NODE(ni); 5222227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5223227364Sadrian int r; 5224227364Sadrian 5225227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5226227364Sadrian "%s: called; status=%d, code=%d, batimeout=%d\n", __func__, 5227227364Sadrian status, code, batimeout); 5228227364Sadrian 5229227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5230227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 5231227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 5232227364Sadrian 5233227364Sadrian /* 5234227364Sadrian * Call this first, so the interface flags get updated 5235227364Sadrian * before the TID is unpaused. Otherwise a race condition 5236227364Sadrian * exists where the unpaused TID still doesn't yet have 5237227364Sadrian * IEEE80211_AGGR_RUNNING set. 5238227364Sadrian */ 5239227364Sadrian r = sc->sc_addba_response(ni, tap, status, code, batimeout); 5240227364Sadrian 5241243786Sadrian ATH_TX_LOCK(sc); 5242235774Sadrian atid->addba_tx_pending = 0; 5243227364Sadrian /* 5244227364Sadrian * XXX dirty! 5245227364Sadrian * Slide the BAW left edge to wherever net80211 left it for us. 5246227364Sadrian * Read above for more information. 5247227364Sadrian */ 5248227364Sadrian tap->txa_start = ni->ni_txseqs[tid]; 5249227364Sadrian ath_tx_tid_resume(sc, atid); 5250243786Sadrian ATH_TX_UNLOCK(sc); 5251227364Sadrian return r; 5252227364Sadrian} 5253227364Sadrian 5254227364Sadrian 5255227364Sadrian/* 5256227364Sadrian * Stop ADDBA on a queue. 5257237593Sadrian * 5258237593Sadrian * This can be called whilst BAR TX is currently active on the queue, 5259237593Sadrian * so make sure this is unblocked before continuing. 5260227364Sadrian */ 5261227364Sadrianvoid 5262227364Sadrianath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 5263227364Sadrian{ 5264227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5265234324Sadrian int tid = tap->txa_tid; 5266227364Sadrian struct ath_node *an = ATH_NODE(ni); 5267227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5268227364Sadrian 5269227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: called\n", __func__); 5270227364Sadrian 5271237593Sadrian /* 5272237593Sadrian * Pause TID traffic early, so there aren't any races 5273237593Sadrian * Unblock the pending BAR held traffic, if it's currently paused. 5274237593Sadrian */ 5275243786Sadrian ATH_TX_LOCK(sc); 5276227364Sadrian ath_tx_tid_pause(sc, atid); 5277237593Sadrian if (atid->bar_wait) { 5278237593Sadrian /* 5279237593Sadrian * bar_unsuspend() expects bar_tx == 1, as it should be 5280237593Sadrian * called from the TX completion path. This quietens 5281237593Sadrian * the warning. It's cleared for us anyway. 5282237593Sadrian */ 5283237593Sadrian atid->bar_tx = 1; 5284237593Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5285237593Sadrian } 5286243786Sadrian ATH_TX_UNLOCK(sc); 5287227364Sadrian 5288227364Sadrian /* There's no need to hold the TXQ lock here */ 5289227364Sadrian sc->sc_addba_stop(ni, tap); 5290227364Sadrian 5291227364Sadrian /* 5292235749Sadrian * ath_tx_tid_cleanup will resume the TID if possible, otherwise 5293227364Sadrian * it'll set the cleanup flag, and it'll be unpaused once 5294227364Sadrian * things have been cleaned up. 5295227364Sadrian */ 5296235749Sadrian ath_tx_tid_cleanup(sc, an, tid); 5297227364Sadrian} 5298227364Sadrian 5299227364Sadrian/* 5300227364Sadrian * Note: net80211 bar_timeout() doesn't call this function on BAR failure; 5301227364Sadrian * it simply tears down the aggregation session. Ew. 5302227364Sadrian * 5303227364Sadrian * It however will call ieee80211_ampdu_stop() which will call 5304227364Sadrian * ic->ic_addba_stop(). 5305227364Sadrian * 5306227364Sadrian * XXX This uses a hard-coded max BAR count value; the whole 5307227364Sadrian * XXX BAR TX success or failure should be better handled! 5308227364Sadrian */ 5309227364Sadrianvoid 5310227364Sadrianath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 5311227364Sadrian int status) 5312227364Sadrian{ 5313227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5314234324Sadrian int tid = tap->txa_tid; 5315227364Sadrian struct ath_node *an = ATH_NODE(ni); 5316227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5317227364Sadrian int attempts = tap->txa_attempts; 5318227364Sadrian 5319235491Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAR, 5320235676Sadrian "%s: called; tap=%p, atid=%p, txa_tid=%d, atid->tid=%d, status=%d, attempts=%d\n", 5321235491Sadrian __func__, 5322235676Sadrian tap, 5323235676Sadrian atid, 5324235676Sadrian tap->txa_tid, 5325235676Sadrian atid->tid, 5326235491Sadrian status, 5327235491Sadrian attempts); 5328227364Sadrian 5329227364Sadrian /* Note: This may update the BAW details */ 5330227364Sadrian sc->sc_bar_response(ni, tap, status); 5331227364Sadrian 5332227364Sadrian /* Unpause the TID */ 5333227364Sadrian /* 5334227364Sadrian * XXX if this is attempt=50, the TID will be downgraded 5335227364Sadrian * XXX to a non-aggregate session. So we must unpause the 5336227364Sadrian * XXX TID here or it'll never be done. 5337240721Sadrian * 5338240721Sadrian * Also, don't call it if bar_tx/bar_wait are 0; something 5339240721Sadrian * has beaten us to the punch? (XXX figure out what?) 5340227364Sadrian */ 5341227364Sadrian if (status == 0 || attempts == 50) { 5342243786Sadrian ATH_TX_LOCK(sc); 5343240721Sadrian if (atid->bar_tx == 0 || atid->bar_wait == 0) 5344240721Sadrian device_printf(sc->sc_dev, 5345240721Sadrian "%s: huh? bar_tx=%d, bar_wait=%d\n", 5346240721Sadrian __func__, 5347240721Sadrian atid->bar_tx, atid->bar_wait); 5348240721Sadrian else 5349240721Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 5350243786Sadrian ATH_TX_UNLOCK(sc); 5351227364Sadrian } 5352227364Sadrian} 5353227364Sadrian 5354227364Sadrian/* 5355227364Sadrian * This is called whenever the pending ADDBA request times out. 5356227364Sadrian * Unpause and reschedule the TID. 5357227364Sadrian */ 5358227364Sadrianvoid 5359227364Sadrianath_addba_response_timeout(struct ieee80211_node *ni, 5360227364Sadrian struct ieee80211_tx_ampdu *tap) 5361227364Sadrian{ 5362227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 5363234324Sadrian int tid = tap->txa_tid; 5364227364Sadrian struct ath_node *an = ATH_NODE(ni); 5365227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 5366227364Sadrian 5367227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 5368227364Sadrian "%s: called; resuming\n", __func__); 5369227364Sadrian 5370243786Sadrian ATH_TX_LOCK(sc); 5371235774Sadrian atid->addba_tx_pending = 0; 5372243786Sadrian ATH_TX_UNLOCK(sc); 5373235774Sadrian 5374227364Sadrian /* Note: This updates the aggregate state to (again) pending */ 5375227364Sadrian sc->sc_addba_response_timeout(ni, tap); 5376227364Sadrian 5377227364Sadrian /* Unpause the TID; which reschedules it */ 5378243786Sadrian ATH_TX_LOCK(sc); 5379227364Sadrian ath_tx_tid_resume(sc, atid); 5380243786Sadrian ATH_TX_UNLOCK(sc); 5381227364Sadrian} 5382238710Sadrian 5383241170Sadrian/* 5384241170Sadrian * Check if a node is asleep or not. 5385241170Sadrian */ 5386242271Sadrianint 5387241170Sadrianath_tx_node_is_asleep(struct ath_softc *sc, struct ath_node *an) 5388241170Sadrian{ 5389241170Sadrian 5390241170Sadrian ATH_NODE_LOCK_ASSERT(an); 5391241170Sadrian 5392241170Sadrian return (an->an_is_powersave); 5393241170Sadrian} 5394241170Sadrian 5395241170Sadrian/* 5396241170Sadrian * Mark a node as currently "in powersaving." 5397241170Sadrian * This suspends all traffic on the node. 5398241170Sadrian * 5399241170Sadrian * This must be called with the node/tx locks free. 5400241170Sadrian * 5401241170Sadrian * XXX TODO: the locking silliness below is due to how the node 5402241170Sadrian * locking currently works. Right now, the node lock is grabbed 5403241170Sadrian * to do rate control lookups and these are done with the TX 5404241170Sadrian * queue lock held. This means the node lock can't be grabbed 5405241170Sadrian * first here or a LOR will occur. 5406241170Sadrian * 5407241170Sadrian * Eventually (hopefully!) the TX path code will only grab 5408241170Sadrian * the TXQ lock when transmitting and the ath_node lock when 5409241170Sadrian * doing node/TID operations. There are other complications - 5410241170Sadrian * the sched/unsched operations involve walking the per-txq 5411241170Sadrian * 'active tid' list and this requires both locks to be held. 5412241170Sadrian */ 5413241170Sadrianvoid 5414241170Sadrianath_tx_node_sleep(struct ath_softc *sc, struct ath_node *an) 5415241170Sadrian{ 5416241170Sadrian struct ath_tid *atid; 5417241170Sadrian struct ath_txq *txq; 5418241170Sadrian int tid; 5419241170Sadrian 5420241170Sadrian ATH_NODE_UNLOCK_ASSERT(an); 5421241170Sadrian 5422241170Sadrian /* 5423241170Sadrian * It's possible that a parallel call to ath_tx_node_wakeup() 5424241170Sadrian * will unpause these queues. 5425241170Sadrian * 5426241170Sadrian * The node lock can't just be grabbed here, as there's places 5427241170Sadrian * in the driver where the node lock is grabbed _within_ a 5428241170Sadrian * TXQ lock. 5429241170Sadrian * So, we do this delicately and unwind state if needed. 5430241170Sadrian * 5431241170Sadrian * + Pause all the queues 5432241170Sadrian * + Grab the node lock 5433241170Sadrian * + If the queue is already asleep, unpause and quit 5434241170Sadrian * + else just mark as asleep. 5435241170Sadrian * 5436241170Sadrian * A parallel sleep() call will just pause and then 5437241170Sadrian * find they're already paused, so undo it. 5438241170Sadrian * 5439241170Sadrian * A parallel wakeup() call will check if asleep is 1 5440241170Sadrian * and if it's not (ie, it's 0), it'll treat it as already 5441241170Sadrian * being awake. If it's 1, it'll mark it as 0 and then 5442241170Sadrian * unpause everything. 5443241170Sadrian * 5444241170Sadrian * (Talk about a delicate hack.) 5445241170Sadrian */ 5446241170Sadrian 5447241170Sadrian /* Suspend all traffic on the node */ 5448243786Sadrian ATH_TX_LOCK(sc); 5449241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5450241170Sadrian atid = &an->an_tid[tid]; 5451241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5452241170Sadrian 5453241170Sadrian ath_tx_tid_pause(sc, atid); 5454241170Sadrian } 5455243786Sadrian ATH_TX_UNLOCK(sc); 5456241170Sadrian 5457241170Sadrian ATH_NODE_LOCK(an); 5458241170Sadrian 5459241170Sadrian /* In case of concurrency races from net80211.. */ 5460241170Sadrian if (an->an_is_powersave == 1) { 5461241170Sadrian ATH_NODE_UNLOCK(an); 5462241170Sadrian device_printf(sc->sc_dev, 5463241170Sadrian "%s: an=%p: node was already asleep\n", 5464241170Sadrian __func__, an); 5465243786Sadrian ATH_TX_LOCK(sc); 5466241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5467241170Sadrian atid = &an->an_tid[tid]; 5468241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5469241170Sadrian 5470241170Sadrian ath_tx_tid_resume(sc, atid); 5471241170Sadrian } 5472243786Sadrian ATH_TX_UNLOCK(sc); 5473241170Sadrian return; 5474241170Sadrian } 5475241170Sadrian 5476241170Sadrian /* Mark node as in powersaving */ 5477241170Sadrian an->an_is_powersave = 1; 5478241170Sadrian 5479241170Sadrian ATH_NODE_UNLOCK(an); 5480241170Sadrian} 5481241170Sadrian 5482241170Sadrian/* 5483241170Sadrian * Mark a node as currently "awake." 5484241170Sadrian * This resumes all traffic to the node. 5485241170Sadrian */ 5486241170Sadrianvoid 5487241170Sadrianath_tx_node_wakeup(struct ath_softc *sc, struct ath_node *an) 5488241170Sadrian{ 5489241170Sadrian struct ath_tid *atid; 5490241170Sadrian struct ath_txq *txq; 5491241170Sadrian int tid; 5492241170Sadrian 5493241170Sadrian ATH_NODE_UNLOCK_ASSERT(an); 5494241170Sadrian ATH_NODE_LOCK(an); 5495241170Sadrian 5496241170Sadrian /* In case of concurrency races from net80211.. */ 5497241170Sadrian if (an->an_is_powersave == 0) { 5498241170Sadrian ATH_NODE_UNLOCK(an); 5499241170Sadrian device_printf(sc->sc_dev, 5500241170Sadrian "%s: an=%p: node was already awake\n", 5501241170Sadrian __func__, an); 5502241170Sadrian return; 5503241170Sadrian } 5504241170Sadrian 5505241170Sadrian /* Mark node as awake */ 5506241170Sadrian an->an_is_powersave = 0; 5507241170Sadrian 5508241170Sadrian ATH_NODE_UNLOCK(an); 5509241170Sadrian 5510243786Sadrian ATH_TX_LOCK(sc); 5511241170Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 5512241170Sadrian atid = &an->an_tid[tid]; 5513241170Sadrian txq = sc->sc_ac2q[atid->ac]; 5514241170Sadrian 5515241170Sadrian ath_tx_tid_resume(sc, atid); 5516241170Sadrian } 5517243786Sadrian ATH_TX_UNLOCK(sc); 5518241170Sadrian} 5519241170Sadrian 5520241170Sadrianstatic int 5521238710Sadrianath_legacy_dma_txsetup(struct ath_softc *sc) 5522238710Sadrian{ 5523238710Sadrian 5524238710Sadrian /* nothing new needed */ 5525238710Sadrian return (0); 5526238710Sadrian} 5527238710Sadrian 5528238710Sadrianstatic int 5529238710Sadrianath_legacy_dma_txteardown(struct ath_softc *sc) 5530238710Sadrian{ 5531238710Sadrian 5532238710Sadrian /* nothing new needed */ 5533238710Sadrian return (0); 5534238710Sadrian} 5535238710Sadrian 5536238710Sadrianvoid 5537238710Sadrianath_xmit_setup_legacy(struct ath_softc *sc) 5538238710Sadrian{ 5539238729Sadrian /* 5540238729Sadrian * For now, just set the descriptor length to sizeof(ath_desc); 5541238729Sadrian * worry about extracting the real length out of the HAL later. 5542238729Sadrian */ 5543238729Sadrian sc->sc_tx_desclen = sizeof(struct ath_desc); 5544243162Sadrian sc->sc_tx_statuslen = sizeof(struct ath_desc); 5545238729Sadrian sc->sc_tx_nmaps = 1; /* only one buffer per TX desc */ 5546238710Sadrian 5547238710Sadrian sc->sc_tx.xmit_setup = ath_legacy_dma_txsetup; 5548238710Sadrian sc->sc_tx.xmit_teardown = ath_legacy_dma_txteardown; 5549238931Sadrian sc->sc_tx.xmit_attach_comp_func = ath_legacy_attach_comp_func; 5550238930Sadrian 5551238930Sadrian sc->sc_tx.xmit_dma_restart = ath_legacy_tx_dma_restart; 5552238930Sadrian sc->sc_tx.xmit_handoff = ath_legacy_xmit_handoff; 5553239204Sadrian 5554239204Sadrian sc->sc_tx.xmit_drain = ath_legacy_tx_drain; 5555238710Sadrian} 5556