1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
15 static void ath10k_htc_control_tx_complete(struct ath10k
*ar
,
21 static struct sk_buff
*ath10k_htc_build_tx_ctrl_skb(void *ar
)
24 struct ath10k_skb_cb
*skb_cb
;
26 skb
= dev_alloc_skb(ATH10K_HTC_CONTROL_BUFFER_SIZE
);
30 skb_reserve(skb
, 20); /* FIXME: why 20 bytes? */
31 WARN_ONCE((unsigned long)skb
->data
& 3, "unaligned skb");
33 skb_cb
= ATH10K_SKB_CB(skb
);
34 memset(skb_cb
, 0, sizeof(*skb_cb
));
36 ath10k_dbg(ar
, ATH10K_DBG_HTC
, "%s: skb %pK\n", __func__
, skb
);
40 static inline void ath10k_htc_restore_tx_skb(struct ath10k_htc
*htc
,
43 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
45 if (htc
->ar
->bus_param
.dev_type
!= ATH10K_DEV_TYPE_HL
)
46 dma_unmap_single(htc
->ar
->dev
, skb_cb
->paddr
, skb
->len
, DMA_TO_DEVICE
);
47 skb_pull(skb
, sizeof(struct ath10k_htc_hdr
));
50 void ath10k_htc_notify_tx_completion(struct ath10k_htc_ep
*ep
,
53 struct ath10k
*ar
= ep
->htc
->ar
;
55 ath10k_dbg(ar
, ATH10K_DBG_HTC
, "%s: ep %d skb %pK\n", __func__
,
58 ath10k_htc_restore_tx_skb(ep
->htc
, skb
);
60 if (!ep
->ep_ops
.ep_tx_complete
) {
61 ath10k_warn(ar
, "no tx handler for eid %d\n", ep
->eid
);
62 dev_kfree_skb_any(skb
);
66 ep
->ep_ops
.ep_tx_complete(ep
->htc
->ar
, skb
);
68 EXPORT_SYMBOL(ath10k_htc_notify_tx_completion
);
70 static void ath10k_htc_prepare_tx_skb(struct ath10k_htc_ep
*ep
,
73 struct ath10k_htc_hdr
*hdr
;
75 hdr
= (struct ath10k_htc_hdr
*)skb
->data
;
76 memset(hdr
, 0, sizeof(struct ath10k_htc_hdr
));
79 hdr
->len
= __cpu_to_le16(skb
->len
- sizeof(*hdr
));
81 if (ep
->tx_credit_flow_enabled
)
82 hdr
->flags
|= ATH10K_HTC_FLAG_NEED_CREDIT_UPDATE
;
84 spin_lock_bh(&ep
->htc
->tx_lock
);
85 hdr
->seq_no
= ep
->seq_no
++;
86 spin_unlock_bh(&ep
->htc
->tx_lock
);
89 int ath10k_htc_send(struct ath10k_htc
*htc
,
90 enum ath10k_htc_ep_id eid
,
93 struct ath10k
*ar
= htc
->ar
;
94 struct ath10k_htc_ep
*ep
= &htc
->endpoint
[eid
];
95 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
96 struct ath10k_hif_sg_item sg_item
;
97 struct device
*dev
= htc
->ar
->dev
;
101 if (htc
->ar
->state
== ATH10K_STATE_WEDGED
)
104 if (eid
>= ATH10K_HTC_EP_COUNT
) {
105 ath10k_warn(ar
, "Invalid endpoint id: %d\n", eid
);
109 skb_push(skb
, sizeof(struct ath10k_htc_hdr
));
111 if (ep
->tx_credit_flow_enabled
) {
112 credits
= DIV_ROUND_UP(skb
->len
, htc
->target_credit_size
);
113 spin_lock_bh(&htc
->tx_lock
);
114 if (ep
->tx_credits
< credits
) {
115 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
116 "htc insufficient credits ep %d required %d available %d\n",
117 eid
, credits
, ep
->tx_credits
);
118 spin_unlock_bh(&htc
->tx_lock
);
122 ep
->tx_credits
-= credits
;
123 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
124 "htc ep %d consumed %d credits (total %d)\n",
125 eid
, credits
, ep
->tx_credits
);
126 spin_unlock_bh(&htc
->tx_lock
);
129 ath10k_htc_prepare_tx_skb(ep
, skb
);
132 if (ar
->bus_param
.dev_type
!= ATH10K_DEV_TYPE_HL
) {
133 skb_cb
->paddr
= dma_map_single(dev
, skb
->data
, skb
->len
,
135 ret
= dma_mapping_error(dev
, skb_cb
->paddr
);
142 sg_item
.transfer_id
= ep
->eid
;
143 sg_item
.transfer_context
= skb
;
144 sg_item
.vaddr
= skb
->data
;
145 sg_item
.paddr
= skb_cb
->paddr
;
146 sg_item
.len
= skb
->len
;
148 ret
= ath10k_hif_tx_sg(htc
->ar
, ep
->ul_pipe_id
, &sg_item
, 1);
155 if (ar
->bus_param
.dev_type
!= ATH10K_DEV_TYPE_HL
)
156 dma_unmap_single(dev
, skb_cb
->paddr
, skb
->len
, DMA_TO_DEVICE
);
158 if (ep
->tx_credit_flow_enabled
) {
159 spin_lock_bh(&htc
->tx_lock
);
160 ep
->tx_credits
+= credits
;
161 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
162 "htc ep %d reverted %d credits back (total %d)\n",
163 eid
, credits
, ep
->tx_credits
);
164 spin_unlock_bh(&htc
->tx_lock
);
166 if (ep
->ep_ops
.ep_tx_credits
)
167 ep
->ep_ops
.ep_tx_credits(htc
->ar
);
170 skb_pull(skb
, sizeof(struct ath10k_htc_hdr
));
174 void ath10k_htc_tx_completion_handler(struct ath10k
*ar
, struct sk_buff
*skb
)
176 struct ath10k_htc
*htc
= &ar
->htc
;
177 struct ath10k_skb_cb
*skb_cb
;
178 struct ath10k_htc_ep
*ep
;
180 if (WARN_ON_ONCE(!skb
))
183 skb_cb
= ATH10K_SKB_CB(skb
);
184 ep
= &htc
->endpoint
[skb_cb
->eid
];
186 ath10k_htc_notify_tx_completion(ep
, skb
);
187 /* the skb now belongs to the completion handler */
189 EXPORT_SYMBOL(ath10k_htc_tx_completion_handler
);
196 ath10k_htc_process_credit_report(struct ath10k_htc
*htc
,
197 const struct ath10k_htc_credit_report
*report
,
199 enum ath10k_htc_ep_id eid
)
201 struct ath10k
*ar
= htc
->ar
;
202 struct ath10k_htc_ep
*ep
;
205 if (len
% sizeof(*report
))
206 ath10k_warn(ar
, "Uneven credit report len %d", len
);
208 n_reports
= len
/ sizeof(*report
);
210 spin_lock_bh(&htc
->tx_lock
);
211 for (i
= 0; i
< n_reports
; i
++, report
++) {
212 if (report
->eid
>= ATH10K_HTC_EP_COUNT
)
215 ep
= &htc
->endpoint
[report
->eid
];
216 ep
->tx_credits
+= report
->credits
;
218 ath10k_dbg(ar
, ATH10K_DBG_HTC
, "htc ep %d got %d credits (total %d)\n",
219 report
->eid
, report
->credits
, ep
->tx_credits
);
221 if (ep
->ep_ops
.ep_tx_credits
) {
222 spin_unlock_bh(&htc
->tx_lock
);
223 ep
->ep_ops
.ep_tx_credits(htc
->ar
);
224 spin_lock_bh(&htc
->tx_lock
);
227 spin_unlock_bh(&htc
->tx_lock
);
231 ath10k_htc_process_lookahead(struct ath10k_htc
*htc
,
232 const struct ath10k_htc_lookahead_report
*report
,
234 enum ath10k_htc_ep_id eid
,
235 void *next_lookaheads
,
236 int *next_lookaheads_len
)
238 struct ath10k
*ar
= htc
->ar
;
240 /* Invalid lookahead flags are actually transmitted by
241 * the target in the HTC control message.
242 * Since this will happen at every boot we silently ignore
243 * the lookahead in this case
245 if (report
->pre_valid
!= ((~report
->post_valid
) & 0xFF))
248 if (next_lookaheads
&& next_lookaheads_len
) {
249 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
250 "htc rx lookahead found pre_valid 0x%x post_valid 0x%x\n",
251 report
->pre_valid
, report
->post_valid
);
253 /* look ahead bytes are valid, copy them over */
254 memcpy((u8
*)next_lookaheads
, report
->lookahead
, 4);
256 *next_lookaheads_len
= 1;
263 ath10k_htc_process_lookahead_bundle(struct ath10k_htc
*htc
,
264 const struct ath10k_htc_lookahead_bundle
*report
,
266 enum ath10k_htc_ep_id eid
,
267 void *next_lookaheads
,
268 int *next_lookaheads_len
)
270 struct ath10k
*ar
= htc
->ar
;
271 int bundle_cnt
= len
/ sizeof(*report
);
273 if (!bundle_cnt
|| (bundle_cnt
> htc
->max_msgs_per_htc_bundle
)) {
274 ath10k_warn(ar
, "Invalid lookahead bundle count: %d\n",
279 if (next_lookaheads
&& next_lookaheads_len
) {
282 for (i
= 0; i
< bundle_cnt
; i
++) {
283 memcpy(((u8
*)next_lookaheads
) + 4 * i
,
284 report
->lookahead
, 4);
288 *next_lookaheads_len
= bundle_cnt
;
294 int ath10k_htc_process_trailer(struct ath10k_htc
*htc
,
297 enum ath10k_htc_ep_id src_eid
,
298 void *next_lookaheads
,
299 int *next_lookaheads_len
)
301 struct ath10k_htc_lookahead_bundle
*bundle
;
302 struct ath10k
*ar
= htc
->ar
;
304 struct ath10k_htc_record
*record
;
309 orig_buffer
= buffer
;
310 orig_length
= length
;
313 record
= (struct ath10k_htc_record
*)buffer
;
315 if (length
< sizeof(record
->hdr
)) {
320 if (record
->hdr
.len
> length
) {
321 /* no room left in buffer for record */
322 ath10k_warn(ar
, "Invalid record length: %d\n",
328 switch (record
->hdr
.id
) {
329 case ATH10K_HTC_RECORD_CREDITS
:
330 len
= sizeof(struct ath10k_htc_credit_report
);
331 if (record
->hdr
.len
< len
) {
332 ath10k_warn(ar
, "Credit report too long\n");
336 ath10k_htc_process_credit_report(htc
,
337 record
->credit_report
,
341 case ATH10K_HTC_RECORD_LOOKAHEAD
:
342 len
= sizeof(struct ath10k_htc_lookahead_report
);
343 if (record
->hdr
.len
< len
) {
344 ath10k_warn(ar
, "Lookahead report too long\n");
348 status
= ath10k_htc_process_lookahead(htc
,
349 record
->lookahead_report
,
353 next_lookaheads_len
);
355 case ATH10K_HTC_RECORD_LOOKAHEAD_BUNDLE
:
356 bundle
= record
->lookahead_bundle
;
357 status
= ath10k_htc_process_lookahead_bundle(htc
,
362 next_lookaheads_len
);
365 ath10k_warn(ar
, "Unhandled record: id:%d length:%d\n",
366 record
->hdr
.id
, record
->hdr
.len
);
373 /* multiple records may be present in a trailer */
374 buffer
+= sizeof(record
->hdr
) + record
->hdr
.len
;
375 length
-= sizeof(record
->hdr
) + record
->hdr
.len
;
379 ath10k_dbg_dump(ar
, ATH10K_DBG_HTC
, "htc rx bad trailer", "",
380 orig_buffer
, orig_length
);
384 EXPORT_SYMBOL(ath10k_htc_process_trailer
);
386 void ath10k_htc_rx_completion_handler(struct ath10k
*ar
, struct sk_buff
*skb
)
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(ar
, "HTC Rx: invalid eid %d\n", eid
);
405 ath10k_dbg_dump(ar
, ATH10K_DBG_HTC
, "htc bad header", "",
410 ep
= &htc
->endpoint
[eid
];
412 payload_len
= __le16_to_cpu(hdr
->len
);
414 if (payload_len
+ sizeof(*hdr
) > ATH10K_HTC_MAX_LEN
) {
415 ath10k_warn(ar
, "HTC rx frame too long, len: %zu\n",
416 payload_len
+ sizeof(*hdr
));
417 ath10k_dbg_dump(ar
, ATH10K_DBG_HTC
, "htc bad rx pkt len", "",
422 if (skb
->len
< payload_len
) {
423 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
424 "HTC Rx: insufficient length, got %d, expected %d\n",
425 skb
->len
, payload_len
);
426 ath10k_dbg_dump(ar
, ATH10K_DBG_HTC
, "htc bad rx pkt len",
427 "", hdr
, sizeof(*hdr
));
431 /* get flags to check for trailer */
432 trailer_present
= hdr
->flags
& ATH10K_HTC_FLAG_TRAILER_PRESENT
;
433 if (trailer_present
) {
436 trailer_len
= hdr
->trailer_len
;
437 min_len
= sizeof(struct ath10k_ath10k_htc_record_hdr
);
439 if ((trailer_len
< min_len
) ||
440 (trailer_len
> payload_len
)) {
441 ath10k_warn(ar
, "Invalid trailer length: %d\n",
447 trailer
+= sizeof(*hdr
);
448 trailer
+= payload_len
;
449 trailer
-= trailer_len
;
450 status
= ath10k_htc_process_trailer(htc
, trailer
,
451 trailer_len
, hdr
->eid
,
456 skb_trim(skb
, skb
->len
- trailer_len
);
459 if (((int)payload_len
- (int)trailer_len
) <= 0)
460 /* zero length packet with trailer data, just drop these */
463 ath10k_dbg(ar
, ATH10K_DBG_HTC
, "htc rx completion ep %d skb %pK\n",
465 ep
->ep_ops
.ep_rx_complete(ar
, skb
);
467 /* skb is now owned by the rx completion handler */
472 EXPORT_SYMBOL(ath10k_htc_rx_completion_handler
);
474 static void ath10k_htc_control_rx_complete(struct ath10k
*ar
,
477 struct ath10k_htc
*htc
= &ar
->htc
;
478 struct ath10k_htc_msg
*msg
= (struct ath10k_htc_msg
*)skb
->data
;
480 switch (__le16_to_cpu(msg
->hdr
.message_id
)) {
481 case ATH10K_HTC_MSG_READY_ID
:
482 case ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID
:
483 /* handle HTC control message */
484 if (completion_done(&htc
->ctl_resp
)) {
485 /* this is a fatal error, target should not be
486 * sending unsolicited messages on the ep 0
488 ath10k_warn(ar
, "HTC rx ctrl still processing\n");
489 complete(&htc
->ctl_resp
);
493 htc
->control_resp_len
=
495 ATH10K_HTC_MAX_CTRL_MSG_LEN
);
497 memcpy(htc
->control_resp_buffer
, skb
->data
,
498 htc
->control_resp_len
);
500 complete(&htc
->ctl_resp
);
502 case ATH10K_HTC_MSG_SEND_SUSPEND_COMPLETE
:
503 htc
->htc_ops
.target_send_suspend_complete(ar
);
506 ath10k_warn(ar
, "ignoring unsolicited htc ep0 event\n");
518 static const char *htc_service_name(enum ath10k_htc_svc_id id
)
521 case ATH10K_HTC_SVC_ID_RESERVED
:
523 case ATH10K_HTC_SVC_ID_RSVD_CTRL
:
525 case ATH10K_HTC_SVC_ID_WMI_CONTROL
:
527 case ATH10K_HTC_SVC_ID_WMI_DATA_BE
:
529 case ATH10K_HTC_SVC_ID_WMI_DATA_BK
:
531 case ATH10K_HTC_SVC_ID_WMI_DATA_VI
:
533 case ATH10K_HTC_SVC_ID_WMI_DATA_VO
:
535 case ATH10K_HTC_SVC_ID_NMI_CONTROL
:
536 return "NMI Control";
537 case ATH10K_HTC_SVC_ID_NMI_DATA
:
539 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG
:
541 case ATH10K_HTC_SVC_ID_HTT_DATA2_MSG
:
543 case ATH10K_HTC_SVC_ID_HTT_DATA3_MSG
:
545 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
:
547 case ATH10K_HTC_SVC_ID_HTT_LOG_MSG
:
554 static void ath10k_htc_reset_endpoint_states(struct ath10k_htc
*htc
)
556 struct ath10k_htc_ep
*ep
;
559 for (i
= ATH10K_HTC_EP_0
; i
< ATH10K_HTC_EP_COUNT
; i
++) {
560 ep
= &htc
->endpoint
[i
];
561 ep
->service_id
= ATH10K_HTC_SVC_ID_UNUSED
;
562 ep
->max_ep_message_len
= 0;
563 ep
->max_tx_queue_depth
= 0;
566 ep
->tx_credit_flow_enabled
= true;
570 static u8
ath10k_htc_get_credit_allocation(struct ath10k_htc
*htc
,
575 /* The WMI control service is the only service with flow control.
576 * Let it have all transmit credits.
578 if (service_id
== ATH10K_HTC_SVC_ID_WMI_CONTROL
)
579 allocation
= htc
->total_transmit_credits
;
584 int ath10k_htc_wait_target(struct ath10k_htc
*htc
)
586 struct ath10k
*ar
= htc
->ar
;
588 unsigned long time_left
;
589 struct ath10k_htc_msg
*msg
;
592 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
593 ATH10K_HTC_WAIT_TIMEOUT_HZ
);
595 /* Workaround: In some cases the PCI HIF doesn't
596 * receive interrupt for the control response message
597 * even if the buffer was completed. It is suspected
598 * iomap writes unmasking PCI CE irqs aren't propagated
599 * properly in KVM PCI-passthrough sometimes.
601 ath10k_warn(ar
, "failed to receive control response completion, polling..\n");
603 for (i
= 0; i
< CE_COUNT
; i
++)
604 ath10k_hif_send_complete_check(htc
->ar
, i
, 1);
607 wait_for_completion_timeout(&htc
->ctl_resp
,
608 ATH10K_HTC_WAIT_TIMEOUT_HZ
);
615 ath10k_err(ar
, "ctl_resp never came in (%d)\n", status
);
619 if (htc
->control_resp_len
< sizeof(msg
->hdr
) + sizeof(msg
->ready
)) {
620 ath10k_err(ar
, "Invalid HTC ready msg len:%d\n",
621 htc
->control_resp_len
);
625 msg
= (struct ath10k_htc_msg
*)htc
->control_resp_buffer
;
626 message_id
= __le16_to_cpu(msg
->hdr
.message_id
);
628 if (message_id
!= ATH10K_HTC_MSG_READY_ID
) {
629 ath10k_err(ar
, "Invalid HTC ready msg: 0x%x\n", message_id
);
633 htc
->total_transmit_credits
= __le16_to_cpu(msg
->ready
.credit_count
);
634 htc
->target_credit_size
= __le16_to_cpu(msg
->ready
.credit_size
);
636 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
637 "Target ready! transmit resources: %d size:%d\n",
638 htc
->total_transmit_credits
,
639 htc
->target_credit_size
);
641 if ((htc
->total_transmit_credits
== 0) ||
642 (htc
->target_credit_size
== 0)) {
643 ath10k_err(ar
, "Invalid credit size received\n");
647 /* The only way to determine if the ready message is an extended
648 * message is from the size.
650 if (htc
->control_resp_len
>=
651 sizeof(msg
->hdr
) + sizeof(msg
->ready_ext
)) {
652 htc
->max_msgs_per_htc_bundle
=
653 min_t(u8
, msg
->ready_ext
.max_msgs_per_htc_bundle
,
654 HTC_HOST_MAX_MSG_PER_RX_BUNDLE
);
655 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
656 "Extended ready message. RX bundle size: %d\n",
657 htc
->max_msgs_per_htc_bundle
);
663 int ath10k_htc_connect_service(struct ath10k_htc
*htc
,
664 struct ath10k_htc_svc_conn_req
*conn_req
,
665 struct ath10k_htc_svc_conn_resp
*conn_resp
)
667 struct ath10k
*ar
= htc
->ar
;
668 struct ath10k_htc_msg
*msg
;
669 struct ath10k_htc_conn_svc
*req_msg
;
670 struct ath10k_htc_conn_svc_response resp_msg_dummy
;
671 struct ath10k_htc_conn_svc_response
*resp_msg
= &resp_msg_dummy
;
672 enum ath10k_htc_ep_id assigned_eid
= ATH10K_HTC_EP_COUNT
;
673 struct ath10k_htc_ep
*ep
;
675 unsigned int max_msg_size
= 0;
677 unsigned long time_left
;
678 bool disable_credit_flow_ctrl
= false;
679 u16 message_id
, service_id
, flags
= 0;
682 /* special case for HTC pseudo control service */
683 if (conn_req
->service_id
== ATH10K_HTC_SVC_ID_RSVD_CTRL
) {
684 disable_credit_flow_ctrl
= true;
685 assigned_eid
= ATH10K_HTC_EP_0
;
686 max_msg_size
= ATH10K_HTC_MAX_CTRL_MSG_LEN
;
687 memset(&resp_msg_dummy
, 0, sizeof(resp_msg_dummy
));
691 tx_alloc
= ath10k_htc_get_credit_allocation(htc
,
692 conn_req
->service_id
);
694 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
695 "boot htc service %s does not allocate target credits\n",
696 htc_service_name(conn_req
->service_id
));
698 skb
= ath10k_htc_build_tx_ctrl_skb(htc
->ar
);
700 ath10k_err(ar
, "Failed to allocate HTC packet\n");
704 length
= sizeof(msg
->hdr
) + sizeof(msg
->connect_service
);
705 skb_put(skb
, length
);
706 memset(skb
->data
, 0, length
);
708 msg
= (struct ath10k_htc_msg
*)skb
->data
;
709 msg
->hdr
.message_id
=
710 __cpu_to_le16(ATH10K_HTC_MSG_CONNECT_SERVICE_ID
);
712 flags
|= SM(tx_alloc
, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC
);
714 /* Only enable credit flow control for WMI ctrl service */
715 if (conn_req
->service_id
!= ATH10K_HTC_SVC_ID_WMI_CONTROL
) {
716 flags
|= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL
;
717 disable_credit_flow_ctrl
= true;
720 req_msg
= &msg
->connect_service
;
721 req_msg
->flags
= __cpu_to_le16(flags
);
722 req_msg
->service_id
= __cpu_to_le16(conn_req
->service_id
);
724 reinit_completion(&htc
->ctl_resp
);
726 status
= ath10k_htc_send(htc
, ATH10K_HTC_EP_0
, skb
);
732 /* wait for response */
733 time_left
= wait_for_completion_timeout(&htc
->ctl_resp
,
734 ATH10K_HTC_CONN_SVC_TIMEOUT_HZ
);
736 ath10k_err(ar
, "Service connect timeout\n");
740 /* we controlled the buffer creation, it's aligned */
741 msg
= (struct ath10k_htc_msg
*)htc
->control_resp_buffer
;
742 resp_msg
= &msg
->connect_service_response
;
743 message_id
= __le16_to_cpu(msg
->hdr
.message_id
);
744 service_id
= __le16_to_cpu(resp_msg
->service_id
);
746 if ((message_id
!= ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID
) ||
747 (htc
->control_resp_len
< sizeof(msg
->hdr
) +
748 sizeof(msg
->connect_service_response
))) {
749 ath10k_err(ar
, "Invalid resp message ID 0x%x", message_id
);
753 ath10k_dbg(ar
, ATH10K_DBG_HTC
,
754 "HTC Service %s connect response: status: 0x%x, assigned ep: 0x%x\n",
755 htc_service_name(service_id
),
756 resp_msg
->status
, resp_msg
->eid
);
758 conn_resp
->connect_resp_code
= resp_msg
->status
;
760 /* check response status */
761 if (resp_msg
->status
!= ATH10K_HTC_CONN_SVC_STATUS_SUCCESS
) {
762 ath10k_err(ar
, "HTC Service %s connect request failed: 0x%x)\n",
763 htc_service_name(service_id
),
768 assigned_eid
= (enum ath10k_htc_ep_id
)resp_msg
->eid
;
769 max_msg_size
= __le16_to_cpu(resp_msg
->max_msg_size
);
773 if (assigned_eid
>= ATH10K_HTC_EP_COUNT
)
776 if (max_msg_size
== 0)
779 ep
= &htc
->endpoint
[assigned_eid
];
780 ep
->eid
= assigned_eid
;
782 if (ep
->service_id
!= ATH10K_HTC_SVC_ID_UNUSED
)
785 /* return assigned endpoint to caller */
786 conn_resp
->eid
= assigned_eid
;
787 conn_resp
->max_msg_len
= __le16_to_cpu(resp_msg
->max_msg_size
);
789 /* setup the endpoint */
790 ep
->service_id
= conn_req
->service_id
;
791 ep
->max_tx_queue_depth
= conn_req
->max_send_queue_depth
;
792 ep
->max_ep_message_len
= __le16_to_cpu(resp_msg
->max_msg_size
);
793 ep
->tx_credits
= tx_alloc
;
795 /* copy all the callbacks */
796 ep
->ep_ops
= conn_req
->ep_ops
;
798 status
= ath10k_hif_map_service_to_pipe(htc
->ar
,
803 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "unsupported HTC service id: %d\n",
808 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
809 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
810 htc_service_name(ep
->service_id
), ep
->ul_pipe_id
,
811 ep
->dl_pipe_id
, ep
->eid
);
813 if (disable_credit_flow_ctrl
&& ep
->tx_credit_flow_enabled
) {
814 ep
->tx_credit_flow_enabled
= false;
815 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
816 "boot htc service '%s' eid %d TX flow control disabled\n",
817 htc_service_name(ep
->service_id
), assigned_eid
);
823 struct sk_buff
*ath10k_htc_alloc_skb(struct ath10k
*ar
, int size
)
827 skb
= dev_alloc_skb(size
+ sizeof(struct ath10k_htc_hdr
));
831 skb_reserve(skb
, sizeof(struct ath10k_htc_hdr
));
833 /* FW/HTC requires 4-byte aligned streams */
834 if (!IS_ALIGNED((unsigned long)skb
->data
, 4))
835 ath10k_warn(ar
, "Unaligned HTC tx skb\n");
840 static void ath10k_htc_pktlog_process_rx(struct ath10k
*ar
, struct sk_buff
*skb
)
842 trace_ath10k_htt_pktlog(ar
, skb
->data
, skb
->len
);
843 dev_kfree_skb_any(skb
);
846 static int ath10k_htc_pktlog_connect(struct ath10k
*ar
)
848 struct ath10k_htc_svc_conn_resp conn_resp
;
849 struct ath10k_htc_svc_conn_req conn_req
;
852 memset(&conn_req
, 0, sizeof(conn_req
));
853 memset(&conn_resp
, 0, sizeof(conn_resp
));
855 conn_req
.ep_ops
.ep_tx_complete
= NULL
;
856 conn_req
.ep_ops
.ep_rx_complete
= ath10k_htc_pktlog_process_rx
;
857 conn_req
.ep_ops
.ep_tx_credits
= NULL
;
859 /* connect to control service */
860 conn_req
.service_id
= ATH10K_HTC_SVC_ID_HTT_LOG_MSG
;
861 status
= ath10k_htc_connect_service(&ar
->htc
, &conn_req
, &conn_resp
);
863 ath10k_warn(ar
, "failed to connect to PKTLOG service: %d\n",
871 static bool ath10k_htc_pktlog_svc_supported(struct ath10k
*ar
)
877 status
= ath10k_hif_map_service_to_pipe(ar
, ATH10K_HTC_SVC_ID_HTT_LOG_MSG
,
881 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "unsupported HTC pktlog service id: %d\n",
882 ATH10K_HTC_SVC_ID_HTT_LOG_MSG
);
890 int ath10k_htc_start(struct ath10k_htc
*htc
)
892 struct ath10k
*ar
= htc
->ar
;
895 struct ath10k_htc_msg
*msg
;
897 skb
= ath10k_htc_build_tx_ctrl_skb(htc
->ar
);
901 skb_put(skb
, sizeof(msg
->hdr
) + sizeof(msg
->setup_complete_ext
));
902 memset(skb
->data
, 0, skb
->len
);
904 msg
= (struct ath10k_htc_msg
*)skb
->data
;
905 msg
->hdr
.message_id
=
906 __cpu_to_le16(ATH10K_HTC_MSG_SETUP_COMPLETE_EX_ID
);
908 if (ar
->hif
.bus
== ATH10K_BUS_SDIO
) {
909 /* Extra setup params used by SDIO */
910 msg
->setup_complete_ext
.flags
=
911 __cpu_to_le32(ATH10K_HTC_SETUP_COMPLETE_FLAGS_RX_BNDL_EN
);
912 msg
->setup_complete_ext
.max_msgs_per_bundled_recv
=
913 htc
->max_msgs_per_htc_bundle
;
915 ath10k_dbg(ar
, ATH10K_DBG_HTC
, "HTC is using TX credit flow control\n");
917 status
= ath10k_htc_send(htc
, ATH10K_HTC_EP_0
, skb
);
923 if (ath10k_htc_pktlog_svc_supported(ar
)) {
924 status
= ath10k_htc_pktlog_connect(ar
);
926 ath10k_err(ar
, "failed to connect to pktlog: %d\n", status
);
934 /* registered target arrival callback from the HIF layer */
935 int ath10k_htc_init(struct ath10k
*ar
)
938 struct ath10k_htc
*htc
= &ar
->htc
;
939 struct ath10k_htc_svc_conn_req conn_req
;
940 struct ath10k_htc_svc_conn_resp conn_resp
;
942 spin_lock_init(&htc
->tx_lock
);
944 ath10k_htc_reset_endpoint_states(htc
);
948 /* setup our pseudo HTC control endpoint connection */
949 memset(&conn_req
, 0, sizeof(conn_req
));
950 memset(&conn_resp
, 0, sizeof(conn_resp
));
951 conn_req
.ep_ops
.ep_tx_complete
= ath10k_htc_control_tx_complete
;
952 conn_req
.ep_ops
.ep_rx_complete
= ath10k_htc_control_rx_complete
;
953 conn_req
.max_send_queue_depth
= ATH10K_NUM_CONTROL_TX_BUFFERS
;
954 conn_req
.service_id
= ATH10K_HTC_SVC_ID_RSVD_CTRL
;
956 /* connect fake service */
957 status
= ath10k_htc_connect_service(htc
, &conn_req
, &conn_resp
);
959 ath10k_err(ar
, "could not connect to htc service (%d)\n",
964 init_completion(&htc
->ctl_resp
);