Wifi: add rtl8723au & rtl8723bu wifi support.
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / include / byteorder / generic.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_GENERIC_H
21 #define _LINUX_BYTEORDER_GENERIC_H
22
23 /*
24  * linux/byteorder_generic.h
25  * Generic Byte-reordering support
26  *
27  * Francois-Rene Rideau <fare@tunes.org> 19970707
28  *    gathered all the good ideas from all asm-foo/byteorder.h into one file,
29  *    cleaned them up.
30  *    I hope it is compliant with non-GCC compilers.
31  *    I decided to put __BYTEORDER_HAS_U64__ in byteorder.h,
32  *    because I wasn't sure it would be ok to put it in types.h
33  *    Upgraded it to 2.1.43
34  * Francois-Rene Rideau <fare@tunes.org> 19971012
35  *    Upgraded it to 2.1.57
36  *    to please Linus T., replaced huge #ifdef's between little/big endian
37  *    by nestedly #include'd files.
38  * Francois-Rene Rideau <fare@tunes.org> 19971205
39  *    Made it to 2.1.71; now a facelift:
40  *    Put files under include/linux/byteorder/
41  *    Split swab from generic support.
42  *
43  * TODO:
44  *   = Regular kernel maintainers could also replace all these manual
45  *    byteswap macros that remain, disseminated among drivers,
46  *    after some grep or the sources...
47  *   = Linus might want to rename all these macros and files to fit his taste,
48  *    to fit his personal naming scheme.
49  *   = it seems that a few drivers would also appreciate
50  *    nybble swapping support...
51  *   = every architecture could add their byteswap macro in asm/byteorder.h
52  *    see how some architectures already do (i386, alpha, ppc, etc)
53  *   = cpu_to_beXX and beXX_to_cpu might some day need to be well
54  *    distinguished throughout the kernel. This is not the case currently,
55  *    since little endian, big endian, and pdp endian machines needn't it.
56  *    But this might be the case for, say, a port of Linux to 20/21 bit
57  *    architectures (and F21 Linux addict around?).
58  */
59
60 /*
61  * The following macros are to be defined by <asm/byteorder.h>:
62  *
63  * Conversion of long and short int between network and host format
64  *      ntohl(__u32 x)
65  *      ntohs(__u16 x)
66  *      htonl(__u32 x)
67  *      htons(__u16 x)
68  * It seems that some programs (which? where? or perhaps a standard? POSIX?)
69  * might like the above to be functions, not macros (why?).
70  * if that's true, then detect them, and take measures.
71  * Anyway, the measure is: define only ___ntohl as a macro instead,
72  * and in a separate file, have
73  * unsigned long inline ntohl(x){return ___ntohl(x);}
74  *
75  * The same for constant arguments
76  *      __constant_ntohl(__u32 x)
77  *      __constant_ntohs(__u16 x)
78  *      __constant_htonl(__u32 x)
79  *      __constant_htons(__u16 x)
80  *
81  * Conversion of XX-bit integers (16- 32- or 64-)
82  * between native CPU format and little/big endian format
83  * 64-bit stuff only defined for proper architectures
84  *      cpu_to_[bl]eXX(__uXX x)
85  *      [bl]eXX_to_cpu(__uXX x)
86  *
87  * The same, but takes a pointer to the value to convert
88  *      cpu_to_[bl]eXXp(__uXX x)
89  *      [bl]eXX_to_cpup(__uXX x)
90  *
91  * The same, but change in situ
92  *      cpu_to_[bl]eXXs(__uXX x)
93  *      [bl]eXX_to_cpus(__uXX x)
94  *
95  * See asm-foo/byteorder.h for examples of how to provide
96  * architecture-optimized versions
97  *
98  */
99
100
101 #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_MPIXEL) || defined(PLATFORM_FREEBSD)
102 /*
103  * inside the kernel, we can use nicknames;
104  * outside of it, we must avoid POSIX namespace pollution...
105  */
106 #define cpu_to_le64 __cpu_to_le64
107 #define le64_to_cpu __le64_to_cpu
108 #define cpu_to_le32 __cpu_to_le32
109 #define le32_to_cpu __le32_to_cpu
110 #define cpu_to_le16 __cpu_to_le16
111 #define le16_to_cpu __le16_to_cpu
112 #define cpu_to_be64 __cpu_to_be64
113 #define be64_to_cpu __be64_to_cpu
114 #define cpu_to_be32 __cpu_to_be32
115 #define be32_to_cpu __be32_to_cpu
116 #define cpu_to_be16 __cpu_to_be16
117 #define be16_to_cpu __be16_to_cpu
118 #define cpu_to_le64p __cpu_to_le64p
119 #define le64_to_cpup __le64_to_cpup
120 #define cpu_to_le32p __cpu_to_le32p
121 #define le32_to_cpup __le32_to_cpup
122 #define cpu_to_le16p __cpu_to_le16p
123 #define le16_to_cpup __le16_to_cpup
124 #define cpu_to_be64p __cpu_to_be64p
125 #define be64_to_cpup __be64_to_cpup
126 #define cpu_to_be32p __cpu_to_be32p
127 #define be32_to_cpup __be32_to_cpup
128 #define cpu_to_be16p __cpu_to_be16p
129 #define be16_to_cpup __be16_to_cpup
130 #define cpu_to_le64s __cpu_to_le64s
131 #define le64_to_cpus __le64_to_cpus
132 #define cpu_to_le32s __cpu_to_le32s
133 #define le32_to_cpus __le32_to_cpus
134 #define cpu_to_le16s __cpu_to_le16s
135 #define le16_to_cpus __le16_to_cpus
136 #define cpu_to_be64s __cpu_to_be64s
137 #define be64_to_cpus __be64_to_cpus
138 #define cpu_to_be32s __cpu_to_be32s
139 #define be32_to_cpus __be32_to_cpus
140 #define cpu_to_be16s __cpu_to_be16s
141 #define be16_to_cpus __be16_to_cpus
142 #endif
143
144
145 /*
146  * Handle ntohl and suches. These have various compatibility
147  * issues - like we want to give the prototype even though we
148  * also have a macro for them in case some strange program
149  * wants to take the address of the thing or something..
150  *
151  * Note that these used to return a "long" in libc5, even though
152  * long is often 64-bit these days.. Thus the casts.
153  *
154  * They have to be macros in order to do the constant folding
155  * correctly - if the argument passed into a inline function
156  * it is no longer constant according to gcc..
157  */
158
159 #undef ntohl
160 #undef ntohs
161 #undef htonl
162 #undef htons
163
164 /*
165  * Do the prototypes. Somebody might want to take the
166  * address or some such sick thing..
167  */
168 #if defined(PLATFORM_LINUX) || (defined (__GLIBC__) && __GLIBC__ >= 2)
169 extern __u32                    ntohl(__u32);
170 extern __u32                    htonl(__u32);
171 #else //defined(PLATFORM_LINUX) || (defined (__GLIBC__) && __GLIBC__ >= 2)
172 #ifndef PLATFORM_FREEBSD
173 extern unsigned long int        ntohl(unsigned long int);
174 extern unsigned long int        htonl(unsigned long int);
175 #endif
176 #endif
177 #ifndef PLATFORM_FREEBSD
178 extern unsigned short int       ntohs(unsigned short int);
179 extern unsigned short int       htons(unsigned short int);
180 #endif
181
182 #if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__) ||  defined(PLATFORM_MPIXEL)
183
184 #define ___htonl(x) __cpu_to_be32(x)
185 #define ___htons(x) __cpu_to_be16(x)
186 #define ___ntohl(x) __be32_to_cpu(x)
187 #define ___ntohs(x) __be16_to_cpu(x)
188
189 #if defined(PLATFORM_LINUX) || (defined (__GLIBC__) && __GLIBC__ >= 2)
190 #define htonl(x) ___htonl(x)
191 #define ntohl(x) ___ntohl(x)
192 #else
193 #define htonl(x) ((unsigned long)___htonl(x))
194 #define ntohl(x) ((unsigned long)___ntohl(x))
195 #endif
196 #define htons(x) ___htons(x)
197 #define ntohs(x) ___ntohs(x)
198
199 #endif /* OPTIMIZE */
200
201
202 #if defined (PLATFORM_WINDOWS)
203
204 #define htonl(x) __cpu_to_be32(x)
205 #define ntohl(x) __be32_to_cpu(x)
206 #define htons(x) __cpu_to_be16(x)
207 #define ntohs(x) __be16_to_cpu(x)
208
209
210 #endif
211
212 #endif /* _LINUX_BYTEORDER_GENERIC_H */
213