qdf_hrtimer.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * Copyright (c) 2014-2018, 2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 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. * @clock: clock type
  60. * @mode: mode of qdf_hrtimer_data_t
  61. * @ctx: 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. void qdf_hrtimer_add_expires(qdf_hrtimer_data_t *timer, qdf_ktime_t interval);
  151. #else
  152. /**
  153. * qdf_hrtimer_start() - Starts hrtimer in given context
  154. * @timer: pointer to the qdf_hrtimer_data_t object
  155. * @interval: interval to forward as qdf_ktime_t object
  156. * @mode: mode of qdf_hrtimer_data_t
  157. *
  158. * Starts hrtimer in given context
  159. *
  160. * Return: void
  161. */
  162. static inline
  163. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  164. enum qdf_hrtimer_mode mode)
  165. {
  166. __qdf_hrtimer_start(timer, interval, mode);
  167. }
  168. /**
  169. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  170. * @timer: pointer to the qdf_hrtimer_data_t object
  171. *
  172. * Cancels hrtimer in given context
  173. *
  174. * Return: int
  175. */
  176. static inline
  177. int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
  178. {
  179. return __qdf_hrtimer_cancel(timer);
  180. }
  181. /**
  182. * qdf_hrtimer_init() - init hrtimer based on context
  183. * @timer: pointer to the qdf_hrtimer_data_t object
  184. * @callback: callback function to be fired
  185. * @clock: clock type
  186. * @mode: mode of qdf_hrtimer_data_t
  187. * @ctx: interrupt context mode
  188. *
  189. * starts hrtimer in a context passed as per qdf_context_mode
  190. *
  191. * Return: void
  192. */
  193. static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  194. qdf_hrtimer_func_t callback,
  195. enum qdf_clock_id clock,
  196. enum qdf_hrtimer_mode mode,
  197. enum qdf_context_mode ctx)
  198. {
  199. __qdf_hrtimer_init(timer, callback, clock, mode, ctx);
  200. }
  201. /**
  202. * qdf_time_ms_to_ktime() - Converts milliseconds to a qdf_ktime_t object
  203. * @ms: time in milliseconds
  204. *
  205. * Return: milliseconds as qdf_ktime_t object
  206. */
  207. static inline qdf_ktime_t qdf_time_ms_to_ktime(uint64_t ms)
  208. {
  209. return __qdf_time_ms_to_ktime(ms);
  210. }
  211. /**
  212. * qdf_hrtimer_kill() - kills hrtimer in given context
  213. * @timer: pointer to the hrtimer object
  214. *
  215. * kills hrtimer in given context
  216. *
  217. * Return: void
  218. */
  219. static inline
  220. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
  221. {
  222. __qdf_hrtimer_kill(timer);
  223. }
  224. /**
  225. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  226. * @timer: pointer to the qdf_hrtimer_data_t object
  227. *
  228. * check whether the timer is on one of the queues
  229. *
  230. * Return: remaining time as qdf_ktime_t object
  231. */
  232. static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
  233. {
  234. return __qdf_hrtimer_get_remaining(timer);
  235. }
  236. /**
  237. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  238. * @timer: pointer to the qdf_hrtimer_data_t object
  239. *
  240. * check whether the timer is on one of the queues
  241. *
  242. * Return: false when the timer was not in queue
  243. * true when the timer was in queue
  244. */
  245. static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
  246. {
  247. return __qdf_hrtimer_is_queued(timer);
  248. }
  249. /**
  250. * qdf_hrtimer_callback_running() - check if callback is running
  251. * @timer: pointer to the qdf_hrtimer_data_t object
  252. *
  253. * check whether the timer is running the callback function
  254. *
  255. * Return: false when callback is not running
  256. * true when callback is running
  257. */
  258. static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
  259. {
  260. return __qdf_hrtimer_callback_running(timer);
  261. }
  262. /**
  263. * qdf_hrtimer_active() - check if timer is active
  264. * @timer: pointer to the qdf_hrtimer_data_t object
  265. *
  266. * Check if timer is active. A timer is active, when it is enqueued into
  267. * the rbtree or the callback function is running.
  268. *
  269. * Return: false if timer is not active
  270. * true if timer is active
  271. */
  272. static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
  273. {
  274. return __qdf_hrtimer_active(timer);
  275. }
  276. /**
  277. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  278. * @timer: pointer to the qdf_hrtimer_data_t object
  279. *
  280. * Get remaining time in the hrtimer callback
  281. *
  282. * Return: time remaining as qdf_ktime_t object
  283. */
  284. static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
  285. {
  286. return __qdf_hrtimer_cb_get_time(timer);
  287. }
  288. /**
  289. * qdf_hrtimer_forward() - forward the hrtimer
  290. * @timer: pointer to the qdf_hrtimer_data_t object
  291. * @now: current time as qdf_ktime_t object
  292. * @interval: interval to forward as qdf_ktime_t object
  293. *
  294. * Forward the timer expiry so it will expire in the future
  295. *
  296. * Return: the number of overruns
  297. */
  298. static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  299. qdf_ktime_t now,
  300. qdf_ktime_t interval)
  301. {
  302. return __qdf_hrtimer_forward(timer, now, interval);
  303. }
  304. /**
  305. * qdf_hrtimer_add_expires() - Add expiry to hrtimer with given interval
  306. * @timer: pointer to the qdf_hrtimer_data_t object
  307. * @interval: interval to add as qdf_ktime_t object
  308. *
  309. * Add the timer expiry so it will expire in the future
  310. *
  311. * Return: None
  312. */
  313. static inline
  314. void qdf_hrtimer_add_expires(qdf_hrtimer_data_t *timer, qdf_ktime_t interval)
  315. {
  316. return __qdf_hrtimer_add_expires(timer, interval);
  317. }
  318. #endif
  319. #endif /* _QDF_HRTIMER_H */