qdf_hrtimer.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2014-2018 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_hrtimer
  28. * This file abstracts high resolution timers running in hardware context.
  29. */
  30. #ifndef _QDF_HRTIMER_H
  31. #define _QDF_HRTIMER_H
  32. #include <qdf_types.h>
  33. #include <i_qdf_hrtimer.h>
  34. #include <qdf_time.h>
  35. /* Context independent hrtimer object */
  36. typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
  37. /* Platform independent timer callback function */
  38. typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
  39. (qdf_hrtimer_data_t *timer);
  40. /**
  41. * qdf_hrtimer_start() - Starts hrtimer in given context
  42. * @timer: pointer to the qdf_hrtimer_data_t object
  43. * @interval: interval to forward as qdf_ktime_t object
  44. * @mode: mode of qdf_hrtimer_data_t
  45. *
  46. * Starts hrtimer in given context
  47. *
  48. * Return: void
  49. */
  50. static inline
  51. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  52. enum qdf_hrtimer_mode mode)
  53. {
  54. __qdf_hrtimer_start(timer, interval, mode);
  55. }
  56. /**
  57. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  58. * @timer: pointer to the qdf_hrtimer_data_t object
  59. *
  60. * Cancels hrtimer in given context
  61. *
  62. * Return: void
  63. */
  64. static inline
  65. void qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
  66. {
  67. __qdf_hrtimer_cancel(timer);
  68. }
  69. /**
  70. * qdf_hrtimer_init() - init hrtimer based on context
  71. * @timer: pointer to the qdf_hrtimer_data_t object
  72. * @callback: callback function to be fired
  73. * @qdf_clock_id: clock type
  74. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  75. * @qdf_context_mode: interrupt context mode
  76. *
  77. * starts hrtimer in a context passed as per qdf_context_mode
  78. *
  79. * Return: void
  80. */
  81. static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  82. qdf_hrtimer_func_t callback,
  83. enum qdf_clock_id clock,
  84. enum qdf_hrtimer_mode mode,
  85. enum qdf_context_mode ctx)
  86. {
  87. __qdf_hrtimer_init(timer, callback, clock, mode, ctx);
  88. }
  89. /**
  90. * qdf_hrtimer_kill() - kills hrtimer in given context
  91. * @timer: pointer to the hrtimer object
  92. *
  93. * kills hrtimer in given context
  94. *
  95. * Return: void
  96. */
  97. static inline
  98. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
  99. {
  100. __qdf_hrtimer_kill(timer);
  101. }
  102. /**
  103. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  104. * @timer: pointer to the qdf_hrtimer_data_t object
  105. *
  106. * check whether the timer is on one of the queues
  107. *
  108. * Return: remaining time as qdf_ktime_t object
  109. */
  110. static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
  111. {
  112. return __qdf_hrtimer_get_remaining(timer);
  113. }
  114. /**
  115. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  116. * @timer: pointer to the qdf_hrtimer_data_t object
  117. *
  118. * check whether the timer is on one of the queues
  119. *
  120. * Return: false when the timer was not in queue
  121. * true when the timer was in queue
  122. */
  123. static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
  124. {
  125. return __qdf_hrtimer_is_queued(timer);
  126. }
  127. /**
  128. * qdf_hrtimer_callback_running() - check if callback is running
  129. * @timer: pointer to the qdf_hrtimer_data_t object
  130. *
  131. * check whether the timer is running the callback function
  132. *
  133. * Return: false when callback is not running
  134. * true when callback is running
  135. */
  136. static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
  137. {
  138. return __qdf_hrtimer_callback_running(timer);
  139. }
  140. /**
  141. * qdf_hrtimer_active() - check if timer is active
  142. * @timer: pointer to the qdf_hrtimer_data_t object
  143. *
  144. * Check if timer is active. A timer is active, when it is enqueued into
  145. * the rbtree or the callback function is running.
  146. *
  147. * Return: false if timer is not active
  148. * true if timer is active
  149. */
  150. static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
  151. {
  152. return __qdf_hrtimer_active(timer);
  153. }
  154. /**
  155. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  156. * @timer: pointer to the qdf_hrtimer_data_t object
  157. *
  158. * Get remaining time in the hrtimer callback
  159. *
  160. * Return: time remaining as qdf_ktime_t object
  161. */
  162. static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
  163. {
  164. return __qdf_hrtimer_cb_get_time(timer);
  165. }
  166. /**
  167. * qdf_hrtimer_forward() - forward the hrtimer
  168. * @timer: pointer to the qdf_hrtimer_data_t object
  169. * @now: current time as qdf_ktime_t object
  170. * @interval: interval to forward as qdf_ktime_t object
  171. *
  172. * Forward the timer expiry so it will expire in the future
  173. *
  174. * Return: the number of overruns
  175. */
  176. static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  177. qdf_ktime_t now,
  178. qdf_ktime_t interval)
  179. {
  180. return __qdf_hrtimer_forward(timer, now, interval);
  181. }
  182. #endif /* _QDF_HRTIMER_H */