1 /* 2 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: qdf_threads 22 * QCA driver framework (QDF) thread related APIs 23 */ 24 25 #if !defined(__QDF_THREADS_H) 26 #define __QDF_THREADS_H 27 28 #include <qdf_types.h> 29 #include "i_qdf_threads.h" 30 31 typedef __qdf_thread_t qdf_thread_t; 32 typedef QDF_STATUS (*qdf_thread_func)(void *context); 33 34 /* Function declarations and documentation */ 35 36 void qdf_sleep(uint32_t ms_interval); 37 38 void qdf_sleep_us(uint32_t us_interval); 39 40 void qdf_busy_wait(uint32_t us_interval); 41 42 /** 43 * qdf_set_wake_up_idle() - set wakeup idle value 44 * @idle: true/false value for wake up idle 45 * 46 * Return: none 47 */ 48 void qdf_set_wake_up_idle(bool idle); 49 50 /** 51 * qdf_set_user_nice() - set thread's nice value 52 * @thread: pointer to thread 53 * @nice: nice value 54 * 55 * Return: void 56 */ 57 void qdf_set_user_nice(qdf_thread_t *thread, long nice); 58 59 /** 60 * qdf_create_thread() - create a kernel thread 61 * @thread: pointer to thread 62 * @nice: nice value 63 * 64 * Return: pointer to created kernel thread on success else NULL 65 */ 66 qdf_thread_t *qdf_create_thread(int (*thread_handler)(void *data), void *data, 67 const char thread_name[]); 68 69 /** 70 * qdf_thread_run() - run the given function in a new thread 71 * 72 * You must call qdf_thread_join() to avoid a reasource leak! 73 * 74 * For more flexibility, use qdf_create_thread() instead. 75 * 76 * Return: a new qdf_thread pointer 77 */ 78 qdf_thread_t *qdf_thread_run(qdf_thread_func callback, void *context); 79 80 /** 81 * qdf_thread_join() - signal and wait for a thread to stop 82 * 83 * This sets a flag that the given thread can check to see if it should exit. 84 * The thread can check to see if this flag has been set by calling 85 * qdf_thread_should_stop(). 86 * 87 * Return: QDF_STATUS - the return value from the thread function 88 */ 89 QDF_STATUS qdf_thread_join(qdf_thread_t *thread); 90 91 /** 92 * qdf_thread_should_stop() - true if the current thread was signalled to stop 93 * 94 * If qdf_thread_join() has been called on the current thread, this API returns 95 * true. Otherwise, this returns false. 96 * 97 * Return: true if the current thread should stop 98 */ 99 bool qdf_thread_should_stop(void); 100 101 /** 102 * qdf_wake_up_process() - wake up given thread 103 * @thread: pointer to thread which needs to be woken up 104 * 105 * Return: none 106 */ 107 int qdf_wake_up_process(qdf_thread_t *thread); 108 109 /** 110 * qdf_print_stack_trace_thread() - prints the stack trace of the given thread 111 * @thread: the thread for which the stack trace will be printed 112 * 113 * Return: None 114 */ 115 void qdf_print_thread_trace(qdf_thread_t *thread); 116 117 /** 118 * qdf_get_current_task() - get current task struct 119 * 120 * Return: pointer to task struct 121 */ 122 qdf_thread_t *qdf_get_current_task(void); 123 124 /** 125 * qdf_get_current_pid() - get current task's process id 126 * 127 * Return: current task's process id (int) 128 */ 129 int qdf_get_current_pid(void); 130 131 /** 132 * qdf_get_current_comm() - get current task's command name 133 * 134 * Return: current task's command name(char *) 135 */ 136 const char *qdf_get_current_comm(void); 137 138 /** 139 * qdf_thread_set_cpus_allowed_mask() - set cpu mask for a particular thread 140 * @thread: thread for which new cpu mask is set 141 * @new_mask: new cpu mask to be set for the thread 142 * 143 * Return: None 144 */ 145 void 146 qdf_thread_set_cpus_allowed_mask(qdf_thread_t *thread, qdf_cpu_mask *new_mask); 147 148 /** 149 * qdf_cpumask_clear() - clear all cpus in a cpumask 150 * @dstp: cpumask pointer 151 * 152 * Return: None 153 */ 154 void qdf_cpumask_clear(qdf_cpu_mask *dstp); 155 156 /** 157 * qdf_cpumask_set_cpu() - set a cpu in a cpumask 158 * @cpu: cpu number 159 * @dstp: cpumask pointer 160 * 161 * Return: None 162 */ 163 void qdf_cpumask_set_cpu(unsigned int cpu, qdf_cpu_mask *dstp); 164 165 /** 166 * qdf_cpumask_setall - set all cpus 167 * @dstp: cpumask pointer 168 * 169 * Return: None 170 */ 171 void qdf_cpumask_setall(qdf_cpu_mask *dstp); 172 173 /** 174 * qdf_cpumask_clear_cpu() - clear a cpu in a cpumask 175 * @cpu: cpu number 176 * @dstp: cpumask pointer 177 * 178 * Return: None 179 */ 180 void qdf_cpumask_clear_cpu(unsigned int cpu, qdf_cpu_mask *dstp); 181 182 /** 183 * qdf_cpumask_empty - Check if cpu_mask is empty 184 * @srcp: cpumask pointer 185 * 186 * Return: true or false 187 * 188 */ 189 bool qdf_cpumask_empty(const qdf_cpu_mask *srcp); 190 191 /** 192 * qdf_cpumask_copy - Copy srcp cpumask to dstp 193 * @srcp: source cpumask pointer 194 * @dstp: destination cpumask pointer 195 * 196 * Return: None 197 * 198 */ 199 void qdf_cpumask_copy(qdf_cpu_mask *dstp, 200 const qdf_cpu_mask *srcp); 201 202 /** 203 * qdf_cpumask_or - set *dstp = *src1p | *src2p 204 * @dstp: the cpumask result 205 * @src1p: the first input 206 * @src2p: the second input 207 * 208 * Return: None 209 */ 210 void qdf_cpumask_or(qdf_cpu_mask *dstp, qdf_cpu_mask *src1p, 211 qdf_cpu_mask *src2p); 212 #endif /* __QDF_THREADS_H */ 213