xmit.c 63 KB

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