qdf_mc_timer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Copyright (c) 2014-2019, 2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-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_mc_timer
  21. * QCA driver framework timer APIs serialized to MC thread
  22. */
  23. #if !defined(__QDF_MC_TIMER_H)
  24. #define __QDF_MC_TIMER_H
  25. /* Include Files */
  26. #include <qdf_types.h>
  27. #include <qdf_status.h>
  28. #include <qdf_lock.h>
  29. #include <i_qdf_mc_timer.h>
  30. #ifdef TIMER_MANAGER
  31. #include <qdf_list.h>
  32. #endif
  33. /* Preprocessor definitions and constants */
  34. #define QDF_TIMER_STATE_COOKIE (0x12)
  35. #define QDF_MC_TIMER_TO_MS_UNIT (1000)
  36. #define QDF_MC_TIMER_TO_SEC_UNIT (1000000)
  37. /* Type declarations */
  38. /* qdf Timer callback function prototype (well, actually a prototype for
  39. * a pointer to this callback function)
  40. */
  41. typedef void (*qdf_mc_timer_callback_t)(void *user_data);
  42. typedef enum {
  43. QDF_TIMER_STATE_UNUSED = QDF_TIMER_STATE_COOKIE,
  44. QDF_TIMER_STATE_STOPPED,
  45. QDF_TIMER_STATE_STARTING,
  46. QDF_TIMER_STATE_RUNNING,
  47. } QDF_TIMER_STATE;
  48. #ifdef TIMER_MANAGER
  49. struct qdf_mc_timer_s;
  50. typedef struct qdf_mc_timer_node_s {
  51. qdf_list_node_t node;
  52. char *file_name;
  53. uint32_t line_num;
  54. struct qdf_mc_timer_s *qdf_timer;
  55. } qdf_mc_timer_node_t;
  56. #endif
  57. typedef struct qdf_mc_timer_s {
  58. #ifdef TIMER_MANAGER
  59. qdf_mc_timer_node_t *timer_node;
  60. #endif
  61. qdf_mc_timer_platform_t platform_info;
  62. qdf_mc_timer_callback_t callback;
  63. void *user_data;
  64. qdf_mutex_t lock;
  65. QDF_TIMER_TYPE type;
  66. QDF_TIMER_STATE state;
  67. qdf_time_t timer_start_jiffies;
  68. qdf_time_t timer_end_jiffies;
  69. } qdf_mc_timer_t;
  70. /**
  71. * qdf_try_allowing_sleep() - clean up timer states after it has been deactivated
  72. * @type: timer type
  73. *
  74. * Clean up timer states after it has been deactivated check and try to allow
  75. * sleep after a timer has been stopped or expired.
  76. *
  77. * Return: none
  78. */
  79. void qdf_try_allowing_sleep(QDF_TIMER_TYPE type);
  80. #ifdef TIMER_MANAGER
  81. /**
  82. * qdf_mc_timer_manager_init() - initialize QDF debug timer manager
  83. * This API initializes QDF timer debug functionality.
  84. *
  85. * Return: none
  86. */
  87. void qdf_mc_timer_manager_init(void);
  88. /**
  89. * qdf_mc_timer_manager_exit() - exit QDF timer debug functionality
  90. * This API exists QDF timer debug functionality
  91. *
  92. * Return: none
  93. */
  94. void qdf_mc_timer_manager_exit(void);
  95. /**
  96. * qdf_mc_timer_check_for_leaks() - Assert there are no active mc timers
  97. *
  98. * If there are active timers, this API prints them and panics.
  99. *
  100. * Return: None
  101. */
  102. void qdf_mc_timer_check_for_leaks(void);
  103. #else
  104. static inline void qdf_mc_timer_manager_init(void)
  105. {
  106. }
  107. static inline void qdf_mc_timer_manager_exit(void)
  108. {
  109. }
  110. static inline void qdf_mc_timer_check_for_leaks(void)
  111. {
  112. }
  113. #endif
  114. /**
  115. * qdf_mc_timer_get_current_state() - get the current state of the timer
  116. * @timer: Pointer to timer object
  117. *
  118. * Return:
  119. * QDF_TIMER_STATE - qdf timer state
  120. */
  121. QDF_TIMER_STATE qdf_mc_timer_get_current_state(qdf_mc_timer_t *timer);
  122. /**
  123. * qdf_mc_timer_init() - initialize a QDF timer
  124. * @timer: Pointer to timer object
  125. * @timer_type: Type of timer
  126. * @callback: Callback to be called after timer expiry
  127. * @user_data: User data which will be passed to callback function
  128. *
  129. * This API initializes a QDF Timer object.
  130. *
  131. * qdf_mc_timer_init() initializes a QDF Timer object. A timer must be
  132. * initialized by calling qdf_mc_timer_initialize() before it may be used in
  133. * any other timer functions.
  134. *
  135. * Attempting to initialize timer that is already initialized results in
  136. * a failure. A destroyed timer object can be re-initialized with a call to
  137. * qdf_mc_timer_init(). The results of otherwise referencing the object
  138. * after it has been destroyed are undefined.
  139. *
  140. * Calls to QDF timer functions to manipulate the timer such
  141. * as qdf_mc_timer_set() will fail if the timer is not initialized or has
  142. * been destroyed. Therefore, don't use the timer after it has been
  143. * destroyed until it has been re-initialized.
  144. *
  145. * All callback will be executed within the CDS main thread unless it is
  146. * initialized from the Tx thread flow, in which case it will be executed
  147. * within the tx thread flow.
  148. *
  149. * Return:
  150. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  151. * QDF failure status - Timer initialization failed
  152. */
  153. #ifdef TIMER_MANAGER
  154. #define qdf_mc_timer_init(timer, timer_type, callback, user_data) \
  155. qdf_mc_timer_init_debug(timer, timer_type, callback, user_data, \
  156. __FILE__, __LINE__)
  157. QDF_STATUS qdf_mc_timer_init_debug(qdf_mc_timer_t *timer,
  158. QDF_TIMER_TYPE timer_type,
  159. qdf_mc_timer_callback_t callback,
  160. void *user_data, char *file_name,
  161. uint32_t line_num);
  162. #else
  163. QDF_STATUS qdf_mc_timer_init(qdf_mc_timer_t *timer, QDF_TIMER_TYPE timer_type,
  164. qdf_mc_timer_callback_t callback,
  165. void *user_data);
  166. #endif
  167. /**
  168. * qdf_mc_timer_destroy() - destroy QDF timer
  169. * @timer: Pointer to timer object
  170. *
  171. * qdf_mc_timer_destroy() function shall destroy the timer object.
  172. * After a successful return from \a qdf_mc_timer_destroy() the timer
  173. * object becomes, in effect, uninitialized.
  174. *
  175. * A destroyed timer object can be re-initialized by calling
  176. * qdf_mc_timer_init(). The results of otherwise referencing the object
  177. * after it has been destroyed are undefined.
  178. *
  179. * Calls to QDF timer functions to manipulate the timer, such
  180. * as qdf_mc_timer_set() will fail if the lock is destroyed. Therefore,
  181. * don't use the timer after it has been destroyed until it has
  182. * been re-initialized.
  183. *
  184. * Return:
  185. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  186. * QDF failure status - Timer initialization failed
  187. */
  188. QDF_STATUS qdf_mc_timer_destroy(qdf_mc_timer_t *timer);
  189. /**
  190. * qdf_mc_timer_start() - start a QDF Timer object
  191. * @timer: Pointer to timer object
  192. * @expiration_time: Time to expire
  193. *
  194. * qdf_mc_timer_start() function starts a timer to expire after the
  195. * specified interval, thus running the timer callback function when
  196. * the interval expires.
  197. *
  198. * A timer only runs once (a one-shot timer). To re-start the
  199. * timer, qdf_mc_timer_start() has to be called after the timer runs
  200. * or has been cancelled.
  201. *
  202. * Return:
  203. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  204. * QDF failure status - Timer initialization failed
  205. */
  206. QDF_STATUS qdf_mc_timer_start(qdf_mc_timer_t *timer, uint32_t expiration_time);
  207. /**
  208. * qdf_mc_timer_stop() - stop a QDF Timer
  209. * @timer: Pointer to timer object
  210. * qdf_mc_timer_stop() function stops a timer that has been started but
  211. * has not expired, essentially cancelling the 'start' request.
  212. *
  213. * After a timer is stopped, it goes back to the state it was in after it
  214. * was created and can be started again via a call to qdf_mc_timer_start().
  215. *
  216. * Return:
  217. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  218. * QDF failure status - Timer initialization failed
  219. */
  220. QDF_STATUS qdf_mc_timer_stop(qdf_mc_timer_t *timer);
  221. /**
  222. * qdf_mc_timer_stop_sync() - stop a QDF Timer
  223. * @timer: Pointer to timer object
  224. * qdf_mc_timer_stop_sync() function stops a timer synchronously
  225. * that has been started but has not expired, essentially
  226. * cancelling the 'start' request.
  227. *
  228. * After a timer is stopped, it goes back to the state it was in after it
  229. * was created and can be started again via a call to qdf_mc_timer_start().
  230. *
  231. * Return:
  232. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  233. * QDF failure status - Timer initialization failed
  234. */
  235. QDF_STATUS qdf_mc_timer_stop_sync(qdf_mc_timer_t *timer);
  236. /**
  237. * qdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks
  238. *
  239. * qdf_mc_timer_get_system_ticks() function returns the current number
  240. * of timer ticks in 10msec intervals. This function is suitable timestamping
  241. * and calculating time intervals by calculating the difference between two
  242. * timestamps.
  243. *
  244. * Return:
  245. * The current system tick count (in 10msec intervals). This
  246. * function cannot fail.
  247. */
  248. unsigned long qdf_mc_timer_get_system_ticks(void);
  249. /**
  250. * qdf_mc_timer_get_system_time() - Get the system time in milliseconds
  251. *
  252. * qdf_mc_timer_get_system_time() function returns the number of milliseconds
  253. * that have elapsed since the system was started
  254. *
  255. * Return:
  256. * The current system time in milliseconds
  257. */
  258. unsigned long qdf_mc_timer_get_system_time(void);
  259. /**
  260. * qdf_get_monotonic_boottime_ns() - Get kernel boottime in ns
  261. *
  262. * Return: kernel boottime in nano sec (includes time spent in suspend)
  263. */
  264. s64 qdf_get_monotonic_boottime_ns(void);
  265. /**
  266. * qdf_timer_module_init() - initializes a QDF timer module.
  267. *
  268. * This API initializes the QDF timer module. This needs to be called
  269. * exactly once prior to using any QDF timers.
  270. *
  271. * Return: none
  272. */
  273. void qdf_timer_module_init(void);
  274. /**
  275. * qdf_get_time_of_the_day_us() - Get time of the day in microseconds
  276. *
  277. * Return: None
  278. */
  279. uint64_t qdf_get_time_of_the_day_us(void);
  280. /**
  281. * qdf_get_time_of_the_day_ms() - get time of the day in millisec
  282. *
  283. * Return: time of the day in ms
  284. */
  285. qdf_time_t qdf_get_time_of_the_day_ms(void);
  286. /**
  287. * qdf_timer_module_deinit() - Deinitializes the QDF timer module.
  288. *
  289. * This API deinitializes the QDF timer module.
  290. * Return: none
  291. */
  292. void qdf_timer_module_deinit(void);
  293. /**
  294. * qdf_get_time_of_the_day_in_hr_min_sec_usec() - Get system time
  295. * @tbuf: Pointer to time stamp buffer
  296. * @len: Time buffer size
  297. *
  298. * This function updates the 'tbuf' with system time in hr:min:sec:msec format
  299. *
  300. * Return: None
  301. */
  302. void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len);
  303. void qdf_register_mc_timer_callback(void (*callback) (qdf_mc_timer_t *data));
  304. /**
  305. * qdf_timer_set_multiplier() - set the global QDF timer scalar value
  306. * @multiplier: the scalar value to apply
  307. *
  308. * Return: None
  309. */
  310. void qdf_timer_set_multiplier(uint32_t multiplier);
  311. /**
  312. * qdf_timer_get_multiplier() - get the global QDF timer scalar value
  313. *
  314. * Return: the global QDF timer scalar value
  315. */
  316. uint32_t qdf_timer_get_multiplier(void);
  317. #endif /* __QDF_MC_TIMER_H */