2 * Copyright (c) 2007-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.
21 #define HTC_PACKET_CONTAINER_ALLOCATION 32
22 #define HTC_CONTROL_BUFFER_SIZE (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH)
24 static int ath6kl_htc_pipe_tx(struct htc_target
*handle
,
25 struct htc_packet
*packet
);
26 static void ath6kl_htc_pipe_cleanup(struct htc_target
*handle
);
28 /* htc pipe tx path */
29 static inline void restore_tx_packet(struct htc_packet
*packet
)
31 if (packet
->info
.tx
.flags
& HTC_FLAGS_TX_FIXUP_NETBUF
) {
32 skb_pull(packet
->skb
, sizeof(struct htc_frame_hdr
));
33 packet
->info
.tx
.flags
&= ~HTC_FLAGS_TX_FIXUP_NETBUF
;
37 static void do_send_completion(struct htc_endpoint
*ep
,
38 struct list_head
*queue_to_indicate
)
40 struct htc_packet
*packet
;
42 if (list_empty(queue_to_indicate
)) {
43 /* nothing to indicate */
47 if (ep
->ep_cb
.tx_comp_multi
!= NULL
) {
48 ath6kl_dbg(ATH6KL_DBG_HTC
,
49 "%s: calling ep %d, send complete multiple callback (%d pkts)\n",
51 get_queue_depth(queue_to_indicate
));
53 * a multiple send complete handler is being used,
54 * pass the queue to the handler
56 ep
->ep_cb
.tx_comp_multi(ep
->target
, queue_to_indicate
);
58 * all packets are now owned by the callback,
59 * reset queue to be safe
61 INIT_LIST_HEAD(queue_to_indicate
);
63 /* using legacy EpTxComplete */
65 packet
= list_first_entry(queue_to_indicate
,
66 struct htc_packet
, list
);
68 list_del(&packet
->list
);
69 ath6kl_dbg(ATH6KL_DBG_HTC
,
70 "%s: calling ep %d send complete callback on packet 0x%p\n",
71 __func__
, ep
->eid
, packet
);
72 ep
->ep_cb
.tx_complete(ep
->target
, packet
);
73 } while (!list_empty(queue_to_indicate
));
77 static void send_packet_completion(struct htc_target
*target
,
78 struct htc_packet
*packet
)
80 struct htc_endpoint
*ep
= &target
->endpoint
[packet
->endpoint
];
81 struct list_head container
;
83 restore_tx_packet(packet
);
84 INIT_LIST_HEAD(&container
);
85 list_add_tail(&packet
->list
, &container
);
88 do_send_completion(ep
, &container
);
91 static void get_htc_packet_credit_based(struct htc_target
*target
,
92 struct htc_endpoint
*ep
,
93 struct list_head
*queue
)
98 struct htc_packet
*packet
;
99 unsigned int transfer_len
;
101 /* NOTE : the TX lock is held when this function is called */
103 /* loop until we can grab as many packets out of the queue as we can */
106 if (list_empty(&ep
->txq
))
109 /* get packet at head, but don't remove it */
110 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
114 ath6kl_dbg(ATH6KL_DBG_HTC
,
115 "%s: got head packet:0x%p , queue depth: %d\n",
116 __func__
, packet
, get_queue_depth(&ep
->txq
));
118 transfer_len
= packet
->act_len
+ HTC_HDR_LENGTH
;
120 if (transfer_len
<= target
->tgt_cred_sz
) {
121 credits_required
= 1;
123 /* figure out how many credits this message requires */
124 credits_required
= transfer_len
/ target
->tgt_cred_sz
;
125 remainder
= transfer_len
% target
->tgt_cred_sz
;
131 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: creds required:%d got:%d\n",
132 __func__
, credits_required
, ep
->cred_dist
.credits
);
134 if (ep
->eid
== ENDPOINT_0
) {
136 * endpoint 0 is special, it always has a credit and
137 * does not require credit based flow control
139 credits_required
= 0;
143 if (ep
->cred_dist
.credits
< credits_required
)
146 ep
->cred_dist
.credits
-= credits_required
;
147 ep
->ep_st
.cred_cosumd
+= credits_required
;
149 /* check if we need credits back from the target */
150 if (ep
->cred_dist
.credits
<
151 ep
->cred_dist
.cred_per_msg
) {
152 /* tell the target we need credits ASAP! */
153 send_flags
|= HTC_FLAGS_NEED_CREDIT_UPDATE
;
154 ep
->ep_st
.cred_low_indicate
+= 1;
155 ath6kl_dbg(ATH6KL_DBG_HTC
,
156 "%s: host needs credits\n",
161 /* now we can fully dequeue */
162 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
164 list_del(&packet
->list
);
165 /* save the number of credits this packet consumed */
166 packet
->info
.tx
.cred_used
= credits_required
;
167 /* save send flags */
168 packet
->info
.tx
.flags
= send_flags
;
169 packet
->info
.tx
.seqno
= ep
->seqno
;
171 /* queue this packet into the caller's queue */
172 list_add_tail(&packet
->list
, queue
);
177 static void get_htc_packet(struct htc_target
*target
,
178 struct htc_endpoint
*ep
,
179 struct list_head
*queue
, int resources
)
181 struct htc_packet
*packet
;
183 /* NOTE : the TX lock is held when this function is called */
185 /* loop until we can grab as many packets out of the queue as we can */
187 if (list_empty(&ep
->txq
))
190 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
191 list_del(&packet
->list
);
193 ath6kl_dbg(ATH6KL_DBG_HTC
,
194 "%s: got packet:0x%p , new queue depth: %d\n",
195 __func__
, packet
, get_queue_depth(&ep
->txq
));
196 packet
->info
.tx
.seqno
= ep
->seqno
;
197 packet
->info
.tx
.flags
= 0;
198 packet
->info
.tx
.cred_used
= 0;
201 /* queue this packet into the caller's queue */
202 list_add_tail(&packet
->list
, queue
);
207 static int htc_issue_packets(struct htc_target
*target
,
208 struct htc_endpoint
*ep
,
209 struct list_head
*pkt_queue
)
214 struct htc_frame_hdr
*htc_hdr
;
215 struct htc_packet
*packet
;
217 ath6kl_dbg(ATH6KL_DBG_HTC
,
218 "%s: queue: 0x%p, pkts %d\n", __func__
,
219 pkt_queue
, get_queue_depth(pkt_queue
));
221 while (!list_empty(pkt_queue
)) {
222 packet
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
223 list_del(&packet
->list
);
232 payload_len
= packet
->act_len
;
234 /* setup HTC frame header */
235 htc_hdr
= (struct htc_frame_hdr
*) skb_push(skb
,
243 packet
->info
.tx
.flags
|= HTC_FLAGS_TX_FIXUP_NETBUF
;
246 put_unaligned((u16
) payload_len
, &htc_hdr
->payld_len
);
247 htc_hdr
->flags
= packet
->info
.tx
.flags
;
248 htc_hdr
->eid
= (u8
) packet
->endpoint
;
249 htc_hdr
->ctrl
[0] = 0;
250 htc_hdr
->ctrl
[1] = (u8
) packet
->info
.tx
.seqno
;
252 spin_lock_bh(&target
->tx_lock
);
254 /* store in look up queue to match completions */
255 list_add_tail(&packet
->list
, &ep
->pipe
.tx_lookup_queue
);
256 ep
->ep_st
.tx_issued
+= 1;
257 spin_unlock_bh(&target
->tx_lock
);
259 status
= ath6kl_hif_pipe_send(target
->dev
->ar
,
260 ep
->pipe
.pipeid_ul
, NULL
, skb
);
263 if (status
!= -ENOMEM
) {
264 /* TODO: if more than 1 endpoint maps to the
265 * same PipeID, it is possible to run out of
266 * resources in the HIF layer.
267 * Don't emit the error
269 ath6kl_dbg(ATH6KL_DBG_HTC
,
270 "%s: failed status:%d\n",
273 spin_lock_bh(&target
->tx_lock
);
274 list_del(&packet
->list
);
276 /* reclaim credits */
277 ep
->cred_dist
.credits
+= packet
->info
.tx
.cred_used
;
278 spin_unlock_bh(&target
->tx_lock
);
280 /* put it back into the callers queue */
281 list_add(&packet
->list
, pkt_queue
);
288 while (!list_empty(pkt_queue
)) {
289 if (status
!= -ENOMEM
) {
290 ath6kl_dbg(ATH6KL_DBG_HTC
,
291 "%s: failed pkt:0x%p status:%d\n",
292 __func__
, packet
, status
);
295 packet
= list_first_entry(pkt_queue
,
296 struct htc_packet
, list
);
297 list_del(&packet
->list
);
298 packet
->status
= status
;
299 send_packet_completion(target
, packet
);
306 static enum htc_send_queue_result
htc_try_send(struct htc_target
*target
,
307 struct htc_endpoint
*ep
,
308 struct list_head
*txq
)
310 struct list_head send_queue
; /* temp queue to hold packets */
311 struct htc_packet
*packet
, *tmp_pkt
;
312 struct ath6kl
*ar
= target
->dev
->ar
;
313 enum htc_send_full_action action
;
314 int tx_resources
, overflow
, txqueue_depth
, i
, good_pkts
;
317 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: (queue:0x%p depth:%d)\n",
319 (txq
== NULL
) ? 0 : get_queue_depth(txq
));
321 /* init the local send queue */
322 INIT_LIST_HEAD(&send_queue
);
325 * txq equals to NULL means
326 * caller didn't provide a queue, just wants us to
327 * check queues and send
330 if (list_empty(txq
)) {
332 return HTC_SEND_QUEUE_DROP
;
335 spin_lock_bh(&target
->tx_lock
);
336 txqueue_depth
= get_queue_depth(&ep
->txq
);
337 spin_unlock_bh(&target
->tx_lock
);
339 if (txqueue_depth
>= ep
->max_txq_depth
) {
340 /* we've already overflowed */
341 overflow
= get_queue_depth(txq
);
343 /* get how much we will overflow by */
344 overflow
= txqueue_depth
;
345 overflow
+= get_queue_depth(txq
);
346 /* get how much we will overflow the TX queue by */
347 overflow
-= ep
->max_txq_depth
;
350 /* if overflow is negative or zero, we are okay */
352 ath6kl_dbg(ATH6KL_DBG_HTC
,
353 "%s: Endpoint %d, TX queue will overflow :%d, Tx Depth:%d, Max:%d\n",
354 __func__
, ep
->eid
, overflow
, txqueue_depth
,
357 if ((overflow
<= 0) ||
358 (ep
->ep_cb
.tx_full
== NULL
)) {
360 * all packets will fit or caller did not provide send
361 * full indication handler -- just move all of them
362 * to the local send_queue object
364 list_splice_tail_init(txq
, &send_queue
);
366 good_pkts
= get_queue_depth(txq
) - overflow
;
369 return HTC_SEND_QUEUE_DROP
;
372 /* we have overflowed, and a callback is provided */
373 /* dequeue all non-overflow packets to the sendqueue */
374 for (i
= 0; i
< good_pkts
; i
++) {
375 /* pop off caller's queue */
376 packet
= list_first_entry(txq
,
379 list_del(&packet
->list
);
380 /* insert into local queue */
381 list_add_tail(&packet
->list
, &send_queue
);
385 * the caller's queue has all the packets that won't fit
386 * walk through the caller's queue and indicate each to
387 * the send full handler
389 list_for_each_entry_safe(packet
, tmp_pkt
,
392 ath6kl_dbg(ATH6KL_DBG_HTC
,
393 "%s: Indicat overflowed TX pkts: %p\n",
395 action
= ep
->ep_cb
.tx_full(ep
->target
, packet
);
396 if (action
== HTC_SEND_FULL_DROP
) {
397 /* callback wants the packet dropped */
398 ep
->ep_st
.tx_dropped
+= 1;
400 /* leave this one in the caller's queue
403 /* callback wants to keep this packet,
404 * remove from caller's queue */
405 list_del(&packet
->list
);
406 /* put it in the send queue */
407 list_add_tail(&packet
->list
,
413 if (list_empty(&send_queue
)) {
414 /* no packets made it in, caller will cleanup */
415 return HTC_SEND_QUEUE_DROP
;
420 if (!ep
->pipe
.tx_credit_flow_enabled
) {
422 ath6kl_hif_pipe_get_free_queue_number(ar
,
428 spin_lock_bh(&target
->tx_lock
);
429 if (!list_empty(&send_queue
)) {
430 /* transfer packets to tail */
431 list_splice_tail_init(&send_queue
, &ep
->txq
);
432 if (!list_empty(&send_queue
)) {
434 spin_unlock_bh(&target
->tx_lock
);
435 return HTC_SEND_QUEUE_DROP
;
437 INIT_LIST_HEAD(&send_queue
);
440 /* increment tx processing count on entry */
443 if (ep
->tx_proc_cnt
> 1) {
445 * Another thread or task is draining the TX queues on this
446 * endpoint that thread will reset the tx processing count
447 * when the queue is drained.
450 spin_unlock_bh(&target
->tx_lock
);
451 return HTC_SEND_QUEUE_OK
;
454 /***** beyond this point only 1 thread may enter ******/
457 * Now drain the endpoint TX queue for transmission as long as we have
458 * enough transmit resources.
462 if (get_queue_depth(&ep
->txq
) == 0)
465 if (ep
->pipe
.tx_credit_flow_enabled
) {
467 * Credit based mechanism provides flow control
468 * based on target transmit resource availability,
469 * we assume that the HIF layer will always have
470 * bus resources greater than target transmit
473 get_htc_packet_credit_based(target
, ep
, &send_queue
);
476 * Get all packets for this endpoint that we can
479 get_htc_packet(target
, ep
, &send_queue
, tx_resources
);
482 if (get_queue_depth(&send_queue
) == 0) {
484 * Didn't get packets due to out of resources or TX
490 spin_unlock_bh(&target
->tx_lock
);
492 /* send what we can */
493 htc_issue_packets(target
, ep
, &send_queue
);
495 if (!ep
->pipe
.tx_credit_flow_enabled
) {
496 pipeid
= ep
->pipe
.pipeid_ul
;
498 ath6kl_hif_pipe_get_free_queue_number(ar
, pipeid
);
501 spin_lock_bh(&target
->tx_lock
);
504 /* done with this endpoint, we can clear the count */
506 spin_unlock_bh(&target
->tx_lock
);
508 return HTC_SEND_QUEUE_OK
;
511 /* htc control packet manipulation */
512 static void destroy_htc_txctrl_packet(struct htc_packet
*packet
)
522 static struct htc_packet
*build_htc_txctrl_packet(void)
524 struct htc_packet
*packet
= NULL
;
527 packet
= kzalloc(sizeof(struct htc_packet
), GFP_KERNEL
);
531 skb
= __dev_alloc_skb(HTC_CONTROL_BUFFER_SIZE
, GFP_KERNEL
);
542 static void htc_free_txctrl_packet(struct htc_target
*target
,
543 struct htc_packet
*packet
)
545 destroy_htc_txctrl_packet(packet
);
548 static struct htc_packet
*htc_alloc_txctrl_packet(struct htc_target
*target
)
550 return build_htc_txctrl_packet();
553 static void htc_txctrl_complete(struct htc_target
*target
,
554 struct htc_packet
*packet
)
556 htc_free_txctrl_packet(target
, packet
);
559 #define MAX_MESSAGE_SIZE 1536
561 static int htc_setup_target_buffer_assignments(struct htc_target
*target
)
563 int status
, credits
, credit_per_maxmsg
, i
;
564 struct htc_pipe_txcredit_alloc
*entry
;
565 unsigned int hif_usbaudioclass
= 0;
567 credit_per_maxmsg
= MAX_MESSAGE_SIZE
/ target
->tgt_cred_sz
;
568 if (MAX_MESSAGE_SIZE
% target
->tgt_cred_sz
)
571 /* TODO, this should be configured by the caller! */
573 credits
= target
->tgt_creds
;
574 entry
= &target
->pipe
.txcredit_alloc
[0];
578 /* FIXME: hif_usbaudioclass is always zero */
579 if (hif_usbaudioclass
) {
580 ath6kl_dbg(ATH6KL_DBG_HTC
,
581 "%s: For USB Audio Class- Total:%d\n",
585 /* Setup VO Service To have Max Credits */
586 entry
->service_id
= WMI_DATA_VO_SVC
;
587 entry
->credit_alloc
= (credits
- 6);
588 if (entry
->credit_alloc
== 0)
589 entry
->credit_alloc
++;
591 credits
-= (int) entry
->credit_alloc
;
596 entry
->service_id
= WMI_CONTROL_SVC
;
597 entry
->credit_alloc
= credit_per_maxmsg
;
598 credits
-= (int) entry
->credit_alloc
;
602 /* leftovers go to best effort */
605 entry
->service_id
= WMI_DATA_BE_SVC
;
606 entry
->credit_alloc
= (u8
) credits
;
610 entry
->service_id
= WMI_DATA_VI_SVC
;
611 entry
->credit_alloc
= credits
/ 4;
612 if (entry
->credit_alloc
== 0)
613 entry
->credit_alloc
++;
615 credits
-= (int) entry
->credit_alloc
;
620 entry
->service_id
= WMI_DATA_VO_SVC
;
621 entry
->credit_alloc
= credits
/ 4;
622 if (entry
->credit_alloc
== 0)
623 entry
->credit_alloc
++;
625 credits
-= (int) entry
->credit_alloc
;
630 entry
->service_id
= WMI_CONTROL_SVC
;
631 entry
->credit_alloc
= credit_per_maxmsg
;
632 credits
-= (int) entry
->credit_alloc
;
637 entry
->service_id
= WMI_DATA_BK_SVC
;
638 entry
->credit_alloc
= credit_per_maxmsg
;
639 credits
-= (int) entry
->credit_alloc
;
643 /* leftovers go to best effort */
645 entry
->service_id
= WMI_DATA_BE_SVC
;
646 entry
->credit_alloc
= (u8
) credits
;
651 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
652 if (target
->pipe
.txcredit_alloc
[i
].service_id
!= 0) {
653 ath6kl_dbg(ATH6KL_DBG_HTC
,
654 "HTC Service Index : %d TX : 0x%2.2X : alloc:%d\n",
656 target
->pipe
.txcredit_alloc
[i
].
658 target
->pipe
.txcredit_alloc
[i
].
666 /* process credit reports and call distribution function */
667 static void htc_process_credit_report(struct htc_target
*target
,
668 struct htc_credit_report
*rpt
,
670 enum htc_endpoint_id from_ep
)
672 int total_credits
= 0, i
;
673 struct htc_endpoint
*ep
;
675 /* lock out TX while we update credits */
676 spin_lock_bh(&target
->tx_lock
);
678 for (i
= 0; i
< num_entries
; i
++, rpt
++) {
679 if (rpt
->eid
>= ENDPOINT_MAX
) {
681 spin_unlock_bh(&target
->tx_lock
);
685 ep
= &target
->endpoint
[rpt
->eid
];
686 ep
->cred_dist
.credits
+= rpt
->credits
;
688 if (ep
->cred_dist
.credits
&& get_queue_depth(&ep
->txq
)) {
689 spin_unlock_bh(&target
->tx_lock
);
690 htc_try_send(target
, ep
, NULL
);
691 spin_lock_bh(&target
->tx_lock
);
694 total_credits
+= rpt
->credits
;
696 ath6kl_dbg(ATH6KL_DBG_HTC
,
697 "Report indicated %d credits to distribute\n",
700 spin_unlock_bh(&target
->tx_lock
);
703 /* flush endpoint TX queue */
704 static void htc_flush_tx_endpoint(struct htc_target
*target
,
705 struct htc_endpoint
*ep
, u16 tag
)
707 struct htc_packet
*packet
;
709 spin_lock_bh(&target
->tx_lock
);
710 while (get_queue_depth(&ep
->txq
)) {
711 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
712 list_del(&packet
->list
);
714 send_packet_completion(target
, packet
);
716 spin_unlock_bh(&target
->tx_lock
);
720 * In the adapted HIF layer, struct sk_buff * are passed between HIF and HTC,
721 * since upper layers expects struct htc_packet containers we use the completed
722 * skb and lookup it's corresponding HTC packet buffer from a lookup list.
723 * This is extra overhead that can be fixed by re-aligning HIF interfaces with
726 static struct htc_packet
*htc_lookup_tx_packet(struct htc_target
*target
,
727 struct htc_endpoint
*ep
,
730 struct htc_packet
*packet
, *tmp_pkt
, *found_packet
= NULL
;
732 spin_lock_bh(&target
->tx_lock
);
735 * interate from the front of tx lookup queue
736 * this lookup should be fast since lower layers completes in-order and
737 * so the completed packet should be at the head of the list generally
739 list_for_each_entry_safe(packet
, tmp_pkt
, &ep
->pipe
.tx_lookup_queue
,
741 /* check for removal */
742 if (skb
== packet
->skb
) {
744 list_del(&packet
->list
);
745 found_packet
= packet
;
750 spin_unlock_bh(&target
->tx_lock
);
755 static int ath6kl_htc_pipe_tx_complete(struct ath6kl
*ar
, struct sk_buff
*skb
)
757 struct htc_target
*target
= ar
->htc_target
;
758 struct htc_frame_hdr
*htc_hdr
;
759 struct htc_endpoint
*ep
;
760 struct htc_packet
*packet
;
767 htc_hdr
= (struct htc_frame_hdr
*) netdata
;
769 ep_id
= htc_hdr
->eid
;
770 ep
= &target
->endpoint
[ep_id
];
772 packet
= htc_lookup_tx_packet(target
, ep
, skb
);
773 if (packet
== NULL
) {
774 /* may have already been flushed and freed */
775 ath6kl_err("HTC TX lookup failed!\n");
777 /* will be giving this buffer back to upper layers */
779 send_packet_completion(target
, packet
);
783 if (!ep
->pipe
.tx_credit_flow_enabled
) {
785 * note: when using TX credit flow, the re-checking of queues
786 * happens when credits flow back from the target. in the
787 * non-TX credit case, we recheck after the packet completes
789 htc_try_send(target
, ep
, NULL
);
795 static int htc_send_packets_multiple(struct htc_target
*target
,
796 struct list_head
*pkt_queue
)
798 struct htc_endpoint
*ep
;
799 struct htc_packet
*packet
, *tmp_pkt
;
801 if (list_empty(pkt_queue
))
804 /* get first packet to find out which ep the packets will go into */
805 packet
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
809 if (packet
->endpoint
>= ENDPOINT_MAX
) {
813 ep
= &target
->endpoint
[packet
->endpoint
];
815 htc_try_send(target
, ep
, pkt_queue
);
817 /* do completion on any packets that couldn't get in */
818 if (!list_empty(pkt_queue
)) {
819 list_for_each_entry_safe(packet
, tmp_pkt
, pkt_queue
, list
) {
820 packet
->status
= -ENOMEM
;
823 do_send_completion(ep
, pkt_queue
);
829 /* htc pipe rx path */
830 static struct htc_packet
*alloc_htc_packet_container(struct htc_target
*target
)
832 struct htc_packet
*packet
;
833 spin_lock_bh(&target
->rx_lock
);
835 if (target
->pipe
.htc_packet_pool
== NULL
) {
836 spin_unlock_bh(&target
->rx_lock
);
840 packet
= target
->pipe
.htc_packet_pool
;
841 target
->pipe
.htc_packet_pool
= (struct htc_packet
*) packet
->list
.next
;
843 spin_unlock_bh(&target
->rx_lock
);
845 packet
->list
.next
= NULL
;
849 static void free_htc_packet_container(struct htc_target
*target
,
850 struct htc_packet
*packet
)
852 struct list_head
*lh
;
854 spin_lock_bh(&target
->rx_lock
);
856 if (target
->pipe
.htc_packet_pool
== NULL
) {
857 target
->pipe
.htc_packet_pool
= packet
;
858 packet
->list
.next
= NULL
;
860 lh
= (struct list_head
*) target
->pipe
.htc_packet_pool
;
861 packet
->list
.next
= lh
;
862 target
->pipe
.htc_packet_pool
= packet
;
865 spin_unlock_bh(&target
->rx_lock
);
868 static int htc_process_trailer(struct htc_target
*target
, u8
*buffer
,
869 int len
, enum htc_endpoint_id from_ep
)
871 struct htc_credit_report
*report
;
872 struct htc_record_hdr
*record
;
873 u8
*record_buf
, *orig_buf
;
874 int orig_len
, status
;
881 if (len
< sizeof(struct htc_record_hdr
)) {
886 /* these are byte aligned structs */
887 record
= (struct htc_record_hdr
*) buffer
;
888 len
-= sizeof(struct htc_record_hdr
);
889 buffer
+= sizeof(struct htc_record_hdr
);
891 if (record
->len
> len
) {
892 /* no room left in buffer for record */
893 ath6kl_dbg(ATH6KL_DBG_HTC
,
894 "invalid length: %d (id:%d) buffer has: %d bytes left\n",
895 record
->len
, record
->rec_id
, len
);
900 /* start of record follows the header */
903 switch (record
->rec_id
) {
904 case HTC_RECORD_CREDITS
:
905 if (record
->len
< sizeof(struct htc_credit_report
)) {
910 report
= (struct htc_credit_report
*) record_buf
;
911 htc_process_credit_report(target
, report
,
912 record
->len
/ sizeof(*report
),
916 ath6kl_dbg(ATH6KL_DBG_HTC
,
917 "unhandled record: id:%d length:%d\n",
918 record
->rec_id
, record
->len
);
925 /* advance buffer past this record for next time around */
926 buffer
+= record
->len
;
933 static void do_recv_completion(struct htc_endpoint
*ep
,
934 struct list_head
*queue_to_indicate
)
936 struct htc_packet
*packet
;
938 if (list_empty(queue_to_indicate
)) {
939 /* nothing to indicate */
943 /* using legacy EpRecv */
944 while (!list_empty(queue_to_indicate
)) {
945 packet
= list_first_entry(queue_to_indicate
,
946 struct htc_packet
, list
);
947 list_del(&packet
->list
);
948 ep
->ep_cb
.rx(ep
->target
, packet
);
954 static void recv_packet_completion(struct htc_target
*target
,
955 struct htc_endpoint
*ep
,
956 struct htc_packet
*packet
)
958 struct list_head container
;
959 INIT_LIST_HEAD(&container
);
960 list_add_tail(&packet
->list
, &container
);
963 do_recv_completion(ep
, &container
);
966 static int ath6kl_htc_pipe_rx_complete(struct ath6kl
*ar
, struct sk_buff
*skb
,
969 struct htc_target
*target
= ar
->htc_target
;
970 u8
*netdata
, *trailer
, hdr_info
;
971 struct htc_frame_hdr
*htc_hdr
;
972 u32 netlen
, trailerlen
= 0;
973 struct htc_packet
*packet
;
974 struct htc_endpoint
*ep
;
981 htc_hdr
= (struct htc_frame_hdr
*) netdata
;
983 ep
= &target
->endpoint
[htc_hdr
->eid
];
985 if (htc_hdr
->eid
>= ENDPOINT_MAX
) {
986 ath6kl_dbg(ATH6KL_DBG_HTC
,
987 "HTC Rx: invalid EndpointID=%d\n",
993 payload_len
= le16_to_cpu(get_unaligned(&htc_hdr
->payld_len
));
995 if (netlen
< (payload_len
+ HTC_HDR_LENGTH
)) {
996 ath6kl_dbg(ATH6KL_DBG_HTC
,
997 "HTC Rx: insufficient length, got:%d expected =%u\n",
998 netlen
, payload_len
+ HTC_HDR_LENGTH
);
1003 /* get flags to check for trailer */
1004 hdr_info
= htc_hdr
->flags
;
1005 if (hdr_info
& HTC_FLG_RX_TRAILER
) {
1006 /* extract the trailer length */
1007 hdr_info
= htc_hdr
->ctrl
[0];
1008 if ((hdr_info
< sizeof(struct htc_record_hdr
)) ||
1009 (hdr_info
> payload_len
)) {
1010 ath6kl_dbg(ATH6KL_DBG_HTC
,
1011 "invalid header: payloadlen should be %d, CB[0]: %d\n",
1012 payload_len
, hdr_info
);
1017 trailerlen
= hdr_info
;
1018 /* process trailer after hdr/apps payload */
1019 trailer
= (u8
*) htc_hdr
+ HTC_HDR_LENGTH
+
1020 payload_len
- hdr_info
;
1021 status
= htc_process_trailer(target
, trailer
, hdr_info
,
1027 if (((int) payload_len
- (int) trailerlen
) <= 0) {
1028 /* zero length packet with trailer, just drop these */
1032 if (htc_hdr
->eid
== ENDPOINT_0
) {
1033 /* handle HTC control message */
1034 if (target
->htc_flags
& HTC_OP_STATE_SETUP_COMPLETE
) {
1036 * fatal: target should not send unsolicited
1037 * messageson the endpoint 0
1039 ath6kl_dbg(ATH6KL_DBG_HTC
,
1040 "HTC ignores Rx Ctrl after setup complete\n");
1045 /* remove HTC header */
1046 skb_pull(skb
, HTC_HDR_LENGTH
);
1048 netdata
= skb
->data
;
1051 spin_lock_bh(&target
->rx_lock
);
1053 target
->pipe
.ctrl_response_valid
= true;
1054 target
->pipe
.ctrl_response_len
= min_t(int, netlen
,
1055 HTC_MAX_CTRL_MSG_LEN
);
1056 memcpy(target
->pipe
.ctrl_response_buf
, netdata
,
1057 target
->pipe
.ctrl_response_len
);
1059 spin_unlock_bh(&target
->rx_lock
);
1067 * TODO: the message based HIF architecture allocates net bufs
1068 * for recv packets since it bridges that HIF to upper layers,
1069 * which expects HTC packets, we form the packets here
1071 packet
= alloc_htc_packet_container(target
);
1072 if (packet
== NULL
) {
1078 packet
->endpoint
= htc_hdr
->eid
;
1079 packet
->pkt_cntxt
= skb
;
1081 /* TODO: for backwards compatibility */
1082 packet
->buf
= skb_push(skb
, 0) + HTC_HDR_LENGTH
;
1083 packet
->act_len
= netlen
- HTC_HDR_LENGTH
- trailerlen
;
1086 * TODO: this is a hack because the driver layer will set the
1087 * actual len of the skb again which will just double the len
1091 recv_packet_completion(target
, ep
, packet
);
1093 /* recover the packet container */
1094 free_htc_packet_container(target
, packet
);
1105 static void htc_flush_rx_queue(struct htc_target
*target
,
1106 struct htc_endpoint
*ep
)
1108 struct list_head container
;
1109 struct htc_packet
*packet
;
1111 spin_lock_bh(&target
->rx_lock
);
1114 if (list_empty(&ep
->rx_bufq
))
1117 packet
= list_first_entry(&ep
->rx_bufq
,
1118 struct htc_packet
, list
);
1119 list_del(&packet
->list
);
1121 spin_unlock_bh(&target
->rx_lock
);
1122 packet
->status
= -ECANCELED
;
1123 packet
->act_len
= 0;
1125 ath6kl_dbg(ATH6KL_DBG_HTC
,
1126 "Flushing RX packet:0x%p, length:%d, ep:%d\n",
1127 packet
, packet
->buf_len
,
1130 INIT_LIST_HEAD(&container
);
1131 list_add_tail(&packet
->list
, &container
);
1133 /* give the packet back */
1134 do_recv_completion(ep
, &container
);
1135 spin_lock_bh(&target
->rx_lock
);
1138 spin_unlock_bh(&target
->rx_lock
);
1141 /* polling routine to wait for a control packet to be received */
1142 static int htc_wait_recv_ctrl_message(struct htc_target
*target
)
1144 int count
= HTC_TARGET_RESPONSE_POLL_COUNT
;
1147 spin_lock_bh(&target
->rx_lock
);
1149 if (target
->pipe
.ctrl_response_valid
) {
1150 target
->pipe
.ctrl_response_valid
= false;
1151 spin_unlock_bh(&target
->rx_lock
);
1155 spin_unlock_bh(&target
->rx_lock
);
1159 msleep_interruptible(HTC_TARGET_RESPONSE_POLL_WAIT
);
1163 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: Timeout!\n", __func__
);
1170 static void htc_rxctrl_complete(struct htc_target
*context
,
1171 struct htc_packet
*packet
)
1173 /* TODO, can't really receive HTC control messages yet.... */
1174 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: invalid call function\n", __func__
);
1177 /* htc pipe initialization */
1178 static void reset_endpoint_states(struct htc_target
*target
)
1180 struct htc_endpoint
*ep
;
1183 for (i
= ENDPOINT_0
; i
< ENDPOINT_MAX
; i
++) {
1184 ep
= &target
->endpoint
[i
];
1187 ep
->max_txq_depth
= 0;
1189 INIT_LIST_HEAD(&ep
->txq
);
1190 INIT_LIST_HEAD(&ep
->pipe
.tx_lookup_queue
);
1191 INIT_LIST_HEAD(&ep
->rx_bufq
);
1192 ep
->target
= target
;
1193 ep
->pipe
.tx_credit_flow_enabled
= (bool) 1; /* FIXME */
1197 /* start HTC, this is called after all services are connected */
1198 static int htc_config_target_hif_pipe(struct htc_target
*target
)
1203 /* htc service functions */
1204 static u8
htc_get_credit_alloc(struct htc_target
*target
, u16 service_id
)
1209 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
1210 if (target
->pipe
.txcredit_alloc
[i
].service_id
== service_id
)
1212 target
->pipe
.txcredit_alloc
[i
].credit_alloc
;
1215 if (allocation
== 0) {
1216 ath6kl_dbg(ATH6KL_DBG_HTC
,
1217 "HTC Service TX : 0x%2.2X : allocation is zero!\n",
1224 static int ath6kl_htc_pipe_conn_service(struct htc_target
*target
,
1225 struct htc_service_connect_req
*conn_req
,
1226 struct htc_service_connect_resp
*conn_resp
)
1228 struct ath6kl
*ar
= target
->dev
->ar
;
1229 struct htc_packet
*packet
= NULL
;
1230 struct htc_conn_service_resp
*resp_msg
;
1231 struct htc_conn_service_msg
*conn_msg
;
1232 enum htc_endpoint_id assigned_epid
= ENDPOINT_MAX
;
1233 bool disable_credit_flowctrl
= false;
1234 unsigned int max_msg_size
= 0;
1235 struct htc_endpoint
*ep
;
1236 int length
, status
= 0;
1237 struct sk_buff
*skb
;
1241 if (conn_req
->svc_id
== 0) {
1247 if (conn_req
->svc_id
== HTC_CTRL_RSVD_SVC
) {
1248 /* special case for pseudo control service */
1249 assigned_epid
= ENDPOINT_0
;
1250 max_msg_size
= HTC_MAX_CTRL_MSG_LEN
;
1255 tx_alloc
= htc_get_credit_alloc(target
, conn_req
->svc_id
);
1256 if (tx_alloc
== 0) {
1261 /* allocate a packet to send to the target */
1262 packet
= htc_alloc_txctrl_packet(target
);
1264 if (packet
== NULL
) {
1271 length
= sizeof(struct htc_conn_service_msg
);
1273 /* assemble connect service message */
1274 conn_msg
= (struct htc_conn_service_msg
*) skb_put(skb
,
1276 if (conn_msg
== NULL
) {
1283 sizeof(struct htc_conn_service_msg
));
1284 conn_msg
->msg_id
= cpu_to_le16(HTC_MSG_CONN_SVC_ID
);
1285 conn_msg
->svc_id
= cpu_to_le16(conn_req
->svc_id
);
1286 conn_msg
->conn_flags
= cpu_to_le16(conn_req
->conn_flags
&
1287 ~HTC_CONN_FLGS_SET_RECV_ALLOC_MASK
);
1289 /* tell target desired recv alloc for this ep */
1290 flags
= tx_alloc
<< HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT
;
1291 conn_msg
->conn_flags
|= cpu_to_le16(flags
);
1293 if (conn_req
->conn_flags
&
1294 HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL
) {
1295 disable_credit_flowctrl
= true;
1298 set_htc_pkt_info(packet
, NULL
, (u8
*) conn_msg
,
1300 ENDPOINT_0
, HTC_SERVICE_TX_PACKET_TAG
);
1302 status
= ath6kl_htc_pipe_tx(target
, packet
);
1304 /* we don't own it anymore */
1309 /* wait for response */
1310 status
= htc_wait_recv_ctrl_message(target
);
1314 /* we controlled the buffer creation so it has to be
1317 resp_msg
= (struct htc_conn_service_resp
*)
1318 target
->pipe
.ctrl_response_buf
;
1320 if (resp_msg
->msg_id
!= cpu_to_le16(HTC_MSG_CONN_SVC_RESP_ID
) ||
1321 (target
->pipe
.ctrl_response_len
< sizeof(*resp_msg
))) {
1322 /* this message is not valid */
1328 ath6kl_dbg(ATH6KL_DBG_TRC
,
1329 "%s: service 0x%X conn resp: status: %d ep: %d\n",
1330 __func__
, resp_msg
->svc_id
, resp_msg
->status
,
1333 conn_resp
->resp_code
= resp_msg
->status
;
1334 /* check response status */
1335 if (resp_msg
->status
!= HTC_SERVICE_SUCCESS
) {
1336 ath6kl_dbg(ATH6KL_DBG_HTC
,
1337 "Target failed service 0x%X connect request (status:%d)\n",
1338 resp_msg
->svc_id
, resp_msg
->status
);
1343 assigned_epid
= (enum htc_endpoint_id
) resp_msg
->eid
;
1344 max_msg_size
= le16_to_cpu(resp_msg
->max_msg_sz
);
1347 /* the rest are parameter checks so set the error status */
1350 if (assigned_epid
>= ENDPOINT_MAX
) {
1355 if (max_msg_size
== 0) {
1360 ep
= &target
->endpoint
[assigned_epid
];
1361 ep
->eid
= assigned_epid
;
1362 if (ep
->svc_id
!= 0) {
1363 /* endpoint already in use! */
1368 /* return assigned endpoint to caller */
1369 conn_resp
->endpoint
= assigned_epid
;
1370 conn_resp
->len_max
= max_msg_size
;
1372 /* setup the endpoint */
1373 ep
->svc_id
= conn_req
->svc_id
; /* this marks ep in use */
1374 ep
->max_txq_depth
= conn_req
->max_txq_depth
;
1375 ep
->len_max
= max_msg_size
;
1376 ep
->cred_dist
.credits
= tx_alloc
;
1377 ep
->cred_dist
.cred_sz
= target
->tgt_cred_sz
;
1378 ep
->cred_dist
.cred_per_msg
= max_msg_size
/ target
->tgt_cred_sz
;
1379 if (max_msg_size
% target
->tgt_cred_sz
)
1380 ep
->cred_dist
.cred_per_msg
++;
1382 /* copy all the callbacks */
1383 ep
->ep_cb
= conn_req
->ep_cb
;
1385 status
= ath6kl_hif_pipe_map_service(ar
, ep
->svc_id
,
1386 &ep
->pipe
.pipeid_ul
,
1387 &ep
->pipe
.pipeid_dl
);
1391 ath6kl_dbg(ATH6KL_DBG_HTC
,
1392 "SVC Ready: 0x%4.4X: ULpipe:%d DLpipe:%d id:%d\n",
1393 ep
->svc_id
, ep
->pipe
.pipeid_ul
,
1394 ep
->pipe
.pipeid_dl
, ep
->eid
);
1396 if (disable_credit_flowctrl
&& ep
->pipe
.tx_credit_flow_enabled
) {
1397 ep
->pipe
.tx_credit_flow_enabled
= false;
1398 ath6kl_dbg(ATH6KL_DBG_HTC
,
1399 "SVC: 0x%4.4X ep:%d TX flow control off\n",
1400 ep
->svc_id
, assigned_epid
);
1405 htc_free_txctrl_packet(target
, packet
);
1409 /* htc export functions */
1410 static void *ath6kl_htc_pipe_create(struct ath6kl
*ar
)
1413 struct htc_endpoint
*ep
= NULL
;
1414 struct htc_target
*target
= NULL
;
1415 struct htc_packet
*packet
;
1418 target
= kzalloc(sizeof(struct htc_target
), GFP_KERNEL
);
1419 if (target
== NULL
) {
1420 ath6kl_err("htc create unable to allocate memory\n");
1422 goto fail_htc_create
;
1425 spin_lock_init(&target
->htc_lock
);
1426 spin_lock_init(&target
->rx_lock
);
1427 spin_lock_init(&target
->tx_lock
);
1429 reset_endpoint_states(target
);
1431 for (i
= 0; i
< HTC_PACKET_CONTAINER_ALLOCATION
; i
++) {
1432 packet
= kzalloc(sizeof(struct htc_packet
), GFP_KERNEL
);
1435 free_htc_packet_container(target
, packet
);
1438 target
->dev
= kzalloc(sizeof(*target
->dev
), GFP_KERNEL
);
1440 ath6kl_err("unable to allocate memory\n");
1442 goto fail_htc_create
;
1444 target
->dev
->ar
= ar
;
1445 target
->dev
->htc_cnxt
= target
;
1447 /* Get HIF default pipe for HTC message exchange */
1448 ep
= &target
->endpoint
[ENDPOINT_0
];
1450 ath6kl_hif_pipe_get_default(ar
, &ep
->pipe
.pipeid_ul
,
1451 &ep
->pipe
.pipeid_dl
);
1458 ath6kl_htc_pipe_cleanup(target
);
1465 /* cleanup the HTC instance */
1466 static void ath6kl_htc_pipe_cleanup(struct htc_target
*target
)
1468 struct htc_packet
*packet
;
1471 packet
= alloc_htc_packet_container(target
);
1479 /* kfree our instance */
1483 static int ath6kl_htc_pipe_start(struct htc_target
*target
)
1485 struct sk_buff
*skb
;
1486 struct htc_setup_comp_ext_msg
*setup
;
1487 struct htc_packet
*packet
;
1489 htc_config_target_hif_pipe(target
);
1491 /* allocate a buffer to send */
1492 packet
= htc_alloc_txctrl_packet(target
);
1493 if (packet
== NULL
) {
1500 /* assemble setup complete message */
1501 setup
= (struct htc_setup_comp_ext_msg
*) skb_put(skb
,
1503 memset(setup
, 0, sizeof(struct htc_setup_comp_ext_msg
));
1504 setup
->msg_id
= cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID
);
1506 ath6kl_dbg(ATH6KL_DBG_HTC
, "HTC using TX credit flow control\n");
1508 set_htc_pkt_info(packet
, NULL
, (u8
*) setup
,
1509 sizeof(struct htc_setup_comp_ext_msg
),
1510 ENDPOINT_0
, HTC_SERVICE_TX_PACKET_TAG
);
1512 target
->htc_flags
|= HTC_OP_STATE_SETUP_COMPLETE
;
1514 return ath6kl_htc_pipe_tx(target
, packet
);
1517 static void ath6kl_htc_pipe_stop(struct htc_target
*target
)
1520 struct htc_endpoint
*ep
;
1522 /* cleanup endpoints */
1523 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
1524 ep
= &target
->endpoint
[i
];
1525 htc_flush_rx_queue(target
, ep
);
1526 htc_flush_tx_endpoint(target
, ep
, HTC_TX_PACKET_TAG_ALL
);
1529 reset_endpoint_states(target
);
1530 target
->htc_flags
&= ~HTC_OP_STATE_SETUP_COMPLETE
;
1533 static int ath6kl_htc_pipe_get_rxbuf_num(struct htc_target
*target
,
1534 enum htc_endpoint_id endpoint
)
1538 spin_lock_bh(&target
->rx_lock
);
1539 num
= get_queue_depth(&(target
->endpoint
[endpoint
].rx_bufq
));
1540 spin_unlock_bh(&target
->rx_lock
);
1545 static int ath6kl_htc_pipe_tx(struct htc_target
*target
,
1546 struct htc_packet
*packet
)
1548 struct list_head queue
;
1550 ath6kl_dbg(ATH6KL_DBG_HTC
,
1551 "%s: endPointId: %d, buffer: 0x%p, length: %d\n",
1552 __func__
, packet
->endpoint
, packet
->buf
,
1555 INIT_LIST_HEAD(&queue
);
1556 list_add_tail(&packet
->list
, &queue
);
1558 return htc_send_packets_multiple(target
, &queue
);
1561 static int ath6kl_htc_pipe_wait_target(struct htc_target
*target
)
1563 struct htc_ready_ext_msg
*ready_msg
;
1564 struct htc_service_connect_req connect
;
1565 struct htc_service_connect_resp resp
;
1568 status
= htc_wait_recv_ctrl_message(target
);
1573 if (target
->pipe
.ctrl_response_len
< sizeof(*ready_msg
)) {
1574 ath6kl_dbg(ATH6KL_DBG_HTC
, "invalid htc ready msg len:%d!\n",
1575 target
->pipe
.ctrl_response_len
);
1579 ready_msg
= (struct htc_ready_ext_msg
*) target
->pipe
.ctrl_response_buf
;
1581 if (ready_msg
->ver2_0_info
.msg_id
!= cpu_to_le16(HTC_MSG_READY_ID
)) {
1582 ath6kl_dbg(ATH6KL_DBG_HTC
, "invalid htc ready msg : 0x%X !\n",
1583 ready_msg
->ver2_0_info
.msg_id
);
1587 ath6kl_dbg(ATH6KL_DBG_HTC
,
1588 "Target Ready! : transmit resources : %d size:%d\n",
1589 ready_msg
->ver2_0_info
.cred_cnt
,
1590 ready_msg
->ver2_0_info
.cred_sz
);
1592 target
->tgt_creds
= le16_to_cpu(ready_msg
->ver2_0_info
.cred_cnt
);
1593 target
->tgt_cred_sz
= le16_to_cpu(ready_msg
->ver2_0_info
.cred_sz
);
1595 if ((target
->tgt_creds
== 0) || (target
->tgt_cred_sz
== 0))
1598 htc_setup_target_buffer_assignments(target
);
1600 /* setup our pseudo HTC control endpoint connection */
1601 memset(&connect
, 0, sizeof(connect
));
1602 memset(&resp
, 0, sizeof(resp
));
1603 connect
.ep_cb
.tx_complete
= htc_txctrl_complete
;
1604 connect
.ep_cb
.rx
= htc_rxctrl_complete
;
1605 connect
.max_txq_depth
= NUM_CONTROL_TX_BUFFERS
;
1606 connect
.svc_id
= HTC_CTRL_RSVD_SVC
;
1608 /* connect fake service */
1609 status
= ath6kl_htc_pipe_conn_service(target
, &connect
, &resp
);
1614 static void ath6kl_htc_pipe_flush_txep(struct htc_target
*target
,
1615 enum htc_endpoint_id endpoint
, u16 tag
)
1617 struct htc_endpoint
*ep
= &target
->endpoint
[endpoint
];
1619 if (ep
->svc_id
== 0) {
1625 htc_flush_tx_endpoint(target
, ep
, tag
);
1628 static int ath6kl_htc_pipe_add_rxbuf_multiple(struct htc_target
*target
,
1629 struct list_head
*pkt_queue
)
1631 struct htc_packet
*packet
, *tmp_pkt
, *first
;
1632 struct htc_endpoint
*ep
;
1635 if (list_empty(pkt_queue
))
1638 first
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
1639 if (first
== NULL
) {
1644 if (first
->endpoint
>= ENDPOINT_MAX
) {
1649 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: epid: %d, cnt:%d, len: %d\n",
1650 __func__
, first
->endpoint
, get_queue_depth(pkt_queue
),
1653 ep
= &target
->endpoint
[first
->endpoint
];
1655 spin_lock_bh(&target
->rx_lock
);
1657 /* store receive packets */
1658 list_splice_tail_init(pkt_queue
, &ep
->rx_bufq
);
1660 spin_unlock_bh(&target
->rx_lock
);
1663 /* walk through queue and mark each one canceled */
1664 list_for_each_entry_safe(packet
, tmp_pkt
, pkt_queue
, list
) {
1665 packet
->status
= -ECANCELED
;
1668 do_recv_completion(ep
, pkt_queue
);
1674 static void ath6kl_htc_pipe_activity_changed(struct htc_target
*target
,
1675 enum htc_endpoint_id ep
,
1681 static void ath6kl_htc_pipe_flush_rx_buf(struct htc_target
*target
)
1686 static int ath6kl_htc_pipe_credit_setup(struct htc_target
*target
,
1687 struct ath6kl_htc_credit_info
*info
)
1692 static const struct ath6kl_htc_ops ath6kl_htc_pipe_ops
= {
1693 .create
= ath6kl_htc_pipe_create
,
1694 .wait_target
= ath6kl_htc_pipe_wait_target
,
1695 .start
= ath6kl_htc_pipe_start
,
1696 .conn_service
= ath6kl_htc_pipe_conn_service
,
1697 .tx
= ath6kl_htc_pipe_tx
,
1698 .stop
= ath6kl_htc_pipe_stop
,
1699 .cleanup
= ath6kl_htc_pipe_cleanup
,
1700 .flush_txep
= ath6kl_htc_pipe_flush_txep
,
1701 .flush_rx_buf
= ath6kl_htc_pipe_flush_rx_buf
,
1702 .activity_changed
= ath6kl_htc_pipe_activity_changed
,
1703 .get_rxbuf_num
= ath6kl_htc_pipe_get_rxbuf_num
,
1704 .add_rxbuf_multiple
= ath6kl_htc_pipe_add_rxbuf_multiple
,
1705 .credit_setup
= ath6kl_htc_pipe_credit_setup
,
1706 .tx_complete
= ath6kl_htc_pipe_tx_complete
,
1707 .rx_complete
= ath6kl_htc_pipe_rx_complete
,
1710 void ath6kl_htc_pipe_attach(struct ath6kl
*ar
)
1712 ar
->htc_ops
= &ath6kl_htc_pipe_ops
;