ath6kl: Introduce spinlock to protect vif specific information
[deliverable/linux.git] / drivers / net / wireless / ath / ath6kl / txrx.c
1 /*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include "core.h"
18 #include "debug.h"
19
20 static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev,
21 u32 *map_no)
22 {
23 struct ath6kl *ar = ath6kl_priv(dev);
24 struct ethhdr *eth_hdr;
25 u32 i, ep_map = -1;
26 u8 *datap;
27
28 *map_no = 0;
29 datap = skb->data;
30 eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr));
31
32 if (is_multicast_ether_addr(eth_hdr->h_dest))
33 return ENDPOINT_2;
34
35 for (i = 0; i < ar->node_num; i++) {
36 if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr,
37 ETH_ALEN) == 0) {
38 *map_no = i + 1;
39 ar->node_map[i].tx_pend++;
40 return ar->node_map[i].ep_id;
41 }
42
43 if ((ep_map == -1) && !ar->node_map[i].tx_pend)
44 ep_map = i;
45 }
46
47 if (ep_map == -1) {
48 ep_map = ar->node_num;
49 ar->node_num++;
50 if (ar->node_num > MAX_NODE_NUM)
51 return ENDPOINT_UNUSED;
52 }
53
54 memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN);
55
56 for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) {
57 if (!ar->tx_pending[i]) {
58 ar->node_map[ep_map].ep_id = i;
59 break;
60 }
61
62 /*
63 * No free endpoint is available, start redistribution on
64 * the inuse endpoints.
65 */
66 if (i == ENDPOINT_5) {
67 ar->node_map[ep_map].ep_id = ar->next_ep_id;
68 ar->next_ep_id++;
69 if (ar->next_ep_id > ENDPOINT_5)
70 ar->next_ep_id = ENDPOINT_2;
71 }
72 }
73
74 *map_no = ep_map + 1;
75 ar->node_map[ep_map].tx_pend++;
76
77 return ar->node_map[ep_map].ep_id;
78 }
79
80 static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb,
81 bool *more_data)
82 {
83 struct ethhdr *datap = (struct ethhdr *) skb->data;
84 struct ath6kl_sta *conn = NULL;
85 bool ps_queued = false, is_psq_empty = false;
86 struct ath6kl *ar = vif->ar;
87
88 if (is_multicast_ether_addr(datap->h_dest)) {
89 u8 ctr = 0;
90 bool q_mcast = false;
91
92 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
93 if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) {
94 q_mcast = true;
95 break;
96 }
97 }
98
99 if (q_mcast) {
100 /*
101 * If this transmit is not because of a Dtim Expiry
102 * q it.
103 */
104 if (!test_bit(DTIM_EXPIRED, &vif->flags)) {
105 bool is_mcastq_empty = false;
106
107 spin_lock_bh(&ar->mcastpsq_lock);
108 is_mcastq_empty =
109 skb_queue_empty(&ar->mcastpsq);
110 skb_queue_tail(&ar->mcastpsq, skb);
111 spin_unlock_bh(&ar->mcastpsq_lock);
112
113 /*
114 * If this is the first Mcast pkt getting
115 * queued indicate to the target to set the
116 * BitmapControl LSB of the TIM IE.
117 */
118 if (is_mcastq_empty)
119 ath6kl_wmi_set_pvb_cmd(ar->wmi,
120 vif->fw_vif_idx,
121 MCAST_AID, 1);
122
123 ps_queued = true;
124 } else {
125 /*
126 * This transmit is because of Dtim expiry.
127 * Determine if MoreData bit has to be set.
128 */
129 spin_lock_bh(&ar->mcastpsq_lock);
130 if (!skb_queue_empty(&ar->mcastpsq))
131 *more_data = true;
132 spin_unlock_bh(&ar->mcastpsq_lock);
133 }
134 }
135 } else {
136 conn = ath6kl_find_sta(vif, datap->h_dest);
137 if (!conn) {
138 dev_kfree_skb(skb);
139
140 /* Inform the caller that the skb is consumed */
141 return true;
142 }
143
144 if (conn->sta_flags & STA_PS_SLEEP) {
145 if (!(conn->sta_flags & STA_PS_POLLED)) {
146 /* Queue the frames if the STA is sleeping */
147 spin_lock_bh(&conn->psq_lock);
148 is_psq_empty = skb_queue_empty(&conn->psq);
149 skb_queue_tail(&conn->psq, skb);
150 spin_unlock_bh(&conn->psq_lock);
151
152 /*
153 * If this is the first pkt getting queued
154 * for this STA, update the PVB for this
155 * STA.
156 */
157 if (is_psq_empty)
158 ath6kl_wmi_set_pvb_cmd(ar->wmi,
159 vif->fw_vif_idx,
160 conn->aid, 1);
161
162 ps_queued = true;
163 } else {
164 /*
165 * This tx is because of a PsPoll.
166 * Determine if MoreData bit has to be set.
167 */
168 spin_lock_bh(&conn->psq_lock);
169 if (!skb_queue_empty(&conn->psq))
170 *more_data = true;
171 spin_unlock_bh(&conn->psq_lock);
172 }
173 }
174 }
175
176 return ps_queued;
177 }
178
179 /* Tx functions */
180
181 int ath6kl_control_tx(void *devt, struct sk_buff *skb,
182 enum htc_endpoint_id eid)
183 {
184 struct ath6kl *ar = devt;
185 int status = 0;
186 struct ath6kl_cookie *cookie = NULL;
187
188 spin_lock_bh(&ar->lock);
189
190 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
191 "%s: skb=0x%p, len=0x%x eid =%d\n", __func__,
192 skb, skb->len, eid);
193
194 if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) {
195 /*
196 * Control endpoint is full, don't allocate resources, we
197 * are just going to drop this packet.
198 */
199 cookie = NULL;
200 ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
201 skb, skb->len);
202 } else
203 cookie = ath6kl_alloc_cookie(ar);
204
205 if (cookie == NULL) {
206 spin_unlock_bh(&ar->lock);
207 status = -ENOMEM;
208 goto fail_ctrl_tx;
209 }
210
211 ar->tx_pending[eid]++;
212
213 if (eid != ar->ctrl_ep)
214 ar->total_tx_data_pend++;
215
216 spin_unlock_bh(&ar->lock);
217
218 cookie->skb = skb;
219 cookie->map_no = 0;
220 set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
221 eid, ATH6KL_CONTROL_PKT_TAG);
222
223 /*
224 * This interface is asynchronous, if there is an error, cleanup
225 * will happen in the TX completion callback.
226 */
227 ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
228
229 return 0;
230
231 fail_ctrl_tx:
232 dev_kfree_skb(skb);
233 return status;
234 }
235
236 int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev)
237 {
238 struct ath6kl *ar = ath6kl_priv(dev);
239 struct ath6kl_cookie *cookie = NULL;
240 enum htc_endpoint_id eid = ENDPOINT_UNUSED;
241 struct ath6kl_vif *vif = netdev_priv(dev);
242 u32 map_no = 0;
243 u16 htc_tag = ATH6KL_DATA_PKT_TAG;
244 u8 ac = 99 ; /* initialize to unmapped ac */
245 bool chk_adhoc_ps_mapping = false, more_data = false;
246 int ret;
247
248 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
249 "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__,
250 skb, skb->data, skb->len);
251
252 /* If target is not associated */
253 if (!test_bit(CONNECTED, &vif->flags)) {
254 dev_kfree_skb(skb);
255 return 0;
256 }
257
258 if (!test_bit(WMI_READY, &ar->flag))
259 goto fail_tx;
260
261 /* AP mode Power saving processing */
262 if (vif->nw_type == AP_NETWORK) {
263 if (ath6kl_powersave_ap(vif, skb, &more_data))
264 return 0;
265 }
266
267 if (test_bit(WMI_ENABLED, &ar->flag)) {
268 if (skb_headroom(skb) < dev->needed_headroom) {
269 WARN_ON(1);
270 goto fail_tx;
271 }
272
273 if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) {
274 ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
275 goto fail_tx;
276 }
277
278 if (ath6kl_wmi_data_hdr_add(ar->wmi, skb, DATA_MSGTYPE,
279 more_data, 0, 0, NULL,
280 vif->fw_vif_idx)) {
281 ath6kl_err("wmi_data_hdr_add failed\n");
282 goto fail_tx;
283 }
284
285 if ((vif->nw_type == ADHOC_NETWORK) &&
286 ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags))
287 chk_adhoc_ps_mapping = true;
288 else {
289 /* get the stream mapping */
290 ret = ath6kl_wmi_implicit_create_pstream(ar->wmi,
291 vif->fw_vif_idx, skb,
292 0, test_bit(WMM_ENABLED, &vif->flags), &ac);
293 if (ret)
294 goto fail_tx;
295 }
296 } else
297 goto fail_tx;
298
299 spin_lock_bh(&ar->lock);
300
301 if (chk_adhoc_ps_mapping)
302 eid = ath6kl_ibss_map_epid(skb, dev, &map_no);
303 else
304 eid = ar->ac2ep_map[ac];
305
306 if (eid == 0 || eid == ENDPOINT_UNUSED) {
307 ath6kl_err("eid %d is not mapped!\n", eid);
308 spin_unlock_bh(&ar->lock);
309 goto fail_tx;
310 }
311
312 /* allocate resource for this packet */
313 cookie = ath6kl_alloc_cookie(ar);
314
315 if (!cookie) {
316 spin_unlock_bh(&ar->lock);
317 goto fail_tx;
318 }
319
320 /* update counts while the lock is held */
321 ar->tx_pending[eid]++;
322 ar->total_tx_data_pend++;
323
324 spin_unlock_bh(&ar->lock);
325
326 if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) &&
327 skb_cloned(skb)) {
328 /*
329 * We will touch (move the buffer data to align it. Since the
330 * skb buffer is cloned and not only the header is changed, we
331 * have to copy it to allow the changes. Since we are copying
332 * the data here, we may as well align it by reserving suitable
333 * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
334 */
335 struct sk_buff *nskb;
336
337 nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC);
338 if (nskb == NULL)
339 goto fail_tx;
340 kfree_skb(skb);
341 skb = nskb;
342 }
343
344 cookie->skb = skb;
345 cookie->map_no = map_no;
346 set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
347 eid, htc_tag);
348
349 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ",
350 skb->data, skb->len);
351
352 /*
353 * HTC interface is asynchronous, if this fails, cleanup will
354 * happen in the ath6kl_tx_complete callback.
355 */
356 ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
357
358 return 0;
359
360 fail_tx:
361 dev_kfree_skb(skb);
362
363 vif->net_stats.tx_dropped++;
364 vif->net_stats.tx_aborted_errors++;
365
366 return 0;
367 }
368
369 /* indicate tx activity or inactivity on a WMI stream */
370 void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active)
371 {
372 struct ath6kl *ar = devt;
373 enum htc_endpoint_id eid;
374 int i;
375
376 eid = ar->ac2ep_map[traffic_class];
377
378 if (!test_bit(WMI_ENABLED, &ar->flag))
379 goto notify_htc;
380
381 spin_lock_bh(&ar->lock);
382
383 ar->ac_stream_active[traffic_class] = active;
384
385 if (active) {
386 /*
387 * Keep track of the active stream with the highest
388 * priority.
389 */
390 if (ar->ac_stream_pri_map[traffic_class] >
391 ar->hiac_stream_active_pri)
392 /* set the new highest active priority */
393 ar->hiac_stream_active_pri =
394 ar->ac_stream_pri_map[traffic_class];
395
396 } else {
397 /*
398 * We may have to search for the next active stream
399 * that is the highest priority.
400 */
401 if (ar->hiac_stream_active_pri ==
402 ar->ac_stream_pri_map[traffic_class]) {
403 /*
404 * The highest priority stream just went inactive
405 * reset and search for the "next" highest "active"
406 * priority stream.
407 */
408 ar->hiac_stream_active_pri = 0;
409
410 for (i = 0; i < WMM_NUM_AC; i++) {
411 if (ar->ac_stream_active[i] &&
412 (ar->ac_stream_pri_map[i] >
413 ar->hiac_stream_active_pri))
414 /*
415 * Set the new highest active
416 * priority.
417 */
418 ar->hiac_stream_active_pri =
419 ar->ac_stream_pri_map[i];
420 }
421 }
422 }
423
424 spin_unlock_bh(&ar->lock);
425
426 notify_htc:
427 /* notify HTC, this may cause credit distribution changes */
428 ath6kl_htc_indicate_activity_change(ar->htc_target, eid, active);
429 }
430
431 enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
432 struct htc_packet *packet)
433 {
434 struct ath6kl *ar = target->dev->ar;
435 /* TODO: Findout vif properly */
436 struct ath6kl_vif *vif = ar->vif;
437 enum htc_endpoint_id endpoint = packet->endpoint;
438
439 if (endpoint == ar->ctrl_ep) {
440 /*
441 * Under normal WMI if this is getting full, then something
442 * is running rampant the host should not be exhausting the
443 * WMI queue with too many commands the only exception to
444 * this is during testing using endpointping.
445 */
446 spin_lock_bh(&ar->lock);
447 set_bit(WMI_CTRL_EP_FULL, &ar->flag);
448 spin_unlock_bh(&ar->lock);
449 ath6kl_err("wmi ctrl ep is full\n");
450 return HTC_SEND_FULL_KEEP;
451 }
452
453 if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG)
454 return HTC_SEND_FULL_KEEP;
455
456 if (vif->nw_type == ADHOC_NETWORK)
457 /*
458 * In adhoc mode, we cannot differentiate traffic
459 * priorities so there is no need to continue, however we
460 * should stop the network.
461 */
462 goto stop_net_queues;
463
464 /*
465 * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
466 * the highest active stream.
467 */
468 if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] <
469 ar->hiac_stream_active_pri &&
470 ar->cookie_count <= MAX_HI_COOKIE_NUM)
471 /*
472 * Give preference to the highest priority stream by
473 * dropping the packets which overflowed.
474 */
475 return HTC_SEND_FULL_DROP;
476
477 stop_net_queues:
478 spin_lock_bh(&vif->if_lock);
479 set_bit(NETQ_STOPPED, &vif->flags);
480 spin_unlock_bh(&vif->if_lock);
481 netif_stop_queue(vif->ndev);
482
483 return HTC_SEND_FULL_KEEP;
484 }
485
486 /* TODO this needs to be looked at */
487 static void ath6kl_tx_clear_node_map(struct ath6kl *ar,
488 enum htc_endpoint_id eid, u32 map_no)
489 {
490 /* TODO: Findout vif */
491 struct ath6kl_vif *vif = ar->vif;
492 u32 i;
493
494 if (vif->nw_type != ADHOC_NETWORK)
495 return;
496
497 if (!ar->ibss_ps_enable)
498 return;
499
500 if (eid == ar->ctrl_ep)
501 return;
502
503 if (map_no == 0)
504 return;
505
506 map_no--;
507 ar->node_map[map_no].tx_pend--;
508
509 if (ar->node_map[map_no].tx_pend)
510 return;
511
512 if (map_no != (ar->node_num - 1))
513 return;
514
515 for (i = ar->node_num; i > 0; i--) {
516 if (ar->node_map[i - 1].tx_pend)
517 break;
518
519 memset(&ar->node_map[i - 1], 0,
520 sizeof(struct ath6kl_node_mapping));
521 ar->node_num--;
522 }
523 }
524
525 void ath6kl_tx_complete(void *context, struct list_head *packet_queue)
526 {
527 struct ath6kl *ar = context;
528 struct sk_buff_head skb_queue;
529 struct htc_packet *packet;
530 struct sk_buff *skb;
531 struct ath6kl_cookie *ath6kl_cookie;
532 u32 map_no = 0;
533 int status;
534 enum htc_endpoint_id eid;
535 bool wake_event = false;
536 bool flushing = false;
537 u8 if_idx;
538 /* TODO: Findout vif */
539 struct ath6kl_vif *vif = ar->vif;
540
541 skb_queue_head_init(&skb_queue);
542
543 /* lock the driver as we update internal state */
544 spin_lock_bh(&ar->lock);
545
546 /* reap completed packets */
547 while (!list_empty(packet_queue)) {
548
549 packet = list_first_entry(packet_queue, struct htc_packet,
550 list);
551 list_del(&packet->list);
552
553 ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt;
554 if (!ath6kl_cookie)
555 goto fatal;
556
557 status = packet->status;
558 skb = ath6kl_cookie->skb;
559 eid = packet->endpoint;
560 map_no = ath6kl_cookie->map_no;
561
562 if (!skb || !skb->data)
563 goto fatal;
564
565 packet->buf = skb->data;
566
567 __skb_queue_tail(&skb_queue, skb);
568
569 if (!status && (packet->act_len != skb->len))
570 goto fatal;
571
572 ar->tx_pending[eid]--;
573
574 if (eid != ar->ctrl_ep)
575 ar->total_tx_data_pend--;
576
577 if (eid == ar->ctrl_ep) {
578 if (test_bit(WMI_CTRL_EP_FULL, &ar->flag))
579 clear_bit(WMI_CTRL_EP_FULL, &ar->flag);
580
581 if (ar->tx_pending[eid] == 0)
582 wake_event = true;
583 }
584
585 if (eid == ar->ctrl_ep) {
586 if_idx = wmi_cmd_hdr_get_if_idx(
587 (struct wmi_cmd_hdr *) skb->data);
588 } else {
589 if_idx = wmi_data_hdr_get_if_idx(
590 (struct wmi_data_hdr *) skb->data);
591 }
592
593 vif = ath6kl_get_vif_by_index(ar, if_idx);
594 if (!vif) {
595 ath6kl_free_cookie(ar, ath6kl_cookie);
596 continue;
597 }
598
599 if (status) {
600 if (status == -ECANCELED)
601 /* a packet was flushed */
602 flushing = true;
603
604 vif->net_stats.tx_errors++;
605
606 if (status != -ENOSPC)
607 ath6kl_err("tx error, status: 0x%x\n", status);
608 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
609 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
610 __func__, skb, packet->buf, packet->act_len,
611 eid, "error!");
612 } else {
613 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
614 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
615 __func__, skb, packet->buf, packet->act_len,
616 eid, "OK");
617
618 flushing = false;
619 vif->net_stats.tx_packets++;
620 vif->net_stats.tx_bytes += skb->len;
621 }
622
623 ath6kl_tx_clear_node_map(ar, eid, map_no);
624
625 ath6kl_free_cookie(ar, ath6kl_cookie);
626
627 if (test_bit(NETQ_STOPPED, &vif->flags))
628 clear_bit(NETQ_STOPPED, &vif->flags);
629 }
630
631 spin_unlock_bh(&ar->lock);
632
633 __skb_queue_purge(&skb_queue);
634
635 if (test_bit(CONNECTED, &vif->flags)) {
636 if (!flushing)
637 netif_wake_queue(vif->ndev);
638 }
639
640 if (wake_event)
641 wake_up(&ar->event_wq);
642
643 return;
644
645 fatal:
646 WARN_ON(1);
647 spin_unlock_bh(&ar->lock);
648 return;
649 }
650
651 void ath6kl_tx_data_cleanup(struct ath6kl *ar)
652 {
653 int i;
654
655 /* flush all the data (non-control) streams */
656 for (i = 0; i < WMM_NUM_AC; i++)
657 ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i],
658 ATH6KL_DATA_PKT_TAG);
659 }
660
661 /* Rx functions */
662
663 static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev,
664 struct sk_buff *skb)
665 {
666 if (!skb)
667 return;
668
669 skb->dev = dev;
670
671 if (!(skb->dev->flags & IFF_UP)) {
672 dev_kfree_skb(skb);
673 return;
674 }
675
676 skb->protocol = eth_type_trans(skb, skb->dev);
677
678 netif_rx_ni(skb);
679 }
680
681 static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num)
682 {
683 struct sk_buff *skb;
684
685 while (num) {
686 skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
687 if (!skb) {
688 ath6kl_err("netbuf allocation failed\n");
689 return;
690 }
691 skb_queue_tail(q, skb);
692 num--;
693 }
694 }
695
696 static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr)
697 {
698 struct sk_buff *skb = NULL;
699
700 if (skb_queue_len(&p_aggr->free_q) < (AGGR_NUM_OF_FREE_NETBUFS >> 2))
701 ath6kl_alloc_netbufs(&p_aggr->free_q, AGGR_NUM_OF_FREE_NETBUFS);
702
703 skb = skb_dequeue(&p_aggr->free_q);
704
705 return skb;
706 }
707
708 void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint)
709 {
710 struct ath6kl *ar = target->dev->ar;
711 struct sk_buff *skb;
712 int rx_buf;
713 int n_buf_refill;
714 struct htc_packet *packet;
715 struct list_head queue;
716
717 n_buf_refill = ATH6KL_MAX_RX_BUFFERS -
718 ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint);
719
720 if (n_buf_refill <= 0)
721 return;
722
723 INIT_LIST_HEAD(&queue);
724
725 ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
726 "%s: providing htc with %d buffers at eid=%d\n",
727 __func__, n_buf_refill, endpoint);
728
729 for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) {
730 skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
731 if (!skb)
732 break;
733
734 packet = (struct htc_packet *) skb->head;
735 if (!IS_ALIGNED((unsigned long) skb->data, 4))
736 skb->data = PTR_ALIGN(skb->data - 4, 4);
737 set_htc_rxpkt_info(packet, skb, skb->data,
738 ATH6KL_BUFFER_SIZE, endpoint);
739 list_add_tail(&packet->list, &queue);
740 }
741
742 if (!list_empty(&queue))
743 ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue);
744 }
745
746 void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count)
747 {
748 struct htc_packet *packet;
749 struct sk_buff *skb;
750
751 while (count) {
752 skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE);
753 if (!skb)
754 return;
755
756 packet = (struct htc_packet *) skb->head;
757 if (!IS_ALIGNED((unsigned long) skb->data, 4))
758 skb->data = PTR_ALIGN(skb->data - 4, 4);
759 set_htc_rxpkt_info(packet, skb, skb->data,
760 ATH6KL_AMSDU_BUFFER_SIZE, 0);
761 spin_lock_bh(&ar->lock);
762 list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue);
763 spin_unlock_bh(&ar->lock);
764 count--;
765 }
766 }
767
768 /*
769 * Callback to allocate a receive buffer for a pending packet. We use a
770 * pre-allocated list of buffers of maximum AMSDU size (4K).
771 */
772 struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
773 enum htc_endpoint_id endpoint,
774 int len)
775 {
776 struct ath6kl *ar = target->dev->ar;
777 struct htc_packet *packet = NULL;
778 struct list_head *pkt_pos;
779 int refill_cnt = 0, depth = 0;
780
781 ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n",
782 __func__, endpoint, len);
783
784 if ((len <= ATH6KL_BUFFER_SIZE) ||
785 (len > ATH6KL_AMSDU_BUFFER_SIZE))
786 return NULL;
787
788 spin_lock_bh(&ar->lock);
789
790 if (list_empty(&ar->amsdu_rx_buffer_queue)) {
791 spin_unlock_bh(&ar->lock);
792 refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS;
793 goto refill_buf;
794 }
795
796 packet = list_first_entry(&ar->amsdu_rx_buffer_queue,
797 struct htc_packet, list);
798 list_del(&packet->list);
799 list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue)
800 depth++;
801
802 refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth;
803 spin_unlock_bh(&ar->lock);
804
805 /* set actual endpoint ID */
806 packet->endpoint = endpoint;
807
808 refill_buf:
809 if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD)
810 ath6kl_refill_amsdu_rxbufs(ar, refill_cnt);
811
812 return packet;
813 }
814
815 static void aggr_slice_amsdu(struct aggr_info *p_aggr,
816 struct rxtid *rxtid, struct sk_buff *skb)
817 {
818 struct sk_buff *new_skb;
819 struct ethhdr *hdr;
820 u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len;
821 u8 *framep;
822
823 mac_hdr_len = sizeof(struct ethhdr);
824 framep = skb->data + mac_hdr_len;
825 amsdu_len = skb->len - mac_hdr_len;
826
827 while (amsdu_len > mac_hdr_len) {
828 hdr = (struct ethhdr *) framep;
829 payload_8023_len = ntohs(hdr->h_proto);
830
831 if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN ||
832 payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) {
833 ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
834 payload_8023_len);
835 break;
836 }
837
838 frame_8023_len = payload_8023_len + mac_hdr_len;
839 new_skb = aggr_get_free_skb(p_aggr);
840 if (!new_skb) {
841 ath6kl_err("no buffer available\n");
842 break;
843 }
844
845 memcpy(new_skb->data, framep, frame_8023_len);
846 skb_put(new_skb, frame_8023_len);
847 if (ath6kl_wmi_dot3_2_dix(new_skb)) {
848 ath6kl_err("dot3_2_dix error\n");
849 dev_kfree_skb(new_skb);
850 break;
851 }
852
853 skb_queue_tail(&rxtid->q, new_skb);
854
855 /* Is this the last subframe within this aggregate ? */
856 if ((amsdu_len - frame_8023_len) == 0)
857 break;
858
859 /* Add the length of A-MSDU subframe padding bytes -
860 * Round to nearest word.
861 */
862 frame_8023_len = ALIGN(frame_8023_len, 4);
863
864 framep += frame_8023_len;
865 amsdu_len -= frame_8023_len;
866 }
867
868 dev_kfree_skb(skb);
869 }
870
871 static void aggr_deque_frms(struct aggr_info *p_aggr, u8 tid,
872 u16 seq_no, u8 order)
873 {
874 struct sk_buff *skb;
875 struct rxtid *rxtid;
876 struct skb_hold_q *node;
877 u16 idx, idx_end, seq_end;
878 struct rxtid_stats *stats;
879
880 if (!p_aggr)
881 return;
882
883 rxtid = &p_aggr->rx_tid[tid];
884 stats = &p_aggr->stat[tid];
885
886 idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
887
888 /*
889 * idx_end is typically the last possible frame in the window,
890 * but changes to 'the' seq_no, when BAR comes. If seq_no
891 * is non-zero, we will go up to that and stop.
892 * Note: last seq no in current window will occupy the same
893 * index position as index that is just previous to start.
894 * An imp point : if win_sz is 7, for seq_no space of 4095,
895 * then, there would be holes when sequence wrap around occurs.
896 * Target should judiciously choose the win_sz, based on
897 * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
898 * 2, 4, 8, 16 win_sz works fine).
899 * We must deque from "idx" to "idx_end", including both.
900 */
901 seq_end = seq_no ? seq_no : rxtid->seq_next;
902 idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz);
903
904 spin_lock_bh(&rxtid->lock);
905
906 do {
907 node = &rxtid->hold_q[idx];
908 if ((order == 1) && (!node->skb))
909 break;
910
911 if (node->skb) {
912 if (node->is_amsdu)
913 aggr_slice_amsdu(p_aggr, rxtid, node->skb);
914 else
915 skb_queue_tail(&rxtid->q, node->skb);
916 node->skb = NULL;
917 } else
918 stats->num_hole++;
919
920 rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next);
921 idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
922 } while (idx != idx_end);
923
924 spin_unlock_bh(&rxtid->lock);
925
926 stats->num_delivered += skb_queue_len(&rxtid->q);
927
928 while ((skb = skb_dequeue(&rxtid->q)))
929 ath6kl_deliver_frames_to_nw_stack(p_aggr->dev, skb);
930 }
931
932 static bool aggr_process_recv_frm(struct aggr_info *agg_info, u8 tid,
933 u16 seq_no,
934 bool is_amsdu, struct sk_buff *frame)
935 {
936 struct rxtid *rxtid;
937 struct rxtid_stats *stats;
938 struct sk_buff *skb;
939 struct skb_hold_q *node;
940 u16 idx, st, cur, end;
941 bool is_queued = false;
942 u16 extended_end;
943
944 rxtid = &agg_info->rx_tid[tid];
945 stats = &agg_info->stat[tid];
946
947 stats->num_into_aggr++;
948
949 if (!rxtid->aggr) {
950 if (is_amsdu) {
951 aggr_slice_amsdu(agg_info, rxtid, frame);
952 is_queued = true;
953 stats->num_amsdu++;
954 while ((skb = skb_dequeue(&rxtid->q)))
955 ath6kl_deliver_frames_to_nw_stack(agg_info->dev,
956 skb);
957 }
958 return is_queued;
959 }
960
961 /* Check the incoming sequence no, if it's in the window */
962 st = rxtid->seq_next;
963 cur = seq_no;
964 end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO;
965
966 if (((st < end) && (cur < st || cur > end)) ||
967 ((st > end) && (cur > end) && (cur < st))) {
968 extended_end = (end + rxtid->hold_q_sz - 1) &
969 ATH6KL_MAX_SEQ_NO;
970
971 if (((end < extended_end) &&
972 (cur < end || cur > extended_end)) ||
973 ((end > extended_end) && (cur > extended_end) &&
974 (cur < end))) {
975 aggr_deque_frms(agg_info, tid, 0, 0);
976 if (cur >= rxtid->hold_q_sz - 1)
977 rxtid->seq_next = cur - (rxtid->hold_q_sz - 1);
978 else
979 rxtid->seq_next = ATH6KL_MAX_SEQ_NO -
980 (rxtid->hold_q_sz - 2 - cur);
981 } else {
982 /*
983 * Dequeue only those frames that are outside the
984 * new shifted window.
985 */
986 if (cur >= rxtid->hold_q_sz - 1)
987 st = cur - (rxtid->hold_q_sz - 1);
988 else
989 st = ATH6KL_MAX_SEQ_NO -
990 (rxtid->hold_q_sz - 2 - cur);
991
992 aggr_deque_frms(agg_info, tid, st, 0);
993 }
994
995 stats->num_oow++;
996 }
997
998 idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz);
999
1000 node = &rxtid->hold_q[idx];
1001
1002 spin_lock_bh(&rxtid->lock);
1003
1004 /*
1005 * Is the cur frame duplicate or something beyond our window(hold_q
1006 * -> which is 2x, already)?
1007 *
1008 * 1. Duplicate is easy - drop incoming frame.
1009 * 2. Not falling in current sliding window.
1010 * 2a. is the frame_seq_no preceding current tid_seq_no?
1011 * -> drop the frame. perhaps sender did not get our ACK.
1012 * this is taken care of above.
1013 * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
1014 * -> Taken care of it above, by moving window forward.
1015 */
1016 dev_kfree_skb(node->skb);
1017 stats->num_dups++;
1018
1019 node->skb = frame;
1020 is_queued = true;
1021 node->is_amsdu = is_amsdu;
1022 node->seq_no = seq_no;
1023
1024 if (node->is_amsdu)
1025 stats->num_amsdu++;
1026 else
1027 stats->num_mpdu++;
1028
1029 spin_unlock_bh(&rxtid->lock);
1030
1031 aggr_deque_frms(agg_info, tid, 0, 1);
1032
1033 if (agg_info->timer_scheduled)
1034 rxtid->progress = true;
1035 else
1036 for (idx = 0 ; idx < rxtid->hold_q_sz; idx++) {
1037 if (rxtid->hold_q[idx].skb) {
1038 /*
1039 * There is a frame in the queue and no
1040 * timer so start a timer to ensure that
1041 * the frame doesn't remain stuck
1042 * forever.
1043 */
1044 agg_info->timer_scheduled = true;
1045 mod_timer(&agg_info->timer,
1046 (jiffies +
1047 HZ * (AGGR_RX_TIMEOUT) / 1000));
1048 rxtid->progress = false;
1049 rxtid->timer_mon = true;
1050 break;
1051 }
1052 }
1053
1054 return is_queued;
1055 }
1056
1057 void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
1058 {
1059 struct ath6kl *ar = target->dev->ar;
1060 struct sk_buff *skb = packet->pkt_cntxt;
1061 struct wmi_rx_meta_v2 *meta;
1062 struct wmi_data_hdr *dhdr;
1063 int min_hdr_len;
1064 u8 meta_type, dot11_hdr = 0;
1065 int status = packet->status;
1066 enum htc_endpoint_id ept = packet->endpoint;
1067 bool is_amsdu, prev_ps, ps_state = false;
1068 struct ath6kl_sta *conn = NULL;
1069 struct sk_buff *skb1 = NULL;
1070 struct ethhdr *datap = NULL;
1071 struct ath6kl_vif *vif;
1072 u16 seq_no, offset;
1073 u8 tid, if_idx;
1074
1075 ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
1076 "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
1077 __func__, ar, ept, skb, packet->buf,
1078 packet->act_len, status);
1079
1080 if (status || !(skb->data + HTC_HDR_LENGTH)) {
1081 dev_kfree_skb(skb);
1082 return;
1083 }
1084
1085 skb_put(skb, packet->act_len + HTC_HDR_LENGTH);
1086 skb_pull(skb, HTC_HDR_LENGTH);
1087
1088 if (ept == ar->ctrl_ep) {
1089 if_idx =
1090 wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data);
1091 } else {
1092 if_idx =
1093 wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data);
1094 }
1095
1096 vif = ath6kl_get_vif_by_index(ar, if_idx);
1097 if (!vif) {
1098 dev_kfree_skb(skb);
1099 return;
1100 }
1101
1102 /*
1103 * Take lock to protect buffer counts and adaptive power throughput
1104 * state.
1105 */
1106 spin_lock_bh(&vif->if_lock);
1107
1108 vif->net_stats.rx_packets++;
1109 vif->net_stats.rx_bytes += packet->act_len;
1110
1111 spin_unlock_bh(&vif->if_lock);
1112
1113
1114 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ",
1115 skb->data, skb->len);
1116
1117 skb->dev = vif->ndev;
1118
1119 if (!test_bit(WMI_ENABLED, &ar->flag)) {
1120 if (EPPING_ALIGNMENT_PAD > 0)
1121 skb_pull(skb, EPPING_ALIGNMENT_PAD);
1122 ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
1123 return;
1124 }
1125
1126 if (ept == ar->ctrl_ep) {
1127 ath6kl_wmi_control_rx(ar->wmi, skb);
1128 return;
1129 }
1130
1131 min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) +
1132 sizeof(struct ath6kl_llc_snap_hdr);
1133
1134 dhdr = (struct wmi_data_hdr *) skb->data;
1135
1136 /*
1137 * In the case of AP mode we may receive NULL data frames
1138 * that do not have LLC hdr. They are 16 bytes in size.
1139 * Allow these frames in the AP mode.
1140 */
1141 if (vif->nw_type != AP_NETWORK &&
1142 ((packet->act_len < min_hdr_len) ||
1143 (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) {
1144 ath6kl_info("frame len is too short or too long\n");
1145 vif->net_stats.rx_errors++;
1146 vif->net_stats.rx_length_errors++;
1147 dev_kfree_skb(skb);
1148 return;
1149 }
1150
1151 /* Get the Power save state of the STA */
1152 if (vif->nw_type == AP_NETWORK) {
1153 meta_type = wmi_data_hdr_get_meta(dhdr);
1154
1155 ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) &
1156 WMI_DATA_HDR_PS_MASK);
1157
1158 offset = sizeof(struct wmi_data_hdr);
1159
1160 switch (meta_type) {
1161 case 0:
1162 break;
1163 case WMI_META_VERSION_1:
1164 offset += sizeof(struct wmi_rx_meta_v1);
1165 break;
1166 case WMI_META_VERSION_2:
1167 offset += sizeof(struct wmi_rx_meta_v2);
1168 break;
1169 default:
1170 break;
1171 }
1172
1173 datap = (struct ethhdr *) (skb->data + offset);
1174 conn = ath6kl_find_sta(vif, datap->h_source);
1175
1176 if (!conn) {
1177 dev_kfree_skb(skb);
1178 return;
1179 }
1180
1181 /*
1182 * If there is a change in PS state of the STA,
1183 * take appropriate steps:
1184 *
1185 * 1. If Sleep-->Awake, flush the psq for the STA
1186 * Clear the PVB for the STA.
1187 * 2. If Awake-->Sleep, Starting queueing frames
1188 * the STA.
1189 */
1190 prev_ps = !!(conn->sta_flags & STA_PS_SLEEP);
1191
1192 if (ps_state)
1193 conn->sta_flags |= STA_PS_SLEEP;
1194 else
1195 conn->sta_flags &= ~STA_PS_SLEEP;
1196
1197 if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) {
1198 if (!(conn->sta_flags & STA_PS_SLEEP)) {
1199 struct sk_buff *skbuff = NULL;
1200
1201 spin_lock_bh(&conn->psq_lock);
1202 while ((skbuff = skb_dequeue(&conn->psq))
1203 != NULL) {
1204 spin_unlock_bh(&conn->psq_lock);
1205 ath6kl_data_tx(skbuff, vif->ndev);
1206 spin_lock_bh(&conn->psq_lock);
1207 }
1208 spin_unlock_bh(&conn->psq_lock);
1209 /* Clear the PVB for this STA */
1210 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
1211 conn->aid, 0);
1212 }
1213 }
1214
1215 /* drop NULL data frames here */
1216 if ((packet->act_len < min_hdr_len) ||
1217 (packet->act_len >
1218 WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) {
1219 dev_kfree_skb(skb);
1220 return;
1221 }
1222 }
1223
1224 is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false;
1225 tid = wmi_data_hdr_get_up(dhdr);
1226 seq_no = wmi_data_hdr_get_seqno(dhdr);
1227 meta_type = wmi_data_hdr_get_meta(dhdr);
1228 dot11_hdr = wmi_data_hdr_get_dot11(dhdr);
1229 skb_pull(skb, sizeof(struct wmi_data_hdr));
1230
1231 switch (meta_type) {
1232 case WMI_META_VERSION_1:
1233 skb_pull(skb, sizeof(struct wmi_rx_meta_v1));
1234 break;
1235 case WMI_META_VERSION_2:
1236 meta = (struct wmi_rx_meta_v2 *) skb->data;
1237 if (meta->csum_flags & 0x1) {
1238 skb->ip_summed = CHECKSUM_COMPLETE;
1239 skb->csum = (__force __wsum) meta->csum;
1240 }
1241 skb_pull(skb, sizeof(struct wmi_rx_meta_v2));
1242 break;
1243 default:
1244 break;
1245 }
1246
1247 if (dot11_hdr)
1248 status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb);
1249 else if (!is_amsdu)
1250 status = ath6kl_wmi_dot3_2_dix(skb);
1251
1252 if (status) {
1253 /*
1254 * Drop frames that could not be processed (lack of
1255 * memory, etc.)
1256 */
1257 dev_kfree_skb(skb);
1258 return;
1259 }
1260
1261 if (!(vif->ndev->flags & IFF_UP)) {
1262 dev_kfree_skb(skb);
1263 return;
1264 }
1265
1266 if (vif->nw_type == AP_NETWORK) {
1267 datap = (struct ethhdr *) skb->data;
1268 if (is_multicast_ether_addr(datap->h_dest))
1269 /*
1270 * Bcast/Mcast frames should be sent to the
1271 * OS stack as well as on the air.
1272 */
1273 skb1 = skb_copy(skb, GFP_ATOMIC);
1274 else {
1275 /*
1276 * Search for a connected STA with dstMac
1277 * as the Mac address. If found send the
1278 * frame to it on the air else send the
1279 * frame up the stack.
1280 */
1281 conn = ath6kl_find_sta(vif, datap->h_dest);
1282
1283 if (conn && ar->intra_bss) {
1284 skb1 = skb;
1285 skb = NULL;
1286 } else if (conn && !ar->intra_bss) {
1287 dev_kfree_skb(skb);
1288 skb = NULL;
1289 }
1290 }
1291 if (skb1)
1292 ath6kl_data_tx(skb1, vif->ndev);
1293
1294 if (skb == NULL) {
1295 /* nothing to deliver up the stack */
1296 return;
1297 }
1298 }
1299
1300 datap = (struct ethhdr *) skb->data;
1301
1302 if (is_unicast_ether_addr(datap->h_dest) &&
1303 aggr_process_recv_frm(vif->aggr_cntxt, tid, seq_no,
1304 is_amsdu, skb))
1305 /* aggregation code will handle the skb */
1306 return;
1307
1308 ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
1309 }
1310
1311 static void aggr_timeout(unsigned long arg)
1312 {
1313 u8 i, j;
1314 struct aggr_info *p_aggr = (struct aggr_info *) arg;
1315 struct rxtid *rxtid;
1316 struct rxtid_stats *stats;
1317
1318 for (i = 0; i < NUM_OF_TIDS; i++) {
1319 rxtid = &p_aggr->rx_tid[i];
1320 stats = &p_aggr->stat[i];
1321
1322 if (!rxtid->aggr || !rxtid->timer_mon || rxtid->progress)
1323 continue;
1324
1325 stats->num_timeouts++;
1326 ath6kl_dbg(ATH6KL_DBG_AGGR,
1327 "aggr timeout (st %d end %d)\n",
1328 rxtid->seq_next,
1329 ((rxtid->seq_next + rxtid->hold_q_sz-1) &
1330 ATH6KL_MAX_SEQ_NO));
1331 aggr_deque_frms(p_aggr, i, 0, 0);
1332 }
1333
1334 p_aggr->timer_scheduled = false;
1335
1336 for (i = 0; i < NUM_OF_TIDS; i++) {
1337 rxtid = &p_aggr->rx_tid[i];
1338
1339 if (rxtid->aggr && rxtid->hold_q) {
1340 for (j = 0; j < rxtid->hold_q_sz; j++) {
1341 if (rxtid->hold_q[j].skb) {
1342 p_aggr->timer_scheduled = true;
1343 rxtid->timer_mon = true;
1344 rxtid->progress = false;
1345 break;
1346 }
1347 }
1348
1349 if (j >= rxtid->hold_q_sz)
1350 rxtid->timer_mon = false;
1351 }
1352 }
1353
1354 if (p_aggr->timer_scheduled)
1355 mod_timer(&p_aggr->timer,
1356 jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT));
1357 }
1358
1359 static void aggr_delete_tid_state(struct aggr_info *p_aggr, u8 tid)
1360 {
1361 struct rxtid *rxtid;
1362 struct rxtid_stats *stats;
1363
1364 if (!p_aggr || tid >= NUM_OF_TIDS)
1365 return;
1366
1367 rxtid = &p_aggr->rx_tid[tid];
1368 stats = &p_aggr->stat[tid];
1369
1370 if (rxtid->aggr)
1371 aggr_deque_frms(p_aggr, tid, 0, 0);
1372
1373 rxtid->aggr = false;
1374 rxtid->progress = false;
1375 rxtid->timer_mon = false;
1376 rxtid->win_sz = 0;
1377 rxtid->seq_next = 0;
1378 rxtid->hold_q_sz = 0;
1379
1380 kfree(rxtid->hold_q);
1381 rxtid->hold_q = NULL;
1382
1383 memset(stats, 0, sizeof(struct rxtid_stats));
1384 }
1385
1386 void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid, u16 seq_no,
1387 u8 win_sz)
1388 {
1389 struct aggr_info *p_aggr = vif->aggr_cntxt;
1390 struct rxtid *rxtid;
1391 struct rxtid_stats *stats;
1392 u16 hold_q_size;
1393
1394 if (!p_aggr)
1395 return;
1396
1397 rxtid = &p_aggr->rx_tid[tid];
1398 stats = &p_aggr->stat[tid];
1399
1400 if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX)
1401 ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n",
1402 __func__, win_sz, tid);
1403
1404 if (rxtid->aggr)
1405 aggr_delete_tid_state(p_aggr, tid);
1406
1407 rxtid->seq_next = seq_no;
1408 hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q);
1409 rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL);
1410 if (!rxtid->hold_q)
1411 return;
1412
1413 rxtid->win_sz = win_sz;
1414 rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz);
1415 if (!skb_queue_empty(&rxtid->q))
1416 return;
1417
1418 rxtid->aggr = true;
1419 }
1420
1421 struct aggr_info *aggr_init(struct net_device *dev)
1422 {
1423 struct aggr_info *p_aggr = NULL;
1424 struct rxtid *rxtid;
1425 u8 i;
1426
1427 p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL);
1428 if (!p_aggr) {
1429 ath6kl_err("failed to alloc memory for aggr_node\n");
1430 return NULL;
1431 }
1432
1433 p_aggr->aggr_sz = AGGR_SZ_DEFAULT;
1434 p_aggr->dev = dev;
1435 init_timer(&p_aggr->timer);
1436 p_aggr->timer.function = aggr_timeout;
1437 p_aggr->timer.data = (unsigned long) p_aggr;
1438
1439 p_aggr->timer_scheduled = false;
1440 skb_queue_head_init(&p_aggr->free_q);
1441
1442 ath6kl_alloc_netbufs(&p_aggr->free_q, AGGR_NUM_OF_FREE_NETBUFS);
1443
1444 for (i = 0; i < NUM_OF_TIDS; i++) {
1445 rxtid = &p_aggr->rx_tid[i];
1446 rxtid->aggr = false;
1447 rxtid->progress = false;
1448 rxtid->timer_mon = false;
1449 skb_queue_head_init(&rxtid->q);
1450 spin_lock_init(&rxtid->lock);
1451 }
1452
1453 return p_aggr;
1454 }
1455
1456 void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid)
1457 {
1458 struct aggr_info *p_aggr = vif->aggr_cntxt;
1459 struct rxtid *rxtid;
1460
1461 if (!p_aggr)
1462 return;
1463
1464 rxtid = &p_aggr->rx_tid[tid];
1465
1466 if (rxtid->aggr)
1467 aggr_delete_tid_state(p_aggr, tid);
1468 }
1469
1470 void aggr_reset_state(struct aggr_info *aggr_info)
1471 {
1472 u8 tid;
1473
1474 for (tid = 0; tid < NUM_OF_TIDS; tid++)
1475 aggr_delete_tid_state(aggr_info, tid);
1476 }
1477
1478 /* clean up our amsdu buffer list */
1479 void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar)
1480 {
1481 struct htc_packet *packet, *tmp_pkt;
1482
1483 spin_lock_bh(&ar->lock);
1484 if (list_empty(&ar->amsdu_rx_buffer_queue)) {
1485 spin_unlock_bh(&ar->lock);
1486 return;
1487 }
1488
1489 list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue,
1490 list) {
1491 list_del(&packet->list);
1492 spin_unlock_bh(&ar->lock);
1493 dev_kfree_skb(packet->pkt_cntxt);
1494 spin_lock_bh(&ar->lock);
1495 }
1496
1497 spin_unlock_bh(&ar->lock);
1498 }
1499
1500 void aggr_module_destroy(struct aggr_info *aggr_info)
1501 {
1502 struct rxtid *rxtid;
1503 u8 i, k;
1504
1505 if (!aggr_info)
1506 return;
1507
1508 if (aggr_info->timer_scheduled) {
1509 del_timer(&aggr_info->timer);
1510 aggr_info->timer_scheduled = false;
1511 }
1512
1513 for (i = 0; i < NUM_OF_TIDS; i++) {
1514 rxtid = &aggr_info->rx_tid[i];
1515 if (rxtid->hold_q) {
1516 for (k = 0; k < rxtid->hold_q_sz; k++)
1517 dev_kfree_skb(rxtid->hold_q[k].skb);
1518 kfree(rxtid->hold_q);
1519 }
1520
1521 skb_queue_purge(&rxtid->q);
1522 }
1523
1524 skb_queue_purge(&aggr_info->free_q);
1525 kfree(aggr_info);
1526 }
This page took 0.065331 seconds and 6 git commands to generate.