8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[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         #include <linux/version.h>
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         #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
100                 typedef _Bool bool;
101         #endif
102
103         typedef void (*proc_t)(void*);
104
105         typedef         __kernel_size_t SIZE_T; 
106         typedef __kernel_ssize_t        SSIZE_T;
107         #define FIELD_OFFSET(s,field)   ((SSIZE_T)&((s*)(0))->field)
108         
109 #endif
110
111
112 #ifdef PLATFORM_FREEBSD
113
114         typedef signed char s8;
115         typedef unsigned char u8;
116
117         typedef signed short s16;
118         typedef unsigned short u16;
119
120         typedef signed int s32;
121         typedef unsigned int u32;
122         
123         typedef unsigned int    uint;
124         typedef signed int              sint;
125         typedef long atomic_t;
126
127         typedef signed long long s64;
128         typedef unsigned long long u64;
129         #define IN
130         #define OUT
131         #define VOID void
132         #define NDIS_OID uint
133         #define NDIS_STATUS uint
134         
135         #ifndef PVOID
136         typedef void * PVOID;
137         //#define PVOID (void *)
138         #endif
139         typedef u32 dma_addr_t;
140     #define UCHAR u8
141         #define USHORT u16
142         #define UINT u32
143         #define ULONG u32       
144
145         typedef void (*proc_t)(void*);
146   
147   typedef unsigned int __kernel_size_t;
148   typedef int __kernel_ssize_t;
149   
150         typedef         __kernel_size_t SIZE_T; 
151         typedef __kernel_ssize_t        SSIZE_T;
152         #define FIELD_OFFSET(s,field)   ((SSIZE_T)&((s*)(0))->field)
153         
154 #endif
155
156 #define MEM_ALIGNMENT_OFFSET    (sizeof (SIZE_T))
157 #define MEM_ALIGNMENT_PADDING   (sizeof(SIZE_T) - 1)
158
159 #define SIZE_PTR SIZE_T
160 #define SSIZE_PTR SSIZE_T
161
162 //port from fw by thomas
163 // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
164
165 /*
166  *      Call endian free function when
167  *              1. Read/write packet content.
168  *              2. Before write integer to IO.
169  *              3. After read integer from IO.
170 */
171
172 //
173 // Byte Swapping routine.
174 //
175 #define EF1Byte (u8)
176 #define EF2Byte         le16_to_cpu
177 #define EF4Byte le32_to_cpu
178
179 //
180 // Read LE format data from memory
181 //
182 #define ReadEF1Byte(_ptr)               EF1Byte(*((u8 *)(_ptr)))
183 #define ReadEF2Byte(_ptr)               EF2Byte(*((u16 *)(_ptr)))
184 #define ReadEF4Byte(_ptr)               EF4Byte(*((u32 *)(_ptr)))
185
186 //
187 // Write LE data to memory
188 //
189 #define WriteEF1Byte(_ptr, _val)        (*((u8 *)(_ptr)))=EF1Byte(_val)
190 #define WriteEF2Byte(_ptr, _val)        (*((u16 *)(_ptr)))=EF2Byte(_val)
191 #define WriteEF4Byte(_ptr, _val)        (*((u32 *)(_ptr)))=EF4Byte(_val)                                                                        
192
193 //
194 //      Example:
195 //              BIT_LEN_MASK_32(0) => 0x00000000
196 //              BIT_LEN_MASK_32(1) => 0x00000001
197 //              BIT_LEN_MASK_32(2) => 0x00000003
198 //              BIT_LEN_MASK_32(32) => 0xFFFFFFFF
199 //
200 #define BIT_LEN_MASK_32(__BitLen) \
201         (0xFFFFFFFF >> (32 - (__BitLen)))
202 //
203 //      Example:
204 //              BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
205 //              BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
206 //
207 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
208         (BIT_LEN_MASK_32(__BitLen) << (__BitOffset)) 
209
210 //
211 //      Description:
212 //              Return 4-byte value in host byte ordering from
213 //              4-byte pointer in litten-endian system.
214 //
215 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
216         (EF4Byte(*((u32 *)(__pStart))))
217
218 //
219 //      Description:
220 //              Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
221 //              4-byte value in host byte ordering.
222 //
223 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
224         ( \
225                 ( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
226                 & \
227                 BIT_LEN_MASK_32(__BitLen) \
228         )
229
230 //
231 //      Description:
232 //              Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering  
233 //              and return the result in 4-byte value in host byte ordering.
234 //
235 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
236         ( \
237                 LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
238                 & \
239                 ( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
240         )
241
242 //
243 //      Description:
244 //              Set subfield of little-endian 4-byte value to specified value.  
245 //
246 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
247         *((u32 *)(__pStart)) = \
248                 EF4Byte( \
249                         LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
250                         | \
251                         ( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
252                 );
253
254                 
255 #define BIT_LEN_MASK_16(__BitLen) \
256                 (0xFFFF >> (16 - (__BitLen)))
257                 
258 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
259         (BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
260         
261 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
262         (EF2Byte(*((u16 *)(__pStart))))
263         
264 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
265         ( \
266                 ( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
267                 & \
268                 BIT_LEN_MASK_16(__BitLen) \
269         )
270         
271 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
272         ( \
273                 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
274                 & \
275                 (u16)(~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen))\
276         )
277
278 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
279         *((u16 *)(__pStart)) = \
280                 EF2Byte( \
281                         LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
282                         | \
283                         ( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
284                 );
285                         
286 #define BIT_LEN_MASK_8(__BitLen) \
287                 (0xFF >> (8 - (__BitLen)))
288
289 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
290         (BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
291
292 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
293         (EF1Byte(*((u8 *)(__pStart))))
294
295 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
296         ( \
297                 ( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
298                 & \
299                 BIT_LEN_MASK_8(__BitLen) \
300         )
301
302 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
303         ( \
304                 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
305                 & \
306                 (u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))\
307         )
308
309 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
310         *((u8 *)(__pStart)) = \
311                 EF1Byte( \
312                         LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
313                         | \
314                         ( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
315                 );
316
317
318 #define LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
319         ( \
320                 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
321         )
322
323 #define SET_BITS_TO_LE_2BYTE_16BIT(__pStart, __BitOffset, __BitLen, __Value) \
324         *((u16 *)(__pStart)) = \
325                 EF2Byte( \
326                         LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
327                         | \
328                         ( (u16)__Value) \
329                 );
330
331 #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
332         ( \
333                 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
334         )
335
336 #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
337 do { \
338         *((u8 *)(__pStart)) = \
339                 EF1Byte( \
340                         LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
341                         | \
342                         ((u8)__Value) \
343                 ); \
344 } while (0)
345
346 // Get the N-bytes aligment offset from the current length
347 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
348
349 typedef unsigned char   BOOLEAN,*PBOOLEAN;
350
351 #define TEST_FLAG(__Flag,__testFlag)            (((__Flag) & (__testFlag)) != 0)
352 #define SET_FLAG(__Flag, __setFlag)                     ((__Flag) |= __setFlag)
353 #define CLEAR_FLAG(__Flag, __clearFlag)         ((__Flag) &= ~(__clearFlag))
354 #define CLEAR_FLAGS(__Flag)                                     ((__Flag) = 0)
355 #define TEST_FLAGS(__Flag, __testFlags)         (((__Flag) & (__testFlags)) == (__testFlags))
356
357 #endif //__BASIC_TYPES_H__
358