net/xfrm/xfrm_output.c: move EXPORT_SYMBOL
[deliverable/linux.git] / drivers / net / wireless / mwifiex / 11ac.c
1 /*
2 * Marvell Wireless LAN device driver: 802.11ac
3 *
4 * Copyright (C) 2013, 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 "fw.h"
23 #include "main.h"
24 #include "11ac.h"
25
26 /* Tables of the MCS map to the highest data rate (in Mbps) supported
27 * for long GI.
28 */
29 static const u16 max_rate_lgi_80MHZ[8][3] = {
30 {0x124, 0x15F, 0x186}, /* NSS = 1 */
31 {0x249, 0x2BE, 0x30C}, /* NSS = 2 */
32 {0x36D, 0x41D, 0x492}, /* NSS = 3 */
33 {0x492, 0x57C, 0x618}, /* NSS = 4 */
34 {0x5B6, 0x6DB, 0x79E}, /* NSS = 5 */
35 {0x6DB, 0x83A, 0x0}, /* NSS = 6 */
36 {0x7FF, 0x999, 0xAAA}, /* NSS = 7 */
37 {0x924, 0xAF8, 0xC30} /* NSS = 8 */
38 };
39
40 static const u16 max_rate_lgi_160MHZ[8][3] = {
41 {0x249, 0x2BE, 0x30C}, /* NSS = 1 */
42 {0x492, 0x57C, 0x618}, /* NSS = 2 */
43 {0x6DB, 0x83A, 0x0}, /* NSS = 3 */
44 {0x924, 0xAF8, 0xC30}, /* NSS = 4 */
45 {0xB6D, 0xDB6, 0xF3C}, /* NSS = 5 */
46 {0xDB6, 0x1074, 0x1248}, /* NSS = 6 */
47 {0xFFF, 0x1332, 0x1554}, /* NSS = 7 */
48 {0x1248, 0x15F0, 0x1860} /* NSS = 8 */
49 };
50
51 /* This function converts the 2-bit MCS map to the highest long GI
52 * VHT data rate.
53 */
54 static u16
55 mwifiex_convert_mcsmap_to_maxrate(struct mwifiex_private *priv,
56 u8 bands, u16 mcs_map)
57 {
58 u8 i, nss, mcs;
59 u16 max_rate = 0;
60 u32 usr_vht_cap_info = 0;
61 struct mwifiex_adapter *adapter = priv->adapter;
62
63 if (bands & BAND_AAC)
64 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
65 else
66 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
67
68 /* find the max NSS supported */
69 nss = 1;
70 for (i = 1; i <= 8; i++) {
71 mcs = GET_VHTNSSMCS(mcs_map, i);
72 if (mcs < IEEE80211_VHT_MCS_NOT_SUPPORTED)
73 nss = i;
74 }
75 mcs = GET_VHTNSSMCS(mcs_map, nss);
76
77 /* if mcs is 3, nss must be 1 (NSS = 1). Default mcs to MCS 0~9 */
78 if (mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
79 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
80
81 if (GET_VHTCAP_CHWDSET(usr_vht_cap_info)) {
82 /* support 160 MHz */
83 max_rate = max_rate_lgi_160MHZ[nss - 1][mcs];
84 if (!max_rate)
85 /* MCS9 is not supported in NSS6 */
86 max_rate = max_rate_lgi_160MHZ[nss - 1][mcs - 1];
87 } else {
88 max_rate = max_rate_lgi_80MHZ[nss - 1][mcs];
89 if (!max_rate)
90 /* MCS9 is not supported in NSS3 */
91 max_rate = max_rate_lgi_80MHZ[nss - 1][mcs - 1];
92 }
93
94 return max_rate;
95 }
96
97 static void
98 mwifiex_fill_vht_cap_info(struct mwifiex_private *priv,
99 struct ieee80211_vht_cap *vht_cap, u8 bands)
100 {
101 struct mwifiex_adapter *adapter = priv->adapter;
102
103 if (bands & BAND_A)
104 vht_cap->vht_cap_info =
105 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_a);
106 else
107 vht_cap->vht_cap_info =
108 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_bg);
109 }
110
111 void mwifiex_fill_vht_cap_tlv(struct mwifiex_private *priv,
112 struct ieee80211_vht_cap *vht_cap, u8 bands)
113 {
114 struct mwifiex_adapter *adapter = priv->adapter;
115 u16 mcs_map_user, mcs_map_resp, mcs_map_result;
116 u16 mcs_user, mcs_resp, nss, tmp;
117
118 /* Fill VHT cap info */
119 mwifiex_fill_vht_cap_info(priv, vht_cap, bands);
120
121 /* rx MCS Set: find the minimum of the user rx mcs and ap rx mcs */
122 mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
123 mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
124 mcs_map_result = 0;
125
126 for (nss = 1; nss <= 8; nss++) {
127 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
128 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
129
130 if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
131 (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
132 SET_VHTNSSMCS(mcs_map_result, nss,
133 IEEE80211_VHT_MCS_NOT_SUPPORTED);
134 else
135 SET_VHTNSSMCS(mcs_map_result, nss,
136 min(mcs_user, mcs_resp));
137 }
138
139 vht_cap->supp_mcs.rx_mcs_map = cpu_to_le16(mcs_map_result);
140
141 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
142 vht_cap->supp_mcs.rx_highest = cpu_to_le16(tmp);
143
144 /* tx MCS Set: find the minimum of the user tx mcs and ap tx mcs */
145 mcs_map_user = GET_DEVTXMCSMAP(adapter->usr_dot_11ac_mcs_support);
146 mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
147 mcs_map_result = 0;
148
149 for (nss = 1; nss <= 8; nss++) {
150 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
151 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
152 if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
153 (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
154 SET_VHTNSSMCS(mcs_map_result, nss,
155 IEEE80211_VHT_MCS_NOT_SUPPORTED);
156 else
157 SET_VHTNSSMCS(mcs_map_result, nss,
158 min(mcs_user, mcs_resp));
159 }
160
161 vht_cap->supp_mcs.tx_mcs_map = cpu_to_le16(mcs_map_result);
162
163 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
164 vht_cap->supp_mcs.tx_highest = cpu_to_le16(tmp);
165
166 return;
167 }
168
169 int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
170 struct mwifiex_bssdescriptor *bss_desc,
171 u8 **buffer)
172 {
173 struct mwifiex_ie_types_vhtcap *vht_cap;
174 struct mwifiex_ie_types_oper_mode_ntf *oper_ntf;
175 struct ieee_types_oper_mode_ntf *ieee_oper_ntf;
176 struct mwifiex_ie_types_vht_oper *vht_op;
177 struct mwifiex_adapter *adapter = priv->adapter;
178 u8 supp_chwd_set;
179 u32 usr_vht_cap_info;
180 int ret_len = 0;
181
182 if (bss_desc->bss_band & BAND_A)
183 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
184 else
185 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
186
187 /* VHT Capabilities IE */
188 if (bss_desc->bcn_vht_cap) {
189 vht_cap = (struct mwifiex_ie_types_vhtcap *)*buffer;
190 memset(vht_cap, 0, sizeof(*vht_cap));
191 vht_cap->header.type = cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
192 vht_cap->header.len =
193 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
194 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
195 (u8 *)bss_desc->bcn_vht_cap,
196 le16_to_cpu(vht_cap->header.len));
197
198 mwifiex_fill_vht_cap_tlv(priv, &vht_cap->vht_cap,
199 bss_desc->bss_band);
200 *buffer += sizeof(*vht_cap);
201 ret_len += sizeof(*vht_cap);
202 }
203
204 /* VHT Operation IE */
205 if (bss_desc->bcn_vht_oper) {
206 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
207 vht_op = (struct mwifiex_ie_types_vht_oper *)*buffer;
208 memset(vht_op, 0, sizeof(*vht_op));
209 vht_op->header.type =
210 cpu_to_le16(WLAN_EID_VHT_OPERATION);
211 vht_op->header.len = cpu_to_le16(sizeof(*vht_op) -
212 sizeof(struct mwifiex_ie_types_header));
213 memcpy((u8 *)vht_op +
214 sizeof(struct mwifiex_ie_types_header),
215 (u8 *)bss_desc->bcn_vht_oper +
216 sizeof(struct ieee_types_header),
217 le16_to_cpu(vht_op->header.len));
218
219 /* negotiate the channel width and central freq
220 * and keep the central freq as the peer suggests
221 */
222 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
223
224 switch (supp_chwd_set) {
225 case 0:
226 vht_op->chan_width =
227 min_t(u8, IEEE80211_VHT_CHANWIDTH_80MHZ,
228 bss_desc->bcn_vht_oper->chan_width);
229 break;
230 case 1:
231 vht_op->chan_width =
232 min_t(u8, IEEE80211_VHT_CHANWIDTH_160MHZ,
233 bss_desc->bcn_vht_oper->chan_width);
234 break;
235 case 2:
236 vht_op->chan_width =
237 min_t(u8, IEEE80211_VHT_CHANWIDTH_80P80MHZ,
238 bss_desc->bcn_vht_oper->chan_width);
239 break;
240 default:
241 vht_op->chan_width =
242 IEEE80211_VHT_CHANWIDTH_USE_HT;
243 break;
244 }
245
246 *buffer += sizeof(*vht_op);
247 ret_len += sizeof(*vht_op);
248 }
249 }
250
251 /* Operating Mode Notification IE */
252 if (bss_desc->oper_mode) {
253 ieee_oper_ntf = bss_desc->oper_mode;
254 oper_ntf = (void *)*buffer;
255 memset(oper_ntf, 0, sizeof(*oper_ntf));
256 oper_ntf->header.type = cpu_to_le16(WLAN_EID_OPMODE_NOTIF);
257 oper_ntf->header.len = cpu_to_le16(sizeof(u8));
258 oper_ntf->oper_mode = ieee_oper_ntf->oper_mode;
259 *buffer += sizeof(*oper_ntf);
260 ret_len += sizeof(*oper_ntf);
261 }
262
263 return ret_len;
264 }
265
266 int mwifiex_cmd_11ac_cfg(struct mwifiex_private *priv,
267 struct host_cmd_ds_command *cmd, u16 cmd_action,
268 struct mwifiex_11ac_vht_cfg *cfg)
269 {
270 struct host_cmd_11ac_vht_cfg *vhtcfg = &cmd->params.vht_cfg;
271
272 cmd->command = cpu_to_le16(HostCmd_CMD_11AC_CFG);
273 cmd->size = cpu_to_le16(sizeof(struct host_cmd_11ac_vht_cfg) +
274 S_DS_GEN);
275 vhtcfg->action = cpu_to_le16(cmd_action);
276 vhtcfg->band_config = cfg->band_config;
277 vhtcfg->misc_config = cfg->misc_config;
278 vhtcfg->cap_info = cpu_to_le32(cfg->cap_info);
279 vhtcfg->mcs_tx_set = cpu_to_le32(cfg->mcs_tx_set);
280 vhtcfg->mcs_rx_set = cpu_to_le32(cfg->mcs_rx_set);
281
282 return 0;
283 }
284
285 /* This function initializes the BlockACK setup information for given
286 * mwifiex_private structure for 11ac enabled networks.
287 */
288 void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv)
289 {
290 priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
291
292 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
293 priv->add_ba_param.tx_win_size =
294 MWIFIEX_11AC_UAP_AMPDU_DEF_TXWINSIZE;
295 priv->add_ba_param.rx_win_size =
296 MWIFIEX_11AC_UAP_AMPDU_DEF_RXWINSIZE;
297 } else {
298 priv->add_ba_param.tx_win_size =
299 MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE;
300 priv->add_ba_param.rx_win_size =
301 MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
302 }
303
304 return;
305 }
306
307 bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv)
308 {
309 struct mwifiex_bssdescriptor *bss_desc;
310 struct ieee80211_vht_operation *vht_oper;
311
312 bss_desc = &priv->curr_bss_params.bss_descriptor;
313 vht_oper = bss_desc->bcn_vht_oper;
314
315 if (!bss_desc->bcn_vht_cap || !vht_oper)
316 return false;
317
318 if (vht_oper->chan_width == IEEE80211_VHT_CHANWIDTH_USE_HT)
319 return false;
320
321 return true;
322 }
323
324 u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
325 u32 pri_chan, u8 chan_bw)
326 {
327 u8 center_freq_idx = 0;
328
329 if (band & BAND_AAC) {
330 switch (pri_chan) {
331 case 36:
332 case 40:
333 case 44:
334 case 48:
335 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
336 center_freq_idx = 42;
337 break;
338 case 52:
339 case 56:
340 case 60:
341 case 64:
342 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
343 center_freq_idx = 58;
344 else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
345 center_freq_idx = 50;
346 break;
347 case 100:
348 case 104:
349 case 108:
350 case 112:
351 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
352 center_freq_idx = 106;
353 break;
354 case 116:
355 case 120:
356 case 124:
357 case 128:
358 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
359 center_freq_idx = 122;
360 else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
361 center_freq_idx = 114;
362 break;
363 case 132:
364 case 136:
365 case 140:
366 case 144:
367 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
368 center_freq_idx = 138;
369 break;
370 case 149:
371 case 153:
372 case 157:
373 case 161:
374 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
375 center_freq_idx = 155;
376 break;
377 default:
378 center_freq_idx = 42;
379 }
380 }
381
382 return center_freq_idx;
383 }
This page took 0.038964 seconds and 5 git commands to generate.