1 /* 2 * Copyright (c) 2014-2019 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 /** 20 * DOC: i_qdf_defer.h 21 * This file provides OS dependent deferred API's. 22 */ 23 24 #ifndef _I_QDF_DEFER_H 25 #define _I_QDF_DEFER_H 26 27 #include <linux/workqueue.h> 28 #include <linux/interrupt.h> 29 #include <qdf_types.h> 30 #include <qdf_status.h> 31 #include <qdf_trace.h> 32 33 typedef struct tasklet_struct __qdf_bh_t; 34 typedef struct workqueue_struct __qdf_workqueue_t; 35 36 /** 37 * __qdf_work_t - wrapper around the real task func 38 * @work: Instance of work 39 * @fn: function pointer to the handler 40 * @arg: pointer to argument 41 */ 42 typedef struct { 43 struct work_struct work; 44 qdf_defer_fn_t fn; 45 void *arg; 46 } __qdf_work_t; 47 48 extern void __qdf_defer_func(struct work_struct *work); 49 50 typedef void (*__qdf_bh_fn_t)(unsigned long arg); 51 52 /** 53 * __qdf_init_work - Initialize a work/task queue, This runs in non-interrupt 54 * context, so can be preempted by H/W & S/W intr 55 * @work: pointer to work 56 * @func: deferred function to run at bottom half non-interrupt context. 57 * @arg: argument for the deferred function 58 * Return: none 59 */ 60 static inline QDF_STATUS 61 __qdf_init_work(__qdf_work_t *work, qdf_defer_fn_t func, void *arg) 62 { 63 work->fn = func; 64 work->arg = arg; 65 INIT_WORK(&work->work, __qdf_defer_func); 66 return QDF_STATUS_SUCCESS; 67 } 68 69 /** 70 * __qdf_queue_work - Queue the work/task 71 * @wqueue: pointer to workqueue 72 * @work: pointer to work 73 * Return: none 74 */ 75 static inline void 76 __qdf_queue_work(__qdf_workqueue_t *wqueue, __qdf_work_t *work) 77 { 78 queue_work(wqueue, &work->work); 79 } 80 81 /** 82 * __qdf_sched_work - Schedule a deferred task on non-interrupt context 83 * @work: pointer to work 84 * Retrun: none 85 */ 86 static inline QDF_STATUS __qdf_sched_work(__qdf_work_t *work) 87 { 88 schedule_work(&work->work); 89 return QDF_STATUS_SUCCESS; 90 } 91 92 /** 93 * __qdf_cancel_work() - Cancel a work 94 * @work: pointer to work 95 * Return: true if work was pending, false otherwise 96 */ 97 static inline bool __qdf_cancel_work(__qdf_work_t *work) 98 { 99 return cancel_work_sync(&work->work); 100 } 101 102 /** 103 * __qdf_flush_work - Flush a deferred task on non-interrupt context 104 * @work: pointer to work 105 * Return: none 106 */ 107 static inline uint32_t __qdf_flush_work(__qdf_work_t *work) 108 { 109 flush_work(&work->work); 110 return QDF_STATUS_SUCCESS; 111 } 112 113 /** 114 * __qdf_create_workqueue - create a workqueue, This runs in non-interrupt 115 * context, so can be preempted by H/W & S/W intr 116 * @name: string 117 * Return: pointer of type qdf_workqueue_t 118 */ 119 static inline __qdf_workqueue_t *__qdf_create_workqueue(char *name) 120 { 121 return create_workqueue(name); 122 } 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 create_singlethread_workqueue(name); 137 } 138 139 /** 140 * __qdf_alloc_unbound_workqueue - alloc an unbound workqueue 141 * @name: string 142 * 143 * Return: pointer of type qdf_workqueue_t 144 */ 145 static inline __qdf_workqueue_t *__qdf_alloc_unbound_workqueue(char *name) 146 { 147 return alloc_workqueue(name, WQ_UNBOUND, 0); 148 } 149 150 /** 151 * __qdf_flush_workqueue - flush the workqueue 152 * @wqueue: pointer to workqueue 153 * Return: none 154 */ 155 static inline void __qdf_flush_workqueue(__qdf_workqueue_t *wqueue) 156 { 157 flush_workqueue(wqueue); 158 } 159 160 /** 161 * __qdf_destroy_workqueue - Destroy the workqueue 162 * @wqueue: pointer to workqueue 163 * Return: none 164 */ 165 static inline void __qdf_destroy_workqueue(__qdf_workqueue_t *wqueue) 166 { 167 destroy_workqueue(wqueue); 168 } 169 170 /** 171 * __qdf_init_bh - creates the Bottom half deferred handler 172 * @bh: pointer to bottom 173 * @func: deferred function to run at bottom half interrupt context. 174 * @arg: argument for the deferred function 175 * Return: none 176 */ 177 static inline QDF_STATUS 178 __qdf_init_bh(struct tasklet_struct *bh, qdf_defer_fn_t func, void *arg) 179 { 180 tasklet_init(bh, (__qdf_bh_fn_t) func, (unsigned long)arg); 181 return QDF_STATUS_SUCCESS; 182 } 183 184 /** 185 * __qdf_sched_bh - schedule a bottom half (DPC) 186 * @bh: pointer to bottom 187 * Return: none 188 */ 189 static inline QDF_STATUS __qdf_sched_bh(struct tasklet_struct *bh) 190 { 191 tasklet_schedule(bh); 192 return QDF_STATUS_SUCCESS; 193 } 194 195 /** 196 * __qdf_disable_work - disable the deferred task (synchronous) 197 * @work: pointer to work 198 * Return: unsigned int 199 */ 200 static inline QDF_STATUS __qdf_disable_work(__qdf_work_t *work) 201 { 202 if (cancel_work_sync(&work->work)) 203 return QDF_STATUS_E_ALREADY; 204 205 return QDF_STATUS_SUCCESS; 206 } 207 208 /** 209 * __qdf_disable_bh - destroy the bh (synchronous) 210 * @bh: pointer to bottom 211 * Return: none 212 */ 213 static inline QDF_STATUS __qdf_disable_bh(struct tasklet_struct *bh) 214 { 215 tasklet_kill(bh); 216 return QDF_STATUS_SUCCESS; 217 } 218 219 #endif /*_I_QDF_DEFER_H*/ 220