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