1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
5 #include <linux/skbuff.h>
6 #include <linux/ctype.h>
11 struct sk_buff *ath11k_htc_alloc_skb(struct ath11k_base *ab, int size)
15 skb = dev_alloc_skb(size + sizeof(struct ath11k_htc_hdr));
19 skb_reserve(skb, sizeof(struct ath11k_htc_hdr));
21 /* FW/HTC requires 4-byte aligned streams */
22 if (!IS_ALIGNED((unsigned long)skb->data, 4))
23 ath11k_warn(ab, "Unaligned HTC tx skb\n");
28 static void ath11k_htc_control_tx_complete(struct ath11k_base *ab,
34 static struct sk_buff *ath11k_htc_build_tx_ctrl_skb(void *ab)
37 struct ath11k_skb_cb *skb_cb;
39 skb = dev_alloc_skb(ATH11K_HTC_CONTROL_BUFFER_SIZE);
43 skb_reserve(skb, sizeof(struct ath11k_htc_hdr));
44 WARN_ON_ONCE(!IS_ALIGNED((unsigned long)skb->data, 4));
46 skb_cb = ATH11K_SKB_CB(skb);
47 memset(skb_cb, 0, sizeof(*skb_cb));
49 ath11k_dbg(ab, ATH11K_DBG_HTC, "%s: skb %pK\n", __func__, skb);
53 static void ath11k_htc_prepare_tx_skb(struct ath11k_htc_ep *ep,
56 struct ath11k_htc_hdr *hdr;
58 hdr = (struct ath11k_htc_hdr *)skb->data;
60 memset(hdr, 0, sizeof(*hdr));
61 hdr->htc_info = FIELD_PREP(HTC_HDR_ENDPOINTID, ep->eid) |
62 FIELD_PREP(HTC_HDR_PAYLOADLEN,
63 (skb->len - sizeof(*hdr)));
65 if (ep->tx_credit_flow_enabled)
66 hdr->htc_info |= FIELD_PREP(HTC_HDR_FLAGS,
67 ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE);
69 spin_lock_bh(&ep->htc->tx_lock);
70 hdr->ctrl_info = FIELD_PREP(HTC_HDR_CONTROLBYTES1, ep->seq_no++);
71 spin_unlock_bh(&ep->htc->tx_lock);
74 int ath11k_htc_send(struct ath11k_htc *htc,
75 enum ath11k_htc_ep_id eid,
78 struct ath11k_htc_ep *ep = &htc->endpoint[eid];
79 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
80 struct device *dev = htc->ab->dev;
81 struct ath11k_base *ab = htc->ab;
84 bool credit_flow_enabled = (ab->hw_params.credit_flow &&
85 ep->tx_credit_flow_enabled);
87 if (eid >= ATH11K_HTC_EP_COUNT) {
88 ath11k_warn(ab, "Invalid endpoint id: %d\n", eid);
92 skb_push(skb, sizeof(struct ath11k_htc_hdr));
94 if (credit_flow_enabled) {
95 credits = DIV_ROUND_UP(skb->len, htc->target_credit_size);
96 spin_lock_bh(&htc->tx_lock);
97 if (ep->tx_credits < credits) {
98 ath11k_dbg(ab, ATH11K_DBG_HTC,
99 "htc insufficient credits ep %d required %d available %d\n",
100 eid, credits, ep->tx_credits);
101 spin_unlock_bh(&htc->tx_lock);
105 ep->tx_credits -= credits;
106 ath11k_dbg(ab, ATH11K_DBG_HTC,
107 "htc ep %d consumed %d credits (total %d)\n",
108 eid, credits, ep->tx_credits);
109 spin_unlock_bh(&htc->tx_lock);
112 ath11k_htc_prepare_tx_skb(ep, skb);
115 skb_cb->paddr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
116 ret = dma_mapping_error(dev, skb_cb->paddr);
122 ret = ath11k_ce_send(htc->ab, skb, ep->ul_pipe_id, ep->eid);
129 dma_unmap_single(dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE);
131 if (credit_flow_enabled) {
132 spin_lock_bh(&htc->tx_lock);
133 ep->tx_credits += credits;
134 ath11k_dbg(ab, ATH11K_DBG_HTC,
135 "htc ep %d reverted %d credits back (total %d)\n",
136 eid, credits, ep->tx_credits);
137 spin_unlock_bh(&htc->tx_lock);
139 if (ep->ep_ops.ep_tx_credits)
140 ep->ep_ops.ep_tx_credits(htc->ab);
143 skb_pull(skb, sizeof(struct ath11k_htc_hdr));
148 ath11k_htc_process_credit_report(struct ath11k_htc *htc,
149 const struct ath11k_htc_credit_report *report,
151 enum ath11k_htc_ep_id eid)
153 struct ath11k_base *ab = htc->ab;
154 struct ath11k_htc_ep *ep;
157 if (len % sizeof(*report))
158 ath11k_warn(ab, "Uneven credit report len %d", len);
160 n_reports = len / sizeof(*report);
162 spin_lock_bh(&htc->tx_lock);
163 for (i = 0; i < n_reports; i++, report++) {
164 if (report->eid >= ATH11K_HTC_EP_COUNT)
167 ep = &htc->endpoint[report->eid];
168 ep->tx_credits += report->credits;
170 ath11k_dbg(ab, ATH11K_DBG_HTC, "htc ep %d got %d credits (total %d)\n",
171 report->eid, report->credits, ep->tx_credits);
173 if (ep->ep_ops.ep_tx_credits) {
174 spin_unlock_bh(&htc->tx_lock);
175 ep->ep_ops.ep_tx_credits(htc->ab);
176 spin_lock_bh(&htc->tx_lock);
179 spin_unlock_bh(&htc->tx_lock);
182 static int ath11k_htc_process_trailer(struct ath11k_htc *htc,
185 enum ath11k_htc_ep_id src_eid)
187 struct ath11k_base *ab = htc->ab;
189 struct ath11k_htc_record *record;
193 record = (struct ath11k_htc_record *)buffer;
195 if (length < sizeof(record->hdr)) {
200 if (record->hdr.len > length) {
201 /* no room left in buffer for record */
202 ath11k_warn(ab, "Invalid record length: %d\n",
208 if (ab->hw_params.credit_flow) {
209 switch (record->hdr.id) {
210 case ATH11K_HTC_RECORD_CREDITS:
211 len = sizeof(struct ath11k_htc_credit_report);
212 if (record->hdr.len < len) {
213 ath11k_warn(ab, "Credit report too long\n");
217 ath11k_htc_process_credit_report(htc,
218 record->credit_report,
223 ath11k_warn(ab, "Unhandled record: id:%d length:%d\n",
224 record->hdr.id, record->hdr.len);
232 /* multiple records may be present in a trailer */
233 buffer += sizeof(record->hdr) + record->hdr.len;
234 length -= sizeof(record->hdr) + record->hdr.len;
240 static void ath11k_htc_suspend_complete(struct ath11k_base *ab, bool ack)
242 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot suspend complete %d\n", ack);
245 set_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags);
247 clear_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags);
249 complete(&ab->htc_suspend);
252 void ath11k_htc_tx_completion_handler(struct ath11k_base *ab,
255 struct ath11k_htc *htc = &ab->htc;
256 struct ath11k_htc_ep *ep;
257 void (*ep_tx_complete)(struct ath11k_base *, struct sk_buff *);
260 eid = ATH11K_SKB_CB(skb)->eid;
261 if (eid >= ATH11K_HTC_EP_COUNT)
264 ep = &htc->endpoint[eid];
265 spin_lock_bh(&htc->tx_lock);
266 ep_tx_complete = ep->ep_ops.ep_tx_complete;
267 spin_unlock_bh(&htc->tx_lock);
268 if (!ep_tx_complete) {
269 dev_kfree_skb_any(skb);
272 ep_tx_complete(htc->ab, skb);
275 static void ath11k_htc_wakeup_from_suspend(struct ath11k_base *ab)
277 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot wakeup from suspend is received\n");
280 void ath11k_htc_rx_completion_handler(struct ath11k_base *ab,
284 struct ath11k_htc *htc = &ab->htc;
285 struct ath11k_htc_hdr *hdr;
286 struct ath11k_htc_ep *ep;
291 bool trailer_present;
293 hdr = (struct ath11k_htc_hdr *)skb->data;
294 skb_pull(skb, sizeof(*hdr));
296 eid = FIELD_GET(HTC_HDR_ENDPOINTID, hdr->htc_info);
298 if (eid >= ATH11K_HTC_EP_COUNT) {
299 ath11k_warn(ab, "HTC Rx: invalid eid %d\n", eid);
303 ep = &htc->endpoint[eid];
305 payload_len = FIELD_GET(HTC_HDR_PAYLOADLEN, hdr->htc_info);
307 if (payload_len + sizeof(*hdr) > ATH11K_HTC_MAX_LEN) {
308 ath11k_warn(ab, "HTC rx frame too long, len: %zu\n",
309 payload_len + sizeof(*hdr));
313 if (skb->len < payload_len) {
314 ath11k_warn(ab, "HTC Rx: insufficient length, got %d, expected %d\n",
315 skb->len, payload_len);
319 /* get flags to check for trailer */
320 trailer_present = (FIELD_GET(HTC_HDR_FLAGS, hdr->htc_info)) &
321 ATH11K_HTC_FLAG_TRAILER_PRESENT;
323 if (trailer_present) {
326 trailer_len = FIELD_GET(HTC_HDR_CONTROLBYTES0, hdr->ctrl_info);
327 min_len = sizeof(struct ath11k_htc_record_hdr);
329 if ((trailer_len < min_len) ||
330 (trailer_len > payload_len)) {
331 ath11k_warn(ab, "Invalid trailer length: %d\n",
337 trailer += sizeof(*hdr);
338 trailer += payload_len;
339 trailer -= trailer_len;
340 status = ath11k_htc_process_trailer(htc, trailer,
345 skb_trim(skb, skb->len - trailer_len);
348 if (trailer_len >= payload_len)
349 /* zero length packet with trailer data, just drop these */
352 if (eid == ATH11K_HTC_EP_0) {
353 struct ath11k_htc_msg *msg = (struct ath11k_htc_msg *)skb->data;
355 switch (FIELD_GET(HTC_MSG_MESSAGEID, msg->msg_svc_id)) {
356 case ATH11K_HTC_MSG_READY_ID:
357 case ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID:
358 /* handle HTC control message */
359 if (completion_done(&htc->ctl_resp)) {
360 /* this is a fatal error, target should not be
361 * sending unsolicited messages on the ep 0
363 ath11k_warn(ab, "HTC rx ctrl still processing\n");
364 complete(&htc->ctl_resp);
368 htc->control_resp_len =
370 ATH11K_HTC_MAX_CTRL_MSG_LEN);
372 memcpy(htc->control_resp_buffer, skb->data,
373 htc->control_resp_len);
375 complete(&htc->ctl_resp);
377 case ATH11K_HTC_MSG_SEND_SUSPEND_COMPLETE:
378 ath11k_htc_suspend_complete(ab, true);
380 case ATH11K_HTC_MSG_NACK_SUSPEND:
381 ath11k_htc_suspend_complete(ab, false);
383 case ATH11K_HTC_MSG_WAKEUP_FROM_SUSPEND_ID:
384 ath11k_htc_wakeup_from_suspend(ab);
387 ath11k_warn(ab, "ignoring unsolicited htc ep0 event %ld\n",
388 FIELD_GET(HTC_MSG_MESSAGEID, msg->msg_svc_id));
394 ath11k_dbg(ab, ATH11K_DBG_HTC, "htc rx completion ep %d skb %pK\n",
396 ep->ep_ops.ep_rx_complete(ab, skb);
398 /* poll tx completion for interrupt disabled CE's */
399 ath11k_ce_poll_send_completed(ab, ep->ul_pipe_id);
401 /* skb is now owned by the rx completion handler */
407 static void ath11k_htc_control_rx_complete(struct ath11k_base *ab,
410 /* This is unexpected. FW is not supposed to send regular rx on this
413 ath11k_warn(ab, "unexpected htc rx\n");
417 static const char *htc_service_name(enum ath11k_htc_svc_id id)
420 case ATH11K_HTC_SVC_ID_RESERVED:
422 case ATH11K_HTC_SVC_ID_RSVD_CTRL:
424 case ATH11K_HTC_SVC_ID_WMI_CONTROL:
426 case ATH11K_HTC_SVC_ID_WMI_DATA_BE:
428 case ATH11K_HTC_SVC_ID_WMI_DATA_BK:
430 case ATH11K_HTC_SVC_ID_WMI_DATA_VI:
432 case ATH11K_HTC_SVC_ID_WMI_DATA_VO:
434 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1:
436 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2:
438 case ATH11K_HTC_SVC_ID_NMI_CONTROL:
439 return "NMI Control";
440 case ATH11K_HTC_SVC_ID_NMI_DATA:
442 case ATH11K_HTC_SVC_ID_HTT_DATA_MSG:
444 case ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS:
446 case ATH11K_HTC_SVC_ID_IPA_TX:
448 case ATH11K_HTC_SVC_ID_PKT_LOG:
455 static void ath11k_htc_reset_endpoint_states(struct ath11k_htc *htc)
457 struct ath11k_htc_ep *ep;
460 for (i = ATH11K_HTC_EP_0; i < ATH11K_HTC_EP_COUNT; i++) {
461 ep = &htc->endpoint[i];
462 ep->service_id = ATH11K_HTC_SVC_ID_UNUSED;
463 ep->max_ep_message_len = 0;
464 ep->max_tx_queue_depth = 0;
467 ep->tx_credit_flow_enabled = true;
471 static u8 ath11k_htc_get_credit_allocation(struct ath11k_htc *htc,
474 u8 i, allocation = 0;
476 for (i = 0; i < ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
477 if (htc->service_alloc_table[i].service_id == service_id) {
479 htc->service_alloc_table[i].credit_allocation;
486 static int ath11k_htc_setup_target_buffer_assignments(struct ath11k_htc *htc)
488 struct ath11k_htc_svc_tx_credits *serv_entry;
490 ATH11K_HTC_SVC_ID_WMI_CONTROL,
491 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
492 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2,
496 credits = htc->total_transmit_credits;
497 serv_entry = htc->service_alloc_table;
499 if ((htc->wmi_ep_count == 0) ||
500 (htc->wmi_ep_count > ARRAY_SIZE(svc_id)))
503 /* Divide credits among number of endpoints for WMI */
504 credits = credits / htc->wmi_ep_count;
505 for (i = 0; i < htc->wmi_ep_count; i++) {
506 serv_entry[i].service_id = svc_id[i];
507 serv_entry[i].credit_allocation = credits;
513 int ath11k_htc_wait_target(struct ath11k_htc *htc)
516 struct ath11k_base *ab = htc->ab;
517 unsigned long time_left;
518 struct ath11k_htc_ready *ready;
523 time_left = wait_for_completion_timeout(&htc->ctl_resp,
524 ATH11K_HTC_WAIT_TIMEOUT_HZ);
526 ath11k_warn(ab, "failed to receive control response completion, polling..\n");
528 for (i = 0; i < ab->hw_params.ce_count; i++)
529 ath11k_ce_per_engine_service(htc->ab, i);
532 wait_for_completion_timeout(&htc->ctl_resp,
533 ATH11K_HTC_WAIT_TIMEOUT_HZ);
540 ath11k_warn(ab, "ctl_resp never came in (%d)\n", status);
544 if (htc->control_resp_len < sizeof(*ready)) {
545 ath11k_warn(ab, "Invalid HTC ready msg len:%d\n",
546 htc->control_resp_len);
550 ready = (struct ath11k_htc_ready *)htc->control_resp_buffer;
551 message_id = FIELD_GET(HTC_MSG_MESSAGEID, ready->id_credit_count);
552 credit_count = FIELD_GET(HTC_READY_MSG_CREDITCOUNT,
553 ready->id_credit_count);
554 credit_size = FIELD_GET(HTC_READY_MSG_CREDITSIZE, ready->size_ep);
556 if (message_id != ATH11K_HTC_MSG_READY_ID) {
557 ath11k_warn(ab, "Invalid HTC ready msg: 0x%x\n", message_id);
561 htc->total_transmit_credits = credit_count;
562 htc->target_credit_size = credit_size;
564 ath11k_dbg(ab, ATH11K_DBG_HTC,
565 "Target ready! transmit resources: %d size:%d\n",
566 htc->total_transmit_credits, htc->target_credit_size);
568 if ((htc->total_transmit_credits == 0) ||
569 (htc->target_credit_size == 0)) {
570 ath11k_warn(ab, "Invalid credit size received\n");
574 /* For QCA6390, wmi endpoint uses 1 credit to avoid
575 * back-to-back write.
577 if (ab->hw_params.supports_shadow_regs)
578 htc->total_transmit_credits = 1;
580 ath11k_htc_setup_target_buffer_assignments(htc);
585 int ath11k_htc_connect_service(struct ath11k_htc *htc,
586 struct ath11k_htc_svc_conn_req *conn_req,
587 struct ath11k_htc_svc_conn_resp *conn_resp)
589 struct ath11k_base *ab = htc->ab;
590 struct ath11k_htc_conn_svc *req_msg;
591 struct ath11k_htc_conn_svc_resp resp_msg_dummy;
592 struct ath11k_htc_conn_svc_resp *resp_msg = &resp_msg_dummy;
593 enum ath11k_htc_ep_id assigned_eid = ATH11K_HTC_EP_COUNT;
594 struct ath11k_htc_ep *ep;
596 unsigned int max_msg_size = 0;
598 unsigned long time_left;
599 bool disable_credit_flow_ctrl = false;
600 u16 message_id, service_id, flags = 0;
603 /* special case for HTC pseudo control service */
604 if (conn_req->service_id == ATH11K_HTC_SVC_ID_RSVD_CTRL) {
605 disable_credit_flow_ctrl = true;
606 assigned_eid = ATH11K_HTC_EP_0;
607 max_msg_size = ATH11K_HTC_MAX_CTRL_MSG_LEN;
608 memset(&resp_msg_dummy, 0, sizeof(resp_msg_dummy));
612 tx_alloc = ath11k_htc_get_credit_allocation(htc,
613 conn_req->service_id);
615 ath11k_dbg(ab, ATH11K_DBG_BOOT,
616 "boot htc service %s does not allocate target credits\n",
617 htc_service_name(conn_req->service_id));
619 skb = ath11k_htc_build_tx_ctrl_skb(htc->ab);
621 ath11k_warn(ab, "Failed to allocate HTC packet\n");
625 length = sizeof(*req_msg);
626 skb_put(skb, length);
627 memset(skb->data, 0, length);
629 req_msg = (struct ath11k_htc_conn_svc *)skb->data;
630 req_msg->msg_svc_id = FIELD_PREP(HTC_MSG_MESSAGEID,
631 ATH11K_HTC_MSG_CONNECT_SERVICE_ID);
633 flags |= FIELD_PREP(ATH11K_HTC_CONN_FLAGS_RECV_ALLOC, tx_alloc);
635 /* Only enable credit flow control for WMI ctrl service */
636 if (!(conn_req->service_id == ATH11K_HTC_SVC_ID_WMI_CONTROL ||
637 conn_req->service_id == ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 ||
638 conn_req->service_id == ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2)) {
639 flags |= ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
640 disable_credit_flow_ctrl = true;
643 if (!ab->hw_params.credit_flow) {
644 flags |= ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
645 disable_credit_flow_ctrl = true;
648 req_msg->flags_len = FIELD_PREP(HTC_SVC_MSG_CONNECTIONFLAGS, flags);
649 req_msg->msg_svc_id |= FIELD_PREP(HTC_SVC_MSG_SERVICE_ID,
650 conn_req->service_id);
652 reinit_completion(&htc->ctl_resp);
654 status = ath11k_htc_send(htc, ATH11K_HTC_EP_0, skb);
660 /* wait for response */
661 time_left = wait_for_completion_timeout(&htc->ctl_resp,
662 ATH11K_HTC_CONN_SVC_TIMEOUT_HZ);
664 ath11k_err(ab, "Service connect timeout\n");
668 /* we controlled the buffer creation, it's aligned */
669 resp_msg = (struct ath11k_htc_conn_svc_resp *)htc->control_resp_buffer;
670 message_id = FIELD_GET(HTC_MSG_MESSAGEID, resp_msg->msg_svc_id);
671 service_id = FIELD_GET(HTC_SVC_RESP_MSG_SERVICEID,
672 resp_msg->msg_svc_id);
674 if ((message_id != ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID) ||
675 (htc->control_resp_len < sizeof(*resp_msg))) {
676 ath11k_err(ab, "Invalid resp message ID 0x%x", message_id);
680 ath11k_dbg(ab, ATH11K_DBG_HTC,
681 "HTC Service %s connect response: status: 0x%lx, assigned ep: 0x%lx\n",
682 htc_service_name(service_id),
683 FIELD_GET(HTC_SVC_RESP_MSG_STATUS, resp_msg->flags_len),
684 FIELD_GET(HTC_SVC_RESP_MSG_ENDPOINTID, resp_msg->flags_len));
686 conn_resp->connect_resp_code = FIELD_GET(HTC_SVC_RESP_MSG_STATUS,
687 resp_msg->flags_len);
689 /* check response status */
690 if (conn_resp->connect_resp_code != ATH11K_HTC_CONN_SVC_STATUS_SUCCESS) {
691 ath11k_err(ab, "HTC Service %s connect request failed: 0x%x)\n",
692 htc_service_name(service_id),
693 conn_resp->connect_resp_code);
697 assigned_eid = (enum ath11k_htc_ep_id)FIELD_GET(
698 HTC_SVC_RESP_MSG_ENDPOINTID,
699 resp_msg->flags_len);
701 max_msg_size = FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE,
702 resp_msg->flags_len);
706 if (assigned_eid >= ATH11K_HTC_EP_COUNT)
709 if (max_msg_size == 0)
712 ep = &htc->endpoint[assigned_eid];
713 ep->eid = assigned_eid;
715 if (ep->service_id != ATH11K_HTC_SVC_ID_UNUSED)
718 /* return assigned endpoint to caller */
719 conn_resp->eid = assigned_eid;
720 conn_resp->max_msg_len = FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE,
721 resp_msg->flags_len);
723 /* setup the endpoint */
724 ep->service_id = conn_req->service_id;
725 ep->max_tx_queue_depth = conn_req->max_send_queue_depth;
726 ep->max_ep_message_len = FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE,
727 resp_msg->flags_len);
728 ep->tx_credits = tx_alloc;
730 /* copy all the callbacks */
731 ep->ep_ops = conn_req->ep_ops;
733 status = ath11k_hif_map_service_to_pipe(htc->ab,
740 ath11k_dbg(ab, ATH11K_DBG_BOOT,
741 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
742 htc_service_name(ep->service_id), ep->ul_pipe_id,
743 ep->dl_pipe_id, ep->eid);
745 if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) {
746 ep->tx_credit_flow_enabled = false;
747 ath11k_dbg(ab, ATH11K_DBG_BOOT,
748 "boot htc service '%s' eid %d TX flow control disabled\n",
749 htc_service_name(ep->service_id), assigned_eid);
755 int ath11k_htc_start(struct ath11k_htc *htc)
759 struct ath11k_base *ab = htc->ab;
760 struct ath11k_htc_setup_complete_extended *msg;
762 skb = ath11k_htc_build_tx_ctrl_skb(htc->ab);
766 skb_put(skb, sizeof(*msg));
767 memset(skb->data, 0, skb->len);
769 msg = (struct ath11k_htc_setup_complete_extended *)skb->data;
770 msg->msg_id = FIELD_PREP(HTC_MSG_MESSAGEID,
771 ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID);
773 if (ab->hw_params.credit_flow)
774 ath11k_dbg(ab, ATH11K_DBG_HTC, "HTC is using TX credit flow control\n");
776 msg->flags |= ATH11K_GLOBAL_DISABLE_CREDIT_FLOW;
778 status = ath11k_htc_send(htc, ATH11K_HTC_EP_0, skb);
787 int ath11k_htc_init(struct ath11k_base *ab)
789 struct ath11k_htc *htc = &ab->htc;
790 struct ath11k_htc_svc_conn_req conn_req;
791 struct ath11k_htc_svc_conn_resp conn_resp;
794 spin_lock_init(&htc->tx_lock);
796 ath11k_htc_reset_endpoint_states(htc);
800 switch (ab->wmi_ab.preferred_hw_mode) {
801 case WMI_HOST_HW_MODE_SINGLE:
802 htc->wmi_ep_count = 1;
804 case WMI_HOST_HW_MODE_DBS:
805 case WMI_HOST_HW_MODE_DBS_OR_SBS:
806 htc->wmi_ep_count = 2;
808 case WMI_HOST_HW_MODE_DBS_SBS:
809 htc->wmi_ep_count = 3;
812 htc->wmi_ep_count = ab->hw_params.max_radios;
816 /* setup our pseudo HTC control endpoint connection */
817 memset(&conn_req, 0, sizeof(conn_req));
818 memset(&conn_resp, 0, sizeof(conn_resp));
819 conn_req.ep_ops.ep_tx_complete = ath11k_htc_control_tx_complete;
820 conn_req.ep_ops.ep_rx_complete = ath11k_htc_control_rx_complete;
821 conn_req.max_send_queue_depth = ATH11K_NUM_CONTROL_TX_BUFFERS;
822 conn_req.service_id = ATH11K_HTC_SVC_ID_RSVD_CTRL;
824 /* connect fake service */
825 ret = ath11k_htc_connect_service(htc, &conn_req, &conn_resp);
827 ath11k_err(ab, "could not connect to htc service (%d)\n", ret);
831 init_completion(&htc->ctl_resp);