scheduler_api.h 10 KB

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