xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_threads.h (revision d57e7836dc389f88871517cfeedfdd0f572e4b31)
1 /*
2  * Copyright (c) 2014-2020 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:  qdf_threads
21  * QCA driver framework (QDF) thread related APIs
22  */
23 
24 #if !defined(__QDF_THREADS_H)
25 #define __QDF_THREADS_H
26 
27 #include <qdf_types.h>
28 #include "i_qdf_threads.h"
29 
30 typedef __qdf_thread_t qdf_thread_t;
31 typedef QDF_STATUS (*qdf_thread_func)(void *context);
32 
33 /* Function declarations and documenation */
34 
35 void qdf_sleep(uint32_t ms_interval);
36 
37 void qdf_sleep_us(uint32_t us_interval);
38 
39 void qdf_busy_wait(uint32_t us_interval);
40 
41 /**
42  * qdf_set_wake_up_idle() - set wakeup idle value
43  * @idle: true/false value for wake up idle
44  *
45  * Return: none
46  */
47 void qdf_set_wake_up_idle(bool idle);
48 
49 /**
50  * qdf_set_user_nice() - set thread's nice value
51  * @thread: pointer to thread
52  * @nice: nice value
53  *
54  * Return: void
55  */
56 void qdf_set_user_nice(qdf_thread_t *thread, long nice);
57 
58 /**
59  * qdf_create_thread() - create a kernel thread
60  * @thread: pointer to thread
61  * @nice: nice value
62  *
63  * Return: pointer to created kernel thread on success else NULL
64  */
65 qdf_thread_t *qdf_create_thread(int (*thread_handler)(void *data), void *data,
66 				const char thread_name[]);
67 
68 /**
69  * qdf_thread_run() - run the given function in a new thread
70  *
71  * You must call qdf_thread_join() to avoid a reasource leak!
72  *
73  * For more flexibility, use qdf_create_thread() instead.
74  *
75  * Return: a new qdf_thread pointer
76  */
77 qdf_thread_t *qdf_thread_run(qdf_thread_func callback, void *context);
78 
79 /**
80  * qdf_thread_join() - signal and wait for a thread to stop
81  *
82  * This sets a flag that the given thread can check to see if it should exit.
83  * The thread can check to see if this flag has been set by calling
84  * qdf_thread_should_stop().
85  *
86  * Return: QDF_STATUS - the return value from the thread function
87  */
88 QDF_STATUS qdf_thread_join(qdf_thread_t *thread);
89 
90 /**
91  * qdf_thread_should_stop() - true if the current thread was signalled to stop
92  *
93  * If qdf_thread_join() has been called on the current thread, this API returns
94  * true. Otherwise, this returns false.
95  *
96  * Return: true if the current thread should stop
97  */
98 bool qdf_thread_should_stop(void);
99 
100 /**
101  * qdf_wake_up_process() - wake up given thread
102  * @thread: pointer to thread which needs to be woken up
103  *
104  * Return: none
105  */
106 int qdf_wake_up_process(qdf_thread_t *thread);
107 
108 /**
109  * qdf_print_stack_trace_thread() - prints the stack trace of the given thread
110  * @thread: the thread for which the stack trace will be printed
111  *
112  * Return: None
113  */
114 void qdf_print_thread_trace(qdf_thread_t *thread);
115 
116 /**
117  * qdf_get_current_task() - get current task struct
118  *
119  * Return: pointer to task struct
120  */
121 qdf_thread_t *qdf_get_current_task(void);
122 
123 /**
124  * qdf_get_current_pid() - get current task's process id
125  *
126  * Return: current task's process id (int)
127  */
128 int qdf_get_current_pid(void);
129 
130 /**
131  * qdf_get_current_comm() - get current task's command name
132  *
133  * Return: current task's command name(char *)
134  */
135 const char *qdf_get_current_comm(void);
136 
137 /**
138  * qdf_thread_set_cpus_allowed_mask() - set cpu mask for a particular thread
139  * @thread: thread for which new cpu mask is set
140  * @new_mask: new cpu mask to be set for the thread
141  *
142  * Return: None
143  */
144 void
145 qdf_thread_set_cpus_allowed_mask(qdf_thread_t *thread, qdf_cpu_mask *new_mask);
146 
147 /**
148  * qdf_cpumask_clear() - clear all cpus in a cpumask
149  * @dstp: cpumask pointer
150  *
151  * Return: None
152  */
153 void qdf_cpumask_clear(qdf_cpu_mask *dstp);
154 
155 /**
156  * qdf_cpumask_set_cpu() - set a cpu in a cpumask
157  * @cpu: cpu number
158  * @dstp: cpumask pointer
159  *
160  * Return: None
161  */
162 void qdf_cpumask_set_cpu(unsigned int cpu, qdf_cpu_mask *dstp);
163 
164 /**
165  * qdf_cpumask_setall - set all cpus
166  * @dstp: cpumask pointer
167  *
168  * Return: None
169  */
170 void qdf_cpumask_setall(qdf_cpu_mask *dstp);
171 
172 /**
173  * qdf_cpumask_empty - Check if cpu_mask is empty
174  * @srcp: cpumask pointer
175  *
176  * Return: true or false
177  *
178  */
179 bool qdf_cpumask_empty(const qdf_cpu_mask *srcp);
180 
181 /**
182  * qdf_cpumask_copy - Copy srcp cpumask to dstp
183  * @srcp: source cpumask pointer
184  * @dstp: destination cpumask pointer
185  *
186  * Return: None
187  *
188  */
189 void qdf_cpumask_copy(qdf_cpu_mask *dstp,
190 		      const qdf_cpu_mask *srcp);
191 #endif /* __QDF_THREADS_H */
192