scheduler_api.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. * Copyright (c) 2014-2020 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. #if !defined(__SCHEDULER_API_H)
  19. #define __SCHEDULER_API_H
  20. #include <qdf_event.h>
  21. #include <qdf_types.h>
  22. #include <qdf_lock.h>
  23. #include <qdf_mc_timer.h>
  24. #include <qdf_status.h>
  25. /* Controller thread various event masks
  26. * MC_POST_EVENT_MASK: wake up thread after posting message
  27. * MC_SUSPEND_EVENT_MASK: signal thread to suspend during kernel pm suspend
  28. * MC_SHUTDOWN_EVENT_MASK: signal thread to shutdown and exit during unload
  29. */
  30. #define MC_POST_EVENT_MASK 0x001
  31. #define MC_SUSPEND_EVENT_MASK 0x002
  32. #define MC_SHUTDOWN_EVENT_MASK 0x010
  33. /*
  34. * Cookie for timer messages. Note that anyone posting a timer message
  35. * has to write the COOKIE in the reserved field of the message. The
  36. * timer queue handler relies on this COOKIE
  37. */
  38. #define SYS_MSG_COOKIE 0xFACE
  39. #define scheduler_get_src_id(qid) (((qid) >> 20) & 0x3FF)
  40. #define scheduler_get_dest_id(qid) (((qid) >> 10) & 0x3FF)
  41. #define scheduler_get_que_id(qid) ((qid) & 0x3FF)
  42. #define scheduler_get_qid(src, dest, que_id) ((que_id) | ((dest) << 10) |\
  43. ((src) << 20))
  44. typedef enum {
  45. SYS_MSG_ID_MC_TIMER,
  46. SYS_MSG_ID_FTM_RSP,
  47. SYS_MSG_ID_QVIT,
  48. SYS_MSG_ID_DATA_STALL_MSG,
  49. SYS_MSG_ID_UMAC_STOP,
  50. } SYS_MSG_ID;
  51. struct scheduler_msg;
  52. typedef QDF_STATUS (*scheduler_msg_process_fn_t)(struct scheduler_msg *msg);
  53. typedef void (*hdd_suspend_callback)(void);
  54. /**
  55. * struct scheduler_msg: scheduler message structure
  56. * @type: message type
  57. * @reserved: reserved field
  58. * @bodyval: message body val
  59. * @bodyptr: message body pointer based on the type either a bodyptr pointer
  60. * into memory or bodyval as a 32 bit data is used. bodyptr is always a
  61. * freeable pointer, one should always make sure that bodyptr is always
  62. * freeable.
  63. * Messages should use either bodyptr or bodyval; not both !!!
  64. * @callback: callback to be called by scheduler thread once message is posted
  65. * and scheduler thread has started processing the message.
  66. * @flush_callback: flush callback which will be invoked during driver unload
  67. * such that component can release the ref count of common global objects
  68. * like PSOC, PDEV, VDEV and PEER. A component needs to populate flush
  69. * callback in message body pointer for those messages which have taken ref
  70. * count for above mentioned common objects.
  71. * @node: list node for queue membership
  72. * @queue_id: Id of the queue the message was added to
  73. * @queue_depth: depth of the queue when the message was queued
  74. * @queued_at_us: timestamp when the message was queued in microseconds
  75. */
  76. struct scheduler_msg {
  77. uint16_t type;
  78. uint16_t reserved;
  79. uint32_t bodyval;
  80. void *bodyptr;
  81. scheduler_msg_process_fn_t callback;
  82. scheduler_msg_process_fn_t flush_callback;
  83. qdf_list_node_t node;
  84. #ifdef WLAN_SCHED_HISTORY_SIZE
  85. QDF_MODULE_ID queue_id;
  86. uint32_t queue_depth;
  87. uint64_t queued_at_us;
  88. #endif /* WLAN_SCHED_HISTORY_SIZE */
  89. };
  90. /**
  91. * sched_history_print() - print scheduler history
  92. *
  93. * This API prints the scheduler history.
  94. *
  95. * Return: None
  96. */
  97. void sched_history_print(void);
  98. /**
  99. * scheduler_init() - initialize control path scheduler
  100. *
  101. * This API initializes control path scheduler.
  102. *
  103. * Return: QDF status
  104. */
  105. QDF_STATUS scheduler_init(void);
  106. /**
  107. * scheduler_deinit() - de-initialize control path scheduler
  108. *
  109. * This API de-initializes control path scheduler.
  110. *
  111. * Return: QDF status
  112. */
  113. QDF_STATUS scheduler_deinit(void);
  114. /**
  115. * scheduler_enable() - start the scheduler module
  116. *
  117. * Ready the scheduler module to service requests, and start the scheduler's
  118. * message processing thread. Must only be called after scheduler_init().
  119. *
  120. * Return: QDF_STATUS
  121. */
  122. QDF_STATUS scheduler_enable(void);
  123. /**
  124. * scheduler_disable() - stop the scheduler module
  125. *
  126. * Stop the scheduler module from servicing requests, and terminate the
  127. * scheduler's message processing thread. Must be called before
  128. * scheduler_deinit().
  129. *
  130. * Return: QDF_STATUS
  131. */
  132. QDF_STATUS scheduler_disable(void);
  133. /**
  134. * scheduler_register_module() - register input module/queue id
  135. * @qid: queue id to get registered
  136. * @callback: queue message to be called when a message is posted
  137. *
  138. * Return: QDF status
  139. */
  140. QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid,
  141. scheduler_msg_process_fn_t callback);
  142. /**
  143. * scheduler_deregister_module() - deregister input module/queue id
  144. * @qid: queue id to get deregistered
  145. *
  146. * Return: QDF status
  147. */
  148. QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid);
  149. /**
  150. * scheduler_post_msg_by_priority() - post messages by priority
  151. * @qid: queue id to which the message has to be posted.
  152. * @msg: message pointer
  153. * @is_high_priority: set to true for high priority message else false
  154. *
  155. * Return: QDF status
  156. */
  157. QDF_STATUS scheduler_post_msg_by_priority(uint32_t qid,
  158. struct scheduler_msg *msg,
  159. bool is_high_priority);
  160. /**
  161. * scheduler_post_msg() - post normal messages(no priority)
  162. * @qid: queue id to which the message has to be posted.
  163. * @msg: message pointer
  164. *
  165. * Return: QDF status
  166. */
  167. static inline QDF_STATUS scheduler_post_msg(uint32_t qid,
  168. struct scheduler_msg *msg)
  169. {
  170. return scheduler_post_msg_by_priority(qid, msg, false);
  171. }
  172. /**
  173. * scheduler_post_message() - post normal messages(no priority)
  174. * @src_id: Source module of the message
  175. * @dest_id: Destination module of the message
  176. * @que_id: Queue to which the message has to posted.
  177. * @msg: message pointer
  178. *
  179. * This function will mask the src_id, and destination id to qid of
  180. * scheduler_post_msg
  181. * Return: QDF status
  182. */
  183. QDF_STATUS scheduler_post_message_debug(QDF_MODULE_ID src_id,
  184. QDF_MODULE_ID dest_id,
  185. QDF_MODULE_ID que_id,
  186. struct scheduler_msg *msg,
  187. int line,
  188. const char *func);
  189. #define scheduler_post_message(src_id, dest_id, que_id, msg) \
  190. scheduler_post_message_debug(src_id, dest_id, que_id, msg, \
  191. __LINE__, __func__)
  192. /**
  193. * scheduler_resume() - resume scheduler thread
  194. *
  195. * Complete scheduler thread resume wait event such that scheduler
  196. * thread can wake up and process message queues
  197. *
  198. * Return: none
  199. */
  200. void scheduler_resume(void);
  201. /**
  202. * scheduler_register_hdd_suspend_callback() - suspend callback to hdd
  203. * @callback: hdd callback to be called when controllred thread is suspended
  204. *
  205. * Return: none
  206. */
  207. void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback);
  208. /**
  209. * scheduler_wake_up_controller_thread() - wake up controller thread
  210. *
  211. * Wake up controller thread to process a critical message.
  212. *
  213. * Return: none
  214. */
  215. void scheduler_wake_up_controller_thread(void);
  216. /**
  217. * scheduler_set_event_mask() - set given event mask
  218. * @event_mask: event mask to set
  219. *
  220. * Set given event mask such that controller scheduler thread can do
  221. * specified work after wake up.
  222. *
  223. * Return: none
  224. */
  225. void scheduler_set_event_mask(uint32_t event_mask);
  226. /**
  227. * scheduler_clear_event_mask() - clear given event mask
  228. * @event_mask: event mask to set
  229. *
  230. * Return: none
  231. */
  232. void scheduler_clear_event_mask(uint32_t event_mask);
  233. /**
  234. * scheduler_target_if_mq_handler() - top level message queue handler for
  235. * target_if message queue
  236. * @msg: pointer to actual message being handled
  237. *
  238. * Return: none
  239. */
  240. QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg);
  241. /**
  242. * scheduler_os_if_mq_handler() - top level message queue handler for
  243. * os_if message queue
  244. * @msg: pointer to actual message being handled
  245. *
  246. * Return: none
  247. */
  248. QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg);
  249. /**
  250. * scheduler_timer_q_mq_handler() - top level message queue handler for
  251. * timer queue
  252. * @msg: pointer to actual message being handled
  253. *
  254. * Return: none
  255. */
  256. QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg);
  257. /**
  258. * scheduler_mlme_mq_handler() - top level message queue handler for
  259. * mlme queue
  260. * @msg: pointer to actual message being handled
  261. *
  262. * Return: QDF status
  263. */
  264. QDF_STATUS scheduler_mlme_mq_handler(struct scheduler_msg *msg);
  265. /**
  266. * scheduler_scan_mq_handler() - top level message queue handler for
  267. * scan queue
  268. * @msg: pointer to actual message being handled
  269. *
  270. * Return: QDF status
  271. */
  272. QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg);
  273. /**
  274. * scheduler_register_wma_legacy_handler() - register legacy wma handler
  275. * @callback: legacy wma handler to be called for WMA messages
  276. *
  277. * Return: QDF status
  278. */
  279. QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t
  280. callback);
  281. /**
  282. * scheduler_register_sys_legacy_handler() - register legacy sys handler
  283. * @callback: legacy sys handler to be called for sys messages
  284. *
  285. * Return: QDF status
  286. */
  287. QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t
  288. callback);
  289. /**
  290. * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler
  291. *
  292. * Return: QDF status
  293. */
  294. QDF_STATUS scheduler_deregister_sys_legacy_handler(void);
  295. /**
  296. * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler
  297. *
  298. * Return: QDF status
  299. */
  300. QDF_STATUS scheduler_deregister_wma_legacy_handler(void);
  301. /**
  302. * scheduler_mc_timer_callback() - timer callback, gets called at time out
  303. * @timer: holds the mc timer object.
  304. *
  305. * Return: None
  306. */
  307. void scheduler_mc_timer_callback(qdf_mc_timer_t *timer);
  308. /**
  309. * scheduler_get_queue_size() - Get the current size of the scheduler queue
  310. * @qid: Queue ID for which the size is requested
  311. * @size: Pointer to size where the size would be returned to the caller
  312. *
  313. * This API finds the size of the scheduler queue for the given Queue ID
  314. *
  315. * Return: QDF Status
  316. */
  317. QDF_STATUS scheduler_get_queue_size(QDF_MODULE_ID qid, uint32_t *size);
  318. #endif