qdf_mc_timer.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright (c) 2014-2016 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. typedef void (*qdf_mc_timer_callback_t)(void *user_data);
  48. typedef enum {
  49. QDF_TIMER_STATE_UNUSED = QDF_TIMER_STATE_COOKIE,
  50. QDF_TIMER_STATE_STOPPED,
  51. QDF_TIMER_STATE_STARTING,
  52. QDF_TIMER_STATE_RUNNING,
  53. } QDF_TIMER_STATE;
  54. #ifdef TIMER_MANAGER
  55. struct qdf_mc_timer_s;
  56. typedef struct qdf_mc_timer_node_s {
  57. qdf_list_node_t node;
  58. char *file_name;
  59. unsigned int line_num;
  60. struct qdf_mc_timer_s *qdf_timer;
  61. } qdf_mc_timer_node_t;
  62. #endif
  63. typedef struct qdf_mc_timer_s {
  64. #ifdef TIMER_MANAGER
  65. qdf_mc_timer_node_t *timer_node;
  66. #endif
  67. qdf_mc_timer_platform_t platform_info;
  68. qdf_mc_timer_callback_t callback;
  69. void *user_data;
  70. qdf_mutex_t lock;
  71. QDF_TIMER_TYPE type;
  72. QDF_TIMER_STATE state;
  73. } qdf_mc_timer_t;
  74. void qdf_try_allowing_sleep(QDF_TIMER_TYPE type);
  75. /* Function declarations and documenation */
  76. #ifdef TIMER_MANAGER
  77. void qdf_mc_timer_manager_init(void);
  78. void qdf_mc_timer_manager_exit(void);
  79. #else
  80. /**
  81. * qdf_mc_timer_manager_init() - initialize QDF debug timer manager
  82. * This API initializes QDF timer debug functionality.
  83. *
  84. * Return: none
  85. */
  86. static inline void qdf_mc_timer_manager_init(void)
  87. {
  88. }
  89. /**
  90. * qdf_mc_timer_manager_exit() - exit QDF timer debug functionality
  91. * This API exists QDF timer debug functionality
  92. *
  93. * Return: none
  94. */
  95. static inline void qdf_mc_timer_manager_exit(void)
  96. {
  97. }
  98. #endif
  99. /**
  100. * qdf_mc_timer_get_current_state() - get the current state of the timer
  101. * @timer: Pointer to timer object
  102. *
  103. * Return:
  104. * QDF_TIMER_STATE - qdf timer state
  105. */
  106. QDF_TIMER_STATE qdf_mc_timer_get_current_state(qdf_mc_timer_t *timer);
  107. /**
  108. * qdf_mc_timer_init() - initialize a QDF timer
  109. * @timer: Pointer to timer object
  110. * @timer_type: Type of timer
  111. * @callback: Callback to be called after timer expiry
  112. * @ser_data: User data which will be passed to callback function
  113. *
  114. * This API initializes a QDF Timer object.
  115. *
  116. * qdf_mc_timer_init() initializes a QDF Timer object. A timer must be
  117. * initialized by calling qdf_mc_timer_initialize() before it may be used in
  118. * any other timer functions.
  119. *
  120. * Attempting to initialize timer that is already initialized results in
  121. * a failure. A destroyed timer object can be re-initialized with a call to
  122. * qdf_mc_timer_init(). The results of otherwise referencing the object
  123. * after it has been destroyed are undefined.
  124. *
  125. * Calls to QDF timer functions to manipulate the timer such
  126. * as qdf_mc_timer_set() will fail if the timer is not initialized or has
  127. * been destroyed. Therefore, don't use the timer after it has been
  128. * destroyed until it has been re-initialized.
  129. *
  130. * All callback will be executed within the CDS main thread unless it is
  131. * initialized from the Tx thread flow, in which case it will be executed
  132. * within the tx thread flow.
  133. *
  134. * Return:
  135. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  136. * QDF failure status - Timer initialization failed
  137. */
  138. #ifdef TIMER_MANAGER
  139. #define qdf_mc_timer_init(timer, timer_type, callback, userdata) \
  140. qdf_mc_timer_init_debug(timer, timer_type, callback, userdata, \
  141. __FILE__, __LINE__)
  142. QDF_STATUS qdf_mc_timer_init_debug(qdf_mc_timer_t *timer,
  143. QDF_TIMER_TYPE timer_type,
  144. qdf_mc_timer_callback_t callback,
  145. void *user_data, char *file_name,
  146. uint32_t line_num);
  147. #else
  148. QDF_STATUS qdf_mc_timer_init(qdf_mc_timer_t *timer, QDF_TIMER_TYPE timer_type,
  149. qdf_mc_timer_callback_t callback,
  150. void *user_data);
  151. #endif
  152. /**
  153. * qdf_mc_timer_destroy() - destroy QDF timer
  154. * @timer: Pointer to timer object
  155. *
  156. * qdf_mc_timer_destroy() function shall destroy the timer object.
  157. * After a successful return from \a qdf_mc_timer_destroy() the timer
  158. * object becomes, in effect, uninitialized.
  159. *
  160. * A destroyed timer object can be re-initialized by calling
  161. * qdf_mc_timer_init(). The results of otherwise referencing the object
  162. * after it has been destroyed are undefined.
  163. *
  164. * Calls to QDF timer functions to manipulate the timer, such
  165. * as qdf_mc_timer_set() will fail if the lock is destroyed. Therefore,
  166. * don't use the timer after it has been destroyed until it has
  167. * been re-initialized.
  168. *
  169. * Return:
  170. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  171. * QDF failure status - Timer initialization failed
  172. */
  173. QDF_STATUS qdf_mc_timer_destroy(qdf_mc_timer_t *timer);
  174. /**
  175. * qdf_mc_timer_start() - start a QDF Timer object
  176. * @timer: Pointer to timer object
  177. * @expiration_time: Time to expire
  178. *
  179. * qdf_mc_timer_start() function starts a timer to expire after the
  180. * specified interval, thus running the timer callback function when
  181. * the interval expires.
  182. *
  183. * A timer only runs once (a one-shot timer). To re-start the
  184. * timer, qdf_mc_timer_start() has to be called after the timer runs
  185. * or has been cancelled.
  186. *
  187. * Return:
  188. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  189. * QDF failure status - Timer initialization failed
  190. */
  191. QDF_STATUS qdf_mc_timer_start(qdf_mc_timer_t *timer, uint32_t expiration_time);
  192. /**
  193. * qdf_mc_timer_stop() - stop a QDF Timer
  194. * @timer: Pointer to timer object
  195. * qdf_mc_timer_stop() function stops a timer that has been started but
  196. * has not expired, essentially cancelling the 'start' request.
  197. *
  198. * After a timer is stopped, it goes back to the state it was in after it
  199. * was created and can be started again via a call to qdf_mc_timer_start().
  200. *
  201. * Return:
  202. * QDF_STATUS_SUCCESS - Timer is initialized successfully
  203. * QDF failure status - Timer initialization failed
  204. */
  205. QDF_STATUS qdf_mc_timer_stop(qdf_mc_timer_t *timer);
  206. /**
  207. * qdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks
  208. *
  209. * qdf_mc_timer_get_system_ticks() function returns the current number
  210. * of timer ticks in 10msec intervals. This function is suitable timestamping
  211. * and calculating time intervals by calculating the difference between two
  212. * timestamps.
  213. *
  214. * Return:
  215. * The current system tick count (in 10msec intervals). This
  216. * function cannot fail.
  217. */
  218. unsigned long qdf_mc_timer_get_system_ticks(void);
  219. /**
  220. * qdf_mc_timer_get_system_time() - Get the system time in milliseconds
  221. *
  222. * qdf_mc_timer_get_system_time() function returns the number of milliseconds
  223. * that have elapsed since the system was started
  224. *
  225. * Return:
  226. * The current system time in milliseconds
  227. */
  228. unsigned long qdf_mc_timer_get_system_time(void);
  229. /**
  230. * qdf_timer_module_init() - initializes a QDF timer module.
  231. *
  232. * This API initializes the QDF timer module. This needs to be called
  233. * exactly once prior to using any QDF timers.
  234. *
  235. * Return: none
  236. */
  237. void qdf_timer_module_init(void);
  238. /**
  239. * qdf_timer_module_deinit() - Deinitializes a QDF timer module.
  240. *
  241. * This API deinitializes the QDF timer module.
  242. * Return: none
  243. */
  244. void qdf_timer_module_deinit(void);
  245. #endif /* __QDF_MC_TIMER_H */