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