xref: /wlan-dirver/qca-wifi-host-cmn/scheduler/inc/scheduler_api.h (revision 6e4b9c54b687e18b0132e53b73b6cc7445a0ba3d)
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 #define scheduler_get_src_id(qid)       ((qid) >> 16)
45 #define scheduler_get_dest_id(qid)      ((qid) & 0xFFFF)
46 #define scheduler_get_qid(src, dest)    ((dest) | ((src) << 16))
47 
48 typedef enum {
49 	SYS_MSG_ID_MC_TIMER,
50 	SYS_MSG_ID_FTM_RSP,
51 	SYS_MSG_ID_QVIT,
52 	SYS_MSG_ID_DATA_STALL_MSG,
53 	SYS_MSG_ID_UMAC_STOP,
54 } SYS_MSG_ID;
55 
56 /**
57  * struct scheduler_msg: scheduler message structure
58  * @type: message type
59  * @reserved: reserved field
60  * @bodyval: message body val
61  * @bodyptr: message body pointer based on the type either a bodyptr pointer
62  *     into memory or bodyval as a 32 bit data is used. bodyptr is always a
63  *     freeable pointer, one should always make sure that bodyptr is always
64  *     freeable.
65  * Messages should use either bodyptr or bodyval; not both !!!
66  * @callback: callback to be called by scheduler thread once message is posted
67  *   and scheduler thread has started processing the message.
68  * @flush_callback: flush callback which will be invoked during driver unload
69  *   such that component can release the ref count of common global objects
70  *   like PSOC, PDEV, VDEV and PEER. A component needs to populate flush
71  *   callback in message body pointer for those messages which have taken ref
72  *   count for above mentioned common objects.
73  * @node: list node for queue membership
74  */
75 struct scheduler_msg {
76 	uint16_t type;
77 	uint16_t reserved;
78 	uint32_t bodyval;
79 	void *bodyptr;
80 	void *callback;
81 	void *flush_callback;
82 	qdf_list_node_t node;
83 };
84 
85 typedef QDF_STATUS (*scheduler_msg_process_fn_t) (struct scheduler_msg  *msg);
86 typedef void (*hdd_suspend_callback)(void);
87 
88 /**
89  * scheduler_init() - initialize control path scheduler
90  *
91  * This API initializes control path scheduler.
92  *
93  * Return: QDF status
94  */
95 QDF_STATUS scheduler_init(void);
96 
97 /**
98  * scheduler_deinit() - de-initialize control path scheduler
99  *
100  * This API de-initializes control path scheduler.
101  *
102  * Return: QDF status
103  */
104 QDF_STATUS scheduler_deinit(void);
105 
106 /**
107  * scheduler_enable() - start the scheduler module
108  *
109  * Ready the scheduler module to service requests, and start the scheduler's
110  * message processing thread. Must only be called after scheduler_init().
111  *
112  * Return: QDF_STATUS
113  */
114 QDF_STATUS scheduler_enable(void);
115 
116 /**
117  * scheduler_disable() - stop the scheduler module
118  *
119  * Stop the scheduler module from servicing requests, and terminate the
120  * scheduler's message processing thread. Must be called before
121  * scheduler_deinit().
122  *
123  * Return: QDF_STATUS
124  */
125 QDF_STATUS scheduler_disable(void);
126 
127 /**
128  * scheduler_register_module() - register input module/queue id
129  * @qid: queue id to get registered
130  * @callback: queue message to be called when a message is posted
131  *
132  * Return: QDF status
133  */
134 QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid,
135 		scheduler_msg_process_fn_t callback);
136 
137 /**
138  * scheduler_deregister_module() - deregister input module/queue id
139  * @qid: queue id to get deregistered
140  *
141  * Return: QDF status
142  */
143 QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid);
144 
145 /**
146  * scheduler_post_msg_by_priority() - post messages by priority
147  * @qid: queue id to which the message has to be posted.
148  * @msg: message pointer
149  * @is_high_priority: set to true for high priority message else false
150  *
151  * Return: QDF status
152  */
153 QDF_STATUS scheduler_post_msg_by_priority(uint32_t qid,
154 					  struct scheduler_msg *msg,
155 					  bool is_high_priority);
156 
157 /**
158  * scheduler_post_msg() - post normal messages(no priority)
159  * @qid: queue id to which the message has to be posted.
160  * @msg: message pointer
161  *
162  * Return: QDF status
163  */
164 static inline QDF_STATUS scheduler_post_msg(uint32_t qid,
165 					    struct scheduler_msg *msg)
166 {
167 	return scheduler_post_msg_by_priority(qid, msg, false);
168 }
169 
170 /**
171  * scheduler_post_message() - post normal messages(no priority)
172  * @src_id: Source module of the message
173  * @dest_id: Destination module of the message
174  * @msg: message pointer
175  *
176  * This function will mask the src_id, and destination id to qid of
177  * scheduler_post_msg
178  * Return: QDF status
179  */
180 static inline QDF_STATUS scheduler_post_message(QDF_MODULE_ID src_id,
181 						QDF_MODULE_ID dest_id,
182 						struct scheduler_msg *msg)
183 {
184 	return scheduler_post_msg(scheduler_get_qid(src_id, dest_id), msg);
185 }
186 
187 /**
188  * scheduler_resume() - resume scheduler thread
189  *
190  * Complete scheduler thread resume wait event such that scheduler
191  * thread can wake up and process message queues
192  *
193  * Return: none
194  */
195 void scheduler_resume(void);
196 
197 /**
198  * scheduler_register_hdd_suspend_callback() - suspend callback to hdd
199  * @callback: hdd callback to be called when controllred thread is suspended
200  *
201  * Return: none
202  */
203 void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback);
204 
205 /**
206  * scheduler_wake_up_controller_thread() - wake up controller thread
207  *
208  * Wake up controller thread to process a critical message.
209  *
210  * Return: none
211  */
212 void scheduler_wake_up_controller_thread(void);
213 
214 /**
215  * scheduler_set_event_mask() - set given event mask
216  * @event_mask: event mask to set
217  *
218  * Set given event mask such that controller scheduler thread can do
219  * specified work after wake up.
220  *
221  * Return: none
222  */
223 void scheduler_set_event_mask(uint32_t event_mask);
224 
225 /**
226  * scheduler_clear_event_mask() - clear given event mask
227  * @event_mask: event mask to set
228  *
229  * Return: none
230  */
231 void scheduler_clear_event_mask(uint32_t event_mask);
232 
233 /**
234  * scheduler_target_if_mq_handler() - top level message queue handler for
235  *                                    target_if message queue
236  * @msg: pointer to actual message being handled
237  *
238  * Return: none
239  */
240 QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg);
241 
242 /**
243  * scheduler_os_if_mq_handler() - top level message queue handler for
244  *                                os_if message queue
245  * @msg: pointer to actual message being handled
246  *
247  * Return: none
248  */
249 QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg);
250 
251 /**
252  * scheduler_timer_q_mq_handler() - top level message queue handler for
253  *                                timer queue
254  * @msg: pointer to actual message being handled
255  *
256  * Return: none
257  */
258 QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg);
259 
260 /**
261  * scheduler_scan_mq_handler() - top level message queue handler for
262  *                               scan queue
263  * @msg: pointer to actual message being handled
264  *
265  * Return: QDF status
266  */
267 QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg);
268 
269 /**
270  * scheduler_register_wma_legacy_handler() - register legacy wma handler
271  * @callback: legacy wma handler to be called for WMA messages
272  *
273  * Return: QDF status
274  */
275 QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t
276 						callback);
277 
278 /**
279  * scheduler_register_sys_legacy_handler() - register legacy sys handler
280  * @callback: legacy sys handler to be called for sys messages
281  *
282  * Return: QDF status
283  */
284 QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t
285 						callback);
286 /**
287  * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler
288  *
289  * Return: QDF status
290  */
291 QDF_STATUS scheduler_deregister_sys_legacy_handler(void);
292 
293 /**
294  * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler
295  *
296  * Return: QDF status
297  */
298 QDF_STATUS scheduler_deregister_wma_legacy_handler(void);
299 
300 /**
301  * scheduler_mc_timer_callback() - timer callback, gets called at time out
302  * @data: unsigned long, holds the timer object.
303  *
304  * Return: None
305  */
306 void scheduler_mc_timer_callback(unsigned long data);
307 
308 /**
309  * scheduler_get_queue_size() - Get the current size of the scheduler queue
310  * @qid: Queue ID for which the size is requested
311  * @size: Pointer to size where the size would be returned to the caller
312  *
313  * This API finds the size of the scheduler queue for the given Queue ID
314  *
315  * Return: QDF Status
316  */
317 QDF_STATUS scheduler_get_queue_size(QDF_MODULE_ID qid, uint32_t *size);
318 #endif
319