]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/brcm80211/sys/wlc_channel.c
Staging: brcm80211: remove broken MIN() implementation
[net-next-2.6.git] / drivers / staging / brcm80211 / sys / wlc_channel.c
CommitLineData
a9533e7e
HP
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 <wlc_cfg.h>
18#include <typedefs.h>
19#include <bcmdefs.h>
20#include <osl.h>
3327989a
BR
21#include <linux/kernel.h>
22#include <linux/string.h>
23#include <linuxver.h>
a9533e7e
HP
24#include <bcmutils.h>
25#include <siutils.h>
26#include <wlioctl.h>
27#include <wlc_pub.h>
28#include <wlc_key.h>
29#include <wlc_mac80211.h>
30#include <wlc_bmac.h>
31#include <wlc_stf.h>
32#include <wlc_channel.h>
33
34typedef struct wlc_cm_band {
41feb5ed 35 u8 locale_flags; /* locale_info_t flags */
a9533e7e
HP
36 chanvec_t valid_channels; /* List of valid channels in the country */
37 const chanvec_t *restricted_channels; /* List of restricted use channels */
38 const chanvec_t *radar_channels; /* List of radar sensitive channels */
41feb5ed 39 u8 PAD[8];
a9533e7e
HP
40} wlc_cm_band_t;
41
42struct wlc_cm_info {
43 wlc_pub_t *pub;
44 wlc_info_t *wlc;
45 char srom_ccode[WLC_CNTRY_BUF_SZ]; /* Country Code in SROM */
46 uint srom_regrev; /* Regulatory Rev for the SROM ccode */
47 const country_info_t *country; /* current country def */
48 char ccode[WLC_CNTRY_BUF_SZ]; /* current internal Country Code */
49 uint regrev; /* current Regulatory Revision */
50 char country_abbrev[WLC_CNTRY_BUF_SZ]; /* current advertised ccode */
51 wlc_cm_band_t bandstate[MAXBANDS]; /* per-band state (one per phy/radio) */
52 /* quiet channels currently for radar sensitivity or 11h support */
53 chanvec_t quiet_channels; /* channels on which we cannot transmit */
54};
55
7cc4a4c0
JC
56static int wlc_channels_init(wlc_cm_info_t *wlc_cm,
57 const country_info_t *country);
58static void wlc_set_country_common(wlc_cm_info_t *wlc_cm,
a9533e7e
HP
59 const char *country_abbrev,
60 const char *ccode, uint regrev,
7cc4a4c0
JC
61 const country_info_t *country);
62static int wlc_country_aggregate_map(wlc_cm_info_t *wlc_cm, const char *ccode,
63 char *mapped_ccode, uint *mapped_regrev);
a9533e7e
HP
64static const country_info_t *wlc_country_lookup_direct(const char *ccode,
65 uint regrev);
7cc4a4c0 66static const country_info_t *wlc_countrycode_map(wlc_cm_info_t *wlc_cm,
a9533e7e
HP
67 const char *ccode,
68 char *mapped_ccode,
7cc4a4c0
JC
69 uint *mapped_regrev);
70static void wlc_channels_commit(wlc_cm_info_t *wlc_cm);
a9533e7e
HP
71static bool wlc_japan_ccode(const char *ccode);
72static void wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t *
73 wlc_cm,
74 struct
75 txpwr_limits
76 *txpwr,
41feb5ed 77 u8
a9533e7e 78 local_constraint_qdbm);
7cc4a4c0 79void wlc_locale_add_channels(chanvec_t *target, const chanvec_t *channels);
41feb5ed
GKH
80static const locale_mimo_info_t *wlc_get_mimo_2g(u8 locale_idx);
81static const locale_mimo_info_t *wlc_get_mimo_5g(u8 locale_idx);
a9533e7e
HP
82
83/* QDB() macro takes a dB value and converts to a quarter dB value */
84#ifdef QDB
85#undef QDB
86#endif
87#define QDB(n) ((n) * WLC_TXPWR_DB_FACTOR)
88
89/* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
90
91/*
92 * Some common channel sets
93 */
94
95/* No channels */
96static const chanvec_t chanvec_none = {
97 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00}
101};
102
103/* All 2.4 GHz HW channels */
104const chanvec_t chanvec_all_2G = {
105 {0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00}
109};
110
111/* All 5 GHz HW channels */
112const chanvec_t chanvec_all_5G = {
113 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x11, 0x11,
114 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11,
115 0x11, 0x11, 0x20, 0x22, 0x22, 0x00, 0x00, 0x11,
116 0x11, 0x11, 0x11, 0x01}
117};
118
119/*
120 * Radar channel sets
121 */
122
123/* No radar */
124#define radar_set_none chanvec_none
125
126static const chanvec_t radar_set1 = { /* Channels 52 - 64, 100 - 140 */
127 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, /* 52 - 60 */
128 0x01, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x11, /* 64, 100 - 124 */
129 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128 - 140 */
130 0x00, 0x00, 0x00, 0x00}
131};
132
133/*
134 * Restricted channel sets
135 */
136
137#define restricted_set_none chanvec_none
138
139/* Channels 34, 38, 42, 46 */
140static const chanvec_t restricted_set_japan_legacy = {
141 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 0x00, 0x00, 0x00, 0x00}
145};
146
147/* Channels 12, 13 */
148static const chanvec_t restricted_set_2g_short = {
149 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00}
153};
154
155/* Channel 165 */
156static const chanvec_t restricted_chan_165 = {
157 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00}
161};
162
163/* Channels 36 - 48 & 149 - 165 */
164static const chanvec_t restricted_low_hi = {
165 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x20, 0x22, 0x22, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00}
169};
170
171/* Channels 12 - 14 */
172static const chanvec_t restricted_set_12_13_14 = {
173 {0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0x00}
177};
178
179#define LOCALE_CHAN_01_11 (1<<0)
180#define LOCALE_CHAN_12_13 (1<<1)
181#define LOCALE_CHAN_14 (1<<2)
182#define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
183#define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
184#define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
185#define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
186#define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
187#define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
188#define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
189#define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
190#define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
191#define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
192#define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
193#define LOCALE_CHAN_52_140_ALL (1<<14)
194#define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
195
0d706ef4
JC
196#define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
197#define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
198#define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
a9533e7e 199#define LOCALE_CHAN_100_140 \
0d706ef4
JC
200 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
201#define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
a9533e7e
HP
202#define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
203
204#define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13 | LOCALE_CHAN_14)
205
206#define LOCALE_RADAR_SET_NONE 0
207#define LOCALE_RADAR_SET_1 1
208
209#define LOCALE_RESTRICTED_NONE 0
210#define LOCALE_RESTRICTED_SET_2G_SHORT 1
211#define LOCALE_RESTRICTED_CHAN_165 2
212#define LOCALE_CHAN_ALL_5G 3
213#define LOCALE_RESTRICTED_JAPAN_LEGACY 4
214#define LOCALE_RESTRICTED_11D_2G 5
215#define LOCALE_RESTRICTED_11D_5G 6
216#define LOCALE_RESTRICTED_LOW_HI 7
217#define LOCALE_RESTRICTED_12_13_14 8
218
219/* global memory to provide working buffer for expanded locale */
220
221static const chanvec_t *g_table_radar_set[] = {
222 &chanvec_none,
223 &radar_set1
224};
225
226static const chanvec_t *g_table_restricted_chan[] = {
227 &chanvec_none, /* restricted_set_none */
228 &restricted_set_2g_short,
229 &restricted_chan_165,
230 &chanvec_all_5G,
231 &restricted_set_japan_legacy,
232 &chanvec_all_2G, /* restricted_set_11d_2G */
233 &chanvec_all_5G, /* restricted_set_11d_5G */
234 &restricted_low_hi,
235 &restricted_set_12_13_14
236};
237
238static const chanvec_t locale_2g_01_11 = {
239 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00}
243};
244
245static const chanvec_t locale_2g_12_13 = {
246 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00}
250};
251
252static const chanvec_t locale_2g_14 = {
253 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00}
257};
258
259static const chanvec_t locale_5g_LOW_JP1 = {
260 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00}
264};
265
266static const chanvec_t locale_5g_LOW_JP2 = {
267 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00}
271};
272
273static const chanvec_t locale_5g_LOW1 = {
274 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00}
278};
279
280static const chanvec_t locale_5g_LOW2 = {
281 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00}
285};
286
287static const chanvec_t locale_5g_LOW3 = {
288 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
289 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0x00, 0x00, 0x00, 0x00}
292};
293
294static const chanvec_t locale_5g_MID1 = {
295 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 0x00, 0x00, 0x00, 0x00}
299};
300
301static const chanvec_t locale_5g_MID2 = {
302 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00}
306};
307
308static const chanvec_t locale_5g_MID3 = {
309 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00}
313};
314
315static const chanvec_t locale_5g_HIGH1 = {
316 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x00, 0x00, 0x00, 0x00}
320};
321
322static const chanvec_t locale_5g_HIGH2 = {
323 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
326 0x00, 0x00, 0x00, 0x00}
327};
328
329static const chanvec_t locale_5g_HIGH3 = {
330 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
333 0x00, 0x00, 0x00, 0x00}
334};
335
336static const chanvec_t locale_5g_52_140_ALL = {
337 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
338 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
339 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
340 0x00, 0x00, 0x00, 0x00}
341};
342
343static const chanvec_t locale_5g_HIGH4 = {
344 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
347 0x11, 0x11, 0x11, 0x11}
348};
349
350static const chanvec_t *g_table_locale_base[] = {
351 &locale_2g_01_11,
352 &locale_2g_12_13,
353 &locale_2g_14,
354 &locale_5g_LOW_JP1,
355 &locale_5g_LOW_JP2,
356 &locale_5g_LOW1,
357 &locale_5g_LOW2,
358 &locale_5g_LOW3,
359 &locale_5g_MID1,
360 &locale_5g_MID2,
361 &locale_5g_MID3,
362 &locale_5g_HIGH1,
363 &locale_5g_HIGH2,
364 &locale_5g_HIGH3,
365 &locale_5g_52_140_ALL,
366 &locale_5g_HIGH4
367};
368
7cc4a4c0 369void wlc_locale_add_channels(chanvec_t *target, const chanvec_t *channels)
a9533e7e 370{
41feb5ed 371 u8 i;
a9533e7e
HP
372 for (i = 0; i < sizeof(chanvec_t); i++) {
373 target->vec[i] |= channels->vec[i];
374 }
375}
376
7cc4a4c0 377void wlc_locale_get_channels(const locale_info_t *locale, chanvec_t *channels)
a9533e7e 378{
41feb5ed 379 u8 i;
a9533e7e
HP
380
381 bzero(channels, sizeof(chanvec_t));
382
383 for (i = 0; i < ARRAYSIZE(g_table_locale_base); i++) {
384 if (locale->valid_channels & (1 << i)) {
385 wlc_locale_add_channels(channels,
386 g_table_locale_base[i]);
387 }
388 }
389}
390
391/*
392 * Locale Definitions - 2.4 GHz
393 */
394static const locale_info_t locale_i = { /* locale i. channel 1 - 13 */
395 LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13,
396 LOCALE_RADAR_SET_NONE,
397 LOCALE_RESTRICTED_SET_2G_SHORT,
398 {QDB(19), QDB(19), QDB(19),
399 QDB(19), QDB(19), QDB(19)},
400 {20, 20, 20, 0},
401 WLC_EIRP
402};
403
404/*
405 * Locale Definitions - 5 GHz
406 */
407static const locale_info_t locale_11 = {
408 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
409 LOCALE_CHAN_36_64 | LOCALE_CHAN_100_140 | LOCALE_CHAN_149_165,
410 LOCALE_RADAR_SET_1,
411 LOCALE_RESTRICTED_NONE,
412 {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
413 {23, 23, 23, 30, 30},
414 WLC_EIRP | WLC_DFS_EU
415};
416
417#define LOCALE_2G_IDX_i 0
418static const locale_info_t *g_locale_2g_table[] = {
419 &locale_i
420};
421
422#define LOCALE_5G_IDX_11 0
423static const locale_info_t *g_locale_5g_table[] = {
424 &locale_11
425};
426
427/*
428 * MIMO Locale Definitions - 2.4 GHz
429 */
430static const locale_mimo_info_t locale_bn = {
431 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
432 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
433 QDB(13), QDB(13), QDB(13)},
434 {0, 0, QDB(13), QDB(13), QDB(13),
435 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
436 QDB(13), 0, 0},
437 0
438};
439
440/* locale mimo 2g indexes */
441#define LOCALE_MIMO_IDX_bn 0
442
443static const locale_mimo_info_t *g_mimo_2g_table[] = {
444 &locale_bn
445};
446
447/*
448 * MIMO Locale Definitions - 5 GHz
449 */
450static const locale_mimo_info_t locale_11n = {
451 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
452 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
453 0
454};
455
456#define LOCALE_MIMO_IDX_11n 0
457static const locale_mimo_info_t *g_mimo_5g_table[] = {
458 &locale_11n
459};
460
461#ifdef LC
462#undef LC
463#endif
464#define LC(id) LOCALE_MIMO_IDX_ ## id
465
466#ifdef LC_2G
467#undef LC_2G
468#endif
469#define LC_2G(id) LOCALE_2G_IDX_ ## id
470
471#ifdef LC_5G
472#undef LC_5G
473#endif
474#define LC_5G(id) LOCALE_5G_IDX_ ## id
475
476#define LOCALES(band2, band5, mimo2, mimo5) {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
477
478static const struct {
479 char abbrev[WLC_CNTRY_BUF_SZ]; /* country abbreviation */
480 country_info_t country;
481} cntry_locales[] = {
482 {
483 "X2", LOCALES(i, 11, bn, 11n)}, /* Worldwide RoW 2 */
484};
485
486#ifdef SUPPORT_40MHZ
487/* 20MHz channel info for 40MHz pairing support */
488struct chan20_info {
41feb5ed
GKH
489 u8 sb;
490 u8 adj_sbs;
a9533e7e
HP
491};
492
493/* indicates adjacent channels that are allowed for a 40 Mhz channel and
494 * those that permitted by the HT
495 */
496struct chan20_info chan20_info[] = {
497 /* 11b/11g */
498/* 0 */ {1, (CH_UPPER_SB | CH_EWA_VALID)},
499/* 1 */ {2, (CH_UPPER_SB | CH_EWA_VALID)},
500/* 2 */ {3, (CH_UPPER_SB | CH_EWA_VALID)},
501/* 3 */ {4, (CH_UPPER_SB | CH_EWA_VALID)},
502/* 4 */ {5, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
503/* 5 */ {6, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
504/* 6 */ {7, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
505/* 7 */ {8, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
506/* 8 */ {9, (CH_UPPER_SB | CH_LOWER_SB | CH_EWA_VALID)},
507/* 9 */ {10, (CH_LOWER_SB | CH_EWA_VALID)},
508/* 10 */ {11, (CH_LOWER_SB | CH_EWA_VALID)},
509/* 11 */ {12, (CH_LOWER_SB)},
510/* 12 */ {13, (CH_LOWER_SB)},
511/* 13 */ {14, (CH_LOWER_SB)},
512
513/* 11a japan high */
514/* 14 */ {34, (CH_UPPER_SB)},
515/* 15 */ {38, (CH_LOWER_SB)},
516/* 16 */ {42, (CH_LOWER_SB)},
517/* 17 */ {46, (CH_LOWER_SB)},
518
519/* 11a usa low */
520/* 18 */ {36, (CH_UPPER_SB | CH_EWA_VALID)},
521/* 19 */ {40, (CH_LOWER_SB | CH_EWA_VALID)},
522/* 20 */ {44, (CH_UPPER_SB | CH_EWA_VALID)},
523/* 21 */ {48, (CH_LOWER_SB | CH_EWA_VALID)},
524/* 22 */ {52, (CH_UPPER_SB | CH_EWA_VALID)},
525/* 23 */ {56, (CH_LOWER_SB | CH_EWA_VALID)},
526/* 24 */ {60, (CH_UPPER_SB | CH_EWA_VALID)},
527/* 25 */ {64, (CH_LOWER_SB | CH_EWA_VALID)},
528
529/* 11a Europe */
530/* 26 */ {100, (CH_UPPER_SB | CH_EWA_VALID)},
531/* 27 */ {104, (CH_LOWER_SB | CH_EWA_VALID)},
532/* 28 */ {108, (CH_UPPER_SB | CH_EWA_VALID)},
533/* 29 */ {112, (CH_LOWER_SB | CH_EWA_VALID)},
534/* 30 */ {116, (CH_UPPER_SB | CH_EWA_VALID)},
535/* 31 */ {120, (CH_LOWER_SB | CH_EWA_VALID)},
536/* 32 */ {124, (CH_UPPER_SB | CH_EWA_VALID)},
537/* 33 */ {128, (CH_LOWER_SB | CH_EWA_VALID)},
538/* 34 */ {132, (CH_UPPER_SB | CH_EWA_VALID)},
539/* 35 */ {136, (CH_LOWER_SB | CH_EWA_VALID)},
540/* 36 */ {140, (CH_LOWER_SB)},
541
542/* 11a usa high, ref5 only */
543/* The 0x80 bit in pdiv means these are REF5, other entries are REF20 */
544/* 37 */ {149, (CH_UPPER_SB | CH_EWA_VALID)},
545/* 38 */ {153, (CH_LOWER_SB | CH_EWA_VALID)},
546/* 39 */ {157, (CH_UPPER_SB | CH_EWA_VALID)},
547/* 40 */ {161, (CH_LOWER_SB | CH_EWA_VALID)},
548/* 41 */ {165, (CH_LOWER_SB)},
549
550/* 11a japan */
551/* 42 */ {184, (CH_UPPER_SB)},
552/* 43 */ {188, (CH_LOWER_SB)},
553/* 44 */ {192, (CH_UPPER_SB)},
554/* 45 */ {196, (CH_LOWER_SB)},
555/* 46 */ {200, (CH_UPPER_SB)},
556/* 47 */ {204, (CH_LOWER_SB)},
557/* 48 */ {208, (CH_UPPER_SB)},
558/* 49 */ {212, (CH_LOWER_SB)},
559/* 50 */ {216, (CH_LOWER_SB)}
560};
561#endif /* SUPPORT_40MHZ */
562
41feb5ed 563const locale_info_t *wlc_get_locale_2g(u8 locale_idx)
a9533e7e
HP
564{
565 if (locale_idx >= ARRAYSIZE(g_locale_2g_table)) {
566 WL_ERROR(("%s: locale 2g index size out of range %d\n",
567 __func__, locale_idx));
568 ASSERT(locale_idx < ARRAYSIZE(g_locale_2g_table));
569 return NULL;
570 }
571 return g_locale_2g_table[locale_idx];
572}
573
41feb5ed 574const locale_info_t *wlc_get_locale_5g(u8 locale_idx)
a9533e7e
HP
575{
576 if (locale_idx >= ARRAYSIZE(g_locale_5g_table)) {
577 WL_ERROR(("%s: locale 5g index size out of range %d\n",
578 __func__, locale_idx));
579 ASSERT(locale_idx < ARRAYSIZE(g_locale_5g_table));
580 return NULL;
581 }
582 return g_locale_5g_table[locale_idx];
583}
584
41feb5ed 585const locale_mimo_info_t *wlc_get_mimo_2g(u8 locale_idx)
a9533e7e
HP
586{
587 if (locale_idx >= ARRAYSIZE(g_mimo_2g_table)) {
588 WL_ERROR(("%s: mimo 2g index size out of range %d\n", __func__,
589 locale_idx));
590 return NULL;
591 }
592 return g_mimo_2g_table[locale_idx];
593}
594
41feb5ed 595const locale_mimo_info_t *wlc_get_mimo_5g(u8 locale_idx)
a9533e7e
HP
596{
597 if (locale_idx >= ARRAYSIZE(g_mimo_5g_table)) {
598 WL_ERROR(("%s: mimo 5g index size out of range %d\n", __func__,
599 locale_idx));
600 return NULL;
601 }
602 return g_mimo_5g_table[locale_idx];
603}
604
a2627bc0
JC
605wlc_cm_info_t *BCMATTACHFN(wlc_channel_mgr_attach) (wlc_info_t *wlc)
606{
a9533e7e
HP
607 wlc_cm_info_t *wlc_cm;
608 char country_abbrev[WLC_CNTRY_BUF_SZ];
609 const country_info_t *country;
610 wlc_pub_t *pub = wlc->pub;
611 char *ccode;
612
613 WL_TRACE(("wl%d: wlc_channel_mgr_attach\n", wlc->pub->unit));
614
ca8c1e59
JC
615 wlc_cm = (wlc_cm_info_t *) MALLOC(pub->osh, sizeof(wlc_cm_info_t));
616 if (wlc_cm == NULL) {
a9533e7e
HP
617 WL_ERROR(("wl%d: %s: out of memory, malloced %d bytes",
618 pub->unit, __func__, MALLOCED(pub->osh)));
619 return NULL;
620 }
621 bzero((char *)wlc_cm, sizeof(wlc_cm_info_t));
622 wlc_cm->pub = pub;
623 wlc_cm->wlc = wlc;
624 wlc->cmi = wlc_cm;
625
626 /* store the country code for passing up as a regulatory hint */
627 ccode = getvar(wlc->pub->vars, "ccode");
628 if (ccode) {
629 strncpy(wlc->pub->srom_ccode, ccode, WLC_CNTRY_BUF_SZ - 1);
630 WL_NONE(("%s: SROM country code is %c%c\n", __func__,
631 wlc->pub->srom_ccode[0], wlc->pub->srom_ccode[1]));
632 }
633
634 /* internal country information which must match regulatory constraints in firmware */
635 bzero(country_abbrev, WLC_CNTRY_BUF_SZ);
636 strncpy(country_abbrev, "X2", sizeof(country_abbrev) - 1);
637 country = wlc_country_lookup(wlc, country_abbrev);
638
639 ASSERT(country != NULL);
640
641 /* save default country for exiting 11d regulatory mode */
642 strncpy(wlc->country_default, country_abbrev, WLC_CNTRY_BUF_SZ - 1);
643
644 /* initialize autocountry_default to driver default */
645 strncpy(wlc->autocountry_default, "X2", WLC_CNTRY_BUF_SZ - 1);
646
647 wlc_set_countrycode(wlc_cm, country_abbrev);
648
649 return wlc_cm;
650}
651
a2627bc0
JC
652void BCMATTACHFN(wlc_channel_mgr_detach) (wlc_cm_info_t *wlc_cm)
653{
a9533e7e
HP
654 if (wlc_cm)
655 MFREE(wlc_cm->pub->osh, wlc_cm, sizeof(wlc_cm_info_t));
656}
657
7cc4a4c0 658const char *wlc_channel_country_abbrev(wlc_cm_info_t *wlc_cm)
a9533e7e
HP
659{
660 return wlc_cm->country_abbrev;
661}
662
41feb5ed 663u8 wlc_channel_locale_flags(wlc_cm_info_t *wlc_cm)
a9533e7e
HP
664{
665 wlc_info_t *wlc = wlc_cm->wlc;
666
667 return wlc_cm->bandstate[wlc->band->bandunit].locale_flags;
668}
669
41feb5ed 670u8 wlc_channel_locale_flags_in_band(wlc_cm_info_t *wlc_cm, uint bandunit)
a9533e7e
HP
671{
672 return wlc_cm->bandstate[bandunit].locale_flags;
673}
674
675/* return chanvec for a given country code and band */
676bool
7cc4a4c0
JC
677wlc_channel_get_chanvec(struct wlc_info *wlc, const char *country_abbrev,
678 int bandtype, chanvec_t *channels)
a9533e7e
HP
679{
680 const country_info_t *country;
681 const locale_info_t *locale = NULL;
682
683 country = wlc_country_lookup(wlc, country_abbrev);
684 if (country == NULL)
685 return FALSE;
686
687 if (bandtype == WLC_BAND_2G)
688 locale = wlc_get_locale_2g(country->locale_2G);
689 else if (bandtype == WLC_BAND_5G)
690 locale = wlc_get_locale_5g(country->locale_5G);
691 if (locale == NULL)
692 return FALSE;
693
694 wlc_locale_get_channels(locale, channels);
695 return TRUE;
696}
697
698/* set the driver's current country and regulatory information using a country code
699 * as the source. Lookup built in country information found with the country code.
700 */
7cc4a4c0 701int wlc_set_countrycode(wlc_cm_info_t *wlc_cm, const char *ccode)
a9533e7e
HP
702{
703 char country_abbrev[WLC_CNTRY_BUF_SZ];
704 strncpy(country_abbrev, ccode, WLC_CNTRY_BUF_SZ);
705 return wlc_set_countrycode_rev(wlc_cm, country_abbrev, ccode, -1);
706}
707
708int
7cc4a4c0 709wlc_set_countrycode_rev(wlc_cm_info_t *wlc_cm,
a9533e7e
HP
710 const char *country_abbrev,
711 const char *ccode, int regrev)
712{
713 const country_info_t *country;
714 char mapped_ccode[WLC_CNTRY_BUF_SZ];
715 uint mapped_regrev;
716
717 WL_NONE(("%s: (country_abbrev \"%s\", ccode \"%s\", regrev %d) SPROM \"%s\"/%u\n", __func__, country_abbrev, ccode, regrev, wlc_cm->srom_ccode, wlc_cm->srom_regrev));
718
719 /* if regrev is -1, lookup the mapped country code,
720 * otherwise use the ccode and regrev directly
721 */
722 if (regrev == -1) {
723 /* map the country code to a built-in country code, regrev, and country_info */
724 country =
725 wlc_countrycode_map(wlc_cm, ccode, mapped_ccode,
726 &mapped_regrev);
727 } else {
728 /* find the matching built-in country definition */
729 ASSERT(0);
730 country = wlc_country_lookup_direct(ccode, regrev);
731 strncpy(mapped_ccode, ccode, WLC_CNTRY_BUF_SZ);
732 mapped_regrev = regrev;
733 }
734
735 if (country == NULL)
736 return BCME_BADARG;
737
738 /* set the driver state for the country */
739 wlc_set_country_common(wlc_cm, country_abbrev, mapped_ccode,
740 mapped_regrev, country);
741
742 return 0;
743}
744
745/* set the driver's current country and regulatory information using a country code
746 * as the source. Look up built in country information found with the country code.
747 */
748static void
7cc4a4c0 749wlc_set_country_common(wlc_cm_info_t *wlc_cm,
a9533e7e
HP
750 const char *country_abbrev,
751 const char *ccode, uint regrev,
7cc4a4c0 752 const country_info_t *country)
a9533e7e
HP
753{
754 const locale_mimo_info_t *li_mimo;
755 const locale_info_t *locale;
756 wlc_info_t *wlc = wlc_cm->wlc;
757 char prev_country_abbrev[WLC_CNTRY_BUF_SZ];
758
759 ASSERT(country != NULL);
760
761 /* save current country state */
762 wlc_cm->country = country;
763
764 bzero(&prev_country_abbrev, WLC_CNTRY_BUF_SZ);
765 strncpy(prev_country_abbrev, wlc_cm->country_abbrev,
766 WLC_CNTRY_BUF_SZ - 1);
767
768 strncpy(wlc_cm->country_abbrev, country_abbrev, WLC_CNTRY_BUF_SZ - 1);
769 strncpy(wlc_cm->ccode, ccode, WLC_CNTRY_BUF_SZ - 1);
770 wlc_cm->regrev = regrev;
771
772 /* disable/restore nmode based on country regulations */
773 li_mimo = wlc_get_mimo_2g(country->locale_mimo_2G);
774 if (li_mimo && (li_mimo->flags & WLC_NO_MIMO)) {
775 wlc_set_nmode(wlc, OFF);
776 wlc->stf->no_cddstbc = TRUE;
777 } else {
778 wlc->stf->no_cddstbc = FALSE;
779 if (N_ENAB(wlc->pub) != wlc->protection->nmode_user)
780 wlc_set_nmode(wlc, wlc->protection->nmode_user);
781 }
782
783 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
784 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
785 /* set or restore gmode as required by regulatory */
786 locale = wlc_get_locale_2g(country->locale_2G);
787 if (locale && (locale->flags & WLC_NO_OFDM)) {
788 wlc_set_gmode(wlc, GMODE_LEGACY_B, FALSE);
789 } else {
790 wlc_set_gmode(wlc, wlc->protection->gmode_user, FALSE);
791 }
792
793 wlc_channels_init(wlc_cm, country);
794
795 return;
796}
797
798/* Lookup a country info structure from a null terminated country code
799 * The lookup is case sensitive.
800 */
801const country_info_t *wlc_country_lookup(struct wlc_info *wlc,
802 const char *ccode)
803{
804 const country_info_t *country;
805 char mapped_ccode[WLC_CNTRY_BUF_SZ];
806 uint mapped_regrev;
807
808 /* map the country code to a built-in country code, regrev, and country_info struct */
809 country =
810 wlc_countrycode_map(wlc->cmi, ccode, mapped_ccode, &mapped_regrev);
811
812 return country;
813}
814
7cc4a4c0 815static const country_info_t *wlc_countrycode_map(wlc_cm_info_t *wlc_cm,
a9533e7e
HP
816 const char *ccode,
817 char *mapped_ccode,
7cc4a4c0 818 uint *mapped_regrev)
a9533e7e
HP
819{
820 wlc_info_t *wlc = wlc_cm->wlc;
821 const country_info_t *country;
822 uint srom_regrev = wlc_cm->srom_regrev;
823 const char *srom_ccode = wlc_cm->srom_ccode;
824 int mapped;
825
826 /* check for currently supported ccode size */
827 if (strlen(ccode) > (WLC_CNTRY_BUF_SZ - 1)) {
828 WL_ERROR(("wl%d: %s: ccode \"%s\" too long for match\n",
829 wlc->pub->unit, __func__, ccode));
830 return NULL;
831 }
832
833 /* default mapping is the given ccode and regrev 0 */
834 strncpy(mapped_ccode, ccode, WLC_CNTRY_BUF_SZ);
835 *mapped_regrev = 0;
836
837 /* If the desired country code matches the srom country code,
838 * then the mapped country is the srom regulatory rev.
839 * Otherwise look for an aggregate mapping.
840 */
841 if (!strcmp(srom_ccode, ccode)) {
842 *mapped_regrev = srom_regrev;
843 mapped = 0;
844 WL_ERROR(("srom_code == ccode %s\n", __func__));
845 ASSERT(0);
846 } else {
847 mapped =
848 wlc_country_aggregate_map(wlc_cm, ccode, mapped_ccode,
849 mapped_regrev);
850 }
851
852 /* find the matching built-in country definition */
853 country = wlc_country_lookup_direct(mapped_ccode, *mapped_regrev);
854
855 /* if there is not an exact rev match, default to rev zero */
856 if (country == NULL && *mapped_regrev != 0) {
857 *mapped_regrev = 0;
858 ASSERT(0);
859 country =
860 wlc_country_lookup_direct(mapped_ccode, *mapped_regrev);
861 }
862
863 return country;
864}
865
866static int
7cc4a4c0
JC
867wlc_country_aggregate_map(wlc_cm_info_t *wlc_cm, const char *ccode,
868 char *mapped_ccode, uint *mapped_regrev)
a9533e7e
HP
869{
870 return FALSE;
871}
872
873/* Lookup a country info structure from a null terminated country
874 * abbreviation and regrev directly with no translation.
875 */
876static const country_info_t *wlc_country_lookup_direct(const char *ccode,
877 uint regrev)
878{
879 uint size, i;
880
881 /* Should just return 0 for single locale driver. */
882 /* Keep it this way in case we add more locales. (for now anyway) */
883
884 /* all other country def arrays are for regrev == 0, so if regrev is non-zero, fail */
885 if (regrev > 0)
886 return NULL;
887
888 /* find matched table entry from country code */
889 size = ARRAYSIZE(cntry_locales);
890 for (i = 0; i < size; i++) {
891 if (strcmp(ccode, cntry_locales[i].abbrev) == 0) {
892 return &cntry_locales[i].country;
893 }
894 }
895
896 WL_ERROR(("%s: Returning NULL\n", __func__));
897 ASSERT(0);
898 return NULL;
899}
900
901static int
7cc4a4c0 902wlc_channels_init(wlc_cm_info_t *wlc_cm, const country_info_t *country)
a9533e7e
HP
903{
904 wlc_info_t *wlc = wlc_cm->wlc;
905 uint i, j;
906 wlcband_t *band;
907 const locale_info_t *li;
908 chanvec_t sup_chan;
909 const locale_mimo_info_t *li_mimo;
910
911 band = wlc->band;
912 for (i = 0; i < NBANDS(wlc);
913 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
914
915 li = BAND_5G(band->bandtype) ?
916 wlc_get_locale_5g(country->locale_5G) :
917 wlc_get_locale_2g(country->locale_2G);
918 ASSERT(li);
919 wlc_cm->bandstate[band->bandunit].locale_flags = li->flags;
920 li_mimo = BAND_5G(band->bandtype) ?
921 wlc_get_mimo_5g(country->locale_mimo_5G) :
922 wlc_get_mimo_2g(country->locale_mimo_2G);
923 ASSERT(li_mimo);
924
925 /* merge the mimo non-mimo locale flags */
926 wlc_cm->bandstate[band->bandunit].locale_flags |=
927 li_mimo->flags;
928
929 wlc_cm->bandstate[band->bandunit].restricted_channels =
930 g_table_restricted_chan[li->restricted_channels];
931 wlc_cm->bandstate[band->bandunit].radar_channels =
932 g_table_radar_set[li->radar_channels];
933
934 /* set the channel availability,
935 * masking out the channels that may not be supported on this phy
936 */
937 wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
938 &sup_chan);
939 wlc_locale_get_channels(li,
940 &wlc_cm->bandstate[band->bandunit].
941 valid_channels);
942 for (j = 0; j < sizeof(chanvec_t); j++)
943 wlc_cm->bandstate[band->bandunit].valid_channels.
944 vec[j] &= sup_chan.vec[j];
945 }
946
947 wlc_quiet_channels_reset(wlc_cm);
948 wlc_channels_commit(wlc_cm);
949
90ea2296 950 return 0;
a9533e7e
HP
951}
952
953/* Update the radio state (enable/disable) and tx power targets
954 * based on a new set of channel/regulatory information
955 */
7cc4a4c0 956static void wlc_channels_commit(wlc_cm_info_t *wlc_cm)
a9533e7e
HP
957{
958 wlc_info_t *wlc = wlc_cm->wlc;
959 uint chan;
960 struct txpwr_limits txpwr;
961
962 /* search for the existence of any valid channel */
963 for (chan = 0; chan < MAXCHANNEL; chan++) {
964 if (VALID_CHANNEL20_DB(wlc, chan)) {
965 break;
966 }
967 }
968 if (chan == MAXCHANNEL)
969 chan = INVCHANNEL;
970
971 /* based on the channel search above, set or clear WL_RADIO_COUNTRY_DISABLE */
972 if (chan == INVCHANNEL) {
973 /* country/locale with no valid channels, set the radio disable bit */
974 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
975 WL_ERROR(("wl%d: %s: no valid channel for \"%s\" nbands %d bandlocked %d\n", wlc->pub->unit, __func__, wlc_cm->country_abbrev, NBANDS(wlc), wlc->bandlocked));
976 } else
e5c4536f
JC
977 if (mboolisset(wlc->pub->radio_disabled,
978 WL_RADIO_COUNTRY_DISABLE)) {
a9533e7e
HP
979 /* country/locale with valid channel, clear the radio disable bit */
980 mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
981 }
982
983 /* Now that the country abbreviation is set, if the radio supports 2G, then
984 * set channel 14 restrictions based on the new locale.
985 */
986 if (NBANDS(wlc) > 1 || BAND_2G(wlc->band->bandtype)) {
987 wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
988 wlc_japan(wlc) ? TRUE :
989 FALSE);
990 }
991
992 if (wlc->pub->up && chan != INVCHANNEL) {
993 wlc_channel_reg_limits(wlc_cm, wlc->chanspec, &txpwr);
994 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm,
995 &txpwr,
996 WLC_TXPWR_MAX);
997 wlc_phy_txpower_limit_set(wlc->band->pi, &txpwr, wlc->chanspec);
998 }
999}
1000
1001/* reset the quiet channels vector to the union of the restricted and radar channel sets */
7cc4a4c0 1002void wlc_quiet_channels_reset(wlc_cm_info_t *wlc_cm)
a9533e7e
HP
1003{
1004 wlc_info_t *wlc = wlc_cm->wlc;
1005 uint i, j;
1006 wlcband_t *band;
1007 const chanvec_t *chanvec;
1008
1009 bzero(&wlc_cm->quiet_channels, sizeof(chanvec_t));
1010
1011 band = wlc->band;
1012 for (i = 0; i < NBANDS(wlc);
1013 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
1014
1015 /* initialize quiet channels for restricted channels */
1016 chanvec = wlc_cm->bandstate[band->bandunit].restricted_channels;
1017 for (j = 0; j < sizeof(chanvec_t); j++)
1018 wlc_cm->quiet_channels.vec[j] |= chanvec->vec[j];
1019
1020 }
1021}
1022
7cc4a4c0 1023bool wlc_quiet_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chspec)
a9533e7e 1024{
90ea2296 1025 return N_ENAB(wlc_cm->wlc->pub) && CHSPEC_IS40(chspec) ?
a9533e7e
HP
1026 (isset
1027 (wlc_cm->quiet_channels.vec,
1028 LOWER_20_SB(CHSPEC_CHANNEL(chspec)))
1029 || isset(wlc_cm->quiet_channels.vec,
1030 UPPER_20_SB(CHSPEC_CHANNEL(chspec)))) : isset(wlc_cm->
1031 quiet_channels.
1032 vec,
1033 CHSPEC_CHANNEL
90ea2296 1034 (chspec));
a9533e7e
HP
1035}
1036
1037/* Is the channel valid for the current locale? (but don't consider channels not
1038 * available due to bandlocking)
1039 */
7cc4a4c0 1040bool wlc_valid_channel20_db(wlc_cm_info_t *wlc_cm, uint val)
a9533e7e
HP
1041{
1042 wlc_info_t *wlc = wlc_cm->wlc;
1043
90ea2296 1044 return VALID_CHANNEL20(wlc, val) ||
a9533e7e 1045 (!wlc->bandlocked
90ea2296 1046 && VALID_CHANNEL20_IN_BAND(wlc, OTHERBANDUNIT(wlc), val));
a9533e7e
HP
1047}
1048
1049/* Is the channel valid for the current locale and specified band? */
1050bool
7cc4a4c0 1051wlc_valid_channel20_in_band(wlc_cm_info_t *wlc_cm, uint bandunit, uint val)
a9533e7e
HP
1052{
1053 return ((val < MAXCHANNEL)
1054 && isset(wlc_cm->bandstate[bandunit].valid_channels.vec, val));
1055}
1056
1057/* Is the channel valid for the current locale and current band? */
7cc4a4c0 1058bool wlc_valid_channel20(wlc_cm_info_t *wlc_cm, uint val)
a9533e7e
HP
1059{
1060 wlc_info_t *wlc = wlc_cm->wlc;
1061
1062 return ((val < MAXCHANNEL) &&
1063 isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec,
1064 val));
1065}
1066
1067/* Is the 40 MHz allowed for the current locale and specified band? */
7cc4a4c0 1068bool wlc_valid_40chanspec_in_band(wlc_cm_info_t *wlc_cm, uint bandunit)
a9533e7e
HP
1069{
1070 wlc_info_t *wlc = wlc_cm->wlc;
1071
1072 return (((wlc_cm->bandstate[bandunit].
1073 locale_flags & (WLC_NO_MIMO | WLC_NO_40MHZ)) == 0)
1074 && wlc->bandstate[bandunit]->mimo_cap_40);
1075}
1076
1077static void
7cc4a4c0 1078wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm_info_t *wlc_cm,
a9533e7e 1079 struct txpwr_limits *txpwr,
41feb5ed 1080 u8
a9533e7e
HP
1081 local_constraint_qdbm)
1082{
1083 int j;
1084
1085 /* CCK Rates */
1086 for (j = 0; j < WL_TX_POWER_CCK_NUM; j++) {
7068c2f1 1087 txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
a9533e7e
HP
1088 }
1089
1090 /* 20 MHz Legacy OFDM SISO */
1091 for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++) {
7068c2f1 1092 txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
a9533e7e
HP
1093 }
1094
1095 /* 20 MHz Legacy OFDM CDD */
1096 for (j = 0; j < WLC_NUM_RATES_OFDM; j++) {
1097 txpwr->ofdm_cdd[j] =
7068c2f1 1098 min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
a9533e7e
HP
1099 }
1100
1101 /* 40 MHz Legacy OFDM SISO */
1102 for (j = 0; j < WLC_NUM_RATES_OFDM; j++) {
1103 txpwr->ofdm_40_siso[j] =
7068c2f1 1104 min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
a9533e7e
HP
1105 }
1106
1107 /* 40 MHz Legacy OFDM CDD */
1108 for (j = 0; j < WLC_NUM_RATES_OFDM; j++) {
1109 txpwr->ofdm_40_cdd[j] =
7068c2f1 1110 min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
a9533e7e
HP
1111 }
1112
1113 /* 20MHz MCS 0-7 SISO */
1114 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1115 txpwr->mcs_20_siso[j] =
7068c2f1 1116 min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
a9533e7e
HP
1117 }
1118
1119 /* 20MHz MCS 0-7 CDD */
1120 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1121 txpwr->mcs_20_cdd[j] =
7068c2f1 1122 min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
a9533e7e
HP
1123 }
1124
1125 /* 20MHz MCS 0-7 STBC */
1126 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1127 txpwr->mcs_20_stbc[j] =
7068c2f1 1128 min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
a9533e7e
HP
1129 }
1130
1131 /* 20MHz MCS 8-15 MIMO */
1132 for (j = 0; j < WLC_NUM_RATES_MCS_2_STREAM; j++)
1133 txpwr->mcs_20_mimo[j] =
7068c2f1 1134 min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
a9533e7e
HP
1135
1136 /* 40MHz MCS 0-7 SISO */
1137 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1138 txpwr->mcs_40_siso[j] =
7068c2f1 1139 min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
a9533e7e
HP
1140 }
1141
1142 /* 40MHz MCS 0-7 CDD */
1143 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1144 txpwr->mcs_40_cdd[j] =
7068c2f1 1145 min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
a9533e7e
HP
1146 }
1147
1148 /* 40MHz MCS 0-7 STBC */
1149 for (j = 0; j < WLC_NUM_RATES_MCS_1_STREAM; j++) {
1150 txpwr->mcs_40_stbc[j] =
7068c2f1 1151 min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
a9533e7e
HP
1152 }
1153
1154 /* 40MHz MCS 8-15 MIMO */
1155 for (j = 0; j < WLC_NUM_RATES_MCS_2_STREAM; j++)
1156 txpwr->mcs_40_mimo[j] =
7068c2f1 1157 min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
a9533e7e
HP
1158
1159 /* 40MHz MCS 32 */
7068c2f1 1160 txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
a9533e7e
HP
1161
1162}
1163
1164void
7cc4a4c0 1165wlc_channel_set_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chanspec,
41feb5ed 1166 u8 local_constraint_qdbm)
a9533e7e
HP
1167{
1168 wlc_info_t *wlc = wlc_cm->wlc;
1169 struct txpwr_limits txpwr;
1170
1171 wlc_channel_reg_limits(wlc_cm, chanspec, &txpwr);
1172
1173 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm, &txpwr,
1174 local_constraint_qdbm);
1175
1176 wlc_bmac_set_chanspec(wlc->hw, chanspec,
1177 (wlc_quiet_chanspec(wlc_cm, chanspec) != 0),
1178 &txpwr);
1179}
1180
1181int
7cc4a4c0 1182wlc_channel_set_txpower_limit(wlc_cm_info_t *wlc_cm,
41feb5ed 1183 u8 local_constraint_qdbm)
a9533e7e
HP
1184{
1185 wlc_info_t *wlc = wlc_cm->wlc;
1186 struct txpwr_limits txpwr;
1187
1188 wlc_channel_reg_limits(wlc_cm, wlc->chanspec, &txpwr);
1189
1190 wlc_channel_min_txpower_limits_with_local_constraint(wlc_cm, &txpwr,
1191 local_constraint_qdbm);
1192
1193 wlc_phy_txpower_limit_set(wlc->band->pi, &txpwr, wlc->chanspec);
1194
1195 return 0;
1196}
1197
1198#ifdef POWER_DBG
7cc4a4c0 1199static void wlc_phy_txpower_limits_dump(txpwr_limits_t *txpwr)
a9533e7e
HP
1200{
1201 int i;
1202 char fraction[4][4] = { " ", ".25", ".5 ", ".75" };
1203
1204 printf("CCK ");
1205 for (i = 0; i < WLC_NUM_RATES_CCK; i++) {
1206 printf(" %2d%s", txpwr->cck[i] / WLC_TXPWR_DB_FACTOR,
1207 fraction[txpwr->cck[i] % WLC_TXPWR_DB_FACTOR]);
1208 }
1209 printf("\n");
1210
1211 printf("20 MHz OFDM SISO ");
1212 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
1213 printf(" %2d%s", txpwr->ofdm[i] / WLC_TXPWR_DB_FACTOR,
1214 fraction[txpwr->ofdm[i] % WLC_TXPWR_DB_FACTOR]);
1215 }
1216 printf("\n");
1217
1218 printf("20 MHz OFDM CDD ");
1219 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
1220 printf(" %2d%s", txpwr->ofdm_cdd[i] / WLC_TXPWR_DB_FACTOR,
1221 fraction[txpwr->ofdm_cdd[i] % WLC_TXPWR_DB_FACTOR]);
1222 }
1223 printf("\n");
1224
1225 printf("40 MHz OFDM SISO ");
1226 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
1227 printf(" %2d%s", txpwr->ofdm_40_siso[i] / WLC_TXPWR_DB_FACTOR,
1228 fraction[txpwr->ofdm_40_siso[i] % WLC_TXPWR_DB_FACTOR]);
1229 }
1230 printf("\n");
1231
1232 printf("40 MHz OFDM CDD ");
1233 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
1234 printf(" %2d%s", txpwr->ofdm_40_cdd[i] / WLC_TXPWR_DB_FACTOR,
1235 fraction[txpwr->ofdm_40_cdd[i] % WLC_TXPWR_DB_FACTOR]);
1236 }
1237 printf("\n");
1238
1239 printf("20 MHz MCS0-7 SISO ");
1240 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1241 printf(" %2d%s", txpwr->mcs_20_siso[i] / WLC_TXPWR_DB_FACTOR,
1242 fraction[txpwr->mcs_20_siso[i] % WLC_TXPWR_DB_FACTOR]);
1243 }
1244 printf("\n");
1245
1246 printf("20 MHz MCS0-7 CDD ");
1247 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1248 printf(" %2d%s", txpwr->mcs_20_cdd[i] / WLC_TXPWR_DB_FACTOR,
1249 fraction[txpwr->mcs_20_cdd[i] % WLC_TXPWR_DB_FACTOR]);
1250 }
1251 printf("\n");
1252
1253 printf("20 MHz MCS0-7 STBC ");
1254 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1255 printf(" %2d%s", txpwr->mcs_20_stbc[i] / WLC_TXPWR_DB_FACTOR,
1256 fraction[txpwr->mcs_20_stbc[i] % WLC_TXPWR_DB_FACTOR]);
1257 }
1258 printf("\n");
1259
1260 printf("20 MHz MCS8-15 SDM ");
1261 for (i = 0; i < WLC_NUM_RATES_MCS_2_STREAM; i++) {
1262 printf(" %2d%s", txpwr->mcs_20_mimo[i] / WLC_TXPWR_DB_FACTOR,
1263 fraction[txpwr->mcs_20_mimo[i] % WLC_TXPWR_DB_FACTOR]);
1264 }
1265 printf("\n");
1266
1267 printf("40 MHz MCS0-7 SISO ");
1268 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1269 printf(" %2d%s", txpwr->mcs_40_siso[i] / WLC_TXPWR_DB_FACTOR,
1270 fraction[txpwr->mcs_40_siso[i] % WLC_TXPWR_DB_FACTOR]);
1271 }
1272 printf("\n");
1273
1274 printf("40 MHz MCS0-7 CDD ");
1275 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1276 printf(" %2d%s", txpwr->mcs_40_cdd[i] / WLC_TXPWR_DB_FACTOR,
1277 fraction[txpwr->mcs_40_cdd[i] % WLC_TXPWR_DB_FACTOR]);
1278 }
1279 printf("\n");
1280
1281 printf("40 MHz MCS0-7 STBC ");
1282 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1283 printf(" %2d%s", txpwr->mcs_40_stbc[i] / WLC_TXPWR_DB_FACTOR,
1284 fraction[txpwr->mcs_40_stbc[i] % WLC_TXPWR_DB_FACTOR]);
1285 }
1286 printf("\n");
1287
1288 printf("40 MHz MCS8-15 SDM ");
1289 for (i = 0; i < WLC_NUM_RATES_MCS_2_STREAM; i++) {
1290 printf(" %2d%s", txpwr->mcs_40_mimo[i] / WLC_TXPWR_DB_FACTOR,
1291 fraction[txpwr->mcs_40_mimo[i] % WLC_TXPWR_DB_FACTOR]);
1292 }
1293 printf("\n");
1294
1295 printf("MCS32 %2d%s\n",
1296 txpwr->mcs32 / WLC_TXPWR_DB_FACTOR,
1297 fraction[txpwr->mcs32 % WLC_TXPWR_DB_FACTOR]);
1298}
1299#endif /* POWER_DBG */
1300
1301void
7cc4a4c0
JC
1302wlc_channel_reg_limits(wlc_cm_info_t *wlc_cm, chanspec_t chanspec,
1303 txpwr_limits_t *txpwr)
a9533e7e
HP
1304{
1305 wlc_info_t *wlc = wlc_cm->wlc;
1306 uint i;
1307 uint chan;
1308 int maxpwr;
1309 int delta;
1310 const country_info_t *country;
1311 wlcband_t *band;
1312 const locale_info_t *li;
1313 int conducted_max;
1314 int conducted_ofdm_max;
1315 const locale_mimo_info_t *li_mimo;
1316 int maxpwr20, maxpwr40;
1317 int maxpwr_idx;
1318 uint j;
1319
1320 bzero(txpwr, sizeof(txpwr_limits_t));
1321
1322 if (!wlc_valid_chanspec_db(wlc_cm, chanspec)) {
1323 country = wlc_country_lookup(wlc, wlc->autocountry_default);
1324 if (country == NULL)
1325 return;
1326 } else {
1327 country = wlc_cm->country;
1328 }
1329
1330 chan = CHSPEC_CHANNEL(chanspec);
1331 band = wlc->bandstate[CHSPEC_WLCBANDUNIT(chanspec)];
1332 li = BAND_5G(band->bandtype) ?
1333 wlc_get_locale_5g(country->locale_5G) :
1334 wlc_get_locale_2g(country->locale_2G);
1335
1336 li_mimo = BAND_5G(band->bandtype) ?
1337 wlc_get_mimo_5g(country->locale_mimo_5G) :
1338 wlc_get_mimo_2g(country->locale_mimo_2G);
1339
1340 if (li->flags & WLC_EIRP) {
1341 delta = band->antgain;
1342 } else {
1343 delta = 0;
1344 if (band->antgain > QDB(6))
1345 delta = band->antgain - QDB(6); /* Excess over 6 dB */
1346 }
1347
1348 if (li == &locale_i) {
1349 conducted_max = QDB(22);
1350 conducted_ofdm_max = QDB(22);
1351 }
1352
1353 /* CCK txpwr limits for 2.4G band */
1354 if (BAND_2G(band->bandtype)) {
1355 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_CCK(chan)];
1356
1357 maxpwr = maxpwr - delta;
1358 maxpwr = MAX(maxpwr, 0);
7068c2f1 1359 maxpwr = min(maxpwr, conducted_max);
a9533e7e
HP
1360
1361 for (i = 0; i < WLC_NUM_RATES_CCK; i++)
41feb5ed 1362 txpwr->cck[i] = (u8) maxpwr;
a9533e7e
HP
1363 }
1364
1365 /* OFDM txpwr limits for 2.4G or 5G bands */
1366 if (BAND_2G(band->bandtype)) {
1367 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_OFDM(chan)];
1368
1369 } else {
1370 maxpwr = li->maxpwr[CHANNEL_POWER_IDX_5G(chan)];
1371 }
1372
1373 maxpwr = maxpwr - delta;
1374 maxpwr = MAX(maxpwr, 0);
7068c2f1 1375 maxpwr = min(maxpwr, conducted_ofdm_max);
a9533e7e
HP
1376
1377 /* Keep OFDM lmit below CCK limit */
1378 if (BAND_2G(band->bandtype))
7068c2f1 1379 maxpwr = min(maxpwr, txpwr->cck[0]);
a9533e7e
HP
1380
1381 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
41feb5ed 1382 txpwr->ofdm[i] = (u8) maxpwr;
a9533e7e
HP
1383 }
1384
1385 for (i = 0; i < WLC_NUM_RATES_OFDM; i++) {
1386 /* OFDM 40 MHz SISO has the same power as the corresponding MCS0-7 rate unless
1387 * overriden by the locale specific code. We set this value to 0 as a
1388 * flag (presumably 0 dBm isn't a possibility) and then copy the MCS0-7 value
1389 * to the 40 MHz value if it wasn't explicitly set.
1390 */
1391 txpwr->ofdm_40_siso[i] = 0;
1392
41feb5ed 1393 txpwr->ofdm_cdd[i] = (u8) maxpwr;
a9533e7e
HP
1394
1395 txpwr->ofdm_40_cdd[i] = 0;
1396 }
1397
1398 /* MIMO/HT specific limits */
1399 if (li_mimo->flags & WLC_EIRP) {
1400 delta = band->antgain;
1401 } else {
1402 delta = 0;
1403 if (band->antgain > QDB(6))
1404 delta = band->antgain - QDB(6); /* Excess over 6 dB */
1405 }
1406
1407 if (BAND_2G(band->bandtype))
1408 maxpwr_idx = (chan - 1);
1409 else
1410 maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
1411
1412 maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
1413 maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
1414
1415 maxpwr20 = maxpwr20 - delta;
1416 maxpwr20 = MAX(maxpwr20, 0);
1417 maxpwr40 = maxpwr40 - delta;
1418 maxpwr40 = MAX(maxpwr40, 0);
1419
1420 /* Fill in the MCS 0-7 (SISO) rates */
1421 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1422
1423 /* 20 MHz has the same power as the corresponding OFDM rate unless
1424 * overriden by the locale specific code.
1425 */
1426 txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
1427 txpwr->mcs_40_siso[i] = 0;
1428 }
1429
1430 /* Fill in the MCS 0-7 CDD rates */
1431 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
41feb5ed
GKH
1432 txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
1433 txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
a9533e7e
HP
1434 }
1435
1436 /* These locales have SISO expressed in the table and override CDD later */
1437 if (li_mimo == &locale_bn) {
1438 if (li_mimo == &locale_bn) {
1439 maxpwr20 = QDB(16);
1440 maxpwr40 = 0;
1441
1442 if (chan >= 3 && chan <= 11) {
1443 maxpwr40 = QDB(16);
1444 }
1445 }
1446
1447 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
41feb5ed
GKH
1448 txpwr->mcs_20_siso[i] = (u8) maxpwr20;
1449 txpwr->mcs_40_siso[i] = (u8) maxpwr40;
a9533e7e
HP
1450 }
1451 }
1452
1453 /* Fill in the MCS 0-7 STBC rates */
1454 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1455 txpwr->mcs_20_stbc[i] = 0;
1456 txpwr->mcs_40_stbc[i] = 0;
1457 }
1458
1459 /* Fill in the MCS 8-15 SDM rates */
1460 for (i = 0; i < WLC_NUM_RATES_MCS_2_STREAM; i++) {
41feb5ed
GKH
1461 txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
1462 txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
a9533e7e
HP
1463 }
1464
1465 /* Fill in MCS32 */
41feb5ed 1466 txpwr->mcs32 = (u8) maxpwr40;
a9533e7e
HP
1467
1468 for (i = 0, j = 0; i < WLC_NUM_RATES_OFDM; i++, j++) {
1469 if (txpwr->ofdm_40_cdd[i] == 0)
1470 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
1471 if (i == 0) {
1472 i = i + 1;
1473 if (txpwr->ofdm_40_cdd[i] == 0)
1474 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
1475 }
1476 }
1477
1478 /* Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO value if it wasn't
92dfc7d1 1479 * provided explicitly.
a9533e7e
HP
1480 */
1481
1482 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1483 if (txpwr->mcs_40_siso[i] == 0)
1484 txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
1485 }
1486
1487 for (i = 0, j = 0; i < WLC_NUM_RATES_OFDM; i++, j++) {
1488 if (txpwr->ofdm_40_siso[i] == 0)
1489 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
1490 if (i == 0) {
1491 i = i + 1;
1492 if (txpwr->ofdm_40_siso[i] == 0)
1493 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
1494 }
1495 }
1496
1497 /* Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding STBC values if they weren't
1498 * provided explicitly.
1499 */
1500 for (i = 0; i < WLC_NUM_RATES_MCS_1_STREAM; i++) {
1501 if (txpwr->mcs_20_stbc[i] == 0)
1502 txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
1503
1504 if (txpwr->mcs_40_stbc[i] == 0)
1505 txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
1506 }
1507
1508#ifdef POWER_DBG
1509 wlc_phy_txpower_limits_dump(txpwr);
1510#endif
1511 return;
1512}
1513
1514/* Returns TRUE if currently set country is Japan or variant */
7cc4a4c0 1515bool wlc_japan(struct wlc_info *wlc)
a9533e7e
HP
1516{
1517 return wlc_japan_ccode(wlc->cmi->country_abbrev);
1518}
1519
1520/* JP, J1 - J10 are Japan ccodes */
1521static bool wlc_japan_ccode(const char *ccode)
1522{
1523 return (ccode[0] == 'J' &&
1524 (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
1525}
1526
1527/*
1528 * Validate the chanspec for this locale, for 40MHZ we need to also check that the sidebands
1529 * are valid 20MZH channels in this locale and they are also a legal HT combination
1530 */
1531static bool
7cc4a4c0 1532wlc_valid_chanspec_ext(wlc_cm_info_t *wlc_cm, chanspec_t chspec, bool dualband)
a9533e7e
HP
1533{
1534 wlc_info_t *wlc = wlc_cm->wlc;
41feb5ed 1535 u8 channel = CHSPEC_CHANNEL(chspec);
a9533e7e
HP
1536
1537 /* check the chanspec */
1538 if (wf_chspec_malformed(chspec)) {
1539 WL_ERROR(("wl%d: malformed chanspec 0x%x\n", wlc->pub->unit,
1540 chspec));
1541 ASSERT(0);
1542 return FALSE;
1543 }
1544
1545 if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
1546 CHSPEC_WLCBANDUNIT(chspec))
1547 return FALSE;
1548
1549 /* Check a 20Mhz channel */
1550 if (CHSPEC_IS20(chspec)) {
1551 if (dualband)
90ea2296 1552 return VALID_CHANNEL20_DB(wlc_cm->wlc, channel);
a9533e7e 1553 else
90ea2296 1554 return VALID_CHANNEL20(wlc_cm->wlc, channel);
a9533e7e
HP
1555 }
1556#ifdef SUPPORT_40MHZ
1557 /* We know we are now checking a 40MHZ channel, so we should only be here
1558 * for NPHYS
1559 */
1560 if (WLCISNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band)) {
41feb5ed
GKH
1561 u8 upper_sideband = 0, idx;
1562 u8 num_ch20_entries =
a9533e7e
HP
1563 sizeof(chan20_info) / sizeof(struct chan20_info);
1564
1565 if (!VALID_40CHANSPEC_IN_BAND(wlc, CHSPEC_WLCBANDUNIT(chspec)))
1566 return FALSE;
1567
1568 if (dualband) {
1569 if (!VALID_CHANNEL20_DB(wlc, LOWER_20_SB(channel)) ||
1570 !VALID_CHANNEL20_DB(wlc, UPPER_20_SB(channel)))
1571 return FALSE;
1572 } else {
1573 if (!VALID_CHANNEL20(wlc, LOWER_20_SB(channel)) ||
1574 !VALID_CHANNEL20(wlc, UPPER_20_SB(channel)))
1575 return FALSE;
1576 }
1577
1578 /* find the lower sideband info in the sideband array */
1579 for (idx = 0; idx < num_ch20_entries; idx++) {
1580 if (chan20_info[idx].sb == LOWER_20_SB(channel))
1581 upper_sideband = chan20_info[idx].adj_sbs;
1582 }
1583 /* check that the lower sideband allows an upper sideband */
1584 if ((upper_sideband & (CH_UPPER_SB | CH_EWA_VALID)) ==
1585 (CH_UPPER_SB | CH_EWA_VALID))
1586 return TRUE;
1587 return FALSE;
1588 }
1589#endif /* 40 MHZ */
1590
1591 return FALSE;
1592}
1593
7cc4a4c0 1594bool wlc_valid_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chspec)
a9533e7e
HP
1595{
1596 return wlc_valid_chanspec_ext(wlc_cm, chspec, FALSE);
1597}
1598
7cc4a4c0 1599bool wlc_valid_chanspec_db(wlc_cm_info_t *wlc_cm, chanspec_t chspec)
a9533e7e
HP
1600{
1601 return wlc_valid_chanspec_ext(wlc_cm, chspec, TRUE);
1602}