xmit.c 72 KB

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