qdf_time.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_time
  28. * This file abstracts time related functionality.
  29. */
  30. #ifndef _QDF_OS_TIME_H
  31. #define _QDF_OS_TIME_H
  32. #include <i_qdf_time.h>
  33. typedef __qdf_time_t qdf_time_t;
  34. /**
  35. * qdf_system_ticks - Count the number of ticks elapsed from the time when
  36. * the system booted
  37. *
  38. * Return: ticks
  39. */
  40. static inline qdf_time_t qdf_system_ticks(void)
  41. {
  42. return __qdf_system_ticks();
  43. }
  44. /**
  45. * qdf_system_ticks_to_msecs - convert ticks to milliseconds
  46. * @clock_ticks: Number of ticks
  47. *
  48. * Return: unsigned int Time in milliseconds
  49. */
  50. static inline uint32_t qdf_system_ticks_to_msecs(unsigned long clock_ticks)
  51. {
  52. return __qdf_system_ticks_to_msecs(clock_ticks);
  53. }
  54. /**
  55. * qdf_system_msecs_to_ticks - convert milliseconds to ticks
  56. * @msec: Time in milliseconds
  57. *
  58. * Return: unsigned long number of ticks
  59. */
  60. static inline qdf_time_t qdf_system_msecs_to_ticks(uint32_t msecs)
  61. {
  62. return __qdf_system_msecs_to_ticks(msecs);
  63. }
  64. /**
  65. * qdf_get_system_uptime - Return a monotonically increasing time
  66. * This increments once per HZ ticks
  67. *
  68. * Return: qdf_time_t system up time in ticks
  69. */
  70. static inline qdf_time_t qdf_get_system_uptime(void)
  71. {
  72. return __qdf_get_system_uptime();
  73. }
  74. /**
  75. * qdf_get_system_timestamp - Return current timestamp
  76. *
  77. * Return: unsigned long timestamp in ms.
  78. */
  79. static inline unsigned long qdf_get_system_timestamp(void)
  80. {
  81. return __qdf_get_system_timestamp();
  82. }
  83. /**
  84. * qdf_udelay - delay in microseconds
  85. * @usecs: Number of microseconds to delay
  86. *
  87. * Return: none
  88. */
  89. static inline void qdf_udelay(int usecs)
  90. {
  91. __qdf_udelay(usecs);
  92. }
  93. /**
  94. * qdf_mdelay - Delay in milliseconds.
  95. * @msec: Number of milliseconds to delay
  96. *
  97. * Return: none
  98. */
  99. static inline void qdf_mdelay(int msecs)
  100. {
  101. __qdf_mdelay(msecs);
  102. }
  103. /**
  104. * qdf_system_time_after() - Check if a is later than b
  105. * @a: Time stamp value a
  106. * @b: Time stamp value b
  107. *
  108. * Return:
  109. * true if a < b else false
  110. */
  111. static inline bool qdf_system_time_after(qdf_time_t a, qdf_time_t b)
  112. {
  113. return __qdf_system_time_after(a, b);
  114. }
  115. /**
  116. * qdf_system_time_before() - Check if a is before b
  117. * @a: Time stamp value a
  118. * @b: Time stamp value b
  119. *
  120. * Return:
  121. * true if a is before b else false
  122. */
  123. static inline bool qdf_system_time_before(qdf_time_t a, qdf_time_t b)
  124. {
  125. return __qdf_system_time_before(a, b);
  126. }
  127. /**
  128. * qdf_system_time_after_eq() - Check if a atleast as recent as b, if not
  129. * later
  130. * @a: Time stamp value a
  131. * @b: Time stamp value b
  132. *
  133. * Return:
  134. * true if a >= b else false
  135. */
  136. static inline bool qdf_system_time_after_eq(qdf_time_t a, qdf_time_t b)
  137. {
  138. return __qdf_system_time_after_eq(a, b);
  139. }
  140. /**
  141. * enum qdf_timestamp_unit - what unit the qdf timestamp is in
  142. * @KERNEL_LOG: boottime time in uS (micro seconds)
  143. * @QTIMER: QTIME in (1/19200)S
  144. *
  145. * This enum is used to distinguish which timer source is used.
  146. */
  147. enum qdf_timestamp_unit {
  148. KERNEL_LOG,
  149. QTIMER,
  150. };
  151. #ifdef QCA_WIFI_3_0_ADRASTEA
  152. #define QDF_LOG_TIMESTAMP_UNIT QTIMER
  153. #else
  154. #define QDF_LOG_TIMESTAMP_UNIT KERNEL_LOG
  155. #endif
  156. /**
  157. * qdf_get_log_timestamp - get time stamp for logging
  158. * For adrastea this API returns QTIMER tick which is needed to synchronize
  159. * host and fw log timestamps
  160. * For ROME and other discrete solution this API returns system boot time stamp
  161. *
  162. * Return:
  163. * QTIMER ticks(19.2MHz) for adrastea
  164. * System tick for rome and other future discrete solutions
  165. */
  166. static inline uint64_t qdf_get_log_timestamp(void)
  167. {
  168. return __qdf_get_log_timestamp();
  169. }
  170. /**
  171. * qdf_get_monotonic_boottime - get monotonic kernel boot time
  172. * This API is similar to qdf_get_system_boottime but it includes
  173. * time spent in suspend.
  174. *
  175. * Return: Time in microseconds
  176. */
  177. static inline uint64_t qdf_get_monotonic_boottime(void)
  178. {
  179. return __qdf_get_monotonic_boottime();
  180. }
  181. #endif