2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 static inline void ath10k_htc_send_complete_check(struct ath10k_htc_ep *ep,
30 * Check whether HIF has any prior sends that have finished,
31 * have not had the post-processing done.
33 ath10k_hif_send_complete_check(ep->htc->ar, ep->ul_pipe_id, force);
36 static void ath10k_htc_control_tx_complete(struct ath10k *ar,
42 static struct sk_buff *ath10k_htc_build_tx_ctrl_skb(void *ar)
45 struct ath10k_skb_cb *skb_cb;
47 skb = dev_alloc_skb(ATH10K_HTC_CONTROL_BUFFER_SIZE);
51 skb_reserve(skb, 20); /* FIXME: why 20 bytes? */
52 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
54 skb_cb = ATH10K_SKB_CB(skb);
55 memset(skb_cb, 0, sizeof(*skb_cb));
57 ath10k_dbg(ar, ATH10K_DBG_HTC, "%s: skb %p\n", __func__, skb);
61 static inline void ath10k_htc_restore_tx_skb(struct ath10k_htc *htc,
64 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
66 dma_unmap_single(htc->ar->dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE);
67 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
70 static void ath10k_htc_notify_tx_completion(struct ath10k_htc_ep *ep,
73 struct ath10k *ar = ep->htc->ar;
75 ath10k_dbg(ar, ATH10K_DBG_HTC, "%s: ep %d skb %p\n", __func__,
78 ath10k_htc_restore_tx_skb(ep->htc, skb);
80 if (!ep->ep_ops.ep_tx_complete) {
81 ath10k_warn(ar, "no tx handler for eid %d\n", ep->eid);
82 dev_kfree_skb_any(skb);
86 ep->ep_ops.ep_tx_complete(ep->htc->ar, skb);
89 static void ath10k_htc_prepare_tx_skb(struct ath10k_htc_ep *ep,
92 struct ath10k_htc_hdr *hdr;
94 hdr = (struct ath10k_htc_hdr *)skb->data;
97 hdr->len = __cpu_to_le16(skb->len - sizeof(*hdr));
99 hdr->flags |= ATH10K_HTC_FLAG_NEED_CREDIT_UPDATE;
101 spin_lock_bh(&ep->htc->tx_lock);
102 hdr->seq_no = ep->seq_no++;
103 spin_unlock_bh(&ep->htc->tx_lock);
106 int ath10k_htc_send(struct ath10k_htc *htc,
107 enum ath10k_htc_ep_id eid,
110 struct ath10k *ar = htc->ar;
111 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
112 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
113 struct ath10k_hif_sg_item sg_item;
114 struct device *dev = htc->ar->dev;
118 if (htc->ar->state == ATH10K_STATE_WEDGED)
121 if (eid >= ATH10K_HTC_EP_COUNT) {
122 ath10k_warn(ar, "Invalid endpoint id: %d\n", eid);
126 skb_push(skb, sizeof(struct ath10k_htc_hdr));
128 if (ep->tx_credit_flow_enabled) {
129 credits = DIV_ROUND_UP(skb->len, htc->target_credit_size);
130 spin_lock_bh(&htc->tx_lock);
131 if (ep->tx_credits < credits) {
132 spin_unlock_bh(&htc->tx_lock);
136 ep->tx_credits -= credits;
137 ath10k_dbg(ar, ATH10K_DBG_HTC,
138 "htc ep %d consumed %d credits (total %d)\n",
139 eid, credits, ep->tx_credits);
140 spin_unlock_bh(&htc->tx_lock);
143 ath10k_htc_prepare_tx_skb(ep, skb);
146 skb_cb->paddr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
147 ret = dma_mapping_error(dev, skb_cb->paddr);
151 sg_item.transfer_id = ep->eid;
152 sg_item.transfer_context = skb;
153 sg_item.vaddr = skb->data;
154 sg_item.paddr = skb_cb->paddr;
155 sg_item.len = skb->len;
157 ret = ath10k_hif_tx_sg(htc->ar, ep->ul_pipe_id, &sg_item, 1);
164 dma_unmap_single(dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE);
166 if (ep->tx_credit_flow_enabled) {
167 spin_lock_bh(&htc->tx_lock);
168 ep->tx_credits += credits;
169 ath10k_dbg(ar, ATH10K_DBG_HTC,
170 "htc ep %d reverted %d credits back (total %d)\n",
171 eid, credits, ep->tx_credits);
172 spin_unlock_bh(&htc->tx_lock);
174 if (ep->ep_ops.ep_tx_credits)
175 ep->ep_ops.ep_tx_credits(htc->ar);
178 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
182 static int ath10k_htc_tx_completion_handler(struct ath10k *ar,
185 struct ath10k_htc *htc = &ar->htc;
186 struct ath10k_skb_cb *skb_cb;
187 struct ath10k_htc_ep *ep;
189 if (WARN_ON_ONCE(!skb))
192 skb_cb = ATH10K_SKB_CB(skb);
193 ep = &htc->endpoint[skb_cb->eid];
195 ath10k_htc_notify_tx_completion(ep, skb);
196 /* the skb now belongs to the completion handler */
206 ath10k_htc_process_credit_report(struct ath10k_htc *htc,
207 const struct ath10k_htc_credit_report *report,
209 enum ath10k_htc_ep_id eid)
211 struct ath10k *ar = htc->ar;
212 struct ath10k_htc_ep *ep;
215 if (len % sizeof(*report))
216 ath10k_warn(ar, "Uneven credit report len %d", len);
218 n_reports = len / sizeof(*report);
220 spin_lock_bh(&htc->tx_lock);
221 for (i = 0; i < n_reports; i++, report++) {
222 if (report->eid >= ATH10K_HTC_EP_COUNT)
225 ep = &htc->endpoint[report->eid];
226 ep->tx_credits += report->credits;
228 ath10k_dbg(ar, ATH10K_DBG_HTC, "htc ep %d got %d credits (total %d)\n",
229 report->eid, report->credits, ep->tx_credits);
231 if (ep->ep_ops.ep_tx_credits) {
232 spin_unlock_bh(&htc->tx_lock);
233 ep->ep_ops.ep_tx_credits(htc->ar);
234 spin_lock_bh(&htc->tx_lock);
237 spin_unlock_bh(&htc->tx_lock);
240 static int ath10k_htc_process_trailer(struct ath10k_htc *htc,
243 enum ath10k_htc_ep_id src_eid)
245 struct ath10k *ar = htc->ar;
247 struct ath10k_htc_record *record;
252 orig_buffer = buffer;
253 orig_length = length;
256 record = (struct ath10k_htc_record *)buffer;
258 if (length < sizeof(record->hdr)) {
263 if (record->hdr.len > length) {
264 /* no room left in buffer for record */
265 ath10k_warn(ar, "Invalid record length: %d\n",
271 switch (record->hdr.id) {
272 case ATH10K_HTC_RECORD_CREDITS:
273 len = sizeof(struct ath10k_htc_credit_report);
274 if (record->hdr.len < len) {
275 ath10k_warn(ar, "Credit report too long\n");
279 ath10k_htc_process_credit_report(htc,
280 record->credit_report,
285 ath10k_warn(ar, "Unhandled record: id:%d length:%d\n",
286 record->hdr.id, record->hdr.len);
293 /* multiple records may be present in a trailer */
294 buffer += sizeof(record->hdr) + record->hdr.len;
295 length -= sizeof(record->hdr) + record->hdr.len;
299 ath10k_dbg_dump(ar, ATH10K_DBG_HTC, "htc rx bad trailer", "",
300 orig_buffer, orig_length);
305 static int ath10k_htc_rx_completion_handler(struct ath10k *ar,
309 struct ath10k_htc *htc = &ar->htc;
310 struct ath10k_htc_hdr *hdr;
311 struct ath10k_htc_ep *ep;
316 bool trailer_present;
318 hdr = (struct ath10k_htc_hdr *)skb->data;
319 skb_pull(skb, sizeof(*hdr));
323 if (eid >= ATH10K_HTC_EP_COUNT) {
324 ath10k_warn(ar, "HTC Rx: invalid eid %d\n", eid);
325 ath10k_dbg_dump(ar, ATH10K_DBG_HTC, "htc bad header", "",
331 ep = &htc->endpoint[eid];
334 * If this endpoint that received a message from the target has
335 * a to-target HIF pipe whose send completions are polled rather
336 * than interrupt-driven, this is a good point to ask HIF to check
337 * whether it has any completed sends to handle.
339 if (ep->ul_is_polled)
340 ath10k_htc_send_complete_check(ep, 1);
342 payload_len = __le16_to_cpu(hdr->len);
344 if (payload_len + sizeof(*hdr) > ATH10K_HTC_MAX_LEN) {
345 ath10k_warn(ar, "HTC rx frame too long, len: %zu\n",
346 payload_len + sizeof(*hdr));
347 ath10k_dbg_dump(ar, ATH10K_DBG_HTC, "htc bad rx pkt len", "",
353 if (skb->len < payload_len) {
354 ath10k_dbg(ar, ATH10K_DBG_HTC,
355 "HTC Rx: insufficient length, got %d, expected %d\n",
356 skb->len, payload_len);
357 ath10k_dbg_dump(ar, ATH10K_DBG_HTC, "htc bad rx pkt len",
358 "", hdr, sizeof(*hdr));
363 /* get flags to check for trailer */
364 trailer_present = hdr->flags & ATH10K_HTC_FLAG_TRAILER_PRESENT;
365 if (trailer_present) {
368 trailer_len = hdr->trailer_len;
369 min_len = sizeof(struct ath10k_ath10k_htc_record_hdr);
371 if ((trailer_len < min_len) ||
372 (trailer_len > payload_len)) {
373 ath10k_warn(ar, "Invalid trailer length: %d\n",
380 trailer += sizeof(*hdr);
381 trailer += payload_len;
382 trailer -= trailer_len;
383 status = ath10k_htc_process_trailer(htc, trailer,
384 trailer_len, hdr->eid);
388 skb_trim(skb, skb->len - trailer_len);
391 if (((int)payload_len - (int)trailer_len) <= 0)
392 /* zero length packet with trailer data, just drop these */
395 if (eid == ATH10K_HTC_EP_0) {
396 struct ath10k_htc_msg *msg = (struct ath10k_htc_msg *)skb->data;
398 switch (__le16_to_cpu(msg->hdr.message_id)) {
399 case ATH10K_HTC_MSG_READY_ID:
400 case ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID:
401 /* handle HTC control message */
402 if (completion_done(&htc->ctl_resp)) {
404 * this is a fatal error, target should not be
405 * sending unsolicited messages on the ep 0
407 ath10k_warn(ar, "HTC rx ctrl still processing\n");
409 complete(&htc->ctl_resp);
413 htc->control_resp_len =
415 ATH10K_HTC_MAX_CTRL_MSG_LEN);
417 memcpy(htc->control_resp_buffer, skb->data,
418 htc->control_resp_len);
420 complete(&htc->ctl_resp);
422 case ATH10K_HTC_MSG_SEND_SUSPEND_COMPLETE:
423 htc->htc_ops.target_send_suspend_complete(ar);
426 ath10k_warn(ar, "ignoring unsolicited htc ep0 event\n");
432 ath10k_dbg(ar, ATH10K_DBG_HTC, "htc rx completion ep %d skb %p\n",
434 ep->ep_ops.ep_rx_complete(ar, skb);
436 /* skb is now owned by the rx completion handler */
444 static void ath10k_htc_control_rx_complete(struct ath10k *ar,
447 /* This is unexpected. FW is not supposed to send regular rx on this
449 ath10k_warn(ar, "unexpected htc rx\n");
457 static const char *htc_service_name(enum ath10k_htc_svc_id id)
460 case ATH10K_HTC_SVC_ID_RESERVED:
462 case ATH10K_HTC_SVC_ID_RSVD_CTRL:
464 case ATH10K_HTC_SVC_ID_WMI_CONTROL:
466 case ATH10K_HTC_SVC_ID_WMI_DATA_BE:
468 case ATH10K_HTC_SVC_ID_WMI_DATA_BK:
470 case ATH10K_HTC_SVC_ID_WMI_DATA_VI:
472 case ATH10K_HTC_SVC_ID_WMI_DATA_VO:
474 case ATH10K_HTC_SVC_ID_NMI_CONTROL:
475 return "NMI Control";
476 case ATH10K_HTC_SVC_ID_NMI_DATA:
478 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG:
480 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS:
487 static void ath10k_htc_reset_endpoint_states(struct ath10k_htc *htc)
489 struct ath10k_htc_ep *ep;
492 for (i = ATH10K_HTC_EP_0; i < ATH10K_HTC_EP_COUNT; i++) {
493 ep = &htc->endpoint[i];
494 ep->service_id = ATH10K_HTC_SVC_ID_UNUSED;
495 ep->max_ep_message_len = 0;
496 ep->max_tx_queue_depth = 0;
499 ep->tx_credit_flow_enabled = true;
503 static void ath10k_htc_setup_target_buffer_assignments(struct ath10k_htc *htc)
505 struct ath10k_htc_svc_tx_credits *entry;
507 entry = &htc->service_tx_alloc[0];
510 * for PCIE allocate all credists/HTC buffers to WMI.
511 * no buffers are used/required for data. data always
515 entry->service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
516 entry->credit_allocation = htc->total_transmit_credits;
519 static u8 ath10k_htc_get_credit_allocation(struct ath10k_htc *htc,
525 for (i = 0; i < ATH10K_HTC_EP_COUNT; i++) {
526 if (htc->service_tx_alloc[i].service_id == service_id)
528 htc->service_tx_alloc[i].credit_allocation;
534 int ath10k_htc_wait_target(struct ath10k_htc *htc)
536 struct ath10k *ar = htc->ar;
538 unsigned long time_left;
539 struct ath10k_htc_svc_conn_req conn_req;
540 struct ath10k_htc_svc_conn_resp conn_resp;
541 struct ath10k_htc_msg *msg;
546 time_left = wait_for_completion_timeout(&htc->ctl_resp,
547 ATH10K_HTC_WAIT_TIMEOUT_HZ);
549 /* Workaround: In some cases the PCI HIF doesn't
550 * receive interrupt for the control response message
551 * even if the buffer was completed. It is suspected
552 * iomap writes unmasking PCI CE irqs aren't propagated
553 * properly in KVM PCI-passthrough sometimes.
555 ath10k_warn(ar, "failed to receive control response completion, polling..\n");
557 for (i = 0; i < CE_COUNT; i++)
558 ath10k_hif_send_complete_check(htc->ar, i, 1);
561 wait_for_completion_timeout(&htc->ctl_resp,
562 ATH10K_HTC_WAIT_TIMEOUT_HZ);
569 ath10k_err(ar, "ctl_resp never came in (%d)\n", status);
573 if (htc->control_resp_len < sizeof(msg->hdr) + sizeof(msg->ready)) {
574 ath10k_err(ar, "Invalid HTC ready msg len:%d\n",
575 htc->control_resp_len);
579 msg = (struct ath10k_htc_msg *)htc->control_resp_buffer;
580 message_id = __le16_to_cpu(msg->hdr.message_id);
581 credit_count = __le16_to_cpu(msg->ready.credit_count);
582 credit_size = __le16_to_cpu(msg->ready.credit_size);
584 if (message_id != ATH10K_HTC_MSG_READY_ID) {
585 ath10k_err(ar, "Invalid HTC ready msg: 0x%x\n", message_id);
589 htc->total_transmit_credits = credit_count;
590 htc->target_credit_size = credit_size;
592 ath10k_dbg(ar, ATH10K_DBG_HTC,
593 "Target ready! transmit resources: %d size:%d\n",
594 htc->total_transmit_credits,
595 htc->target_credit_size);
597 if ((htc->total_transmit_credits == 0) ||
598 (htc->target_credit_size == 0)) {
599 ath10k_err(ar, "Invalid credit size received\n");
603 ath10k_htc_setup_target_buffer_assignments(htc);
605 /* setup our pseudo HTC control endpoint connection */
606 memset(&conn_req, 0, sizeof(conn_req));
607 memset(&conn_resp, 0, sizeof(conn_resp));
608 conn_req.ep_ops.ep_tx_complete = ath10k_htc_control_tx_complete;
609 conn_req.ep_ops.ep_rx_complete = ath10k_htc_control_rx_complete;
610 conn_req.max_send_queue_depth = ATH10K_NUM_CONTROL_TX_BUFFERS;
611 conn_req.service_id = ATH10K_HTC_SVC_ID_RSVD_CTRL;
613 /* connect fake service */
614 status = ath10k_htc_connect_service(htc, &conn_req, &conn_resp);
616 ath10k_err(ar, "could not connect to htc service (%d)\n",
624 int ath10k_htc_connect_service(struct ath10k_htc *htc,
625 struct ath10k_htc_svc_conn_req *conn_req,
626 struct ath10k_htc_svc_conn_resp *conn_resp)
628 struct ath10k *ar = htc->ar;
629 struct ath10k_htc_msg *msg;
630 struct ath10k_htc_conn_svc *req_msg;
631 struct ath10k_htc_conn_svc_response resp_msg_dummy;
632 struct ath10k_htc_conn_svc_response *resp_msg = &resp_msg_dummy;
633 enum ath10k_htc_ep_id assigned_eid = ATH10K_HTC_EP_COUNT;
634 struct ath10k_htc_ep *ep;
636 unsigned int max_msg_size = 0;
638 unsigned long time_left;
639 bool disable_credit_flow_ctrl = false;
640 u16 message_id, service_id, flags = 0;
643 /* special case for HTC pseudo control service */
644 if (conn_req->service_id == ATH10K_HTC_SVC_ID_RSVD_CTRL) {
645 disable_credit_flow_ctrl = true;
646 assigned_eid = ATH10K_HTC_EP_0;
647 max_msg_size = ATH10K_HTC_MAX_CTRL_MSG_LEN;
648 memset(&resp_msg_dummy, 0, sizeof(resp_msg_dummy));
652 tx_alloc = ath10k_htc_get_credit_allocation(htc,
653 conn_req->service_id);
655 ath10k_dbg(ar, ATH10K_DBG_BOOT,
656 "boot htc service %s does not allocate target credits\n",
657 htc_service_name(conn_req->service_id));
659 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar);
661 ath10k_err(ar, "Failed to allocate HTC packet\n");
665 length = sizeof(msg->hdr) + sizeof(msg->connect_service);
666 skb_put(skb, length);
667 memset(skb->data, 0, length);
669 msg = (struct ath10k_htc_msg *)skb->data;
670 msg->hdr.message_id =
671 __cpu_to_le16(ATH10K_HTC_MSG_CONNECT_SERVICE_ID);
673 flags |= SM(tx_alloc, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC);
675 /* Only enable credit flow control for WMI ctrl service */
676 if (conn_req->service_id != ATH10K_HTC_SVC_ID_WMI_CONTROL) {
677 flags |= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
678 disable_credit_flow_ctrl = true;
681 req_msg = &msg->connect_service;
682 req_msg->flags = __cpu_to_le16(flags);
683 req_msg->service_id = __cpu_to_le16(conn_req->service_id);
685 reinit_completion(&htc->ctl_resp);
687 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb);
693 /* wait for response */
694 time_left = wait_for_completion_timeout(&htc->ctl_resp,
695 ATH10K_HTC_CONN_SVC_TIMEOUT_HZ);
697 ath10k_err(ar, "Service connect timeout\n");
701 /* we controlled the buffer creation, it's aligned */
702 msg = (struct ath10k_htc_msg *)htc->control_resp_buffer;
703 resp_msg = &msg->connect_service_response;
704 message_id = __le16_to_cpu(msg->hdr.message_id);
705 service_id = __le16_to_cpu(resp_msg->service_id);
707 if ((message_id != ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID) ||
708 (htc->control_resp_len < sizeof(msg->hdr) +
709 sizeof(msg->connect_service_response))) {
710 ath10k_err(ar, "Invalid resp message ID 0x%x", message_id);
714 ath10k_dbg(ar, ATH10K_DBG_HTC,
715 "HTC Service %s connect response: status: 0x%x, assigned ep: 0x%x\n",
716 htc_service_name(service_id),
717 resp_msg->status, resp_msg->eid);
719 conn_resp->connect_resp_code = resp_msg->status;
721 /* check response status */
722 if (resp_msg->status != ATH10K_HTC_CONN_SVC_STATUS_SUCCESS) {
723 ath10k_err(ar, "HTC Service %s connect request failed: 0x%x)\n",
724 htc_service_name(service_id),
729 assigned_eid = (enum ath10k_htc_ep_id)resp_msg->eid;
730 max_msg_size = __le16_to_cpu(resp_msg->max_msg_size);
734 if (assigned_eid >= ATH10K_HTC_EP_COUNT)
737 if (max_msg_size == 0)
740 ep = &htc->endpoint[assigned_eid];
741 ep->eid = assigned_eid;
743 if (ep->service_id != ATH10K_HTC_SVC_ID_UNUSED)
746 /* return assigned endpoint to caller */
747 conn_resp->eid = assigned_eid;
748 conn_resp->max_msg_len = __le16_to_cpu(resp_msg->max_msg_size);
750 /* setup the endpoint */
751 ep->service_id = conn_req->service_id;
752 ep->max_tx_queue_depth = conn_req->max_send_queue_depth;
753 ep->max_ep_message_len = __le16_to_cpu(resp_msg->max_msg_size);
754 ep->tx_credits = tx_alloc;
755 ep->tx_credit_size = htc->target_credit_size;
756 ep->tx_credits_per_max_message = ep->max_ep_message_len /
757 htc->target_credit_size;
759 if (ep->max_ep_message_len % htc->target_credit_size)
760 ep->tx_credits_per_max_message++;
762 /* copy all the callbacks */
763 ep->ep_ops = conn_req->ep_ops;
765 status = ath10k_hif_map_service_to_pipe(htc->ar,
774 ath10k_dbg(ar, ATH10K_DBG_BOOT,
775 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
776 htc_service_name(ep->service_id), ep->ul_pipe_id,
777 ep->dl_pipe_id, ep->eid);
779 ath10k_dbg(ar, ATH10K_DBG_BOOT,
780 "boot htc ep %d ul polled %d dl polled %d\n",
781 ep->eid, ep->ul_is_polled, ep->dl_is_polled);
783 if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) {
784 ep->tx_credit_flow_enabled = false;
785 ath10k_dbg(ar, ATH10K_DBG_BOOT,
786 "boot htc service '%s' eid %d TX flow control disabled\n",
787 htc_service_name(ep->service_id), assigned_eid);
793 struct sk_buff *ath10k_htc_alloc_skb(struct ath10k *ar, int size)
797 skb = dev_alloc_skb(size + sizeof(struct ath10k_htc_hdr));
801 skb_reserve(skb, sizeof(struct ath10k_htc_hdr));
803 /* FW/HTC requires 4-byte aligned streams */
804 if (!IS_ALIGNED((unsigned long)skb->data, 4))
805 ath10k_warn(ar, "Unaligned HTC tx skb\n");
810 int ath10k_htc_start(struct ath10k_htc *htc)
812 struct ath10k *ar = htc->ar;
815 struct ath10k_htc_msg *msg;
817 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar);
821 skb_put(skb, sizeof(msg->hdr) + sizeof(msg->setup_complete_ext));
822 memset(skb->data, 0, skb->len);
824 msg = (struct ath10k_htc_msg *)skb->data;
825 msg->hdr.message_id =
826 __cpu_to_le16(ATH10K_HTC_MSG_SETUP_COMPLETE_EX_ID);
828 ath10k_dbg(ar, ATH10K_DBG_HTC, "HTC is using TX credit flow control\n");
830 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb);
839 /* registered target arrival callback from the HIF layer */
840 int ath10k_htc_init(struct ath10k *ar)
842 struct ath10k_hif_cb htc_callbacks;
843 struct ath10k_htc_ep *ep = NULL;
844 struct ath10k_htc *htc = &ar->htc;
846 spin_lock_init(&htc->tx_lock);
848 ath10k_htc_reset_endpoint_states(htc);
850 /* setup HIF layer callbacks */
851 htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
852 htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
855 /* Get HIF default pipe for HTC message exchange */
856 ep = &htc->endpoint[ATH10K_HTC_EP_0];
858 ath10k_hif_set_callbacks(ar, &htc_callbacks);
859 ath10k_hif_get_default_pipe(ar, &ep->ul_pipe_id, &ep->dl_pipe_id);
861 init_completion(&htc->ctl_resp);