1 /* 2 * Copyright (c) 2014-2018, 2021 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 #ifdef ENHANCED_OS_ABSTRACTION 39 /** 40 * qdf_hrtimer_start() - Starts hrtimer in given context 41 * @timer: pointer to the qdf_hrtimer_data_t object 42 * @interval: interval to forward as qdf_ktime_t object 43 * @mode: mode of qdf_hrtimer_data_t 44 * 45 * Starts hrtimer in given context 46 * 47 * Return: void 48 */ 49 void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval, 50 enum qdf_hrtimer_mode mode); 51 52 /** 53 * qdf_hrtimer_cancel() - Cancels hrtimer in given context 54 * @timer: pointer to the qdf_hrtimer_data_t object 55 * 56 * Cancels hrtimer in given context 57 * 58 * Return: int 59 */ 60 int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer); 61 62 /** 63 * qdf_hrtimer_init() - init hrtimer based on context 64 * @timer: pointer to the qdf_hrtimer_data_t object 65 * @callback: callback function to be fired 66 * @qdf_clock_id: clock type 67 * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t 68 * @qdf_context_mode: interrupt context mode 69 * 70 * starts hrtimer in a context passed as per qdf_context_mode 71 * 72 * Return: void 73 */ 74 void qdf_hrtimer_init(qdf_hrtimer_data_t *timer, 75 qdf_hrtimer_func_t callback, 76 enum qdf_clock_id clock, 77 enum qdf_hrtimer_mode mode, 78 enum qdf_context_mode ctx); 79 80 /** 81 * qdf_hrtimer_kill() - kills hrtimer in given context 82 * @timer: pointer to the hrtimer object 83 * 84 * kills hrtimer in given context 85 * 86 * Return: void 87 */ 88 void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer); 89 90 /** 91 * qdf_hrtimer_get_remaining() - check remaining time in the timer 92 * @timer: pointer to the qdf_hrtimer_data_t object 93 * 94 * check whether the timer is on one of the queues 95 * 96 * Return: remaining time as qdf_ktime_t object 97 */ 98 qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer); 99 100 /** 101 * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues 102 * @timer: pointer to the qdf_hrtimer_data_t object 103 * 104 * check whether the timer is on one of the queues 105 * 106 * Return: false when the timer was not in queue 107 * true when the timer was in queue 108 */ 109 bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer); 110 111 /** 112 * qdf_hrtimer_callback_running() - check if callback is running 113 * @timer: pointer to the qdf_hrtimer_data_t object 114 * 115 * check whether the timer is running the callback function 116 * 117 * Return: false when callback is not running 118 * true when callback is running 119 */ 120 bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer); 121 122 /** 123 * qdf_hrtimer_active() - check if timer is active 124 * @timer: pointer to the qdf_hrtimer_data_t object 125 * 126 * Check if timer is active. A timer is active, when it is enqueued into 127 * the rbtree or the callback function is running. 128 * 129 * Return: false if timer is not active 130 * true if timer is active 131 */ 132 bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer); 133 134 /** 135 * qdf_hrtimer_cb_get_time() - get remaining time in callback 136 * @timer: pointer to the qdf_hrtimer_data_t object 137 * 138 * Get remaining time in the hrtimer callback 139 * 140 * Return: time remaining as qdf_ktime_t object 141 */ 142 qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer); 143 144 /** 145 * qdf_hrtimer_forward() - forward the hrtimer 146 * @timer: pointer to the qdf_hrtimer_data_t object 147 * @now: current time as qdf_ktime_t object 148 * @interval: interval to forward as qdf_ktime_t object 149 * 150 * Forward the timer expiry so it will expire in the future 151 * 152 * Return: the number of overruns 153 */ 154 uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer, 155 qdf_ktime_t now, 156 qdf_ktime_t interval); 157 #else 158 /** 159 * qdf_hrtimer_start() - Starts hrtimer in given context 160 * @timer: pointer to the qdf_hrtimer_data_t object 161 * @interval: interval to forward as qdf_ktime_t object 162 * @mode: mode of qdf_hrtimer_data_t 163 * 164 * Starts hrtimer in given context 165 * 166 * Return: void 167 */ 168 static inline 169 void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval, 170 enum qdf_hrtimer_mode mode) 171 { 172 __qdf_hrtimer_start(timer, interval, mode); 173 } 174 175 /** 176 * qdf_hrtimer_cancel() - Cancels hrtimer in given context 177 * @timer: pointer to the qdf_hrtimer_data_t object 178 * 179 * Cancels hrtimer in given context 180 * 181 * Return: int 182 */ 183 static inline 184 int qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer) 185 { 186 return __qdf_hrtimer_cancel(timer); 187 } 188 189 /** 190 * qdf_hrtimer_init() - init hrtimer based on context 191 * @timer: pointer to the qdf_hrtimer_data_t object 192 * @callback: callback function to be fired 193 * @qdf_clock_id: clock type 194 * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t 195 * @qdf_context_mode: interrupt context mode 196 * 197 * starts hrtimer in a context passed as per qdf_context_mode 198 * 199 * Return: void 200 */ 201 static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer, 202 qdf_hrtimer_func_t callback, 203 enum qdf_clock_id clock, 204 enum qdf_hrtimer_mode mode, 205 enum qdf_context_mode ctx) 206 { 207 __qdf_hrtimer_init(timer, callback, clock, mode, ctx); 208 } 209 210 /** 211 * qdf_hrtimer_kill() - kills hrtimer in given context 212 * @timer: pointer to the hrtimer object 213 * 214 * kills hrtimer in given context 215 * 216 * Return: void 217 */ 218 static inline 219 void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer) 220 { 221 __qdf_hrtimer_kill(timer); 222 } 223 224 /** 225 * qdf_hrtimer_get_remaining() - check remaining time in the timer 226 * @timer: pointer to the qdf_hrtimer_data_t object 227 * 228 * check whether the timer is on one of the queues 229 * 230 * Return: remaining time as qdf_ktime_t object 231 */ 232 static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer) 233 { 234 return __qdf_hrtimer_get_remaining(timer); 235 } 236 237 /** 238 * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues 239 * @timer: pointer to the qdf_hrtimer_data_t object 240 * 241 * check whether the timer is on one of the queues 242 * 243 * Return: false when the timer was not in queue 244 * true when the timer was in queue 245 */ 246 static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer) 247 { 248 return __qdf_hrtimer_is_queued(timer); 249 } 250 251 /** 252 * qdf_hrtimer_callback_running() - check if callback is running 253 * @timer: pointer to the qdf_hrtimer_data_t object 254 * 255 * check whether the timer is running the callback function 256 * 257 * Return: false when callback is not running 258 * true when callback is running 259 */ 260 static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer) 261 { 262 return __qdf_hrtimer_callback_running(timer); 263 } 264 265 /** 266 * qdf_hrtimer_active() - check if timer is active 267 * @timer: pointer to the qdf_hrtimer_data_t object 268 * 269 * Check if timer is active. A timer is active, when it is enqueued into 270 * the rbtree or the callback function is running. 271 * 272 * Return: false if timer is not active 273 * true if timer is active 274 */ 275 static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer) 276 { 277 return __qdf_hrtimer_active(timer); 278 } 279 280 /** 281 * qdf_hrtimer_cb_get_time() - get remaining time in callback 282 * @timer: pointer to the qdf_hrtimer_data_t object 283 * 284 * Get remaining time in the hrtimer callback 285 * 286 * Return: time remaining as qdf_ktime_t object 287 */ 288 static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer) 289 { 290 return __qdf_hrtimer_cb_get_time(timer); 291 } 292 293 /** 294 * qdf_hrtimer_forward() - forward the hrtimer 295 * @timer: pointer to the qdf_hrtimer_data_t object 296 * @now: current time as qdf_ktime_t object 297 * @interval: interval to forward as qdf_ktime_t object 298 * 299 * Forward the timer expiry so it will expire in the future 300 * 301 * Return: the number of overruns 302 */ 303 static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer, 304 qdf_ktime_t now, 305 qdf_ktime_t interval) 306 { 307 return __qdf_hrtimer_forward(timer, now, interval); 308 } 309 #endif 310 311 #endif /* _QDF_HRTIMER_H */ 312