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