2 * Marvell Wireless LAN device driver: Channel, Frequence and Power
4 * Copyright (C) 2011, 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
] = { 0x10, 0x20, 0x30,
70 0x32, 0x40, 0x41, 0xff };
72 static u8 supported_rates_n
[N_SUPPORTED_RATES
] = { 0x02, 0x04, 0 };
74 struct region_code_mapping
{
76 u8 region
[IEEE80211_COUNTRY_STRING_LEN
];
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 */
90 /* This function converts integer code to region string */
91 u8
*mwifiex_11d_code_2_region(u8 code
)
94 u8 size
= sizeof(region_code_mapping_t
)/
95 sizeof(struct region_code_mapping
);
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
;
106 * This function maps an index in supported rates table into
107 * the corresponding data rate.
109 u32
mwifiex_index_to_data_rate(struct mwifiex_private
*priv
, u8 index
,
113 * For every mcs_rate line, the first 8 bytes are for stream 1x1,
114 * and all 16 bytes are for stream 2x2.
116 u16 mcs_rate
[4][16] = {
118 { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e,
119 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c },
122 { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c,
123 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 },
126 { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82,
127 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 },
130 { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90,
131 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 }
134 (priv
->adapter
->hw_dev_mcs_support
== HT_STREAM_2X2
) ? 16 : 8;
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 */
142 rate
= 0x0C; /* MCS 32 LGI rate */
143 } else if (index
< mcs_num_supp
) {
144 if (ht_info
& BIT(1)) {
145 if (ht_info
& BIT(2))
147 rate
= mcs_rate
[1][index
];
150 rate
= mcs_rate
[0][index
];
152 if (ht_info
& BIT(2))
154 rate
= mcs_rate
[3][index
];
157 rate
= mcs_rate
[2][index
];
160 rate
= mwifiex_data_rates
[0];
162 if (index
>= MWIFIEX_SUPPORTED_RATES_EXT
)
164 rate
= mwifiex_data_rates
[index
];
170 * This function maps a data rate value into corresponding index in supported
173 u8
mwifiex_data_rate_to_index(u32 rate
)
178 ptr
= memchr(mwifiex_data_rates
, rate
,
179 sizeof(mwifiex_data_rates
));
181 return (u8
) (ptr
- mwifiex_data_rates
);
187 * This function returns the current active data rates.
189 * The result may vary depending upon connection status.
191 u32
mwifiex_get_active_data_rates(struct mwifiex_private
*priv
, u8
*rates
)
193 if (!priv
->media_connected
)
194 return mwifiex_get_supported_rates(priv
, rates
);
196 return mwifiex_copy_rates(rates
, 0,
197 priv
->curr_bss_params
.data_rates
,
198 priv
->curr_bss_params
.num_of_rates
);
202 * This function locates the Channel-Frequency-Power triplet based upon
203 * band and channel/frequency parameters.
205 struct mwifiex_chan_freq_power
*
206 mwifiex_get_cfp(struct mwifiex_private
*priv
, u8 band
, u16 channel
, u32 freq
)
208 struct mwifiex_chan_freq_power
*cfp
= NULL
;
209 struct ieee80211_supported_band
*sband
;
210 struct ieee80211_channel
*ch
= NULL
;
213 if (!channel
&& !freq
)
216 if (mwifiex_band_to_radio_type(band
) == HostCmd_SCAN_RADIO_TYPE_BG
)
217 sband
= priv
->wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
219 sband
= priv
->wdev
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
222 dev_err(priv
->adapter
->dev
, "%s: cannot find cfp by band %d\n",
227 for (i
= 0; i
< sband
->n_channels
; i
++) {
228 ch
= &sband
->channels
[i
];
230 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
234 if (ch
->center_freq
== freq
)
237 /* find by valid channel*/
238 if (ch
->hw_value
== channel
||
239 channel
== FIRST_VALID_CHANNEL
)
243 if (i
== sband
->n_channels
) {
244 dev_err(priv
->adapter
->dev
, "%s: cannot find cfp by band %d"
245 " & channel=%d freq=%d\n", __func__
, band
, channel
,
251 priv
->cfp
.channel
= ch
->hw_value
;
252 priv
->cfp
.freq
= ch
->center_freq
;
253 priv
->cfp
.max_tx_power
= ch
->max_power
;
261 * This function checks if the data rate is set to auto.
264 mwifiex_is_rate_auto(struct mwifiex_private
*priv
)
269 for (i
= 0; i
< ARRAY_SIZE(priv
->bitmap_rates
); i
++)
270 if (priv
->bitmap_rates
[i
])
280 * This function converts rate bitmap into rate index.
282 int mwifiex_get_rate_index(u16
*rate_bitmap
, int size
)
286 for (i
= 0; i
< size
* 8; i
++)
287 if (rate_bitmap
[i
/ 16] & (1 << (i
% 16)))
294 * This function gets the supported data rates.
296 * The function works in both Ad-Hoc and infra mode by printing the
297 * band and returning the data rates.
299 u32
mwifiex_get_supported_rates(struct mwifiex_private
*priv
, u8
*rates
)
302 struct mwifiex_adapter
*adapter
= priv
->adapter
;
303 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
) {
304 switch (adapter
->config_bands
) {
306 dev_dbg(adapter
->dev
, "info: infra band=%d "
307 "supported_rates_b\n", adapter
->config_bands
);
308 k
= mwifiex_copy_rates(rates
, k
, supported_rates_b
,
309 sizeof(supported_rates_b
));
312 case BAND_G
| BAND_GN
:
313 dev_dbg(adapter
->dev
, "info: infra band=%d "
314 "supported_rates_g\n", adapter
->config_bands
);
315 k
= mwifiex_copy_rates(rates
, k
, supported_rates_g
,
316 sizeof(supported_rates_g
));
318 case BAND_B
| BAND_G
:
319 case BAND_A
| BAND_B
| BAND_G
:
320 case BAND_A
| BAND_B
:
321 case BAND_A
| BAND_B
| BAND_G
| BAND_GN
| BAND_AN
:
322 case BAND_B
| BAND_G
| BAND_GN
:
323 dev_dbg(adapter
->dev
, "info: infra band=%d "
324 "supported_rates_bg\n", adapter
->config_bands
);
325 k
= mwifiex_copy_rates(rates
, k
, supported_rates_bg
,
326 sizeof(supported_rates_bg
));
329 case BAND_A
| BAND_G
:
330 dev_dbg(adapter
->dev
, "info: infra band=%d "
331 "supported_rates_a\n", adapter
->config_bands
);
332 k
= mwifiex_copy_rates(rates
, k
, supported_rates_a
,
333 sizeof(supported_rates_a
));
335 case BAND_A
| BAND_AN
:
336 case BAND_A
| BAND_G
| BAND_AN
| BAND_GN
:
337 dev_dbg(adapter
->dev
, "info: infra band=%d "
338 "supported_rates_a\n", adapter
->config_bands
);
339 k
= mwifiex_copy_rates(rates
, k
, supported_rates_a
,
340 sizeof(supported_rates_a
));
343 dev_dbg(adapter
->dev
, "info: infra band=%d "
344 "supported_rates_n\n", adapter
->config_bands
);
345 k
= mwifiex_copy_rates(rates
, k
, supported_rates_n
,
346 sizeof(supported_rates_n
));
351 switch (adapter
->adhoc_start_band
) {
353 dev_dbg(adapter
->dev
, "info: adhoc B\n");
354 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_b
,
355 sizeof(adhoc_rates_b
));
358 case BAND_G
| BAND_GN
:
359 dev_dbg(adapter
->dev
, "info: adhoc G only\n");
360 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_g
,
361 sizeof(adhoc_rates_g
));
363 case BAND_B
| BAND_G
:
364 case BAND_B
| BAND_G
| BAND_GN
:
365 dev_dbg(adapter
->dev
, "info: adhoc BG\n");
366 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_bg
,
367 sizeof(adhoc_rates_bg
));
370 case BAND_A
| BAND_AN
:
371 dev_dbg(adapter
->dev
, "info: adhoc A\n");
372 k
= mwifiex_copy_rates(rates
, k
, adhoc_rates_a
,
373 sizeof(adhoc_rates_a
));