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_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 htc_prep_send_pkt(struct htc_packet *packet, u8 flags, int ctrl0,
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_SEND, "ctxt:0x%p dist:0x%p\n",
106 target->cred_dist_cntxt, &target->cred_dist_list);
108 ath6k_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_SEND,
122 "send complete ep %d, (%d pkts)\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_SEND,
152 "htc_async_tx_scat_complete total 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 htc_issue_send(struct htc_target *target, struct htc_packet *packet)
185 u32 padded_len, send_len;
187 if (!packet->completion)
190 send_len = packet->act_len + HTC_HDR_LENGTH;
192 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "%s: transmit len : %d (%s)\n",
193 __func__, send_len, sync ? "sync" : "async");
195 padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
197 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
198 "DevSendPacket, padded len: %d mbox:0x%X (mode:%s)\n",
200 target->dev->ar->mbox_info.htc_addr,
201 sync ? "sync" : "async");
204 status = hif_read_write_sync(target->dev->ar,
205 target->dev->ar->mbox_info.htc_addr,
206 packet->buf, padded_len,
207 HIF_WR_SYNC_BLOCK_INC);
209 packet->status = status;
210 packet->buf += HTC_HDR_LENGTH;
212 status = hif_write_async(target->dev->ar,
213 target->dev->ar->mbox_info.htc_addr,
214 packet->buf, padded_len,
215 HIF_WR_ASYNC_BLOCK_INC, packet);
220 static int htc_check_credits(struct htc_target *target,
221 struct htc_endpoint *ep, u8 *flags,
222 enum htc_endpoint_id eid, unsigned int len,
226 *req_cred = (len > target->tgt_cred_sz) ?
227 DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
229 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "creds required:%d got:%d\n",
230 *req_cred, ep->cred_dist.credits);
232 if (ep->cred_dist.credits < *req_cred) {
233 if (eid == ENDPOINT_0)
236 /* Seek more credits */
237 ep->cred_dist.seek_cred = *req_cred - ep->cred_dist.credits;
239 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
240 target->cred_dist_cntxt, &ep->cred_dist);
242 ath6k_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
244 ep->cred_dist.seek_cred = 0;
246 if (ep->cred_dist.credits < *req_cred) {
247 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
248 "not enough credits for ep %d - leaving packet in queue\n",
254 ep->cred_dist.credits -= *req_cred;
255 ep->ep_st.cred_cosumd += *req_cred;
257 /* When we are getting low on credits, ask for more */
258 if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
259 ep->cred_dist.seek_cred =
260 ep->cred_dist.cred_per_msg - ep->cred_dist.credits;
262 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
263 target->cred_dist_cntxt, &ep->cred_dist);
265 ath6k_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
267 /* see if we were successful in getting more */
268 if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
269 /* tell the target we need credits ASAP! */
270 *flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
271 ep->ep_st.cred_low_indicate += 1;
272 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "host needs credits\n");
279 static void htc_tx_pkts_get(struct htc_target *target,
280 struct htc_endpoint *endpoint,
281 struct list_head *queue)
285 struct htc_packet *packet;
292 if (list_empty(&endpoint->txq))
294 packet = list_first_entry(&endpoint->txq, struct htc_packet,
297 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
298 "got head pkt:0x%p , queue depth: %d\n",
299 packet, get_queue_depth(&endpoint->txq));
301 len = CALC_TXRX_PADDED_LEN(target,
302 packet->act_len + HTC_HDR_LENGTH);
304 if (htc_check_credits(target, endpoint, &flags,
305 packet->endpoint, len, &req_cred))
308 /* now we can fully move onto caller's queue */
309 packet = list_first_entry(&endpoint->txq, struct htc_packet,
311 list_move_tail(&packet->list, queue);
313 /* save the number of credits this packet consumed */
314 packet->info.tx.cred_used = req_cred;
316 /* all TX packets are handled asynchronously */
317 packet->completion = htc_tx_comp_handler;
318 packet->context = target;
319 endpoint->ep_st.tx_issued += 1;
321 /* save send flags */
322 packet->info.tx.flags = flags;
323 packet->info.tx.seqno = endpoint->seqno;
328 /* See if the padded tx length falls on a credit boundary */
329 static int htc_get_credit_padding(unsigned int cred_sz, int *len,
330 struct htc_endpoint *ep)
332 int rem_cred, cred_pad;
334 rem_cred = *len % cred_sz;
336 /* No padding needed */
340 if (!(ep->conn_flags & HTC_FLGS_TX_BNDL_PAD_EN))
344 * The transfer consumes a "partial" credit, this
345 * packet cannot be bundled unless we add
346 * additional "dummy" padding (max 255 bytes) to
347 * consume the entire credit.
349 cred_pad = *len < cred_sz ? (cred_sz - *len) : rem_cred;
351 if ((cred_pad > 0) && (cred_pad <= 255))
354 /* The amount of padding is too large, send as non-bundled */
360 static int htc_setup_send_scat_list(struct htc_target *target,
361 struct htc_endpoint *endpoint,
362 struct hif_scatter_req *scat_req,
364 struct list_head *queue)
366 struct htc_packet *packet;
367 int i, len, rem_scat, cred_pad;
370 rem_scat = target->max_tx_bndl_sz;
372 for (i = 0; i < n_scat; i++) {
373 scat_req->scat_list[i].packet = NULL;
375 if (list_empty(queue))
378 packet = list_first_entry(queue, struct htc_packet, list);
379 len = CALC_TXRX_PADDED_LEN(target,
380 packet->act_len + HTC_HDR_LENGTH);
382 cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
384 if (cred_pad < 0 || rem_scat < len) {
390 /* now remove it from the queue */
391 packet = list_first_entry(queue, struct htc_packet, list);
392 list_del(&packet->list);
394 scat_req->scat_list[i].packet = packet;
395 /* prepare packet and flag message as part of a send bundle */
396 htc_prep_send_pkt(packet,
397 packet->info.tx.flags | HTC_FLAGS_SEND_BUNDLE,
398 cred_pad, packet->info.tx.seqno);
399 /* Make sure the buffer is 4-byte aligned */
400 ath6kl_htc_buf_align(&packet->buf,
401 packet->act_len + HTC_HDR_LENGTH);
402 scat_req->scat_list[i].buf = packet->buf;
403 scat_req->scat_list[i].len = len;
405 scat_req->len += len;
406 scat_req->scat_entries++;
407 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
408 "%d, adding pkt : 0x%p len:%d (remaining space:%d)\n",
409 i, packet, len, rem_scat);
412 /* Roll back scatter setup in case of any failure */
413 if (scat_req->scat_entries < HTC_MIN_HTC_MSGS_TO_BUNDLE) {
414 for (i = scat_req->scat_entries - 1; i >= 0; i--) {
415 packet = scat_req->scat_list[i].packet;
417 packet->buf += HTC_HDR_LENGTH;
418 list_add(&packet->list, queue);
428 * htc_issue_send_bundle: drain a queue and send as bundles
429 * this function may return without fully draining the queue
432 * 1. scatter resources are exhausted
433 * 2. a message that will consume a partial credit will stop the
434 * bundling process early
435 * 3. we drop below the minimum number of messages for a bundle
437 static void htc_issue_send_bundle(struct htc_endpoint *endpoint,
438 struct list_head *queue,
439 int *sent_bundle, int *n_bundle_pkts)
441 struct htc_target *target = endpoint->target;
442 struct hif_scatter_req *scat_req = NULL;
443 int n_scat, n_sent_bundle = 0, tot_pkts_bundle = 0;
448 n_scat = get_queue_depth(queue);
449 n_scat = min(n_scat, target->msg_per_bndl_max);
451 if (n_scat < HTC_MIN_HTC_MSGS_TO_BUNDLE)
452 /* not enough to bundle */
455 scat_req = hif_scatter_req_get(target->dev->ar);
458 /* no scatter resources */
459 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
460 "no more scatter resources\n");
464 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "pkts to scatter: %d\n",
468 scat_req->scat_entries = 0;
470 status = htc_setup_send_scat_list(target, endpoint,
471 scat_req, n_scat, queue);
472 if (status == -EAGAIN) {
473 hif_scatter_req_add(target->dev->ar, scat_req);
477 /* send path is always asynchronous */
478 scat_req->complete = htc_async_tx_scat_complete;
480 tot_pkts_bundle += scat_req->scat_entries;
482 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
483 "send scatter total bytes: %d , entries: %d\n",
484 scat_req->len, scat_req->scat_entries);
485 ath6kldev_submit_scat_req(target->dev, scat_req, false);
491 *sent_bundle = n_sent_bundle;
492 *n_bundle_pkts = tot_pkts_bundle;
493 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "htc_issue_send_bundle (sent:%d)\n",
499 static void htc_tx_from_ep_txq(struct htc_target *target,
500 struct htc_endpoint *endpoint)
502 struct list_head txq;
503 struct htc_packet *packet;
507 spin_lock_bh(&target->tx_lock);
509 endpoint->tx_proc_cnt++;
510 if (endpoint->tx_proc_cnt > 1) {
511 endpoint->tx_proc_cnt--;
512 spin_unlock_bh(&target->tx_lock);
513 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "htc_try_send (busy)\n");
518 * drain the endpoint TX queue for transmission as long
519 * as we have enough credits.
521 INIT_LIST_HEAD(&txq);
525 if (list_empty(&endpoint->txq))
528 htc_tx_pkts_get(target, endpoint, &txq);
530 if (list_empty(&txq))
533 spin_unlock_bh(&target->tx_lock);
539 /* try to send a bundle on each pass */
540 if ((target->tx_bndl_enable) &&
541 (get_queue_depth(&txq) >=
542 HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
543 int temp1 = 0, temp2 = 0;
545 htc_issue_send_bundle(endpoint, &txq,
547 bundle_sent += temp1;
548 n_pkts_bundle += temp2;
551 if (list_empty(&txq))
554 packet = list_first_entry(&txq, struct htc_packet,
556 list_del(&packet->list);
558 htc_prep_send_pkt(packet, packet->info.tx.flags,
559 0, packet->info.tx.seqno);
560 htc_issue_send(target, packet);
563 spin_lock_bh(&target->tx_lock);
565 endpoint->ep_st.tx_bundles += bundle_sent;
566 endpoint->ep_st.tx_pkt_bundled += n_pkts_bundle;
569 endpoint->tx_proc_cnt = 0;
570 spin_unlock_bh(&target->tx_lock);
573 static bool htc_try_send(struct htc_target *target,
574 struct htc_endpoint *endpoint,
575 struct htc_packet *tx_pkt)
577 struct htc_ep_callbacks ep_cb;
579 bool overflow = false;
581 ep_cb = endpoint->ep_cb;
583 spin_lock_bh(&target->tx_lock);
584 txq_depth = get_queue_depth(&endpoint->txq);
585 spin_unlock_bh(&target->tx_lock);
587 if (txq_depth >= endpoint->max_txq_depth)
591 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
592 "ep %d, tx queue will overflow :%d , tx depth:%d, max:%d\n",
593 endpoint->eid, overflow, txq_depth,
594 endpoint->max_txq_depth);
596 if (overflow && ep_cb.tx_full) {
597 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
598 "indicating overflowed tx packet: 0x%p\n", tx_pkt);
600 if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
601 HTC_SEND_FULL_DROP) {
602 endpoint->ep_st.tx_dropped += 1;
607 spin_lock_bh(&target->tx_lock);
608 list_add_tail(&tx_pkt->list, &endpoint->txq);
609 spin_unlock_bh(&target->tx_lock);
611 htc_tx_from_ep_txq(target, endpoint);
616 static void htc_chk_ep_txq(struct htc_target *target)
618 struct htc_endpoint *endpoint;
619 struct htc_endpoint_credit_dist *cred_dist;
622 * Run through the credit distribution list to see if there are
623 * packets queued. NOTE: no locks need to be taken since the
624 * distribution list is not dynamic (cannot be re-ordered) and we
625 * are not modifying any state.
627 list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
628 endpoint = (struct htc_endpoint *)cred_dist->htc_rsvd;
630 spin_lock_bh(&target->tx_lock);
631 if (!list_empty(&endpoint->txq)) {
632 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
633 "ep %d has %d credits and %d packets in tx queue\n",
635 endpoint->cred_dist.credits,
636 get_queue_depth(&endpoint->txq));
637 spin_unlock_bh(&target->tx_lock);
639 * Try to start the stalled queue, this list is
640 * ordered by priority. If there are credits
641 * available the highest priority queue will get a
642 * chance to reclaim credits from lower priority
645 htc_tx_from_ep_txq(target, endpoint);
646 spin_lock_bh(&target->tx_lock);
648 spin_unlock_bh(&target->tx_lock);
652 static int htc_setup_tx_complete(struct htc_target *target)
654 struct htc_packet *send_pkt = NULL;
657 send_pkt = htc_get_control_buf(target, true);
662 if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
663 struct htc_setup_comp_ext_msg *setup_comp_ext;
667 (struct htc_setup_comp_ext_msg *)send_pkt->buf;
668 memset(setup_comp_ext, 0, sizeof(*setup_comp_ext));
669 setup_comp_ext->msg_id =
670 cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
672 if (target->msg_per_bndl_max > 0) {
673 /* Indicate HTC bundling to the target */
674 flags |= HTC_SETUP_COMP_FLG_RX_BNDL_EN;
675 setup_comp_ext->msg_per_rxbndl =
676 target->msg_per_bndl_max;
679 memcpy(&setup_comp_ext->flags, &flags,
680 sizeof(setup_comp_ext->flags));
681 set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp_ext,
682 sizeof(struct htc_setup_comp_ext_msg),
683 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
686 struct htc_setup_comp_msg *setup_comp;
687 setup_comp = (struct htc_setup_comp_msg *)send_pkt->buf;
688 memset(setup_comp, 0, sizeof(struct htc_setup_comp_msg));
689 setup_comp->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_ID);
690 set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp,
691 sizeof(struct htc_setup_comp_msg),
692 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
695 /* we want synchronous operation */
696 send_pkt->completion = NULL;
697 htc_prep_send_pkt(send_pkt, 0, 0, 0);
698 status = htc_issue_send(target, send_pkt);
700 if (send_pkt != NULL)
701 htc_reclaim_txctrl_buf(target, send_pkt);
706 void ath6kl_htc_set_credit_dist(struct htc_target *target,
707 struct htc_credit_state_info *cred_dist_cntxt,
708 u16 srvc_pri_order[], int list_len)
710 struct htc_endpoint *endpoint;
713 target->cred_dist_cntxt = cred_dist_cntxt;
715 list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
716 &target->cred_dist_list);
718 for (i = 0; i < list_len; i++) {
719 for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) {
720 endpoint = &target->endpoint[ep];
721 if (endpoint->svc_id == srvc_pri_order[i]) {
722 list_add_tail(&endpoint->cred_dist.list,
723 &target->cred_dist_list);
727 if (ep >= ENDPOINT_MAX) {
734 int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet)
736 struct htc_endpoint *endpoint;
737 struct list_head queue;
739 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
740 "htc_tx: ep id: %d, buf: 0x%p, len: %d\n",
741 packet->endpoint, packet->buf, packet->act_len);
743 if (packet->endpoint >= ENDPOINT_MAX) {
748 endpoint = &target->endpoint[packet->endpoint];
750 if (!htc_try_send(target, endpoint, packet)) {
751 packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
752 -ECANCELED : -ENOSPC;
753 INIT_LIST_HEAD(&queue);
754 list_add(&packet->list, &queue);
755 htc_tx_complete(endpoint, &queue);
761 /* flush endpoint TX queue */
762 void ath6kl_htc_flush_txep(struct htc_target *target,
763 enum htc_endpoint_id eid, u16 tag)
765 struct htc_packet *packet, *tmp_pkt;
766 struct list_head discard_q, container;
767 struct htc_endpoint *endpoint = &target->endpoint[eid];
769 if (!endpoint->svc_id) {
774 /* initialize the discard queue */
775 INIT_LIST_HEAD(&discard_q);
777 spin_lock_bh(&target->tx_lock);
779 list_for_each_entry_safe(packet, tmp_pkt, &endpoint->txq, list) {
780 if ((tag == HTC_TX_PACKET_TAG_ALL) ||
781 (tag == packet->info.tx.tag))
782 list_move_tail(&packet->list, &discard_q);
785 spin_unlock_bh(&target->tx_lock);
787 list_for_each_entry_safe(packet, tmp_pkt, &discard_q, list) {
788 packet->status = -ECANCELED;
789 list_del(&packet->list);
790 ath6kl_dbg(ATH6KL_DBG_TRC,
791 "flushing tx pkt:0x%p, len:%d, ep:%d tag:0x%X\n",
792 packet, packet->act_len,
793 packet->endpoint, packet->info.tx.tag);
795 INIT_LIST_HEAD(&container);
796 list_add_tail(&packet->list, &container);
797 htc_tx_complete(endpoint, &container);
802 static void ath6kl_htc_flush_txep_all(struct htc_target *target)
804 struct htc_endpoint *endpoint;
807 dump_cred_dist_stats(target);
809 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
810 endpoint = &target->endpoint[i];
811 if (endpoint->svc_id == 0)
814 ath6kl_htc_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
818 void ath6kl_htc_indicate_activity_change(struct htc_target *target,
819 enum htc_endpoint_id eid, bool active)
821 struct htc_endpoint *endpoint = &target->endpoint[eid];
824 if (endpoint->svc_id == 0) {
829 spin_lock_bh(&target->tx_lock);
832 if (!(endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE)) {
833 endpoint->cred_dist.dist_flags |= HTC_EP_ACTIVE;
837 if (endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE) {
838 endpoint->cred_dist.dist_flags &= ~HTC_EP_ACTIVE;
844 endpoint->cred_dist.txq_depth =
845 get_queue_depth(&endpoint->txq);
847 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
848 target->cred_dist_cntxt, &target->cred_dist_list);
850 ath6k_credit_distribute(target->cred_dist_cntxt,
851 &target->cred_dist_list,
852 HTC_CREDIT_DIST_ACTIVITY_CHANGE);
855 spin_unlock_bh(&target->tx_lock);
858 htc_chk_ep_txq(target);
863 static inline void htc_update_rx_stats(struct htc_endpoint *endpoint,
866 endpoint->ep_st.rx_pkts++;
867 if (n_look_ahds == 1)
868 endpoint->ep_st.rx_lkahds++;
869 else if (n_look_ahds > 1)
870 endpoint->ep_st.rx_bundle_lkahd++;
873 static inline bool htc_valid_rx_frame_len(struct htc_target *target,
874 enum htc_endpoint_id eid, int len)
876 return (eid == target->dev->ar->ctrl_ep) ?
877 len <= ATH6KL_BUFFER_SIZE : len <= ATH6KL_AMSDU_BUFFER_SIZE;
880 static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
882 struct list_head queue;
884 INIT_LIST_HEAD(&queue);
885 list_add_tail(&packet->list, &queue);
886 return ath6kl_htc_add_rxbuf_multiple(target, &queue);
889 static void htc_reclaim_rxbuf(struct htc_target *target,
890 struct htc_packet *packet,
891 struct htc_endpoint *ep)
893 if (packet->info.rx.rx_flags & HTC_RX_PKT_NO_RECYCLE) {
894 htc_rxpkt_reset(packet);
895 packet->status = -ECANCELED;
896 ep->ep_cb.rx(ep->target, packet);
898 htc_rxpkt_reset(packet);
899 htc_add_rxbuf((void *)(target), packet);
903 static void reclaim_rx_ctrl_buf(struct htc_target *target,
904 struct htc_packet *packet)
906 spin_lock_bh(&target->htc_lock);
907 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
908 spin_unlock_bh(&target->htc_lock);
911 static int dev_rx_pkt(struct htc_target *target, struct htc_packet *packet,
914 struct ath6kl_device *dev = target->dev;
918 padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
920 if (padded_len > packet->buf_len) {
921 ath6kl_err("not enough receive space for packet - padlen:%d recvlen:%d bufferlen:%d\n",
922 padded_len, rx_len, packet->buf_len);
926 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
927 "dev_rx_pkt (0x%p : hdr:0x%X) padded len: %d mbox:0x%X (mode:%s)\n",
928 packet, packet->info.rx.exp_hdr,
929 padded_len, dev->ar->mbox_info.htc_addr, "sync");
931 status = hif_read_write_sync(dev->ar,
932 dev->ar->mbox_info.htc_addr,
933 packet->buf, padded_len,
934 HIF_RD_SYNC_BLOCK_FIX);
936 packet->status = status;
942 * optimization for recv packets, we can indicate a
943 * "hint" that there are more single-packets to fetch
946 static void set_rxpkt_indication_flag(u32 lk_ahd,
947 struct htc_endpoint *endpoint,
948 struct htc_packet *packet)
950 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)&lk_ahd;
952 if (htc_hdr->eid == packet->endpoint) {
953 if (!list_empty(&endpoint->rx_bufq))
954 packet->info.rx.indicat_flags |=
955 HTC_RX_FLAGS_INDICATE_MORE_PKTS;
959 static void chk_rx_water_mark(struct htc_endpoint *endpoint)
961 struct htc_ep_callbacks ep_cb = endpoint->ep_cb;
963 if (ep_cb.rx_refill_thresh > 0) {
964 spin_lock_bh(&endpoint->target->rx_lock);
965 if (get_queue_depth(&endpoint->rx_bufq)
966 < ep_cb.rx_refill_thresh) {
967 spin_unlock_bh(&endpoint->target->rx_lock);
968 ep_cb.rx_refill(endpoint->target, endpoint->eid);
971 spin_unlock_bh(&endpoint->target->rx_lock);
975 /* This function is called with rx_lock held */
976 static int htc_setup_rxpkts(struct htc_target *target, struct htc_endpoint *ep,
977 u32 *lk_ahds, struct list_head *queue, int n_msg)
979 struct htc_packet *packet;
980 /* FIXME: type of lk_ahds can't be right */
981 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)lk_ahds;
982 struct htc_ep_callbacks ep_cb;
983 int status = 0, j, full_len;
986 full_len = CALC_TXRX_PADDED_LEN(target,
987 le16_to_cpu(htc_hdr->payld_len) +
990 if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
991 ath6kl_warn("Rx buffer requested with invalid length\n");
996 for (j = 0; j < n_msg; j++) {
999 * Reset flag, any packets allocated using the
1000 * rx_alloc() API cannot be recycled on
1001 * cleanup,they must be explicitly returned.
1005 if (ep_cb.rx_allocthresh &&
1006 (full_len > ep_cb.rx_alloc_thresh)) {
1007 ep->ep_st.rx_alloc_thresh_hit += 1;
1008 ep->ep_st.rxalloc_thresh_byte +=
1009 le16_to_cpu(htc_hdr->payld_len);
1011 spin_unlock_bh(&target->rx_lock);
1014 packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
1016 spin_lock_bh(&target->rx_lock);
1018 /* refill handler is being used */
1019 if (list_empty(&ep->rx_bufq)) {
1020 if (ep_cb.rx_refill) {
1021 spin_unlock_bh(&target->rx_lock);
1022 ep_cb.rx_refill(ep->target, ep->eid);
1023 spin_lock_bh(&target->rx_lock);
1027 if (list_empty(&ep->rx_bufq))
1030 packet = list_first_entry(&ep->rx_bufq,
1031 struct htc_packet, list);
1032 list_del(&packet->list);
1037 target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
1038 target->ep_waiting = ep->eid;
1043 packet->info.rx.rx_flags = 0;
1044 packet->info.rx.indicat_flags = 0;
1049 * flag that these packets cannot be
1050 * recycled, they have to be returned to
1053 packet->info.rx.rx_flags |= HTC_RX_PKT_NO_RECYCLE;
1055 /* Caller needs to free this upon any failure */
1056 list_add_tail(&packet->list, queue);
1058 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1059 status = -ECANCELED;
1064 packet->info.rx.rx_flags |= HTC_RX_PKT_REFRESH_HDR;
1065 packet->info.rx.exp_hdr = 0xFFFFFFFF;
1067 /* set expected look ahead */
1068 packet->info.rx.exp_hdr = *lk_ahds;
1070 packet->act_len = le16_to_cpu(htc_hdr->payld_len) +
1077 static int alloc_and_prep_rxpkts(struct htc_target *target,
1078 u32 lk_ahds[], int msg,
1079 struct htc_endpoint *endpoint,
1080 struct list_head *queue)
1083 struct htc_packet *packet, *tmp_pkt;
1084 struct htc_frame_hdr *htc_hdr;
1087 spin_lock_bh(&target->rx_lock);
1089 for (i = 0; i < msg; i++) {
1091 htc_hdr = (struct htc_frame_hdr *)&lk_ahds[i];
1093 if (htc_hdr->eid >= ENDPOINT_MAX) {
1094 ath6kl_err("invalid ep in look-ahead: %d\n",
1100 if (htc_hdr->eid != endpoint->eid) {
1101 ath6kl_err("invalid ep in look-ahead: %d should be : %d (index:%d)\n",
1102 htc_hdr->eid, endpoint->eid, i);
1107 if (le16_to_cpu(htc_hdr->payld_len) > HTC_MAX_PAYLOAD_LENGTH) {
1108 ath6kl_err("payload len %d exceeds max htc : %d !\n",
1110 (u32) HTC_MAX_PAYLOAD_LENGTH);
1115 if (endpoint->svc_id == 0) {
1116 ath6kl_err("ep %d is not connected !\n", htc_hdr->eid);
1121 if (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) {
1123 * HTC header indicates that every packet to follow
1124 * has the same padded length so that it can be
1125 * optimally fetched as a full bundle.
1127 n_msg = (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) >>
1128 HTC_FLG_RX_BNDL_CNT_S;
1130 /* the count doesn't include the starter frame */
1132 if (n_msg > target->msg_per_bndl_max) {
1137 endpoint->ep_st.rx_bundle_from_hdr += 1;
1138 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1139 "htc hdr indicates :%d msg can be fetched as a bundle\n",
1142 /* HTC header only indicates 1 message to fetch */
1145 /* Setup packet buffers for each message */
1146 status = htc_setup_rxpkts(target, endpoint, &lk_ahds[i], queue,
1150 * This is due to unavailabilty of buffers to rx entire data.
1151 * Return no error so that free buffers from queue can be used
1152 * to receive partial data.
1154 if (status == -ENOSPC) {
1155 spin_unlock_bh(&target->rx_lock);
1163 spin_unlock_bh(&target->rx_lock);
1166 list_for_each_entry_safe(packet, tmp_pkt, queue, list) {
1167 list_del(&packet->list);
1168 htc_reclaim_rxbuf(target, packet,
1169 &target->endpoint[packet->endpoint]);
1176 static void htc_ctrl_rx(struct htc_target *context, struct htc_packet *packets)
1178 if (packets->endpoint != ENDPOINT_0) {
1183 if (packets->status == -ECANCELED) {
1184 reclaim_rx_ctrl_buf(context, packets);
1188 if (packets->act_len > 0) {
1189 ath6kl_err("htc_ctrl_rx, got message with len:%zu\n",
1190 packets->act_len + HTC_HDR_LENGTH);
1192 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES,
1193 "Unexpected ENDPOINT 0 Message",
1194 packets->buf - HTC_HDR_LENGTH,
1195 packets->act_len + HTC_HDR_LENGTH);
1198 htc_reclaim_rxbuf(context, packets, &context->endpoint[0]);
1201 static void htc_proc_cred_rpt(struct htc_target *target,
1202 struct htc_credit_report *rpt,
1204 enum htc_endpoint_id from_ep)
1206 struct htc_endpoint *endpoint;
1207 int tot_credits = 0, i;
1210 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
1211 "htc_proc_cred_rpt, credit report entries:%d\n", n_entries);
1213 spin_lock_bh(&target->tx_lock);
1215 for (i = 0; i < n_entries; i++, rpt++) {
1216 if (rpt->eid >= ENDPOINT_MAX) {
1218 spin_unlock_bh(&target->tx_lock);
1222 endpoint = &target->endpoint[rpt->eid];
1224 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, " ep %d got %d credits\n",
1225 rpt->eid, rpt->credits);
1227 endpoint->ep_st.tx_cred_rpt += 1;
1228 endpoint->ep_st.cred_retnd += rpt->credits;
1230 if (from_ep == rpt->eid) {
1232 * This credit report arrived on the same endpoint
1233 * indicating it arrived in an RX packet.
1235 endpoint->ep_st.cred_from_rx += rpt->credits;
1236 endpoint->ep_st.cred_rpt_from_rx += 1;
1237 } else if (from_ep == ENDPOINT_0) {
1238 /* credit arrived on endpoint 0 as a NULL message */
1239 endpoint->ep_st.cred_from_ep0 += rpt->credits;
1240 endpoint->ep_st.cred_rpt_ep0 += 1;
1242 endpoint->ep_st.cred_from_other += rpt->credits;
1243 endpoint->ep_st.cred_rpt_from_other += 1;
1246 if (rpt->eid == ENDPOINT_0)
1247 /* always give endpoint 0 credits back */
1248 endpoint->cred_dist.credits += rpt->credits;
1250 endpoint->cred_dist.cred_to_dist += rpt->credits;
1255 * Refresh tx depth for distribution function that will
1256 * recover these credits NOTE: this is only valid when
1257 * there are credits to recover!
1259 endpoint->cred_dist.txq_depth =
1260 get_queue_depth(&endpoint->txq);
1262 tot_credits += rpt->credits;
1265 ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
1266 "report indicated %d credits to distribute\n",
1271 * This was a credit return based on a completed send
1272 * operations note, this is done with the lock held
1274 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
1275 target->cred_dist_cntxt, &target->cred_dist_list);
1277 ath6k_credit_distribute(target->cred_dist_cntxt,
1278 &target->cred_dist_list,
1279 HTC_CREDIT_DIST_SEND_COMPLETE);
1282 spin_unlock_bh(&target->tx_lock);
1285 htc_chk_ep_txq(target);
1288 static int htc_parse_trailer(struct htc_target *target,
1289 struct htc_record_hdr *record,
1290 u8 *record_buf, u32 *next_lk_ahds,
1291 enum htc_endpoint_id endpoint,
1294 struct htc_bundle_lkahd_rpt *bundle_lkahd_rpt;
1295 struct htc_lookahead_report *lk_ahd;
1298 switch (record->rec_id) {
1299 case HTC_RECORD_CREDITS:
1300 len = record->len / sizeof(struct htc_credit_report);
1306 htc_proc_cred_rpt(target,
1307 (struct htc_credit_report *) record_buf,
1310 case HTC_RECORD_LOOKAHEAD:
1311 len = record->len / sizeof(*lk_ahd);
1317 lk_ahd = (struct htc_lookahead_report *) record_buf;
1318 if ((lk_ahd->pre_valid == ((~lk_ahd->post_valid) & 0xFF))
1321 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1322 "lk_ahd report found (pre valid:0x%X, post valid:0x%X)\n",
1323 lk_ahd->pre_valid, lk_ahd->post_valid);
1325 /* look ahead bytes are valid, copy them over */
1326 memcpy((u8 *)&next_lk_ahds[0], lk_ahd->lk_ahd, 4);
1328 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Next Look Ahead",
1334 case HTC_RECORD_LOOKAHEAD_BUNDLE:
1335 len = record->len / sizeof(*bundle_lkahd_rpt);
1336 if (!len || (len > HTC_HOST_MAX_MSG_PER_BUNDLE)) {
1345 (struct htc_bundle_lkahd_rpt *) record_buf;
1347 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Bundle lk_ahd",
1348 record_buf, record->len);
1350 for (i = 0; i < len; i++) {
1351 memcpy((u8 *)&next_lk_ahds[i],
1352 bundle_lkahd_rpt->lk_ahd, 4);
1360 ath6kl_err("unhandled record: id:%d len:%d\n",
1361 record->rec_id, record->len);
1369 static int htc_proc_trailer(struct htc_target *target,
1370 u8 *buf, int len, u32 *next_lk_ahds,
1371 int *n_lk_ahds, enum htc_endpoint_id endpoint)
1373 struct htc_record_hdr *record;
1379 ath6kl_dbg(ATH6KL_DBG_HTC_RECV, "+htc_proc_trailer (len:%d)\n", len);
1381 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Recv Trailer", buf, len);
1389 if (len < sizeof(struct htc_record_hdr)) {
1393 /* these are byte aligned structs */
1394 record = (struct htc_record_hdr *) buf;
1395 len -= sizeof(struct htc_record_hdr);
1396 buf += sizeof(struct htc_record_hdr);
1398 if (record->len > len) {
1399 ath6kl_err("invalid record len: %d (id:%d) buf has: %d bytes left\n",
1400 record->len, record->rec_id, len);
1406 status = htc_parse_trailer(target, record, record_buf,
1407 next_lk_ahds, endpoint, n_lk_ahds);
1412 /* advance buffer past this record for next time around */
1418 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "BAD Recv Trailer",
1419 orig_buf, orig_len);
1424 static int htc_proc_rxhdr(struct htc_target *target,
1425 struct htc_packet *packet,
1426 u32 *next_lkahds, int *n_lkahds)
1431 struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)packet->buf;
1433 if (n_lkahds != NULL)
1436 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "HTC Recv PKT", packet->buf,
1440 * NOTE: we cannot assume the alignment of buf, so we use the safe
1441 * macros to retrieve 16 bit fields.
1443 payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
1445 memcpy((u8 *)&lk_ahd, packet->buf, sizeof(lk_ahd));
1447 if (packet->info.rx.rx_flags & HTC_RX_PKT_REFRESH_HDR) {
1449 * Refresh the expected header and the actual length as it
1450 * was unknown when this packet was grabbed as part of the
1453 packet->info.rx.exp_hdr = lk_ahd;
1454 packet->act_len = payload_len + HTC_HDR_LENGTH;
1456 /* validate the actual header that was refreshed */
1457 if (packet->act_len > packet->buf_len) {
1458 ath6kl_err("refreshed hdr payload len (%d) in bundled recv is invalid (hdr: 0x%X)\n",
1459 payload_len, lk_ahd);
1461 * Limit this to max buffer just to print out some
1464 packet->act_len = min(packet->act_len, packet->buf_len);
1469 if (packet->endpoint != htc_hdr->eid) {
1470 ath6kl_err("refreshed hdr ep (%d) does not match expected ep (%d)\n",
1471 htc_hdr->eid, packet->endpoint);
1477 if (lk_ahd != packet->info.rx.exp_hdr) {
1478 ath6kl_err("htc_proc_rxhdr, lk_ahd mismatch! (pPkt:0x%p flags:0x%X)\n",
1479 packet, packet->info.rx.rx_flags);
1480 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Expected Message lk_ahd",
1481 &packet->info.rx.exp_hdr, 4);
1482 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Current Frame Header",
1483 (u8 *)&lk_ahd, sizeof(lk_ahd));
1488 if (htc_hdr->flags & HTC_FLG_RX_TRAILER) {
1489 if (htc_hdr->ctrl[0] < sizeof(struct htc_record_hdr) ||
1490 htc_hdr->ctrl[0] > payload_len) {
1491 ath6kl_err("htc_proc_rxhdr, invalid hdr (payload len should be :%d, CB[0] is:%d)\n",
1492 payload_len, htc_hdr->ctrl[0]);
1497 if (packet->info.rx.rx_flags & HTC_RX_PKT_IGNORE_LOOKAHEAD) {
1502 status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
1503 + payload_len - htc_hdr->ctrl[0],
1504 htc_hdr->ctrl[0], next_lkahds,
1505 n_lkahds, packet->endpoint);
1510 packet->act_len -= htc_hdr->ctrl[0];
1513 packet->buf += HTC_HDR_LENGTH;
1514 packet->act_len -= HTC_HDR_LENGTH;
1518 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "BAD HTC Recv PKT",
1520 packet->act_len < 256 ? packet->act_len : 256);
1522 if (packet->act_len > 0)
1523 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES,
1524 "HTC - Application Msg",
1525 packet->buf, packet->act_len);
1531 static void do_rx_completion(struct htc_endpoint *endpoint,
1532 struct htc_packet *packet)
1534 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1535 "htc calling ep %d recv callback on packet 0x%p\n",
1536 endpoint->eid, packet);
1537 endpoint->ep_cb.rx(endpoint->target, packet);
1540 static int htc_issue_rxpkt_bundle(struct htc_target *target,
1541 struct list_head *rxq,
1542 struct list_head *sync_compq,
1543 int *n_pkt_fetched, bool part_bundle)
1545 struct hif_scatter_req *scat_req;
1546 struct htc_packet *packet;
1547 int rem_space = target->max_rx_bndl_sz;
1548 int n_scat_pkt, status = 0, i, len;
1550 n_scat_pkt = get_queue_depth(rxq);
1551 n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
1553 if ((get_queue_depth(rxq) - n_scat_pkt) > 0) {
1555 * We were forced to split this bundle receive operation
1556 * all packets in this partial bundle must have their
1557 * lookaheads ignored.
1562 * This would only happen if the target ignored our max
1565 ath6kl_warn("htc_issue_rxpkt_bundle : partial bundle detected num:%d , %d\n",
1566 get_queue_depth(rxq), n_scat_pkt);
1571 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1572 "htc_issue_rxpkt_bundle (numpackets: %d , actual : %d)\n",
1573 get_queue_depth(rxq), n_scat_pkt);
1575 scat_req = hif_scatter_req_get(target->dev->ar);
1577 if (scat_req == NULL)
1580 for (i = 0; i < n_scat_pkt; i++) {
1583 packet = list_first_entry(rxq, struct htc_packet, list);
1584 list_del(&packet->list);
1586 pad_len = CALC_TXRX_PADDED_LEN(target,
1589 if ((rem_space - pad_len) < 0) {
1590 list_add(&packet->list, rxq);
1594 rem_space -= pad_len;
1596 if (part_bundle || (i < (n_scat_pkt - 1)))
1598 * Packet 0..n-1 cannot be checked for look-aheads
1599 * since we are fetching a bundle the last packet
1600 * however can have it's lookahead used
1602 packet->info.rx.rx_flags |=
1603 HTC_RX_PKT_IGNORE_LOOKAHEAD;
1605 /* NOTE: 1 HTC packet per scatter entry */
1606 scat_req->scat_list[i].buf = packet->buf;
1607 scat_req->scat_list[i].len = pad_len;
1609 packet->info.rx.rx_flags |= HTC_RX_PKT_PART_OF_BUNDLE;
1611 list_add_tail(&packet->list, sync_compq);
1613 WARN_ON(!scat_req->scat_list[i].len);
1614 len += scat_req->scat_list[i].len;
1617 scat_req->len = len;
1618 scat_req->scat_entries = i;
1620 status = ath6kldev_submit_scat_req(target->dev, scat_req, true);
1625 /* free scatter request */
1626 hif_scatter_req_add(target->dev->ar, scat_req);
1633 static int htc_proc_fetched_rxpkts(struct htc_target *target,
1634 struct list_head *comp_pktq, u32 lk_ahds[],
1637 struct htc_packet *packet, *tmp_pkt;
1638 struct htc_endpoint *ep;
1641 list_for_each_entry_safe(packet, tmp_pkt, comp_pktq, list) {
1642 list_del(&packet->list);
1643 ep = &target->endpoint[packet->endpoint];
1645 /* process header for each of the recv packet */
1646 status = htc_proc_rxhdr(target, packet, lk_ahds, n_lk_ahd);
1650 if (list_empty(comp_pktq)) {
1652 * Last packet's more packet flag is set
1653 * based on the lookahead.
1656 set_rxpkt_indication_flag(lk_ahds[0],
1660 * Packets in a bundle automatically have
1663 packet->info.rx.indicat_flags |=
1664 HTC_RX_FLAGS_INDICATE_MORE_PKTS;
1666 htc_update_rx_stats(ep, *n_lk_ahd);
1668 if (packet->info.rx.rx_flags & HTC_RX_PKT_PART_OF_BUNDLE)
1669 ep->ep_st.rx_bundl += 1;
1671 do_rx_completion(ep, packet);
1677 static int htc_fetch_rxpkts(struct htc_target *target,
1678 struct list_head *rx_pktq,
1679 struct list_head *comp_pktq)
1682 bool part_bundle = false;
1685 /* now go fetch the list of HTC packets */
1686 while (!list_empty(rx_pktq)) {
1689 if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
1691 * There are enough packets to attempt a
1692 * bundle transfer and recv bundling is
1695 status = htc_issue_rxpkt_bundle(target, rx_pktq,
1702 if (!list_empty(rx_pktq))
1706 if (!fetched_pkts) {
1707 struct htc_packet *packet;
1709 packet = list_first_entry(rx_pktq, struct htc_packet,
1712 list_del(&packet->list);
1714 /* fully synchronous */
1715 packet->completion = NULL;
1717 if (!list_empty(rx_pktq))
1719 * look_aheads in all packet
1720 * except the last one in the
1721 * bundle must be ignored
1723 packet->info.rx.rx_flags |=
1724 HTC_RX_PKT_IGNORE_LOOKAHEAD;
1726 /* go fetch the packet */
1727 status = dev_rx_pkt(target, packet, packet->act_len);
1731 list_add_tail(&packet->list, comp_pktq);
1738 int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
1739 u32 msg_look_ahead[], int *num_pkts)
1741 struct htc_packet *packets, *tmp_pkt;
1742 struct htc_endpoint *endpoint;
1743 struct list_head rx_pktq, comp_pktq;
1745 u32 look_aheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
1746 int num_look_ahead = 1;
1747 enum htc_endpoint_id id;
1753 * On first entry copy the look_aheads into our temp array for
1756 memcpy(look_aheads, msg_look_ahead, sizeof(look_aheads));
1761 * First lookahead sets the expected endpoint IDs for all
1762 * packets in a bundle.
1764 id = ((struct htc_frame_hdr *)&look_aheads[0])->eid;
1765 endpoint = &target->endpoint[id];
1767 if (id >= ENDPOINT_MAX) {
1768 ath6kl_err("MsgPend, invalid endpoint in look-ahead: %d\n",
1774 INIT_LIST_HEAD(&rx_pktq);
1775 INIT_LIST_HEAD(&comp_pktq);
1778 * Try to allocate as many HTC RX packets indicated by the
1781 status = alloc_and_prep_rxpkts(target, look_aheads,
1782 num_look_ahead, endpoint,
1787 if (get_queue_depth(&rx_pktq) >= 2)
1789 * A recv bundle was detected, force IRQ status
1792 target->chk_irq_status_cnt = 1;
1794 n_fetched += get_queue_depth(&rx_pktq);
1798 status = htc_fetch_rxpkts(target, &rx_pktq, &comp_pktq);
1801 chk_rx_water_mark(endpoint);
1803 /* Process fetched packets */
1804 status = htc_proc_fetched_rxpkts(target, &comp_pktq,
1805 look_aheads, &num_look_ahead);
1807 if (!num_look_ahead || status)
1811 * For SYNCH processing, if we get here, we are running
1812 * through the loop again due to a detected lookahead. Set
1813 * flag that we should re-check IRQ status registers again
1814 * before leaving IRQ processing, this can net better
1815 * performance in high throughput situations.
1817 target->chk_irq_status_cnt = 1;
1821 ath6kl_err("failed to get pending recv messages: %d\n",
1824 * Cleanup any packets we allocated but didn't use to
1825 * actually fetch any packets.
1827 list_for_each_entry_safe(packets, tmp_pkt, &rx_pktq, list) {
1828 list_del(&packets->list);
1829 htc_reclaim_rxbuf(target, packets,
1830 &target->endpoint[packets->endpoint]);
1833 /* cleanup any packets in sync completion queue */
1834 list_for_each_entry_safe(packets, tmp_pkt, &comp_pktq, list) {
1835 list_del(&packets->list);
1836 htc_reclaim_rxbuf(target, packets,
1837 &target->endpoint[packets->endpoint]);
1840 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1841 ath6kl_warn("host is going to stop blocking receiver for htc_stop\n");
1842 ath6kldev_rx_control(target->dev, false);
1847 * Before leaving, check to see if host ran out of buffers and
1848 * needs to stop the receiver.
1850 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
1851 ath6kl_warn("host has no rx buffers blocking receiver to prevent overrun\n");
1852 ath6kldev_rx_control(target->dev, false);
1854 *num_pkts = n_fetched;
1860 * Synchronously wait for a control message from the target,
1861 * This function is used at initialization time ONLY. At init messages
1862 * on ENDPOINT 0 are expected.
1864 static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
1866 struct htc_packet *packet = NULL;
1867 struct htc_frame_hdr *htc_hdr;
1870 if (ath6kldev_poll_mboxmsg_rx(target->dev, &look_ahead,
1871 HTC_TARGET_RESPONSE_TIMEOUT))
1874 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1875 "htc_wait_for_ctrl_msg: look_ahead : 0x%X\n", look_ahead);
1877 htc_hdr = (struct htc_frame_hdr *)&look_ahead;
1879 if (htc_hdr->eid != ENDPOINT_0)
1882 packet = htc_get_control_buf(target, false);
1887 packet->info.rx.rx_flags = 0;
1888 packet->info.rx.exp_hdr = look_ahead;
1889 packet->act_len = le16_to_cpu(htc_hdr->payld_len) + HTC_HDR_LENGTH;
1891 if (packet->act_len > packet->buf_len)
1894 /* we want synchronous operation */
1895 packet->completion = NULL;
1897 /* get the message from the device, this will block */
1898 if (dev_rx_pkt(target, packet, packet->act_len))
1901 /* process receive header */
1902 packet->status = htc_proc_rxhdr(target, packet, NULL, NULL);
1904 if (packet->status) {
1905 ath6kl_err("htc_wait_for_ctrl_msg, htc_proc_rxhdr failed (status = %d)\n",
1913 if (packet != NULL) {
1914 htc_rxpkt_reset(packet);
1915 reclaim_rx_ctrl_buf(target, packet);
1921 int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
1922 struct list_head *pkt_queue)
1924 struct htc_endpoint *endpoint;
1925 struct htc_packet *first_pkt;
1926 bool rx_unblock = false;
1927 int status = 0, depth;
1929 if (list_empty(pkt_queue))
1932 first_pkt = list_first_entry(pkt_queue, struct htc_packet, list);
1934 if (first_pkt->endpoint >= ENDPOINT_MAX)
1937 depth = get_queue_depth(pkt_queue);
1939 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1940 "htc_add_rxbuf_multiple: ep id: %d, cnt:%d, len: %d\n",
1941 first_pkt->endpoint, depth, first_pkt->buf_len);
1943 endpoint = &target->endpoint[first_pkt->endpoint];
1945 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1946 struct htc_packet *packet, *tmp_pkt;
1948 /* walk through queue and mark each one canceled */
1949 list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
1950 packet->status = -ECANCELED;
1951 list_del(&packet->list);
1952 do_rx_completion(endpoint, packet);
1958 spin_lock_bh(&target->rx_lock);
1960 list_splice_tail_init(pkt_queue, &endpoint->rx_bufq);
1962 /* check if we are blocked waiting for a new buffer */
1963 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
1964 if (target->ep_waiting == first_pkt->endpoint) {
1965 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
1966 "receiver was blocked on ep:%d, unblocking.\n",
1967 target->ep_waiting);
1968 target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
1969 target->ep_waiting = ENDPOINT_MAX;
1974 spin_unlock_bh(&target->rx_lock);
1976 if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
1977 /* TODO : implement a buffer threshold count? */
1978 ath6kldev_rx_control(target->dev, true);
1983 void ath6kl_htc_flush_rx_buf(struct htc_target *target)
1985 struct htc_endpoint *endpoint;
1986 struct htc_packet *packet, *tmp_pkt;
1989 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
1990 endpoint = &target->endpoint[i];
1991 if (!endpoint->svc_id)
1995 spin_lock_bh(&target->rx_lock);
1996 list_for_each_entry_safe(packet, tmp_pkt,
1997 &endpoint->rx_bufq, list) {
1998 list_del(&packet->list);
1999 spin_unlock_bh(&target->rx_lock);
2000 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
2001 "flushing rx pkt:0x%p, len:%d, ep:%d\n",
2002 packet, packet->buf_len,
2004 dev_kfree_skb(packet->pkt_cntxt);
2005 spin_lock_bh(&target->rx_lock);
2007 spin_unlock_bh(&target->rx_lock);
2011 int ath6kl_htc_conn_service(struct htc_target *target,
2012 struct htc_service_connect_req *conn_req,
2013 struct htc_service_connect_resp *conn_resp)
2015 struct htc_packet *rx_pkt = NULL;
2016 struct htc_packet *tx_pkt = NULL;
2017 struct htc_conn_service_resp *resp_msg;
2018 struct htc_conn_service_msg *conn_msg;
2019 struct htc_endpoint *endpoint;
2020 enum htc_endpoint_id assigned_ep = ENDPOINT_MAX;
2021 unsigned int max_msg_sz = 0;
2024 ath6kl_dbg(ATH6KL_DBG_TRC,
2025 "htc_conn_service, target:0x%p service id:0x%X\n",
2026 target, conn_req->svc_id);
2028 if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
2029 /* special case for pseudo control service */
2030 assigned_ep = ENDPOINT_0;
2031 max_msg_sz = HTC_MAX_CTRL_MSG_LEN;
2033 /* allocate a packet to send to the target */
2034 tx_pkt = htc_get_control_buf(target, true);
2039 conn_msg = (struct htc_conn_service_msg *)tx_pkt->buf;
2040 memset(conn_msg, 0, sizeof(*conn_msg));
2041 conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
2042 conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
2043 conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags);
2045 set_htc_pkt_info(tx_pkt, NULL, (u8 *) conn_msg,
2046 sizeof(*conn_msg) + conn_msg->svc_meta_len,
2047 ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
2049 /* we want synchronous operation */
2050 tx_pkt->completion = NULL;
2051 htc_prep_send_pkt(tx_pkt, 0, 0, 0);
2052 status = htc_issue_send(target, tx_pkt);
2057 /* wait for response */
2058 rx_pkt = htc_wait_for_ctrl_msg(target);
2065 resp_msg = (struct htc_conn_service_resp *)rx_pkt->buf;
2067 if ((le16_to_cpu(resp_msg->msg_id) != HTC_MSG_CONN_SVC_RESP_ID)
2068 || (rx_pkt->act_len < sizeof(*resp_msg))) {
2073 conn_resp->resp_code = resp_msg->status;
2074 /* check response status */
2075 if (resp_msg->status != HTC_SERVICE_SUCCESS) {
2076 ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
2077 resp_msg->svc_id, resp_msg->status);
2082 assigned_ep = (enum htc_endpoint_id)resp_msg->eid;
2083 max_msg_sz = le16_to_cpu(resp_msg->max_msg_sz);
2086 if (assigned_ep >= ENDPOINT_MAX || !max_msg_sz) {
2091 endpoint = &target->endpoint[assigned_ep];
2092 endpoint->eid = assigned_ep;
2093 if (endpoint->svc_id) {
2098 /* return assigned endpoint to caller */
2099 conn_resp->endpoint = assigned_ep;
2100 conn_resp->len_max = max_msg_sz;
2102 /* setup the endpoint */
2104 /* this marks the endpoint in use */
2105 endpoint->svc_id = conn_req->svc_id;
2107 endpoint->max_txq_depth = conn_req->max_txq_depth;
2108 endpoint->len_max = max_msg_sz;
2109 endpoint->ep_cb = conn_req->ep_cb;
2110 endpoint->cred_dist.svc_id = conn_req->svc_id;
2111 endpoint->cred_dist.htc_rsvd = endpoint;
2112 endpoint->cred_dist.endpoint = assigned_ep;
2113 endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
2115 if (conn_req->max_rxmsg_sz) {
2117 * Override cred_per_msg calculation, this optimizes
2118 * the credit-low indications since the host will actually
2119 * issue smaller messages in the Send path.
2121 if (conn_req->max_rxmsg_sz > max_msg_sz) {
2125 endpoint->cred_dist.cred_per_msg =
2126 conn_req->max_rxmsg_sz / target->tgt_cred_sz;
2128 endpoint->cred_dist.cred_per_msg =
2129 max_msg_sz / target->tgt_cred_sz;
2131 if (!endpoint->cred_dist.cred_per_msg)
2132 endpoint->cred_dist.cred_per_msg = 1;
2134 /* save local connection flags */
2135 endpoint->conn_flags = conn_req->flags;
2139 htc_reclaim_txctrl_buf(target, tx_pkt);
2142 htc_rxpkt_reset(rx_pkt);
2143 reclaim_rx_ctrl_buf(target, rx_pkt);
2149 static void reset_ep_state(struct htc_target *target)
2151 struct htc_endpoint *endpoint;
2154 for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
2155 endpoint = &target->endpoint[i];
2156 memset(&endpoint->cred_dist, 0, sizeof(endpoint->cred_dist));
2157 endpoint->svc_id = 0;
2158 endpoint->len_max = 0;
2159 endpoint->max_txq_depth = 0;
2160 memset(&endpoint->ep_st, 0,
2161 sizeof(endpoint->ep_st));
2162 INIT_LIST_HEAD(&endpoint->rx_bufq);
2163 INIT_LIST_HEAD(&endpoint->txq);
2164 endpoint->target = target;
2167 /* reset distribution list */
2168 INIT_LIST_HEAD(&target->cred_dist_list);
2171 int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
2172 enum htc_endpoint_id endpoint)
2176 spin_lock_bh(&target->rx_lock);
2177 num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
2178 spin_unlock_bh(&target->rx_lock);
2182 static void htc_setup_msg_bndl(struct htc_target *target)
2184 /* limit what HTC can handle */
2185 target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
2186 target->msg_per_bndl_max);
2188 if (ath6kl_hif_enable_scatter(target->dev->ar)) {
2189 target->msg_per_bndl_max = 0;
2193 /* limit bundle what the device layer can handle */
2194 target->msg_per_bndl_max = min(target->max_scat_entries,
2195 target->msg_per_bndl_max);
2197 ath6kl_dbg(ATH6KL_DBG_TRC,
2198 "htc bundling allowed. max msg per htc bundle: %d\n",
2199 target->msg_per_bndl_max);
2201 /* Max rx bundle size is limited by the max tx bundle size */
2202 target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
2203 /* Max tx bundle size if limited by the extended mbox address range */
2204 target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
2205 target->max_xfer_szper_scatreq);
2207 ath6kl_dbg(ATH6KL_DBG_ANY, "max recv: %d max send: %d\n",
2208 target->max_rx_bndl_sz, target->max_tx_bndl_sz);
2210 if (target->max_tx_bndl_sz)
2211 target->tx_bndl_enable = true;
2213 if (target->max_rx_bndl_sz)
2214 target->rx_bndl_enable = true;
2216 if ((target->tgt_cred_sz % target->block_sz) != 0) {
2217 ath6kl_warn("credit size: %d is not block aligned! Disabling send bundling\n",
2218 target->tgt_cred_sz);
2221 * Disallow send bundling since the credit size is
2222 * not aligned to a block size the I/O block
2223 * padding will spill into the next credit buffer
2226 target->tx_bndl_enable = false;
2230 int ath6kl_htc_wait_target(struct htc_target *target)
2232 struct htc_packet *packet = NULL;
2233 struct htc_ready_ext_msg *rdy_msg;
2234 struct htc_service_connect_req connect;
2235 struct htc_service_connect_resp resp;
2238 /* we should be getting 1 control message that the target is ready */
2239 packet = htc_wait_for_ctrl_msg(target);
2244 /* we controlled the buffer creation so it's properly aligned */
2245 rdy_msg = (struct htc_ready_ext_msg *)packet->buf;
2247 if ((le16_to_cpu(rdy_msg->ver2_0_info.msg_id) != HTC_MSG_READY_ID) ||
2248 (packet->act_len < sizeof(struct htc_ready_msg))) {
2250 goto fail_wait_target;
2253 if (!rdy_msg->ver2_0_info.cred_cnt || !rdy_msg->ver2_0_info.cred_sz) {
2255 goto fail_wait_target;
2258 target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
2259 target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
2261 ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
2262 "target ready: credits: %d credit size: %d\n",
2263 target->tgt_creds, target->tgt_cred_sz);
2265 /* check if this is an extended ready message */
2266 if (packet->act_len >= sizeof(struct htc_ready_ext_msg)) {
2267 /* this is an extended message */
2268 target->htc_tgt_ver = rdy_msg->htc_ver;
2269 target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
2272 target->htc_tgt_ver = HTC_VERSION_2P0;
2273 target->msg_per_bndl_max = 0;
2276 ath6kl_dbg(ATH6KL_DBG_TRC, "using htc protocol version : %s (%d)\n",
2277 (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
2278 target->htc_tgt_ver);
2280 if (target->msg_per_bndl_max > 0)
2281 htc_setup_msg_bndl(target);
2283 /* setup our pseudo HTC control endpoint connection */
2284 memset(&connect, 0, sizeof(connect));
2285 memset(&resp, 0, sizeof(resp));
2286 connect.ep_cb.rx = htc_ctrl_rx;
2287 connect.ep_cb.rx_refill = NULL;
2288 connect.ep_cb.tx_full = NULL;
2289 connect.max_txq_depth = NUM_CONTROL_BUFFERS;
2290 connect.svc_id = HTC_CTRL_RSVD_SVC;
2292 /* connect fake service */
2293 status = ath6kl_htc_conn_service((void *)target, &connect, &resp);
2296 ath6kl_hif_cleanup_scatter(target->dev->ar);
2300 htc_rxpkt_reset(packet);
2301 reclaim_rx_ctrl_buf(target, packet);
2308 * Start HTC, enable interrupts and let the target know
2309 * host has finished setup.
2311 int ath6kl_htc_start(struct htc_target *target)
2313 struct htc_packet *packet;
2316 /* Disable interrupts at the chip level */
2317 ath6kldev_disable_intrs(target->dev);
2319 target->htc_flags = 0;
2320 target->rx_st_flags = 0;
2322 /* Push control receive buffers into htc control endpoint */
2323 while ((packet = htc_get_control_buf(target, false)) != NULL) {
2324 status = htc_add_rxbuf(target, packet);
2329 /* NOTE: the first entry in the distribution list is ENDPOINT_0 */
2330 ath6k_credit_init(target->cred_dist_cntxt, &target->cred_dist_list,
2333 dump_cred_dist_stats(target);
2335 /* Indicate to the target of the setup completion */
2336 status = htc_setup_tx_complete(target);
2341 /* unmask interrupts */
2342 status = ath6kldev_unmask_intrs(target->dev);
2345 ath6kl_htc_stop(target);
2350 /* htc_stop: stop interrupt reception, and flush all queued buffers */
2351 void ath6kl_htc_stop(struct htc_target *target)
2353 spin_lock_bh(&target->htc_lock);
2354 target->htc_flags |= HTC_OP_STATE_STOPPING;
2355 spin_unlock_bh(&target->htc_lock);
2358 * Masking interrupts is a synchronous operation, when this
2359 * function returns all pending HIF I/O has completed, we can
2360 * safely flush the queues.
2362 ath6kldev_mask_intrs(target->dev);
2364 ath6kl_htc_flush_txep_all(target);
2366 ath6kl_htc_flush_rx_buf(target);
2368 reset_ep_state(target);
2371 void *ath6kl_htc_create(struct ath6kl *ar)
2373 struct htc_target *target = NULL;
2374 struct htc_packet *packet;
2375 int status = 0, i = 0;
2376 u32 block_size, ctrl_bufsz;
2378 target = kzalloc(sizeof(*target), GFP_KERNEL);
2380 ath6kl_err("unable to allocate memory\n");
2384 target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
2386 ath6kl_err("unable to allocate memory\n");
2388 goto fail_create_htc;
2391 spin_lock_init(&target->htc_lock);
2392 spin_lock_init(&target->rx_lock);
2393 spin_lock_init(&target->tx_lock);
2395 INIT_LIST_HEAD(&target->free_ctrl_txbuf);
2396 INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
2397 INIT_LIST_HEAD(&target->cred_dist_list);
2399 target->dev->ar = ar;
2400 target->dev->htc_cnxt = target;
2401 target->ep_waiting = ENDPOINT_MAX;
2403 reset_ep_state(target);
2405 status = ath6kldev_setup(target->dev);
2408 goto fail_create_htc;
2410 block_size = ar->mbox_info.block_size;
2412 ctrl_bufsz = (block_size > HTC_MAX_CTRL_MSG_LEN) ?
2413 (block_size + HTC_HDR_LENGTH) :
2414 (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH);
2416 for (i = 0; i < NUM_CONTROL_BUFFERS; i++) {
2417 packet = kzalloc(sizeof(*packet), GFP_KERNEL);
2421 packet->buf_start = kzalloc(ctrl_bufsz, GFP_KERNEL);
2422 if (!packet->buf_start) {
2427 packet->buf_len = ctrl_bufsz;
2428 if (i < NUM_CONTROL_RX_BUFFERS) {
2429 packet->act_len = 0;
2430 packet->buf = packet->buf_start;
2431 packet->endpoint = ENDPOINT_0;
2432 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
2434 list_add_tail(&packet->list, &target->free_ctrl_txbuf);
2438 if (i != NUM_CONTROL_BUFFERS || status) {
2440 ath6kl_htc_cleanup(target);
2448 /* cleanup the HTC instance */
2449 void ath6kl_htc_cleanup(struct htc_target *target)
2451 struct htc_packet *packet, *tmp_packet;
2453 ath6kl_hif_cleanup_scatter(target->dev->ar);
2455 list_for_each_entry_safe(packet, tmp_packet,
2456 &target->free_ctrl_txbuf, list) {
2457 list_del(&packet->list);
2458 kfree(packet->buf_start);
2462 list_for_each_entry_safe(packet, tmp_packet,
2463 &target->free_ctrl_rxbuf, list) {
2464 list_del(&packet->list);
2465 kfree(packet->buf_start);