net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / 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         #include <linux/module.h>
82         #include <linux/kernel.h>
83         #include <linux/init.h>
84         #include <linux/utsname.h>
85         #define IN
86         #define OUT
87         #define VOID void
88         #define NDIS_OID uint
89         #define NDIS_STATUS uint
90
91         typedef signed int sint;
92
93         #ifndef PVOID
94                 typedef void *PVOID;
95                 /* #define PVOID        (void *) */
96         #endif
97
98         #define UCHAR u8
99         #define USHORT u16
100         #define UINT u32
101         #define ULONG u32
102
103         #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
104                 typedef _Bool bool;
105         #endif
106
107         typedef void (*proc_t)(void *);
108
109         typedef __kernel_size_t SIZE_T;
110         typedef __kernel_ssize_t        SSIZE_T;
111         #define FIELD_OFFSET(s, field)  ((SSIZE_T)&((s *)(0))->field)
112
113 #endif
114
115
116 #ifdef PLATFORM_FREEBSD
117
118         typedef signed char s8;
119         typedef unsigned char u8;
120
121         typedef signed short s16;
122         typedef unsigned short u16;
123
124         typedef signed int s32;
125         typedef unsigned int u32;
126
127         typedef unsigned int    uint;
128         typedef signed int              sint;
129         typedef long atomic_t;
130
131         typedef signed long long s64;
132         typedef unsigned long long u64;
133         #define IN
134         #define OUT
135         #define VOID void
136         #define NDIS_OID uint
137         #define NDIS_STATUS uint
138
139         #ifndef PVOID
140                 typedef void *PVOID;
141                 /* #define PVOID        (void *) */
142         #endif
143         typedef u32 dma_addr_t;
144         #define UCHAR u8
145         #define USHORT u16
146         #define UINT u32
147         #define ULONG u32
148
149         typedef void (*proc_t)(void *);
150
151         typedef unsigned int __kernel_size_t;
152         typedef int __kernel_ssize_t;
153
154         typedef __kernel_size_t SIZE_T;
155         typedef __kernel_ssize_t        SSIZE_T;
156         #define FIELD_OFFSET(s, field)  ((SSIZE_T)&((s *)(0))->field)
157
158 #endif
159
160 #define MEM_ALIGNMENT_OFFSET    (sizeof (SIZE_T))
161 #define MEM_ALIGNMENT_PADDING   (sizeof(SIZE_T) - 1)
162
163 #define SIZE_PTR SIZE_T
164 #define SSIZE_PTR SSIZE_T
165
166 /*
167 * Continuous bits starting from least significant bit
168 * Example:
169 * BIT_LEN_MASK_32(0) => 0x00000000
170 * BIT_LEN_MASK_32(1) => 0x00000001
171 * BIT_LEN_MASK_32(2) => 0x00000003
172 * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
173 */
174 #define BIT_LEN_MASK_32(__BitLen) ((u32)(0xFFFFFFFF >> (32 - (__BitLen))))
175 #define BIT_LEN_MASK_16(__BitLen) ((u16)(0xFFFF >> (16 - (__BitLen))))
176 #define BIT_LEN_MASK_8(__BitLen) ((u8)(0xFF >> (8 - (__BitLen))))
177
178 /*
179 * Continuous bits starting from least significant bit
180 * Example:
181 * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
182 * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
183 */
184 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ((u32)(BIT_LEN_MASK_32(__BitLen) << (__BitOffset)))
185 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ((u16)(BIT_LEN_MASK_16(__BitLen) << (__BitOffset)))
186 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ((u8)(BIT_LEN_MASK_8(__BitLen) << (__BitOffset)))
187
188 /*
189 * Convert LE data to host byte order
190 */
191 #define EF1Byte (u8)
192 #define EF2Byte le16_to_cpu
193 #define EF4Byte le32_to_cpu
194
195 /*
196 * Read LE data from memory to host byte order
197 */
198 #define ReadLE4Byte(_ptr)       le32_to_cpu(*((u32 *)(_ptr)))
199 #define ReadLE2Byte(_ptr)       le16_to_cpu(*((u16 *)(_ptr)))
200 #define ReadLE1Byte(_ptr)       (*((u8 *)(_ptr)))
201
202 /*
203 * Read BE data from memory to host byte order
204 */
205 #define ReadBEE4Byte(_ptr)      be32_to_cpu(*((u32 *)(_ptr)))
206 #define ReadBE2Byte(_ptr)       be16_to_cpu(*((u16 *)(_ptr)))
207 #define ReadBE1Byte(_ptr)       (*((u8 *)(_ptr)))
208
209 /*
210 * Write host byte order data to memory in LE order
211 */
212 #define WriteLE4Byte(_ptr, _val)        ((*((u32 *)(_ptr))) = cpu_to_le32(_val))
213 #define WriteLE2Byte(_ptr, _val)        ((*((u16 *)(_ptr))) = cpu_to_le16(_val))
214 #define WriteLE1Byte(_ptr, _val)        ((*((u8 *)(_ptr))) = ((u8)(_val)))
215
216 /*
217 * Write host byte order data to memory in BE order
218 */
219 #define WriteBE4Byte(_ptr, _val)        ((*((u32 *)(_ptr))) = cpu_to_be32(_val))
220 #define WriteBE2Byte(_ptr, _val)        ((*((u16 *)(_ptr))) = cpu_to_be16(_val))
221 #define WriteBE1Byte(_ptr, _val)        ((*((u8 *)(_ptr))) = ((u8)(_val)))
222
223 /*
224 * Return 4-byte value in host byte ordering from 4-byte pointer in litten-endian system.
225 */
226 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) (le32_to_cpu(*((u32 *)(__pStart))))
227 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) (le16_to_cpu(*((u16 *)(__pStart))))
228 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
229
230 /*
231 * Return 4-byte value in host byte ordering from 4-byte pointer in big-endian system.
232 */
233 #define BE_P4BYTE_TO_HOST_4BYTE(__pStart) (be32_to_cpu(*((u32 *)(__pStart))))
234 #define BE_P2BYTE_TO_HOST_2BYTE(__pStart) (be16_to_cpu(*((u16 *)(__pStart))))
235 #define BE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
236
237 /*
238 * Translate subfield (continuous bits in little-endian) of 4-byte value in LE byte to
239 * 4-byte value in host byte ordering.
240 */
241 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
242         ((LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
243
244 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
245         ((LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
246
247 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
248         ((LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
249
250 /*
251 * Translate subfield (continuous bits in big-endian) of 4-byte value in BE byte to
252 * 4-byte value in host byte ordering.
253 */
254 #define BE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
255         ((BE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
256
257 #define BE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
258         ((BE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
259
260 #define BE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
261         ((BE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
262
263 /*
264 * Mask subfield (continuous bits in little-endian) of 4-byte value in LE byte oredering
265 * and return the result in 4-byte value in host byte ordering.
266 */
267 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
268         (LE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
269
270 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
271         (LE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
272
273 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
274         (LE_P1BYTE_TO_HOST_1BYTE(__pStart) & ((u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))))
275
276 /*
277 * Mask subfield (continuous bits in big-endian) of 4-byte value in BE byte oredering
278 * and return the result in 4-byte value in host byte ordering.
279 */
280 #define BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
281         (BE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
282
283 #define BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
284         (BE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
285
286 #define BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
287         (BE_P1BYTE_TO_HOST_1BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen)))
288
289 /*
290 * Set subfield of little-endian 4-byte value to specified value.
291 */
292 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
293         do { \
294                 if (__BitOffset == 0 && __BitLen == 32) \
295                         WriteLE4Byte(__pStart, __Value); \
296                 else { \
297                         WriteLE4Byte(__pStart, \
298                                 LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
299                                 | \
300                                 ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
301                         ); \
302                 } \
303         } while (0)
304
305 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
306         do { \
307                 if (__BitOffset == 0 && __BitLen == 16) \
308                         WriteLE2Byte(__pStart, __Value); \
309                 else { \
310                         WriteLE2Byte(__pStart, \
311                                 LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
312                                 | \
313                                 ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
314                         ); \
315                 } \
316         } while (0)
317
318 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
319         do { \
320                 if (__BitOffset == 0 && __BitLen == 8) \
321                         WriteLE1Byte(__pStart, __Value); \
322                 else { \
323                         WriteLE1Byte(__pStart, \
324                                 LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
325                                 | \
326                                 ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
327                         ); \
328                 } \
329         } while (0)
330
331 /*
332 * Set subfield of big-endian 4-byte value to specified value.
333 */
334 #define SET_BITS_TO_BE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
335         do { \
336                 if (__BitOffset == 0 && __BitLen == 32) \
337                         WriteBE4Byte(__pStart, __Value); \
338                 else { \
339                         WriteBE4Byte(__pStart, \
340                                 BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
341                                 | \
342                                 ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
343                         ); \
344                 } \
345         } while (0)
346
347 #define SET_BITS_TO_BE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
348         do { \
349                 if (__BitOffset == 0 && __BitLen == 16) \
350                         WriteBE2Byte(__pStart, __Value); \
351                 else { \
352                         WriteBE2Byte(__pStart, \
353                                 BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
354                                 | \
355                                 ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
356                         ); \
357                 } \
358         } while (0)
359
360 #define SET_BITS_TO_BE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
361         do { \
362                 if (__BitOffset == 0 && __BitLen == 8) \
363                         WriteBE1Byte(__pStart, __Value); \
364                 else { \
365                         WriteBE1Byte(__pStart, \
366                                 BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
367                                 | \
368                                 ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
369                         ); \
370                 } \
371         } while (0)
372
373 /* Get the N-bytes aligment offset from the current length */
374 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
375
376 typedef unsigned char   BOOLEAN, *PBOOLEAN, boolean;
377
378 #define TEST_FLAG(__Flag, __testFlag)           (((__Flag) & (__testFlag)) != 0)
379 #define SET_FLAG(__Flag, __setFlag)                     ((__Flag) |= __setFlag)
380 #define CLEAR_FLAG(__Flag, __clearFlag)         ((__Flag) &= ~(__clearFlag))
381 #define CLEAR_FLAGS(__Flag)                                     ((__Flag) = 0)
382 #define TEST_FLAGS(__Flag, __testFlags)         (((__Flag) & (__testFlags)) == (__testFlags))
383
384 #endif /* __BASIC_TYPES_H__ */