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