xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189es/include/basic_types.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 //port from fw by thomas
167 // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
168 
169 /*
170  *	Call endian free function when
171  *		1. Read/write packet content.
172  *		2. Before write integer to IO.
173  *		3. After read integer from IO.
174 */
175 
176 //
177 // Byte Swapping routine.
178 //
179 #define EF1Byte	(u8)
180 #define EF2Byte 	le16_to_cpu
181 #define EF4Byte	le32_to_cpu
182 
183 //
184 // Read LE format data from memory
185 //
186 #define ReadEF1Byte(_ptr)		EF1Byte(*((u8 *)(_ptr)))
187 #define ReadEF2Byte(_ptr)		EF2Byte(*((u16 *)(_ptr)))
188 #define ReadEF4Byte(_ptr)		EF4Byte(*((u32 *)(_ptr)))
189 
190 //
191 // Write LE data to memory
192 //
193 #define WriteEF1Byte(_ptr, _val)	(*((u8 *)(_ptr)))=EF1Byte(_val)
194 #define WriteEF2Byte(_ptr, _val)	(*((u16 *)(_ptr)))=EF2Byte(_val)
195 #define WriteEF4Byte(_ptr, _val)	(*((u32 *)(_ptr)))=EF4Byte(_val)
196 
197 //
198 //	Example:
199 //		BIT_LEN_MASK_32(0) => 0x00000000
200 //		BIT_LEN_MASK_32(1) => 0x00000001
201 //		BIT_LEN_MASK_32(2) => 0x00000003
202 //		BIT_LEN_MASK_32(32) => 0xFFFFFFFF
203 //
204 #define BIT_LEN_MASK_32(__BitLen) \
205 	(0xFFFFFFFF >> (32 - (__BitLen)))
206 //
207 //	Example:
208 //		BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
209 //		BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
210 //
211 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
212 	(BIT_LEN_MASK_32(__BitLen) << (__BitOffset))
213 
214 //
215 //	Description:
216 //		Return 4-byte value in host byte ordering from
217 //		4-byte pointer in litten-endian system.
218 //
219 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
220 	(EF4Byte(*((u32 *)(__pStart))))
221 
222 //
223 //	Description:
224 //		Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
225 //		4-byte value in host byte ordering.
226 //
227 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
228 	( \
229 		( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
230 		& \
231 		BIT_LEN_MASK_32(__BitLen) \
232 	)
233 
234 //
235 //	Description:
236 //		Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering
237 //		and return the result in 4-byte value in host byte ordering.
238 //
239 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
240 	( \
241 		LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
242 		& \
243 		( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
244 	)
245 
246 //
247 //	Description:
248 //		Set subfield of little-endian 4-byte value to specified value.
249 //
250 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
251 	*((u32 *)(__pStart)) = \
252 		EF4Byte( \
253 			LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
254 			| \
255 			( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
256 		);
257 
258 
259 #define BIT_LEN_MASK_16(__BitLen) \
260 		(0xFFFF >> (16 - (__BitLen)))
261 
262 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
263 	(BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
264 
265 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
266 	(EF2Byte(*((u16 *)(__pStart))))
267 
268 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
269 	( \
270 		( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
271 		& \
272 		BIT_LEN_MASK_16(__BitLen) \
273 	)
274 
275 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
276 	( \
277 		LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
278 		& \
279 		(u16)(~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen))\
280 	)
281 
282 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
283 	*((u16 *)(__pStart)) = \
284 		EF2Byte( \
285 			LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
286 			| \
287 			( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
288 		);
289 
290 #define BIT_LEN_MASK_8(__BitLen) \
291 		(0xFF >> (8 - (__BitLen)))
292 
293 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
294 	(BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
295 
296 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
297 	(EF1Byte(*((u8 *)(__pStart))))
298 
299 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
300 	( \
301 		( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
302 		& \
303 		BIT_LEN_MASK_8(__BitLen) \
304 	)
305 
306 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
307 	( \
308 		LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
309 		& \
310 		(u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))\
311 	)
312 
313 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
314 do { \
315 	*((u8 *)(__pStart)) = \
316 		EF1Byte( \
317 			LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
318 			| \
319 			( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
320 		); \
321 } while (0)
322 
323 
324 #define LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
325 	( \
326 		LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
327 	)
328 
329 #define SET_BITS_TO_LE_2BYTE_16BIT(__pStart, __BitOffset, __BitLen, __Value) \
330 	*((u16 *)(__pStart)) = \
331 		EF2Byte( \
332 			LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
333 			| \
334 			( (u16)__Value) \
335 		);
336 
337 #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
338 	( \
339 		LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
340 	)
341 
342 #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
343 do { \
344 	*((u8 *)(__pStart)) = \
345 		EF1Byte( \
346 			LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
347 			| \
348 			((u8)__Value) \
349 		); \
350 } while (0)
351 
352 // Get the N-bytes aligment offset from the current length
353 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
354 
355 typedef unsigned char	BOOLEAN,*PBOOLEAN;
356 
357 #define TEST_FLAG(__Flag,__testFlag)		(((__Flag) & (__testFlag)) != 0)
358 #define SET_FLAG(__Flag, __setFlag)			((__Flag) |= __setFlag)
359 #define CLEAR_FLAG(__Flag, __clearFlag)		((__Flag) &= ~(__clearFlag))
360 #define CLEAR_FLAGS(__Flag)					((__Flag) = 0)
361 #define TEST_FLAGS(__Flag, __testFlags)		(((__Flag) & (__testFlags)) == (__testFlags))
362 
363 #endif //__BASIC_TYPES_H__
364 
365