i_qdf_time.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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: i_qdf_time
  28. * This file provides OS dependent time API's.
  29. */
  30. #ifndef _I_QDF_TIME_H
  31. #define _I_QDF_TIME_H
  32. #include <linux/jiffies.h>
  33. #include <linux/delay.h>
  34. #ifdef MSM_PLATFORM
  35. #include <asm/arch_timer.h>
  36. #else
  37. #include <linux/ktime.h>
  38. #endif
  39. #ifdef CONFIG_CNSS
  40. #include <net/cnss.h>
  41. #endif
  42. typedef unsigned long __qdf_time_t;
  43. /**
  44. * __qdf_system_ticks() - get system ticks
  45. *
  46. * Return: system tick in jiffies
  47. */
  48. static inline __qdf_time_t __qdf_system_ticks(void)
  49. {
  50. return jiffies;
  51. }
  52. /**
  53. * __qdf_system_ticks_to_msecs() - convert system ticks into milli seconds
  54. * @ticks: System ticks
  55. *
  56. * Return: system tick converted into milli seconds
  57. */
  58. static inline uint32_t __qdf_system_ticks_to_msecs(unsigned long ticks)
  59. {
  60. return jiffies_to_msecs(ticks);
  61. }
  62. /**
  63. * __qdf_system_msecs_to_ticks() - convert milli seconds into system ticks
  64. * @msecs: Milli seconds
  65. *
  66. * Return: milli seconds converted into system ticks
  67. */
  68. static inline __qdf_time_t __qdf_system_msecs_to_ticks(uint32_t msecs)
  69. {
  70. return msecs_to_jiffies(msecs);
  71. }
  72. /**
  73. * __qdf_get_system_uptime() - get system uptime
  74. *
  75. * Return: system uptime in jiffies
  76. */
  77. static inline __qdf_time_t __qdf_get_system_uptime(void)
  78. {
  79. return jiffies;
  80. }
  81. static inline unsigned long __qdf_get_system_timestamp(void)
  82. {
  83. return (jiffies / HZ) * 1000 + (jiffies % HZ) * (1000 / HZ);
  84. }
  85. #ifdef CONFIG_ARM
  86. /**
  87. * __qdf_udelay() - delay execution for given microseconds
  88. * @usecs: Micro seconds to delay
  89. *
  90. * Return: none
  91. */
  92. static inline void __qdf_udelay(uint32_t usecs)
  93. {
  94. /*
  95. * This is in support of XScale build. They have a limit on the udelay
  96. * value, so we have to make sure we don't approach the limit
  97. */
  98. uint32_t mticks;
  99. uint32_t leftover;
  100. int i;
  101. /* slice into 1024 usec chunks (simplifies calculation) */
  102. mticks = usecs >> 10;
  103. leftover = usecs - (mticks << 10);
  104. for (i = 0; i < mticks; i++)
  105. udelay(1024);
  106. udelay(leftover);
  107. }
  108. #else
  109. static inline void __qdf_udelay(uint32_t usecs)
  110. {
  111. /* Normal Delay functions. Time specified in microseconds */
  112. udelay(usecs);
  113. }
  114. #endif
  115. /**
  116. * __qdf_mdelay() - delay execution for given milliseconds
  117. * @usecs: Milliseconds to delay
  118. *
  119. * Return: none
  120. */
  121. static inline void __qdf_mdelay(uint32_t msecs)
  122. {
  123. mdelay(msecs);
  124. }
  125. /**
  126. * __qdf_system_time_after() - Check if a is later than b
  127. * @a: Time stamp value a
  128. * @b: Time stamp value b
  129. *
  130. * Return:
  131. * true if a < b else false
  132. */
  133. static inline bool __qdf_system_time_after(__qdf_time_t a, __qdf_time_t b)
  134. {
  135. return (long)(b) - (long)(a) < 0;
  136. }
  137. /**
  138. * __qdf_system_time_before() - Check if a is before b
  139. * @a: Time stamp value a
  140. * @b: Time stamp value b
  141. *
  142. * Return:
  143. * true if a is before b else false
  144. */
  145. static inline bool __qdf_system_time_before(__qdf_time_t a, __qdf_time_t b)
  146. {
  147. return __qdf_system_time_after(b, a);
  148. }
  149. /**
  150. * __qdf_system_time_after_eq() - Check if a atleast as recent as b, if not
  151. * later
  152. * @a: Time stamp value a
  153. * @b: Time stamp value b
  154. *
  155. * Return:
  156. * true if a >= b else false
  157. */
  158. static inline bool __qdf_system_time_after_eq(__qdf_time_t a, __qdf_time_t b)
  159. {
  160. return (long)(a) - (long)(b) >= 0;
  161. }
  162. /**
  163. * __qdf_get_monotonic_boottime() - get monotonic kernel boot time
  164. * This API is similar to qdf_get_system_boottime but it includes
  165. * time spent in suspend.
  166. *
  167. * Return: Time in microseconds
  168. */
  169. static inline uint64_t __qdf_get_monotonic_boottime(void)
  170. {
  171. struct timespec ts;
  172. get_monotonic_boottime(&ts);
  173. return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
  174. }
  175. #ifdef QCA_WIFI_3_0_ADRASTEA
  176. #include <asm/arch_timer.h>
  177. /**
  178. * __qdf_get_log_timestamp() - get QTIMER ticks
  179. *
  180. * Returns QTIMER(19.2 MHz) clock ticks. To convert it into seconds
  181. * divide it by 19200.
  182. *
  183. * Return: QTIMER(19.2 MHz) clock ticks
  184. */
  185. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
  186. static inline uint64_t __qdf_get_log_timestamp(void)
  187. {
  188. return arch_counter_get_cntvct();
  189. }
  190. #else
  191. static inline uint64_t __qdf_get_log_timestamp(void)
  192. {
  193. return arch_counter_get_cntpct();
  194. }
  195. #endif /* LINUX_VERSION_CODE */
  196. #else
  197. /**
  198. * __qdf_get_log_timestamp - get time stamp for logging
  199. * For adrastea this API returns QTIMER tick which is needed to synchronize
  200. * host and fw log timestamps
  201. * For ROME and other discrete solution this API returns system boot time stamp
  202. *
  203. * Return:
  204. * QTIMER ticks(19.2MHz) for adrastea
  205. * System tick for rome and other future discrete solutions
  206. */
  207. static inline uint64_t __qdf_get_log_timestamp(void)
  208. {
  209. struct timespec ts;
  210. ktime_get_ts(&ts);
  211. return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
  212. }
  213. #endif /* QCA_WIFI_3_0_ADRASTEA */
  214. #endif