124269Speter/*-
224269Speter * Copyright (c) 2010 Isilon Systems, Inc.
324269Speter * Copyright (c) 2010 iX Systems, Inc.
424269Speter * Copyright (c) 2010 Panasas, Inc.
524269Speter * All rights reserved.
624269Speter *
724269Speter * Redistribution and use in source and binary forms, with or without
824269Speter * modification, are permitted provided that the following conditions
924269Speter * are met:
1024269Speter * 1. Redistributions of source code must retain the above copyright
1124269Speter *    notice unmodified, this list of conditions, and the following
1224269Speter *    disclaimer.
1324269Speter * 2. Redistributions in binary form must reproduce the above copyright
1424269Speter *    notice, this list of conditions and the following disclaimer in the
1524269Speter *    documentation and/or other materials provided with the distribution.
1624269Speter *
1724269Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1824269Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1924269Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2024269Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2124269Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2224269Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2324269Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2424269Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2524269Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2624269Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2724269Speter */
2824269Speter#ifndef	_INFINIBAND_BYTEORDER_H_
2924269Speter#define	_INFINIBAND_BYTEORDER_H_
3024269Speter
3124269Speter#include <sys/types.h>
3224269Speter#include <sys/endian.h>
3324269Speter
3424269Speter#if BYTE_ORDER == LITTLE_ENDIAN
3524269Speter#define	__LITTLE_ENDIAN
3624269Speter#else
3724269Speter#define	__BIG_ENDIAN
3824269Speter#endif
3924269Speter
4024269Speter#define	cpu_to_le64	htole64
4124269Speter#define	le64_to_cpu	le64toh
4224269Speter#define	cpu_to_le32	htole32
4324269Speter#define	le32_to_cpu	le32toh
4424269Speter#define	cpu_to_le16	htole16
4524269Speter#define	le16_to_cpu	le16toh
4624269Speter#define	cpu_to_be64	htobe64
4724269Speter#define	be64_to_cpu	be64toh
4824269Speter#define	cpu_to_be32	htobe32
4924269Speter#define	be32_to_cpu	be32toh
5024269Speter#define	cpu_to_be16	htobe16
5124269Speter#define	be16_to_cpu	be16toh
5224269Speter#define	__be16_to_cpu	be16toh
5324269Speter
5424269Speter#define	cpu_to_le64p(x)	htole64(*((uint64_t *)x))
5524269Speter#define	le64_to_cpup(x)	le64toh(*((uint64_t *)x))
5624269Speter#define	cpu_to_le32p(x)	htole32(*((uint32_t *)x))
5724269Speter#define	le32_to_cpup(x)	le32toh(*((uint32_t *)x))
5824269Speter#define	cpu_to_le16p(x)	htole16(*((uint16_t *)x))
5924269Speter#define	le16_to_cpup(x)	le16toh(*((uint16_t *)x))
6024269Speter#define	cpu_to_be64p(x)	htobe64(*((uint64_t *)x))
6124269Speter#define	be64_to_cpup(x)	be64toh(*((uint64_t *)x))
6224269Speter#define	cpu_to_be32p(x)	htobe32(*((uint32_t *)x))
6324269Speter#define	be32_to_cpup(x)	be32toh(*((uint32_t *)x))
6424269Speter#define	cpu_to_be16p(x)	htobe16(*((uint16_t *)x))
6524269Speter#define	be16_to_cpup(x)	be16toh(*((uint16_t *)x))
6624269Speter
6724269Speter#define	cpu_to_le64s(x)	do { *((uint64_t *)x) = cpu_to_le64p((x)) } while (0)
6824269Speter#define	le64_to_cpus(x)	do { *((uint64_t *)x) = le64_to_cpup((x)) } while (0)
6924269Speter#define	cpu_to_le32s(x)	do { *((uint32_t *)x) = cpu_to_le32p((x)) } while (0)
7024269Speter#define	le32_to_cpus(x)	do { *((uint32_t *)x) = le32_to_cpup((x)) } while (0)
7124269Speter#define	cpu_to_le16s(x)	do { *((uint16_t *)x) = cpu_to_le16p((x)) } while (0)
7224269Speter#define	le16_to_cpus(x)	do { *((uint16_t *)x) = le16_to_cpup((x)) } while (0)
7324269Speter#define	cpu_to_be64s(x)	do { *((uint64_t *)x) = cpu_to_be64p((x)) } while (0)
7424269Speter#define	be64_to_cpus(x)	do { *((uint64_t *)x) = be64_to_cpup((x)) } while (0)
7524269Speter#define	cpu_to_be32s(x)	do { *((uint32_t *)x) = cpu_to_be32p((x)) } while (0)
7624269Speter#define	be32_to_cpus(x)	do { *((uint32_t *)x) = be32_to_cpup((x)) } while (0)
7724269Speter#define	cpu_to_be16s(x)	do { *((uint16_t *)x) = cpu_to_be16p((x)) } while (0)
7824269Speter#define	be16_to_cpus(x)	do { *((uint16_t *)x) = be16_to_cpup((x)) } while (0)
7924269Speter
8024269Speter#define	swab16	bswap16
8124269Speter#define	swab32	bswap32
8224269Speter#define	swab64	bswap64
8324269Speter
8424269Speter#endif	/* _INFINIBAND_BYTEORDER_H_ */
8524269Speter