xref: /wlan-dirver/qca-wifi-host-cmn/scheduler/inc/scheduler_api.h (revision c7ee85c4a8a137b3fbd2615cffa733a81882242f)
1 /*
2  * Copyright (c) 2014-2018 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 #if !defined(__SCHEDULER_API_H)
20 #define __SCHEDULER_API_H
21 
22 #include <qdf_event.h>
23 #include <qdf_types.h>
24 #include <qdf_lock.h>
25 #include <qdf_mc_timer.h>
26 #include <qdf_status.h>
27 
28 /* Controller thread various event masks
29  * MC_POST_EVENT_MASK: wake up thread after posting message
30  * MC_SUSPEND_EVENT_MASK: signal thread to suspend during kernel pm suspend
31  * MC_SHUTDOWN_EVENT_MASK: signal thread to shutdown and exit during unload
32  */
33 #define MC_POST_EVENT_MASK               0x001
34 #define MC_SUSPEND_EVENT_MASK            0x002
35 #define MC_SHUTDOWN_EVENT_MASK           0x010
36 
37 /*
38  * Cookie for timer messages.  Note that anyone posting a timer message
39  * has to write the COOKIE in the reserved field of the message.  The
40  * timer queue handler relies on this COOKIE
41  */
42 #define SYS_MSG_COOKIE      0xFACE
43 
44 typedef enum {
45 	SYS_MSG_ID_MC_THR_PROBE,
46 	SYS_MSG_ID_MC_TIMER,
47 	SYS_MSG_ID_FTM_RSP,
48 	SYS_MSG_ID_QVIT,
49 	SYS_MSG_ID_DATA_STALL_MSG,
50 	SYS_MSG_ID_UMAC_STOP,
51 } SYS_MSG_ID;
52 
53 /**
54  * struct scheduler_msg: scheduler message structure
55  * @type: message type
56  * @reserved: reserved field
57  * @bodyval: message body val
58  * @bodyptr: message body pointer based on the type either a bodyptr pointer
59  *     into memory or bodyval as a 32 bit data is used. bodyptr is always a
60  *     freeable pointer, one should always make sure that bodyptr is always
61  *     freeable.
62  * Messages should use either bodyptr or bodyval; not both !!!
63  * @callback: callback to be called by scheduler thread once message is posted
64  *   and scheduler thread has started processing the message.
65  * @flush_callback: flush callback which will be invoked during driver unload
66  *   such that component can release the ref count of common global objects
67  *   like PSOC, PDEV, VDEV and PEER. A component needs to populate flush
68  *   callback in message body pointer for those messages which have taken ref
69  *   count for above mentioned common objects.
70  * @node: list node for queue membership
71  */
72 struct scheduler_msg {
73 	uint16_t type;
74 	uint16_t reserved;
75 	uint32_t bodyval;
76 	void *bodyptr;
77 	void *callback;
78 	void *flush_callback;
79 	qdf_list_node_t node;
80 };
81 
82 typedef QDF_STATUS (*scheduler_msg_process_fn_t) (struct scheduler_msg  *msg);
83 typedef void (*hdd_suspend_callback)(void);
84 
85 /**
86  * scheduler_init() - initialize control path scheduler
87  *
88  * This API initializes control path scheduler.
89  *
90  * Return: QDF status
91  */
92 QDF_STATUS scheduler_init(void);
93 
94 /**
95  * scheduler_deinit() - de-initialize control path scheduler
96  *
97  * This API de-initializes control path scheduler.
98  *
99  * Return: QDF status
100  */
101 QDF_STATUS scheduler_deinit(void);
102 
103 /**
104  * scheduler_enable() - start the scheduler module
105  *
106  * Ready the scheduler module to service requests, and start the scheduler's
107  * message processing thread. Must only be called after scheduler_init().
108  *
109  * Return: QDF_STATUS
110  */
111 QDF_STATUS scheduler_enable(void);
112 
113 /**
114  * scheduler_disable() - stop the scheduler module
115  *
116  * Stop the scheduler module from servicing requests, and terminate the
117  * scheduler's message processing thread. Must be called before
118  * scheduler_deinit().
119  *
120  * Return: QDF_STATUS
121  */
122 QDF_STATUS scheduler_disable(void);
123 
124 /**
125  * scheduler_register_module() - register input module/queue id
126  * @qid: queue id to get registered
127  * @callback: queue message to be called when a message is posted
128  *
129  * Return: QDF status
130  */
131 QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid,
132 		scheduler_msg_process_fn_t callback);
133 
134 /**
135  * scheduler_deregister_module() - deregister input module/queue id
136  * @qid: queue id to get deregistered
137  *
138  * Return: QDF status
139  */
140 QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid);
141 
142 /**
143  * scheduler_post_msg_by_priority() - post messages by priority
144  * @qid: queue id to to post message
145  * @msg: message pointer
146  * @is_high_priority: set to true for high priority message else false
147  *
148  * Return: QDF status
149  */
150 QDF_STATUS scheduler_post_msg_by_priority(QDF_MODULE_ID qid,
151 		struct scheduler_msg *msg, bool is_high_priority);
152 
153 /**
154  * scheduler_post_msg() - post normal messages(no priority)
155  * @qid: queue id to to post message
156  * @msg: message pointer
157  *
158  * Return: QDF status
159  */
160 static inline QDF_STATUS scheduler_post_msg(QDF_MODULE_ID qid,
161 		struct scheduler_msg *msg)
162 {
163 	return scheduler_post_msg_by_priority(qid, msg, false);
164 }
165 
166 /**
167  * scheduler_resume() - resume scheduler thread
168  *
169  * Complete scheduler thread resume wait event such that scheduler
170  * thread can wake up and process message queues
171  *
172  * Return: none
173  */
174 void scheduler_resume(void);
175 
176 /**
177  * scheduler_register_hdd_suspend_callback() - suspend callback to hdd
178  * @callback: hdd callback to be called when controllred thread is suspended
179  *
180  * Return: none
181  */
182 void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback);
183 
184 /**
185  * scheduler_wake_up_controller_thread() - wake up controller thread
186  *
187  * Wake up controller thread to process a critical message.
188  *
189  * Return: none
190  */
191 void scheduler_wake_up_controller_thread(void);
192 
193 /**
194  * scheduler_set_event_mask() - set given event mask
195  * @event_mask: event mask to set
196  *
197  * Set given event mask such that controller scheduler thread can do
198  * specified work after wake up.
199  *
200  * Return: none
201  */
202 void scheduler_set_event_mask(uint32_t event_mask);
203 
204 /**
205  * scheduler_clear_event_mask() - clear given event mask
206  * @event_mask: event mask to set
207  *
208  * Return: none
209  */
210 void scheduler_clear_event_mask(uint32_t event_mask);
211 
212 /**
213  * scheduler_target_if_mq_handler() - top level message queue handler for
214  *                                    target_if message queue
215  * @msg: pointer to actual message being handled
216  *
217  * Return: none
218  */
219 QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg);
220 
221 /**
222  * scheduler_os_if_mq_handler() - top level message queue handler for
223  *                                os_if message queue
224  * @msg: pointer to actual message being handled
225  *
226  * Return: none
227  */
228 QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg);
229 
230 /**
231  * scheduler_timer_q_mq_handler() - top level message queue handler for
232  *                                timer queue
233  * @msg: pointer to actual message being handled
234  *
235  * Return: none
236  */
237 QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg);
238 
239 /**
240  * scheduler_scan_mq_handler() - top level message queue handler for
241  *                               scan queue
242  * @msg: pointer to actual message being handled
243  *
244  * Return: QDF status
245  */
246 QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg);
247 
248 /**
249  * scheduler_register_wma_legacy_handler() - register legacy wma handler
250  * @callback: legacy wma handler to be called for WMA messages
251  *
252  * Return: QDF status
253  */
254 QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t
255 						callback);
256 
257 /**
258  * scheduler_register_sys_legacy_handler() - register legacy sys handler
259  * @callback: legacy sys handler to be called for sys messages
260  *
261  * Return: QDF status
262  */
263 QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t
264 						callback);
265 /**
266  * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler
267  *
268  * Return: QDF status
269  */
270 QDF_STATUS scheduler_deregister_sys_legacy_handler(void);
271 
272 /**
273  * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler
274  *
275  * Return: QDF status
276  */
277 QDF_STATUS scheduler_deregister_wma_legacy_handler(void);
278 
279 /**
280  * scheduler_mc_timer_callback() - timer callback, gets called at time out
281  * @data: unsigned long, holds the timer object.
282  *
283  * Return: None
284  */
285 void scheduler_mc_timer_callback(unsigned long data);
286 
287 #endif
288