2 * Copyright (c) 2010 Broadcom Corporation
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.
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/types.h>
18 #include <net/cfg80211.h>
19 #include <net/mac80211.h>
20 #include <net/regulatory.h>
24 #include "phy/phy_hal.h"
28 #include "mac80211_if.h"
31 /* QDB() macro takes a dB value and converts to a quarter dB value */
32 #define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
34 #define LOCALE_MIMO_IDX_bn 0
35 #define LOCALE_MIMO_IDX_11n 0
37 /* max of BAND_5G_PWR_LVLS and 14 for 2.4 GHz */
38 #define BRCMS_MAXPWR_MIMO_TBL_SIZE 14
40 /* maxpwr mapping to 5GHz band channels:
41 * maxpwr[0] - channels [34-48]
42 * maxpwr[1] - channels [52-60]
43 * maxpwr[2] - channels [62-64]
44 * maxpwr[3] - channels [100-140]
45 * maxpwr[4] - channels [149-165]
47 #define BAND_5G_PWR_LVLS 5 /* 5 power levels for 5G */
49 #define LC(id) LOCALE_MIMO_IDX_ ## id
51 #define LOCALES(mimo2, mimo5) \
52 {LC(mimo2), LC(mimo5)}
54 /* macro to get 5 GHz channel group index for tx power */
55 #define CHANNEL_POWER_IDX_5G(c) (((c) < 52) ? 0 : \
58 (((c) < 149) ? 3 : 4))))
60 #define BRCM_2GHZ_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
61 #define BRCM_2GHZ_2467_2472 REG_RULE(2467-10, 2472+10, 20, 0, 19, \
64 #define BRCM_5GHZ_5180_5240 REG_RULE(5180-10, 5240+10, 40, 0, 21, \
66 #define BRCM_5GHZ_5260_5320 REG_RULE(5260-10, 5320+10, 40, 0, 21, \
69 #define BRCM_5GHZ_5500_5700 REG_RULE(5500-10, 5700+10, 40, 0, 21, \
72 #define BRCM_5GHZ_5745_5825 REG_RULE(5745-10, 5825+10, 40, 0, 21, \
75 static const struct ieee80211_regdomain brcms_regdom_x2
= {
88 /* locale per-channel tx power limits for MIMO frames
89 * maxpwr arrays are index by channel for 2.4 GHz limits, and
90 * by sub-band for 5 GHz limits using CHANNEL_POWER_IDX_5G(channel)
92 struct locale_mimo_info
{
93 /* tx 20 MHz power limits, qdBm units */
94 s8 maxpwr20
[BRCMS_MAXPWR_MIMO_TBL_SIZE
];
95 /* tx 40 MHz power limits, qdBm units */
96 s8 maxpwr40
[BRCMS_MAXPWR_MIMO_TBL_SIZE
];
99 /* Country names and abbreviations with locale defined from ISO 3166 */
100 struct country_info
{
101 const u8 locale_mimo_2G
; /* 2.4G mimo info */
102 const u8 locale_mimo_5G
; /* 5G mimo info */
106 struct country_info country
;
107 const struct ieee80211_regdomain
*regdomain
;
110 struct brcms_cm_info
{
111 struct brcms_pub
*pub
;
112 struct brcms_c_info
*wlc
;
113 const struct brcms_regd
*world_regd
;
117 * MIMO Locale Definitions - 2.4 GHz
119 static const struct locale_mimo_info locale_bn
= {
120 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
121 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
122 QDB(13), QDB(13), QDB(13)},
123 {0, 0, QDB(13), QDB(13), QDB(13),
124 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
128 static const struct locale_mimo_info
*g_mimo_2g_table
[] = {
133 * MIMO Locale Definitions - 5 GHz
135 static const struct locale_mimo_info locale_11n
= {
136 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
137 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
140 static const struct locale_mimo_info
*g_mimo_5g_table
[] = {
144 static const struct brcms_regd cntry_locales
[] = {
145 /* Worldwide RoW 2, must always be at index 0 */
147 .country
= LOCALES(bn
, 11n
),
148 .regdomain
= &brcms_regdom_x2
,
152 static const struct locale_mimo_info
*brcms_c_get_mimo_2g(u8 locale_idx
)
154 if (locale_idx
>= ARRAY_SIZE(g_mimo_2g_table
))
157 return g_mimo_2g_table
[locale_idx
];
160 static const struct locale_mimo_info
*brcms_c_get_mimo_5g(u8 locale_idx
)
162 if (locale_idx
>= ARRAY_SIZE(g_mimo_5g_table
))
165 return g_mimo_5g_table
[locale_idx
];
169 * Indicates whether the country provided is valid to pass
170 * to cfg80211 or not.
172 * returns true if valid; false if not.
174 static bool brcms_c_country_valid(const char *ccode
)
177 * only allow ascii alpha uppercase for the first 2
180 if (!((ccode
[0] & 0x80) == 0 && ccode
[0] >= 0x41 && ccode
[0] <= 0x5A &&
181 (ccode
[1] & 0x80) == 0 && ccode
[1] >= 0x41 && ccode
[1] <= 0x5A))
185 * do not match ISO 3166-1 user assigned country codes
186 * that may be in the driver table
188 if (!strcmp("AA", ccode
) || /* AA */
189 !strcmp("ZZ", ccode
) || /* ZZ */
190 ccode
[0] == 'X' || /* XA - XZ */
191 (ccode
[0] == 'Q' && /* QM - QZ */
192 (ccode
[1] >= 'M' && ccode
[1] <= 'Z')))
195 if (!strcmp("NA", ccode
))
201 static const struct brcms_regd
*brcms_world_regd(const char *regdom
, int len
)
203 const struct brcms_regd
*regd
= NULL
;
206 for (i
= 0; i
< ARRAY_SIZE(cntry_locales
); i
++) {
207 if (!strncmp(regdom
, cntry_locales
[i
].regdomain
->alpha2
, len
)) {
208 regd
= &cntry_locales
[i
];
216 static const struct brcms_regd
*brcms_default_world_regd(void)
218 return &cntry_locales
[0];
221 /* JP, J1 - J10 are Japan ccodes */
222 static bool brcms_c_japan_ccode(const char *ccode
)
224 return (ccode
[0] == 'J' &&
225 (ccode
[1] == 'P' || (ccode
[1] >= '1' && ccode
[1] <= '9')));
229 brcms_c_channel_min_txpower_limits_with_local_constraint(
230 struct brcms_cm_info
*wlc_cm
, struct txpwr_limits
*txpwr
,
231 u8 local_constraint_qdbm
)
236 for (j
= 0; j
< WL_TX_POWER_CCK_NUM
; j
++)
237 txpwr
->cck
[j
] = min(txpwr
->cck
[j
], local_constraint_qdbm
);
239 /* 20 MHz Legacy OFDM SISO */
240 for (j
= 0; j
< WL_TX_POWER_OFDM_NUM
; j
++)
241 txpwr
->ofdm
[j
] = min(txpwr
->ofdm
[j
], local_constraint_qdbm
);
243 /* 20 MHz Legacy OFDM CDD */
244 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++)
246 min(txpwr
->ofdm_cdd
[j
], local_constraint_qdbm
);
248 /* 40 MHz Legacy OFDM SISO */
249 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++)
250 txpwr
->ofdm_40_siso
[j
] =
251 min(txpwr
->ofdm_40_siso
[j
], local_constraint_qdbm
);
253 /* 40 MHz Legacy OFDM CDD */
254 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++)
255 txpwr
->ofdm_40_cdd
[j
] =
256 min(txpwr
->ofdm_40_cdd
[j
], local_constraint_qdbm
);
258 /* 20MHz MCS 0-7 SISO */
259 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
260 txpwr
->mcs_20_siso
[j
] =
261 min(txpwr
->mcs_20_siso
[j
], local_constraint_qdbm
);
263 /* 20MHz MCS 0-7 CDD */
264 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
265 txpwr
->mcs_20_cdd
[j
] =
266 min(txpwr
->mcs_20_cdd
[j
], local_constraint_qdbm
);
268 /* 20MHz MCS 0-7 STBC */
269 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
270 txpwr
->mcs_20_stbc
[j
] =
271 min(txpwr
->mcs_20_stbc
[j
], local_constraint_qdbm
);
273 /* 20MHz MCS 8-15 MIMO */
274 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_2_STREAM
; j
++)
275 txpwr
->mcs_20_mimo
[j
] =
276 min(txpwr
->mcs_20_mimo
[j
], local_constraint_qdbm
);
278 /* 40MHz MCS 0-7 SISO */
279 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
280 txpwr
->mcs_40_siso
[j
] =
281 min(txpwr
->mcs_40_siso
[j
], local_constraint_qdbm
);
283 /* 40MHz MCS 0-7 CDD */
284 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
285 txpwr
->mcs_40_cdd
[j
] =
286 min(txpwr
->mcs_40_cdd
[j
], local_constraint_qdbm
);
288 /* 40MHz MCS 0-7 STBC */
289 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++)
290 txpwr
->mcs_40_stbc
[j
] =
291 min(txpwr
->mcs_40_stbc
[j
], local_constraint_qdbm
);
293 /* 40MHz MCS 8-15 MIMO */
294 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_2_STREAM
; j
++)
295 txpwr
->mcs_40_mimo
[j
] =
296 min(txpwr
->mcs_40_mimo
[j
], local_constraint_qdbm
);
299 txpwr
->mcs32
= min(txpwr
->mcs32
, local_constraint_qdbm
);
304 * set the driver's current country and regulatory information
305 * using a country code as the source. Look up built in country
306 * information found with the country code.
309 brcms_c_set_country(struct brcms_cm_info
*wlc_cm
,
310 const struct brcms_regd
*regd
)
312 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
314 if ((wlc
->pub
->_n_enab
& SUPPORT_11N
) !=
315 wlc
->protection
->nmode_user
)
316 brcms_c_set_nmode(wlc
);
318 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
319 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
321 brcms_c_set_gmode(wlc
, wlc
->protection
->gmode_user
, false);
326 struct brcms_cm_info
*brcms_c_channel_mgr_attach(struct brcms_c_info
*wlc
)
328 struct brcms_cm_info
*wlc_cm
;
329 struct brcms_pub
*pub
= wlc
->pub
;
330 struct ssb_sprom
*sprom
= &wlc
->hw
->d11core
->bus
->sprom
;
331 const char *ccode
= sprom
->alpha2
;
332 int ccode_len
= sizeof(sprom
->alpha2
);
334 wlc_cm
= kzalloc(sizeof(struct brcms_cm_info
), GFP_ATOMIC
);
341 /* store the country code for passing up as a regulatory hint */
342 wlc_cm
->world_regd
= brcms_world_regd(ccode
, ccode_len
);
343 if (brcms_c_country_valid(ccode
))
344 strncpy(wlc
->pub
->srom_ccode
, ccode
, ccode_len
);
347 * If no custom world domain is found in the SROM, use the
348 * default "X2" domain.
350 if (!wlc_cm
->world_regd
) {
351 wlc_cm
->world_regd
= brcms_default_world_regd();
352 ccode
= wlc_cm
->world_regd
->regdomain
->alpha2
;
353 ccode_len
= BRCM_CNTRY_BUF_SZ
- 1;
356 /* save default country for exiting 11d regulatory mode */
357 strncpy(wlc
->country_default
, ccode
, ccode_len
);
359 /* initialize autocountry_default to driver default */
360 strncpy(wlc
->autocountry_default
, ccode
, ccode_len
);
362 brcms_c_set_country(wlc_cm
, wlc_cm
->world_regd
);
367 void brcms_c_channel_mgr_detach(struct brcms_cm_info
*wlc_cm
)
373 brcms_c_channel_set_chanspec(struct brcms_cm_info
*wlc_cm
, u16 chanspec
,
374 u8 local_constraint_qdbm
)
376 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
377 struct ieee80211_channel
*ch
= wlc
->pub
->ieee_hw
->conf
.chandef
.chan
;
378 struct txpwr_limits txpwr
;
380 brcms_c_channel_reg_limits(wlc_cm
, chanspec
, &txpwr
);
382 brcms_c_channel_min_txpower_limits_with_local_constraint(
383 wlc_cm
, &txpwr
, local_constraint_qdbm
386 /* set or restore gmode as required by regulatory */
387 if (ch
->flags
& IEEE80211_CHAN_NO_OFDM
)
388 brcms_c_set_gmode(wlc
, GMODE_LEGACY_B
, false);
390 brcms_c_set_gmode(wlc
, wlc
->protection
->gmode_user
, false);
392 brcms_b_set_chanspec(wlc
->hw
, chanspec
,
393 !!(ch
->flags
& IEEE80211_CHAN_NO_IR
),
398 brcms_c_channel_reg_limits(struct brcms_cm_info
*wlc_cm
, u16 chanspec
,
399 struct txpwr_limits
*txpwr
)
401 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
402 struct ieee80211_channel
*ch
= wlc
->pub
->ieee_hw
->conf
.chandef
.chan
;
407 const struct country_info
*country
;
408 struct brcms_band
*band
;
409 int conducted_max
= BRCMS_TXPWR_MAX
;
410 const struct locale_mimo_info
*li_mimo
;
411 int maxpwr20
, maxpwr40
;
415 memset(txpwr
, 0, sizeof(struct txpwr_limits
));
420 country
= &wlc_cm
->world_regd
->country
;
422 chan
= CHSPEC_CHANNEL(chanspec
);
423 band
= wlc
->bandstate
[chspec_bandunit(chanspec
)];
424 li_mimo
= (band
->bandtype
== BRCM_BAND_5G
) ?
425 brcms_c_get_mimo_5g(country
->locale_mimo_5G
) :
426 brcms_c_get_mimo_2g(country
->locale_mimo_2G
);
428 delta
= band
->antgain
;
430 if (band
->bandtype
== BRCM_BAND_2G
)
431 conducted_max
= QDB(22);
433 maxpwr
= QDB(ch
->max_power
) - delta
;
434 maxpwr
= max(maxpwr
, 0);
435 maxpwr
= min(maxpwr
, conducted_max
);
437 /* CCK txpwr limits for 2.4G band */
438 if (band
->bandtype
== BRCM_BAND_2G
) {
439 for (i
= 0; i
< BRCMS_NUM_RATES_CCK
; i
++)
440 txpwr
->cck
[i
] = (u8
) maxpwr
;
443 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
444 txpwr
->ofdm
[i
] = (u8
) maxpwr
;
447 * OFDM 40 MHz SISO has the same power as the corresponding
448 * MCS0-7 rate unless overriden by the locale specific code.
449 * We set this value to 0 as a flag (presumably 0 dBm isn't
450 * a possibility) and then copy the MCS0-7 value to the 40 MHz
451 * value if it wasn't explicitly set.
453 txpwr
->ofdm_40_siso
[i
] = 0;
455 txpwr
->ofdm_cdd
[i
] = (u8
) maxpwr
;
457 txpwr
->ofdm_40_cdd
[i
] = 0;
461 if (band
->antgain
> QDB(6))
462 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
464 if (band
->bandtype
== BRCM_BAND_2G
)
465 maxpwr_idx
= (chan
- 1);
467 maxpwr_idx
= CHANNEL_POWER_IDX_5G(chan
);
469 maxpwr20
= li_mimo
->maxpwr20
[maxpwr_idx
];
470 maxpwr40
= li_mimo
->maxpwr40
[maxpwr_idx
];
472 maxpwr20
= maxpwr20
- delta
;
473 maxpwr20
= max(maxpwr20
, 0);
474 maxpwr40
= maxpwr40
- delta
;
475 maxpwr40
= max(maxpwr40
, 0);
477 /* Fill in the MCS 0-7 (SISO) rates */
478 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
481 * 20 MHz has the same power as the corresponding OFDM rate
482 * unless overriden by the locale specific code.
484 txpwr
->mcs_20_siso
[i
] = txpwr
->ofdm
[i
];
485 txpwr
->mcs_40_siso
[i
] = 0;
488 /* Fill in the MCS 0-7 CDD rates */
489 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
490 txpwr
->mcs_20_cdd
[i
] = (u8
) maxpwr20
;
491 txpwr
->mcs_40_cdd
[i
] = (u8
) maxpwr40
;
495 * These locales have SISO expressed in the
496 * table and override CDD later
498 if (li_mimo
== &locale_bn
) {
499 if (li_mimo
== &locale_bn
) {
503 if (chan
>= 3 && chan
<= 11)
507 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
508 txpwr
->mcs_20_siso
[i
] = (u8
) maxpwr20
;
509 txpwr
->mcs_40_siso
[i
] = (u8
) maxpwr40
;
513 /* Fill in the MCS 0-7 STBC rates */
514 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
515 txpwr
->mcs_20_stbc
[i
] = 0;
516 txpwr
->mcs_40_stbc
[i
] = 0;
519 /* Fill in the MCS 8-15 SDM rates */
520 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_2_STREAM
; i
++) {
521 txpwr
->mcs_20_mimo
[i
] = (u8
) maxpwr20
;
522 txpwr
->mcs_40_mimo
[i
] = (u8
) maxpwr40
;
526 txpwr
->mcs32
= (u8
) maxpwr40
;
528 for (i
= 0, j
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++, j
++) {
529 if (txpwr
->ofdm_40_cdd
[i
] == 0)
530 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
533 if (txpwr
->ofdm_40_cdd
[i
] == 0)
534 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
539 * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
540 * value if it wasn't provided explicitly.
542 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
543 if (txpwr
->mcs_40_siso
[i
] == 0)
544 txpwr
->mcs_40_siso
[i
] = txpwr
->mcs_40_cdd
[i
];
547 for (i
= 0, j
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++, j
++) {
548 if (txpwr
->ofdm_40_siso
[i
] == 0)
549 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
552 if (txpwr
->ofdm_40_siso
[i
] == 0)
553 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
558 * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
559 * STBC values if they weren't provided explicitly.
561 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
562 if (txpwr
->mcs_20_stbc
[i
] == 0)
563 txpwr
->mcs_20_stbc
[i
] = txpwr
->mcs_20_cdd
[i
];
565 if (txpwr
->mcs_40_stbc
[i
] == 0)
566 txpwr
->mcs_40_stbc
[i
] = txpwr
->mcs_40_cdd
[i
];
573 * Verify the chanspec is using a legal set of parameters, i.e. that the
574 * chanspec specified a band, bw, ctl_sb and channel and that the
575 * combination could be legal given any set of circumstances.
576 * RETURNS: true is the chanspec is malformed, false if it looks good.
578 static bool brcms_c_chspec_malformed(u16 chanspec
)
580 /* must be 2G or 5G band */
581 if (!CHSPEC_IS5G(chanspec
) && !CHSPEC_IS2G(chanspec
))
583 /* must be 20 or 40 bandwidth */
584 if (!CHSPEC_IS40(chanspec
) && !CHSPEC_IS20(chanspec
))
587 /* 20MHZ b/w must have no ctl sb, 40 must have a ctl sb */
588 if (CHSPEC_IS20(chanspec
)) {
589 if (!CHSPEC_SB_NONE(chanspec
))
591 } else if (!CHSPEC_SB_UPPER(chanspec
) && !CHSPEC_SB_LOWER(chanspec
)) {
599 * Validate the chanspec for this locale, for 40MHZ we need to also
600 * check that the sidebands are valid 20MZH channels in this locale
601 * and they are also a legal HT combination
604 brcms_c_valid_chanspec_ext(struct brcms_cm_info
*wlc_cm
, u16 chspec
)
606 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
607 u8 channel
= CHSPEC_CHANNEL(chspec
);
609 /* check the chanspec */
610 if (brcms_c_chspec_malformed(chspec
)) {
611 brcms_err(wlc
->hw
->d11core
, "wl%d: malformed chanspec 0x%x\n",
612 wlc
->pub
->unit
, chspec
);
616 if (CHANNEL_BANDUNIT(wlc_cm
->wlc
, channel
) !=
617 chspec_bandunit(chspec
))
623 bool brcms_c_valid_chanspec_db(struct brcms_cm_info
*wlc_cm
, u16 chspec
)
625 return brcms_c_valid_chanspec_ext(wlc_cm
, chspec
);
628 static bool brcms_is_radar_freq(u16 center_freq
)
630 return center_freq
>= 5260 && center_freq
<= 5700;
633 static void brcms_reg_apply_radar_flags(struct wiphy
*wiphy
)
635 struct ieee80211_supported_band
*sband
;
636 struct ieee80211_channel
*ch
;
639 sband
= wiphy
->bands
[NL80211_BAND_5GHZ
];
643 for (i
= 0; i
< sband
->n_channels
; i
++) {
644 ch
= &sband
->channels
[i
];
646 if (!brcms_is_radar_freq(ch
->center_freq
))
650 * All channels in this range should be passive and have
653 if (!(ch
->flags
& IEEE80211_CHAN_DISABLED
))
654 ch
->flags
|= IEEE80211_CHAN_RADAR
|
655 IEEE80211_CHAN_NO_IR
|
656 IEEE80211_CHAN_NO_IR
;
661 brcms_reg_apply_beaconing_flags(struct wiphy
*wiphy
,
662 enum nl80211_reg_initiator initiator
)
664 struct ieee80211_supported_band
*sband
;
665 struct ieee80211_channel
*ch
;
666 const struct ieee80211_reg_rule
*rule
;
669 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
670 sband
= wiphy
->bands
[band
];
674 for (i
= 0; i
< sband
->n_channels
; i
++) {
675 ch
= &sband
->channels
[i
];
678 (IEEE80211_CHAN_DISABLED
| IEEE80211_CHAN_RADAR
))
681 if (initiator
== NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
682 rule
= freq_reg_info(wiphy
,
683 MHZ_TO_KHZ(ch
->center_freq
));
687 if (!(rule
->flags
& NL80211_RRF_NO_IR
))
688 ch
->flags
&= ~IEEE80211_CHAN_NO_IR
;
689 } else if (ch
->beacon_found
) {
690 ch
->flags
&= ~IEEE80211_CHAN_NO_IR
;
696 static void brcms_reg_notifier(struct wiphy
*wiphy
,
697 struct regulatory_request
*request
)
699 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
700 struct brcms_info
*wl
= hw
->priv
;
701 struct brcms_c_info
*wlc
= wl
->wlc
;
702 struct ieee80211_supported_band
*sband
;
703 struct ieee80211_channel
*ch
;
705 bool ch_found
= false;
707 brcms_reg_apply_radar_flags(wiphy
);
709 if (request
->initiator
== NL80211_REGDOM_SET_BY_COUNTRY_IE
)
710 brcms_reg_apply_beaconing_flags(wiphy
, request
->initiator
);
712 /* Disable radio if all channels disallowed by regulatory */
713 for (band
= 0; !ch_found
&& band
< NUM_NL80211_BANDS
; band
++) {
714 sband
= wiphy
->bands
[band
];
718 for (i
= 0; !ch_found
&& i
< sband
->n_channels
; i
++) {
719 ch
= &sband
->channels
[i
];
721 if (!(ch
->flags
& IEEE80211_CHAN_DISABLED
))
727 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
729 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
730 brcms_err(wlc
->hw
->d11core
,
731 "wl%d: %s: no valid channel for \"%s\"\n",
732 wlc
->pub
->unit
, __func__
, request
->alpha2
);
735 if (wlc
->pub
->_nbands
> 1 || wlc
->band
->bandtype
== BRCM_BAND_2G
)
736 wlc_phy_chanspec_ch14_widefilter_set(wlc
->band
->pi
,
737 brcms_c_japan_ccode(request
->alpha2
));
740 void brcms_c_regd_init(struct brcms_c_info
*wlc
)
742 struct wiphy
*wiphy
= wlc
->wiphy
;
743 const struct brcms_regd
*regd
= wlc
->cmi
->world_regd
;
744 struct ieee80211_supported_band
*sband
;
745 struct ieee80211_channel
*ch
;
746 struct brcms_chanvec sup_chan
;
747 struct brcms_band
*band
;
750 /* Disable any channels not supported by the phy */
751 for (band_idx
= 0; band_idx
< wlc
->pub
->_nbands
; band_idx
++) {
752 band
= wlc
->bandstate
[band_idx
];
754 wlc_phy_chanspec_band_validch(band
->pi
, band
->bandtype
,
757 if (band_idx
== BAND_2G_INDEX
)
758 sband
= wiphy
->bands
[NL80211_BAND_2GHZ
];
760 sband
= wiphy
->bands
[NL80211_BAND_5GHZ
];
762 for (i
= 0; i
< sband
->n_channels
; i
++) {
763 ch
= &sband
->channels
[i
];
764 if (!isset(sup_chan
.vec
, ch
->hw_value
))
765 ch
->flags
|= IEEE80211_CHAN_DISABLED
;
769 wlc
->wiphy
->reg_notifier
= brcms_reg_notifier
;
770 wlc
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
771 REGULATORY_STRICT_REG
;
772 wiphy_apply_custom_regulatory(wlc
->wiphy
, regd
->regdomain
);
773 brcms_reg_apply_beaconing_flags(wiphy
, NL80211_REGDOM_SET_BY_DRIVER
);