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
);
112 ath6kl_dbg(ATH6KL_DBG_HTC
,
113 "%s: got head packet:0x%p , queue depth: %d\n",
114 __func__
, packet
, get_queue_depth(&ep
->txq
));
116 transfer_len
= packet
->act_len
+ HTC_HDR_LENGTH
;
118 if (transfer_len
<= target
->tgt_cred_sz
) {
119 credits_required
= 1;
121 /* figure out how many credits this message requires */
122 credits_required
= transfer_len
/ target
->tgt_cred_sz
;
123 remainder
= transfer_len
% target
->tgt_cred_sz
;
129 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: creds required:%d got:%d\n",
130 __func__
, credits_required
, ep
->cred_dist
.credits
);
132 if (ep
->eid
== ENDPOINT_0
) {
134 * endpoint 0 is special, it always has a credit and
135 * does not require credit based flow control
137 credits_required
= 0;
140 if (ep
->cred_dist
.credits
< credits_required
)
143 ep
->cred_dist
.credits
-= credits_required
;
144 ep
->ep_st
.cred_cosumd
+= credits_required
;
146 /* check if we need credits back from the target */
147 if (ep
->cred_dist
.credits
<
148 ep
->cred_dist
.cred_per_msg
) {
149 /* tell the target we need credits ASAP! */
150 send_flags
|= HTC_FLAGS_NEED_CREDIT_UPDATE
;
151 ep
->ep_st
.cred_low_indicate
+= 1;
152 ath6kl_dbg(ATH6KL_DBG_HTC
,
153 "%s: host needs credits\n",
158 /* now we can fully dequeue */
159 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
161 list_del(&packet
->list
);
162 /* save the number of credits this packet consumed */
163 packet
->info
.tx
.cred_used
= credits_required
;
164 /* save send flags */
165 packet
->info
.tx
.flags
= send_flags
;
166 packet
->info
.tx
.seqno
= ep
->seqno
;
168 /* queue this packet into the caller's queue */
169 list_add_tail(&packet
->list
, queue
);
173 static void get_htc_packet(struct htc_target
*target
,
174 struct htc_endpoint
*ep
,
175 struct list_head
*queue
, int resources
)
177 struct htc_packet
*packet
;
179 /* NOTE : the TX lock is held when this function is called */
181 /* loop until we can grab as many packets out of the queue as we can */
183 if (list_empty(&ep
->txq
))
186 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
187 list_del(&packet
->list
);
189 ath6kl_dbg(ATH6KL_DBG_HTC
,
190 "%s: got packet:0x%p , new queue depth: %d\n",
191 __func__
, packet
, get_queue_depth(&ep
->txq
));
192 packet
->info
.tx
.seqno
= ep
->seqno
;
193 packet
->info
.tx
.flags
= 0;
194 packet
->info
.tx
.cred_used
= 0;
197 /* queue this packet into the caller's queue */
198 list_add_tail(&packet
->list
, queue
);
203 static int htc_issue_packets(struct htc_target
*target
,
204 struct htc_endpoint
*ep
,
205 struct list_head
*pkt_queue
)
210 struct htc_frame_hdr
*htc_hdr
;
211 struct htc_packet
*packet
;
213 ath6kl_dbg(ATH6KL_DBG_HTC
,
214 "%s: queue: 0x%p, pkts %d\n", __func__
,
215 pkt_queue
, get_queue_depth(pkt_queue
));
217 while (!list_empty(pkt_queue
)) {
218 packet
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
219 list_del(&packet
->list
);
228 payload_len
= packet
->act_len
;
230 /* setup HTC frame header */
231 htc_hdr
= (struct htc_frame_hdr
*) skb_push(skb
,
239 packet
->info
.tx
.flags
|= HTC_FLAGS_TX_FIXUP_NETBUF
;
242 put_unaligned((u16
) payload_len
, &htc_hdr
->payld_len
);
243 htc_hdr
->flags
= packet
->info
.tx
.flags
;
244 htc_hdr
->eid
= (u8
) packet
->endpoint
;
245 htc_hdr
->ctrl
[0] = 0;
246 htc_hdr
->ctrl
[1] = (u8
) packet
->info
.tx
.seqno
;
248 spin_lock_bh(&target
->tx_lock
);
250 /* store in look up queue to match completions */
251 list_add_tail(&packet
->list
, &ep
->pipe
.tx_lookup_queue
);
252 ep
->ep_st
.tx_issued
+= 1;
253 spin_unlock_bh(&target
->tx_lock
);
255 status
= ath6kl_hif_pipe_send(target
->dev
->ar
,
256 ep
->pipe
.pipeid_ul
, NULL
, skb
);
259 if (status
!= -ENOMEM
) {
260 /* TODO: if more than 1 endpoint maps to the
261 * same PipeID, it is possible to run out of
262 * resources in the HIF layer.
263 * Don't emit the error
265 ath6kl_dbg(ATH6KL_DBG_HTC
,
266 "%s: failed status:%d\n",
269 spin_lock_bh(&target
->tx_lock
);
270 list_del(&packet
->list
);
272 /* reclaim credits */
273 ep
->cred_dist
.credits
+= packet
->info
.tx
.cred_used
;
274 spin_unlock_bh(&target
->tx_lock
);
276 /* put it back into the callers queue */
277 list_add(&packet
->list
, pkt_queue
);
283 while (!list_empty(pkt_queue
)) {
284 if (status
!= -ENOMEM
) {
285 ath6kl_dbg(ATH6KL_DBG_HTC
,
286 "%s: failed pkt:0x%p status:%d\n",
287 __func__
, packet
, status
);
290 packet
= list_first_entry(pkt_queue
,
291 struct htc_packet
, list
);
292 list_del(&packet
->list
);
293 packet
->status
= status
;
294 send_packet_completion(target
, packet
);
301 static enum htc_send_queue_result
htc_try_send(struct htc_target
*target
,
302 struct htc_endpoint
*ep
,
303 struct list_head
*txq
)
305 struct list_head send_queue
; /* temp queue to hold packets */
306 struct htc_packet
*packet
, *tmp_pkt
;
307 struct ath6kl
*ar
= target
->dev
->ar
;
308 enum htc_send_full_action action
;
309 int tx_resources
, overflow
, txqueue_depth
, i
, good_pkts
;
312 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: (queue:0x%p depth:%d)\n",
314 (txq
== NULL
) ? 0 : get_queue_depth(txq
));
316 /* init the local send queue */
317 INIT_LIST_HEAD(&send_queue
);
320 * txq equals to NULL means
321 * caller didn't provide a queue, just wants us to
322 * check queues and send
325 if (list_empty(txq
)) {
327 return HTC_SEND_QUEUE_DROP
;
330 spin_lock_bh(&target
->tx_lock
);
331 txqueue_depth
= get_queue_depth(&ep
->txq
);
332 spin_unlock_bh(&target
->tx_lock
);
334 if (txqueue_depth
>= ep
->max_txq_depth
) {
335 /* we've already overflowed */
336 overflow
= get_queue_depth(txq
);
338 /* get how much we will overflow by */
339 overflow
= txqueue_depth
;
340 overflow
+= get_queue_depth(txq
);
341 /* get how much we will overflow the TX queue by */
342 overflow
-= ep
->max_txq_depth
;
345 /* if overflow is negative or zero, we are okay */
347 ath6kl_dbg(ATH6KL_DBG_HTC
,
348 "%s: Endpoint %d, TX queue will overflow :%d, Tx Depth:%d, Max:%d\n",
349 __func__
, ep
->eid
, overflow
, txqueue_depth
,
352 if ((overflow
<= 0) ||
353 (ep
->ep_cb
.tx_full
== NULL
)) {
355 * all packets will fit or caller did not provide send
356 * full indication handler -- just move all of them
357 * to the local send_queue object
359 list_splice_tail_init(txq
, &send_queue
);
361 good_pkts
= get_queue_depth(txq
) - overflow
;
364 return HTC_SEND_QUEUE_DROP
;
367 /* we have overflowed, and a callback is provided */
368 /* dequeue all non-overflow packets to the sendqueue */
369 for (i
= 0; i
< good_pkts
; i
++) {
370 /* pop off caller's queue */
371 packet
= list_first_entry(txq
,
374 /* move to local queue */
375 list_move_tail(&packet
->list
, &send_queue
);
379 * the caller's queue has all the packets that won't fit
380 * walk through the caller's queue and indicate each to
381 * the send full handler
383 list_for_each_entry_safe(packet
, tmp_pkt
,
385 ath6kl_dbg(ATH6KL_DBG_HTC
,
386 "%s: Indicat overflowed TX pkts: %p\n",
388 action
= ep
->ep_cb
.tx_full(ep
->target
, packet
);
389 if (action
== HTC_SEND_FULL_DROP
) {
390 /* callback wants the packet dropped */
391 ep
->ep_st
.tx_dropped
+= 1;
393 /* leave this one in the caller's queue
396 /* callback wants to keep this packet,
397 * move from caller's queue to the send
399 list_move_tail(&packet
->list
,
404 if (list_empty(&send_queue
)) {
405 /* no packets made it in, caller will cleanup */
406 return HTC_SEND_QUEUE_DROP
;
411 if (!ep
->pipe
.tx_credit_flow_enabled
) {
413 ath6kl_hif_pipe_get_free_queue_number(ar
,
419 spin_lock_bh(&target
->tx_lock
);
420 if (!list_empty(&send_queue
)) {
421 /* transfer packets to tail */
422 list_splice_tail_init(&send_queue
, &ep
->txq
);
423 if (!list_empty(&send_queue
)) {
425 spin_unlock_bh(&target
->tx_lock
);
426 return HTC_SEND_QUEUE_DROP
;
428 INIT_LIST_HEAD(&send_queue
);
431 /* increment tx processing count on entry */
434 if (ep
->tx_proc_cnt
> 1) {
436 * Another thread or task is draining the TX queues on this
437 * endpoint that thread will reset the tx processing count
438 * when the queue is drained.
441 spin_unlock_bh(&target
->tx_lock
);
442 return HTC_SEND_QUEUE_OK
;
445 /***** beyond this point only 1 thread may enter ******/
448 * Now drain the endpoint TX queue for transmission as long as we have
449 * enough transmit resources.
452 if (get_queue_depth(&ep
->txq
) == 0)
455 if (ep
->pipe
.tx_credit_flow_enabled
) {
457 * Credit based mechanism provides flow control
458 * based on target transmit resource availability,
459 * we assume that the HIF layer will always have
460 * bus resources greater than target transmit
463 get_htc_packet_credit_based(target
, ep
, &send_queue
);
466 * Get all packets for this endpoint that we can
469 get_htc_packet(target
, ep
, &send_queue
, tx_resources
);
472 if (get_queue_depth(&send_queue
) == 0) {
474 * Didn't get packets due to out of resources or TX
480 spin_unlock_bh(&target
->tx_lock
);
482 /* send what we can */
483 htc_issue_packets(target
, ep
, &send_queue
);
485 if (!ep
->pipe
.tx_credit_flow_enabled
) {
486 pipeid
= ep
->pipe
.pipeid_ul
;
488 ath6kl_hif_pipe_get_free_queue_number(ar
, pipeid
);
491 spin_lock_bh(&target
->tx_lock
);
494 /* done with this endpoint, we can clear the count */
496 spin_unlock_bh(&target
->tx_lock
);
498 return HTC_SEND_QUEUE_OK
;
501 /* htc control packet manipulation */
502 static void destroy_htc_txctrl_packet(struct htc_packet
*packet
)
510 static struct htc_packet
*build_htc_txctrl_packet(void)
512 struct htc_packet
*packet
= NULL
;
515 packet
= kzalloc(sizeof(struct htc_packet
), GFP_KERNEL
);
519 skb
= __dev_alloc_skb(HTC_CONTROL_BUFFER_SIZE
, GFP_KERNEL
);
530 static void htc_free_txctrl_packet(struct htc_target
*target
,
531 struct htc_packet
*packet
)
533 destroy_htc_txctrl_packet(packet
);
536 static struct htc_packet
*htc_alloc_txctrl_packet(struct htc_target
*target
)
538 return build_htc_txctrl_packet();
541 static void htc_txctrl_complete(struct htc_target
*target
,
542 struct htc_packet
*packet
)
544 htc_free_txctrl_packet(target
, packet
);
547 #define MAX_MESSAGE_SIZE 1536
549 static int htc_setup_target_buffer_assignments(struct htc_target
*target
)
551 int status
, credits
, credit_per_maxmsg
, i
;
552 struct htc_pipe_txcredit_alloc
*entry
;
553 unsigned int hif_usbaudioclass
= 0;
555 credit_per_maxmsg
= MAX_MESSAGE_SIZE
/ target
->tgt_cred_sz
;
556 if (MAX_MESSAGE_SIZE
% target
->tgt_cred_sz
)
559 /* TODO, this should be configured by the caller! */
561 credits
= target
->tgt_creds
;
562 entry
= &target
->pipe
.txcredit_alloc
[0];
566 /* FIXME: hif_usbaudioclass is always zero */
567 if (hif_usbaudioclass
) {
568 ath6kl_dbg(ATH6KL_DBG_HTC
,
569 "%s: For USB Audio Class- Total:%d\n",
573 /* Setup VO Service To have Max Credits */
574 entry
->service_id
= WMI_DATA_VO_SVC
;
575 entry
->credit_alloc
= (credits
- 6);
576 if (entry
->credit_alloc
== 0)
577 entry
->credit_alloc
++;
579 credits
-= (int) entry
->credit_alloc
;
584 entry
->service_id
= WMI_CONTROL_SVC
;
585 entry
->credit_alloc
= credit_per_maxmsg
;
586 credits
-= (int) entry
->credit_alloc
;
590 /* leftovers go to best effort */
593 entry
->service_id
= WMI_DATA_BE_SVC
;
594 entry
->credit_alloc
= (u8
) credits
;
598 entry
->service_id
= WMI_DATA_VI_SVC
;
599 entry
->credit_alloc
= credits
/ 4;
600 if (entry
->credit_alloc
== 0)
601 entry
->credit_alloc
++;
603 credits
-= (int) entry
->credit_alloc
;
608 entry
->service_id
= WMI_DATA_VO_SVC
;
609 entry
->credit_alloc
= credits
/ 4;
610 if (entry
->credit_alloc
== 0)
611 entry
->credit_alloc
++;
613 credits
-= (int) entry
->credit_alloc
;
618 entry
->service_id
= WMI_CONTROL_SVC
;
619 entry
->credit_alloc
= credit_per_maxmsg
;
620 credits
-= (int) entry
->credit_alloc
;
625 entry
->service_id
= WMI_DATA_BK_SVC
;
626 entry
->credit_alloc
= credit_per_maxmsg
;
627 credits
-= (int) entry
->credit_alloc
;
631 /* leftovers go to best effort */
633 entry
->service_id
= WMI_DATA_BE_SVC
;
634 entry
->credit_alloc
= (u8
) credits
;
639 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
640 if (target
->pipe
.txcredit_alloc
[i
].service_id
!= 0) {
641 ath6kl_dbg(ATH6KL_DBG_HTC
,
642 "HTC Service Index : %d TX : 0x%2.2X : alloc:%d\n",
644 target
->pipe
.txcredit_alloc
[i
].
646 target
->pipe
.txcredit_alloc
[i
].
654 /* process credit reports and call distribution function */
655 static void htc_process_credit_report(struct htc_target
*target
,
656 struct htc_credit_report
*rpt
,
658 enum htc_endpoint_id from_ep
)
660 int total_credits
= 0, i
;
661 struct htc_endpoint
*ep
;
663 /* lock out TX while we update credits */
664 spin_lock_bh(&target
->tx_lock
);
666 for (i
= 0; i
< num_entries
; i
++, rpt
++) {
667 if (rpt
->eid
>= ENDPOINT_MAX
) {
669 spin_unlock_bh(&target
->tx_lock
);
673 ep
= &target
->endpoint
[rpt
->eid
];
674 ep
->cred_dist
.credits
+= rpt
->credits
;
676 if (ep
->cred_dist
.credits
&& get_queue_depth(&ep
->txq
)) {
677 spin_unlock_bh(&target
->tx_lock
);
678 htc_try_send(target
, ep
, NULL
);
679 spin_lock_bh(&target
->tx_lock
);
682 total_credits
+= rpt
->credits
;
684 ath6kl_dbg(ATH6KL_DBG_HTC
,
685 "Report indicated %d credits to distribute\n",
688 spin_unlock_bh(&target
->tx_lock
);
691 /* flush endpoint TX queue */
692 static void htc_flush_tx_endpoint(struct htc_target
*target
,
693 struct htc_endpoint
*ep
, u16 tag
)
695 struct htc_packet
*packet
;
697 spin_lock_bh(&target
->tx_lock
);
698 while (get_queue_depth(&ep
->txq
)) {
699 packet
= list_first_entry(&ep
->txq
, struct htc_packet
, list
);
700 list_del(&packet
->list
);
702 send_packet_completion(target
, packet
);
704 spin_unlock_bh(&target
->tx_lock
);
708 * In the adapted HIF layer, struct sk_buff * are passed between HIF and HTC,
709 * since upper layers expects struct htc_packet containers we use the completed
710 * skb and lookup it's corresponding HTC packet buffer from a lookup list.
711 * This is extra overhead that can be fixed by re-aligning HIF interfaces with
714 static struct htc_packet
*htc_lookup_tx_packet(struct htc_target
*target
,
715 struct htc_endpoint
*ep
,
718 struct htc_packet
*packet
, *tmp_pkt
, *found_packet
= NULL
;
720 spin_lock_bh(&target
->tx_lock
);
723 * interate from the front of tx lookup queue
724 * this lookup should be fast since lower layers completes in-order and
725 * so the completed packet should be at the head of the list generally
727 list_for_each_entry_safe(packet
, tmp_pkt
, &ep
->pipe
.tx_lookup_queue
,
729 /* check for removal */
730 if (skb
== packet
->skb
) {
732 list_del(&packet
->list
);
733 found_packet
= packet
;
738 spin_unlock_bh(&target
->tx_lock
);
743 static int ath6kl_htc_pipe_tx_complete(struct ath6kl
*ar
, struct sk_buff
*skb
)
745 struct htc_target
*target
= ar
->htc_target
;
746 struct htc_frame_hdr
*htc_hdr
;
747 struct htc_endpoint
*ep
;
748 struct htc_packet
*packet
;
755 htc_hdr
= (struct htc_frame_hdr
*) netdata
;
757 ep_id
= htc_hdr
->eid
;
758 ep
= &target
->endpoint
[ep_id
];
760 packet
= htc_lookup_tx_packet(target
, ep
, skb
);
761 if (packet
== NULL
) {
762 /* may have already been flushed and freed */
763 ath6kl_err("HTC TX lookup failed!\n");
765 /* will be giving this buffer back to upper layers */
767 send_packet_completion(target
, packet
);
771 if (!ep
->pipe
.tx_credit_flow_enabled
) {
773 * note: when using TX credit flow, the re-checking of queues
774 * happens when credits flow back from the target. in the
775 * non-TX credit case, we recheck after the packet completes
777 htc_try_send(target
, ep
, NULL
);
783 static int htc_send_packets_multiple(struct htc_target
*target
,
784 struct list_head
*pkt_queue
)
786 struct htc_endpoint
*ep
;
787 struct htc_packet
*packet
, *tmp_pkt
;
789 if (list_empty(pkt_queue
))
792 /* get first packet to find out which ep the packets will go into */
793 packet
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
795 if (packet
->endpoint
>= ENDPOINT_MAX
) {
799 ep
= &target
->endpoint
[packet
->endpoint
];
801 htc_try_send(target
, ep
, pkt_queue
);
803 /* do completion on any packets that couldn't get in */
804 if (!list_empty(pkt_queue
)) {
805 list_for_each_entry_safe(packet
, tmp_pkt
, pkt_queue
, list
) {
806 packet
->status
= -ENOMEM
;
809 do_send_completion(ep
, pkt_queue
);
815 /* htc pipe rx path */
816 static struct htc_packet
*alloc_htc_packet_container(struct htc_target
*target
)
818 struct htc_packet
*packet
;
819 spin_lock_bh(&target
->rx_lock
);
821 if (target
->pipe
.htc_packet_pool
== NULL
) {
822 spin_unlock_bh(&target
->rx_lock
);
826 packet
= target
->pipe
.htc_packet_pool
;
827 target
->pipe
.htc_packet_pool
= (struct htc_packet
*) packet
->list
.next
;
829 spin_unlock_bh(&target
->rx_lock
);
831 packet
->list
.next
= NULL
;
835 static void free_htc_packet_container(struct htc_target
*target
,
836 struct htc_packet
*packet
)
838 struct list_head
*lh
;
840 spin_lock_bh(&target
->rx_lock
);
842 if (target
->pipe
.htc_packet_pool
== NULL
) {
843 target
->pipe
.htc_packet_pool
= packet
;
844 packet
->list
.next
= NULL
;
846 lh
= (struct list_head
*) target
->pipe
.htc_packet_pool
;
847 packet
->list
.next
= lh
;
848 target
->pipe
.htc_packet_pool
= packet
;
851 spin_unlock_bh(&target
->rx_lock
);
854 static int htc_process_trailer(struct htc_target
*target
, u8
*buffer
,
855 int len
, enum htc_endpoint_id from_ep
)
857 struct htc_credit_report
*report
;
858 struct htc_record_hdr
*record
;
859 u8
*record_buf
, *orig_buf
;
860 int orig_len
, status
;
867 if (len
< sizeof(struct htc_record_hdr
)) {
872 /* these are byte aligned structs */
873 record
= (struct htc_record_hdr
*) buffer
;
874 len
-= sizeof(struct htc_record_hdr
);
875 buffer
+= sizeof(struct htc_record_hdr
);
877 if (record
->len
> len
) {
878 /* no room left in buffer for record */
879 ath6kl_dbg(ATH6KL_DBG_HTC
,
880 "invalid length: %d (id:%d) buffer has: %d bytes left\n",
881 record
->len
, record
->rec_id
, len
);
886 /* start of record follows the header */
889 switch (record
->rec_id
) {
890 case HTC_RECORD_CREDITS
:
891 if (record
->len
< sizeof(struct htc_credit_report
)) {
896 report
= (struct htc_credit_report
*) record_buf
;
897 htc_process_credit_report(target
, report
,
898 record
->len
/ sizeof(*report
),
902 ath6kl_dbg(ATH6KL_DBG_HTC
,
903 "unhandled record: id:%d length:%d\n",
904 record
->rec_id
, record
->len
);
911 /* advance buffer past this record for next time around */
912 buffer
+= record
->len
;
919 static void do_recv_completion(struct htc_endpoint
*ep
,
920 struct list_head
*queue_to_indicate
)
922 struct htc_packet
*packet
;
924 if (list_empty(queue_to_indicate
)) {
925 /* nothing to indicate */
929 /* using legacy EpRecv */
930 while (!list_empty(queue_to_indicate
)) {
931 packet
= list_first_entry(queue_to_indicate
,
932 struct htc_packet
, list
);
933 list_del(&packet
->list
);
934 ep
->ep_cb
.rx(ep
->target
, packet
);
940 static void recv_packet_completion(struct htc_target
*target
,
941 struct htc_endpoint
*ep
,
942 struct htc_packet
*packet
)
944 struct list_head container
;
945 INIT_LIST_HEAD(&container
);
946 list_add_tail(&packet
->list
, &container
);
949 do_recv_completion(ep
, &container
);
952 static int ath6kl_htc_pipe_rx_complete(struct ath6kl
*ar
, struct sk_buff
*skb
,
955 struct htc_target
*target
= ar
->htc_target
;
956 u8
*netdata
, *trailer
, hdr_info
;
957 struct htc_frame_hdr
*htc_hdr
;
958 u32 netlen
, trailerlen
= 0;
959 struct htc_packet
*packet
;
960 struct htc_endpoint
*ep
;
965 * ar->htc_target can be NULL due to a race condition that can occur
966 * during driver initialization(we do 'ath6kl_hif_power_on' before
967 * initializing 'ar->htc_target' via 'ath6kl_htc_create').
968 * 'ath6kl_hif_power_on' assigns 'ath6kl_recv_complete' as
969 * usb_complete_t/callback function for 'usb_fill_bulk_urb'.
970 * Thus the possibility of ar->htc_target being NULL
971 * via ath6kl_recv_complete -> ath6kl_usb_io_comp_work.
973 if (WARN_ON_ONCE(!target
)) {
974 ath6kl_err("Target not yet initialized\n");
983 htc_hdr
= (struct htc_frame_hdr
*) netdata
;
985 if (htc_hdr
->eid
>= ENDPOINT_MAX
) {
986 ath6kl_dbg(ATH6KL_DBG_HTC
,
987 "HTC Rx: invalid EndpointID=%d\n",
992 ep
= &target
->endpoint
[htc_hdr
->eid
];
994 payload_len
= le16_to_cpu(get_unaligned(&htc_hdr
->payld_len
));
996 if (netlen
< (payload_len
+ HTC_HDR_LENGTH
)) {
997 ath6kl_dbg(ATH6KL_DBG_HTC
,
998 "HTC Rx: insufficient length, got:%d expected =%u\n",
999 netlen
, payload_len
+ HTC_HDR_LENGTH
);
1004 /* get flags to check for trailer */
1005 hdr_info
= htc_hdr
->flags
;
1006 if (hdr_info
& HTC_FLG_RX_TRAILER
) {
1007 /* extract the trailer length */
1008 hdr_info
= htc_hdr
->ctrl
[0];
1009 if ((hdr_info
< sizeof(struct htc_record_hdr
)) ||
1010 (hdr_info
> payload_len
)) {
1011 ath6kl_dbg(ATH6KL_DBG_HTC
,
1012 "invalid header: payloadlen should be %d, CB[0]: %d\n",
1013 payload_len
, hdr_info
);
1018 trailerlen
= hdr_info
;
1019 /* process trailer after hdr/apps payload */
1020 trailer
= (u8
*) htc_hdr
+ HTC_HDR_LENGTH
+
1021 payload_len
- hdr_info
;
1022 status
= htc_process_trailer(target
, trailer
, hdr_info
,
1028 if (((int) payload_len
- (int) trailerlen
) <= 0) {
1029 /* zero length packet with trailer, just drop these */
1033 if (htc_hdr
->eid
== ENDPOINT_0
) {
1034 /* handle HTC control message */
1035 if (target
->htc_flags
& HTC_OP_STATE_SETUP_COMPLETE
) {
1037 * fatal: target should not send unsolicited
1038 * messageson the endpoint 0
1040 ath6kl_dbg(ATH6KL_DBG_HTC
,
1041 "HTC ignores Rx Ctrl after setup complete\n");
1046 /* remove HTC header */
1047 skb_pull(skb
, HTC_HDR_LENGTH
);
1049 netdata
= skb
->data
;
1052 spin_lock_bh(&target
->rx_lock
);
1054 target
->pipe
.ctrl_response_valid
= true;
1055 target
->pipe
.ctrl_response_len
= min_t(int, netlen
,
1056 HTC_MAX_CTRL_MSG_LEN
);
1057 memcpy(target
->pipe
.ctrl_response_buf
, netdata
,
1058 target
->pipe
.ctrl_response_len
);
1060 spin_unlock_bh(&target
->rx_lock
);
1069 * TODO: the message based HIF architecture allocates net bufs
1070 * for recv packets since it bridges that HIF to upper layers,
1071 * which expects HTC packets, we form the packets here
1073 packet
= alloc_htc_packet_container(target
);
1074 if (packet
== NULL
) {
1080 packet
->endpoint
= htc_hdr
->eid
;
1081 packet
->pkt_cntxt
= skb
;
1083 /* TODO: for backwards compatibility */
1084 packet
->buf
= skb_push(skb
, 0) + HTC_HDR_LENGTH
;
1085 packet
->act_len
= netlen
- HTC_HDR_LENGTH
- trailerlen
;
1088 * TODO: this is a hack because the driver layer will set the
1089 * actual len of the skb again which will just double the len
1093 recv_packet_completion(target
, ep
, packet
);
1095 /* recover the packet container */
1096 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_warn("htc pipe control receive timeout!\n");
1170 static void htc_rxctrl_complete(struct htc_target
*context
,
1171 struct htc_packet
*packet
)
1173 struct sk_buff
*skb
= packet
->skb
;
1175 if (packet
->endpoint
== ENDPOINT_0
&&
1176 packet
->status
== -ECANCELED
&&
1181 /* htc pipe initialization */
1182 static void reset_endpoint_states(struct htc_target
*target
)
1184 struct htc_endpoint
*ep
;
1187 for (i
= ENDPOINT_0
; i
< ENDPOINT_MAX
; i
++) {
1188 ep
= &target
->endpoint
[i
];
1191 ep
->max_txq_depth
= 0;
1193 INIT_LIST_HEAD(&ep
->txq
);
1194 INIT_LIST_HEAD(&ep
->pipe
.tx_lookup_queue
);
1195 INIT_LIST_HEAD(&ep
->rx_bufq
);
1196 ep
->target
= target
;
1197 ep
->pipe
.tx_credit_flow_enabled
= true;
1201 /* start HTC, this is called after all services are connected */
1202 static int htc_config_target_hif_pipe(struct htc_target
*target
)
1207 /* htc service functions */
1208 static u8
htc_get_credit_alloc(struct htc_target
*target
, u16 service_id
)
1213 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
1214 if (target
->pipe
.txcredit_alloc
[i
].service_id
== service_id
)
1216 target
->pipe
.txcredit_alloc
[i
].credit_alloc
;
1219 if (allocation
== 0) {
1220 ath6kl_dbg(ATH6KL_DBG_HTC
,
1221 "HTC Service TX : 0x%2.2X : allocation is zero!\n",
1228 static int ath6kl_htc_pipe_conn_service(struct htc_target
*target
,
1229 struct htc_service_connect_req
*conn_req
,
1230 struct htc_service_connect_resp
*conn_resp
)
1232 struct ath6kl
*ar
= target
->dev
->ar
;
1233 struct htc_packet
*packet
= NULL
;
1234 struct htc_conn_service_resp
*resp_msg
;
1235 struct htc_conn_service_msg
*conn_msg
;
1236 enum htc_endpoint_id assigned_epid
= ENDPOINT_MAX
;
1237 bool disable_credit_flowctrl
= false;
1238 unsigned int max_msg_size
= 0;
1239 struct htc_endpoint
*ep
;
1240 int length
, status
= 0;
1241 struct sk_buff
*skb
;
1245 if (conn_req
->svc_id
== 0) {
1251 if (conn_req
->svc_id
== HTC_CTRL_RSVD_SVC
) {
1252 /* special case for pseudo control service */
1253 assigned_epid
= ENDPOINT_0
;
1254 max_msg_size
= HTC_MAX_CTRL_MSG_LEN
;
1258 tx_alloc
= htc_get_credit_alloc(target
, conn_req
->svc_id
);
1259 if (tx_alloc
== 0) {
1264 /* allocate a packet to send to the target */
1265 packet
= htc_alloc_txctrl_packet(target
);
1267 if (packet
== NULL
) {
1274 length
= sizeof(struct htc_conn_service_msg
);
1276 /* assemble connect service message */
1277 conn_msg
= (struct htc_conn_service_msg
*) skb_put(skb
,
1279 if (conn_msg
== NULL
) {
1286 sizeof(struct htc_conn_service_msg
));
1287 conn_msg
->msg_id
= cpu_to_le16(HTC_MSG_CONN_SVC_ID
);
1288 conn_msg
->svc_id
= cpu_to_le16(conn_req
->svc_id
);
1289 conn_msg
->conn_flags
= cpu_to_le16(conn_req
->conn_flags
&
1290 ~HTC_CONN_FLGS_SET_RECV_ALLOC_MASK
);
1292 /* tell target desired recv alloc for this ep */
1293 flags
= tx_alloc
<< HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT
;
1294 conn_msg
->conn_flags
|= cpu_to_le16(flags
);
1296 if (conn_req
->conn_flags
&
1297 HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL
) {
1298 disable_credit_flowctrl
= true;
1301 set_htc_pkt_info(packet
, NULL
, (u8
*) conn_msg
,
1303 ENDPOINT_0
, HTC_SERVICE_TX_PACKET_TAG
);
1305 status
= ath6kl_htc_pipe_tx(target
, packet
);
1307 /* we don't own it anymore */
1312 /* wait for response */
1313 status
= htc_wait_recv_ctrl_message(target
);
1317 /* we controlled the buffer creation so it has to be
1320 resp_msg
= (struct htc_conn_service_resp
*)
1321 target
->pipe
.ctrl_response_buf
;
1323 if (resp_msg
->msg_id
!= cpu_to_le16(HTC_MSG_CONN_SVC_RESP_ID
) ||
1324 (target
->pipe
.ctrl_response_len
< sizeof(*resp_msg
))) {
1325 /* this message is not valid */
1331 ath6kl_dbg(ATH6KL_DBG_TRC
,
1332 "%s: service 0x%X conn resp: status: %d ep: %d\n",
1333 __func__
, resp_msg
->svc_id
, resp_msg
->status
,
1336 conn_resp
->resp_code
= resp_msg
->status
;
1337 /* check response status */
1338 if (resp_msg
->status
!= HTC_SERVICE_SUCCESS
) {
1339 ath6kl_dbg(ATH6KL_DBG_HTC
,
1340 "Target failed service 0x%X connect request (status:%d)\n",
1341 resp_msg
->svc_id
, resp_msg
->status
);
1346 assigned_epid
= (enum htc_endpoint_id
) resp_msg
->eid
;
1347 max_msg_size
= le16_to_cpu(resp_msg
->max_msg_sz
);
1350 /* the rest are parameter checks so set the error status */
1353 if (assigned_epid
>= ENDPOINT_MAX
) {
1358 if (max_msg_size
== 0) {
1363 ep
= &target
->endpoint
[assigned_epid
];
1364 ep
->eid
= assigned_epid
;
1365 if (ep
->svc_id
!= 0) {
1366 /* endpoint already in use! */
1371 /* return assigned endpoint to caller */
1372 conn_resp
->endpoint
= assigned_epid
;
1373 conn_resp
->len_max
= max_msg_size
;
1375 /* setup the endpoint */
1376 ep
->svc_id
= conn_req
->svc_id
; /* this marks ep in use */
1377 ep
->max_txq_depth
= conn_req
->max_txq_depth
;
1378 ep
->len_max
= max_msg_size
;
1379 ep
->cred_dist
.credits
= tx_alloc
;
1380 ep
->cred_dist
.cred_sz
= target
->tgt_cred_sz
;
1381 ep
->cred_dist
.cred_per_msg
= max_msg_size
/ target
->tgt_cred_sz
;
1382 if (max_msg_size
% target
->tgt_cred_sz
)
1383 ep
->cred_dist
.cred_per_msg
++;
1385 /* copy all the callbacks */
1386 ep
->ep_cb
= conn_req
->ep_cb
;
1388 /* initialize tx_drop_packet_threshold */
1389 ep
->tx_drop_packet_threshold
= MAX_HI_COOKIE_NUM
;
1391 status
= ath6kl_hif_pipe_map_service(ar
, ep
->svc_id
,
1392 &ep
->pipe
.pipeid_ul
,
1393 &ep
->pipe
.pipeid_dl
);
1397 ath6kl_dbg(ATH6KL_DBG_HTC
,
1398 "SVC Ready: 0x%4.4X: ULpipe:%d DLpipe:%d id:%d\n",
1399 ep
->svc_id
, ep
->pipe
.pipeid_ul
,
1400 ep
->pipe
.pipeid_dl
, ep
->eid
);
1402 if (disable_credit_flowctrl
&& ep
->pipe
.tx_credit_flow_enabled
) {
1403 ep
->pipe
.tx_credit_flow_enabled
= false;
1404 ath6kl_dbg(ATH6KL_DBG_HTC
,
1405 "SVC: 0x%4.4X ep:%d TX flow control off\n",
1406 ep
->svc_id
, assigned_epid
);
1411 htc_free_txctrl_packet(target
, packet
);
1415 /* htc export functions */
1416 static void *ath6kl_htc_pipe_create(struct ath6kl
*ar
)
1419 struct htc_endpoint
*ep
= NULL
;
1420 struct htc_target
*target
= NULL
;
1421 struct htc_packet
*packet
;
1424 target
= kzalloc(sizeof(struct htc_target
), GFP_KERNEL
);
1425 if (target
== NULL
) {
1426 ath6kl_err("htc create unable to allocate memory\n");
1428 goto fail_htc_create
;
1431 spin_lock_init(&target
->htc_lock
);
1432 spin_lock_init(&target
->rx_lock
);
1433 spin_lock_init(&target
->tx_lock
);
1435 reset_endpoint_states(target
);
1437 for (i
= 0; i
< HTC_PACKET_CONTAINER_ALLOCATION
; i
++) {
1438 packet
= kzalloc(sizeof(struct htc_packet
), GFP_KERNEL
);
1441 free_htc_packet_container(target
, packet
);
1444 target
->dev
= kzalloc(sizeof(*target
->dev
), GFP_KERNEL
);
1446 ath6kl_err("unable to allocate memory\n");
1448 goto fail_htc_create
;
1450 target
->dev
->ar
= ar
;
1451 target
->dev
->htc_cnxt
= target
;
1453 /* Get HIF default pipe for HTC message exchange */
1454 ep
= &target
->endpoint
[ENDPOINT_0
];
1456 ath6kl_hif_pipe_get_default(ar
, &ep
->pipe
.pipeid_ul
,
1457 &ep
->pipe
.pipeid_dl
);
1464 ath6kl_htc_pipe_cleanup(target
);
1471 /* cleanup the HTC instance */
1472 static void ath6kl_htc_pipe_cleanup(struct htc_target
*target
)
1474 struct htc_packet
*packet
;
1477 packet
= alloc_htc_packet_container(target
);
1485 /* kfree our instance */
1489 static int ath6kl_htc_pipe_start(struct htc_target
*target
)
1491 struct sk_buff
*skb
;
1492 struct htc_setup_comp_ext_msg
*setup
;
1493 struct htc_packet
*packet
;
1495 htc_config_target_hif_pipe(target
);
1497 /* allocate a buffer to send */
1498 packet
= htc_alloc_txctrl_packet(target
);
1499 if (packet
== NULL
) {
1506 /* assemble setup complete message */
1507 setup
= (struct htc_setup_comp_ext_msg
*) skb_put(skb
,
1509 memset(setup
, 0, sizeof(struct htc_setup_comp_ext_msg
));
1510 setup
->msg_id
= cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID
);
1512 ath6kl_dbg(ATH6KL_DBG_HTC
, "HTC using TX credit flow control\n");
1514 set_htc_pkt_info(packet
, NULL
, (u8
*) setup
,
1515 sizeof(struct htc_setup_comp_ext_msg
),
1516 ENDPOINT_0
, HTC_SERVICE_TX_PACKET_TAG
);
1518 target
->htc_flags
|= HTC_OP_STATE_SETUP_COMPLETE
;
1520 return ath6kl_htc_pipe_tx(target
, packet
);
1523 static void ath6kl_htc_pipe_stop(struct htc_target
*target
)
1526 struct htc_endpoint
*ep
;
1528 /* cleanup endpoints */
1529 for (i
= 0; i
< ENDPOINT_MAX
; i
++) {
1530 ep
= &target
->endpoint
[i
];
1531 htc_flush_rx_queue(target
, ep
);
1532 htc_flush_tx_endpoint(target
, ep
, HTC_TX_PACKET_TAG_ALL
);
1535 reset_endpoint_states(target
);
1536 target
->htc_flags
&= ~HTC_OP_STATE_SETUP_COMPLETE
;
1539 static int ath6kl_htc_pipe_get_rxbuf_num(struct htc_target
*target
,
1540 enum htc_endpoint_id endpoint
)
1544 spin_lock_bh(&target
->rx_lock
);
1545 num
= get_queue_depth(&(target
->endpoint
[endpoint
].rx_bufq
));
1546 spin_unlock_bh(&target
->rx_lock
);
1551 static int ath6kl_htc_pipe_tx(struct htc_target
*target
,
1552 struct htc_packet
*packet
)
1554 struct list_head queue
;
1556 ath6kl_dbg(ATH6KL_DBG_HTC
,
1557 "%s: endPointId: %d, buffer: 0x%p, length: %d\n",
1558 __func__
, packet
->endpoint
, packet
->buf
,
1561 INIT_LIST_HEAD(&queue
);
1562 list_add_tail(&packet
->list
, &queue
);
1564 return htc_send_packets_multiple(target
, &queue
);
1567 static int ath6kl_htc_pipe_wait_target(struct htc_target
*target
)
1569 struct htc_ready_ext_msg
*ready_msg
;
1570 struct htc_service_connect_req connect
;
1571 struct htc_service_connect_resp resp
;
1574 status
= htc_wait_recv_ctrl_message(target
);
1579 if (target
->pipe
.ctrl_response_len
< sizeof(*ready_msg
)) {
1580 ath6kl_warn("invalid htc pipe ready msg len: %d\n",
1581 target
->pipe
.ctrl_response_len
);
1585 ready_msg
= (struct htc_ready_ext_msg
*) target
->pipe
.ctrl_response_buf
;
1587 if (ready_msg
->ver2_0_info
.msg_id
!= cpu_to_le16(HTC_MSG_READY_ID
)) {
1588 ath6kl_warn("invalid htc pipe ready msg: 0x%x\n",
1589 ready_msg
->ver2_0_info
.msg_id
);
1593 ath6kl_dbg(ATH6KL_DBG_HTC
,
1594 "Target Ready! : transmit resources : %d size:%d\n",
1595 ready_msg
->ver2_0_info
.cred_cnt
,
1596 ready_msg
->ver2_0_info
.cred_sz
);
1598 target
->tgt_creds
= le16_to_cpu(ready_msg
->ver2_0_info
.cred_cnt
);
1599 target
->tgt_cred_sz
= le16_to_cpu(ready_msg
->ver2_0_info
.cred_sz
);
1601 if ((target
->tgt_creds
== 0) || (target
->tgt_cred_sz
== 0))
1604 htc_setup_target_buffer_assignments(target
);
1606 /* setup our pseudo HTC control endpoint connection */
1607 memset(&connect
, 0, sizeof(connect
));
1608 memset(&resp
, 0, sizeof(resp
));
1609 connect
.ep_cb
.tx_complete
= htc_txctrl_complete
;
1610 connect
.ep_cb
.rx
= htc_rxctrl_complete
;
1611 connect
.max_txq_depth
= NUM_CONTROL_TX_BUFFERS
;
1612 connect
.svc_id
= HTC_CTRL_RSVD_SVC
;
1614 /* connect fake service */
1615 status
= ath6kl_htc_pipe_conn_service(target
, &connect
, &resp
);
1620 static void ath6kl_htc_pipe_flush_txep(struct htc_target
*target
,
1621 enum htc_endpoint_id endpoint
, u16 tag
)
1623 struct htc_endpoint
*ep
= &target
->endpoint
[endpoint
];
1625 if (ep
->svc_id
== 0) {
1631 htc_flush_tx_endpoint(target
, ep
, tag
);
1634 static int ath6kl_htc_pipe_add_rxbuf_multiple(struct htc_target
*target
,
1635 struct list_head
*pkt_queue
)
1637 struct htc_packet
*packet
, *tmp_pkt
, *first
;
1638 struct htc_endpoint
*ep
;
1641 if (list_empty(pkt_queue
))
1644 first
= list_first_entry(pkt_queue
, struct htc_packet
, list
);
1646 if (first
->endpoint
>= ENDPOINT_MAX
) {
1651 ath6kl_dbg(ATH6KL_DBG_HTC
, "%s: epid: %d, cnt:%d, len: %d\n",
1652 __func__
, first
->endpoint
, get_queue_depth(pkt_queue
),
1655 ep
= &target
->endpoint
[first
->endpoint
];
1657 spin_lock_bh(&target
->rx_lock
);
1659 /* store receive packets */
1660 list_splice_tail_init(pkt_queue
, &ep
->rx_bufq
);
1662 spin_unlock_bh(&target
->rx_lock
);
1665 /* walk through queue and mark each one canceled */
1666 list_for_each_entry_safe(packet
, tmp_pkt
, pkt_queue
, list
) {
1667 packet
->status
= -ECANCELED
;
1670 do_recv_completion(ep
, pkt_queue
);
1676 static void ath6kl_htc_pipe_activity_changed(struct htc_target
*target
,
1677 enum htc_endpoint_id ep
,
1683 static void ath6kl_htc_pipe_flush_rx_buf(struct htc_target
*target
)
1685 struct htc_endpoint
*endpoint
;
1686 struct htc_packet
*packet
, *tmp_pkt
;
1689 for (i
= ENDPOINT_0
; i
< ENDPOINT_MAX
; i
++) {
1690 endpoint
= &target
->endpoint
[i
];
1692 spin_lock_bh(&target
->rx_lock
);
1694 list_for_each_entry_safe(packet
, tmp_pkt
,
1695 &endpoint
->rx_bufq
, list
) {
1696 list_del(&packet
->list
);
1697 spin_unlock_bh(&target
->rx_lock
);
1698 ath6kl_dbg(ATH6KL_DBG_HTC
,
1699 "htc rx flush pkt 0x%p len %d ep %d\n",
1700 packet
, packet
->buf_len
,
1702 dev_kfree_skb(packet
->pkt_cntxt
);
1703 spin_lock_bh(&target
->rx_lock
);
1706 spin_unlock_bh(&target
->rx_lock
);
1710 static int ath6kl_htc_pipe_credit_setup(struct htc_target
*target
,
1711 struct ath6kl_htc_credit_info
*info
)
1716 static const struct ath6kl_htc_ops ath6kl_htc_pipe_ops
= {
1717 .create
= ath6kl_htc_pipe_create
,
1718 .wait_target
= ath6kl_htc_pipe_wait_target
,
1719 .start
= ath6kl_htc_pipe_start
,
1720 .conn_service
= ath6kl_htc_pipe_conn_service
,
1721 .tx
= ath6kl_htc_pipe_tx
,
1722 .stop
= ath6kl_htc_pipe_stop
,
1723 .cleanup
= ath6kl_htc_pipe_cleanup
,
1724 .flush_txep
= ath6kl_htc_pipe_flush_txep
,
1725 .flush_rx_buf
= ath6kl_htc_pipe_flush_rx_buf
,
1726 .activity_changed
= ath6kl_htc_pipe_activity_changed
,
1727 .get_rxbuf_num
= ath6kl_htc_pipe_get_rxbuf_num
,
1728 .add_rxbuf_multiple
= ath6kl_htc_pipe_add_rxbuf_multiple
,
1729 .credit_setup
= ath6kl_htc_pipe_credit_setup
,
1730 .tx_complete
= ath6kl_htc_pipe_tx_complete
,
1731 .rx_complete
= ath6kl_htc_pipe_rx_complete
,
1734 void ath6kl_htc_pipe_attach(struct ath6kl
*ar
)
1736 ar
->htc_ops
= &ath6kl_htc_pipe_ops
;