OSDN Git Service

835a7238c067c0dd509eb9dd573df1ceacca6151
[android-x86/kernel.git] / drivers / staging / rtl8723bs / include / osdep_service.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2013 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
24 #define _FAIL           0
25 #define _SUCCESS        1
26 #define RTW_RX_HANDLED 2
27 //#define RTW_STATUS_TIMEDOUT -110
28
29 #include <osdep_service_linux.h>
30
31 //#include <rtw_byteorder.h>
32
33 #ifndef BIT
34         #define BIT(x)  ( 1 << (x))
35 #endif
36
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
74
75 extern int RTW_STATUS_CODE(int error_code);
76
77 /* flags used for rtw_mstat_update() */
78 enum mstat_f {
79         /* type: 0x00ff */
80         MSTAT_TYPE_VIR = 0x00,
81         MSTAT_TYPE_PHY= 0x01,
82         MSTAT_TYPE_SKB = 0x02,
83         MSTAT_TYPE_USB = 0x03,
84         MSTAT_TYPE_MAX = 0x04,
85
86         /* func: 0xff00 */
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,
94 };
95
96 #define mstat_tf_idx(flags) ((flags)&0xff)
97 #define mstat_ff_idx(flags) (((flags)&0xff00) >> 8)
98
99 typedef enum mstat_status{
100         MSTAT_ALLOC_SUCCESS = 0,
101         MSTAT_ALLOC_FAIL,
102         MSTAT_FREE
103 } MSTAT_STATUS;
104
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);
110
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);
115
116 #define rtw_malloc(sz)                  _rtw_malloc((sz))
117 #define rtw_zmalloc(sz)                 _rtw_zmalloc((sz))
118
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)
126
127 extern void     _rtw_init_queue(_queue  *pqueue);
128
129 extern void rtw_init_timer(_timer *ptimer, void *padapter, void *pfunc);
130
131
132 __inline static unsigned char _cancel_timer_ex(_timer *ptimer)
133 {
134         return del_timer_sync(ptimer);
135 }
136
137 static __inline void thread_enter(char *name)
138 {
139         allow_signal(SIGTERM);
140 }
141
142 __inline static void flush_signals_thread(void)
143 {
144         if (signal_pending (current))
145         {
146                 flush_signals(current);
147         }
148 }
149
150 #define rtw_warn_on(condition) WARN_ON(condition)
151
152 __inline static int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *parg4)
153 {
154         int ret = true;
155
156         return ret;
157
158 }
159
160 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
161 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ?  0: 1)) << 2)
162
163 __inline static u32 _RND4(u32 sz)
164 {
165
166         u32     val;
167
168         val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
169
170         return val;
171
172 }
173
174 __inline static u32 _RND8(u32 sz)
175 {
176
177         u32     val;
178
179         val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
180
181         return val;
182
183 }
184
185 #ifndef MAC_FMT
186 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
187 #endif
188 #ifndef MAC_ARG
189 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
190 #endif
191
192
193 #ifdef CONFIG_AP_WOWLAN
194 extern void rtw_softap_lock_suspend(void);
195 extern void rtw_softap_unlock_suspend(void);
196 #endif
197
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);
201
202 extern void rtw_free_netdev(struct net_device * netdev);
203
204
205 extern u64 rtw_modular64(u64 x, u64 y);
206
207 /* Macros for handling unaligned memory accesses */
208
209 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
210 #define RTW_PUT_BE16(a, val)                    \
211         do {                                    \
212                 (a)[0] = ((u16) (val)) >> 8;    \
213                 (a)[1] = ((u16) (val)) & 0xff;  \
214         } while (0)
215
216 #define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
217 #define RTW_PUT_LE16(a, val)                    \
218         do {                                    \
219                 (a)[1] = ((u16) (val)) >> 8;    \
220                 (a)[0] = ((u16) (val)) & 0xff;  \
221         } while (0)
222
223 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
224                          ((u32) (a)[2]))
225 #define RTW_PUT_BE24(a, val)                                    \
226         do {                                                    \
227                 (a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff);   \
228                 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff);    \
229                 (a)[2] = (u8) (((u32) (val)) & 0xff);           \
230         } while (0)
231
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)                                    \
235         do {                                                    \
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);           \
240         } while (0)
241
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)                                    \
245         do {                                                    \
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);           \
250         } while (0)
251
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)                            \
257         do {                                            \
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);   \
266         } while (0)
267
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]))
272
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);
275
276 struct rtw_cbuf {
277         u32 write;
278         u32 read;
279         u32 size;
280         void *bufs[0];
281 };
282
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);
288
289 // String handler
290 /*
291  * Write formatted output to sized buffer
292  */
293 #define rtw_sprintf(buf, size, format, arg...)  snprintf(buf, size, format, ##arg)
294
295 #endif