scheduler_core.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (c) 2014-2016 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 <scheduler_api.h>
  30. #include <qdf_list.h>
  31. #define SCHEDULER_CORE_MAX_MESSAGES 8000
  32. #define SCHEDULER_NUMBER_OF_MSG_QUEUE 5
  33. /**
  34. * struct scheduler_mq_type - scheduler message queue
  35. * @mq_lock: message queue lock
  36. * @mq_list: message queue list
  37. * @qid: queue id
  38. */
  39. struct scheduler_mq_type {
  40. qdf_spinlock_t mq_lock;
  41. qdf_list_t mq_list;
  42. QDF_MODULE_ID qid;
  43. };
  44. /**
  45. * struct scheduler_msg_wrapper - scheduler message wrapper
  46. * @msg_node: message node
  47. * @msg_buf: message buffer pointer
  48. */
  49. struct scheduler_msg_wrapper {
  50. qdf_list_node_t msg_node;
  51. struct scheduler_msg *msg_buf;
  52. };
  53. /**
  54. * struct scheduler_mq_ctx - scheduler message queue context
  55. * @msg_buffers: array of message buffers
  56. * @msg_wrappers: array of message wrappers
  57. * @free_msg_q: free message queue
  58. * @sch_msg_q: scheduler message queue
  59. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  60. * @scheduler_msg_process_fn: array of message queue handler function pointers
  61. */
  62. struct scheduler_mq_ctx {
  63. struct scheduler_msg msg_buffers[SCHEDULER_CORE_MAX_MESSAGES];
  64. struct scheduler_msg_wrapper msg_wrappers[SCHEDULER_CORE_MAX_MESSAGES];
  65. struct scheduler_mq_type free_msg_q;
  66. struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE];
  67. uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX];
  68. QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE])
  69. (struct scheduler_msg *msg);
  70. };
  71. /**
  72. * struct scheduler_ctx - scheduler context
  73. * @queue_ctx: message queue context
  74. * @sch_start_event: scheduler thread start wait event
  75. * @sch_thread: scheduler thread
  76. * @sch_shutdown: scheduler thread shutdown wait event
  77. * @sch_wait_queue: scheduler wait queue
  78. * @sch_event_flag: scheduler events flag
  79. * @resume_sch_event: scheduler resume wait event
  80. * @sch_thread_lock: scheduler thread lock
  81. * @sch_last_qidx: scheduler last qidx allocation
  82. * @hdd_callback: os if suspend callback
  83. * @legacy_wma_handler: legacy wma message handler
  84. * @legacy_sys_handler: legacy sys message handler
  85. */
  86. struct scheduler_ctx {
  87. struct scheduler_mq_ctx queue_ctx;
  88. qdf_event_t sch_start_event;
  89. qdf_thread_t *sch_thread;
  90. qdf_event_t sch_shutdown;
  91. qdf_wait_queue_head_t sch_wait_queue;
  92. unsigned long sch_event_flag;
  93. qdf_event_t resume_sch_event;
  94. qdf_spinlock_t sch_thread_lock;
  95. uint8_t sch_last_qidx;
  96. hdd_suspend_callback hdd_callback;
  97. scheduler_msg_process_fn_t legacy_wma_handler;
  98. scheduler_msg_process_fn_t legacy_sys_handler;
  99. };
  100. /**
  101. * scheduler_get_context() - to get scheduler context
  102. *
  103. * This routine is used retrieve scheduler context
  104. *
  105. * Return: Pointer to scheduler context
  106. */
  107. struct scheduler_ctx *scheduler_get_context(void);
  108. /**
  109. * scheduler_thread() - spawned thread will execute this routine
  110. * @arg: pointer to scheduler context
  111. *
  112. * Newly created thread will use this routine to perform its duty
  113. *
  114. * Return: none
  115. */
  116. int scheduler_thread(void *arg);
  117. /**
  118. * scheduler_cleanup_queues() - to clean up the given module's queue
  119. * @sch_ctx: pointer to scheduler context
  120. * @idx: index of the queue which needs to be cleanup.
  121. *
  122. * This routine is used to clean the module's queue provided by
  123. * user through idx field
  124. *
  125. * Return: none
  126. */
  127. void scheduler_cleanup_queues(struct scheduler_ctx *sch_ctx, int idx);
  128. /**
  129. * scheduler_create_ctx() - to create scheduler context
  130. *
  131. * This routine is used to create scheduler context
  132. *
  133. * Return: QDF_STATUS based on success or failure
  134. */
  135. QDF_STATUS scheduler_create_ctx(void);
  136. /**
  137. * scheduler_destroy_ctx() - to destroy scheduler context
  138. *
  139. * This routine is used to destroy scheduler context
  140. *
  141. * Return: QDF_STATUS based on success or failure
  142. */
  143. QDF_STATUS scheduler_destroy_ctx(void);
  144. /**
  145. * scheduler_mq_init() - initialize scheduler message queue
  146. * @msg_q: Pointer to the message queue
  147. *
  148. * This function initializes the Message queue.
  149. *
  150. * Return: qdf status
  151. */
  152. QDF_STATUS scheduler_mq_init(struct scheduler_mq_type *msg_q);
  153. /**
  154. * scheduler_mq_deinit() - de-initialize scheduler message queue
  155. * @msg_q: Pointer to the message queue
  156. *
  157. * This function de-initializes scheduler message queue
  158. *
  159. * Return: none
  160. */
  161. void scheduler_mq_deinit(struct scheduler_mq_type *msg_q);
  162. /**
  163. * scheduler_mq_put() - put message in the back of queue
  164. * @msg_q: Pointer to the message queue
  165. * @msg_wrapper: pointer to message wrapper
  166. *
  167. * This function is used to put message in back of provided message
  168. * queue
  169. *
  170. * Return: none
  171. */
  172. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  173. struct scheduler_msg_wrapper *msg_wrapper);
  174. /**
  175. * scheduler_mq_put_front() - put message in the front of queue
  176. * @msg_q: Pointer to the message queue
  177. * @msg_wrapper: pointer to message wrapper
  178. *
  179. * This function is used to put message in front of provided message
  180. * queue
  181. *
  182. * Return: none
  183. */
  184. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  185. struct scheduler_msg_wrapper *msg_wrapper);
  186. /**
  187. * scheduler_mq_get() - to get message from message queue
  188. * @msg_q: Pointer to the message queue
  189. *
  190. * This function is used to get message from given message queue
  191. *
  192. * Return: none
  193. */
  194. struct scheduler_msg_wrapper *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  195. /**
  196. * scheduler_is_mq_empty() - to check if message queue is empty
  197. * @msg_q: Pointer to the message queue
  198. *
  199. * This function is used to check if message queue is empty
  200. *
  201. * Return: true or false
  202. */
  203. bool scheduler_is_mq_empty(struct scheduler_mq_type *msg_q);
  204. /**
  205. * scheduler_queues_init() - to initialize all the modules' queues
  206. * @sched_ctx: pointer to scheduler context
  207. *
  208. * This function is used to initialize the queues for all the modules
  209. *
  210. * Return: QDF_STATUS based on success of failure
  211. */
  212. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  213. /**
  214. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  215. * @sched_ctx: pointer to scheduler context
  216. *
  217. * This function is used to de-initialize the queues for all the modules
  218. *
  219. * Return: QDF_STATUS based on success of failure
  220. */
  221. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx);
  222. #endif