xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_hrtimer.h (revision 4865edfd190c086bbe2c69aae12a8226f877b91e)
1 /*
2  * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: qdf_hrtimer
21  * This file abstracts high resolution timers running in hardware context.
22  */
23 
24 #ifndef _QDF_HRTIMER_H
25 #define _QDF_HRTIMER_H
26 
27 #include <qdf_types.h>
28 #include <i_qdf_hrtimer.h>
29 #include <qdf_time.h>
30 
31 /* Context independent hrtimer object */
32 typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
33 
34 /* Platform independent timer callback function */
35 typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
36 					(qdf_hrtimer_data_t *timer);
37 
38 /**
39  * qdf_hrtimer_start() - Starts hrtimer in given context
40  * @timer: pointer to the qdf_hrtimer_data_t object
41  * @interval: interval to forward as qdf_ktime_t object
42  * @mode: mode of qdf_hrtimer_data_t
43  *
44  * Starts hrtimer in given context
45  *
46  * Return: void
47  */
48 static inline
49 void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
50 		       enum qdf_hrtimer_mode mode)
51 {
52 	__qdf_hrtimer_start(timer, interval, mode);
53 }
54 
55 /**
56  * qdf_hrtimer_cancel() - Cancels hrtimer in given context
57  * @timer: pointer to the qdf_hrtimer_data_t object
58  *
59  * Cancels hrtimer in given context
60  *
61  * Return: void
62  */
63 static inline
64 void qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
65 {
66 	__qdf_hrtimer_cancel(timer);
67 }
68 
69 /**
70  * qdf_hrtimer_init() - init hrtimer based on context
71  * @timer: pointer to the qdf_hrtimer_data_t object
72  * @callback: callback function to be fired
73  * @qdf_clock_id: clock type
74  * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
75  * @qdf_context_mode: interrupt context mode
76  *
77  * starts hrtimer in a context passed as per qdf_context_mode
78  *
79  * Return: void
80  */
81 static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
82 				    qdf_hrtimer_func_t callback,
83 				    enum qdf_clock_id clock,
84 				    enum qdf_hrtimer_mode mode,
85 				    enum qdf_context_mode ctx)
86 {
87 	__qdf_hrtimer_init(timer, callback, clock, mode, ctx);
88 }
89 
90 /**
91  * qdf_hrtimer_kill() - kills hrtimer in given context
92  * @timer: pointer to the hrtimer object
93  *
94  * kills hrtimer in given context
95  *
96  * Return: void
97  */
98 static inline
99 void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
100 {
101 	 __qdf_hrtimer_kill(timer);
102 }
103 
104 /**
105  * qdf_hrtimer_get_remaining() - check remaining time in the timer
106  * @timer: pointer to the qdf_hrtimer_data_t object
107  *
108  * check whether the timer is on one of the queues
109  *
110  * Return: remaining time as qdf_ktime_t object
111  */
112 static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
113 {
114 	return __qdf_hrtimer_get_remaining(timer);
115 }
116 
117 /**
118  * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
119  * @timer: pointer to the qdf_hrtimer_data_t object
120  *
121  * check whether the timer is on one of the queues
122  *
123  * Return: false when the timer was not in queue
124  *         true when the timer was in queue
125  */
126 static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
127 {
128 	return __qdf_hrtimer_is_queued(timer);
129 }
130 
131 /**
132  * qdf_hrtimer_callback_running() - check if callback is running
133  * @timer: pointer to the qdf_hrtimer_data_t object
134  *
135  * check whether the timer is running the callback function
136  *
137  * Return: false when callback is not running
138  *         true when callback is running
139  */
140 static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
141 {
142 	return __qdf_hrtimer_callback_running(timer);
143 }
144 
145 /**
146  * qdf_hrtimer_active() - check if timer is active
147  * @timer: pointer to the qdf_hrtimer_data_t object
148  *
149  * Check if timer is active. A timer is active, when it is enqueued into
150  * the rbtree or the callback function is running.
151  *
152  * Return: false if timer is not active
153  *         true if timer is active
154  */
155 static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
156 {
157 	return __qdf_hrtimer_active(timer);
158 }
159 
160 /**
161  * qdf_hrtimer_cb_get_time() - get remaining time in callback
162  * @timer: pointer to the qdf_hrtimer_data_t object
163  *
164  * Get remaining time in the hrtimer callback
165  *
166  * Return: time remaining as qdf_ktime_t object
167  */
168 static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
169 {
170 	return __qdf_hrtimer_cb_get_time(timer);
171 }
172 
173 /**
174  * qdf_hrtimer_forward() - forward the hrtimer
175  * @timer: pointer to the qdf_hrtimer_data_t object
176  * @now: current time as qdf_ktime_t object
177  * @interval: interval to forward as qdf_ktime_t object
178  *
179  * Forward the timer expiry so it will expire in the future
180  *
181  * Return: the number of overruns
182  */
183 static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
184 					   qdf_ktime_t now,
185 					   qdf_ktime_t interval)
186 {
187 	return __qdf_hrtimer_forward(timer, now, interval);
188 }
189 
190 #endif /* _QDF_HRTIMER_H */
191