Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless
[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 ||
d35f1035
AK
56 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
57 (priv->adapter->sec_chan_offset !=
58 IEEE80211_HT_PARAM_CHA_SEC_NONE)))
5e6e3a92
BZ
59 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
60 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
61
62 /* Clear RD responder bit */
a3731658 63 ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER;
5e6e3a92 64
a46b7b5c 65 ht_cap->ht_cap.cap_info = cpu_to_le16(sband->ht_cap.cap);
5e6e3a92
BZ
66 ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
67}
68
5e6e3a92
BZ
69/*
70 * This function returns the pointer to an entry in BA Stream
71 * table which matches the requested BA status.
72 */
73static struct mwifiex_tx_ba_stream_tbl *
3e822635
YAP
74mwifiex_get_ba_status(struct mwifiex_private *priv,
75 enum mwifiex_ba_status ba_status)
5e6e3a92
BZ
76{
77 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
78 unsigned long flags;
79
80 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
81 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
82 if (tx_ba_tsr_tbl->ba_status == ba_status) {
83 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
84 flags);
85 return tx_ba_tsr_tbl;
86 }
87 }
88 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
89 return NULL;
90}
91
92/*
93 * This function handles the command response of delete a block
94 * ack request.
95 *
96 * The function checks the response success status and takes action
97 * accordingly (send an add BA request in case of success, or recreate
98 * the deleted stream in case of failure, if the add BA was also
99 * initiated by us).
100 */
101int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
102 struct host_cmd_ds_command *resp)
103{
104 int tid;
105 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
2c208890 106 struct host_cmd_ds_11n_delba *del_ba = &resp->params.del_ba;
5e6e3a92
BZ
107 uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
108
109 tid = del_ba_param_set >> DELBA_TID_POS;
110 if (del_ba->del_result == BA_RESULT_SUCCESS) {
3e822635
YAP
111 mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr,
112 TYPE_DELBA_SENT,
113 INITIATOR_BIT(del_ba_param_set));
5e6e3a92 114
3e822635 115 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
5e6e3a92
BZ
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 */
3e822635
YAP
123 if (!INITIATOR_BIT(del_ba_param_set))
124 return 0;
125
126 mwifiex_create_ba_tbl(priv, del_ba->peer_mac_addr, tid,
127 BA_SETUP_INPROGRESS);
128
129 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
130
131 if (tx_ba_tbl)
132 mwifiex_del_ba_tbl(priv, tx_ba_tbl->tid, tx_ba_tbl->ra,
133 TYPE_DELBA_SENT, true);
5e6e3a92
BZ
134 }
135
136 return 0;
137}
138
139/*
140 * This function handles the command response of add a block
141 * ack request.
142 *
143 * Handling includes changing the header fields to CPU formats, checking
144 * the response success status and taking actions accordingly (delete the
145 * BA stream table in case of failure).
146 */
147int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
148 struct host_cmd_ds_command *resp)
149{
150 int tid;
2c208890 151 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
5e6e3a92
BZ
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
5e6e3a92
BZ
180/*
181 * This function prepares command of reconfigure Tx buffer.
182 *
183 * Preparation includes -
184 * - Setting command ID, action and proper size
185 * - Setting Tx buffer size (for SET only)
186 * - Ensuring correct endian-ness
187 */
188int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
189 struct host_cmd_ds_command *cmd, int cmd_action,
a5ffddb7 190 u16 *buf_size)
5e6e3a92
BZ
191{
192 struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
193 u16 action = (u16) cmd_action;
5e6e3a92
BZ
194
195 cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
196 cmd->size =
197 cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
198 tx_buf->action = cpu_to_le16(action);
199 switch (action) {
200 case HostCmd_ACT_GEN_SET:
a5ffddb7
AK
201 dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
202 tx_buf->buff_size = cpu_to_le16(*buf_size);
5e6e3a92
BZ
203 break;
204 case HostCmd_ACT_GEN_GET:
205 default:
206 tx_buf->buff_size = 0;
207 break;
208 }
209 return 0;
210}
211
212/*
213 * This function prepares command of AMSDU aggregation control.
214 *
215 * Preparation includes -
216 * - Setting command ID, action and proper size
217 * - Setting AMSDU control parameters (for SET only)
218 * - Ensuring correct endian-ness
219 */
572e8f3e 220int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
a5ffddb7
AK
221 int cmd_action,
222 struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
5e6e3a92
BZ
223{
224 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
225 &cmd->params.amsdu_aggr_ctrl;
226 u16 action = (u16) cmd_action;
5e6e3a92
BZ
227
228 cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
229 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
230 + S_DS_GEN);
231 amsdu_ctrl->action = cpu_to_le16(action);
232 switch (action) {
233 case HostCmd_ACT_GEN_SET:
234 amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
235 amsdu_ctrl->curr_buf_size = 0;
236 break;
237 case HostCmd_ACT_GEN_GET:
238 default:
239 amsdu_ctrl->curr_buf_size = 0;
240 break;
241 }
242 return 0;
243}
244
5e6e3a92
BZ
245/*
246 * This function prepares 11n configuration command.
247 *
248 * Preparation includes -
249 * - Setting command ID, action and proper size
250 * - Setting HT Tx capability and HT Tx information fields
251 * - Ensuring correct endian-ness
252 */
a5f39056
YAP
253int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
254 struct host_cmd_ds_command *cmd, u16 cmd_action,
a5ffddb7 255 struct mwifiex_ds_11n_tx_cfg *txcfg)
5e6e3a92
BZ
256{
257 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
5e6e3a92
BZ
258
259 cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
260 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
261 htcfg->action = cpu_to_le16(cmd_action);
262 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
263 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
a5f39056
YAP
264
265 if (priv->adapter->is_hw_11ac_capable)
266 htcfg->misc_config = cpu_to_le16(txcfg->misc_config);
267
5e6e3a92
BZ
268 return 0;
269}
270
271/*
272 * This function appends an 11n TLV to a buffer.
273 *
274 * Buffer allocation is responsibility of the calling
275 * function. No size validation is made here.
276 *
277 * The function fills up the following sections, if applicable -
278 * - HT capability IE
279 * - HT information IE (with channel list)
280 * - 20/40 BSS Coexistence IE
281 * - HT Extended Capabilities IE
282 */
283int
284mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
285 struct mwifiex_bssdescriptor *bss_desc,
286 u8 **buffer)
287{
288 struct mwifiex_ie_types_htcap *ht_cap;
289 struct mwifiex_ie_types_htinfo *ht_info;
290 struct mwifiex_ie_types_chan_list_param_set *chan_list;
291 struct mwifiex_ie_types_2040bssco *bss_co_2040;
292 struct mwifiex_ie_types_extcap *ext_cap;
293 int ret_len = 0;
a46b7b5c
AK
294 struct ieee80211_supported_band *sband;
295 u8 radio_type;
5e6e3a92
BZ
296
297 if (!buffer || !*buffer)
298 return ret_len;
299
a46b7b5c
AK
300 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
301 sband = priv->wdev->wiphy->bands[radio_type];
302
5e6e3a92
BZ
303 if (bss_desc->bcn_ht_cap) {
304 ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
305 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
306 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
307 ht_cap->header.len =
308 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
309 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
310 (u8 *) bss_desc->bcn_ht_cap +
311 sizeof(struct ieee_types_header),
312 le16_to_cpu(ht_cap->header.len));
313
a46b7b5c 314 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
5e6e3a92
BZ
315
316 *buffer += sizeof(struct mwifiex_ie_types_htcap);
317 ret_len += sizeof(struct mwifiex_ie_types_htcap);
318 }
319
074d46d1 320 if (bss_desc->bcn_ht_oper) {
eecd8250 321 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
322 ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
323 memset(ht_info, 0,
324 sizeof(struct mwifiex_ie_types_htinfo));
325 ht_info->header.type =
074d46d1 326 cpu_to_le16(WLAN_EID_HT_OPERATION);
5e6e3a92 327 ht_info->header.len =
074d46d1
JB
328 cpu_to_le16(
329 sizeof(struct ieee80211_ht_operation));
5e6e3a92
BZ
330
331 memcpy((u8 *) ht_info +
332 sizeof(struct mwifiex_ie_types_header),
074d46d1 333 (u8 *) bss_desc->bcn_ht_oper +
5e6e3a92
BZ
334 sizeof(struct ieee_types_header),
335 le16_to_cpu(ht_info->header.len));
336
a46b7b5c
AK
337 if (!(sband->ht_cap.cap &
338 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
074d46d1 339 ht_info->ht_oper.ht_param &=
6d2bd916
MY
340 ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
341 IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
5e6e3a92
BZ
342
343 *buffer += sizeof(struct mwifiex_ie_types_htinfo);
344 ret_len += sizeof(struct mwifiex_ie_types_htinfo);
345 }
346
347 chan_list =
348 (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
349 memset(chan_list, 0,
350 sizeof(struct mwifiex_ie_types_chan_list_param_set));
351 chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
352 chan_list->header.len = cpu_to_le16(
353 sizeof(struct mwifiex_ie_types_chan_list_param_set) -
354 sizeof(struct mwifiex_ie_types_header));
355 chan_list->chan_scan_param[0].chan_number =
074d46d1 356 bss_desc->bcn_ht_oper->primary_chan;
5e6e3a92
BZ
357 chan_list->chan_scan_param[0].radio_type =
358 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
359
84266841 360 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
074d46d1 361 bss_desc->bcn_ht_oper->ht_param &
84266841 362 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
5e6e3a92
BZ
363 SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
364 radio_type,
074d46d1 365 (bss_desc->bcn_ht_oper->ht_param &
6d2bd916 366 IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
5e6e3a92
BZ
367
368 *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
369 ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
370 }
371
372 if (bss_desc->bcn_bss_co_2040) {
373 bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
374 memset(bss_co_2040, 0,
375 sizeof(struct mwifiex_ie_types_2040bssco));
376 bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
377 bss_co_2040->header.len =
378 cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
379
380 memcpy((u8 *) bss_co_2040 +
381 sizeof(struct mwifiex_ie_types_header),
2c208890 382 bss_desc->bcn_bss_co_2040 +
5e6e3a92
BZ
383 sizeof(struct ieee_types_header),
384 le16_to_cpu(bss_co_2040->header.len));
385
386 *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
387 ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
388 }
389
390 if (bss_desc->bcn_ext_cap) {
391 ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
392 memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
393 ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
394 ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
395
2c208890
JP
396 memcpy((u8 *)ext_cap + sizeof(struct mwifiex_ie_types_header),
397 bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header),
5e6e3a92
BZ
398 le16_to_cpu(ext_cap->header.len));
399
400 *buffer += sizeof(struct mwifiex_ie_types_extcap);
401 ret_len += sizeof(struct mwifiex_ie_types_extcap);
402 }
403
404 return ret_len;
405}
406
5e6e3a92
BZ
407/*
408 * This function checks if the given pointer is valid entry of
409 * Tx BA Stream table.
410 */
411static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
412 struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
413{
414 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
415
416 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
417 if (tx_ba_tsr_tbl == tx_tbl_ptr)
418 return true;
419 }
420
421 return false;
422}
423
424/*
425 * This function deletes the given entry in Tx BA Stream table.
426 *
427 * The function also performs a validity check on the supplied
428 * pointer before trying to delete.
429 */
430void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
431 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
432{
433 if (!tx_ba_tsr_tbl &&
84266841 434 mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
5e6e3a92
BZ
435 return;
436
437 dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
438
439 list_del(&tx_ba_tsr_tbl->list);
440
441 kfree(tx_ba_tsr_tbl);
5e6e3a92
BZ
442}
443
444/*
445 * This function deletes all the entries in Tx BA Stream table.
446 */
447void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
448{
449 int i;
450 struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
451 unsigned long flags;
452
453 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
454 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
455 &priv->tx_ba_stream_tbl_ptr, list)
456 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
457 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
458
459 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
460
461 for (i = 0; i < MAX_NUM_TID; ++i)
462 priv->aggr_prio_tbl[i].ampdu_ap =
463 priv->aggr_prio_tbl[i].ampdu_user;
464}
465
466/*
467 * This function returns the pointer to an entry in BA Stream
468 * table which matches the given RA/TID pair.
469 */
470struct mwifiex_tx_ba_stream_tbl *
3e822635 471mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
5e6e3a92
BZ
472{
473 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
474 unsigned long flags;
475
476 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
477 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
84266841
YAP
478 if (!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN) &&
479 tx_ba_tsr_tbl->tid == tid) {
5e6e3a92
BZ
480 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
481 flags);
482 return tx_ba_tsr_tbl;
483 }
484 }
485 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
486 return NULL;
487}
488
489/*
490 * This function creates an entry in Tx BA stream table for the
491 * given RA/TID pair.
492 */
3e822635
YAP
493void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
494 enum mwifiex_ba_status ba_status)
5e6e3a92
BZ
495{
496 struct mwifiex_tx_ba_stream_tbl *new_node;
497 unsigned long flags;
498
3e822635 499 if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
5e6e3a92
BZ
500 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
501 GFP_ATOMIC);
0d2e7a5c 502 if (!new_node)
5e6e3a92 503 return;
5e6e3a92
BZ
504
505 INIT_LIST_HEAD(&new_node->list);
506
507 new_node->tid = tid;
508 new_node->ba_status = ba_status;
509 memcpy(new_node->ra, ra, ETH_ALEN);
510
511 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
512 list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
513 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
514 }
5e6e3a92
BZ
515}
516
517/*
518 * This function sends an add BA request to the given TID/RA pair.
519 */
520int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
521{
522 struct host_cmd_ds_11n_addba_req add_ba_req;
523 static u8 dialog_tok;
524 int ret;
525
526 dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
527
528 add_ba_req.block_ack_param_set = cpu_to_le16(
529 (u16) ((tid << BLOCKACKPARAM_TID_POS) |
530 (priv->add_ba_param.
531 tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
532 IMMEDIATE_BLOCK_ACK));
533 add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
534
535 ++dialog_tok;
536
537 if (dialog_tok == 0)
538 dialog_tok = 1;
539
540 add_ba_req.dialog_token = dialog_tok;
541 memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
542
543 /* We don't wait for the response of this command */
600f5d90
AK
544 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
545 0, 0, &add_ba_req);
5e6e3a92
BZ
546
547 return ret;
548}
549
550/*
551 * This function sends a delete BA request to the given TID/RA pair.
552 */
553int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
554 int initiator)
555{
556 struct host_cmd_ds_11n_delba delba;
557 int ret;
558 uint16_t del_ba_param_set;
559
560 memset(&delba, 0, sizeof(delba));
561 delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
562
563 del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
564 if (initiator)
565 del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
566 else
567 del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
568
569 memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
570
571 /* We don't wait for the response of this command */
600f5d90
AK
572 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
573 HostCmd_ACT_GEN_SET, 0, &delba);
5e6e3a92
BZ
574
575 return ret;
576}
577
578/*
579 * This function handles the command response of a delete BA request.
580 */
581void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
582{
583 struct host_cmd_ds_11n_delba *cmd_del_ba =
584 (struct host_cmd_ds_11n_delba *) del_ba;
585 uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
586 int tid;
587
588 tid = del_ba_param_set >> DELBA_TID_POS;
589
3e822635
YAP
590 mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
591 TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
5e6e3a92
BZ
592}
593
594/*
595 * This function retrieves the Rx reordering table.
596 */
597int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
598 struct mwifiex_ds_rx_reorder_tbl *buf)
599{
600 int i;
601 struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
602 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
603 int count = 0;
604 unsigned long flags;
605
606 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
607 list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
608 list) {
609 rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
610 memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
611 rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
612 rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
613 for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
614 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
615 rx_reo_tbl->buffer[i] = true;
616 else
617 rx_reo_tbl->buffer[i] = false;
618 }
619 rx_reo_tbl++;
620 count++;
621
622 if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
623 break;
624 }
625 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
626
627 return count;
628}
629
630/*
631 * This function retrieves the Tx BA stream table.
632 */
633int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
634 struct mwifiex_ds_tx_ba_stream_tbl *buf)
635{
636 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
637 struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
638 int count = 0;
639 unsigned long flags;
640
641 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
642 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
643 rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
644 dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
84266841 645 __func__, rx_reo_tbl->tid);
5e6e3a92
BZ
646 memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
647 rx_reo_tbl++;
648 count++;
649 if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
650 break;
651 }
652 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
653
654 return count;
655}
3e238a11
AP
656
657/*
658 * This function retrieves the entry for specific tx BA stream table by RA and
659 * deletes it.
660 */
661void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra)
662{
663 struct mwifiex_tx_ba_stream_tbl *tbl, *tmp;
664 unsigned long flags;
665
666 if (!ra)
667 return;
668
669 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
670 list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list) {
671 if (!memcmp(tbl->ra, ra, ETH_ALEN)) {
672 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
673 flags);
674 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl);
675 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
676 }
677 }
678 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
679
680 return;
681}
This page took 0.21666 seconds and 5 git commands to generate.