ampdu.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  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 ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <net/mac80211.h>
  17. #include "rate.h"
  18. #include "scb.h"
  19. #include "phy/phy_hal.h"
  20. #include "antsel.h"
  21. #include "main.h"
  22. #include "ampdu.h"
  23. #include "debug.h"
  24. #include "brcms_trace_events.h"
  25. /* max number of mpdus in an ampdu */
  26. #define AMPDU_MAX_MPDU 32
  27. /* max number of mpdus in an ampdu to a legacy */
  28. #define AMPDU_NUM_MPDU_LEGACY 16
  29. /* max Tx ba window size (in pdu) */
  30. #define AMPDU_TX_BA_MAX_WSIZE 64
  31. /* default Tx ba window size (in pdu) */
  32. #define AMPDU_TX_BA_DEF_WSIZE 64
  33. /* default Rx ba window size (in pdu) */
  34. #define AMPDU_RX_BA_DEF_WSIZE 64
  35. /* max Rx ba window size (in pdu) */
  36. #define AMPDU_RX_BA_MAX_WSIZE 64
  37. /* max dur of tx ampdu (in msec) */
  38. #define AMPDU_MAX_DUR 5
  39. /* default tx retry limit */
  40. #define AMPDU_DEF_RETRY_LIMIT 5
  41. /* default tx retry limit at reg rate */
  42. #define AMPDU_DEF_RR_RETRY_LIMIT 2
  43. /* default ffpld reserved bytes */
  44. #define AMPDU_DEF_FFPLD_RSVD 2048
  45. /* # of inis to be freed on detach */
  46. #define AMPDU_INI_FREE 10
  47. /* max # of mpdus released at a time */
  48. #define AMPDU_SCB_MAX_RELEASE 20
  49. #define NUM_FFPLD_FIFO 4 /* number of fifo concerned by pre-loading */
  50. #define FFPLD_TX_MAX_UNFL 200 /* default value of the average number of ampdu
  51. * without underflows
  52. */
  53. #define FFPLD_MPDU_SIZE 1800 /* estimate of maximum mpdu size */
  54. #define FFPLD_MAX_MCS 23 /* we don't deal with mcs 32 */
  55. #define FFPLD_PLD_INCR 1000 /* increments in bytes */
  56. #define FFPLD_MAX_AMPDU_CNT 5000 /* maximum number of ampdu we
  57. * accumulate between resets.
  58. */
  59. #define AMPDU_DELIMITER_LEN 4
  60. /* max allowed number of mpdus in an ampdu (2 streams) */
  61. #define AMPDU_NUM_MPDU 16
  62. #define TX_SEQ_TO_INDEX(seq) ((seq) % AMPDU_TX_BA_MAX_WSIZE)
  63. /* max possible overhead per mpdu in the ampdu; 3 is for roundup if needed */
  64. #define AMPDU_MAX_MPDU_OVERHEAD (FCS_LEN + DOT11_ICV_AES_LEN +\
  65. AMPDU_DELIMITER_LEN + 3\
  66. + DOT11_A4_HDR_LEN + DOT11_QOS_LEN + DOT11_IV_MAX_LEN)
  67. /* modulo add/sub, bound = 2^k */
  68. #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
  69. #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
  70. /* structure to hold tx fifo information and pre-loading state
  71. * counters specific to tx underflows of ampdus
  72. * some counters might be redundant with the ones in wlc or ampdu structures.
  73. * This allows to maintain a specific state independently of
  74. * how often and/or when the wlc counters are updated.
  75. *
  76. * ampdu_pld_size: number of bytes to be pre-loaded
  77. * mcs2ampdu_table: per-mcs max # of mpdus in an ampdu
  78. * prev_txfunfl: num of underflows last read from the HW macstats counter
  79. * accum_txfunfl: num of underflows since we modified pld params
  80. * accum_txampdu: num of tx ampdu since we modified pld params
  81. * prev_txampdu: previous reading of tx ampdu
  82. * dmaxferrate: estimated dma avg xfer rate in kbits/sec
  83. */
  84. struct brcms_fifo_info {
  85. u16 ampdu_pld_size;
  86. u8 mcs2ampdu_table[FFPLD_MAX_MCS + 1];
  87. u16 prev_txfunfl;
  88. u32 accum_txfunfl;
  89. u32 accum_txampdu;
  90. u32 prev_txampdu;
  91. u32 dmaxferrate;
  92. };
  93. /* AMPDU module specific state
  94. *
  95. * wlc: pointer to main wlc structure
  96. * scb_handle: scb cubby handle to retrieve data from scb
  97. * ini_enable: per-tid initiator enable/disable of ampdu
  98. * ba_tx_wsize: Tx ba window size (in pdu)
  99. * ba_rx_wsize: Rx ba window size (in pdu)
  100. * retry_limit: mpdu transmit retry limit
  101. * rr_retry_limit: mpdu transmit retry limit at regular rate
  102. * retry_limit_tid: per-tid mpdu transmit retry limit
  103. * rr_retry_limit_tid: per-tid mpdu transmit retry limit at regular rate
  104. * mpdu_density: min mpdu spacing (0-7) ==> 2^(x-1)/8 usec
  105. * max_pdu: max pdus allowed in ampdu
  106. * dur: max duration of an ampdu (in msec)
  107. * rx_factor: maximum rx ampdu factor (0-3) ==> 2^(13+x) bytes
  108. * ffpld_rsvd: number of bytes to reserve for preload
  109. * max_txlen: max size of ampdu per mcs, bw and sgi
  110. * mfbr: enable multiple fallback rate
  111. * tx_max_funl: underflows should be kept such that
  112. * (tx_max_funfl*underflows) < tx frames
  113. * fifo_tb: table of fifo infos
  114. */
  115. struct ampdu_info {
  116. struct brcms_c_info *wlc;
  117. int scb_handle;
  118. u8 ini_enable[AMPDU_MAX_SCB_TID];
  119. u8 ba_tx_wsize;
  120. u8 ba_rx_wsize;
  121. u8 retry_limit;
  122. u8 rr_retry_limit;
  123. u8 retry_limit_tid[AMPDU_MAX_SCB_TID];
  124. u8 rr_retry_limit_tid[AMPDU_MAX_SCB_TID];
  125. u8 mpdu_density;
  126. s8 max_pdu;
  127. u8 dur;
  128. u8 rx_factor;
  129. u32 ffpld_rsvd;
  130. u32 max_txlen[MCS_TABLE_SIZE][2][2];
  131. bool mfbr;
  132. u32 tx_max_funl;
  133. struct brcms_fifo_info fifo_tb[NUM_FFPLD_FIFO];
  134. };
  135. static void brcms_c_scb_ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur)
  136. {
  137. u32 rate, mcs;
  138. for (mcs = 0; mcs < MCS_TABLE_SIZE; mcs++) {
  139. /* rate is in Kbps; dur is in msec ==> len = (rate * dur) / 8 */
  140. /* 20MHz, No SGI */
  141. rate = mcs_2_rate(mcs, false, false);
  142. ampdu->max_txlen[mcs][0][0] = (rate * dur) >> 3;
  143. /* 40 MHz, No SGI */
  144. rate = mcs_2_rate(mcs, true, false);
  145. ampdu->max_txlen[mcs][1][0] = (rate * dur) >> 3;
  146. /* 20MHz, SGI */
  147. rate = mcs_2_rate(mcs, false, true);
  148. ampdu->max_txlen[mcs][0][1] = (rate * dur) >> 3;
  149. /* 40 MHz, SGI */
  150. rate = mcs_2_rate(mcs, true, true);
  151. ampdu->max_txlen[mcs][1][1] = (rate * dur) >> 3;
  152. }
  153. }
  154. static bool brcms_c_ampdu_cap(struct ampdu_info *ampdu)
  155. {
  156. if (BRCMS_PHY_11N_CAP(ampdu->wlc->band))
  157. return true;
  158. else
  159. return false;
  160. }
  161. static int brcms_c_ampdu_set(struct ampdu_info *ampdu, bool on)
  162. {
  163. struct brcms_c_info *wlc = ampdu->wlc;
  164. struct bcma_device *core = wlc->hw->d11core;
  165. wlc->pub->_ampdu = false;
  166. if (on) {
  167. if (!(wlc->pub->_n_enab & SUPPORT_11N)) {
  168. brcms_err(core, "wl%d: driver not nmode enabled\n",
  169. wlc->pub->unit);
  170. return -ENOTSUPP;
  171. }
  172. if (!brcms_c_ampdu_cap(ampdu)) {
  173. brcms_err(core, "wl%d: device not ampdu capable\n",
  174. wlc->pub->unit);
  175. return -ENOTSUPP;
  176. }
  177. wlc->pub->_ampdu = on;
  178. }
  179. return 0;
  180. }
  181. static void brcms_c_ffpld_init(struct ampdu_info *ampdu)
  182. {
  183. int i, j;
  184. struct brcms_fifo_info *fifo;
  185. for (j = 0; j < NUM_FFPLD_FIFO; j++) {
  186. fifo = (ampdu->fifo_tb + j);
  187. fifo->ampdu_pld_size = 0;
  188. for (i = 0; i <= FFPLD_MAX_MCS; i++)
  189. fifo->mcs2ampdu_table[i] = 255;
  190. fifo->dmaxferrate = 0;
  191. fifo->accum_txampdu = 0;
  192. fifo->prev_txfunfl = 0;
  193. fifo->accum_txfunfl = 0;
  194. }
  195. }
  196. struct ampdu_info *brcms_c_ampdu_attach(struct brcms_c_info *wlc)
  197. {
  198. struct ampdu_info *ampdu;
  199. int i;
  200. ampdu = kzalloc(sizeof(*ampdu), GFP_ATOMIC);
  201. if (!ampdu)
  202. return NULL;
  203. ampdu->wlc = wlc;
  204. for (i = 0; i < AMPDU_MAX_SCB_TID; i++)
  205. ampdu->ini_enable[i] = true;
  206. /* Disable ampdu for VO by default */
  207. ampdu->ini_enable[PRIO_8021D_VO] = false;
  208. ampdu->ini_enable[PRIO_8021D_NC] = false;
  209. /* Disable ampdu for BK by default since not enough fifo space */
  210. ampdu->ini_enable[PRIO_8021D_NONE] = false;
  211. ampdu->ini_enable[PRIO_8021D_BK] = false;
  212. ampdu->ba_tx_wsize = AMPDU_TX_BA_DEF_WSIZE;
  213. ampdu->ba_rx_wsize = AMPDU_RX_BA_DEF_WSIZE;
  214. ampdu->mpdu_density = AMPDU_DEF_MPDU_DENSITY;
  215. ampdu->max_pdu = AUTO;
  216. ampdu->dur = AMPDU_MAX_DUR;
  217. ampdu->ffpld_rsvd = AMPDU_DEF_FFPLD_RSVD;
  218. /*
  219. * bump max ampdu rcv size to 64k for all 11n
  220. * devices except 4321A0 and 4321A1
  221. */
  222. if (BRCMS_ISNPHY(wlc->band) && NREV_LT(wlc->band->phyrev, 2))
  223. ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_32K;
  224. else
  225. ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_64K;
  226. ampdu->retry_limit = AMPDU_DEF_RETRY_LIMIT;
  227. ampdu->rr_retry_limit = AMPDU_DEF_RR_RETRY_LIMIT;
  228. for (i = 0; i < AMPDU_MAX_SCB_TID; i++) {
  229. ampdu->retry_limit_tid[i] = ampdu->retry_limit;
  230. ampdu->rr_retry_limit_tid[i] = ampdu->rr_retry_limit;
  231. }
  232. brcms_c_scb_ampdu_update_max_txlen(ampdu, ampdu->dur);
  233. ampdu->mfbr = false;
  234. /* try to set ampdu to the default value */
  235. brcms_c_ampdu_set(ampdu, wlc->pub->_ampdu);
  236. ampdu->tx_max_funl = FFPLD_TX_MAX_UNFL;
  237. brcms_c_ffpld_init(ampdu);
  238. return ampdu;
  239. }
  240. void brcms_c_ampdu_detach(struct ampdu_info *ampdu)
  241. {
  242. kfree(ampdu);
  243. }
  244. static void brcms_c_scb_ampdu_update_config(struct ampdu_info *ampdu,
  245. struct scb *scb)
  246. {
  247. struct scb_ampdu *scb_ampdu = &scb->scb_ampdu;
  248. int i;
  249. scb_ampdu->max_pdu = AMPDU_NUM_MPDU;
  250. /* go back to legacy size if some preloading is occurring */
  251. for (i = 0; i < NUM_FFPLD_FIFO; i++) {
  252. if (ampdu->fifo_tb[i].ampdu_pld_size > FFPLD_PLD_INCR)
  253. scb_ampdu->max_pdu = AMPDU_NUM_MPDU_LEGACY;
  254. }
  255. /* apply user override */
  256. if (ampdu->max_pdu != AUTO)
  257. scb_ampdu->max_pdu = (u8) ampdu->max_pdu;
  258. scb_ampdu->release = min_t(u8, scb_ampdu->max_pdu,
  259. AMPDU_SCB_MAX_RELEASE);
  260. if (scb_ampdu->max_rx_ampdu_bytes)
  261. scb_ampdu->release = min_t(u8, scb_ampdu->release,
  262. scb_ampdu->max_rx_ampdu_bytes / 1600);
  263. scb_ampdu->release = min(scb_ampdu->release,
  264. ampdu->fifo_tb[TX_AC_BE_FIFO].
  265. mcs2ampdu_table[FFPLD_MAX_MCS]);
  266. }
  267. static void brcms_c_scb_ampdu_update_config_all(struct ampdu_info *ampdu)
  268. {
  269. brcms_c_scb_ampdu_update_config(ampdu, &ampdu->wlc->pri_scb);
  270. }
  271. static void brcms_c_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f)
  272. {
  273. int i;
  274. u32 phy_rate, dma_rate, tmp;
  275. u8 max_mpdu;
  276. struct brcms_fifo_info *fifo = (ampdu->fifo_tb + f);
  277. /* recompute the dma rate */
  278. /* note : we divide/multiply by 100 to avoid integer overflows */
  279. max_mpdu = min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS],
  280. AMPDU_NUM_MPDU_LEGACY);
  281. phy_rate = mcs_2_rate(FFPLD_MAX_MCS, true, false);
  282. dma_rate =
  283. (((phy_rate / 100) *
  284. (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
  285. / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
  286. fifo->dmaxferrate = dma_rate;
  287. /* fill up the mcs2ampdu table; do not recalc the last mcs */
  288. dma_rate = dma_rate >> 7;
  289. for (i = 0; i < FFPLD_MAX_MCS; i++) {
  290. /* shifting to keep it within integer range */
  291. phy_rate = mcs_2_rate(i, true, false) >> 7;
  292. if (phy_rate > dma_rate) {
  293. tmp = ((fifo->ampdu_pld_size * phy_rate) /
  294. ((phy_rate - dma_rate) * FFPLD_MPDU_SIZE)) + 1;
  295. tmp = min_t(u32, tmp, 255);
  296. fifo->mcs2ampdu_table[i] = (u8) tmp;
  297. }
  298. }
  299. }
  300. /* evaluate the dma transfer rate using the tx underflows as feedback.
  301. * If necessary, increase tx fifo preloading. If not enough,
  302. * decrease maximum ampdu size for each mcs till underflows stop
  303. * Return 1 if pre-loading not active, -1 if not an underflow event,
  304. * 0 if pre-loading module took care of the event.
  305. */
  306. static int brcms_c_ffpld_check_txfunfl(struct brcms_c_info *wlc, int fid)
  307. {
  308. struct ampdu_info *ampdu = wlc->ampdu;
  309. u32 phy_rate = mcs_2_rate(FFPLD_MAX_MCS, true, false);
  310. u8 max_mpdu;
  311. u16 max_pld_size;
  312. u32 new_txunfl;
  313. struct brcms_fifo_info *fifo = (ampdu->fifo_tb + fid);
  314. uint xmtfifo_sz;
  315. u16 cur_txunfl;
  316. /* return if we got here for a different reason than underflows */
  317. cur_txunfl = brcms_b_read_shm(wlc->hw,
  318. M_UCODE_MACSTAT +
  319. offsetof(struct macstat, txfunfl[fid]));
  320. new_txunfl = (u16) (cur_txunfl - fifo->prev_txfunfl);
  321. if (new_txunfl == 0) {
  322. brcms_dbg_ht(wlc->hw->d11core,
  323. "TX status FRAG set but no tx underflows\n");
  324. return -1;
  325. }
  326. fifo->prev_txfunfl = cur_txunfl;
  327. if (!ampdu->tx_max_funl)
  328. return 1;
  329. /* check if fifo is big enough */
  330. if (brcms_b_xmtfifo_sz_get(wlc->hw, fid, &xmtfifo_sz))
  331. return -1;
  332. if ((TXFIFO_SIZE_UNIT * (u32) xmtfifo_sz) <= ampdu->ffpld_rsvd)
  333. return 1;
  334. max_pld_size = TXFIFO_SIZE_UNIT * xmtfifo_sz - ampdu->ffpld_rsvd;
  335. fifo->accum_txfunfl += new_txunfl;
  336. /* we need to wait for at least 10 underflows */
  337. if (fifo->accum_txfunfl < 10)
  338. return 0;
  339. brcms_dbg_ht(wlc->hw->d11core, "tx_underflows %d\n", fifo->accum_txfunfl);
  340. max_mpdu = min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS],
  341. AMPDU_NUM_MPDU_LEGACY);
  342. /* In case max value max_pdu is already lower than
  343. the fifo depth, there is nothing more we can do.
  344. */
  345. if (fifo->ampdu_pld_size >= max_mpdu * FFPLD_MPDU_SIZE) {
  346. fifo->accum_txfunfl = 0;
  347. return 0;
  348. }
  349. if (fifo->ampdu_pld_size < max_pld_size) {
  350. /* increment by TX_FIFO_PLD_INC bytes */
  351. fifo->ampdu_pld_size += FFPLD_PLD_INCR;
  352. if (fifo->ampdu_pld_size > max_pld_size)
  353. fifo->ampdu_pld_size = max_pld_size;
  354. /* update scb release size */
  355. brcms_c_scb_ampdu_update_config_all(ampdu);
  356. /*
  357. * compute a new dma xfer rate for max_mpdu @ max mcs.
  358. * This is the minimum dma rate that can achieve no
  359. * underflow condition for the current mpdu size.
  360. *
  361. * note : we divide/multiply by 100 to avoid integer overflows
  362. */
  363. fifo->dmaxferrate =
  364. (((phy_rate / 100) *
  365. (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
  366. / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
  367. brcms_dbg_ht(wlc->hw->d11core,
  368. "DMA estimated transfer rate %d; "
  369. "pre-load size %d\n",
  370. fifo->dmaxferrate, fifo->ampdu_pld_size);
  371. } else {
  372. /* decrease ampdu size */
  373. if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] > 1) {
  374. if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] == 255)
  375. fifo->mcs2ampdu_table[FFPLD_MAX_MCS] =
  376. AMPDU_NUM_MPDU_LEGACY - 1;
  377. else
  378. fifo->mcs2ampdu_table[FFPLD_MAX_MCS] -= 1;
  379. /* recompute the table */
  380. brcms_c_ffpld_calc_mcs2ampdu_table(ampdu, fid);
  381. /* update scb release size */
  382. brcms_c_scb_ampdu_update_config_all(ampdu);
  383. }
  384. }
  385. fifo->accum_txfunfl = 0;
  386. return 0;
  387. }
  388. void
  389. brcms_c_ampdu_tx_operational(struct brcms_c_info *wlc, u8 tid,
  390. uint max_rx_ampdu_bytes) /* from ht_cap in beacon */
  391. {
  392. struct scb_ampdu *scb_ampdu;
  393. struct ampdu_info *ampdu = wlc->ampdu;
  394. struct scb *scb = &wlc->pri_scb;
  395. scb_ampdu = &scb->scb_ampdu;
  396. if (!ampdu->ini_enable[tid]) {
  397. brcms_err(wlc->hw->d11core, "%s: Rejecting tid %d\n",
  398. __func__, tid);
  399. return;
  400. }
  401. scb_ampdu->max_rx_ampdu_bytes = max_rx_ampdu_bytes;
  402. }
  403. void brcms_c_ampdu_reset_session(struct brcms_ampdu_session *session,
  404. struct brcms_c_info *wlc)
  405. {
  406. session->wlc = wlc;
  407. skb_queue_head_init(&session->skb_list);
  408. session->max_ampdu_len = 0; /* determined from first MPDU */
  409. session->max_ampdu_frames = 0; /* determined from first MPDU */
  410. session->ampdu_len = 0;
  411. session->dma_len = 0;
  412. }
  413. /*
  414. * Preps the given packet for AMPDU based on the session data. If the
  415. * frame cannot be accomodated in the current session, -ENOSPC is
  416. * returned.
  417. */
  418. int brcms_c_ampdu_add_frame(struct brcms_ampdu_session *session,
  419. struct sk_buff *p)
  420. {
  421. struct brcms_c_info *wlc = session->wlc;
  422. struct ampdu_info *ampdu = wlc->ampdu;
  423. struct scb *scb = &wlc->pri_scb;
  424. struct scb_ampdu *scb_ampdu = &scb->scb_ampdu;
  425. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(p);
  426. struct ieee80211_tx_rate *txrate = tx_info->status.rates;
  427. struct d11txh *txh = (struct d11txh *)p->data;
  428. unsigned ampdu_frames;
  429. u8 ndelim, tid;
  430. u8 *plcp;
  431. uint len;
  432. u16 mcl;
  433. bool fbr_iscck;
  434. bool rr;
  435. ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
  436. plcp = (u8 *)(txh + 1);
  437. fbr_iscck = !(le16_to_cpu(txh->XtraFrameTypes) & 0x03);
  438. len = fbr_iscck ? BRCMS_GET_CCK_PLCP_LEN(txh->FragPLCPFallback) :
  439. BRCMS_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
  440. len = roundup(len, 4) + (ndelim + 1) * AMPDU_DELIMITER_LEN;
  441. ampdu_frames = skb_queue_len(&session->skb_list);
  442. if (ampdu_frames != 0) {
  443. struct sk_buff *first;
  444. if (ampdu_frames + 1 > session->max_ampdu_frames ||
  445. session->ampdu_len + len > session->max_ampdu_len)
  446. return -ENOSPC;
  447. /*
  448. * We aren't really out of space if the new frame is of
  449. * a different priority, but we want the same behaviour
  450. * so return -ENOSPC anyway.
  451. *
  452. * XXX: The old AMPDU code did this, but is it really
  453. * necessary?
  454. */
  455. first = skb_peek(&session->skb_list);
  456. if (p->priority != first->priority)
  457. return -ENOSPC;
  458. }
  459. /*
  460. * Now that we're sure this frame can be accomodated, update the
  461. * session information.
  462. */
  463. session->ampdu_len += len;
  464. session->dma_len += p->len;
  465. tid = (u8)p->priority;
  466. /* Handle retry limits */
  467. if (txrate[0].count <= ampdu->rr_retry_limit_tid[tid]) {
  468. txrate[0].count++;
  469. rr = true;
  470. } else {
  471. txrate[1].count++;
  472. rr = false;
  473. }
  474. if (ampdu_frames == 0) {
  475. u8 plcp0, plcp3, is40, sgi, mcs;
  476. uint fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
  477. struct brcms_fifo_info *f = &ampdu->fifo_tb[fifo];
  478. if (rr) {
  479. plcp0 = plcp[0];
  480. plcp3 = plcp[3];
  481. } else {
  482. plcp0 = txh->FragPLCPFallback[0];
  483. plcp3 = txh->FragPLCPFallback[3];
  484. }
  485. /* Limit AMPDU size based on MCS */
  486. is40 = (plcp0 & MIMO_PLCP_40MHZ) ? 1 : 0;
  487. sgi = plcp3_issgi(plcp3) ? 1 : 0;
  488. mcs = plcp0 & ~MIMO_PLCP_40MHZ;
  489. session->max_ampdu_len = min(scb_ampdu->max_rx_ampdu_bytes,
  490. ampdu->max_txlen[mcs][is40][sgi]);
  491. session->max_ampdu_frames = scb_ampdu->max_pdu;
  492. if (mcs_2_rate(mcs, true, false) >= f->dmaxferrate) {
  493. session->max_ampdu_frames =
  494. min_t(u16, f->mcs2ampdu_table[mcs],
  495. session->max_ampdu_frames);
  496. }
  497. }
  498. /*
  499. * Treat all frames as "middle" frames of AMPDU here. First and
  500. * last frames must be fixed up after all MPDUs have been prepped.
  501. */
  502. mcl = le16_to_cpu(txh->MacTxControlLow);
  503. mcl &= ~TXC_AMPDU_MASK;
  504. mcl |= (TXC_AMPDU_MIDDLE << TXC_AMPDU_SHIFT);
  505. mcl &= ~(TXC_STARTMSDU | TXC_SENDRTS | TXC_SENDCTS);
  506. txh->MacTxControlLow = cpu_to_le16(mcl);
  507. txh->PreloadSize = 0; /* always default to 0 */
  508. skb_queue_tail(&session->skb_list, p);
  509. return 0;
  510. }
  511. void brcms_c_ampdu_finalize(struct brcms_ampdu_session *session)
  512. {
  513. struct brcms_c_info *wlc = session->wlc;
  514. struct ampdu_info *ampdu = wlc->ampdu;
  515. struct sk_buff *first, *last;
  516. struct d11txh *txh;
  517. struct ieee80211_tx_info *tx_info;
  518. struct ieee80211_tx_rate *txrate;
  519. u8 ndelim;
  520. u8 *plcp;
  521. uint len;
  522. uint fifo;
  523. struct brcms_fifo_info *f;
  524. u16 mcl;
  525. bool fbr;
  526. bool fbr_iscck;
  527. struct ieee80211_rts *rts;
  528. bool use_rts = false, use_cts = false;
  529. u16 dma_len = session->dma_len;
  530. u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
  531. u32 rspec = 0, rspec_fallback = 0;
  532. u32 rts_rspec = 0, rts_rspec_fallback = 0;
  533. u8 plcp0, is40, mcs;
  534. u16 mch;
  535. u8 preamble_type = BRCMS_GF_PREAMBLE;
  536. u8 fbr_preamble_type = BRCMS_GF_PREAMBLE;
  537. u8 rts_preamble_type = BRCMS_LONG_PREAMBLE;
  538. u8 rts_fbr_preamble_type = BRCMS_LONG_PREAMBLE;
  539. if (skb_queue_empty(&session->skb_list))
  540. return;
  541. first = skb_peek(&session->skb_list);
  542. last = skb_peek_tail(&session->skb_list);
  543. /* Need to fix up last MPDU first to adjust AMPDU length */
  544. txh = (struct d11txh *)last->data;
  545. fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
  546. f = &ampdu->fifo_tb[fifo];
  547. mcl = le16_to_cpu(txh->MacTxControlLow);
  548. mcl &= ~TXC_AMPDU_MASK;
  549. mcl |= (TXC_AMPDU_LAST << TXC_AMPDU_SHIFT);
  550. txh->MacTxControlLow = cpu_to_le16(mcl);
  551. /* remove the null delimiter after last mpdu */
  552. ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
  553. txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = 0;
  554. session->ampdu_len -= ndelim * AMPDU_DELIMITER_LEN;
  555. /* remove the pad len from last mpdu */
  556. fbr_iscck = ((le16_to_cpu(txh->XtraFrameTypes) & 0x3) == 0);
  557. len = fbr_iscck ? BRCMS_GET_CCK_PLCP_LEN(txh->FragPLCPFallback) :
  558. BRCMS_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
  559. session->ampdu_len -= roundup(len, 4) - len;
  560. /* Now fix up the first MPDU */
  561. tx_info = IEEE80211_SKB_CB(first);
  562. txrate = tx_info->status.rates;
  563. txh = (struct d11txh *)first->data;
  564. plcp = (u8 *)(txh + 1);
  565. rts = (struct ieee80211_rts *)&txh->rts_frame;
  566. mcl = le16_to_cpu(txh->MacTxControlLow);
  567. /* If only one MPDU leave it marked as last */
  568. if (first != last) {
  569. mcl &= ~TXC_AMPDU_MASK;
  570. mcl |= (TXC_AMPDU_FIRST << TXC_AMPDU_SHIFT);
  571. }
  572. mcl |= TXC_STARTMSDU;
  573. if (ieee80211_is_rts(rts->frame_control)) {
  574. mcl |= TXC_SENDRTS;
  575. use_rts = true;
  576. }
  577. if (ieee80211_is_cts(rts->frame_control)) {
  578. mcl |= TXC_SENDCTS;
  579. use_cts = true;
  580. }
  581. txh->MacTxControlLow = cpu_to_le16(mcl);
  582. fbr = txrate[1].count > 0;
  583. if (!fbr)
  584. plcp0 = plcp[0];
  585. else
  586. plcp0 = txh->FragPLCPFallback[0];
  587. is40 = (plcp0 & MIMO_PLCP_40MHZ) ? 1 : 0;
  588. mcs = plcp0 & ~MIMO_PLCP_40MHZ;
  589. if (is40) {
  590. if (CHSPEC_SB_UPPER(wlc_phy_chanspec_get(wlc->band->pi)))
  591. mimo_ctlchbw = PHY_TXC1_BW_20MHZ_UP;
  592. else
  593. mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
  594. }
  595. /* rebuild the rspec and rspec_fallback */
  596. rspec = RSPEC_MIMORATE;
  597. rspec |= plcp[0] & ~MIMO_PLCP_40MHZ;
  598. if (plcp[0] & MIMO_PLCP_40MHZ)
  599. rspec |= (PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT);
  600. fbr_iscck = !(le16_to_cpu(txh->XtraFrameTypes) & 0x03);
  601. if (fbr_iscck) {
  602. rspec_fallback =
  603. cck_rspec(cck_phy2mac_rate(txh->FragPLCPFallback[0]));
  604. } else {
  605. rspec_fallback = RSPEC_MIMORATE;
  606. rspec_fallback |= txh->FragPLCPFallback[0] & ~MIMO_PLCP_40MHZ;
  607. if (txh->FragPLCPFallback[0] & MIMO_PLCP_40MHZ)
  608. rspec_fallback |= PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT;
  609. }
  610. if (use_rts || use_cts) {
  611. rts_rspec =
  612. brcms_c_rspec_to_rts_rspec(wlc, rspec,
  613. false, mimo_ctlchbw);
  614. rts_rspec_fallback =
  615. brcms_c_rspec_to_rts_rspec(wlc, rspec_fallback,
  616. false, mimo_ctlchbw);
  617. }
  618. BRCMS_SET_MIMO_PLCP_LEN(plcp, session->ampdu_len);
  619. /* mark plcp to indicate ampdu */
  620. BRCMS_SET_MIMO_PLCP_AMPDU(plcp);
  621. /* reset the mixed mode header durations */
  622. if (txh->MModeLen) {
  623. u16 mmodelen = brcms_c_calc_lsig_len(wlc, rspec,
  624. session->ampdu_len);
  625. txh->MModeLen = cpu_to_le16(mmodelen);
  626. preamble_type = BRCMS_MM_PREAMBLE;
  627. }
  628. if (txh->MModeFbrLen) {
  629. u16 mmfbrlen = brcms_c_calc_lsig_len(wlc, rspec_fallback,
  630. session->ampdu_len);
  631. txh->MModeFbrLen = cpu_to_le16(mmfbrlen);
  632. fbr_preamble_type = BRCMS_MM_PREAMBLE;
  633. }
  634. /* set the preload length */
  635. if (mcs_2_rate(mcs, true, false) >= f->dmaxferrate) {
  636. dma_len = min(dma_len, f->ampdu_pld_size);
  637. txh->PreloadSize = cpu_to_le16(dma_len);
  638. } else {
  639. txh->PreloadSize = 0;
  640. }
  641. mch = le16_to_cpu(txh->MacTxControlHigh);
  642. /* update RTS dur fields */
  643. if (use_rts || use_cts) {
  644. u16 durid;
  645. if ((mch & TXC_PREAMBLE_RTS_MAIN_SHORT) ==
  646. TXC_PREAMBLE_RTS_MAIN_SHORT)
  647. rts_preamble_type = BRCMS_SHORT_PREAMBLE;
  648. if ((mch & TXC_PREAMBLE_RTS_FB_SHORT) ==
  649. TXC_PREAMBLE_RTS_FB_SHORT)
  650. rts_fbr_preamble_type = BRCMS_SHORT_PREAMBLE;
  651. durid = brcms_c_compute_rtscts_dur(wlc, use_cts, rts_rspec,
  652. rspec, rts_preamble_type,
  653. preamble_type,
  654. session->ampdu_len, true);
  655. rts->duration = cpu_to_le16(durid);
  656. durid = brcms_c_compute_rtscts_dur(wlc, use_cts,
  657. rts_rspec_fallback,
  658. rspec_fallback,
  659. rts_fbr_preamble_type,
  660. fbr_preamble_type,
  661. session->ampdu_len, true);
  662. txh->RTSDurFallback = cpu_to_le16(durid);
  663. /* set TxFesTimeNormal */
  664. txh->TxFesTimeNormal = rts->duration;
  665. /* set fallback rate version of TxFesTimeNormal */
  666. txh->TxFesTimeFallback = txh->RTSDurFallback;
  667. }
  668. /* set flag and plcp for fallback rate */
  669. if (fbr) {
  670. mch |= TXC_AMPDU_FBR;
  671. txh->MacTxControlHigh = cpu_to_le16(mch);
  672. BRCMS_SET_MIMO_PLCP_AMPDU(plcp);
  673. BRCMS_SET_MIMO_PLCP_AMPDU(txh->FragPLCPFallback);
  674. }
  675. brcms_dbg_ht(wlc->hw->d11core, "wl%d: count %d ampdu_len %d\n",
  676. wlc->pub->unit, skb_queue_len(&session->skb_list),
  677. session->ampdu_len);
  678. }
  679. static void
  680. brcms_c_ampdu_rate_status(struct brcms_c_info *wlc,
  681. struct ieee80211_tx_info *tx_info,
  682. struct tx_status *txs, u8 mcs)
  683. {
  684. struct ieee80211_tx_rate *txrate = tx_info->status.rates;
  685. int i;
  686. /* clear the rest of the rates */
  687. for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
  688. txrate[i].idx = -1;
  689. txrate[i].count = 0;
  690. }
  691. }
  692. static void
  693. brcms_c_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb,
  694. struct sk_buff *p, struct tx_status *txs,
  695. u32 s1, u32 s2)
  696. {
  697. struct scb_ampdu *scb_ampdu;
  698. struct brcms_c_info *wlc = ampdu->wlc;
  699. struct scb_ampdu_tid_ini *ini;
  700. u8 bitmap[8], queue, tid;
  701. struct d11txh *txh;
  702. u8 *plcp;
  703. struct ieee80211_hdr *h;
  704. u16 seq, start_seq = 0, bindex, index, mcl;
  705. u8 mcs = 0;
  706. bool ba_recd = false, ack_recd = false;
  707. u8 tot_mpdu = 0;
  708. uint supr_status;
  709. bool retry = true;
  710. u16 mimoantsel = 0;
  711. u8 retry_limit;
  712. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(p);
  713. #ifdef DEBUG
  714. u8 hole[AMPDU_MAX_MPDU];
  715. memset(hole, 0, sizeof(hole));
  716. #endif
  717. scb_ampdu = &scb->scb_ampdu;
  718. tid = (u8) (p->priority);
  719. ini = &scb_ampdu->ini[tid];
  720. retry_limit = ampdu->retry_limit_tid[tid];
  721. memset(bitmap, 0, sizeof(bitmap));
  722. queue = txs->frameid & TXFID_QUEUE_MASK;
  723. supr_status = txs->status & TX_STATUS_SUPR_MASK;
  724. if (txs->status & TX_STATUS_ACK_RCV) {
  725. WARN_ON(!(txs->status & TX_STATUS_INTERMEDIATE));
  726. start_seq = txs->sequence >> SEQNUM_SHIFT;
  727. bitmap[0] = (txs->status & TX_STATUS_BA_BMAP03_MASK) >>
  728. TX_STATUS_BA_BMAP03_SHIFT;
  729. WARN_ON(s1 & TX_STATUS_INTERMEDIATE);
  730. WARN_ON(!(s1 & TX_STATUS_AMPDU));
  731. bitmap[0] |=
  732. (s1 & TX_STATUS_BA_BMAP47_MASK) <<
  733. TX_STATUS_BA_BMAP47_SHIFT;
  734. bitmap[1] = (s1 >> 8) & 0xff;
  735. bitmap[2] = (s1 >> 16) & 0xff;
  736. bitmap[3] = (s1 >> 24) & 0xff;
  737. bitmap[4] = s2 & 0xff;
  738. bitmap[5] = (s2 >> 8) & 0xff;
  739. bitmap[6] = (s2 >> 16) & 0xff;
  740. bitmap[7] = (s2 >> 24) & 0xff;
  741. ba_recd = true;
  742. } else {
  743. if (supr_status) {
  744. if (supr_status == TX_STATUS_SUPR_BADCH) {
  745. brcms_dbg_ht(wlc->hw->d11core,
  746. "%s: Pkt tx suppressed, illegal channel possibly %d\n",
  747. __func__, CHSPEC_CHANNEL(
  748. wlc->default_bss->chanspec));
  749. } else {
  750. if (supr_status != TX_STATUS_SUPR_FRAG)
  751. brcms_err(wlc->hw->d11core,
  752. "%s: supr_status 0x%x\n",
  753. __func__, supr_status);
  754. }
  755. /* no need to retry for badch; will fail again */
  756. if (supr_status == TX_STATUS_SUPR_BADCH ||
  757. supr_status == TX_STATUS_SUPR_EXPTIME) {
  758. retry = false;
  759. } else if (supr_status == TX_STATUS_SUPR_EXPTIME) {
  760. /* TX underflow:
  761. * try tuning pre-loading or ampdu size
  762. */
  763. } else if (supr_status == TX_STATUS_SUPR_FRAG) {
  764. /*
  765. * if there were underflows, but pre-loading
  766. * is not active, notify rate adaptation.
  767. */
  768. brcms_c_ffpld_check_txfunfl(wlc, queue);
  769. }
  770. } else if (txs->phyerr) {
  771. brcms_dbg_ht(wlc->hw->d11core,
  772. "%s: ampdu tx phy error (0x%x)\n",
  773. __func__, txs->phyerr);
  774. }
  775. }
  776. /* loop through all pkts and retry if not acked */
  777. while (p) {
  778. tx_info = IEEE80211_SKB_CB(p);
  779. txh = (struct d11txh *) p->data;
  780. mcl = le16_to_cpu(txh->MacTxControlLow);
  781. plcp = (u8 *) (txh + 1);
  782. h = (struct ieee80211_hdr *)(plcp + D11_PHY_HDR_LEN);
  783. seq = le16_to_cpu(h->seq_ctrl) >> SEQNUM_SHIFT;
  784. trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh));
  785. if (tot_mpdu == 0) {
  786. mcs = plcp[0] & MIMO_PLCP_MCS_MASK;
  787. mimoantsel = le16_to_cpu(txh->ABI_MimoAntSel);
  788. }
  789. index = TX_SEQ_TO_INDEX(seq);
  790. ack_recd = false;
  791. if (ba_recd) {
  792. int block_acked;
  793. bindex = MODSUB_POW2(seq, start_seq, SEQNUM_MAX);
  794. if (bindex < AMPDU_TX_BA_MAX_WSIZE)
  795. block_acked = isset(bitmap, bindex);
  796. else
  797. block_acked = 0;
  798. brcms_dbg_ht(wlc->hw->d11core,
  799. "tid %d seq %d, start_seq %d, bindex %d set %d, index %d\n",
  800. tid, seq, start_seq, bindex,
  801. block_acked, index);
  802. /* if acked then clear bit and free packet */
  803. if (block_acked) {
  804. ini->txretry[index] = 0;
  805. /*
  806. * ampdu_ack_len:
  807. * number of acked aggregated frames
  808. */
  809. /* ampdu_len: number of aggregated frames */
  810. brcms_c_ampdu_rate_status(wlc, tx_info, txs,
  811. mcs);
  812. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  813. tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
  814. tx_info->status.ampdu_ack_len =
  815. tx_info->status.ampdu_len = 1;
  816. skb_pull(p, D11_PHY_HDR_LEN);
  817. skb_pull(p, D11_TXH_LEN);
  818. ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
  819. p);
  820. ack_recd = true;
  821. }
  822. }
  823. /* either retransmit or send bar if ack not recd */
  824. if (!ack_recd) {
  825. if (retry && (ini->txretry[index] < (int)retry_limit)) {
  826. int ret;
  827. ini->txretry[index]++;
  828. ret = brcms_c_txfifo(wlc, queue, p);
  829. /*
  830. * We shouldn't be out of space in the DMA
  831. * ring here since we're reinserting a frame
  832. * that was just pulled out.
  833. */
  834. WARN_ONCE(ret, "queue %d out of txds\n", queue);
  835. } else {
  836. /* Retry timeout */
  837. ieee80211_tx_info_clear_status(tx_info);
  838. tx_info->status.ampdu_ack_len = 0;
  839. tx_info->status.ampdu_len = 1;
  840. tx_info->flags |=
  841. IEEE80211_TX_STAT_AMPDU_NO_BACK;
  842. skb_pull(p, D11_PHY_HDR_LEN);
  843. skb_pull(p, D11_TXH_LEN);
  844. brcms_dbg_ht(wlc->hw->d11core,
  845. "BA Timeout, seq %d\n",
  846. seq);
  847. ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
  848. p);
  849. }
  850. }
  851. tot_mpdu++;
  852. /* break out if last packet of ampdu */
  853. if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
  854. TXC_AMPDU_LAST)
  855. break;
  856. p = dma_getnexttxp(wlc->hw->di[queue], DMA_RANGE_TRANSMITTED);
  857. }
  858. /* update rate state */
  859. brcms_c_antsel_antsel2id(wlc->asi, mimoantsel);
  860. }
  861. void
  862. brcms_c_ampdu_dotxstatus(struct ampdu_info *ampdu, struct scb *scb,
  863. struct sk_buff *p, struct tx_status *txs)
  864. {
  865. struct brcms_c_info *wlc = ampdu->wlc;
  866. u32 s1 = 0, s2 = 0;
  867. /* BMAC_NOTE: For the split driver, second level txstatus comes later
  868. * So if the ACK was received then wait for the second level else just
  869. * call the first one
  870. */
  871. if (txs->status & TX_STATUS_ACK_RCV) {
  872. u8 status_delay = 0;
  873. /* wait till the next 8 bytes of txstatus is available */
  874. s1 = bcma_read32(wlc->hw->d11core, D11REGOFFS(frmtxstatus));
  875. while ((s1 & TXS_V) == 0) {
  876. udelay(1);
  877. status_delay++;
  878. if (status_delay > 10)
  879. return; /* error condition */
  880. s1 = bcma_read32(wlc->hw->d11core,
  881. D11REGOFFS(frmtxstatus));
  882. }
  883. s2 = bcma_read32(wlc->hw->d11core, D11REGOFFS(frmtxstatus2));
  884. }
  885. if (scb) {
  886. brcms_c_ampdu_dotxstatus_complete(ampdu, scb, p, txs, s1, s2);
  887. } else {
  888. /* loop through all pkts and free */
  889. u8 queue = txs->frameid & TXFID_QUEUE_MASK;
  890. struct d11txh *txh;
  891. u16 mcl;
  892. while (p) {
  893. txh = (struct d11txh *) p->data;
  894. trace_brcms_txdesc(&wlc->hw->d11core->dev, txh,
  895. sizeof(*txh));
  896. mcl = le16_to_cpu(txh->MacTxControlLow);
  897. brcmu_pkt_buf_free_skb(p);
  898. /* break out if last packet of ampdu */
  899. if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
  900. TXC_AMPDU_LAST)
  901. break;
  902. p = dma_getnexttxp(wlc->hw->di[queue],
  903. DMA_RANGE_TRANSMITTED);
  904. }
  905. }
  906. }
  907. void brcms_c_ampdu_macaddr_upd(struct brcms_c_info *wlc)
  908. {
  909. char template[T_RAM_ACCESS_SZ * 2];
  910. /* driver needs to write the ta in the template; ta is at offset 16 */
  911. memset(template, 0, sizeof(template));
  912. memcpy(template, wlc->pub->cur_etheraddr, ETH_ALEN);
  913. brcms_b_write_template_ram(wlc->hw, (T_BA_TPL_BASE + 16),
  914. (T_RAM_ACCESS_SZ * 2),
  915. template);
  916. }
  917. bool brcms_c_aggregatable(struct brcms_c_info *wlc, u8 tid)
  918. {
  919. return wlc->ampdu->ini_enable[tid];
  920. }
  921. void brcms_c_ampdu_shm_upd(struct ampdu_info *ampdu)
  922. {
  923. struct brcms_c_info *wlc = ampdu->wlc;
  924. /*
  925. * Extend ucode internal watchdog timer to
  926. * match larger received frames
  927. */
  928. if ((ampdu->rx_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) ==
  929. IEEE80211_HT_MAX_AMPDU_64K) {
  930. brcms_b_write_shm(wlc->hw, M_MIMO_MAXSYM, MIMO_MAXSYM_MAX);
  931. brcms_b_write_shm(wlc->hw, M_WATCHDOG_8TU, WATCHDOG_8TU_MAX);
  932. } else {
  933. brcms_b_write_shm(wlc->hw, M_MIMO_MAXSYM, MIMO_MAXSYM_DEF);
  934. brcms_b_write_shm(wlc->hw, M_WATCHDOG_8TU, WATCHDOG_8TU_DEF);
  935. }
  936. }
  937. /*
  938. * callback function that helps invalidating ampdu packets in a DMA queue
  939. */
  940. static void dma_cb_fn_ampdu(void *txi, void *arg_a)
  941. {
  942. struct ieee80211_sta *sta = arg_a;
  943. struct ieee80211_tx_info *tx_info = (struct ieee80211_tx_info *)txi;
  944. if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
  945. (tx_info->rate_driver_data[0] == sta || sta == NULL))
  946. tx_info->rate_driver_data[0] = NULL;
  947. }
  948. /*
  949. * When a remote party is no longer available for ampdu communication, any
  950. * pending tx ampdu packets in the driver have to be flushed.
  951. */
  952. void brcms_c_ampdu_flush(struct brcms_c_info *wlc,
  953. struct ieee80211_sta *sta, u16 tid)
  954. {
  955. brcms_c_inval_dma_pkts(wlc->hw, sta, dma_cb_fn_ampdu);
  956. }