2 * Marvell Wireless LAN device driver: 802.11ac
4 * Copyright (C) 2013, 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.
26 /* Tables of the MCS map to the highest data rate (in Mbps) supported
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 */
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 */
51 /* This function converts the 2-bit MCS map to the highest long GI
55 mwifiex_convert_mcsmap_to_maxrate(struct mwifiex_private *priv,
56 u8 bands, u16 mcs_map)
60 u32 usr_vht_cap_info = 0;
61 struct mwifiex_adapter *adapter = priv->adapter;
64 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
66 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
68 /* find the max NSS supported */
70 for (i = 1; i <= 8; i++) {
71 mcs = GET_VHTNSSMCS(mcs_map, i);
72 if (mcs < IEEE80211_VHT_MCS_NOT_SUPPORTED)
75 mcs = GET_VHTNSSMCS(mcs_map, nss);
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;
81 if (GET_VHTCAP_CHWDSET(usr_vht_cap_info)) {
83 max_rate = max_rate_lgi_160MHZ[nss - 1][mcs];
85 /* MCS9 is not supported in NSS6 */
86 max_rate = max_rate_lgi_160MHZ[nss - 1][mcs - 1];
88 max_rate = max_rate_lgi_80MHZ[nss - 1][mcs];
90 /* MCS9 is not supported in NSS3 */
91 max_rate = max_rate_lgi_80MHZ[nss - 1][mcs - 1];
98 mwifiex_fill_vht_cap_info(struct mwifiex_private *priv,
99 struct ieee80211_vht_cap *vht_cap, u8 bands)
101 struct mwifiex_adapter *adapter = priv->adapter;
104 vht_cap->vht_cap_info =
105 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_a);
107 vht_cap->vht_cap_info =
108 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_bg);
111 void mwifiex_fill_vht_cap_tlv(struct mwifiex_private *priv,
112 struct ieee80211_vht_cap *vht_cap, u8 bands)
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;
118 /* Fill VHT cap info */
119 mwifiex_fill_vht_cap_info(priv, vht_cap, bands);
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);
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);
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);
135 SET_VHTNSSMCS(mcs_map_result, nss,
136 min(mcs_user, mcs_resp));
139 vht_cap->supp_mcs.rx_mcs_map = cpu_to_le16(mcs_map_result);
141 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
142 vht_cap->supp_mcs.rx_highest = cpu_to_le16(tmp);
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);
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);
157 SET_VHTNSSMCS(mcs_map_result, nss,
158 min(mcs_user, mcs_resp));
161 vht_cap->supp_mcs.tx_mcs_map = cpu_to_le16(mcs_map_result);
163 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
164 vht_cap->supp_mcs.tx_highest = cpu_to_le16(tmp);
169 int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
170 struct mwifiex_bssdescriptor *bss_desc,
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;
179 u32 usr_vht_cap_info;
182 if (bss_desc->bss_band & BAND_A)
183 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
185 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
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));
198 mwifiex_fill_vht_cap_tlv(priv, &vht_cap->vht_cap,
200 *buffer += sizeof(*vht_cap);
201 ret_len += sizeof(*vht_cap);
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));
219 /* negotiate the channel width and central freq
220 * and keep the central freq as the peer suggests
222 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
224 switch (supp_chwd_set) {
227 min_t(u8, IEEE80211_VHT_CHANWIDTH_80MHZ,
228 bss_desc->bcn_vht_oper->chan_width);
232 min_t(u8, IEEE80211_VHT_CHANWIDTH_160MHZ,
233 bss_desc->bcn_vht_oper->chan_width);
237 min_t(u8, IEEE80211_VHT_CHANWIDTH_80P80MHZ,
238 bss_desc->bcn_vht_oper->chan_width);
242 IEEE80211_VHT_CHANWIDTH_USE_HT;
246 *buffer += sizeof(*vht_op);
247 ret_len += sizeof(*vht_op);
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);
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)
270 struct host_cmd_11ac_vht_cfg *vhtcfg = &cmd->params.vht_cfg;
272 cmd->command = cpu_to_le16(HostCmd_CMD_11AC_CFG);
273 cmd->size = cpu_to_le16(sizeof(struct host_cmd_11ac_vht_cfg) +
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);
285 /* This function initializes the BlockACK setup information for given
286 * mwifiex_private structure for 11ac enabled networks.
288 void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv)
290 priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
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;
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;
307 bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv)
309 struct mwifiex_bssdescriptor *bss_desc;
310 struct ieee80211_vht_operation *vht_oper;
312 bss_desc = &priv->curr_bss_params.bss_descriptor;
313 vht_oper = bss_desc->bcn_vht_oper;
315 if (!bss_desc->bcn_vht_cap || !vht_oper)
318 if (vht_oper->chan_width == IEEE80211_VHT_CHANWIDTH_USE_HT)
324 u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
325 u32 pri_chan, u8 chan_bw)
327 u8 center_freq_idx = 0;
329 if (band & BAND_AAC) {
335 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
336 center_freq_idx = 42;
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;
351 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
352 center_freq_idx = 106;
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;
367 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
368 center_freq_idx = 138;
374 if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
375 center_freq_idx = 155;
378 center_freq_idx = 42;
382 return center_freq_idx;