xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_platform.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2018-2021 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_is_driver_state_module_stop_callback() - callback to get driver state is
130  * module stop or not
131  *
132  * Return: true if driver state is module stop else false
133  */
134 typedef bool (*qdf_is_driver_state_module_stop_callback)(void);
135 
136 /**
137  * qdf_register_is_driver_state_module_stop_callback() - driver state is
138  * module stop or not
139  * @callback:  driver state module stop callback
140  *
141  * Return: None
142  */
143 void qdf_register_is_driver_state_module_stop_callback(
144 			qdf_is_driver_state_module_stop_callback callback);
145 
146 /**
147  * qdf_register_self_recovery_callback() - register self recovery callback
148  * @callback:  self recovery callback
149  *
150  * Return: None
151  */
152 void qdf_register_self_recovery_callback(qdf_self_recovery_callback callback);
153 
154 /**
155  * qdf_trigger_self_recovery () - trigger self recovery
156  * @psoc: the psoc at which the recovery is being triggered
157  * @reason: the reason for the recovery request
158  *
159  * Call API only in case of fatal error,
160  * if self_recovery_cb callback is registered, injcets fw crash and recovers
161  * else raises QDF_BUG()
162  *
163  * Return: None
164  */
165 #define qdf_trigger_self_recovery(psoc, reason) \
166 	__qdf_trigger_self_recovery(psoc, reason, __func__, __LINE__)
167 void __qdf_trigger_self_recovery(void *psoc, enum qdf_hang_reason reason,
168 				 const char *func, const uint32_t line);
169 
170 /**
171  * qdf_is_recovering_callback() - callback to get driver recovering in
172  * progress or not
173  *
174  * Return: true if driver is doing recovering else false
175  */
176 typedef bool (*qdf_is_recovering_callback)(void);
177 
178 /**
179  * qdf_register_recovering_state_query_callback() - register recover status
180  * query callback
181  *
182  * Return: none
183  */
184 void qdf_register_recovering_state_query_callback(
185 	qdf_is_recovering_callback is_recovering);
186 
187 /**
188  * qdf_is_driver_unloading() - get driver unloading in progress status
189  * or not
190  *
191  * Return: true if driver is unloading else false
192  */
193 bool qdf_is_driver_unloading(void);
194 
195 /**
196  * qdf_is_driver_state_module_stop() - get driver state is module stop or not
197  *
198  * Return: true if driver state is module stop else false
199  */
200 bool qdf_is_driver_state_module_stop(void);
201 
202 /**
203  * qdf_is_recovering() - get driver recovering in progress status
204  * or not
205  *
206  * Return: true if driver is doing recovering else false
207  */
208 bool qdf_is_recovering(void);
209 
210 /**
211  * struct qdf_op_sync - opaque operation synchronization context handle
212  */
213 struct qdf_op_sync;
214 
215 typedef int (*qdf_op_protect_cb)(void **out_sync, const char *func);
216 typedef void (*qdf_op_unprotect_cb)(void *sync, const char *func);
217 
218 /**
219  * qdf_op_protect() - attempt to protect a driver operation
220  * @out_sync: output parameter for the synchronization context, populated on
221  *	success
222  *
223  * Return: Errno
224  */
225 #define qdf_op_protect(out_sync) __qdf_op_protect(out_sync, __func__)
226 
227 qdf_must_check int
228 __qdf_op_protect(struct qdf_op_sync **out_sync, const char *func);
229 
230 /**
231  * qdf_op_unprotect() - release driver operation protection
232  * @sync: synchronization context returned from qdf_op_protect()
233  *
234  * Return: None
235  */
236 #define qdf_op_unprotect(sync) __qdf_op_unprotect(sync, __func__)
237 
238 void __qdf_op_unprotect(struct qdf_op_sync *sync, const char *func);
239 
240 /**
241  * qdf_op_callbacks_register() - register driver operation protection callbacks
242  *
243  * Return: None
244  */
245 void qdf_op_callbacks_register(qdf_op_protect_cb on_protect,
246 			       qdf_op_unprotect_cb on_unprotect);
247 
248 /**
249  * qdf_is_drv_connected_callback() - callback to query if drv is connected
250  *
251  * Return: true if drv is connected else false
252  */
253 typedef bool (*qdf_is_drv_connected_callback)(void);
254 
255 /**
256  * qdf_is_drv_connected() - API to check if drv is connected or not
257  *
258  * DRV is dynamic request voting using which fw can do page fault and
259  * bring in page back without apps wake up
260  *
261  * Return: true: if drv is connected
262  *	   false: if drv is not connected
263  */
264 bool qdf_is_drv_connected(void);
265 
266 /**
267  * qdf_register_drv_connected_callback() - API to register drv connected cb
268  * @is_drv_connected: callback to query if drv is connected or not
269  *
270  * Return: none
271  */
272 void qdf_register_drv_connected_callback(qdf_is_drv_connected_callback
273 					 is_drv_connected);
274 
275 /**
276  * qdf_check_state_before_panic() - API to check if FW is down
277  * or driver is in recovery before calling assert
278  * @func: Caller function pointer used for debug info
279  * @line: Caller function line number
280  *
281  * Return: none
282  */
283 void qdf_check_state_before_panic(const char *func, const uint32_t line);
284 
285 /**
286  * qdf_is_drv_supported_callback() - callback to query if drv is supported
287  *
288  * Return: true if drv is supported else false
289  */
290 typedef bool (*qdf_is_drv_supported_callback)(void);
291 
292 /**
293  * qdf_is_drv_supported_callback() - API to check if drv is supported or not
294  *
295  * DRV is dynamic request voting using which fw can do page fault and
296  * bring in page back without apps wake up
297  *
298  * Return: true: if drv is supported
299  *	   false: if drv is not supported
300  */
301 bool qdf_is_drv_supported(void);
302 
303 /**
304  * qdf_register_drv_supported_callback() - API to register drv supported cb
305  * @is_drv_supported: callback to query if drv is supported or not
306  *
307  * Return: none
308  */
309 void qdf_register_drv_supported_callback(qdf_is_drv_supported_callback
310 					 is_drv_supported);
311 
312 typedef void (*qdf_recovery_reason_update_callback)(enum qdf_hang_reason
313 						    reason);
314 
315 /**
316  * qdf_register_recovery_reason_update() - Register callback to update recovery
317  *                                         reason
318  * @qdf_recovery_reason_update_callback: callback to update recovery reason
319  *
320  * Return: none
321  */
322 void qdf_register_recovery_reason_update(qdf_recovery_reason_update_callback
323 					 callback);
324 
325 /**
326  * qdf_recovery_reason_update() - update recovery reason
327  * @reason: recovery reason
328  *
329  * Return: none
330  */
331 void qdf_recovery_reason_update(enum qdf_hang_reason reason);
332 
333 /**
334  * qdf_bus_reg_dump() - callback for getting bus specific register dump
335  * @dev: Bus specific device
336  * @buf: Hang event buffer in which the data will be populated
337  * @len: length of data to be populated in the hang event buffer
338  *
339  * Return: none
340  */
341 typedef void (*qdf_bus_reg_dump)(struct device *dev, uint8_t *buf,
342 				 uint32_t len);
343 
344 /**
345  * qdf_register_get_bus_reg_dump() - Register callback to update bus register
346  *                                   dump
347  * @qdf_bus_reg_dump: callback to update bus register dump
348  *
349  * Return: none
350  */
351 void qdf_register_get_bus_reg_dump(qdf_bus_reg_dump callback);
352 
353 /**
354  * qdf_get_bus_reg_dump() - Get the register dump for the bus
355  * @dev: device
356  * @buffer: buffer for hang data
357  * @len: len of hang data
358  *
359  * Return: none
360  */
361 void qdf_get_bus_reg_dump(struct device *dev, uint8_t *buf, uint32_t len);
362 #endif /*_QDF_PLATFORM_H*/
363