aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Copeland <me@bobcopeland.com>2009-03-30 22:30:29 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-04-22 16:54:37 -0400
commit3a702e49c03ba959e3f5bb2b74ec9921a81c8c98 (patch)
tree721e8a222648284660f5bf6c5edfba5a6e4d4527
parentc02cf3738c9dbc446c160b9d49a001eb2be316c8 (diff)
atheros: introduce ath module containing common ath5k/ath9k/ar9170 code
This change creates a new module, ath.ko, which includes code that can be shared between ath5k, ath9k and ar9170. For now, extract most of the ath9k regulatory code so it can also be used in ath5k. Signed-off-by: Bob Copeland <me@bobcopeland.com> Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/Kconfig1
-rw-r--r--drivers/net/wireless/Makefile1
-rw-r--r--drivers/net/wireless/ath/Kconfig4
-rw-r--r--drivers/net/wireless/ath/Makefile3
-rw-r--r--drivers/net/wireless/ath/regd.c (renamed from drivers/net/wireless/ath9k/regd.c)154
-rw-r--r--drivers/net/wireless/ath/regd.h (renamed from drivers/net/wireless/ath9k/regd.h)48
-rw-r--r--drivers/net/wireless/ath/regd_common.h (renamed from drivers/net/wireless/ath9k/regd_common.h)0
-rw-r--r--drivers/net/wireless/ath9k/Kconfig1
-rw-r--r--drivers/net/wireless/ath9k/Makefile1
-rw-r--r--drivers/net/wireless/ath9k/eeprom.h2
-rw-r--r--drivers/net/wireless/ath9k/hw.c15
-rw-r--r--drivers/net/wireless/ath9k/hw.h5
-rw-r--r--drivers/net/wireless/ath9k/main.c31
13 files changed, 155 insertions, 111 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 8a0823588c51..9e2c7e26fcbf 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -483,6 +483,7 @@ config MWL8K
483 will be called mwl8k. If unsure, say N. 483 will be called mwl8k. If unsure, say N.
484 484
485source "drivers/net/wireless/p54/Kconfig" 485source "drivers/net/wireless/p54/Kconfig"
486source "drivers/net/wireless/ath/Kconfig"
486source "drivers/net/wireless/ath5k/Kconfig" 487source "drivers/net/wireless/ath5k/Kconfig"
487source "drivers/net/wireless/ath9k/Kconfig" 488source "drivers/net/wireless/ath9k/Kconfig"
488source "drivers/net/wireless/ar9170/Kconfig" 489source "drivers/net/wireless/ar9170/Kconfig"
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 50e7fba7f0ea..104639e2783d 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_RT2X00) += rt2x00/
55 55
56obj-$(CONFIG_P54_COMMON) += p54/ 56obj-$(CONFIG_P54_COMMON) += p54/
57 57
58obj-$(CONFIG_ATH_COMMON) += ath/
58obj-$(CONFIG_ATH5K) += ath5k/ 59obj-$(CONFIG_ATH5K) += ath5k/
59obj-$(CONFIG_ATH9K) += ath9k/ 60obj-$(CONFIG_ATH9K) += ath9k/
60obj-$(CONFIG_AR9170_USB) += ar9170/ 61obj-$(CONFIG_AR9170_USB) += ar9170/
diff --git a/drivers/net/wireless/ath/Kconfig b/drivers/net/wireless/ath/Kconfig
new file mode 100644
index 000000000000..c2873a24baae
--- /dev/null
+++ b/drivers/net/wireless/ath/Kconfig
@@ -0,0 +1,4 @@
1config ATH_COMMON
2 tristate "Atheros Wireless Cards Shared Support"
3 depends on ATH5K || ATH9K
4
diff --git a/drivers/net/wireless/ath/Makefile b/drivers/net/wireless/ath/Makefile
new file mode 100644
index 000000000000..bc77646f90ad
--- /dev/null
+++ b/drivers/net/wireless/ath/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_ATH_COMMON) += ath.o
2ath-objs := regd.o
3
diff --git a/drivers/net/wireless/ath9k/regd.c b/drivers/net/wireless/ath/regd.c
index 7eaa59e4a7d1..4d3935b6fbdd 100644
--- a/drivers/net/wireless/ath9k/regd.c
+++ b/drivers/net/wireless/ath/regd.c
@@ -16,8 +16,10 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <net/cfg80211.h>
20#include <net/mac80211.h>
19#include <net/wireless.h> 21#include <net/wireless.h>
20#include "ath9k.h" 22#include "regd.h"
21#include "regd_common.h" 23#include "regd_common.h"
22 24
23/* 25/*
@@ -56,7 +58,7 @@
56 58
57/* Can be used for: 59/* Can be used for:
58 * 0x60, 0x61, 0x62 */ 60 * 0x60, 0x61, 0x62 */
59static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = { 61static const struct ieee80211_regdomain ath_world_regdom_60_61_62 = {
60 .n_reg_rules = 5, 62 .n_reg_rules = 5,
61 .alpha2 = "99", 63 .alpha2 = "99",
62 .reg_rules = { 64 .reg_rules = {
@@ -66,7 +68,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = {
66}; 68};
67 69
68/* Can be used by 0x63 and 0x65 */ 70/* Can be used by 0x63 and 0x65 */
69static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = { 71static const struct ieee80211_regdomain ath_world_regdom_63_65 = {
70 .n_reg_rules = 4, 72 .n_reg_rules = 4,
71 .alpha2 = "99", 73 .alpha2 = "99",
72 .reg_rules = { 74 .reg_rules = {
@@ -77,7 +79,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = {
77}; 79};
78 80
79/* Can be used by 0x64 only */ 81/* Can be used by 0x64 only */
80static const struct ieee80211_regdomain ath9k_world_regdom_64 = { 82static const struct ieee80211_regdomain ath_world_regdom_64 = {
81 .n_reg_rules = 3, 83 .n_reg_rules = 3,
82 .alpha2 = "99", 84 .alpha2 = "99",
83 .reg_rules = { 85 .reg_rules = {
@@ -87,7 +89,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_64 = {
87}; 89};
88 90
89/* Can be used by 0x66 and 0x69 */ 91/* Can be used by 0x66 and 0x69 */
90static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = { 92static const struct ieee80211_regdomain ath_world_regdom_66_69 = {
91 .n_reg_rules = 3, 93 .n_reg_rules = 3,
92 .alpha2 = "99", 94 .alpha2 = "99",
93 .reg_rules = { 95 .reg_rules = {
@@ -97,7 +99,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = {
97}; 99};
98 100
99/* Can be used by 0x67, 0x6A and 0x68 */ 101/* Can be used by 0x67, 0x6A and 0x68 */
100static const struct ieee80211_regdomain ath9k_world_regdom_67_68_6A = { 102static const struct ieee80211_regdomain ath_world_regdom_67_68_6A = {
101 .n_reg_rules = 4, 103 .n_reg_rules = 4,
102 .alpha2 = "99", 104 .alpha2 = "99",
103 .reg_rules = { 105 .reg_rules = {
@@ -113,50 +115,53 @@ static inline bool is_wwr_sku(u16 regd)
113 (regd == WORLD); 115 (regd == WORLD);
114} 116}
115 117
116static u16 ath9k_regd_get_eepromRD(struct ath9k_regulatory *reg) 118static u16 ath_regd_get_eepromRD(struct ath_regulatory *reg)
117{ 119{
118 return reg->current_rd & ~WORLDWIDE_ROAMING_FLAG; 120 return reg->current_rd & ~WORLDWIDE_ROAMING_FLAG;
119} 121}
120 122
121bool ath9k_is_world_regd(struct ath9k_regulatory *reg) 123bool ath_is_world_regd(struct ath_regulatory *reg)
122{ 124{
123 return is_wwr_sku(ath9k_regd_get_eepromRD(reg)); 125 return is_wwr_sku(ath_regd_get_eepromRD(reg));
124} 126}
127EXPORT_SYMBOL(ath_is_world_regd);
125 128
126const struct ieee80211_regdomain *ath9k_default_world_regdomain(void) 129const struct ieee80211_regdomain *ath_default_world_regdomain(void)
127{ 130{
128 /* this is the most restrictive */ 131 /* this is the most restrictive */
129 return &ath9k_world_regdom_64; 132 return &ath_world_regdom_64;
130} 133}
134EXPORT_SYMBOL(ath_default_world_regdomain);
131 135
132const struct 136const struct
133ieee80211_regdomain *ath9k_world_regdomain(struct ath9k_regulatory *reg) 137ieee80211_regdomain *ath_world_regdomain(struct ath_regulatory *reg)
134{ 138{
135 switch (reg->regpair->regDmnEnum) { 139 switch (reg->regpair->regDmnEnum) {
136 case 0x60: 140 case 0x60:
137 case 0x61: 141 case 0x61:
138 case 0x62: 142 case 0x62:
139 return &ath9k_world_regdom_60_61_62; 143 return &ath_world_regdom_60_61_62;
140 case 0x63: 144 case 0x63:
141 case 0x65: 145 case 0x65:
142 return &ath9k_world_regdom_63_65; 146 return &ath_world_regdom_63_65;
143 case 0x64: 147 case 0x64:
144 return &ath9k_world_regdom_64; 148 return &ath_world_regdom_64;
145 case 0x66: 149 case 0x66:
146 case 0x69: 150 case 0x69:
147 return &ath9k_world_regdom_66_69; 151 return &ath_world_regdom_66_69;
148 case 0x67: 152 case 0x67:
149 case 0x68: 153 case 0x68:
150 case 0x6A: 154 case 0x6A:
151 return &ath9k_world_regdom_67_68_6A; 155 return &ath_world_regdom_67_68_6A;
152 default: 156 default:
153 WARN_ON(1); 157 WARN_ON(1);
154 return ath9k_default_world_regdomain(); 158 return ath_default_world_regdomain();
155 } 159 }
156} 160}
161EXPORT_SYMBOL(ath_world_regdomain);
157 162
158/* Frequency is one where radar detection is required */ 163/* Frequency is one where radar detection is required */
159static bool ath9k_is_radar_freq(u16 center_freq) 164static bool ath_is_radar_freq(u16 center_freq)
160{ 165{
161 return (center_freq >= 5260 && center_freq <= 5700); 166 return (center_freq >= 5260 && center_freq <= 5700);
162} 167}
@@ -170,7 +175,7 @@ static bool ath9k_is_radar_freq(u16 center_freq)
170 * received a beacon on a channel we can enable active scan and 175 * received a beacon on a channel we can enable active scan and
171 * adhoc (or beaconing). 176 * adhoc (or beaconing).
172 */ 177 */
173static void ath9k_reg_apply_beaconing_flags( 178static void ath_reg_apply_beaconing_flags(
174 struct wiphy *wiphy, 179 struct wiphy *wiphy,
175 enum nl80211_reg_initiator initiator) 180 enum nl80211_reg_initiator initiator)
176{ 181{
@@ -193,7 +198,7 @@ static void ath9k_reg_apply_beaconing_flags(
193 198
194 ch = &sband->channels[i]; 199 ch = &sband->channels[i];
195 200
196 if (ath9k_is_radar_freq(ch->center_freq) || 201 if (ath_is_radar_freq(ch->center_freq) ||
197 (ch->flags & IEEE80211_CHAN_RADAR)) 202 (ch->flags & IEEE80211_CHAN_RADAR))
198 continue; 203 continue;
199 204
@@ -229,7 +234,7 @@ static void ath9k_reg_apply_beaconing_flags(
229} 234}
230 235
231/* Allows active scan scan on Ch 12 and 13 */ 236/* Allows active scan scan on Ch 12 and 13 */
232static void ath9k_reg_apply_active_scan_flags( 237static void ath_reg_apply_active_scan_flags(
233 struct wiphy *wiphy, 238 struct wiphy *wiphy,
234 enum nl80211_reg_initiator initiator) 239 enum nl80211_reg_initiator initiator)
235{ 240{
@@ -280,7 +285,7 @@ static void ath9k_reg_apply_active_scan_flags(
280} 285}
281 286
282/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */ 287/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */
283void ath9k_reg_apply_radar_flags(struct wiphy *wiphy) 288void ath_reg_apply_radar_flags(struct wiphy *wiphy)
284{ 289{
285 struct ieee80211_supported_band *sband; 290 struct ieee80211_supported_band *sband;
286 struct ieee80211_channel *ch; 291 struct ieee80211_channel *ch;
@@ -293,7 +298,7 @@ void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
293 298
294 for (i = 0; i < sband->n_channels; i++) { 299 for (i = 0; i < sband->n_channels; i++) {
295 ch = &sband->channels[i]; 300 ch = &sband->channels[i];
296 if (!ath9k_is_radar_freq(ch->center_freq)) 301 if (!ath_is_radar_freq(ch->center_freq))
297 continue; 302 continue;
298 /* We always enable radar detection/DFS on this 303 /* We always enable radar detection/DFS on this
299 * frequency range. Additionally we also apply on 304 * frequency range. Additionally we also apply on
@@ -311,31 +316,33 @@ void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
311 IEEE80211_CHAN_PASSIVE_SCAN; 316 IEEE80211_CHAN_PASSIVE_SCAN;
312 } 317 }
313} 318}
319EXPORT_SYMBOL(ath_reg_apply_radar_flags);
314 320
315void ath9k_reg_apply_world_flags(struct wiphy *wiphy, 321void ath_reg_apply_world_flags(struct wiphy *wiphy,
316 enum nl80211_reg_initiator initiator, 322 enum nl80211_reg_initiator initiator,
317 struct ath9k_regulatory *reg) 323 struct ath_regulatory *reg)
318{ 324{
319 switch (reg->regpair->regDmnEnum) { 325 switch (reg->regpair->regDmnEnum) {
320 case 0x60: 326 case 0x60:
321 case 0x63: 327 case 0x63:
322 case 0x66: 328 case 0x66:
323 case 0x67: 329 case 0x67:
324 ath9k_reg_apply_beaconing_flags(wiphy, initiator); 330 ath_reg_apply_beaconing_flags(wiphy, initiator);
325 break; 331 break;
326 case 0x68: 332 case 0x68:
327 ath9k_reg_apply_beaconing_flags(wiphy, initiator); 333 ath_reg_apply_beaconing_flags(wiphy, initiator);
328 ath9k_reg_apply_active_scan_flags(wiphy, initiator); 334 ath_reg_apply_active_scan_flags(wiphy, initiator);
329 break; 335 break;
330 } 336 }
331 return; 337 return;
332} 338}
339EXPORT_SYMBOL(ath_reg_apply_world_flags);
333 340
334static int ath9k_reg_notifier_apply(struct wiphy *wiphy, 341int ath_reg_notifier_apply(struct wiphy *wiphy,
335 struct regulatory_request *request, struct ath9k_regulatory *reg) 342 struct regulatory_request *request, struct ath_regulatory *reg)
336{ 343{
337 /* We always apply this */ 344 /* We always apply this */
338 ath9k_reg_apply_radar_flags(wiphy); 345 ath_reg_apply_radar_flags(wiphy);
339 346
340 switch (request->initiator) { 347 switch (request->initiator) {
341 case NL80211_REGDOM_SET_BY_DRIVER: 348 case NL80211_REGDOM_SET_BY_DRIVER:
@@ -343,28 +350,19 @@ static int ath9k_reg_notifier_apply(struct wiphy *wiphy,
343 case NL80211_REGDOM_SET_BY_USER: 350 case NL80211_REGDOM_SET_BY_USER:
344 break; 351 break;
345 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 352 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
346 if (ath9k_is_world_regd(reg)) 353 if (ath_is_world_regd(reg))
347 ath9k_reg_apply_world_flags(wiphy, request->initiator, 354 ath_reg_apply_world_flags(wiphy, request->initiator,
348 reg); 355 reg);
349 break; 356 break;
350 } 357 }
351 358
352 return 0; 359 return 0;
353} 360}
361EXPORT_SYMBOL(ath_reg_notifier_apply);
354 362
355int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) 363bool ath_regd_is_eeprom_valid(struct ath_regulatory *reg)
356{ 364{
357 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 365 u16 rd = ath_regd_get_eepromRD(reg);
358 struct ath_wiphy *aphy = hw->priv;
359 struct ath_softc *sc = aphy->sc;
360 struct ath9k_regulatory *reg = &sc->sc_ah->regulatory;
361
362 return ath9k_reg_notifier_apply(wiphy, request, reg);
363}
364
365bool ath9k_regd_is_eeprom_valid(struct ath9k_regulatory *reg)
366{
367 u16 rd = ath9k_regd_get_eepromRD(reg);
368 int i; 366 int i;
369 367
370 if (rd & COUNTRY_ERD_FLAG) { 368 if (rd & COUNTRY_ERD_FLAG) {
@@ -380,13 +378,14 @@ bool ath9k_regd_is_eeprom_valid(struct ath9k_regulatory *reg)
380 return true; 378 return true;
381 } 379 }
382 printk(KERN_DEBUG 380 printk(KERN_DEBUG
383 "ath9k: invalid regulatory domain/country code 0x%x\n", rd); 381 "ath: invalid regulatory domain/country code 0x%x\n", rd);
384 return false; 382 return false;
385} 383}
384EXPORT_SYMBOL(ath_regd_is_eeprom_valid);
386 385
387/* EEPROM country code to regpair mapping */ 386/* EEPROM country code to regpair mapping */
388static struct country_code_to_enum_rd* 387static struct country_code_to_enum_rd*
389ath9k_regd_find_country(u16 countryCode) 388ath_regd_find_country(u16 countryCode)
390{ 389{
391 int i; 390 int i;
392 391
@@ -399,7 +398,7 @@ ath9k_regd_find_country(u16 countryCode)
399 398
400/* EEPROM rd code to regpair mapping */ 399/* EEPROM rd code to regpair mapping */
401static struct country_code_to_enum_rd* 400static struct country_code_to_enum_rd*
402ath9k_regd_find_country_by_rd(int regdmn) 401ath_regd_find_country_by_rd(int regdmn)
403{ 402{
404 int i; 403 int i;
405 404
@@ -411,13 +410,13 @@ ath9k_regd_find_country_by_rd(int regdmn)
411} 410}
412 411
413/* Returns the map of the EEPROM set RD to a country code */ 412/* Returns the map of the EEPROM set RD to a country code */
414static u16 ath9k_regd_get_default_country(u16 rd) 413static u16 ath_regd_get_default_country(u16 rd)
415{ 414{
416 if (rd & COUNTRY_ERD_FLAG) { 415 if (rd & COUNTRY_ERD_FLAG) {
417 struct country_code_to_enum_rd *country = NULL; 416 struct country_code_to_enum_rd *country = NULL;
418 u16 cc = rd & ~COUNTRY_ERD_FLAG; 417 u16 cc = rd & ~COUNTRY_ERD_FLAG;
419 418
420 country = ath9k_regd_find_country(cc); 419 country = ath_regd_find_country(cc);
421 if (country != NULL) 420 if (country != NULL)
422 return cc; 421 return cc;
423 } 422 }
@@ -426,7 +425,7 @@ static u16 ath9k_regd_get_default_country(u16 rd)
426} 425}
427 426
428static struct reg_dmn_pair_mapping* 427static struct reg_dmn_pair_mapping*
429ath9k_get_regpair(int regdmn) 428ath_get_regpair(int regdmn)
430{ 429{
431 int i; 430 int i;
432 431
@@ -439,18 +438,18 @@ ath9k_get_regpair(int regdmn)
439 return NULL; 438 return NULL;
440} 439}
441 440
442int ath9k_regd_init(struct ath9k_regulatory *reg) 441int ath_regd_init(struct ath_regulatory *reg)
443{ 442{
444 struct country_code_to_enum_rd *country = NULL; 443 struct country_code_to_enum_rd *country = NULL;
445 u16 regdmn; 444 u16 regdmn;
446 445
447 if (!ath9k_regd_is_eeprom_valid(reg)) { 446 if (!ath_regd_is_eeprom_valid(reg)) {
448 printk(KERN_DEBUG "ath9k: Invalid EEPROM contents\n"); 447 printk(KERN_DEBUG "ath: Invalid EEPROM contents\n");
449 return -EINVAL; 448 return -EINVAL;
450 } 449 }
451 450
452 regdmn = ath9k_regd_get_eepromRD(reg); 451 regdmn = ath_regd_get_eepromRD(reg);
453 reg->country_code = ath9k_regd_get_default_country(regdmn); 452 reg->country_code = ath_regd_get_default_country(regdmn);
454 453
455 if (reg->country_code == CTRY_DEFAULT && 454 if (reg->country_code == CTRY_DEFAULT &&
456 regdmn == CTRY_DEFAULT) 455 regdmn == CTRY_DEFAULT)
@@ -459,26 +458,26 @@ int ath9k_regd_init(struct ath9k_regulatory *reg)
459 if (reg->country_code == CTRY_DEFAULT) { 458 if (reg->country_code == CTRY_DEFAULT) {
460 country = NULL; 459 country = NULL;
461 } else { 460 } else {
462 country = ath9k_regd_find_country(reg->country_code); 461 country = ath_regd_find_country(reg->country_code);
463 if (country == NULL) { 462 if (country == NULL) {
464 printk(KERN_DEBUG 463 printk(KERN_DEBUG
465 "ath9k: Country is NULL!!!!, cc= %d\n", 464 "ath: Country is NULL!!!!, cc= %d\n",
466 reg->country_code); 465 reg->country_code);
467 return -EINVAL; 466 return -EINVAL;
468 } else 467 } else
469 regdmn = country->regDmnEnum; 468 regdmn = country->regDmnEnum;
470 } 469 }
471 470
472 reg->regpair = ath9k_get_regpair(regdmn); 471 reg->regpair = ath_get_regpair(regdmn);
473 472
474 if (!reg->regpair) { 473 if (!reg->regpair) {
475 printk(KERN_DEBUG "ath9k: " 474 printk(KERN_DEBUG "ath: "
476 "No regulatory domain pair found, cannot continue\n"); 475 "No regulatory domain pair found, cannot continue\n");
477 return -EINVAL; 476 return -EINVAL;
478 } 477 }
479 478
480 if (!country) 479 if (!country)
481 country = ath9k_regd_find_country_by_rd(regdmn); 480 country = ath_regd_find_country_by_rd(regdmn);
482 481
483 if (country) { 482 if (country) {
484 reg->alpha2[0] = country->isoName[0]; 483 reg->alpha2[0] = country->isoName[0];
@@ -488,21 +487,21 @@ int ath9k_regd_init(struct ath9k_regulatory *reg)
488 reg->alpha2[1] = '0'; 487 reg->alpha2[1] = '0';
489 } 488 }
490 489
491 printk(KERN_DEBUG "ath9k: Country alpha2 being used: %c%c\n", 490 printk(KERN_DEBUG "ath: Country alpha2 being used: %c%c\n",
492 reg->alpha2[0], reg->alpha2[1]); 491 reg->alpha2[0], reg->alpha2[1]);
493 printk(KERN_DEBUG "ath9k: Regpair detected: 0x%0x\n", 492 printk(KERN_DEBUG "ath: Regpair detected: 0x%0x\n",
494 reg->regpair->regDmnEnum); 493 reg->regpair->regDmnEnum);
495 494
496 return 0; 495 return 0;
497} 496}
497EXPORT_SYMBOL(ath_regd_init);
498 498
499static 499u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
500u32 ath9k_regd_get_band_ctl(struct ath9k_regulatory *reg, 500 enum ieee80211_band band)
501 enum ieee80211_band band)
502{ 501{
503 if (!reg->regpair || 502 if (!reg->regpair ||
504 (reg->country_code == CTRY_DEFAULT && 503 (reg->country_code == CTRY_DEFAULT &&
505 is_wwr_sku(ath9k_regd_get_eepromRD(reg)))) { 504 is_wwr_sku(ath_regd_get_eepromRD(reg)))) {
506 return SD_NO_CTL; 505 return SD_NO_CTL;
507 } 506 }
508 507
@@ -517,17 +516,4 @@ u32 ath9k_regd_get_band_ctl(struct ath9k_regulatory *reg,
517 516
518 return NO_CTL; 517 return NO_CTL;
519} 518}
520 519EXPORT_SYMBOL(ath_regd_get_band_ctl);
521u32 ath9k_regd_get_ctl(struct ath9k_regulatory *reg, struct ath9k_channel *chan)
522{
523 u32 ctl = ath9k_regd_get_band_ctl(reg, chan->chan->band);
524
525 if (IS_CHAN_B(chan))
526 ctl |= CTL_11B;
527 else if (IS_CHAN_G(chan))
528 ctl |= CTL_11G;
529 else
530 ctl |= CTL_11A;
531
532 return ctl;
533}
diff --git a/drivers/net/wireless/ath9k/regd.h b/drivers/net/wireless/ath/regd.h
index 61fa42ebfbc4..981f5cf2bdb8 100644
--- a/drivers/net/wireless/ath9k/regd.h
+++ b/drivers/net/wireless/ath/regd.h
@@ -19,6 +19,24 @@
19 19
20#include <linux/nl80211.h> 20#include <linux/nl80211.h>
21 21
22#include <net/cfg80211.h>
23#include <net/wireless.h>
24
25#define NO_CTL 0xff
26#define SD_NO_CTL 0xE0
27#define NO_CTL 0xff
28#define CTL_MODE_M 7
29#define CTL_11A 0
30#define CTL_11B 1
31#define CTL_11G 2
32#define CTL_2GHT20 5
33#define CTL_5GHT20 6
34#define CTL_2GHT40 7
35#define CTL_5GHT40 8
36
37#define CTRY_DEBUG 0x1ff
38#define CTRY_DEFAULT 0
39
22#define COUNTRY_ERD_FLAG 0x8000 40#define COUNTRY_ERD_FLAG 0x8000
23#define WORLDWIDE_ROAMING_FLAG 0x4000 41#define WORLDWIDE_ROAMING_FLAG 0x4000
24 42
@@ -42,7 +60,7 @@ struct country_code_to_enum_rd {
42 const char *isoName; 60 const char *isoName;
43}; 61};
44 62
45struct ath9k_regulatory { 63struct ath_regulatory {
46 char alpha2[2]; 64 char alpha2[2];
47 u16 country_code; 65 u16 country_code;
48 u16 max_power_level; 66 u16 max_power_level;
@@ -235,18 +253,20 @@ enum CountryCode {
235 CTRY_BELGIUM2 = 5002 253 CTRY_BELGIUM2 = 5002
236}; 254};
237 255
238bool ath9k_is_world_regd(struct ath9k_regulatory *reg); 256bool ath_is_world_regd(struct ath_regulatory *reg);
239const struct ieee80211_regdomain *ath9k_world_regdomain( 257const
240 struct ath9k_regulatory *reg); 258struct ieee80211_regdomain *ath_world_regdomain(struct ath_regulatory *reg);
241const struct ieee80211_regdomain *ath9k_default_world_regdomain(void); 259const struct ieee80211_regdomain *ath_default_world_regdomain(void);
242void ath9k_reg_apply_world_flags(struct wiphy *wiphy, 260void ath_reg_apply_world_flags(struct wiphy *wiphy,
243 enum nl80211_reg_initiator, 261 enum nl80211_reg_initiator,
244 struct ath9k_regulatory *reg); 262 struct ath_regulatory *reg);
245void ath9k_reg_apply_radar_flags(struct wiphy *wiphy); 263void ath_reg_apply_radar_flags(struct wiphy *wiphy);
246int ath9k_regd_init(struct ath9k_regulatory *reg); 264int ath_regd_init(struct ath_regulatory *reg);
247bool ath9k_regd_is_eeprom_valid(struct ath9k_regulatory *reg); 265bool ath_regd_is_eeprom_valid(struct ath_regulatory *reg);
248u32 ath9k_regd_get_ctl(struct ath9k_regulatory *reg, 266u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
249 struct ath9k_channel *chan); 267 enum ieee80211_band band);
250int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request); 268int ath_reg_notifier_apply(struct wiphy *wiphy,
269 struct regulatory_request *request,
270 struct ath_regulatory *reg);
251 271
252#endif 272#endif
diff --git a/drivers/net/wireless/ath9k/regd_common.h b/drivers/net/wireless/ath/regd_common.h
index 4d0e298cd1c7..4d0e298cd1c7 100644
--- a/drivers/net/wireless/ath9k/regd_common.h
+++ b/drivers/net/wireless/ath/regd_common.h
diff --git a/drivers/net/wireless/ath9k/Kconfig b/drivers/net/wireless/ath9k/Kconfig
index 90a8dd873786..0ed1ac312aa6 100644
--- a/drivers/net/wireless/ath9k/Kconfig
+++ b/drivers/net/wireless/ath9k/Kconfig
@@ -2,6 +2,7 @@ config ATH9K
2 tristate "Atheros 802.11n wireless cards support" 2 tristate "Atheros 802.11n wireless cards support"
3 depends on PCI && MAC80211 && WLAN_80211 3 depends on PCI && MAC80211 && WLAN_80211
4 depends on RFKILL || RFKILL=n 4 depends on RFKILL || RFKILL=n
5 select ATH_COMMON
5 select MAC80211_LEDS 6 select MAC80211_LEDS
6 select LEDS_CLASS 7 select LEDS_CLASS
7 select NEW_LEDS 8 select NEW_LEDS
diff --git a/drivers/net/wireless/ath9k/Makefile b/drivers/net/wireless/ath9k/Makefile
index 1a4d4eab6fe8..783bc39eb2ff 100644
--- a/drivers/net/wireless/ath9k/Makefile
+++ b/drivers/net/wireless/ath9k/Makefile
@@ -4,7 +4,6 @@ ath9k-y += hw.o \
4 calib.o \ 4 calib.o \
5 ani.o \ 5 ani.o \
6 phy.o \ 6 phy.o \
7 regd.o \
8 beacon.o \ 7 beacon.o \
9 main.o \ 8 main.o \
10 recv.o \ 9 recv.o \
diff --git a/drivers/net/wireless/ath9k/eeprom.h b/drivers/net/wireless/ath9k/eeprom.h
index 25b68c881ff1..9a7715df5cff 100644
--- a/drivers/net/wireless/ath9k/eeprom.h
+++ b/drivers/net/wireless/ath9k/eeprom.h
@@ -17,6 +17,8 @@
17#ifndef EEPROM_H 17#ifndef EEPROM_H
18#define EEPROM_H 18#define EEPROM_H
19 19
20#include <net/wireless.h>
21
20#define AH_USE_EEPROM 0x1 22#define AH_USE_EEPROM 0x1
21 23
22#ifdef __BIG_ENDIAN 24#ifdef __BIG_ENDIAN
diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath9k/hw.c
index a8465bb418a9..24299e65fdcf 100644
--- a/drivers/net/wireless/ath9k/hw.c
+++ b/drivers/net/wireless/ath9k/hw.c
@@ -1220,6 +1220,21 @@ static void ath9k_olc_init(struct ath_hw *ah)
1220 ah->PDADCdelta = 0; 1220 ah->PDADCdelta = 0;
1221} 1221}
1222 1222
1223static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1224 struct ath9k_channel *chan)
1225{
1226 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1227
1228 if (IS_CHAN_B(chan))
1229 ctl |= CTL_11B;
1230 else if (IS_CHAN_G(chan))
1231 ctl |= CTL_11G;
1232 else
1233 ctl |= CTL_11A;
1234
1235 return ctl;
1236}
1237
1223static int ath9k_hw_process_ini(struct ath_hw *ah, 1238static int ath9k_hw_process_ini(struct ath_hw *ah,
1224 struct ath9k_channel *chan, 1239 struct ath9k_channel *chan,
1225 enum ath9k_ht_macmode macmode) 1240 enum ath9k_ht_macmode macmode)
diff --git a/drivers/net/wireless/ath9k/hw.h b/drivers/net/wireless/ath9k/hw.h
index 5a1128ddb464..984ac7da09d6 100644
--- a/drivers/net/wireless/ath9k/hw.h
+++ b/drivers/net/wireless/ath9k/hw.h
@@ -25,10 +25,11 @@
25#include "ani.h" 25#include "ani.h"
26#include "eeprom.h" 26#include "eeprom.h"
27#include "calib.h" 27#include "calib.h"
28#include "regd.h"
29#include "reg.h" 28#include "reg.h"
30#include "phy.h" 29#include "phy.h"
31 30
31#include "../ath/regd.h"
32
32#define ATHEROS_VENDOR_ID 0x168c 33#define ATHEROS_VENDOR_ID 0x168c
33#define AR5416_DEVID_PCI 0x0023 34#define AR5416_DEVID_PCI 0x0023
34#define AR5416_DEVID_PCIE 0x0024 35#define AR5416_DEVID_PCIE 0x0024
@@ -404,7 +405,7 @@ struct ath_hw {
404 struct ath9k_hw_version hw_version; 405 struct ath9k_hw_version hw_version;
405 struct ath9k_ops_config config; 406 struct ath9k_ops_config config;
406 struct ath9k_hw_capabilities caps; 407 struct ath9k_hw_capabilities caps;
407 struct ath9k_regulatory regulatory; 408 struct ath_regulatory regulatory;
408 struct ath9k_channel channels[38]; 409 struct ath9k_channel channels[38];
409 struct ath9k_channel *curchan; 410 struct ath9k_channel *curchan;
410 411
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 3647a47d939d..d779f00c9b9d 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -1406,7 +1406,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
1406 for (i = 0; i < sc->keymax; i++) 1406 for (i = 0; i < sc->keymax; i++)
1407 ath9k_hw_keyreset(ah, (u16) i); 1407 ath9k_hw_keyreset(ah, (u16) i);
1408 1408
1409 if (ath9k_regd_init(&sc->sc_ah->regulatory)) 1409 if (ath_regd_init(&sc->sc_ah->regulatory))
1410 goto bad; 1410 goto bad;
1411 1411
1412 /* default to MONITOR mode */ 1412 /* default to MONITOR mode */
@@ -1570,6 +1570,17 @@ bad:
1570 return error; 1570 return error;
1571} 1571}
1572 1572
1573static int ath9k_reg_notifier(struct wiphy *wiphy,
1574 struct regulatory_request *request)
1575{
1576 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1577 struct ath_wiphy *aphy = hw->priv;
1578 struct ath_softc *sc = aphy->sc;
1579 struct ath_regulatory *reg = &sc->sc_ah->regulatory;
1580
1581 return ath_reg_notifier_apply(wiphy, request, reg);
1582}
1583
1573void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) 1584void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
1574{ 1585{
1575 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | 1586 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
@@ -1614,7 +1625,7 @@ int ath_attach(u16 devid, struct ath_softc *sc)
1614 struct ieee80211_hw *hw = sc->hw; 1625 struct ieee80211_hw *hw = sc->hw;
1615 const struct ieee80211_regdomain *regd; 1626 const struct ieee80211_regdomain *regd;
1616 int error = 0, i; 1627 int error = 0, i;
1617 struct ath9k_regulatory *reg; 1628 struct ath_regulatory *reg;
1618 1629
1619 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n"); 1630 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
1620 1631
@@ -1656,23 +1667,23 @@ int ath_attach(u16 devid, struct ath_softc *sc)
1656 goto error_attach; 1667 goto error_attach;
1657#endif 1668#endif
1658 1669
1659 if (ath9k_is_world_regd(reg)) { 1670 if (ath_is_world_regd(reg)) {
1660 /* Anything applied here (prior to wiphy registration) gets 1671 /* Anything applied here (prior to wiphy registration) gets
1661 * saved on the wiphy orig_* parameters */ 1672 * saved on the wiphy orig_* parameters */
1662 regd = ath9k_world_regdomain(reg); 1673 regd = ath_world_regdomain(reg);
1663 hw->wiphy->custom_regulatory = true; 1674 hw->wiphy->custom_regulatory = true;
1664 hw->wiphy->strict_regulatory = false; 1675 hw->wiphy->strict_regulatory = false;
1665 } else { 1676 } else {
1666 /* This gets applied in the case of the absense of CRDA, 1677 /* This gets applied in the case of the absense of CRDA,
1667 * it's our own custom world regulatory domain, similar to 1678 * it's our own custom world regulatory domain, similar to
1668 * cfg80211's but we enable passive scanning */ 1679 * cfg80211's but we enable passive scanning */
1669 regd = ath9k_default_world_regdomain(); 1680 regd = ath_default_world_regdomain();
1670 } 1681 }
1671 wiphy_apply_custom_regulatory(hw->wiphy, regd); 1682 wiphy_apply_custom_regulatory(hw->wiphy, regd);
1672 ath9k_reg_apply_radar_flags(hw->wiphy); 1683 ath_reg_apply_radar_flags(hw->wiphy);
1673 ath9k_reg_apply_world_flags(hw->wiphy, 1684 ath_reg_apply_world_flags(hw->wiphy,
1674 NL80211_REGDOM_SET_BY_DRIVER, 1685 NL80211_REGDOM_SET_BY_DRIVER,
1675 reg); 1686 reg);
1676 1687
1677 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work); 1688 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
1678 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work); 1689 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
@@ -1680,7 +1691,7 @@ int ath_attach(u16 devid, struct ath_softc *sc)
1680 1691
1681 error = ieee80211_register_hw(hw); 1692 error = ieee80211_register_hw(hw);
1682 1693
1683 if (!ath9k_is_world_regd(reg)) { 1694 if (!ath_is_world_regd(reg)) {
1684 error = regulatory_hint(hw->wiphy, reg->alpha2); 1695 error = regulatory_hint(hw->wiphy, reg->alpha2);
1685 if (error) 1696 if (error)
1686 goto error_attach; 1697 goto error_attach;