scheduler_core.h 7.1 KB

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