1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
20 #ifndef __BASIC_TYPES_H__
21 #define __BASIC_TYPES_H__
39 #ifdef PLATFORM_WINDOWS
41 typedef signed char s8;
42 typedef unsigned char u8;
44 typedef signed short s16;
45 typedef unsigned short u16;
47 typedef signed long s32;
48 typedef unsigned long u32;
50 typedef unsigned int uint;
51 typedef signed int sint;
54 typedef signed long long s64;
55 typedef unsigned long long u64;
57 #ifdef NDIS50_MINIPORT
59 #define NDIS_MAJOR_VERSION 5
60 #define NDIS_MINOR_VERSION 0
64 #ifdef NDIS51_MINIPORT
66 #define NDIS_MAJOR_VERSION 5
67 #define NDIS_MINOR_VERSION 1
71 typedef NDIS_PROC proc_t;
73 typedef LONG atomic_t;
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>
89 #define NDIS_STATUS uint
91 typedef signed int sint;
95 /* #define PVOID (void *) */
103 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
107 typedef void (*proc_t)(void *);
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)
116 #ifdef PLATFORM_FREEBSD
118 typedef signed char s8;
119 typedef unsigned char u8;
121 typedef signed short s16;
122 typedef unsigned short u16;
124 typedef signed int s32;
125 typedef unsigned int u32;
127 typedef unsigned int uint;
128 typedef signed int sint;
129 typedef long atomic_t;
131 typedef signed long long s64;
132 typedef unsigned long long u64;
136 #define NDIS_OID uint
137 #define NDIS_STATUS uint
141 /* #define PVOID (void *) */
143 typedef u32 dma_addr_t;
149 typedef void (*proc_t)(void *);
151 typedef unsigned int __kernel_size_t;
152 typedef int __kernel_ssize_t;
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)
160 #define MEM_ALIGNMENT_OFFSET (sizeof (SIZE_T))
161 #define MEM_ALIGNMENT_PADDING (sizeof(SIZE_T) - 1)
163 #define SIZE_PTR SIZE_T
164 #define SSIZE_PTR SSIZE_T
167 * Continuous bits starting from least significant bit
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
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))))
179 * Continuous bits starting from least significant bit
181 * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
182 * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
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)))
189 * Convert LE data to host byte order
192 #define EF2Byte le16_to_cpu
193 #define EF4Byte le32_to_cpu
196 * Read LE data from memory to host byte order
198 #define ReadLE4Byte(_ptr) le32_to_cpu(*((u32 *)(_ptr)))
199 #define ReadLE2Byte(_ptr) le16_to_cpu(*((u16 *)(_ptr)))
200 #define ReadLE1Byte(_ptr) (*((u8 *)(_ptr)))
203 * Read BE data from memory to host byte order
205 #define ReadBEE4Byte(_ptr) be32_to_cpu(*((u32 *)(_ptr)))
206 #define ReadBE2Byte(_ptr) be16_to_cpu(*((u16 *)(_ptr)))
207 #define ReadBE1Byte(_ptr) (*((u8 *)(_ptr)))
210 * Write host byte order data to memory in LE order
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)))
217 * Write host byte order data to memory in BE order
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)))
224 * Return 4-byte value in host byte ordering from 4-byte pointer in litten-endian system.
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))))
231 * Return 4-byte value in host byte ordering from 4-byte pointer in big-endian system.
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))))
238 * Translate subfield (continuous bits in little-endian) of 4-byte value in LE byte to
239 * 4-byte value in host byte ordering.
241 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
242 ((LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
244 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
245 ((LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
247 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
248 ((LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
251 * Translate subfield (continuous bits in big-endian) of 4-byte value in BE byte to
252 * 4-byte value in host byte ordering.
254 #define BE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
255 ((BE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
257 #define BE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
258 ((BE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
260 #define BE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
261 ((BE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
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.
267 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
268 (LE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
270 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
271 (LE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
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))))
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.
280 #define BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
281 (BE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
283 #define BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
284 (BE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
286 #define BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
287 (BE_P1BYTE_TO_HOST_1BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen)))
290 * Set subfield of little-endian 4-byte value to specified value.
292 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
294 if (__BitOffset == 0 && __BitLen == 32) \
295 WriteLE4Byte(__pStart, __Value); \
297 WriteLE4Byte(__pStart, \
298 LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
300 ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
305 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
307 if (__BitOffset == 0 && __BitLen == 16) \
308 WriteLE2Byte(__pStart, __Value); \
310 WriteLE2Byte(__pStart, \
311 LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
313 ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
318 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
320 if (__BitOffset == 0 && __BitLen == 8) \
321 WriteLE1Byte(__pStart, __Value); \
323 WriteLE1Byte(__pStart, \
324 LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
326 ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
332 * Set subfield of big-endian 4-byte value to specified value.
334 #define SET_BITS_TO_BE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
336 if (__BitOffset == 0 && __BitLen == 32) \
337 WriteBE4Byte(__pStart, __Value); \
339 WriteBE4Byte(__pStart, \
340 BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
342 ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
347 #define SET_BITS_TO_BE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
349 if (__BitOffset == 0 && __BitLen == 16) \
350 WriteBE2Byte(__pStart, __Value); \
352 WriteBE2Byte(__pStart, \
353 BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
355 ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
360 #define SET_BITS_TO_BE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
362 if (__BitOffset == 0 && __BitLen == 8) \
363 WriteBE1Byte(__pStart, __Value); \
365 WriteBE1Byte(__pStart, \
366 BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
368 ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
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))
376 typedef unsigned char BOOLEAN, *PBOOLEAN, boolean;
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))
384 #endif /* __BASIC_TYPES_H__ */