if_ath_tx.c revision 234725
1218065Sadrian/*- 2218065Sadrian * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3218065Sadrian * All rights reserved. 4218065Sadrian * 5218065Sadrian * Redistribution and use in source and binary forms, with or without 6218065Sadrian * modification, are permitted provided that the following conditions 7218065Sadrian * are met: 8218065Sadrian * 1. Redistributions of source code must retain the above copyright 9218065Sadrian * notice, this list of conditions and the following disclaimer, 10218065Sadrian * without modification. 11218065Sadrian * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12218065Sadrian * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13218065Sadrian * redistribution must be conditioned upon including a substantially 14218065Sadrian * similar Disclaimer requirement for further binary redistribution. 15218065Sadrian * 16218065Sadrian * NO WARRANTY 17218065Sadrian * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18218065Sadrian * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19218065Sadrian * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20218065Sadrian * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21218065Sadrian * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22218065Sadrian * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23218065Sadrian * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24218065Sadrian * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25218065Sadrian * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26218065Sadrian * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27218065Sadrian * THE POSSIBILITY OF SUCH DAMAGES. 28218065Sadrian */ 29218065Sadrian 30218065Sadrian#include <sys/cdefs.h> 31218065Sadrian__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath_tx.c 234725 2012-04-26 23:57:24Z adrian $"); 32218065Sadrian 33218065Sadrian/* 34218065Sadrian * Driver for the Atheros Wireless LAN controller. 35218065Sadrian * 36218065Sadrian * This software is derived from work of Atsushi Onoe; his contribution 37218065Sadrian * is greatly appreciated. 38218065Sadrian */ 39218065Sadrian 40218065Sadrian#include "opt_inet.h" 41218065Sadrian#include "opt_ath.h" 42218065Sadrian#include "opt_wlan.h" 43218065Sadrian 44218065Sadrian#include <sys/param.h> 45218065Sadrian#include <sys/systm.h> 46218065Sadrian#include <sys/sysctl.h> 47218065Sadrian#include <sys/mbuf.h> 48218065Sadrian#include <sys/malloc.h> 49218065Sadrian#include <sys/lock.h> 50218065Sadrian#include <sys/mutex.h> 51218065Sadrian#include <sys/kernel.h> 52218065Sadrian#include <sys/socket.h> 53218065Sadrian#include <sys/sockio.h> 54218065Sadrian#include <sys/errno.h> 55218065Sadrian#include <sys/callout.h> 56218065Sadrian#include <sys/bus.h> 57218065Sadrian#include <sys/endian.h> 58218065Sadrian#include <sys/kthread.h> 59218065Sadrian#include <sys/taskqueue.h> 60218065Sadrian#include <sys/priv.h> 61218065Sadrian 62218065Sadrian#include <machine/bus.h> 63218065Sadrian 64218065Sadrian#include <net/if.h> 65218065Sadrian#include <net/if_dl.h> 66218065Sadrian#include <net/if_media.h> 67218065Sadrian#include <net/if_types.h> 68218065Sadrian#include <net/if_arp.h> 69218065Sadrian#include <net/ethernet.h> 70218065Sadrian#include <net/if_llc.h> 71218065Sadrian 72218065Sadrian#include <net80211/ieee80211_var.h> 73218065Sadrian#include <net80211/ieee80211_regdomain.h> 74218065Sadrian#ifdef IEEE80211_SUPPORT_SUPERG 75218065Sadrian#include <net80211/ieee80211_superg.h> 76218065Sadrian#endif 77218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 78218065Sadrian#include <net80211/ieee80211_tdma.h> 79218065Sadrian#endif 80227364Sadrian#include <net80211/ieee80211_ht.h> 81218065Sadrian 82218065Sadrian#include <net/bpf.h> 83218065Sadrian 84218065Sadrian#ifdef INET 85218065Sadrian#include <netinet/in.h> 86218065Sadrian#include <netinet/if_ether.h> 87218065Sadrian#endif 88218065Sadrian 89218065Sadrian#include <dev/ath/if_athvar.h> 90218065Sadrian#include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */ 91218065Sadrian#include <dev/ath/ath_hal/ah_diagcodes.h> 92218065Sadrian 93218065Sadrian#include <dev/ath/if_ath_debug.h> 94218065Sadrian 95218065Sadrian#ifdef ATH_TX99_DIAG 96218065Sadrian#include <dev/ath/ath_tx99/ath_tx99.h> 97218065Sadrian#endif 98218065Sadrian 99218065Sadrian#include <dev/ath/if_ath_misc.h> 100218065Sadrian#include <dev/ath/if_ath_tx.h> 101218240Sadrian#include <dev/ath/if_ath_tx_ht.h> 102218065Sadrian 103218154Sadrian/* 104227364Sadrian * How many retries to perform in software 105227364Sadrian */ 106227364Sadrian#define SWMAX_RETRIES 10 107227364Sadrian 108227364Sadrianstatic int ath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, 109227364Sadrian int tid); 110227364Sadrianstatic int ath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, 111227364Sadrian int tid); 112227364Sadrianstatic int ath_tx_action_frame_override_queue(struct ath_softc *sc, 113227364Sadrian struct ieee80211_node *ni, struct mbuf *m0, int *tid); 114233227Sadrianstatic int ath_tx_seqno_required(struct ath_softc *sc, 115233227Sadrian struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0); 116227364Sadrian 117227364Sadrian/* 118218154Sadrian * Whether to use the 11n rate scenario functions or not 119218154Sadrian */ 120218154Sadrianstatic inline int 121218154Sadrianath_tx_is_11n(struct ath_softc *sc) 122218154Sadrian{ 123218154Sadrian return (sc->sc_ah->ah_magic == 0x20065416); 124218154Sadrian} 125218154Sadrian 126227364Sadrian/* 127227364Sadrian * Obtain the current TID from the given frame. 128227364Sadrian * 129227364Sadrian * Non-QoS frames need to go into TID 16 (IEEE80211_NONQOS_TID.) 130227364Sadrian * This has implications for which AC/priority the packet is placed 131227364Sadrian * in. 132227364Sadrian */ 133227364Sadrianstatic int 134227364Sadrianath_tx_gettid(struct ath_softc *sc, const struct mbuf *m0) 135227364Sadrian{ 136227364Sadrian const struct ieee80211_frame *wh; 137227364Sadrian int pri = M_WME_GETAC(m0); 138227364Sadrian 139227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 140227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 141227364Sadrian return IEEE80211_NONQOS_TID; 142227364Sadrian else 143227364Sadrian return WME_AC_TO_TID(pri); 144227364Sadrian} 145227364Sadrian 146227364Sadrian/* 147227364Sadrian * Determine what the correct AC queue for the given frame 148227364Sadrian * should be. 149227364Sadrian * 150227364Sadrian * This code assumes that the TIDs map consistently to 151227364Sadrian * the underlying hardware (or software) ath_txq. 152227364Sadrian * Since the sender may try to set an AC which is 153227364Sadrian * arbitrary, non-QoS TIDs may end up being put on 154227364Sadrian * completely different ACs. There's no way to put a 155227364Sadrian * TID into multiple ath_txq's for scheduling, so 156227364Sadrian * for now we override the AC/TXQ selection and set 157227364Sadrian * non-QOS TID frames into the BE queue. 158227364Sadrian * 159227364Sadrian * This may be completely incorrect - specifically, 160227364Sadrian * some management frames may end up out of order 161227364Sadrian * compared to the QoS traffic they're controlling. 162227364Sadrian * I'll look into this later. 163227364Sadrian */ 164227364Sadrianstatic int 165227364Sadrianath_tx_getac(struct ath_softc *sc, const struct mbuf *m0) 166227364Sadrian{ 167227364Sadrian const struct ieee80211_frame *wh; 168227364Sadrian int pri = M_WME_GETAC(m0); 169227364Sadrian wh = mtod(m0, const struct ieee80211_frame *); 170227364Sadrian if (IEEE80211_QOS_HAS_SEQ(wh)) 171227364Sadrian return pri; 172227364Sadrian 173227364Sadrian return WME_AC_BE; 174227364Sadrian} 175227364Sadrian 176218065Sadrianvoid 177218065Sadrianath_txfrag_cleanup(struct ath_softc *sc, 178218065Sadrian ath_bufhead *frags, struct ieee80211_node *ni) 179218065Sadrian{ 180218065Sadrian struct ath_buf *bf, *next; 181218065Sadrian 182218065Sadrian ATH_TXBUF_LOCK_ASSERT(sc); 183218065Sadrian 184227344Sadrian TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) { 185218065Sadrian /* NB: bf assumed clean */ 186227344Sadrian TAILQ_REMOVE(frags, bf, bf_list); 187227344Sadrian TAILQ_INSERT_HEAD(&sc->sc_txbuf, bf, bf_list); 188218065Sadrian ieee80211_node_decref(ni); 189218065Sadrian } 190218065Sadrian} 191218065Sadrian 192218065Sadrian/* 193218065Sadrian * Setup xmit of a fragmented frame. Allocate a buffer 194218065Sadrian * for each frag and bump the node reference count to 195218065Sadrian * reflect the held reference to be setup by ath_tx_start. 196218065Sadrian */ 197218065Sadrianint 198218065Sadrianath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags, 199218065Sadrian struct mbuf *m0, struct ieee80211_node *ni) 200218065Sadrian{ 201218065Sadrian struct mbuf *m; 202218065Sadrian struct ath_buf *bf; 203218065Sadrian 204218065Sadrian ATH_TXBUF_LOCK(sc); 205218065Sadrian for (m = m0->m_nextpkt; m != NULL; m = m->m_nextpkt) { 206218065Sadrian bf = _ath_getbuf_locked(sc); 207218065Sadrian if (bf == NULL) { /* out of buffers, cleanup */ 208234009Sadrian device_printf(sc->sc_dev, "%s: no buffer?\n", 209234009Sadrian __func__); 210218065Sadrian ath_txfrag_cleanup(sc, frags, ni); 211218065Sadrian break; 212218065Sadrian } 213218065Sadrian ieee80211_node_incref(ni); 214227344Sadrian TAILQ_INSERT_TAIL(frags, bf, bf_list); 215218065Sadrian } 216218065Sadrian ATH_TXBUF_UNLOCK(sc); 217218065Sadrian 218227344Sadrian return !TAILQ_EMPTY(frags); 219218065Sadrian} 220218065Sadrian 221218065Sadrian/* 222218065Sadrian * Reclaim mbuf resources. For fragmented frames we 223218065Sadrian * need to claim each frag chained with m_nextpkt. 224218065Sadrian */ 225218065Sadrianvoid 226218065Sadrianath_freetx(struct mbuf *m) 227218065Sadrian{ 228218065Sadrian struct mbuf *next; 229218065Sadrian 230218065Sadrian do { 231218065Sadrian next = m->m_nextpkt; 232218065Sadrian m->m_nextpkt = NULL; 233218065Sadrian m_freem(m); 234218065Sadrian } while ((m = next) != NULL); 235218065Sadrian} 236218065Sadrian 237218065Sadrianstatic int 238218065Sadrianath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0) 239218065Sadrian{ 240218065Sadrian struct mbuf *m; 241218065Sadrian int error; 242218065Sadrian 243218065Sadrian /* 244218065Sadrian * Load the DMA map so any coalescing is done. This 245218065Sadrian * also calculates the number of descriptors we need. 246218065Sadrian */ 247218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 248218065Sadrian bf->bf_segs, &bf->bf_nseg, 249218065Sadrian BUS_DMA_NOWAIT); 250218065Sadrian if (error == EFBIG) { 251218065Sadrian /* XXX packet requires too many descriptors */ 252218065Sadrian bf->bf_nseg = ATH_TXDESC+1; 253218065Sadrian } else if (error != 0) { 254218065Sadrian sc->sc_stats.ast_tx_busdma++; 255218065Sadrian ath_freetx(m0); 256218065Sadrian return error; 257218065Sadrian } 258218065Sadrian /* 259218065Sadrian * Discard null packets and check for packets that 260218065Sadrian * require too many TX descriptors. We try to convert 261218065Sadrian * the latter to a cluster. 262218065Sadrian */ 263218065Sadrian if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ 264218065Sadrian sc->sc_stats.ast_tx_linear++; 265218065Sadrian m = m_collapse(m0, M_DONTWAIT, ATH_TXDESC); 266218065Sadrian if (m == NULL) { 267218065Sadrian ath_freetx(m0); 268218065Sadrian sc->sc_stats.ast_tx_nombuf++; 269218065Sadrian return ENOMEM; 270218065Sadrian } 271218065Sadrian m0 = m; 272218065Sadrian error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0, 273218065Sadrian bf->bf_segs, &bf->bf_nseg, 274218065Sadrian BUS_DMA_NOWAIT); 275218065Sadrian if (error != 0) { 276218065Sadrian sc->sc_stats.ast_tx_busdma++; 277218065Sadrian ath_freetx(m0); 278218065Sadrian return error; 279218065Sadrian } 280218065Sadrian KASSERT(bf->bf_nseg <= ATH_TXDESC, 281218065Sadrian ("too many segments after defrag; nseg %u", bf->bf_nseg)); 282218065Sadrian } else if (bf->bf_nseg == 0) { /* null packet, discard */ 283218065Sadrian sc->sc_stats.ast_tx_nodata++; 284218065Sadrian ath_freetx(m0); 285218065Sadrian return EIO; 286218065Sadrian } 287218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n", 288218065Sadrian __func__, m0, m0->m_pkthdr.len); 289218065Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 290218065Sadrian bf->bf_m = m0; 291218065Sadrian 292218065Sadrian return 0; 293218065Sadrian} 294218065Sadrian 295227360Sadrian/* 296227360Sadrian * Chain together segments+descriptors for a non-11n frame. 297227360Sadrian */ 298218065Sadrianstatic void 299227364Sadrianath_tx_chaindesclist(struct ath_softc *sc, struct ath_buf *bf) 300218065Sadrian{ 301218065Sadrian struct ath_hal *ah = sc->sc_ah; 302218065Sadrian struct ath_desc *ds, *ds0; 303218065Sadrian int i; 304218065Sadrian 305218065Sadrian /* 306218065Sadrian * Fillin the remainder of the descriptor info. 307218065Sadrian */ 308218065Sadrian ds0 = ds = bf->bf_desc; 309218065Sadrian for (i = 0; i < bf->bf_nseg; i++, ds++) { 310218065Sadrian ds->ds_data = bf->bf_segs[i].ds_addr; 311218065Sadrian if (i == bf->bf_nseg - 1) 312218065Sadrian ds->ds_link = 0; 313218065Sadrian else 314218065Sadrian ds->ds_link = bf->bf_daddr + sizeof(*ds) * (i + 1); 315218065Sadrian ath_hal_filltxdesc(ah, ds 316218065Sadrian , bf->bf_segs[i].ds_len /* segment length */ 317218065Sadrian , i == 0 /* first segment */ 318218065Sadrian , i == bf->bf_nseg - 1 /* last segment */ 319218065Sadrian , ds0 /* first descriptor */ 320218065Sadrian ); 321218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 322218065Sadrian "%s: %d: %08x %08x %08x %08x %08x %08x\n", 323218065Sadrian __func__, i, ds->ds_link, ds->ds_data, 324218065Sadrian ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1]); 325227360Sadrian bf->bf_lastds = ds; 326218065Sadrian } 327233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); 328218154Sadrian} 329218154Sadrian 330227364Sadrian/* 331227364Sadrian * Fill in the descriptor list for a aggregate subframe. 332227364Sadrian * 333227364Sadrian * The subframe is returned with the ds_link field in the last subframe 334227364Sadrian * pointing to 0. 335227364Sadrian */ 336218154Sadrianstatic void 337227364Sadrianath_tx_chaindesclist_subframe(struct ath_softc *sc, struct ath_buf *bf) 338218154Sadrian{ 339218154Sadrian struct ath_hal *ah = sc->sc_ah; 340227364Sadrian struct ath_desc *ds, *ds0; 341227364Sadrian int i; 342218154Sadrian 343227364Sadrian ds0 = ds = bf->bf_desc; 344218154Sadrian 345218065Sadrian /* 346227364Sadrian * There's no need to call ath_hal_setupfirsttxdesc here; 347227364Sadrian * That's only going to occur for the first frame in an aggregate. 348227364Sadrian */ 349227364Sadrian for (i = 0; i < bf->bf_nseg; i++, ds++) { 350227364Sadrian ds->ds_data = bf->bf_segs[i].ds_addr; 351227364Sadrian if (i == bf->bf_nseg - 1) 352227364Sadrian ds->ds_link = 0; 353227364Sadrian else 354227364Sadrian ds->ds_link = bf->bf_daddr + sizeof(*ds) * (i + 1); 355227364Sadrian 356227364Sadrian /* 357227364Sadrian * This performs the setup for an aggregate frame. 358227364Sadrian * This includes enabling the aggregate flags if needed. 359227364Sadrian */ 360227364Sadrian ath_hal_chaintxdesc(ah, ds, 361227364Sadrian bf->bf_state.bfs_pktlen, 362227364Sadrian bf->bf_state.bfs_hdrlen, 363227364Sadrian HAL_PKT_TYPE_AMPDU, /* forces aggregate bits to be set */ 364227364Sadrian bf->bf_state.bfs_keyix, 365227364Sadrian 0, /* cipher, calculated from keyix */ 366227364Sadrian bf->bf_state.bfs_ndelim, 367227364Sadrian bf->bf_segs[i].ds_len, /* segment length */ 368227364Sadrian i == 0, /* first segment */ 369233895Sadrian i == bf->bf_nseg - 1, /* last segment */ 370233895Sadrian bf->bf_next == NULL /* last sub-frame in aggr */ 371227364Sadrian ); 372227364Sadrian 373227364Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 374227364Sadrian "%s: %d: %08x %08x %08x %08x %08x %08x\n", 375227364Sadrian __func__, i, ds->ds_link, ds->ds_data, 376227364Sadrian ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1]); 377227364Sadrian bf->bf_lastds = ds; 378233990Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 379233990Sadrian BUS_DMASYNC_PREWRITE); 380227364Sadrian } 381227364Sadrian} 382227364Sadrian 383227364Sadrian/* 384227364Sadrian * Setup segments+descriptors for an 11n aggregate. 385227364Sadrian * bf_first is the first buffer in the aggregate. 386227364Sadrian * The descriptor list must already been linked together using 387227364Sadrian * bf->bf_next. 388227364Sadrian */ 389227364Sadrianstatic void 390227364Sadrianath_tx_setds_11n(struct ath_softc *sc, struct ath_buf *bf_first) 391227364Sadrian{ 392227364Sadrian struct ath_buf *bf, *bf_prev = NULL; 393227364Sadrian 394227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: nframes=%d, al=%d\n", 395227364Sadrian __func__, bf_first->bf_state.bfs_nframes, 396227364Sadrian bf_first->bf_state.bfs_al); 397227364Sadrian 398227364Sadrian /* 399227364Sadrian * Setup all descriptors of all subframes. 400227364Sadrian */ 401227364Sadrian bf = bf_first; 402227364Sadrian while (bf != NULL) { 403227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 404227364Sadrian "%s: bf=%p, nseg=%d, pktlen=%d, seqno=%d\n", 405227364Sadrian __func__, bf, bf->bf_nseg, bf->bf_state.bfs_pktlen, 406227364Sadrian SEQNO(bf->bf_state.bfs_seqno)); 407227364Sadrian 408227364Sadrian /* Sub-frame setup */ 409227364Sadrian ath_tx_chaindesclist_subframe(sc, bf); 410227364Sadrian 411227364Sadrian /* 412227364Sadrian * Link the last descriptor of the previous frame 413227364Sadrian * to the beginning descriptor of this frame. 414227364Sadrian */ 415227364Sadrian if (bf_prev != NULL) 416227364Sadrian bf_prev->bf_lastds->ds_link = bf->bf_daddr; 417227364Sadrian 418227364Sadrian /* Save a copy so we can link the next descriptor in */ 419227364Sadrian bf_prev = bf; 420227364Sadrian bf = bf->bf_next; 421227364Sadrian } 422227364Sadrian 423227364Sadrian /* 424227364Sadrian * Setup first descriptor of first frame. 425227364Sadrian * chaintxdesc() overwrites the descriptor entries; 426227364Sadrian * setupfirsttxdesc() merges in things. 427227364Sadrian * Otherwise various fields aren't set correctly (eg flags). 428227364Sadrian */ 429227364Sadrian ath_hal_setupfirsttxdesc(sc->sc_ah, 430227364Sadrian bf_first->bf_desc, 431227364Sadrian bf_first->bf_state.bfs_al, 432233966Sadrian bf_first->bf_state.bfs_txflags | HAL_TXDESC_INTREQ, 433227364Sadrian bf_first->bf_state.bfs_txpower, 434227364Sadrian bf_first->bf_state.bfs_txrate0, 435227364Sadrian bf_first->bf_state.bfs_try0, 436227364Sadrian bf_first->bf_state.bfs_txantenna, 437227364Sadrian bf_first->bf_state.bfs_ctsrate, 438227364Sadrian bf_first->bf_state.bfs_ctsduration); 439227364Sadrian 440227364Sadrian /* 441227364Sadrian * Setup the last descriptor in the list. 442227364Sadrian * bf_prev points to the last; bf is NULL here. 443227364Sadrian */ 444229949Sadrian ath_hal_setuplasttxdesc(sc->sc_ah, bf_prev->bf_desc, 445229949Sadrian bf_first->bf_desc); 446227364Sadrian 447227364Sadrian /* 448227364Sadrian * Set the first descriptor bf_lastds field to point to 449227364Sadrian * the last descriptor in the last subframe, that's where 450227364Sadrian * the status update will occur. 451227364Sadrian */ 452227364Sadrian bf_first->bf_lastds = bf_prev->bf_lastds; 453227364Sadrian 454227364Sadrian /* 455227364Sadrian * And bf_last in the first descriptor points to the end of 456227364Sadrian * the aggregate list. 457227364Sadrian */ 458227364Sadrian bf_first->bf_last = bf_prev; 459227364Sadrian 460227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: end\n", __func__); 461227364Sadrian} 462227364Sadrian 463227364Sadrianstatic void 464227364Sadrianath_tx_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq, 465227364Sadrian struct ath_buf *bf) 466227364Sadrian{ 467227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 468227364Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 469227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 470227364Sadrian if (txq->axq_link != NULL) { 471227364Sadrian struct ath_buf *last = ATH_TXQ_LAST(txq, axq_q_s); 472227364Sadrian struct ieee80211_frame *wh; 473227364Sadrian 474227364Sadrian /* mark previous frame */ 475227364Sadrian wh = mtod(last->bf_m, struct ieee80211_frame *); 476227364Sadrian wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; 477227364Sadrian bus_dmamap_sync(sc->sc_dmat, last->bf_dmamap, 478227364Sadrian BUS_DMASYNC_PREWRITE); 479227364Sadrian 480227364Sadrian /* link descriptor */ 481227364Sadrian *txq->axq_link = bf->bf_daddr; 482227364Sadrian } 483227364Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 484227364Sadrian txq->axq_link = &bf->bf_lastds->ds_link; 485227364Sadrian} 486227364Sadrian 487227364Sadrian/* 488227364Sadrian * Hand-off packet to a hardware queue. 489227364Sadrian */ 490227364Sadrianstatic void 491229949Sadrianath_tx_handoff_hw(struct ath_softc *sc, struct ath_txq *txq, 492229949Sadrian struct ath_buf *bf) 493227364Sadrian{ 494227364Sadrian struct ath_hal *ah = sc->sc_ah; 495227364Sadrian 496227364Sadrian /* 497218065Sadrian * Insert the frame on the outbound list and pass it on 498218065Sadrian * to the hardware. Multicast frames buffered for power 499218065Sadrian * save stations and transmit from the CAB queue are stored 500218065Sadrian * on a s/w only queue and loaded on to the CAB queue in 501218065Sadrian * the SWBA handler since frames only go out on DTIM and 502218065Sadrian * to avoid possible races. 503218065Sadrian */ 504227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 505218065Sadrian KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0, 506227364Sadrian ("%s: busy status 0x%x", __func__, bf->bf_flags)); 507227364Sadrian KASSERT(txq->axq_qnum != ATH_TXQ_SWQ, 508227364Sadrian ("ath_tx_handoff_hw called for mcast queue")); 509227364Sadrian 510227651Sadrian#if 0 511227651Sadrian /* 512227651Sadrian * This causes a LOR. Find out where the PCU lock is being 513227651Sadrian * held whilst the TXQ lock is grabbed - that shouldn't 514227651Sadrian * be occuring. 515227651Sadrian */ 516227651Sadrian ATH_PCU_LOCK(sc); 517227651Sadrian if (sc->sc_inreset_cnt) { 518227651Sadrian ATH_PCU_UNLOCK(sc); 519227651Sadrian DPRINTF(sc, ATH_DEBUG_RESET, 520227651Sadrian "%s: called with sc_in_reset != 0\n", 521227651Sadrian __func__); 522227651Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 523227651Sadrian "%s: queued: TXDP[%u] = %p (%p) depth %d\n", 524227651Sadrian __func__, txq->axq_qnum, 525227651Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 526227651Sadrian txq->axq_depth); 527227651Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 528227651Sadrian if (bf->bf_state.bfs_aggr) 529227651Sadrian txq->axq_aggr_depth++; 530227651Sadrian /* 531227651Sadrian * There's no need to update axq_link; the hardware 532227651Sadrian * is in reset and once the reset is complete, any 533227651Sadrian * non-empty queues will simply have DMA restarted. 534227651Sadrian */ 535227651Sadrian return; 536227651Sadrian } 537227651Sadrian ATH_PCU_UNLOCK(sc); 538227651Sadrian#endif 539227651Sadrian 540227364Sadrian /* For now, so not to generate whitespace diffs */ 541227364Sadrian if (1) { 542218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 543218065Sadrian int qbusy; 544218065Sadrian 545218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 546218065Sadrian qbusy = ath_hal_txqenabled(ah, txq->axq_qnum); 547218065Sadrian if (txq->axq_link == NULL) { 548218065Sadrian /* 549218065Sadrian * Be careful writing the address to TXDP. If 550218065Sadrian * the tx q is enabled then this write will be 551218065Sadrian * ignored. Normally this is not an issue but 552218065Sadrian * when tdma is in use and the q is beacon gated 553218065Sadrian * this race can occur. If the q is busy then 554218065Sadrian * defer the work to later--either when another 555218065Sadrian * packet comes along or when we prepare a beacon 556218065Sadrian * frame at SWBA. 557218065Sadrian */ 558218065Sadrian if (!qbusy) { 559229949Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 560229949Sadrian bf->bf_daddr); 561218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 562218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 563218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 564218065Sadrian __func__, txq->axq_qnum, 565218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 566218065Sadrian txq->axq_depth); 567218065Sadrian } else { 568218065Sadrian txq->axq_flags |= ATH_TXQ_PUTPENDING; 569218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 570218065Sadrian "%s: Q%u busy, defer enable\n", __func__, 571218065Sadrian txq->axq_qnum); 572218065Sadrian } 573218065Sadrian } else { 574218065Sadrian *txq->axq_link = bf->bf_daddr; 575218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 576218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 577218065Sadrian txq->axq_qnum, txq->axq_link, 578229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 579229949Sadrian txq->axq_depth); 580218065Sadrian if ((txq->axq_flags & ATH_TXQ_PUTPENDING) && !qbusy) { 581218065Sadrian /* 582218065Sadrian * The q was busy when we previously tried 583218065Sadrian * to write the address of the first buffer 584218065Sadrian * in the chain. Since it's not busy now 585218065Sadrian * handle this chore. We are certain the 586218065Sadrian * buffer at the front is the right one since 587218065Sadrian * axq_link is NULL only when the buffer list 588218065Sadrian * is/was empty. 589218065Sadrian */ 590218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, 591227344Sadrian TAILQ_FIRST(&txq->axq_q)->bf_daddr); 592218065Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 593218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA | ATH_DEBUG_XMIT, 594218065Sadrian "%s: Q%u restarted\n", __func__, 595218065Sadrian txq->axq_qnum); 596218065Sadrian } 597218065Sadrian } 598218065Sadrian#else 599218065Sadrian ATH_TXQ_INSERT_TAIL(txq, bf, bf_list); 600218065Sadrian if (txq->axq_link == NULL) { 601218065Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 602218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 603218065Sadrian "%s: TXDP[%u] = %p (%p) depth %d\n", 604218065Sadrian __func__, txq->axq_qnum, 605218065Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 606218065Sadrian txq->axq_depth); 607218065Sadrian } else { 608218065Sadrian *txq->axq_link = bf->bf_daddr; 609218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 610218065Sadrian "%s: link[%u](%p)=%p (%p) depth %d\n", __func__, 611218065Sadrian txq->axq_qnum, txq->axq_link, 612229949Sadrian (caddr_t)bf->bf_daddr, bf->bf_desc, 613229949Sadrian txq->axq_depth); 614218065Sadrian } 615218065Sadrian#endif /* IEEE80211_SUPPORT_TDMA */ 616227360Sadrian if (bf->bf_state.bfs_aggr) 617227360Sadrian txq->axq_aggr_depth++; 618227360Sadrian txq->axq_link = &bf->bf_lastds->ds_link; 619218065Sadrian ath_hal_txstart(ah, txq->axq_qnum); 620227364Sadrian } 621227364Sadrian} 622218065Sadrian 623227364Sadrian/* 624227364Sadrian * Restart TX DMA for the given TXQ. 625227364Sadrian * 626227364Sadrian * This must be called whether the queue is empty or not. 627227364Sadrian */ 628227364Sadrianvoid 629227364Sadrianath_txq_restart_dma(struct ath_softc *sc, struct ath_txq *txq) 630227364Sadrian{ 631227364Sadrian struct ath_hal *ah = sc->sc_ah; 632232707Sadrian struct ath_buf *bf, *bf_last; 633218065Sadrian 634227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 635227364Sadrian 636227364Sadrian /* This is always going to be cleared, empty or not */ 637227364Sadrian txq->axq_flags &= ~ATH_TXQ_PUTPENDING; 638227364Sadrian 639232707Sadrian /* XXX make this ATH_TXQ_FIRST */ 640227364Sadrian bf = TAILQ_FIRST(&txq->axq_q); 641232707Sadrian bf_last = ATH_TXQ_LAST(txq, axq_q_s); 642232707Sadrian 643227364Sadrian if (bf == NULL) 644227364Sadrian return; 645227364Sadrian 646227364Sadrian ath_hal_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); 647232707Sadrian txq->axq_link = &bf_last->bf_lastds->ds_link; 648227364Sadrian ath_hal_txstart(ah, txq->axq_qnum); 649218065Sadrian} 650218065Sadrian 651227364Sadrian/* 652227364Sadrian * Hand off a packet to the hardware (or mcast queue.) 653227364Sadrian * 654227364Sadrian * The relevant hardware txq should be locked. 655227364Sadrian */ 656227364Sadrianstatic void 657227364Sadrianath_tx_handoff(struct ath_softc *sc, struct ath_txq *txq, struct ath_buf *bf) 658227364Sadrian{ 659227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 660227364Sadrian 661227364Sadrian if (txq->axq_qnum == ATH_TXQ_SWQ) 662227364Sadrian ath_tx_handoff_mcast(sc, txq, bf); 663227364Sadrian else 664227364Sadrian ath_tx_handoff_hw(sc, txq, bf); 665227364Sadrian} 666227364Sadrian 667218154Sadrianstatic int 668218154Sadrianath_tx_tag_crypto(struct ath_softc *sc, struct ieee80211_node *ni, 669229949Sadrian struct mbuf *m0, int iswep, int isfrag, int *hdrlen, int *pktlen, 670229949Sadrian int *keyix) 671218154Sadrian{ 672233330Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, 673233330Sadrian "%s: hdrlen=%d, pktlen=%d, isfrag=%d, iswep=%d, m0=%p\n", 674233330Sadrian __func__, 675233330Sadrian *hdrlen, 676233330Sadrian *pktlen, 677233330Sadrian isfrag, 678233330Sadrian iswep, 679233330Sadrian m0); 680233330Sadrian 681218154Sadrian if (iswep) { 682218154Sadrian const struct ieee80211_cipher *cip; 683218154Sadrian struct ieee80211_key *k; 684218154Sadrian 685218154Sadrian /* 686218154Sadrian * Construct the 802.11 header+trailer for an encrypted 687218154Sadrian * frame. The only reason this can fail is because of an 688218154Sadrian * unknown or unsupported cipher/key type. 689218154Sadrian */ 690218154Sadrian k = ieee80211_crypto_encap(ni, m0); 691218154Sadrian if (k == NULL) { 692218154Sadrian /* 693218154Sadrian * This can happen when the key is yanked after the 694218154Sadrian * frame was queued. Just discard the frame; the 695218154Sadrian * 802.11 layer counts failures and provides 696218154Sadrian * debugging/diagnostics. 697218154Sadrian */ 698229949Sadrian return (0); 699218154Sadrian } 700218154Sadrian /* 701218154Sadrian * Adjust the packet + header lengths for the crypto 702218154Sadrian * additions and calculate the h/w key index. When 703218154Sadrian * a s/w mic is done the frame will have had any mic 704218154Sadrian * added to it prior to entry so m0->m_pkthdr.len will 705218154Sadrian * account for it. Otherwise we need to add it to the 706218154Sadrian * packet length. 707218154Sadrian */ 708218154Sadrian cip = k->wk_cipher; 709218154Sadrian (*hdrlen) += cip->ic_header; 710218154Sadrian (*pktlen) += cip->ic_header + cip->ic_trailer; 711218154Sadrian /* NB: frags always have any TKIP MIC done in s/w */ 712218154Sadrian if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && !isfrag) 713218154Sadrian (*pktlen) += cip->ic_miclen; 714218154Sadrian (*keyix) = k->wk_keyix; 715218154Sadrian } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { 716218154Sadrian /* 717218154Sadrian * Use station key cache slot, if assigned. 718218154Sadrian */ 719218154Sadrian (*keyix) = ni->ni_ucastkey.wk_keyix; 720218154Sadrian if ((*keyix) == IEEE80211_KEYIX_NONE) 721218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 722218154Sadrian } else 723218154Sadrian (*keyix) = HAL_TXKEYIX_INVALID; 724218154Sadrian 725229949Sadrian return (1); 726218154Sadrian} 727218154Sadrian 728233989Sadrian/* 729233989Sadrian * Calculate whether interoperability protection is required for 730233989Sadrian * this frame. 731233989Sadrian * 732233989Sadrian * This requires the rate control information be filled in, 733233989Sadrian * as the protection requirement depends upon the current 734233989Sadrian * operating mode / PHY. 735233989Sadrian */ 736233989Sadrianstatic void 737233989Sadrianath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf) 738233989Sadrian{ 739233989Sadrian struct ieee80211_frame *wh; 740233989Sadrian uint8_t rix; 741233989Sadrian uint16_t flags; 742233989Sadrian int shortPreamble; 743233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 744233989Sadrian struct ifnet *ifp = sc->sc_ifp; 745233989Sadrian struct ieee80211com *ic = ifp->if_l2com; 746233989Sadrian 747233989Sadrian flags = bf->bf_state.bfs_txflags; 748233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 749233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 750233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 751233989Sadrian 752233989Sadrian /* 753233989Sadrian * If 802.11g protection is enabled, determine whether 754233989Sadrian * to use RTS/CTS or just CTS. Note that this is only 755233989Sadrian * done for OFDM unicast frames. 756233989Sadrian */ 757233989Sadrian if ((ic->ic_flags & IEEE80211_F_USEPROT) && 758233989Sadrian rt->info[rix].phy == IEEE80211_T_OFDM && 759233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 760233989Sadrian bf->bf_state.bfs_doprot = 1; 761233989Sadrian /* XXX fragments must use CCK rates w/ protection */ 762233989Sadrian if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) { 763233989Sadrian flags |= HAL_TXDESC_RTSENA; 764233989Sadrian } else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) { 765233989Sadrian flags |= HAL_TXDESC_CTSENA; 766233989Sadrian } 767233989Sadrian /* 768233989Sadrian * For frags it would be desirable to use the 769233989Sadrian * highest CCK rate for RTS/CTS. But stations 770233989Sadrian * farther away may detect it at a lower CCK rate 771233989Sadrian * so use the configured protection rate instead 772233989Sadrian * (for now). 773233989Sadrian */ 774233989Sadrian sc->sc_stats.ast_tx_protect++; 775233989Sadrian } 776233989Sadrian 777233989Sadrian /* 778233989Sadrian * If 11n protection is enabled and it's a HT frame, 779233989Sadrian * enable RTS. 780233989Sadrian * 781233989Sadrian * XXX ic_htprotmode or ic_curhtprotmode? 782233989Sadrian * XXX should it_htprotmode only matter if ic_curhtprotmode 783233989Sadrian * XXX indicates it's not a HT pure environment? 784233989Sadrian */ 785233989Sadrian if ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && 786233989Sadrian rt->info[rix].phy == IEEE80211_T_HT && 787233989Sadrian (flags & HAL_TXDESC_NOACK) == 0) { 788233989Sadrian flags |= HAL_TXDESC_RTSENA; 789233989Sadrian sc->sc_stats.ast_tx_htprotect++; 790233989Sadrian } 791233989Sadrian bf->bf_state.bfs_txflags = flags; 792233989Sadrian} 793233989Sadrian 794233989Sadrian/* 795233989Sadrian * Update the frame duration given the currently selected rate. 796233989Sadrian * 797233989Sadrian * This also updates the frame duration value, so it will require 798233989Sadrian * a DMA flush. 799233989Sadrian */ 800233989Sadrianstatic void 801233989Sadrianath_tx_calc_duration(struct ath_softc *sc, struct ath_buf *bf) 802233989Sadrian{ 803233989Sadrian struct ieee80211_frame *wh; 804233989Sadrian uint8_t rix; 805233989Sadrian uint16_t flags; 806233989Sadrian int shortPreamble; 807233989Sadrian struct ath_hal *ah = sc->sc_ah; 808233989Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 809233989Sadrian int isfrag = bf->bf_m->m_flags & M_FRAG; 810233989Sadrian 811233989Sadrian flags = bf->bf_state.bfs_txflags; 812233989Sadrian rix = bf->bf_state.bfs_rc[0].rix; 813233989Sadrian shortPreamble = bf->bf_state.bfs_shpream; 814233989Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 815233989Sadrian 816233989Sadrian /* 817233989Sadrian * Calculate duration. This logically belongs in the 802.11 818233989Sadrian * layer but it lacks sufficient information to calculate it. 819233989Sadrian */ 820233989Sadrian if ((flags & HAL_TXDESC_NOACK) == 0 && 821233989Sadrian (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) { 822233989Sadrian u_int16_t dur; 823233989Sadrian if (shortPreamble) 824233989Sadrian dur = rt->info[rix].spAckDuration; 825233989Sadrian else 826233989Sadrian dur = rt->info[rix].lpAckDuration; 827233989Sadrian if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { 828233989Sadrian dur += dur; /* additional SIFS+ACK */ 829233989Sadrian KASSERT(bf->bf_m->m_nextpkt != NULL, ("no fragment")); 830233989Sadrian /* 831233989Sadrian * Include the size of next fragment so NAV is 832233989Sadrian * updated properly. The last fragment uses only 833233989Sadrian * the ACK duration 834233989Sadrian */ 835233989Sadrian dur += ath_hal_computetxtime(ah, rt, 836233989Sadrian bf->bf_m->m_nextpkt->m_pkthdr.len, 837233989Sadrian rix, shortPreamble); 838233989Sadrian } 839233989Sadrian if (isfrag) { 840233989Sadrian /* 841233989Sadrian * Force hardware to use computed duration for next 842233989Sadrian * fragment by disabling multi-rate retry which updates 843233989Sadrian * duration based on the multi-rate duration table. 844233989Sadrian */ 845233989Sadrian bf->bf_state.bfs_ismrr = 0; 846233989Sadrian bf->bf_state.bfs_try0 = ATH_TXMGTTRY; 847233989Sadrian /* XXX update bfs_rc[0].try? */ 848233989Sadrian } 849233989Sadrian 850233989Sadrian /* Update the duration field itself */ 851233989Sadrian *(u_int16_t *)wh->i_dur = htole16(dur); 852233989Sadrian } 853233989Sadrian} 854233989Sadrian 855218932Sadrianstatic uint8_t 856218932Sadrianath_tx_get_rtscts_rate(struct ath_hal *ah, const HAL_RATE_TABLE *rt, 857227364Sadrian int cix, int shortPreamble) 858218157Sadrian{ 859218932Sadrian uint8_t ctsrate; 860218932Sadrian 861218157Sadrian /* 862218157Sadrian * CTS transmit rate is derived from the transmit rate 863218157Sadrian * by looking in the h/w rate table. We must also factor 864218157Sadrian * in whether or not a short preamble is to be used. 865218157Sadrian */ 866218157Sadrian /* NB: cix is set above where RTS/CTS is enabled */ 867218157Sadrian KASSERT(cix != 0xff, ("cix not setup")); 868218932Sadrian ctsrate = rt->info[cix].rateCode; 869218932Sadrian 870218932Sadrian /* XXX this should only matter for legacy rates */ 871218932Sadrian if (shortPreamble) 872218932Sadrian ctsrate |= rt->info[cix].shortPreamble; 873218932Sadrian 874229949Sadrian return (ctsrate); 875218932Sadrian} 876218932Sadrian 877218932Sadrian/* 878218932Sadrian * Calculate the RTS/CTS duration for legacy frames. 879218932Sadrian */ 880218932Sadrianstatic int 881218932Sadrianath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix, 882218932Sadrian int shortPreamble, int pktlen, const HAL_RATE_TABLE *rt, 883218932Sadrian int flags) 884218932Sadrian{ 885218932Sadrian int ctsduration = 0; 886218932Sadrian 887218932Sadrian /* This mustn't be called for HT modes */ 888218932Sadrian if (rt->info[cix].phy == IEEE80211_T_HT) { 889218932Sadrian printf("%s: HT rate where it shouldn't be (0x%x)\n", 890218932Sadrian __func__, rt->info[cix].rateCode); 891229949Sadrian return (-1); 892218932Sadrian } 893218932Sadrian 894218157Sadrian /* 895218157Sadrian * Compute the transmit duration based on the frame 896218157Sadrian * size and the size of an ACK frame. We call into the 897218157Sadrian * HAL to do the computation since it depends on the 898218157Sadrian * characteristics of the actual PHY being used. 899218157Sadrian * 900218157Sadrian * NB: CTS is assumed the same size as an ACK so we can 901218157Sadrian * use the precalculated ACK durations. 902218157Sadrian */ 903218157Sadrian if (shortPreamble) { 904218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 905218932Sadrian ctsduration += rt->info[cix].spAckDuration; 906218932Sadrian ctsduration += ath_hal_computetxtime(ah, 907218157Sadrian rt, pktlen, rix, AH_TRUE); 908218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 909218932Sadrian ctsduration += rt->info[rix].spAckDuration; 910218157Sadrian } else { 911218157Sadrian if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */ 912218932Sadrian ctsduration += rt->info[cix].lpAckDuration; 913218932Sadrian ctsduration += ath_hal_computetxtime(ah, 914218157Sadrian rt, pktlen, rix, AH_FALSE); 915218157Sadrian if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */ 916218932Sadrian ctsduration += rt->info[rix].lpAckDuration; 917218157Sadrian } 918218932Sadrian 919229949Sadrian return (ctsduration); 920218157Sadrian} 921218157Sadrian 922227364Sadrian/* 923227364Sadrian * Update the given ath_buf with updated rts/cts setup and duration 924227364Sadrian * values. 925227364Sadrian * 926227364Sadrian * To support rate lookups for each software retry, the rts/cts rate 927227364Sadrian * and cts duration must be re-calculated. 928227364Sadrian * 929227364Sadrian * This function assumes the RTS/CTS flags have been set as needed; 930227364Sadrian * mrr has been disabled; and the rate control lookup has been done. 931227364Sadrian * 932227364Sadrian * XXX TODO: MRR need only be disabled for the pre-11n NICs. 933227364Sadrian * XXX The 11n NICs support per-rate RTS/CTS configuration. 934227364Sadrian */ 935227364Sadrianstatic void 936227364Sadrianath_tx_set_rtscts(struct ath_softc *sc, struct ath_buf *bf) 937218065Sadrian{ 938227364Sadrian uint16_t ctsduration = 0; 939227364Sadrian uint8_t ctsrate = 0; 940227364Sadrian uint8_t rix = bf->bf_state.bfs_rc[0].rix; 941227364Sadrian uint8_t cix = 0; 942227364Sadrian const HAL_RATE_TABLE *rt = sc->sc_currates; 943227364Sadrian 944227364Sadrian /* 945227364Sadrian * No RTS/CTS enabled? Don't bother. 946227364Sadrian */ 947233966Sadrian if ((bf->bf_state.bfs_txflags & 948227364Sadrian (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) == 0) { 949227364Sadrian /* XXX is this really needed? */ 950227364Sadrian bf->bf_state.bfs_ctsrate = 0; 951227364Sadrian bf->bf_state.bfs_ctsduration = 0; 952227364Sadrian return; 953227364Sadrian } 954227364Sadrian 955227364Sadrian /* 956227364Sadrian * If protection is enabled, use the protection rix control 957227364Sadrian * rate. Otherwise use the rate0 control rate. 958227364Sadrian */ 959227364Sadrian if (bf->bf_state.bfs_doprot) 960227364Sadrian rix = sc->sc_protrix; 961227364Sadrian else 962227364Sadrian rix = bf->bf_state.bfs_rc[0].rix; 963227364Sadrian 964227364Sadrian /* 965227364Sadrian * If the raw path has hard-coded ctsrate0 to something, 966227364Sadrian * use it. 967227364Sadrian */ 968227364Sadrian if (bf->bf_state.bfs_ctsrate0 != 0) 969227364Sadrian cix = ath_tx_findrix(sc, bf->bf_state.bfs_ctsrate0); 970227364Sadrian else 971227364Sadrian /* Control rate from above */ 972227364Sadrian cix = rt->info[rix].controlRate; 973227364Sadrian 974227364Sadrian /* Calculate the rtscts rate for the given cix */ 975227364Sadrian ctsrate = ath_tx_get_rtscts_rate(sc->sc_ah, rt, cix, 976227364Sadrian bf->bf_state.bfs_shpream); 977227364Sadrian 978227364Sadrian /* The 11n chipsets do ctsduration calculations for you */ 979227364Sadrian if (! ath_tx_is_11n(sc)) 980227364Sadrian ctsduration = ath_tx_calc_ctsduration(sc->sc_ah, rix, cix, 981227364Sadrian bf->bf_state.bfs_shpream, bf->bf_state.bfs_pktlen, 982233966Sadrian rt, bf->bf_state.bfs_txflags); 983227364Sadrian 984227364Sadrian /* Squirrel away in ath_buf */ 985227364Sadrian bf->bf_state.bfs_ctsrate = ctsrate; 986227364Sadrian bf->bf_state.bfs_ctsduration = ctsduration; 987227364Sadrian 988227364Sadrian /* 989227364Sadrian * Must disable multi-rate retry when using RTS/CTS. 990227364Sadrian * XXX TODO: only for pre-11n NICs. 991227364Sadrian */ 992227364Sadrian bf->bf_state.bfs_ismrr = 0; 993227364Sadrian bf->bf_state.bfs_try0 = 994227364Sadrian bf->bf_state.bfs_rc[0].tries = ATH_TXMGTTRY; /* XXX ew */ 995227364Sadrian} 996227364Sadrian 997227364Sadrian/* 998227364Sadrian * Setup the descriptor chain for a normal or fast-frame 999227364Sadrian * frame. 1000227364Sadrian */ 1001227364Sadrianstatic void 1002227364Sadrianath_tx_setds(struct ath_softc *sc, struct ath_buf *bf) 1003227364Sadrian{ 1004227364Sadrian struct ath_desc *ds = bf->bf_desc; 1005227364Sadrian struct ath_hal *ah = sc->sc_ah; 1006227364Sadrian 1007227364Sadrian ath_hal_setuptxdesc(ah, ds 1008227364Sadrian , bf->bf_state.bfs_pktlen /* packet length */ 1009227364Sadrian , bf->bf_state.bfs_hdrlen /* header length */ 1010227364Sadrian , bf->bf_state.bfs_atype /* Atheros packet type */ 1011227364Sadrian , bf->bf_state.bfs_txpower /* txpower */ 1012227364Sadrian , bf->bf_state.bfs_txrate0 1013227364Sadrian , bf->bf_state.bfs_try0 /* series 0 rate/tries */ 1014227364Sadrian , bf->bf_state.bfs_keyix /* key cache index */ 1015227364Sadrian , bf->bf_state.bfs_txantenna /* antenna mode */ 1016233966Sadrian , bf->bf_state.bfs_txflags /* flags */ 1017227364Sadrian , bf->bf_state.bfs_ctsrate /* rts/cts rate */ 1018227364Sadrian , bf->bf_state.bfs_ctsduration /* rts/cts duration */ 1019227364Sadrian ); 1020227364Sadrian 1021227364Sadrian /* 1022227364Sadrian * This will be overriden when the descriptor chain is written. 1023227364Sadrian */ 1024227364Sadrian bf->bf_lastds = ds; 1025227364Sadrian bf->bf_last = bf; 1026227364Sadrian 1027227364Sadrian /* XXX TODO: Setup descriptor chain */ 1028227364Sadrian} 1029227364Sadrian 1030227364Sadrian/* 1031227364Sadrian * Do a rate lookup. 1032227364Sadrian * 1033227364Sadrian * This performs a rate lookup for the given ath_buf only if it's required. 1034227364Sadrian * Non-data frames and raw frames don't require it. 1035227364Sadrian * 1036227364Sadrian * This populates the primary and MRR entries; MRR values are 1037227364Sadrian * then disabled later on if something requires it (eg RTS/CTS on 1038227364Sadrian * pre-11n chipsets. 1039227364Sadrian * 1040227364Sadrian * This needs to be done before the RTS/CTS fields are calculated 1041227364Sadrian * as they may depend upon the rate chosen. 1042227364Sadrian */ 1043227364Sadrianstatic void 1044227364Sadrianath_tx_do_ratelookup(struct ath_softc *sc, struct ath_buf *bf) 1045227364Sadrian{ 1046227364Sadrian uint8_t rate, rix; 1047227364Sadrian int try0; 1048227364Sadrian 1049227364Sadrian if (! bf->bf_state.bfs_doratelookup) 1050227364Sadrian return; 1051227364Sadrian 1052227364Sadrian /* Get rid of any previous state */ 1053227364Sadrian bzero(bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1054227364Sadrian 1055227364Sadrian ATH_NODE_LOCK(ATH_NODE(bf->bf_node)); 1056227364Sadrian ath_rate_findrate(sc, ATH_NODE(bf->bf_node), bf->bf_state.bfs_shpream, 1057227364Sadrian bf->bf_state.bfs_pktlen, &rix, &try0, &rate); 1058227364Sadrian 1059227364Sadrian /* In case MRR is disabled, make sure rc[0] is setup correctly */ 1060227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1061227364Sadrian bf->bf_state.bfs_rc[0].ratecode = rate; 1062227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1063227364Sadrian 1064227364Sadrian if (bf->bf_state.bfs_ismrr && try0 != ATH_TXMAXTRY) 1065227364Sadrian ath_rate_getxtxrates(sc, ATH_NODE(bf->bf_node), rix, 1066227364Sadrian bf->bf_state.bfs_rc); 1067227364Sadrian ATH_NODE_UNLOCK(ATH_NODE(bf->bf_node)); 1068227364Sadrian 1069227364Sadrian sc->sc_txrix = rix; /* for LED blinking */ 1070227364Sadrian sc->sc_lastdatarix = rix; /* for fast frames */ 1071227364Sadrian bf->bf_state.bfs_try0 = try0; 1072227364Sadrian bf->bf_state.bfs_txrate0 = rate; 1073227364Sadrian} 1074227364Sadrian 1075227364Sadrian/* 1076227364Sadrian * Set the rate control fields in the given descriptor based on 1077227364Sadrian * the bf_state fields and node state. 1078227364Sadrian * 1079227364Sadrian * The bfs fields should already be set with the relevant rate 1080227364Sadrian * control information, including whether MRR is to be enabled. 1081227364Sadrian * 1082227364Sadrian * Since the FreeBSD HAL currently sets up the first TX rate 1083227364Sadrian * in ath_hal_setuptxdesc(), this will setup the MRR 1084227364Sadrian * conditionally for the pre-11n chips, and call ath_buf_set_rate 1085227364Sadrian * unconditionally for 11n chips. These require the 11n rate 1086227364Sadrian * scenario to be set if MCS rates are enabled, so it's easier 1087227364Sadrian * to just always call it. The caller can then only set rates 2, 3 1088227364Sadrian * and 4 if multi-rate retry is needed. 1089227364Sadrian */ 1090227364Sadrianstatic void 1091227364Sadrianath_tx_set_ratectrl(struct ath_softc *sc, struct ieee80211_node *ni, 1092227364Sadrian struct ath_buf *bf) 1093227364Sadrian{ 1094227364Sadrian struct ath_rc_series *rc = bf->bf_state.bfs_rc; 1095227364Sadrian 1096227364Sadrian /* If mrr is disabled, blank tries 1, 2, 3 */ 1097227364Sadrian if (! bf->bf_state.bfs_ismrr) 1098227364Sadrian rc[1].tries = rc[2].tries = rc[3].tries = 0; 1099227364Sadrian 1100227364Sadrian /* 1101227364Sadrian * Always call - that way a retried descriptor will 1102227364Sadrian * have the MRR fields overwritten. 1103227364Sadrian * 1104227364Sadrian * XXX TODO: see if this is really needed - setting up 1105227364Sadrian * the first descriptor should set the MRR fields to 0 1106227364Sadrian * for us anyway. 1107227364Sadrian */ 1108227364Sadrian if (ath_tx_is_11n(sc)) { 1109227364Sadrian ath_buf_set_rate(sc, ni, bf); 1110227364Sadrian } else { 1111227364Sadrian ath_hal_setupxtxdesc(sc->sc_ah, bf->bf_desc 1112227364Sadrian , rc[1].ratecode, rc[1].tries 1113227364Sadrian , rc[2].ratecode, rc[2].tries 1114227364Sadrian , rc[3].ratecode, rc[3].tries 1115227364Sadrian ); 1116227364Sadrian } 1117227364Sadrian} 1118227364Sadrian 1119227364Sadrian/* 1120227364Sadrian * Transmit the given frame to the hardware. 1121227364Sadrian * 1122227364Sadrian * The frame must already be setup; rate control must already have 1123227364Sadrian * been done. 1124227364Sadrian * 1125227364Sadrian * XXX since the TXQ lock is being held here (and I dislike holding 1126227364Sadrian * it for this long when not doing software aggregation), later on 1127227364Sadrian * break this function into "setup_normal" and "xmit_normal". The 1128227364Sadrian * lock only needs to be held for the ath_tx_handoff call. 1129227364Sadrian */ 1130227364Sadrianstatic void 1131227364Sadrianath_tx_xmit_normal(struct ath_softc *sc, struct ath_txq *txq, 1132227364Sadrian struct ath_buf *bf) 1133227364Sadrian{ 1134227364Sadrian 1135227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 1136227364Sadrian 1137227364Sadrian /* Setup the descriptor before handoff */ 1138227364Sadrian ath_tx_do_ratelookup(sc, bf); 1139233989Sadrian ath_tx_calc_duration(sc, bf); 1140233989Sadrian ath_tx_calc_protection(sc, bf); 1141233989Sadrian ath_tx_set_rtscts(sc, bf); 1142227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 1143227364Sadrian ath_tx_setds(sc, bf); 1144227364Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 1145227364Sadrian ath_tx_chaindesclist(sc, bf); 1146227364Sadrian 1147227364Sadrian /* Hand off to hardware */ 1148227364Sadrian ath_tx_handoff(sc, txq, bf); 1149227364Sadrian} 1150227364Sadrian 1151227364Sadrian 1152227364Sadrian 1153227364Sadrianstatic int 1154227364Sadrianath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni, 1155234009Sadrian struct ath_buf *bf, struct mbuf *m0, struct ath_txq *txq) 1156227364Sadrian{ 1157218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1158218065Sadrian struct ath_hal *ah = sc->sc_ah; 1159218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1160218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1161218065Sadrian const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; 1162218065Sadrian int error, iswep, ismcast, isfrag, ismrr; 1163227364Sadrian int keyix, hdrlen, pktlen, try0 = 0; 1164227364Sadrian u_int8_t rix = 0, txrate = 0; 1165218065Sadrian struct ath_desc *ds; 1166218065Sadrian struct ieee80211_frame *wh; 1167227364Sadrian u_int subtype, flags; 1168218065Sadrian HAL_PKT_TYPE atype; 1169218065Sadrian const HAL_RATE_TABLE *rt; 1170218065Sadrian HAL_BOOL shortPreamble; 1171218065Sadrian struct ath_node *an; 1172218065Sadrian u_int pri; 1173218065Sadrian 1174218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1175218065Sadrian iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; 1176218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1177218065Sadrian isfrag = m0->m_flags & M_FRAG; 1178218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1179218065Sadrian /* 1180218065Sadrian * Packet length must not include any 1181218065Sadrian * pad bytes; deduct them here. 1182218065Sadrian */ 1183218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3); 1184218065Sadrian 1185218154Sadrian /* Handle encryption twiddling if needed */ 1186227364Sadrian if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen, 1187227364Sadrian &pktlen, &keyix)) { 1188218154Sadrian ath_freetx(m0); 1189218154Sadrian return EIO; 1190218154Sadrian } 1191218065Sadrian 1192218154Sadrian /* packet header may have moved, reset our local pointer */ 1193218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1194218065Sadrian 1195218065Sadrian pktlen += IEEE80211_CRC_LEN; 1196218065Sadrian 1197218065Sadrian /* 1198218065Sadrian * Load the DMA map so any coalescing is done. This 1199218065Sadrian * also calculates the number of descriptors we need. 1200218065Sadrian */ 1201218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1202218065Sadrian if (error != 0) 1203218065Sadrian return error; 1204218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1205218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1206218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1207218065Sadrian 1208218065Sadrian /* setup descriptors */ 1209218065Sadrian ds = bf->bf_desc; 1210218065Sadrian rt = sc->sc_currates; 1211218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1212218065Sadrian 1213218065Sadrian /* 1214218065Sadrian * NB: the 802.11 layer marks whether or not we should 1215218065Sadrian * use short preamble based on the current mode and 1216218065Sadrian * negotiated parameters. 1217218065Sadrian */ 1218218065Sadrian if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 1219218065Sadrian (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) { 1220218065Sadrian shortPreamble = AH_TRUE; 1221218065Sadrian sc->sc_stats.ast_tx_shortpre++; 1222218065Sadrian } else { 1223218065Sadrian shortPreamble = AH_FALSE; 1224218065Sadrian } 1225218065Sadrian 1226218065Sadrian an = ATH_NODE(ni); 1227218065Sadrian flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1228218065Sadrian ismrr = 0; /* default no multi-rate retry*/ 1229218065Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 1230218065Sadrian /* XXX use txparams instead of fixed values */ 1231218065Sadrian /* 1232218065Sadrian * Calculate Atheros packet type from IEEE80211 packet header, 1233218065Sadrian * setup for rate calculations, and select h/w transmit queue. 1234218065Sadrian */ 1235218065Sadrian switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1236218065Sadrian case IEEE80211_FC0_TYPE_MGT: 1237218065Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1238218065Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) 1239218065Sadrian atype = HAL_PKT_TYPE_BEACON; 1240218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) 1241218065Sadrian atype = HAL_PKT_TYPE_PROBE_RESP; 1242218065Sadrian else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) 1243218065Sadrian atype = HAL_PKT_TYPE_ATIM; 1244218065Sadrian else 1245218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* XXX */ 1246218065Sadrian rix = an->an_mgmtrix; 1247218065Sadrian txrate = rt->info[rix].rateCode; 1248218065Sadrian if (shortPreamble) 1249218065Sadrian txrate |= rt->info[rix].shortPreamble; 1250218065Sadrian try0 = ATH_TXMGTTRY; 1251218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1252218065Sadrian break; 1253218065Sadrian case IEEE80211_FC0_TYPE_CTL: 1254218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; /* stop setting of duration */ 1255218065Sadrian rix = an->an_mgmtrix; 1256218065Sadrian txrate = rt->info[rix].rateCode; 1257218065Sadrian if (shortPreamble) 1258218065Sadrian txrate |= rt->info[rix].shortPreamble; 1259218065Sadrian try0 = ATH_TXMGTTRY; 1260218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1261218065Sadrian break; 1262218065Sadrian case IEEE80211_FC0_TYPE_DATA: 1263218065Sadrian atype = HAL_PKT_TYPE_NORMAL; /* default */ 1264218065Sadrian /* 1265218065Sadrian * Data frames: multicast frames go out at a fixed rate, 1266218065Sadrian * EAPOL frames use the mgmt frame rate; otherwise consult 1267218065Sadrian * the rate control module for the rate to use. 1268218065Sadrian */ 1269218065Sadrian if (ismcast) { 1270218065Sadrian rix = an->an_mcastrix; 1271218065Sadrian txrate = rt->info[rix].rateCode; 1272218065Sadrian if (shortPreamble) 1273218065Sadrian txrate |= rt->info[rix].shortPreamble; 1274218065Sadrian try0 = 1; 1275218065Sadrian } else if (m0->m_flags & M_EAPOL) { 1276218065Sadrian /* XXX? maybe always use long preamble? */ 1277218065Sadrian rix = an->an_mgmtrix; 1278218065Sadrian txrate = rt->info[rix].rateCode; 1279218065Sadrian if (shortPreamble) 1280218065Sadrian txrate |= rt->info[rix].shortPreamble; 1281218065Sadrian try0 = ATH_TXMAXTRY; /* XXX?too many? */ 1282218065Sadrian } else { 1283227364Sadrian /* 1284227364Sadrian * Do rate lookup on each TX, rather than using 1285227364Sadrian * the hard-coded TX information decided here. 1286227364Sadrian */ 1287227364Sadrian ismrr = 1; 1288227364Sadrian bf->bf_state.bfs_doratelookup = 1; 1289218065Sadrian } 1290218065Sadrian if (cap->cap_wmeParams[pri].wmep_noackPolicy) 1291218065Sadrian flags |= HAL_TXDESC_NOACK; 1292218065Sadrian break; 1293218065Sadrian default: 1294218065Sadrian if_printf(ifp, "bogus frame type 0x%x (%s)\n", 1295218065Sadrian wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__); 1296218065Sadrian /* XXX statistic */ 1297218065Sadrian ath_freetx(m0); 1298218065Sadrian return EIO; 1299218065Sadrian } 1300218065Sadrian 1301218065Sadrian /* 1302218065Sadrian * Calculate miscellaneous flags. 1303218065Sadrian */ 1304218065Sadrian if (ismcast) { 1305218065Sadrian flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ 1306218065Sadrian } else if (pktlen > vap->iv_rtsthreshold && 1307218065Sadrian (ni->ni_ath_flags & IEEE80211_NODE_FF) == 0) { 1308218065Sadrian flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ 1309218065Sadrian sc->sc_stats.ast_tx_rts++; 1310218065Sadrian } 1311218065Sadrian if (flags & HAL_TXDESC_NOACK) /* NB: avoid double counting */ 1312218065Sadrian sc->sc_stats.ast_tx_noack++; 1313218065Sadrian#ifdef IEEE80211_SUPPORT_TDMA 1314218065Sadrian if (sc->sc_tdma && (flags & HAL_TXDESC_NOACK) == 0) { 1315218065Sadrian DPRINTF(sc, ATH_DEBUG_TDMA, 1316218065Sadrian "%s: discard frame, ACK required w/ TDMA\n", __func__); 1317218065Sadrian sc->sc_stats.ast_tdma_ack++; 1318218065Sadrian ath_freetx(m0); 1319218065Sadrian return EIO; 1320218065Sadrian } 1321218065Sadrian#endif 1322218065Sadrian 1323218065Sadrian /* 1324227364Sadrian * Determine if a tx interrupt should be generated for 1325227364Sadrian * this descriptor. We take a tx interrupt to reap 1326227364Sadrian * descriptors when the h/w hits an EOL condition or 1327227364Sadrian * when the descriptor is specifically marked to generate 1328227364Sadrian * an interrupt. We periodically mark descriptors in this 1329227364Sadrian * way to insure timely replenishing of the supply needed 1330227364Sadrian * for sending frames. Defering interrupts reduces system 1331227364Sadrian * load and potentially allows more concurrent work to be 1332227364Sadrian * done but if done to aggressively can cause senders to 1333227364Sadrian * backup. 1334227364Sadrian * 1335227364Sadrian * NB: use >= to deal with sc_txintrperiod changing 1336227364Sadrian * dynamically through sysctl. 1337218065Sadrian */ 1338227364Sadrian if (flags & HAL_TXDESC_INTREQ) { 1339227364Sadrian txq->axq_intrcnt = 0; 1340227364Sadrian } else if (++txq->axq_intrcnt >= sc->sc_txintrperiod) { 1341227364Sadrian flags |= HAL_TXDESC_INTREQ; 1342227364Sadrian txq->axq_intrcnt = 0; 1343227364Sadrian } 1344218932Sadrian 1345227364Sadrian /* This point forward is actual TX bits */ 1346218065Sadrian 1347218065Sadrian /* 1348218065Sadrian * At this point we are committed to sending the frame 1349218065Sadrian * and we don't need to look at m_nextpkt; clear it in 1350218065Sadrian * case this frame is part of frag chain. 1351218065Sadrian */ 1352218065Sadrian m0->m_nextpkt = NULL; 1353218065Sadrian 1354218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1355218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, const uint8_t *), m0->m_len, 1356218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1357218065Sadrian 1358218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1359218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1360218065Sadrian 1361218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1362218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1363218065Sadrian if (iswep) 1364218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1365218065Sadrian if (isfrag) 1366218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1367218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1368218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1369218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1370218065Sadrian 1371218065Sadrian ieee80211_radiotap_tx(vap, m0); 1372218065Sadrian } 1373218065Sadrian 1374227364Sadrian /* Blank the legacy rate array */ 1375227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1376227364Sadrian 1377218065Sadrian /* 1378227364Sadrian * ath_buf_set_rate needs at least one rate/try to setup 1379227364Sadrian * the rate scenario. 1380227364Sadrian */ 1381227364Sadrian bf->bf_state.bfs_rc[0].rix = rix; 1382227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1383227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1384227364Sadrian 1385227364Sadrian /* Store the decided rate index values away */ 1386227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1387227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1388227364Sadrian bf->bf_state.bfs_atype = atype; 1389227364Sadrian bf->bf_state.bfs_txpower = ni->ni_txpower; 1390227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1391227364Sadrian bf->bf_state.bfs_try0 = try0; 1392227364Sadrian bf->bf_state.bfs_keyix = keyix; 1393227364Sadrian bf->bf_state.bfs_txantenna = sc->sc_txantenna; 1394233966Sadrian bf->bf_state.bfs_txflags = flags; 1395227364Sadrian bf->bf_state.bfs_shpream = shortPreamble; 1396227364Sadrian 1397227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1398227364Sadrian bf->bf_state.bfs_ctsrate0 = 0; /* ie, no hard-coded ctsrate */ 1399227364Sadrian bf->bf_state.bfs_ctsrate = 0; /* calculated later */ 1400227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1401227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1402227364Sadrian 1403227364Sadrian return 0; 1404227364Sadrian} 1405227364Sadrian 1406227364Sadrian/* 1407227364Sadrian * Direct-dispatch the current frame to the hardware. 1408227364Sadrian * 1409227364Sadrian * This can be called by the net80211 code. 1410227364Sadrian * 1411227364Sadrian * XXX what about locking? Or, push the seqno assign into the 1412227364Sadrian * XXX aggregate scheduler so its serialised? 1413227364Sadrian */ 1414227364Sadrianint 1415227364Sadrianath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, 1416227364Sadrian struct ath_buf *bf, struct mbuf *m0) 1417227364Sadrian{ 1418227364Sadrian struct ieee80211vap *vap = ni->ni_vap; 1419227364Sadrian struct ath_vap *avp = ATH_VAP(vap); 1420232764Sadrian int r = 0; 1421227364Sadrian u_int pri; 1422227364Sadrian int tid; 1423227364Sadrian struct ath_txq *txq; 1424227364Sadrian int ismcast; 1425227364Sadrian const struct ieee80211_frame *wh; 1426227364Sadrian int is_ampdu, is_ampdu_tx, is_ampdu_pending; 1427233227Sadrian //ieee80211_seq seqno; 1428227364Sadrian uint8_t type, subtype; 1429227364Sadrian 1430227364Sadrian /* 1431227364Sadrian * Determine the target hardware queue. 1432218065Sadrian * 1433234009Sadrian * For multicast frames, the txq gets overridden appropriately 1434234009Sadrian * depending upon the state of PS. 1435227364Sadrian * 1436227364Sadrian * For any other frame, we do a TID/QoS lookup inside the frame 1437227364Sadrian * to see what the TID should be. If it's a non-QoS frame, the 1438227364Sadrian * AC and TID are overridden. The TID/TXQ code assumes the 1439227364Sadrian * TID is on a predictable hardware TXQ, so we don't support 1440227364Sadrian * having a node TID queued to multiple hardware TXQs. 1441227364Sadrian * This may change in the future but would require some locking 1442227364Sadrian * fudgery. 1443218065Sadrian */ 1444227364Sadrian pri = ath_tx_getac(sc, m0); 1445227364Sadrian tid = ath_tx_gettid(sc, m0); 1446218065Sadrian 1447227364Sadrian txq = sc->sc_ac2q[pri]; 1448227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 1449227364Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1450227364Sadrian type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 1451227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 1452227364Sadrian 1453232764Sadrian /* 1454232764Sadrian * Enforce how deep the multicast queue can grow. 1455232764Sadrian * 1456232764Sadrian * XXX duplicated in ath_raw_xmit(). 1457232764Sadrian */ 1458232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1459232764Sadrian ATH_TXQ_LOCK(sc->sc_cabq); 1460232764Sadrian 1461232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 1462232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 1463232764Sadrian r = ENOBUFS; 1464232764Sadrian } 1465232764Sadrian 1466232764Sadrian ATH_TXQ_UNLOCK(sc->sc_cabq); 1467232764Sadrian 1468232764Sadrian if (r != 0) { 1469232764Sadrian m_freem(m0); 1470232764Sadrian return r; 1471232764Sadrian } 1472232764Sadrian } 1473232764Sadrian 1474227364Sadrian /* A-MPDU TX */ 1475227364Sadrian is_ampdu_tx = ath_tx_ampdu_running(sc, ATH_NODE(ni), tid); 1476227364Sadrian is_ampdu_pending = ath_tx_ampdu_pending(sc, ATH_NODE(ni), tid); 1477227364Sadrian is_ampdu = is_ampdu_tx | is_ampdu_pending; 1478227364Sadrian 1479233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1480233227Sadrian "%s: bf=%p, tid=%d, ac=%d, is_ampdu=%d\n", 1481233227Sadrian __func__, bf, tid, pri, is_ampdu); 1482227364Sadrian 1483232753Sadrian /* 1484234009Sadrian * When servicing one or more stations in power-save mode 1485234009Sadrian * (or) if there is some mcast data waiting on the mcast 1486234009Sadrian * queue (to prevent out of order delivery) multicast frames 1487234009Sadrian * must be bufferd until after the beacon. 1488234009Sadrian * 1489234009Sadrian * TODO: we should lock the mcastq before we check the length. 1490232753Sadrian */ 1491234009Sadrian if (ismcast && (vap->iv_ps_sta || avp->av_mcastq.axq_depth)) 1492227364Sadrian txq = &avp->av_mcastq; 1493227364Sadrian 1494227364Sadrian /* Do the generic frame setup */ 1495227364Sadrian /* XXX should just bzero the bf_state? */ 1496227364Sadrian bf->bf_state.bfs_dobaw = 0; 1497233227Sadrian bf->bf_state.bfs_seqno_assigned = 0; 1498233227Sadrian bf->bf_state.bfs_need_seqno = 0; 1499233227Sadrian bf->bf_state.bfs_seqno = -1; /* XXX debugging */ 1500227364Sadrian 1501227364Sadrian /* A-MPDU TX? Manually set sequence number */ 1502227364Sadrian /* Don't do it whilst pending; the net80211 layer still assigns them */ 1503227364Sadrian /* XXX do we need locking here? */ 1504227364Sadrian if (is_ampdu_tx) { 1505227364Sadrian ATH_TXQ_LOCK(txq); 1506227364Sadrian /* 1507227364Sadrian * Always call; this function will 1508227364Sadrian * handle making sure that null data frames 1509227364Sadrian * don't get a sequence number from the current 1510227364Sadrian * TID and thus mess with the BAW. 1511227364Sadrian */ 1512233227Sadrian //seqno = ath_tx_tid_seqno_assign(sc, ni, bf, m0); 1513233227Sadrian if (ath_tx_seqno_required(sc, ni, bf, m0)) { 1514227364Sadrian bf->bf_state.bfs_dobaw = 1; 1515233227Sadrian bf->bf_state.bfs_need_seqno = 1; 1516227364Sadrian } 1517227364Sadrian ATH_TXQ_UNLOCK(txq); 1518233227Sadrian } else { 1519233227Sadrian /* No AMPDU TX, we've been assigned a sequence number. */ 1520233227Sadrian if (IEEE80211_QOS_HAS_SEQ(wh)) { 1521233227Sadrian bf->bf_state.bfs_seqno_assigned = 1; 1522233330Sadrian /* XXX we should store the frag+seqno in bfs_seqno */ 1523233227Sadrian bf->bf_state.bfs_seqno = 1524233227Sadrian M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1525233227Sadrian } 1526218240Sadrian } 1527218240Sadrian 1528218065Sadrian /* 1529227364Sadrian * If needed, the sequence number has been assigned. 1530227364Sadrian * Squirrel it away somewhere easy to get to. 1531218065Sadrian */ 1532233227Sadrian //bf->bf_state.bfs_seqno = M_SEQNO_GET(m0) << IEEE80211_SEQ_SEQ_SHIFT; 1533227364Sadrian 1534227364Sadrian /* Is ampdu pending? fetch the seqno and print it out */ 1535227364Sadrian if (is_ampdu_pending) 1536227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1537227364Sadrian "%s: tid %d: ampdu pending, seqno %d\n", 1538227364Sadrian __func__, tid, M_SEQNO_GET(m0)); 1539227364Sadrian 1540227364Sadrian /* This also sets up the DMA map */ 1541234009Sadrian r = ath_tx_normal_setup(sc, ni, bf, m0, txq); 1542227364Sadrian 1543227364Sadrian if (r != 0) 1544227364Sadrian return r; 1545227364Sadrian 1546227364Sadrian /* At this point m0 could have changed! */ 1547227364Sadrian m0 = bf->bf_m; 1548227364Sadrian 1549233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 1550233227Sadrian "%s: DONE: bf=%p, tid=%d, ac=%d, is_ampdu=%d, dobaw=%d, seqno=%d\n", 1551233227Sadrian __func__, bf, tid, pri, is_ampdu, bf->bf_state.bfs_dobaw, M_SEQNO_GET(m0)); 1552233227Sadrian 1553227364Sadrian#if 1 1554218065Sadrian /* 1555227364Sadrian * If it's a multicast frame, do a direct-dispatch to the 1556227364Sadrian * destination hardware queue. Don't bother software 1557227364Sadrian * queuing it. 1558218065Sadrian */ 1559227364Sadrian /* 1560227364Sadrian * If it's a BAR frame, do a direct dispatch to the 1561227364Sadrian * destination hardware queue. Don't bother software 1562227364Sadrian * queuing it, as the TID will now be paused. 1563227364Sadrian * Sending a BAR frame can occur from the net80211 txa timer 1564227364Sadrian * (ie, retries) or from the ath txtask (completion call.) 1565227364Sadrian * It queues directly to hardware because the TID is paused 1566227364Sadrian * at this point (and won't be unpaused until the BAR has 1567227364Sadrian * either been TXed successfully or max retries has been 1568227364Sadrian * reached.) 1569227364Sadrian */ 1570227364Sadrian if (txq == &avp->av_mcastq) { 1571233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 1572233227Sadrian "%s: bf=%p: mcastq: TX'ing\n", __func__, bf); 1573227364Sadrian ATH_TXQ_LOCK(txq); 1574227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1575227364Sadrian ATH_TXQ_UNLOCK(txq); 1576227364Sadrian } else if (type == IEEE80211_FC0_TYPE_CTL && 1577227364Sadrian subtype == IEEE80211_FC0_SUBTYPE_BAR) { 1578227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 1579227364Sadrian "%s: BAR: TX'ing direct\n", __func__); 1580227364Sadrian ATH_TXQ_LOCK(txq); 1581227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1582227364Sadrian ATH_TXQ_UNLOCK(txq); 1583227364Sadrian } else { 1584227364Sadrian /* add to software queue */ 1585233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 1586233227Sadrian "%s: bf=%p: swq: TX'ing\n", __func__, bf); 1587227364Sadrian ath_tx_swq(sc, ni, txq, bf); 1588227364Sadrian } 1589227364Sadrian#else 1590227364Sadrian /* 1591227364Sadrian * For now, since there's no software queue, 1592227364Sadrian * direct-dispatch to the hardware. 1593227364Sadrian */ 1594227364Sadrian ATH_TXQ_LOCK(txq); 1595227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 1596227364Sadrian ATH_TXQ_UNLOCK(txq); 1597227364Sadrian#endif 1598218065Sadrian 1599218065Sadrian return 0; 1600218065Sadrian} 1601218065Sadrian 1602218065Sadrianstatic int 1603218065Sadrianath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni, 1604218065Sadrian struct ath_buf *bf, struct mbuf *m0, 1605218065Sadrian const struct ieee80211_bpf_params *params) 1606218065Sadrian{ 1607218065Sadrian struct ifnet *ifp = sc->sc_ifp; 1608218065Sadrian struct ieee80211com *ic = ifp->if_l2com; 1609218065Sadrian struct ath_hal *ah = sc->sc_ah; 1610218065Sadrian struct ieee80211vap *vap = ni->ni_vap; 1611218065Sadrian int error, ismcast, ismrr; 1612218065Sadrian int keyix, hdrlen, pktlen, try0, txantenna; 1613227364Sadrian u_int8_t rix, txrate; 1614218065Sadrian struct ieee80211_frame *wh; 1615227364Sadrian u_int flags; 1616218065Sadrian HAL_PKT_TYPE atype; 1617218065Sadrian const HAL_RATE_TABLE *rt; 1618218065Sadrian struct ath_desc *ds; 1619218065Sadrian u_int pri; 1620227364Sadrian int o_tid = -1; 1621227364Sadrian int do_override; 1622218065Sadrian 1623218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1624218065Sadrian ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); 1625218065Sadrian hdrlen = ieee80211_anyhdrsize(wh); 1626218065Sadrian /* 1627218065Sadrian * Packet length must not include any 1628218065Sadrian * pad bytes; deduct them here. 1629218065Sadrian */ 1630218065Sadrian /* XXX honor IEEE80211_BPF_DATAPAD */ 1631218065Sadrian pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; 1632218065Sadrian 1633227364Sadrian 1634227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: ismcast=%d\n", 1635227364Sadrian __func__, ismcast); 1636227364Sadrian 1637218154Sadrian /* Handle encryption twiddling if needed */ 1638227364Sadrian if (! ath_tx_tag_crypto(sc, ni, 1639227364Sadrian m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0, 1640227364Sadrian &hdrlen, &pktlen, &keyix)) { 1641218154Sadrian ath_freetx(m0); 1642218154Sadrian return EIO; 1643218154Sadrian } 1644218154Sadrian /* packet header may have moved, reset our local pointer */ 1645218154Sadrian wh = mtod(m0, struct ieee80211_frame *); 1646218065Sadrian 1647227364Sadrian /* Do the generic frame setup */ 1648227364Sadrian /* XXX should just bzero the bf_state? */ 1649227364Sadrian bf->bf_state.bfs_dobaw = 0; 1650227364Sadrian 1651218065Sadrian error = ath_tx_dmasetup(sc, bf, m0); 1652218065Sadrian if (error != 0) 1653218065Sadrian return error; 1654218065Sadrian m0 = bf->bf_m; /* NB: may have changed */ 1655218065Sadrian wh = mtod(m0, struct ieee80211_frame *); 1656218065Sadrian bf->bf_node = ni; /* NB: held reference */ 1657218065Sadrian 1658218065Sadrian flags = HAL_TXDESC_CLRDMASK; /* XXX needed for crypto errs */ 1659218065Sadrian flags |= HAL_TXDESC_INTREQ; /* force interrupt */ 1660218065Sadrian if (params->ibp_flags & IEEE80211_BPF_RTS) 1661218065Sadrian flags |= HAL_TXDESC_RTSENA; 1662227364Sadrian else if (params->ibp_flags & IEEE80211_BPF_CTS) { 1663227364Sadrian /* XXX assume 11g/11n protection? */ 1664227364Sadrian bf->bf_state.bfs_doprot = 1; 1665218065Sadrian flags |= HAL_TXDESC_CTSENA; 1666227364Sadrian } 1667218065Sadrian /* XXX leave ismcast to injector? */ 1668218065Sadrian if ((params->ibp_flags & IEEE80211_BPF_NOACK) || ismcast) 1669218065Sadrian flags |= HAL_TXDESC_NOACK; 1670218065Sadrian 1671218065Sadrian rt = sc->sc_currates; 1672218065Sadrian KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 1673218065Sadrian rix = ath_tx_findrix(sc, params->ibp_rate0); 1674218065Sadrian txrate = rt->info[rix].rateCode; 1675218065Sadrian if (params->ibp_flags & IEEE80211_BPF_SHORTPRE) 1676218065Sadrian txrate |= rt->info[rix].shortPreamble; 1677218065Sadrian sc->sc_txrix = rix; 1678218065Sadrian try0 = params->ibp_try0; 1679218065Sadrian ismrr = (params->ibp_try1 != 0); 1680218065Sadrian txantenna = params->ibp_pri >> 2; 1681218065Sadrian if (txantenna == 0) /* XXX? */ 1682218065Sadrian txantenna = sc->sc_txantenna; 1683218157Sadrian 1684227364Sadrian /* 1685227364Sadrian * Since ctsrate is fixed, store it away for later 1686227364Sadrian * use when the descriptor fields are being set. 1687227364Sadrian */ 1688227364Sadrian if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) 1689227364Sadrian bf->bf_state.bfs_ctsrate0 = params->ibp_ctsrate; 1690218157Sadrian 1691218065Sadrian pri = params->ibp_pri & 3; 1692227364Sadrian /* Override pri if the frame isn't a QoS one */ 1693227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 1694227364Sadrian pri = ath_tx_getac(sc, m0); 1695227364Sadrian 1696218065Sadrian /* 1697218065Sadrian * NB: we mark all packets as type PSPOLL so the h/w won't 1698218065Sadrian * set the sequence number, duration, etc. 1699218065Sadrian */ 1700218065Sadrian atype = HAL_PKT_TYPE_PSPOLL; 1701218065Sadrian 1702218065Sadrian if (IFF_DUMPPKTS(sc, ATH_DEBUG_XMIT)) 1703218065Sadrian ieee80211_dump_pkt(ic, mtod(m0, caddr_t), m0->m_len, 1704218065Sadrian sc->sc_hwmap[rix].ieeerate, -1); 1705218065Sadrian 1706218065Sadrian if (ieee80211_radiotap_active_vap(vap)) { 1707218065Sadrian u_int64_t tsf = ath_hal_gettsf64(ah); 1708218065Sadrian 1709218065Sadrian sc->sc_tx_th.wt_tsf = htole64(tsf); 1710218065Sadrian sc->sc_tx_th.wt_flags = sc->sc_hwmap[rix].txflags; 1711218065Sadrian if (wh->i_fc[1] & IEEE80211_FC1_WEP) 1712218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP; 1713218065Sadrian if (m0->m_flags & M_FRAG) 1714218065Sadrian sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 1715218065Sadrian sc->sc_tx_th.wt_rate = sc->sc_hwmap[rix].ieeerate; 1716218065Sadrian sc->sc_tx_th.wt_txpower = ni->ni_txpower; 1717218065Sadrian sc->sc_tx_th.wt_antenna = sc->sc_txantenna; 1718218065Sadrian 1719218065Sadrian ieee80211_radiotap_tx(vap, m0); 1720218065Sadrian } 1721218065Sadrian 1722218065Sadrian /* 1723218065Sadrian * Formulate first tx descriptor with tx controls. 1724218065Sadrian */ 1725218065Sadrian ds = bf->bf_desc; 1726218065Sadrian /* XXX check return value? */ 1727227364Sadrian 1728227364Sadrian /* Store the decided rate index values away */ 1729227364Sadrian bf->bf_state.bfs_pktlen = pktlen; 1730227364Sadrian bf->bf_state.bfs_hdrlen = hdrlen; 1731227364Sadrian bf->bf_state.bfs_atype = atype; 1732227364Sadrian bf->bf_state.bfs_txpower = params->ibp_power; 1733227364Sadrian bf->bf_state.bfs_txrate0 = txrate; 1734227364Sadrian bf->bf_state.bfs_try0 = try0; 1735227364Sadrian bf->bf_state.bfs_keyix = keyix; 1736227364Sadrian bf->bf_state.bfs_txantenna = txantenna; 1737233966Sadrian bf->bf_state.bfs_txflags = flags; 1738227364Sadrian bf->bf_state.bfs_shpream = 1739227364Sadrian !! (params->ibp_flags & IEEE80211_BPF_SHORTPRE); 1740218065Sadrian 1741227364Sadrian /* XXX this should be done in ath_tx_setrate() */ 1742227364Sadrian bf->bf_state.bfs_ctsrate = 0; 1743227364Sadrian bf->bf_state.bfs_ctsduration = 0; 1744227364Sadrian bf->bf_state.bfs_ismrr = ismrr; 1745218240Sadrian 1746227364Sadrian /* Blank the legacy rate array */ 1747227364Sadrian bzero(&bf->bf_state.bfs_rc, sizeof(bf->bf_state.bfs_rc)); 1748218240Sadrian 1749227364Sadrian bf->bf_state.bfs_rc[0].rix = 1750227364Sadrian ath_tx_findrix(sc, params->ibp_rate0); 1751227364Sadrian bf->bf_state.bfs_rc[0].tries = try0; 1752227364Sadrian bf->bf_state.bfs_rc[0].ratecode = txrate; 1753227364Sadrian 1754227364Sadrian if (ismrr) { 1755227364Sadrian int rix; 1756227364Sadrian 1757227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate1); 1758227364Sadrian bf->bf_state.bfs_rc[1].rix = rix; 1759227364Sadrian bf->bf_state.bfs_rc[1].tries = params->ibp_try1; 1760227364Sadrian 1761227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate2); 1762227364Sadrian bf->bf_state.bfs_rc[2].rix = rix; 1763227364Sadrian bf->bf_state.bfs_rc[2].tries = params->ibp_try2; 1764227364Sadrian 1765227364Sadrian rix = ath_tx_findrix(sc, params->ibp_rate3); 1766227364Sadrian bf->bf_state.bfs_rc[3].rix = rix; 1767227364Sadrian bf->bf_state.bfs_rc[3].tries = params->ibp_try3; 1768218065Sadrian } 1769227364Sadrian /* 1770227364Sadrian * All the required rate control decisions have been made; 1771227364Sadrian * fill in the rc flags. 1772227364Sadrian */ 1773227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 1774218065Sadrian 1775227364Sadrian /* NB: no buffered multicast in power save support */ 1776227364Sadrian 1777227364Sadrian /* XXX If it's an ADDBA, override the correct queue */ 1778227364Sadrian do_override = ath_tx_action_frame_override_queue(sc, ni, m0, &o_tid); 1779227364Sadrian 1780227364Sadrian /* Map ADDBA to the correct priority */ 1781227364Sadrian if (do_override) { 1782227364Sadrian#if 0 1783227364Sadrian device_printf(sc->sc_dev, 1784227364Sadrian "%s: overriding tid %d pri %d -> %d\n", 1785227364Sadrian __func__, o_tid, pri, TID_TO_WME_AC(o_tid)); 1786227364Sadrian#endif 1787227364Sadrian pri = TID_TO_WME_AC(o_tid); 1788218240Sadrian } 1789218240Sadrian 1790227364Sadrian /* 1791227364Sadrian * If we're overiding the ADDBA destination, dump directly 1792227364Sadrian * into the hardware queue, right after any pending 1793227364Sadrian * frames to that node are. 1794227364Sadrian */ 1795227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: dooverride=%d\n", 1796227364Sadrian __func__, do_override); 1797227364Sadrian 1798227364Sadrian if (do_override) { 1799227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[pri]); 1800227364Sadrian ath_tx_xmit_normal(sc, sc->sc_ac2q[pri], bf); 1801227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[pri]); 1802227364Sadrian } else { 1803227364Sadrian /* Queue to software queue */ 1804227364Sadrian ath_tx_swq(sc, ni, sc->sc_ac2q[pri], bf); 1805227364Sadrian } 1806227364Sadrian 1807218065Sadrian return 0; 1808218065Sadrian} 1809218065Sadrian 1810227364Sadrian/* 1811227364Sadrian * Send a raw frame. 1812227364Sadrian * 1813227364Sadrian * This can be called by net80211. 1814227364Sadrian */ 1815218065Sadrianint 1816218065Sadrianath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 1817218065Sadrian const struct ieee80211_bpf_params *params) 1818218065Sadrian{ 1819218065Sadrian struct ieee80211com *ic = ni->ni_ic; 1820218065Sadrian struct ifnet *ifp = ic->ic_ifp; 1821218065Sadrian struct ath_softc *sc = ifp->if_softc; 1822218065Sadrian struct ath_buf *bf; 1823232764Sadrian struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 1824232764Sadrian int error = 0; 1825218065Sadrian 1826227651Sadrian ATH_PCU_LOCK(sc); 1827227651Sadrian if (sc->sc_inreset_cnt > 0) { 1828227651Sadrian device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; bailing\n", 1829227651Sadrian __func__); 1830227651Sadrian error = EIO; 1831227651Sadrian ATH_PCU_UNLOCK(sc); 1832227651Sadrian goto bad0; 1833227651Sadrian } 1834227651Sadrian sc->sc_txstart_cnt++; 1835227651Sadrian ATH_PCU_UNLOCK(sc); 1836227651Sadrian 1837218065Sadrian if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) { 1838218065Sadrian DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__, 1839218065Sadrian (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ? 1840218065Sadrian "!running" : "invalid"); 1841218065Sadrian m_freem(m); 1842218065Sadrian error = ENETDOWN; 1843218065Sadrian goto bad; 1844218065Sadrian } 1845232764Sadrian 1846218065Sadrian /* 1847232764Sadrian * Enforce how deep the multicast queue can grow. 1848232764Sadrian * 1849232764Sadrian * XXX duplicated in ath_tx_start(). 1850232764Sadrian */ 1851232764Sadrian if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1852232764Sadrian ATH_TXQ_LOCK(sc->sc_cabq); 1853232764Sadrian 1854232794Sadrian if (sc->sc_cabq->axq_depth > sc->sc_txq_mcastq_maxdepth) { 1855232764Sadrian sc->sc_stats.ast_tx_mcastq_overflow++; 1856232764Sadrian error = ENOBUFS; 1857232764Sadrian } 1858232764Sadrian 1859232764Sadrian ATH_TXQ_UNLOCK(sc->sc_cabq); 1860232764Sadrian 1861232764Sadrian if (error != 0) { 1862232764Sadrian m_freem(m); 1863232764Sadrian goto bad; 1864232764Sadrian } 1865232764Sadrian } 1866232764Sadrian 1867232764Sadrian /* 1868218065Sadrian * Grab a TX buffer and associated resources. 1869218065Sadrian */ 1870218065Sadrian bf = ath_getbuf(sc); 1871218065Sadrian if (bf == NULL) { 1872218065Sadrian sc->sc_stats.ast_tx_nobuf++; 1873218065Sadrian m_freem(m); 1874218065Sadrian error = ENOBUFS; 1875218065Sadrian goto bad; 1876218065Sadrian } 1877218065Sadrian 1878218065Sadrian if (params == NULL) { 1879218065Sadrian /* 1880218065Sadrian * Legacy path; interpret frame contents to decide 1881218065Sadrian * precisely how to send the frame. 1882218065Sadrian */ 1883218065Sadrian if (ath_tx_start(sc, ni, bf, m)) { 1884218065Sadrian error = EIO; /* XXX */ 1885218065Sadrian goto bad2; 1886218065Sadrian } 1887218065Sadrian } else { 1888218065Sadrian /* 1889218065Sadrian * Caller supplied explicit parameters to use in 1890218065Sadrian * sending the frame. 1891218065Sadrian */ 1892218065Sadrian if (ath_tx_raw_start(sc, ni, bf, m, params)) { 1893218065Sadrian error = EIO; /* XXX */ 1894218065Sadrian goto bad2; 1895218065Sadrian } 1896218065Sadrian } 1897218065Sadrian sc->sc_wd_timer = 5; 1898218065Sadrian ifp->if_opackets++; 1899218065Sadrian sc->sc_stats.ast_tx_raw++; 1900218065Sadrian 1901227651Sadrian ATH_PCU_LOCK(sc); 1902227651Sadrian sc->sc_txstart_cnt--; 1903227651Sadrian ATH_PCU_UNLOCK(sc); 1904227651Sadrian 1905218065Sadrian return 0; 1906218065Sadrianbad2: 1907218065Sadrian ATH_TXBUF_LOCK(sc); 1908227344Sadrian TAILQ_INSERT_HEAD(&sc->sc_txbuf, bf, bf_list); 1909218065Sadrian ATH_TXBUF_UNLOCK(sc); 1910218065Sadrianbad: 1911227651Sadrian ATH_PCU_LOCK(sc); 1912227651Sadrian sc->sc_txstart_cnt--; 1913227651Sadrian ATH_PCU_UNLOCK(sc); 1914227651Sadrianbad0: 1915218065Sadrian ifp->if_oerrors++; 1916218065Sadrian sc->sc_stats.ast_tx_raw_fail++; 1917218065Sadrian ieee80211_free_node(ni); 1918227651Sadrian 1919218065Sadrian return error; 1920218065Sadrian} 1921227364Sadrian 1922227364Sadrian/* Some helper functions */ 1923227364Sadrian 1924227364Sadrian/* 1925227364Sadrian * ADDBA (and potentially others) need to be placed in the same 1926227364Sadrian * hardware queue as the TID/node it's relating to. This is so 1927227364Sadrian * it goes out after any pending non-aggregate frames to the 1928227364Sadrian * same node/TID. 1929227364Sadrian * 1930227364Sadrian * If this isn't done, the ADDBA can go out before the frames 1931227364Sadrian * queued in hardware. Even though these frames have a sequence 1932227364Sadrian * number -earlier- than the ADDBA can be transmitted (but 1933227364Sadrian * no frames whose sequence numbers are after the ADDBA should 1934227364Sadrian * be!) they'll arrive after the ADDBA - and the receiving end 1935227364Sadrian * will simply drop them as being out of the BAW. 1936227364Sadrian * 1937227364Sadrian * The frames can't be appended to the TID software queue - it'll 1938227364Sadrian * never be sent out. So these frames have to be directly 1939227364Sadrian * dispatched to the hardware, rather than queued in software. 1940227364Sadrian * So if this function returns true, the TXQ has to be 1941227364Sadrian * overridden and it has to be directly dispatched. 1942227364Sadrian * 1943227364Sadrian * It's a dirty hack, but someone's gotta do it. 1944227364Sadrian */ 1945227364Sadrian 1946227364Sadrian/* 1947227364Sadrian * XXX doesn't belong here! 1948227364Sadrian */ 1949227364Sadrianstatic int 1950227364Sadrianieee80211_is_action(struct ieee80211_frame *wh) 1951227364Sadrian{ 1952227364Sadrian /* Type: Management frame? */ 1953227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != 1954227364Sadrian IEEE80211_FC0_TYPE_MGT) 1955227364Sadrian return 0; 1956227364Sadrian 1957227364Sadrian /* Subtype: Action frame? */ 1958227364Sadrian if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) != 1959227364Sadrian IEEE80211_FC0_SUBTYPE_ACTION) 1960227364Sadrian return 0; 1961227364Sadrian 1962227364Sadrian return 1; 1963227364Sadrian} 1964227364Sadrian 1965227364Sadrian#define MS(_v, _f) (((_v) & _f) >> _f##_S) 1966227364Sadrian/* 1967227364Sadrian * Return an alternate TID for ADDBA request frames. 1968227364Sadrian * 1969227364Sadrian * Yes, this likely should be done in the net80211 layer. 1970227364Sadrian */ 1971227364Sadrianstatic int 1972227364Sadrianath_tx_action_frame_override_queue(struct ath_softc *sc, 1973227364Sadrian struct ieee80211_node *ni, 1974227364Sadrian struct mbuf *m0, int *tid) 1975227364Sadrian{ 1976227364Sadrian struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *); 1977227364Sadrian struct ieee80211_action_ba_addbarequest *ia; 1978227364Sadrian uint8_t *frm; 1979227364Sadrian uint16_t baparamset; 1980227364Sadrian 1981227364Sadrian /* Not action frame? Bail */ 1982227364Sadrian if (! ieee80211_is_action(wh)) 1983227364Sadrian return 0; 1984227364Sadrian 1985227364Sadrian /* XXX Not needed for frames we send? */ 1986227364Sadrian#if 0 1987227364Sadrian /* Correct length? */ 1988227364Sadrian if (! ieee80211_parse_action(ni, m)) 1989227364Sadrian return 0; 1990227364Sadrian#endif 1991227364Sadrian 1992227364Sadrian /* Extract out action frame */ 1993227364Sadrian frm = (u_int8_t *)&wh[1]; 1994227364Sadrian ia = (struct ieee80211_action_ba_addbarequest *) frm; 1995227364Sadrian 1996227364Sadrian /* Not ADDBA? Bail */ 1997227364Sadrian if (ia->rq_header.ia_category != IEEE80211_ACTION_CAT_BA) 1998227364Sadrian return 0; 1999227364Sadrian if (ia->rq_header.ia_action != IEEE80211_ACTION_BA_ADDBA_REQUEST) 2000227364Sadrian return 0; 2001227364Sadrian 2002227364Sadrian /* Extract TID, return it */ 2003227364Sadrian baparamset = le16toh(ia->rq_baparamset); 2004227364Sadrian *tid = (int) MS(baparamset, IEEE80211_BAPS_TID); 2005227364Sadrian 2006227364Sadrian return 1; 2007227364Sadrian} 2008227364Sadrian#undef MS 2009227364Sadrian 2010227364Sadrian/* Per-node software queue operations */ 2011227364Sadrian 2012227364Sadrian/* 2013227364Sadrian * Add the current packet to the given BAW. 2014227364Sadrian * It is assumed that the current packet 2015227364Sadrian * 2016227364Sadrian * + fits inside the BAW; 2017227364Sadrian * + already has had a sequence number allocated. 2018227364Sadrian * 2019227364Sadrian * Since the BAW status may be modified by both the ath task and 2020227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2021227364Sadrian */ 2022227364Sadrianvoid 2023227364Sadrianath_tx_addto_baw(struct ath_softc *sc, struct ath_node *an, 2024227364Sadrian struct ath_tid *tid, struct ath_buf *bf) 2025227364Sadrian{ 2026227364Sadrian int index, cindex; 2027227364Sadrian struct ieee80211_tx_ampdu *tap; 2028227364Sadrian 2029227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2030227364Sadrian 2031227364Sadrian if (bf->bf_state.bfs_isretried) 2032227364Sadrian return; 2033227364Sadrian 2034233227Sadrian /* 2035233227Sadrian * If this occurs we're in a lot of trouble. We should try to 2036233227Sadrian * recover from this without the session hanging? 2037233227Sadrian */ 2038233227Sadrian if (! bf->bf_state.bfs_seqno_assigned) { 2039233227Sadrian device_printf(sc->sc_dev, 2040233227Sadrian "%s: bf=%p, seqno_assigned is 0?!\n", __func__, bf); 2041233227Sadrian return; 2042233227Sadrian } 2043233227Sadrian 2044227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2045227364Sadrian 2046227364Sadrian if (bf->bf_state.bfs_addedbaw) 2047227364Sadrian device_printf(sc->sc_dev, 2048233227Sadrian "%s: re-added? bf=%p, tid=%d, seqno %d; window %d:%d; " 2049229949Sadrian "baw head=%d tail=%d\n", 2050233227Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2051229949Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2052229949Sadrian tid->baw_tail); 2053227364Sadrian 2054227364Sadrian /* 2055233227Sadrian * Verify that the given sequence number is not outside of the 2056233227Sadrian * BAW. Complain loudly if that's the case. 2057233227Sadrian */ 2058233227Sadrian if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2059233227Sadrian SEQNO(bf->bf_state.bfs_seqno))) { 2060233227Sadrian device_printf(sc->sc_dev, 2061233227Sadrian "%s: bf=%p: outside of BAW?? tid=%d, seqno %d; window %d:%d; " 2062233227Sadrian "baw head=%d tail=%d\n", 2063233227Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2064233227Sadrian tap->txa_start, tap->txa_wnd, tid->baw_head, 2065233227Sadrian tid->baw_tail); 2066233227Sadrian 2067233227Sadrian } 2068233227Sadrian 2069233227Sadrian /* 2070227364Sadrian * ni->ni_txseqs[] is the currently allocated seqno. 2071227364Sadrian * the txa state contains the current baw start. 2072227364Sadrian */ 2073227364Sadrian index = ATH_BA_INDEX(tap->txa_start, SEQNO(bf->bf_state.bfs_seqno)); 2074227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2075227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2076233227Sadrian "%s: bf=%p, tid=%d, seqno %d; window %d:%d; index=%d cindex=%d " 2077229949Sadrian "baw head=%d tail=%d\n", 2078233227Sadrian __func__, bf, tid->tid, SEQNO(bf->bf_state.bfs_seqno), 2079229949Sadrian tap->txa_start, tap->txa_wnd, index, cindex, tid->baw_head, 2080229949Sadrian tid->baw_tail); 2081227364Sadrian 2082227364Sadrian 2083227364Sadrian#if 0 2084227364Sadrian assert(tid->tx_buf[cindex] == NULL); 2085227364Sadrian#endif 2086227364Sadrian if (tid->tx_buf[cindex] != NULL) { 2087227364Sadrian device_printf(sc->sc_dev, 2088227364Sadrian "%s: ba packet dup (index=%d, cindex=%d, " 2089227364Sadrian "head=%d, tail=%d)\n", 2090227364Sadrian __func__, index, cindex, tid->baw_head, tid->baw_tail); 2091227364Sadrian device_printf(sc->sc_dev, 2092227364Sadrian "%s: BA bf: %p; seqno=%d ; new bf: %p; seqno=%d\n", 2093227364Sadrian __func__, 2094227364Sadrian tid->tx_buf[cindex], 2095227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno), 2096227364Sadrian bf, 2097227364Sadrian SEQNO(bf->bf_state.bfs_seqno) 2098227364Sadrian ); 2099227364Sadrian } 2100227364Sadrian tid->tx_buf[cindex] = bf; 2101227364Sadrian 2102229949Sadrian if (index >= ((tid->baw_tail - tid->baw_head) & 2103229949Sadrian (ATH_TID_MAX_BUFS - 1))) { 2104227364Sadrian tid->baw_tail = cindex; 2105227364Sadrian INCR(tid->baw_tail, ATH_TID_MAX_BUFS); 2106227364Sadrian } 2107227364Sadrian} 2108227364Sadrian 2109227364Sadrian/* 2110227398Sadrian * Flip the BAW buffer entry over from the existing one to the new one. 2111227398Sadrian * 2112227398Sadrian * When software retransmitting a (sub-)frame, it is entirely possible that 2113227398Sadrian * the frame ath_buf is marked as BUSY and can't be immediately reused. 2114227398Sadrian * In that instance the buffer is cloned and the new buffer is used for 2115227398Sadrian * retransmit. We thus need to update the ath_buf slot in the BAW buf 2116227398Sadrian * tracking array to maintain consistency. 2117227398Sadrian */ 2118227398Sadrianstatic void 2119227398Sadrianath_tx_switch_baw_buf(struct ath_softc *sc, struct ath_node *an, 2120227398Sadrian struct ath_tid *tid, struct ath_buf *old_bf, struct ath_buf *new_bf) 2121227398Sadrian{ 2122227398Sadrian int index, cindex; 2123227398Sadrian struct ieee80211_tx_ampdu *tap; 2124227398Sadrian int seqno = SEQNO(old_bf->bf_state.bfs_seqno); 2125227398Sadrian 2126227398Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2127227398Sadrian 2128227398Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2129227398Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2130227398Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2131227398Sadrian 2132227398Sadrian /* 2133227398Sadrian * Just warn for now; if it happens then we should find out 2134227398Sadrian * about it. It's highly likely the aggregation session will 2135227398Sadrian * soon hang. 2136227398Sadrian */ 2137227398Sadrian if (old_bf->bf_state.bfs_seqno != new_bf->bf_state.bfs_seqno) { 2138227398Sadrian device_printf(sc->sc_dev, "%s: retransmitted buffer" 2139227398Sadrian " has mismatching seqno's, BA session may hang.\n", 2140227398Sadrian __func__); 2141227398Sadrian device_printf(sc->sc_dev, "%s: old seqno=%d, new_seqno=%d\n", 2142227398Sadrian __func__, 2143227398Sadrian old_bf->bf_state.bfs_seqno, 2144227398Sadrian new_bf->bf_state.bfs_seqno); 2145227398Sadrian } 2146227398Sadrian 2147227398Sadrian if (tid->tx_buf[cindex] != old_bf) { 2148227398Sadrian device_printf(sc->sc_dev, "%s: ath_buf pointer incorrect; " 2149227398Sadrian " has m BA session may hang.\n", 2150227398Sadrian __func__); 2151227398Sadrian device_printf(sc->sc_dev, "%s: old bf=%p, new bf=%p\n", 2152227398Sadrian __func__, 2153227398Sadrian old_bf, new_bf); 2154227398Sadrian } 2155227398Sadrian 2156227398Sadrian tid->tx_buf[cindex] = new_bf; 2157227398Sadrian} 2158227398Sadrian 2159227398Sadrian/* 2160227364Sadrian * seq_start - left edge of BAW 2161227364Sadrian * seq_next - current/next sequence number to allocate 2162227364Sadrian * 2163227364Sadrian * Since the BAW status may be modified by both the ath task and 2164227364Sadrian * the net80211/ifnet contexts, the TID must be locked. 2165227364Sadrian */ 2166227364Sadrianstatic void 2167227364Sadrianath_tx_update_baw(struct ath_softc *sc, struct ath_node *an, 2168227364Sadrian struct ath_tid *tid, const struct ath_buf *bf) 2169227364Sadrian{ 2170227364Sadrian int index, cindex; 2171227364Sadrian struct ieee80211_tx_ampdu *tap; 2172227364Sadrian int seqno = SEQNO(bf->bf_state.bfs_seqno); 2173227364Sadrian 2174227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2175227364Sadrian 2176227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2177227364Sadrian index = ATH_BA_INDEX(tap->txa_start, seqno); 2178227364Sadrian cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); 2179227364Sadrian 2180227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2181233227Sadrian "%s: bf=%p: tid=%d, baw=%d:%d, seqno=%d, index=%d, cindex=%d, " 2182229949Sadrian "baw head=%d, tail=%d\n", 2183233227Sadrian __func__, bf, tid->tid, tap->txa_start, tap->txa_wnd, seqno, index, 2184227364Sadrian cindex, tid->baw_head, tid->baw_tail); 2185227364Sadrian 2186227364Sadrian /* 2187227364Sadrian * If this occurs then we have a big problem - something else 2188227364Sadrian * has slid tap->txa_start along without updating the BAW 2189227364Sadrian * tracking start/end pointers. Thus the TX BAW state is now 2190227364Sadrian * completely busted. 2191227364Sadrian * 2192227364Sadrian * But for now, since I haven't yet fixed TDMA and buffer cloning, 2193227364Sadrian * it's quite possible that a cloned buffer is making its way 2194227364Sadrian * here and causing it to fire off. Disable TDMA for now. 2195227364Sadrian */ 2196227364Sadrian if (tid->tx_buf[cindex] != bf) { 2197227364Sadrian device_printf(sc->sc_dev, 2198227364Sadrian "%s: comp bf=%p, seq=%d; slot bf=%p, seqno=%d\n", 2199227364Sadrian __func__, 2200227364Sadrian bf, SEQNO(bf->bf_state.bfs_seqno), 2201227364Sadrian tid->tx_buf[cindex], 2202227364Sadrian SEQNO(tid->tx_buf[cindex]->bf_state.bfs_seqno)); 2203227364Sadrian } 2204227364Sadrian 2205227364Sadrian tid->tx_buf[cindex] = NULL; 2206227364Sadrian 2207229949Sadrian while (tid->baw_head != tid->baw_tail && 2208229949Sadrian !tid->tx_buf[tid->baw_head]) { 2209227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 2210227364Sadrian INCR(tid->baw_head, ATH_TID_MAX_BUFS); 2211227364Sadrian } 2212229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2213229949Sadrian "%s: baw is now %d:%d, baw head=%d\n", 2214227364Sadrian __func__, tap->txa_start, tap->txa_wnd, tid->baw_head); 2215227364Sadrian} 2216227364Sadrian 2217227364Sadrian/* 2218227364Sadrian * Mark the current node/TID as ready to TX. 2219227364Sadrian * 2220227364Sadrian * This is done to make it easy for the software scheduler to 2221227364Sadrian * find which nodes have data to send. 2222227364Sadrian * 2223227364Sadrian * The TXQ lock must be held. 2224227364Sadrian */ 2225227364Sadrianstatic void 2226227364Sadrianath_tx_tid_sched(struct ath_softc *sc, struct ath_tid *tid) 2227227364Sadrian{ 2228227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2229227364Sadrian 2230227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2231227364Sadrian 2232227364Sadrian if (tid->paused) 2233227364Sadrian return; /* paused, can't schedule yet */ 2234227364Sadrian 2235227364Sadrian if (tid->sched) 2236227364Sadrian return; /* already scheduled */ 2237227364Sadrian 2238227364Sadrian tid->sched = 1; 2239227364Sadrian 2240227364Sadrian TAILQ_INSERT_TAIL(&txq->axq_tidq, tid, axq_qelem); 2241227364Sadrian} 2242227364Sadrian 2243227364Sadrian/* 2244227364Sadrian * Mark the current node as no longer needing to be polled for 2245227364Sadrian * TX packets. 2246227364Sadrian * 2247227364Sadrian * The TXQ lock must be held. 2248227364Sadrian */ 2249227364Sadrianstatic void 2250227364Sadrianath_tx_tid_unsched(struct ath_softc *sc, struct ath_tid *tid) 2251227364Sadrian{ 2252227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2253227364Sadrian 2254227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2255227364Sadrian 2256227364Sadrian if (tid->sched == 0) 2257227364Sadrian return; 2258227364Sadrian 2259227364Sadrian tid->sched = 0; 2260227364Sadrian TAILQ_REMOVE(&txq->axq_tidq, tid, axq_qelem); 2261227364Sadrian} 2262227364Sadrian 2263227364Sadrian/* 2264233227Sadrian * Return whether a sequence number is actually required. 2265233227Sadrian * 2266233227Sadrian * A sequence number must only be allocated at the time that a frame 2267233227Sadrian * is considered for addition to the BAW/aggregate and being TXed. 2268233227Sadrian * The sequence number must not be allocated before the frame 2269233227Sadrian * is added to the BAW (protected by the same lock instance) 2270233227Sadrian * otherwise a the multi-entrant TX path may result in a later seqno 2271233227Sadrian * being added to the BAW first. The subsequent addition of the 2272233227Sadrian * earlier seqno would then not go into the BAW as it's now outside 2273233227Sadrian * of said BAW. 2274233227Sadrian * 2275233227Sadrian * This routine is used by ath_tx_start() to mark whether the frame 2276233227Sadrian * should get a sequence number before adding it to the BAW. 2277233227Sadrian * 2278233227Sadrian * Then the actual aggregate TX routines will check whether this 2279233227Sadrian * flag is set and if the frame needs to go into the BAW, it'll 2280233227Sadrian * have a sequence number allocated for it. 2281233227Sadrian */ 2282233227Sadrianstatic int 2283233227Sadrianath_tx_seqno_required(struct ath_softc *sc, struct ieee80211_node *ni, 2284233227Sadrian struct ath_buf *bf, struct mbuf *m0) 2285233227Sadrian{ 2286233227Sadrian const struct ieee80211_frame *wh; 2287233227Sadrian uint8_t subtype; 2288233227Sadrian 2289233227Sadrian wh = mtod(m0, const struct ieee80211_frame *); 2290233227Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2291233227Sadrian 2292233227Sadrian /* XXX assert txq lock */ 2293233227Sadrian /* XXX assert ampdu is set */ 2294233227Sadrian 2295233227Sadrian return ((IEEE80211_QOS_HAS_SEQ(wh) && 2296233227Sadrian subtype != IEEE80211_FC0_SUBTYPE_QOS_NULL)); 2297233227Sadrian} 2298233227Sadrian 2299233227Sadrian/* 2300227364Sadrian * Assign a sequence number manually to the given frame. 2301227364Sadrian * 2302227364Sadrian * This should only be called for A-MPDU TX frames. 2303233227Sadrian * 2304233227Sadrian * If this is called after the initial frame setup, make sure you've flushed 2305233227Sadrian * the DMA map or you'll risk sending stale data to the NIC. This routine 2306233227Sadrian * updates the actual frame contents with the relevant seqno. 2307227364Sadrian */ 2308233227Sadrianint 2309227364Sadrianath_tx_tid_seqno_assign(struct ath_softc *sc, struct ieee80211_node *ni, 2310227364Sadrian struct ath_buf *bf, struct mbuf *m0) 2311227364Sadrian{ 2312227364Sadrian struct ieee80211_frame *wh; 2313227364Sadrian int tid, pri; 2314227364Sadrian ieee80211_seq seqno; 2315227364Sadrian uint8_t subtype; 2316227364Sadrian 2317227364Sadrian /* TID lookup */ 2318227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2319227364Sadrian pri = M_WME_GETAC(m0); /* honor classification */ 2320227364Sadrian tid = WME_AC_TO_TID(pri); 2321233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2322233227Sadrian "%s: bf=%p, pri=%d, tid=%d, qos has seq=%d\n", 2323233227Sadrian __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh)); 2324227364Sadrian 2325233227Sadrian if (! bf->bf_state.bfs_need_seqno) { 2326233227Sadrian device_printf(sc->sc_dev, "%s: bf=%p: need_seqno not set?!\n", 2327233227Sadrian __func__, bf); 2328233227Sadrian return -1; 2329233227Sadrian } 2330233227Sadrian /* XXX check for bfs_need_seqno? */ 2331233227Sadrian if (bf->bf_state.bfs_seqno_assigned) { 2332233227Sadrian device_printf(sc->sc_dev, 2333233227Sadrian "%s: bf=%p: seqno already assigned (%d)?!\n", 2334233227Sadrian __func__, bf, SEQNO(bf->bf_state.bfs_seqno)); 2335233227Sadrian return bf->bf_state.bfs_seqno >> IEEE80211_SEQ_SEQ_SHIFT; 2336233227Sadrian } 2337233227Sadrian 2338227364Sadrian /* XXX Is it a control frame? Ignore */ 2339227364Sadrian 2340227364Sadrian /* Does the packet require a sequence number? */ 2341227364Sadrian if (! IEEE80211_QOS_HAS_SEQ(wh)) 2342227364Sadrian return -1; 2343227364Sadrian 2344227364Sadrian /* 2345227364Sadrian * Is it a QOS NULL Data frame? Give it a sequence number from 2346227364Sadrian * the default TID (IEEE80211_NONQOS_TID.) 2347227364Sadrian * 2348227364Sadrian * The RX path of everything I've looked at doesn't include the NULL 2349227364Sadrian * data frame sequence number in the aggregation state updates, so 2350227364Sadrian * assigning it a sequence number there will cause a BAW hole on the 2351227364Sadrian * RX side. 2352227364Sadrian */ 2353227364Sadrian subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 2354227364Sadrian if (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) { 2355227364Sadrian seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 2356227364Sadrian INCR(ni->ni_txseqs[IEEE80211_NONQOS_TID], IEEE80211_SEQ_RANGE); 2357227364Sadrian } else { 2358227364Sadrian /* Manually assign sequence number */ 2359227364Sadrian seqno = ni->ni_txseqs[tid]; 2360227364Sadrian INCR(ni->ni_txseqs[tid], IEEE80211_SEQ_RANGE); 2361227364Sadrian } 2362227364Sadrian *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); 2363227364Sadrian M_SEQNO_SET(m0, seqno); 2364233227Sadrian bf->bf_state.bfs_seqno = seqno << IEEE80211_SEQ_SEQ_SHIFT; 2365233227Sadrian bf->bf_state.bfs_seqno_assigned = 1; 2366227364Sadrian 2367227364Sadrian /* Return so caller can do something with it if needed */ 2368233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: -> seqno=%d\n", 2369233227Sadrian __func__, 2370233227Sadrian bf, 2371233227Sadrian seqno); 2372227364Sadrian return seqno; 2373227364Sadrian} 2374227364Sadrian 2375227364Sadrian/* 2376227364Sadrian * Attempt to direct dispatch an aggregate frame to hardware. 2377227364Sadrian * If the frame is out of BAW, queue. 2378227364Sadrian * Otherwise, schedule it as a single frame. 2379227364Sadrian */ 2380227364Sadrianstatic void 2381227364Sadrianath_tx_xmit_aggr(struct ath_softc *sc, struct ath_node *an, struct ath_buf *bf) 2382227364Sadrian{ 2383233227Sadrian struct ieee80211_node *ni = &an->an_node; 2384227364Sadrian struct ath_tid *tid = &an->an_tid[bf->bf_state.bfs_tid]; 2385227364Sadrian struct ath_txq *txq = bf->bf_state.bfs_txq; 2386227364Sadrian struct ieee80211_tx_ampdu *tap; 2387227364Sadrian 2388227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 2389227364Sadrian 2390227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2391227364Sadrian 2392227364Sadrian /* paused? queue */ 2393227364Sadrian if (tid->paused) { 2394227364Sadrian ATH_TXQ_INSERT_TAIL(tid, bf, bf_list); 2395233480Sadrian /* XXX don't sched - we're paused! */ 2396227364Sadrian return; 2397227364Sadrian } 2398227364Sadrian 2399233227Sadrian /* 2400233227Sadrian * TODO: If it's _before_ the BAW left edge, complain very loudly. 2401233227Sadrian * This means something (else) has slid the left edge along 2402233227Sadrian * before we got a chance to be TXed. 2403233227Sadrian */ 2404233227Sadrian 2405233227Sadrian /* 2406233227Sadrian * Is there space in this BAW for another frame? 2407233227Sadrian * If not, don't bother trying to schedule it; just 2408233227Sadrian * throw it back on the queue. 2409233227Sadrian * 2410233227Sadrian * If we allocate the sequence number before we add 2411233227Sadrian * it to the BAW, we risk racing with another TX 2412233227Sadrian * thread that gets in a frame into the BAW with 2413233227Sadrian * seqno greater than ours. We'd then fail the 2414233227Sadrian * below check and throw the frame on the tail of 2415233227Sadrian * the queue. The sender would then have a hole. 2416233227Sadrian * 2417233227Sadrian * XXX again, we're protecting ni->ni_txseqs[tid] 2418233227Sadrian * behind this hardware TXQ lock, like the rest of 2419233227Sadrian * the TIDs that map to it. Ugh. 2420233227Sadrian */ 2421233227Sadrian if (bf->bf_state.bfs_dobaw) { 2422233514Sadrian ieee80211_seq seqno; 2423233514Sadrian 2424233514Sadrian /* 2425233514Sadrian * If the sequence number is allocated, use it. 2426233514Sadrian * Otherwise, use the sequence number we WOULD 2427233514Sadrian * allocate. 2428233514Sadrian */ 2429233514Sadrian if (bf->bf_state.bfs_seqno_assigned) 2430233514Sadrian seqno = SEQNO(bf->bf_state.bfs_seqno); 2431233514Sadrian else 2432233514Sadrian seqno = ni->ni_txseqs[bf->bf_state.bfs_tid]; 2433233514Sadrian 2434233514Sadrian /* 2435233514Sadrian * Check whether either the currently allocated 2436233514Sadrian * sequence number _OR_ the to-be allocated 2437233514Sadrian * sequence number is inside the BAW. 2438233514Sadrian */ 2439233514Sadrian if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, seqno)) { 2440233227Sadrian ATH_TXQ_INSERT_TAIL(tid, bf, bf_list); 2441233227Sadrian ath_tx_tid_sched(sc, tid); 2442233227Sadrian return; 2443233227Sadrian } 2444233227Sadrian if (! bf->bf_state.bfs_seqno_assigned) { 2445233514Sadrian int seqno; 2446233514Sadrian 2447233227Sadrian seqno = ath_tx_tid_seqno_assign(sc, ni, bf, bf->bf_m); 2448233227Sadrian if (seqno < 0) { 2449233227Sadrian device_printf(sc->sc_dev, 2450233227Sadrian "%s: bf=%p, huh, seqno=-1?\n", 2451233227Sadrian __func__, 2452233227Sadrian bf); 2453233227Sadrian /* XXX what can we even do here? */ 2454233227Sadrian } 2455233227Sadrian /* Flush seqno update to RAM */ 2456233227Sadrian /* 2457233227Sadrian * XXX This is required because the dmasetup 2458233227Sadrian * XXX is done early rather than at dispatch 2459233227Sadrian * XXX time. Ew, we should fix this! 2460233227Sadrian */ 2461233227Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 2462233227Sadrian BUS_DMASYNC_PREWRITE); 2463233227Sadrian } 2464233227Sadrian } 2465233227Sadrian 2466227364Sadrian /* outside baw? queue */ 2467227364Sadrian if (bf->bf_state.bfs_dobaw && 2468227364Sadrian (! BAW_WITHIN(tap->txa_start, tap->txa_wnd, 2469227364Sadrian SEQNO(bf->bf_state.bfs_seqno)))) { 2470233227Sadrian device_printf(sc->sc_dev, 2471233227Sadrian "%s: bf=%p, shouldn't be outside BAW now?!\n", 2472233227Sadrian __func__, 2473233227Sadrian bf); 2474227364Sadrian ATH_TXQ_INSERT_TAIL(tid, bf, bf_list); 2475227364Sadrian ath_tx_tid_sched(sc, tid); 2476227364Sadrian return; 2477227364Sadrian } 2478227364Sadrian 2479227364Sadrian /* Direct dispatch to hardware */ 2480227364Sadrian ath_tx_do_ratelookup(sc, bf); 2481233989Sadrian ath_tx_calc_duration(sc, bf); 2482233989Sadrian ath_tx_calc_protection(sc, bf); 2483233989Sadrian ath_tx_set_rtscts(sc, bf); 2484227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 2485227364Sadrian ath_tx_setds(sc, bf); 2486227364Sadrian ath_tx_set_ratectrl(sc, bf->bf_node, bf); 2487227364Sadrian ath_tx_chaindesclist(sc, bf); 2488227364Sadrian 2489227364Sadrian /* Statistics */ 2490227364Sadrian sc->sc_aggr_stats.aggr_low_hwq_single_pkt++; 2491227364Sadrian 2492227364Sadrian /* Track per-TID hardware queue depth correctly */ 2493227364Sadrian tid->hwq_depth++; 2494227364Sadrian 2495227364Sadrian /* Add to BAW */ 2496227364Sadrian if (bf->bf_state.bfs_dobaw) { 2497227364Sadrian ath_tx_addto_baw(sc, an, tid, bf); 2498227364Sadrian bf->bf_state.bfs_addedbaw = 1; 2499227364Sadrian } 2500227364Sadrian 2501227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 2502227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 2503227364Sadrian 2504227364Sadrian /* Hand off to hardware */ 2505227364Sadrian ath_tx_handoff(sc, txq, bf); 2506227364Sadrian} 2507227364Sadrian 2508227364Sadrian/* 2509227364Sadrian * Attempt to send the packet. 2510227364Sadrian * If the queue isn't busy, direct-dispatch. 2511227364Sadrian * If the queue is busy enough, queue the given packet on the 2512227364Sadrian * relevant software queue. 2513227364Sadrian */ 2514227364Sadrianvoid 2515227364Sadrianath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_txq *txq, 2516227364Sadrian struct ath_buf *bf) 2517227364Sadrian{ 2518227364Sadrian struct ath_node *an = ATH_NODE(ni); 2519227364Sadrian struct ieee80211_frame *wh; 2520227364Sadrian struct ath_tid *atid; 2521227364Sadrian int pri, tid; 2522227364Sadrian struct mbuf *m0 = bf->bf_m; 2523227364Sadrian 2524227364Sadrian /* Fetch the TID - non-QoS frames get assigned to TID 16 */ 2525227364Sadrian wh = mtod(m0, struct ieee80211_frame *); 2526227364Sadrian pri = ath_tx_getac(sc, m0); 2527227364Sadrian tid = ath_tx_gettid(sc, m0); 2528227364Sadrian atid = &an->an_tid[tid]; 2529227364Sadrian 2530233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p, pri=%d, tid=%d, qos=%d, seqno=%d\n", 2531233227Sadrian __func__, bf, pri, tid, IEEE80211_QOS_HAS_SEQ(wh), SEQNO(bf->bf_state.bfs_seqno)); 2532227364Sadrian 2533227364Sadrian /* Set local packet state, used to queue packets to hardware */ 2534227364Sadrian bf->bf_state.bfs_tid = tid; 2535227364Sadrian bf->bf_state.bfs_txq = txq; 2536227364Sadrian bf->bf_state.bfs_pri = pri; 2537227364Sadrian 2538227364Sadrian /* 2539227364Sadrian * If the hardware queue isn't busy, queue it directly. 2540227364Sadrian * If the hardware queue is busy, queue it. 2541227364Sadrian * If the TID is paused or the traffic it outside BAW, software 2542227364Sadrian * queue it. 2543227364Sadrian */ 2544227364Sadrian ATH_TXQ_LOCK(txq); 2545227364Sadrian if (atid->paused) { 2546227364Sadrian /* TID is paused, queue */ 2547233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: paused\n", __func__, bf); 2548227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2549227364Sadrian } else if (ath_tx_ampdu_pending(sc, an, tid)) { 2550227364Sadrian /* AMPDU pending; queue */ 2551233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: pending\n", __func__, bf); 2552227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2553227364Sadrian /* XXX sched? */ 2554227364Sadrian } else if (ath_tx_ampdu_running(sc, an, tid)) { 2555227364Sadrian /* AMPDU running, attempt direct dispatch if possible */ 2556229949Sadrian if (txq->axq_depth < sc->sc_hwq_limit) { 2557233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2558233227Sadrian "%s: bf=%p: xmit_aggr\n", 2559233227Sadrian __func__, bf); 2560227364Sadrian ath_tx_xmit_aggr(sc, an, bf); 2561229949Sadrian } else { 2562229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 2563233227Sadrian "%s: bf=%p: ampdu; swq'ing\n", 2564233227Sadrian __func__, bf); 2565227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2566227364Sadrian ath_tx_tid_sched(sc, atid); 2567227364Sadrian } 2568227364Sadrian } else if (txq->axq_depth < sc->sc_hwq_limit) { 2569227364Sadrian /* AMPDU not running, attempt direct dispatch */ 2570233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: xmit_normal\n", __func__, bf); 2571227364Sadrian ath_tx_xmit_normal(sc, txq, bf); 2572227364Sadrian } else { 2573227364Sadrian /* Busy; queue */ 2574233227Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: swq'ing\n", __func__, bf); 2575227364Sadrian ATH_TXQ_INSERT_TAIL(atid, bf, bf_list); 2576227364Sadrian ath_tx_tid_sched(sc, atid); 2577227364Sadrian } 2578227364Sadrian ATH_TXQ_UNLOCK(txq); 2579227364Sadrian} 2580227364Sadrian 2581227364Sadrian/* 2582227364Sadrian * Do the basic frame setup stuff that's required before the frame 2583227364Sadrian * is added to a software queue. 2584227364Sadrian * 2585227364Sadrian * All frames get mostly the same treatment and it's done once. 2586227364Sadrian * Retransmits fiddle with things like the rate control setup, 2587227364Sadrian * setting the retransmit bit in the packet; doing relevant DMA/bus 2588227364Sadrian * syncing and relinking it (back) into the hardware TX queue. 2589227364Sadrian * 2590227364Sadrian * Note that this may cause the mbuf to be reallocated, so 2591227364Sadrian * m0 may not be valid. 2592227364Sadrian */ 2593227364Sadrian 2594227364Sadrian 2595227364Sadrian/* 2596227364Sadrian * Configure the per-TID node state. 2597227364Sadrian * 2598227364Sadrian * This likely belongs in if_ath_node.c but I can't think of anywhere 2599227364Sadrian * else to put it just yet. 2600227364Sadrian * 2601227364Sadrian * This sets up the SLISTs and the mutex as appropriate. 2602227364Sadrian */ 2603227364Sadrianvoid 2604227364Sadrianath_tx_tid_init(struct ath_softc *sc, struct ath_node *an) 2605227364Sadrian{ 2606227364Sadrian int i, j; 2607227364Sadrian struct ath_tid *atid; 2608227364Sadrian 2609227364Sadrian for (i = 0; i < IEEE80211_TID_SIZE; i++) { 2610227364Sadrian atid = &an->an_tid[i]; 2611227364Sadrian TAILQ_INIT(&atid->axq_q); 2612227364Sadrian atid->tid = i; 2613227364Sadrian atid->an = an; 2614227364Sadrian for (j = 0; j < ATH_TID_MAX_BUFS; j++) 2615227364Sadrian atid->tx_buf[j] = NULL; 2616227364Sadrian atid->baw_head = atid->baw_tail = 0; 2617227364Sadrian atid->paused = 0; 2618227364Sadrian atid->sched = 0; 2619227364Sadrian atid->hwq_depth = 0; 2620227364Sadrian atid->cleanup_inprogress = 0; 2621227364Sadrian if (i == IEEE80211_NONQOS_TID) 2622227364Sadrian atid->ac = WME_AC_BE; 2623227364Sadrian else 2624227364Sadrian atid->ac = TID_TO_WME_AC(i); 2625227364Sadrian } 2626227364Sadrian} 2627227364Sadrian 2628227364Sadrian/* 2629227364Sadrian * Pause the current TID. This stops packets from being transmitted 2630227364Sadrian * on it. 2631227364Sadrian * 2632227364Sadrian * Since this is also called from upper layers as well as the driver, 2633227364Sadrian * it will get the TID lock. 2634227364Sadrian */ 2635227364Sadrianstatic void 2636227364Sadrianath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid) 2637227364Sadrian{ 2638233908Sadrian 2639233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2640227364Sadrian tid->paused++; 2641227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: paused = %d\n", 2642227364Sadrian __func__, tid->paused); 2643227364Sadrian} 2644227364Sadrian 2645227364Sadrian/* 2646227364Sadrian * Unpause the current TID, and schedule it if needed. 2647227364Sadrian */ 2648227364Sadrianstatic void 2649227364Sadrianath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid) 2650227364Sadrian{ 2651227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2652227364Sadrian 2653227364Sadrian tid->paused--; 2654227364Sadrian 2655227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: unpaused = %d\n", 2656227364Sadrian __func__, tid->paused); 2657227364Sadrian 2658227364Sadrian if (tid->paused || tid->axq_depth == 0) { 2659227364Sadrian return; 2660227364Sadrian } 2661227364Sadrian 2662227364Sadrian ath_tx_tid_sched(sc, tid); 2663227364Sadrian /* Punt some frames to the hardware if needed */ 2664233673Sadrian //ath_txq_sched(sc, sc->sc_ac2q[tid->ac]); 2665233673Sadrian taskqueue_enqueue(sc->sc_tq, &sc->sc_txqtask); 2666227364Sadrian} 2667227364Sadrian 2668227364Sadrian/* 2669233908Sadrian * Suspend the queue because we need to TX a BAR. 2670233908Sadrian */ 2671233908Sadrianstatic void 2672233908Sadrianath_tx_tid_bar_suspend(struct ath_softc *sc, struct ath_tid *tid) 2673233908Sadrian{ 2674233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2675233908Sadrian 2676233908Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2677233908Sadrian "%s: tid=%p, called\n", 2678233908Sadrian __func__, 2679233908Sadrian tid); 2680233908Sadrian 2681233908Sadrian /* We shouldn't be called when bar_tx is 1 */ 2682233908Sadrian if (tid->bar_tx) { 2683233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx is 1?!\n", 2684233908Sadrian __func__); 2685233908Sadrian } 2686233908Sadrian 2687233908Sadrian /* If we've already been called, just be patient. */ 2688233908Sadrian if (tid->bar_wait) 2689233908Sadrian return; 2690233908Sadrian 2691233908Sadrian /* Wait! */ 2692233908Sadrian tid->bar_wait = 1; 2693233908Sadrian 2694233908Sadrian /* Only one pause, no matter how many frames fail */ 2695233908Sadrian ath_tx_tid_pause(sc, tid); 2696233908Sadrian} 2697233908Sadrian 2698233908Sadrian/* 2699233908Sadrian * We've finished with BAR handling - either we succeeded or 2700233908Sadrian * failed. Either way, unsuspend TX. 2701233908Sadrian */ 2702233908Sadrianstatic void 2703233908Sadrianath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid) 2704233908Sadrian{ 2705233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2706233908Sadrian 2707233908Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2708233908Sadrian "%s: tid=%p, called\n", 2709233908Sadrian __func__, 2710233908Sadrian tid); 2711233908Sadrian 2712233908Sadrian if (tid->bar_tx == 0 || tid->bar_wait == 0) { 2713233908Sadrian device_printf(sc->sc_dev, "%s: bar_tx=%d, bar_wait=%d: ?\n", 2714233908Sadrian __func__, tid->bar_tx, tid->bar_wait); 2715233908Sadrian } 2716233908Sadrian 2717233908Sadrian tid->bar_tx = tid->bar_wait = 0; 2718233908Sadrian ath_tx_tid_resume(sc, tid); 2719233908Sadrian} 2720233908Sadrian 2721233908Sadrian/* 2722233908Sadrian * Return whether we're ready to TX a BAR frame. 2723233908Sadrian * 2724233908Sadrian * Requires the TID lock be held. 2725233908Sadrian */ 2726233908Sadrianstatic int 2727233908Sadrianath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid) 2728233908Sadrian{ 2729233908Sadrian 2730233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2731233908Sadrian 2732233908Sadrian if (tid->bar_wait == 0 || tid->hwq_depth > 0) 2733233908Sadrian return (0); 2734233908Sadrian 2735233908Sadrian return (1); 2736233908Sadrian} 2737233908Sadrian 2738233908Sadrian/* 2739233908Sadrian * Check whether the current TID is ready to have a BAR 2740233908Sadrian * TXed and if so, do the TX. 2741233908Sadrian * 2742233908Sadrian * Since the TID/TXQ lock can't be held during a call to 2743233908Sadrian * ieee80211_send_bar(), we have to do the dirty thing of unlocking it, 2744233908Sadrian * sending the BAR and locking it again. 2745233908Sadrian * 2746233908Sadrian * Eventually, the code to send the BAR should be broken out 2747233908Sadrian * from this routine so the lock doesn't have to be reacquired 2748233908Sadrian * just to be immediately dropped by the caller. 2749233908Sadrian */ 2750233908Sadrianstatic void 2751233908Sadrianath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid) 2752233908Sadrian{ 2753233908Sadrian struct ieee80211_tx_ampdu *tap; 2754233908Sadrian 2755233908Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2756233908Sadrian 2757233908Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2758233908Sadrian "%s: tid=%p, called\n", 2759233908Sadrian __func__, 2760233908Sadrian tid); 2761233908Sadrian 2762233908Sadrian tap = ath_tx_get_tx_tid(tid->an, tid->tid); 2763233908Sadrian 2764233908Sadrian /* 2765233908Sadrian * This is an error condition! 2766233908Sadrian */ 2767233908Sadrian if (tid->bar_wait == 0 || tid->bar_tx == 1) { 2768233908Sadrian device_printf(sc->sc_dev, 2769233908Sadrian "%s: tid=%p, bar_tx=%d, bar_wait=%d: ?\n", 2770233908Sadrian __func__, 2771233908Sadrian tid, 2772233908Sadrian tid->bar_tx, 2773233908Sadrian tid->bar_wait); 2774233908Sadrian return; 2775233908Sadrian } 2776233908Sadrian 2777233908Sadrian /* Don't do anything if we still have pending frames */ 2778233908Sadrian if (tid->hwq_depth > 0) { 2779233908Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2780233908Sadrian "%s: tid=%p, hwq_depth=%d, waiting\n", 2781233908Sadrian __func__, 2782233908Sadrian tid, 2783233908Sadrian tid->hwq_depth); 2784233908Sadrian return; 2785233908Sadrian } 2786233908Sadrian 2787233908Sadrian /* We're now about to TX */ 2788233908Sadrian tid->bar_tx = 1; 2789233908Sadrian 2790233908Sadrian /* 2791233908Sadrian * Calculate new BAW left edge, now that all frames have either 2792233908Sadrian * succeeded or failed. 2793233908Sadrian * 2794233908Sadrian * XXX verify this is _actually_ the valid value to begin at! 2795233908Sadrian */ 2796233908Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_BAW, 2797233908Sadrian "%s: tid=%p, new BAW left edge=%d\n", 2798233908Sadrian __func__, 2799233908Sadrian tid, 2800233908Sadrian tap->txa_start); 2801233908Sadrian 2802233908Sadrian /* Try sending the BAR frame */ 2803233908Sadrian /* We can't hold the lock here! */ 2804233908Sadrian 2805233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 2806233908Sadrian if (ieee80211_send_bar(&tid->an->an_node, tap, tap->txa_start) == 0) { 2807233908Sadrian /* Success? Now we wait for notification that it's done */ 2808233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 2809233908Sadrian return; 2810233908Sadrian } 2811233908Sadrian 2812233908Sadrian /* Failure? For now, warn loudly and continue */ 2813233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 2814233908Sadrian device_printf(sc->sc_dev, "%s: tid=%p, failed to TX BAR, continue!\n", 2815233908Sadrian __func__, tid); 2816233908Sadrian ath_tx_tid_bar_unsuspend(sc, tid); 2817233908Sadrian} 2818233908Sadrian 2819233908Sadrian 2820233908Sadrian/* 2821227364Sadrian * Free any packets currently pending in the software TX queue. 2822227364Sadrian * 2823227364Sadrian * This will be called when a node is being deleted. 2824227364Sadrian * 2825227364Sadrian * It can also be called on an active node during an interface 2826227364Sadrian * reset or state transition. 2827227364Sadrian * 2828227364Sadrian * (From Linux/reference): 2829227364Sadrian * 2830227364Sadrian * TODO: For frame(s) that are in the retry state, we will reuse the 2831227364Sadrian * sequence number(s) without setting the retry bit. The 2832227364Sadrian * alternative is to give up on these and BAR the receiver's window 2833227364Sadrian * forward. 2834227364Sadrian */ 2835227364Sadrianstatic void 2836229949Sadrianath_tx_tid_drain(struct ath_softc *sc, struct ath_node *an, 2837229949Sadrian struct ath_tid *tid, ath_bufhead *bf_cq) 2838227364Sadrian{ 2839227364Sadrian struct ath_buf *bf; 2840227364Sadrian struct ieee80211_tx_ampdu *tap; 2841227364Sadrian struct ieee80211_node *ni = &an->an_node; 2842227364Sadrian int t = 0; 2843227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 2844227364Sadrian 2845227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 2846227364Sadrian 2847227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[tid->ac]); 2848227364Sadrian 2849227364Sadrian /* Walk the queue, free frames */ 2850227364Sadrian for (;;) { 2851227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 2852227364Sadrian if (bf == NULL) { 2853227364Sadrian break; 2854227364Sadrian } 2855227364Sadrian 2856227364Sadrian if (t == 0) { 2857227364Sadrian device_printf(sc->sc_dev, 2858233330Sadrian "%s: node %p: bf=%p: addbaw=%d, dobaw=%d, " 2859233480Sadrian "seqno_assign=%d, seqno_required=%d, seqno=%d, retry=%d\n", 2860233330Sadrian __func__, ni, bf, 2861233330Sadrian bf->bf_state.bfs_addedbaw, 2862233330Sadrian bf->bf_state.bfs_dobaw, 2863233330Sadrian bf->bf_state.bfs_need_seqno, 2864233330Sadrian bf->bf_state.bfs_seqno_assigned, 2865233480Sadrian SEQNO(bf->bf_state.bfs_seqno), 2866233480Sadrian bf->bf_state.bfs_retries); 2867233330Sadrian device_printf(sc->sc_dev, 2868233480Sadrian "%s: node %p: bf=%p: tid txq_depth=%d hwq_depth=%d\n", 2869233480Sadrian __func__, ni, bf, 2870233480Sadrian tid->axq_depth, 2871233480Sadrian tid->hwq_depth); 2872233480Sadrian device_printf(sc->sc_dev, 2873233227Sadrian "%s: node %p: bf=%p: tid %d: txq_depth=%d, " 2874227364Sadrian "txq_aggr_depth=%d, sched=%d, paused=%d, " 2875229949Sadrian "hwq_depth=%d, incomp=%d, baw_head=%d, " 2876229949Sadrian "baw_tail=%d txa_start=%d, ni_txseqs=%d\n", 2877233227Sadrian __func__, ni, bf, tid->tid, txq->axq_depth, 2878227364Sadrian txq->axq_aggr_depth, tid->sched, tid->paused, 2879227364Sadrian tid->hwq_depth, tid->incomp, tid->baw_head, 2880227364Sadrian tid->baw_tail, tap == NULL ? -1 : tap->txa_start, 2881227364Sadrian ni->ni_txseqs[tid->tid]); 2882229165Sadrian 2883229165Sadrian /* XXX Dump the frame, see what it is? */ 2884229165Sadrian ieee80211_dump_pkt(ni->ni_ic, 2885229165Sadrian mtod(bf->bf_m, const uint8_t *), 2886229165Sadrian bf->bf_m->m_len, 0, -1); 2887229165Sadrian 2888233897Sadrian t = 1; 2889227364Sadrian } 2890227364Sadrian 2891227364Sadrian 2892227364Sadrian /* 2893227364Sadrian * If the current TID is running AMPDU, update 2894227364Sadrian * the BAW. 2895227364Sadrian */ 2896227364Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid) && 2897227364Sadrian bf->bf_state.bfs_dobaw) { 2898227364Sadrian /* 2899227364Sadrian * Only remove the frame from the BAW if it's 2900227364Sadrian * been transmitted at least once; this means 2901227364Sadrian * the frame was in the BAW to begin with. 2902227364Sadrian */ 2903227364Sadrian if (bf->bf_state.bfs_retries > 0) { 2904227364Sadrian ath_tx_update_baw(sc, an, tid, bf); 2905227364Sadrian bf->bf_state.bfs_dobaw = 0; 2906227364Sadrian } 2907227364Sadrian /* 2908227364Sadrian * This has become a non-fatal error now 2909227364Sadrian */ 2910227364Sadrian if (! bf->bf_state.bfs_addedbaw) 2911227364Sadrian device_printf(sc->sc_dev, 2912227364Sadrian "%s: wasn't added: seqno %d\n", 2913227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 2914227364Sadrian } 2915227364Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 2916227364Sadrian TAILQ_INSERT_TAIL(bf_cq, bf, bf_list); 2917227364Sadrian } 2918227364Sadrian 2919227364Sadrian /* 2920227364Sadrian * Now that it's completed, grab the TID lock and update 2921227364Sadrian * the sequence number and BAW window. 2922227364Sadrian * Because sequence numbers have been assigned to frames 2923227364Sadrian * that haven't been sent yet, it's entirely possible 2924227364Sadrian * we'll be called with some pending frames that have not 2925227364Sadrian * been transmitted. 2926227364Sadrian * 2927227364Sadrian * The cleaner solution is to do the sequence number allocation 2928227364Sadrian * when the packet is first transmitted - and thus the "retries" 2929227364Sadrian * check above would be enough to update the BAW/seqno. 2930227364Sadrian */ 2931227364Sadrian 2932227364Sadrian /* But don't do it for non-QoS TIDs */ 2933227364Sadrian if (tap) { 2934227364Sadrian#if 0 2935227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 2936227364Sadrian "%s: node %p: TID %d: sliding BAW left edge to %d\n", 2937227364Sadrian __func__, an, tid->tid, tap->txa_start); 2938227364Sadrian#endif 2939227364Sadrian ni->ni_txseqs[tid->tid] = tap->txa_start; 2940227364Sadrian tid->baw_tail = tid->baw_head; 2941227364Sadrian } 2942227364Sadrian} 2943227364Sadrian 2944227364Sadrian/* 2945227364Sadrian * Flush all software queued packets for the given node. 2946227364Sadrian * 2947227364Sadrian * This occurs when a completion handler frees the last buffer 2948227364Sadrian * for a node, and the node is thus freed. This causes the node 2949227364Sadrian * to be cleaned up, which ends up calling ath_tx_node_flush. 2950227364Sadrian */ 2951227364Sadrianvoid 2952227364Sadrianath_tx_node_flush(struct ath_softc *sc, struct ath_node *an) 2953227364Sadrian{ 2954227364Sadrian int tid; 2955227364Sadrian ath_bufhead bf_cq; 2956227364Sadrian struct ath_buf *bf; 2957227364Sadrian 2958227364Sadrian TAILQ_INIT(&bf_cq); 2959227364Sadrian 2960227364Sadrian for (tid = 0; tid < IEEE80211_TID_SIZE; tid++) { 2961227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 2962227364Sadrian struct ath_txq *txq = sc->sc_ac2q[atid->ac]; 2963227364Sadrian 2964227364Sadrian /* Remove this tid from the list of active tids */ 2965227364Sadrian ATH_TXQ_LOCK(txq); 2966227364Sadrian ath_tx_tid_unsched(sc, atid); 2967227364Sadrian 2968227364Sadrian /* Free packets */ 2969227364Sadrian ath_tx_tid_drain(sc, an, atid, &bf_cq); 2970227364Sadrian ATH_TXQ_UNLOCK(txq); 2971227364Sadrian } 2972227364Sadrian 2973227364Sadrian /* Handle completed frames */ 2974227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 2975227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 2976227364Sadrian ath_tx_default_comp(sc, bf, 0); 2977227364Sadrian } 2978227364Sadrian} 2979227364Sadrian 2980227364Sadrian/* 2981227364Sadrian * Drain all the software TXQs currently with traffic queued. 2982227364Sadrian */ 2983227364Sadrianvoid 2984227364Sadrianath_tx_txq_drain(struct ath_softc *sc, struct ath_txq *txq) 2985227364Sadrian{ 2986227364Sadrian struct ath_tid *tid; 2987227364Sadrian ath_bufhead bf_cq; 2988227364Sadrian struct ath_buf *bf; 2989227364Sadrian 2990227364Sadrian TAILQ_INIT(&bf_cq); 2991227364Sadrian ATH_TXQ_LOCK(txq); 2992227364Sadrian 2993227364Sadrian /* 2994227364Sadrian * Iterate over all active tids for the given txq, 2995227364Sadrian * flushing and unsched'ing them 2996227364Sadrian */ 2997227364Sadrian while (! TAILQ_EMPTY(&txq->axq_tidq)) { 2998227364Sadrian tid = TAILQ_FIRST(&txq->axq_tidq); 2999227364Sadrian ath_tx_tid_drain(sc, tid->an, tid, &bf_cq); 3000227364Sadrian ath_tx_tid_unsched(sc, tid); 3001227364Sadrian } 3002227364Sadrian 3003227364Sadrian ATH_TXQ_UNLOCK(txq); 3004227364Sadrian 3005227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3006227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3007227364Sadrian ath_tx_default_comp(sc, bf, 0); 3008227364Sadrian } 3009227364Sadrian} 3010227364Sadrian 3011227364Sadrian/* 3012227364Sadrian * Handle completion of non-aggregate session frames. 3013227364Sadrian */ 3014227364Sadrianvoid 3015227364Sadrianath_tx_normal_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3016227364Sadrian{ 3017227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3018227364Sadrian struct ath_node *an = ATH_NODE(ni); 3019227364Sadrian int tid = bf->bf_state.bfs_tid; 3020227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3021227364Sadrian struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3022227364Sadrian 3023227364Sadrian /* The TID state is protected behind the TXQ lock */ 3024227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3025227364Sadrian 3026227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: bf=%p: fail=%d, hwq_depth now %d\n", 3027227364Sadrian __func__, bf, fail, atid->hwq_depth - 1); 3028227364Sadrian 3029227364Sadrian atid->hwq_depth--; 3030227364Sadrian if (atid->hwq_depth < 0) 3031227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3032227364Sadrian __func__, atid->hwq_depth); 3033227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3034227364Sadrian 3035227364Sadrian /* 3036227364Sadrian * punt to rate control if we're not being cleaned up 3037227364Sadrian * during a hw queue drain and the frame wanted an ACK. 3038227364Sadrian */ 3039233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3040227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3041227364Sadrian ts, bf->bf_state.bfs_pktlen, 3042227364Sadrian 1, (ts->ts_status == 0) ? 0 : 1); 3043227364Sadrian 3044227364Sadrian ath_tx_default_comp(sc, bf, fail); 3045227364Sadrian} 3046227364Sadrian 3047227364Sadrian/* 3048227364Sadrian * Handle cleanup of aggregate session packets that aren't 3049227364Sadrian * an A-MPDU. 3050227364Sadrian * 3051227364Sadrian * There's no need to update the BAW here - the session is being 3052227364Sadrian * torn down. 3053227364Sadrian */ 3054227364Sadrianstatic void 3055227364Sadrianath_tx_comp_cleanup_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3056227364Sadrian{ 3057227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3058227364Sadrian struct ath_node *an = ATH_NODE(ni); 3059227364Sadrian int tid = bf->bf_state.bfs_tid; 3060227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3061227364Sadrian 3062227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: TID %d: incomp=%d\n", 3063227364Sadrian __func__, tid, atid->incomp); 3064227364Sadrian 3065227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3066227364Sadrian atid->incomp--; 3067227364Sadrian if (atid->incomp == 0) { 3068227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3069227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3070227364Sadrian __func__, tid); 3071227364Sadrian atid->cleanup_inprogress = 0; 3072227364Sadrian ath_tx_tid_resume(sc, atid); 3073227364Sadrian } 3074227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3075227364Sadrian 3076227364Sadrian ath_tx_default_comp(sc, bf, 0); 3077227364Sadrian} 3078227364Sadrian 3079227364Sadrian/* 3080227364Sadrian * Performs transmit side cleanup when TID changes from aggregated to 3081227364Sadrian * unaggregated. 3082227364Sadrian * 3083227364Sadrian * - Discard all retry frames from the s/w queue. 3084227364Sadrian * - Fix the tx completion function for all buffers in s/w queue. 3085227364Sadrian * - Count the number of unacked frames, and let transmit completion 3086227364Sadrian * handle it later. 3087227364Sadrian * 3088227364Sadrian * The caller is responsible for pausing the TID. 3089227364Sadrian */ 3090227364Sadrianstatic void 3091227364Sadrianath_tx_cleanup(struct ath_softc *sc, struct ath_node *an, int tid) 3092227364Sadrian{ 3093227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3094227364Sadrian struct ieee80211_tx_ampdu *tap; 3095227364Sadrian struct ath_buf *bf, *bf_next; 3096227364Sadrian ath_bufhead bf_cq; 3097227364Sadrian 3098227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3099227364Sadrian "%s: TID %d: called\n", __func__, tid); 3100227364Sadrian 3101227364Sadrian TAILQ_INIT(&bf_cq); 3102227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3103227364Sadrian 3104227364Sadrian /* 3105227364Sadrian * Update the frames in the software TX queue: 3106227364Sadrian * 3107227364Sadrian * + Discard retry frames in the queue 3108227364Sadrian * + Fix the completion function to be non-aggregate 3109227364Sadrian */ 3110227364Sadrian bf = TAILQ_FIRST(&atid->axq_q); 3111227364Sadrian while (bf) { 3112227364Sadrian if (bf->bf_state.bfs_isretried) { 3113227364Sadrian bf_next = TAILQ_NEXT(bf, bf_list); 3114227364Sadrian TAILQ_REMOVE(&atid->axq_q, bf, bf_list); 3115227364Sadrian atid->axq_depth--; 3116227364Sadrian if (bf->bf_state.bfs_dobaw) { 3117227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3118227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3119227364Sadrian device_printf(sc->sc_dev, 3120227364Sadrian "%s: wasn't added: seqno %d\n", 3121229949Sadrian __func__, 3122229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3123227364Sadrian } 3124227364Sadrian bf->bf_state.bfs_dobaw = 0; 3125227364Sadrian /* 3126227364Sadrian * Call the default completion handler with "fail" just 3127227364Sadrian * so upper levels are suitably notified about this. 3128227364Sadrian */ 3129227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3130227364Sadrian bf = bf_next; 3131227364Sadrian continue; 3132227364Sadrian } 3133227364Sadrian /* Give these the default completion handler */ 3134227364Sadrian bf->bf_comp = ath_tx_normal_comp; 3135227364Sadrian bf = TAILQ_NEXT(bf, bf_list); 3136227364Sadrian } 3137227364Sadrian 3138227364Sadrian /* The caller is required to pause the TID */ 3139227364Sadrian#if 0 3140227364Sadrian /* Pause the TID */ 3141227364Sadrian ath_tx_tid_pause(sc, atid); 3142227364Sadrian#endif 3143227364Sadrian 3144227364Sadrian /* 3145227364Sadrian * Calculate what hardware-queued frames exist based 3146227364Sadrian * on the current BAW size. Ie, what frames have been 3147227364Sadrian * added to the TX hardware queue for this TID but 3148227364Sadrian * not yet ACKed. 3149227364Sadrian */ 3150227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3151227364Sadrian /* Need the lock - fiddling with BAW */ 3152227364Sadrian while (atid->baw_head != atid->baw_tail) { 3153227364Sadrian if (atid->tx_buf[atid->baw_head]) { 3154227364Sadrian atid->incomp++; 3155227364Sadrian atid->cleanup_inprogress = 1; 3156227364Sadrian atid->tx_buf[atid->baw_head] = NULL; 3157227364Sadrian } 3158227364Sadrian INCR(atid->baw_head, ATH_TID_MAX_BUFS); 3159227364Sadrian INCR(tap->txa_start, IEEE80211_SEQ_RANGE); 3160227364Sadrian } 3161227364Sadrian 3162227364Sadrian /* 3163227364Sadrian * If cleanup is required, defer TID scheduling 3164227364Sadrian * until all the HW queued packets have been 3165227364Sadrian * sent. 3166227364Sadrian */ 3167227364Sadrian if (! atid->cleanup_inprogress) 3168227364Sadrian ath_tx_tid_resume(sc, atid); 3169227364Sadrian 3170227364Sadrian if (atid->cleanup_inprogress) 3171227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3172227364Sadrian "%s: TID %d: cleanup needed: %d packets\n", 3173227364Sadrian __func__, tid, atid->incomp); 3174227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3175227364Sadrian 3176227364Sadrian /* Handle completing frames and fail them */ 3177227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3178227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3179227364Sadrian ath_tx_default_comp(sc, bf, 1); 3180227364Sadrian } 3181227364Sadrian} 3182227364Sadrian 3183227364Sadrianstatic void 3184227364Sadrianath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) 3185227364Sadrian{ 3186227364Sadrian struct ieee80211_frame *wh; 3187227364Sadrian 3188227364Sadrian wh = mtod(bf->bf_m, struct ieee80211_frame *); 3189227364Sadrian /* Only update/resync if needed */ 3190227364Sadrian if (bf->bf_state.bfs_isretried == 0) { 3191227364Sadrian wh->i_fc[1] |= IEEE80211_FC1_RETRY; 3192227364Sadrian bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, 3193227364Sadrian BUS_DMASYNC_PREWRITE); 3194227364Sadrian } 3195227364Sadrian sc->sc_stats.ast_tx_swretries++; 3196227364Sadrian bf->bf_state.bfs_isretried = 1; 3197227364Sadrian bf->bf_state.bfs_retries ++; 3198227364Sadrian} 3199227364Sadrian 3200227364Sadrianstatic struct ath_buf * 3201227398Sadrianath_tx_retry_clone(struct ath_softc *sc, struct ath_node *an, 3202227398Sadrian struct ath_tid *tid, struct ath_buf *bf) 3203227364Sadrian{ 3204227364Sadrian struct ath_buf *nbf; 3205227364Sadrian int error; 3206227364Sadrian 3207227364Sadrian nbf = ath_buf_clone(sc, bf); 3208227364Sadrian 3209227364Sadrian#if 0 3210227364Sadrian device_printf(sc->sc_dev, "%s: ATH_BUF_BUSY; cloning\n", 3211227364Sadrian __func__); 3212227364Sadrian#endif 3213227364Sadrian 3214227364Sadrian if (nbf == NULL) { 3215227364Sadrian /* Failed to clone */ 3216227364Sadrian device_printf(sc->sc_dev, 3217227364Sadrian "%s: failed to clone a busy buffer\n", 3218227364Sadrian __func__); 3219227364Sadrian return NULL; 3220227364Sadrian } 3221227364Sadrian 3222227364Sadrian /* Setup the dma for the new buffer */ 3223227364Sadrian error = ath_tx_dmasetup(sc, nbf, nbf->bf_m); 3224227364Sadrian if (error != 0) { 3225227364Sadrian device_printf(sc->sc_dev, 3226227364Sadrian "%s: failed to setup dma for clone\n", 3227227364Sadrian __func__); 3228227364Sadrian /* 3229227364Sadrian * Put this at the head of the list, not tail; 3230227364Sadrian * that way it doesn't interfere with the 3231227364Sadrian * busy buffer logic (which uses the tail of 3232227364Sadrian * the list.) 3233227364Sadrian */ 3234227364Sadrian ATH_TXBUF_LOCK(sc); 3235227364Sadrian TAILQ_INSERT_HEAD(&sc->sc_txbuf, nbf, bf_list); 3236227364Sadrian ATH_TXBUF_UNLOCK(sc); 3237227364Sadrian return NULL; 3238227364Sadrian } 3239227364Sadrian 3240227398Sadrian /* Update BAW if required, before we free the original buf */ 3241227398Sadrian if (bf->bf_state.bfs_dobaw) 3242227398Sadrian ath_tx_switch_baw_buf(sc, an, tid, bf, nbf); 3243227398Sadrian 3244227364Sadrian /* Free current buffer; return the older buffer */ 3245227364Sadrian bf->bf_m = NULL; 3246227364Sadrian bf->bf_node = NULL; 3247227364Sadrian ath_freebuf(sc, bf); 3248227364Sadrian return nbf; 3249227364Sadrian} 3250227364Sadrian 3251227364Sadrian/* 3252227364Sadrian * Handle retrying an unaggregate frame in an aggregate 3253227364Sadrian * session. 3254227364Sadrian * 3255227364Sadrian * If too many retries occur, pause the TID, wait for 3256227364Sadrian * any further retransmits (as there's no reason why 3257227364Sadrian * non-aggregate frames in an aggregate session are 3258227364Sadrian * transmitted in-order; they just have to be in-BAW) 3259227364Sadrian * and then queue a BAR. 3260227364Sadrian */ 3261227364Sadrianstatic void 3262227364Sadrianath_tx_aggr_retry_unaggr(struct ath_softc *sc, struct ath_buf *bf) 3263227364Sadrian{ 3264227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3265227364Sadrian struct ath_node *an = ATH_NODE(ni); 3266227364Sadrian int tid = bf->bf_state.bfs_tid; 3267227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3268227364Sadrian struct ieee80211_tx_ampdu *tap; 3269227364Sadrian 3270227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3271227364Sadrian 3272227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3273227364Sadrian 3274227364Sadrian /* 3275227364Sadrian * If the buffer is marked as busy, we can't directly 3276227364Sadrian * reuse it. Instead, try to clone the buffer. 3277227364Sadrian * If the clone is successful, recycle the old buffer. 3278227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3279227364Sadrian * to force the next bit of code to free the buffer 3280227364Sadrian * for us. 3281227364Sadrian */ 3282227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3283227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3284227364Sadrian struct ath_buf *nbf; 3285227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3286227364Sadrian if (nbf) 3287227364Sadrian /* bf has been freed at this point */ 3288227364Sadrian bf = nbf; 3289227364Sadrian else 3290227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3291227364Sadrian } 3292227364Sadrian 3293227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3294227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3295227364Sadrian "%s: exceeded retries; seqno %d\n", 3296227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3297227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3298227364Sadrian 3299227364Sadrian /* Update BAW anyway */ 3300227364Sadrian if (bf->bf_state.bfs_dobaw) { 3301227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3302227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3303227364Sadrian device_printf(sc->sc_dev, 3304227364Sadrian "%s: wasn't added: seqno %d\n", 3305227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3306227364Sadrian } 3307227364Sadrian bf->bf_state.bfs_dobaw = 0; 3308227364Sadrian 3309233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3310233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 3311227364Sadrian 3312233908Sadrian /* Send the BAR if there are no other frames waiting */ 3313233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3314233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3315227364Sadrian 3316233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3317227364Sadrian 3318227364Sadrian /* Free buffer, bf is free after this call */ 3319227364Sadrian ath_tx_default_comp(sc, bf, 0); 3320227364Sadrian return; 3321227364Sadrian } 3322227364Sadrian 3323227364Sadrian /* 3324227364Sadrian * This increments the retry counter as well as 3325227364Sadrian * sets the retry flag in the ath_buf and packet 3326227364Sadrian * body. 3327227364Sadrian */ 3328227364Sadrian ath_tx_set_retry(sc, bf); 3329227364Sadrian 3330227364Sadrian /* 3331227364Sadrian * Insert this at the head of the queue, so it's 3332227364Sadrian * retried before any current/subsequent frames. 3333227364Sadrian */ 3334227364Sadrian ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3335227364Sadrian ath_tx_tid_sched(sc, atid); 3336233908Sadrian /* Send the BAR if there are no other frames waiting */ 3337233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3338233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3339227364Sadrian 3340227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3341227364Sadrian} 3342227364Sadrian 3343227364Sadrian/* 3344227364Sadrian * Common code for aggregate excessive retry/subframe retry. 3345227364Sadrian * If retrying, queues buffers to bf_q. If not, frees the 3346227364Sadrian * buffers. 3347227364Sadrian * 3348227364Sadrian * XXX should unify this with ath_tx_aggr_retry_unaggr() 3349227364Sadrian */ 3350227364Sadrianstatic int 3351227364Sadrianath_tx_retry_subframe(struct ath_softc *sc, struct ath_buf *bf, 3352227364Sadrian ath_bufhead *bf_q) 3353227364Sadrian{ 3354227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3355227364Sadrian struct ath_node *an = ATH_NODE(ni); 3356227364Sadrian int tid = bf->bf_state.bfs_tid; 3357227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3358227364Sadrian 3359227364Sadrian ATH_TXQ_LOCK_ASSERT(sc->sc_ac2q[atid->ac]); 3360227364Sadrian 3361227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 3362227364Sadrian ath_hal_set11nburstduration(sc->sc_ah, bf->bf_desc, 0); 3363227364Sadrian /* ath_hal_set11n_virtualmorefrag(sc->sc_ah, bf->bf_desc, 0); */ 3364227364Sadrian 3365227364Sadrian /* 3366227364Sadrian * If the buffer is marked as busy, we can't directly 3367227364Sadrian * reuse it. Instead, try to clone the buffer. 3368227364Sadrian * If the clone is successful, recycle the old buffer. 3369227364Sadrian * If the clone is unsuccessful, set bfs_retries to max 3370227364Sadrian * to force the next bit of code to free the buffer 3371227364Sadrian * for us. 3372227364Sadrian */ 3373227364Sadrian if ((bf->bf_state.bfs_retries < SWMAX_RETRIES) && 3374227364Sadrian (bf->bf_flags & ATH_BUF_BUSY)) { 3375227364Sadrian struct ath_buf *nbf; 3376227398Sadrian nbf = ath_tx_retry_clone(sc, an, atid, bf); 3377227364Sadrian if (nbf) 3378227364Sadrian /* bf has been freed at this point */ 3379227364Sadrian bf = nbf; 3380227364Sadrian else 3381227364Sadrian bf->bf_state.bfs_retries = SWMAX_RETRIES + 1; 3382227364Sadrian } 3383227364Sadrian 3384227364Sadrian if (bf->bf_state.bfs_retries >= SWMAX_RETRIES) { 3385227364Sadrian sc->sc_stats.ast_tx_swretrymax++; 3386227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_RETRIES, 3387227364Sadrian "%s: max retries: seqno %d\n", 3388227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3389227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3390227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3391227364Sadrian device_printf(sc->sc_dev, 3392227364Sadrian "%s: wasn't added: seqno %d\n", 3393227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3394227364Sadrian bf->bf_state.bfs_dobaw = 0; 3395227364Sadrian return 1; 3396227364Sadrian } 3397227364Sadrian 3398227364Sadrian ath_tx_set_retry(sc, bf); 3399227364Sadrian bf->bf_next = NULL; /* Just to make sure */ 3400227364Sadrian 3401227364Sadrian TAILQ_INSERT_TAIL(bf_q, bf, bf_list); 3402227364Sadrian return 0; 3403227364Sadrian} 3404227364Sadrian 3405227364Sadrian/* 3406227364Sadrian * error pkt completion for an aggregate destination 3407227364Sadrian */ 3408227364Sadrianstatic void 3409227364Sadrianath_tx_comp_aggr_error(struct ath_softc *sc, struct ath_buf *bf_first, 3410227364Sadrian struct ath_tid *tid) 3411227364Sadrian{ 3412227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3413227364Sadrian struct ath_node *an = ATH_NODE(ni); 3414227364Sadrian struct ath_buf *bf_next, *bf; 3415227364Sadrian ath_bufhead bf_q; 3416227364Sadrian int drops = 0; 3417227364Sadrian struct ieee80211_tx_ampdu *tap; 3418227364Sadrian ath_bufhead bf_cq; 3419227364Sadrian 3420227364Sadrian TAILQ_INIT(&bf_q); 3421227364Sadrian TAILQ_INIT(&bf_cq); 3422227364Sadrian 3423227364Sadrian /* 3424227364Sadrian * Update rate control - all frames have failed. 3425227364Sadrian * 3426227364Sadrian * XXX use the length in the first frame in the series; 3427227364Sadrian * XXX just so things are consistent for now. 3428227364Sadrian */ 3429227364Sadrian ath_tx_update_ratectrl(sc, ni, bf_first->bf_state.bfs_rc, 3430227364Sadrian &bf_first->bf_status.ds_txstat, 3431227364Sadrian bf_first->bf_state.bfs_pktlen, 3432227364Sadrian bf_first->bf_state.bfs_nframes, bf_first->bf_state.bfs_nframes); 3433227364Sadrian 3434227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[tid->ac]); 3435227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3436227868Sadrian sc->sc_stats.ast_tx_aggr_failall++; 3437227364Sadrian 3438227364Sadrian /* Retry all subframes */ 3439227364Sadrian bf = bf_first; 3440227364Sadrian while (bf) { 3441227364Sadrian bf_next = bf->bf_next; 3442227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 3443227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 3444227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 3445227364Sadrian drops++; 3446227364Sadrian bf->bf_next = NULL; 3447227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3448227364Sadrian } 3449227364Sadrian bf = bf_next; 3450227364Sadrian } 3451227364Sadrian 3452227364Sadrian /* Prepend all frames to the beginning of the queue */ 3453227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 3454227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 3455227364Sadrian ATH_TXQ_INSERT_HEAD(tid, bf, bf_list); 3456227364Sadrian } 3457227364Sadrian 3458234725Sadrian /* 3459234725Sadrian * Schedule the TID to be re-tried. 3460234725Sadrian */ 3461227364Sadrian ath_tx_tid_sched(sc, tid); 3462227364Sadrian 3463227364Sadrian /* 3464227364Sadrian * send bar if we dropped any frames 3465227364Sadrian * 3466227364Sadrian * Keep the txq lock held for now, as we need to ensure 3467227364Sadrian * that ni_txseqs[] is consistent (as it's being updated 3468227364Sadrian * in the ifnet TX context or raw TX context.) 3469227364Sadrian */ 3470227364Sadrian if (drops) { 3471233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3472233908Sadrian ath_tx_tid_bar_suspend(sc, tid); 3473227364Sadrian } 3474227364Sadrian 3475233908Sadrian /* 3476233908Sadrian * Send BAR if required 3477233908Sadrian */ 3478233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, tid)) 3479233908Sadrian ath_tx_tid_bar_tx(sc, tid); 3480233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[tid->ac]); 3481233908Sadrian 3482227364Sadrian /* Complete frames which errored out */ 3483227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3484227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3485227364Sadrian ath_tx_default_comp(sc, bf, 0); 3486227364Sadrian } 3487227364Sadrian} 3488227364Sadrian 3489227364Sadrian/* 3490227364Sadrian * Handle clean-up of packets from an aggregate list. 3491227364Sadrian * 3492227364Sadrian * There's no need to update the BAW here - the session is being 3493227364Sadrian * torn down. 3494227364Sadrian */ 3495227364Sadrianstatic void 3496227364Sadrianath_tx_comp_cleanup_aggr(struct ath_softc *sc, struct ath_buf *bf_first) 3497227364Sadrian{ 3498227364Sadrian struct ath_buf *bf, *bf_next; 3499227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3500227364Sadrian struct ath_node *an = ATH_NODE(ni); 3501227364Sadrian int tid = bf_first->bf_state.bfs_tid; 3502227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3503227364Sadrian 3504227364Sadrian bf = bf_first; 3505227364Sadrian 3506227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3507227364Sadrian 3508227364Sadrian /* update incomp */ 3509227364Sadrian while (bf) { 3510227364Sadrian atid->incomp--; 3511227364Sadrian bf = bf->bf_next; 3512227364Sadrian } 3513227364Sadrian 3514227364Sadrian if (atid->incomp == 0) { 3515227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 3516227364Sadrian "%s: TID %d: cleaned up! resume!\n", 3517227364Sadrian __func__, tid); 3518227364Sadrian atid->cleanup_inprogress = 0; 3519227364Sadrian ath_tx_tid_resume(sc, atid); 3520227364Sadrian } 3521233908Sadrian 3522233908Sadrian /* Send BAR if required */ 3523233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3524233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3525227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3526227364Sadrian 3527227364Sadrian /* Handle frame completion */ 3528227364Sadrian while (bf) { 3529227364Sadrian bf_next = bf->bf_next; 3530227364Sadrian ath_tx_default_comp(sc, bf, 1); 3531227364Sadrian bf = bf_next; 3532227364Sadrian } 3533227364Sadrian} 3534227364Sadrian 3535227364Sadrian/* 3536227364Sadrian * Handle completion of an set of aggregate frames. 3537227364Sadrian * 3538227364Sadrian * XXX for now, simply complete each sub-frame. 3539227364Sadrian * 3540227364Sadrian * Note: the completion handler is the last descriptor in the aggregate, 3541227364Sadrian * not the last descriptor in the first frame. 3542227364Sadrian */ 3543227364Sadrianstatic void 3544229949Sadrianath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first, 3545229949Sadrian int fail) 3546227364Sadrian{ 3547227364Sadrian //struct ath_desc *ds = bf->bf_lastds; 3548227364Sadrian struct ieee80211_node *ni = bf_first->bf_node; 3549227364Sadrian struct ath_node *an = ATH_NODE(ni); 3550227364Sadrian int tid = bf_first->bf_state.bfs_tid; 3551227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3552227364Sadrian struct ath_tx_status ts; 3553227364Sadrian struct ieee80211_tx_ampdu *tap; 3554227364Sadrian ath_bufhead bf_q; 3555227364Sadrian ath_bufhead bf_cq; 3556227364Sadrian int seq_st, tx_ok; 3557227364Sadrian int hasba, isaggr; 3558227364Sadrian uint32_t ba[2]; 3559227364Sadrian struct ath_buf *bf, *bf_next; 3560227364Sadrian int ba_index; 3561227364Sadrian int drops = 0; 3562227364Sadrian int nframes = 0, nbad = 0, nf; 3563227364Sadrian int pktlen; 3564227364Sadrian /* XXX there's too much on the stack? */ 3565227364Sadrian struct ath_rc_series rc[4]; 3566227364Sadrian int txseq; 3567227364Sadrian 3568227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: called; hwq_depth=%d\n", 3569227364Sadrian __func__, atid->hwq_depth); 3570227364Sadrian 3571227364Sadrian /* The TID state is kept behind the TXQ lock */ 3572227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3573227364Sadrian 3574227364Sadrian atid->hwq_depth--; 3575227364Sadrian if (atid->hwq_depth < 0) 3576227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3577227364Sadrian __func__, atid->hwq_depth); 3578227364Sadrian 3579227364Sadrian /* 3580227364Sadrian * Punt cleanup to the relevant function, not our problem now 3581227364Sadrian */ 3582227364Sadrian if (atid->cleanup_inprogress) { 3583227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3584227364Sadrian ath_tx_comp_cleanup_aggr(sc, bf_first); 3585227364Sadrian return; 3586227364Sadrian } 3587227364Sadrian 3588227364Sadrian /* 3589227364Sadrian * Take a copy; this may be needed -after- bf_first 3590227364Sadrian * has been completed and freed. 3591227364Sadrian */ 3592227364Sadrian ts = bf_first->bf_status.ds_txstat; 3593227364Sadrian /* 3594227364Sadrian * XXX for now, use the first frame in the aggregate for 3595227364Sadrian * XXX rate control completion; it's at least consistent. 3596227364Sadrian */ 3597227364Sadrian pktlen = bf_first->bf_state.bfs_pktlen; 3598227364Sadrian 3599227364Sadrian /* 3600227364Sadrian * handle errors first 3601227364Sadrian */ 3602227364Sadrian if (ts.ts_status & HAL_TXERR_XRETRY) { 3603227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3604227364Sadrian ath_tx_comp_aggr_error(sc, bf_first, atid); 3605227364Sadrian return; 3606227364Sadrian } 3607227364Sadrian 3608227364Sadrian TAILQ_INIT(&bf_q); 3609227364Sadrian TAILQ_INIT(&bf_cq); 3610227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 3611227364Sadrian 3612227364Sadrian /* 3613227364Sadrian * extract starting sequence and block-ack bitmap 3614227364Sadrian */ 3615227364Sadrian /* XXX endian-ness of seq_st, ba? */ 3616227364Sadrian seq_st = ts.ts_seqnum; 3617227364Sadrian hasba = !! (ts.ts_flags & HAL_TX_BA); 3618227364Sadrian tx_ok = (ts.ts_status == 0); 3619227364Sadrian isaggr = bf_first->bf_state.bfs_aggr; 3620227364Sadrian ba[0] = ts.ts_ba_low; 3621227364Sadrian ba[1] = ts.ts_ba_high; 3622227364Sadrian 3623227364Sadrian /* 3624227364Sadrian * Copy the TX completion status and the rate control 3625227364Sadrian * series from the first descriptor, as it may be freed 3626227364Sadrian * before the rate control code can get its grubby fingers 3627227364Sadrian * into things. 3628227364Sadrian */ 3629227364Sadrian memcpy(rc, bf_first->bf_state.bfs_rc, sizeof(rc)); 3630227364Sadrian 3631227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 3632229949Sadrian "%s: txa_start=%d, tx_ok=%d, status=%.8x, flags=%.8x, " 3633229949Sadrian "isaggr=%d, seq_st=%d, hasba=%d, ba=%.8x, %.8x\n", 3634227364Sadrian __func__, tap->txa_start, tx_ok, ts.ts_status, ts.ts_flags, 3635227364Sadrian isaggr, seq_st, hasba, ba[0], ba[1]); 3636227364Sadrian 3637227364Sadrian /* Occasionally, the MAC sends a tx status for the wrong TID. */ 3638227364Sadrian if (tid != ts.ts_tid) { 3639227364Sadrian device_printf(sc->sc_dev, "%s: tid %d != hw tid %d\n", 3640227364Sadrian __func__, tid, ts.ts_tid); 3641227364Sadrian tx_ok = 0; 3642227364Sadrian } 3643227364Sadrian 3644227364Sadrian /* AR5416 BA bug; this requires an interface reset */ 3645227364Sadrian if (isaggr && tx_ok && (! hasba)) { 3646227364Sadrian device_printf(sc->sc_dev, 3647229949Sadrian "%s: AR5416 bug: hasba=%d; txok=%d, isaggr=%d, " 3648229949Sadrian "seq_st=%d\n", 3649227364Sadrian __func__, hasba, tx_ok, isaggr, seq_st); 3650227364Sadrian /* XXX TODO: schedule an interface reset */ 3651227364Sadrian } 3652227364Sadrian 3653227364Sadrian /* 3654227364Sadrian * Walk the list of frames, figure out which ones were correctly 3655227364Sadrian * sent and which weren't. 3656227364Sadrian */ 3657227364Sadrian bf = bf_first; 3658227364Sadrian nf = bf_first->bf_state.bfs_nframes; 3659227364Sadrian 3660227364Sadrian /* bf_first is going to be invalid once this list is walked */ 3661227364Sadrian bf_first = NULL; 3662227364Sadrian 3663227364Sadrian /* 3664227364Sadrian * Walk the list of completed frames and determine 3665227364Sadrian * which need to be completed and which need to be 3666227364Sadrian * retransmitted. 3667227364Sadrian * 3668227364Sadrian * For completed frames, the completion functions need 3669227364Sadrian * to be called at the end of this function as the last 3670227364Sadrian * node reference may free the node. 3671227364Sadrian * 3672227364Sadrian * Finally, since the TXQ lock can't be held during the 3673227364Sadrian * completion callback (to avoid lock recursion), 3674227364Sadrian * the completion calls have to be done outside of the 3675227364Sadrian * lock. 3676227364Sadrian */ 3677227364Sadrian while (bf) { 3678227364Sadrian nframes++; 3679229949Sadrian ba_index = ATH_BA_INDEX(seq_st, 3680229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3681227364Sadrian bf_next = bf->bf_next; 3682227364Sadrian bf->bf_next = NULL; /* Remove it from the aggr list */ 3683227364Sadrian 3684227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 3685227364Sadrian "%s: checking bf=%p seqno=%d; ack=%d\n", 3686227364Sadrian __func__, bf, SEQNO(bf->bf_state.bfs_seqno), 3687227364Sadrian ATH_BA_ISSET(ba, ba_index)); 3688227364Sadrian 3689227364Sadrian if (tx_ok && ATH_BA_ISSET(ba, ba_index)) { 3690227868Sadrian sc->sc_stats.ast_tx_aggr_ok++; 3691227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3692227364Sadrian bf->bf_state.bfs_dobaw = 0; 3693227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3694227364Sadrian device_printf(sc->sc_dev, 3695227364Sadrian "%s: wasn't added: seqno %d\n", 3696227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3697227364Sadrian bf->bf_next = NULL; 3698227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3699227364Sadrian } else { 3700227868Sadrian sc->sc_stats.ast_tx_aggr_fail++; 3701227364Sadrian if (ath_tx_retry_subframe(sc, bf, &bf_q)) { 3702227364Sadrian drops++; 3703227364Sadrian bf->bf_next = NULL; 3704227364Sadrian TAILQ_INSERT_TAIL(&bf_cq, bf, bf_list); 3705227364Sadrian } 3706227364Sadrian nbad++; 3707227364Sadrian } 3708227364Sadrian bf = bf_next; 3709227364Sadrian } 3710227364Sadrian 3711227364Sadrian /* 3712227364Sadrian * Now that the BAW updates have been done, unlock 3713227364Sadrian * 3714227364Sadrian * txseq is grabbed before the lock is released so we 3715227364Sadrian * have a consistent view of what -was- in the BAW. 3716227364Sadrian * Anything after this point will not yet have been 3717227364Sadrian * TXed. 3718227364Sadrian */ 3719227364Sadrian txseq = tap->txa_start; 3720227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3721227364Sadrian 3722227364Sadrian if (nframes != nf) 3723227364Sadrian device_printf(sc->sc_dev, 3724227364Sadrian "%s: num frames seen=%d; bf nframes=%d\n", 3725227364Sadrian __func__, nframes, nf); 3726227364Sadrian 3727227364Sadrian /* 3728227364Sadrian * Now we know how many frames were bad, call the rate 3729227364Sadrian * control code. 3730227364Sadrian */ 3731227364Sadrian if (fail == 0) 3732229949Sadrian ath_tx_update_ratectrl(sc, ni, rc, &ts, pktlen, nframes, 3733229949Sadrian nbad); 3734227364Sadrian 3735227364Sadrian /* 3736227364Sadrian * send bar if we dropped any frames 3737227364Sadrian */ 3738227364Sadrian if (drops) { 3739233908Sadrian /* Suspend the TX queue and get ready to send the BAR */ 3740233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3741233908Sadrian ath_tx_tid_bar_suspend(sc, atid); 3742233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3743227364Sadrian } 3744227364Sadrian 3745234725Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 3746234725Sadrian "%s: txa_start now %d\n", __func__, tap->txa_start); 3747234725Sadrian 3748234725Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3749234725Sadrian 3750227364Sadrian /* Prepend all frames to the beginning of the queue */ 3751227364Sadrian while ((bf = TAILQ_LAST(&bf_q, ath_bufhead_s)) != NULL) { 3752227364Sadrian TAILQ_REMOVE(&bf_q, bf, bf_list); 3753227364Sadrian ATH_TXQ_INSERT_HEAD(atid, bf, bf_list); 3754227364Sadrian } 3755234725Sadrian 3756234725Sadrian /* 3757234725Sadrian * Reschedule to grab some further frames. 3758234725Sadrian */ 3759227364Sadrian ath_tx_tid_sched(sc, atid); 3760227364Sadrian 3761233908Sadrian /* 3762233908Sadrian * Send BAR if required 3763233908Sadrian */ 3764233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3765233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3766234725Sadrian 3767233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3768233908Sadrian 3769227364Sadrian /* Do deferred completion */ 3770227364Sadrian while ((bf = TAILQ_FIRST(&bf_cq)) != NULL) { 3771227364Sadrian TAILQ_REMOVE(&bf_cq, bf, bf_list); 3772227364Sadrian ath_tx_default_comp(sc, bf, 0); 3773227364Sadrian } 3774227364Sadrian} 3775227364Sadrian 3776227364Sadrian/* 3777227364Sadrian * Handle completion of unaggregated frames in an ADDBA 3778227364Sadrian * session. 3779227364Sadrian * 3780227364Sadrian * Fail is set to 1 if the entry is being freed via a call to 3781227364Sadrian * ath_tx_draintxq(). 3782227364Sadrian */ 3783227364Sadrianstatic void 3784227364Sadrianath_tx_aggr_comp_unaggr(struct ath_softc *sc, struct ath_buf *bf, int fail) 3785227364Sadrian{ 3786227364Sadrian struct ieee80211_node *ni = bf->bf_node; 3787227364Sadrian struct ath_node *an = ATH_NODE(ni); 3788227364Sadrian int tid = bf->bf_state.bfs_tid; 3789227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 3790227364Sadrian struct ath_tx_status *ts = &bf->bf_status.ds_txstat; 3791227364Sadrian 3792227364Sadrian /* 3793227364Sadrian * Update rate control status here, before we possibly 3794227364Sadrian * punt to retry or cleanup. 3795227364Sadrian * 3796227364Sadrian * Do it outside of the TXQ lock. 3797227364Sadrian */ 3798233966Sadrian if (fail == 0 && ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) 3799227364Sadrian ath_tx_update_ratectrl(sc, ni, bf->bf_state.bfs_rc, 3800227364Sadrian &bf->bf_status.ds_txstat, 3801227364Sadrian bf->bf_state.bfs_pktlen, 3802227364Sadrian 1, (ts->ts_status == 0) ? 0 : 1); 3803227364Sadrian 3804227364Sadrian /* 3805227364Sadrian * This is called early so atid->hwq_depth can be tracked. 3806227364Sadrian * This unfortunately means that it's released and regrabbed 3807227364Sadrian * during retry and cleanup. That's rather inefficient. 3808227364Sadrian */ 3809227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 3810227364Sadrian 3811227364Sadrian if (tid == IEEE80211_NONQOS_TID) 3812227364Sadrian device_printf(sc->sc_dev, "%s: TID=16!\n", __func__); 3813227364Sadrian 3814229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, 3815229949Sadrian "%s: bf=%p: tid=%d, hwq_depth=%d, seqno=%d\n", 3816229949Sadrian __func__, bf, bf->bf_state.bfs_tid, atid->hwq_depth, 3817229949Sadrian SEQNO(bf->bf_state.bfs_seqno)); 3818227364Sadrian 3819227364Sadrian atid->hwq_depth--; 3820227364Sadrian if (atid->hwq_depth < 0) 3821227364Sadrian device_printf(sc->sc_dev, "%s: hwq_depth < 0: %d\n", 3822227364Sadrian __func__, atid->hwq_depth); 3823227364Sadrian 3824227364Sadrian /* 3825227364Sadrian * If a cleanup is in progress, punt to comp_cleanup; 3826227364Sadrian * rather than handling it here. It's thus their 3827227364Sadrian * responsibility to clean up, call the completion 3828227364Sadrian * function in net80211, etc. 3829227364Sadrian */ 3830227364Sadrian if (atid->cleanup_inprogress) { 3831227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3832229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: cleanup_unaggr\n", 3833229949Sadrian __func__); 3834227364Sadrian ath_tx_comp_cleanup_unaggr(sc, bf); 3835227364Sadrian return; 3836227364Sadrian } 3837227364Sadrian 3838227364Sadrian /* 3839227364Sadrian * Don't bother with the retry check if all frames 3840227364Sadrian * are being failed (eg during queue deletion.) 3841227364Sadrian */ 3842227364Sadrian if (fail == 0 && ts->ts_status & HAL_TXERR_XRETRY) { 3843227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3844229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: retry_unaggr\n", 3845229949Sadrian __func__); 3846227364Sadrian ath_tx_aggr_retry_unaggr(sc, bf); 3847227364Sadrian return; 3848227364Sadrian } 3849227364Sadrian 3850227364Sadrian /* Success? Complete */ 3851227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: TID=%d, seqno %d\n", 3852227364Sadrian __func__, tid, SEQNO(bf->bf_state.bfs_seqno)); 3853227364Sadrian if (bf->bf_state.bfs_dobaw) { 3854227364Sadrian ath_tx_update_baw(sc, an, atid, bf); 3855227364Sadrian bf->bf_state.bfs_dobaw = 0; 3856227364Sadrian if (! bf->bf_state.bfs_addedbaw) 3857227364Sadrian device_printf(sc->sc_dev, 3858227364Sadrian "%s: wasn't added: seqno %d\n", 3859227364Sadrian __func__, SEQNO(bf->bf_state.bfs_seqno)); 3860227364Sadrian } 3861227364Sadrian 3862233908Sadrian /* 3863233908Sadrian * Send BAR if required 3864233908Sadrian */ 3865233908Sadrian if (ath_tx_tid_bar_tx_ready(sc, atid)) 3866233908Sadrian ath_tx_tid_bar_tx(sc, atid); 3867233908Sadrian 3868227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 3869227364Sadrian 3870227364Sadrian ath_tx_default_comp(sc, bf, fail); 3871227364Sadrian /* bf is freed at this point */ 3872227364Sadrian} 3873227364Sadrian 3874227364Sadrianvoid 3875227364Sadrianath_tx_aggr_comp(struct ath_softc *sc, struct ath_buf *bf, int fail) 3876227364Sadrian{ 3877227364Sadrian if (bf->bf_state.bfs_aggr) 3878227364Sadrian ath_tx_aggr_comp_aggr(sc, bf, fail); 3879227364Sadrian else 3880227364Sadrian ath_tx_aggr_comp_unaggr(sc, bf, fail); 3881227364Sadrian} 3882227364Sadrian 3883227364Sadrian/* 3884227364Sadrian * Schedule some packets from the given node/TID to the hardware. 3885227364Sadrian * 3886227364Sadrian * This is the aggregate version. 3887227364Sadrian */ 3888227364Sadrianvoid 3889227364Sadrianath_tx_tid_hw_queue_aggr(struct ath_softc *sc, struct ath_node *an, 3890227364Sadrian struct ath_tid *tid) 3891227364Sadrian{ 3892227364Sadrian struct ath_buf *bf; 3893227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 3894227364Sadrian struct ieee80211_tx_ampdu *tap; 3895227364Sadrian struct ieee80211_node *ni = &an->an_node; 3896227364Sadrian ATH_AGGR_STATUS status; 3897227364Sadrian ath_bufhead bf_q; 3898227364Sadrian 3899227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d\n", __func__, tid->tid); 3900227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 3901227364Sadrian 3902227364Sadrian tap = ath_tx_get_tx_tid(an, tid->tid); 3903227364Sadrian 3904227364Sadrian if (tid->tid == IEEE80211_NONQOS_TID) 3905227364Sadrian device_printf(sc->sc_dev, "%s: called for TID=NONQOS_TID?\n", 3906227364Sadrian __func__); 3907227364Sadrian 3908227364Sadrian for (;;) { 3909227364Sadrian status = ATH_AGGR_DONE; 3910227364Sadrian 3911227364Sadrian /* 3912227364Sadrian * If the upper layer has paused the TID, don't 3913227364Sadrian * queue any further packets. 3914227364Sadrian * 3915227364Sadrian * This can also occur from the completion task because 3916227364Sadrian * of packet loss; but as its serialised with this code, 3917227364Sadrian * it won't "appear" half way through queuing packets. 3918227364Sadrian */ 3919227364Sadrian if (tid->paused) 3920227364Sadrian break; 3921227364Sadrian 3922227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 3923227364Sadrian if (bf == NULL) { 3924227364Sadrian break; 3925227364Sadrian } 3926227364Sadrian 3927227364Sadrian /* 3928227364Sadrian * If the packet doesn't fall within the BAW (eg a NULL 3929227364Sadrian * data frame), schedule it directly; continue. 3930227364Sadrian */ 3931227364Sadrian if (! bf->bf_state.bfs_dobaw) { 3932229949Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 3933229949Sadrian "%s: non-baw packet\n", 3934227364Sadrian __func__); 3935227364Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 3936227364Sadrian bf->bf_state.bfs_aggr = 0; 3937227364Sadrian ath_tx_do_ratelookup(sc, bf); 3938233989Sadrian ath_tx_calc_duration(sc, bf); 3939233989Sadrian ath_tx_calc_protection(sc, bf); 3940233989Sadrian ath_tx_set_rtscts(sc, bf); 3941227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 3942227364Sadrian ath_tx_setds(sc, bf); 3943227364Sadrian ath_tx_chaindesclist(sc, bf); 3944227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 3945227364Sadrian ath_tx_set_ratectrl(sc, ni, bf); 3946227364Sadrian 3947227364Sadrian sc->sc_aggr_stats.aggr_nonbaw_pkt++; 3948227364Sadrian 3949227364Sadrian /* Queue the packet; continue */ 3950227364Sadrian goto queuepkt; 3951227364Sadrian } 3952227364Sadrian 3953227364Sadrian TAILQ_INIT(&bf_q); 3954227364Sadrian 3955227364Sadrian /* 3956227364Sadrian * Do a rate control lookup on the first frame in the 3957227364Sadrian * list. The rate control code needs that to occur 3958227364Sadrian * before it can determine whether to TX. 3959227364Sadrian * It's inaccurate because the rate control code doesn't 3960227364Sadrian * really "do" aggregate lookups, so it only considers 3961227364Sadrian * the size of the first frame. 3962227364Sadrian */ 3963227364Sadrian ath_tx_do_ratelookup(sc, bf); 3964227364Sadrian bf->bf_state.bfs_rc[3].rix = 0; 3965227364Sadrian bf->bf_state.bfs_rc[3].tries = 0; 3966233989Sadrian 3967233989Sadrian ath_tx_calc_duration(sc, bf); 3968233989Sadrian ath_tx_calc_protection(sc, bf); 3969233989Sadrian 3970233989Sadrian ath_tx_set_rtscts(sc, bf); 3971227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 3972227364Sadrian 3973227364Sadrian status = ath_tx_form_aggr(sc, an, tid, &bf_q); 3974227364Sadrian 3975227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 3976227364Sadrian "%s: ath_tx_form_aggr() status=%d\n", __func__, status); 3977227364Sadrian 3978227364Sadrian /* 3979227364Sadrian * No frames to be picked up - out of BAW 3980227364Sadrian */ 3981227364Sadrian if (TAILQ_EMPTY(&bf_q)) 3982227364Sadrian break; 3983227364Sadrian 3984227364Sadrian /* 3985227364Sadrian * This assumes that the descriptor list in the ath_bufhead 3986227364Sadrian * are already linked together via bf_next pointers. 3987227364Sadrian */ 3988227364Sadrian bf = TAILQ_FIRST(&bf_q); 3989227364Sadrian 3990233989Sadrian if (status == ATH_AGGR_8K_LIMITED) 3991233989Sadrian sc->sc_aggr_stats.aggr_rts_aggr_limited++; 3992233989Sadrian 3993227364Sadrian /* 3994227364Sadrian * If it's the only frame send as non-aggregate 3995227364Sadrian * assume that ath_tx_form_aggr() has checked 3996227364Sadrian * whether it's in the BAW and added it appropriately. 3997227364Sadrian */ 3998227364Sadrian if (bf->bf_state.bfs_nframes == 1) { 3999227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4000227364Sadrian "%s: single-frame aggregate\n", __func__); 4001227364Sadrian bf->bf_state.bfs_aggr = 0; 4002227364Sadrian ath_tx_setds(sc, bf); 4003227364Sadrian ath_tx_chaindesclist(sc, bf); 4004227364Sadrian ath_hal_clr11n_aggr(sc->sc_ah, bf->bf_desc); 4005227364Sadrian ath_tx_set_ratectrl(sc, ni, bf); 4006227364Sadrian if (status == ATH_AGGR_BAW_CLOSED) 4007227364Sadrian sc->sc_aggr_stats.aggr_baw_closed_single_pkt++; 4008227364Sadrian else 4009227364Sadrian sc->sc_aggr_stats.aggr_single_pkt++; 4010227364Sadrian } else { 4011227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, 4012229949Sadrian "%s: multi-frame aggregate: %d frames, " 4013229949Sadrian "length %d\n", 4014227364Sadrian __func__, bf->bf_state.bfs_nframes, 4015227364Sadrian bf->bf_state.bfs_al); 4016227364Sadrian bf->bf_state.bfs_aggr = 1; 4017227364Sadrian sc->sc_aggr_stats.aggr_pkts[bf->bf_state.bfs_nframes]++; 4018227364Sadrian sc->sc_aggr_stats.aggr_aggr_pkt++; 4019227364Sadrian 4020227364Sadrian /* 4021233989Sadrian * Calculate the duration/protection as required. 4022233989Sadrian */ 4023233989Sadrian ath_tx_calc_duration(sc, bf); 4024233989Sadrian ath_tx_calc_protection(sc, bf); 4025233989Sadrian 4026233989Sadrian /* 4027227364Sadrian * Update the rate and rtscts information based on the 4028227364Sadrian * rate decision made by the rate control code; 4029227364Sadrian * the first frame in the aggregate needs it. 4030227364Sadrian */ 4031227364Sadrian ath_tx_set_rtscts(sc, bf); 4032227364Sadrian 4033227364Sadrian /* 4034227364Sadrian * Setup the relevant descriptor fields 4035227364Sadrian * for aggregation. The first descriptor 4036227364Sadrian * already points to the rest in the chain. 4037227364Sadrian */ 4038227364Sadrian ath_tx_setds_11n(sc, bf); 4039227364Sadrian 4040227364Sadrian /* 4041227364Sadrian * setup first desc with rate and aggr info 4042227364Sadrian */ 4043227364Sadrian ath_tx_set_ratectrl(sc, ni, bf); 4044227364Sadrian } 4045227364Sadrian queuepkt: 4046227364Sadrian //txq = bf->bf_state.bfs_txq; 4047227364Sadrian 4048227364Sadrian /* Set completion handler, multi-frame aggregate or not */ 4049227364Sadrian bf->bf_comp = ath_tx_aggr_comp; 4050227364Sadrian 4051227364Sadrian if (bf->bf_state.bfs_tid == IEEE80211_NONQOS_TID) 4052227364Sadrian device_printf(sc->sc_dev, "%s: TID=16?\n", __func__); 4053227364Sadrian 4054227364Sadrian /* Punt to txq */ 4055227364Sadrian ath_tx_handoff(sc, txq, bf); 4056227364Sadrian 4057227364Sadrian /* Track outstanding buffer count to hardware */ 4058227364Sadrian /* aggregates are "one" buffer */ 4059227364Sadrian tid->hwq_depth++; 4060227364Sadrian 4061227364Sadrian /* 4062227364Sadrian * Break out if ath_tx_form_aggr() indicated 4063227364Sadrian * there can't be any further progress (eg BAW is full.) 4064227364Sadrian * Checking for an empty txq is done above. 4065227364Sadrian * 4066227364Sadrian * XXX locking on txq here? 4067227364Sadrian */ 4068227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit || 4069227364Sadrian status == ATH_AGGR_BAW_CLOSED) 4070227364Sadrian break; 4071227364Sadrian } 4072227364Sadrian} 4073227364Sadrian 4074227364Sadrian/* 4075227364Sadrian * Schedule some packets from the given node/TID to the hardware. 4076227364Sadrian */ 4077227364Sadrianvoid 4078227364Sadrianath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an, 4079227364Sadrian struct ath_tid *tid) 4080227364Sadrian{ 4081227364Sadrian struct ath_buf *bf; 4082227364Sadrian struct ath_txq *txq = sc->sc_ac2q[tid->ac]; 4083227364Sadrian struct ieee80211_node *ni = &an->an_node; 4084227364Sadrian 4085227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: node %p: TID %d: called\n", 4086227364Sadrian __func__, an, tid->tid); 4087227364Sadrian 4088227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 4089227364Sadrian 4090227364Sadrian /* Check - is AMPDU pending or running? then print out something */ 4091227364Sadrian if (ath_tx_ampdu_pending(sc, an, tid->tid)) 4092227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu pending?\n", 4093227364Sadrian __func__, tid->tid); 4094227364Sadrian if (ath_tx_ampdu_running(sc, an, tid->tid)) 4095227364Sadrian device_printf(sc->sc_dev, "%s: tid=%d, ampdu running?\n", 4096227364Sadrian __func__, tid->tid); 4097227364Sadrian 4098227364Sadrian for (;;) { 4099227364Sadrian 4100227364Sadrian /* 4101227364Sadrian * If the upper layers have paused the TID, don't 4102227364Sadrian * queue any further packets. 4103227364Sadrian */ 4104227364Sadrian if (tid->paused) 4105227364Sadrian break; 4106227364Sadrian 4107227364Sadrian bf = TAILQ_FIRST(&tid->axq_q); 4108227364Sadrian if (bf == NULL) { 4109227364Sadrian break; 4110227364Sadrian } 4111227364Sadrian 4112227364Sadrian ATH_TXQ_REMOVE(tid, bf, bf_list); 4113227364Sadrian 4114227364Sadrian KASSERT(txq == bf->bf_state.bfs_txq, ("txqs not equal!\n")); 4115227364Sadrian 4116227364Sadrian /* Sanity check! */ 4117227364Sadrian if (tid->tid != bf->bf_state.bfs_tid) { 4118227364Sadrian device_printf(sc->sc_dev, "%s: bfs_tid %d !=" 4119227364Sadrian " tid %d\n", 4120227364Sadrian __func__, bf->bf_state.bfs_tid, tid->tid); 4121227364Sadrian } 4122227364Sadrian /* Normal completion handler */ 4123227364Sadrian bf->bf_comp = ath_tx_normal_comp; 4124227364Sadrian 4125227364Sadrian /* Program descriptors + rate control */ 4126227364Sadrian ath_tx_do_ratelookup(sc, bf); 4127233989Sadrian ath_tx_calc_duration(sc, bf); 4128233989Sadrian ath_tx_calc_protection(sc, bf); 4129233989Sadrian ath_tx_set_rtscts(sc, bf); 4130227364Sadrian ath_tx_rate_fill_rcflags(sc, bf); 4131227364Sadrian ath_tx_setds(sc, bf); 4132227364Sadrian ath_tx_chaindesclist(sc, bf); 4133227364Sadrian ath_tx_set_ratectrl(sc, ni, bf); 4134227364Sadrian 4135227364Sadrian /* Track outstanding buffer count to hardware */ 4136227364Sadrian /* aggregates are "one" buffer */ 4137227364Sadrian tid->hwq_depth++; 4138227364Sadrian 4139227364Sadrian /* Punt to hardware or software txq */ 4140227364Sadrian ath_tx_handoff(sc, txq, bf); 4141227364Sadrian } 4142227364Sadrian} 4143227364Sadrian 4144227364Sadrian/* 4145227364Sadrian * Schedule some packets to the given hardware queue. 4146227364Sadrian * 4147227364Sadrian * This function walks the list of TIDs (ie, ath_node TIDs 4148227364Sadrian * with queued traffic) and attempts to schedule traffic 4149227364Sadrian * from them. 4150227364Sadrian * 4151227364Sadrian * TID scheduling is implemented as a FIFO, with TIDs being 4152227364Sadrian * added to the end of the queue after some frames have been 4153227364Sadrian * scheduled. 4154227364Sadrian */ 4155227364Sadrianvoid 4156227364Sadrianath_txq_sched(struct ath_softc *sc, struct ath_txq *txq) 4157227364Sadrian{ 4158227364Sadrian struct ath_tid *tid, *next, *last; 4159227364Sadrian 4160227364Sadrian ATH_TXQ_LOCK_ASSERT(txq); 4161227364Sadrian 4162227364Sadrian /* 4163227364Sadrian * Don't schedule if the hardware queue is busy. 4164227364Sadrian * This (hopefully) gives some more time to aggregate 4165227364Sadrian * some packets in the aggregation queue. 4166227364Sadrian */ 4167227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4168227364Sadrian sc->sc_aggr_stats.aggr_sched_nopkt++; 4169227364Sadrian return; 4170227364Sadrian } 4171227364Sadrian 4172227364Sadrian last = TAILQ_LAST(&txq->axq_tidq, axq_t_s); 4173227364Sadrian 4174227364Sadrian TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) { 4175227364Sadrian /* 4176227364Sadrian * Suspend paused queues here; they'll be resumed 4177227364Sadrian * once the addba completes or times out. 4178227364Sadrian */ 4179227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX, "%s: tid=%d, paused=%d\n", 4180227364Sadrian __func__, tid->tid, tid->paused); 4181227364Sadrian ath_tx_tid_unsched(sc, tid); 4182227364Sadrian if (tid->paused) { 4183227364Sadrian continue; 4184227364Sadrian } 4185227364Sadrian if (ath_tx_ampdu_running(sc, tid->an, tid->tid)) 4186227364Sadrian ath_tx_tid_hw_queue_aggr(sc, tid->an, tid); 4187227364Sadrian else 4188227364Sadrian ath_tx_tid_hw_queue_norm(sc, tid->an, tid); 4189227364Sadrian 4190227364Sadrian /* Not empty? Re-schedule */ 4191227364Sadrian if (tid->axq_depth != 0) 4192227364Sadrian ath_tx_tid_sched(sc, tid); 4193227364Sadrian 4194227364Sadrian /* Give the software queue time to aggregate more packets */ 4195227364Sadrian if (txq->axq_aggr_depth >= sc->sc_hwq_limit) { 4196227364Sadrian break; 4197227364Sadrian } 4198227364Sadrian 4199227364Sadrian /* 4200227364Sadrian * If this was the last entry on the original list, stop. 4201227364Sadrian * Otherwise nodes that have been rescheduled onto the end 4202227364Sadrian * of the TID FIFO list will just keep being rescheduled. 4203227364Sadrian */ 4204227364Sadrian if (tid == last) 4205227364Sadrian break; 4206227364Sadrian } 4207227364Sadrian} 4208227364Sadrian 4209227364Sadrian/* 4210227364Sadrian * TX addba handling 4211227364Sadrian */ 4212227364Sadrian 4213227364Sadrian/* 4214227364Sadrian * Return net80211 TID struct pointer, or NULL for none 4215227364Sadrian */ 4216227364Sadrianstruct ieee80211_tx_ampdu * 4217227364Sadrianath_tx_get_tx_tid(struct ath_node *an, int tid) 4218227364Sadrian{ 4219227364Sadrian struct ieee80211_node *ni = &an->an_node; 4220227364Sadrian struct ieee80211_tx_ampdu *tap; 4221227364Sadrian 4222227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4223227364Sadrian return NULL; 4224227364Sadrian 4225234324Sadrian tap = &ni->ni_tx_ampdu[tid]; 4226227364Sadrian return tap; 4227227364Sadrian} 4228227364Sadrian 4229227364Sadrian/* 4230227364Sadrian * Is AMPDU-TX running? 4231227364Sadrian */ 4232227364Sadrianstatic int 4233227364Sadrianath_tx_ampdu_running(struct ath_softc *sc, struct ath_node *an, int tid) 4234227364Sadrian{ 4235227364Sadrian struct ieee80211_tx_ampdu *tap; 4236227364Sadrian 4237227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4238227364Sadrian return 0; 4239227364Sadrian 4240227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4241227364Sadrian if (tap == NULL) 4242227364Sadrian return 0; /* Not valid; default to not running */ 4243227364Sadrian 4244227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_RUNNING); 4245227364Sadrian} 4246227364Sadrian 4247227364Sadrian/* 4248227364Sadrian * Is AMPDU-TX negotiation pending? 4249227364Sadrian */ 4250227364Sadrianstatic int 4251227364Sadrianath_tx_ampdu_pending(struct ath_softc *sc, struct ath_node *an, int tid) 4252227364Sadrian{ 4253227364Sadrian struct ieee80211_tx_ampdu *tap; 4254227364Sadrian 4255227364Sadrian if (tid == IEEE80211_NONQOS_TID) 4256227364Sadrian return 0; 4257227364Sadrian 4258227364Sadrian tap = ath_tx_get_tx_tid(an, tid); 4259227364Sadrian if (tap == NULL) 4260227364Sadrian return 0; /* Not valid; default to not pending */ 4261227364Sadrian 4262227364Sadrian return !! (tap->txa_flags & IEEE80211_AGGR_XCHGPEND); 4263227364Sadrian} 4264227364Sadrian 4265227364Sadrian/* 4266227364Sadrian * Is AMPDU-TX pending for the given TID? 4267227364Sadrian */ 4268227364Sadrian 4269227364Sadrian 4270227364Sadrian/* 4271227364Sadrian * Method to handle sending an ADDBA request. 4272227364Sadrian * 4273227364Sadrian * We tap this so the relevant flags can be set to pause the TID 4274227364Sadrian * whilst waiting for the response. 4275227364Sadrian * 4276227364Sadrian * XXX there's no timeout handler we can override? 4277227364Sadrian */ 4278227364Sadrianint 4279227364Sadrianath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 4280227364Sadrian int dialogtoken, int baparamset, int batimeout) 4281227364Sadrian{ 4282227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4283234324Sadrian int tid = tap->txa_tid; 4284227364Sadrian struct ath_node *an = ATH_NODE(ni); 4285227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4286227364Sadrian 4287227364Sadrian /* 4288227364Sadrian * XXX danger Will Robinson! 4289227364Sadrian * 4290227364Sadrian * Although the taskqueue may be running and scheduling some more 4291227364Sadrian * packets, these should all be _before_ the addba sequence number. 4292227364Sadrian * However, net80211 will keep self-assigning sequence numbers 4293227364Sadrian * until addba has been negotiated. 4294227364Sadrian * 4295227364Sadrian * In the past, these packets would be "paused" (which still works 4296227364Sadrian * fine, as they're being scheduled to the driver in the same 4297227364Sadrian * serialised method which is calling the addba request routine) 4298227364Sadrian * and when the aggregation session begins, they'll be dequeued 4299227364Sadrian * as aggregate packets and added to the BAW. However, now there's 4300227364Sadrian * a "bf->bf_state.bfs_dobaw" flag, and this isn't set for these 4301227364Sadrian * packets. Thus they never get included in the BAW tracking and 4302227364Sadrian * this can cause the initial burst of packets after the addba 4303227364Sadrian * negotiation to "hang", as they quickly fall outside the BAW. 4304227364Sadrian * 4305227364Sadrian * The "eventual" solution should be to tag these packets with 4306227364Sadrian * dobaw. Although net80211 has given us a sequence number, 4307227364Sadrian * it'll be "after" the left edge of the BAW and thus it'll 4308227364Sadrian * fall within it. 4309227364Sadrian */ 4310233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->tid]); 4311227364Sadrian ath_tx_tid_pause(sc, atid); 4312233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->tid]); 4313227364Sadrian 4314227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4315227364Sadrian "%s: called; dialogtoken=%d, baparamset=%d, batimeout=%d\n", 4316227364Sadrian __func__, dialogtoken, baparamset, batimeout); 4317227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4318227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 4319227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 4320227364Sadrian 4321227364Sadrian return sc->sc_addba_request(ni, tap, dialogtoken, baparamset, 4322227364Sadrian batimeout); 4323227364Sadrian} 4324227364Sadrian 4325227364Sadrian/* 4326227364Sadrian * Handle an ADDBA response. 4327227364Sadrian * 4328227364Sadrian * We unpause the queue so TX'ing can resume. 4329227364Sadrian * 4330227364Sadrian * Any packets TX'ed from this point should be "aggregate" (whether 4331227364Sadrian * aggregate or not) so the BAW is updated. 4332227364Sadrian * 4333227364Sadrian * Note! net80211 keeps self-assigning sequence numbers until 4334227364Sadrian * ampdu is negotiated. This means the initially-negotiated BAW left 4335227364Sadrian * edge won't match the ni->ni_txseq. 4336227364Sadrian * 4337227364Sadrian * So, being very dirty, the BAW left edge is "slid" here to match 4338227364Sadrian * ni->ni_txseq. 4339227364Sadrian * 4340227364Sadrian * What likely SHOULD happen is that all packets subsequent to the 4341227364Sadrian * addba request should be tagged as aggregate and queued as non-aggregate 4342227364Sadrian * frames; thus updating the BAW. For now though, I'll just slide the 4343227364Sadrian * window. 4344227364Sadrian */ 4345227364Sadrianint 4346227364Sadrianath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 4347227364Sadrian int status, int code, int batimeout) 4348227364Sadrian{ 4349227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4350234324Sadrian int tid = tap->txa_tid; 4351227364Sadrian struct ath_node *an = ATH_NODE(ni); 4352227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4353227364Sadrian int r; 4354227364Sadrian 4355227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4356227364Sadrian "%s: called; status=%d, code=%d, batimeout=%d\n", __func__, 4357227364Sadrian status, code, batimeout); 4358227364Sadrian 4359227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4360227364Sadrian "%s: txa_start=%d, ni_txseqs=%d\n", 4361227364Sadrian __func__, tap->txa_start, ni->ni_txseqs[tid]); 4362227364Sadrian 4363227364Sadrian /* 4364227364Sadrian * Call this first, so the interface flags get updated 4365227364Sadrian * before the TID is unpaused. Otherwise a race condition 4366227364Sadrian * exists where the unpaused TID still doesn't yet have 4367227364Sadrian * IEEE80211_AGGR_RUNNING set. 4368227364Sadrian */ 4369227364Sadrian r = sc->sc_addba_response(ni, tap, status, code, batimeout); 4370227364Sadrian 4371227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4372227364Sadrian /* 4373227364Sadrian * XXX dirty! 4374227364Sadrian * Slide the BAW left edge to wherever net80211 left it for us. 4375227364Sadrian * Read above for more information. 4376227364Sadrian */ 4377227364Sadrian tap->txa_start = ni->ni_txseqs[tid]; 4378227364Sadrian ath_tx_tid_resume(sc, atid); 4379227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4380227364Sadrian return r; 4381227364Sadrian} 4382227364Sadrian 4383227364Sadrian 4384227364Sadrian/* 4385227364Sadrian * Stop ADDBA on a queue. 4386227364Sadrian */ 4387227364Sadrianvoid 4388227364Sadrianath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 4389227364Sadrian{ 4390227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4391234324Sadrian int tid = tap->txa_tid; 4392227364Sadrian struct ath_node *an = ATH_NODE(ni); 4393227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4394227364Sadrian 4395227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: called\n", __func__); 4396227364Sadrian 4397227364Sadrian /* Pause TID traffic early, so there aren't any races */ 4398233908Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->tid]); 4399227364Sadrian ath_tx_tid_pause(sc, atid); 4400233908Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->tid]); 4401227364Sadrian 4402227364Sadrian /* There's no need to hold the TXQ lock here */ 4403227364Sadrian sc->sc_addba_stop(ni, tap); 4404227364Sadrian 4405227364Sadrian /* 4406227364Sadrian * ath_tx_cleanup will resume the TID if possible, otherwise 4407227364Sadrian * it'll set the cleanup flag, and it'll be unpaused once 4408227364Sadrian * things have been cleaned up. 4409227364Sadrian */ 4410227364Sadrian ath_tx_cleanup(sc, an, tid); 4411227364Sadrian} 4412227364Sadrian 4413227364Sadrian/* 4414227364Sadrian * Note: net80211 bar_timeout() doesn't call this function on BAR failure; 4415227364Sadrian * it simply tears down the aggregation session. Ew. 4416227364Sadrian * 4417227364Sadrian * It however will call ieee80211_ampdu_stop() which will call 4418227364Sadrian * ic->ic_addba_stop(). 4419227364Sadrian * 4420227364Sadrian * XXX This uses a hard-coded max BAR count value; the whole 4421227364Sadrian * XXX BAR TX success or failure should be better handled! 4422227364Sadrian */ 4423227364Sadrianvoid 4424227364Sadrianath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 4425227364Sadrian int status) 4426227364Sadrian{ 4427227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4428234324Sadrian int tid = tap->txa_tid; 4429227364Sadrian struct ath_node *an = ATH_NODE(ni); 4430227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4431227364Sadrian int attempts = tap->txa_attempts; 4432227364Sadrian 4433227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4434227364Sadrian "%s: called; status=%d\n", __func__, status); 4435227364Sadrian 4436227364Sadrian /* Note: This may update the BAW details */ 4437227364Sadrian sc->sc_bar_response(ni, tap, status); 4438227364Sadrian 4439227364Sadrian /* Unpause the TID */ 4440227364Sadrian /* 4441227364Sadrian * XXX if this is attempt=50, the TID will be downgraded 4442227364Sadrian * XXX to a non-aggregate session. So we must unpause the 4443227364Sadrian * XXX TID here or it'll never be done. 4444227364Sadrian */ 4445227364Sadrian if (status == 0 || attempts == 50) { 4446227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4447233908Sadrian ath_tx_tid_bar_unsuspend(sc, atid); 4448227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4449227364Sadrian } 4450227364Sadrian} 4451227364Sadrian 4452227364Sadrian/* 4453227364Sadrian * This is called whenever the pending ADDBA request times out. 4454227364Sadrian * Unpause and reschedule the TID. 4455227364Sadrian */ 4456227364Sadrianvoid 4457227364Sadrianath_addba_response_timeout(struct ieee80211_node *ni, 4458227364Sadrian struct ieee80211_tx_ampdu *tap) 4459227364Sadrian{ 4460227364Sadrian struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc; 4461234324Sadrian int tid = tap->txa_tid; 4462227364Sadrian struct ath_node *an = ATH_NODE(ni); 4463227364Sadrian struct ath_tid *atid = &an->an_tid[tid]; 4464227364Sadrian 4465227364Sadrian DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, 4466227364Sadrian "%s: called; resuming\n", __func__); 4467227364Sadrian 4468227364Sadrian /* Note: This updates the aggregate state to (again) pending */ 4469227364Sadrian sc->sc_addba_response_timeout(ni, tap); 4470227364Sadrian 4471227364Sadrian /* Unpause the TID; which reschedules it */ 4472227364Sadrian ATH_TXQ_LOCK(sc->sc_ac2q[atid->ac]); 4473227364Sadrian ath_tx_tid_resume(sc, atid); 4474227364Sadrian ATH_TXQ_UNLOCK(sc->sc_ac2q[atid->ac]); 4475227364Sadrian} 4476