xmit.c 63 KB

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