Linux 3.3-rc6
[linux/fpc-iii.git] / drivers / staging / rtl8712 / swab.h
blobf12781829c1b0c732dca745f025b29bd25976754
1 /******************************************************************************
3 * Copyright(c) 2007 - 2010 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
12 * more details.
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
18 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
25 ******************************************************************************/
26 #ifndef _LINUX_BYTEORDER_SWAB_H
27 #define _LINUX_BYTEORDER_SWAB_H
29 #ifndef __u16
30 #define __u16 unsigned short
31 #endif
33 #ifndef __u32
34 #define __u32 unsigned int
35 #endif
37 #ifndef __u8
38 #define __u8 unsigned char
39 #endif
41 #ifndef __u64
42 #define __u64 unsigned long long
43 #endif
46 static inline __u16 ___swab16(__u16 x)
48 __u16 __x = x;
49 return (__u16)(
50 (((__u16)(__x) & (__u16)0x00ffU) << 8) |
51 (((__u16)(__x) & (__u16)0xff00U) >> 8));
55 static inline __u32 ___swab32(__u32 x)
57 __u32 __x = (x);
58 return (__u32)(
59 (((__u32)(__x) & (__u32)0x000000ffUL) << 24) |
60 (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) |
61 (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) |
62 (((__u32)(__x) & (__u32)0xff000000UL) >> 24));
65 static inline __u64 ___swab64(__u64 x)
67 __u64 __x = (x);
69 return (__u64)( \
70 (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \
71 (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \
72 (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \
73 (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \
74 (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \
75 (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
76 (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
77 (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56));
80 #ifndef __arch__swab16
81 static inline __u16 __arch__swab16(__u16 x)
83 return ___swab16(x);
86 #endif
88 #ifndef __arch__swab32
89 static inline __u32 __arch__swab32(__u32 x)
91 __u32 __tmp = (x) ;
92 return ___swab32(__tmp);
94 #endif
96 #ifndef __arch__swab64
98 static inline __u64 __arch__swab64(__u64 x)
100 __u64 __tmp = (x) ;
101 return ___swab64(__tmp);
105 #endif
107 #define __swab16(x) __fswab16(x)
108 #define __swab32(x) __fswab32(x)
109 #define __swab64(x) __fswab64(x)
111 static inline const __u16 __fswab16(__u16 x)
113 return __arch__swab16(x);
115 static inline const __u32 __fswab32(__u32 x)
117 return __arch__swab32(x);
120 #define swab16 __swab16
121 #define swab32 __swab32
122 #define swab64 __swab64
123 #define swab16p __swab16p
124 #define swab32p __swab32p
125 #define swab64p __swab64p
126 #define swab16s __swab16s
127 #define swab32s __swab32s
128 #define swab64s __swab64s
130 #endif /* _LINUX_BYTEORDER_SWAB_H */