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