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