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