2 * Copyright (c) 2004-2011 Atheros Communications Inc.
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.
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.
20 static u8
ath6kl_ibss_map_epid(struct sk_buff
*skb
, struct net_device
*dev
,
23 struct ath6kl
*ar
= ath6kl_priv(dev
);
24 struct ethhdr
*eth_hdr
;
30 eth_hdr
= (struct ethhdr
*) (datap
+ sizeof(struct wmi_data_hdr
));
32 if (is_multicast_ether_addr(eth_hdr
->h_dest
))
35 for (i
= 0; i
< ar
->node_num
; i
++) {
36 if (memcmp(eth_hdr
->h_dest
, ar
->node_map
[i
].mac_addr
,
39 ar
->node_map
[i
].tx_pend
++;
40 return ar
->node_map
[i
].ep_id
;
43 if ((ep_map
== -1) && !ar
->node_map
[i
].tx_pend
)
48 ep_map
= ar
->node_num
;
50 if (ar
->node_num
> MAX_NODE_NUM
)
51 return ENDPOINT_UNUSED
;
54 memcpy(ar
->node_map
[ep_map
].mac_addr
, eth_hdr
->h_dest
, ETH_ALEN
);
56 for (i
= ENDPOINT_2
; i
<= ENDPOINT_5
; i
++) {
57 if (!ar
->tx_pending
[i
]) {
58 ar
->node_map
[ep_map
].ep_id
= i
;
63 * No free endpoint is available, start redistribution on
64 * the inuse endpoints.
66 if (i
== ENDPOINT_5
) {
67 ar
->node_map
[ep_map
].ep_id
= ar
->next_ep_id
;
69 if (ar
->next_ep_id
> ENDPOINT_5
)
70 ar
->next_ep_id
= ENDPOINT_2
;
75 ar
->node_map
[ep_map
].tx_pend
++;
77 return ar
->node_map
[ep_map
].ep_id
;
80 static bool ath6kl_powersave_ap(struct ath6kl_vif
*vif
, struct sk_buff
*skb
,
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
;
88 if (is_multicast_ether_addr(datap
->h_dest
)) {
92 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
93 if (ar
->sta_list
[ctr
].sta_flags
& STA_PS_SLEEP
) {
101 * If this transmit is not because of a Dtim Expiry
104 if (!test_bit(DTIM_EXPIRED
, &vif
->flags
)) {
105 bool is_mcastq_empty
= false;
107 spin_lock_bh(&ar
->mcastpsq_lock
);
109 skb_queue_empty(&ar
->mcastpsq
);
110 skb_queue_tail(&ar
->mcastpsq
, skb
);
111 spin_unlock_bh(&ar
->mcastpsq_lock
);
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.
119 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
126 * This transmit is because of Dtim expiry.
127 * Determine if MoreData bit has to be set.
129 spin_lock_bh(&ar
->mcastpsq_lock
);
130 if (!skb_queue_empty(&ar
->mcastpsq
))
132 spin_unlock_bh(&ar
->mcastpsq_lock
);
136 conn
= ath6kl_find_sta(vif
, datap
->h_dest
);
140 /* Inform the caller that the skb is consumed */
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
);
153 * If this is the first pkt getting queued
154 * for this STA, update the PVB for this
158 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
165 * This tx is because of a PsPoll.
166 * Determine if MoreData bit has to be set.
168 spin_lock_bh(&conn
->psq_lock
);
169 if (!skb_queue_empty(&conn
->psq
))
171 spin_unlock_bh(&conn
->psq_lock
);
181 int ath6kl_control_tx(void *devt
, struct sk_buff
*skb
,
182 enum htc_endpoint_id eid
)
184 struct ath6kl
*ar
= devt
;
186 struct ath6kl_cookie
*cookie
= NULL
;
188 spin_lock_bh(&ar
->lock
);
190 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
191 "%s: skb=0x%p, len=0x%x eid =%d\n", __func__
,
194 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
) && (eid
== ar
->ctrl_ep
)) {
196 * Control endpoint is full, don't allocate resources, we
197 * are just going to drop this packet.
200 ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
203 cookie
= ath6kl_alloc_cookie(ar
);
205 if (cookie
== NULL
) {
206 spin_unlock_bh(&ar
->lock
);
211 ar
->tx_pending
[eid
]++;
213 if (eid
!= ar
->ctrl_ep
)
214 ar
->total_tx_data_pend
++;
216 spin_unlock_bh(&ar
->lock
);
220 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
221 eid
, ATH6KL_CONTROL_PKT_TAG
);
224 * This interface is asynchronous, if there is an error, cleanup
225 * will happen in the TX completion callback.
227 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
236 int ath6kl_data_tx(struct sk_buff
*skb
, struct net_device
*dev
)
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
);
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;
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
);
252 /* If target is not associated */
253 if (!test_bit(CONNECTED
, &vif
->flags
)) {
258 if (!test_bit(WMI_READY
, &ar
->flag
))
261 /* AP mode Power saving processing */
262 if (vif
->nw_type
== AP_NETWORK
) {
263 if (ath6kl_powersave_ap(vif
, skb
, &more_data
))
267 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
268 if (skb_headroom(skb
) < dev
->needed_headroom
) {
269 struct sk_buff
*tmp_skb
= skb
;
271 skb
= skb_realloc_headroom(skb
, dev
->needed_headroom
);
274 vif
->net_stats
.tx_dropped
++;
279 if (ath6kl_wmi_dix_2_dot3(ar
->wmi
, skb
)) {
280 ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
284 if (ath6kl_wmi_data_hdr_add(ar
->wmi
, skb
, DATA_MSGTYPE
,
285 more_data
, 0, 0, NULL
,
287 ath6kl_err("wmi_data_hdr_add failed\n");
291 if ((vif
->nw_type
== ADHOC_NETWORK
) &&
292 ar
->ibss_ps_enable
&& test_bit(CONNECTED
, &vif
->flags
))
293 chk_adhoc_ps_mapping
= true;
295 /* get the stream mapping */
296 ret
= ath6kl_wmi_implicit_create_pstream(ar
->wmi
,
297 vif
->fw_vif_idx
, skb
,
298 0, test_bit(WMM_ENABLED
, &vif
->flags
), &ac
);
305 spin_lock_bh(&ar
->lock
);
307 if (chk_adhoc_ps_mapping
)
308 eid
= ath6kl_ibss_map_epid(skb
, dev
, &map_no
);
310 eid
= ar
->ac2ep_map
[ac
];
312 if (eid
== 0 || eid
== ENDPOINT_UNUSED
) {
313 ath6kl_err("eid %d is not mapped!\n", eid
);
314 spin_unlock_bh(&ar
->lock
);
318 /* allocate resource for this packet */
319 cookie
= ath6kl_alloc_cookie(ar
);
322 spin_unlock_bh(&ar
->lock
);
326 /* update counts while the lock is held */
327 ar
->tx_pending
[eid
]++;
328 ar
->total_tx_data_pend
++;
330 spin_unlock_bh(&ar
->lock
);
332 if (!IS_ALIGNED((unsigned long) skb
->data
- HTC_HDR_LENGTH
, 4) &&
335 * We will touch (move the buffer data to align it. Since the
336 * skb buffer is cloned and not only the header is changed, we
337 * have to copy it to allow the changes. Since we are copying
338 * the data here, we may as well align it by reserving suitable
339 * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
341 struct sk_buff
*nskb
;
343 nskb
= skb_copy_expand(skb
, HTC_HDR_LENGTH
, 0, GFP_ATOMIC
);
351 cookie
->map_no
= map_no
;
352 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
355 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "tx ",
356 skb
->data
, skb
->len
);
359 * HTC interface is asynchronous, if this fails, cleanup will
360 * happen in the ath6kl_tx_complete callback.
362 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
369 vif
->net_stats
.tx_dropped
++;
370 vif
->net_stats
.tx_aborted_errors
++;
375 /* indicate tx activity or inactivity on a WMI stream */
376 void ath6kl_indicate_tx_activity(void *devt
, u8 traffic_class
, bool active
)
378 struct ath6kl
*ar
= devt
;
379 enum htc_endpoint_id eid
;
382 eid
= ar
->ac2ep_map
[traffic_class
];
384 if (!test_bit(WMI_ENABLED
, &ar
->flag
))
387 spin_lock_bh(&ar
->lock
);
389 ar
->ac_stream_active
[traffic_class
] = active
;
393 * Keep track of the active stream with the highest
396 if (ar
->ac_stream_pri_map
[traffic_class
] >
397 ar
->hiac_stream_active_pri
)
398 /* set the new highest active priority */
399 ar
->hiac_stream_active_pri
=
400 ar
->ac_stream_pri_map
[traffic_class
];
404 * We may have to search for the next active stream
405 * that is the highest priority.
407 if (ar
->hiac_stream_active_pri
==
408 ar
->ac_stream_pri_map
[traffic_class
]) {
410 * The highest priority stream just went inactive
411 * reset and search for the "next" highest "active"
414 ar
->hiac_stream_active_pri
= 0;
416 for (i
= 0; i
< WMM_NUM_AC
; i
++) {
417 if (ar
->ac_stream_active
[i
] &&
418 (ar
->ac_stream_pri_map
[i
] >
419 ar
->hiac_stream_active_pri
))
421 * Set the new highest active
424 ar
->hiac_stream_active_pri
=
425 ar
->ac_stream_pri_map
[i
];
430 spin_unlock_bh(&ar
->lock
);
433 /* notify HTC, this may cause credit distribution changes */
434 ath6kl_htc_indicate_activity_change(ar
->htc_target
, eid
, active
);
437 enum htc_send_full_action
ath6kl_tx_queue_full(struct htc_target
*target
,
438 struct htc_packet
*packet
)
440 struct ath6kl
*ar
= target
->dev
->ar
;
441 struct ath6kl_vif
*vif
;
442 enum htc_endpoint_id endpoint
= packet
->endpoint
;
443 enum htc_send_full_action action
= HTC_SEND_FULL_KEEP
;
445 if (endpoint
== ar
->ctrl_ep
) {
447 * Under normal WMI if this is getting full, then something
448 * is running rampant the host should not be exhausting the
449 * WMI queue with too many commands the only exception to
450 * this is during testing using endpointping.
452 spin_lock_bh(&ar
->lock
);
453 set_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
454 spin_unlock_bh(&ar
->lock
);
455 ath6kl_err("wmi ctrl ep is full\n");
456 goto stop_adhoc_netq
;
459 if (packet
->info
.tx
.tag
== ATH6KL_CONTROL_PKT_TAG
)
460 goto stop_adhoc_netq
;
463 * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
464 * the highest active stream.
466 if (ar
->ac_stream_pri_map
[ar
->ep2ac_map
[endpoint
]] <
467 ar
->hiac_stream_active_pri
&&
468 ar
->cookie_count
<= MAX_HI_COOKIE_NUM
) {
470 * Give preference to the highest priority stream by
471 * dropping the packets which overflowed.
473 action
= HTC_SEND_FULL_DROP
;
474 goto stop_adhoc_netq
;
479 spin_lock_bh(&ar
->list_lock
);
480 list_for_each_entry(vif
, &ar
->vif_list
, list
) {
481 if (vif
->nw_type
== ADHOC_NETWORK
) {
482 spin_unlock_bh(&ar
->list_lock
);
484 spin_lock_bh(&vif
->if_lock
);
485 set_bit(NETQ_STOPPED
, &vif
->flags
);
486 spin_unlock_bh(&vif
->if_lock
);
487 netif_stop_queue(vif
->ndev
);
492 spin_unlock_bh(&ar
->list_lock
);
497 /* TODO this needs to be looked at */
498 static void ath6kl_tx_clear_node_map(struct ath6kl_vif
*vif
,
499 enum htc_endpoint_id eid
, u32 map_no
)
501 struct ath6kl
*ar
= vif
->ar
;
504 if (vif
->nw_type
!= ADHOC_NETWORK
)
507 if (!ar
->ibss_ps_enable
)
510 if (eid
== ar
->ctrl_ep
)
517 ar
->node_map
[map_no
].tx_pend
--;
519 if (ar
->node_map
[map_no
].tx_pend
)
522 if (map_no
!= (ar
->node_num
- 1))
525 for (i
= ar
->node_num
; i
> 0; i
--) {
526 if (ar
->node_map
[i
- 1].tx_pend
)
529 memset(&ar
->node_map
[i
- 1], 0,
530 sizeof(struct ath6kl_node_mapping
));
535 void ath6kl_tx_complete(void *context
, struct list_head
*packet_queue
)
537 struct ath6kl
*ar
= context
;
538 struct sk_buff_head skb_queue
;
539 struct htc_packet
*packet
;
541 struct ath6kl_cookie
*ath6kl_cookie
;
544 enum htc_endpoint_id eid
;
545 bool wake_event
= false;
546 bool flushing
[MAX_NUM_VIF
] = {false};
548 struct ath6kl_vif
*vif
;
550 skb_queue_head_init(&skb_queue
);
552 /* lock the driver as we update internal state */
553 spin_lock_bh(&ar
->lock
);
555 /* reap completed packets */
556 while (!list_empty(packet_queue
)) {
558 packet
= list_first_entry(packet_queue
, struct htc_packet
,
560 list_del(&packet
->list
);
562 ath6kl_cookie
= (struct ath6kl_cookie
*)packet
->pkt_cntxt
;
566 status
= packet
->status
;
567 skb
= ath6kl_cookie
->skb
;
568 eid
= packet
->endpoint
;
569 map_no
= ath6kl_cookie
->map_no
;
571 if (!skb
|| !skb
->data
)
574 packet
->buf
= skb
->data
;
576 __skb_queue_tail(&skb_queue
, skb
);
578 if (!status
&& (packet
->act_len
!= skb
->len
))
581 ar
->tx_pending
[eid
]--;
583 if (eid
!= ar
->ctrl_ep
)
584 ar
->total_tx_data_pend
--;
586 if (eid
== ar
->ctrl_ep
) {
587 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
))
588 clear_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
590 if (ar
->tx_pending
[eid
] == 0)
594 if (eid
== ar
->ctrl_ep
) {
595 if_idx
= wmi_cmd_hdr_get_if_idx(
596 (struct wmi_cmd_hdr
*) skb
->data
);
598 if_idx
= wmi_data_hdr_get_if_idx(
599 (struct wmi_data_hdr
*) skb
->data
);
602 vif
= ath6kl_get_vif_by_index(ar
, if_idx
);
604 ath6kl_free_cookie(ar
, ath6kl_cookie
);
609 if (status
== -ECANCELED
)
610 /* a packet was flushed */
611 flushing
[if_idx
] = true;
613 vif
->net_stats
.tx_errors
++;
615 if (status
!= -ENOSPC
&& status
!= -ECANCELED
)
616 ath6kl_warn("tx complete error: %d\n", status
);
618 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
619 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
620 __func__
, skb
, packet
->buf
, packet
->act_len
,
623 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
624 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
625 __func__
, skb
, packet
->buf
, packet
->act_len
,
628 flushing
[if_idx
] = false;
629 vif
->net_stats
.tx_packets
++;
630 vif
->net_stats
.tx_bytes
+= skb
->len
;
633 ath6kl_tx_clear_node_map(vif
, eid
, map_no
);
635 ath6kl_free_cookie(ar
, ath6kl_cookie
);
637 if (test_bit(NETQ_STOPPED
, &vif
->flags
))
638 clear_bit(NETQ_STOPPED
, &vif
->flags
);
641 spin_unlock_bh(&ar
->lock
);
643 __skb_queue_purge(&skb_queue
);
646 spin_lock_bh(&ar
->list_lock
);
647 list_for_each_entry(vif
, &ar
->vif_list
, list
) {
648 if (test_bit(CONNECTED
, &vif
->flags
) &&
649 !flushing
[vif
->fw_vif_idx
]) {
650 spin_unlock_bh(&ar
->list_lock
);
651 netif_wake_queue(vif
->ndev
);
652 spin_lock_bh(&ar
->list_lock
);
655 spin_unlock_bh(&ar
->list_lock
);
658 wake_up(&ar
->event_wq
);
664 spin_unlock_bh(&ar
->lock
);
668 void ath6kl_tx_data_cleanup(struct ath6kl
*ar
)
672 /* flush all the data (non-control) streams */
673 for (i
= 0; i
< WMM_NUM_AC
; i
++)
674 ath6kl_htc_flush_txep(ar
->htc_target
, ar
->ac2ep_map
[i
],
675 ATH6KL_DATA_PKT_TAG
);
680 static void ath6kl_deliver_frames_to_nw_stack(struct net_device
*dev
,
688 if (!(skb
->dev
->flags
& IFF_UP
)) {
693 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
698 static void ath6kl_alloc_netbufs(struct sk_buff_head
*q
, u16 num
)
703 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
705 ath6kl_err("netbuf allocation failed\n");
708 skb_queue_tail(q
, skb
);
713 static struct sk_buff
*aggr_get_free_skb(struct aggr_info
*p_aggr
)
715 struct sk_buff
*skb
= NULL
;
717 if (skb_queue_len(&p_aggr
->free_q
) < (AGGR_NUM_OF_FREE_NETBUFS
>> 2))
718 ath6kl_alloc_netbufs(&p_aggr
->free_q
, AGGR_NUM_OF_FREE_NETBUFS
);
720 skb
= skb_dequeue(&p_aggr
->free_q
);
725 void ath6kl_rx_refill(struct htc_target
*target
, enum htc_endpoint_id endpoint
)
727 struct ath6kl
*ar
= target
->dev
->ar
;
731 struct htc_packet
*packet
;
732 struct list_head queue
;
734 n_buf_refill
= ATH6KL_MAX_RX_BUFFERS
-
735 ath6kl_htc_get_rxbuf_num(ar
->htc_target
, endpoint
);
737 if (n_buf_refill
<= 0)
740 INIT_LIST_HEAD(&queue
);
742 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
743 "%s: providing htc with %d buffers at eid=%d\n",
744 __func__
, n_buf_refill
, endpoint
);
746 for (rx_buf
= 0; rx_buf
< n_buf_refill
; rx_buf
++) {
747 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
751 packet
= (struct htc_packet
*) skb
->head
;
752 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
753 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
754 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
755 ATH6KL_BUFFER_SIZE
, endpoint
);
756 list_add_tail(&packet
->list
, &queue
);
759 if (!list_empty(&queue
))
760 ath6kl_htc_add_rxbuf_multiple(ar
->htc_target
, &queue
);
763 void ath6kl_refill_amsdu_rxbufs(struct ath6kl
*ar
, int count
)
765 struct htc_packet
*packet
;
769 skb
= ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE
);
773 packet
= (struct htc_packet
*) skb
->head
;
774 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
775 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
776 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
777 ATH6KL_AMSDU_BUFFER_SIZE
, 0);
778 spin_lock_bh(&ar
->lock
);
779 list_add_tail(&packet
->list
, &ar
->amsdu_rx_buffer_queue
);
780 spin_unlock_bh(&ar
->lock
);
786 * Callback to allocate a receive buffer for a pending packet. We use a
787 * pre-allocated list of buffers of maximum AMSDU size (4K).
789 struct htc_packet
*ath6kl_alloc_amsdu_rxbuf(struct htc_target
*target
,
790 enum htc_endpoint_id endpoint
,
793 struct ath6kl
*ar
= target
->dev
->ar
;
794 struct htc_packet
*packet
= NULL
;
795 struct list_head
*pkt_pos
;
796 int refill_cnt
= 0, depth
= 0;
798 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: eid=%d, len:%d\n",
799 __func__
, endpoint
, len
);
801 if ((len
<= ATH6KL_BUFFER_SIZE
) ||
802 (len
> ATH6KL_AMSDU_BUFFER_SIZE
))
805 spin_lock_bh(&ar
->lock
);
807 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
808 spin_unlock_bh(&ar
->lock
);
809 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
;
813 packet
= list_first_entry(&ar
->amsdu_rx_buffer_queue
,
814 struct htc_packet
, list
);
815 list_del(&packet
->list
);
816 list_for_each(pkt_pos
, &ar
->amsdu_rx_buffer_queue
)
819 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
- depth
;
820 spin_unlock_bh(&ar
->lock
);
822 /* set actual endpoint ID */
823 packet
->endpoint
= endpoint
;
826 if (refill_cnt
>= ATH6KL_AMSDU_REFILL_THRESHOLD
)
827 ath6kl_refill_amsdu_rxbufs(ar
, refill_cnt
);
832 static void aggr_slice_amsdu(struct aggr_info
*p_aggr
,
833 struct rxtid
*rxtid
, struct sk_buff
*skb
)
835 struct sk_buff
*new_skb
;
837 u16 frame_8023_len
, payload_8023_len
, mac_hdr_len
, amsdu_len
;
840 mac_hdr_len
= sizeof(struct ethhdr
);
841 framep
= skb
->data
+ mac_hdr_len
;
842 amsdu_len
= skb
->len
- mac_hdr_len
;
844 while (amsdu_len
> mac_hdr_len
) {
845 hdr
= (struct ethhdr
*) framep
;
846 payload_8023_len
= ntohs(hdr
->h_proto
);
848 if (payload_8023_len
< MIN_MSDU_SUBFRAME_PAYLOAD_LEN
||
849 payload_8023_len
> MAX_MSDU_SUBFRAME_PAYLOAD_LEN
) {
850 ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
855 frame_8023_len
= payload_8023_len
+ mac_hdr_len
;
856 new_skb
= aggr_get_free_skb(p_aggr
);
858 ath6kl_err("no buffer available\n");
862 memcpy(new_skb
->data
, framep
, frame_8023_len
);
863 skb_put(new_skb
, frame_8023_len
);
864 if (ath6kl_wmi_dot3_2_dix(new_skb
)) {
865 ath6kl_err("dot3_2_dix error\n");
866 dev_kfree_skb(new_skb
);
870 skb_queue_tail(&rxtid
->q
, new_skb
);
872 /* Is this the last subframe within this aggregate ? */
873 if ((amsdu_len
- frame_8023_len
) == 0)
876 /* Add the length of A-MSDU subframe padding bytes -
877 * Round to nearest word.
879 frame_8023_len
= ALIGN(frame_8023_len
, 4);
881 framep
+= frame_8023_len
;
882 amsdu_len
-= frame_8023_len
;
888 static void aggr_deque_frms(struct aggr_info
*p_aggr
, u8 tid
,
889 u16 seq_no
, u8 order
)
893 struct skb_hold_q
*node
;
894 u16 idx
, idx_end
, seq_end
;
895 struct rxtid_stats
*stats
;
900 rxtid
= &p_aggr
->rx_tid
[tid
];
901 stats
= &p_aggr
->stat
[tid
];
903 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
906 * idx_end is typically the last possible frame in the window,
907 * but changes to 'the' seq_no, when BAR comes. If seq_no
908 * is non-zero, we will go up to that and stop.
909 * Note: last seq no in current window will occupy the same
910 * index position as index that is just previous to start.
911 * An imp point : if win_sz is 7, for seq_no space of 4095,
912 * then, there would be holes when sequence wrap around occurs.
913 * Target should judiciously choose the win_sz, based on
914 * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
915 * 2, 4, 8, 16 win_sz works fine).
916 * We must deque from "idx" to "idx_end", including both.
918 seq_end
= seq_no
? seq_no
: rxtid
->seq_next
;
919 idx_end
= AGGR_WIN_IDX(seq_end
, rxtid
->hold_q_sz
);
921 spin_lock_bh(&rxtid
->lock
);
924 node
= &rxtid
->hold_q
[idx
];
925 if ((order
== 1) && (!node
->skb
))
930 aggr_slice_amsdu(p_aggr
, rxtid
, node
->skb
);
932 skb_queue_tail(&rxtid
->q
, node
->skb
);
937 rxtid
->seq_next
= ATH6KL_NEXT_SEQ_NO(rxtid
->seq_next
);
938 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
939 } while (idx
!= idx_end
);
941 spin_unlock_bh(&rxtid
->lock
);
943 stats
->num_delivered
+= skb_queue_len(&rxtid
->q
);
945 while ((skb
= skb_dequeue(&rxtid
->q
)))
946 ath6kl_deliver_frames_to_nw_stack(p_aggr
->dev
, skb
);
949 static bool aggr_process_recv_frm(struct aggr_info
*agg_info
, u8 tid
,
951 bool is_amsdu
, struct sk_buff
*frame
)
954 struct rxtid_stats
*stats
;
956 struct skb_hold_q
*node
;
957 u16 idx
, st
, cur
, end
;
958 bool is_queued
= false;
961 rxtid
= &agg_info
->rx_tid
[tid
];
962 stats
= &agg_info
->stat
[tid
];
964 stats
->num_into_aggr
++;
968 aggr_slice_amsdu(agg_info
, rxtid
, frame
);
971 while ((skb
= skb_dequeue(&rxtid
->q
)))
972 ath6kl_deliver_frames_to_nw_stack(agg_info
->dev
,
978 /* Check the incoming sequence no, if it's in the window */
979 st
= rxtid
->seq_next
;
981 end
= (st
+ rxtid
->hold_q_sz
-1) & ATH6KL_MAX_SEQ_NO
;
983 if (((st
< end
) && (cur
< st
|| cur
> end
)) ||
984 ((st
> end
) && (cur
> end
) && (cur
< st
))) {
985 extended_end
= (end
+ rxtid
->hold_q_sz
- 1) &
988 if (((end
< extended_end
) &&
989 (cur
< end
|| cur
> extended_end
)) ||
990 ((end
> extended_end
) && (cur
> extended_end
) &&
992 aggr_deque_frms(agg_info
, tid
, 0, 0);
993 if (cur
>= rxtid
->hold_q_sz
- 1)
994 rxtid
->seq_next
= cur
- (rxtid
->hold_q_sz
- 1);
996 rxtid
->seq_next
= ATH6KL_MAX_SEQ_NO
-
997 (rxtid
->hold_q_sz
- 2 - cur
);
1000 * Dequeue only those frames that are outside the
1001 * new shifted window.
1003 if (cur
>= rxtid
->hold_q_sz
- 1)
1004 st
= cur
- (rxtid
->hold_q_sz
- 1);
1006 st
= ATH6KL_MAX_SEQ_NO
-
1007 (rxtid
->hold_q_sz
- 2 - cur
);
1009 aggr_deque_frms(agg_info
, tid
, st
, 0);
1015 idx
= AGGR_WIN_IDX(seq_no
, rxtid
->hold_q_sz
);
1017 node
= &rxtid
->hold_q
[idx
];
1019 spin_lock_bh(&rxtid
->lock
);
1022 * Is the cur frame duplicate or something beyond our window(hold_q
1023 * -> which is 2x, already)?
1025 * 1. Duplicate is easy - drop incoming frame.
1026 * 2. Not falling in current sliding window.
1027 * 2a. is the frame_seq_no preceding current tid_seq_no?
1028 * -> drop the frame. perhaps sender did not get our ACK.
1029 * this is taken care of above.
1030 * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
1031 * -> Taken care of it above, by moving window forward.
1033 dev_kfree_skb(node
->skb
);
1038 node
->is_amsdu
= is_amsdu
;
1039 node
->seq_no
= seq_no
;
1046 spin_unlock_bh(&rxtid
->lock
);
1048 aggr_deque_frms(agg_info
, tid
, 0, 1);
1050 if (agg_info
->timer_scheduled
)
1051 rxtid
->progress
= true;
1053 for (idx
= 0 ; idx
< rxtid
->hold_q_sz
; idx
++) {
1054 if (rxtid
->hold_q
[idx
].skb
) {
1056 * There is a frame in the queue and no
1057 * timer so start a timer to ensure that
1058 * the frame doesn't remain stuck
1061 agg_info
->timer_scheduled
= true;
1062 mod_timer(&agg_info
->timer
,
1064 HZ
* (AGGR_RX_TIMEOUT
) / 1000));
1065 rxtid
->progress
= false;
1066 rxtid
->timer_mon
= true;
1074 void ath6kl_rx(struct htc_target
*target
, struct htc_packet
*packet
)
1076 struct ath6kl
*ar
= target
->dev
->ar
;
1077 struct sk_buff
*skb
= packet
->pkt_cntxt
;
1078 struct wmi_rx_meta_v2
*meta
;
1079 struct wmi_data_hdr
*dhdr
;
1081 u8 meta_type
, dot11_hdr
= 0;
1082 int status
= packet
->status
;
1083 enum htc_endpoint_id ept
= packet
->endpoint
;
1084 bool is_amsdu
, prev_ps
, ps_state
= false;
1085 struct ath6kl_sta
*conn
= NULL
;
1086 struct sk_buff
*skb1
= NULL
;
1087 struct ethhdr
*datap
= NULL
;
1088 struct ath6kl_vif
*vif
;
1092 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
1093 "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
1094 __func__
, ar
, ept
, skb
, packet
->buf
,
1095 packet
->act_len
, status
);
1097 if (status
|| !(skb
->data
+ HTC_HDR_LENGTH
)) {
1102 skb_put(skb
, packet
->act_len
+ HTC_HDR_LENGTH
);
1103 skb_pull(skb
, HTC_HDR_LENGTH
);
1105 if (ept
== ar
->ctrl_ep
) {
1107 wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr
*) skb
->data
);
1110 wmi_data_hdr_get_if_idx((struct wmi_data_hdr
*) skb
->data
);
1113 vif
= ath6kl_get_vif_by_index(ar
, if_idx
);
1120 * Take lock to protect buffer counts and adaptive power throughput
1123 spin_lock_bh(&vif
->if_lock
);
1125 vif
->net_stats
.rx_packets
++;
1126 vif
->net_stats
.rx_bytes
+= packet
->act_len
;
1128 spin_unlock_bh(&vif
->if_lock
);
1131 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "rx ",
1132 skb
->data
, skb
->len
);
1134 skb
->dev
= vif
->ndev
;
1136 if (!test_bit(WMI_ENABLED
, &ar
->flag
)) {
1137 if (EPPING_ALIGNMENT_PAD
> 0)
1138 skb_pull(skb
, EPPING_ALIGNMENT_PAD
);
1139 ath6kl_deliver_frames_to_nw_stack(vif
->ndev
, skb
);
1143 ath6kl_check_wow_status(ar
);
1145 if (ept
== ar
->ctrl_ep
) {
1146 ath6kl_wmi_control_rx(ar
->wmi
, skb
);
1150 min_hdr_len
= sizeof(struct ethhdr
) + sizeof(struct wmi_data_hdr
) +
1151 sizeof(struct ath6kl_llc_snap_hdr
);
1153 dhdr
= (struct wmi_data_hdr
*) skb
->data
;
1156 * In the case of AP mode we may receive NULL data frames
1157 * that do not have LLC hdr. They are 16 bytes in size.
1158 * Allow these frames in the AP mode.
1160 if (vif
->nw_type
!= AP_NETWORK
&&
1161 ((packet
->act_len
< min_hdr_len
) ||
1162 (packet
->act_len
> WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
))) {
1163 ath6kl_info("frame len is too short or too long\n");
1164 vif
->net_stats
.rx_errors
++;
1165 vif
->net_stats
.rx_length_errors
++;
1170 /* Get the Power save state of the STA */
1171 if (vif
->nw_type
== AP_NETWORK
) {
1172 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1174 ps_state
= !!((dhdr
->info
>> WMI_DATA_HDR_PS_SHIFT
) &
1175 WMI_DATA_HDR_PS_MASK
);
1177 offset
= sizeof(struct wmi_data_hdr
);
1179 switch (meta_type
) {
1182 case WMI_META_VERSION_1
:
1183 offset
+= sizeof(struct wmi_rx_meta_v1
);
1185 case WMI_META_VERSION_2
:
1186 offset
+= sizeof(struct wmi_rx_meta_v2
);
1192 datap
= (struct ethhdr
*) (skb
->data
+ offset
);
1193 conn
= ath6kl_find_sta(vif
, datap
->h_source
);
1201 * If there is a change in PS state of the STA,
1202 * take appropriate steps:
1204 * 1. If Sleep-->Awake, flush the psq for the STA
1205 * Clear the PVB for the STA.
1206 * 2. If Awake-->Sleep, Starting queueing frames
1209 prev_ps
= !!(conn
->sta_flags
& STA_PS_SLEEP
);
1212 conn
->sta_flags
|= STA_PS_SLEEP
;
1214 conn
->sta_flags
&= ~STA_PS_SLEEP
;
1216 if (prev_ps
^ !!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1217 if (!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1218 struct sk_buff
*skbuff
= NULL
;
1220 spin_lock_bh(&conn
->psq_lock
);
1221 while ((skbuff
= skb_dequeue(&conn
->psq
))
1223 spin_unlock_bh(&conn
->psq_lock
);
1224 ath6kl_data_tx(skbuff
, vif
->ndev
);
1225 spin_lock_bh(&conn
->psq_lock
);
1227 spin_unlock_bh(&conn
->psq_lock
);
1228 /* Clear the PVB for this STA */
1229 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
,
1234 /* drop NULL data frames here */
1235 if ((packet
->act_len
< min_hdr_len
) ||
1237 WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
)) {
1243 is_amsdu
= wmi_data_hdr_is_amsdu(dhdr
) ? true : false;
1244 tid
= wmi_data_hdr_get_up(dhdr
);
1245 seq_no
= wmi_data_hdr_get_seqno(dhdr
);
1246 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1247 dot11_hdr
= wmi_data_hdr_get_dot11(dhdr
);
1248 skb_pull(skb
, sizeof(struct wmi_data_hdr
));
1250 switch (meta_type
) {
1251 case WMI_META_VERSION_1
:
1252 skb_pull(skb
, sizeof(struct wmi_rx_meta_v1
));
1254 case WMI_META_VERSION_2
:
1255 meta
= (struct wmi_rx_meta_v2
*) skb
->data
;
1256 if (meta
->csum_flags
& 0x1) {
1257 skb
->ip_summed
= CHECKSUM_COMPLETE
;
1258 skb
->csum
= (__force __wsum
) meta
->csum
;
1260 skb_pull(skb
, sizeof(struct wmi_rx_meta_v2
));
1267 status
= ath6kl_wmi_dot11_hdr_remove(ar
->wmi
, skb
);
1269 status
= ath6kl_wmi_dot3_2_dix(skb
);
1273 * Drop frames that could not be processed (lack of
1280 if (!(vif
->ndev
->flags
& IFF_UP
)) {
1285 if (vif
->nw_type
== AP_NETWORK
) {
1286 datap
= (struct ethhdr
*) skb
->data
;
1287 if (is_multicast_ether_addr(datap
->h_dest
))
1289 * Bcast/Mcast frames should be sent to the
1290 * OS stack as well as on the air.
1292 skb1
= skb_copy(skb
, GFP_ATOMIC
);
1295 * Search for a connected STA with dstMac
1296 * as the Mac address. If found send the
1297 * frame to it on the air else send the
1298 * frame up the stack.
1300 conn
= ath6kl_find_sta(vif
, datap
->h_dest
);
1302 if (conn
&& ar
->intra_bss
) {
1305 } else if (conn
&& !ar
->intra_bss
) {
1311 ath6kl_data_tx(skb1
, vif
->ndev
);
1314 /* nothing to deliver up the stack */
1319 datap
= (struct ethhdr
*) skb
->data
;
1321 if (is_unicast_ether_addr(datap
->h_dest
) &&
1322 aggr_process_recv_frm(vif
->aggr_cntxt
, tid
, seq_no
,
1324 /* aggregation code will handle the skb */
1327 ath6kl_deliver_frames_to_nw_stack(vif
->ndev
, skb
);
1330 static void aggr_timeout(unsigned long arg
)
1333 struct aggr_info
*p_aggr
= (struct aggr_info
*) arg
;
1334 struct rxtid
*rxtid
;
1335 struct rxtid_stats
*stats
;
1337 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1338 rxtid
= &p_aggr
->rx_tid
[i
];
1339 stats
= &p_aggr
->stat
[i
];
1341 if (!rxtid
->aggr
|| !rxtid
->timer_mon
|| rxtid
->progress
)
1344 stats
->num_timeouts
++;
1345 ath6kl_dbg(ATH6KL_DBG_AGGR
,
1346 "aggr timeout (st %d end %d)\n",
1348 ((rxtid
->seq_next
+ rxtid
->hold_q_sz
-1) &
1349 ATH6KL_MAX_SEQ_NO
));
1350 aggr_deque_frms(p_aggr
, i
, 0, 0);
1353 p_aggr
->timer_scheduled
= false;
1355 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1356 rxtid
= &p_aggr
->rx_tid
[i
];
1358 if (rxtid
->aggr
&& rxtid
->hold_q
) {
1359 for (j
= 0; j
< rxtid
->hold_q_sz
; j
++) {
1360 if (rxtid
->hold_q
[j
].skb
) {
1361 p_aggr
->timer_scheduled
= true;
1362 rxtid
->timer_mon
= true;
1363 rxtid
->progress
= false;
1368 if (j
>= rxtid
->hold_q_sz
)
1369 rxtid
->timer_mon
= false;
1373 if (p_aggr
->timer_scheduled
)
1374 mod_timer(&p_aggr
->timer
,
1375 jiffies
+ msecs_to_jiffies(AGGR_RX_TIMEOUT
));
1378 static void aggr_delete_tid_state(struct aggr_info
*p_aggr
, u8 tid
)
1380 struct rxtid
*rxtid
;
1381 struct rxtid_stats
*stats
;
1383 if (!p_aggr
|| tid
>= NUM_OF_TIDS
)
1386 rxtid
= &p_aggr
->rx_tid
[tid
];
1387 stats
= &p_aggr
->stat
[tid
];
1390 aggr_deque_frms(p_aggr
, tid
, 0, 0);
1392 rxtid
->aggr
= false;
1393 rxtid
->progress
= false;
1394 rxtid
->timer_mon
= false;
1396 rxtid
->seq_next
= 0;
1397 rxtid
->hold_q_sz
= 0;
1399 kfree(rxtid
->hold_q
);
1400 rxtid
->hold_q
= NULL
;
1402 memset(stats
, 0, sizeof(struct rxtid_stats
));
1405 void aggr_recv_addba_req_evt(struct ath6kl_vif
*vif
, u8 tid
, u16 seq_no
,
1408 struct aggr_info
*p_aggr
= vif
->aggr_cntxt
;
1409 struct rxtid
*rxtid
;
1410 struct rxtid_stats
*stats
;
1416 rxtid
= &p_aggr
->rx_tid
[tid
];
1417 stats
= &p_aggr
->stat
[tid
];
1419 if (win_sz
< AGGR_WIN_SZ_MIN
|| win_sz
> AGGR_WIN_SZ_MAX
)
1420 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: win_sz %d, tid %d\n",
1421 __func__
, win_sz
, tid
);
1424 aggr_delete_tid_state(p_aggr
, tid
);
1426 rxtid
->seq_next
= seq_no
;
1427 hold_q_size
= TID_WINDOW_SZ(win_sz
) * sizeof(struct skb_hold_q
);
1428 rxtid
->hold_q
= kzalloc(hold_q_size
, GFP_KERNEL
);
1432 rxtid
->win_sz
= win_sz
;
1433 rxtid
->hold_q_sz
= TID_WINDOW_SZ(win_sz
);
1434 if (!skb_queue_empty(&rxtid
->q
))
1440 struct aggr_info
*aggr_init(struct net_device
*dev
)
1442 struct aggr_info
*p_aggr
= NULL
;
1443 struct rxtid
*rxtid
;
1446 p_aggr
= kzalloc(sizeof(struct aggr_info
), GFP_KERNEL
);
1448 ath6kl_err("failed to alloc memory for aggr_node\n");
1452 p_aggr
->aggr_sz
= AGGR_SZ_DEFAULT
;
1454 init_timer(&p_aggr
->timer
);
1455 p_aggr
->timer
.function
= aggr_timeout
;
1456 p_aggr
->timer
.data
= (unsigned long) p_aggr
;
1458 p_aggr
->timer_scheduled
= false;
1459 skb_queue_head_init(&p_aggr
->free_q
);
1461 ath6kl_alloc_netbufs(&p_aggr
->free_q
, AGGR_NUM_OF_FREE_NETBUFS
);
1463 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1464 rxtid
= &p_aggr
->rx_tid
[i
];
1465 rxtid
->aggr
= false;
1466 rxtid
->progress
= false;
1467 rxtid
->timer_mon
= false;
1468 skb_queue_head_init(&rxtid
->q
);
1469 spin_lock_init(&rxtid
->lock
);
1475 void aggr_recv_delba_req_evt(struct ath6kl_vif
*vif
, u8 tid
)
1477 struct aggr_info
*p_aggr
= vif
->aggr_cntxt
;
1478 struct rxtid
*rxtid
;
1483 rxtid
= &p_aggr
->rx_tid
[tid
];
1486 aggr_delete_tid_state(p_aggr
, tid
);
1489 void aggr_reset_state(struct aggr_info
*aggr_info
)
1493 for (tid
= 0; tid
< NUM_OF_TIDS
; tid
++)
1494 aggr_delete_tid_state(aggr_info
, tid
);
1497 /* clean up our amsdu buffer list */
1498 void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl
*ar
)
1500 struct htc_packet
*packet
, *tmp_pkt
;
1502 spin_lock_bh(&ar
->lock
);
1503 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
1504 spin_unlock_bh(&ar
->lock
);
1508 list_for_each_entry_safe(packet
, tmp_pkt
, &ar
->amsdu_rx_buffer_queue
,
1510 list_del(&packet
->list
);
1511 spin_unlock_bh(&ar
->lock
);
1512 dev_kfree_skb(packet
->pkt_cntxt
);
1513 spin_lock_bh(&ar
->lock
);
1516 spin_unlock_bh(&ar
->lock
);
1519 void aggr_module_destroy(struct aggr_info
*aggr_info
)
1521 struct rxtid
*rxtid
;
1527 if (aggr_info
->timer_scheduled
) {
1528 del_timer(&aggr_info
->timer
);
1529 aggr_info
->timer_scheduled
= false;
1532 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1533 rxtid
= &aggr_info
->rx_tid
[i
];
1534 if (rxtid
->hold_q
) {
1535 for (k
= 0; k
< rxtid
->hold_q_sz
; k
++)
1536 dev_kfree_skb(rxtid
->hold_q
[k
].skb
);
1537 kfree(rxtid
->hold_q
);
1540 skb_queue_purge(&rxtid
->q
);
1543 skb_queue_purge(&aggr_info
->free_q
);