Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/slab.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 19 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | #include "regd_common.h" |
| 21 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 22 | /* |
| 23 | * This is a set of common rules used by our world regulatory domains. |
| 24 | * We have 12 world regulatory domains. To save space we consolidate |
| 25 | * the regulatory domains in 5 structures by frequency and change |
| 26 | * the flags on our reg_notifier() on a case by case basis. |
| 27 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 28 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 29 | /* Only these channels all allow active scan on all world regulatory domains */ |
| 30 | #define ATH9K_2GHZ_CH01_11 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 31 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 32 | /* We enable active scan on these a case by case basis by regulatory domain */ |
| 33 | #define ATH9K_2GHZ_CH12_13 REG_RULE(2467-10, 2472+10, 40, 0, 20,\ |
| 34 | NL80211_RRF_PASSIVE_SCAN) |
| 35 | #define ATH9K_2GHZ_CH14 REG_RULE(2484-10, 2484+10, 40, 0, 20,\ |
| 36 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 38 | /* We allow IBSS on these on a case by case basis by regulatory domain */ |
| 39 | #define ATH9K_5GHZ_5150_5350 REG_RULE(5150-10, 5350+10, 40, 0, 30,\ |
| 40 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 41 | #define ATH9K_5GHZ_5470_5850 REG_RULE(5470-10, 5850+10, 40, 0, 30,\ |
| 42 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 43 | #define ATH9K_5GHZ_5725_5850 REG_RULE(5725-10, 5850+10, 40, 0, 30,\ |
| 44 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 45 | |
| 46 | #define ATH9K_2GHZ_ALL ATH9K_2GHZ_CH01_11, \ |
| 47 | ATH9K_2GHZ_CH12_13, \ |
| 48 | ATH9K_2GHZ_CH14 |
| 49 | |
| 50 | #define ATH9K_5GHZ_ALL ATH9K_5GHZ_5150_5350, \ |
| 51 | ATH9K_5GHZ_5470_5850 |
| 52 | /* This one skips what we call "mid band" */ |
| 53 | #define ATH9K_5GHZ_NO_MIDBAND ATH9K_5GHZ_5150_5350, \ |
| 54 | ATH9K_5GHZ_5725_5850 |
| 55 | |
| 56 | /* Can be used for: |
| 57 | * 0x60, 0x61, 0x62 */ |
| 58 | static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = { |
| 59 | .n_reg_rules = 5, |
| 60 | .alpha2 = "99", |
| 61 | .reg_rules = { |
| 62 | ATH9K_2GHZ_ALL, |
| 63 | ATH9K_5GHZ_ALL, |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | /* Can be used by 0x63 and 0x65 */ |
| 68 | static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = { |
| 69 | .n_reg_rules = 4, |
| 70 | .alpha2 = "99", |
| 71 | .reg_rules = { |
| 72 | ATH9K_2GHZ_CH01_11, |
| 73 | ATH9K_2GHZ_CH12_13, |
| 74 | ATH9K_5GHZ_NO_MIDBAND, |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | /* Can be used by 0x64 only */ |
| 79 | static const struct ieee80211_regdomain ath9k_world_regdom_64 = { |
| 80 | .n_reg_rules = 3, |
| 81 | .alpha2 = "99", |
| 82 | .reg_rules = { |
| 83 | ATH9K_2GHZ_CH01_11, |
| 84 | ATH9K_5GHZ_NO_MIDBAND, |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | /* Can be used by 0x66 and 0x69 */ |
| 89 | static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = { |
| 90 | .n_reg_rules = 3, |
| 91 | .alpha2 = "99", |
| 92 | .reg_rules = { |
| 93 | ATH9K_2GHZ_CH01_11, |
| 94 | ATH9K_5GHZ_ALL, |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | /* Can be used by 0x67, 0x6A and 0x68 */ |
| 99 | static const struct ieee80211_regdomain ath9k_world_regdom_67_68_6A = { |
| 100 | .n_reg_rules = 4, |
| 101 | .alpha2 = "99", |
| 102 | .reg_rules = { |
| 103 | ATH9K_2GHZ_CH01_11, |
| 104 | ATH9K_2GHZ_CH12_13, |
| 105 | ATH9K_5GHZ_ALL, |
| 106 | } |
| 107 | }; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 108 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 109 | static u16 ath9k_regd_get_eepromRD(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 110 | { |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 111 | return ah->regulatory.current_rd & ~WORLDWIDE_ROAMING_FLAG; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 114 | u16 ath9k_regd_get_rd(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 115 | { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 116 | return ath9k_regd_get_eepromRD(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 119 | bool ath9k_is_world_regd(struct ath_hw *ah) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 120 | { |
| 121 | return isWwrSKU(ah); |
| 122 | } |
| 123 | |
| 124 | const struct ieee80211_regdomain *ath9k_default_world_regdomain(void) |
| 125 | { |
| 126 | /* this is the most restrictive */ |
| 127 | return &ath9k_world_regdom_64; |
| 128 | } |
| 129 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 130 | const struct ieee80211_regdomain *ath9k_world_regdomain(struct ath_hw *ah) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 131 | { |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 132 | switch (ah->regulatory.regpair->regDmnEnum) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 133 | case 0x60: |
| 134 | case 0x61: |
| 135 | case 0x62: |
| 136 | return &ath9k_world_regdom_60_61_62; |
| 137 | case 0x63: |
| 138 | case 0x65: |
| 139 | return &ath9k_world_regdom_63_65; |
| 140 | case 0x64: |
| 141 | return &ath9k_world_regdom_64; |
| 142 | case 0x66: |
| 143 | case 0x69: |
| 144 | return &ath9k_world_regdom_66_69; |
| 145 | case 0x67: |
| 146 | case 0x68: |
| 147 | case 0x6A: |
| 148 | return &ath9k_world_regdom_67_68_6A; |
| 149 | default: |
| 150 | WARN_ON(1); |
| 151 | return ath9k_default_world_regdomain(); |
| 152 | } |
| 153 | } |
| 154 | |
Luis R. Rodriguez | 547e4c2 | 2009-01-28 12:17:48 -0800 | [diff] [blame] | 155 | /* Frequency is one where radar detection is required */ |
| 156 | static bool ath9k_is_radar_freq(u16 center_freq) |
| 157 | { |
| 158 | return (center_freq >= 5260 && center_freq <= 5700); |
| 159 | } |
| 160 | |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 161 | /* |
| 162 | * Enable adhoc on 5 GHz if allowed by 11d. |
| 163 | * Remove passive scan if channel is allowed by 11d, |
| 164 | * except when on radar frequencies. |
| 165 | */ |
| 166 | static void ath9k_reg_apply_5ghz_beaconing_flags(struct wiphy *wiphy, |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 167 | enum reg_set_by setby) |
| 168 | { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 169 | struct ieee80211_supported_band *sband; |
| 170 | const struct ieee80211_reg_rule *reg_rule; |
| 171 | struct ieee80211_channel *ch; |
| 172 | unsigned int i; |
| 173 | u32 bandwidth = 0; |
| 174 | int r; |
| 175 | |
| 176 | if (setby != REGDOM_SET_BY_COUNTRY_IE) |
| 177 | return; |
Luis R. Rodriguez | 8c63c46 | 2009-01-28 12:17:47 -0800 | [diff] [blame] | 178 | if (!wiphy->bands[IEEE80211_BAND_5GHZ]) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 179 | return; |
| 180 | |
| 181 | sband = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 182 | for (i = 0; i < sband->n_channels; i++) { |
| 183 | ch = &sband->channels[i]; |
| 184 | r = freq_reg_info(wiphy, ch->center_freq, |
| 185 | &bandwidth, ®_rule); |
| 186 | if (r) |
| 187 | continue; |
| 188 | /* If 11d had a rule for this channel ensure we enable adhoc |
| 189 | * if it allows us to use it. Note that we would have disabled |
| 190 | * it by applying our static world regdomain by default during |
| 191 | * probe */ |
| 192 | if (!(reg_rule->flags & NL80211_RRF_NO_IBSS)) |
Luis R. Rodriguez | de9f97e | 2009-02-02 20:35:05 -0800 | [diff] [blame] | 193 | ch->flags &= ~IEEE80211_CHAN_NO_IBSS; |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 194 | if (!ath9k_is_radar_freq(ch->center_freq)) |
| 195 | continue; |
| 196 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
Luis R. Rodriguez | de9f97e | 2009-02-02 20:35:05 -0800 | [diff] [blame] | 197 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | /* Allows active scan scan on Ch 12 and 13 */ |
| 202 | static void ath9k_reg_apply_active_scan_flags(struct wiphy *wiphy, |
| 203 | enum reg_set_by setby) |
| 204 | { |
| 205 | struct ieee80211_supported_band *sband; |
| 206 | struct ieee80211_channel *ch; |
| 207 | const struct ieee80211_reg_rule *reg_rule; |
| 208 | u32 bandwidth = 0; |
| 209 | int r; |
| 210 | |
| 211 | /* Force passive scan on Channels 12-13 */ |
| 212 | sband = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 213 | |
| 214 | /* If no country IE has been received always enable active scan |
| 215 | * on these channels */ |
| 216 | if (setby != REGDOM_SET_BY_COUNTRY_IE) { |
| 217 | ch = &sband->channels[11]; /* CH 12 */ |
| 218 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 219 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 220 | ch = &sband->channels[12]; /* CH 13 */ |
| 221 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 222 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | /* If a country IE has been recieved check its rule for this |
| 227 | * channel first before enabling active scan. The passive scan |
| 228 | * would have been enforced by the initial probe processing on |
| 229 | * our custom regulatory domain. */ |
| 230 | |
| 231 | ch = &sband->channels[11]; /* CH 12 */ |
| 232 | r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, ®_rule); |
| 233 | if (!r) { |
| 234 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
| 235 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 236 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 237 | } |
| 238 | |
| 239 | ch = &sband->channels[12]; /* CH 13 */ |
| 240 | r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, ®_rule); |
| 241 | if (!r) { |
| 242 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
| 243 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 244 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */ |
| 249 | void ath9k_reg_apply_radar_flags(struct wiphy *wiphy) |
| 250 | { |
| 251 | struct ieee80211_supported_band *sband; |
| 252 | struct ieee80211_channel *ch; |
| 253 | unsigned int i; |
| 254 | |
| 255 | if (!wiphy->bands[IEEE80211_BAND_5GHZ]) |
| 256 | return; |
| 257 | |
| 258 | sband = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 259 | |
| 260 | for (i = 0; i < sband->n_channels; i++) { |
| 261 | ch = &sband->channels[i]; |
Luis R. Rodriguez | 547e4c2 | 2009-01-28 12:17:48 -0800 | [diff] [blame] | 262 | if (!ath9k_is_radar_freq(ch->center_freq)) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 263 | continue; |
| 264 | /* We always enable radar detection/DFS on this |
| 265 | * frequency range. Additionally we also apply on |
| 266 | * this frequency range: |
| 267 | * - If STA mode does not yet have DFS supports disable |
| 268 | * active scanning |
| 269 | * - If adhoc mode does not support DFS yet then |
| 270 | * disable adhoc in the frequency. |
| 271 | * - If AP mode does not yet support radar detection/DFS |
| 272 | * do not allow AP mode |
| 273 | */ |
| 274 | if (!(ch->flags & IEEE80211_CHAN_DISABLED)) |
| 275 | ch->flags |= IEEE80211_CHAN_RADAR | |
| 276 | IEEE80211_CHAN_NO_IBSS | |
| 277 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | void ath9k_reg_apply_world_flags(struct wiphy *wiphy, enum reg_set_by setby) |
| 282 | { |
| 283 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 284 | struct ath_softc *sc = hw->priv; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 285 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 286 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 287 | switch (ah->regulatory.regpair->regDmnEnum) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 288 | case 0x60: |
| 289 | case 0x63: |
| 290 | case 0x66: |
| 291 | case 0x67: |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 292 | ath9k_reg_apply_5ghz_beaconing_flags(wiphy, setby); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 293 | break; |
| 294 | case 0x68: |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 295 | ath9k_reg_apply_5ghz_beaconing_flags(wiphy, setby); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 296 | ath9k_reg_apply_active_scan_flags(wiphy, setby); |
| 297 | break; |
| 298 | } |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) |
| 303 | { |
| 304 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 305 | struct ath_softc *sc = hw->priv; |
| 306 | |
| 307 | /* We always apply this */ |
| 308 | ath9k_reg_apply_radar_flags(wiphy); |
| 309 | |
| 310 | switch (request->initiator) { |
| 311 | case REGDOM_SET_BY_DRIVER: |
| 312 | case REGDOM_SET_BY_INIT: |
| 313 | case REGDOM_SET_BY_CORE: |
| 314 | case REGDOM_SET_BY_USER: |
| 315 | break; |
| 316 | case REGDOM_SET_BY_COUNTRY_IE: |
| 317 | if (ath9k_is_world_regd(sc->sc_ah)) |
| 318 | ath9k_reg_apply_world_flags(wiphy, request->initiator); |
| 319 | break; |
| 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 325 | bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 326 | { |
| 327 | u16 rd = ath9k_regd_get_eepromRD(ah); |
| 328 | int i; |
| 329 | |
| 330 | if (rd & COUNTRY_ERD_FLAG) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 331 | /* EEPROM value is a country code */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 332 | u16 cc = rd & ~COUNTRY_ERD_FLAG; |
| 333 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) |
| 334 | if (allCountries[i].countryCode == cc) |
| 335 | return true; |
| 336 | } else { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 337 | /* EEPROM value is a regpair value */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 338 | for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) |
| 339 | if (regDomainPairs[i].regDmnEnum == rd) |
| 340 | return true; |
| 341 | } |
| 342 | DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 343 | "invalid regulatory domain/country code 0x%x\n", rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 344 | return false; |
| 345 | } |
| 346 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 347 | /* EEPROM country code to regpair mapping */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 348 | static struct country_code_to_enum_rd* |
| 349 | ath9k_regd_find_country(u16 countryCode) |
| 350 | { |
| 351 | int i; |
| 352 | |
| 353 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) { |
| 354 | if (allCountries[i].countryCode == countryCode) |
| 355 | return &allCountries[i]; |
| 356 | } |
| 357 | return NULL; |
| 358 | } |
| 359 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 360 | /* EEPROM rd code to regpair mapping */ |
| 361 | static struct country_code_to_enum_rd* |
| 362 | ath9k_regd_find_country_by_rd(int regdmn) |
| 363 | { |
| 364 | int i; |
| 365 | |
| 366 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) { |
| 367 | if (allCountries[i].regDmnEnum == regdmn) |
| 368 | return &allCountries[i]; |
| 369 | } |
| 370 | return NULL; |
| 371 | } |
| 372 | |
| 373 | /* Returns the map of the EEPROM set RD to a country code */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 374 | static u16 ath9k_regd_get_default_country(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 375 | { |
| 376 | u16 rd; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 377 | |
| 378 | rd = ath9k_regd_get_eepromRD(ah); |
| 379 | if (rd & COUNTRY_ERD_FLAG) { |
| 380 | struct country_code_to_enum_rd *country = NULL; |
| 381 | u16 cc = rd & ~COUNTRY_ERD_FLAG; |
| 382 | |
| 383 | country = ath9k_regd_find_country(cc); |
| 384 | if (country != NULL) |
| 385 | return cc; |
| 386 | } |
| 387 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 388 | return CTRY_DEFAULT; |
| 389 | } |
| 390 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 391 | static struct reg_dmn_pair_mapping* |
| 392 | ath9k_get_regpair(int regdmn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 393 | { |
| 394 | int i; |
| 395 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 396 | if (regdmn == NO_ENUMRD) |
| 397 | return NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 398 | for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 399 | if (regDomainPairs[i].regDmnEnum == regdmn) |
| 400 | return ®DomainPairs[i]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 401 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 402 | return NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 405 | int ath9k_regd_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 406 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 407 | struct country_code_to_enum_rd *country = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 408 | int regdmn; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 409 | |
| 410 | if (!ath9k_regd_is_eeprom_valid(ah)) { |
| 411 | DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 412 | "Invalid EEPROM contents\n"); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 413 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 416 | ah->regulatory.country_code = ath9k_regd_get_default_country(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 417 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 418 | if (ah->regulatory.country_code == CTRY_DEFAULT && |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 419 | ath9k_regd_get_eepromRD(ah) == CTRY_DEFAULT) |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 420 | ah->regulatory.country_code = CTRY_UNITED_STATES; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 421 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 422 | if (ah->regulatory.country_code == CTRY_DEFAULT) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 423 | regdmn = ath9k_regd_get_eepromRD(ah); |
| 424 | country = NULL; |
| 425 | } else { |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 426 | country = ath9k_regd_find_country(ah->regulatory.country_code); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 427 | if (country == NULL) { |
| 428 | DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, |
| 429 | "Country is NULL!!!!, cc= %d\n", |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 430 | ah->regulatory.country_code); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 431 | return -EINVAL; |
| 432 | } else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 433 | regdmn = country->regDmnEnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 434 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 435 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 436 | ah->regulatory.current_rd_inuse = regdmn; |
| 437 | ah->regulatory.regpair = ath9k_get_regpair(regdmn); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 438 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 439 | if (!ah->regulatory.regpair) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 440 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
| 441 | "No regulatory domain pair found, cannot continue\n"); |
| 442 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 445 | if (!country) |
| 446 | country = ath9k_regd_find_country_by_rd(regdmn); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 447 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 448 | if (country) { |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 449 | ah->regulatory.alpha2[0] = country->isoName[0]; |
| 450 | ah->regulatory.alpha2[1] = country->isoName[1]; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 451 | } else { |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 452 | ah->regulatory.alpha2[0] = '0'; |
| 453 | ah->regulatory.alpha2[1] = '0'; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 454 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 455 | |
| 456 | DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, |
Luis R. Rodriguez | 0c6666e | 2009-01-26 06:48:10 -0800 | [diff] [blame] | 457 | "Country alpha2 being used: %c%c\n" |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 458 | "Regulatory.Regpair detected: 0x%0x\n", |
| 459 | ah->regulatory.alpha2[0], ah->regulatory.alpha2[1], |
| 460 | ah->regulatory.regpair->regDmnEnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 461 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 462 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame^] | 465 | u32 ath9k_regd_get_ctl(struct ath_hw *ah, struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 466 | { |
| 467 | u32 ctl = NO_CTL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 469 | if (!ah->regulatory.regpair || |
| 470 | (ah->regulatory.country_code == CTRY_DEFAULT && isWwrSKU(ah))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 471 | if (IS_CHAN_B(chan)) |
| 472 | ctl = SD_NO_CTL | CTL_11B; |
| 473 | else if (IS_CHAN_G(chan)) |
| 474 | ctl = SD_NO_CTL | CTL_11G; |
| 475 | else |
| 476 | ctl = SD_NO_CTL | CTL_11A; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 477 | return ctl; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 478 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 479 | |
| 480 | if (IS_CHAN_B(chan)) |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 481 | ctl = ah->regulatory.regpair->reg_2ghz_ctl | CTL_11B; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 482 | else if (IS_CHAN_G(chan)) |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 483 | ctl = ah->regulatory.regpair->reg_5ghz_ctl | CTL_11G; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 484 | else |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 485 | ctl = ah->regulatory.regpair->reg_5ghz_ctl | CTL_11A; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 486 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 487 | return ctl; |
| 488 | } |