qdf_hrtimer.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright (c) 2014-2018, 2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_hrtimer
  20. * This file abstracts high resolution timers running in hardware context.
  21. */
  22. #ifndef _QDF_HRTIMER_H
  23. #define _QDF_HRTIMER_H
  24. #include <qdf_types.h>
  25. #include <i_qdf_hrtimer.h>
  26. #include <qdf_time.h>
  27. /* Context independent hrtimer object */
  28. typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
  29. /* Platform independent timer callback function */
  30. typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
  31. (qdf_hrtimer_data_t *timer);
  32. #ifdef ENHANCED_OS_ABSTRACTION
  33. /**
  34. * qdf_hrtimer_start() - Starts hrtimer in given context
  35. * @timer: pointer to the qdf_hrtimer_data_t object
  36. * @interval: interval to forward as qdf_ktime_t object
  37. * @mode: mode of qdf_hrtimer_data_t
  38. *
  39. * Starts hrtimer in given context
  40. *
  41. * Return: void
  42. */
  43. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  44. enum qdf_hrtimer_mode mode);
  45. /**
  46. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  47. * @timer: pointer to the qdf_hrtimer_data_t object
  48. *
  49. * Cancels hrtimer in given context
  50. *
  51. * Return: int
  52. */
  53. int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer);
  54. /**
  55. * qdf_hrtimer_init() - init hrtimer based on context
  56. * @timer: pointer to the qdf_hrtimer_data_t object
  57. * @callback: callback function to be fired
  58. * @qdf_clock_id: clock type
  59. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  60. * @qdf_context_mode: interrupt context mode
  61. *
  62. * starts hrtimer in a context passed as per qdf_context_mode
  63. *
  64. * Return: void
  65. */
  66. void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  67. qdf_hrtimer_func_t callback,
  68. enum qdf_clock_id clock,
  69. enum qdf_hrtimer_mode mode,
  70. enum qdf_context_mode ctx);
  71. /**
  72. * qdf_hrtimer_kill() - kills hrtimer in given context
  73. * @timer: pointer to the hrtimer object
  74. *
  75. * kills hrtimer in given context
  76. *
  77. * Return: void
  78. */
  79. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer);
  80. /**
  81. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  82. * @timer: pointer to the qdf_hrtimer_data_t object
  83. *
  84. * check whether the timer is on one of the queues
  85. *
  86. * Return: remaining time as qdf_ktime_t object
  87. */
  88. qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer);
  89. /**
  90. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  91. * @timer: pointer to the qdf_hrtimer_data_t object
  92. *
  93. * check whether the timer is on one of the queues
  94. *
  95. * Return: false when the timer was not in queue
  96. * true when the timer was in queue
  97. */
  98. bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer);
  99. /**
  100. * qdf_hrtimer_callback_running() - check if callback is running
  101. * @timer: pointer to the qdf_hrtimer_data_t object
  102. *
  103. * check whether the timer is running the callback function
  104. *
  105. * Return: false when callback is not running
  106. * true when callback is running
  107. */
  108. bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer);
  109. /**
  110. * qdf_hrtimer_active() - check if timer is active
  111. * @timer: pointer to the qdf_hrtimer_data_t object
  112. *
  113. * Check if timer is active. A timer is active, when it is enqueued into
  114. * the rbtree or the callback function is running.
  115. *
  116. * Return: false if timer is not active
  117. * true if timer is active
  118. */
  119. bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer);
  120. /**
  121. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  122. * @timer: pointer to the qdf_hrtimer_data_t object
  123. *
  124. * Get remaining time in the hrtimer callback
  125. *
  126. * Return: time remaining as qdf_ktime_t object
  127. */
  128. qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer);
  129. /**
  130. * qdf_hrtimer_forward() - forward the hrtimer
  131. * @timer: pointer to the qdf_hrtimer_data_t object
  132. * @now: current time as qdf_ktime_t object
  133. * @interval: interval to forward as qdf_ktime_t object
  134. *
  135. * Forward the timer expiry so it will expire in the future
  136. *
  137. * Return: the number of overruns
  138. */
  139. uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  140. qdf_ktime_t now,
  141. qdf_ktime_t interval);
  142. #else
  143. /**
  144. * qdf_hrtimer_start() - Starts hrtimer in given context
  145. * @timer: pointer to the qdf_hrtimer_data_t object
  146. * @interval: interval to forward as qdf_ktime_t object
  147. * @mode: mode of qdf_hrtimer_data_t
  148. *
  149. * Starts hrtimer in given context
  150. *
  151. * Return: void
  152. */
  153. static inline
  154. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  155. enum qdf_hrtimer_mode mode)
  156. {
  157. __qdf_hrtimer_start(timer, interval, mode);
  158. }
  159. /**
  160. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  161. * @timer: pointer to the qdf_hrtimer_data_t object
  162. *
  163. * Cancels hrtimer in given context
  164. *
  165. * Return: int
  166. */
  167. static inline
  168. int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
  169. {
  170. return __qdf_hrtimer_cancel(timer);
  171. }
  172. /**
  173. * qdf_hrtimer_init() - init hrtimer based on context
  174. * @timer: pointer to the qdf_hrtimer_data_t object
  175. * @callback: callback function to be fired
  176. * @qdf_clock_id: clock type
  177. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  178. * @qdf_context_mode: interrupt context mode
  179. *
  180. * starts hrtimer in a context passed as per qdf_context_mode
  181. *
  182. * Return: void
  183. */
  184. static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  185. qdf_hrtimer_func_t callback,
  186. enum qdf_clock_id clock,
  187. enum qdf_hrtimer_mode mode,
  188. enum qdf_context_mode ctx)
  189. {
  190. __qdf_hrtimer_init(timer, callback, clock, mode, ctx);
  191. }
  192. /**
  193. * qdf_hrtimer_kill() - kills hrtimer in given context
  194. * @timer: pointer to the hrtimer object
  195. *
  196. * kills hrtimer in given context
  197. *
  198. * Return: void
  199. */
  200. static inline
  201. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
  202. {
  203. __qdf_hrtimer_kill(timer);
  204. }
  205. /**
  206. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  207. * @timer: pointer to the qdf_hrtimer_data_t object
  208. *
  209. * check whether the timer is on one of the queues
  210. *
  211. * Return: remaining time as qdf_ktime_t object
  212. */
  213. static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
  214. {
  215. return __qdf_hrtimer_get_remaining(timer);
  216. }
  217. /**
  218. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  219. * @timer: pointer to the qdf_hrtimer_data_t object
  220. *
  221. * check whether the timer is on one of the queues
  222. *
  223. * Return: false when the timer was not in queue
  224. * true when the timer was in queue
  225. */
  226. static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
  227. {
  228. return __qdf_hrtimer_is_queued(timer);
  229. }
  230. /**
  231. * qdf_hrtimer_callback_running() - check if callback is running
  232. * @timer: pointer to the qdf_hrtimer_data_t object
  233. *
  234. * check whether the timer is running the callback function
  235. *
  236. * Return: false when callback is not running
  237. * true when callback is running
  238. */
  239. static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
  240. {
  241. return __qdf_hrtimer_callback_running(timer);
  242. }
  243. /**
  244. * qdf_hrtimer_active() - check if timer is active
  245. * @timer: pointer to the qdf_hrtimer_data_t object
  246. *
  247. * Check if timer is active. A timer is active, when it is enqueued into
  248. * the rbtree or the callback function is running.
  249. *
  250. * Return: false if timer is not active
  251. * true if timer is active
  252. */
  253. static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
  254. {
  255. return __qdf_hrtimer_active(timer);
  256. }
  257. /**
  258. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  259. * @timer: pointer to the qdf_hrtimer_data_t object
  260. *
  261. * Get remaining time in the hrtimer callback
  262. *
  263. * Return: time remaining as qdf_ktime_t object
  264. */
  265. static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
  266. {
  267. return __qdf_hrtimer_cb_get_time(timer);
  268. }
  269. /**
  270. * qdf_hrtimer_forward() - forward the hrtimer
  271. * @timer: pointer to the qdf_hrtimer_data_t object
  272. * @now: current time as qdf_ktime_t object
  273. * @interval: interval to forward as qdf_ktime_t object
  274. *
  275. * Forward the timer expiry so it will expire in the future
  276. *
  277. * Return: the number of overruns
  278. */
  279. static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  280. qdf_ktime_t now,
  281. qdf_ktime_t interval)
  282. {
  283. return __qdf_hrtimer_forward(timer, now, interval);
  284. }
  285. #endif
  286. #endif /* _QDF_HRTIMER_H */