blob: bdb11ffcc1544f973884f2c9a7f2bf3918b39a74 [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/types.h>
Seth Forsheecf03c5d2012-06-16 07:47:52 -050018#include <net/cfg80211.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020019#include <net/mac80211.h>
Seth Forsheecf03c5d2012-06-16 07:47:52 -050020#include <net/regulatory.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020021
22#include <defs.h>
23#include "pub.h"
24#include "phy/phy_hal.h"
25#include "main.h"
26#include "stf.h"
27#include "channel.h"
Seth Forsheecf03c5d2012-06-16 07:47:52 -050028#include "mac80211_if.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020029
30/* QDB() macro takes a dB value and converts to a quarter dB value */
31#define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
32
33#define LOCALE_CHAN_01_11 (1<<0)
34#define LOCALE_CHAN_12_13 (1<<1)
35#define LOCALE_CHAN_14 (1<<2)
36#define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
37#define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
38#define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
39#define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
40#define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
41#define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
42#define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
43#define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
44#define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
45#define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
46#define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
47#define LOCALE_CHAN_52_140_ALL (1<<14)
48#define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
49
50#define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | \
51 LOCALE_SET_5G_LOW2 | \
52 LOCALE_SET_5G_LOW3)
53#define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
54#define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
55#define LOCALE_CHAN_100_140 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | \
56 LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
57#define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
58#define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
59
60#define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | \
61 LOCALE_CHAN_12_13 | \
62 LOCALE_CHAN_14)
63
Arend van Spriel5b435de2011-10-05 13:19:03 +020064#define LOCALE_RESTRICTED_NONE 0
65#define LOCALE_RESTRICTED_SET_2G_SHORT 1
Arend van Spriel5b435de2011-10-05 13:19:03 +020066
67#define LOCALE_2G_IDX_i 0
68#define LOCALE_5G_IDX_11 0
69#define LOCALE_MIMO_IDX_bn 0
70#define LOCALE_MIMO_IDX_11n 0
71
72/* max of BAND_5G_PWR_LVLS and 6 for 2.4 GHz */
73#define BRCMS_MAXPWR_TBL_SIZE 6
74/* max of BAND_5G_PWR_LVLS and 14 for 2.4 GHz */
75#define BRCMS_MAXPWR_MIMO_TBL_SIZE 14
76
Arend van Spriel5b435de2011-10-05 13:19:03 +020077/* maxpwr mapping to 5GHz band channels:
78 * maxpwr[0] - channels [34-48]
79 * maxpwr[1] - channels [52-60]
80 * maxpwr[2] - channels [62-64]
81 * maxpwr[3] - channels [100-140]
82 * maxpwr[4] - channels [149-165]
83 */
84#define BAND_5G_PWR_LVLS 5 /* 5 power levels for 5G */
85
86#define LC(id) LOCALE_MIMO_IDX_ ## id
87
88#define LC_2G(id) LOCALE_2G_IDX_ ## id
89
90#define LC_5G(id) LOCALE_5G_IDX_ ## id
91
92#define LOCALES(band2, band5, mimo2, mimo5) \
93 {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
94
Arend van Spriel5b435de2011-10-05 13:19:03 +020095/* macro to get 5 GHz channel group index for tx power */
96#define CHANNEL_POWER_IDX_5G(c) (((c) < 52) ? 0 : \
97 (((c) < 62) ? 1 : \
98 (((c) < 100) ? 2 : \
99 (((c) < 149) ? 3 : 4))))
100
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500101#define BRCM_2GHZ_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
102#define BRCM_2GHZ_2467_2472 REG_RULE(2467-10, 2472+10, 20, 0, 19, \
103 NL80211_RRF_PASSIVE_SCAN | \
104 NL80211_RRF_NO_IBSS)
105
106#define BRCM_5GHZ_5180_5240 REG_RULE(5180-10, 5240+10, 40, 0, 21, \
107 NL80211_RRF_PASSIVE_SCAN | \
108 NL80211_RRF_NO_IBSS)
109#define BRCM_5GHZ_5260_5320 REG_RULE(5260-10, 5320+10, 40, 0, 21, \
110 NL80211_RRF_PASSIVE_SCAN | \
111 NL80211_RRF_DFS | \
112 NL80211_RRF_NO_IBSS)
113#define BRCM_5GHZ_5500_5700 REG_RULE(5500-10, 5700+10, 40, 0, 21, \
114 NL80211_RRF_PASSIVE_SCAN | \
115 NL80211_RRF_DFS | \
116 NL80211_RRF_NO_IBSS)
117#define BRCM_5GHZ_5745_5825 REG_RULE(5745-10, 5825+10, 40, 0, 21, \
118 NL80211_RRF_PASSIVE_SCAN | \
119 NL80211_RRF_NO_IBSS)
120
121static const struct ieee80211_regdomain brcms_regdom_x2 = {
122 .n_reg_rules = 7,
123 .alpha2 = "X2",
124 .reg_rules = {
125 BRCM_2GHZ_2412_2462,
126 BRCM_2GHZ_2467_2472,
127 BRCM_5GHZ_5180_5240,
128 BRCM_5GHZ_5260_5320,
129 BRCM_5GHZ_5500_5700,
130 BRCM_5GHZ_5745_5825,
131 }
132};
133
Arend van Spriel5b435de2011-10-05 13:19:03 +0200134struct brcms_cm_band {
135 /* struct locale_info flags */
136 u8 locale_flags;
137 /* List of valid channels in the country */
138 struct brcms_chanvec valid_channels;
139 /* List of restricted use channels */
140 const struct brcms_chanvec *restricted_channels;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200141};
142
143 /* locale per-channel tx power limits for MIMO frames
144 * maxpwr arrays are index by channel for 2.4 GHz limits, and
145 * by sub-band for 5 GHz limits using CHANNEL_POWER_IDX_5G(channel)
146 */
147struct locale_mimo_info {
148 /* tx 20 MHz power limits, qdBm units */
149 s8 maxpwr20[BRCMS_MAXPWR_MIMO_TBL_SIZE];
150 /* tx 40 MHz power limits, qdBm units */
151 s8 maxpwr40[BRCMS_MAXPWR_MIMO_TBL_SIZE];
152 u8 flags;
153};
154
155/* Country names and abbreviations with locale defined from ISO 3166 */
156struct country_info {
157 const u8 locale_2G; /* 2.4G band locale */
158 const u8 locale_5G; /* 5G band locale */
159 const u8 locale_mimo_2G; /* 2.4G mimo info */
160 const u8 locale_mimo_5G; /* 5G mimo info */
161};
162
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500163struct brcms_regd {
164 struct country_info country;
165 const struct ieee80211_regdomain *regdomain;
166};
167
Arend van Spriel5b435de2011-10-05 13:19:03 +0200168struct brcms_cm_info {
169 struct brcms_pub *pub;
170 struct brcms_c_info *wlc;
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500171 const struct brcms_regd *world_regd;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200172 /* per-band state (one per phy/radio) */
173 struct brcms_cm_band bandstate[MAXBANDS];
174 /* quiet channels currently for radar sensitivity or 11h support */
175 /* channels on which we cannot transmit */
176 struct brcms_chanvec quiet_channels;
177};
178
179/* locale channel and power info. */
180struct locale_info {
181 u32 valid_channels;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200182 /* List of channels used only if APs are detected */
183 u8 restricted_channels;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200184 u8 flags;
185};
186
187/* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
188
189/*
190 * Some common channel sets
191 */
192
193/* No channels */
194static const struct brcms_chanvec chanvec_none = {
195 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00}
199};
200
Arend van Spriel5b435de2011-10-05 13:19:03 +0200201/*
202 * Restricted channel sets
203 */
204
Arend van Spriel5b435de2011-10-05 13:19:03 +0200205/* Channels 12, 13 */
206static const struct brcms_chanvec restricted_set_2g_short = {
207 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210 0x00, 0x00, 0x00, 0x00}
211};
212
Arend van Spriel5b435de2011-10-05 13:19:03 +0200213/* global memory to provide working buffer for expanded locale */
214
Arend van Spriel5b435de2011-10-05 13:19:03 +0200215static const struct brcms_chanvec *g_table_restricted_chan[] = {
216 &chanvec_none, /* restricted_set_none */
217 &restricted_set_2g_short,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200218};
219
220static const struct brcms_chanvec locale_2g_01_11 = {
221 {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x00, 0x00, 0x00}
225};
226
227static const struct brcms_chanvec locale_2g_12_13 = {
228 {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00}
232};
233
234static const struct brcms_chanvec locale_2g_14 = {
235 {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00}
239};
240
241static const struct brcms_chanvec locale_5g_LOW_JP1 = {
242 {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00}
246};
247
248static const struct brcms_chanvec locale_5g_LOW_JP2 = {
249 {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00}
253};
254
255static const struct brcms_chanvec locale_5g_LOW1 = {
256 {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00}
260};
261
262static const struct brcms_chanvec locale_5g_LOW2 = {
263 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00}
267};
268
269static const struct brcms_chanvec locale_5g_LOW3 = {
270 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
271 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00}
274};
275
276static const struct brcms_chanvec locale_5g_MID1 = {
277 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00}
281};
282
283static const struct brcms_chanvec locale_5g_MID2 = {
284 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00}
288};
289
290static const struct brcms_chanvec locale_5g_MID3 = {
291 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00}
295};
296
297static const struct brcms_chanvec locale_5g_HIGH1 = {
298 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x00, 0x00, 0x00, 0x00}
302};
303
304static const struct brcms_chanvec locale_5g_HIGH2 = {
305 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00}
309};
310
311static const struct brcms_chanvec locale_5g_HIGH3 = {
312 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00}
316};
317
318static const struct brcms_chanvec locale_5g_52_140_ALL = {
319 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
320 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
321 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
322 0x00, 0x00, 0x00, 0x00}
323};
324
325static const struct brcms_chanvec locale_5g_HIGH4 = {
326 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
329 0x11, 0x11, 0x11, 0x11}
330};
331
332static const struct brcms_chanvec *g_table_locale_base[] = {
333 &locale_2g_01_11,
334 &locale_2g_12_13,
335 &locale_2g_14,
336 &locale_5g_LOW_JP1,
337 &locale_5g_LOW_JP2,
338 &locale_5g_LOW1,
339 &locale_5g_LOW2,
340 &locale_5g_LOW3,
341 &locale_5g_MID1,
342 &locale_5g_MID2,
343 &locale_5g_MID3,
344 &locale_5g_HIGH1,
345 &locale_5g_HIGH2,
346 &locale_5g_HIGH3,
347 &locale_5g_52_140_ALL,
348 &locale_5g_HIGH4
349};
350
351static void brcms_c_locale_add_channels(struct brcms_chanvec *target,
352 const struct brcms_chanvec *channels)
353{
354 u8 i;
355 for (i = 0; i < sizeof(struct brcms_chanvec); i++)
356 target->vec[i] |= channels->vec[i];
357}
358
359static void brcms_c_locale_get_channels(const struct locale_info *locale,
360 struct brcms_chanvec *channels)
361{
362 u8 i;
363
364 memset(channels, 0, sizeof(struct brcms_chanvec));
365
366 for (i = 0; i < ARRAY_SIZE(g_table_locale_base); i++) {
367 if (locale->valid_channels & (1 << i))
368 brcms_c_locale_add_channels(channels,
369 g_table_locale_base[i]);
370 }
371}
372
373/*
374 * Locale Definitions - 2.4 GHz
375 */
376static const struct locale_info locale_i = { /* locale i. channel 1 - 13 */
377 LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200378 LOCALE_RESTRICTED_SET_2G_SHORT,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200379 BRCMS_EIRP
380};
381
382/*
383 * Locale Definitions - 5 GHz
384 */
385static const struct locale_info locale_11 = {
386 /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
387 LOCALE_CHAN_36_64 | LOCALE_CHAN_100_140 | LOCALE_CHAN_149_165,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200388 LOCALE_RESTRICTED_NONE,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200389 BRCMS_EIRP | BRCMS_DFS_EU
390};
391
392static const struct locale_info *g_locale_2g_table[] = {
393 &locale_i
394};
395
396static const struct locale_info *g_locale_5g_table[] = {
397 &locale_11
398};
399
400/*
401 * MIMO Locale Definitions - 2.4 GHz
402 */
403static const struct locale_mimo_info locale_bn = {
404 {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
405 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
406 QDB(13), QDB(13), QDB(13)},
407 {0, 0, QDB(13), QDB(13), QDB(13),
408 QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
409 QDB(13), 0, 0},
410 0
411};
412
413static const struct locale_mimo_info *g_mimo_2g_table[] = {
414 &locale_bn
415};
416
417/*
418 * MIMO Locale Definitions - 5 GHz
419 */
420static const struct locale_mimo_info locale_11n = {
421 { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
422 {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
423 0
424};
425
426static const struct locale_mimo_info *g_mimo_5g_table[] = {
427 &locale_11n
428};
429
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500430static const struct brcms_regd cntry_locales[] = {
431 /* Worldwide RoW 2, must always be at index 0 */
Arend van Spriel5b435de2011-10-05 13:19:03 +0200432 {
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500433 .country = LOCALES(i, 11, bn, 11n),
434 .regdomain = &brcms_regdom_x2,
435 },
Arend van Spriel5b435de2011-10-05 13:19:03 +0200436};
437
Arend van Spriel5b435de2011-10-05 13:19:03 +0200438static const struct locale_info *brcms_c_get_locale_2g(u8 locale_idx)
439{
440 if (locale_idx >= ARRAY_SIZE(g_locale_2g_table))
441 return NULL; /* error condition */
442
443 return g_locale_2g_table[locale_idx];
444}
445
446static const struct locale_info *brcms_c_get_locale_5g(u8 locale_idx)
447{
448 if (locale_idx >= ARRAY_SIZE(g_locale_5g_table))
449 return NULL; /* error condition */
450
451 return g_locale_5g_table[locale_idx];
452}
453
454static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx)
455{
456 if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table))
457 return NULL;
458
459 return g_mimo_2g_table[locale_idx];
460}
461
462static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx)
463{
464 if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table))
465 return NULL;
466
467 return g_mimo_5g_table[locale_idx];
468}
469
Arend van Spriel94a2ca32012-04-11 11:52:50 +0200470/*
471 * Indicates whether the country provided is valid to pass
472 * to cfg80211 or not.
473 *
474 * returns true if valid; false if not.
475 */
476static bool brcms_c_country_valid(const char *ccode)
477{
478 /*
479 * only allow ascii alpha uppercase for the first 2
480 * chars.
481 */
482 if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
483 (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A &&
484 ccode[2] == '\0'))
485 return false;
486
487 /*
488 * do not match ISO 3166-1 user assigned country codes
489 * that may be in the driver table
490 */
491 if (!strcmp("AA", ccode) || /* AA */
492 !strcmp("ZZ", ccode) || /* ZZ */
493 ccode[0] == 'X' || /* XA - XZ */
494 (ccode[0] == 'Q' && /* QM - QZ */
495 (ccode[1] >= 'M' && ccode[1] <= 'Z')))
496 return false;
497
498 if (!strcmp("NA", ccode))
499 return false;
500
501 return true;
502}
503
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500504static const struct brcms_regd *brcms_world_regd(const char *regdom, int len)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200505{
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500506 const struct brcms_regd *regd = NULL;
507 int i;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200508
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500509 for (i = 0; i < ARRAY_SIZE(cntry_locales); i++) {
510 if (!strncmp(regdom, cntry_locales[i].regdomain->alpha2, len)) {
511 regd = &cntry_locales[i];
512 break;
513 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200514 }
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500515
516 return regd;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200517}
518
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500519static const struct brcms_regd *brcms_default_world_regd(void)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200520{
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500521 return &cntry_locales[0];
Arend van Spriel5b435de2011-10-05 13:19:03 +0200522}
523
524/*
525 * reset the quiet channels vector to the union
526 * of the restricted and radar channel sets
527 */
528static void brcms_c_quiet_channels_reset(struct brcms_cm_info *wlc_cm)
529{
530 struct brcms_c_info *wlc = wlc_cm->wlc;
531 uint i, j;
532 struct brcms_band *band;
533 const struct brcms_chanvec *chanvec;
534
535 memset(&wlc_cm->quiet_channels, 0, sizeof(struct brcms_chanvec));
536
537 band = wlc->band;
538 for (i = 0; i < wlc->pub->_nbands;
539 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
540
541 /* initialize quiet channels for restricted channels */
542 chanvec = wlc_cm->bandstate[band->bandunit].restricted_channels;
543 for (j = 0; j < sizeof(struct brcms_chanvec); j++)
544 wlc_cm->quiet_channels.vec[j] |= chanvec->vec[j];
545
546 }
547}
548
549/* Is the channel valid for the current locale and current band? */
550static bool brcms_c_valid_channel20(struct brcms_cm_info *wlc_cm, uint val)
551{
552 struct brcms_c_info *wlc = wlc_cm->wlc;
553
554 return ((val < MAXCHANNEL) &&
555 isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec,
556 val));
557}
558
559/* Is the channel valid for the current locale and specified band? */
560static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info *wlc_cm,
561 uint bandunit, uint val)
562{
563 return ((val < MAXCHANNEL)
564 && isset(wlc_cm->bandstate[bandunit].valid_channels.vec, val));
565}
566
567/* Is the channel valid for the current locale? (but don't consider channels not
568 * available due to bandlocking)
569 */
570static bool brcms_c_valid_channel20_db(struct brcms_cm_info *wlc_cm, uint val)
571{
572 struct brcms_c_info *wlc = wlc_cm->wlc;
573
574 return brcms_c_valid_channel20(wlc->cmi, val) ||
575 (!wlc->bandlocked
576 && brcms_c_valid_channel20_in_band(wlc->cmi,
577 OTHERBANDUNIT(wlc), val));
578}
579
580/* JP, J1 - J10 are Japan ccodes */
581static bool brcms_c_japan_ccode(const char *ccode)
582{
583 return (ccode[0] == 'J' &&
584 (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
585}
586
Arend van Spriel5b435de2011-10-05 13:19:03 +0200587static void
588brcms_c_channel_min_txpower_limits_with_local_constraint(
589 struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
590 u8 local_constraint_qdbm)
591{
592 int j;
593
594 /* CCK Rates */
595 for (j = 0; j < WL_TX_POWER_CCK_NUM; j++)
596 txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
597
598 /* 20 MHz Legacy OFDM SISO */
599 for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++)
600 txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
601
602 /* 20 MHz Legacy OFDM CDD */
603 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
604 txpwr->ofdm_cdd[j] =
605 min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
606
607 /* 40 MHz Legacy OFDM SISO */
608 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
609 txpwr->ofdm_40_siso[j] =
610 min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
611
612 /* 40 MHz Legacy OFDM CDD */
613 for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
614 txpwr->ofdm_40_cdd[j] =
615 min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
616
617 /* 20MHz MCS 0-7 SISO */
618 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
619 txpwr->mcs_20_siso[j] =
620 min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
621
622 /* 20MHz MCS 0-7 CDD */
623 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
624 txpwr->mcs_20_cdd[j] =
625 min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
626
627 /* 20MHz MCS 0-7 STBC */
628 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
629 txpwr->mcs_20_stbc[j] =
630 min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
631
632 /* 20MHz MCS 8-15 MIMO */
633 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
634 txpwr->mcs_20_mimo[j] =
635 min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
636
637 /* 40MHz MCS 0-7 SISO */
638 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
639 txpwr->mcs_40_siso[j] =
640 min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
641
642 /* 40MHz MCS 0-7 CDD */
643 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
644 txpwr->mcs_40_cdd[j] =
645 min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
646
647 /* 40MHz MCS 0-7 STBC */
648 for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
649 txpwr->mcs_40_stbc[j] =
650 min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
651
652 /* 40MHz MCS 8-15 MIMO */
653 for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
654 txpwr->mcs_40_mimo[j] =
655 min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
656
657 /* 40MHz MCS 32 */
658 txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
659
660}
661
Arend van Spriel5b435de2011-10-05 13:19:03 +0200662static int
663brcms_c_channels_init(struct brcms_cm_info *wlc_cm,
664 const struct country_info *country)
665{
666 struct brcms_c_info *wlc = wlc_cm->wlc;
667 uint i, j;
668 struct brcms_band *band;
669 const struct locale_info *li;
670 struct brcms_chanvec sup_chan;
671 const struct locale_mimo_info *li_mimo;
672
673 band = wlc->band;
674 for (i = 0; i < wlc->pub->_nbands;
675 i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
676
677 li = (band->bandtype == BRCM_BAND_5G) ?
678 brcms_c_get_locale_5g(country->locale_5G) :
679 brcms_c_get_locale_2g(country->locale_2G);
680 wlc_cm->bandstate[band->bandunit].locale_flags = li->flags;
681 li_mimo = (band->bandtype == BRCM_BAND_5G) ?
682 brcms_c_get_mimo_5g(country->locale_mimo_5G) :
683 brcms_c_get_mimo_2g(country->locale_mimo_2G);
684
685 /* merge the mimo non-mimo locale flags */
686 wlc_cm->bandstate[band->bandunit].locale_flags |=
687 li_mimo->flags;
688
689 wlc_cm->bandstate[band->bandunit].restricted_channels =
690 g_table_restricted_chan[li->restricted_channels];
Arend van Spriel5b435de2011-10-05 13:19:03 +0200691
692 /*
693 * set the channel availability, masking out the channels
694 * that may not be supported on this phy.
695 */
696 wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
697 &sup_chan);
698 brcms_c_locale_get_channels(li,
699 &wlc_cm->bandstate[band->bandunit].
700 valid_channels);
701 for (j = 0; j < sizeof(struct brcms_chanvec); j++)
702 wlc_cm->bandstate[band->bandunit].valid_channels.
703 vec[j] &= sup_chan.vec[j];
704 }
705
706 brcms_c_quiet_channels_reset(wlc_cm);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200707
708 return 0;
709}
710
711/*
712 * set the driver's current country and regulatory information
713 * using a country code as the source. Look up built in country
714 * information found with the country code.
715 */
716static void
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500717brcms_c_set_country(struct brcms_cm_info *wlc_cm,
718 const struct brcms_regd *regd)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200719{
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500720 const struct country_info *country = &regd->country;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200721 const struct locale_info *locale;
722 struct brcms_c_info *wlc = wlc_cm->wlc;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200723
Arend van Spriel5b435de2011-10-05 13:19:03 +0200724 if ((wlc->pub->_n_enab & SUPPORT_11N) !=
725 wlc->protection->nmode_user)
726 brcms_c_set_nmode(wlc);
727
728 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
729 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
730 /* set or restore gmode as required by regulatory */
731 locale = brcms_c_get_locale_2g(country->locale_2G);
732 if (locale && (locale->flags & BRCMS_NO_OFDM))
733 brcms_c_set_gmode(wlc, GMODE_LEGACY_B, false);
734 else
735 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
736
737 brcms_c_channels_init(wlc_cm, country);
738
739 return;
740}
741
Arend van Spriel5b435de2011-10-05 13:19:03 +0200742struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
743{
744 struct brcms_cm_info *wlc_cm;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200745 struct brcms_pub *pub = wlc->pub;
Hauke Mehrtens898d3c32012-04-29 02:50:25 +0200746 struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500747 const char *ccode = sprom->alpha2;
748 int ccode_len = sizeof(sprom->alpha2);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200749
750 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
751
752 wlc_cm = kzalloc(sizeof(struct brcms_cm_info), GFP_ATOMIC);
753 if (wlc_cm == NULL)
754 return NULL;
755 wlc_cm->pub = pub;
756 wlc_cm->wlc = wlc;
757 wlc->cmi = wlc_cm;
758
759 /* store the country code for passing up as a regulatory hint */
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500760 wlc_cm->world_regd = brcms_world_regd(ccode, ccode_len);
761 if (brcms_c_country_valid(ccode))
762 strncpy(wlc->pub->srom_ccode, ccode, ccode_len);
763
764 /*
765 * If no custom world domain is found in the SROM, use the
766 * default "X2" domain.
767 */
768 if (!wlc_cm->world_regd) {
769 wlc_cm->world_regd = brcms_default_world_regd();
770 ccode = wlc_cm->world_regd->regdomain->alpha2;
771 ccode_len = BRCM_CNTRY_BUF_SZ - 1;
772 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200773
Arend van Spriel5b435de2011-10-05 13:19:03 +0200774 /* save default country for exiting 11d regulatory mode */
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500775 strncpy(wlc->country_default, ccode, ccode_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200776
777 /* initialize autocountry_default to driver default */
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500778 strncpy(wlc->autocountry_default, ccode, ccode_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200779
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500780 brcms_c_set_country(wlc_cm, wlc_cm->world_regd);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200781
782 return wlc_cm;
783}
784
785void brcms_c_channel_mgr_detach(struct brcms_cm_info *wlc_cm)
786{
787 kfree(wlc_cm);
788}
789
790u8
791brcms_c_channel_locale_flags_in_band(struct brcms_cm_info *wlc_cm,
792 uint bandunit)
793{
794 return wlc_cm->bandstate[bandunit].locale_flags;
795}
796
797static bool
798brcms_c_quiet_chanspec(struct brcms_cm_info *wlc_cm, u16 chspec)
799{
800 return (wlc_cm->wlc->pub->_n_enab & SUPPORT_11N) &&
801 CHSPEC_IS40(chspec) ?
802 (isset(wlc_cm->quiet_channels.vec,
803 lower_20_sb(CHSPEC_CHANNEL(chspec))) ||
804 isset(wlc_cm->quiet_channels.vec,
805 upper_20_sb(CHSPEC_CHANNEL(chspec)))) :
806 isset(wlc_cm->quiet_channels.vec, CHSPEC_CHANNEL(chspec));
807}
808
809void
810brcms_c_channel_set_chanspec(struct brcms_cm_info *wlc_cm, u16 chanspec,
811 u8 local_constraint_qdbm)
812{
813 struct brcms_c_info *wlc = wlc_cm->wlc;
814 struct txpwr_limits txpwr;
815
816 brcms_c_channel_reg_limits(wlc_cm, chanspec, &txpwr);
817
818 brcms_c_channel_min_txpower_limits_with_local_constraint(
819 wlc_cm, &txpwr, local_constraint_qdbm
820 );
821
822 brcms_b_set_chanspec(wlc->hw, chanspec,
823 (brcms_c_quiet_chanspec(wlc_cm, chanspec) != 0),
824 &txpwr);
825}
826
Arend van Spriel5b435de2011-10-05 13:19:03 +0200827void
828brcms_c_channel_reg_limits(struct brcms_cm_info *wlc_cm, u16 chanspec,
829 struct txpwr_limits *txpwr)
830{
831 struct brcms_c_info *wlc = wlc_cm->wlc;
Seth Forshee2cf50892012-06-16 07:47:54 -0500832 struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200833 uint i;
834 uint chan;
835 int maxpwr;
836 int delta;
837 const struct country_info *country;
838 struct brcms_band *band;
839 const struct locale_info *li;
840 int conducted_max = BRCMS_TXPWR_MAX;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200841 const struct locale_mimo_info *li_mimo;
842 int maxpwr20, maxpwr40;
843 int maxpwr_idx;
844 uint j;
845
846 memset(txpwr, 0, sizeof(struct txpwr_limits));
847
Seth Forshee2cf50892012-06-16 07:47:54 -0500848 if (WARN_ON(!ch))
849 return;
850
Seth Forsheecf03c5d2012-06-16 07:47:52 -0500851 country = &wlc_cm->world_regd->country;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200852
853 chan = CHSPEC_CHANNEL(chanspec);
854 band = wlc->bandstate[chspec_bandunit(chanspec)];
855 li = (band->bandtype == BRCM_BAND_5G) ?
856 brcms_c_get_locale_5g(country->locale_5G) :
857 brcms_c_get_locale_2g(country->locale_2G);
858
859 li_mimo = (band->bandtype == BRCM_BAND_5G) ?
860 brcms_c_get_mimo_5g(country->locale_mimo_5G) :
861 brcms_c_get_mimo_2g(country->locale_mimo_2G);
862
Seth Forshee2cf50892012-06-16 07:47:54 -0500863 delta = band->antgain;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200864
Seth Forshee2cf50892012-06-16 07:47:54 -0500865 if (li == &locale_i)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200866 conducted_max = QDB(22);
Seth Forshee2cf50892012-06-16 07:47:54 -0500867
868 maxpwr = QDB(ch->max_power) - delta;
869 maxpwr = max(maxpwr, 0);
870 maxpwr = min(maxpwr, conducted_max);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200871
872 /* CCK txpwr limits for 2.4G band */
873 if (band->bandtype == BRCM_BAND_2G) {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200874 for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
875 txpwr->cck[i] = (u8) maxpwr;
876 }
877
Seth Forshee2cf50892012-06-16 07:47:54 -0500878 for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++) {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200879 txpwr->ofdm[i] = (u8) maxpwr;
880
Arend van Spriel5b435de2011-10-05 13:19:03 +0200881 /*
882 * OFDM 40 MHz SISO has the same power as the corresponding
883 * MCS0-7 rate unless overriden by the locale specific code.
884 * We set this value to 0 as a flag (presumably 0 dBm isn't
885 * a possibility) and then copy the MCS0-7 value to the 40 MHz
886 * value if it wasn't explicitly set.
887 */
888 txpwr->ofdm_40_siso[i] = 0;
889
890 txpwr->ofdm_cdd[i] = (u8) maxpwr;
891
892 txpwr->ofdm_40_cdd[i] = 0;
893 }
894
Seth Forshee2cf50892012-06-16 07:47:54 -0500895 delta = 0;
896 if (band->antgain > QDB(6))
897 delta = band->antgain - QDB(6); /* Excess over 6 dB */
Arend van Spriel5b435de2011-10-05 13:19:03 +0200898
899 if (band->bandtype == BRCM_BAND_2G)
900 maxpwr_idx = (chan - 1);
901 else
902 maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
903
904 maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
905 maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
906
907 maxpwr20 = maxpwr20 - delta;
908 maxpwr20 = max(maxpwr20, 0);
909 maxpwr40 = maxpwr40 - delta;
910 maxpwr40 = max(maxpwr40, 0);
911
912 /* Fill in the MCS 0-7 (SISO) rates */
913 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
914
915 /*
916 * 20 MHz has the same power as the corresponding OFDM rate
917 * unless overriden by the locale specific code.
918 */
919 txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
920 txpwr->mcs_40_siso[i] = 0;
921 }
922
923 /* Fill in the MCS 0-7 CDD rates */
924 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
925 txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
926 txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
927 }
928
929 /*
930 * These locales have SISO expressed in the
931 * table and override CDD later
932 */
933 if (li_mimo == &locale_bn) {
934 if (li_mimo == &locale_bn) {
935 maxpwr20 = QDB(16);
936 maxpwr40 = 0;
937
938 if (chan >= 3 && chan <= 11)
939 maxpwr40 = QDB(16);
940 }
941
942 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
943 txpwr->mcs_20_siso[i] = (u8) maxpwr20;
944 txpwr->mcs_40_siso[i] = (u8) maxpwr40;
945 }
946 }
947
948 /* Fill in the MCS 0-7 STBC rates */
949 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
950 txpwr->mcs_20_stbc[i] = 0;
951 txpwr->mcs_40_stbc[i] = 0;
952 }
953
954 /* Fill in the MCS 8-15 SDM rates */
955 for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++) {
956 txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
957 txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
958 }
959
960 /* Fill in MCS32 */
961 txpwr->mcs32 = (u8) maxpwr40;
962
963 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
964 if (txpwr->ofdm_40_cdd[i] == 0)
965 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
966 if (i == 0) {
967 i = i + 1;
968 if (txpwr->ofdm_40_cdd[i] == 0)
969 txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
970 }
971 }
972
973 /*
974 * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
975 * value if it wasn't provided explicitly.
976 */
977 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
978 if (txpwr->mcs_40_siso[i] == 0)
979 txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
980 }
981
982 for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
983 if (txpwr->ofdm_40_siso[i] == 0)
984 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
985 if (i == 0) {
986 i = i + 1;
987 if (txpwr->ofdm_40_siso[i] == 0)
988 txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
989 }
990 }
991
992 /*
993 * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
994 * STBC values if they weren't provided explicitly.
995 */
996 for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
997 if (txpwr->mcs_20_stbc[i] == 0)
998 txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
999
1000 if (txpwr->mcs_40_stbc[i] == 0)
1001 txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
1002 }
1003
Arend van Spriel5b435de2011-10-05 13:19:03 +02001004 return;
1005}
1006
1007/*
Alwin Beukers3de67812011-10-12 20:51:29 +02001008 * Verify the chanspec is using a legal set of parameters, i.e. that the
1009 * chanspec specified a band, bw, ctl_sb and channel and that the
1010 * combination could be legal given any set of circumstances.
1011 * RETURNS: true is the chanspec is malformed, false if it looks good.
1012 */
1013static bool brcms_c_chspec_malformed(u16 chanspec)
1014{
1015 /* must be 2G or 5G band */
1016 if (!CHSPEC_IS5G(chanspec) && !CHSPEC_IS2G(chanspec))
1017 return true;
1018 /* must be 20 or 40 bandwidth */
1019 if (!CHSPEC_IS40(chanspec) && !CHSPEC_IS20(chanspec))
1020 return true;
1021
1022 /* 20MHZ b/w must have no ctl sb, 40 must have a ctl sb */
1023 if (CHSPEC_IS20(chanspec)) {
1024 if (!CHSPEC_SB_NONE(chanspec))
1025 return true;
1026 } else if (!CHSPEC_SB_UPPER(chanspec) && !CHSPEC_SB_LOWER(chanspec)) {
1027 return true;
1028 }
1029
1030 return false;
1031}
1032
1033/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001034 * Validate the chanspec for this locale, for 40MHZ we need to also
1035 * check that the sidebands are valid 20MZH channels in this locale
1036 * and they are also a legal HT combination
1037 */
1038static bool
1039brcms_c_valid_chanspec_ext(struct brcms_cm_info *wlc_cm, u16 chspec,
1040 bool dualband)
1041{
1042 struct brcms_c_info *wlc = wlc_cm->wlc;
1043 u8 channel = CHSPEC_CHANNEL(chspec);
1044
1045 /* check the chanspec */
Alwin Beukers3de67812011-10-12 20:51:29 +02001046 if (brcms_c_chspec_malformed(chspec)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001047 wiphy_err(wlc->wiphy, "wl%d: malformed chanspec 0x%x\n",
1048 wlc->pub->unit, chspec);
1049 return false;
1050 }
1051
1052 if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
1053 chspec_bandunit(chspec))
1054 return false;
1055
1056 /* Check a 20Mhz channel */
1057 if (CHSPEC_IS20(chspec)) {
1058 if (dualband)
1059 return brcms_c_valid_channel20_db(wlc_cm->wlc->cmi,
1060 channel);
1061 else
1062 return brcms_c_valid_channel20(wlc_cm->wlc->cmi,
1063 channel);
1064 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001065
1066 return false;
1067}
1068
1069bool brcms_c_valid_chanspec_db(struct brcms_cm_info *wlc_cm, u16 chspec)
1070{
1071 return brcms_c_valid_chanspec_ext(wlc_cm, chspec, true);
1072}
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001073
1074static bool brcms_is_radar_freq(u16 center_freq)
1075{
1076 return center_freq >= 5260 && center_freq <= 5700;
1077}
1078
1079static void brcms_reg_apply_radar_flags(struct wiphy *wiphy)
1080{
1081 struct ieee80211_supported_band *sband;
1082 struct ieee80211_channel *ch;
1083 int i;
1084
1085 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
1086 if (!sband)
1087 return;
1088
1089 for (i = 0; i < sband->n_channels; i++) {
1090 ch = &sband->channels[i];
1091
1092 if (!brcms_is_radar_freq(ch->center_freq))
1093 continue;
1094
1095 /*
1096 * All channels in this range should be passive and have
1097 * DFS enabled.
1098 */
1099 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
1100 ch->flags |= IEEE80211_CHAN_RADAR |
1101 IEEE80211_CHAN_NO_IBSS |
1102 IEEE80211_CHAN_PASSIVE_SCAN;
1103 }
1104}
1105
1106static void
1107brcms_reg_apply_beaconing_flags(struct wiphy *wiphy,
1108 enum nl80211_reg_initiator initiator)
1109{
1110 struct ieee80211_supported_band *sband;
1111 struct ieee80211_channel *ch;
1112 const struct ieee80211_reg_rule *rule;
1113 int band, i, ret;
1114
1115 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1116 sband = wiphy->bands[band];
1117 if (!sband)
1118 continue;
1119
1120 for (i = 0; i < sband->n_channels; i++) {
1121 ch = &sband->channels[i];
1122
1123 if (ch->flags &
1124 (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_RADAR))
1125 continue;
1126
1127 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1128 ret = freq_reg_info(wiphy, ch->center_freq,
1129 0, &rule);
1130 if (ret)
1131 continue;
1132
1133 if (!(rule->flags & NL80211_RRF_NO_IBSS))
1134 ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
1135 if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
1136 ch->flags &=
1137 ~IEEE80211_CHAN_PASSIVE_SCAN;
1138 } else if (ch->beacon_found) {
1139 ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
1140 IEEE80211_CHAN_PASSIVE_SCAN);
1141 }
1142 }
1143 }
1144}
1145
1146static int brcms_reg_notifier(struct wiphy *wiphy,
1147 struct regulatory_request *request)
1148{
1149 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1150 struct brcms_info *wl = hw->priv;
1151 struct brcms_c_info *wlc = wl->wlc;
Seth Forshee2ab631f2012-06-16 07:47:53 -05001152 struct ieee80211_supported_band *sband;
1153 struct ieee80211_channel *ch;
1154 int band, i;
1155 bool ch_found = false;
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001156
1157 brcms_reg_apply_radar_flags(wiphy);
1158
1159 if (request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
1160 brcms_reg_apply_beaconing_flags(wiphy, request->initiator);
1161
Seth Forshee2ab631f2012-06-16 07:47:53 -05001162 /* Disable radio if all channels disallowed by regulatory */
1163 for (band = 0; !ch_found && band < IEEE80211_NUM_BANDS; band++) {
1164 sband = wiphy->bands[band];
1165 if (!sband)
1166 continue;
1167
1168 for (i = 0; !ch_found && i < sband->n_channels; i++) {
1169 ch = &sband->channels[i];
1170
1171 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
1172 ch_found = true;
1173 }
1174 }
1175
1176 if (ch_found) {
1177 mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
1178 } else {
1179 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
1180 wiphy_err(wlc->wiphy, "wl%d: %s: no valid channel for \"%s\"\n",
1181 wlc->pub->unit, __func__, request->alpha2);
1182 }
1183
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001184 if (wlc->pub->_nbands > 1 || wlc->band->bandtype == BRCM_BAND_2G)
1185 wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
1186 brcms_c_japan_ccode(request->alpha2));
1187
1188 return 0;
1189}
1190
1191void brcms_c_regd_init(struct brcms_c_info *wlc)
1192{
1193 struct wiphy *wiphy = wlc->wiphy;
1194 const struct brcms_regd *regd = wlc->cmi->world_regd;
1195 struct ieee80211_supported_band *sband;
1196 struct ieee80211_channel *ch;
1197 struct brcms_chanvec sup_chan;
1198 struct brcms_band *band;
1199 int band_idx, i;
1200
1201 /* Disable any channels not supported by the phy */
1202 for (band_idx = 0; band_idx < IEEE80211_NUM_BANDS; band_idx++) {
1203 if (band_idx == IEEE80211_BAND_2GHZ)
1204 band = wlc->bandstate[BAND_2G_INDEX];
1205 else
1206 band = wlc->bandstate[BAND_5G_INDEX];
1207 wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
1208 &sup_chan);
1209
1210 sband = wiphy->bands[band_idx];
1211 for (i = 0; i < sband->n_channels; i++) {
1212 ch = &sband->channels[i];
1213 if (!isset(sup_chan.vec, ch->hw_value))
1214 ch->flags |= IEEE80211_CHAN_DISABLED;
1215 }
1216 }
1217
1218 wlc->wiphy->reg_notifier = brcms_reg_notifier;
1219 wlc->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
1220 WIPHY_FLAG_STRICT_REGULATORY;
1221 wiphy_apply_custom_regulatory(wlc->wiphy, regd->regdomain);
1222 brcms_reg_apply_beaconing_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER);
1223}