qdf_time.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2014-2015 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: cdf_time
  28. * This file abstracts time related functionality.
  29. */
  30. #ifndef _CDF_OS_TIME_H
  31. #define _CDF_OS_TIME_H
  32. #include <i_cdf_time.h>
  33. #ifdef CONFIG_CNSS
  34. #include <net/cnss.h>
  35. #endif
  36. typedef __cdf_time_t cdf_time_t;
  37. /**
  38. * cdf_system_ticks() - Count the number of ticks elapsed from the time when
  39. * the system booted
  40. *
  41. * Return: ticks
  42. */
  43. static inline unsigned long cdf_system_ticks(void)
  44. {
  45. return __cdf_system_ticks();
  46. }
  47. /**
  48. * cdf_system_ticks_to_msecs() - convert ticks to milliseconds
  49. * @clock_ticks: Number of ticks
  50. *
  51. * Return: Time in milliseconds
  52. */
  53. static inline uint32_t cdf_system_ticks_to_msecs(unsigned long clock_ticks)
  54. {
  55. return __cdf_system_ticks_to_msecs(clock_ticks);
  56. }
  57. /**
  58. * cdf_system_msecs_to_ticks() - convert milliseconds to ticks
  59. * @msec: Time in milliseconds
  60. *
  61. * Return: number of ticks
  62. */
  63. static inline unsigned long cdf_system_msecs_to_ticks(uint32_t msecs)
  64. {
  65. return __cdf_system_msecs_to_ticks(msecs);
  66. }
  67. /**
  68. * cdf_get_system_uptime() - Return a monotonically increasing time.
  69. * This increments once per HZ ticks
  70. *
  71. * Return: system up time
  72. */
  73. static inline unsigned long cdf_get_system_uptime(void)
  74. {
  75. return __cdf_get_system_uptime();
  76. }
  77. /**
  78. * cdf_get_system_timestamp() - brief Return current timestamp
  79. *
  80. * Return: none
  81. */
  82. static inline unsigned long cdf_get_system_timestamp(void)
  83. {
  84. return __cdf_get_system_timestamp();
  85. }
  86. /**
  87. * cdf_udelay() - delay in microseconds
  88. * @usecs: Number of microseconds to delay
  89. *
  90. * Return: none
  91. */
  92. static inline void cdf_udelay(int usecs)
  93. {
  94. __cdf_udelay(usecs);
  95. }
  96. /**
  97. * cdf_mdelay() - Delay in milliseconds.
  98. * @msec: Number of milliseconds to delay
  99. *
  100. * Return: none
  101. */
  102. static inline void cdf_mdelay(int msecs)
  103. {
  104. __cdf_mdelay(msecs);
  105. }
  106. /* Check if _a is later than _b */
  107. #define cdf_system_time_after(_a, _b) __cdf_system_time_after(_a, _b)
  108. /* Check if _a is prior to _b */
  109. #define cdf_system_time_before(_a, _b) __cdf_system_time_before(_a, _b)
  110. /* Check if _a atleast as recent as _b, if not later */
  111. #define cdf_system_time_after_eq(_a, _b) __cdf_system_time_after_eq(_a, _b)
  112. /**
  113. * enum cdf_timestamp_unit - what unit the cdf timestamp is in
  114. * @KERNEL_LOG: boottime time in uS (micro seconds)
  115. * @KERNEL_LOG: QTIME in (1/19200)S
  116. *
  117. * This enum is used to distinguish which timer source is used.
  118. */
  119. enum cdf_timestamp_unit {
  120. KERNEL_LOG,
  121. QTIMER,
  122. };
  123. #ifdef QCA_WIFI_3_0_ADRASTEA
  124. #define CDF_LOG_TIMESTAMP_UNIT QTIMER
  125. #else
  126. #define CDF_LOG_TIMESTAMP_UNIT KERNEL_LOG
  127. #endif
  128. #ifdef QCA_WIFI_3_0_ADRASTEA
  129. /**
  130. * cdf_get_log_timestamp() - get time stamp for logging
  131. *
  132. * For adrastea this API returns QTIMER tick which is needed to synchronize
  133. * host and fw log timestamps
  134. *
  135. * For ROME and other discrete solution this API returns system boot time stamp
  136. *
  137. * Return:
  138. * QTIMER ticks(19.2MHz) for adrastea
  139. * System tick for rome and other future discrete solutions
  140. */
  141. static inline uint64_t cdf_get_log_timestamp(void)
  142. {
  143. return __cdf_get_qtimer_ticks();
  144. }
  145. #else
  146. /**
  147. * cdf_get_log_timestamp() - get time stamp for logging
  148. *
  149. * For adrastea this API returns QTIMER tick which is needed to synchronize
  150. * host and fw log timestamps
  151. *
  152. * For ROME and other discrete solution this API returns system boot time stamp
  153. *
  154. * Return:
  155. * QTIMER ticks(19.2MHz) for adrastea
  156. * System tick for rome and other future discrete solutions
  157. */
  158. static inline uint64_t cdf_get_log_timestamp(void)
  159. {
  160. #ifdef CONFIG_CNSS
  161. struct timespec ts;
  162. cnss_get_boottime(&ts);
  163. return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
  164. #else
  165. return cdf_system_ticks_to_msecs(cdf_system_ticks()) * 1000;
  166. #endif /* CONFIG_CNSS */
  167. }
  168. #endif /* QCA_WIFI_3_0_ADRASTEA */
  169. /**
  170. * cdf_get_monotonic_boottime() - get monotonic kernel boot time
  171. * This API is similar to cdf_get_system_boottime but it includes
  172. * time spent in suspend.
  173. *
  174. * Return: Time in microseconds
  175. */
  176. static inline uint64_t cdf_get_monotonic_boottime(void)
  177. {
  178. return __cdf_get_monotonic_boottime();
  179. }
  180. #endif