1*d6b92ffaSHans Petter Selasky /*- 2*d6b92ffaSHans Petter Selasky * Copyright (c) 2010 Isilon Systems, Inc. 3*d6b92ffaSHans Petter Selasky * Copyright (c) 2010 iX Systems, Inc. 4*d6b92ffaSHans Petter Selasky * Copyright (c) 2010 Panasas, Inc. 5*d6b92ffaSHans Petter Selasky * All rights reserved. 6*d6b92ffaSHans Petter Selasky * 7*d6b92ffaSHans Petter Selasky * Redistribution and use in source and binary forms, with or without 8*d6b92ffaSHans Petter Selasky * modification, are permitted provided that the following conditions 9*d6b92ffaSHans Petter Selasky * are met: 10*d6b92ffaSHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 11*d6b92ffaSHans Petter Selasky * notice unmodified, this list of conditions, and the following 12*d6b92ffaSHans Petter Selasky * disclaimer. 13*d6b92ffaSHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 14*d6b92ffaSHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 15*d6b92ffaSHans Petter Selasky * documentation and/or other materials provided with the distribution. 16*d6b92ffaSHans Petter Selasky * 17*d6b92ffaSHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18*d6b92ffaSHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19*d6b92ffaSHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20*d6b92ffaSHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21*d6b92ffaSHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22*d6b92ffaSHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23*d6b92ffaSHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24*d6b92ffaSHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25*d6b92ffaSHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26*d6b92ffaSHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*d6b92ffaSHans Petter Selasky */ 28*d6b92ffaSHans Petter Selasky #ifndef _INFINIBAND_BYTEORDER_H_ 29*d6b92ffaSHans Petter Selasky #define _INFINIBAND_BYTEORDER_H_ 30*d6b92ffaSHans Petter Selasky 31*d6b92ffaSHans Petter Selasky #include <sys/types.h> 32*d6b92ffaSHans Petter Selasky #include <sys/endian.h> 33*d6b92ffaSHans Petter Selasky 34*d6b92ffaSHans Petter Selasky #if BYTE_ORDER == LITTLE_ENDIAN 35*d6b92ffaSHans Petter Selasky #define __LITTLE_ENDIAN 36*d6b92ffaSHans Petter Selasky #else 37*d6b92ffaSHans Petter Selasky #define __BIG_ENDIAN 38*d6b92ffaSHans Petter Selasky #endif 39*d6b92ffaSHans Petter Selasky 40*d6b92ffaSHans Petter Selasky #define cpu_to_le64 htole64 41*d6b92ffaSHans Petter Selasky #define le64_to_cpu le64toh 42*d6b92ffaSHans Petter Selasky #define cpu_to_le32 htole32 43*d6b92ffaSHans Petter Selasky #define le32_to_cpu le32toh 44*d6b92ffaSHans Petter Selasky #define cpu_to_le16 htole16 45*d6b92ffaSHans Petter Selasky #define le16_to_cpu le16toh 46*d6b92ffaSHans Petter Selasky #define cpu_to_be64 htobe64 47*d6b92ffaSHans Petter Selasky #define be64_to_cpu be64toh 48*d6b92ffaSHans Petter Selasky #define cpu_to_be32 htobe32 49*d6b92ffaSHans Petter Selasky #define be32_to_cpu be32toh 50*d6b92ffaSHans Petter Selasky #define cpu_to_be16 htobe16 51*d6b92ffaSHans Petter Selasky #define be16_to_cpu be16toh 52*d6b92ffaSHans Petter Selasky #define __be16_to_cpu be16toh 53*d6b92ffaSHans Petter Selasky 54*d6b92ffaSHans Petter Selasky #define cpu_to_le64p(x) htole64(*((uint64_t *)x)) 55*d6b92ffaSHans Petter Selasky #define le64_to_cpup(x) le64toh(*((uint64_t *)x)) 56*d6b92ffaSHans Petter Selasky #define cpu_to_le32p(x) htole32(*((uint32_t *)x)) 57*d6b92ffaSHans Petter Selasky #define le32_to_cpup(x) le32toh(*((uint32_t *)x)) 58*d6b92ffaSHans Petter Selasky #define cpu_to_le16p(x) htole16(*((uint16_t *)x)) 59*d6b92ffaSHans Petter Selasky #define le16_to_cpup(x) le16toh(*((uint16_t *)x)) 60*d6b92ffaSHans Petter Selasky #define cpu_to_be64p(x) htobe64(*((uint64_t *)x)) 61*d6b92ffaSHans Petter Selasky #define be64_to_cpup(x) be64toh(*((uint64_t *)x)) 62*d6b92ffaSHans Petter Selasky #define cpu_to_be32p(x) htobe32(*((uint32_t *)x)) 63*d6b92ffaSHans Petter Selasky #define be32_to_cpup(x) be32toh(*((uint32_t *)x)) 64*d6b92ffaSHans Petter Selasky #define cpu_to_be16p(x) htobe16(*((uint16_t *)x)) 65*d6b92ffaSHans Petter Selasky #define be16_to_cpup(x) be16toh(*((uint16_t *)x)) 66*d6b92ffaSHans Petter Selasky 67*d6b92ffaSHans Petter Selasky #define cpu_to_le64s(x) do { *((uint64_t *)x) = cpu_to_le64p((x)) } while (0) 68*d6b92ffaSHans Petter Selasky #define le64_to_cpus(x) do { *((uint64_t *)x) = le64_to_cpup((x)) } while (0) 69*d6b92ffaSHans Petter Selasky #define cpu_to_le32s(x) do { *((uint32_t *)x) = cpu_to_le32p((x)) } while (0) 70*d6b92ffaSHans Petter Selasky #define le32_to_cpus(x) do { *((uint32_t *)x) = le32_to_cpup((x)) } while (0) 71*d6b92ffaSHans Petter Selasky #define cpu_to_le16s(x) do { *((uint16_t *)x) = cpu_to_le16p((x)) } while (0) 72*d6b92ffaSHans Petter Selasky #define le16_to_cpus(x) do { *((uint16_t *)x) = le16_to_cpup((x)) } while (0) 73*d6b92ffaSHans Petter Selasky #define cpu_to_be64s(x) do { *((uint64_t *)x) = cpu_to_be64p((x)) } while (0) 74*d6b92ffaSHans Petter Selasky #define be64_to_cpus(x) do { *((uint64_t *)x) = be64_to_cpup((x)) } while (0) 75*d6b92ffaSHans Petter Selasky #define cpu_to_be32s(x) do { *((uint32_t *)x) = cpu_to_be32p((x)) } while (0) 76*d6b92ffaSHans Petter Selasky #define be32_to_cpus(x) do { *((uint32_t *)x) = be32_to_cpup((x)) } while (0) 77*d6b92ffaSHans Petter Selasky #define cpu_to_be16s(x) do { *((uint16_t *)x) = cpu_to_be16p((x)) } while (0) 78*d6b92ffaSHans Petter Selasky #define be16_to_cpus(x) do { *((uint16_t *)x) = be16_to_cpup((x)) } while (0) 79*d6b92ffaSHans Petter Selasky 80*d6b92ffaSHans Petter Selasky #define swab16 bswap16 81*d6b92ffaSHans Petter Selasky #define swab32 bswap32 82*d6b92ffaSHans Petter Selasky #define swab64 bswap64 83*d6b92ffaSHans Petter Selasky 84*d6b92ffaSHans Petter Selasky #endif /* _INFINIBAND_BYTEORDER_H_ */ 85