xmit.c 75 KB

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