Path: blob/master/ALFA-W1F1/RTL8814AU/include/byteorder/generic.h
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#ifndef _LINUX_BYTEORDER_GENERIC_H15#define _LINUX_BYTEORDER_GENERIC_H1617/*18* linux/byteorder_generic.h19* Generic Byte-reordering support20*21* Francois-Rene Rideau <[email protected]> 1997070722* gathered all the good ideas from all asm-foo/byteorder.h into one file,23* cleaned them up.24* I hope it is compliant with non-GCC compilers.25* I decided to put __BYTEORDER_HAS_U64__ in byteorder.h,26* because I wasn't sure it would be ok to put it in types.h27* Upgraded it to 2.1.4328* Francois-Rene Rideau <[email protected]> 1997101229* Upgraded it to 2.1.5730* to please Linus T., replaced huge #ifdef's between little/big endian31* by nestedly #include'd files.32* Francois-Rene Rideau <[email protected]> 1997120533* Made it to 2.1.71; now a facelift:34* Put files under include/linux/byteorder/35* Split swab from generic support.36*37* TODO:38* = Regular kernel maintainers could also replace all these manual39* byteswap macros that remain, disseminated among drivers,40* after some grep or the sources...41* = Linus might want to rename all these macros and files to fit his taste,42* to fit his personal naming scheme.43* = it seems that a few drivers would also appreciate44* nybble swapping support...45* = every architecture could add their byteswap macro in asm/byteorder.h46* see how some architectures already do (i386, alpha, ppc, etc)47* = cpu_to_beXX and beXX_to_cpu might some day need to be well48* distinguished throughout the kernel. This is not the case currently,49* since little endian, big endian, and pdp endian machines needn't it.50* But this might be the case for, say, a port of Linux to 20/21 bit51* architectures (and F21 Linux addict around?).52*/5354/*55* The following macros are to be defined by <asm/byteorder.h>:56*57* Conversion of long and short int between network and host format58* ntohl(__u32 x)59* ntohs(__u16 x)60* htonl(__u32 x)61* htons(__u16 x)62* It seems that some programs (which? where? or perhaps a standard? POSIX?)63* might like the above to be functions, not macros (why?).64* if that's true, then detect them, and take measures.65* Anyway, the measure is: define only ___ntohl as a macro instead,66* and in a separate file, have67* unsigned long inline ntohl(x){return ___ntohl(x);}68*69* The same for constant arguments70* __constant_ntohl(__u32 x)71* __constant_ntohs(__u16 x)72* __constant_htonl(__u32 x)73* __constant_htons(__u16 x)74*75* Conversion of XX-bit integers (16- 32- or 64-)76* between native CPU format and little/big endian format77* 64-bit stuff only defined for proper architectures78* cpu_to_[bl]eXX(__uXX x)79* [bl]eXX_to_cpu(__uXX x)80*81* The same, but takes a pointer to the value to convert82* cpu_to_[bl]eXXp(__uXX x)83* [bl]eXX_to_cpup(__uXX x)84*85* The same, but change in situ86* cpu_to_[bl]eXXs(__uXX x)87* [bl]eXX_to_cpus(__uXX x)88*89* See asm-foo/byteorder.h for examples of how to provide90* architecture-optimized versions91*92*/939495#if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_MPIXEL) || defined(PLATFORM_FREEBSD)96/*97* inside the kernel, we can use nicknames;98* outside of it, we must avoid POSIX namespace pollution...99*/100#define cpu_to_le64 __cpu_to_le64101#define le64_to_cpu __le64_to_cpu102#define cpu_to_le32 __cpu_to_le32103#define le32_to_cpu __le32_to_cpu104#define cpu_to_le16 __cpu_to_le16105#define le16_to_cpu __le16_to_cpu106#define cpu_to_be64 __cpu_to_be64107#define be64_to_cpu __be64_to_cpu108#define cpu_to_be32 __cpu_to_be32109#define be32_to_cpu __be32_to_cpu110#define cpu_to_be16 __cpu_to_be16111#define be16_to_cpu __be16_to_cpu112#define cpu_to_le64p __cpu_to_le64p113#define le64_to_cpup __le64_to_cpup114#define cpu_to_le32p __cpu_to_le32p115#define le32_to_cpup __le32_to_cpup116#define cpu_to_le16p __cpu_to_le16p117#define le16_to_cpup __le16_to_cpup118#define cpu_to_be64p __cpu_to_be64p119#define be64_to_cpup __be64_to_cpup120#define cpu_to_be32p __cpu_to_be32p121#define be32_to_cpup __be32_to_cpup122#define cpu_to_be16p __cpu_to_be16p123#define be16_to_cpup __be16_to_cpup124#define cpu_to_le64s __cpu_to_le64s125#define le64_to_cpus __le64_to_cpus126#define cpu_to_le32s __cpu_to_le32s127#define le32_to_cpus __le32_to_cpus128#define cpu_to_le16s __cpu_to_le16s129#define le16_to_cpus __le16_to_cpus130#define cpu_to_be64s __cpu_to_be64s131#define be64_to_cpus __be64_to_cpus132#define cpu_to_be32s __cpu_to_be32s133#define be32_to_cpus __be32_to_cpus134#define cpu_to_be16s __cpu_to_be16s135#define be16_to_cpus __be16_to_cpus136#endif137138139/*140* Handle ntohl and suches. These have various compatibility141* issues - like we want to give the prototype even though we142* also have a macro for them in case some strange program143* wants to take the address of the thing or something..144*145* Note that these used to return a "long" in libc5, even though146* long is often 64-bit these days.. Thus the casts.147*148* They have to be macros in order to do the constant folding149* correctly - if the argument passed into a inline function150* it is no longer constant according to gcc..151*/152153#undef ntohl154#undef ntohs155#undef htonl156#undef htons157158/*159* Do the prototypes. Somebody might want to take the160* address or some such sick thing..161*/162#if defined(PLATFORM_LINUX) || (defined(__GLIBC__) && __GLIBC__ >= 2)163extern __u32 ntohl(__u32);164extern __u32 htonl(__u32);165#else /* defined(PLATFORM_LINUX) || (defined (__GLIBC__) && __GLIBC__ >= 2) */166#ifndef PLATFORM_FREEBSD167extern unsigned long int ntohl(unsigned long int);168extern unsigned long int htonl(unsigned long int);169#endif170#endif171#ifndef PLATFORM_FREEBSD172extern unsigned short int ntohs(unsigned short int);173extern unsigned short int htons(unsigned short int);174#endif175176#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__) || defined(PLATFORM_MPIXEL)177178#define ___htonl(x) __cpu_to_be32(x)179#define ___htons(x) __cpu_to_be16(x)180#define ___ntohl(x) __be32_to_cpu(x)181#define ___ntohs(x) __be16_to_cpu(x)182183#if defined(PLATFORM_LINUX) || (defined(__GLIBC__) && __GLIBC__ >= 2)184#define htonl(x) ___htonl(x)185#define ntohl(x) ___ntohl(x)186#else187#define htonl(x) ((unsigned long)___htonl(x))188#define ntohl(x) ((unsigned long)___ntohl(x))189#endif190#define htons(x) ___htons(x)191#define ntohs(x) ___ntohs(x)192193#endif /* OPTIMIZE */194195196#if defined(PLATFORM_WINDOWS)197198#define htonl(x) __cpu_to_be32(x)199#define ntohl(x) __be32_to_cpu(x)200#define htons(x) __cpu_to_be16(x)201#define ntohs(x) __be16_to_cpu(x)202203204#endif205206#endif /* _LINUX_BYTEORDER_GENERIC_H */207208209