qdf_platform.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. * DOC: qdf_platform.h
  21. * This file defines platform API abstractions.
  22. */
  23. #ifndef _QDF_PLATFORM_H
  24. #define _QDF_PLATFORM_H
  25. #include "qdf_types.h"
  26. /**
  27. * typedef qdf_self_recovery_callback() - callback for self recovery
  28. * @psoc: pointer to the posc object
  29. * @reason: the reason for the recovery request
  30. * @func: the caller's function name
  31. * @line: the line number of the callsite
  32. *
  33. * Return: none
  34. */
  35. typedef void (*qdf_self_recovery_callback)(void *psoc,
  36. enum qdf_hang_reason reason,
  37. const char *func,
  38. const uint32_t line);
  39. /**
  40. * typedef qdf_is_fw_down_callback() - callback to query if fw is down
  41. *
  42. * Return: true if fw is down and false if fw is not down
  43. */
  44. typedef bool (*qdf_is_fw_down_callback)(void);
  45. /**
  46. * qdf_register_fw_down_callback() - API to register fw down callback
  47. * @is_fw_down: callback to query if fw is down or not
  48. *
  49. * Return: none
  50. */
  51. void qdf_register_fw_down_callback(qdf_is_fw_down_callback is_fw_down);
  52. /**
  53. * qdf_is_fw_down() - API to check if fw is down or not
  54. *
  55. * Return: true: if fw is down
  56. * false: if fw is not down
  57. */
  58. bool qdf_is_fw_down(void);
  59. /**
  60. * typedef qdf_wmi_recv_qmi_cb() - callback to receive WMI over QMI
  61. * @cb_ctx: WMI event recv callback context(wmi_handle)
  62. * @buf: WMI buffer
  63. * @len: WMI buffer len
  64. *
  65. * Return: 0 if success otherwise -EINVAL
  66. */
  67. typedef int (*qdf_wmi_recv_qmi_cb)(void *cb_ctx, void *buf, int len);
  68. /**
  69. * typedef qdf_wmi_send_over_qmi_callback() - callback to send WMI over QMI
  70. * @buf: WMI buffer
  71. * @len: WMI buffer len
  72. * @cb_ctx: WMI event recv callback context(wmi_handle)
  73. * @wmi_rx_cb: WMI event receive call back
  74. *
  75. * Return: QDF_STATUS_SUCCESS if success otherwise QDF error code
  76. */
  77. typedef QDF_STATUS (*qdf_wmi_send_over_qmi_callback)(void *buf, uint32_t len,
  78. void *cb_ctx,
  79. qdf_wmi_recv_qmi_cb
  80. wmi_rx_cb);
  81. /**
  82. * qdf_register_wmi_send_recv_qmi_callback() - Register WMI over QMI callback
  83. * @wmi_send_recv_qmi_cb: callback to send recv WMI data over QMI
  84. *
  85. * Return: none
  86. */
  87. void qdf_register_wmi_send_recv_qmi_callback(qdf_wmi_send_over_qmi_callback
  88. wmi_send_recv_qmi_cb);
  89. /**
  90. * qdf_wmi_send_recv_qmi() - API to send receive WMI data over QMI
  91. * @buf: WMI buffer
  92. * @len: WMI buffer len
  93. * @cb_ctx: WMI event recv callback context(wmi_handle)
  94. * @wmi_rx_cb: WMI event receive call back
  95. *
  96. * Return: QDF STATUS of operation
  97. */
  98. QDF_STATUS qdf_wmi_send_recv_qmi(void *buf, uint32_t len, void *cb_ctx,
  99. qdf_wmi_recv_qmi_cb wmi_rx_cb);
  100. /**
  101. * typedef qdf_is_driver_unloading_callback() - callback to get driver
  102. * unloading in progress or not
  103. *
  104. * Return: true if driver is unloading else false
  105. */
  106. typedef bool (*qdf_is_driver_unloading_callback)(void);
  107. /**
  108. * qdf_register_is_driver_unloading_callback() - driver unloading callback
  109. * @callback: driver unloading callback
  110. *
  111. * Return: None
  112. */
  113. void qdf_register_is_driver_unloading_callback(
  114. qdf_is_driver_unloading_callback callback);
  115. /**
  116. * typedef qdf_is_driver_state_module_stop_callback() - callback to get driver
  117. * state is module stop or not
  118. *
  119. * Return: true if driver state is module stop else false
  120. */
  121. typedef bool (*qdf_is_driver_state_module_stop_callback)(void);
  122. /**
  123. * qdf_register_is_driver_state_module_stop_callback() - driver state is
  124. * module stop or not
  125. * @callback: driver state module stop callback
  126. *
  127. * Return: None
  128. */
  129. void qdf_register_is_driver_state_module_stop_callback(
  130. qdf_is_driver_state_module_stop_callback callback);
  131. /**
  132. * qdf_register_self_recovery_callback() - register self recovery callback
  133. * @callback: self recovery callback
  134. *
  135. * Return: None
  136. */
  137. void qdf_register_self_recovery_callback(qdf_self_recovery_callback callback);
  138. /**
  139. * qdf_trigger_self_recovery () - trigger self recovery
  140. * @psoc: the psoc at which the recovery is being triggered
  141. * @reason: the reason for the recovery request
  142. *
  143. * Call API only in case of fatal error,
  144. * if self_recovery_cb callback is registered, injcets fw crash and recovers
  145. * else raises QDF_BUG()
  146. *
  147. * Return: None
  148. */
  149. #define qdf_trigger_self_recovery(psoc, reason) \
  150. __qdf_trigger_self_recovery(psoc, reason, __func__, __LINE__)
  151. void __qdf_trigger_self_recovery(void *psoc, enum qdf_hang_reason reason,
  152. const char *func, const uint32_t line);
  153. /**
  154. * typedef qdf_is_recovering_callback() - callback to get driver recovering in
  155. * progress or not
  156. *
  157. * Return: true if driver is doing recovering else false
  158. */
  159. typedef bool (*qdf_is_recovering_callback)(void);
  160. /**
  161. * qdf_register_recovering_state_query_callback() - register recover status
  162. * query callback
  163. * @is_recovering: true if driver is recovering
  164. *
  165. * Return: none
  166. */
  167. void qdf_register_recovering_state_query_callback(
  168. qdf_is_recovering_callback is_recovering);
  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. * qdf_is_driver_state_module_stop() - get driver state is module stop or not
  178. *
  179. * Return: true if driver state is module stop else false
  180. */
  181. bool qdf_is_driver_state_module_stop(void);
  182. /**
  183. * qdf_is_recovering() - get driver recovering in progress status
  184. * or not
  185. *
  186. * Return: true if driver is doing recovering else false
  187. */
  188. bool qdf_is_recovering(void);
  189. /*
  190. * struct qdf_op_sync - opaque operation synchronization context handle
  191. */
  192. struct qdf_op_sync;
  193. typedef int (*qdf_op_protect_cb)(void **out_sync, const char *func);
  194. typedef void (*qdf_op_unprotect_cb)(void *sync, const char *func);
  195. /**
  196. * qdf_op_protect() - attempt to protect a driver operation
  197. * @out_sync: output parameter for the synchronization context, populated on
  198. * success
  199. *
  200. * Return: Errno
  201. */
  202. #define qdf_op_protect(out_sync) __qdf_op_protect(out_sync, __func__)
  203. qdf_must_check int
  204. __qdf_op_protect(struct qdf_op_sync **out_sync, const char *func);
  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. void __qdf_op_unprotect(struct qdf_op_sync *sync, const char *func);
  213. /**
  214. * qdf_op_callbacks_register() - register driver operation protection callbacks
  215. * @on_protect: callback on protect
  216. * @on_unprotect: callback on unprotect
  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. * typedef qdf_is_drv_connected_callback() - callback to query if drv
  224. * is connected
  225. *
  226. * Return: true if drv is connected else false
  227. */
  228. typedef bool (*qdf_is_drv_connected_callback)(void);
  229. /**
  230. * qdf_is_drv_connected() - API to check if drv is connected or not
  231. *
  232. * DRV is dynamic request voting using which fw can do page fault and
  233. * bring in page back without apps wake up
  234. *
  235. * Return: true: if drv is connected
  236. * false: if drv is not connected
  237. */
  238. bool qdf_is_drv_connected(void);
  239. /**
  240. * qdf_register_drv_connected_callback() - API to register drv connected cb
  241. * @is_drv_connected: callback to query if drv is connected or not
  242. *
  243. * Return: none
  244. */
  245. void qdf_register_drv_connected_callback(qdf_is_drv_connected_callback
  246. is_drv_connected);
  247. /**
  248. * qdf_check_state_before_panic() - API to check if FW is down
  249. * or driver is in recovery before calling assert
  250. * @func: Caller function pointer used for debug info
  251. * @line: Caller function line number
  252. *
  253. * Return: none
  254. */
  255. void qdf_check_state_before_panic(const char *func, const uint32_t line);
  256. /**
  257. *typedef qdf_is_drv_supported_callback() - callback to query if drv is supported
  258. *
  259. * Return: true if drv is supported else false
  260. */
  261. typedef bool (*qdf_is_drv_supported_callback)(void);
  262. /**
  263. * qdf_is_drv_supported() - API to check if drv is supported or not
  264. *
  265. * DRV is dynamic request voting using which fw can do page fault and
  266. * bring in page back without apps wake up
  267. *
  268. * Return: true: if drv is supported
  269. * false: if drv is not supported
  270. */
  271. bool qdf_is_drv_supported(void);
  272. /**
  273. * qdf_register_drv_supported_callback() - API to register drv supported cb
  274. * @is_drv_supported: callback to query if drv is supported or not
  275. *
  276. * Return: none
  277. */
  278. void qdf_register_drv_supported_callback(qdf_is_drv_supported_callback
  279. is_drv_supported);
  280. /**
  281. * typedef qdf_recovery_reason_update_callback() - recovery reason update callback
  282. * @reason: recovery reason
  283. */
  284. typedef void (*qdf_recovery_reason_update_callback)(enum qdf_hang_reason
  285. reason);
  286. /**
  287. * qdf_register_recovery_reason_update() - Register callback to update recovery
  288. * reason
  289. * @callback: callback to update recovery reason
  290. *
  291. * Return: none
  292. */
  293. void qdf_register_recovery_reason_update(qdf_recovery_reason_update_callback
  294. callback);
  295. /**
  296. * qdf_recovery_reason_update() - update recovery reason
  297. * @reason: recovery reason
  298. *
  299. * Return: none
  300. */
  301. void qdf_recovery_reason_update(enum qdf_hang_reason reason);
  302. /**
  303. * typedef qdf_bus_reg_dump() - callback for getting bus specific register dump
  304. * @dev: Bus specific device
  305. * @buf: Hang event buffer in which the data will be populated
  306. * @len: length of data to be populated in the hang event buffer
  307. *
  308. * Return: none
  309. */
  310. typedef void (*qdf_bus_reg_dump)(struct device *dev, uint8_t *buf,
  311. uint32_t len);
  312. /**
  313. * qdf_register_get_bus_reg_dump() - Register callback to update bus register
  314. * dump
  315. * @callback: callback to update bus register dump
  316. *
  317. * Return: none
  318. */
  319. void qdf_register_get_bus_reg_dump(qdf_bus_reg_dump callback);
  320. /**
  321. * qdf_get_bus_reg_dump() - Get the register dump for the bus
  322. * @dev: device
  323. * @buf: buffer for hang data
  324. * @len: len of hang data
  325. *
  326. * Return: none
  327. */
  328. void qdf_get_bus_reg_dump(struct device *dev, uint8_t *buf, uint32_t len);
  329. #endif /*_QDF_PLATFORM_H*/