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