1 /* 2 * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #if !defined(__SCHEDULER_API_H) 21 #define __SCHEDULER_API_H 22 23 #include <qdf_event.h> 24 #include <qdf_types.h> 25 #include <qdf_lock.h> 26 #include <qdf_mc_timer.h> 27 #include <qdf_status.h> 28 29 /* Controller thread various event masks 30 * MC_POST_EVENT_MASK: wake up thread after posting message 31 * MC_SUSPEND_EVENT_MASK: signal thread to suspend during kernel pm suspend 32 * MC_SHUTDOWN_EVENT_MASK: signal thread to shutdown and exit during unload 33 */ 34 #define MC_POST_EVENT_MASK 0x001 35 #define MC_SUSPEND_EVENT_MASK 0x002 36 #define MC_SHUTDOWN_EVENT_MASK 0x010 37 38 /* 39 * Cookie for timer messages. Note that anyone posting a timer message 40 * has to write the COOKIE in the reserved field of the message. The 41 * timer queue handler relies on this COOKIE 42 */ 43 #define SYS_MSG_COOKIE 0xFACE 44 45 #define scheduler_get_src_id(qid) (((qid) >> 20) & 0x3FF) 46 #define scheduler_get_dest_id(qid) (((qid) >> 10) & 0x3FF) 47 #define scheduler_get_que_id(qid) ((qid) & 0x3FF) 48 #define scheduler_get_qid(src, dest, que_id) ((que_id) | ((dest) << 10) |\ 49 ((src) << 20)) 50 51 typedef enum { 52 SYS_MSG_ID_MC_TIMER, 53 SYS_MSG_ID_FTM_RSP, 54 SYS_MSG_ID_QVIT, 55 SYS_MSG_ID_DATA_STALL_MSG, 56 SYS_MSG_ID_UMAC_STOP, 57 } SYS_MSG_ID; 58 59 struct scheduler_msg; 60 typedef QDF_STATUS (*scheduler_msg_process_fn_t)(struct scheduler_msg *msg); 61 typedef void (*hdd_suspend_callback)(void); 62 63 /** 64 * struct scheduler_msg: scheduler message structure 65 * @type: message type 66 * @reserved: reserved field 67 * @bodyval: message body val 68 * @bodyptr: message body pointer based on the type either a bodyptr pointer 69 * into memory or bodyval as a 32 bit data is used. bodyptr is always a 70 * freeable pointer, one should always make sure that bodyptr is always 71 * freeable. 72 * Messages should use either bodyptr or bodyval; not both !!! 73 * @callback: callback to be called by scheduler thread once message is posted 74 * and scheduler thread has started processing the message. 75 * @flush_callback: flush callback which will be invoked during driver unload 76 * such that component can release the ref count of common global objects 77 * like PSOC, PDEV, VDEV and PEER. A component needs to populate flush 78 * callback in message body pointer for those messages which have taken ref 79 * count for above mentioned common objects. 80 * @node: list node for queue membership 81 * @queue_id: Id of the queue the message was added to 82 * @queue_depth: depth of the queue when the message was queued 83 * @queued_at_us: timestamp when the message was queued in microseconds 84 */ 85 struct scheduler_msg { 86 uint16_t type; 87 uint16_t reserved; 88 uint32_t bodyval; 89 void *bodyptr; 90 scheduler_msg_process_fn_t callback; 91 scheduler_msg_process_fn_t flush_callback; 92 qdf_list_node_t node; 93 #ifdef WLAN_SCHED_HISTORY_SIZE 94 QDF_MODULE_ID queue_id; 95 uint32_t queue_depth; 96 uint64_t queued_at_us; 97 #endif /* WLAN_SCHED_HISTORY_SIZE */ 98 }; 99 100 struct sched_qdf_mc_timer_cb_wrapper; 101 102 /** 103 * scheduler_qdf_mc_timer_init() - initialize and fill callback and data 104 * @timer_callback: callback to timer 105 * @data: data pointer 106 * 107 * Return: return pointer to struct sched_qdf_mc_timer_cb_wrapper 108 */ 109 struct sched_qdf_mc_timer_cb_wrapper *scheduler_qdf_mc_timer_init( 110 qdf_mc_timer_callback_t timer_callback, 111 void *data); 112 113 /** 114 * scheduler_qdf_mc_timer_callback_t_wrapper() - wrapper for mc timer callbacks 115 * @wrapper_ptr: wrapper ptr 116 * 117 * Return: return void ptr 118 */ 119 void *scheduler_qdf_mc_timer_deinit_return_data_ptr( 120 struct sched_qdf_mc_timer_cb_wrapper *wrapper_ptr); 121 122 /** 123 * scheduler_qdf_mc_timer_callback_t_wrapper() - wrapper for mc timer callbacks 124 * @msg: message pointer 125 * 126 * Return: None 127 */ 128 QDF_STATUS scheduler_qdf_mc_timer_callback_t_wrapper(struct scheduler_msg *msg); 129 130 /** 131 * sched_history_print() - print scheduler history 132 * 133 * This API prints the scheduler history. 134 * 135 * Return: None 136 */ 137 void sched_history_print(void); 138 139 /** 140 * scheduler_init() - initialize control path scheduler 141 * 142 * This API initializes control path scheduler. 143 * 144 * Return: QDF status 145 */ 146 QDF_STATUS scheduler_init(void); 147 148 /** 149 * scheduler_deinit() - de-initialize control path scheduler 150 * 151 * This API de-initializes control path scheduler. 152 * 153 * Return: QDF status 154 */ 155 QDF_STATUS scheduler_deinit(void); 156 157 /** 158 * scheduler_enable() - start the scheduler module 159 * 160 * Ready the scheduler module to service requests, and start the scheduler's 161 * message processing thread. Must only be called after scheduler_init(). 162 * 163 * Return: QDF_STATUS 164 */ 165 QDF_STATUS scheduler_enable(void); 166 167 /** 168 * scheduler_disable() - stop the scheduler module 169 * 170 * Stop the scheduler module from servicing requests, and terminate the 171 * scheduler's message processing thread. Must be called before 172 * scheduler_deinit(). 173 * 174 * Return: QDF_STATUS 175 */ 176 QDF_STATUS scheduler_disable(void); 177 178 /** 179 * scheduler_register_module() - register input module/queue id 180 * @qid: queue id to get registered 181 * @callback: queue message to be called when a message is posted 182 * 183 * Return: QDF status 184 */ 185 QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid, 186 scheduler_msg_process_fn_t callback); 187 188 /** 189 * scheduler_deregister_module() - deregister input module/queue id 190 * @qid: queue id to get deregistered 191 * 192 * Return: QDF status 193 */ 194 QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid); 195 196 /** 197 * scheduler_post_msg_by_priority() - post messages by priority 198 * @qid: queue id to which the message has to be posted. 199 * @msg: message pointer 200 * @is_high_priority: set to true for high priority message else false 201 * 202 * Return: QDF status 203 */ 204 QDF_STATUS scheduler_post_msg_by_priority(uint32_t qid, 205 struct scheduler_msg *msg, 206 bool is_high_priority); 207 208 /** 209 * scheduler_post_msg() - post normal messages(no priority) 210 * @qid: queue id to which the message has to be posted. 211 * @msg: message pointer 212 * 213 * Return: QDF status 214 */ 215 static inline QDF_STATUS scheduler_post_msg(uint32_t qid, 216 struct scheduler_msg *msg) 217 { 218 return scheduler_post_msg_by_priority(qid, msg, false); 219 } 220 221 /** 222 * scheduler_post_message() - post normal messages(no priority) 223 * @src_id: Source module of the message 224 * @dest_id: Destination module of the message 225 * @que_id: Queue to which the message has to posted. 226 * @msg: message pointer 227 * 228 * This function will mask the src_id, and destination id to qid of 229 * scheduler_post_msg 230 * Return: QDF status 231 */ 232 QDF_STATUS scheduler_post_message_debug(QDF_MODULE_ID src_id, 233 QDF_MODULE_ID dest_id, 234 QDF_MODULE_ID que_id, 235 struct scheduler_msg *msg, 236 int line, 237 const char *func); 238 239 #define scheduler_post_message(src_id, dest_id, que_id, msg) \ 240 scheduler_post_message_debug(src_id, dest_id, que_id, msg, \ 241 __LINE__, __func__) 242 243 /** 244 * scheduler_resume() - resume scheduler thread 245 * 246 * Complete scheduler thread resume wait event such that scheduler 247 * thread can wake up and process message queues 248 * 249 * Return: none 250 */ 251 void scheduler_resume(void); 252 253 /** 254 * scheduler_set_timeout() - set scheduler timeout for msg processing 255 * 256 * Configure the timeout for triggering the scheduler watchdog timer 257 * in milliseconds 258 * 259 * Return: none 260 */ 261 void scheduler_set_watchdog_timeout(uint32_t timeout); 262 263 /** 264 * scheduler_register_hdd_suspend_callback() - suspend callback to hdd 265 * @callback: hdd callback to be called when controllred thread is suspended 266 * 267 * Return: none 268 */ 269 void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback); 270 271 /** 272 * scheduler_wake_up_controller_thread() - wake up controller thread 273 * 274 * Wake up controller thread to process a critical message. 275 * 276 * Return: none 277 */ 278 void scheduler_wake_up_controller_thread(void); 279 280 /** 281 * scheduler_set_event_mask() - set given event mask 282 * @event_mask: event mask to set 283 * 284 * Set given event mask such that controller scheduler thread can do 285 * specified work after wake up. 286 * 287 * Return: none 288 */ 289 void scheduler_set_event_mask(uint32_t event_mask); 290 291 /** 292 * scheduler_clear_event_mask() - clear given event mask 293 * @event_mask: event mask to set 294 * 295 * Return: none 296 */ 297 void scheduler_clear_event_mask(uint32_t event_mask); 298 299 /** 300 * scheduler_target_if_mq_handler() - top level message queue handler for 301 * target_if message queue 302 * @msg: pointer to actual message being handled 303 * 304 * Return: none 305 */ 306 QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg); 307 308 /** 309 * scheduler_os_if_mq_handler() - top level message queue handler for 310 * os_if message queue 311 * @msg: pointer to actual message being handled 312 * 313 * Return: none 314 */ 315 QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg); 316 317 /** 318 * scheduler_timer_q_mq_handler() - top level message queue handler for 319 * timer queue 320 * @msg: pointer to actual message being handled 321 * 322 * Return: none 323 */ 324 QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg); 325 326 /** 327 * scheduler_mlme_mq_handler() - top level message queue handler for 328 * mlme queue 329 * @msg: pointer to actual message being handled 330 * 331 * Return: QDF status 332 */ 333 QDF_STATUS scheduler_mlme_mq_handler(struct scheduler_msg *msg); 334 335 /** 336 * scheduler_scan_mq_handler() - top level message queue handler for 337 * scan queue 338 * @msg: pointer to actual message being handled 339 * 340 * Return: QDF status 341 */ 342 QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg); 343 344 /** 345 * scheduler_register_wma_legacy_handler() - register legacy wma handler 346 * @callback: legacy wma handler to be called for WMA messages 347 * 348 * Return: QDF status 349 */ 350 QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t 351 callback); 352 353 /** 354 * scheduler_register_sys_legacy_handler() - register legacy sys handler 355 * @callback: legacy sys handler to be called for sys messages 356 * 357 * Return: QDF status 358 */ 359 QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t 360 callback); 361 /** 362 * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler 363 * 364 * Return: QDF status 365 */ 366 QDF_STATUS scheduler_deregister_sys_legacy_handler(void); 367 368 /** 369 * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler 370 * 371 * Return: QDF status 372 */ 373 QDF_STATUS scheduler_deregister_wma_legacy_handler(void); 374 375 /** 376 * scheduler_mc_timer_callback() - timer callback, gets called at time out 377 * @timer: holds the mc timer object. 378 * 379 * Return: None 380 */ 381 void scheduler_mc_timer_callback(qdf_mc_timer_t *timer); 382 383 /** 384 * scheduler_get_queue_size() - Get the current size of the scheduler queue 385 * @qid: Queue ID for which the size is requested 386 * @size: Pointer to size where the size would be returned to the caller 387 * 388 * This API finds the size of the scheduler queue for the given Queue ID 389 * 390 * Return: QDF Status 391 */ 392 QDF_STATUS scheduler_get_queue_size(QDF_MODULE_ID qid, uint32_t *size); 393 #endif 394