Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: Channel, Frequence and Power |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "cfg80211.h" |
| 26 | |
| 27 | /* 100mW */ |
| 28 | #define MWIFIEX_TX_PWR_DEFAULT 20 |
| 29 | /* 100mW */ |
| 30 | #define MWIFIEX_TX_PWR_US_DEFAULT 20 |
| 31 | /* 50mW */ |
| 32 | #define MWIFIEX_TX_PWR_JP_DEFAULT 16 |
| 33 | /* 100mW */ |
| 34 | #define MWIFIEX_TX_PWR_FR_100MW 20 |
| 35 | /* 10mW */ |
| 36 | #define MWIFIEX_TX_PWR_FR_10MW 10 |
| 37 | /* 100mW */ |
| 38 | #define MWIFIEX_TX_PWR_EMEA_DEFAULT 20 |
| 39 | |
| 40 | static u8 adhoc_rates_b[B_SUPPORTED_RATES] = { 0x82, 0x84, 0x8b, 0x96, 0 }; |
| 41 | |
| 42 | static u8 adhoc_rates_g[G_SUPPORTED_RATES] = { 0x8c, 0x12, 0x98, 0x24, |
| 43 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
| 44 | |
| 45 | static u8 adhoc_rates_bg[BG_SUPPORTED_RATES] = { 0x82, 0x84, 0x8b, 0x96, |
| 46 | 0x0c, 0x12, 0x18, 0x24, |
| 47 | 0x30, 0x48, 0x60, 0x6c, 0 }; |
| 48 | |
| 49 | static u8 adhoc_rates_a[A_SUPPORTED_RATES] = { 0x8c, 0x12, 0x98, 0x24, |
| 50 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 51 | static u8 supported_rates_a[A_SUPPORTED_RATES] = { 0x0c, 0x12, 0x18, 0x24, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 52 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
| 53 | static u16 mwifiex_data_rates[MWIFIEX_SUPPORTED_RATES_EXT] = { 0x02, 0x04, |
| 54 | 0x0B, 0x16, 0x00, 0x0C, 0x12, 0x18, |
| 55 | 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90, |
| 56 | 0x0D, 0x1A, 0x27, 0x34, 0x4E, 0x68, |
| 57 | 0x75, 0x82, 0x0C, 0x1B, 0x36, 0x51, |
| 58 | 0x6C, 0xA2, 0xD8, 0xF3, 0x10E, 0x00 }; |
| 59 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 60 | static u8 supported_rates_b[B_SUPPORTED_RATES] = { 0x02, 0x04, 0x0b, 0x16, 0 }; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 61 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 62 | static u8 supported_rates_g[G_SUPPORTED_RATES] = { 0x0c, 0x12, 0x18, 0x24, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 63 | 0x30, 0x48, 0x60, 0x6c, 0 }; |
| 64 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 65 | static u8 supported_rates_bg[BG_SUPPORTED_RATES] = { 0x02, 0x04, 0x0b, 0x0c, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 66 | 0x12, 0x16, 0x18, 0x24, 0x30, 0x48, |
| 67 | 0x60, 0x6c, 0 }; |
| 68 | |
| 69 | u16 region_code_index[MWIFIEX_MAX_REGION_CODE] = { 0x10, 0x20, 0x30, |
| 70 | 0x32, 0x40, 0x41, 0xff }; |
| 71 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 72 | static u8 supported_rates_n[N_SUPPORTED_RATES] = { 0x02, 0x04, 0 }; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 73 | |
Amitkumar Karwar | 9e04a7c | 2012-04-09 20:06:54 -0700 | [diff] [blame] | 74 | struct region_code_mapping { |
| 75 | u8 code; |
| 76 | u8 region[IEEE80211_COUNTRY_STRING_LEN]; |
| 77 | }; |
| 78 | |
| 79 | static struct region_code_mapping region_code_mapping_t[] = { |
| 80 | { 0x10, "US " }, /* US FCC */ |
| 81 | { 0x20, "CA " }, /* IC Canada */ |
| 82 | { 0x30, "EU " }, /* ETSI */ |
| 83 | { 0x31, "ES " }, /* Spain */ |
| 84 | { 0x32, "FR " }, /* France */ |
| 85 | { 0x40, "JP " }, /* Japan */ |
| 86 | { 0x41, "JP " }, /* Japan */ |
| 87 | { 0x50, "CN " }, /* China */ |
| 88 | }; |
| 89 | |
| 90 | /* This function converts integer code to region string */ |
| 91 | u8 *mwifiex_11d_code_2_region(u8 code) |
| 92 | { |
| 93 | u8 i; |
| 94 | u8 size = sizeof(region_code_mapping_t)/ |
| 95 | sizeof(struct region_code_mapping); |
| 96 | |
| 97 | /* Look for code in mapping table */ |
| 98 | for (i = 0; i < size; i++) |
| 99 | if (region_code_mapping_t[i].code == code) |
| 100 | return region_code_mapping_t[i].region; |
| 101 | |
| 102 | return NULL; |
| 103 | } |
| 104 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 105 | /* |
| 106 | * This function maps an index in supported rates table into |
| 107 | * the corresponding data rate. |
| 108 | */ |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 109 | u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index, |
| 110 | u8 ht_info) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 111 | { |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 112 | /* |
| 113 | * For every mcs_rate line, the first 8 bytes are for stream 1x1, |
| 114 | * and all 16 bytes are for stream 2x2. |
| 115 | */ |
| 116 | u16 mcs_rate[4][16] = { |
| 117 | /* LGI 40M */ |
| 118 | { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e, |
| 119 | 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c }, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 120 | |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 121 | /* SGI 40M */ |
| 122 | { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c, |
| 123 | 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 }, |
| 124 | |
| 125 | /* LGI 20M */ |
| 126 | { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82, |
| 127 | 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 }, |
| 128 | |
| 129 | /* SGI 20M */ |
| 130 | { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90, |
| 131 | 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 } |
| 132 | }; |
| 133 | u32 mcs_num_supp = |
| 134 | (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) ? 16 : 8; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 135 | u32 rate; |
| 136 | |
| 137 | if (ht_info & BIT(0)) { |
| 138 | if (index == MWIFIEX_RATE_BITMAP_MCS0) { |
| 139 | if (ht_info & BIT(2)) |
| 140 | rate = 0x0D; /* MCS 32 SGI rate */ |
| 141 | else |
| 142 | rate = 0x0C; /* MCS 32 LGI rate */ |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 143 | } else if (index < mcs_num_supp) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 144 | if (ht_info & BIT(1)) { |
| 145 | if (ht_info & BIT(2)) |
| 146 | /* SGI, 40M */ |
| 147 | rate = mcs_rate[1][index]; |
| 148 | else |
| 149 | /* LGI, 40M */ |
| 150 | rate = mcs_rate[0][index]; |
| 151 | } else { |
| 152 | if (ht_info & BIT(2)) |
| 153 | /* SGI, 20M */ |
| 154 | rate = mcs_rate[3][index]; |
| 155 | else |
| 156 | /* LGI, 20M */ |
| 157 | rate = mcs_rate[2][index]; |
| 158 | } |
| 159 | } else |
| 160 | rate = mwifiex_data_rates[0]; |
| 161 | } else { |
| 162 | if (index >= MWIFIEX_SUPPORTED_RATES_EXT) |
| 163 | index = 0; |
| 164 | rate = mwifiex_data_rates[index]; |
| 165 | } |
| 166 | return rate; |
| 167 | } |
| 168 | |
| 169 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 170 | * This function returns the current active data rates. |
| 171 | * |
| 172 | * The result may vary depending upon connection status. |
| 173 | */ |
| 174 | u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv, u8 *rates) |
| 175 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 176 | if (!priv->media_connected) |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 177 | return mwifiex_get_supported_rates(priv, rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 178 | else |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 179 | return mwifiex_copy_rates(rates, 0, |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 180 | priv->curr_bss_params.data_rates, |
| 181 | priv->curr_bss_params.num_of_rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* |
| 185 | * This function locates the Channel-Frequency-Power triplet based upon |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 186 | * band and channel/frequency parameters. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 187 | */ |
| 188 | struct mwifiex_chan_freq_power * |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 189 | mwifiex_get_cfp(struct mwifiex_private *priv, u8 band, u16 channel, u32 freq) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 190 | { |
| 191 | struct mwifiex_chan_freq_power *cfp = NULL; |
| 192 | struct ieee80211_supported_band *sband; |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 193 | struct ieee80211_channel *ch = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 194 | int i; |
| 195 | |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 196 | if (!channel && !freq) |
| 197 | return cfp; |
| 198 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 199 | if (mwifiex_band_to_radio_type(band) == HostCmd_SCAN_RADIO_TYPE_BG) |
| 200 | sband = priv->wdev->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 201 | else |
| 202 | sband = priv->wdev->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 203 | |
| 204 | if (!sband) { |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 205 | dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d\n", |
| 206 | __func__, band); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 207 | return cfp; |
| 208 | } |
| 209 | |
| 210 | for (i = 0; i < sband->n_channels; i++) { |
| 211 | ch = &sband->channels[i]; |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 212 | |
| 213 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 214 | continue; |
| 215 | |
| 216 | if (freq) { |
| 217 | if (ch->center_freq == freq) |
| 218 | break; |
| 219 | } else { |
| 220 | /* find by valid channel*/ |
| 221 | if (ch->hw_value == channel || |
| 222 | channel == FIRST_VALID_CHANNEL) |
| 223 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 226 | if (i == sband->n_channels) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 227 | dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d" |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 228 | " & channel=%d freq=%d\n", __func__, band, channel, |
| 229 | freq); |
| 230 | } else { |
| 231 | if (!ch) |
| 232 | return cfp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 233 | |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 234 | priv->cfp.channel = ch->hw_value; |
| 235 | priv->cfp.freq = ch->center_freq; |
| 236 | priv->cfp.max_tx_power = ch->max_power; |
| 237 | cfp = &priv->cfp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 240 | return cfp; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * This function checks if the data rate is set to auto. |
| 245 | */ |
| 246 | u8 |
| 247 | mwifiex_is_rate_auto(struct mwifiex_private *priv) |
| 248 | { |
| 249 | u32 i; |
| 250 | int rate_num = 0; |
| 251 | |
| 252 | for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates); i++) |
| 253 | if (priv->bitmap_rates[i]) |
| 254 | rate_num++; |
| 255 | |
| 256 | if (rate_num > 1) |
| 257 | return true; |
| 258 | else |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 263 | * This function gets the supported data rates. |
| 264 | * |
| 265 | * The function works in both Ad-Hoc and infra mode by printing the |
| 266 | * band and returning the data rates. |
| 267 | */ |
| 268 | u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates) |
| 269 | { |
| 270 | u32 k = 0; |
| 271 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 272 | if (priv->bss_mode == NL80211_IFTYPE_STATION) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 273 | switch (adapter->config_bands) { |
| 274 | case BAND_B: |
| 275 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 276 | "supported_rates_b\n", adapter->config_bands); |
| 277 | k = mwifiex_copy_rates(rates, k, supported_rates_b, |
| 278 | sizeof(supported_rates_b)); |
| 279 | break; |
| 280 | case BAND_G: |
| 281 | case BAND_G | BAND_GN: |
| 282 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 283 | "supported_rates_g\n", adapter->config_bands); |
| 284 | k = mwifiex_copy_rates(rates, k, supported_rates_g, |
| 285 | sizeof(supported_rates_g)); |
| 286 | break; |
| 287 | case BAND_B | BAND_G: |
| 288 | case BAND_A | BAND_B | BAND_G: |
| 289 | case BAND_A | BAND_B: |
| 290 | case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN: |
| 291 | case BAND_B | BAND_G | BAND_GN: |
| 292 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 293 | "supported_rates_bg\n", adapter->config_bands); |
| 294 | k = mwifiex_copy_rates(rates, k, supported_rates_bg, |
| 295 | sizeof(supported_rates_bg)); |
| 296 | break; |
| 297 | case BAND_A: |
| 298 | case BAND_A | BAND_G: |
| 299 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 300 | "supported_rates_a\n", adapter->config_bands); |
| 301 | k = mwifiex_copy_rates(rates, k, supported_rates_a, |
| 302 | sizeof(supported_rates_a)); |
| 303 | break; |
| 304 | case BAND_A | BAND_AN: |
| 305 | case BAND_A | BAND_G | BAND_AN | BAND_GN: |
| 306 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 307 | "supported_rates_a\n", adapter->config_bands); |
| 308 | k = mwifiex_copy_rates(rates, k, supported_rates_a, |
| 309 | sizeof(supported_rates_a)); |
| 310 | break; |
| 311 | case BAND_GN: |
| 312 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 313 | "supported_rates_n\n", adapter->config_bands); |
| 314 | k = mwifiex_copy_rates(rates, k, supported_rates_n, |
| 315 | sizeof(supported_rates_n)); |
| 316 | break; |
| 317 | } |
| 318 | } else { |
| 319 | /* Ad-hoc mode */ |
| 320 | switch (adapter->adhoc_start_band) { |
| 321 | case BAND_B: |
| 322 | dev_dbg(adapter->dev, "info: adhoc B\n"); |
| 323 | k = mwifiex_copy_rates(rates, k, adhoc_rates_b, |
| 324 | sizeof(adhoc_rates_b)); |
| 325 | break; |
| 326 | case BAND_G: |
| 327 | case BAND_G | BAND_GN: |
| 328 | dev_dbg(adapter->dev, "info: adhoc G only\n"); |
| 329 | k = mwifiex_copy_rates(rates, k, adhoc_rates_g, |
| 330 | sizeof(adhoc_rates_g)); |
| 331 | break; |
| 332 | case BAND_B | BAND_G: |
| 333 | case BAND_B | BAND_G | BAND_GN: |
| 334 | dev_dbg(adapter->dev, "info: adhoc BG\n"); |
| 335 | k = mwifiex_copy_rates(rates, k, adhoc_rates_bg, |
| 336 | sizeof(adhoc_rates_bg)); |
| 337 | break; |
| 338 | case BAND_A: |
| 339 | case BAND_A | BAND_AN: |
| 340 | dev_dbg(adapter->dev, "info: adhoc A\n"); |
| 341 | k = mwifiex_copy_rates(rates, k, adhoc_rates_a, |
| 342 | sizeof(adhoc_rates_a)); |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | return k; |
| 348 | } |