2 * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/sysctl.h>
41 #include <sys/malloc.h>
43 #include <sys/mutex.h>
44 #include <sys/kernel.h>
45 #include <sys/socket.h>
46 #include <sys/sockio.h>
47 #include <sys/errno.h>
48 #include <sys/callout.h>
50 #include <sys/endian.h>
51 #include <sys/kthread.h>
52 #include <sys/taskqueue.h>
55 #if defined(__DragonFly__)
58 #include <machine/bus.h>
62 #include <net/if_dl.h>
63 #include <net/if_media.h>
64 #include <net/if_types.h>
65 #include <net/if_arp.h>
66 #include <net/ethernet.h>
67 #include <net/if_llc.h>
69 #include <netproto/802_11/ieee80211_var.h>
70 #include <netproto/802_11/ieee80211_regdomain.h>
71 #ifdef IEEE80211_SUPPORT_SUPERG
72 #include <netproto/802_11/ieee80211_superg.h>
74 #ifdef IEEE80211_SUPPORT_TDMA
75 #include <netproto/802_11/ieee80211_tdma.h>
81 #include <netinet/in.h>
82 #include <netinet/if_ether.h>
85 #include <dev/netif/ath/ath/if_athvar.h>
86 #include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
87 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
90 #include <dev/netif/ath/ath_tx99/ath_tx99.h>
93 #include <dev/netif/ath/ath/if_ath_tx.h> /* XXX for some support functions */
94 #include <dev/netif/ath/ath/if_ath_tx_ht.h>
95 #include <dev/netif/ath/ath/if_athrate.h>
96 #include <dev/netif/ath/ath/if_ath_debug.h>
101 #define IEEE80211_AMPDU_SUBFRAME_DEFAULT 32
103 #define ATH_AGGR_DELIM_SZ 4 /* delimiter size */
104 #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */
105 /* number of delimiters for encryption padding */
106 #define ATH_AGGR_ENCRYPTDELIM 10
109 * returns delimiter padding required given the packet length
111 #define ATH_AGGR_GET_NDELIM(_len) \
112 (((((_len) + ATH_AGGR_DELIM_SZ) < ATH_AGGR_MINPLEN) ? \
113 (ATH_AGGR_MINPLEN - (_len) - ATH_AGGR_DELIM_SZ) : 0) >> 2)
115 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
117 int ath_max_4ms_framelen[4][32] = {
119 3212, 6432, 9648, 12864, 19300, 25736, 28952, 32172,
120 6424, 12852, 19280, 25708, 38568, 51424, 57852, 64280,
121 9628, 19260, 28896, 38528, 57792, 65532, 65532, 65532,
122 12828, 25656, 38488, 51320, 65532, 65532, 65532, 65532,
125 3572, 7144, 10720, 14296, 21444, 28596, 32172, 35744,
126 7140, 14284, 21428, 28568, 42856, 57144, 64288, 65532,
127 10700, 21408, 32112, 42816, 64228, 65532, 65532, 65532,
128 14256, 28516, 42780, 57040, 65532, 65532, 65532, 65532,
131 6680, 13360, 20044, 26724, 40092, 53456, 60140, 65532,
132 13348, 26700, 40052, 53400, 65532, 65532, 65532, 65532,
133 20004, 40008, 60016, 65532, 65532, 65532, 65532, 65532,
134 26644, 53292, 65532, 65532, 65532, 65532, 65532, 65532,
137 7420, 14844, 22272, 29696, 44544, 59396, 65532, 65532,
138 14832, 29668, 44504, 59340, 65532, 65532, 65532, 65532,
139 22232, 44464, 65532, 65532, 65532, 65532, 65532, 65532,
140 29616, 59232, 65532, 65532, 65532, 65532, 65532, 65532,
145 * XXX should be in net80211
147 static int ieee80211_mpdudensity_map[] = {
148 0, /* IEEE80211_HTCAP_MPDUDENSITY_NA */
149 25, /* IEEE80211_HTCAP_MPDUDENSITY_025 */
150 50, /* IEEE80211_HTCAP_MPDUDENSITY_05 */
151 100, /* IEEE80211_HTCAP_MPDUDENSITY_1 */
152 200, /* IEEE80211_HTCAP_MPDUDENSITY_2 */
153 400, /* IEEE80211_HTCAP_MPDUDENSITY_4 */
154 800, /* IEEE80211_HTCAP_MPDUDENSITY_8 */
155 1600, /* IEEE80211_HTCAP_MPDUDENSITY_16 */
159 * XXX should be in the HAL/net80211 ?
161 #define BITS_PER_BYTE 8
162 #define OFDM_PLCP_BITS 22
163 #define HT_RC_2_MCS(_rc) ((_rc) & 0x7f)
164 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
170 #define HT_LTF(_ns) (4 * (_ns))
171 #define SYMBOL_TIME(_ns) ((_ns) << 2) // ns * 4 us
172 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) // ns * 3.6 us
173 #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
174 #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
175 #define IS_HT_RATE(_rate) ((_rate) & 0x80)
177 const uint32_t bits_per_symbol[][2] = {
179 { 26, 54 }, // 0: BPSK
180 { 52, 108 }, // 1: QPSK 1/2
181 { 78, 162 }, // 2: QPSK 3/4
182 { 104, 216 }, // 3: 16-QAM 1/2
183 { 156, 324 }, // 4: 16-QAM 3/4
184 { 208, 432 }, // 5: 64-QAM 2/3
185 { 234, 486 }, // 6: 64-QAM 3/4
186 { 260, 540 }, // 7: 64-QAM 5/6
187 { 52, 108 }, // 8: BPSK
188 { 104, 216 }, // 9: QPSK 1/2
189 { 156, 324 }, // 10: QPSK 3/4
190 { 208, 432 }, // 11: 16-QAM 1/2
191 { 312, 648 }, // 12: 16-QAM 3/4
192 { 416, 864 }, // 13: 64-QAM 2/3
193 { 468, 972 }, // 14: 64-QAM 3/4
194 { 520, 1080 }, // 15: 64-QAM 5/6
195 { 78, 162 }, // 16: BPSK
196 { 156, 324 }, // 17: QPSK 1/2
197 { 234, 486 }, // 18: QPSK 3/4
198 { 312, 648 }, // 19: 16-QAM 1/2
199 { 468, 972 }, // 20: 16-QAM 3/4
200 { 624, 1296 }, // 21: 64-QAM 2/3
201 { 702, 1458 }, // 22: 64-QAM 3/4
202 { 780, 1620 }, // 23: 64-QAM 5/6
203 { 104, 216 }, // 24: BPSK
204 { 208, 432 }, // 25: QPSK 1/2
205 { 312, 648 }, // 26: QPSK 3/4
206 { 416, 864 }, // 27: 16-QAM 1/2
207 { 624, 1296 }, // 28: 16-QAM 3/4
208 { 832, 1728 }, // 29: 64-QAM 2/3
209 { 936, 1944 }, // 30: 64-QAM 3/4
210 { 1040, 2160 }, // 31: 64-QAM 5/6
214 * Fill in the rate array information based on the current
215 * node configuration and the choices made by the rate
216 * selection code and ath_buf setup code.
218 * Later on, this may end up also being made by the
219 * rate control code, but for now it can live here.
221 * This needs to be called just before the packet is
222 * queued to the software queue or hardware queue,
223 * so all of the needed fields in bf_state are setup.
226 ath_tx_rate_fill_rcflags(struct ath_softc *sc, struct ath_buf *bf)
228 struct ieee80211_node *ni = bf->bf_node;
229 struct ieee80211com *ic = ni->ni_ic;
230 const HAL_RATE_TABLE *rt = sc->sc_currates;
231 struct ath_rc_series *rc = bf->bf_state.bfs_rc;
238 * We only do LDPC if the rate is 11n, both we and the
239 * receiver support LDPC and it's enabled.
241 * It's a global flag, not a per-try flag, so we clear
242 * it if any of the rate entries aren't 11n.
245 if ((ni->ni_vap->iv_htcaps & IEEE80211_HTCAP_LDPC) &&
246 (ni->ni_htcap & IEEE80211_HTCAP_LDPC))
250 for (i = 0; i < ATH_RC_NUM; i++) {
252 if (rc[i].tries == 0)
255 rate = rt->info[rc[i].rix].rateCode;
258 * Only enable short preamble for legacy rates
260 if ((! IS_HT_RATE(rate)) && bf->bf_state.bfs_shpream)
261 rate |= rt->info[rc[i].rix].shortPreamble;
264 * Save this, used by the TX and completion code
266 rc[i].ratecode = rate;
268 if (bf->bf_state.bfs_txflags &
269 (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA))
270 rc[i].flags |= ATH_RC_RTSCTS_FLAG;
273 * If we can't do LDPC, don't.
275 if (! IS_HT_RATE(rate))
278 /* Only enable shortgi, 2040, dual-stream if HT is set */
279 if (IS_HT_RATE(rate)) {
280 rc[i].flags |= ATH_RC_HT_FLAG;
282 if (ni->ni_chw == 40)
283 rc[i].flags |= ATH_RC_CW40_FLAG;
285 if (ni->ni_chw == 40 &&
286 ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI40 &&
287 ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40)
288 rc[i].flags |= ATH_RC_SGI_FLAG;
290 if (ni->ni_chw == 20 &&
291 ic->ic_htcaps & IEEE80211_HTCAP_SHORTGI20 &&
292 ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20)
293 rc[i].flags |= ATH_RC_SGI_FLAG;
296 * If we have STBC TX enabled and the receiver
297 * can receive (at least) 1 stream STBC, AND it's
298 * MCS 0-7, AND we have at least two chains enabled,
301 * XXX TODO: .. and the rate is an 11n rate?
303 if (ic->ic_htcaps & IEEE80211_HTCAP_TXSTBC &&
304 ni->ni_vap->iv_flags_ht & IEEE80211_FHT_STBC_TX &&
305 ni->ni_htcap & IEEE80211_HTCAP_RXSTBC_1STREAM &&
306 (sc->sc_cur_txchainmask > 1) &&
307 HT_RC_2_STREAMS(rate) == 1) {
308 rc[i].flags |= ATH_RC_STBC_FLAG;
313 * Dual / Triple stream rate?
315 if (HT_RC_2_STREAMS(rate) == 2)
316 rc[i].flags |= ATH_RC_DS_FLAG;
317 else if (HT_RC_2_STREAMS(rate) == 3)
318 rc[i].flags |= ATH_RC_TS_FLAG;
322 * Calculate the maximum TX power cap for the current
325 rc[i].tx_power_cap = ieee80211_get_node_txpower(ni);
328 * Calculate the maximum 4ms frame length based
329 * on the MCS rate, SGI and channel width flags.
331 if ((rc[i].flags & ATH_RC_HT_FLAG) &&
332 (HT_RC_2_MCS(rate) < 32)) {
334 if (rc[i].flags & ATH_RC_CW40_FLAG) {
335 if (rc[i].flags & ATH_RC_SGI_FLAG)
340 if (rc[i].flags & ATH_RC_SGI_FLAG)
345 rc[i].max4msframelen =
346 ath_max_4ms_framelen[j][HT_RC_2_MCS(rate)];
348 rc[i].max4msframelen = 0;
349 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
350 "%s: i=%d, rate=0x%x, flags=0x%x, max4ms=%d\n",
351 __func__, i, rate, rc[i].flags, rc[i].max4msframelen);
355 * LDPC is a global flag, so ...
358 bf->bf_state.bfs_txflags |= HAL_TXDESC_LDPC;
359 sc->sc_stats.ast_tx_ldpc++;
363 sc->sc_stats.ast_tx_stbc++;
368 * Return the number of delimiters to be added to
369 * meet the minimum required mpdudensity.
371 * Caller should make sure that the rate is HT.
373 * TODO: is this delimiter calculation supposed to be the
374 * total frame length, the hdr length, the data length (including
375 * delimiters, padding, CRC, etc) or ?
377 * TODO: this should ensure that the rate control information
378 * HAS been setup for the first rate.
380 * TODO: ensure this is only called for MCS rates.
382 * TODO: enforce MCS < 31
385 ath_compute_num_delims(struct ath_softc *sc, struct ath_buf *first_bf,
388 const HAL_RATE_TABLE *rt = sc->sc_currates;
389 struct ieee80211_node *ni = first_bf->bf_node;
390 struct ieee80211vap *vap = ni->ni_vap;
391 int ndelim, mindelim = 0;
392 int mpdudensity; /* in 1/100'th of a microsecond */
393 uint8_t rc, rix, flags;
395 uint32_t nsymbits, nsymbols;
399 * vap->iv_ampdu_density is a value, rather than the actual
402 if (vap->iv_ampdu_density > IEEE80211_HTCAP_MPDUDENSITY_16)
403 mpdudensity = 1600; /* maximum density */
405 mpdudensity = ieee80211_mpdudensity_map[vap->iv_ampdu_density];
407 /* Select standard number of delimiters based on frame length */
408 ndelim = ATH_AGGR_GET_NDELIM(pktlen);
411 * If encryption is enabled, add extra delimiters to let the
412 * crypto hardware catch up. This could be tuned per-MAC and
413 * per-rate, but for now we'll simply assume encryption is
416 * Also note that the Atheros reference driver inserts two
417 * delimiters by default for pre-AR9380 peers. This will
418 * include "that" required delimiter.
420 ndelim += ATH_AGGR_ENCRYPTDELIM;
423 * For AR9380, there's a minimum number of delimeters
424 * required when doing RTS.
426 * XXX TODO: this is only needed if (a) RTS/CTS is enabled, and
427 * XXX (b) this is the first sub-frame in the aggregate.
429 if (sc->sc_use_ent && (sc->sc_ent_cfg & AH_ENT_RTSCTS_DELIM_WAR)
430 && ndelim < AH_FIRST_DESC_NDELIMS)
431 ndelim = AH_FIRST_DESC_NDELIMS;
434 * If sc_delim_min_pad is non-zero, enforce it as the minimum
435 * pad delimiter count.
437 if (sc->sc_delim_min_pad != 0)
438 ndelim = MAX(ndelim, sc->sc_delim_min_pad);
440 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
441 "%s: pktlen=%d, ndelim=%d, mpdudensity=%d\n",
442 __func__, pktlen, ndelim, mpdudensity);
445 * If the MPDU density is 0, we can return here.
446 * Otherwise, we need to convert the desired mpdudensity
447 * into a byte length, based on the rate in the subframe.
449 if (mpdudensity == 0)
453 * Convert desired mpdu density from microeconds to bytes based
454 * on highest rate in rate series (i.e. first rate) to determine
455 * required minimum length for subframe. Take into account
456 * whether high rate is 20 or 40Mhz and half or full GI.
458 rix = first_bf->bf_state.bfs_rc[0].rix;
459 rc = rt->info[rix].rateCode;
460 flags = first_bf->bf_state.bfs_rc[0].flags;
461 width = !! (flags & ATH_RC_CW40_FLAG);
462 half_gi = !! (flags & ATH_RC_SGI_FLAG);
465 * mpdudensity is in 1/100th of a usec, so divide by 100
468 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity);
470 nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity);
476 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
477 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
480 * Min length is the minimum frame length for the
481 * required MPDU density.
483 if (pktlen < minlen) {
484 mindelim = (minlen - pktlen) / ATH_AGGR_DELIM_SZ;
485 ndelim = MAX(mindelim, ndelim);
488 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR,
489 "%s: pktlen=%d, minlen=%d, rix=%x, rc=%x, width=%d, hgi=%d, ndelim=%d\n",
490 __func__, pktlen, minlen, rix, rc, width, half_gi, ndelim);
496 * Fetch the aggregation limit.
498 * It's the lowest of the four rate series 4ms frame length.
501 ath_get_aggr_limit(struct ath_softc *sc, struct ath_buf *bf)
503 int amin = ATH_AGGR_MAXSIZE;
506 if (sc->sc_aggr_limit > 0 && sc->sc_aggr_limit < ATH_AGGR_MAXSIZE)
507 amin = sc->sc_aggr_limit;
509 for (i = 0; i < ATH_RC_NUM; i++) {
510 if (bf->bf_state.bfs_rc[i].tries == 0)
512 amin = MIN(amin, bf->bf_state.bfs_rc[i].max4msframelen);
515 DPRINTF(sc, ATH_DEBUG_SW_TX_AGGR, "%s: max frame len= %d\n",
522 * Setup a 11n rate series structure
524 * This should be called for both legacy and MCS rates.
526 * This uses the rate series stuf from ath_tx_rate_fill_rcflags().
528 * It, along with ath_buf_set_rate, must be called -after- a burst
529 * or aggregate is setup.
532 ath_rateseries_setup(struct ath_softc *sc, struct ieee80211_node *ni,
533 struct ath_buf *bf, HAL_11N_RATE_SERIES *series)
535 struct ieee80211com *ic = ni->ni_ic;
536 struct ath_hal *ah = sc->sc_ah;
537 HAL_BOOL shortPreamble = AH_FALSE;
538 const HAL_RATE_TABLE *rt = sc->sc_currates;
541 struct ath_rc_series *rc = bf->bf_state.bfs_rc;
543 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
544 (ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE))
545 shortPreamble = AH_TRUE;
548 * If this is the first frame in an aggregate series,
549 * use the aggregate length.
551 if (bf->bf_state.bfs_aggr)
552 pktlen = bf->bf_state.bfs_al;
554 pktlen = bf->bf_state.bfs_pktlen;
557 * XXX TODO: modify this routine to use the bfs_rc[x].flags
560 memset(series, 0, sizeof(HAL_11N_RATE_SERIES) * 4);
561 for (i = 0; i < ATH_RC_NUM; i++) {
562 /* Only set flags for actual TX attempts */
563 if (rc[i].tries == 0)
566 series[i].Tries = rc[i].tries;
569 * XXX TODO: When the NIC is capable of three stream TX,
570 * transmit 1/2 stream rates on two streams.
572 * This reduces the power consumption of the NIC and
573 * keeps it within the PCIe slot power limits.
575 series[i].ChSel = sc->sc_cur_txchainmask;
578 * Setup rate and TX power cap for this series.
580 series[i].Rate = rt->info[rc[i].rix].rateCode;
581 series[i].RateIndex = rc[i].rix;
582 series[i].tx_power_cap = rc[i].tx_power_cap;
585 * Enable RTS/CTS as appropriate.
587 if (rc[i].flags & ATH_RC_RTSCTS_FLAG)
588 series[i].RateFlags |= HAL_RATESERIES_RTS_CTS;
591 * 11n rate? Update 11n flags.
593 if (rc[i].flags & ATH_RC_HT_FLAG) {
594 if (rc[i].flags & ATH_RC_CW40_FLAG)
595 series[i].RateFlags |= HAL_RATESERIES_2040;
597 if (rc[i].flags & ATH_RC_SGI_FLAG)
598 series[i].RateFlags |= HAL_RATESERIES_HALFGI;
600 if (rc[i].flags & ATH_RC_STBC_FLAG)
601 series[i].RateFlags |= HAL_RATESERIES_STBC;
605 * TODO: If we're all doing 11n rates then we can set LDPC.
606 * If we've been asked to /do/ LDPC but we are handed a
607 * legacy rate, then we should complain. Loudly.
611 * PktDuration doesn't include slot, ACK, RTS, etc timing -
612 * it's just the packet duration
614 if (rc[i].flags & ATH_RC_HT_FLAG) {
615 series[i].PktDuration =
616 ath_computedur_ht(pktlen
618 , HT_RC_2_STREAMS(series[i].Rate)
619 , series[i].RateFlags & HAL_RATESERIES_2040
620 , series[i].RateFlags & HAL_RATESERIES_HALFGI);
624 rt->info[rc[i].rix].shortPreamble;
625 series[i].PktDuration = ath_hal_computetxtime(ah,
626 rt, pktlen, rc[i].rix, shortPreamble);
633 ath_rateseries_print(struct ath_softc *sc, HAL_11N_RATE_SERIES *series)
636 for (i = 0; i < ATH_RC_NUM; i++) {
637 device_printf(sc->sc_dev ,"series %d: rate %x; tries %d; "
638 "pktDuration %d; chSel %d; txpowcap %d, rateFlags %x\n",
642 series[i].PktDuration,
644 series[i].tx_power_cap,
645 series[i].RateFlags);
651 * Setup the 11n rate scenario and burst duration for the given TX descriptor
654 * This isn't useful for sending beacon frames, which has different needs
655 * wrt what's passed into the rate scenario function.
658 ath_buf_set_rate(struct ath_softc *sc, struct ieee80211_node *ni,
661 HAL_11N_RATE_SERIES series[4];
662 struct ath_desc *ds = bf->bf_desc;
663 struct ath_hal *ah = sc->sc_ah;
664 int is_pspoll = (bf->bf_state.bfs_atype == HAL_PKT_TYPE_PSPOLL);
665 int ctsrate = bf->bf_state.bfs_ctsrate;
666 int flags = bf->bf_state.bfs_txflags;
668 /* Setup rate scenario */
669 memset(&series, 0, sizeof(series));
671 ath_rateseries_setup(sc, ni, bf, series);
674 if (sc->sc_debug & ATH_DEBUG_XMIT)
675 ath_rateseries_print(sc, series);
678 /* Set rate scenario */
680 * Note: Don't allow hardware to override the duration on
683 ath_hal_set11nratescenario(ah, ds,
684 !is_pspoll, /* whether to override the duration or not */
685 ctsrate, /* rts/cts rate */
686 series, /* 11n rate series */
687 4, /* number of series */
690 /* Set burst duration */
692 * This is only required when doing 11n burst, not aggregation
693 * ie, if there's a second frame in a RIFS or A-MPDU burst
694 * w/ >1 A-MPDU frame bursting back to back.
695 * Normal A-MPDU doesn't do bursting -between- aggregates.
697 * .. and it's highly likely this won't ever be implemented
699 //ath_hal_set11nburstduration(ah, ds, 8192);
703 * Form an aggregate packet list.
705 * This function enforces the aggregate restrictions/requirements.
709 * + The aggregate size maximum (64k for AR9160 and later, 8K for
710 * AR5416 when doing RTS frame protection.)
711 * + Maximum number of sub-frames for an aggregate
712 * + The aggregate delimiter size, giving MACs time to do whatever is
713 * needed before each frame
714 * + Enforce the BAW limit
716 * Each descriptor queued should have the DMA setup.
717 * The rate series, descriptor setup, linking, etc is all done
718 * externally. This routine simply chains them together.
719 * ath_tx_setds_11n() will take care of configuring the per-
720 * descriptor setup, and ath_buf_set_rate() will configure the
723 * The TID lock is required for the entirety of this function.
725 * If some code in another thread adds to the head of this
726 * list, very strange behaviour will occur. Since retransmission is the
727 * only reason this will occur, and this routine is designed to be called
728 * from within the scheduler task, it won't ever clash with the completion
731 * So if you want to call this from an upper layer context (eg, to direct-
732 * dispatch aggregate frames to the hardware), please keep this in mind.
735 ath_tx_form_aggr(struct ath_softc *sc, struct ath_node *an,
736 struct ath_tid *tid, ath_bufhead *bf_q)
738 //struct ieee80211_node *ni = &an->an_node;
739 struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
741 uint16_t aggr_limit = 0, al = 0, bpad = 0, al_delta, h_baw;
742 struct ieee80211_tx_ampdu *tap;
743 int status = ATH_AGGR_DONE;
744 int prev_frames = 0; /* XXX for AR5416 burst, not done here */
745 int prev_al = 0; /* XXX also for AR5416 burst */
747 ATH_TX_LOCK_ASSERT(sc);
749 tap = ath_tx_get_tx_tid(an, tid->tid);
751 status = ATH_AGGR_ERROR;
755 h_baw = tap->txa_wnd / 2;
758 bf = ATH_TID_FIRST(tid);
759 if (bf_first == NULL)
762 status = ATH_AGGR_DONE;
766 * It's the first frame;
767 * set the aggregation limit based on the
768 * rate control decision that has been made.
770 aggr_limit = ath_get_aggr_limit(sc, bf_first);
773 /* Set this early just so things don't get confused */
777 * If the frame doesn't have a sequence number that we're
778 * tracking in the BAW (eg NULL QOS data frame), we can't
779 * aggregate it. Stop the aggregation process; the sender
780 * can then TX what's in the list thus far and then
781 * TX the frame individually.
783 if (! bf->bf_state.bfs_dobaw) {
784 status = ATH_AGGR_NONAGGR;
789 * If any of the rates are non-HT, this packet
790 * can't be aggregated.
791 * XXX TODO: add a bf_state flag which gets marked
792 * if any active rate is non-HT.
796 * do not exceed aggregation limit
798 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_state.bfs_pktlen;
800 (aggr_limit < (al + bpad + al_delta + prev_al))) {
801 status = ATH_AGGR_LIMITED;
806 * If RTS/CTS is set on the first frame, enforce
807 * the RTS aggregate limit.
809 if (bf_first->bf_state.bfs_txflags &
810 (HAL_TXDESC_CTSENA | HAL_TXDESC_RTSENA)) {
812 (sc->sc_rts_aggr_limit <
813 (al + bpad + al_delta + prev_al))) {
814 status = ATH_AGGR_8K_LIMITED;
820 * Do not exceed subframe limit.
822 if ((nframes + prev_frames) >= MIN((h_baw),
823 IEEE80211_AMPDU_SUBFRAME_DEFAULT)) {
824 status = ATH_AGGR_LIMITED;
829 * If the current frame has an RTS/CTS configuration
830 * that differs from the first frame, override the
831 * subsequent frame with this config.
833 if (bf != bf_first) {
834 bf->bf_state.bfs_txflags &=
835 ~ (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA);
836 bf->bf_state.bfs_txflags |=
837 bf_first->bf_state.bfs_txflags &
838 (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA);
842 * If the packet has a sequence number, do not
843 * step outside of the block-ack window.
845 if (! BAW_WITHIN(tap->txa_start, tap->txa_wnd,
846 SEQNO(bf->bf_state.bfs_seqno))) {
847 status = ATH_AGGR_BAW_CLOSED;
852 * this packet is part of an aggregate.
854 ATH_TID_REMOVE(tid, bf, bf_list);
856 /* The TID lock is required for the BAW update */
857 ath_tx_addto_baw(sc, an, tid, bf);
858 bf->bf_state.bfs_addedbaw = 1;
861 * XXX enforce ACK for aggregate frames (this needs to be
862 * XXX handled more gracefully?
864 if (bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) {
865 device_printf(sc->sc_dev,
866 "%s: HAL_TXDESC_NOACK set for an aggregate frame?\n",
868 bf->bf_state.bfs_txflags &= (~HAL_TXDESC_NOACK);
872 * Add the now owned buffer (which isn't
873 * on the software TXQ any longer) to our
874 * aggregate frame list.
876 TAILQ_INSERT_TAIL(bf_q, bf, bf_list);
879 /* Completion handler */
880 bf->bf_comp = ath_tx_aggr_comp;
883 * add padding for previous frame to aggregation length
885 al += bpad + al_delta;
888 * Calculate delimiters needed for the current frame
890 bf->bf_state.bfs_ndelim =
891 ath_compute_num_delims(sc, bf_first,
892 bf->bf_state.bfs_pktlen);
895 * Calculate the padding needed from this set of delimiters,
896 * used when calculating if the next frame will fit in
899 bpad = PADBYTES(al_delta) + (bf->bf_state.bfs_ndelim << 2);
902 * Chain the buffers together
905 bf_prev->bf_next = bf;
909 * If we're leaking frames, just return at this point;
910 * we've queued a single frame and we don't want to add
913 if (tid->an->an_leak_count) {
914 status = ATH_AGGR_LEAK_CLOSED;
920 * terminate aggregation on a small packet boundary
922 if (bf->bf_state.bfs_pktlen < ATH_AGGR_MINPLEN) {
923 status = ATH_AGGR_SHORTPKT;
932 * Just in case the list was empty when we tried to
933 * dequeue a packet ..
936 bf_first->bf_state.bfs_al = al;
937 bf_first->bf_state.bfs_nframes = nframes;