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"
27 #define VALID_CHANNEL20_DB(wlc, val) brcms_c_valid_channel20_db((wlc)->cmi, val)
28 #define VALID_CHANNEL20_IN_BAND(wlc, bandunit, val) \
29 brcms_c_valid_channel20_in_band((wlc)->cmi, bandunit, val)
30 #define VALID_CHANNEL20(wlc, val) brcms_c_valid_channel20((wlc)->cmi, val)
32 struct brcms_cm_band {
33 /* struct locale_info flags */
35 /* List of valid channels in the country */
36 struct brcms_chanvec valid_channels;
37 /* List of restricted use channels */
38 const struct brcms_chanvec *restricted_channels;
39 /* List of radar sensitive channels */
40 const struct brcms_chanvec *radar_channels;
44 struct brcms_cm_info {
45 struct brcms_pub *pub;
46 struct brcms_c_info *wlc;
47 char srom_ccode[BRCM_CNTRY_BUF_SZ]; /* Country Code in SROM */
48 uint srom_regrev; /* Regulatory Rev for the SROM ccode */
49 const struct country_info *country; /* current country def */
50 char ccode[BRCM_CNTRY_BUF_SZ]; /* current internal Country Code */
51 uint regrev; /* current Regulatory Revision */
52 char country_abbrev[BRCM_CNTRY_BUF_SZ]; /* current advertised ccode */
53 /* per-band state (one per phy/radio) */
54 struct brcms_cm_band bandstate[MAXBANDS];
55 /* quiet channels currently for radar sensitivity or 11h support */
56 /* channels on which we cannot transmit */
57 struct brcms_chanvec quiet_channels;
60 static int brcms_c_channels_init(struct brcms_cm_info *wlc_cm,
61 const struct country_info *country);
62 static void brcms_c_set_country_common(struct brcms_cm_info *wlc_cm,
63 const char *country_abbrev,
64 const char *ccode, uint regrev,
65 const struct country_info *country);
66 static int brcms_c_set_countrycode(struct brcms_cm_info *wlc_cm,
68 static int brcms_c_set_countrycode_rev(struct brcms_cm_info *wlc_cm,
69 const char *country_abbrev,
70 const char *ccode, int regrev);
71 static int brcms_c_country_aggregate_map(struct brcms_cm_info *wlc_cm,
73 char *mapped_ccode, uint *mapped_regrev);
75 static const struct country_info *
76 brcms_c_country_lookup_direct(const char *ccode, uint regrev);
78 static const struct country_info *
79 brcms_c_countrycode_map(struct brcms_cm_info *wlc_cm,
80 const char *ccode, char *mapped_ccode,
83 static void brcms_c_channels_commit(struct brcms_cm_info *wlc_cm);
84 static void brcms_c_quiet_channels_reset(struct brcms_cm_info *wlc_cm);
85 static bool brcms_c_quiet_chanspec(struct brcms_cm_info *wlc_cm,
87 static bool brcms_c_valid_channel20_db(struct brcms_cm_info *wlc_cm, uint val);
88 static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info *wlc_cm,
89 uint bandunit, uint val);
90 static bool brcms_c_valid_channel20(struct brcms_cm_info *wlc_cm, uint val);
92 static const struct country_info *
93 brcms_c_country_lookup(struct brcms_c_info *wlc, const char *ccode);
95 static void brcms_c_locale_get_channels(const struct locale_info *locale,
96 struct brcms_chanvec *valid_channels);
97 static const struct locale_info *brcms_c_get_locale_2g(u8 locale_idx);
98 static const struct locale_info *brcms_c_get_locale_5g(u8 locale_idx);
99 static bool brcms_c_japan(struct brcms_c_info *wlc);
100 static bool brcms_c_japan_ccode(const char *ccode);
101 static void brcms_c_channel_min_txpower_limits_with_local_constraint(
102 struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
103 u8 local_constraint_qdbm);
104 static void brcms_c_locale_add_channels(struct brcms_chanvec *target,
105 const struct brcms_chanvec *channels);
106 static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx);
107 static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx);
109 /* QDB() macro takes a dB value and converts to a quarter dB value */
113 #define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
115 /* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
118 * Some common channel sets
122 static const struct brcms_chanvec chanvec_none = {
123 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00}
129 /* All 2.4 GHz HW channels */
130 const struct brcms_chanvec chanvec_all_2G = {
131 {0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00}
137 /* All 5 GHz HW channels */
138 const struct brcms_chanvec chanvec_all_5G = {
139 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x11, 0x11,
140 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11,
141 0x11, 0x11, 0x20, 0x22, 0x22, 0x00, 0x00, 0x11,
142 0x11, 0x11, 0x11, 0x01}
150 #define radar_set_none chanvec_none
152 /* Channels 52 - 64, 100 - 140 */
153 static const struct brcms_chanvec radar_set1 = {
154 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, /* 52 - 60 */
155 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11, /* 64, 100 - 124 */
156 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128 - 140 */
157 0x00, 0x00, 0x00, 0x00}
161 * Restricted channel sets
164 #define restricted_set_none chanvec_none
166 /* Channels 34, 38, 42, 46 */
167 static const struct brcms_chanvec restricted_set_japan_legacy = {
168 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x00, 0x00}
174 /* Channels 12, 13 */
175 static const struct brcms_chanvec restricted_set_2g_short = {
176 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 0x00, 0x00, 0x00, 0x00}
183 static const struct brcms_chanvec restricted_chan_165 = {
184 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
187 0x00, 0x00, 0x00, 0x00}
190 /* Channels 36 - 48 & 149 - 165 */
191 static const struct brcms_chanvec restricted_low_hi = {
192 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x20, 0x22, 0x22, 0x00, 0x00, 0x00,
195 0x00, 0x00, 0x00, 0x00}
198 /* Channels 12 - 14 */
199 static const struct brcms_chanvec restricted_set_12_13_14 = {
200 {0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00}
206 #define LOCALE_CHAN_01_11 (1<<0)
207 #define LOCALE_CHAN_12_13 (1<<1)
208 #define LOCALE_CHAN_14 (1<<2)
209 #define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
210 #define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
211 #define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
212 #define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
213 #define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
214 #define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
215 #define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
216 #define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
217 #define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
218 #define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
219 #define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
220 #define LOCALE_CHAN_52_140_ALL (1<<14)
221 #define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
223 #define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | \
224 LOCALE_SET_5G_LOW2 | \
226 #define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
227 #define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
228 #define LOCALE_CHAN_100_140 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | \
229 LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
230 #define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
231 #define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
233 #define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | \
234 LOCALE_CHAN_12_13 | \
237 #define LOCALE_RADAR_SET_NONE 0
238 #define LOCALE_RADAR_SET_1 1
240 #define LOCALE_RESTRICTED_NONE 0
241 #define LOCALE_RESTRICTED_SET_2G_SHORT 1
242 #define LOCALE_RESTRICTED_CHAN_165 2
243 #define LOCALE_CHAN_ALL_5G 3
244 #define LOCALE_RESTRICTED_JAPAN_LEGACY 4
245 #define LOCALE_RESTRICTED_11D_2G 5
246 #define LOCALE_RESTRICTED_11D_5G 6
247 #define LOCALE_RESTRICTED_LOW_HI 7
248 #define LOCALE_RESTRICTED_12_13_14 8
250 /* global memory to provide working buffer for expanded locale */
252 static const struct brcms_chanvec *g_table_radar_set[] = {
257 static const struct brcms_chanvec *g_table_restricted_chan[] = {
258 &chanvec_none, /* restricted_set_none */
259 &restricted_set_2g_short,
260 &restricted_chan_165,
262 &restricted_set_japan_legacy,
263 &chanvec_all_2G, /* restricted_set_11d_2G */
264 &chanvec_all_5G, /* restricted_set_11d_5G */
266 &restricted_set_12_13_14
269 static const struct brcms_chanvec locale_2g_01_11 = {
270 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00}
276 static const struct brcms_chanvec locale_2g_12_13 = {
277 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00}
283 static const struct brcms_chanvec locale_2g_14 = {
284 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00}
290 static const struct brcms_chanvec locale_5g_LOW_JP1 = {
291 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00}
297 static const struct brcms_chanvec locale_5g_LOW_JP2 = {
298 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x00, 0x00, 0x00, 0x00}
304 static const struct brcms_chanvec locale_5g_LOW1 = {
305 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00}
311 static const struct brcms_chanvec locale_5g_LOW2 = {
312 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00}
318 static const struct brcms_chanvec locale_5g_LOW3 = {
319 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
320 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 0x00, 0x00, 0x00, 0x00}
325 static const struct brcms_chanvec locale_5g_MID1 = {
326 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329 0x00, 0x00, 0x00, 0x00}
332 static const struct brcms_chanvec locale_5g_MID2 = {
333 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336 0x00, 0x00, 0x00, 0x00}
339 static const struct brcms_chanvec locale_5g_MID3 = {
340 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00}
346 static const struct brcms_chanvec locale_5g_HIGH1 = {
347 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350 0x00, 0x00, 0x00, 0x00}
353 static const struct brcms_chanvec locale_5g_HIGH2 = {
354 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00}
360 static const struct brcms_chanvec locale_5g_HIGH3 = {
361 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
364 0x00, 0x00, 0x00, 0x00}
367 static const struct brcms_chanvec locale_5g_52_140_ALL = {
368 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
369 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
370 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
371 0x00, 0x00, 0x00, 0x00}
374 static const struct brcms_chanvec locale_5g_HIGH4 = {
375 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
378 0x11, 0x11, 0x11, 0x11}
381 static const struct brcms_chanvec *g_table_locale_base[] = {
396 &locale_5g_52_140_ALL,
400 static void brcms_c_locale_add_channels(struct brcms_chanvec *target,
401 const struct brcms_chanvec *channels)
404 for (i = 0; i < sizeof(struct brcms_chanvec); i++)
405 target->vec[i] |= channels->vec[i];
408 static void brcms_c_locale_get_channels(const struct locale_info *locale,
409 struct brcms_chanvec *channels)
413 memset(channels, 0, sizeof(struct brcms_chanvec));
415 for (i = 0; i < ARRAY_SIZE(g_table_locale_base); i++) {
416 if (locale->valid_channels & (1 << i))
417 brcms_c_locale_add_channels(channels,
418 g_table_locale_base[i]);
423 * Locale Definitions - 2.4 GHz
425 static const struct locale_info locale_i = { /* locale i. channel 1 - 13 */
426 LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13,
427 LOCALE_RADAR_SET_NONE,
428 LOCALE_RESTRICTED_SET_2G_SHORT,
429 {QDB(19), QDB(19), QDB(19),
430 QDB(19), QDB(19), QDB(19)},
436 * Locale Definitions - 5 GHz
438 static const struct locale_info locale_11 = {
439 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
440 LOCALE_CHAN_36_64 | LOCALE_CHAN_100_140 | LOCALE_CHAN_149_165,
442 LOCALE_RESTRICTED_NONE,
443 {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
444 {23, 23, 23, 30, 30},
445 BRCMS_EIRP | BRCMS_DFS_EU
448 #define LOCALE_2G_IDX_i 0
449 static const struct locale_info *g_locale_2g_table[] = {
453 #define LOCALE_5G_IDX_11 0
454 static const struct locale_info *g_locale_5g_table[] = {
459 * MIMO Locale Definitions - 2.4 GHz
461 static const struct locale_mimo_info locale_bn = {
462 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
463 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
464 QDB(13), QDB(13), QDB(13)},
465 {0, 0, QDB(13), QDB(13), QDB(13),
466 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
471 /* locale mimo 2g indexes */
472 #define LOCALE_MIMO_IDX_bn 0
474 static const struct locale_mimo_info *g_mimo_2g_table[] = {
479 * MIMO Locale Definitions - 5 GHz
481 static const struct locale_mimo_info locale_11n = {
482 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
483 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
487 #define LOCALE_MIMO_IDX_11n 0
488 static const struct locale_mimo_info *g_mimo_5g_table[] = {
495 #define LC(id) LOCALE_MIMO_IDX_ ## id
500 #define LC_2G(id) LOCALE_2G_IDX_ ## id
505 #define LC_5G(id) LOCALE_5G_IDX_ ## id
507 #define LOCALES(band2, band5, mimo2, mimo5) \
508 {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
510 static const struct {
511 char abbrev[BRCM_CNTRY_BUF_SZ]; /* country abbreviation */
512 struct country_info country;
513 } cntry_locales[] = {
515 "X2", LOCALES(i, 11, bn, 11n)}, /* Worldwide RoW 2 */
519 /* 20MHz channel info for 40MHz pairing support */
525 /* indicates adjacent channels that are allowed for a 40 Mhz channel and
526 * those that permitted by the HT
528 struct chan20_info chan20_info[] = {
530 /* 0 */ {1, (CH_UPPER_SB | CH_EWA_VALID)},
531 /* 1 */ {2, (CH_UPPER_SB | CH_EWA_VALID)},
532 /* 2 */ {3, (CH_UPPER_SB | CH_EWA_VALID)},
533 /* 3 */ {4, (CH_UPPER_SB | CH_EWA_VALID)},
534 /* 4 */ {5, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
535 /* 5 */ {6, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
536 /* 6 */ {7, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
537 /* 7 */ {8, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
538 /* 8 */ {9, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
539 /* 9 */ {10, (CH_LOWER_SB | CH_EWA_VALID)},
540 /* 10 */ {11, (CH_LOWER_SB | CH_EWA_VALID)},
541 /* 11 */ {12, (CH_LOWER_SB)},
542 /* 12 */ {13, (CH_LOWER_SB)},
543 /* 13 */ {14, (CH_LOWER_SB)},
546 /* 14 */ {34, (CH_UPPER_SB)},
547 /* 15 */ {38, (CH_LOWER_SB)},
548 /* 16 */ {42, (CH_LOWER_SB)},
549 /* 17 */ {46, (CH_LOWER_SB)},
552 /* 18 */ {36, (CH_UPPER_SB | CH_EWA_VALID)},
553 /* 19 */ {40, (CH_LOWER_SB | CH_EWA_VALID)},
554 /* 20 */ {44, (CH_UPPER_SB | CH_EWA_VALID)},
555 /* 21 */ {48, (CH_LOWER_SB | CH_EWA_VALID)},
556 /* 22 */ {52, (CH_UPPER_SB | CH_EWA_VALID)},
557 /* 23 */ {56, (CH_LOWER_SB | CH_EWA_VALID)},
558 /* 24 */ {60, (CH_UPPER_SB | CH_EWA_VALID)},
559 /* 25 */ {64, (CH_LOWER_SB | CH_EWA_VALID)},
562 /* 26 */ {100, (CH_UPPER_SB | CH_EWA_VALID)},
563 /* 27 */ {104, (CH_LOWER_SB | CH_EWA_VALID)},
564 /* 28 */ {108, (CH_UPPER_SB | CH_EWA_VALID)},
565 /* 29 */ {112, (CH_LOWER_SB | CH_EWA_VALID)},
566 /* 30 */ {116, (CH_UPPER_SB | CH_EWA_VALID)},
567 /* 31 */ {120, (CH_LOWER_SB | CH_EWA_VALID)},
568 /* 32 */ {124, (CH_UPPER_SB | CH_EWA_VALID)},
569 /* 33 */ {128, (CH_LOWER_SB | CH_EWA_VALID)},
570 /* 34 */ {132, (CH_UPPER_SB | CH_EWA_VALID)},
571 /* 35 */ {136, (CH_LOWER_SB | CH_EWA_VALID)},
572 /* 36 */ {140, (CH_LOWER_SB)},
574 /* 11a usa high, ref5 only */
575 /* The 0x80 bit in pdiv means these are REF5, other entries are REF20 */
576 /* 37 */ {149, (CH_UPPER_SB | CH_EWA_VALID)},
577 /* 38 */ {153, (CH_LOWER_SB | CH_EWA_VALID)},
578 /* 39 */ {157, (CH_UPPER_SB | CH_EWA_VALID)},
579 /* 40 */ {161, (CH_LOWER_SB | CH_EWA_VALID)},
580 /* 41 */ {165, (CH_LOWER_SB)},
583 /* 42 */ {184, (CH_UPPER_SB)},
584 /* 43 */ {188, (CH_LOWER_SB)},
585 /* 44 */ {192, (CH_UPPER_SB)},
586 /* 45 */ {196, (CH_LOWER_SB)},
587 /* 46 */ {200, (CH_UPPER_SB)},
588 /* 47 */ {204, (CH_LOWER_SB)},
589 /* 48 */ {208, (CH_UPPER_SB)},
590 /* 49 */ {212, (CH_LOWER_SB)},
591 /* 50 */ {216, (CH_LOWER_SB)}
593 #endif /* SUPPORT_40MHZ */
595 static const struct locale_info *brcms_c_get_locale_2g(u8 locale_idx)
597 if (locale_idx >= ARRAY_SIZE(g_locale_2g_table))
598 return NULL; /* error condition */
600 return g_locale_2g_table[locale_idx];
603 static const struct locale_info *brcms_c_get_locale_5g(u8 locale_idx)
605 if (locale_idx >= ARRAY_SIZE(g_locale_5g_table))
606 return NULL; /* error condition */
608 return g_locale_5g_table[locale_idx];
611 static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx)
613 if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table))
616 return g_mimo_2g_table[locale_idx];
619 static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx)
621 if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table))
624 return g_mimo_5g_table[locale_idx];
627 struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
629 struct brcms_cm_info *wlc_cm;
630 char country_abbrev[BRCM_CNTRY_BUF_SZ];
631 const struct country_info *country;
632 struct brcms_pub *pub = wlc->pub;
635 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
637 wlc_cm = kzalloc(sizeof(struct brcms_cm_info), GFP_ATOMIC);
638 if (wlc_cm == NULL) {
639 wiphy_err(wlc->wiphy, "wl%d: %s: out of memory", pub->unit,
647 /* store the country code for passing up as a regulatory hint */
648 ccode = getvar(wlc->pub->vars, "ccode");
650 strncpy(wlc->pub->srom_ccode, ccode, BRCM_CNTRY_BUF_SZ - 1);
653 * internal country information which must match
654 * regulatory constraints in firmware
656 memset(country_abbrev, 0, BRCM_CNTRY_BUF_SZ);
657 strncpy(country_abbrev, "X2", sizeof(country_abbrev) - 1);
658 country = brcms_c_country_lookup(wlc, country_abbrev);
660 /* save default country for exiting 11d regulatory mode */
661 strncpy(wlc->country_default, country_abbrev, BRCM_CNTRY_BUF_SZ - 1);
663 /* initialize autocountry_default to driver default */
664 strncpy(wlc->autocountry_default, "X2", BRCM_CNTRY_BUF_SZ - 1);
666 brcms_c_set_countrycode(wlc_cm, country_abbrev);
671 void brcms_c_channel_mgr_detach(struct brcms_cm_info *wlc_cm)
677 brcms_c_channel_locale_flags_in_band(struct brcms_cm_info *wlc_cm,
680 return wlc_cm->bandstate[bandunit].locale_flags;
684 * set the driver's current country and regulatory information using
685 * a country code as the source. Lookup built in country information
686 * found with the country code.
689 brcms_c_set_countrycode(struct brcms_cm_info *wlc_cm, const char *ccode)
691 char country_abbrev[BRCM_CNTRY_BUF_SZ];
692 strncpy(country_abbrev, ccode, BRCM_CNTRY_BUF_SZ);
693 return brcms_c_set_countrycode_rev(wlc_cm, country_abbrev, ccode, -1);
697 brcms_c_set_countrycode_rev(struct brcms_cm_info *wlc_cm,
698 const char *country_abbrev,
699 const char *ccode, int regrev)
701 const struct country_info *country;
702 char mapped_ccode[BRCM_CNTRY_BUF_SZ];
705 /* if regrev is -1, lookup the mapped country code,
706 * otherwise use the ccode and regrev directly
710 * map the country code to a built-in country
711 * code, regrev, and country_info
714 brcms_c_countrycode_map(wlc_cm, ccode, mapped_ccode,
717 /* find the matching built-in country definition */
718 country = brcms_c_country_lookup_direct(ccode, regrev);
719 strncpy(mapped_ccode, ccode, BRCM_CNTRY_BUF_SZ);
720 mapped_regrev = regrev;
726 /* set the driver state for the country */
727 brcms_c_set_country_common(wlc_cm, country_abbrev, mapped_ccode,
728 mapped_regrev, country);
734 * set the driver's current country and regulatory information
735 * using a country code as the source. Look up built in country
736 * information found with the country code.
739 brcms_c_set_country_common(struct brcms_cm_info *wlc_cm,
740 const char *country_abbrev,
741 const char *ccode, uint regrev,
742 const struct country_info *country)
744 const struct locale_mimo_info *li_mimo;
745 const struct locale_info *locale;
746 struct brcms_c_info *wlc = wlc_cm->wlc;
747 char prev_country_abbrev[BRCM_CNTRY_BUF_SZ];
749 /* save current country state */
750 wlc_cm->country = country;
752 memset(&prev_country_abbrev, 0, BRCM_CNTRY_BUF_SZ);
753 strncpy(prev_country_abbrev, wlc_cm->country_abbrev,
754 BRCM_CNTRY_BUF_SZ - 1);
756 strncpy(wlc_cm->country_abbrev, country_abbrev, BRCM_CNTRY_BUF_SZ - 1);
757 strncpy(wlc_cm->ccode, ccode, BRCM_CNTRY_BUF_SZ - 1);
758 wlc_cm->regrev = regrev;
760 /* disable/restore nmode based on country regulations */
761 li_mimo = brcms_c_get_mimo_2g(country->locale_mimo_2G);
762 if (li_mimo && (li_mimo->flags & BRCMS_NO_MIMO)) {
763 brcms_c_set_nmode(wlc, OFF);
764 wlc->stf->no_cddstbc = true;
766 wlc->stf->no_cddstbc = false;
767 if (N_ENAB(wlc->pub) != wlc->protection->nmode_user)
768 brcms_c_set_nmode(wlc, wlc->protection->nmode_user);
771 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
772 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
773 /* set or restore gmode as required by regulatory */
774 locale = brcms_c_get_locale_2g(country->locale_2G);
775 if (locale && (locale->flags & BRCMS_NO_OFDM))
776 brcms_c_set_gmode(wlc, GMODE_LEGACY_B, false);
778 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
780 brcms_c_channels_init(wlc_cm, country);
785 /* Lookup a country info structure from a null terminated country code
786 * The lookup is case sensitive.
788 static const struct country_info *
789 brcms_c_country_lookup(struct brcms_c_info *wlc, const char *ccode)
791 const struct country_info *country;
792 char mapped_ccode[BRCM_CNTRY_BUF_SZ];
796 * map the country code to a built-in country code, regrev, and
797 * country_info struct
799 country = brcms_c_countrycode_map(wlc->cmi, ccode, mapped_ccode,
805 static const struct country_info *
806 brcms_c_countrycode_map(struct brcms_cm_info *wlc_cm, const char *ccode,
807 char *mapped_ccode, uint *mapped_regrev)
809 struct brcms_c_info *wlc = wlc_cm->wlc;
810 const struct country_info *country;
811 uint srom_regrev = wlc_cm->srom_regrev;
812 const char *srom_ccode = wlc_cm->srom_ccode;
815 /* check for currently supported ccode size */
816 if (strlen(ccode) > (BRCM_CNTRY_BUF_SZ - 1)) {
817 wiphy_err(wlc->wiphy, "wl%d: %s: ccode \"%s\" too long for "
818 "match\n", wlc->pub->unit, __func__, ccode);
822 /* default mapping is the given ccode and regrev 0 */
823 strncpy(mapped_ccode, ccode, BRCM_CNTRY_BUF_SZ);
826 /* If the desired country code matches the srom country code,
827 * then the mapped country is the srom regulatory rev.
828 * Otherwise look for an aggregate mapping.
830 if (!strcmp(srom_ccode, ccode)) {
831 *mapped_regrev = srom_regrev;
833 wiphy_err(wlc->wiphy, "srom_code == ccode %s\n", __func__);
836 brcms_c_country_aggregate_map(wlc_cm, ccode, mapped_ccode,
840 /* find the matching built-in country definition */
841 country = brcms_c_country_lookup_direct(mapped_ccode, *mapped_regrev);
843 /* if there is not an exact rev match, default to rev zero */
844 if (country == NULL && *mapped_regrev != 0) {
847 brcms_c_country_lookup_direct(mapped_ccode, *mapped_regrev);
854 brcms_c_country_aggregate_map(struct brcms_cm_info *wlc_cm, const char *ccode,
855 char *mapped_ccode, uint *mapped_regrev)
860 /* Lookup a country info structure from a null terminated country
861 * abbreviation and regrev directly with no translation.
863 static const struct country_info *
864 brcms_c_country_lookup_direct(const char *ccode, uint regrev)
868 /* Should just return 0 for single locale driver. */
869 /* Keep it this way in case we add more locales. (for now anyway) */
872 * all other country def arrays are for regrev == 0, so if
873 * regrev is non-zero, fail
878 /* find matched table entry from country code */
879 size = ARRAY_SIZE(cntry_locales);
880 for (i = 0; i < size; i++) {
881 if (strcmp(ccode, cntry_locales[i].abbrev) == 0)
882 return &cntry_locales[i].country;
888 brcms_c_channels_init(struct brcms_cm_info *wlc_cm,
889 const struct country_info *country)
891 struct brcms_c_info *wlc = wlc_cm->wlc;
893 struct brcms_band *band;
894 const struct locale_info *li;
895 struct brcms_chanvec sup_chan;
896 const struct locale_mimo_info *li_mimo;
899 for (i = 0; i < NBANDS(wlc);
900 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
902 li = BAND_5G(band->bandtype) ?
903 brcms_c_get_locale_5g(country->locale_5G) :
904 brcms_c_get_locale_2g(country->locale_2G);
905 wlc_cm->bandstate[band->bandunit].locale_flags = li->flags;
906 li_mimo = BAND_5G(band->bandtype) ?
907 brcms_c_get_mimo_5g(country->locale_mimo_5G) :
908 brcms_c_get_mimo_2g(country->locale_mimo_2G);
910 /* merge the mimo non-mimo locale flags */
911 wlc_cm->bandstate[band->bandunit].locale_flags |=
914 wlc_cm->bandstate[band->bandunit].restricted_channels =
915 g_table_restricted_chan[li->restricted_channels];
916 wlc_cm->bandstate[band->bandunit].radar_channels =
917 g_table_radar_set[li->radar_channels];
920 * set the channel availability, masking out the channels
921 * that may not be supported on this phy.
923 wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
925 brcms_c_locale_get_channels(li,
926 &wlc_cm->bandstate[band->bandunit].
928 for (j = 0; j < sizeof(struct brcms_chanvec); j++)
929 wlc_cm->bandstate[band->bandunit].valid_channels.
930 vec[j] &= sup_chan.vec[j];
933 brcms_c_quiet_channels_reset(wlc_cm);
934 brcms_c_channels_commit(wlc_cm);
939 /* Update the radio state (enable/disable) and tx power targets
940 * based on a new set of channel/regulatory information
942 static void brcms_c_channels_commit(struct brcms_cm_info *wlc_cm)
944 struct brcms_c_info *wlc = wlc_cm->wlc;
946 struct txpwr_limits txpwr;
948 /* search for the existence of any valid channel */
949 for (chan = 0; chan < MAXCHANNEL; chan++) {
950 if (VALID_CHANNEL20_DB(wlc, chan))
953 if (chan == MAXCHANNEL)
957 * based on the channel search above, set or
958 * clear WL_RADIO_COUNTRY_DISABLE.
960 if (chan == INVCHANNEL) {
962 * country/locale with no valid channels, set
963 * the radio disable bit
965 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
966 wiphy_err(wlc->wiphy, "wl%d: %s: no valid channel for \"%s\" "
967 "nbands %d bandlocked %d\n", wlc->pub->unit,
968 __func__, wlc_cm->country_abbrev, NBANDS(wlc),
970 } else if (mboolisset(wlc->pub->radio_disabled,
971 WL_RADIO_COUNTRY_DISABLE)) {
973 * country/locale with valid channel, clear
974 * the radio disable bit
976 mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
980 * Now that the country abbreviation is set, if the radio supports 2G,
981 * then set channel 14 restrictions based on the new locale.
983 if (NBANDS(wlc) > 1 || BAND_2G(wlc->band->bandtype))
984 wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
985 brcms_c_japan(wlc) ? true :
988 if (wlc->pub->up && chan != INVCHANNEL) {
989 brcms_c_channel_reg_limits(wlc_cm, wlc->chanspec, &txpwr);
990 brcms_c_channel_min_txpower_limits_with_local_constraint(wlc_cm,
991 &txpwr, BRCMS_TXPWR_MAX);
992 wlc_phy_txpower_limit_set(wlc->band->pi, &txpwr, wlc->chanspec);
997 * reset the quiet channels vector to the union
998 * of the restricted and radar channel sets
1000 static void brcms_c_quiet_channels_reset(struct brcms_cm_info *wlc_cm)
1002 struct brcms_c_info *wlc = wlc_cm->wlc;
1004 struct brcms_band *band;
1005 const struct brcms_chanvec *chanvec;
1007 memset(&wlc_cm->quiet_channels, 0, sizeof(struct brcms_chanvec));
1010 for (i = 0; i < NBANDS(wlc);
1011 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
1013 /* initialize quiet channels for restricted channels */
1014 chanvec = wlc_cm->bandstate[band->bandunit].restricted_channels;
1015 for (j = 0; j < sizeof(struct brcms_chanvec); j++)
1016 wlc_cm->quiet_channels.vec[j] |= chanvec->vec[j];
1022 brcms_c_quiet_chanspec(struct brcms_cm_info *wlc_cm, u16 chspec)
1024 return N_ENAB(wlc_cm->wlc->pub) && CHSPEC_IS40(chspec) ?
1025 (isset(wlc_cm->quiet_channels.vec,
1026 LOWER_20_SB(CHSPEC_CHANNEL(chspec))) ||
1027 isset(wlc_cm->quiet_channels.vec,
1028 UPPER_20_SB(CHSPEC_CHANNEL(chspec)))) :
1029 isset(wlc_cm->quiet_channels.vec, CHSPEC_CHANNEL(chspec));
1032 /* Is the channel valid for the current locale? (but don't consider channels not
1033 * available due to bandlocking)
1035 static bool brcms_c_valid_channel20_db(struct brcms_cm_info *wlc_cm, uint val)
1037 struct brcms_c_info *wlc = wlc_cm->wlc;
1039 return VALID_CHANNEL20(wlc, val) ||
1041 && VALID_CHANNEL20_IN_BAND(wlc, OTHERBANDUNIT(wlc), val));
1044 /* Is the channel valid for the current locale and specified band? */
1045 static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info *wlc_cm,
1046 uint bandunit, uint val)
1048 return ((val < MAXCHANNEL)
1049 && isset(wlc_cm->bandstate[bandunit].valid_channels.vec, val));
1052 /* Is the channel valid for the current locale and current band? */
1053 static bool brcms_c_valid_channel20(struct brcms_cm_info *wlc_cm, uint val)
1055 struct brcms_c_info *wlc = wlc_cm->wlc;
1057 return ((val < MAXCHANNEL) &&
1058 isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec,
1063 brcms_c_channel_min_txpower_limits_with_local_constraint(
1064 struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
1065 u8 local_constraint_qdbm)
1070 for (j = 0; j < WL_TX_POWER_CCK_NUM; j++)
1071 txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
1073 /* 20 MHz Legacy OFDM SISO */
1074 for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++)
1075 txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
1077 /* 20 MHz Legacy OFDM CDD */
1078 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
1079 txpwr->ofdm_cdd[j] =
1080 min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
1082 /* 40 MHz Legacy OFDM SISO */
1083 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
1084 txpwr->ofdm_40_siso[j] =
1085 min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
1087 /* 40 MHz Legacy OFDM CDD */
1088 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
1089 txpwr->ofdm_40_cdd[j] =
1090 min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
1092 /* 20MHz MCS 0-7 SISO */
1093 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1094 txpwr->mcs_20_siso[j] =
1095 min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
1097 /* 20MHz MCS 0-7 CDD */
1098 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1099 txpwr->mcs_20_cdd[j] =
1100 min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
1102 /* 20MHz MCS 0-7 STBC */
1103 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1104 txpwr->mcs_20_stbc[j] =
1105 min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
1107 /* 20MHz MCS 8-15 MIMO */
1108 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
1109 txpwr->mcs_20_mimo[j] =
1110 min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
1112 /* 40MHz MCS 0-7 SISO */
1113 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1114 txpwr->mcs_40_siso[j] =
1115 min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
1117 /* 40MHz MCS 0-7 CDD */
1118 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1119 txpwr->mcs_40_cdd[j] =
1120 min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
1122 /* 40MHz MCS 0-7 STBC */
1123 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
1124 txpwr->mcs_40_stbc[j] =
1125 min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
1127 /* 40MHz MCS 8-15 MIMO */
1128 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
1129 txpwr->mcs_40_mimo[j] =
1130 min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
1133 txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
1138 brcms_c_channel_set_chanspec(struct brcms_cm_info *wlc_cm, u16 chanspec,
1139 u8 local_constraint_qdbm)
1141 struct brcms_c_info *wlc = wlc_cm->wlc;
1142 struct txpwr_limits txpwr;
1144 brcms_c_channel_reg_limits(wlc_cm, chanspec, &txpwr);
1146 brcms_c_channel_min_txpower_limits_with_local_constraint(
1147 wlc_cm, &txpwr, local_constraint_qdbm
1150 brcms_b_set_chanspec(wlc->hw, chanspec,
1151 (brcms_c_quiet_chanspec(wlc_cm, chanspec) != 0),
1156 static void wlc_phy_txpower_limits_dump(struct txpwr_limits *txpwr)
1160 char fraction[4][4] = { " ", ".25", ".5 ", ".75" };
1162 sprintf(buf, "CCK ");
1163 for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
1164 sprintf(buf[strlen(buf)], " %2d%s",
1165 txpwr->cck[i] / BRCMS_TXPWR_DB_FACTOR,
1166 fraction[txpwr->cck[i] % BRCMS_TXPWR_DB_FACTOR]);
1167 printk(KERN_DEBUG "%s\n", buf);
1169 sprintf(buf, "20 MHz OFDM SISO ");
1170 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
1171 sprintf(buf[strlen(buf)], " %2d%s",
1172 txpwr->ofdm[i] / BRCMS_TXPWR_DB_FACTOR,
1173 fraction[txpwr->ofdm[i] % BRCMS_TXPWR_DB_FACTOR]);
1174 printk(KERN_DEBUG "%s\n", buf);
1176 sprintf(buf, "20 MHz OFDM CDD ");
1177 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
1178 sprintf(buf[strlen(buf)], " %2d%s",
1179 txpwr->ofdm_cdd[i] / BRCMS_TXPWR_DB_FACTOR,
1180 fraction[txpwr->ofdm_cdd[i] % BRCMS_TXPWR_DB_FACTOR]);
1181 printk(KERN_DEBUG "%s\n", buf);
1183 sprintf(buf, "40 MHz OFDM SISO ");
1184 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
1185 sprintf(buf[strlen(buf)], " %2d%s",
1186 txpwr->ofdm_40_siso[i] / BRCMS_TXPWR_DB_FACTOR,
1187 fraction[txpwr->ofdm_40_siso[i] %
1188 BRCMS_TXPWR_DB_FACTOR]);
1189 printk(KERN_DEBUG "%s\n", buf);
1191 sprintf(buf, "40 MHz OFDM CDD ");
1192 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
1193 sprintf(buf[strlen(buf)], " %2d%s",
1194 txpwr->ofdm_40_cdd[i] / BRCMS_TXPWR_DB_FACTOR,
1195 fraction[txpwr->ofdm_40_cdd[i] %
1196 BRCMS_TXPWR_DB_FACTOR]);
1197 printk(KERN_DEBUG "%s\n", buf);
1199 sprintf(buf, "20 MHz MCS0-7 SISO ");
1200 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1201 sprintf(buf[strlen(buf)], " %2d%s",
1202 txpwr->mcs_20_siso[i] / BRCMS_TXPWR_DB_FACTOR,
1203 fraction[txpwr->mcs_20_siso[i] %
1204 BRCMS_TXPWR_DB_FACTOR]);
1205 printk(KERN_DEBUG "%s\n", buf);
1207 sprintf(buf, "20 MHz MCS0-7 CDD ");
1208 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1209 sprintf(buf[strlen(buf)], " %2d%s",
1210 txpwr->mcs_20_cdd[i] / BRCMS_TXPWR_DB_FACTOR,
1211 fraction[txpwr->mcs_20_cdd[i] %
1212 BRCMS_TXPWR_DB_FACTOR]);
1213 printk(KERN_DEBUG "%s\n", buf);
1215 sprintf(buf, "20 MHz MCS0-7 STBC ");
1216 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1217 sprintf(buf[strlen(buf)], " %2d%s",
1218 txpwr->mcs_20_stbc[i] / BRCMS_TXPWR_DB_FACTOR,
1219 fraction[txpwr->mcs_20_stbc[i] %
1220 BRCMS_TXPWR_DB_FACTOR]);
1221 printk(KERN_DEBUG "%s\n", buf);
1223 sprintf(buf, "20 MHz MCS8-15 SDM ");
1224 for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++)
1225 sprintf(buf[strlen(buf)], " %2d%s",
1226 txpwr->mcs_20_mimo[i] / BRCMS_TXPWR_DB_FACTOR,
1227 fraction[txpwr->mcs_20_mimo[i] %
1228 BRCMS_TXPWR_DB_FACTOR]);
1229 printk(KERN_DEBUG "%s\n", buf);
1231 sprintf(buf, "40 MHz MCS0-7 SISO ");
1232 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1233 sprintf(buf[strlen(buf)], " %2d%s",
1234 txpwr->mcs_40_siso[i] / BRCMS_TXPWR_DB_FACTOR,
1235 fraction[txpwr->mcs_40_siso[i] %
1236 BRCMS_TXPWR_DB_FACTOR]);
1237 printk(KERN_DEBUG "%s\n", buf);
1239 sprintf(buf, "40 MHz MCS0-7 CDD ");
1240 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1241 sprintf(buf[strlen(buf)], " %2d%s",
1242 txpwr->mcs_40_cdd[i] / BRCMS_TXPWR_DB_FACTOR,
1243 fraction[txpwr->mcs_40_cdd[i] %
1244 BRCMS_TXPWR_DB_FACTOR]);
1245 printk(KERN_DEBUG "%s\n", buf);
1247 sprintf(buf, "40 MHz MCS0-7 STBC ");
1248 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++)
1249 sprintf(buf[strlen(buf)], " %2d%s",
1250 txpwr->mcs_40_stbc[i] / BRCMS_TXPWR_DB_FACTOR,
1251 fraction[txpwr->mcs_40_stbc[i] %
1252 BRCMS_TXPWR_DB_FACTOR]);
1253 printk(KERN_DEBUG "%s\n", buf);
1255 sprintf(buf, "40 MHz MCS8-15 SDM ");
1256 for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++)
1257 sprintf(buf[strlen(buf)], " %2d%s",
1258 txpwr->mcs_40_mimo[i] / BRCMS_TXPWR_DB_FACTOR,
1259 fraction[txpwr->mcs_40_mimo[i] %
1260 BRCMS_TXPWR_DB_FACTOR]);
1262 printk(KERN_DEBUG "%s\n", buf);
1264 printk(KERN_DEBUG "MCS32 %2d%s\n",
1265 txpwr->mcs32 / BRCMS_TXPWR_DB_FACTOR,
1266 fraction[txpwr->mcs32 % BRCMS_TXPWR_DB_FACTOR]);
1268 #endif /* POWER_DBG */
1271 brcms_c_channel_reg_limits(struct brcms_cm_info *wlc_cm, u16 chanspec,
1272 struct txpwr_limits *txpwr)
1274 struct brcms_c_info *wlc = wlc_cm->wlc;
1279 const struct country_info *country;
1280 struct brcms_band *band;
1281 const struct locale_info *li;
1282 int conducted_max = BRCMS_TXPWR_MAX;
1283 int conducted_ofdm_max = BRCMS_TXPWR_MAX;
1284 const struct locale_mimo_info *li_mimo;
1285 int maxpwr20, maxpwr40;
1289 memset(txpwr, 0, sizeof(struct txpwr_limits));
1291 if (!brcms_c_valid_chanspec_db(wlc_cm, chanspec)) {
1292 country = brcms_c_country_lookup(wlc, wlc->autocountry_default);
1293 if (country == NULL)
1296 country = wlc_cm->country;
1299 chan = CHSPEC_CHANNEL(chanspec);
1300 band = wlc->bandstate[CHSPEC_BANDUNIT(chanspec)];
1301 li = BAND_5G(band->bandtype) ?
1302 brcms_c_get_locale_5g(country->locale_5G) :
1303 brcms_c_get_locale_2g(country->locale_2G);
1305 li_mimo = BAND_5G(band->bandtype) ?
1306 brcms_c_get_mimo_5g(country->locale_mimo_5G) :
1307 brcms_c_get_mimo_2g(country->locale_mimo_2G);
1309 if (li->flags & BRCMS_EIRP) {
1310 delta = band->antgain;
1313 if (band->antgain > QDB(6))
1314 delta = band->antgain - QDB(6); /* Excess over 6 dB */
1317 if (li == &locale_i) {
1318 conducted_max = QDB(22);
1319 conducted_ofdm_max = QDB(22);
1322 /* CCK txpwr limits for 2.4G band */
1323 if (BAND_2G(band->bandtype)) {
1324 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_CCK(chan)];
1326 maxpwr = maxpwr - delta;
1327 maxpwr = max(maxpwr, 0);
1328 maxpwr = min(maxpwr, conducted_max);
1330 for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
1331 txpwr->cck[i] = (u8) maxpwr;
1334 /* OFDM txpwr limits for 2.4G or 5G bands */
1335 if (BAND_2G(band->bandtype))
1336 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_OFDM(chan)];
1338 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_5G(chan)];
1340 maxpwr = maxpwr - delta;
1341 maxpwr = max(maxpwr, 0);
1342 maxpwr = min(maxpwr, conducted_ofdm_max);
1344 /* Keep OFDM lmit below CCK limit */
1345 if (BAND_2G(band->bandtype))
1346 maxpwr = min_t(int, maxpwr, txpwr->cck[0]);
1348 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
1349 txpwr->ofdm[i] = (u8) maxpwr;
1351 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++) {
1353 * OFDM 40 MHz SISO has the same power as the corresponding
1354 * MCS0-7 rate unless overriden by the locale specific code.
1355 * We set this value to 0 as a flag (presumably 0 dBm isn't
1356 * a possibility) and then copy the MCS0-7 value to the 40 MHz
1357 * value if it wasn't explicitly set.
1359 txpwr->ofdm_40_siso[i] = 0;
1361 txpwr->ofdm_cdd[i] = (u8) maxpwr;
1363 txpwr->ofdm_40_cdd[i] = 0;
1366 /* MIMO/HT specific limits */
1367 if (li_mimo->flags & BRCMS_EIRP) {
1368 delta = band->antgain;
1371 if (band->antgain > QDB(6))
1372 delta = band->antgain - QDB(6); /* Excess over 6 dB */
1375 if (BAND_2G(band->bandtype))
1376 maxpwr_idx = (chan - 1);
1378 maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
1380 maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
1381 maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
1383 maxpwr20 = maxpwr20 - delta;
1384 maxpwr20 = max(maxpwr20, 0);
1385 maxpwr40 = maxpwr40 - delta;
1386 maxpwr40 = max(maxpwr40, 0);
1388 /* Fill in the MCS 0-7 (SISO) rates */
1389 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1392 * 20 MHz has the same power as the corresponding OFDM rate
1393 * unless overriden by the locale specific code.
1395 txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
1396 txpwr->mcs_40_siso[i] = 0;
1399 /* Fill in the MCS 0-7 CDD rates */
1400 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1401 txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
1402 txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
1406 * These locales have SISO expressed in the
1407 * table and override CDD later
1409 if (li_mimo == &locale_bn) {
1410 if (li_mimo == &locale_bn) {
1414 if (chan >= 3 && chan <= 11)
1418 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1419 txpwr->mcs_20_siso[i] = (u8) maxpwr20;
1420 txpwr->mcs_40_siso[i] = (u8) maxpwr40;
1424 /* Fill in the MCS 0-7 STBC rates */
1425 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1426 txpwr->mcs_20_stbc[i] = 0;
1427 txpwr->mcs_40_stbc[i] = 0;
1430 /* Fill in the MCS 8-15 SDM rates */
1431 for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++) {
1432 txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
1433 txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
1437 txpwr->mcs32 = (u8) maxpwr40;
1439 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
1440 if (txpwr->ofdm_40_cdd[i] == 0)
1441 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
1444 if (txpwr->ofdm_40_cdd[i] == 0)
1445 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
1450 * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
1451 * value if it wasn't provided explicitly.
1453 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1454 if (txpwr->mcs_40_siso[i] == 0)
1455 txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
1458 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
1459 if (txpwr->ofdm_40_siso[i] == 0)
1460 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
1463 if (txpwr->ofdm_40_siso[i] == 0)
1464 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
1469 * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
1470 * STBC values if they weren't provided explicitly.
1472 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
1473 if (txpwr->mcs_20_stbc[i] == 0)
1474 txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
1476 if (txpwr->mcs_40_stbc[i] == 0)
1477 txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
1481 wlc_phy_txpower_limits_dump(txpwr);
1486 /* Returns true if currently set country is Japan or variant */
1487 static bool brcms_c_japan(struct brcms_c_info *wlc)
1489 return brcms_c_japan_ccode(wlc->cmi->country_abbrev);
1492 /* JP, J1 - J10 are Japan ccodes */
1493 static bool brcms_c_japan_ccode(const char *ccode)
1495 return (ccode[0] == 'J' &&
1496 (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
1500 * Validate the chanspec for this locale, for 40MHZ we need to also
1501 * check that the sidebands are valid 20MZH channels in this locale
1502 * and they are also a legal HT combination
1505 brcms_c_valid_chanspec_ext(struct brcms_cm_info *wlc_cm, u16 chspec,
1508 struct brcms_c_info *wlc = wlc_cm->wlc;
1509 u8 channel = CHSPEC_CHANNEL(chspec);
1511 /* check the chanspec */
1512 if (brcmu_chspec_malformed(chspec)) {
1513 wiphy_err(wlc->wiphy, "wl%d: malformed chanspec 0x%x\n",
1514 wlc->pub->unit, chspec);
1518 if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
1519 CHSPEC_BANDUNIT(chspec))
1522 /* Check a 20Mhz channel */
1523 if (CHSPEC_IS20(chspec)) {
1525 return VALID_CHANNEL20_DB(wlc_cm->wlc, channel);
1527 return VALID_CHANNEL20(wlc_cm->wlc, channel);
1529 #ifdef SUPPORT_40MHZ
1531 * We know we are now checking a 40MHZ channel, so we should
1532 * only be here for NPHYS
1534 if (BRCMS_ISNPHY(wlc->band) || BRCMS_ISSSLPNPHY(wlc->band)) {
1535 u8 upper_sideband = 0, idx;
1536 u8 num_ch20_entries =
1537 sizeof(chan20_info) / sizeof(struct chan20_info);
1539 if (!VALID_40CHANSPEC_IN_BAND(wlc, CHSPEC_BANDUNIT(chspec)))
1543 if (!VALID_CHANNEL20_DB(wlc, LOWER_20_SB(channel)) ||
1544 !VALID_CHANNEL20_DB(wlc, UPPER_20_SB(channel)))
1547 if (!VALID_CHANNEL20(wlc, LOWER_20_SB(channel)) ||
1548 !VALID_CHANNEL20(wlc, UPPER_20_SB(channel)))
1552 /* find the lower sideband info in the sideband array */
1553 for (idx = 0; idx < num_ch20_entries; idx++) {
1554 if (chan20_info[idx].sb == LOWER_20_SB(channel))
1555 upper_sideband = chan20_info[idx].adj_sbs;
1557 /* check that the lower sideband allows an upper sideband */
1558 if ((upper_sideband & (CH_UPPER_SB | CH_EWA_VALID)) ==
1559 (CH_UPPER_SB | CH_EWA_VALID))
1568 bool brcms_c_valid_chanspec_db(struct brcms_cm_info *wlc_cm, u16 chspec)
1570 return brcms_c_valid_chanspec_ext(wlc_cm, chspec, true);