2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 * tid - tid_mux0..tid_mux3
26 * aid - tid_mux4..tid_mux7
28 #define ATH6KL_TID_MASK 0xf
29 #define ATH6KL_AID_SHIFT 4
31 static inline u8
ath6kl_get_tid(u8 tid_mux
)
33 return tid_mux
& ATH6KL_TID_MASK
;
36 static inline u8
ath6kl_get_aid(u8 tid_mux
)
38 return tid_mux
>> ATH6KL_AID_SHIFT
;
41 static u8
ath6kl_ibss_map_epid(struct sk_buff
*skb
, struct net_device
*dev
,
44 struct ath6kl
*ar
= ath6kl_priv(dev
);
45 struct ethhdr
*eth_hdr
;
51 eth_hdr
= (struct ethhdr
*) (datap
+ sizeof(struct wmi_data_hdr
));
53 if (is_multicast_ether_addr(eth_hdr
->h_dest
))
56 for (i
= 0; i
< ar
->node_num
; i
++) {
57 if (memcmp(eth_hdr
->h_dest
, ar
->node_map
[i
].mac_addr
,
60 ar
->node_map
[i
].tx_pend
++;
61 return ar
->node_map
[i
].ep_id
;
64 if ((ep_map
== -1) && !ar
->node_map
[i
].tx_pend
)
69 ep_map
= ar
->node_num
;
71 if (ar
->node_num
> MAX_NODE_NUM
)
72 return ENDPOINT_UNUSED
;
75 memcpy(ar
->node_map
[ep_map
].mac_addr
, eth_hdr
->h_dest
, ETH_ALEN
);
77 for (i
= ENDPOINT_2
; i
<= ENDPOINT_5
; i
++) {
78 if (!ar
->tx_pending
[i
]) {
79 ar
->node_map
[ep_map
].ep_id
= i
;
84 * No free endpoint is available, start redistribution on
85 * the inuse endpoints.
87 if (i
== ENDPOINT_5
) {
88 ar
->node_map
[ep_map
].ep_id
= ar
->next_ep_id
;
90 if (ar
->next_ep_id
> ENDPOINT_5
)
91 ar
->next_ep_id
= ENDPOINT_2
;
96 ar
->node_map
[ep_map
].tx_pend
++;
98 return ar
->node_map
[ep_map
].ep_id
;
101 static bool ath6kl_process_uapsdq(struct ath6kl_sta
*conn
,
102 struct ath6kl_vif
*vif
,
106 struct ath6kl
*ar
= vif
->ar
;
107 bool is_apsdq_empty
= false;
108 struct ethhdr
*datap
= (struct ethhdr
*) skb
->data
;
109 u8 up
= 0, traffic_class
, *ip_hdr
;
111 struct ath6kl_llc_snap_hdr
*llc_hdr
;
113 if (conn
->sta_flags
& STA_PS_APSD_TRIGGER
) {
115 * This tx is because of a uAPSD trigger, determine
116 * more and EOSP bit. Set EOSP if queue is empty
117 * or sufficient frames are delivered for this trigger.
119 spin_lock_bh(&conn
->psq_lock
);
120 if (!skb_queue_empty(&conn
->apsdq
))
121 *flags
|= WMI_DATA_HDR_FLAGS_MORE
;
122 else if (conn
->sta_flags
& STA_PS_APSD_EOSP
)
123 *flags
|= WMI_DATA_HDR_FLAGS_EOSP
;
124 *flags
|= WMI_DATA_HDR_FLAGS_UAPSD
;
125 spin_unlock_bh(&conn
->psq_lock
);
127 } else if (!conn
->apsd_info
)
130 if (test_bit(WMM_ENABLED
, &vif
->flags
)) {
131 ether_type
= be16_to_cpu(datap
->h_proto
);
132 if (is_ethertype(ether_type
)) {
133 /* packet is in DIX format */
134 ip_hdr
= (u8
*)(datap
+ 1);
136 /* packet is in 802.3 format */
137 llc_hdr
= (struct ath6kl_llc_snap_hdr
*)
139 ether_type
= be16_to_cpu(llc_hdr
->eth_type
);
140 ip_hdr
= (u8
*)(llc_hdr
+ 1);
143 if (ether_type
== IP_ETHERTYPE
)
144 up
= ath6kl_wmi_determine_user_priority(
148 traffic_class
= ath6kl_wmi_get_traffic_class(up
);
150 if ((conn
->apsd_info
& (1 << traffic_class
)) == 0)
153 /* Queue the frames if the STA is sleeping */
154 spin_lock_bh(&conn
->psq_lock
);
155 is_apsdq_empty
= skb_queue_empty(&conn
->apsdq
);
156 skb_queue_tail(&conn
->apsdq
, skb
);
157 spin_unlock_bh(&conn
->psq_lock
);
160 * If this is the first pkt getting queued
161 * for this STA, update the PVB for this STA
163 if (is_apsdq_empty
) {
164 ath6kl_wmi_set_apsd_bfrd_traf(ar
->wmi
,
168 *flags
|= WMI_DATA_HDR_FLAGS_UAPSD
;
173 static bool ath6kl_process_psq(struct ath6kl_sta
*conn
,
174 struct ath6kl_vif
*vif
,
178 bool is_psq_empty
= false;
179 struct ath6kl
*ar
= vif
->ar
;
181 if (conn
->sta_flags
& STA_PS_POLLED
) {
182 spin_lock_bh(&conn
->psq_lock
);
183 if (!skb_queue_empty(&conn
->psq
))
184 *flags
|= WMI_DATA_HDR_FLAGS_MORE
;
185 spin_unlock_bh(&conn
->psq_lock
);
189 /* Queue the frames if the STA is sleeping */
190 spin_lock_bh(&conn
->psq_lock
);
191 is_psq_empty
= skb_queue_empty(&conn
->psq
);
192 skb_queue_tail(&conn
->psq
, skb
);
193 spin_unlock_bh(&conn
->psq_lock
);
196 * If this is the first pkt getting queued
197 * for this STA, update the PVB for this
201 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
207 static bool ath6kl_powersave_ap(struct ath6kl_vif
*vif
, struct sk_buff
*skb
,
210 struct ethhdr
*datap
= (struct ethhdr
*) skb
->data
;
211 struct ath6kl_sta
*conn
= NULL
;
212 bool ps_queued
= false;
213 struct ath6kl
*ar
= vif
->ar
;
215 if (is_multicast_ether_addr(datap
->h_dest
)) {
217 bool q_mcast
= false;
219 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
220 if (ar
->sta_list
[ctr
].sta_flags
& STA_PS_SLEEP
) {
228 * If this transmit is not because of a Dtim Expiry
231 if (!test_bit(DTIM_EXPIRED
, &vif
->flags
)) {
232 bool is_mcastq_empty
= false;
234 spin_lock_bh(&ar
->mcastpsq_lock
);
236 skb_queue_empty(&ar
->mcastpsq
);
237 skb_queue_tail(&ar
->mcastpsq
, skb
);
238 spin_unlock_bh(&ar
->mcastpsq_lock
);
241 * If this is the first Mcast pkt getting
242 * queued indicate to the target to set the
243 * BitmapControl LSB of the TIM IE.
246 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
253 * This transmit is because of Dtim expiry.
254 * Determine if MoreData bit has to be set.
256 spin_lock_bh(&ar
->mcastpsq_lock
);
257 if (!skb_queue_empty(&ar
->mcastpsq
))
258 *flags
|= WMI_DATA_HDR_FLAGS_MORE
;
259 spin_unlock_bh(&ar
->mcastpsq_lock
);
263 conn
= ath6kl_find_sta(vif
, datap
->h_dest
);
267 /* Inform the caller that the skb is consumed */
271 if (conn
->sta_flags
& STA_PS_SLEEP
) {
272 ps_queued
= ath6kl_process_uapsdq(conn
,
274 if (!(*flags
& WMI_DATA_HDR_FLAGS_UAPSD
))
275 ps_queued
= ath6kl_process_psq(conn
,
284 int ath6kl_control_tx(void *devt
, struct sk_buff
*skb
,
285 enum htc_endpoint_id eid
)
287 struct ath6kl
*ar
= devt
;
289 struct ath6kl_cookie
*cookie
= NULL
;
291 if (WARN_ON_ONCE(ar
->state
== ATH6KL_STATE_WOW
))
294 spin_lock_bh(&ar
->lock
);
296 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
297 "%s: skb=0x%p, len=0x%x eid =%d\n", __func__
,
300 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
) && (eid
== ar
->ctrl_ep
)) {
302 * Control endpoint is full, don't allocate resources, we
303 * are just going to drop this packet.
306 ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
309 cookie
= ath6kl_alloc_cookie(ar
);
311 if (cookie
== NULL
) {
312 spin_unlock_bh(&ar
->lock
);
317 ar
->tx_pending
[eid
]++;
319 if (eid
!= ar
->ctrl_ep
)
320 ar
->total_tx_data_pend
++;
322 spin_unlock_bh(&ar
->lock
);
326 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
327 eid
, ATH6KL_CONTROL_PKT_TAG
);
328 cookie
->htc_pkt
.skb
= skb
;
331 * This interface is asynchronous, if there is an error, cleanup
332 * will happen in the TX completion callback.
334 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
343 int ath6kl_data_tx(struct sk_buff
*skb
, struct net_device
*dev
)
345 struct ath6kl
*ar
= ath6kl_priv(dev
);
346 struct ath6kl_cookie
*cookie
= NULL
;
347 enum htc_endpoint_id eid
= ENDPOINT_UNUSED
;
348 struct ath6kl_vif
*vif
= netdev_priv(dev
);
350 u16 htc_tag
= ATH6KL_DATA_PKT_TAG
;
351 u8 ac
= 99 ; /* initialize to unmapped ac */
352 bool chk_adhoc_ps_mapping
= false;
354 struct wmi_tx_meta_v2 meta_v2
;
356 u8 csum_start
= 0, csum_dest
= 0, csum
= skb
->ip_summed
;
360 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
361 "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__
,
362 skb
, skb
->data
, skb
->len
);
364 /* If target is not associated */
365 if (!test_bit(CONNECTED
, &vif
->flags
)) {
370 if (WARN_ON_ONCE(ar
->state
!= ATH6KL_STATE_ON
)) {
375 if (!test_bit(WMI_READY
, &ar
->flag
))
378 /* AP mode Power saving processing */
379 if (vif
->nw_type
== AP_NETWORK
) {
380 if (ath6kl_powersave_ap(vif
, skb
, &flags
))
384 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
385 if ((dev
->features
& NETIF_F_IP_CSUM
) &&
386 (csum
== CHECKSUM_PARTIAL
)) {
387 csum_start
= skb
->csum_start
-
388 (skb_network_header(skb
) - skb
->head
) +
389 sizeof(struct ath6kl_llc_snap_hdr
);
390 csum_dest
= skb
->csum_offset
+ csum_start
;
393 if (skb_headroom(skb
) < dev
->needed_headroom
) {
394 struct sk_buff
*tmp_skb
= skb
;
396 skb
= skb_realloc_headroom(skb
, dev
->needed_headroom
);
399 vif
->net_stats
.tx_dropped
++;
404 if (ath6kl_wmi_dix_2_dot3(ar
->wmi
, skb
)) {
405 ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
409 if ((dev
->features
& NETIF_F_IP_CSUM
) &&
410 (csum
== CHECKSUM_PARTIAL
)) {
411 meta_v2
.csum_start
= csum_start
;
412 meta_v2
.csum_dest
= csum_dest
;
414 /* instruct target to calculate checksum */
415 meta_v2
.csum_flags
= WMI_META_V2_FLAG_CSUM_OFFLOAD
;
416 meta_ver
= WMI_META_VERSION_2
;
423 ret
= ath6kl_wmi_data_hdr_add(ar
->wmi
, skb
,
424 DATA_MSGTYPE
, flags
, 0,
426 meta
, vif
->fw_vif_idx
);
429 ath6kl_warn("failed to add wmi data header:%d\n"
434 if ((vif
->nw_type
== ADHOC_NETWORK
) &&
435 ar
->ibss_ps_enable
&& test_bit(CONNECTED
, &vif
->flags
))
436 chk_adhoc_ps_mapping
= true;
438 /* get the stream mapping */
439 ret
= ath6kl_wmi_implicit_create_pstream(ar
->wmi
,
440 vif
->fw_vif_idx
, skb
,
441 0, test_bit(WMM_ENABLED
, &vif
->flags
), &ac
);
448 spin_lock_bh(&ar
->lock
);
450 if (chk_adhoc_ps_mapping
)
451 eid
= ath6kl_ibss_map_epid(skb
, dev
, &map_no
);
453 eid
= ar
->ac2ep_map
[ac
];
455 if (eid
== 0 || eid
== ENDPOINT_UNUSED
) {
456 ath6kl_err("eid %d is not mapped!\n", eid
);
457 spin_unlock_bh(&ar
->lock
);
461 /* allocate resource for this packet */
462 cookie
= ath6kl_alloc_cookie(ar
);
465 spin_unlock_bh(&ar
->lock
);
469 /* update counts while the lock is held */
470 ar
->tx_pending
[eid
]++;
471 ar
->total_tx_data_pend
++;
473 spin_unlock_bh(&ar
->lock
);
475 if (!IS_ALIGNED((unsigned long) skb
->data
- HTC_HDR_LENGTH
, 4) &&
478 * We will touch (move the buffer data to align it. Since the
479 * skb buffer is cloned and not only the header is changed, we
480 * have to copy it to allow the changes. Since we are copying
481 * the data here, we may as well align it by reserving suitable
482 * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
484 struct sk_buff
*nskb
;
486 nskb
= skb_copy_expand(skb
, HTC_HDR_LENGTH
, 0, GFP_ATOMIC
);
494 cookie
->map_no
= map_no
;
495 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
497 cookie
->htc_pkt
.skb
= skb
;
499 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "tx ",
500 skb
->data
, skb
->len
);
503 * HTC interface is asynchronous, if this fails, cleanup will
504 * happen in the ath6kl_tx_complete callback.
506 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
513 vif
->net_stats
.tx_dropped
++;
514 vif
->net_stats
.tx_aborted_errors
++;
519 /* indicate tx activity or inactivity on a WMI stream */
520 void ath6kl_indicate_tx_activity(void *devt
, u8 traffic_class
, bool active
)
522 struct ath6kl
*ar
= devt
;
523 enum htc_endpoint_id eid
;
526 eid
= ar
->ac2ep_map
[traffic_class
];
528 if (!test_bit(WMI_ENABLED
, &ar
->flag
))
531 spin_lock_bh(&ar
->lock
);
533 ar
->ac_stream_active
[traffic_class
] = active
;
537 * Keep track of the active stream with the highest
540 if (ar
->ac_stream_pri_map
[traffic_class
] >
541 ar
->hiac_stream_active_pri
)
542 /* set the new highest active priority */
543 ar
->hiac_stream_active_pri
=
544 ar
->ac_stream_pri_map
[traffic_class
];
548 * We may have to search for the next active stream
549 * that is the highest priority.
551 if (ar
->hiac_stream_active_pri
==
552 ar
->ac_stream_pri_map
[traffic_class
]) {
554 * The highest priority stream just went inactive
555 * reset and search for the "next" highest "active"
558 ar
->hiac_stream_active_pri
= 0;
560 for (i
= 0; i
< WMM_NUM_AC
; i
++) {
561 if (ar
->ac_stream_active
[i
] &&
562 (ar
->ac_stream_pri_map
[i
] >
563 ar
->hiac_stream_active_pri
))
565 * Set the new highest active
568 ar
->hiac_stream_active_pri
=
569 ar
->ac_stream_pri_map
[i
];
574 spin_unlock_bh(&ar
->lock
);
577 /* notify HTC, this may cause credit distribution changes */
578 ath6kl_htc_activity_changed(ar
->htc_target
, eid
, active
);
581 enum htc_send_full_action
ath6kl_tx_queue_full(struct htc_target
*target
,
582 struct htc_packet
*packet
)
584 struct ath6kl
*ar
= target
->dev
->ar
;
585 struct ath6kl_vif
*vif
;
586 enum htc_endpoint_id endpoint
= packet
->endpoint
;
587 enum htc_send_full_action action
= HTC_SEND_FULL_KEEP
;
589 if (endpoint
== ar
->ctrl_ep
) {
591 * Under normal WMI if this is getting full, then something
592 * is running rampant the host should not be exhausting the
593 * WMI queue with too many commands the only exception to
594 * this is during testing using endpointping.
596 set_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
597 ath6kl_err("wmi ctrl ep is full\n");
601 if (packet
->info
.tx
.tag
== ATH6KL_CONTROL_PKT_TAG
)
605 * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
606 * the highest active stream.
608 if (ar
->ac_stream_pri_map
[ar
->ep2ac_map
[endpoint
]] <
609 ar
->hiac_stream_active_pri
&&
611 target
->endpoint
[endpoint
].tx_drop_packet_threshold
)
613 * Give preference to the highest priority stream by
614 * dropping the packets which overflowed.
616 action
= HTC_SEND_FULL_DROP
;
619 spin_lock_bh(&ar
->list_lock
);
620 list_for_each_entry(vif
, &ar
->vif_list
, list
) {
621 if (vif
->nw_type
== ADHOC_NETWORK
||
622 action
!= HTC_SEND_FULL_DROP
) {
623 spin_unlock_bh(&ar
->list_lock
);
625 set_bit(NETQ_STOPPED
, &vif
->flags
);
626 netif_stop_queue(vif
->ndev
);
631 spin_unlock_bh(&ar
->list_lock
);
636 /* TODO this needs to be looked at */
637 static void ath6kl_tx_clear_node_map(struct ath6kl_vif
*vif
,
638 enum htc_endpoint_id eid
, u32 map_no
)
640 struct ath6kl
*ar
= vif
->ar
;
643 if (vif
->nw_type
!= ADHOC_NETWORK
)
646 if (!ar
->ibss_ps_enable
)
649 if (eid
== ar
->ctrl_ep
)
656 ar
->node_map
[map_no
].tx_pend
--;
658 if (ar
->node_map
[map_no
].tx_pend
)
661 if (map_no
!= (ar
->node_num
- 1))
664 for (i
= ar
->node_num
; i
> 0; i
--) {
665 if (ar
->node_map
[i
- 1].tx_pend
)
668 memset(&ar
->node_map
[i
- 1], 0,
669 sizeof(struct ath6kl_node_mapping
));
674 void ath6kl_tx_complete(struct htc_target
*target
,
675 struct list_head
*packet_queue
)
677 struct ath6kl
*ar
= target
->dev
->ar
;
678 struct sk_buff_head skb_queue
;
679 struct htc_packet
*packet
;
681 struct ath6kl_cookie
*ath6kl_cookie
;
684 enum htc_endpoint_id eid
;
685 bool wake_event
= false;
686 bool flushing
[ATH6KL_VIF_MAX
] = {false};
688 struct ath6kl_vif
*vif
;
690 skb_queue_head_init(&skb_queue
);
692 /* lock the driver as we update internal state */
693 spin_lock_bh(&ar
->lock
);
695 /* reap completed packets */
696 while (!list_empty(packet_queue
)) {
698 packet
= list_first_entry(packet_queue
, struct htc_packet
,
700 list_del(&packet
->list
);
702 ath6kl_cookie
= (struct ath6kl_cookie
*)packet
->pkt_cntxt
;
706 status
= packet
->status
;
707 skb
= ath6kl_cookie
->skb
;
708 eid
= packet
->endpoint
;
709 map_no
= ath6kl_cookie
->map_no
;
711 if (!skb
|| !skb
->data
)
714 __skb_queue_tail(&skb_queue
, skb
);
716 if (!status
&& (packet
->act_len
!= skb
->len
))
719 ar
->tx_pending
[eid
]--;
721 if (eid
!= ar
->ctrl_ep
)
722 ar
->total_tx_data_pend
--;
724 if (eid
== ar
->ctrl_ep
) {
725 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
))
726 clear_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
728 if (ar
->tx_pending
[eid
] == 0)
732 if (eid
== ar
->ctrl_ep
) {
733 if_idx
= wmi_cmd_hdr_get_if_idx(
734 (struct wmi_cmd_hdr
*) packet
->buf
);
736 if_idx
= wmi_data_hdr_get_if_idx(
737 (struct wmi_data_hdr
*) packet
->buf
);
740 vif
= ath6kl_get_vif_by_index(ar
, if_idx
);
742 ath6kl_free_cookie(ar
, ath6kl_cookie
);
747 if (status
== -ECANCELED
)
748 /* a packet was flushed */
749 flushing
[if_idx
] = true;
751 vif
->net_stats
.tx_errors
++;
753 if (status
!= -ENOSPC
&& status
!= -ECANCELED
)
754 ath6kl_warn("tx complete error: %d\n", status
);
756 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
757 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
758 __func__
, skb
, packet
->buf
, packet
->act_len
,
761 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
762 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
763 __func__
, skb
, packet
->buf
, packet
->act_len
,
766 flushing
[if_idx
] = false;
767 vif
->net_stats
.tx_packets
++;
768 vif
->net_stats
.tx_bytes
+= skb
->len
;
771 ath6kl_tx_clear_node_map(vif
, eid
, map_no
);
773 ath6kl_free_cookie(ar
, ath6kl_cookie
);
775 if (test_bit(NETQ_STOPPED
, &vif
->flags
))
776 clear_bit(NETQ_STOPPED
, &vif
->flags
);
779 spin_unlock_bh(&ar
->lock
);
781 __skb_queue_purge(&skb_queue
);
784 spin_lock_bh(&ar
->list_lock
);
785 list_for_each_entry(vif
, &ar
->vif_list
, list
) {
786 if (test_bit(CONNECTED
, &vif
->flags
) &&
787 !flushing
[vif
->fw_vif_idx
]) {
788 spin_unlock_bh(&ar
->list_lock
);
789 netif_wake_queue(vif
->ndev
);
790 spin_lock_bh(&ar
->list_lock
);
793 spin_unlock_bh(&ar
->list_lock
);
796 wake_up(&ar
->event_wq
);
802 spin_unlock_bh(&ar
->lock
);
806 void ath6kl_tx_data_cleanup(struct ath6kl
*ar
)
810 /* flush all the data (non-control) streams */
811 for (i
= 0; i
< WMM_NUM_AC
; i
++)
812 ath6kl_htc_flush_txep(ar
->htc_target
, ar
->ac2ep_map
[i
],
813 ATH6KL_DATA_PKT_TAG
);
818 static void ath6kl_deliver_frames_to_nw_stack(struct net_device
*dev
,
826 if (!(skb
->dev
->flags
& IFF_UP
)) {
831 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
836 static void ath6kl_alloc_netbufs(struct sk_buff_head
*q
, u16 num
)
841 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
843 ath6kl_err("netbuf allocation failed\n");
846 skb_queue_tail(q
, skb
);
851 static struct sk_buff
*aggr_get_free_skb(struct aggr_info
*p_aggr
)
853 struct sk_buff
*skb
= NULL
;
855 if (skb_queue_len(&p_aggr
->rx_amsdu_freeq
) <
856 (AGGR_NUM_OF_FREE_NETBUFS
>> 2))
857 ath6kl_alloc_netbufs(&p_aggr
->rx_amsdu_freeq
,
858 AGGR_NUM_OF_FREE_NETBUFS
);
860 skb
= skb_dequeue(&p_aggr
->rx_amsdu_freeq
);
865 void ath6kl_rx_refill(struct htc_target
*target
, enum htc_endpoint_id endpoint
)
867 struct ath6kl
*ar
= target
->dev
->ar
;
871 struct htc_packet
*packet
;
872 struct list_head queue
;
874 n_buf_refill
= ATH6KL_MAX_RX_BUFFERS
-
875 ath6kl_htc_get_rxbuf_num(ar
->htc_target
, endpoint
);
877 if (n_buf_refill
<= 0)
880 INIT_LIST_HEAD(&queue
);
882 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
883 "%s: providing htc with %d buffers at eid=%d\n",
884 __func__
, n_buf_refill
, endpoint
);
886 for (rx_buf
= 0; rx_buf
< n_buf_refill
; rx_buf
++) {
887 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
891 packet
= (struct htc_packet
*) skb
->head
;
892 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
893 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
894 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
895 ATH6KL_BUFFER_SIZE
, endpoint
);
897 list_add_tail(&packet
->list
, &queue
);
900 if (!list_empty(&queue
))
901 ath6kl_htc_add_rxbuf_multiple(ar
->htc_target
, &queue
);
904 void ath6kl_refill_amsdu_rxbufs(struct ath6kl
*ar
, int count
)
906 struct htc_packet
*packet
;
910 skb
= ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE
);
914 packet
= (struct htc_packet
*) skb
->head
;
915 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
916 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
917 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
918 ATH6KL_AMSDU_BUFFER_SIZE
, 0);
921 spin_lock_bh(&ar
->lock
);
922 list_add_tail(&packet
->list
, &ar
->amsdu_rx_buffer_queue
);
923 spin_unlock_bh(&ar
->lock
);
929 * Callback to allocate a receive buffer for a pending packet. We use a
930 * pre-allocated list of buffers of maximum AMSDU size (4K).
932 struct htc_packet
*ath6kl_alloc_amsdu_rxbuf(struct htc_target
*target
,
933 enum htc_endpoint_id endpoint
,
936 struct ath6kl
*ar
= target
->dev
->ar
;
937 struct htc_packet
*packet
= NULL
;
938 struct list_head
*pkt_pos
;
939 int refill_cnt
= 0, depth
= 0;
941 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: eid=%d, len:%d\n",
942 __func__
, endpoint
, len
);
944 if ((len
<= ATH6KL_BUFFER_SIZE
) ||
945 (len
> ATH6KL_AMSDU_BUFFER_SIZE
))
948 spin_lock_bh(&ar
->lock
);
950 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
951 spin_unlock_bh(&ar
->lock
);
952 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
;
956 packet
= list_first_entry(&ar
->amsdu_rx_buffer_queue
,
957 struct htc_packet
, list
);
958 list_del(&packet
->list
);
959 list_for_each(pkt_pos
, &ar
->amsdu_rx_buffer_queue
)
962 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
- depth
;
963 spin_unlock_bh(&ar
->lock
);
965 /* set actual endpoint ID */
966 packet
->endpoint
= endpoint
;
969 if (refill_cnt
>= ATH6KL_AMSDU_REFILL_THRESHOLD
)
970 ath6kl_refill_amsdu_rxbufs(ar
, refill_cnt
);
975 static void aggr_slice_amsdu(struct aggr_info
*p_aggr
,
976 struct rxtid
*rxtid
, struct sk_buff
*skb
)
978 struct sk_buff
*new_skb
;
980 u16 frame_8023_len
, payload_8023_len
, mac_hdr_len
, amsdu_len
;
983 mac_hdr_len
= sizeof(struct ethhdr
);
984 framep
= skb
->data
+ mac_hdr_len
;
985 amsdu_len
= skb
->len
- mac_hdr_len
;
987 while (amsdu_len
> mac_hdr_len
) {
988 hdr
= (struct ethhdr
*) framep
;
989 payload_8023_len
= ntohs(hdr
->h_proto
);
991 if (payload_8023_len
< MIN_MSDU_SUBFRAME_PAYLOAD_LEN
||
992 payload_8023_len
> MAX_MSDU_SUBFRAME_PAYLOAD_LEN
) {
993 ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
998 frame_8023_len
= payload_8023_len
+ mac_hdr_len
;
999 new_skb
= aggr_get_free_skb(p_aggr
);
1001 ath6kl_err("no buffer available\n");
1005 memcpy(new_skb
->data
, framep
, frame_8023_len
);
1006 skb_put(new_skb
, frame_8023_len
);
1007 if (ath6kl_wmi_dot3_2_dix(new_skb
)) {
1008 ath6kl_err("dot3_2_dix error\n");
1009 dev_kfree_skb(new_skb
);
1013 skb_queue_tail(&rxtid
->q
, new_skb
);
1015 /* Is this the last subframe within this aggregate ? */
1016 if ((amsdu_len
- frame_8023_len
) == 0)
1019 /* Add the length of A-MSDU subframe padding bytes -
1020 * Round to nearest word.
1022 frame_8023_len
= ALIGN(frame_8023_len
, 4);
1024 framep
+= frame_8023_len
;
1025 amsdu_len
-= frame_8023_len
;
1031 static void aggr_deque_frms(struct aggr_info_conn
*agg_conn
, u8 tid
,
1032 u16 seq_no
, u8 order
)
1034 struct sk_buff
*skb
;
1035 struct rxtid
*rxtid
;
1036 struct skb_hold_q
*node
;
1037 u16 idx
, idx_end
, seq_end
;
1038 struct rxtid_stats
*stats
;
1040 rxtid
= &agg_conn
->rx_tid
[tid
];
1041 stats
= &agg_conn
->stat
[tid
];
1043 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
1046 * idx_end is typically the last possible frame in the window,
1047 * but changes to 'the' seq_no, when BAR comes. If seq_no
1048 * is non-zero, we will go up to that and stop.
1049 * Note: last seq no in current window will occupy the same
1050 * index position as index that is just previous to start.
1051 * An imp point : if win_sz is 7, for seq_no space of 4095,
1052 * then, there would be holes when sequence wrap around occurs.
1053 * Target should judiciously choose the win_sz, based on
1054 * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
1055 * 2, 4, 8, 16 win_sz works fine).
1056 * We must deque from "idx" to "idx_end", including both.
1058 seq_end
= seq_no
? seq_no
: rxtid
->seq_next
;
1059 idx_end
= AGGR_WIN_IDX(seq_end
, rxtid
->hold_q_sz
);
1061 spin_lock_bh(&rxtid
->lock
);
1064 node
= &rxtid
->hold_q
[idx
];
1065 if ((order
== 1) && (!node
->skb
))
1070 aggr_slice_amsdu(agg_conn
->aggr_info
, rxtid
,
1073 skb_queue_tail(&rxtid
->q
, node
->skb
);
1078 rxtid
->seq_next
= ATH6KL_NEXT_SEQ_NO(rxtid
->seq_next
);
1079 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
1080 } while (idx
!= idx_end
);
1082 spin_unlock_bh(&rxtid
->lock
);
1084 stats
->num_delivered
+= skb_queue_len(&rxtid
->q
);
1086 while ((skb
= skb_dequeue(&rxtid
->q
)))
1087 ath6kl_deliver_frames_to_nw_stack(agg_conn
->dev
, skb
);
1090 static bool aggr_process_recv_frm(struct aggr_info_conn
*agg_conn
, u8 tid
,
1092 bool is_amsdu
, struct sk_buff
*frame
)
1094 struct rxtid
*rxtid
;
1095 struct rxtid_stats
*stats
;
1096 struct sk_buff
*skb
;
1097 struct skb_hold_q
*node
;
1098 u16 idx
, st
, cur
, end
;
1099 bool is_queued
= false;
1102 rxtid
= &agg_conn
->rx_tid
[tid
];
1103 stats
= &agg_conn
->stat
[tid
];
1105 stats
->num_into_aggr
++;
1109 aggr_slice_amsdu(agg_conn
->aggr_info
, rxtid
, frame
);
1112 while ((skb
= skb_dequeue(&rxtid
->q
)))
1113 ath6kl_deliver_frames_to_nw_stack(agg_conn
->dev
,
1119 /* Check the incoming sequence no, if it's in the window */
1120 st
= rxtid
->seq_next
;
1122 end
= (st
+ rxtid
->hold_q_sz
-1) & ATH6KL_MAX_SEQ_NO
;
1124 if (((st
< end
) && (cur
< st
|| cur
> end
)) ||
1125 ((st
> end
) && (cur
> end
) && (cur
< st
))) {
1126 extended_end
= (end
+ rxtid
->hold_q_sz
- 1) &
1129 if (((end
< extended_end
) &&
1130 (cur
< end
|| cur
> extended_end
)) ||
1131 ((end
> extended_end
) && (cur
> extended_end
) &&
1133 aggr_deque_frms(agg_conn
, tid
, 0, 0);
1134 if (cur
>= rxtid
->hold_q_sz
- 1)
1135 rxtid
->seq_next
= cur
- (rxtid
->hold_q_sz
- 1);
1137 rxtid
->seq_next
= ATH6KL_MAX_SEQ_NO
-
1138 (rxtid
->hold_q_sz
- 2 - cur
);
1141 * Dequeue only those frames that are outside the
1142 * new shifted window.
1144 if (cur
>= rxtid
->hold_q_sz
- 1)
1145 st
= cur
- (rxtid
->hold_q_sz
- 1);
1147 st
= ATH6KL_MAX_SEQ_NO
-
1148 (rxtid
->hold_q_sz
- 2 - cur
);
1150 aggr_deque_frms(agg_conn
, tid
, st
, 0);
1156 idx
= AGGR_WIN_IDX(seq_no
, rxtid
->hold_q_sz
);
1158 node
= &rxtid
->hold_q
[idx
];
1160 spin_lock_bh(&rxtid
->lock
);
1163 * Is the cur frame duplicate or something beyond our window(hold_q
1164 * -> which is 2x, already)?
1166 * 1. Duplicate is easy - drop incoming frame.
1167 * 2. Not falling in current sliding window.
1168 * 2a. is the frame_seq_no preceding current tid_seq_no?
1169 * -> drop the frame. perhaps sender did not get our ACK.
1170 * this is taken care of above.
1171 * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
1172 * -> Taken care of it above, by moving window forward.
1174 dev_kfree_skb(node
->skb
);
1179 node
->is_amsdu
= is_amsdu
;
1180 node
->seq_no
= seq_no
;
1187 spin_unlock_bh(&rxtid
->lock
);
1189 aggr_deque_frms(agg_conn
, tid
, 0, 1);
1191 if (agg_conn
->timer_scheduled
)
1192 rxtid
->progress
= true;
1194 for (idx
= 0 ; idx
< rxtid
->hold_q_sz
; idx
++) {
1195 if (rxtid
->hold_q
[idx
].skb
) {
1197 * There is a frame in the queue and no
1198 * timer so start a timer to ensure that
1199 * the frame doesn't remain stuck
1202 agg_conn
->timer_scheduled
= true;
1203 mod_timer(&agg_conn
->timer
,
1205 HZ
* (AGGR_RX_TIMEOUT
) / 1000));
1206 rxtid
->progress
= false;
1207 rxtid
->timer_mon
= true;
1215 static void ath6kl_uapsd_trigger_frame_rx(struct ath6kl_vif
*vif
,
1216 struct ath6kl_sta
*conn
)
1218 struct ath6kl
*ar
= vif
->ar
;
1219 bool is_apsdq_empty
, is_apsdq_empty_at_start
;
1220 u32 num_frames_to_deliver
, flags
;
1221 struct sk_buff
*skb
= NULL
;
1224 * If the APSD q for this STA is not empty, dequeue and
1225 * send a pkt from the head of the q. Also update the
1226 * More data bit in the WMI_DATA_HDR if there are
1227 * more pkts for this STA in the APSD q.
1228 * If there are no more pkts for this STA,
1229 * update the APSD bitmap for this STA.
1232 num_frames_to_deliver
= (conn
->apsd_info
>> ATH6KL_APSD_NUM_OF_AC
) &
1233 ATH6KL_APSD_FRAME_MASK
;
1235 * Number of frames to send in a service period is
1236 * indicated by the station
1237 * in the QOS_INFO of the association request
1238 * If it is zero, send all frames
1240 if (!num_frames_to_deliver
)
1241 num_frames_to_deliver
= ATH6KL_APSD_ALL_FRAME
;
1243 spin_lock_bh(&conn
->psq_lock
);
1244 is_apsdq_empty
= skb_queue_empty(&conn
->apsdq
);
1245 spin_unlock_bh(&conn
->psq_lock
);
1246 is_apsdq_empty_at_start
= is_apsdq_empty
;
1248 while ((!is_apsdq_empty
) && (num_frames_to_deliver
)) {
1250 spin_lock_bh(&conn
->psq_lock
);
1251 skb
= skb_dequeue(&conn
->apsdq
);
1252 is_apsdq_empty
= skb_queue_empty(&conn
->apsdq
);
1253 spin_unlock_bh(&conn
->psq_lock
);
1256 * Set the STA flag to Trigger delivery,
1257 * so that the frame will go out
1259 conn
->sta_flags
|= STA_PS_APSD_TRIGGER
;
1260 num_frames_to_deliver
--;
1262 /* Last frame in the service period, set EOSP or queue empty */
1263 if ((is_apsdq_empty
) || (!num_frames_to_deliver
))
1264 conn
->sta_flags
|= STA_PS_APSD_EOSP
;
1266 ath6kl_data_tx(skb
, vif
->ndev
);
1267 conn
->sta_flags
&= ~(STA_PS_APSD_TRIGGER
);
1268 conn
->sta_flags
&= ~(STA_PS_APSD_EOSP
);
1271 if (is_apsdq_empty
) {
1272 if (is_apsdq_empty_at_start
)
1273 flags
= WMI_AP_APSD_NO_DELIVERY_FRAMES
;
1277 ath6kl_wmi_set_apsd_bfrd_traf(ar
->wmi
,
1279 conn
->aid
, 0, flags
);
1285 void ath6kl_rx(struct htc_target
*target
, struct htc_packet
*packet
)
1287 struct ath6kl
*ar
= target
->dev
->ar
;
1288 struct sk_buff
*skb
= packet
->pkt_cntxt
;
1289 struct wmi_rx_meta_v2
*meta
;
1290 struct wmi_data_hdr
*dhdr
;
1292 u8 meta_type
, dot11_hdr
= 0;
1293 u8 pad_before_data_start
;
1294 int status
= packet
->status
;
1295 enum htc_endpoint_id ept
= packet
->endpoint
;
1296 bool is_amsdu
, prev_ps
, ps_state
= false;
1297 bool trig_state
= false;
1298 struct ath6kl_sta
*conn
= NULL
;
1299 struct sk_buff
*skb1
= NULL
;
1300 struct ethhdr
*datap
= NULL
;
1301 struct ath6kl_vif
*vif
;
1302 struct aggr_info_conn
*aggr_conn
;
1306 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
1307 "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
1308 __func__
, ar
, ept
, skb
, packet
->buf
,
1309 packet
->act_len
, status
);
1311 if (status
|| !(skb
->data
+ HTC_HDR_LENGTH
)) {
1316 skb_put(skb
, packet
->act_len
+ HTC_HDR_LENGTH
);
1317 skb_pull(skb
, HTC_HDR_LENGTH
);
1319 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "rx ",
1320 skb
->data
, skb
->len
);
1322 if (ept
== ar
->ctrl_ep
) {
1323 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
1324 ath6kl_check_wow_status(ar
);
1325 ath6kl_wmi_control_rx(ar
->wmi
, skb
);
1329 wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr
*) skb
->data
);
1332 wmi_data_hdr_get_if_idx((struct wmi_data_hdr
*) skb
->data
);
1335 vif
= ath6kl_get_vif_by_index(ar
, if_idx
);
1342 * Take lock to protect buffer counts and adaptive power throughput
1345 spin_lock_bh(&vif
->if_lock
);
1347 vif
->net_stats
.rx_packets
++;
1348 vif
->net_stats
.rx_bytes
+= packet
->act_len
;
1350 spin_unlock_bh(&vif
->if_lock
);
1352 skb
->dev
= vif
->ndev
;
1354 if (!test_bit(WMI_ENABLED
, &ar
->flag
)) {
1355 if (EPPING_ALIGNMENT_PAD
> 0)
1356 skb_pull(skb
, EPPING_ALIGNMENT_PAD
);
1357 ath6kl_deliver_frames_to_nw_stack(vif
->ndev
, skb
);
1361 ath6kl_check_wow_status(ar
);
1363 min_hdr_len
= sizeof(struct ethhdr
) + sizeof(struct wmi_data_hdr
) +
1364 sizeof(struct ath6kl_llc_snap_hdr
);
1366 dhdr
= (struct wmi_data_hdr
*) skb
->data
;
1369 * In the case of AP mode we may receive NULL data frames
1370 * that do not have LLC hdr. They are 16 bytes in size.
1371 * Allow these frames in the AP mode.
1373 if (vif
->nw_type
!= AP_NETWORK
&&
1374 ((packet
->act_len
< min_hdr_len
) ||
1375 (packet
->act_len
> WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
))) {
1376 ath6kl_info("frame len is too short or too long\n");
1377 vif
->net_stats
.rx_errors
++;
1378 vif
->net_stats
.rx_length_errors
++;
1383 /* Get the Power save state of the STA */
1384 if (vif
->nw_type
== AP_NETWORK
) {
1385 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1387 ps_state
= !!((dhdr
->info
>> WMI_DATA_HDR_PS_SHIFT
) &
1388 WMI_DATA_HDR_PS_MASK
);
1390 offset
= sizeof(struct wmi_data_hdr
);
1391 trig_state
= !!(le16_to_cpu(dhdr
->info3
) & WMI_DATA_HDR_TRIG
);
1393 switch (meta_type
) {
1396 case WMI_META_VERSION_1
:
1397 offset
+= sizeof(struct wmi_rx_meta_v1
);
1399 case WMI_META_VERSION_2
:
1400 offset
+= sizeof(struct wmi_rx_meta_v2
);
1406 datap
= (struct ethhdr
*) (skb
->data
+ offset
);
1407 conn
= ath6kl_find_sta(vif
, datap
->h_source
);
1415 * If there is a change in PS state of the STA,
1416 * take appropriate steps:
1418 * 1. If Sleep-->Awake, flush the psq for the STA
1419 * Clear the PVB for the STA.
1420 * 2. If Awake-->Sleep, Starting queueing frames
1423 prev_ps
= !!(conn
->sta_flags
& STA_PS_SLEEP
);
1426 conn
->sta_flags
|= STA_PS_SLEEP
;
1428 conn
->sta_flags
&= ~STA_PS_SLEEP
;
1430 /* Accept trigger only when the station is in sleep */
1431 if ((conn
->sta_flags
& STA_PS_SLEEP
) && trig_state
)
1432 ath6kl_uapsd_trigger_frame_rx(vif
, conn
);
1434 if (prev_ps
^ !!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1435 if (!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1436 struct sk_buff
*skbuff
= NULL
;
1437 bool is_apsdq_empty
;
1438 struct ath6kl_mgmt_buff
*mgmt
;
1441 spin_lock_bh(&conn
->psq_lock
);
1442 while (conn
->mgmt_psq_len
> 0) {
1443 mgmt
= list_first_entry(
1445 struct ath6kl_mgmt_buff
,
1447 list_del(&mgmt
->list
);
1448 conn
->mgmt_psq_len
--;
1449 spin_unlock_bh(&conn
->psq_lock
);
1450 idx
= vif
->fw_vif_idx
;
1452 ath6kl_wmi_send_mgmt_cmd(ar
->wmi
,
1462 spin_lock_bh(&conn
->psq_lock
);
1464 conn
->mgmt_psq_len
= 0;
1465 while ((skbuff
= skb_dequeue(&conn
->psq
))) {
1466 spin_unlock_bh(&conn
->psq_lock
);
1467 ath6kl_data_tx(skbuff
, vif
->ndev
);
1468 spin_lock_bh(&conn
->psq_lock
);
1471 is_apsdq_empty
= skb_queue_empty(&conn
->apsdq
);
1472 while ((skbuff
= skb_dequeue(&conn
->apsdq
))) {
1473 spin_unlock_bh(&conn
->psq_lock
);
1474 ath6kl_data_tx(skbuff
, vif
->ndev
);
1475 spin_lock_bh(&conn
->psq_lock
);
1477 spin_unlock_bh(&conn
->psq_lock
);
1479 if (!is_apsdq_empty
)
1480 ath6kl_wmi_set_apsd_bfrd_traf(
1485 /* Clear the PVB for this STA */
1486 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
,
1491 /* drop NULL data frames here */
1492 if ((packet
->act_len
< min_hdr_len
) ||
1494 WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
)) {
1500 is_amsdu
= wmi_data_hdr_is_amsdu(dhdr
) ? true : false;
1501 tid
= wmi_data_hdr_get_up(dhdr
);
1502 seq_no
= wmi_data_hdr_get_seqno(dhdr
);
1503 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1504 dot11_hdr
= wmi_data_hdr_get_dot11(dhdr
);
1505 pad_before_data_start
=
1506 (le16_to_cpu(dhdr
->info3
) >> WMI_DATA_HDR_PAD_BEFORE_DATA_SHIFT
)
1507 & WMI_DATA_HDR_PAD_BEFORE_DATA_MASK
;
1509 skb_pull(skb
, sizeof(struct wmi_data_hdr
));
1511 switch (meta_type
) {
1512 case WMI_META_VERSION_1
:
1513 skb_pull(skb
, sizeof(struct wmi_rx_meta_v1
));
1515 case WMI_META_VERSION_2
:
1516 meta
= (struct wmi_rx_meta_v2
*) skb
->data
;
1517 if (meta
->csum_flags
& 0x1) {
1518 skb
->ip_summed
= CHECKSUM_COMPLETE
;
1519 skb
->csum
= (__force __wsum
) meta
->csum
;
1521 skb_pull(skb
, sizeof(struct wmi_rx_meta_v2
));
1527 skb_pull(skb
, pad_before_data_start
);
1530 status
= ath6kl_wmi_dot11_hdr_remove(ar
->wmi
, skb
);
1532 status
= ath6kl_wmi_dot3_2_dix(skb
);
1536 * Drop frames that could not be processed (lack of
1543 if (!(vif
->ndev
->flags
& IFF_UP
)) {
1548 if (vif
->nw_type
== AP_NETWORK
) {
1549 datap
= (struct ethhdr
*) skb
->data
;
1550 if (is_multicast_ether_addr(datap
->h_dest
))
1552 * Bcast/Mcast frames should be sent to the
1553 * OS stack as well as on the air.
1555 skb1
= skb_copy(skb
, GFP_ATOMIC
);
1558 * Search for a connected STA with dstMac
1559 * as the Mac address. If found send the
1560 * frame to it on the air else send the
1561 * frame up the stack.
1563 conn
= ath6kl_find_sta(vif
, datap
->h_dest
);
1565 if (conn
&& ar
->intra_bss
) {
1568 } else if (conn
&& !ar
->intra_bss
) {
1574 ath6kl_data_tx(skb1
, vif
->ndev
);
1577 /* nothing to deliver up the stack */
1582 datap
= (struct ethhdr
*) skb
->data
;
1584 if (is_unicast_ether_addr(datap
->h_dest
)) {
1585 if (vif
->nw_type
== AP_NETWORK
) {
1586 conn
= ath6kl_find_sta(vif
, datap
->h_source
);
1589 aggr_conn
= conn
->aggr_conn
;
1591 aggr_conn
= vif
->aggr_cntxt
->aggr_conn
;
1593 if (aggr_process_recv_frm(aggr_conn
, tid
, seq_no
,
1595 /* aggregation code will handle the skb */
1598 } else if (!is_broadcast_ether_addr(datap
->h_dest
))
1599 vif
->net_stats
.multicast
++;
1601 ath6kl_deliver_frames_to_nw_stack(vif
->ndev
, skb
);
1604 static void aggr_timeout(unsigned long arg
)
1607 struct aggr_info_conn
*aggr_conn
= (struct aggr_info_conn
*) arg
;
1608 struct rxtid
*rxtid
;
1609 struct rxtid_stats
*stats
;
1611 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1612 rxtid
= &aggr_conn
->rx_tid
[i
];
1613 stats
= &aggr_conn
->stat
[i
];
1615 if (!rxtid
->aggr
|| !rxtid
->timer_mon
|| rxtid
->progress
)
1618 stats
->num_timeouts
++;
1619 ath6kl_dbg(ATH6KL_DBG_AGGR
,
1620 "aggr timeout (st %d end %d)\n",
1622 ((rxtid
->seq_next
+ rxtid
->hold_q_sz
-1) &
1623 ATH6KL_MAX_SEQ_NO
));
1624 aggr_deque_frms(aggr_conn
, i
, 0, 0);
1627 aggr_conn
->timer_scheduled
= false;
1629 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1630 rxtid
= &aggr_conn
->rx_tid
[i
];
1632 if (rxtid
->aggr
&& rxtid
->hold_q
) {
1633 for (j
= 0; j
< rxtid
->hold_q_sz
; j
++) {
1634 if (rxtid
->hold_q
[j
].skb
) {
1635 aggr_conn
->timer_scheduled
= true;
1636 rxtid
->timer_mon
= true;
1637 rxtid
->progress
= false;
1642 if (j
>= rxtid
->hold_q_sz
)
1643 rxtid
->timer_mon
= false;
1647 if (aggr_conn
->timer_scheduled
)
1648 mod_timer(&aggr_conn
->timer
,
1649 jiffies
+ msecs_to_jiffies(AGGR_RX_TIMEOUT
));
1652 static void aggr_delete_tid_state(struct aggr_info_conn
*aggr_conn
, u8 tid
)
1654 struct rxtid
*rxtid
;
1655 struct rxtid_stats
*stats
;
1657 if (!aggr_conn
|| tid
>= NUM_OF_TIDS
)
1660 rxtid
= &aggr_conn
->rx_tid
[tid
];
1661 stats
= &aggr_conn
->stat
[tid
];
1664 aggr_deque_frms(aggr_conn
, tid
, 0, 0);
1666 rxtid
->aggr
= false;
1667 rxtid
->progress
= false;
1668 rxtid
->timer_mon
= false;
1670 rxtid
->seq_next
= 0;
1671 rxtid
->hold_q_sz
= 0;
1673 kfree(rxtid
->hold_q
);
1674 rxtid
->hold_q
= NULL
;
1676 memset(stats
, 0, sizeof(struct rxtid_stats
));
1679 void aggr_recv_addba_req_evt(struct ath6kl_vif
*vif
, u8 tid_mux
, u16 seq_no
,
1682 struct ath6kl_sta
*sta
;
1683 struct aggr_info_conn
*aggr_conn
= NULL
;
1684 struct rxtid
*rxtid
;
1685 struct rxtid_stats
*stats
;
1689 if (vif
->nw_type
== AP_NETWORK
) {
1690 aid
= ath6kl_get_aid(tid_mux
);
1691 sta
= ath6kl_find_sta_by_aid(vif
->ar
, aid
);
1693 aggr_conn
= sta
->aggr_conn
;
1695 aggr_conn
= vif
->aggr_cntxt
->aggr_conn
;
1700 tid
= ath6kl_get_tid(tid_mux
);
1701 if (tid
>= NUM_OF_TIDS
)
1704 rxtid
= &aggr_conn
->rx_tid
[tid
];
1705 stats
= &aggr_conn
->stat
[tid
];
1707 if (win_sz
< AGGR_WIN_SZ_MIN
|| win_sz
> AGGR_WIN_SZ_MAX
)
1708 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: win_sz %d, tid %d\n",
1709 __func__
, win_sz
, tid
);
1712 aggr_delete_tid_state(aggr_conn
, tid
);
1714 rxtid
->seq_next
= seq_no
;
1715 hold_q_size
= TID_WINDOW_SZ(win_sz
) * sizeof(struct skb_hold_q
);
1716 rxtid
->hold_q
= kzalloc(hold_q_size
, GFP_KERNEL
);
1720 rxtid
->win_sz
= win_sz
;
1721 rxtid
->hold_q_sz
= TID_WINDOW_SZ(win_sz
);
1722 if (!skb_queue_empty(&rxtid
->q
))
1728 void aggr_conn_init(struct ath6kl_vif
*vif
, struct aggr_info
*aggr_info
,
1729 struct aggr_info_conn
*aggr_conn
)
1731 struct rxtid
*rxtid
;
1734 aggr_conn
->aggr_sz
= AGGR_SZ_DEFAULT
;
1735 aggr_conn
->dev
= vif
->ndev
;
1736 init_timer(&aggr_conn
->timer
);
1737 aggr_conn
->timer
.function
= aggr_timeout
;
1738 aggr_conn
->timer
.data
= (unsigned long) aggr_conn
;
1739 aggr_conn
->aggr_info
= aggr_info
;
1741 aggr_conn
->timer_scheduled
= false;
1743 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1744 rxtid
= &aggr_conn
->rx_tid
[i
];
1745 rxtid
->aggr
= false;
1746 rxtid
->progress
= false;
1747 rxtid
->timer_mon
= false;
1748 skb_queue_head_init(&rxtid
->q
);
1749 spin_lock_init(&rxtid
->lock
);
1754 struct aggr_info
*aggr_init(struct ath6kl_vif
*vif
)
1756 struct aggr_info
*p_aggr
= NULL
;
1758 p_aggr
= kzalloc(sizeof(struct aggr_info
), GFP_KERNEL
);
1760 ath6kl_err("failed to alloc memory for aggr_node\n");
1764 p_aggr
->aggr_conn
= kzalloc(sizeof(struct aggr_info_conn
), GFP_KERNEL
);
1765 if (!p_aggr
->aggr_conn
) {
1766 ath6kl_err("failed to alloc memory for connection specific aggr info\n");
1771 aggr_conn_init(vif
, p_aggr
, p_aggr
->aggr_conn
);
1773 skb_queue_head_init(&p_aggr
->rx_amsdu_freeq
);
1774 ath6kl_alloc_netbufs(&p_aggr
->rx_amsdu_freeq
, AGGR_NUM_OF_FREE_NETBUFS
);
1779 void aggr_recv_delba_req_evt(struct ath6kl_vif
*vif
, u8 tid_mux
)
1781 struct ath6kl_sta
*sta
;
1782 struct rxtid
*rxtid
;
1783 struct aggr_info_conn
*aggr_conn
= NULL
;
1786 if (vif
->nw_type
== AP_NETWORK
) {
1787 aid
= ath6kl_get_aid(tid_mux
);
1788 sta
= ath6kl_find_sta_by_aid(vif
->ar
, aid
);
1790 aggr_conn
= sta
->aggr_conn
;
1792 aggr_conn
= vif
->aggr_cntxt
->aggr_conn
;
1797 tid
= ath6kl_get_tid(tid_mux
);
1798 if (tid
>= NUM_OF_TIDS
)
1801 rxtid
= &aggr_conn
->rx_tid
[tid
];
1804 aggr_delete_tid_state(aggr_conn
, tid
);
1807 void aggr_reset_state(struct aggr_info_conn
*aggr_conn
)
1814 if (aggr_conn
->timer_scheduled
) {
1815 del_timer(&aggr_conn
->timer
);
1816 aggr_conn
->timer_scheduled
= false;
1819 for (tid
= 0; tid
< NUM_OF_TIDS
; tid
++)
1820 aggr_delete_tid_state(aggr_conn
, tid
);
1823 /* clean up our amsdu buffer list */
1824 void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl
*ar
)
1826 struct htc_packet
*packet
, *tmp_pkt
;
1828 spin_lock_bh(&ar
->lock
);
1829 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
1830 spin_unlock_bh(&ar
->lock
);
1834 list_for_each_entry_safe(packet
, tmp_pkt
, &ar
->amsdu_rx_buffer_queue
,
1836 list_del(&packet
->list
);
1837 spin_unlock_bh(&ar
->lock
);
1838 dev_kfree_skb(packet
->pkt_cntxt
);
1839 spin_lock_bh(&ar
->lock
);
1842 spin_unlock_bh(&ar
->lock
);
1845 void aggr_module_destroy(struct aggr_info
*aggr_info
)
1850 aggr_reset_state(aggr_info
->aggr_conn
);
1851 skb_queue_purge(&aggr_info
->rx_amsdu_freeq
);
1852 kfree(aggr_info
->aggr_conn
);