2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2005-2006 Atheros Communications, Inc.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <net80211/_ieee80211.h>
25 #include <net80211/ieee80211_regdomain.h>
27 #include "ah_internal.h"
28 #include "ah_eeprom.h"
31 #include "ah_regdomain.h"
34 * XXX this code needs a audit+review
37 /* used throughout this file... */
38 #define N(a) nitems(a)
40 #define HAL_MODE_11A_TURBO HAL_MODE_108A
41 #define HAL_MODE_11G_TURBO HAL_MODE_108G
44 * Mask to check whether a domain is a multidomain or a single domain
46 #define MULTI_DOMAIN_MASK 0xFF00
49 * Enumerated Regulatory Domain Information 8 bit values indicate that
50 * the regdomain is really a pair of unitary regdomains. 12 bit values
51 * are the real unitary regdomains and are the only ones which have the
52 * frequency bitmasks and flags set.
54 #include "ah_regdomain/ah_rd_regenum.h"
56 #define WORLD_SKU_MASK 0x00F0
57 #define WORLD_SKU_PREFIX 0x0060
60 * THE following table is the mapping of regdomain pairs specified by
61 * an 8 bit regdomain value to the individual unitary reg domains
63 #include "ah_regdomain/ah_rd_regmap.h"
66 * The following tables are the master list for all different freqeuncy
67 * bands with the complete matrix of all possible flags and settings
68 * for each band if it is used in ANY reg domain.
71 #define COUNTRY_ERD_FLAG 0x8000
72 #define WORLDWIDE_ROAMING_FLAG 0x4000
75 * This table maps country ISO codes from net80211 into regulatory
76 * domains which the ath regulatory domain code understands.
78 #include "ah_regdomain/ah_rd_ctry.h"
81 * The frequency band collections are a set of frequency ranges
82 * with shared properties - max tx power, max antenna gain, channel width,
83 * channel spacing, DFS requirements and passive scanning requirements.
85 * These are represented as entries in a frequency band bitmask.
86 * Each regulatory domain entry in ah_regdomain_domains.h uses one
87 * or more frequency band entries for each of the channel modes
88 * supported (11bg, 11a, half, quarter, turbo, etc.)
91 #include "ah_regdomain/ah_rd_freqbands.h"
94 * This is the main regulatory database. It defines the supported
95 * set of features and requirements for each of the defined regulatory
96 * zones. It uses combinations of frequency ranges - represented in
97 * a bitmask - to determine the requirements and limitations needed.
99 #include "ah_regdomain/ah_rd_domains.h"
101 static const struct cmode modes[] = {
102 { HAL_MODE_TURBO, IEEE80211_CHAN_ST, ®Dmn5GhzTurboFreq[0] },
103 { HAL_MODE_11A, IEEE80211_CHAN_A, ®Dmn5GhzFreq[0] },
104 { HAL_MODE_11B, IEEE80211_CHAN_B, ®Dmn2GhzFreq[0] },
105 { HAL_MODE_11G, IEEE80211_CHAN_G, ®Dmn2Ghz11gFreq[0] },
106 { HAL_MODE_11G_TURBO, IEEE80211_CHAN_108G, ®Dmn2Ghz11gTurboFreq[0] },
107 { HAL_MODE_11A_TURBO, IEEE80211_CHAN_108A, ®Dmn5GhzTurboFreq[0] },
108 { HAL_MODE_11A_QUARTER_RATE,
109 IEEE80211_CHAN_A | IEEE80211_CHAN_QUARTER, ®Dmn5GhzFreq[0] },
110 { HAL_MODE_11A_HALF_RATE,
111 IEEE80211_CHAN_A | IEEE80211_CHAN_HALF, ®Dmn5GhzFreq[0] },
112 { HAL_MODE_11G_QUARTER_RATE,
113 IEEE80211_CHAN_G | IEEE80211_CHAN_QUARTER, ®Dmn2Ghz11gFreq[0] },
114 { HAL_MODE_11G_HALF_RATE,
115 IEEE80211_CHAN_G | IEEE80211_CHAN_HALF, ®Dmn2Ghz11gFreq[0] },
116 { HAL_MODE_11NG_HT20,
117 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20, ®Dmn2Ghz11gFreq[0] },
118 { HAL_MODE_11NG_HT40PLUS,
119 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U, ®Dmn2Ghz11gFreq[0] },
120 { HAL_MODE_11NG_HT40MINUS,
121 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D, ®Dmn2Ghz11gFreq[0] },
122 { HAL_MODE_11NA_HT20,
123 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20, ®Dmn5GhzFreq[0] },
124 { HAL_MODE_11NA_HT40PLUS,
125 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U, ®Dmn5GhzFreq[0] },
126 { HAL_MODE_11NA_HT40MINUS,
127 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D, ®Dmn5GhzFreq[0] },
130 static void ath_hal_update_dfsdomain(struct ath_hal *ah);
132 static OS_INLINE uint16_t
133 getEepromRD(struct ath_hal *ah)
135 return AH_PRIVATE(ah)->ah_currentRD &~ WORLDWIDE_ROAMING_FLAG;
139 * Test to see if the bitmask array is all zeros
142 isChanBitMaskZero(const uint64_t *bitmask)
145 #error "add more cases"
151 return (bitmask[0] == 0);
155 * Return whether or not the regulatory domain/country in EEPROM
159 isEepromValid(struct ath_hal *ah)
161 uint16_t rd = getEepromRD(ah);
164 if (rd & COUNTRY_ERD_FLAG) {
165 uint16_t cc = rd &~ COUNTRY_ERD_FLAG;
166 for (i = 0; i < N(allCountries); i++)
167 if (allCountries[i].countryCode == cc)
170 for (i = 0; i < N(regDomainPairs); i++)
171 if (regDomainPairs[i].regDmnEnum == rd)
175 if (rd == FCC_UBNT) {
179 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
180 "%s: invalid regulatory domain/country code 0x%x\n", __func__, rd);
185 * Find the pointer to the country element in the country table
186 * corresponding to the country code
188 static COUNTRY_CODE_TO_ENUM_RD*
189 findCountry(HAL_CTRY_CODE countryCode)
193 for (i = 0; i < N(allCountries); i++) {
194 if (allCountries[i].countryCode == countryCode)
195 return &allCountries[i];
201 findRegDmn(int regDmn)
205 for (i = 0; i < N(regDomains); i++) {
206 if (regDomains[i].regDmnEnum == regDmn)
207 return ®Domains[i];
212 static REG_DMN_PAIR_MAPPING *
213 findRegDmnPair(int regDmnPair)
217 if (regDmnPair != NO_ENUMRD) {
218 for (i = 0; i < N(regDomainPairs); i++) {
219 if (regDomainPairs[i].regDmnEnum == regDmnPair)
220 return ®DomainPairs[i];
227 * Calculate a default country based on the EEPROM setting.
230 getDefaultCountry(struct ath_hal *ah)
232 REG_DMN_PAIR_MAPPING *regpair;
235 rd = getEepromRD(ah);
236 if (rd & COUNTRY_ERD_FLAG) {
237 COUNTRY_CODE_TO_ENUM_RD *country;
238 uint16_t cc = rd & ~COUNTRY_ERD_FLAG;
239 country = findCountry(cc);
240 if (country != AH_NULL)
244 * Check reg domains that have only one country
246 regpair = findRegDmnPair(rd);
247 return (regpair != AH_NULL) ? regpair->singleCC : CTRY_DEFAULT;
251 IS_BIT_SET(int bit, const uint64_t bitmask[])
253 int byteOffset, bitnum;
257 bitnum = bit - byteOffset*64;
258 val = ((uint64_t) 1) << bitnum;
259 return (bitmask[byteOffset] & val) != 0;
263 getregstate(struct ath_hal *ah, HAL_CTRY_CODE cc, HAL_REG_DOMAIN regDmn,
264 COUNTRY_CODE_TO_ENUM_RD **pcountry,
265 REG_DOMAIN **prd2GHz, REG_DOMAIN **prd5GHz)
267 COUNTRY_CODE_TO_ENUM_RD *country;
268 REG_DOMAIN *rd5GHz, *rd2GHz;
270 if (cc == CTRY_DEFAULT && regDmn == SKU_NONE) {
272 * Validate the EEPROM setting and setup defaults
274 if (!isEepromValid(ah)) {
276 * Don't return any channels if the EEPROM has an
277 * invalid regulatory domain/country code setting.
279 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
280 "%s: invalid EEPROM contents\n",__func__);
284 cc = getDefaultCountry(ah);
285 country = findCountry(cc);
286 if (country == AH_NULL) {
287 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
288 "NULL Country!, cc %d\n", cc);
291 regDmn = country->regDmnEnum;
292 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s: EEPROM cc %u rd 0x%x\n",
293 __func__, cc, regDmn);
295 if (country->countryCode == CTRY_DEFAULT) {
297 * Check EEPROM; SKU may be for a country, single
298 * domain, or multiple domains (WWR).
300 uint16_t rdnum = getEepromRD(ah);
301 if ((rdnum & COUNTRY_ERD_FLAG) == 0 &&
302 (findRegDmn(rdnum) != AH_NULL ||
303 findRegDmnPair(rdnum) != AH_NULL)) {
305 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
306 "%s: EEPROM rd 0x%x\n", __func__, rdnum);
310 country = findCountry(cc);
311 if (country == AH_NULL) {
312 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
313 "unknown country, cc %d\n", cc);
316 if (regDmn == SKU_NONE)
317 regDmn = country->regDmnEnum;
318 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s: cc %u rd 0x%x\n",
319 __func__, cc, regDmn);
323 * Setup per-band state.
325 if ((regDmn & MULTI_DOMAIN_MASK) == 0) {
326 REG_DMN_PAIR_MAPPING *regpair = findRegDmnPair(regDmn);
327 if (regpair == AH_NULL) {
328 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
329 "%s: no reg domain pair %u for country %u\n",
330 __func__, regDmn, country->countryCode);
333 rd5GHz = findRegDmn(regpair->regDmn5GHz);
334 if (rd5GHz == AH_NULL) {
335 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
336 "%s: no 5GHz reg domain %u for country %u\n",
337 __func__, regpair->regDmn5GHz, country->countryCode);
340 rd2GHz = findRegDmn(regpair->regDmn2GHz);
341 if (rd2GHz == AH_NULL) {
342 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
343 "%s: no 2GHz reg domain %u for country %u\n",
344 __func__, regpair->regDmn2GHz, country->countryCode);
348 rd5GHz = rd2GHz = findRegDmn(regDmn);
349 if (rd2GHz == AH_NULL) {
350 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
351 "%s: no unitary reg domain %u for country %u\n",
352 __func__, regDmn, country->countryCode);
356 if (pcountry != AH_NULL)
364 getchannelBM(u_int mode, REG_DOMAIN *rd)
368 return (rd->chan11b);
369 case HAL_MODE_11G_QUARTER_RATE:
370 return (rd->chan11g_quarter);
371 case HAL_MODE_11G_HALF_RATE:
372 return (rd->chan11g_half);
374 case HAL_MODE_11NG_HT20:
375 case HAL_MODE_11NG_HT40PLUS:
376 case HAL_MODE_11NG_HT40MINUS:
377 return (rd->chan11g);
378 case HAL_MODE_11G_TURBO:
379 return (rd->chan11g_turbo);
380 case HAL_MODE_11A_QUARTER_RATE:
381 return (rd->chan11a_quarter);
382 case HAL_MODE_11A_HALF_RATE:
383 return (rd->chan11a_half);
385 case HAL_MODE_11NA_HT20:
386 case HAL_MODE_11NA_HT40PLUS:
387 case HAL_MODE_11NA_HT40MINUS:
388 return (rd->chan11a);
390 return (rd->chan11a_turbo);
391 case HAL_MODE_11A_TURBO:
392 return (rd->chan11a_dyn_turbo);
399 setchannelflags(struct ieee80211_channel *c, REG_DMN_FREQ_BAND *fband,
402 if (fband->usePassScan & rd->pscan)
403 c->ic_flags |= IEEE80211_CHAN_PASSIVE;
404 if (fband->useDfs & rd->dfsMask)
405 c->ic_flags |= IEEE80211_CHAN_DFS;
406 if (IEEE80211_IS_CHAN_5GHZ(c) && (rd->flags & DISALLOW_ADHOC_11A))
407 c->ic_flags |= IEEE80211_CHAN_NOADHOC;
408 if (IEEE80211_IS_CHAN_TURBO(c) &&
409 (rd->flags & DISALLOW_ADHOC_11A_TURB))
410 c->ic_flags |= IEEE80211_CHAN_NOADHOC;
411 if (rd->flags & NO_HOSTAP)
412 c->ic_flags |= IEEE80211_CHAN_NOHOSTAP;
413 if (rd->flags & LIMIT_FRAME_4MS)
414 c->ic_flags |= IEEE80211_CHAN_4MSXMIT;
415 if (rd->flags & NEED_NFC)
416 c->ic_flags |= CHANNEL_NFCREQUIRED;
420 addchan(struct ath_hal *ah, struct ieee80211_channel chans[],
421 u_int maxchans, int *nchans, uint16_t freq, uint32_t flags,
422 REG_DMN_FREQ_BAND *fband, REG_DOMAIN *rd)
424 struct ieee80211_channel *c;
426 if (*nchans >= maxchans)
429 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
430 "%s: %d: freq=%d, flags=0x%08x\n",
431 __func__, *nchans, (int) freq, flags);
433 c = &chans[(*nchans)++];
436 setchannelflags(c, fband, rd);
437 c->ic_maxregpower = fband->powerDfs;
438 ath_hal_getpowerlimits(ah, c);
439 c->ic_maxantgain = fband->antennaMax;
445 copychan_prev(struct ath_hal *ah, struct ieee80211_channel chans[],
446 u_int maxchans, int *nchans, uint16_t freq, uint32_t flags)
448 struct ieee80211_channel *c;
453 if (*nchans >= maxchans)
456 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
457 "%s: %d: freq=%d, flags=0x%08x\n",
458 __func__, *nchans, (int) freq, flags);
460 c = &chans[(*nchans)++];
463 /* XXX is it needed here? */
464 ath_hal_getpowerlimits(ah, c);
470 add_chanlist_band(struct ath_hal *ah, struct ieee80211_channel chans[],
471 int maxchans, int *nchans, uint16_t freq_lo, uint16_t freq_hi, int step,
472 uint32_t flags, REG_DMN_FREQ_BAND *fband, REG_DOMAIN *rd)
474 uint16_t freq = freq_lo;
477 if (freq_hi < freq_lo)
480 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
481 "%s: freq=%d..%d, flags=0x%08x, step=%d\n", __func__,
482 (int) freq_lo, (int) freq_hi, flags, step);
484 error = addchan(ah, chans, maxchans, nchans, freq, flags, fband, rd);
485 for (freq += step; freq <= freq_hi && error == 0; freq += step)
486 error = copychan_prev(ah, chans, maxchans, nchans, freq, flags);
492 adj_freq_ht40(u_int mode, int *low_adj, int *hi_adj, int *channelSep)
495 *low_adj = *hi_adj = *channelSep = 0;
497 case HAL_MODE_11NA_HT40PLUS:
500 case HAL_MODE_11NG_HT40PLUS:
503 case HAL_MODE_11NA_HT40MINUS:
506 case HAL_MODE_11NG_HT40MINUS:
513 add_chanlist_mode(struct ath_hal *ah, struct ieee80211_channel chans[],
514 u_int maxchans, int *nchans, const struct cmode *cm, REG_DOMAIN *rd,
515 HAL_BOOL enableExtendedChannels)
518 uint16_t freq_lo, freq_hi;
519 int b, error, low_adj, hi_adj, channelSep;
521 if (!ath_hal_getChannelEdges(ah, cm->flags, &freq_lo, &freq_hi)) {
522 /* channel not supported by hardware, skip it */
523 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
524 "%s: channels 0x%x not supported by hardware\n",
525 __func__, cm->flags);
529 channelBM = getchannelBM(cm->mode, rd);
530 if (isChanBitMaskZero(channelBM))
534 * Setup special handling for HT40 channels; e.g.
535 * 5G HT40 channels require 40Mhz channel separation.
537 adj_freq_ht40(cm->mode, &low_adj, &hi_adj, &channelSep);
539 for (b = 0; b < 64*BMLEN; b++) {
540 REG_DMN_FREQ_BAND *fband;
541 uint16_t bfreq_lo, bfreq_hi;
544 if (!IS_BIT_SET(b, channelBM))
546 fband = &cm->freqs[b];
548 if ((fband->usePassScan & IS_ECM_CHAN) &&
549 !enableExtendedChannels) {
550 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
551 "skip ecm channels\n");
555 if ((fband->useDfs & rd->dfsMask) &&
556 (cm->flags & IEEE80211_CHAN_HT40)) {
557 /* NB: DFS and HT40 don't mix */
558 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
559 "skip HT40 chan, DFS required\n");
564 * XXX TODO: handle REG_EXT_FCC_CH_144.
566 * Figure out which instances/uses cause us to not
567 * be allowed to use channel 144 (pri or sec overlap.)
570 bfreq_lo = MAX(fband->lowChannel + low_adj, freq_lo);
571 bfreq_hi = MIN(fband->highChannel + hi_adj, freq_hi);
574 * Don't start the 5GHz channel list at 5120MHz.
576 * Unfortunately (sigh) the HT40 channel creation
577 * logic will create HT40U channels at 5120, 5160, 5200.
578 * This means that 36 (5180) isn't considered as a
579 * HT40 channel, and everything goes messed up from there.
581 if ((cm->flags & IEEE80211_CHAN_5GHZ) &&
582 (cm->flags & IEEE80211_CHAN_HT40U)) {
588 * Same with HT40D - need to start at 5200 or the low
589 * channels are all wrong again.
591 if ((cm->flags & IEEE80211_CHAN_5GHZ) &&
592 (cm->flags & IEEE80211_CHAN_HT40D)) {
597 if (fband->channelSep >= channelSep)
598 step = fband->channelSep;
600 step = roundup(channelSep, fband->channelSep);
602 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
603 "%s: freq_lo=%d, freq_hi=%d, low_adj=%d, hi_adj=%d, "
604 "bandlo=%d, bandhi=%d, bfreqlo=%d, bfreqhi=%d, step=%d, "
611 (int) fband->lowChannel,
612 (int) fband->highChannel,
618 error = add_chanlist_band(ah, chans, maxchans, nchans,
619 bfreq_lo, bfreq_hi, step, cm->flags, fband, rd);
621 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
622 "%s: too many channels for channel table\n",
630 getmodesmask(struct ath_hal *ah, REG_DOMAIN *rd5GHz, u_int modeSelect)
632 #define HAL_MODE_11A_ALL \
633 (HAL_MODE_11A | HAL_MODE_11A_TURBO | HAL_MODE_TURBO | \
634 HAL_MODE_11A_QUARTER_RATE | HAL_MODE_11A_HALF_RATE)
637 /* get modes that HW is capable of */
638 modesMask = ath_hal_getWirelessModes(ah);
639 modesMask &= modeSelect;
640 /* optimize work below if no 11a channels */
641 if (isChanBitMaskZero(rd5GHz->chan11a) &&
642 (modesMask & HAL_MODE_11A_ALL)) {
643 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
644 "%s: disallow all 11a\n", __func__);
645 modesMask &= ~HAL_MODE_11A_ALL;
649 #undef HAL_MODE_11A_ALL
653 * Construct the channel list for the specified regulatory config.
656 getchannels(struct ath_hal *ah,
657 struct ieee80211_channel chans[], u_int maxchans, int *nchans,
658 u_int modeSelect, HAL_CTRY_CODE cc, HAL_REG_DOMAIN regDmn,
659 HAL_BOOL enableExtendedChannels,
660 COUNTRY_CODE_TO_ENUM_RD **pcountry,
661 REG_DOMAIN **prd2GHz, REG_DOMAIN **prd5GHz)
663 REG_DOMAIN *rd5GHz, *rd2GHz;
665 const struct cmode *cm;
668 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s: cc %u regDmn 0x%x mode 0x%x%s\n",
669 __func__, cc, regDmn, modeSelect,
670 enableExtendedChannels ? " ecm" : "");
672 status = getregstate(ah, cc, regDmn, pcountry, &rd2GHz, &rd5GHz);
673 if (status != HAL_OK)
676 modesMask = getmodesmask(ah, rd5GHz, modeSelect);
681 for (cm = modes; cm < &modes[N(modes)]; cm++) {
684 if ((cm->mode & modesMask) == 0) {
685 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
686 "%s: skip mode 0x%x flags 0x%x\n",
687 __func__, cm->mode, cm->flags);
691 if (cm->flags & IEEE80211_CHAN_5GHZ)
693 else if (cm->flags & IEEE80211_CHAN_2GHZ)
696 ath_hal_printf(ah, "%s: Unkonwn HAL flags 0x%x\n",
697 __func__, cm->flags);
701 add_chanlist_mode(ah, chans, maxchans, nchans, cm,
702 rd, enableExtendedChannels);
703 if (*nchans >= maxchans)
707 /* NB: pcountry set above by getregstate */
708 if (prd2GHz != AH_NULL)
710 if (prd5GHz != AH_NULL)
716 * Retrieve a channel list without affecting runtime state.
719 ath_hal_getchannels(struct ath_hal *ah,
720 struct ieee80211_channel chans[], u_int maxchans, int *nchans,
721 u_int modeSelect, HAL_CTRY_CODE cc, HAL_REG_DOMAIN regDmn,
722 HAL_BOOL enableExtendedChannels)
724 return getchannels(ah, chans, maxchans, nchans, modeSelect,
725 cc, regDmn, enableExtendedChannels, AH_NULL, AH_NULL, AH_NULL);
729 * Handle frequency mapping from 900Mhz range to 2.4GHz range
730 * for GSM radios. This is done when we need the h/w frequency
731 * and the channel is marked IEEE80211_CHAN_GSM.
734 ath_hal_mapgsm(int sku, int freq)
738 if (sku == SKU_GZ901)
742 if (sku == SKU_XC900M)
744 HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
745 "%s: cannot map freq %u unknown gsm sku %u\n",
746 __func__, freq, sku);
751 * Setup the internal/private channel state given a table of
752 * net80211 channels. We collapse entries for the same frequency
753 * and record the frequency for doing noise floor processing
754 * where we don't have net80211 channel context.
757 assignPrivateChannels(struct ath_hal *ah,
758 struct ieee80211_channel chans[], int nchans, int sku)
760 HAL_CHANNEL_INTERNAL *ic;
761 int i, j, next, freq;
764 for (i = 0; i < nchans; i++) {
765 struct ieee80211_channel *c = &chans[i];
766 for (j = i-1; j >= 0; j--)
767 if (chans[j].ic_freq == c->ic_freq) {
768 c->ic_devdata = chans[j].ic_devdata;
772 /* new entry, assign a private channel entry */
773 if (next >= N(AH_PRIVATE(ah)->ah_channels)) {
774 HALDEBUG(ah, HAL_DEBUG_ANY,
775 "%s: too many channels, max %zu\n",
776 __func__, N(AH_PRIVATE(ah)->ah_channels));
780 * Handle frequency mapping for 900MHz devices.
781 * The hardware uses 2.4GHz frequencies that are
782 * down-converted. The 802.11 layer uses the
785 freq = IEEE80211_IS_CHAN_GSM(c) ?
786 ath_hal_mapgsm(sku, c->ic_freq) : c->ic_freq;
788 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN,
789 "%s: private[%3u] %u/0x%x -> channel %u\n",
790 __func__, next, c->ic_freq, c->ic_flags, freq);
792 ic = &AH_PRIVATE(ah)->ah_channels[next];
794 * NB: This clears privFlags which means ancillary
795 * code like ANI and IQ calibration will be
796 * restarted and re-setup any per-channel state.
798 OS_MEMZERO(ic, sizeof(*ic));
800 c->ic_devdata = next;
804 AH_PRIVATE(ah)->ah_nchan = next;
805 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: %u public, %u private channels\n",
806 __func__, nchans, next);
811 * Setup the channel list based on the information in the EEPROM.
814 ath_hal_init_channels(struct ath_hal *ah,
815 struct ieee80211_channel chans[], u_int maxchans, int *nchans,
816 u_int modeSelect, HAL_CTRY_CODE cc, HAL_REG_DOMAIN regDmn,
817 HAL_BOOL enableExtendedChannels)
819 COUNTRY_CODE_TO_ENUM_RD *country;
820 REG_DOMAIN *rd5GHz, *rd2GHz;
823 status = getchannels(ah, chans, maxchans, nchans, modeSelect,
824 cc, regDmn, enableExtendedChannels, &country, &rd2GHz, &rd5GHz);
825 if (status == HAL_OK &&
826 assignPrivateChannels(ah, chans, *nchans, AH_PRIVATE(ah)->ah_currentRD)) {
827 AH_PRIVATE(ah)->ah_rd2GHz = rd2GHz;
828 AH_PRIVATE(ah)->ah_rd5GHz = rd5GHz;
830 ah->ah_countryCode = country->countryCode;
831 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s: cc %u\n",
832 __func__, ah->ah_countryCode);
834 /* Update current DFS domain */
835 ath_hal_update_dfsdomain(ah);
843 * Set the channel list.
846 ath_hal_set_channels(struct ath_hal *ah,
847 struct ieee80211_channel chans[], int nchans,
848 HAL_CTRY_CODE cc, HAL_REG_DOMAIN rd)
850 COUNTRY_CODE_TO_ENUM_RD *country;
851 REG_DOMAIN *rd5GHz, *rd2GHz;
860 * Map 900MHz sku's. The frequencies will be mapped
861 * according to the sku to compensate for the down-converter.
862 * We use the FCC for these sku's as the mapped channel
863 * list is known compatible (will need to change if/when
864 * vendors do different mapping in different locales).
866 status = getregstate(ah, CTRY_DEFAULT, SKU_FCC,
867 &country, &rd2GHz, &rd5GHz);
870 status = getregstate(ah, cc, rd,
871 &country, &rd2GHz, &rd5GHz);
872 rd = AH_PRIVATE(ah)->ah_currentRD;
875 if (status == HAL_OK && assignPrivateChannels(ah, chans, nchans, rd)) {
876 AH_PRIVATE(ah)->ah_rd2GHz = rd2GHz;
877 AH_PRIVATE(ah)->ah_rd5GHz = rd5GHz;
879 ah->ah_countryCode = country->countryCode;
880 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s: cc %u\n",
881 __func__, ah->ah_countryCode);
885 if (status == HAL_OK) {
886 /* Update current DFS domain */
887 (void) ath_hal_update_dfsdomain(ah);
894 * Return the internal channel corresponding to a public channel.
895 * NB: normally this routine is inline'd (see ah_internal.h)
897 HAL_CHANNEL_INTERNAL *
898 ath_hal_checkchannel(struct ath_hal *ah, const struct ieee80211_channel *c)
900 HAL_CHANNEL_INTERNAL *cc = &AH_PRIVATE(ah)->ah_channels[c->ic_devdata];
902 if (c->ic_devdata < AH_PRIVATE(ah)->ah_nchan &&
903 (c->ic_freq == cc->channel || IEEE80211_IS_CHAN_GSM(c)))
905 if (c->ic_devdata >= AH_PRIVATE(ah)->ah_nchan) {
906 HALDEBUG(ah, HAL_DEBUG_ANY,
907 "%s: bad mapping, devdata %u nchans %u\n",
908 __func__, c->ic_devdata, AH_PRIVATE(ah)->ah_nchan);
909 HALASSERT(c->ic_devdata < AH_PRIVATE(ah)->ah_nchan);
911 HALDEBUG(ah, HAL_DEBUG_ANY,
912 "%s: no match for %u/0x%x devdata %u channel %u\n",
913 __func__, c->ic_freq, c->ic_flags, c->ic_devdata,
915 HALASSERT(c->ic_freq == cc->channel || IEEE80211_IS_CHAN_GSM(c));
919 #endif /* AH_DEBUG */
921 #define isWwrSKU(_ah) \
922 ((getEepromRD((_ah)) & WORLD_SKU_MASK) == WORLD_SKU_PREFIX || \
923 getEepromRD(_ah) == WORLD)
926 * Return the test group for the specific channel based on
927 * the current regulatory setup.
930 ath_hal_getctl(struct ath_hal *ah, const struct ieee80211_channel *c)
934 if (AH_PRIVATE(ah)->ah_rd2GHz == AH_PRIVATE(ah)->ah_rd5GHz ||
935 (ah->ah_countryCode == CTRY_DEFAULT && isWwrSKU(ah)))
937 else if (IEEE80211_IS_CHAN_2GHZ(c))
938 ctl = AH_PRIVATE(ah)->ah_rd2GHz->conformanceTestLimit;
940 ctl = AH_PRIVATE(ah)->ah_rd5GHz->conformanceTestLimit;
941 if (IEEE80211_IS_CHAN_B(c))
942 return ctl | CTL_11B;
943 if (IEEE80211_IS_CHAN_G(c))
944 return ctl | CTL_11G;
945 if (IEEE80211_IS_CHAN_108G(c))
946 return ctl | CTL_108G;
947 if (IEEE80211_IS_CHAN_TURBO(c))
948 return ctl | CTL_TURBO;
949 if (IEEE80211_IS_CHAN_A(c))
950 return ctl | CTL_11A;
956 * Update the current dfsDomain setting based on the given
959 * Since FreeBSD/net80211 allows the channel set to change
960 * after the card has been setup (via ath_hal_init_channels())
961 * this function method is needed to update ah_dfsDomain.
964 ath_hal_update_dfsdomain(struct ath_hal *ah)
966 const REG_DOMAIN *rd5GHz = AH_PRIVATE(ah)->ah_rd5GHz;
967 HAL_DFS_DOMAIN dfsDomain = HAL_DFS_UNINIT_DOMAIN;
969 if (rd5GHz->dfsMask & DFS_FCC3)
970 dfsDomain = HAL_DFS_FCC_DOMAIN;
971 if (rd5GHz->dfsMask & DFS_ETSI)
972 dfsDomain = HAL_DFS_ETSI_DOMAIN;
973 if (rd5GHz->dfsMask & DFS_MKK4)
974 dfsDomain = HAL_DFS_MKK4_DOMAIN;
975 AH_PRIVATE(ah)->ah_dfsDomain = dfsDomain;
976 HALDEBUG(ah, HAL_DEBUG_REGDOMAIN, "%s ah_dfsDomain: %d\n",
977 __func__, AH_PRIVATE(ah)->ah_dfsDomain);
982 * Return the max allowed antenna gain and apply any regulatory
983 * domain specific changes.
985 * NOTE: a negative reduction is possible in RD's that only
986 * measure radiated power (e.g., ETSI) which would increase
987 * that actual conducted output power (though never beyond
988 * the calibrated target power).
991 ath_hal_getantennareduction(struct ath_hal *ah,
992 const struct ieee80211_channel *chan, u_int twiceGain)
994 int8_t antennaMax = twiceGain - chan->ic_maxantgain*2;
995 return (antennaMax < 0) ? 0 : antennaMax;