xmit.c 63 KB

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