xmit.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/dma-mapping.h>
  17. #include "ath9k.h"
  18. #include "ar9003_mac.h"
  19. #define BITS_PER_BYTE 8
  20. #define OFDM_PLCP_BITS 22
  21. #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
  22. #define L_STF 8
  23. #define L_LTF 8
  24. #define L_SIG 4
  25. #define HT_SIG 8
  26. #define HT_STF 4
  27. #define HT_LTF(_ns) (4 * (_ns))
  28. #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
  29. #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
  30. #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
  31. #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
  32. static u16 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. };
  43. #define IS_HT_RATE(_rate) ((_rate) & 0x80)
  44. static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
  45. struct ath_atx_tid *tid,
  46. struct list_head *bf_head);
  47. static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
  48. struct ath_txq *txq, struct list_head *bf_q,
  49. struct ath_tx_status *ts, int txok, int sendbar);
  50. static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
  51. struct list_head *head, bool internal);
  52. static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, int len);
  53. static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf,
  54. struct ath_tx_status *ts, int nframes, int nbad,
  55. int txok, bool update_rc);
  56. static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  57. int seqno);
  58. enum {
  59. MCS_HT20,
  60. MCS_HT20_SGI,
  61. MCS_HT40,
  62. MCS_HT40_SGI,
  63. };
  64. static int ath_max_4ms_framelen[4][32] = {
  65. [MCS_HT20] = {
  66. 3212, 6432, 9648, 12864, 19300, 25736, 28952, 32172,
  67. 6424, 12852, 19280, 25708, 38568, 51424, 57852, 64280,
  68. 9628, 19260, 28896, 38528, 57792, 65532, 65532, 65532,
  69. 12828, 25656, 38488, 51320, 65532, 65532, 65532, 65532,
  70. },
  71. [MCS_HT20_SGI] = {
  72. 3572, 7144, 10720, 14296, 21444, 28596, 32172, 35744,
  73. 7140, 14284, 21428, 28568, 42856, 57144, 64288, 65532,
  74. 10700, 21408, 32112, 42816, 64228, 65532, 65532, 65532,
  75. 14256, 28516, 42780, 57040, 65532, 65532, 65532, 65532,
  76. },
  77. [MCS_HT40] = {
  78. 6680, 13360, 20044, 26724, 40092, 53456, 60140, 65532,
  79. 13348, 26700, 40052, 53400, 65532, 65532, 65532, 65532,
  80. 20004, 40008, 60016, 65532, 65532, 65532, 65532, 65532,
  81. 26644, 53292, 65532, 65532, 65532, 65532, 65532, 65532,
  82. },
  83. [MCS_HT40_SGI] = {
  84. 7420, 14844, 22272, 29696, 44544, 59396, 65532, 65532,
  85. 14832, 29668, 44504, 59340, 65532, 65532, 65532, 65532,
  86. 22232, 44464, 65532, 65532, 65532, 65532, 65532, 65532,
  87. 29616, 59232, 65532, 65532, 65532, 65532, 65532, 65532,
  88. }
  89. };
  90. /*********************/
  91. /* Aggregation logic */
  92. /*********************/
  93. static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
  94. {
  95. struct ath_atx_ac *ac = tid->ac;
  96. if (tid->paused)
  97. return;
  98. if (tid->sched)
  99. return;
  100. tid->sched = true;
  101. list_add_tail(&tid->list, &ac->tid_q);
  102. if (ac->sched)
  103. return;
  104. ac->sched = true;
  105. list_add_tail(&ac->list, &txq->axq_acq);
  106. }
  107. static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  108. {
  109. struct ath_txq *txq = tid->ac->txq;
  110. WARN_ON(!tid->paused);
  111. spin_lock_bh(&txq->axq_lock);
  112. tid->paused = false;
  113. if (skb_queue_empty(&tid->buf_q))
  114. goto unlock;
  115. ath_tx_queue_tid(txq, tid);
  116. ath_txq_schedule(sc, txq);
  117. unlock:
  118. spin_unlock_bh(&txq->axq_lock);
  119. }
  120. static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
  121. {
  122. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  123. BUILD_BUG_ON(sizeof(struct ath_frame_info) >
  124. sizeof(tx_info->rate_driver_data));
  125. return (struct ath_frame_info *) &tx_info->rate_driver_data[0];
  126. }
  127. static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  128. {
  129. struct ath_txq *txq = tid->ac->txq;
  130. struct sk_buff *skb;
  131. struct ath_buf *bf;
  132. struct list_head bf_head;
  133. struct ath_tx_status ts;
  134. struct ath_frame_info *fi;
  135. INIT_LIST_HEAD(&bf_head);
  136. memset(&ts, 0, sizeof(ts));
  137. spin_lock_bh(&txq->axq_lock);
  138. while ((skb = __skb_dequeue(&tid->buf_q))) {
  139. fi = get_frame_info(skb);
  140. bf = fi->bf;
  141. list_add_tail(&bf->list, &bf_head);
  142. spin_unlock_bh(&txq->axq_lock);
  143. if (fi->retries) {
  144. ath_tx_update_baw(sc, tid, fi->seqno);
  145. ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 1);
  146. } else {
  147. ath_tx_send_normal(sc, txq, NULL, &bf_head);
  148. }
  149. spin_lock_bh(&txq->axq_lock);
  150. }
  151. spin_unlock_bh(&txq->axq_lock);
  152. }
  153. static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  154. int seqno)
  155. {
  156. int index, cindex;
  157. index = ATH_BA_INDEX(tid->seq_start, seqno);
  158. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  159. __clear_bit(cindex, tid->tx_buf);
  160. while (tid->baw_head != tid->baw_tail && !test_bit(tid->baw_head, tid->tx_buf)) {
  161. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  162. INCR(tid->baw_head, ATH_TID_MAX_BUFS);
  163. }
  164. }
  165. static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  166. u16 seqno)
  167. {
  168. int index, cindex;
  169. index = ATH_BA_INDEX(tid->seq_start, seqno);
  170. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  171. __set_bit(cindex, tid->tx_buf);
  172. if (index >= ((tid->baw_tail - tid->baw_head) &
  173. (ATH_TID_MAX_BUFS - 1))) {
  174. tid->baw_tail = cindex;
  175. INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
  176. }
  177. }
  178. /*
  179. * TODO: For frame(s) that are in the retry state, we will reuse the
  180. * sequence number(s) without setting the retry bit. The
  181. * alternative is to give up on these and BAR the receiver's window
  182. * forward.
  183. */
  184. static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
  185. struct ath_atx_tid *tid)
  186. {
  187. struct sk_buff *skb;
  188. struct ath_buf *bf;
  189. struct list_head bf_head;
  190. struct ath_tx_status ts;
  191. struct ath_frame_info *fi;
  192. memset(&ts, 0, sizeof(ts));
  193. INIT_LIST_HEAD(&bf_head);
  194. while ((skb = __skb_dequeue(&tid->buf_q))) {
  195. fi = get_frame_info(skb);
  196. bf = fi->bf;
  197. list_add_tail(&bf->list, &bf_head);
  198. if (fi->retries)
  199. ath_tx_update_baw(sc, tid, fi->seqno);
  200. spin_unlock(&txq->axq_lock);
  201. ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 0);
  202. spin_lock(&txq->axq_lock);
  203. }
  204. tid->seq_next = tid->seq_start;
  205. tid->baw_tail = tid->baw_head;
  206. }
  207. static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
  208. struct sk_buff *skb)
  209. {
  210. struct ath_frame_info *fi = get_frame_info(skb);
  211. struct ieee80211_hdr *hdr;
  212. TX_STAT_INC(txq->axq_qnum, a_retries);
  213. if (fi->retries++ > 0)
  214. return;
  215. hdr = (struct ieee80211_hdr *)skb->data;
  216. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
  217. }
  218. static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
  219. {
  220. struct ath_buf *bf = NULL;
  221. spin_lock_bh(&sc->tx.txbuflock);
  222. if (unlikely(list_empty(&sc->tx.txbuf))) {
  223. spin_unlock_bh(&sc->tx.txbuflock);
  224. return NULL;
  225. }
  226. bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
  227. list_del(&bf->list);
  228. spin_unlock_bh(&sc->tx.txbuflock);
  229. return bf;
  230. }
  231. static void ath_tx_return_buffer(struct ath_softc *sc, struct ath_buf *bf)
  232. {
  233. spin_lock_bh(&sc->tx.txbuflock);
  234. list_add_tail(&bf->list, &sc->tx.txbuf);
  235. spin_unlock_bh(&sc->tx.txbuflock);
  236. }
  237. static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
  238. {
  239. struct ath_buf *tbf;
  240. tbf = ath_tx_get_buffer(sc);
  241. if (WARN_ON(!tbf))
  242. return NULL;
  243. ATH_TXBUF_RESET(tbf);
  244. tbf->bf_mpdu = bf->bf_mpdu;
  245. tbf->bf_buf_addr = bf->bf_buf_addr;
  246. memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len);
  247. tbf->bf_state = bf->bf_state;
  248. return tbf;
  249. }
  250. static void ath_tx_count_frames(struct ath_softc *sc, struct ath_buf *bf,
  251. struct ath_tx_status *ts, int txok,
  252. int *nframes, int *nbad)
  253. {
  254. struct ath_frame_info *fi;
  255. u16 seq_st = 0;
  256. u32 ba[WME_BA_BMP_SIZE >> 5];
  257. int ba_index;
  258. int isaggr = 0;
  259. *nbad = 0;
  260. *nframes = 0;
  261. isaggr = bf_isaggr(bf);
  262. if (isaggr) {
  263. seq_st = ts->ts_seqnum;
  264. memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
  265. }
  266. while (bf) {
  267. fi = get_frame_info(bf->bf_mpdu);
  268. ba_index = ATH_BA_INDEX(seq_st, fi->seqno);
  269. (*nframes)++;
  270. if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
  271. (*nbad)++;
  272. bf = bf->bf_next;
  273. }
  274. }
  275. static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
  276. struct ath_buf *bf, struct list_head *bf_q,
  277. struct ath_tx_status *ts, int txok, bool retry)
  278. {
  279. struct ath_node *an = NULL;
  280. struct sk_buff *skb;
  281. struct ieee80211_sta *sta;
  282. struct ieee80211_hw *hw = sc->hw;
  283. struct ieee80211_hdr *hdr;
  284. struct ieee80211_tx_info *tx_info;
  285. struct ath_atx_tid *tid = NULL;
  286. struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
  287. struct list_head bf_head;
  288. struct sk_buff_head bf_pending;
  289. u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0;
  290. u32 ba[WME_BA_BMP_SIZE >> 5];
  291. int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
  292. bool rc_update = true;
  293. struct ieee80211_tx_rate rates[4];
  294. struct ath_frame_info *fi;
  295. int nframes;
  296. u8 tidno;
  297. bool clear_filter;
  298. skb = bf->bf_mpdu;
  299. hdr = (struct ieee80211_hdr *)skb->data;
  300. tx_info = IEEE80211_SKB_CB(skb);
  301. memcpy(rates, tx_info->control.rates, sizeof(rates));
  302. rcu_read_lock();
  303. sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
  304. if (!sta) {
  305. rcu_read_unlock();
  306. INIT_LIST_HEAD(&bf_head);
  307. while (bf) {
  308. bf_next = bf->bf_next;
  309. bf->bf_state.bf_type |= BUF_XRETRY;
  310. if (!bf->bf_stale || bf_next != NULL)
  311. list_move_tail(&bf->list, &bf_head);
  312. ath_tx_rc_status(sc, bf, ts, 1, 1, 0, false);
  313. ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
  314. 0, 0);
  315. bf = bf_next;
  316. }
  317. return;
  318. }
  319. an = (struct ath_node *)sta->drv_priv;
  320. tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
  321. tid = ATH_AN_2_TID(an, tidno);
  322. /*
  323. * The hardware occasionally sends a tx status for the wrong TID.
  324. * In this case, the BA status cannot be considered valid and all
  325. * subframes need to be retransmitted
  326. */
  327. if (tidno != ts->tid)
  328. txok = false;
  329. isaggr = bf_isaggr(bf);
  330. memset(ba, 0, WME_BA_BMP_SIZE >> 3);
  331. if (isaggr && txok) {
  332. if (ts->ts_flags & ATH9K_TX_BA) {
  333. seq_st = ts->ts_seqnum;
  334. memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
  335. } else {
  336. /*
  337. * AR5416 can become deaf/mute when BA
  338. * issue happens. Chip needs to be reset.
  339. * But AP code may have sychronization issues
  340. * when perform internal reset in this routine.
  341. * Only enable reset in STA mode for now.
  342. */
  343. if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
  344. needreset = 1;
  345. }
  346. }
  347. __skb_queue_head_init(&bf_pending);
  348. ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad);
  349. while (bf) {
  350. txfail = txpending = sendbar = 0;
  351. bf_next = bf->bf_next;
  352. skb = bf->bf_mpdu;
  353. tx_info = IEEE80211_SKB_CB(skb);
  354. fi = get_frame_info(skb);
  355. if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, fi->seqno))) {
  356. /* transmit completion, subframe is
  357. * acked by block ack */
  358. acked_cnt++;
  359. } else if (!isaggr && txok) {
  360. /* transmit completion */
  361. acked_cnt++;
  362. } else {
  363. if ((tid->state & AGGR_CLEANUP) || !retry) {
  364. /*
  365. * cleanup in progress, just fail
  366. * the un-acked sub-frames
  367. */
  368. txfail = 1;
  369. } else if (fi->retries < ATH_MAX_SW_RETRIES) {
  370. if (!(ts->ts_status & ATH9K_TXERR_FILT) ||
  371. !an->sleeping)
  372. ath_tx_set_retry(sc, txq, bf->bf_mpdu);
  373. clear_filter = true;
  374. txpending = 1;
  375. } else {
  376. bf->bf_state.bf_type |= BUF_XRETRY;
  377. txfail = 1;
  378. sendbar = 1;
  379. txfail_cnt++;
  380. }
  381. }
  382. /*
  383. * Make sure the last desc is reclaimed if it
  384. * not a holding desc.
  385. */
  386. INIT_LIST_HEAD(&bf_head);
  387. if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) ||
  388. bf_next != NULL || !bf_last->bf_stale)
  389. list_move_tail(&bf->list, &bf_head);
  390. if (!txpending || (tid->state & AGGR_CLEANUP)) {
  391. /*
  392. * complete the acked-ones/xretried ones; update
  393. * block-ack window
  394. */
  395. spin_lock_bh(&txq->axq_lock);
  396. ath_tx_update_baw(sc, tid, fi->seqno);
  397. spin_unlock_bh(&txq->axq_lock);
  398. if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
  399. memcpy(tx_info->control.rates, rates, sizeof(rates));
  400. ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok, true);
  401. rc_update = false;
  402. } else {
  403. ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok, false);
  404. }
  405. ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
  406. !txfail, sendbar);
  407. } else {
  408. /* retry the un-acked ones */
  409. ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, false);
  410. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)) {
  411. if (bf->bf_next == NULL && bf_last->bf_stale) {
  412. struct ath_buf *tbf;
  413. tbf = ath_clone_txbuf(sc, bf_last);
  414. /*
  415. * Update tx baw and complete the
  416. * frame with failed status if we
  417. * run out of tx buf.
  418. */
  419. if (!tbf) {
  420. spin_lock_bh(&txq->axq_lock);
  421. ath_tx_update_baw(sc, tid, fi->seqno);
  422. spin_unlock_bh(&txq->axq_lock);
  423. bf->bf_state.bf_type |=
  424. BUF_XRETRY;
  425. ath_tx_rc_status(sc, bf, ts, nframes,
  426. nbad, 0, false);
  427. ath_tx_complete_buf(sc, bf, txq,
  428. &bf_head,
  429. ts, 0, 0);
  430. break;
  431. }
  432. ath9k_hw_cleartxdesc(sc->sc_ah,
  433. tbf->bf_desc);
  434. fi->bf = tbf;
  435. } else {
  436. /*
  437. * Clear descriptor status words for
  438. * software retry
  439. */
  440. ath9k_hw_cleartxdesc(sc->sc_ah,
  441. bf->bf_desc);
  442. }
  443. }
  444. /*
  445. * Put this buffer to the temporary pending
  446. * queue to retain ordering
  447. */
  448. __skb_queue_tail(&bf_pending, skb);
  449. }
  450. bf = bf_next;
  451. }
  452. /* prepend un-acked frames to the beginning of the pending frame queue */
  453. if (!skb_queue_empty(&bf_pending)) {
  454. if (an->sleeping)
  455. ieee80211_sta_set_tim(sta);
  456. spin_lock_bh(&txq->axq_lock);
  457. if (clear_filter)
  458. tid->ac->clear_ps_filter = true;
  459. skb_queue_splice(&bf_pending, &tid->buf_q);
  460. if (!an->sleeping)
  461. ath_tx_queue_tid(txq, tid);
  462. spin_unlock_bh(&txq->axq_lock);
  463. }
  464. if (tid->state & AGGR_CLEANUP) {
  465. ath_tx_flush_tid(sc, tid);
  466. if (tid->baw_head == tid->baw_tail) {
  467. tid->state &= ~AGGR_ADDBA_COMPLETE;
  468. tid->state &= ~AGGR_CLEANUP;
  469. }
  470. }
  471. rcu_read_unlock();
  472. if (needreset)
  473. ath_reset(sc, false);
  474. }
  475. static bool ath_lookup_legacy(struct ath_buf *bf)
  476. {
  477. struct sk_buff *skb;
  478. struct ieee80211_tx_info *tx_info;
  479. struct ieee80211_tx_rate *rates;
  480. int i;
  481. skb = bf->bf_mpdu;
  482. tx_info = IEEE80211_SKB_CB(skb);
  483. rates = tx_info->control.rates;
  484. for (i = 0; i < 4; i++) {
  485. if (!rates[i].count || rates[i].idx < 0)
  486. break;
  487. if (!(rates[i].flags & IEEE80211_TX_RC_MCS))
  488. return true;
  489. }
  490. return false;
  491. }
  492. static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
  493. struct ath_atx_tid *tid)
  494. {
  495. struct sk_buff *skb;
  496. struct ieee80211_tx_info *tx_info;
  497. struct ieee80211_tx_rate *rates;
  498. u32 max_4ms_framelen, frmlen;
  499. u16 aggr_limit, legacy = 0;
  500. int i;
  501. skb = bf->bf_mpdu;
  502. tx_info = IEEE80211_SKB_CB(skb);
  503. rates = tx_info->control.rates;
  504. /*
  505. * Find the lowest frame length among the rate series that will have a
  506. * 4ms transmit duration.
  507. * TODO - TXOP limit needs to be considered.
  508. */
  509. max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
  510. for (i = 0; i < 4; i++) {
  511. if (rates[i].count) {
  512. int modeidx;
  513. if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) {
  514. legacy = 1;
  515. break;
  516. }
  517. if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  518. modeidx = MCS_HT40;
  519. else
  520. modeidx = MCS_HT20;
  521. if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
  522. modeidx++;
  523. frmlen = ath_max_4ms_framelen[modeidx][rates[i].idx];
  524. max_4ms_framelen = min(max_4ms_framelen, frmlen);
  525. }
  526. }
  527. /*
  528. * limit aggregate size by the minimum rate if rate selected is
  529. * not a probe rate, if rate selected is a probe rate then
  530. * avoid aggregation of this packet.
  531. */
  532. if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
  533. return 0;
  534. if (sc->sc_flags & SC_OP_BT_PRIORITY_DETECTED)
  535. aggr_limit = min((max_4ms_framelen * 3) / 8,
  536. (u32)ATH_AMPDU_LIMIT_MAX);
  537. else
  538. aggr_limit = min(max_4ms_framelen,
  539. (u32)ATH_AMPDU_LIMIT_MAX);
  540. /*
  541. * h/w can accept aggregates up to 16 bit lengths (65535).
  542. * The IE, however can hold up to 65536, which shows up here
  543. * as zero. Ignore 65536 since we are constrained by hw.
  544. */
  545. if (tid->an->maxampdu)
  546. aggr_limit = min(aggr_limit, tid->an->maxampdu);
  547. return aggr_limit;
  548. }
  549. /*
  550. * Returns the number of delimiters to be added to
  551. * meet the minimum required mpdudensity.
  552. */
  553. static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
  554. struct ath_buf *bf, u16 frmlen,
  555. bool first_subfrm)
  556. {
  557. #define FIRST_DESC_NDELIMS 60
  558. struct sk_buff *skb = bf->bf_mpdu;
  559. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  560. u32 nsymbits, nsymbols;
  561. u16 minlen;
  562. u8 flags, rix;
  563. int width, streams, half_gi, ndelim, mindelim;
  564. struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
  565. /* Select standard number of delimiters based on frame length alone */
  566. ndelim = ATH_AGGR_GET_NDELIM(frmlen);
  567. /*
  568. * If encryption enabled, hardware requires some more padding between
  569. * subframes.
  570. * TODO - this could be improved to be dependent on the rate.
  571. * The hardware can keep up at lower rates, but not higher rates
  572. */
  573. if ((fi->keyix != ATH9K_TXKEYIX_INVALID) &&
  574. !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))
  575. ndelim += ATH_AGGR_ENCRYPTDELIM;
  576. /*
  577. * Add delimiter when using RTS/CTS with aggregation
  578. * and non enterprise AR9003 card
  579. */
  580. if (first_subfrm)
  581. ndelim = max(ndelim, FIRST_DESC_NDELIMS);
  582. /*
  583. * Convert desired mpdu density from microeconds to bytes based
  584. * on highest rate in rate series (i.e. first rate) to determine
  585. * required minimum length for subframe. Take into account
  586. * whether high rate is 20 or 40Mhz and half or full GI.
  587. *
  588. * If there is no mpdu density restriction, no further calculation
  589. * is needed.
  590. */
  591. if (tid->an->mpdudensity == 0)
  592. return ndelim;
  593. rix = tx_info->control.rates[0].idx;
  594. flags = tx_info->control.rates[0].flags;
  595. width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
  596. half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
  597. if (half_gi)
  598. nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity);
  599. else
  600. nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity);
  601. if (nsymbols == 0)
  602. nsymbols = 1;
  603. streams = HT_RC_2_STREAMS(rix);
  604. nsymbits = bits_per_symbol[rix % 8][width] * streams;
  605. minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
  606. if (frmlen < minlen) {
  607. mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
  608. ndelim = max(mindelim, ndelim);
  609. }
  610. return ndelim;
  611. }
  612. static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
  613. struct ath_txq *txq,
  614. struct ath_atx_tid *tid,
  615. struct list_head *bf_q,
  616. int *aggr_len)
  617. {
  618. #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
  619. struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
  620. int rl = 0, nframes = 0, ndelim, prev_al = 0;
  621. u16 aggr_limit = 0, al = 0, bpad = 0,
  622. al_delta, h_baw = tid->baw_size / 2;
  623. enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
  624. struct ieee80211_tx_info *tx_info;
  625. struct ath_frame_info *fi;
  626. struct sk_buff *skb;
  627. do {
  628. skb = skb_peek(&tid->buf_q);
  629. fi = get_frame_info(skb);
  630. bf = fi->bf;
  631. if (!bf_first)
  632. bf_first = bf;
  633. /* do not step over block-ack window */
  634. if (!BAW_WITHIN(tid->seq_start, tid->baw_size, fi->seqno)) {
  635. status = ATH_AGGR_BAW_CLOSED;
  636. break;
  637. }
  638. if (!rl) {
  639. aggr_limit = ath_lookup_rate(sc, bf, tid);
  640. rl = 1;
  641. }
  642. /* do not exceed aggregation limit */
  643. al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
  644. if (nframes &&
  645. ((aggr_limit < (al + bpad + al_delta + prev_al)) ||
  646. ath_lookup_legacy(bf))) {
  647. status = ATH_AGGR_LIMITED;
  648. break;
  649. }
  650. tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
  651. if (nframes && ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
  652. !(tx_info->control.rates[0].flags & IEEE80211_TX_RC_MCS)))
  653. break;
  654. /* do not exceed subframe limit */
  655. if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
  656. status = ATH_AGGR_LIMITED;
  657. break;
  658. }
  659. /* add padding for previous frame to aggregation length */
  660. al += bpad + al_delta;
  661. /*
  662. * Get the delimiters needed to meet the MPDU
  663. * density for this node.
  664. */
  665. ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->framelen,
  666. !nframes);
  667. bpad = PADBYTES(al_delta) + (ndelim << 2);
  668. nframes++;
  669. bf->bf_next = NULL;
  670. ath9k_hw_set_desc_link(sc->sc_ah, bf->bf_desc, 0);
  671. /* link buffers of this frame to the aggregate */
  672. if (!fi->retries)
  673. ath_tx_addto_baw(sc, tid, fi->seqno);
  674. ath9k_hw_set11n_aggr_middle(sc->sc_ah, bf->bf_desc, ndelim);
  675. __skb_unlink(skb, &tid->buf_q);
  676. list_add_tail(&bf->list, bf_q);
  677. if (bf_prev) {
  678. bf_prev->bf_next = bf;
  679. ath9k_hw_set_desc_link(sc->sc_ah, bf_prev->bf_desc,
  680. bf->bf_daddr);
  681. }
  682. bf_prev = bf;
  683. } while (!skb_queue_empty(&tid->buf_q));
  684. *aggr_len = al;
  685. return status;
  686. #undef PADBYTES
  687. }
  688. static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
  689. struct ath_atx_tid *tid)
  690. {
  691. struct ath_buf *bf;
  692. enum ATH_AGGR_STATUS status;
  693. struct ath_frame_info *fi;
  694. struct list_head bf_q;
  695. int aggr_len;
  696. do {
  697. if (skb_queue_empty(&tid->buf_q))
  698. return;
  699. INIT_LIST_HEAD(&bf_q);
  700. status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len);
  701. /*
  702. * no frames picked up to be aggregated;
  703. * block-ack window is not open.
  704. */
  705. if (list_empty(&bf_q))
  706. break;
  707. bf = list_first_entry(&bf_q, struct ath_buf, list);
  708. bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
  709. if (tid->ac->clear_ps_filter) {
  710. tid->ac->clear_ps_filter = false;
  711. ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true);
  712. }
  713. /* if only one frame, send as non-aggregate */
  714. if (bf == bf->bf_lastbf) {
  715. fi = get_frame_info(bf->bf_mpdu);
  716. bf->bf_state.bf_type &= ~BUF_AGGR;
  717. ath9k_hw_clr11n_aggr(sc->sc_ah, bf->bf_desc);
  718. ath_buf_set_rate(sc, bf, fi->framelen);
  719. ath_tx_txqaddbuf(sc, txq, &bf_q, false);
  720. continue;
  721. }
  722. /* setup first desc of aggregate */
  723. bf->bf_state.bf_type |= BUF_AGGR;
  724. ath_buf_set_rate(sc, bf, aggr_len);
  725. ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, aggr_len);
  726. /* anchor last desc of aggregate */
  727. ath9k_hw_set11n_aggr_last(sc->sc_ah, bf->bf_lastbf->bf_desc);
  728. ath_tx_txqaddbuf(sc, txq, &bf_q, false);
  729. TX_STAT_INC(txq->axq_qnum, a_aggr);
  730. } while (txq->axq_ampdu_depth < ATH_AGGR_MIN_QDEPTH &&
  731. status != ATH_AGGR_BAW_CLOSED);
  732. }
  733. int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
  734. u16 tid, u16 *ssn)
  735. {
  736. struct ath_atx_tid *txtid;
  737. struct ath_node *an;
  738. an = (struct ath_node *)sta->drv_priv;
  739. txtid = ATH_AN_2_TID(an, tid);
  740. if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE))
  741. return -EAGAIN;
  742. txtid->state |= AGGR_ADDBA_PROGRESS;
  743. txtid->paused = true;
  744. *ssn = txtid->seq_start = txtid->seq_next;
  745. memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf));
  746. txtid->baw_head = txtid->baw_tail = 0;
  747. return 0;
  748. }
  749. void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  750. {
  751. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  752. struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
  753. struct ath_txq *txq = txtid->ac->txq;
  754. if (txtid->state & AGGR_CLEANUP)
  755. return;
  756. if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
  757. txtid->state &= ~AGGR_ADDBA_PROGRESS;
  758. return;
  759. }
  760. spin_lock_bh(&txq->axq_lock);
  761. txtid->paused = true;
  762. /*
  763. * If frames are still being transmitted for this TID, they will be
  764. * cleaned up during tx completion. To prevent race conditions, this
  765. * TID can only be reused after all in-progress subframes have been
  766. * completed.
  767. */
  768. if (txtid->baw_head != txtid->baw_tail)
  769. txtid->state |= AGGR_CLEANUP;
  770. else
  771. txtid->state &= ~AGGR_ADDBA_COMPLETE;
  772. spin_unlock_bh(&txq->axq_lock);
  773. ath_tx_flush_tid(sc, txtid);
  774. }
  775. bool ath_tx_aggr_sleep(struct ath_softc *sc, struct ath_node *an)
  776. {
  777. struct ath_atx_tid *tid;
  778. struct ath_atx_ac *ac;
  779. struct ath_txq *txq;
  780. bool buffered = false;
  781. int tidno;
  782. for (tidno = 0, tid = &an->tid[tidno];
  783. tidno < WME_NUM_TID; tidno++, tid++) {
  784. if (!tid->sched)
  785. continue;
  786. ac = tid->ac;
  787. txq = ac->txq;
  788. spin_lock_bh(&txq->axq_lock);
  789. if (!skb_queue_empty(&tid->buf_q))
  790. buffered = true;
  791. tid->sched = false;
  792. list_del(&tid->list);
  793. if (ac->sched) {
  794. ac->sched = false;
  795. list_del(&ac->list);
  796. }
  797. spin_unlock_bh(&txq->axq_lock);
  798. }
  799. return buffered;
  800. }
  801. void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an)
  802. {
  803. struct ath_atx_tid *tid;
  804. struct ath_atx_ac *ac;
  805. struct ath_txq *txq;
  806. int tidno;
  807. for (tidno = 0, tid = &an->tid[tidno];
  808. tidno < WME_NUM_TID; tidno++, tid++) {
  809. ac = tid->ac;
  810. txq = ac->txq;
  811. spin_lock_bh(&txq->axq_lock);
  812. ac->clear_ps_filter = true;
  813. if (!skb_queue_empty(&tid->buf_q) && !tid->paused) {
  814. ath_tx_queue_tid(txq, tid);
  815. ath_txq_schedule(sc, txq);
  816. }
  817. spin_unlock_bh(&txq->axq_lock);
  818. }
  819. }
  820. void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  821. {
  822. struct ath_atx_tid *txtid;
  823. struct ath_node *an;
  824. an = (struct ath_node *)sta->drv_priv;
  825. if (sc->sc_flags & SC_OP_TXAGGR) {
  826. txtid = ATH_AN_2_TID(an, tid);
  827. txtid->baw_size =
  828. IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
  829. txtid->state |= AGGR_ADDBA_COMPLETE;
  830. txtid->state &= ~AGGR_ADDBA_PROGRESS;
  831. ath_tx_resume_tid(sc, txtid);
  832. }
  833. }
  834. /********************/
  835. /* Queue Management */
  836. /********************/
  837. static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
  838. struct ath_txq *txq)
  839. {
  840. struct ath_atx_ac *ac, *ac_tmp;
  841. struct ath_atx_tid *tid, *tid_tmp;
  842. list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
  843. list_del(&ac->list);
  844. ac->sched = false;
  845. list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
  846. list_del(&tid->list);
  847. tid->sched = false;
  848. ath_tid_drain(sc, txq, tid);
  849. }
  850. }
  851. }
  852. struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
  853. {
  854. struct ath_hw *ah = sc->sc_ah;
  855. struct ath_common *common = ath9k_hw_common(ah);
  856. struct ath9k_tx_queue_info qi;
  857. static const int subtype_txq_to_hwq[] = {
  858. [WME_AC_BE] = ATH_TXQ_AC_BE,
  859. [WME_AC_BK] = ATH_TXQ_AC_BK,
  860. [WME_AC_VI] = ATH_TXQ_AC_VI,
  861. [WME_AC_VO] = ATH_TXQ_AC_VO,
  862. };
  863. int axq_qnum, i;
  864. memset(&qi, 0, sizeof(qi));
  865. qi.tqi_subtype = subtype_txq_to_hwq[subtype];
  866. qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
  867. qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  868. qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
  869. qi.tqi_physCompBuf = 0;
  870. /*
  871. * Enable interrupts only for EOL and DESC conditions.
  872. * We mark tx descriptors to receive a DESC interrupt
  873. * when a tx queue gets deep; otherwise waiting for the
  874. * EOL to reap descriptors. Note that this is done to
  875. * reduce interrupt load and this only defers reaping
  876. * descriptors, never transmitting frames. Aside from
  877. * reducing interrupts this also permits more concurrency.
  878. * The only potential downside is if the tx queue backs
  879. * up in which case the top half of the kernel may backup
  880. * due to a lack of tx descriptors.
  881. *
  882. * The UAPSD queue is an exception, since we take a desc-
  883. * based intr on the EOSP frames.
  884. */
  885. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  886. qi.tqi_qflags = TXQ_FLAG_TXOKINT_ENABLE |
  887. TXQ_FLAG_TXERRINT_ENABLE;
  888. } else {
  889. if (qtype == ATH9K_TX_QUEUE_UAPSD)
  890. qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
  891. else
  892. qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
  893. TXQ_FLAG_TXDESCINT_ENABLE;
  894. }
  895. axq_qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
  896. if (axq_qnum == -1) {
  897. /*
  898. * NB: don't print a message, this happens
  899. * normally on parts with too few tx queues
  900. */
  901. return NULL;
  902. }
  903. if (axq_qnum >= ARRAY_SIZE(sc->tx.txq)) {
  904. ath_err(common, "qnum %u out of range, max %zu!\n",
  905. axq_qnum, ARRAY_SIZE(sc->tx.txq));
  906. ath9k_hw_releasetxqueue(ah, axq_qnum);
  907. return NULL;
  908. }
  909. if (!ATH_TXQ_SETUP(sc, axq_qnum)) {
  910. struct ath_txq *txq = &sc->tx.txq[axq_qnum];
  911. txq->axq_qnum = axq_qnum;
  912. txq->mac80211_qnum = -1;
  913. txq->axq_link = NULL;
  914. INIT_LIST_HEAD(&txq->axq_q);
  915. INIT_LIST_HEAD(&txq->axq_acq);
  916. spin_lock_init(&txq->axq_lock);
  917. txq->axq_depth = 0;
  918. txq->axq_ampdu_depth = 0;
  919. txq->axq_tx_inprogress = false;
  920. sc->tx.txqsetup |= 1<<axq_qnum;
  921. txq->txq_headidx = txq->txq_tailidx = 0;
  922. for (i = 0; i < ATH_TXFIFO_DEPTH; i++)
  923. INIT_LIST_HEAD(&txq->txq_fifo[i]);
  924. }
  925. return &sc->tx.txq[axq_qnum];
  926. }
  927. int ath_txq_update(struct ath_softc *sc, int qnum,
  928. struct ath9k_tx_queue_info *qinfo)
  929. {
  930. struct ath_hw *ah = sc->sc_ah;
  931. int error = 0;
  932. struct ath9k_tx_queue_info qi;
  933. if (qnum == sc->beacon.beaconq) {
  934. /*
  935. * XXX: for beacon queue, we just save the parameter.
  936. * It will be picked up by ath_beaconq_config when
  937. * it's necessary.
  938. */
  939. sc->beacon.beacon_qi = *qinfo;
  940. return 0;
  941. }
  942. BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum);
  943. ath9k_hw_get_txq_props(ah, qnum, &qi);
  944. qi.tqi_aifs = qinfo->tqi_aifs;
  945. qi.tqi_cwmin = qinfo->tqi_cwmin;
  946. qi.tqi_cwmax = qinfo->tqi_cwmax;
  947. qi.tqi_burstTime = qinfo->tqi_burstTime;
  948. qi.tqi_readyTime = qinfo->tqi_readyTime;
  949. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  950. ath_err(ath9k_hw_common(sc->sc_ah),
  951. "Unable to update hardware queue %u!\n", qnum);
  952. error = -EIO;
  953. } else {
  954. ath9k_hw_resettxqueue(ah, qnum);
  955. }
  956. return error;
  957. }
  958. int ath_cabq_update(struct ath_softc *sc)
  959. {
  960. struct ath9k_tx_queue_info qi;
  961. struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
  962. int qnum = sc->beacon.cabq->axq_qnum;
  963. ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
  964. /*
  965. * Ensure the readytime % is within the bounds.
  966. */
  967. if (sc->config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
  968. sc->config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
  969. else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
  970. sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
  971. qi.tqi_readyTime = (cur_conf->beacon_interval *
  972. sc->config.cabqReadytime) / 100;
  973. ath_txq_update(sc, qnum, &qi);
  974. return 0;
  975. }
  976. static bool bf_is_ampdu_not_probing(struct ath_buf *bf)
  977. {
  978. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(bf->bf_mpdu);
  979. return bf_isampdu(bf) && !(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
  980. }
  981. static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq,
  982. struct list_head *list, bool retry_tx)
  983. __releases(txq->axq_lock)
  984. __acquires(txq->axq_lock)
  985. {
  986. struct ath_buf *bf, *lastbf;
  987. struct list_head bf_head;
  988. struct ath_tx_status ts;
  989. memset(&ts, 0, sizeof(ts));
  990. INIT_LIST_HEAD(&bf_head);
  991. while (!list_empty(list)) {
  992. bf = list_first_entry(list, struct ath_buf, list);
  993. if (bf->bf_stale) {
  994. list_del(&bf->list);
  995. ath_tx_return_buffer(sc, bf);
  996. continue;
  997. }
  998. lastbf = bf->bf_lastbf;
  999. list_cut_position(&bf_head, list, &lastbf->list);
  1000. txq->axq_depth--;
  1001. if (bf_is_ampdu_not_probing(bf))
  1002. txq->axq_ampdu_depth--;
  1003. spin_unlock_bh(&txq->axq_lock);
  1004. if (bf_isampdu(bf))
  1005. ath_tx_complete_aggr(sc, txq, bf, &bf_head, &ts, 0,
  1006. retry_tx);
  1007. else
  1008. ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 0);
  1009. spin_lock_bh(&txq->axq_lock);
  1010. }
  1011. }
  1012. /*
  1013. * Drain a given TX queue (could be Beacon or Data)
  1014. *
  1015. * This assumes output has been stopped and
  1016. * we do not need to block ath_tx_tasklet.
  1017. */
  1018. void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
  1019. {
  1020. spin_lock_bh(&txq->axq_lock);
  1021. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  1022. int idx = txq->txq_tailidx;
  1023. while (!list_empty(&txq->txq_fifo[idx])) {
  1024. ath_drain_txq_list(sc, txq, &txq->txq_fifo[idx],
  1025. retry_tx);
  1026. INCR(idx, ATH_TXFIFO_DEPTH);
  1027. }
  1028. txq->txq_tailidx = idx;
  1029. }
  1030. txq->axq_link = NULL;
  1031. txq->axq_tx_inprogress = false;
  1032. ath_drain_txq_list(sc, txq, &txq->axq_q, retry_tx);
  1033. /* flush any pending frames if aggregation is enabled */
  1034. if ((sc->sc_flags & SC_OP_TXAGGR) && !retry_tx)
  1035. ath_txq_drain_pending_buffers(sc, txq);
  1036. spin_unlock_bh(&txq->axq_lock);
  1037. }
  1038. bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
  1039. {
  1040. struct ath_hw *ah = sc->sc_ah;
  1041. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1042. struct ath_txq *txq;
  1043. int i, npend = 0;
  1044. if (sc->sc_flags & SC_OP_INVALID)
  1045. return true;
  1046. ath9k_hw_abort_tx_dma(ah);
  1047. /* Check if any queue remains active */
  1048. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1049. if (!ATH_TXQ_SETUP(sc, i))
  1050. continue;
  1051. npend += ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum);
  1052. }
  1053. if (npend)
  1054. ath_err(common, "Failed to stop TX DMA!\n");
  1055. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1056. if (!ATH_TXQ_SETUP(sc, i))
  1057. continue;
  1058. /*
  1059. * The caller will resume queues with ieee80211_wake_queues.
  1060. * Mark the queue as not stopped to prevent ath_tx_complete
  1061. * from waking the queue too early.
  1062. */
  1063. txq = &sc->tx.txq[i];
  1064. txq->stopped = false;
  1065. ath_draintxq(sc, txq, retry_tx);
  1066. }
  1067. return !npend;
  1068. }
  1069. void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
  1070. {
  1071. ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
  1072. sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
  1073. }
  1074. /* For each axq_acq entry, for each tid, try to schedule packets
  1075. * for transmit until ampdu_depth has reached min Q depth.
  1076. */
  1077. void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
  1078. {
  1079. struct ath_atx_ac *ac, *ac_tmp, *last_ac;
  1080. struct ath_atx_tid *tid, *last_tid;
  1081. if (list_empty(&txq->axq_acq) ||
  1082. txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
  1083. return;
  1084. ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
  1085. last_ac = list_entry(txq->axq_acq.prev, struct ath_atx_ac, list);
  1086. list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
  1087. last_tid = list_entry(ac->tid_q.prev, struct ath_atx_tid, list);
  1088. list_del(&ac->list);
  1089. ac->sched = false;
  1090. while (!list_empty(&ac->tid_q)) {
  1091. tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
  1092. list);
  1093. list_del(&tid->list);
  1094. tid->sched = false;
  1095. if (tid->paused)
  1096. continue;
  1097. ath_tx_sched_aggr(sc, txq, tid);
  1098. /*
  1099. * add tid to round-robin queue if more frames
  1100. * are pending for the tid
  1101. */
  1102. if (!skb_queue_empty(&tid->buf_q))
  1103. ath_tx_queue_tid(txq, tid);
  1104. if (tid == last_tid ||
  1105. txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
  1106. break;
  1107. }
  1108. if (!list_empty(&ac->tid_q)) {
  1109. if (!ac->sched) {
  1110. ac->sched = true;
  1111. list_add_tail(&ac->list, &txq->axq_acq);
  1112. }
  1113. }
  1114. if (ac == last_ac ||
  1115. txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
  1116. return;
  1117. }
  1118. }
  1119. /***********/
  1120. /* TX, DMA */
  1121. /***********/
  1122. /*
  1123. * Insert a chain of ath_buf (descriptors) on a txq and
  1124. * assume the descriptors are already chained together by caller.
  1125. */
  1126. static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
  1127. struct list_head *head, bool internal)
  1128. {
  1129. struct ath_hw *ah = sc->sc_ah;
  1130. struct ath_common *common = ath9k_hw_common(ah);
  1131. struct ath_buf *bf, *bf_last;
  1132. bool puttxbuf = false;
  1133. bool edma;
  1134. /*
  1135. * Insert the frame on the outbound list and
  1136. * pass it on to the hardware.
  1137. */
  1138. if (list_empty(head))
  1139. return;
  1140. edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1141. bf = list_first_entry(head, struct ath_buf, list);
  1142. bf_last = list_entry(head->prev, struct ath_buf, list);
  1143. ath_dbg(common, ATH_DBG_QUEUE,
  1144. "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
  1145. if (edma && list_empty(&txq->txq_fifo[txq->txq_headidx])) {
  1146. list_splice_tail_init(head, &txq->txq_fifo[txq->txq_headidx]);
  1147. INCR(txq->txq_headidx, ATH_TXFIFO_DEPTH);
  1148. puttxbuf = true;
  1149. } else {
  1150. list_splice_tail_init(head, &txq->axq_q);
  1151. if (txq->axq_link) {
  1152. ath9k_hw_set_desc_link(ah, txq->axq_link, bf->bf_daddr);
  1153. ath_dbg(common, ATH_DBG_XMIT,
  1154. "link[%u] (%p)=%llx (%p)\n",
  1155. txq->axq_qnum, txq->axq_link,
  1156. ito64(bf->bf_daddr), bf->bf_desc);
  1157. } else if (!edma)
  1158. puttxbuf = true;
  1159. txq->axq_link = bf_last->bf_desc;
  1160. }
  1161. if (puttxbuf) {
  1162. TX_STAT_INC(txq->axq_qnum, puttxbuf);
  1163. ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
  1164. ath_dbg(common, ATH_DBG_XMIT, "TXDP[%u] = %llx (%p)\n",
  1165. txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
  1166. }
  1167. if (!edma) {
  1168. TX_STAT_INC(txq->axq_qnum, txstart);
  1169. ath9k_hw_txstart(ah, txq->axq_qnum);
  1170. }
  1171. if (!internal) {
  1172. txq->axq_depth++;
  1173. if (bf_is_ampdu_not_probing(bf))
  1174. txq->axq_ampdu_depth++;
  1175. }
  1176. }
  1177. static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
  1178. struct ath_buf *bf, struct ath_tx_control *txctl)
  1179. {
  1180. struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
  1181. struct list_head bf_head;
  1182. bf->bf_state.bf_type |= BUF_AMPDU;
  1183. /*
  1184. * Do not queue to h/w when any of the following conditions is true:
  1185. * - there are pending frames in software queue
  1186. * - the TID is currently paused for ADDBA/BAR request
  1187. * - seqno is not within block-ack window
  1188. * - h/w queue depth exceeds low water mark
  1189. */
  1190. if (!skb_queue_empty(&tid->buf_q) || tid->paused ||
  1191. !BAW_WITHIN(tid->seq_start, tid->baw_size, fi->seqno) ||
  1192. txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) {
  1193. /*
  1194. * Add this frame to software queue for scheduling later
  1195. * for aggregation.
  1196. */
  1197. TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw);
  1198. __skb_queue_tail(&tid->buf_q, bf->bf_mpdu);
  1199. if (!txctl->an || !txctl->an->sleeping)
  1200. ath_tx_queue_tid(txctl->txq, tid);
  1201. return;
  1202. }
  1203. INIT_LIST_HEAD(&bf_head);
  1204. list_add(&bf->list, &bf_head);
  1205. /* Add sub-frame to BAW */
  1206. if (!fi->retries)
  1207. ath_tx_addto_baw(sc, tid, fi->seqno);
  1208. /* Queue to h/w without aggregation */
  1209. TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw);
  1210. bf->bf_lastbf = bf;
  1211. ath_buf_set_rate(sc, bf, fi->framelen);
  1212. ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false);
  1213. }
  1214. static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
  1215. struct ath_atx_tid *tid,
  1216. struct list_head *bf_head)
  1217. {
  1218. struct ath_frame_info *fi;
  1219. struct ath_buf *bf;
  1220. bf = list_first_entry(bf_head, struct ath_buf, list);
  1221. bf->bf_state.bf_type &= ~BUF_AMPDU;
  1222. /* update starting sequence number for subsequent ADDBA request */
  1223. if (tid)
  1224. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  1225. bf->bf_lastbf = bf;
  1226. fi = get_frame_info(bf->bf_mpdu);
  1227. ath_buf_set_rate(sc, bf, fi->framelen);
  1228. ath_tx_txqaddbuf(sc, txq, bf_head, false);
  1229. TX_STAT_INC(txq->axq_qnum, queued);
  1230. }
  1231. static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
  1232. {
  1233. struct ieee80211_hdr *hdr;
  1234. enum ath9k_pkt_type htype;
  1235. __le16 fc;
  1236. hdr = (struct ieee80211_hdr *)skb->data;
  1237. fc = hdr->frame_control;
  1238. if (ieee80211_is_beacon(fc))
  1239. htype = ATH9K_PKT_TYPE_BEACON;
  1240. else if (ieee80211_is_probe_resp(fc))
  1241. htype = ATH9K_PKT_TYPE_PROBE_RESP;
  1242. else if (ieee80211_is_atim(fc))
  1243. htype = ATH9K_PKT_TYPE_ATIM;
  1244. else if (ieee80211_is_pspoll(fc))
  1245. htype = ATH9K_PKT_TYPE_PSPOLL;
  1246. else
  1247. htype = ATH9K_PKT_TYPE_NORMAL;
  1248. return htype;
  1249. }
  1250. static void setup_frame_info(struct ieee80211_hw *hw, struct sk_buff *skb,
  1251. int framelen)
  1252. {
  1253. struct ath_softc *sc = hw->priv;
  1254. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1255. struct ieee80211_sta *sta = tx_info->control.sta;
  1256. struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
  1257. struct ieee80211_hdr *hdr;
  1258. struct ath_frame_info *fi = get_frame_info(skb);
  1259. struct ath_node *an = NULL;
  1260. struct ath_atx_tid *tid;
  1261. enum ath9k_key_type keytype;
  1262. u16 seqno = 0;
  1263. u8 tidno;
  1264. keytype = ath9k_cmn_get_hw_crypto_keytype(skb);
  1265. if (sta)
  1266. an = (struct ath_node *) sta->drv_priv;
  1267. hdr = (struct ieee80211_hdr *)skb->data;
  1268. if (an && ieee80211_is_data_qos(hdr->frame_control) &&
  1269. conf_is_ht(&hw->conf) && (sc->sc_flags & SC_OP_TXAGGR)) {
  1270. tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
  1271. /*
  1272. * Override seqno set by upper layer with the one
  1273. * in tx aggregation state.
  1274. */
  1275. tid = ATH_AN_2_TID(an, tidno);
  1276. seqno = tid->seq_next;
  1277. hdr->seq_ctrl = cpu_to_le16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
  1278. INCR(tid->seq_next, IEEE80211_SEQ_MAX);
  1279. }
  1280. memset(fi, 0, sizeof(*fi));
  1281. if (hw_key)
  1282. fi->keyix = hw_key->hw_key_idx;
  1283. else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0)
  1284. fi->keyix = an->ps_key;
  1285. else
  1286. fi->keyix = ATH9K_TXKEYIX_INVALID;
  1287. fi->keytype = keytype;
  1288. fi->framelen = framelen;
  1289. fi->seqno = seqno;
  1290. }
  1291. static int setup_tx_flags(struct sk_buff *skb)
  1292. {
  1293. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1294. int flags = 0;
  1295. flags |= ATH9K_TXDESC_INTREQ;
  1296. if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
  1297. flags |= ATH9K_TXDESC_NOACK;
  1298. if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
  1299. flags |= ATH9K_TXDESC_LDPC;
  1300. return flags;
  1301. }
  1302. /*
  1303. * rix - rate index
  1304. * pktlen - total bytes (delims + data + fcs + pads + pad delims)
  1305. * width - 0 for 20 MHz, 1 for 40 MHz
  1306. * half_gi - to use 4us v/s 3.6 us for symbol time
  1307. */
  1308. static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen,
  1309. int width, int half_gi, bool shortPreamble)
  1310. {
  1311. u32 nbits, nsymbits, duration, nsymbols;
  1312. int streams;
  1313. /* find number of symbols: PLCP + data */
  1314. streams = HT_RC_2_STREAMS(rix);
  1315. nbits = (pktlen << 3) + OFDM_PLCP_BITS;
  1316. nsymbits = bits_per_symbol[rix % 8][width] * streams;
  1317. nsymbols = (nbits + nsymbits - 1) / nsymbits;
  1318. if (!half_gi)
  1319. duration = SYMBOL_TIME(nsymbols);
  1320. else
  1321. duration = SYMBOL_TIME_HALFGI(nsymbols);
  1322. /* addup duration for legacy/ht training and signal fields */
  1323. duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
  1324. return duration;
  1325. }
  1326. u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate)
  1327. {
  1328. struct ath_hw *ah = sc->sc_ah;
  1329. struct ath9k_channel *curchan = ah->curchan;
  1330. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) &&
  1331. (curchan->channelFlags & CHANNEL_5GHZ) &&
  1332. (chainmask == 0x7) && (rate < 0x90))
  1333. return 0x3;
  1334. else
  1335. return chainmask;
  1336. }
  1337. static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, int len)
  1338. {
  1339. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1340. struct ath9k_11n_rate_series series[4];
  1341. struct sk_buff *skb;
  1342. struct ieee80211_tx_info *tx_info;
  1343. struct ieee80211_tx_rate *rates;
  1344. const struct ieee80211_rate *rate;
  1345. struct ieee80211_hdr *hdr;
  1346. int i, flags = 0;
  1347. u8 rix = 0, ctsrate = 0;
  1348. bool is_pspoll;
  1349. memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
  1350. skb = bf->bf_mpdu;
  1351. tx_info = IEEE80211_SKB_CB(skb);
  1352. rates = tx_info->control.rates;
  1353. hdr = (struct ieee80211_hdr *)skb->data;
  1354. is_pspoll = ieee80211_is_pspoll(hdr->frame_control);
  1355. /*
  1356. * We check if Short Preamble is needed for the CTS rate by
  1357. * checking the BSS's global flag.
  1358. * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
  1359. */
  1360. rate = ieee80211_get_rts_cts_rate(sc->hw, tx_info);
  1361. ctsrate = rate->hw_value;
  1362. if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
  1363. ctsrate |= rate->hw_value_short;
  1364. for (i = 0; i < 4; i++) {
  1365. bool is_40, is_sgi, is_sp;
  1366. int phy;
  1367. if (!rates[i].count || (rates[i].idx < 0))
  1368. continue;
  1369. rix = rates[i].idx;
  1370. series[i].Tries = rates[i].count;
  1371. if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  1372. series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
  1373. flags |= ATH9K_TXDESC_RTSENA;
  1374. } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  1375. series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
  1376. flags |= ATH9K_TXDESC_CTSENA;
  1377. }
  1378. if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1379. series[i].RateFlags |= ATH9K_RATESERIES_2040;
  1380. if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
  1381. series[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
  1382. is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI);
  1383. is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH);
  1384. is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
  1385. if (rates[i].flags & IEEE80211_TX_RC_MCS) {
  1386. /* MCS rates */
  1387. series[i].Rate = rix | 0x80;
  1388. series[i].ChSel = ath_txchainmask_reduction(sc,
  1389. common->tx_chainmask, series[i].Rate);
  1390. series[i].PktDuration = ath_pkt_duration(sc, rix, len,
  1391. is_40, is_sgi, is_sp);
  1392. if (rix < 8 && (tx_info->flags & IEEE80211_TX_CTL_STBC))
  1393. series[i].RateFlags |= ATH9K_RATESERIES_STBC;
  1394. continue;
  1395. }
  1396. /* legacy rates */
  1397. if ((tx_info->band == IEEE80211_BAND_2GHZ) &&
  1398. !(rate->flags & IEEE80211_RATE_ERP_G))
  1399. phy = WLAN_RC_PHY_CCK;
  1400. else
  1401. phy = WLAN_RC_PHY_OFDM;
  1402. rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx];
  1403. series[i].Rate = rate->hw_value;
  1404. if (rate->hw_value_short) {
  1405. if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  1406. series[i].Rate |= rate->hw_value_short;
  1407. } else {
  1408. is_sp = false;
  1409. }
  1410. if (bf->bf_state.bfs_paprd)
  1411. series[i].ChSel = common->tx_chainmask;
  1412. else
  1413. series[i].ChSel = ath_txchainmask_reduction(sc,
  1414. common->tx_chainmask, series[i].Rate);
  1415. series[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah,
  1416. phy, rate->bitrate * 100, len, rix, is_sp);
  1417. }
  1418. /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
  1419. if (bf_isaggr(bf) && (len > sc->sc_ah->caps.rts_aggr_limit))
  1420. flags &= ~ATH9K_TXDESC_RTSENA;
  1421. /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */
  1422. if (flags & ATH9K_TXDESC_RTSENA)
  1423. flags &= ~ATH9K_TXDESC_CTSENA;
  1424. /* set dur_update_en for l-sig computation except for PS-Poll frames */
  1425. ath9k_hw_set11n_ratescenario(sc->sc_ah, bf->bf_desc,
  1426. bf->bf_lastbf->bf_desc,
  1427. !is_pspoll, ctsrate,
  1428. 0, series, 4, flags);
  1429. }
  1430. static struct ath_buf *ath_tx_setup_buffer(struct ieee80211_hw *hw,
  1431. struct ath_txq *txq,
  1432. struct sk_buff *skb)
  1433. {
  1434. struct ath_softc *sc = hw->priv;
  1435. struct ath_hw *ah = sc->sc_ah;
  1436. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1437. struct ath_frame_info *fi = get_frame_info(skb);
  1438. struct ath_buf *bf;
  1439. struct ath_desc *ds;
  1440. int frm_type;
  1441. bf = ath_tx_get_buffer(sc);
  1442. if (!bf) {
  1443. ath_dbg(common, ATH_DBG_XMIT, "TX buffers are full\n");
  1444. return NULL;
  1445. }
  1446. ATH_TXBUF_RESET(bf);
  1447. bf->bf_flags = setup_tx_flags(skb);
  1448. bf->bf_mpdu = skb;
  1449. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  1450. skb->len, DMA_TO_DEVICE);
  1451. if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
  1452. bf->bf_mpdu = NULL;
  1453. bf->bf_buf_addr = 0;
  1454. ath_err(ath9k_hw_common(sc->sc_ah),
  1455. "dma_mapping_error() on TX\n");
  1456. ath_tx_return_buffer(sc, bf);
  1457. return NULL;
  1458. }
  1459. frm_type = get_hw_packet_type(skb);
  1460. ds = bf->bf_desc;
  1461. ath9k_hw_set_desc_link(ah, ds, 0);
  1462. ath9k_hw_set11n_txdesc(ah, ds, fi->framelen, frm_type, MAX_RATE_POWER,
  1463. fi->keyix, fi->keytype, bf->bf_flags);
  1464. ath9k_hw_filltxdesc(ah, ds,
  1465. skb->len, /* segment length */
  1466. true, /* first segment */
  1467. true, /* last segment */
  1468. ds, /* first descriptor */
  1469. bf->bf_buf_addr,
  1470. txq->axq_qnum);
  1471. fi->bf = bf;
  1472. return bf;
  1473. }
  1474. /* FIXME: tx power */
  1475. static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
  1476. struct ath_tx_control *txctl)
  1477. {
  1478. struct sk_buff *skb = bf->bf_mpdu;
  1479. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1480. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1481. struct list_head bf_head;
  1482. struct ath_atx_tid *tid = NULL;
  1483. u8 tidno;
  1484. spin_lock_bh(&txctl->txq->axq_lock);
  1485. if ((sc->sc_flags & SC_OP_TXAGGR) && txctl->an &&
  1486. ieee80211_is_data_qos(hdr->frame_control)) {
  1487. tidno = ieee80211_get_qos_ctl(hdr)[0] &
  1488. IEEE80211_QOS_CTL_TID_MASK;
  1489. tid = ATH_AN_2_TID(txctl->an, tidno);
  1490. WARN_ON(tid->ac->txq != txctl->txq);
  1491. }
  1492. if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
  1493. /*
  1494. * Try aggregation if it's a unicast data frame
  1495. * and the destination is HT capable.
  1496. */
  1497. ath_tx_send_ampdu(sc, tid, bf, txctl);
  1498. } else {
  1499. INIT_LIST_HEAD(&bf_head);
  1500. list_add_tail(&bf->list, &bf_head);
  1501. bf->bf_state.bfs_paprd = txctl->paprd;
  1502. if (bf->bf_state.bfs_paprd)
  1503. ar9003_hw_set_paprd_txdesc(sc->sc_ah, bf->bf_desc,
  1504. bf->bf_state.bfs_paprd);
  1505. if (txctl->paprd)
  1506. bf->bf_state.bfs_paprd_timestamp = jiffies;
  1507. if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
  1508. ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true);
  1509. ath_tx_send_normal(sc, txctl->txq, tid, &bf_head);
  1510. }
  1511. spin_unlock_bh(&txctl->txq->axq_lock);
  1512. }
  1513. /* Upon failure caller should free skb */
  1514. int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
  1515. struct ath_tx_control *txctl)
  1516. {
  1517. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1518. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1519. struct ieee80211_sta *sta = info->control.sta;
  1520. struct ieee80211_vif *vif = info->control.vif;
  1521. struct ath_softc *sc = hw->priv;
  1522. struct ath_txq *txq = txctl->txq;
  1523. struct ath_buf *bf;
  1524. int padpos, padsize;
  1525. int frmlen = skb->len + FCS_LEN;
  1526. int q;
  1527. /* NOTE: sta can be NULL according to net/mac80211.h */
  1528. if (sta)
  1529. txctl->an = (struct ath_node *)sta->drv_priv;
  1530. if (info->control.hw_key)
  1531. frmlen += info->control.hw_key->icv_len;
  1532. /*
  1533. * As a temporary workaround, assign seq# here; this will likely need
  1534. * to be cleaned up to work better with Beacon transmission and virtual
  1535. * BSSes.
  1536. */
  1537. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1538. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1539. sc->tx.seq_no += 0x10;
  1540. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1541. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1542. }
  1543. /* Add the padding after the header if this is not already done */
  1544. padpos = ath9k_cmn_padpos(hdr->frame_control);
  1545. padsize = padpos & 3;
  1546. if (padsize && skb->len > padpos) {
  1547. if (skb_headroom(skb) < padsize)
  1548. return -ENOMEM;
  1549. skb_push(skb, padsize);
  1550. memmove(skb->data, skb->data + padsize, padpos);
  1551. }
  1552. if ((vif && vif->type != NL80211_IFTYPE_AP &&
  1553. vif->type != NL80211_IFTYPE_AP_VLAN) ||
  1554. !ieee80211_is_data(hdr->frame_control))
  1555. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  1556. setup_frame_info(hw, skb, frmlen);
  1557. /*
  1558. * At this point, the vif, hw_key and sta pointers in the tx control
  1559. * info are no longer valid (overwritten by the ath_frame_info data.
  1560. */
  1561. bf = ath_tx_setup_buffer(hw, txctl->txq, skb);
  1562. if (unlikely(!bf))
  1563. return -ENOMEM;
  1564. q = skb_get_queue_mapping(skb);
  1565. spin_lock_bh(&txq->axq_lock);
  1566. if (txq == sc->tx.txq_map[q] &&
  1567. ++txq->pending_frames > ATH_MAX_QDEPTH && !txq->stopped) {
  1568. ieee80211_stop_queue(sc->hw, q);
  1569. txq->stopped = 1;
  1570. }
  1571. spin_unlock_bh(&txq->axq_lock);
  1572. ath_tx_start_dma(sc, bf, txctl);
  1573. return 0;
  1574. }
  1575. /*****************/
  1576. /* TX Completion */
  1577. /*****************/
  1578. static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
  1579. int tx_flags, struct ath_txq *txq)
  1580. {
  1581. struct ieee80211_hw *hw = sc->hw;
  1582. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1583. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1584. struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
  1585. int q, padpos, padsize;
  1586. ath_dbg(common, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
  1587. if (tx_flags & ATH_TX_BAR)
  1588. tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1589. if (!(tx_flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
  1590. /* Frame was ACKed */
  1591. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  1592. }
  1593. padpos = ath9k_cmn_padpos(hdr->frame_control);
  1594. padsize = padpos & 3;
  1595. if (padsize && skb->len>padpos+padsize) {
  1596. /*
  1597. * Remove MAC header padding before giving the frame back to
  1598. * mac80211.
  1599. */
  1600. memmove(skb->data + padsize, skb->data, padpos);
  1601. skb_pull(skb, padsize);
  1602. }
  1603. if (sc->ps_flags & PS_WAIT_FOR_TX_ACK) {
  1604. sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
  1605. ath_dbg(common, ATH_DBG_PS,
  1606. "Going back to sleep after having received TX status (0x%lx)\n",
  1607. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  1608. PS_WAIT_FOR_CAB |
  1609. PS_WAIT_FOR_PSPOLL_DATA |
  1610. PS_WAIT_FOR_TX_ACK));
  1611. }
  1612. q = skb_get_queue_mapping(skb);
  1613. if (txq == sc->tx.txq_map[q]) {
  1614. spin_lock_bh(&txq->axq_lock);
  1615. if (WARN_ON(--txq->pending_frames < 0))
  1616. txq->pending_frames = 0;
  1617. if (txq->stopped && txq->pending_frames < ATH_MAX_QDEPTH) {
  1618. ieee80211_wake_queue(sc->hw, q);
  1619. txq->stopped = 0;
  1620. }
  1621. spin_unlock_bh(&txq->axq_lock);
  1622. }
  1623. ieee80211_tx_status(hw, skb);
  1624. }
  1625. static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
  1626. struct ath_txq *txq, struct list_head *bf_q,
  1627. struct ath_tx_status *ts, int txok, int sendbar)
  1628. {
  1629. struct sk_buff *skb = bf->bf_mpdu;
  1630. unsigned long flags;
  1631. int tx_flags = 0;
  1632. if (sendbar)
  1633. tx_flags = ATH_TX_BAR;
  1634. if (!txok) {
  1635. tx_flags |= ATH_TX_ERROR;
  1636. if (bf_isxretried(bf))
  1637. tx_flags |= ATH_TX_XRETRY;
  1638. }
  1639. dma_unmap_single(sc->dev, bf->bf_buf_addr, skb->len, DMA_TO_DEVICE);
  1640. bf->bf_buf_addr = 0;
  1641. if (bf->bf_state.bfs_paprd) {
  1642. if (time_after(jiffies,
  1643. bf->bf_state.bfs_paprd_timestamp +
  1644. msecs_to_jiffies(ATH_PAPRD_TIMEOUT)))
  1645. dev_kfree_skb_any(skb);
  1646. else
  1647. complete(&sc->paprd_complete);
  1648. } else {
  1649. ath_debug_stat_tx(sc, bf, ts, txq);
  1650. ath_tx_complete(sc, skb, tx_flags, txq);
  1651. }
  1652. /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't
  1653. * accidentally reference it later.
  1654. */
  1655. bf->bf_mpdu = NULL;
  1656. /*
  1657. * Return the list of ath_buf of this mpdu to free queue
  1658. */
  1659. spin_lock_irqsave(&sc->tx.txbuflock, flags);
  1660. list_splice_tail_init(bf_q, &sc->tx.txbuf);
  1661. spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
  1662. }
  1663. static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf,
  1664. struct ath_tx_status *ts, int nframes, int nbad,
  1665. int txok, bool update_rc)
  1666. {
  1667. struct sk_buff *skb = bf->bf_mpdu;
  1668. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1669. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1670. struct ieee80211_hw *hw = sc->hw;
  1671. struct ath_hw *ah = sc->sc_ah;
  1672. u8 i, tx_rateindex;
  1673. if (txok)
  1674. tx_info->status.ack_signal = ts->ts_rssi;
  1675. tx_rateindex = ts->ts_rateindex;
  1676. WARN_ON(tx_rateindex >= hw->max_rates);
  1677. if (ts->ts_status & ATH9K_TXERR_FILT)
  1678. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  1679. if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && update_rc) {
  1680. tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
  1681. BUG_ON(nbad > nframes);
  1682. tx_info->status.ampdu_len = nframes;
  1683. tx_info->status.ampdu_ack_len = nframes - nbad;
  1684. }
  1685. if ((ts->ts_status & ATH9K_TXERR_FILT) == 0 &&
  1686. (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0 && update_rc) {
  1687. /*
  1688. * If an underrun error is seen assume it as an excessive
  1689. * retry only if max frame trigger level has been reached
  1690. * (2 KB for single stream, and 4 KB for dual stream).
  1691. * Adjust the long retry as if the frame was tried
  1692. * hw->max_rate_tries times to affect how rate control updates
  1693. * PER for the failed rate.
  1694. * In case of congestion on the bus penalizing this type of
  1695. * underruns should help hardware actually transmit new frames
  1696. * successfully by eventually preferring slower rates.
  1697. * This itself should also alleviate congestion on the bus.
  1698. */
  1699. if (ieee80211_is_data(hdr->frame_control) &&
  1700. (ts->ts_flags & (ATH9K_TX_DATA_UNDERRUN |
  1701. ATH9K_TX_DELIM_UNDERRUN)) &&
  1702. ah->tx_trig_level >= sc->sc_ah->config.max_txtrig_level)
  1703. tx_info->status.rates[tx_rateindex].count =
  1704. hw->max_rate_tries;
  1705. }
  1706. for (i = tx_rateindex + 1; i < hw->max_rates; i++) {
  1707. tx_info->status.rates[i].count = 0;
  1708. tx_info->status.rates[i].idx = -1;
  1709. }
  1710. tx_info->status.rates[tx_rateindex].count = ts->ts_longretry + 1;
  1711. }
  1712. static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
  1713. struct ath_tx_status *ts, struct ath_buf *bf,
  1714. struct list_head *bf_head)
  1715. __releases(txq->axq_lock)
  1716. __acquires(txq->axq_lock)
  1717. {
  1718. int txok;
  1719. txq->axq_depth--;
  1720. txok = !(ts->ts_status & ATH9K_TXERR_MASK);
  1721. txq->axq_tx_inprogress = false;
  1722. if (bf_is_ampdu_not_probing(bf))
  1723. txq->axq_ampdu_depth--;
  1724. spin_unlock_bh(&txq->axq_lock);
  1725. if (!bf_isampdu(bf)) {
  1726. /*
  1727. * This frame is sent out as a single frame.
  1728. * Use hardware retry status for this frame.
  1729. */
  1730. if (ts->ts_status & ATH9K_TXERR_XRETRY)
  1731. bf->bf_state.bf_type |= BUF_XRETRY;
  1732. ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok, true);
  1733. ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok, 0);
  1734. } else
  1735. ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok, true);
  1736. spin_lock_bh(&txq->axq_lock);
  1737. if (sc->sc_flags & SC_OP_TXAGGR)
  1738. ath_txq_schedule(sc, txq);
  1739. }
  1740. static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
  1741. {
  1742. struct ath_hw *ah = sc->sc_ah;
  1743. struct ath_common *common = ath9k_hw_common(ah);
  1744. struct ath_buf *bf, *lastbf, *bf_held = NULL;
  1745. struct list_head bf_head;
  1746. struct ath_desc *ds;
  1747. struct ath_tx_status ts;
  1748. int status;
  1749. ath_dbg(common, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
  1750. txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
  1751. txq->axq_link);
  1752. spin_lock_bh(&txq->axq_lock);
  1753. for (;;) {
  1754. if (list_empty(&txq->axq_q)) {
  1755. txq->axq_link = NULL;
  1756. if (sc->sc_flags & SC_OP_TXAGGR)
  1757. ath_txq_schedule(sc, txq);
  1758. break;
  1759. }
  1760. bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
  1761. /*
  1762. * There is a race condition that a BH gets scheduled
  1763. * after sw writes TxE and before hw re-load the last
  1764. * descriptor to get the newly chained one.
  1765. * Software must keep the last DONE descriptor as a
  1766. * holding descriptor - software does so by marking
  1767. * it with the STALE flag.
  1768. */
  1769. bf_held = NULL;
  1770. if (bf->bf_stale) {
  1771. bf_held = bf;
  1772. if (list_is_last(&bf_held->list, &txq->axq_q))
  1773. break;
  1774. bf = list_entry(bf_held->list.next, struct ath_buf,
  1775. list);
  1776. }
  1777. lastbf = bf->bf_lastbf;
  1778. ds = lastbf->bf_desc;
  1779. memset(&ts, 0, sizeof(ts));
  1780. status = ath9k_hw_txprocdesc(ah, ds, &ts);
  1781. if (status == -EINPROGRESS)
  1782. break;
  1783. TX_STAT_INC(txq->axq_qnum, txprocdesc);
  1784. /*
  1785. * Remove ath_buf's of the same transmit unit from txq,
  1786. * however leave the last descriptor back as the holding
  1787. * descriptor for hw.
  1788. */
  1789. lastbf->bf_stale = true;
  1790. INIT_LIST_HEAD(&bf_head);
  1791. if (!list_is_singular(&lastbf->list))
  1792. list_cut_position(&bf_head,
  1793. &txq->axq_q, lastbf->list.prev);
  1794. if (bf_held) {
  1795. list_del(&bf_held->list);
  1796. ath_tx_return_buffer(sc, bf_held);
  1797. }
  1798. ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
  1799. }
  1800. spin_unlock_bh(&txq->axq_lock);
  1801. }
  1802. static void ath_tx_complete_poll_work(struct work_struct *work)
  1803. {
  1804. struct ath_softc *sc = container_of(work, struct ath_softc,
  1805. tx_complete_work.work);
  1806. struct ath_txq *txq;
  1807. int i;
  1808. bool needreset = false;
  1809. #ifdef CONFIG_ATH9K_DEBUGFS
  1810. sc->tx_complete_poll_work_seen++;
  1811. #endif
  1812. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1813. if (ATH_TXQ_SETUP(sc, i)) {
  1814. txq = &sc->tx.txq[i];
  1815. spin_lock_bh(&txq->axq_lock);
  1816. if (txq->axq_depth) {
  1817. if (txq->axq_tx_inprogress) {
  1818. needreset = true;
  1819. spin_unlock_bh(&txq->axq_lock);
  1820. break;
  1821. } else {
  1822. txq->axq_tx_inprogress = true;
  1823. }
  1824. }
  1825. spin_unlock_bh(&txq->axq_lock);
  1826. }
  1827. if (needreset) {
  1828. ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET,
  1829. "tx hung, resetting the chip\n");
  1830. spin_lock_bh(&sc->sc_pcu_lock);
  1831. ath_reset(sc, true);
  1832. spin_unlock_bh(&sc->sc_pcu_lock);
  1833. }
  1834. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
  1835. msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
  1836. }
  1837. void ath_tx_tasklet(struct ath_softc *sc)
  1838. {
  1839. int i;
  1840. u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
  1841. ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
  1842. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1843. if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
  1844. ath_tx_processq(sc, &sc->tx.txq[i]);
  1845. }
  1846. }
  1847. void ath_tx_edma_tasklet(struct ath_softc *sc)
  1848. {
  1849. struct ath_tx_status ts;
  1850. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1851. struct ath_hw *ah = sc->sc_ah;
  1852. struct ath_txq *txq;
  1853. struct ath_buf *bf, *lastbf;
  1854. struct list_head bf_head;
  1855. int status;
  1856. for (;;) {
  1857. status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts);
  1858. if (status == -EINPROGRESS)
  1859. break;
  1860. if (status == -EIO) {
  1861. ath_dbg(common, ATH_DBG_XMIT,
  1862. "Error processing tx status\n");
  1863. break;
  1864. }
  1865. /* Skip beacon completions */
  1866. if (ts.qid == sc->beacon.beaconq)
  1867. continue;
  1868. txq = &sc->tx.txq[ts.qid];
  1869. spin_lock_bh(&txq->axq_lock);
  1870. if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) {
  1871. spin_unlock_bh(&txq->axq_lock);
  1872. return;
  1873. }
  1874. bf = list_first_entry(&txq->txq_fifo[txq->txq_tailidx],
  1875. struct ath_buf, list);
  1876. lastbf = bf->bf_lastbf;
  1877. INIT_LIST_HEAD(&bf_head);
  1878. list_cut_position(&bf_head, &txq->txq_fifo[txq->txq_tailidx],
  1879. &lastbf->list);
  1880. if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) {
  1881. INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH);
  1882. if (!list_empty(&txq->axq_q)) {
  1883. struct list_head bf_q;
  1884. INIT_LIST_HEAD(&bf_q);
  1885. txq->axq_link = NULL;
  1886. list_splice_tail_init(&txq->axq_q, &bf_q);
  1887. ath_tx_txqaddbuf(sc, txq, &bf_q, true);
  1888. }
  1889. }
  1890. ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
  1891. spin_unlock_bh(&txq->axq_lock);
  1892. }
  1893. }
  1894. /*****************/
  1895. /* Init, Cleanup */
  1896. /*****************/
  1897. static int ath_txstatus_setup(struct ath_softc *sc, int size)
  1898. {
  1899. struct ath_descdma *dd = &sc->txsdma;
  1900. u8 txs_len = sc->sc_ah->caps.txs_len;
  1901. dd->dd_desc_len = size * txs_len;
  1902. dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
  1903. &dd->dd_desc_paddr, GFP_KERNEL);
  1904. if (!dd->dd_desc)
  1905. return -ENOMEM;
  1906. return 0;
  1907. }
  1908. static int ath_tx_edma_init(struct ath_softc *sc)
  1909. {
  1910. int err;
  1911. err = ath_txstatus_setup(sc, ATH_TXSTATUS_RING_SIZE);
  1912. if (!err)
  1913. ath9k_hw_setup_statusring(sc->sc_ah, sc->txsdma.dd_desc,
  1914. sc->txsdma.dd_desc_paddr,
  1915. ATH_TXSTATUS_RING_SIZE);
  1916. return err;
  1917. }
  1918. static void ath_tx_edma_cleanup(struct ath_softc *sc)
  1919. {
  1920. struct ath_descdma *dd = &sc->txsdma;
  1921. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  1922. dd->dd_desc_paddr);
  1923. }
  1924. int ath_tx_init(struct ath_softc *sc, int nbufs)
  1925. {
  1926. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1927. int error = 0;
  1928. spin_lock_init(&sc->tx.txbuflock);
  1929. error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
  1930. "tx", nbufs, 1, 1);
  1931. if (error != 0) {
  1932. ath_err(common,
  1933. "Failed to allocate tx descriptors: %d\n", error);
  1934. goto err;
  1935. }
  1936. error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
  1937. "beacon", ATH_BCBUF, 1, 1);
  1938. if (error != 0) {
  1939. ath_err(common,
  1940. "Failed to allocate beacon descriptors: %d\n", error);
  1941. goto err;
  1942. }
  1943. INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work);
  1944. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  1945. error = ath_tx_edma_init(sc);
  1946. if (error)
  1947. goto err;
  1948. }
  1949. err:
  1950. if (error != 0)
  1951. ath_tx_cleanup(sc);
  1952. return error;
  1953. }
  1954. void ath_tx_cleanup(struct ath_softc *sc)
  1955. {
  1956. if (sc->beacon.bdma.dd_desc_len != 0)
  1957. ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
  1958. if (sc->tx.txdma.dd_desc_len != 0)
  1959. ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
  1960. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  1961. ath_tx_edma_cleanup(sc);
  1962. }
  1963. void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
  1964. {
  1965. struct ath_atx_tid *tid;
  1966. struct ath_atx_ac *ac;
  1967. int tidno, acno;
  1968. for (tidno = 0, tid = &an->tid[tidno];
  1969. tidno < WME_NUM_TID;
  1970. tidno++, tid++) {
  1971. tid->an = an;
  1972. tid->tidno = tidno;
  1973. tid->seq_start = tid->seq_next = 0;
  1974. tid->baw_size = WME_MAX_BA;
  1975. tid->baw_head = tid->baw_tail = 0;
  1976. tid->sched = false;
  1977. tid->paused = false;
  1978. tid->state &= ~AGGR_CLEANUP;
  1979. __skb_queue_head_init(&tid->buf_q);
  1980. acno = TID_TO_WME_AC(tidno);
  1981. tid->ac = &an->ac[acno];
  1982. tid->state &= ~AGGR_ADDBA_COMPLETE;
  1983. tid->state &= ~AGGR_ADDBA_PROGRESS;
  1984. }
  1985. for (acno = 0, ac = &an->ac[acno];
  1986. acno < WME_NUM_AC; acno++, ac++) {
  1987. ac->sched = false;
  1988. ac->txq = sc->tx.txq_map[acno];
  1989. INIT_LIST_HEAD(&ac->tid_q);
  1990. }
  1991. }
  1992. void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
  1993. {
  1994. struct ath_atx_ac *ac;
  1995. struct ath_atx_tid *tid;
  1996. struct ath_txq *txq;
  1997. int tidno;
  1998. for (tidno = 0, tid = &an->tid[tidno];
  1999. tidno < WME_NUM_TID; tidno++, tid++) {
  2000. ac = tid->ac;
  2001. txq = ac->txq;
  2002. spin_lock_bh(&txq->axq_lock);
  2003. if (tid->sched) {
  2004. list_del(&tid->list);
  2005. tid->sched = false;
  2006. }
  2007. if (ac->sched) {
  2008. list_del(&ac->list);
  2009. tid->ac->sched = false;
  2010. }
  2011. ath_tid_drain(sc, txq, tid);
  2012. tid->state &= ~AGGR_ADDBA_COMPLETE;
  2013. tid->state &= ~AGGR_CLEANUP;
  2014. spin_unlock_bh(&txq->axq_lock);
  2015. }
  2016. }