Whamcloud - gitweb
LU-8058 lnet: Remove old commented out code
[fs/lustre-release.git] / libcfs / include / libcfs / byteorder.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2014, 2015, Intel Corporation.
24  * Author: John L. Hammond <john.hammond@intel.com>
25  */
26 #ifndef _LIBCFS_BYTEORDER_H
27 #define _LIBCFS_BYTERODER_H
28
29 #ifdef __KERNEL__
30 # include <asm/byteorder.h>
31 #else /* __KERNEL__ */
32
33 # ifdef HAVE_ENDIAN_H
34 #  include <endian.h>
35 # endif
36 # include <byteswap.h>
37
38 # define __swab16(x) bswap_16(x)
39 # define __swab32(x) bswap_32(x)
40 # define __swab64(x) bswap_64(x)
41 # define __swab16s(x)                           \
42         do {                                    \
43                 *(x) = bswap_16(*(x));          \
44         } while (0)
45 # define __swab32s(x)                           \
46         do {                                    \
47                 *(x) = bswap_32(*(x));          \
48         } while (0)
49 # define __swab64s(x)                           \
50         do {                                    \
51                 *(x) = bswap_64(*(x));          \
52         } while (0)
53 # if __BYTE_ORDER == __LITTLE_ENDIAN
54 #  define le16_to_cpu(x) (x)
55 #  define cpu_to_le16(x) (x)
56 #  define le32_to_cpu(x) (x)
57 #  define cpu_to_le32(x) (x)
58 #  define le64_to_cpu(x) (x)
59 #  define cpu_to_le64(x) (x)
60
61 #  define be16_to_cpu(x) bswap_16(x)
62 #  define cpu_to_be16(x) bswap_16(x)
63 #  define be32_to_cpu(x) bswap_32(x)
64 #  define cpu_to_be32(x) bswap_32(x)
65 #  define be64_to_cpu(x) ((__u64)bswap_64(x))
66 #  define cpu_to_be64(x) ((__u64)bswap_64(x))
67 # elif __BYTE_ORDER == __BIG_ENDIAN
68 #  define le16_to_cpu(x) bswap_16(x)
69 #  define cpu_to_le16(x) bswap_16(x)
70 #  define le32_to_cpu(x) bswap_32(x)
71 #  define cpu_to_le32(x) bswap_32(x)
72 #  define le64_to_cpu(x) ((__u64)bswap_64(x))
73 #  define cpu_to_le64(x) ((__u64)bswap_64(x))
74
75 #  define be16_to_cpu(x) (x)
76 #  define cpu_to_be16(x) (x)
77 #  define be32_to_cpu(x) (x)
78 #  define cpu_to_be32(x) (x)
79 #  define be64_to_cpu(x) (x)
80 #  define cpu_to_be64(x) (x)
81 # else /*  __BYTE_ORDER == __BIG_ENDIAN */
82 #  error "Unknown byte order"
83 # endif /* __BYTE_ORDER != __BIG_ENDIAN */
84
85 #endif /* !__KERNEL__ */
86
87 #endif /* _LIBCFS_BYTEORDER_H */