Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: 802.11n RX Re-ordering | |
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 | #include "11n_rxreorder.h" | |
28 | ||
29 | /* | |
30 | * This function processes a received packet and forwards | |
31 | * it to the kernel/upper layer. | |
32 | */ | |
33 | static int mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv, void *payload) | |
34 | { | |
35 | int ret = 0; | |
36 | struct mwifiex_adapter *adapter = priv->adapter; | |
37 | ||
38 | ret = mwifiex_process_rx_packet(adapter, (struct sk_buff *) payload); | |
39 | return ret; | |
40 | } | |
41 | ||
42 | /* | |
43 | * This function dispatches all packets in the Rx reorder table. | |
44 | * | |
45 | * There could be holes in the buffer, which are skipped by the function. | |
46 | * Since the buffer is linear, the function uses rotation to simulate | |
47 | * circular buffer. | |
48 | */ | |
49 | static int | |
50 | mwifiex_11n_dispatch_pkt_until_start_win(struct mwifiex_private *priv, | |
51 | struct mwifiex_rx_reorder_tbl | |
52 | *rx_reor_tbl_ptr, int start_win) | |
53 | { | |
54 | int no_pkt_to_send, i, xchg; | |
55 | void *rx_tmp_ptr = NULL; | |
56 | unsigned long flags; | |
57 | ||
58 | no_pkt_to_send = (start_win > rx_reor_tbl_ptr->start_win) ? | |
59 | min((start_win - rx_reor_tbl_ptr->start_win), | |
60 | rx_reor_tbl_ptr->win_size) : rx_reor_tbl_ptr->win_size; | |
61 | ||
62 | for (i = 0; i < no_pkt_to_send; ++i) { | |
63 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); | |
64 | rx_tmp_ptr = NULL; | |
65 | if (rx_reor_tbl_ptr->rx_reorder_ptr[i]) { | |
66 | rx_tmp_ptr = rx_reor_tbl_ptr->rx_reorder_ptr[i]; | |
67 | rx_reor_tbl_ptr->rx_reorder_ptr[i] = NULL; | |
68 | } | |
69 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
70 | if (rx_tmp_ptr) | |
71 | mwifiex_11n_dispatch_pkt(priv, rx_tmp_ptr); | |
72 | } | |
73 | ||
74 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); | |
75 | /* | |
76 | * We don't have a circular buffer, hence use rotation to simulate | |
77 | * circular buffer | |
78 | */ | |
79 | xchg = rx_reor_tbl_ptr->win_size - no_pkt_to_send; | |
80 | for (i = 0; i < xchg; ++i) { | |
81 | rx_reor_tbl_ptr->rx_reorder_ptr[i] = | |
82 | rx_reor_tbl_ptr->rx_reorder_ptr[no_pkt_to_send + i]; | |
83 | rx_reor_tbl_ptr->rx_reorder_ptr[no_pkt_to_send + i] = NULL; | |
84 | } | |
85 | ||
86 | rx_reor_tbl_ptr->start_win = start_win; | |
87 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
92 | /* | |
93 | * This function dispatches all packets in the Rx reorder table until | |
94 | * a hole is found. | |
95 | * | |
96 | * The start window is adjusted automatically when a hole is located. | |
97 | * Since the buffer is linear, the function uses rotation to simulate | |
98 | * circular buffer. | |
99 | */ | |
100 | static int | |
101 | mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv, | |
102 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr) | |
103 | { | |
104 | int i, j, xchg; | |
105 | void *rx_tmp_ptr = NULL; | |
106 | unsigned long flags; | |
107 | ||
108 | for (i = 0; i < rx_reor_tbl_ptr->win_size; ++i) { | |
109 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); | |
110 | if (!rx_reor_tbl_ptr->rx_reorder_ptr[i]) { | |
111 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
112 | break; | |
113 | } | |
114 | rx_tmp_ptr = rx_reor_tbl_ptr->rx_reorder_ptr[i]; | |
115 | rx_reor_tbl_ptr->rx_reorder_ptr[i] = NULL; | |
116 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
117 | mwifiex_11n_dispatch_pkt(priv, rx_tmp_ptr); | |
118 | } | |
119 | ||
120 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); | |
121 | /* | |
122 | * We don't have a circular buffer, hence use rotation to simulate | |
123 | * circular buffer | |
124 | */ | |
125 | if (i > 0) { | |
126 | xchg = rx_reor_tbl_ptr->win_size - i; | |
127 | for (j = 0; j < xchg; ++j) { | |
128 | rx_reor_tbl_ptr->rx_reorder_ptr[j] = | |
129 | rx_reor_tbl_ptr->rx_reorder_ptr[i + j]; | |
130 | rx_reor_tbl_ptr->rx_reorder_ptr[i + j] = NULL; | |
131 | } | |
132 | } | |
133 | rx_reor_tbl_ptr->start_win = (rx_reor_tbl_ptr->start_win + i) | |
134 | &(MAX_TID_VALUE - 1); | |
135 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
136 | return 0; | |
137 | } | |
138 | ||
139 | /* | |
140 | * This function deletes the Rx reorder table and frees the memory. | |
141 | * | |
142 | * The function stops the associated timer and dispatches all the | |
143 | * pending packets in the Rx reorder table before deletion. | |
144 | */ | |
145 | static void | |
146 | mwifiex_11n_delete_rx_reorder_tbl_entry(struct mwifiex_private *priv, | |
147 | struct mwifiex_rx_reorder_tbl | |
148 | *rx_reor_tbl_ptr) | |
149 | { | |
150 | unsigned long flags; | |
151 | ||
152 | if (!rx_reor_tbl_ptr) | |
153 | return; | |
154 | ||
155 | mwifiex_11n_dispatch_pkt_until_start_win(priv, rx_reor_tbl_ptr, | |
156 | (rx_reor_tbl_ptr->start_win + | |
157 | rx_reor_tbl_ptr->win_size) | |
158 | &(MAX_TID_VALUE - 1)); | |
159 | ||
160 | del_timer(&rx_reor_tbl_ptr->timer_context.timer); | |
161 | ||
162 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
163 | list_del(&rx_reor_tbl_ptr->list); | |
164 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
165 | ||
166 | kfree(rx_reor_tbl_ptr->rx_reorder_ptr); | |
167 | kfree(rx_reor_tbl_ptr); | |
168 | } | |
169 | ||
170 | /* | |
171 | * This function returns the pointer to an entry in Rx reordering | |
172 | * table which matches the given TA/TID pair. | |
173 | */ | |
174 | static struct mwifiex_rx_reorder_tbl * | |
175 | mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta) | |
176 | { | |
177 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr; | |
178 | unsigned long flags; | |
179 | ||
180 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
181 | list_for_each_entry(rx_reor_tbl_ptr, &priv->rx_reorder_tbl_ptr, list) { | |
182 | if ((!memcmp(rx_reor_tbl_ptr->ta, ta, ETH_ALEN)) | |
183 | && (rx_reor_tbl_ptr->tid == tid)) { | |
184 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, | |
185 | flags); | |
186 | return rx_reor_tbl_ptr; | |
187 | } | |
188 | } | |
189 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
190 | ||
191 | return NULL; | |
192 | } | |
193 | ||
194 | /* | |
195 | * This function finds the last sequence number used in the packets | |
196 | * buffered in Rx reordering table. | |
197 | */ | |
198 | static int | |
199 | mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr) | |
200 | { | |
201 | int i; | |
202 | ||
203 | for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i) | |
204 | if (rx_reorder_tbl_ptr->rx_reorder_ptr[i]) | |
205 | return i; | |
206 | ||
207 | return -1; | |
208 | } | |
209 | ||
210 | /* | |
211 | * This function flushes all the packets in Rx reordering table. | |
212 | * | |
213 | * The function checks if any packets are currently buffered in the | |
214 | * table or not. In case there are packets available, it dispatches | |
215 | * them and then dumps the Rx reordering table. | |
216 | */ | |
217 | static void | |
218 | mwifiex_flush_data(unsigned long context) | |
219 | { | |
220 | struct reorder_tmr_cnxt *reorder_cnxt = | |
221 | (struct reorder_tmr_cnxt *) context; | |
222 | int start_win; | |
223 | ||
224 | start_win = mwifiex_11n_find_last_seq_num(reorder_cnxt->ptr); | |
225 | if (start_win >= 0) { | |
226 | dev_dbg(reorder_cnxt->priv->adapter->dev, | |
227 | "info: flush data %d\n", start_win); | |
228 | mwifiex_11n_dispatch_pkt_until_start_win(reorder_cnxt->priv, | |
229 | reorder_cnxt->ptr, | |
230 | ((reorder_cnxt->ptr->start_win + | |
231 | start_win + 1) & (MAX_TID_VALUE - 1))); | |
232 | } | |
233 | } | |
234 | ||
235 | /* | |
236 | * This function creates an entry in Rx reordering table for the | |
237 | * given TA/TID. | |
238 | * | |
239 | * The function also initializes the entry with sequence number, window | |
240 | * size as well as initializes the timer. | |
241 | * | |
242 | * If the received TA/TID pair is already present, all the packets are | |
243 | * dispatched and the window size is moved until the SSN. | |
244 | */ | |
245 | static void | |
246 | mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, | |
247 | int tid, int win_size, int seq_num) | |
248 | { | |
249 | int i; | |
250 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr, *new_node; | |
251 | u16 last_seq = 0; | |
252 | unsigned long flags; | |
253 | ||
254 | /* | |
255 | * If we get a TID, ta pair which is already present dispatch all the | |
256 | * the packets and move the window size until the ssn | |
257 | */ | |
258 | rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta); | |
259 | if (rx_reor_tbl_ptr) { | |
260 | mwifiex_11n_dispatch_pkt_until_start_win(priv, rx_reor_tbl_ptr, | |
261 | seq_num); | |
262 | return; | |
263 | } | |
264 | /* if !rx_reor_tbl_ptr then create one */ | |
265 | new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL); | |
266 | if (!new_node) { | |
267 | dev_err(priv->adapter->dev, "%s: failed to alloc new_node\n", | |
268 | __func__); | |
269 | return; | |
270 | } | |
271 | ||
272 | INIT_LIST_HEAD(&new_node->list); | |
273 | new_node->tid = tid; | |
274 | memcpy(new_node->ta, ta, ETH_ALEN); | |
275 | new_node->start_win = seq_num; | |
276 | if (mwifiex_queuing_ra_based(priv)) | |
277 | /* TODO for adhoc */ | |
278 | dev_dbg(priv->adapter->dev, | |
279 | "info: ADHOC:last_seq=%d start_win=%d\n", | |
280 | last_seq, new_node->start_win); | |
281 | else | |
282 | last_seq = priv->rx_seq[tid]; | |
283 | ||
284 | if (last_seq >= new_node->start_win) | |
285 | new_node->start_win = last_seq + 1; | |
286 | ||
287 | new_node->win_size = win_size; | |
288 | ||
289 | new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size, | |
290 | GFP_KERNEL); | |
291 | if (!new_node->rx_reorder_ptr) { | |
292 | kfree((u8 *) new_node); | |
293 | dev_err(priv->adapter->dev, | |
294 | "%s: failed to alloc reorder_ptr\n", __func__); | |
295 | return; | |
296 | } | |
297 | ||
298 | new_node->timer_context.ptr = new_node; | |
299 | new_node->timer_context.priv = priv; | |
300 | ||
301 | init_timer(&new_node->timer_context.timer); | |
302 | new_node->timer_context.timer.function = mwifiex_flush_data; | |
303 | new_node->timer_context.timer.data = | |
304 | (unsigned long) &new_node->timer_context; | |
305 | ||
306 | for (i = 0; i < win_size; ++i) | |
307 | new_node->rx_reorder_ptr[i] = NULL; | |
308 | ||
309 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
310 | list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr); | |
311 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
5e6e3a92 BZ |
312 | } |
313 | ||
314 | /* | |
315 | * This function prepares command for adding a BA request. | |
316 | * | |
317 | * Preparation includes - | |
318 | * - Setting command ID and proper size | |
319 | * - Setting add BA request buffer | |
320 | * - Ensuring correct endian-ness | |
321 | */ | |
572e8f3e | 322 | int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 BZ |
323 | { |
324 | struct host_cmd_ds_11n_addba_req *add_ba_req = | |
325 | (struct host_cmd_ds_11n_addba_req *) | |
326 | &cmd->params.add_ba_req; | |
327 | ||
328 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ); | |
329 | cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN); | |
330 | memcpy(add_ba_req, data_buf, sizeof(*add_ba_req)); | |
331 | ||
332 | return 0; | |
333 | } | |
334 | ||
335 | /* | |
336 | * This function prepares command for adding a BA response. | |
337 | * | |
338 | * Preparation includes - | |
339 | * - Setting command ID and proper size | |
340 | * - Setting add BA response buffer | |
341 | * - Ensuring correct endian-ness | |
342 | */ | |
343 | int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv, | |
344 | struct host_cmd_ds_command *cmd, | |
345 | void *data_buf) | |
346 | { | |
347 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = | |
348 | (struct host_cmd_ds_11n_addba_rsp *) | |
349 | &cmd->params.add_ba_rsp; | |
350 | struct host_cmd_ds_11n_addba_req *cmd_addba_req = | |
351 | (struct host_cmd_ds_11n_addba_req *) data_buf; | |
352 | u8 tid = 0; | |
353 | int win_size = 0; | |
354 | uint16_t block_ack_param_set; | |
355 | ||
356 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP); | |
357 | cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN); | |
358 | ||
359 | memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr, | |
360 | ETH_ALEN); | |
361 | add_ba_rsp->dialog_token = cmd_addba_req->dialog_token; | |
362 | add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo; | |
363 | add_ba_rsp->ssn = cmd_addba_req->ssn; | |
364 | ||
365 | block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set); | |
366 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
367 | >> BLOCKACKPARAM_TID_POS; | |
368 | add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT); | |
369 | block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; | |
370 | /* We donot support AMSDU inside AMPDU, hence reset the bit */ | |
371 | block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK; | |
372 | block_ack_param_set |= (priv->add_ba_param.rx_win_size << | |
373 | BLOCKACKPARAM_WINSIZE_POS); | |
374 | add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set); | |
375 | win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set) | |
376 | & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) | |
377 | >> BLOCKACKPARAM_WINSIZE_POS; | |
378 | cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set); | |
379 | ||
380 | mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr, | |
381 | tid, win_size, le16_to_cpu(cmd_addba_req->ssn)); | |
382 | return 0; | |
383 | } | |
384 | ||
385 | /* | |
386 | * This function prepares command for deleting a BA request. | |
387 | * | |
388 | * Preparation includes - | |
389 | * - Setting command ID and proper size | |
390 | * - Setting del BA request buffer | |
391 | * - Ensuring correct endian-ness | |
392 | */ | |
572e8f3e | 393 | int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 BZ |
394 | { |
395 | struct host_cmd_ds_11n_delba *del_ba = (struct host_cmd_ds_11n_delba *) | |
396 | &cmd->params.del_ba; | |
397 | ||
398 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA); | |
399 | cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN); | |
400 | memcpy(del_ba, data_buf, sizeof(*del_ba)); | |
401 | ||
402 | return 0; | |
403 | } | |
404 | ||
405 | /* | |
406 | * This function identifies if Rx reordering is needed for a received packet. | |
407 | * | |
408 | * In case reordering is required, the function will do the reordering | |
409 | * before sending it to kernel. | |
410 | * | |
411 | * The Rx reorder table is checked first with the received TID/TA pair. If | |
412 | * not found, the received packet is dispatched immediately. But if found, | |
413 | * the packet is reordered and all the packets in the updated Rx reordering | |
414 | * table is dispatched until a hole is found. | |
415 | * | |
416 | * For sequence number less than the starting window, the packet is dropped. | |
417 | */ | |
418 | int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv, | |
419 | u16 seq_num, u16 tid, | |
420 | u8 *ta, u8 pkt_type, void *payload) | |
421 | { | |
422 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr; | |
423 | int start_win, end_win, win_size; | |
424 | int ret = 0; | |
425 | u16 pkt_index = 0; | |
426 | ||
427 | rx_reor_tbl_ptr = | |
428 | mwifiex_11n_get_rx_reorder_tbl((struct mwifiex_private *) priv, | |
429 | tid, ta); | |
430 | if (!rx_reor_tbl_ptr) { | |
431 | if (pkt_type != PKT_TYPE_BAR) | |
432 | mwifiex_11n_dispatch_pkt(priv, payload); | |
433 | return 0; | |
434 | } | |
435 | start_win = rx_reor_tbl_ptr->start_win; | |
436 | win_size = rx_reor_tbl_ptr->win_size; | |
437 | end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1); | |
438 | del_timer(&rx_reor_tbl_ptr->timer_context.timer); | |
439 | mod_timer(&rx_reor_tbl_ptr->timer_context.timer, jiffies | |
440 | + (MIN_FLUSH_TIMER_MS * win_size * HZ) / 1000); | |
441 | ||
442 | /* | |
443 | * If seq_num is less then starting win then ignore and drop the | |
444 | * packet | |
445 | */ | |
446 | if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {/* Wrap */ | |
447 | if (seq_num >= ((start_win + (TWOPOW11)) & (MAX_TID_VALUE - 1)) | |
448 | && (seq_num < start_win)) | |
449 | return -1; | |
450 | } else if ((seq_num < start_win) | |
451 | || (seq_num > (start_win + (TWOPOW11)))) { | |
452 | return -1; | |
453 | } | |
454 | ||
455 | /* | |
456 | * If this packet is a BAR we adjust seq_num as | |
457 | * WinStart = seq_num | |
458 | */ | |
459 | if (pkt_type == PKT_TYPE_BAR) | |
460 | seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1); | |
461 | ||
462 | if (((end_win < start_win) | |
463 | && (seq_num < (TWOPOW11 - (MAX_TID_VALUE - start_win))) | |
464 | && (seq_num > end_win)) || ((end_win > start_win) | |
465 | && ((seq_num > end_win) || (seq_num < start_win)))) { | |
466 | end_win = seq_num; | |
467 | if (((seq_num - win_size) + 1) >= 0) | |
468 | start_win = (end_win - win_size) + 1; | |
469 | else | |
470 | start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1; | |
471 | ret = mwifiex_11n_dispatch_pkt_until_start_win(priv, | |
472 | rx_reor_tbl_ptr, start_win); | |
473 | ||
474 | if (ret) | |
475 | return ret; | |
476 | } | |
477 | ||
478 | if (pkt_type != PKT_TYPE_BAR) { | |
479 | if (seq_num >= start_win) | |
480 | pkt_index = seq_num - start_win; | |
481 | else | |
482 | pkt_index = (seq_num+MAX_TID_VALUE) - start_win; | |
483 | ||
484 | if (rx_reor_tbl_ptr->rx_reorder_ptr[pkt_index]) | |
485 | return -1; | |
486 | ||
487 | rx_reor_tbl_ptr->rx_reorder_ptr[pkt_index] = payload; | |
488 | } | |
489 | ||
490 | /* | |
491 | * Dispatch all packets sequentially from start_win until a | |
492 | * hole is found and adjust the start_win appropriately | |
493 | */ | |
494 | ret = mwifiex_11n_scan_and_dispatch(priv, rx_reor_tbl_ptr); | |
495 | ||
496 | return ret; | |
497 | } | |
498 | ||
499 | /* | |
500 | * This function deletes an entry for a given TID/TA pair. | |
501 | * | |
502 | * The TID/TA are taken from del BA event body. | |
503 | */ | |
504 | void | |
505 | mwifiex_11n_delete_ba_stream_tbl(struct mwifiex_private *priv, int tid, | |
506 | u8 *peer_mac, u8 type, int initiator) | |
507 | { | |
508 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr; | |
509 | struct mwifiex_tx_ba_stream_tbl *ptx_tbl; | |
510 | u8 cleanup_rx_reorder_tbl; | |
511 | unsigned long flags; | |
512 | ||
513 | if (type == TYPE_DELBA_RECEIVE) | |
514 | cleanup_rx_reorder_tbl = (initiator) ? true : false; | |
515 | else | |
516 | cleanup_rx_reorder_tbl = (initiator) ? false : true; | |
517 | ||
518 | dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d, " | |
519 | "initiator=%d\n", peer_mac, tid, initiator); | |
520 | ||
521 | if (cleanup_rx_reorder_tbl) { | |
522 | rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv, tid, | |
523 | peer_mac); | |
524 | if (!rx_reor_tbl_ptr) { | |
525 | dev_dbg(priv->adapter->dev, | |
526 | "event: TID, TA not found in table\n"); | |
527 | return; | |
528 | } | |
529 | mwifiex_11n_delete_rx_reorder_tbl_entry(priv, rx_reor_tbl_ptr); | |
530 | } else { | |
531 | ptx_tbl = mwifiex_11n_get_tx_ba_stream_tbl(priv, tid, peer_mac); | |
532 | if (!ptx_tbl) { | |
533 | dev_dbg(priv->adapter->dev, | |
534 | "event: TID, RA not found in table\n"); | |
535 | return; | |
536 | } | |
537 | ||
538 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); | |
539 | mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl); | |
540 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); | |
541 | } | |
542 | } | |
543 | ||
544 | /* | |
545 | * This function handles the command response of an add BA response. | |
546 | * | |
547 | * Handling includes changing the header fields into CPU format and | |
548 | * creating the stream, provided the add BA is accepted. | |
549 | */ | |
550 | int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv, | |
551 | struct host_cmd_ds_command *resp) | |
552 | { | |
553 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = | |
554 | (struct host_cmd_ds_11n_addba_rsp *) | |
555 | &resp->params.add_ba_rsp; | |
556 | int tid, win_size; | |
557 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr = NULL; | |
558 | uint16_t block_ack_param_set; | |
559 | ||
560 | block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set); | |
561 | ||
562 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
563 | >> BLOCKACKPARAM_TID_POS; | |
564 | /* | |
565 | * Check if we had rejected the ADDBA, if yes then do not create | |
566 | * the stream | |
567 | */ | |
568 | if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) { | |
569 | win_size = (block_ack_param_set & | |
570 | IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) | |
571 | >> BLOCKACKPARAM_WINSIZE_POS; | |
572 | ||
573 | dev_dbg(priv->adapter->dev, "cmd: ADDBA RSP: %pM" | |
574 | " tid=%d ssn=%d win_size=%d\n", | |
575 | add_ba_rsp->peer_mac_addr, | |
576 | tid, add_ba_rsp->ssn, win_size); | |
577 | } else { | |
578 | dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n", | |
579 | add_ba_rsp->peer_mac_addr, tid); | |
580 | ||
581 | rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv, | |
582 | tid, add_ba_rsp->peer_mac_addr); | |
583 | if (rx_reor_tbl_ptr) | |
584 | mwifiex_11n_delete_rx_reorder_tbl_entry(priv, | |
585 | rx_reor_tbl_ptr); | |
586 | } | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
591 | /* | |
592 | * This function handles BA stream timeout event by preparing and sending | |
593 | * a command to the firmware. | |
594 | */ | |
595 | void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv, | |
596 | struct host_cmd_ds_11n_batimeout *event) | |
597 | { | |
598 | struct host_cmd_ds_11n_delba delba; | |
599 | ||
600 | memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba)); | |
601 | memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN); | |
602 | ||
603 | delba.del_ba_param_set |= | |
604 | cpu_to_le16((u16) event->tid << DELBA_TID_POS); | |
605 | delba.del_ba_param_set |= cpu_to_le16( | |
606 | (u16) event->origninator << DELBA_INITIATOR_POS); | |
607 | delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); | |
600f5d90 | 608 | mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba); |
5e6e3a92 BZ |
609 | } |
610 | ||
611 | /* | |
612 | * This function cleans up the Rx reorder table by deleting all the entries | |
613 | * and re-initializing. | |
614 | */ | |
615 | void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv) | |
616 | { | |
617 | struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node; | |
618 | unsigned long flags; | |
619 | ||
620 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
621 | list_for_each_entry_safe(del_tbl_ptr, tmp_node, | |
622 | &priv->rx_reorder_tbl_ptr, list) { | |
623 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
624 | mwifiex_11n_delete_rx_reorder_tbl_entry(priv, del_tbl_ptr); | |
625 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
626 | } | |
627 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
628 | ||
629 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); | |
630 | memset(priv->rx_seq, 0, sizeof(priv->rx_seq)); | |
631 | } |