qdf_defer.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /**
  19. * DOC: qdf_defer.h
  20. * This file abstracts deferred execution API's.
  21. */
  22. #ifndef __QDF_DEFER_H
  23. #define __QDF_DEFER_H
  24. #include <qdf_types.h>
  25. #include <i_qdf_defer.h>
  26. /**
  27. * TODO This implements work queues (worker threads, kernel threads etc.).
  28. * Note that there is no cancel on a scheduled work. You cannot free a work
  29. * item if its queued. You cannot know if a work item is queued or not unless
  30. * its running, hence you know its not queued.
  31. *
  32. * so if, say, a module is asked to unload itself, how exactly will it make
  33. * sure that the work's not queued, for OS'es that dont provide such a
  34. * mechanism??
  35. */
  36. /*
  37. * Representation of a work queue.
  38. */
  39. typedef __qdf_work_t qdf_work_t;
  40. typedef __qdf_workqueue_t qdf_workqueue_t;
  41. /*
  42. * Representation of a bottom half.
  43. */
  44. typedef __qdf_bh_t qdf_bh_t;
  45. /**
  46. * qdf_create_bh - creates the bottom half deferred handler
  47. * @bh: pointer to bottom
  48. * @func: deferred function to run at bottom half interrupt context.
  49. * @arg: argument for the deferred function
  50. * Return: none
  51. */
  52. static inline void
  53. qdf_create_bh(qdf_bh_t *bh, qdf_defer_fn_t func, void *arg)
  54. {
  55. __qdf_init_bh(bh, func, arg);
  56. }
  57. /**
  58. * qdf_sched - schedule a bottom half (DPC)
  59. * @bh: pointer to bottom
  60. * Return: none
  61. */
  62. static inline void qdf_sched_bh(qdf_bh_t *bh)
  63. {
  64. __qdf_sched_bh(bh);
  65. }
  66. /**
  67. * qdf_destroy_bh - destroy the bh (synchronous)
  68. * @bh: pointer to bottom
  69. * Return: none
  70. */
  71. static inline void qdf_destroy_bh(qdf_bh_t *bh)
  72. {
  73. __qdf_disable_bh(bh);
  74. }
  75. /*********************Non-Interrupt Context deferred Execution***************/
  76. /**
  77. * qdf_create_work - create a work/task queue, This runs in non-interrupt
  78. * context, so can be preempted by H/W & S/W intr
  79. * @hdl: OS handle
  80. * @work: pointer to work
  81. * @func: deferred function to run at bottom half non-interrupt context.
  82. * @arg: argument for the deferred function
  83. *
  84. * Return: QDF status
  85. */
  86. static inline QDF_STATUS qdf_create_work(qdf_handle_t hdl, qdf_work_t *work,
  87. qdf_defer_fn_t func, void *arg)
  88. {
  89. return __qdf_init_work(work, func, arg);
  90. }
  91. /**
  92. * qdf_create_workqueue - create a workqueue, This runs in non-interrupt
  93. * context, so can be preempted by H/W & S/W intr
  94. * @name: string
  95. * Return: pointer of type qdf_workqueue_t
  96. */
  97. static inline qdf_workqueue_t *qdf_create_workqueue(char *name)
  98. {
  99. return __qdf_create_workqueue(name);
  100. }
  101. /**
  102. * qdf_create_singlethread_workqueue() - create a single threaded workqueue
  103. * @name: string
  104. *
  105. * This API creates a dedicated work queue with a single worker thread to avoid
  106. * wasting unnecessary resources when works which needs to be submitted in this
  107. * queue are not very critical and frequent.
  108. *
  109. * Return: pointer of type qdf_workqueue_t
  110. */
  111. static inline qdf_workqueue_t *qdf_create_singlethread_workqueue(char *name)
  112. {
  113. return __qdf_create_singlethread_workqueue(name);
  114. }
  115. /**
  116. * qdf_alloc_high_prior_ordered_workqueue - alloc high-prior ordered workqueue
  117. * @name: string
  118. *
  119. * Return: pointer of type qdf_workqueue_t
  120. */
  121. static inline
  122. qdf_workqueue_t *qdf_alloc_high_prior_ordered_workqueue(char *name)
  123. {
  124. return __qdf_alloc_high_prior_ordered_workqueue(name);
  125. }
  126. /**
  127. * qdf_alloc_unbound_workqueue - allocate an unbound workqueue
  128. * @name: string
  129. *
  130. * Return: pointer of type qdf_workqueue_t
  131. */
  132. static inline qdf_workqueue_t *qdf_alloc_unbound_workqueue(char *name)
  133. {
  134. return __qdf_alloc_unbound_workqueue(name);
  135. }
  136. /**
  137. * qdf_queue_work - Queue the work/task
  138. * @hdl: OS handle
  139. * @wqueue: pointer to workqueue
  140. * @work: pointer to work
  141. * Return: none
  142. */
  143. static inline void
  144. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  145. {
  146. return __qdf_queue_work(wqueue, work);
  147. }
  148. /**
  149. * qdf_flush_workqueue - flush the workqueue
  150. * @hdl: OS handle
  151. * @wqueue: pointer to workqueue
  152. * Return: none
  153. */
  154. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  155. qdf_workqueue_t *wqueue)
  156. {
  157. return __qdf_flush_workqueue(wqueue);
  158. }
  159. /**
  160. * qdf_destroy_workqueue - Destroy the workqueue
  161. * @hdl: OS handle
  162. * @wqueue: pointer to workqueue
  163. * Return: none
  164. */
  165. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  166. qdf_workqueue_t *wqueue)
  167. {
  168. return __qdf_destroy_workqueue(wqueue);
  169. }
  170. /**
  171. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  172. * @hdl: OS handle
  173. * @work: pointer to work
  174. * Retrun: none
  175. */
  176. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  177. {
  178. __qdf_sched_work(work);
  179. }
  180. /**
  181. * qdf_cancel_work() - Cancel a work
  182. * @work: pointer to work
  183. *
  184. * Cancel work and wait for its execution to finish.
  185. * This function can be used even if the work re-queues
  186. * itself or migrates to another workqueue. On return
  187. * from this function, work is guaranteed to be not
  188. * pending or executing on any CPU. The caller must
  189. * ensure that the workqueue on which work was last
  190. * queued can't be destroyed before this function returns.
  191. *
  192. * Return: true if work was pending, false otherwise
  193. */
  194. static inline bool qdf_cancel_work(qdf_work_t *work)
  195. {
  196. return __qdf_cancel_work(work);
  197. }
  198. /**
  199. * qdf_flush_work - Flush a deferred task on non-interrupt context
  200. * @work: pointer to work
  201. *
  202. * Wait until work has finished execution. work is guaranteed to be
  203. * idle on return if it hasn't been requeued since flush started.
  204. *
  205. * Return: none
  206. */
  207. static inline void qdf_flush_work(qdf_work_t *work)
  208. {
  209. __qdf_flush_work(work);
  210. }
  211. /**
  212. * qdf_disable_work - disable the deferred task (synchronous)
  213. * @work: pointer to work
  214. * Return: unsigned int
  215. */
  216. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  217. {
  218. return __qdf_disable_work(work);
  219. }
  220. /**
  221. * qdf_destroy_work - destroy the deferred task (synchronous)
  222. * @hdl: OS handle
  223. * @work: pointer to work
  224. * Return: none
  225. */
  226. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  227. {
  228. __qdf_disable_work(work);
  229. }
  230. #endif /*_QDF_DEFER_H*/