__wlan_dsc.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * Copyright (c) 2018-2019 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 "qdf_list.h"
  19. #include "qdf_mem.h"
  20. #include "qdf_status.h"
  21. #include "qdf_str.h"
  22. #include "qdf_threads.h"
  23. #include "qdf_timer.h"
  24. #include "__wlan_dsc.h"
  25. #include "cds_api.h"
  26. #ifdef WLAN_DSC_DEBUG
  27. static void __dsc_dbg_op_timeout(void *opaque_op)
  28. {
  29. struct dsc_op *op = opaque_op;
  30. qdf_print_thread_trace(op->thread);
  31. QDF_DEBUG_PANIC("Operation '%s' exceeded %ums",
  32. op->func, DSC_OP_TIMEOUT_MS);
  33. }
  34. /**
  35. * __dsc_dbg_ops_init() - initialize debug ops data structures
  36. * @ops: the ops container to initialize
  37. *
  38. * Return: None
  39. */
  40. static inline void __dsc_dbg_ops_init(struct dsc_ops *ops)
  41. {
  42. qdf_list_create(&ops->list, 0);
  43. }
  44. /**
  45. * __dsc_dbg_ops_deinit() - de-initialize debug ops data structures
  46. * @ops: the ops container to de-initialize
  47. *
  48. * Return: None
  49. */
  50. static inline void __dsc_dbg_ops_deinit(struct dsc_ops *ops)
  51. {
  52. qdf_list_destroy(&ops->list);
  53. }
  54. /**
  55. * __dsc_dbg_ops_insert() - insert @func into the debug information in @ops
  56. * @ops: the ops container to insert into
  57. * @func: the debug information to insert
  58. *
  59. * Return: QDF_STATUS
  60. */
  61. static QDF_STATUS __dsc_dbg_ops_insert(struct dsc_ops *ops, const char *func)
  62. {
  63. QDF_STATUS status;
  64. struct dsc_op *op;
  65. op = qdf_mem_malloc(sizeof(*op));
  66. if (!op)
  67. return QDF_STATUS_E_NOMEM;
  68. op->thread = qdf_get_current_task();
  69. status = qdf_timer_init(NULL, &op->timeout_timer, __dsc_dbg_op_timeout,
  70. op, QDF_TIMER_TYPE_SW);
  71. if (QDF_IS_STATUS_ERROR(status))
  72. goto free_op;
  73. op->func = func;
  74. qdf_timer_start(&op->timeout_timer, DSC_OP_TIMEOUT_MS);
  75. qdf_list_insert_back(&ops->list, &op->node);
  76. return QDF_STATUS_SUCCESS;
  77. free_op:
  78. qdf_mem_free(op);
  79. return status;
  80. }
  81. /**
  82. * __dsc_dbg_ops_remove() - remove @func from the debug information in @ops
  83. * @ops: the ops container to remove from
  84. * @func: the debug information to remove
  85. *
  86. * Return: None
  87. */
  88. static void __dsc_dbg_ops_remove(struct dsc_ops *ops, const char *func)
  89. {
  90. struct dsc_op *op;
  91. /* Global pending op depth is usually <=3. Use linear search for now */
  92. qdf_list_for_each(&ops->list, op, node) {
  93. if (!qdf_str_eq(op->func, func))
  94. continue;
  95. /* this is safe because we cease iteration */
  96. qdf_list_remove_node(&ops->list, &op->node);
  97. qdf_timer_stop(&op->timeout_timer);
  98. qdf_timer_free(&op->timeout_timer);
  99. qdf_mem_free(op);
  100. return;
  101. }
  102. QDF_DEBUG_PANIC("Driver op '%s' is not pending", func);
  103. }
  104. #else
  105. static inline void __dsc_dbg_ops_init(struct dsc_ops *ops) { }
  106. static inline void __dsc_dbg_ops_deinit(struct dsc_ops *ops) { }
  107. static inline QDF_STATUS
  108. __dsc_dbg_ops_insert(struct dsc_ops *ops, const char *func)
  109. {
  110. return QDF_STATUS_SUCCESS;
  111. }
  112. static inline void
  113. __dsc_dbg_ops_remove(struct dsc_ops *ops, const char *func) { }
  114. #endif /* WLAN_DSC_DEBUG */
  115. void __dsc_ops_init(struct dsc_ops *ops)
  116. {
  117. ops->count = 0;
  118. qdf_event_create(&ops->event);
  119. __dsc_dbg_ops_init(ops);
  120. }
  121. void __dsc_ops_deinit(struct dsc_ops *ops)
  122. {
  123. /* assert no ops in flight */
  124. dsc_assert(!ops->count);
  125. __dsc_dbg_ops_deinit(ops);
  126. qdf_event_destroy(&ops->event);
  127. }
  128. QDF_STATUS __dsc_ops_insert(struct dsc_ops *ops, const char *func)
  129. {
  130. QDF_STATUS status;
  131. status = __dsc_dbg_ops_insert(ops, func);
  132. if (QDF_IS_STATUS_ERROR(status))
  133. return status;
  134. ops->count++;
  135. return QDF_STATUS_SUCCESS;
  136. }
  137. bool __dsc_ops_remove(struct dsc_ops *ops, const char *func)
  138. {
  139. dsc_assert(ops->count);
  140. ops->count--;
  141. __dsc_dbg_ops_remove(ops, func);
  142. return ops->count == 0;
  143. }
  144. #ifdef WLAN_DSC_DEBUG
  145. static void __dsc_dbg_trans_timeout(void *opaque_trans)
  146. {
  147. struct dsc_trans *trans = opaque_trans;
  148. qdf_print_thread_trace(trans->thread);
  149. if (cds_is_fw_down())
  150. dsc_err("fw is down avoid panic");
  151. else
  152. QDF_DEBUG_PANIC("Transition '%s' exceeded %ums",
  153. trans->active_desc, DSC_TRANS_TIMEOUT_MS);
  154. }
  155. /**
  156. * __dsc_dbg_trans_timeout_start() - start a timeout timer for @trans
  157. * @trans: the active transition to start a timeout timer for
  158. *
  159. * Return: QDF_STATUS
  160. */
  161. static QDF_STATUS __dsc_dbg_trans_timeout_start(struct dsc_trans *trans)
  162. {
  163. QDF_STATUS status;
  164. trans->thread = qdf_get_current_task();
  165. status = qdf_timer_init(NULL, &trans->timeout_timer,
  166. __dsc_dbg_trans_timeout, trans,
  167. QDF_TIMER_TYPE_SW);
  168. if (QDF_IS_STATUS_ERROR(status))
  169. return status;
  170. qdf_timer_start(&trans->timeout_timer, DSC_TRANS_TIMEOUT_MS);
  171. return QDF_STATUS_SUCCESS;
  172. }
  173. /**
  174. * __dsc_dbg_trans_timeout_stop() - stop the timeout timer for @trans
  175. * @trans: the active transition to stop the timeout timer for
  176. *
  177. * Return: None
  178. */
  179. static void __dsc_dbg_trans_timeout_stop(struct dsc_trans *trans)
  180. {
  181. qdf_timer_stop(&trans->timeout_timer);
  182. qdf_timer_free(&trans->timeout_timer);
  183. }
  184. static void __dsc_dbg_tran_wait_timeout(void *opaque_tran)
  185. {
  186. struct dsc_tran *tran = opaque_tran;
  187. qdf_print_thread_trace(tran->thread);
  188. QDF_DEBUG_PANIC("Transition '%s' waited more than %ums",
  189. tran->desc, DSC_TRANS_WAIT_TIMEOUT_MS);
  190. }
  191. /**
  192. * __dsc_dbg_tran_wait_timeout_start() - start a timeout timer for @tran
  193. * @tran: the pending transition to start a timeout timer for
  194. *
  195. * Return: QDF_STATUS
  196. */
  197. static QDF_STATUS __dsc_dbg_tran_wait_timeout_start(struct dsc_tran *tran)
  198. {
  199. QDF_STATUS status;
  200. tran->thread = qdf_get_current_task();
  201. status = qdf_timer_init(NULL, &tran->timeout_timer,
  202. __dsc_dbg_tran_wait_timeout, tran,
  203. QDF_TIMER_TYPE_SW);
  204. if (QDF_IS_STATUS_ERROR(status))
  205. return status;
  206. qdf_timer_start(&tran->timeout_timer, DSC_TRANS_WAIT_TIMEOUT_MS);
  207. return QDF_STATUS_SUCCESS;
  208. }
  209. /**
  210. * __dsc_dbg_tran_wait_timeout_stop() - stop the timeout timer for @tran
  211. * @tran: the pending transition to stop the timeout timer for
  212. *
  213. * Return: None
  214. */
  215. static void __dsc_dbg_tran_wait_timeout_stop(struct dsc_tran *tran)
  216. {
  217. qdf_timer_stop(&tran->timeout_timer);
  218. qdf_timer_free(&tran->timeout_timer);
  219. }
  220. #else
  221. static inline QDF_STATUS __dsc_dbg_trans_timeout_start(struct dsc_trans *trans)
  222. {
  223. return QDF_STATUS_SUCCESS;
  224. }
  225. static inline void __dsc_dbg_trans_timeout_stop(struct dsc_trans *trans) { }
  226. static inline QDF_STATUS
  227. __dsc_dbg_tran_wait_timeout_start(struct dsc_tran *tran)
  228. {
  229. return QDF_STATUS_SUCCESS;
  230. }
  231. static inline void __dsc_dbg_tran_wait_timeout_stop(struct dsc_tran *tran) { }
  232. #endif /* WLAN_DSC_DEBUG */
  233. void __dsc_trans_init(struct dsc_trans *trans)
  234. {
  235. trans->active_desc = NULL;
  236. qdf_list_create(&trans->queue, 0);
  237. }
  238. void __dsc_trans_deinit(struct dsc_trans *trans)
  239. {
  240. qdf_list_destroy(&trans->queue);
  241. trans->active_desc = NULL;
  242. }
  243. QDF_STATUS __dsc_trans_start(struct dsc_trans *trans, const char *desc)
  244. {
  245. QDF_STATUS status;
  246. status = __dsc_dbg_trans_timeout_start(trans);
  247. if (QDF_IS_STATUS_ERROR(status))
  248. return status;
  249. dsc_assert(!trans->active_desc);
  250. trans->active_desc = desc;
  251. return QDF_STATUS_SUCCESS;
  252. }
  253. void __dsc_trans_stop(struct dsc_trans *trans)
  254. {
  255. dsc_assert(trans->active_desc);
  256. trans->active_desc = NULL;
  257. __dsc_dbg_trans_timeout_stop(trans);
  258. }
  259. QDF_STATUS __dsc_trans_queue(struct dsc_trans *trans, struct dsc_tran *tran,
  260. const char *desc)
  261. {
  262. QDF_STATUS status;
  263. tran->abort = false;
  264. tran->desc = desc;
  265. qdf_event_create(&tran->event);
  266. status = __dsc_dbg_tran_wait_timeout_start(tran);
  267. if (QDF_IS_STATUS_ERROR(status))
  268. goto event_destroy;
  269. qdf_list_insert_back(&trans->queue, &tran->node);
  270. return QDF_STATUS_SUCCESS;
  271. event_destroy:
  272. qdf_event_destroy(&tran->event);
  273. return status;
  274. }
  275. /**
  276. * __dsc_trans_dequeue() - dequeue the next queued transition from @trans
  277. * @trans: the transactions container to dequeue from
  278. *
  279. * Return: the dequeued transition, or NULL if @trans is empty
  280. */
  281. static struct dsc_tran *__dsc_trans_dequeue(struct dsc_trans *trans)
  282. {
  283. QDF_STATUS status;
  284. qdf_list_node_t *node;
  285. struct dsc_tran *tran;
  286. status = qdf_list_remove_front(&trans->queue, &node);
  287. if (QDF_IS_STATUS_ERROR(status))
  288. return NULL;
  289. tran = qdf_container_of(node, struct dsc_tran, node);
  290. __dsc_dbg_tran_wait_timeout_stop(tran);
  291. return tran;
  292. }
  293. bool __dsc_trans_abort(struct dsc_trans *trans)
  294. {
  295. struct dsc_tran *tran;
  296. tran = __dsc_trans_dequeue(trans);
  297. if (!tran)
  298. return false;
  299. tran->abort = true;
  300. qdf_event_set(&tran->event);
  301. return true;
  302. }
  303. bool __dsc_trans_trigger(struct dsc_trans *trans)
  304. {
  305. struct dsc_tran *tran;
  306. tran = __dsc_trans_dequeue(trans);
  307. if (!tran)
  308. return false;
  309. __dsc_trans_start(trans, tran->desc);
  310. qdf_event_set(&tran->event);
  311. return true;
  312. }
  313. bool __dsc_trans_active(struct dsc_trans *trans)
  314. {
  315. return !!trans->active_desc;
  316. }
  317. bool __dsc_trans_queued(struct dsc_trans *trans)
  318. {
  319. return !qdf_list_empty(&trans->queue);
  320. }
  321. bool __dsc_trans_active_or_queued(struct dsc_trans *trans)
  322. {
  323. return __dsc_trans_active(trans) || __dsc_trans_queued(trans);
  324. }
  325. QDF_STATUS __dsc_tran_wait(struct dsc_tran *tran)
  326. {
  327. QDF_STATUS status;
  328. status = qdf_wait_single_event(&tran->event, 0);
  329. qdf_event_destroy(&tran->event);
  330. if (QDF_IS_STATUS_ERROR(status))
  331. return status;
  332. if (tran->abort)
  333. return QDF_STATUS_E_ABORTED;
  334. return QDF_STATUS_SUCCESS;
  335. }