scheduler_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 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_deinit_return_data_ptr() - deinitialize callback and
  104. * return data
  105. * @wrapper_ptr: wrapper ptr
  106. *
  107. * Return: original data supplied to scheduler_qdf_mc_timer_init()
  108. */
  109. void *scheduler_qdf_mc_timer_deinit_return_data_ptr(
  110. struct sched_qdf_mc_timer_cb_wrapper *wrapper_ptr);
  111. /**
  112. * scheduler_qdf_mc_timer_callback_t_wrapper() - wrapper for mc timer callbacks
  113. * @msg: message pointer
  114. *
  115. * Return: None
  116. */
  117. QDF_STATUS scheduler_qdf_mc_timer_callback_t_wrapper(struct scheduler_msg *msg);
  118. /**
  119. * sched_history_print() - print scheduler history
  120. *
  121. * This API prints the scheduler history.
  122. *
  123. * Return: None
  124. */
  125. void sched_history_print(void);
  126. /**
  127. * scheduler_init() - initialize control path scheduler
  128. *
  129. * This API initializes control path scheduler.
  130. *
  131. * Return: QDF status
  132. */
  133. QDF_STATUS scheduler_init(void);
  134. /**
  135. * scheduler_deinit() - de-initialize control path scheduler
  136. *
  137. * This API de-initializes control path scheduler.
  138. *
  139. * Return: QDF status
  140. */
  141. QDF_STATUS scheduler_deinit(void);
  142. /**
  143. * scheduler_enable() - start the scheduler module
  144. *
  145. * Ready the scheduler module to service requests, and start the scheduler's
  146. * message processing thread. Must only be called after scheduler_init().
  147. *
  148. * Return: QDF_STATUS
  149. */
  150. QDF_STATUS scheduler_enable(void);
  151. /**
  152. * scheduler_disable() - stop the scheduler module
  153. *
  154. * Stop the scheduler module from servicing requests, and terminate the
  155. * scheduler's message processing thread. Must be called before
  156. * scheduler_deinit().
  157. *
  158. * Return: QDF_STATUS
  159. */
  160. QDF_STATUS scheduler_disable(void);
  161. /**
  162. * scheduler_register_module() - register input module/queue id
  163. * @qid: queue id to get registered
  164. * @callback: queue message to be called when a message is posted
  165. *
  166. * Return: QDF status
  167. */
  168. QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid,
  169. scheduler_msg_process_fn_t callback);
  170. /**
  171. * scheduler_deregister_module() - deregister input module/queue id
  172. * @qid: queue id to get deregistered
  173. *
  174. * Return: QDF status
  175. */
  176. QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid);
  177. /**
  178. * scheduler_post_msg_by_priority() - post messages by priority
  179. * @qid: queue id to which the message has to be posted.
  180. * @msg: message pointer
  181. * @is_high_priority: set to true for high priority message else false
  182. *
  183. * Return: QDF status
  184. */
  185. QDF_STATUS scheduler_post_msg_by_priority(uint32_t qid,
  186. struct scheduler_msg *msg,
  187. bool is_high_priority);
  188. /**
  189. * scheduler_post_msg() - post normal messages(no priority)
  190. * @qid: queue id to which the message has to be posted.
  191. * @msg: message pointer
  192. *
  193. * Return: QDF status
  194. */
  195. static inline QDF_STATUS scheduler_post_msg(uint32_t qid,
  196. struct scheduler_msg *msg)
  197. {
  198. return scheduler_post_msg_by_priority(qid, msg, false);
  199. }
  200. /**
  201. * scheduler_post_message_debug() - post normal messages(no priority)
  202. * @src_id: Source module of the message
  203. * @dest_id: Destination module of the message
  204. * @que_id: Queue to which the message has to posted.
  205. * @msg: message pointer
  206. * @line: caller line number
  207. * @func: caller function
  208. *
  209. * This function will mask the src_id, and destination id to qid of
  210. * scheduler_post_msg
  211. *
  212. * Return: QDF status
  213. */
  214. QDF_STATUS scheduler_post_message_debug(QDF_MODULE_ID src_id,
  215. QDF_MODULE_ID dest_id,
  216. QDF_MODULE_ID que_id,
  217. struct scheduler_msg *msg,
  218. int line,
  219. const char *func);
  220. /**
  221. * scheduler_post_message() - post normal messages(no priority)
  222. * @src_id: Source module of the message
  223. * @dest_id: Destination module of the message
  224. * @que_id: Queue to which the message has to posted.
  225. * @msg: message pointer
  226. *
  227. * This function will mask the src_id, and destination id to qid of
  228. * scheduler_post_msg
  229. *
  230. * Return: QDF status
  231. */
  232. #define scheduler_post_message(src_id, dest_id, que_id, msg) \
  233. scheduler_post_message_debug(src_id, dest_id, que_id, msg, \
  234. __LINE__, __func__)
  235. /**
  236. * scheduler_resume() - resume scheduler thread
  237. *
  238. * Complete scheduler thread resume wait event such that scheduler
  239. * thread can wake up and process message queues
  240. *
  241. * Return: none
  242. */
  243. void scheduler_resume(void);
  244. /**
  245. * scheduler_set_watchdog_timeout() - set scheduler timeout for msg processing
  246. * @timeout: timeout value in milliseconds
  247. *
  248. * Configure the timeout for triggering the scheduler watchdog timer
  249. * in milliseconds
  250. *
  251. * Return: none
  252. */
  253. void scheduler_set_watchdog_timeout(uint32_t timeout);
  254. /**
  255. * scheduler_register_hdd_suspend_callback() - suspend callback to hdd
  256. * @callback: hdd callback to be called when controller thread is suspended
  257. *
  258. * Return: none
  259. */
  260. void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback);
  261. /**
  262. * scheduler_wake_up_controller_thread() - wake up controller thread
  263. *
  264. * Wake up controller thread to process a critical message.
  265. *
  266. * Return: none
  267. */
  268. void scheduler_wake_up_controller_thread(void);
  269. /**
  270. * scheduler_set_event_mask() - set given event mask
  271. * @event_mask: event mask to set
  272. *
  273. * Set given event mask such that controller scheduler thread can do
  274. * specified work after wake up.
  275. *
  276. * Return: none
  277. */
  278. void scheduler_set_event_mask(uint32_t event_mask);
  279. /**
  280. * scheduler_clear_event_mask() - clear given event mask
  281. * @event_mask: event mask to set
  282. *
  283. * Return: none
  284. */
  285. void scheduler_clear_event_mask(uint32_t event_mask);
  286. /**
  287. * scheduler_target_if_mq_handler() - top level message queue handler for
  288. * target_if message queue
  289. * @msg: pointer to actual message being handled
  290. *
  291. * Return: none
  292. */
  293. QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg);
  294. /**
  295. * scheduler_os_if_mq_handler() - top level message queue handler for
  296. * os_if message queue
  297. * @msg: pointer to actual message being handled
  298. *
  299. * Return: none
  300. */
  301. QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg);
  302. /**
  303. * scheduler_timer_q_mq_handler() - top level message queue handler for
  304. * timer queue
  305. * @msg: pointer to actual message being handled
  306. *
  307. * Return: none
  308. */
  309. QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg);
  310. /**
  311. * scheduler_mlme_mq_handler() - top level message queue handler for
  312. * mlme queue
  313. * @msg: pointer to actual message being handled
  314. *
  315. * Return: QDF status
  316. */
  317. QDF_STATUS scheduler_mlme_mq_handler(struct scheduler_msg *msg);
  318. /**
  319. * scheduler_scan_mq_handler() - top level message queue handler for
  320. * scan queue
  321. * @msg: pointer to actual message being handled
  322. *
  323. * Return: QDF status
  324. */
  325. QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg);
  326. /**
  327. * scheduler_register_wma_legacy_handler() - register legacy wma handler
  328. * @callback: legacy wma handler to be called for WMA messages
  329. *
  330. * Return: QDF status
  331. */
  332. QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t
  333. callback);
  334. /**
  335. * scheduler_register_sys_legacy_handler() - register legacy sys handler
  336. * @callback: legacy sys handler to be called for sys messages
  337. *
  338. * Return: QDF status
  339. */
  340. QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t
  341. callback);
  342. /**
  343. * scheduler_deregister_sys_legacy_handler() - deregister legacy sys handler
  344. *
  345. * Return: QDF status
  346. */
  347. QDF_STATUS scheduler_deregister_sys_legacy_handler(void);
  348. /**
  349. * scheduler_deregister_wma_legacy_handler() - deregister legacy wma handler
  350. *
  351. * Return: QDF status
  352. */
  353. QDF_STATUS scheduler_deregister_wma_legacy_handler(void);
  354. /**
  355. * scheduler_mc_timer_callback() - timer callback, gets called at time out
  356. * @timer: holds the mc timer object.
  357. *
  358. * Return: None
  359. */
  360. void scheduler_mc_timer_callback(qdf_mc_timer_t *timer);
  361. /**
  362. * scheduler_get_queue_size() - Get the current size of the scheduler queue
  363. * @qid: Queue ID for which the size is requested
  364. * @size: Pointer to size where the size would be returned to the caller
  365. *
  366. * This API finds the size of the scheduler queue for the given Queue ID
  367. *
  368. * Return: QDF Status
  369. */
  370. QDF_STATUS scheduler_get_queue_size(QDF_MODULE_ID qid, uint32_t *size);
  371. #endif