qdf_mc_timer.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /**
  27. * DOC: qdf_mc_timer
  28. * QCA driver framework timer APIs serialized to MC thread
  29. */
  30. #if !defined(__QDF_MC_TIMER_H)
  31. #define __QDF_MC_TIMER_H
  32. /* Include Files */
  33. #include <qdf_types.h>
  34. #include <qdf_status.h>
  35. #include <qdf_lock.h>
  36. #include <i_qdf_mc_timer.h>
  37. #ifdef TIMER_MANAGER
  38. #include <qdf_list.h>
  39. #endif
  40. /* Preprocessor definitions and constants */
  41. #define QDF_TIMER_STATE_COOKIE (0x12)
  42. #define QDF_MC_TIMER_TO_MS_UNIT (1000)
  43. #define QDF_MC_TIMER_TO_SEC_UNIT (1000000)
  44. /* Type declarations */
  45. /* qdf Timer callback function prototype (well, actually a prototype for
  46. * a pointer to this callback function)
  47. */
  48. typedef void (*qdf_mc_timer_callback_t)(void *user_data);
  49. typedef enum {
  50. QDF_TIMER_STATE_UNUSED = QDF_TIMER_STATE_COOKIE,
  51. QDF_TIMER_STATE_STOPPED,
  52. QDF_TIMER_STATE_STARTING,
  53. QDF_TIMER_STATE_RUNNING,
  54. } QDF_TIMER_STATE;
  55. #ifdef TIMER_MANAGER
  56. struct qdf_mc_timer_s;
  57. typedef struct qdf_mc_timer_node_s {
  58. qdf_list_node_t node;
  59. char *file_name;
  60. uint32_t line_num;
  61. struct qdf_mc_timer_s *qdf_timer;
  62. } qdf_mc_timer_node_t;
  63. #endif
  64. typedef struct qdf_mc_timer_s {
  65. #ifdef TIMER_MANAGER
  66. qdf_mc_timer_node_t *timer_node;
  67. #endif
  68. qdf_mc_timer_platform_t platform_info;
  69. qdf_mc_timer_callback_t callback;
  70. void *user_data;
  71. qdf_mutex_t lock;
  72. QDF_TIMER_TYPE type;
  73. QDF_TIMER_STATE state;
  74. } qdf_mc_timer_t;
  75. void qdf_try_allowing_sleep(QDF_TIMER_TYPE type);
  76. /* Function declarations and documenation */
  77. #ifdef TIMER_MANAGER
  78. void qdf_mc_timer_manager_init(void);
  79. void qdf_mc_timer_manager_exit(void);
  80. void qdf_mc_timer_check_for_leaks(void);
  81. #else
  82. /**
  83. * qdf_mc_timer_manager_init() - initialize QDF debug timer manager
  84. * This API initializes QDF timer debug functionality.
  85. *
  86. * Return: none
  87. */
  88. static inline void qdf_mc_timer_manager_init(void)
  89. {
  90. }
  91. /**
  92. * qdf_mc_timer_manager_exit() - exit QDF timer debug functionality
  93. * This API exists QDF timer debug functionality
  94. *
  95. * Return: none
  96. */
  97. static inline void qdf_mc_timer_manager_exit(void)
  98. {
  99. }
  100. /**
  101. * qdf_mc_timer_check_for_leaks() - Assert there are no active mc timers
  102. *
  103. * If there are active timers, this API prints them and panics.
  104. *
  105. * Return: None
  106. */
  107. static inline void qdf_mc_timer_check_for_leaks(void) { }
  108. #endif
  109. /**
  110. * qdf_mc_timer_get_current_state() - get the current state of the timer
  111. * @timer: Pointer to timer object
  112. *
  113. * Return:
  114. * QDF_TIMER_STATE - qdf timer state
  115. */
  116. QDF_TIMER_STATE qdf_mc_timer_get_current_state(qdf_mc_timer_t *timer);
  117. /**
  118. * qdf_mc_timer_init() - initialize a QDF timer
  119. * @timer: Pointer to timer object
  120. * @timer_type: Type of timer
  121. * @callback: Callback to be called after timer expiry
  122. * @ser_data: User data which will be passed to callback function
  123. *
  124. * This API initializes a QDF Timer object.
  125. *
  126. * qdf_mc_timer_init() initializes a QDF Timer object. A timer must be
  127. * initialized by calling qdf_mc_timer_initialize() before it may be used in
  128. * any other timer functions.
  129. *
  130. * Attempting to initialize timer that is already initialized results in
  131. * a failure. A destroyed timer object can be re-initialized with a call to
  132. * qdf_mc_timer_init(). The results of otherwise referencing the object
  133. * after it has been destroyed are undefined.
  134. *
  135. * Calls to QDF timer functions to manipulate the timer such
  136. * as qdf_mc_timer_set() will fail if the timer is not initialized or has
  137. * been destroyed. Therefore, don't use the timer after it has been
  138. * destroyed until it has been re-initialized.
  139. *
  140. * All callback will be executed within the CDS main thread unless it is
  141. * initialized from the Tx thread flow, in which case it will be executed
  142. * within the tx thread flow.
  143. *
  144. * Return:
  145. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  146. * QDF failure status - Timer initialization failed
  147. */
  148. #ifdef TIMER_MANAGER
  149. #define qdf_mc_timer_init(timer, timer_type, callback, userdata) \
  150. qdf_mc_timer_init_debug(timer, timer_type, callback, userdata, \
  151. __FILE__, __LINE__)
  152. QDF_STATUS qdf_mc_timer_init_debug(qdf_mc_timer_t *timer,
  153. QDF_TIMER_TYPE timer_type,
  154. qdf_mc_timer_callback_t callback,
  155. void *user_data, char *file_name,
  156. uint32_t line_num);
  157. #else
  158. QDF_STATUS qdf_mc_timer_init(qdf_mc_timer_t *timer, QDF_TIMER_TYPE timer_type,
  159. qdf_mc_timer_callback_t callback,
  160. void *user_data);
  161. #endif
  162. /**
  163. * qdf_mc_timer_destroy() - destroy QDF timer
  164. * @timer: Pointer to timer object
  165. *
  166. * qdf_mc_timer_destroy() function shall destroy the timer object.
  167. * After a successful return from \a qdf_mc_timer_destroy() the timer
  168. * object becomes, in effect, uninitialized.
  169. *
  170. * A destroyed timer object can be re-initialized by calling
  171. * qdf_mc_timer_init(). The results of otherwise referencing the object
  172. * after it has been destroyed are undefined.
  173. *
  174. * Calls to QDF timer functions to manipulate the timer, such
  175. * as qdf_mc_timer_set() will fail if the lock is destroyed. Therefore,
  176. * don't use the timer after it has been destroyed until it has
  177. * been re-initialized.
  178. *
  179. * Return:
  180. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  181. * QDF failure status - Timer initialization failed
  182. */
  183. QDF_STATUS qdf_mc_timer_destroy(qdf_mc_timer_t *timer);
  184. /**
  185. * qdf_mc_timer_start() - start a QDF Timer object
  186. * @timer: Pointer to timer object
  187. * @expiration_time: Time to expire
  188. *
  189. * qdf_mc_timer_start() function starts a timer to expire after the
  190. * specified interval, thus running the timer callback function when
  191. * the interval expires.
  192. *
  193. * A timer only runs once (a one-shot timer). To re-start the
  194. * timer, qdf_mc_timer_start() has to be called after the timer runs
  195. * or has been cancelled.
  196. *
  197. * Return:
  198. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  199. * QDF failure status - Timer initialization failed
  200. */
  201. QDF_STATUS qdf_mc_timer_start(qdf_mc_timer_t *timer, uint32_t expiration_time);
  202. /**
  203. * qdf_mc_timer_stop() - stop a QDF Timer
  204. * @timer: Pointer to timer object
  205. * qdf_mc_timer_stop() function stops a timer that has been started but
  206. * has not expired, essentially cancelling the 'start' request.
  207. *
  208. * After a timer is stopped, it goes back to the state it was in after it
  209. * was created and can be started again via a call to qdf_mc_timer_start().
  210. *
  211. * Return:
  212. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  213. * QDF failure status - Timer initialization failed
  214. */
  215. QDF_STATUS qdf_mc_timer_stop(qdf_mc_timer_t *timer);
  216. /**
  217. * qdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks
  218. *
  219. * qdf_mc_timer_get_system_ticks() function returns the current number
  220. * of timer ticks in 10msec intervals. This function is suitable timestamping
  221. * and calculating time intervals by calculating the difference between two
  222. * timestamps.
  223. *
  224. * Return:
  225. * The current system tick count (in 10msec intervals). This
  226. * function cannot fail.
  227. */
  228. unsigned long qdf_mc_timer_get_system_ticks(void);
  229. /**
  230. * qdf_mc_timer_get_system_time() - Get the system time in milliseconds
  231. *
  232. * qdf_mc_timer_get_system_time() function returns the number of milliseconds
  233. * that have elapsed since the system was started
  234. *
  235. * Return:
  236. * The current system time in milliseconds
  237. */
  238. unsigned long qdf_mc_timer_get_system_time(void);
  239. /**
  240. * qdf_get_monotonic_boottime_ns() - Get kernel boottime in ns
  241. *
  242. * Return: kernel boottime in nano sec
  243. */
  244. s64 qdf_get_monotonic_boottime_ns(void);
  245. /**
  246. * qdf_timer_module_init() - initializes a QDF timer module.
  247. *
  248. * This API initializes the QDF timer module. This needs to be called
  249. * exactly once prior to using any QDF timers.
  250. *
  251. * Return: none
  252. */
  253. void qdf_timer_module_init(void);
  254. /**
  255. * qdf_timer_module_deinit() - Deinitializes a QDF timer module.
  256. *
  257. * This API deinitializes the QDF timer module.
  258. * Return: none
  259. */
  260. void qdf_timer_module_deinit(void);
  261. /**
  262. * qdf_get_time_of_the_day_in_hr_min_sec_usec() - Get system time
  263. * @tbuf: Pointer to time stamp buffer
  264. * @len: Time buffer size
  265. *
  266. * This function updates the 'tbuf' with system time in hr:min:sec:msec format
  267. *
  268. * Return: None
  269. */
  270. void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len);
  271. void qdf_register_mc_timer_callback(void (*callback) (unsigned long data));
  272. /**
  273. * qdf_timer_set_multiplier() - set the global QDF timer scalar value
  274. * @multiplier: the scalar value to apply
  275. *
  276. * Return: None
  277. */
  278. void qdf_timer_set_multiplier(uint32_t multiplier);
  279. /**
  280. * qdf_timer_get_multiplier() - get the global QDF timer scalar value
  281. *
  282. * Return: the global QDF timer scalar value
  283. */
  284. uint32_t qdf_timer_get_multiplier(void);
  285. #endif /* __QDF_MC_TIMER_H */