scheduler_core.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #if !defined(__SCHEDULER_CORE_H)
  27. #define __SCHEDULER_CORE_H
  28. #include <qdf_threads.h>
  29. #include <qdf_timer.h>
  30. #include <scheduler_api.h>
  31. #include <qdf_list.h>
  32. #ifdef CONFIG_MCL
  33. #define SCHEDULER_CORE_MAX_MESSAGES 8000
  34. #else
  35. #define SCHEDULER_CORE_MAX_MESSAGES 2000
  36. #endif
  37. #define SCHEDULER_NUMBER_OF_MSG_QUEUE 5
  38. #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3)
  39. #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */
  40. #define sched_log(level, args...) \
  41. QDF_TRACE(QDF_MODULE_ID_SCHEDULER, level, ## args)
  42. #define sched_logfl(level, format, args...) \
  43. sched_log(level, FL(format), ## args)
  44. #define sched_fatal(format, args...) \
  45. sched_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args)
  46. #define sched_err(format, args...) \
  47. sched_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args)
  48. #define sched_warn(format, args...) \
  49. sched_logfl(QDF_TRACE_LEVEL_WARN, format, ## args)
  50. #define sched_info(format, args...) \
  51. sched_logfl(QDF_TRACE_LEVEL_INFO, format, ## args)
  52. #define sched_debug(format, args...) \
  53. sched_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args)
  54. #define sched_enter() sched_debug("Enter")
  55. #define sched_exit() sched_debug("Exit")
  56. /**
  57. * struct scheduler_mq_type - scheduler message queue
  58. * @mq_lock: message queue lock
  59. * @mq_list: message queue list
  60. * @qid: queue id
  61. */
  62. struct scheduler_mq_type {
  63. qdf_spinlock_t mq_lock;
  64. qdf_list_t mq_list;
  65. QDF_MODULE_ID qid;
  66. };
  67. /**
  68. * struct scheduler_msg_wrapper - scheduler message wrapper
  69. * @msg_node: message node
  70. * @msg_buf: message buffer pointer
  71. */
  72. struct scheduler_msg_wrapper {
  73. qdf_list_node_t msg_node;
  74. struct scheduler_msg *msg_buf;
  75. };
  76. /**
  77. * struct scheduler_mq_ctx - scheduler message queue context
  78. * @msg_buffers: array of message buffers
  79. * @msg_wrappers: array of message wrappers
  80. * @free_msg_q: free message queue
  81. * @sch_msg_q: scheduler message queue
  82. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  83. * @scheduler_msg_process_fn: array of message queue handler function pointers
  84. */
  85. struct scheduler_mq_ctx {
  86. struct scheduler_msg msg_buffers[SCHEDULER_CORE_MAX_MESSAGES];
  87. struct scheduler_msg_wrapper msg_wrappers[SCHEDULER_CORE_MAX_MESSAGES];
  88. struct scheduler_mq_type free_msg_q;
  89. struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE];
  90. uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX];
  91. QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE])
  92. (struct scheduler_msg *msg);
  93. };
  94. /**
  95. * struct scheduler_ctx - scheduler context
  96. * @queue_ctx: message queue context
  97. * @sch_start_event: scheduler thread start wait event
  98. * @sch_thread: scheduler thread
  99. * @sch_shutdown: scheduler thread shutdown wait event
  100. * @sch_wait_queue: scheduler wait queue
  101. * @sch_event_flag: scheduler events flag
  102. * @resume_sch_event: scheduler resume wait event
  103. * @sch_thread_lock: scheduler thread lock
  104. * @sch_last_qidx: scheduler last qidx allocation
  105. * @hdd_callback: os if suspend callback
  106. * @legacy_wma_handler: legacy wma message handler
  107. * @legacy_sys_handler: legacy sys message handler
  108. * @watchdog_timer: timer for triggering a scheduler watchdog bite
  109. * @watchdog_msg_type: 'type' of the current msg being processed
  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. hdd_suspend_callback hdd_callback;
  123. scheduler_msg_process_fn_t legacy_wma_handler;
  124. scheduler_msg_process_fn_t legacy_sys_handler;
  125. qdf_timer_t watchdog_timer;
  126. uint16_t watchdog_msg_type;
  127. void *watchdog_callback;
  128. };
  129. /**
  130. * scheduler_get_context() - to get scheduler context
  131. *
  132. * This routine is used retrieve scheduler context
  133. *
  134. * Return: Pointer to scheduler context
  135. */
  136. struct scheduler_ctx *scheduler_get_context(void);
  137. /**
  138. * scheduler_thread() - spawned thread will execute this routine
  139. * @arg: pointer to scheduler context
  140. *
  141. * Newly created thread will use this routine to perform its duty
  142. *
  143. * Return: none
  144. */
  145. int scheduler_thread(void *arg);
  146. /**
  147. * scheduler_cleanup_queues() - to clean up the given module's queue
  148. * @sch_ctx: pointer to scheduler context
  149. * @idx: index of the queue which needs to be cleanup.
  150. *
  151. * This routine is used to clean the module's queue provided by
  152. * user through idx field
  153. *
  154. * Return: none
  155. */
  156. void scheduler_cleanup_queues(struct scheduler_ctx *sch_ctx, int idx);
  157. /**
  158. * scheduler_create_ctx() - to create scheduler context
  159. *
  160. * This routine is used to create scheduler context
  161. *
  162. * Return: QDF_STATUS based on success or failure
  163. */
  164. QDF_STATUS scheduler_create_ctx(void);
  165. /**
  166. * scheduler_destroy_ctx() - to destroy scheduler context
  167. *
  168. * This routine is used to destroy scheduler context
  169. *
  170. * Return: QDF_STATUS based on success or failure
  171. */
  172. QDF_STATUS scheduler_destroy_ctx(void);
  173. /**
  174. * scheduler_mq_init() - initialize scheduler message queue
  175. * @msg_q: Pointer to the message queue
  176. *
  177. * This function initializes the Message queue.
  178. *
  179. * Return: qdf status
  180. */
  181. QDF_STATUS scheduler_mq_init(struct scheduler_mq_type *msg_q);
  182. /**
  183. * scheduler_mq_deinit() - de-initialize scheduler message queue
  184. * @msg_q: Pointer to the message queue
  185. *
  186. * This function de-initializes scheduler message queue
  187. *
  188. * Return: none
  189. */
  190. void scheduler_mq_deinit(struct scheduler_mq_type *msg_q);
  191. /**
  192. * scheduler_mq_put() - put message in the back of queue
  193. * @msg_q: Pointer to the message queue
  194. * @msg_wrapper: pointer to message wrapper
  195. *
  196. * This function is used to put message in back of provided message
  197. * queue
  198. *
  199. * Return: none
  200. */
  201. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  202. struct scheduler_msg_wrapper *msg_wrapper);
  203. /**
  204. * scheduler_mq_put_front() - put message in the front of queue
  205. * @msg_q: Pointer to the message queue
  206. * @msg_wrapper: pointer to message wrapper
  207. *
  208. * This function is used to put message in front of provided message
  209. * queue
  210. *
  211. * Return: none
  212. */
  213. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  214. struct scheduler_msg_wrapper *msg_wrapper);
  215. /**
  216. * scheduler_mq_get() - to get message from message queue
  217. * @msg_q: Pointer to the message queue
  218. *
  219. * This function is used to get message from given message queue
  220. *
  221. * Return: none
  222. */
  223. struct scheduler_msg_wrapper *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  224. /**
  225. * scheduler_is_mq_empty() - to check if message queue is empty
  226. * @msg_q: Pointer to the message queue
  227. *
  228. * This function is used to check if message queue is empty
  229. *
  230. * Return: true or false
  231. */
  232. bool scheduler_is_mq_empty(struct scheduler_mq_type *msg_q);
  233. /**
  234. * scheduler_queues_init() - to initialize all the modules' queues
  235. * @sched_ctx: pointer to scheduler context
  236. *
  237. * This function is used to initialize the queues for all the modules
  238. *
  239. * Return: QDF_STATUS based on success of failure
  240. */
  241. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  242. /**
  243. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  244. * @sched_ctx: pointer to scheduler context
  245. *
  246. * This function is used to de-initialize the queues for all the modules
  247. *
  248. * Return: QDF_STATUS based on success of failure
  249. */
  250. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx);
  251. #endif