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.
21 #include <linux/kernel.h>
22 #include <linux/string.h>
29 #include <wlc_mac80211.h>
32 #include <wlc_channel.h>
34 typedef struct wlc_cm_band
{
35 u8 locale_flags
; /* locale_info_t flags */
36 chanvec_t valid_channels
; /* List of valid channels in the country */
37 const chanvec_t
*restricted_channels
; /* List of restricted use channels */
38 const chanvec_t
*radar_channels
; /* List of radar sensitive channels */
45 char srom_ccode
[WLC_CNTRY_BUF_SZ
]; /* Country Code in SROM */
46 uint srom_regrev
; /* Regulatory Rev for the SROM ccode */
47 const country_info_t
*country
; /* current country def */
48 char ccode
[WLC_CNTRY_BUF_SZ
]; /* current internal Country Code */
49 uint regrev
; /* current Regulatory Revision */
50 char country_abbrev
[WLC_CNTRY_BUF_SZ
]; /* current advertised ccode */
51 wlc_cm_band_t bandstate
[MAXBANDS
]; /* per-band state (one per phy/radio) */
52 /* quiet channels currently for radar sensitivity or 11h support */
53 chanvec_t quiet_channels
; /* channels on which we cannot transmit */
56 static int wlc_channels_init(wlc_cm_info_t
*wlc_cm
,
57 const country_info_t
*country
);
58 static void wlc_set_country_common(wlc_cm_info_t
*wlc_cm
,
59 const char *country_abbrev
,
60 const char *ccode
, uint regrev
,
61 const country_info_t
*country
);
62 static int wlc_country_aggregate_map(wlc_cm_info_t
*wlc_cm
, const char *ccode
,
63 char *mapped_ccode
, uint
*mapped_regrev
);
64 static const country_info_t
*wlc_country_lookup_direct(const char *ccode
,
66 static const country_info_t
*wlc_countrycode_map(wlc_cm_info_t
*wlc_cm
,
70 static void wlc_channels_commit(wlc_cm_info_t
*wlc_cm
);
71 static bool wlc_japan_ccode(const char *ccode
);
72 static void wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t
*
78 local_constraint_qdbm
);
79 void wlc_locale_add_channels(chanvec_t
*target
, const chanvec_t
*channels
);
80 static const locale_mimo_info_t
*wlc_get_mimo_2g(u8 locale_idx
);
81 static const locale_mimo_info_t
*wlc_get_mimo_5g(u8 locale_idx
);
83 /* QDB() macro takes a dB value and converts to a quarter dB value */
87 #define QDB(n) ((n) * WLC_TXPWR_DB_FACTOR)
89 /* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
92 * Some common channel sets
96 static const chanvec_t chanvec_none
= {
97 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00}
103 /* All 2.4 GHz HW channels */
104 const chanvec_t chanvec_all_2G
= {
105 {0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00}
111 /* All 5 GHz HW channels */
112 const chanvec_t chanvec_all_5G
= {
113 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x11, 0x11,
114 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11,
115 0x11, 0x11, 0x20, 0x22, 0x22, 0x00, 0x00, 0x11,
116 0x11, 0x11, 0x11, 0x01}
124 #define radar_set_none chanvec_none
126 static const chanvec_t radar_set1
= { /* Channels 52 - 64, 100 - 140 */
127 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, /* 52 - 60 */
128 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11, /* 64, 100 - 124 */
129 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128 - 140 */
130 0x00, 0x00, 0x00, 0x00}
134 * Restricted channel sets
137 #define restricted_set_none chanvec_none
139 /* Channels 34, 38, 42, 46 */
140 static const chanvec_t restricted_set_japan_legacy
= {
141 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 0x00, 0x00, 0x00, 0x00}
147 /* Channels 12, 13 */
148 static const chanvec_t restricted_set_2g_short
= {
149 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00}
156 static const chanvec_t restricted_chan_165
= {
157 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00}
163 /* Channels 36 - 48 & 149 - 165 */
164 static const chanvec_t restricted_low_hi
= {
165 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x20, 0x22, 0x22, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00}
171 /* Channels 12 - 14 */
172 static const chanvec_t restricted_set_12_13_14
= {
173 {0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0x00}
179 #define LOCALE_CHAN_01_11 (1<<0)
180 #define LOCALE_CHAN_12_13 (1<<1)
181 #define LOCALE_CHAN_14 (1<<2)
182 #define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
183 #define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
184 #define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
185 #define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
186 #define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
187 #define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
188 #define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
189 #define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
190 #define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
191 #define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
192 #define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
193 #define LOCALE_CHAN_52_140_ALL (1<<14)
194 #define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
196 #define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
197 #define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
198 #define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
199 #define LOCALE_CHAN_100_140 \
200 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
201 #define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
202 #define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
204 #define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13 | LOCALE_CHAN_14)
206 #define LOCALE_RADAR_SET_NONE 0
207 #define LOCALE_RADAR_SET_1 1
209 #define LOCALE_RESTRICTED_NONE 0
210 #define LOCALE_RESTRICTED_SET_2G_SHORT 1
211 #define LOCALE_RESTRICTED_CHAN_165 2
212 #define LOCALE_CHAN_ALL_5G 3
213 #define LOCALE_RESTRICTED_JAPAN_LEGACY 4
214 #define LOCALE_RESTRICTED_11D_2G 5
215 #define LOCALE_RESTRICTED_11D_5G 6
216 #define LOCALE_RESTRICTED_LOW_HI 7
217 #define LOCALE_RESTRICTED_12_13_14 8
219 /* global memory to provide working buffer for expanded locale */
221 static const chanvec_t
*g_table_radar_set
[] = {
226 static const chanvec_t
*g_table_restricted_chan
[] = {
227 &chanvec_none
, /* restricted_set_none */
228 &restricted_set_2g_short
,
229 &restricted_chan_165
,
231 &restricted_set_japan_legacy
,
232 &chanvec_all_2G
, /* restricted_set_11d_2G */
233 &chanvec_all_5G
, /* restricted_set_11d_5G */
235 &restricted_set_12_13_14
238 static const chanvec_t locale_2g_01_11
= {
239 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00}
245 static const chanvec_t locale_2g_12_13
= {
246 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00}
252 static const chanvec_t locale_2g_14
= {
253 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00}
259 static const chanvec_t locale_5g_LOW_JP1
= {
260 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00}
266 static const chanvec_t locale_5g_LOW_JP2
= {
267 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00}
273 static const chanvec_t locale_5g_LOW1
= {
274 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00}
280 static const chanvec_t locale_5g_LOW2
= {
281 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00}
287 static const chanvec_t locale_5g_LOW3
= {
288 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
289 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0x00, 0x00, 0x00, 0x00}
294 static const chanvec_t locale_5g_MID1
= {
295 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 0x00, 0x00, 0x00, 0x00}
301 static const chanvec_t locale_5g_MID2
= {
302 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00}
308 static const chanvec_t locale_5g_MID3
= {
309 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00}
315 static const chanvec_t locale_5g_HIGH1
= {
316 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x00, 0x00, 0x00, 0x00}
322 static const chanvec_t locale_5g_HIGH2
= {
323 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
326 0x00, 0x00, 0x00, 0x00}
329 static const chanvec_t locale_5g_HIGH3
= {
330 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
333 0x00, 0x00, 0x00, 0x00}
336 static const chanvec_t locale_5g_52_140_ALL
= {
337 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
338 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
339 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
340 0x00, 0x00, 0x00, 0x00}
343 static const chanvec_t locale_5g_HIGH4
= {
344 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
347 0x11, 0x11, 0x11, 0x11}
350 static const chanvec_t
*g_table_locale_base
[] = {
365 &locale_5g_52_140_ALL
,
369 void wlc_locale_add_channels(chanvec_t
*target
, const chanvec_t
*channels
)
372 for (i
= 0; i
< sizeof(chanvec_t
); i
++) {
373 target
->vec
[i
] |= channels
->vec
[i
];
377 void wlc_locale_get_channels(const locale_info_t
*locale
, chanvec_t
*channels
)
381 bzero(channels
, sizeof(chanvec_t
));
383 for (i
= 0; i
< ARRAYSIZE(g_table_locale_base
); i
++) {
384 if (locale
->valid_channels
& (1 << i
)) {
385 wlc_locale_add_channels(channels
,
386 g_table_locale_base
[i
]);
392 * Locale Definitions - 2.4 GHz
394 static const locale_info_t locale_i
= { /* locale i. channel 1 - 13 */
395 LOCALE_CHAN_01_11
| LOCALE_CHAN_12_13
,
396 LOCALE_RADAR_SET_NONE
,
397 LOCALE_RESTRICTED_SET_2G_SHORT
,
398 {QDB(19), QDB(19), QDB(19),
399 QDB(19), QDB(19), QDB(19)},
405 * Locale Definitions - 5 GHz
407 static const locale_info_t locale_11
= {
408 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
409 LOCALE_CHAN_36_64
| LOCALE_CHAN_100_140
| LOCALE_CHAN_149_165
,
411 LOCALE_RESTRICTED_NONE
,
412 {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
413 {23, 23, 23, 30, 30},
414 WLC_EIRP
| WLC_DFS_EU
417 #define LOCALE_2G_IDX_i 0
418 static const locale_info_t
*g_locale_2g_table
[] = {
422 #define LOCALE_5G_IDX_11 0
423 static const locale_info_t
*g_locale_5g_table
[] = {
428 * MIMO Locale Definitions - 2.4 GHz
430 static const locale_mimo_info_t locale_bn
= {
431 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
432 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
433 QDB(13), QDB(13), QDB(13)},
434 {0, 0, QDB(13), QDB(13), QDB(13),
435 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
440 /* locale mimo 2g indexes */
441 #define LOCALE_MIMO_IDX_bn 0
443 static const locale_mimo_info_t
*g_mimo_2g_table
[] = {
448 * MIMO Locale Definitions - 5 GHz
450 static const locale_mimo_info_t locale_11n
= {
451 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
452 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
456 #define LOCALE_MIMO_IDX_11n 0
457 static const locale_mimo_info_t
*g_mimo_5g_table
[] = {
464 #define LC(id) LOCALE_MIMO_IDX_ ## id
469 #define LC_2G(id) LOCALE_2G_IDX_ ## id
474 #define LC_5G(id) LOCALE_5G_IDX_ ## id
476 #define LOCALES(band2, band5, mimo2, mimo5) {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
478 static const struct {
479 char abbrev
[WLC_CNTRY_BUF_SZ
]; /* country abbreviation */
480 country_info_t country
;
481 } cntry_locales
[] = {
483 "X2", LOCALES(i
, 11, bn
, 11n
)}, /* Worldwide RoW 2 */
487 /* 20MHz channel info for 40MHz pairing support */
493 /* indicates adjacent channels that are allowed for a 40 Mhz channel and
494 * those that permitted by the HT
496 struct chan20_info chan20_info
[] = {
498 /* 0 */ {1, (CH_UPPER_SB
| CH_EWA_VALID
)},
499 /* 1 */ {2, (CH_UPPER_SB
| CH_EWA_VALID
)},
500 /* 2 */ {3, (CH_UPPER_SB
| CH_EWA_VALID
)},
501 /* 3 */ {4, (CH_UPPER_SB
| CH_EWA_VALID
)},
502 /* 4 */ {5, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
503 /* 5 */ {6, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
504 /* 6 */ {7, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
505 /* 7 */ {8, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
506 /* 8 */ {9, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
507 /* 9 */ {10, (CH_LOWER_SB
| CH_EWA_VALID
)},
508 /* 10 */ {11, (CH_LOWER_SB
| CH_EWA_VALID
)},
509 /* 11 */ {12, (CH_LOWER_SB
)},
510 /* 12 */ {13, (CH_LOWER_SB
)},
511 /* 13 */ {14, (CH_LOWER_SB
)},
514 /* 14 */ {34, (CH_UPPER_SB
)},
515 /* 15 */ {38, (CH_LOWER_SB
)},
516 /* 16 */ {42, (CH_LOWER_SB
)},
517 /* 17 */ {46, (CH_LOWER_SB
)},
520 /* 18 */ {36, (CH_UPPER_SB
| CH_EWA_VALID
)},
521 /* 19 */ {40, (CH_LOWER_SB
| CH_EWA_VALID
)},
522 /* 20 */ {44, (CH_UPPER_SB
| CH_EWA_VALID
)},
523 /* 21 */ {48, (CH_LOWER_SB
| CH_EWA_VALID
)},
524 /* 22 */ {52, (CH_UPPER_SB
| CH_EWA_VALID
)},
525 /* 23 */ {56, (CH_LOWER_SB
| CH_EWA_VALID
)},
526 /* 24 */ {60, (CH_UPPER_SB
| CH_EWA_VALID
)},
527 /* 25 */ {64, (CH_LOWER_SB
| CH_EWA_VALID
)},
530 /* 26 */ {100, (CH_UPPER_SB
| CH_EWA_VALID
)},
531 /* 27 */ {104, (CH_LOWER_SB
| CH_EWA_VALID
)},
532 /* 28 */ {108, (CH_UPPER_SB
| CH_EWA_VALID
)},
533 /* 29 */ {112, (CH_LOWER_SB
| CH_EWA_VALID
)},
534 /* 30 */ {116, (CH_UPPER_SB
| CH_EWA_VALID
)},
535 /* 31 */ {120, (CH_LOWER_SB
| CH_EWA_VALID
)},
536 /* 32 */ {124, (CH_UPPER_SB
| CH_EWA_VALID
)},
537 /* 33 */ {128, (CH_LOWER_SB
| CH_EWA_VALID
)},
538 /* 34 */ {132, (CH_UPPER_SB
| CH_EWA_VALID
)},
539 /* 35 */ {136, (CH_LOWER_SB
| CH_EWA_VALID
)},
540 /* 36 */ {140, (CH_LOWER_SB
)},
542 /* 11a usa high, ref5 only */
543 /* The 0x80 bit in pdiv means these are REF5, other entries are REF20 */
544 /* 37 */ {149, (CH_UPPER_SB
| CH_EWA_VALID
)},
545 /* 38 */ {153, (CH_LOWER_SB
| CH_EWA_VALID
)},
546 /* 39 */ {157, (CH_UPPER_SB
| CH_EWA_VALID
)},
547 /* 40 */ {161, (CH_LOWER_SB
| CH_EWA_VALID
)},
548 /* 41 */ {165, (CH_LOWER_SB
)},
551 /* 42 */ {184, (CH_UPPER_SB
)},
552 /* 43 */ {188, (CH_LOWER_SB
)},
553 /* 44 */ {192, (CH_UPPER_SB
)},
554 /* 45 */ {196, (CH_LOWER_SB
)},
555 /* 46 */ {200, (CH_UPPER_SB
)},
556 /* 47 */ {204, (CH_LOWER_SB
)},
557 /* 48 */ {208, (CH_UPPER_SB
)},
558 /* 49 */ {212, (CH_LOWER_SB
)},
559 /* 50 */ {216, (CH_LOWER_SB
)}
561 #endif /* SUPPORT_40MHZ */
563 const locale_info_t
*wlc_get_locale_2g(u8 locale_idx
)
565 if (locale_idx
>= ARRAYSIZE(g_locale_2g_table
)) {
566 WL_ERROR(("%s: locale 2g index size out of range %d\n",
567 __func__
, locale_idx
));
568 ASSERT(locale_idx
< ARRAYSIZE(g_locale_2g_table
));
571 return g_locale_2g_table
[locale_idx
];
574 const locale_info_t
*wlc_get_locale_5g(u8 locale_idx
)
576 if (locale_idx
>= ARRAYSIZE(g_locale_5g_table
)) {
577 WL_ERROR(("%s: locale 5g index size out of range %d\n",
578 __func__
, locale_idx
));
579 ASSERT(locale_idx
< ARRAYSIZE(g_locale_5g_table
));
582 return g_locale_5g_table
[locale_idx
];
585 const locale_mimo_info_t
*wlc_get_mimo_2g(u8 locale_idx
)
587 if (locale_idx
>= ARRAYSIZE(g_mimo_2g_table
)) {
588 WL_ERROR(("%s: mimo 2g index size out of range %d\n", __func__
,
592 return g_mimo_2g_table
[locale_idx
];
595 const locale_mimo_info_t
*wlc_get_mimo_5g(u8 locale_idx
)
597 if (locale_idx
>= ARRAYSIZE(g_mimo_5g_table
)) {
598 WL_ERROR(("%s: mimo 5g index size out of range %d\n", __func__
,
602 return g_mimo_5g_table
[locale_idx
];
605 wlc_cm_info_t
*BCMATTACHFN(wlc_channel_mgr_attach
) (wlc_info_t
*wlc
)
607 wlc_cm_info_t
*wlc_cm
;
608 char country_abbrev
[WLC_CNTRY_BUF_SZ
];
609 const country_info_t
*country
;
610 wlc_pub_t
*pub
= wlc
->pub
;
613 WL_TRACE(("wl%d: wlc_channel_mgr_attach\n", wlc
->pub
->unit
));
615 wlc_cm
= (wlc_cm_info_t
*) MALLOC(pub
->osh
, sizeof(wlc_cm_info_t
));
616 if (wlc_cm
== NULL
) {
617 WL_ERROR(("wl%d: %s: out of memory, malloced %d bytes",
618 pub
->unit
, __func__
, MALLOCED(pub
->osh
)));
621 bzero((char *)wlc_cm
, sizeof(wlc_cm_info_t
));
626 /* store the country code for passing up as a regulatory hint */
627 ccode
= getvar(wlc
->pub
->vars
, "ccode");
629 strncpy(wlc
->pub
->srom_ccode
, ccode
, WLC_CNTRY_BUF_SZ
- 1);
630 WL_NONE(("%s: SROM country code is %c%c\n", __func__
,
631 wlc
->pub
->srom_ccode
[0], wlc
->pub
->srom_ccode
[1]));
634 /* internal country information which must match regulatory constraints in firmware */
635 bzero(country_abbrev
, WLC_CNTRY_BUF_SZ
);
636 strncpy(country_abbrev
, "X2", sizeof(country_abbrev
) - 1);
637 country
= wlc_country_lookup(wlc
, country_abbrev
);
639 ASSERT(country
!= NULL
);
641 /* save default country for exiting 11d regulatory mode */
642 strncpy(wlc
->country_default
, country_abbrev
, WLC_CNTRY_BUF_SZ
- 1);
644 /* initialize autocountry_default to driver default */
645 strncpy(wlc
->autocountry_default
, "X2", WLC_CNTRY_BUF_SZ
- 1);
647 wlc_set_countrycode(wlc_cm
, country_abbrev
);
652 void BCMATTACHFN(wlc_channel_mgr_detach
) (wlc_cm_info_t
*wlc_cm
)
655 MFREE(wlc_cm
->pub
->osh
, wlc_cm
, sizeof(wlc_cm_info_t
));
658 const char *wlc_channel_country_abbrev(wlc_cm_info_t
*wlc_cm
)
660 return wlc_cm
->country_abbrev
;
663 u8
wlc_channel_locale_flags(wlc_cm_info_t
*wlc_cm
)
665 wlc_info_t
*wlc
= wlc_cm
->wlc
;
667 return wlc_cm
->bandstate
[wlc
->band
->bandunit
].locale_flags
;
670 u8
wlc_channel_locale_flags_in_band(wlc_cm_info_t
*wlc_cm
, uint bandunit
)
672 return wlc_cm
->bandstate
[bandunit
].locale_flags
;
675 /* return chanvec for a given country code and band */
677 wlc_channel_get_chanvec(struct wlc_info
*wlc
, const char *country_abbrev
,
678 int bandtype
, chanvec_t
*channels
)
680 const country_info_t
*country
;
681 const locale_info_t
*locale
= NULL
;
683 country
= wlc_country_lookup(wlc
, country_abbrev
);
687 if (bandtype
== WLC_BAND_2G
)
688 locale
= wlc_get_locale_2g(country
->locale_2G
);
689 else if (bandtype
== WLC_BAND_5G
)
690 locale
= wlc_get_locale_5g(country
->locale_5G
);
694 wlc_locale_get_channels(locale
, channels
);
698 /* set the driver's current country and regulatory information using a country code
699 * as the source. Lookup built in country information found with the country code.
701 int wlc_set_countrycode(wlc_cm_info_t
*wlc_cm
, const char *ccode
)
703 char country_abbrev
[WLC_CNTRY_BUF_SZ
];
704 strncpy(country_abbrev
, ccode
, WLC_CNTRY_BUF_SZ
);
705 return wlc_set_countrycode_rev(wlc_cm
, country_abbrev
, ccode
, -1);
709 wlc_set_countrycode_rev(wlc_cm_info_t
*wlc_cm
,
710 const char *country_abbrev
,
711 const char *ccode
, int regrev
)
713 const country_info_t
*country
;
714 char mapped_ccode
[WLC_CNTRY_BUF_SZ
];
717 WL_NONE(("%s: (country_abbrev \"%s\", ccode \"%s\", regrev %d) SPROM \"%s\"/%u\n", __func__
, country_abbrev
, ccode
, regrev
, wlc_cm
->srom_ccode
, wlc_cm
->srom_regrev
));
719 /* if regrev is -1, lookup the mapped country code,
720 * otherwise use the ccode and regrev directly
723 /* map the country code to a built-in country code, regrev, and country_info */
725 wlc_countrycode_map(wlc_cm
, ccode
, mapped_ccode
,
728 /* find the matching built-in country definition */
730 country
= wlc_country_lookup_direct(ccode
, regrev
);
731 strncpy(mapped_ccode
, ccode
, WLC_CNTRY_BUF_SZ
);
732 mapped_regrev
= regrev
;
738 /* set the driver state for the country */
739 wlc_set_country_common(wlc_cm
, country_abbrev
, mapped_ccode
,
740 mapped_regrev
, country
);
745 /* set the driver's current country and regulatory information using a country code
746 * as the source. Look up built in country information found with the country code.
749 wlc_set_country_common(wlc_cm_info_t
*wlc_cm
,
750 const char *country_abbrev
,
751 const char *ccode
, uint regrev
,
752 const country_info_t
*country
)
754 const locale_mimo_info_t
*li_mimo
;
755 const locale_info_t
*locale
;
756 wlc_info_t
*wlc
= wlc_cm
->wlc
;
757 char prev_country_abbrev
[WLC_CNTRY_BUF_SZ
];
759 ASSERT(country
!= NULL
);
761 /* save current country state */
762 wlc_cm
->country
= country
;
764 bzero(&prev_country_abbrev
, WLC_CNTRY_BUF_SZ
);
765 strncpy(prev_country_abbrev
, wlc_cm
->country_abbrev
,
766 WLC_CNTRY_BUF_SZ
- 1);
768 strncpy(wlc_cm
->country_abbrev
, country_abbrev
, WLC_CNTRY_BUF_SZ
- 1);
769 strncpy(wlc_cm
->ccode
, ccode
, WLC_CNTRY_BUF_SZ
- 1);
770 wlc_cm
->regrev
= regrev
;
772 /* disable/restore nmode based on country regulations */
773 li_mimo
= wlc_get_mimo_2g(country
->locale_mimo_2G
);
774 if (li_mimo
&& (li_mimo
->flags
& WLC_NO_MIMO
)) {
775 wlc_set_nmode(wlc
, OFF
);
776 wlc
->stf
->no_cddstbc
= TRUE
;
778 wlc
->stf
->no_cddstbc
= FALSE
;
779 if (N_ENAB(wlc
->pub
) != wlc
->protection
->nmode_user
)
780 wlc_set_nmode(wlc
, wlc
->protection
->nmode_user
);
783 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
784 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
785 /* set or restore gmode as required by regulatory */
786 locale
= wlc_get_locale_2g(country
->locale_2G
);
787 if (locale
&& (locale
->flags
& WLC_NO_OFDM
)) {
788 wlc_set_gmode(wlc
, GMODE_LEGACY_B
, FALSE
);
790 wlc_set_gmode(wlc
, wlc
->protection
->gmode_user
, FALSE
);
793 wlc_channels_init(wlc_cm
, country
);
798 /* Lookup a country info structure from a null terminated country code
799 * The lookup is case sensitive.
801 const country_info_t
*wlc_country_lookup(struct wlc_info
*wlc
,
804 const country_info_t
*country
;
805 char mapped_ccode
[WLC_CNTRY_BUF_SZ
];
808 /* map the country code to a built-in country code, regrev, and country_info struct */
810 wlc_countrycode_map(wlc
->cmi
, ccode
, mapped_ccode
, &mapped_regrev
);
815 static const country_info_t
*wlc_countrycode_map(wlc_cm_info_t
*wlc_cm
,
820 wlc_info_t
*wlc
= wlc_cm
->wlc
;
821 const country_info_t
*country
;
822 uint srom_regrev
= wlc_cm
->srom_regrev
;
823 const char *srom_ccode
= wlc_cm
->srom_ccode
;
826 /* check for currently supported ccode size */
827 if (strlen(ccode
) > (WLC_CNTRY_BUF_SZ
- 1)) {
828 WL_ERROR(("wl%d: %s: ccode \"%s\" too long for match\n",
829 wlc
->pub
->unit
, __func__
, ccode
));
833 /* default mapping is the given ccode and regrev 0 */
834 strncpy(mapped_ccode
, ccode
, WLC_CNTRY_BUF_SZ
);
837 /* If the desired country code matches the srom country code,
838 * then the mapped country is the srom regulatory rev.
839 * Otherwise look for an aggregate mapping.
841 if (!strcmp(srom_ccode
, ccode
)) {
842 *mapped_regrev
= srom_regrev
;
844 WL_ERROR(("srom_code == ccode %s\n", __func__
));
848 wlc_country_aggregate_map(wlc_cm
, ccode
, mapped_ccode
,
852 /* find the matching built-in country definition */
853 country
= wlc_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
855 /* if there is not an exact rev match, default to rev zero */
856 if (country
== NULL
&& *mapped_regrev
!= 0) {
860 wlc_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
867 wlc_country_aggregate_map(wlc_cm_info_t
*wlc_cm
, const char *ccode
,
868 char *mapped_ccode
, uint
*mapped_regrev
)
873 /* Lookup a country info structure from a null terminated country
874 * abbreviation and regrev directly with no translation.
876 static const country_info_t
*wlc_country_lookup_direct(const char *ccode
,
881 /* Should just return 0 for single locale driver. */
882 /* Keep it this way in case we add more locales. (for now anyway) */
884 /* all other country def arrays are for regrev == 0, so if regrev is non-zero, fail */
888 /* find matched table entry from country code */
889 size
= ARRAYSIZE(cntry_locales
);
890 for (i
= 0; i
< size
; i
++) {
891 if (strcmp(ccode
, cntry_locales
[i
].abbrev
) == 0) {
892 return &cntry_locales
[i
].country
;
896 WL_ERROR(("%s: Returning NULL\n", __func__
));
902 wlc_channels_init(wlc_cm_info_t
*wlc_cm
, const country_info_t
*country
)
904 wlc_info_t
*wlc
= wlc_cm
->wlc
;
907 const locale_info_t
*li
;
909 const locale_mimo_info_t
*li_mimo
;
912 for (i
= 0; i
< NBANDS(wlc
);
913 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
915 li
= BAND_5G(band
->bandtype
) ?
916 wlc_get_locale_5g(country
->locale_5G
) :
917 wlc_get_locale_2g(country
->locale_2G
);
919 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
= li
->flags
;
920 li_mimo
= BAND_5G(band
->bandtype
) ?
921 wlc_get_mimo_5g(country
->locale_mimo_5G
) :
922 wlc_get_mimo_2g(country
->locale_mimo_2G
);
925 /* merge the mimo non-mimo locale flags */
926 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
|=
929 wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
=
930 g_table_restricted_chan
[li
->restricted_channels
];
931 wlc_cm
->bandstate
[band
->bandunit
].radar_channels
=
932 g_table_radar_set
[li
->radar_channels
];
934 /* set the channel availability,
935 * masking out the channels that may not be supported on this phy
937 wlc_phy_chanspec_band_validch(band
->pi
, band
->bandtype
,
939 wlc_locale_get_channels(li
,
940 &wlc_cm
->bandstate
[band
->bandunit
].
942 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
943 wlc_cm
->bandstate
[band
->bandunit
].valid_channels
.
944 vec
[j
] &= sup_chan
.vec
[j
];
947 wlc_quiet_channels_reset(wlc_cm
);
948 wlc_channels_commit(wlc_cm
);
953 /* Update the radio state (enable/disable) and tx power targets
954 * based on a new set of channel/regulatory information
956 static void wlc_channels_commit(wlc_cm_info_t
*wlc_cm
)
958 wlc_info_t
*wlc
= wlc_cm
->wlc
;
960 struct txpwr_limits txpwr
;
962 /* search for the existence of any valid channel */
963 for (chan
= 0; chan
< MAXCHANNEL
; chan
++) {
964 if (VALID_CHANNEL20_DB(wlc
, chan
)) {
968 if (chan
== MAXCHANNEL
)
971 /* based on the channel search above, set or clear WL_RADIO_COUNTRY_DISABLE */
972 if (chan
== INVCHANNEL
) {
973 /* country/locale with no valid channels, set the radio disable bit */
974 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
975 WL_ERROR(("wl%d: %s: no valid channel for \"%s\" nbands %d bandlocked %d\n", wlc
->pub
->unit
, __func__
, wlc_cm
->country_abbrev
, NBANDS(wlc
), wlc
->bandlocked
));
977 if (mboolisset(wlc
->pub
->radio_disabled
,
978 WL_RADIO_COUNTRY_DISABLE
)) {
979 /* country/locale with valid channel, clear the radio disable bit */
980 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
983 /* Now that the country abbreviation is set, if the radio supports 2G, then
984 * set channel 14 restrictions based on the new locale.
986 if (NBANDS(wlc
) > 1 || BAND_2G(wlc
->band
->bandtype
)) {
987 wlc_phy_chanspec_ch14_widefilter_set(wlc
->band
->pi
,
988 wlc_japan(wlc
) ? TRUE
:
992 if (wlc
->pub
->up
&& chan
!= INVCHANNEL
) {
993 wlc_channel_reg_limits(wlc_cm
, wlc
->chanspec
, &txpwr
);
994 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm
,
997 wlc_phy_txpower_limit_set(wlc
->band
->pi
, &txpwr
, wlc
->chanspec
);
1001 /* reset the quiet channels vector to the union of the restricted and radar channel sets */
1002 void wlc_quiet_channels_reset(wlc_cm_info_t
*wlc_cm
)
1004 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1007 const chanvec_t
*chanvec
;
1009 bzero(&wlc_cm
->quiet_channels
, sizeof(chanvec_t
));
1012 for (i
= 0; i
< NBANDS(wlc
);
1013 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
1015 /* initialize quiet channels for restricted channels */
1016 chanvec
= wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
;
1017 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
1018 wlc_cm
->quiet_channels
.vec
[j
] |= chanvec
->vec
[j
];
1023 bool wlc_quiet_chanspec(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
)
1025 return N_ENAB(wlc_cm
->wlc
->pub
) && CHSPEC_IS40(chspec
) ?
1027 (wlc_cm
->quiet_channels
.vec
,
1028 LOWER_20_SB(CHSPEC_CHANNEL(chspec
)))
1029 || isset(wlc_cm
->quiet_channels
.vec
,
1030 UPPER_20_SB(CHSPEC_CHANNEL(chspec
)))) : isset(wlc_cm
->
1037 /* Is the channel valid for the current locale? (but don't consider channels not
1038 * available due to bandlocking)
1040 bool wlc_valid_channel20_db(wlc_cm_info_t
*wlc_cm
, uint val
)
1042 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1044 return VALID_CHANNEL20(wlc
, val
) ||
1046 && VALID_CHANNEL20_IN_BAND(wlc
, OTHERBANDUNIT(wlc
), val
));
1049 /* Is the channel valid for the current locale and specified band? */
1051 wlc_valid_channel20_in_band(wlc_cm_info_t
*wlc_cm
, uint bandunit
, uint val
)
1053 return ((val
< MAXCHANNEL
)
1054 && isset(wlc_cm
->bandstate
[bandunit
].valid_channels
.vec
, val
));
1057 /* Is the channel valid for the current locale and current band? */
1058 bool wlc_valid_channel20(wlc_cm_info_t
*wlc_cm
, uint val
)
1060 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1062 return ((val
< MAXCHANNEL
) &&
1063 isset(wlc_cm
->bandstate
[wlc
->band
->bandunit
].valid_channels
.vec
,
1067 /* Is the 40 MHz allowed for the current locale and specified band? */
1068 bool wlc_valid_40chanspec_in_band(wlc_cm_info_t
*wlc_cm
, uint bandunit
)
1070 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1072 return (((wlc_cm
->bandstate
[bandunit
].
1073 locale_flags
& (WLC_NO_MIMO
| WLC_NO_40MHZ
)) == 0)
1074 && wlc
->bandstate
[bandunit
]->mimo_cap_40
);
1078 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t
*wlc_cm
,
1079 struct txpwr_limits
*txpwr
,
1081 local_constraint_qdbm
)
1086 for (j
= 0; j
< WL_TX_POWER_CCK_NUM
; j
++) {
1087 txpwr
->cck
[j
] = min(txpwr
->cck
[j
], local_constraint_qdbm
);
1090 /* 20 MHz Legacy OFDM SISO */
1091 for (j
= 0; j
< WL_TX_POWER_OFDM_NUM
; j
++) {
1092 txpwr
->ofdm
[j
] = min(txpwr
->ofdm
[j
], local_constraint_qdbm
);
1095 /* 20 MHz Legacy OFDM CDD */
1096 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1097 txpwr
->ofdm_cdd
[j
] =
1098 min(txpwr
->ofdm_cdd
[j
], local_constraint_qdbm
);
1101 /* 40 MHz Legacy OFDM SISO */
1102 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1103 txpwr
->ofdm_40_siso
[j
] =
1104 min(txpwr
->ofdm_40_siso
[j
], local_constraint_qdbm
);
1107 /* 40 MHz Legacy OFDM CDD */
1108 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1109 txpwr
->ofdm_40_cdd
[j
] =
1110 min(txpwr
->ofdm_40_cdd
[j
], local_constraint_qdbm
);
1113 /* 20MHz MCS 0-7 SISO */
1114 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1115 txpwr
->mcs_20_siso
[j
] =
1116 min(txpwr
->mcs_20_siso
[j
], local_constraint_qdbm
);
1119 /* 20MHz MCS 0-7 CDD */
1120 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1121 txpwr
->mcs_20_cdd
[j
] =
1122 min(txpwr
->mcs_20_cdd
[j
], local_constraint_qdbm
);
1125 /* 20MHz MCS 0-7 STBC */
1126 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1127 txpwr
->mcs_20_stbc
[j
] =
1128 min(txpwr
->mcs_20_stbc
[j
], local_constraint_qdbm
);
1131 /* 20MHz MCS 8-15 MIMO */
1132 for (j
= 0; j
< WLC_NUM_RATES_MCS_2_STREAM
; j
++)
1133 txpwr
->mcs_20_mimo
[j
] =
1134 min(txpwr
->mcs_20_mimo
[j
], local_constraint_qdbm
);
1136 /* 40MHz MCS 0-7 SISO */
1137 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1138 txpwr
->mcs_40_siso
[j
] =
1139 min(txpwr
->mcs_40_siso
[j
], local_constraint_qdbm
);
1142 /* 40MHz MCS 0-7 CDD */
1143 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1144 txpwr
->mcs_40_cdd
[j
] =
1145 min(txpwr
->mcs_40_cdd
[j
], local_constraint_qdbm
);
1148 /* 40MHz MCS 0-7 STBC */
1149 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1150 txpwr
->mcs_40_stbc
[j
] =
1151 min(txpwr
->mcs_40_stbc
[j
], local_constraint_qdbm
);
1154 /* 40MHz MCS 8-15 MIMO */
1155 for (j
= 0; j
< WLC_NUM_RATES_MCS_2_STREAM
; j
++)
1156 txpwr
->mcs_40_mimo
[j
] =
1157 min(txpwr
->mcs_40_mimo
[j
], local_constraint_qdbm
);
1160 txpwr
->mcs32
= min(txpwr
->mcs32
, local_constraint_qdbm
);
1165 wlc_channel_set_chanspec(wlc_cm_info_t
*wlc_cm
, chanspec_t chanspec
,
1166 u8 local_constraint_qdbm
)
1168 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1169 struct txpwr_limits txpwr
;
1171 wlc_channel_reg_limits(wlc_cm
, chanspec
, &txpwr
);
1173 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm
, &txpwr
,
1174 local_constraint_qdbm
);
1176 wlc_bmac_set_chanspec(wlc
->hw
, chanspec
,
1177 (wlc_quiet_chanspec(wlc_cm
, chanspec
) != 0),
1182 wlc_channel_set_txpower_limit(wlc_cm_info_t
*wlc_cm
,
1183 u8 local_constraint_qdbm
)
1185 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1186 struct txpwr_limits txpwr
;
1188 wlc_channel_reg_limits(wlc_cm
, wlc
->chanspec
, &txpwr
);
1190 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm
, &txpwr
,
1191 local_constraint_qdbm
);
1193 wlc_phy_txpower_limit_set(wlc
->band
->pi
, &txpwr
, wlc
->chanspec
);
1199 static void wlc_phy_txpower_limits_dump(txpwr_limits_t
*txpwr
)
1202 char fraction
[4][4] = { " ", ".25", ".5 ", ".75" };
1205 for (i
= 0; i
< WLC_NUM_RATES_CCK
; i
++) {
1206 printf(" %2d%s", txpwr
->cck
[i
] / WLC_TXPWR_DB_FACTOR
,
1207 fraction
[txpwr
->cck
[i
] % WLC_TXPWR_DB_FACTOR
]);
1211 printf("20 MHz OFDM SISO ");
1212 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1213 printf(" %2d%s", txpwr
->ofdm
[i
] / WLC_TXPWR_DB_FACTOR
,
1214 fraction
[txpwr
->ofdm
[i
] % WLC_TXPWR_DB_FACTOR
]);
1218 printf("20 MHz OFDM CDD ");
1219 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1220 printf(" %2d%s", txpwr
->ofdm_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1221 fraction
[txpwr
->ofdm_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1225 printf("40 MHz OFDM SISO ");
1226 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1227 printf(" %2d%s", txpwr
->ofdm_40_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1228 fraction
[txpwr
->ofdm_40_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1232 printf("40 MHz OFDM CDD ");
1233 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1234 printf(" %2d%s", txpwr
->ofdm_40_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1235 fraction
[txpwr
->ofdm_40_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1239 printf("20 MHz MCS0-7 SISO ");
1240 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1241 printf(" %2d%s", txpwr
->mcs_20_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1242 fraction
[txpwr
->mcs_20_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1246 printf("20 MHz MCS0-7 CDD ");
1247 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1248 printf(" %2d%s", txpwr
->mcs_20_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1249 fraction
[txpwr
->mcs_20_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1253 printf("20 MHz MCS0-7 STBC ");
1254 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1255 printf(" %2d%s", txpwr
->mcs_20_stbc
[i
] / WLC_TXPWR_DB_FACTOR
,
1256 fraction
[txpwr
->mcs_20_stbc
[i
] % WLC_TXPWR_DB_FACTOR
]);
1260 printf("20 MHz MCS8-15 SDM ");
1261 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1262 printf(" %2d%s", txpwr
->mcs_20_mimo
[i
] / WLC_TXPWR_DB_FACTOR
,
1263 fraction
[txpwr
->mcs_20_mimo
[i
] % WLC_TXPWR_DB_FACTOR
]);
1267 printf("40 MHz MCS0-7 SISO ");
1268 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1269 printf(" %2d%s", txpwr
->mcs_40_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1270 fraction
[txpwr
->mcs_40_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1274 printf("40 MHz MCS0-7 CDD ");
1275 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1276 printf(" %2d%s", txpwr
->mcs_40_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1277 fraction
[txpwr
->mcs_40_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1281 printf("40 MHz MCS0-7 STBC ");
1282 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1283 printf(" %2d%s", txpwr
->mcs_40_stbc
[i
] / WLC_TXPWR_DB_FACTOR
,
1284 fraction
[txpwr
->mcs_40_stbc
[i
] % WLC_TXPWR_DB_FACTOR
]);
1288 printf("40 MHz MCS8-15 SDM ");
1289 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1290 printf(" %2d%s", txpwr
->mcs_40_mimo
[i
] / WLC_TXPWR_DB_FACTOR
,
1291 fraction
[txpwr
->mcs_40_mimo
[i
] % WLC_TXPWR_DB_FACTOR
]);
1295 printf("MCS32 %2d%s\n",
1296 txpwr
->mcs32
/ WLC_TXPWR_DB_FACTOR
,
1297 fraction
[txpwr
->mcs32
% WLC_TXPWR_DB_FACTOR
]);
1299 #endif /* POWER_DBG */
1302 wlc_channel_reg_limits(wlc_cm_info_t
*wlc_cm
, chanspec_t chanspec
,
1303 txpwr_limits_t
*txpwr
)
1305 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1310 const country_info_t
*country
;
1312 const locale_info_t
*li
;
1314 int conducted_ofdm_max
;
1315 const locale_mimo_info_t
*li_mimo
;
1316 int maxpwr20
, maxpwr40
;
1320 bzero(txpwr
, sizeof(txpwr_limits_t
));
1322 if (!wlc_valid_chanspec_db(wlc_cm
, chanspec
)) {
1323 country
= wlc_country_lookup(wlc
, wlc
->autocountry_default
);
1324 if (country
== NULL
)
1327 country
= wlc_cm
->country
;
1330 chan
= CHSPEC_CHANNEL(chanspec
);
1331 band
= wlc
->bandstate
[CHSPEC_WLCBANDUNIT(chanspec
)];
1332 li
= BAND_5G(band
->bandtype
) ?
1333 wlc_get_locale_5g(country
->locale_5G
) :
1334 wlc_get_locale_2g(country
->locale_2G
);
1336 li_mimo
= BAND_5G(band
->bandtype
) ?
1337 wlc_get_mimo_5g(country
->locale_mimo_5G
) :
1338 wlc_get_mimo_2g(country
->locale_mimo_2G
);
1340 if (li
->flags
& WLC_EIRP
) {
1341 delta
= band
->antgain
;
1344 if (band
->antgain
> QDB(6))
1345 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1348 if (li
== &locale_i
) {
1349 conducted_max
= QDB(22);
1350 conducted_ofdm_max
= QDB(22);
1353 /* CCK txpwr limits for 2.4G band */
1354 if (BAND_2G(band
->bandtype
)) {
1355 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_CCK(chan
)];
1357 maxpwr
= maxpwr
- delta
;
1358 maxpwr
= max(maxpwr
, 0);
1359 maxpwr
= min(maxpwr
, conducted_max
);
1361 for (i
= 0; i
< WLC_NUM_RATES_CCK
; i
++)
1362 txpwr
->cck
[i
] = (u8
) maxpwr
;
1365 /* OFDM txpwr limits for 2.4G or 5G bands */
1366 if (BAND_2G(band
->bandtype
)) {
1367 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_OFDM(chan
)];
1370 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_5G(chan
)];
1373 maxpwr
= maxpwr
- delta
;
1374 maxpwr
= max(maxpwr
, 0);
1375 maxpwr
= min(maxpwr
, conducted_ofdm_max
);
1377 /* Keep OFDM lmit below CCK limit */
1378 if (BAND_2G(band
->bandtype
))
1379 maxpwr
= min(maxpwr
, txpwr
->cck
[0]);
1381 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1382 txpwr
->ofdm
[i
] = (u8
) maxpwr
;
1385 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1386 /* OFDM 40 MHz SISO has the same power as the corresponding MCS0-7 rate unless
1387 * overriden by the locale specific code. We set this value to 0 as a
1388 * flag (presumably 0 dBm isn't a possibility) and then copy the MCS0-7 value
1389 * to the 40 MHz value if it wasn't explicitly set.
1391 txpwr
->ofdm_40_siso
[i
] = 0;
1393 txpwr
->ofdm_cdd
[i
] = (u8
) maxpwr
;
1395 txpwr
->ofdm_40_cdd
[i
] = 0;
1398 /* MIMO/HT specific limits */
1399 if (li_mimo
->flags
& WLC_EIRP
) {
1400 delta
= band
->antgain
;
1403 if (band
->antgain
> QDB(6))
1404 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1407 if (BAND_2G(band
->bandtype
))
1408 maxpwr_idx
= (chan
- 1);
1410 maxpwr_idx
= CHANNEL_POWER_IDX_5G(chan
);
1412 maxpwr20
= li_mimo
->maxpwr20
[maxpwr_idx
];
1413 maxpwr40
= li_mimo
->maxpwr40
[maxpwr_idx
];
1415 maxpwr20
= maxpwr20
- delta
;
1416 maxpwr20
= max(maxpwr20
, 0);
1417 maxpwr40
= maxpwr40
- delta
;
1418 maxpwr40
= max(maxpwr40
, 0);
1420 /* Fill in the MCS 0-7 (SISO) rates */
1421 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1423 /* 20 MHz has the same power as the corresponding OFDM rate unless
1424 * overriden by the locale specific code.
1426 txpwr
->mcs_20_siso
[i
] = txpwr
->ofdm
[i
];
1427 txpwr
->mcs_40_siso
[i
] = 0;
1430 /* Fill in the MCS 0-7 CDD rates */
1431 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1432 txpwr
->mcs_20_cdd
[i
] = (u8
) maxpwr20
;
1433 txpwr
->mcs_40_cdd
[i
] = (u8
) maxpwr40
;
1436 /* These locales have SISO expressed in the table and override CDD later */
1437 if (li_mimo
== &locale_bn
) {
1438 if (li_mimo
== &locale_bn
) {
1442 if (chan
>= 3 && chan
<= 11) {
1447 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1448 txpwr
->mcs_20_siso
[i
] = (u8
) maxpwr20
;
1449 txpwr
->mcs_40_siso
[i
] = (u8
) maxpwr40
;
1453 /* Fill in the MCS 0-7 STBC rates */
1454 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1455 txpwr
->mcs_20_stbc
[i
] = 0;
1456 txpwr
->mcs_40_stbc
[i
] = 0;
1459 /* Fill in the MCS 8-15 SDM rates */
1460 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1461 txpwr
->mcs_20_mimo
[i
] = (u8
) maxpwr20
;
1462 txpwr
->mcs_40_mimo
[i
] = (u8
) maxpwr40
;
1466 txpwr
->mcs32
= (u8
) maxpwr40
;
1468 for (i
= 0, j
= 0; i
< WLC_NUM_RATES_OFDM
; i
++, j
++) {
1469 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1470 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1473 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1474 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1478 /* Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO value if it wasn't
1479 * provided explicitly.
1482 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1483 if (txpwr
->mcs_40_siso
[i
] == 0)
1484 txpwr
->mcs_40_siso
[i
] = txpwr
->mcs_40_cdd
[i
];
1487 for (i
= 0, j
= 0; i
< WLC_NUM_RATES_OFDM
; i
++, j
++) {
1488 if (txpwr
->ofdm_40_siso
[i
] == 0)
1489 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1492 if (txpwr
->ofdm_40_siso
[i
] == 0)
1493 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1497 /* Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding STBC values if they weren't
1498 * provided explicitly.
1500 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1501 if (txpwr
->mcs_20_stbc
[i
] == 0)
1502 txpwr
->mcs_20_stbc
[i
] = txpwr
->mcs_20_cdd
[i
];
1504 if (txpwr
->mcs_40_stbc
[i
] == 0)
1505 txpwr
->mcs_40_stbc
[i
] = txpwr
->mcs_40_cdd
[i
];
1509 wlc_phy_txpower_limits_dump(txpwr
);
1514 /* Returns TRUE if currently set country is Japan or variant */
1515 bool wlc_japan(struct wlc_info
*wlc
)
1517 return wlc_japan_ccode(wlc
->cmi
->country_abbrev
);
1520 /* JP, J1 - J10 are Japan ccodes */
1521 static bool wlc_japan_ccode(const char *ccode
)
1523 return (ccode
[0] == 'J' &&
1524 (ccode
[1] == 'P' || (ccode
[1] >= '1' && ccode
[1] <= '9')));
1528 * Validate the chanspec for this locale, for 40MHZ we need to also check that the sidebands
1529 * are valid 20MZH channels in this locale and they are also a legal HT combination
1532 wlc_valid_chanspec_ext(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
, bool dualband
)
1534 wlc_info_t
*wlc
= wlc_cm
->wlc
;
1535 u8 channel
= CHSPEC_CHANNEL(chspec
);
1537 /* check the chanspec */
1538 if (wf_chspec_malformed(chspec
)) {
1539 WL_ERROR(("wl%d: malformed chanspec 0x%x\n", wlc
->pub
->unit
,
1545 if (CHANNEL_BANDUNIT(wlc_cm
->wlc
, channel
) !=
1546 CHSPEC_WLCBANDUNIT(chspec
))
1549 /* Check a 20Mhz channel */
1550 if (CHSPEC_IS20(chspec
)) {
1552 return VALID_CHANNEL20_DB(wlc_cm
->wlc
, channel
);
1554 return VALID_CHANNEL20(wlc_cm
->wlc
, channel
);
1556 #ifdef SUPPORT_40MHZ
1557 /* We know we are now checking a 40MHZ channel, so we should only be here
1560 if (WLCISNPHY(wlc
->band
) || WLCISSSLPNPHY(wlc
->band
)) {
1561 u8 upper_sideband
= 0, idx
;
1562 u8 num_ch20_entries
=
1563 sizeof(chan20_info
) / sizeof(struct chan20_info
);
1565 if (!VALID_40CHANSPEC_IN_BAND(wlc
, CHSPEC_WLCBANDUNIT(chspec
)))
1569 if (!VALID_CHANNEL20_DB(wlc
, LOWER_20_SB(channel
)) ||
1570 !VALID_CHANNEL20_DB(wlc
, UPPER_20_SB(channel
)))
1573 if (!VALID_CHANNEL20(wlc
, LOWER_20_SB(channel
)) ||
1574 !VALID_CHANNEL20(wlc
, UPPER_20_SB(channel
)))
1578 /* find the lower sideband info in the sideband array */
1579 for (idx
= 0; idx
< num_ch20_entries
; idx
++) {
1580 if (chan20_info
[idx
].sb
== LOWER_20_SB(channel
))
1581 upper_sideband
= chan20_info
[idx
].adj_sbs
;
1583 /* check that the lower sideband allows an upper sideband */
1584 if ((upper_sideband
& (CH_UPPER_SB
| CH_EWA_VALID
)) ==
1585 (CH_UPPER_SB
| CH_EWA_VALID
))
1594 bool wlc_valid_chanspec(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
)
1596 return wlc_valid_chanspec_ext(wlc_cm
, chspec
, FALSE
);
1599 bool wlc_valid_chanspec_db(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
)
1601 return wlc_valid_chanspec_ext(wlc_cm
, chspec
, TRUE
);