qdf_defer.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /**
  27. * DOC: qdf_defer.h
  28. * This file abstracts deferred execution API's.
  29. */
  30. #ifndef __QDF_DEFER_H
  31. #define __QDF_DEFER_H
  32. #include <qdf_types.h>
  33. #include <i_qdf_defer.h>
  34. /**
  35. * TODO This implements work queues (worker threads, kernel threads etc.).
  36. * Note that there is no cancel on a scheduled work. You cannot free a work
  37. * item if its queued. You cannot know if a work item is queued or not unless
  38. * its running, hence you know its not queued.
  39. *
  40. * so if, say, a module is asked to unload itself, how exactly will it make
  41. * sure that the work's not queued, for OS'es that dont provide such a
  42. * mechanism??
  43. */
  44. /*
  45. * Representation of a work queue.
  46. */
  47. typedef __qdf_work_t qdf_work_t;
  48. typedef __qdf_delayed_work_t qdf_delayed_work_t;
  49. typedef __qdf_workqueue_t qdf_workqueue_t;
  50. /*
  51. * Representation of a bottom half.
  52. */
  53. typedef __qdf_bh_t qdf_bh_t;
  54. /**
  55. * qdf_create_bh - creates the bottom half deferred handler
  56. * @bh: pointer to bottom
  57. * @func: deferred function to run at bottom half interrupt context.
  58. * @arg: argument for the deferred function
  59. * Return: none
  60. */
  61. static inline void
  62. qdf_create_bh(qdf_bh_t *bh, qdf_defer_fn_t func, void *arg)
  63. {
  64. __qdf_init_bh(bh, func, arg);
  65. }
  66. /**
  67. * qdf_sched - schedule a bottom half (DPC)
  68. * @bh: pointer to bottom
  69. * Return: none
  70. */
  71. static inline void qdf_sched_bh(qdf_bh_t *bh)
  72. {
  73. __qdf_sched_bh(bh);
  74. }
  75. /**
  76. * qdf_destroy_bh - destroy the bh (synchronous)
  77. * @bh: pointer to bottom
  78. * Return: none
  79. */
  80. static inline void qdf_destroy_bh(qdf_bh_t *bh)
  81. {
  82. __qdf_disable_bh(bh);
  83. }
  84. /*********************Non-Interrupt Context deferred Execution***************/
  85. /**
  86. * qdf_create_work - create a work/task queue, This runs in non-interrupt
  87. * context, so can be preempted by H/W & S/W intr
  88. * @hdl: OS handle
  89. * @work: pointer to work
  90. * @func: deferred function to run at bottom half non-interrupt context.
  91. * @arg: argument for the deferred function
  92. *
  93. * Return: QDF status
  94. */
  95. static inline QDF_STATUS qdf_create_work(qdf_handle_t hdl, qdf_work_t *work,
  96. qdf_defer_fn_t func, void *arg)
  97. {
  98. return __qdf_init_work(work, func, arg);
  99. }
  100. /**
  101. * qdf_create_delayed_work - create a delayed work/task, This runs in
  102. * non-interrupt context, so can be preempted by H/W & S/W intr
  103. * @work: pointer to work
  104. * @func: deferred function to run at bottom half non-interrupt context.
  105. * @arg: argument for the deferred function
  106. * Return: none
  107. */
  108. static inline void qdf_create_delayed_work(qdf_delayed_work_t *work,
  109. qdf_defer_fn_t func,
  110. void *arg)
  111. {
  112. __qdf_init_delayed_work(work, func, arg);
  113. }
  114. /**
  115. * qdf_create_workqueue - create a workqueue, This runs in non-interrupt
  116. * context, so can be preempted by H/W & S/W intr
  117. * @name: string
  118. * Return: pointer of type qdf_workqueue_t
  119. */
  120. static inline qdf_workqueue_t *qdf_create_workqueue(char *name)
  121. {
  122. return __qdf_create_workqueue(name);
  123. }
  124. /**
  125. * qdf_create_singlethread_workqueue() - create a single threaded workqueue
  126. * @name: string
  127. *
  128. * This API creates a dedicated work queue with a single worker thread to avoid
  129. * wasting unnecessary resources when works which needs to be submitted in this
  130. * queue are not very critical and frequent.
  131. *
  132. * Return: pointer of type qdf_workqueue_t
  133. */
  134. static inline qdf_workqueue_t *qdf_create_singlethread_workqueue(char *name)
  135. {
  136. return __qdf_create_singlethread_workqueue(name);
  137. }
  138. /**
  139. * qdf_queue_work - Queue the work/task
  140. * @hdl: OS handle
  141. * @wqueue: pointer to workqueue
  142. * @work: pointer to work
  143. * Return: none
  144. */
  145. static inline void
  146. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  147. {
  148. return __qdf_queue_work(wqueue, work);
  149. }
  150. /**
  151. * qdf_queue_delayed_work - Queue the delayed work/task
  152. * @wqueue: pointer to workqueue
  153. * @work: pointer to work
  154. * @delay: delay interval in milliseconds
  155. * Return: none
  156. */
  157. static inline void qdf_queue_delayed_work(qdf_workqueue_t *wqueue,
  158. qdf_delayed_work_t *work,
  159. uint32_t delay)
  160. {
  161. return __qdf_queue_delayed_work(wqueue, work, delay);
  162. }
  163. /**
  164. * qdf_flush_workqueue - flush the workqueue
  165. * @hdl: OS handle
  166. * @wqueue: pointer to workqueue
  167. * Return: none
  168. */
  169. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  170. qdf_workqueue_t *wqueue)
  171. {
  172. return __qdf_flush_workqueue(wqueue);
  173. }
  174. /**
  175. * qdf_destroy_workqueue - Destroy the workqueue
  176. * @hdl: OS handle
  177. * @wqueue: pointer to workqueue
  178. * Return: none
  179. */
  180. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  181. qdf_workqueue_t *wqueue)
  182. {
  183. return __qdf_destroy_workqueue(wqueue);
  184. }
  185. /**
  186. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  187. * @hdl: OS handle
  188. * @work: pointer to work
  189. * Retrun: none
  190. */
  191. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  192. {
  193. __qdf_sched_work(work);
  194. }
  195. /**
  196. * qdf_sched_delayed_work() - Schedule a delayed task
  197. * @work: pointer to delayed work
  198. * @delay: delay interval in milliseconds
  199. * Return: none
  200. */
  201. static inline void
  202. qdf_sched_delayed_work(qdf_delayed_work_t *work, uint32_t delay)
  203. {
  204. __qdf_sched_delayed_work(work, delay);
  205. }
  206. /**
  207. * qdf_cancel_work() - Cancel a work
  208. * @work: pointer to work
  209. *
  210. * Cancel work and wait for its execution to finish.
  211. * This function can be used even if the work re-queues
  212. * itself or migrates to another workqueue. On return
  213. * from this function, work is guaranteed to be not
  214. * pending or executing on any CPU. The caller must
  215. * ensure that the workqueue on which work was last
  216. * queued can't be destroyed before this function returns.
  217. *
  218. * Return: true if work was pending, false otherwise
  219. */
  220. static inline bool qdf_cancel_work(qdf_work_t *work)
  221. {
  222. return __qdf_cancel_work(work);
  223. }
  224. /**
  225. * qdf_cancel_delayed_work() - Cancel a delayed work
  226. * @work: pointer to delayed work
  227. *
  228. * This is qdf_cancel_work for delayed works.
  229. *
  230. * Return: true if work was pending, false otherwise
  231. */
  232. static inline bool qdf_cancel_delayed_work(qdf_delayed_work_t *work)
  233. {
  234. return __qdf_cancel_delayed_work(work);
  235. }
  236. /**
  237. * qdf_flush_work - Flush a deferred task on non-interrupt context
  238. * @work: pointer to work
  239. *
  240. * Wait until work has finished execution. work is guaranteed to be
  241. * idle on return if it hasn't been requeued since flush started.
  242. *
  243. * Return: none
  244. */
  245. static inline void qdf_flush_work(qdf_work_t *work)
  246. {
  247. __qdf_flush_work(work);
  248. }
  249. /**
  250. * qdf_flush_delayed_work() - Flush a delayed work
  251. * @work: pointer to delayed work
  252. *
  253. * This is qdf_flush_work for delayed works.
  254. *
  255. * Return: none
  256. */
  257. static inline void qdf_flush_delayed_work(qdf_delayed_work_t *work)
  258. {
  259. __qdf_flush_delayed_work(work);
  260. }
  261. /**
  262. * qdf_disable_work - disable the deferred task (synchronous)
  263. * @work: pointer to work
  264. * Return: unsigned int
  265. */
  266. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  267. {
  268. return __qdf_disable_work(work);
  269. }
  270. /**
  271. * qdf_destroy_work - destroy the deferred task (synchronous)
  272. * @hdl: OS handle
  273. * @work: pointer to work
  274. * Return: none
  275. */
  276. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  277. {
  278. __qdf_disable_work(work);
  279. }
  280. #endif /*_QDF_DEFER_H*/