qdf_defer.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Copyright (c) 2014-2018 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_delayed_work_t qdf_delayed_work_t;
  41. typedef __qdf_workqueue_t qdf_workqueue_t;
  42. /*
  43. * Representation of a bottom half.
  44. */
  45. typedef __qdf_bh_t qdf_bh_t;
  46. /**
  47. * qdf_create_bh - creates the bottom half deferred handler
  48. * @bh: pointer to bottom
  49. * @func: deferred function to run at bottom half interrupt context.
  50. * @arg: argument for the deferred function
  51. * Return: none
  52. */
  53. static inline void
  54. qdf_create_bh(qdf_bh_t *bh, qdf_defer_fn_t func, void *arg)
  55. {
  56. __qdf_init_bh(bh, func, arg);
  57. }
  58. /**
  59. * qdf_sched - schedule a bottom half (DPC)
  60. * @bh: pointer to bottom
  61. * Return: none
  62. */
  63. static inline void qdf_sched_bh(qdf_bh_t *bh)
  64. {
  65. __qdf_sched_bh(bh);
  66. }
  67. /**
  68. * qdf_destroy_bh - destroy the bh (synchronous)
  69. * @bh: pointer to bottom
  70. * Return: none
  71. */
  72. static inline void qdf_destroy_bh(qdf_bh_t *bh)
  73. {
  74. __qdf_disable_bh(bh);
  75. }
  76. /*********************Non-Interrupt Context deferred Execution***************/
  77. /**
  78. * qdf_create_work - create a work/task queue, This runs in non-interrupt
  79. * context, so can be preempted by H/W & S/W intr
  80. * @hdl: OS handle
  81. * @work: pointer to work
  82. * @func: deferred function to run at bottom half non-interrupt context.
  83. * @arg: argument for the deferred function
  84. *
  85. * Return: QDF status
  86. */
  87. static inline QDF_STATUS qdf_create_work(qdf_handle_t hdl, qdf_work_t *work,
  88. qdf_defer_fn_t func, void *arg)
  89. {
  90. return __qdf_init_work(work, func, arg);
  91. }
  92. /**
  93. * qdf_create_delayed_work - create a delayed work/task, This runs in
  94. * non-interrupt context, so can be preempted by H/W & S/W intr
  95. * @work: pointer to work
  96. * @func: deferred function to run at bottom half non-interrupt context.
  97. * @arg: argument for the deferred function
  98. * Return: none
  99. */
  100. static inline void qdf_create_delayed_work(qdf_delayed_work_t *work,
  101. qdf_defer_fn_t func,
  102. void *arg)
  103. {
  104. __qdf_init_delayed_work(work, func, arg);
  105. }
  106. /**
  107. * qdf_create_workqueue - create a workqueue, This runs in non-interrupt
  108. * context, so can be preempted by H/W & S/W intr
  109. * @name: string
  110. * Return: pointer of type qdf_workqueue_t
  111. */
  112. static inline qdf_workqueue_t *qdf_create_workqueue(char *name)
  113. {
  114. return __qdf_create_workqueue(name);
  115. }
  116. /**
  117. * qdf_create_singlethread_workqueue() - create a single threaded workqueue
  118. * @name: string
  119. *
  120. * This API creates a dedicated work queue with a single worker thread to avoid
  121. * wasting unnecessary resources when works which needs to be submitted in this
  122. * queue are not very critical and frequent.
  123. *
  124. * Return: pointer of type qdf_workqueue_t
  125. */
  126. static inline qdf_workqueue_t *qdf_create_singlethread_workqueue(char *name)
  127. {
  128. return __qdf_create_singlethread_workqueue(name);
  129. }
  130. /**
  131. * qdf_alloc_unbound_workqueue - allocate an unbound workqueue
  132. * @name: string
  133. *
  134. * Return: pointer of type qdf_workqueue_t
  135. */
  136. static inline qdf_workqueue_t *qdf_alloc_unbound_workqueue(char *name)
  137. {
  138. return __qdf_alloc_unbound_workqueue(name);
  139. }
  140. /**
  141. * qdf_queue_work - Queue the work/task
  142. * @hdl: OS handle
  143. * @wqueue: pointer to workqueue
  144. * @work: pointer to work
  145. * Return: none
  146. */
  147. static inline void
  148. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  149. {
  150. return __qdf_queue_work(wqueue, work);
  151. }
  152. /**
  153. * qdf_queue_delayed_work - Queue the delayed work/task
  154. * @wqueue: pointer to workqueue
  155. * @work: pointer to work
  156. * @delay: delay interval in milliseconds
  157. * Return: none
  158. */
  159. static inline void qdf_queue_delayed_work(qdf_workqueue_t *wqueue,
  160. qdf_delayed_work_t *work,
  161. uint32_t delay)
  162. {
  163. return __qdf_queue_delayed_work(wqueue, work, delay);
  164. }
  165. /**
  166. * qdf_flush_workqueue - flush the workqueue
  167. * @hdl: OS handle
  168. * @wqueue: pointer to workqueue
  169. * Return: none
  170. */
  171. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  172. qdf_workqueue_t *wqueue)
  173. {
  174. return __qdf_flush_workqueue(wqueue);
  175. }
  176. /**
  177. * qdf_destroy_workqueue - Destroy the workqueue
  178. * @hdl: OS handle
  179. * @wqueue: pointer to workqueue
  180. * Return: none
  181. */
  182. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  183. qdf_workqueue_t *wqueue)
  184. {
  185. return __qdf_destroy_workqueue(wqueue);
  186. }
  187. /**
  188. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  189. * @hdl: OS handle
  190. * @work: pointer to work
  191. * Retrun: none
  192. */
  193. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  194. {
  195. __qdf_sched_work(work);
  196. }
  197. /**
  198. * qdf_sched_delayed_work() - Schedule a delayed task
  199. * @work: pointer to delayed work
  200. * @delay: delay interval in milliseconds
  201. * Return: none
  202. */
  203. static inline void
  204. qdf_sched_delayed_work(qdf_delayed_work_t *work, uint32_t delay)
  205. {
  206. __qdf_sched_delayed_work(work, delay);
  207. }
  208. /**
  209. * qdf_cancel_work() - Cancel a work
  210. * @work: pointer to work
  211. *
  212. * Cancel work and wait for its execution to finish.
  213. * This function can be used even if the work re-queues
  214. * itself or migrates to another workqueue. On return
  215. * from this function, work is guaranteed to be not
  216. * pending or executing on any CPU. The caller must
  217. * ensure that the workqueue on which work was last
  218. * queued can't be destroyed before this function returns.
  219. *
  220. * Return: true if work was pending, false otherwise
  221. */
  222. static inline bool qdf_cancel_work(qdf_work_t *work)
  223. {
  224. return __qdf_cancel_work(work);
  225. }
  226. /**
  227. * qdf_cancel_delayed_work() - Cancel a delayed work
  228. * @work: pointer to delayed work
  229. *
  230. * This is qdf_cancel_work for delayed works.
  231. *
  232. * Return: true if work was pending, false otherwise
  233. */
  234. static inline bool qdf_cancel_delayed_work(qdf_delayed_work_t *work)
  235. {
  236. return __qdf_cancel_delayed_work(work);
  237. }
  238. /**
  239. * qdf_flush_work - Flush a deferred task on non-interrupt context
  240. * @work: pointer to work
  241. *
  242. * Wait until work has finished execution. work is guaranteed to be
  243. * idle on return if it hasn't been requeued since flush started.
  244. *
  245. * Return: none
  246. */
  247. static inline void qdf_flush_work(qdf_work_t *work)
  248. {
  249. __qdf_flush_work(work);
  250. }
  251. /**
  252. * qdf_flush_delayed_work() - Flush a delayed work
  253. * @work: pointer to delayed work
  254. *
  255. * This is qdf_flush_work for delayed works.
  256. *
  257. * Return: none
  258. */
  259. static inline void qdf_flush_delayed_work(qdf_delayed_work_t *work)
  260. {
  261. __qdf_flush_delayed_work(work);
  262. }
  263. /**
  264. * qdf_disable_work - disable the deferred task (synchronous)
  265. * @work: pointer to work
  266. * Return: unsigned int
  267. */
  268. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  269. {
  270. return __qdf_disable_work(work);
  271. }
  272. /**
  273. * qdf_destroy_work - destroy the deferred task (synchronous)
  274. * @hdl: OS handle
  275. * @work: pointer to work
  276. * Return: none
  277. */
  278. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  279. {
  280. __qdf_disable_work(work);
  281. }
  282. #endif /*_QDF_DEFER_H*/