2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "ah_internal.h"
27 #include "ar5416/ar5416.h"
28 #include "ar5416/ar5416reg.h"
29 #include "ar5416/ar5416phy.h"
30 #include "ar5416/ar5416desc.h"
33 * Stop transmit on the specified queue
36 ar5416StopTxDma(struct ath_hal *ah, u_int q)
38 #define STOP_DMA_TIMEOUT 4000 /* us */
39 #define STOP_DMA_ITER 100 /* us */
42 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
44 HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
46 OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
47 for (i = STOP_DMA_TIMEOUT/STOP_DMA_ITER; i != 0; i--) {
48 if (ar5212NumTxPending(ah, q) == 0)
50 OS_DELAY(STOP_DMA_ITER);
54 HALDEBUG(ah, HAL_DEBUG_ANY,
55 "%s: queue %u DMA did not stop in 400 msec\n", __func__, q);
56 HALDEBUG(ah, HAL_DEBUG_ANY,
57 "%s: QSTS 0x%x Q_TXE 0x%x Q_TXD 0x%x Q_CBR 0x%x\n", __func__,
58 OS_REG_READ(ah, AR_QSTS(q)), OS_REG_READ(ah, AR_Q_TXE),
59 OS_REG_READ(ah, AR_Q_TXD), OS_REG_READ(ah, AR_QCBRCFG(q)));
60 HALDEBUG(ah, HAL_DEBUG_ANY,
61 "%s: Q_MISC 0x%x Q_RDYTIMECFG 0x%x Q_RDYTIMESHDN 0x%x\n",
62 __func__, OS_REG_READ(ah, AR_QMISC(q)),
63 OS_REG_READ(ah, AR_QRDYTIMECFG(q)),
64 OS_REG_READ(ah, AR_Q_RDYTIMESHDN));
68 /* ar5416 and up can kill packets at the PCU level */
69 if (ar5212NumTxPending(ah, q)) {
72 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
73 "%s: Num of pending TX Frames %d on Q %d\n",
74 __func__, ar5212NumTxPending(ah, q), q);
76 /* Kill last PCU Tx Frame */
77 /* TODO - save off and restore current values of Q1/Q2? */
78 for (j = 0; j < 2; j++) {
79 uint32_t tsfLow = OS_REG_READ(ah, AR_TSF_L32);
80 OS_REG_WRITE(ah, AR_QUIET2,
81 SM(10, AR_QUIET2_QUIET_DUR));
82 OS_REG_WRITE(ah, AR_QUIET_PERIOD, 100);
83 OS_REG_WRITE(ah, AR_NEXT_QUIET, tsfLow >> 10);
84 OS_REG_SET_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);
86 if ((OS_REG_READ(ah, AR_TSF_L32)>>10) == (tsfLow>>10))
89 HALDEBUG(ah, HAL_DEBUG_ANY,
90 "%s: TSF moved while trying to set quiet time "
91 "TSF: 0x%08x\n", __func__, tsfLow);
92 HALASSERT(j < 1); /* TSF shouldn't count twice or reg access is taking forever */
95 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);
97 /* Allow the quiet mechanism to do its work */
99 OS_REG_CLR_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);
101 /* Verify the transmit q is empty */
102 for (i = STOP_DMA_TIMEOUT/STOP_DMA_ITER; i != 0; i--) {
103 if (ar5212NumTxPending(ah, q) == 0)
105 OS_DELAY(STOP_DMA_ITER);
108 HALDEBUG(ah, HAL_DEBUG_ANY,
109 "%s: Failed to stop Tx DMA in %d msec after killing"
110 " last frame\n", __func__, STOP_DMA_TIMEOUT / 1000);
112 OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);
115 OS_REG_WRITE(ah, AR_Q_TXD, 0);
118 #undef STOP_DMA_TIMEOUT
121 #define VALID_KEY_TYPES \
122 ((1 << HAL_KEY_TYPE_CLEAR) | (1 << HAL_KEY_TYPE_WEP)|\
123 (1 << HAL_KEY_TYPE_AES) | (1 << HAL_KEY_TYPE_TKIP))
124 #define isValidKeyType(_t) ((1 << (_t)) & VALID_KEY_TYPES)
126 #define set11nTries(_series, _index) \
127 (SM((_series)[_index].Tries, AR_XmitDataTries##_index))
129 #define set11nRate(_series, _index) \
130 (SM((_series)[_index].Rate, AR_XmitRate##_index))
132 #define set11nPktDurRTSCTS(_series, _index) \
133 (SM((_series)[_index].PktDuration, AR_PacketDur##_index) |\
134 ((_series)[_index].RateFlags & HAL_RATESERIES_RTS_CTS ?\
135 AR_RTSCTSQual##_index : 0))
137 #define set11nRateFlags(_series, _index) \
138 ((_series)[_index].RateFlags & HAL_RATESERIES_2040 ? AR_2040_##_index : 0) \
139 |((_series)[_index].RateFlags & HAL_RATESERIES_HALFGI ? AR_GI##_index : 0) \
140 |((_series)[_index].RateFlags & HAL_RATESERIES_STBC ? AR_STBC##_index : 0) \
141 |SM((_series)[_index].ChSel, AR_ChainSel##_index)
144 * Descriptor Access Functions
147 #define VALID_PKT_TYPES \
148 ((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\
149 (1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\
150 (1<<HAL_PKT_TYPE_BEACON)|(1<<HAL_PKT_TYPE_AMPDU))
151 #define isValidPktType(_t) ((1<<(_t)) & VALID_PKT_TYPES)
152 #define VALID_TX_RATES \
153 ((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\
154 (1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\
155 (1<<0x1d)|(1<<0x18)|(1<<0x1c)|(1<<0x01)|(1<<0x02)|(1<<0x03)|\
156 (1<<0x04)|(1<<0x05)|(1<<0x06)|(1<<0x07)|(1<<0x00))
157 /* NB: accept HT rates */
158 #define isValidTxRate(_r) ((1<<((_r) & 0x7f)) & VALID_TX_RATES)
161 ar5416RateToRateTable(struct ath_hal *ah, uint8_t rate, HAL_BOOL is_ht40)
165 * Handle the non-MCS rates
168 case /* 1 Mb */ 0x1b:
169 case /* 1 MbS*/ 0x1b | 0x4:
170 return (AH5416(ah)->ah_ratesArray[rate1l]);
171 case /* 2 Mb */ 0x1a:
172 return (AH5416(ah)->ah_ratesArray[rate2l]);
173 case /* 2 MbS*/ 0x1a | 0x4:
174 return (AH5416(ah)->ah_ratesArray[rate2s]);
175 case /* 5.5 Mb */ 0x19:
176 return (AH5416(ah)->ah_ratesArray[rate5_5l]);
177 case /* 5.5 MbS*/ 0x19 | 0x4:
178 return (AH5416(ah)->ah_ratesArray[rate5_5s]);
179 case /* 11 Mb */ 0x18:
180 return (AH5416(ah)->ah_ratesArray[rate11l]);
181 case /* 11 MbS*/ 0x18 | 0x4:
182 return (AH5416(ah)->ah_ratesArray[rate11s]);
187 case /* 6 Mb */ 0x0b:
188 return (AH5416(ah)->ah_ratesArray[rate6mb]);
189 case /* 9 Mb */ 0x0f:
190 return (AH5416(ah)->ah_ratesArray[rate9mb]);
191 case /* 12 Mb */ 0x0a:
192 return (AH5416(ah)->ah_ratesArray[rate12mb]);
193 case /* 18 Mb */ 0x0e:
194 return (AH5416(ah)->ah_ratesArray[rate18mb]);
195 case /* 24 Mb */ 0x09:
196 return (AH5416(ah)->ah_ratesArray[rate24mb]);
197 case /* 36 Mb */ 0x0d:
198 return (AH5416(ah)->ah_ratesArray[rate36mb]);
199 case /* 48 Mb */ 0x08:
200 return (AH5416(ah)->ah_ratesArray[rate48mb]);
201 case /* 54 Mb */ 0x0c:
202 return (AH5416(ah)->ah_ratesArray[rate54mb]);
206 * Handle HT20/HT40 - we only have to do MCS0-7;
207 * there's no stream differences.
209 if ((rate & 0x80) && is_ht40) {
210 return (AH5416(ah)->ah_ratesArray[rateHt40_0 + (rate & 0x7)]);
211 } else if (rate & 0x80) {
212 return (AH5416(ah)->ah_ratesArray[rateHt20_0 + (rate & 0x7)]);
215 /* XXX default (eg XR, bad bad person!) */
216 return (AH5416(ah)->ah_ratesArray[rate6mb]);
220 * Return the TX power to be used for the given rate/chains/TX power.
222 * There are a bunch of tweaks to make to a given TX power based on
223 * the current configuration, so...
226 ar5416GetTxRatePower(struct ath_hal *ah, uint8_t rate, uint8_t tx_chainmask,
227 uint16_t txPower, HAL_BOOL is_ht40)
229 int n_txpower, max_txpower;
230 const int cck_ofdm_delta = 2;
231 #define EEP_MINOR(_ah) \
232 (AH_PRIVATE(_ah)->ah_eeversion & AR5416_EEP_VER_MINOR_MASK)
233 #define IS_EEP_MINOR_V2(_ah) (EEP_MINOR(_ah) >= AR5416_EEP_MINOR_VER_2)
235 /* Take a copy ; we may underflow and thus need to clamp things */
238 /* HT40? Need to adjust the TX power by this */
240 n_txpower += AH5416(ah)->ah_ht40PowerIncForPdadc;
243 * Merlin? Offset the target TX power offset - it defaults to
244 * starting at -5.0dBm, but that can change!
246 * Kiwi/Kite? Always -5.0dBm offset.
248 if (AR_SREV_KIWI_10_OR_LATER(ah)) {
249 n_txpower -= (AR5416_PWR_TABLE_OFFSET_DB * 2);
250 } else if (AR_SREV_MERLIN_20_OR_LATER(ah)) {
251 int8_t pwr_table_offset = 0;
252 /* This is in dBm, convert to 1/2 dBm */
253 (void) ath_hal_eepromGet(ah, AR_EEP_PWR_TABLE_OFFSET,
255 n_txpower -= (pwr_table_offset * 2);
259 * If Open-loop TX power control is used, the CCK rates need
260 * to be offset by that.
262 * Rates: 2S, 2L, 1S, 1L, 5.5S, 5.5L
264 * XXX Odd, we don't have a PHY table entry for long preamble
267 if (AR_SREV_MERLIN_20_OR_LATER(ah) &&
268 ath_hal_eepromGetFlag(ah, AR_EEP_OL_PWRCTRL)) {
270 if (rate == 0x19 || rate == 0x1a || rate == 0x1b ||
271 rate == (0x19 | 0x04) || rate == (0x1a | 0x04) ||
272 rate == (0x1b | 0x04)) {
273 n_txpower -= cck_ofdm_delta;
278 * We're now offset by the same amount that the static maximum
279 * PHY power tables are. So, clamp the value based on that rate.
281 max_txpower = ar5416RateToRateTable(ah, rate, is_ht40);
283 ath_hal_printf(ah, "%s: n_txpower = %d, max_txpower = %d, "
284 "rate = 0x%x , is_ht40 = %d\n",
291 n_txpower = MIN(max_txpower, n_txpower);
294 * We don't have to offset the TX power for two or three
295 * chain operation here - it's done by the AR_PHY_POWER_TX_SUB
296 * register setting via the EEPROM.
298 * So for vendors that programmed the maximum target power assuming
299 * that 2/3 chains are always on, things will just plain work.
300 * (They won't reach that target power if only one chain is on, but
301 * that's a different problem.)
304 /* Over/underflow? Adjust */
307 else if (n_txpower > 63)
311 * For some odd reason the AR9160 with txpower=0 results in a
312 * much higher (max?) TX power. So, if it's a chipset before
313 * AR9220/AR9280, just clamp the minimum value at 1.
315 if ((! AR_SREV_MERLIN_10_OR_LATER(ah)) && (n_txpower == 0))
320 #undef IS_EEP_MINOR_V2
324 ar5416SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,
329 u_int txRate0, u_int txTries0,
334 u_int rtsctsDuration,
339 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
340 struct ar5416_desc *ads = AR5416DESC(ds);
341 struct ath_hal_5416 *ahp = AH5416(ah);
345 HALASSERT(txTries0 != 0);
346 HALASSERT(isValidPktType(type));
347 HALASSERT(isValidTxRate(txRate0));
348 HALASSERT((flags & RTSCTS) != RTSCTS);
349 /* XXX validate antMode */
351 txPower = (txPower + AH5212(ah)->ah_txPowerIndexOffset);
356 * XXX For now, just assume that this isn't a HT40 frame.
357 * It'll get over-ridden by the multi-rate TX power setup.
359 if (AH5212(ah)->ah_tpcEnabled) {
360 txPower = ar5416GetTxRatePower(ah, txRate0,
361 ahp->ah_tx_chainmask,
366 ads->ds_ctl0 = (pktLen & AR_FrameLen)
367 | (txPower << AR_XmitPower_S)
368 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
369 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
370 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0)
372 ads->ds_ctl1 = (type << AR_FrameType_S)
373 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
374 | (flags & HAL_TXDESC_HWTS ? AR_InsertTS : 0)
376 ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0)
377 | (flags & HAL_TXDESC_DURENA ? AR_DurUpdateEn : 0)
379 ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S)
384 ads->ds_ctl7 = SM(ahp->ah_tx_chainmask, AR_ChainSel0)
385 | SM(ahp->ah_tx_chainmask, AR_ChainSel1)
386 | SM(ahp->ah_tx_chainmask, AR_ChainSel2)
387 | SM(ahp->ah_tx_chainmask, AR_ChainSel3)
389 ads->ds_ctl8 = SM(0, AR_AntCtl0);
390 ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);
391 ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);
392 ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);
394 if (keyIx != HAL_TXKEYIX_INVALID) {
395 /* XXX validate key index */
396 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
397 ads->ds_ctl0 |= AR_DestIdxValid;
398 ads->ds_ctl6 |= SM(ahp->ah_keytype[keyIx], AR_EncrType);
400 if (flags & RTSCTS) {
401 if (!isValidTxRate(rtsctsRate)) {
402 HALDEBUG(ah, HAL_DEBUG_ANY,
403 "%s: invalid rts/cts rate 0x%x\n",
404 __func__, rtsctsRate);
407 /* XXX validate rtsctsDuration */
408 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
409 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0)
411 ads->ds_ctl7 |= (rtsctsRate << AR_RTSCTSRate_S);
415 * Set the TX antenna to 0 for Kite
416 * To preserve existing behaviour, also set the TPC bits to 0;
417 * when TPC is enabled these should be filled in appropriately.
419 * XXX TODO: when doing TPC, set the TX power up appropriately?
421 if (AR_SREV_KITE(ah)) {
422 ads->ds_ctl8 = SM(0, AR_AntCtl0);
423 ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(0, AR_XmitPower1);
424 ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(0, AR_XmitPower2);
425 ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(0, AR_XmitPower3);
432 ar5416SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,
433 u_int txRate1, u_int txTries1,
434 u_int txRate2, u_int txTries2,
435 u_int txRate3, u_int txTries3)
437 struct ar5416_desc *ads = AR5416DESC(ds);
440 HALASSERT(isValidTxRate(txRate1));
441 ads->ds_ctl2 |= SM(txTries1, AR_XmitDataTries1);
442 ads->ds_ctl3 |= (txRate1 << AR_XmitRate1_S);
445 HALASSERT(isValidTxRate(txRate2));
446 ads->ds_ctl2 |= SM(txTries2, AR_XmitDataTries2);
447 ads->ds_ctl3 |= (txRate2 << AR_XmitRate2_S);
450 HALASSERT(isValidTxRate(txRate3));
451 ads->ds_ctl2 |= SM(txTries3, AR_XmitDataTries3);
452 ads->ds_ctl3 |= (txRate3 << AR_XmitRate3_S);
458 * XXX TODO: Figure out if AR_InsertTS is required on all sub-frames
459 * of a TX descriptor.
462 ar5416FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,
463 HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList, u_int descId,
464 u_int qcuId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
465 const struct ath_desc *ds0)
467 struct ar5416_desc *ads = AR5416DESC(ds);
468 uint32_t segLen = segLenList[0];
470 HALASSERT((segLen &~ AR_BufLen) == 0);
472 ds->ds_data = bufAddrList[0];
476 * First descriptor, don't clobber xmit control data
477 * setup by ar5212SetupTxDesc.
479 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
480 } else if (lastSeg) { /* !firstSeg && lastSeg */
482 * Last descriptor in a multi-descriptor frame,
483 * copy the multi-rate transmit parameters from
484 * the first frame for processing on completion.
486 ads->ds_ctl1 = segLen;
487 #ifdef AH_NEED_DESC_SWAP
488 ads->ds_ctl0 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl0)
490 ads->ds_ctl2 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl2);
491 ads->ds_ctl3 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl3);
492 /* ctl6 - we only need encrtype; the rest are blank */
493 ads->ds_ctl6 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType);
495 ads->ds_ctl0 = AR5416DESC_CONST(ds0)->ds_ctl0 & AR_TxIntrReq;
496 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
497 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
498 /* ctl6 - we only need encrtype; the rest are blank */
499 ads->ds_ctl6 = AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType;
501 } else { /* !firstSeg && !lastSeg */
503 * Intermediate descriptor in a multi-descriptor frame.
505 #ifdef AH_NEED_DESC_SWAP
506 ads->ds_ctl0 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl0)
508 ads->ds_ctl6 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType);
510 ads->ds_ctl0 = AR5416DESC_CONST(ds0)->ds_ctl0 & AR_TxIntrReq;
511 ads->ds_ctl6 = AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType;
513 ads->ds_ctl1 = segLen | AR_TxMore;
517 /* XXX only on last descriptor? */
518 OS_MEMZERO(ads->u.tx.status, sizeof(ads->u.tx.status));
523 * NB: cipher is no longer used, it's calculated.
526 ar5416ChainTxDesc(struct ath_hal *ah, struct ath_desc *ds,
527 HAL_DMA_ADDR *bufAddrList,
528 uint32_t *segLenList,
539 struct ar5416_desc *ads = AR5416DESC(ds);
540 uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);
541 struct ath_hal_5416 *ahp = AH5416(ah);
542 u_int segLen = segLenList[0];
545 uint32_t last_aggr = 0;
550 HALASSERT((segLen &~ AR_BufLen) == 0);
551 ds->ds_data = bufAddrList[0];
553 HALASSERT(isValidPktType(type));
554 if (type == HAL_PKT_TYPE_AMPDU) {
555 type = HAL_PKT_TYPE_NORMAL;
557 if (lastAggr == AH_FALSE)
558 last_aggr = AR_MoreAggr;
562 * Since this function is called before any of the other
563 * descriptor setup functions (at least in this particular
564 * 802.11n aggregation implementation), always bzero() the
565 * descriptor. Previously this would be done for all but
567 * XXX TODO: figure out why; perhaps I'm using this slightly
570 OS_MEMZERO(ds->ds_hw, AR5416_DESC_TX_CTL_SZ);
573 * Note: VEOL should only be for the last descriptor in the chain.
575 ads->ds_ctl0 = (pktLen & AR_FrameLen);
579 * + IsAggr must be set for all descriptors of all subframes of
581 * + MoreAggr must be set for all descriptors of all subframes
582 * of the aggregate EXCEPT the last subframe;
583 * + MoreAggr must be _CLEAR_ for all descrpitors of the last
584 * subframe of the aggregate.
586 ads->ds_ctl1 = (type << AR_FrameType_S)
587 | (isaggr ? (AR_IsAggr | last_aggr) : 0);
591 if (keyIx != HAL_TXKEYIX_INVALID) {
592 /* XXX validate key index */
593 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
594 ads->ds_ctl0 |= AR_DestIdxValid;
597 ads->ds_ctl6 |= SM(ahp->ah_keytype[keyIx], AR_EncrType);
599 ads->ds_ctl6 |= SM(delims, AR_PadDelim);
603 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
604 } else if (lastSeg) { /* !firstSeg && lastSeg */
606 ads->ds_ctl1 |= segLen;
607 } else { /* !firstSeg && !lastSeg */
609 * Intermediate descriptor in a multi-descriptor frame.
612 ads->ds_ctl1 |= segLen | AR_TxMore;
614 ds_txstatus[0] = ds_txstatus[1] = 0;
615 ds_txstatus[9] &= ~AR_TxDone;
621 ar5416SetupFirstTxDesc(struct ath_hal *ah, struct ath_desc *ds,
622 u_int aggrLen, u_int flags, u_int txPower,
623 u_int txRate0, u_int txTries0, u_int antMode,
624 u_int rtsctsRate, u_int rtsctsDuration)
626 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
627 struct ar5416_desc *ads = AR5416DESC(ds);
628 struct ath_hal_5212 *ahp = AH5212(ah);
630 HALASSERT(txTries0 != 0);
631 HALASSERT(isValidTxRate(txRate0));
632 HALASSERT((flags & RTSCTS) != RTSCTS);
633 /* XXX validate antMode */
635 txPower = (txPower + ahp->ah_txPowerIndexOffset );
636 if(txPower > 63) txPower=63;
638 ads->ds_ctl0 |= (txPower << AR_XmitPower_S)
639 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
640 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
641 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0);
642 ads->ds_ctl1 |= (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0);
643 ads->ds_ctl2 |= SM(txTries0, AR_XmitDataTries0);
644 ads->ds_ctl3 |= (txRate0 << AR_XmitRate0_S);
645 ads->ds_ctl7 = SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel0)
646 | SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel1)
647 | SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel2)
648 | SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel3);
651 ads->ds_ctl8 = SM(0, AR_AntCtl0);
652 ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);
653 ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);
654 ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);
656 ads->ds_ctl6 &= ~(0xffff);
657 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
659 if (flags & RTSCTS) {
660 /* XXX validate rtsctsDuration */
661 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
662 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0);
666 * Set the TX antenna to 0 for Kite
667 * To preserve existing behaviour, also set the TPC bits to 0;
668 * when TPC is enabled these should be filled in appropriately.
670 if (AR_SREV_KITE(ah)) {
671 ads->ds_ctl8 = SM(0, AR_AntCtl0);
672 ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(0, AR_XmitPower1);
673 ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(0, AR_XmitPower2);
674 ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(0, AR_XmitPower3);
682 ar5416SetupLastTxDesc(struct ath_hal *ah, struct ath_desc *ds,
683 const struct ath_desc *ds0)
685 struct ar5416_desc *ads = AR5416DESC(ds);
687 ads->ds_ctl1 &= ~AR_MoreAggr;
688 ads->ds_ctl6 &= ~AR_PadDelim;
690 /* hack to copy rate info to last desc for later processing */
691 #ifdef AH_NEED_DESC_SWAP
692 ads->ds_ctl2 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl2);
693 ads->ds_ctl3 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl3);
695 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
696 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
701 #ifdef AH_NEED_DESC_SWAP
702 /* Swap transmit descriptor */
704 ar5416SwapTxDesc(struct ath_desc *ds)
706 ds->ds_data = __bswap32(ds->ds_data);
707 ds->ds_ctl0 = __bswap32(ds->ds_ctl0);
708 ds->ds_ctl1 = __bswap32(ds->ds_ctl1);
709 ds->ds_hw[0] = __bswap32(ds->ds_hw[0]);
710 ds->ds_hw[1] = __bswap32(ds->ds_hw[1]);
711 ds->ds_hw[2] = __bswap32(ds->ds_hw[2]);
712 ds->ds_hw[3] = __bswap32(ds->ds_hw[3]);
717 * Processing of HW TX descriptor.
720 ar5416ProcTxDesc(struct ath_hal *ah,
721 struct ath_desc *ds, struct ath_tx_status *ts)
723 struct ar5416_desc *ads = AR5416DESC(ds);
724 uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);
726 #ifdef AH_NEED_DESC_SWAP
727 if ((ds_txstatus[9] & __bswap32(AR_TxDone)) == 0)
728 return HAL_EINPROGRESS;
729 ar5416SwapTxDesc(ds);
731 if ((ds_txstatus[9] & AR_TxDone) == 0)
732 return HAL_EINPROGRESS;
735 /* Update software copies of the HW status */
736 ts->ts_seqnum = MS(ds_txstatus[9], AR_SeqNum);
737 ts->ts_tstamp = AR_SendTimestamp(ds_txstatus);
738 ts->ts_tid = MS(ds_txstatus[9], AR_TxTid);
741 if (ds_txstatus[1] & AR_ExcessiveRetries)
742 ts->ts_status |= HAL_TXERR_XRETRY;
743 if (ds_txstatus[1] & AR_Filtered)
744 ts->ts_status |= HAL_TXERR_FILT;
745 if (ds_txstatus[1] & AR_FIFOUnderrun)
746 ts->ts_status |= HAL_TXERR_FIFO;
747 if (ds_txstatus[9] & AR_TxOpExceeded)
748 ts->ts_status |= HAL_TXERR_XTXOP;
749 if (ds_txstatus[1] & AR_TxTimerExpired)
750 ts->ts_status |= HAL_TXERR_TIMER_EXPIRED;
753 if (ds_txstatus[0] & AR_TxBaStatus) {
754 ts->ts_flags |= HAL_TX_BA;
755 ts->ts_ba_low = AR_BaBitmapLow(ds_txstatus);
756 ts->ts_ba_high = AR_BaBitmapHigh(ds_txstatus);
758 if (ds->ds_ctl1 & AR_IsAggr)
759 ts->ts_flags |= HAL_TX_AGGR;
760 if (ds_txstatus[1] & AR_DescCfgErr)
761 ts->ts_flags |= HAL_TX_DESC_CFG_ERR;
762 if (ds_txstatus[1] & AR_TxDataUnderrun)
763 ts->ts_flags |= HAL_TX_DATA_UNDERRUN;
764 if (ds_txstatus[1] & AR_TxDelimUnderrun)
765 ts->ts_flags |= HAL_TX_DELIM_UNDERRUN;
768 * Extract the transmit rate used and mark the rate as
769 * ``alternate'' if it wasn't the series 0 rate.
771 ts->ts_finaltsi = MS(ds_txstatus[9], AR_FinalTxIdx);
772 switch (ts->ts_finaltsi) {
774 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate0);
777 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate1);
780 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate2);
783 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate3);
787 ts->ts_rssi = MS(ds_txstatus[5], AR_TxRSSICombined);
788 ts->ts_rssi_ctl[0] = MS(ds_txstatus[0], AR_TxRSSIAnt00);
789 ts->ts_rssi_ctl[1] = MS(ds_txstatus[0], AR_TxRSSIAnt01);
790 ts->ts_rssi_ctl[2] = MS(ds_txstatus[0], AR_TxRSSIAnt02);
791 ts->ts_rssi_ext[0] = MS(ds_txstatus[5], AR_TxRSSIAnt10);
792 ts->ts_rssi_ext[1] = MS(ds_txstatus[5], AR_TxRSSIAnt11);
793 ts->ts_rssi_ext[2] = MS(ds_txstatus[5], AR_TxRSSIAnt12);
794 ts->ts_evm0 = AR_TxEVM0(ds_txstatus);
795 ts->ts_evm1 = AR_TxEVM1(ds_txstatus);
796 ts->ts_evm2 = AR_TxEVM2(ds_txstatus);
798 ts->ts_shortretry = MS(ds_txstatus[1], AR_RTSFailCnt);
799 ts->ts_longretry = MS(ds_txstatus[1], AR_DataFailCnt);
801 * The retry count has the number of un-acked tries for the
802 * final series used. When doing multi-rate retry we must
803 * fixup the retry count by adding in the try counts for
804 * each series that was fully-processed. Beware that this
805 * takes values from the try counts in the final descriptor.
806 * These are not required by the hardware. We assume they
807 * are placed there by the driver as otherwise we have no
808 * access and the driver can't do the calculation because it
809 * doesn't know the descriptor format.
811 switch (ts->ts_finaltsi) {
812 case 3: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries2);
813 case 2: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries1);
814 case 1: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries0);
818 * These fields are not used. Zero these to preserve compatibility
819 * with existing drivers.
821 ts->ts_virtcol = MS(ads->ds_ctl1, AR_VirtRetryCnt);
822 ts->ts_antenna = 0; /* We don't switch antennas on Owl*/
824 /* handle tx trigger level changes internally */
825 if ((ts->ts_status & HAL_TXERR_FIFO) ||
826 (ts->ts_flags & (HAL_TX_DATA_UNDERRUN | HAL_TX_DELIM_UNDERRUN)))
827 ar5212UpdateTxTrigLevel(ah, AH_TRUE);
833 ar5416SetGlobalTxTimeout(struct ath_hal *ah, u_int tu)
835 struct ath_hal_5416 *ahp = AH5416(ah);
838 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad global tx timeout %u\n",
840 /* restore default handling */
841 ahp->ah_globaltxtimeout = (u_int) -1;
844 OS_REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
845 ahp->ah_globaltxtimeout = tu;
850 ar5416GetGlobalTxTimeout(struct ath_hal *ah)
852 return MS(OS_REG_READ(ah, AR_GTXTO), AR_GTXTO_TIMEOUT_LIMIT);
855 #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
856 static const u_int8_t baDurationDelta[] = {
876 ar5416Set11nRateScenario(struct ath_hal *ah, struct ath_desc *ds,
877 u_int durUpdateEn, u_int rtsctsRate,
878 HAL_11N_RATE_SERIES series[], u_int nseries, u_int flags)
880 struct ar5416_desc *ads = AR5416DESC(ds);
883 HALASSERT(nseries == 4);
887 * Only one of RTS and CTS enable must be set.
888 * If a frame has both set, just do RTS protection -
889 * that's enough to satisfy legacy protection.
891 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
892 ds_ctl0 = ads->ds_ctl0;
894 if (flags & HAL_TXDESC_RTSENA) {
895 ds_ctl0 &= ~AR_CTSEnable;
896 ds_ctl0 |= AR_RTSEnable;
898 ds_ctl0 &= ~AR_RTSEnable;
899 ds_ctl0 |= AR_CTSEnable;
902 ads->ds_ctl0 = ds_ctl0;
905 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
908 ads->ds_ctl2 = set11nTries(series, 0)
909 | set11nTries(series, 1)
910 | set11nTries(series, 2)
911 | set11nTries(series, 3)
912 | (durUpdateEn ? AR_DurUpdateEn : 0);
914 ads->ds_ctl3 = set11nRate(series, 0)
915 | set11nRate(series, 1)
916 | set11nRate(series, 2)
917 | set11nRate(series, 3);
919 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
920 | set11nPktDurRTSCTS(series, 1);
922 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
923 | set11nPktDurRTSCTS(series, 3);
925 ads->ds_ctl7 = set11nRateFlags(series, 0)
926 | set11nRateFlags(series, 1)
927 | set11nRateFlags(series, 2)
928 | set11nRateFlags(series, 3)
929 | SM(rtsctsRate, AR_RTSCTSRate);
932 * Doing per-packet TPC - update the TX power for the first
933 * field; program in the other series.
935 if (AH5212(ah)->ah_tpcEnabled) {
939 /* Modify the tx power field for rate 0 */
940 txPower = ar5416GetTxRatePower(ah, series[0].Rate,
942 series[0].tx_power_cap,
943 !! (series[0].RateFlags & HAL_RATESERIES_2040));
944 ds_ctl0 = ads->ds_ctl0 & ~AR_XmitPower;
945 ds_ctl0 |= (txPower << AR_XmitPower_S);
946 ads->ds_ctl0 = ds_ctl0;
949 * Override the whole descriptor field for each TX power.
951 * This will need changing if we ever support antenna control
954 txPower = ar5416GetTxRatePower(ah, series[1].Rate,
956 series[1].tx_power_cap,
957 !! (series[1].RateFlags & HAL_RATESERIES_2040));
958 ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);
960 txPower = ar5416GetTxRatePower(ah, series[2].Rate,
962 series[2].tx_power_cap,
963 !! (series[2].RateFlags & HAL_RATESERIES_2040));
964 ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);
966 txPower = ar5416GetTxRatePower(ah, series[3].Rate,
968 series[3].tx_power_cap,
969 !! (series[3].RateFlags & HAL_RATESERIES_2040));
970 ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);
975 * Note: this should be called before calling ar5416SetBurstDuration()
976 * (if it is indeed called) in order to ensure that the burst duration
977 * is correctly updated with the BA delta workaround.
980 ar5416Set11nAggrFirst(struct ath_hal *ah, struct ath_desc *ds, u_int aggrLen,
983 struct ar5416_desc *ads = AR5416DESC(ds);
988 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
990 ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);
991 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
992 ads->ds_ctl6 |= SM(numDelims, AR_PadDelim);
994 if (! AR_SREV_MERLIN_10_OR_LATER(ah)) {
996 * XXX It'd be nice if I were passed in the rate scenario
999 rate = MS(ads->ds_ctl3, AR_XmitRate0);
1000 flags = ads->ds_ctl0 & (AR_CTSEnable | AR_RTSEnable);
1002 * WAR - MAC assumes normal ACK time instead of
1003 * block ACK while computing packet duration.
1004 * Add this delta to the burst duration in the descriptor.
1006 if (flags && (ads->ds_ctl1 & AR_IsAggr)) {
1007 burstDur = baDurationDelta[HT_RC_2_MCS(rate)];
1008 ads->ds_ctl2 &= ~(AR_BurstDur);
1009 ads->ds_ctl2 |= SM(burstDur, AR_BurstDur);
1015 ar5416Set11nAggrMiddle(struct ath_hal *ah, struct ath_desc *ds, u_int numDelims)
1017 struct ar5416_desc *ads = AR5416DESC(ds);
1018 uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);
1020 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1022 ads->ds_ctl6 &= ~AR_PadDelim;
1023 ads->ds_ctl6 |= SM(numDelims, AR_PadDelim);
1024 ads->ds_ctl6 &= ~AR_AggrLen;
1027 * Clear the TxDone status here, may need to change
1028 * func name to reflect this
1030 ds_txstatus[9] &= ~AR_TxDone;
1034 ar5416Set11nAggrLast(struct ath_hal *ah, struct ath_desc *ds)
1036 struct ar5416_desc *ads = AR5416DESC(ds);
1038 ads->ds_ctl1 |= AR_IsAggr;
1039 ads->ds_ctl1 &= ~AR_MoreAggr;
1040 ads->ds_ctl6 &= ~AR_PadDelim;
1044 ar5416Clr11nAggr(struct ath_hal *ah, struct ath_desc *ds)
1046 struct ar5416_desc *ads = AR5416DESC(ds);
1048 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
1049 ads->ds_ctl6 &= ~AR_PadDelim;
1050 ads->ds_ctl6 &= ~AR_AggrLen;
1054 ar5416Set11nVirtualMoreFrag(struct ath_hal *ah, struct ath_desc *ds,
1057 struct ar5416_desc *ads = AR5416DESC(ds);
1059 ads->ds_ctl0 |= AR_VirtMoreFrag;
1061 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
1065 * Program the burst duration, with the included BA delta if it's
1069 ar5416Set11nBurstDuration(struct ath_hal *ah, struct ath_desc *ds,
1070 u_int burstDuration)
1072 struct ar5416_desc *ads = AR5416DESC(ds);
1073 uint32_t burstDur = 0;
1076 if (! AR_SREV_MERLIN_10_OR_LATER(ah)) {
1078 * XXX It'd be nice if I were passed in the rate scenario
1081 rate = MS(ads->ds_ctl3, AR_XmitDataTries0);
1083 * WAR - MAC assumes normal ACK time instead of
1084 * block ACK while computing packet duration.
1085 * Add this delta to the burst duration in the descriptor.
1087 if (ads->ds_ctl1 & AR_IsAggr) {
1088 burstDur = baDurationDelta[HT_RC_2_MCS(rate)];
1092 ads->ds_ctl2 &= ~AR_BurstDur;
1093 ads->ds_ctl2 |= SM(burstDur + burstDuration, AR_BurstDur);
1097 * Retrieve the rate table from the given TX completion descriptor
1100 ar5416GetTxCompletionRates(struct ath_hal *ah, const struct ath_desc *ds0, int *rates, int *tries)
1102 const struct ar5416_desc *ads = AR5416DESC_CONST(ds0);
1104 rates[0] = MS(ads->ds_ctl3, AR_XmitRate0);
1105 rates[1] = MS(ads->ds_ctl3, AR_XmitRate1);
1106 rates[2] = MS(ads->ds_ctl3, AR_XmitRate2);
1107 rates[3] = MS(ads->ds_ctl3, AR_XmitRate3);
1109 tries[0] = MS(ads->ds_ctl2, AR_XmitDataTries0);
1110 tries[1] = MS(ads->ds_ctl2, AR_XmitDataTries1);
1111 tries[2] = MS(ads->ds_ctl2, AR_XmitDataTries2);
1112 tries[3] = MS(ads->ds_ctl2, AR_XmitDataTries3);
1119 * TX queue management routines - AR5416 and later chipsets
1123 * Allocate and initialize a tx DCU/QCU combination.
1126 ar5416SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
1127 const HAL_TXQ_INFO *qInfo)
1129 struct ath_hal_5212 *ahp = AH5212(ah);
1130 HAL_TX_QUEUE_INFO *qi;
1131 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
1134 /* by default enable OK+ERR+DESC+URN interrupts */
1135 defqflags = HAL_TXQ_TXOKINT_ENABLE
1136 | HAL_TXQ_TXERRINT_ENABLE
1137 | HAL_TXQ_TXDESCINT_ENABLE
1138 | HAL_TXQ_TXURNINT_ENABLE;
1139 /* XXX move queue assignment to driver */
1141 case HAL_TX_QUEUE_BEACON:
1142 q = pCap->halTotalQueues-1; /* highest priority */
1143 defqflags |= HAL_TXQ_DBA_GATED
1144 | HAL_TXQ_CBR_DIS_QEMPTY
1145 | HAL_TXQ_ARB_LOCKOUT_GLOBAL
1146 | HAL_TXQ_BACKOFF_DISABLE;
1148 case HAL_TX_QUEUE_CAB:
1149 q = pCap->halTotalQueues-2; /* next highest priority */
1150 defqflags |= HAL_TXQ_DBA_GATED
1151 | HAL_TXQ_CBR_DIS_QEMPTY
1152 | HAL_TXQ_CBR_DIS_BEMPTY
1153 | HAL_TXQ_ARB_LOCKOUT_GLOBAL
1154 | HAL_TXQ_BACKOFF_DISABLE;
1156 case HAL_TX_QUEUE_PSPOLL:
1157 q = 1; /* lowest priority */
1158 defqflags |= HAL_TXQ_DBA_GATED
1159 | HAL_TXQ_CBR_DIS_QEMPTY
1160 | HAL_TXQ_CBR_DIS_BEMPTY
1161 | HAL_TXQ_ARB_LOCKOUT_GLOBAL
1162 | HAL_TXQ_BACKOFF_DISABLE;
1164 case HAL_TX_QUEUE_UAPSD:
1165 q = pCap->halTotalQueues-3; /* nextest highest priority */
1166 if (ahp->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE) {
1167 HALDEBUG(ah, HAL_DEBUG_ANY,
1168 "%s: no available UAPSD tx queue\n", __func__);
1172 case HAL_TX_QUEUE_DATA:
1173 for (q = 0; q < pCap->halTotalQueues; q++)
1174 if (ahp->ah_txq[q].tqi_type == HAL_TX_QUEUE_INACTIVE)
1176 if (q == pCap->halTotalQueues) {
1177 HALDEBUG(ah, HAL_DEBUG_ANY,
1178 "%s: no available tx queue\n", __func__);
1183 HALDEBUG(ah, HAL_DEBUG_ANY,
1184 "%s: bad tx queue type %u\n", __func__, type);
1188 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
1190 qi = &ahp->ah_txq[q];
1191 if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {
1192 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",
1196 OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));
1197 qi->tqi_type = type;
1198 if (qInfo == AH_NULL) {
1199 qi->tqi_qflags = defqflags;
1200 qi->tqi_aifs = INIT_AIFS;
1201 qi->tqi_cwmin = HAL_TXQ_USEDEFAULT; /* NB: do at reset */
1202 qi->tqi_cwmax = INIT_CWMAX;
1203 qi->tqi_shretry = INIT_SH_RETRY;
1204 qi->tqi_lgretry = INIT_LG_RETRY;
1205 qi->tqi_physCompBuf = 0;
1207 qi->tqi_physCompBuf = qInfo->tqi_compBuf;
1208 (void) ar5212SetTxQueueProps(ah, q, qInfo);
1210 /* NB: must be followed by ar5212ResetTxQueue */
1215 * Update the h/w interrupt registers to reflect a tx q's configuration.
1218 setTxQInterrupts(struct ath_hal *ah, HAL_TX_QUEUE_INFO *qi)
1220 struct ath_hal_5212 *ahp = AH5212(ah);
1222 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
1223 "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", __func__,
1224 ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask,
1225 ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask,
1226 ahp->ah_txUrnInterruptMask);
1228 OS_REG_WRITE(ah, AR_IMR_S0,
1229 SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
1230 | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)
1232 OS_REG_WRITE(ah, AR_IMR_S1,
1233 SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
1234 | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)
1236 OS_REG_RMW_FIELD(ah, AR_IMR_S2,
1237 AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
1241 * Set the retry, aifs, cwmin/max, readyTime regs for specified queue
1243 * phwChannel has been set to point to the current channel
1245 #define TU_TO_USEC(_tu) ((_tu) << 10)
1247 ar5416ResetTxQueue(struct ath_hal *ah, u_int q)
1249 struct ath_hal_5212 *ahp = AH5212(ah);
1250 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
1251 const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;
1252 HAL_TX_QUEUE_INFO *qi;
1253 uint32_t cwMin, chanCwMin, qmisc, dmisc;
1255 if (q >= pCap->halTotalQueues) {
1256 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
1260 qi = &ahp->ah_txq[q];
1261 if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
1262 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
1264 return AH_TRUE; /* XXX??? */
1267 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: reset queue %u\n", __func__, q);
1269 if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT) {
1271 * Select cwmin according to channel type.
1272 * NB: chan can be NULL during attach
1274 if (chan && IEEE80211_IS_CHAN_B(chan))
1275 chanCwMin = INIT_CWMIN_11B;
1277 chanCwMin = INIT_CWMIN;
1278 /* make sure that the CWmin is of the form (2^n - 1) */
1279 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1)
1282 cwMin = qi->tqi_cwmin;
1284 /* set cwMin/Max and AIFS values */
1285 OS_REG_WRITE(ah, AR_DLCL_IFS(q),
1286 SM(cwMin, AR_D_LCL_IFS_CWMIN)
1287 | SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX)
1288 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
1290 /* Set retry limit values */
1291 OS_REG_WRITE(ah, AR_DRETRY_LIMIT(q),
1292 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH)
1293 | SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG)
1294 | SM(qi->tqi_lgretry, AR_D_RETRY_LIMIT_FR_LG)
1295 | SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)
1298 /* NB: always enable early termination on the QCU */
1299 qmisc = AR_Q_MISC_DCU_EARLY_TERM_REQ
1300 | SM(AR_Q_MISC_FSP_ASAP, AR_Q_MISC_FSP);
1302 /* NB: always enable DCU to wait for next fragment from QCU */
1303 dmisc = AR_D_MISC_FRAG_WAIT_EN;
1305 /* Enable exponential backoff window */
1306 dmisc |= AR_D_MISC_BKOFF_PERSISTENCE;
1309 * The chip reset default is to use a DCU backoff threshold of 0x2.
1310 * Restore this when programming the DCU MISC register.
1314 /* multiqueue support */
1315 if (qi->tqi_cbrPeriod) {
1316 OS_REG_WRITE(ah, AR_QCBRCFG(q),
1317 SM(qi->tqi_cbrPeriod,AR_Q_CBRCFG_CBR_INTERVAL)
1318 | SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_CBR_OVF_THRESH));
1319 qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_CBR;
1320 if (qi->tqi_cbrOverflowLimit)
1321 qmisc |= AR_Q_MISC_CBR_EXP_CNTR_LIMIT;
1324 if (qi->tqi_readyTime && (qi->tqi_type != HAL_TX_QUEUE_CAB)) {
1325 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
1326 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT)
1327 | AR_Q_RDYTIMECFG_ENA);
1330 OS_REG_WRITE(ah, AR_DCHNTIME(q),
1331 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR)
1332 | (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
1334 if (qi->tqi_readyTime &&
1335 (qi->tqi_qflags & HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE))
1336 qmisc |= AR_Q_MISC_RDYTIME_EXP_POLICY;
1337 if (qi->tqi_qflags & HAL_TXQ_DBA_GATED)
1338 qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_DBA_GATED;
1339 if (MS(qmisc, AR_Q_MISC_FSP) != AR_Q_MISC_FSP_ASAP) {
1341 * These are meangingful only when not scheduled asap.
1343 if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_BEMPTY)
1344 qmisc |= AR_Q_MISC_CBR_INCR_DIS0;
1346 qmisc &= ~AR_Q_MISC_CBR_INCR_DIS0;
1347 if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_QEMPTY)
1348 qmisc |= AR_Q_MISC_CBR_INCR_DIS1;
1350 qmisc &= ~AR_Q_MISC_CBR_INCR_DIS1;
1353 if (qi->tqi_qflags & HAL_TXQ_BACKOFF_DISABLE)
1354 dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;
1355 if (qi->tqi_qflags & HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE)
1356 dmisc |= AR_D_MISC_FRAG_BKOFF_EN;
1357 if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_GLOBAL)
1358 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
1359 AR_D_MISC_ARB_LOCKOUT_CNTRL);
1360 else if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_INTRA)
1361 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_INTRA_FR,
1362 AR_D_MISC_ARB_LOCKOUT_CNTRL);
1363 if (qi->tqi_qflags & HAL_TXQ_IGNORE_VIRTCOL)
1364 dmisc |= SM(AR_D_MISC_VIR_COL_HANDLING_IGNORE,
1365 AR_D_MISC_VIR_COL_HANDLING);
1366 if (qi->tqi_qflags & HAL_TXQ_SEQNUM_INC_DIS)
1367 dmisc |= AR_D_MISC_SEQ_NUM_INCR_DIS;
1370 * Fillin type-dependent bits. Most of this can be
1371 * removed by specifying the queue parameters in the
1372 * driver; it's here for backwards compatibility.
1374 switch (qi->tqi_type) {
1375 case HAL_TX_QUEUE_BEACON: /* beacon frames */
1376 qmisc |= AR_Q_MISC_FSP_DBA_GATED
1377 | AR_Q_MISC_BEACON_USE
1378 | AR_Q_MISC_CBR_INCR_DIS1;
1380 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
1381 AR_D_MISC_ARB_LOCKOUT_CNTRL)
1382 | AR_D_MISC_BEACON_USE
1383 | AR_D_MISC_POST_FR_BKOFF_DIS;
1385 case HAL_TX_QUEUE_CAB: /* CAB frames */
1387 * No longer Enable AR_Q_MISC_RDYTIME_EXP_POLICY,
1388 * There is an issue with the CAB Queue
1389 * not properly refreshing the Tx descriptor if
1390 * the TXE clear setting is used.
1392 qmisc |= AR_Q_MISC_FSP_DBA_GATED
1393 | AR_Q_MISC_CBR_INCR_DIS1
1394 | AR_Q_MISC_CBR_INCR_DIS0;
1395 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: CAB: tqi_readyTime = %d\n",
1396 __func__, qi->tqi_readyTime);
1397 if (qi->tqi_readyTime) {
1398 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
1399 "%s: using tqi_readyTime\n", __func__);
1400 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
1401 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT) |
1402 AR_Q_RDYTIMECFG_ENA);
1406 * NB: don't set default ready time if driver
1407 * has explicitly specified something. This is
1408 * here solely for backwards compatibility.
1411 * XXX for now, hard-code a CAB interval of 70%
1412 * XXX of the total beacon interval.
1414 * XXX This keeps Merlin and later based MACs
1415 * XXX quite a bit happier (stops stuck beacons,
1416 * XXX which I gather is because of such a long
1419 value = (ahp->ah_beaconInterval * 50 / 100)
1420 - ah->ah_config.ah_additional_swba_backoff
1421 - ah->ah_config.ah_sw_beacon_response_time
1422 + ah->ah_config.ah_dma_beacon_response_time;
1424 * XXX Ensure it isn't too low - nothing lower
1429 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
1430 "%s: defaulting to rdytime = %d uS\n",
1432 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
1433 SM(TU_TO_USEC(value), AR_Q_RDYTIMECFG_INT) |
1434 AR_Q_RDYTIMECFG_ENA);
1436 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
1437 AR_D_MISC_ARB_LOCKOUT_CNTRL);
1439 case HAL_TX_QUEUE_PSPOLL:
1440 qmisc |= AR_Q_MISC_CBR_INCR_DIS1;
1442 case HAL_TX_QUEUE_UAPSD:
1443 dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;
1445 default: /* NB: silence compiler */
1449 OS_REG_WRITE(ah, AR_QMISC(q), qmisc);
1450 OS_REG_WRITE(ah, AR_DMISC(q), dmisc);
1452 /* Setup compression scratchpad buffer */
1454 * XXX: calling this asynchronously to queue operation can
1455 * cause unexpected behavior!!!
1457 if (qi->tqi_physCompBuf) {
1458 HALASSERT(qi->tqi_type == HAL_TX_QUEUE_DATA ||
1459 qi->tqi_type == HAL_TX_QUEUE_UAPSD);
1460 OS_REG_WRITE(ah, AR_Q_CBBS, (80 + 2*q));
1461 OS_REG_WRITE(ah, AR_Q_CBBA, qi->tqi_physCompBuf);
1462 OS_REG_WRITE(ah, AR_Q_CBC, HAL_COMP_BUF_MAX_SIZE/1024);
1463 OS_REG_WRITE(ah, AR_Q0_MISC + 4*q,
1464 OS_REG_READ(ah, AR_Q0_MISC + 4*q)
1465 | AR_Q_MISC_QCU_COMP_EN);
1469 * Always update the secondary interrupt mask registers - this
1470 * could be a new queue getting enabled in a running system or
1471 * hw getting re-initialized during a reset!
1473 * Since we don't differentiate between tx interrupts corresponding
1474 * to individual queues - secondary tx mask regs are always unmasked;
1475 * tx interrupts are enabled/disabled for all queues collectively
1476 * using the primary mask reg
1478 if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)
1479 ahp->ah_txOkInterruptMask |= 1 << q;
1481 ahp->ah_txOkInterruptMask &= ~(1 << q);
1482 if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)
1483 ahp->ah_txErrInterruptMask |= 1 << q;
1485 ahp->ah_txErrInterruptMask &= ~(1 << q);
1486 if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)
1487 ahp->ah_txDescInterruptMask |= 1 << q;
1489 ahp->ah_txDescInterruptMask &= ~(1 << q);
1490 if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)
1491 ahp->ah_txEolInterruptMask |= 1 << q;
1493 ahp->ah_txEolInterruptMask &= ~(1 << q);
1494 if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)
1495 ahp->ah_txUrnInterruptMask |= 1 << q;
1497 ahp->ah_txUrnInterruptMask &= ~(1 << q);
1498 setTxQInterrupts(ah, qi);