xmit.c 57 KB

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