rtlwifi: Remove redundant if clause
[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 sizeof(struct ieee_types_header),
197 le16_to_cpu(vht_cap->header.len));
198
199 mwifiex_fill_vht_cap_tlv(priv, &vht_cap->vht_cap,
200 bss_desc->bss_band);
201 *buffer += sizeof(*vht_cap);
202 ret_len += sizeof(*vht_cap);
203 }
204
205 /* VHT Operation IE */
206 if (bss_desc->bcn_vht_oper) {
207 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
208 vht_op = (struct mwifiex_ie_types_vht_oper *)*buffer;
209 memset(vht_op, 0, sizeof(*vht_op));
210 vht_op->header.type =
211 cpu_to_le16(WLAN_EID_VHT_OPERATION);
212 vht_op->header.len = cpu_to_le16(sizeof(*vht_op) -
213 sizeof(struct mwifiex_ie_types_header));
214 memcpy((u8 *)vht_op +
215 sizeof(struct mwifiex_ie_types_header),
216 (u8 *)bss_desc->bcn_vht_oper +
217 sizeof(struct ieee_types_header),
218 le16_to_cpu(vht_op->header.len));
219
220 /* negotiate the channel width and central freq
221 * and keep the central freq as the peer suggests
222 */
223 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
224
225 switch (supp_chwd_set) {
226 case 0:
227 vht_op->chan_width =
228 min_t(u8, IEEE80211_VHT_CHANWIDTH_80MHZ,
229 bss_desc->bcn_vht_oper->chan_width);
230 break;
231 case 1:
232 vht_op->chan_width =
233 min_t(u8, IEEE80211_VHT_CHANWIDTH_160MHZ,
234 bss_desc->bcn_vht_oper->chan_width);
235 break;
236 case 2:
237 vht_op->chan_width =
238 min_t(u8, IEEE80211_VHT_CHANWIDTH_80P80MHZ,
239 bss_desc->bcn_vht_oper->chan_width);
240 break;
241 default:
242 vht_op->chan_width =
243 IEEE80211_VHT_CHANWIDTH_USE_HT;
244 break;
245 }
246
247 *buffer += sizeof(*vht_op);
248 ret_len += sizeof(*vht_op);
249 }
250 }
251
252 /* Operating Mode Notification IE */
253 if (bss_desc->oper_mode) {
254 ieee_oper_ntf = bss_desc->oper_mode;
255 oper_ntf = (void *)*buffer;
256 memset(oper_ntf, 0, sizeof(*oper_ntf));
257 oper_ntf->header.type = cpu_to_le16(WLAN_EID_OPMODE_NOTIF);
258 oper_ntf->header.len = cpu_to_le16(sizeof(u8));
259 oper_ntf->oper_mode = ieee_oper_ntf->oper_mode;
260 *buffer += sizeof(*oper_ntf);
261 ret_len += sizeof(*oper_ntf);
262 }
263
264 return ret_len;
265 }
266
267 int mwifiex_cmd_11ac_cfg(struct mwifiex_private *priv,
268 struct host_cmd_ds_command *cmd, u16 cmd_action,
269 struct mwifiex_11ac_vht_cfg *cfg)
270 {
271 struct host_cmd_11ac_vht_cfg *vhtcfg = &cmd->params.vht_cfg;
272
273 cmd->command = cpu_to_le16(HostCmd_CMD_11AC_CFG);
274 cmd->size = cpu_to_le16(sizeof(struct host_cmd_11ac_vht_cfg) +
275 S_DS_GEN);
276 vhtcfg->action = cpu_to_le16(cmd_action);
277 vhtcfg->band_config = cfg->band_config;
278 vhtcfg->misc_config = cfg->misc_config;
279 vhtcfg->cap_info = cpu_to_le32(cfg->cap_info);
280 vhtcfg->mcs_tx_set = cpu_to_le32(cfg->mcs_tx_set);
281 vhtcfg->mcs_rx_set = cpu_to_le32(cfg->mcs_rx_set);
282
283 return 0;
284 }
285
286 /* This function initializes the BlockACK setup information for given
287 * mwifiex_private structure for 11ac enabled networks.
288 */
289 void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv)
290 {
291 priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
292
293 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
294 priv->add_ba_param.tx_win_size =
295 MWIFIEX_11AC_UAP_AMPDU_DEF_TXWINSIZE;
296 priv->add_ba_param.rx_win_size =
297 MWIFIEX_11AC_UAP_AMPDU_DEF_RXWINSIZE;
298 } else {
299 priv->add_ba_param.tx_win_size =
300 MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE;
301 priv->add_ba_param.rx_win_size =
302 MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
303 }
304
305 return;
306 }
307
308 bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv)
309 {
310 struct mwifiex_bssdescriptor *bss_desc;
311 struct ieee80211_vht_operation *vht_oper;
312
313 bss_desc = &priv->curr_bss_params.bss_descriptor;
314 vht_oper = bss_desc->bcn_vht_oper;
315
316 if (!bss_desc->bcn_vht_cap || !vht_oper)
317 return false;
318
319 if (vht_oper->chan_width == IEEE80211_VHT_CHANWIDTH_USE_HT)
320 return false;
321
322 return true;
323 }
324
325 u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
326 u32 pri_chan, u8 chan_bw)
327 {
328 u8 center_freq_idx = 0;
329
330 if (band & BAND_AAC) {
331 switch (pri_chan) {
332 case 36:
333 case 40:
334 case 44:
335 case 48:
336 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
337 center_freq_idx = 42;
338 break;
339 case 52:
340 case 56:
341 case 60:
342 case 64:
343 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
344 center_freq_idx = 58;
345 else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
346 center_freq_idx = 50;
347 break;
348 case 100:
349 case 104:
350 case 108:
351 case 112:
352 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
353 center_freq_idx = 106;
354 break;
355 case 116:
356 case 120:
357 case 124:
358 case 128:
359 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
360 center_freq_idx = 122;
361 else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
362 center_freq_idx = 114;
363 break;
364 case 132:
365 case 136:
366 case 140:
367 case 144:
368 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
369 center_freq_idx = 138;
370 break;
371 case 149:
372 case 153:
373 case 157:
374 case 161:
375 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
376 center_freq_idx = 155;
377 break;
378 default:
379 center_freq_idx = 42;
380 }
381 }
382
383 return center_freq_idx;
384 }
This page took 0.046023 seconds and 5 git commands to generate.