scheduler_api.h 11 KB

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