1 /* 2 * Copyright (c) 2014-2021 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_CORE_H) 20 #define __SCHEDULER_CORE_H 21 22 #include <qdf_threads.h> 23 #include <qdf_timer.h> 24 #include <scheduler_api.h> 25 #include <qdf_list.h> 26 27 #ifndef SCHEDULER_CORE_MAX_MESSAGES 28 #define SCHEDULER_CORE_MAX_MESSAGES 4000 29 #endif 30 #ifndef WLAN_SCHED_REDUCTION_LIMIT 31 #define WLAN_SCHED_REDUCTION_LIMIT 32 32 #endif 33 #define SCHEDULER_NUMBER_OF_MSG_QUEUE 6 34 #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3) 35 #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */ 36 37 #ifdef CONFIG_AP_PLATFORM 38 #define SCHED_DEBUG_PANIC(msg) 39 #else 40 #define SCHED_DEBUG_PANIC(msg) QDF_DEBUG_PANIC(msg) 41 #endif 42 43 #define sched_fatal(params...) \ 44 QDF_TRACE_FATAL(QDF_MODULE_ID_SCHEDULER, params) 45 #define sched_err(params...) \ 46 QDF_TRACE_ERROR(QDF_MODULE_ID_SCHEDULER, params) 47 #define sched_warn(params...) \ 48 QDF_TRACE_WARN(QDF_MODULE_ID_SCHEDULER, params) 49 #define sched_info(params...) \ 50 QDF_TRACE_INFO(QDF_MODULE_ID_SCHEDULER, params) 51 #define sched_debug(params...) \ 52 QDF_TRACE_DEBUG(QDF_MODULE_ID_SCHEDULER, params) 53 54 #define sched_nofl_fatal(params...) \ 55 QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 56 #define sched_nofl_err(params...) \ 57 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 58 #define sched_nofl_warn(params...) \ 59 QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 60 #define sched_nofl_info(params...) \ 61 QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 62 #define sched_nofl_debug(params...) \ 63 QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 64 65 #define sched_enter() sched_debug("Enter") 66 #define sched_exit() sched_debug("Exit") 67 68 /** 69 * struct scheduler_mq_type - scheduler message queue 70 * @mq_lock: message queue lock 71 * @mq_list: message queue list 72 * @qid: queue id 73 */ 74 struct scheduler_mq_type { 75 qdf_spinlock_t mq_lock; 76 qdf_list_t mq_list; 77 QDF_MODULE_ID qid; 78 }; 79 80 /** 81 * struct scheduler_mq_ctx - scheduler message queue context 82 * @sch_msg_q: scheduler message queue 83 * @scheduler_msg_qid_to_qidx: message qid to qidx mapping 84 * @scheduler_msg_process_fn: array of message queue handler function pointers 85 */ 86 struct scheduler_mq_ctx { 87 struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE]; 88 uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX]; 89 QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE]) 90 (struct scheduler_msg *msg); 91 }; 92 93 /** 94 * struct scheduler_ctx - scheduler context 95 * @queue_ctx: message queue context 96 * @sch_start_event: scheduler thread start wait event 97 * @sch_thread: scheduler thread 98 * @sch_shutdown: scheduler thread shutdown wait event 99 * @sch_wait_queue: scheduler wait queue 100 * @sch_event_flag: scheduler events flag 101 * @resume_sch_event: scheduler resume wait event 102 * @sch_thread_lock: scheduler thread lock 103 * @sch_last_qidx: scheduler last qidx allocation 104 * @watchdog_msg_type: 'type' of the current msg being processed 105 * @hdd_callback: os if suspend callback 106 * @legacy_wma_handler: legacy wma message handler 107 * @legacy_sys_handler: legacy sys message handler 108 * @timeout: timeout value for scheduler watchdog timer 109 * @watchdog_timer: timer for triggering a scheduler watchdog bite 110 * @watchdog_callback: the callback of the current msg being processed 111 */ 112 struct scheduler_ctx { 113 struct scheduler_mq_ctx queue_ctx; 114 qdf_event_t sch_start_event; 115 qdf_thread_t *sch_thread; 116 qdf_event_t sch_shutdown; 117 qdf_wait_queue_head_t sch_wait_queue; 118 unsigned long sch_event_flag; 119 qdf_event_t resume_sch_event; 120 qdf_spinlock_t sch_thread_lock; 121 uint8_t sch_last_qidx; 122 uint16_t watchdog_msg_type; 123 hdd_suspend_callback hdd_callback; 124 scheduler_msg_process_fn_t legacy_wma_handler; 125 scheduler_msg_process_fn_t legacy_sys_handler; 126 uint32_t timeout; 127 qdf_timer_t watchdog_timer; 128 void *watchdog_callback; 129 }; 130 131 /** 132 * scheduler_core_msg_dup() duplicate the given scheduler message 133 * @msg: the message to duplicated 134 * 135 * Note: Duplicated messages must be freed using scheduler_core_msg_free(). 136 * 137 * Return: pointer to the duplicated message 138 */ 139 struct scheduler_msg *scheduler_core_msg_dup(struct scheduler_msg *msg); 140 141 /** 142 * scheduler_core_msg_free() - free the given scheduler message 143 * @msg: the duplicated message to free 144 * 145 * Return: None 146 */ 147 void scheduler_core_msg_free(struct scheduler_msg *msg); 148 149 /** 150 * scheduler_get_context() - to get scheduler context 151 * 152 * This routine is used retrieve scheduler context 153 * 154 * Return: Pointer to scheduler context 155 */ 156 struct scheduler_ctx *scheduler_get_context(void); 157 158 /** 159 * scheduler_thread() - spawned thread will execute this routine 160 * @arg: pointer to scheduler context 161 * 162 * Newly created thread will use this routine to perform its duty 163 * 164 * Return: none 165 */ 166 int scheduler_thread(void *arg); 167 168 /** 169 * scheduler_create_ctx() - to create scheduler context 170 * 171 * This routine is used to create scheduler context 172 * 173 * Return: QDF_STATUS based on success or failure 174 */ 175 QDF_STATUS scheduler_create_ctx(void); 176 /** 177 * scheduler_destroy_ctx() - to destroy scheduler context 178 * 179 * This routine is used to destroy scheduler context 180 * 181 * Return: QDF_STATUS based on success or failure 182 */ 183 QDF_STATUS scheduler_destroy_ctx(void); 184 185 /** 186 * scheduler_mq_put() - put message in the back of queue 187 * @msg_q: Pointer to the message queue 188 * @msg: the message to enqueue 189 * 190 * This function is used to put message in back of provided message 191 * queue 192 * 193 * Return: none 194 */ 195 void scheduler_mq_put(struct scheduler_mq_type *msg_q, 196 struct scheduler_msg *msg); 197 /** 198 * scheduler_mq_put_front() - put message in the front of queue 199 * @msg_q: Pointer to the message queue 200 * @msg: the message to enqueue 201 * 202 * This function is used to put message in front of provided message 203 * queue 204 * 205 * Return: none 206 */ 207 void scheduler_mq_put_front(struct scheduler_mq_type *msg_q, 208 struct scheduler_msg *msg); 209 /** 210 * scheduler_mq_get() - to get message from message queue 211 * @msg_q: Pointer to the message queue 212 * 213 * This function is used to get message from given message queue 214 * 215 * Return: none 216 */ 217 struct scheduler_msg *scheduler_mq_get(struct scheduler_mq_type *msg_q); 218 219 /** 220 * scheduler_queues_init() - to initialize all the modules' queues 221 * @sched_ctx: pointer to scheduler context 222 * 223 * This function is used to initialize the queues for all the modules 224 * 225 * Return: QDF_STATUS based on success of failure 226 */ 227 QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx); 228 229 /** 230 * scheduler_queues_deinit() - to de-initialize all the modules' queues 231 * @sched_ctx: pointer to scheduler context 232 * 233 * This function is used to de-initialize the queues for all the modules 234 * 235 * Return: QDF_STATUS based on success of failure 236 */ 237 QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx); 238 239 /** 240 * scheduler_queues_flush() - flush all of the scheduler queues 241 * @sch_ctx: pointer to scheduler context 242 * 243 * This routine is used to clean the module's queues 244 * 245 * Return: none 246 */ 247 void scheduler_queues_flush(struct scheduler_ctx *sched_ctx); 248 #endif 249