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