xmit.c 73 KB

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