ethernet: Remove casts to same type
[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 &
84266841 47 IEEE80211_HT_AMPDU_PARM_FACTOR) |
a46b7b5c
AK
48 ((sband->ht_cap.ampdu_density <<
49 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) &
50 IEEE80211_HT_AMPDU_PARM_DENSITY);
5e6e3a92 51
a46b7b5c 52 memcpy((u8 *) &ht_cap->ht_cap.mcs, &sband->ht_cap.mcs,
84266841 53 sizeof(sband->ht_cap.mcs));
5e6e3a92 54
eecd8250 55 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
84266841 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 *
3e822635
YAP
72mwifiex_get_ba_status(struct mwifiex_private *priv,
73 enum mwifiex_ba_status ba_status)
5e6e3a92
BZ
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) {
3e822635
YAP
110 mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr,
111 TYPE_DELBA_SENT,
112 INITIATOR_BIT(del_ba_param_set));
5e6e3a92 113
3e822635 114 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
5e6e3a92
BZ
115 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 */
3e822635
YAP
122 if (!INITIATOR_BIT(del_ba_param_set))
123 return 0;
124
125 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);
5e6e3a92
BZ
133 }
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) {
3e822635 161 tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid,
5e6e3a92
BZ
162 add_ba_rsp->peer_mac_addr);
163 if (tx_ba_tbl) {
164 dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
3e822635 165 tx_ba_tbl->ba_status = BA_SETUP_COMPLETE;
5e6e3a92
BZ
166 } else {
167 dev_err(priv->adapter->dev, "BA stream not created\n");
168 }
169 } else {
3e822635
YAP
170 mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr,
171 TYPE_DELBA_SENT, true);
5e6e3a92
BZ
172 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 */
a5ffddb7
AK
185int mwifiex_ret_11n_cfg(struct host_cmd_ds_command *resp,
186 struct mwifiex_ds_11n_tx_cfg *tx_cfg)
5e6e3a92 187{
5e6e3a92
BZ
188 struct host_cmd_ds_11n_cfg *htcfg = &resp->params.htcfg;
189
a5ffddb7 190 if (tx_cfg) {
5e6e3a92
BZ
191 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,
a5ffddb7 207 u16 *buf_size)
5e6e3a92
BZ
208{
209 struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
210 u16 action = (u16) cmd_action;
5e6e3a92
BZ
211
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:
a5ffddb7
AK
218 dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
219 tx_buf->buff_size = cpu_to_le16(*buf_size);
5e6e3a92
BZ
220 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 */
572e8f3e 237int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
a5ffddb7
AK
238 int cmd_action,
239 struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
5e6e3a92
BZ
240{
241 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
242 &cmd->params.amsdu_aggr_ctrl;
243 u16 action = (u16) cmd_action;
5e6e3a92
BZ
244
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 */
572e8f3e 268int mwifiex_ret_amsdu_aggr_ctrl(struct host_cmd_ds_command *resp,
a5ffddb7
AK
269 struct mwifiex_ds_11n_amsdu_aggr_ctrl
270 *amsdu_aggr_ctrl)
5e6e3a92 271{
5e6e3a92
BZ
272 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
273 &resp->params.amsdu_aggr_ctrl;
274
a5ffddb7 275 if (amsdu_aggr_ctrl) {
5e6e3a92
BZ
276 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 */
a5ffddb7
AK
291int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action,
292 struct mwifiex_ds_11n_tx_cfg *txcfg)
5e6e3a92
BZ
293{
294 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
5e6e3a92
BZ
295
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;
a46b7b5c
AK
327 struct ieee80211_supported_band *sband;
328 u8 radio_type;
5e6e3a92
BZ
329
330 if (!buffer || !*buffer)
331 return ret_len;
332
a46b7b5c
AK
333 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
334 sband = priv->wdev->wiphy->bands[radio_type];
335
5e6e3a92
BZ
336 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),
343 (u8 *) bss_desc->bcn_ht_cap +
344 sizeof(struct ieee_types_header),
345 le16_to_cpu(ht_cap->header.len));
346
a46b7b5c 347 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
5e6e3a92
BZ
348
349 *buffer += sizeof(struct mwifiex_ie_types_htcap);
350 ret_len += sizeof(struct mwifiex_ie_types_htcap);
351 }
352
074d46d1 353 if (bss_desc->bcn_ht_oper) {
eecd8250 354 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
355 ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
356 memset(ht_info, 0,
357 sizeof(struct mwifiex_ie_types_htinfo));
358 ht_info->header.type =
074d46d1 359 cpu_to_le16(WLAN_EID_HT_OPERATION);
5e6e3a92 360 ht_info->header.len =
074d46d1
JB
361 cpu_to_le16(
362 sizeof(struct ieee80211_ht_operation));
5e6e3a92
BZ
363
364 memcpy((u8 *) ht_info +
365 sizeof(struct mwifiex_ie_types_header),
074d46d1 366 (u8 *) bss_desc->bcn_ht_oper +
5e6e3a92
BZ
367 sizeof(struct ieee_types_header),
368 le16_to_cpu(ht_info->header.len));
369
a46b7b5c
AK
370 if (!(sband->ht_cap.cap &
371 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
074d46d1 372 ht_info->ht_oper.ht_param &=
6d2bd916
MY
373 ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
374 IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
5e6e3a92
BZ
375
376 *buffer += sizeof(struct mwifiex_ie_types_htinfo);
377 ret_len += sizeof(struct mwifiex_ie_types_htinfo);
378 }
379
380 chan_list =
381 (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
382 memset(chan_list, 0,
383 sizeof(struct mwifiex_ie_types_chan_list_param_set));
384 chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
385 chan_list->header.len = cpu_to_le16(
386 sizeof(struct mwifiex_ie_types_chan_list_param_set) -
387 sizeof(struct mwifiex_ie_types_header));
388 chan_list->chan_scan_param[0].chan_number =
074d46d1 389 bss_desc->bcn_ht_oper->primary_chan;
5e6e3a92
BZ
390 chan_list->chan_scan_param[0].radio_type =
391 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
392
84266841 393 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
074d46d1 394 bss_desc->bcn_ht_oper->ht_param &
84266841 395 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
5e6e3a92
BZ
396 SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
397 radio_type,
074d46d1 398 (bss_desc->bcn_ht_oper->ht_param &
6d2bd916 399 IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
5e6e3a92
BZ
400
401 *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
402 ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
403 }
404
405 if (bss_desc->bcn_bss_co_2040) {
406 bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
407 memset(bss_co_2040, 0,
408 sizeof(struct mwifiex_ie_types_2040bssco));
409 bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
410 bss_co_2040->header.len =
411 cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
412
413 memcpy((u8 *) bss_co_2040 +
414 sizeof(struct mwifiex_ie_types_header),
415 (u8 *) bss_desc->bcn_bss_co_2040 +
416 sizeof(struct ieee_types_header),
417 le16_to_cpu(bss_co_2040->header.len));
418
419 *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
420 ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
421 }
422
423 if (bss_desc->bcn_ext_cap) {
424 ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
425 memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
426 ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
427 ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
428
429 memcpy((u8 *) ext_cap +
430 sizeof(struct mwifiex_ie_types_header),
431 (u8 *) bss_desc->bcn_ext_cap +
432 sizeof(struct ieee_types_header),
433 le16_to_cpu(ext_cap->header.len));
434
435 *buffer += sizeof(struct mwifiex_ie_types_extcap);
436 ret_len += sizeof(struct mwifiex_ie_types_extcap);
437 }
438
439 return ret_len;
440}
441
442/*
443 * This function reconfigures the Tx buffer size in firmware.
444 *
445 * This function prepares a firmware command and issues it, if
446 * the current Tx buffer size is different from the one requested.
447 * Maximum configurable Tx buffer size is limited by the HT capability
448 * field value.
449 */
450void
451mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
452 struct mwifiex_bssdescriptor *bss_desc)
453{
454 u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
270e58e8 455 u16 tx_buf, curr_tx_buf_size = 0;
5e6e3a92
BZ
456
457 if (bss_desc->bcn_ht_cap) {
6d2bd916
MY
458 if (le16_to_cpu(bss_desc->bcn_ht_cap->cap_info) &
459 IEEE80211_HT_CAP_MAX_AMSDU)
5e6e3a92
BZ
460 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
461 else
462 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
463 }
464
465 tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
466
467 dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
84266841 468 max_amsdu, priv->adapter->max_tx_buf_size);
5e6e3a92
BZ
469
470 if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
471 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
472 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
473 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
474 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
475 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
476 if (curr_tx_buf_size != tx_buf)
600f5d90
AK
477 mwifiex_send_cmd_async(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
478 HostCmd_ACT_GEN_SET, 0, &tx_buf);
5e6e3a92
BZ
479}
480
481/*
482 * This function checks if the given pointer is valid entry of
483 * Tx BA Stream table.
484 */
485static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
486 struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
487{
488 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
489
490 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
491 if (tx_ba_tsr_tbl == tx_tbl_ptr)
492 return true;
493 }
494
495 return false;
496}
497
498/*
499 * This function deletes the given entry in Tx BA Stream table.
500 *
501 * The function also performs a validity check on the supplied
502 * pointer before trying to delete.
503 */
504void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
505 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
506{
507 if (!tx_ba_tsr_tbl &&
84266841 508 mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
5e6e3a92
BZ
509 return;
510
511 dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
512
513 list_del(&tx_ba_tsr_tbl->list);
514
515 kfree(tx_ba_tsr_tbl);
5e6e3a92
BZ
516}
517
518/*
519 * This function deletes all the entries in Tx BA Stream table.
520 */
521void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
522{
523 int i;
524 struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
525 unsigned long flags;
526
527 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
528 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
529 &priv->tx_ba_stream_tbl_ptr, list)
530 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
531 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
532
533 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
534
535 for (i = 0; i < MAX_NUM_TID; ++i)
536 priv->aggr_prio_tbl[i].ampdu_ap =
537 priv->aggr_prio_tbl[i].ampdu_user;
538}
539
540/*
541 * This function returns the pointer to an entry in BA Stream
542 * table which matches the given RA/TID pair.
543 */
544struct mwifiex_tx_ba_stream_tbl *
3e822635 545mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
5e6e3a92
BZ
546{
547 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
548 unsigned long flags;
549
550 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
551 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
84266841
YAP
552 if (!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN) &&
553 tx_ba_tsr_tbl->tid == tid) {
5e6e3a92
BZ
554 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
555 flags);
556 return tx_ba_tsr_tbl;
557 }
558 }
559 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
560 return NULL;
561}
562
563/*
564 * This function creates an entry in Tx BA stream table for the
565 * given RA/TID pair.
566 */
3e822635
YAP
567void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
568 enum mwifiex_ba_status ba_status)
5e6e3a92
BZ
569{
570 struct mwifiex_tx_ba_stream_tbl *new_node;
571 unsigned long flags;
572
3e822635 573 if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
5e6e3a92
BZ
574 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
575 GFP_ATOMIC);
576 if (!new_node) {
577 dev_err(priv->adapter->dev,
578 "%s: failed to alloc new_node\n", __func__);
579 return;
580 }
581
582 INIT_LIST_HEAD(&new_node->list);
583
584 new_node->tid = tid;
585 new_node->ba_status = ba_status;
586 memcpy(new_node->ra, ra, ETH_ALEN);
587
588 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
589 list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
590 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
591 }
5e6e3a92
BZ
592}
593
594/*
595 * This function sends an add BA request to the given TID/RA pair.
596 */
597int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
598{
599 struct host_cmd_ds_11n_addba_req add_ba_req;
600 static u8 dialog_tok;
601 int ret;
602
603 dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
604
605 add_ba_req.block_ack_param_set = cpu_to_le16(
606 (u16) ((tid << BLOCKACKPARAM_TID_POS) |
607 (priv->add_ba_param.
608 tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
609 IMMEDIATE_BLOCK_ACK));
610 add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
611
612 ++dialog_tok;
613
614 if (dialog_tok == 0)
615 dialog_tok = 1;
616
617 add_ba_req.dialog_token = dialog_tok;
618 memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
619
620 /* We don't wait for the response of this command */
600f5d90
AK
621 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
622 0, 0, &add_ba_req);
5e6e3a92
BZ
623
624 return ret;
625}
626
627/*
628 * This function sends a delete BA request to the given TID/RA pair.
629 */
630int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
631 int initiator)
632{
633 struct host_cmd_ds_11n_delba delba;
634 int ret;
635 uint16_t del_ba_param_set;
636
637 memset(&delba, 0, sizeof(delba));
638 delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
639
640 del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
641 if (initiator)
642 del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
643 else
644 del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
645
646 memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
647
648 /* We don't wait for the response of this command */
600f5d90
AK
649 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
650 HostCmd_ACT_GEN_SET, 0, &delba);
5e6e3a92
BZ
651
652 return ret;
653}
654
655/*
656 * This function handles the command response of a delete BA request.
657 */
658void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
659{
660 struct host_cmd_ds_11n_delba *cmd_del_ba =
661 (struct host_cmd_ds_11n_delba *) del_ba;
662 uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
663 int tid;
664
665 tid = del_ba_param_set >> DELBA_TID_POS;
666
3e822635
YAP
667 mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
668 TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
5e6e3a92
BZ
669}
670
671/*
672 * This function retrieves the Rx reordering table.
673 */
674int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
675 struct mwifiex_ds_rx_reorder_tbl *buf)
676{
677 int i;
678 struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
679 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
680 int count = 0;
681 unsigned long flags;
682
683 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
684 list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
685 list) {
686 rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
687 memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
688 rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
689 rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
690 for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
691 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
692 rx_reo_tbl->buffer[i] = true;
693 else
694 rx_reo_tbl->buffer[i] = false;
695 }
696 rx_reo_tbl++;
697 count++;
698
699 if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
700 break;
701 }
702 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
703
704 return count;
705}
706
707/*
708 * This function retrieves the Tx BA stream table.
709 */
710int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
711 struct mwifiex_ds_tx_ba_stream_tbl *buf)
712{
713 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
714 struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
715 int count = 0;
716 unsigned long flags;
717
718 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
719 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
720 rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
721 dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
84266841 722 __func__, rx_reo_tbl->tid);
5e6e3a92
BZ
723 memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
724 rx_reo_tbl++;
725 count++;
726 if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
727 break;
728 }
729 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
730
731 return count;
732}
This page took 0.161871 seconds and 5 git commands to generate.