xref: /linux/drivers/net/wireless/ath/ath10k/hif.h (revision 44f57d78)
1 /* SPDX-License-Identifier: ISC */
2 /*
3  * Copyright (c) 2005-2011 Atheros Communications Inc.
4  * Copyright (c) 2011-2015,2017 Qualcomm Atheros, Inc.
5  */
6 
7 #ifndef _HIF_H_
8 #define _HIF_H_
9 
10 #include <linux/kernel.h>
11 #include "core.h"
12 #include "bmi.h"
13 #include "debug.h"
14 
15 struct ath10k_hif_sg_item {
16 	u16 transfer_id;
17 	void *transfer_context; /* NULL = tx completion callback not called */
18 	void *vaddr; /* for debugging mostly */
19 	dma_addr_t paddr;
20 	u16 len;
21 };
22 
23 struct ath10k_hif_ops {
24 	/* send a scatter-gather list to the target */
25 	int (*tx_sg)(struct ath10k *ar, u8 pipe_id,
26 		     struct ath10k_hif_sg_item *items, int n_items);
27 
28 	/* read firmware memory through the diagnose interface */
29 	int (*diag_read)(struct ath10k *ar, u32 address, void *buf,
30 			 size_t buf_len);
31 
32 	int (*diag_write)(struct ath10k *ar, u32 address, const void *data,
33 			  int nbytes);
34 	/*
35 	 * API to handle HIF-specific BMI message exchanges, this API is
36 	 * synchronous and only allowed to be called from a context that
37 	 * can block (sleep)
38 	 */
39 	int (*exchange_bmi_msg)(struct ath10k *ar,
40 				void *request, u32 request_len,
41 				void *response, u32 *response_len);
42 
43 	/* Post BMI phase, after FW is loaded. Starts regular operation */
44 	int (*start)(struct ath10k *ar);
45 
46 	/* Clean up what start() did. This does not revert to BMI phase. If
47 	 * desired so, call power_down() and power_up()
48 	 */
49 	void (*stop)(struct ath10k *ar);
50 
51 	int (*swap_mailbox)(struct ath10k *ar);
52 
53 	int (*map_service_to_pipe)(struct ath10k *ar, u16 service_id,
54 				   u8 *ul_pipe, u8 *dl_pipe);
55 
56 	void (*get_default_pipe)(struct ath10k *ar, u8 *ul_pipe, u8 *dl_pipe);
57 
58 	/*
59 	 * Check if prior sends have completed.
60 	 *
61 	 * Check whether the pipe in question has any completed
62 	 * sends that have not yet been processed.
63 	 * This function is only relevant for HIF pipes that are configured
64 	 * to be polled rather than interrupt-driven.
65 	 */
66 	void (*send_complete_check)(struct ath10k *ar, u8 pipe_id, int force);
67 
68 	u16 (*get_free_queue_number)(struct ath10k *ar, u8 pipe_id);
69 
70 	u32 (*read32)(struct ath10k *ar, u32 address);
71 
72 	void (*write32)(struct ath10k *ar, u32 address, u32 value);
73 
74 	/* Power up the device and enter BMI transfer mode for FW download */
75 	int (*power_up)(struct ath10k *ar, enum ath10k_firmware_mode fw_mode);
76 
77 	/* Power down the device and free up resources. stop() must be called
78 	 * before this if start() was called earlier
79 	 */
80 	void (*power_down)(struct ath10k *ar);
81 
82 	int (*suspend)(struct ath10k *ar);
83 	int (*resume)(struct ath10k *ar);
84 
85 	/* fetch calibration data from target eeprom */
86 	int (*fetch_cal_eeprom)(struct ath10k *ar, void **data,
87 				size_t *data_len);
88 
89 	int (*get_target_info)(struct ath10k *ar,
90 			       struct bmi_target_info *target_info);
91 };
92 
93 static inline int ath10k_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
94 				   struct ath10k_hif_sg_item *items,
95 				   int n_items)
96 {
97 	return ar->hif.ops->tx_sg(ar, pipe_id, items, n_items);
98 }
99 
100 static inline int ath10k_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
101 				       size_t buf_len)
102 {
103 	return ar->hif.ops->diag_read(ar, address, buf, buf_len);
104 }
105 
106 static inline int ath10k_hif_diag_write(struct ath10k *ar, u32 address,
107 					const void *data, int nbytes)
108 {
109 	if (!ar->hif.ops->diag_write)
110 		return -EOPNOTSUPP;
111 
112 	return ar->hif.ops->diag_write(ar, address, data, nbytes);
113 }
114 
115 static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar,
116 					      void *request, u32 request_len,
117 					      void *response, u32 *response_len)
118 {
119 	return ar->hif.ops->exchange_bmi_msg(ar, request, request_len,
120 					     response, response_len);
121 }
122 
123 static inline int ath10k_hif_start(struct ath10k *ar)
124 {
125 	return ar->hif.ops->start(ar);
126 }
127 
128 static inline void ath10k_hif_stop(struct ath10k *ar)
129 {
130 	return ar->hif.ops->stop(ar);
131 }
132 
133 static inline int ath10k_hif_swap_mailbox(struct ath10k *ar)
134 {
135 	if (ar->hif.ops->swap_mailbox)
136 		return ar->hif.ops->swap_mailbox(ar);
137 	return 0;
138 }
139 
140 static inline int ath10k_hif_map_service_to_pipe(struct ath10k *ar,
141 						 u16 service_id,
142 						 u8 *ul_pipe, u8 *dl_pipe)
143 {
144 	return ar->hif.ops->map_service_to_pipe(ar, service_id,
145 						ul_pipe, dl_pipe);
146 }
147 
148 static inline void ath10k_hif_get_default_pipe(struct ath10k *ar,
149 					       u8 *ul_pipe, u8 *dl_pipe)
150 {
151 	ar->hif.ops->get_default_pipe(ar, ul_pipe, dl_pipe);
152 }
153 
154 static inline void ath10k_hif_send_complete_check(struct ath10k *ar,
155 						  u8 pipe_id, int force)
156 {
157 	ar->hif.ops->send_complete_check(ar, pipe_id, force);
158 }
159 
160 static inline u16 ath10k_hif_get_free_queue_number(struct ath10k *ar,
161 						   u8 pipe_id)
162 {
163 	return ar->hif.ops->get_free_queue_number(ar, pipe_id);
164 }
165 
166 static inline int ath10k_hif_power_up(struct ath10k *ar,
167 				      enum ath10k_firmware_mode fw_mode)
168 {
169 	return ar->hif.ops->power_up(ar, fw_mode);
170 }
171 
172 static inline void ath10k_hif_power_down(struct ath10k *ar)
173 {
174 	ar->hif.ops->power_down(ar);
175 }
176 
177 static inline int ath10k_hif_suspend(struct ath10k *ar)
178 {
179 	if (!ar->hif.ops->suspend)
180 		return -EOPNOTSUPP;
181 
182 	return ar->hif.ops->suspend(ar);
183 }
184 
185 static inline int ath10k_hif_resume(struct ath10k *ar)
186 {
187 	if (!ar->hif.ops->resume)
188 		return -EOPNOTSUPP;
189 
190 	return ar->hif.ops->resume(ar);
191 }
192 
193 static inline u32 ath10k_hif_read32(struct ath10k *ar, u32 address)
194 {
195 	if (!ar->hif.ops->read32) {
196 		ath10k_warn(ar, "hif read32 not supported\n");
197 		return 0xdeaddead;
198 	}
199 
200 	return ar->hif.ops->read32(ar, address);
201 }
202 
203 static inline void ath10k_hif_write32(struct ath10k *ar,
204 				      u32 address, u32 data)
205 {
206 	if (!ar->hif.ops->write32) {
207 		ath10k_warn(ar, "hif write32 not supported\n");
208 		return;
209 	}
210 
211 	ar->hif.ops->write32(ar, address, data);
212 }
213 
214 static inline int ath10k_hif_fetch_cal_eeprom(struct ath10k *ar,
215 					      void **data,
216 					      size_t *data_len)
217 {
218 	if (!ar->hif.ops->fetch_cal_eeprom)
219 		return -EOPNOTSUPP;
220 
221 	return ar->hif.ops->fetch_cal_eeprom(ar, data, data_len);
222 }
223 
224 static inline int ath10k_hif_get_target_info(struct ath10k *ar,
225 					     struct bmi_target_info *tgt_info)
226 {
227 	if (!ar->hif.ops->get_target_info)
228 		return -EOPNOTSUPP;
229 
230 	return ar->hif.ops->get_target_info(ar, tgt_info);
231 }
232 
233 #endif /* _HIF_H_ */
234