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
;
85 if (eid
>= ATH11K_HTC_EP_COUNT
) {
86 ath11k_warn(ab
, "Invalid endpoint id: %d\n", eid
);
90 skb_push(skb
, sizeof(struct ath11k_htc_hdr
));
92 if (ep
->tx_credit_flow_enabled
) {
93 credits
= DIV_ROUND_UP(skb
->len
, htc
->target_credit_size
);
94 spin_lock_bh(&htc
->tx_lock
);
95 if (ep
->tx_credits
< credits
) {
96 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
97 "htc insufficient credits ep %d required %d available %d\n",
98 eid
, credits
, ep
->tx_credits
);
99 spin_unlock_bh(&htc
->tx_lock
);
103 ep
->tx_credits
-= credits
;
104 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
105 "htc ep %d consumed %d credits (total %d)\n",
106 eid
, credits
, ep
->tx_credits
);
107 spin_unlock_bh(&htc
->tx_lock
);
110 ath11k_htc_prepare_tx_skb(ep
, skb
);
113 skb_cb
->paddr
= dma_map_single(dev
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
114 ret
= dma_mapping_error(dev
, skb_cb
->paddr
);
120 ret
= ath11k_ce_send(htc
->ab
, skb
, ep
->ul_pipe_id
, ep
->eid
);
127 dma_unmap_single(dev
, skb_cb
->paddr
, skb
->len
, DMA_TO_DEVICE
);
129 if (ep
->tx_credit_flow_enabled
) {
130 spin_lock_bh(&htc
->tx_lock
);
131 ep
->tx_credits
+= credits
;
132 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
133 "htc ep %d reverted %d credits back (total %d)\n",
134 eid
, credits
, ep
->tx_credits
);
135 spin_unlock_bh(&htc
->tx_lock
);
137 if (ep
->ep_ops
.ep_tx_credits
)
138 ep
->ep_ops
.ep_tx_credits(htc
->ab
);
141 skb_pull(skb
, sizeof(struct ath11k_htc_hdr
));
146 ath11k_htc_process_credit_report(struct ath11k_htc
*htc
,
147 const struct ath11k_htc_credit_report
*report
,
149 enum ath11k_htc_ep_id eid
)
151 struct ath11k_base
*ab
= htc
->ab
;
152 struct ath11k_htc_ep
*ep
;
155 if (len
% sizeof(*report
))
156 ath11k_warn(ab
, "Uneven credit report len %d", len
);
158 n_reports
= len
/ sizeof(*report
);
160 spin_lock_bh(&htc
->tx_lock
);
161 for (i
= 0; i
< n_reports
; i
++, report
++) {
162 if (report
->eid
>= ATH11K_HTC_EP_COUNT
)
165 ep
= &htc
->endpoint
[report
->eid
];
166 ep
->tx_credits
+= report
->credits
;
168 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "htc ep %d got %d credits (total %d)\n",
169 report
->eid
, report
->credits
, ep
->tx_credits
);
171 if (ep
->ep_ops
.ep_tx_credits
) {
172 spin_unlock_bh(&htc
->tx_lock
);
173 ep
->ep_ops
.ep_tx_credits(htc
->ab
);
174 spin_lock_bh(&htc
->tx_lock
);
177 spin_unlock_bh(&htc
->tx_lock
);
180 static int ath11k_htc_process_trailer(struct ath11k_htc
*htc
,
183 enum ath11k_htc_ep_id src_eid
)
185 struct ath11k_base
*ab
= htc
->ab
;
187 struct ath11k_htc_record
*record
;
191 record
= (struct ath11k_htc_record
*)buffer
;
193 if (length
< sizeof(record
->hdr
)) {
198 if (record
->hdr
.len
> length
) {
199 /* no room left in buffer for record */
200 ath11k_warn(ab
, "Invalid record length: %d\n",
206 switch (record
->hdr
.id
) {
207 case ATH11K_HTC_RECORD_CREDITS
:
208 len
= sizeof(struct ath11k_htc_credit_report
);
209 if (record
->hdr
.len
< len
) {
210 ath11k_warn(ab
, "Credit report too long\n");
214 ath11k_htc_process_credit_report(htc
,
215 record
->credit_report
,
220 ath11k_warn(ab
, "Unhandled record: id:%d length:%d\n",
221 record
->hdr
.id
, record
->hdr
.len
);
228 /* multiple records may be present in a trailer */
229 buffer
+= sizeof(record
->hdr
) + record
->hdr
.len
;
230 length
-= sizeof(record
->hdr
) + record
->hdr
.len
;
236 static void ath11k_htc_suspend_complete(struct ath11k_base
*ab
, bool ack
)
238 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "boot suspend complete %d\n", ack
);
241 set_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE
, &ab
->dev_flags
);
243 clear_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE
, &ab
->dev_flags
);
245 complete(&ab
->htc_suspend
);
248 void ath11k_htc_rx_completion_handler(struct ath11k_base
*ab
,
252 struct ath11k_htc
*htc
= &ab
->htc
;
253 struct ath11k_htc_hdr
*hdr
;
254 struct ath11k_htc_ep
*ep
;
259 bool trailer_present
;
261 hdr
= (struct ath11k_htc_hdr
*)skb
->data
;
262 skb_pull(skb
, sizeof(*hdr
));
264 eid
= FIELD_GET(HTC_HDR_ENDPOINTID
, hdr
->htc_info
);
266 if (eid
>= ATH11K_HTC_EP_COUNT
) {
267 ath11k_warn(ab
, "HTC Rx: invalid eid %d\n", eid
);
271 ep
= &htc
->endpoint
[eid
];
273 payload_len
= FIELD_GET(HTC_HDR_PAYLOADLEN
, hdr
->htc_info
);
275 if (payload_len
+ sizeof(*hdr
) > ATH11K_HTC_MAX_LEN
) {
276 ath11k_warn(ab
, "HTC rx frame too long, len: %zu\n",
277 payload_len
+ sizeof(*hdr
));
281 if (skb
->len
< payload_len
) {
282 ath11k_warn(ab
, "HTC Rx: insufficient length, got %d, expected %d\n",
283 skb
->len
, payload_len
);
287 /* get flags to check for trailer */
288 trailer_present
= (FIELD_GET(HTC_HDR_FLAGS
, hdr
->htc_info
)) &
289 ATH11K_HTC_FLAG_TRAILER_PRESENT
;
291 if (trailer_present
) {
294 trailer_len
= FIELD_GET(HTC_HDR_CONTROLBYTES0
, hdr
->ctrl_info
);
295 min_len
= sizeof(struct ath11k_htc_record_hdr
);
297 if ((trailer_len
< min_len
) ||
298 (trailer_len
> payload_len
)) {
299 ath11k_warn(ab
, "Invalid trailer length: %d\n",
305 trailer
+= sizeof(*hdr
);
306 trailer
+= payload_len
;
307 trailer
-= trailer_len
;
308 status
= ath11k_htc_process_trailer(htc
, trailer
,
313 skb_trim(skb
, skb
->len
- trailer_len
);
316 if (trailer_len
>= payload_len
)
317 /* zero length packet with trailer data, just drop these */
320 if (eid
== ATH11K_HTC_EP_0
) {
321 struct ath11k_htc_msg
*msg
= (struct ath11k_htc_msg
*)skb
->data
;
323 switch (FIELD_GET(HTC_MSG_MESSAGEID
, msg
->msg_svc_id
)) {
324 case ATH11K_HTC_MSG_READY_ID
:
325 case ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID
:
326 /* handle HTC control message */
327 if (completion_done(&htc
->ctl_resp
)) {
328 /* this is a fatal error, target should not be
329 * sending unsolicited messages on the ep 0
331 ath11k_warn(ab
, "HTC rx ctrl still processing\n");
332 complete(&htc
->ctl_resp
);
336 htc
->control_resp_len
=
338 ATH11K_HTC_MAX_CTRL_MSG_LEN
);
340 memcpy(htc
->control_resp_buffer
, skb
->data
,
341 htc
->control_resp_len
);
343 complete(&htc
->ctl_resp
);
345 case ATH11K_HTC_MSG_SEND_SUSPEND_COMPLETE
:
346 ath11k_htc_suspend_complete(ab
, true);
348 case ATH11K_HTC_MSG_NACK_SUSPEND
:
349 ath11k_htc_suspend_complete(ab
, false);
351 case ATH11K_HTC_MSG_WAKEUP_FROM_SUSPEND_ID
:
354 ath11k_warn(ab
, "ignoring unsolicited htc ep0 event %ld\n",
355 FIELD_GET(HTC_MSG_MESSAGEID
, msg
->msg_svc_id
));
361 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "htc rx completion ep %d skb %pK\n",
363 ep
->ep_ops
.ep_rx_complete(ab
, skb
);
365 /* poll tx completion for interrupt disabled CE's */
366 ath11k_ce_poll_send_completed(ab
, ep
->ul_pipe_id
);
368 /* skb is now owned by the rx completion handler */
374 static void ath11k_htc_control_rx_complete(struct ath11k_base
*ab
,
377 /* This is unexpected. FW is not supposed to send regular rx on this
380 ath11k_warn(ab
, "unexpected htc rx\n");
384 static const char *htc_service_name(enum ath11k_htc_svc_id id
)
387 case ATH11K_HTC_SVC_ID_RESERVED
:
389 case ATH11K_HTC_SVC_ID_RSVD_CTRL
:
391 case ATH11K_HTC_SVC_ID_WMI_CONTROL
:
393 case ATH11K_HTC_SVC_ID_WMI_DATA_BE
:
395 case ATH11K_HTC_SVC_ID_WMI_DATA_BK
:
397 case ATH11K_HTC_SVC_ID_WMI_DATA_VI
:
399 case ATH11K_HTC_SVC_ID_WMI_DATA_VO
:
401 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
:
403 case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
:
405 case ATH11K_HTC_SVC_ID_NMI_CONTROL
:
406 return "NMI Control";
407 case ATH11K_HTC_SVC_ID_NMI_DATA
:
409 case ATH11K_HTC_SVC_ID_HTT_DATA_MSG
:
411 case ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS
:
413 case ATH11K_HTC_SVC_ID_IPA_TX
:
415 case ATH11K_HTC_SVC_ID_PKT_LOG
:
422 static void ath11k_htc_reset_endpoint_states(struct ath11k_htc
*htc
)
424 struct ath11k_htc_ep
*ep
;
427 for (i
= ATH11K_HTC_EP_0
; i
< ATH11K_HTC_EP_COUNT
; i
++) {
428 ep
= &htc
->endpoint
[i
];
429 ep
->service_id
= ATH11K_HTC_SVC_ID_UNUSED
;
430 ep
->max_ep_message_len
= 0;
431 ep
->max_tx_queue_depth
= 0;
434 ep
->tx_credit_flow_enabled
= true;
438 static u8
ath11k_htc_get_credit_allocation(struct ath11k_htc
*htc
,
441 u8 i
, allocation
= 0;
443 for (i
= 0; i
< ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES
; i
++) {
444 if (htc
->service_alloc_table
[i
].service_id
== service_id
) {
446 htc
->service_alloc_table
[i
].credit_allocation
;
453 static int ath11k_htc_setup_target_buffer_assignments(struct ath11k_htc
*htc
)
455 struct ath11k_htc_svc_tx_credits
*serv_entry
;
457 ATH11K_HTC_SVC_ID_WMI_CONTROL
,
458 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
,
459 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
,
463 credits
= htc
->total_transmit_credits
;
464 serv_entry
= htc
->service_alloc_table
;
466 if ((htc
->wmi_ep_count
== 0) ||
467 (htc
->wmi_ep_count
> ARRAY_SIZE(svc_id
)))
470 /* Divide credits among number of endpoints for WMI */
471 credits
= credits
/ htc
->wmi_ep_count
;
472 for (i
= 0; i
< htc
->wmi_ep_count
; i
++) {
473 serv_entry
[i
].service_id
= svc_id
[i
];
474 serv_entry
[i
].credit_allocation
= credits
;
480 int ath11k_htc_wait_target(struct ath11k_htc
*htc
)
483 struct ath11k_base
*ab
= htc
->ab
;
484 unsigned long time_left
;
485 struct ath11k_htc_ready
*ready
;
490 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
491 ATH11K_HTC_WAIT_TIMEOUT_HZ
);
493 ath11k_warn(ab
, "failed to receive control response completion, polling..\n");
495 for (i
= 0; i
< ab
->hw_params
.ce_count
; i
++)
496 ath11k_ce_per_engine_service(htc
->ab
, i
);
499 wait_for_completion_timeout(&htc
->ctl_resp
,
500 ATH11K_HTC_WAIT_TIMEOUT_HZ
);
507 ath11k_warn(ab
, "ctl_resp never came in (%d)\n", status
);
511 if (htc
->control_resp_len
< sizeof(*ready
)) {
512 ath11k_warn(ab
, "Invalid HTC ready msg len:%d\n",
513 htc
->control_resp_len
);
517 ready
= (struct ath11k_htc_ready
*)htc
->control_resp_buffer
;
518 message_id
= FIELD_GET(HTC_MSG_MESSAGEID
, ready
->id_credit_count
);
519 credit_count
= FIELD_GET(HTC_READY_MSG_CREDITCOUNT
,
520 ready
->id_credit_count
);
521 credit_size
= FIELD_GET(HTC_READY_MSG_CREDITSIZE
, ready
->size_ep
);
523 if (message_id
!= ATH11K_HTC_MSG_READY_ID
) {
524 ath11k_warn(ab
, "Invalid HTC ready msg: 0x%x\n", message_id
);
528 htc
->total_transmit_credits
= credit_count
;
529 htc
->target_credit_size
= credit_size
;
531 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
532 "Target ready! transmit resources: %d size:%d\n",
533 htc
->total_transmit_credits
, htc
->target_credit_size
);
535 if ((htc
->total_transmit_credits
== 0) ||
536 (htc
->target_credit_size
== 0)) {
537 ath11k_warn(ab
, "Invalid credit size received\n");
541 /* For QCA6390, wmi endpoint uses 1 credit to avoid
542 * back-to-back write.
544 if (ab
->hw_params
.supports_shadow_regs
)
545 htc
->total_transmit_credits
= 1;
547 ath11k_htc_setup_target_buffer_assignments(htc
);
552 int ath11k_htc_connect_service(struct ath11k_htc
*htc
,
553 struct ath11k_htc_svc_conn_req
*conn_req
,
554 struct ath11k_htc_svc_conn_resp
*conn_resp
)
556 struct ath11k_base
*ab
= htc
->ab
;
557 struct ath11k_htc_conn_svc
*req_msg
;
558 struct ath11k_htc_conn_svc_resp resp_msg_dummy
;
559 struct ath11k_htc_conn_svc_resp
*resp_msg
= &resp_msg_dummy
;
560 enum ath11k_htc_ep_id assigned_eid
= ATH11K_HTC_EP_COUNT
;
561 struct ath11k_htc_ep
*ep
;
563 unsigned int max_msg_size
= 0;
565 unsigned long time_left
;
566 bool disable_credit_flow_ctrl
= false;
567 u16 message_id
, service_id
, flags
= 0;
570 /* special case for HTC pseudo control service */
571 if (conn_req
->service_id
== ATH11K_HTC_SVC_ID_RSVD_CTRL
) {
572 disable_credit_flow_ctrl
= true;
573 assigned_eid
= ATH11K_HTC_EP_0
;
574 max_msg_size
= ATH11K_HTC_MAX_CTRL_MSG_LEN
;
575 memset(&resp_msg_dummy
, 0, sizeof(resp_msg_dummy
));
579 tx_alloc
= ath11k_htc_get_credit_allocation(htc
,
580 conn_req
->service_id
);
582 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
583 "boot htc service %s does not allocate target credits\n",
584 htc_service_name(conn_req
->service_id
));
586 skb
= ath11k_htc_build_tx_ctrl_skb(htc
->ab
);
588 ath11k_warn(ab
, "Failed to allocate HTC packet\n");
592 length
= sizeof(*req_msg
);
593 skb_put(skb
, length
);
594 memset(skb
->data
, 0, length
);
596 req_msg
= (struct ath11k_htc_conn_svc
*)skb
->data
;
597 req_msg
->msg_svc_id
= FIELD_PREP(HTC_MSG_MESSAGEID
,
598 ATH11K_HTC_MSG_CONNECT_SERVICE_ID
);
600 flags
|= FIELD_PREP(ATH11K_HTC_CONN_FLAGS_RECV_ALLOC
, tx_alloc
);
602 /* Only enable credit flow control for WMI ctrl service */
603 if (!(conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL
||
604 conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1
||
605 conn_req
->service_id
== ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2
)) {
606 flags
|= ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL
;
607 disable_credit_flow_ctrl
= true;
610 req_msg
->flags_len
= FIELD_PREP(HTC_SVC_MSG_CONNECTIONFLAGS
, flags
);
611 req_msg
->msg_svc_id
|= FIELD_PREP(HTC_SVC_MSG_SERVICE_ID
,
612 conn_req
->service_id
);
614 reinit_completion(&htc
->ctl_resp
);
616 status
= ath11k_htc_send(htc
, ATH11K_HTC_EP_0
, skb
);
622 /* wait for response */
623 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
624 ATH11K_HTC_CONN_SVC_TIMEOUT_HZ
);
626 ath11k_err(ab
, "Service connect timeout\n");
630 /* we controlled the buffer creation, it's aligned */
631 resp_msg
= (struct ath11k_htc_conn_svc_resp
*)htc
->control_resp_buffer
;
632 message_id
= FIELD_GET(HTC_MSG_MESSAGEID
, resp_msg
->msg_svc_id
);
633 service_id
= FIELD_GET(HTC_SVC_RESP_MSG_SERVICEID
,
634 resp_msg
->msg_svc_id
);
636 if ((message_id
!= ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID
) ||
637 (htc
->control_resp_len
< sizeof(*resp_msg
))) {
638 ath11k_err(ab
, "Invalid resp message ID 0x%x", message_id
);
642 ath11k_dbg(ab
, ATH11K_DBG_HTC
,
643 "HTC Service %s connect response: status: 0x%lx, assigned ep: 0x%lx\n",
644 htc_service_name(service_id
),
645 FIELD_GET(HTC_SVC_RESP_MSG_STATUS
, resp_msg
->flags_len
),
646 FIELD_GET(HTC_SVC_RESP_MSG_ENDPOINTID
, resp_msg
->flags_len
));
648 conn_resp
->connect_resp_code
= FIELD_GET(HTC_SVC_RESP_MSG_STATUS
,
649 resp_msg
->flags_len
);
651 /* check response status */
652 if (conn_resp
->connect_resp_code
!= ATH11K_HTC_CONN_SVC_STATUS_SUCCESS
) {
653 ath11k_err(ab
, "HTC Service %s connect request failed: 0x%x)\n",
654 htc_service_name(service_id
),
655 conn_resp
->connect_resp_code
);
659 assigned_eid
= (enum ath11k_htc_ep_id
)FIELD_GET(
660 HTC_SVC_RESP_MSG_ENDPOINTID
,
661 resp_msg
->flags_len
);
663 max_msg_size
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
664 resp_msg
->flags_len
);
668 if (assigned_eid
>= ATH11K_HTC_EP_COUNT
)
671 if (max_msg_size
== 0)
674 ep
= &htc
->endpoint
[assigned_eid
];
675 ep
->eid
= assigned_eid
;
677 if (ep
->service_id
!= ATH11K_HTC_SVC_ID_UNUSED
)
680 /* return assigned endpoint to caller */
681 conn_resp
->eid
= assigned_eid
;
682 conn_resp
->max_msg_len
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
683 resp_msg
->flags_len
);
685 /* setup the endpoint */
686 ep
->service_id
= conn_req
->service_id
;
687 ep
->max_tx_queue_depth
= conn_req
->max_send_queue_depth
;
688 ep
->max_ep_message_len
= FIELD_GET(HTC_SVC_RESP_MSG_MAXMSGSIZE
,
689 resp_msg
->flags_len
);
690 ep
->tx_credits
= tx_alloc
;
692 /* copy all the callbacks */
693 ep
->ep_ops
= conn_req
->ep_ops
;
695 status
= ath11k_hif_map_service_to_pipe(htc
->ab
,
702 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
703 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
704 htc_service_name(ep
->service_id
), ep
->ul_pipe_id
,
705 ep
->dl_pipe_id
, ep
->eid
);
707 if (disable_credit_flow_ctrl
&& ep
->tx_credit_flow_enabled
) {
708 ep
->tx_credit_flow_enabled
= false;
709 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
710 "boot htc service '%s' eid %d TX flow control disabled\n",
711 htc_service_name(ep
->service_id
), assigned_eid
);
717 int ath11k_htc_start(struct ath11k_htc
*htc
)
721 struct ath11k_base
*ab
= htc
->ab
;
722 struct ath11k_htc_setup_complete_extended
*msg
;
724 skb
= ath11k_htc_build_tx_ctrl_skb(htc
->ab
);
728 skb_put(skb
, sizeof(*msg
));
729 memset(skb
->data
, 0, skb
->len
);
731 msg
= (struct ath11k_htc_setup_complete_extended
*)skb
->data
;
732 msg
->msg_id
= FIELD_PREP(HTC_MSG_MESSAGEID
,
733 ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID
);
735 ath11k_dbg(ab
, ATH11K_DBG_HTC
, "HTC is using TX credit flow control\n");
737 status
= ath11k_htc_send(htc
, ATH11K_HTC_EP_0
, skb
);
746 int ath11k_htc_init(struct ath11k_base
*ab
)
748 struct ath11k_htc
*htc
= &ab
->htc
;
749 struct ath11k_htc_svc_conn_req conn_req
;
750 struct ath11k_htc_svc_conn_resp conn_resp
;
753 spin_lock_init(&htc
->tx_lock
);
755 ath11k_htc_reset_endpoint_states(htc
);
759 switch (ab
->wmi_ab
.preferred_hw_mode
) {
760 case WMI_HOST_HW_MODE_SINGLE
:
761 htc
->wmi_ep_count
= 1;
763 case WMI_HOST_HW_MODE_DBS
:
764 case WMI_HOST_HW_MODE_DBS_OR_SBS
:
765 htc
->wmi_ep_count
= 2;
767 case WMI_HOST_HW_MODE_DBS_SBS
:
768 htc
->wmi_ep_count
= 3;
771 htc
->wmi_ep_count
= ab
->hw_params
.max_radios
;
775 /* setup our pseudo HTC control endpoint connection */
776 memset(&conn_req
, 0, sizeof(conn_req
));
777 memset(&conn_resp
, 0, sizeof(conn_resp
));
778 conn_req
.ep_ops
.ep_tx_complete
= ath11k_htc_control_tx_complete
;
779 conn_req
.ep_ops
.ep_rx_complete
= ath11k_htc_control_rx_complete
;
780 conn_req
.max_send_queue_depth
= ATH11K_NUM_CONTROL_TX_BUFFERS
;
781 conn_req
.service_id
= ATH11K_HTC_SVC_ID_RSVD_CTRL
;
783 /* connect fake service */
784 ret
= ath11k_htc_connect_service(htc
, &conn_req
, &conn_resp
);
786 ath11k_err(ab
, "could not connect to htc service (%d)\n", ret
);
790 init_completion(&htc
->ctl_resp
);