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