2 * Marvell Wireless LAN device driver: WMM
4 * Copyright (C) 2011, 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.
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 /* WMM information IE */
41 static const u8 wmm_info_ie
[] = { WLAN_EID_VENDOR_SPECIFIC
, 0x07,
42 0x00, 0x50, 0xf2, 0x02,
46 static const u8 wmm_aci_to_qidx_map
[] = { WMM_AC_BE
,
52 static u8 tos_to_tid
[] = {
53 /* TID DSCP_P2 DSCP_P1 DSCP_P0 WMM_AC */
54 0x01, /* 0 1 0 AC_BK */
55 0x02, /* 0 0 0 AC_BK */
56 0x00, /* 0 0 1 AC_BE */
57 0x03, /* 0 1 1 AC_BE */
58 0x04, /* 1 0 0 AC_VI */
59 0x05, /* 1 0 1 AC_VI */
60 0x06, /* 1 1 0 AC_VO */
61 0x07 /* 1 1 1 AC_VO */
65 * This table inverses the tos_to_tid operation to get a priority
66 * which is in sequential order, and can be compared.
67 * Use this to compare the priority of two different TIDs.
69 static u8 tos_to_tid_inv
[] = {
70 0x02, /* from tos_to_tid[2] = 0 */
71 0x00, /* from tos_to_tid[0] = 1 */
72 0x01, /* from tos_to_tid[1] = 2 */
79 static u8 ac_to_tid
[4][2] = { {1, 2}, {0, 3}, {4, 5}, {6, 7} };
82 * This function debug prints the priority parameters for a WMM AC.
85 mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters
*ac_param
)
87 const char *ac_str
[] = { "BK", "BE", "VI", "VO" };
89 pr_debug("info: WMM AC_%s: ACI=%d, ACM=%d, Aifsn=%d, "
90 "EcwMin=%d, EcwMax=%d, TxopLimit=%d\n",
91 ac_str
[wmm_aci_to_qidx_map
[(ac_param
->aci_aifsn_bitmap
92 & MWIFIEX_ACI
) >> 5]],
93 (ac_param
->aci_aifsn_bitmap
& MWIFIEX_ACI
) >> 5,
94 (ac_param
->aci_aifsn_bitmap
& MWIFIEX_ACM
) >> 4,
95 ac_param
->aci_aifsn_bitmap
& MWIFIEX_AIFSN
,
96 ac_param
->ecw_bitmap
& MWIFIEX_ECW_MIN
,
97 (ac_param
->ecw_bitmap
& MWIFIEX_ECW_MAX
) >> 4,
98 le16_to_cpu(ac_param
->tx_op_limit
));
102 * This function allocates a route address list.
104 * The function also initializes the list with the provided RA.
106 static struct mwifiex_ra_list_tbl
*
107 mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter
*adapter
, u8
*ra
)
109 struct mwifiex_ra_list_tbl
*ra_list
;
111 ra_list
= kzalloc(sizeof(struct mwifiex_ra_list_tbl
), GFP_ATOMIC
);
114 dev_err(adapter
->dev
, "%s: failed to alloc ra_list\n",
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_pkts_size
= 0;
124 ra_list
->total_pkts
= 0;
126 dev_dbg(adapter
->dev
, "info: allocated ra_list %p\n", ra_list
);
132 * This function allocates and adds a RA list for all TIDs
136 mwifiex_ralist_add(struct mwifiex_private
*priv
, u8
*ra
)
139 struct mwifiex_ra_list_tbl
*ra_list
;
140 struct mwifiex_adapter
*adapter
= priv
->adapter
;
142 for (i
= 0; i
< MAX_NUM_TID
; ++i
) {
143 ra_list
= mwifiex_wmm_allocate_ralist_node(adapter
, ra
);
144 dev_dbg(adapter
->dev
, "info: created ra_list %p\n", ra_list
);
149 if (!mwifiex_queuing_ra_based(priv
))
150 ra_list
->is_11n_enabled
= IS_11N_ENABLED(priv
);
152 ra_list
->is_11n_enabled
= false;
154 dev_dbg(adapter
->dev
, "data: ralist %p: is_11n_enabled=%d\n",
155 ra_list
, ra_list
->is_11n_enabled
);
157 list_add_tail(&ra_list
->list
,
158 &priv
->wmm
.tid_tbl_ptr
[i
].ra_list
);
160 if (!priv
->wmm
.tid_tbl_ptr
[i
].ra_list_curr
)
161 priv
->wmm
.tid_tbl_ptr
[i
].ra_list_curr
= ra_list
;
166 * This function sets the WMM queue priorities to their default values.
168 static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private
*priv
)
170 /* Default queue priorities: VO->VI->BE->BK */
171 priv
->wmm
.queue_priority
[0] = WMM_AC_VO
;
172 priv
->wmm
.queue_priority
[1] = WMM_AC_VI
;
173 priv
->wmm
.queue_priority
[2] = WMM_AC_BE
;
174 priv
->wmm
.queue_priority
[3] = WMM_AC_BK
;
178 * This function map ACs to TIDs.
181 mwifiex_wmm_queue_priorities_tid(struct mwifiex_wmm_desc
*wmm
)
183 u8
*queue_priority
= wmm
->queue_priority
;
186 for (i
= 0; i
< 4; ++i
) {
187 tos_to_tid
[7 - (i
* 2)] = ac_to_tid
[queue_priority
[i
]][1];
188 tos_to_tid
[6 - (i
* 2)] = ac_to_tid
[queue_priority
[i
]][0];
191 for (i
= 0; i
< MAX_NUM_TID
; ++i
)
192 tos_to_tid_inv
[tos_to_tid
[i
]] = (u8
)i
;
194 atomic_set(&wmm
->highest_queued_prio
, HIGH_PRIO_TID
);
198 * This function initializes WMM priority queues.
201 mwifiex_wmm_setup_queue_priorities(struct mwifiex_private
*priv
,
202 struct ieee_types_wmm_parameter
*wmm_ie
)
204 u16 cw_min
, avg_back_off
, tmp
[4];
208 if (!wmm_ie
|| !priv
->wmm_enabled
) {
209 /* WMM is not enabled, just set the defaults and return */
210 mwifiex_wmm_default_queue_priorities(priv
);
214 dev_dbg(priv
->adapter
->dev
, "info: WMM Parameter IE: version=%d, "
215 "qos_info Parameter Set Count=%d, Reserved=%#x\n",
216 wmm_ie
->vend_hdr
.version
, wmm_ie
->qos_info_bitmap
&
217 IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK
,
220 for (num_ac
= 0; num_ac
< ARRAY_SIZE(wmm_ie
->ac_params
); num_ac
++) {
221 cw_min
= (1 << (wmm_ie
->ac_params
[num_ac
].ecw_bitmap
&
222 MWIFIEX_ECW_MIN
)) - 1;
223 avg_back_off
= (cw_min
>> 1) +
224 (wmm_ie
->ac_params
[num_ac
].aci_aifsn_bitmap
&
227 ac_idx
= wmm_aci_to_qidx_map
[(wmm_ie
->ac_params
[num_ac
].
230 priv
->wmm
.queue_priority
[ac_idx
] = ac_idx
;
231 tmp
[ac_idx
] = avg_back_off
;
233 dev_dbg(priv
->adapter
->dev
, "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n",
234 (1 << ((wmm_ie
->ac_params
[num_ac
].ecw_bitmap
&
235 MWIFIEX_ECW_MAX
) >> 4)) - 1,
236 cw_min
, avg_back_off
);
237 mwifiex_wmm_ac_debug_print(&wmm_ie
->ac_params
[num_ac
]);
241 for (i
= 0; i
< num_ac
; i
++) {
242 for (j
= 1; j
< num_ac
- i
; j
++) {
243 if (tmp
[j
- 1] > tmp
[j
]) {
244 swap(tmp
[j
- 1], tmp
[j
]);
245 swap(priv
->wmm
.queue_priority
[j
- 1],
246 priv
->wmm
.queue_priority
[j
]);
247 } else if (tmp
[j
- 1] == tmp
[j
]) {
248 if (priv
->wmm
.queue_priority
[j
- 1]
249 < priv
->wmm
.queue_priority
[j
])
250 swap(priv
->wmm
.queue_priority
[j
- 1],
251 priv
->wmm
.queue_priority
[j
]);
256 mwifiex_wmm_queue_priorities_tid(&priv
->wmm
);
260 * This function evaluates whether or not an AC is to be downgraded.
262 * In case the AC is not enabled, the highest AC is returned that is
263 * enabled and does not require admission control.
265 static enum mwifiex_wmm_ac_e
266 mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private
*priv
,
267 enum mwifiex_wmm_ac_e eval_ac
)
270 enum mwifiex_wmm_ac_e ret_ac
;
271 struct mwifiex_wmm_ac_status
*ac_status
;
273 ac_status
= &priv
->wmm
.ac_status
[eval_ac
];
275 if (!ac_status
->disabled
)
276 /* Okay to use this AC, its enabled */
279 /* Setup a default return value of the lowest priority */
283 * Find the highest AC that is enabled and does not require
284 * admission control. The spec disallows downgrading to an AC,
285 * which is enabled due to a completed admission control.
286 * Unadmitted traffic is not to be sent on an AC with admitted
289 for (down_ac
= WMM_AC_BK
; down_ac
< eval_ac
; down_ac
++) {
290 ac_status
= &priv
->wmm
.ac_status
[down_ac
];
292 if (!ac_status
->disabled
&& !ac_status
->flow_required
)
293 /* AC is enabled and does not require admission
295 ret_ac
= (enum mwifiex_wmm_ac_e
) down_ac
;
302 * This function downgrades WMM priority queue.
305 mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private
*priv
)
309 dev_dbg(priv
->adapter
->dev
, "info: WMM: AC Priorities:"
310 "BK(0), BE(1), VI(2), VO(3)\n");
312 if (!priv
->wmm_enabled
) {
313 /* WMM is not enabled, default priorities */
314 for (ac_val
= WMM_AC_BK
; ac_val
<= WMM_AC_VO
; ac_val
++)
315 priv
->wmm
.ac_down_graded_vals
[ac_val
] =
316 (enum mwifiex_wmm_ac_e
) ac_val
;
318 for (ac_val
= WMM_AC_BK
; ac_val
<= WMM_AC_VO
; ac_val
++) {
319 priv
->wmm
.ac_down_graded_vals
[ac_val
]
320 = mwifiex_wmm_eval_downgrade_ac(priv
,
321 (enum mwifiex_wmm_ac_e
) ac_val
);
322 dev_dbg(priv
->adapter
->dev
, "info: WMM: AC PRIO %d maps to %d\n",
323 ac_val
, priv
->wmm
.ac_down_graded_vals
[ac_val
]);
329 * This function converts the IP TOS field to an WMM AC
332 static enum mwifiex_wmm_ac_e
333 mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter
*adapter
, u32 tos
)
335 /* Map of TOS UP values to WMM AC */
336 const enum mwifiex_wmm_ac_e tos_to_ac
[] = { WMM_AC_BE
,
346 if (tos
>= ARRAY_SIZE(tos_to_ac
))
349 return tos_to_ac
[tos
];
353 * This function evaluates a given TID and downgrades it to a lower
354 * TID if the WMM Parameter IE received from the AP indicates that the
355 * AP is disabled (due to call admission control (ACM bit). Mapping
356 * of TID to AC is taken care of internally.
359 mwifiex_wmm_downgrade_tid(struct mwifiex_private
*priv
, u32 tid
)
361 enum mwifiex_wmm_ac_e ac
, ac_down
;
364 ac
= mwifiex_wmm_convert_tos_to_ac(priv
->adapter
, tid
);
365 ac_down
= priv
->wmm
.ac_down_graded_vals
[ac
];
367 /* Send the index to tid array, picking from the array will be
368 * taken care by dequeuing function
370 new_tid
= ac_to_tid
[ac_down
][tid
% 2];
376 * This function initializes the WMM state information and the
377 * WMM data path queues.
380 mwifiex_wmm_init(struct mwifiex_adapter
*adapter
)
383 struct mwifiex_private
*priv
;
385 for (j
= 0; j
< adapter
->priv_num
; ++j
) {
386 priv
= adapter
->priv
[j
];
390 for (i
= 0; i
< MAX_NUM_TID
; ++i
) {
391 priv
->aggr_prio_tbl
[i
].amsdu
= tos_to_tid_inv
[i
];
392 priv
->aggr_prio_tbl
[i
].ampdu_ap
= tos_to_tid_inv
[i
];
393 priv
->aggr_prio_tbl
[i
].ampdu_user
= tos_to_tid_inv
[i
];
394 priv
->wmm
.tid_tbl_ptr
[i
].ra_list_curr
= NULL
;
397 priv
->aggr_prio_tbl
[6].amsdu
398 = priv
->aggr_prio_tbl
[6].ampdu_ap
399 = priv
->aggr_prio_tbl
[6].ampdu_user
400 = BA_STREAM_NOT_ALLOWED
;
402 priv
->aggr_prio_tbl
[7].amsdu
= priv
->aggr_prio_tbl
[7].ampdu_ap
403 = priv
->aggr_prio_tbl
[7].ampdu_user
404 = BA_STREAM_NOT_ALLOWED
;
406 priv
->add_ba_param
.timeout
= MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT
;
407 priv
->add_ba_param
.tx_win_size
= MWIFIEX_AMPDU_DEF_TXWINSIZE
;
408 priv
->add_ba_param
.rx_win_size
= MWIFIEX_AMPDU_DEF_RXWINSIZE
;
410 atomic_set(&priv
->wmm
.tx_pkts_queued
, 0);
411 atomic_set(&priv
->wmm
.highest_queued_prio
, HIGH_PRIO_TID
);
416 * This function checks if WMM Tx queue is empty.
419 mwifiex_wmm_lists_empty(struct mwifiex_adapter
*adapter
)
422 struct mwifiex_private
*priv
;
424 for (i
= 0; i
< adapter
->priv_num
; ++i
) {
425 priv
= adapter
->priv
[i
];
426 if (priv
&& atomic_read(&priv
->wmm
.tx_pkts_queued
))
434 * This function deletes all packets in an RA list node.
436 * The packet sent completion callback handler are called with
437 * status failure, after they are dequeued to ensure proper
438 * cleanup. The RA list node itself is freed at the end.
441 mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private
*priv
,
442 struct mwifiex_ra_list_tbl
*ra_list
)
444 struct mwifiex_adapter
*adapter
= priv
->adapter
;
445 struct sk_buff
*skb
, *tmp
;
447 skb_queue_walk_safe(&ra_list
->skb_head
, skb
, tmp
)
448 mwifiex_write_data_complete(adapter
, skb
, -1);
452 * This function deletes all packets in an RA list.
454 * Each nodes in the RA list are freed individually first, and then
455 * the RA list itself is freed.
458 mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private
*priv
,
459 struct list_head
*ra_list_head
)
461 struct mwifiex_ra_list_tbl
*ra_list
;
463 list_for_each_entry(ra_list
, ra_list_head
, list
)
464 mwifiex_wmm_del_pkts_in_ralist_node(priv
, ra_list
);
468 * This function deletes all packets in all RA lists.
470 static void mwifiex_wmm_cleanup_queues(struct mwifiex_private
*priv
)
474 for (i
= 0; i
< MAX_NUM_TID
; i
++)
475 mwifiex_wmm_del_pkts_in_ralist(priv
, &priv
->wmm
.tid_tbl_ptr
[i
].
478 atomic_set(&priv
->wmm
.tx_pkts_queued
, 0);
479 atomic_set(&priv
->wmm
.highest_queued_prio
, HIGH_PRIO_TID
);
483 * This function deletes all route addresses from all RA lists.
485 static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private
*priv
)
487 struct mwifiex_ra_list_tbl
*ra_list
, *tmp_node
;
490 for (i
= 0; i
< MAX_NUM_TID
; ++i
) {
491 dev_dbg(priv
->adapter
->dev
,
492 "info: ra_list: freeing buf for tid %d\n", i
);
493 list_for_each_entry_safe(ra_list
, tmp_node
,
494 &priv
->wmm
.tid_tbl_ptr
[i
].ra_list
, list
) {
495 list_del(&ra_list
->list
);
499 INIT_LIST_HEAD(&priv
->wmm
.tid_tbl_ptr
[i
].ra_list
);
501 priv
->wmm
.tid_tbl_ptr
[i
].ra_list_curr
= NULL
;
506 * This function cleans up the Tx and Rx queues.
509 * - All packets in RA lists
510 * - All entries in Rx reorder table
511 * - All entries in Tx BA stream table
512 * - MPA buffer (if required)
516 mwifiex_clean_txrx(struct mwifiex_private
*priv
)
520 mwifiex_11n_cleanup_reorder_tbl(priv
);
521 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, flags
);
523 mwifiex_wmm_cleanup_queues(priv
);
524 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv
);
526 if (priv
->adapter
->if_ops
.cleanup_mpa_buf
)
527 priv
->adapter
->if_ops
.cleanup_mpa_buf(priv
->adapter
);
529 mwifiex_wmm_delete_all_ralist(priv
);
530 memcpy(tos_to_tid
, ac_to_tid
, sizeof(tos_to_tid
));
532 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, flags
);
536 * This function retrieves a particular RA list node, matching with the
537 * given TID and RA address.
539 static struct mwifiex_ra_list_tbl
*
540 mwifiex_wmm_get_ralist_node(struct mwifiex_private
*priv
, u8 tid
,
543 struct mwifiex_ra_list_tbl
*ra_list
;
545 list_for_each_entry(ra_list
, &priv
->wmm
.tid_tbl_ptr
[tid
].ra_list
,
547 if (!memcmp(ra_list
->ra
, ra_addr
, ETH_ALEN
))
555 * This function retrieves an RA list node for a given TID and
558 * If no such node is found, a new node is added first and then
561 static struct mwifiex_ra_list_tbl
*
562 mwifiex_wmm_get_queue_raptr(struct mwifiex_private
*priv
, u8 tid
, u8
*ra_addr
)
564 struct mwifiex_ra_list_tbl
*ra_list
;
566 ra_list
= mwifiex_wmm_get_ralist_node(priv
, tid
, ra_addr
);
569 mwifiex_ralist_add(priv
, ra_addr
);
571 return mwifiex_wmm_get_ralist_node(priv
, tid
, ra_addr
);
575 * This function checks if a particular RA list node exists in a given TID
579 mwifiex_is_ralist_valid(struct mwifiex_private
*priv
,
580 struct mwifiex_ra_list_tbl
*ra_list
, int ptr_index
)
582 struct mwifiex_ra_list_tbl
*rlist
;
584 list_for_each_entry(rlist
, &priv
->wmm
.tid_tbl_ptr
[ptr_index
].ra_list
,
586 if (rlist
== ra_list
)
594 * This function adds a packet to WMM queue.
596 * In disconnected state the packet is immediately dropped and the
597 * packet send completion callback is called with status failure.
599 * Otherwise, the correct RA list node is located and the packet
600 * is queued at the list tail.
603 mwifiex_wmm_add_buf_txqueue(struct mwifiex_adapter
*adapter
,
606 struct mwifiex_txinfo
*tx_info
= MWIFIEX_SKB_TXCB(skb
);
607 struct mwifiex_private
*priv
= adapter
->priv
[tx_info
->bss_index
];
609 struct mwifiex_ra_list_tbl
*ra_list
;
610 u8 ra
[ETH_ALEN
], tid_down
;
613 if (!priv
->media_connected
) {
614 dev_dbg(adapter
->dev
, "data: drop packet in disconnect\n");
615 mwifiex_write_data_complete(adapter
, skb
, -1);
621 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, flags
);
623 tid_down
= mwifiex_wmm_downgrade_tid(priv
, tid
);
625 /* In case of infra as we have already created the list during
626 association we just don't have to call get_queue_raptr, we will
627 have only 1 raptr for a tid in case of infra */
628 if (!mwifiex_queuing_ra_based(priv
)) {
629 if (!list_empty(&priv
->wmm
.tid_tbl_ptr
[tid_down
].ra_list
))
630 ra_list
= list_first_entry(
631 &priv
->wmm
.tid_tbl_ptr
[tid_down
].ra_list
,
632 struct mwifiex_ra_list_tbl
, list
);
636 memcpy(ra
, skb
->data
, ETH_ALEN
);
638 memset(ra
, 0xff, ETH_ALEN
);
639 ra_list
= mwifiex_wmm_get_queue_raptr(priv
, tid_down
, ra
);
643 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, flags
);
644 mwifiex_write_data_complete(adapter
, skb
, -1);
648 skb_queue_tail(&ra_list
->skb_head
, skb
);
650 ra_list
->total_pkts_size
+= skb
->len
;
651 ra_list
->total_pkts
++;
653 atomic_inc(&priv
->wmm
.tx_pkts_queued
);
655 if (atomic_read(&priv
->wmm
.highest_queued_prio
) <
656 tos_to_tid_inv
[tid_down
])
657 atomic_set(&priv
->wmm
.highest_queued_prio
,
658 tos_to_tid_inv
[tid_down
]);
660 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, flags
);
664 * This function processes the get WMM status command response from firmware.
666 * The response may contain multiple TLVs -
667 * - AC Queue status TLVs
668 * - Current WMM Parameter IE TLV
669 * - Admission Control action frame TLVs
671 * This function parses the TLVs and then calls further specific functions
672 * to process any changes in the queue prioritize or state.
674 int mwifiex_ret_wmm_get_status(struct mwifiex_private
*priv
,
675 const struct host_cmd_ds_command
*resp
)
677 u8
*curr
= (u8
*) &resp
->params
.get_wmm_status
;
678 uint16_t resp_len
= le16_to_cpu(resp
->size
), tlv_len
;
681 struct mwifiex_ie_types_data
*tlv_hdr
;
682 struct mwifiex_ie_types_wmm_queue_status
*tlv_wmm_qstatus
;
683 struct ieee_types_wmm_parameter
*wmm_param_ie
= NULL
;
684 struct mwifiex_wmm_ac_status
*ac_status
;
686 dev_dbg(priv
->adapter
->dev
, "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
689 while ((resp_len
>= sizeof(tlv_hdr
->header
)) && valid
) {
690 tlv_hdr
= (struct mwifiex_ie_types_data
*) curr
;
691 tlv_len
= le16_to_cpu(tlv_hdr
->header
.len
);
693 switch (le16_to_cpu(tlv_hdr
->header
.type
)) {
694 case TLV_TYPE_WMMQSTATUS
:
696 (struct mwifiex_ie_types_wmm_queue_status
*)
698 dev_dbg(priv
->adapter
->dev
,
699 "info: CMD_RESP: WMM_GET_STATUS:"
700 " QSTATUS TLV: %d, %d, %d\n",
701 tlv_wmm_qstatus
->queue_index
,
702 tlv_wmm_qstatus
->flow_required
,
703 tlv_wmm_qstatus
->disabled
);
705 ac_status
= &priv
->wmm
.ac_status
[tlv_wmm_qstatus
->
707 ac_status
->disabled
= tlv_wmm_qstatus
->disabled
;
708 ac_status
->flow_required
=
709 tlv_wmm_qstatus
->flow_required
;
710 ac_status
->flow_created
= tlv_wmm_qstatus
->flow_created
;
713 case WLAN_EID_VENDOR_SPECIFIC
:
715 * Point the regular IEEE IE 2 bytes into the Marvell IE
716 * and setup the IEEE IE type and length byte fields
720 (struct ieee_types_wmm_parameter
*) (curr
+
722 wmm_param_ie
->vend_hdr
.len
= (u8
) tlv_len
;
723 wmm_param_ie
->vend_hdr
.element_id
=
724 WLAN_EID_VENDOR_SPECIFIC
;
726 dev_dbg(priv
->adapter
->dev
,
727 "info: CMD_RESP: WMM_GET_STATUS:"
728 " WMM Parameter Set Count: %d\n",
729 wmm_param_ie
->qos_info_bitmap
&
730 IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK
);
732 memcpy((u8
*) &priv
->curr_bss_params
.bss_descriptor
.
733 wmm_ie
, wmm_param_ie
,
734 wmm_param_ie
->vend_hdr
.len
+ 2);
743 curr
+= (tlv_len
+ sizeof(tlv_hdr
->header
));
744 resp_len
-= (tlv_len
+ sizeof(tlv_hdr
->header
));
747 mwifiex_wmm_setup_queue_priorities(priv
, wmm_param_ie
);
748 mwifiex_wmm_setup_ac_downgrade(priv
);
754 * Callback handler from the command module to allow insertion of a WMM TLV.
756 * If the BSS we are associating to supports WMM, this function adds the
757 * required WMM Information IE to the association request command buffer in
758 * the form of a Marvell extended IEEE IE.
761 mwifiex_wmm_process_association_req(struct mwifiex_private
*priv
,
763 struct ieee_types_wmm_parameter
*wmm_ie
,
764 struct ieee80211_ht_cap
*ht_cap
)
766 struct mwifiex_ie_types_wmm_param_set
*wmm_tlv
;
778 dev_dbg(priv
->adapter
->dev
, "info: WMM: process assoc req:"
780 wmm_ie
->vend_hdr
.element_id
);
782 if ((priv
->wmm_required
783 || (ht_cap
&& (priv
->adapter
->config_bands
& BAND_GN
784 || priv
->adapter
->config_bands
& BAND_AN
))
786 && wmm_ie
->vend_hdr
.element_id
== WLAN_EID_VENDOR_SPECIFIC
) {
787 wmm_tlv
= (struct mwifiex_ie_types_wmm_param_set
*) *assoc_buf
;
788 wmm_tlv
->header
.type
= cpu_to_le16((u16
) wmm_info_ie
[0]);
789 wmm_tlv
->header
.len
= cpu_to_le16((u16
) wmm_info_ie
[1]);
790 memcpy(wmm_tlv
->wmm_ie
, &wmm_info_ie
[2],
791 le16_to_cpu(wmm_tlv
->header
.len
));
792 if (wmm_ie
->qos_info_bitmap
& IEEE80211_WMM_IE_AP_QOSINFO_UAPSD
)
793 memcpy((u8
*) (wmm_tlv
->wmm_ie
794 + le16_to_cpu(wmm_tlv
->header
.len
)
795 - sizeof(priv
->wmm_qosinfo
)),
797 sizeof(priv
->wmm_qosinfo
));
799 ret_len
= sizeof(wmm_tlv
->header
)
800 + le16_to_cpu(wmm_tlv
->header
.len
);
802 *assoc_buf
+= ret_len
;
809 * This function computes the time delay in the driver queues for a
812 * When the packet is received at the OS/Driver interface, the current
813 * time is set in the packet structure. The difference between the present
814 * time and that received time is computed in this function and limited
815 * based on pre-compiled limits in the driver.
818 mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private
*priv
,
819 const struct sk_buff
*skb
)
822 struct timeval out_tstamp
, in_tstamp
;
825 do_gettimeofday(&out_tstamp
);
826 in_tstamp
= ktime_to_timeval(skb
->tstamp
);
828 queue_delay
= (out_tstamp
.tv_sec
- in_tstamp
.tv_sec
) * 1000;
829 queue_delay
+= (out_tstamp
.tv_usec
- in_tstamp
.tv_usec
) / 1000;
832 * Queue delay is passed as a uint8 in units of 2ms (ms shifted
833 * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
835 * Pass max value if queue_delay is beyond the uint8 range
837 ret_val
= (u8
) (min(queue_delay
, priv
->wmm
.drv_pkt_delay_max
) >> 1);
839 dev_dbg(priv
->adapter
->dev
, "data: WMM: Pkt Delay: %d ms,"
840 " %d ms sent to FW\n", queue_delay
, ret_val
);
846 * This function retrieves the highest priority RA list table pointer.
848 static struct mwifiex_ra_list_tbl
*
849 mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter
*adapter
,
850 struct mwifiex_private
**priv
, int *tid
)
852 struct mwifiex_private
*priv_tmp
;
853 struct mwifiex_ra_list_tbl
*ptr
, *head
;
854 struct mwifiex_bss_prio_node
*bssprio_node
, *bssprio_head
;
855 struct mwifiex_tid_tbl
*tid_ptr
;
860 for (j
= adapter
->priv_num
- 1; j
>= 0; --j
) {
861 spin_lock_irqsave(&adapter
->bss_prio_tbl
[j
].bss_prio_lock
,
863 is_list_empty
= list_empty(&adapter
->bss_prio_tbl
[j
]
865 spin_unlock_irqrestore(&adapter
->bss_prio_tbl
[j
].bss_prio_lock
,
870 if (adapter
->bss_prio_tbl
[j
].bss_prio_cur
==
871 (struct mwifiex_bss_prio_node
*)
872 &adapter
->bss_prio_tbl
[j
].bss_prio_head
) {
874 list_first_entry(&adapter
->bss_prio_tbl
[j
]
876 struct mwifiex_bss_prio_node
,
878 bssprio_head
= bssprio_node
;
880 bssprio_node
= adapter
->bss_prio_tbl
[j
].bss_prio_cur
;
881 bssprio_head
= bssprio_node
;
888 priv_tmp
= bssprio_node
->priv
;
889 hqp
= &priv_tmp
->wmm
.highest_queued_prio
;
890 lock
= &priv_tmp
->wmm
.ra_list_spinlock
;
892 for (i
= atomic_read(hqp
); i
>= LOW_PRIO_TID
; --i
) {
894 tid_ptr
= &(priv_tmp
)->wmm
.
895 tid_tbl_ptr
[tos_to_tid
[i
]];
897 spin_lock_irqsave(&tid_ptr
->tid_tbl_lock
,
900 list_empty(&adapter
->bss_prio_tbl
[j
]
902 spin_unlock_irqrestore(&tid_ptr
->tid_tbl_lock
,
908 * Always choose the next ra we transmitted
909 * last time, this way we pick the ra's in
910 * round robin fashion.
912 ptr
= list_first_entry(
913 &tid_ptr
->ra_list_curr
->list
,
914 struct mwifiex_ra_list_tbl
,
918 if (ptr
== (struct mwifiex_ra_list_tbl
*)
921 ptr
= list_first_entry(&ptr
->list
,
922 struct mwifiex_ra_list_tbl
, list
);
928 skb_queue_empty(&ptr
->skb_head
);
929 if (!is_list_empty
) {
930 spin_lock_irqsave(lock
, flags
);
931 if (atomic_read(hqp
) > i
)
933 spin_unlock_irqrestore(lock
,
936 *tid
= tos_to_tid
[i
];
940 ptr
= list_first_entry(&ptr
->list
,
941 struct mwifiex_ra_list_tbl
,
944 (struct mwifiex_ra_list_tbl
*)
946 ptr
= list_first_entry(
948 struct mwifiex_ra_list_tbl
,
950 } while (ptr
!= head
);
953 /* No packet at any TID for this priv. Mark as such
954 * to skip checking TIDs for this priv (until pkt is
957 atomic_set(hqp
, NO_PKT_PRIO_TID
);
959 /* Get next bss priority node */
960 bssprio_node
= list_first_entry(&bssprio_node
->list
,
961 struct mwifiex_bss_prio_node
,
965 (struct mwifiex_bss_prio_node
*)
966 &adapter
->bss_prio_tbl
[j
].bss_prio_head
)
967 /* Get next bss priority node */
968 bssprio_node
= list_first_entry(
970 struct mwifiex_bss_prio_node
,
972 } while (bssprio_node
!= bssprio_head
);
978 * This function sends a single packet to firmware for transmission.
981 mwifiex_send_single_packet(struct mwifiex_private
*priv
,
982 struct mwifiex_ra_list_tbl
*ptr
, int ptr_index
,
983 unsigned long ra_list_flags
)
984 __releases(&priv
->wmm
.ra_list_spinlock
)
986 struct sk_buff
*skb
, *skb_next
;
987 struct mwifiex_tx_param tx_param
;
988 struct mwifiex_adapter
*adapter
= priv
->adapter
;
989 struct mwifiex_txinfo
*tx_info
;
991 if (skb_queue_empty(&ptr
->skb_head
)) {
992 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
994 dev_dbg(adapter
->dev
, "data: nothing to send\n");
998 skb
= skb_dequeue(&ptr
->skb_head
);
1000 tx_info
= MWIFIEX_SKB_TXCB(skb
);
1001 dev_dbg(adapter
->dev
, "data: dequeuing the packet %p %p\n", ptr
, skb
);
1003 ptr
->total_pkts_size
-= skb
->len
;
1006 if (!skb_queue_empty(&ptr
->skb_head
))
1007 skb_next
= skb_peek(&ptr
->skb_head
);
1011 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1013 tx_param
.next_pkt_len
= ((skb_next
) ? skb_next
->len
+
1014 sizeof(struct txpd
) : 0);
1016 if (mwifiex_process_tx(priv
, skb
, &tx_param
) == -EBUSY
) {
1017 /* Queue the packet back at the head */
1018 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1020 if (!mwifiex_is_ralist_valid(priv
, ptr
, ptr_index
)) {
1021 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1023 mwifiex_write_data_complete(adapter
, skb
, -1);
1027 skb_queue_tail(&ptr
->skb_head
, skb
);
1029 ptr
->total_pkts_size
+= skb
->len
;
1031 tx_info
->flags
|= MWIFIEX_BUF_FLAG_REQUEUED_PKT
;
1032 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1035 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1036 if (mwifiex_is_ralist_valid(priv
, ptr
, ptr_index
)) {
1037 priv
->wmm
.packets_out
[ptr_index
]++;
1038 priv
->wmm
.tid_tbl_ptr
[ptr_index
].ra_list_curr
= ptr
;
1040 adapter
->bss_prio_tbl
[priv
->bss_priority
].bss_prio_cur
=
1042 &adapter
->bss_prio_tbl
[priv
->bss_priority
]
1043 .bss_prio_cur
->list
,
1044 struct mwifiex_bss_prio_node
,
1046 atomic_dec(&priv
->wmm
.tx_pkts_queued
);
1047 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1053 * This function checks if the first packet in the given RA list
1054 * is already processed or not.
1057 mwifiex_is_ptr_processed(struct mwifiex_private
*priv
,
1058 struct mwifiex_ra_list_tbl
*ptr
)
1060 struct sk_buff
*skb
;
1061 struct mwifiex_txinfo
*tx_info
;
1063 if (skb_queue_empty(&ptr
->skb_head
))
1066 skb
= skb_peek(&ptr
->skb_head
);
1068 tx_info
= MWIFIEX_SKB_TXCB(skb
);
1069 if (tx_info
->flags
& MWIFIEX_BUF_FLAG_REQUEUED_PKT
)
1076 * This function sends a single processed packet to firmware for
1080 mwifiex_send_processed_packet(struct mwifiex_private
*priv
,
1081 struct mwifiex_ra_list_tbl
*ptr
, int ptr_index
,
1082 unsigned long ra_list_flags
)
1083 __releases(&priv
->wmm
.ra_list_spinlock
)
1085 struct mwifiex_tx_param tx_param
;
1086 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1088 struct sk_buff
*skb
, *skb_next
;
1089 struct mwifiex_txinfo
*tx_info
;
1091 if (skb_queue_empty(&ptr
->skb_head
)) {
1092 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1097 skb
= skb_dequeue(&ptr
->skb_head
);
1099 if (!skb_queue_empty(&ptr
->skb_head
))
1100 skb_next
= skb_peek(&ptr
->skb_head
);
1104 tx_info
= MWIFIEX_SKB_TXCB(skb
);
1106 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1107 tx_param
.next_pkt_len
=
1108 ((skb_next
) ? skb_next
->len
+
1109 sizeof(struct txpd
) : 0);
1110 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_DATA
,
1111 skb
->data
, skb
->len
, &tx_param
);
1114 dev_dbg(adapter
->dev
, "data: -EBUSY is returned\n");
1115 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1117 if (!mwifiex_is_ralist_valid(priv
, ptr
, ptr_index
)) {
1118 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1120 mwifiex_write_data_complete(adapter
, skb
, -1);
1124 skb_queue_tail(&ptr
->skb_head
, skb
);
1126 tx_info
->flags
|= MWIFIEX_BUF_FLAG_REQUEUED_PKT
;
1127 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1131 adapter
->data_sent
= false;
1132 dev_err(adapter
->dev
, "host_to_card failed: %#x\n", ret
);
1133 adapter
->dbg
.num_tx_host_to_card_failure
++;
1134 mwifiex_write_data_complete(adapter
, skb
, ret
);
1137 adapter
->data_sent
= false;
1141 if (ret
!= -EBUSY
) {
1142 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, ra_list_flags
);
1143 if (mwifiex_is_ralist_valid(priv
, ptr
, ptr_index
)) {
1144 priv
->wmm
.packets_out
[ptr_index
]++;
1145 priv
->wmm
.tid_tbl_ptr
[ptr_index
].ra_list_curr
= ptr
;
1147 adapter
->bss_prio_tbl
[priv
->bss_priority
].bss_prio_cur
=
1149 &adapter
->bss_prio_tbl
[priv
->bss_priority
]
1150 .bss_prio_cur
->list
,
1151 struct mwifiex_bss_prio_node
,
1153 atomic_dec(&priv
->wmm
.tx_pkts_queued
);
1154 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
,
1160 * This function dequeues a packet from the highest priority list
1164 mwifiex_dequeue_tx_packet(struct mwifiex_adapter
*adapter
)
1166 struct mwifiex_ra_list_tbl
*ptr
;
1167 struct mwifiex_private
*priv
= NULL
;
1170 int tid_del
= 0, tid
= 0;
1171 unsigned long flags
;
1173 ptr
= mwifiex_wmm_get_highest_priolist_ptr(adapter
, &priv
, &ptr_index
);
1177 tid
= mwifiex_get_tid(ptr
);
1179 dev_dbg(adapter
->dev
, "data: tid=%d\n", tid
);
1181 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, flags
);
1182 if (!mwifiex_is_ralist_valid(priv
, ptr
, ptr_index
)) {
1183 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, flags
);
1187 if (mwifiex_is_ptr_processed(priv
, ptr
)) {
1188 mwifiex_send_processed_packet(priv
, ptr
, ptr_index
, flags
);
1189 /* ra_list_spinlock has been freed in
1190 mwifiex_send_processed_packet() */
1194 if (!ptr
->is_11n_enabled
|| mwifiex_is_ba_stream_setup(priv
, ptr
, tid
)
1195 || ((priv
->sec_info
.wpa_enabled
1196 || priv
->sec_info
.wpa2_enabled
) && !priv
->wpa_is_gtk_set
)
1198 mwifiex_send_single_packet(priv
, ptr
, ptr_index
, flags
);
1199 /* ra_list_spinlock has been freed in
1200 mwifiex_send_single_packet() */
1202 if (mwifiex_is_ampdu_allowed(priv
, tid
)) {
1203 if (mwifiex_space_avail_for_new_ba_stream(adapter
)) {
1204 mwifiex_11n_create_tx_ba_stream_tbl(priv
,
1206 BA_STREAM_SETUP_INPROGRESS
);
1207 mwifiex_send_addba(priv
, tid
, ptr
->ra
);
1208 } else if (mwifiex_find_stream_to_delete
1209 (priv
, tid
, &tid_del
, ra
)) {
1210 mwifiex_11n_create_tx_ba_stream_tbl(priv
,
1212 BA_STREAM_SETUP_INPROGRESS
);
1213 mwifiex_send_delba(priv
, tid_del
, ra
, 1);
1216 /* Minimum number of AMSDU */
1217 #define MIN_NUM_AMSDU 2
1219 if (mwifiex_is_amsdu_allowed(priv
, tid
) &&
1220 (ptr
->total_pkts
>= MIN_NUM_AMSDU
))
1221 mwifiex_11n_aggregate_pkt(priv
, ptr
, INTF_HEADER_LEN
,
1223 /* ra_list_spinlock has been freed in
1224 mwifiex_11n_aggregate_pkt() */
1226 mwifiex_send_single_packet(priv
, ptr
, ptr_index
, flags
);
1227 /* ra_list_spinlock has been freed in
1228 mwifiex_send_single_packet() */
1234 * This function transmits the highest priority packet awaiting in the
1238 mwifiex_wmm_process_tx(struct mwifiex_adapter
*adapter
)
1242 if (adapter
->data_sent
|| adapter
->tx_lock_flag
)
1245 if (mwifiex_dequeue_tx_packet(adapter
))
1247 } while (!mwifiex_wmm_lists_empty(adapter
));