basic_types.h 11 KB

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