qdf_defer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) 2014-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. /**
  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_unbound_workqueue - allocate an unbound workqueue
  117. * @name: string
  118. *
  119. * Return: pointer of type qdf_workqueue_t
  120. */
  121. static inline qdf_workqueue_t *qdf_alloc_unbound_workqueue(char *name)
  122. {
  123. return __qdf_alloc_unbound_workqueue(name);
  124. }
  125. /**
  126. * qdf_queue_work - Queue the work/task
  127. * @hdl: OS handle
  128. * @wqueue: pointer to workqueue
  129. * @work: pointer to work
  130. * Return: none
  131. */
  132. static inline void
  133. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  134. {
  135. return __qdf_queue_work(wqueue, work);
  136. }
  137. /**
  138. * qdf_flush_workqueue - flush the workqueue
  139. * @hdl: OS handle
  140. * @wqueue: pointer to workqueue
  141. * Return: none
  142. */
  143. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  144. qdf_workqueue_t *wqueue)
  145. {
  146. return __qdf_flush_workqueue(wqueue);
  147. }
  148. /**
  149. * qdf_destroy_workqueue - Destroy the workqueue
  150. * @hdl: OS handle
  151. * @wqueue: pointer to workqueue
  152. * Return: none
  153. */
  154. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  155. qdf_workqueue_t *wqueue)
  156. {
  157. return __qdf_destroy_workqueue(wqueue);
  158. }
  159. /**
  160. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  161. * @hdl: OS handle
  162. * @work: pointer to work
  163. * Retrun: none
  164. */
  165. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  166. {
  167. __qdf_sched_work(work);
  168. }
  169. /**
  170. * qdf_cancel_work() - Cancel a work
  171. * @work: pointer to work
  172. *
  173. * Cancel work and wait for its execution to finish.
  174. * This function can be used even if the work re-queues
  175. * itself or migrates to another workqueue. On return
  176. * from this function, work is guaranteed to be not
  177. * pending or executing on any CPU. The caller must
  178. * ensure that the workqueue on which work was last
  179. * queued can't be destroyed before this function returns.
  180. *
  181. * Return: true if work was pending, false otherwise
  182. */
  183. static inline bool qdf_cancel_work(qdf_work_t *work)
  184. {
  185. return __qdf_cancel_work(work);
  186. }
  187. /**
  188. * qdf_flush_work - Flush a deferred task on non-interrupt context
  189. * @work: pointer to work
  190. *
  191. * Wait until work has finished execution. work is guaranteed to be
  192. * idle on return if it hasn't been requeued since flush started.
  193. *
  194. * Return: none
  195. */
  196. static inline void qdf_flush_work(qdf_work_t *work)
  197. {
  198. __qdf_flush_work(work);
  199. }
  200. /**
  201. * qdf_disable_work - disable the deferred task (synchronous)
  202. * @work: pointer to work
  203. * Return: unsigned int
  204. */
  205. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  206. {
  207. return __qdf_disable_work(work);
  208. }
  209. /**
  210. * qdf_destroy_work - destroy the deferred task (synchronous)
  211. * @hdl: OS handle
  212. * @work: pointer to work
  213. * Return: none
  214. */
  215. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  216. {
  217. __qdf_disable_work(work);
  218. }
  219. #endif /*_QDF_DEFER_H*/