1 /*
2 * Copyright (c) 2014-2016, 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_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
qdf_timer_init(qdf_handle_t hdl,qdf_timer_t * timer,qdf_timer_func_t func,void * arg,QDF_TIMER_TYPE type)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 * If QDF timer multiplier is set, the timeout value may get scaled.
60 *
61 * Return: none
62 */
qdf_timer_start(qdf_timer_t * timer,int msec)63 static inline void qdf_timer_start(qdf_timer_t *timer, int msec)
64 {
65 __qdf_timer_start(timer, msec);
66 }
67
68 /**
69 * qdf_timer_start_on() - start a timer on assigned cpu
70 * @timer: timer to start
71 * @msec: Expiration period in milliseconds
72 * @cpu: cpu to attach timer
73 *
74 *
75 * Return: none
76 */
qdf_timer_start_on(qdf_timer_t * timer,int msec,int cpu)77 static inline void qdf_timer_start_on(qdf_timer_t *timer, int msec, int cpu)
78 {
79 __qdf_timer_start_on(timer, msec, cpu);
80 }
81
82 /**
83 * qdf_timer_mod() - modify the timeout on a timer
84 * @timer: timer to modify
85 * @msec: Expiration period in milliseconds
86 *
87 * If @timer is not active, it will be activated.
88 *
89 * If QDF timer multiplier is set, the timeout value may get scaled.
90 *
91 * Return: true if @timer is already active, false if @timer was not active
92 */
qdf_timer_mod(qdf_timer_t * timer,int msec)93 static inline bool qdf_timer_mod(qdf_timer_t *timer, int msec)
94 {
95 return __qdf_timer_mod(timer, msec);
96 }
97
98 /**
99 * qdf_timer_stop() - cancel a timer
100 * @timer: timer to cancel
101 *
102 * Note! The timer callback may be executing when this function call returns.
103 * If you want to ensure that it is not, use qdf_timer_sync_cancel() instead.
104 *
105 * Return: true if @timer was deactivated, false if @timer was not active
106 */
qdf_timer_stop(qdf_timer_t * timer)107 static inline bool qdf_timer_stop(qdf_timer_t *timer)
108 {
109 return __qdf_timer_stop(timer);
110 }
111
112 /**
113 * qdf_timer_sync_cancel - Cancel a timer synchronously
114 * @timer: timer to cancel
115 *
116 * If the timer callback is already running, this function blocks until it
117 * completes.
118 *
119 * Return: true if @timer was deactivated, false if @timer was not active
120 */
qdf_timer_sync_cancel(qdf_timer_t * timer)121 static inline bool qdf_timer_sync_cancel(qdf_timer_t *timer)
122 {
123 return __qdf_timer_sync_cancel(timer);
124 }
125
126 /**
127 * qdf_timer_free() - free a timer
128 * @timer: timer to free
129 *
130 * If the timer callback is already running, this function blocks until it
131 * completes.
132 *
133 * Return: none
134 */
qdf_timer_free(qdf_timer_t * timer)135 static inline void qdf_timer_free(qdf_timer_t *timer)
136 {
137 __qdf_timer_free(timer);
138 }
139
140 #endif /* _QDF_TIMER_H */
141