xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_timer.h (revision ad85c389289a03e320cd08dea21861f9857892fc)
1 /*
2  * Copyright (c) 2014-2016, 2018-2019 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_timer
21  * This file abstracts OS timers running in soft IRQ context.
22  */
23 
24 #ifndef _QDF_TIMER_H
25 #define _QDF_TIMER_H
26 
27 #include <qdf_types.h>
28 #include <i_qdf_timer.h>
29 
30 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
31 typedef struct __qdf_timer_t qdf_timer_t;
32 #else
33 typedef __qdf_timer_t qdf_timer_t;
34 #endif
35 
36 /**
37  * qdf_timer_init() - initialize a timer
38  * @hdl: OS handle
39  * @timer: Timer object pointer
40  * @func: Timer function
41  * @arg: Argument of timer function
42  * @type: deferrable or non deferrable timer type
43  *
44  * Timer type QDF_TIMER_TYPE_SW means its a deferrable sw timer which will
45  * not cause CPU wake upon expiry
46  * Timer type QDF_TIMER_TYPE_WAKE_APPS means its a non-deferrable timer which
47  * will cause CPU wake up on expiry
48  *
49  * Return: QDF_STATUS
50  */
51 static inline QDF_STATUS
52 qdf_timer_init(qdf_handle_t hdl, qdf_timer_t *timer, qdf_timer_func_t func,
53 	       void *arg, QDF_TIMER_TYPE type)
54 {
55 	return __qdf_timer_init(timer, func, arg, type);
56 }
57 
58 /**
59  * qdf_timer_start() - start a timer
60  * @timer: timer to start
61  * @msec: Expiration period in milliseconds
62  *
63  * Return: none
64  */
65 static inline void qdf_timer_start(qdf_timer_t *timer, int msec)
66 {
67 	__qdf_timer_start(timer, msec);
68 }
69 
70 /**
71  * qdf_timer_mod() - modify the timeout on a timer
72  * @timer: timer to modify
73  * @msec: Expiration period in milliseconds
74  *
75  * If @timer is not active, it will be activated.
76  *
77  * Return: none
78  */
79 static inline void qdf_timer_mod(qdf_timer_t *timer, int msec)
80 {
81 	__qdf_timer_mod(timer, msec);
82 }
83 
84 /**
85  * qdf_timer_stop() - cancel a timer
86  * @timer: timer to cancel
87  *
88  * Note! The timer callback may be executing when this function call returns.
89  * If you want to ensure that it is not, use qdf_timer_sync_cancel() instead.
90  *
91  * Return: true if @timer was deactivated, false if @timer was not active
92  */
93 static inline bool qdf_timer_stop(qdf_timer_t *timer)
94 {
95 	return __qdf_timer_stop(timer);
96 }
97 
98 /**
99  * qdf_timer_sync_cancel - Cancel a timer synchronously
100  * @timer: timer to cancel
101  *
102  * If the timer callback is already running, this function blocks until it
103  * completes.
104  *
105  * Return: true if @timer was deactivated, false if @timer was not active
106  */
107 static inline bool qdf_timer_sync_cancel(qdf_timer_t *timer)
108 {
109 	return __qdf_timer_sync_cancel(timer);
110 }
111 
112 /**
113  * qdf_timer_free() - free a timer
114  * @timer: timer to free
115  *
116  * If the timer callback is already running, this function blocks until it
117  * completes.
118  *
119  * Return: none
120  */
121 static inline void qdf_timer_free(qdf_timer_t *timer)
122 {
123 	__qdf_timer_free(timer);
124 }
125 
126 #endif /* _QDF_TIMER_H */
127