xref: /wlan-driver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_hrtimer.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2014-2019,2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name /**
21*5113495bSYour Name  * DOC: i_qdf_hrtimer
22*5113495bSYour Name  * This file provides OS dependent timer API's.
23*5113495bSYour Name  */
24*5113495bSYour Name 
25*5113495bSYour Name #ifndef _I_QDF_HRTIMER_H
26*5113495bSYour Name #define _I_QDF_HRTIMER_H
27*5113495bSYour Name 
28*5113495bSYour Name #include <linux/version.h>
29*5113495bSYour Name #include <linux/delay.h>
30*5113495bSYour Name #include <linux/timer.h>
31*5113495bSYour Name #include <linux/jiffies.h>
32*5113495bSYour Name #include <qdf_types.h>
33*5113495bSYour Name #include <i_qdf_trace.h>
34*5113495bSYour Name 
35*5113495bSYour Name struct __qdf_hrtimer_data_internal_t;
36*5113495bSYour Name /* hrtimer data type */
37*5113495bSYour Name typedef struct __qdf_hrtimer_data_internal_t {
38*5113495bSYour Name 	union {
39*5113495bSYour Name 		struct hrtimer hrtimer;
40*5113495bSYour Name #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0))
41*5113495bSYour Name 		struct tasklet_hrtimer tasklet_hrtimer;
42*5113495bSYour Name #endif
43*5113495bSYour Name 	} u;
44*5113495bSYour Name 	enum qdf_context_mode ctx;
45*5113495bSYour Name 	struct __qdf_hrtimer_data_internal_t *cb_ctx;
46*5113495bSYour Name 	enum qdf_hrtimer_restart_status (*callback)
47*5113495bSYour Name 				(struct __qdf_hrtimer_data_internal_t *);
48*5113495bSYour Name } __qdf_hrtimer_data_t;
49*5113495bSYour Name 
50*5113495bSYour Name /**
51*5113495bSYour Name  * __qdf_hrtimer_get_mode() - Get hrtimer_mode with qdf mode
52*5113495bSYour Name  * @mode: mode of hrtimer
53*5113495bSYour Name  *
54*5113495bSYour Name  * Get hrtimer_mode with qdf hrtimer mode
55*5113495bSYour Name  *
56*5113495bSYour Name  * Return: void
57*5113495bSYour Name  */
58*5113495bSYour Name static inline
__qdf_hrtimer_get_mode(enum qdf_hrtimer_mode mode)59*5113495bSYour Name enum hrtimer_mode __qdf_hrtimer_get_mode(enum qdf_hrtimer_mode mode)
60*5113495bSYour Name {
61*5113495bSYour Name 	return (enum hrtimer_mode)mode;
62*5113495bSYour Name }
63*5113495bSYour Name 
64*5113495bSYour Name /**
65*5113495bSYour Name  * __qdf_hrtimer_start() - Starts hrtimer in given context
66*5113495bSYour Name  * @timer: pointer to the hrtimer object
67*5113495bSYour Name  * @interval: interval to forward as qdf_ktime_t object
68*5113495bSYour Name  * @mode: mode of hrtimer
69*5113495bSYour Name  *
70*5113495bSYour Name  * Starts hrtimer in given context
71*5113495bSYour Name  *
72*5113495bSYour Name  * Return: void
73*5113495bSYour Name  */
74*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
75*5113495bSYour Name static inline
__qdf_hrtimer_start(__qdf_hrtimer_data_t * timer,ktime_t interval,enum qdf_hrtimer_mode mode)76*5113495bSYour Name void __qdf_hrtimer_start(__qdf_hrtimer_data_t *timer, ktime_t interval,
77*5113495bSYour Name 			 enum qdf_hrtimer_mode mode)
78*5113495bSYour Name {
79*5113495bSYour Name 	enum hrtimer_mode hrt_mode;
80*5113495bSYour Name 
81*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_TASKLET)
82*5113495bSYour Name 		mode |= HRTIMER_MODE_SOFT;
83*5113495bSYour Name 
84*5113495bSYour Name 	hrt_mode = __qdf_hrtimer_get_mode(mode);
85*5113495bSYour Name 	hrtimer_start(&timer->u.hrtimer, interval, hrt_mode);
86*5113495bSYour Name }
87*5113495bSYour Name #else
88*5113495bSYour Name static inline
__qdf_hrtimer_start(__qdf_hrtimer_data_t * timer,ktime_t interval,enum qdf_hrtimer_mode mode)89*5113495bSYour Name void __qdf_hrtimer_start(__qdf_hrtimer_data_t *timer, ktime_t interval,
90*5113495bSYour Name 			 enum qdf_hrtimer_mode mode)
91*5113495bSYour Name {
92*5113495bSYour Name 	enum hrtimer_mode hrt_mode = __qdf_hrtimer_get_mode(mode);
93*5113495bSYour Name 
94*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
95*5113495bSYour Name 		hrtimer_start(&timer->u.hrtimer, interval, hrt_mode);
96*5113495bSYour Name 	else if (timer->ctx == QDF_CONTEXT_TASKLET)
97*5113495bSYour Name 		tasklet_hrtimer_start(&timer->u.tasklet_hrtimer,
98*5113495bSYour Name 				      interval, hrt_mode);
99*5113495bSYour Name }
100*5113495bSYour Name #endif
101*5113495bSYour Name 
102*5113495bSYour Name /**
103*5113495bSYour Name  * __qdf_hrtimer_cancel() - cancels hrtimer in given context
104*5113495bSYour Name  * @timer: pointer to the hrtimer object
105*5113495bSYour Name  *
106*5113495bSYour Name  * cancels hrtimer in given context
107*5113495bSYour Name  *
108*5113495bSYour Name  * Return: int
109*5113495bSYour Name  */
110*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
111*5113495bSYour Name static inline
__qdf_hrtimer_cancel(__qdf_hrtimer_data_t * timer)112*5113495bSYour Name int __qdf_hrtimer_cancel(__qdf_hrtimer_data_t *timer)
113*5113495bSYour Name {
114*5113495bSYour Name 	return hrtimer_cancel(&timer->u.hrtimer);
115*5113495bSYour Name }
116*5113495bSYour Name #else
117*5113495bSYour Name static inline
__qdf_hrtimer_cancel(__qdf_hrtimer_data_t * timer)118*5113495bSYour Name int __qdf_hrtimer_cancel(__qdf_hrtimer_data_t *timer)
119*5113495bSYour Name {
120*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
121*5113495bSYour Name 		return hrtimer_cancel(&timer->u.hrtimer);
122*5113495bSYour Name 	else if (timer->ctx == QDF_CONTEXT_TASKLET)
123*5113495bSYour Name 		return hrtimer_cancel(&timer->u.tasklet_hrtimer.timer);
124*5113495bSYour Name 
125*5113495bSYour Name 	return 0;
126*5113495bSYour Name }
127*5113495bSYour Name #endif
128*5113495bSYour Name 
__qdf_hrtimer_cb(struct hrtimer * arg)129*5113495bSYour Name static enum hrtimer_restart __qdf_hrtimer_cb(struct hrtimer *arg)
130*5113495bSYour Name {
131*5113495bSYour Name 	__qdf_hrtimer_data_t *timer = container_of(arg, __qdf_hrtimer_data_t,
132*5113495bSYour Name 						   u.hrtimer);
133*5113495bSYour Name 
134*5113495bSYour Name 	return (enum hrtimer_restart)timer->callback(timer->cb_ctx);
135*5113495bSYour Name }
136*5113495bSYour Name 
137*5113495bSYour Name /**
138*5113495bSYour Name  * __qdf_hrtimer_init() - init hrtimer in a given context
139*5113495bSYour Name  * @timer: pointer to the hrtimer object
140*5113495bSYour Name  * @cback: callback function to be fired
141*5113495bSYour Name  * @clock: clock id
142*5113495bSYour Name  * @mode: mode of hrtimer
143*5113495bSYour Name  * @ctx:  interrupt context mode
144*5113495bSYour Name  *
145*5113495bSYour Name  * starts hrtimer in a context passed as per the context
146*5113495bSYour Name  *
147*5113495bSYour Name  * Return: void
148*5113495bSYour Name  */
149*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_init(__qdf_hrtimer_data_t * timer,void * cback,enum qdf_clock_id clock,enum qdf_hrtimer_mode mode,enum qdf_context_mode ctx)150*5113495bSYour Name static inline void  __qdf_hrtimer_init(__qdf_hrtimer_data_t *timer,
151*5113495bSYour Name 				       void *cback,
152*5113495bSYour Name 				       enum qdf_clock_id clock,
153*5113495bSYour Name 				       enum qdf_hrtimer_mode mode,
154*5113495bSYour Name 				       enum qdf_context_mode ctx)
155*5113495bSYour Name {
156*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
157*5113495bSYour Name 	enum hrtimer_mode hrt_mode;
158*5113495bSYour Name 
159*5113495bSYour Name 	timer->ctx = ctx;
160*5113495bSYour Name 	timer->callback = cback;
161*5113495bSYour Name 	timer->cb_ctx = timer;
162*5113495bSYour Name 
163*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_TASKLET)
164*5113495bSYour Name 		mode |= HRTIMER_MODE_SOFT;
165*5113495bSYour Name 
166*5113495bSYour Name 	hrt_mode = __qdf_hrtimer_get_mode(mode);
167*5113495bSYour Name 	hrtimer_init(hrtimer, clock, hrt_mode);
168*5113495bSYour Name 	hrtimer->function = __qdf_hrtimer_cb;
169*5113495bSYour Name }
170*5113495bSYour Name #else
__qdf_hrtimer_init(__qdf_hrtimer_data_t * timer,void * cback,enum qdf_clock_id clock,enum qdf_hrtimer_mode mode,enum qdf_context_mode ctx)171*5113495bSYour Name static inline void  __qdf_hrtimer_init(__qdf_hrtimer_data_t *timer,
172*5113495bSYour Name 				       void *cback,
173*5113495bSYour Name 				       enum qdf_clock_id clock,
174*5113495bSYour Name 				       enum qdf_hrtimer_mode mode,
175*5113495bSYour Name 				       enum qdf_context_mode ctx)
176*5113495bSYour Name {
177*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
178*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
179*5113495bSYour Name 	enum hrtimer_mode hrt_mode = __qdf_hrtimer_get_mode(mode);
180*5113495bSYour Name 
181*5113495bSYour Name 	timer->ctx = ctx;
182*5113495bSYour Name 	timer->callback = cback;
183*5113495bSYour Name 	timer->cb_ctx = timer;
184*5113495bSYour Name 
185*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE) {
186*5113495bSYour Name 		hrtimer_init(hrtimer, clock, hrt_mode);
187*5113495bSYour Name 		hrtimer->function = __qdf_hrtimer_cb;
188*5113495bSYour Name 	} else if (timer->ctx == QDF_CONTEXT_TASKLET) {
189*5113495bSYour Name 		tasklet_hrtimer_init(tasklet_hrtimer, cback, clock, hrt_mode);
190*5113495bSYour Name 	}
191*5113495bSYour Name }
192*5113495bSYour Name #endif
193*5113495bSYour Name 
194*5113495bSYour Name /**
195*5113495bSYour Name  * __qdf_hrtimer_kill() - kills hrtimer in given context
196*5113495bSYour Name  * @timer: pointer to the hrtimer object
197*5113495bSYour Name  *
198*5113495bSYour Name  * kills hrtimer in given context
199*5113495bSYour Name  *
200*5113495bSYour Name  * Return: void
201*5113495bSYour Name  */
202*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
203*5113495bSYour Name static inline
__qdf_hrtimer_kill(__qdf_hrtimer_data_t * timer)204*5113495bSYour Name void __qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
205*5113495bSYour Name {
206*5113495bSYour Name 	hrtimer_cancel(&timer->u.hrtimer);
207*5113495bSYour Name }
208*5113495bSYour Name #else
209*5113495bSYour Name static inline
__qdf_hrtimer_kill(__qdf_hrtimer_data_t * timer)210*5113495bSYour Name void __qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
211*5113495bSYour Name {
212*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
213*5113495bSYour Name 		hrtimer_cancel(&timer->u.hrtimer);
214*5113495bSYour Name 	else if (timer->ctx == QDF_CONTEXT_TASKLET)
215*5113495bSYour Name 		tasklet_hrtimer_cancel(&timer->u.tasklet_hrtimer);
216*5113495bSYour Name }
217*5113495bSYour Name #endif
218*5113495bSYour Name 
219*5113495bSYour Name /**
220*5113495bSYour Name  * __qdf_hrtimer_get_remaining() - check remaining time in the timer
221*5113495bSYour Name  * @timer: pointer to the hrtimer object
222*5113495bSYour Name  *
223*5113495bSYour Name  * check whether the timer is on one of the queues
224*5113495bSYour Name  *
225*5113495bSYour Name  * Return: remaining time as ktime object
226*5113495bSYour Name  */
227*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_get_remaining(__qdf_hrtimer_data_t * timer)228*5113495bSYour Name static inline ktime_t __qdf_hrtimer_get_remaining(__qdf_hrtimer_data_t *timer)
229*5113495bSYour Name {
230*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
231*5113495bSYour Name 
232*5113495bSYour Name 	return hrtimer_get_remaining(hrtimer);
233*5113495bSYour Name }
234*5113495bSYour Name #else
__qdf_hrtimer_get_remaining(__qdf_hrtimer_data_t * timer)235*5113495bSYour Name static inline ktime_t __qdf_hrtimer_get_remaining(__qdf_hrtimer_data_t *timer)
236*5113495bSYour Name {
237*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
238*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
239*5113495bSYour Name 
240*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
241*5113495bSYour Name 		return hrtimer_get_remaining(hrtimer);
242*5113495bSYour Name 	else
243*5113495bSYour Name 		return hrtimer_get_remaining(&tasklet_hrtimer->timer);
244*5113495bSYour Name }
245*5113495bSYour Name #endif
246*5113495bSYour Name 
247*5113495bSYour Name /**
248*5113495bSYour Name  * __qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
249*5113495bSYour Name  * @timer: pointer to the hrtimer object
250*5113495bSYour Name  *
251*5113495bSYour Name  * check whether the timer is on one of the queues
252*5113495bSYour Name  *
253*5113495bSYour Name  * Return: false when the timer was not in queue
254*5113495bSYour Name  *         true when the timer was in queue
255*5113495bSYour Name  */
256*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_is_queued(__qdf_hrtimer_data_t * timer)257*5113495bSYour Name static inline bool __qdf_hrtimer_is_queued(__qdf_hrtimer_data_t *timer)
258*5113495bSYour Name {
259*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
260*5113495bSYour Name 
261*5113495bSYour Name 	return hrtimer_is_queued(hrtimer);
262*5113495bSYour Name }
263*5113495bSYour Name #else
__qdf_hrtimer_is_queued(__qdf_hrtimer_data_t * timer)264*5113495bSYour Name static inline bool __qdf_hrtimer_is_queued(__qdf_hrtimer_data_t *timer)
265*5113495bSYour Name {
266*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
267*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
268*5113495bSYour Name 
269*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
270*5113495bSYour Name 		return hrtimer_is_queued(hrtimer);
271*5113495bSYour Name 	else
272*5113495bSYour Name 		return hrtimer_is_queued(&tasklet_hrtimer->timer);
273*5113495bSYour Name }
274*5113495bSYour Name #endif
275*5113495bSYour Name 
276*5113495bSYour Name /**
277*5113495bSYour Name  * __qdf_hrtimer_callback_running() - check if callback is running
278*5113495bSYour Name  * @timer: pointer to the hrtimer object
279*5113495bSYour Name  *
280*5113495bSYour Name  * check whether the timer is running the callback function
281*5113495bSYour Name  *
282*5113495bSYour Name  * Return: false when callback is not running
283*5113495bSYour Name  *         true when callback is running
284*5113495bSYour Name  */
285*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_callback_running(__qdf_hrtimer_data_t * timer)286*5113495bSYour Name static inline bool __qdf_hrtimer_callback_running(__qdf_hrtimer_data_t *timer)
287*5113495bSYour Name {
288*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
289*5113495bSYour Name 
290*5113495bSYour Name 	return hrtimer_callback_running(hrtimer);
291*5113495bSYour Name }
292*5113495bSYour Name #else
__qdf_hrtimer_callback_running(__qdf_hrtimer_data_t * timer)293*5113495bSYour Name static inline bool __qdf_hrtimer_callback_running(__qdf_hrtimer_data_t *timer)
294*5113495bSYour Name {
295*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
296*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
297*5113495bSYour Name 
298*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
299*5113495bSYour Name 		return hrtimer_callback_running(hrtimer);
300*5113495bSYour Name 	else
301*5113495bSYour Name 		return hrtimer_callback_running(&tasklet_hrtimer->timer);
302*5113495bSYour Name }
303*5113495bSYour Name #endif
304*5113495bSYour Name 
305*5113495bSYour Name /**
306*5113495bSYour Name  * __qdf_hrtimer_active() - check if timer is active
307*5113495bSYour Name  * @timer: pointer to the hrtimer object
308*5113495bSYour Name  *
309*5113495bSYour Name  * Check if timer is active. A timer is active, when it is enqueued into
310*5113495bSYour Name  * the rbtree or the callback function is running.
311*5113495bSYour Name  *
312*5113495bSYour Name  * Return: false if timer is not active
313*5113495bSYour Name  *         true if timer is active
314*5113495bSYour Name  */
315*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_active(__qdf_hrtimer_data_t * timer)316*5113495bSYour Name static inline bool __qdf_hrtimer_active(__qdf_hrtimer_data_t *timer)
317*5113495bSYour Name {
318*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
319*5113495bSYour Name 
320*5113495bSYour Name 	return hrtimer_active(hrtimer);
321*5113495bSYour Name }
322*5113495bSYour Name #else
__qdf_hrtimer_active(__qdf_hrtimer_data_t * timer)323*5113495bSYour Name static inline bool __qdf_hrtimer_active(__qdf_hrtimer_data_t *timer)
324*5113495bSYour Name {
325*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
326*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
327*5113495bSYour Name 
328*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
329*5113495bSYour Name 		return hrtimer_active(hrtimer);
330*5113495bSYour Name 	else
331*5113495bSYour Name 		return hrtimer_active(&tasklet_hrtimer->timer);
332*5113495bSYour Name }
333*5113495bSYour Name #endif
334*5113495bSYour Name 
335*5113495bSYour Name /**
336*5113495bSYour Name  * __qdf_hrtimer_cb_get_time() - get remaining time in callback
337*5113495bSYour Name  * @timer: pointer to the hrtimer object
338*5113495bSYour Name  *
339*5113495bSYour Name  * Get remaining time in the hrtimer callback
340*5113495bSYour Name  *
341*5113495bSYour Name  * Return: time remaining as ktime object
342*5113495bSYour Name  */
343*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_cb_get_time(__qdf_hrtimer_data_t * timer)344*5113495bSYour Name static inline ktime_t __qdf_hrtimer_cb_get_time(__qdf_hrtimer_data_t *timer)
345*5113495bSYour Name {
346*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
347*5113495bSYour Name 
348*5113495bSYour Name 	return hrtimer_cb_get_time(hrtimer);
349*5113495bSYour Name }
350*5113495bSYour Name #else
__qdf_hrtimer_cb_get_time(__qdf_hrtimer_data_t * timer)351*5113495bSYour Name static inline ktime_t __qdf_hrtimer_cb_get_time(__qdf_hrtimer_data_t *timer)
352*5113495bSYour Name {
353*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
354*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
355*5113495bSYour Name 
356*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
357*5113495bSYour Name 		return hrtimer_cb_get_time(hrtimer);
358*5113495bSYour Name 	else
359*5113495bSYour Name 		return hrtimer_cb_get_time(&tasklet_hrtimer->timer);
360*5113495bSYour Name }
361*5113495bSYour Name #endif
362*5113495bSYour Name 
363*5113495bSYour Name /**
364*5113495bSYour Name  * __qdf_hrtimer_forward() - forward the hrtimer
365*5113495bSYour Name  * @timer: pointer to the hrtimer object
366*5113495bSYour Name  * @now: current ktime
367*5113495bSYour Name  * @interval: interval to forward as ktime object
368*5113495bSYour Name  *
369*5113495bSYour Name  * Forward the timer expiry so it will expire in the future
370*5113495bSYour Name  *
371*5113495bSYour Name  * Return:the number of overruns
372*5113495bSYour Name  */
373*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0))
__qdf_hrtimer_forward(__qdf_hrtimer_data_t * timer,ktime_t now,ktime_t interval)374*5113495bSYour Name static inline uint64_t __qdf_hrtimer_forward(__qdf_hrtimer_data_t *timer,
375*5113495bSYour Name 					     ktime_t now,
376*5113495bSYour Name 					     ktime_t interval)
377*5113495bSYour Name {
378*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
379*5113495bSYour Name 
380*5113495bSYour Name 	return hrtimer_forward(hrtimer, now, interval);
381*5113495bSYour Name }
382*5113495bSYour Name 
383*5113495bSYour Name #else
__qdf_hrtimer_forward(__qdf_hrtimer_data_t * timer,ktime_t now,ktime_t interval)384*5113495bSYour Name static inline uint64_t __qdf_hrtimer_forward(__qdf_hrtimer_data_t *timer,
385*5113495bSYour Name 					     ktime_t now,
386*5113495bSYour Name 					     ktime_t interval)
387*5113495bSYour Name {
388*5113495bSYour Name 	struct hrtimer *hrtimer = &timer->u.hrtimer;
389*5113495bSYour Name 	struct tasklet_hrtimer *tasklet_hrtimer = &timer->u.tasklet_hrtimer;
390*5113495bSYour Name 
391*5113495bSYour Name 	if (timer->ctx == QDF_CONTEXT_HARDWARE)
392*5113495bSYour Name 		return hrtimer_forward(hrtimer, now, interval);
393*5113495bSYour Name 	else
394*5113495bSYour Name 		return hrtimer_forward(&tasklet_hrtimer->timer, now, interval);
395*5113495bSYour Name }
396*5113495bSYour Name #endif
397*5113495bSYour Name 
398*5113495bSYour Name /**
399*5113495bSYour Name  * __qdf_hrtimer_add_expires() - Add expiry to hrtimer with given interval
400*5113495bSYour Name  * @timer: pointer to the __qdf_hrtimer_data_t object
401*5113495bSYour Name  * @interval: interval to add as ktime_t object
402*5113495bSYour Name  *
403*5113495bSYour Name  * Add the timer expiry so it will expire in the future
404*5113495bSYour Name  *
405*5113495bSYour Name  * Return: None
406*5113495bSYour Name  */
407*5113495bSYour Name static inline
__qdf_hrtimer_add_expires(__qdf_hrtimer_data_t * timer,ktime_t interval)408*5113495bSYour Name void __qdf_hrtimer_add_expires(__qdf_hrtimer_data_t *timer, ktime_t interval)
409*5113495bSYour Name {
410*5113495bSYour Name 	hrtimer_add_expires(&timer->u.hrtimer, interval);
411*5113495bSYour Name }
412*5113495bSYour Name #endif /* _I_QDF_HRTIMER_H */
413