]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - drivers/staging/r8188eu/include/osdep_service.h
exit/r8188eu: Replace the macro thread_exit with a simple return 0
[mirror_ubuntu-kernels.git] / drivers / staging / r8188eu / include / osdep_service.h
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #ifndef __OSDEP_SERVICE_H_
5 #define __OSDEP_SERVICE_H_
6
7 #include <linux/sched/signal.h>
8 #include "basic_types.h"
9
10 #define _FAIL 0
11 #define _SUCCESS 1
12 #define RTW_RX_HANDLED 2
13
14 #include <linux/spinlock.h>
15 #include <linux/compiler.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/kref.h>
22 #include <linux/netdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/circ_buf.h>
25 #include <linux/uaccess.h>
26 #include <asm/byteorder.h>
27 #include <asm/atomic.h>
28 #include <linux/io.h>
29 #include <linux/semaphore.h>
30 #include <linux/sem.h>
31 #include <linux/sched.h>
32 #include <linux/etherdevice.h>
33 #include <linux/wireless.h>
34 #include <net/iw_handler.h>
35 #include <linux/if_arp.h>
36 #include <linux/rtnetlink.h>
37 #include <linux/delay.h>
38 #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
39 #include <linux/interrupt.h> /* for struct tasklet_struct */
40 #include <linux/ip.h>
41 #include <linux/kthread.h>
42 #include <linux/vmalloc.h>
43
44 #include <linux/usb.h>
45 #include <linux/usb/ch9.h>
46
47 struct __queue {
48 struct list_head queue;
49 spinlock_t lock;
50 };
51
52 static inline struct list_head *get_list_head(struct __queue *queue)
53 {
54 return (&(queue->queue));
55 }
56
57 static inline int _enter_critical_mutex(struct mutex *pmutex, unsigned long *pirqL)
58 {
59 int ret;
60
61 ret = mutex_lock_interruptible(pmutex);
62 return ret;
63 }
64
65 static inline void _exit_critical_mutex(struct mutex *pmutex, unsigned long *pirqL)
66 {
67 mutex_unlock(pmutex);
68 }
69
70 static inline void rtw_list_delete(struct list_head *plist)
71 {
72 list_del_init(plist);
73 }
74
75 static inline void _set_timer(struct timer_list *ptimer,u32 delay_time)
76 {
77 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
78 }
79
80 static inline void _cancel_timer(struct timer_list *ptimer,u8 *bcancelled)
81 {
82 del_timer_sync(ptimer);
83 *bcancelled= true;/* true ==1; false==0 */
84 }
85
86 #define RTW_TIMER_HDL_ARGS void *FunctionContext
87 #define RTW_TIMER_HDL_NAME(name) rtw_##name##_timer_hdl
88 #define RTW_DECLARE_TIMER_HDL(name) void RTW_TIMER_HDL_NAME(name)(RTW_TIMER_HDL_ARGS)
89
90 static inline void _init_workitem(struct work_struct *pwork, void *pfunc, void * cntx)
91 {
92 INIT_WORK(pwork, pfunc);
93 }
94
95 static inline void _set_workitem(struct work_struct *pwork)
96 {
97 schedule_work(pwork);
98 }
99
100 static inline void _cancel_workitem_sync(struct work_struct *pwork)
101 {
102 cancel_work_sync(pwork);
103 }
104 /* */
105 /* Global Mutex: can only be used at PASSIVE level. */
106 /* */
107
108 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
109 { \
110 while (atomic_inc_return((atomic_t *)&(_MutexCounter)) != 1)\
111 { \
112 atomic_dec((atomic_t *)&(_MutexCounter)); \
113 msleep(10); \
114 } \
115 }
116
117 #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
118 { \
119 atomic_dec((atomic_t *)&(_MutexCounter)); \
120 }
121
122 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
123 {
124 return netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
125 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
126 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
127 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
128 }
129
130 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
131 {
132 netif_tx_wake_all_queues(pnetdev);
133 }
134
135 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
136 {
137 netif_tx_start_all_queues(pnetdev);
138 }
139
140 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
141 {
142 netif_tx_stop_all_queues(pnetdev);
143 }
144
145 extern int RTW_STATUS_CODE(int error_code);
146
147 extern unsigned char MCS_rate_2R[16];
148 extern unsigned char MCS_rate_1R[16];
149 extern unsigned char RTW_WPA_OUI[];
150 extern unsigned char WPA_TKIP_CIPHER[4];
151 extern unsigned char RSN_TKIP_CIPHER[4];
152
153 void *rtw_malloc2d(int h, int w, int size);
154
155 u32 _rtw_down_sema(struct semaphore *sema);
156 void _rtw_mutex_init(struct mutex *pmutex);
157 void _rtw_mutex_free(struct mutex *pmutex);
158
159 void _rtw_init_queue(struct __queue *pqueue);
160
161 u32 rtw_systime_to_ms(u32 systime);
162 u32 rtw_ms_to_systime(u32 ms);
163 s32 rtw_get_passing_time_ms(u32 start);
164
165 void rtw_usleep_os(int us);
166
167 u32 rtw_atoi(u8 *s);
168
169 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
170 {
171 return del_timer_sync(ptimer);
172 }
173
174 static __inline void thread_enter(char *name)
175 {
176 #ifdef daemonize
177 daemonize("%s", name);
178 #endif
179 allow_signal(SIGTERM);
180 }
181
182 static inline void flush_signals_thread(void)
183 {
184 if (signal_pending (current))
185 flush_signals(current);
186 }
187
188 static inline int res_to_status(int res)
189 {
190 return res;
191 }
192
193 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
194 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
195
196 static inline u32 _RND4(u32 sz)
197 {
198 u32 val;
199
200 val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
201 return val;
202 }
203
204 static inline u32 _RND8(u32 sz)
205 {
206 u32 val;
207
208 val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
209 return val;
210 }
211
212 static inline u32 _RND128(u32 sz)
213 {
214 u32 val;
215
216 val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
217 return val;
218 }
219
220 static inline u32 _RND256(u32 sz)
221 {
222 u32 val;
223
224 val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
225 return val;
226 }
227
228 static inline u32 _RND512(u32 sz)
229 {
230 u32 val;
231
232 val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
233 return val;
234 }
235
236 static inline u32 bitshift(u32 bitmask)
237 {
238 u32 i;
239
240 for (i = 0; i <= 31; i++)
241 if (((bitmask>>i) & 0x1) == 1) break;
242 return i;
243 }
244
245 /* limitation of path length */
246 #define PATH_LENGTH_MAX PATH_MAX
247
248 struct rtw_netdev_priv_indicator {
249 void *priv;
250 u32 sizeof_priv;
251 };
252 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
253 void *old_priv);
254 struct net_device *rtw_alloc_etherdev(int sizeof_priv);
255
256 #define rtw_netdev_priv(netdev) \
257 (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
258 void rtw_free_netdev(struct net_device *netdev);
259
260 #define NDEV_FMT "%s"
261 #define NDEV_ARG(ndev) ndev->name
262 #define ADPT_FMT "%s"
263 #define ADPT_ARG(adapter) adapter->pnetdev->name
264 #define FUNC_NDEV_FMT "%s(%s)"
265 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
266 #define FUNC_ADPT_FMT "%s(%s)"
267 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
268
269 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)
270
271 /* Macros for handling unaligned memory accesses */
272
273 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
274 #define RTW_PUT_BE16(a, val) \
275 do { \
276 (a)[0] = ((u16) (val)) >> 8; \
277 (a)[1] = ((u16) (val)) & 0xff; \
278 } while (0)
279
280 #define RTW_PUT_LE16(a, val) \
281 do { \
282 (a)[1] = ((u16) (val)) >> 8; \
283 (a)[0] = ((u16) (val)) & 0xff; \
284 } while (0)
285
286 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
287 ((u32) (a)[2]))
288
289 #define RTW_PUT_BE32(a, val) \
290 do { \
291 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
292 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
293 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
294 (a)[3] = (u8) (((u32) (val)) & 0xff); \
295 } while (0)
296
297 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
298
299 struct rtw_cbuf {
300 u32 write;
301 u32 read;
302 u32 size;
303 void *bufs[0];
304 };
305
306 bool rtw_cbuf_full(struct rtw_cbuf *cbuf);
307 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
308 bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf);
309 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
310 struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
311 int wifirate2_ratetbl_inx(unsigned char rate);
312
313 #endif