1 /*
2 * Copyright (c) 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 /**
21 * DOC: qdf_time
22 * QCA driver framework (QDF) timer APIs
23 */
24
25 #include <i_qdf_time.h>
26 #include "qdf_time.h"
27 #include <qdf_module.h>
28
qdf_ns_to_ktime(uint64_t ns)29 qdf_ktime_t qdf_ns_to_ktime(uint64_t ns)
30 {
31 return __qdf_ns_to_ktime(ns);
32 }
33
34 qdf_export_symbol(qdf_ns_to_ktime);
35
qdf_ktime_add(qdf_ktime_t ktime1,qdf_ktime_t ktime2)36 qdf_ktime_t qdf_ktime_add(qdf_ktime_t ktime1, qdf_ktime_t ktime2)
37 {
38 return __qdf_ktime_add(ktime1, ktime2);
39 }
40
41 qdf_export_symbol(qdf_ktime_add);
42
qdf_ktime_get(void)43 qdf_ktime_t qdf_ktime_get(void)
44 {
45 return __qdf_ktime_get();
46 }
47
48 qdf_export_symbol(qdf_ktime_get);
49
qdf_ktime_real_get(void)50 qdf_ktime_t qdf_ktime_real_get(void)
51 {
52 return __qdf_ktime_real_get();
53 }
54
55 qdf_export_symbol(qdf_ktime_real_get);
56
qdf_ktime_add_ns(qdf_ktime_t ktime,int64_t ns)57 qdf_ktime_t qdf_ktime_add_ns(qdf_ktime_t ktime, int64_t ns)
58 {
59 return __qdf_ktime_add_ns(ktime, ns);
60 }
61
62 qdf_export_symbol(qdf_ktime_add_ns);
63
qdf_ktime_to_ms(qdf_ktime_t ktime)64 int64_t qdf_ktime_to_ms(qdf_ktime_t ktime)
65 {
66 return __qdf_ktime_to_ms(ktime);
67 }
68
69 qdf_export_symbol(qdf_ktime_to_ms);
70
qdf_ktime_to_us(qdf_ktime_t ktime)71 int64_t qdf_ktime_to_us(qdf_ktime_t ktime)
72 {
73 return __qdf_time_ktime_to_us(ktime);
74 }
75
76 qdf_export_symbol(qdf_ktime_to_us);
77
qdf_ktime_to_ns(qdf_ktime_t ktime)78 int64_t qdf_ktime_to_ns(qdf_ktime_t ktime)
79 {
80 return __qdf_ktime_to_ns(ktime);
81 }
82
83 qdf_export_symbol(qdf_ktime_to_ns);
84
qdf_time_ktime_set(const s64 secs,const unsigned long nsecs)85 qdf_ktime_t qdf_time_ktime_set(const s64 secs, const unsigned long nsecs)
86 {
87 return __qdf_time_ktime_set(secs, nsecs);
88 }
89
90 qdf_export_symbol(qdf_time_ktime_set);
91
qdf_system_ticks(void)92 qdf_time_t qdf_system_ticks(void)
93 {
94 return __qdf_system_ticks();
95 }
96
97 qdf_export_symbol(qdf_system_ticks);
98
qdf_system_ticks_to_msecs(unsigned long clock_ticks)99 uint32_t qdf_system_ticks_to_msecs(unsigned long clock_ticks)
100 {
101 return __qdf_system_ticks_to_msecs(clock_ticks);
102 }
103
104 qdf_export_symbol(qdf_system_ticks_to_msecs);
105
qdf_system_ticks_to_nsecs(unsigned long clock_ticks)106 uint32_t qdf_system_ticks_to_nsecs(unsigned long clock_ticks)
107 {
108 return __qdf_system_ticks_to_nsecs(clock_ticks);
109 }
110
111 qdf_export_symbol(qdf_system_ticks_to_nsecs);
112
qdf_system_msecs_to_ticks(uint32_t msecs)113 qdf_time_t qdf_system_msecs_to_ticks(uint32_t msecs)
114 {
115 return __qdf_system_msecs_to_ticks(msecs);
116 }
117
118 qdf_export_symbol(qdf_system_msecs_to_ticks);
119
qdf_get_system_uptime(void)120 qdf_time_t qdf_get_system_uptime(void)
121 {
122 return __qdf_get_system_uptime();
123 }
124
125 qdf_export_symbol(qdf_get_system_uptime);
126
qdf_get_bootbased_boottime_ns(void)127 uint64_t qdf_get_bootbased_boottime_ns(void)
128 {
129 return __qdf_get_bootbased_boottime_ns();
130 }
131
132 qdf_export_symbol(qdf_get_bootbased_boottime_ns);
133
qdf_get_system_timestamp(void)134 unsigned long qdf_get_system_timestamp(void)
135 {
136 return __qdf_get_system_timestamp();
137 }
138
139 qdf_export_symbol(qdf_get_system_timestamp);
140
qdf_udelay(int usecs)141 void qdf_udelay(int usecs)
142 {
143 __qdf_udelay(usecs);
144 }
145
146 qdf_export_symbol(qdf_udelay);
147
qdf_mdelay(int msecs)148 void qdf_mdelay(int msecs)
149 {
150 __qdf_mdelay(msecs);
151 }
152
153 qdf_export_symbol(qdf_mdelay);
154
qdf_system_time_after(qdf_time_t a,qdf_time_t b)155 bool qdf_system_time_after(qdf_time_t a, qdf_time_t b)
156 {
157 return __qdf_system_time_after(a, b);
158 }
159
160 qdf_export_symbol(qdf_system_time_after);
161
qdf_system_time_before(qdf_time_t a,qdf_time_t b)162 bool qdf_system_time_before(qdf_time_t a, qdf_time_t b)
163 {
164 return __qdf_system_time_before(a, b);
165 }
166
167 qdf_export_symbol(qdf_system_time_before);
168
qdf_system_time_after_eq(qdf_time_t a,qdf_time_t b)169 bool qdf_system_time_after_eq(qdf_time_t a, qdf_time_t b)
170 {
171 return __qdf_system_time_after_eq(a, b);
172 }
173
174 qdf_export_symbol(qdf_system_time_after_eq);
175
176 #ifdef MSM_PLATFORM
qdf_log_timestamp_to_usecs(uint64_t time)177 uint64_t qdf_log_timestamp_to_usecs(uint64_t time)
178 {
179 /*
180 * Try to preserve precision by multiplying by 10 first.
181 * If that would cause a wrap around, divide first instead.
182 */
183 if (time * 10 < time) {
184 do_div(time, QDF_LOG_TIMESTAMP_CYCLES_PER_10_US);
185 return time * 10;
186 }
187
188 time = time * 10;
189 do_div(time, QDF_LOG_TIMESTAMP_CYCLES_PER_10_US);
190
191 return time;
192 }
193
194 qdf_export_symbol(qdf_log_timestamp_to_usecs);
195 #else
qdf_log_timestamp_to_usecs(uint64_t time)196 uint64_t qdf_log_timestamp_to_usecs(uint64_t time)
197 {
198 /* timestamps are already in micro seconds */
199 return time;
200 }
201
202 qdf_export_symbol(qdf_log_timestamp_to_usecs);
203 #endif /* end of MSM_PLATFORM */
204
qdf_log_timestamp_to_secs(uint64_t time,uint64_t * secs,uint64_t * usecs)205 void qdf_log_timestamp_to_secs(uint64_t time, uint64_t *secs,
206 uint64_t *usecs)
207 {
208 *secs = qdf_log_timestamp_to_usecs(time);
209 *usecs = do_div(*secs, 1000000ul);
210 }
211
212 qdf_export_symbol(qdf_log_timestamp_to_secs);
213
qdf_usecs_to_log_timestamp(uint64_t usecs)214 uint64_t qdf_usecs_to_log_timestamp(uint64_t usecs)
215 {
216 uint64_t ts;
217
218 ts = (usecs * QDF_LOG_TIMESTAMP_CYCLES_PER_10_US);
219
220 do_div(ts, 10ul);
221 return ts;
222 }
223
224 qdf_export_symbol(qdf_usecs_to_log_timestamp);
225
qdf_get_log_timestamp(void)226 uint64_t qdf_get_log_timestamp(void)
227 {
228 return __qdf_get_log_timestamp();
229 }
230
231 qdf_export_symbol(qdf_get_log_timestamp);
232
qdf_get_log_timestamp_usecs(void)233 uint64_t qdf_get_log_timestamp_usecs(void)
234 {
235 return qdf_log_timestamp_to_usecs(qdf_get_log_timestamp());
236 }
237
238 qdf_export_symbol(qdf_get_log_timestamp_usecs);
239
qdf_get_monotonic_boottime(void)240 uint64_t qdf_get_monotonic_boottime(void)
241 {
242 return __qdf_get_monotonic_boottime();
243 }
244
245 qdf_export_symbol(qdf_get_monotonic_boottime);
246
qdf_time_ktime_get_real_time(qdf_timespec_t * ts)247 void qdf_time_ktime_get_real_time(qdf_timespec_t *ts)
248 {
249 return __qdf_time_ktime_get_real_time(ts);
250 }
251
252 qdf_export_symbol(qdf_time_ktime_get_real_time);
253
qdf_time_sched_clock(void)254 unsigned long long qdf_time_sched_clock(void)
255 {
256 return __qdf_time_sched_clock();
257 }
258
259 qdf_export_symbol(qdf_time_sched_clock);
260
qdf_usleep_range(unsigned long min,unsigned long max)261 void qdf_usleep_range(unsigned long min, unsigned long max)
262 {
263 __qdf_usleep_range(min, max);
264 }
265
266 qdf_export_symbol(qdf_usleep_range);
267
qdf_ktime_get_ns(void)268 qdf_ktime_t qdf_ktime_get_ns(void)
269 {
270 return __qdf_ktime_get_ns();
271 }
272
273 qdf_export_symbol(qdf_ktime_get_ns);
274
qdf_ktime_get_real_ns(void)275 qdf_ktime_t qdf_ktime_get_real_ns(void)
276 {
277 return __qdf_ktime_get_real_ns();
278 }
279
280 qdf_export_symbol(qdf_ktime_get_real_ns);
281
qdf_ktime_compare(qdf_ktime_t ktime1,qdf_ktime_t ktime2)282 int qdf_ktime_compare(qdf_ktime_t ktime1, qdf_ktime_t ktime2)
283 {
284 return __qdf_ktime_compare(ktime1, ktime2);
285 }
286
287 qdf_export_symbol(qdf_ktime_compare);
288