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 inline void ath11k_htc_restore_tx_skb(struct ath11k_htc
*htc
,
56 struct ath11k_skb_cb
*skb_cb
= ATH11K_SKB_CB(skb
);
58 dma_unmap_single(htc
->ab
->dev
, skb_cb
->paddr
, skb
->len
, DMA_TO_DEVICE
);
59 skb_pull(skb
, sizeof(struct ath11k_htc_hdr
));
62 static void ath11k_htc_prepare_tx_skb(struct ath11k_htc_ep
*ep
,
65 struct ath11k_htc_hdr
*hdr
;
67 hdr
= (struct ath11k_htc_hdr
*)skb
->data
;
69 memset(hdr
, 0, sizeof(*hdr
));
70 hdr
->htc_info
= FIELD_PREP(HTC_HDR_ENDPOINTID
, ep
->eid
) |
71 FIELD_PREP(HTC_HDR_PAYLOADLEN
,
72 (skb
->len
- sizeof(*hdr
))) |
73 FIELD_PREP(HTC_HDR_FLAGS
,
74 ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE
);
76 spin_lock_bh(&ep
->htc
->tx_lock
);
77 hdr
->ctrl_info
= FIELD_PREP(HTC_HDR_CONTROLBYTES1
, ep
->seq_no
++);
78 spin_unlock_bh(&ep
->htc
->tx_lock
);
81 int ath11k_htc_send(struct ath11k_htc
*htc
,
82 enum ath11k_htc_ep_id eid
,
85 struct ath11k_htc_ep
*ep
= &htc
->endpoint
[eid
];
86 struct ath11k_skb_cb
*skb_cb
= ATH11K_SKB_CB(skb
);
87 struct device
*dev
= htc
->ab
->dev
;
88 struct ath11k_base
*ab
= htc
->ab
;
92 if (eid
>= ATH11K_HTC_EP_COUNT
) {
93 ath11k_warn(ab
, "Invalid endpoint id: %d\n", eid
);
97 skb_push(skb
, sizeof(struct ath11k_htc_hdr
));
99 if (ep
->tx_credit_flow_enabled
) {
100 credits
= DIV_ROUND_UP(skb
->len
, htc
->target_credit_size
);
101 spin_lock_bh(&htc
->tx_lock
);
102 if (ep
->tx_credits
< credits
) {
103 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
104 "htc insufficient credits ep %d required %d available %d\n",
105 eid
, credits
, ep
->tx_credits
);
106 spin_unlock_bh(&htc
->tx_lock
);
110 ep
->tx_credits
-= credits
;
111 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
112 "htc ep %d consumed %d credits (total %d)\n",
113 eid
, credits
, ep
->tx_credits
);
114 spin_unlock_bh(&htc
->tx_lock
);
117 ath11k_htc_prepare_tx_skb(ep
, skb
);
120 skb_cb
->paddr
= dma_map_single(dev
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
121 ret
= dma_mapping_error(dev
, skb_cb
->paddr
);
127 ret
= ath11k_ce_send(htc
->ab
, skb
, ep
->ul_pipe_id
, ep
->eid
);
134 dma_unmap_single(dev
, skb_cb
->paddr
, skb
->len
, DMA_TO_DEVICE
);
136 if (ep
->tx_credit_flow_enabled
) {
137 spin_lock_bh(&htc
->tx_lock
);
138 ep
->tx_credits
+= credits
;
139 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
140 "htc ep %d reverted %d credits back (total %d)\n",
141 eid
, credits
, ep
->tx_credits
);
142 spin_unlock_bh(&htc
->tx_lock
);
144 if (ep
->ep_ops
.ep_tx_credits
)
145 ep
->ep_ops
.ep_tx_credits(htc
->ab
);
148 skb_pull(skb
, sizeof(struct ath11k_htc_hdr
));
153 ath11k_htc_process_credit_report(struct ath11k_htc
*htc
,
154 const struct ath11k_htc_credit_report
*report
,
156 enum ath11k_htc_ep_id eid
)
158 struct ath11k_base
*ab
= htc
->ab
;
159 struct ath11k_htc_ep
*ep
;
162 if (len
% sizeof(*report
))
163 ath11k_warn(ab
, "Uneven credit report len %d", len
);
165 n_reports
= len
/ sizeof(*report
);
167 spin_lock_bh(&htc
->tx_lock
);
168 for (i
= 0; i
< n_reports
; i
++, report
++) {
169 if (report
->eid
>= ATH11K_HTC_EP_COUNT
)
172 ep
= &htc
->endpoint
[report
->eid
];
173 ep
->tx_credits
+= report
->credits
;
175 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "htc ep %d got %d credits (total %d)\n",
176 report
->eid
, report
->credits
, ep
->tx_credits
);
178 if (ep
->ep_ops
.ep_tx_credits
) {
179 spin_unlock_bh(&htc
->tx_lock
);
180 ep
->ep_ops
.ep_tx_credits(htc
->ab
);
181 spin_lock_bh(&htc
->tx_lock
);
184 spin_unlock_bh(&htc
->tx_lock
);
187 static int ath11k_htc_process_trailer(struct ath11k_htc
*htc
,
190 enum ath11k_htc_ep_id src_eid
)
192 struct ath11k_base
*ab
= htc
->ab
;
194 struct ath11k_htc_record
*record
;
198 record
= (struct ath11k_htc_record
*)buffer
;
200 if (length
< sizeof(record
->hdr
)) {
205 if (record
->hdr
.len
> length
) {
206 /* no room left in buffer for record */
207 ath11k_warn(ab
, "Invalid record length: %d\n",
213 switch (record
->hdr
.id
) {
214 case ATH11K_HTC_RECORD_CREDITS
:
215 len
= sizeof(struct ath11k_htc_credit_report
);
216 if (record
->hdr
.len
< len
) {
217 ath11k_warn(ab
, "Credit report too long\n");
221 ath11k_htc_process_credit_report(htc
,
222 record
->credit_report
,
227 ath11k_warn(ab
, "Unhandled record: id:%d length:%d\n",
228 record
->hdr
.id
, record
->hdr
.len
);
235 /* multiple records may be present in a trailer */
236 buffer
+= sizeof(record
->hdr
) + record
->hdr
.len
;
237 length
-= sizeof(record
->hdr
) + record
->hdr
.len
;
243 void ath11k_htc_rx_completion_handler(struct ath11k_base
*ab
,
247 struct ath11k_htc
*htc
= &ab
->htc
;
248 struct ath11k_htc_hdr
*hdr
;
249 struct ath11k_htc_ep
*ep
;
254 bool trailer_present
;
256 hdr
= (struct ath11k_htc_hdr
*)skb
->data
;
257 skb_pull(skb
, sizeof(*hdr
));
259 eid
= FIELD_GET(HTC_HDR_ENDPOINTID
, hdr
->htc_info
);
261 if (eid
>= ATH11K_HTC_EP_COUNT
) {
262 ath11k_warn(ab
, "HTC Rx: invalid eid %d\n", eid
);
266 ep
= &htc
->endpoint
[eid
];
268 payload_len
= FIELD_GET(HTC_HDR_PAYLOADLEN
, hdr
->htc_info
);
270 if (payload_len
+ sizeof(*hdr
) > ATH11K_HTC_MAX_LEN
) {
271 ath11k_warn(ab
, "HTC rx frame too long, len: %zu\n",
272 payload_len
+ sizeof(*hdr
));
276 if (skb
->len
< payload_len
) {
277 ath11k_warn(ab
, "HTC Rx: insufficient length, got %d, expected %d\n",
278 skb
->len
, payload_len
);
282 /* get flags to check for trailer */
283 trailer_present
= (FIELD_GET(HTC_HDR_FLAGS
, hdr
->htc_info
)) &
284 ATH11K_HTC_FLAG_TRAILER_PRESENT
;
286 if (trailer_present
) {
289 trailer_len
= FIELD_GET(HTC_HDR_CONTROLBYTES0
, hdr
->ctrl_info
);
290 min_len
= sizeof(struct ath11k_htc_record_hdr
);
292 if ((trailer_len
< min_len
) ||
293 (trailer_len
> payload_len
)) {
294 ath11k_warn(ab
, "Invalid trailer length: %d\n",
300 trailer
+= sizeof(*hdr
);
301 trailer
+= payload_len
;
302 trailer
-= trailer_len
;
303 status
= ath11k_htc_process_trailer(htc
, trailer
,
308 skb_trim(skb
, skb
->len
- trailer_len
);
311 if (trailer_len
>= payload_len
)
312 /* zero length packet with trailer data, just drop these */
315 if (eid
== ATH11K_HTC_EP_0
) {
316 struct ath11k_htc_msg
*msg
= (struct ath11k_htc_msg
*)skb
->data
;
318 switch (FIELD_GET(HTC_MSG_MESSAGEID
, msg
->msg_svc_id
)) {
319 case ATH11K_HTC_MSG_READY_ID
:
320 case ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID
:
321 /* handle HTC control message */
322 if (completion_done(&htc
->ctl_resp
)) {
323 /* this is a fatal error, target should not be
324 * sending unsolicited messages on the ep 0
326 ath11k_warn(ab
, "HTC rx ctrl still processing\n");
327 complete(&htc
->ctl_resp
);
331 htc
->control_resp_len
=
333 ATH11K_HTC_MAX_CTRL_MSG_LEN
);
335 memcpy(htc
->control_resp_buffer
, skb
->data
,
336 htc
->control_resp_len
);
338 complete(&htc
->ctl_resp
);
341 ath11k_warn(ab
, "ignoring unsolicited htc ep0 event\n");
347 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "htc rx completion ep %d skb %pK\n",
349 ep
->ep_ops
.ep_rx_complete(ab
, skb
);
351 /* poll tx completion for interrupt disabled CE's */
352 ath11k_ce_poll_send_completed(ab
, ep
->ul_pipe_id
);
354 /* skb is now owned by the rx completion handler */
360 static void ath11k_htc_control_rx_complete(struct ath11k_base
*ab
,
363 /* This is unexpected. FW is not supposed to send regular rx on this
366 ath11k_warn(ab
, "unexpected htc rx\n");
370 static const char *htc_service_name(enum ath11k_htc_svc_id id
)
373 case ATH11K_HTC_SVC_ID_RESERVED
:
375 case ATH11K_HTC_SVC_ID_RSVD_CTRL
:
377 case ATH11K_HTC_SVC_ID_WMI_CONTROL
:
379 case ATH11K_HTC_SVC_ID_WMI_DATA_BE
:
381 case ATH11K_HTC_SVC_ID_WMI_DATA_BK
:
383 case ATH11K_HTC_SVC_ID_WMI_DATA_VI
:
385 case ATH11K_HTC_SVC_ID_WMI_DATA_VO
:
387 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
:
389 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
:
391 case ATH11K_HTC_SVC_ID_NMI_CONTROL
:
392 return "NMI Control";
393 case ATH11K_HTC_SVC_ID_NMI_DATA
:
395 case ATH11K_HTC_SVC_ID_HTT_DATA_MSG
:
397 case ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS
:
399 case ATH11K_HTC_SVC_ID_IPA_TX
:
401 case ATH11K_HTC_SVC_ID_PKT_LOG
:
408 static void ath11k_htc_reset_endpoint_states(struct ath11k_htc
*htc
)
410 struct ath11k_htc_ep
*ep
;
413 for (i
= ATH11K_HTC_EP_0
; i
< ATH11K_HTC_EP_COUNT
; i
++) {
414 ep
= &htc
->endpoint
[i
];
415 ep
->service_id
= ATH11K_HTC_SVC_ID_UNUSED
;
416 ep
->max_ep_message_len
= 0;
417 ep
->max_tx_queue_depth
= 0;
420 ep
->tx_credit_flow_enabled
= true;
424 static u8
ath11k_htc_get_credit_allocation(struct ath11k_htc
*htc
,
427 u8 i
, allocation
= 0;
429 for (i
= 0; i
< ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES
; i
++) {
430 if (htc
->service_alloc_table
[i
].service_id
== service_id
) {
432 htc
->service_alloc_table
[i
].credit_allocation
;
439 static int ath11k_htc_setup_target_buffer_assignments(struct ath11k_htc
*htc
)
441 struct ath11k_htc_svc_tx_credits
*serv_entry
;
443 ATH11K_HTC_SVC_ID_WMI_CONTROL
,
444 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
,
445 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
,
449 credits
= htc
->total_transmit_credits
;
450 serv_entry
= htc
->service_alloc_table
;
452 if ((htc
->wmi_ep_count
== 0) ||
453 (htc
->wmi_ep_count
> ARRAY_SIZE(svc_id
)))
456 /* Divide credits among number of endpoints for WMI */
457 credits
= credits
/ htc
->wmi_ep_count
;
458 for (i
= 0; i
< htc
->wmi_ep_count
; i
++) {
459 serv_entry
[i
].service_id
= svc_id
[i
];
460 serv_entry
[i
].credit_allocation
= credits
;
466 int ath11k_htc_wait_target(struct ath11k_htc
*htc
)
469 struct ath11k_base
*ab
= htc
->ab
;
470 unsigned long time_left
;
471 struct ath11k_htc_ready
*ready
;
476 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
477 ATH11K_HTC_WAIT_TIMEOUT_HZ
);
479 ath11k_warn(ab
, "failed to receive control response completion, polling..\n");
481 for (i
= 0; i
< CE_COUNT
; i
++)
482 ath11k_ce_per_engine_service(htc
->ab
, i
);
485 wait_for_completion_timeout(&htc
->ctl_resp
,
486 ATH11K_HTC_WAIT_TIMEOUT_HZ
);
493 ath11k_warn(ab
, "ctl_resp never came in (%d)\n", status
);
497 if (htc
->control_resp_len
< sizeof(*ready
)) {
498 ath11k_warn(ab
, "Invalid HTC ready msg len:%d\n",
499 htc
->control_resp_len
);
503 ready
= (struct ath11k_htc_ready
*)htc
->control_resp_buffer
;
504 message_id
= FIELD_GET(HTC_MSG_MESSAGEID
, ready
->id_credit_count
);
505 credit_count
= FIELD_GET(HTC_READY_MSG_CREDITCOUNT
,
506 ready
->id_credit_count
);
507 credit_size
= FIELD_GET(HTC_READY_MSG_CREDITSIZE
, ready
->size_ep
);
509 if (message_id
!= ATH11K_HTC_MSG_READY_ID
) {
510 ath11k_warn(ab
, "Invalid HTC ready msg: 0x%x\n", message_id
);
514 htc
->total_transmit_credits
= credit_count
;
515 htc
->target_credit_size
= credit_size
;
517 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
518 "Target ready! transmit resources: %d size:%d\n",
519 htc
->total_transmit_credits
, htc
->target_credit_size
);
521 if ((htc
->total_transmit_credits
== 0) ||
522 (htc
->target_credit_size
== 0)) {
523 ath11k_warn(ab
, "Invalid credit size received\n");
527 ath11k_htc_setup_target_buffer_assignments(htc
);
532 int ath11k_htc_connect_service(struct ath11k_htc
*htc
,
533 struct ath11k_htc_svc_conn_req
*conn_req
,
534 struct ath11k_htc_svc_conn_resp
*conn_resp
)
536 struct ath11k_base
*ab
= htc
->ab
;
537 struct ath11k_htc_conn_svc
*req_msg
;
538 struct ath11k_htc_conn_svc_resp resp_msg_dummy
;
539 struct ath11k_htc_conn_svc_resp
*resp_msg
= &resp_msg_dummy
;
540 enum ath11k_htc_ep_id assigned_eid
= ATH11K_HTC_EP_COUNT
;
541 struct ath11k_htc_ep
*ep
;
543 unsigned int max_msg_size
= 0;
545 unsigned long time_left
;
546 bool disable_credit_flow_ctrl
= false;
547 u16 message_id
, service_id
, flags
= 0;
550 /* special case for HTC pseudo control service */
551 if (conn_req
->service_id
== ATH11K_HTC_SVC_ID_RSVD_CTRL
) {
552 disable_credit_flow_ctrl
= true;
553 assigned_eid
= ATH11K_HTC_EP_0
;
554 max_msg_size
= ATH11K_HTC_MAX_CTRL_MSG_LEN
;
555 memset(&resp_msg_dummy
, 0, sizeof(resp_msg_dummy
));
559 tx_alloc
= ath11k_htc_get_credit_allocation(htc
,
560 conn_req
->service_id
);
562 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
563 "boot htc service %s does not allocate target credits\n",
564 htc_service_name(conn_req
->service_id
));
566 skb
= ath11k_htc_build_tx_ctrl_skb(htc
->ab
);
568 ath11k_warn(ab
, "Failed to allocate HTC packet\n");
572 length
= sizeof(*req_msg
);
573 skb_put(skb
, length
);
574 memset(skb
->data
, 0, length
);
576 req_msg
= (struct ath11k_htc_conn_svc
*)skb
->data
;
577 req_msg
->msg_svc_id
= FIELD_PREP(HTC_MSG_MESSAGEID
,
578 ATH11K_HTC_MSG_CONNECT_SERVICE_ID
);
580 flags
|= FIELD_PREP(ATH11K_HTC_CONN_FLAGS_RECV_ALLOC
, tx_alloc
);
582 /* Only enable credit flow control for WMI ctrl service */
583 if (!(conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL
||
584 conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
||
585 conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
)) {
586 flags
|= ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL
;
587 disable_credit_flow_ctrl
= true;
590 req_msg
->flags_len
= FIELD_PREP(HTC_SVC_MSG_CONNECTIONFLAGS
, flags
);
591 req_msg
->msg_svc_id
|= FIELD_PREP(HTC_SVC_MSG_SERVICE_ID
,
592 conn_req
->service_id
);
594 reinit_completion(&htc
->ctl_resp
);
596 status
= ath11k_htc_send(htc
, ATH11K_HTC_EP_0
, skb
);
602 /* wait for response */
603 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
604 ATH11K_HTC_CONN_SVC_TIMEOUT_HZ
);
606 ath11k_err(ab
, "Service connect timeout\n");
610 /* we controlled the buffer creation, it's aligned */
611 resp_msg
= (struct ath11k_htc_conn_svc_resp
*)htc
->control_resp_buffer
;
612 message_id
= FIELD_GET(HTC_MSG_MESSAGEID
, resp_msg
->msg_svc_id
);
613 service_id
= FIELD_GET(HTC_SVC_RESP_MSG_SERVICEID
,
614 resp_msg
->msg_svc_id
);
616 if ((message_id
!= ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID
) ||
617 (htc
->control_resp_len
< sizeof(*resp_msg
))) {
618 ath11k_err(ab
, "Invalid resp message ID 0x%x", message_id
);
622 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
623 "HTC Service %s connect response: status: 0x%lx, assigned ep: 0x%lx\n",
624 htc_service_name(service_id
),
625 FIELD_GET(HTC_SVC_RESP_MSG_STATUS
, resp_msg
->flags_len
),
626 FIELD_GET(HTC_SVC_RESP_MSG_ENDPOINTID
, resp_msg
->flags_len
));
628 conn_resp
->connect_resp_code
= FIELD_GET(HTC_SVC_RESP_MSG_STATUS
,
629 resp_msg
->flags_len
);
631 /* check response status */
632 if (conn_resp
->connect_resp_code
!= ATH11K_HTC_CONN_SVC_STATUS_SUCCESS
) {
633 ath11k_err(ab
, "HTC Service %s connect request failed: 0x%x)\n",
634 htc_service_name(service_id
),
635 conn_resp
->connect_resp_code
);
639 assigned_eid
= (enum ath11k_htc_ep_id
)FIELD_GET(
640 HTC_SVC_RESP_MSG_ENDPOINTID
,
641 resp_msg
->flags_len
);
643 max_msg_size
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
644 resp_msg
->flags_len
);
648 if (assigned_eid
>= ATH11K_HTC_EP_COUNT
)
651 if (max_msg_size
== 0)
654 ep
= &htc
->endpoint
[assigned_eid
];
655 ep
->eid
= assigned_eid
;
657 if (ep
->service_id
!= ATH11K_HTC_SVC_ID_UNUSED
)
660 /* return assigned endpoint to caller */
661 conn_resp
->eid
= assigned_eid
;
662 conn_resp
->max_msg_len
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
663 resp_msg
->flags_len
);
665 /* setup the endpoint */
666 ep
->service_id
= conn_req
->service_id
;
667 ep
->max_tx_queue_depth
= conn_req
->max_send_queue_depth
;
668 ep
->max_ep_message_len
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
669 resp_msg
->flags_len
);
670 ep
->tx_credits
= tx_alloc
;
672 /* copy all the callbacks */
673 ep
->ep_ops
= conn_req
->ep_ops
;
675 status
= ath11k_ahb_map_service_to_pipe(htc
->ab
,
682 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
683 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
684 htc_service_name(ep
->service_id
), ep
->ul_pipe_id
,
685 ep
->dl_pipe_id
, ep
->eid
);
687 if (disable_credit_flow_ctrl
&& ep
->tx_credit_flow_enabled
) {
688 ep
->tx_credit_flow_enabled
= false;
689 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
690 "boot htc service '%s' eid %d TX flow control disabled\n",
691 htc_service_name(ep
->service_id
), assigned_eid
);
697 int ath11k_htc_start(struct ath11k_htc
*htc
)
701 struct ath11k_base
*ab
= htc
->ab
;
702 struct ath11k_htc_setup_complete_extended
*msg
;
704 skb
= ath11k_htc_build_tx_ctrl_skb(htc
->ab
);
708 skb_put(skb
, sizeof(*msg
));
709 memset(skb
->data
, 0, skb
->len
);
711 msg
= (struct ath11k_htc_setup_complete_extended
*)skb
->data
;
712 msg
->msg_id
= FIELD_PREP(HTC_MSG_MESSAGEID
,
713 ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID
);
715 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "HTC is using TX credit flow control\n");
717 status
= ath11k_htc_send(htc
, ATH11K_HTC_EP_0
, skb
);
726 int ath11k_htc_init(struct ath11k_base
*ab
)
728 struct ath11k_htc
*htc
= &ab
->htc
;
729 struct ath11k_htc_svc_conn_req conn_req
;
730 struct ath11k_htc_svc_conn_resp conn_resp
;
733 spin_lock_init(&htc
->tx_lock
);
735 ath11k_htc_reset_endpoint_states(htc
);
739 switch (ab
->wmi_ab
.preferred_hw_mode
) {
740 case WMI_HOST_HW_MODE_SINGLE
:
741 htc
->wmi_ep_count
= 1;
743 case WMI_HOST_HW_MODE_DBS
:
744 case WMI_HOST_HW_MODE_DBS_OR_SBS
:
745 htc
->wmi_ep_count
= 2;
747 case WMI_HOST_HW_MODE_DBS_SBS
:
748 htc
->wmi_ep_count
= 3;
751 htc
->wmi_ep_count
= 3;
755 /* setup our pseudo HTC control endpoint connection */
756 memset(&conn_req
, 0, sizeof(conn_req
));
757 memset(&conn_resp
, 0, sizeof(conn_resp
));
758 conn_req
.ep_ops
.ep_tx_complete
= ath11k_htc_control_tx_complete
;
759 conn_req
.ep_ops
.ep_rx_complete
= ath11k_htc_control_rx_complete
;
760 conn_req
.max_send_queue_depth
= ATH11K_NUM_CONTROL_TX_BUFFERS
;
761 conn_req
.service_id
= ATH11K_HTC_SVC_ID_RSVD_CTRL
;
763 /* connect fake service */
764 ret
= ath11k_htc_connect_service(htc
, &conn_req
, &conn_resp
);
766 ath11k_err(ab
, "could not connect to htc service (%d)\n", ret
);
770 init_completion(&htc
->ctl_resp
);