wimax: Remove unnecessary alloc/OOM messages, alloc cleanups
[deliverable/linux.git] / drivers / net / wireless / mwifiex / wmm.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: WMM
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28
29/* Maximum value FW can accept for driver delay in packet transmission */
30#define DRV_PKT_DELAY_TO_FW_MAX 512
31
32
33#define WMM_QUEUED_PACKET_LOWER_LIMIT 180
34
35#define WMM_QUEUED_PACKET_UPPER_LIMIT 200
36
37/* Offset for TOS field in the IP header */
38#define IPTOS_OFFSET 5
39
40/* WMM information IE */
41static const u8 wmm_info_ie[] = { WLAN_EID_VENDOR_SPECIFIC, 0x07,
42 0x00, 0x50, 0xf2, 0x02,
43 0x00, 0x01, 0x00
44};
45
46static const u8 wmm_aci_to_qidx_map[] = { WMM_AC_BE,
47 WMM_AC_BK,
48 WMM_AC_VI,
49 WMM_AC_VO
50};
51
52static 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 */
62};
63
64/*
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.
68 */
69static 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 */
73 0x03,
74 0x04,
75 0x05,
76 0x06,
77 0x07};
78
79static u8 ac_to_tid[4][2] = { {1, 2}, {0, 3}, {4, 5}, {6, 7} };
80
81/*
82 * This function debug prints the priority parameters for a WMM AC.
83 */
84static void
85mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters *ac_param)
86{
87 const char *ac_str[] = { "BK", "BE", "VI", "VO" };
88
89 pr_debug("info: WMM AC_%s: ACI=%d, ACM=%d, Aifsn=%d, "
c65a30f3
YAP
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));
5e6e3a92
BZ
99}
100
101/*
102 * This function allocates a route address list.
103 *
104 * The function also initializes the list with the provided RA.
105 */
106static struct mwifiex_ra_list_tbl *
107mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, u8 *ra)
108{
109 struct mwifiex_ra_list_tbl *ra_list;
110
111 ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC);
112
113 if (!ra_list) {
114 dev_err(adapter->dev, "%s: failed to alloc ra_list\n",
c65a30f3 115 __func__);
5e6e3a92
BZ
116 return NULL;
117 }
118 INIT_LIST_HEAD(&ra_list->list);
119 skb_queue_head_init(&ra_list->skb_head);
120
121 memcpy(ra_list->ra, ra, ETH_ALEN);
122
123 ra_list->total_pkts_size = 0;
124
125 dev_dbg(adapter->dev, "info: allocated ra_list %p\n", ra_list);
126
127 return ra_list;
128}
129
5a009adf
AP
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.
132 */
133static u8 mwifiex_get_random_ba_threshold(void)
134{
135 u32 sec, usec;
136 struct timeval ba_tstamp;
137 u8 ba_threshold;
138
139 /* setup ba_packet_threshold here random number between
140 * [BA_SETUP_PACKET_OFFSET,
141 * BA_SETUP_PACKET_OFFSET+BA_SETUP_MAX_PACKET_THRESHOLD-1]
142 */
143
144 do_gettimeofday(&ba_tstamp);
145 sec = (ba_tstamp.tv_sec & 0xFFFF) + (ba_tstamp.tv_sec >> 16);
146 usec = (ba_tstamp.tv_usec & 0xFFFF) + (ba_tstamp.tv_usec >> 16);
147 ba_threshold = (((sec << 16) + usec) % BA_SETUP_MAX_PACKET_THRESHOLD)
148 + BA_SETUP_PACKET_OFFSET;
149
150 return ba_threshold;
151}
152
5e6e3a92
BZ
153/*
154 * This function allocates and adds a RA list for all TIDs
155 * with the given RA.
156 */
157void
158mwifiex_ralist_add(struct mwifiex_private *priv, u8 *ra)
159{
160 int i;
161 struct mwifiex_ra_list_tbl *ra_list;
162 struct mwifiex_adapter *adapter = priv->adapter;
5a009adf
AP
163 struct mwifiex_sta_node *node;
164 unsigned long flags;
165
166 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
167 node = mwifiex_get_sta_entry(priv, ra);
168 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
5e6e3a92
BZ
169
170 for (i = 0; i < MAX_NUM_TID; ++i) {
171 ra_list = mwifiex_wmm_allocate_ralist_node(adapter, ra);
172 dev_dbg(adapter->dev, "info: created ra_list %p\n", ra_list);
173
174 if (!ra_list)
175 break;
176
5a009adf
AP
177 ra_list->is_11n_enabled = 0;
178 if (!mwifiex_queuing_ra_based(priv)) {
5e6e3a92 179 ra_list->is_11n_enabled = IS_11N_ENABLED(priv);
5a009adf
AP
180 } else {
181 ra_list->is_11n_enabled =
182 mwifiex_is_sta_11n_enabled(priv, node);
183 if (ra_list->is_11n_enabled)
184 ra_list->max_amsdu = node->max_amsdu;
185 }
5e6e3a92
BZ
186
187 dev_dbg(adapter->dev, "data: ralist %p: is_11n_enabled=%d\n",
188 ra_list, ra_list->is_11n_enabled);
189
5a009adf
AP
190 if (ra_list->is_11n_enabled) {
191 ra_list->pkt_count = 0;
192 ra_list->ba_packet_thr =
193 mwifiex_get_random_ba_threshold();
194 }
5e6e3a92 195 list_add_tail(&ra_list->list,
c65a30f3 196 &priv->wmm.tid_tbl_ptr[i].ra_list);
5e6e3a92
BZ
197
198 if (!priv->wmm.tid_tbl_ptr[i].ra_list_curr)
199 priv->wmm.tid_tbl_ptr[i].ra_list_curr = ra_list;
200 }
201}
202
203/*
204 * This function sets the WMM queue priorities to their default values.
205 */
206static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private *priv)
207{
208 /* Default queue priorities: VO->VI->BE->BK */
209 priv->wmm.queue_priority[0] = WMM_AC_VO;
210 priv->wmm.queue_priority[1] = WMM_AC_VI;
211 priv->wmm.queue_priority[2] = WMM_AC_BE;
212 priv->wmm.queue_priority[3] = WMM_AC_BK;
213}
214
215/*
216 * This function map ACs to TIDs.
217 */
218static void
49729ff6 219mwifiex_wmm_queue_priorities_tid(struct mwifiex_wmm_desc *wmm)
5e6e3a92 220{
49729ff6 221 u8 *queue_priority = wmm->queue_priority;
5e6e3a92
BZ
222 int i;
223
224 for (i = 0; i < 4; ++i) {
225 tos_to_tid[7 - (i * 2)] = ac_to_tid[queue_priority[i]][1];
226 tos_to_tid[6 - (i * 2)] = ac_to_tid[queue_priority[i]][0];
227 }
49729ff6
MY
228
229 for (i = 0; i < MAX_NUM_TID; ++i)
230 tos_to_tid_inv[tos_to_tid[i]] = (u8)i;
231
232 atomic_set(&wmm->highest_queued_prio, HIGH_PRIO_TID);
5e6e3a92
BZ
233}
234
235/*
236 * This function initializes WMM priority queues.
237 */
238void
239mwifiex_wmm_setup_queue_priorities(struct mwifiex_private *priv,
240 struct ieee_types_wmm_parameter *wmm_ie)
241{
242 u16 cw_min, avg_back_off, tmp[4];
243 u32 i, j, num_ac;
244 u8 ac_idx;
245
246 if (!wmm_ie || !priv->wmm_enabled) {
247 /* WMM is not enabled, just set the defaults and return */
248 mwifiex_wmm_default_queue_priorities(priv);
249 return;
250 }
251
252 dev_dbg(priv->adapter->dev, "info: WMM Parameter IE: version=%d, "
253 "qos_info Parameter Set Count=%d, Reserved=%#x\n",
254 wmm_ie->vend_hdr.version, wmm_ie->qos_info_bitmap &
255 IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK,
256 wmm_ie->reserved);
257
258 for (num_ac = 0; num_ac < ARRAY_SIZE(wmm_ie->ac_params); num_ac++) {
c65a30f3
YAP
259 u8 ecw = wmm_ie->ac_params[num_ac].ecw_bitmap;
260 u8 aci_aifsn = wmm_ie->ac_params[num_ac].aci_aifsn_bitmap;
261 cw_min = (1 << (ecw & MWIFIEX_ECW_MIN)) - 1;
262 avg_back_off = (cw_min >> 1) + (aci_aifsn & MWIFIEX_AIFSN);
263
264 ac_idx = wmm_aci_to_qidx_map[(aci_aifsn & MWIFIEX_ACI) >> 5];
5e6e3a92
BZ
265 priv->wmm.queue_priority[ac_idx] = ac_idx;
266 tmp[ac_idx] = avg_back_off;
267
c65a30f3
YAP
268 dev_dbg(priv->adapter->dev,
269 "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n",
270 (1 << ((ecw & MWIFIEX_ECW_MAX) >> 4)) - 1,
271 cw_min, avg_back_off);
5e6e3a92
BZ
272 mwifiex_wmm_ac_debug_print(&wmm_ie->ac_params[num_ac]);
273 }
274
275 /* Bubble sort */
276 for (i = 0; i < num_ac; i++) {
277 for (j = 1; j < num_ac - i; j++) {
278 if (tmp[j - 1] > tmp[j]) {
279 swap(tmp[j - 1], tmp[j]);
280 swap(priv->wmm.queue_priority[j - 1],
281 priv->wmm.queue_priority[j]);
282 } else if (tmp[j - 1] == tmp[j]) {
283 if (priv->wmm.queue_priority[j - 1]
284 < priv->wmm.queue_priority[j])
285 swap(priv->wmm.queue_priority[j - 1],
286 priv->wmm.queue_priority[j]);
287 }
288 }
289 }
290
49729ff6 291 mwifiex_wmm_queue_priorities_tid(&priv->wmm);
5e6e3a92
BZ
292}
293
294/*
295 * This function evaluates whether or not an AC is to be downgraded.
296 *
297 * In case the AC is not enabled, the highest AC is returned that is
298 * enabled and does not require admission control.
299 */
300static enum mwifiex_wmm_ac_e
301mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private *priv,
302 enum mwifiex_wmm_ac_e eval_ac)
303{
304 int down_ac;
305 enum mwifiex_wmm_ac_e ret_ac;
306 struct mwifiex_wmm_ac_status *ac_status;
307
308 ac_status = &priv->wmm.ac_status[eval_ac];
309
310 if (!ac_status->disabled)
311 /* Okay to use this AC, its enabled */
312 return eval_ac;
313
314 /* Setup a default return value of the lowest priority */
315 ret_ac = WMM_AC_BK;
316
317 /*
318 * Find the highest AC that is enabled and does not require
319 * admission control. The spec disallows downgrading to an AC,
320 * which is enabled due to a completed admission control.
321 * Unadmitted traffic is not to be sent on an AC with admitted
322 * traffic.
323 */
324 for (down_ac = WMM_AC_BK; down_ac < eval_ac; down_ac++) {
325 ac_status = &priv->wmm.ac_status[down_ac];
326
327 if (!ac_status->disabled && !ac_status->flow_required)
328 /* AC is enabled and does not require admission
329 control */
330 ret_ac = (enum mwifiex_wmm_ac_e) down_ac;
331 }
332
333 return ret_ac;
334}
335
336/*
337 * This function downgrades WMM priority queue.
338 */
339void
340mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private *priv)
341{
342 int ac_val;
343
344 dev_dbg(priv->adapter->dev, "info: WMM: AC Priorities:"
345 "BK(0), BE(1), VI(2), VO(3)\n");
346
347 if (!priv->wmm_enabled) {
348 /* WMM is not enabled, default priorities */
349 for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++)
350 priv->wmm.ac_down_graded_vals[ac_val] =
c65a30f3 351 (enum mwifiex_wmm_ac_e) ac_val;
5e6e3a92
BZ
352 } else {
353 for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) {
354 priv->wmm.ac_down_graded_vals[ac_val]
355 = mwifiex_wmm_eval_downgrade_ac(priv,
356 (enum mwifiex_wmm_ac_e) ac_val);
c65a30f3
YAP
357 dev_dbg(priv->adapter->dev,
358 "info: WMM: AC PRIO %d maps to %d\n",
5e6e3a92
BZ
359 ac_val, priv->wmm.ac_down_graded_vals[ac_val]);
360 }
361 }
362}
363
364/*
365 * This function converts the IP TOS field to an WMM AC
366 * Queue assignment.
367 */
368static enum mwifiex_wmm_ac_e
369mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter *adapter, u32 tos)
370{
371 /* Map of TOS UP values to WMM AC */
372 const enum mwifiex_wmm_ac_e tos_to_ac[] = { WMM_AC_BE,
373 WMM_AC_BK,
374 WMM_AC_BK,
375 WMM_AC_BE,
376 WMM_AC_VI,
377 WMM_AC_VI,
378 WMM_AC_VO,
379 WMM_AC_VO
380 };
381
382 if (tos >= ARRAY_SIZE(tos_to_ac))
383 return WMM_AC_BE;
384
385 return tos_to_ac[tos];
386}
387
388/*
389 * This function evaluates a given TID and downgrades it to a lower
390 * TID if the WMM Parameter IE received from the AP indicates that the
391 * AP is disabled (due to call admission control (ACM bit). Mapping
392 * of TID to AC is taken care of internally.
393 */
394static u8
395mwifiex_wmm_downgrade_tid(struct mwifiex_private *priv, u32 tid)
396{
397 enum mwifiex_wmm_ac_e ac, ac_down;
398 u8 new_tid;
399
400 ac = mwifiex_wmm_convert_tos_to_ac(priv->adapter, tid);
401 ac_down = priv->wmm.ac_down_graded_vals[ac];
402
403 /* Send the index to tid array, picking from the array will be
404 * taken care by dequeuing function
405 */
406 new_tid = ac_to_tid[ac_down][tid % 2];
407
408 return new_tid;
409}
410
411/*
412 * This function initializes the WMM state information and the
413 * WMM data path queues.
414 */
415void
416mwifiex_wmm_init(struct mwifiex_adapter *adapter)
417{
418 int i, j;
419 struct mwifiex_private *priv;
420
421 for (j = 0; j < adapter->priv_num; ++j) {
422 priv = adapter->priv[j];
423 if (!priv)
424 continue;
425
426 for (i = 0; i < MAX_NUM_TID; ++i) {
427 priv->aggr_prio_tbl[i].amsdu = tos_to_tid_inv[i];
428 priv->aggr_prio_tbl[i].ampdu_ap = tos_to_tid_inv[i];
429 priv->aggr_prio_tbl[i].ampdu_user = tos_to_tid_inv[i];
430 priv->wmm.tid_tbl_ptr[i].ra_list_curr = NULL;
431 }
432
433 priv->aggr_prio_tbl[6].amsdu
c65a30f3
YAP
434 = priv->aggr_prio_tbl[6].ampdu_ap
435 = priv->aggr_prio_tbl[6].ampdu_user
436 = BA_STREAM_NOT_ALLOWED;
5e6e3a92
BZ
437
438 priv->aggr_prio_tbl[7].amsdu = priv->aggr_prio_tbl[7].ampdu_ap
c65a30f3
YAP
439 = priv->aggr_prio_tbl[7].ampdu_user
440 = BA_STREAM_NOT_ALLOWED;
5e6e3a92
BZ
441
442 priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
443 priv->add_ba_param.tx_win_size = MWIFIEX_AMPDU_DEF_TXWINSIZE;
444 priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE;
f699254c 445
92583924
SP
446 mwifiex_reset_11n_rx_seq_num(priv);
447
f699254c 448 atomic_set(&priv->wmm.tx_pkts_queued, 0);
49729ff6 449 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
5e6e3a92
BZ
450 }
451}
452
453/*
454 * This function checks if WMM Tx queue is empty.
455 */
456int
457mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter)
458{
f699254c 459 int i;
5e6e3a92
BZ
460 struct mwifiex_private *priv;
461
f699254c
MY
462 for (i = 0; i < adapter->priv_num; ++i) {
463 priv = adapter->priv[i];
464 if (priv && atomic_read(&priv->wmm.tx_pkts_queued))
a8aa69dc 465 return false;
5e6e3a92
BZ
466 }
467
468 return true;
469}
470
471/*
472 * This function deletes all packets in an RA list node.
473 *
474 * The packet sent completion callback handler are called with
475 * status failure, after they are dequeued to ensure proper
476 * cleanup. The RA list node itself is freed at the end.
477 */
478static void
479mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
480 struct mwifiex_ra_list_tbl *ra_list)
481{
482 struct mwifiex_adapter *adapter = priv->adapter;
483 struct sk_buff *skb, *tmp;
484
485 skb_queue_walk_safe(&ra_list->skb_head, skb, tmp)
47411a06 486 mwifiex_write_data_complete(adapter, skb, 0, -1);
5e6e3a92
BZ
487}
488
489/*
490 * This function deletes all packets in an RA list.
491 *
492 * Each nodes in the RA list are freed individually first, and then
493 * the RA list itself is freed.
494 */
495static void
496mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
497 struct list_head *ra_list_head)
498{
499 struct mwifiex_ra_list_tbl *ra_list;
500
501 list_for_each_entry(ra_list, ra_list_head, list)
502 mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
503}
504
505/*
506 * This function deletes all packets in all RA lists.
507 */
508static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
509{
510 int i;
511
512 for (i = 0; i < MAX_NUM_TID; i++)
513 mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
c65a30f3 514 ra_list);
f699254c
MY
515
516 atomic_set(&priv->wmm.tx_pkts_queued, 0);
49729ff6 517 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
5e6e3a92
BZ
518}
519
520/*
521 * This function deletes all route addresses from all RA lists.
522 */
523static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
524{
525 struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
526 int i;
527
528 for (i = 0; i < MAX_NUM_TID; ++i) {
529 dev_dbg(priv->adapter->dev,
c65a30f3 530 "info: ra_list: freeing buf for tid %d\n", i);
5e6e3a92 531 list_for_each_entry_safe(ra_list, tmp_node,
c65a30f3
YAP
532 &priv->wmm.tid_tbl_ptr[i].ra_list,
533 list) {
5e6e3a92
BZ
534 list_del(&ra_list->list);
535 kfree(ra_list);
536 }
537
538 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
539
540 priv->wmm.tid_tbl_ptr[i].ra_list_curr = NULL;
541 }
542}
543
544/*
545 * This function cleans up the Tx and Rx queues.
546 *
547 * Cleanup includes -
548 * - All packets in RA lists
549 * - All entries in Rx reorder table
550 * - All entries in Tx BA stream table
551 * - MPA buffer (if required)
552 * - All RA lists
553 */
554void
555mwifiex_clean_txrx(struct mwifiex_private *priv)
556{
557 unsigned long flags;
558
559 mwifiex_11n_cleanup_reorder_tbl(priv);
560 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
561
562 mwifiex_wmm_cleanup_queues(priv);
563 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
564
565 if (priv->adapter->if_ops.cleanup_mpa_buf)
566 priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
567
568 mwifiex_wmm_delete_all_ralist(priv);
569 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
570
fbd7e7ac
AP
571 if (priv->adapter->if_ops.clean_pcie_ring)
572 priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
5e6e3a92
BZ
573 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
574}
575
576/*
577 * This function retrieves a particular RA list node, matching with the
578 * given TID and RA address.
579 */
580static struct mwifiex_ra_list_tbl *
581mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
582 u8 *ra_addr)
583{
584 struct mwifiex_ra_list_tbl *ra_list;
585
586 list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
587 list) {
588 if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
589 return ra_list;
590 }
591
592 return NULL;
593}
594
595/*
596 * This function retrieves an RA list node for a given TID and
597 * RA address pair.
598 *
599 * If no such node is found, a new node is added first and then
600 * retrieved.
601 */
602static struct mwifiex_ra_list_tbl *
603mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid, u8 *ra_addr)
604{
605 struct mwifiex_ra_list_tbl *ra_list;
606
607 ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
608 if (ra_list)
609 return ra_list;
610 mwifiex_ralist_add(priv, ra_addr);
611
612 return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
613}
614
615/*
616 * This function checks if a particular RA list node exists in a given TID
617 * table index.
618 */
619int
620mwifiex_is_ralist_valid(struct mwifiex_private *priv,
621 struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
622{
623 struct mwifiex_ra_list_tbl *rlist;
624
625 list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
626 list) {
627 if (rlist == ra_list)
628 return true;
629 }
630
631 return false;
632}
633
634/*
635 * This function adds a packet to WMM queue.
636 *
637 * In disconnected state the packet is immediately dropped and the
638 * packet send completion callback is called with status failure.
639 *
640 * Otherwise, the correct RA list node is located and the packet
641 * is queued at the list tail.
642 */
643void
2690e1bb 644mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
5e6e3a92
BZ
645 struct sk_buff *skb)
646{
2690e1bb 647 struct mwifiex_adapter *adapter = priv->adapter;
5e6e3a92
BZ
648 u32 tid;
649 struct mwifiex_ra_list_tbl *ra_list;
650 u8 ra[ETH_ALEN], tid_down;
651 unsigned long flags;
652
e39faa73 653 if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
5e6e3a92 654 dev_dbg(adapter->dev, "data: drop packet in disconnect\n");
47411a06 655 mwifiex_write_data_complete(adapter, skb, 0, -1);
5e6e3a92
BZ
656 return;
657 }
658
659 tid = skb->priority;
660
661 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
662
663 tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
664
665 /* In case of infra as we have already created the list during
666 association we just don't have to call get_queue_raptr, we will
667 have only 1 raptr for a tid in case of infra */
e39faa73
SP
668 if (!mwifiex_queuing_ra_based(priv) &&
669 !mwifiex_is_skb_mgmt_frame(skb)) {
5e6e3a92
BZ
670 if (!list_empty(&priv->wmm.tid_tbl_ptr[tid_down].ra_list))
671 ra_list = list_first_entry(
672 &priv->wmm.tid_tbl_ptr[tid_down].ra_list,
673 struct mwifiex_ra_list_tbl, list);
674 else
675 ra_list = NULL;
676 } else {
677 memcpy(ra, skb->data, ETH_ALEN);
e39faa73 678 if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
4e3c4420 679 memset(ra, 0xff, ETH_ALEN);
5e6e3a92
BZ
680 ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
681 }
682
683 if (!ra_list) {
684 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
47411a06 685 mwifiex_write_data_complete(adapter, skb, 0, -1);
5e6e3a92
BZ
686 return;
687 }
688
689 skb_queue_tail(&ra_list->skb_head, skb);
690
691 ra_list->total_pkts_size += skb->len;
5a009adf 692 ra_list->pkt_count++;
5e6e3a92 693
f699254c
MY
694 atomic_inc(&priv->wmm.tx_pkts_queued);
695
49729ff6
MY
696 if (atomic_read(&priv->wmm.highest_queued_prio) <
697 tos_to_tid_inv[tid_down])
698 atomic_set(&priv->wmm.highest_queued_prio,
c65a30f3 699 tos_to_tid_inv[tid_down]);
49729ff6 700
5e6e3a92
BZ
701 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
702}
703
704/*
705 * This function processes the get WMM status command response from firmware.
706 *
707 * The response may contain multiple TLVs -
708 * - AC Queue status TLVs
709 * - Current WMM Parameter IE TLV
710 * - Admission Control action frame TLVs
711 *
712 * This function parses the TLVs and then calls further specific functions
713 * to process any changes in the queue prioritize or state.
714 */
715int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
716 const struct host_cmd_ds_command *resp)
717{
718 u8 *curr = (u8 *) &resp->params.get_wmm_status;
719 uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
720 int valid = true;
721
722 struct mwifiex_ie_types_data *tlv_hdr;
723 struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
724 struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
725 struct mwifiex_wmm_ac_status *ac_status;
726
727 dev_dbg(priv->adapter->dev, "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
c65a30f3 728 resp_len);
5e6e3a92
BZ
729
730 while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
731 tlv_hdr = (struct mwifiex_ie_types_data *) curr;
732 tlv_len = le16_to_cpu(tlv_hdr->header.len);
733
734 switch (le16_to_cpu(tlv_hdr->header.type)) {
735 case TLV_TYPE_WMMQSTATUS:
736 tlv_wmm_qstatus =
737 (struct mwifiex_ie_types_wmm_queue_status *)
738 tlv_hdr;
739 dev_dbg(priv->adapter->dev,
740 "info: CMD_RESP: WMM_GET_STATUS:"
741 " QSTATUS TLV: %d, %d, %d\n",
c65a30f3
YAP
742 tlv_wmm_qstatus->queue_index,
743 tlv_wmm_qstatus->flow_required,
744 tlv_wmm_qstatus->disabled);
5e6e3a92
BZ
745
746 ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
747 queue_index];
748 ac_status->disabled = tlv_wmm_qstatus->disabled;
749 ac_status->flow_required =
c65a30f3 750 tlv_wmm_qstatus->flow_required;
5e6e3a92
BZ
751 ac_status->flow_created = tlv_wmm_qstatus->flow_created;
752 break;
753
754 case WLAN_EID_VENDOR_SPECIFIC:
755 /*
756 * Point the regular IEEE IE 2 bytes into the Marvell IE
757 * and setup the IEEE IE type and length byte fields
758 */
759
760 wmm_param_ie =
761 (struct ieee_types_wmm_parameter *) (curr +
762 2);
763 wmm_param_ie->vend_hdr.len = (u8) tlv_len;
764 wmm_param_ie->vend_hdr.element_id =
765 WLAN_EID_VENDOR_SPECIFIC;
766
767 dev_dbg(priv->adapter->dev,
768 "info: CMD_RESP: WMM_GET_STATUS:"
769 " WMM Parameter Set Count: %d\n",
770 wmm_param_ie->qos_info_bitmap &
771 IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK);
772
773 memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
774 wmm_ie, wmm_param_ie,
775 wmm_param_ie->vend_hdr.len + 2);
776
777 break;
778
779 default:
780 valid = false;
781 break;
782 }
783
784 curr += (tlv_len + sizeof(tlv_hdr->header));
785 resp_len -= (tlv_len + sizeof(tlv_hdr->header));
786 }
787
788 mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
789 mwifiex_wmm_setup_ac_downgrade(priv);
790
791 return 0;
792}
793
794/*
795 * Callback handler from the command module to allow insertion of a WMM TLV.
796 *
797 * If the BSS we are associating to supports WMM, this function adds the
798 * required WMM Information IE to the association request command buffer in
799 * the form of a Marvell extended IEEE IE.
800 */
801u32
802mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
803 u8 **assoc_buf,
804 struct ieee_types_wmm_parameter *wmm_ie,
805 struct ieee80211_ht_cap *ht_cap)
806{
807 struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
808 u32 ret_len = 0;
809
810 /* Null checks */
811 if (!assoc_buf)
812 return 0;
813 if (!(*assoc_buf))
814 return 0;
815
816 if (!wmm_ie)
817 return 0;
818
c65a30f3
YAP
819 dev_dbg(priv->adapter->dev,
820 "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
821 wmm_ie->vend_hdr.element_id);
5e6e3a92 822
c65a30f3
YAP
823 if ((priv->wmm_required ||
824 (ht_cap && (priv->adapter->config_bands & BAND_GN ||
825 priv->adapter->config_bands & BAND_AN))) &&
826 wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
5e6e3a92
BZ
827 wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
828 wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
829 wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
830 memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
c65a30f3 831 le16_to_cpu(wmm_tlv->header.len));
5e6e3a92
BZ
832 if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
833 memcpy((u8 *) (wmm_tlv->wmm_ie
c65a30f3
YAP
834 + le16_to_cpu(wmm_tlv->header.len)
835 - sizeof(priv->wmm_qosinfo)),
836 &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
5e6e3a92
BZ
837
838 ret_len = sizeof(wmm_tlv->header)
c65a30f3 839 + le16_to_cpu(wmm_tlv->header.len);
5e6e3a92
BZ
840
841 *assoc_buf += ret_len;
842 }
843
844 return ret_len;
845}
846
847/*
848 * This function computes the time delay in the driver queues for a
849 * given packet.
850 *
851 * When the packet is received at the OS/Driver interface, the current
852 * time is set in the packet structure. The difference between the present
853 * time and that received time is computed in this function and limited
854 * based on pre-compiled limits in the driver.
855 */
856u8
857mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
c65a30f3 858 const struct sk_buff *skb)
5e6e3a92 859{
270e58e8 860 u8 ret_val;
5e6e3a92
BZ
861 struct timeval out_tstamp, in_tstamp;
862 u32 queue_delay;
863
864 do_gettimeofday(&out_tstamp);
865 in_tstamp = ktime_to_timeval(skb->tstamp);
866
867 queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) * 1000;
868 queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) / 1000;
869
870 /*
871 * Queue delay is passed as a uint8 in units of 2ms (ms shifted
872 * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
873 *
874 * Pass max value if queue_delay is beyond the uint8 range
875 */
876 ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
877
878 dev_dbg(priv->adapter->dev, "data: WMM: Pkt Delay: %d ms,"
879 " %d ms sent to FW\n", queue_delay, ret_val);
880
881 return ret_val;
882}
883
884/*
885 * This function retrieves the highest priority RA list table pointer.
886 */
887static struct mwifiex_ra_list_tbl *
888mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
889 struct mwifiex_private **priv, int *tid)
890{
891 struct mwifiex_private *priv_tmp;
892 struct mwifiex_ra_list_tbl *ptr, *head;
893 struct mwifiex_bss_prio_node *bssprio_node, *bssprio_head;
894 struct mwifiex_tid_tbl *tid_ptr;
bb7de2ba 895 atomic_t *hqp;
5e6e3a92
BZ
896 int is_list_empty;
897 unsigned long flags;
898 int i, j;
899
900 for (j = adapter->priv_num - 1; j >= 0; --j) {
901 spin_lock_irqsave(&adapter->bss_prio_tbl[j].bss_prio_lock,
c65a30f3 902 flags);
5e6e3a92 903 is_list_empty = list_empty(&adapter->bss_prio_tbl[j]
c65a30f3 904 .bss_prio_head);
5e6e3a92 905 spin_unlock_irqrestore(&adapter->bss_prio_tbl[j].bss_prio_lock,
c65a30f3 906 flags);
5e6e3a92
BZ
907 if (is_list_empty)
908 continue;
909
910 if (adapter->bss_prio_tbl[j].bss_prio_cur ==
911 (struct mwifiex_bss_prio_node *)
912 &adapter->bss_prio_tbl[j].bss_prio_head) {
16051b0e 913 adapter->bss_prio_tbl[j].bss_prio_cur =
5e6e3a92
BZ
914 list_first_entry(&adapter->bss_prio_tbl[j]
915 .bss_prio_head,
916 struct mwifiex_bss_prio_node,
917 list);
5e6e3a92
BZ
918 }
919
16051b0e
AK
920 bssprio_node = adapter->bss_prio_tbl[j].bss_prio_cur;
921 bssprio_head = bssprio_node;
922
5e6e3a92
BZ
923 do {
924 priv_tmp = bssprio_node->priv;
49729ff6 925 hqp = &priv_tmp->wmm.highest_queued_prio;
5e6e3a92 926
49729ff6 927 for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
5e6e3a92
BZ
928
929 tid_ptr = &(priv_tmp)->wmm.
930 tid_tbl_ptr[tos_to_tid[i]];
931
64b05e2f
AP
932 /* For non-STA ra_list_curr may be NULL */
933 if (!tid_ptr->ra_list_curr)
934 continue;
935
5e6e3a92
BZ
936 spin_lock_irqsave(&tid_ptr->tid_tbl_lock,
937 flags);
938 is_list_empty =
939 list_empty(&adapter->bss_prio_tbl[j]
940 .bss_prio_head);
941 spin_unlock_irqrestore(&tid_ptr->tid_tbl_lock,
942 flags);
943 if (is_list_empty)
944 continue;
945
946 /*
947 * Always choose the next ra we transmitted
948 * last time, this way we pick the ra's in
949 * round robin fashion.
950 */
951 ptr = list_first_entry(
952 &tid_ptr->ra_list_curr->list,
953 struct mwifiex_ra_list_tbl,
954 list);
955
956 head = ptr;
957 if (ptr == (struct mwifiex_ra_list_tbl *)
958 &tid_ptr->ra_list) {
959 /* Get next ra */
960 ptr = list_first_entry(&ptr->list,
961 struct mwifiex_ra_list_tbl, list);
962 head = ptr;
963 }
964
965 do {
966 is_list_empty =
967 skb_queue_empty(&ptr->skb_head);
bb7de2ba
YAP
968
969 if (!is_list_empty)
970 goto found;
971
5e6e3a92
BZ
972 /* Get next ra */
973 ptr = list_first_entry(&ptr->list,
974 struct mwifiex_ra_list_tbl,
975 list);
976 if (ptr ==
977 (struct mwifiex_ra_list_tbl *)
978 &tid_ptr->ra_list)
979 ptr = list_first_entry(
980 &ptr->list,
981 struct mwifiex_ra_list_tbl,
982 list);
983 } while (ptr != head);
984 }
985
17e8cec8
MY
986 /* No packet at any TID for this priv. Mark as such
987 * to skip checking TIDs for this priv (until pkt is
988 * added).
989 */
990 atomic_set(hqp, NO_PKT_PRIO_TID);
991
5e6e3a92
BZ
992 /* Get next bss priority node */
993 bssprio_node = list_first_entry(&bssprio_node->list,
994 struct mwifiex_bss_prio_node,
995 list);
996
997 if (bssprio_node ==
998 (struct mwifiex_bss_prio_node *)
999 &adapter->bss_prio_tbl[j].bss_prio_head)
1000 /* Get next bss priority node */
1001 bssprio_node = list_first_entry(
1002 &bssprio_node->list,
1003 struct mwifiex_bss_prio_node,
1004 list);
1005 } while (bssprio_node != bssprio_head);
1006 }
1007 return NULL;
bb7de2ba
YAP
1008
1009found:
1010 spin_lock_irqsave(&priv_tmp->wmm.ra_list_spinlock, flags);
1011 if (atomic_read(hqp) > i)
1012 atomic_set(hqp, i);
1013 spin_unlock_irqrestore(&priv_tmp->wmm.ra_list_spinlock, flags);
1014
1015 *priv = priv_tmp;
1016 *tid = tos_to_tid[i];
1017
1018 return ptr;
5e6e3a92
BZ
1019}
1020
d85c5fe4
AK
1021/*
1022 * This function checks if 11n aggregation is possible.
1023 */
1024static int
1025mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
1026 struct mwifiex_ra_list_tbl *ptr,
1027 int max_buf_size)
1028{
1029 int count = 0, total_size = 0;
1030 struct sk_buff *skb, *tmp;
5a009adf
AP
1031 int max_amsdu_size;
1032
1033 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
1034 ptr->is_11n_enabled)
1035 max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
1036 else
1037 max_amsdu_size = max_buf_size;
d85c5fe4
AK
1038
1039 skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
1040 total_size += skb->len;
5a009adf 1041 if (total_size >= max_amsdu_size)
d85c5fe4
AK
1042 break;
1043 if (++count >= MIN_NUM_AMSDU)
1044 return true;
1045 }
1046
1047 return false;
1048}
1049
5e6e3a92
BZ
1050/*
1051 * This function sends a single packet to firmware for transmission.
1052 */
1053static void
1054mwifiex_send_single_packet(struct mwifiex_private *priv,
1055 struct mwifiex_ra_list_tbl *ptr, int ptr_index,
1056 unsigned long ra_list_flags)
1057 __releases(&priv->wmm.ra_list_spinlock)
1058{
1059 struct sk_buff *skb, *skb_next;
1060 struct mwifiex_tx_param tx_param;
1061 struct mwifiex_adapter *adapter = priv->adapter;
5e6e3a92
BZ
1062 struct mwifiex_txinfo *tx_info;
1063
1064 if (skb_queue_empty(&ptr->skb_head)) {
1065 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1066 ra_list_flags);
1067 dev_dbg(adapter->dev, "data: nothing to send\n");
1068 return;
1069 }
1070
1071 skb = skb_dequeue(&ptr->skb_head);
1072
1073 tx_info = MWIFIEX_SKB_TXCB(skb);
1074 dev_dbg(adapter->dev, "data: dequeuing the packet %p %p\n", ptr, skb);
1075
1076 ptr->total_pkts_size -= skb->len;
1077
1078 if (!skb_queue_empty(&ptr->skb_head))
1079 skb_next = skb_peek(&ptr->skb_head);
1080 else
1081 skb_next = NULL;
1082
1083 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
1084
1085 tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
1086 sizeof(struct txpd) : 0);
1087
636c4598 1088 if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
5e6e3a92
BZ
1089 /* Queue the packet back at the head */
1090 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
1091
1092 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1093 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1094 ra_list_flags);
47411a06 1095 mwifiex_write_data_complete(adapter, skb, 0, -1);
5e6e3a92
BZ
1096 return;
1097 }
1098
1099 skb_queue_tail(&ptr->skb_head, skb);
1100
1101 ptr->total_pkts_size += skb->len;
5a009adf 1102 ptr->pkt_count++;
5e6e3a92
BZ
1103 tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1104 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1105 ra_list_flags);
1106 } else {
1107 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
1108 if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1109 priv->wmm.packets_out[ptr_index]++;
1110 priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
1111 }
1112 adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
1113 list_first_entry(
1114 &adapter->bss_prio_tbl[priv->bss_priority]
1115 .bss_prio_cur->list,
1116 struct mwifiex_bss_prio_node,
1117 list);
f699254c 1118 atomic_dec(&priv->wmm.tx_pkts_queued);
5e6e3a92
BZ
1119 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1120 ra_list_flags);
1121 }
1122}
1123
1124/*
1125 * This function checks if the first packet in the given RA list
1126 * is already processed or not.
1127 */
1128static int
1129mwifiex_is_ptr_processed(struct mwifiex_private *priv,
1130 struct mwifiex_ra_list_tbl *ptr)
1131{
1132 struct sk_buff *skb;
1133 struct mwifiex_txinfo *tx_info;
1134
1135 if (skb_queue_empty(&ptr->skb_head))
1136 return false;
1137
1138 skb = skb_peek(&ptr->skb_head);
1139
1140 tx_info = MWIFIEX_SKB_TXCB(skb);
1141 if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
1142 return true;
1143
1144 return false;
1145}
1146
1147/*
1148 * This function sends a single processed packet to firmware for
1149 * transmission.
1150 */
1151static void
1152mwifiex_send_processed_packet(struct mwifiex_private *priv,
1153 struct mwifiex_ra_list_tbl *ptr, int ptr_index,
1154 unsigned long ra_list_flags)
1155 __releases(&priv->wmm.ra_list_spinlock)
1156{
1157 struct mwifiex_tx_param tx_param;
1158 struct mwifiex_adapter *adapter = priv->adapter;
1159 int ret = -1;
1160 struct sk_buff *skb, *skb_next;
1161 struct mwifiex_txinfo *tx_info;
1162
1163 if (skb_queue_empty(&ptr->skb_head)) {
1164 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1165 ra_list_flags);
1166 return;
1167 }
1168
1169 skb = skb_dequeue(&ptr->skb_head);
1170
1171 if (!skb_queue_empty(&ptr->skb_head))
1172 skb_next = skb_peek(&ptr->skb_head);
1173 else
1174 skb_next = NULL;
1175
1176 tx_info = MWIFIEX_SKB_TXCB(skb);
1177
1178 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
4daffe35
AK
1179
1180 if (adapter->iface_type == MWIFIEX_USB) {
1181 adapter->data_sent = true;
1182 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
1183 skb, NULL);
1184 } else {
1185 tx_param.next_pkt_len =
1186 ((skb_next) ? skb_next->len +
1187 sizeof(struct txpd) : 0);
1188 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
1189 skb, &tx_param);
1190 }
1191
5e6e3a92
BZ
1192 switch (ret) {
1193 case -EBUSY:
1194 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
1195 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
1196
1197 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1198 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1199 ra_list_flags);
47411a06 1200 mwifiex_write_data_complete(adapter, skb, 0, -1);
5e6e3a92
BZ
1201 return;
1202 }
1203
1204 skb_queue_tail(&ptr->skb_head, skb);
1205
1206 tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1207 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1208 ra_list_flags);
1209 break;
1210 case -1:
e7f767a7
AP
1211 if (adapter->iface_type != MWIFIEX_PCIE)
1212 adapter->data_sent = false;
5e6e3a92
BZ
1213 dev_err(adapter->dev, "host_to_card failed: %#x\n", ret);
1214 adapter->dbg.num_tx_host_to_card_failure++;
47411a06 1215 mwifiex_write_data_complete(adapter, skb, 0, ret);
5e6e3a92
BZ
1216 break;
1217 case -EINPROGRESS:
e7f767a7
AP
1218 if (adapter->iface_type != MWIFIEX_PCIE)
1219 adapter->data_sent = false;
5e6e3a92
BZ
1220 default:
1221 break;
1222 }
1223 if (ret != -EBUSY) {
1224 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
1225 if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1226 priv->wmm.packets_out[ptr_index]++;
1227 priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
1228 }
1229 adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
1230 list_first_entry(
1231 &adapter->bss_prio_tbl[priv->bss_priority]
1232 .bss_prio_cur->list,
1233 struct mwifiex_bss_prio_node,
1234 list);
f699254c 1235 atomic_dec(&priv->wmm.tx_pkts_queued);
5e6e3a92
BZ
1236 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1237 ra_list_flags);
1238 }
1239}
1240
1241/*
1242 * This function dequeues a packet from the highest priority list
1243 * and transmits it.
1244 */
1245static int
1246mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
1247{
1248 struct mwifiex_ra_list_tbl *ptr;
1249 struct mwifiex_private *priv = NULL;
1250 int ptr_index = 0;
1251 u8 ra[ETH_ALEN];
1252 int tid_del = 0, tid = 0;
1253 unsigned long flags;
1254
1255 ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
1256 if (!ptr)
1257 return -1;
1258
572e8f3e 1259 tid = mwifiex_get_tid(ptr);
5e6e3a92
BZ
1260
1261 dev_dbg(adapter->dev, "data: tid=%d\n", tid);
1262
1263 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
1264 if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
1265 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
1266 return -1;
1267 }
1268
1269 if (mwifiex_is_ptr_processed(priv, ptr)) {
1270 mwifiex_send_processed_packet(priv, ptr, ptr_index, flags);
1271 /* ra_list_spinlock has been freed in
1272 mwifiex_send_processed_packet() */
1273 return 0;
1274 }
1275
c65a30f3
YAP
1276 if (!ptr->is_11n_enabled ||
1277 mwifiex_is_ba_stream_setup(priv, ptr, tid) ||
f03ba7e9 1278 priv->wps.session_enable ||
c65a30f3
YAP
1279 ((priv->sec_info.wpa_enabled ||
1280 priv->sec_info.wpa2_enabled) &&
1281 !priv->wpa_is_gtk_set)) {
5e6e3a92
BZ
1282 mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
1283 /* ra_list_spinlock has been freed in
1284 mwifiex_send_single_packet() */
1285 } else {
5a009adf
AP
1286 if (mwifiex_is_ampdu_allowed(priv, tid) &&
1287 ptr->pkt_count > ptr->ba_packet_thr) {
53d7938e 1288 if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
3e822635
YAP
1289 mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1290 BA_SETUP_INPROGRESS);
5e6e3a92
BZ
1291 mwifiex_send_addba(priv, tid, ptr->ra);
1292 } else if (mwifiex_find_stream_to_delete
572e8f3e 1293 (priv, tid, &tid_del, ra)) {
3e822635
YAP
1294 mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1295 BA_SETUP_INPROGRESS);
5e6e3a92
BZ
1296 mwifiex_send_delba(priv, tid_del, ra, 1);
1297 }
1298 }
572e8f3e 1299 if (mwifiex_is_amsdu_allowed(priv, tid) &&
d85c5fe4
AK
1300 mwifiex_is_11n_aggragation_possible(priv, ptr,
1301 adapter->tx_buf_size))
5e6e3a92
BZ
1302 mwifiex_11n_aggregate_pkt(priv, ptr, INTF_HEADER_LEN,
1303 ptr_index, flags);
1304 /* ra_list_spinlock has been freed in
1305 mwifiex_11n_aggregate_pkt() */
1306 else
1307 mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
1308 /* ra_list_spinlock has been freed in
1309 mwifiex_send_single_packet() */
1310 }
1311 return 0;
1312}
1313
1314/*
1315 * This function transmits the highest priority packet awaiting in the
1316 * WMM Queues.
1317 */
1318void
1319mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
1320{
1321 do {
1322 /* Check if busy */
1323 if (adapter->data_sent || adapter->tx_lock_flag)
1324 break;
1325
1326 if (mwifiex_dequeue_tx_packet(adapter))
1327 break;
93968147 1328 } while (!mwifiex_wmm_lists_empty(adapter));
5e6e3a92 1329}
This page took 0.338085 seconds and 5 git commands to generate.