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/mac80211.h>
22 #include "phy/phy_hal.h"
28 #define VALID_CHANNEL20_DB(wlc, val) brcms_c_valid_channel20_db((wlc)->cmi, val)
29 #define VALID_CHANNEL20_IN_BAND(wlc, bandunit, val) \
30 brcms_c_valid_channel20_in_band((wlc)->cmi, bandunit, val)
31 #define VALID_CHANNEL20(wlc, val) brcms_c_valid_channel20((wlc)->cmi, val)
33 struct brcms_cm_band
{
34 u8 locale_flags
; /* struct locale_info flags */
35 chanvec_t valid_channels
; /* List of valid channels in the country */
36 const chanvec_t
*restricted_channels
; /* List of restricted use channels */
37 const chanvec_t
*radar_channels
; /* List of radar sensitive channels */
41 struct brcms_cm_info
{
42 struct brcms_pub
*pub
;
43 struct brcms_c_info
*wlc
;
44 char srom_ccode
[BRCM_CNTRY_BUF_SZ
]; /* Country Code in SROM */
45 uint srom_regrev
; /* Regulatory Rev for the SROM ccode */
46 const struct country_info
*country
; /* current country def */
47 char ccode
[BRCM_CNTRY_BUF_SZ
]; /* current internal Country Code */
48 uint regrev
; /* current Regulatory Revision */
49 char country_abbrev
[BRCM_CNTRY_BUF_SZ
]; /* current advertised ccode */
50 /* per-band state (one per phy/radio) */
51 struct brcms_cm_band bandstate
[MAXBANDS
];
52 /* quiet channels currently for radar sensitivity or 11h support */
53 chanvec_t quiet_channels
; /* channels on which we cannot transmit */
56 static int brcms_c_channels_init(struct brcms_cm_info
*wlc_cm
,
57 const struct country_info
*country
);
58 static void brcms_c_set_country_common(struct brcms_cm_info
*wlc_cm
,
59 const char *country_abbrev
,
60 const char *ccode
, uint regrev
,
61 const struct country_info
*country
);
62 static int brcms_c_set_countrycode(struct brcms_cm_info
*wlc_cm
,
64 static int brcms_c_set_countrycode_rev(struct brcms_cm_info
*wlc_cm
,
65 const char *country_abbrev
,
66 const char *ccode
, int regrev
);
67 static int brcms_c_country_aggregate_map(struct brcms_cm_info
*wlc_cm
,
69 char *mapped_ccode
, uint
*mapped_regrev
);
71 static const struct country_info
*
72 brcms_c_country_lookup_direct(const char *ccode
, uint regrev
);
74 static const struct country_info
*
75 brcms_c_countrycode_map(struct brcms_cm_info
*wlc_cm
,
76 const char *ccode
, char *mapped_ccode
,
79 static void brcms_c_channels_commit(struct brcms_cm_info
*wlc_cm
);
80 static void brcms_c_quiet_channels_reset(struct brcms_cm_info
*wlc_cm
);
81 static bool brcms_c_quiet_chanspec(struct brcms_cm_info
*wlc_cm
,
83 static bool brcms_c_valid_channel20_db(struct brcms_cm_info
*wlc_cm
, uint val
);
84 static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info
*wlc_cm
,
85 uint bandunit
, uint val
);
86 static bool brcms_c_valid_channel20(struct brcms_cm_info
*wlc_cm
, uint val
);
88 static const struct country_info
*
89 brcms_c_country_lookup(struct brcms_c_info
*wlc
, const char *ccode
);
91 static void brcms_c_locale_get_channels(const struct locale_info
*locale
,
92 chanvec_t
*valid_channels
);
93 static const struct locale_info
*brcms_c_get_locale_2g(u8 locale_idx
);
94 static const struct locale_info
*brcms_c_get_locale_5g(u8 locale_idx
);
95 static bool brcms_c_japan(struct brcms_c_info
*wlc
);
96 static bool brcms_c_japan_ccode(const char *ccode
);
97 static void brcms_c_channel_min_txpower_limits_with_local_constraint(
98 struct brcms_cm_info
*wlc_cm
, struct txpwr_limits
*txpwr
,
99 u8 local_constraint_qdbm
);
100 static void brcms_c_locale_add_channels(chanvec_t
*target
,
101 const chanvec_t
*channels
);
102 static const struct locale_mimo_info
*brcms_c_get_mimo_2g(u8 locale_idx
);
103 static const struct locale_mimo_info
*brcms_c_get_mimo_5g(u8 locale_idx
);
105 /* QDB() macro takes a dB value and converts to a quarter dB value */
109 #define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
111 /* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
114 * Some common channel sets
118 static const chanvec_t chanvec_none
= {
119 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 0x00, 0x00, 0x00, 0x00}
125 /* All 2.4 GHz HW channels */
126 const chanvec_t chanvec_all_2G
= {
127 {0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00}
133 /* All 5 GHz HW channels */
134 const chanvec_t chanvec_all_5G
= {
135 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x11, 0x11,
136 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11,
137 0x11, 0x11, 0x20, 0x22, 0x22, 0x00, 0x00, 0x11,
138 0x11, 0x11, 0x11, 0x01}
146 #define radar_set_none chanvec_none
148 static const chanvec_t radar_set1
= { /* Channels 52 - 64, 100 - 140 */
149 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, /* 52 - 60 */
150 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11, /* 64, 100 - 124 */
151 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128 - 140 */
152 0x00, 0x00, 0x00, 0x00}
156 * Restricted channel sets
159 #define restricted_set_none chanvec_none
161 /* Channels 34, 38, 42, 46 */
162 static const chanvec_t restricted_set_japan_legacy
= {
163 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166 0x00, 0x00, 0x00, 0x00}
169 /* Channels 12, 13 */
170 static const chanvec_t restricted_set_2g_short
= {
171 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00}
178 static const chanvec_t restricted_chan_165
= {
179 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
182 0x00, 0x00, 0x00, 0x00}
185 /* Channels 36 - 48 & 149 - 165 */
186 static const chanvec_t restricted_low_hi
= {
187 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189 0x00, 0x00, 0x20, 0x22, 0x22, 0x00, 0x00, 0x00,
190 0x00, 0x00, 0x00, 0x00}
193 /* Channels 12 - 14 */
194 static const chanvec_t restricted_set_12_13_14
= {
195 {0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00}
201 #define LOCALE_CHAN_01_11 (1<<0)
202 #define LOCALE_CHAN_12_13 (1<<1)
203 #define LOCALE_CHAN_14 (1<<2)
204 #define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
205 #define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
206 #define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
207 #define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
208 #define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
209 #define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
210 #define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
211 #define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
212 #define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
213 #define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
214 #define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
215 #define LOCALE_CHAN_52_140_ALL (1<<14)
216 #define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
218 #define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
219 #define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
220 #define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
221 #define LOCALE_CHAN_100_140 \
222 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
223 #define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
224 #define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
226 #define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13 | LOCALE_CHAN_14)
228 #define LOCALE_RADAR_SET_NONE 0
229 #define LOCALE_RADAR_SET_1 1
231 #define LOCALE_RESTRICTED_NONE 0
232 #define LOCALE_RESTRICTED_SET_2G_SHORT 1
233 #define LOCALE_RESTRICTED_CHAN_165 2
234 #define LOCALE_CHAN_ALL_5G 3
235 #define LOCALE_RESTRICTED_JAPAN_LEGACY 4
236 #define LOCALE_RESTRICTED_11D_2G 5
237 #define LOCALE_RESTRICTED_11D_5G 6
238 #define LOCALE_RESTRICTED_LOW_HI 7
239 #define LOCALE_RESTRICTED_12_13_14 8
241 /* global memory to provide working buffer for expanded locale */
243 static const chanvec_t
*g_table_radar_set
[] = {
248 static const chanvec_t
*g_table_restricted_chan
[] = {
249 &chanvec_none
, /* restricted_set_none */
250 &restricted_set_2g_short
,
251 &restricted_chan_165
,
253 &restricted_set_japan_legacy
,
254 &chanvec_all_2G
, /* restricted_set_11d_2G */
255 &chanvec_all_5G
, /* restricted_set_11d_5G */
257 &restricted_set_12_13_14
260 static const chanvec_t locale_2g_01_11
= {
261 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00}
267 static const chanvec_t locale_2g_12_13
= {
268 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00}
274 static const chanvec_t locale_2g_14
= {
275 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00}
281 static const chanvec_t locale_5g_LOW_JP1
= {
282 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00}
288 static const chanvec_t locale_5g_LOW_JP2
= {
289 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00}
295 static const chanvec_t locale_5g_LOW1
= {
296 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299 0x00, 0x00, 0x00, 0x00}
302 static const chanvec_t locale_5g_LOW2
= {
303 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00}
309 static const chanvec_t locale_5g_LOW3
= {
310 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
311 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00}
316 static const chanvec_t locale_5g_MID1
= {
317 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00}
323 static const chanvec_t locale_5g_MID2
= {
324 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00}
330 static const chanvec_t locale_5g_MID3
= {
331 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
334 0x00, 0x00, 0x00, 0x00}
337 static const chanvec_t locale_5g_HIGH1
= {
338 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00}
344 static const chanvec_t locale_5g_HIGH2
= {
345 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x00}
351 static const chanvec_t locale_5g_HIGH3
= {
352 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
355 0x00, 0x00, 0x00, 0x00}
358 static const chanvec_t locale_5g_52_140_ALL
= {
359 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
360 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
361 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00}
365 static const chanvec_t locale_5g_HIGH4
= {
366 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
369 0x11, 0x11, 0x11, 0x11}
372 static const chanvec_t
*g_table_locale_base
[] = {
387 &locale_5g_52_140_ALL
,
391 static void brcms_c_locale_add_channels(chanvec_t
*target
,
392 const chanvec_t
*channels
)
395 for (i
= 0; i
< sizeof(chanvec_t
); i
++) {
396 target
->vec
[i
] |= channels
->vec
[i
];
400 static void brcms_c_locale_get_channels(const struct locale_info
*locale
,
405 memset(channels
, 0, sizeof(chanvec_t
));
407 for (i
= 0; i
< ARRAY_SIZE(g_table_locale_base
); i
++) {
408 if (locale
->valid_channels
& (1 << i
)) {
409 brcms_c_locale_add_channels(channels
,
410 g_table_locale_base
[i
]);
416 * Locale Definitions - 2.4 GHz
418 static const struct locale_info locale_i
= { /* locale i. channel 1 - 13 */
419 LOCALE_CHAN_01_11
| LOCALE_CHAN_12_13
,
420 LOCALE_RADAR_SET_NONE
,
421 LOCALE_RESTRICTED_SET_2G_SHORT
,
422 {QDB(19), QDB(19), QDB(19),
423 QDB(19), QDB(19), QDB(19)},
429 * Locale Definitions - 5 GHz
431 static const struct locale_info locale_11
= {
432 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
433 LOCALE_CHAN_36_64
| LOCALE_CHAN_100_140
| LOCALE_CHAN_149_165
,
435 LOCALE_RESTRICTED_NONE
,
436 {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
437 {23, 23, 23, 30, 30},
438 BRCMS_EIRP
| BRCMS_DFS_EU
441 #define LOCALE_2G_IDX_i 0
442 static const struct locale_info
*g_locale_2g_table
[] = {
446 #define LOCALE_5G_IDX_11 0
447 static const struct locale_info
*g_locale_5g_table
[] = {
452 * MIMO Locale Definitions - 2.4 GHz
454 static const struct locale_mimo_info locale_bn
= {
455 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
456 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
457 QDB(13), QDB(13), QDB(13)},
458 {0, 0, QDB(13), QDB(13), QDB(13),
459 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
464 /* locale mimo 2g indexes */
465 #define LOCALE_MIMO_IDX_bn 0
467 static const struct locale_mimo_info
*g_mimo_2g_table
[] = {
472 * MIMO Locale Definitions - 5 GHz
474 static const struct locale_mimo_info locale_11n
= {
475 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
476 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
480 #define LOCALE_MIMO_IDX_11n 0
481 static const struct locale_mimo_info
*g_mimo_5g_table
[] = {
488 #define LC(id) LOCALE_MIMO_IDX_ ## id
493 #define LC_2G(id) LOCALE_2G_IDX_ ## id
498 #define LC_5G(id) LOCALE_5G_IDX_ ## id
500 #define LOCALES(band2, band5, mimo2, mimo5) {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
502 static const struct {
503 char abbrev
[BRCM_CNTRY_BUF_SZ
]; /* country abbreviation */
504 struct country_info country
;
505 } cntry_locales
[] = {
507 "X2", LOCALES(i
, 11, bn
, 11n
)}, /* Worldwide RoW 2 */
511 /* 20MHz channel info for 40MHz pairing support */
517 /* indicates adjacent channels that are allowed for a 40 Mhz channel and
518 * those that permitted by the HT
520 struct chan20_info chan20_info
[] = {
522 /* 0 */ {1, (CH_UPPER_SB
| CH_EWA_VALID
)},
523 /* 1 */ {2, (CH_UPPER_SB
| CH_EWA_VALID
)},
524 /* 2 */ {3, (CH_UPPER_SB
| CH_EWA_VALID
)},
525 /* 3 */ {4, (CH_UPPER_SB
| CH_EWA_VALID
)},
526 /* 4 */ {5, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
527 /* 5 */ {6, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
528 /* 6 */ {7, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
529 /* 7 */ {8, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
530 /* 8 */ {9, (CH_UPPER_SB
| CH_LOWER_SB
| CH_EWA_VALID
)},
531 /* 9 */ {10, (CH_LOWER_SB
| CH_EWA_VALID
)},
532 /* 10 */ {11, (CH_LOWER_SB
| CH_EWA_VALID
)},
533 /* 11 */ {12, (CH_LOWER_SB
)},
534 /* 12 */ {13, (CH_LOWER_SB
)},
535 /* 13 */ {14, (CH_LOWER_SB
)},
538 /* 14 */ {34, (CH_UPPER_SB
)},
539 /* 15 */ {38, (CH_LOWER_SB
)},
540 /* 16 */ {42, (CH_LOWER_SB
)},
541 /* 17 */ {46, (CH_LOWER_SB
)},
544 /* 18 */ {36, (CH_UPPER_SB
| CH_EWA_VALID
)},
545 /* 19 */ {40, (CH_LOWER_SB
| CH_EWA_VALID
)},
546 /* 20 */ {44, (CH_UPPER_SB
| CH_EWA_VALID
)},
547 /* 21 */ {48, (CH_LOWER_SB
| CH_EWA_VALID
)},
548 /* 22 */ {52, (CH_UPPER_SB
| CH_EWA_VALID
)},
549 /* 23 */ {56, (CH_LOWER_SB
| CH_EWA_VALID
)},
550 /* 24 */ {60, (CH_UPPER_SB
| CH_EWA_VALID
)},
551 /* 25 */ {64, (CH_LOWER_SB
| CH_EWA_VALID
)},
554 /* 26 */ {100, (CH_UPPER_SB
| CH_EWA_VALID
)},
555 /* 27 */ {104, (CH_LOWER_SB
| CH_EWA_VALID
)},
556 /* 28 */ {108, (CH_UPPER_SB
| CH_EWA_VALID
)},
557 /* 29 */ {112, (CH_LOWER_SB
| CH_EWA_VALID
)},
558 /* 30 */ {116, (CH_UPPER_SB
| CH_EWA_VALID
)},
559 /* 31 */ {120, (CH_LOWER_SB
| CH_EWA_VALID
)},
560 /* 32 */ {124, (CH_UPPER_SB
| CH_EWA_VALID
)},
561 /* 33 */ {128, (CH_LOWER_SB
| CH_EWA_VALID
)},
562 /* 34 */ {132, (CH_UPPER_SB
| CH_EWA_VALID
)},
563 /* 35 */ {136, (CH_LOWER_SB
| CH_EWA_VALID
)},
564 /* 36 */ {140, (CH_LOWER_SB
)},
566 /* 11a usa high, ref5 only */
567 /* The 0x80 bit in pdiv means these are REF5, other entries are REF20 */
568 /* 37 */ {149, (CH_UPPER_SB
| CH_EWA_VALID
)},
569 /* 38 */ {153, (CH_LOWER_SB
| CH_EWA_VALID
)},
570 /* 39 */ {157, (CH_UPPER_SB
| CH_EWA_VALID
)},
571 /* 40 */ {161, (CH_LOWER_SB
| CH_EWA_VALID
)},
572 /* 41 */ {165, (CH_LOWER_SB
)},
575 /* 42 */ {184, (CH_UPPER_SB
)},
576 /* 43 */ {188, (CH_LOWER_SB
)},
577 /* 44 */ {192, (CH_UPPER_SB
)},
578 /* 45 */ {196, (CH_LOWER_SB
)},
579 /* 46 */ {200, (CH_UPPER_SB
)},
580 /* 47 */ {204, (CH_LOWER_SB
)},
581 /* 48 */ {208, (CH_UPPER_SB
)},
582 /* 49 */ {212, (CH_LOWER_SB
)},
583 /* 50 */ {216, (CH_LOWER_SB
)}
585 #endif /* SUPPORT_40MHZ */
587 static const struct locale_info
*brcms_c_get_locale_2g(u8 locale_idx
)
589 if (locale_idx
>= ARRAY_SIZE(g_locale_2g_table
)) {
590 return NULL
; /* error condition */
592 return g_locale_2g_table
[locale_idx
];
595 static const struct locale_info
*brcms_c_get_locale_5g(u8 locale_idx
)
597 if (locale_idx
>= ARRAY_SIZE(g_locale_5g_table
)) {
598 return NULL
; /* error condition */
600 return g_locale_5g_table
[locale_idx
];
603 static const struct locale_mimo_info
*brcms_c_get_mimo_2g(u8 locale_idx
)
605 if (locale_idx
>= ARRAY_SIZE(g_mimo_2g_table
)) {
608 return g_mimo_2g_table
[locale_idx
];
611 static const struct locale_mimo_info
*brcms_c_get_mimo_5g(u8 locale_idx
)
613 if (locale_idx
>= ARRAY_SIZE(g_mimo_5g_table
)) {
616 return g_mimo_5g_table
[locale_idx
];
619 struct brcms_cm_info
*brcms_c_channel_mgr_attach(struct brcms_c_info
*wlc
)
621 struct brcms_cm_info
*wlc_cm
;
622 char country_abbrev
[BRCM_CNTRY_BUF_SZ
];
623 const struct country_info
*country
;
624 struct brcms_pub
*pub
= wlc
->pub
;
627 BCMMSG(wlc
->wiphy
, "wl%d\n", wlc
->pub
->unit
);
629 wlc_cm
= kzalloc(sizeof(struct brcms_cm_info
), GFP_ATOMIC
);
630 if (wlc_cm
== NULL
) {
631 wiphy_err(wlc
->wiphy
, "wl%d: %s: out of memory", pub
->unit
,
639 /* store the country code for passing up as a regulatory hint */
640 ccode
= getvar(wlc
->pub
->vars
, "ccode");
642 strncpy(wlc
->pub
->srom_ccode
, ccode
, BRCM_CNTRY_BUF_SZ
- 1);
645 /* internal country information which must match regulatory constraints in firmware */
646 memset(country_abbrev
, 0, BRCM_CNTRY_BUF_SZ
);
647 strncpy(country_abbrev
, "X2", sizeof(country_abbrev
) - 1);
648 country
= brcms_c_country_lookup(wlc
, country_abbrev
);
650 /* save default country for exiting 11d regulatory mode */
651 strncpy(wlc
->country_default
, country_abbrev
, BRCM_CNTRY_BUF_SZ
- 1);
653 /* initialize autocountry_default to driver default */
654 strncpy(wlc
->autocountry_default
, "X2", BRCM_CNTRY_BUF_SZ
- 1);
656 brcms_c_set_countrycode(wlc_cm
, country_abbrev
);
661 void brcms_c_channel_mgr_detach(struct brcms_cm_info
*wlc_cm
)
667 brcms_c_channel_locale_flags_in_band(struct brcms_cm_info
*wlc_cm
,
670 return wlc_cm
->bandstate
[bandunit
].locale_flags
;
673 /* set the driver's current country and regulatory information using a country code
674 * as the source. Lookup built in country information found with the country code.
677 brcms_c_set_countrycode(struct brcms_cm_info
*wlc_cm
, const char *ccode
)
679 char country_abbrev
[BRCM_CNTRY_BUF_SZ
];
680 strncpy(country_abbrev
, ccode
, BRCM_CNTRY_BUF_SZ
);
681 return brcms_c_set_countrycode_rev(wlc_cm
, country_abbrev
, ccode
, -1);
685 brcms_c_set_countrycode_rev(struct brcms_cm_info
*wlc_cm
,
686 const char *country_abbrev
,
687 const char *ccode
, int regrev
)
689 const struct country_info
*country
;
690 char mapped_ccode
[BRCM_CNTRY_BUF_SZ
];
693 /* if regrev is -1, lookup the mapped country code,
694 * otherwise use the ccode and regrev directly
697 /* map the country code to a built-in country code, regrev, and country_info */
699 brcms_c_countrycode_map(wlc_cm
, ccode
, mapped_ccode
,
702 /* find the matching built-in country definition */
703 country
= brcms_c_country_lookup_direct(ccode
, regrev
);
704 strncpy(mapped_ccode
, ccode
, BRCM_CNTRY_BUF_SZ
);
705 mapped_regrev
= regrev
;
711 /* set the driver state for the country */
712 brcms_c_set_country_common(wlc_cm
, country_abbrev
, mapped_ccode
,
713 mapped_regrev
, country
);
718 /* set the driver's current country and regulatory information using a country code
719 * as the source. Look up built in country information found with the country code.
722 brcms_c_set_country_common(struct brcms_cm_info
*wlc_cm
,
723 const char *country_abbrev
,
724 const char *ccode
, uint regrev
,
725 const struct country_info
*country
)
727 const struct locale_mimo_info
*li_mimo
;
728 const struct locale_info
*locale
;
729 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
730 char prev_country_abbrev
[BRCM_CNTRY_BUF_SZ
];
732 /* save current country state */
733 wlc_cm
->country
= country
;
735 memset(&prev_country_abbrev
, 0, BRCM_CNTRY_BUF_SZ
);
736 strncpy(prev_country_abbrev
, wlc_cm
->country_abbrev
,
737 BRCM_CNTRY_BUF_SZ
- 1);
739 strncpy(wlc_cm
->country_abbrev
, country_abbrev
, BRCM_CNTRY_BUF_SZ
- 1);
740 strncpy(wlc_cm
->ccode
, ccode
, BRCM_CNTRY_BUF_SZ
- 1);
741 wlc_cm
->regrev
= regrev
;
743 /* disable/restore nmode based on country regulations */
744 li_mimo
= brcms_c_get_mimo_2g(country
->locale_mimo_2G
);
745 if (li_mimo
&& (li_mimo
->flags
& BRCMS_NO_MIMO
)) {
746 brcms_c_set_nmode(wlc
, OFF
);
747 wlc
->stf
->no_cddstbc
= true;
749 wlc
->stf
->no_cddstbc
= false;
750 if (N_ENAB(wlc
->pub
) != wlc
->protection
->nmode_user
)
751 brcms_c_set_nmode(wlc
, wlc
->protection
->nmode_user
);
754 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
755 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
756 /* set or restore gmode as required by regulatory */
757 locale
= brcms_c_get_locale_2g(country
->locale_2G
);
758 if (locale
&& (locale
->flags
& BRCMS_NO_OFDM
)) {
759 brcms_c_set_gmode(wlc
, GMODE_LEGACY_B
, false);
761 brcms_c_set_gmode(wlc
, wlc
->protection
->gmode_user
, false);
764 brcms_c_channels_init(wlc_cm
, country
);
769 /* Lookup a country info structure from a null terminated country code
770 * The lookup is case sensitive.
772 static const struct country_info
*
773 brcms_c_country_lookup(struct brcms_c_info
*wlc
, const char *ccode
)
775 const struct country_info
*country
;
776 char mapped_ccode
[BRCM_CNTRY_BUF_SZ
];
779 /* map the country code to a built-in country code, regrev, and country_info struct */
780 country
= brcms_c_countrycode_map(wlc
->cmi
, ccode
, mapped_ccode
,
786 static const struct country_info
*
787 brcms_c_countrycode_map(struct brcms_cm_info
*wlc_cm
, const char *ccode
,
788 char *mapped_ccode
, uint
*mapped_regrev
)
790 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
791 const struct country_info
*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
) > (BRCM_CNTRY_BUF_SZ
- 1)) {
798 wiphy_err(wlc
->wiphy
, "wl%d: %s: ccode \"%s\" too long for "
799 "match\n", wlc
->pub
->unit
, __func__
, ccode
);
803 /* default mapping is the given ccode and regrev 0 */
804 strncpy(mapped_ccode
, ccode
, BRCM_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 wiphy_err(wlc
->wiphy
, "srom_code == ccode %s\n", __func__
);
817 brcms_c_country_aggregate_map(wlc_cm
, ccode
, mapped_ccode
,
821 /* find the matching built-in country definition */
822 country
= brcms_c_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
824 /* if there is not an exact rev match, default to rev zero */
825 if (country
== NULL
&& *mapped_regrev
!= 0) {
828 brcms_c_country_lookup_direct(mapped_ccode
, *mapped_regrev
);
835 brcms_c_country_aggregate_map(struct brcms_cm_info
*wlc_cm
, const char *ccode
,
836 char *mapped_ccode
, uint
*mapped_regrev
)
841 /* Lookup a country info structure from a null terminated country
842 * abbreviation and regrev directly with no translation.
844 static const struct country_info
*
845 brcms_c_country_lookup_direct(const char *ccode
, uint regrev
)
849 /* Should just return 0 for single locale driver. */
850 /* Keep it this way in case we add more locales. (for now anyway) */
852 /* all other country def arrays are for regrev == 0, so if regrev is non-zero, fail */
856 /* find matched table entry from country code */
857 size
= ARRAY_SIZE(cntry_locales
);
858 for (i
= 0; i
< size
; i
++) {
859 if (strcmp(ccode
, cntry_locales
[i
].abbrev
) == 0) {
860 return &cntry_locales
[i
].country
;
867 brcms_c_channels_init(struct brcms_cm_info
*wlc_cm
,
868 const struct country_info
*country
)
870 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
872 struct brcms_band
*band
;
873 const struct locale_info
*li
;
875 const struct locale_mimo_info
*li_mimo
;
878 for (i
= 0; i
< NBANDS(wlc
);
879 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
881 li
= BAND_5G(band
->bandtype
) ?
882 brcms_c_get_locale_5g(country
->locale_5G
) :
883 brcms_c_get_locale_2g(country
->locale_2G
);
884 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
= li
->flags
;
885 li_mimo
= BAND_5G(band
->bandtype
) ?
886 brcms_c_get_mimo_5g(country
->locale_mimo_5G
) :
887 brcms_c_get_mimo_2g(country
->locale_mimo_2G
);
889 /* merge the mimo non-mimo locale flags */
890 wlc_cm
->bandstate
[band
->bandunit
].locale_flags
|=
893 wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
=
894 g_table_restricted_chan
[li
->restricted_channels
];
895 wlc_cm
->bandstate
[band
->bandunit
].radar_channels
=
896 g_table_radar_set
[li
->radar_channels
];
898 /* set the channel availability,
899 * masking out the channels that may not be supported on this phy
901 wlc_phy_chanspec_band_validch(band
->pi
, band
->bandtype
,
903 brcms_c_locale_get_channels(li
,
904 &wlc_cm
->bandstate
[band
->bandunit
].
906 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
907 wlc_cm
->bandstate
[band
->bandunit
].valid_channels
.
908 vec
[j
] &= sup_chan
.vec
[j
];
911 brcms_c_quiet_channels_reset(wlc_cm
);
912 brcms_c_channels_commit(wlc_cm
);
917 /* Update the radio state (enable/disable) and tx power targets
918 * based on a new set of channel/regulatory information
920 static void brcms_c_channels_commit(struct brcms_cm_info
*wlc_cm
)
922 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
924 struct txpwr_limits txpwr
;
926 /* search for the existence of any valid channel */
927 for (chan
= 0; chan
< MAXCHANNEL
; chan
++) {
928 if (VALID_CHANNEL20_DB(wlc
, chan
)) {
932 if (chan
== MAXCHANNEL
)
935 /* based on the channel search above, set or clear WL_RADIO_COUNTRY_DISABLE */
936 if (chan
== INVCHANNEL
) {
937 /* country/locale with no valid channels, set the radio disable bit */
938 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
939 wiphy_err(wlc
->wiphy
, "wl%d: %s: no valid channel for \"%s\" "
940 "nbands %d bandlocked %d\n", wlc
->pub
->unit
,
941 __func__
, wlc_cm
->country_abbrev
, NBANDS(wlc
),
944 if (mboolisset(wlc
->pub
->radio_disabled
,
945 WL_RADIO_COUNTRY_DISABLE
)) {
946 /* country/locale with valid channel, clear the radio disable bit */
947 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_COUNTRY_DISABLE
);
950 /* Now that the country abbreviation is set, if the radio supports 2G, then
951 * set channel 14 restrictions based on the new locale.
953 if (NBANDS(wlc
) > 1 || BAND_2G(wlc
->band
->bandtype
)) {
954 wlc_phy_chanspec_ch14_widefilter_set(wlc
->band
->pi
,
955 brcms_c_japan(wlc
) ? true :
959 if (wlc
->pub
->up
&& chan
!= INVCHANNEL
) {
960 brcms_c_channel_reg_limits(wlc_cm
, wlc
->chanspec
, &txpwr
);
961 brcms_c_channel_min_txpower_limits_with_local_constraint(wlc_cm
,
962 &txpwr
, BRCMS_TXPWR_MAX
);
963 wlc_phy_txpower_limit_set(wlc
->band
->pi
, &txpwr
, wlc
->chanspec
);
967 /* reset the quiet channels vector to the union of the restricted and radar channel sets */
968 static void brcms_c_quiet_channels_reset(struct brcms_cm_info
*wlc_cm
)
970 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
972 struct brcms_band
*band
;
973 const chanvec_t
*chanvec
;
975 memset(&wlc_cm
->quiet_channels
, 0, sizeof(chanvec_t
));
978 for (i
= 0; i
< NBANDS(wlc
);
979 i
++, band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]) {
981 /* initialize quiet channels for restricted channels */
982 chanvec
= wlc_cm
->bandstate
[band
->bandunit
].restricted_channels
;
983 for (j
= 0; j
< sizeof(chanvec_t
); j
++)
984 wlc_cm
->quiet_channels
.vec
[j
] |= chanvec
->vec
[j
];
990 brcms_c_quiet_chanspec(struct brcms_cm_info
*wlc_cm
, chanspec_t chspec
)
992 return N_ENAB(wlc_cm
->wlc
->pub
) && CHSPEC_IS40(chspec
) ?
994 (wlc_cm
->quiet_channels
.vec
,
995 LOWER_20_SB(CHSPEC_CHANNEL(chspec
)))
996 || isset(wlc_cm
->quiet_channels
.vec
,
997 UPPER_20_SB(CHSPEC_CHANNEL(chspec
)))) : isset(wlc_cm
->
1004 /* Is the channel valid for the current locale? (but don't consider channels not
1005 * available due to bandlocking)
1007 static bool brcms_c_valid_channel20_db(struct brcms_cm_info
*wlc_cm
, uint val
)
1009 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
1011 return VALID_CHANNEL20(wlc
, val
) ||
1013 && VALID_CHANNEL20_IN_BAND(wlc
, OTHERBANDUNIT(wlc
), val
));
1016 /* Is the channel valid for the current locale and specified band? */
1017 static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info
*wlc_cm
,
1018 uint bandunit
, uint val
)
1020 return ((val
< MAXCHANNEL
)
1021 && isset(wlc_cm
->bandstate
[bandunit
].valid_channels
.vec
, val
));
1024 /* Is the channel valid for the current locale and current band? */
1025 static bool brcms_c_valid_channel20(struct brcms_cm_info
*wlc_cm
, uint val
)
1027 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
1029 return ((val
< MAXCHANNEL
) &&
1030 isset(wlc_cm
->bandstate
[wlc
->band
->bandunit
].valid_channels
.vec
,
1035 brcms_c_channel_min_txpower_limits_with_local_constraint(
1036 struct brcms_cm_info
*wlc_cm
, struct txpwr_limits
*txpwr
,
1037 u8 local_constraint_qdbm
)
1042 for (j
= 0; j
< WL_TX_POWER_CCK_NUM
; j
++) {
1043 txpwr
->cck
[j
] = min(txpwr
->cck
[j
], local_constraint_qdbm
);
1046 /* 20 MHz Legacy OFDM SISO */
1047 for (j
= 0; j
< WL_TX_POWER_OFDM_NUM
; j
++) {
1048 txpwr
->ofdm
[j
] = min(txpwr
->ofdm
[j
], local_constraint_qdbm
);
1051 /* 20 MHz Legacy OFDM CDD */
1052 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++) {
1053 txpwr
->ofdm_cdd
[j
] =
1054 min(txpwr
->ofdm_cdd
[j
], local_constraint_qdbm
);
1057 /* 40 MHz Legacy OFDM SISO */
1058 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++) {
1059 txpwr
->ofdm_40_siso
[j
] =
1060 min(txpwr
->ofdm_40_siso
[j
], local_constraint_qdbm
);
1063 /* 40 MHz Legacy OFDM CDD */
1064 for (j
= 0; j
< BRCMS_NUM_RATES_OFDM
; j
++) {
1065 txpwr
->ofdm_40_cdd
[j
] =
1066 min(txpwr
->ofdm_40_cdd
[j
], local_constraint_qdbm
);
1069 /* 20MHz MCS 0-7 SISO */
1070 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1071 txpwr
->mcs_20_siso
[j
] =
1072 min(txpwr
->mcs_20_siso
[j
], local_constraint_qdbm
);
1075 /* 20MHz MCS 0-7 CDD */
1076 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1077 txpwr
->mcs_20_cdd
[j
] =
1078 min(txpwr
->mcs_20_cdd
[j
], local_constraint_qdbm
);
1081 /* 20MHz MCS 0-7 STBC */
1082 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1083 txpwr
->mcs_20_stbc
[j
] =
1084 min(txpwr
->mcs_20_stbc
[j
], local_constraint_qdbm
);
1087 /* 20MHz MCS 8-15 MIMO */
1088 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_2_STREAM
; j
++)
1089 txpwr
->mcs_20_mimo
[j
] =
1090 min(txpwr
->mcs_20_mimo
[j
], local_constraint_qdbm
);
1092 /* 40MHz MCS 0-7 SISO */
1093 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1094 txpwr
->mcs_40_siso
[j
] =
1095 min(txpwr
->mcs_40_siso
[j
], local_constraint_qdbm
);
1098 /* 40MHz MCS 0-7 CDD */
1099 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1100 txpwr
->mcs_40_cdd
[j
] =
1101 min(txpwr
->mcs_40_cdd
[j
], local_constraint_qdbm
);
1104 /* 40MHz MCS 0-7 STBC */
1105 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_1_STREAM
; j
++) {
1106 txpwr
->mcs_40_stbc
[j
] =
1107 min(txpwr
->mcs_40_stbc
[j
], local_constraint_qdbm
);
1110 /* 40MHz MCS 8-15 MIMO */
1111 for (j
= 0; j
< BRCMS_NUM_RATES_MCS_2_STREAM
; j
++)
1112 txpwr
->mcs_40_mimo
[j
] =
1113 min(txpwr
->mcs_40_mimo
[j
], local_constraint_qdbm
);
1116 txpwr
->mcs32
= min(txpwr
->mcs32
, local_constraint_qdbm
);
1121 brcms_c_channel_set_chanspec(struct brcms_cm_info
*wlc_cm
, chanspec_t chanspec
,
1122 u8 local_constraint_qdbm
)
1124 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
1125 struct txpwr_limits txpwr
;
1127 brcms_c_channel_reg_limits(wlc_cm
, chanspec
, &txpwr
);
1129 brcms_c_channel_min_txpower_limits_with_local_constraint(wlc_cm
, &txpwr
,
1130 local_constraint_qdbm
);
1132 brcms_b_set_chanspec(wlc
->hw
, chanspec
,
1133 (brcms_c_quiet_chanspec(wlc_cm
, chanspec
) != 0),
1138 static void wlc_phy_txpower_limits_dump(struct txpwr_limits
*txpwr
)
1142 char fraction
[4][4] = { " ", ".25", ".5 ", ".75" };
1144 sprintf(buf
, "CCK ");
1145 for (i
= 0; i
< BRCMS_NUM_RATES_CCK
; i
++) {
1146 sprintf(buf
[strlen(buf
)], " %2d%s",
1147 txpwr
->cck
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1148 fraction
[txpwr
->cck
[i
] % BRCMS_TXPWR_DB_FACTOR
]);
1150 printk(KERN_DEBUG
"%s\n", buf
);
1152 sprintf(buf
, "20 MHz OFDM SISO ");
1153 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
1154 sprintf(buf
[strlen(buf
)], " %2d%s",
1155 txpwr
->ofdm
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1156 fraction
[txpwr
->ofdm
[i
] % BRCMS_TXPWR_DB_FACTOR
]);
1158 printk(KERN_DEBUG
"%s\n", buf
);
1160 sprintf(buf
, "20 MHz OFDM CDD ");
1161 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
1162 sprintf(buf
[strlen(buf
)], " %2d%s",
1163 txpwr
->ofdm_cdd
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1164 fraction
[txpwr
->ofdm_cdd
[i
] % BRCMS_TXPWR_DB_FACTOR
]);
1166 printk(KERN_DEBUG
"%s\n", buf
);
1168 sprintf(buf
, "40 MHz OFDM SISO ");
1169 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
1170 sprintf(buf
[strlen(buf
)], " %2d%s",
1171 txpwr
->ofdm_40_siso
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1172 fraction
[txpwr
->ofdm_40_siso
[i
] %
1173 BRCMS_TXPWR_DB_FACTOR
]);
1175 printk(KERN_DEBUG
"%s\n", buf
);
1177 sprintf(buf
, "40 MHz OFDM CDD ");
1178 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
1179 sprintf(buf
[strlen(buf
)], " %2d%s",
1180 txpwr
->ofdm_40_cdd
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1181 fraction
[txpwr
->ofdm_40_cdd
[i
] %
1182 BRCMS_TXPWR_DB_FACTOR
]);
1184 printk(KERN_DEBUG
"%s\n", buf
);
1186 sprintf(buf
, "20 MHz MCS0-7 SISO ");
1187 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1188 sprintf(buf
[strlen(buf
)], " %2d%s",
1189 txpwr
->mcs_20_siso
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1190 fraction
[txpwr
->mcs_20_siso
[i
] %
1191 BRCMS_TXPWR_DB_FACTOR
]);
1193 printk(KERN_DEBUG
"%s\n", buf
);
1195 sprintf(buf
, "20 MHz MCS0-7 CDD ");
1196 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1197 sprintf(buf
[strlen(buf
)], " %2d%s",
1198 txpwr
->mcs_20_cdd
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1199 fraction
[txpwr
->mcs_20_cdd
[i
] %
1200 BRCMS_TXPWR_DB_FACTOR
]);
1202 printk(KERN_DEBUG
"%s\n", buf
);
1204 sprintf(buf
, "20 MHz MCS0-7 STBC ");
1205 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1206 sprintf(buf
[strlen(buf
)], " %2d%s",
1207 txpwr
->mcs_20_stbc
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1208 fraction
[txpwr
->mcs_20_stbc
[i
] %
1209 BRCMS_TXPWR_DB_FACTOR
]);
1211 printk(KERN_DEBUG
"%s\n", buf
);
1213 sprintf(buf
, "20 MHz MCS8-15 SDM ");
1214 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_2_STREAM
; i
++) {
1215 sprintf(buf
[strlen(buf
)], " %2d%s",
1216 txpwr
->mcs_20_mimo
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1217 fraction
[txpwr
->mcs_20_mimo
[i
] %
1218 BRCMS_TXPWR_DB_FACTOR
]);
1220 printk(KERN_DEBUG
"%s\n", buf
);
1222 sprintf(buf
, "40 MHz MCS0-7 SISO ");
1223 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1224 sprintf(buf
[strlen(buf
)], " %2d%s",
1225 txpwr
->mcs_40_siso
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1226 fraction
[txpwr
->mcs_40_siso
[i
] %
1227 BRCMS_TXPWR_DB_FACTOR
]);
1229 printk(KERN_DEBUG
"%s\n", buf
);
1231 sprintf(buf
, "40 MHz MCS0-7 CDD ");
1232 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1233 sprintf(buf
[strlen(buf
)], " %2d%s",
1234 txpwr
->mcs_40_cdd
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1235 fraction
[txpwr
->mcs_40_cdd
[i
] %
1236 BRCMS_TXPWR_DB_FACTOR
]);
1238 printk(KERN_DEBUG
"%s\n", buf
);
1240 sprintf(buf
, "40 MHz MCS0-7 STBC ");
1241 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1242 sprintf(buf
[strlen(buf
)], " %2d%s",
1243 txpwr
->mcs_40_stbc
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1244 fraction
[txpwr
->mcs_40_stbc
[i
] %
1245 BRCMS_TXPWR_DB_FACTOR
]);
1247 printk(KERN_DEBUG
"%s\n", buf
);
1249 sprintf(buf
, "40 MHz MCS8-15 SDM ");
1250 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_2_STREAM
; i
++) {
1251 sprintf(buf
[strlen(buf
)], " %2d%s",
1252 txpwr
->mcs_40_mimo
[i
] / BRCMS_TXPWR_DB_FACTOR
,
1253 fraction
[txpwr
->mcs_40_mimo
[i
] %
1254 BRCMS_TXPWR_DB_FACTOR
]);
1256 printk(KERN_DEBUG
"%s\n", buf
);
1258 printk(KERN_DEBUG
"MCS32 %2d%s\n",
1259 txpwr
->mcs32
/ BRCMS_TXPWR_DB_FACTOR
,
1260 fraction
[txpwr
->mcs32
% BRCMS_TXPWR_DB_FACTOR
]);
1262 #endif /* POWER_DBG */
1265 brcms_c_channel_reg_limits(struct brcms_cm_info
*wlc_cm
, chanspec_t chanspec
,
1266 struct txpwr_limits
*txpwr
)
1268 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
1273 const struct country_info
*country
;
1274 struct brcms_band
*band
;
1275 const struct locale_info
*li
;
1277 int conducted_ofdm_max
;
1278 const struct locale_mimo_info
*li_mimo
;
1279 int maxpwr20
, maxpwr40
;
1283 memset(txpwr
, 0, sizeof(struct txpwr_limits
));
1285 if (!brcms_c_valid_chanspec_db(wlc_cm
, chanspec
)) {
1286 country
= brcms_c_country_lookup(wlc
, wlc
->autocountry_default
);
1287 if (country
== NULL
)
1290 country
= wlc_cm
->country
;
1293 chan
= CHSPEC_CHANNEL(chanspec
);
1294 band
= wlc
->bandstate
[CHSPEC_BANDUNIT(chanspec
)];
1295 li
= BAND_5G(band
->bandtype
) ?
1296 brcms_c_get_locale_5g(country
->locale_5G
) :
1297 brcms_c_get_locale_2g(country
->locale_2G
);
1299 li_mimo
= BAND_5G(band
->bandtype
) ?
1300 brcms_c_get_mimo_5g(country
->locale_mimo_5G
) :
1301 brcms_c_get_mimo_2g(country
->locale_mimo_2G
);
1303 if (li
->flags
& BRCMS_EIRP
) {
1304 delta
= band
->antgain
;
1307 if (band
->antgain
> QDB(6))
1308 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1311 if (li
== &locale_i
) {
1312 conducted_max
= QDB(22);
1313 conducted_ofdm_max
= QDB(22);
1316 /* CCK txpwr limits for 2.4G band */
1317 if (BAND_2G(band
->bandtype
)) {
1318 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_CCK(chan
)];
1320 maxpwr
= maxpwr
- delta
;
1321 maxpwr
= max(maxpwr
, 0);
1322 maxpwr
= min(maxpwr
, conducted_max
);
1324 for (i
= 0; i
< BRCMS_NUM_RATES_CCK
; i
++)
1325 txpwr
->cck
[i
] = (u8
) maxpwr
;
1328 /* OFDM txpwr limits for 2.4G or 5G bands */
1329 if (BAND_2G(band
->bandtype
)) {
1330 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_2G_OFDM(chan
)];
1333 maxpwr
= li
->maxpwr
[CHANNEL_POWER_IDX_5G(chan
)];
1336 maxpwr
= maxpwr
- delta
;
1337 maxpwr
= max(maxpwr
, 0);
1338 maxpwr
= min(maxpwr
, conducted_ofdm_max
);
1340 /* Keep OFDM lmit below CCK limit */
1341 if (BAND_2G(band
->bandtype
))
1342 maxpwr
= min_t(int, maxpwr
, txpwr
->cck
[0]);
1344 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++)
1345 txpwr
->ofdm
[i
] = (u8
) maxpwr
;
1347 for (i
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++) {
1348 /* OFDM 40 MHz SISO has the same power as the corresponding MCS0-7 rate unless
1349 * overriden by the locale specific code. We set this value to 0 as a
1350 * flag (presumably 0 dBm isn't a possibility) and then copy the MCS0-7 value
1351 * to the 40 MHz value if it wasn't explicitly set.
1353 txpwr
->ofdm_40_siso
[i
] = 0;
1355 txpwr
->ofdm_cdd
[i
] = (u8
) maxpwr
;
1357 txpwr
->ofdm_40_cdd
[i
] = 0;
1360 /* MIMO/HT specific limits */
1361 if (li_mimo
->flags
& BRCMS_EIRP
) {
1362 delta
= band
->antgain
;
1365 if (band
->antgain
> QDB(6))
1366 delta
= band
->antgain
- QDB(6); /* Excess over 6 dB */
1369 if (BAND_2G(band
->bandtype
))
1370 maxpwr_idx
= (chan
- 1);
1372 maxpwr_idx
= CHANNEL_POWER_IDX_5G(chan
);
1374 maxpwr20
= li_mimo
->maxpwr20
[maxpwr_idx
];
1375 maxpwr40
= li_mimo
->maxpwr40
[maxpwr_idx
];
1377 maxpwr20
= maxpwr20
- delta
;
1378 maxpwr20
= max(maxpwr20
, 0);
1379 maxpwr40
= maxpwr40
- delta
;
1380 maxpwr40
= max(maxpwr40
, 0);
1382 /* Fill in the MCS 0-7 (SISO) rates */
1383 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1385 /* 20 MHz has the same power as the corresponding OFDM rate unless
1386 * overriden by the locale specific code.
1388 txpwr
->mcs_20_siso
[i
] = txpwr
->ofdm
[i
];
1389 txpwr
->mcs_40_siso
[i
] = 0;
1392 /* Fill in the MCS 0-7 CDD rates */
1393 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1394 txpwr
->mcs_20_cdd
[i
] = (u8
) maxpwr20
;
1395 txpwr
->mcs_40_cdd
[i
] = (u8
) maxpwr40
;
1398 /* These locales have SISO expressed in the table and override CDD later */
1399 if (li_mimo
== &locale_bn
) {
1400 if (li_mimo
== &locale_bn
) {
1404 if (chan
>= 3 && chan
<= 11) {
1409 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1410 txpwr
->mcs_20_siso
[i
] = (u8
) maxpwr20
;
1411 txpwr
->mcs_40_siso
[i
] = (u8
) maxpwr40
;
1415 /* Fill in the MCS 0-7 STBC rates */
1416 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1417 txpwr
->mcs_20_stbc
[i
] = 0;
1418 txpwr
->mcs_40_stbc
[i
] = 0;
1421 /* Fill in the MCS 8-15 SDM rates */
1422 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_2_STREAM
; i
++) {
1423 txpwr
->mcs_20_mimo
[i
] = (u8
) maxpwr20
;
1424 txpwr
->mcs_40_mimo
[i
] = (u8
) maxpwr40
;
1428 txpwr
->mcs32
= (u8
) maxpwr40
;
1430 for (i
= 0, j
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++, j
++) {
1431 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1432 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1435 if (txpwr
->ofdm_40_cdd
[i
] == 0)
1436 txpwr
->ofdm_40_cdd
[i
] = txpwr
->mcs_40_cdd
[j
];
1440 /* Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO value if it wasn't
1441 * provided explicitly.
1444 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1445 if (txpwr
->mcs_40_siso
[i
] == 0)
1446 txpwr
->mcs_40_siso
[i
] = txpwr
->mcs_40_cdd
[i
];
1449 for (i
= 0, j
= 0; i
< BRCMS_NUM_RATES_OFDM
; i
++, j
++) {
1450 if (txpwr
->ofdm_40_siso
[i
] == 0)
1451 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1454 if (txpwr
->ofdm_40_siso
[i
] == 0)
1455 txpwr
->ofdm_40_siso
[i
] = txpwr
->mcs_40_siso
[j
];
1459 /* Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding STBC values if they weren't
1460 * provided explicitly.
1462 for (i
= 0; i
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++) {
1463 if (txpwr
->mcs_20_stbc
[i
] == 0)
1464 txpwr
->mcs_20_stbc
[i
] = txpwr
->mcs_20_cdd
[i
];
1466 if (txpwr
->mcs_40_stbc
[i
] == 0)
1467 txpwr
->mcs_40_stbc
[i
] = txpwr
->mcs_40_cdd
[i
];
1471 wlc_phy_txpower_limits_dump(txpwr
);
1476 /* Returns true if currently set country is Japan or variant */
1477 static bool brcms_c_japan(struct brcms_c_info
*wlc
)
1479 return brcms_c_japan_ccode(wlc
->cmi
->country_abbrev
);
1482 /* JP, J1 - J10 are Japan ccodes */
1483 static bool brcms_c_japan_ccode(const char *ccode
)
1485 return (ccode
[0] == 'J' &&
1486 (ccode
[1] == 'P' || (ccode
[1] >= '1' && ccode
[1] <= '9')));
1490 * Validate the chanspec for this locale, for 40MHZ we need to also check that the sidebands
1491 * are valid 20MZH channels in this locale and they are also a legal HT combination
1494 brcms_c_valid_chanspec_ext(struct brcms_cm_info
*wlc_cm
, chanspec_t chspec
,
1497 struct brcms_c_info
*wlc
= wlc_cm
->wlc
;
1498 u8 channel
= CHSPEC_CHANNEL(chspec
);
1500 /* check the chanspec */
1501 if (brcmu_chspec_malformed(chspec
)) {
1502 wiphy_err(wlc
->wiphy
, "wl%d: malformed chanspec 0x%x\n",
1503 wlc
->pub
->unit
, chspec
);
1507 if (CHANNEL_BANDUNIT(wlc_cm
->wlc
, channel
) !=
1508 CHSPEC_BANDUNIT(chspec
))
1511 /* Check a 20Mhz channel */
1512 if (CHSPEC_IS20(chspec
)) {
1514 return VALID_CHANNEL20_DB(wlc_cm
->wlc
, channel
);
1516 return VALID_CHANNEL20(wlc_cm
->wlc
, channel
);
1518 #ifdef SUPPORT_40MHZ
1519 /* We know we are now checking a 40MHZ channel, so we should only be here
1522 if (BRCMS_ISNPHY(wlc
->band
) || BRCMS_ISSSLPNPHY(wlc
->band
)) {
1523 u8 upper_sideband
= 0, idx
;
1524 u8 num_ch20_entries
=
1525 sizeof(chan20_info
) / sizeof(struct chan20_info
);
1527 if (!VALID_40CHANSPEC_IN_BAND(wlc
, CHSPEC_BANDUNIT(chspec
)))
1531 if (!VALID_CHANNEL20_DB(wlc
, LOWER_20_SB(channel
)) ||
1532 !VALID_CHANNEL20_DB(wlc
, UPPER_20_SB(channel
)))
1535 if (!VALID_CHANNEL20(wlc
, LOWER_20_SB(channel
)) ||
1536 !VALID_CHANNEL20(wlc
, UPPER_20_SB(channel
)))
1540 /* find the lower sideband info in the sideband array */
1541 for (idx
= 0; idx
< num_ch20_entries
; idx
++) {
1542 if (chan20_info
[idx
].sb
== LOWER_20_SB(channel
))
1543 upper_sideband
= chan20_info
[idx
].adj_sbs
;
1545 /* check that the lower sideband allows an upper sideband */
1546 if ((upper_sideband
& (CH_UPPER_SB
| CH_EWA_VALID
)) ==
1547 (CH_UPPER_SB
| CH_EWA_VALID
))
1556 bool brcms_c_valid_chanspec_db(struct brcms_cm_info
*wlc_cm
, chanspec_t chspec
)
1558 return brcms_c_valid_chanspec_ext(wlc_cm
, chspec
, true);