xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_platform.h (revision 97f44cd39e4ff816eaa1710279d28cf6b9e65ad9)
1 /*
2  * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: qdf_platform.h
21  * This file defines platform API abstractions.
22  */
23 
24 #ifndef _QDF_PLATFORM_H
25 #define _QDF_PLATFORM_H
26 
27 #include "qdf_types.h"
28 
29 /**
30  * qdf_self_recovery_callback() - callback for self recovery
31  * @psoc: pointer to the posc object
32  * @reason: the reason for the recovery request
33  * @func: the caller's function name
34  * @line: the line number of the callsite
35  *
36  * Return: none
37  */
38 typedef void (*qdf_self_recovery_callback)(void *psoc,
39 					   enum qdf_hang_reason reason,
40 					   const char *func,
41 					   const uint32_t line);
42 
43 /**
44  * qdf_is_fw_down_callback() - callback to query if fw is down
45  *
46  * Return: true if fw is down and false if fw is not down
47  */
48 typedef bool (*qdf_is_fw_down_callback)(void);
49 
50 /**
51  * qdf_register_fw_down_callback() - API to register fw down callback
52  * @is_fw_down: callback to query if fw is down or not
53  *
54  * Return: none
55  */
56 void qdf_register_fw_down_callback(qdf_is_fw_down_callback is_fw_down);
57 
58 /**
59  * qdf_is_fw_down() - API to check if fw is down or not
60  *
61  * Return: true: if fw is down
62  *	   false: if fw is not down
63  */
64 bool qdf_is_fw_down(void);
65 
66 /**
67  * qdf_wmi_recv_qmi_cb() - callback to receive WMI over QMI
68  * @cb_ctx: WMI event recv callback context(wmi_handle)
69  * @buf: WMI buffer
70  * @len: WMI buffer len
71  *
72  * Return: 0 if success otherwise -EINVAL
73  */
74 typedef int (*qdf_wmi_recv_qmi_cb)(void *cb_ctx, void *buf, int len);
75 
76 /**
77  * qdf_wmi_send_over_qmi_callback() - callback to send WMI over QMI
78  * @buf: WMI buffer
79  * @len: WMI buffer len
80  * @cb_ctx: WMI event recv callback context(wmi_handle)
81  * @wmi_rx_cb: WMI event receive call back
82  *
83  * Return: QDF_STATUS_SUCCESS if success otherwise QDF error code
84  */
85 typedef QDF_STATUS (*qdf_wmi_send_over_qmi_callback)(void *buf, uint32_t len,
86 						     void *cb_ctx,
87 						     qdf_wmi_recv_qmi_cb
88 						     wmi_rx_cb);
89 
90 /**
91  * qdf_register_wmi_send_recv_qmi_callback() - Register WMI over QMI callback
92  * @qdf_wmi_send_over_qmi_callback: callback to send recv WMI data over QMI
93  *
94  * Return: none
95  */
96 void qdf_register_wmi_send_recv_qmi_callback(qdf_wmi_send_over_qmi_callback
97 					     wmi_send_recv_qmi_cb);
98 
99 /**
100  * qdf_wmi_send_recv_qmi() - API to send receive WMI data over QMI
101  * @buf: WMI buffer
102  * @len: WMI buffer len
103  * @cb_ctx: WMI event recv callback context(wmi_handle)
104  * @wmi_rx_cb: WMI event receive call back
105  *
106  * Return: QDF STATUS of operation
107  */
108 QDF_STATUS qdf_wmi_send_recv_qmi(void *buf, uint32_t len, void *cb_ctx,
109 				 qdf_wmi_recv_qmi_cb wmi_rx_cb);
110 
111 /**
112  * qdf_is_driver_unloading_callback() - callback to get driver unloading in progress
113  * or not
114  *
115  * Return: true if driver is unloading else false
116  */
117 typedef bool (*qdf_is_driver_unloading_callback)(void);
118 
119 /**
120  * qdf_register_is_driver_unloading_callback() - driver unloading callback
121  * @callback:  driver unloading callback
122  *
123  * Return: None
124  */
125 void qdf_register_is_driver_unloading_callback(
126 				qdf_is_driver_unloading_callback callback);
127 
128 /**
129  * qdf_register_self_recovery_callback() - register self recovery callback
130  * @callback:  self recovery callback
131  *
132  * Return: None
133  */
134 void qdf_register_self_recovery_callback(qdf_self_recovery_callback callback);
135 
136 /**
137  * qdf_trigger_self_recovery () - trigger self recovery
138  * @psoc: the psoc at which the recovery is being triggered
139  * @reason: the reason for the recovery request
140  *
141  * Call API only in case of fatal error,
142  * if self_recovery_cb callback is registered, injcets fw crash and recovers
143  * else raises QDF_BUG()
144  *
145  * Return: None
146  */
147 #define qdf_trigger_self_recovery(psoc, reason) \
148 	__qdf_trigger_self_recovery(psoc, reason, __func__, __LINE__)
149 void __qdf_trigger_self_recovery(void *psoc, enum qdf_hang_reason reason,
150 				 const char *func, const uint32_t line);
151 
152 /**
153  * qdf_is_recovering_callback() - callback to get driver recovering in
154  * progress or not
155  *
156  * Return: true if driver is doing recovering else false
157  */
158 typedef bool (*qdf_is_recovering_callback)(void);
159 
160 /**
161  * qdf_register_recovering_state_query_callback() - register recover status
162  * query callback
163  *
164  * Return: none
165  */
166 void qdf_register_recovering_state_query_callback(
167 	qdf_is_recovering_callback is_recovering);
168 
169 /**
170  * qdf_is_driver_unloading() - get driver unloading in progress status
171  * or not
172  *
173  * Return: true if driver is unloading else false
174  */
175 bool qdf_is_driver_unloading(void);
176 
177 /**
178  * qdf_is_recovering() - get driver recovering in progress status
179  * or not
180  *
181  * Return: true if driver is doing recovering else false
182  */
183 bool qdf_is_recovering(void);
184 
185 /**
186  * struct qdf_op_sync - opaque operation synchronization context handle
187  */
188 struct qdf_op_sync;
189 
190 typedef int (*qdf_op_protect_cb)(void **out_sync, const char *func);
191 typedef void (*qdf_op_unprotect_cb)(void *sync, const char *func);
192 
193 /**
194  * qdf_op_protect() - attempt to protect a driver operation
195  * @out_sync: output parameter for the synchronization context, populated on
196  *	success
197  *
198  * Return: Errno
199  */
200 #define qdf_op_protect(out_sync) __qdf_op_protect(out_sync, __func__)
201 
202 qdf_must_check int
203 __qdf_op_protect(struct qdf_op_sync **out_sync, const char *func);
204 
205 /**
206  * qdf_op_unprotect() - release driver operation protection
207  * @sync: synchronization context returned from qdf_op_protect()
208  *
209  * Return: None
210  */
211 #define qdf_op_unprotect(sync) __qdf_op_unprotect(sync, __func__)
212 
213 void __qdf_op_unprotect(struct qdf_op_sync *sync, const char *func);
214 
215 /**
216  * qdf_op_callbacks_register() - register driver operation protection callbacks
217  *
218  * Return: None
219  */
220 void qdf_op_callbacks_register(qdf_op_protect_cb on_protect,
221 			       qdf_op_unprotect_cb on_unprotect);
222 
223 /**
224  * qdf_is_drv_connected_callback() - callback to query if drv is connected
225  *
226  * Return: true if drv is connected else false
227  */
228 typedef bool (*qdf_is_drv_connected_callback)(void);
229 
230 /**
231  * qdf_is_drv_connected() - API to check if drv is connected or not
232  *
233  * DRV is dynamic request voting using which fw can do page fault and
234  * bring in page back without apps wake up
235  *
236  * Return: true: if drv is connected
237  *	   false: if drv is not connected
238  */
239 bool qdf_is_drv_connected(void);
240 
241 /**
242  * qdf_register_drv_connected_callback() - API to register drv connected cb
243  * @is_drv_connected: callback to query if drv is connected or not
244  *
245  * Return: none
246  */
247 void qdf_register_drv_connected_callback(qdf_is_drv_connected_callback
248 					 is_drv_connected);
249 
250 /**
251  * qdf_check_state_before_panic() - API to check if FW is down
252  * or driver is in recovery before calling assert
253  *
254  * Return: none
255  */
256 void qdf_check_state_before_panic(void);
257 
258 /**
259  * qdf_is_drv_supported_callback() - callback to query if drv is supported
260  *
261  * Return: true if drv is supported else false
262  */
263 typedef bool (*qdf_is_drv_supported_callback)(void);
264 
265 /**
266  * qdf_is_drv_supported_callback() - API to check if drv is supported or not
267  *
268  * DRV is dynamic request voting using which fw can do page fault and
269  * bring in page back without apps wake up
270  *
271  * Return: true: if drv is supported
272  *	   false: if drv is not supported
273  */
274 bool qdf_is_drv_supported(void);
275 
276 /**
277  * qdf_register_drv_supported_callback() - API to register drv supported cb
278  * @is_drv_supported: callback to query if drv is supported or not
279  *
280  * Return: none
281  */
282 void qdf_register_drv_supported_callback(qdf_is_drv_supported_callback
283 					 is_drv_supported);
284 
285 typedef void (*qdf_recovery_reason_update_callback)(enum qdf_hang_reason
286 						    reason);
287 
288 /**
289  * qdf_register_recovery_reason_update() - Register callback to update recovery
290  *                                         reason
291  * @qdf_recovery_reason_update_callback: callback to update recovery reason
292  *
293  * Return: none
294  */
295 void qdf_register_recovery_reason_update(qdf_recovery_reason_update_callback
296 					 callback);
297 
298 /**
299  * qdf_recovery_reason_update() - update recovery reason
300  * @reason: recovery reason
301  *
302  * Return: none
303  */
304 void qdf_recovery_reason_update(enum qdf_hang_reason reason);
305 
306 /**
307  * qdf_bus_reg_dump() - callback for getting bus specific register dump
308  * @dev: Bus specific device
309  * @buf: Hang event buffer in which the data will be populated
310  * @len: length of data to be populated in the hang event buffer
311  *
312  * Return: none
313  */
314 typedef void (*qdf_bus_reg_dump)(struct device *dev, uint8_t *buf,
315 				 uint32_t len);
316 
317 /**
318  * qdf_register_get_bus_reg_dump() - Register callback to update bus register
319  *                                   dump
320  * @qdf_bus_reg_dump: callback to update bus register dump
321  *
322  * Return: none
323  */
324 void qdf_register_get_bus_reg_dump(qdf_bus_reg_dump callback);
325 
326 /**
327  * qdf_get_bus_reg_dump() - Get the register dump for the bus
328  * @dev: device
329  * @buffer: buffer for hang data
330  * @len: len of hang data
331  *
332  * Return: none
333  */
334 void qdf_get_bus_reg_dump(struct device *dev, uint8_t *buf, uint32_t len);
335 #endif /*_QDF_PLATFORM_H*/
336