1 /*
2  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: qdf_delayed_work.h
22  * A simple, delayed work type for executing a callback after some delay.
23  */
24 
25 #ifndef __QDF_DELAYED_WORK_H
26 #define __QDF_DELAYED_WORK_H
27 
28 #include "i_qdf_delayed_work.h"
29 #include "qdf_status.h"
30 #include "qdf_types.h"
31 
32 typedef void (*qdf_delayed_work_cb)(void *context);
33 
34 /**
35  * struct qdf_delayed_work - a deferred work type which executes a callback after
36  *	some delay
37  * @dwork: OS-specific delayed work
38  * @callback: the callback to be executed
39  * @context: the context to pass to the callback
40  */
41 struct qdf_delayed_work {
42 	struct __qdf_opaque_delayed_work dwork;
43 	qdf_delayed_work_cb callback;
44 	void *context;
45 };
46 
47 /**
48  * qdf_delayed_work_create() - initialized a delayed work @dwork
49  * @dwork: the delayed work to initialize
50  * @callback: the callback to be executed
51  * @context: the context to pass to the callback
52  *
53  * Return: QDF_STATUS
54  */
55 #define qdf_delayed_work_create(dwork, callback, context) \
56 	__qdf_delayed_work_create(dwork, callback, context, __func__, __LINE__)
57 
58 qdf_must_check QDF_STATUS
59 __qdf_delayed_work_create(struct qdf_delayed_work *dwork,
60 			  qdf_delayed_work_cb callback, void *context,
61 			  const char *func, uint32_t line);
62 
63 /**
64  * qdf_delayed_work_destroy() - deinitialize a delayed work @dwork
65  * @dwork: the delayed work to de-initialize
66  *
67  * Return: None
68  */
69 #define qdf_delayed_work_destroy(dwork) \
70 	__qdf_delayed_work_destroy(dwork, __func__, __LINE__)
71 
72 void __qdf_delayed_work_destroy(struct qdf_delayed_work *dwork,
73 				const char *func, uint32_t line);
74 
75 /**
76  * qdf_delayed_work_start() - schedule execution of @dwork callback
77  * @dwork: the delayed work to start
78  * @msec: the delay before execution in milliseconds
79  *
80  * Return: true if started successfully
81  */
82 #define qdf_delayed_work_start(dwork, msec) \
83 	__qdf_delayed_work_start(dwork, msec)
84 
85 bool __qdf_delayed_work_start(struct qdf_delayed_work *dwork, uint32_t msec);
86 
87 /**
88  * qdf_delayed_work_stop_sync() - Synchronously stop execution of @dwork
89  * @dwork: the delayed work to stop
90  *
91  * When this returns, @dwork is guaranteed to not be queued, and its callback
92  * not executing.
93  *
94  * Return: true if @dwork was queued or running
95  */
96 #define qdf_delayed_work_stop_sync(dwork) \
97 	__qdf_delayed_work_stop_sync(dwork)
98 
99 bool __qdf_delayed_work_stop_sync(struct qdf_delayed_work *dwork);
100 
101 /**
102  * qdf_delayed_work_stop() - Stop execution of @dwork
103  * @dwork: the delayed work to stop
104  *
105  * Kill off a pending delayed_work
106  *
107  * Return: true if dwork was pending and canceled
108  */
109 #define qdf_delayed_work_stop(dwork) \
110 	__qdf_delayed_work_stop(dwork)
111 
112 bool __qdf_delayed_work_stop(struct qdf_delayed_work *dwork);
113 
114 #ifdef WLAN_DELAYED_WORK_DEBUG
115 /**
116  * qdf_delayed_work_check_for_leaks() - assert no delayed work leaks
117  *
118  * Return: None
119  */
120 void qdf_delayed_work_check_for_leaks(void);
121 
122 /**
123  * qdf_delayed_work_feature_init() - global init logic for delayed work
124  *
125  * Return: None
126  */
127 void qdf_delayed_work_feature_init(void);
128 
129 /**
130  * qdf_delayed_work_feature_deinit() - global de-init logic for delayed work
131  *
132  * Return: None
133  */
134 void qdf_delayed_work_feature_deinit(void);
135 #else
qdf_delayed_work_check_for_leaks(void)136 static inline void qdf_delayed_work_check_for_leaks(void) { }
qdf_delayed_work_feature_init(void)137 static inline void qdf_delayed_work_feature_init(void) { }
qdf_delayed_work_feature_deinit(void)138 static inline void qdf_delayed_work_feature_deinit(void) { }
139 #endif /* WLAN_DELAYED_WORK_DEBUG */
140 
141 #endif /* __QDF_DELAYED_WORK_H */
142 
143