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
*ar
, 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 /* TODO: Findout vif */
87 struct ath6kl_vif
*vif
= ar
->vif
;
89 if (is_multicast_ether_addr(datap
->h_dest
)) {
93 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
94 if (ar
->sta_list
[ctr
].sta_flags
& STA_PS_SLEEP
) {
102 * If this transmit is not because of a Dtim Expiry
105 if (!test_bit(DTIM_EXPIRED
, &vif
->flags
)) {
106 bool is_mcastq_empty
= false;
108 spin_lock_bh(&ar
->mcastpsq_lock
);
110 skb_queue_empty(&ar
->mcastpsq
);
111 skb_queue_tail(&ar
->mcastpsq
, skb
);
112 spin_unlock_bh(&ar
->mcastpsq_lock
);
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.
120 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
127 * This transmit is because of Dtim expiry.
128 * Determine if MoreData bit has to be set.
130 spin_lock_bh(&ar
->mcastpsq_lock
);
131 if (!skb_queue_empty(&ar
->mcastpsq
))
133 spin_unlock_bh(&ar
->mcastpsq_lock
);
137 conn
= ath6kl_find_sta(ar
, datap
->h_dest
);
141 /* Inform the caller that the skb is consumed */
145 if (conn
->sta_flags
& STA_PS_SLEEP
) {
146 if (!(conn
->sta_flags
& STA_PS_POLLED
)) {
147 /* Queue the frames if the STA is sleeping */
148 spin_lock_bh(&conn
->psq_lock
);
149 is_psq_empty
= skb_queue_empty(&conn
->psq
);
150 skb_queue_tail(&conn
->psq
, skb
);
151 spin_unlock_bh(&conn
->psq_lock
);
154 * If this is the first pkt getting queued
155 * for this STA, update the PVB for this
159 ath6kl_wmi_set_pvb_cmd(ar
->wmi
,
166 * This tx is because of a PsPoll.
167 * Determine if MoreData bit has to be set.
169 spin_lock_bh(&conn
->psq_lock
);
170 if (!skb_queue_empty(&conn
->psq
))
172 spin_unlock_bh(&conn
->psq_lock
);
182 int ath6kl_control_tx(void *devt
, struct sk_buff
*skb
,
183 enum htc_endpoint_id eid
)
185 struct ath6kl
*ar
= devt
;
187 struct ath6kl_cookie
*cookie
= NULL
;
189 spin_lock_bh(&ar
->lock
);
191 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
192 "%s: skb=0x%p, len=0x%x eid =%d\n", __func__
,
195 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
) && (eid
== ar
->ctrl_ep
)) {
197 * Control endpoint is full, don't allocate resources, we
198 * are just going to drop this packet.
201 ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
204 cookie
= ath6kl_alloc_cookie(ar
);
206 if (cookie
== NULL
) {
207 spin_unlock_bh(&ar
->lock
);
212 ar
->tx_pending
[eid
]++;
214 if (eid
!= ar
->ctrl_ep
)
215 ar
->total_tx_data_pend
++;
217 spin_unlock_bh(&ar
->lock
);
221 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
222 eid
, ATH6KL_CONTROL_PKT_TAG
);
225 * This interface is asynchronous, if there is an error, cleanup
226 * will happen in the TX completion callback.
228 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
237 int ath6kl_data_tx(struct sk_buff
*skb
, struct net_device
*dev
)
239 struct ath6kl
*ar
= ath6kl_priv(dev
);
240 struct ath6kl_cookie
*cookie
= NULL
;
241 enum htc_endpoint_id eid
= ENDPOINT_UNUSED
;
242 struct ath6kl_vif
*vif
= netdev_priv(dev
);
244 u16 htc_tag
= ATH6KL_DATA_PKT_TAG
;
245 u8 ac
= 99 ; /* initialize to unmapped ac */
246 bool chk_adhoc_ps_mapping
= false, more_data
= false;
249 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
250 "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__
,
251 skb
, skb
->data
, skb
->len
);
253 /* If target is not associated */
254 if (!test_bit(CONNECTED
, &vif
->flags
)) {
259 if (!test_bit(WMI_READY
, &ar
->flag
))
262 /* AP mode Power saving processing */
263 if (vif
->nw_type
== AP_NETWORK
) {
264 if (ath6kl_powersave_ap(ar
, skb
, &more_data
))
268 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
269 if (skb_headroom(skb
) < dev
->needed_headroom
) {
274 if (ath6kl_wmi_dix_2_dot3(ar
->wmi
, skb
)) {
275 ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
279 if (ath6kl_wmi_data_hdr_add(ar
->wmi
, skb
, DATA_MSGTYPE
,
280 more_data
, 0, 0, NULL
)) {
281 ath6kl_err("wmi_data_hdr_add failed\n");
285 if ((vif
->nw_type
== ADHOC_NETWORK
) &&
286 ar
->ibss_ps_enable
&& test_bit(CONNECTED
, &vif
->flags
))
287 chk_adhoc_ps_mapping
= true;
289 /* get the stream mapping */
290 ret
= ath6kl_wmi_implicit_create_pstream(ar
->wmi
, skb
,
291 0, test_bit(WMM_ENABLED
, &vif
->flags
), &ac
);
298 spin_lock_bh(&ar
->lock
);
300 if (chk_adhoc_ps_mapping
)
301 eid
= ath6kl_ibss_map_epid(skb
, dev
, &map_no
);
303 eid
= ar
->ac2ep_map
[ac
];
305 if (eid
== 0 || eid
== ENDPOINT_UNUSED
) {
306 ath6kl_err("eid %d is not mapped!\n", eid
);
307 spin_unlock_bh(&ar
->lock
);
311 /* allocate resource for this packet */
312 cookie
= ath6kl_alloc_cookie(ar
);
315 spin_unlock_bh(&ar
->lock
);
319 /* update counts while the lock is held */
320 ar
->tx_pending
[eid
]++;
321 ar
->total_tx_data_pend
++;
323 spin_unlock_bh(&ar
->lock
);
325 if (!IS_ALIGNED((unsigned long) skb
->data
- HTC_HDR_LENGTH
, 4) &&
328 * We will touch (move the buffer data to align it. Since the
329 * skb buffer is cloned and not only the header is changed, we
330 * have to copy it to allow the changes. Since we are copying
331 * the data here, we may as well align it by reserving suitable
332 * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
334 struct sk_buff
*nskb
;
336 nskb
= skb_copy_expand(skb
, HTC_HDR_LENGTH
, 0, GFP_ATOMIC
);
344 cookie
->map_no
= map_no
;
345 set_htc_pkt_info(&cookie
->htc_pkt
, cookie
, skb
->data
, skb
->len
,
348 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "tx ",
349 skb
->data
, skb
->len
);
352 * HTC interface is asynchronous, if this fails, cleanup will
353 * happen in the ath6kl_tx_complete callback.
355 ath6kl_htc_tx(ar
->htc_target
, &cookie
->htc_pkt
);
362 vif
->net_stats
.tx_dropped
++;
363 vif
->net_stats
.tx_aborted_errors
++;
368 /* indicate tx activity or inactivity on a WMI stream */
369 void ath6kl_indicate_tx_activity(void *devt
, u8 traffic_class
, bool active
)
371 struct ath6kl
*ar
= devt
;
372 enum htc_endpoint_id eid
;
375 eid
= ar
->ac2ep_map
[traffic_class
];
377 if (!test_bit(WMI_ENABLED
, &ar
->flag
))
380 spin_lock_bh(&ar
->lock
);
382 ar
->ac_stream_active
[traffic_class
] = active
;
386 * Keep track of the active stream with the highest
389 if (ar
->ac_stream_pri_map
[traffic_class
] >
390 ar
->hiac_stream_active_pri
)
391 /* set the new highest active priority */
392 ar
->hiac_stream_active_pri
=
393 ar
->ac_stream_pri_map
[traffic_class
];
397 * We may have to search for the next active stream
398 * that is the highest priority.
400 if (ar
->hiac_stream_active_pri
==
401 ar
->ac_stream_pri_map
[traffic_class
]) {
403 * The highest priority stream just went inactive
404 * reset and search for the "next" highest "active"
407 ar
->hiac_stream_active_pri
= 0;
409 for (i
= 0; i
< WMM_NUM_AC
; i
++) {
410 if (ar
->ac_stream_active
[i
] &&
411 (ar
->ac_stream_pri_map
[i
] >
412 ar
->hiac_stream_active_pri
))
414 * Set the new highest active
417 ar
->hiac_stream_active_pri
=
418 ar
->ac_stream_pri_map
[i
];
423 spin_unlock_bh(&ar
->lock
);
426 /* notify HTC, this may cause credit distribution changes */
427 ath6kl_htc_indicate_activity_change(ar
->htc_target
, eid
, active
);
430 enum htc_send_full_action
ath6kl_tx_queue_full(struct htc_target
*target
,
431 struct htc_packet
*packet
)
433 struct ath6kl
*ar
= target
->dev
->ar
;
434 /* TODO: Findout vif properly */
435 struct ath6kl_vif
*vif
= ar
->vif
;
436 enum htc_endpoint_id endpoint
= packet
->endpoint
;
438 if (endpoint
== ar
->ctrl_ep
) {
440 * Under normal WMI if this is getting full, then something
441 * is running rampant the host should not be exhausting the
442 * WMI queue with too many commands the only exception to
443 * this is during testing using endpointping.
445 spin_lock_bh(&ar
->lock
);
446 set_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
447 spin_unlock_bh(&ar
->lock
);
448 ath6kl_err("wmi ctrl ep is full\n");
449 return HTC_SEND_FULL_KEEP
;
452 if (packet
->info
.tx
.tag
== ATH6KL_CONTROL_PKT_TAG
)
453 return HTC_SEND_FULL_KEEP
;
455 if (vif
->nw_type
== ADHOC_NETWORK
)
457 * In adhoc mode, we cannot differentiate traffic
458 * priorities so there is no need to continue, however we
459 * should stop the network.
461 goto stop_net_queues
;
464 * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
465 * the highest active stream.
467 if (ar
->ac_stream_pri_map
[ar
->ep2ac_map
[endpoint
]] <
468 ar
->hiac_stream_active_pri
&&
469 ar
->cookie_count
<= MAX_HI_COOKIE_NUM
)
471 * Give preference to the highest priority stream by
472 * dropping the packets which overflowed.
474 return HTC_SEND_FULL_DROP
;
477 spin_lock_bh(&ar
->lock
);
478 set_bit(NETQ_STOPPED
, &vif
->flags
);
479 spin_unlock_bh(&ar
->lock
);
480 netif_stop_queue(ar
->net_dev
);
482 return HTC_SEND_FULL_KEEP
;
485 /* TODO this needs to be looked at */
486 static void ath6kl_tx_clear_node_map(struct ath6kl
*ar
,
487 enum htc_endpoint_id eid
, u32 map_no
)
489 /* TODO: Findout vif */
490 struct ath6kl_vif
*vif
= ar
->vif
;
493 if (vif
->nw_type
!= ADHOC_NETWORK
)
496 if (!ar
->ibss_ps_enable
)
499 if (eid
== ar
->ctrl_ep
)
506 ar
->node_map
[map_no
].tx_pend
--;
508 if (ar
->node_map
[map_no
].tx_pend
)
511 if (map_no
!= (ar
->node_num
- 1))
514 for (i
= ar
->node_num
; i
> 0; i
--) {
515 if (ar
->node_map
[i
- 1].tx_pend
)
518 memset(&ar
->node_map
[i
- 1], 0,
519 sizeof(struct ath6kl_node_mapping
));
524 void ath6kl_tx_complete(void *context
, struct list_head
*packet_queue
)
526 struct ath6kl
*ar
= context
;
527 struct sk_buff_head skb_queue
;
528 struct htc_packet
*packet
;
530 struct ath6kl_cookie
*ath6kl_cookie
;
533 enum htc_endpoint_id eid
;
534 bool wake_event
= false;
535 bool flushing
= false;
536 /* TODO: Findout vif */
537 struct ath6kl_vif
*vif
= ar
->vif
;
539 skb_queue_head_init(&skb_queue
);
541 /* lock the driver as we update internal state */
542 spin_lock_bh(&ar
->lock
);
544 /* reap completed packets */
545 while (!list_empty(packet_queue
)) {
547 packet
= list_first_entry(packet_queue
, struct htc_packet
,
549 list_del(&packet
->list
);
551 ath6kl_cookie
= (struct ath6kl_cookie
*)packet
->pkt_cntxt
;
555 status
= packet
->status
;
556 skb
= ath6kl_cookie
->skb
;
557 eid
= packet
->endpoint
;
558 map_no
= ath6kl_cookie
->map_no
;
560 if (!skb
|| !skb
->data
)
563 packet
->buf
= skb
->data
;
565 __skb_queue_tail(&skb_queue
, skb
);
567 if (!status
&& (packet
->act_len
!= skb
->len
))
570 ar
->tx_pending
[eid
]--;
572 if (eid
!= ar
->ctrl_ep
)
573 ar
->total_tx_data_pend
--;
575 if (eid
== ar
->ctrl_ep
) {
576 if (test_bit(WMI_CTRL_EP_FULL
, &ar
->flag
))
577 clear_bit(WMI_CTRL_EP_FULL
, &ar
->flag
);
579 if (ar
->tx_pending
[eid
] == 0)
584 if (status
== -ECANCELED
)
585 /* a packet was flushed */
588 vif
->net_stats
.tx_errors
++;
590 if (status
!= -ENOSPC
)
591 ath6kl_err("tx error, status: 0x%x\n", status
);
592 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
593 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
594 __func__
, skb
, packet
->buf
, packet
->act_len
,
597 ath6kl_dbg(ATH6KL_DBG_WLAN_TX
,
598 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
599 __func__
, skb
, packet
->buf
, packet
->act_len
,
603 vif
->net_stats
.tx_packets
++;
604 vif
->net_stats
.tx_bytes
+= skb
->len
;
607 ath6kl_tx_clear_node_map(ar
, eid
, map_no
);
609 ath6kl_free_cookie(ar
, ath6kl_cookie
);
611 if (test_bit(NETQ_STOPPED
, &vif
->flags
))
612 clear_bit(NETQ_STOPPED
, &vif
->flags
);
615 spin_unlock_bh(&ar
->lock
);
617 __skb_queue_purge(&skb_queue
);
619 if (test_bit(CONNECTED
, &vif
->flags
)) {
621 netif_wake_queue(ar
->net_dev
);
625 wake_up(&ar
->event_wq
);
631 spin_unlock_bh(&ar
->lock
);
635 void ath6kl_tx_data_cleanup(struct ath6kl
*ar
)
639 /* flush all the data (non-control) streams */
640 for (i
= 0; i
< WMM_NUM_AC
; i
++)
641 ath6kl_htc_flush_txep(ar
->htc_target
, ar
->ac2ep_map
[i
],
642 ATH6KL_DATA_PKT_TAG
);
647 static void ath6kl_deliver_frames_to_nw_stack(struct net_device
*dev
,
655 if (!(skb
->dev
->flags
& IFF_UP
)) {
660 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
665 static void ath6kl_alloc_netbufs(struct sk_buff_head
*q
, u16 num
)
670 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
672 ath6kl_err("netbuf allocation failed\n");
675 skb_queue_tail(q
, skb
);
680 static struct sk_buff
*aggr_get_free_skb(struct aggr_info
*p_aggr
)
682 struct sk_buff
*skb
= NULL
;
684 if (skb_queue_len(&p_aggr
->free_q
) < (AGGR_NUM_OF_FREE_NETBUFS
>> 2))
685 ath6kl_alloc_netbufs(&p_aggr
->free_q
, AGGR_NUM_OF_FREE_NETBUFS
);
687 skb
= skb_dequeue(&p_aggr
->free_q
);
692 void ath6kl_rx_refill(struct htc_target
*target
, enum htc_endpoint_id endpoint
)
694 struct ath6kl
*ar
= target
->dev
->ar
;
698 struct htc_packet
*packet
;
699 struct list_head queue
;
701 n_buf_refill
= ATH6KL_MAX_RX_BUFFERS
-
702 ath6kl_htc_get_rxbuf_num(ar
->htc_target
, endpoint
);
704 if (n_buf_refill
<= 0)
707 INIT_LIST_HEAD(&queue
);
709 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
710 "%s: providing htc with %d buffers at eid=%d\n",
711 __func__
, n_buf_refill
, endpoint
);
713 for (rx_buf
= 0; rx_buf
< n_buf_refill
; rx_buf
++) {
714 skb
= ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE
);
718 packet
= (struct htc_packet
*) skb
->head
;
719 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
720 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
721 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
722 ATH6KL_BUFFER_SIZE
, endpoint
);
723 list_add_tail(&packet
->list
, &queue
);
726 if (!list_empty(&queue
))
727 ath6kl_htc_add_rxbuf_multiple(ar
->htc_target
, &queue
);
730 void ath6kl_refill_amsdu_rxbufs(struct ath6kl
*ar
, int count
)
732 struct htc_packet
*packet
;
736 skb
= ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE
);
740 packet
= (struct htc_packet
*) skb
->head
;
741 if (!IS_ALIGNED((unsigned long) skb
->data
, 4))
742 skb
->data
= PTR_ALIGN(skb
->data
- 4, 4);
743 set_htc_rxpkt_info(packet
, skb
, skb
->data
,
744 ATH6KL_AMSDU_BUFFER_SIZE
, 0);
745 spin_lock_bh(&ar
->lock
);
746 list_add_tail(&packet
->list
, &ar
->amsdu_rx_buffer_queue
);
747 spin_unlock_bh(&ar
->lock
);
753 * Callback to allocate a receive buffer for a pending packet. We use a
754 * pre-allocated list of buffers of maximum AMSDU size (4K).
756 struct htc_packet
*ath6kl_alloc_amsdu_rxbuf(struct htc_target
*target
,
757 enum htc_endpoint_id endpoint
,
760 struct ath6kl
*ar
= target
->dev
->ar
;
761 struct htc_packet
*packet
= NULL
;
762 struct list_head
*pkt_pos
;
763 int refill_cnt
= 0, depth
= 0;
765 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: eid=%d, len:%d\n",
766 __func__
, endpoint
, len
);
768 if ((len
<= ATH6KL_BUFFER_SIZE
) ||
769 (len
> ATH6KL_AMSDU_BUFFER_SIZE
))
772 spin_lock_bh(&ar
->lock
);
774 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
775 spin_unlock_bh(&ar
->lock
);
776 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
;
780 packet
= list_first_entry(&ar
->amsdu_rx_buffer_queue
,
781 struct htc_packet
, list
);
782 list_del(&packet
->list
);
783 list_for_each(pkt_pos
, &ar
->amsdu_rx_buffer_queue
)
786 refill_cnt
= ATH6KL_MAX_AMSDU_RX_BUFFERS
- depth
;
787 spin_unlock_bh(&ar
->lock
);
789 /* set actual endpoint ID */
790 packet
->endpoint
= endpoint
;
793 if (refill_cnt
>= ATH6KL_AMSDU_REFILL_THRESHOLD
)
794 ath6kl_refill_amsdu_rxbufs(ar
, refill_cnt
);
799 static void aggr_slice_amsdu(struct aggr_info
*p_aggr
,
800 struct rxtid
*rxtid
, struct sk_buff
*skb
)
802 struct sk_buff
*new_skb
;
804 u16 frame_8023_len
, payload_8023_len
, mac_hdr_len
, amsdu_len
;
807 mac_hdr_len
= sizeof(struct ethhdr
);
808 framep
= skb
->data
+ mac_hdr_len
;
809 amsdu_len
= skb
->len
- mac_hdr_len
;
811 while (amsdu_len
> mac_hdr_len
) {
812 hdr
= (struct ethhdr
*) framep
;
813 payload_8023_len
= ntohs(hdr
->h_proto
);
815 if (payload_8023_len
< MIN_MSDU_SUBFRAME_PAYLOAD_LEN
||
816 payload_8023_len
> MAX_MSDU_SUBFRAME_PAYLOAD_LEN
) {
817 ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
822 frame_8023_len
= payload_8023_len
+ mac_hdr_len
;
823 new_skb
= aggr_get_free_skb(p_aggr
);
825 ath6kl_err("no buffer available\n");
829 memcpy(new_skb
->data
, framep
, frame_8023_len
);
830 skb_put(new_skb
, frame_8023_len
);
831 if (ath6kl_wmi_dot3_2_dix(new_skb
)) {
832 ath6kl_err("dot3_2_dix error\n");
833 dev_kfree_skb(new_skb
);
837 skb_queue_tail(&rxtid
->q
, new_skb
);
839 /* Is this the last subframe within this aggregate ? */
840 if ((amsdu_len
- frame_8023_len
) == 0)
843 /* Add the length of A-MSDU subframe padding bytes -
844 * Round to nearest word.
846 frame_8023_len
= ALIGN(frame_8023_len
, 4);
848 framep
+= frame_8023_len
;
849 amsdu_len
-= frame_8023_len
;
855 static void aggr_deque_frms(struct aggr_info
*p_aggr
, u8 tid
,
856 u16 seq_no
, u8 order
)
860 struct skb_hold_q
*node
;
861 u16 idx
, idx_end
, seq_end
;
862 struct rxtid_stats
*stats
;
867 rxtid
= &p_aggr
->rx_tid
[tid
];
868 stats
= &p_aggr
->stat
[tid
];
870 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
873 * idx_end is typically the last possible frame in the window,
874 * but changes to 'the' seq_no, when BAR comes. If seq_no
875 * is non-zero, we will go up to that and stop.
876 * Note: last seq no in current window will occupy the same
877 * index position as index that is just previous to start.
878 * An imp point : if win_sz is 7, for seq_no space of 4095,
879 * then, there would be holes when sequence wrap around occurs.
880 * Target should judiciously choose the win_sz, based on
881 * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
882 * 2, 4, 8, 16 win_sz works fine).
883 * We must deque from "idx" to "idx_end", including both.
885 seq_end
= seq_no
? seq_no
: rxtid
->seq_next
;
886 idx_end
= AGGR_WIN_IDX(seq_end
, rxtid
->hold_q_sz
);
888 spin_lock_bh(&rxtid
->lock
);
891 node
= &rxtid
->hold_q
[idx
];
892 if ((order
== 1) && (!node
->skb
))
897 aggr_slice_amsdu(p_aggr
, rxtid
, node
->skb
);
899 skb_queue_tail(&rxtid
->q
, node
->skb
);
904 rxtid
->seq_next
= ATH6KL_NEXT_SEQ_NO(rxtid
->seq_next
);
905 idx
= AGGR_WIN_IDX(rxtid
->seq_next
, rxtid
->hold_q_sz
);
906 } while (idx
!= idx_end
);
908 spin_unlock_bh(&rxtid
->lock
);
910 stats
->num_delivered
+= skb_queue_len(&rxtid
->q
);
912 while ((skb
= skb_dequeue(&rxtid
->q
)))
913 ath6kl_deliver_frames_to_nw_stack(p_aggr
->dev
, skb
);
916 static bool aggr_process_recv_frm(struct aggr_info
*agg_info
, u8 tid
,
918 bool is_amsdu
, struct sk_buff
*frame
)
921 struct rxtid_stats
*stats
;
923 struct skb_hold_q
*node
;
924 u16 idx
, st
, cur
, end
;
925 bool is_queued
= false;
928 rxtid
= &agg_info
->rx_tid
[tid
];
929 stats
= &agg_info
->stat
[tid
];
931 stats
->num_into_aggr
++;
935 aggr_slice_amsdu(agg_info
, rxtid
, frame
);
938 while ((skb
= skb_dequeue(&rxtid
->q
)))
939 ath6kl_deliver_frames_to_nw_stack(agg_info
->dev
,
945 /* Check the incoming sequence no, if it's in the window */
946 st
= rxtid
->seq_next
;
948 end
= (st
+ rxtid
->hold_q_sz
-1) & ATH6KL_MAX_SEQ_NO
;
950 if (((st
< end
) && (cur
< st
|| cur
> end
)) ||
951 ((st
> end
) && (cur
> end
) && (cur
< st
))) {
952 extended_end
= (end
+ rxtid
->hold_q_sz
- 1) &
955 if (((end
< extended_end
) &&
956 (cur
< end
|| cur
> extended_end
)) ||
957 ((end
> extended_end
) && (cur
> extended_end
) &&
959 aggr_deque_frms(agg_info
, tid
, 0, 0);
960 if (cur
>= rxtid
->hold_q_sz
- 1)
961 rxtid
->seq_next
= cur
- (rxtid
->hold_q_sz
- 1);
963 rxtid
->seq_next
= ATH6KL_MAX_SEQ_NO
-
964 (rxtid
->hold_q_sz
- 2 - cur
);
967 * Dequeue only those frames that are outside the
968 * new shifted window.
970 if (cur
>= rxtid
->hold_q_sz
- 1)
971 st
= cur
- (rxtid
->hold_q_sz
- 1);
973 st
= ATH6KL_MAX_SEQ_NO
-
974 (rxtid
->hold_q_sz
- 2 - cur
);
976 aggr_deque_frms(agg_info
, tid
, st
, 0);
982 idx
= AGGR_WIN_IDX(seq_no
, rxtid
->hold_q_sz
);
984 node
= &rxtid
->hold_q
[idx
];
986 spin_lock_bh(&rxtid
->lock
);
989 * Is the cur frame duplicate or something beyond our window(hold_q
990 * -> which is 2x, already)?
992 * 1. Duplicate is easy - drop incoming frame.
993 * 2. Not falling in current sliding window.
994 * 2a. is the frame_seq_no preceding current tid_seq_no?
995 * -> drop the frame. perhaps sender did not get our ACK.
996 * this is taken care of above.
997 * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
998 * -> Taken care of it above, by moving window forward.
1000 dev_kfree_skb(node
->skb
);
1005 node
->is_amsdu
= is_amsdu
;
1006 node
->seq_no
= seq_no
;
1013 spin_unlock_bh(&rxtid
->lock
);
1015 aggr_deque_frms(agg_info
, tid
, 0, 1);
1017 if (agg_info
->timer_scheduled
)
1018 rxtid
->progress
= true;
1020 for (idx
= 0 ; idx
< rxtid
->hold_q_sz
; idx
++) {
1021 if (rxtid
->hold_q
[idx
].skb
) {
1023 * There is a frame in the queue and no
1024 * timer so start a timer to ensure that
1025 * the frame doesn't remain stuck
1028 agg_info
->timer_scheduled
= true;
1029 mod_timer(&agg_info
->timer
,
1031 HZ
* (AGGR_RX_TIMEOUT
) / 1000));
1032 rxtid
->progress
= false;
1033 rxtid
->timer_mon
= true;
1041 void ath6kl_rx(struct htc_target
*target
, struct htc_packet
*packet
)
1043 struct ath6kl
*ar
= target
->dev
->ar
;
1044 struct sk_buff
*skb
= packet
->pkt_cntxt
;
1045 struct wmi_rx_meta_v2
*meta
;
1046 struct wmi_data_hdr
*dhdr
;
1048 u8 meta_type
, dot11_hdr
= 0;
1049 int status
= packet
->status
;
1050 enum htc_endpoint_id ept
= packet
->endpoint
;
1051 bool is_amsdu
, prev_ps
, ps_state
= false;
1052 struct ath6kl_sta
*conn
= NULL
;
1053 struct sk_buff
*skb1
= NULL
;
1054 struct ethhdr
*datap
= NULL
;
1055 /* TODO: Findout vif */
1056 struct ath6kl_vif
*vif
= ar
->vif
;
1060 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
,
1061 "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
1062 __func__
, ar
, ept
, skb
, packet
->buf
,
1063 packet
->act_len
, status
);
1065 if (status
|| !(skb
->data
+ HTC_HDR_LENGTH
)) {
1066 vif
->net_stats
.rx_errors
++;
1072 * Take lock to protect buffer counts and adaptive power throughput
1075 spin_lock_bh(&ar
->lock
);
1077 vif
->net_stats
.rx_packets
++;
1078 vif
->net_stats
.rx_bytes
+= packet
->act_len
;
1080 spin_unlock_bh(&ar
->lock
);
1082 skb_put(skb
, packet
->act_len
+ HTC_HDR_LENGTH
);
1083 skb_pull(skb
, HTC_HDR_LENGTH
);
1085 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES
, __func__
, "rx ",
1086 skb
->data
, skb
->len
);
1088 skb
->dev
= ar
->net_dev
;
1090 if (!test_bit(WMI_ENABLED
, &ar
->flag
)) {
1091 if (EPPING_ALIGNMENT_PAD
> 0)
1092 skb_pull(skb
, EPPING_ALIGNMENT_PAD
);
1093 ath6kl_deliver_frames_to_nw_stack(ar
->net_dev
, skb
);
1097 if (ept
== ar
->ctrl_ep
) {
1098 ath6kl_wmi_control_rx(ar
->wmi
, skb
);
1102 min_hdr_len
= sizeof(struct ethhdr
) + sizeof(struct wmi_data_hdr
) +
1103 sizeof(struct ath6kl_llc_snap_hdr
);
1105 dhdr
= (struct wmi_data_hdr
*) skb
->data
;
1108 * In the case of AP mode we may receive NULL data frames
1109 * that do not have LLC hdr. They are 16 bytes in size.
1110 * Allow these frames in the AP mode.
1112 if (vif
->nw_type
!= AP_NETWORK
&&
1113 ((packet
->act_len
< min_hdr_len
) ||
1114 (packet
->act_len
> WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
))) {
1115 ath6kl_info("frame len is too short or too long\n");
1116 vif
->net_stats
.rx_errors
++;
1117 vif
->net_stats
.rx_length_errors
++;
1122 /* Get the Power save state of the STA */
1123 if (vif
->nw_type
== AP_NETWORK
) {
1124 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1126 ps_state
= !!((dhdr
->info
>> WMI_DATA_HDR_PS_SHIFT
) &
1127 WMI_DATA_HDR_PS_MASK
);
1129 offset
= sizeof(struct wmi_data_hdr
);
1131 switch (meta_type
) {
1134 case WMI_META_VERSION_1
:
1135 offset
+= sizeof(struct wmi_rx_meta_v1
);
1137 case WMI_META_VERSION_2
:
1138 offset
+= sizeof(struct wmi_rx_meta_v2
);
1144 datap
= (struct ethhdr
*) (skb
->data
+ offset
);
1145 conn
= ath6kl_find_sta(ar
, datap
->h_source
);
1153 * If there is a change in PS state of the STA,
1154 * take appropriate steps:
1156 * 1. If Sleep-->Awake, flush the psq for the STA
1157 * Clear the PVB for the STA.
1158 * 2. If Awake-->Sleep, Starting queueing frames
1161 prev_ps
= !!(conn
->sta_flags
& STA_PS_SLEEP
);
1164 conn
->sta_flags
|= STA_PS_SLEEP
;
1166 conn
->sta_flags
&= ~STA_PS_SLEEP
;
1168 if (prev_ps
^ !!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1169 if (!(conn
->sta_flags
& STA_PS_SLEEP
)) {
1170 struct sk_buff
*skbuff
= NULL
;
1172 spin_lock_bh(&conn
->psq_lock
);
1173 while ((skbuff
= skb_dequeue(&conn
->psq
))
1175 spin_unlock_bh(&conn
->psq_lock
);
1176 ath6kl_data_tx(skbuff
, ar
->net_dev
);
1177 spin_lock_bh(&conn
->psq_lock
);
1179 spin_unlock_bh(&conn
->psq_lock
);
1180 /* Clear the PVB for this STA */
1181 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
,
1186 /* drop NULL data frames here */
1187 if ((packet
->act_len
< min_hdr_len
) ||
1189 WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH
)) {
1195 is_amsdu
= wmi_data_hdr_is_amsdu(dhdr
) ? true : false;
1196 tid
= wmi_data_hdr_get_up(dhdr
);
1197 seq_no
= wmi_data_hdr_get_seqno(dhdr
);
1198 meta_type
= wmi_data_hdr_get_meta(dhdr
);
1199 dot11_hdr
= wmi_data_hdr_get_dot11(dhdr
);
1200 skb_pull(skb
, sizeof(struct wmi_data_hdr
));
1202 switch (meta_type
) {
1203 case WMI_META_VERSION_1
:
1204 skb_pull(skb
, sizeof(struct wmi_rx_meta_v1
));
1206 case WMI_META_VERSION_2
:
1207 meta
= (struct wmi_rx_meta_v2
*) skb
->data
;
1208 if (meta
->csum_flags
& 0x1) {
1209 skb
->ip_summed
= CHECKSUM_COMPLETE
;
1210 skb
->csum
= (__force __wsum
) meta
->csum
;
1212 skb_pull(skb
, sizeof(struct wmi_rx_meta_v2
));
1219 status
= ath6kl_wmi_dot11_hdr_remove(ar
->wmi
, skb
);
1221 status
= ath6kl_wmi_dot3_2_dix(skb
);
1225 * Drop frames that could not be processed (lack of
1232 if (!(ar
->net_dev
->flags
& IFF_UP
)) {
1237 if (vif
->nw_type
== AP_NETWORK
) {
1238 datap
= (struct ethhdr
*) skb
->data
;
1239 if (is_multicast_ether_addr(datap
->h_dest
))
1241 * Bcast/Mcast frames should be sent to the
1242 * OS stack as well as on the air.
1244 skb1
= skb_copy(skb
, GFP_ATOMIC
);
1247 * Search for a connected STA with dstMac
1248 * as the Mac address. If found send the
1249 * frame to it on the air else send the
1250 * frame up the stack.
1252 conn
= ath6kl_find_sta(ar
, datap
->h_dest
);
1254 if (conn
&& ar
->intra_bss
) {
1257 } else if (conn
&& !ar
->intra_bss
) {
1263 ath6kl_data_tx(skb1
, ar
->net_dev
);
1266 /* nothing to deliver up the stack */
1271 datap
= (struct ethhdr
*) skb
->data
;
1273 if (is_unicast_ether_addr(datap
->h_dest
) &&
1274 aggr_process_recv_frm(vif
->aggr_cntxt
, tid
, seq_no
,
1276 /* aggregation code will handle the skb */
1279 ath6kl_deliver_frames_to_nw_stack(ar
->net_dev
, skb
);
1282 static void aggr_timeout(unsigned long arg
)
1285 struct aggr_info
*p_aggr
= (struct aggr_info
*) arg
;
1286 struct rxtid
*rxtid
;
1287 struct rxtid_stats
*stats
;
1289 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1290 rxtid
= &p_aggr
->rx_tid
[i
];
1291 stats
= &p_aggr
->stat
[i
];
1293 if (!rxtid
->aggr
|| !rxtid
->timer_mon
|| rxtid
->progress
)
1296 stats
->num_timeouts
++;
1297 ath6kl_dbg(ATH6KL_DBG_AGGR
,
1298 "aggr timeout (st %d end %d)\n",
1300 ((rxtid
->seq_next
+ rxtid
->hold_q_sz
-1) &
1301 ATH6KL_MAX_SEQ_NO
));
1302 aggr_deque_frms(p_aggr
, i
, 0, 0);
1305 p_aggr
->timer_scheduled
= false;
1307 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1308 rxtid
= &p_aggr
->rx_tid
[i
];
1310 if (rxtid
->aggr
&& rxtid
->hold_q
) {
1311 for (j
= 0; j
< rxtid
->hold_q_sz
; j
++) {
1312 if (rxtid
->hold_q
[j
].skb
) {
1313 p_aggr
->timer_scheduled
= true;
1314 rxtid
->timer_mon
= true;
1315 rxtid
->progress
= false;
1320 if (j
>= rxtid
->hold_q_sz
)
1321 rxtid
->timer_mon
= false;
1325 if (p_aggr
->timer_scheduled
)
1326 mod_timer(&p_aggr
->timer
,
1327 jiffies
+ msecs_to_jiffies(AGGR_RX_TIMEOUT
));
1330 static void aggr_delete_tid_state(struct aggr_info
*p_aggr
, u8 tid
)
1332 struct rxtid
*rxtid
;
1333 struct rxtid_stats
*stats
;
1335 if (!p_aggr
|| tid
>= NUM_OF_TIDS
)
1338 rxtid
= &p_aggr
->rx_tid
[tid
];
1339 stats
= &p_aggr
->stat
[tid
];
1342 aggr_deque_frms(p_aggr
, tid
, 0, 0);
1344 rxtid
->aggr
= false;
1345 rxtid
->progress
= false;
1346 rxtid
->timer_mon
= false;
1348 rxtid
->seq_next
= 0;
1349 rxtid
->hold_q_sz
= 0;
1351 kfree(rxtid
->hold_q
);
1352 rxtid
->hold_q
= NULL
;
1354 memset(stats
, 0, sizeof(struct rxtid_stats
));
1357 void aggr_recv_addba_req_evt(struct ath6kl
*ar
, u8 tid
, u16 seq_no
, u8 win_sz
)
1359 /* TODO: Findout vif */
1360 struct ath6kl_vif
*vif
= ar
->vif
;
1361 struct aggr_info
*p_aggr
= vif
->aggr_cntxt
;
1362 struct rxtid
*rxtid
;
1363 struct rxtid_stats
*stats
;
1369 rxtid
= &p_aggr
->rx_tid
[tid
];
1370 stats
= &p_aggr
->stat
[tid
];
1372 if (win_sz
< AGGR_WIN_SZ_MIN
|| win_sz
> AGGR_WIN_SZ_MAX
)
1373 ath6kl_dbg(ATH6KL_DBG_WLAN_RX
, "%s: win_sz %d, tid %d\n",
1374 __func__
, win_sz
, tid
);
1377 aggr_delete_tid_state(p_aggr
, tid
);
1379 rxtid
->seq_next
= seq_no
;
1380 hold_q_size
= TID_WINDOW_SZ(win_sz
) * sizeof(struct skb_hold_q
);
1381 rxtid
->hold_q
= kzalloc(hold_q_size
, GFP_KERNEL
);
1385 rxtid
->win_sz
= win_sz
;
1386 rxtid
->hold_q_sz
= TID_WINDOW_SZ(win_sz
);
1387 if (!skb_queue_empty(&rxtid
->q
))
1393 struct aggr_info
*aggr_init(struct net_device
*dev
)
1395 struct aggr_info
*p_aggr
= NULL
;
1396 struct rxtid
*rxtid
;
1399 p_aggr
= kzalloc(sizeof(struct aggr_info
), GFP_KERNEL
);
1401 ath6kl_err("failed to alloc memory for aggr_node\n");
1405 p_aggr
->aggr_sz
= AGGR_SZ_DEFAULT
;
1407 init_timer(&p_aggr
->timer
);
1408 p_aggr
->timer
.function
= aggr_timeout
;
1409 p_aggr
->timer
.data
= (unsigned long) p_aggr
;
1411 p_aggr
->timer_scheduled
= false;
1412 skb_queue_head_init(&p_aggr
->free_q
);
1414 ath6kl_alloc_netbufs(&p_aggr
->free_q
, AGGR_NUM_OF_FREE_NETBUFS
);
1416 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1417 rxtid
= &p_aggr
->rx_tid
[i
];
1418 rxtid
->aggr
= false;
1419 rxtid
->progress
= false;
1420 rxtid
->timer_mon
= false;
1421 skb_queue_head_init(&rxtid
->q
);
1422 spin_lock_init(&rxtid
->lock
);
1428 void aggr_recv_delba_req_evt(struct ath6kl
*ar
, u8 tid
)
1430 /* TODO: Findout vif */
1431 struct ath6kl_vif
*vif
= ar
->vif
;
1432 struct aggr_info
*p_aggr
= vif
->aggr_cntxt
;
1433 struct rxtid
*rxtid
;
1438 rxtid
= &p_aggr
->rx_tid
[tid
];
1441 aggr_delete_tid_state(p_aggr
, tid
);
1444 void aggr_reset_state(struct aggr_info
*aggr_info
)
1448 for (tid
= 0; tid
< NUM_OF_TIDS
; tid
++)
1449 aggr_delete_tid_state(aggr_info
, tid
);
1452 /* clean up our amsdu buffer list */
1453 void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl
*ar
)
1455 struct htc_packet
*packet
, *tmp_pkt
;
1457 spin_lock_bh(&ar
->lock
);
1458 if (list_empty(&ar
->amsdu_rx_buffer_queue
)) {
1459 spin_unlock_bh(&ar
->lock
);
1463 list_for_each_entry_safe(packet
, tmp_pkt
, &ar
->amsdu_rx_buffer_queue
,
1465 list_del(&packet
->list
);
1466 spin_unlock_bh(&ar
->lock
);
1467 dev_kfree_skb(packet
->pkt_cntxt
);
1468 spin_lock_bh(&ar
->lock
);
1471 spin_unlock_bh(&ar
->lock
);
1474 void aggr_module_destroy(struct aggr_info
*aggr_info
)
1476 struct rxtid
*rxtid
;
1482 if (aggr_info
->timer_scheduled
) {
1483 del_timer(&aggr_info
->timer
);
1484 aggr_info
->timer_scheduled
= false;
1487 for (i
= 0; i
< NUM_OF_TIDS
; i
++) {
1488 rxtid
= &aggr_info
->rx_tid
[i
];
1489 if (rxtid
->hold_q
) {
1490 for (k
= 0; k
< rxtid
->hold_q_sz
; k
++)
1491 dev_kfree_skb(rxtid
->hold_q
[k
].skb
);
1492 kfree(rxtid
->hold_q
);
1495 skb_queue_purge(&rxtid
->q
);
1498 skb_queue_purge(&aggr_info
->free_q
);