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