xmit.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "ath9k.h"
  17. #define BITS_PER_BYTE 8
  18. #define OFDM_PLCP_BITS 22
  19. #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
  20. #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
  21. #define L_STF 8
  22. #define L_LTF 8
  23. #define L_SIG 4
  24. #define HT_SIG 8
  25. #define HT_STF 4
  26. #define HT_LTF(_ns) (4 * (_ns))
  27. #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
  28. #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
  29. #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
  30. #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
  31. #define OFDM_SIFS_TIME 16
  32. static u32 bits_per_symbol[][2] = {
  33. /* 20MHz 40MHz */
  34. { 26, 54 }, /* 0: BPSK */
  35. { 52, 108 }, /* 1: QPSK 1/2 */
  36. { 78, 162 }, /* 2: QPSK 3/4 */
  37. { 104, 216 }, /* 3: 16-QAM 1/2 */
  38. { 156, 324 }, /* 4: 16-QAM 3/4 */
  39. { 208, 432 }, /* 5: 64-QAM 2/3 */
  40. { 234, 486 }, /* 6: 64-QAM 3/4 */
  41. { 260, 540 }, /* 7: 64-QAM 5/6 */
  42. { 52, 108 }, /* 8: BPSK */
  43. { 104, 216 }, /* 9: QPSK 1/2 */
  44. { 156, 324 }, /* 10: QPSK 3/4 */
  45. { 208, 432 }, /* 11: 16-QAM 1/2 */
  46. { 312, 648 }, /* 12: 16-QAM 3/4 */
  47. { 416, 864 }, /* 13: 64-QAM 2/3 */
  48. { 468, 972 }, /* 14: 64-QAM 3/4 */
  49. { 520, 1080 }, /* 15: 64-QAM 5/6 */
  50. };
  51. #define IS_HT_RATE(_rate) ((_rate) & 0x80)
  52. static void ath_tx_send_ht_normal(struct ath_softc *sc, struct ath_txq *txq,
  53. struct ath_atx_tid *tid,
  54. struct list_head *bf_head);
  55. static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
  56. struct ath_txq *txq,
  57. struct list_head *bf_q,
  58. int txok, int sendbar);
  59. static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
  60. struct list_head *head);
  61. static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf);
  62. static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
  63. int txok);
  64. static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
  65. int nbad, int txok, bool update_rc);
  66. /*********************/
  67. /* Aggregation logic */
  68. /*********************/
  69. static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
  70. {
  71. struct ath_atx_ac *ac = tid->ac;
  72. if (tid->paused)
  73. return;
  74. if (tid->sched)
  75. return;
  76. tid->sched = true;
  77. list_add_tail(&tid->list, &ac->tid_q);
  78. if (ac->sched)
  79. return;
  80. ac->sched = true;
  81. list_add_tail(&ac->list, &txq->axq_acq);
  82. }
  83. static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  84. {
  85. struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
  86. spin_lock_bh(&txq->axq_lock);
  87. tid->paused++;
  88. spin_unlock_bh(&txq->axq_lock);
  89. }
  90. static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  91. {
  92. struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
  93. BUG_ON(tid->paused <= 0);
  94. spin_lock_bh(&txq->axq_lock);
  95. tid->paused--;
  96. if (tid->paused > 0)
  97. goto unlock;
  98. if (list_empty(&tid->buf_q))
  99. goto unlock;
  100. ath_tx_queue_tid(txq, tid);
  101. ath_txq_schedule(sc, txq);
  102. unlock:
  103. spin_unlock_bh(&txq->axq_lock);
  104. }
  105. static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  106. {
  107. struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
  108. struct ath_buf *bf;
  109. struct list_head bf_head;
  110. INIT_LIST_HEAD(&bf_head);
  111. BUG_ON(tid->paused <= 0);
  112. spin_lock_bh(&txq->axq_lock);
  113. tid->paused--;
  114. if (tid->paused > 0) {
  115. spin_unlock_bh(&txq->axq_lock);
  116. return;
  117. }
  118. while (!list_empty(&tid->buf_q)) {
  119. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  120. BUG_ON(bf_isretried(bf));
  121. list_move_tail(&bf->list, &bf_head);
  122. ath_tx_send_ht_normal(sc, txq, tid, &bf_head);
  123. }
  124. spin_unlock_bh(&txq->axq_lock);
  125. }
  126. static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  127. int seqno)
  128. {
  129. int index, cindex;
  130. index = ATH_BA_INDEX(tid->seq_start, seqno);
  131. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  132. tid->tx_buf[cindex] = NULL;
  133. while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
  134. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  135. INCR(tid->baw_head, ATH_TID_MAX_BUFS);
  136. }
  137. }
  138. static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  139. struct ath_buf *bf)
  140. {
  141. int index, cindex;
  142. if (bf_isretried(bf))
  143. return;
  144. index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
  145. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  146. BUG_ON(tid->tx_buf[cindex] != NULL);
  147. tid->tx_buf[cindex] = bf;
  148. if (index >= ((tid->baw_tail - tid->baw_head) &
  149. (ATH_TID_MAX_BUFS - 1))) {
  150. tid->baw_tail = cindex;
  151. INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
  152. }
  153. }
  154. /*
  155. * TODO: For frame(s) that are in the retry state, we will reuse the
  156. * sequence number(s) without setting the retry bit. The
  157. * alternative is to give up on these and BAR the receiver's window
  158. * forward.
  159. */
  160. static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
  161. struct ath_atx_tid *tid)
  162. {
  163. struct ath_buf *bf;
  164. struct list_head bf_head;
  165. INIT_LIST_HEAD(&bf_head);
  166. for (;;) {
  167. if (list_empty(&tid->buf_q))
  168. break;
  169. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  170. list_move_tail(&bf->list, &bf_head);
  171. if (bf_isretried(bf))
  172. ath_tx_update_baw(sc, tid, bf->bf_seqno);
  173. spin_unlock(&txq->axq_lock);
  174. ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
  175. spin_lock(&txq->axq_lock);
  176. }
  177. tid->seq_next = tid->seq_start;
  178. tid->baw_tail = tid->baw_head;
  179. }
  180. static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
  181. struct ath_buf *bf)
  182. {
  183. struct sk_buff *skb;
  184. struct ieee80211_hdr *hdr;
  185. bf->bf_state.bf_type |= BUF_RETRY;
  186. bf->bf_retries++;
  187. TX_STAT_INC(txq->axq_qnum, a_retries);
  188. skb = bf->bf_mpdu;
  189. hdr = (struct ieee80211_hdr *)skb->data;
  190. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
  191. }
  192. static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
  193. {
  194. struct ath_buf *tbf;
  195. spin_lock_bh(&sc->tx.txbuflock);
  196. if (WARN_ON(list_empty(&sc->tx.txbuf))) {
  197. spin_unlock_bh(&sc->tx.txbuflock);
  198. return NULL;
  199. }
  200. tbf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
  201. list_del(&tbf->list);
  202. spin_unlock_bh(&sc->tx.txbuflock);
  203. ATH_TXBUF_RESET(tbf);
  204. tbf->bf_mpdu = bf->bf_mpdu;
  205. tbf->bf_buf_addr = bf->bf_buf_addr;
  206. *(tbf->bf_desc) = *(bf->bf_desc);
  207. tbf->bf_state = bf->bf_state;
  208. tbf->bf_dmacontext = bf->bf_dmacontext;
  209. return tbf;
  210. }
  211. static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
  212. struct ath_buf *bf, struct list_head *bf_q,
  213. int txok)
  214. {
  215. struct ath_node *an = NULL;
  216. struct sk_buff *skb;
  217. struct ieee80211_sta *sta;
  218. struct ieee80211_hw *hw;
  219. struct ieee80211_hdr *hdr;
  220. struct ieee80211_tx_info *tx_info;
  221. struct ath_tx_info_priv *tx_info_priv;
  222. struct ath_atx_tid *tid = NULL;
  223. struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
  224. struct ath_desc *ds = bf_last->bf_desc;
  225. struct list_head bf_head, bf_pending;
  226. u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0;
  227. u32 ba[WME_BA_BMP_SIZE >> 5];
  228. int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
  229. bool rc_update = true;
  230. skb = bf->bf_mpdu;
  231. hdr = (struct ieee80211_hdr *)skb->data;
  232. tx_info = IEEE80211_SKB_CB(skb);
  233. tx_info_priv = (struct ath_tx_info_priv *) tx_info->rate_driver_data[0];
  234. hw = tx_info_priv->aphy->hw;
  235. rcu_read_lock();
  236. /* XXX: use ieee80211_find_sta! */
  237. sta = ieee80211_find_sta_by_hw(hw, hdr->addr1);
  238. if (!sta) {
  239. rcu_read_unlock();
  240. return;
  241. }
  242. an = (struct ath_node *)sta->drv_priv;
  243. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  244. isaggr = bf_isaggr(bf);
  245. memset(ba, 0, WME_BA_BMP_SIZE >> 3);
  246. if (isaggr && txok) {
  247. if (ATH_DS_TX_BA(ds)) {
  248. seq_st = ATH_DS_BA_SEQ(ds);
  249. memcpy(ba, ATH_DS_BA_BITMAP(ds),
  250. WME_BA_BMP_SIZE >> 3);
  251. } else {
  252. /*
  253. * AR5416 can become deaf/mute when BA
  254. * issue happens. Chip needs to be reset.
  255. * But AP code may have sychronization issues
  256. * when perform internal reset in this routine.
  257. * Only enable reset in STA mode for now.
  258. */
  259. if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
  260. needreset = 1;
  261. }
  262. }
  263. INIT_LIST_HEAD(&bf_pending);
  264. INIT_LIST_HEAD(&bf_head);
  265. nbad = ath_tx_num_badfrms(sc, bf, txok);
  266. while (bf) {
  267. txfail = txpending = 0;
  268. bf_next = bf->bf_next;
  269. if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
  270. /* transmit completion, subframe is
  271. * acked by block ack */
  272. acked_cnt++;
  273. } else if (!isaggr && txok) {
  274. /* transmit completion */
  275. acked_cnt++;
  276. } else {
  277. if (!(tid->state & AGGR_CLEANUP) &&
  278. ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
  279. if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
  280. ath_tx_set_retry(sc, txq, bf);
  281. txpending = 1;
  282. } else {
  283. bf->bf_state.bf_type |= BUF_XRETRY;
  284. txfail = 1;
  285. sendbar = 1;
  286. txfail_cnt++;
  287. }
  288. } else {
  289. /*
  290. * cleanup in progress, just fail
  291. * the un-acked sub-frames
  292. */
  293. txfail = 1;
  294. }
  295. }
  296. if (bf_next == NULL) {
  297. /*
  298. * Make sure the last desc is reclaimed if it
  299. * not a holding desc.
  300. */
  301. if (!bf_last->bf_stale)
  302. list_move_tail(&bf->list, &bf_head);
  303. else
  304. INIT_LIST_HEAD(&bf_head);
  305. } else {
  306. BUG_ON(list_empty(bf_q));
  307. list_move_tail(&bf->list, &bf_head);
  308. }
  309. if (!txpending) {
  310. /*
  311. * complete the acked-ones/xretried ones; update
  312. * block-ack window
  313. */
  314. spin_lock_bh(&txq->axq_lock);
  315. ath_tx_update_baw(sc, tid, bf->bf_seqno);
  316. spin_unlock_bh(&txq->axq_lock);
  317. if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
  318. ath_tx_rc_status(bf, ds, nbad, txok, true);
  319. rc_update = false;
  320. } else {
  321. ath_tx_rc_status(bf, ds, nbad, txok, false);
  322. }
  323. ath_tx_complete_buf(sc, bf, txq, &bf_head, !txfail, sendbar);
  324. } else {
  325. /* retry the un-acked ones */
  326. if (bf->bf_next == NULL && bf_last->bf_stale) {
  327. struct ath_buf *tbf;
  328. tbf = ath_clone_txbuf(sc, bf_last);
  329. /*
  330. * Update tx baw and complete the frame with
  331. * failed status if we run out of tx buf
  332. */
  333. if (!tbf) {
  334. spin_lock_bh(&txq->axq_lock);
  335. ath_tx_update_baw(sc, tid,
  336. bf->bf_seqno);
  337. spin_unlock_bh(&txq->axq_lock);
  338. bf->bf_state.bf_type |= BUF_XRETRY;
  339. ath_tx_rc_status(bf, ds, nbad,
  340. 0, false);
  341. ath_tx_complete_buf(sc, bf, txq,
  342. &bf_head, 0, 0);
  343. break;
  344. }
  345. ath9k_hw_cleartxdesc(sc->sc_ah, tbf->bf_desc);
  346. list_add_tail(&tbf->list, &bf_head);
  347. } else {
  348. /*
  349. * Clear descriptor status words for
  350. * software retry
  351. */
  352. ath9k_hw_cleartxdesc(sc->sc_ah, bf->bf_desc);
  353. }
  354. /*
  355. * Put this buffer to the temporary pending
  356. * queue to retain ordering
  357. */
  358. list_splice_tail_init(&bf_head, &bf_pending);
  359. }
  360. bf = bf_next;
  361. }
  362. if (tid->state & AGGR_CLEANUP) {
  363. if (tid->baw_head == tid->baw_tail) {
  364. tid->state &= ~AGGR_ADDBA_COMPLETE;
  365. tid->state &= ~AGGR_CLEANUP;
  366. /* send buffered frames as singles */
  367. ath_tx_flush_tid(sc, tid);
  368. }
  369. rcu_read_unlock();
  370. return;
  371. }
  372. /* prepend un-acked frames to the beginning of the pending frame queue */
  373. if (!list_empty(&bf_pending)) {
  374. spin_lock_bh(&txq->axq_lock);
  375. list_splice(&bf_pending, &tid->buf_q);
  376. ath_tx_queue_tid(txq, tid);
  377. spin_unlock_bh(&txq->axq_lock);
  378. }
  379. rcu_read_unlock();
  380. if (needreset)
  381. ath_reset(sc, false);
  382. }
  383. static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
  384. struct ath_atx_tid *tid)
  385. {
  386. const struct ath_rate_table *rate_table = sc->cur_rate_table;
  387. struct sk_buff *skb;
  388. struct ieee80211_tx_info *tx_info;
  389. struct ieee80211_tx_rate *rates;
  390. struct ath_tx_info_priv *tx_info_priv;
  391. u32 max_4ms_framelen, frmlen;
  392. u16 aggr_limit, legacy = 0;
  393. int i;
  394. skb = bf->bf_mpdu;
  395. tx_info = IEEE80211_SKB_CB(skb);
  396. rates = tx_info->control.rates;
  397. tx_info_priv = (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
  398. /*
  399. * Find the lowest frame length among the rate series that will have a
  400. * 4ms transmit duration.
  401. * TODO - TXOP limit needs to be considered.
  402. */
  403. max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
  404. for (i = 0; i < 4; i++) {
  405. if (rates[i].count) {
  406. if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
  407. legacy = 1;
  408. break;
  409. }
  410. frmlen = rate_table->info[rates[i].idx].max_4ms_framelen;
  411. max_4ms_framelen = min(max_4ms_framelen, frmlen);
  412. }
  413. }
  414. /*
  415. * limit aggregate size by the minimum rate if rate selected is
  416. * not a probe rate, if rate selected is a probe rate then
  417. * avoid aggregation of this packet.
  418. */
  419. if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
  420. return 0;
  421. if (sc->sc_flags & SC_OP_BT_PRIORITY_DETECTED)
  422. aggr_limit = min((max_4ms_framelen * 3) / 8,
  423. (u32)ATH_AMPDU_LIMIT_MAX);
  424. else
  425. aggr_limit = min(max_4ms_framelen,
  426. (u32)ATH_AMPDU_LIMIT_MAX);
  427. /*
  428. * h/w can accept aggregates upto 16 bit lengths (65535).
  429. * The IE, however can hold upto 65536, which shows up here
  430. * as zero. Ignore 65536 since we are constrained by hw.
  431. */
  432. if (tid->an->maxampdu)
  433. aggr_limit = min(aggr_limit, tid->an->maxampdu);
  434. return aggr_limit;
  435. }
  436. /*
  437. * Returns the number of delimiters to be added to
  438. * meet the minimum required mpdudensity.
  439. */
  440. static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
  441. struct ath_buf *bf, u16 frmlen)
  442. {
  443. const struct ath_rate_table *rt = sc->cur_rate_table;
  444. struct sk_buff *skb = bf->bf_mpdu;
  445. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  446. u32 nsymbits, nsymbols;
  447. u16 minlen;
  448. u8 rc, flags, rix;
  449. int width, half_gi, ndelim, mindelim;
  450. /* Select standard number of delimiters based on frame length alone */
  451. ndelim = ATH_AGGR_GET_NDELIM(frmlen);
  452. /*
  453. * If encryption enabled, hardware requires some more padding between
  454. * subframes.
  455. * TODO - this could be improved to be dependent on the rate.
  456. * The hardware can keep up at lower rates, but not higher rates
  457. */
  458. if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
  459. ndelim += ATH_AGGR_ENCRYPTDELIM;
  460. /*
  461. * Convert desired mpdu density from microeconds to bytes based
  462. * on highest rate in rate series (i.e. first rate) to determine
  463. * required minimum length for subframe. Take into account
  464. * whether high rate is 20 or 40Mhz and half or full GI.
  465. *
  466. * If there is no mpdu density restriction, no further calculation
  467. * is needed.
  468. */
  469. if (tid->an->mpdudensity == 0)
  470. return ndelim;
  471. rix = tx_info->control.rates[0].idx;
  472. flags = tx_info->control.rates[0].flags;
  473. rc = rt->info[rix].ratecode;
  474. width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
  475. half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
  476. if (half_gi)
  477. nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity);
  478. else
  479. nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity);
  480. if (nsymbols == 0)
  481. nsymbols = 1;
  482. nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
  483. minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
  484. if (frmlen < minlen) {
  485. mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
  486. ndelim = max(mindelim, ndelim);
  487. }
  488. return ndelim;
  489. }
  490. static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
  491. struct ath_txq *txq,
  492. struct ath_atx_tid *tid,
  493. struct list_head *bf_q)
  494. {
  495. #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
  496. struct ath_buf *bf, *bf_first, *bf_prev = NULL;
  497. int rl = 0, nframes = 0, ndelim, prev_al = 0;
  498. u16 aggr_limit = 0, al = 0, bpad = 0,
  499. al_delta, h_baw = tid->baw_size / 2;
  500. enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
  501. bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
  502. do {
  503. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  504. /* do not step over block-ack window */
  505. if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
  506. status = ATH_AGGR_BAW_CLOSED;
  507. break;
  508. }
  509. if (!rl) {
  510. aggr_limit = ath_lookup_rate(sc, bf, tid);
  511. rl = 1;
  512. }
  513. /* do not exceed aggregation limit */
  514. al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
  515. if (nframes &&
  516. (aggr_limit < (al + bpad + al_delta + prev_al))) {
  517. status = ATH_AGGR_LIMITED;
  518. break;
  519. }
  520. /* do not exceed subframe limit */
  521. if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
  522. status = ATH_AGGR_LIMITED;
  523. break;
  524. }
  525. nframes++;
  526. /* add padding for previous frame to aggregation length */
  527. al += bpad + al_delta;
  528. /*
  529. * Get the delimiters needed to meet the MPDU
  530. * density for this node.
  531. */
  532. ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
  533. bpad = PADBYTES(al_delta) + (ndelim << 2);
  534. bf->bf_next = NULL;
  535. bf->bf_desc->ds_link = 0;
  536. /* link buffers of this frame to the aggregate */
  537. ath_tx_addto_baw(sc, tid, bf);
  538. ath9k_hw_set11n_aggr_middle(sc->sc_ah, bf->bf_desc, ndelim);
  539. list_move_tail(&bf->list, bf_q);
  540. if (bf_prev) {
  541. bf_prev->bf_next = bf;
  542. bf_prev->bf_desc->ds_link = bf->bf_daddr;
  543. }
  544. bf_prev = bf;
  545. } while (!list_empty(&tid->buf_q));
  546. bf_first->bf_al = al;
  547. bf_first->bf_nframes = nframes;
  548. return status;
  549. #undef PADBYTES
  550. }
  551. static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
  552. struct ath_atx_tid *tid)
  553. {
  554. struct ath_buf *bf;
  555. enum ATH_AGGR_STATUS status;
  556. struct list_head bf_q;
  557. do {
  558. if (list_empty(&tid->buf_q))
  559. return;
  560. INIT_LIST_HEAD(&bf_q);
  561. status = ath_tx_form_aggr(sc, txq, tid, &bf_q);
  562. /*
  563. * no frames picked up to be aggregated;
  564. * block-ack window is not open.
  565. */
  566. if (list_empty(&bf_q))
  567. break;
  568. bf = list_first_entry(&bf_q, struct ath_buf, list);
  569. bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
  570. /* if only one frame, send as non-aggregate */
  571. if (bf->bf_nframes == 1) {
  572. bf->bf_state.bf_type &= ~BUF_AGGR;
  573. ath9k_hw_clr11n_aggr(sc->sc_ah, bf->bf_desc);
  574. ath_buf_set_rate(sc, bf);
  575. ath_tx_txqaddbuf(sc, txq, &bf_q);
  576. continue;
  577. }
  578. /* setup first desc of aggregate */
  579. bf->bf_state.bf_type |= BUF_AGGR;
  580. ath_buf_set_rate(sc, bf);
  581. ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
  582. /* anchor last desc of aggregate */
  583. ath9k_hw_set11n_aggr_last(sc->sc_ah, bf->bf_lastbf->bf_desc);
  584. txq->axq_aggr_depth++;
  585. ath_tx_txqaddbuf(sc, txq, &bf_q);
  586. TX_STAT_INC(txq->axq_qnum, a_aggr);
  587. } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
  588. status != ATH_AGGR_BAW_CLOSED);
  589. }
  590. void ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
  591. u16 tid, u16 *ssn)
  592. {
  593. struct ath_atx_tid *txtid;
  594. struct ath_node *an;
  595. an = (struct ath_node *)sta->drv_priv;
  596. txtid = ATH_AN_2_TID(an, tid);
  597. txtid->state |= AGGR_ADDBA_PROGRESS;
  598. ath_tx_pause_tid(sc, txtid);
  599. *ssn = txtid->seq_start;
  600. }
  601. void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  602. {
  603. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  604. struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
  605. struct ath_txq *txq = &sc->tx.txq[txtid->ac->qnum];
  606. struct ath_buf *bf;
  607. struct list_head bf_head;
  608. INIT_LIST_HEAD(&bf_head);
  609. if (txtid->state & AGGR_CLEANUP)
  610. return;
  611. if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
  612. txtid->state &= ~AGGR_ADDBA_PROGRESS;
  613. return;
  614. }
  615. ath_tx_pause_tid(sc, txtid);
  616. /* drop all software retried frames and mark this TID */
  617. spin_lock_bh(&txq->axq_lock);
  618. while (!list_empty(&txtid->buf_q)) {
  619. bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
  620. if (!bf_isretried(bf)) {
  621. /*
  622. * NB: it's based on the assumption that
  623. * software retried frame will always stay
  624. * at the head of software queue.
  625. */
  626. break;
  627. }
  628. list_move_tail(&bf->list, &bf_head);
  629. ath_tx_update_baw(sc, txtid, bf->bf_seqno);
  630. ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
  631. }
  632. spin_unlock_bh(&txq->axq_lock);
  633. if (txtid->baw_head != txtid->baw_tail) {
  634. txtid->state |= AGGR_CLEANUP;
  635. } else {
  636. txtid->state &= ~AGGR_ADDBA_COMPLETE;
  637. ath_tx_flush_tid(sc, txtid);
  638. }
  639. }
  640. void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  641. {
  642. struct ath_atx_tid *txtid;
  643. struct ath_node *an;
  644. an = (struct ath_node *)sta->drv_priv;
  645. if (sc->sc_flags & SC_OP_TXAGGR) {
  646. txtid = ATH_AN_2_TID(an, tid);
  647. txtid->baw_size =
  648. IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
  649. txtid->state |= AGGR_ADDBA_COMPLETE;
  650. txtid->state &= ~AGGR_ADDBA_PROGRESS;
  651. ath_tx_resume_tid(sc, txtid);
  652. }
  653. }
  654. bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
  655. {
  656. struct ath_atx_tid *txtid;
  657. if (!(sc->sc_flags & SC_OP_TXAGGR))
  658. return false;
  659. txtid = ATH_AN_2_TID(an, tidno);
  660. if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
  661. return true;
  662. return false;
  663. }
  664. /********************/
  665. /* Queue Management */
  666. /********************/
  667. static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
  668. struct ath_txq *txq)
  669. {
  670. struct ath_atx_ac *ac, *ac_tmp;
  671. struct ath_atx_tid *tid, *tid_tmp;
  672. list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
  673. list_del(&ac->list);
  674. ac->sched = false;
  675. list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
  676. list_del(&tid->list);
  677. tid->sched = false;
  678. ath_tid_drain(sc, txq, tid);
  679. }
  680. }
  681. }
  682. struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
  683. {
  684. struct ath_hw *ah = sc->sc_ah;
  685. struct ath_common *common = ath9k_hw_common(ah);
  686. struct ath9k_tx_queue_info qi;
  687. int qnum;
  688. memset(&qi, 0, sizeof(qi));
  689. qi.tqi_subtype = subtype;
  690. qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
  691. qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  692. qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
  693. qi.tqi_physCompBuf = 0;
  694. /*
  695. * Enable interrupts only for EOL and DESC conditions.
  696. * We mark tx descriptors to receive a DESC interrupt
  697. * when a tx queue gets deep; otherwise waiting for the
  698. * EOL to reap descriptors. Note that this is done to
  699. * reduce interrupt load and this only defers reaping
  700. * descriptors, never transmitting frames. Aside from
  701. * reducing interrupts this also permits more concurrency.
  702. * The only potential downside is if the tx queue backs
  703. * up in which case the top half of the kernel may backup
  704. * due to a lack of tx descriptors.
  705. *
  706. * The UAPSD queue is an exception, since we take a desc-
  707. * based intr on the EOSP frames.
  708. */
  709. if (qtype == ATH9K_TX_QUEUE_UAPSD)
  710. qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
  711. else
  712. qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
  713. TXQ_FLAG_TXDESCINT_ENABLE;
  714. qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
  715. if (qnum == -1) {
  716. /*
  717. * NB: don't print a message, this happens
  718. * normally on parts with too few tx queues
  719. */
  720. return NULL;
  721. }
  722. if (qnum >= ARRAY_SIZE(sc->tx.txq)) {
  723. ath_print(common, ATH_DBG_FATAL,
  724. "qnum %u out of range, max %u!\n",
  725. qnum, (unsigned int)ARRAY_SIZE(sc->tx.txq));
  726. ath9k_hw_releasetxqueue(ah, qnum);
  727. return NULL;
  728. }
  729. if (!ATH_TXQ_SETUP(sc, qnum)) {
  730. struct ath_txq *txq = &sc->tx.txq[qnum];
  731. txq->axq_qnum = qnum;
  732. txq->axq_link = NULL;
  733. INIT_LIST_HEAD(&txq->axq_q);
  734. INIT_LIST_HEAD(&txq->axq_acq);
  735. spin_lock_init(&txq->axq_lock);
  736. txq->axq_depth = 0;
  737. txq->axq_aggr_depth = 0;
  738. txq->axq_linkbuf = NULL;
  739. txq->axq_tx_inprogress = false;
  740. sc->tx.txqsetup |= 1<<qnum;
  741. }
  742. return &sc->tx.txq[qnum];
  743. }
  744. int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
  745. {
  746. int qnum;
  747. switch (qtype) {
  748. case ATH9K_TX_QUEUE_DATA:
  749. if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
  750. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  751. "HAL AC %u out of range, max %zu!\n",
  752. haltype, ARRAY_SIZE(sc->tx.hwq_map));
  753. return -1;
  754. }
  755. qnum = sc->tx.hwq_map[haltype];
  756. break;
  757. case ATH9K_TX_QUEUE_BEACON:
  758. qnum = sc->beacon.beaconq;
  759. break;
  760. case ATH9K_TX_QUEUE_CAB:
  761. qnum = sc->beacon.cabq->axq_qnum;
  762. break;
  763. default:
  764. qnum = -1;
  765. }
  766. return qnum;
  767. }
  768. struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
  769. {
  770. struct ath_txq *txq = NULL;
  771. u16 skb_queue = skb_get_queue_mapping(skb);
  772. int qnum;
  773. qnum = ath_get_hal_qnum(skb_queue, sc);
  774. txq = &sc->tx.txq[qnum];
  775. spin_lock_bh(&txq->axq_lock);
  776. if (txq->axq_depth >= (ATH_TXBUF - 20)) {
  777. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_XMIT,
  778. "TX queue: %d is full, depth: %d\n",
  779. qnum, txq->axq_depth);
  780. ath_mac80211_stop_queue(sc, skb_queue);
  781. txq->stopped = 1;
  782. spin_unlock_bh(&txq->axq_lock);
  783. return NULL;
  784. }
  785. spin_unlock_bh(&txq->axq_lock);
  786. return txq;
  787. }
  788. int ath_txq_update(struct ath_softc *sc, int qnum,
  789. struct ath9k_tx_queue_info *qinfo)
  790. {
  791. struct ath_hw *ah = sc->sc_ah;
  792. int error = 0;
  793. struct ath9k_tx_queue_info qi;
  794. if (qnum == sc->beacon.beaconq) {
  795. /*
  796. * XXX: for beacon queue, we just save the parameter.
  797. * It will be picked up by ath_beaconq_config when
  798. * it's necessary.
  799. */
  800. sc->beacon.beacon_qi = *qinfo;
  801. return 0;
  802. }
  803. BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum);
  804. ath9k_hw_get_txq_props(ah, qnum, &qi);
  805. qi.tqi_aifs = qinfo->tqi_aifs;
  806. qi.tqi_cwmin = qinfo->tqi_cwmin;
  807. qi.tqi_cwmax = qinfo->tqi_cwmax;
  808. qi.tqi_burstTime = qinfo->tqi_burstTime;
  809. qi.tqi_readyTime = qinfo->tqi_readyTime;
  810. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  811. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  812. "Unable to update hardware queue %u!\n", qnum);
  813. error = -EIO;
  814. } else {
  815. ath9k_hw_resettxqueue(ah, qnum);
  816. }
  817. return error;
  818. }
  819. int ath_cabq_update(struct ath_softc *sc)
  820. {
  821. struct ath9k_tx_queue_info qi;
  822. int qnum = sc->beacon.cabq->axq_qnum;
  823. ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
  824. /*
  825. * Ensure the readytime % is within the bounds.
  826. */
  827. if (sc->config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
  828. sc->config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
  829. else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
  830. sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
  831. qi.tqi_readyTime = (sc->beacon_interval *
  832. sc->config.cabqReadytime) / 100;
  833. ath_txq_update(sc, qnum, &qi);
  834. return 0;
  835. }
  836. /*
  837. * Drain a given TX queue (could be Beacon or Data)
  838. *
  839. * This assumes output has been stopped and
  840. * we do not need to block ath_tx_tasklet.
  841. */
  842. void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
  843. {
  844. struct ath_buf *bf, *lastbf;
  845. struct list_head bf_head;
  846. INIT_LIST_HEAD(&bf_head);
  847. for (;;) {
  848. spin_lock_bh(&txq->axq_lock);
  849. if (list_empty(&txq->axq_q)) {
  850. txq->axq_link = NULL;
  851. txq->axq_linkbuf = NULL;
  852. spin_unlock_bh(&txq->axq_lock);
  853. break;
  854. }
  855. bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
  856. if (bf->bf_stale) {
  857. list_del(&bf->list);
  858. spin_unlock_bh(&txq->axq_lock);
  859. spin_lock_bh(&sc->tx.txbuflock);
  860. list_add_tail(&bf->list, &sc->tx.txbuf);
  861. spin_unlock_bh(&sc->tx.txbuflock);
  862. continue;
  863. }
  864. lastbf = bf->bf_lastbf;
  865. if (!retry_tx)
  866. lastbf->bf_desc->ds_txstat.ts_flags =
  867. ATH9K_TX_SW_ABORTED;
  868. /* remove ath_buf's of the same mpdu from txq */
  869. list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
  870. txq->axq_depth--;
  871. spin_unlock_bh(&txq->axq_lock);
  872. if (bf_isampdu(bf))
  873. ath_tx_complete_aggr(sc, txq, bf, &bf_head, 0);
  874. else
  875. ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
  876. }
  877. spin_lock_bh(&txq->axq_lock);
  878. txq->axq_tx_inprogress = false;
  879. spin_unlock_bh(&txq->axq_lock);
  880. /* flush any pending frames if aggregation is enabled */
  881. if (sc->sc_flags & SC_OP_TXAGGR) {
  882. if (!retry_tx) {
  883. spin_lock_bh(&txq->axq_lock);
  884. ath_txq_drain_pending_buffers(sc, txq);
  885. spin_unlock_bh(&txq->axq_lock);
  886. }
  887. }
  888. }
  889. void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
  890. {
  891. struct ath_hw *ah = sc->sc_ah;
  892. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  893. struct ath_txq *txq;
  894. int i, npend = 0;
  895. if (sc->sc_flags & SC_OP_INVALID)
  896. return;
  897. /* Stop beacon queue */
  898. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  899. /* Stop data queues */
  900. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  901. if (ATH_TXQ_SETUP(sc, i)) {
  902. txq = &sc->tx.txq[i];
  903. ath9k_hw_stoptxdma(ah, txq->axq_qnum);
  904. npend += ath9k_hw_numtxpending(ah, txq->axq_qnum);
  905. }
  906. }
  907. if (npend) {
  908. int r;
  909. ath_print(common, ATH_DBG_XMIT,
  910. "Unable to stop TxDMA. Reset HAL!\n");
  911. spin_lock_bh(&sc->sc_resetlock);
  912. r = ath9k_hw_reset(ah, sc->sc_ah->curchan, true);
  913. if (r)
  914. ath_print(common, ATH_DBG_FATAL,
  915. "Unable to reset hardware; reset status %d\n",
  916. r);
  917. spin_unlock_bh(&sc->sc_resetlock);
  918. }
  919. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  920. if (ATH_TXQ_SETUP(sc, i))
  921. ath_draintxq(sc, &sc->tx.txq[i], retry_tx);
  922. }
  923. }
  924. void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
  925. {
  926. ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
  927. sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
  928. }
  929. void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
  930. {
  931. struct ath_atx_ac *ac;
  932. struct ath_atx_tid *tid;
  933. if (list_empty(&txq->axq_acq))
  934. return;
  935. ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
  936. list_del(&ac->list);
  937. ac->sched = false;
  938. do {
  939. if (list_empty(&ac->tid_q))
  940. return;
  941. tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
  942. list_del(&tid->list);
  943. tid->sched = false;
  944. if (tid->paused)
  945. continue;
  946. ath_tx_sched_aggr(sc, txq, tid);
  947. /*
  948. * add tid to round-robin queue if more frames
  949. * are pending for the tid
  950. */
  951. if (!list_empty(&tid->buf_q))
  952. ath_tx_queue_tid(txq, tid);
  953. break;
  954. } while (!list_empty(&ac->tid_q));
  955. if (!list_empty(&ac->tid_q)) {
  956. if (!ac->sched) {
  957. ac->sched = true;
  958. list_add_tail(&ac->list, &txq->axq_acq);
  959. }
  960. }
  961. }
  962. int ath_tx_setup(struct ath_softc *sc, int haltype)
  963. {
  964. struct ath_txq *txq;
  965. if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
  966. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  967. "HAL AC %u out of range, max %zu!\n",
  968. haltype, ARRAY_SIZE(sc->tx.hwq_map));
  969. return 0;
  970. }
  971. txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
  972. if (txq != NULL) {
  973. sc->tx.hwq_map[haltype] = txq->axq_qnum;
  974. return 1;
  975. } else
  976. return 0;
  977. }
  978. /***********/
  979. /* TX, DMA */
  980. /***********/
  981. /*
  982. * Insert a chain of ath_buf (descriptors) on a txq and
  983. * assume the descriptors are already chained together by caller.
  984. */
  985. static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
  986. struct list_head *head)
  987. {
  988. struct ath_hw *ah = sc->sc_ah;
  989. struct ath_common *common = ath9k_hw_common(ah);
  990. struct ath_buf *bf;
  991. /*
  992. * Insert the frame on the outbound list and
  993. * pass it on to the hardware.
  994. */
  995. if (list_empty(head))
  996. return;
  997. bf = list_first_entry(head, struct ath_buf, list);
  998. list_splice_tail_init(head, &txq->axq_q);
  999. txq->axq_depth++;
  1000. txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
  1001. ath_print(common, ATH_DBG_QUEUE,
  1002. "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
  1003. if (txq->axq_link == NULL) {
  1004. ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
  1005. ath_print(common, ATH_DBG_XMIT,
  1006. "TXDP[%u] = %llx (%p)\n",
  1007. txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
  1008. } else {
  1009. *txq->axq_link = bf->bf_daddr;
  1010. ath_print(common, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n",
  1011. txq->axq_qnum, txq->axq_link,
  1012. ito64(bf->bf_daddr), bf->bf_desc);
  1013. }
  1014. txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
  1015. ath9k_hw_txstart(ah, txq->axq_qnum);
  1016. }
  1017. static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
  1018. {
  1019. struct ath_buf *bf = NULL;
  1020. spin_lock_bh(&sc->tx.txbuflock);
  1021. if (unlikely(list_empty(&sc->tx.txbuf))) {
  1022. spin_unlock_bh(&sc->tx.txbuflock);
  1023. return NULL;
  1024. }
  1025. bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
  1026. list_del(&bf->list);
  1027. spin_unlock_bh(&sc->tx.txbuflock);
  1028. return bf;
  1029. }
  1030. static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
  1031. struct list_head *bf_head,
  1032. struct ath_tx_control *txctl)
  1033. {
  1034. struct ath_buf *bf;
  1035. bf = list_first_entry(bf_head, struct ath_buf, list);
  1036. bf->bf_state.bf_type |= BUF_AMPDU;
  1037. TX_STAT_INC(txctl->txq->axq_qnum, a_queued);
  1038. /*
  1039. * Do not queue to h/w when any of the following conditions is true:
  1040. * - there are pending frames in software queue
  1041. * - the TID is currently paused for ADDBA/BAR request
  1042. * - seqno is not within block-ack window
  1043. * - h/w queue depth exceeds low water mark
  1044. */
  1045. if (!list_empty(&tid->buf_q) || tid->paused ||
  1046. !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
  1047. txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
  1048. /*
  1049. * Add this frame to software queue for scheduling later
  1050. * for aggregation.
  1051. */
  1052. list_move_tail(&bf->list, &tid->buf_q);
  1053. ath_tx_queue_tid(txctl->txq, tid);
  1054. return;
  1055. }
  1056. /* Add sub-frame to BAW */
  1057. ath_tx_addto_baw(sc, tid, bf);
  1058. /* Queue to h/w without aggregation */
  1059. bf->bf_nframes = 1;
  1060. bf->bf_lastbf = bf;
  1061. ath_buf_set_rate(sc, bf);
  1062. ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
  1063. }
  1064. static void ath_tx_send_ht_normal(struct ath_softc *sc, struct ath_txq *txq,
  1065. struct ath_atx_tid *tid,
  1066. struct list_head *bf_head)
  1067. {
  1068. struct ath_buf *bf;
  1069. bf = list_first_entry(bf_head, struct ath_buf, list);
  1070. bf->bf_state.bf_type &= ~BUF_AMPDU;
  1071. /* update starting sequence number for subsequent ADDBA request */
  1072. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  1073. bf->bf_nframes = 1;
  1074. bf->bf_lastbf = bf;
  1075. ath_buf_set_rate(sc, bf);
  1076. ath_tx_txqaddbuf(sc, txq, bf_head);
  1077. TX_STAT_INC(txq->axq_qnum, queued);
  1078. }
  1079. static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
  1080. struct list_head *bf_head)
  1081. {
  1082. struct ath_buf *bf;
  1083. bf = list_first_entry(bf_head, struct ath_buf, list);
  1084. bf->bf_lastbf = bf;
  1085. bf->bf_nframes = 1;
  1086. ath_buf_set_rate(sc, bf);
  1087. ath_tx_txqaddbuf(sc, txq, bf_head);
  1088. TX_STAT_INC(txq->axq_qnum, queued);
  1089. }
  1090. static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
  1091. {
  1092. struct ieee80211_hdr *hdr;
  1093. enum ath9k_pkt_type htype;
  1094. __le16 fc;
  1095. hdr = (struct ieee80211_hdr *)skb->data;
  1096. fc = hdr->frame_control;
  1097. if (ieee80211_is_beacon(fc))
  1098. htype = ATH9K_PKT_TYPE_BEACON;
  1099. else if (ieee80211_is_probe_resp(fc))
  1100. htype = ATH9K_PKT_TYPE_PROBE_RESP;
  1101. else if (ieee80211_is_atim(fc))
  1102. htype = ATH9K_PKT_TYPE_ATIM;
  1103. else if (ieee80211_is_pspoll(fc))
  1104. htype = ATH9K_PKT_TYPE_PSPOLL;
  1105. else
  1106. htype = ATH9K_PKT_TYPE_NORMAL;
  1107. return htype;
  1108. }
  1109. static bool is_pae(struct sk_buff *skb)
  1110. {
  1111. struct ieee80211_hdr *hdr;
  1112. __le16 fc;
  1113. hdr = (struct ieee80211_hdr *)skb->data;
  1114. fc = hdr->frame_control;
  1115. if (ieee80211_is_data(fc)) {
  1116. if (ieee80211_is_nullfunc(fc) ||
  1117. /* Port Access Entity (IEEE 802.1X) */
  1118. (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  1119. return true;
  1120. }
  1121. }
  1122. return false;
  1123. }
  1124. static int get_hw_crypto_keytype(struct sk_buff *skb)
  1125. {
  1126. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1127. if (tx_info->control.hw_key) {
  1128. if (tx_info->control.hw_key->alg == ALG_WEP)
  1129. return ATH9K_KEY_TYPE_WEP;
  1130. else if (tx_info->control.hw_key->alg == ALG_TKIP)
  1131. return ATH9K_KEY_TYPE_TKIP;
  1132. else if (tx_info->control.hw_key->alg == ALG_CCMP)
  1133. return ATH9K_KEY_TYPE_AES;
  1134. }
  1135. return ATH9K_KEY_TYPE_CLEAR;
  1136. }
  1137. static void assign_aggr_tid_seqno(struct sk_buff *skb,
  1138. struct ath_buf *bf)
  1139. {
  1140. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1141. struct ieee80211_hdr *hdr;
  1142. struct ath_node *an;
  1143. struct ath_atx_tid *tid;
  1144. __le16 fc;
  1145. u8 *qc;
  1146. if (!tx_info->control.sta)
  1147. return;
  1148. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  1149. hdr = (struct ieee80211_hdr *)skb->data;
  1150. fc = hdr->frame_control;
  1151. if (ieee80211_is_data_qos(fc)) {
  1152. qc = ieee80211_get_qos_ctl(hdr);
  1153. bf->bf_tidno = qc[0] & 0xf;
  1154. }
  1155. /*
  1156. * For HT capable stations, we save tidno for later use.
  1157. * We also override seqno set by upper layer with the one
  1158. * in tx aggregation state.
  1159. *
  1160. * If fragmentation is on, the sequence number is
  1161. * not overridden, since it has been
  1162. * incremented by the fragmentation routine.
  1163. *
  1164. * FIXME: check if the fragmentation threshold exceeds
  1165. * IEEE80211 max.
  1166. */
  1167. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  1168. hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
  1169. IEEE80211_SEQ_SEQ_SHIFT);
  1170. bf->bf_seqno = tid->seq_next;
  1171. INCR(tid->seq_next, IEEE80211_SEQ_MAX);
  1172. }
  1173. static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
  1174. struct ath_txq *txq)
  1175. {
  1176. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1177. int flags = 0;
  1178. flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
  1179. flags |= ATH9K_TXDESC_INTREQ;
  1180. if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
  1181. flags |= ATH9K_TXDESC_NOACK;
  1182. return flags;
  1183. }
  1184. /*
  1185. * rix - rate index
  1186. * pktlen - total bytes (delims + data + fcs + pads + pad delims)
  1187. * width - 0 for 20 MHz, 1 for 40 MHz
  1188. * half_gi - to use 4us v/s 3.6 us for symbol time
  1189. */
  1190. static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
  1191. int width, int half_gi, bool shortPreamble)
  1192. {
  1193. const struct ath_rate_table *rate_table = sc->cur_rate_table;
  1194. u32 nbits, nsymbits, duration, nsymbols;
  1195. u8 rc;
  1196. int streams, pktlen;
  1197. pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
  1198. rc = rate_table->info[rix].ratecode;
  1199. /* for legacy rates, use old function to compute packet duration */
  1200. if (!IS_HT_RATE(rc))
  1201. return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
  1202. rix, shortPreamble);
  1203. /* find number of symbols: PLCP + data */
  1204. nbits = (pktlen << 3) + OFDM_PLCP_BITS;
  1205. nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
  1206. nsymbols = (nbits + nsymbits - 1) / nsymbits;
  1207. if (!half_gi)
  1208. duration = SYMBOL_TIME(nsymbols);
  1209. else
  1210. duration = SYMBOL_TIME_HALFGI(nsymbols);
  1211. /* addup duration for legacy/ht training and signal fields */
  1212. streams = HT_RC_2_STREAMS(rc);
  1213. duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
  1214. return duration;
  1215. }
  1216. static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
  1217. {
  1218. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1219. const struct ath_rate_table *rt = sc->cur_rate_table;
  1220. struct ath9k_11n_rate_series series[4];
  1221. struct sk_buff *skb;
  1222. struct ieee80211_tx_info *tx_info;
  1223. struct ieee80211_tx_rate *rates;
  1224. struct ieee80211_hdr *hdr;
  1225. int i, flags = 0;
  1226. u8 rix = 0, ctsrate = 0;
  1227. bool is_pspoll;
  1228. memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
  1229. skb = bf->bf_mpdu;
  1230. tx_info = IEEE80211_SKB_CB(skb);
  1231. rates = tx_info->control.rates;
  1232. hdr = (struct ieee80211_hdr *)skb->data;
  1233. is_pspoll = ieee80211_is_pspoll(hdr->frame_control);
  1234. /*
  1235. * We check if Short Preamble is needed for the CTS rate by
  1236. * checking the BSS's global flag.
  1237. * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
  1238. */
  1239. if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
  1240. ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode |
  1241. rt->info[tx_info->control.rts_cts_rate_idx].short_preamble;
  1242. else
  1243. ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode;
  1244. /*
  1245. * ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive.
  1246. * Check the first rate in the series to decide whether RTS/CTS
  1247. * or CTS-to-self has to be used.
  1248. */
  1249. if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  1250. flags = ATH9K_TXDESC_CTSENA;
  1251. else if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1252. flags = ATH9K_TXDESC_RTSENA;
  1253. /* FIXME: Handle aggregation protection */
  1254. if (sc->config.ath_aggr_prot &&
  1255. (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
  1256. flags = ATH9K_TXDESC_RTSENA;
  1257. }
  1258. /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
  1259. if (bf_isaggr(bf) && (bf->bf_al > sc->sc_ah->caps.rts_aggr_limit))
  1260. flags &= ~(ATH9K_TXDESC_RTSENA);
  1261. for (i = 0; i < 4; i++) {
  1262. if (!rates[i].count || (rates[i].idx < 0))
  1263. continue;
  1264. rix = rates[i].idx;
  1265. series[i].Tries = rates[i].count;
  1266. series[i].ChSel = common->tx_chainmask;
  1267. if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  1268. series[i].Rate = rt->info[rix].ratecode |
  1269. rt->info[rix].short_preamble;
  1270. else
  1271. series[i].Rate = rt->info[rix].ratecode;
  1272. if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1273. series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
  1274. if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1275. series[i].RateFlags |= ATH9K_RATESERIES_2040;
  1276. if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
  1277. series[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
  1278. series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
  1279. (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
  1280. (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
  1281. (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE));
  1282. }
  1283. /* set dur_update_en for l-sig computation except for PS-Poll frames */
  1284. ath9k_hw_set11n_ratescenario(sc->sc_ah, bf->bf_desc,
  1285. bf->bf_lastbf->bf_desc,
  1286. !is_pspoll, ctsrate,
  1287. 0, series, 4, flags);
  1288. if (sc->config.ath_aggr_prot && flags)
  1289. ath9k_hw_set11n_burstduration(sc->sc_ah, bf->bf_desc, 8192);
  1290. }
  1291. static int ath_tx_setup_buffer(struct ieee80211_hw *hw, struct ath_buf *bf,
  1292. struct sk_buff *skb,
  1293. struct ath_tx_control *txctl)
  1294. {
  1295. struct ath_wiphy *aphy = hw->priv;
  1296. struct ath_softc *sc = aphy->sc;
  1297. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1298. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1299. struct ath_tx_info_priv *tx_info_priv;
  1300. int hdrlen;
  1301. __le16 fc;
  1302. tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
  1303. if (unlikely(!tx_info_priv))
  1304. return -ENOMEM;
  1305. tx_info->rate_driver_data[0] = tx_info_priv;
  1306. tx_info_priv->aphy = aphy;
  1307. tx_info_priv->frame_type = txctl->frame_type;
  1308. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1309. fc = hdr->frame_control;
  1310. ATH_TXBUF_RESET(bf);
  1311. bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
  1312. if (conf_is_ht(&hw->conf) && !is_pae(skb))
  1313. bf->bf_state.bf_type |= BUF_HT;
  1314. bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
  1315. bf->bf_keytype = get_hw_crypto_keytype(skb);
  1316. if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
  1317. bf->bf_frmlen += tx_info->control.hw_key->icv_len;
  1318. bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
  1319. } else {
  1320. bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
  1321. }
  1322. if (ieee80211_is_data_qos(fc) && (sc->sc_flags & SC_OP_TXAGGR))
  1323. assign_aggr_tid_seqno(skb, bf);
  1324. bf->bf_mpdu = skb;
  1325. bf->bf_dmacontext = dma_map_single(sc->dev, skb->data,
  1326. skb->len, DMA_TO_DEVICE);
  1327. if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
  1328. bf->bf_mpdu = NULL;
  1329. kfree(tx_info_priv);
  1330. tx_info->rate_driver_data[0] = NULL;
  1331. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  1332. "dma_mapping_error() on TX\n");
  1333. return -ENOMEM;
  1334. }
  1335. bf->bf_buf_addr = bf->bf_dmacontext;
  1336. return 0;
  1337. }
  1338. /* FIXME: tx power */
  1339. static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
  1340. struct ath_tx_control *txctl)
  1341. {
  1342. struct sk_buff *skb = bf->bf_mpdu;
  1343. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1344. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1345. struct ath_node *an = NULL;
  1346. struct list_head bf_head;
  1347. struct ath_desc *ds;
  1348. struct ath_atx_tid *tid;
  1349. struct ath_hw *ah = sc->sc_ah;
  1350. int frm_type;
  1351. __le16 fc;
  1352. frm_type = get_hw_packet_type(skb);
  1353. fc = hdr->frame_control;
  1354. INIT_LIST_HEAD(&bf_head);
  1355. list_add_tail(&bf->list, &bf_head);
  1356. ds = bf->bf_desc;
  1357. ds->ds_link = 0;
  1358. ds->ds_data = bf->bf_buf_addr;
  1359. ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
  1360. bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
  1361. ath9k_hw_filltxdesc(ah, ds,
  1362. skb->len, /* segment length */
  1363. true, /* first segment */
  1364. true, /* last segment */
  1365. ds); /* first descriptor */
  1366. spin_lock_bh(&txctl->txq->axq_lock);
  1367. if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
  1368. tx_info->control.sta) {
  1369. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  1370. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  1371. if (!ieee80211_is_data_qos(fc)) {
  1372. ath_tx_send_normal(sc, txctl->txq, &bf_head);
  1373. goto tx_done;
  1374. }
  1375. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
  1376. /*
  1377. * Try aggregation if it's a unicast data frame
  1378. * and the destination is HT capable.
  1379. */
  1380. ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
  1381. } else {
  1382. /*
  1383. * Send this frame as regular when ADDBA
  1384. * exchange is neither complete nor pending.
  1385. */
  1386. ath_tx_send_ht_normal(sc, txctl->txq,
  1387. tid, &bf_head);
  1388. }
  1389. } else {
  1390. ath_tx_send_normal(sc, txctl->txq, &bf_head);
  1391. }
  1392. tx_done:
  1393. spin_unlock_bh(&txctl->txq->axq_lock);
  1394. }
  1395. /* Upon failure caller should free skb */
  1396. int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
  1397. struct ath_tx_control *txctl)
  1398. {
  1399. struct ath_wiphy *aphy = hw->priv;
  1400. struct ath_softc *sc = aphy->sc;
  1401. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1402. struct ath_buf *bf;
  1403. int r;
  1404. bf = ath_tx_get_buffer(sc);
  1405. if (!bf) {
  1406. ath_print(common, ATH_DBG_XMIT, "TX buffers are full\n");
  1407. return -1;
  1408. }
  1409. r = ath_tx_setup_buffer(hw, bf, skb, txctl);
  1410. if (unlikely(r)) {
  1411. struct ath_txq *txq = txctl->txq;
  1412. ath_print(common, ATH_DBG_FATAL, "TX mem alloc failure\n");
  1413. /* upon ath_tx_processq() this TX queue will be resumed, we
  1414. * guarantee this will happen by knowing beforehand that
  1415. * we will at least have to run TX completionon one buffer
  1416. * on the queue */
  1417. spin_lock_bh(&txq->axq_lock);
  1418. if (sc->tx.txq[txq->axq_qnum].axq_depth > 1) {
  1419. ath_mac80211_stop_queue(sc, skb_get_queue_mapping(skb));
  1420. txq->stopped = 1;
  1421. }
  1422. spin_unlock_bh(&txq->axq_lock);
  1423. spin_lock_bh(&sc->tx.txbuflock);
  1424. list_add_tail(&bf->list, &sc->tx.txbuf);
  1425. spin_unlock_bh(&sc->tx.txbuflock);
  1426. return r;
  1427. }
  1428. ath_tx_start_dma(sc, bf, txctl);
  1429. return 0;
  1430. }
  1431. void ath_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb)
  1432. {
  1433. struct ath_wiphy *aphy = hw->priv;
  1434. struct ath_softc *sc = aphy->sc;
  1435. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1436. int hdrlen, padsize;
  1437. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1438. struct ath_tx_control txctl;
  1439. memset(&txctl, 0, sizeof(struct ath_tx_control));
  1440. /*
  1441. * As a temporary workaround, assign seq# here; this will likely need
  1442. * to be cleaned up to work better with Beacon transmission and virtual
  1443. * BSSes.
  1444. */
  1445. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1446. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1447. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1448. sc->tx.seq_no += 0x10;
  1449. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1450. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1451. }
  1452. /* Add the padding after the header if this is not already done */
  1453. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1454. if (hdrlen & 3) {
  1455. padsize = hdrlen % 4;
  1456. if (skb_headroom(skb) < padsize) {
  1457. ath_print(common, ATH_DBG_XMIT,
  1458. "TX CABQ padding failed\n");
  1459. dev_kfree_skb_any(skb);
  1460. return;
  1461. }
  1462. skb_push(skb, padsize);
  1463. memmove(skb->data, skb->data + padsize, hdrlen);
  1464. }
  1465. txctl.txq = sc->beacon.cabq;
  1466. ath_print(common, ATH_DBG_XMIT,
  1467. "transmitting CABQ packet, skb: %p\n", skb);
  1468. if (ath_tx_start(hw, skb, &txctl) != 0) {
  1469. ath_print(common, ATH_DBG_XMIT, "CABQ TX failed\n");
  1470. goto exit;
  1471. }
  1472. return;
  1473. exit:
  1474. dev_kfree_skb_any(skb);
  1475. }
  1476. /*****************/
  1477. /* TX Completion */
  1478. /*****************/
  1479. static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
  1480. int tx_flags)
  1481. {
  1482. struct ieee80211_hw *hw = sc->hw;
  1483. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1484. struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1485. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1486. int hdrlen, padsize;
  1487. int frame_type = ATH9K_NOT_INTERNAL;
  1488. ath_print(common, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
  1489. if (tx_info_priv) {
  1490. hw = tx_info_priv->aphy->hw;
  1491. frame_type = tx_info_priv->frame_type;
  1492. }
  1493. if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
  1494. tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  1495. kfree(tx_info_priv);
  1496. tx_info->rate_driver_data[0] = NULL;
  1497. }
  1498. if (tx_flags & ATH_TX_BAR)
  1499. tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1500. if (!(tx_flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
  1501. /* Frame was ACKed */
  1502. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  1503. }
  1504. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1505. padsize = hdrlen & 3;
  1506. if (padsize && hdrlen >= 24) {
  1507. /*
  1508. * Remove MAC header padding before giving the frame back to
  1509. * mac80211.
  1510. */
  1511. memmove(skb->data + padsize, skb->data, hdrlen);
  1512. skb_pull(skb, padsize);
  1513. }
  1514. if (sc->sc_flags & SC_OP_WAIT_FOR_TX_ACK) {
  1515. sc->sc_flags &= ~SC_OP_WAIT_FOR_TX_ACK;
  1516. ath_print(common, ATH_DBG_PS,
  1517. "Going back to sleep after having "
  1518. "received TX status (0x%x)\n",
  1519. sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
  1520. SC_OP_WAIT_FOR_CAB |
  1521. SC_OP_WAIT_FOR_PSPOLL_DATA |
  1522. SC_OP_WAIT_FOR_TX_ACK));
  1523. }
  1524. if (frame_type == ATH9K_NOT_INTERNAL)
  1525. ieee80211_tx_status(hw, skb);
  1526. else
  1527. ath9k_tx_status(hw, skb);
  1528. }
  1529. static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
  1530. struct ath_txq *txq,
  1531. struct list_head *bf_q,
  1532. int txok, int sendbar)
  1533. {
  1534. struct sk_buff *skb = bf->bf_mpdu;
  1535. unsigned long flags;
  1536. int tx_flags = 0;
  1537. if (sendbar)
  1538. tx_flags = ATH_TX_BAR;
  1539. if (!txok) {
  1540. tx_flags |= ATH_TX_ERROR;
  1541. if (bf_isxretried(bf))
  1542. tx_flags |= ATH_TX_XRETRY;
  1543. }
  1544. dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
  1545. ath_tx_complete(sc, skb, tx_flags);
  1546. ath_debug_stat_tx(sc, txq, bf);
  1547. /*
  1548. * Return the list of ath_buf of this mpdu to free queue
  1549. */
  1550. spin_lock_irqsave(&sc->tx.txbuflock, flags);
  1551. list_splice_tail_init(bf_q, &sc->tx.txbuf);
  1552. spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
  1553. }
  1554. static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
  1555. int txok)
  1556. {
  1557. struct ath_buf *bf_last = bf->bf_lastbf;
  1558. struct ath_desc *ds = bf_last->bf_desc;
  1559. u16 seq_st = 0;
  1560. u32 ba[WME_BA_BMP_SIZE >> 5];
  1561. int ba_index;
  1562. int nbad = 0;
  1563. int isaggr = 0;
  1564. if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
  1565. return 0;
  1566. isaggr = bf_isaggr(bf);
  1567. if (isaggr) {
  1568. seq_st = ATH_DS_BA_SEQ(ds);
  1569. memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
  1570. }
  1571. while (bf) {
  1572. ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
  1573. if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
  1574. nbad++;
  1575. bf = bf->bf_next;
  1576. }
  1577. return nbad;
  1578. }
  1579. static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
  1580. int nbad, int txok, bool update_rc)
  1581. {
  1582. struct sk_buff *skb = bf->bf_mpdu;
  1583. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1584. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1585. struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1586. struct ieee80211_hw *hw = tx_info_priv->aphy->hw;
  1587. u8 i, tx_rateindex;
  1588. if (txok)
  1589. tx_info->status.ack_signal = ds->ds_txstat.ts_rssi;
  1590. tx_rateindex = ds->ds_txstat.ts_rateindex;
  1591. WARN_ON(tx_rateindex >= hw->max_rates);
  1592. tx_info_priv->update_rc = update_rc;
  1593. if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
  1594. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  1595. if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
  1596. (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0 && update_rc) {
  1597. if (ieee80211_is_data(hdr->frame_control)) {
  1598. memcpy(&tx_info_priv->tx, &ds->ds_txstat,
  1599. sizeof(tx_info_priv->tx));
  1600. tx_info_priv->n_frames = bf->bf_nframes;
  1601. tx_info_priv->n_bad_frames = nbad;
  1602. }
  1603. }
  1604. for (i = tx_rateindex + 1; i < hw->max_rates; i++)
  1605. tx_info->status.rates[i].count = 0;
  1606. tx_info->status.rates[tx_rateindex].count = bf->bf_retries + 1;
  1607. }
  1608. static void ath_wake_mac80211_queue(struct ath_softc *sc, struct ath_txq *txq)
  1609. {
  1610. int qnum;
  1611. spin_lock_bh(&txq->axq_lock);
  1612. if (txq->stopped &&
  1613. sc->tx.txq[txq->axq_qnum].axq_depth <= (ATH_TXBUF - 20)) {
  1614. qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
  1615. if (qnum != -1) {
  1616. ath_mac80211_start_queue(sc, qnum);
  1617. txq->stopped = 0;
  1618. }
  1619. }
  1620. spin_unlock_bh(&txq->axq_lock);
  1621. }
  1622. static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
  1623. {
  1624. struct ath_hw *ah = sc->sc_ah;
  1625. struct ath_common *common = ath9k_hw_common(ah);
  1626. struct ath_buf *bf, *lastbf, *bf_held = NULL;
  1627. struct list_head bf_head;
  1628. struct ath_desc *ds;
  1629. int txok;
  1630. int status;
  1631. ath_print(common, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
  1632. txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
  1633. txq->axq_link);
  1634. for (;;) {
  1635. spin_lock_bh(&txq->axq_lock);
  1636. if (list_empty(&txq->axq_q)) {
  1637. txq->axq_link = NULL;
  1638. txq->axq_linkbuf = NULL;
  1639. spin_unlock_bh(&txq->axq_lock);
  1640. break;
  1641. }
  1642. bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
  1643. /*
  1644. * There is a race condition that a BH gets scheduled
  1645. * after sw writes TxE and before hw re-load the last
  1646. * descriptor to get the newly chained one.
  1647. * Software must keep the last DONE descriptor as a
  1648. * holding descriptor - software does so by marking
  1649. * it with the STALE flag.
  1650. */
  1651. bf_held = NULL;
  1652. if (bf->bf_stale) {
  1653. bf_held = bf;
  1654. if (list_is_last(&bf_held->list, &txq->axq_q)) {
  1655. spin_unlock_bh(&txq->axq_lock);
  1656. break;
  1657. } else {
  1658. bf = list_entry(bf_held->list.next,
  1659. struct ath_buf, list);
  1660. }
  1661. }
  1662. lastbf = bf->bf_lastbf;
  1663. ds = lastbf->bf_desc;
  1664. status = ath9k_hw_txprocdesc(ah, ds);
  1665. if (status == -EINPROGRESS) {
  1666. spin_unlock_bh(&txq->axq_lock);
  1667. break;
  1668. }
  1669. if (bf->bf_desc == txq->axq_lastdsWithCTS)
  1670. txq->axq_lastdsWithCTS = NULL;
  1671. if (ds == txq->axq_gatingds)
  1672. txq->axq_gatingds = NULL;
  1673. /*
  1674. * Remove ath_buf's of the same transmit unit from txq,
  1675. * however leave the last descriptor back as the holding
  1676. * descriptor for hw.
  1677. */
  1678. lastbf->bf_stale = true;
  1679. INIT_LIST_HEAD(&bf_head);
  1680. if (!list_is_singular(&lastbf->list))
  1681. list_cut_position(&bf_head,
  1682. &txq->axq_q, lastbf->list.prev);
  1683. txq->axq_depth--;
  1684. if (bf_isaggr(bf))
  1685. txq->axq_aggr_depth--;
  1686. txok = (ds->ds_txstat.ts_status == 0);
  1687. txq->axq_tx_inprogress = false;
  1688. spin_unlock_bh(&txq->axq_lock);
  1689. if (bf_held) {
  1690. spin_lock_bh(&sc->tx.txbuflock);
  1691. list_move_tail(&bf_held->list, &sc->tx.txbuf);
  1692. spin_unlock_bh(&sc->tx.txbuflock);
  1693. }
  1694. if (!bf_isampdu(bf)) {
  1695. /*
  1696. * This frame is sent out as a single frame.
  1697. * Use hardware retry status for this frame.
  1698. */
  1699. bf->bf_retries = ds->ds_txstat.ts_longretry;
  1700. if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
  1701. bf->bf_state.bf_type |= BUF_XRETRY;
  1702. ath_tx_rc_status(bf, ds, 0, txok, true);
  1703. }
  1704. if (bf_isampdu(bf))
  1705. ath_tx_complete_aggr(sc, txq, bf, &bf_head, txok);
  1706. else
  1707. ath_tx_complete_buf(sc, bf, txq, &bf_head, txok, 0);
  1708. ath_wake_mac80211_queue(sc, txq);
  1709. spin_lock_bh(&txq->axq_lock);
  1710. if (sc->sc_flags & SC_OP_TXAGGR)
  1711. ath_txq_schedule(sc, txq);
  1712. spin_unlock_bh(&txq->axq_lock);
  1713. }
  1714. }
  1715. static void ath_tx_complete_poll_work(struct work_struct *work)
  1716. {
  1717. struct ath_softc *sc = container_of(work, struct ath_softc,
  1718. tx_complete_work.work);
  1719. struct ath_txq *txq;
  1720. int i;
  1721. bool needreset = false;
  1722. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1723. if (ATH_TXQ_SETUP(sc, i)) {
  1724. txq = &sc->tx.txq[i];
  1725. spin_lock_bh(&txq->axq_lock);
  1726. if (txq->axq_depth) {
  1727. if (txq->axq_tx_inprogress) {
  1728. needreset = true;
  1729. spin_unlock_bh(&txq->axq_lock);
  1730. break;
  1731. } else {
  1732. txq->axq_tx_inprogress = true;
  1733. }
  1734. }
  1735. spin_unlock_bh(&txq->axq_lock);
  1736. }
  1737. if (needreset) {
  1738. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET,
  1739. "tx hung, resetting the chip\n");
  1740. ath9k_ps_wakeup(sc);
  1741. ath_reset(sc, false);
  1742. ath9k_ps_restore(sc);
  1743. }
  1744. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
  1745. msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
  1746. }
  1747. void ath_tx_tasklet(struct ath_softc *sc)
  1748. {
  1749. int i;
  1750. u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
  1751. ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
  1752. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1753. if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
  1754. ath_tx_processq(sc, &sc->tx.txq[i]);
  1755. }
  1756. }
  1757. /*****************/
  1758. /* Init, Cleanup */
  1759. /*****************/
  1760. int ath_tx_init(struct ath_softc *sc, int nbufs)
  1761. {
  1762. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1763. int error = 0;
  1764. spin_lock_init(&sc->tx.txbuflock);
  1765. error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
  1766. "tx", nbufs, 1);
  1767. if (error != 0) {
  1768. ath_print(common, ATH_DBG_FATAL,
  1769. "Failed to allocate tx descriptors: %d\n", error);
  1770. goto err;
  1771. }
  1772. error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
  1773. "beacon", ATH_BCBUF, 1);
  1774. if (error != 0) {
  1775. ath_print(common, ATH_DBG_FATAL,
  1776. "Failed to allocate beacon descriptors: %d\n", error);
  1777. goto err;
  1778. }
  1779. INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work);
  1780. err:
  1781. if (error != 0)
  1782. ath_tx_cleanup(sc);
  1783. return error;
  1784. }
  1785. void ath_tx_cleanup(struct ath_softc *sc)
  1786. {
  1787. if (sc->beacon.bdma.dd_desc_len != 0)
  1788. ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
  1789. if (sc->tx.txdma.dd_desc_len != 0)
  1790. ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
  1791. }
  1792. void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
  1793. {
  1794. struct ath_atx_tid *tid;
  1795. struct ath_atx_ac *ac;
  1796. int tidno, acno;
  1797. for (tidno = 0, tid = &an->tid[tidno];
  1798. tidno < WME_NUM_TID;
  1799. tidno++, tid++) {
  1800. tid->an = an;
  1801. tid->tidno = tidno;
  1802. tid->seq_start = tid->seq_next = 0;
  1803. tid->baw_size = WME_MAX_BA;
  1804. tid->baw_head = tid->baw_tail = 0;
  1805. tid->sched = false;
  1806. tid->paused = false;
  1807. tid->state &= ~AGGR_CLEANUP;
  1808. INIT_LIST_HEAD(&tid->buf_q);
  1809. acno = TID_TO_WME_AC(tidno);
  1810. tid->ac = &an->ac[acno];
  1811. tid->state &= ~AGGR_ADDBA_COMPLETE;
  1812. tid->state &= ~AGGR_ADDBA_PROGRESS;
  1813. }
  1814. for (acno = 0, ac = &an->ac[acno];
  1815. acno < WME_NUM_AC; acno++, ac++) {
  1816. ac->sched = false;
  1817. INIT_LIST_HEAD(&ac->tid_q);
  1818. switch (acno) {
  1819. case WME_AC_BE:
  1820. ac->qnum = ath_tx_get_qnum(sc,
  1821. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
  1822. break;
  1823. case WME_AC_BK:
  1824. ac->qnum = ath_tx_get_qnum(sc,
  1825. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
  1826. break;
  1827. case WME_AC_VI:
  1828. ac->qnum = ath_tx_get_qnum(sc,
  1829. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
  1830. break;
  1831. case WME_AC_VO:
  1832. ac->qnum = ath_tx_get_qnum(sc,
  1833. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
  1834. break;
  1835. }
  1836. }
  1837. }
  1838. void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
  1839. {
  1840. int i;
  1841. struct ath_atx_ac *ac, *ac_tmp;
  1842. struct ath_atx_tid *tid, *tid_tmp;
  1843. struct ath_txq *txq;
  1844. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1845. if (ATH_TXQ_SETUP(sc, i)) {
  1846. txq = &sc->tx.txq[i];
  1847. spin_lock(&txq->axq_lock);
  1848. list_for_each_entry_safe(ac,
  1849. ac_tmp, &txq->axq_acq, list) {
  1850. tid = list_first_entry(&ac->tid_q,
  1851. struct ath_atx_tid, list);
  1852. if (tid && tid->an != an)
  1853. continue;
  1854. list_del(&ac->list);
  1855. ac->sched = false;
  1856. list_for_each_entry_safe(tid,
  1857. tid_tmp, &ac->tid_q, list) {
  1858. list_del(&tid->list);
  1859. tid->sched = false;
  1860. ath_tid_drain(sc, txq, tid);
  1861. tid->state &= ~AGGR_ADDBA_COMPLETE;
  1862. tid->state &= ~AGGR_CLEANUP;
  1863. }
  1864. }
  1865. spin_unlock(&txq->axq_lock);
  1866. }
  1867. }
  1868. }