blob: 6f882bcf96f16e73b9a174574f743c4fd833d21c [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: 802.11n
3 *
4 * Copyright (C) 2011, 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 "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28/*
29 * Fills HT capability information field, AMPDU Parameters field, HT extended
30 * capability field, and supported MCS set fields.
31 *
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070032 * HT capability information field, AMPDU Parameters field, supported MCS set
33 * fields are retrieved from cfg80211 stack
Bing Zhao5e6e3a92011-03-21 18:00:50 -070034 *
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070035 * RD responder bit to set to clear in the extended capability header.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070036 */
37void
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070038mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type,
Bing Zhao5e6e3a92011-03-21 18:00:50 -070039 struct mwifiex_ie_types_htcap *ht_cap)
40{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041 uint16_t ht_ext_cap = le16_to_cpu(ht_cap->ht_cap.extended_ht_cap_info);
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070042 struct ieee80211_supported_band *sband =
43 priv->wdev->wiphy->bands[radio_type];
Bing Zhao5e6e3a92011-03-21 18:00:50 -070044
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070045 ht_cap->ht_cap.ampdu_params_info =
46 (sband->ht_cap.ampdu_factor &
Yogesh Ashok Powar84266842012-03-13 19:22:34 -070047 IEEE80211_HT_AMPDU_PARM_FACTOR) |
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070048 ((sband->ht_cap.ampdu_density <<
49 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) &
50 IEEE80211_HT_AMPDU_PARM_DENSITY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070051
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070052 memcpy((u8 *) &ht_cap->ht_cap.mcs, &sband->ht_cap.mcs,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -070053 sizeof(sband->ht_cap.mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -070054
Bing Zhaoeecd8252011-03-28 17:55:41 -070055 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powar84266842012-03-13 19:22:34 -070056 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070057 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
58 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
59
60 /* Clear RD responder bit */
Amitkumar Karwara3731652011-04-15 20:50:41 -070061 ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070063 ht_cap->ht_cap.cap_info = cpu_to_le16(sband->ht_cap.cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064 ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
65}
66
67/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070068 * This function returns the pointer to an entry in BA Stream
69 * table which matches the requested BA status.
70 */
71static struct mwifiex_tx_ba_stream_tbl *
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -070072mwifiex_get_ba_status(struct mwifiex_private *priv,
73 enum mwifiex_ba_status ba_status)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070074{
75 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
76 unsigned long flags;
77
78 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
79 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
80 if (tx_ba_tsr_tbl->ba_status == ba_status) {
81 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
82 flags);
83 return tx_ba_tsr_tbl;
84 }
85 }
86 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
87 return NULL;
88}
89
90/*
91 * This function handles the command response of delete a block
92 * ack request.
93 *
94 * The function checks the response success status and takes action
95 * accordingly (send an add BA request in case of success, or recreate
96 * the deleted stream in case of failure, if the add BA was also
97 * initiated by us).
98 */
99int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
100 struct host_cmd_ds_command *resp)
101{
102 int tid;
103 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
104 struct host_cmd_ds_11n_delba *del_ba =
105 (struct host_cmd_ds_11n_delba *) &resp->params.del_ba;
106 uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
107
108 tid = del_ba_param_set >> DELBA_TID_POS;
109 if (del_ba->del_result == BA_RESULT_SUCCESS) {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700110 mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr,
111 TYPE_DELBA_SENT,
112 INITIATOR_BIT(del_ba_param_set));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700113
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700114 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700115 if (tx_ba_tbl)
116 mwifiex_send_addba(priv, tx_ba_tbl->tid,
117 tx_ba_tbl->ra);
118 } else { /*
119 * In case of failure, recreate the deleted stream in case
120 * we initiated the ADDBA
121 */
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700122 if (!INITIATOR_BIT(del_ba_param_set))
123 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700125 mwifiex_create_ba_tbl(priv, del_ba->peer_mac_addr, tid,
126 BA_SETUP_INPROGRESS);
127
128 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
129
130 if (tx_ba_tbl)
131 mwifiex_del_ba_tbl(priv, tx_ba_tbl->tid, tx_ba_tbl->ra,
132 TYPE_DELBA_SENT, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700133 }
134
135 return 0;
136}
137
138/*
139 * This function handles the command response of add a block
140 * ack request.
141 *
142 * Handling includes changing the header fields to CPU formats, checking
143 * the response success status and taking actions accordingly (delete the
144 * BA stream table in case of failure).
145 */
146int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
147 struct host_cmd_ds_command *resp)
148{
149 int tid;
150 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
151 (struct host_cmd_ds_11n_addba_rsp *) &resp->params.add_ba_rsp;
152 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
153
154 add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
155 & SSN_MASK);
156
157 tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
158 & IEEE80211_ADDBA_PARAM_TID_MASK)
159 >> BLOCKACKPARAM_TID_POS;
160 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700161 tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700162 add_ba_rsp->peer_mac_addr);
163 if (tx_ba_tbl) {
164 dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700165 tx_ba_tbl->ba_status = BA_SETUP_COMPLETE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166 } else {
167 dev_err(priv->adapter->dev, "BA stream not created\n");
168 }
169 } else {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700170 mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr,
171 TYPE_DELBA_SENT, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172 if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
173 priv->aggr_prio_tbl[tid].ampdu_ap =
174 BA_STREAM_NOT_ALLOWED;
175 }
176
177 return 0;
178}
179
180/*
181 * This function handles the command response of 11n configuration request.
182 *
183 * Handling includes changing the header fields into CPU format.
184 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700185int mwifiex_ret_11n_cfg(struct host_cmd_ds_command *resp,
186 struct mwifiex_ds_11n_tx_cfg *tx_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700187{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188 struct host_cmd_ds_11n_cfg *htcfg = &resp->params.htcfg;
189
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700190 if (tx_cfg) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700191 tx_cfg->tx_htcap = le16_to_cpu(htcfg->ht_tx_cap);
192 tx_cfg->tx_htinfo = le16_to_cpu(htcfg->ht_tx_info);
193 }
194 return 0;
195}
196
197/*
198 * This function prepares command of reconfigure Tx buffer.
199 *
200 * Preparation includes -
201 * - Setting command ID, action and proper size
202 * - Setting Tx buffer size (for SET only)
203 * - Ensuring correct endian-ness
204 */
205int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
206 struct host_cmd_ds_command *cmd, int cmd_action,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700207 u16 *buf_size)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700208{
209 struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
210 u16 action = (u16) cmd_action;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700211
212 cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
213 cmd->size =
214 cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
215 tx_buf->action = cpu_to_le16(action);
216 switch (action) {
217 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700218 dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
219 tx_buf->buff_size = cpu_to_le16(*buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700220 break;
221 case HostCmd_ACT_GEN_GET:
222 default:
223 tx_buf->buff_size = 0;
224 break;
225 }
226 return 0;
227}
228
229/*
230 * This function prepares command of AMSDU aggregation control.
231 *
232 * Preparation includes -
233 * - Setting command ID, action and proper size
234 * - Setting AMSDU control parameters (for SET only)
235 * - Ensuring correct endian-ness
236 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700237int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700238 int cmd_action,
239 struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700240{
241 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
242 &cmd->params.amsdu_aggr_ctrl;
243 u16 action = (u16) cmd_action;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700244
245 cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
246 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
247 + S_DS_GEN);
248 amsdu_ctrl->action = cpu_to_le16(action);
249 switch (action) {
250 case HostCmd_ACT_GEN_SET:
251 amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
252 amsdu_ctrl->curr_buf_size = 0;
253 break;
254 case HostCmd_ACT_GEN_GET:
255 default:
256 amsdu_ctrl->curr_buf_size = 0;
257 break;
258 }
259 return 0;
260}
261
262/*
263 * This function handles the command response of AMSDU aggregation
264 * control request.
265 *
266 * Handling includes changing the header fields into CPU format.
267 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700268int mwifiex_ret_amsdu_aggr_ctrl(struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700269 struct mwifiex_ds_11n_amsdu_aggr_ctrl
270 *amsdu_aggr_ctrl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700272 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
273 &resp->params.amsdu_aggr_ctrl;
274
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700275 if (amsdu_aggr_ctrl) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 amsdu_aggr_ctrl->enable = le16_to_cpu(amsdu_ctrl->enable);
277 amsdu_aggr_ctrl->curr_buf_size =
278 le16_to_cpu(amsdu_ctrl->curr_buf_size);
279 }
280 return 0;
281}
282
283/*
284 * This function prepares 11n configuration command.
285 *
286 * Preparation includes -
287 * - Setting command ID, action and proper size
288 * - Setting HT Tx capability and HT Tx information fields
289 * - Ensuring correct endian-ness
290 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700291int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action,
292 struct mwifiex_ds_11n_tx_cfg *txcfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700293{
294 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700295
296 cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
297 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
298 htcfg->action = cpu_to_le16(cmd_action);
299 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
300 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
301 return 0;
302}
303
304/*
305 * This function appends an 11n TLV to a buffer.
306 *
307 * Buffer allocation is responsibility of the calling
308 * function. No size validation is made here.
309 *
310 * The function fills up the following sections, if applicable -
311 * - HT capability IE
312 * - HT information IE (with channel list)
313 * - 20/40 BSS Coexistence IE
314 * - HT Extended Capabilities IE
315 */
316int
317mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
318 struct mwifiex_bssdescriptor *bss_desc,
319 u8 **buffer)
320{
321 struct mwifiex_ie_types_htcap *ht_cap;
322 struct mwifiex_ie_types_htinfo *ht_info;
323 struct mwifiex_ie_types_chan_list_param_set *chan_list;
324 struct mwifiex_ie_types_2040bssco *bss_co_2040;
325 struct mwifiex_ie_types_extcap *ext_cap;
326 int ret_len = 0;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700327 struct ieee80211_supported_band *sband;
328 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329
330 if (!buffer || !*buffer)
331 return ret_len;
332
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700333 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
334 sband = priv->wdev->wiphy->bands[radio_type];
335
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 if (bss_desc->bcn_ht_cap) {
337 ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
338 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
339 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
340 ht_cap->header.len =
341 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
342 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
Amitkumar Karwarc7fc3682014-03-04 18:43:13 -0800343 (u8 *)bss_desc->bcn_ht_cap,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 le16_to_cpu(ht_cap->header.len));
345
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700346 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347
348 *buffer += sizeof(struct mwifiex_ie_types_htcap);
349 ret_len += sizeof(struct mwifiex_ie_types_htcap);
350 }
351
352 if (bss_desc->bcn_ht_info) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700353 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700354 ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
355 memset(ht_info, 0,
356 sizeof(struct mwifiex_ie_types_htinfo));
357 ht_info->header.type =
358 cpu_to_le16(WLAN_EID_HT_INFORMATION);
359 ht_info->header.len =
360 cpu_to_le16(sizeof(struct ieee80211_ht_info));
361
362 memcpy((u8 *) ht_info +
363 sizeof(struct mwifiex_ie_types_header),
364 (u8 *) bss_desc->bcn_ht_info +
365 sizeof(struct ieee_types_header),
366 le16_to_cpu(ht_info->header.len));
367
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700368 if (!(sband->ht_cap.cap &
369 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Marc Yang6d2bd912011-03-25 19:47:02 -0700370 ht_info->ht_info.ht_param &=
371 ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
372 IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373
374 *buffer += sizeof(struct mwifiex_ie_types_htinfo);
375 ret_len += sizeof(struct mwifiex_ie_types_htinfo);
376 }
377
378 chan_list =
379 (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
380 memset(chan_list, 0,
381 sizeof(struct mwifiex_ie_types_chan_list_param_set));
382 chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
383 chan_list->header.len = cpu_to_le16(
384 sizeof(struct mwifiex_ie_types_chan_list_param_set) -
385 sizeof(struct mwifiex_ie_types_header));
386 chan_list->chan_scan_param[0].chan_number =
387 bss_desc->bcn_ht_info->control_chan;
388 chan_list->chan_scan_param[0].radio_type =
389 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
390
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700391 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
392 bss_desc->bcn_ht_info->ht_param &
393 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700394 SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
395 radio_type,
Marc Yang6d2bd912011-03-25 19:47:02 -0700396 (bss_desc->bcn_ht_info->ht_param &
397 IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398
399 *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
400 ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
401 }
402
403 if (bss_desc->bcn_bss_co_2040) {
404 bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
405 memset(bss_co_2040, 0,
406 sizeof(struct mwifiex_ie_types_2040bssco));
407 bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
408 bss_co_2040->header.len =
409 cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
410
411 memcpy((u8 *) bss_co_2040 +
412 sizeof(struct mwifiex_ie_types_header),
413 (u8 *) bss_desc->bcn_bss_co_2040 +
414 sizeof(struct ieee_types_header),
415 le16_to_cpu(bss_co_2040->header.len));
416
417 *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
418 ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
419 }
420
421 if (bss_desc->bcn_ext_cap) {
422 ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
423 memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
424 ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
425 ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
426
427 memcpy((u8 *) ext_cap +
428 sizeof(struct mwifiex_ie_types_header),
429 (u8 *) bss_desc->bcn_ext_cap +
430 sizeof(struct ieee_types_header),
431 le16_to_cpu(ext_cap->header.len));
432
433 *buffer += sizeof(struct mwifiex_ie_types_extcap);
434 ret_len += sizeof(struct mwifiex_ie_types_extcap);
435 }
436
437 return ret_len;
438}
439
440/*
441 * This function reconfigures the Tx buffer size in firmware.
442 *
443 * This function prepares a firmware command and issues it, if
444 * the current Tx buffer size is different from the one requested.
445 * Maximum configurable Tx buffer size is limited by the HT capability
446 * field value.
447 */
448void
449mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
450 struct mwifiex_bssdescriptor *bss_desc)
451{
452 u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700453 u16 tx_buf, curr_tx_buf_size = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454
455 if (bss_desc->bcn_ht_cap) {
Marc Yang6d2bd912011-03-25 19:47:02 -0700456 if (le16_to_cpu(bss_desc->bcn_ht_cap->cap_info) &
457 IEEE80211_HT_CAP_MAX_AMSDU)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700458 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
459 else
460 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
461 }
462
463 tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
464
465 dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700466 max_amsdu, priv->adapter->max_tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467
468 if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
469 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
470 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
471 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
472 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
473 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
474 if (curr_tx_buf_size != tx_buf)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700475 mwifiex_send_cmd_async(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
476 HostCmd_ACT_GEN_SET, 0, &tx_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477}
478
479/*
480 * This function checks if the given pointer is valid entry of
481 * Tx BA Stream table.
482 */
483static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
484 struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
485{
486 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
487
488 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
489 if (tx_ba_tsr_tbl == tx_tbl_ptr)
490 return true;
491 }
492
493 return false;
494}
495
496/*
497 * This function deletes the given entry in Tx BA Stream table.
498 *
499 * The function also performs a validity check on the supplied
500 * pointer before trying to delete.
501 */
502void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
503 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
504{
505 if (!tx_ba_tsr_tbl &&
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700506 mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507 return;
508
509 dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
510
511 list_del(&tx_ba_tsr_tbl->list);
512
513 kfree(tx_ba_tsr_tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514}
515
516/*
517 * This function deletes all the entries in Tx BA Stream table.
518 */
519void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
520{
521 int i;
522 struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
523 unsigned long flags;
524
525 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
526 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
527 &priv->tx_ba_stream_tbl_ptr, list)
528 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
529 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
530
531 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
532
533 for (i = 0; i < MAX_NUM_TID; ++i)
534 priv->aggr_prio_tbl[i].ampdu_ap =
535 priv->aggr_prio_tbl[i].ampdu_user;
536}
537
538/*
539 * This function returns the pointer to an entry in BA Stream
540 * table which matches the given RA/TID pair.
541 */
542struct mwifiex_tx_ba_stream_tbl *
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700543mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544{
545 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
546 unsigned long flags;
547
548 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
549 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700550 if (!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN) &&
551 tx_ba_tsr_tbl->tid == tid) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
553 flags);
554 return tx_ba_tsr_tbl;
555 }
556 }
557 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
558 return NULL;
559}
560
561/*
562 * This function creates an entry in Tx BA stream table for the
563 * given RA/TID pair.
564 */
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700565void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
566 enum mwifiex_ba_status ba_status)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567{
568 struct mwifiex_tx_ba_stream_tbl *new_node;
569 unsigned long flags;
570
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700571 if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700572 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
573 GFP_ATOMIC);
574 if (!new_node) {
575 dev_err(priv->adapter->dev,
576 "%s: failed to alloc new_node\n", __func__);
577 return;
578 }
579
580 INIT_LIST_HEAD(&new_node->list);
581
582 new_node->tid = tid;
583 new_node->ba_status = ba_status;
584 memcpy(new_node->ra, ra, ETH_ALEN);
585
586 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
587 list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
588 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
589 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590}
591
592/*
593 * This function sends an add BA request to the given TID/RA pair.
594 */
595int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
596{
597 struct host_cmd_ds_11n_addba_req add_ba_req;
598 static u8 dialog_tok;
599 int ret;
600
601 dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
602
603 add_ba_req.block_ack_param_set = cpu_to_le16(
604 (u16) ((tid << BLOCKACKPARAM_TID_POS) |
605 (priv->add_ba_param.
606 tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
607 IMMEDIATE_BLOCK_ACK));
608 add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
609
610 ++dialog_tok;
611
612 if (dialog_tok == 0)
613 dialog_tok = 1;
614
615 add_ba_req.dialog_token = dialog_tok;
616 memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
617
618 /* We don't wait for the response of this command */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700619 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
620 0, 0, &add_ba_req);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621
622 return ret;
623}
624
625/*
626 * This function sends a delete BA request to the given TID/RA pair.
627 */
628int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
629 int initiator)
630{
631 struct host_cmd_ds_11n_delba delba;
632 int ret;
633 uint16_t del_ba_param_set;
634
635 memset(&delba, 0, sizeof(delba));
636 delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
637
638 del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
639 if (initiator)
640 del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
641 else
642 del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
643
644 memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
645
646 /* We don't wait for the response of this command */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700647 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
648 HostCmd_ACT_GEN_SET, 0, &delba);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649
650 return ret;
651}
652
653/*
654 * This function handles the command response of a delete BA request.
655 */
656void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
657{
658 struct host_cmd_ds_11n_delba *cmd_del_ba =
659 (struct host_cmd_ds_11n_delba *) del_ba;
660 uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
661 int tid;
662
663 tid = del_ba_param_set >> DELBA_TID_POS;
664
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700665 mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
666 TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700667}
668
669/*
670 * This function retrieves the Rx reordering table.
671 */
672int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
673 struct mwifiex_ds_rx_reorder_tbl *buf)
674{
675 int i;
676 struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
677 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
678 int count = 0;
679 unsigned long flags;
680
681 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
682 list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
683 list) {
684 rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
685 memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
686 rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
687 rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
688 for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
689 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
690 rx_reo_tbl->buffer[i] = true;
691 else
692 rx_reo_tbl->buffer[i] = false;
693 }
694 rx_reo_tbl++;
695 count++;
696
697 if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
698 break;
699 }
700 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
701
702 return count;
703}
704
705/*
706 * This function retrieves the Tx BA stream table.
707 */
708int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
709 struct mwifiex_ds_tx_ba_stream_tbl *buf)
710{
711 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
712 struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
713 int count = 0;
714 unsigned long flags;
715
716 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
717 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
718 rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
719 dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700720 __func__, rx_reo_tbl->tid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700721 memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
722 rx_reo_tbl++;
723 count++;
724 if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
725 break;
726 }
727 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
728
729 return count;
730}