1*828c91f7SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2277b024eSKalle Valo /*
3932183aaSGanapathi Bhat * NXP Wireless LAN device driver: WMM
4277b024eSKalle Valo *
5932183aaSGanapathi Bhat * Copyright 2011-2020 NXP
6277b024eSKalle Valo */
7277b024eSKalle Valo
8277b024eSKalle Valo #include "decl.h"
9277b024eSKalle Valo #include "ioctl.h"
10277b024eSKalle Valo #include "util.h"
11277b024eSKalle Valo #include "fw.h"
12277b024eSKalle Valo #include "main.h"
13277b024eSKalle Valo #include "wmm.h"
14277b024eSKalle Valo #include "11n.h"
15277b024eSKalle Valo
16277b024eSKalle Valo
17277b024eSKalle Valo /* Maximum value FW can accept for driver delay in packet transmission */
18277b024eSKalle Valo #define DRV_PKT_DELAY_TO_FW_MAX 512
19277b024eSKalle Valo
20277b024eSKalle Valo
21277b024eSKalle Valo #define WMM_QUEUED_PACKET_LOWER_LIMIT 180
22277b024eSKalle Valo
23277b024eSKalle Valo #define WMM_QUEUED_PACKET_UPPER_LIMIT 200
24277b024eSKalle Valo
25277b024eSKalle Valo /* Offset for TOS field in the IP header */
26277b024eSKalle Valo #define IPTOS_OFFSET 5
27277b024eSKalle Valo
28277b024eSKalle Valo static bool disable_tx_amsdu;
29277b024eSKalle Valo module_param(disable_tx_amsdu, bool, 0644);
30277b024eSKalle Valo
31d56ee19aSYueHaibing /* This table inverses the tos_to_tid operation to get a priority
32d56ee19aSYueHaibing * which is in sequential order, and can be compared.
33d56ee19aSYueHaibing * Use this to compare the priority of two different TIDs.
34d56ee19aSYueHaibing */
35d56ee19aSYueHaibing const u8 tos_to_tid_inv[] = {
36d56ee19aSYueHaibing 0x02, /* from tos_to_tid[2] = 0 */
37d56ee19aSYueHaibing 0x00, /* from tos_to_tid[0] = 1 */
38d56ee19aSYueHaibing 0x01, /* from tos_to_tid[1] = 2 */
39d56ee19aSYueHaibing 0x03,
40d56ee19aSYueHaibing 0x04,
41d56ee19aSYueHaibing 0x05,
42d56ee19aSYueHaibing 0x06,
43d56ee19aSYueHaibing 0x07
44d56ee19aSYueHaibing };
45d56ee19aSYueHaibing
46277b024eSKalle Valo /* WMM information IE */
47277b024eSKalle Valo static const u8 wmm_info_ie[] = { WLAN_EID_VENDOR_SPECIFIC, 0x07,
48277b024eSKalle Valo 0x00, 0x50, 0xf2, 0x02,
49277b024eSKalle Valo 0x00, 0x01, 0x00
50277b024eSKalle Valo };
51277b024eSKalle Valo
52277b024eSKalle Valo static const u8 wmm_aci_to_qidx_map[] = { WMM_AC_BE,
53277b024eSKalle Valo WMM_AC_BK,
54277b024eSKalle Valo WMM_AC_VI,
55277b024eSKalle Valo WMM_AC_VO
56277b024eSKalle Valo };
57277b024eSKalle Valo
58277b024eSKalle Valo static u8 tos_to_tid[] = {
59277b024eSKalle Valo /* TID DSCP_P2 DSCP_P1 DSCP_P0 WMM_AC */
60277b024eSKalle Valo 0x01, /* 0 1 0 AC_BK */
61277b024eSKalle Valo 0x02, /* 0 0 0 AC_BK */
62277b024eSKalle Valo 0x00, /* 0 0 1 AC_BE */
63277b024eSKalle Valo 0x03, /* 0 1 1 AC_BE */
64277b024eSKalle Valo 0x04, /* 1 0 0 AC_VI */
65277b024eSKalle Valo 0x05, /* 1 0 1 AC_VI */
66277b024eSKalle Valo 0x06, /* 1 1 0 AC_VO */
67277b024eSKalle Valo 0x07 /* 1 1 1 AC_VO */
68277b024eSKalle Valo };
69277b024eSKalle Valo
70277b024eSKalle Valo static u8 ac_to_tid[4][2] = { {1, 2}, {0, 3}, {4, 5}, {6, 7} };
71277b024eSKalle Valo
72277b024eSKalle Valo /*
73277b024eSKalle Valo * This function debug prints the priority parameters for a WMM AC.
74277b024eSKalle Valo */
75277b024eSKalle Valo static void
mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters * ac_param)76277b024eSKalle Valo mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters *ac_param)
77277b024eSKalle Valo {
78277b024eSKalle Valo const char *ac_str[] = { "BK", "BE", "VI", "VO" };
79277b024eSKalle Valo
80277b024eSKalle Valo pr_debug("info: WMM AC_%s: ACI=%d, ACM=%d, Aifsn=%d, "
81277b024eSKalle Valo "EcwMin=%d, EcwMax=%d, TxopLimit=%d\n",
82277b024eSKalle Valo ac_str[wmm_aci_to_qidx_map[(ac_param->aci_aifsn_bitmap
83277b024eSKalle Valo & MWIFIEX_ACI) >> 5]],
84277b024eSKalle Valo (ac_param->aci_aifsn_bitmap & MWIFIEX_ACI) >> 5,
85277b024eSKalle Valo (ac_param->aci_aifsn_bitmap & MWIFIEX_ACM) >> 4,
86277b024eSKalle Valo ac_param->aci_aifsn_bitmap & MWIFIEX_AIFSN,
87277b024eSKalle Valo ac_param->ecw_bitmap & MWIFIEX_ECW_MIN,
88277b024eSKalle Valo (ac_param->ecw_bitmap & MWIFIEX_ECW_MAX) >> 4,
89277b024eSKalle Valo le16_to_cpu(ac_param->tx_op_limit));
90277b024eSKalle Valo }
91277b024eSKalle Valo
92277b024eSKalle Valo /*
93277b024eSKalle Valo * This function allocates a route address list.
94277b024eSKalle Valo *
95277b024eSKalle Valo * The function also initializes the list with the provided RA.
96277b024eSKalle Valo */
97277b024eSKalle Valo static struct mwifiex_ra_list_tbl *
mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter * adapter,const u8 * ra)98277b024eSKalle Valo mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, const u8 *ra)
99277b024eSKalle Valo {
100277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
101277b024eSKalle Valo
102277b024eSKalle Valo ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC);
103277b024eSKalle Valo if (!ra_list)
104277b024eSKalle Valo return NULL;
105277b024eSKalle Valo
106277b024eSKalle Valo INIT_LIST_HEAD(&ra_list->list);
107277b024eSKalle Valo skb_queue_head_init(&ra_list->skb_head);
108277b024eSKalle Valo
109277b024eSKalle Valo memcpy(ra_list->ra, ra, ETH_ALEN);
110277b024eSKalle Valo
111277b024eSKalle Valo ra_list->total_pkt_count = 0;
112277b024eSKalle Valo
113277b024eSKalle Valo mwifiex_dbg(adapter, INFO, "info: allocated ra_list %p\n", ra_list);
114277b024eSKalle Valo
115277b024eSKalle Valo return ra_list;
116277b024eSKalle Valo }
117277b024eSKalle Valo
118277b024eSKalle Valo /* This function returns random no between 16 and 32 to be used as threshold
119277b024eSKalle Valo * for no of packets after which BA setup is initiated.
120277b024eSKalle Valo */
mwifiex_get_random_ba_threshold(void)121277b024eSKalle Valo static u8 mwifiex_get_random_ba_threshold(void)
122277b024eSKalle Valo {
123277b024eSKalle Valo u64 ns;
124277b024eSKalle Valo /* setup ba_packet_threshold here random number between
125277b024eSKalle Valo * [BA_SETUP_PACKET_OFFSET,
126277b024eSKalle Valo * BA_SETUP_PACKET_OFFSET+BA_SETUP_MAX_PACKET_THRESHOLD-1]
127277b024eSKalle Valo */
128277b024eSKalle Valo ns = ktime_get_ns();
129277b024eSKalle Valo ns += (ns >> 32) + (ns >> 16);
130277b024eSKalle Valo
131277b024eSKalle Valo return ((u8)ns % BA_SETUP_MAX_PACKET_THRESHOLD) + BA_SETUP_PACKET_OFFSET;
132277b024eSKalle Valo }
133277b024eSKalle Valo
134277b024eSKalle Valo /*
135277b024eSKalle Valo * This function allocates and adds a RA list for all TIDs
136277b024eSKalle Valo * with the given RA.
137277b024eSKalle Valo */
mwifiex_ralist_add(struct mwifiex_private * priv,const u8 * ra)138277b024eSKalle Valo void mwifiex_ralist_add(struct mwifiex_private *priv, const u8 *ra)
139277b024eSKalle Valo {
140277b024eSKalle Valo int i;
141277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
142277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
143277b024eSKalle Valo struct mwifiex_sta_node *node;
144277b024eSKalle Valo
145277b024eSKalle Valo
146277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
147277b024eSKalle Valo ra_list = mwifiex_wmm_allocate_ralist_node(adapter, ra);
148277b024eSKalle Valo mwifiex_dbg(adapter, INFO,
149277b024eSKalle Valo "info: created ra_list %p\n", ra_list);
150277b024eSKalle Valo
151277b024eSKalle Valo if (!ra_list)
152277b024eSKalle Valo break;
153277b024eSKalle Valo
154277b024eSKalle Valo ra_list->is_11n_enabled = 0;
155277b024eSKalle Valo ra_list->tdls_link = false;
156277b024eSKalle Valo ra_list->ba_status = BA_SETUP_NONE;
157277b024eSKalle Valo ra_list->amsdu_in_ampdu = false;
158277b024eSKalle Valo if (!mwifiex_queuing_ra_based(priv)) {
159277b024eSKalle Valo if (mwifiex_is_tdls_link_setup
160277b024eSKalle Valo (mwifiex_get_tdls_link_status(priv, ra))) {
161277b024eSKalle Valo ra_list->tdls_link = true;
162277b024eSKalle Valo ra_list->is_11n_enabled =
163277b024eSKalle Valo mwifiex_tdls_peer_11n_enabled(priv, ra);
164277b024eSKalle Valo } else {
165277b024eSKalle Valo ra_list->is_11n_enabled = IS_11N_ENABLED(priv);
166277b024eSKalle Valo }
167277b024eSKalle Valo } else {
1688a7f9fd8SBrian Norris spin_lock_bh(&priv->sta_list_spinlock);
169277b024eSKalle Valo node = mwifiex_get_sta_entry(priv, ra);
170277b024eSKalle Valo if (node)
171277b024eSKalle Valo ra_list->tx_paused = node->tx_pause;
172277b024eSKalle Valo ra_list->is_11n_enabled =
173277b024eSKalle Valo mwifiex_is_sta_11n_enabled(priv, node);
174277b024eSKalle Valo if (ra_list->is_11n_enabled)
175277b024eSKalle Valo ra_list->max_amsdu = node->max_amsdu;
1768a7f9fd8SBrian Norris spin_unlock_bh(&priv->sta_list_spinlock);
177277b024eSKalle Valo }
178277b024eSKalle Valo
179277b024eSKalle Valo mwifiex_dbg(adapter, DATA, "data: ralist %p: is_11n_enabled=%d\n",
180277b024eSKalle Valo ra_list, ra_list->is_11n_enabled);
181277b024eSKalle Valo
182277b024eSKalle Valo if (ra_list->is_11n_enabled) {
183277b024eSKalle Valo ra_list->ba_pkt_count = 0;
184277b024eSKalle Valo ra_list->ba_packet_thr =
185277b024eSKalle Valo mwifiex_get_random_ba_threshold();
186277b024eSKalle Valo }
187277b024eSKalle Valo list_add_tail(&ra_list->list,
188277b024eSKalle Valo &priv->wmm.tid_tbl_ptr[i].ra_list);
189277b024eSKalle Valo }
190277b024eSKalle Valo }
191277b024eSKalle Valo
192277b024eSKalle Valo /*
193277b024eSKalle Valo * This function sets the WMM queue priorities to their default values.
194277b024eSKalle Valo */
mwifiex_wmm_default_queue_priorities(struct mwifiex_private * priv)195277b024eSKalle Valo static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private *priv)
196277b024eSKalle Valo {
197277b024eSKalle Valo /* Default queue priorities: VO->VI->BE->BK */
198277b024eSKalle Valo priv->wmm.queue_priority[0] = WMM_AC_VO;
199277b024eSKalle Valo priv->wmm.queue_priority[1] = WMM_AC_VI;
200277b024eSKalle Valo priv->wmm.queue_priority[2] = WMM_AC_BE;
201277b024eSKalle Valo priv->wmm.queue_priority[3] = WMM_AC_BK;
202277b024eSKalle Valo }
203277b024eSKalle Valo
204277b024eSKalle Valo /*
205277b024eSKalle Valo * This function map ACs to TIDs.
206277b024eSKalle Valo */
207277b024eSKalle Valo static void
mwifiex_wmm_queue_priorities_tid(struct mwifiex_private * priv)208277b024eSKalle Valo mwifiex_wmm_queue_priorities_tid(struct mwifiex_private *priv)
209277b024eSKalle Valo {
210277b024eSKalle Valo struct mwifiex_wmm_desc *wmm = &priv->wmm;
211277b024eSKalle Valo u8 *queue_priority = wmm->queue_priority;
212277b024eSKalle Valo int i;
213277b024eSKalle Valo
214277b024eSKalle Valo for (i = 0; i < 4; ++i) {
215277b024eSKalle Valo tos_to_tid[7 - (i * 2)] = ac_to_tid[queue_priority[i]][1];
216277b024eSKalle Valo tos_to_tid[6 - (i * 2)] = ac_to_tid[queue_priority[i]][0];
217277b024eSKalle Valo }
218277b024eSKalle Valo
219277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i)
220277b024eSKalle Valo priv->tos_to_tid_inv[tos_to_tid[i]] = (u8)i;
221277b024eSKalle Valo
222277b024eSKalle Valo atomic_set(&wmm->highest_queued_prio, HIGH_PRIO_TID);
223277b024eSKalle Valo }
224277b024eSKalle Valo
225277b024eSKalle Valo /*
226277b024eSKalle Valo * This function initializes WMM priority queues.
227277b024eSKalle Valo */
228277b024eSKalle Valo void
mwifiex_wmm_setup_queue_priorities(struct mwifiex_private * priv,struct ieee_types_wmm_parameter * wmm_ie)229277b024eSKalle Valo mwifiex_wmm_setup_queue_priorities(struct mwifiex_private *priv,
230277b024eSKalle Valo struct ieee_types_wmm_parameter *wmm_ie)
231277b024eSKalle Valo {
232277b024eSKalle Valo u16 cw_min, avg_back_off, tmp[4];
233277b024eSKalle Valo u32 i, j, num_ac;
234277b024eSKalle Valo u8 ac_idx;
235277b024eSKalle Valo
236277b024eSKalle Valo if (!wmm_ie || !priv->wmm_enabled) {
237277b024eSKalle Valo /* WMM is not enabled, just set the defaults and return */
238277b024eSKalle Valo mwifiex_wmm_default_queue_priorities(priv);
239277b024eSKalle Valo return;
240277b024eSKalle Valo }
241277b024eSKalle Valo
242277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
243277b024eSKalle Valo "info: WMM Parameter IE: version=%d,\t"
244277b024eSKalle Valo "qos_info Parameter Set Count=%d, Reserved=%#x\n",
24563d7ef36SBrian Norris wmm_ie->version, wmm_ie->qos_info_bitmap &
246277b024eSKalle Valo IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK,
247277b024eSKalle Valo wmm_ie->reserved);
248277b024eSKalle Valo
249277b024eSKalle Valo for (num_ac = 0; num_ac < ARRAY_SIZE(wmm_ie->ac_params); num_ac++) {
250277b024eSKalle Valo u8 ecw = wmm_ie->ac_params[num_ac].ecw_bitmap;
251277b024eSKalle Valo u8 aci_aifsn = wmm_ie->ac_params[num_ac].aci_aifsn_bitmap;
252277b024eSKalle Valo cw_min = (1 << (ecw & MWIFIEX_ECW_MIN)) - 1;
253277b024eSKalle Valo avg_back_off = (cw_min >> 1) + (aci_aifsn & MWIFIEX_AIFSN);
254277b024eSKalle Valo
255277b024eSKalle Valo ac_idx = wmm_aci_to_qidx_map[(aci_aifsn & MWIFIEX_ACI) >> 5];
256277b024eSKalle Valo priv->wmm.queue_priority[ac_idx] = ac_idx;
257277b024eSKalle Valo tmp[ac_idx] = avg_back_off;
258277b024eSKalle Valo
259277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
260277b024eSKalle Valo "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n",
261277b024eSKalle Valo (1 << ((ecw & MWIFIEX_ECW_MAX) >> 4)) - 1,
262277b024eSKalle Valo cw_min, avg_back_off);
263277b024eSKalle Valo mwifiex_wmm_ac_debug_print(&wmm_ie->ac_params[num_ac]);
264277b024eSKalle Valo }
265277b024eSKalle Valo
266277b024eSKalle Valo /* Bubble sort */
267277b024eSKalle Valo for (i = 0; i < num_ac; i++) {
268277b024eSKalle Valo for (j = 1; j < num_ac - i; j++) {
269277b024eSKalle Valo if (tmp[j - 1] > tmp[j]) {
270277b024eSKalle Valo swap(tmp[j - 1], tmp[j]);
271277b024eSKalle Valo swap(priv->wmm.queue_priority[j - 1],
272277b024eSKalle Valo priv->wmm.queue_priority[j]);
273277b024eSKalle Valo } else if (tmp[j - 1] == tmp[j]) {
274277b024eSKalle Valo if (priv->wmm.queue_priority[j - 1]
275277b024eSKalle Valo < priv->wmm.queue_priority[j])
276277b024eSKalle Valo swap(priv->wmm.queue_priority[j - 1],
277277b024eSKalle Valo priv->wmm.queue_priority[j]);
278277b024eSKalle Valo }
279277b024eSKalle Valo }
280277b024eSKalle Valo }
281277b024eSKalle Valo
282277b024eSKalle Valo mwifiex_wmm_queue_priorities_tid(priv);
283277b024eSKalle Valo }
284277b024eSKalle Valo
285277b024eSKalle Valo /*
286277b024eSKalle Valo * This function evaluates whether or not an AC is to be downgraded.
287277b024eSKalle Valo *
288277b024eSKalle Valo * In case the AC is not enabled, the highest AC is returned that is
289277b024eSKalle Valo * enabled and does not require admission control.
290277b024eSKalle Valo */
291277b024eSKalle Valo static enum mwifiex_wmm_ac_e
mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private * priv,enum mwifiex_wmm_ac_e eval_ac)292277b024eSKalle Valo mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private *priv,
293277b024eSKalle Valo enum mwifiex_wmm_ac_e eval_ac)
294277b024eSKalle Valo {
295277b024eSKalle Valo int down_ac;
296277b024eSKalle Valo enum mwifiex_wmm_ac_e ret_ac;
297277b024eSKalle Valo struct mwifiex_wmm_ac_status *ac_status;
298277b024eSKalle Valo
299277b024eSKalle Valo ac_status = &priv->wmm.ac_status[eval_ac];
300277b024eSKalle Valo
301277b024eSKalle Valo if (!ac_status->disabled)
302277b024eSKalle Valo /* Okay to use this AC, its enabled */
303277b024eSKalle Valo return eval_ac;
304277b024eSKalle Valo
305277b024eSKalle Valo /* Setup a default return value of the lowest priority */
306277b024eSKalle Valo ret_ac = WMM_AC_BK;
307277b024eSKalle Valo
308277b024eSKalle Valo /*
309277b024eSKalle Valo * Find the highest AC that is enabled and does not require
310277b024eSKalle Valo * admission control. The spec disallows downgrading to an AC,
311277b024eSKalle Valo * which is enabled due to a completed admission control.
312277b024eSKalle Valo * Unadmitted traffic is not to be sent on an AC with admitted
313277b024eSKalle Valo * traffic.
314277b024eSKalle Valo */
315277b024eSKalle Valo for (down_ac = WMM_AC_BK; down_ac < eval_ac; down_ac++) {
316277b024eSKalle Valo ac_status = &priv->wmm.ac_status[down_ac];
317277b024eSKalle Valo
318277b024eSKalle Valo if (!ac_status->disabled && !ac_status->flow_required)
319277b024eSKalle Valo /* AC is enabled and does not require admission
320277b024eSKalle Valo control */
321277b024eSKalle Valo ret_ac = (enum mwifiex_wmm_ac_e) down_ac;
322277b024eSKalle Valo }
323277b024eSKalle Valo
324277b024eSKalle Valo return ret_ac;
325277b024eSKalle Valo }
326277b024eSKalle Valo
327277b024eSKalle Valo /*
328277b024eSKalle Valo * This function downgrades WMM priority queue.
329277b024eSKalle Valo */
330277b024eSKalle Valo void
mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private * priv)331277b024eSKalle Valo mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private *priv)
332277b024eSKalle Valo {
333277b024eSKalle Valo int ac_val;
334277b024eSKalle Valo
335277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO, "info: WMM: AC Priorities:\t"
336277b024eSKalle Valo "BK(0), BE(1), VI(2), VO(3)\n");
337277b024eSKalle Valo
338277b024eSKalle Valo if (!priv->wmm_enabled) {
339277b024eSKalle Valo /* WMM is not enabled, default priorities */
340277b024eSKalle Valo for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++)
341277b024eSKalle Valo priv->wmm.ac_down_graded_vals[ac_val] =
342277b024eSKalle Valo (enum mwifiex_wmm_ac_e) ac_val;
343277b024eSKalle Valo } else {
344277b024eSKalle Valo for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) {
345277b024eSKalle Valo priv->wmm.ac_down_graded_vals[ac_val]
346277b024eSKalle Valo = mwifiex_wmm_eval_downgrade_ac(priv,
347277b024eSKalle Valo (enum mwifiex_wmm_ac_e) ac_val);
348277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
349277b024eSKalle Valo "info: WMM: AC PRIO %d maps to %d\n",
350277b024eSKalle Valo ac_val,
351277b024eSKalle Valo priv->wmm.ac_down_graded_vals[ac_val]);
352277b024eSKalle Valo }
353277b024eSKalle Valo }
354277b024eSKalle Valo }
355277b024eSKalle Valo
356277b024eSKalle Valo /*
357277b024eSKalle Valo * This function converts the IP TOS field to an WMM AC
358277b024eSKalle Valo * Queue assignment.
359277b024eSKalle Valo */
360277b024eSKalle Valo static enum mwifiex_wmm_ac_e
mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter * adapter,u32 tos)361277b024eSKalle Valo mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter *adapter, u32 tos)
362277b024eSKalle Valo {
363277b024eSKalle Valo /* Map of TOS UP values to WMM AC */
3647dfb0ebdSColin Ian King static const enum mwifiex_wmm_ac_e tos_to_ac[] = {
3657dfb0ebdSColin Ian King WMM_AC_BE,
366277b024eSKalle Valo WMM_AC_BK,
367277b024eSKalle Valo WMM_AC_BK,
368277b024eSKalle Valo WMM_AC_BE,
369277b024eSKalle Valo WMM_AC_VI,
370277b024eSKalle Valo WMM_AC_VI,
371277b024eSKalle Valo WMM_AC_VO,
372277b024eSKalle Valo WMM_AC_VO
373277b024eSKalle Valo };
374277b024eSKalle Valo
375277b024eSKalle Valo if (tos >= ARRAY_SIZE(tos_to_ac))
376277b024eSKalle Valo return WMM_AC_BE;
377277b024eSKalle Valo
378277b024eSKalle Valo return tos_to_ac[tos];
379277b024eSKalle Valo }
380277b024eSKalle Valo
381277b024eSKalle Valo /*
382277b024eSKalle Valo * This function evaluates a given TID and downgrades it to a lower
383277b024eSKalle Valo * TID if the WMM Parameter IE received from the AP indicates that the
384277b024eSKalle Valo * AP is disabled (due to call admission control (ACM bit). Mapping
385277b024eSKalle Valo * of TID to AC is taken care of internally.
386277b024eSKalle Valo */
mwifiex_wmm_downgrade_tid(struct mwifiex_private * priv,u32 tid)387277b024eSKalle Valo u8 mwifiex_wmm_downgrade_tid(struct mwifiex_private *priv, u32 tid)
388277b024eSKalle Valo {
389277b024eSKalle Valo enum mwifiex_wmm_ac_e ac, ac_down;
390277b024eSKalle Valo u8 new_tid;
391277b024eSKalle Valo
392277b024eSKalle Valo ac = mwifiex_wmm_convert_tos_to_ac(priv->adapter, tid);
393277b024eSKalle Valo ac_down = priv->wmm.ac_down_graded_vals[ac];
394277b024eSKalle Valo
395277b024eSKalle Valo /* Send the index to tid array, picking from the array will be
396277b024eSKalle Valo * taken care by dequeuing function
397277b024eSKalle Valo */
398277b024eSKalle Valo new_tid = ac_to_tid[ac_down][tid % 2];
399277b024eSKalle Valo
400277b024eSKalle Valo return new_tid;
401277b024eSKalle Valo }
402277b024eSKalle Valo
403277b024eSKalle Valo /*
404277b024eSKalle Valo * This function initializes the WMM state information and the
405277b024eSKalle Valo * WMM data path queues.
406277b024eSKalle Valo */
407277b024eSKalle Valo void
mwifiex_wmm_init(struct mwifiex_adapter * adapter)408277b024eSKalle Valo mwifiex_wmm_init(struct mwifiex_adapter *adapter)
409277b024eSKalle Valo {
410277b024eSKalle Valo int i, j;
411277b024eSKalle Valo struct mwifiex_private *priv;
412277b024eSKalle Valo
413277b024eSKalle Valo for (j = 0; j < adapter->priv_num; ++j) {
414277b024eSKalle Valo priv = adapter->priv[j];
415277b024eSKalle Valo if (!priv)
416277b024eSKalle Valo continue;
417277b024eSKalle Valo
418277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
419277b024eSKalle Valo if (!disable_tx_amsdu &&
420277b024eSKalle Valo adapter->tx_buf_size > MWIFIEX_TX_DATA_BUF_SIZE_2K)
421277b024eSKalle Valo priv->aggr_prio_tbl[i].amsdu =
422277b024eSKalle Valo priv->tos_to_tid_inv[i];
423277b024eSKalle Valo else
424277b024eSKalle Valo priv->aggr_prio_tbl[i].amsdu =
425277b024eSKalle Valo BA_STREAM_NOT_ALLOWED;
426277b024eSKalle Valo priv->aggr_prio_tbl[i].ampdu_ap =
427277b024eSKalle Valo priv->tos_to_tid_inv[i];
428277b024eSKalle Valo priv->aggr_prio_tbl[i].ampdu_user =
429277b024eSKalle Valo priv->tos_to_tid_inv[i];
430277b024eSKalle Valo }
431277b024eSKalle Valo
432277b024eSKalle Valo priv->aggr_prio_tbl[6].amsdu
433277b024eSKalle Valo = priv->aggr_prio_tbl[6].ampdu_ap
434277b024eSKalle Valo = priv->aggr_prio_tbl[6].ampdu_user
435277b024eSKalle Valo = BA_STREAM_NOT_ALLOWED;
436277b024eSKalle Valo
437277b024eSKalle Valo priv->aggr_prio_tbl[7].amsdu = priv->aggr_prio_tbl[7].ampdu_ap
438277b024eSKalle Valo = priv->aggr_prio_tbl[7].ampdu_user
439277b024eSKalle Valo = BA_STREAM_NOT_ALLOWED;
440277b024eSKalle Valo
441277b024eSKalle Valo mwifiex_set_ba_params(priv);
442277b024eSKalle Valo mwifiex_reset_11n_rx_seq_num(priv);
443277b024eSKalle Valo
4446970cd44SXinming Hu priv->wmm.drv_pkt_delay_max = MWIFIEX_WMM_DRV_DELAY_MAX;
445277b024eSKalle Valo atomic_set(&priv->wmm.tx_pkts_queued, 0);
446277b024eSKalle Valo atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
447277b024eSKalle Valo }
448277b024eSKalle Valo }
449277b024eSKalle Valo
mwifiex_bypass_txlist_empty(struct mwifiex_adapter * adapter)450277b024eSKalle Valo int mwifiex_bypass_txlist_empty(struct mwifiex_adapter *adapter)
451277b024eSKalle Valo {
452277b024eSKalle Valo struct mwifiex_private *priv;
453277b024eSKalle Valo int i;
454277b024eSKalle Valo
455277b024eSKalle Valo for (i = 0; i < adapter->priv_num; i++) {
456277b024eSKalle Valo priv = adapter->priv[i];
457277b024eSKalle Valo if (!priv)
458277b024eSKalle Valo continue;
459277b024eSKalle Valo if (adapter->if_ops.is_port_ready &&
460277b024eSKalle Valo !adapter->if_ops.is_port_ready(priv))
461277b024eSKalle Valo continue;
462277b024eSKalle Valo if (!skb_queue_empty(&priv->bypass_txq))
463277b024eSKalle Valo return false;
464277b024eSKalle Valo }
465277b024eSKalle Valo
466277b024eSKalle Valo return true;
467277b024eSKalle Valo }
468277b024eSKalle Valo
469277b024eSKalle Valo /*
470277b024eSKalle Valo * This function checks if WMM Tx queue is empty.
471277b024eSKalle Valo */
472277b024eSKalle Valo int
mwifiex_wmm_lists_empty(struct mwifiex_adapter * adapter)473277b024eSKalle Valo mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter)
474277b024eSKalle Valo {
475277b024eSKalle Valo int i;
476277b024eSKalle Valo struct mwifiex_private *priv;
477277b024eSKalle Valo
478277b024eSKalle Valo for (i = 0; i < adapter->priv_num; ++i) {
479277b024eSKalle Valo priv = adapter->priv[i];
480277b024eSKalle Valo if (!priv)
481277b024eSKalle Valo continue;
482dc386ce7Schunfan chen if (!priv->port_open &&
483dc386ce7Schunfan chen (priv->bss_mode != NL80211_IFTYPE_ADHOC))
484277b024eSKalle Valo continue;
485277b024eSKalle Valo if (adapter->if_ops.is_port_ready &&
486277b024eSKalle Valo !adapter->if_ops.is_port_ready(priv))
487277b024eSKalle Valo continue;
488277b024eSKalle Valo if (atomic_read(&priv->wmm.tx_pkts_queued))
489277b024eSKalle Valo return false;
490277b024eSKalle Valo }
491277b024eSKalle Valo
492277b024eSKalle Valo return true;
493277b024eSKalle Valo }
494277b024eSKalle Valo
495277b024eSKalle Valo /*
496277b024eSKalle Valo * This function deletes all packets in an RA list node.
497277b024eSKalle Valo *
498277b024eSKalle Valo * The packet sent completion callback handler are called with
499277b024eSKalle Valo * status failure, after they are dequeued to ensure proper
500277b024eSKalle Valo * cleanup. The RA list node itself is freed at the end.
501277b024eSKalle Valo */
502277b024eSKalle Valo static void
mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ra_list)503277b024eSKalle Valo mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
504277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list)
505277b024eSKalle Valo {
506277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
507277b024eSKalle Valo struct sk_buff *skb, *tmp;
508277b024eSKalle Valo
509c44c0403SAmitkumar Karwar skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) {
510c44c0403SAmitkumar Karwar skb_unlink(skb, &ra_list->skb_head);
511277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, -1);
512277b024eSKalle Valo }
513c44c0403SAmitkumar Karwar }
514277b024eSKalle Valo
515277b024eSKalle Valo /*
516277b024eSKalle Valo * This function deletes all packets in an RA list.
517277b024eSKalle Valo *
518277b024eSKalle Valo * Each nodes in the RA list are freed individually first, and then
519277b024eSKalle Valo * the RA list itself is freed.
520277b024eSKalle Valo */
521277b024eSKalle Valo static void
mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private * priv,struct list_head * ra_list_head)522277b024eSKalle Valo mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
523277b024eSKalle Valo struct list_head *ra_list_head)
524277b024eSKalle Valo {
525277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
526277b024eSKalle Valo
527277b024eSKalle Valo list_for_each_entry(ra_list, ra_list_head, list)
528277b024eSKalle Valo mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
529277b024eSKalle Valo }
530277b024eSKalle Valo
531277b024eSKalle Valo /*
532277b024eSKalle Valo * This function deletes all packets in all RA lists.
533277b024eSKalle Valo */
mwifiex_wmm_cleanup_queues(struct mwifiex_private * priv)534277b024eSKalle Valo static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
535277b024eSKalle Valo {
536277b024eSKalle Valo int i;
537277b024eSKalle Valo
538277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; i++)
539277b024eSKalle Valo mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
540277b024eSKalle Valo ra_list);
541277b024eSKalle Valo
542277b024eSKalle Valo atomic_set(&priv->wmm.tx_pkts_queued, 0);
543277b024eSKalle Valo atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
544277b024eSKalle Valo }
545277b024eSKalle Valo
546277b024eSKalle Valo /*
547277b024eSKalle Valo * This function deletes all route addresses from all RA lists.
548277b024eSKalle Valo */
mwifiex_wmm_delete_all_ralist(struct mwifiex_private * priv)549277b024eSKalle Valo static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
550277b024eSKalle Valo {
551277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
552277b024eSKalle Valo int i;
553277b024eSKalle Valo
554277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
555277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
556277b024eSKalle Valo "info: ra_list: freeing buf for tid %d\n", i);
557277b024eSKalle Valo list_for_each_entry_safe(ra_list, tmp_node,
558277b024eSKalle Valo &priv->wmm.tid_tbl_ptr[i].ra_list,
559277b024eSKalle Valo list) {
560277b024eSKalle Valo list_del(&ra_list->list);
561277b024eSKalle Valo kfree(ra_list);
562277b024eSKalle Valo }
563277b024eSKalle Valo
564277b024eSKalle Valo INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
565277b024eSKalle Valo }
566277b024eSKalle Valo }
567277b024eSKalle Valo
mwifiex_free_ack_frame(int id,void * p,void * data)568277b024eSKalle Valo static int mwifiex_free_ack_frame(int id, void *p, void *data)
569277b024eSKalle Valo {
570277b024eSKalle Valo pr_warn("Have pending ack frames!\n");
571277b024eSKalle Valo kfree_skb(p);
572277b024eSKalle Valo return 0;
573277b024eSKalle Valo }
574277b024eSKalle Valo
575277b024eSKalle Valo /*
576277b024eSKalle Valo * This function cleans up the Tx and Rx queues.
577277b024eSKalle Valo *
578277b024eSKalle Valo * Cleanup includes -
579277b024eSKalle Valo * - All packets in RA lists
580277b024eSKalle Valo * - All entries in Rx reorder table
581277b024eSKalle Valo * - All entries in Tx BA stream table
582277b024eSKalle Valo * - MPA buffer (if required)
583277b024eSKalle Valo * - All RA lists
584277b024eSKalle Valo */
585277b024eSKalle Valo void
mwifiex_clean_txrx(struct mwifiex_private * priv)586277b024eSKalle Valo mwifiex_clean_txrx(struct mwifiex_private *priv)
587277b024eSKalle Valo {
588277b024eSKalle Valo struct sk_buff *skb, *tmp;
589277b024eSKalle Valo
590277b024eSKalle Valo mwifiex_11n_cleanup_reorder_tbl(priv);
5918a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
592277b024eSKalle Valo
593277b024eSKalle Valo mwifiex_wmm_cleanup_queues(priv);
594277b024eSKalle Valo mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
595277b024eSKalle Valo
596277b024eSKalle Valo if (priv->adapter->if_ops.cleanup_mpa_buf)
597277b024eSKalle Valo priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
598277b024eSKalle Valo
599277b024eSKalle Valo mwifiex_wmm_delete_all_ralist(priv);
600277b024eSKalle Valo memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
601277b024eSKalle Valo
602277b024eSKalle Valo if (priv->adapter->if_ops.clean_pcie_ring &&
603fc3a2fcaSGanapathi Bhat !test_bit(MWIFIEX_SURPRISE_REMOVED, &priv->adapter->work_flags))
604277b024eSKalle Valo priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
6058a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
606277b024eSKalle Valo
607c44c0403SAmitkumar Karwar skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
608c44c0403SAmitkumar Karwar skb_unlink(skb, &priv->tdls_txq);
609277b024eSKalle Valo mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
610c44c0403SAmitkumar Karwar }
611277b024eSKalle Valo
612c44c0403SAmitkumar Karwar skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
613c44c0403SAmitkumar Karwar skb_unlink(skb, &priv->bypass_txq);
614277b024eSKalle Valo mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
615c44c0403SAmitkumar Karwar }
616277b024eSKalle Valo atomic_set(&priv->adapter->bypass_tx_pending, 0);
617277b024eSKalle Valo
618277b024eSKalle Valo idr_for_each(&priv->ack_status_frames, mwifiex_free_ack_frame, NULL);
619277b024eSKalle Valo idr_destroy(&priv->ack_status_frames);
620277b024eSKalle Valo }
621277b024eSKalle Valo
622277b024eSKalle Valo /*
623277b024eSKalle Valo * This function retrieves a particular RA list node, matching with the
624277b024eSKalle Valo * given TID and RA address.
625277b024eSKalle Valo */
626277b024eSKalle Valo struct mwifiex_ra_list_tbl *
mwifiex_wmm_get_ralist_node(struct mwifiex_private * priv,u8 tid,const u8 * ra_addr)627277b024eSKalle Valo mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
628277b024eSKalle Valo const u8 *ra_addr)
629277b024eSKalle Valo {
630277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
631277b024eSKalle Valo
632277b024eSKalle Valo list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
633277b024eSKalle Valo list) {
634277b024eSKalle Valo if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
635277b024eSKalle Valo return ra_list;
636277b024eSKalle Valo }
637277b024eSKalle Valo
638277b024eSKalle Valo return NULL;
639277b024eSKalle Valo }
640277b024eSKalle Valo
mwifiex_update_ralist_tx_pause(struct mwifiex_private * priv,u8 * mac,u8 tx_pause)641277b024eSKalle Valo void mwifiex_update_ralist_tx_pause(struct mwifiex_private *priv, u8 *mac,
642277b024eSKalle Valo u8 tx_pause)
643277b024eSKalle Valo {
644277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
645277b024eSKalle Valo u32 pkt_cnt = 0, tx_pkts_queued;
646277b024eSKalle Valo int i;
647277b024eSKalle Valo
6488a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
649277b024eSKalle Valo
650277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
651277b024eSKalle Valo ra_list = mwifiex_wmm_get_ralist_node(priv, i, mac);
652277b024eSKalle Valo if (ra_list && ra_list->tx_paused != tx_pause) {
653277b024eSKalle Valo pkt_cnt += ra_list->total_pkt_count;
654277b024eSKalle Valo ra_list->tx_paused = tx_pause;
655277b024eSKalle Valo if (tx_pause)
656277b024eSKalle Valo priv->wmm.pkts_paused[i] +=
657277b024eSKalle Valo ra_list->total_pkt_count;
658277b024eSKalle Valo else
659277b024eSKalle Valo priv->wmm.pkts_paused[i] -=
660277b024eSKalle Valo ra_list->total_pkt_count;
661277b024eSKalle Valo }
662277b024eSKalle Valo }
663277b024eSKalle Valo
664277b024eSKalle Valo if (pkt_cnt) {
665277b024eSKalle Valo tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
666277b024eSKalle Valo if (tx_pause)
667277b024eSKalle Valo tx_pkts_queued -= pkt_cnt;
668277b024eSKalle Valo else
669277b024eSKalle Valo tx_pkts_queued += pkt_cnt;
670277b024eSKalle Valo
671277b024eSKalle Valo atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
672277b024eSKalle Valo atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
673277b024eSKalle Valo }
6748a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
675277b024eSKalle Valo }
676277b024eSKalle Valo
67708a7e621SMasahiro Yamada /* This function updates non-tdls peer ralist tx_pause while
67808a7e621SMasahiro Yamada * tdls channel switching
679277b024eSKalle Valo */
mwifiex_update_ralist_tx_pause_in_tdls_cs(struct mwifiex_private * priv,u8 * mac,u8 tx_pause)680277b024eSKalle Valo void mwifiex_update_ralist_tx_pause_in_tdls_cs(struct mwifiex_private *priv,
681277b024eSKalle Valo u8 *mac, u8 tx_pause)
682277b024eSKalle Valo {
683277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
684277b024eSKalle Valo u32 pkt_cnt = 0, tx_pkts_queued;
685277b024eSKalle Valo int i;
686277b024eSKalle Valo
6878a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
688277b024eSKalle Valo
689277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
690277b024eSKalle Valo list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[i].ra_list,
691277b024eSKalle Valo list) {
692277b024eSKalle Valo if (!memcmp(ra_list->ra, mac, ETH_ALEN))
693277b024eSKalle Valo continue;
694277b024eSKalle Valo
695277b024eSKalle Valo if (ra_list->tx_paused != tx_pause) {
696277b024eSKalle Valo pkt_cnt += ra_list->total_pkt_count;
697277b024eSKalle Valo ra_list->tx_paused = tx_pause;
698277b024eSKalle Valo if (tx_pause)
699277b024eSKalle Valo priv->wmm.pkts_paused[i] +=
700277b024eSKalle Valo ra_list->total_pkt_count;
701277b024eSKalle Valo else
702277b024eSKalle Valo priv->wmm.pkts_paused[i] -=
703277b024eSKalle Valo ra_list->total_pkt_count;
704277b024eSKalle Valo }
705277b024eSKalle Valo }
706277b024eSKalle Valo }
707277b024eSKalle Valo
708277b024eSKalle Valo if (pkt_cnt) {
709277b024eSKalle Valo tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
710277b024eSKalle Valo if (tx_pause)
711277b024eSKalle Valo tx_pkts_queued -= pkt_cnt;
712277b024eSKalle Valo else
713277b024eSKalle Valo tx_pkts_queued += pkt_cnt;
714277b024eSKalle Valo
715277b024eSKalle Valo atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
716277b024eSKalle Valo atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
717277b024eSKalle Valo }
7188a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
719277b024eSKalle Valo }
720277b024eSKalle Valo
721277b024eSKalle Valo /*
722277b024eSKalle Valo * This function retrieves an RA list node for a given TID and
723277b024eSKalle Valo * RA address pair.
724277b024eSKalle Valo *
725277b024eSKalle Valo * If no such node is found, a new node is added first and then
726277b024eSKalle Valo * retrieved.
727277b024eSKalle Valo */
728277b024eSKalle Valo struct mwifiex_ra_list_tbl *
mwifiex_wmm_get_queue_raptr(struct mwifiex_private * priv,u8 tid,const u8 * ra_addr)729277b024eSKalle Valo mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid,
730277b024eSKalle Valo const u8 *ra_addr)
731277b024eSKalle Valo {
732277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
733277b024eSKalle Valo
734277b024eSKalle Valo ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
735277b024eSKalle Valo if (ra_list)
736277b024eSKalle Valo return ra_list;
737277b024eSKalle Valo mwifiex_ralist_add(priv, ra_addr);
738277b024eSKalle Valo
739277b024eSKalle Valo return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
740277b024eSKalle Valo }
741277b024eSKalle Valo
742277b024eSKalle Valo /*
743277b024eSKalle Valo * This function deletes RA list nodes for given mac for all TIDs.
744277b024eSKalle Valo * Function also decrements TX pending count accordingly.
745277b024eSKalle Valo */
746277b024eSKalle Valo void
mwifiex_wmm_del_peer_ra_list(struct mwifiex_private * priv,const u8 * ra_addr)747277b024eSKalle Valo mwifiex_wmm_del_peer_ra_list(struct mwifiex_private *priv, const u8 *ra_addr)
748277b024eSKalle Valo {
749277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
750277b024eSKalle Valo int i;
751277b024eSKalle Valo
7528a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
753277b024eSKalle Valo
754277b024eSKalle Valo for (i = 0; i < MAX_NUM_TID; ++i) {
755277b024eSKalle Valo ra_list = mwifiex_wmm_get_ralist_node(priv, i, ra_addr);
756277b024eSKalle Valo
757277b024eSKalle Valo if (!ra_list)
758277b024eSKalle Valo continue;
759277b024eSKalle Valo mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
760277b024eSKalle Valo if (ra_list->tx_paused)
761277b024eSKalle Valo priv->wmm.pkts_paused[i] -= ra_list->total_pkt_count;
762277b024eSKalle Valo else
763277b024eSKalle Valo atomic_sub(ra_list->total_pkt_count,
764277b024eSKalle Valo &priv->wmm.tx_pkts_queued);
765277b024eSKalle Valo list_del(&ra_list->list);
766277b024eSKalle Valo kfree(ra_list);
767277b024eSKalle Valo }
7688a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
769277b024eSKalle Valo }
770277b024eSKalle Valo
771277b024eSKalle Valo /*
772277b024eSKalle Valo * This function checks if a particular RA list node exists in a given TID
773277b024eSKalle Valo * table index.
774277b024eSKalle Valo */
775277b024eSKalle Valo int
mwifiex_is_ralist_valid(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ra_list,int ptr_index)776277b024eSKalle Valo mwifiex_is_ralist_valid(struct mwifiex_private *priv,
777277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
778277b024eSKalle Valo {
779277b024eSKalle Valo struct mwifiex_ra_list_tbl *rlist;
780277b024eSKalle Valo
781277b024eSKalle Valo list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
782277b024eSKalle Valo list) {
783277b024eSKalle Valo if (rlist == ra_list)
784277b024eSKalle Valo return true;
785277b024eSKalle Valo }
786277b024eSKalle Valo
787277b024eSKalle Valo return false;
788277b024eSKalle Valo }
789277b024eSKalle Valo
790277b024eSKalle Valo /*
791277b024eSKalle Valo * This function adds a packet to bypass TX queue.
792277b024eSKalle Valo * This is special TX queue for packets which can be sent even when port_open
793277b024eSKalle Valo * is false.
794277b024eSKalle Valo */
795277b024eSKalle Valo void
mwifiex_wmm_add_buf_bypass_txqueue(struct mwifiex_private * priv,struct sk_buff * skb)796277b024eSKalle Valo mwifiex_wmm_add_buf_bypass_txqueue(struct mwifiex_private *priv,
797277b024eSKalle Valo struct sk_buff *skb)
798277b024eSKalle Valo {
799277b024eSKalle Valo skb_queue_tail(&priv->bypass_txq, skb);
800277b024eSKalle Valo }
801277b024eSKalle Valo
802277b024eSKalle Valo /*
803277b024eSKalle Valo * This function adds a packet to WMM queue.
804277b024eSKalle Valo *
805277b024eSKalle Valo * In disconnected state the packet is immediately dropped and the
806277b024eSKalle Valo * packet send completion callback is called with status failure.
807277b024eSKalle Valo *
808277b024eSKalle Valo * Otherwise, the correct RA list node is located and the packet
809277b024eSKalle Valo * is queued at the list tail.
810277b024eSKalle Valo */
811277b024eSKalle Valo void
mwifiex_wmm_add_buf_txqueue(struct mwifiex_private * priv,struct sk_buff * skb)812277b024eSKalle Valo mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
813277b024eSKalle Valo struct sk_buff *skb)
814277b024eSKalle Valo {
815277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
816277b024eSKalle Valo u32 tid;
817277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra_list;
818277b024eSKalle Valo u8 ra[ETH_ALEN], tid_down;
819277b024eSKalle Valo struct list_head list_head;
820277b024eSKalle Valo int tdls_status = TDLS_NOT_SETUP;
821277b024eSKalle Valo struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
822277b024eSKalle Valo struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
823277b024eSKalle Valo
824277b024eSKalle Valo memcpy(ra, eth_hdr->h_dest, ETH_ALEN);
825277b024eSKalle Valo
826277b024eSKalle Valo if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
827277b024eSKalle Valo ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) {
828277b024eSKalle Valo if (ntohs(eth_hdr->h_proto) == ETH_P_TDLS)
829277b024eSKalle Valo mwifiex_dbg(adapter, DATA,
830277b024eSKalle Valo "TDLS setup packet for %pM.\t"
831277b024eSKalle Valo "Don't block\n", ra);
832277b024eSKalle Valo else if (memcmp(priv->cfg_bssid, ra, ETH_ALEN))
833277b024eSKalle Valo tdls_status = mwifiex_get_tdls_link_status(priv, ra);
834277b024eSKalle Valo }
835277b024eSKalle Valo
836277b024eSKalle Valo if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
837277b024eSKalle Valo mwifiex_dbg(adapter, DATA, "data: drop packet in disconnect\n");
838277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, -1);
839277b024eSKalle Valo return;
840277b024eSKalle Valo }
841277b024eSKalle Valo
842277b024eSKalle Valo tid = skb->priority;
843277b024eSKalle Valo
8448a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
845277b024eSKalle Valo
846277b024eSKalle Valo tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
847277b024eSKalle Valo
848277b024eSKalle Valo /* In case of infra as we have already created the list during
849277b024eSKalle Valo association we just don't have to call get_queue_raptr, we will
850277b024eSKalle Valo have only 1 raptr for a tid in case of infra */
851277b024eSKalle Valo if (!mwifiex_queuing_ra_based(priv) &&
852277b024eSKalle Valo !mwifiex_is_skb_mgmt_frame(skb)) {
853277b024eSKalle Valo switch (tdls_status) {
854277b024eSKalle Valo case TDLS_SETUP_COMPLETE:
855277b024eSKalle Valo case TDLS_CHAN_SWITCHING:
856277b024eSKalle Valo case TDLS_IN_BASE_CHAN:
857277b024eSKalle Valo case TDLS_IN_OFF_CHAN:
858277b024eSKalle Valo ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down,
859277b024eSKalle Valo ra);
860277b024eSKalle Valo tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
861277b024eSKalle Valo break;
862277b024eSKalle Valo case TDLS_SETUP_INPROGRESS:
863277b024eSKalle Valo skb_queue_tail(&priv->tdls_txq, skb);
8648a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
865277b024eSKalle Valo return;
866277b024eSKalle Valo default:
867277b024eSKalle Valo list_head = priv->wmm.tid_tbl_ptr[tid_down].ra_list;
86801926202SShawn Lin ra_list = list_first_entry_or_null(&list_head,
86901926202SShawn Lin struct mwifiex_ra_list_tbl, list);
870277b024eSKalle Valo break;
871277b024eSKalle Valo }
872277b024eSKalle Valo } else {
873277b024eSKalle Valo memcpy(ra, skb->data, ETH_ALEN);
874277b024eSKalle Valo if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
875277b024eSKalle Valo eth_broadcast_addr(ra);
876277b024eSKalle Valo ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
877277b024eSKalle Valo }
878277b024eSKalle Valo
879277b024eSKalle Valo if (!ra_list) {
8808a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
881277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, -1);
882277b024eSKalle Valo return;
883277b024eSKalle Valo }
884277b024eSKalle Valo
885277b024eSKalle Valo skb_queue_tail(&ra_list->skb_head, skb);
886277b024eSKalle Valo
887277b024eSKalle Valo ra_list->ba_pkt_count++;
888277b024eSKalle Valo ra_list->total_pkt_count++;
889277b024eSKalle Valo
890277b024eSKalle Valo if (atomic_read(&priv->wmm.highest_queued_prio) <
891277b024eSKalle Valo priv->tos_to_tid_inv[tid_down])
892277b024eSKalle Valo atomic_set(&priv->wmm.highest_queued_prio,
893277b024eSKalle Valo priv->tos_to_tid_inv[tid_down]);
894277b024eSKalle Valo
895277b024eSKalle Valo if (ra_list->tx_paused)
896277b024eSKalle Valo priv->wmm.pkts_paused[tid_down]++;
897277b024eSKalle Valo else
898277b024eSKalle Valo atomic_inc(&priv->wmm.tx_pkts_queued);
899277b024eSKalle Valo
9008a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
901277b024eSKalle Valo }
902277b024eSKalle Valo
903277b024eSKalle Valo /*
904277b024eSKalle Valo * This function processes the get WMM status command response from firmware.
905277b024eSKalle Valo *
906277b024eSKalle Valo * The response may contain multiple TLVs -
907277b024eSKalle Valo * - AC Queue status TLVs
908277b024eSKalle Valo * - Current WMM Parameter IE TLV
909277b024eSKalle Valo * - Admission Control action frame TLVs
910277b024eSKalle Valo *
911277b024eSKalle Valo * This function parses the TLVs and then calls further specific functions
912277b024eSKalle Valo * to process any changes in the queue prioritize or state.
913277b024eSKalle Valo */
mwifiex_ret_wmm_get_status(struct mwifiex_private * priv,const struct host_cmd_ds_command * resp)914277b024eSKalle Valo int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
915277b024eSKalle Valo const struct host_cmd_ds_command *resp)
916277b024eSKalle Valo {
917277b024eSKalle Valo u8 *curr = (u8 *) &resp->params.get_wmm_status;
918277b024eSKalle Valo uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
919277b024eSKalle Valo int mask = IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK;
920277b024eSKalle Valo bool valid = true;
921277b024eSKalle Valo
922277b024eSKalle Valo struct mwifiex_ie_types_data *tlv_hdr;
923277b024eSKalle Valo struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
924277b024eSKalle Valo struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
925277b024eSKalle Valo struct mwifiex_wmm_ac_status *ac_status;
926277b024eSKalle Valo
927277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
928277b024eSKalle Valo "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
929277b024eSKalle Valo resp_len);
930277b024eSKalle Valo
931277b024eSKalle Valo while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
932277b024eSKalle Valo tlv_hdr = (struct mwifiex_ie_types_data *) curr;
933277b024eSKalle Valo tlv_len = le16_to_cpu(tlv_hdr->header.len);
934277b024eSKalle Valo
935277b024eSKalle Valo if (resp_len < tlv_len + sizeof(tlv_hdr->header))
936277b024eSKalle Valo break;
937277b024eSKalle Valo
938277b024eSKalle Valo switch (le16_to_cpu(tlv_hdr->header.type)) {
939277b024eSKalle Valo case TLV_TYPE_WMMQSTATUS:
940277b024eSKalle Valo tlv_wmm_qstatus =
941277b024eSKalle Valo (struct mwifiex_ie_types_wmm_queue_status *)
942277b024eSKalle Valo tlv_hdr;
943277b024eSKalle Valo mwifiex_dbg(priv->adapter, CMD,
944277b024eSKalle Valo "info: CMD_RESP: WMM_GET_STATUS:\t"
945277b024eSKalle Valo "QSTATUS TLV: %d, %d, %d\n",
946277b024eSKalle Valo tlv_wmm_qstatus->queue_index,
947277b024eSKalle Valo tlv_wmm_qstatus->flow_required,
948277b024eSKalle Valo tlv_wmm_qstatus->disabled);
949277b024eSKalle Valo
950277b024eSKalle Valo ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
951277b024eSKalle Valo queue_index];
952277b024eSKalle Valo ac_status->disabled = tlv_wmm_qstatus->disabled;
953277b024eSKalle Valo ac_status->flow_required =
954277b024eSKalle Valo tlv_wmm_qstatus->flow_required;
955277b024eSKalle Valo ac_status->flow_created = tlv_wmm_qstatus->flow_created;
956277b024eSKalle Valo break;
957277b024eSKalle Valo
958277b024eSKalle Valo case WLAN_EID_VENDOR_SPECIFIC:
959277b024eSKalle Valo /*
960277b024eSKalle Valo * Point the regular IEEE IE 2 bytes into the Marvell IE
961277b024eSKalle Valo * and setup the IEEE IE type and length byte fields
962277b024eSKalle Valo */
963277b024eSKalle Valo
964277b024eSKalle Valo wmm_param_ie =
965277b024eSKalle Valo (struct ieee_types_wmm_parameter *) (curr +
966277b024eSKalle Valo 2);
967277b024eSKalle Valo wmm_param_ie->vend_hdr.len = (u8) tlv_len;
968277b024eSKalle Valo wmm_param_ie->vend_hdr.element_id =
969277b024eSKalle Valo WLAN_EID_VENDOR_SPECIFIC;
970277b024eSKalle Valo
971277b024eSKalle Valo mwifiex_dbg(priv->adapter, CMD,
972277b024eSKalle Valo "info: CMD_RESP: WMM_GET_STATUS:\t"
973277b024eSKalle Valo "WMM Parameter Set Count: %d\n",
974277b024eSKalle Valo wmm_param_ie->qos_info_bitmap & mask);
975277b024eSKalle Valo
9763a9b153cSQing Xu if (wmm_param_ie->vend_hdr.len + 2 >
9773a9b153cSQing Xu sizeof(struct ieee_types_wmm_parameter))
9783a9b153cSQing Xu break;
9793a9b153cSQing Xu
980277b024eSKalle Valo memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
981277b024eSKalle Valo wmm_ie, wmm_param_ie,
982277b024eSKalle Valo wmm_param_ie->vend_hdr.len + 2);
983277b024eSKalle Valo
984277b024eSKalle Valo break;
985277b024eSKalle Valo
986277b024eSKalle Valo default:
987277b024eSKalle Valo valid = false;
988277b024eSKalle Valo break;
989277b024eSKalle Valo }
990277b024eSKalle Valo
991277b024eSKalle Valo curr += (tlv_len + sizeof(tlv_hdr->header));
992277b024eSKalle Valo resp_len -= (tlv_len + sizeof(tlv_hdr->header));
993277b024eSKalle Valo }
994277b024eSKalle Valo
995277b024eSKalle Valo mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
996277b024eSKalle Valo mwifiex_wmm_setup_ac_downgrade(priv);
997277b024eSKalle Valo
998277b024eSKalle Valo return 0;
999277b024eSKalle Valo }
1000277b024eSKalle Valo
1001277b024eSKalle Valo /*
1002277b024eSKalle Valo * Callback handler from the command module to allow insertion of a WMM TLV.
1003277b024eSKalle Valo *
1004277b024eSKalle Valo * If the BSS we are associating to supports WMM, this function adds the
1005277b024eSKalle Valo * required WMM Information IE to the association request command buffer in
1006277b024eSKalle Valo * the form of a Marvell extended IEEE IE.
1007277b024eSKalle Valo */
1008277b024eSKalle Valo u32
mwifiex_wmm_process_association_req(struct mwifiex_private * priv,u8 ** assoc_buf,struct ieee_types_wmm_parameter * wmm_ie,struct ieee80211_ht_cap * ht_cap)1009277b024eSKalle Valo mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
1010277b024eSKalle Valo u8 **assoc_buf,
1011277b024eSKalle Valo struct ieee_types_wmm_parameter *wmm_ie,
1012277b024eSKalle Valo struct ieee80211_ht_cap *ht_cap)
1013277b024eSKalle Valo {
1014277b024eSKalle Valo struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
1015277b024eSKalle Valo u32 ret_len = 0;
1016277b024eSKalle Valo
1017277b024eSKalle Valo /* Null checks */
1018277b024eSKalle Valo if (!assoc_buf)
1019277b024eSKalle Valo return 0;
1020277b024eSKalle Valo if (!(*assoc_buf))
1021277b024eSKalle Valo return 0;
1022277b024eSKalle Valo
1023277b024eSKalle Valo if (!wmm_ie)
1024277b024eSKalle Valo return 0;
1025277b024eSKalle Valo
1026277b024eSKalle Valo mwifiex_dbg(priv->adapter, INFO,
1027277b024eSKalle Valo "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
1028277b024eSKalle Valo wmm_ie->vend_hdr.element_id);
1029277b024eSKalle Valo
1030277b024eSKalle Valo if ((priv->wmm_required ||
1031277b024eSKalle Valo (ht_cap && (priv->adapter->config_bands & BAND_GN ||
1032277b024eSKalle Valo priv->adapter->config_bands & BAND_AN))) &&
1033277b024eSKalle Valo wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
1034277b024eSKalle Valo wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
1035277b024eSKalle Valo wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
1036277b024eSKalle Valo wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
1037277b024eSKalle Valo memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
1038277b024eSKalle Valo le16_to_cpu(wmm_tlv->header.len));
1039277b024eSKalle Valo if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
1040277b024eSKalle Valo memcpy((u8 *) (wmm_tlv->wmm_ie
1041277b024eSKalle Valo + le16_to_cpu(wmm_tlv->header.len)
1042277b024eSKalle Valo - sizeof(priv->wmm_qosinfo)),
1043277b024eSKalle Valo &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
1044277b024eSKalle Valo
1045277b024eSKalle Valo ret_len = sizeof(wmm_tlv->header)
1046277b024eSKalle Valo + le16_to_cpu(wmm_tlv->header.len);
1047277b024eSKalle Valo
1048277b024eSKalle Valo *assoc_buf += ret_len;
1049277b024eSKalle Valo }
1050277b024eSKalle Valo
1051277b024eSKalle Valo return ret_len;
1052277b024eSKalle Valo }
1053277b024eSKalle Valo
1054277b024eSKalle Valo /*
1055277b024eSKalle Valo * This function computes the time delay in the driver queues for a
1056277b024eSKalle Valo * given packet.
1057277b024eSKalle Valo *
1058277b024eSKalle Valo * When the packet is received at the OS/Driver interface, the current
1059277b024eSKalle Valo * time is set in the packet structure. The difference between the present
1060277b024eSKalle Valo * time and that received time is computed in this function and limited
1061277b024eSKalle Valo * based on pre-compiled limits in the driver.
1062277b024eSKalle Valo */
1063277b024eSKalle Valo u8
mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private * priv,const struct sk_buff * skb)1064277b024eSKalle Valo mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
1065277b024eSKalle Valo const struct sk_buff *skb)
1066277b024eSKalle Valo {
1067277b024eSKalle Valo u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));
1068277b024eSKalle Valo u8 ret_val;
1069277b024eSKalle Valo
1070277b024eSKalle Valo /*
1071277b024eSKalle Valo * Queue delay is passed as a uint8 in units of 2ms (ms shifted
1072277b024eSKalle Valo * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
1073277b024eSKalle Valo *
1074277b024eSKalle Valo * Pass max value if queue_delay is beyond the uint8 range
1075277b024eSKalle Valo */
1076277b024eSKalle Valo ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
1077277b024eSKalle Valo
1078277b024eSKalle Valo mwifiex_dbg(priv->adapter, DATA, "data: WMM: Pkt Delay: %d ms,\t"
1079277b024eSKalle Valo "%d ms sent to FW\n", queue_delay, ret_val);
1080277b024eSKalle Valo
1081277b024eSKalle Valo return ret_val;
1082277b024eSKalle Valo }
1083277b024eSKalle Valo
1084277b024eSKalle Valo /*
1085277b024eSKalle Valo * This function retrieves the highest priority RA list table pointer.
1086277b024eSKalle Valo */
1087277b024eSKalle Valo static struct mwifiex_ra_list_tbl *
mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter * adapter,struct mwifiex_private ** priv,int * tid)1088277b024eSKalle Valo mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
1089277b024eSKalle Valo struct mwifiex_private **priv, int *tid)
1090277b024eSKalle Valo {
1091277b024eSKalle Valo struct mwifiex_private *priv_tmp;
1092277b024eSKalle Valo struct mwifiex_ra_list_tbl *ptr;
1093277b024eSKalle Valo struct mwifiex_tid_tbl *tid_ptr;
1094277b024eSKalle Valo atomic_t *hqp;
1095277b024eSKalle Valo int i, j;
1096277b024eSKalle Valo
1097277b024eSKalle Valo /* check the BSS with highest priority first */
1098277b024eSKalle Valo for (j = adapter->priv_num - 1; j >= 0; --j) {
1099277b024eSKalle Valo /* iterate over BSS with the equal priority */
1100277b024eSKalle Valo list_for_each_entry(adapter->bss_prio_tbl[j].bss_prio_cur,
1101277b024eSKalle Valo &adapter->bss_prio_tbl[j].bss_prio_head,
1102277b024eSKalle Valo list) {
1103277b024eSKalle Valo
110449abe5c8SXinming Hu try_again:
1105277b024eSKalle Valo priv_tmp = adapter->bss_prio_tbl[j].bss_prio_cur->priv;
1106277b024eSKalle Valo
1107dc386ce7Schunfan chen if (((priv_tmp->bss_mode != NL80211_IFTYPE_ADHOC) &&
1108dc386ce7Schunfan chen !priv_tmp->port_open) ||
1109277b024eSKalle Valo (atomic_read(&priv_tmp->wmm.tx_pkts_queued) == 0))
1110277b024eSKalle Valo continue;
1111277b024eSKalle Valo
1112277b024eSKalle Valo if (adapter->if_ops.is_port_ready &&
1113277b024eSKalle Valo !adapter->if_ops.is_port_ready(priv_tmp))
1114277b024eSKalle Valo continue;
1115277b024eSKalle Valo
1116277b024eSKalle Valo /* iterate over the WMM queues of the BSS */
1117277b024eSKalle Valo hqp = &priv_tmp->wmm.highest_queued_prio;
1118277b024eSKalle Valo for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
1119277b024eSKalle Valo
11208a7f9fd8SBrian Norris spin_lock_bh(&priv_tmp->wmm.ra_list_spinlock);
1121277b024eSKalle Valo
1122277b024eSKalle Valo tid_ptr = &(priv_tmp)->wmm.
1123277b024eSKalle Valo tid_tbl_ptr[tos_to_tid[i]];
1124277b024eSKalle Valo
1125277b024eSKalle Valo /* iterate over receiver addresses */
1126277b024eSKalle Valo list_for_each_entry(ptr, &tid_ptr->ra_list,
1127277b024eSKalle Valo list) {
1128277b024eSKalle Valo
1129277b024eSKalle Valo if (!ptr->tx_paused &&
1130277b024eSKalle Valo !skb_queue_empty(&ptr->skb_head))
1131277b024eSKalle Valo /* holds both locks */
1132277b024eSKalle Valo goto found;
1133277b024eSKalle Valo }
1134277b024eSKalle Valo
11358a7f9fd8SBrian Norris spin_unlock_bh(&priv_tmp->wmm.ra_list_spinlock);
1136277b024eSKalle Valo }
1137277b024eSKalle Valo
113849abe5c8SXinming Hu if (atomic_read(&priv_tmp->wmm.tx_pkts_queued) != 0) {
113949abe5c8SXinming Hu atomic_set(&priv_tmp->wmm.highest_queued_prio,
114049abe5c8SXinming Hu HIGH_PRIO_TID);
114149abe5c8SXinming Hu /* Iterate current private once more, since
114249abe5c8SXinming Hu * there still exist packets in data queue
114349abe5c8SXinming Hu */
114449abe5c8SXinming Hu goto try_again;
114549abe5c8SXinming Hu } else
114649abe5c8SXinming Hu atomic_set(&priv_tmp->wmm.highest_queued_prio,
114749abe5c8SXinming Hu NO_PKT_PRIO_TID);
114849abe5c8SXinming Hu }
1149277b024eSKalle Valo }
1150277b024eSKalle Valo
1151277b024eSKalle Valo return NULL;
1152277b024eSKalle Valo
1153277b024eSKalle Valo found:
1154277b024eSKalle Valo /* holds ra_list_spinlock */
1155277b024eSKalle Valo if (atomic_read(hqp) > i)
1156277b024eSKalle Valo atomic_set(hqp, i);
11578a7f9fd8SBrian Norris spin_unlock_bh(&priv_tmp->wmm.ra_list_spinlock);
1158277b024eSKalle Valo
1159277b024eSKalle Valo *priv = priv_tmp;
1160277b024eSKalle Valo *tid = tos_to_tid[i];
1161277b024eSKalle Valo
1162277b024eSKalle Valo return ptr;
1163277b024eSKalle Valo }
1164277b024eSKalle Valo
1165277b024eSKalle Valo /* This functions rotates ra and bss lists so packets are picked round robin.
1166277b024eSKalle Valo *
1167277b024eSKalle Valo * After a packet is successfully transmitted, rotate the ra list, so the ra
1168277b024eSKalle Valo * next to the one transmitted, will come first in the list. This way we pick
1169277b024eSKalle Valo * the ra' in a round robin fashion. Same applies to bss nodes of equal
1170277b024eSKalle Valo * priority.
1171277b024eSKalle Valo *
1172277b024eSKalle Valo * Function also increments wmm.packets_out counter.
1173277b024eSKalle Valo */
mwifiex_rotate_priolists(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ra,int tid)1174277b024eSKalle Valo void mwifiex_rotate_priolists(struct mwifiex_private *priv,
1175277b024eSKalle Valo struct mwifiex_ra_list_tbl *ra,
1176277b024eSKalle Valo int tid)
1177277b024eSKalle Valo {
1178277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
1179277b024eSKalle Valo struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
1180277b024eSKalle Valo struct mwifiex_tid_tbl *tid_ptr = &priv->wmm.tid_tbl_ptr[tid];
1181277b024eSKalle Valo
11828a7f9fd8SBrian Norris spin_lock_bh(&tbl[priv->bss_priority].bss_prio_lock);
1183277b024eSKalle Valo /*
1184277b024eSKalle Valo * dirty trick: we remove 'head' temporarily and reinsert it after
1185277b024eSKalle Valo * curr bss node. imagine list to stay fixed while head is moved
1186277b024eSKalle Valo */
1187277b024eSKalle Valo list_move(&tbl[priv->bss_priority].bss_prio_head,
1188277b024eSKalle Valo &tbl[priv->bss_priority].bss_prio_cur->list);
11898a7f9fd8SBrian Norris spin_unlock_bh(&tbl[priv->bss_priority].bss_prio_lock);
1190277b024eSKalle Valo
11918a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
1192277b024eSKalle Valo if (mwifiex_is_ralist_valid(priv, ra, tid)) {
1193277b024eSKalle Valo priv->wmm.packets_out[tid]++;
1194277b024eSKalle Valo /* same as above */
1195277b024eSKalle Valo list_move(&tid_ptr->ra_list, &ra->list);
1196277b024eSKalle Valo }
11978a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1198277b024eSKalle Valo }
1199277b024eSKalle Valo
1200277b024eSKalle Valo /*
1201277b024eSKalle Valo * This function checks if 11n aggregation is possible.
1202277b024eSKalle Valo */
1203277b024eSKalle Valo static int
mwifiex_is_11n_aggragation_possible(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ptr,int max_buf_size)1204277b024eSKalle Valo mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
1205277b024eSKalle Valo struct mwifiex_ra_list_tbl *ptr,
1206277b024eSKalle Valo int max_buf_size)
1207277b024eSKalle Valo {
1208277b024eSKalle Valo int count = 0, total_size = 0;
1209277b024eSKalle Valo struct sk_buff *skb, *tmp;
1210277b024eSKalle Valo int max_amsdu_size;
1211277b024eSKalle Valo
1212277b024eSKalle Valo if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
1213277b024eSKalle Valo ptr->is_11n_enabled)
1214277b024eSKalle Valo max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
1215277b024eSKalle Valo else
1216277b024eSKalle Valo max_amsdu_size = max_buf_size;
1217277b024eSKalle Valo
1218277b024eSKalle Valo skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
1219277b024eSKalle Valo total_size += skb->len;
1220277b024eSKalle Valo if (total_size >= max_amsdu_size)
1221277b024eSKalle Valo break;
1222277b024eSKalle Valo if (++count >= MIN_NUM_AMSDU)
1223277b024eSKalle Valo return true;
1224277b024eSKalle Valo }
1225277b024eSKalle Valo
1226277b024eSKalle Valo return false;
1227277b024eSKalle Valo }
1228277b024eSKalle Valo
1229277b024eSKalle Valo /*
1230277b024eSKalle Valo * This function sends a single packet to firmware for transmission.
1231277b024eSKalle Valo */
1232277b024eSKalle Valo static void
mwifiex_send_single_packet(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ptr,int ptr_index)1233277b024eSKalle Valo mwifiex_send_single_packet(struct mwifiex_private *priv,
12348a7f9fd8SBrian Norris struct mwifiex_ra_list_tbl *ptr, int ptr_index)
1235277b024eSKalle Valo __releases(&priv->wmm.ra_list_spinlock)
1236277b024eSKalle Valo {
1237277b024eSKalle Valo struct sk_buff *skb, *skb_next;
1238277b024eSKalle Valo struct mwifiex_tx_param tx_param;
1239277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
1240277b024eSKalle Valo struct mwifiex_txinfo *tx_info;
1241277b024eSKalle Valo
1242277b024eSKalle Valo if (skb_queue_empty(&ptr->skb_head)) {
12438a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1244277b024eSKalle Valo mwifiex_dbg(adapter, DATA, "data: nothing to send\n");
1245277b024eSKalle Valo return;
1246277b024eSKalle Valo }
1247277b024eSKalle Valo
1248277b024eSKalle Valo skb = skb_dequeue(&ptr->skb_head);
1249277b024eSKalle Valo
1250277b024eSKalle Valo tx_info = MWIFIEX_SKB_TXCB(skb);
1251277b024eSKalle Valo mwifiex_dbg(adapter, DATA,
1252277b024eSKalle Valo "data: dequeuing the packet %p %p\n", ptr, skb);
1253277b024eSKalle Valo
1254277b024eSKalle Valo ptr->total_pkt_count--;
1255277b024eSKalle Valo
1256277b024eSKalle Valo if (!skb_queue_empty(&ptr->skb_head))
1257277b024eSKalle Valo skb_next = skb_peek(&ptr->skb_head);
1258277b024eSKalle Valo else
1259277b024eSKalle Valo skb_next = NULL;
1260277b024eSKalle Valo
12618a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1262277b024eSKalle Valo
1263277b024eSKalle Valo tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
1264277b024eSKalle Valo sizeof(struct txpd) : 0);
1265277b024eSKalle Valo
1266277b024eSKalle Valo if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
1267277b024eSKalle Valo /* Queue the packet back at the head */
12688a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
1269277b024eSKalle Valo
1270277b024eSKalle Valo if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
12718a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1272277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, -1);
1273277b024eSKalle Valo return;
1274277b024eSKalle Valo }
1275277b024eSKalle Valo
1276277b024eSKalle Valo skb_queue_tail(&ptr->skb_head, skb);
1277277b024eSKalle Valo
1278277b024eSKalle Valo ptr->total_pkt_count++;
1279277b024eSKalle Valo ptr->ba_pkt_count++;
1280277b024eSKalle Valo tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
12818a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1282277b024eSKalle Valo } else {
1283277b024eSKalle Valo mwifiex_rotate_priolists(priv, ptr, ptr_index);
1284277b024eSKalle Valo atomic_dec(&priv->wmm.tx_pkts_queued);
1285277b024eSKalle Valo }
1286277b024eSKalle Valo }
1287277b024eSKalle Valo
1288277b024eSKalle Valo /*
1289277b024eSKalle Valo * This function checks if the first packet in the given RA list
1290277b024eSKalle Valo * is already processed or not.
1291277b024eSKalle Valo */
1292277b024eSKalle Valo static int
mwifiex_is_ptr_processed(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ptr)1293277b024eSKalle Valo mwifiex_is_ptr_processed(struct mwifiex_private *priv,
1294277b024eSKalle Valo struct mwifiex_ra_list_tbl *ptr)
1295277b024eSKalle Valo {
1296277b024eSKalle Valo struct sk_buff *skb;
1297277b024eSKalle Valo struct mwifiex_txinfo *tx_info;
1298277b024eSKalle Valo
1299277b024eSKalle Valo if (skb_queue_empty(&ptr->skb_head))
1300277b024eSKalle Valo return false;
1301277b024eSKalle Valo
1302277b024eSKalle Valo skb = skb_peek(&ptr->skb_head);
1303277b024eSKalle Valo
1304277b024eSKalle Valo tx_info = MWIFIEX_SKB_TXCB(skb);
1305277b024eSKalle Valo if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
1306277b024eSKalle Valo return true;
1307277b024eSKalle Valo
1308277b024eSKalle Valo return false;
1309277b024eSKalle Valo }
1310277b024eSKalle Valo
1311277b024eSKalle Valo /*
1312277b024eSKalle Valo * This function sends a single processed packet to firmware for
1313277b024eSKalle Valo * transmission.
1314277b024eSKalle Valo */
1315277b024eSKalle Valo static void
mwifiex_send_processed_packet(struct mwifiex_private * priv,struct mwifiex_ra_list_tbl * ptr,int ptr_index)1316277b024eSKalle Valo mwifiex_send_processed_packet(struct mwifiex_private *priv,
13178a7f9fd8SBrian Norris struct mwifiex_ra_list_tbl *ptr, int ptr_index)
1318277b024eSKalle Valo __releases(&priv->wmm.ra_list_spinlock)
1319277b024eSKalle Valo {
1320277b024eSKalle Valo struct mwifiex_tx_param tx_param;
1321277b024eSKalle Valo struct mwifiex_adapter *adapter = priv->adapter;
1322277b024eSKalle Valo int ret = -1;
1323277b024eSKalle Valo struct sk_buff *skb, *skb_next;
1324277b024eSKalle Valo struct mwifiex_txinfo *tx_info;
1325277b024eSKalle Valo
1326277b024eSKalle Valo if (skb_queue_empty(&ptr->skb_head)) {
13278a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1328277b024eSKalle Valo return;
1329277b024eSKalle Valo }
1330277b024eSKalle Valo
1331277b024eSKalle Valo skb = skb_dequeue(&ptr->skb_head);
1332277b024eSKalle Valo
1333277b024eSKalle Valo if (adapter->data_sent || adapter->tx_lock_flag) {
133477f486c8SXinming Hu ptr->total_pkt_count--;
13358a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1336277b024eSKalle Valo skb_queue_tail(&adapter->tx_data_q, skb);
133777f486c8SXinming Hu atomic_dec(&priv->wmm.tx_pkts_queued);
1338277b024eSKalle Valo atomic_inc(&adapter->tx_queued);
1339277b024eSKalle Valo return;
1340277b024eSKalle Valo }
1341277b024eSKalle Valo
1342277b024eSKalle Valo if (!skb_queue_empty(&ptr->skb_head))
1343277b024eSKalle Valo skb_next = skb_peek(&ptr->skb_head);
1344277b024eSKalle Valo else
1345277b024eSKalle Valo skb_next = NULL;
1346277b024eSKalle Valo
1347277b024eSKalle Valo tx_info = MWIFIEX_SKB_TXCB(skb);
1348277b024eSKalle Valo
13498a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1350277b024eSKalle Valo
1351277b024eSKalle Valo tx_param.next_pkt_len =
1352277b024eSKalle Valo ((skb_next) ? skb_next->len +
1353277b024eSKalle Valo sizeof(struct txpd) : 0);
1354822446d4SXinming Hu if (adapter->iface_type == MWIFIEX_USB) {
1355822446d4SXinming Hu ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
1356822446d4SXinming Hu skb, &tx_param);
1357822446d4SXinming Hu } else {
1358277b024eSKalle Valo ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
1359277b024eSKalle Valo skb, &tx_param);
1360277b024eSKalle Valo }
1361277b024eSKalle Valo
1362277b024eSKalle Valo switch (ret) {
1363277b024eSKalle Valo case -EBUSY:
1364277b024eSKalle Valo mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
13658a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
1366277b024eSKalle Valo
1367277b024eSKalle Valo if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
13688a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1369277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, -1);
1370277b024eSKalle Valo return;
1371277b024eSKalle Valo }
1372277b024eSKalle Valo
1373277b024eSKalle Valo skb_queue_tail(&ptr->skb_head, skb);
1374277b024eSKalle Valo
1375277b024eSKalle Valo tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
13768a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1377277b024eSKalle Valo break;
1378277b024eSKalle Valo case -1:
1379277b024eSKalle Valo mwifiex_dbg(adapter, ERROR, "host_to_card failed: %#x\n", ret);
1380277b024eSKalle Valo adapter->dbg.num_tx_host_to_card_failure++;
1381277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, ret);
1382277b024eSKalle Valo break;
1383277b024eSKalle Valo case -EINPROGRESS:
1384277b024eSKalle Valo break;
1385277b024eSKalle Valo case 0:
1386277b024eSKalle Valo mwifiex_write_data_complete(adapter, skb, 0, ret);
138700331758SGustavo A. R. Silva break;
1388277b024eSKalle Valo default:
1389277b024eSKalle Valo break;
1390277b024eSKalle Valo }
1391277b024eSKalle Valo if (ret != -EBUSY) {
1392277b024eSKalle Valo mwifiex_rotate_priolists(priv, ptr, ptr_index);
1393277b024eSKalle Valo atomic_dec(&priv->wmm.tx_pkts_queued);
13948a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
139577f486c8SXinming Hu ptr->total_pkt_count--;
13968a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1397277b024eSKalle Valo }
1398277b024eSKalle Valo }
1399277b024eSKalle Valo
1400277b024eSKalle Valo /*
1401277b024eSKalle Valo * This function dequeues a packet from the highest priority list
1402277b024eSKalle Valo * and transmits it.
1403277b024eSKalle Valo */
1404277b024eSKalle Valo static int
mwifiex_dequeue_tx_packet(struct mwifiex_adapter * adapter)1405277b024eSKalle Valo mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
1406277b024eSKalle Valo {
1407277b024eSKalle Valo struct mwifiex_ra_list_tbl *ptr;
1408277b024eSKalle Valo struct mwifiex_private *priv = NULL;
1409277b024eSKalle Valo int ptr_index = 0;
1410277b024eSKalle Valo u8 ra[ETH_ALEN];
1411277b024eSKalle Valo int tid_del = 0, tid = 0;
1412277b024eSKalle Valo
1413277b024eSKalle Valo ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
1414277b024eSKalle Valo if (!ptr)
1415277b024eSKalle Valo return -1;
1416277b024eSKalle Valo
1417277b024eSKalle Valo tid = mwifiex_get_tid(ptr);
1418277b024eSKalle Valo
1419277b024eSKalle Valo mwifiex_dbg(adapter, DATA, "data: tid=%d\n", tid);
1420277b024eSKalle Valo
14218a7f9fd8SBrian Norris spin_lock_bh(&priv->wmm.ra_list_spinlock);
1422277b024eSKalle Valo if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
14238a7f9fd8SBrian Norris spin_unlock_bh(&priv->wmm.ra_list_spinlock);
1424277b024eSKalle Valo return -1;
1425277b024eSKalle Valo }
1426277b024eSKalle Valo
1427277b024eSKalle Valo if (mwifiex_is_ptr_processed(priv, ptr)) {
14288a7f9fd8SBrian Norris mwifiex_send_processed_packet(priv, ptr, ptr_index);
1429277b024eSKalle Valo /* ra_list_spinlock has been freed in
1430277b024eSKalle Valo mwifiex_send_processed_packet() */
1431277b024eSKalle Valo return 0;
1432277b024eSKalle Valo }
1433277b024eSKalle Valo
1434277b024eSKalle Valo if (!ptr->is_11n_enabled ||
1435277b024eSKalle Valo ptr->ba_status ||
1436277b024eSKalle Valo priv->wps.session_enable) {
1437277b024eSKalle Valo if (ptr->is_11n_enabled &&
1438277b024eSKalle Valo ptr->ba_status &&
1439277b024eSKalle Valo ptr->amsdu_in_ampdu &&
1440277b024eSKalle Valo mwifiex_is_amsdu_allowed(priv, tid) &&
1441277b024eSKalle Valo mwifiex_is_11n_aggragation_possible(priv, ptr,
1442277b024eSKalle Valo adapter->tx_buf_size))
14438a7f9fd8SBrian Norris mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index);
1444277b024eSKalle Valo /* ra_list_spinlock has been freed in
1445277b024eSKalle Valo * mwifiex_11n_aggregate_pkt()
1446277b024eSKalle Valo */
1447277b024eSKalle Valo else
14488a7f9fd8SBrian Norris mwifiex_send_single_packet(priv, ptr, ptr_index);
1449277b024eSKalle Valo /* ra_list_spinlock has been freed in
1450277b024eSKalle Valo * mwifiex_send_single_packet()
1451277b024eSKalle Valo */
1452277b024eSKalle Valo } else {
1453277b024eSKalle Valo if (mwifiex_is_ampdu_allowed(priv, ptr, tid) &&
1454277b024eSKalle Valo ptr->ba_pkt_count > ptr->ba_packet_thr) {
1455277b024eSKalle Valo if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
1456277b024eSKalle Valo mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1457277b024eSKalle Valo BA_SETUP_INPROGRESS);
1458277b024eSKalle Valo mwifiex_send_addba(priv, tid, ptr->ra);
1459277b024eSKalle Valo } else if (mwifiex_find_stream_to_delete
1460277b024eSKalle Valo (priv, tid, &tid_del, ra)) {
1461277b024eSKalle Valo mwifiex_create_ba_tbl(priv, ptr->ra, tid,
1462277b024eSKalle Valo BA_SETUP_INPROGRESS);
1463277b024eSKalle Valo mwifiex_send_delba(priv, tid_del, ra, 1);
1464277b024eSKalle Valo }
1465277b024eSKalle Valo }
1466277b024eSKalle Valo if (mwifiex_is_amsdu_allowed(priv, tid) &&
1467277b024eSKalle Valo mwifiex_is_11n_aggragation_possible(priv, ptr,
1468277b024eSKalle Valo adapter->tx_buf_size))
14698a7f9fd8SBrian Norris mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index);
1470277b024eSKalle Valo /* ra_list_spinlock has been freed in
1471277b024eSKalle Valo mwifiex_11n_aggregate_pkt() */
1472277b024eSKalle Valo else
14738a7f9fd8SBrian Norris mwifiex_send_single_packet(priv, ptr, ptr_index);
1474277b024eSKalle Valo /* ra_list_spinlock has been freed in
1475277b024eSKalle Valo mwifiex_send_single_packet() */
1476277b024eSKalle Valo }
1477277b024eSKalle Valo return 0;
1478277b024eSKalle Valo }
1479277b024eSKalle Valo
mwifiex_process_bypass_tx(struct mwifiex_adapter * adapter)1480277b024eSKalle Valo void mwifiex_process_bypass_tx(struct mwifiex_adapter *adapter)
1481277b024eSKalle Valo {
1482277b024eSKalle Valo struct mwifiex_tx_param tx_param;
1483277b024eSKalle Valo struct sk_buff *skb;
1484277b024eSKalle Valo struct mwifiex_txinfo *tx_info;
1485277b024eSKalle Valo struct mwifiex_private *priv;
1486277b024eSKalle Valo int i;
1487277b024eSKalle Valo
1488277b024eSKalle Valo if (adapter->data_sent || adapter->tx_lock_flag)
1489277b024eSKalle Valo return;
1490277b024eSKalle Valo
1491277b024eSKalle Valo for (i = 0; i < adapter->priv_num; ++i) {
1492277b024eSKalle Valo priv = adapter->priv[i];
1493277b024eSKalle Valo
1494277b024eSKalle Valo if (!priv)
1495277b024eSKalle Valo continue;
1496277b024eSKalle Valo
1497277b024eSKalle Valo if (adapter->if_ops.is_port_ready &&
1498277b024eSKalle Valo !adapter->if_ops.is_port_ready(priv))
1499277b024eSKalle Valo continue;
1500277b024eSKalle Valo
1501277b024eSKalle Valo if (skb_queue_empty(&priv->bypass_txq))
1502277b024eSKalle Valo continue;
1503277b024eSKalle Valo
1504277b024eSKalle Valo skb = skb_dequeue(&priv->bypass_txq);
1505277b024eSKalle Valo tx_info = MWIFIEX_SKB_TXCB(skb);
1506277b024eSKalle Valo
1507277b024eSKalle Valo /* no aggregation for bypass packets */
1508277b024eSKalle Valo tx_param.next_pkt_len = 0;
1509277b024eSKalle Valo
1510277b024eSKalle Valo if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
1511277b024eSKalle Valo skb_queue_head(&priv->bypass_txq, skb);
1512277b024eSKalle Valo tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
1513277b024eSKalle Valo } else {
1514277b024eSKalle Valo atomic_dec(&adapter->bypass_tx_pending);
1515277b024eSKalle Valo }
1516277b024eSKalle Valo }
1517277b024eSKalle Valo }
1518277b024eSKalle Valo
1519277b024eSKalle Valo /*
1520277b024eSKalle Valo * This function transmits the highest priority packet awaiting in the
1521277b024eSKalle Valo * WMM Queues.
1522277b024eSKalle Valo */
1523277b024eSKalle Valo void
mwifiex_wmm_process_tx(struct mwifiex_adapter * adapter)1524277b024eSKalle Valo mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
1525277b024eSKalle Valo {
1526277b024eSKalle Valo do {
1527277b024eSKalle Valo if (mwifiex_dequeue_tx_packet(adapter))
1528277b024eSKalle Valo break;
1529277b024eSKalle Valo if (adapter->iface_type != MWIFIEX_SDIO) {
1530277b024eSKalle Valo if (adapter->data_sent ||
1531277b024eSKalle Valo adapter->tx_lock_flag)
1532277b024eSKalle Valo break;
1533277b024eSKalle Valo } else {
1534277b024eSKalle Valo if (atomic_read(&adapter->tx_queued) >=
1535277b024eSKalle Valo MWIFIEX_MAX_PKTS_TXQ)
1536277b024eSKalle Valo break;
1537277b024eSKalle Valo }
1538277b024eSKalle Valo } while (!mwifiex_wmm_lists_empty(adapter));
1539277b024eSKalle Valo }
1540