xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_periodic_work.h (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
1 /*
2  * Copyright (c) 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_periodic_work.h
21  * A simple, periodic work type for repeatedly executing a callback with a
22  * certain frequency.
23  */
24 
25 #ifndef __QDF_PERIODIC_WORK_H
26 #define __QDF_PERIODIC_WORK_H
27 
28 #include "i_qdf_periodic_work.h"
29 #include "qdf_status.h"
30 #include "qdf_types.h"
31 
32 typedef void (*qdf_periodic_work_cb)(void *context);
33 
34 /**
35  * struct qdf_periodic_work - a defered work type which executes a callback
36  *	periodically until stopped
37  * @dwork: OS-specific delayed work
38  * @callback: the callback to be executed periodically
39  * @context: the context to pass to the callback
40  * @msec: the delay between executions in milliseconds
41  */
42 struct qdf_periodic_work {
43 	struct __qdf_opaque_delayed_work dwork;
44 	qdf_periodic_work_cb callback;
45 	void *context;
46 	uint32_t msec;
47 };
48 
49 /**
50  * qdf_periodic_work_create() - initialized a periodic work @pwork
51  * @pwork: the periodic work to initialize
52  * @callback: the callback to be executed periodically
53  * @context: the context to pass to the callback
54  *
55  * Return: QDF_STATUS
56  */
57 #define qdf_periodic_work_create(pwork, callback, context) \
58 	__qdf_periodic_work_create(pwork, callback, context, __func__, __LINE__)
59 
60 qdf_must_check QDF_STATUS
61 __qdf_periodic_work_create(struct qdf_periodic_work *pwork,
62 			   qdf_periodic_work_cb callback, void *context,
63 			   const char *func, uint32_t line);
64 
65 /**
66  * qdf_periodic_work_destroy() - deinitialize a periodic work @pwork
67  * @pwork: the periodic work to de-initialize
68  *
69  * Return: None
70  */
71 #define qdf_periodic_work_destroy(pwork) \
72 	__qdf_periodic_work_destroy(pwork, __func__, __LINE__)
73 
74 void __qdf_periodic_work_destroy(struct qdf_periodic_work *pwork,
75 				 const char *func, uint32_t line);
76 
77 /**
78  * qdf_periodic_work_start() - begin periodic execution of @pwork callback
79  * @pwork: the periodic work to start
80  * @msec: the delay between executions in milliseconds
81  *
82  * Return: true if started successfully
83  */
84 bool qdf_periodic_work_start(struct qdf_periodic_work *pwork, uint32_t msec);
85 
86 /**
87  * qdf_periodic_work_stop_async() - Asynchronously stop execution of @pwork
88  * @pwork: the periodic work to stop
89  *
90  * When this returns, @pwork is guaranteed to not be queued, *but* its callback
91  * may still be executing.
92  *
93  * This is safe to call from the @pwork callback.
94  *
95  * Return: true if @pwork was previously started
96  */
97 bool qdf_periodic_work_stop_async(struct qdf_periodic_work *pwork);
98 
99 /**
100  * qdf_periodic_work_stop_sync() - Synchronously stop execution of @pwork
101  * @pwork: the periodic work to stop
102  *
103  * When this returns, @pwork is guaranteed to not be queued, and its callback
104  * not executing.
105  *
106  * This will deadlock if called from the @pwork callback.
107  *
108  * Return: true if @pwork was previously started
109  */
110 bool qdf_periodic_work_stop_sync(struct qdf_periodic_work *pwork);
111 
112 #ifdef WLAN_PERIODIC_WORK_DEBUG
113 /**
114  * qdf_periodic_work_check_for_leaks() - assert no periodic work leaks
115  *
116  * Return: None
117  */
118 void qdf_periodic_work_check_for_leaks(void);
119 
120 /**
121  * qdf_periodic_work_feature_init() - global init logic for periodic work
122  *
123  * Return: None
124  */
125 void qdf_periodic_work_feature_init(void);
126 
127 /**
128  * qdf_periodic_work_feature_deinit() - global de-init logic for periodic work
129  *
130  * Return: None
131  */
132 void qdf_periodic_work_feature_deinit(void);
133 #else
134 static inline void qdf_periodic_work_check_for_leaks(void) { }
135 static inline void qdf_periodic_work_feature_init(void) { }
136 static inline void qdf_periodic_work_feature_deinit(void) { }
137 #endif /* WLAN_PERIODIC_WORK_DEBUG */
138 
139 #endif /* __QDF_PERIODIC_WORK_H */
140 
141