scheduler_api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. #include <scheduler_api.h>
  19. #include <scheduler_core.h>
  20. #include <qdf_atomic.h>
  21. #include <qdf_module.h>
  22. #include <qdf_platform.h>
  23. QDF_STATUS scheduler_disable(void)
  24. {
  25. struct scheduler_ctx *sched_ctx;
  26. sched_debug("Disabling Scheduler");
  27. sched_ctx = scheduler_get_context();
  28. QDF_BUG(sched_ctx);
  29. if (!sched_ctx)
  30. return QDF_STATUS_E_INVAL;
  31. /* send shutdown signal to scheduler thread */
  32. qdf_atomic_set_bit(MC_SHUTDOWN_EVENT_MASK, &sched_ctx->sch_event_flag);
  33. qdf_atomic_set_bit(MC_POST_EVENT_MASK, &sched_ctx->sch_event_flag);
  34. qdf_wake_up_interruptible(&sched_ctx->sch_wait_queue);
  35. /* wait for scheduler thread to shutdown */
  36. qdf_wait_single_event(&sched_ctx->sch_shutdown, 0);
  37. sched_ctx->sch_thread = NULL;
  38. /* flush any unprocessed scheduler messages */
  39. scheduler_queues_flush(sched_ctx);
  40. return QDF_STATUS_SUCCESS;
  41. }
  42. static inline void scheduler_watchdog_notify(struct scheduler_ctx *sched)
  43. {
  44. char symbol[QDF_SYMBOL_LEN];
  45. if (sched->watchdog_callback)
  46. qdf_sprint_symbol(symbol, sched->watchdog_callback);
  47. sched_fatal("Callback %s (type 0x%x) exceeded its allotted time of %ds",
  48. sched->watchdog_callback ? symbol : "<null>",
  49. sched->watchdog_msg_type,
  50. SCHEDULER_WATCHDOG_TIMEOUT / 1000);
  51. }
  52. static void scheduler_watchdog_timeout(void *arg)
  53. {
  54. struct scheduler_ctx *sched = arg;
  55. if (qdf_is_recovering()) {
  56. sched_debug("Recovery is in progress ignore timeout");
  57. return;
  58. }
  59. scheduler_watchdog_notify(sched);
  60. if (sched->sch_thread)
  61. qdf_print_thread_trace(sched->sch_thread);
  62. /* avoid crashing during shutdown */
  63. if (qdf_atomic_test_bit(MC_SHUTDOWN_EVENT_MASK, &sched->sch_event_flag))
  64. return;
  65. QDF_DEBUG_PANIC("Going down for Scheduler Watchdog Bite!");
  66. }
  67. QDF_STATUS scheduler_enable(void)
  68. {
  69. struct scheduler_ctx *sched_ctx;
  70. sched_debug("Enabling Scheduler");
  71. sched_ctx = scheduler_get_context();
  72. QDF_BUG(sched_ctx);
  73. if (!sched_ctx)
  74. return QDF_STATUS_E_INVAL;
  75. qdf_atomic_clear_bit(MC_SHUTDOWN_EVENT_MASK,
  76. &sched_ctx->sch_event_flag);
  77. qdf_atomic_clear_bit(MC_POST_EVENT_MASK,
  78. &sched_ctx->sch_event_flag);
  79. /* create the scheduler thread */
  80. sched_ctx->sch_thread = qdf_create_thread(scheduler_thread, sched_ctx,
  81. "scheduler_thread");
  82. if (!sched_ctx->sch_thread) {
  83. sched_fatal("Failed to create scheduler thread");
  84. return QDF_STATUS_E_RESOURCES;
  85. }
  86. sched_debug("Scheduler thread created");
  87. /* wait for the scheduler thread to startup */
  88. qdf_wake_up_process(sched_ctx->sch_thread);
  89. qdf_wait_single_event(&sched_ctx->sch_start_event, 0);
  90. sched_debug("Scheduler thread started");
  91. return QDF_STATUS_SUCCESS;
  92. }
  93. QDF_STATUS scheduler_init(void)
  94. {
  95. QDF_STATUS status;
  96. struct scheduler_ctx *sched_ctx;
  97. sched_debug("Initializing Scheduler");
  98. status = scheduler_create_ctx();
  99. if (QDF_IS_STATUS_ERROR(status)) {
  100. sched_fatal("Failed to create context; status:%d", status);
  101. return status;
  102. }
  103. sched_ctx = scheduler_get_context();
  104. QDF_BUG(sched_ctx);
  105. if (!sched_ctx) {
  106. status = QDF_STATUS_E_FAILURE;
  107. goto ctx_destroy;
  108. }
  109. status = scheduler_queues_init(sched_ctx);
  110. if (QDF_IS_STATUS_ERROR(status)) {
  111. sched_fatal("Failed to init queues; status:%d", status);
  112. goto ctx_destroy;
  113. }
  114. status = qdf_event_create(&sched_ctx->sch_start_event);
  115. if (QDF_IS_STATUS_ERROR(status)) {
  116. sched_fatal("Failed to create start event; status:%d", status);
  117. goto queues_deinit;
  118. }
  119. status = qdf_event_create(&sched_ctx->sch_shutdown);
  120. if (QDF_IS_STATUS_ERROR(status)) {
  121. sched_fatal("Failed to create shutdown event; status:%d",
  122. status);
  123. goto start_event_destroy;
  124. }
  125. status = qdf_event_create(&sched_ctx->resume_sch_event);
  126. if (QDF_IS_STATUS_ERROR(status)) {
  127. sched_fatal("Failed to create resume event; status:%d", status);
  128. goto shutdown_event_destroy;
  129. }
  130. qdf_spinlock_create(&sched_ctx->sch_thread_lock);
  131. qdf_init_waitqueue_head(&sched_ctx->sch_wait_queue);
  132. sched_ctx->sch_event_flag = 0;
  133. qdf_timer_init(NULL,
  134. &sched_ctx->watchdog_timer,
  135. &scheduler_watchdog_timeout,
  136. sched_ctx,
  137. QDF_TIMER_TYPE_SW);
  138. qdf_register_mc_timer_callback(scheduler_mc_timer_callback);
  139. return QDF_STATUS_SUCCESS;
  140. shutdown_event_destroy:
  141. qdf_event_destroy(&sched_ctx->sch_shutdown);
  142. start_event_destroy:
  143. qdf_event_destroy(&sched_ctx->sch_start_event);
  144. queues_deinit:
  145. scheduler_queues_deinit(sched_ctx);
  146. ctx_destroy:
  147. scheduler_destroy_ctx();
  148. return status;
  149. }
  150. QDF_STATUS scheduler_deinit(void)
  151. {
  152. QDF_STATUS status;
  153. struct scheduler_ctx *sched_ctx;
  154. sched_debug("Deinitializing Scheduler");
  155. sched_ctx = scheduler_get_context();
  156. QDF_BUG(sched_ctx);
  157. if (!sched_ctx)
  158. return QDF_STATUS_E_INVAL;
  159. qdf_timer_free(&sched_ctx->watchdog_timer);
  160. qdf_spinlock_destroy(&sched_ctx->sch_thread_lock);
  161. qdf_event_destroy(&sched_ctx->resume_sch_event);
  162. qdf_event_destroy(&sched_ctx->sch_shutdown);
  163. qdf_event_destroy(&sched_ctx->sch_start_event);
  164. status = scheduler_queues_deinit(sched_ctx);
  165. if (QDF_IS_STATUS_ERROR(status))
  166. sched_err("Failed to deinit queues; status:%d", status);
  167. status = scheduler_destroy_ctx();
  168. if (QDF_IS_STATUS_ERROR(status))
  169. sched_err("Failed to destroy context; status:%d", status);
  170. return QDF_STATUS_SUCCESS;
  171. }
  172. QDF_STATUS scheduler_post_msg_by_priority(uint32_t qid,
  173. struct scheduler_msg *msg,
  174. bool is_high_priority)
  175. {
  176. uint8_t qidx;
  177. struct scheduler_mq_type *target_mq;
  178. struct scheduler_msg *queue_msg;
  179. struct scheduler_ctx *sched_ctx;
  180. uint16_t src_id;
  181. uint16_t dest_id;
  182. uint16_t que_id;
  183. QDF_BUG(msg);
  184. if (!msg)
  185. return QDF_STATUS_E_INVAL;
  186. sched_ctx = scheduler_get_context();
  187. QDF_BUG(sched_ctx);
  188. if (!sched_ctx)
  189. return QDF_STATUS_E_INVAL;
  190. if (!sched_ctx->sch_thread) {
  191. sched_err("Cannot post message; scheduler thread is stopped");
  192. return QDF_STATUS_E_FAILURE;
  193. }
  194. if (msg->reserved != 0 && msg->reserved != SYS_MSG_COOKIE) {
  195. QDF_DEBUG_PANIC("Scheduler messages must be initialized");
  196. return QDF_STATUS_E_FAILURE;
  197. }
  198. dest_id = scheduler_get_dest_id(qid);
  199. src_id = scheduler_get_src_id(qid);
  200. que_id = scheduler_get_que_id(qid);
  201. if (que_id >= QDF_MODULE_ID_MAX || src_id >= QDF_MODULE_ID_MAX ||
  202. dest_id >= QDF_MODULE_ID_MAX) {
  203. sched_err("Src_id/Dest_id invalid, cannot post message");
  204. return QDF_STATUS_E_FAILURE;
  205. }
  206. /* Target_If is a special message queue in phase 3 convergence beacause
  207. * its used by both legacy WMA and as well as new UMAC components which
  208. * directly populate callback handlers in message body.
  209. * 1) WMA legacy messages should not have callback
  210. * 2) New target_if message needs to have valid callback
  211. * Clear callback handler for legacy WMA messages such that in case
  212. * if someone is sending legacy WMA message from stack which has
  213. * uninitialized callback then its handled properly. Also change
  214. * legacy WMA message queue id to target_if queue such that its always
  215. * handled in right order.
  216. */
  217. if (QDF_MODULE_ID_WMA == que_id) {
  218. msg->callback = NULL;
  219. /* change legacy WMA message id to new target_if mq id */
  220. que_id = QDF_MODULE_ID_TARGET_IF;
  221. }
  222. qdf_mtrace(src_id, dest_id, msg->type, 0xFF, 0);
  223. qidx = sched_ctx->queue_ctx.scheduler_msg_qid_to_qidx[que_id];
  224. if (qidx >= SCHEDULER_NUMBER_OF_MSG_QUEUE) {
  225. sched_err("Scheduler is deinitialized ignore msg");
  226. return QDF_STATUS_E_FAILURE;
  227. }
  228. if (!sched_ctx->queue_ctx.scheduler_msg_process_fn[qidx]) {
  229. QDF_DEBUG_PANIC("callback not registered for qid[%d]", que_id);
  230. return QDF_STATUS_E_FAILURE;
  231. }
  232. target_mq = &(sched_ctx->queue_ctx.sch_msg_q[qidx]);
  233. queue_msg = scheduler_core_msg_dup(msg);
  234. if (!queue_msg)
  235. return QDF_STATUS_E_NOMEM;
  236. if (is_high_priority)
  237. scheduler_mq_put_front(target_mq, queue_msg);
  238. else
  239. scheduler_mq_put(target_mq, queue_msg);
  240. qdf_atomic_set_bit(MC_POST_EVENT_MASK, &sched_ctx->sch_event_flag);
  241. qdf_wake_up_interruptible(&sched_ctx->sch_wait_queue);
  242. return QDF_STATUS_SUCCESS;
  243. }
  244. QDF_STATUS scheduler_register_module(QDF_MODULE_ID qid,
  245. scheduler_msg_process_fn_t callback)
  246. {
  247. struct scheduler_mq_ctx *ctx;
  248. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  249. sched_enter();
  250. QDF_BUG(sched_ctx);
  251. if (!sched_ctx)
  252. return QDF_STATUS_E_FAILURE;
  253. if (sched_ctx->sch_last_qidx >= SCHEDULER_NUMBER_OF_MSG_QUEUE) {
  254. sched_err("Already registered max %d no of message queues",
  255. SCHEDULER_NUMBER_OF_MSG_QUEUE);
  256. return QDF_STATUS_E_FAILURE;
  257. }
  258. ctx = &sched_ctx->queue_ctx;
  259. ctx->scheduler_msg_qid_to_qidx[qid] = sched_ctx->sch_last_qidx;
  260. ctx->sch_msg_q[sched_ctx->sch_last_qidx].qid = qid;
  261. ctx->scheduler_msg_process_fn[sched_ctx->sch_last_qidx] = callback;
  262. sched_ctx->sch_last_qidx++;
  263. sched_exit();
  264. return QDF_STATUS_SUCCESS;
  265. }
  266. QDF_STATUS scheduler_deregister_module(QDF_MODULE_ID qid)
  267. {
  268. struct scheduler_mq_ctx *ctx;
  269. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  270. uint8_t qidx;
  271. sched_enter();
  272. QDF_BUG(sched_ctx);
  273. if (!sched_ctx)
  274. return QDF_STATUS_E_FAILURE;
  275. ctx = &sched_ctx->queue_ctx;
  276. qidx = ctx->scheduler_msg_qid_to_qidx[qid];
  277. ctx->scheduler_msg_process_fn[qidx] = NULL;
  278. sched_ctx->sch_last_qidx--;
  279. ctx->scheduler_msg_qid_to_qidx[qidx] = SCHEDULER_NUMBER_OF_MSG_QUEUE;
  280. sched_exit();
  281. return QDF_STATUS_SUCCESS;
  282. }
  283. void scheduler_resume(void)
  284. {
  285. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  286. if (sched_ctx)
  287. qdf_event_set(&sched_ctx->resume_sch_event);
  288. }
  289. void scheduler_register_hdd_suspend_callback(hdd_suspend_callback callback)
  290. {
  291. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  292. if (sched_ctx)
  293. sched_ctx->hdd_callback = callback;
  294. }
  295. void scheduler_wake_up_controller_thread(void)
  296. {
  297. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  298. if (sched_ctx)
  299. qdf_wake_up_interruptible(&sched_ctx->sch_wait_queue);
  300. }
  301. void scheduler_set_event_mask(uint32_t event_mask)
  302. {
  303. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  304. if (sched_ctx)
  305. qdf_atomic_set_bit(event_mask, &sched_ctx->sch_event_flag);
  306. }
  307. void scheduler_clear_event_mask(uint32_t event_mask)
  308. {
  309. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  310. if (sched_ctx)
  311. qdf_atomic_clear_bit(event_mask, &sched_ctx->sch_event_flag);
  312. }
  313. QDF_STATUS scheduler_target_if_mq_handler(struct scheduler_msg *msg)
  314. {
  315. QDF_STATUS status;
  316. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  317. QDF_STATUS (*target_if_msg_handler)(struct scheduler_msg *);
  318. QDF_BUG(msg);
  319. if (!msg)
  320. return QDF_STATUS_E_FAILURE;
  321. QDF_BUG(sched_ctx);
  322. if (!sched_ctx)
  323. return QDF_STATUS_E_FAILURE;
  324. target_if_msg_handler = msg->callback;
  325. /* Target_If is a special message queue in phase 3 convergence beacause
  326. * its used by both legacy WMA and as well as new UMAC components. New
  327. * UMAC components directly pass their message handlers as callback in
  328. * message body.
  329. * 1) All Legacy WMA messages do not contain message callback so invoke
  330. * registered legacy WMA handler. Scheduler message posting APIs
  331. * makes sure legacy WMA messages do not have callbacks.
  332. * 2) For new messages which have valid callbacks invoke their callbacks
  333. * directly.
  334. */
  335. if (!target_if_msg_handler)
  336. status = sched_ctx->legacy_wma_handler(msg);
  337. else
  338. status = target_if_msg_handler(msg);
  339. return status;
  340. }
  341. QDF_STATUS scheduler_os_if_mq_handler(struct scheduler_msg *msg)
  342. {
  343. QDF_STATUS (*os_if_msg_handler)(struct scheduler_msg *);
  344. QDF_BUG(msg);
  345. if (!msg)
  346. return QDF_STATUS_E_FAILURE;
  347. os_if_msg_handler = msg->callback;
  348. QDF_BUG(os_if_msg_handler);
  349. if (!os_if_msg_handler)
  350. return QDF_STATUS_E_FAILURE;
  351. os_if_msg_handler(msg);
  352. return QDF_STATUS_SUCCESS;
  353. }
  354. QDF_STATUS scheduler_timer_q_mq_handler(struct scheduler_msg *msg)
  355. {
  356. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  357. qdf_mc_timer_callback_t timer_callback;
  358. QDF_BUG(msg);
  359. if (!msg)
  360. return QDF_STATUS_E_FAILURE;
  361. QDF_BUG(sched_ctx);
  362. if (!sched_ctx)
  363. return QDF_STATUS_E_FAILURE;
  364. /* legacy sys message handler? */
  365. if (msg->reserved != SYS_MSG_COOKIE || msg->type != SYS_MSG_ID_MC_TIMER)
  366. return sched_ctx->legacy_sys_handler(msg);
  367. timer_callback = msg->callback;
  368. QDF_BUG(timer_callback);
  369. if (!timer_callback)
  370. return QDF_STATUS_E_FAILURE;
  371. timer_callback(msg->bodyptr);
  372. return QDF_STATUS_SUCCESS;
  373. }
  374. QDF_STATUS scheduler_mlme_mq_handler(struct scheduler_msg *msg)
  375. {
  376. scheduler_msg_process_fn_t mlme_msg_handler;
  377. QDF_BUG(msg);
  378. if (!msg)
  379. return QDF_STATUS_E_FAILURE;
  380. mlme_msg_handler = msg->callback;
  381. QDF_BUG(mlme_msg_handler);
  382. if (!mlme_msg_handler)
  383. return QDF_STATUS_E_FAILURE;
  384. mlme_msg_handler(msg);
  385. return QDF_STATUS_SUCCESS;
  386. }
  387. QDF_STATUS scheduler_scan_mq_handler(struct scheduler_msg *msg)
  388. {
  389. QDF_STATUS (*scan_q_msg_handler)(struct scheduler_msg *);
  390. QDF_BUG(msg);
  391. if (!msg)
  392. return QDF_STATUS_E_FAILURE;
  393. scan_q_msg_handler = msg->callback;
  394. QDF_BUG(scan_q_msg_handler);
  395. if (!scan_q_msg_handler)
  396. return QDF_STATUS_E_FAILURE;
  397. scan_q_msg_handler(msg);
  398. return QDF_STATUS_SUCCESS;
  399. }
  400. QDF_STATUS scheduler_register_wma_legacy_handler(scheduler_msg_process_fn_t
  401. wma_callback)
  402. {
  403. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  404. QDF_BUG(sched_ctx);
  405. if (!sched_ctx)
  406. return QDF_STATUS_E_FAILURE;
  407. sched_ctx->legacy_wma_handler = wma_callback;
  408. return QDF_STATUS_SUCCESS;
  409. }
  410. QDF_STATUS scheduler_register_sys_legacy_handler(scheduler_msg_process_fn_t
  411. sys_callback)
  412. {
  413. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  414. QDF_BUG(sched_ctx);
  415. if (!sched_ctx)
  416. return QDF_STATUS_E_FAILURE;
  417. sched_ctx->legacy_sys_handler = sys_callback;
  418. return QDF_STATUS_SUCCESS;
  419. }
  420. QDF_STATUS scheduler_deregister_wma_legacy_handler(void)
  421. {
  422. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  423. QDF_BUG(sched_ctx);
  424. if (!sched_ctx)
  425. return QDF_STATUS_E_FAILURE;
  426. sched_ctx->legacy_wma_handler = NULL;
  427. return QDF_STATUS_SUCCESS;
  428. }
  429. QDF_STATUS scheduler_deregister_sys_legacy_handler(void)
  430. {
  431. struct scheduler_ctx *sched_ctx = scheduler_get_context();
  432. QDF_BUG(sched_ctx);
  433. if (!sched_ctx)
  434. return QDF_STATUS_E_FAILURE;
  435. sched_ctx->legacy_sys_handler = NULL;
  436. return QDF_STATUS_SUCCESS;
  437. }
  438. static QDF_STATUS scheduler_msg_flush_noop(struct scheduler_msg *msg)
  439. {
  440. return QDF_STATUS_SUCCESS;
  441. }
  442. void scheduler_mc_timer_callback(qdf_mc_timer_t *timer)
  443. {
  444. struct scheduler_msg msg = {0};
  445. QDF_STATUS status;
  446. qdf_mc_timer_callback_t callback = NULL;
  447. void *user_data = NULL;
  448. QDF_TIMER_TYPE type = QDF_TIMER_TYPE_SW;
  449. QDF_BUG(timer);
  450. if (!timer)
  451. return;
  452. qdf_spin_lock_irqsave(&timer->platform_info.spinlock);
  453. switch (timer->state) {
  454. case QDF_TIMER_STATE_STARTING:
  455. /* we are in this state because someone just started the timer,
  456. * MC timer got started and expired, but the time content have
  457. * not been updated this is a rare race condition!
  458. */
  459. timer->state = QDF_TIMER_STATE_STOPPED;
  460. status = QDF_STATUS_E_ALREADY;
  461. break;
  462. case QDF_TIMER_STATE_STOPPED:
  463. status = QDF_STATUS_E_ALREADY;
  464. break;
  465. case QDF_TIMER_STATE_UNUSED:
  466. status = QDF_STATUS_E_EXISTS;
  467. break;
  468. case QDF_TIMER_STATE_RUNNING:
  469. /* need to go to stop state here because the call-back function
  470. * may restart timer (to emulate periodic timer)
  471. */
  472. timer->state = QDF_TIMER_STATE_STOPPED;
  473. /* copy the relevant timer information to local variables;
  474. * once we exits from this critical section, the timer content
  475. * may be modified by other tasks
  476. */
  477. callback = timer->callback;
  478. user_data = timer->user_data;
  479. type = timer->type;
  480. status = QDF_STATUS_SUCCESS;
  481. break;
  482. default:
  483. QDF_ASSERT(0);
  484. status = QDF_STATUS_E_FAULT;
  485. break;
  486. }
  487. qdf_spin_unlock_irqrestore(&timer->platform_info.spinlock);
  488. if (QDF_IS_STATUS_ERROR(status)) {
  489. sched_debug("MC timer fired but is not running; skip callback");
  490. return;
  491. }
  492. qdf_try_allowing_sleep(type);
  493. QDF_BUG(callback);
  494. if (!callback)
  495. return;
  496. /* serialize to scheduler controller thread */
  497. msg.type = SYS_MSG_ID_MC_TIMER;
  498. msg.reserved = SYS_MSG_COOKIE;
  499. msg.callback = callback;
  500. msg.bodyptr = user_data;
  501. msg.bodyval = 0;
  502. /* bodyptr points to user data, do not free it during msg flush */
  503. msg.flush_callback = scheduler_msg_flush_noop;
  504. status = scheduler_post_message(QDF_MODULE_ID_SCHEDULER,
  505. QDF_MODULE_ID_SCHEDULER,
  506. QDF_MODULE_ID_SYS, &msg);
  507. if (QDF_IS_STATUS_ERROR(status))
  508. sched_err("Could not enqueue timer to timer queue");
  509. }
  510. QDF_STATUS scheduler_get_queue_size(QDF_MODULE_ID qid, uint32_t *size)
  511. {
  512. uint8_t qidx;
  513. struct scheduler_mq_type *target_mq;
  514. struct scheduler_ctx *sched_ctx;
  515. sched_ctx = scheduler_get_context();
  516. if (!sched_ctx)
  517. return QDF_STATUS_E_INVAL;
  518. /* WMA also uses the target_if queue, so replace the QID */
  519. if (QDF_MODULE_ID_WMA == qid)
  520. qid = QDF_MODULE_ID_TARGET_IF;
  521. qidx = sched_ctx->queue_ctx.scheduler_msg_qid_to_qidx[qid];
  522. if (qidx >= SCHEDULER_NUMBER_OF_MSG_QUEUE) {
  523. sched_err("Scheduler is deinitialized");
  524. return QDF_STATUS_E_FAILURE;
  525. }
  526. target_mq = &(sched_ctx->queue_ctx.sch_msg_q[qidx]);
  527. *size = qdf_list_size(&target_mq->mq_list);
  528. return QDF_STATUS_SUCCESS;
  529. }
  530. QDF_STATUS scheduler_post_message_debug(QDF_MODULE_ID src_id,
  531. QDF_MODULE_ID dest_id,
  532. QDF_MODULE_ID que_id,
  533. struct scheduler_msg *msg,
  534. int line,
  535. const char *func)
  536. {
  537. QDF_STATUS status;
  538. status = scheduler_post_msg(scheduler_get_qid(src_id, dest_id, que_id),
  539. msg);
  540. if (QDF_IS_STATUS_ERROR(status))
  541. sched_err("couldn't post from %d to %d - called from %d, %s",
  542. src_id, dest_id, line, func);
  543. return status;
  544. }
  545. qdf_export_symbol(scheduler_post_message_debug);