net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / include / byteorder / swab.h
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 _LINUX_BYTEORDER_SWAB_H
21 #define _LINUX_BYTEORDER_SWAB_H
22
23 #if !defined(CONFIG_PLATFORM_MSTAR)
24 #ifndef __u16
25         typedef unsigned short __u16;
26 #endif
27
28 #ifndef __u32
29         typedef unsigned int    __u32;
30 #endif
31
32 #ifndef __u8
33         typedef unsigned char __u8;
34 #endif
35
36 #ifndef __u64
37         typedef unsigned long long      __u64;
38 #endif
39
40
41 __inline static __u16  ___swab16(__u16 x)
42 {
43         __u16 __x = x;
44         return
45                  (__u16)(
46                          (((__u16)(__x)&(__u16)0x00ffU) << 8) |
47                          (((__u16)(__x)&(__u16)0xff00U) >> 8));
48
49 }
50
51 __inline static __u32  ___swab32(__u32 x)
52 {
53         __u32 __x = (x);
54         return  (__u32)(
55                         (((__u32)(__x)&(__u32)0x000000ffUL) << 24) |
56                         (((__u32)(__x)&(__u32)0x0000ff00UL) <<  8) |
57                         (((__u32)(__x)&(__u32)0x00ff0000UL) >>  8) |
58                         (((__u32)(__x)&(__u32)0xff000000UL) >> 24));
59 }
60
61 __inline static __u64  ___swab64(__u64 x)
62 {
63         __u64 __x = (x);
64
65         return
66                  (__u64)(\
67                  (__u64)(((__u64)(__x)&(__u64)0x00000000000000ffULL) << 56) | \
68                  (__u64)(((__u64)(__x)&(__u64)0x000000000000ff00ULL) << 40) | \
69                  (__u64)(((__u64)(__x)&(__u64)0x0000000000ff0000ULL) << 24) | \
70                  (__u64)(((__u64)(__x)&(__u64)0x00000000ff000000ULL) <<  8) | \
71                  (__u64)(((__u64)(__x)&(__u64)0x000000ff00000000ULL) >>  8) | \
72                  (__u64)(((__u64)(__x)&(__u64)0x0000ff0000000000ULL) >> 24) | \
73                  (__u64)(((__u64)(__x)&(__u64)0x00ff000000000000ULL) >> 40) | \
74                  (__u64)(((__u64)(__x)&(__u64)0xff00000000000000ULL) >> 56));
75         \
76 }
77 #endif /* CONFIG_PLATFORM_MSTAR */
78
79 #ifndef __arch__swab16
80 __inline static __u16 __arch__swab16(__u16 x)
81 {
82         return ___swab16(x);
83 }
84
85 #endif
86
87 #ifndef __arch__swab32
88 __inline static __u32 __arch__swab32(__u32 x)
89 {
90         __u32 __tmp = (x) ;
91         return ___swab32(__tmp);
92 }
93 #endif
94
95 #ifndef __arch__swab64
96
97 __inline static __u64 __arch__swab64(__u64 x)
98 {
99         __u64 __tmp = (x) ;
100         return ___swab64(__tmp);
101 }
102
103
104 #endif
105
106 #ifndef __swab16
107         #define __swab16(x) __fswab16(x)
108         #define __swab32(x) __fswab32(x)
109         #define __swab64(x) __fswab64(x)
110 #endif /* __swab16 */
111
112 #ifdef PLATFORM_FREEBSD
113         __inline static __u16 __fswab16(__u16 x)
114 #else
115         __inline static const __u16 __fswab16(__u16 x)
116 #endif /* PLATFORM_FREEBSD */
117 {
118         return __arch__swab16(x);
119 }
120 #ifdef PLATFORM_FREEBSD
121         __inline static __u32 __fswab32(__u32 x)
122 #else
123         __inline static const __u32 __fswab32(__u32 x)
124 #endif /* PLATFORM_FREEBSD */
125 {
126         return __arch__swab32(x);
127 }
128
129 #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS)
130         #define swab16 __swab16
131         #define swab32 __swab32
132         #define swab64 __swab64
133         #define swab16p __swab16p
134         #define swab32p __swab32p
135         #define swab64p __swab64p
136         #define swab16s __swab16s
137         #define swab32s __swab32s
138         #define swab64s __swab64s
139 #endif
140
141 #endif /* _LINUX_BYTEORDER_SWAB_H */