1cd395495SRajeev Kumar /* 22f4b444fSVivek * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved. 3*70a19e16SJeff Johnson * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. 4cd395495SRajeev Kumar * 5cd395495SRajeev Kumar * Permission to use, copy, modify, and/or distribute this software for 6cd395495SRajeev Kumar * any purpose with or without fee is hereby granted, provided that the 7cd395495SRajeev Kumar * above copyright notice and this permission notice appear in all 8cd395495SRajeev Kumar * copies. 9cd395495SRajeev Kumar * 10cd395495SRajeev Kumar * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11cd395495SRajeev Kumar * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12cd395495SRajeev Kumar * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13cd395495SRajeev Kumar * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14cd395495SRajeev Kumar * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15cd395495SRajeev Kumar * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16cd395495SRajeev Kumar * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17cd395495SRajeev Kumar * PERFORMANCE OF THIS SOFTWARE. 18cd395495SRajeev Kumar */ 19cd395495SRajeev Kumar 20cd395495SRajeev Kumar #if !defined(__SCHEDULER_CORE_H) 21cd395495SRajeev Kumar #define __SCHEDULER_CORE_H 22cd395495SRajeev Kumar 23cd395495SRajeev Kumar #include <qdf_threads.h> 24e226cebdSDustin Brown #include <qdf_timer.h> 25cd395495SRajeev Kumar #include <scheduler_api.h> 26cd395495SRajeev Kumar #include <qdf_list.h> 27cd395495SRajeev Kumar 28dd4dc88bSsheenam monga #ifndef SCHEDULER_CORE_MAX_MESSAGES 29fa47688fSVivek #define SCHEDULER_CORE_MAX_MESSAGES 4000 30dd4dc88bSsheenam monga #endif 31dd4dc88bSsheenam monga #ifndef WLAN_SCHED_REDUCTION_LIMIT 32d78dedc9SVivek #define WLAN_SCHED_REDUCTION_LIMIT 32 33f227fb74SVivek #endif 346ecd284eSVignesh Viswanathan #define SCHEDULER_NUMBER_OF_MSG_QUEUE 6 3573c05a80SRajeev Kumar #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3) 36e226cebdSDustin Brown #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */ 37cd395495SRajeev Kumar 382f4b444fSVivek #ifdef CONFIG_AP_PLATFORM 392f4b444fSVivek #define SCHED_DEBUG_PANIC(msg) 402f4b444fSVivek #else 412f4b444fSVivek #define SCHED_DEBUG_PANIC(msg) QDF_DEBUG_PANIC(msg) 422f4b444fSVivek #endif 432f4b444fSVivek 44a175314cSNirav Shah #define sched_fatal(params...) \ 45a175314cSNirav Shah QDF_TRACE_FATAL(QDF_MODULE_ID_SCHEDULER, params) 46a175314cSNirav Shah #define sched_err(params...) \ 47a175314cSNirav Shah QDF_TRACE_ERROR(QDF_MODULE_ID_SCHEDULER, params) 48a175314cSNirav Shah #define sched_warn(params...) \ 49a175314cSNirav Shah QDF_TRACE_WARN(QDF_MODULE_ID_SCHEDULER, params) 50a175314cSNirav Shah #define sched_info(params...) \ 51a175314cSNirav Shah QDF_TRACE_INFO(QDF_MODULE_ID_SCHEDULER, params) 52a175314cSNirav Shah #define sched_debug(params...) \ 53a175314cSNirav Shah QDF_TRACE_DEBUG(QDF_MODULE_ID_SCHEDULER, params) 54e1d3d092SDustin Brown 551b9674e2SNirav Shah #define sched_nofl_fatal(params...) \ 561b9674e2SNirav Shah QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 571b9674e2SNirav Shah #define sched_nofl_err(params...) \ 581b9674e2SNirav Shah QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 591b9674e2SNirav Shah #define sched_nofl_warn(params...) \ 601b9674e2SNirav Shah QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 611b9674e2SNirav Shah #define sched_nofl_info(params...) \ 621b9674e2SNirav Shah QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 631b9674e2SNirav Shah #define sched_nofl_debug(params...) \ 641b9674e2SNirav Shah QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_SCHEDULER, params) 651b9674e2SNirav Shah 6691abaccbSDustin Brown #define sched_enter() sched_debug("Enter") 6791abaccbSDustin Brown #define sched_exit() sched_debug("Exit") 6891abaccbSDustin Brown 69cd395495SRajeev Kumar /** 70cd395495SRajeev Kumar * struct scheduler_mq_type - scheduler message queue 71cd395495SRajeev Kumar * @mq_lock: message queue lock 72cd395495SRajeev Kumar * @mq_list: message queue list 73cd395495SRajeev Kumar * @qid: queue id 74cd395495SRajeev Kumar */ 75cd395495SRajeev Kumar struct scheduler_mq_type { 76cd395495SRajeev Kumar qdf_spinlock_t mq_lock; 77cd395495SRajeev Kumar qdf_list_t mq_list; 78cd395495SRajeev Kumar QDF_MODULE_ID qid; 79cd395495SRajeev Kumar }; 80cd395495SRajeev Kumar 81cd395495SRajeev Kumar /** 82cd395495SRajeev Kumar * struct scheduler_mq_ctx - scheduler message queue context 83cd395495SRajeev Kumar * @sch_msg_q: scheduler message queue 84cd395495SRajeev Kumar * @scheduler_msg_qid_to_qidx: message qid to qidx mapping 85cd395495SRajeev Kumar * @scheduler_msg_process_fn: array of message queue handler function pointers 86cd395495SRajeev Kumar */ 87cd395495SRajeev Kumar struct scheduler_mq_ctx { 88cd395495SRajeev Kumar struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE]; 89cd395495SRajeev Kumar uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX]; 90cd395495SRajeev Kumar QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE]) 91cd395495SRajeev Kumar (struct scheduler_msg *msg); 92cd395495SRajeev Kumar }; 93cd395495SRajeev Kumar 94cd395495SRajeev Kumar /** 95cd395495SRajeev Kumar * struct scheduler_ctx - scheduler context 96cd395495SRajeev Kumar * @queue_ctx: message queue context 97cd395495SRajeev Kumar * @sch_start_event: scheduler thread start wait event 98cd395495SRajeev Kumar * @sch_thread: scheduler thread 99cd395495SRajeev Kumar * @sch_shutdown: scheduler thread shutdown wait event 100cd395495SRajeev Kumar * @sch_wait_queue: scheduler wait queue 101cd395495SRajeev Kumar * @sch_event_flag: scheduler events flag 102cd395495SRajeev Kumar * @resume_sch_event: scheduler resume wait event 103cd395495SRajeev Kumar * @sch_thread_lock: scheduler thread lock 104cd395495SRajeev Kumar * @sch_last_qidx: scheduler last qidx allocation 105503663c6SNeha Bisht * @watchdog_msg_type: 'type' of the current msg being processed 106cd395495SRajeev Kumar * @hdd_callback: os if suspend callback 107cd395495SRajeev Kumar * @legacy_wma_handler: legacy wma message handler 108cd395495SRajeev Kumar * @legacy_sys_handler: legacy sys message handler 10997f44cd3SVivek * @timeout: timeout value for scheduler watchdog timer 110e226cebdSDustin Brown * @watchdog_timer: timer for triggering a scheduler watchdog bite 111e226cebdSDustin Brown * @watchdog_callback: the callback of the current msg being processed 112cd395495SRajeev Kumar */ 113cd395495SRajeev Kumar struct scheduler_ctx { 114cd395495SRajeev Kumar struct scheduler_mq_ctx queue_ctx; 115cd395495SRajeev Kumar qdf_event_t sch_start_event; 116cd395495SRajeev Kumar qdf_thread_t *sch_thread; 117cd395495SRajeev Kumar qdf_event_t sch_shutdown; 118cd395495SRajeev Kumar qdf_wait_queue_head_t sch_wait_queue; 119cd395495SRajeev Kumar unsigned long sch_event_flag; 120cd395495SRajeev Kumar qdf_event_t resume_sch_event; 121cd395495SRajeev Kumar qdf_spinlock_t sch_thread_lock; 122cd395495SRajeev Kumar uint8_t sch_last_qidx; 123503663c6SNeha Bisht uint16_t watchdog_msg_type; 124cd395495SRajeev Kumar hdd_suspend_callback hdd_callback; 125cd395495SRajeev Kumar scheduler_msg_process_fn_t legacy_wma_handler; 126cd395495SRajeev Kumar scheduler_msg_process_fn_t legacy_sys_handler; 12797f44cd3SVivek uint32_t timeout; 128e226cebdSDustin Brown qdf_timer_t watchdog_timer; 129e226cebdSDustin Brown void *watchdog_callback; 130cd395495SRajeev Kumar }; 131cd395495SRajeev Kumar 132c7ee85c4SDustin Brown /** 133*70a19e16SJeff Johnson * scheduler_core_msg_dup() - duplicate the given scheduler message 134c7ee85c4SDustin Brown * @msg: the message to duplicated 135c7ee85c4SDustin Brown * 136c7ee85c4SDustin Brown * Note: Duplicated messages must be freed using scheduler_core_msg_free(). 137c7ee85c4SDustin Brown * 138c7ee85c4SDustin Brown * Return: pointer to the duplicated message 139c7ee85c4SDustin Brown */ 140c7ee85c4SDustin Brown struct scheduler_msg *scheduler_core_msg_dup(struct scheduler_msg *msg); 141c7ee85c4SDustin Brown 142c7ee85c4SDustin Brown /** 143c7ee85c4SDustin Brown * scheduler_core_msg_free() - free the given scheduler message 144c7ee85c4SDustin Brown * @msg: the duplicated message to free 145c7ee85c4SDustin Brown * 146c7ee85c4SDustin Brown * Return: None 147c7ee85c4SDustin Brown */ 148c7ee85c4SDustin Brown void scheduler_core_msg_free(struct scheduler_msg *msg); 149cd395495SRajeev Kumar 150cd395495SRajeev Kumar /** 151cd395495SRajeev Kumar * scheduler_get_context() - to get scheduler context 152cd395495SRajeev Kumar * 153cd395495SRajeev Kumar * This routine is used retrieve scheduler context 154cd395495SRajeev Kumar * 155cd395495SRajeev Kumar * Return: Pointer to scheduler context 156cd395495SRajeev Kumar */ 157cd395495SRajeev Kumar struct scheduler_ctx *scheduler_get_context(void); 158c7ee85c4SDustin Brown 159cd395495SRajeev Kumar /** 160cd395495SRajeev Kumar * scheduler_thread() - spawned thread will execute this routine 161cd395495SRajeev Kumar * @arg: pointer to scheduler context 162cd395495SRajeev Kumar * 163cd395495SRajeev Kumar * Newly created thread will use this routine to perform its duty 164cd395495SRajeev Kumar * 165cd395495SRajeev Kumar * Return: none 166cd395495SRajeev Kumar */ 167cd395495SRajeev Kumar int scheduler_thread(void *arg); 168cd395495SRajeev Kumar 169cd395495SRajeev Kumar /** 170cd395495SRajeev Kumar * scheduler_create_ctx() - to create scheduler context 171cd395495SRajeev Kumar * 172cd395495SRajeev Kumar * This routine is used to create scheduler context 173cd395495SRajeev Kumar * 174cd395495SRajeev Kumar * Return: QDF_STATUS based on success or failure 175cd395495SRajeev Kumar */ 176cd395495SRajeev Kumar QDF_STATUS scheduler_create_ctx(void); 177cd395495SRajeev Kumar /** 178cd395495SRajeev Kumar * scheduler_destroy_ctx() - to destroy scheduler context 179cd395495SRajeev Kumar * 180cd395495SRajeev Kumar * This routine is used to destroy scheduler context 181cd395495SRajeev Kumar * 182cd395495SRajeev Kumar * Return: QDF_STATUS based on success or failure 183cd395495SRajeev Kumar */ 184cd395495SRajeev Kumar QDF_STATUS scheduler_destroy_ctx(void); 185c7ee85c4SDustin Brown 186cd395495SRajeev Kumar /** 187cd395495SRajeev Kumar * scheduler_mq_put() - put message in the back of queue 188cd395495SRajeev Kumar * @msg_q: Pointer to the message queue 189c7ee85c4SDustin Brown * @msg: the message to enqueue 190cd395495SRajeev Kumar * 191cd395495SRajeev Kumar * This function is used to put message in back of provided message 192cd395495SRajeev Kumar * queue 193cd395495SRajeev Kumar * 194cd395495SRajeev Kumar * Return: none 195cd395495SRajeev Kumar */ 196cd395495SRajeev Kumar void scheduler_mq_put(struct scheduler_mq_type *msg_q, 197c7ee85c4SDustin Brown struct scheduler_msg *msg); 198cd395495SRajeev Kumar /** 199cd395495SRajeev Kumar * scheduler_mq_put_front() - put message in the front of queue 200cd395495SRajeev Kumar * @msg_q: Pointer to the message queue 201c7ee85c4SDustin Brown * @msg: the message to enqueue 202cd395495SRajeev Kumar * 203cd395495SRajeev Kumar * This function is used to put message in front of provided message 204cd395495SRajeev Kumar * queue 205cd395495SRajeev Kumar * 206cd395495SRajeev Kumar * Return: none 207cd395495SRajeev Kumar */ 208cd395495SRajeev Kumar void scheduler_mq_put_front(struct scheduler_mq_type *msg_q, 209c7ee85c4SDustin Brown struct scheduler_msg *msg); 210cd395495SRajeev Kumar /** 211cd395495SRajeev Kumar * scheduler_mq_get() - to get message from message queue 212cd395495SRajeev Kumar * @msg_q: Pointer to the message queue 213cd395495SRajeev Kumar * 214cd395495SRajeev Kumar * This function is used to get message from given message queue 215cd395495SRajeev Kumar * 216cd395495SRajeev Kumar * Return: none 217cd395495SRajeev Kumar */ 218c7ee85c4SDustin Brown struct scheduler_msg *scheduler_mq_get(struct scheduler_mq_type *msg_q); 219c7ee85c4SDustin Brown 220cd395495SRajeev Kumar /** 221cd395495SRajeev Kumar * scheduler_queues_init() - to initialize all the modules' queues 222cd395495SRajeev Kumar * @sched_ctx: pointer to scheduler context 223cd395495SRajeev Kumar * 224cd395495SRajeev Kumar * This function is used to initialize the queues for all the modules 225cd395495SRajeev Kumar * 226cd395495SRajeev Kumar * Return: QDF_STATUS based on success of failure 227cd395495SRajeev Kumar */ 228cd395495SRajeev Kumar QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx); 229c7ee85c4SDustin Brown 230cd395495SRajeev Kumar /** 231cd395495SRajeev Kumar * scheduler_queues_deinit() - to de-initialize all the modules' queues 232cd395495SRajeev Kumar * @sched_ctx: pointer to scheduler context 233cd395495SRajeev Kumar * 234cd395495SRajeev Kumar * This function is used to de-initialize the queues for all the modules 235cd395495SRajeev Kumar * 236cd395495SRajeev Kumar * Return: QDF_STATUS based on success of failure 237cd395495SRajeev Kumar */ 238*70a19e16SJeff Johnson QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *sched_ctx); 239c7ee85c4SDustin Brown 240c7ee85c4SDustin Brown /** 241c7ee85c4SDustin Brown * scheduler_queues_flush() - flush all of the scheduler queues 242*70a19e16SJeff Johnson * @sched_ctx: pointer to scheduler context 243c7ee85c4SDustin Brown * 244c7ee85c4SDustin Brown * This routine is used to clean the module's queues 245c7ee85c4SDustin Brown * 246c7ee85c4SDustin Brown * Return: none 247c7ee85c4SDustin Brown */ 248c7ee85c4SDustin Brown void scheduler_queues_flush(struct scheduler_ctx *sched_ctx); 249cd395495SRajeev Kumar #endif 250