2 * Marvell Wireless LAN device driver: 802.11n RX Re-ordering
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
27 #include "11n_rxreorder.h"
29 /* This function will dispatch amsdu packet and forward it to kernel/upper
32 static int mwifiex_11n_dispatch_amsdu_pkt(struct mwifiex_private
*priv
,
35 struct rxpd
*local_rx_pd
= (struct rxpd
*)(skb
->data
);
38 if (le16_to_cpu(local_rx_pd
->rx_pkt_type
) == PKT_TYPE_AMSDU
) {
39 struct sk_buff_head list
;
40 struct sk_buff
*rx_skb
;
42 __skb_queue_head_init(&list
);
44 skb_pull(skb
, le16_to_cpu(local_rx_pd
->rx_pkt_offset
));
45 skb_trim(skb
, le16_to_cpu(local_rx_pd
->rx_pkt_length
));
47 ieee80211_amsdu_to_8023s(skb
, &list
, priv
->curr_addr
,
48 priv
->wdev
.iftype
, 0, false);
50 while (!skb_queue_empty(&list
)) {
51 struct rx_packet_hdr
*rx_hdr
;
53 rx_skb
= __skb_dequeue(&list
);
54 rx_hdr
= (struct rx_packet_hdr
*)rx_skb
->data
;
55 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
56 ntohs(rx_hdr
->eth803_hdr
.h_proto
) == ETH_P_TDLS
) {
57 mwifiex_process_tdls_action_frame(priv
,
62 ret
= mwifiex_recv_packet(priv
, rx_skb
);
64 mwifiex_dbg(priv
->adapter
, ERROR
,
65 "Rx of A-MSDU failed");
73 /* This function will process the rx packet and forward it to kernel/upper
76 static int mwifiex_11n_dispatch_pkt(struct mwifiex_private
*priv
, void *payload
)
78 int ret
= mwifiex_11n_dispatch_amsdu_pkt(priv
, payload
);
83 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
84 return mwifiex_handle_uap_rx_forward(priv
, payload
);
86 return mwifiex_process_rx_packet(priv
, payload
);
90 * This function dispatches all packets in the Rx reorder table until the
93 * There could be holes in the buffer, which are skipped by the function.
94 * Since the buffer is linear, the function uses rotation to simulate
98 mwifiex_11n_dispatch_pkt_until_start_win(struct mwifiex_private
*priv
,
99 struct mwifiex_rx_reorder_tbl
*tbl
,
106 pkt_to_send
= (start_win
> tbl
->start_win
) ?
107 min((start_win
- tbl
->start_win
), tbl
->win_size
) :
110 for (i
= 0; i
< pkt_to_send
; ++i
) {
111 spin_lock_irqsave(&priv
->rx_pkt_lock
, flags
);
113 if (tbl
->rx_reorder_ptr
[i
]) {
114 rx_tmp_ptr
= tbl
->rx_reorder_ptr
[i
];
115 tbl
->rx_reorder_ptr
[i
] = NULL
;
117 spin_unlock_irqrestore(&priv
->rx_pkt_lock
, flags
);
119 mwifiex_11n_dispatch_pkt(priv
, rx_tmp_ptr
);
122 spin_lock_irqsave(&priv
->rx_pkt_lock
, flags
);
124 * We don't have a circular buffer, hence use rotation to simulate
127 for (i
= 0; i
< tbl
->win_size
- pkt_to_send
; ++i
) {
128 tbl
->rx_reorder_ptr
[i
] = tbl
->rx_reorder_ptr
[pkt_to_send
+ i
];
129 tbl
->rx_reorder_ptr
[pkt_to_send
+ i
] = NULL
;
132 tbl
->start_win
= start_win
;
133 spin_unlock_irqrestore(&priv
->rx_pkt_lock
, flags
);
137 * This function dispatches all packets in the Rx reorder table until
140 * The start window is adjusted automatically when a hole is located.
141 * Since the buffer is linear, the function uses rotation to simulate
145 mwifiex_11n_scan_and_dispatch(struct mwifiex_private
*priv
,
146 struct mwifiex_rx_reorder_tbl
*tbl
)
152 for (i
= 0; i
< tbl
->win_size
; ++i
) {
153 spin_lock_irqsave(&priv
->rx_pkt_lock
, flags
);
154 if (!tbl
->rx_reorder_ptr
[i
]) {
155 spin_unlock_irqrestore(&priv
->rx_pkt_lock
, flags
);
158 rx_tmp_ptr
= tbl
->rx_reorder_ptr
[i
];
159 tbl
->rx_reorder_ptr
[i
] = NULL
;
160 spin_unlock_irqrestore(&priv
->rx_pkt_lock
, flags
);
161 mwifiex_11n_dispatch_pkt(priv
, rx_tmp_ptr
);
164 spin_lock_irqsave(&priv
->rx_pkt_lock
, flags
);
166 * We don't have a circular buffer, hence use rotation to simulate
170 xchg
= tbl
->win_size
- i
;
171 for (j
= 0; j
< xchg
; ++j
) {
172 tbl
->rx_reorder_ptr
[j
] = tbl
->rx_reorder_ptr
[i
+ j
];
173 tbl
->rx_reorder_ptr
[i
+ j
] = NULL
;
176 tbl
->start_win
= (tbl
->start_win
+ i
) & (MAX_TID_VALUE
- 1);
177 spin_unlock_irqrestore(&priv
->rx_pkt_lock
, flags
);
181 * This function deletes the Rx reorder table and frees the memory.
183 * The function stops the associated timer and dispatches all the
184 * pending packets in the Rx reorder table before deletion.
187 mwifiex_del_rx_reorder_entry(struct mwifiex_private
*priv
,
188 struct mwifiex_rx_reorder_tbl
*tbl
)
196 spin_lock_irqsave(&priv
->adapter
->rx_proc_lock
, flags
);
197 priv
->adapter
->rx_locked
= true;
198 if (priv
->adapter
->rx_processing
) {
199 spin_unlock_irqrestore(&priv
->adapter
->rx_proc_lock
, flags
);
200 flush_workqueue(priv
->adapter
->rx_workqueue
);
202 spin_unlock_irqrestore(&priv
->adapter
->rx_proc_lock
, flags
);
205 start_win
= (tbl
->start_win
+ tbl
->win_size
) & (MAX_TID_VALUE
- 1);
206 mwifiex_11n_dispatch_pkt_until_start_win(priv
, tbl
, start_win
);
208 del_timer_sync(&tbl
->timer_context
.timer
);
209 tbl
->timer_context
.timer_is_set
= false;
211 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
212 list_del(&tbl
->list
);
213 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
215 kfree(tbl
->rx_reorder_ptr
);
218 spin_lock_irqsave(&priv
->adapter
->rx_proc_lock
, flags
);
219 priv
->adapter
->rx_locked
= false;
220 spin_unlock_irqrestore(&priv
->adapter
->rx_proc_lock
, flags
);
225 * This function returns the pointer to an entry in Rx reordering
226 * table which matches the given TA/TID pair.
228 struct mwifiex_rx_reorder_tbl
*
229 mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private
*priv
, int tid
, u8
*ta
)
231 struct mwifiex_rx_reorder_tbl
*tbl
;
234 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
235 list_for_each_entry(tbl
, &priv
->rx_reorder_tbl_ptr
, list
) {
236 if (!memcmp(tbl
->ta
, ta
, ETH_ALEN
) && tbl
->tid
== tid
) {
237 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
,
242 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
247 /* This function retrieves the pointer to an entry in Rx reordering
248 * table which matches the given TA and deletes it.
250 void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private
*priv
, u8
*ta
)
252 struct mwifiex_rx_reorder_tbl
*tbl
, *tmp
;
258 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
259 list_for_each_entry_safe(tbl
, tmp
, &priv
->rx_reorder_tbl_ptr
, list
) {
260 if (!memcmp(tbl
->ta
, ta
, ETH_ALEN
)) {
261 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
,
263 mwifiex_del_rx_reorder_entry(priv
, tbl
);
264 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
267 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
273 * This function finds the last sequence number used in the packets
274 * buffered in Rx reordering table.
277 mwifiex_11n_find_last_seq_num(struct reorder_tmr_cnxt
*ctx
)
279 struct mwifiex_rx_reorder_tbl
*rx_reorder_tbl_ptr
= ctx
->ptr
;
280 struct mwifiex_private
*priv
= ctx
->priv
;
284 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
285 for (i
= rx_reorder_tbl_ptr
->win_size
- 1; i
>= 0; --i
) {
286 if (rx_reorder_tbl_ptr
->rx_reorder_ptr
[i
]) {
287 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
,
292 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
298 * This function flushes all the packets in Rx reordering table.
300 * The function checks if any packets are currently buffered in the
301 * table or not. In case there are packets available, it dispatches
302 * them and then dumps the Rx reordering table.
305 mwifiex_flush_data(unsigned long context
)
307 struct reorder_tmr_cnxt
*ctx
=
308 (struct reorder_tmr_cnxt
*) context
;
309 int start_win
, seq_num
;
311 ctx
->timer_is_set
= false;
312 seq_num
= mwifiex_11n_find_last_seq_num(ctx
);
317 mwifiex_dbg(ctx
->priv
->adapter
, INFO
, "info: flush data %d\n", seq_num
);
318 start_win
= (ctx
->ptr
->start_win
+ seq_num
+ 1) & (MAX_TID_VALUE
- 1);
319 mwifiex_11n_dispatch_pkt_until_start_win(ctx
->priv
, ctx
->ptr
,
324 * This function creates an entry in Rx reordering table for the
327 * The function also initializes the entry with sequence number, window
328 * size as well as initializes the timer.
330 * If the received TA/TID pair is already present, all the packets are
331 * dispatched and the window size is moved until the SSN.
334 mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private
*priv
, u8
*ta
,
335 int tid
, int win_size
, int seq_num
)
338 struct mwifiex_rx_reorder_tbl
*tbl
, *new_node
;
341 struct mwifiex_sta_node
*node
;
344 * If we get a TID, ta pair which is already present dispatch all the
345 * the packets and move the window size until the ssn
347 tbl
= mwifiex_11n_get_rx_reorder_tbl(priv
, tid
, ta
);
349 mwifiex_11n_dispatch_pkt_until_start_win(priv
, tbl
, seq_num
);
352 /* if !tbl then create one */
353 new_node
= kzalloc(sizeof(struct mwifiex_rx_reorder_tbl
), GFP_KERNEL
);
357 INIT_LIST_HEAD(&new_node
->list
);
359 memcpy(new_node
->ta
, ta
, ETH_ALEN
);
360 new_node
->start_win
= seq_num
;
361 new_node
->init_win
= seq_num
;
364 spin_lock_irqsave(&priv
->sta_list_spinlock
, flags
);
365 if (mwifiex_queuing_ra_based(priv
)) {
366 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
) {
367 node
= mwifiex_get_sta_entry(priv
, ta
);
369 last_seq
= node
->rx_seq
[tid
];
372 node
= mwifiex_get_sta_entry(priv
, ta
);
374 last_seq
= node
->rx_seq
[tid
];
376 last_seq
= priv
->rx_seq
[tid
];
378 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
380 mwifiex_dbg(priv
->adapter
, INFO
,
381 "info: last_seq=%d start_win=%d\n",
382 last_seq
, new_node
->start_win
);
384 if (last_seq
!= MWIFIEX_DEF_11N_RX_SEQ_NUM
&&
385 last_seq
>= new_node
->start_win
) {
386 new_node
->start_win
= last_seq
+ 1;
387 new_node
->flags
|= RXREOR_INIT_WINDOW_SHIFT
;
390 new_node
->win_size
= win_size
;
392 new_node
->rx_reorder_ptr
= kzalloc(sizeof(void *) * win_size
,
394 if (!new_node
->rx_reorder_ptr
) {
395 kfree((u8
*) new_node
);
396 mwifiex_dbg(priv
->adapter
, ERROR
,
397 "%s: failed to alloc reorder_ptr\n", __func__
);
401 new_node
->timer_context
.ptr
= new_node
;
402 new_node
->timer_context
.priv
= priv
;
403 new_node
->timer_context
.timer_is_set
= false;
405 setup_timer(&new_node
->timer_context
.timer
, mwifiex_flush_data
,
406 (unsigned long)&new_node
->timer_context
);
408 for (i
= 0; i
< win_size
; ++i
)
409 new_node
->rx_reorder_ptr
[i
] = NULL
;
411 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
412 list_add_tail(&new_node
->list
, &priv
->rx_reorder_tbl_ptr
);
413 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
417 mwifiex_11n_rxreorder_timer_restart(struct mwifiex_rx_reorder_tbl
*tbl
)
421 if (tbl
->win_size
>= MWIFIEX_BA_WIN_SIZE_32
)
422 min_flush_time
= MIN_FLUSH_TIMER_15_MS
;
424 min_flush_time
= MIN_FLUSH_TIMER_MS
;
426 mod_timer(&tbl
->timer_context
.timer
,
427 jiffies
+ msecs_to_jiffies(min_flush_time
* tbl
->win_size
));
429 tbl
->timer_context
.timer_is_set
= true;
433 * This function prepares command for adding a BA request.
435 * Preparation includes -
436 * - Setting command ID and proper size
437 * - Setting add BA request buffer
438 * - Ensuring correct endian-ness
440 int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command
*cmd
, void *data_buf
)
442 struct host_cmd_ds_11n_addba_req
*add_ba_req
= &cmd
->params
.add_ba_req
;
444 cmd
->command
= cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ
);
445 cmd
->size
= cpu_to_le16(sizeof(*add_ba_req
) + S_DS_GEN
);
446 memcpy(add_ba_req
, data_buf
, sizeof(*add_ba_req
));
452 * This function prepares command for adding a BA response.
454 * Preparation includes -
455 * - Setting command ID and proper size
456 * - Setting add BA response buffer
457 * - Ensuring correct endian-ness
459 int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private
*priv
,
460 struct host_cmd_ds_command
*cmd
,
461 struct host_cmd_ds_11n_addba_req
464 struct host_cmd_ds_11n_addba_rsp
*add_ba_rsp
= &cmd
->params
.add_ba_rsp
;
465 struct mwifiex_sta_node
*sta_ptr
;
466 u32 rx_win_size
= priv
->add_ba_param
.rx_win_size
;
470 uint16_t block_ack_param_set
;
472 if ((GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
) &&
473 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
474 priv
->adapter
->is_hw_11ac_capable
&&
475 memcmp(priv
->cfg_bssid
, cmd_addba_req
->peer_mac_addr
, ETH_ALEN
)) {
476 spin_lock_irqsave(&priv
->sta_list_spinlock
, flags
);
477 sta_ptr
= mwifiex_get_sta_entry(priv
,
478 cmd_addba_req
->peer_mac_addr
);
480 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
481 mwifiex_dbg(priv
->adapter
, ERROR
,
482 "BA setup with unknown TDLS peer %pM!\n",
483 cmd_addba_req
->peer_mac_addr
);
486 if (sta_ptr
->is_11ac_enabled
)
487 rx_win_size
= MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE
;
488 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
491 cmd
->command
= cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP
);
492 cmd
->size
= cpu_to_le16(sizeof(*add_ba_rsp
) + S_DS_GEN
);
494 memcpy(add_ba_rsp
->peer_mac_addr
, cmd_addba_req
->peer_mac_addr
,
496 add_ba_rsp
->dialog_token
= cmd_addba_req
->dialog_token
;
497 add_ba_rsp
->block_ack_tmo
= cmd_addba_req
->block_ack_tmo
;
498 add_ba_rsp
->ssn
= cmd_addba_req
->ssn
;
500 block_ack_param_set
= le16_to_cpu(cmd_addba_req
->block_ack_param_set
);
501 tid
= (block_ack_param_set
& IEEE80211_ADDBA_PARAM_TID_MASK
)
502 >> BLOCKACKPARAM_TID_POS
;
503 add_ba_rsp
->status_code
= cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT
);
504 block_ack_param_set
&= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
;
506 /* If we don't support AMSDU inside AMPDU, reset the bit */
507 if (!priv
->add_ba_param
.rx_amsdu
||
508 (priv
->aggr_prio_tbl
[tid
].amsdu
== BA_STREAM_NOT_ALLOWED
))
509 block_ack_param_set
&= ~BLOCKACKPARAM_AMSDU_SUPP_MASK
;
510 block_ack_param_set
|= rx_win_size
<< BLOCKACKPARAM_WINSIZE_POS
;
511 add_ba_rsp
->block_ack_param_set
= cpu_to_le16(block_ack_param_set
);
512 win_size
= (le16_to_cpu(add_ba_rsp
->block_ack_param_set
)
513 & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
)
514 >> BLOCKACKPARAM_WINSIZE_POS
;
515 cmd_addba_req
->block_ack_param_set
= cpu_to_le16(block_ack_param_set
);
517 mwifiex_11n_create_rx_reorder_tbl(priv
, cmd_addba_req
->peer_mac_addr
,
519 le16_to_cpu(cmd_addba_req
->ssn
));
524 * This function prepares command for deleting a BA request.
526 * Preparation includes -
527 * - Setting command ID and proper size
528 * - Setting del BA request buffer
529 * - Ensuring correct endian-ness
531 int mwifiex_cmd_11n_delba(struct host_cmd_ds_command
*cmd
, void *data_buf
)
533 struct host_cmd_ds_11n_delba
*del_ba
= &cmd
->params
.del_ba
;
535 cmd
->command
= cpu_to_le16(HostCmd_CMD_11N_DELBA
);
536 cmd
->size
= cpu_to_le16(sizeof(*del_ba
) + S_DS_GEN
);
537 memcpy(del_ba
, data_buf
, sizeof(*del_ba
));
543 * This function identifies if Rx reordering is needed for a received packet.
545 * In case reordering is required, the function will do the reordering
546 * before sending it to kernel.
548 * The Rx reorder table is checked first with the received TID/TA pair. If
549 * not found, the received packet is dispatched immediately. But if found,
550 * the packet is reordered and all the packets in the updated Rx reordering
551 * table is dispatched until a hole is found.
553 * For sequence number less than the starting window, the packet is dropped.
555 int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private
*priv
,
556 u16 seq_num
, u16 tid
,
557 u8
*ta
, u8 pkt_type
, void *payload
)
559 struct mwifiex_rx_reorder_tbl
*tbl
;
560 int prev_start_win
, start_win
, end_win
, win_size
;
562 bool init_window_shift
= false;
565 tbl
= mwifiex_11n_get_rx_reorder_tbl(priv
, tid
, ta
);
567 if (pkt_type
!= PKT_TYPE_BAR
)
568 mwifiex_11n_dispatch_pkt(priv
, payload
);
572 if ((pkt_type
== PKT_TYPE_AMSDU
) && !tbl
->amsdu
) {
573 mwifiex_11n_dispatch_pkt(priv
, payload
);
577 start_win
= tbl
->start_win
;
578 prev_start_win
= start_win
;
579 win_size
= tbl
->win_size
;
580 end_win
= ((start_win
+ win_size
) - 1) & (MAX_TID_VALUE
- 1);
581 if (tbl
->flags
& RXREOR_INIT_WINDOW_SHIFT
) {
582 init_window_shift
= true;
583 tbl
->flags
&= ~RXREOR_INIT_WINDOW_SHIFT
;
586 if (tbl
->flags
& RXREOR_FORCE_NO_DROP
) {
587 mwifiex_dbg(priv
->adapter
, INFO
,
588 "RXREOR_FORCE_NO_DROP when HS is activated\n");
589 tbl
->flags
&= ~RXREOR_FORCE_NO_DROP
;
590 } else if (init_window_shift
&& seq_num
< start_win
&&
591 seq_num
>= tbl
->init_win
) {
592 mwifiex_dbg(priv
->adapter
, INFO
,
593 "Sender TID sequence number reset %d->%d for SSN %d\n",
594 start_win
, seq_num
, tbl
->init_win
);
595 tbl
->start_win
= start_win
= seq_num
;
596 end_win
= ((start_win
+ win_size
) - 1) & (MAX_TID_VALUE
- 1);
599 * If seq_num is less then starting win then ignore and drop
602 if ((start_win
+ TWOPOW11
) > (MAX_TID_VALUE
- 1)) {
603 if (seq_num
>= ((start_win
+ TWOPOW11
) &
604 (MAX_TID_VALUE
- 1)) &&
605 seq_num
< start_win
) {
609 } else if ((seq_num
< start_win
) ||
610 (seq_num
>= (start_win
+ TWOPOW11
))) {
617 * If this packet is a BAR we adjust seq_num as
620 if (pkt_type
== PKT_TYPE_BAR
)
621 seq_num
= ((seq_num
+ win_size
) - 1) & (MAX_TID_VALUE
- 1);
623 if (((end_win
< start_win
) &&
624 (seq_num
< start_win
) && (seq_num
> end_win
)) ||
625 ((end_win
> start_win
) && ((seq_num
> end_win
) ||
626 (seq_num
< start_win
)))) {
628 if (((end_win
- win_size
) + 1) >= 0)
629 start_win
= (end_win
- win_size
) + 1;
631 start_win
= (MAX_TID_VALUE
- (win_size
- end_win
)) + 1;
632 mwifiex_11n_dispatch_pkt_until_start_win(priv
, tbl
, start_win
);
635 if (pkt_type
!= PKT_TYPE_BAR
) {
636 if (seq_num
>= start_win
)
637 pkt_index
= seq_num
- start_win
;
639 pkt_index
= (seq_num
+MAX_TID_VALUE
) - start_win
;
641 if (tbl
->rx_reorder_ptr
[pkt_index
]) {
646 tbl
->rx_reorder_ptr
[pkt_index
] = payload
;
650 * Dispatch all packets sequentially from start_win until a
651 * hole is found and adjust the start_win appropriately
653 mwifiex_11n_scan_and_dispatch(priv
, tbl
);
656 if (!tbl
->timer_context
.timer_is_set
||
657 prev_start_win
!= tbl
->start_win
)
658 mwifiex_11n_rxreorder_timer_restart(tbl
);
663 * This function deletes an entry for a given TID/TA pair.
665 * The TID/TA are taken from del BA event body.
668 mwifiex_del_ba_tbl(struct mwifiex_private
*priv
, int tid
, u8
*peer_mac
,
669 u8 type
, int initiator
)
671 struct mwifiex_rx_reorder_tbl
*tbl
;
672 struct mwifiex_tx_ba_stream_tbl
*ptx_tbl
;
673 struct mwifiex_ra_list_tbl
*ra_list
;
674 u8 cleanup_rx_reorder_tbl
;
678 if (type
== TYPE_DELBA_RECEIVE
)
679 cleanup_rx_reorder_tbl
= (initiator
) ? true : false;
681 cleanup_rx_reorder_tbl
= (initiator
) ? false : true;
683 mwifiex_dbg(priv
->adapter
, EVENT
, "event: DELBA: %pM tid=%d initiator=%d\n",
684 peer_mac
, tid
, initiator
);
686 if (cleanup_rx_reorder_tbl
) {
687 tbl
= mwifiex_11n_get_rx_reorder_tbl(priv
, tid
,
690 mwifiex_dbg(priv
->adapter
, EVENT
,
691 "event: TID, TA not found in table\n");
694 mwifiex_del_rx_reorder_entry(priv
, tbl
);
696 ptx_tbl
= mwifiex_get_ba_tbl(priv
, tid
, peer_mac
);
698 mwifiex_dbg(priv
->adapter
, EVENT
,
699 "event: TID, RA not found in table\n");
703 tid_down
= mwifiex_wmm_downgrade_tid(priv
, tid
);
704 ra_list
= mwifiex_wmm_get_ralist_node(priv
, tid_down
, peer_mac
);
706 ra_list
->amsdu_in_ampdu
= false;
707 ra_list
->ba_status
= BA_SETUP_NONE
;
709 spin_lock_irqsave(&priv
->tx_ba_stream_tbl_lock
, flags
);
710 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv
, ptx_tbl
);
711 spin_unlock_irqrestore(&priv
->tx_ba_stream_tbl_lock
, flags
);
716 * This function handles the command response of an add BA response.
718 * Handling includes changing the header fields into CPU format and
719 * creating the stream, provided the add BA is accepted.
721 int mwifiex_ret_11n_addba_resp(struct mwifiex_private
*priv
,
722 struct host_cmd_ds_command
*resp
)
724 struct host_cmd_ds_11n_addba_rsp
*add_ba_rsp
= &resp
->params
.add_ba_rsp
;
726 struct mwifiex_rx_reorder_tbl
*tbl
;
727 uint16_t block_ack_param_set
;
729 block_ack_param_set
= le16_to_cpu(add_ba_rsp
->block_ack_param_set
);
731 tid
= (block_ack_param_set
& IEEE80211_ADDBA_PARAM_TID_MASK
)
732 >> BLOCKACKPARAM_TID_POS
;
734 * Check if we had rejected the ADDBA, if yes then do not create
737 if (le16_to_cpu(add_ba_rsp
->status_code
) != BA_RESULT_SUCCESS
) {
738 mwifiex_dbg(priv
->adapter
, ERROR
, "ADDBA RSP: failed %pM tid=%d)\n",
739 add_ba_rsp
->peer_mac_addr
, tid
);
741 tbl
= mwifiex_11n_get_rx_reorder_tbl(priv
, tid
,
742 add_ba_rsp
->peer_mac_addr
);
744 mwifiex_del_rx_reorder_entry(priv
, tbl
);
749 win_size
= (block_ack_param_set
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
)
750 >> BLOCKACKPARAM_WINSIZE_POS
;
752 tbl
= mwifiex_11n_get_rx_reorder_tbl(priv
, tid
,
753 add_ba_rsp
->peer_mac_addr
);
755 if ((block_ack_param_set
& BLOCKACKPARAM_AMSDU_SUPP_MASK
) &&
756 priv
->add_ba_param
.rx_amsdu
&&
757 (priv
->aggr_prio_tbl
[tid
].amsdu
!= BA_STREAM_NOT_ALLOWED
))
763 mwifiex_dbg(priv
->adapter
, CMD
,
764 "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
765 add_ba_rsp
->peer_mac_addr
, tid
, add_ba_rsp
->ssn
, win_size
);
771 * This function handles BA stream timeout event by preparing and sending
772 * a command to the firmware.
774 void mwifiex_11n_ba_stream_timeout(struct mwifiex_private
*priv
,
775 struct host_cmd_ds_11n_batimeout
*event
)
777 struct host_cmd_ds_11n_delba delba
;
779 memset(&delba
, 0, sizeof(struct host_cmd_ds_11n_delba
));
780 memcpy(delba
.peer_mac_addr
, event
->peer_mac_addr
, ETH_ALEN
);
782 delba
.del_ba_param_set
|=
783 cpu_to_le16((u16
) event
->tid
<< DELBA_TID_POS
);
784 delba
.del_ba_param_set
|= cpu_to_le16(
785 (u16
) event
->origninator
<< DELBA_INITIATOR_POS
);
786 delba
.reason_code
= cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT
);
787 mwifiex_send_cmd(priv
, HostCmd_CMD_11N_DELBA
, 0, 0, &delba
, false);
791 * This function cleans up the Rx reorder table by deleting all the entries
792 * and re-initializing.
794 void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private
*priv
)
796 struct mwifiex_rx_reorder_tbl
*del_tbl_ptr
, *tmp_node
;
799 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
800 list_for_each_entry_safe(del_tbl_ptr
, tmp_node
,
801 &priv
->rx_reorder_tbl_ptr
, list
) {
802 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
803 mwifiex_del_rx_reorder_entry(priv
, del_tbl_ptr
);
804 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, flags
);
806 INIT_LIST_HEAD(&priv
->rx_reorder_tbl_ptr
);
807 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, flags
);
809 mwifiex_reset_11n_rx_seq_num(priv
);
813 * This function updates all rx_reorder_tbl's flags.
815 void mwifiex_update_rxreor_flags(struct mwifiex_adapter
*adapter
, u8 flags
)
817 struct mwifiex_private
*priv
;
818 struct mwifiex_rx_reorder_tbl
*tbl
;
819 unsigned long lock_flags
;
822 for (i
= 0; i
< adapter
->priv_num
; i
++) {
823 priv
= adapter
->priv
[i
];
827 spin_lock_irqsave(&priv
->rx_reorder_tbl_lock
, lock_flags
);
828 if (list_empty(&priv
->rx_reorder_tbl_ptr
)) {
829 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
,
834 list_for_each_entry(tbl
, &priv
->rx_reorder_tbl_ptr
, list
)
836 spin_unlock_irqrestore(&priv
->rx_reorder_tbl_lock
, lock_flags
);
842 /* This function update all the rx_win_size based on coex flag
844 static void mwifiex_update_ampdu_rxwinsize(struct mwifiex_adapter
*adapter
,
849 struct mwifiex_private
*priv
;
851 dev_dbg(adapter
->dev
, "Update rxwinsize %d\n", coex_flag
);
853 for (i
= 0; i
< adapter
->priv_num
; i
++) {
854 if (!adapter
->priv
[i
])
856 priv
= adapter
->priv
[i
];
857 rx_win_size
= priv
->add_ba_param
.rx_win_size
;
859 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
)
860 priv
->add_ba_param
.rx_win_size
=
861 MWIFIEX_STA_COEX_AMPDU_DEF_RXWINSIZE
;
862 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_P2P
)
863 priv
->add_ba_param
.rx_win_size
=
864 MWIFIEX_STA_COEX_AMPDU_DEF_RXWINSIZE
;
865 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_UAP
)
866 priv
->add_ba_param
.rx_win_size
=
867 MWIFIEX_UAP_COEX_AMPDU_DEF_RXWINSIZE
;
869 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
)
870 priv
->add_ba_param
.rx_win_size
=
871 MWIFIEX_STA_AMPDU_DEF_RXWINSIZE
;
872 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_P2P
)
873 priv
->add_ba_param
.rx_win_size
=
874 MWIFIEX_STA_AMPDU_DEF_RXWINSIZE
;
875 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_UAP
)
876 priv
->add_ba_param
.rx_win_size
=
877 MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE
;
880 if (adapter
->coex_win_size
&& adapter
->coex_rx_win_size
)
881 priv
->add_ba_param
.rx_win_size
=
882 adapter
->coex_rx_win_size
;
884 if (rx_win_size
!= priv
->add_ba_param
.rx_win_size
) {
885 if (!priv
->media_connected
)
887 for (i
= 0; i
< MAX_NUM_TID
; i
++)
888 mwifiex_11n_delba(priv
, i
);
893 /* This function check coex for RX BA
895 void mwifiex_coex_ampdu_rxwinsize(struct mwifiex_adapter
*adapter
)
898 struct mwifiex_private
*priv
;
901 for (i
= 0; i
< adapter
->priv_num
; i
++) {
902 if (adapter
->priv
[i
]) {
903 priv
= adapter
->priv
[i
];
904 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
) {
905 if (priv
->media_connected
)
908 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
909 if (priv
->bss_started
)
913 if (count
>= MWIFIEX_BSS_COEX_COUNT
)
916 if (count
>= MWIFIEX_BSS_COEX_COUNT
)
917 mwifiex_update_ampdu_rxwinsize(adapter
, true);
919 mwifiex_update_ampdu_rxwinsize(adapter
, false);