qdf_defer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * Copyright (c) 2014-2021 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. #ifdef ENHANCED_OS_ABSTRACTION
  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. void
  54. qdf_create_bh(qdf_bh_t *bh, qdf_defer_fn_t func, void *arg);
  55. /**
  56. * qdf_sched - schedule a bottom half (DPC)
  57. * @bh: pointer to bottom
  58. * Return: none
  59. */
  60. void qdf_sched_bh(qdf_bh_t *bh);
  61. /**
  62. * qdf_destroy_bh - destroy the bh (synchronous)
  63. * @bh: pointer to bottom
  64. * Return: none
  65. */
  66. void qdf_destroy_bh(qdf_bh_t *bh);
  67. /**
  68. * qdf_create_workqueue - create a workqueue, This runs in non-interrupt
  69. * context, so can be preempted by H/W & S/W intr
  70. * @name: string
  71. *
  72. * Return: pointer of type qdf_workqueue_t
  73. */
  74. qdf_workqueue_t *qdf_create_workqueue(char *name);
  75. /**
  76. * qdf_create_singlethread_workqueue() - create a single threaded workqueue
  77. * @name: string
  78. *
  79. * This API creates a dedicated work queue with a single worker thread to avoid
  80. * wasting unnecessary resources when works which needs to be submitted in this
  81. * queue are not very critical and frequent.
  82. *
  83. * Return: pointer of type qdf_workqueue_t
  84. */
  85. qdf_workqueue_t *qdf_create_singlethread_workqueue(char *name);
  86. /**
  87. * qdf_alloc_unbound_workqueue - allocate an unbound workqueue
  88. * @name: string
  89. *
  90. * Return: pointer of type qdf_workqueue_t
  91. */
  92. qdf_workqueue_t *qdf_alloc_unbound_workqueue(char *name);
  93. /**
  94. * qdf_destroy_workqueue - Destroy the workqueue
  95. * @hdl: OS handle
  96. * @wqueue: pointer to workqueue
  97. *
  98. * Return: none
  99. */
  100. void qdf_destroy_workqueue(qdf_handle_t hdl, qdf_workqueue_t *wqueue);
  101. /**
  102. * qdf_cancel_work() - Cancel a work
  103. * @work: pointer to work
  104. *
  105. * Cancel work and wait for its execution to finish.
  106. * This function can be used even if the work re-queues
  107. * itself or migrates to another workqueue. On return
  108. * from this function, work is guaranteed to be not
  109. * pending or executing on any CPU. The caller must
  110. * ensure that the workqueue on which work was last
  111. * queued can't be destroyed before this function returns.
  112. *
  113. * Return: true if work was pending, false otherwise
  114. */
  115. bool qdf_cancel_work(qdf_work_t *work);
  116. /**
  117. * qdf_disable_work - disable the deferred task (synchronous)
  118. * @work: pointer to work
  119. *
  120. * Return: unsigned int
  121. */
  122. uint32_t qdf_disable_work(qdf_work_t *work);
  123. /**
  124. * qdf_flush_work - Flush a deferred task on non-interrupt context
  125. * @work: pointer to work
  126. *
  127. * Wait until work has finished execution. work is guaranteed to be
  128. * idle on return if it hasn't been requeued since flush started.
  129. *
  130. * Return: none
  131. */
  132. void qdf_flush_work(qdf_work_t *work);
  133. /**
  134. * qdf_create_work - create a work/task queue, This runs in non-interrupt
  135. * context, so can be preempted by H/W & S/W intr
  136. * @hdl: OS handle
  137. * @work: pointer to work
  138. * @func: deferred function to run at bottom half non-interrupt context.
  139. * @arg: argument for the deferred function
  140. *
  141. * Return: QDF status
  142. */
  143. QDF_STATUS qdf_create_work(qdf_handle_t hdl, qdf_work_t *work,
  144. qdf_defer_fn_t func, void *arg);
  145. /**
  146. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  147. * @hdl: OS handle
  148. * @work: pointer to work
  149. *
  150. * Retrun: none
  151. */
  152. void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work);
  153. /**
  154. * qdf_queue_work - Queue the work/task
  155. * @hdl: OS handle
  156. * @wqueue: pointer to workqueue
  157. * @work: pointer to work
  158. *
  159. * Return: false if work was already on a queue, true otherwise
  160. */
  161. bool
  162. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work);
  163. /**
  164. * qdf_flush_workqueue - flush the workqueue
  165. * @hdl: OS handle
  166. * @wqueue: pointer to workqueue
  167. *
  168. * Return: none
  169. */
  170. void qdf_flush_workqueue(qdf_handle_t hdl, qdf_workqueue_t *wqueue);
  171. /**
  172. * qdf_destroy_work - destroy the deferred task (synchronous)
  173. * @hdl: OS handle
  174. * @work: pointer to work
  175. *
  176. * Return: none
  177. */
  178. void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work);
  179. #else
  180. /**
  181. * qdf_create_bh - creates the bottom half deferred handler
  182. * @bh: pointer to bottom
  183. * @func: deferred function to run at bottom half interrupt context.
  184. * @arg: argument for the deferred function
  185. * Return: none
  186. */
  187. static inline void
  188. qdf_create_bh(qdf_bh_t *bh, qdf_defer_fn_t func, void *arg)
  189. {
  190. __qdf_init_bh(bh, func, arg);
  191. }
  192. /**
  193. * qdf_sched - schedule a bottom half (DPC)
  194. * @bh: pointer to bottom
  195. * Return: none
  196. */
  197. static inline void qdf_sched_bh(qdf_bh_t *bh)
  198. {
  199. __qdf_sched_bh(bh);
  200. }
  201. /**
  202. * qdf_destroy_bh - destroy the bh (synchronous)
  203. * @bh: pointer to bottom
  204. * Return: none
  205. */
  206. static inline void qdf_destroy_bh(qdf_bh_t *bh)
  207. {
  208. __qdf_disable_bh(bh);
  209. }
  210. /*********************Non-Interrupt Context deferred Execution***************/
  211. /**
  212. * qdf_create_work - create a work/task queue, This runs in non-interrupt
  213. * context, so can be preempted by H/W & S/W intr
  214. * @hdl: OS handle
  215. * @work: pointer to work
  216. * @func: deferred function to run at bottom half non-interrupt context.
  217. * @arg: argument for the deferred function
  218. *
  219. * Return: QDF status
  220. */
  221. static inline QDF_STATUS qdf_create_work(qdf_handle_t hdl, qdf_work_t *work,
  222. qdf_defer_fn_t func, void *arg)
  223. {
  224. return __qdf_init_work(work, func, arg);
  225. }
  226. /**
  227. * qdf_create_workqueue - create a workqueue, This runs in non-interrupt
  228. * context, so can be preempted by H/W & S/W intr
  229. * @name: string
  230. * Return: pointer of type qdf_workqueue_t
  231. */
  232. static inline qdf_workqueue_t *qdf_create_workqueue(char *name)
  233. {
  234. return __qdf_create_workqueue(name);
  235. }
  236. /**
  237. * qdf_create_singlethread_workqueue() - create a single threaded workqueue
  238. * @name: string
  239. *
  240. * This API creates a dedicated work queue with a single worker thread to avoid
  241. * wasting unnecessary resources when works which needs to be submitted in this
  242. * queue are not very critical and frequent.
  243. *
  244. * Return: pointer of type qdf_workqueue_t
  245. */
  246. static inline qdf_workqueue_t *qdf_create_singlethread_workqueue(char *name)
  247. {
  248. return __qdf_create_singlethread_workqueue(name);
  249. }
  250. /**
  251. * qdf_alloc_high_prior_ordered_workqueue - alloc high-prior ordered workqueue
  252. * @name: string
  253. *
  254. * Return: pointer of type qdf_workqueue_t
  255. */
  256. static inline
  257. qdf_workqueue_t *qdf_alloc_high_prior_ordered_workqueue(char *name)
  258. {
  259. return __qdf_alloc_high_prior_ordered_workqueue(name);
  260. }
  261. /**
  262. * qdf_alloc_unbound_workqueue - allocate an unbound workqueue
  263. * @name: string
  264. *
  265. * Return: pointer of type qdf_workqueue_t
  266. */
  267. static inline qdf_workqueue_t *qdf_alloc_unbound_workqueue(char *name)
  268. {
  269. return __qdf_alloc_unbound_workqueue(name);
  270. }
  271. /**
  272. * qdf_queue_work - Queue the work/task
  273. * @hdl: OS handle
  274. * @wqueue: pointer to workqueue
  275. * @work: pointer to work
  276. * Return: false if work was already on a queue, true otherwise
  277. */
  278. static inline bool
  279. qdf_queue_work(qdf_handle_t hdl, qdf_workqueue_t *wqueue, qdf_work_t *work)
  280. {
  281. return __qdf_queue_work(wqueue, work);
  282. }
  283. /**
  284. * qdf_flush_workqueue - flush the workqueue
  285. * @hdl: OS handle
  286. * @wqueue: pointer to workqueue
  287. * Return: none
  288. */
  289. static inline void qdf_flush_workqueue(qdf_handle_t hdl,
  290. qdf_workqueue_t *wqueue)
  291. {
  292. return __qdf_flush_workqueue(wqueue);
  293. }
  294. /**
  295. * qdf_destroy_workqueue - Destroy the workqueue
  296. * @hdl: OS handle
  297. * @wqueue: pointer to workqueue
  298. * Return: none
  299. */
  300. static inline void qdf_destroy_workqueue(qdf_handle_t hdl,
  301. qdf_workqueue_t *wqueue)
  302. {
  303. return __qdf_destroy_workqueue(wqueue);
  304. }
  305. /**
  306. * qdf_sched_work - Schedule a deferred task on non-interrupt context
  307. * @hdl: OS handle
  308. * @work: pointer to work
  309. * Retrun: none
  310. */
  311. static inline void qdf_sched_work(qdf_handle_t hdl, qdf_work_t *work)
  312. {
  313. __qdf_sched_work(work);
  314. }
  315. /**
  316. * qdf_cancel_work() - Cancel a work
  317. * @work: pointer to work
  318. *
  319. * Cancel work and wait for its execution to finish.
  320. * This function can be used even if the work re-queues
  321. * itself or migrates to another workqueue. On return
  322. * from this function, work is guaranteed to be not
  323. * pending or executing on any CPU. The caller must
  324. * ensure that the workqueue on which work was last
  325. * queued can't be destroyed before this function returns.
  326. *
  327. * Return: true if work was pending, false otherwise
  328. */
  329. static inline bool qdf_cancel_work(qdf_work_t *work)
  330. {
  331. return __qdf_cancel_work(work);
  332. }
  333. /**
  334. * qdf_flush_work - Flush a deferred task on non-interrupt context
  335. * @work: pointer to work
  336. *
  337. * Wait until work has finished execution. work is guaranteed to be
  338. * idle on return if it hasn't been requeued since flush started.
  339. *
  340. * Return: none
  341. */
  342. static inline void qdf_flush_work(qdf_work_t *work)
  343. {
  344. __qdf_flush_work(work);
  345. }
  346. /**
  347. * qdf_disable_work - disable the deferred task (synchronous)
  348. * @work: pointer to work
  349. * Return: unsigned int
  350. */
  351. static inline uint32_t qdf_disable_work(qdf_work_t *work)
  352. {
  353. return __qdf_disable_work(work);
  354. }
  355. /**
  356. * qdf_destroy_work - destroy the deferred task (synchronous)
  357. * @hdl: OS handle
  358. * @work: pointer to work
  359. * Return: none
  360. */
  361. static inline void qdf_destroy_work(qdf_handle_t hdl, qdf_work_t *work)
  362. {
  363. __qdf_disable_work(work);
  364. }
  365. #endif
  366. #endif /*_QDF_DEFER_H*/