qdf_mc_timer.h 9.1 KB

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