xref: /wlan-driver/qca-wifi-host-cmn/qdf/inc/qdf_periodic_work.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2019 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name /**
21*5113495bSYour Name  * DOC: qdf_periodic_work.h
22*5113495bSYour Name  * A simple, periodic work type for repeatedly executing a callback with a
23*5113495bSYour Name  * certain frequency.
24*5113495bSYour Name  */
25*5113495bSYour Name 
26*5113495bSYour Name #ifndef __QDF_PERIODIC_WORK_H
27*5113495bSYour Name #define __QDF_PERIODIC_WORK_H
28*5113495bSYour Name 
29*5113495bSYour Name #include "i_qdf_periodic_work.h"
30*5113495bSYour Name #include "qdf_status.h"
31*5113495bSYour Name #include "qdf_types.h"
32*5113495bSYour Name 
33*5113495bSYour Name typedef void (*qdf_periodic_work_cb)(void *context);
34*5113495bSYour Name 
35*5113495bSYour Name /**
36*5113495bSYour Name  * struct qdf_periodic_work - a deferred work type which executes a callback
37*5113495bSYour Name  *	periodically until stopped
38*5113495bSYour Name  * @dwork: OS-specific delayed work
39*5113495bSYour Name  * @callback: the callback to be executed periodically
40*5113495bSYour Name  * @context: the context to pass to the callback
41*5113495bSYour Name  * @msec: the delay between executions in milliseconds
42*5113495bSYour Name  */
43*5113495bSYour Name struct qdf_periodic_work {
44*5113495bSYour Name 	struct __qdf_opaque_delayed_work dwork;
45*5113495bSYour Name 	qdf_periodic_work_cb callback;
46*5113495bSYour Name 	void *context;
47*5113495bSYour Name 	uint32_t msec;
48*5113495bSYour Name };
49*5113495bSYour Name 
50*5113495bSYour Name /**
51*5113495bSYour Name  * qdf_periodic_work_create() - initialized a periodic work @pwork
52*5113495bSYour Name  * @pwork: the periodic work to initialize
53*5113495bSYour Name  * @callback: the callback to be executed periodically
54*5113495bSYour Name  * @context: the context to pass to the callback
55*5113495bSYour Name  *
56*5113495bSYour Name  * Return: QDF_STATUS
57*5113495bSYour Name  */
58*5113495bSYour Name #define qdf_periodic_work_create(pwork, callback, context) \
59*5113495bSYour Name 	__qdf_periodic_work_create(pwork, callback, context, __func__, __LINE__)
60*5113495bSYour Name 
61*5113495bSYour Name qdf_must_check QDF_STATUS
62*5113495bSYour Name __qdf_periodic_work_create(struct qdf_periodic_work *pwork,
63*5113495bSYour Name 			   qdf_periodic_work_cb callback, void *context,
64*5113495bSYour Name 			   const char *func, uint32_t line);
65*5113495bSYour Name 
66*5113495bSYour Name /**
67*5113495bSYour Name  * qdf_periodic_work_destroy() - deinitialize a periodic work @pwork
68*5113495bSYour Name  * @pwork: the periodic work to de-initialize
69*5113495bSYour Name  *
70*5113495bSYour Name  * Return: None
71*5113495bSYour Name  */
72*5113495bSYour Name #define qdf_periodic_work_destroy(pwork) \
73*5113495bSYour Name 	__qdf_periodic_work_destroy(pwork, __func__, __LINE__)
74*5113495bSYour Name 
75*5113495bSYour Name void __qdf_periodic_work_destroy(struct qdf_periodic_work *pwork,
76*5113495bSYour Name 				 const char *func, uint32_t line);
77*5113495bSYour Name 
78*5113495bSYour Name /**
79*5113495bSYour Name  * qdf_periodic_work_start() - begin periodic execution of @pwork callback
80*5113495bSYour Name  * @pwork: the periodic work to start
81*5113495bSYour Name  * @msec: the delay between executions in milliseconds
82*5113495bSYour Name  *
83*5113495bSYour Name  * Return: true if started successfully
84*5113495bSYour Name  */
85*5113495bSYour Name bool qdf_periodic_work_start(struct qdf_periodic_work *pwork, uint32_t msec);
86*5113495bSYour Name 
87*5113495bSYour Name /**
88*5113495bSYour Name  * qdf_periodic_work_stop_async() - Asynchronously stop execution of @pwork
89*5113495bSYour Name  * @pwork: the periodic work to stop
90*5113495bSYour Name  *
91*5113495bSYour Name  * When this returns, @pwork is guaranteed to not be queued, *but* its callback
92*5113495bSYour Name  * may still be executing.
93*5113495bSYour Name  *
94*5113495bSYour Name  * This is safe to call from the @pwork callback.
95*5113495bSYour Name  *
96*5113495bSYour Name  * Return: true if @pwork was previously started
97*5113495bSYour Name  */
98*5113495bSYour Name bool qdf_periodic_work_stop_async(struct qdf_periodic_work *pwork);
99*5113495bSYour Name 
100*5113495bSYour Name /**
101*5113495bSYour Name  * qdf_periodic_work_stop_sync() - Synchronously stop execution of @pwork
102*5113495bSYour Name  * @pwork: the periodic work to stop
103*5113495bSYour Name  *
104*5113495bSYour Name  * When this returns, @pwork is guaranteed to not be queued, and its callback
105*5113495bSYour Name  * not executing.
106*5113495bSYour Name  *
107*5113495bSYour Name  * This will deadlock if called from the @pwork callback.
108*5113495bSYour Name  *
109*5113495bSYour Name  * Return: true if @pwork was previously started
110*5113495bSYour Name  */
111*5113495bSYour Name bool qdf_periodic_work_stop_sync(struct qdf_periodic_work *pwork);
112*5113495bSYour Name 
113*5113495bSYour Name #ifdef WLAN_PERIODIC_WORK_DEBUG
114*5113495bSYour Name /**
115*5113495bSYour Name  * qdf_periodic_work_check_for_leaks() - assert no periodic work leaks
116*5113495bSYour Name  *
117*5113495bSYour Name  * Return: None
118*5113495bSYour Name  */
119*5113495bSYour Name void qdf_periodic_work_check_for_leaks(void);
120*5113495bSYour Name 
121*5113495bSYour Name /**
122*5113495bSYour Name  * qdf_periodic_work_feature_init() - global init logic for periodic work
123*5113495bSYour Name  *
124*5113495bSYour Name  * Return: None
125*5113495bSYour Name  */
126*5113495bSYour Name void qdf_periodic_work_feature_init(void);
127*5113495bSYour Name 
128*5113495bSYour Name /**
129*5113495bSYour Name  * qdf_periodic_work_feature_deinit() - global de-init logic for periodic work
130*5113495bSYour Name  *
131*5113495bSYour Name  * Return: None
132*5113495bSYour Name  */
133*5113495bSYour Name void qdf_periodic_work_feature_deinit(void);
134*5113495bSYour Name #else
qdf_periodic_work_check_for_leaks(void)135*5113495bSYour Name static inline void qdf_periodic_work_check_for_leaks(void) { }
qdf_periodic_work_feature_init(void)136*5113495bSYour Name static inline void qdf_periodic_work_feature_init(void) { }
qdf_periodic_work_feature_deinit(void)137*5113495bSYour Name static inline void qdf_periodic_work_feature_deinit(void) { }
138*5113495bSYour Name #endif /* WLAN_PERIODIC_WORK_DEBUG */
139*5113495bSYour Name 
140*5113495bSYour Name #endif /* __QDF_PERIODIC_WORK_H */
141*5113495bSYour Name 
142