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