1 /* SPDX-License-Identifier: ISC */
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2015,2017 Qualcomm Atheros, Inc.
10 #include <linux/kernel.h>
15 /* Types of fw logging mode */
17 ATH10K_ENABLE_FW_LOG_DIAG
,
18 ATH10K_ENABLE_FW_LOG_CE
,
21 struct ath10k_hif_sg_item
{
23 void *transfer_context
; /* NULL = tx completion callback not called */
24 void *vaddr
; /* for debugging mostly */
29 struct ath10k_hif_ops
{
30 /* send a scatter-gather list to the target */
31 int (*tx_sg
)(struct ath10k
*ar
, u8 pipe_id
,
32 struct ath10k_hif_sg_item
*items
, int n_items
);
34 /* read firmware memory through the diagnose interface */
35 int (*diag_read
)(struct ath10k
*ar
, u32 address
, void *buf
,
38 int (*diag_write
)(struct ath10k
*ar
, u32 address
, const void *data
,
41 * API to handle HIF-specific BMI message exchanges, this API is
42 * synchronous and only allowed to be called from a context that
45 int (*exchange_bmi_msg
)(struct ath10k
*ar
,
46 void *request
, u32 request_len
,
47 void *response
, u32
*response_len
);
49 /* Post BMI phase, after FW is loaded. Starts regular operation */
50 int (*start
)(struct ath10k
*ar
);
52 /* Clean up what start() did. This does not revert to BMI phase. If
53 * desired so, call power_down() and power_up()
55 void (*stop
)(struct ath10k
*ar
);
57 int (*swap_mailbox
)(struct ath10k
*ar
);
59 int (*map_service_to_pipe
)(struct ath10k
*ar
, u16 service_id
,
60 u8
*ul_pipe
, u8
*dl_pipe
);
62 void (*get_default_pipe
)(struct ath10k
*ar
, u8
*ul_pipe
, u8
*dl_pipe
);
65 * Check if prior sends have completed.
67 * Check whether the pipe in question has any completed
68 * sends that have not yet been processed.
69 * This function is only relevant for HIF pipes that are configured
70 * to be polled rather than interrupt-driven.
72 void (*send_complete_check
)(struct ath10k
*ar
, u8 pipe_id
, int force
);
74 u16 (*get_free_queue_number
)(struct ath10k
*ar
, u8 pipe_id
);
76 u32 (*read32
)(struct ath10k
*ar
, u32 address
);
78 void (*write32
)(struct ath10k
*ar
, u32 address
, u32 value
);
80 /* Power up the device and enter BMI transfer mode for FW download */
81 int (*power_up
)(struct ath10k
*ar
, enum ath10k_firmware_mode fw_mode
);
83 /* Power down the device and free up resources. stop() must be called
84 * before this if start() was called earlier
86 void (*power_down
)(struct ath10k
*ar
);
88 int (*suspend
)(struct ath10k
*ar
);
89 int (*resume
)(struct ath10k
*ar
);
91 /* fetch calibration data from target eeprom */
92 int (*fetch_cal_eeprom
)(struct ath10k
*ar
, void **data
,
95 int (*get_target_info
)(struct ath10k
*ar
,
96 struct bmi_target_info
*target_info
);
97 int (*set_target_log_mode
)(struct ath10k
*ar
, u8 fw_log_mode
);
100 static inline int ath10k_hif_tx_sg(struct ath10k
*ar
, u8 pipe_id
,
101 struct ath10k_hif_sg_item
*items
,
104 return ar
->hif
.ops
->tx_sg(ar
, pipe_id
, items
, n_items
);
107 static inline int ath10k_hif_diag_read(struct ath10k
*ar
, u32 address
, void *buf
,
110 return ar
->hif
.ops
->diag_read(ar
, address
, buf
, buf_len
);
113 static inline int ath10k_hif_diag_write(struct ath10k
*ar
, u32 address
,
114 const void *data
, int nbytes
)
116 if (!ar
->hif
.ops
->diag_write
)
119 return ar
->hif
.ops
->diag_write(ar
, address
, data
, nbytes
);
122 static inline int ath10k_hif_exchange_bmi_msg(struct ath10k
*ar
,
123 void *request
, u32 request_len
,
124 void *response
, u32
*response_len
)
126 return ar
->hif
.ops
->exchange_bmi_msg(ar
, request
, request_len
,
127 response
, response_len
);
130 static inline int ath10k_hif_start(struct ath10k
*ar
)
132 return ar
->hif
.ops
->start(ar
);
135 static inline void ath10k_hif_stop(struct ath10k
*ar
)
137 return ar
->hif
.ops
->stop(ar
);
140 static inline int ath10k_hif_swap_mailbox(struct ath10k
*ar
)
142 if (ar
->hif
.ops
->swap_mailbox
)
143 return ar
->hif
.ops
->swap_mailbox(ar
);
147 static inline int ath10k_hif_map_service_to_pipe(struct ath10k
*ar
,
149 u8
*ul_pipe
, u8
*dl_pipe
)
151 return ar
->hif
.ops
->map_service_to_pipe(ar
, service_id
,
155 static inline void ath10k_hif_get_default_pipe(struct ath10k
*ar
,
156 u8
*ul_pipe
, u8
*dl_pipe
)
158 ar
->hif
.ops
->get_default_pipe(ar
, ul_pipe
, dl_pipe
);
161 static inline void ath10k_hif_send_complete_check(struct ath10k
*ar
,
162 u8 pipe_id
, int force
)
164 ar
->hif
.ops
->send_complete_check(ar
, pipe_id
, force
);
167 static inline u16
ath10k_hif_get_free_queue_number(struct ath10k
*ar
,
170 return ar
->hif
.ops
->get_free_queue_number(ar
, pipe_id
);
173 static inline int ath10k_hif_power_up(struct ath10k
*ar
,
174 enum ath10k_firmware_mode fw_mode
)
176 return ar
->hif
.ops
->power_up(ar
, fw_mode
);
179 static inline void ath10k_hif_power_down(struct ath10k
*ar
)
181 ar
->hif
.ops
->power_down(ar
);
184 static inline int ath10k_hif_suspend(struct ath10k
*ar
)
186 if (!ar
->hif
.ops
->suspend
)
189 return ar
->hif
.ops
->suspend(ar
);
192 static inline int ath10k_hif_resume(struct ath10k
*ar
)
194 if (!ar
->hif
.ops
->resume
)
197 return ar
->hif
.ops
->resume(ar
);
200 static inline u32
ath10k_hif_read32(struct ath10k
*ar
, u32 address
)
202 if (!ar
->hif
.ops
->read32
) {
203 ath10k_warn(ar
, "hif read32 not supported\n");
207 return ar
->hif
.ops
->read32(ar
, address
);
210 static inline void ath10k_hif_write32(struct ath10k
*ar
,
211 u32 address
, u32 data
)
213 if (!ar
->hif
.ops
->write32
) {
214 ath10k_warn(ar
, "hif write32 not supported\n");
218 ar
->hif
.ops
->write32(ar
, address
, data
);
221 static inline int ath10k_hif_fetch_cal_eeprom(struct ath10k
*ar
,
225 if (!ar
->hif
.ops
->fetch_cal_eeprom
)
228 return ar
->hif
.ops
->fetch_cal_eeprom(ar
, data
, data_len
);
231 static inline int ath10k_hif_get_target_info(struct ath10k
*ar
,
232 struct bmi_target_info
*tgt_info
)
234 if (!ar
->hif
.ops
->get_target_info
)
237 return ar
->hif
.ops
->get_target_info(ar
, tgt_info
);
240 static inline int ath10k_hif_set_target_log_mode(struct ath10k
*ar
,
243 if (!ar
->hif
.ops
->set_target_log_mode
)
246 return ar
->hif
.ops
->set_target_log_mode(ar
, fw_log_mode
);