2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "ah_internal.h"
25 /* linker set of registered chips */
26 OS_SET_DECLARE(ah_chips, struct ath_hal_chip);
29 * Check the set of registered chips to see if any recognize
30 * the device as one they can support.
33 ath_hal_probe(uint16_t vendorid, uint16_t devid)
35 struct ath_hal_chip * const *pchip;
37 OS_SET_FOREACH(pchip, ah_chips) {
38 const char *name = (*pchip)->probe(vendorid, devid);
46 * Attach detects device chip revisions, initializes the hwLayer
47 * function list, reads EEPROM information,
48 * selects reset vectors, and performs a short self test.
49 * Any failures will return an error that should cause a hardware
53 ath_hal_attach(uint16_t devid, HAL_SOFTC sc,
54 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *error)
56 struct ath_hal_chip * const *pchip;
58 OS_SET_FOREACH(pchip, ah_chips) {
59 struct ath_hal_chip *chip = *pchip;
62 /* XXX don't have vendorid, assume atheros one works */
63 if (chip->probe(ATHEROS_VENDOR_ID, devid) == AH_NULL)
65 ah = chip->attach(devid, sc, st, sh, error);
67 /* copy back private state to public area */
68 ah->ah_devid = AH_PRIVATE(ah)->ah_devid;
69 ah->ah_subvendorid = AH_PRIVATE(ah)->ah_subvendorid;
70 ah->ah_macVersion = AH_PRIVATE(ah)->ah_macVersion;
71 ah->ah_macRev = AH_PRIVATE(ah)->ah_macRev;
72 ah->ah_phyRev = AH_PRIVATE(ah)->ah_phyRev;
73 ah->ah_analog5GhzRev = AH_PRIVATE(ah)->ah_analog5GhzRev;
74 ah->ah_analog2GhzRev = AH_PRIVATE(ah)->ah_analog2GhzRev;
81 /* linker set of registered RF backends */
82 OS_SET_DECLARE(ah_rfs, struct ath_hal_rf);
85 * Check the set of registered RF backends to see if
86 * any recognize the device as one they can support.
89 ath_hal_rfprobe(struct ath_hal *ah, HAL_STATUS *ecode)
91 struct ath_hal_rf * const *prf;
93 OS_SET_FOREACH(prf, ah_rfs) {
94 struct ath_hal_rf *rf = *prf;
98 *ecode = HAL_ENOTSUPP;
103 * Poll the register looking for a specific value.
106 ath_hal_wait(struct ath_hal *ah, u_int reg, uint32_t mask, uint32_t val)
108 #define AH_TIMEOUT 1000
111 for (i = 0; i < AH_TIMEOUT; i++) {
112 if ((OS_REG_READ(ah, reg) & mask) == val)
116 HALDEBUG(ah, HAL_DEBUG_REGIO | HAL_DEBUG_PHYIO,
117 "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
118 __func__, reg, OS_REG_READ(ah, reg), mask, val);
124 * Reverse the bits starting at the low bit for a value of
128 ath_hal_reverseBits(uint32_t val, uint32_t n)
133 for (i = 0, retval = 0; i < n; i++) {
134 retval = (retval << 1) | (val & 1);
141 * Compute the time to transmit a frame of length frameLen bytes
142 * using the specified rate, phy, and short preamble setting.
145 ath_hal_computetxtime(struct ath_hal *ah,
146 const HAL_RATE_TABLE *rates, uint32_t frameLen, uint16_t rateix,
147 HAL_BOOL shortPreamble)
149 uint32_t bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
152 kbps = rates->info[rateix].rateKbps;
154 * index can be invalid duting dynamic Turbo transitions.
156 if(kbps == 0) return 0;
157 switch (rates->info[rateix].phy) {
159 case IEEE80211_T_CCK:
160 #define CCK_SIFS_TIME 10
161 #define CCK_PREAMBLE_BITS 144
162 #define CCK_PLCP_BITS 48
163 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
164 if (shortPreamble && rates->info[rateix].shortPreamble)
166 numBits = frameLen << 3;
167 txTime = CCK_SIFS_TIME + phyTime
168 + ((numBits * 1000)/kbps);
171 #undef CCK_PREAMBLE_BITS
174 case IEEE80211_T_OFDM:
175 #define OFDM_SIFS_TIME 16
176 #define OFDM_PREAMBLE_TIME 20
177 #define OFDM_PLCP_BITS 22
178 #define OFDM_SYMBOL_TIME 4
180 #define OFDM_SIFS_TIME_HALF 32
181 #define OFDM_PREAMBLE_TIME_HALF 40
182 #define OFDM_PLCP_BITS_HALF 22
183 #define OFDM_SYMBOL_TIME_HALF 8
185 #define OFDM_SIFS_TIME_QUARTER 64
186 #define OFDM_PREAMBLE_TIME_QUARTER 80
187 #define OFDM_PLCP_BITS_QUARTER 22
188 #define OFDM_SYMBOL_TIME_QUARTER 16
190 if (AH_PRIVATE(ah)->ah_curchan &&
191 IS_CHAN_QUARTER_RATE(AH_PRIVATE(ah)->ah_curchan)) {
192 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
193 HALASSERT(bitsPerSymbol != 0);
195 numBits = OFDM_PLCP_BITS + (frameLen << 3);
196 numSymbols = howmany(numBits, bitsPerSymbol);
197 txTime = OFDM_SIFS_TIME_QUARTER
198 + OFDM_PREAMBLE_TIME_QUARTER
199 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
200 } else if (AH_PRIVATE(ah)->ah_curchan &&
201 IS_CHAN_HALF_RATE(AH_PRIVATE(ah)->ah_curchan)) {
202 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
203 HALASSERT(bitsPerSymbol != 0);
205 numBits = OFDM_PLCP_BITS + (frameLen << 3);
206 numSymbols = howmany(numBits, bitsPerSymbol);
207 txTime = OFDM_SIFS_TIME_HALF +
208 OFDM_PREAMBLE_TIME_HALF
209 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
210 } else { /* full rate channel */
211 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
212 HALASSERT(bitsPerSymbol != 0);
214 numBits = OFDM_PLCP_BITS + (frameLen << 3);
215 numSymbols = howmany(numBits, bitsPerSymbol);
216 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
217 + (numSymbols * OFDM_SYMBOL_TIME);
221 #undef OFDM_SIFS_TIME
222 #undef OFDM_PREAMBLE_TIME
223 #undef OFDM_PLCP_BITS
224 #undef OFDM_SYMBOL_TIME
226 case IEEE80211_T_TURBO:
227 #define TURBO_SIFS_TIME 8
228 #define TURBO_PREAMBLE_TIME 14
229 #define TURBO_PLCP_BITS 22
230 #define TURBO_SYMBOL_TIME 4
231 /* we still save OFDM rates in kbps - so double them */
232 bitsPerSymbol = ((kbps << 1) * TURBO_SYMBOL_TIME) / 1000;
233 HALASSERT(bitsPerSymbol != 0);
235 numBits = TURBO_PLCP_BITS + (frameLen << 3);
236 numSymbols = howmany(numBits, bitsPerSymbol);
237 txTime = TURBO_SIFS_TIME + TURBO_PREAMBLE_TIME
238 + (numSymbols * TURBO_SYMBOL_TIME);
240 #undef TURBO_SIFS_TIME
241 #undef TURBO_PREAMBLE_TIME
242 #undef TURBO_PLCP_BITS
243 #undef TURBO_SYMBOL_TIME
246 HALDEBUG(ah, HAL_DEBUG_PHYIO,
247 "%s: unknown phy %u (rate ix %u)\n",
248 __func__, rates->info[rateix].phy, rateix);
256 mapgsm(u_int freq, u_int flags)
259 if (flags & CHANNEL_QUARTER)
261 else if (flags & CHANNEL_HALF)
265 return (freq - 24220) / 5;
269 mappsb(u_int freq, u_int flags)
271 return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
275 * Convert GHz frequency to IEEE channel number.
278 ath_hal_mhz2ieee(struct ath_hal *ah, u_int freq, u_int flags)
280 if (flags & CHANNEL_2GHZ) { /* 2GHz band */
284 if (ath_hal_isgsmsku(ah))
285 return mapgsm(freq, flags);
286 return ((int)freq - 2407) / 5;
288 return 15 + ((freq - 2512) / 20);
289 } else if (flags & CHANNEL_5GHZ) {/* 5Ghz band */
290 if (ath_hal_ispublicsafetysku(ah) &&
291 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
292 return mappsb(freq, flags);
293 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
294 return (freq - 4000) / 5;
296 return (freq - 5000) / 5;
298 } else { /* either, guess */
302 if (ath_hal_isgsmsku(ah))
303 return mapgsm(freq, flags);
304 return ((int)freq - 2407) / 5;
307 if (ath_hal_ispublicsafetysku(ah) &&
308 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
309 return mappsb(freq, flags);
310 } else if (freq > 4900) {
311 return (freq - 4000) / 5;
313 return 15 + ((freq - 2512) / 20);
316 return (freq - 5000) / 5;
321 WIRELESS_MODE_11a = 0,
322 WIRELESS_MODE_TURBO = 1,
323 WIRELESS_MODE_11b = 2,
324 WIRELESS_MODE_11g = 3,
325 WIRELESS_MODE_108g = 4,
331 ath_hal_chan2wmode(struct ath_hal *ah, const HAL_CHANNEL *chan)
333 if (IS_CHAN_CCK(chan))
334 return WIRELESS_MODE_11b;
336 return WIRELESS_MODE_11g;
337 if (IS_CHAN_108G(chan))
338 return WIRELESS_MODE_108g;
339 if (IS_CHAN_TURBO(chan))
340 return WIRELESS_MODE_TURBO;
341 return WIRELESS_MODE_11a;
345 * Convert between microseconds and core system clocks.
347 /* 11a Turbo 11b 11g 108g */
348 static const uint8_t CLOCK_RATE[] = { 40, 80, 22, 44, 88 };
351 ath_hal_mac_clks(struct ath_hal *ah, u_int usecs)
353 const HAL_CHANNEL *c = (const HAL_CHANNEL *) AH_PRIVATE(ah)->ah_curchan;
356 /* NB: ah_curchan may be null when called attach time */
358 clks = usecs * CLOCK_RATE[ath_hal_chan2wmode(ah, c)];
361 else if (IS_CHAN_HALF_RATE(c))
363 else if (IS_CHAN_QUARTER_RATE(c))
366 clks = usecs * CLOCK_RATE[WIRELESS_MODE_11b];
371 ath_hal_mac_usec(struct ath_hal *ah, u_int clks)
373 const HAL_CHANNEL *c = (const HAL_CHANNEL *) AH_PRIVATE(ah)->ah_curchan;
376 /* NB: ah_curchan may be null when called attach time */
378 usec = clks / CLOCK_RATE[ath_hal_chan2wmode(ah, c)];
381 else if (IS_CHAN_HALF_RATE(c))
383 else if (IS_CHAN_QUARTER_RATE(c))
386 usec = clks / CLOCK_RATE[WIRELESS_MODE_11b];
391 * Setup a h/w rate table's reverse lookup table and
392 * fill in ack durations. This routine is called for
393 * each rate table returned through the ah_getRateTable
394 * method. The reverse lookup tables are assumed to be
395 * initialized to zero (or at least the first entry).
396 * We use this as a key that indicates whether or not
397 * we've previously setup the reverse lookup table.
399 * XXX not reentrant, but shouldn't matter
402 ath_hal_setupratetable(struct ath_hal *ah, HAL_RATE_TABLE *rt)
404 #define N(a) (sizeof(a)/sizeof(a[0]))
407 if (rt->rateCodeToIndex[0] != 0) /* already setup */
409 for (i = 0; i < N(rt->rateCodeToIndex); i++)
410 rt->rateCodeToIndex[i] = (uint8_t) -1;
411 for (i = 0; i < rt->rateCount; i++) {
412 uint8_t code = rt->info[i].rateCode;
413 uint8_t cix = rt->info[i].controlRate;
415 HALASSERT(code < N(rt->rateCodeToIndex));
416 rt->rateCodeToIndex[code] = i;
417 HALASSERT((code | rt->info[i].shortPreamble) <
418 N(rt->rateCodeToIndex));
419 rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
421 * XXX for 11g the control rate to use for 5.5 and 11 Mb/s
422 * depends on whether they are marked as basic rates;
423 * the static tables are setup with an 11b-compatible
424 * 2Mb/s rate which will work but is suboptimal
426 rt->info[i].lpAckDuration = ath_hal_computetxtime(ah, rt,
427 WLAN_CTRL_FRAME_SIZE, cix, AH_FALSE);
428 rt->info[i].spAckDuration = ath_hal_computetxtime(ah, rt,
429 WLAN_CTRL_FRAME_SIZE, cix, AH_TRUE);
435 ath_hal_getcapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
436 uint32_t capability, uint32_t *result)
438 const HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
441 case HAL_CAP_REG_DMN: /* regulatory domain */
442 *result = AH_PRIVATE(ah)->ah_currentRD;
444 case HAL_CAP_CIPHER: /* cipher handled in hardware */
445 case HAL_CAP_TKIP_MIC: /* handle TKIP MIC in hardware */
447 case HAL_CAP_TKIP_SPLIT: /* hardware TKIP uses split keys */
449 case HAL_CAP_PHYCOUNTERS: /* hardware PHY error counters */
450 return pCap->halHwPhyCounterSupport ? HAL_OK : HAL_ENXIO;
451 case HAL_CAP_WME_TKIPMIC: /* hardware can do TKIP MIC when WMM is turned on */
453 case HAL_CAP_DIVERSITY: /* hardware supports fast diversity */
455 case HAL_CAP_KEYCACHE_SIZE: /* hardware key cache size */
456 *result = pCap->halKeyCacheSize;
458 case HAL_CAP_NUM_TXQUEUES: /* number of hardware tx queues */
459 *result = pCap->halTotalQueues;
461 case HAL_CAP_VEOL: /* hardware supports virtual EOL */
462 return pCap->halVEOLSupport ? HAL_OK : HAL_ENOTSUPP;
463 case HAL_CAP_PSPOLL: /* hardware PS-Poll support works */
464 return pCap->halPSPollBroken ? HAL_ENOTSUPP : HAL_OK;
465 case HAL_CAP_COMPRESSION:
466 return pCap->halCompressSupport ? HAL_OK : HAL_ENOTSUPP;
468 return pCap->halBurstSupport ? HAL_OK : HAL_ENOTSUPP;
469 case HAL_CAP_FASTFRAME:
470 return pCap->halFastFramesSupport ? HAL_OK : HAL_ENOTSUPP;
471 case HAL_CAP_DIAG: /* hardware diagnostic support */
472 *result = AH_PRIVATE(ah)->ah_diagreg;
474 case HAL_CAP_TXPOW: /* global tx power limit */
475 switch (capability) {
476 case 0: /* facility is supported */
478 case 1: /* current limit */
479 *result = AH_PRIVATE(ah)->ah_powerLimit;
481 case 2: /* current max tx power */
482 *result = AH_PRIVATE(ah)->ah_maxPowerLevel;
484 case 3: /* scale factor */
485 *result = AH_PRIVATE(ah)->ah_tpScale;
489 case HAL_CAP_BSSIDMASK: /* hardware supports bssid mask */
490 return pCap->halBssIdMaskSupport ? HAL_OK : HAL_ENOTSUPP;
491 case HAL_CAP_MCAST_KEYSRCH: /* multicast frame keycache search */
492 return pCap->halMcastKeySrchSupport ? HAL_OK : HAL_ENOTSUPP;
493 case HAL_CAP_TSF_ADJUST: /* hardware has beacon tsf adjust */
495 case HAL_CAP_RFSILENT: /* rfsilent support */
496 switch (capability) {
497 case 0: /* facility is supported */
498 return pCap->halRfSilentSupport ? HAL_OK : HAL_ENOTSUPP;
499 case 1: /* current setting */
500 return AH_PRIVATE(ah)->ah_rfkillEnabled ?
501 HAL_OK : HAL_ENOTSUPP;
502 case 2: /* rfsilent config */
503 *result = AH_PRIVATE(ah)->ah_rfsilent;
508 #ifdef AH_SUPPORT_11D
513 case HAL_CAP_RXORN_FATAL: /* HAL_INT_RXORN treated as fatal */
514 return AH_PRIVATE(ah)->ah_rxornIsFatal ? HAL_OK : HAL_ENOTSUPP;
516 return pCap->halHTSupport ? HAL_OK : HAL_ENOTSUPP;
517 case HAL_CAP_TX_CHAINMASK: /* mask of TX chains supported */
518 *result = pCap->halTxChainMask;
520 case HAL_CAP_RX_CHAINMASK: /* mask of RX chains supported */
521 *result = pCap->halRxChainMask;
523 case HAL_CAP_RXTSTAMP_PREC: /* rx desc tstamp precision (bits) */
524 *result = pCap->halTstampPrecision;
532 ath_hal_setcapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
533 uint32_t capability, uint32_t setting, HAL_STATUS *status)
538 switch (capability) {
540 if (setting <= HAL_TP_SCALE_MIN) {
541 AH_PRIVATE(ah)->ah_tpScale = setting;
547 case HAL_CAP_RFSILENT: /* rfsilent support */
549 * NB: allow even if halRfSilentSupport is false
550 * in case the EEPROM is misprogrammed.
552 switch (capability) {
553 case 1: /* current setting */
554 AH_PRIVATE(ah)->ah_rfkillEnabled = (setting != 0);
556 case 2: /* rfsilent config */
557 /* XXX better done per-chip for validation? */
558 AH_PRIVATE(ah)->ah_rfsilent = setting;
562 case HAL_CAP_REG_DMN: /* regulatory domain */
563 AH_PRIVATE(ah)->ah_currentRD = setting;
565 case HAL_CAP_RXORN_FATAL: /* HAL_INT_RXORN treated as fatal */
566 AH_PRIVATE(ah)->ah_rxornIsFatal = setting;
572 *status = HAL_EINVAL;
577 * Common support for getDiagState method.
581 ath_hal_getregdump(struct ath_hal *ah, const HAL_REGRANGE *regs,
582 void *dstbuf, int space)
584 uint32_t *dp = dstbuf;
587 for (i = 0; space >= 2*sizeof(uint32_t); i++) {
588 u_int r = regs[i].start;
589 u_int e = regs[i].end;
591 space -= sizeof(uint32_t);
593 *dp++ = OS_REG_READ(ah, r);
594 r += sizeof(uint32_t);
595 space -= sizeof(uint32_t);
596 } while (r <= e && space >= sizeof(uint32_t));
598 return (char *) dp - (char *) dstbuf;
602 ath_hal_getdiagstate(struct ath_hal *ah, int request,
603 const void *args, uint32_t argsize,
604 void **result, uint32_t *resultsize)
608 *result = &AH_PRIVATE(ah)->ah_devid;
609 *resultsize = sizeof(HAL_REVS);
612 *resultsize = ath_hal_getregdump(ah, args, *result,*resultsize);
614 case HAL_DIAG_FATALERR:
615 *result = &AH_PRIVATE(ah)->ah_fatalState[0];
616 *resultsize = sizeof(AH_PRIVATE(ah)->ah_fatalState);
618 case HAL_DIAG_EEREAD:
619 if (argsize != sizeof(uint16_t))
621 if (!ath_hal_eepromRead(ah, *(const uint16_t *)args, *result))
623 *resultsize = sizeof(uint16_t);
625 #ifdef AH_PRIVATE_DIAG
626 case HAL_DIAG_SETKEY: {
627 const HAL_DIAG_KEYVAL *dk;
629 if (argsize != sizeof(HAL_DIAG_KEYVAL))
631 dk = (const HAL_DIAG_KEYVAL *)args;
632 return ah->ah_setKeyCacheEntry(ah, dk->dk_keyix,
633 &dk->dk_keyval, dk->dk_mac, dk->dk_xor);
635 case HAL_DIAG_RESETKEY:
636 if (argsize != sizeof(uint16_t))
638 return ah->ah_resetKeyCacheEntry(ah, *(const uint16_t *)args);
639 #ifdef AH_SUPPORT_WRITE_EEPROM
640 case HAL_DIAG_EEWRITE: {
641 const HAL_DIAG_EEVAL *ee;
642 if (argsize != sizeof(HAL_DIAG_EEVAL))
644 ee = (const HAL_DIAG_EEVAL *)args;
645 return ath_hal_eepromWrite(ah, ee->ee_off, ee->ee_data);
647 #endif /* AH_SUPPORT_WRITE_EEPROM */
648 #endif /* AH_PRIVATE_DIAG */
649 case HAL_DIAG_11NCOMPAT:
651 *resultsize = sizeof(uint32_t);
652 *((uint32_t *)(*result)) =
653 AH_PRIVATE(ah)->ah_11nCompat;
654 } else if (argsize == sizeof(uint32_t)) {
655 AH_PRIVATE(ah)->ah_11nCompat = *(const uint32_t *)args;
664 * Set the properties of the tx queue with the parameters
668 ath_hal_setTxQProps(struct ath_hal *ah,
669 HAL_TX_QUEUE_INFO *qi, const HAL_TXQ_INFO *qInfo)
673 if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
674 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
675 "%s: inactive queue\n", __func__);
678 /* XXX validate parameters */
679 qi->tqi_ver = qInfo->tqi_ver;
680 qi->tqi_subtype = qInfo->tqi_subtype;
681 qi->tqi_qflags = qInfo->tqi_qflags;
682 qi->tqi_priority = qInfo->tqi_priority;
683 if (qInfo->tqi_aifs != HAL_TXQ_USEDEFAULT)
684 qi->tqi_aifs = AH_MIN(qInfo->tqi_aifs, 255);
686 qi->tqi_aifs = INIT_AIFS;
687 if (qInfo->tqi_cwmin != HAL_TXQ_USEDEFAULT) {
688 cw = AH_MIN(qInfo->tqi_cwmin, 1024);
689 /* make sure that the CWmin is of the form (2^n - 1) */
691 while (qi->tqi_cwmin < cw)
692 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
694 qi->tqi_cwmin = qInfo->tqi_cwmin;
695 if (qInfo->tqi_cwmax != HAL_TXQ_USEDEFAULT) {
696 cw = AH_MIN(qInfo->tqi_cwmax, 1024);
697 /* make sure that the CWmax is of the form (2^n - 1) */
699 while (qi->tqi_cwmax < cw)
700 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
702 qi->tqi_cwmax = INIT_CWMAX;
703 /* Set retry limit values */
704 if (qInfo->tqi_shretry != 0)
705 qi->tqi_shretry = AH_MIN(qInfo->tqi_shretry, 15);
707 qi->tqi_shretry = INIT_SH_RETRY;
708 if (qInfo->tqi_lgretry != 0)
709 qi->tqi_lgretry = AH_MIN(qInfo->tqi_lgretry, 15);
711 qi->tqi_lgretry = INIT_LG_RETRY;
712 qi->tqi_cbrPeriod = qInfo->tqi_cbrPeriod;
713 qi->tqi_cbrOverflowLimit = qInfo->tqi_cbrOverflowLimit;
714 qi->tqi_burstTime = qInfo->tqi_burstTime;
715 qi->tqi_readyTime = qInfo->tqi_readyTime;
717 switch (qInfo->tqi_subtype) {
719 if (qi->tqi_type == HAL_TX_QUEUE_DATA)
720 qi->tqi_intFlags = HAL_TXQ_USE_LOCKOUT_BKOFF_DIS;
723 break; /* NB: silence compiler */
729 ath_hal_getTxQProps(struct ath_hal *ah,
730 HAL_TXQ_INFO *qInfo, const HAL_TX_QUEUE_INFO *qi)
732 if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
733 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
734 "%s: inactive queue\n", __func__);
738 qInfo->tqi_qflags = qi->tqi_qflags;
739 qInfo->tqi_ver = qi->tqi_ver;
740 qInfo->tqi_subtype = qi->tqi_subtype;
741 qInfo->tqi_qflags = qi->tqi_qflags;
742 qInfo->tqi_priority = qi->tqi_priority;
743 qInfo->tqi_aifs = qi->tqi_aifs;
744 qInfo->tqi_cwmin = qi->tqi_cwmin;
745 qInfo->tqi_cwmax = qi->tqi_cwmax;
746 qInfo->tqi_shretry = qi->tqi_shretry;
747 qInfo->tqi_lgretry = qi->tqi_lgretry;
748 qInfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
749 qInfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
750 qInfo->tqi_burstTime = qi->tqi_burstTime;
751 qInfo->tqi_readyTime = qi->tqi_readyTime;
755 /* 11a Turbo 11b 11g 108g */
756 static const int16_t NOISE_FLOOR[] = { -96, -93, -98, -96, -93 };
759 * Read the current channel noise floor and return.
760 * If nf cal hasn't finished, channel noise floor should be 0
761 * and we return a nominal value based on band and frequency.
763 * NB: This is a private routine used by per-chip code to
764 * implement the ah_getChanNoise method.
767 ath_hal_getChanNoise(struct ath_hal *ah, HAL_CHANNEL *chan)
769 HAL_CHANNEL_INTERNAL *ichan;
771 ichan = ath_hal_checkchannel(ah, chan);
772 if (ichan == AH_NULL) {
773 HALDEBUG(ah, HAL_DEBUG_NFCAL,
774 "%s: invalid channel %u/0x%x; no mapping\n",
775 __func__, chan->channel, chan->channelFlags);
778 if (ichan->rawNoiseFloor == 0) {
779 WIRELESS_MODE mode = ath_hal_chan2wmode(ah, chan);
781 HALASSERT(mode < WIRELESS_MODE_MAX);
782 return NOISE_FLOOR[mode] + ath_hal_getNfAdjust(ah, ichan);
784 return ichan->rawNoiseFloor + ichan->noiseFloorAdjust;
788 * Process all valid raw noise floors into the dBm noise floor values.
789 * Though our device has no reference for a dBm noise floor, we perform
790 * a relative minimization of NF's based on the lowest NF found across a
794 ath_hal_process_noisefloor(struct ath_hal *ah)
796 HAL_CHANNEL_INTERNAL *c;
797 int16_t correct2, correct5;
798 int16_t lowest2, lowest5;
802 * Find the lowest 2GHz and 5GHz noise floor values after adjusting
803 * for statistically recorded NF/channel deviation.
805 correct2 = lowest2 = 0;
806 correct5 = lowest5 = 0;
807 for (i = 0; i < AH_PRIVATE(ah)->ah_nchan; i++) {
811 c = &AH_PRIVATE(ah)->ah_channels[i];
812 if (c->rawNoiseFloor >= 0)
814 mode = ath_hal_chan2wmode(ah, (HAL_CHANNEL *) c);
815 HALASSERT(mode < WIRELESS_MODE_MAX);
816 nf = c->rawNoiseFloor + NOISE_FLOOR[mode] +
817 ath_hal_getNfAdjust(ah, c);
818 if (IS_CHAN_5GHZ(c)) {
821 correct5 = NOISE_FLOOR[mode] -
822 (c->rawNoiseFloor + ath_hal_getNfAdjust(ah, c));
827 correct2 = NOISE_FLOOR[mode] -
828 (c->rawNoiseFloor + ath_hal_getNfAdjust(ah, c));
833 /* Correct the channels to reach the expected NF value */
834 for (i = 0; i < AH_PRIVATE(ah)->ah_nchan; i++) {
835 c = &AH_PRIVATE(ah)->ah_channels[i];
836 if (c->rawNoiseFloor >= 0)
838 /* Apply correction factor */
839 c->noiseFloorAdjust = ath_hal_getNfAdjust(ah, c) +
840 (IS_CHAN_5GHZ(c) ? correct5 : correct2);
841 HALDEBUG(ah, HAL_DEBUG_NFCAL, "%u/0x%x raw nf %d adjust %d\n",
842 c->channel, c->channelFlags, c->rawNoiseFloor,
843 c->noiseFloorAdjust);
848 * INI support routines.
852 ath_hal_ini_write(struct ath_hal *ah, const HAL_INI_ARRAY *ia,
857 for (r = 0; r < ia->rows; r++) {
858 OS_REG_WRITE(ah, HAL_INI_VAL(ia, r, 0),
859 HAL_INI_VAL(ia, r, col));
866 ath_hal_ini_bank_setup(uint32_t data[], const HAL_INI_ARRAY *ia, int col)
870 for (r = 0; r < ia->rows; r++)
871 data[r] = HAL_INI_VAL(ia, r, col);
875 ath_hal_ini_bank_write(struct ath_hal *ah, const HAL_INI_ARRAY *ia,
876 const uint32_t data[], int regWr)
880 for (r = 0; r < ia->rows; r++) {
881 OS_REG_WRITE(ah, HAL_INI_VAL(ia, r, 0), data[r]);