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/kernel.h>
18 #include <linux/string.h>
22 #include <linux/module.h>
23 #include <linux/pci.h>
31 #include <wlc_event.h>
32 #include <wlc_mac80211.h>
35 #include <wlc_channel.h>
38 typedef struct wlc_cm_band
{
39 u8 locale_flags
; /* locale_info_t flags */
40 chanvec_t valid_channels
; /* List of valid channels in the country */
41 const chanvec_t
*restricted_channels
; /* List of restricted use channels */
42 const chanvec_t
*radar_channels
; /* List of radar sensitive channels */
49 char srom_ccode
[WLC_CNTRY_BUF_SZ
]; /* Country Code in SROM */
50 uint srom_regrev
; /* Regulatory Rev for the SROM ccode */
51 const country_info_t
*country
; /* current country def */
52 char ccode
[WLC_CNTRY_BUF_SZ
]; /* current internal Country Code */
53 uint regrev
; /* current Regulatory Revision */
54 char country_abbrev
[WLC_CNTRY_BUF_SZ
]; /* current advertised ccode */
55 wlc_cm_band_t bandstate
[MAXBANDS
]; /* per-band state (one per phy/radio) */
56 /* quiet channels currently for radar sensitivity or 11h support */
57 chanvec_t quiet_channels
; /* channels on which we cannot transmit */
60 static int wlc_channels_init(wlc_cm_info_t
*wlc_cm
,
61 const country_info_t
*country
);
62 static void wlc_set_country_common(wlc_cm_info_t
*wlc_cm
,
63 const char *country_abbrev
,
64 const char *ccode
, uint regrev
,
65 const country_info_t
*country
);
66 static int wlc_country_aggregate_map(wlc_cm_info_t
*wlc_cm
, const char *ccode
,
67 char *mapped_ccode
, uint
*mapped_regrev
);
68 static const country_info_t
*wlc_country_lookup_direct(const char *ccode
,
70 static const country_info_t
*wlc_countrycode_map(wlc_cm_info_t
*wlc_cm
,
74 static void wlc_channels_commit(wlc_cm_info_t
*wlc_cm
);
75 static bool wlc_japan_ccode(const char *ccode
);
76 static void wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t
*
82 local_constraint_qdbm
);
83 void wlc_locale_add_channels(chanvec_t
*target
, const chanvec_t
*channels
);
84 static const locale_mimo_info_t
*wlc_get_mimo_2g(u8 locale_idx
);
85 static const locale_mimo_info_t
*wlc_get_mimo_5g(u8 locale_idx
);
87 /* QDB() macro takes a dB value and converts to a quarter dB value */
91 #define QDB(n) ((n) * WLC_TXPWR_DB_FACTOR)
93 /* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
96 * Some common channel sets
100 static const chanvec_t chanvec_none
= {
101 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0x00, 0x00}
107 /* All 2.4 GHz HW channels */
108 const chanvec_t chanvec_all_2G
= {
109 {0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00}
115 /* All 5 GHz HW channels */
116 const chanvec_t chanvec_all_5G
= {
117 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x11, 0x11,
118 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11,
119 0x11, 0x11, 0x20, 0x22, 0x22, 0x00, 0x00, 0x11,
120 0x11, 0x11, 0x11, 0x01}
128 #define radar_set_none chanvec_none
130 static const chanvec_t radar_set1
= { /* Channels 52 - 64, 100 - 140 */
131 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, /* 52 - 60 */
132 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11, /* 64, 100 - 124 */
133 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128 - 140 */
134 0x00, 0x00, 0x00, 0x00}
138 * Restricted channel sets
141 #define restricted_set_none chanvec_none
143 /* Channels 34, 38, 42, 46 */
144 static const chanvec_t restricted_set_japan_legacy
= {
145 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x00, 0x00, 0x00}
151 /* Channels 12, 13 */
152 static const chanvec_t restricted_set_2g_short
= {
153 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156 0x00, 0x00, 0x00, 0x00}
160 static const chanvec_t restricted_chan_165
= {
161 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00}
167 /* Channels 36 - 48 & 149 - 165 */
168 static const chanvec_t restricted_low_hi
= {
169 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x20, 0x22, 0x22, 0x00, 0x00, 0x00,
172 0x00, 0x00, 0x00, 0x00}
175 /* Channels 12 - 14 */
176 static const chanvec_t restricted_set_12_13_14
= {
177 {0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00}
183 #define LOCALE_CHAN_01_11 (1<<0)
184 #define LOCALE_CHAN_12_13 (1<<1)
185 #define LOCALE_CHAN_14 (1<<2)
186 #define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
187 #define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
188 #define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
189 #define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
190 #define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
191 #define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
192 #define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
193 #define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
194 #define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
195 #define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
196 #define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
197 #define LOCALE_CHAN_52_140_ALL (1<<14)
198 #define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
200 #define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
201 #define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
202 #define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
203 #define LOCALE_CHAN_100_140 \
204 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
205 #define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
206 #define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
208 #define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13 | LOCALE_CHAN_14)
210 #define LOCALE_RADAR_SET_NONE 0
211 #define LOCALE_RADAR_SET_1 1
213 #define LOCALE_RESTRICTED_NONE 0
214 #define LOCALE_RESTRICTED_SET_2G_SHORT 1
215 #define LOCALE_RESTRICTED_CHAN_165 2
216 #define LOCALE_CHAN_ALL_5G 3
217 #define LOCALE_RESTRICTED_JAPAN_LEGACY 4
218 #define LOCALE_RESTRICTED_11D_2G 5
219 #define LOCALE_RESTRICTED_11D_5G 6
220 #define LOCALE_RESTRICTED_LOW_HI 7
221 #define LOCALE_RESTRICTED_12_13_14 8
223 /* global memory to provide working buffer for expanded locale */
225 static const chanvec_t
*g_table_radar_set
[] = {
230 static const chanvec_t
*g_table_restricted_chan
[] = {
231 &chanvec_none
, /* restricted_set_none */
232 &restricted_set_2g_short
,
233 &restricted_chan_165
,
235 &restricted_set_japan_legacy
,
236 &chanvec_all_2G
, /* restricted_set_11d_2G */
237 &chanvec_all_5G
, /* restricted_set_11d_5G */
239 &restricted_set_12_13_14
242 static const chanvec_t locale_2g_01_11
= {
243 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00}
249 static const chanvec_t locale_2g_12_13
= {
250 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00}
256 static const chanvec_t locale_2g_14
= {
257 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00}
263 static const chanvec_t locale_5g_LOW_JP1
= {
264 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00}
270 static const chanvec_t locale_5g_LOW_JP2
= {
271 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00}
277 static const chanvec_t locale_5g_LOW1
= {
278 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00}
284 static const chanvec_t locale_5g_LOW2
= {
285 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00}
291 static const chanvec_t locale_5g_LOW3
= {
292 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
293 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 0x00, 0x00, 0x00, 0x00}
298 static const chanvec_t locale_5g_MID1
= {
299 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 0x00, 0x00, 0x00, 0x00}
305 static const chanvec_t locale_5g_MID2
= {
306 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x00}
312 static const chanvec_t locale_5g_MID3
= {
313 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00}
319 static const chanvec_t locale_5g_HIGH1
= {
320 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00}
326 static const chanvec_t locale_5g_HIGH2
= {
327 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
330 0x00, 0x00, 0x00, 0x00}
333 static const chanvec_t locale_5g_HIGH3
= {
334 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
337 0x00, 0x00, 0x00, 0x00}
340 static const chanvec_t locale_5g_52_140_ALL
= {
341 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
342 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
343 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
344 0x00, 0x00, 0x00, 0x00}
347 static const chanvec_t locale_5g_HIGH4
= {
348 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
351 0x11, 0x11, 0x11, 0x11}
354 static const chanvec_t
*g_table_locale_base
[] = {
369 &locale_5g_52_140_ALL
,
373 void wlc_locale_add_channels(chanvec_t
*target
, const chanvec_t
*channels
)
376 for (i
= 0; i
< sizeof(chanvec_t
); i
++) {
377 target
->vec
[i
] |= channels
->vec
[i
];
381 void wlc_locale_get_channels(const locale_info_t
*locale
, chanvec_t
*channels
)
385 memset(channels
, 0, sizeof(chanvec_t
));
387 for (i
= 0; i
< ARRAY_SIZE(g_table_locale_base
); i
++) {
388 if (locale
->valid_channels
& (1 << i
)) {
389 wlc_locale_add_channels(channels
,
390 g_table_locale_base
[i
]);
396 * Locale Definitions - 2.4 GHz
398 static const locale_info_t locale_i
= { /* locale i. channel 1 - 13 */
399 LOCALE_CHAN_01_11
| LOCALE_CHAN_12_13
,
400 LOCALE_RADAR_SET_NONE
,
401 LOCALE_RESTRICTED_SET_2G_SHORT
,
402 {QDB(19), QDB(19), QDB(19),
403 QDB(19), QDB(19), QDB(19)},
409 * Locale Definitions - 5 GHz
411 static const locale_info_t locale_11
= {
412 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
413 LOCALE_CHAN_36_64
| LOCALE_CHAN_100_140
| LOCALE_CHAN_149_165
,
415 LOCALE_RESTRICTED_NONE
,
416 {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
417 {23, 23, 23, 30, 30},
418 WLC_EIRP
| WLC_DFS_EU
421 #define LOCALE_2G_IDX_i 0
422 static const locale_info_t
*g_locale_2g_table
[] = {
426 #define LOCALE_5G_IDX_11 0
427 static const locale_info_t
*g_locale_5g_table
[] = {
432 * MIMO Locale Definitions - 2.4 GHz
434 static const locale_mimo_info_t locale_bn
= {
435 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
436 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
437 QDB(13), QDB(13), QDB(13)},
438 {0, 0, QDB(13), QDB(13), QDB(13),
439 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
444 /* locale mimo 2g indexes */
445 #define LOCALE_MIMO_IDX_bn 0
447 static const locale_mimo_info_t
*g_mimo_2g_table
[] = {
452 * MIMO Locale Definitions - 5 GHz
454 static const locale_mimo_info_t locale_11n
= {
455 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
456 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
460 #define LOCALE_MIMO_IDX_11n 0
461 static const locale_mimo_info_t
*g_mimo_5g_table
[] = {
468 #define LC(id) LOCALE_MIMO_IDX_ ## id
473 #define LC_2G(id) LOCALE_2G_IDX_ ## id
478 #define LC_5G(id) LOCALE_5G_IDX_ ## id
480 #define LOCALES(band2, band5, mimo2, mimo5) {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
482 static const struct {
483 char abbrev
[WLC_CNTRY_BUF_SZ
]; /* country abbreviation */
484 country_info_t country
;
485 } cntry_locales
[] = {
487 "X2", LOCALES(i
, 11, bn
, 11n
)}, /* Worldwide RoW 2 */
491 /* 20MHz channel info for 40MHz pairing support */
497 /* indicates adjacent channels that are allowed for a 40 Mhz channel and
498 * those that permitted by the HT
500 struct chan20_info chan20_info
[] = {
502 /* 0 */ {1, (CH_UPPER_SB
| CH_EWA_VALID
)},
503 /* 1 */ {2, (CH_UPPER_SB
| CH_EWA_VALID
)},
504 /* 2 */ {3, (CH_UPPER_SB
| CH_EWA_VALID
)},
505 /* 3 */ {4, (CH_UPPER_SB
| CH_EWA_VALID
)},
506 /* 4 */ {5, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
507 /* 5 */ {6, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
508 /* 6 */ {7, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
509 /* 7 */ {8, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
510 /* 8 */ {9, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
511 /* 9 */ {10, (CH_LOWER_SB
| CH_EWA_VALID
)},
512 /* 10 */ {11, (CH_LOWER_SB
| CH_EWA_VALID
)},
513 /* 11 */ {12, (CH_LOWER_SB
)},
514 /* 12 */ {13, (CH_LOWER_SB
)},
515 /* 13 */ {14, (CH_LOWER_SB
)},
518 /* 14 */ {34, (CH_UPPER_SB
)},
519 /* 15 */ {38, (CH_LOWER_SB
)},
520 /* 16 */ {42, (CH_LOWER_SB
)},
521 /* 17 */ {46, (CH_LOWER_SB
)},
524 /* 18 */ {36, (CH_UPPER_SB
| CH_EWA_VALID
)},
525 /* 19 */ {40, (CH_LOWER_SB
| CH_EWA_VALID
)},
526 /* 20 */ {44, (CH_UPPER_SB
| CH_EWA_VALID
)},
527 /* 21 */ {48, (CH_LOWER_SB
| CH_EWA_VALID
)},
528 /* 22 */ {52, (CH_UPPER_SB
| CH_EWA_VALID
)},
529 /* 23 */ {56, (CH_LOWER_SB
| CH_EWA_VALID
)},
530 /* 24 */ {60, (CH_UPPER_SB
| CH_EWA_VALID
)},
531 /* 25 */ {64, (CH_LOWER_SB
| CH_EWA_VALID
)},
534 /* 26 */ {100, (CH_UPPER_SB
| CH_EWA_VALID
)},
535 /* 27 */ {104, (CH_LOWER_SB
| CH_EWA_VALID
)},
536 /* 28 */ {108, (CH_UPPER_SB
| CH_EWA_VALID
)},
537 /* 29 */ {112, (CH_LOWER_SB
| CH_EWA_VALID
)},
538 /* 30 */ {116, (CH_UPPER_SB
| CH_EWA_VALID
)},
539 /* 31 */ {120, (CH_LOWER_SB
| CH_EWA_VALID
)},
540 /* 32 */ {124, (CH_UPPER_SB
| CH_EWA_VALID
)},
541 /* 33 */ {128, (CH_LOWER_SB
| CH_EWA_VALID
)},
542 /* 34 */ {132, (CH_UPPER_SB
| CH_EWA_VALID
)},
543 /* 35 */ {136, (CH_LOWER_SB
| CH_EWA_VALID
)},
544 /* 36 */ {140, (CH_LOWER_SB
)},
546 /* 11a usa high, ref5 only */
547 /* The 0x80 bit in pdiv means these are REF5, other entries are REF20 */
548 /* 37 */ {149, (CH_UPPER_SB
| CH_EWA_VALID
)},
549 /* 38 */ {153, (CH_LOWER_SB
| CH_EWA_VALID
)},
550 /* 39 */ {157, (CH_UPPER_SB
| CH_EWA_VALID
)},
551 /* 40 */ {161, (CH_LOWER_SB
| CH_EWA_VALID
)},
552 /* 41 */ {165, (CH_LOWER_SB
)},
555 /* 42 */ {184, (CH_UPPER_SB
)},
556 /* 43 */ {188, (CH_LOWER_SB
)},
557 /* 44 */ {192, (CH_UPPER_SB
)},
558 /* 45 */ {196, (CH_LOWER_SB
)},
559 /* 46 */ {200, (CH_UPPER_SB
)},
560 /* 47 */ {204, (CH_LOWER_SB
)},
561 /* 48 */ {208, (CH_UPPER_SB
)},
562 /* 49 */ {212, (CH_LOWER_SB
)},
563 /* 50 */ {216, (CH_LOWER_SB
)}
565 #endif /* SUPPORT_40MHZ */
567 const locale_info_t
*wlc_get_locale_2g(u8 locale_idx
)
569 if (locale_idx
>= ARRAY_SIZE(g_locale_2g_table
)) {
570 WL_ERROR("%s: locale 2g index size out of range %d\n",
571 __func__
, locale_idx
);
572 ASSERT(locale_idx
< ARRAY_SIZE(g_locale_2g_table
));
575 return g_locale_2g_table
[locale_idx
];
578 const locale_info_t
*wlc_get_locale_5g(u8 locale_idx
)
580 if (locale_idx
>= ARRAY_SIZE(g_locale_5g_table
)) {
581 WL_ERROR("%s: locale 5g index size out of range %d\n",
582 __func__
, locale_idx
);
583 ASSERT(locale_idx
< ARRAY_SIZE(g_locale_5g_table
));
586 return g_locale_5g_table
[locale_idx
];
589 const locale_mimo_info_t
*wlc_get_mimo_2g(u8 locale_idx
)
591 if (locale_idx
>= ARRAY_SIZE(g_mimo_2g_table
)) {
592 WL_ERROR("%s: mimo 2g index size out of range %d\n",
593 __func__
, locale_idx
);
596 return g_mimo_2g_table
[locale_idx
];
599 const locale_mimo_info_t
*wlc_get_mimo_5g(u8 locale_idx
)
601 if (locale_idx
>= ARRAY_SIZE(g_mimo_5g_table
)) {
602 WL_ERROR("%s: mimo 5g index size out of range %d\n",
603 __func__
, locale_idx
);
606 return g_mimo_5g_table
[locale_idx
];
609 wlc_cm_info_t
*wlc_channel_mgr_attach(struct wlc_info
*wlc
)
611 wlc_cm_info_t
*wlc_cm
;
612 char country_abbrev
[WLC_CNTRY_BUF_SZ
];
613 const country_info_t
*country
;
614 struct wlc_pub
*pub
= wlc
->pub
;
617 WL_TRACE("wl%d: wlc_channel_mgr_attach\n", wlc
->pub
->unit
);
619 wlc_cm
= kzalloc(sizeof(wlc_cm_info_t
), GFP_ATOMIC
);
620 if (wlc_cm
== NULL
) {
621 WL_ERROR("wl%d: %s: out of memory", pub
->unit
, __func__
);
628 /* store the country code for passing up as a regulatory hint */
629 ccode
= getvar(wlc
->pub
->vars
, "ccode");
631 strncpy(wlc
->pub
->srom_ccode
, ccode
, WLC_CNTRY_BUF_SZ
- 1);
632 WL_NONE("%s: SROM country code is %c%c\n",
634 wlc
->pub
->srom_ccode
[0], wlc
->pub
->srom_ccode
[1]);
637 /* internal country information which must match regulatory constraints in firmware */
638 memset(country_abbrev
, 0, WLC_CNTRY_BUF_SZ
);
639 strncpy(country_abbrev
, "X2", sizeof(country_abbrev
) - 1);
640 country
= wlc_country_lookup(wlc
, country_abbrev
);
642 ASSERT(country
!= NULL
);
644 /* save default country for exiting 11d regulatory mode */
645 strncpy(wlc
->country_default
, country_abbrev
, WLC_CNTRY_BUF_SZ
- 1);
647 /* initialize autocountry_default to driver default */
648 strncpy(wlc
->autocountry_default
, "X2", WLC_CNTRY_BUF_SZ
- 1);
650 wlc_set_countrycode(wlc_cm
, country_abbrev
);
655 void wlc_channel_mgr_detach(wlc_cm_info_t
*wlc_cm
)
661 u8
wlc_channel_locale_flags_in_band(wlc_cm_info_t
*wlc_cm
, uint bandunit
)
663 return wlc_cm
->bandstate
[bandunit
].locale_flags
;
666 /* set the driver's current country and regulatory information using a country code
667 * as the source. Lookup built in country information found with the country code.
669 int wlc_set_countrycode(wlc_cm_info_t
*wlc_cm
, const char *ccode
)
671 char country_abbrev
[WLC_CNTRY_BUF_SZ
];
672 strncpy(country_abbrev
, ccode
, WLC_CNTRY_BUF_SZ
);
673 return wlc_set_countrycode_rev(wlc_cm
, country_abbrev
, ccode
, -1);
677 wlc_set_countrycode_rev(wlc_cm_info_t
*wlc_cm
,
678 const char *country_abbrev
,
679 const char *ccode
, int regrev
)
681 const country_info_t
*country
;
682 char mapped_ccode
[WLC_CNTRY_BUF_SZ
];
685 WL_NONE("%s: (country_abbrev \"%s\", ccode \"%s\", regrev %d) SPROM \"%s\"/%u\n",
686 __func__
, country_abbrev
, ccode
, regrev
,
687 wlc_cm
->srom_ccode
, wlc_cm
->srom_regrev
);
689 /* if regrev is -1, lookup the mapped country code,
690 * otherwise use the ccode and regrev directly
693 /* map the country code to a built-in country code, regrev, and country_info */
695 wlc_countrycode_map(wlc_cm
, ccode
, mapped_ccode
,
698 /* find the matching built-in country definition */
700 country
= wlc_country_lookup_direct(ccode
, regrev
);
701 strncpy(mapped_ccode
, ccode
, WLC_CNTRY_BUF_SZ
);
702 mapped_regrev
= regrev
;
708 /* set the driver state for the country */
709 wlc_set_country_common(wlc_cm
, country_abbrev
, mapped_ccode
,
710 mapped_regrev
, country
);
715 /* set the driver's current country and regulatory information using a country code
716 * as the source. Look up built in country information found with the country code.
719 wlc_set_country_common(wlc_cm_info_t
*wlc_cm
,
720 const char *country_abbrev
,
721 const char *ccode
, uint regrev
,
722 const country_info_t
*country
)
724 const locale_mimo_info_t
*li_mimo
;
725 const locale_info_t
*locale
;
726 struct wlc_info
*wlc
= wlc_cm
->wlc
;
727 char prev_country_abbrev
[WLC_CNTRY_BUF_SZ
];
729 ASSERT(country
!= NULL
);
731 /* save current country state */
732 wlc_cm
->country
= country
;
734 memset(&prev_country_abbrev
, 0, WLC_CNTRY_BUF_SZ
);
735 strncpy(prev_country_abbrev
, wlc_cm
->country_abbrev
,
736 WLC_CNTRY_BUF_SZ
- 1);
738 strncpy(wlc_cm
->country_abbrev
, country_abbrev
, WLC_CNTRY_BUF_SZ
- 1);
739 strncpy(wlc_cm
->ccode
, ccode
, WLC_CNTRY_BUF_SZ
- 1);
740 wlc_cm
->regrev
= regrev
;
742 /* disable/restore nmode based on country regulations */
743 li_mimo
= wlc_get_mimo_2g(country
->locale_mimo_2G
);
744 if (li_mimo
&& (li_mimo
->flags
& WLC_NO_MIMO
)) {
745 wlc_set_nmode(wlc
, OFF
);
746 wlc
->stf
->no_cddstbc
= true;
748 wlc
->stf
->no_cddstbc
= false;
749 if (N_ENAB(wlc
->pub
) != wlc
->protection
->nmode_user
)
750 wlc_set_nmode(wlc
, wlc
->protection
->nmode_user
);
753 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
754 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
755 /* set or restore gmode as required by regulatory */
756 locale
= wlc_get_locale_2g(country
->locale_2G
);
757 if (locale
&& (locale
->flags
& WLC_NO_OFDM
)) {
758 wlc_set_gmode(wlc
, GMODE_LEGACY_B
, false);
760 wlc_set_gmode(wlc
, wlc
->protection
->gmode_user
, false);
763 wlc_channels_init(wlc_cm
, country
);
768 /* Lookup a country info structure from a null terminated country code
769 * The lookup is case sensitive.
771 const country_info_t
*wlc_country_lookup(struct wlc_info
*wlc
,
774 const country_info_t
*country
;
775 char mapped_ccode
[WLC_CNTRY_BUF_SZ
];
778 /* map the country code to a built-in country code, regrev, and country_info struct */
780 wlc_countrycode_map(wlc
->cmi
, ccode
, mapped_ccode
, &mapped_regrev
);
785 static const country_info_t
*wlc_countrycode_map(wlc_cm_info_t
*wlc_cm
,
790 struct wlc_info
*wlc
= wlc_cm
->wlc
;
791 const country_info_t
*country
;
792 uint srom_regrev
= wlc_cm
->srom_regrev
;
793 const char *srom_ccode
= wlc_cm
->srom_ccode
;
796 /* check for currently supported ccode size */
797 if (strlen(ccode
) > (WLC_CNTRY_BUF_SZ
- 1)) {
798 WL_ERROR("wl%d: %s: ccode \"%s\" too long for match\n",
799 wlc
->pub
->unit
, __func__
, ccode
);
803 /* default mapping is the given ccode and regrev 0 */
804 strncpy(mapped_ccode
, ccode
, WLC_CNTRY_BUF_SZ
);
807 /* If the desired country code matches the srom country code,
808 * then the mapped country is the srom regulatory rev.
809 * Otherwise look for an aggregate mapping.
811 if (!strcmp(srom_ccode
, ccode
)) {
812 *mapped_regrev
= srom_regrev
;
814 WL_ERROR("srom_code == ccode %s\n", __func__
);
818 wlc_country_aggregate_map(wlc_cm
, ccode
, mapped_ccode
,
822 /* find the matching built-in country definition */
823 country
= wlc_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
825 /* if there is not an exact rev match, default to rev zero */
826 if (country
== NULL
&& *mapped_regrev
!= 0) {
830 wlc_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
837 wlc_country_aggregate_map(wlc_cm_info_t
*wlc_cm
, const char *ccode
,
838 char *mapped_ccode
, uint
*mapped_regrev
)
843 /* Lookup a country info structure from a null terminated country
844 * abbreviation and regrev directly with no translation.
846 static const country_info_t
*wlc_country_lookup_direct(const char *ccode
,
851 /* Should just return 0 for single locale driver. */
852 /* Keep it this way in case we add more locales. (for now anyway) */
854 /* all other country def arrays are for regrev == 0, so if regrev is non-zero, fail */
858 /* find matched table entry from country code */
859 size
= ARRAY_SIZE(cntry_locales
);
860 for (i
= 0; i
< size
; i
++) {
861 if (strcmp(ccode
, cntry_locales
[i
].abbrev
) == 0) {
862 return &cntry_locales
[i
].country
;
866 WL_ERROR("%s: Returning NULL\n", __func__
);
872 wlc_channels_init(wlc_cm_info_t
*wlc_cm
, const country_info_t
*country
)
874 struct wlc_info
*wlc
= wlc_cm
->wlc
;
876 struct wlcband
*band
;
877 const locale_info_t
*li
;
879 const locale_mimo_info_t
*li_mimo
;
882 for (i
= 0; i
< NBANDS(wlc
);
883 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
885 li
= BAND_5G(band
->bandtype
) ?
886 wlc_get_locale_5g(country
->locale_5G
) :
887 wlc_get_locale_2g(country
->locale_2G
);
889 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
= li
->flags
;
890 li_mimo
= BAND_5G(band
->bandtype
) ?
891 wlc_get_mimo_5g(country
->locale_mimo_5G
) :
892 wlc_get_mimo_2g(country
->locale_mimo_2G
);
895 /* merge the mimo non-mimo locale flags */
896 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
|=
899 wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
=
900 g_table_restricted_chan
[li
->restricted_channels
];
901 wlc_cm
->bandstate
[band
->bandunit
].radar_channels
=
902 g_table_radar_set
[li
->radar_channels
];
904 /* set the channel availability,
905 * masking out the channels that may not be supported on this phy
907 wlc_phy_chanspec_band_validch(band
->pi
, band
->bandtype
,
909 wlc_locale_get_channels(li
,
910 &wlc_cm
->bandstate
[band
->bandunit
].
912 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
913 wlc_cm
->bandstate
[band
->bandunit
].valid_channels
.
914 vec
[j
] &= sup_chan
.vec
[j
];
917 wlc_quiet_channels_reset(wlc_cm
);
918 wlc_channels_commit(wlc_cm
);
923 /* Update the radio state (enable/disable) and tx power targets
924 * based on a new set of channel/regulatory information
926 static void wlc_channels_commit(wlc_cm_info_t
*wlc_cm
)
928 struct wlc_info
*wlc
= wlc_cm
->wlc
;
930 struct txpwr_limits txpwr
;
932 /* search for the existence of any valid channel */
933 for (chan
= 0; chan
< MAXCHANNEL
; chan
++) {
934 if (VALID_CHANNEL20_DB(wlc
, chan
)) {
938 if (chan
== MAXCHANNEL
)
941 /* based on the channel search above, set or clear WL_RADIO_COUNTRY_DISABLE */
942 if (chan
== INVCHANNEL
) {
943 /* country/locale with no valid channels, set the radio disable bit */
944 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
945 WL_ERROR("wl%d: %s: no valid channel for \"%s\" nbands %d bandlocked %d\n",
946 wlc
->pub
->unit
, __func__
,
947 wlc_cm
->country_abbrev
, NBANDS(wlc
), wlc
->bandlocked
);
949 if (mboolisset(wlc
->pub
->radio_disabled
,
950 WL_RADIO_COUNTRY_DISABLE
)) {
951 /* country/locale with valid channel, clear the radio disable bit */
952 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
955 /* Now that the country abbreviation is set, if the radio supports 2G, then
956 * set channel 14 restrictions based on the new locale.
958 if (NBANDS(wlc
) > 1 || BAND_2G(wlc
->band
->bandtype
)) {
959 wlc_phy_chanspec_ch14_widefilter_set(wlc
->band
->pi
,
960 wlc_japan(wlc
) ? true :
964 if (wlc
->pub
->up
&& chan
!= INVCHANNEL
) {
965 wlc_channel_reg_limits(wlc_cm
, wlc
->chanspec
, &txpwr
);
966 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm
,
969 wlc_phy_txpower_limit_set(wlc
->band
->pi
, &txpwr
, wlc
->chanspec
);
973 /* reset the quiet channels vector to the union of the restricted and radar channel sets */
974 void wlc_quiet_channels_reset(wlc_cm_info_t
*wlc_cm
)
976 struct wlc_info
*wlc
= wlc_cm
->wlc
;
978 struct wlcband
*band
;
979 const chanvec_t
*chanvec
;
981 memset(&wlc_cm
->quiet_channels
, 0, sizeof(chanvec_t
));
984 for (i
= 0; i
< NBANDS(wlc
);
985 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
987 /* initialize quiet channels for restricted channels */
988 chanvec
= wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
;
989 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
990 wlc_cm
->quiet_channels
.vec
[j
] |= chanvec
->vec
[j
];
995 bool wlc_quiet_chanspec(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
)
997 return N_ENAB(wlc_cm
->wlc
->pub
) && CHSPEC_IS40(chspec
) ?
999 (wlc_cm
->quiet_channels
.vec
,
1000 LOWER_20_SB(CHSPEC_CHANNEL(chspec
)))
1001 || isset(wlc_cm
->quiet_channels
.vec
,
1002 UPPER_20_SB(CHSPEC_CHANNEL(chspec
)))) : isset(wlc_cm
->
1009 /* Is the channel valid for the current locale? (but don't consider channels not
1010 * available due to bandlocking)
1012 bool wlc_valid_channel20_db(wlc_cm_info_t
*wlc_cm
, uint val
)
1014 struct wlc_info
*wlc
= wlc_cm
->wlc
;
1016 return VALID_CHANNEL20(wlc
, val
) ||
1018 && VALID_CHANNEL20_IN_BAND(wlc
, OTHERBANDUNIT(wlc
), val
));
1021 /* Is the channel valid for the current locale and specified band? */
1023 wlc_valid_channel20_in_band(wlc_cm_info_t
*wlc_cm
, uint bandunit
, uint val
)
1025 return ((val
< MAXCHANNEL
)
1026 && isset(wlc_cm
->bandstate
[bandunit
].valid_channels
.vec
, val
));
1029 /* Is the channel valid for the current locale and current band? */
1030 bool wlc_valid_channel20(wlc_cm_info_t
*wlc_cm
, uint val
)
1032 struct wlc_info
*wlc
= wlc_cm
->wlc
;
1034 return ((val
< MAXCHANNEL
) &&
1035 isset(wlc_cm
->bandstate
[wlc
->band
->bandunit
].valid_channels
.vec
,
1040 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t
*wlc_cm
,
1041 struct txpwr_limits
*txpwr
,
1043 local_constraint_qdbm
)
1048 for (j
= 0; j
< WL_TX_POWER_CCK_NUM
; j
++) {
1049 txpwr
->cck
[j
] = min(txpwr
->cck
[j
], local_constraint_qdbm
);
1052 /* 20 MHz Legacy OFDM SISO */
1053 for (j
= 0; j
< WL_TX_POWER_OFDM_NUM
; j
++) {
1054 txpwr
->ofdm
[j
] = min(txpwr
->ofdm
[j
], local_constraint_qdbm
);
1057 /* 20 MHz Legacy OFDM CDD */
1058 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1059 txpwr
->ofdm_cdd
[j
] =
1060 min(txpwr
->ofdm_cdd
[j
], local_constraint_qdbm
);
1063 /* 40 MHz Legacy OFDM SISO */
1064 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1065 txpwr
->ofdm_40_siso
[j
] =
1066 min(txpwr
->ofdm_40_siso
[j
], local_constraint_qdbm
);
1069 /* 40 MHz Legacy OFDM CDD */
1070 for (j
= 0; j
< WLC_NUM_RATES_OFDM
; j
++) {
1071 txpwr
->ofdm_40_cdd
[j
] =
1072 min(txpwr
->ofdm_40_cdd
[j
], local_constraint_qdbm
);
1075 /* 20MHz MCS 0-7 SISO */
1076 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1077 txpwr
->mcs_20_siso
[j
] =
1078 min(txpwr
->mcs_20_siso
[j
], local_constraint_qdbm
);
1081 /* 20MHz MCS 0-7 CDD */
1082 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1083 txpwr
->mcs_20_cdd
[j
] =
1084 min(txpwr
->mcs_20_cdd
[j
], local_constraint_qdbm
);
1087 /* 20MHz MCS 0-7 STBC */
1088 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1089 txpwr
->mcs_20_stbc
[j
] =
1090 min(txpwr
->mcs_20_stbc
[j
], local_constraint_qdbm
);
1093 /* 20MHz MCS 8-15 MIMO */
1094 for (j
= 0; j
< WLC_NUM_RATES_MCS_2_STREAM
; j
++)
1095 txpwr
->mcs_20_mimo
[j
] =
1096 min(txpwr
->mcs_20_mimo
[j
], local_constraint_qdbm
);
1098 /* 40MHz MCS 0-7 SISO */
1099 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1100 txpwr
->mcs_40_siso
[j
] =
1101 min(txpwr
->mcs_40_siso
[j
], local_constraint_qdbm
);
1104 /* 40MHz MCS 0-7 CDD */
1105 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1106 txpwr
->mcs_40_cdd
[j
] =
1107 min(txpwr
->mcs_40_cdd
[j
], local_constraint_qdbm
);
1110 /* 40MHz MCS 0-7 STBC */
1111 for (j
= 0; j
< WLC_NUM_RATES_MCS_1_STREAM
; j
++) {
1112 txpwr
->mcs_40_stbc
[j
] =
1113 min(txpwr
->mcs_40_stbc
[j
], local_constraint_qdbm
);
1116 /* 40MHz MCS 8-15 MIMO */
1117 for (j
= 0; j
< WLC_NUM_RATES_MCS_2_STREAM
; j
++)
1118 txpwr
->mcs_40_mimo
[j
] =
1119 min(txpwr
->mcs_40_mimo
[j
], local_constraint_qdbm
);
1122 txpwr
->mcs32
= min(txpwr
->mcs32
, local_constraint_qdbm
);
1127 wlc_channel_set_chanspec(wlc_cm_info_t
*wlc_cm
, chanspec_t chanspec
,
1128 u8 local_constraint_qdbm
)
1130 struct wlc_info
*wlc
= wlc_cm
->wlc
;
1131 struct txpwr_limits txpwr
;
1133 wlc_channel_reg_limits(wlc_cm
, chanspec
, &txpwr
);
1135 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm
, &txpwr
,
1136 local_constraint_qdbm
);
1138 wlc_bmac_set_chanspec(wlc
->hw
, chanspec
,
1139 (wlc_quiet_chanspec(wlc_cm
, chanspec
) != 0),
1144 static void wlc_phy_txpower_limits_dump(txpwr_limits_t
*txpwr
)
1147 char fraction
[4][4] = { " ", ".25", ".5 ", ".75" };
1150 for (i
= 0; i
< WLC_NUM_RATES_CCK
; i
++) {
1151 printf(" %2d%s", txpwr
->cck
[i
] / WLC_TXPWR_DB_FACTOR
,
1152 fraction
[txpwr
->cck
[i
] % WLC_TXPWR_DB_FACTOR
]);
1156 printf("20 MHz OFDM SISO ");
1157 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1158 printf(" %2d%s", txpwr
->ofdm
[i
] / WLC_TXPWR_DB_FACTOR
,
1159 fraction
[txpwr
->ofdm
[i
] % WLC_TXPWR_DB_FACTOR
]);
1163 printf("20 MHz OFDM CDD ");
1164 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1165 printf(" %2d%s", txpwr
->ofdm_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1166 fraction
[txpwr
->ofdm_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1170 printf("40 MHz OFDM SISO ");
1171 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1172 printf(" %2d%s", txpwr
->ofdm_40_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1173 fraction
[txpwr
->ofdm_40_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1177 printf("40 MHz OFDM CDD ");
1178 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1179 printf(" %2d%s", txpwr
->ofdm_40_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1180 fraction
[txpwr
->ofdm_40_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1184 printf("20 MHz MCS0-7 SISO ");
1185 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1186 printf(" %2d%s", txpwr
->mcs_20_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1187 fraction
[txpwr
->mcs_20_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1191 printf("20 MHz MCS0-7 CDD ");
1192 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1193 printf(" %2d%s", txpwr
->mcs_20_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1194 fraction
[txpwr
->mcs_20_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1198 printf("20 MHz MCS0-7 STBC ");
1199 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1200 printf(" %2d%s", txpwr
->mcs_20_stbc
[i
] / WLC_TXPWR_DB_FACTOR
,
1201 fraction
[txpwr
->mcs_20_stbc
[i
] % WLC_TXPWR_DB_FACTOR
]);
1205 printf("20 MHz MCS8-15 SDM ");
1206 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1207 printf(" %2d%s", txpwr
->mcs_20_mimo
[i
] / WLC_TXPWR_DB_FACTOR
,
1208 fraction
[txpwr
->mcs_20_mimo
[i
] % WLC_TXPWR_DB_FACTOR
]);
1212 printf("40 MHz MCS0-7 SISO ");
1213 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1214 printf(" %2d%s", txpwr
->mcs_40_siso
[i
] / WLC_TXPWR_DB_FACTOR
,
1215 fraction
[txpwr
->mcs_40_siso
[i
] % WLC_TXPWR_DB_FACTOR
]);
1219 printf("40 MHz MCS0-7 CDD ");
1220 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1221 printf(" %2d%s", txpwr
->mcs_40_cdd
[i
] / WLC_TXPWR_DB_FACTOR
,
1222 fraction
[txpwr
->mcs_40_cdd
[i
] % WLC_TXPWR_DB_FACTOR
]);
1226 printf("40 MHz MCS0-7 STBC ");
1227 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1228 printf(" %2d%s", txpwr
->mcs_40_stbc
[i
] / WLC_TXPWR_DB_FACTOR
,
1229 fraction
[txpwr
->mcs_40_stbc
[i
] % WLC_TXPWR_DB_FACTOR
]);
1233 printf("40 MHz MCS8-15 SDM ");
1234 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1235 printf(" %2d%s", txpwr
->mcs_40_mimo
[i
] / WLC_TXPWR_DB_FACTOR
,
1236 fraction
[txpwr
->mcs_40_mimo
[i
] % WLC_TXPWR_DB_FACTOR
]);
1240 printf("MCS32 %2d%s\n",
1241 txpwr
->mcs32
/ WLC_TXPWR_DB_FACTOR
,
1242 fraction
[txpwr
->mcs32
% WLC_TXPWR_DB_FACTOR
]);
1244 #endif /* POWER_DBG */
1247 wlc_channel_reg_limits(wlc_cm_info_t
*wlc_cm
, chanspec_t chanspec
,
1248 txpwr_limits_t
*txpwr
)
1250 struct wlc_info
*wlc
= wlc_cm
->wlc
;
1255 const country_info_t
*country
;
1256 struct wlcband
*band
;
1257 const locale_info_t
*li
;
1259 int conducted_ofdm_max
;
1260 const locale_mimo_info_t
*li_mimo
;
1261 int maxpwr20
, maxpwr40
;
1265 memset(txpwr
, 0, sizeof(txpwr_limits_t
));
1267 if (!wlc_valid_chanspec_db(wlc_cm
, chanspec
)) {
1268 country
= wlc_country_lookup(wlc
, wlc
->autocountry_default
);
1269 if (country
== NULL
)
1272 country
= wlc_cm
->country
;
1275 chan
= CHSPEC_CHANNEL(chanspec
);
1276 band
= wlc
->bandstate
[CHSPEC_WLCBANDUNIT(chanspec
)];
1277 li
= BAND_5G(band
->bandtype
) ?
1278 wlc_get_locale_5g(country
->locale_5G
) :
1279 wlc_get_locale_2g(country
->locale_2G
);
1281 li_mimo
= BAND_5G(band
->bandtype
) ?
1282 wlc_get_mimo_5g(country
->locale_mimo_5G
) :
1283 wlc_get_mimo_2g(country
->locale_mimo_2G
);
1285 if (li
->flags
& WLC_EIRP
) {
1286 delta
= band
->antgain
;
1289 if (band
->antgain
> QDB(6))
1290 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1293 if (li
== &locale_i
) {
1294 conducted_max
= QDB(22);
1295 conducted_ofdm_max
= QDB(22);
1298 /* CCK txpwr limits for 2.4G band */
1299 if (BAND_2G(band
->bandtype
)) {
1300 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_CCK(chan
)];
1302 maxpwr
= maxpwr
- delta
;
1303 maxpwr
= max(maxpwr
, 0);
1304 maxpwr
= min(maxpwr
, conducted_max
);
1306 for (i
= 0; i
< WLC_NUM_RATES_CCK
; i
++)
1307 txpwr
->cck
[i
] = (u8
) maxpwr
;
1310 /* OFDM txpwr limits for 2.4G or 5G bands */
1311 if (BAND_2G(band
->bandtype
)) {
1312 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_OFDM(chan
)];
1315 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_5G(chan
)];
1318 maxpwr
= maxpwr
- delta
;
1319 maxpwr
= max(maxpwr
, 0);
1320 maxpwr
= min(maxpwr
, conducted_ofdm_max
);
1322 /* Keep OFDM lmit below CCK limit */
1323 if (BAND_2G(band
->bandtype
))
1324 maxpwr
= min_t(int, maxpwr
, txpwr
->cck
[0]);
1326 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1327 txpwr
->ofdm
[i
] = (u8
) maxpwr
;
1330 for (i
= 0; i
< WLC_NUM_RATES_OFDM
; i
++) {
1331 /* OFDM 40 MHz SISO has the same power as the corresponding MCS0-7 rate unless
1332 * overriden by the locale specific code. We set this value to 0 as a
1333 * flag (presumably 0 dBm isn't a possibility) and then copy the MCS0-7 value
1334 * to the 40 MHz value if it wasn't explicitly set.
1336 txpwr
->ofdm_40_siso
[i
] = 0;
1338 txpwr
->ofdm_cdd
[i
] = (u8
) maxpwr
;
1340 txpwr
->ofdm_40_cdd
[i
] = 0;
1343 /* MIMO/HT specific limits */
1344 if (li_mimo
->flags
& WLC_EIRP
) {
1345 delta
= band
->antgain
;
1348 if (band
->antgain
> QDB(6))
1349 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1352 if (BAND_2G(band
->bandtype
))
1353 maxpwr_idx
= (chan
- 1);
1355 maxpwr_idx
= CHANNEL_POWER_IDX_5G(chan
);
1357 maxpwr20
= li_mimo
->maxpwr20
[maxpwr_idx
];
1358 maxpwr40
= li_mimo
->maxpwr40
[maxpwr_idx
];
1360 maxpwr20
= maxpwr20
- delta
;
1361 maxpwr20
= max(maxpwr20
, 0);
1362 maxpwr40
= maxpwr40
- delta
;
1363 maxpwr40
= max(maxpwr40
, 0);
1365 /* Fill in the MCS 0-7 (SISO) rates */
1366 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1368 /* 20 MHz has the same power as the corresponding OFDM rate unless
1369 * overriden by the locale specific code.
1371 txpwr
->mcs_20_siso
[i
] = txpwr
->ofdm
[i
];
1372 txpwr
->mcs_40_siso
[i
] = 0;
1375 /* Fill in the MCS 0-7 CDD rates */
1376 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1377 txpwr
->mcs_20_cdd
[i
] = (u8
) maxpwr20
;
1378 txpwr
->mcs_40_cdd
[i
] = (u8
) maxpwr40
;
1381 /* These locales have SISO expressed in the table and override CDD later */
1382 if (li_mimo
== &locale_bn
) {
1383 if (li_mimo
== &locale_bn
) {
1387 if (chan
>= 3 && chan
<= 11) {
1392 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1393 txpwr
->mcs_20_siso
[i
] = (u8
) maxpwr20
;
1394 txpwr
->mcs_40_siso
[i
] = (u8
) maxpwr40
;
1398 /* Fill in the MCS 0-7 STBC rates */
1399 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1400 txpwr
->mcs_20_stbc
[i
] = 0;
1401 txpwr
->mcs_40_stbc
[i
] = 0;
1404 /* Fill in the MCS 8-15 SDM rates */
1405 for (i
= 0; i
< WLC_NUM_RATES_MCS_2_STREAM
; i
++) {
1406 txpwr
->mcs_20_mimo
[i
] = (u8
) maxpwr20
;
1407 txpwr
->mcs_40_mimo
[i
] = (u8
) maxpwr40
;
1411 txpwr
->mcs32
= (u8
) maxpwr40
;
1413 for (i
= 0, j
= 0; i
< WLC_NUM_RATES_OFDM
; i
++, j
++) {
1414 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1415 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1418 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1419 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1423 /* Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO value if it wasn't
1424 * provided explicitly.
1427 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1428 if (txpwr
->mcs_40_siso
[i
] == 0)
1429 txpwr
->mcs_40_siso
[i
] = txpwr
->mcs_40_cdd
[i
];
1432 for (i
= 0, j
= 0; i
< WLC_NUM_RATES_OFDM
; i
++, j
++) {
1433 if (txpwr
->ofdm_40_siso
[i
] == 0)
1434 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1437 if (txpwr
->ofdm_40_siso
[i
] == 0)
1438 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1442 /* Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding STBC values if they weren't
1443 * provided explicitly.
1445 for (i
= 0; i
< WLC_NUM_RATES_MCS_1_STREAM
; i
++) {
1446 if (txpwr
->mcs_20_stbc
[i
] == 0)
1447 txpwr
->mcs_20_stbc
[i
] = txpwr
->mcs_20_cdd
[i
];
1449 if (txpwr
->mcs_40_stbc
[i
] == 0)
1450 txpwr
->mcs_40_stbc
[i
] = txpwr
->mcs_40_cdd
[i
];
1454 wlc_phy_txpower_limits_dump(txpwr
);
1459 /* Returns true if currently set country is Japan or variant */
1460 bool wlc_japan(struct wlc_info
*wlc
)
1462 return wlc_japan_ccode(wlc
->cmi
->country_abbrev
);
1465 /* JP, J1 - J10 are Japan ccodes */
1466 static bool wlc_japan_ccode(const char *ccode
)
1468 return (ccode
[0] == 'J' &&
1469 (ccode
[1] == 'P' || (ccode
[1] >= '1' && ccode
[1] <= '9')));
1473 * Validate the chanspec for this locale, for 40MHZ we need to also check that the sidebands
1474 * are valid 20MZH channels in this locale and they are also a legal HT combination
1477 wlc_valid_chanspec_ext(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
, bool dualband
)
1479 struct wlc_info
*wlc
= wlc_cm
->wlc
;
1480 u8 channel
= CHSPEC_CHANNEL(chspec
);
1482 /* check the chanspec */
1483 if (wf_chspec_malformed(chspec
)) {
1484 WL_ERROR("wl%d: malformed chanspec 0x%x\n",
1485 wlc
->pub
->unit
, chspec
);
1490 if (CHANNEL_BANDUNIT(wlc_cm
->wlc
, channel
) !=
1491 CHSPEC_WLCBANDUNIT(chspec
))
1494 /* Check a 20Mhz channel */
1495 if (CHSPEC_IS20(chspec
)) {
1497 return VALID_CHANNEL20_DB(wlc_cm
->wlc
, channel
);
1499 return VALID_CHANNEL20(wlc_cm
->wlc
, channel
);
1501 #ifdef SUPPORT_40MHZ
1502 /* We know we are now checking a 40MHZ channel, so we should only be here
1505 if (WLCISNPHY(wlc
->band
) || WLCISSSLPNPHY(wlc
->band
)) {
1506 u8 upper_sideband
= 0, idx
;
1507 u8 num_ch20_entries
=
1508 sizeof(chan20_info
) / sizeof(struct chan20_info
);
1510 if (!VALID_40CHANSPEC_IN_BAND(wlc
, CHSPEC_WLCBANDUNIT(chspec
)))
1514 if (!VALID_CHANNEL20_DB(wlc
, LOWER_20_SB(channel
)) ||
1515 !VALID_CHANNEL20_DB(wlc
, UPPER_20_SB(channel
)))
1518 if (!VALID_CHANNEL20(wlc
, LOWER_20_SB(channel
)) ||
1519 !VALID_CHANNEL20(wlc
, UPPER_20_SB(channel
)))
1523 /* find the lower sideband info in the sideband array */
1524 for (idx
= 0; idx
< num_ch20_entries
; idx
++) {
1525 if (chan20_info
[idx
].sb
== LOWER_20_SB(channel
))
1526 upper_sideband
= chan20_info
[idx
].adj_sbs
;
1528 /* check that the lower sideband allows an upper sideband */
1529 if ((upper_sideband
& (CH_UPPER_SB
| CH_EWA_VALID
)) ==
1530 (CH_UPPER_SB
| CH_EWA_VALID
))
1539 bool wlc_valid_chanspec_db(wlc_cm_info_t
*wlc_cm
, chanspec_t chspec
)
1541 return wlc_valid_chanspec_ext(wlc_cm
, chspec
, true);