xmit.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. /*
  2. * Copyright (c) 2008 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 "core.h"
  17. #define BITS_PER_BYTE 8
  18. #define OFDM_PLCP_BITS 22
  19. #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
  20. #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
  21. #define L_STF 8
  22. #define L_LTF 8
  23. #define L_SIG 4
  24. #define HT_SIG 8
  25. #define HT_STF 4
  26. #define HT_LTF(_ns) (4 * (_ns))
  27. #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
  28. #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
  29. #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
  30. #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
  31. #define OFDM_SIFS_TIME 16
  32. static u32 bits_per_symbol[][2] = {
  33. /* 20MHz 40MHz */
  34. { 26, 54 }, /* 0: BPSK */
  35. { 52, 108 }, /* 1: QPSK 1/2 */
  36. { 78, 162 }, /* 2: QPSK 3/4 */
  37. { 104, 216 }, /* 3: 16-QAM 1/2 */
  38. { 156, 324 }, /* 4: 16-QAM 3/4 */
  39. { 208, 432 }, /* 5: 64-QAM 2/3 */
  40. { 234, 486 }, /* 6: 64-QAM 3/4 */
  41. { 260, 540 }, /* 7: 64-QAM 5/6 */
  42. { 52, 108 }, /* 8: BPSK */
  43. { 104, 216 }, /* 9: QPSK 1/2 */
  44. { 156, 324 }, /* 10: QPSK 3/4 */
  45. { 208, 432 }, /* 11: 16-QAM 1/2 */
  46. { 312, 648 }, /* 12: 16-QAM 3/4 */
  47. { 416, 864 }, /* 13: 64-QAM 2/3 */
  48. { 468, 972 }, /* 14: 64-QAM 3/4 */
  49. { 520, 1080 }, /* 15: 64-QAM 5/6 */
  50. };
  51. #define IS_HT_RATE(_rate) ((_rate) & 0x80)
  52. /*
  53. * Insert a chain of ath_buf (descriptors) on a txq and
  54. * assume the descriptors are already chained together by caller.
  55. * NB: must be called with txq lock held
  56. */
  57. static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
  58. struct list_head *head)
  59. {
  60. struct ath_hal *ah = sc->sc_ah;
  61. struct ath_buf *bf;
  62. /*
  63. * Insert the frame on the outbound list and
  64. * pass it on to the hardware.
  65. */
  66. if (list_empty(head))
  67. return;
  68. bf = list_first_entry(head, struct ath_buf, list);
  69. list_splice_tail_init(head, &txq->axq_q);
  70. txq->axq_depth++;
  71. txq->axq_totalqueued++;
  72. txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
  73. DPRINTF(sc, ATH_DBG_QUEUE,
  74. "%s: txq depth = %d\n", __func__, txq->axq_depth);
  75. if (txq->axq_link == NULL) {
  76. ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
  77. DPRINTF(sc, ATH_DBG_XMIT,
  78. "%s: TXDP[%u] = %llx (%p)\n",
  79. __func__, txq->axq_qnum,
  80. ito64(bf->bf_daddr), bf->bf_desc);
  81. } else {
  82. *txq->axq_link = bf->bf_daddr;
  83. DPRINTF(sc, ATH_DBG_XMIT, "%s: link[%u] (%p)=%llx (%p)\n",
  84. __func__,
  85. txq->axq_qnum, txq->axq_link,
  86. ito64(bf->bf_daddr), bf->bf_desc);
  87. }
  88. txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
  89. ath9k_hw_txstart(ah, txq->axq_qnum);
  90. }
  91. /* Check if it's okay to send out aggregates */
  92. static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
  93. {
  94. struct ath_atx_tid *tid;
  95. tid = ATH_AN_2_TID(an, tidno);
  96. if (tid->state & AGGR_ADDBA_COMPLETE ||
  97. tid->state & AGGR_ADDBA_PROGRESS)
  98. return 1;
  99. else
  100. return 0;
  101. }
  102. /* Calculate Atheros packet type from IEEE80211 packet header */
  103. static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
  104. {
  105. struct ieee80211_hdr *hdr;
  106. enum ath9k_pkt_type htype;
  107. __le16 fc;
  108. hdr = (struct ieee80211_hdr *)skb->data;
  109. fc = hdr->frame_control;
  110. if (ieee80211_is_beacon(fc))
  111. htype = ATH9K_PKT_TYPE_BEACON;
  112. else if (ieee80211_is_probe_resp(fc))
  113. htype = ATH9K_PKT_TYPE_PROBE_RESP;
  114. else if (ieee80211_is_atim(fc))
  115. htype = ATH9K_PKT_TYPE_ATIM;
  116. else if (ieee80211_is_pspoll(fc))
  117. htype = ATH9K_PKT_TYPE_PSPOLL;
  118. else
  119. htype = ATH9K_PKT_TYPE_NORMAL;
  120. return htype;
  121. }
  122. static bool is_pae(struct sk_buff *skb)
  123. {
  124. struct ieee80211_hdr *hdr;
  125. __le16 fc;
  126. hdr = (struct ieee80211_hdr *)skb->data;
  127. fc = hdr->frame_control;
  128. if (ieee80211_is_data(fc)) {
  129. if (ieee80211_is_nullfunc(fc) ||
  130. /* Port Access Entity (IEEE 802.1X) */
  131. (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  132. return true;
  133. }
  134. }
  135. return false;
  136. }
  137. static int get_hw_crypto_keytype(struct sk_buff *skb)
  138. {
  139. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  140. if (tx_info->control.hw_key) {
  141. if (tx_info->control.hw_key->alg == ALG_WEP)
  142. return ATH9K_KEY_TYPE_WEP;
  143. else if (tx_info->control.hw_key->alg == ALG_TKIP)
  144. return ATH9K_KEY_TYPE_TKIP;
  145. else if (tx_info->control.hw_key->alg == ALG_CCMP)
  146. return ATH9K_KEY_TYPE_AES;
  147. }
  148. return ATH9K_KEY_TYPE_CLEAR;
  149. }
  150. /* Called only when tx aggregation is enabled and HT is supported */
  151. static void assign_aggr_tid_seqno(struct sk_buff *skb,
  152. struct ath_buf *bf)
  153. {
  154. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  155. struct ieee80211_hdr *hdr;
  156. struct ath_node *an;
  157. struct ath_atx_tid *tid;
  158. __le16 fc;
  159. u8 *qc;
  160. if (!tx_info->control.sta)
  161. return;
  162. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  163. hdr = (struct ieee80211_hdr *)skb->data;
  164. fc = hdr->frame_control;
  165. /* Get tidno */
  166. if (ieee80211_is_data_qos(fc)) {
  167. qc = ieee80211_get_qos_ctl(hdr);
  168. bf->bf_tidno = qc[0] & 0xf;
  169. }
  170. /* Get seqno */
  171. if (ieee80211_is_data(fc) && !is_pae(skb)) {
  172. /* For HT capable stations, we save tidno for later use.
  173. * We also override seqno set by upper layer with the one
  174. * in tx aggregation state.
  175. *
  176. * If fragmentation is on, the sequence number is
  177. * not overridden, since it has been
  178. * incremented by the fragmentation routine.
  179. *
  180. * FIXME: check if the fragmentation threshold exceeds
  181. * IEEE80211 max.
  182. */
  183. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  184. hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
  185. IEEE80211_SEQ_SEQ_SHIFT);
  186. bf->bf_seqno = tid->seq_next;
  187. INCR(tid->seq_next, IEEE80211_SEQ_MAX);
  188. }
  189. }
  190. static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
  191. struct ath_txq *txq)
  192. {
  193. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  194. int flags = 0;
  195. flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
  196. flags |= ATH9K_TXDESC_INTREQ;
  197. if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
  198. flags |= ATH9K_TXDESC_NOACK;
  199. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  200. flags |= ATH9K_TXDESC_RTSENA;
  201. return flags;
  202. }
  203. static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
  204. {
  205. struct ath_buf *bf = NULL;
  206. spin_lock_bh(&sc->sc_txbuflock);
  207. if (unlikely(list_empty(&sc->sc_txbuf))) {
  208. spin_unlock_bh(&sc->sc_txbuflock);
  209. return NULL;
  210. }
  211. bf = list_first_entry(&sc->sc_txbuf, struct ath_buf, list);
  212. list_del(&bf->list);
  213. spin_unlock_bh(&sc->sc_txbuflock);
  214. return bf;
  215. }
  216. /* To complete a chain of buffers associated a frame */
  217. static void ath_tx_complete_buf(struct ath_softc *sc,
  218. struct ath_buf *bf,
  219. struct list_head *bf_q,
  220. int txok, int sendbar)
  221. {
  222. struct sk_buff *skb = bf->bf_mpdu;
  223. struct ath_xmit_status tx_status;
  224. /*
  225. * Set retry information.
  226. * NB: Don't use the information in the descriptor, because the frame
  227. * could be software retried.
  228. */
  229. tx_status.retries = bf->bf_retries;
  230. tx_status.flags = 0;
  231. if (sendbar)
  232. tx_status.flags = ATH_TX_BAR;
  233. if (!txok) {
  234. tx_status.flags |= ATH_TX_ERROR;
  235. if (bf_isxretried(bf))
  236. tx_status.flags |= ATH_TX_XRETRY;
  237. }
  238. /* Unmap this frame */
  239. pci_unmap_single(sc->pdev,
  240. bf->bf_dmacontext,
  241. skb->len,
  242. PCI_DMA_TODEVICE);
  243. /* complete this frame */
  244. ath_tx_complete(sc, skb, &tx_status);
  245. /*
  246. * Return the list of ath_buf of this mpdu to free queue
  247. */
  248. spin_lock_bh(&sc->sc_txbuflock);
  249. list_splice_tail_init(bf_q, &sc->sc_txbuf);
  250. spin_unlock_bh(&sc->sc_txbuflock);
  251. }
  252. /*
  253. * queue up a dest/ac pair for tx scheduling
  254. * NB: must be called with txq lock held
  255. */
  256. static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
  257. {
  258. struct ath_atx_ac *ac = tid->ac;
  259. /*
  260. * if tid is paused, hold off
  261. */
  262. if (tid->paused)
  263. return;
  264. /*
  265. * add tid to ac atmost once
  266. */
  267. if (tid->sched)
  268. return;
  269. tid->sched = true;
  270. list_add_tail(&tid->list, &ac->tid_q);
  271. /*
  272. * add node ac to txq atmost once
  273. */
  274. if (ac->sched)
  275. return;
  276. ac->sched = true;
  277. list_add_tail(&ac->list, &txq->axq_acq);
  278. }
  279. /* pause a tid */
  280. static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  281. {
  282. struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
  283. spin_lock_bh(&txq->axq_lock);
  284. tid->paused++;
  285. spin_unlock_bh(&txq->axq_lock);
  286. }
  287. /* resume a tid and schedule aggregate */
  288. void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  289. {
  290. struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
  291. ASSERT(tid->paused > 0);
  292. spin_lock_bh(&txq->axq_lock);
  293. tid->paused--;
  294. if (tid->paused > 0)
  295. goto unlock;
  296. if (list_empty(&tid->buf_q))
  297. goto unlock;
  298. /*
  299. * Add this TID to scheduler and try to send out aggregates
  300. */
  301. ath_tx_queue_tid(txq, tid);
  302. ath_txq_schedule(sc, txq);
  303. unlock:
  304. spin_unlock_bh(&txq->axq_lock);
  305. }
  306. /* Compute the number of bad frames */
  307. static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
  308. int txok)
  309. {
  310. struct ath_buf *bf_last = bf->bf_lastbf;
  311. struct ath_desc *ds = bf_last->bf_desc;
  312. u16 seq_st = 0;
  313. u32 ba[WME_BA_BMP_SIZE >> 5];
  314. int ba_index;
  315. int nbad = 0;
  316. int isaggr = 0;
  317. if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
  318. return 0;
  319. isaggr = bf_isaggr(bf);
  320. if (isaggr) {
  321. seq_st = ATH_DS_BA_SEQ(ds);
  322. memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
  323. }
  324. while (bf) {
  325. ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
  326. if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
  327. nbad++;
  328. bf = bf->bf_next;
  329. }
  330. return nbad;
  331. }
  332. static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
  333. {
  334. struct sk_buff *skb;
  335. struct ieee80211_hdr *hdr;
  336. bf->bf_state.bf_type |= BUF_RETRY;
  337. bf->bf_retries++;
  338. skb = bf->bf_mpdu;
  339. hdr = (struct ieee80211_hdr *)skb->data;
  340. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
  341. }
  342. /* Update block ack window */
  343. static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
  344. int seqno)
  345. {
  346. int index, cindex;
  347. index = ATH_BA_INDEX(tid->seq_start, seqno);
  348. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  349. tid->tx_buf[cindex] = NULL;
  350. while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
  351. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  352. INCR(tid->baw_head, ATH_TID_MAX_BUFS);
  353. }
  354. }
  355. /*
  356. * ath_pkt_dur - compute packet duration (NB: not NAV)
  357. *
  358. * rix - rate index
  359. * pktlen - total bytes (delims + data + fcs + pads + pad delims)
  360. * width - 0 for 20 MHz, 1 for 40 MHz
  361. * half_gi - to use 4us v/s 3.6 us for symbol time
  362. */
  363. static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
  364. int width, int half_gi, bool shortPreamble)
  365. {
  366. struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
  367. u32 nbits, nsymbits, duration, nsymbols;
  368. u8 rc;
  369. int streams, pktlen;
  370. pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
  371. rc = rate_table->info[rix].ratecode;
  372. /* for legacy rates, use old function to compute packet duration */
  373. if (!IS_HT_RATE(rc))
  374. return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
  375. rix, shortPreamble);
  376. /* find number of symbols: PLCP + data */
  377. nbits = (pktlen << 3) + OFDM_PLCP_BITS;
  378. nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
  379. nsymbols = (nbits + nsymbits - 1) / nsymbits;
  380. if (!half_gi)
  381. duration = SYMBOL_TIME(nsymbols);
  382. else
  383. duration = SYMBOL_TIME_HALFGI(nsymbols);
  384. /* addup duration for legacy/ht training and signal fields */
  385. streams = HT_RC_2_STREAMS(rc);
  386. duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
  387. return duration;
  388. }
  389. /* Rate module function to set rate related fields in tx descriptor */
  390. static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
  391. {
  392. struct ath_hal *ah = sc->sc_ah;
  393. struct ath_rate_table *rt;
  394. struct ath_desc *ds = bf->bf_desc;
  395. struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
  396. struct ath9k_11n_rate_series series[4];
  397. struct ath_node *an = NULL;
  398. struct sk_buff *skb;
  399. struct ieee80211_tx_info *tx_info;
  400. struct ieee80211_tx_rate *rates;
  401. struct ieee80211_hdr *hdr;
  402. int i, flags, rtsctsena = 0;
  403. u32 ctsduration = 0;
  404. u8 rix = 0, cix, ctsrate = 0;
  405. __le16 fc;
  406. memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
  407. skb = (struct sk_buff *)bf->bf_mpdu;
  408. hdr = (struct ieee80211_hdr *)skb->data;
  409. fc = hdr->frame_control;
  410. tx_info = IEEE80211_SKB_CB(skb);
  411. rates = tx_info->control.rates;
  412. if (tx_info->control.sta)
  413. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  414. if (ieee80211_has_morefrags(fc) ||
  415. (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
  416. rates[1].count = rates[2].count = rates[3].count = 0;
  417. rates[1].idx = rates[2].idx = rates[3].idx = 0;
  418. rates[0].count = ATH_TXMAXTRY;
  419. }
  420. /* get the cix for the lowest valid rix */
  421. rt = sc->hw_rate_table[sc->sc_curmode];
  422. for (i = 3; i >= 0; i--) {
  423. if (rates[i].count && (rates[i].idx >= 0)) {
  424. rix = rates[i].idx;
  425. break;
  426. }
  427. }
  428. flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA));
  429. cix = rt->info[rix].ctrl_rate;
  430. /*
  431. * If 802.11g protection is enabled, determine whether to use RTS/CTS or
  432. * just CTS. Note that this is only done for OFDM/HT unicast frames.
  433. */
  434. if (sc->sc_protmode != PROT_M_NONE && !(bf->bf_flags & ATH9K_TXDESC_NOACK)
  435. && (rt->info[rix].phy == WLAN_PHY_OFDM ||
  436. WLAN_RC_PHY_HT(rt->info[rix].phy))) {
  437. if (sc->sc_protmode == PROT_M_RTSCTS)
  438. flags = ATH9K_TXDESC_RTSENA;
  439. else if (sc->sc_protmode == PROT_M_CTSONLY)
  440. flags = ATH9K_TXDESC_CTSENA;
  441. cix = rt->info[sc->sc_protrix].ctrl_rate;
  442. rtsctsena = 1;
  443. }
  444. /* For 11n, the default behavior is to enable RTS for hw retried frames.
  445. * We enable the global flag here and let rate series flags determine
  446. * which rates will actually use RTS.
  447. */
  448. if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
  449. /* 802.11g protection not needed, use our default behavior */
  450. if (!rtsctsena)
  451. flags = ATH9K_TXDESC_RTSENA;
  452. }
  453. /* Set protection if aggregate protection on */
  454. if (sc->sc_config.ath_aggr_prot &&
  455. (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
  456. flags = ATH9K_TXDESC_RTSENA;
  457. cix = rt->info[sc->sc_protrix].ctrl_rate;
  458. rtsctsena = 1;
  459. }
  460. /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
  461. if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit))
  462. flags &= ~(ATH9K_TXDESC_RTSENA);
  463. /*
  464. * CTS transmit rate is derived from the transmit rate by looking in the
  465. * h/w rate table. We must also factor in whether or not a short
  466. * preamble is to be used. NB: cix is set above where RTS/CTS is enabled
  467. */
  468. ctsrate = rt->info[cix].ratecode |
  469. (bf_isshpreamble(bf) ? rt->info[cix].short_preamble : 0);
  470. for (i = 0; i < 4; i++) {
  471. if (!rates[i].count || (rates[i].idx < 0))
  472. continue;
  473. rix = rates[i].idx;
  474. series[i].Rate = rt->info[rix].ratecode |
  475. (bf_isshpreamble(bf) ? rt->info[rix].short_preamble : 0);
  476. series[i].Tries = rates[i].count;
  477. series[i].RateFlags = (
  478. (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ?
  479. ATH9K_RATESERIES_RTS_CTS : 0) |
  480. ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ?
  481. ATH9K_RATESERIES_2040 : 0) |
  482. ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ?
  483. ATH9K_RATESERIES_HALFGI : 0);
  484. series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
  485. (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
  486. (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
  487. bf_isshpreamble(bf));
  488. if (bf_isht(bf) && an)
  489. series[i].ChSel = ath_chainmask_sel_logic(sc, an);
  490. else
  491. series[i].ChSel = sc->sc_tx_chainmask;
  492. if (rtsctsena)
  493. series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
  494. }
  495. /* set dur_update_en for l-sig computation except for PS-Poll frames */
  496. ath9k_hw_set11n_ratescenario(ah, ds, lastds, !bf_ispspoll(bf),
  497. ctsrate, ctsduration,
  498. series, 4, flags);
  499. if (sc->sc_config.ath_aggr_prot && flags)
  500. ath9k_hw_set11n_burstduration(ah, ds, 8192);
  501. }
  502. /*
  503. * Function to send a normal HT (non-AMPDU) frame
  504. * NB: must be called with txq lock held
  505. */
  506. static int ath_tx_send_normal(struct ath_softc *sc,
  507. struct ath_txq *txq,
  508. struct ath_atx_tid *tid,
  509. struct list_head *bf_head)
  510. {
  511. struct ath_buf *bf;
  512. BUG_ON(list_empty(bf_head));
  513. bf = list_first_entry(bf_head, struct ath_buf, list);
  514. bf->bf_state.bf_type &= ~BUF_AMPDU; /* regular HT frame */
  515. /* update starting sequence number for subsequent ADDBA request */
  516. INCR(tid->seq_start, IEEE80211_SEQ_MAX);
  517. /* Queue to h/w without aggregation */
  518. bf->bf_nframes = 1;
  519. bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
  520. ath_buf_set_rate(sc, bf);
  521. ath_tx_txqaddbuf(sc, txq, bf_head);
  522. return 0;
  523. }
  524. /* flush tid's software queue and send frames as non-ampdu's */
  525. static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
  526. {
  527. struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
  528. struct ath_buf *bf;
  529. struct list_head bf_head;
  530. INIT_LIST_HEAD(&bf_head);
  531. ASSERT(tid->paused > 0);
  532. spin_lock_bh(&txq->axq_lock);
  533. tid->paused--;
  534. if (tid->paused > 0) {
  535. spin_unlock_bh(&txq->axq_lock);
  536. return;
  537. }
  538. while (!list_empty(&tid->buf_q)) {
  539. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  540. ASSERT(!bf_isretried(bf));
  541. list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
  542. ath_tx_send_normal(sc, txq, tid, &bf_head);
  543. }
  544. spin_unlock_bh(&txq->axq_lock);
  545. }
  546. /* Completion routine of an aggregate */
  547. static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
  548. struct ath_txq *txq,
  549. struct ath_buf *bf,
  550. struct list_head *bf_q,
  551. int txok)
  552. {
  553. struct ath_node *an = NULL;
  554. struct sk_buff *skb;
  555. struct ieee80211_tx_info *tx_info;
  556. struct ath_atx_tid *tid = NULL;
  557. struct ath_buf *bf_last = bf->bf_lastbf;
  558. struct ath_desc *ds = bf_last->bf_desc;
  559. struct ath_buf *bf_next, *bf_lastq = NULL;
  560. struct list_head bf_head, bf_pending;
  561. u16 seq_st = 0;
  562. u32 ba[WME_BA_BMP_SIZE >> 5];
  563. int isaggr, txfail, txpending, sendbar = 0, needreset = 0;
  564. skb = (struct sk_buff *)bf->bf_mpdu;
  565. tx_info = IEEE80211_SKB_CB(skb);
  566. if (tx_info->control.sta) {
  567. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  568. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  569. }
  570. isaggr = bf_isaggr(bf);
  571. if (isaggr) {
  572. if (txok) {
  573. if (ATH_DS_TX_BA(ds)) {
  574. /*
  575. * extract starting sequence and
  576. * block-ack bitmap
  577. */
  578. seq_st = ATH_DS_BA_SEQ(ds);
  579. memcpy(ba,
  580. ATH_DS_BA_BITMAP(ds),
  581. WME_BA_BMP_SIZE >> 3);
  582. } else {
  583. memset(ba, 0, WME_BA_BMP_SIZE >> 3);
  584. /*
  585. * AR5416 can become deaf/mute when BA
  586. * issue happens. Chip needs to be reset.
  587. * But AP code may have sychronization issues
  588. * when perform internal reset in this routine.
  589. * Only enable reset in STA mode for now.
  590. */
  591. if (sc->sc_ah->ah_opmode == ATH9K_M_STA)
  592. needreset = 1;
  593. }
  594. } else {
  595. memset(ba, 0, WME_BA_BMP_SIZE >> 3);
  596. }
  597. }
  598. INIT_LIST_HEAD(&bf_pending);
  599. INIT_LIST_HEAD(&bf_head);
  600. while (bf) {
  601. txfail = txpending = 0;
  602. bf_next = bf->bf_next;
  603. if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
  604. /* transmit completion, subframe is
  605. * acked by block ack */
  606. } else if (!isaggr && txok) {
  607. /* transmit completion */
  608. } else {
  609. if (!(tid->state & AGGR_CLEANUP) &&
  610. ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
  611. if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
  612. ath_tx_set_retry(sc, bf);
  613. txpending = 1;
  614. } else {
  615. bf->bf_state.bf_type |= BUF_XRETRY;
  616. txfail = 1;
  617. sendbar = 1;
  618. }
  619. } else {
  620. /*
  621. * cleanup in progress, just fail
  622. * the un-acked sub-frames
  623. */
  624. txfail = 1;
  625. }
  626. }
  627. /*
  628. * Remove ath_buf's of this sub-frame from aggregate queue.
  629. */
  630. if (bf_next == NULL) { /* last subframe in the aggregate */
  631. ASSERT(bf->bf_lastfrm == bf_last);
  632. /*
  633. * The last descriptor of the last sub frame could be
  634. * a holding descriptor for h/w. If that's the case,
  635. * bf->bf_lastfrm won't be in the bf_q.
  636. * Make sure we handle bf_q properly here.
  637. */
  638. if (!list_empty(bf_q)) {
  639. bf_lastq = list_entry(bf_q->prev,
  640. struct ath_buf, list);
  641. list_cut_position(&bf_head,
  642. bf_q, &bf_lastq->list);
  643. } else {
  644. /*
  645. * XXX: if the last subframe only has one
  646. * descriptor which is also being used as
  647. * a holding descriptor. Then the ath_buf
  648. * is not in the bf_q at all.
  649. */
  650. INIT_LIST_HEAD(&bf_head);
  651. }
  652. } else {
  653. ASSERT(!list_empty(bf_q));
  654. list_cut_position(&bf_head,
  655. bf_q, &bf->bf_lastfrm->list);
  656. }
  657. if (!txpending) {
  658. /*
  659. * complete the acked-ones/xretried ones; update
  660. * block-ack window
  661. */
  662. spin_lock_bh(&txq->axq_lock);
  663. ath_tx_update_baw(sc, tid, bf->bf_seqno);
  664. spin_unlock_bh(&txq->axq_lock);
  665. /* complete this sub-frame */
  666. ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar);
  667. } else {
  668. /*
  669. * retry the un-acked ones
  670. */
  671. /*
  672. * XXX: if the last descriptor is holding descriptor,
  673. * in order to requeue the frame to software queue, we
  674. * need to allocate a new descriptor and
  675. * copy the content of holding descriptor to it.
  676. */
  677. if (bf->bf_next == NULL &&
  678. bf_last->bf_status & ATH_BUFSTATUS_STALE) {
  679. struct ath_buf *tbf;
  680. /* allocate new descriptor */
  681. spin_lock_bh(&sc->sc_txbuflock);
  682. ASSERT(!list_empty((&sc->sc_txbuf)));
  683. tbf = list_first_entry(&sc->sc_txbuf,
  684. struct ath_buf, list);
  685. list_del(&tbf->list);
  686. spin_unlock_bh(&sc->sc_txbuflock);
  687. ATH_TXBUF_RESET(tbf);
  688. /* copy descriptor content */
  689. tbf->bf_mpdu = bf_last->bf_mpdu;
  690. tbf->bf_buf_addr = bf_last->bf_buf_addr;
  691. *(tbf->bf_desc) = *(bf_last->bf_desc);
  692. /* link it to the frame */
  693. if (bf_lastq) {
  694. bf_lastq->bf_desc->ds_link =
  695. tbf->bf_daddr;
  696. bf->bf_lastfrm = tbf;
  697. ath9k_hw_cleartxdesc(sc->sc_ah,
  698. bf->bf_lastfrm->bf_desc);
  699. } else {
  700. tbf->bf_state = bf_last->bf_state;
  701. tbf->bf_lastfrm = tbf;
  702. ath9k_hw_cleartxdesc(sc->sc_ah,
  703. tbf->bf_lastfrm->bf_desc);
  704. /* copy the DMA context */
  705. tbf->bf_dmacontext =
  706. bf_last->bf_dmacontext;
  707. }
  708. list_add_tail(&tbf->list, &bf_head);
  709. } else {
  710. /*
  711. * Clear descriptor status words for
  712. * software retry
  713. */
  714. ath9k_hw_cleartxdesc(sc->sc_ah,
  715. bf->bf_lastfrm->bf_desc);
  716. }
  717. /*
  718. * Put this buffer to the temporary pending
  719. * queue to retain ordering
  720. */
  721. list_splice_tail_init(&bf_head, &bf_pending);
  722. }
  723. bf = bf_next;
  724. }
  725. if (tid->state & AGGR_CLEANUP) {
  726. /* check to see if we're done with cleaning the h/w queue */
  727. spin_lock_bh(&txq->axq_lock);
  728. if (tid->baw_head == tid->baw_tail) {
  729. tid->state &= ~AGGR_ADDBA_COMPLETE;
  730. tid->addba_exchangeattempts = 0;
  731. spin_unlock_bh(&txq->axq_lock);
  732. tid->state &= ~AGGR_CLEANUP;
  733. /* send buffered frames as singles */
  734. ath_tx_flush_tid(sc, tid);
  735. } else
  736. spin_unlock_bh(&txq->axq_lock);
  737. return;
  738. }
  739. /*
  740. * prepend un-acked frames to the beginning of the pending frame queue
  741. */
  742. if (!list_empty(&bf_pending)) {
  743. spin_lock_bh(&txq->axq_lock);
  744. /* Note: we _prepend_, we _do_not_ at to
  745. * the end of the queue ! */
  746. list_splice(&bf_pending, &tid->buf_q);
  747. ath_tx_queue_tid(txq, tid);
  748. spin_unlock_bh(&txq->axq_lock);
  749. }
  750. if (needreset)
  751. ath_reset(sc, false);
  752. return;
  753. }
  754. /* Process completed xmit descriptors from the specified queue */
  755. static int ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
  756. {
  757. struct ath_hal *ah = sc->sc_ah;
  758. struct ath_buf *bf, *lastbf, *bf_held = NULL;
  759. struct list_head bf_head;
  760. struct ath_desc *ds, *tmp_ds;
  761. struct sk_buff *skb;
  762. struct ieee80211_tx_info *tx_info;
  763. struct ath_tx_info_priv *tx_info_priv;
  764. int nacked, txok, nbad = 0, isrifs = 0;
  765. int status;
  766. DPRINTF(sc, ATH_DBG_QUEUE,
  767. "%s: tx queue %d (%x), link %p\n", __func__,
  768. txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
  769. txq->axq_link);
  770. nacked = 0;
  771. for (;;) {
  772. spin_lock_bh(&txq->axq_lock);
  773. if (list_empty(&txq->axq_q)) {
  774. txq->axq_link = NULL;
  775. txq->axq_linkbuf = NULL;
  776. spin_unlock_bh(&txq->axq_lock);
  777. break;
  778. }
  779. bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
  780. /*
  781. * There is a race condition that a BH gets scheduled
  782. * after sw writes TxE and before hw re-load the last
  783. * descriptor to get the newly chained one.
  784. * Software must keep the last DONE descriptor as a
  785. * holding descriptor - software does so by marking
  786. * it with the STALE flag.
  787. */
  788. bf_held = NULL;
  789. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  790. bf_held = bf;
  791. if (list_is_last(&bf_held->list, &txq->axq_q)) {
  792. /* FIXME:
  793. * The holding descriptor is the last
  794. * descriptor in queue. It's safe to remove
  795. * the last holding descriptor in BH context.
  796. */
  797. spin_unlock_bh(&txq->axq_lock);
  798. break;
  799. } else {
  800. /* Lets work with the next buffer now */
  801. bf = list_entry(bf_held->list.next,
  802. struct ath_buf, list);
  803. }
  804. }
  805. lastbf = bf->bf_lastbf;
  806. ds = lastbf->bf_desc; /* NB: last decriptor */
  807. status = ath9k_hw_txprocdesc(ah, ds);
  808. if (status == -EINPROGRESS) {
  809. spin_unlock_bh(&txq->axq_lock);
  810. break;
  811. }
  812. if (bf->bf_desc == txq->axq_lastdsWithCTS)
  813. txq->axq_lastdsWithCTS = NULL;
  814. if (ds == txq->axq_gatingds)
  815. txq->axq_gatingds = NULL;
  816. /*
  817. * Remove ath_buf's of the same transmit unit from txq,
  818. * however leave the last descriptor back as the holding
  819. * descriptor for hw.
  820. */
  821. lastbf->bf_status |= ATH_BUFSTATUS_STALE;
  822. INIT_LIST_HEAD(&bf_head);
  823. if (!list_is_singular(&lastbf->list))
  824. list_cut_position(&bf_head,
  825. &txq->axq_q, lastbf->list.prev);
  826. txq->axq_depth--;
  827. if (bf_isaggr(bf))
  828. txq->axq_aggr_depth--;
  829. txok = (ds->ds_txstat.ts_status == 0);
  830. spin_unlock_bh(&txq->axq_lock);
  831. if (bf_held) {
  832. list_del(&bf_held->list);
  833. spin_lock_bh(&sc->sc_txbuflock);
  834. list_add_tail(&bf_held->list, &sc->sc_txbuf);
  835. spin_unlock_bh(&sc->sc_txbuflock);
  836. }
  837. if (!bf_isampdu(bf)) {
  838. /*
  839. * This frame is sent out as a single frame.
  840. * Use hardware retry status for this frame.
  841. */
  842. bf->bf_retries = ds->ds_txstat.ts_longretry;
  843. if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
  844. bf->bf_state.bf_type |= BUF_XRETRY;
  845. nbad = 0;
  846. } else {
  847. nbad = ath_tx_num_badfrms(sc, bf, txok);
  848. }
  849. skb = bf->bf_mpdu;
  850. tx_info = IEEE80211_SKB_CB(skb);
  851. tx_info_priv =
  852. (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
  853. if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
  854. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  855. if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
  856. (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
  857. if (ds->ds_txstat.ts_status == 0)
  858. nacked++;
  859. if (bf_isdata(bf)) {
  860. if (isrifs)
  861. tmp_ds = bf->bf_rifslast->bf_desc;
  862. else
  863. tmp_ds = ds;
  864. memcpy(&tx_info_priv->tx,
  865. &tmp_ds->ds_txstat,
  866. sizeof(tx_info_priv->tx));
  867. tx_info_priv->n_frames = bf->bf_nframes;
  868. tx_info_priv->n_bad_frames = nbad;
  869. }
  870. }
  871. /*
  872. * Complete this transmit unit
  873. */
  874. if (bf_isampdu(bf))
  875. ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok);
  876. else
  877. ath_tx_complete_buf(sc, bf, &bf_head, txok, 0);
  878. /* Wake up mac80211 queue */
  879. spin_lock_bh(&txq->axq_lock);
  880. if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <=
  881. (ATH_TXBUF - 20)) {
  882. int qnum;
  883. qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
  884. if (qnum != -1) {
  885. ieee80211_wake_queue(sc->hw, qnum);
  886. txq->stopped = 0;
  887. }
  888. }
  889. /*
  890. * schedule any pending packets if aggregation is enabled
  891. */
  892. if (sc->sc_flags & SC_OP_TXAGGR)
  893. ath_txq_schedule(sc, txq);
  894. spin_unlock_bh(&txq->axq_lock);
  895. }
  896. return nacked;
  897. }
  898. static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq)
  899. {
  900. struct ath_hal *ah = sc->sc_ah;
  901. (void) ath9k_hw_stoptxdma(ah, txq->axq_qnum);
  902. DPRINTF(sc, ATH_DBG_XMIT, "%s: tx queue [%u] %x, link %p\n",
  903. __func__, txq->axq_qnum,
  904. ath9k_hw_gettxbuf(ah, txq->axq_qnum), txq->axq_link);
  905. }
  906. /* Drain only the data queues */
  907. static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
  908. {
  909. struct ath_hal *ah = sc->sc_ah;
  910. int i, status, npend = 0;
  911. if (!(sc->sc_flags & SC_OP_INVALID)) {
  912. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  913. if (ATH_TXQ_SETUP(sc, i)) {
  914. ath_tx_stopdma(sc, &sc->sc_txq[i]);
  915. /* The TxDMA may not really be stopped.
  916. * Double check the hal tx pending count */
  917. npend += ath9k_hw_numtxpending(ah,
  918. sc->sc_txq[i].axq_qnum);
  919. }
  920. }
  921. }
  922. if (npend) {
  923. /* TxDMA not stopped, reset the hal */
  924. DPRINTF(sc, ATH_DBG_XMIT,
  925. "%s: Unable to stop TxDMA. Reset HAL!\n", __func__);
  926. spin_lock_bh(&sc->sc_resetlock);
  927. if (!ath9k_hw_reset(ah,
  928. sc->sc_ah->ah_curchan,
  929. sc->sc_ht_info.tx_chan_width,
  930. sc->sc_tx_chainmask, sc->sc_rx_chainmask,
  931. sc->sc_ht_extprotspacing, true, &status)) {
  932. DPRINTF(sc, ATH_DBG_FATAL,
  933. "%s: unable to reset hardware; hal status %u\n",
  934. __func__,
  935. status);
  936. }
  937. spin_unlock_bh(&sc->sc_resetlock);
  938. }
  939. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  940. if (ATH_TXQ_SETUP(sc, i))
  941. ath_tx_draintxq(sc, &sc->sc_txq[i], retry_tx);
  942. }
  943. }
  944. /* Add a sub-frame to block ack window */
  945. static void ath_tx_addto_baw(struct ath_softc *sc,
  946. struct ath_atx_tid *tid,
  947. struct ath_buf *bf)
  948. {
  949. int index, cindex;
  950. if (bf_isretried(bf))
  951. return;
  952. index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
  953. cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  954. ASSERT(tid->tx_buf[cindex] == NULL);
  955. tid->tx_buf[cindex] = bf;
  956. if (index >= ((tid->baw_tail - tid->baw_head) &
  957. (ATH_TID_MAX_BUFS - 1))) {
  958. tid->baw_tail = cindex;
  959. INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
  960. }
  961. }
  962. /*
  963. * Function to send an A-MPDU
  964. * NB: must be called with txq lock held
  965. */
  966. static int ath_tx_send_ampdu(struct ath_softc *sc,
  967. struct ath_atx_tid *tid,
  968. struct list_head *bf_head,
  969. struct ath_tx_control *txctl)
  970. {
  971. struct ath_buf *bf;
  972. BUG_ON(list_empty(bf_head));
  973. bf = list_first_entry(bf_head, struct ath_buf, list);
  974. bf->bf_state.bf_type |= BUF_AMPDU;
  975. /*
  976. * Do not queue to h/w when any of the following conditions is true:
  977. * - there are pending frames in software queue
  978. * - the TID is currently paused for ADDBA/BAR request
  979. * - seqno is not within block-ack window
  980. * - h/w queue depth exceeds low water mark
  981. */
  982. if (!list_empty(&tid->buf_q) || tid->paused ||
  983. !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
  984. txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
  985. /*
  986. * Add this frame to software queue for scheduling later
  987. * for aggregation.
  988. */
  989. list_splice_tail_init(bf_head, &tid->buf_q);
  990. ath_tx_queue_tid(txctl->txq, tid);
  991. return 0;
  992. }
  993. /* Add sub-frame to BAW */
  994. ath_tx_addto_baw(sc, tid, bf);
  995. /* Queue to h/w without aggregation */
  996. bf->bf_nframes = 1;
  997. bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
  998. ath_buf_set_rate(sc, bf);
  999. ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
  1000. return 0;
  1001. }
  1002. /*
  1003. * looks up the rate
  1004. * returns aggr limit based on lowest of the rates
  1005. */
  1006. static u32 ath_lookup_rate(struct ath_softc *sc,
  1007. struct ath_buf *bf,
  1008. struct ath_atx_tid *tid)
  1009. {
  1010. struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
  1011. struct sk_buff *skb;
  1012. struct ieee80211_tx_info *tx_info;
  1013. struct ieee80211_tx_rate *rates;
  1014. struct ath_tx_info_priv *tx_info_priv;
  1015. u32 max_4ms_framelen, frame_length;
  1016. u16 aggr_limit, legacy = 0, maxampdu;
  1017. int i;
  1018. skb = (struct sk_buff *)bf->bf_mpdu;
  1019. tx_info = IEEE80211_SKB_CB(skb);
  1020. rates = tx_info->control.rates;
  1021. tx_info_priv =
  1022. (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
  1023. /*
  1024. * Find the lowest frame length among the rate series that will have a
  1025. * 4ms transmit duration.
  1026. * TODO - TXOP limit needs to be considered.
  1027. */
  1028. max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
  1029. for (i = 0; i < 4; i++) {
  1030. if (rates[i].count) {
  1031. if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
  1032. legacy = 1;
  1033. break;
  1034. }
  1035. frame_length =
  1036. rate_table->info[rates[i].idx].max_4ms_framelen;
  1037. max_4ms_framelen = min(max_4ms_framelen, frame_length);
  1038. }
  1039. }
  1040. /*
  1041. * limit aggregate size by the minimum rate if rate selected is
  1042. * not a probe rate, if rate selected is a probe rate then
  1043. * avoid aggregation of this packet.
  1044. */
  1045. if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
  1046. return 0;
  1047. aggr_limit = min(max_4ms_framelen,
  1048. (u32)ATH_AMPDU_LIMIT_DEFAULT);
  1049. /*
  1050. * h/w can accept aggregates upto 16 bit lengths (65535).
  1051. * The IE, however can hold upto 65536, which shows up here
  1052. * as zero. Ignore 65536 since we are constrained by hw.
  1053. */
  1054. maxampdu = tid->an->maxampdu;
  1055. if (maxampdu)
  1056. aggr_limit = min(aggr_limit, maxampdu);
  1057. return aggr_limit;
  1058. }
  1059. /*
  1060. * returns the number of delimiters to be added to
  1061. * meet the minimum required mpdudensity.
  1062. * caller should make sure that the rate is HT rate .
  1063. */
  1064. static int ath_compute_num_delims(struct ath_softc *sc,
  1065. struct ath_atx_tid *tid,
  1066. struct ath_buf *bf,
  1067. u16 frmlen)
  1068. {
  1069. struct ath_rate_table *rt = sc->hw_rate_table[sc->sc_curmode];
  1070. struct sk_buff *skb = bf->bf_mpdu;
  1071. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1072. u32 nsymbits, nsymbols, mpdudensity;
  1073. u16 minlen;
  1074. u8 rc, flags, rix;
  1075. int width, half_gi, ndelim, mindelim;
  1076. /* Select standard number of delimiters based on frame length alone */
  1077. ndelim = ATH_AGGR_GET_NDELIM(frmlen);
  1078. /*
  1079. * If encryption enabled, hardware requires some more padding between
  1080. * subframes.
  1081. * TODO - this could be improved to be dependent on the rate.
  1082. * The hardware can keep up at lower rates, but not higher rates
  1083. */
  1084. if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
  1085. ndelim += ATH_AGGR_ENCRYPTDELIM;
  1086. /*
  1087. * Convert desired mpdu density from microeconds to bytes based
  1088. * on highest rate in rate series (i.e. first rate) to determine
  1089. * required minimum length for subframe. Take into account
  1090. * whether high rate is 20 or 40Mhz and half or full GI.
  1091. */
  1092. mpdudensity = tid->an->mpdudensity;
  1093. /*
  1094. * If there is no mpdu density restriction, no further calculation
  1095. * is needed.
  1096. */
  1097. if (mpdudensity == 0)
  1098. return ndelim;
  1099. rix = tx_info->control.rates[0].idx;
  1100. flags = tx_info->control.rates[0].flags;
  1101. rc = rt->info[rix].ratecode;
  1102. width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
  1103. half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
  1104. if (half_gi)
  1105. nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity);
  1106. else
  1107. nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity);
  1108. if (nsymbols == 0)
  1109. nsymbols = 1;
  1110. nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
  1111. minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
  1112. /* Is frame shorter than required minimum length? */
  1113. if (frmlen < minlen) {
  1114. /* Get the minimum number of delimiters required. */
  1115. mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
  1116. ndelim = max(mindelim, ndelim);
  1117. }
  1118. return ndelim;
  1119. }
  1120. /*
  1121. * For aggregation from software buffer queue.
  1122. * NB: must be called with txq lock held
  1123. */
  1124. static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
  1125. struct ath_atx_tid *tid,
  1126. struct list_head *bf_q,
  1127. struct ath_buf **bf_last,
  1128. struct aggr_rifs_param *param,
  1129. int *prev_frames)
  1130. {
  1131. #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
  1132. struct ath_buf *bf, *tbf, *bf_first, *bf_prev = NULL;
  1133. struct list_head bf_head;
  1134. int rl = 0, nframes = 0, ndelim;
  1135. u16 aggr_limit = 0, al = 0, bpad = 0,
  1136. al_delta, h_baw = tid->baw_size / 2;
  1137. enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
  1138. int prev_al = 0;
  1139. INIT_LIST_HEAD(&bf_head);
  1140. BUG_ON(list_empty(&tid->buf_q));
  1141. bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
  1142. do {
  1143. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  1144. /*
  1145. * do not step over block-ack window
  1146. */
  1147. if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
  1148. status = ATH_AGGR_BAW_CLOSED;
  1149. break;
  1150. }
  1151. if (!rl) {
  1152. aggr_limit = ath_lookup_rate(sc, bf, tid);
  1153. rl = 1;
  1154. }
  1155. /*
  1156. * do not exceed aggregation limit
  1157. */
  1158. al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
  1159. if (nframes && (aggr_limit <
  1160. (al + bpad + al_delta + prev_al))) {
  1161. status = ATH_AGGR_LIMITED;
  1162. break;
  1163. }
  1164. /*
  1165. * do not exceed subframe limit
  1166. */
  1167. if ((nframes + *prev_frames) >=
  1168. min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
  1169. status = ATH_AGGR_LIMITED;
  1170. break;
  1171. }
  1172. /*
  1173. * add padding for previous frame to aggregation length
  1174. */
  1175. al += bpad + al_delta;
  1176. /*
  1177. * Get the delimiters needed to meet the MPDU
  1178. * density for this node.
  1179. */
  1180. ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
  1181. bpad = PADBYTES(al_delta) + (ndelim << 2);
  1182. bf->bf_next = NULL;
  1183. bf->bf_lastfrm->bf_desc->ds_link = 0;
  1184. /*
  1185. * this packet is part of an aggregate
  1186. * - remove all descriptors belonging to this frame from
  1187. * software queue
  1188. * - add it to block ack window
  1189. * - set up descriptors for aggregation
  1190. */
  1191. list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
  1192. ath_tx_addto_baw(sc, tid, bf);
  1193. list_for_each_entry(tbf, &bf_head, list) {
  1194. ath9k_hw_set11n_aggr_middle(sc->sc_ah,
  1195. tbf->bf_desc, ndelim);
  1196. }
  1197. /*
  1198. * link buffers of this frame to the aggregate
  1199. */
  1200. list_splice_tail_init(&bf_head, bf_q);
  1201. nframes++;
  1202. if (bf_prev) {
  1203. bf_prev->bf_next = bf;
  1204. bf_prev->bf_lastfrm->bf_desc->ds_link = bf->bf_daddr;
  1205. }
  1206. bf_prev = bf;
  1207. #ifdef AGGR_NOSHORT
  1208. /*
  1209. * terminate aggregation on a small packet boundary
  1210. */
  1211. if (bf->bf_frmlen < ATH_AGGR_MINPLEN) {
  1212. status = ATH_AGGR_SHORTPKT;
  1213. break;
  1214. }
  1215. #endif
  1216. } while (!list_empty(&tid->buf_q));
  1217. bf_first->bf_al = al;
  1218. bf_first->bf_nframes = nframes;
  1219. *bf_last = bf_prev;
  1220. return status;
  1221. #undef PADBYTES
  1222. }
  1223. /*
  1224. * process pending frames possibly doing a-mpdu aggregation
  1225. * NB: must be called with txq lock held
  1226. */
  1227. static void ath_tx_sched_aggr(struct ath_softc *sc,
  1228. struct ath_txq *txq, struct ath_atx_tid *tid)
  1229. {
  1230. struct ath_buf *bf, *tbf, *bf_last, *bf_lastaggr = NULL;
  1231. enum ATH_AGGR_STATUS status;
  1232. struct list_head bf_q;
  1233. struct aggr_rifs_param param = {0, 0, 0, 0, NULL};
  1234. int prev_frames = 0;
  1235. do {
  1236. if (list_empty(&tid->buf_q))
  1237. return;
  1238. INIT_LIST_HEAD(&bf_q);
  1239. status = ath_tx_form_aggr(sc, tid, &bf_q, &bf_lastaggr, &param,
  1240. &prev_frames);
  1241. /*
  1242. * no frames picked up to be aggregated; block-ack
  1243. * window is not open
  1244. */
  1245. if (list_empty(&bf_q))
  1246. break;
  1247. bf = list_first_entry(&bf_q, struct ath_buf, list);
  1248. bf_last = list_entry(bf_q.prev, struct ath_buf, list);
  1249. bf->bf_lastbf = bf_last;
  1250. /*
  1251. * if only one frame, send as non-aggregate
  1252. */
  1253. if (bf->bf_nframes == 1) {
  1254. ASSERT(bf->bf_lastfrm == bf_last);
  1255. bf->bf_state.bf_type &= ~BUF_AGGR;
  1256. /*
  1257. * clear aggr bits for every descriptor
  1258. * XXX TODO: is there a way to optimize it?
  1259. */
  1260. list_for_each_entry(tbf, &bf_q, list) {
  1261. ath9k_hw_clr11n_aggr(sc->sc_ah, tbf->bf_desc);
  1262. }
  1263. ath_buf_set_rate(sc, bf);
  1264. ath_tx_txqaddbuf(sc, txq, &bf_q);
  1265. continue;
  1266. }
  1267. /*
  1268. * setup first desc with rate and aggr info
  1269. */
  1270. bf->bf_state.bf_type |= BUF_AGGR;
  1271. ath_buf_set_rate(sc, bf);
  1272. ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
  1273. /*
  1274. * anchor last frame of aggregate correctly
  1275. */
  1276. ASSERT(bf_lastaggr);
  1277. ASSERT(bf_lastaggr->bf_lastfrm == bf_last);
  1278. tbf = bf_lastaggr;
  1279. ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
  1280. /* XXX: We don't enter into this loop, consider removing this */
  1281. while (!list_empty(&bf_q) && !list_is_last(&tbf->list, &bf_q)) {
  1282. tbf = list_entry(tbf->list.next, struct ath_buf, list);
  1283. ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
  1284. }
  1285. txq->axq_aggr_depth++;
  1286. /*
  1287. * Normal aggregate, queue to hardware
  1288. */
  1289. ath_tx_txqaddbuf(sc, txq, &bf_q);
  1290. } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
  1291. status != ATH_AGGR_BAW_CLOSED);
  1292. }
  1293. /* Called with txq lock held */
  1294. static void ath_tid_drain(struct ath_softc *sc,
  1295. struct ath_txq *txq,
  1296. struct ath_atx_tid *tid)
  1297. {
  1298. struct ath_buf *bf;
  1299. struct list_head bf_head;
  1300. INIT_LIST_HEAD(&bf_head);
  1301. for (;;) {
  1302. if (list_empty(&tid->buf_q))
  1303. break;
  1304. bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
  1305. list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
  1306. /* update baw for software retried frame */
  1307. if (bf_isretried(bf))
  1308. ath_tx_update_baw(sc, tid, bf->bf_seqno);
  1309. /*
  1310. * do not indicate packets while holding txq spinlock.
  1311. * unlock is intentional here
  1312. */
  1313. spin_unlock(&txq->axq_lock);
  1314. /* complete this sub-frame */
  1315. ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
  1316. spin_lock(&txq->axq_lock);
  1317. }
  1318. /*
  1319. * TODO: For frame(s) that are in the retry state, we will reuse the
  1320. * sequence number(s) without setting the retry bit. The
  1321. * alternative is to give up on these and BAR the receiver's window
  1322. * forward.
  1323. */
  1324. tid->seq_next = tid->seq_start;
  1325. tid->baw_tail = tid->baw_head;
  1326. }
  1327. /*
  1328. * Drain all pending buffers
  1329. * NB: must be called with txq lock held
  1330. */
  1331. static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
  1332. struct ath_txq *txq)
  1333. {
  1334. struct ath_atx_ac *ac, *ac_tmp;
  1335. struct ath_atx_tid *tid, *tid_tmp;
  1336. list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
  1337. list_del(&ac->list);
  1338. ac->sched = false;
  1339. list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
  1340. list_del(&tid->list);
  1341. tid->sched = false;
  1342. ath_tid_drain(sc, txq, tid);
  1343. }
  1344. }
  1345. }
  1346. static void ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
  1347. struct sk_buff *skb, struct scatterlist *sg,
  1348. struct ath_tx_control *txctl)
  1349. {
  1350. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1351. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1352. struct ath_tx_info_priv *tx_info_priv;
  1353. int hdrlen;
  1354. __le16 fc;
  1355. tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_KERNEL);
  1356. tx_info->rate_driver_data[0] = tx_info_priv;
  1357. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1358. fc = hdr->frame_control;
  1359. ATH_TXBUF_RESET(bf);
  1360. /* Frame type */
  1361. bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
  1362. ieee80211_is_data(fc) ?
  1363. (bf->bf_state.bf_type |= BUF_DATA) :
  1364. (bf->bf_state.bf_type &= ~BUF_DATA);
  1365. ieee80211_is_back_req(fc) ?
  1366. (bf->bf_state.bf_type |= BUF_BAR) :
  1367. (bf->bf_state.bf_type &= ~BUF_BAR);
  1368. ieee80211_is_pspoll(fc) ?
  1369. (bf->bf_state.bf_type |= BUF_PSPOLL) :
  1370. (bf->bf_state.bf_type &= ~BUF_PSPOLL);
  1371. (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
  1372. (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
  1373. (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
  1374. (sc->hw->conf.ht.enabled && !is_pae(skb) &&
  1375. (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
  1376. (bf->bf_state.bf_type |= BUF_HT) :
  1377. (bf->bf_state.bf_type &= ~BUF_HT);
  1378. bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
  1379. /* Crypto */
  1380. bf->bf_keytype = get_hw_crypto_keytype(skb);
  1381. if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
  1382. bf->bf_frmlen += tx_info->control.hw_key->icv_len;
  1383. bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
  1384. } else {
  1385. bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
  1386. }
  1387. /* Assign seqno, tidno */
  1388. if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR))
  1389. assign_aggr_tid_seqno(skb, bf);
  1390. /* DMA setup */
  1391. bf->bf_mpdu = skb;
  1392. bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
  1393. skb->len, PCI_DMA_TODEVICE);
  1394. bf->bf_buf_addr = bf->bf_dmacontext;
  1395. }
  1396. /* FIXME: tx power */
  1397. static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
  1398. struct scatterlist *sg, u32 n_sg,
  1399. struct ath_tx_control *txctl)
  1400. {
  1401. struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
  1402. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1403. struct ath_node *an = NULL;
  1404. struct list_head bf_head;
  1405. struct ath_desc *ds;
  1406. struct ath_atx_tid *tid;
  1407. struct ath_hal *ah = sc->sc_ah;
  1408. int frm_type;
  1409. frm_type = get_hw_packet_type(skb);
  1410. INIT_LIST_HEAD(&bf_head);
  1411. list_add_tail(&bf->list, &bf_head);
  1412. /* setup descriptor */
  1413. ds = bf->bf_desc;
  1414. ds->ds_link = 0;
  1415. ds->ds_data = bf->bf_buf_addr;
  1416. /* Formulate first tx descriptor with tx controls */
  1417. ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
  1418. bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
  1419. ath9k_hw_filltxdesc(ah, ds,
  1420. sg_dma_len(sg), /* segment length */
  1421. true, /* first segment */
  1422. (n_sg == 1) ? true : false, /* last segment */
  1423. ds); /* first descriptor */
  1424. bf->bf_lastfrm = bf;
  1425. spin_lock_bh(&txctl->txq->axq_lock);
  1426. if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
  1427. tx_info->control.sta) {
  1428. an = (struct ath_node *)tx_info->control.sta->drv_priv;
  1429. tid = ATH_AN_2_TID(an, bf->bf_tidno);
  1430. if (ath_aggr_query(sc, an, bf->bf_tidno)) {
  1431. /*
  1432. * Try aggregation if it's a unicast data frame
  1433. * and the destination is HT capable.
  1434. */
  1435. ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
  1436. } else {
  1437. /*
  1438. * Send this frame as regular when ADDBA
  1439. * exchange is neither complete nor pending.
  1440. */
  1441. ath_tx_send_normal(sc, txctl->txq,
  1442. tid, &bf_head);
  1443. }
  1444. } else {
  1445. bf->bf_lastbf = bf;
  1446. bf->bf_nframes = 1;
  1447. ath_buf_set_rate(sc, bf);
  1448. ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
  1449. }
  1450. spin_unlock_bh(&txctl->txq->axq_lock);
  1451. }
  1452. int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
  1453. struct ath_tx_control *txctl)
  1454. {
  1455. struct ath_buf *bf;
  1456. struct scatterlist sg;
  1457. /* Check if a tx buffer is available */
  1458. bf = ath_tx_get_buffer(sc);
  1459. if (!bf) {
  1460. DPRINTF(sc, ATH_DBG_XMIT, "%s: TX buffers are full\n",
  1461. __func__);
  1462. return -1;
  1463. }
  1464. ath_tx_setup_buffer(sc, bf, skb, &sg, txctl);
  1465. /* Setup S/G */
  1466. memset(&sg, 0, sizeof(struct scatterlist));
  1467. sg_dma_address(&sg) = bf->bf_dmacontext;
  1468. sg_dma_len(&sg) = skb->len;
  1469. ath_tx_start_dma(sc, bf, &sg, 1, txctl);
  1470. return 0;
  1471. }
  1472. /* Initialize TX queue and h/w */
  1473. int ath_tx_init(struct ath_softc *sc, int nbufs)
  1474. {
  1475. int error = 0;
  1476. do {
  1477. spin_lock_init(&sc->sc_txbuflock);
  1478. /* Setup tx descriptors */
  1479. error = ath_descdma_setup(sc, &sc->sc_txdma, &sc->sc_txbuf,
  1480. "tx", nbufs, 1);
  1481. if (error != 0) {
  1482. DPRINTF(sc, ATH_DBG_FATAL,
  1483. "%s: failed to allocate tx descriptors: %d\n",
  1484. __func__, error);
  1485. break;
  1486. }
  1487. /* XXX allocate beacon state together with vap */
  1488. error = ath_descdma_setup(sc, &sc->sc_bdma, &sc->sc_bbuf,
  1489. "beacon", ATH_BCBUF, 1);
  1490. if (error != 0) {
  1491. DPRINTF(sc, ATH_DBG_FATAL,
  1492. "%s: failed to allocate "
  1493. "beacon descripotrs: %d\n",
  1494. __func__, error);
  1495. break;
  1496. }
  1497. } while (0);
  1498. if (error != 0)
  1499. ath_tx_cleanup(sc);
  1500. return error;
  1501. }
  1502. /* Reclaim all tx queue resources */
  1503. int ath_tx_cleanup(struct ath_softc *sc)
  1504. {
  1505. /* cleanup beacon descriptors */
  1506. if (sc->sc_bdma.dd_desc_len != 0)
  1507. ath_descdma_cleanup(sc, &sc->sc_bdma, &sc->sc_bbuf);
  1508. /* cleanup tx descriptors */
  1509. if (sc->sc_txdma.dd_desc_len != 0)
  1510. ath_descdma_cleanup(sc, &sc->sc_txdma, &sc->sc_txbuf);
  1511. return 0;
  1512. }
  1513. /* Setup a h/w transmit queue */
  1514. struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
  1515. {
  1516. struct ath_hal *ah = sc->sc_ah;
  1517. struct ath9k_tx_queue_info qi;
  1518. int qnum;
  1519. memset(&qi, 0, sizeof(qi));
  1520. qi.tqi_subtype = subtype;
  1521. qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
  1522. qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  1523. qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
  1524. qi.tqi_physCompBuf = 0;
  1525. /*
  1526. * Enable interrupts only for EOL and DESC conditions.
  1527. * We mark tx descriptors to receive a DESC interrupt
  1528. * when a tx queue gets deep; otherwise waiting for the
  1529. * EOL to reap descriptors. Note that this is done to
  1530. * reduce interrupt load and this only defers reaping
  1531. * descriptors, never transmitting frames. Aside from
  1532. * reducing interrupts this also permits more concurrency.
  1533. * The only potential downside is if the tx queue backs
  1534. * up in which case the top half of the kernel may backup
  1535. * due to a lack of tx descriptors.
  1536. *
  1537. * The UAPSD queue is an exception, since we take a desc-
  1538. * based intr on the EOSP frames.
  1539. */
  1540. if (qtype == ATH9K_TX_QUEUE_UAPSD)
  1541. qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
  1542. else
  1543. qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
  1544. TXQ_FLAG_TXDESCINT_ENABLE;
  1545. qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
  1546. if (qnum == -1) {
  1547. /*
  1548. * NB: don't print a message, this happens
  1549. * normally on parts with too few tx queues
  1550. */
  1551. return NULL;
  1552. }
  1553. if (qnum >= ARRAY_SIZE(sc->sc_txq)) {
  1554. DPRINTF(sc, ATH_DBG_FATAL,
  1555. "%s: hal qnum %u out of range, max %u!\n",
  1556. __func__, qnum, (unsigned int)ARRAY_SIZE(sc->sc_txq));
  1557. ath9k_hw_releasetxqueue(ah, qnum);
  1558. return NULL;
  1559. }
  1560. if (!ATH_TXQ_SETUP(sc, qnum)) {
  1561. struct ath_txq *txq = &sc->sc_txq[qnum];
  1562. txq->axq_qnum = qnum;
  1563. txq->axq_link = NULL;
  1564. INIT_LIST_HEAD(&txq->axq_q);
  1565. INIT_LIST_HEAD(&txq->axq_acq);
  1566. spin_lock_init(&txq->axq_lock);
  1567. txq->axq_depth = 0;
  1568. txq->axq_aggr_depth = 0;
  1569. txq->axq_totalqueued = 0;
  1570. txq->axq_linkbuf = NULL;
  1571. sc->sc_txqsetup |= 1<<qnum;
  1572. }
  1573. return &sc->sc_txq[qnum];
  1574. }
  1575. /* Reclaim resources for a setup queue */
  1576. void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
  1577. {
  1578. ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
  1579. sc->sc_txqsetup &= ~(1<<txq->axq_qnum);
  1580. }
  1581. /*
  1582. * Setup a hardware data transmit queue for the specified
  1583. * access control. The hal may not support all requested
  1584. * queues in which case it will return a reference to a
  1585. * previously setup queue. We record the mapping from ac's
  1586. * to h/w queues for use by ath_tx_start and also track
  1587. * the set of h/w queues being used to optimize work in the
  1588. * transmit interrupt handler and related routines.
  1589. */
  1590. int ath_tx_setup(struct ath_softc *sc, int haltype)
  1591. {
  1592. struct ath_txq *txq;
  1593. if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
  1594. DPRINTF(sc, ATH_DBG_FATAL,
  1595. "%s: HAL AC %u out of range, max %zu!\n",
  1596. __func__, haltype, ARRAY_SIZE(sc->sc_haltype2q));
  1597. return 0;
  1598. }
  1599. txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
  1600. if (txq != NULL) {
  1601. sc->sc_haltype2q[haltype] = txq->axq_qnum;
  1602. return 1;
  1603. } else
  1604. return 0;
  1605. }
  1606. int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
  1607. {
  1608. int qnum;
  1609. switch (qtype) {
  1610. case ATH9K_TX_QUEUE_DATA:
  1611. if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
  1612. DPRINTF(sc, ATH_DBG_FATAL,
  1613. "%s: HAL AC %u out of range, max %zu!\n",
  1614. __func__,
  1615. haltype, ARRAY_SIZE(sc->sc_haltype2q));
  1616. return -1;
  1617. }
  1618. qnum = sc->sc_haltype2q[haltype];
  1619. break;
  1620. case ATH9K_TX_QUEUE_BEACON:
  1621. qnum = sc->sc_bhalq;
  1622. break;
  1623. case ATH9K_TX_QUEUE_CAB:
  1624. qnum = sc->sc_cabq->axq_qnum;
  1625. break;
  1626. default:
  1627. qnum = -1;
  1628. }
  1629. return qnum;
  1630. }
  1631. /* Get a transmit queue, if available */
  1632. struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
  1633. {
  1634. struct ath_txq *txq = NULL;
  1635. int qnum;
  1636. qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
  1637. txq = &sc->sc_txq[qnum];
  1638. spin_lock_bh(&txq->axq_lock);
  1639. /* Try to avoid running out of descriptors */
  1640. if (txq->axq_depth >= (ATH_TXBUF - 20)) {
  1641. DPRINTF(sc, ATH_DBG_FATAL,
  1642. "%s: TX queue: %d is full, depth: %d\n",
  1643. __func__, qnum, txq->axq_depth);
  1644. ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
  1645. txq->stopped = 1;
  1646. spin_unlock_bh(&txq->axq_lock);
  1647. return NULL;
  1648. }
  1649. spin_unlock_bh(&txq->axq_lock);
  1650. return txq;
  1651. }
  1652. /* Update parameters for a transmit queue */
  1653. int ath_txq_update(struct ath_softc *sc, int qnum,
  1654. struct ath9k_tx_queue_info *qinfo)
  1655. {
  1656. struct ath_hal *ah = sc->sc_ah;
  1657. int error = 0;
  1658. struct ath9k_tx_queue_info qi;
  1659. if (qnum == sc->sc_bhalq) {
  1660. /*
  1661. * XXX: for beacon queue, we just save the parameter.
  1662. * It will be picked up by ath_beaconq_config when
  1663. * it's necessary.
  1664. */
  1665. sc->sc_beacon_qi = *qinfo;
  1666. return 0;
  1667. }
  1668. ASSERT(sc->sc_txq[qnum].axq_qnum == qnum);
  1669. ath9k_hw_get_txq_props(ah, qnum, &qi);
  1670. qi.tqi_aifs = qinfo->tqi_aifs;
  1671. qi.tqi_cwmin = qinfo->tqi_cwmin;
  1672. qi.tqi_cwmax = qinfo->tqi_cwmax;
  1673. qi.tqi_burstTime = qinfo->tqi_burstTime;
  1674. qi.tqi_readyTime = qinfo->tqi_readyTime;
  1675. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  1676. DPRINTF(sc, ATH_DBG_FATAL,
  1677. "%s: unable to update hardware queue %u!\n",
  1678. __func__, qnum);
  1679. error = -EIO;
  1680. } else {
  1681. ath9k_hw_resettxqueue(ah, qnum); /* push to h/w */
  1682. }
  1683. return error;
  1684. }
  1685. int ath_cabq_update(struct ath_softc *sc)
  1686. {
  1687. struct ath9k_tx_queue_info qi;
  1688. int qnum = sc->sc_cabq->axq_qnum;
  1689. struct ath_beacon_config conf;
  1690. ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
  1691. /*
  1692. * Ensure the readytime % is within the bounds.
  1693. */
  1694. if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
  1695. sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
  1696. else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
  1697. sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
  1698. ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf);
  1699. qi.tqi_readyTime =
  1700. (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100;
  1701. ath_txq_update(sc, qnum, &qi);
  1702. return 0;
  1703. }
  1704. /* Deferred processing of transmit interrupt */
  1705. void ath_tx_tasklet(struct ath_softc *sc)
  1706. {
  1707. int i;
  1708. u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
  1709. ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
  1710. /*
  1711. * Process each active queue.
  1712. */
  1713. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1714. if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
  1715. ath_tx_processq(sc, &sc->sc_txq[i]);
  1716. }
  1717. }
  1718. void ath_tx_draintxq(struct ath_softc *sc,
  1719. struct ath_txq *txq, bool retry_tx)
  1720. {
  1721. struct ath_buf *bf, *lastbf;
  1722. struct list_head bf_head;
  1723. INIT_LIST_HEAD(&bf_head);
  1724. /*
  1725. * NB: this assumes output has been stopped and
  1726. * we do not need to block ath_tx_tasklet
  1727. */
  1728. for (;;) {
  1729. spin_lock_bh(&txq->axq_lock);
  1730. if (list_empty(&txq->axq_q)) {
  1731. txq->axq_link = NULL;
  1732. txq->axq_linkbuf = NULL;
  1733. spin_unlock_bh(&txq->axq_lock);
  1734. break;
  1735. }
  1736. bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
  1737. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  1738. list_del(&bf->list);
  1739. spin_unlock_bh(&txq->axq_lock);
  1740. spin_lock_bh(&sc->sc_txbuflock);
  1741. list_add_tail(&bf->list, &sc->sc_txbuf);
  1742. spin_unlock_bh(&sc->sc_txbuflock);
  1743. continue;
  1744. }
  1745. lastbf = bf->bf_lastbf;
  1746. if (!retry_tx)
  1747. lastbf->bf_desc->ds_txstat.ts_flags =
  1748. ATH9K_TX_SW_ABORTED;
  1749. /* remove ath_buf's of the same mpdu from txq */
  1750. list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
  1751. txq->axq_depth--;
  1752. spin_unlock_bh(&txq->axq_lock);
  1753. if (bf_isampdu(bf))
  1754. ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0);
  1755. else
  1756. ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
  1757. }
  1758. /* flush any pending frames if aggregation is enabled */
  1759. if (sc->sc_flags & SC_OP_TXAGGR) {
  1760. if (!retry_tx) {
  1761. spin_lock_bh(&txq->axq_lock);
  1762. ath_txq_drain_pending_buffers(sc, txq);
  1763. spin_unlock_bh(&txq->axq_lock);
  1764. }
  1765. }
  1766. }
  1767. /* Drain the transmit queues and reclaim resources */
  1768. void ath_draintxq(struct ath_softc *sc, bool retry_tx)
  1769. {
  1770. /* stop beacon queue. The beacon will be freed when
  1771. * we go to INIT state */
  1772. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1773. (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
  1774. DPRINTF(sc, ATH_DBG_XMIT, "%s: beacon queue %x\n", __func__,
  1775. ath9k_hw_gettxbuf(sc->sc_ah, sc->sc_bhalq));
  1776. }
  1777. ath_drain_txdataq(sc, retry_tx);
  1778. }
  1779. u32 ath_txq_depth(struct ath_softc *sc, int qnum)
  1780. {
  1781. return sc->sc_txq[qnum].axq_depth;
  1782. }
  1783. u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum)
  1784. {
  1785. return sc->sc_txq[qnum].axq_aggr_depth;
  1786. }
  1787. bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
  1788. {
  1789. struct ath_atx_tid *txtid;
  1790. if (!(sc->sc_flags & SC_OP_TXAGGR))
  1791. return false;
  1792. txtid = ATH_AN_2_TID(an, tidno);
  1793. if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
  1794. if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
  1795. (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
  1796. txtid->addba_exchangeattempts++;
  1797. return true;
  1798. }
  1799. }
  1800. return false;
  1801. }
  1802. /* Start TX aggregation */
  1803. int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
  1804. u16 tid, u16 *ssn)
  1805. {
  1806. struct ath_atx_tid *txtid;
  1807. struct ath_node *an;
  1808. an = (struct ath_node *)sta->drv_priv;
  1809. if (sc->sc_flags & SC_OP_TXAGGR) {
  1810. txtid = ATH_AN_2_TID(an, tid);
  1811. txtid->state |= AGGR_ADDBA_PROGRESS;
  1812. ath_tx_pause_tid(sc, txtid);
  1813. }
  1814. return 0;
  1815. }
  1816. /* Stop tx aggregation */
  1817. int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  1818. {
  1819. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  1820. ath_tx_aggr_teardown(sc, an, tid);
  1821. return 0;
  1822. }
  1823. /* Resume tx aggregation */
  1824. void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
  1825. {
  1826. struct ath_atx_tid *txtid;
  1827. struct ath_node *an;
  1828. an = (struct ath_node *)sta->drv_priv;
  1829. if (sc->sc_flags & SC_OP_TXAGGR) {
  1830. txtid = ATH_AN_2_TID(an, tid);
  1831. txtid->baw_size =
  1832. IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
  1833. txtid->state |= AGGR_ADDBA_COMPLETE;
  1834. txtid->state &= ~AGGR_ADDBA_PROGRESS;
  1835. ath_tx_resume_tid(sc, txtid);
  1836. }
  1837. }
  1838. /*
  1839. * Performs transmit side cleanup when TID changes from aggregated to
  1840. * unaggregated.
  1841. * - Pause the TID and mark cleanup in progress
  1842. * - Discard all retry frames from the s/w queue.
  1843. */
  1844. void ath_tx_aggr_teardown(struct ath_softc *sc, struct ath_node *an, u8 tid)
  1845. {
  1846. struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
  1847. struct ath_txq *txq = &sc->sc_txq[txtid->ac->qnum];
  1848. struct ath_buf *bf;
  1849. struct list_head bf_head;
  1850. INIT_LIST_HEAD(&bf_head);
  1851. DPRINTF(sc, ATH_DBG_AGGR, "%s: teardown TX aggregation\n", __func__);
  1852. if (txtid->state & AGGR_CLEANUP) /* cleanup is in progress */
  1853. return;
  1854. if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
  1855. txtid->addba_exchangeattempts = 0;
  1856. return;
  1857. }
  1858. /* TID must be paused first */
  1859. ath_tx_pause_tid(sc, txtid);
  1860. /* drop all software retried frames and mark this TID */
  1861. spin_lock_bh(&txq->axq_lock);
  1862. while (!list_empty(&txtid->buf_q)) {
  1863. bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
  1864. if (!bf_isretried(bf)) {
  1865. /*
  1866. * NB: it's based on the assumption that
  1867. * software retried frame will always stay
  1868. * at the head of software queue.
  1869. */
  1870. break;
  1871. }
  1872. list_cut_position(&bf_head,
  1873. &txtid->buf_q, &bf->bf_lastfrm->list);
  1874. ath_tx_update_baw(sc, txtid, bf->bf_seqno);
  1875. /* complete this sub-frame */
  1876. ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
  1877. }
  1878. if (txtid->baw_head != txtid->baw_tail) {
  1879. spin_unlock_bh(&txq->axq_lock);
  1880. txtid->state |= AGGR_CLEANUP;
  1881. } else {
  1882. txtid->state &= ~AGGR_ADDBA_COMPLETE;
  1883. txtid->addba_exchangeattempts = 0;
  1884. spin_unlock_bh(&txq->axq_lock);
  1885. ath_tx_flush_tid(sc, txtid);
  1886. }
  1887. }
  1888. /*
  1889. * Tx scheduling logic
  1890. * NB: must be called with txq lock held
  1891. */
  1892. void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
  1893. {
  1894. struct ath_atx_ac *ac;
  1895. struct ath_atx_tid *tid;
  1896. /* nothing to schedule */
  1897. if (list_empty(&txq->axq_acq))
  1898. return;
  1899. /*
  1900. * get the first node/ac pair on the queue
  1901. */
  1902. ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
  1903. list_del(&ac->list);
  1904. ac->sched = false;
  1905. /*
  1906. * process a single tid per destination
  1907. */
  1908. do {
  1909. /* nothing to schedule */
  1910. if (list_empty(&ac->tid_q))
  1911. return;
  1912. tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
  1913. list_del(&tid->list);
  1914. tid->sched = false;
  1915. if (tid->paused) /* check next tid to keep h/w busy */
  1916. continue;
  1917. if ((txq->axq_depth % 2) == 0)
  1918. ath_tx_sched_aggr(sc, txq, tid);
  1919. /*
  1920. * add tid to round-robin queue if more frames
  1921. * are pending for the tid
  1922. */
  1923. if (!list_empty(&tid->buf_q))
  1924. ath_tx_queue_tid(txq, tid);
  1925. /* only schedule one TID at a time */
  1926. break;
  1927. } while (!list_empty(&ac->tid_q));
  1928. /*
  1929. * schedule AC if more TIDs need processing
  1930. */
  1931. if (!list_empty(&ac->tid_q)) {
  1932. /*
  1933. * add dest ac to txq if not already added
  1934. */
  1935. if (!ac->sched) {
  1936. ac->sched = true;
  1937. list_add_tail(&ac->list, &txq->axq_acq);
  1938. }
  1939. }
  1940. }
  1941. /* Initialize per-node transmit state */
  1942. void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
  1943. {
  1944. struct ath_atx_tid *tid;
  1945. struct ath_atx_ac *ac;
  1946. int tidno, acno;
  1947. /*
  1948. * Init per tid tx state
  1949. */
  1950. for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno];
  1951. tidno < WME_NUM_TID;
  1952. tidno++, tid++) {
  1953. tid->an = an;
  1954. tid->tidno = tidno;
  1955. tid->seq_start = tid->seq_next = 0;
  1956. tid->baw_size = WME_MAX_BA;
  1957. tid->baw_head = tid->baw_tail = 0;
  1958. tid->sched = false;
  1959. tid->paused = false;
  1960. tid->state &= ~AGGR_CLEANUP;
  1961. INIT_LIST_HEAD(&tid->buf_q);
  1962. acno = TID_TO_WME_AC(tidno);
  1963. tid->ac = &an->an_aggr.tx.ac[acno];
  1964. /* ADDBA state */
  1965. tid->state &= ~AGGR_ADDBA_COMPLETE;
  1966. tid->state &= ~AGGR_ADDBA_PROGRESS;
  1967. tid->addba_exchangeattempts = 0;
  1968. }
  1969. /*
  1970. * Init per ac tx state
  1971. */
  1972. for (acno = 0, ac = &an->an_aggr.tx.ac[acno];
  1973. acno < WME_NUM_AC; acno++, ac++) {
  1974. ac->sched = false;
  1975. INIT_LIST_HEAD(&ac->tid_q);
  1976. switch (acno) {
  1977. case WME_AC_BE:
  1978. ac->qnum = ath_tx_get_qnum(sc,
  1979. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
  1980. break;
  1981. case WME_AC_BK:
  1982. ac->qnum = ath_tx_get_qnum(sc,
  1983. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
  1984. break;
  1985. case WME_AC_VI:
  1986. ac->qnum = ath_tx_get_qnum(sc,
  1987. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
  1988. break;
  1989. case WME_AC_VO:
  1990. ac->qnum = ath_tx_get_qnum(sc,
  1991. ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
  1992. break;
  1993. }
  1994. }
  1995. }
  1996. /* Cleanupthe pending buffers for the node. */
  1997. void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
  1998. {
  1999. int i;
  2000. struct ath_atx_ac *ac, *ac_tmp;
  2001. struct ath_atx_tid *tid, *tid_tmp;
  2002. struct ath_txq *txq;
  2003. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  2004. if (ATH_TXQ_SETUP(sc, i)) {
  2005. txq = &sc->sc_txq[i];
  2006. spin_lock(&txq->axq_lock);
  2007. list_for_each_entry_safe(ac,
  2008. ac_tmp, &txq->axq_acq, list) {
  2009. tid = list_first_entry(&ac->tid_q,
  2010. struct ath_atx_tid, list);
  2011. if (tid && tid->an != an)
  2012. continue;
  2013. list_del(&ac->list);
  2014. ac->sched = false;
  2015. list_for_each_entry_safe(tid,
  2016. tid_tmp, &ac->tid_q, list) {
  2017. list_del(&tid->list);
  2018. tid->sched = false;
  2019. ath_tid_drain(sc, txq, tid);
  2020. tid->state &= ~AGGR_ADDBA_COMPLETE;
  2021. tid->addba_exchangeattempts = 0;
  2022. tid->state &= ~AGGR_CLEANUP;
  2023. }
  2024. }
  2025. spin_unlock(&txq->axq_lock);
  2026. }
  2027. }
  2028. }
  2029. void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
  2030. {
  2031. int hdrlen, padsize;
  2032. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2033. struct ath_tx_control txctl;
  2034. memset(&txctl, 0, sizeof(struct ath_tx_control));
  2035. /*
  2036. * As a temporary workaround, assign seq# here; this will likely need
  2037. * to be cleaned up to work better with Beacon transmission and virtual
  2038. * BSSes.
  2039. */
  2040. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  2041. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  2042. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  2043. sc->seq_no += 0x10;
  2044. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  2045. hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
  2046. }
  2047. /* Add the padding after the header if this is not already done */
  2048. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  2049. if (hdrlen & 3) {
  2050. padsize = hdrlen % 4;
  2051. if (skb_headroom(skb) < padsize) {
  2052. DPRINTF(sc, ATH_DBG_XMIT, "%s: TX CABQ padding "
  2053. "failed\n", __func__);
  2054. dev_kfree_skb_any(skb);
  2055. return;
  2056. }
  2057. skb_push(skb, padsize);
  2058. memmove(skb->data, skb->data + padsize, hdrlen);
  2059. }
  2060. txctl.txq = sc->sc_cabq;
  2061. DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting CABQ packet, skb: %p\n",
  2062. __func__,
  2063. skb);
  2064. if (ath_tx_start(sc, skb, &txctl) != 0) {
  2065. DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
  2066. goto exit;
  2067. }
  2068. return;
  2069. exit:
  2070. dev_kfree_skb_any(skb);
  2071. }