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 #include <asm/unaligned.h>
23 #define CALC_TXRX_PADDED_LEN(dev, len) (__ALIGN_MASK((len), (dev)->block_mask))
25 static void ath6kl_htc_tx_buf_align(u8 **buf, unsigned long len)
29 if (!IS_ALIGNED((unsigned long) *buf, 4)) {
30 align_addr = PTR_ALIGN(*buf - 4, 4);
31 memmove(align_addr, *buf, len);
36 static void ath6kl_htc_tx_prep_pkt(struct htc_packet *packet, u8 flags,
39 struct htc_frame_hdr *hdr;
41 packet->buf -= HTC_HDR_LENGTH;
42 hdr = (struct htc_frame_hdr *)packet->buf;
45 put_unaligned((u16)packet->act_len, &hdr->payld_len);
47 hdr->eid = packet->endpoint;
52 static void htc_reclaim_txctrl_buf(struct htc_target *target,
53 struct htc_packet *pkt)
55 spin_lock_bh(&target->htc_lock);
56 list_add_tail(&pkt->list, &target->free_ctrl_txbuf);
57 spin_unlock_bh(&target->htc_lock);
60 static struct htc_packet *htc_get_control_buf(struct htc_target *target,
63 struct htc_packet *packet = NULL;
64 struct list_head *buf_list;
66 buf_list = tx ? &target->free_ctrl_txbuf : &target->free_ctrl_rxbuf;
68 spin_lock_bh(&target->htc_lock);
70 if (list_empty(buf_list)) {
71 spin_unlock_bh(&target->htc_lock);
75 packet = list_first_entry(buf_list, struct htc_packet, list);
76 list_del(&packet->list);
77 spin_unlock_bh(&target->htc_lock);
80 packet->buf = packet->buf_start + HTC_HDR_LENGTH;
85 static void htc_tx_comp_update(struct htc_target *target,
86 struct htc_endpoint *endpoint,
87 struct htc_packet *packet)
89 packet->completion = NULL;
90 packet->buf += HTC_HDR_LENGTH;
95 ath6kl_err("req failed (status:%d, ep:%d, len:%d creds:%d)\n",
96 packet->status, packet->endpoint, packet->act_len,
97 packet->info.tx.cred_used);
99 /* on failure to submit, reclaim credits for this packet */
100 spin_lock_bh(&target->tx_lock);
101 endpoint->cred_dist.cred_to_dist +=
102 packet->info.tx.cred_used;
103 endpoint->cred_dist.txq_depth = get_queue_depth(&endpoint->txq);
105 ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx ctxt 0x%p dist 0x%p\n",
106 target->cred_dist_cntxt, &target->cred_dist_list);
108 ath6kl_credit_distribute(target->cred_dist_cntxt,
109 &target->cred_dist_list,
110 HTC_CREDIT_DIST_SEND_COMPLETE);
112 spin_unlock_bh(&target->tx_lock);
115 static void htc_tx_complete(struct htc_endpoint *endpoint,
116 struct list_head *txq)
121 ath6kl_dbg(ATH6KL_DBG_HTC,
122 "htc tx complete ep %d pkts %d\n",
123 endpoint->eid, get_queue_depth(txq));
125 ath6kl_tx_complete(endpoint->target->dev->ar, txq);
128 static void htc_tx_comp_handler(struct htc_target *target,
129 struct htc_packet *packet)
131 struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
132 struct list_head container;
134 htc_tx_comp_update(target, endpoint, packet);
135 INIT_LIST_HEAD(&container);
136 list_add_tail(&packet->list, &container);
138 htc_tx_complete(endpoint, &container);
141 static void htc_async_tx_scat_complete(struct htc_target *target,
142 struct hif_scatter_req *scat_req)
144 struct htc_endpoint *endpoint;
145 struct htc_packet *packet;
146 struct list_head tx_compq;
149 INIT_LIST_HEAD(&tx_compq);
151 ath6kl_dbg(ATH6KL_DBG_HTC,
152 "htc tx scat complete len %d entries %d\n",
153 scat_req->len, scat_req->scat_entries);
155 if (scat_req->status)
156 ath6kl_err("send scatter req failed: %d\n", scat_req->status);
158 packet = scat_req->scat_list[0].packet;
159 endpoint = &target->endpoint[packet->endpoint];
161 /* walk through the scatter list and process */
162 for (i = 0; i < scat_req->scat_entries; i++) {
163 packet = scat_req->scat_list[i].packet;
169 packet->status = scat_req->status;
170 htc_tx_comp_update(target, endpoint, packet);
171 list_add_tail(&packet->list, &tx_compq);
174 /* free scatter request */
175 hif_scatter_req_add(target->dev->ar, scat_req);
177 /* complete all packets */
178 htc_tx_complete(endpoint, &tx_compq);
181 static int ath6kl_htc_tx_issue(struct htc_target *target,
182 struct htc_packet *packet)
186 u32 padded_len, send_len;
188 if (!packet->completion)
191 send_len = packet->act_len + HTC_HDR_LENGTH;
193 padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
195 ath6kl_dbg(ATH6KL_DBG_HTC,
196 "htc tx issue len %d padded_len %d mbox 0x%X %s\n",
197 send_len, padded_len,
198 target->dev->ar->mbox_info.htc_addr,
199 sync ? "sync" : "async");
202 status = hif_read_write_sync(target->dev->ar,
203 target->dev->ar->mbox_info.htc_addr,
204 packet->buf, padded_len,
205 HIF_WR_SYNC_BLOCK_INC);
207 packet->status = status;
208 packet->buf += HTC_HDR_LENGTH;
210 status = hif_write_async(target->dev->ar,
211 target->dev->ar->mbox_info.htc_addr,
212 packet->buf, padded_len,
213 HIF_WR_ASYNC_BLOCK_INC, packet);
218 static int htc_check_credits(struct htc_target *target,
219 struct htc_endpoint *ep, u8 *flags,
220 enum htc_endpoint_id eid, unsigned int len,
224 *req_cred = (len > target->tgt_cred_sz) ?
225 DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
227 ath6kl_dbg(ATH6KL_DBG_HTC, "htc creds required %d got %d\n",
228 *req_cred, ep->cred_dist.credits);
230 if (ep->cred_dist.credits < *req_cred) {
231 if (eid == ENDPOINT_0)
234 /* Seek more credits */
235 ep->cred_dist.seek_cred = *req_cred - ep->cred_dist.credits;
237 ath6kl_dbg(ATH6KL_DBG_HTC, "htc creds ctxt 0x%p dist 0x%p\n",
238 target->cred_dist_cntxt, &ep->cred_dist);
240 ath6kl_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
242 ep->cred_dist.seek_cred = 0;
244 if (ep->cred_dist.credits < *req_cred) {
245 ath6kl_dbg(ATH6KL_DBG_HTC,
246 "htc creds not enough credits for ep %d\n",
252 ep->cred_dist.credits -= *req_cred;
253 ep->ep_st.cred_cosumd += *req_cred;
255 /* When we are getting low on credits, ask for more */
256 if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
257 ep->cred_dist.seek_cred =
258 ep->cred_dist.cred_per_msg - ep->cred_dist.credits;
260 ath6kl_dbg(ATH6KL_DBG_HTC, "htc creds ctxt 0x%p dist 0x%p\n",
261 target->cred_dist_cntxt, &ep->cred_dist);
263 ath6kl_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
265 /* see if we were successful in getting more */
266 if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
267 /* tell the target we need credits ASAP! */
268 *flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
269 ep->ep_st.cred_low_indicate += 1;
270 ath6kl_dbg(ATH6KL_DBG_HTC, "htc creds host needs credits\n");
277 static void ath6kl_htc_tx_pkts_get(struct htc_target *target,
278 struct htc_endpoint *endpoint,
279 struct list_head *queue)
283 struct htc_packet *packet;
290 if (list_empty(&endpoint->txq))
292 packet = list_first_entry(&endpoint->txq, struct htc_packet,
295 ath6kl_dbg(ATH6KL_DBG_HTC,
296 "htc tx got packet 0x%p queue depth %d\n",
297 packet, get_queue_depth(&endpoint->txq));
299 len = CALC_TXRX_PADDED_LEN(target,
300 packet->act_len + HTC_HDR_LENGTH);
302 if (htc_check_credits(target, endpoint, &flags,
303 packet->endpoint, len, &req_cred))
306 /* now we can fully move onto caller's queue */
307 packet = list_first_entry(&endpoint->txq, struct htc_packet,
309 list_move_tail(&packet->list, queue);
311 /* save the number of credits this packet consumed */
312 packet->info.tx.cred_used = req_cred;
314 /* all TX packets are handled asynchronously */
315 packet->completion = htc_tx_comp_handler;
316 packet->context = target;
317 endpoint->ep_st.tx_issued += 1;
319 /* save send flags */
320 packet->info.tx.flags = flags;
321 packet->info.tx.seqno = endpoint->seqno;
326 /* See if the padded tx length falls on a credit boundary */
327 static int htc_get_credit_padding(unsigned int cred_sz, int *len,
328 struct htc_endpoint *ep)
330 int rem_cred, cred_pad;
332 rem_cred = *len % cred_sz;
334 /* No padding needed */
338 if (!(ep->conn_flags & HTC_FLGS_TX_BNDL_PAD_EN))
342 * The transfer consumes a "partial" credit, this
343 * packet cannot be bundled unless we add
344 * additional "dummy" padding (max 255 bytes) to
345 * consume the entire credit.
347 cred_pad = *len < cred_sz ? (cred_sz - *len) : rem_cred;
349 if ((cred_pad > 0) && (cred_pad <= 255))
352 /* The amount of padding is too large, send as non-bundled */
358 static int ath6kl_htc_tx_setup_scat_list(struct htc_target *target,
359 struct htc_endpoint *endpoint,
360 struct hif_scatter_req *scat_req,
362 struct list_head *queue)
364 struct htc_packet *packet;
365 int i, len, rem_scat, cred_pad;
368 rem_scat = target->max_tx_bndl_sz;
370 for (i = 0; i < n_scat; i++) {
371 scat_req->scat_list[i].packet = NULL;
373 if (list_empty(queue))
376 packet = list_first_entry(queue, struct htc_packet, list);
377 len = CALC_TXRX_PADDED_LEN(target,
378 packet->act_len + HTC_HDR_LENGTH);
380 cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
382 if (cred_pad < 0 || rem_scat < len) {
388 /* now remove it from the queue */
389 list_del(&packet->list);
391 scat_req->scat_list[i].packet = packet;
392 /* prepare packet and flag message as part of a send bundle */
393 ath6kl_htc_tx_prep_pkt(packet,
394 packet->info.tx.flags | HTC_FLAGS_SEND_BUNDLE,
395 cred_pad, packet->info.tx.seqno);
396 /* Make sure the buffer is 4-byte aligned */
397 ath6kl_htc_tx_buf_align(&packet->buf,
398 packet->act_len + HTC_HDR_LENGTH);
399 scat_req->scat_list[i].buf = packet->buf;
400 scat_req->scat_list[i].len = len;
402 scat_req->len += len;
403 scat_req->scat_entries++;
404 ath6kl_dbg(ATH6KL_DBG_HTC,
405 "htc tx adding (%d) pkt 0x%p len %d remaining %d\n",
406 i, packet, len, rem_scat);
409 /* Roll back scatter setup in case of any failure */
410 if (scat_req->scat_entries < HTC_MIN_HTC_MSGS_TO_BUNDLE) {
411 for (i = scat_req->scat_entries - 1; i >= 0; i--) {
412 packet = scat_req->scat_list[i].packet;
414 packet->buf += HTC_HDR_LENGTH;
415 list_add(&packet->list, queue);
425 * Drain a queue and send as bundles this function may return without fully
426 * draining the queue when
428 * 1. scatter resources are exhausted
429 * 2. a message that will consume a partial credit will stop the
430 * bundling process early
431 * 3. we drop below the minimum number of messages for a bundle
433 static void ath6kl_htc_tx_bundle(struct htc_endpoint *endpoint,
434 struct list_head *queue,
435 int *sent_bundle, int *n_bundle_pkts)
437 struct htc_target *target = endpoint->target;
438 struct hif_scatter_req *scat_req = NULL;
439 int n_scat, n_sent_bundle = 0, tot_pkts_bundle = 0;
444 n_scat = get_queue_depth(queue);
445 n_scat = min(n_scat, target->msg_per_bndl_max);
447 if (n_scat < HTC_MIN_HTC_MSGS_TO_BUNDLE)
448 /* not enough to bundle */
451 scat_req = hif_scatter_req_get(target->dev->ar);
454 /* no scatter resources */
455 ath6kl_dbg(ATH6KL_DBG_HTC,
456 "htc tx no more scatter resources\n");
460 ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx pkts to scatter: %d\n",
464 scat_req->scat_entries = 0;
466 status = ath6kl_htc_tx_setup_scat_list(target, endpoint,
469 if (status == -EAGAIN) {
470 hif_scatter_req_add(target->dev->ar, scat_req);
474 /* send path is always asynchronous */
475 scat_req->complete = htc_async_tx_scat_complete;
477 tot_pkts_bundle += scat_req->scat_entries;
479 ath6kl_dbg(ATH6KL_DBG_HTC,
480 "htc tx scatter bytes %d entries %d\n",
481 scat_req->len, scat_req->scat_entries);
482 ath6kl_hif_submit_scat_req(target->dev, scat_req, false);
488 *sent_bundle = n_sent_bundle;
489 *n_bundle_pkts = tot_pkts_bundle;
490 ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx bundle sent %d pkts\n",
496 static void ath6kl_htc_tx_from_queue(struct htc_target *target,
497 struct htc_endpoint *endpoint)
499 struct list_head txq;
500 struct htc_packet *packet;
504 spin_lock_bh(&target->tx_lock);
506 endpoint->tx_proc_cnt++;
507 if (endpoint->tx_proc_cnt > 1) {
508 endpoint->tx_proc_cnt--;
509 spin_unlock_bh(&target->tx_lock);
510 ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx busy\n");
515 * drain the endpoint TX queue for transmission as long
516 * as we have enough credits.
518 INIT_LIST_HEAD(&txq);
522 if (list_empty(&endpoint->txq))
525 ath6kl_htc_tx_pkts_get(target, endpoint, &txq);
527 if (list_empty(&txq))
530 spin_unlock_bh(&target->tx_lock);
536 /* try to send a bundle on each pass */
537 if ((target->tx_bndl_enable) &&
538 (get_queue_depth(&txq) >=
539 HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
540 int temp1 = 0, temp2 = 0;
542 ath6kl_htc_tx_bundle(endpoint, &txq,
544 bundle_sent += temp1;
545 n_pkts_bundle += temp2;
548 if (list_empty(&txq))
551 packet = list_first_entry(&txq, struct htc_packet,
553 list_del(&packet->list);
555 ath6kl_htc_tx_prep_pkt(packet, packet->info.tx.flags,
556 0, packet->info.tx.seqno);
557 ath6kl_htc_tx_issue(target, packet);
560 spin_lock_bh(&target->tx_lock);
562 endpoint->ep_st.tx_bundles += bundle_sent;
563 endpoint->ep_st.tx_pkt_bundled += n_pkts_bundle;
566 endpoint->tx_proc_cnt = 0;
567 spin_unlock_bh(&target->tx_lock);
570 static bool ath6kl_htc_tx_try(struct htc_target *target,
571 struct htc_endpoint *endpoint,
572 struct htc_packet *tx_pkt)
574 struct htc_ep_callbacks ep_cb;
576 bool overflow = false;
578 ep_cb = endpoint->ep_cb;
580 spin_lock_bh(&target->tx_lock);
581 txq_depth = get_queue_depth(&endpoint->txq);
582 spin_unlock_bh(&target->tx_lock);
584 if (txq_depth >= endpoint->max_txq_depth)
588 ath6kl_dbg(ATH6KL_DBG_HTC,
589 "htc tx overflow ep %d depth %d max %d\n",
590 endpoint->eid, txq_depth,
591 endpoint->max_txq_depth);
593 if (overflow && ep_cb.tx_full) {
594 if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
595 HTC_SEND_FULL_DROP) {
596 endpoint->ep_st.tx_dropped += 1;
601 spin_lock_bh(&target->tx_lock);
602 list_add_tail(&tx_pkt->list, &endpoint->txq);
603 spin_unlock_bh(&target->tx_lock);
605 ath6kl_htc_tx_from_queue(target, endpoint);
610 static void htc_chk_ep_txq(struct htc_target *target)
612 struct htc_endpoint *endpoint;
613 struct htc_endpoint_credit_dist *cred_dist;
616 * Run through the credit distribution list to see if there are
617 * packets queued. NOTE: no locks need to be taken since the
618 * distribution list is not dynamic (cannot be re-ordered) and we
619 * are not modifying any state.
621 list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
622 endpoint = (struct htc_endpoint *)cred_dist->htc_rsvd;
624 spin_lock_bh(&target->tx_lock);
625 if (!list_empty(&endpoint->txq)) {
626 ath6kl_dbg(ATH6KL_DBG_HTC,
627 "htc creds ep %d credits %d pkts %d\n",
629 endpoint->cred_dist.credits,
630 get_queue_depth(&endpoint->txq));
631 spin_unlock_bh(&target->tx_lock);
633 * Try to start the stalled queue, this list is
634 * ordered by priority. If there are credits
635 * available the highest priority queue will get a
636 * chance to reclaim credits from lower priority
639 ath6kl_htc_tx_from_queue(target, endpoint);
640 spin_lock_bh(&target->tx_lock);
642 spin_unlock_bh(&target->tx_lock);
646 static int htc_setup_tx_complete(struct htc_target *target)
648 struct htc_packet *send_pkt = NULL;
651 send_pkt = htc_get_control_buf(target, true);
656 if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
657 struct htc_setup_comp_ext_msg *setup_comp_ext;
661 (struct htc_setup_comp_ext_msg *)send_pkt->buf;
662 memset(setup_comp_ext, 0, sizeof(*setup_comp_ext));
663 setup_comp_ext->msg_id =
664 cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
666 if (target->msg_per_bndl_max > 0) {
667 /* Indicate HTC bundling to the target */
668 flags |= HTC_SETUP_COMP_FLG_RX_BNDL_EN;
669 setup_comp_ext->msg_per_rxbndl =
670 target->msg_per_bndl_max;
673 memcpy(&setup_comp_ext->flags, &flags,
674 sizeof(setup_comp_ext->flags));
675 set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp_ext,
676 sizeof(struct htc_setup_comp_ext_msg),
677 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
680 struct htc_setup_comp_msg *setup_comp;
681 setup_comp = (struct htc_setup_comp_msg *)send_pkt->buf;
682 memset(setup_comp, 0, sizeof(struct htc_setup_comp_msg));
683 setup_comp->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_ID);
684 set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp,
685 sizeof(struct htc_setup_comp_msg),
686 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
689 /* we want synchronous operation */
690 send_pkt->completion = NULL;
691 ath6kl_htc_tx_prep_pkt(send_pkt, 0, 0, 0);
692 status = ath6kl_htc_tx_issue(target, send_pkt);
694 if (send_pkt != NULL)
695 htc_reclaim_txctrl_buf(target, send_pkt);
700 void ath6kl_htc_set_credit_dist(struct htc_target *target,
701 struct htc_credit_state_info *cred_dist_cntxt,
702 u16 srvc_pri_order[], int list_len)
704 struct htc_endpoint *endpoint;
707 target->cred_dist_cntxt = cred_dist_cntxt;
709 list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
710 &target->cred_dist_list);
712 for (i = 0; i < list_len; i++) {
713 for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) {
714 endpoint = &target->endpoint[ep];
715 if (endpoint->svc_id == srvc_pri_order[i]) {
716 list_add_tail(&endpoint->cred_dist.list,
717 &target->cred_dist_list);
721 if (ep >= ENDPOINT_MAX) {
728 int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet)
730 struct htc_endpoint *endpoint;
731 struct list_head queue;
733 ath6kl_dbg(ATH6KL_DBG_HTC,
734 "htc tx ep id %d buf 0x%p len %d\n",
735 packet->endpoint, packet->buf, packet->act_len);
737 if (packet->endpoint >= ENDPOINT_MAX) {
742 endpoint = &target->endpoint[packet->endpoint];
744 if (!ath6kl_htc_tx_try(target, endpoint, packet)) {
745 packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
746 -ECANCELED : -ENOSPC;
747 INIT_LIST_HEAD(&queue);
748 list_add(&packet->list, &queue);
749 htc_tx_complete(endpoint, &queue);
755 /* flush endpoint TX queue */
756 void ath6kl_htc_flush_txep(struct htc_target *target,
757 enum htc_endpoint_id eid, u16 tag)
759 struct htc_packet *packet, *tmp_pkt;
760 struct list_head discard_q, container;
761 struct htc_endpoint *endpoint = &target->endpoint[eid];
763 if (!endpoint->svc_id) {
768 /* initialize the discard queue */
769 INIT_LIST_HEAD(&discard_q);
771 spin_lock_bh(&target->tx_lock);
773 list_for_each_entry_safe(packet, tmp_pkt, &endpoint->txq, list) {
774 if ((tag == HTC_TX_PACKET_TAG_ALL) ||
775 (tag == packet->info.tx.tag))
776 list_move_tail(&packet->list, &discard_q);
779 spin_unlock_bh(&target->tx_lock);
781 list_for_each_entry_safe(packet, tmp_pkt, &discard_q, list) {
782 packet->status = -ECANCELED;
783 list_del(&packet->list);
784 ath6kl_dbg(ATH6KL_DBG_HTC,
785 "htc tx flushing pkt 0x%p len %d ep %d tag 0x%x\n",
786 packet, packet->act_len,
787 packet->endpoint, packet->info.tx.tag);
789 INIT_LIST_HEAD(&container);
790 list_add_tail(&packet->list, &container);
791 htc_tx_complete(endpoint, &container);
796 static void ath6kl_htc_flush_txep_all(struct htc_target *target)
798 struct htc_endpoint *endpoint;
801 dump_cred_dist_stats(target);
803 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
804 endpoint = &target->endpoint[i];
805 if (endpoint->svc_id == 0)
808 ath6kl_htc_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
812 void ath6kl_htc_indicate_activity_change(struct htc_target *target,
813 enum htc_endpoint_id eid, bool active)
815 struct htc_endpoint *endpoint = &target->endpoint[eid];
818 if (endpoint->svc_id == 0) {
823 spin_lock_bh(&target->tx_lock);
826 if (!(endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE)) {
827 endpoint->cred_dist.dist_flags |= HTC_EP_ACTIVE;
831 if (endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE) {
832 endpoint->cred_dist.dist_flags &= ~HTC_EP_ACTIVE;
838 endpoint->cred_dist.txq_depth =
839 get_queue_depth(&endpoint->txq);
841 ath6kl_dbg(ATH6KL_DBG_HTC,
842 "htc tx activity ctxt 0x%p dist 0x%p\n",
843 target->cred_dist_cntxt, &target->cred_dist_list);
845 ath6kl_credit_distribute(target->cred_dist_cntxt,
846 &target->cred_dist_list,
847 HTC_CREDIT_DIST_ACTIVITY_CHANGE);
850 spin_unlock_bh(&target->tx_lock);
853 htc_chk_ep_txq(target);
858 static inline void ath6kl_htc_rx_update_stats(struct htc_endpoint *endpoint,
861 endpoint->ep_st.rx_pkts++;
862 if (n_look_ahds == 1)
863 endpoint->ep_st.rx_lkahds++;
864 else if (n_look_ahds > 1)
865 endpoint->ep_st.rx_bundle_lkahd++;
868 static inline bool htc_valid_rx_frame_len(struct htc_target *target,
869 enum htc_endpoint_id eid, int len)
871 return (eid == target->dev->ar->ctrl_ep) ?
872 len <= ATH6KL_BUFFER_SIZE : len <= ATH6KL_AMSDU_BUFFER_SIZE;
875 static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
877 struct list_head queue;
879 INIT_LIST_HEAD(&queue);
880 list_add_tail(&packet->list, &queue);
881 return ath6kl_htc_add_rxbuf_multiple(target, &queue);
884 static void htc_reclaim_rxbuf(struct htc_target *target,
885 struct htc_packet *packet,
886 struct htc_endpoint *ep)
888 if (packet->info.rx.rx_flags & HTC_RX_PKT_NO_RECYCLE) {
889 htc_rxpkt_reset(packet);
890 packet->status = -ECANCELED;
891 ep->ep_cb.rx(ep->target, packet);
893 htc_rxpkt_reset(packet);
894 htc_add_rxbuf((void *)(target), packet);
898 static void reclaim_rx_ctrl_buf(struct htc_target *target,
899 struct htc_packet *packet)
901 spin_lock_bh(&target->htc_lock);
902 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
903 spin_unlock_bh(&target->htc_lock);
906 static int ath6kl_htc_rx_packet(struct htc_target *target,
907 struct htc_packet *packet,
910 struct ath6kl_device *dev = target->dev;
914 padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
916 if (padded_len > packet->buf_len) {
917 ath6kl_err("not enough receive space for packet - padlen %d recvlen %d bufferlen %d\n",
918 padded_len, rx_len, packet->buf_len);
922 ath6kl_dbg(ATH6KL_DBG_HTC,
923 "htc rx 0x%p hdr x%x len %d mbox 0x%x\n",
924 packet, packet->info.rx.exp_hdr,
925 padded_len, dev->ar->mbox_info.htc_addr);
927 status = hif_read_write_sync(dev->ar,
928 dev->ar->mbox_info.htc_addr,
929 packet->buf, padded_len,
930 HIF_RD_SYNC_BLOCK_FIX);
932 packet->status = status;
938 * optimization for recv packets, we can indicate a
939 * "hint" that there are more single-packets to fetch
942 static void ath6kl_htc_rx_set_indicate(u32 lk_ahd,
943 struct htc_endpoint *endpoint,
944 struct htc_packet *packet)
946 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)&lk_ahd;
948 if (htc_hdr->eid == packet->endpoint) {
949 if (!list_empty(&endpoint->rx_bufq))
950 packet->info.rx.indicat_flags |=
951 HTC_RX_FLAGS_INDICATE_MORE_PKTS;
955 static void ath6kl_htc_rx_chk_water_mark(struct htc_endpoint *endpoint)
957 struct htc_ep_callbacks ep_cb = endpoint->ep_cb;
959 if (ep_cb.rx_refill_thresh > 0) {
960 spin_lock_bh(&endpoint->target->rx_lock);
961 if (get_queue_depth(&endpoint->rx_bufq)
962 < ep_cb.rx_refill_thresh) {
963 spin_unlock_bh(&endpoint->target->rx_lock);
964 ep_cb.rx_refill(endpoint->target, endpoint->eid);
967 spin_unlock_bh(&endpoint->target->rx_lock);
971 /* This function is called with rx_lock held */
972 static int ath6kl_htc_rx_setup(struct htc_target *target,
973 struct htc_endpoint *ep,
974 u32 *lk_ahds, struct list_head *queue, int n_msg)
976 struct htc_packet *packet;
977 /* FIXME: type of lk_ahds can't be right */
978 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)lk_ahds;
979 struct htc_ep_callbacks ep_cb;
980 int status = 0, j, full_len;
983 full_len = CALC_TXRX_PADDED_LEN(target,
984 le16_to_cpu(htc_hdr->payld_len) +
987 if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
988 ath6kl_warn("Rx buffer requested with invalid length\n");
993 for (j = 0; j < n_msg; j++) {
996 * Reset flag, any packets allocated using the
997 * rx_alloc() API cannot be recycled on
998 * cleanup,they must be explicitly returned.
1002 if (ep_cb.rx_allocthresh &&
1003 (full_len > ep_cb.rx_alloc_thresh)) {
1004 ep->ep_st.rx_alloc_thresh_hit += 1;
1005 ep->ep_st.rxalloc_thresh_byte +=
1006 le16_to_cpu(htc_hdr->payld_len);
1008 spin_unlock_bh(&target->rx_lock);
1011 packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
1013 spin_lock_bh(&target->rx_lock);
1015 /* refill handler is being used */
1016 if (list_empty(&ep->rx_bufq)) {
1017 if (ep_cb.rx_refill) {
1018 spin_unlock_bh(&target->rx_lock);
1019 ep_cb.rx_refill(ep->target, ep->eid);
1020 spin_lock_bh(&target->rx_lock);
1024 if (list_empty(&ep->rx_bufq))
1027 packet = list_first_entry(&ep->rx_bufq,
1028 struct htc_packet, list);
1029 list_del(&packet->list);
1034 target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
1035 target->ep_waiting = ep->eid;
1040 packet->info.rx.rx_flags = 0;
1041 packet->info.rx.indicat_flags = 0;
1046 * flag that these packets cannot be
1047 * recycled, they have to be returned to
1050 packet->info.rx.rx_flags |= HTC_RX_PKT_NO_RECYCLE;
1052 /* Caller needs to free this upon any failure */
1053 list_add_tail(&packet->list, queue);
1055 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1056 status = -ECANCELED;
1061 packet->info.rx.rx_flags |= HTC_RX_PKT_REFRESH_HDR;
1062 packet->info.rx.exp_hdr = 0xFFFFFFFF;
1064 /* set expected look ahead */
1065 packet->info.rx.exp_hdr = *lk_ahds;
1067 packet->act_len = le16_to_cpu(htc_hdr->payld_len) +
1074 static int ath6kl_htc_rx_alloc(struct htc_target *target,
1075 u32 lk_ahds[], int msg,
1076 struct htc_endpoint *endpoint,
1077 struct list_head *queue)
1080 struct htc_packet *packet, *tmp_pkt;
1081 struct htc_frame_hdr *htc_hdr;
1084 spin_lock_bh(&target->rx_lock);
1086 for (i = 0; i < msg; i++) {
1088 htc_hdr = (struct htc_frame_hdr *)&lk_ahds[i];
1090 if (htc_hdr->eid >= ENDPOINT_MAX) {
1091 ath6kl_err("invalid ep in look-ahead: %d\n",
1097 if (htc_hdr->eid != endpoint->eid) {
1098 ath6kl_err("invalid ep in look-ahead: %d should be : %d (index:%d)\n",
1099 htc_hdr->eid, endpoint->eid, i);
1104 if (le16_to_cpu(htc_hdr->payld_len) > HTC_MAX_PAYLOAD_LENGTH) {
1105 ath6kl_err("payload len %d exceeds max htc : %d !\n",
1107 (u32) HTC_MAX_PAYLOAD_LENGTH);
1112 if (endpoint->svc_id == 0) {
1113 ath6kl_err("ep %d is not connected !\n", htc_hdr->eid);
1118 if (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) {
1120 * HTC header indicates that every packet to follow
1121 * has the same padded length so that it can be
1122 * optimally fetched as a full bundle.
1124 n_msg = (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) >>
1125 HTC_FLG_RX_BNDL_CNT_S;
1127 /* the count doesn't include the starter frame */
1129 if (n_msg > target->msg_per_bndl_max) {
1134 endpoint->ep_st.rx_bundle_from_hdr += 1;
1135 ath6kl_dbg(ATH6KL_DBG_HTC,
1136 "htc rx bundle pkts %d\n",
1139 /* HTC header only indicates 1 message to fetch */
1142 /* Setup packet buffers for each message */
1143 status = ath6kl_htc_rx_setup(target, endpoint, &lk_ahds[i],
1147 * This is due to unavailabilty of buffers to rx entire data.
1148 * Return no error so that free buffers from queue can be used
1149 * to receive partial data.
1151 if (status == -ENOSPC) {
1152 spin_unlock_bh(&target->rx_lock);
1160 spin_unlock_bh(&target->rx_lock);
1163 list_for_each_entry_safe(packet, tmp_pkt, queue, list) {
1164 list_del(&packet->list);
1165 htc_reclaim_rxbuf(target, packet,
1166 &target->endpoint[packet->endpoint]);
1173 static void htc_ctrl_rx(struct htc_target *context, struct htc_packet *packets)
1175 if (packets->endpoint != ENDPOINT_0) {
1180 if (packets->status == -ECANCELED) {
1181 reclaim_rx_ctrl_buf(context, packets);
1185 if (packets->act_len > 0) {
1186 ath6kl_err("htc_ctrl_rx, got message with len:%zu\n",
1187 packets->act_len + HTC_HDR_LENGTH);
1189 ath6kl_dbg_dump(ATH6KL_DBG_HTC,
1190 "htc rx unexpected endpoint 0 message", "",
1191 packets->buf - HTC_HDR_LENGTH,
1192 packets->act_len + HTC_HDR_LENGTH);
1195 htc_reclaim_rxbuf(context, packets, &context->endpoint[0]);
1198 static void htc_proc_cred_rpt(struct htc_target *target,
1199 struct htc_credit_report *rpt,
1201 enum htc_endpoint_id from_ep)
1203 struct htc_endpoint *endpoint;
1204 int tot_credits = 0, i;
1207 ath6kl_dbg(ATH6KL_DBG_HTC,
1208 "htc creds report entries %d\n", n_entries);
1210 spin_lock_bh(&target->tx_lock);
1212 for (i = 0; i < n_entries; i++, rpt++) {
1213 if (rpt->eid >= ENDPOINT_MAX) {
1215 spin_unlock_bh(&target->tx_lock);
1219 endpoint = &target->endpoint[rpt->eid];
1221 ath6kl_dbg(ATH6KL_DBG_HTC,
1222 "htc creds report ep %d credits %d\n",
1223 rpt->eid, rpt->credits);
1225 endpoint->ep_st.tx_cred_rpt += 1;
1226 endpoint->ep_st.cred_retnd += rpt->credits;
1228 if (from_ep == rpt->eid) {
1230 * This credit report arrived on the same endpoint
1231 * indicating it arrived in an RX packet.
1233 endpoint->ep_st.cred_from_rx += rpt->credits;
1234 endpoint->ep_st.cred_rpt_from_rx += 1;
1235 } else if (from_ep == ENDPOINT_0) {
1236 /* credit arrived on endpoint 0 as a NULL message */
1237 endpoint->ep_st.cred_from_ep0 += rpt->credits;
1238 endpoint->ep_st.cred_rpt_ep0 += 1;
1240 endpoint->ep_st.cred_from_other += rpt->credits;
1241 endpoint->ep_st.cred_rpt_from_other += 1;
1244 if (rpt->eid == ENDPOINT_0)
1245 /* always give endpoint 0 credits back */
1246 endpoint->cred_dist.credits += rpt->credits;
1248 endpoint->cred_dist.cred_to_dist += rpt->credits;
1253 * Refresh tx depth for distribution function that will
1254 * recover these credits NOTE: this is only valid when
1255 * there are credits to recover!
1257 endpoint->cred_dist.txq_depth =
1258 get_queue_depth(&endpoint->txq);
1260 tot_credits += rpt->credits;
1263 ath6kl_dbg(ATH6KL_DBG_HTC,
1264 "htc creds report tot_credits %d\n",
1269 * This was a credit return based on a completed send
1270 * operations note, this is done with the lock held
1272 ath6kl_dbg(ATH6KL_DBG_HTC, "htc creds ctxt 0x%p dist 0x%p\n",
1273 target->cred_dist_cntxt, &target->cred_dist_list);
1275 ath6kl_credit_distribute(target->cred_dist_cntxt,
1276 &target->cred_dist_list,
1277 HTC_CREDIT_DIST_SEND_COMPLETE);
1280 spin_unlock_bh(&target->tx_lock);
1283 htc_chk_ep_txq(target);
1286 static int htc_parse_trailer(struct htc_target *target,
1287 struct htc_record_hdr *record,
1288 u8 *record_buf, u32 *next_lk_ahds,
1289 enum htc_endpoint_id endpoint,
1292 struct htc_bundle_lkahd_rpt *bundle_lkahd_rpt;
1293 struct htc_lookahead_report *lk_ahd;
1296 switch (record->rec_id) {
1297 case HTC_RECORD_CREDITS:
1298 len = record->len / sizeof(struct htc_credit_report);
1304 htc_proc_cred_rpt(target,
1305 (struct htc_credit_report *) record_buf,
1308 case HTC_RECORD_LOOKAHEAD:
1309 len = record->len / sizeof(*lk_ahd);
1315 lk_ahd = (struct htc_lookahead_report *) record_buf;
1316 if ((lk_ahd->pre_valid == ((~lk_ahd->post_valid) & 0xFF))
1319 ath6kl_dbg(ATH6KL_DBG_HTC,
1320 "htc rx lk_ahd found pre_valid 0x%x post_valid 0x%x\n",
1321 lk_ahd->pre_valid, lk_ahd->post_valid);
1323 /* look ahead bytes are valid, copy them over */
1324 memcpy((u8 *)&next_lk_ahds[0], lk_ahd->lk_ahd, 4);
1326 ath6kl_dbg_dump(ATH6KL_DBG_HTC,
1327 "htc rx next look ahead",
1328 "", next_lk_ahds, 4);
1333 case HTC_RECORD_LOOKAHEAD_BUNDLE:
1334 len = record->len / sizeof(*bundle_lkahd_rpt);
1335 if (!len || (len > HTC_HOST_MAX_MSG_PER_BUNDLE)) {
1344 (struct htc_bundle_lkahd_rpt *) record_buf;
1346 ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bundle lk_ahd",
1347 "", record_buf, record->len);
1349 for (i = 0; i < len; i++) {
1350 memcpy((u8 *)&next_lk_ahds[i],
1351 bundle_lkahd_rpt->lk_ahd, 4);
1359 ath6kl_err("unhandled record: id:%d len:%d\n",
1360 record->rec_id, record->len);
1368 static int htc_proc_trailer(struct htc_target *target,
1369 u8 *buf, int len, u32 *next_lk_ahds,
1370 int *n_lk_ahds, enum htc_endpoint_id endpoint)
1372 struct htc_record_hdr *record;
1378 ath6kl_dbg(ATH6KL_DBG_HTC, "htc rx trailer len %d\n", len);
1379 ath6kl_dbg_dump(ATH6KL_DBG_HTC, NULL, "", buf, len);
1387 if (len < sizeof(struct htc_record_hdr)) {
1391 /* these are byte aligned structs */
1392 record = (struct htc_record_hdr *) buf;
1393 len -= sizeof(struct htc_record_hdr);
1394 buf += sizeof(struct htc_record_hdr);
1396 if (record->len > len) {
1397 ath6kl_err("invalid record len: %d (id:%d) buf has: %d bytes left\n",
1398 record->len, record->rec_id, len);
1404 status = htc_parse_trailer(target, record, record_buf,
1405 next_lk_ahds, endpoint, n_lk_ahds);
1410 /* advance buffer past this record for next time around */
1416 ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad trailer",
1417 "", orig_buf, orig_len);
1422 static int ath6kl_htc_rx_process_hdr(struct htc_target *target,
1423 struct htc_packet *packet,
1424 u32 *next_lkahds, int *n_lkahds)
1429 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)packet->buf;
1431 if (n_lkahds != NULL)
1435 * NOTE: we cannot assume the alignment of buf, so we use the safe
1436 * macros to retrieve 16 bit fields.
1438 payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
1440 memcpy((u8 *)&lk_ahd, packet->buf, sizeof(lk_ahd));
1442 if (packet->info.rx.rx_flags & HTC_RX_PKT_REFRESH_HDR) {
1444 * Refresh the expected header and the actual length as it
1445 * was unknown when this packet was grabbed as part of the
1448 packet->info.rx.exp_hdr = lk_ahd;
1449 packet->act_len = payload_len + HTC_HDR_LENGTH;
1451 /* validate the actual header that was refreshed */
1452 if (packet->act_len > packet->buf_len) {
1453 ath6kl_err("refreshed hdr payload len (%d) in bundled recv is invalid (hdr: 0x%X)\n",
1454 payload_len, lk_ahd);
1456 * Limit this to max buffer just to print out some
1459 packet->act_len = min(packet->act_len, packet->buf_len);
1464 if (packet->endpoint != htc_hdr->eid) {
1465 ath6kl_err("refreshed hdr ep (%d) does not match expected ep (%d)\n",
1466 htc_hdr->eid, packet->endpoint);
1472 if (lk_ahd != packet->info.rx.exp_hdr) {
1473 ath6kl_err("%s(): lk_ahd mismatch! (pPkt:0x%p flags:0x%X)\n",
1474 __func__, packet, packet->info.rx.rx_flags);
1475 ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx expected lk_ahd",
1476 "", &packet->info.rx.exp_hdr, 4);
1477 ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx current header",
1478 "", (u8 *)&lk_ahd, sizeof(lk_ahd));
1483 if (htc_hdr->flags & HTC_FLG_RX_TRAILER) {
1484 if (htc_hdr->ctrl[0] < sizeof(struct htc_record_hdr) ||
1485 htc_hdr->ctrl[0] > payload_len) {
1486 ath6kl_err("%s(): invalid hdr (payload len should be :%d, CB[0] is:%d)\n",
1487 __func__, payload_len, htc_hdr->ctrl[0]);
1492 if (packet->info.rx.rx_flags & HTC_RX_PKT_IGNORE_LOOKAHEAD) {
1497 status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
1498 + payload_len - htc_hdr->ctrl[0],
1499 htc_hdr->ctrl[0], next_lkahds,
1500 n_lkahds, packet->endpoint);
1505 packet->act_len -= htc_hdr->ctrl[0];
1508 packet->buf += HTC_HDR_LENGTH;
1509 packet->act_len -= HTC_HDR_LENGTH;
1513 ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad packet",
1514 "", packet->buf, packet->act_len);
1519 static void ath6kl_htc_rx_complete(struct htc_endpoint *endpoint,
1520 struct htc_packet *packet)
1522 ath6kl_dbg(ATH6KL_DBG_HTC,
1523 "htc rx complete ep %d packet 0x%p\n",
1524 endpoint->eid, packet);
1525 endpoint->ep_cb.rx(endpoint->target, packet);
1528 static int ath6kl_htc_rx_bundle(struct htc_target *target,
1529 struct list_head *rxq,
1530 struct list_head *sync_compq,
1531 int *n_pkt_fetched, bool part_bundle)
1533 struct hif_scatter_req *scat_req;
1534 struct htc_packet *packet;
1535 int rem_space = target->max_rx_bndl_sz;
1536 int n_scat_pkt, status = 0, i, len;
1538 n_scat_pkt = get_queue_depth(rxq);
1539 n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
1541 if ((get_queue_depth(rxq) - n_scat_pkt) > 0) {
1543 * We were forced to split this bundle receive operation
1544 * all packets in this partial bundle must have their
1545 * lookaheads ignored.
1550 * This would only happen if the target ignored our max
1553 ath6kl_warn("%s(): partial bundle detected num:%d , %d\n",
1554 __func__, get_queue_depth(rxq), n_scat_pkt);
1559 ath6kl_dbg(ATH6KL_DBG_HTC,
1560 "htc rx bundle depth %d pkts %d\n",
1561 get_queue_depth(rxq), n_scat_pkt);
1563 scat_req = hif_scatter_req_get(target->dev->ar);
1565 if (scat_req == NULL)
1568 for (i = 0; i < n_scat_pkt; i++) {
1571 packet = list_first_entry(rxq, struct htc_packet, list);
1572 list_del(&packet->list);
1574 pad_len = CALC_TXRX_PADDED_LEN(target,
1577 if ((rem_space - pad_len) < 0) {
1578 list_add(&packet->list, rxq);
1582 rem_space -= pad_len;
1584 if (part_bundle || (i < (n_scat_pkt - 1)))
1586 * Packet 0..n-1 cannot be checked for look-aheads
1587 * since we are fetching a bundle the last packet
1588 * however can have it's lookahead used
1590 packet->info.rx.rx_flags |=
1591 HTC_RX_PKT_IGNORE_LOOKAHEAD;
1593 /* NOTE: 1 HTC packet per scatter entry */
1594 scat_req->scat_list[i].buf = packet->buf;
1595 scat_req->scat_list[i].len = pad_len;
1597 packet->info.rx.rx_flags |= HTC_RX_PKT_PART_OF_BUNDLE;
1599 list_add_tail(&packet->list, sync_compq);
1601 WARN_ON(!scat_req->scat_list[i].len);
1602 len += scat_req->scat_list[i].len;
1605 scat_req->len = len;
1606 scat_req->scat_entries = i;
1608 status = ath6kl_hif_submit_scat_req(target->dev, scat_req, true);
1613 /* free scatter request */
1614 hif_scatter_req_add(target->dev->ar, scat_req);
1621 static int ath6kl_htc_rx_process_packets(struct htc_target *target,
1622 struct list_head *comp_pktq,
1626 struct htc_packet *packet, *tmp_pkt;
1627 struct htc_endpoint *ep;
1630 list_for_each_entry_safe(packet, tmp_pkt, comp_pktq, list) {
1631 ep = &target->endpoint[packet->endpoint];
1633 /* process header for each of the recv packet */
1634 status = ath6kl_htc_rx_process_hdr(target, packet, lk_ahds,
1639 list_del(&packet->list);
1641 if (list_empty(comp_pktq)) {
1643 * Last packet's more packet flag is set
1644 * based on the lookahead.
1647 ath6kl_htc_rx_set_indicate(lk_ahds[0],
1651 * Packets in a bundle automatically have
1654 packet->info.rx.indicat_flags |=
1655 HTC_RX_FLAGS_INDICATE_MORE_PKTS;
1657 ath6kl_htc_rx_update_stats(ep, *n_lk_ahd);
1659 if (packet->info.rx.rx_flags & HTC_RX_PKT_PART_OF_BUNDLE)
1660 ep->ep_st.rx_bundl += 1;
1662 ath6kl_htc_rx_complete(ep, packet);
1668 static int ath6kl_htc_rx_fetch(struct htc_target *target,
1669 struct list_head *rx_pktq,
1670 struct list_head *comp_pktq)
1673 bool part_bundle = false;
1675 struct list_head tmp_rxq;
1676 struct htc_packet *packet, *tmp_pkt;
1678 /* now go fetch the list of HTC packets */
1679 while (!list_empty(rx_pktq)) {
1682 INIT_LIST_HEAD(&tmp_rxq);
1684 if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
1686 * There are enough packets to attempt a
1687 * bundle transfer and recv bundling is
1690 status = ath6kl_htc_rx_bundle(target, rx_pktq,
1697 if (!list_empty(rx_pktq))
1700 list_splice_tail_init(&tmp_rxq, comp_pktq);
1703 if (!fetched_pkts) {
1705 packet = list_first_entry(rx_pktq, struct htc_packet,
1708 /* fully synchronous */
1709 packet->completion = NULL;
1711 if (!list_is_singular(rx_pktq))
1713 * look_aheads in all packet
1714 * except the last one in the
1715 * bundle must be ignored
1717 packet->info.rx.rx_flags |=
1718 HTC_RX_PKT_IGNORE_LOOKAHEAD;
1720 /* go fetch the packet */
1721 status = ath6kl_htc_rx_packet(target, packet,
1724 list_move_tail(&packet->list, &tmp_rxq);
1729 list_splice_tail_init(&tmp_rxq, comp_pktq);
1738 * Cleanup any packets we allocated but didn't use to
1739 * actually fetch any packets.
1742 list_for_each_entry_safe(packet, tmp_pkt, rx_pktq, list) {
1743 list_del(&packet->list);
1744 htc_reclaim_rxbuf(target, packet,
1745 &target->endpoint[packet->endpoint]);
1748 list_for_each_entry_safe(packet, tmp_pkt, &tmp_rxq, list) {
1749 list_del(&packet->list);
1750 htc_reclaim_rxbuf(target, packet,
1751 &target->endpoint[packet->endpoint]);
1757 int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
1758 u32 msg_look_ahead, int *num_pkts)
1760 struct htc_packet *packets, *tmp_pkt;
1761 struct htc_endpoint *endpoint;
1762 struct list_head rx_pktq, comp_pktq;
1764 u32 look_aheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
1765 int num_look_ahead = 1;
1766 enum htc_endpoint_id id;
1772 * On first entry copy the look_aheads into our temp array for
1775 look_aheads[0] = msg_look_ahead;
1780 * First lookahead sets the expected endpoint IDs for all
1781 * packets in a bundle.
1783 id = ((struct htc_frame_hdr *)&look_aheads[0])->eid;
1784 endpoint = &target->endpoint[id];
1786 if (id >= ENDPOINT_MAX) {
1787 ath6kl_err("MsgPend, invalid endpoint in look-ahead: %d\n",
1793 INIT_LIST_HEAD(&rx_pktq);
1794 INIT_LIST_HEAD(&comp_pktq);
1797 * Try to allocate as many HTC RX packets indicated by the
1800 status = ath6kl_htc_rx_alloc(target, look_aheads,
1801 num_look_ahead, endpoint,
1806 if (get_queue_depth(&rx_pktq) >= 2)
1808 * A recv bundle was detected, force IRQ status
1811 target->chk_irq_status_cnt = 1;
1813 n_fetched += get_queue_depth(&rx_pktq);
1817 status = ath6kl_htc_rx_fetch(target, &rx_pktq, &comp_pktq);
1820 ath6kl_htc_rx_chk_water_mark(endpoint);
1822 /* Process fetched packets */
1823 status = ath6kl_htc_rx_process_packets(target, &comp_pktq,
1827 if (!num_look_ahead || status)
1831 * For SYNCH processing, if we get here, we are running
1832 * through the loop again due to a detected lookahead. Set
1833 * flag that we should re-check IRQ status registers again
1834 * before leaving IRQ processing, this can net better
1835 * performance in high throughput situations.
1837 target->chk_irq_status_cnt = 1;
1841 ath6kl_err("failed to get pending recv messages: %d\n",
1844 /* cleanup any packets in sync completion queue */
1845 list_for_each_entry_safe(packets, tmp_pkt, &comp_pktq, list) {
1846 list_del(&packets->list);
1847 htc_reclaim_rxbuf(target, packets,
1848 &target->endpoint[packets->endpoint]);
1851 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1852 ath6kl_warn("host is going to stop blocking receiver for htc_stop\n");
1853 ath6kl_hif_rx_control(target->dev, false);
1858 * Before leaving, check to see if host ran out of buffers and
1859 * needs to stop the receiver.
1861 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
1862 ath6kl_warn("host has no rx buffers blocking receiver to prevent overrun\n");
1863 ath6kl_hif_rx_control(target->dev, false);
1865 *num_pkts = n_fetched;
1871 * Synchronously wait for a control message from the target,
1872 * This function is used at initialization time ONLY. At init messages
1873 * on ENDPOINT 0 are expected.
1875 static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
1877 struct htc_packet *packet = NULL;
1878 struct htc_frame_hdr *htc_hdr;
1881 if (ath6kl_hif_poll_mboxmsg_rx(target->dev, &look_ahead,
1882 HTC_TARGET_RESPONSE_TIMEOUT))
1885 ath6kl_dbg(ATH6KL_DBG_HTC,
1886 "htc rx wait ctrl look_ahead 0x%X\n", look_ahead);
1888 htc_hdr = (struct htc_frame_hdr *)&look_ahead;
1890 if (htc_hdr->eid != ENDPOINT_0)
1893 packet = htc_get_control_buf(target, false);
1898 packet->info.rx.rx_flags = 0;
1899 packet->info.rx.exp_hdr = look_ahead;
1900 packet->act_len = le16_to_cpu(htc_hdr->payld_len) + HTC_HDR_LENGTH;
1902 if (packet->act_len > packet->buf_len)
1905 /* we want synchronous operation */
1906 packet->completion = NULL;
1908 /* get the message from the device, this will block */
1909 if (ath6kl_htc_rx_packet(target, packet, packet->act_len))
1912 /* process receive header */
1913 packet->status = ath6kl_htc_rx_process_hdr(target, packet, NULL, NULL);
1915 if (packet->status) {
1916 ath6kl_err("htc_wait_for_ctrl_msg, ath6kl_htc_rx_process_hdr failed (status = %d)\n",
1924 if (packet != NULL) {
1925 htc_rxpkt_reset(packet);
1926 reclaim_rx_ctrl_buf(target, packet);
1932 int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
1933 struct list_head *pkt_queue)
1935 struct htc_endpoint *endpoint;
1936 struct htc_packet *first_pkt;
1937 bool rx_unblock = false;
1938 int status = 0, depth;
1940 if (list_empty(pkt_queue))
1943 first_pkt = list_first_entry(pkt_queue, struct htc_packet, list);
1945 if (first_pkt->endpoint >= ENDPOINT_MAX)
1948 depth = get_queue_depth(pkt_queue);
1950 ath6kl_dbg(ATH6KL_DBG_HTC,
1951 "htc rx add multiple ep id %d cnt %d len %d\n",
1952 first_pkt->endpoint, depth, first_pkt->buf_len);
1954 endpoint = &target->endpoint[first_pkt->endpoint];
1956 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1957 struct htc_packet *packet, *tmp_pkt;
1959 /* walk through queue and mark each one canceled */
1960 list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
1961 packet->status = -ECANCELED;
1962 list_del(&packet->list);
1963 ath6kl_htc_rx_complete(endpoint, packet);
1969 spin_lock_bh(&target->rx_lock);
1971 list_splice_tail_init(pkt_queue, &endpoint->rx_bufq);
1973 /* check if we are blocked waiting for a new buffer */
1974 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
1975 if (target->ep_waiting == first_pkt->endpoint) {
1976 ath6kl_dbg(ATH6KL_DBG_HTC,
1977 "htc rx blocked on ep %d, unblocking\n",
1978 target->ep_waiting);
1979 target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
1980 target->ep_waiting = ENDPOINT_MAX;
1985 spin_unlock_bh(&target->rx_lock);
1987 if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
1988 /* TODO : implement a buffer threshold count? */
1989 ath6kl_hif_rx_control(target->dev, true);
1994 void ath6kl_htc_flush_rx_buf(struct htc_target *target)
1996 struct htc_endpoint *endpoint;
1997 struct htc_packet *packet, *tmp_pkt;
2000 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
2001 endpoint = &target->endpoint[i];
2002 if (!endpoint->svc_id)
2006 spin_lock_bh(&target->rx_lock);
2007 list_for_each_entry_safe(packet, tmp_pkt,
2008 &endpoint->rx_bufq, list) {
2009 list_del(&packet->list);
2010 spin_unlock_bh(&target->rx_lock);
2011 ath6kl_dbg(ATH6KL_DBG_HTC,
2012 "htc rx flush pkt 0x%p len %d ep %d\n",
2013 packet, packet->buf_len,
2015 dev_kfree_skb(packet->pkt_cntxt);
2016 spin_lock_bh(&target->rx_lock);
2018 spin_unlock_bh(&target->rx_lock);
2022 int ath6kl_htc_conn_service(struct htc_target *target,
2023 struct htc_service_connect_req *conn_req,
2024 struct htc_service_connect_resp *conn_resp)
2026 struct htc_packet *rx_pkt = NULL;
2027 struct htc_packet *tx_pkt = NULL;
2028 struct htc_conn_service_resp *resp_msg;
2029 struct htc_conn_service_msg *conn_msg;
2030 struct htc_endpoint *endpoint;
2031 enum htc_endpoint_id assigned_ep = ENDPOINT_MAX;
2032 unsigned int max_msg_sz = 0;
2035 ath6kl_dbg(ATH6KL_DBG_HTC,
2036 "htc connect service target 0x%p service id 0x%x\n",
2037 target, conn_req->svc_id);
2039 if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
2040 /* special case for pseudo control service */
2041 assigned_ep = ENDPOINT_0;
2042 max_msg_sz = HTC_MAX_CTRL_MSG_LEN;
2044 /* allocate a packet to send to the target */
2045 tx_pkt = htc_get_control_buf(target, true);
2050 conn_msg = (struct htc_conn_service_msg *)tx_pkt->buf;
2051 memset(conn_msg, 0, sizeof(*conn_msg));
2052 conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
2053 conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
2054 conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags);
2056 set_htc_pkt_info(tx_pkt, NULL, (u8 *) conn_msg,
2057 sizeof(*conn_msg) + conn_msg->svc_meta_len,
2058 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
2060 /* we want synchronous operation */
2061 tx_pkt->completion = NULL;
2062 ath6kl_htc_tx_prep_pkt(tx_pkt, 0, 0, 0);
2063 status = ath6kl_htc_tx_issue(target, tx_pkt);
2068 /* wait for response */
2069 rx_pkt = htc_wait_for_ctrl_msg(target);
2076 resp_msg = (struct htc_conn_service_resp *)rx_pkt->buf;
2078 if ((le16_to_cpu(resp_msg->msg_id) != HTC_MSG_CONN_SVC_RESP_ID)
2079 || (rx_pkt->act_len < sizeof(*resp_msg))) {
2084 conn_resp->resp_code = resp_msg->status;
2085 /* check response status */
2086 if (resp_msg->status != HTC_SERVICE_SUCCESS) {
2087 ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
2088 resp_msg->svc_id, resp_msg->status);
2093 assigned_ep = (enum htc_endpoint_id)resp_msg->eid;
2094 max_msg_sz = le16_to_cpu(resp_msg->max_msg_sz);
2097 if (assigned_ep >= ENDPOINT_MAX || !max_msg_sz) {
2102 endpoint = &target->endpoint[assigned_ep];
2103 endpoint->eid = assigned_ep;
2104 if (endpoint->svc_id) {
2109 /* return assigned endpoint to caller */
2110 conn_resp->endpoint = assigned_ep;
2111 conn_resp->len_max = max_msg_sz;
2113 /* setup the endpoint */
2115 /* this marks the endpoint in use */
2116 endpoint->svc_id = conn_req->svc_id;
2118 endpoint->max_txq_depth = conn_req->max_txq_depth;
2119 endpoint->len_max = max_msg_sz;
2120 endpoint->ep_cb = conn_req->ep_cb;
2121 endpoint->cred_dist.svc_id = conn_req->svc_id;
2122 endpoint->cred_dist.htc_rsvd = endpoint;
2123 endpoint->cred_dist.endpoint = assigned_ep;
2124 endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
2126 if (conn_req->max_rxmsg_sz) {
2128 * Override cred_per_msg calculation, this optimizes
2129 * the credit-low indications since the host will actually
2130 * issue smaller messages in the Send path.
2132 if (conn_req->max_rxmsg_sz > max_msg_sz) {
2136 endpoint->cred_dist.cred_per_msg =
2137 conn_req->max_rxmsg_sz / target->tgt_cred_sz;
2139 endpoint->cred_dist.cred_per_msg =
2140 max_msg_sz / target->tgt_cred_sz;
2142 if (!endpoint->cred_dist.cred_per_msg)
2143 endpoint->cred_dist.cred_per_msg = 1;
2145 /* save local connection flags */
2146 endpoint->conn_flags = conn_req->flags;
2150 htc_reclaim_txctrl_buf(target, tx_pkt);
2153 htc_rxpkt_reset(rx_pkt);
2154 reclaim_rx_ctrl_buf(target, rx_pkt);
2160 static void reset_ep_state(struct htc_target *target)
2162 struct htc_endpoint *endpoint;
2165 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
2166 endpoint = &target->endpoint[i];
2167 memset(&endpoint->cred_dist, 0, sizeof(endpoint->cred_dist));
2168 endpoint->svc_id = 0;
2169 endpoint->len_max = 0;
2170 endpoint->max_txq_depth = 0;
2171 memset(&endpoint->ep_st, 0,
2172 sizeof(endpoint->ep_st));
2173 INIT_LIST_HEAD(&endpoint->rx_bufq);
2174 INIT_LIST_HEAD(&endpoint->txq);
2175 endpoint->target = target;
2178 /* reset distribution list */
2179 INIT_LIST_HEAD(&target->cred_dist_list);
2182 int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
2183 enum htc_endpoint_id endpoint)
2187 spin_lock_bh(&target->rx_lock);
2188 num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
2189 spin_unlock_bh(&target->rx_lock);
2193 static void htc_setup_msg_bndl(struct htc_target *target)
2195 /* limit what HTC can handle */
2196 target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
2197 target->msg_per_bndl_max);
2199 if (ath6kl_hif_enable_scatter(target->dev->ar)) {
2200 target->msg_per_bndl_max = 0;
2204 /* limit bundle what the device layer can handle */
2205 target->msg_per_bndl_max = min(target->max_scat_entries,
2206 target->msg_per_bndl_max);
2208 ath6kl_dbg(ATH6KL_DBG_HTC,
2209 "htc bundling allowed msg_per_bndl_max %d\n",
2210 target->msg_per_bndl_max);
2212 /* Max rx bundle size is limited by the max tx bundle size */
2213 target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
2214 /* Max tx bundle size if limited by the extended mbox address range */
2215 target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
2216 target->max_xfer_szper_scatreq);
2218 ath6kl_dbg(ATH6KL_DBG_HTC, "htc max_rx_bndl_sz %d max_tx_bndl_sz %d\n",
2219 target->max_rx_bndl_sz, target->max_tx_bndl_sz);
2221 if (target->max_tx_bndl_sz)
2222 target->tx_bndl_enable = true;
2224 if (target->max_rx_bndl_sz)
2225 target->rx_bndl_enable = true;
2227 if ((target->tgt_cred_sz % target->block_sz) != 0) {
2228 ath6kl_warn("credit size: %d is not block aligned! Disabling send bundling\n",
2229 target->tgt_cred_sz);
2232 * Disallow send bundling since the credit size is
2233 * not aligned to a block size the I/O block
2234 * padding will spill into the next credit buffer
2237 target->tx_bndl_enable = false;
2241 int ath6kl_htc_wait_target(struct htc_target *target)
2243 struct htc_packet *packet = NULL;
2244 struct htc_ready_ext_msg *rdy_msg;
2245 struct htc_service_connect_req connect;
2246 struct htc_service_connect_resp resp;
2249 /* we should be getting 1 control message that the target is ready */
2250 packet = htc_wait_for_ctrl_msg(target);
2255 /* we controlled the buffer creation so it's properly aligned */
2256 rdy_msg = (struct htc_ready_ext_msg *)packet->buf;
2258 if ((le16_to_cpu(rdy_msg->ver2_0_info.msg_id) != HTC_MSG_READY_ID) ||
2259 (packet->act_len < sizeof(struct htc_ready_msg))) {
2261 goto fail_wait_target;
2264 if (!rdy_msg->ver2_0_info.cred_cnt || !rdy_msg->ver2_0_info.cred_sz) {
2266 goto fail_wait_target;
2269 target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
2270 target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
2272 ath6kl_dbg(ATH6KL_DBG_HTC,
2273 "htc target ready credits %d size %d\n",
2274 target->tgt_creds, target->tgt_cred_sz);
2276 /* check if this is an extended ready message */
2277 if (packet->act_len >= sizeof(struct htc_ready_ext_msg)) {
2278 /* this is an extended message */
2279 target->htc_tgt_ver = rdy_msg->htc_ver;
2280 target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
2283 target->htc_tgt_ver = HTC_VERSION_2P0;
2284 target->msg_per_bndl_max = 0;
2287 ath6kl_dbg(ATH6KL_DBG_HTC, "htc using protocol %s (%d)\n",
2288 (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
2289 target->htc_tgt_ver);
2291 if (target->msg_per_bndl_max > 0)
2292 htc_setup_msg_bndl(target);
2294 /* setup our pseudo HTC control endpoint connection */
2295 memset(&connect, 0, sizeof(connect));
2296 memset(&resp, 0, sizeof(resp));
2297 connect.ep_cb.rx = htc_ctrl_rx;
2298 connect.ep_cb.rx_refill = NULL;
2299 connect.ep_cb.tx_full = NULL;
2300 connect.max_txq_depth = NUM_CONTROL_BUFFERS;
2301 connect.svc_id = HTC_CTRL_RSVD_SVC;
2303 /* connect fake service */
2304 status = ath6kl_htc_conn_service((void *)target, &connect, &resp);
2307 ath6kl_hif_cleanup_scatter(target->dev->ar);
2311 htc_rxpkt_reset(packet);
2312 reclaim_rx_ctrl_buf(target, packet);
2319 * Start HTC, enable interrupts and let the target know
2320 * host has finished setup.
2322 int ath6kl_htc_start(struct htc_target *target)
2324 struct htc_packet *packet;
2327 /* Disable interrupts at the chip level */
2328 ath6kl_hif_disable_intrs(target->dev);
2330 target->htc_flags = 0;
2331 target->rx_st_flags = 0;
2333 /* Push control receive buffers into htc control endpoint */
2334 while ((packet = htc_get_control_buf(target, false)) != NULL) {
2335 status = htc_add_rxbuf(target, packet);
2340 /* NOTE: the first entry in the distribution list is ENDPOINT_0 */
2341 ath6kl_credit_init(target->cred_dist_cntxt, &target->cred_dist_list,
2344 dump_cred_dist_stats(target);
2346 /* Indicate to the target of the setup completion */
2347 status = htc_setup_tx_complete(target);
2352 /* unmask interrupts */
2353 status = ath6kl_hif_unmask_intrs(target->dev);
2356 ath6kl_htc_stop(target);
2361 /* htc_stop: stop interrupt reception, and flush all queued buffers */
2362 void ath6kl_htc_stop(struct htc_target *target)
2364 spin_lock_bh(&target->htc_lock);
2365 target->htc_flags |= HTC_OP_STATE_STOPPING;
2366 spin_unlock_bh(&target->htc_lock);
2369 * Masking interrupts is a synchronous operation, when this
2370 * function returns all pending HIF I/O has completed, we can
2371 * safely flush the queues.
2373 ath6kl_hif_mask_intrs(target->dev);
2375 ath6kl_htc_flush_txep_all(target);
2377 ath6kl_htc_flush_rx_buf(target);
2379 reset_ep_state(target);
2382 void *ath6kl_htc_create(struct ath6kl *ar)
2384 struct htc_target *target = NULL;
2385 struct htc_packet *packet;
2386 int status = 0, i = 0;
2387 u32 block_size, ctrl_bufsz;
2389 target = kzalloc(sizeof(*target), GFP_KERNEL);
2391 ath6kl_err("unable to allocate memory\n");
2395 target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
2397 ath6kl_err("unable to allocate memory\n");
2399 goto fail_create_htc;
2402 spin_lock_init(&target->htc_lock);
2403 spin_lock_init(&target->rx_lock);
2404 spin_lock_init(&target->tx_lock);
2406 INIT_LIST_HEAD(&target->free_ctrl_txbuf);
2407 INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
2408 INIT_LIST_HEAD(&target->cred_dist_list);
2410 target->dev->ar = ar;
2411 target->dev->htc_cnxt = target;
2412 target->ep_waiting = ENDPOINT_MAX;
2414 reset_ep_state(target);
2416 status = ath6kl_hif_setup(target->dev);
2419 goto fail_create_htc;
2421 block_size = ar->mbox_info.block_size;
2423 ctrl_bufsz = (block_size > HTC_MAX_CTRL_MSG_LEN) ?
2424 (block_size + HTC_HDR_LENGTH) :
2425 (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH);
2427 for (i = 0; i < NUM_CONTROL_BUFFERS; i++) {
2428 packet = kzalloc(sizeof(*packet), GFP_KERNEL);
2432 packet->buf_start = kzalloc(ctrl_bufsz, GFP_KERNEL);
2433 if (!packet->buf_start) {
2438 packet->buf_len = ctrl_bufsz;
2439 if (i < NUM_CONTROL_RX_BUFFERS) {
2440 packet->act_len = 0;
2441 packet->buf = packet->buf_start;
2442 packet->endpoint = ENDPOINT_0;
2443 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
2445 list_add_tail(&packet->list, &target->free_ctrl_txbuf);
2449 if (i != NUM_CONTROL_BUFFERS || status) {
2451 ath6kl_htc_cleanup(target);
2459 /* cleanup the HTC instance */
2460 void ath6kl_htc_cleanup(struct htc_target *target)
2462 struct htc_packet *packet, *tmp_packet;
2464 ath6kl_hif_cleanup_scatter(target->dev->ar);
2466 list_for_each_entry_safe(packet, tmp_packet,
2467 &target->free_ctrl_txbuf, list) {
2468 list_del(&packet->list);
2469 kfree(packet->buf_start);
2473 list_for_each_entry_safe(packet, tmp_packet,
2474 &target->free_ctrl_rxbuf, list) {
2475 list_del(&packet->list);
2476 kfree(packet->buf_start);