xmit.c 57 KB

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