xmit.c 62 KB

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