qdf_defer.h 8.4 KB

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