staging: brcm80211: cleaned up prefix for utility functions
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmsmac / wlc_ampdu.c
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 <linux/kernel.h>
17 #include <net/mac80211.h>
18
19 #include <bcmdefs.h>
20 #include <bcmutils.h>
21 #include <aiutils.h>
22 #include "bcmdma.h"
23 #include <bcmdma.h>
24 #include <d11.h>
25
26 #include "wlc_types.h"
27 #include "wlc_cfg.h"
28 #include "wlc_rate.h"
29 #include "wlc_scb.h"
30 #include "wlc_pub.h"
31 #include "wlc_key.h"
32 #include "phy/wlc_phy_hal.h"
33 #include "wlc_antsel.h"
34 #include "wlc_channel.h"
35 #include "wlc_main.h"
36 #include "wlc_ampdu.h"
37
38 #define AMPDU_MAX_MPDU 32 /* max number of mpdus in an ampdu */
39 #define AMPDU_NUM_MPDU_LEGACY 16 /* max number of mpdus in an ampdu to a legacy */
40 #define AMPDU_TX_BA_MAX_WSIZE 64 /* max Tx ba window size (in pdu) */
41 #define AMPDU_TX_BA_DEF_WSIZE 64 /* default Tx ba window size (in pdu) */
42 #define AMPDU_RX_BA_DEF_WSIZE 64 /* max Rx ba window size (in pdu) */
43 #define AMPDU_RX_BA_MAX_WSIZE 64 /* default Rx ba window size (in pdu) */
44 #define AMPDU_MAX_DUR 5 /* max dur of tx ampdu (in msec) */
45 #define AMPDU_DEF_RETRY_LIMIT 5 /* default tx retry limit */
46 #define AMPDU_DEF_RR_RETRY_LIMIT 2 /* default tx retry limit at reg rate */
47 #define AMPDU_DEF_TXPKT_WEIGHT 2 /* default weight of ampdu in txfifo */
48 #define AMPDU_DEF_FFPLD_RSVD 2048 /* default ffpld reserved bytes */
49 #define AMPDU_INI_FREE 10 /* # of inis to be freed on detach */
50 #define AMPDU_SCB_MAX_RELEASE 20 /* max # of mpdus released at a time */
51
52 #define NUM_FFPLD_FIFO 4 /* number of fifo concerned by pre-loading */
53 #define FFPLD_TX_MAX_UNFL 200 /* default value of the average number of ampdu
54 * without underflows
55 */
56 #define FFPLD_MPDU_SIZE 1800 /* estimate of maximum mpdu size */
57 #define FFPLD_MAX_MCS 23 /* we don't deal with mcs 32 */
58 #define FFPLD_PLD_INCR 1000 /* increments in bytes */
59 #define FFPLD_MAX_AMPDU_CNT 5000 /* maximum number of ampdu we
60 * accumulate between resets.
61 */
62
63 #define TX_SEQ_TO_INDEX(seq) ((seq) % AMPDU_TX_BA_MAX_WSIZE)
64
65 /* max possible overhead per mpdu in the ampdu; 3 is for roundup if needed */
66 #define AMPDU_MAX_MPDU_OVERHEAD (FCS_LEN + DOT11_ICV_AES_LEN +\
67 AMPDU_DELIMITER_LEN + 3\
68 + DOT11_A4_HDR_LEN + DOT11_QOS_LEN + DOT11_IV_MAX_LEN)
69
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 typedef struct wlc_fifo_info {
77 u16 ampdu_pld_size; /* number of bytes to be pre-loaded */
78 u8 mcs2ampdu_table[FFPLD_MAX_MCS + 1]; /* per-mcs max # of mpdus in an ampdu */
79 u16 prev_txfunfl; /* num of underflows last read from the HW macstats counter */
80 u32 accum_txfunfl; /* num of underflows since we modified pld params */
81 u32 accum_txampdu; /* num of tx ampdu since we modified pld params */
82 u32 prev_txampdu; /* previous reading of tx ampdu */
83 u32 dmaxferrate; /* estimated dma avg xfer rate in kbits/sec */
84 } wlc_fifo_info_t;
85
86 /* AMPDU module specific state */
87 struct ampdu_info {
88 struct wlc_info *wlc; /* pointer to main wlc structure */
89 int scb_handle; /* scb cubby handle to retrieve data from scb */
90 u8 ini_enable[AMPDU_MAX_SCB_TID]; /* per-tid initiator enable/disable of ampdu */
91 u8 ba_tx_wsize; /* Tx ba window size (in pdu) */
92 u8 ba_rx_wsize; /* Rx ba window size (in pdu) */
93 u8 retry_limit; /* mpdu transmit retry limit */
94 u8 rr_retry_limit; /* mpdu transmit retry limit at regular rate */
95 u8 retry_limit_tid[AMPDU_MAX_SCB_TID]; /* per-tid mpdu transmit retry limit */
96 /* per-tid mpdu transmit retry limit at regular rate */
97 u8 rr_retry_limit_tid[AMPDU_MAX_SCB_TID];
98 u8 mpdu_density; /* min mpdu spacing (0-7) ==> 2^(x-1)/8 usec */
99 s8 max_pdu; /* max pdus allowed in ampdu */
100 u8 dur; /* max duration of an ampdu (in msec) */
101 u8 txpkt_weight; /* weight of ampdu in txfifo; reduces rate lag */
102 u8 rx_factor; /* maximum rx ampdu factor (0-3) ==> 2^(13+x) bytes */
103 u32 ffpld_rsvd; /* number of bytes to reserve for preload */
104 u32 max_txlen[MCS_TABLE_SIZE][2][2]; /* max size of ampdu per mcs, bw and sgi */
105 void *ini_free[AMPDU_INI_FREE]; /* array of ini's to be freed on detach */
106 bool mfbr; /* enable multiple fallback rate */
107 u32 tx_max_funl; /* underflows should be kept such that
108 * (tx_max_funfl*underflows) < tx frames
109 */
110 wlc_fifo_info_t fifo_tb[NUM_FFPLD_FIFO]; /* table of fifo infos */
111
112 };
113
114 /* used for flushing ampdu packets */
115 struct cb_del_ampdu_pars {
116 struct ieee80211_sta *sta;
117 u16 tid;
118 };
119
120 #define AMPDU_CLEANUPFLAG_RX (0x1)
121 #define AMPDU_CLEANUPFLAG_TX (0x2)
122
123 #define SCB_AMPDU_CUBBY(ampdu, scb) (&(scb->scb_ampdu))
124 #define SCB_AMPDU_INI(scb_ampdu, tid) (&(scb_ampdu->ini[tid]))
125
126 static void wlc_ffpld_init(struct ampdu_info *ampdu);
127 static int wlc_ffpld_check_txfunfl(struct wlc_info *wlc, int f);
128 static void wlc_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f);
129
130 static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(struct ampdu_info *ampdu,
131 scb_ampdu_t *scb_ampdu,
132 u8 tid, bool override);
133 static void ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur);
134 static void scb_ampdu_update_config(struct ampdu_info *ampdu, struct scb *scb);
135 static void scb_ampdu_update_config_all(struct ampdu_info *ampdu);
136
137 #define wlc_ampdu_txflowcontrol(a, b, c) do {} while (0)
138
139 static void wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu,
140 struct scb *scb,
141 struct sk_buff *p, tx_status_t *txs,
142 u32 frmtxstatus, u32 frmtxstatus2);
143 static bool wlc_ampdu_cap(struct ampdu_info *ampdu);
144 static int wlc_ampdu_set(struct ampdu_info *ampdu, bool on);
145
146 struct ampdu_info *wlc_ampdu_attach(struct wlc_info *wlc)
147 {
148 struct ampdu_info *ampdu;
149 int i;
150
151 ampdu = kzalloc(sizeof(struct ampdu_info), GFP_ATOMIC);
152 if (!ampdu) {
153 wiphy_err(wlc->wiphy, "wl%d: wlc_ampdu_attach: out of mem\n",
154 wlc->pub->unit);
155 return NULL;
156 }
157 ampdu->wlc = wlc;
158
159 for (i = 0; i < AMPDU_MAX_SCB_TID; i++)
160 ampdu->ini_enable[i] = true;
161 /* Disable ampdu for VO by default */
162 ampdu->ini_enable[PRIO_8021D_VO] = false;
163 ampdu->ini_enable[PRIO_8021D_NC] = false;
164
165 /* Disable ampdu for BK by default since not enough fifo space */
166 ampdu->ini_enable[PRIO_8021D_NONE] = false;
167 ampdu->ini_enable[PRIO_8021D_BK] = false;
168
169 ampdu->ba_tx_wsize = AMPDU_TX_BA_DEF_WSIZE;
170 ampdu->ba_rx_wsize = AMPDU_RX_BA_DEF_WSIZE;
171 ampdu->mpdu_density = AMPDU_DEF_MPDU_DENSITY;
172 ampdu->max_pdu = AUTO;
173 ampdu->dur = AMPDU_MAX_DUR;
174 ampdu->txpkt_weight = AMPDU_DEF_TXPKT_WEIGHT;
175
176 ampdu->ffpld_rsvd = AMPDU_DEF_FFPLD_RSVD;
177 /* bump max ampdu rcv size to 64k for all 11n devices except 4321A0 and 4321A1 */
178 if (WLCISNPHY(wlc->band) && NREV_LT(wlc->band->phyrev, 2))
179 ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_32K;
180 else
181 ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_64K;
182 ampdu->retry_limit = AMPDU_DEF_RETRY_LIMIT;
183 ampdu->rr_retry_limit = AMPDU_DEF_RR_RETRY_LIMIT;
184
185 for (i = 0; i < AMPDU_MAX_SCB_TID; i++) {
186 ampdu->retry_limit_tid[i] = ampdu->retry_limit;
187 ampdu->rr_retry_limit_tid[i] = ampdu->rr_retry_limit;
188 }
189
190 ampdu_update_max_txlen(ampdu, ampdu->dur);
191 ampdu->mfbr = false;
192 /* try to set ampdu to the default value */
193 wlc_ampdu_set(ampdu, wlc->pub->_ampdu);
194
195 ampdu->tx_max_funl = FFPLD_TX_MAX_UNFL;
196 wlc_ffpld_init(ampdu);
197
198 return ampdu;
199 }
200
201 void wlc_ampdu_detach(struct ampdu_info *ampdu)
202 {
203 int i;
204
205 if (!ampdu)
206 return;
207
208 /* free all ini's which were to be freed on callbacks which were never called */
209 for (i = 0; i < AMPDU_INI_FREE; i++) {
210 kfree(ampdu->ini_free[i]);
211 }
212
213 wlc_module_unregister(ampdu->wlc->pub, "ampdu", ampdu);
214 kfree(ampdu);
215 }
216
217 static void scb_ampdu_update_config(struct ampdu_info *ampdu, struct scb *scb)
218 {
219 scb_ampdu_t *scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
220 int i;
221
222 scb_ampdu->max_pdu = (u8) ampdu->wlc->pub->tunables->ampdunummpdu;
223
224 /* go back to legacy size if some preloading is occurring */
225 for (i = 0; i < NUM_FFPLD_FIFO; i++) {
226 if (ampdu->fifo_tb[i].ampdu_pld_size > FFPLD_PLD_INCR)
227 scb_ampdu->max_pdu = AMPDU_NUM_MPDU_LEGACY;
228 }
229
230 /* apply user override */
231 if (ampdu->max_pdu != AUTO)
232 scb_ampdu->max_pdu = (u8) ampdu->max_pdu;
233
234 scb_ampdu->release = min_t(u8, scb_ampdu->max_pdu, AMPDU_SCB_MAX_RELEASE);
235
236 if (scb_ampdu->max_rxlen)
237 scb_ampdu->release =
238 min_t(u8, scb_ampdu->release, scb_ampdu->max_rxlen / 1600);
239
240 scb_ampdu->release = min(scb_ampdu->release,
241 ampdu->fifo_tb[TX_AC_BE_FIFO].
242 mcs2ampdu_table[FFPLD_MAX_MCS]);
243 }
244
245 static void scb_ampdu_update_config_all(struct ampdu_info *ampdu)
246 {
247 scb_ampdu_update_config(ampdu, ampdu->wlc->pub->global_scb);
248 }
249
250 static void wlc_ffpld_init(struct ampdu_info *ampdu)
251 {
252 int i, j;
253 wlc_fifo_info_t *fifo;
254
255 for (j = 0; j < NUM_FFPLD_FIFO; j++) {
256 fifo = (ampdu->fifo_tb + j);
257 fifo->ampdu_pld_size = 0;
258 for (i = 0; i <= FFPLD_MAX_MCS; i++)
259 fifo->mcs2ampdu_table[i] = 255;
260 fifo->dmaxferrate = 0;
261 fifo->accum_txampdu = 0;
262 fifo->prev_txfunfl = 0;
263 fifo->accum_txfunfl = 0;
264
265 }
266 }
267
268 /* evaluate the dma transfer rate using the tx underflows as feedback.
269 * If necessary, increase tx fifo preloading. If not enough,
270 * decrease maximum ampdu size for each mcs till underflows stop
271 * Return 1 if pre-loading not active, -1 if not an underflow event,
272 * 0 if pre-loading module took care of the event.
273 */
274 static int wlc_ffpld_check_txfunfl(struct wlc_info *wlc, int fid)
275 {
276 struct ampdu_info *ampdu = wlc->ampdu;
277 u32 phy_rate = MCS_RATE(FFPLD_MAX_MCS, true, false);
278 u32 txunfl_ratio;
279 u8 max_mpdu;
280 u32 current_ampdu_cnt = 0;
281 u16 max_pld_size;
282 u32 new_txunfl;
283 wlc_fifo_info_t *fifo = (ampdu->fifo_tb + fid);
284 uint xmtfifo_sz;
285 u16 cur_txunfl;
286
287 /* return if we got here for a different reason than underflows */
288 cur_txunfl =
289 wlc_read_shm(wlc,
290 M_UCODE_MACSTAT + offsetof(macstat_t, txfunfl[fid]));
291 new_txunfl = (u16) (cur_txunfl - fifo->prev_txfunfl);
292 if (new_txunfl == 0) {
293 BCMMSG(wlc->wiphy, "TX status FRAG set but no tx underflows\n");
294 return -1;
295 }
296 fifo->prev_txfunfl = cur_txunfl;
297
298 if (!ampdu->tx_max_funl)
299 return 1;
300
301 /* check if fifo is big enough */
302 if (wlc_xmtfifo_sz_get(wlc, fid, &xmtfifo_sz)) {
303 return -1;
304 }
305
306 if ((TXFIFO_SIZE_UNIT * (u32) xmtfifo_sz) <= ampdu->ffpld_rsvd)
307 return 1;
308
309 max_pld_size = TXFIFO_SIZE_UNIT * xmtfifo_sz - ampdu->ffpld_rsvd;
310 fifo->accum_txfunfl += new_txunfl;
311
312 /* we need to wait for at least 10 underflows */
313 if (fifo->accum_txfunfl < 10)
314 return 0;
315
316 BCMMSG(wlc->wiphy, "ampdu_count %d tx_underflows %d\n",
317 current_ampdu_cnt, fifo->accum_txfunfl);
318
319 /*
320 compute the current ratio of tx unfl per ampdu.
321 When the current ampdu count becomes too
322 big while the ratio remains small, we reset
323 the current count in order to not
324 introduce too big of a latency in detecting a
325 large amount of tx underflows later.
326 */
327
328 txunfl_ratio = current_ampdu_cnt / fifo->accum_txfunfl;
329
330 if (txunfl_ratio > ampdu->tx_max_funl) {
331 if (current_ampdu_cnt >= FFPLD_MAX_AMPDU_CNT) {
332 fifo->accum_txfunfl = 0;
333 }
334 return 0;
335 }
336 max_mpdu =
337 min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS], AMPDU_NUM_MPDU_LEGACY);
338
339 /* In case max value max_pdu is already lower than
340 the fifo depth, there is nothing more we can do.
341 */
342
343 if (fifo->ampdu_pld_size >= max_mpdu * FFPLD_MPDU_SIZE) {
344 fifo->accum_txfunfl = 0;
345 return 0;
346 }
347
348 if (fifo->ampdu_pld_size < max_pld_size) {
349
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
355 /* update scb release size */
356 scb_ampdu_update_config_all(ampdu);
357
358 /*
359 compute a new dma xfer rate for max_mpdu @ max mcs.
360 This is the minimum dma rate that
361 can achieve no underflow condition for the current mpdu size.
362 */
363 /* note : we divide/multiply by 100 to avoid integer overflows */
364 fifo->dmaxferrate =
365 (((phy_rate / 100) *
366 (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
367 / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
368
369 BCMMSG(wlc->wiphy, "DMA estimated transfer rate %d; "
370 "pre-load size %d\n",
371 fifo->dmaxferrate, fifo->ampdu_pld_size);
372 } else {
373
374 /* decrease ampdu size */
375 if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] > 1) {
376 if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] == 255)
377 fifo->mcs2ampdu_table[FFPLD_MAX_MCS] =
378 AMPDU_NUM_MPDU_LEGACY - 1;
379 else
380 fifo->mcs2ampdu_table[FFPLD_MAX_MCS] -= 1;
381
382 /* recompute the table */
383 wlc_ffpld_calc_mcs2ampdu_table(ampdu, fid);
384
385 /* update scb release size */
386 scb_ampdu_update_config_all(ampdu);
387 }
388 }
389 fifo->accum_txfunfl = 0;
390 return 0;
391 }
392
393 static void wlc_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f)
394 {
395 int i;
396 u32 phy_rate, dma_rate, tmp;
397 u8 max_mpdu;
398 wlc_fifo_info_t *fifo = (ampdu->fifo_tb + f);
399
400 /* recompute the dma rate */
401 /* note : we divide/multiply by 100 to avoid integer overflows */
402 max_mpdu =
403 min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS], AMPDU_NUM_MPDU_LEGACY);
404 phy_rate = MCS_RATE(FFPLD_MAX_MCS, true, false);
405 dma_rate =
406 (((phy_rate / 100) *
407 (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
408 / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
409 fifo->dmaxferrate = dma_rate;
410
411 /* fill up the mcs2ampdu table; do not recalc the last mcs */
412 dma_rate = dma_rate >> 7;
413 for (i = 0; i < FFPLD_MAX_MCS; i++) {
414 /* shifting to keep it within integer range */
415 phy_rate = MCS_RATE(i, true, false) >> 7;
416 if (phy_rate > dma_rate) {
417 tmp = ((fifo->ampdu_pld_size * phy_rate) /
418 ((phy_rate - dma_rate) * FFPLD_MPDU_SIZE)) + 1;
419 tmp = min_t(u32, tmp, 255);
420 fifo->mcs2ampdu_table[i] = (u8) tmp;
421 }
422 }
423 }
424
425 static void
426 wlc_ampdu_agg(struct ampdu_info *ampdu, struct scb *scb, struct sk_buff *p,
427 uint prec)
428 {
429 scb_ampdu_t *scb_ampdu;
430 scb_ampdu_tid_ini_t *ini;
431 u8 tid = (u8) (p->priority);
432
433 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
434
435 /* initialize initiator on first packet; sends addba req */
436 ini = SCB_AMPDU_INI(scb_ampdu, tid);
437 if (ini->magic != INI_MAGIC) {
438 ini = wlc_ampdu_init_tid_ini(ampdu, scb_ampdu, tid, false);
439 }
440 return;
441 }
442
443 int
444 wlc_sendampdu(struct ampdu_info *ampdu, struct wlc_txq_info *qi,
445 struct sk_buff **pdu, int prec)
446 {
447 struct wlc_info *wlc;
448 struct sk_buff *p, *pkt[AMPDU_MAX_MPDU];
449 u8 tid, ndelim;
450 int err = 0;
451 u8 preamble_type = WLC_GF_PREAMBLE;
452 u8 fbr_preamble_type = WLC_GF_PREAMBLE;
453 u8 rts_preamble_type = WLC_LONG_PREAMBLE;
454 u8 rts_fbr_preamble_type = WLC_LONG_PREAMBLE;
455
456 bool rr = true, fbr = false;
457 uint i, count = 0, fifo, seg_cnt = 0;
458 u16 plen, len, seq = 0, mcl, mch, index, frameid, dma_len = 0;
459 u32 ampdu_len, maxlen = 0;
460 d11txh_t *txh = NULL;
461 u8 *plcp;
462 struct ieee80211_hdr *h;
463 struct scb *scb;
464 scb_ampdu_t *scb_ampdu;
465 scb_ampdu_tid_ini_t *ini;
466 u8 mcs = 0;
467 bool use_rts = false, use_cts = false;
468 ratespec_t rspec = 0, rspec_fallback = 0;
469 ratespec_t rts_rspec = 0, rts_rspec_fallback = 0;
470 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
471 struct ieee80211_rts *rts;
472 u8 rr_retry_limit;
473 wlc_fifo_info_t *f;
474 bool fbr_iscck;
475 struct ieee80211_tx_info *tx_info;
476 u16 qlen;
477 struct wiphy *wiphy;
478
479 wlc = ampdu->wlc;
480 wiphy = wlc->wiphy;
481 p = *pdu;
482
483 tid = (u8) (p->priority);
484
485 f = ampdu->fifo_tb + prio2fifo[tid];
486
487 scb = wlc->pub->global_scb;
488 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
489 ini = &scb_ampdu->ini[tid];
490
491 /* Let pressure continue to build ... */
492 qlen = pktq_plen(&qi->q, prec);
493 if (ini->tx_in_transit > 0 && qlen < scb_ampdu->max_pdu) {
494 return -EBUSY;
495 }
496
497 wlc_ampdu_agg(ampdu, scb, p, tid);
498
499 rr_retry_limit = ampdu->rr_retry_limit_tid[tid];
500 ampdu_len = 0;
501 dma_len = 0;
502 while (p) {
503 struct ieee80211_tx_rate *txrate;
504
505 tx_info = IEEE80211_SKB_CB(p);
506 txrate = tx_info->status.rates;
507
508 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
509 err = wlc_prep_pdu(wlc, p, &fifo);
510 } else {
511 wiphy_err(wiphy, "%s: AMPDU flag is off!\n", __func__);
512 *pdu = NULL;
513 err = 0;
514 break;
515 }
516
517 if (err) {
518 if (err == -EBUSY) {
519 wiphy_err(wiphy, "wl%d: wlc_sendampdu: "
520 "prep_xdu retry; seq 0x%x\n",
521 wlc->pub->unit, seq);
522 *pdu = p;
523 break;
524 }
525
526 /* error in the packet; reject it */
527 wiphy_err(wiphy, "wl%d: wlc_sendampdu: prep_xdu "
528 "rejected; seq 0x%x\n", wlc->pub->unit, seq);
529 *pdu = NULL;
530 break;
531 }
532
533 /* pkt is good to be aggregated */
534 txh = (d11txh_t *) p->data;
535 plcp = (u8 *) (txh + 1);
536 h = (struct ieee80211_hdr *)(plcp + D11_PHY_HDR_LEN);
537 seq = le16_to_cpu(h->seq_ctrl) >> SEQNUM_SHIFT;
538 index = TX_SEQ_TO_INDEX(seq);
539
540 /* check mcl fields and test whether it can be agg'd */
541 mcl = le16_to_cpu(txh->MacTxControlLow);
542 mcl &= ~TXC_AMPDU_MASK;
543 fbr_iscck = !(le16_to_cpu(txh->XtraFrameTypes) & 0x3);
544 txh->PreloadSize = 0; /* always default to 0 */
545
546 /* Handle retry limits */
547 if (txrate[0].count <= rr_retry_limit) {
548 txrate[0].count++;
549 rr = true;
550 fbr = false;
551 } else {
552 fbr = true;
553 rr = false;
554 txrate[1].count++;
555 }
556
557 /* extract the length info */
558 len = fbr_iscck ? WLC_GET_CCK_PLCP_LEN(txh->FragPLCPFallback)
559 : WLC_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
560
561 /* retrieve null delimiter count */
562 ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
563 seg_cnt += 1;
564
565 BCMMSG(wlc->wiphy, "wl%d: mpdu %d plcp_len %d\n",
566 wlc->pub->unit, count, len);
567
568 /*
569 * aggregateable mpdu. For ucode/hw agg,
570 * test whether need to break or change the epoch
571 */
572 if (count == 0) {
573 mcl |= (TXC_AMPDU_FIRST << TXC_AMPDU_SHIFT);
574 /* refill the bits since might be a retx mpdu */
575 mcl |= TXC_STARTMSDU;
576 rts = (struct ieee80211_rts *)&txh->rts_frame;
577
578 if (ieee80211_is_rts(rts->frame_control)) {
579 mcl |= TXC_SENDRTS;
580 use_rts = true;
581 }
582 if (ieee80211_is_cts(rts->frame_control)) {
583 mcl |= TXC_SENDCTS;
584 use_cts = true;
585 }
586 } else {
587 mcl |= (TXC_AMPDU_MIDDLE << TXC_AMPDU_SHIFT);
588 mcl &= ~(TXC_STARTMSDU | TXC_SENDRTS | TXC_SENDCTS);
589 }
590
591 len = roundup(len, 4);
592 ampdu_len += (len + (ndelim + 1) * AMPDU_DELIMITER_LEN);
593
594 dma_len += (u16) brcmu_pkttotlen(p);
595
596 BCMMSG(wlc->wiphy, "wl%d: ampdu_len %d"
597 " seg_cnt %d null delim %d\n",
598 wlc->pub->unit, ampdu_len, seg_cnt, ndelim);
599
600 txh->MacTxControlLow = cpu_to_le16(mcl);
601
602 /* this packet is added */
603 pkt[count++] = p;
604
605 /* patch the first MPDU */
606 if (count == 1) {
607 u8 plcp0, plcp3, is40, sgi;
608 struct ieee80211_sta *sta;
609
610 sta = tx_info->control.sta;
611
612 if (rr) {
613 plcp0 = plcp[0];
614 plcp3 = plcp[3];
615 } else {
616 plcp0 = txh->FragPLCPFallback[0];
617 plcp3 = txh->FragPLCPFallback[3];
618
619 }
620 is40 = (plcp0 & MIMO_PLCP_40MHZ) ? 1 : 0;
621 sgi = PLCP3_ISSGI(plcp3) ? 1 : 0;
622 mcs = plcp0 & ~MIMO_PLCP_40MHZ;
623 maxlen =
624 min(scb_ampdu->max_rxlen,
625 ampdu->max_txlen[mcs][is40][sgi]);
626
627 /* XXX Fix me to honor real max_rxlen */
628 /* can fix this as soon as ampdu_action() in mac80211.h
629 * gets extra u8buf_size par */
630 maxlen = 64 * 1024;
631
632 if (is40)
633 mimo_ctlchbw =
634 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
635 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
636
637 /* rebuild the rspec and rspec_fallback */
638 rspec = RSPEC_MIMORATE;
639 rspec |= plcp[0] & ~MIMO_PLCP_40MHZ;
640 if (plcp[0] & MIMO_PLCP_40MHZ)
641 rspec |= (PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT);
642
643 if (fbr_iscck) /* CCK */
644 rspec_fallback =
645 CCK_RSPEC(CCK_PHY2MAC_RATE
646 (txh->FragPLCPFallback[0]));
647 else { /* MIMO */
648 rspec_fallback = RSPEC_MIMORATE;
649 rspec_fallback |=
650 txh->FragPLCPFallback[0] & ~MIMO_PLCP_40MHZ;
651 if (txh->FragPLCPFallback[0] & MIMO_PLCP_40MHZ)
652 rspec_fallback |=
653 (PHY_TXC1_BW_40MHZ <<
654 RSPEC_BW_SHIFT);
655 }
656
657 if (use_rts || use_cts) {
658 rts_rspec =
659 wlc_rspec_to_rts_rspec(wlc, rspec, false,
660 mimo_ctlchbw);
661 rts_rspec_fallback =
662 wlc_rspec_to_rts_rspec(wlc, rspec_fallback,
663 false, mimo_ctlchbw);
664 }
665 }
666
667 /* if (first mpdu for host agg) */
668 /* test whether to add more */
669 if ((MCS_RATE(mcs, true, false) >= f->dmaxferrate) &&
670 (count == f->mcs2ampdu_table[mcs])) {
671 BCMMSG(wlc->wiphy, "wl%d: PR 37644: stopping"
672 " ampdu at %d for mcs %d\n",
673 wlc->pub->unit, count, mcs);
674 break;
675 }
676
677 if (count == scb_ampdu->max_pdu) {
678 break;
679 }
680
681 /* check to see if the next pkt is a candidate for aggregation */
682 p = pktq_ppeek(&qi->q, prec);
683 tx_info = IEEE80211_SKB_CB(p); /* tx_info must be checked with current p */
684
685 if (p) {
686 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
687 ((u8) (p->priority) == tid)) {
688
689 plen = brcmu_pkttotlen(p) +
690 AMPDU_MAX_MPDU_OVERHEAD;
691 plen = max(scb_ampdu->min_len, plen);
692
693 if ((plen + ampdu_len) > maxlen) {
694 p = NULL;
695 wiphy_err(wiphy, "%s: Bogus plen #1\n",
696 __func__);
697 continue;
698 }
699
700 /* check if there are enough descriptors available */
701 if (TXAVAIL(wlc, fifo) <= (seg_cnt + 1)) {
702 wiphy_err(wiphy, "%s: No fifo space "
703 "!!\n", __func__);
704 p = NULL;
705 continue;
706 }
707 p = brcmu_pktq_pdeq(&qi->q, prec);
708 } else {
709 p = NULL;
710 }
711 }
712 } /* end while(p) */
713
714 ini->tx_in_transit += count;
715
716 if (count) {
717 /* patch up the last txh */
718 txh = (d11txh_t *) pkt[count - 1]->data;
719 mcl = le16_to_cpu(txh->MacTxControlLow);
720 mcl &= ~TXC_AMPDU_MASK;
721 mcl |= (TXC_AMPDU_LAST << TXC_AMPDU_SHIFT);
722 txh->MacTxControlLow = cpu_to_le16(mcl);
723
724 /* remove the null delimiter after last mpdu */
725 ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
726 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = 0;
727 ampdu_len -= ndelim * AMPDU_DELIMITER_LEN;
728
729 /* remove the pad len from last mpdu */
730 fbr_iscck = ((le16_to_cpu(txh->XtraFrameTypes) & 0x3) == 0);
731 len = fbr_iscck ? WLC_GET_CCK_PLCP_LEN(txh->FragPLCPFallback)
732 : WLC_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
733 ampdu_len -= roundup(len, 4) - len;
734
735 /* patch up the first txh & plcp */
736 txh = (d11txh_t *) pkt[0]->data;
737 plcp = (u8 *) (txh + 1);
738
739 WLC_SET_MIMO_PLCP_LEN(plcp, ampdu_len);
740 /* mark plcp to indicate ampdu */
741 WLC_SET_MIMO_PLCP_AMPDU(plcp);
742
743 /* reset the mixed mode header durations */
744 if (txh->MModeLen) {
745 u16 mmodelen =
746 wlc_calc_lsig_len(wlc, rspec, ampdu_len);
747 txh->MModeLen = cpu_to_le16(mmodelen);
748 preamble_type = WLC_MM_PREAMBLE;
749 }
750 if (txh->MModeFbrLen) {
751 u16 mmfbrlen =
752 wlc_calc_lsig_len(wlc, rspec_fallback, ampdu_len);
753 txh->MModeFbrLen = cpu_to_le16(mmfbrlen);
754 fbr_preamble_type = WLC_MM_PREAMBLE;
755 }
756
757 /* set the preload length */
758 if (MCS_RATE(mcs, true, false) >= f->dmaxferrate) {
759 dma_len = min(dma_len, f->ampdu_pld_size);
760 txh->PreloadSize = cpu_to_le16(dma_len);
761 } else
762 txh->PreloadSize = 0;
763
764 mch = le16_to_cpu(txh->MacTxControlHigh);
765
766 /* update RTS dur fields */
767 if (use_rts || use_cts) {
768 u16 durid;
769 rts = (struct ieee80211_rts *)&txh->rts_frame;
770 if ((mch & TXC_PREAMBLE_RTS_MAIN_SHORT) ==
771 TXC_PREAMBLE_RTS_MAIN_SHORT)
772 rts_preamble_type = WLC_SHORT_PREAMBLE;
773
774 if ((mch & TXC_PREAMBLE_RTS_FB_SHORT) ==
775 TXC_PREAMBLE_RTS_FB_SHORT)
776 rts_fbr_preamble_type = WLC_SHORT_PREAMBLE;
777
778 durid =
779 wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec,
780 rspec, rts_preamble_type,
781 preamble_type, ampdu_len,
782 true);
783 rts->duration = cpu_to_le16(durid);
784 durid = wlc_compute_rtscts_dur(wlc, use_cts,
785 rts_rspec_fallback,
786 rspec_fallback,
787 rts_fbr_preamble_type,
788 fbr_preamble_type,
789 ampdu_len, true);
790 txh->RTSDurFallback = cpu_to_le16(durid);
791 /* set TxFesTimeNormal */
792 txh->TxFesTimeNormal = rts->duration;
793 /* set fallback rate version of TxFesTimeNormal */
794 txh->TxFesTimeFallback = txh->RTSDurFallback;
795 }
796
797 /* set flag and plcp for fallback rate */
798 if (fbr) {
799 mch |= TXC_AMPDU_FBR;
800 txh->MacTxControlHigh = cpu_to_le16(mch);
801 WLC_SET_MIMO_PLCP_AMPDU(plcp);
802 WLC_SET_MIMO_PLCP_AMPDU(txh->FragPLCPFallback);
803 }
804
805 BCMMSG(wlc->wiphy, "wl%d: count %d ampdu_len %d\n",
806 wlc->pub->unit, count, ampdu_len);
807
808 /* inform rate_sel if it this is a rate probe pkt */
809 frameid = le16_to_cpu(txh->TxFrameID);
810 if (frameid & TXFID_RATE_PROBE_MASK) {
811 wiphy_err(wiphy, "%s: XXX what to do with "
812 "TXFID_RATE_PROBE_MASK!?\n", __func__);
813 }
814 for (i = 0; i < count; i++)
815 wlc_txfifo(wlc, fifo, pkt[i], i == (count - 1),
816 ampdu->txpkt_weight);
817
818 }
819 /* endif (count) */
820 return err;
821 }
822
823 void
824 wlc_ampdu_dotxstatus(struct ampdu_info *ampdu, struct scb *scb,
825 struct sk_buff *p, tx_status_t *txs)
826 {
827 scb_ampdu_t *scb_ampdu;
828 struct wlc_info *wlc = ampdu->wlc;
829 scb_ampdu_tid_ini_t *ini;
830 u32 s1 = 0, s2 = 0;
831 struct ieee80211_tx_info *tx_info;
832
833 tx_info = IEEE80211_SKB_CB(p);
834
835 /* BMAC_NOTE: For the split driver, second level txstatus comes later
836 * So if the ACK was received then wait for the second level else just
837 * call the first one
838 */
839 if (txs->status & TX_STATUS_ACK_RCV) {
840 u8 status_delay = 0;
841
842 /* wait till the next 8 bytes of txstatus is available */
843 while (((s1 = R_REG(&wlc->regs->frmtxstatus)) & TXS_V) == 0) {
844 udelay(1);
845 status_delay++;
846 if (status_delay > 10) {
847 return; /* error condition */
848 }
849 }
850
851 s2 = R_REG(&wlc->regs->frmtxstatus2);
852 }
853
854 if (likely(scb)) {
855 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
856 ini = SCB_AMPDU_INI(scb_ampdu, p->priority);
857 wlc_ampdu_dotxstatus_complete(ampdu, scb, p, txs, s1, s2);
858 } else {
859 /* loop through all pkts and free */
860 u8 queue = txs->frameid & TXFID_QUEUE_MASK;
861 d11txh_t *txh;
862 u16 mcl;
863 while (p) {
864 tx_info = IEEE80211_SKB_CB(p);
865 txh = (d11txh_t *) p->data;
866 mcl = le16_to_cpu(txh->MacTxControlLow);
867 brcmu_pkt_buf_free_skb(p);
868 /* break out if last packet of ampdu */
869 if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
870 TXC_AMPDU_LAST)
871 break;
872 p = GETNEXTTXP(wlc, queue);
873 }
874 wlc_txfifo_complete(wlc, queue, ampdu->txpkt_weight);
875 }
876 wlc_ampdu_txflowcontrol(wlc, scb_ampdu, ini);
877 }
878
879 static void
880 rate_status(struct wlc_info *wlc, struct ieee80211_tx_info *tx_info,
881 tx_status_t *txs, u8 mcs)
882 {
883 struct ieee80211_tx_rate *txrate = tx_info->status.rates;
884 int i;
885
886 /* clear the rest of the rates */
887 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
888 txrate[i].idx = -1;
889 txrate[i].count = 0;
890 }
891 }
892
893 #define SHORTNAME "AMPDU status"
894
895 static void
896 wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb,
897 struct sk_buff *p, tx_status_t *txs,
898 u32 s1, u32 s2)
899 {
900 scb_ampdu_t *scb_ampdu;
901 struct wlc_info *wlc = ampdu->wlc;
902 scb_ampdu_tid_ini_t *ini;
903 u8 bitmap[8], queue, tid;
904 d11txh_t *txh;
905 u8 *plcp;
906 struct ieee80211_hdr *h;
907 u16 seq, start_seq = 0, bindex, index, mcl;
908 u8 mcs = 0;
909 bool ba_recd = false, ack_recd = false;
910 u8 suc_mpdu = 0, tot_mpdu = 0;
911 uint supr_status;
912 bool update_rate = true, retry = true, tx_error = false;
913 u16 mimoantsel = 0;
914 u8 antselid = 0;
915 u8 retry_limit, rr_retry_limit;
916 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(p);
917 struct wiphy *wiphy = wlc->wiphy;
918
919 #ifdef BCMDBG
920 u8 hole[AMPDU_MAX_MPDU];
921 memset(hole, 0, sizeof(hole));
922 #endif
923
924 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
925 tid = (u8) (p->priority);
926
927 ini = SCB_AMPDU_INI(scb_ampdu, tid);
928 retry_limit = ampdu->retry_limit_tid[tid];
929 rr_retry_limit = ampdu->rr_retry_limit_tid[tid];
930 memset(bitmap, 0, sizeof(bitmap));
931 queue = txs->frameid & TXFID_QUEUE_MASK;
932 supr_status = txs->status & TX_STATUS_SUPR_MASK;
933
934 if (txs->status & TX_STATUS_ACK_RCV) {
935 if (TX_STATUS_SUPR_UF == supr_status) {
936 update_rate = false;
937 }
938
939 WARN_ON(!(txs->status & TX_STATUS_INTERMEDIATE));
940 start_seq = txs->sequence >> SEQNUM_SHIFT;
941 bitmap[0] = (txs->status & TX_STATUS_BA_BMAP03_MASK) >>
942 TX_STATUS_BA_BMAP03_SHIFT;
943
944 WARN_ON(s1 & TX_STATUS_INTERMEDIATE);
945 WARN_ON(!(s1 & TX_STATUS_AMPDU));
946
947 bitmap[0] |=
948 (s1 & TX_STATUS_BA_BMAP47_MASK) <<
949 TX_STATUS_BA_BMAP47_SHIFT;
950 bitmap[1] = (s1 >> 8) & 0xff;
951 bitmap[2] = (s1 >> 16) & 0xff;
952 bitmap[3] = (s1 >> 24) & 0xff;
953
954 bitmap[4] = s2 & 0xff;
955 bitmap[5] = (s2 >> 8) & 0xff;
956 bitmap[6] = (s2 >> 16) & 0xff;
957 bitmap[7] = (s2 >> 24) & 0xff;
958
959 ba_recd = true;
960 } else {
961 if (supr_status) {
962 update_rate = false;
963 if (supr_status == TX_STATUS_SUPR_BADCH) {
964 wiphy_err(wiphy, "%s: Pkt tx suppressed, "
965 "illegal channel possibly %d\n",
966 __func__, CHSPEC_CHANNEL(
967 wlc->default_bss->chanspec));
968 } else {
969 if (supr_status != TX_STATUS_SUPR_FRAG)
970 wiphy_err(wiphy, "%s: wlc_ampdu_dotx"
971 "status:supr_status 0x%x\n",
972 __func__, supr_status);
973 }
974 /* no need to retry for badch; will fail again */
975 if (supr_status == TX_STATUS_SUPR_BADCH ||
976 supr_status == TX_STATUS_SUPR_EXPTIME) {
977 retry = false;
978 } else if (supr_status == TX_STATUS_SUPR_EXPTIME) {
979 /* TX underflow : try tuning pre-loading or ampdu size */
980 } else if (supr_status == TX_STATUS_SUPR_FRAG) {
981 /* if there were underflows, but pre-loading is not active,
982 notify rate adaptation.
983 */
984 if (wlc_ffpld_check_txfunfl(wlc, prio2fifo[tid])
985 > 0) {
986 tx_error = true;
987 }
988 }
989 } else if (txs->phyerr) {
990 update_rate = false;
991 wiphy_err(wiphy, "wl%d: wlc_ampdu_dotxstatus: tx phy "
992 "error (0x%x)\n", wlc->pub->unit,
993 txs->phyerr);
994
995 if (WL_ERROR_ON()) {
996 brcmu_prpkt("txpkt (AMPDU)", p);
997 wlc_print_txdesc((d11txh_t *) p->data);
998 }
999 wlc_print_txstatus(txs);
1000 }
1001 }
1002
1003 /* loop through all pkts and retry if not acked */
1004 while (p) {
1005 tx_info = IEEE80211_SKB_CB(p);
1006 txh = (d11txh_t *) p->data;
1007 mcl = le16_to_cpu(txh->MacTxControlLow);
1008 plcp = (u8 *) (txh + 1);
1009 h = (struct ieee80211_hdr *)(plcp + D11_PHY_HDR_LEN);
1010 seq = le16_to_cpu(h->seq_ctrl) >> SEQNUM_SHIFT;
1011
1012 if (tot_mpdu == 0) {
1013 mcs = plcp[0] & MIMO_PLCP_MCS_MASK;
1014 mimoantsel = le16_to_cpu(txh->ABI_MimoAntSel);
1015 }
1016
1017 index = TX_SEQ_TO_INDEX(seq);
1018 ack_recd = false;
1019 if (ba_recd) {
1020 bindex = MODSUB_POW2(seq, start_seq, SEQNUM_MAX);
1021 BCMMSG(wlc->wiphy, "tid %d seq %d,"
1022 " start_seq %d, bindex %d set %d, index %d\n",
1023 tid, seq, start_seq, bindex,
1024 isset(bitmap, bindex), index);
1025 /* if acked then clear bit and free packet */
1026 if ((bindex < AMPDU_TX_BA_MAX_WSIZE)
1027 && isset(bitmap, bindex)) {
1028 ini->tx_in_transit--;
1029 ini->txretry[index] = 0;
1030
1031 /* ampdu_ack_len: number of acked aggregated frames */
1032 /* ampdu_len: number of aggregated frames */
1033 rate_status(wlc, tx_info, txs, mcs);
1034 tx_info->flags |= IEEE80211_TX_STAT_ACK;
1035 tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
1036 tx_info->status.ampdu_ack_len =
1037 tx_info->status.ampdu_len = 1;
1038
1039 skb_pull(p, D11_PHY_HDR_LEN);
1040 skb_pull(p, D11_TXH_LEN);
1041
1042 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
1043 p);
1044 ack_recd = true;
1045 suc_mpdu++;
1046 }
1047 }
1048 /* either retransmit or send bar if ack not recd */
1049 if (!ack_recd) {
1050 struct ieee80211_tx_rate *txrate =
1051 tx_info->status.rates;
1052 if (retry && (txrate[0].count < (int)retry_limit)) {
1053 ini->txretry[index]++;
1054 ini->tx_in_transit--;
1055 /* Use high prededence for retransmit to give some punch */
1056 /* wlc_txq_enq(wlc, scb, p, WLC_PRIO_TO_PREC(tid)); */
1057 wlc_txq_enq(wlc, scb, p,
1058 WLC_PRIO_TO_HI_PREC(tid));
1059 } else {
1060 /* Retry timeout */
1061 ini->tx_in_transit--;
1062 ieee80211_tx_info_clear_status(tx_info);
1063 tx_info->status.ampdu_ack_len = 0;
1064 tx_info->status.ampdu_len = 1;
1065 tx_info->flags |=
1066 IEEE80211_TX_STAT_AMPDU_NO_BACK;
1067 skb_pull(p, D11_PHY_HDR_LEN);
1068 skb_pull(p, D11_TXH_LEN);
1069 wiphy_err(wiphy, "%s: BA Timeout, seq %d, in_"
1070 "transit %d\n", SHORTNAME, seq,
1071 ini->tx_in_transit);
1072 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
1073 p);
1074 }
1075 }
1076 tot_mpdu++;
1077
1078 /* break out if last packet of ampdu */
1079 if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
1080 TXC_AMPDU_LAST)
1081 break;
1082
1083 p = GETNEXTTXP(wlc, queue);
1084 }
1085 wlc_send_q(wlc);
1086
1087 /* update rate state */
1088 antselid = wlc_antsel_antsel2id(wlc->asi, mimoantsel);
1089
1090 wlc_txfifo_complete(wlc, queue, ampdu->txpkt_weight);
1091 }
1092
1093 /* initialize the initiator code for tid */
1094 static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(struct ampdu_info *ampdu,
1095 scb_ampdu_t *scb_ampdu,
1096 u8 tid, bool override)
1097 {
1098 scb_ampdu_tid_ini_t *ini;
1099
1100 /* check for per-tid control of ampdu */
1101 if (!ampdu->ini_enable[tid]) {
1102 wiphy_err(ampdu->wlc->wiphy, "%s: Rejecting tid %d\n",
1103 __func__, tid);
1104 return NULL;
1105 }
1106
1107 ini = SCB_AMPDU_INI(scb_ampdu, tid);
1108 ini->tid = tid;
1109 ini->scb = scb_ampdu->scb;
1110 ini->magic = INI_MAGIC;
1111 return ini;
1112 }
1113
1114 static int wlc_ampdu_set(struct ampdu_info *ampdu, bool on)
1115 {
1116 struct wlc_info *wlc = ampdu->wlc;
1117
1118 wlc->pub->_ampdu = false;
1119
1120 if (on) {
1121 if (!N_ENAB(wlc->pub)) {
1122 wiphy_err(ampdu->wlc->wiphy, "wl%d: driver not "
1123 "nmode enabled\n", wlc->pub->unit);
1124 return -ENOTSUPP;
1125 }
1126 if (!wlc_ampdu_cap(ampdu)) {
1127 wiphy_err(ampdu->wlc->wiphy, "wl%d: device not "
1128 "ampdu capable\n", wlc->pub->unit);
1129 return -ENOTSUPP;
1130 }
1131 wlc->pub->_ampdu = on;
1132 }
1133
1134 return 0;
1135 }
1136
1137 static bool wlc_ampdu_cap(struct ampdu_info *ampdu)
1138 {
1139 if (WLC_PHY_11N_CAP(ampdu->wlc->band))
1140 return true;
1141 else
1142 return false;
1143 }
1144
1145 static void ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur)
1146 {
1147 u32 rate, mcs;
1148
1149 for (mcs = 0; mcs < MCS_TABLE_SIZE; mcs++) {
1150 /* rate is in Kbps; dur is in msec ==> len = (rate * dur) / 8 */
1151 /* 20MHz, No SGI */
1152 rate = MCS_RATE(mcs, false, false);
1153 ampdu->max_txlen[mcs][0][0] = (rate * dur) >> 3;
1154 /* 40 MHz, No SGI */
1155 rate = MCS_RATE(mcs, true, false);
1156 ampdu->max_txlen[mcs][1][0] = (rate * dur) >> 3;
1157 /* 20MHz, SGI */
1158 rate = MCS_RATE(mcs, false, true);
1159 ampdu->max_txlen[mcs][0][1] = (rate * dur) >> 3;
1160 /* 40 MHz, SGI */
1161 rate = MCS_RATE(mcs, true, true);
1162 ampdu->max_txlen[mcs][1][1] = (rate * dur) >> 3;
1163 }
1164 }
1165
1166 void wlc_ampdu_macaddr_upd(struct wlc_info *wlc)
1167 {
1168 char template[T_RAM_ACCESS_SZ * 2];
1169
1170 /* driver needs to write the ta in the template; ta is at offset 16 */
1171 memset(template, 0, sizeof(template));
1172 memcpy(template, wlc->pub->cur_etheraddr, ETH_ALEN);
1173 wlc_write_template_ram(wlc, (T_BA_TPL_BASE + 16), (T_RAM_ACCESS_SZ * 2),
1174 template);
1175 }
1176
1177 bool wlc_aggregatable(struct wlc_info *wlc, u8 tid)
1178 {
1179 return wlc->ampdu->ini_enable[tid];
1180 }
1181
1182 void wlc_ampdu_shm_upd(struct ampdu_info *ampdu)
1183 {
1184 struct wlc_info *wlc = ampdu->wlc;
1185
1186 /* Extend ucode internal watchdog timer to match larger received frames */
1187 if ((ampdu->rx_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) ==
1188 IEEE80211_HT_MAX_AMPDU_64K) {
1189 wlc_write_shm(wlc, M_MIMO_MAXSYM, MIMO_MAXSYM_MAX);
1190 wlc_write_shm(wlc, M_WATCHDOG_8TU, WATCHDOG_8TU_MAX);
1191 } else {
1192 wlc_write_shm(wlc, M_MIMO_MAXSYM, MIMO_MAXSYM_DEF);
1193 wlc_write_shm(wlc, M_WATCHDOG_8TU, WATCHDOG_8TU_DEF);
1194 }
1195 }
1196
1197 /*
1198 * callback function that helps flushing ampdu packets from a priority queue
1199 */
1200 static bool cb_del_ampdu_pkt(struct sk_buff *mpdu, void *arg_a)
1201 {
1202 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(mpdu);
1203 struct cb_del_ampdu_pars *ampdu_pars =
1204 (struct cb_del_ampdu_pars *)arg_a;
1205 bool rc;
1206
1207 rc = tx_info->flags & IEEE80211_TX_CTL_AMPDU ? true : false;
1208 rc = rc && (tx_info->control.sta == NULL || ampdu_pars->sta == NULL ||
1209 tx_info->control.sta == ampdu_pars->sta);
1210 rc = rc && ((u8)(mpdu->priority) == ampdu_pars->tid);
1211 return rc;
1212 }
1213
1214 /*
1215 * callback function that helps invalidating ampdu packets in a DMA queue
1216 */
1217 static void dma_cb_fn_ampdu(void *txi, void *arg_a)
1218 {
1219 struct ieee80211_sta *sta = arg_a;
1220 struct ieee80211_tx_info *tx_info = (struct ieee80211_tx_info *)txi;
1221
1222 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
1223 (tx_info->control.sta == sta || sta == NULL))
1224 tx_info->control.sta = NULL;
1225 }
1226
1227 /*
1228 * When a remote party is no longer available for ampdu communication, any
1229 * pending tx ampdu packets in the driver have to be flushed.
1230 */
1231 void wlc_ampdu_flush(struct wlc_info *wlc,
1232 struct ieee80211_sta *sta, u16 tid)
1233 {
1234 struct wlc_txq_info *qi = wlc->pkt_queue;
1235 struct pktq *pq = &qi->q;
1236 int prec;
1237 struct cb_del_ampdu_pars ampdu_pars;
1238
1239 ampdu_pars.sta = sta;
1240 ampdu_pars.tid = tid;
1241 for (prec = 0; prec < pq->num_prec; prec++) {
1242 brcmu_pktq_pflush(pq, prec, true, cb_del_ampdu_pkt,
1243 (void *)&ampdu_pars);
1244 }
1245 wlc_inval_dma_pkts(wlc->hw, sta, dma_cb_fn_ampdu);
1246 }
This page took 0.080209 seconds and 5 git commands to generate.