qdf_mc_timer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * Copyright (c) 2014-2019, 2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 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. void qdf_try_allowing_sleep(QDF_TIMER_TYPE type);
  71. /* Function declarations and documenation */
  72. #ifdef TIMER_MANAGER
  73. void qdf_mc_timer_manager_init(void);
  74. void qdf_mc_timer_manager_exit(void);
  75. void qdf_mc_timer_check_for_leaks(void);
  76. #else
  77. /**
  78. * qdf_mc_timer_manager_init() - initialize QDF debug timer manager
  79. * This API initializes QDF timer debug functionality.
  80. *
  81. * Return: none
  82. */
  83. static inline void qdf_mc_timer_manager_init(void)
  84. {
  85. }
  86. /**
  87. * qdf_mc_timer_manager_exit() - exit QDF timer debug functionality
  88. * This API exists QDF timer debug functionality
  89. *
  90. * Return: none
  91. */
  92. static inline void qdf_mc_timer_manager_exit(void)
  93. {
  94. }
  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. static inline void qdf_mc_timer_check_for_leaks(void) { }
  103. #endif
  104. /**
  105. * qdf_mc_timer_get_current_state() - get the current state of the timer
  106. * @timer: Pointer to timer object
  107. *
  108. * Return:
  109. * QDF_TIMER_STATE - qdf timer state
  110. */
  111. QDF_TIMER_STATE qdf_mc_timer_get_current_state(qdf_mc_timer_t *timer);
  112. /**
  113. * qdf_mc_timer_init() - initialize a QDF timer
  114. * @timer: Pointer to timer object
  115. * @timer_type: Type of timer
  116. * @callback: Callback to be called after timer expiry
  117. * @ser_data: User data which will be passed to callback function
  118. *
  119. * This API initializes a QDF Timer object.
  120. *
  121. * qdf_mc_timer_init() initializes a QDF Timer object. A timer must be
  122. * initialized by calling qdf_mc_timer_initialize() before it may be used in
  123. * any other timer functions.
  124. *
  125. * Attempting to initialize timer that is already initialized results in
  126. * a failure. A destroyed timer object can be re-initialized with a call to
  127. * qdf_mc_timer_init(). The results of otherwise referencing the object
  128. * after it has been destroyed are undefined.
  129. *
  130. * Calls to QDF timer functions to manipulate the timer such
  131. * as qdf_mc_timer_set() will fail if the timer is not initialized or has
  132. * been destroyed. Therefore, don't use the timer after it has been
  133. * destroyed until it has been re-initialized.
  134. *
  135. * All callback will be executed within the CDS main thread unless it is
  136. * initialized from the Tx thread flow, in which case it will be executed
  137. * within the tx thread flow.
  138. *
  139. * Return:
  140. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  141. * QDF failure status - Timer initialization failed
  142. */
  143. #ifdef TIMER_MANAGER
  144. #define qdf_mc_timer_init(timer, timer_type, callback, userdata) \
  145. qdf_mc_timer_init_debug(timer, timer_type, callback, userdata, \
  146. __FILE__, __LINE__)
  147. QDF_STATUS qdf_mc_timer_init_debug(qdf_mc_timer_t *timer,
  148. QDF_TIMER_TYPE timer_type,
  149. qdf_mc_timer_callback_t callback,
  150. void *user_data, char *file_name,
  151. uint32_t line_num);
  152. #else
  153. QDF_STATUS qdf_mc_timer_init(qdf_mc_timer_t *timer, QDF_TIMER_TYPE timer_type,
  154. qdf_mc_timer_callback_t callback,
  155. void *user_data);
  156. #endif
  157. /**
  158. * qdf_mc_timer_destroy() - destroy QDF timer
  159. * @timer: Pointer to timer object
  160. *
  161. * qdf_mc_timer_destroy() function shall destroy the timer object.
  162. * After a successful return from \a qdf_mc_timer_destroy() the timer
  163. * object becomes, in effect, uninitialized.
  164. *
  165. * A destroyed timer object can be re-initialized by calling
  166. * qdf_mc_timer_init(). The results of otherwise referencing the object
  167. * after it has been destroyed are undefined.
  168. *
  169. * Calls to QDF timer functions to manipulate the timer, such
  170. * as qdf_mc_timer_set() will fail if the lock is destroyed. Therefore,
  171. * don't use the timer after it has been destroyed until it has
  172. * been re-initialized.
  173. *
  174. * Return:
  175. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  176. * QDF failure status - Timer initialization failed
  177. */
  178. QDF_STATUS qdf_mc_timer_destroy(qdf_mc_timer_t *timer);
  179. /**
  180. * qdf_mc_timer_start() - start a QDF Timer object
  181. * @timer: Pointer to timer object
  182. * @expiration_time: Time to expire
  183. *
  184. * qdf_mc_timer_start() function starts a timer to expire after the
  185. * specified interval, thus running the timer callback function when
  186. * the interval expires.
  187. *
  188. * A timer only runs once (a one-shot timer). To re-start the
  189. * timer, qdf_mc_timer_start() has to be called after the timer runs
  190. * or has been cancelled.
  191. *
  192. * Return:
  193. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  194. * QDF failure status - Timer initialization failed
  195. */
  196. QDF_STATUS qdf_mc_timer_start(qdf_mc_timer_t *timer, uint32_t expiration_time);
  197. /**
  198. * qdf_mc_timer_stop() - stop a QDF Timer
  199. * @timer: Pointer to timer object
  200. * qdf_mc_timer_stop() function stops a timer that has been started but
  201. * has not expired, essentially cancelling the 'start' request.
  202. *
  203. * After a timer is stopped, it goes back to the state it was in after it
  204. * was created and can be started again via a call to qdf_mc_timer_start().
  205. *
  206. * Return:
  207. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  208. * QDF failure status - Timer initialization failed
  209. */
  210. QDF_STATUS qdf_mc_timer_stop(qdf_mc_timer_t *timer);
  211. /**
  212. * qdf_mc_timer_stop_sync() - stop a QDF Timer
  213. * @timer: Pointer to timer object
  214. * qdf_mc_timer_stop_sync() function stops a timer synchronously
  215. * that has been started but has not expired, essentially
  216. * cancelling the 'start' request.
  217. *
  218. * After a timer is stopped, it goes back to the state it was in after it
  219. * was created and can be started again via a call to qdf_mc_timer_start().
  220. *
  221. * Return:
  222. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  223. * QDF failure status - Timer initialization failed
  224. */
  225. QDF_STATUS qdf_mc_timer_stop_sync(qdf_mc_timer_t *timer);
  226. /**
  227. * qdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks
  228. *
  229. * qdf_mc_timer_get_system_ticks() function returns the current number
  230. * of timer ticks in 10msec intervals. This function is suitable timestamping
  231. * and calculating time intervals by calculating the difference between two
  232. * timestamps.
  233. *
  234. * Return:
  235. * The current system tick count (in 10msec intervals). This
  236. * function cannot fail.
  237. */
  238. unsigned long qdf_mc_timer_get_system_ticks(void);
  239. /**
  240. * qdf_mc_timer_get_system_time() - Get the system time in milliseconds
  241. *
  242. * qdf_mc_timer_get_system_time() function returns the number of milliseconds
  243. * that have elapsed since the system was started
  244. *
  245. * Return:
  246. * The current system time in milliseconds
  247. */
  248. unsigned long qdf_mc_timer_get_system_time(void);
  249. /**
  250. * qdf_get_monotonic_boottime_ns() - Get kernel boottime in ns
  251. *
  252. * Return: kernel boottime in nano sec (includes time spent in suspend)
  253. */
  254. s64 qdf_get_monotonic_boottime_ns(void);
  255. /**
  256. * qdf_timer_module_init() - initializes a QDF timer module.
  257. *
  258. * This API initializes the QDF timer module. This needs to be called
  259. * exactly once prior to using any QDF timers.
  260. *
  261. * Return: none
  262. */
  263. void qdf_timer_module_init(void);
  264. /**
  265. * qdf_get_time_of_the_day_us() - Get time of the day in microseconds
  266. *
  267. * Return: None
  268. */
  269. uint64_t qdf_get_time_of_the_day_us(void);
  270. /**
  271. * qdf_get_time_of_the_day_ms() - get time of the day in millisec
  272. *
  273. * Return: time of the day in ms
  274. */
  275. qdf_time_t qdf_get_time_of_the_day_ms(void);
  276. /**
  277. * qdf_timer_module_deinit() - Deinitializes a QDF timer module.
  278. *
  279. * This API deinitializes the QDF timer module.
  280. * Return: none
  281. */
  282. void qdf_timer_module_deinit(void);
  283. /**
  284. * qdf_get_time_of_the_day_in_hr_min_sec_usec() - Get system time
  285. * @tbuf: Pointer to time stamp buffer
  286. * @len: Time buffer size
  287. *
  288. * This function updates the 'tbuf' with system time in hr:min:sec:msec format
  289. *
  290. * Return: None
  291. */
  292. void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len);
  293. void qdf_register_mc_timer_callback(void (*callback) (qdf_mc_timer_t *data));
  294. /**
  295. * qdf_timer_set_multiplier() - set the global QDF timer scalar value
  296. * @multiplier: the scalar value to apply
  297. *
  298. * Return: None
  299. */
  300. void qdf_timer_set_multiplier(uint32_t multiplier);
  301. /**
  302. * qdf_timer_get_multiplier() - get the global QDF timer scalar value
  303. *
  304. * Return: the global QDF timer scalar value
  305. */
  306. uint32_t qdf_timer_get_multiplier(void);
  307. #endif /* __QDF_MC_TIMER_H */