2 * Marvell Wireless LAN device driver: Channel, Frequence and Power
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
28 #define MWIFIEX_TX_PWR_DEFAULT 20
30 #define MWIFIEX_TX_PWR_US_DEFAULT 20
32 #define MWIFIEX_TX_PWR_JP_DEFAULT 16
34 #define MWIFIEX_TX_PWR_FR_100MW 20
36 #define MWIFIEX_TX_PWR_FR_10MW 10
38 #define MWIFIEX_TX_PWR_EMEA_DEFAULT 20
40 static u8 adhoc_rates_b
[B_SUPPORTED_RATES
] = { 0x82, 0x84, 0x8b, 0x96, 0 };
42 static u8 adhoc_rates_g
[G_SUPPORTED_RATES
] = { 0x8c, 0x12, 0x98, 0x24,
43 0xb0, 0x48, 0x60, 0x6c, 0 };
45 static u8 adhoc_rates_bg
[BG_SUPPORTED_RATES
] = { 0x82, 0x84, 0x8b, 0x96,
46 0x0c, 0x12, 0x18, 0x24,
47 0x30, 0x48, 0x60, 0x6c, 0 };
49 static u8 adhoc_rates_a
[A_SUPPORTED_RATES
] = { 0x8c, 0x12, 0x98, 0x24,
50 0xb0, 0x48, 0x60, 0x6c, 0 };
51 static u8 supported_rates_a
[A_SUPPORTED_RATES
] = { 0x0c, 0x12, 0x18, 0x24,
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 };
60 static u8 supported_rates_b
[B_SUPPORTED_RATES
] = { 0x02, 0x04, 0x0b, 0x16, 0 };
62 static u8 supported_rates_g
[G_SUPPORTED_RATES
] = { 0x0c, 0x12, 0x18, 0x24,
63 0x30, 0x48, 0x60, 0x6c, 0 };
65 static u8 supported_rates_bg
[BG_SUPPORTED_RATES
] = { 0x02, 0x04, 0x0b, 0x0c,
66 0x12, 0x16, 0x18, 0x24, 0x30, 0x48,
69 u16 region_code_index
[MWIFIEX_MAX_REGION_CODE
] = { 0x00, 0x10, 0x20, 0x30,
70 0x31, 0x32, 0x40, 0x41, 0x50 };
72 static u8 supported_rates_n
[N_SUPPORTED_RATES
] = { 0x02, 0x04, 0 };
74 /* For every mcs_rate line, the first 8 bytes are for stream 1x1,
75 * and all 16 bytes are for stream 2x2.
77 static const u16 mcs_rate
[4][16] = {
79 { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e,
80 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c },
83 { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c,
84 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 },
87 { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82,
88 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 },
91 { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90,
92 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 }
96 static const u16 ac_mcs_rate_nss1
[8][10] = {
98 { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D,
99 0x492, 0x57C, 0x618 },
102 { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492,
103 0x514, 0x618, 0x6C6 },
106 { 0x3B, 0x75, 0xB0, 0xEA, 0x15F, 0x1D4, 0x20F,
107 0x249, 0x2BE, 0x30C },
110 { 0x41, 0x82, 0xC3, 0x104, 0x186, 0x208, 0x249,
111 0x28A, 0x30C, 0x363 },
114 { 0x1B, 0x36, 0x51, 0x6C, 0xA2, 0xD8, 0xF3,
115 0x10E, 0x144, 0x168 },
118 { 0x1E, 0x3C, 0x5A, 0x78, 0xB4, 0xF0, 0x10E,
119 0x12C, 0x168, 0x190 },
122 { 0xD, 0x1A, 0x27, 0x34, 0x4E, 0x68, 0x75, 0x82, 0x9C, 0x00 },
125 { 0xF, 0x1D, 0x2C, 0x3A, 0x57, 0x74, 0x82, 0x91, 0xAE, 0x00 },
128 /* NSS2 note: the value in the table is 2 multiplier of the actual rate */
129 static const u16 ac_mcs_rate_nss2
[8][10] = {
131 { 0xEA, 0x1D4, 0x2BE, 0x3A8, 0x57C, 0x750, 0x83A,
132 0x924, 0xAF8, 0xC30 },
135 { 0x104, 0x208, 0x30C, 0x410, 0x618, 0x820, 0x924,
136 0xA28, 0xC30, 0xD8B },
139 { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D,
140 0x492, 0x57C, 0x618 },
143 { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492,
144 0x514, 0x618, 0x6C6 },
147 { 0x36, 0x6C, 0xA2, 0xD8, 0x144, 0x1B0, 0x1E6,
148 0x21C, 0x288, 0x2D0 },
151 { 0x3C, 0x78, 0xB4, 0xF0, 0x168, 0x1E0, 0x21C,
152 0x258, 0x2D0, 0x320 },
155 { 0x1A, 0x34, 0x4A, 0x68, 0x9C, 0xD0, 0xEA, 0x104,
159 { 0x1D, 0x3A, 0x57, 0x74, 0xAE, 0xE6, 0x104, 0x121,
163 struct region_code_mapping
{
165 u8 region
[IEEE80211_COUNTRY_STRING_LEN
];
168 static struct region_code_mapping region_code_mapping_t
[] = {
169 { 0x10, "US " }, /* US FCC */
170 { 0x20, "CA " }, /* IC Canada */
171 { 0x30, "FR " }, /* France */
172 { 0x31, "ES " }, /* Spain */
173 { 0x32, "FR " }, /* France */
174 { 0x40, "JP " }, /* Japan */
175 { 0x41, "JP " }, /* Japan */
176 { 0x50, "CN " }, /* China */
179 /* This function converts integer code to region string */
180 u8
*mwifiex_11d_code_2_region(u8 code
)
183 u8 size
= sizeof(region_code_mapping_t
)/
184 sizeof(struct region_code_mapping
);
186 /* Look for code in mapping table */
187 for (i
= 0; i
< size
; i
++)
188 if (region_code_mapping_t
[i
].code
== code
)
189 return region_code_mapping_t
[i
].region
;
195 * This function maps an index in supported rates table into
196 * the corresponding data rate.
198 u32
mwifiex_index_to_acs_data_rate(struct mwifiex_private
*priv
,
199 u8 index
, u8 ht_info
)
206 if ((ht_info
& 0x3) == MWIFIEX_RATE_FORMAT_VHT
) {
207 mcs_index
= min(index
& 0xF, 9);
209 /* 20M: bw=0, 40M: bw=1, 80M: bw=2, 160M: bw=3 */
210 bw
= (ht_info
& 0xC) >> 2;
212 /* LGI: gi =0, SGI: gi = 1 */
213 gi
= (ht_info
& 0x10) >> 4;
215 if ((index
>> 4) == 1) /* NSS = 2 */
216 rate
= ac_mcs_rate_nss2
[2 * (3 - bw
) + gi
][mcs_index
];
218 rate
= ac_mcs_rate_nss1
[2 * (3 - bw
) + gi
][mcs_index
];
219 } else if ((ht_info
& 0x3) == MWIFIEX_RATE_FORMAT_HT
) {
220 /* 20M: bw=0, 40M: bw=1 */
221 bw
= (ht_info
& 0xC) >> 2;
223 /* LGI: gi =0, SGI: gi = 1 */
224 gi
= (ht_info
& 0x10) >> 4;
226 if (index
== MWIFIEX_RATE_BITMAP_MCS0
) {
228 rate
= 0x0D; /* MCS 32 SGI rate */
230 rate
= 0x0C; /* MCS 32 LGI rate */
231 } else if (index
< 16) {
232 if ((bw
== 1) || (bw
== 0))
233 rate
= mcs_rate
[2 * (1 - bw
) + gi
][index
];
235 rate
= mwifiex_data_rates
[0];
237 rate
= mwifiex_data_rates
[0];
240 /* 11n non-HT rates */
241 if (index
>= MWIFIEX_SUPPORTED_RATES_EXT
)
243 rate
= mwifiex_data_rates
[index
];
249 /* This function maps an index in supported rates table into
250 * the corresponding data rate.
252 u32
mwifiex_index_to_data_rate(struct mwifiex_private
*priv
,
253 u8 index
, u8 ht_info
)
256 (priv
->adapter
->user_dev_mcs_support
== HT_STREAM_2X2
) ? 16 : 8;
259 if (priv
->adapter
->is_hw_11ac_capable
)
260 return mwifiex_index_to_acs_data_rate(priv
, index
, ht_info
);
262 if (ht_info
& BIT(0)) {
263 if (index
== MWIFIEX_RATE_BITMAP_MCS0
) {
264 if (ht_info
& BIT(2))
265 rate
= 0x0D; /* MCS 32 SGI rate */
267 rate
= 0x0C; /* MCS 32 LGI rate */
268 } else if (index
< mcs_num_supp
) {
269 if (ht_info
& BIT(1)) {
270 if (ht_info
& BIT(2))
272 rate
= mcs_rate
[1][index
];
275 rate
= mcs_rate
[0][index
];
277 if (ht_info
& BIT(2))
279 rate
= mcs_rate
[3][index
];
282 rate
= mcs_rate
[2][index
];
285 rate
= mwifiex_data_rates
[0];
287 if (index
>= MWIFIEX_SUPPORTED_RATES_EXT
)
289 rate
= mwifiex_data_rates
[index
];
295 * This function returns the current active data rates.
297 * The result may vary depending upon connection status.
299 u32
mwifiex_get_active_data_rates(struct mwifiex_private
*priv
, u8
*rates
)
301 if (!priv
->media_connected
)
302 return mwifiex_get_supported_rates(priv
, rates
);
304 return mwifiex_copy_rates(rates
, 0,
305 priv
->curr_bss_params
.data_rates
,
306 priv
->curr_bss_params
.num_of_rates
);
310 * This function locates the Channel-Frequency-Power triplet based upon
311 * band and channel/frequency parameters.
313 struct mwifiex_chan_freq_power
*
314 mwifiex_get_cfp(struct mwifiex_private
*priv
, u8 band
, u16 channel
, u32 freq
)
316 struct mwifiex_chan_freq_power
*cfp
= NULL
;
317 struct ieee80211_supported_band
*sband
;
318 struct ieee80211_channel
*ch
= NULL
;
321 if (!channel
&& !freq
)
324 if (mwifiex_band_to_radio_type(band
) == HostCmd_SCAN_RADIO_TYPE_BG
)
325 sband
= priv
->wdev
.wiphy
->bands
[NL80211_BAND_2GHZ
];
327 sband
= priv
->wdev
.wiphy
->bands
[NL80211_BAND_5GHZ
];
330 mwifiex_dbg(priv
->adapter
, ERROR
,
331 "%s: cannot find cfp by band %d\n",
336 for (i
= 0; i
< sband
->n_channels
; i
++) {
337 ch
= &sband
->channels
[i
];
339 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
343 if (ch
->center_freq
== freq
)
346 /* find by valid channel*/
347 if (ch
->hw_value
== channel
||
348 channel
== FIRST_VALID_CHANNEL
)
352 if (i
== sband
->n_channels
) {
353 mwifiex_dbg(priv
->adapter
, ERROR
,
354 "%s: cannot find cfp by band %d\t"
355 "& channel=%d freq=%d\n",
356 __func__
, band
, channel
, freq
);
361 priv
->cfp
.channel
= ch
->hw_value
;
362 priv
->cfp
.freq
= ch
->center_freq
;
363 priv
->cfp
.max_tx_power
= ch
->max_power
;
371 * This function checks if the data rate is set to auto.
374 mwifiex_is_rate_auto(struct mwifiex_private
*priv
)
379 for (i
= 0; i
< ARRAY_SIZE(priv
->bitmap_rates
); i
++)
380 if (priv
->bitmap_rates
[i
])
389 /* This function gets the supported data rates from bitmask inside
390 * cfg80211_scan_request.
392 u32
mwifiex_get_rates_from_cfg80211(struct mwifiex_private
*priv
,
393 u8
*rates
, u8 radio_type
)
395 struct wiphy
*wiphy
= priv
->adapter
->wiphy
;
396 struct cfg80211_scan_request
*request
= priv
->scan_request
;
397 u32 num_rates
, rate_mask
;
398 struct ieee80211_supported_band
*sband
;
402 sband
= wiphy
->bands
[NL80211_BAND_5GHZ
];
403 if (WARN_ON_ONCE(!sband
))
405 rate_mask
= request
->rates
[NL80211_BAND_5GHZ
];
407 sband
= wiphy
->bands
[NL80211_BAND_2GHZ
];
408 if (WARN_ON_ONCE(!sband
))
410 rate_mask
= request
->rates
[NL80211_BAND_2GHZ
];
414 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
415 if ((BIT(i
) & rate_mask
) == 0)
416 continue; /* skip rate */
417 rates
[num_rates
++] = (u8
)(sband
->bitrates
[i
].bitrate
/ 5);
423 /* This function gets the supported data rates. The function works in
424 * both Ad-Hoc and infra mode by printing the band and returning the
427 u32
mwifiex_get_supported_rates(struct mwifiex_private
*priv
, u8
*rates
)
430 struct mwifiex_adapter
*adapter
= priv
->adapter
;
432 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
||
433 priv
->bss_mode
== NL80211_IFTYPE_P2P_CLIENT
) {
434 switch (adapter
->config_bands
) {
436 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
437 "supported_rates_b\n",
438 adapter
->config_bands
);
439 k
= mwifiex_copy_rates(rates
, k
, supported_rates_b
,
440 sizeof(supported_rates_b
));
443 case BAND_G
| BAND_GN
:
444 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
445 "supported_rates_g\n",
446 adapter
->config_bands
);
447 k
= mwifiex_copy_rates(rates
, k
, supported_rates_g
,
448 sizeof(supported_rates_g
));
450 case BAND_B
| BAND_G
:
451 case BAND_A
| BAND_B
| BAND_G
:
452 case BAND_A
| BAND_B
:
453 case BAND_A
| BAND_B
| BAND_G
| BAND_GN
| BAND_AN
:
454 case BAND_A
| BAND_B
| BAND_G
| BAND_GN
| BAND_AN
| BAND_AAC
:
455 case BAND_B
| BAND_G
| BAND_GN
:
456 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
457 "supported_rates_bg\n",
458 adapter
->config_bands
);
459 k
= mwifiex_copy_rates(rates
, k
, supported_rates_bg
,
460 sizeof(supported_rates_bg
));
463 case BAND_A
| BAND_G
:
464 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
465 "supported_rates_a\n",
466 adapter
->config_bands
);
467 k
= mwifiex_copy_rates(rates
, k
, supported_rates_a
,
468 sizeof(supported_rates_a
));
471 case BAND_A
| BAND_AN
:
472 case BAND_A
| BAND_AN
| BAND_AAC
:
473 case BAND_A
| BAND_G
| BAND_AN
| BAND_GN
:
474 case BAND_A
| BAND_G
| BAND_AN
| BAND_GN
| BAND_AAC
:
475 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
476 "supported_rates_a\n",
477 adapter
->config_bands
);
478 k
= mwifiex_copy_rates(rates
, k
, supported_rates_a
,
479 sizeof(supported_rates_a
));
482 mwifiex_dbg(adapter
, INFO
, "info: infra band=%d\t"
483 "supported_rates_n\n",
484 adapter
->config_bands
);
485 k
= mwifiex_copy_rates(rates
, k
, supported_rates_n
,
486 sizeof(supported_rates_n
));
491 switch (adapter
->adhoc_start_band
) {
493 mwifiex_dbg(adapter
, INFO
, "info: adhoc B\n");
494 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_b
,
495 sizeof(adhoc_rates_b
));
498 case BAND_G
| BAND_GN
:
499 mwifiex_dbg(adapter
, INFO
, "info: adhoc G only\n");
500 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_g
,
501 sizeof(adhoc_rates_g
));
503 case BAND_B
| BAND_G
:
504 case BAND_B
| BAND_G
| BAND_GN
:
505 mwifiex_dbg(adapter
, INFO
, "info: adhoc BG\n");
506 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_bg
,
507 sizeof(adhoc_rates_bg
));
510 case BAND_A
| BAND_AN
:
511 mwifiex_dbg(adapter
, INFO
, "info: adhoc A\n");
512 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_a
,
513 sizeof(adhoc_rates_a
));
521 u8
mwifiex_adjust_data_rate(struct mwifiex_private
*priv
,
522 u8 rx_rate
, u8 rate_info
)
527 if ((rate_info
& BIT(0)) && (rate_info
& BIT(1)))
528 rate_index
= MWIFIEX_RATE_INDEX_MCS0
+
529 MWIFIEX_BW20_MCS_NUM
+ rx_rate
;
530 else if (rate_info
& BIT(0)) /* HT20 */
531 rate_index
= MWIFIEX_RATE_INDEX_MCS0
+ rx_rate
;
533 rate_index
= (rx_rate
> MWIFIEX_RATE_INDEX_OFDM0
) ?
534 rx_rate
- 1 : rx_rate
;