1 /******************************************************************************
3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
20 #ifndef __OSDEP_SERVICE_H_
21 #define __OSDEP_SERVICE_H_
26 #define RTW_RX_HANDLED 2
27 //#define RTW_STATUS_TIMEDOUT -110
29 #include <osdep_service_linux.h>
31 //#include <rtw_byteorder.h>
34 #define BIT(x) ( 1 << (x))
37 #define BIT0 0x00000001
38 #define BIT1 0x00000002
39 #define BIT2 0x00000004
40 #define BIT3 0x00000008
41 #define BIT4 0x00000010
42 #define BIT5 0x00000020
43 #define BIT6 0x00000040
44 #define BIT7 0x00000080
45 #define BIT8 0x00000100
46 #define BIT9 0x00000200
47 #define BIT10 0x00000400
48 #define BIT11 0x00000800
49 #define BIT12 0x00001000
50 #define BIT13 0x00002000
51 #define BIT14 0x00004000
52 #define BIT15 0x00008000
53 #define BIT16 0x00010000
54 #define BIT17 0x00020000
55 #define BIT18 0x00040000
56 #define BIT19 0x00080000
57 #define BIT20 0x00100000
58 #define BIT21 0x00200000
59 #define BIT22 0x00400000
60 #define BIT23 0x00800000
61 #define BIT24 0x01000000
62 #define BIT25 0x02000000
63 #define BIT26 0x04000000
64 #define BIT27 0x08000000
65 #define BIT28 0x10000000
66 #define BIT29 0x20000000
67 #define BIT30 0x40000000
68 #define BIT31 0x80000000
69 #define BIT32 0x0100000000
70 #define BIT33 0x0200000000
71 #define BIT34 0x0400000000
72 #define BIT35 0x0800000000
73 #define BIT36 0x1000000000
75 extern int RTW_STATUS_CODE(int error_code);
77 /* flags used for rtw_mstat_update() */
80 MSTAT_TYPE_VIR = 0x00,
82 MSTAT_TYPE_SKB = 0x02,
83 MSTAT_TYPE_USB = 0x03,
84 MSTAT_TYPE_MAX = 0x04,
87 MSTAT_FUNC_UNSPECIFIED = 0x00<<8,
88 MSTAT_FUNC_IO = 0x01<<8,
89 MSTAT_FUNC_TX_IO = 0x02<<8,
90 MSTAT_FUNC_RX_IO = 0x03<<8,
91 MSTAT_FUNC_TX = 0x04<<8,
92 MSTAT_FUNC_RX = 0x05<<8,
93 MSTAT_FUNC_MAX = 0x06<<8,
96 #define mstat_tf_idx(flags) ((flags)&0xff)
97 #define mstat_ff_idx(flags) (((flags)&0xff00) >> 8)
99 typedef enum mstat_status{
100 MSTAT_ALLOC_SUCCESS = 0,
105 #define rtw_mstat_update(flag, status, sz) do {} while(0)
106 #define rtw_mstat_dump(sel) do {} while(0)
107 u8* _rtw_zmalloc(u32 sz);
108 u8* _rtw_malloc(u32 sz);
109 void _kfree(u8 *pbuf, u32 sz);
111 struct sk_buff *_rtw_skb_alloc(u32 sz);
112 struct sk_buff *_rtw_skb_copy(const struct sk_buff *skb);
113 struct sk_buff *_rtw_skb_clone(struct sk_buff *skb);
114 int _rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb);
116 #define rtw_malloc(sz) _rtw_malloc((sz))
117 #define rtw_zmalloc(sz) _rtw_zmalloc((sz))
119 #define rtw_skb_alloc(size) _rtw_skb_alloc((size))
120 #define rtw_skb_alloc_f(size, mstat_f) _rtw_skb_alloc((size))
121 #define rtw_skb_copy(skb) _rtw_skb_copy((skb))
122 #define rtw_skb_clone(skb) _rtw_skb_clone((skb))
123 #define rtw_skb_copy_f(skb, mstat_f) _rtw_skb_copy((skb))
124 #define rtw_skb_clone_f(skb, mstat_f) _rtw_skb_clone((skb))
125 #define rtw_netif_rx(ndev, skb) _rtw_netif_rx(ndev, skb)
127 extern void _rtw_init_queue(_queue *pqueue);
129 extern void rtw_init_timer(_timer *ptimer, void *padapter, void *pfunc);
132 __inline static unsigned char _cancel_timer_ex(_timer *ptimer)
134 return del_timer_sync(ptimer);
137 static __inline void thread_enter(char *name)
139 allow_signal(SIGTERM);
142 __inline static void flush_signals_thread(void)
144 if (signal_pending (current))
146 flush_signals(current);
150 #define rtw_warn_on(condition) WARN_ON(condition)
152 __inline static int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *parg4)
160 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
161 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
163 __inline static u32 _RND4(u32 sz)
168 val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
174 __inline static u32 _RND8(u32 sz)
179 val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
186 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
189 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
193 #ifdef CONFIG_AP_WOWLAN
194 extern void rtw_softap_lock_suspend(void);
195 extern void rtw_softap_unlock_suspend(void);
198 //File operation APIs, just for linux now
199 extern int rtw_is_file_readable(char *path);
200 extern int rtw_retrive_from_file(char *path, u8* buf, u32 sz);
202 extern void rtw_free_netdev(struct net_device * netdev);
205 extern u64 rtw_modular64(u64 x, u64 y);
207 /* Macros for handling unaligned memory accesses */
209 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
210 #define RTW_PUT_BE16(a, val) \
212 (a)[0] = ((u16) (val)) >> 8; \
213 (a)[1] = ((u16) (val)) & 0xff; \
216 #define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
217 #define RTW_PUT_LE16(a, val) \
219 (a)[1] = ((u16) (val)) >> 8; \
220 (a)[0] = ((u16) (val)) & 0xff; \
223 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
225 #define RTW_PUT_BE24(a, val) \
227 (a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
228 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
229 (a)[2] = (u8) (((u32) (val)) & 0xff); \
232 #define RTW_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
233 (((u32) (a)[2]) << 8) | ((u32) (a)[3]))
234 #define RTW_PUT_BE32(a, val) \
236 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
237 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
238 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
239 (a)[3] = (u8) (((u32) (val)) & 0xff); \
242 #define RTW_GET_LE32(a) ((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \
243 (((u32) (a)[1]) << 8) | ((u32) (a)[0]))
244 #define RTW_PUT_LE32(a, val) \
246 (a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \
247 (a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \
248 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
249 (a)[0] = (u8) (((u32) (val)) & 0xff); \
252 #define RTW_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \
253 (((u64) (a)[2]) << 40) | (((u64) (a)[3]) << 32) | \
254 (((u64) (a)[4]) << 24) | (((u64) (a)[5]) << 16) | \
255 (((u64) (a)[6]) << 8) | ((u64) (a)[7]))
256 #define RTW_PUT_BE64(a, val) \
258 (a)[0] = (u8) (((u64) (val)) >> 56); \
259 (a)[1] = (u8) (((u64) (val)) >> 48); \
260 (a)[2] = (u8) (((u64) (val)) >> 40); \
261 (a)[3] = (u8) (((u64) (val)) >> 32); \
262 (a)[4] = (u8) (((u64) (val)) >> 24); \
263 (a)[5] = (u8) (((u64) (val)) >> 16); \
264 (a)[6] = (u8) (((u64) (val)) >> 8); \
265 (a)[7] = (u8) (((u64) (val)) & 0xff); \
268 #define RTW_GET_LE64(a) ((((u64) (a)[7]) << 56) | (((u64) (a)[6]) << 48) | \
269 (((u64) (a)[5]) << 40) | (((u64) (a)[4]) << 32) | \
270 (((u64) (a)[3]) << 24) | (((u64) (a)[2]) << 16) | \
271 (((u64) (a)[1]) << 8) | ((u64) (a)[0]))
273 void rtw_buf_free(u8 **buf, u32 *buf_len);
274 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
283 bool rtw_cbuf_full(struct rtw_cbuf *cbuf);
284 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
285 bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf);
286 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
287 struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
291 * Write formatted output to sized buffer
293 #define rtw_sprintf(buf, size, format, arg...) snprintf(buf, size, format, ##arg)