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 | ||
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 | |
252 | mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr) | |
253 | { | |
254 | int i; | |
255 | ||
256 | for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i) | |
257 | if (rx_reorder_tbl_ptr->rx_reorder_ptr[i]) | |
258 | return i; | |
259 | ||
260 | return -1; | |
261 | } | |
262 | ||
263 | /* | |
264 | * This function flushes all the packets in Rx reordering table. | |
265 | * | |
266 | * The function checks if any packets are currently buffered in the | |
267 | * table or not. In case there are packets available, it dispatches | |
268 | * them and then dumps the Rx reordering table. | |
269 | */ | |
270 | static void | |
271 | mwifiex_flush_data(unsigned long context) | |
272 | { | |
8c00228e | 273 | struct reorder_tmr_cnxt *ctx = |
5e6e3a92 | 274 | (struct reorder_tmr_cnxt *) context; |
63410c37 | 275 | int start_win, seq_num; |
5e6e3a92 | 276 | |
63410c37 | 277 | seq_num = mwifiex_11n_find_last_seq_num(ctx->ptr); |
bb7de2ba | 278 | |
63410c37 | 279 | if (seq_num < 0) |
bb7de2ba YAP |
280 | return; |
281 | ||
63410c37 AK |
282 | dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", seq_num); |
283 | start_win = (ctx->ptr->start_win + seq_num + 1) & (MAX_TID_VALUE - 1); | |
5e6e43eb AK |
284 | mwifiex_11n_dispatch_pkt_until_start_win(ctx->priv, ctx->ptr, |
285 | start_win); | |
5e6e3a92 BZ |
286 | } |
287 | ||
288 | /* | |
289 | * This function creates an entry in Rx reordering table for the | |
290 | * given TA/TID. | |
291 | * | |
292 | * The function also initializes the entry with sequence number, window | |
293 | * size as well as initializes the timer. | |
294 | * | |
295 | * If the received TA/TID pair is already present, all the packets are | |
296 | * dispatched and the window size is moved until the SSN. | |
297 | */ | |
298 | static void | |
299 | mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, | |
84266841 | 300 | int tid, int win_size, int seq_num) |
5e6e3a92 BZ |
301 | { |
302 | int i; | |
8c00228e | 303 | struct mwifiex_rx_reorder_tbl *tbl, *new_node; |
5e6e3a92 BZ |
304 | u16 last_seq = 0; |
305 | unsigned long flags; | |
5a009adf | 306 | struct mwifiex_sta_node *node; |
5e6e3a92 BZ |
307 | |
308 | /* | |
309 | * If we get a TID, ta pair which is already present dispatch all the | |
310 | * the packets and move the window size until the ssn | |
311 | */ | |
8c00228e YAP |
312 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta); |
313 | if (tbl) { | |
5e6e43eb | 314 | mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, seq_num); |
5e6e3a92 BZ |
315 | return; |
316 | } | |
8c00228e | 317 | /* if !tbl then create one */ |
5e6e3a92 | 318 | new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL); |
0d2e7a5c | 319 | if (!new_node) |
5e6e3a92 | 320 | return; |
5e6e3a92 BZ |
321 | |
322 | INIT_LIST_HEAD(&new_node->list); | |
323 | new_node->tid = tid; | |
324 | memcpy(new_node->ta, ta, ETH_ALEN); | |
325 | new_node->start_win = seq_num; | |
8acbea61 PS |
326 | new_node->init_win = seq_num; |
327 | new_node->flags = 0; | |
5a009adf AP |
328 | |
329 | if (mwifiex_queuing_ra_based(priv)) { | |
5e6e3a92 | 330 | dev_dbg(priv->adapter->dev, |
5a009adf | 331 | "info: AP/ADHOC:last_seq=%d start_win=%d\n", |
5e6e3a92 | 332 | last_seq, new_node->start_win); |
5a009adf AP |
333 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) { |
334 | node = mwifiex_get_sta_entry(priv, ta); | |
335 | if (node) | |
336 | last_seq = node->rx_seq[tid]; | |
337 | } | |
338 | } else { | |
daeb5bb4 AP |
339 | node = mwifiex_get_sta_entry(priv, ta); |
340 | if (node) | |
341 | last_seq = node->rx_seq[tid]; | |
342 | else | |
343 | last_seq = priv->rx_seq[tid]; | |
5a009adf | 344 | } |
5e6e3a92 | 345 | |
92583924 | 346 | if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM && |
8acbea61 | 347 | last_seq >= new_node->start_win) { |
5e6e3a92 | 348 | new_node->start_win = last_seq + 1; |
8acbea61 PS |
349 | new_node->flags |= RXREOR_INIT_WINDOW_SHIFT; |
350 | } | |
5e6e3a92 BZ |
351 | |
352 | new_node->win_size = win_size; | |
353 | ||
354 | new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size, | |
355 | GFP_KERNEL); | |
356 | if (!new_node->rx_reorder_ptr) { | |
357 | kfree((u8 *) new_node); | |
358 | dev_err(priv->adapter->dev, | |
359 | "%s: failed to alloc reorder_ptr\n", __func__); | |
360 | return; | |
361 | } | |
362 | ||
363 | new_node->timer_context.ptr = new_node; | |
364 | new_node->timer_context.priv = priv; | |
365 | ||
366 | init_timer(&new_node->timer_context.timer); | |
367 | new_node->timer_context.timer.function = mwifiex_flush_data; | |
368 | new_node->timer_context.timer.data = | |
369 | (unsigned long) &new_node->timer_context; | |
370 | ||
371 | for (i = 0; i < win_size; ++i) | |
372 | new_node->rx_reorder_ptr[i] = NULL; | |
373 | ||
374 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
375 | list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr); | |
376 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
5e6e3a92 BZ |
377 | } |
378 | ||
379 | /* | |
380 | * This function prepares command for adding a BA request. | |
381 | * | |
382 | * Preparation includes - | |
383 | * - Setting command ID and proper size | |
384 | * - Setting add BA request buffer | |
385 | * - Ensuring correct endian-ness | |
386 | */ | |
572e8f3e | 387 | int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 | 388 | { |
2c208890 | 389 | struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req; |
5e6e3a92 BZ |
390 | |
391 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ); | |
392 | cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN); | |
393 | memcpy(add_ba_req, data_buf, sizeof(*add_ba_req)); | |
394 | ||
395 | return 0; | |
396 | } | |
397 | ||
398 | /* | |
399 | * This function prepares command for adding a BA response. | |
400 | * | |
401 | * Preparation includes - | |
402 | * - Setting command ID and proper size | |
403 | * - Setting add BA response buffer | |
404 | * - Ensuring correct endian-ness | |
405 | */ | |
406 | int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv, | |
407 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 AK |
408 | struct host_cmd_ds_11n_addba_req |
409 | *cmd_addba_req) | |
5e6e3a92 | 410 | { |
2c208890 | 411 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp; |
b06c5321 AP |
412 | struct mwifiex_sta_node *sta_ptr; |
413 | u32 rx_win_size = priv->add_ba_param.rx_win_size; | |
270e58e8 YAP |
414 | u8 tid; |
415 | int win_size; | |
5e6e3a92 BZ |
416 | uint16_t block_ack_param_set; |
417 | ||
b06c5321 AP |
418 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && |
419 | ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && | |
420 | priv->adapter->is_hw_11ac_capable && | |
421 | memcmp(priv->cfg_bssid, cmd_addba_req->peer_mac_addr, ETH_ALEN)) { | |
422 | sta_ptr = mwifiex_get_sta_entry(priv, | |
423 | cmd_addba_req->peer_mac_addr); | |
424 | if (!sta_ptr) { | |
425 | dev_warn(priv->adapter->dev, | |
426 | "BA setup with unknown TDLS peer %pM!\n", | |
427 | cmd_addba_req->peer_mac_addr); | |
428 | return -1; | |
429 | } | |
430 | if (sta_ptr->is_11ac_enabled) | |
431 | rx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE; | |
432 | } | |
433 | ||
5e6e3a92 BZ |
434 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP); |
435 | cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN); | |
436 | ||
437 | memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr, | |
438 | ETH_ALEN); | |
439 | add_ba_rsp->dialog_token = cmd_addba_req->dialog_token; | |
440 | add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo; | |
441 | add_ba_rsp->ssn = cmd_addba_req->ssn; | |
442 | ||
443 | block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set); | |
444 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
445 | >> BLOCKACKPARAM_TID_POS; | |
446 | add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT); | |
447 | block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; | |
4c9f9fb2 AK |
448 | |
449 | /* If we don't support AMSDU inside AMPDU, reset the bit */ | |
450 | if (!priv->add_ba_param.rx_amsdu || | |
451 | (priv->aggr_prio_tbl[tid].amsdu == BA_STREAM_NOT_ALLOWED)) | |
452 | block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK; | |
b06c5321 | 453 | block_ack_param_set |= rx_win_size << BLOCKACKPARAM_WINSIZE_POS; |
5e6e3a92 BZ |
454 | add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set); |
455 | win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set) | |
456 | & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) | |
457 | >> BLOCKACKPARAM_WINSIZE_POS; | |
458 | cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set); | |
459 | ||
460 | mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr, | |
84266841 YAP |
461 | tid, win_size, |
462 | le16_to_cpu(cmd_addba_req->ssn)); | |
5e6e3a92 BZ |
463 | return 0; |
464 | } | |
465 | ||
466 | /* | |
467 | * This function prepares command for deleting a BA request. | |
468 | * | |
469 | * Preparation includes - | |
470 | * - Setting command ID and proper size | |
471 | * - Setting del BA request buffer | |
472 | * - Ensuring correct endian-ness | |
473 | */ | |
572e8f3e | 474 | int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf) |
5e6e3a92 | 475 | { |
2c208890 | 476 | struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba; |
5e6e3a92 BZ |
477 | |
478 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA); | |
479 | cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN); | |
480 | memcpy(del_ba, data_buf, sizeof(*del_ba)); | |
481 | ||
482 | return 0; | |
483 | } | |
484 | ||
485 | /* | |
486 | * This function identifies if Rx reordering is needed for a received packet. | |
487 | * | |
488 | * In case reordering is required, the function will do the reordering | |
489 | * before sending it to kernel. | |
490 | * | |
491 | * The Rx reorder table is checked first with the received TID/TA pair. If | |
492 | * not found, the received packet is dispatched immediately. But if found, | |
493 | * the packet is reordered and all the packets in the updated Rx reordering | |
494 | * table is dispatched until a hole is found. | |
495 | * | |
496 | * For sequence number less than the starting window, the packet is dropped. | |
497 | */ | |
498 | int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv, | |
499 | u16 seq_num, u16 tid, | |
500 | u8 *ta, u8 pkt_type, void *payload) | |
501 | { | |
8c00228e | 502 | struct mwifiex_rx_reorder_tbl *tbl; |
ab581472 | 503 | int start_win, end_win, win_size; |
270e58e8 | 504 | u16 pkt_index; |
8acbea61 | 505 | bool init_window_shift = false; |
5e6e3a92 | 506 | |
2c208890 | 507 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta); |
8c00228e | 508 | if (!tbl) { |
5e6e43eb AK |
509 | if (pkt_type != PKT_TYPE_BAR) |
510 | mwifiex_11n_dispatch_pkt(priv, payload); | |
5e6e3a92 BZ |
511 | return 0; |
512 | } | |
4c9f9fb2 AK |
513 | |
514 | if ((pkt_type == PKT_TYPE_AMSDU) && !tbl->amsdu) { | |
515 | mwifiex_11n_dispatch_pkt(priv, payload); | |
516 | return 0; | |
517 | } | |
518 | ||
8c00228e YAP |
519 | start_win = tbl->start_win; |
520 | win_size = tbl->win_size; | |
5e6e3a92 | 521 | end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1); |
8acbea61 PS |
522 | if (tbl->flags & RXREOR_INIT_WINDOW_SHIFT) { |
523 | init_window_shift = true; | |
524 | tbl->flags &= ~RXREOR_INIT_WINDOW_SHIFT; | |
525 | } | |
8c00228e | 526 | mod_timer(&tbl->timer_context.timer, |
4587eea5 | 527 | jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size)); |
5e6e3a92 | 528 | |
2db96c3d AP |
529 | if (tbl->flags & RXREOR_FORCE_NO_DROP) { |
530 | dev_dbg(priv->adapter->dev, | |
531 | "RXREOR_FORCE_NO_DROP when HS is activated\n"); | |
532 | tbl->flags &= ~RXREOR_FORCE_NO_DROP; | |
8acbea61 PS |
533 | } else if (init_window_shift && seq_num < start_win && |
534 | seq_num >= tbl->init_win) { | |
535 | dev_dbg(priv->adapter->dev, | |
536 | "Sender TID sequence number reset %d->%d for SSN %d\n", | |
537 | start_win, seq_num, tbl->init_win); | |
538 | tbl->start_win = start_win = seq_num; | |
539 | end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1); | |
2db96c3d | 540 | } else { |
8acbea61 PS |
541 | /* |
542 | * If seq_num is less then starting win then ignore and drop | |
543 | * the packet | |
544 | */ | |
2db96c3d AP |
545 | if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) { |
546 | if (seq_num >= ((start_win + TWOPOW11) & | |
547 | (MAX_TID_VALUE - 1)) && | |
548 | seq_num < start_win) | |
549 | return -1; | |
550 | } else if ((seq_num < start_win) || | |
551 | (seq_num > (start_win + TWOPOW11))) { | |
5e6e3a92 | 552 | return -1; |
2db96c3d | 553 | } |
5e6e3a92 BZ |
554 | } |
555 | ||
556 | /* | |
557 | * If this packet is a BAR we adjust seq_num as | |
558 | * WinStart = seq_num | |
559 | */ | |
560 | if (pkt_type == PKT_TYPE_BAR) | |
561 | seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1); | |
562 | ||
84266841 | 563 | if (((end_win < start_win) && |
2db96c3d | 564 | (seq_num < start_win) && (seq_num > end_win)) || |
84266841 YAP |
565 | ((end_win > start_win) && ((seq_num > end_win) || |
566 | (seq_num < start_win)))) { | |
5e6e3a92 BZ |
567 | end_win = seq_num; |
568 | if (((seq_num - win_size) + 1) >= 0) | |
569 | start_win = (end_win - win_size) + 1; | |
570 | else | |
571 | start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1; | |
5e6e43eb | 572 | mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win); |
5e6e3a92 BZ |
573 | } |
574 | ||
575 | if (pkt_type != PKT_TYPE_BAR) { | |
576 | if (seq_num >= start_win) | |
577 | pkt_index = seq_num - start_win; | |
578 | else | |
579 | pkt_index = (seq_num+MAX_TID_VALUE) - start_win; | |
580 | ||
8c00228e | 581 | if (tbl->rx_reorder_ptr[pkt_index]) |
5e6e3a92 BZ |
582 | return -1; |
583 | ||
8c00228e | 584 | tbl->rx_reorder_ptr[pkt_index] = payload; |
5e6e3a92 BZ |
585 | } |
586 | ||
587 | /* | |
588 | * Dispatch all packets sequentially from start_win until a | |
589 | * hole is found and adjust the start_win appropriately | |
590 | */ | |
8c00228e | 591 | mwifiex_11n_scan_and_dispatch(priv, tbl); |
5e6e3a92 | 592 | |
ab581472 | 593 | return 0; |
5e6e3a92 BZ |
594 | } |
595 | ||
596 | /* | |
597 | * This function deletes an entry for a given TID/TA pair. | |
598 | * | |
599 | * The TID/TA are taken from del BA event body. | |
600 | */ | |
601 | void | |
3e822635 YAP |
602 | mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac, |
603 | u8 type, int initiator) | |
5e6e3a92 | 604 | { |
8c00228e | 605 | struct mwifiex_rx_reorder_tbl *tbl; |
5e6e3a92 BZ |
606 | struct mwifiex_tx_ba_stream_tbl *ptx_tbl; |
607 | u8 cleanup_rx_reorder_tbl; | |
608 | unsigned long flags; | |
609 | ||
610 | if (type == TYPE_DELBA_RECEIVE) | |
611 | cleanup_rx_reorder_tbl = (initiator) ? true : false; | |
612 | else | |
613 | cleanup_rx_reorder_tbl = (initiator) ? false : true; | |
614 | ||
84266841 YAP |
615 | dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n", |
616 | peer_mac, tid, initiator); | |
5e6e3a92 BZ |
617 | |
618 | if (cleanup_rx_reorder_tbl) { | |
8c00228e | 619 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
5e6e3a92 | 620 | peer_mac); |
8c00228e | 621 | if (!tbl) { |
5e6e3a92 | 622 | dev_dbg(priv->adapter->dev, |
84266841 | 623 | "event: TID, TA not found in table\n"); |
5e6e3a92 BZ |
624 | return; |
625 | } | |
8c00228e | 626 | mwifiex_del_rx_reorder_entry(priv, tbl); |
5e6e3a92 | 627 | } else { |
3e822635 | 628 | ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac); |
5e6e3a92 BZ |
629 | if (!ptx_tbl) { |
630 | dev_dbg(priv->adapter->dev, | |
84266841 | 631 | "event: TID, RA not found in table\n"); |
5e6e3a92 BZ |
632 | return; |
633 | } | |
634 | ||
635 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); | |
636 | mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl); | |
637 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); | |
638 | } | |
639 | } | |
640 | ||
641 | /* | |
642 | * This function handles the command response of an add BA response. | |
643 | * | |
644 | * Handling includes changing the header fields into CPU format and | |
645 | * creating the stream, provided the add BA is accepted. | |
646 | */ | |
647 | int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv, | |
648 | struct host_cmd_ds_command *resp) | |
649 | { | |
2c208890 | 650 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp; |
5e6e3a92 | 651 | int tid, win_size; |
8c00228e | 652 | struct mwifiex_rx_reorder_tbl *tbl; |
5e6e3a92 BZ |
653 | uint16_t block_ack_param_set; |
654 | ||
655 | block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set); | |
656 | ||
657 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) | |
658 | >> BLOCKACKPARAM_TID_POS; | |
659 | /* | |
660 | * Check if we had rejected the ADDBA, if yes then do not create | |
661 | * the stream | |
662 | */ | |
63410c37 | 663 | if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) { |
5e6e3a92 | 664 | dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n", |
84266841 | 665 | add_ba_rsp->peer_mac_addr, tid); |
5e6e3a92 | 666 | |
8c00228e YAP |
667 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
668 | add_ba_rsp->peer_mac_addr); | |
669 | if (tbl) | |
670 | mwifiex_del_rx_reorder_entry(priv, tbl); | |
63410c37 AK |
671 | |
672 | return 0; | |
5e6e3a92 BZ |
673 | } |
674 | ||
63410c37 AK |
675 | win_size = (block_ack_param_set & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) |
676 | >> BLOCKACKPARAM_WINSIZE_POS; | |
677 | ||
4c9f9fb2 AK |
678 | tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, |
679 | add_ba_rsp->peer_mac_addr); | |
680 | if (tbl) { | |
681 | if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) && | |
682 | priv->add_ba_param.rx_amsdu && | |
683 | (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED)) | |
684 | tbl->amsdu = true; | |
685 | else | |
686 | tbl->amsdu = false; | |
687 | } | |
688 | ||
63410c37 AK |
689 | dev_dbg(priv->adapter->dev, |
690 | "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n", | |
691 | add_ba_rsp->peer_mac_addr, tid, add_ba_rsp->ssn, win_size); | |
692 | ||
5e6e3a92 BZ |
693 | return 0; |
694 | } | |
695 | ||
696 | /* | |
697 | * This function handles BA stream timeout event by preparing and sending | |
698 | * a command to the firmware. | |
699 | */ | |
700 | void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv, | |
701 | struct host_cmd_ds_11n_batimeout *event) | |
702 | { | |
703 | struct host_cmd_ds_11n_delba delba; | |
704 | ||
705 | memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba)); | |
706 | memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN); | |
707 | ||
708 | delba.del_ba_param_set |= | |
709 | cpu_to_le16((u16) event->tid << DELBA_TID_POS); | |
710 | delba.del_ba_param_set |= cpu_to_le16( | |
711 | (u16) event->origninator << DELBA_INITIATOR_POS); | |
712 | delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); | |
fa0ecbb9 | 713 | mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba, false); |
5e6e3a92 BZ |
714 | } |
715 | ||
716 | /* | |
717 | * This function cleans up the Rx reorder table by deleting all the entries | |
718 | * and re-initializing. | |
719 | */ | |
720 | void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv) | |
721 | { | |
722 | struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node; | |
723 | unsigned long flags; | |
724 | ||
725 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); | |
726 | list_for_each_entry_safe(del_tbl_ptr, tmp_node, | |
727 | &priv->rx_reorder_tbl_ptr, list) { | |
728 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
8c00228e | 729 | mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr); |
5e6e3a92 BZ |
730 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); |
731 | } | |
732 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); | |
733 | ||
734 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); | |
92583924 | 735 | mwifiex_reset_11n_rx_seq_num(priv); |
5e6e3a92 | 736 | } |
2db96c3d AP |
737 | |
738 | /* | |
739 | * This function updates all rx_reorder_tbl's flags. | |
740 | */ | |
741 | void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags) | |
742 | { | |
743 | struct mwifiex_private *priv; | |
744 | struct mwifiex_rx_reorder_tbl *tbl; | |
745 | unsigned long lock_flags; | |
746 | int i; | |
747 | ||
748 | for (i = 0; i < adapter->priv_num; i++) { | |
749 | priv = adapter->priv[i]; | |
750 | if (!priv) | |
751 | continue; | |
752 | if (list_empty(&priv->rx_reorder_tbl_ptr)) | |
753 | continue; | |
754 | ||
755 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags); | |
756 | list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) | |
757 | tbl->flags = flags; | |
758 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags); | |
759 | } | |
760 | ||
761 | return; | |
762 | } |