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);
49 ath10k_warn("Unable to allocate ctrl skb\n");
53 skb_reserve(skb, 20); /* FIXME: why 20 bytes? */
54 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
56 skb_cb = ATH10K_SKB_CB(skb);
57 memset(skb_cb, 0, sizeof(*skb_cb));
59 ath10k_dbg(ATH10K_DBG_HTC, "%s: skb %p\n", __func__, skb);
63 static inline void ath10k_htc_restore_tx_skb(struct ath10k_htc *htc,
66 ath10k_skb_unmap(htc->ar->dev, skb);
67 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
70 static void ath10k_htc_notify_tx_completion(struct ath10k_htc_ep *ep,
73 ath10k_dbg(ATH10K_DBG_HTC, "%s: ep %d skb %p\n", __func__,
76 ath10k_htc_restore_tx_skb(ep->htc, skb);
78 if (!ep->ep_ops.ep_tx_complete) {
79 ath10k_warn("no tx handler for eid %d\n", ep->eid);
80 dev_kfree_skb_any(skb);
84 ep->ep_ops.ep_tx_complete(ep->htc->ar, skb);
87 /* assumes tx_lock is held */
88 static bool ath10k_htc_ep_need_credit_update(struct ath10k_htc_ep *ep)
90 if (!ep->tx_credit_flow_enabled)
92 if (ep->tx_credits >= ep->tx_credits_per_max_message)
95 ath10k_dbg(ATH10K_DBG_HTC, "HTC: endpoint %d needs credit update\n",
100 static void ath10k_htc_prepare_tx_skb(struct ath10k_htc_ep *ep,
103 struct ath10k_htc_hdr *hdr;
105 hdr = (struct ath10k_htc_hdr *)skb->data;
106 memset(hdr, 0, sizeof(*hdr));
109 hdr->len = __cpu_to_le16(skb->len - sizeof(*hdr));
111 spin_lock_bh(&ep->htc->tx_lock);
112 hdr->seq_no = ep->seq_no++;
114 if (ath10k_htc_ep_need_credit_update(ep))
115 hdr->flags |= ATH10K_HTC_FLAG_NEED_CREDIT_UPDATE;
117 spin_unlock_bh(&ep->htc->tx_lock);
120 static int ath10k_htc_issue_skb(struct ath10k_htc *htc,
121 struct ath10k_htc_ep *ep,
125 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
128 ath10k_dbg(ATH10K_DBG_HTC, "%s: ep %d skb %p\n", __func__,
131 ath10k_htc_prepare_tx_skb(ep, skb);
133 ret = ath10k_skb_map(htc->ar->dev, skb);
137 ret = ath10k_hif_send_head(htc->ar,
147 ath10k_warn("HTC issue failed: %d\n", ret);
149 spin_lock_bh(&htc->tx_lock);
150 ep->tx_credits += credits;
151 spin_unlock_bh(&htc->tx_lock);
153 if (ep->ep_ops.ep_tx_credits)
154 ep->ep_ops.ep_tx_credits(htc->ar);
156 /* this is the simplest way to handle out-of-resources for non-credit
157 * based endpoints. credit based endpoints can still get -ENOSR, but
158 * this is highly unlikely as credit reservation should prevent that */
160 spin_lock_bh(&htc->tx_lock);
161 __skb_queue_head(&ep->tx_queue, skb);
162 spin_unlock_bh(&htc->tx_lock);
167 skb_cb->is_aborted = true;
168 ath10k_htc_notify_tx_completion(ep, skb);
173 static void ath10k_htc_send_work(struct work_struct *work)
175 struct ath10k_htc_ep *ep = container_of(work,
176 struct ath10k_htc_ep, send_work);
177 struct ath10k_htc *htc = ep->htc;
183 if (ep->ul_is_polled)
184 ath10k_htc_send_complete_check(ep, 0);
186 spin_lock_bh(&htc->tx_lock);
187 skb = __skb_dequeue(&ep->tx_queue);
189 if (ep->tx_credit_flow_enabled) {
190 credits = DIV_ROUND_UP(skb->len,
191 htc->target_credit_size);
192 if (ep->tx_credits < credits) {
193 __skb_queue_head(&ep->tx_queue, skb);
197 spin_unlock_bh(&htc->tx_lock);
202 ret = ath10k_htc_issue_skb(htc, ep, skb, credits);
208 int ath10k_htc_send(struct ath10k_htc *htc,
209 enum ath10k_htc_ep_id eid,
212 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
214 if (htc->ar->state == ATH10K_STATE_WEDGED)
217 if (eid >= ATH10K_HTC_EP_COUNT) {
218 ath10k_warn("Invalid endpoint id: %d\n", eid);
222 spin_lock_bh(&htc->tx_lock);
224 spin_unlock_bh(&htc->tx_lock);
228 __skb_queue_tail(&ep->tx_queue, skb);
229 skb_push(skb, sizeof(struct ath10k_htc_hdr));
230 spin_unlock_bh(&htc->tx_lock);
232 queue_work(htc->ar->workqueue, &ep->send_work);
236 static int ath10k_htc_tx_completion_handler(struct ath10k *ar,
240 struct ath10k_htc *htc = &ar->htc;
241 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
243 ath10k_htc_notify_tx_completion(ep, skb);
244 /* the skb now belongs to the completion handler */
246 /* note: when using TX credit flow, the re-checking of queues happens
247 * when credits flow back from the target. in the non-TX credit case,
248 * we recheck after the packet completes */
249 spin_lock_bh(&htc->tx_lock);
250 if (!ep->tx_credit_flow_enabled && !htc->stopped)
251 queue_work(ar->workqueue, &ep->send_work);
252 spin_unlock_bh(&htc->tx_lock);
257 /* flush endpoint TX queue */
258 static void ath10k_htc_flush_endpoint_tx(struct ath10k_htc *htc,
259 struct ath10k_htc_ep *ep)
262 struct ath10k_skb_cb *skb_cb;
264 spin_lock_bh(&htc->tx_lock);
266 skb = __skb_dequeue(&ep->tx_queue);
270 skb_cb = ATH10K_SKB_CB(skb);
271 skb_cb->is_aborted = true;
272 ath10k_htc_notify_tx_completion(ep, skb);
274 spin_unlock_bh(&htc->tx_lock);
276 cancel_work_sync(&ep->send_work);
284 ath10k_htc_process_credit_report(struct ath10k_htc *htc,
285 const struct ath10k_htc_credit_report *report,
287 enum ath10k_htc_ep_id eid)
289 struct ath10k_htc_ep *ep;
292 if (len % sizeof(*report))
293 ath10k_warn("Uneven credit report len %d", len);
295 n_reports = len / sizeof(*report);
297 spin_lock_bh(&htc->tx_lock);
298 for (i = 0; i < n_reports; i++, report++) {
299 if (report->eid >= ATH10K_HTC_EP_COUNT)
302 ath10k_dbg(ATH10K_DBG_HTC, "ep %d got %d credits\n",
303 report->eid, report->credits);
305 ep = &htc->endpoint[report->eid];
306 ep->tx_credits += report->credits;
308 if (ep->ep_ops.ep_tx_credits) {
309 spin_unlock_bh(&htc->tx_lock);
310 ep->ep_ops.ep_tx_credits(htc->ar);
311 spin_lock_bh(&htc->tx_lock);
314 if (ep->tx_credits && !skb_queue_empty(&ep->tx_queue))
315 queue_work(htc->ar->workqueue, &ep->send_work);
317 spin_unlock_bh(&htc->tx_lock);
320 static int ath10k_htc_process_trailer(struct ath10k_htc *htc,
323 enum ath10k_htc_ep_id src_eid)
326 struct ath10k_htc_record *record;
331 orig_buffer = buffer;
332 orig_length = length;
335 record = (struct ath10k_htc_record *)buffer;
337 if (length < sizeof(record->hdr)) {
342 if (record->hdr.len > length) {
343 /* no room left in buffer for record */
344 ath10k_warn("Invalid record length: %d\n",
350 switch (record->hdr.id) {
351 case ATH10K_HTC_RECORD_CREDITS:
352 len = sizeof(struct ath10k_htc_credit_report);
353 if (record->hdr.len < len) {
354 ath10k_warn("Credit report too long\n");
358 ath10k_htc_process_credit_report(htc,
359 record->credit_report,
364 ath10k_warn("Unhandled record: id:%d length:%d\n",
365 record->hdr.id, record->hdr.len);
372 /* multiple records may be present in a trailer */
373 buffer += sizeof(record->hdr) + record->hdr.len;
374 length -= sizeof(record->hdr) + record->hdr.len;
378 ath10k_dbg_dump(ATH10K_DBG_HTC, "htc rx bad trailer", "",
379 orig_buffer, orig_length);
384 static int ath10k_htc_rx_completion_handler(struct ath10k *ar,
389 struct ath10k_htc *htc = &ar->htc;
390 struct ath10k_htc_hdr *hdr;
391 struct ath10k_htc_ep *ep;
396 bool trailer_present;
398 hdr = (struct ath10k_htc_hdr *)skb->data;
399 skb_pull(skb, sizeof(*hdr));
403 if (eid >= ATH10K_HTC_EP_COUNT) {
404 ath10k_warn("HTC Rx: invalid eid %d\n", eid);
405 ath10k_dbg_dump(ATH10K_DBG_HTC, "htc bad header", "",
411 ep = &htc->endpoint[eid];
414 * If this endpoint that received a message from the target has
415 * a to-target HIF pipe whose send completions are polled rather
416 * than interrupt-driven, this is a good point to ask HIF to check
417 * whether it has any completed sends to handle.
419 if (ep->ul_is_polled)
420 ath10k_htc_send_complete_check(ep, 1);
422 payload_len = __le16_to_cpu(hdr->len);
424 if (payload_len + sizeof(*hdr) > ATH10K_HTC_MAX_LEN) {
425 ath10k_warn("HTC rx frame too long, len: %zu\n",
426 payload_len + sizeof(*hdr));
427 ath10k_dbg_dump(ATH10K_DBG_HTC, "htc bad rx pkt len", "",
433 if (skb->len < payload_len) {
434 ath10k_dbg(ATH10K_DBG_HTC,
435 "HTC Rx: insufficient length, got %d, expected %d\n",
436 skb->len, payload_len);
437 ath10k_dbg_dump(ATH10K_DBG_HTC, "htc bad rx pkt len",
438 "", hdr, sizeof(*hdr));
443 /* get flags to check for trailer */
444 trailer_present = hdr->flags & ATH10K_HTC_FLAG_TRAILER_PRESENT;
445 if (trailer_present) {
448 trailer_len = hdr->trailer_len;
449 min_len = sizeof(struct ath10k_ath10k_htc_record_hdr);
451 if ((trailer_len < min_len) ||
452 (trailer_len > payload_len)) {
453 ath10k_warn("Invalid trailer length: %d\n",
460 trailer += sizeof(*hdr);
461 trailer += payload_len;
462 trailer -= trailer_len;
463 status = ath10k_htc_process_trailer(htc, trailer,
464 trailer_len, hdr->eid);
468 skb_trim(skb, skb->len - trailer_len);
471 if (((int)payload_len - (int)trailer_len) <= 0)
472 /* zero length packet with trailer data, just drop these */
475 if (eid == ATH10K_HTC_EP_0) {
476 struct ath10k_htc_msg *msg = (struct ath10k_htc_msg *)skb->data;
478 switch (__le16_to_cpu(msg->hdr.message_id)) {
480 /* handle HTC control message */
481 if (completion_done(&htc->ctl_resp)) {
483 * this is a fatal error, target should not be
484 * sending unsolicited messages on the ep 0
486 ath10k_warn("HTC rx ctrl still processing\n");
488 complete(&htc->ctl_resp);
492 htc->control_resp_len =
494 ATH10K_HTC_MAX_CTRL_MSG_LEN);
496 memcpy(htc->control_resp_buffer, skb->data,
497 htc->control_resp_len);
499 complete(&htc->ctl_resp);
501 case ATH10K_HTC_MSG_SEND_SUSPEND_COMPLETE:
502 htc->htc_ops.target_send_suspend_complete(ar);
507 ath10k_dbg(ATH10K_DBG_HTC, "htc rx completion ep %d skb %p\n",
509 ep->ep_ops.ep_rx_complete(ar, skb);
511 /* skb is now owned by the rx completion handler */
519 static void ath10k_htc_control_rx_complete(struct ath10k *ar,
522 /* This is unexpected. FW is not supposed to send regular rx on this
524 ath10k_warn("unexpected htc rx\n");
532 static const char *htc_service_name(enum ath10k_htc_svc_id id)
535 case ATH10K_HTC_SVC_ID_RESERVED:
537 case ATH10K_HTC_SVC_ID_RSVD_CTRL:
539 case ATH10K_HTC_SVC_ID_WMI_CONTROL:
541 case ATH10K_HTC_SVC_ID_WMI_DATA_BE:
543 case ATH10K_HTC_SVC_ID_WMI_DATA_BK:
545 case ATH10K_HTC_SVC_ID_WMI_DATA_VI:
547 case ATH10K_HTC_SVC_ID_WMI_DATA_VO:
549 case ATH10K_HTC_SVC_ID_NMI_CONTROL:
550 return "NMI Control";
551 case ATH10K_HTC_SVC_ID_NMI_DATA:
553 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG:
555 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS:
562 static void ath10k_htc_reset_endpoint_states(struct ath10k_htc *htc)
564 struct ath10k_htc_ep *ep;
567 for (i = ATH10K_HTC_EP_0; i < ATH10K_HTC_EP_COUNT; i++) {
568 ep = &htc->endpoint[i];
569 ep->service_id = ATH10K_HTC_SVC_ID_UNUSED;
570 ep->max_ep_message_len = 0;
571 ep->max_tx_queue_depth = 0;
573 skb_queue_head_init(&ep->tx_queue);
575 ep->tx_credit_flow_enabled = true;
576 INIT_WORK(&ep->send_work, ath10k_htc_send_work);
580 static void ath10k_htc_setup_target_buffer_assignments(struct ath10k_htc *htc)
582 struct ath10k_htc_svc_tx_credits *entry;
584 entry = &htc->service_tx_alloc[0];
587 * for PCIE allocate all credists/HTC buffers to WMI.
588 * no buffers are used/required for data. data always
592 entry->service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
593 entry->credit_allocation = htc->total_transmit_credits;
596 static u8 ath10k_htc_get_credit_allocation(struct ath10k_htc *htc,
602 for (i = 0; i < ATH10K_HTC_EP_COUNT; i++) {
603 if (htc->service_tx_alloc[i].service_id == service_id)
605 htc->service_tx_alloc[i].credit_allocation;
611 int ath10k_htc_wait_target(struct ath10k_htc *htc)
614 struct ath10k_htc_svc_conn_req conn_req;
615 struct ath10k_htc_svc_conn_resp conn_resp;
616 struct ath10k_htc_msg *msg;
621 INIT_COMPLETION(htc->ctl_resp);
623 status = ath10k_hif_start(htc->ar);
625 ath10k_err("could not start HIF (%d)\n", status);
629 status = wait_for_completion_timeout(&htc->ctl_resp,
630 ATH10K_HTC_WAIT_TIMEOUT_HZ);
635 ath10k_err("ctl_resp never came in (%d)\n", status);
639 if (htc->control_resp_len < sizeof(msg->hdr) + sizeof(msg->ready)) {
640 ath10k_err("Invalid HTC ready msg len:%d\n",
641 htc->control_resp_len);
647 msg = (struct ath10k_htc_msg *)htc->control_resp_buffer;
648 message_id = __le16_to_cpu(msg->hdr.message_id);
649 credit_count = __le16_to_cpu(msg->ready.credit_count);
650 credit_size = __le16_to_cpu(msg->ready.credit_size);
652 if (message_id != ATH10K_HTC_MSG_READY_ID) {
653 ath10k_err("Invalid HTC ready msg: 0x%x\n", message_id);
658 htc->total_transmit_credits = credit_count;
659 htc->target_credit_size = credit_size;
661 ath10k_dbg(ATH10K_DBG_HTC,
662 "Target ready! transmit resources: %d size:%d\n",
663 htc->total_transmit_credits,
664 htc->target_credit_size);
666 if ((htc->total_transmit_credits == 0) ||
667 (htc->target_credit_size == 0)) {
669 ath10k_err("Invalid credit size received\n");
673 ath10k_htc_setup_target_buffer_assignments(htc);
675 /* setup our pseudo HTC control endpoint connection */
676 memset(&conn_req, 0, sizeof(conn_req));
677 memset(&conn_resp, 0, sizeof(conn_resp));
678 conn_req.ep_ops.ep_tx_complete = ath10k_htc_control_tx_complete;
679 conn_req.ep_ops.ep_rx_complete = ath10k_htc_control_rx_complete;
680 conn_req.max_send_queue_depth = ATH10K_NUM_CONTROL_TX_BUFFERS;
681 conn_req.service_id = ATH10K_HTC_SVC_ID_RSVD_CTRL;
683 /* connect fake service */
684 status = ath10k_htc_connect_service(htc, &conn_req, &conn_resp);
686 ath10k_err("could not connect to htc service (%d)\n", status);
692 ath10k_hif_stop(htc->ar);
697 int ath10k_htc_connect_service(struct ath10k_htc *htc,
698 struct ath10k_htc_svc_conn_req *conn_req,
699 struct ath10k_htc_svc_conn_resp *conn_resp)
701 struct ath10k_htc_msg *msg;
702 struct ath10k_htc_conn_svc *req_msg;
703 struct ath10k_htc_conn_svc_response resp_msg_dummy;
704 struct ath10k_htc_conn_svc_response *resp_msg = &resp_msg_dummy;
705 enum ath10k_htc_ep_id assigned_eid = ATH10K_HTC_EP_COUNT;
706 struct ath10k_htc_ep *ep;
708 unsigned int max_msg_size = 0;
710 bool disable_credit_flow_ctrl = false;
711 u16 message_id, service_id, flags = 0;
714 /* special case for HTC pseudo control service */
715 if (conn_req->service_id == ATH10K_HTC_SVC_ID_RSVD_CTRL) {
716 disable_credit_flow_ctrl = true;
717 assigned_eid = ATH10K_HTC_EP_0;
718 max_msg_size = ATH10K_HTC_MAX_CTRL_MSG_LEN;
719 memset(&resp_msg_dummy, 0, sizeof(resp_msg_dummy));
723 tx_alloc = ath10k_htc_get_credit_allocation(htc,
724 conn_req->service_id);
726 ath10k_dbg(ATH10K_DBG_BOOT,
727 "boot htc service %s does not allocate target credits\n",
728 htc_service_name(conn_req->service_id));
730 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar);
732 ath10k_err("Failed to allocate HTC packet\n");
736 length = sizeof(msg->hdr) + sizeof(msg->connect_service);
737 skb_put(skb, length);
738 memset(skb->data, 0, length);
740 msg = (struct ath10k_htc_msg *)skb->data;
741 msg->hdr.message_id =
742 __cpu_to_le16(ATH10K_HTC_MSG_CONNECT_SERVICE_ID);
744 flags |= SM(tx_alloc, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC);
746 /* Only enable credit flow control for WMI ctrl service */
747 if (conn_req->service_id != ATH10K_HTC_SVC_ID_WMI_CONTROL) {
748 flags |= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
749 disable_credit_flow_ctrl = true;
752 req_msg = &msg->connect_service;
753 req_msg->flags = __cpu_to_le16(flags);
754 req_msg->service_id = __cpu_to_le16(conn_req->service_id);
756 INIT_COMPLETION(htc->ctl_resp);
758 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb);
764 /* wait for response */
765 status = wait_for_completion_timeout(&htc->ctl_resp,
766 ATH10K_HTC_CONN_SVC_TIMEOUT_HZ);
770 ath10k_err("Service connect timeout: %d\n", status);
774 /* we controlled the buffer creation, it's aligned */
775 msg = (struct ath10k_htc_msg *)htc->control_resp_buffer;
776 resp_msg = &msg->connect_service_response;
777 message_id = __le16_to_cpu(msg->hdr.message_id);
778 service_id = __le16_to_cpu(resp_msg->service_id);
780 if ((message_id != ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID) ||
781 (htc->control_resp_len < sizeof(msg->hdr) +
782 sizeof(msg->connect_service_response))) {
783 ath10k_err("Invalid resp message ID 0x%x", message_id);
787 ath10k_dbg(ATH10K_DBG_HTC,
788 "HTC Service %s connect response: status: 0x%x, assigned ep: 0x%x\n",
789 htc_service_name(service_id),
790 resp_msg->status, resp_msg->eid);
792 conn_resp->connect_resp_code = resp_msg->status;
794 /* check response status */
795 if (resp_msg->status != ATH10K_HTC_CONN_SVC_STATUS_SUCCESS) {
796 ath10k_err("HTC Service %s connect request failed: 0x%x)\n",
797 htc_service_name(service_id),
802 assigned_eid = (enum ath10k_htc_ep_id)resp_msg->eid;
803 max_msg_size = __le16_to_cpu(resp_msg->max_msg_size);
807 if (assigned_eid >= ATH10K_HTC_EP_COUNT)
810 if (max_msg_size == 0)
813 ep = &htc->endpoint[assigned_eid];
814 ep->eid = assigned_eid;
816 if (ep->service_id != ATH10K_HTC_SVC_ID_UNUSED)
819 /* return assigned endpoint to caller */
820 conn_resp->eid = assigned_eid;
821 conn_resp->max_msg_len = __le16_to_cpu(resp_msg->max_msg_size);
823 /* setup the endpoint */
824 ep->service_id = conn_req->service_id;
825 ep->max_tx_queue_depth = conn_req->max_send_queue_depth;
826 ep->max_ep_message_len = __le16_to_cpu(resp_msg->max_msg_size);
827 ep->tx_credits = tx_alloc;
828 ep->tx_credit_size = htc->target_credit_size;
829 ep->tx_credits_per_max_message = ep->max_ep_message_len /
830 htc->target_credit_size;
832 if (ep->max_ep_message_len % htc->target_credit_size)
833 ep->tx_credits_per_max_message++;
835 /* copy all the callbacks */
836 ep->ep_ops = conn_req->ep_ops;
838 status = ath10k_hif_map_service_to_pipe(htc->ar,
847 ath10k_dbg(ATH10K_DBG_BOOT,
848 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
849 htc_service_name(ep->service_id), ep->ul_pipe_id,
850 ep->dl_pipe_id, ep->eid);
852 ath10k_dbg(ATH10K_DBG_BOOT,
853 "boot htc ep %d ul polled %d dl polled %d\n",
854 ep->eid, ep->ul_is_polled, ep->dl_is_polled);
856 if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) {
857 ep->tx_credit_flow_enabled = false;
858 ath10k_dbg(ATH10K_DBG_BOOT,
859 "boot htc service '%s' eid %d TX flow control disabled\n",
860 htc_service_name(ep->service_id), assigned_eid);
866 struct sk_buff *ath10k_htc_alloc_skb(int size)
870 skb = dev_alloc_skb(size + sizeof(struct ath10k_htc_hdr));
872 ath10k_warn("could not allocate HTC tx skb\n");
876 skb_reserve(skb, sizeof(struct ath10k_htc_hdr));
878 /* FW/HTC requires 4-byte aligned streams */
879 if (!IS_ALIGNED((unsigned long)skb->data, 4))
880 ath10k_warn("Unaligned HTC tx skb\n");
885 int ath10k_htc_start(struct ath10k_htc *htc)
889 struct ath10k_htc_msg *msg;
891 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar);
895 skb_put(skb, sizeof(msg->hdr) + sizeof(msg->setup_complete_ext));
896 memset(skb->data, 0, skb->len);
898 msg = (struct ath10k_htc_msg *)skb->data;
899 msg->hdr.message_id =
900 __cpu_to_le16(ATH10K_HTC_MSG_SETUP_COMPLETE_EX_ID);
902 ath10k_dbg(ATH10K_DBG_HTC, "HTC is using TX credit flow control\n");
904 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb);
914 * stop HTC communications, i.e. stop interrupt reception, and flush all
917 void ath10k_htc_stop(struct ath10k_htc *htc)
920 struct ath10k_htc_ep *ep;
922 spin_lock_bh(&htc->tx_lock);
924 spin_unlock_bh(&htc->tx_lock);
926 for (i = ATH10K_HTC_EP_0; i < ATH10K_HTC_EP_COUNT; i++) {
927 ep = &htc->endpoint[i];
928 ath10k_htc_flush_endpoint_tx(htc, ep);
931 ath10k_hif_stop(htc->ar);
934 /* registered target arrival callback from the HIF layer */
935 int ath10k_htc_init(struct ath10k *ar)
937 struct ath10k_hif_cb htc_callbacks;
938 struct ath10k_htc_ep *ep = NULL;
939 struct ath10k_htc *htc = &ar->htc;
941 spin_lock_init(&htc->tx_lock);
943 htc->stopped = false;
944 ath10k_htc_reset_endpoint_states(htc);
946 /* setup HIF layer callbacks */
947 htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
948 htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
951 /* Get HIF default pipe for HTC message exchange */
952 ep = &htc->endpoint[ATH10K_HTC_EP_0];
954 ath10k_hif_set_callbacks(ar, &htc_callbacks);
955 ath10k_hif_get_default_pipe(ar, &ep->ul_pipe_id, &ep->dl_pipe_id);
957 init_completion(&htc->ctl_resp);