Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: 802.11n RX Re-ordering | |
3 | * | |
65da33f5 | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
5e6e3a92 BZ |
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 | ||
4c9f9fb2 AK |
29 | /* This function will dispatch amsdu packet and forward it to kernel/upper |
30 | * layer. | |
31 | */ | |
32 | static int mwifiex_11n_dispatch_amsdu_pkt(struct mwifiex_private *priv, | |
33 | struct sk_buff *skb) | |
34 | { | |
35 | struct rxpd *local_rx_pd = (struct rxpd *)(skb->data); | |
36 | int ret; | |
37 | ||
38 | if (le16_to_cpu(local_rx_pd->rx_pkt_type) == PKT_TYPE_AMSDU) { | |
39 | struct sk_buff_head list; | |
40 | struct sk_buff *rx_skb; | |
41 | ||
42 | __skb_queue_head_init(&list); | |
43 | ||
44 | skb_pull(skb, le16_to_cpu(local_rx_pd->rx_pkt_offset)); | |
45 | skb_trim(skb, le16_to_cpu(local_rx_pd->rx_pkt_length)); | |
46 | ||
47 | ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr, | |
48 | priv->wdev->iftype, 0, false); | |
49 | ||
50 | while (!skb_queue_empty(&list)) { | |
51 | rx_skb = __skb_dequeue(&list); | |
52 | ret = mwifiex_recv_packet(priv, rx_skb); | |
53 | if (ret == -1) | |
54 | dev_err(priv->adapter->dev, | |
55 | "Rx of A-MSDU failed"); | |
56 | } | |
57 | return 0; | |
58 | } | |
59 | ||
60 | return -1; | |
61 | } | |
62 | ||
5e6e43eb AK |
63 | /* This function will process the rx packet and forward it to kernel/upper |
64 | * layer. | |
65 | */ | |
66 | static int mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv, void *payload) | |
67 | { | |
4c9f9fb2 AK |
68 | int ret = mwifiex_11n_dispatch_amsdu_pkt(priv, payload); |
69 | ||
70 | if (!ret) | |
71 | return 0; | |
72 | ||
5e6e43eb AK |
73 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
74 | return mwifiex_handle_uap_rx_forward(priv, payload); | |
75 | ||
76 | return mwifiex_process_rx_packet(priv, payload); | |
77 | } | |
78 | ||
5e6e3a92 | 79 | /* |
8c00228e YAP |
80 | * This function dispatches all packets in the Rx reorder table until the |
81 | * start window. | |
5e6e3a92 BZ |
82 | * |
83 | * There could be holes in the buffer, which are skipped by the function. | |
84 | * Since the buffer is linear, the function uses rotation to simulate | |
85 | * circular buffer. | |
86 | */ | |
ab581472 | 87 | static void |
5e6e43eb AK |
88 | mwifiex_11n_dispatch_pkt_until_start_win(struct mwifiex_private *priv, |
89 | struct mwifiex_rx_reorder_tbl *tbl, | |
90 | int start_win) | |
5e6e3a92 | 91 | { |
8c00228e | 92 | int pkt_to_send, i; |
270e58e8 | 93 | void *rx_tmp_ptr; |
5e6e3a92 BZ |
94 | unsigned long flags; |
95 | ||
8c00228e YAP |
96 | pkt_to_send = (start_win > tbl->start_win) ? |
97 | min((start_win - tbl->start_win), tbl->win_size) : | |
98 | tbl->win_size; | |
5e6e3a92 | 99 | |
8c00228e | 100 | for (i = 0; i < pkt_to_send; ++i) { |
5e6e3a92 BZ |
101 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); |
102 | rx_tmp_ptr = NULL; | |
8c00228e YAP |
103 | if (tbl->rx_reorder_ptr[i]) { |
104 | rx_tmp_ptr = tbl->rx_reorder_ptr[i]; | |
105 | tbl->rx_reorder_ptr[i] = NULL; | |
5e6e3a92 BZ |
106 | } |
107 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); | |
5e6e43eb AK |
108 | if (rx_tmp_ptr) |
109 | mwifiex_11n_dispatch_pkt(priv, 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 | */ | |
8c00228e YAP |
117 | for (i = 0; i < tbl->win_size - pkt_to_send; ++i) { |
118 | tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i]; | |
119 | tbl->rx_reorder_ptr[pkt_to_send + i] = NULL; | |
5e6e3a92 BZ |
120 | } |
121 | ||
8c00228e | 122 | tbl->start_win = start_win; |
5e6e3a92 | 123 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); |
5e6e3a92 BZ |
124 | } |
125 | ||
126 | /* | |
127 | * This function dispatches all packets in the Rx reorder table until | |
128 | * a hole is found. | |
129 | * | |
130 | * The start window is adjusted automatically when a hole is located. | |
131 | * Since the buffer is linear, the function uses rotation to simulate | |
132 | * circular buffer. | |
133 | */ | |
ab581472 | 134 | static void |
5e6e3a92 | 135 | mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv, |
8c00228e | 136 | struct mwifiex_rx_reorder_tbl *tbl) |
5e6e3a92 BZ |
137 | { |
138 | int i, j, xchg; | |
270e58e8 | 139 | void *rx_tmp_ptr; |
5e6e3a92 BZ |
140 | unsigned long flags; |
141 | ||
8c00228e | 142 | for (i = 0; i < tbl->win_size; ++i) { |
5e6e3a92 | 143 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); |
8c00228e | 144 | if (!tbl->rx_reorder_ptr[i]) { |
5e6e3a92 BZ |
145 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); |
146 | break; | |
147 | } | |
8c00228e YAP |
148 | rx_tmp_ptr = tbl->rx_reorder_ptr[i]; |
149 | tbl->rx_reorder_ptr[i] = NULL; | |
5e6e3a92 | 150 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); |
5e6e43eb | 151 | mwifiex_11n_dispatch_pkt(priv, rx_tmp_ptr); |
5e6e3a92 BZ |
152 | } |
153 | ||
154 | spin_lock_irqsave(&priv->rx_pkt_lock, flags); | |
155 | /* | |
156 | * We don't have a circular buffer, hence use rotation to simulate | |
157 | * circular buffer | |
158 | */ | |
159 | if (i > 0) { | |
8c00228e | 160 | xchg = tbl->win_size - i; |
5e6e3a92 | 161 | for (j = 0; j < xchg; ++j) { |
8c00228e YAP |
162 | tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j]; |
163 | tbl->rx_reorder_ptr[i + j] = NULL; | |
5e6e3a92 BZ |
164 | } |
165 | } | |
8c00228e | 166 | tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1); |
5e6e3a92 | 167 | spin_unlock_irqrestore(&priv->rx_pkt_lock, flags); |
5e6e3a92 BZ |
168 | } |
169 | ||
170 | /* | |
171 | * This function deletes the Rx reorder table and frees the memory. | |
172 | * | |
173 | * The function stops the associated timer and dispatches all the | |
174 | * pending packets in the Rx reorder table before deletion. | |
175 | */ | |
176 | static void | |
8c00228e YAP |
177 | mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv, |
178 | struct mwifiex_rx_reorder_tbl *tbl) | |
5e6e3a92 BZ |
179 | { |
180 | unsigned long flags; | |
63410c37 | 181 | int start_win; |
5e6e3a92 | 182 | |
8c00228e | 183 | if (!tbl) |
5e6e3a92 BZ |
184 | return; |
185 | ||
63410c37 | 186 | start_win = (tbl->start_win + tbl->win_size) & (MAX_TID_VALUE - 1); |
5e6e43eb | 187 | mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win); |
5e6e3a92 | 188 | |
629873f2 | 189 | del_timer_sync(&tbl->timer_context.timer); |
5e6e3a92 BZ |
190 | |
191 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
8c00228e | 192 | list_del(&tbl->list); |
5e6e3a92 BZ |
193 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); |
194 | ||
8c00228e YAP |
195 | kfree(tbl->rx_reorder_ptr); |
196 | kfree(tbl); | |
5e6e3a92 BZ |
197 | } |
198 | ||
199 | /* | |
200 | * This function returns the pointer to an entry in Rx reordering | |
201 | * table which matches the given TA/TID pair. | |
202 | */ | |
d1cf3b95 | 203 | struct mwifiex_rx_reorder_tbl * |
5e6e3a92 BZ |
204 | mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta) |
205 | { | |
8c00228e | 206 | struct mwifiex_rx_reorder_tbl *tbl; |
5e6e3a92 BZ |
207 | unsigned long flags; |
208 | ||
209 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
8c00228e YAP |
210 | list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) { |
211 | if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) { | |
5e6e3a92 BZ |
212 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, |
213 | flags); | |
8c00228e | 214 | return tbl; |
5e6e3a92 BZ |
215 | } |
216 | } | |
217 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
218 | ||
219 | return NULL; | |
220 | } | |
221 | ||
3e238a11 AP |
222 | /* This function retrieves the pointer to an entry in Rx reordering |
223 | * table which matches the given TA and deletes it. | |
224 | */ | |
225 | void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta) | |
226 | { | |
227 | struct mwifiex_rx_reorder_tbl *tbl, *tmp; | |
228 | unsigned long flags; | |
229 | ||
230 | if (!ta) | |
231 | return; | |
232 | ||
233 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
234 | list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) { | |
235 | if (!memcmp(tbl->ta, ta, ETH_ALEN)) { | |
236 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, | |
237 | flags); | |
238 | mwifiex_del_rx_reorder_entry(priv, tbl); | |
239 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
240 | } | |
241 | } | |
242 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
243 | ||
244 | return; | |
245 | } | |
246 | ||
5e6e3a92 BZ |
247 | /* |
248 | * This function finds the last sequence number used in the packets | |
249 | * buffered in Rx reordering table. | |
250 | */ | |
251 | static int | |
2d702830 | 252 | mwifiex_11n_find_last_seq_num(struct reorder_tmr_cnxt *ctx) |
5e6e3a92 | 253 | { |
2d702830 AK |
254 | struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr = ctx->ptr; |
255 | struct mwifiex_private *priv = ctx->priv; | |
256 | unsigned long flags; | |
5e6e3a92 BZ |
257 | int i; |
258 | ||
2d702830 AK |
259 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); |
260 | for (i = rx_reorder_tbl_ptr->win_size - 1; i >= 0; --i) { | |
261 | if (rx_reorder_tbl_ptr->rx_reorder_ptr[i]) { | |
262 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, | |
263 | flags); | |
5e6e3a92 | 264 | return i; |
2d702830 AK |
265 | } |
266 | } | |
267 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
5e6e3a92 BZ |
268 | |
269 | return -1; | |
270 | } | |
271 | ||
272 | /* | |
273 | * This function flushes all the packets in Rx reordering table. | |
274 | * | |
275 | * The function checks if any packets are currently buffered in the | |
276 | * table or not. In case there are packets available, it dispatches | |
277 | * them and then dumps the Rx reordering table. | |
278 | */ | |
279 | static void | |
280 | mwifiex_flush_data(unsigned long context) | |
281 | { | |
8c00228e | 282 | struct reorder_tmr_cnxt *ctx = |
5e6e3a92 | 283 | (struct reorder_tmr_cnxt *) context; |
63410c37 | 284 | int start_win, seq_num; |
5e6e3a92 | 285 | |
2d702830 | 286 | seq_num = mwifiex_11n_find_last_seq_num(ctx); |
bb7de2ba | 287 | |
63410c37 | 288 | if (seq_num < 0) |
bb7de2ba YAP |
289 | return; |
290 | ||
63410c37 AK |
291 | dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", seq_num); |
292 | start_win = (ctx->ptr->start_win + seq_num + 1) & (MAX_TID_VALUE - 1); | |
5e6e43eb AK |
293 | mwifiex_11n_dispatch_pkt_until_start_win(ctx->priv, ctx->ptr, |
294 | start_win); | |
5e6e3a92 BZ |
295 | } |
296 | ||
297 | /* | |
298 | * This function creates an entry in Rx reordering table for the | |
299 | * given TA/TID. | |
300 | * | |
301 | * The function also initializes the entry with sequence number, window | |
302 | * size as well as initializes the timer. | |
303 | * | |
304 | * If the received TA/TID pair is already present, all the packets are | |
305 | * dispatched and the window size is moved until the SSN. | |
306 | */ | |
307 | static void | |
308 | mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, | |
84266841 | 309 | int tid, int win_size, int seq_num) |
5e6e3a92 BZ |
310 | { |
311 | int i; | |
8c00228e | 312 | struct mwifiex_rx_reorder_tbl *tbl, *new_node; |
5e6e3a92 BZ |
313 | u16 last_seq = 0; |
314 | unsigned long flags; | |
5a009adf | 315 | struct mwifiex_sta_node *node; |
5e6e3a92 BZ |
316 | |
317 | /* | |
318 | * If we get a TID, ta pair which is already present dispatch all the | |
319 | * the packets and move the window size until the ssn | |
320 | */ | |
8c00228e YAP |
321 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta); |
322 | if (tbl) { | |
5e6e43eb | 323 | mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, seq_num); |
5e6e3a92 BZ |
324 | return; |
325 | } | |
8c00228e | 326 | /* if !tbl then create one */ |
5e6e3a92 | 327 | new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL); |
0d2e7a5c | 328 | if (!new_node) |
5e6e3a92 | 329 | return; |
5e6e3a92 BZ |
330 | |
331 | INIT_LIST_HEAD(&new_node->list); | |
332 | new_node->tid = tid; | |
333 | memcpy(new_node->ta, ta, ETH_ALEN); | |
334 | new_node->start_win = seq_num; | |
8acbea61 PS |
335 | new_node->init_win = seq_num; |
336 | new_node->flags = 0; | |
5a009adf AP |
337 | |
338 | if (mwifiex_queuing_ra_based(priv)) { | |
5e6e3a92 | 339 | dev_dbg(priv->adapter->dev, |
5a009adf | 340 | "info: AP/ADHOC:last_seq=%d start_win=%d\n", |
5e6e3a92 | 341 | last_seq, new_node->start_win); |
5a009adf AP |
342 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) { |
343 | node = mwifiex_get_sta_entry(priv, ta); | |
344 | if (node) | |
345 | last_seq = node->rx_seq[tid]; | |
346 | } | |
347 | } else { | |
daeb5bb4 AP |
348 | node = mwifiex_get_sta_entry(priv, ta); |
349 | if (node) | |
350 | last_seq = node->rx_seq[tid]; | |
351 | else | |
352 | last_seq = priv->rx_seq[tid]; | |
5a009adf | 353 | } |
5e6e3a92 | 354 | |
92583924 | 355 | if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM && |
8acbea61 | 356 | last_seq >= new_node->start_win) { |
5e6e3a92 | 357 | new_node->start_win = last_seq + 1; |
8acbea61 PS |
358 | new_node->flags |= RXREOR_INIT_WINDOW_SHIFT; |
359 | } | |
5e6e3a92 BZ |
360 | |
361 | new_node->win_size = win_size; | |
362 | ||
363 | new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size, | |
364 | GFP_KERNEL); | |
365 | if (!new_node->rx_reorder_ptr) { | |
366 | kfree((u8 *) new_node); | |
367 | dev_err(priv->adapter->dev, | |
368 | "%s: failed to alloc reorder_ptr\n", __func__); | |
369 | return; | |
370 | } | |
371 | ||
372 | new_node->timer_context.ptr = new_node; | |
373 | new_node->timer_context.priv = priv; | |
374 | ||
375 | init_timer(&new_node->timer_context.timer); | |
376 | new_node->timer_context.timer.function = mwifiex_flush_data; | |
377 | new_node->timer_context.timer.data = | |
378 | (unsigned long) &new_node->timer_context; | |
379 | ||
380 | for (i = 0; i < win_size; ++i) | |
381 | new_node->rx_reorder_ptr[i] = NULL; | |
382 | ||
383 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
384 | list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr); | |
385 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
5e6e3a92 BZ |
386 | } |
387 | ||
388 | /* | |
389 | * This function prepares command for adding a BA request. | |
390 | * | |
391 | * Preparation includes - | |
392 | * - Setting command ID and proper size | |
393 | * - Setting add BA request buffer | |
394 | * - Ensuring correct endian-ness | |
395 | */ | |
572e8f3e | 396 | int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 | 397 | { |
2c208890 | 398 | struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req; |
5e6e3a92 BZ |
399 | |
400 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ); | |
401 | cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN); | |
402 | memcpy(add_ba_req, data_buf, sizeof(*add_ba_req)); | |
403 | ||
404 | return 0; | |
405 | } | |
406 | ||
407 | /* | |
408 | * This function prepares command for adding a BA response. | |
409 | * | |
410 | * Preparation includes - | |
411 | * - Setting command ID and proper size | |
412 | * - Setting add BA response buffer | |
413 | * - Ensuring correct endian-ness | |
414 | */ | |
415 | int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv, | |
416 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 AK |
417 | struct host_cmd_ds_11n_addba_req |
418 | *cmd_addba_req) | |
5e6e3a92 | 419 | { |
2c208890 | 420 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp; |
b06c5321 AP |
421 | struct mwifiex_sta_node *sta_ptr; |
422 | u32 rx_win_size = priv->add_ba_param.rx_win_size; | |
270e58e8 YAP |
423 | u8 tid; |
424 | int win_size; | |
5e6e3a92 BZ |
425 | uint16_t block_ack_param_set; |
426 | ||
b06c5321 AP |
427 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && |
428 | ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && | |
429 | priv->adapter->is_hw_11ac_capable && | |
430 | memcmp(priv->cfg_bssid, cmd_addba_req->peer_mac_addr, ETH_ALEN)) { | |
431 | sta_ptr = mwifiex_get_sta_entry(priv, | |
432 | cmd_addba_req->peer_mac_addr); | |
433 | if (!sta_ptr) { | |
434 | dev_warn(priv->adapter->dev, | |
435 | "BA setup with unknown TDLS peer %pM!\n", | |
436 | cmd_addba_req->peer_mac_addr); | |
437 | return -1; | |
438 | } | |
439 | if (sta_ptr->is_11ac_enabled) | |
440 | rx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE; | |
441 | } | |
442 | ||
5e6e3a92 BZ |
443 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP); |
444 | cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN); | |
445 | ||
446 | memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr, | |
447 | ETH_ALEN); | |
448 | add_ba_rsp->dialog_token = cmd_addba_req->dialog_token; | |
449 | add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo; | |
450 | add_ba_rsp->ssn = cmd_addba_req->ssn; | |
451 | ||
452 | block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set); | |
453 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
454 | >> BLOCKACKPARAM_TID_POS; | |
455 | add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT); | |
456 | block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; | |
4c9f9fb2 AK |
457 | |
458 | /* If we don't support AMSDU inside AMPDU, reset the bit */ | |
459 | if (!priv->add_ba_param.rx_amsdu || | |
460 | (priv->aggr_prio_tbl[tid].amsdu == BA_STREAM_NOT_ALLOWED)) | |
461 | block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK; | |
b06c5321 | 462 | block_ack_param_set |= rx_win_size << BLOCKACKPARAM_WINSIZE_POS; |
5e6e3a92 BZ |
463 | add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set); |
464 | win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set) | |
465 | & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) | |
466 | >> BLOCKACKPARAM_WINSIZE_POS; | |
467 | cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set); | |
468 | ||
469 | mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr, | |
84266841 YAP |
470 | tid, win_size, |
471 | le16_to_cpu(cmd_addba_req->ssn)); | |
5e6e3a92 BZ |
472 | return 0; |
473 | } | |
474 | ||
475 | /* | |
476 | * This function prepares command for deleting a BA request. | |
477 | * | |
478 | * Preparation includes - | |
479 | * - Setting command ID and proper size | |
480 | * - Setting del BA request buffer | |
481 | * - Ensuring correct endian-ness | |
482 | */ | |
572e8f3e | 483 | int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 | 484 | { |
2c208890 | 485 | struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba; |
5e6e3a92 BZ |
486 | |
487 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA); | |
488 | cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN); | |
489 | memcpy(del_ba, data_buf, sizeof(*del_ba)); | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | /* | |
495 | * This function identifies if Rx reordering is needed for a received packet. | |
496 | * | |
497 | * In case reordering is required, the function will do the reordering | |
498 | * before sending it to kernel. | |
499 | * | |
500 | * The Rx reorder table is checked first with the received TID/TA pair. If | |
501 | * not found, the received packet is dispatched immediately. But if found, | |
502 | * the packet is reordered and all the packets in the updated Rx reordering | |
503 | * table is dispatched until a hole is found. | |
504 | * | |
505 | * For sequence number less than the starting window, the packet is dropped. | |
506 | */ | |
507 | int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv, | |
508 | u16 seq_num, u16 tid, | |
509 | u8 *ta, u8 pkt_type, void *payload) | |
510 | { | |
8c00228e | 511 | struct mwifiex_rx_reorder_tbl *tbl; |
ab581472 | 512 | int start_win, end_win, win_size; |
270e58e8 | 513 | u16 pkt_index; |
8acbea61 | 514 | bool init_window_shift = false; |
5e6e3a92 | 515 | |
2c208890 | 516 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta); |
8c00228e | 517 | if (!tbl) { |
5e6e43eb AK |
518 | if (pkt_type != PKT_TYPE_BAR) |
519 | mwifiex_11n_dispatch_pkt(priv, payload); | |
5e6e3a92 BZ |
520 | return 0; |
521 | } | |
4c9f9fb2 AK |
522 | |
523 | if ((pkt_type == PKT_TYPE_AMSDU) && !tbl->amsdu) { | |
524 | mwifiex_11n_dispatch_pkt(priv, payload); | |
525 | return 0; | |
526 | } | |
527 | ||
8c00228e YAP |
528 | start_win = tbl->start_win; |
529 | win_size = tbl->win_size; | |
5e6e3a92 | 530 | end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1); |
8acbea61 PS |
531 | if (tbl->flags & RXREOR_INIT_WINDOW_SHIFT) { |
532 | init_window_shift = true; | |
533 | tbl->flags &= ~RXREOR_INIT_WINDOW_SHIFT; | |
534 | } | |
8c00228e | 535 | mod_timer(&tbl->timer_context.timer, |
4587eea5 | 536 | jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size)); |
5e6e3a92 | 537 | |
2db96c3d AP |
538 | if (tbl->flags & RXREOR_FORCE_NO_DROP) { |
539 | dev_dbg(priv->adapter->dev, | |
540 | "RXREOR_FORCE_NO_DROP when HS is activated\n"); | |
541 | tbl->flags &= ~RXREOR_FORCE_NO_DROP; | |
8acbea61 PS |
542 | } else if (init_window_shift && seq_num < start_win && |
543 | seq_num >= tbl->init_win) { | |
544 | dev_dbg(priv->adapter->dev, | |
545 | "Sender TID sequence number reset %d->%d for SSN %d\n", | |
546 | start_win, seq_num, tbl->init_win); | |
547 | tbl->start_win = start_win = seq_num; | |
548 | end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1); | |
2db96c3d | 549 | } else { |
8acbea61 PS |
550 | /* |
551 | * If seq_num is less then starting win then ignore and drop | |
552 | * the packet | |
553 | */ | |
2db96c3d AP |
554 | if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) { |
555 | if (seq_num >= ((start_win + TWOPOW11) & | |
556 | (MAX_TID_VALUE - 1)) && | |
557 | seq_num < start_win) | |
558 | return -1; | |
559 | } else if ((seq_num < start_win) || | |
560 | (seq_num > (start_win + TWOPOW11))) { | |
5e6e3a92 | 561 | return -1; |
2db96c3d | 562 | } |
5e6e3a92 BZ |
563 | } |
564 | ||
565 | /* | |
566 | * If this packet is a BAR we adjust seq_num as | |
567 | * WinStart = seq_num | |
568 | */ | |
569 | if (pkt_type == PKT_TYPE_BAR) | |
570 | seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1); | |
571 | ||
84266841 | 572 | if (((end_win < start_win) && |
2db96c3d | 573 | (seq_num < start_win) && (seq_num > end_win)) || |
84266841 YAP |
574 | ((end_win > start_win) && ((seq_num > end_win) || |
575 | (seq_num < start_win)))) { | |
5e6e3a92 BZ |
576 | end_win = seq_num; |
577 | if (((seq_num - win_size) + 1) >= 0) | |
578 | start_win = (end_win - win_size) + 1; | |
579 | else | |
580 | start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1; | |
5e6e43eb | 581 | mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win); |
5e6e3a92 BZ |
582 | } |
583 | ||
584 | if (pkt_type != PKT_TYPE_BAR) { | |
585 | if (seq_num >= start_win) | |
586 | pkt_index = seq_num - start_win; | |
587 | else | |
588 | pkt_index = (seq_num+MAX_TID_VALUE) - start_win; | |
589 | ||
8c00228e | 590 | if (tbl->rx_reorder_ptr[pkt_index]) |
5e6e3a92 BZ |
591 | return -1; |
592 | ||
8c00228e | 593 | tbl->rx_reorder_ptr[pkt_index] = payload; |
5e6e3a92 BZ |
594 | } |
595 | ||
596 | /* | |
597 | * Dispatch all packets sequentially from start_win until a | |
598 | * hole is found and adjust the start_win appropriately | |
599 | */ | |
8c00228e | 600 | mwifiex_11n_scan_and_dispatch(priv, tbl); |
5e6e3a92 | 601 | |
ab581472 | 602 | return 0; |
5e6e3a92 BZ |
603 | } |
604 | ||
605 | /* | |
606 | * This function deletes an entry for a given TID/TA pair. | |
607 | * | |
608 | * The TID/TA are taken from del BA event body. | |
609 | */ | |
610 | void | |
3e822635 YAP |
611 | mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac, |
612 | u8 type, int initiator) | |
5e6e3a92 | 613 | { |
8c00228e | 614 | struct mwifiex_rx_reorder_tbl *tbl; |
5e6e3a92 BZ |
615 | struct mwifiex_tx_ba_stream_tbl *ptx_tbl; |
616 | u8 cleanup_rx_reorder_tbl; | |
617 | unsigned long flags; | |
618 | ||
619 | if (type == TYPE_DELBA_RECEIVE) | |
620 | cleanup_rx_reorder_tbl = (initiator) ? true : false; | |
621 | else | |
622 | cleanup_rx_reorder_tbl = (initiator) ? false : true; | |
623 | ||
84266841 YAP |
624 | dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n", |
625 | peer_mac, tid, initiator); | |
5e6e3a92 BZ |
626 | |
627 | if (cleanup_rx_reorder_tbl) { | |
8c00228e | 628 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
5e6e3a92 | 629 | peer_mac); |
8c00228e | 630 | if (!tbl) { |
5e6e3a92 | 631 | dev_dbg(priv->adapter->dev, |
84266841 | 632 | "event: TID, TA not found in table\n"); |
5e6e3a92 BZ |
633 | return; |
634 | } | |
8c00228e | 635 | mwifiex_del_rx_reorder_entry(priv, tbl); |
5e6e3a92 | 636 | } else { |
3e822635 | 637 | ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac); |
5e6e3a92 BZ |
638 | if (!ptx_tbl) { |
639 | dev_dbg(priv->adapter->dev, | |
84266841 | 640 | "event: TID, RA not found in table\n"); |
5e6e3a92 BZ |
641 | return; |
642 | } | |
643 | ||
644 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); | |
645 | mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl); | |
646 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); | |
647 | } | |
648 | } | |
649 | ||
650 | /* | |
651 | * This function handles the command response of an add BA response. | |
652 | * | |
653 | * Handling includes changing the header fields into CPU format and | |
654 | * creating the stream, provided the add BA is accepted. | |
655 | */ | |
656 | int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv, | |
657 | struct host_cmd_ds_command *resp) | |
658 | { | |
2c208890 | 659 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp; |
5e6e3a92 | 660 | int tid, win_size; |
8c00228e | 661 | struct mwifiex_rx_reorder_tbl *tbl; |
5e6e3a92 BZ |
662 | uint16_t block_ack_param_set; |
663 | ||
664 | block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set); | |
665 | ||
666 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
667 | >> BLOCKACKPARAM_TID_POS; | |
668 | /* | |
669 | * Check if we had rejected the ADDBA, if yes then do not create | |
670 | * the stream | |
671 | */ | |
63410c37 | 672 | if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) { |
5e6e3a92 | 673 | dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n", |
84266841 | 674 | add_ba_rsp->peer_mac_addr, tid); |
5e6e3a92 | 675 | |
8c00228e YAP |
676 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
677 | add_ba_rsp->peer_mac_addr); | |
678 | if (tbl) | |
679 | mwifiex_del_rx_reorder_entry(priv, tbl); | |
63410c37 AK |
680 | |
681 | return 0; | |
5e6e3a92 BZ |
682 | } |
683 | ||
63410c37 AK |
684 | win_size = (block_ack_param_set & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) |
685 | >> BLOCKACKPARAM_WINSIZE_POS; | |
686 | ||
4c9f9fb2 AK |
687 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
688 | add_ba_rsp->peer_mac_addr); | |
689 | if (tbl) { | |
690 | if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) && | |
691 | priv->add_ba_param.rx_amsdu && | |
692 | (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED)) | |
693 | tbl->amsdu = true; | |
694 | else | |
695 | tbl->amsdu = false; | |
696 | } | |
697 | ||
63410c37 AK |
698 | dev_dbg(priv->adapter->dev, |
699 | "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n", | |
700 | add_ba_rsp->peer_mac_addr, tid, add_ba_rsp->ssn, win_size); | |
701 | ||
5e6e3a92 BZ |
702 | return 0; |
703 | } | |
704 | ||
705 | /* | |
706 | * This function handles BA stream timeout event by preparing and sending | |
707 | * a command to the firmware. | |
708 | */ | |
709 | void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv, | |
710 | struct host_cmd_ds_11n_batimeout *event) | |
711 | { | |
712 | struct host_cmd_ds_11n_delba delba; | |
713 | ||
714 | memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba)); | |
715 | memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN); | |
716 | ||
717 | delba.del_ba_param_set |= | |
718 | cpu_to_le16((u16) event->tid << DELBA_TID_POS); | |
719 | delba.del_ba_param_set |= cpu_to_le16( | |
720 | (u16) event->origninator << DELBA_INITIATOR_POS); | |
721 | delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); | |
fa0ecbb9 | 722 | mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba, false); |
5e6e3a92 BZ |
723 | } |
724 | ||
725 | /* | |
726 | * This function cleans up the Rx reorder table by deleting all the entries | |
727 | * and re-initializing. | |
728 | */ | |
729 | void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv) | |
730 | { | |
731 | struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node; | |
732 | unsigned long flags; | |
733 | ||
734 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
735 | list_for_each_entry_safe(del_tbl_ptr, tmp_node, | |
736 | &priv->rx_reorder_tbl_ptr, list) { | |
737 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
8c00228e | 738 | mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr); |
5e6e3a92 BZ |
739 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); |
740 | } | |
2d702830 | 741 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); |
5e6e3a92 BZ |
742 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); |
743 | ||
92583924 | 744 | mwifiex_reset_11n_rx_seq_num(priv); |
5e6e3a92 | 745 | } |
2db96c3d AP |
746 | |
747 | /* | |
748 | * This function updates all rx_reorder_tbl's flags. | |
749 | */ | |
750 | void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags) | |
751 | { | |
752 | struct mwifiex_private *priv; | |
753 | struct mwifiex_rx_reorder_tbl *tbl; | |
754 | unsigned long lock_flags; | |
755 | int i; | |
756 | ||
757 | for (i = 0; i < adapter->priv_num; i++) { | |
758 | priv = adapter->priv[i]; | |
759 | if (!priv) | |
760 | continue; | |
2db96c3d AP |
761 | |
762 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags); | |
2d702830 AK |
763 | if (list_empty(&priv->rx_reorder_tbl_ptr)) { |
764 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, | |
765 | lock_flags); | |
766 | continue; | |
767 | } | |
768 | ||
2db96c3d AP |
769 | list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) |
770 | tbl->flags = flags; | |
771 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags); | |
772 | } | |
773 | ||
774 | return; | |
775 | } |