xmit.c 74 KB

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