staging: rtl8188eu:Remove rtw_zmalloc(), wrapper for kzalloc()
[deliverable/linux.git] / drivers / staging / rtl8188eu / include / osdep_service.h
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #ifndef __OSDEP_SERVICE_H_
21 #define __OSDEP_SERVICE_H_
22
23 #include <basic_types.h>
24
25 #define _FAIL 0
26 #define _SUCCESS 1
27 #define RTW_RX_HANDLED 2
28
29 #include <linux/spinlock.h>
30 #include <linux/compiler.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/kref.h>
36 #include <linux/netdevice.h>
37 #include <linux/skbuff.h>
38 #include <linux/circ_buf.h>
39 #include <linux/uaccess.h>
40 #include <asm/byteorder.h>
41 #include <linux/atomic.h>
42 #include <linux/io.h>
43 #include <linux/semaphore.h>
44 #include <linux/sem.h>
45 #include <linux/sched.h>
46 #include <linux/etherdevice.h>
47 #include <linux/wireless.h>
48 #include <net/iw_handler.h>
49 #include <linux/if_arp.h>
50 #include <linux/rtnetlink.h>
51 #include <linux/delay.h>
52 #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
53 #include <linux/interrupt.h> /* for struct tasklet_struct */
54 #include <linux/ip.h>
55 #include <linux/kthread.h>
56
57 #include <linux/usb.h>
58 #include <linux/usb/ch9.h>
59
60 struct __queue {
61 struct list_head queue;
62 spinlock_t lock;
63 };
64
65 static inline struct list_head *get_list_head(struct __queue *queue)
66 {
67 return &(queue->queue);
68 }
69
70 static inline int _enter_critical_mutex(struct mutex *pmutex,
71 unsigned long *pirqL)
72 {
73 int ret;
74
75 ret = mutex_lock_interruptible(pmutex);
76 return ret;
77 }
78
79 static inline void rtw_list_delete(struct list_head *plist)
80 {
81 list_del_init(plist);
82 }
83
84 static inline void _init_timer(struct timer_list *ptimer,
85 struct net_device *nic_hdl,
86 void *pfunc, void *cntx)
87 {
88 ptimer->function = pfunc;
89 ptimer->data = (unsigned long)cntx;
90 init_timer(ptimer);
91 }
92
93 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
94 {
95 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
96 }
97
98 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
99 {
100 del_timer_sync(ptimer);
101 *bcancelled = true;/* true ==1; false==0 */
102 }
103
104 #define RTW_TIMER_HDL_ARGS void *FunctionContext
105 #define RTW_TIMER_HDL_NAME(name) rtw_##name##_timer_hdl
106 #define RTW_DECLARE_TIMER_HDL(name) \
107 void RTW_TIMER_HDL_NAME(name)(RTW_TIMER_HDL_ARGS)
108
109 static inline void _cancel_workitem_sync(struct work_struct *pwork)
110 {
111 cancel_work_sync(pwork);
112 }
113
114 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
115 {
116 return netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
117 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
118 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
119 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
120 }
121
122 #ifndef BIT
123 #define BIT(x) (1 << (x))
124 #endif
125
126 #define BIT0 0x00000001
127 #define BIT1 0x00000002
128 #define BIT2 0x00000004
129 #define BIT3 0x00000008
130 #define BIT4 0x00000010
131 #define BIT5 0x00000020
132 #define BIT6 0x00000040
133 #define BIT7 0x00000080
134 #define BIT8 0x00000100
135 #define BIT9 0x00000200
136 #define BIT10 0x00000400
137 #define BIT11 0x00000800
138 #define BIT12 0x00001000
139 #define BIT13 0x00002000
140 #define BIT14 0x00004000
141 #define BIT15 0x00008000
142 #define BIT16 0x00010000
143 #define BIT17 0x00020000
144 #define BIT18 0x00040000
145 #define BIT19 0x00080000
146 #define BIT20 0x00100000
147 #define BIT21 0x00200000
148 #define BIT22 0x00400000
149 #define BIT23 0x00800000
150 #define BIT24 0x01000000
151 #define BIT25 0x02000000
152 #define BIT26 0x04000000
153 #define BIT27 0x08000000
154 #define BIT28 0x10000000
155 #define BIT29 0x20000000
156 #define BIT30 0x40000000
157 #define BIT31 0x80000000
158 #define BIT32 0x0100000000
159 #define BIT33 0x0200000000
160 #define BIT34 0x0400000000
161 #define BIT35 0x0800000000
162 #define BIT36 0x1000000000
163
164 extern int RTW_STATUS_CODE(int error_code);
165
166 /* flags used for rtw_update_mem_stat() */
167 enum {
168 MEM_STAT_VIR_ALLOC_SUCCESS,
169 MEM_STAT_VIR_ALLOC_FAIL,
170 MEM_STAT_VIR_FREE,
171 MEM_STAT_PHY_ALLOC_SUCCESS,
172 MEM_STAT_PHY_ALLOC_FAIL,
173 MEM_STAT_PHY_FREE,
174 MEM_STAT_TX, /* used to distinguish TX/RX, asigned from caller */
175 MEM_STAT_TX_ALLOC_SUCCESS,
176 MEM_STAT_TX_ALLOC_FAIL,
177 MEM_STAT_TX_FREE,
178 MEM_STAT_RX, /* used to distinguish TX/RX, asigned from caller */
179 MEM_STAT_RX_ALLOC_SUCCESS,
180 MEM_STAT_RX_ALLOC_FAIL,
181 MEM_STAT_RX_FREE
182 };
183
184 extern unsigned char MCS_rate_2R[16];
185 extern unsigned char MCS_rate_1R[16];
186 extern unsigned char RTW_WPA_OUI[];
187 extern unsigned char WPA_TKIP_CIPHER[4];
188 extern unsigned char RSN_TKIP_CIPHER[4];
189
190 #define rtw_update_mem_stat(flag, sz) do {} while (0)
191 u8 *_rtw_malloc(u32 sz);
192 void _rtw_mfree(u8 *pbuf, u32 sz);
193 #define rtw_malloc(sz) _rtw_malloc((sz))
194 #define rtw_mfree(pbuf, sz) _rtw_mfree((pbuf), (sz))
195
196 void *rtw_malloc2d(int h, int w, int size);
197
198 void _rtw_memcpy(void *dec, void *sour, u32 sz);
199
200 void rtw_list_delete(struct list_head *plist);
201
202 u32 _rtw_down_sema(struct semaphore *sema);
203
204 void _rtw_init_queue(struct __queue *pqueue);
205 u32 _rtw_queue_empty(struct __queue *pqueue);
206
207 u32 rtw_systime_to_ms(u32 systime);
208 u32 rtw_ms_to_systime(u32 ms);
209 s32 rtw_get_passing_time_ms(u32 start);
210 s32 rtw_get_time_interval_ms(u32 start, u32 end);
211
212 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
213 {
214 return del_timer_sync(ptimer);
215 }
216
217 static inline void thread_enter(char *name)
218 {
219 allow_signal(SIGTERM);
220 }
221
222 static inline void flush_signals_thread(void)
223 {
224 if (signal_pending(current))
225 flush_signals(current);
226 }
227
228 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
229 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0 : 1)) << 2)
230
231 static inline u32 _RND4(u32 sz)
232 {
233 u32 val;
234
235 val = ((sz >> 2) + ((sz & 3) ? 1 : 0)) << 2;
236 return val;
237 }
238
239 static inline u32 _RND8(u32 sz)
240 {
241 u32 val;
242
243 val = ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
244 return val;
245 }
246
247 static inline u32 _RND128(u32 sz)
248 {
249 u32 val;
250
251 val = ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
252 return val;
253 }
254
255 static inline u32 _RND256(u32 sz)
256 {
257 u32 val;
258
259 val = ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
260 return val;
261 }
262
263 static inline u32 _RND512(u32 sz)
264 {
265 u32 val;
266
267 val = ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
268 return val;
269 }
270
271 static inline u32 bitshift(u32 bitmask)
272 {
273 u32 i;
274
275 for (i = 0; i <= 31; i++)
276 if (((bitmask>>i) & 0x1) == 1)
277 break;
278 return i;
279 }
280
281 /* limitation of path length */
282 #define PATH_LENGTH_MAX PATH_MAX
283
284 struct rtw_netdev_priv_indicator {
285 void *priv;
286 u32 sizeof_priv;
287 };
288 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
289 void *old_priv);
290 struct net_device *rtw_alloc_etherdev(int sizeof_priv);
291
292 #define rtw_netdev_priv(netdev) \
293 (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
294 void rtw_free_netdev(struct net_device *netdev);
295
296 #define NDEV_FMT "%s"
297 #define NDEV_ARG(ndev) ndev->name
298 #define ADPT_FMT "%s"
299 #define ADPT_ARG(adapter) adapter->pnetdev->name
300 #define FUNC_NDEV_FMT "%s(%s)"
301 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
302 #define FUNC_ADPT_FMT "%s(%s)"
303 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
304
305 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
306
307 u64 rtw_modular64(u64 x, u64 y);
308 u64 rtw_division64(u64 x, u64 y);
309
310 /* Macros for handling unaligned memory accesses */
311
312 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
313 #define RTW_PUT_BE16(a, val) \
314 do { \
315 (a)[0] = ((u16) (val)) >> 8; \
316 (a)[1] = ((u16) (val)) & 0xff; \
317 } while (0)
318
319 #define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
320 #define RTW_PUT_LE16(a, val) \
321 do { \
322 (a)[1] = ((u16) (val)) >> 8; \
323 (a)[0] = ((u16) (val)) & 0xff; \
324 } while (0)
325
326 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
327 ((u32) (a)[2]))
328
329 #define RTW_PUT_BE32(a, val) \
330 do { \
331 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
332 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
333 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
334 (a)[3] = (u8) (((u32) (val)) & 0xff); \
335 } while (0)
336
337 void rtw_buf_free(u8 **buf, u32 *buf_len);
338 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
339
340 struct rtw_cbuf {
341 u32 write;
342 u32 read;
343 u32 size;
344 void *bufs[0];
345 };
346
347 bool rtw_cbuf_full(struct rtw_cbuf *cbuf);
348 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
349 bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf);
350 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
351 struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
352 int wifirate2_ratetbl_inx(unsigned char rate);
353
354 #endif
This page took 0.041861 seconds and 5 git commands to generate.