net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / include / byteorder / swabb.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_SWABB_H
21 #define _LINUX_BYTEORDER_SWABB_H
22
23 /*
24  * linux/byteorder/swabb.h
25  * SWAp Bytes Bizarrely
26  *      swaHHXX[ps]?(foo)
27  *
28  * Support for obNUXIous pdp-endian and other bizarre architectures.
29  * Will Linux ever run on such ancient beasts? if not, this file
30  * will be but a programming pearl. Still, it's a reminder that we
31  * shouldn't be making too many assumptions when trying to be portable.
32  *
33  */
34
35 /*
36  * Meaning of the names I chose (vaxlinux people feel free to correct them):
37  * swahw32      swap 16-bit half-words in a 32-bit word
38  * swahb32      swap 8-bit halves of each 16-bit half-word in a 32-bit word
39  *
40  * No 64-bit support yet. I don't know NUXI conventions for long longs.
41  * I guarantee it will be a mess when it's there, though :->
42  * It will be even worse if there are conflicting 64-bit conventions.
43  * Hopefully, no one ever used 64-bit objects on NUXI machines.
44  *
45  */
46
47 #define ___swahw32(x) \
48         ({ \
49                 __u32 __x = (x); \
50                 ((__u32)(\
51                          (((__u32)(__x) & (__u32)0x0000ffffUL) << 16) | \
52                          (((__u32)(__x) & (__u32)0xffff0000UL) >> 16))); \
53         })
54 #define ___swahb32(x) \
55         ({ \
56                 __u32 __x = (x); \
57                 ((__u32)(\
58                          (((__u32)(__x) & (__u32)0x00ff00ffUL) << 8) | \
59                          (((__u32)(__x) & (__u32)0xff00ff00UL) >> 8))); \
60         })
61
62 #define ___constant_swahw32(x) \
63         ((__u32)(\
64                  (((__u32)(x) & (__u32)0x0000ffffUL) << 16) | \
65                  (((__u32)(x) & (__u32)0xffff0000UL) >> 16)))
66 #define ___constant_swahb32(x) \
67         ((__u32)(\
68                  (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | \
69                  (((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))
70
71 /*
72  * provide defaults when no architecture-specific optimization is detected
73  */
74 #ifndef __arch__swahw32
75         #define __arch__swahw32(x) ___swahw32(x)
76 #endif
77 #ifndef __arch__swahb32
78         #define __arch__swahb32(x) ___swahb32(x)
79 #endif
80
81 #ifndef __arch__swahw32p
82         #define __arch__swahw32p(x) __swahw32(*(x))
83 #endif
84 #ifndef __arch__swahb32p
85         #define __arch__swahb32p(x) __swahb32(*(x))
86 #endif
87
88 #ifndef __arch__swahw32s
89         #define __arch__swahw32s(x) do { *(x) = __swahw32p((x)); } while (0)
90 #endif
91 #ifndef __arch__swahb32s
92         #define __arch__swahb32s(x) do { *(x) = __swahb32p((x)); } while (0)
93 #endif
94
95
96 /*
97  * Allow constant folding
98  */
99 #if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
100 #  define __swahw32(x) \
101         (__builtin_constant_p((__u32)(x)) ? \
102          ___swahw32((x)) : \
103          __fswahw32((x)))
104 #  define __swahb32(x) \
105         (__builtin_constant_p((__u32)(x)) ? \
106          ___swahb32((x)) : \
107          __fswahb32((x)))
108 #else
109 #  define __swahw32(x) __fswahw32(x)
110 #  define __swahb32(x) __fswahb32(x)
111 #endif /* OPTIMIZE */
112
113
114 __inline static__ __const__ __u32 __fswahw32(__u32 x)
115 {
116         return __arch__swahw32(x);
117 }
118 __inline static__ __u32 __swahw32p(__u32 *x)
119 {
120         return __arch__swahw32p(x);
121 }
122 __inline static__ void __swahw32s(__u32 *addr)
123 {
124         __arch__swahw32s(addr);
125 }
126
127
128 __inline static__ __const__ __u32 __fswahb32(__u32 x)
129 {
130         return __arch__swahb32(x);
131 }
132 __inline static__ __u32 __swahb32p(__u32 *x)
133 {
134         return __arch__swahb32p(x);
135 }
136 __inline static__ void __swahb32s(__u32 *addr)
137 {
138         __arch__swahb32s(addr);
139 }
140
141 #ifdef __BYTEORDER_HAS_U64__
142         /*
143         * Not supported yet
144         */
145 #endif /* __BYTEORDER_HAS_U64__ */
146
147 #if defined(PLATFORM_LINUX)
148         #define swahw32 __swahw32
149         #define swahb32 __swahb32
150         #define swahw32p __swahw32p
151         #define swahb32p __swahb32p
152         #define swahw32s __swahw32s
153         #define swahb32s __swahb32s
154 #endif
155
156 #endif /* _LINUX_BYTEORDER_SWABB_H */