qdf_hrtimer.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Copyright (c) 2014-2018, 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_hrtimer
  21. * This file abstracts high resolution timers running in hardware context.
  22. */
  23. #ifndef _QDF_HRTIMER_H
  24. #define _QDF_HRTIMER_H
  25. #include <qdf_types.h>
  26. #include <i_qdf_hrtimer.h>
  27. #include <qdf_time.h>
  28. /* Context independent hrtimer object */
  29. typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
  30. /* Platform independent timer callback function */
  31. typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
  32. (qdf_hrtimer_data_t *timer);
  33. #ifdef ENHANCED_OS_ABSTRACTION
  34. /**
  35. * qdf_hrtimer_start() - Starts hrtimer in given context
  36. * @timer: pointer to the qdf_hrtimer_data_t object
  37. * @interval: interval to forward as qdf_ktime_t object
  38. * @mode: mode of qdf_hrtimer_data_t
  39. *
  40. * Starts hrtimer in given context
  41. *
  42. * Return: void
  43. */
  44. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  45. enum qdf_hrtimer_mode mode);
  46. /**
  47. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  48. * @timer: pointer to the qdf_hrtimer_data_t object
  49. *
  50. * Cancels hrtimer in given context
  51. *
  52. * Return: int
  53. */
  54. int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer);
  55. /**
  56. * qdf_hrtimer_init() - init hrtimer based on context
  57. * @timer: pointer to the qdf_hrtimer_data_t object
  58. * @callback: callback function to be fired
  59. * @qdf_clock_id: clock type
  60. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  61. * @qdf_context_mode: interrupt context mode
  62. *
  63. * starts hrtimer in a context passed as per qdf_context_mode
  64. *
  65. * Return: void
  66. */
  67. void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  68. qdf_hrtimer_func_t callback,
  69. enum qdf_clock_id clock,
  70. enum qdf_hrtimer_mode mode,
  71. enum qdf_context_mode ctx);
  72. /**
  73. * qdf_time_ms_to_ktime() - Converts milliseconds to a qdf_ktime_t object
  74. * @ms: time in milliseconds
  75. *
  76. * Return: milliseconds as ktime object
  77. */
  78. qdf_ktime_t qdf_time_ms_to_ktime(uint64_t ms);
  79. /**
  80. * qdf_hrtimer_kill() - kills hrtimer in given context
  81. * @timer: pointer to the hrtimer object
  82. *
  83. * kills hrtimer in given context
  84. *
  85. * Return: void
  86. */
  87. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer);
  88. /**
  89. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  90. * @timer: pointer to the qdf_hrtimer_data_t object
  91. *
  92. * check whether the timer is on one of the queues
  93. *
  94. * Return: remaining time as qdf_ktime_t object
  95. */
  96. qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer);
  97. /**
  98. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  99. * @timer: pointer to the qdf_hrtimer_data_t object
  100. *
  101. * check whether the timer is on one of the queues
  102. *
  103. * Return: false when the timer was not in queue
  104. * true when the timer was in queue
  105. */
  106. bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer);
  107. /**
  108. * qdf_hrtimer_callback_running() - check if callback is running
  109. * @timer: pointer to the qdf_hrtimer_data_t object
  110. *
  111. * check whether the timer is running the callback function
  112. *
  113. * Return: false when callback is not running
  114. * true when callback is running
  115. */
  116. bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer);
  117. /**
  118. * qdf_hrtimer_active() - check if timer is active
  119. * @timer: pointer to the qdf_hrtimer_data_t object
  120. *
  121. * Check if timer is active. A timer is active, when it is enqueued into
  122. * the rbtree or the callback function is running.
  123. *
  124. * Return: false if timer is not active
  125. * true if timer is active
  126. */
  127. bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer);
  128. /**
  129. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  130. * @timer: pointer to the qdf_hrtimer_data_t object
  131. *
  132. * Get remaining time in the hrtimer callback
  133. *
  134. * Return: time remaining as qdf_ktime_t object
  135. */
  136. qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer);
  137. /**
  138. * qdf_hrtimer_forward() - forward the hrtimer
  139. * @timer: pointer to the qdf_hrtimer_data_t object
  140. * @now: current time as qdf_ktime_t object
  141. * @interval: interval to forward as qdf_ktime_t object
  142. *
  143. * Forward the timer expiry so it will expire in the future
  144. *
  145. * Return: the number of overruns
  146. */
  147. uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  148. qdf_ktime_t now,
  149. qdf_ktime_t interval);
  150. #else
  151. /**
  152. * qdf_hrtimer_start() - Starts hrtimer in given context
  153. * @timer: pointer to the qdf_hrtimer_data_t object
  154. * @interval: interval to forward as qdf_ktime_t object
  155. * @mode: mode of qdf_hrtimer_data_t
  156. *
  157. * Starts hrtimer in given context
  158. *
  159. * Return: void
  160. */
  161. static inline
  162. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  163. enum qdf_hrtimer_mode mode)
  164. {
  165. __qdf_hrtimer_start(timer, interval, mode);
  166. }
  167. /**
  168. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  169. * @timer: pointer to the qdf_hrtimer_data_t object
  170. *
  171. * Cancels hrtimer in given context
  172. *
  173. * Return: int
  174. */
  175. static inline
  176. int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
  177. {
  178. return __qdf_hrtimer_cancel(timer);
  179. }
  180. /**
  181. * qdf_hrtimer_init() - init hrtimer based on context
  182. * @timer: pointer to the qdf_hrtimer_data_t object
  183. * @callback: callback function to be fired
  184. * @qdf_clock_id: clock type
  185. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  186. * @qdf_context_mode: interrupt context mode
  187. *
  188. * starts hrtimer in a context passed as per qdf_context_mode
  189. *
  190. * Return: void
  191. */
  192. static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  193. qdf_hrtimer_func_t callback,
  194. enum qdf_clock_id clock,
  195. enum qdf_hrtimer_mode mode,
  196. enum qdf_context_mode ctx)
  197. {
  198. __qdf_hrtimer_init(timer, callback, clock, mode, ctx);
  199. }
  200. /**
  201. * qdf_time_ms_to_ktime() - Converts milliseconds to a qdf_ktime_t object
  202. * @ms: time in milliseconds
  203. *
  204. * Return: milliseconds as qdf_ktime_t object
  205. */
  206. static inline qdf_ktime_t qdf_time_ms_to_ktime(uint64_t ms)
  207. {
  208. return __qdf_time_ms_to_ktime(ms);
  209. }
  210. /**
  211. * qdf_hrtimer_kill() - kills hrtimer in given context
  212. * @timer: pointer to the hrtimer object
  213. *
  214. * kills hrtimer in given context
  215. *
  216. * Return: void
  217. */
  218. static inline
  219. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
  220. {
  221. __qdf_hrtimer_kill(timer);
  222. }
  223. /**
  224. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  225. * @timer: pointer to the qdf_hrtimer_data_t object
  226. *
  227. * check whether the timer is on one of the queues
  228. *
  229. * Return: remaining time as qdf_ktime_t object
  230. */
  231. static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
  232. {
  233. return __qdf_hrtimer_get_remaining(timer);
  234. }
  235. /**
  236. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  237. * @timer: pointer to the qdf_hrtimer_data_t object
  238. *
  239. * check whether the timer is on one of the queues
  240. *
  241. * Return: false when the timer was not in queue
  242. * true when the timer was in queue
  243. */
  244. static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
  245. {
  246. return __qdf_hrtimer_is_queued(timer);
  247. }
  248. /**
  249. * qdf_hrtimer_callback_running() - check if callback is running
  250. * @timer: pointer to the qdf_hrtimer_data_t object
  251. *
  252. * check whether the timer is running the callback function
  253. *
  254. * Return: false when callback is not running
  255. * true when callback is running
  256. */
  257. static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
  258. {
  259. return __qdf_hrtimer_callback_running(timer);
  260. }
  261. /**
  262. * qdf_hrtimer_active() - check if timer is active
  263. * @timer: pointer to the qdf_hrtimer_data_t object
  264. *
  265. * Check if timer is active. A timer is active, when it is enqueued into
  266. * the rbtree or the callback function is running.
  267. *
  268. * Return: false if timer is not active
  269. * true if timer is active
  270. */
  271. static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
  272. {
  273. return __qdf_hrtimer_active(timer);
  274. }
  275. /**
  276. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  277. * @timer: pointer to the qdf_hrtimer_data_t object
  278. *
  279. * Get remaining time in the hrtimer callback
  280. *
  281. * Return: time remaining as qdf_ktime_t object
  282. */
  283. static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
  284. {
  285. return __qdf_hrtimer_cb_get_time(timer);
  286. }
  287. /**
  288. * qdf_hrtimer_forward() - forward the hrtimer
  289. * @timer: pointer to the qdf_hrtimer_data_t object
  290. * @now: current time as qdf_ktime_t object
  291. * @interval: interval to forward as qdf_ktime_t object
  292. *
  293. * Forward the timer expiry so it will expire in the future
  294. *
  295. * Return: the number of overruns
  296. */
  297. static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  298. qdf_ktime_t now,
  299. qdf_ktime_t interval)
  300. {
  301. return __qdf_hrtimer_forward(timer, now, interval);
  302. }
  303. #endif
  304. #endif /* _QDF_HRTIMER_H */