rtlwifi: Remove redundant if clause
[deliverable/linux.git] / drivers / net / wireless / mwifiex / 11n_rxreorder.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: 802.11n RX Re-ordering
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#include "11n_rxreorder.h"
28
5e6e3a92 29/*
8c00228e
YAP
30 * This function dispatches all packets in the Rx reorder table until the
31 * start window.
5e6e3a92
BZ
32 *
33 * There could be holes in the buffer, which are skipped by the function.
34 * Since the buffer is linear, the function uses rotation to simulate
35 * circular buffer.
36 */
ab581472 37static void
8c00228e
YAP
38mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv,
39 struct mwifiex_rx_reorder_tbl *tbl, int start_win)
5e6e3a92 40{
8c00228e 41 int pkt_to_send, i;
270e58e8 42 void *rx_tmp_ptr;
5e6e3a92
BZ
43 unsigned long flags;
44
8c00228e
YAP
45 pkt_to_send = (start_win > tbl->start_win) ?
46 min((start_win - tbl->start_win), tbl->win_size) :
47 tbl->win_size;
5e6e3a92 48
8c00228e 49 for (i = 0; i < pkt_to_send; ++i) {
5e6e3a92
BZ
50 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
51 rx_tmp_ptr = NULL;
8c00228e
YAP
52 if (tbl->rx_reorder_ptr[i]) {
53 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
54 tbl->rx_reorder_ptr[i] = NULL;
5e6e3a92
BZ
55 }
56 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
d1cf3b95
AP
57 if (rx_tmp_ptr) {
58 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
59 mwifiex_handle_uap_rx_forward(priv, rx_tmp_ptr);
60 else
f3b369e4 61 mwifiex_process_rx_packet(priv, rx_tmp_ptr);
d1cf3b95 62 }
5e6e3a92
BZ
63 }
64
65 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
66 /*
67 * We don't have a circular buffer, hence use rotation to simulate
68 * circular buffer
69 */
8c00228e
YAP
70 for (i = 0; i < tbl->win_size - pkt_to_send; ++i) {
71 tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i];
72 tbl->rx_reorder_ptr[pkt_to_send + i] = NULL;
5e6e3a92
BZ
73 }
74
8c00228e 75 tbl->start_win = start_win;
5e6e3a92 76 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
5e6e3a92
BZ
77}
78
79/*
80 * This function dispatches all packets in the Rx reorder table until
81 * a hole is found.
82 *
83 * The start window is adjusted automatically when a hole is located.
84 * Since the buffer is linear, the function uses rotation to simulate
85 * circular buffer.
86 */
ab581472 87static void
5e6e3a92 88mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv,
8c00228e 89 struct mwifiex_rx_reorder_tbl *tbl)
5e6e3a92
BZ
90{
91 int i, j, xchg;
270e58e8 92 void *rx_tmp_ptr;
5e6e3a92
BZ
93 unsigned long flags;
94
8c00228e 95 for (i = 0; i < tbl->win_size; ++i) {
5e6e3a92 96 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
8c00228e 97 if (!tbl->rx_reorder_ptr[i]) {
5e6e3a92
BZ
98 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
99 break;
100 }
8c00228e
YAP
101 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
102 tbl->rx_reorder_ptr[i] = NULL;
5e6e3a92 103 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
d1cf3b95
AP
104
105 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
106 mwifiex_handle_uap_rx_forward(priv, rx_tmp_ptr);
107 else
f3b369e4 108 mwifiex_process_rx_packet(priv, rx_tmp_ptr);
5e6e3a92
BZ
109 }
110
111 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
112 /*
113 * We don't have a circular buffer, hence use rotation to simulate
114 * circular buffer
115 */
116 if (i > 0) {
8c00228e 117 xchg = tbl->win_size - i;
5e6e3a92 118 for (j = 0; j < xchg; ++j) {
8c00228e
YAP
119 tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j];
120 tbl->rx_reorder_ptr[i + j] = NULL;
5e6e3a92
BZ
121 }
122 }
8c00228e 123 tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1);
5e6e3a92 124 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
5e6e3a92
BZ
125}
126
127/*
128 * This function deletes the Rx reorder table and frees the memory.
129 *
130 * The function stops the associated timer and dispatches all the
131 * pending packets in the Rx reorder table before deletion.
132 */
133static void
8c00228e
YAP
134mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv,
135 struct mwifiex_rx_reorder_tbl *tbl)
5e6e3a92
BZ
136{
137 unsigned long flags;
138
8c00228e 139 if (!tbl)
5e6e3a92
BZ
140 return;
141
8c00228e
YAP
142 mwifiex_11n_dispatch_pkt(priv, tbl, (tbl->start_win + tbl->win_size) &
143 (MAX_TID_VALUE - 1));
5e6e3a92 144
629873f2 145 del_timer_sync(&tbl->timer_context.timer);
5e6e3a92
BZ
146
147 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
8c00228e 148 list_del(&tbl->list);
5e6e3a92
BZ
149 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
150
8c00228e
YAP
151 kfree(tbl->rx_reorder_ptr);
152 kfree(tbl);
5e6e3a92
BZ
153}
154
155/*
156 * This function returns the pointer to an entry in Rx reordering
157 * table which matches the given TA/TID pair.
158 */
d1cf3b95 159struct mwifiex_rx_reorder_tbl *
5e6e3a92
BZ
160mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
161{
8c00228e 162 struct mwifiex_rx_reorder_tbl *tbl;
5e6e3a92
BZ
163 unsigned long flags;
164
165 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
8c00228e
YAP
166 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) {
167 if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) {
5e6e3a92
BZ
168 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
169 flags);
8c00228e 170 return tbl;
5e6e3a92
BZ
171 }
172 }
173 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
174
175 return NULL;
176}
177
3e238a11
AP
178/* This function retrieves the pointer to an entry in Rx reordering
179 * table which matches the given TA and deletes it.
180 */
181void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta)
182{
183 struct mwifiex_rx_reorder_tbl *tbl, *tmp;
184 unsigned long flags;
185
186 if (!ta)
187 return;
188
189 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
190 list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) {
191 if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
192 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
193 flags);
194 mwifiex_del_rx_reorder_entry(priv, tbl);
195 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
196 }
197 }
198 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
199
200 return;
201}
202
5e6e3a92
BZ
203/*
204 * This function finds the last sequence number used in the packets
205 * buffered in Rx reordering table.
206 */
207static int
208mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr)
209{
210 int i;
211
212 for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i)
213 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
214 return i;
215
216 return -1;
217}
218
219/*
220 * This function flushes all the packets in Rx reordering table.
221 *
222 * The function checks if any packets are currently buffered in the
223 * table or not. In case there are packets available, it dispatches
224 * them and then dumps the Rx reordering table.
225 */
226static void
227mwifiex_flush_data(unsigned long context)
228{
8c00228e 229 struct reorder_tmr_cnxt *ctx =
5e6e3a92
BZ
230 (struct reorder_tmr_cnxt *) context;
231 int start_win;
232
8c00228e 233 start_win = mwifiex_11n_find_last_seq_num(ctx->ptr);
bb7de2ba
YAP
234
235 if (start_win < 0)
236 return;
237
8c00228e
YAP
238 dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", start_win);
239 mwifiex_11n_dispatch_pkt(ctx->priv, ctx->ptr,
240 (ctx->ptr->start_win + start_win + 1) &
241 (MAX_TID_VALUE - 1));
5e6e3a92
BZ
242}
243
244/*
245 * This function creates an entry in Rx reordering table for the
246 * given TA/TID.
247 *
248 * The function also initializes the entry with sequence number, window
249 * size as well as initializes the timer.
250 *
251 * If the received TA/TID pair is already present, all the packets are
252 * dispatched and the window size is moved until the SSN.
253 */
254static void
255mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
84266841 256 int tid, int win_size, int seq_num)
5e6e3a92
BZ
257{
258 int i;
8c00228e 259 struct mwifiex_rx_reorder_tbl *tbl, *new_node;
5e6e3a92
BZ
260 u16 last_seq = 0;
261 unsigned long flags;
5a009adf 262 struct mwifiex_sta_node *node;
5e6e3a92
BZ
263
264 /*
265 * If we get a TID, ta pair which is already present dispatch all the
266 * the packets and move the window size until the ssn
267 */
8c00228e
YAP
268 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
269 if (tbl) {
270 mwifiex_11n_dispatch_pkt(priv, tbl, seq_num);
5e6e3a92
BZ
271 return;
272 }
8c00228e 273 /* if !tbl then create one */
5e6e3a92 274 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
0d2e7a5c 275 if (!new_node)
5e6e3a92 276 return;
5e6e3a92
BZ
277
278 INIT_LIST_HEAD(&new_node->list);
279 new_node->tid = tid;
280 memcpy(new_node->ta, ta, ETH_ALEN);
281 new_node->start_win = seq_num;
8acbea61
PS
282 new_node->init_win = seq_num;
283 new_node->flags = 0;
5a009adf
AP
284
285 if (mwifiex_queuing_ra_based(priv)) {
5e6e3a92 286 dev_dbg(priv->adapter->dev,
5a009adf 287 "info: AP/ADHOC:last_seq=%d start_win=%d\n",
5e6e3a92 288 last_seq, new_node->start_win);
5a009adf
AP
289 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
290 node = mwifiex_get_sta_entry(priv, ta);
291 if (node)
292 last_seq = node->rx_seq[tid];
293 }
294 } else {
daeb5bb4
AP
295 node = mwifiex_get_sta_entry(priv, ta);
296 if (node)
297 last_seq = node->rx_seq[tid];
298 else
299 last_seq = priv->rx_seq[tid];
5a009adf 300 }
5e6e3a92 301
92583924 302 if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
8acbea61 303 last_seq >= new_node->start_win) {
5e6e3a92 304 new_node->start_win = last_seq + 1;
8acbea61
PS
305 new_node->flags |= RXREOR_INIT_WINDOW_SHIFT;
306 }
5e6e3a92
BZ
307
308 new_node->win_size = win_size;
309
310 new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
311 GFP_KERNEL);
312 if (!new_node->rx_reorder_ptr) {
313 kfree((u8 *) new_node);
314 dev_err(priv->adapter->dev,
315 "%s: failed to alloc reorder_ptr\n", __func__);
316 return;
317 }
318
319 new_node->timer_context.ptr = new_node;
320 new_node->timer_context.priv = priv;
321
322 init_timer(&new_node->timer_context.timer);
323 new_node->timer_context.timer.function = mwifiex_flush_data;
324 new_node->timer_context.timer.data =
325 (unsigned long) &new_node->timer_context;
326
327 for (i = 0; i < win_size; ++i)
328 new_node->rx_reorder_ptr[i] = NULL;
329
330 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
331 list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
332 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
5e6e3a92
BZ
333}
334
335/*
336 * This function prepares command for adding a BA request.
337 *
338 * Preparation includes -
339 * - Setting command ID and proper size
340 * - Setting add BA request buffer
341 * - Ensuring correct endian-ness
342 */
572e8f3e 343int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
5e6e3a92 344{
2c208890 345 struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req;
5e6e3a92
BZ
346
347 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
348 cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
349 memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
350
351 return 0;
352}
353
354/*
355 * This function prepares command for adding a BA response.
356 *
357 * Preparation includes -
358 * - Setting command ID and proper size
359 * - Setting add BA response buffer
360 * - Ensuring correct endian-ness
361 */
362int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
363 struct host_cmd_ds_command *cmd,
a5ffddb7
AK
364 struct host_cmd_ds_11n_addba_req
365 *cmd_addba_req)
5e6e3a92 366{
2c208890 367 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp;
b06c5321
AP
368 struct mwifiex_sta_node *sta_ptr;
369 u32 rx_win_size = priv->add_ba_param.rx_win_size;
270e58e8
YAP
370 u8 tid;
371 int win_size;
5e6e3a92
BZ
372 uint16_t block_ack_param_set;
373
b06c5321
AP
374 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
375 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
376 priv->adapter->is_hw_11ac_capable &&
377 memcmp(priv->cfg_bssid, cmd_addba_req->peer_mac_addr, ETH_ALEN)) {
378 sta_ptr = mwifiex_get_sta_entry(priv,
379 cmd_addba_req->peer_mac_addr);
380 if (!sta_ptr) {
381 dev_warn(priv->adapter->dev,
382 "BA setup with unknown TDLS peer %pM!\n",
383 cmd_addba_req->peer_mac_addr);
384 return -1;
385 }
386 if (sta_ptr->is_11ac_enabled)
387 rx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
388 }
389
5e6e3a92
BZ
390 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
391 cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
392
393 memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
394 ETH_ALEN);
395 add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
396 add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
397 add_ba_rsp->ssn = cmd_addba_req->ssn;
398
399 block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
400 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
401 >> BLOCKACKPARAM_TID_POS;
402 add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
403 block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
404 /* We donot support AMSDU inside AMPDU, hence reset the bit */
405 block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
b06c5321 406 block_ack_param_set |= rx_win_size << BLOCKACKPARAM_WINSIZE_POS;
5e6e3a92
BZ
407 add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
408 win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
409 & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
410 >> BLOCKACKPARAM_WINSIZE_POS;
411 cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
412
413 mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
84266841
YAP
414 tid, win_size,
415 le16_to_cpu(cmd_addba_req->ssn));
5e6e3a92
BZ
416 return 0;
417}
418
419/*
420 * This function prepares command for deleting a BA request.
421 *
422 * Preparation includes -
423 * - Setting command ID and proper size
424 * - Setting del BA request buffer
425 * - Ensuring correct endian-ness
426 */
572e8f3e 427int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
5e6e3a92 428{
2c208890 429 struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba;
5e6e3a92
BZ
430
431 cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
432 cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
433 memcpy(del_ba, data_buf, sizeof(*del_ba));
434
435 return 0;
436}
437
438/*
439 * This function identifies if Rx reordering is needed for a received packet.
440 *
441 * In case reordering is required, the function will do the reordering
442 * before sending it to kernel.
443 *
444 * The Rx reorder table is checked first with the received TID/TA pair. If
445 * not found, the received packet is dispatched immediately. But if found,
446 * the packet is reordered and all the packets in the updated Rx reordering
447 * table is dispatched until a hole is found.
448 *
449 * For sequence number less than the starting window, the packet is dropped.
450 */
451int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
452 u16 seq_num, u16 tid,
453 u8 *ta, u8 pkt_type, void *payload)
454{
8c00228e 455 struct mwifiex_rx_reorder_tbl *tbl;
ab581472 456 int start_win, end_win, win_size;
270e58e8 457 u16 pkt_index;
8acbea61 458 bool init_window_shift = false;
5e6e3a92 459
2c208890 460 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
8c00228e 461 if (!tbl) {
d1cf3b95
AP
462 if (pkt_type != PKT_TYPE_BAR) {
463 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
464 mwifiex_handle_uap_rx_forward(priv, payload);
465 else
f3b369e4 466 mwifiex_process_rx_packet(priv, payload);
d1cf3b95 467 }
5e6e3a92
BZ
468 return 0;
469 }
8c00228e
YAP
470 start_win = tbl->start_win;
471 win_size = tbl->win_size;
5e6e3a92 472 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
8acbea61
PS
473 if (tbl->flags & RXREOR_INIT_WINDOW_SHIFT) {
474 init_window_shift = true;
475 tbl->flags &= ~RXREOR_INIT_WINDOW_SHIFT;
476 }
8c00228e 477 mod_timer(&tbl->timer_context.timer,
4587eea5 478 jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size));
5e6e3a92 479
2db96c3d
AP
480 if (tbl->flags & RXREOR_FORCE_NO_DROP) {
481 dev_dbg(priv->adapter->dev,
482 "RXREOR_FORCE_NO_DROP when HS is activated\n");
483 tbl->flags &= ~RXREOR_FORCE_NO_DROP;
8acbea61
PS
484 } else if (init_window_shift && seq_num < start_win &&
485 seq_num >= tbl->init_win) {
486 dev_dbg(priv->adapter->dev,
487 "Sender TID sequence number reset %d->%d for SSN %d\n",
488 start_win, seq_num, tbl->init_win);
489 tbl->start_win = start_win = seq_num;
490 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
2db96c3d 491 } else {
8acbea61
PS
492 /*
493 * If seq_num is less then starting win then ignore and drop
494 * the packet
495 */
2db96c3d
AP
496 if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {
497 if (seq_num >= ((start_win + TWOPOW11) &
498 (MAX_TID_VALUE - 1)) &&
499 seq_num < start_win)
500 return -1;
501 } else if ((seq_num < start_win) ||
502 (seq_num > (start_win + TWOPOW11))) {
5e6e3a92 503 return -1;
2db96c3d 504 }
5e6e3a92
BZ
505 }
506
507 /*
508 * If this packet is a BAR we adjust seq_num as
509 * WinStart = seq_num
510 */
511 if (pkt_type == PKT_TYPE_BAR)
512 seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
513
84266841 514 if (((end_win < start_win) &&
2db96c3d 515 (seq_num < start_win) && (seq_num > end_win)) ||
84266841
YAP
516 ((end_win > start_win) && ((seq_num > end_win) ||
517 (seq_num < start_win)))) {
5e6e3a92
BZ
518 end_win = seq_num;
519 if (((seq_num - win_size) + 1) >= 0)
520 start_win = (end_win - win_size) + 1;
521 else
522 start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
8c00228e 523 mwifiex_11n_dispatch_pkt(priv, tbl, start_win);
5e6e3a92
BZ
524 }
525
526 if (pkt_type != PKT_TYPE_BAR) {
527 if (seq_num >= start_win)
528 pkt_index = seq_num - start_win;
529 else
530 pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
531
8c00228e 532 if (tbl->rx_reorder_ptr[pkt_index])
5e6e3a92
BZ
533 return -1;
534
8c00228e 535 tbl->rx_reorder_ptr[pkt_index] = payload;
5e6e3a92
BZ
536 }
537
538 /*
539 * Dispatch all packets sequentially from start_win until a
540 * hole is found and adjust the start_win appropriately
541 */
8c00228e 542 mwifiex_11n_scan_and_dispatch(priv, tbl);
5e6e3a92 543
ab581472 544 return 0;
5e6e3a92
BZ
545}
546
547/*
548 * This function deletes an entry for a given TID/TA pair.
549 *
550 * The TID/TA are taken from del BA event body.
551 */
552void
3e822635
YAP
553mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
554 u8 type, int initiator)
5e6e3a92 555{
8c00228e 556 struct mwifiex_rx_reorder_tbl *tbl;
5e6e3a92
BZ
557 struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
558 u8 cleanup_rx_reorder_tbl;
559 unsigned long flags;
560
561 if (type == TYPE_DELBA_RECEIVE)
562 cleanup_rx_reorder_tbl = (initiator) ? true : false;
563 else
564 cleanup_rx_reorder_tbl = (initiator) ? false : true;
565
84266841
YAP
566 dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n",
567 peer_mac, tid, initiator);
5e6e3a92
BZ
568
569 if (cleanup_rx_reorder_tbl) {
8c00228e 570 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
5e6e3a92 571 peer_mac);
8c00228e 572 if (!tbl) {
5e6e3a92 573 dev_dbg(priv->adapter->dev,
84266841 574 "event: TID, TA not found in table\n");
5e6e3a92
BZ
575 return;
576 }
8c00228e 577 mwifiex_del_rx_reorder_entry(priv, tbl);
5e6e3a92 578 } else {
3e822635 579 ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
5e6e3a92
BZ
580 if (!ptx_tbl) {
581 dev_dbg(priv->adapter->dev,
84266841 582 "event: TID, RA not found in table\n");
5e6e3a92
BZ
583 return;
584 }
585
586 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
587 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
588 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
589 }
590}
591
592/*
593 * This function handles the command response of an add BA response.
594 *
595 * Handling includes changing the header fields into CPU format and
596 * creating the stream, provided the add BA is accepted.
597 */
598int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
599 struct host_cmd_ds_command *resp)
600{
2c208890 601 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
5e6e3a92 602 int tid, win_size;
8c00228e 603 struct mwifiex_rx_reorder_tbl *tbl;
5e6e3a92
BZ
604 uint16_t block_ack_param_set;
605
606 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
607
608 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
609 >> BLOCKACKPARAM_TID_POS;
610 /*
611 * Check if we had rejected the ADDBA, if yes then do not create
612 * the stream
613 */
614 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
615 win_size = (block_ack_param_set &
616 IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
617 >> BLOCKACKPARAM_WINSIZE_POS;
618
84266841
YAP
619 dev_dbg(priv->adapter->dev,
620 "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
621 add_ba_rsp->peer_mac_addr, tid,
622 add_ba_rsp->ssn, win_size);
5e6e3a92
BZ
623 } else {
624 dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
84266841 625 add_ba_rsp->peer_mac_addr, tid);
5e6e3a92 626
8c00228e
YAP
627 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
628 add_ba_rsp->peer_mac_addr);
629 if (tbl)
630 mwifiex_del_rx_reorder_entry(priv, tbl);
5e6e3a92
BZ
631 }
632
633 return 0;
634}
635
636/*
637 * This function handles BA stream timeout event by preparing and sending
638 * a command to the firmware.
639 */
640void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
641 struct host_cmd_ds_11n_batimeout *event)
642{
643 struct host_cmd_ds_11n_delba delba;
644
645 memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
646 memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
647
648 delba.del_ba_param_set |=
649 cpu_to_le16((u16) event->tid << DELBA_TID_POS);
650 delba.del_ba_param_set |= cpu_to_le16(
651 (u16) event->origninator << DELBA_INITIATOR_POS);
652 delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
600f5d90 653 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba);
5e6e3a92
BZ
654}
655
656/*
657 * This function cleans up the Rx reorder table by deleting all the entries
658 * and re-initializing.
659 */
660void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
661{
662 struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
663 unsigned long flags;
664
665 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
666 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
667 &priv->rx_reorder_tbl_ptr, list) {
668 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
8c00228e 669 mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
5e6e3a92
BZ
670 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
671 }
672 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
673
674 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
92583924 675 mwifiex_reset_11n_rx_seq_num(priv);
5e6e3a92 676}
2db96c3d
AP
677
678/*
679 * This function updates all rx_reorder_tbl's flags.
680 */
681void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags)
682{
683 struct mwifiex_private *priv;
684 struct mwifiex_rx_reorder_tbl *tbl;
685 unsigned long lock_flags;
686 int i;
687
688 for (i = 0; i < adapter->priv_num; i++) {
689 priv = adapter->priv[i];
690 if (!priv)
691 continue;
692 if (list_empty(&priv->rx_reorder_tbl_ptr))
693 continue;
694
695 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags);
696 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list)
697 tbl->flags = flags;
698 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags);
699 }
700
701 return;
702}
This page took 0.348148 seconds and 5 git commands to generate.