1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5299363Shselasky * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/asm/byteorder.h 331756 2018-03-30 02:04:46Z emaste $ 30219820Sjeff */ 31219820Sjeff#ifndef _ASM_BYTEORDER_H_ 32219820Sjeff#define _ASM_BYTEORDER_H_ 33219820Sjeff 34219820Sjeff#include <sys/types.h> 35219820Sjeff#include <sys/endian.h> 36255932Salfred#include <asm/types.h> 37219820Sjeff 38219820Sjeff#if BYTE_ORDER == LITTLE_ENDIAN 39219820Sjeff#define __LITTLE_ENDIAN 40219820Sjeff#else 41219820Sjeff#define __BIG_ENDIAN 42219820Sjeff#endif 43219820Sjeff 44299363Shselasky#define cpu_to_le64(x) htole64(x) 45299363Shselasky#define le64_to_cpu(x) le64toh(x) 46299363Shselasky#define cpu_to_le32(x) htole32(x) 47299363Shselasky#define le32_to_cpu(x) le32toh(x) 48299363Shselasky#define cpu_to_le16(x) htole16(x) 49299363Shselasky#define le16_to_cpu(x) le16toh(x) 50299363Shselasky#define cpu_to_be64(x) htobe64(x) 51299363Shselasky#define be64_to_cpu(x) be64toh(x) 52299363Shselasky#define cpu_to_be32(x) htobe32(x) 53299363Shselasky#define be32_to_cpu(x) be32toh(x) 54299363Shselasky#define cpu_to_be16(x) htobe16(x) 55299363Shselasky#define be16_to_cpu(x) be16toh(x) 56299363Shselasky#define __be16_to_cpu(x) be16toh(x) 57219820Sjeff 58299360Shselasky#define cpu_to_le64p(x) htole64(*((const uint64_t *)(x))) 59299360Shselasky#define le64_to_cpup(x) le64toh(*((const uint64_t *)(x))) 60299360Shselasky#define cpu_to_le32p(x) htole32(*((const uint32_t *)(x))) 61299360Shselasky#define le32_to_cpup(x) le32toh(*((const uint32_t *)(x))) 62299360Shselasky#define cpu_to_le16p(x) htole16(*((const uint16_t *)(x))) 63299360Shselasky#define le16_to_cpup(x) le16toh(*((const uint16_t *)(x))) 64299360Shselasky#define cpu_to_be64p(x) htobe64(*((const uint64_t *)(x))) 65299360Shselasky#define be64_to_cpup(x) be64toh(*((const uint64_t *)(x))) 66299360Shselasky#define cpu_to_be32p(x) htobe32(*((const uint32_t *)(x))) 67299360Shselasky#define be32_to_cpup(x) be32toh(*((const uint32_t *)(x))) 68299360Shselasky#define cpu_to_be16p(x) htobe16(*((const uint16_t *)(x))) 69299360Shselasky#define be16_to_cpup(x) be16toh(*((const uint16_t *)(x))) 70219820Sjeff 71299361Shselasky#define cpu_to_le64s(x) do { *((uint64_t *)(x)) = cpu_to_le64p((x)); } while (0) 72299361Shselasky#define le64_to_cpus(x) do { *((uint64_t *)(x)) = le64_to_cpup((x)); } while (0) 73299361Shselasky#define cpu_to_le32s(x) do { *((uint32_t *)(x)) = cpu_to_le32p((x)); } while (0) 74299361Shselasky#define le32_to_cpus(x) do { *((uint32_t *)(x)) = le32_to_cpup((x)); } while (0) 75299361Shselasky#define cpu_to_le16s(x) do { *((uint16_t *)(x)) = cpu_to_le16p((x)); } while (0) 76299361Shselasky#define le16_to_cpus(x) do { *((uint16_t *)(x)) = le16_to_cpup((x)); } while (0) 77299361Shselasky#define cpu_to_be64s(x) do { *((uint64_t *)(x)) = cpu_to_be64p((x)); } while (0) 78299361Shselasky#define be64_to_cpus(x) do { *((uint64_t *)(x)) = be64_to_cpup((x)); } while (0) 79299361Shselasky#define cpu_to_be32s(x) do { *((uint32_t *)(x)) = cpu_to_be32p((x)); } while (0) 80299361Shselasky#define be32_to_cpus(x) do { *((uint32_t *)(x)) = be32_to_cpup((x)); } while (0) 81299361Shselasky#define cpu_to_be16s(x) do { *((uint16_t *)(x)) = cpu_to_be16p((x)); } while (0) 82299361Shselasky#define be16_to_cpus(x) do { *((uint16_t *)(x)) = be16_to_cpup((x)); } while (0) 83219820Sjeff 84299363Shselasky#define swab16(x) bswap16(x) 85299363Shselasky#define swab32(x) bswap32(x) 86299363Shselasky#define swab64(x) bswap64(x) 87219820Sjeff 88219820Sjeffstatic inline void 89290335Shselaskybe16_add_cpu(uint16_t *var, uint16_t val) 90331756Semaste{ 91219820Sjeff *var = cpu_to_be16(be16_to_cpu(*var) + val); 92219820Sjeff} 93219820Sjeff 94219820Sjeff#endif /* _ASM_BYTEORDER_H_ */ 95