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