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 */ 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 }; 79 80 typedef QDF_STATUS (*scheduler_msg_process_fn_t) (struct scheduler_msg *msg); 81 typedef void (*hdd_suspend_callback)(void); 82 83 /** 84 * scheduler_init() - initialize control path scheduler 85 * 86 * This API initializes control path scheduler. 87 * 88 * Return: QDF status 89 */ 90 QDF_STATUS scheduler_init(void); 91 92 /** 93 * scheduler_deinit() - de-initialize control path scheduler 94 * 95 * This API de-initializes control path scheduler. 96 * 97 * Return: QDF status 98 */ 99 QDF_STATUS scheduler_deinit(void); 100 101 /** 102 * scheduler_enable() - start the scheduler module 103 * 104 * Ready the scheduler module to service requests, and start the scheduler's 105 * message processing thread. Must only be called after scheduler_init(). 106 * 107 * Return: QDF_STATUS 108 */ 109 QDF_STATUS scheduler_enable(void); 110 111 /** 112 * scheduler_disable() - stop the scheduler module 113 * 114 * Stop the scheduler module from servicing requests, and terminate the 115 * scheduler's message processing thread. Must be called before 116 * scheduler_deinit(). 117 * 118 * Return: QDF_STATUS 119 */ 120 QDF_STATUS scheduler_disable(void); 121 122 /** 123 * scheduler_register_module() - register input module/queue id 124 * @qid: queue id to get registered 125 * @callback: queue message to be called when a message is posted 126 * 127 * Return: QDF status 128 */ 129 QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid, 130 scheduler_msg_process_fn_t callback); 131 132 /** 133 * scheduler_deregister_module() - deregister input module/queue id 134 * @qid: queue id to get deregistered 135 * 136 * Return: QDF status 137 */ 138 QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid); 139 140 /** 141 * scheduler_post_msg_by_priority() - post messages by priority 142 * @qid: queue id to to post message 143 * @msg: message pointer 144 * @is_high_priority: set to true for high priority message else false 145 * 146 * Return: QDF status 147 */ 148 QDF_STATUS scheduler_post_msg_by_priority(QDF_MODULE_ID qid, 149 struct scheduler_msg *msg, bool is_high_priority); 150 151 /** 152 * scheduler_post_msg() - post normal messages(no priority) 153 * @qid: queue id to to post message 154 * @msg: message pointer 155 * 156 * Return: QDF status 157 */ 158 static inline QDF_STATUS scheduler_post_msg(QDF_MODULE_ID qid, 159 struct scheduler_msg *msg) 160 { 161 return scheduler_post_msg_by_priority(qid, msg, false); 162 } 163 164 /** 165 * scheduler_resume() - resume scheduler thread 166 * 167 * Complete scheduler thread resume wait event such that scheduler 168 * thread can wake up and process message queues 169 * 170 * Return: none 171 */ 172 void scheduler_resume(void); 173 174 /** 175 * scheduler_register_hdd_suspend_callback() - suspend callback to hdd 176 * @callback: hdd callback to be called when controllred thread is suspended 177 * 178 * Return: none 179 */ 180 void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback); 181 182 /** 183 * scheduler_wake_up_controller_thread() - wake up controller thread 184 * 185 * Wake up controller thread to process a critical message. 186 * 187 * Return: none 188 */ 189 void scheduler_wake_up_controller_thread(void); 190 191 /** 192 * scheduler_set_event_mask() - set given event mask 193 * @event_mask: event mask to set 194 * 195 * Set given event mask such that controller scheduler thread can do 196 * specified work after wake up. 197 * 198 * Return: none 199 */ 200 void scheduler_set_event_mask(uint32_t event_mask); 201 202 /** 203 * scheduler_clear_event_mask() - clear given event mask 204 * @event_mask: event mask to set 205 * 206 * Return: none 207 */ 208 void scheduler_clear_event_mask(uint32_t event_mask); 209 210 /** 211 * scheduler_target_if_mq_handler() - top level message queue handler for 212 * target_if message queue 213 * @msg: pointer to actual message being handled 214 * 215 * Return: none 216 */ 217 QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg); 218 219 /** 220 * scheduler_os_if_mq_handler() - top level message queue handler for 221 * os_if message queue 222 * @msg: pointer to actual message being handled 223 * 224 * Return: none 225 */ 226 QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg); 227 228 /** 229 * scheduler_timer_q_mq_handler() - top level message queue handler for 230 * timer queue 231 * @msg: pointer to actual message being handled 232 * 233 * Return: none 234 */ 235 QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg); 236 237 /** 238 * scheduler_scan_mq_handler() - top level message queue handler for 239 * scan queue 240 * @msg: pointer to actual message being handled 241 * 242 * Return: QDF status 243 */ 244 QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg); 245 246 /** 247 * scheduler_register_wma_legacy_handler() - register legacy wma handler 248 * @callback: legacy wma handler to be called for WMA messages 249 * 250 * Return: QDF status 251 */ 252 QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t 253 callback); 254 255 /** 256 * scheduler_register_sys_legacy_handler() - register legacy sys handler 257 * @callback: legacy sys handler to be called for sys messages 258 * 259 * Return: QDF status 260 */ 261 QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t 262 callback); 263 /** 264 * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler 265 * 266 * Return: QDF status 267 */ 268 QDF_STATUS scheduler_deregister_sys_legacy_handler(void); 269 270 /** 271 * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler 272 * 273 * Return: QDF status 274 */ 275 QDF_STATUS scheduler_deregister_wma_legacy_handler(void); 276 277 /** 278 * scheduler_mc_timer_callback() - timer callback, gets called at time out 279 * @data: unsigned long, holds the timer object. 280 * 281 * Return: None 282 */ 283 void scheduler_mc_timer_callback(unsigned long data); 284 285 #endif 286