mac80211: linearize SKBs as needed for crypto
[deliverable/linux.git] / drivers / net / wireless / mwifiex / 11n.c
CommitLineData
5e6e3a92
BZ
1/*
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 *
a46b7b5c
AK
32 * HT capability information field, AMPDU Parameters field, supported MCS set
33 * fields are retrieved from cfg80211 stack
5e6e3a92 34 *
a46b7b5c 35 * RD responder bit to set to clear in the extended capability header.
5e6e3a92
BZ
36 */
37void
a46b7b5c 38mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type,
5e6e3a92
BZ
39 struct mwifiex_ie_types_htcap *ht_cap)
40{
5e6e3a92 41 uint16_t ht_ext_cap = le16_to_cpu(ht_cap->ht_cap.extended_ht_cap_info);
a46b7b5c
AK
42 struct ieee80211_supported_band *sband =
43 priv->wdev->wiphy->bands[radio_type];
5e6e3a92 44
a46b7b5c
AK
45 ht_cap->ht_cap.ampdu_params_info =
46 (sband->ht_cap.ampdu_factor &
47 IEEE80211_HT_AMPDU_PARM_FACTOR)|
48 ((sband->ht_cap.ampdu_density <<
49 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) &
50 IEEE80211_HT_AMPDU_PARM_DENSITY);
5e6e3a92 51
a46b7b5c
AK
52 memcpy((u8 *) &ht_cap->ht_cap.mcs, &sband->ht_cap.mcs,
53 sizeof(sband->ht_cap.mcs));
5e6e3a92 54
eecd8250 55 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
a46b7b5c 56 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5e6e3a92
BZ
57 /* 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 */
a3731658 61 ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER;
5e6e3a92 62
a46b7b5c 63 ht_cap->ht_cap.cap_info = cpu_to_le16(sband->ht_cap.cap);
5e6e3a92
BZ
64 ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
65}
66
5e6e3a92
BZ
67/*
68 * 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 *
72mwifiex_11n_get_tx_ba_stream_status(struct mwifiex_private *priv,
73 enum mwifiex_ba_status ba_status)
74{
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) {
110 mwifiex_11n_delete_ba_stream_tbl(priv, tid,
111 del_ba->peer_mac_addr, TYPE_DELBA_SENT,
112 INITIATOR_BIT(del_ba_param_set));
113
114 tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
115 BA_STREAM_SETUP_INPROGRESS);
116 if (tx_ba_tbl)
117 mwifiex_send_addba(priv, tx_ba_tbl->tid,
118 tx_ba_tbl->ra);
119 } else { /*
120 * In case of failure, recreate the deleted stream in case
121 * we initiated the ADDBA
122 */
123 if (INITIATOR_BIT(del_ba_param_set)) {
124 mwifiex_11n_create_tx_ba_stream_tbl(priv,
125 del_ba->peer_mac_addr, tid,
126 BA_STREAM_SETUP_INPROGRESS);
127
128 tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
129 BA_STREAM_SETUP_INPROGRESS);
130 if (tx_ba_tbl)
131 mwifiex_11n_delete_ba_stream_tbl(priv,
132 tx_ba_tbl->tid, tx_ba_tbl->ra,
133 TYPE_DELBA_SENT, true);
134 }
135 }
136
137 return 0;
138}
139
140/*
141 * This function handles the command response of add a block
142 * ack request.
143 *
144 * Handling includes changing the header fields to CPU formats, checking
145 * the response success status and taking actions accordingly (delete the
146 * BA stream table in case of failure).
147 */
148int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
149 struct host_cmd_ds_command *resp)
150{
151 int tid;
152 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
153 (struct host_cmd_ds_11n_addba_rsp *) &resp->params.add_ba_rsp;
154 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
155
156 add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
157 & SSN_MASK);
158
159 tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
160 & IEEE80211_ADDBA_PARAM_TID_MASK)
161 >> BLOCKACKPARAM_TID_POS;
162 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
163 tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_tbl(priv, tid,
164 add_ba_rsp->peer_mac_addr);
165 if (tx_ba_tbl) {
166 dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
167 tx_ba_tbl->ba_status = BA_STREAM_SETUP_COMPLETE;
168 } else {
169 dev_err(priv->adapter->dev, "BA stream not created\n");
170 }
171 } else {
172 mwifiex_11n_delete_ba_stream_tbl(priv, tid,
173 add_ba_rsp->peer_mac_addr,
174 TYPE_DELBA_SENT, true);
175 if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
176 priv->aggr_prio_tbl[tid].ampdu_ap =
177 BA_STREAM_NOT_ALLOWED;
178 }
179
180 return 0;
181}
182
183/*
184 * This function handles the command response of 11n configuration request.
185 *
186 * Handling includes changing the header fields into CPU format.
187 */
a5ffddb7
AK
188int mwifiex_ret_11n_cfg(struct host_cmd_ds_command *resp,
189 struct mwifiex_ds_11n_tx_cfg *tx_cfg)
5e6e3a92 190{
5e6e3a92
BZ
191 struct host_cmd_ds_11n_cfg *htcfg = &resp->params.htcfg;
192
a5ffddb7 193 if (tx_cfg) {
5e6e3a92
BZ
194 tx_cfg->tx_htcap = le16_to_cpu(htcfg->ht_tx_cap);
195 tx_cfg->tx_htinfo = le16_to_cpu(htcfg->ht_tx_info);
196 }
197 return 0;
198}
199
200/*
201 * This function prepares command of reconfigure Tx buffer.
202 *
203 * Preparation includes -
204 * - Setting command ID, action and proper size
205 * - Setting Tx buffer size (for SET only)
206 * - Ensuring correct endian-ness
207 */
208int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
209 struct host_cmd_ds_command *cmd, int cmd_action,
a5ffddb7 210 u16 *buf_size)
5e6e3a92
BZ
211{
212 struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
213 u16 action = (u16) cmd_action;
5e6e3a92
BZ
214
215 cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
216 cmd->size =
217 cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
218 tx_buf->action = cpu_to_le16(action);
219 switch (action) {
220 case HostCmd_ACT_GEN_SET:
a5ffddb7
AK
221 dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
222 tx_buf->buff_size = cpu_to_le16(*buf_size);
5e6e3a92
BZ
223 break;
224 case HostCmd_ACT_GEN_GET:
225 default:
226 tx_buf->buff_size = 0;
227 break;
228 }
229 return 0;
230}
231
232/*
233 * This function prepares command of AMSDU aggregation control.
234 *
235 * Preparation includes -
236 * - Setting command ID, action and proper size
237 * - Setting AMSDU control parameters (for SET only)
238 * - Ensuring correct endian-ness
239 */
572e8f3e 240int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
a5ffddb7
AK
241 int cmd_action,
242 struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
5e6e3a92
BZ
243{
244 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
245 &cmd->params.amsdu_aggr_ctrl;
246 u16 action = (u16) cmd_action;
5e6e3a92
BZ
247
248 cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
249 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
250 + S_DS_GEN);
251 amsdu_ctrl->action = cpu_to_le16(action);
252 switch (action) {
253 case HostCmd_ACT_GEN_SET:
254 amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
255 amsdu_ctrl->curr_buf_size = 0;
256 break;
257 case HostCmd_ACT_GEN_GET:
258 default:
259 amsdu_ctrl->curr_buf_size = 0;
260 break;
261 }
262 return 0;
263}
264
265/*
266 * This function handles the command response of AMSDU aggregation
267 * control request.
268 *
269 * Handling includes changing the header fields into CPU format.
270 */
572e8f3e 271int mwifiex_ret_amsdu_aggr_ctrl(struct host_cmd_ds_command *resp,
a5ffddb7
AK
272 struct mwifiex_ds_11n_amsdu_aggr_ctrl
273 *amsdu_aggr_ctrl)
5e6e3a92 274{
5e6e3a92
BZ
275 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
276 &resp->params.amsdu_aggr_ctrl;
277
a5ffddb7 278 if (amsdu_aggr_ctrl) {
5e6e3a92
BZ
279 amsdu_aggr_ctrl->enable = le16_to_cpu(amsdu_ctrl->enable);
280 amsdu_aggr_ctrl->curr_buf_size =
281 le16_to_cpu(amsdu_ctrl->curr_buf_size);
282 }
283 return 0;
284}
285
286/*
287 * This function prepares 11n configuration command.
288 *
289 * Preparation includes -
290 * - Setting command ID, action and proper size
291 * - Setting HT Tx capability and HT Tx information fields
292 * - Ensuring correct endian-ness
293 */
a5ffddb7
AK
294int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action,
295 struct mwifiex_ds_11n_tx_cfg *txcfg)
5e6e3a92
BZ
296{
297 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
5e6e3a92
BZ
298
299 cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
300 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
301 htcfg->action = cpu_to_le16(cmd_action);
302 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
303 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
304 return 0;
305}
306
307/*
308 * This function appends an 11n TLV to a buffer.
309 *
310 * Buffer allocation is responsibility of the calling
311 * function. No size validation is made here.
312 *
313 * The function fills up the following sections, if applicable -
314 * - HT capability IE
315 * - HT information IE (with channel list)
316 * - 20/40 BSS Coexistence IE
317 * - HT Extended Capabilities IE
318 */
319int
320mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
321 struct mwifiex_bssdescriptor *bss_desc,
322 u8 **buffer)
323{
324 struct mwifiex_ie_types_htcap *ht_cap;
325 struct mwifiex_ie_types_htinfo *ht_info;
326 struct mwifiex_ie_types_chan_list_param_set *chan_list;
327 struct mwifiex_ie_types_2040bssco *bss_co_2040;
328 struct mwifiex_ie_types_extcap *ext_cap;
329 int ret_len = 0;
a46b7b5c
AK
330 struct ieee80211_supported_band *sband;
331 u8 radio_type;
5e6e3a92
BZ
332
333 if (!buffer || !*buffer)
334 return ret_len;
335
a46b7b5c
AK
336 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
337 sband = priv->wdev->wiphy->bands[radio_type];
338
5e6e3a92
BZ
339 if (bss_desc->bcn_ht_cap) {
340 ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
341 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
342 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
343 ht_cap->header.len =
344 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
345 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
346 (u8 *) bss_desc->bcn_ht_cap +
347 sizeof(struct ieee_types_header),
348 le16_to_cpu(ht_cap->header.len));
349
a46b7b5c 350 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
5e6e3a92
BZ
351
352 *buffer += sizeof(struct mwifiex_ie_types_htcap);
353 ret_len += sizeof(struct mwifiex_ie_types_htcap);
354 }
355
356 if (bss_desc->bcn_ht_info) {
eecd8250 357 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
358 ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
359 memset(ht_info, 0,
360 sizeof(struct mwifiex_ie_types_htinfo));
361 ht_info->header.type =
362 cpu_to_le16(WLAN_EID_HT_INFORMATION);
363 ht_info->header.len =
364 cpu_to_le16(sizeof(struct ieee80211_ht_info));
365
366 memcpy((u8 *) ht_info +
367 sizeof(struct mwifiex_ie_types_header),
368 (u8 *) bss_desc->bcn_ht_info +
369 sizeof(struct ieee_types_header),
370 le16_to_cpu(ht_info->header.len));
371
a46b7b5c
AK
372 if (!(sband->ht_cap.cap &
373 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
6d2bd916
MY
374 ht_info->ht_info.ht_param &=
375 ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
376 IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
5e6e3a92
BZ
377
378 *buffer += sizeof(struct mwifiex_ie_types_htinfo);
379 ret_len += sizeof(struct mwifiex_ie_types_htinfo);
380 }
381
382 chan_list =
383 (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
384 memset(chan_list, 0,
385 sizeof(struct mwifiex_ie_types_chan_list_param_set));
386 chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
387 chan_list->header.len = cpu_to_le16(
388 sizeof(struct mwifiex_ie_types_chan_list_param_set) -
389 sizeof(struct mwifiex_ie_types_header));
390 chan_list->chan_scan_param[0].chan_number =
391 bss_desc->bcn_ht_info->control_chan;
392 chan_list->chan_scan_param[0].radio_type =
393 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
394
a46b7b5c 395 if ((sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
6d2bd916
MY
396 && (bss_desc->bcn_ht_info->ht_param &
397 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY))
5e6e3a92
BZ
398 SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
399 radio_type,
6d2bd916
MY
400 (bss_desc->bcn_ht_info->ht_param &
401 IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
5e6e3a92
BZ
402
403 *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
404 ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
405 }
406
407 if (bss_desc->bcn_bss_co_2040) {
408 bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
409 memset(bss_co_2040, 0,
410 sizeof(struct mwifiex_ie_types_2040bssco));
411 bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
412 bss_co_2040->header.len =
413 cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
414
415 memcpy((u8 *) bss_co_2040 +
416 sizeof(struct mwifiex_ie_types_header),
417 (u8 *) bss_desc->bcn_bss_co_2040 +
418 sizeof(struct ieee_types_header),
419 le16_to_cpu(bss_co_2040->header.len));
420
421 *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
422 ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
423 }
424
425 if (bss_desc->bcn_ext_cap) {
426 ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
427 memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
428 ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
429 ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
430
431 memcpy((u8 *) ext_cap +
432 sizeof(struct mwifiex_ie_types_header),
433 (u8 *) bss_desc->bcn_ext_cap +
434 sizeof(struct ieee_types_header),
435 le16_to_cpu(ext_cap->header.len));
436
437 *buffer += sizeof(struct mwifiex_ie_types_extcap);
438 ret_len += sizeof(struct mwifiex_ie_types_extcap);
439 }
440
441 return ret_len;
442}
443
444/*
445 * This function reconfigures the Tx buffer size in firmware.
446 *
447 * This function prepares a firmware command and issues it, if
448 * the current Tx buffer size is different from the one requested.
449 * Maximum configurable Tx buffer size is limited by the HT capability
450 * field value.
451 */
452void
453mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
454 struct mwifiex_bssdescriptor *bss_desc)
455{
456 u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
270e58e8 457 u16 tx_buf, curr_tx_buf_size = 0;
5e6e3a92
BZ
458
459 if (bss_desc->bcn_ht_cap) {
6d2bd916
MY
460 if (le16_to_cpu(bss_desc->bcn_ht_cap->cap_info) &
461 IEEE80211_HT_CAP_MAX_AMSDU)
5e6e3a92
BZ
462 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
463 else
464 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
465 }
466
467 tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
468
469 dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
470 max_amsdu, priv->adapter->max_tx_buf_size);
471
472 if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
473 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
474 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
475 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
476 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
477 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
478 if (curr_tx_buf_size != tx_buf)
600f5d90
AK
479 mwifiex_send_cmd_async(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
480 HostCmd_ACT_GEN_SET, 0, &tx_buf);
5e6e3a92
BZ
481}
482
483/*
484 * This function checks if the given pointer is valid entry of
485 * Tx BA Stream table.
486 */
487static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
488 struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
489{
490 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
491
492 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
493 if (tx_ba_tsr_tbl == tx_tbl_ptr)
494 return true;
495 }
496
497 return false;
498}
499
500/*
501 * This function deletes the given entry in Tx BA Stream table.
502 *
503 * The function also performs a validity check on the supplied
504 * pointer before trying to delete.
505 */
506void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
507 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
508{
509 if (!tx_ba_tsr_tbl &&
510 mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
511 return;
512
513 dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
514
515 list_del(&tx_ba_tsr_tbl->list);
516
517 kfree(tx_ba_tsr_tbl);
5e6e3a92
BZ
518}
519
520/*
521 * This function deletes all the entries in Tx BA Stream table.
522 */
523void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
524{
525 int i;
526 struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
527 unsigned long flags;
528
529 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
530 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
531 &priv->tx_ba_stream_tbl_ptr, list)
532 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
533 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
534
535 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
536
537 for (i = 0; i < MAX_NUM_TID; ++i)
538 priv->aggr_prio_tbl[i].ampdu_ap =
539 priv->aggr_prio_tbl[i].ampdu_user;
540}
541
542/*
543 * This function returns the pointer to an entry in BA Stream
544 * table which matches the given RA/TID pair.
545 */
546struct mwifiex_tx_ba_stream_tbl *
547mwifiex_11n_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
548 int tid, u8 *ra)
549{
550 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
551 unsigned long flags;
552
553 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
554 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
555 if ((!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN))
556 && (tx_ba_tsr_tbl->tid == tid)) {
557 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
558 flags);
559 return tx_ba_tsr_tbl;
560 }
561 }
562 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
563 return NULL;
564}
565
566/*
567 * This function creates an entry in Tx BA stream table for the
568 * given RA/TID pair.
569 */
570void mwifiex_11n_create_tx_ba_stream_tbl(struct mwifiex_private *priv,
571 u8 *ra, int tid,
572 enum mwifiex_ba_status ba_status)
573{
574 struct mwifiex_tx_ba_stream_tbl *new_node;
575 unsigned long flags;
576
577 if (!mwifiex_11n_get_tx_ba_stream_tbl(priv, tid, ra)) {
578 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
579 GFP_ATOMIC);
580 if (!new_node) {
581 dev_err(priv->adapter->dev,
582 "%s: failed to alloc new_node\n", __func__);
583 return;
584 }
585
586 INIT_LIST_HEAD(&new_node->list);
587
588 new_node->tid = tid;
589 new_node->ba_status = ba_status;
590 memcpy(new_node->ra, ra, ETH_ALEN);
591
592 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
593 list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
594 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
595 }
5e6e3a92
BZ
596}
597
598/*
599 * This function sends an add BA request to the given TID/RA pair.
600 */
601int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
602{
603 struct host_cmd_ds_11n_addba_req add_ba_req;
604 static u8 dialog_tok;
605 int ret;
606
607 dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
608
609 add_ba_req.block_ack_param_set = cpu_to_le16(
610 (u16) ((tid << BLOCKACKPARAM_TID_POS) |
611 (priv->add_ba_param.
612 tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
613 IMMEDIATE_BLOCK_ACK));
614 add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
615
616 ++dialog_tok;
617
618 if (dialog_tok == 0)
619 dialog_tok = 1;
620
621 add_ba_req.dialog_token = dialog_tok;
622 memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
623
624 /* We don't wait for the response of this command */
600f5d90
AK
625 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
626 0, 0, &add_ba_req);
5e6e3a92
BZ
627
628 return ret;
629}
630
631/*
632 * This function sends a delete BA request to the given TID/RA pair.
633 */
634int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
635 int initiator)
636{
637 struct host_cmd_ds_11n_delba delba;
638 int ret;
639 uint16_t del_ba_param_set;
640
641 memset(&delba, 0, sizeof(delba));
642 delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
643
644 del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
645 if (initiator)
646 del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
647 else
648 del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
649
650 memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
651
652 /* We don't wait for the response of this command */
600f5d90
AK
653 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
654 HostCmd_ACT_GEN_SET, 0, &delba);
5e6e3a92
BZ
655
656 return ret;
657}
658
659/*
660 * This function handles the command response of a delete BA request.
661 */
662void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
663{
664 struct host_cmd_ds_11n_delba *cmd_del_ba =
665 (struct host_cmd_ds_11n_delba *) del_ba;
666 uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
667 int tid;
668
669 tid = del_ba_param_set >> DELBA_TID_POS;
670
671 mwifiex_11n_delete_ba_stream_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
672 TYPE_DELBA_RECEIVE,
673 INITIATOR_BIT(del_ba_param_set));
674}
675
676/*
677 * This function retrieves the Rx reordering table.
678 */
679int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
680 struct mwifiex_ds_rx_reorder_tbl *buf)
681{
682 int i;
683 struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
684 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
685 int count = 0;
686 unsigned long flags;
687
688 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
689 list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
690 list) {
691 rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
692 memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
693 rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
694 rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
695 for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
696 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
697 rx_reo_tbl->buffer[i] = true;
698 else
699 rx_reo_tbl->buffer[i] = false;
700 }
701 rx_reo_tbl++;
702 count++;
703
704 if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
705 break;
706 }
707 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
708
709 return count;
710}
711
712/*
713 * This function retrieves the Tx BA stream table.
714 */
715int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
716 struct mwifiex_ds_tx_ba_stream_tbl *buf)
717{
718 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
719 struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
720 int count = 0;
721 unsigned long flags;
722
723 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
724 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
725 rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
726 dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
727 __func__, rx_reo_tbl->tid);
728 memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
729 rx_reo_tbl++;
730 count++;
731 if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
732 break;
733 }
734 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
735
736 return count;
737}
This page took 0.156574 seconds and 5 git commands to generate.