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
;
108 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 int ath10k_htc_send(struct ath10k_htc
*htc
,
121 enum ath10k_htc_ep_id eid
,
124 struct ath10k_htc_ep
*ep
= &htc
->endpoint
[eid
];
128 if (htc
->ar
->state
== ATH10K_STATE_WEDGED
)
131 if (eid
>= ATH10K_HTC_EP_COUNT
) {
132 ath10k_warn("Invalid endpoint id: %d\n", eid
);
136 /* FIXME: This looks ugly, can we fix it? */
137 spin_lock_bh(&htc
->tx_lock
);
139 spin_unlock_bh(&htc
->tx_lock
);
142 spin_unlock_bh(&htc
->tx_lock
);
144 skb_push(skb
, sizeof(struct ath10k_htc_hdr
));
146 if (ep
->tx_credit_flow_enabled
) {
147 credits
= DIV_ROUND_UP(skb
->len
, htc
->target_credit_size
);
148 spin_lock_bh(&htc
->tx_lock
);
149 if (ep
->tx_credits
< credits
) {
150 spin_unlock_bh(&htc
->tx_lock
);
154 ep
->tx_credits
-= credits
;
155 spin_unlock_bh(&htc
->tx_lock
);
158 ath10k_htc_prepare_tx_skb(ep
, skb
);
160 ret
= ath10k_skb_map(htc
->ar
->dev
, skb
);
164 ret
= ath10k_hif_send_head(htc
->ar
, ep
->ul_pipe_id
, ep
->eid
,
172 ath10k_skb_unmap(htc
->ar
->dev
, skb
);
174 if (ep
->tx_credit_flow_enabled
) {
175 spin_lock_bh(&htc
->tx_lock
);
176 ep
->tx_credits
+= credits
;
177 spin_unlock_bh(&htc
->tx_lock
);
179 if (ep
->ep_ops
.ep_tx_credits
)
180 ep
->ep_ops
.ep_tx_credits(htc
->ar
);
183 skb_pull(skb
, sizeof(struct ath10k_htc_hdr
));
187 static int ath10k_htc_tx_completion_handler(struct ath10k
*ar
,
191 struct ath10k_htc
*htc
= &ar
->htc
;
192 struct ath10k_htc_ep
*ep
= &htc
->endpoint
[eid
];
194 ath10k_htc_notify_tx_completion(ep
, skb
);
195 /* the skb now belongs to the completion handler */
205 ath10k_htc_process_credit_report(struct ath10k_htc
*htc
,
206 const struct ath10k_htc_credit_report
*report
,
208 enum ath10k_htc_ep_id eid
)
210 struct ath10k_htc_ep
*ep
;
213 if (len
% sizeof(*report
))
214 ath10k_warn("Uneven credit report len %d", len
);
216 n_reports
= len
/ sizeof(*report
);
218 spin_lock_bh(&htc
->tx_lock
);
219 for (i
= 0; i
< n_reports
; i
++, report
++) {
220 if (report
->eid
>= ATH10K_HTC_EP_COUNT
)
223 ath10k_dbg(ATH10K_DBG_HTC
, "ep %d got %d credits\n",
224 report
->eid
, report
->credits
);
226 ep
= &htc
->endpoint
[report
->eid
];
227 ep
->tx_credits
+= report
->credits
;
229 if (ep
->ep_ops
.ep_tx_credits
) {
230 spin_unlock_bh(&htc
->tx_lock
);
231 ep
->ep_ops
.ep_tx_credits(htc
->ar
);
232 spin_lock_bh(&htc
->tx_lock
);
235 spin_unlock_bh(&htc
->tx_lock
);
238 static int ath10k_htc_process_trailer(struct ath10k_htc
*htc
,
241 enum ath10k_htc_ep_id src_eid
)
244 struct ath10k_htc_record
*record
;
249 orig_buffer
= buffer
;
250 orig_length
= length
;
253 record
= (struct ath10k_htc_record
*)buffer
;
255 if (length
< sizeof(record
->hdr
)) {
260 if (record
->hdr
.len
> length
) {
261 /* no room left in buffer for record */
262 ath10k_warn("Invalid record length: %d\n",
268 switch (record
->hdr
.id
) {
269 case ATH10K_HTC_RECORD_CREDITS
:
270 len
= sizeof(struct ath10k_htc_credit_report
);
271 if (record
->hdr
.len
< len
) {
272 ath10k_warn("Credit report too long\n");
276 ath10k_htc_process_credit_report(htc
,
277 record
->credit_report
,
282 ath10k_warn("Unhandled record: id:%d length:%d\n",
283 record
->hdr
.id
, record
->hdr
.len
);
290 /* multiple records may be present in a trailer */
291 buffer
+= sizeof(record
->hdr
) + record
->hdr
.len
;
292 length
-= sizeof(record
->hdr
) + record
->hdr
.len
;
296 ath10k_dbg_dump(ATH10K_DBG_HTC
, "htc rx bad trailer", "",
297 orig_buffer
, orig_length
);
302 static int ath10k_htc_rx_completion_handler(struct ath10k
*ar
,
307 struct ath10k_htc
*htc
= &ar
->htc
;
308 struct ath10k_htc_hdr
*hdr
;
309 struct ath10k_htc_ep
*ep
;
314 bool trailer_present
;
316 hdr
= (struct ath10k_htc_hdr
*)skb
->data
;
317 skb_pull(skb
, sizeof(*hdr
));
321 if (eid
>= ATH10K_HTC_EP_COUNT
) {
322 ath10k_warn("HTC Rx: invalid eid %d\n", eid
);
323 ath10k_dbg_dump(ATH10K_DBG_HTC
, "htc bad header", "",
329 ep
= &htc
->endpoint
[eid
];
332 * If this endpoint that received a message from the target has
333 * a to-target HIF pipe whose send completions are polled rather
334 * than interrupt-driven, this is a good point to ask HIF to check
335 * whether it has any completed sends to handle.
337 if (ep
->ul_is_polled
)
338 ath10k_htc_send_complete_check(ep
, 1);
340 payload_len
= __le16_to_cpu(hdr
->len
);
342 if (payload_len
+ sizeof(*hdr
) > ATH10K_HTC_MAX_LEN
) {
343 ath10k_warn("HTC rx frame too long, len: %zu\n",
344 payload_len
+ sizeof(*hdr
));
345 ath10k_dbg_dump(ATH10K_DBG_HTC
, "htc bad rx pkt len", "",
351 if (skb
->len
< payload_len
) {
352 ath10k_dbg(ATH10K_DBG_HTC
,
353 "HTC Rx: insufficient length, got %d, expected %d\n",
354 skb
->len
, payload_len
);
355 ath10k_dbg_dump(ATH10K_DBG_HTC
, "htc bad rx pkt len",
356 "", hdr
, sizeof(*hdr
));
361 /* get flags to check for trailer */
362 trailer_present
= hdr
->flags
& ATH10K_HTC_FLAG_TRAILER_PRESENT
;
363 if (trailer_present
) {
366 trailer_len
= hdr
->trailer_len
;
367 min_len
= sizeof(struct ath10k_ath10k_htc_record_hdr
);
369 if ((trailer_len
< min_len
) ||
370 (trailer_len
> payload_len
)) {
371 ath10k_warn("Invalid trailer length: %d\n",
378 trailer
+= sizeof(*hdr
);
379 trailer
+= payload_len
;
380 trailer
-= trailer_len
;
381 status
= ath10k_htc_process_trailer(htc
, trailer
,
382 trailer_len
, hdr
->eid
);
386 skb_trim(skb
, skb
->len
- trailer_len
);
389 if (((int)payload_len
- (int)trailer_len
) <= 0)
390 /* zero length packet with trailer data, just drop these */
393 if (eid
== ATH10K_HTC_EP_0
) {
394 struct ath10k_htc_msg
*msg
= (struct ath10k_htc_msg
*)skb
->data
;
396 switch (__le16_to_cpu(msg
->hdr
.message_id
)) {
398 /* handle HTC control message */
399 if (completion_done(&htc
->ctl_resp
)) {
401 * this is a fatal error, target should not be
402 * sending unsolicited messages on the ep 0
404 ath10k_warn("HTC rx ctrl still processing\n");
406 complete(&htc
->ctl_resp
);
410 htc
->control_resp_len
=
412 ATH10K_HTC_MAX_CTRL_MSG_LEN
);
414 memcpy(htc
->control_resp_buffer
, skb
->data
,
415 htc
->control_resp_len
);
417 complete(&htc
->ctl_resp
);
419 case ATH10K_HTC_MSG_SEND_SUSPEND_COMPLETE
:
420 htc
->htc_ops
.target_send_suspend_complete(ar
);
425 ath10k_dbg(ATH10K_DBG_HTC
, "htc rx completion ep %d skb %p\n",
427 ep
->ep_ops
.ep_rx_complete(ar
, skb
);
429 /* skb is now owned by the rx completion handler */
437 static void ath10k_htc_control_rx_complete(struct ath10k
*ar
,
440 /* This is unexpected. FW is not supposed to send regular rx on this
442 ath10k_warn("unexpected htc rx\n");
450 static const char *htc_service_name(enum ath10k_htc_svc_id id
)
453 case ATH10K_HTC_SVC_ID_RESERVED
:
455 case ATH10K_HTC_SVC_ID_RSVD_CTRL
:
457 case ATH10K_HTC_SVC_ID_WMI_CONTROL
:
459 case ATH10K_HTC_SVC_ID_WMI_DATA_BE
:
461 case ATH10K_HTC_SVC_ID_WMI_DATA_BK
:
463 case ATH10K_HTC_SVC_ID_WMI_DATA_VI
:
465 case ATH10K_HTC_SVC_ID_WMI_DATA_VO
:
467 case ATH10K_HTC_SVC_ID_NMI_CONTROL
:
468 return "NMI Control";
469 case ATH10K_HTC_SVC_ID_NMI_DATA
:
471 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG
:
473 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
:
480 static void ath10k_htc_reset_endpoint_states(struct ath10k_htc
*htc
)
482 struct ath10k_htc_ep
*ep
;
485 for (i
= ATH10K_HTC_EP_0
; i
< ATH10K_HTC_EP_COUNT
; i
++) {
486 ep
= &htc
->endpoint
[i
];
487 ep
->service_id
= ATH10K_HTC_SVC_ID_UNUSED
;
488 ep
->max_ep_message_len
= 0;
489 ep
->max_tx_queue_depth
= 0;
492 ep
->tx_credit_flow_enabled
= true;
496 static void ath10k_htc_setup_target_buffer_assignments(struct ath10k_htc
*htc
)
498 struct ath10k_htc_svc_tx_credits
*entry
;
500 entry
= &htc
->service_tx_alloc
[0];
503 * for PCIE allocate all credists/HTC buffers to WMI.
504 * no buffers are used/required for data. data always
508 entry
->service_id
= ATH10K_HTC_SVC_ID_WMI_CONTROL
;
509 entry
->credit_allocation
= htc
->total_transmit_credits
;
512 static u8
ath10k_htc_get_credit_allocation(struct ath10k_htc
*htc
,
518 for (i
= 0; i
< ATH10K_HTC_EP_COUNT
; i
++) {
519 if (htc
->service_tx_alloc
[i
].service_id
== service_id
)
521 htc
->service_tx_alloc
[i
].credit_allocation
;
527 int ath10k_htc_wait_target(struct ath10k_htc
*htc
)
530 struct ath10k_htc_svc_conn_req conn_req
;
531 struct ath10k_htc_svc_conn_resp conn_resp
;
532 struct ath10k_htc_msg
*msg
;
537 INIT_COMPLETION(htc
->ctl_resp
);
539 status
= ath10k_hif_start(htc
->ar
);
541 ath10k_err("could not start HIF (%d)\n", status
);
545 status
= wait_for_completion_timeout(&htc
->ctl_resp
,
546 ATH10K_HTC_WAIT_TIMEOUT_HZ
);
551 ath10k_err("ctl_resp never came in (%d)\n", status
);
555 if (htc
->control_resp_len
< sizeof(msg
->hdr
) + sizeof(msg
->ready
)) {
556 ath10k_err("Invalid HTC ready msg len:%d\n",
557 htc
->control_resp_len
);
563 msg
= (struct ath10k_htc_msg
*)htc
->control_resp_buffer
;
564 message_id
= __le16_to_cpu(msg
->hdr
.message_id
);
565 credit_count
= __le16_to_cpu(msg
->ready
.credit_count
);
566 credit_size
= __le16_to_cpu(msg
->ready
.credit_size
);
568 if (message_id
!= ATH10K_HTC_MSG_READY_ID
) {
569 ath10k_err("Invalid HTC ready msg: 0x%x\n", message_id
);
574 htc
->total_transmit_credits
= credit_count
;
575 htc
->target_credit_size
= credit_size
;
577 ath10k_dbg(ATH10K_DBG_HTC
,
578 "Target ready! transmit resources: %d size:%d\n",
579 htc
->total_transmit_credits
,
580 htc
->target_credit_size
);
582 if ((htc
->total_transmit_credits
== 0) ||
583 (htc
->target_credit_size
== 0)) {
585 ath10k_err("Invalid credit size received\n");
589 ath10k_htc_setup_target_buffer_assignments(htc
);
591 /* setup our pseudo HTC control endpoint connection */
592 memset(&conn_req
, 0, sizeof(conn_req
));
593 memset(&conn_resp
, 0, sizeof(conn_resp
));
594 conn_req
.ep_ops
.ep_tx_complete
= ath10k_htc_control_tx_complete
;
595 conn_req
.ep_ops
.ep_rx_complete
= ath10k_htc_control_rx_complete
;
596 conn_req
.max_send_queue_depth
= ATH10K_NUM_CONTROL_TX_BUFFERS
;
597 conn_req
.service_id
= ATH10K_HTC_SVC_ID_RSVD_CTRL
;
599 /* connect fake service */
600 status
= ath10k_htc_connect_service(htc
, &conn_req
, &conn_resp
);
602 ath10k_err("could not connect to htc service (%d)\n", status
);
608 ath10k_hif_stop(htc
->ar
);
613 int ath10k_htc_connect_service(struct ath10k_htc
*htc
,
614 struct ath10k_htc_svc_conn_req
*conn_req
,
615 struct ath10k_htc_svc_conn_resp
*conn_resp
)
617 struct ath10k_htc_msg
*msg
;
618 struct ath10k_htc_conn_svc
*req_msg
;
619 struct ath10k_htc_conn_svc_response resp_msg_dummy
;
620 struct ath10k_htc_conn_svc_response
*resp_msg
= &resp_msg_dummy
;
621 enum ath10k_htc_ep_id assigned_eid
= ATH10K_HTC_EP_COUNT
;
622 struct ath10k_htc_ep
*ep
;
624 unsigned int max_msg_size
= 0;
626 bool disable_credit_flow_ctrl
= false;
627 u16 message_id
, service_id
, flags
= 0;
630 /* special case for HTC pseudo control service */
631 if (conn_req
->service_id
== ATH10K_HTC_SVC_ID_RSVD_CTRL
) {
632 disable_credit_flow_ctrl
= true;
633 assigned_eid
= ATH10K_HTC_EP_0
;
634 max_msg_size
= ATH10K_HTC_MAX_CTRL_MSG_LEN
;
635 memset(&resp_msg_dummy
, 0, sizeof(resp_msg_dummy
));
639 tx_alloc
= ath10k_htc_get_credit_allocation(htc
,
640 conn_req
->service_id
);
642 ath10k_dbg(ATH10K_DBG_BOOT
,
643 "boot htc service %s does not allocate target credits\n",
644 htc_service_name(conn_req
->service_id
));
646 skb
= ath10k_htc_build_tx_ctrl_skb(htc
->ar
);
648 ath10k_err("Failed to allocate HTC packet\n");
652 length
= sizeof(msg
->hdr
) + sizeof(msg
->connect_service
);
653 skb_put(skb
, length
);
654 memset(skb
->data
, 0, length
);
656 msg
= (struct ath10k_htc_msg
*)skb
->data
;
657 msg
->hdr
.message_id
=
658 __cpu_to_le16(ATH10K_HTC_MSG_CONNECT_SERVICE_ID
);
660 flags
|= SM(tx_alloc
, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC
);
662 /* Only enable credit flow control for WMI ctrl service */
663 if (conn_req
->service_id
!= ATH10K_HTC_SVC_ID_WMI_CONTROL
) {
664 flags
|= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL
;
665 disable_credit_flow_ctrl
= true;
668 req_msg
= &msg
->connect_service
;
669 req_msg
->flags
= __cpu_to_le16(flags
);
670 req_msg
->service_id
= __cpu_to_le16(conn_req
->service_id
);
672 INIT_COMPLETION(htc
->ctl_resp
);
674 status
= ath10k_htc_send(htc
, ATH10K_HTC_EP_0
, skb
);
680 /* wait for response */
681 status
= wait_for_completion_timeout(&htc
->ctl_resp
,
682 ATH10K_HTC_CONN_SVC_TIMEOUT_HZ
);
686 ath10k_err("Service connect timeout: %d\n", status
);
690 /* we controlled the buffer creation, it's aligned */
691 msg
= (struct ath10k_htc_msg
*)htc
->control_resp_buffer
;
692 resp_msg
= &msg
->connect_service_response
;
693 message_id
= __le16_to_cpu(msg
->hdr
.message_id
);
694 service_id
= __le16_to_cpu(resp_msg
->service_id
);
696 if ((message_id
!= ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID
) ||
697 (htc
->control_resp_len
< sizeof(msg
->hdr
) +
698 sizeof(msg
->connect_service_response
))) {
699 ath10k_err("Invalid resp message ID 0x%x", message_id
);
703 ath10k_dbg(ATH10K_DBG_HTC
,
704 "HTC Service %s connect response: status: 0x%x, assigned ep: 0x%x\n",
705 htc_service_name(service_id
),
706 resp_msg
->status
, resp_msg
->eid
);
708 conn_resp
->connect_resp_code
= resp_msg
->status
;
710 /* check response status */
711 if (resp_msg
->status
!= ATH10K_HTC_CONN_SVC_STATUS_SUCCESS
) {
712 ath10k_err("HTC Service %s connect request failed: 0x%x)\n",
713 htc_service_name(service_id
),
718 assigned_eid
= (enum ath10k_htc_ep_id
)resp_msg
->eid
;
719 max_msg_size
= __le16_to_cpu(resp_msg
->max_msg_size
);
723 if (assigned_eid
>= ATH10K_HTC_EP_COUNT
)
726 if (max_msg_size
== 0)
729 ep
= &htc
->endpoint
[assigned_eid
];
730 ep
->eid
= assigned_eid
;
732 if (ep
->service_id
!= ATH10K_HTC_SVC_ID_UNUSED
)
735 /* return assigned endpoint to caller */
736 conn_resp
->eid
= assigned_eid
;
737 conn_resp
->max_msg_len
= __le16_to_cpu(resp_msg
->max_msg_size
);
739 /* setup the endpoint */
740 ep
->service_id
= conn_req
->service_id
;
741 ep
->max_tx_queue_depth
= conn_req
->max_send_queue_depth
;
742 ep
->max_ep_message_len
= __le16_to_cpu(resp_msg
->max_msg_size
);
743 ep
->tx_credits
= tx_alloc
;
744 ep
->tx_credit_size
= htc
->target_credit_size
;
745 ep
->tx_credits_per_max_message
= ep
->max_ep_message_len
/
746 htc
->target_credit_size
;
748 if (ep
->max_ep_message_len
% htc
->target_credit_size
)
749 ep
->tx_credits_per_max_message
++;
751 /* copy all the callbacks */
752 ep
->ep_ops
= conn_req
->ep_ops
;
754 status
= ath10k_hif_map_service_to_pipe(htc
->ar
,
763 ath10k_dbg(ATH10K_DBG_BOOT
,
764 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
765 htc_service_name(ep
->service_id
), ep
->ul_pipe_id
,
766 ep
->dl_pipe_id
, ep
->eid
);
768 ath10k_dbg(ATH10K_DBG_BOOT
,
769 "boot htc ep %d ul polled %d dl polled %d\n",
770 ep
->eid
, ep
->ul_is_polled
, ep
->dl_is_polled
);
772 if (disable_credit_flow_ctrl
&& ep
->tx_credit_flow_enabled
) {
773 ep
->tx_credit_flow_enabled
= false;
774 ath10k_dbg(ATH10K_DBG_BOOT
,
775 "boot htc service '%s' eid %d TX flow control disabled\n",
776 htc_service_name(ep
->service_id
), assigned_eid
);
782 struct sk_buff
*ath10k_htc_alloc_skb(int size
)
786 skb
= dev_alloc_skb(size
+ sizeof(struct ath10k_htc_hdr
));
788 ath10k_warn("could not allocate HTC tx skb\n");
792 skb_reserve(skb
, sizeof(struct ath10k_htc_hdr
));
794 /* FW/HTC requires 4-byte aligned streams */
795 if (!IS_ALIGNED((unsigned long)skb
->data
, 4))
796 ath10k_warn("Unaligned HTC tx skb\n");
801 int ath10k_htc_start(struct ath10k_htc
*htc
)
805 struct ath10k_htc_msg
*msg
;
807 skb
= ath10k_htc_build_tx_ctrl_skb(htc
->ar
);
811 skb_put(skb
, sizeof(msg
->hdr
) + sizeof(msg
->setup_complete_ext
));
812 memset(skb
->data
, 0, skb
->len
);
814 msg
= (struct ath10k_htc_msg
*)skb
->data
;
815 msg
->hdr
.message_id
=
816 __cpu_to_le16(ATH10K_HTC_MSG_SETUP_COMPLETE_EX_ID
);
818 ath10k_dbg(ATH10K_DBG_HTC
, "HTC is using TX credit flow control\n");
820 status
= ath10k_htc_send(htc
, ATH10K_HTC_EP_0
, skb
);
830 * stop HTC communications, i.e. stop interrupt reception, and flush all
833 void ath10k_htc_stop(struct ath10k_htc
*htc
)
835 spin_lock_bh(&htc
->tx_lock
);
837 spin_unlock_bh(&htc
->tx_lock
);
839 ath10k_hif_stop(htc
->ar
);
842 /* registered target arrival callback from the HIF layer */
843 int ath10k_htc_init(struct ath10k
*ar
)
845 struct ath10k_hif_cb htc_callbacks
;
846 struct ath10k_htc_ep
*ep
= NULL
;
847 struct ath10k_htc
*htc
= &ar
->htc
;
849 spin_lock_init(&htc
->tx_lock
);
851 htc
->stopped
= false;
852 ath10k_htc_reset_endpoint_states(htc
);
854 /* setup HIF layer callbacks */
855 htc_callbacks
.rx_completion
= ath10k_htc_rx_completion_handler
;
856 htc_callbacks
.tx_completion
= ath10k_htc_tx_completion_handler
;
859 /* Get HIF default pipe for HTC message exchange */
860 ep
= &htc
->endpoint
[ATH10K_HTC_EP_0
];
862 ath10k_hif_set_callbacks(ar
, &htc_callbacks
);
863 ath10k_hif_get_default_pipe(ar
, &ep
->ul_pipe_id
, &ep
->dl_pipe_id
);
865 init_completion(&htc
->ctl_resp
);