• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
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  *****************************************************************************/
15 #ifndef __BASIC_TYPES_H__
16 #define __BASIC_TYPES_H__
17 
18 
19 #define SUCCESS	0
20 #define FAIL	(-1)
21 
22 #ifndef TRUE
23 	#define _TRUE	1
24 #else
25 	#define _TRUE	TRUE
26 #endif
27 
28 #ifndef FALSE
29 	#define _FALSE	0
30 #else
31 	#define _FALSE	FALSE
32 #endif
33 
34 #ifdef PLATFORM_WINDOWS
35 
36 	typedef signed char s8;
37 	typedef unsigned char u8;
38 
39 	typedef signed short s16;
40 	typedef unsigned short u16;
41 
42 	typedef signed long s32;
43 	typedef unsigned long u32;
44 
45 	typedef unsigned int	uint;
46 	typedef	signed int		sint;
47 
48 
49 	typedef signed long long s64;
50 	typedef unsigned long long u64;
51 
52 	#ifdef NDIS50_MINIPORT
53 
54 		#define NDIS_MAJOR_VERSION       5
55 		#define NDIS_MINOR_VERSION       0
56 
57 	#endif
58 
59 	#ifdef NDIS51_MINIPORT
60 
61 		#define NDIS_MAJOR_VERSION       5
62 		#define NDIS_MINOR_VERSION       1
63 
64 	#endif
65 
66 	typedef NDIS_PROC proc_t;
67 
68 	typedef LONG atomic_t;
69 
70 #endif
71 
72 
73 #ifdef PLATFORM_LINUX
74 	#include <linux/version.h>
75 	#include <linux/types.h>
76 	#include <linux/module.h>
77 	#include <linux/kernel.h>
78 	#include <linux/init.h>
79 	#include <linux/utsname.h>
80 
81 	typedef	signed int sint;
82 
83 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
84 typedef _Bool bool;
85 
86 enum {
87 	false	= 0,
88 	true	= 1
89 };
90 #endif
91 
92 	typedef void (*proc_t)(void *);
93 
94 	typedef	__kernel_size_t	SIZE_T;
95 	typedef	__kernel_ssize_t	SSIZE_T;
96 	#define FIELD_OFFSET(s, field)	((SSIZE_T)&((s *)(0))->field)
97 
98 #define NDIS_OID uint
99 #endif /*PLATFORM_LINUX*/
100 
101 
102 #ifdef PLATFORM_FREEBSD
103 
104 	typedef signed char s8;
105 	typedef unsigned char u8;
106 
107 	typedef signed short s16;
108 	typedef unsigned short u16;
109 
110 	typedef signed int s32;
111 	typedef unsigned int u32;
112 
113 	typedef unsigned int	uint;
114 	typedef	signed int		sint;
115 	typedef long atomic_t;
116 
117 	typedef signed long long s64;
118 	typedef unsigned long long u64;
119 
120 	typedef u32 dma_addr_t;
121 
122 	typedef void (*proc_t)(void *);
123 
124 	typedef unsigned int __kernel_size_t;
125 	typedef int __kernel_ssize_t;
126 
127 	typedef	__kernel_size_t	SIZE_T;
128 	typedef	__kernel_ssize_t	SSIZE_T;
129 	#define FIELD_OFFSET(s, field)	((SSIZE_T)&((s *)(0))->field)
130 
131 #endif
132 
133 #define MEM_ALIGNMENT_OFFSET	(sizeof (SIZE_T))
134 #define MEM_ALIGNMENT_PADDING	(sizeof(SIZE_T) - 1)
135 
136 #define SIZE_PTR SIZE_T
137 #define SSIZE_PTR SSIZE_T
138 
139 /*
140 * Continuous bits starting from least significant bit
141 * Example:
142 * BIT_LEN_MASK_32(0) => 0x00000000
143 * BIT_LEN_MASK_32(1) => 0x00000001
144 * BIT_LEN_MASK_32(2) => 0x00000003
145 * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
146 */
147 #define BIT_LEN_MASK_32(__BitLen) ((u32)(0xFFFFFFFF >> (32 - (__BitLen))))
148 #define BIT_LEN_MASK_16(__BitLen) ((u16)(0xFFFF >> (16 - (__BitLen))))
149 #define BIT_LEN_MASK_8(__BitLen) ((u8)(0xFF >> (8 - (__BitLen))))
150 
151 /*
152 * Continuous bits starting from least significant bit
153 * Example:
154 * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
155 * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
156 */
157 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ((u32)(BIT_LEN_MASK_32(__BitLen) << (__BitOffset)))
158 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ((u16)(BIT_LEN_MASK_16(__BitLen) << (__BitOffset)))
159 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ((u8)(BIT_LEN_MASK_8(__BitLen) << (__BitOffset)))
160 
161 /*
162 * Convert LE data to host byte order
163 */
164 #define EF1Byte (u8)
165 #define EF2Byte le16_to_cpu
166 #define EF4Byte le32_to_cpu
167 
168 /*
169 * Read LE data from memory to host byte order
170 */
171 #define ReadLE4Byte(_ptr)	le32_to_cpu(*((u32 *)(_ptr)))
172 #define ReadLE2Byte(_ptr)	le16_to_cpu(*((u16 *)(_ptr)))
173 #define ReadLE1Byte(_ptr)	(*((u8 *)(_ptr)))
174 
175 /*
176 * Read BE data from memory to host byte order
177 */
178 #define ReadBEE4Byte(_ptr)	be32_to_cpu(*((u32 *)(_ptr)))
179 #define ReadBE2Byte(_ptr)	be16_to_cpu(*((u16 *)(_ptr)))
180 #define ReadBE1Byte(_ptr)	(*((u8 *)(_ptr)))
181 
182 /*
183 * Write host byte order data to memory in LE order
184 */
185 #define WriteLE4Byte(_ptr, _val)	((*((u32 *)(_ptr))) = cpu_to_le32(_val))
186 #define WriteLE2Byte(_ptr, _val)	((*((u16 *)(_ptr))) = cpu_to_le16(_val))
187 #define WriteLE1Byte(_ptr, _val)	((*((u8 *)(_ptr))) = ((u8)(_val)))
188 
189 /*
190 * Write host byte order data to memory in BE order
191 */
192 #define WriteBE4Byte(_ptr, _val)	((*((u32 *)(_ptr))) = cpu_to_be32(_val))
193 #define WriteBE2Byte(_ptr, _val)	((*((u16 *)(_ptr))) = cpu_to_be16(_val))
194 #define WriteBE1Byte(_ptr, _val)	((*((u8 *)(_ptr))) = ((u8)(_val)))
195 
196 /*
197 * Return 4-byte value in host byte ordering from 4-byte pointer in litten-endian system.
198 */
199 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) (le32_to_cpu(*((u32 *)(__pStart))))
200 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) (le16_to_cpu(*((u16 *)(__pStart))))
201 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
202 
203 /*
204 * Return 4-byte value in host byte ordering from 4-byte pointer in big-endian system.
205 */
206 #define BE_P4BYTE_TO_HOST_4BYTE(__pStart) (be32_to_cpu(*((u32 *)(__pStart))))
207 #define BE_P2BYTE_TO_HOST_2BYTE(__pStart) (be16_to_cpu(*((u16 *)(__pStart))))
208 #define BE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
209 
210 /*
211 * Translate subfield (continuous bits in little-endian) of 4-byte value in LE byte to
212 * 4-byte value in host byte ordering.
213 */
214 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
215 	((LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
216 
217 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
218 	((LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
219 
220 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
221 	((LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
222 
223 /*
224 * Translate subfield (continuous bits in big-endian) of 4-byte value in BE byte to
225 * 4-byte value in host byte ordering.
226 */
227 #define BE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
228 	((BE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
229 
230 #define BE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
231 	((BE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
232 
233 #define BE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
234 	((BE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
235 
236 /*
237 * Mask subfield (continuous bits in little-endian) of 4-byte value in LE byte oredering
238 * and return the result in 4-byte value in host byte ordering.
239 */
240 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
241 	(LE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
242 
243 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
244 	(LE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
245 
246 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
247 	(LE_P1BYTE_TO_HOST_1BYTE(__pStart) & ((u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))))
248 
249 /*
250 * Mask subfield (continuous bits in big-endian) of 4-byte value in BE byte oredering
251 * and return the result in 4-byte value in host byte ordering.
252 */
253 #define BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
254 	(BE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
255 
256 #define BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
257 	(BE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
258 
259 #define BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
260 	(BE_P1BYTE_TO_HOST_1BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen)))
261 
262 /*
263 * Set subfield of little-endian 4-byte value to specified value.
264 */
265 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
266 	do { \
267 		if (__BitOffset == 0 && __BitLen == 32) \
268 			WriteLE4Byte(__pStart, __Value); \
269 		else { \
270 			WriteLE4Byte(__pStart, \
271 				LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
272 				| \
273 				((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
274 			); \
275 		} \
276 	} while (0)
277 
278 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
279 	do { \
280 		if (__BitOffset == 0 && __BitLen == 16) \
281 			WriteLE2Byte(__pStart, __Value); \
282 		else { \
283 			WriteLE2Byte(__pStart, \
284 				LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
285 				| \
286 				((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
287 			); \
288 		} \
289 	} while (0)
290 
291 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
292 	do { \
293 		if (__BitOffset == 0 && __BitLen == 8) \
294 			WriteLE1Byte(__pStart, __Value); \
295 		else { \
296 			WriteLE1Byte(__pStart, \
297 				LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
298 				| \
299 				((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
300 			); \
301 		} \
302 	} while (0)
303 
304 /*
305 * Set subfield of big-endian 4-byte value to specified value.
306 */
307 #define SET_BITS_TO_BE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
308 	do { \
309 		if (__BitOffset == 0 && __BitLen == 32) \
310 			WriteBE4Byte(__pStart, __Value); \
311 		else { \
312 			WriteBE4Byte(__pStart, \
313 				BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
314 				| \
315 				((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
316 			); \
317 		} \
318 	} while (0)
319 
320 #define SET_BITS_TO_BE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
321 	do { \
322 		if (__BitOffset == 0 && __BitLen == 16) \
323 			WriteBE2Byte(__pStart, __Value); \
324 		else { \
325 			WriteBE2Byte(__pStart, \
326 				BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
327 				| \
328 				((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
329 			); \
330 		} \
331 	} while (0)
332 
333 #define SET_BITS_TO_BE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
334 	do { \
335 		if (__BitOffset == 0 && __BitLen == 8) \
336 			WriteBE1Byte(__pStart, __Value); \
337 		else { \
338 			WriteBE1Byte(__pStart, \
339 				BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
340 				| \
341 				((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
342 			); \
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, boolean;
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