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