Merge tag 'lsk-v3.10-android-15.01'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / include / basic_types.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 __BASIC_TYPES_H__
21 #define __BASIC_TYPES_H__
22
23
24 #define SUCCESS 0
25 #define FAIL    (-1)
26
27 #ifndef TRUE
28         #define _TRUE   1
29 #else
30         #define _TRUE   TRUE    
31 #endif
32                 
33 #ifndef FALSE           
34         #define _FALSE  0
35 #else
36         #define _FALSE  FALSE   
37 #endif
38
39 #ifdef PLATFORM_WINDOWS
40
41         typedef signed char s8;
42         typedef unsigned char u8;
43
44         typedef signed short s16;
45         typedef unsigned short u16;
46
47         typedef signed long s32;
48         typedef unsigned long u32;
49         
50         typedef unsigned int    uint;
51         typedef signed int              sint;
52
53
54         typedef signed long long s64;
55         typedef unsigned long long u64;
56
57         #ifdef NDIS50_MINIPORT
58         
59                 #define NDIS_MAJOR_VERSION       5
60                 #define NDIS_MINOR_VERSION       0
61
62         #endif
63
64         #ifdef NDIS51_MINIPORT
65
66                 #define NDIS_MAJOR_VERSION       5
67                 #define NDIS_MINOR_VERSION       1
68
69         #endif
70
71         typedef NDIS_PROC proc_t;
72
73         typedef LONG atomic_t;
74
75 #endif
76
77
78 #ifdef PLATFORM_LINUX
79
80         #include <linux/types.h>
81         #define IN
82         #define OUT
83         #define VOID void
84         #define NDIS_OID uint
85         #define NDIS_STATUS uint
86
87         typedef signed int sint;
88
89         #ifndef PVOID
90         typedef void * PVOID;
91         //#define PVOID (void *)
92         #endif
93
94         #define UCHAR u8
95         #define USHORT u16
96         #define UINT u32
97         #define ULONG u32       
98
99         typedef void (*proc_t)(void*);
100
101         typedef         __kernel_size_t SIZE_T; 
102         typedef __kernel_ssize_t        SSIZE_T;
103         #define FIELD_OFFSET(s,field)   ((SSIZE_T)&((s*)(0))->field)
104         
105 #endif
106
107
108 #ifdef PLATFORM_FREEBSD
109
110         typedef signed char s8;
111         typedef unsigned char u8;
112
113         typedef signed short s16;
114         typedef unsigned short u16;
115
116         typedef signed int s32;
117         typedef unsigned int u32;
118         
119         typedef unsigned int    uint;
120         typedef signed int              sint;
121         typedef long atomic_t;
122
123         typedef signed long long s64;
124         typedef unsigned long long u64;
125         #define IN
126         #define OUT
127         #define VOID void
128         #define NDIS_OID uint
129         #define NDIS_STATUS uint
130         
131         #ifndef PVOID
132         typedef void * PVOID;
133         //#define PVOID (void *)
134         #endif
135         typedef u32 dma_addr_t;
136     #define UCHAR u8
137         #define USHORT u16
138         #define UINT u32
139         #define ULONG u32       
140
141         typedef void (*proc_t)(void*);
142   
143   typedef unsigned int __kernel_size_t;
144   typedef int __kernel_ssize_t;
145   
146         typedef         __kernel_size_t SIZE_T; 
147         typedef __kernel_ssize_t        SSIZE_T;
148         #define FIELD_OFFSET(s,field)   ((SSIZE_T)&((s*)(0))->field)
149         
150 #endif
151
152 #define MEM_ALIGNMENT_OFFSET    (sizeof (SIZE_T))
153 #define MEM_ALIGNMENT_PADDING   (sizeof(SIZE_T) - 1)
154
155 #define SIZE_PTR SIZE_T
156 #define SSIZE_PTR SSIZE_T
157
158 //port from fw by thomas
159 // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
160
161 /*
162  *      Call endian free function when
163  *              1. Read/write packet content.
164  *              2. Before write integer to IO.
165  *              3. After read integer from IO.
166 */
167
168 //
169 // Byte Swapping routine.
170 //
171 #define EF1Byte (u8)
172 #define EF2Byte         le16_to_cpu
173 #define EF4Byte le32_to_cpu
174
175 //
176 // Read LE format data from memory
177 //
178 #define ReadEF1Byte(_ptr)               EF1Byte(*((u8 *)(_ptr)))
179 #define ReadEF2Byte(_ptr)               EF2Byte(*((u16 *)(_ptr)))
180 #define ReadEF4Byte(_ptr)               EF4Byte(*((u32 *)(_ptr)))
181
182 //
183 // Write LE data to memory
184 //
185 #define WriteEF1Byte(_ptr, _val)        (*((u8 *)(_ptr)))=EF1Byte(_val)
186 #define WriteEF2Byte(_ptr, _val)        (*((u16 *)(_ptr)))=EF2Byte(_val)
187 #define WriteEF4Byte(_ptr, _val)        (*((u32 *)(_ptr)))=EF4Byte(_val)                                                                        
188
189 //
190 //      Example:
191 //              BIT_LEN_MASK_32(0) => 0x00000000
192 //              BIT_LEN_MASK_32(1) => 0x00000001
193 //              BIT_LEN_MASK_32(2) => 0x00000003
194 //              BIT_LEN_MASK_32(32) => 0xFFFFFFFF
195 //
196 #define BIT_LEN_MASK_32(__BitLen) \
197         (0xFFFFFFFF >> (32 - (__BitLen)))
198 //
199 //      Example:
200 //              BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
201 //              BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
202 //
203 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
204         (BIT_LEN_MASK_32(__BitLen) << (__BitOffset)) 
205
206 //
207 //      Description:
208 //              Return 4-byte value in host byte ordering from
209 //              4-byte pointer in litten-endian system.
210 //
211 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
212         (EF4Byte(*((u32 *)(__pStart))))
213
214 //
215 //      Description:
216 //              Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
217 //              4-byte value in host byte ordering.
218 //
219 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
220         ( \
221                 ( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
222                 & \
223                 BIT_LEN_MASK_32(__BitLen) \
224         )
225
226 //
227 //      Description:
228 //              Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering  
229 //              and return the result in 4-byte value in host byte ordering.
230 //
231 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
232         ( \
233                 LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
234                 & \
235                 ( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
236         )
237
238 //
239 //      Description:
240 //              Set subfield of little-endian 4-byte value to specified value.  
241 //
242 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
243         *((u32 *)(__pStart)) = \
244                 EF4Byte( \
245                         LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
246                         | \
247                         ( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
248                 );
249
250                 
251 #define BIT_LEN_MASK_16(__BitLen) \
252                 (0xFFFF >> (16 - (__BitLen)))
253                 
254 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
255         (BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
256         
257 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
258         (EF2Byte(*((u16 *)(__pStart))))
259         
260 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
261         ( \
262                 ( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
263                 & \
264                 BIT_LEN_MASK_16(__BitLen) \
265         )
266         
267 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
268         ( \
269                 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
270                 & \
271                 ( ~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ) \
272         )
273
274 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
275         *((u16 *)(__pStart)) = \
276                 EF2Byte( \
277                         LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
278                         | \
279                         ( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
280                 );
281                         
282 #define BIT_LEN_MASK_8(__BitLen) \
283                 (0xFF >> (8 - (__BitLen)))
284
285 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
286         (BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
287
288 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
289         (EF1Byte(*((u8 *)(__pStart))))
290
291 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
292         ( \
293                 ( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
294                 & \
295                 BIT_LEN_MASK_8(__BitLen) \
296         )
297
298 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
299         ( \
300                 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
301                 & \
302                 ( ~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ) \
303         )
304
305 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
306         *((u8 *)(__pStart)) = \
307                 EF1Byte( \
308                         LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
309                         | \
310                         ( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
311                 );
312
313
314 #define LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
315         ( \
316                 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
317         )
318
319 #define SET_BITS_TO_LE_2BYTE_16BIT(__pStart, __BitOffset, __BitLen, __Value) \
320         *((u16 *)(__pStart)) = \
321                 EF2Byte( \
322                         LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
323                         | \
324                         ( (u16)__Value) \
325                 );
326
327 #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
328         ( \
329                 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
330         )
331
332 #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
333 { \
334         *((u8 *)(__pStart)) = \
335                 EF1Byte( \
336                         LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
337                         | \
338                         ((u8)__Value) \
339                 ); \
340 }
341
342 // Get the N-bytes aligment offset from the current length
343 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
344
345 typedef unsigned char   BOOLEAN,*PBOOLEAN;
346
347 #define TEST_FLAG(__Flag,__testFlag)            (((__Flag) & (__testFlag)) != 0)
348 #define SET_FLAG(__Flag, __setFlag)                     ((__Flag) |= __setFlag)
349 #define CLEAR_FLAG(__Flag, __clearFlag)         ((__Flag) &= ~(__clearFlag))
350 #define CLEAR_FLAGS(__Flag)                                     ((__Flag) = 0)
351 #define TEST_FLAGS(__Flag, __testFlags)         (((__Flag) & (__testFlags)) == (__testFlags))
352
353 #endif //__BASIC_TYPES_H__
354