xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_hrtimer.h (revision 6ecd284e5a94a1c96e26d571dd47419ac305990d)
1 /*
2  * Copyright (c) 2014-2018 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 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 /**
29  * DOC: qdf_hrtimer
30  * This file abstracts high resolution timers running in hardware context.
31  */
32 
33 #ifndef _QDF_HRTIMER_H
34 #define _QDF_HRTIMER_H
35 
36 #include <qdf_types.h>
37 #include <i_qdf_hrtimer.h>
38 #include <qdf_time.h>
39 
40 /* Context independent hrtimer object */
41 typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
42 
43 /* Platform independent timer callback function */
44 typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
45 					(qdf_hrtimer_data_t *timer);
46 
47 /**
48  * qdf_hrtimer_start() - Starts hrtimer in given context
49  * @timer: pointer to the qdf_hrtimer_data_t object
50  * @interval: interval to forward as qdf_ktime_t object
51  * @mode: mode of qdf_hrtimer_data_t
52  *
53  * Starts hrtimer in given context
54  *
55  * Return: void
56  */
57 static inline
58 void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
59 		       enum qdf_hrtimer_mode mode)
60 {
61 	__qdf_hrtimer_start(timer, interval, mode);
62 }
63 
64 /**
65  * qdf_hrtimer_cancel() - Cancels hrtimer in given context
66  * @timer: pointer to the qdf_hrtimer_data_t object
67  *
68  * Cancels hrtimer in given context
69  *
70  * Return: void
71  */
72 static inline
73 void qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
74 {
75 	__qdf_hrtimer_cancel(timer);
76 }
77 
78 /**
79  * qdf_hrtimer_init() - init hrtimer based on context
80  * @timer: pointer to the qdf_hrtimer_data_t object
81  * @callback: callback function to be fired
82  * @qdf_clock_id: clock type
83  * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
84  * @qdf_context_mode: interrupt context mode
85  *
86  * starts hrtimer in a context passed as per qdf_context_mode
87  *
88  * Return: void
89  */
90 static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
91 				    qdf_hrtimer_func_t callback,
92 				    enum qdf_clock_id clock,
93 				    enum qdf_hrtimer_mode mode,
94 				    enum qdf_context_mode ctx)
95 {
96 	__qdf_hrtimer_init(timer, callback, clock, mode, ctx);
97 }
98 
99 /**
100  * qdf_hrtimer_kill() - kills hrtimer in given context
101  * @timer: pointer to the hrtimer object
102  *
103  * kills hrtimer in given context
104  *
105  * Return: void
106  */
107 static inline
108 void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
109 {
110 	 __qdf_hrtimer_kill(timer);
111 }
112 
113 /**
114  * qdf_hrtimer_get_remaining() - check remaining time in the timer
115  * @timer: pointer to the qdf_hrtimer_data_t object
116  *
117  * check whether the timer is on one of the queues
118  *
119  * Return: remaining time as qdf_ktime_t object
120  */
121 static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
122 {
123 	return __qdf_hrtimer_get_remaining(timer);
124 }
125 
126 /**
127  * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
128  * @timer: pointer to the qdf_hrtimer_data_t object
129  *
130  * check whether the timer is on one of the queues
131  *
132  * Return: false when the timer was not in queue
133  *         true when the timer was in queue
134  */
135 static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
136 {
137 	return __qdf_hrtimer_is_queued(timer);
138 }
139 
140 /**
141  * qdf_hrtimer_callback_running() - check if callback is running
142  * @timer: pointer to the qdf_hrtimer_data_t object
143  *
144  * check whether the timer is running the callback function
145  *
146  * Return: false when callback is not running
147  *         true when callback is running
148  */
149 static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
150 {
151 	return __qdf_hrtimer_callback_running(timer);
152 }
153 
154 /**
155  * qdf_hrtimer_active() - check if timer is active
156  * @timer: pointer to the qdf_hrtimer_data_t object
157  *
158  * Check if timer is active. A timer is active, when it is enqueued into
159  * the rbtree or the callback function is running.
160  *
161  * Return: false if timer is not active
162  *         true if timer is active
163  */
164 static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
165 {
166 	return __qdf_hrtimer_active(timer);
167 }
168 
169 /**
170  * qdf_hrtimer_cb_get_time() - get remaining time in callback
171  * @timer: pointer to the qdf_hrtimer_data_t object
172  *
173  * Get remaining time in the hrtimer callback
174  *
175  * Return: time remaining as qdf_ktime_t object
176  */
177 static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
178 {
179 	return __qdf_hrtimer_cb_get_time(timer);
180 }
181 
182 /**
183  * qdf_hrtimer_forward() - forward the hrtimer
184  * @timer: pointer to the qdf_hrtimer_data_t object
185  * @now: current time as qdf_ktime_t object
186  * @interval: interval to forward as qdf_ktime_t object
187  *
188  * Forward the timer expiry so it will expire in the future
189  *
190  * Return: the number of overruns
191  */
192 static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
193 					   qdf_ktime_t now,
194 					   qdf_ktime_t interval)
195 {
196 	return __qdf_hrtimer_forward(timer, now, interval);
197 }
198 
199 #endif /* _QDF_HRTIMER_H */
200