qdf_defer.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2014-2017 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_queue_work - Queue the work/task
  132. * @hdl: OS handle
  133. * @wqueue: pointer to workqueue
  134. * @work: pointer to work
  135. * Return: none
  136. */
  137. static inline void
  138. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  139. {
  140. return __qdf_queue_work(wqueue, work);
  141. }
  142. /**
  143. * qdf_queue_delayed_work - Queue the delayed work/task
  144. * @wqueue: pointer to workqueue
  145. * @work: pointer to work
  146. * @delay: delay interval in milliseconds
  147. * Return: none
  148. */
  149. static inline void qdf_queue_delayed_work(qdf_workqueue_t *wqueue,
  150. qdf_delayed_work_t *work,
  151. uint32_t delay)
  152. {
  153. return __qdf_queue_delayed_work(wqueue, work, delay);
  154. }
  155. /**
  156. * qdf_flush_workqueue - flush the workqueue
  157. * @hdl: OS handle
  158. * @wqueue: pointer to workqueue
  159. * Return: none
  160. */
  161. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  162. qdf_workqueue_t *wqueue)
  163. {
  164. return __qdf_flush_workqueue(wqueue);
  165. }
  166. /**
  167. * qdf_destroy_workqueue - Destroy the workqueue
  168. * @hdl: OS handle
  169. * @wqueue: pointer to workqueue
  170. * Return: none
  171. */
  172. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  173. qdf_workqueue_t *wqueue)
  174. {
  175. return __qdf_destroy_workqueue(wqueue);
  176. }
  177. /**
  178. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  179. * @hdl: OS handle
  180. * @work: pointer to work
  181. * Retrun: none
  182. */
  183. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  184. {
  185. __qdf_sched_work(work);
  186. }
  187. /**
  188. * qdf_sched_delayed_work() - Schedule a delayed task
  189. * @work: pointer to delayed work
  190. * @delay: delay interval in milliseconds
  191. * Return: none
  192. */
  193. static inline void
  194. qdf_sched_delayed_work(qdf_delayed_work_t *work, uint32_t delay)
  195. {
  196. __qdf_sched_delayed_work(work, delay);
  197. }
  198. /**
  199. * qdf_cancel_work() - Cancel a work
  200. * @work: pointer to work
  201. *
  202. * Cancel work and wait for its execution to finish.
  203. * This function can be used even if the work re-queues
  204. * itself or migrates to another workqueue. On return
  205. * from this function, work is guaranteed to be not
  206. * pending or executing on any CPU. The caller must
  207. * ensure that the workqueue on which work was last
  208. * queued can't be destroyed before this function returns.
  209. *
  210. * Return: true if work was pending, false otherwise
  211. */
  212. static inline bool qdf_cancel_work(qdf_work_t *work)
  213. {
  214. return __qdf_cancel_work(work);
  215. }
  216. /**
  217. * qdf_cancel_delayed_work() - Cancel a delayed work
  218. * @work: pointer to delayed work
  219. *
  220. * This is qdf_cancel_work for delayed works.
  221. *
  222. * Return: true if work was pending, false otherwise
  223. */
  224. static inline bool qdf_cancel_delayed_work(qdf_delayed_work_t *work)
  225. {
  226. return __qdf_cancel_delayed_work(work);
  227. }
  228. /**
  229. * qdf_flush_work - Flush a deferred task on non-interrupt context
  230. * @work: pointer to work
  231. *
  232. * Wait until work has finished execution. work is guaranteed to be
  233. * idle on return if it hasn't been requeued since flush started.
  234. *
  235. * Return: none
  236. */
  237. static inline void qdf_flush_work(qdf_work_t *work)
  238. {
  239. __qdf_flush_work(work);
  240. }
  241. /**
  242. * qdf_flush_delayed_work() - Flush a delayed work
  243. * @work: pointer to delayed work
  244. *
  245. * This is qdf_flush_work for delayed works.
  246. *
  247. * Return: none
  248. */
  249. static inline void qdf_flush_delayed_work(qdf_delayed_work_t *work)
  250. {
  251. __qdf_flush_delayed_work(work);
  252. }
  253. /**
  254. * qdf_disable_work - disable the deferred task (synchronous)
  255. * @work: pointer to work
  256. * Return: unsigned int
  257. */
  258. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  259. {
  260. return __qdf_disable_work(work);
  261. }
  262. /**
  263. * qdf_destroy_work - destroy the deferred task (synchronous)
  264. * @hdl: OS handle
  265. * @work: pointer to work
  266. * Return: none
  267. */
  268. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  269. {
  270. __qdf_disable_work(work);
  271. }
  272. #endif /*_QDF_DEFER_H*/