1 // SPDX-License-Identifier: GPL-2.0-only
3 * NXP Wireless LAN device driver: 802.11n RX Re-ordering
5 * Copyright 2011-2020 NXP
15 #include "11n_rxreorder.h"
17 /* This function will dispatch amsdu packet and forward it to kernel/upper
20 static int mwifiex_11n_dispatch_amsdu_pkt(struct mwifiex_private *priv,
23 struct rxpd *local_rx_pd = (struct rxpd *)(skb->data);
26 if (le16_to_cpu(local_rx_pd->rx_pkt_type) == PKT_TYPE_AMSDU) {
27 struct sk_buff_head list;
28 struct sk_buff *rx_skb;
30 __skb_queue_head_init(&list);
32 skb_pull(skb, le16_to_cpu(local_rx_pd->rx_pkt_offset));
33 skb_trim(skb, le16_to_cpu(local_rx_pd->rx_pkt_length));
35 ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr,
36 priv->wdev.iftype, 0, NULL, NULL, false);
38 while (!skb_queue_empty(&list)) {
39 struct rx_packet_hdr *rx_hdr;
41 rx_skb = __skb_dequeue(&list);
42 rx_hdr = (struct rx_packet_hdr *)rx_skb->data;
43 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
44 ntohs(rx_hdr->eth803_hdr.h_proto) == ETH_P_TDLS) {
45 mwifiex_process_tdls_action_frame(priv,
50 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
51 ret = mwifiex_uap_recv_packet(priv, rx_skb);
53 ret = mwifiex_recv_packet(priv, rx_skb);
55 mwifiex_dbg(priv->adapter, ERROR,
56 "Rx of A-MSDU failed");
64 /* This function will process the rx packet and forward it to kernel/upper
67 static int mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv,
68 struct sk_buff *payload)
74 mwifiex_dbg(priv->adapter, INFO, "info: fw drop data\n");
78 ret = mwifiex_11n_dispatch_amsdu_pkt(priv, payload);
82 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
83 return mwifiex_handle_uap_rx_forward(priv, payload);
85 return mwifiex_process_rx_packet(priv, payload);
89 * This function dispatches all packets in the Rx reorder table until the
92 * There could be holes in the buffer, which are skipped by the function.
93 * Since the buffer is linear, the function uses rotation to simulate
97 mwifiex_11n_dispatch_pkt_until_start_win(struct mwifiex_private *priv,
98 struct mwifiex_rx_reorder_tbl *tbl,
101 struct sk_buff_head list;
105 __skb_queue_head_init(&list);
106 spin_lock_bh(&priv->rx_reorder_tbl_lock);
108 pkt_to_send = (start_win > tbl->start_win) ?
109 min((start_win - tbl->start_win), tbl->win_size) :
112 for (i = 0; i < pkt_to_send; ++i) {
113 if (tbl->rx_reorder_ptr[i]) {
114 skb = tbl->rx_reorder_ptr[i];
115 __skb_queue_tail(&list, skb);
116 tbl->rx_reorder_ptr[i] = NULL;
121 * We don't have a circular buffer, hence use rotation to simulate
124 for (i = 0; i < tbl->win_size - pkt_to_send; ++i) {
125 tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i];
126 tbl->rx_reorder_ptr[pkt_to_send + i] = NULL;
129 tbl->start_win = start_win;
130 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
132 while ((skb = __skb_dequeue(&list)))
133 mwifiex_11n_dispatch_pkt(priv, skb);
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)
148 struct sk_buff_head list;
152 __skb_queue_head_init(&list);
153 spin_lock_bh(&priv->rx_reorder_tbl_lock);
155 for (i = 0; i < tbl->win_size; ++i) {
156 if (!tbl->rx_reorder_ptr[i])
158 skb = tbl->rx_reorder_ptr[i];
159 __skb_queue_tail(&list, skb);
160 tbl->rx_reorder_ptr[i] = NULL;
164 * We don't have a circular buffer, hence use rotation to simulate
168 xchg = tbl->win_size - i;
169 for (j = 0; j < xchg; ++j) {
170 tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j];
171 tbl->rx_reorder_ptr[i + j] = NULL;
174 tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1);
176 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
178 while ((skb = __skb_dequeue(&list)))
179 mwifiex_11n_dispatch_pkt(priv, skb);
183 * This function deletes the Rx reorder table and frees the memory.
185 * The function stops the associated timer and dispatches all the
186 * pending packets in the Rx reorder table before deletion.
189 mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv,
190 struct mwifiex_rx_reorder_tbl *tbl)
197 spin_lock_bh(&priv->adapter->rx_proc_lock);
198 priv->adapter->rx_locked = true;
199 if (priv->adapter->rx_processing) {
200 spin_unlock_bh(&priv->adapter->rx_proc_lock);
201 flush_workqueue(priv->adapter->rx_workqueue);
203 spin_unlock_bh(&priv->adapter->rx_proc_lock);
206 start_win = (tbl->start_win + tbl->win_size) & (MAX_TID_VALUE - 1);
207 mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win);
209 del_timer_sync(&tbl->timer_context.timer);
210 tbl->timer_context.timer_is_set = false;
212 spin_lock_bh(&priv->rx_reorder_tbl_lock);
213 list_del(&tbl->list);
214 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
216 kfree(tbl->rx_reorder_ptr);
219 spin_lock_bh(&priv->adapter->rx_proc_lock);
220 priv->adapter->rx_locked = false;
221 spin_unlock_bh(&priv->adapter->rx_proc_lock);
226 * This function returns the pointer to an entry in Rx reordering
227 * table which matches the given TA/TID pair.
229 struct mwifiex_rx_reorder_tbl *
230 mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
232 struct mwifiex_rx_reorder_tbl *tbl;
234 spin_lock_bh(&priv->rx_reorder_tbl_lock);
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_bh(&priv->rx_reorder_tbl_lock);
241 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
246 /* This function retrieves the pointer to an entry in Rx reordering
247 * table which matches the given TA and deletes it.
249 void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta)
251 struct mwifiex_rx_reorder_tbl *tbl, *tmp;
256 spin_lock_bh(&priv->rx_reorder_tbl_lock);
257 list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) {
258 if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
259 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
260 mwifiex_del_rx_reorder_entry(priv, tbl);
261 spin_lock_bh(&priv->rx_reorder_tbl_lock);
264 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
270 * This function finds the last sequence number used in the packets
271 * buffered in Rx reordering table.
274 mwifiex_11n_find_last_seq_num(struct reorder_tmr_cnxt *ctx)
276 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr = ctx->ptr;
277 struct mwifiex_private *priv = ctx->priv;
280 spin_lock_bh(&priv->rx_reorder_tbl_lock);
281 for (i = rx_reorder_tbl_ptr->win_size - 1; i >= 0; --i) {
282 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i]) {
283 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
287 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
293 * This function flushes all the packets in Rx reordering table.
295 * The function checks if any packets are currently buffered in the
296 * table or not. In case there are packets available, it dispatches
297 * them and then dumps the Rx reordering table.
300 mwifiex_flush_data(struct timer_list *t)
302 struct reorder_tmr_cnxt *ctx =
303 from_timer(ctx, t, timer);
304 int start_win, seq_num;
306 ctx->timer_is_set = false;
307 seq_num = mwifiex_11n_find_last_seq_num(ctx);
312 mwifiex_dbg(ctx->priv->adapter, INFO, "info: flush data %d\n", seq_num);
313 start_win = (ctx->ptr->start_win + seq_num + 1) & (MAX_TID_VALUE - 1);
314 mwifiex_11n_dispatch_pkt_until_start_win(ctx->priv, ctx->ptr,
319 * This function creates an entry in Rx reordering table for the
322 * The function also initializes the entry with sequence number, window
323 * size as well as initializes the timer.
325 * If the received TA/TID pair is already present, all the packets are
326 * dispatched and the window size is moved until the SSN.
329 mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
330 int tid, int win_size, int seq_num)
333 struct mwifiex_rx_reorder_tbl *tbl, *new_node;
335 struct mwifiex_sta_node *node;
338 * If we get a TID, ta pair which is already present dispatch all
339 * the packets and move the window size until the ssn
341 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
343 mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, seq_num);
346 /* if !tbl then create one */
347 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
351 INIT_LIST_HEAD(&new_node->list);
353 memcpy(new_node->ta, ta, ETH_ALEN);
354 new_node->start_win = seq_num;
355 new_node->init_win = seq_num;
358 spin_lock_bh(&priv->sta_list_spinlock);
359 if (mwifiex_queuing_ra_based(priv)) {
360 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
361 node = mwifiex_get_sta_entry(priv, ta);
363 last_seq = node->rx_seq[tid];
366 node = mwifiex_get_sta_entry(priv, ta);
368 last_seq = node->rx_seq[tid];
370 last_seq = priv->rx_seq[tid];
372 spin_unlock_bh(&priv->sta_list_spinlock);
374 mwifiex_dbg(priv->adapter, INFO,
375 "info: last_seq=%d start_win=%d\n",
376 last_seq, new_node->start_win);
378 if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
379 last_seq >= new_node->start_win) {
380 new_node->start_win = last_seq + 1;
381 new_node->flags |= RXREOR_INIT_WINDOW_SHIFT;
384 new_node->win_size = win_size;
386 new_node->rx_reorder_ptr = kcalloc(win_size, sizeof(void *),
388 if (!new_node->rx_reorder_ptr) {
390 mwifiex_dbg(priv->adapter, ERROR,
391 "%s: failed to alloc reorder_ptr\n", __func__);
395 new_node->timer_context.ptr = new_node;
396 new_node->timer_context.priv = priv;
397 new_node->timer_context.timer_is_set = false;
399 timer_setup(&new_node->timer_context.timer, mwifiex_flush_data, 0);
401 for (i = 0; i < win_size; ++i)
402 new_node->rx_reorder_ptr[i] = NULL;
404 spin_lock_bh(&priv->rx_reorder_tbl_lock);
405 list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
406 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
410 mwifiex_11n_rxreorder_timer_restart(struct mwifiex_rx_reorder_tbl *tbl)
414 if (tbl->win_size >= MWIFIEX_BA_WIN_SIZE_32)
415 min_flush_time = MIN_FLUSH_TIMER_15_MS;
417 min_flush_time = MIN_FLUSH_TIMER_MS;
419 mod_timer(&tbl->timer_context.timer,
420 jiffies + msecs_to_jiffies(min_flush_time * tbl->win_size));
422 tbl->timer_context.timer_is_set = true;
426 * This function prepares command for adding a BA request.
428 * Preparation includes -
429 * - Setting command ID and proper size
430 * - Setting add BA request buffer
431 * - Ensuring correct endian-ness
433 int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
435 struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req;
437 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
438 cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
439 memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
445 * This function prepares command for adding a BA response.
447 * Preparation includes -
448 * - Setting command ID and proper size
449 * - Setting add BA response buffer
450 * - Ensuring correct endian-ness
452 int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
453 struct host_cmd_ds_command *cmd,
454 struct host_cmd_ds_11n_addba_req
457 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp;
458 struct mwifiex_sta_node *sta_ptr;
459 u32 rx_win_size = priv->add_ba_param.rx_win_size;
462 uint16_t block_ack_param_set;
464 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
465 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
466 priv->adapter->is_hw_11ac_capable &&
467 memcmp(priv->cfg_bssid, cmd_addba_req->peer_mac_addr, ETH_ALEN)) {
468 spin_lock_bh(&priv->sta_list_spinlock);
469 sta_ptr = mwifiex_get_sta_entry(priv,
470 cmd_addba_req->peer_mac_addr);
472 spin_unlock_bh(&priv->sta_list_spinlock);
473 mwifiex_dbg(priv->adapter, ERROR,
474 "BA setup with unknown TDLS peer %pM!\n",
475 cmd_addba_req->peer_mac_addr);
478 if (sta_ptr->is_11ac_enabled)
479 rx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
480 spin_unlock_bh(&priv->sta_list_spinlock);
483 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
484 cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
486 memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
488 add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
489 add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
490 add_ba_rsp->ssn = cmd_addba_req->ssn;
492 block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
493 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
494 >> BLOCKACKPARAM_TID_POS;
495 add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
496 block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
498 /* If we don't support AMSDU inside AMPDU, reset the bit */
499 if (!priv->add_ba_param.rx_amsdu ||
500 (priv->aggr_prio_tbl[tid].amsdu == BA_STREAM_NOT_ALLOWED))
501 block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
502 block_ack_param_set |= rx_win_size << BLOCKACKPARAM_WINSIZE_POS;
503 add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
504 win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
505 & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
506 >> BLOCKACKPARAM_WINSIZE_POS;
507 cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
509 mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
511 le16_to_cpu(cmd_addba_req->ssn));
516 * This function prepares command for deleting a BA request.
518 * Preparation includes -
519 * - Setting command ID and proper size
520 * - Setting del BA request buffer
521 * - Ensuring correct endian-ness
523 int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
525 struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba;
527 cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
528 cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
529 memcpy(del_ba, data_buf, sizeof(*del_ba));
535 * This function identifies if Rx reordering is needed for a received packet.
537 * In case reordering is required, the function will do the reordering
538 * before sending it to kernel.
540 * The Rx reorder table is checked first with the received TID/TA pair. If
541 * not found, the received packet is dispatched immediately. But if found,
542 * the packet is reordered and all the packets in the updated Rx reordering
543 * table is dispatched until a hole is found.
545 * For sequence number less than the starting window, the packet is dropped.
547 int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
548 u16 seq_num, u16 tid,
549 u8 *ta, u8 pkt_type, void *payload)
551 struct mwifiex_rx_reorder_tbl *tbl;
552 int prev_start_win, start_win, end_win, win_size;
554 bool init_window_shift = false;
557 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
559 if (pkt_type != PKT_TYPE_BAR)
560 mwifiex_11n_dispatch_pkt(priv, payload);
564 if ((pkt_type == PKT_TYPE_AMSDU) && !tbl->amsdu) {
565 mwifiex_11n_dispatch_pkt(priv, payload);
569 start_win = tbl->start_win;
570 prev_start_win = start_win;
571 win_size = tbl->win_size;
572 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
573 if (tbl->flags & RXREOR_INIT_WINDOW_SHIFT) {
574 init_window_shift = true;
575 tbl->flags &= ~RXREOR_INIT_WINDOW_SHIFT;
578 if (tbl->flags & RXREOR_FORCE_NO_DROP) {
579 mwifiex_dbg(priv->adapter, INFO,
580 "RXREOR_FORCE_NO_DROP when HS is activated\n");
581 tbl->flags &= ~RXREOR_FORCE_NO_DROP;
582 } else if (init_window_shift && seq_num < start_win &&
583 seq_num >= tbl->init_win) {
584 mwifiex_dbg(priv->adapter, INFO,
585 "Sender TID sequence number reset %d->%d for SSN %d\n",
586 start_win, seq_num, tbl->init_win);
587 tbl->start_win = start_win = seq_num;
588 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
591 * If seq_num is less then starting win then ignore and drop
594 if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {
595 if (seq_num >= ((start_win + TWOPOW11) &
596 (MAX_TID_VALUE - 1)) &&
597 seq_num < start_win) {
601 } else if ((seq_num < start_win) ||
602 (seq_num >= (start_win + TWOPOW11))) {
609 * If this packet is a BAR we adjust seq_num as
612 if (pkt_type == PKT_TYPE_BAR)
613 seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
615 if (((end_win < start_win) &&
616 (seq_num < start_win) && (seq_num > end_win)) ||
617 ((end_win > start_win) && ((seq_num > end_win) ||
618 (seq_num < start_win)))) {
620 if (((end_win - win_size) + 1) >= 0)
621 start_win = (end_win - win_size) + 1;
623 start_win = (MAX_TID_VALUE - (win_size - end_win)) + 1;
624 mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win);
627 if (pkt_type != PKT_TYPE_BAR) {
628 if (seq_num >= start_win)
629 pkt_index = seq_num - start_win;
631 pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
633 if (tbl->rx_reorder_ptr[pkt_index]) {
638 tbl->rx_reorder_ptr[pkt_index] = payload;
642 * Dispatch all packets sequentially from start_win until a
643 * hole is found and adjust the start_win appropriately
645 mwifiex_11n_scan_and_dispatch(priv, tbl);
648 if (!tbl->timer_context.timer_is_set ||
649 prev_start_win != tbl->start_win)
650 mwifiex_11n_rxreorder_timer_restart(tbl);
655 * This function deletes an entry for a given TID/TA pair.
657 * The TID/TA are taken from del BA event body.
660 mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
661 u8 type, int initiator)
663 struct mwifiex_rx_reorder_tbl *tbl;
664 struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
665 struct mwifiex_ra_list_tbl *ra_list;
666 u8 cleanup_rx_reorder_tbl;
669 if (type == TYPE_DELBA_RECEIVE)
670 cleanup_rx_reorder_tbl = (initiator) ? true : false;
672 cleanup_rx_reorder_tbl = (initiator) ? false : true;
674 mwifiex_dbg(priv->adapter, EVENT, "event: DELBA: %pM tid=%d initiator=%d\n",
675 peer_mac, tid, initiator);
677 if (cleanup_rx_reorder_tbl) {
678 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
681 mwifiex_dbg(priv->adapter, EVENT,
682 "event: TID, TA not found in table\n");
685 mwifiex_del_rx_reorder_entry(priv, tbl);
687 ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
689 mwifiex_dbg(priv->adapter, EVENT,
690 "event: TID, RA not found in table\n");
694 tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
695 ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, peer_mac);
697 ra_list->amsdu_in_ampdu = false;
698 ra_list->ba_status = BA_SETUP_NONE;
700 spin_lock_bh(&priv->tx_ba_stream_tbl_lock);
701 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
702 spin_unlock_bh(&priv->tx_ba_stream_tbl_lock);
707 * This function handles the command response of an add BA response.
709 * Handling includes changing the header fields into CPU format and
710 * creating the stream, provided the add BA is accepted.
712 int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
713 struct host_cmd_ds_command *resp)
715 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
717 struct mwifiex_rx_reorder_tbl *tbl;
718 uint16_t block_ack_param_set;
720 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
722 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
723 >> BLOCKACKPARAM_TID_POS;
725 * Check if we had rejected the ADDBA, if yes then do not create
728 if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) {
729 mwifiex_dbg(priv->adapter, ERROR, "ADDBA RSP: failed %pM tid=%d)\n",
730 add_ba_rsp->peer_mac_addr, tid);
732 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
733 add_ba_rsp->peer_mac_addr);
735 mwifiex_del_rx_reorder_entry(priv, tbl);
740 win_size = (block_ack_param_set & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
741 >> BLOCKACKPARAM_WINSIZE_POS;
743 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
744 add_ba_rsp->peer_mac_addr);
746 if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) &&
747 priv->add_ba_param.rx_amsdu &&
748 (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED))
754 mwifiex_dbg(priv->adapter, CMD,
755 "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
756 add_ba_rsp->peer_mac_addr, tid, add_ba_rsp->ssn, win_size);
762 * This function handles BA stream timeout event by preparing and sending
763 * a command to the firmware.
765 void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
766 struct host_cmd_ds_11n_batimeout *event)
768 struct host_cmd_ds_11n_delba delba;
770 memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
771 memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
773 delba.del_ba_param_set |=
774 cpu_to_le16((u16) event->tid << DELBA_TID_POS);
775 delba.del_ba_param_set |= cpu_to_le16(
776 (u16) event->origninator << DELBA_INITIATOR_POS);
777 delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
778 mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba, false);
782 * This function cleans up the Rx reorder table by deleting all the entries
783 * and re-initializing.
785 void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
787 struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
789 spin_lock_bh(&priv->rx_reorder_tbl_lock);
790 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
791 &priv->rx_reorder_tbl_ptr, list) {
792 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
793 mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
794 spin_lock_bh(&priv->rx_reorder_tbl_lock);
796 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
797 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
799 mwifiex_reset_11n_rx_seq_num(priv);
803 * This function updates all rx_reorder_tbl's flags.
805 void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags)
807 struct mwifiex_private *priv;
808 struct mwifiex_rx_reorder_tbl *tbl;
811 for (i = 0; i < adapter->priv_num; i++) {
812 priv = adapter->priv[i];
816 spin_lock_bh(&priv->rx_reorder_tbl_lock);
817 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list)
819 spin_unlock_bh(&priv->rx_reorder_tbl_lock);
825 /* This function update all the rx_win_size based on coex flag
827 static void mwifiex_update_ampdu_rxwinsize(struct mwifiex_adapter *adapter,
832 struct mwifiex_private *priv;
834 dev_dbg(adapter->dev, "Update rxwinsize %d\n", coex_flag);
836 for (i = 0; i < adapter->priv_num; i++) {
837 if (!adapter->priv[i])
839 priv = adapter->priv[i];
840 rx_win_size = priv->add_ba_param.rx_win_size;
842 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA)
843 priv->add_ba_param.rx_win_size =
844 MWIFIEX_STA_COEX_AMPDU_DEF_RXWINSIZE;
845 if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P)
846 priv->add_ba_param.rx_win_size =
847 MWIFIEX_STA_COEX_AMPDU_DEF_RXWINSIZE;
848 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP)
849 priv->add_ba_param.rx_win_size =
850 MWIFIEX_UAP_COEX_AMPDU_DEF_RXWINSIZE;
852 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA)
853 priv->add_ba_param.rx_win_size =
854 MWIFIEX_STA_AMPDU_DEF_RXWINSIZE;
855 if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P)
856 priv->add_ba_param.rx_win_size =
857 MWIFIEX_STA_AMPDU_DEF_RXWINSIZE;
858 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP)
859 priv->add_ba_param.rx_win_size =
860 MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE;
863 if (adapter->coex_win_size && adapter->coex_rx_win_size)
864 priv->add_ba_param.rx_win_size =
865 adapter->coex_rx_win_size;
867 if (rx_win_size != priv->add_ba_param.rx_win_size) {
868 if (!priv->media_connected)
870 for (i = 0; i < MAX_NUM_TID; i++)
871 mwifiex_11n_delba(priv, i);
876 /* This function check coex for RX BA
878 void mwifiex_coex_ampdu_rxwinsize(struct mwifiex_adapter *adapter)
881 struct mwifiex_private *priv;
884 for (i = 0; i < adapter->priv_num; i++) {
885 if (adapter->priv[i]) {
886 priv = adapter->priv[i];
887 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
888 if (priv->media_connected)
891 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
892 if (priv->bss_started)
896 if (count >= MWIFIEX_BSS_COEX_COUNT)
899 if (count >= MWIFIEX_BSS_COEX_COUNT)
900 mwifiex_update_ampdu_rxwinsize(adapter, true);
902 mwifiex_update_ampdu_rxwinsize(adapter, false);
905 /* This function handles rxba_sync event
907 void mwifiex_11n_rxba_sync_event(struct mwifiex_private *priv,
908 u8 *event_buf, u16 len)
910 struct mwifiex_ie_types_rxba_sync *tlv_rxba = (void *)event_buf;
911 u16 tlv_type, tlv_len;
912 struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
914 u16 seq_num, tlv_seq_num, tlv_bitmap_len;
915 int tlv_buf_left = len;
919 mwifiex_dbg_dump(priv->adapter, EVT_D, "RXBA_SYNC event:",
921 while (tlv_buf_left >= sizeof(*tlv_rxba)) {
922 tlv_type = le16_to_cpu(tlv_rxba->header.type);
923 tlv_len = le16_to_cpu(tlv_rxba->header.len);
924 if (tlv_type != TLV_TYPE_RXBA_SYNC) {
925 mwifiex_dbg(priv->adapter, ERROR,
926 "Wrong TLV id=0x%x\n", tlv_type);
930 tlv_seq_num = le16_to_cpu(tlv_rxba->seq_num);
931 tlv_bitmap_len = le16_to_cpu(tlv_rxba->bitmap_len);
932 mwifiex_dbg(priv->adapter, INFO,
933 "%pM tid=%d seq_num=%d bitmap_len=%d\n",
934 tlv_rxba->mac, tlv_rxba->tid, tlv_seq_num,
938 mwifiex_11n_get_rx_reorder_tbl(priv, tlv_rxba->tid,
940 if (!rx_reor_tbl_ptr) {
941 mwifiex_dbg(priv->adapter, ERROR,
942 "Can not find rx_reorder_tbl!");
946 for (i = 0; i < tlv_bitmap_len; i++) {
947 for (j = 0 ; j < 8; j++) {
948 if (tlv_rxba->bitmap[i] & (1 << j)) {
949 seq_num = (MAX_TID_VALUE - 1) &
950 (tlv_seq_num + i * 8 + j);
952 mwifiex_dbg(priv->adapter, ERROR,
953 "drop packet,seq=%d\n",
956 ret = mwifiex_11n_rx_reorder_pkt
957 (priv, seq_num, tlv_rxba->tid,
958 tlv_rxba->mac, 0, NULL);
961 mwifiex_dbg(priv->adapter,
963 "Fail to drop packet");
968 tlv_buf_left -= (sizeof(*tlv_rxba) + tlv_len);
969 tmp = (u8 *)tlv_rxba + tlv_len + sizeof(*tlv_rxba);
970 tlv_rxba = (struct mwifiex_ie_types_rxba_sync *)tmp;