xmit.c 63 KB

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