xmit.c 57 KB

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