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