WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / wireless / marvell / mwifiex / wmm.c
blob0b375608df7db2285697193e355cf906dc81653e
1 /*
2 * NXP Wireless LAN device driver: WMM
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * 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.
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"
29 /* Maximum value FW can accept for driver delay in packet transmission */
30 #define DRV_PKT_DELAY_TO_FW_MAX 512
33 #define WMM_QUEUED_PACKET_LOWER_LIMIT 180
35 #define WMM_QUEUED_PACKET_UPPER_LIMIT 200
37 /* Offset for TOS field in the IP header */
38 #define IPTOS_OFFSET 5
40 static bool disable_tx_amsdu;
41 module_param(disable_tx_amsdu, bool, 0644);
43 /* This table inverses the tos_to_tid operation to get a priority
44 * which is in sequential order, and can be compared.
45 * Use this to compare the priority of two different TIDs.
47 const u8 tos_to_tid_inv[] = {
48 0x02, /* from tos_to_tid[2] = 0 */
49 0x00, /* from tos_to_tid[0] = 1 */
50 0x01, /* from tos_to_tid[1] = 2 */
51 0x03,
52 0x04,
53 0x05,
54 0x06,
55 0x07
58 /* WMM information IE */
59 static const u8 wmm_info_ie[] = { WLAN_EID_VENDOR_SPECIFIC, 0x07,
60 0x00, 0x50, 0xf2, 0x02,
61 0x00, 0x01, 0x00
64 static const u8 wmm_aci_to_qidx_map[] = { WMM_AC_BE,
65 WMM_AC_BK,
66 WMM_AC_VI,
67 WMM_AC_VO
70 static u8 tos_to_tid[] = {
71 /* TID DSCP_P2 DSCP_P1 DSCP_P0 WMM_AC */
72 0x01, /* 0 1 0 AC_BK */
73 0x02, /* 0 0 0 AC_BK */
74 0x00, /* 0 0 1 AC_BE */
75 0x03, /* 0 1 1 AC_BE */
76 0x04, /* 1 0 0 AC_VI */
77 0x05, /* 1 0 1 AC_VI */
78 0x06, /* 1 1 0 AC_VO */
79 0x07 /* 1 1 1 AC_VO */
82 static u8 ac_to_tid[4][2] = { {1, 2}, {0, 3}, {4, 5}, {6, 7} };
85 * This function debug prints the priority parameters for a WMM AC.
87 static void
88 mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters *ac_param)
90 const char *ac_str[] = { "BK", "BE", "VI", "VO" };
92 pr_debug("info: WMM AC_%s: ACI=%d, ACM=%d, Aifsn=%d, "
93 "EcwMin=%d, EcwMax=%d, TxopLimit=%d\n",
94 ac_str[wmm_aci_to_qidx_map[(ac_param->aci_aifsn_bitmap
95 & MWIFIEX_ACI) >> 5]],
96 (ac_param->aci_aifsn_bitmap & MWIFIEX_ACI) >> 5,
97 (ac_param->aci_aifsn_bitmap & MWIFIEX_ACM) >> 4,
98 ac_param->aci_aifsn_bitmap & MWIFIEX_AIFSN,
99 ac_param->ecw_bitmap & MWIFIEX_ECW_MIN,
100 (ac_param->ecw_bitmap & MWIFIEX_ECW_MAX) >> 4,
101 le16_to_cpu(ac_param->tx_op_limit));
105 * This function allocates a route address list.
107 * The function also initializes the list with the provided RA.
109 static struct mwifiex_ra_list_tbl *
110 mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, const u8 *ra)
112 struct mwifiex_ra_list_tbl *ra_list;
114 ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC);
115 if (!ra_list)
116 return NULL;
118 INIT_LIST_HEAD(&ra_list->list);
119 skb_queue_head_init(&ra_list->skb_head);
121 memcpy(ra_list->ra, ra, ETH_ALEN);
123 ra_list->total_pkt_count = 0;
125 mwifiex_dbg(adapter, INFO, "info: allocated ra_list %p\n", ra_list);
127 return ra_list;
130 /* This function returns random no between 16 and 32 to be used as threshold
131 * for no of packets after which BA setup is initiated.
133 static u8 mwifiex_get_random_ba_threshold(void)
135 u64 ns;
136 /* setup ba_packet_threshold here random number between
137 * [BA_SETUP_PACKET_OFFSET,
138 * BA_SETUP_PACKET_OFFSET+BA_SETUP_MAX_PACKET_THRESHOLD-1]
140 ns = ktime_get_ns();
141 ns += (ns >> 32) + (ns >> 16);
143 return ((u8)ns % BA_SETUP_MAX_PACKET_THRESHOLD) + BA_SETUP_PACKET_OFFSET;
147 * This function allocates and adds a RA list for all TIDs
148 * with the given RA.
150 void mwifiex_ralist_add(struct mwifiex_private *priv, const u8 *ra)
152 int i;
153 struct mwifiex_ra_list_tbl *ra_list;
154 struct mwifiex_adapter *adapter = priv->adapter;
155 struct mwifiex_sta_node *node;
158 for (i = 0; i < MAX_NUM_TID; ++i) {
159 ra_list = mwifiex_wmm_allocate_ralist_node(adapter, ra);
160 mwifiex_dbg(adapter, INFO,
161 "info: created ra_list %p\n", ra_list);
163 if (!ra_list)
164 break;
166 ra_list->is_11n_enabled = 0;
167 ra_list->tdls_link = false;
168 ra_list->ba_status = BA_SETUP_NONE;
169 ra_list->amsdu_in_ampdu = false;
170 if (!mwifiex_queuing_ra_based(priv)) {
171 if (mwifiex_is_tdls_link_setup
172 (mwifiex_get_tdls_link_status(priv, ra))) {
173 ra_list->tdls_link = true;
174 ra_list->is_11n_enabled =
175 mwifiex_tdls_peer_11n_enabled(priv, ra);
176 } else {
177 ra_list->is_11n_enabled = IS_11N_ENABLED(priv);
179 } else {
180 spin_lock_bh(&priv->sta_list_spinlock);
181 node = mwifiex_get_sta_entry(priv, ra);
182 if (node)
183 ra_list->tx_paused = node->tx_pause;
184 ra_list->is_11n_enabled =
185 mwifiex_is_sta_11n_enabled(priv, node);
186 if (ra_list->is_11n_enabled)
187 ra_list->max_amsdu = node->max_amsdu;
188 spin_unlock_bh(&priv->sta_list_spinlock);
191 mwifiex_dbg(adapter, DATA, "data: ralist %p: is_11n_enabled=%d\n",
192 ra_list, ra_list->is_11n_enabled);
194 if (ra_list->is_11n_enabled) {
195 ra_list->ba_pkt_count = 0;
196 ra_list->ba_packet_thr =
197 mwifiex_get_random_ba_threshold();
199 list_add_tail(&ra_list->list,
200 &priv->wmm.tid_tbl_ptr[i].ra_list);
205 * This function sets the WMM queue priorities to their default values.
207 static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private *priv)
209 /* Default queue priorities: VO->VI->BE->BK */
210 priv->wmm.queue_priority[0] = WMM_AC_VO;
211 priv->wmm.queue_priority[1] = WMM_AC_VI;
212 priv->wmm.queue_priority[2] = WMM_AC_BE;
213 priv->wmm.queue_priority[3] = WMM_AC_BK;
217 * This function map ACs to TIDs.
219 static void
220 mwifiex_wmm_queue_priorities_tid(struct mwifiex_private *priv)
222 struct mwifiex_wmm_desc *wmm = &priv->wmm;
223 u8 *queue_priority = wmm->queue_priority;
224 int i;
226 for (i = 0; i < 4; ++i) {
227 tos_to_tid[7 - (i * 2)] = ac_to_tid[queue_priority[i]][1];
228 tos_to_tid[6 - (i * 2)] = ac_to_tid[queue_priority[i]][0];
231 for (i = 0; i < MAX_NUM_TID; ++i)
232 priv->tos_to_tid_inv[tos_to_tid[i]] = (u8)i;
234 atomic_set(&wmm->highest_queued_prio, HIGH_PRIO_TID);
238 * This function initializes WMM priority queues.
240 void
241 mwifiex_wmm_setup_queue_priorities(struct mwifiex_private *priv,
242 struct ieee_types_wmm_parameter *wmm_ie)
244 u16 cw_min, avg_back_off, tmp[4];
245 u32 i, j, num_ac;
246 u8 ac_idx;
248 if (!wmm_ie || !priv->wmm_enabled) {
249 /* WMM is not enabled, just set the defaults and return */
250 mwifiex_wmm_default_queue_priorities(priv);
251 return;
254 mwifiex_dbg(priv->adapter, INFO,
255 "info: WMM Parameter IE: version=%d,\t"
256 "qos_info Parameter Set Count=%d, Reserved=%#x\n",
257 wmm_ie->version, wmm_ie->qos_info_bitmap &
258 IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK,
259 wmm_ie->reserved);
261 for (num_ac = 0; num_ac < ARRAY_SIZE(wmm_ie->ac_params); num_ac++) {
262 u8 ecw = wmm_ie->ac_params[num_ac].ecw_bitmap;
263 u8 aci_aifsn = wmm_ie->ac_params[num_ac].aci_aifsn_bitmap;
264 cw_min = (1 << (ecw & MWIFIEX_ECW_MIN)) - 1;
265 avg_back_off = (cw_min >> 1) + (aci_aifsn & MWIFIEX_AIFSN);
267 ac_idx = wmm_aci_to_qidx_map[(aci_aifsn & MWIFIEX_ACI) >> 5];
268 priv->wmm.queue_priority[ac_idx] = ac_idx;
269 tmp[ac_idx] = avg_back_off;
271 mwifiex_dbg(priv->adapter, INFO,
272 "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n",
273 (1 << ((ecw & MWIFIEX_ECW_MAX) >> 4)) - 1,
274 cw_min, avg_back_off);
275 mwifiex_wmm_ac_debug_print(&wmm_ie->ac_params[num_ac]);
278 /* Bubble sort */
279 for (i = 0; i < num_ac; i++) {
280 for (j = 1; j < num_ac - i; j++) {
281 if (tmp[j - 1] > tmp[j]) {
282 swap(tmp[j - 1], tmp[j]);
283 swap(priv->wmm.queue_priority[j - 1],
284 priv->wmm.queue_priority[j]);
285 } else if (tmp[j - 1] == tmp[j]) {
286 if (priv->wmm.queue_priority[j - 1]
287 < priv->wmm.queue_priority[j])
288 swap(priv->wmm.queue_priority[j - 1],
289 priv->wmm.queue_priority[j]);
294 mwifiex_wmm_queue_priorities_tid(priv);
298 * This function evaluates whether or not an AC is to be downgraded.
300 * In case the AC is not enabled, the highest AC is returned that is
301 * enabled and does not require admission control.
303 static enum mwifiex_wmm_ac_e
304 mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private *priv,
305 enum mwifiex_wmm_ac_e eval_ac)
307 int down_ac;
308 enum mwifiex_wmm_ac_e ret_ac;
309 struct mwifiex_wmm_ac_status *ac_status;
311 ac_status = &priv->wmm.ac_status[eval_ac];
313 if (!ac_status->disabled)
314 /* Okay to use this AC, its enabled */
315 return eval_ac;
317 /* Setup a default return value of the lowest priority */
318 ret_ac = WMM_AC_BK;
321 * Find the highest AC that is enabled and does not require
322 * admission control. The spec disallows downgrading to an AC,
323 * which is enabled due to a completed admission control.
324 * Unadmitted traffic is not to be sent on an AC with admitted
325 * traffic.
327 for (down_ac = WMM_AC_BK; down_ac < eval_ac; down_ac++) {
328 ac_status = &priv->wmm.ac_status[down_ac];
330 if (!ac_status->disabled && !ac_status->flow_required)
331 /* AC is enabled and does not require admission
332 control */
333 ret_ac = (enum mwifiex_wmm_ac_e) down_ac;
336 return ret_ac;
340 * This function downgrades WMM priority queue.
342 void
343 mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private *priv)
345 int ac_val;
347 mwifiex_dbg(priv->adapter, INFO, "info: WMM: AC Priorities:\t"
348 "BK(0), BE(1), VI(2), VO(3)\n");
350 if (!priv->wmm_enabled) {
351 /* WMM is not enabled, default priorities */
352 for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++)
353 priv->wmm.ac_down_graded_vals[ac_val] =
354 (enum mwifiex_wmm_ac_e) ac_val;
355 } else {
356 for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) {
357 priv->wmm.ac_down_graded_vals[ac_val]
358 = mwifiex_wmm_eval_downgrade_ac(priv,
359 (enum mwifiex_wmm_ac_e) ac_val);
360 mwifiex_dbg(priv->adapter, INFO,
361 "info: WMM: AC PRIO %d maps to %d\n",
362 ac_val,
363 priv->wmm.ac_down_graded_vals[ac_val]);
369 * This function converts the IP TOS field to an WMM AC
370 * Queue assignment.
372 static enum mwifiex_wmm_ac_e
373 mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter *adapter, u32 tos)
375 /* Map of TOS UP values to WMM AC */
376 static const enum mwifiex_wmm_ac_e tos_to_ac[] = {
377 WMM_AC_BE,
378 WMM_AC_BK,
379 WMM_AC_BK,
380 WMM_AC_BE,
381 WMM_AC_VI,
382 WMM_AC_VI,
383 WMM_AC_VO,
384 WMM_AC_VO
387 if (tos >= ARRAY_SIZE(tos_to_ac))
388 return WMM_AC_BE;
390 return tos_to_ac[tos];
394 * This function evaluates a given TID and downgrades it to a lower
395 * TID if the WMM Parameter IE received from the AP indicates that the
396 * AP is disabled (due to call admission control (ACM bit). Mapping
397 * of TID to AC is taken care of internally.
399 u8 mwifiex_wmm_downgrade_tid(struct mwifiex_private *priv, u32 tid)
401 enum mwifiex_wmm_ac_e ac, ac_down;
402 u8 new_tid;
404 ac = mwifiex_wmm_convert_tos_to_ac(priv->adapter, tid);
405 ac_down = priv->wmm.ac_down_graded_vals[ac];
407 /* Send the index to tid array, picking from the array will be
408 * taken care by dequeuing function
410 new_tid = ac_to_tid[ac_down][tid % 2];
412 return new_tid;
416 * This function initializes the WMM state information and the
417 * WMM data path queues.
419 void
420 mwifiex_wmm_init(struct mwifiex_adapter *adapter)
422 int i, j;
423 struct mwifiex_private *priv;
425 for (j = 0; j < adapter->priv_num; ++j) {
426 priv = adapter->priv[j];
427 if (!priv)
428 continue;
430 for (i = 0; i < MAX_NUM_TID; ++i) {
431 if (!disable_tx_amsdu &&
432 adapter->tx_buf_size > MWIFIEX_TX_DATA_BUF_SIZE_2K)
433 priv->aggr_prio_tbl[i].amsdu =
434 priv->tos_to_tid_inv[i];
435 else
436 priv->aggr_prio_tbl[i].amsdu =
437 BA_STREAM_NOT_ALLOWED;
438 priv->aggr_prio_tbl[i].ampdu_ap =
439 priv->tos_to_tid_inv[i];
440 priv->aggr_prio_tbl[i].ampdu_user =
441 priv->tos_to_tid_inv[i];
444 priv->aggr_prio_tbl[6].amsdu
445 = priv->aggr_prio_tbl[6].ampdu_ap
446 = priv->aggr_prio_tbl[6].ampdu_user
447 = BA_STREAM_NOT_ALLOWED;
449 priv->aggr_prio_tbl[7].amsdu = priv->aggr_prio_tbl[7].ampdu_ap
450 = priv->aggr_prio_tbl[7].ampdu_user
451 = BA_STREAM_NOT_ALLOWED;
453 mwifiex_set_ba_params(priv);
454 mwifiex_reset_11n_rx_seq_num(priv);
456 priv->wmm.drv_pkt_delay_max = MWIFIEX_WMM_DRV_DELAY_MAX;
457 atomic_set(&priv->wmm.tx_pkts_queued, 0);
458 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
462 int mwifiex_bypass_txlist_empty(struct mwifiex_adapter *adapter)
464 struct mwifiex_private *priv;
465 int i;
467 for (i = 0; i < adapter->priv_num; i++) {
468 priv = adapter->priv[i];
469 if (!priv)
470 continue;
471 if (adapter->if_ops.is_port_ready &&
472 !adapter->if_ops.is_port_ready(priv))
473 continue;
474 if (!skb_queue_empty(&priv->bypass_txq))
475 return false;
478 return true;
482 * This function checks if WMM Tx queue is empty.
485 mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter)
487 int i;
488 struct mwifiex_private *priv;
490 for (i = 0; i < adapter->priv_num; ++i) {
491 priv = adapter->priv[i];
492 if (!priv)
493 continue;
494 if (!priv->port_open &&
495 (priv->bss_mode != NL80211_IFTYPE_ADHOC))
496 continue;
497 if (adapter->if_ops.is_port_ready &&
498 !adapter->if_ops.is_port_ready(priv))
499 continue;
500 if (atomic_read(&priv->wmm.tx_pkts_queued))
501 return false;
504 return true;
508 * This function deletes all packets in an RA list node.
510 * The packet sent completion callback handler are called with
511 * status failure, after they are dequeued to ensure proper
512 * cleanup. The RA list node itself is freed at the end.
514 static void
515 mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
516 struct mwifiex_ra_list_tbl *ra_list)
518 struct mwifiex_adapter *adapter = priv->adapter;
519 struct sk_buff *skb, *tmp;
521 skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) {
522 skb_unlink(skb, &ra_list->skb_head);
523 mwifiex_write_data_complete(adapter, skb, 0, -1);
528 * This function deletes all packets in an RA list.
530 * Each nodes in the RA list are freed individually first, and then
531 * the RA list itself is freed.
533 static void
534 mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
535 struct list_head *ra_list_head)
537 struct mwifiex_ra_list_tbl *ra_list;
539 list_for_each_entry(ra_list, ra_list_head, list)
540 mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
544 * This function deletes all packets in all RA lists.
546 static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
548 int i;
550 for (i = 0; i < MAX_NUM_TID; i++)
551 mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
552 ra_list);
554 atomic_set(&priv->wmm.tx_pkts_queued, 0);
555 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
559 * This function deletes all route addresses from all RA lists.
561 static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
563 struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
564 int i;
566 for (i = 0; i < MAX_NUM_TID; ++i) {
567 mwifiex_dbg(priv->adapter, INFO,
568 "info: ra_list: freeing buf for tid %d\n", i);
569 list_for_each_entry_safe(ra_list, tmp_node,
570 &priv->wmm.tid_tbl_ptr[i].ra_list,
571 list) {
572 list_del(&ra_list->list);
573 kfree(ra_list);
576 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
580 static int mwifiex_free_ack_frame(int id, void *p, void *data)
582 pr_warn("Have pending ack frames!\n");
583 kfree_skb(p);
584 return 0;
588 * This function cleans up the Tx and Rx queues.
590 * Cleanup includes -
591 * - All packets in RA lists
592 * - All entries in Rx reorder table
593 * - All entries in Tx BA stream table
594 * - MPA buffer (if required)
595 * - All RA lists
597 void
598 mwifiex_clean_txrx(struct mwifiex_private *priv)
600 struct sk_buff *skb, *tmp;
602 mwifiex_11n_cleanup_reorder_tbl(priv);
603 spin_lock_bh(&priv->wmm.ra_list_spinlock);
605 mwifiex_wmm_cleanup_queues(priv);
606 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
608 if (priv->adapter->if_ops.cleanup_mpa_buf)
609 priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
611 mwifiex_wmm_delete_all_ralist(priv);
612 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
614 if (priv->adapter->if_ops.clean_pcie_ring &&
615 !test_bit(MWIFIEX_SURPRISE_REMOVED, &priv->adapter->work_flags))
616 priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
617 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
619 skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
620 skb_unlink(skb, &priv->tdls_txq);
621 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
624 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
625 skb_unlink(skb, &priv->bypass_txq);
626 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
628 atomic_set(&priv->adapter->bypass_tx_pending, 0);
630 idr_for_each(&priv->ack_status_frames, mwifiex_free_ack_frame, NULL);
631 idr_destroy(&priv->ack_status_frames);
635 * This function retrieves a particular RA list node, matching with the
636 * given TID and RA address.
638 struct mwifiex_ra_list_tbl *
639 mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
640 const u8 *ra_addr)
642 struct mwifiex_ra_list_tbl *ra_list;
644 list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
645 list) {
646 if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
647 return ra_list;
650 return NULL;
653 void mwifiex_update_ralist_tx_pause(struct mwifiex_private *priv, u8 *mac,
654 u8 tx_pause)
656 struct mwifiex_ra_list_tbl *ra_list;
657 u32 pkt_cnt = 0, tx_pkts_queued;
658 int i;
660 spin_lock_bh(&priv->wmm.ra_list_spinlock);
662 for (i = 0; i < MAX_NUM_TID; ++i) {
663 ra_list = mwifiex_wmm_get_ralist_node(priv, i, mac);
664 if (ra_list && ra_list->tx_paused != tx_pause) {
665 pkt_cnt += ra_list->total_pkt_count;
666 ra_list->tx_paused = tx_pause;
667 if (tx_pause)
668 priv->wmm.pkts_paused[i] +=
669 ra_list->total_pkt_count;
670 else
671 priv->wmm.pkts_paused[i] -=
672 ra_list->total_pkt_count;
676 if (pkt_cnt) {
677 tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
678 if (tx_pause)
679 tx_pkts_queued -= pkt_cnt;
680 else
681 tx_pkts_queued += pkt_cnt;
683 atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
684 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
686 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
689 /* This function updates non-tdls peer ralist tx_pause while
690 * tdls channel switching
692 void mwifiex_update_ralist_tx_pause_in_tdls_cs(struct mwifiex_private *priv,
693 u8 *mac, u8 tx_pause)
695 struct mwifiex_ra_list_tbl *ra_list;
696 u32 pkt_cnt = 0, tx_pkts_queued;
697 int i;
699 spin_lock_bh(&priv->wmm.ra_list_spinlock);
701 for (i = 0; i < MAX_NUM_TID; ++i) {
702 list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[i].ra_list,
703 list) {
704 if (!memcmp(ra_list->ra, mac, ETH_ALEN))
705 continue;
707 if (ra_list->tx_paused != tx_pause) {
708 pkt_cnt += ra_list->total_pkt_count;
709 ra_list->tx_paused = tx_pause;
710 if (tx_pause)
711 priv->wmm.pkts_paused[i] +=
712 ra_list->total_pkt_count;
713 else
714 priv->wmm.pkts_paused[i] -=
715 ra_list->total_pkt_count;
720 if (pkt_cnt) {
721 tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
722 if (tx_pause)
723 tx_pkts_queued -= pkt_cnt;
724 else
725 tx_pkts_queued += pkt_cnt;
727 atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
728 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
730 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
734 * This function retrieves an RA list node for a given TID and
735 * RA address pair.
737 * If no such node is found, a new node is added first and then
738 * retrieved.
740 struct mwifiex_ra_list_tbl *
741 mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid,
742 const u8 *ra_addr)
744 struct mwifiex_ra_list_tbl *ra_list;
746 ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
747 if (ra_list)
748 return ra_list;
749 mwifiex_ralist_add(priv, ra_addr);
751 return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
755 * This function deletes RA list nodes for given mac for all TIDs.
756 * Function also decrements TX pending count accordingly.
758 void
759 mwifiex_wmm_del_peer_ra_list(struct mwifiex_private *priv, const u8 *ra_addr)
761 struct mwifiex_ra_list_tbl *ra_list;
762 int i;
764 spin_lock_bh(&priv->wmm.ra_list_spinlock);
766 for (i = 0; i < MAX_NUM_TID; ++i) {
767 ra_list = mwifiex_wmm_get_ralist_node(priv, i, ra_addr);
769 if (!ra_list)
770 continue;
771 mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
772 if (ra_list->tx_paused)
773 priv->wmm.pkts_paused[i] -= ra_list->total_pkt_count;
774 else
775 atomic_sub(ra_list->total_pkt_count,
776 &priv->wmm.tx_pkts_queued);
777 list_del(&ra_list->list);
778 kfree(ra_list);
780 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
784 * This function checks if a particular RA list node exists in a given TID
785 * table index.
788 mwifiex_is_ralist_valid(struct mwifiex_private *priv,
789 struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
791 struct mwifiex_ra_list_tbl *rlist;
793 list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
794 list) {
795 if (rlist == ra_list)
796 return true;
799 return false;
803 * This function adds a packet to bypass TX queue.
804 * This is special TX queue for packets which can be sent even when port_open
805 * is false.
807 void
808 mwifiex_wmm_add_buf_bypass_txqueue(struct mwifiex_private *priv,
809 struct sk_buff *skb)
811 skb_queue_tail(&priv->bypass_txq, skb);
815 * This function adds a packet to WMM queue.
817 * In disconnected state the packet is immediately dropped and the
818 * packet send completion callback is called with status failure.
820 * Otherwise, the correct RA list node is located and the packet
821 * is queued at the list tail.
823 void
824 mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
825 struct sk_buff *skb)
827 struct mwifiex_adapter *adapter = priv->adapter;
828 u32 tid;
829 struct mwifiex_ra_list_tbl *ra_list;
830 u8 ra[ETH_ALEN], tid_down;
831 struct list_head list_head;
832 int tdls_status = TDLS_NOT_SETUP;
833 struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
834 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
836 memcpy(ra, eth_hdr->h_dest, ETH_ALEN);
838 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
839 ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) {
840 if (ntohs(eth_hdr->h_proto) == ETH_P_TDLS)
841 mwifiex_dbg(adapter, DATA,
842 "TDLS setup packet for %pM.\t"
843 "Don't block\n", ra);
844 else if (memcmp(priv->cfg_bssid, ra, ETH_ALEN))
845 tdls_status = mwifiex_get_tdls_link_status(priv, ra);
848 if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
849 mwifiex_dbg(adapter, DATA, "data: drop packet in disconnect\n");
850 mwifiex_write_data_complete(adapter, skb, 0, -1);
851 return;
854 tid = skb->priority;
856 spin_lock_bh(&priv->wmm.ra_list_spinlock);
858 tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
860 /* In case of infra as we have already created the list during
861 association we just don't have to call get_queue_raptr, we will
862 have only 1 raptr for a tid in case of infra */
863 if (!mwifiex_queuing_ra_based(priv) &&
864 !mwifiex_is_skb_mgmt_frame(skb)) {
865 switch (tdls_status) {
866 case TDLS_SETUP_COMPLETE:
867 case TDLS_CHAN_SWITCHING:
868 case TDLS_IN_BASE_CHAN:
869 case TDLS_IN_OFF_CHAN:
870 ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down,
871 ra);
872 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
873 break;
874 case TDLS_SETUP_INPROGRESS:
875 skb_queue_tail(&priv->tdls_txq, skb);
876 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
877 return;
878 default:
879 list_head = priv->wmm.tid_tbl_ptr[tid_down].ra_list;
880 ra_list = list_first_entry_or_null(&list_head,
881 struct mwifiex_ra_list_tbl, list);
882 break;
884 } else {
885 memcpy(ra, skb->data, ETH_ALEN);
886 if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
887 eth_broadcast_addr(ra);
888 ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
891 if (!ra_list) {
892 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
893 mwifiex_write_data_complete(adapter, skb, 0, -1);
894 return;
897 skb_queue_tail(&ra_list->skb_head, skb);
899 ra_list->ba_pkt_count++;
900 ra_list->total_pkt_count++;
902 if (atomic_read(&priv->wmm.highest_queued_prio) <
903 priv->tos_to_tid_inv[tid_down])
904 atomic_set(&priv->wmm.highest_queued_prio,
905 priv->tos_to_tid_inv[tid_down]);
907 if (ra_list->tx_paused)
908 priv->wmm.pkts_paused[tid_down]++;
909 else
910 atomic_inc(&priv->wmm.tx_pkts_queued);
912 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
916 * This function processes the get WMM status command response from firmware.
918 * The response may contain multiple TLVs -
919 * - AC Queue status TLVs
920 * - Current WMM Parameter IE TLV
921 * - Admission Control action frame TLVs
923 * This function parses the TLVs and then calls further specific functions
924 * to process any changes in the queue prioritize or state.
926 int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
927 const struct host_cmd_ds_command *resp)
929 u8 *curr = (u8 *) &resp->params.get_wmm_status;
930 uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
931 int mask = IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK;
932 bool valid = true;
934 struct mwifiex_ie_types_data *tlv_hdr;
935 struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
936 struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
937 struct mwifiex_wmm_ac_status *ac_status;
939 mwifiex_dbg(priv->adapter, INFO,
940 "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
941 resp_len);
943 while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
944 tlv_hdr = (struct mwifiex_ie_types_data *) curr;
945 tlv_len = le16_to_cpu(tlv_hdr->header.len);
947 if (resp_len < tlv_len + sizeof(tlv_hdr->header))
948 break;
950 switch (le16_to_cpu(tlv_hdr->header.type)) {
951 case TLV_TYPE_WMMQSTATUS:
952 tlv_wmm_qstatus =
953 (struct mwifiex_ie_types_wmm_queue_status *)
954 tlv_hdr;
955 mwifiex_dbg(priv->adapter, CMD,
956 "info: CMD_RESP: WMM_GET_STATUS:\t"
957 "QSTATUS TLV: %d, %d, %d\n",
958 tlv_wmm_qstatus->queue_index,
959 tlv_wmm_qstatus->flow_required,
960 tlv_wmm_qstatus->disabled);
962 ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
963 queue_index];
964 ac_status->disabled = tlv_wmm_qstatus->disabled;
965 ac_status->flow_required =
966 tlv_wmm_qstatus->flow_required;
967 ac_status->flow_created = tlv_wmm_qstatus->flow_created;
968 break;
970 case WLAN_EID_VENDOR_SPECIFIC:
972 * Point the regular IEEE IE 2 bytes into the Marvell IE
973 * and setup the IEEE IE type and length byte fields
976 wmm_param_ie =
977 (struct ieee_types_wmm_parameter *) (curr +
979 wmm_param_ie->vend_hdr.len = (u8) tlv_len;
980 wmm_param_ie->vend_hdr.element_id =
981 WLAN_EID_VENDOR_SPECIFIC;
983 mwifiex_dbg(priv->adapter, CMD,
984 "info: CMD_RESP: WMM_GET_STATUS:\t"
985 "WMM Parameter Set Count: %d\n",
986 wmm_param_ie->qos_info_bitmap & mask);
988 if (wmm_param_ie->vend_hdr.len + 2 >
989 sizeof(struct ieee_types_wmm_parameter))
990 break;
992 memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
993 wmm_ie, wmm_param_ie,
994 wmm_param_ie->vend_hdr.len + 2);
996 break;
998 default:
999 valid = false;
1000 break;
1003 curr += (tlv_len + sizeof(tlv_hdr->header));
1004 resp_len -= (tlv_len + sizeof(tlv_hdr->header));
1007 mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
1008 mwifiex_wmm_setup_ac_downgrade(priv);
1010 return 0;
1014 * Callback handler from the command module to allow insertion of a WMM TLV.
1016 * If the BSS we are associating to supports WMM, this function adds the
1017 * required WMM Information IE to the association request command buffer in
1018 * the form of a Marvell extended IEEE IE.
1021 mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
1022 u8 **assoc_buf,
1023 struct ieee_types_wmm_parameter *wmm_ie,
1024 struct ieee80211_ht_cap *ht_cap)
1026 struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
1027 u32 ret_len = 0;
1029 /* Null checks */
1030 if (!assoc_buf)
1031 return 0;
1032 if (!(*assoc_buf))
1033 return 0;
1035 if (!wmm_ie)
1036 return 0;
1038 mwifiex_dbg(priv->adapter, INFO,
1039 "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
1040 wmm_ie->vend_hdr.element_id);
1042 if ((priv->wmm_required ||
1043 (ht_cap && (priv->adapter->config_bands & BAND_GN ||
1044 priv->adapter->config_bands & BAND_AN))) &&
1045 wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
1046 wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
1047 wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
1048 wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
1049 memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
1050 le16_to_cpu(wmm_tlv->header.len));
1051 if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
1052 memcpy((u8 *) (wmm_tlv->wmm_ie
1053 + le16_to_cpu(wmm_tlv->header.len)
1054 - sizeof(priv->wmm_qosinfo)),
1055 &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
1057 ret_len = sizeof(wmm_tlv->header)
1058 + le16_to_cpu(wmm_tlv->header.len);
1060 *assoc_buf += ret_len;
1063 return ret_len;
1067 * This function computes the time delay in the driver queues for a
1068 * given packet.
1070 * When the packet is received at the OS/Driver interface, the current
1071 * time is set in the packet structure. The difference between the present
1072 * time and that received time is computed in this function and limited
1073 * based on pre-compiled limits in the driver.
1076 mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
1077 const struct sk_buff *skb)
1079 u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));
1080 u8 ret_val;
1083 * Queue delay is passed as a uint8 in units of 2ms (ms shifted
1084 * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
1086 * Pass max value if queue_delay is beyond the uint8 range
1088 ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
1090 mwifiex_dbg(priv->adapter, DATA, "data: WMM: Pkt Delay: %d ms,\t"
1091 "%d ms sent to FW\n", queue_delay, ret_val);
1093 return ret_val;
1097 * This function retrieves the highest priority RA list table pointer.
1099 static struct mwifiex_ra_list_tbl *
1100 mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
1101 struct mwifiex_private **priv, int *tid)
1103 struct mwifiex_private *priv_tmp;
1104 struct mwifiex_ra_list_tbl *ptr;
1105 struct mwifiex_tid_tbl *tid_ptr;
1106 atomic_t *hqp;
1107 int i, j;
1109 /* check the BSS with highest priority first */
1110 for (j = adapter->priv_num - 1; j >= 0; --j) {
1111 /* iterate over BSS with the equal priority */
1112 list_for_each_entry(adapter->bss_prio_tbl[j].bss_prio_cur,
1113 &adapter->bss_prio_tbl[j].bss_prio_head,
1114 list) {
1116 try_again:
1117 priv_tmp = adapter->bss_prio_tbl[j].bss_prio_cur->priv;
1119 if (((priv_tmp->bss_mode != NL80211_IFTYPE_ADHOC) &&
1120 !priv_tmp->port_open) ||
1121 (atomic_read(&priv_tmp->wmm.tx_pkts_queued) == 0))
1122 continue;
1124 if (adapter->if_ops.is_port_ready &&
1125 !adapter->if_ops.is_port_ready(priv_tmp))
1126 continue;
1128 /* iterate over the WMM queues of the BSS */
1129 hqp = &priv_tmp->wmm.highest_queued_prio;
1130 for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
1132 spin_lock_bh(&priv_tmp->wmm.ra_list_spinlock);
1134 tid_ptr = &(priv_tmp)->wmm.
1135 tid_tbl_ptr[tos_to_tid[i]];
1137 /* iterate over receiver addresses */
1138 list_for_each_entry(ptr, &tid_ptr->ra_list,
1139 list) {
1141 if (!ptr->tx_paused &&
1142 !skb_queue_empty(&ptr->skb_head))
1143 /* holds both locks */
1144 goto found;
1147 spin_unlock_bh(&priv_tmp->wmm.ra_list_spinlock);
1150 if (atomic_read(&priv_tmp->wmm.tx_pkts_queued) != 0) {
1151 atomic_set(&priv_tmp->wmm.highest_queued_prio,
1152 HIGH_PRIO_TID);
1153 /* Iterate current private once more, since
1154 * there still exist packets in data queue
1156 goto try_again;
1157 } else
1158 atomic_set(&priv_tmp->wmm.highest_queued_prio,
1159 NO_PKT_PRIO_TID);
1163 return NULL;
1165 found:
1166 /* holds ra_list_spinlock */
1167 if (atomic_read(hqp) > i)
1168 atomic_set(hqp, i);
1169 spin_unlock_bh(&priv_tmp->wmm.ra_list_spinlock);
1171 *priv = priv_tmp;
1172 *tid = tos_to_tid[i];
1174 return ptr;
1177 /* This functions rotates ra and bss lists so packets are picked round robin.
1179 * After a packet is successfully transmitted, rotate the ra list, so the ra
1180 * next to the one transmitted, will come first in the list. This way we pick
1181 * the ra' in a round robin fashion. Same applies to bss nodes of equal
1182 * priority.
1184 * Function also increments wmm.packets_out counter.
1186 void mwifiex_rotate_priolists(struct mwifiex_private *priv,
1187 struct mwifiex_ra_list_tbl *ra,
1188 int tid)
1190 struct mwifiex_adapter *adapter = priv->adapter;
1191 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
1192 struct mwifiex_tid_tbl *tid_ptr = &priv->wmm.tid_tbl_ptr[tid];
1194 spin_lock_bh(&tbl[priv->bss_priority].bss_prio_lock);
1196 * dirty trick: we remove 'head' temporarily and reinsert it after
1197 * curr bss node. imagine list to stay fixed while head is moved
1199 list_move(&tbl[priv->bss_priority].bss_prio_head,
1200 &tbl[priv->bss_priority].bss_prio_cur->list);
1201 spin_unlock_bh(&tbl[priv->bss_priority].bss_prio_lock);
1203 spin_lock_bh(&priv->wmm.ra_list_spinlock);
1204 if (mwifiex_is_ralist_valid(priv, ra, tid)) {
1205 priv->wmm.packets_out[tid]++;
1206 /* same as above */
1207 list_move(&tid_ptr->ra_list, &ra->list);
1209 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1213 * This function checks if 11n aggregation is possible.
1215 static int
1216 mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
1217 struct mwifiex_ra_list_tbl *ptr,
1218 int max_buf_size)
1220 int count = 0, total_size = 0;
1221 struct sk_buff *skb, *tmp;
1222 int max_amsdu_size;
1224 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
1225 ptr->is_11n_enabled)
1226 max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
1227 else
1228 max_amsdu_size = max_buf_size;
1230 skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
1231 total_size += skb->len;
1232 if (total_size >= max_amsdu_size)
1233 break;
1234 if (++count >= MIN_NUM_AMSDU)
1235 return true;
1238 return false;
1242 * This function sends a single packet to firmware for transmission.
1244 static void
1245 mwifiex_send_single_packet(struct mwifiex_private *priv,
1246 struct mwifiex_ra_list_tbl *ptr, int ptr_index)
1247 __releases(&priv->wmm.ra_list_spinlock)
1249 struct sk_buff *skb, *skb_next;
1250 struct mwifiex_tx_param tx_param;
1251 struct mwifiex_adapter *adapter = priv->adapter;
1252 struct mwifiex_txinfo *tx_info;
1254 if (skb_queue_empty(&ptr->skb_head)) {
1255 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1256 mwifiex_dbg(adapter, DATA, "data: nothing to send\n");
1257 return;
1260 skb = skb_dequeue(&ptr->skb_head);
1262 tx_info = MWIFIEX_SKB_TXCB(skb);
1263 mwifiex_dbg(adapter, DATA,
1264 "data: dequeuing the packet %p %p\n", ptr, skb);
1266 ptr->total_pkt_count--;
1268 if (!skb_queue_empty(&ptr->skb_head))
1269 skb_next = skb_peek(&ptr->skb_head);
1270 else
1271 skb_next = NULL;
1273 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1275 tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
1276 sizeof(struct txpd) : 0);
1278 if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
1279 /* Queue the packet back at the head */
1280 spin_lock_bh(&priv->wmm.ra_list_spinlock);
1282 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1283 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1284 mwifiex_write_data_complete(adapter, skb, 0, -1);
1285 return;
1288 skb_queue_tail(&ptr->skb_head, skb);
1290 ptr->total_pkt_count++;
1291 ptr->ba_pkt_count++;
1292 tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1293 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1294 } else {
1295 mwifiex_rotate_priolists(priv, ptr, ptr_index);
1296 atomic_dec(&priv->wmm.tx_pkts_queued);
1301 * This function checks if the first packet in the given RA list
1302 * is already processed or not.
1304 static int
1305 mwifiex_is_ptr_processed(struct mwifiex_private *priv,
1306 struct mwifiex_ra_list_tbl *ptr)
1308 struct sk_buff *skb;
1309 struct mwifiex_txinfo *tx_info;
1311 if (skb_queue_empty(&ptr->skb_head))
1312 return false;
1314 skb = skb_peek(&ptr->skb_head);
1316 tx_info = MWIFIEX_SKB_TXCB(skb);
1317 if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
1318 return true;
1320 return false;
1324 * This function sends a single processed packet to firmware for
1325 * transmission.
1327 static void
1328 mwifiex_send_processed_packet(struct mwifiex_private *priv,
1329 struct mwifiex_ra_list_tbl *ptr, int ptr_index)
1330 __releases(&priv->wmm.ra_list_spinlock)
1332 struct mwifiex_tx_param tx_param;
1333 struct mwifiex_adapter *adapter = priv->adapter;
1334 int ret = -1;
1335 struct sk_buff *skb, *skb_next;
1336 struct mwifiex_txinfo *tx_info;
1338 if (skb_queue_empty(&ptr->skb_head)) {
1339 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1340 return;
1343 skb = skb_dequeue(&ptr->skb_head);
1345 if (adapter->data_sent || adapter->tx_lock_flag) {
1346 ptr->total_pkt_count--;
1347 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1348 skb_queue_tail(&adapter->tx_data_q, skb);
1349 atomic_dec(&priv->wmm.tx_pkts_queued);
1350 atomic_inc(&adapter->tx_queued);
1351 return;
1354 if (!skb_queue_empty(&ptr->skb_head))
1355 skb_next = skb_peek(&ptr->skb_head);
1356 else
1357 skb_next = NULL;
1359 tx_info = MWIFIEX_SKB_TXCB(skb);
1361 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1363 tx_param.next_pkt_len =
1364 ((skb_next) ? skb_next->len +
1365 sizeof(struct txpd) : 0);
1366 if (adapter->iface_type == MWIFIEX_USB) {
1367 ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
1368 skb, &tx_param);
1369 } else {
1370 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
1371 skb, &tx_param);
1374 switch (ret) {
1375 case -EBUSY:
1376 mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
1377 spin_lock_bh(&priv->wmm.ra_list_spinlock);
1379 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1380 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1381 mwifiex_write_data_complete(adapter, skb, 0, -1);
1382 return;
1385 skb_queue_tail(&ptr->skb_head, skb);
1387 tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1388 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1389 break;
1390 case -1:
1391 mwifiex_dbg(adapter, ERROR, "host_to_card failed: %#x\n", ret);
1392 adapter->dbg.num_tx_host_to_card_failure++;
1393 mwifiex_write_data_complete(adapter, skb, 0, ret);
1394 break;
1395 case -EINPROGRESS:
1396 break;
1397 case 0:
1398 mwifiex_write_data_complete(adapter, skb, 0, ret);
1399 break;
1400 default:
1401 break;
1403 if (ret != -EBUSY) {
1404 mwifiex_rotate_priolists(priv, ptr, ptr_index);
1405 atomic_dec(&priv->wmm.tx_pkts_queued);
1406 spin_lock_bh(&priv->wmm.ra_list_spinlock);
1407 ptr->total_pkt_count--;
1408 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1413 * This function dequeues a packet from the highest priority list
1414 * and transmits it.
1416 static int
1417 mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
1419 struct mwifiex_ra_list_tbl *ptr;
1420 struct mwifiex_private *priv = NULL;
1421 int ptr_index = 0;
1422 u8 ra[ETH_ALEN];
1423 int tid_del = 0, tid = 0;
1425 ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
1426 if (!ptr)
1427 return -1;
1429 tid = mwifiex_get_tid(ptr);
1431 mwifiex_dbg(adapter, DATA, "data: tid=%d\n", tid);
1433 spin_lock_bh(&priv->wmm.ra_list_spinlock);
1434 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1435 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1436 return -1;
1439 if (mwifiex_is_ptr_processed(priv, ptr)) {
1440 mwifiex_send_processed_packet(priv, ptr, ptr_index);
1441 /* ra_list_spinlock has been freed in
1442 mwifiex_send_processed_packet() */
1443 return 0;
1446 if (!ptr->is_11n_enabled ||
1447 ptr->ba_status ||
1448 priv->wps.session_enable) {
1449 if (ptr->is_11n_enabled &&
1450 ptr->ba_status &&
1451 ptr->amsdu_in_ampdu &&
1452 mwifiex_is_amsdu_allowed(priv, tid) &&
1453 mwifiex_is_11n_aggragation_possible(priv, ptr,
1454 adapter->tx_buf_size))
1455 mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index);
1456 /* ra_list_spinlock has been freed in
1457 * mwifiex_11n_aggregate_pkt()
1459 else
1460 mwifiex_send_single_packet(priv, ptr, ptr_index);
1461 /* ra_list_spinlock has been freed in
1462 * mwifiex_send_single_packet()
1464 } else {
1465 if (mwifiex_is_ampdu_allowed(priv, ptr, tid) &&
1466 ptr->ba_pkt_count > ptr->ba_packet_thr) {
1467 if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
1468 mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1469 BA_SETUP_INPROGRESS);
1470 mwifiex_send_addba(priv, tid, ptr->ra);
1471 } else if (mwifiex_find_stream_to_delete
1472 (priv, tid, &tid_del, ra)) {
1473 mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1474 BA_SETUP_INPROGRESS);
1475 mwifiex_send_delba(priv, tid_del, ra, 1);
1478 if (mwifiex_is_amsdu_allowed(priv, tid) &&
1479 mwifiex_is_11n_aggragation_possible(priv, ptr,
1480 adapter->tx_buf_size))
1481 mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index);
1482 /* ra_list_spinlock has been freed in
1483 mwifiex_11n_aggregate_pkt() */
1484 else
1485 mwifiex_send_single_packet(priv, ptr, ptr_index);
1486 /* ra_list_spinlock has been freed in
1487 mwifiex_send_single_packet() */
1489 return 0;
1492 void mwifiex_process_bypass_tx(struct mwifiex_adapter *adapter)
1494 struct mwifiex_tx_param tx_param;
1495 struct sk_buff *skb;
1496 struct mwifiex_txinfo *tx_info;
1497 struct mwifiex_private *priv;
1498 int i;
1500 if (adapter->data_sent || adapter->tx_lock_flag)
1501 return;
1503 for (i = 0; i < adapter->priv_num; ++i) {
1504 priv = adapter->priv[i];
1506 if (!priv)
1507 continue;
1509 if (adapter->if_ops.is_port_ready &&
1510 !adapter->if_ops.is_port_ready(priv))
1511 continue;
1513 if (skb_queue_empty(&priv->bypass_txq))
1514 continue;
1516 skb = skb_dequeue(&priv->bypass_txq);
1517 tx_info = MWIFIEX_SKB_TXCB(skb);
1519 /* no aggregation for bypass packets */
1520 tx_param.next_pkt_len = 0;
1522 if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
1523 skb_queue_head(&priv->bypass_txq, skb);
1524 tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1525 } else {
1526 atomic_dec(&adapter->bypass_tx_pending);
1532 * This function transmits the highest priority packet awaiting in the
1533 * WMM Queues.
1535 void
1536 mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
1538 do {
1539 if (mwifiex_dequeue_tx_packet(adapter))
1540 break;
1541 if (adapter->iface_type != MWIFIEX_SDIO) {
1542 if (adapter->data_sent ||
1543 adapter->tx_lock_flag)
1544 break;
1545 } else {
1546 if (atomic_read(&adapter->tx_queued) >=
1547 MWIFIEX_MAX_PKTS_TXQ)
1548 break;
1550 } while (!mwifiex_wmm_lists_empty(adapter));