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