xmit.c 73 KB

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