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_mc_timer 30 * QCA driver framework timer APIs serialized to MC thread 31 */ 32 33 #if !defined(__QDF_MC_TIMER_H) 34 #define __QDF_MC_TIMER_H 35 36 /* Include Files */ 37 #include <qdf_types.h> 38 #include <qdf_status.h> 39 #include <qdf_lock.h> 40 #include <i_qdf_mc_timer.h> 41 42 #ifdef TIMER_MANAGER 43 #include <qdf_list.h> 44 #endif 45 46 /* Preprocessor definitions and constants */ 47 #define QDF_TIMER_STATE_COOKIE (0x12) 48 #define QDF_MC_TIMER_TO_MS_UNIT (1000) 49 #define QDF_MC_TIMER_TO_SEC_UNIT (1000000) 50 51 /* Type declarations */ 52 /* qdf Timer callback function prototype (well, actually a prototype for 53 * a pointer to this callback function) 54 */ 55 typedef void (*qdf_mc_timer_callback_t)(void *user_data); 56 57 typedef enum { 58 QDF_TIMER_STATE_UNUSED = QDF_TIMER_STATE_COOKIE, 59 QDF_TIMER_STATE_STOPPED, 60 QDF_TIMER_STATE_STARTING, 61 QDF_TIMER_STATE_RUNNING, 62 } QDF_TIMER_STATE; 63 64 #ifdef TIMER_MANAGER 65 struct qdf_mc_timer_s; 66 typedef struct qdf_mc_timer_node_s { 67 qdf_list_node_t node; 68 char *file_name; 69 uint32_t line_num; 70 struct qdf_mc_timer_s *qdf_timer; 71 } qdf_mc_timer_node_t; 72 #endif 73 74 typedef struct qdf_mc_timer_s { 75 #ifdef TIMER_MANAGER 76 qdf_mc_timer_node_t *timer_node; 77 #endif 78 qdf_mc_timer_platform_t platform_info; 79 qdf_mc_timer_callback_t callback; 80 void *user_data; 81 qdf_mutex_t lock; 82 QDF_TIMER_TYPE type; 83 QDF_TIMER_STATE state; 84 } qdf_mc_timer_t; 85 86 87 void qdf_try_allowing_sleep(QDF_TIMER_TYPE type); 88 89 /* Function declarations and documenation */ 90 #ifdef TIMER_MANAGER 91 void qdf_mc_timer_manager_init(void); 92 void qdf_mc_timer_manager_exit(void); 93 void qdf_mc_timer_check_for_leaks(void); 94 #else 95 /** 96 * qdf_mc_timer_manager_init() - initialize QDF debug timer manager 97 * This API initializes QDF timer debug functionality. 98 * 99 * Return: none 100 */ 101 static inline void qdf_mc_timer_manager_init(void) 102 { 103 } 104 105 /** 106 * qdf_mc_timer_manager_exit() - exit QDF timer debug functionality 107 * This API exists QDF timer debug functionality 108 * 109 * Return: none 110 */ 111 static inline void qdf_mc_timer_manager_exit(void) 112 { 113 } 114 115 /** 116 * qdf_mc_timer_check_for_leaks() - Assert there are no active mc timers 117 * 118 * If there are active timers, this API prints them and panics. 119 * 120 * Return: None 121 */ 122 static inline void qdf_mc_timer_check_for_leaks(void) { } 123 #endif 124 /** 125 * qdf_mc_timer_get_current_state() - get the current state of the timer 126 * @timer: Pointer to timer object 127 * 128 * Return: 129 * QDF_TIMER_STATE - qdf timer state 130 */ 131 132 QDF_TIMER_STATE qdf_mc_timer_get_current_state(qdf_mc_timer_t *timer); 133 134 /** 135 * qdf_mc_timer_init() - initialize a QDF timer 136 * @timer: Pointer to timer object 137 * @timer_type: Type of timer 138 * @callback: Callback to be called after timer expiry 139 * @ser_data: User data which will be passed to callback function 140 * 141 * This API initializes a QDF Timer object. 142 * 143 * qdf_mc_timer_init() initializes a QDF Timer object. A timer must be 144 * initialized by calling qdf_mc_timer_initialize() before it may be used in 145 * any other timer functions. 146 * 147 * Attempting to initialize timer that is already initialized results in 148 * a failure. A destroyed timer object can be re-initialized with a call to 149 * qdf_mc_timer_init(). The results of otherwise referencing the object 150 * after it has been destroyed are undefined. 151 * 152 * Calls to QDF timer functions to manipulate the timer such 153 * as qdf_mc_timer_set() will fail if the timer is not initialized or has 154 * been destroyed. Therefore, don't use the timer after it has been 155 * destroyed until it has been re-initialized. 156 * 157 * All callback will be executed within the CDS main thread unless it is 158 * initialized from the Tx thread flow, in which case it will be executed 159 * within the tx thread flow. 160 * 161 * Return: 162 * QDF_STATUS_SUCCESS - Timer is initialized successfully 163 * QDF failure status - Timer initialization failed 164 */ 165 #ifdef TIMER_MANAGER 166 #define qdf_mc_timer_init(timer, timer_type, callback, userdata) \ 167 qdf_mc_timer_init_debug(timer, timer_type, callback, userdata, \ 168 __FILE__, __LINE__) 169 170 QDF_STATUS qdf_mc_timer_init_debug(qdf_mc_timer_t *timer, 171 QDF_TIMER_TYPE timer_type, 172 qdf_mc_timer_callback_t callback, 173 void *user_data, char *file_name, 174 uint32_t line_num); 175 #else 176 QDF_STATUS qdf_mc_timer_init(qdf_mc_timer_t *timer, QDF_TIMER_TYPE timer_type, 177 qdf_mc_timer_callback_t callback, 178 void *user_data); 179 #endif 180 181 /** 182 * qdf_mc_timer_destroy() - destroy QDF timer 183 * @timer: Pointer to timer object 184 * 185 * qdf_mc_timer_destroy() function shall destroy the timer object. 186 * After a successful return from \a qdf_mc_timer_destroy() the timer 187 * object becomes, in effect, uninitialized. 188 * 189 * A destroyed timer object can be re-initialized by calling 190 * qdf_mc_timer_init(). The results of otherwise referencing the object 191 * after it has been destroyed are undefined. 192 * 193 * Calls to QDF timer functions to manipulate the timer, such 194 * as qdf_mc_timer_set() will fail if the lock is destroyed. Therefore, 195 * don't use the timer after it has been destroyed until it has 196 * been re-initialized. 197 * 198 * Return: 199 * QDF_STATUS_SUCCESS - Timer is initialized successfully 200 * QDF failure status - Timer initialization failed 201 */ 202 QDF_STATUS qdf_mc_timer_destroy(qdf_mc_timer_t *timer); 203 204 /** 205 * qdf_mc_timer_start() - start a QDF Timer object 206 * @timer: Pointer to timer object 207 * @expiration_time: Time to expire 208 * 209 * qdf_mc_timer_start() function starts a timer to expire after the 210 * specified interval, thus running the timer callback function when 211 * the interval expires. 212 * 213 * A timer only runs once (a one-shot timer). To re-start the 214 * timer, qdf_mc_timer_start() has to be called after the timer runs 215 * or has been cancelled. 216 * 217 * Return: 218 * QDF_STATUS_SUCCESS - Timer is initialized successfully 219 * QDF failure status - Timer initialization failed 220 */ 221 QDF_STATUS qdf_mc_timer_start(qdf_mc_timer_t *timer, uint32_t expiration_time); 222 223 /** 224 * qdf_mc_timer_stop() - stop a QDF Timer 225 * @timer: Pointer to timer object 226 * qdf_mc_timer_stop() function stops a timer that has been started but 227 * has not expired, essentially cancelling the 'start' request. 228 * 229 * After a timer is stopped, it goes back to the state it was in after it 230 * was created and can be started again via a call to qdf_mc_timer_start(). 231 * 232 * Return: 233 * QDF_STATUS_SUCCESS - Timer is initialized successfully 234 * QDF failure status - Timer initialization failed 235 */ 236 QDF_STATUS qdf_mc_timer_stop(qdf_mc_timer_t *timer); 237 238 /** 239 * qdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks 240 * 241 * qdf_mc_timer_get_system_ticks() function returns the current number 242 * of timer ticks in 10msec intervals. This function is suitable timestamping 243 * and calculating time intervals by calculating the difference between two 244 * timestamps. 245 * 246 * Return: 247 * The current system tick count (in 10msec intervals). This 248 * function cannot fail. 249 */ 250 unsigned long qdf_mc_timer_get_system_ticks(void); 251 252 /** 253 * qdf_mc_timer_get_system_time() - Get the system time in milliseconds 254 * 255 * qdf_mc_timer_get_system_time() function returns the number of milliseconds 256 * that have elapsed since the system was started 257 * 258 * Return: 259 * The current system time in milliseconds 260 */ 261 unsigned long qdf_mc_timer_get_system_time(void); 262 263 /** 264 * qdf_get_monotonic_boottime_ns() - Get kernel boottime in ns 265 * 266 * Return: kernel boottime in nano sec 267 */ 268 s64 qdf_get_monotonic_boottime_ns(void); 269 270 /** 271 * qdf_timer_module_init() - initializes a QDF timer module. 272 * 273 * This API initializes the QDF timer module. This needs to be called 274 * exactly once prior to using any QDF timers. 275 * 276 * Return: none 277 */ 278 void qdf_timer_module_init(void); 279 280 /** 281 * qdf_get_time_of_the_day_ms() - get time of the day in millisec 282 * 283 * Return: time of the day in ms 284 */ 285 qdf_time_t qdf_get_time_of_the_day_ms(void); 286 287 /** 288 * qdf_timer_module_deinit() - Deinitializes a QDF timer module. 289 * 290 * This API deinitializes the QDF timer module. 291 * Return: none 292 */ 293 void qdf_timer_module_deinit(void); 294 295 /** 296 * qdf_get_time_of_the_day_in_hr_min_sec_usec() - Get system time 297 * @tbuf: Pointer to time stamp buffer 298 * @len: Time buffer size 299 * 300 * This function updates the 'tbuf' with system time in hr:min:sec:msec format 301 * 302 * Return: None 303 */ 304 void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len); 305 void qdf_register_mc_timer_callback(void (*callback) (unsigned long data)); 306 307 /** 308 * qdf_timer_set_multiplier() - set the global QDF timer scalar value 309 * @multiplier: the scalar value to apply 310 * 311 * Return: None 312 */ 313 void qdf_timer_set_multiplier(uint32_t multiplier); 314 315 /** 316 * qdf_timer_get_multiplier() - get the global QDF timer scalar value 317 * 318 * Return: the global QDF timer scalar value 319 */ 320 uint32_t qdf_timer_get_multiplier(void); 321 322 #endif /* __QDF_MC_TIMER_H */ 323