1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
29
30
31
32
33
34
35
36
37static void
38mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv,
39 struct mwifiex_rx_reorder_tbl *tbl, int start_win)
40{
41 int pkt_to_send, i;
42 void *rx_tmp_ptr;
43 unsigned long flags;
44
45 pkt_to_send = (start_win > tbl->start_win) ?
46 min((start_win - tbl->start_win), tbl->win_size) :
47 tbl->win_size;
48
49 for (i = 0; i < pkt_to_send; ++i) {
50 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
51 rx_tmp_ptr = NULL;
52 if (tbl->rx_reorder_ptr[i]) {
53 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
54 tbl->rx_reorder_ptr[i] = NULL;
55 }
56 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
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, rx_tmp_ptr);
62 }
63 }
64
65 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
66
67
68
69
70 for (i = 0; i < tbl->win_size - pkt_to_send; ++i) {
71 tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i];
72 tbl->rx_reorder_ptr[pkt_to_send + i] = NULL;
73 }
74
75 tbl->start_win = start_win;
76 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
77}
78
79
80
81
82
83
84
85
86
87static void
88mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv,
89 struct mwifiex_rx_reorder_tbl *tbl)
90{
91 int i, j, xchg;
92 void *rx_tmp_ptr;
93 unsigned long flags;
94
95 for (i = 0; i < tbl->win_size; ++i) {
96 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
97 if (!tbl->rx_reorder_ptr[i]) {
98 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
99 break;
100 }
101 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
102 tbl->rx_reorder_ptr[i] = NULL;
103 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
104
105 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
106 mwifiex_handle_uap_rx_forward(priv, rx_tmp_ptr);
107 else
108 mwifiex_process_rx_packet(priv, rx_tmp_ptr);
109 }
110
111 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
112
113
114
115
116 if (i > 0) {
117 xchg = tbl->win_size - i;
118 for (j = 0; j < xchg; ++j) {
119 tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j];
120 tbl->rx_reorder_ptr[i + j] = NULL;
121 }
122 }
123 tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1);
124 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
125}
126
127
128
129
130
131
132
133static void
134mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv,
135 struct mwifiex_rx_reorder_tbl *tbl)
136{
137 unsigned long flags;
138
139 if (!tbl)
140 return;
141
142 mwifiex_11n_dispatch_pkt(priv, tbl, (tbl->start_win + tbl->win_size) &
143 (MAX_TID_VALUE - 1));
144
145 del_timer(&tbl->timer_context.timer);
146
147 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
148 list_del(&tbl->list);
149 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
150
151 kfree(tbl->rx_reorder_ptr);
152 kfree(tbl);
153}
154
155
156
157
158
159struct mwifiex_rx_reorder_tbl *
160mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
161{
162 struct mwifiex_rx_reorder_tbl *tbl;
163 unsigned long flags;
164
165 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
166 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) {
167 if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) {
168 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
169 flags);
170 return tbl;
171 }
172 }
173 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
174
175 return NULL;
176}
177
178
179
180
181void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta)
182{
183 struct mwifiex_rx_reorder_tbl *tbl, *tmp;
184 unsigned long flags;
185
186 if (!ta)
187 return;
188
189 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
190 list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) {
191 if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
192 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
193 flags);
194 mwifiex_del_rx_reorder_entry(priv, tbl);
195 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
196 }
197 }
198 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
199
200 return;
201}
202
203
204
205
206
207static int
208mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr)
209{
210 int i;
211
212 for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i)
213 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
214 return i;
215
216 return -1;
217}
218
219
220
221
222
223
224
225
226static void
227mwifiex_flush_data(unsigned long context)
228{
229 struct reorder_tmr_cnxt *ctx =
230 (struct reorder_tmr_cnxt *) context;
231 int start_win;
232
233 start_win = mwifiex_11n_find_last_seq_num(ctx->ptr);
234
235 if (start_win < 0)
236 return;
237
238 dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", start_win);
239 mwifiex_11n_dispatch_pkt(ctx->priv, ctx->ptr,
240 (ctx->ptr->start_win + start_win + 1) &
241 (MAX_TID_VALUE - 1));
242}
243
244
245
246
247
248
249
250
251
252
253
254static void
255mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
256 int tid, int win_size, int seq_num)
257{
258 int i;
259 struct mwifiex_rx_reorder_tbl *tbl, *new_node;
260 u16 last_seq = 0;
261 unsigned long flags;
262 struct mwifiex_sta_node *node;
263
264
265
266
267
268 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
269 if (tbl) {
270 mwifiex_11n_dispatch_pkt(priv, tbl, seq_num);
271 return;
272 }
273
274 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
275 if (!new_node)
276 return;
277
278 INIT_LIST_HEAD(&new_node->list);
279 new_node->tid = tid;
280 memcpy(new_node->ta, ta, ETH_ALEN);
281 new_node->start_win = seq_num;
282
283 if (mwifiex_queuing_ra_based(priv)) {
284 dev_dbg(priv->adapter->dev,
285 "info: AP/ADHOC:last_seq=%d start_win=%d\n",
286 last_seq, new_node->start_win);
287 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
288 node = mwifiex_get_sta_entry(priv, ta);
289 if (node)
290 last_seq = node->rx_seq[tid];
291 }
292 } else {
293 last_seq = priv->rx_seq[tid];
294 }
295
296 if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
297 last_seq >= new_node->start_win)
298 new_node->start_win = last_seq + 1;
299
300 new_node->win_size = win_size;
301 new_node->flags = 0;
302
303 new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
304 GFP_KERNEL);
305 if (!new_node->rx_reorder_ptr) {
306 kfree((u8 *) new_node);
307 dev_err(priv->adapter->dev,
308 "%s: failed to alloc reorder_ptr\n", __func__);
309 return;
310 }
311
312 new_node->timer_context.ptr = new_node;
313 new_node->timer_context.priv = priv;
314
315 init_timer(&new_node->timer_context.timer);
316 new_node->timer_context.timer.function = mwifiex_flush_data;
317 new_node->timer_context.timer.data =
318 (unsigned long) &new_node->timer_context;
319
320 for (i = 0; i < win_size; ++i)
321 new_node->rx_reorder_ptr[i] = NULL;
322
323 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
324 list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
325 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
326}
327
328
329
330
331
332
333
334
335
336int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
337{
338 struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req;
339
340 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
341 cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
342 memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
343
344 return 0;
345}
346
347
348
349
350
351
352
353
354
355int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
356 struct host_cmd_ds_command *cmd,
357 struct host_cmd_ds_11n_addba_req
358 *cmd_addba_req)
359{
360 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp;
361 u8 tid;
362 int win_size;
363 uint16_t block_ack_param_set;
364
365 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
366 cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
367
368 memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
369 ETH_ALEN);
370 add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
371 add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
372 add_ba_rsp->ssn = cmd_addba_req->ssn;
373
374 block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
375 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
376 >> BLOCKACKPARAM_TID_POS;
377 add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
378 block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
379
380 block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
381 block_ack_param_set |= (priv->add_ba_param.rx_win_size <<
382 BLOCKACKPARAM_WINSIZE_POS);
383 add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
384 win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
385 & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
386 >> BLOCKACKPARAM_WINSIZE_POS;
387 cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
388
389 mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
390 tid, win_size,
391 le16_to_cpu(cmd_addba_req->ssn));
392 return 0;
393}
394
395
396
397
398
399
400
401
402
403int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
404{
405 struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba;
406
407 cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
408 cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
409 memcpy(del_ba, data_buf, sizeof(*del_ba));
410
411 return 0;
412}
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
428 u16 seq_num, u16 tid,
429 u8 *ta, u8 pkt_type, void *payload)
430{
431 struct mwifiex_rx_reorder_tbl *tbl;
432 int start_win, end_win, win_size;
433 u16 pkt_index;
434
435 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
436 if (!tbl) {
437 if (pkt_type != PKT_TYPE_BAR) {
438 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
439 mwifiex_handle_uap_rx_forward(priv, payload);
440 else
441 mwifiex_process_rx_packet(priv, payload);
442 }
443 return 0;
444 }
445 start_win = tbl->start_win;
446 win_size = tbl->win_size;
447 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
448 del_timer(&tbl->timer_context.timer);
449 mod_timer(&tbl->timer_context.timer,
450 jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size));
451
452
453
454
455
456 if (tbl->flags & RXREOR_FORCE_NO_DROP) {
457 dev_dbg(priv->adapter->dev,
458 "RXREOR_FORCE_NO_DROP when HS is activated\n");
459 tbl->flags &= ~RXREOR_FORCE_NO_DROP;
460 } else {
461 if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {
462 if (seq_num >= ((start_win + TWOPOW11) &
463 (MAX_TID_VALUE - 1)) &&
464 seq_num < start_win)
465 return -1;
466 } else if ((seq_num < start_win) ||
467 (seq_num > (start_win + TWOPOW11))) {
468 return -1;
469 }
470 }
471
472
473
474
475
476 if (pkt_type == PKT_TYPE_BAR)
477 seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
478
479 if (((end_win < start_win) &&
480 (seq_num < start_win) && (seq_num > end_win)) ||
481 ((end_win > start_win) && ((seq_num > end_win) ||
482 (seq_num < start_win)))) {
483 end_win = seq_num;
484 if (((seq_num - win_size) + 1) >= 0)
485 start_win = (end_win - win_size) + 1;
486 else
487 start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
488 mwifiex_11n_dispatch_pkt(priv, tbl, start_win);
489 }
490
491 if (pkt_type != PKT_TYPE_BAR) {
492 if (seq_num >= start_win)
493 pkt_index = seq_num - start_win;
494 else
495 pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
496
497 if (tbl->rx_reorder_ptr[pkt_index])
498 return -1;
499
500 tbl->rx_reorder_ptr[pkt_index] = payload;
501 }
502
503
504
505
506
507 mwifiex_11n_scan_and_dispatch(priv, tbl);
508
509 return 0;
510}
511
512
513
514
515
516
517void
518mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
519 u8 type, int initiator)
520{
521 struct mwifiex_rx_reorder_tbl *tbl;
522 struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
523 u8 cleanup_rx_reorder_tbl;
524 unsigned long flags;
525
526 if (type == TYPE_DELBA_RECEIVE)
527 cleanup_rx_reorder_tbl = (initiator) ? true : false;
528 else
529 cleanup_rx_reorder_tbl = (initiator) ? false : true;
530
531 dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n",
532 peer_mac, tid, initiator);
533
534 if (cleanup_rx_reorder_tbl) {
535 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
536 peer_mac);
537 if (!tbl) {
538 dev_dbg(priv->adapter->dev,
539 "event: TID, TA not found in table\n");
540 return;
541 }
542 mwifiex_del_rx_reorder_entry(priv, tbl);
543 } else {
544 ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
545 if (!ptx_tbl) {
546 dev_dbg(priv->adapter->dev,
547 "event: TID, RA not found in table\n");
548 return;
549 }
550
551 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
552 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
553 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
554 }
555}
556
557
558
559
560
561
562
563int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
564 struct host_cmd_ds_command *resp)
565{
566 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
567 int tid, win_size;
568 struct mwifiex_rx_reorder_tbl *tbl;
569 uint16_t block_ack_param_set;
570
571 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
572
573 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
574 >> BLOCKACKPARAM_TID_POS;
575
576
577
578
579 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
580 win_size = (block_ack_param_set &
581 IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
582 >> BLOCKACKPARAM_WINSIZE_POS;
583
584 dev_dbg(priv->adapter->dev,
585 "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
586 add_ba_rsp->peer_mac_addr, tid,
587 add_ba_rsp->ssn, win_size);
588 } else {
589 dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
590 add_ba_rsp->peer_mac_addr, tid);
591
592 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
593 add_ba_rsp->peer_mac_addr);
594 if (tbl)
595 mwifiex_del_rx_reorder_entry(priv, tbl);
596 }
597
598 return 0;
599}
600
601
602
603
604
605void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
606 struct host_cmd_ds_11n_batimeout *event)
607{
608 struct host_cmd_ds_11n_delba delba;
609
610 memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
611 memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
612
613 delba.del_ba_param_set |=
614 cpu_to_le16((u16) event->tid << DELBA_TID_POS);
615 delba.del_ba_param_set |= cpu_to_le16(
616 (u16) event->origninator << DELBA_INITIATOR_POS);
617 delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
618 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba);
619}
620
621
622
623
624
625void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
626{
627 struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
628 unsigned long flags;
629
630 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
631 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
632 &priv->rx_reorder_tbl_ptr, list) {
633 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
634 mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
635 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
636 }
637 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
638
639 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
640 mwifiex_reset_11n_rx_seq_num(priv);
641}
642
643
644
645
646void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags)
647{
648 struct mwifiex_private *priv;
649 struct mwifiex_rx_reorder_tbl *tbl;
650 unsigned long lock_flags;
651 int i;
652
653 for (i = 0; i < adapter->priv_num; i++) {
654 priv = adapter->priv[i];
655 if (!priv)
656 continue;
657 if (list_empty(&priv->rx_reorder_tbl_ptr))
658 continue;
659
660 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags);
661 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list)
662 tbl->flags = flags;
663 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags);
664 }
665
666 return;
667}
668