]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/net/wireless/brcm80211/brcmsmac/channel.c
wireless: make the reg_notifier() void
[mirror_ubuntu-jammy-kernel.git] / drivers / net / wireless / brcm80211 / brcmsmac / channel.c
CommitLineData
5b435de0
AS
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
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.
7 *
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.
15 */
16
17#include <linux/types.h>
cf03c5da 18#include <net/cfg80211.h>
5b435de0 19#include <net/mac80211.h>
cf03c5da 20#include <net/regulatory.h>
5b435de0
AS
21
22#include <defs.h>
23#include "pub.h"
24#include "phy/phy_hal.h"
25#include "main.h"
26#include "stf.h"
27#include "channel.h"
cf03c5da 28#include "mac80211_if.h"
b353dda4 29#include "debug.h"
5b435de0
AS
30
31/* QDB() macro takes a dB value and converts to a quarter dB value */
32#define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
33
5b435de0
AS
34#define LOCALE_MIMO_IDX_bn 0
35#define LOCALE_MIMO_IDX_11n 0
36
5b435de0
AS
37/* max of BAND_5G_PWR_LVLS and 14 for 2.4 GHz */
38#define BRCMS_MAXPWR_MIMO_TBL_SIZE 14
39
5b435de0
AS
40/* maxpwr mapping to 5GHz band channels:
41 * maxpwr[0] - channels [34-48]
42 * maxpwr[1] - channels [52-60]
43 * maxpwr[2] - channels [62-64]
44 * maxpwr[3] - channels [100-140]
45 * maxpwr[4] - channels [149-165]
46 */
47#define BAND_5G_PWR_LVLS 5 /* 5 power levels for 5G */
48
49#define LC(id) LOCALE_MIMO_IDX_ ## id
50
edc7651f
SF
51#define LOCALES(mimo2, mimo5) \
52 {LC(mimo2), LC(mimo5)}
5b435de0 53
5b435de0
AS
54/* macro to get 5 GHz channel group index for tx power */
55#define CHANNEL_POWER_IDX_5G(c) (((c) < 52) ? 0 : \
56 (((c) < 62) ? 1 : \
57 (((c) < 100) ? 2 : \
58 (((c) < 149) ? 3 : 4))))
59
cf03c5da
SF
60#define BRCM_2GHZ_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
61#define BRCM_2GHZ_2467_2472 REG_RULE(2467-10, 2472+10, 20, 0, 19, \
62 NL80211_RRF_PASSIVE_SCAN | \
63 NL80211_RRF_NO_IBSS)
64
65#define BRCM_5GHZ_5180_5240 REG_RULE(5180-10, 5240+10, 40, 0, 21, \
66 NL80211_RRF_PASSIVE_SCAN | \
67 NL80211_RRF_NO_IBSS)
68#define BRCM_5GHZ_5260_5320 REG_RULE(5260-10, 5320+10, 40, 0, 21, \
69 NL80211_RRF_PASSIVE_SCAN | \
70 NL80211_RRF_DFS | \
71 NL80211_RRF_NO_IBSS)
72#define BRCM_5GHZ_5500_5700 REG_RULE(5500-10, 5700+10, 40, 0, 21, \
73 NL80211_RRF_PASSIVE_SCAN | \
74 NL80211_RRF_DFS | \
75 NL80211_RRF_NO_IBSS)
76#define BRCM_5GHZ_5745_5825 REG_RULE(5745-10, 5825+10, 40, 0, 21, \
77 NL80211_RRF_PASSIVE_SCAN | \
78 NL80211_RRF_NO_IBSS)
79
80static const struct ieee80211_regdomain brcms_regdom_x2 = {
8a096148 81 .n_reg_rules = 6,
cf03c5da
SF
82 .alpha2 = "X2",
83 .reg_rules = {
84 BRCM_2GHZ_2412_2462,
85 BRCM_2GHZ_2467_2472,
86 BRCM_5GHZ_5180_5240,
87 BRCM_5GHZ_5260_5320,
88 BRCM_5GHZ_5500_5700,
89 BRCM_5GHZ_5745_5825,
90 }
91};
92
5b435de0
AS
93 /* locale per-channel tx power limits for MIMO frames
94 * maxpwr arrays are index by channel for 2.4 GHz limits, and
95 * by sub-band for 5 GHz limits using CHANNEL_POWER_IDX_5G(channel)
96 */
97struct locale_mimo_info {
98 /* tx 20 MHz power limits, qdBm units */
99 s8 maxpwr20[BRCMS_MAXPWR_MIMO_TBL_SIZE];
100 /* tx 40 MHz power limits, qdBm units */
101 s8 maxpwr40[BRCMS_MAXPWR_MIMO_TBL_SIZE];
5b435de0
AS
102};
103
104/* Country names and abbreviations with locale defined from ISO 3166 */
105struct country_info {
5b435de0
AS
106 const u8 locale_mimo_2G; /* 2.4G mimo info */
107 const u8 locale_mimo_5G; /* 5G mimo info */
108};
109
cf03c5da
SF
110struct brcms_regd {
111 struct country_info country;
112 const struct ieee80211_regdomain *regdomain;
113};
114
5b435de0
AS
115struct brcms_cm_info {
116 struct brcms_pub *pub;
117 struct brcms_c_info *wlc;
cf03c5da 118 const struct brcms_regd *world_regd;
5b435de0
AS
119};
120
121/*
122 * MIMO Locale Definitions - 2.4 GHz
123 */
124static const struct locale_mimo_info locale_bn = {
125 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
126 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
127 QDB(13), QDB(13), QDB(13)},
128 {0, 0, QDB(13), QDB(13), QDB(13),
129 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
130 QDB(13), 0, 0},
5b435de0
AS
131};
132
133static const struct locale_mimo_info *g_mimo_2g_table[] = {
134 &locale_bn
135};
136
137/*
138 * MIMO Locale Definitions - 5 GHz
139 */
140static const struct locale_mimo_info locale_11n = {
141 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
142 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
5b435de0
AS
143};
144
145static const struct locale_mimo_info *g_mimo_5g_table[] = {
146 &locale_11n
147};
148
cf03c5da
SF
149static const struct brcms_regd cntry_locales[] = {
150 /* Worldwide RoW 2, must always be at index 0 */
5b435de0 151 {
edc7651f 152 .country = LOCALES(bn, 11n),
cf03c5da
SF
153 .regdomain = &brcms_regdom_x2,
154 },
5b435de0
AS
155};
156
5b435de0
AS
157static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx)
158{
159 if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table))
160 return NULL;
161
162 return g_mimo_2g_table[locale_idx];
163}
164
165static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx)
166{
167 if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table))
168 return NULL;
169
170 return g_mimo_5g_table[locale_idx];
171}
172
94a2ca31
AS
173/*
174 * Indicates whether the country provided is valid to pass
175 * to cfg80211 or not.
176 *
177 * returns true if valid; false if not.
178 */
179static bool brcms_c_country_valid(const char *ccode)
180{
181 /*
182 * only allow ascii alpha uppercase for the first 2
183 * chars.
184 */
185 if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
186 (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A &&
187 ccode[2] == '\0'))
188 return false;
189
190 /*
191 * do not match ISO 3166-1 user assigned country codes
192 * that may be in the driver table
193 */
194 if (!strcmp("AA", ccode) || /* AA */
195 !strcmp("ZZ", ccode) || /* ZZ */
196 ccode[0] == 'X' || /* XA - XZ */
197 (ccode[0] == 'Q' && /* QM - QZ */
198 (ccode[1] >= 'M' && ccode[1] <= 'Z')))
199 return false;
200
201 if (!strcmp("NA", ccode))
202 return false;
203
204 return true;
205}
206
cf03c5da 207static const struct brcms_regd *brcms_world_regd(const char *regdom, int len)
5b435de0 208{
cf03c5da
SF
209 const struct brcms_regd *regd = NULL;
210 int i;
5b435de0 211
cf03c5da
SF
212 for (i = 0; i < ARRAY_SIZE(cntry_locales); i++) {
213 if (!strncmp(regdom, cntry_locales[i].regdomain->alpha2, len)) {
214 regd = &cntry_locales[i];
215 break;
216 }
5b435de0
AS
217 }
218
cf03c5da 219 return regd;
5b435de0
AS
220}
221
cf03c5da 222static const struct brcms_regd *brcms_default_world_regd(void)
5b435de0 223{
cf03c5da 224 return &cntry_locales[0];
5b435de0
AS
225}
226
5b435de0
AS
227/* JP, J1 - J10 are Japan ccodes */
228static bool brcms_c_japan_ccode(const char *ccode)
229{
230 return (ccode[0] == 'J' &&
231 (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
232}
233
5b435de0
AS
234static void
235brcms_c_channel_min_txpower_limits_with_local_constraint(
236 struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
237 u8 local_constraint_qdbm)
238{
239 int j;
240
241 /* CCK Rates */
242 for (j = 0; j < WL_TX_POWER_CCK_NUM; j++)
243 txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
244
245 /* 20 MHz Legacy OFDM SISO */
246 for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++)
247 txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
248
249 /* 20 MHz Legacy OFDM CDD */
250 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
251 txpwr->ofdm_cdd[j] =
252 min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
253
254 /* 40 MHz Legacy OFDM SISO */
255 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
256 txpwr->ofdm_40_siso[j] =
257 min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
258
259 /* 40 MHz Legacy OFDM CDD */
260 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
261 txpwr->ofdm_40_cdd[j] =
262 min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
263
264 /* 20MHz MCS 0-7 SISO */
265 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
266 txpwr->mcs_20_siso[j] =
267 min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
268
269 /* 20MHz MCS 0-7 CDD */
270 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
271 txpwr->mcs_20_cdd[j] =
272 min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
273
274 /* 20MHz MCS 0-7 STBC */
275 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
276 txpwr->mcs_20_stbc[j] =
277 min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
278
279 /* 20MHz MCS 8-15 MIMO */
280 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
281 txpwr->mcs_20_mimo[j] =
282 min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
283
284 /* 40MHz MCS 0-7 SISO */
285 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
286 txpwr->mcs_40_siso[j] =
287 min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
288
289 /* 40MHz MCS 0-7 CDD */
290 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
291 txpwr->mcs_40_cdd[j] =
292 min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
293
294 /* 40MHz MCS 0-7 STBC */
295 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
296 txpwr->mcs_40_stbc[j] =
297 min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
298
299 /* 40MHz MCS 8-15 MIMO */
300 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
301 txpwr->mcs_40_mimo[j] =
302 min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
303
304 /* 40MHz MCS 32 */
305 txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
306
307}
308
5b435de0
AS
309/*
310 * set the driver's current country and regulatory information
311 * using a country code as the source. Look up built in country
312 * information found with the country code.
313 */
314static void
cf03c5da
SF
315brcms_c_set_country(struct brcms_cm_info *wlc_cm,
316 const struct brcms_regd *regd)
5b435de0 317{
5b435de0 318 struct brcms_c_info *wlc = wlc_cm->wlc;
5b435de0 319
5b435de0
AS
320 if ((wlc->pub->_n_enab & SUPPORT_11N) !=
321 wlc->protection->nmode_user)
322 brcms_c_set_nmode(wlc);
323
324 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
325 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
5b435de0 326
edc7651f 327 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
5b435de0
AS
328
329 return;
330}
331
5b435de0
AS
332struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
333{
334 struct brcms_cm_info *wlc_cm;
5b435de0 335 struct brcms_pub *pub = wlc->pub;
898d3c3b 336 struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
cf03c5da
SF
337 const char *ccode = sprom->alpha2;
338 int ccode_len = sizeof(sprom->alpha2);
5b435de0 339
5b435de0
AS
340 wlc_cm = kzalloc(sizeof(struct brcms_cm_info), GFP_ATOMIC);
341 if (wlc_cm == NULL)
342 return NULL;
343 wlc_cm->pub = pub;
344 wlc_cm->wlc = wlc;
345 wlc->cmi = wlc_cm;
346
347 /* store the country code for passing up as a regulatory hint */
cf03c5da
SF
348 wlc_cm->world_regd = brcms_world_regd(ccode, ccode_len);
349 if (brcms_c_country_valid(ccode))
350 strncpy(wlc->pub->srom_ccode, ccode, ccode_len);
351
352 /*
353 * If no custom world domain is found in the SROM, use the
354 * default "X2" domain.
355 */
356 if (!wlc_cm->world_regd) {
357 wlc_cm->world_regd = brcms_default_world_regd();
358 ccode = wlc_cm->world_regd->regdomain->alpha2;
359 ccode_len = BRCM_CNTRY_BUF_SZ - 1;
360 }
5b435de0 361
5b435de0 362 /* save default country for exiting 11d regulatory mode */
cf03c5da 363 strncpy(wlc->country_default, ccode, ccode_len);
5b435de0
AS
364
365 /* initialize autocountry_default to driver default */
cf03c5da 366 strncpy(wlc->autocountry_default, ccode, ccode_len);
5b435de0 367
cf03c5da 368 brcms_c_set_country(wlc_cm, wlc_cm->world_regd);
5b435de0
AS
369
370 return wlc_cm;
371}
372
373void brcms_c_channel_mgr_detach(struct brcms_cm_info *wlc_cm)
374{
375 kfree(wlc_cm);
376}
377
5b435de0
AS
378void
379brcms_c_channel_set_chanspec(struct brcms_cm_info *wlc_cm, u16 chanspec,
380 u8 local_constraint_qdbm)
381{
382 struct brcms_c_info *wlc = wlc_cm->wlc;
853346d8 383 struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel;
5b435de0
AS
384 struct txpwr_limits txpwr;
385
386 brcms_c_channel_reg_limits(wlc_cm, chanspec, &txpwr);
387
388 brcms_c_channel_min_txpower_limits_with_local_constraint(
389 wlc_cm, &txpwr, local_constraint_qdbm
390 );
391
edc7651f 392 /* set or restore gmode as required by regulatory */
7f38e5bc 393 if (ch->flags & IEEE80211_CHAN_NO_OFDM)
edc7651f
SF
394 brcms_c_set_gmode(wlc, GMODE_LEGACY_B, false);
395 else
396 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
397
5b435de0 398 brcms_b_set_chanspec(wlc->hw, chanspec,
853346d8 399 !!(ch->flags & IEEE80211_CHAN_PASSIVE_SCAN),
5b435de0
AS
400 &txpwr);
401}
402
5b435de0
AS
403void
404brcms_c_channel_reg_limits(struct brcms_cm_info *wlc_cm, u16 chanspec,
405 struct txpwr_limits *txpwr)
406{
407 struct brcms_c_info *wlc = wlc_cm->wlc;
2cf5089e 408 struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel;
5b435de0
AS
409 uint i;
410 uint chan;
411 int maxpwr;
412 int delta;
413 const struct country_info *country;
414 struct brcms_band *band;
5b435de0 415 int conducted_max = BRCMS_TXPWR_MAX;
5b435de0
AS
416 const struct locale_mimo_info *li_mimo;
417 int maxpwr20, maxpwr40;
418 int maxpwr_idx;
419 uint j;
420
421 memset(txpwr, 0, sizeof(struct txpwr_limits));
422
2cf5089e
SF
423 if (WARN_ON(!ch))
424 return;
425
cf03c5da 426 country = &wlc_cm->world_regd->country;
5b435de0
AS
427
428 chan = CHSPEC_CHANNEL(chanspec);
429 band = wlc->bandstate[chspec_bandunit(chanspec)];
5b435de0
AS
430 li_mimo = (band->bandtype == BRCM_BAND_5G) ?
431 brcms_c_get_mimo_5g(country->locale_mimo_5G) :
432 brcms_c_get_mimo_2g(country->locale_mimo_2G);
433
2cf5089e 434 delta = band->antgain;
5b435de0 435
edc7651f 436 if (band->bandtype == BRCM_BAND_2G)
5b435de0 437 conducted_max = QDB(22);
2cf5089e
SF
438
439 maxpwr = QDB(ch->max_power) - delta;
440 maxpwr = max(maxpwr, 0);
441 maxpwr = min(maxpwr, conducted_max);
5b435de0
AS
442
443 /* CCK txpwr limits for 2.4G band */
444 if (band->bandtype == BRCM_BAND_2G) {
5b435de0
AS
445 for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
446 txpwr->cck[i] = (u8) maxpwr;
447 }
448
2cf5089e 449 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++) {
5b435de0
AS
450 txpwr->ofdm[i] = (u8) maxpwr;
451
5b435de0
AS
452 /*
453 * OFDM 40 MHz SISO has the same power as the corresponding
454 * MCS0-7 rate unless overriden by the locale specific code.
455 * We set this value to 0 as a flag (presumably 0 dBm isn't
456 * a possibility) and then copy the MCS0-7 value to the 40 MHz
457 * value if it wasn't explicitly set.
458 */
459 txpwr->ofdm_40_siso[i] = 0;
460
461 txpwr->ofdm_cdd[i] = (u8) maxpwr;
462
463 txpwr->ofdm_40_cdd[i] = 0;
464 }
465
2cf5089e
SF
466 delta = 0;
467 if (band->antgain > QDB(6))
468 delta = band->antgain - QDB(6); /* Excess over 6 dB */
5b435de0
AS
469
470 if (band->bandtype == BRCM_BAND_2G)
471 maxpwr_idx = (chan - 1);
472 else
473 maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
474
475 maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
476 maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
477
478 maxpwr20 = maxpwr20 - delta;
479 maxpwr20 = max(maxpwr20, 0);
480 maxpwr40 = maxpwr40 - delta;
481 maxpwr40 = max(maxpwr40, 0);
482
483 /* Fill in the MCS 0-7 (SISO) rates */
484 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
485
486 /*
487 * 20 MHz has the same power as the corresponding OFDM rate
488 * unless overriden by the locale specific code.
489 */
490 txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
491 txpwr->mcs_40_siso[i] = 0;
492 }
493
494 /* Fill in the MCS 0-7 CDD rates */
495 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
496 txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
497 txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
498 }
499
500 /*
501 * These locales have SISO expressed in the
502 * table and override CDD later
503 */
504 if (li_mimo == &locale_bn) {
505 if (li_mimo == &locale_bn) {
506 maxpwr20 = QDB(16);
507 maxpwr40 = 0;
508
509 if (chan >= 3 && chan <= 11)
510 maxpwr40 = QDB(16);
511 }
512
513 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
514 txpwr->mcs_20_siso[i] = (u8) maxpwr20;
515 txpwr->mcs_40_siso[i] = (u8) maxpwr40;
516 }
517 }
518
519 /* Fill in the MCS 0-7 STBC rates */
520 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
521 txpwr->mcs_20_stbc[i] = 0;
522 txpwr->mcs_40_stbc[i] = 0;
523 }
524
525 /* Fill in the MCS 8-15 SDM rates */
526 for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++) {
527 txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
528 txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
529 }
530
531 /* Fill in MCS32 */
532 txpwr->mcs32 = (u8) maxpwr40;
533
534 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
535 if (txpwr->ofdm_40_cdd[i] == 0)
536 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
537 if (i == 0) {
538 i = i + 1;
539 if (txpwr->ofdm_40_cdd[i] == 0)
540 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
541 }
542 }
543
544 /*
545 * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
546 * value if it wasn't provided explicitly.
547 */
548 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
549 if (txpwr->mcs_40_siso[i] == 0)
550 txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
551 }
552
553 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
554 if (txpwr->ofdm_40_siso[i] == 0)
555 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
556 if (i == 0) {
557 i = i + 1;
558 if (txpwr->ofdm_40_siso[i] == 0)
559 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
560 }
561 }
562
563 /*
564 * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
565 * STBC values if they weren't provided explicitly.
566 */
567 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
568 if (txpwr->mcs_20_stbc[i] == 0)
569 txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
570
571 if (txpwr->mcs_40_stbc[i] == 0)
572 txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
573 }
574
5b435de0
AS
575 return;
576}
577
3de67818
AB
578/*
579 * Verify the chanspec is using a legal set of parameters, i.e. that the
580 * chanspec specified a band, bw, ctl_sb and channel and that the
581 * combination could be legal given any set of circumstances.
582 * RETURNS: true is the chanspec is malformed, false if it looks good.
583 */
584static bool brcms_c_chspec_malformed(u16 chanspec)
585{
586 /* must be 2G or 5G band */
587 if (!CHSPEC_IS5G(chanspec) && !CHSPEC_IS2G(chanspec))
588 return true;
589 /* must be 20 or 40 bandwidth */
590 if (!CHSPEC_IS40(chanspec) && !CHSPEC_IS20(chanspec))
591 return true;
592
593 /* 20MHZ b/w must have no ctl sb, 40 must have a ctl sb */
594 if (CHSPEC_IS20(chanspec)) {
595 if (!CHSPEC_SB_NONE(chanspec))
596 return true;
597 } else if (!CHSPEC_SB_UPPER(chanspec) && !CHSPEC_SB_LOWER(chanspec)) {
598 return true;
599 }
600
601 return false;
602}
603
5b435de0
AS
604/*
605 * Validate the chanspec for this locale, for 40MHZ we need to also
606 * check that the sidebands are valid 20MZH channels in this locale
607 * and they are also a legal HT combination
608 */
609static bool
853346d8 610brcms_c_valid_chanspec_ext(struct brcms_cm_info *wlc_cm, u16 chspec)
5b435de0
AS
611{
612 struct brcms_c_info *wlc = wlc_cm->wlc;
613 u8 channel = CHSPEC_CHANNEL(chspec);
614
615 /* check the chanspec */
3de67818 616 if (brcms_c_chspec_malformed(chspec)) {
b353dda4
SF
617 brcms_err(wlc->hw->d11core, "wl%d: malformed chanspec 0x%x\n",
618 wlc->pub->unit, chspec);
5b435de0
AS
619 return false;
620 }
621
622 if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
623 chspec_bandunit(chspec))
624 return false;
625
853346d8 626 return true;
5b435de0
AS
627}
628
629bool brcms_c_valid_chanspec_db(struct brcms_cm_info *wlc_cm, u16 chspec)
630{
853346d8 631 return brcms_c_valid_chanspec_ext(wlc_cm, chspec);
5b435de0 632}
cf03c5da
SF
633
634static bool brcms_is_radar_freq(u16 center_freq)
635{
636 return center_freq >= 5260 && center_freq <= 5700;
637}
638
639static void brcms_reg_apply_radar_flags(struct wiphy *wiphy)
640{
641 struct ieee80211_supported_band *sband;
642 struct ieee80211_channel *ch;
643 int i;
644
645 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
646 if (!sband)
647 return;
648
649 for (i = 0; i < sband->n_channels; i++) {
650 ch = &sband->channels[i];
651
652 if (!brcms_is_radar_freq(ch->center_freq))
653 continue;
654
655 /*
656 * All channels in this range should be passive and have
657 * DFS enabled.
658 */
659 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
660 ch->flags |= IEEE80211_CHAN_RADAR |
661 IEEE80211_CHAN_NO_IBSS |
662 IEEE80211_CHAN_PASSIVE_SCAN;
663 }
664}
665
666static void
667brcms_reg_apply_beaconing_flags(struct wiphy *wiphy,
668 enum nl80211_reg_initiator initiator)
669{
670 struct ieee80211_supported_band *sband;
671 struct ieee80211_channel *ch;
672 const struct ieee80211_reg_rule *rule;
361c9c8b 673 int band, i;
cf03c5da
SF
674
675 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
676 sband = wiphy->bands[band];
677 if (!sband)
678 continue;
679
680 for (i = 0; i < sband->n_channels; i++) {
681 ch = &sband->channels[i];
682
683 if (ch->flags &
684 (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_RADAR))
685 continue;
686
687 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
361c9c8b
JB
688 rule = freq_reg_info(wiphy, ch->center_freq);
689 if (IS_ERR(rule))
cf03c5da
SF
690 continue;
691
692 if (!(rule->flags & NL80211_RRF_NO_IBSS))
693 ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
694 if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
695 ch->flags &=
696 ~IEEE80211_CHAN_PASSIVE_SCAN;
697 } else if (ch->beacon_found) {
698 ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
699 IEEE80211_CHAN_PASSIVE_SCAN);
700 }
701 }
702 }
703}
704
0c0280bd
LR
705static void brcms_reg_notifier(struct wiphy *wiphy,
706 struct regulatory_request *request)
cf03c5da
SF
707{
708 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
709 struct brcms_info *wl = hw->priv;
710 struct brcms_c_info *wlc = wl->wlc;
2ab631f4
SF
711 struct ieee80211_supported_band *sband;
712 struct ieee80211_channel *ch;
713 int band, i;
714 bool ch_found = false;
cf03c5da
SF
715
716 brcms_reg_apply_radar_flags(wiphy);
717
718 if (request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
719 brcms_reg_apply_beaconing_flags(wiphy, request->initiator);
720
2ab631f4
SF
721 /* Disable radio if all channels disallowed by regulatory */
722 for (band = 0; !ch_found && band < IEEE80211_NUM_BANDS; band++) {
723 sband = wiphy->bands[band];
724 if (!sband)
725 continue;
726
727 for (i = 0; !ch_found && i < sband->n_channels; i++) {
728 ch = &sband->channels[i];
729
730 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
731 ch_found = true;
732 }
733 }
734
735 if (ch_found) {
736 mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
737 } else {
738 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
b353dda4
SF
739 brcms_err(wlc->hw->d11core,
740 "wl%d: %s: no valid channel for \"%s\"\n",
2ab631f4
SF
741 wlc->pub->unit, __func__, request->alpha2);
742 }
743
cf03c5da
SF
744 if (wlc->pub->_nbands > 1 || wlc->band->bandtype == BRCM_BAND_2G)
745 wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
746 brcms_c_japan_ccode(request->alpha2));
cf03c5da
SF
747}
748
749void brcms_c_regd_init(struct brcms_c_info *wlc)
750{
751 struct wiphy *wiphy = wlc->wiphy;
752 const struct brcms_regd *regd = wlc->cmi->world_regd;
753 struct ieee80211_supported_band *sband;
754 struct ieee80211_channel *ch;
755 struct brcms_chanvec sup_chan;
756 struct brcms_band *band;
757 int band_idx, i;
758
759 /* Disable any channels not supported by the phy */
32c336a5
AS
760 for (band_idx = 0; band_idx < wlc->pub->_nbands; band_idx++) {
761 band = wlc->bandstate[band_idx];
c49aa4aa 762
cf03c5da
SF
763 wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
764 &sup_chan);
765
32c336a5
AS
766 if (band_idx == BAND_2G_INDEX)
767 sband = wiphy->bands[IEEE80211_BAND_2GHZ];
768 else
769 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
770
cf03c5da
SF
771 for (i = 0; i < sband->n_channels; i++) {
772 ch = &sband->channels[i];
773 if (!isset(sup_chan.vec, ch->hw_value))
774 ch->flags |= IEEE80211_CHAN_DISABLED;
775 }
776 }
777
778 wlc->wiphy->reg_notifier = brcms_reg_notifier;
779 wlc->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
780 WIPHY_FLAG_STRICT_REGULATORY;
781 wiphy_apply_custom_regulatory(wlc->wiphy, regd->regdomain);
782 brcms_reg_apply_beaconing_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER);
783}