1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5219820Sjeff * All rights reserved. 6219820Sjeff * 7219820Sjeff * Redistribution and use in source and binary forms, with or without 8219820Sjeff * modification, are permitted provided that the following conditions 9219820Sjeff * are met: 10219820Sjeff * 1. Redistributions of source code must retain the above copyright 11219820Sjeff * notice unmodified, this list of conditions, and the following 12219820Sjeff * disclaimer. 13219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 14219820Sjeff * notice, this list of conditions and the following disclaimer in the 15219820Sjeff * documentation and/or other materials provided with the distribution. 16219820Sjeff * 17219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27219820Sjeff */ 28219820Sjeff#ifndef _ASM_BYTEORDER_H_ 29219820Sjeff#define _ASM_BYTEORDER_H_ 30219820Sjeff 31219820Sjeff#include <sys/types.h> 32219820Sjeff#include <sys/endian.h> 33219820Sjeff 34219820Sjeff#if BYTE_ORDER == LITTLE_ENDIAN 35219820Sjeff#define __LITTLE_ENDIAN 36219820Sjeff#else 37219820Sjeff#define __BIG_ENDIAN 38219820Sjeff#endif 39219820Sjeff 40219820Sjeff#define cpu_to_le64 htole64 41219820Sjeff#define le64_to_cpu le64toh 42219820Sjeff#define cpu_to_le32 htole32 43219820Sjeff#define le32_to_cpu le32toh 44219820Sjeff#define cpu_to_le16 htole16 45219820Sjeff#define le16_to_cpu le16toh 46219820Sjeff#define cpu_to_be64 htobe64 47219820Sjeff#define be64_to_cpu be64toh 48219820Sjeff#define cpu_to_be32 htobe32 49219820Sjeff#define be32_to_cpu be32toh 50219820Sjeff#define cpu_to_be16 htobe16 51219820Sjeff#define be16_to_cpu be16toh 52219820Sjeff#define __be16_to_cpu be16toh 53219820Sjeff 54219820Sjeff#define cpu_to_le64p(x) htole64(*((uint64_t *)x)) 55219820Sjeff#define le64_to_cpup(x) le64toh(*((uint64_t *)x)) 56219820Sjeff#define cpu_to_le32p(x) htole32(*((uint32_t *)x)) 57219820Sjeff#define le32_to_cpup(x) le32toh(*((uint32_t *)x)) 58219820Sjeff#define cpu_to_le16p(x) htole16(*((uint16_t *)x)) 59219820Sjeff#define le16_to_cpup(x) le16toh(*((uint16_t *)x)) 60219820Sjeff#define cpu_to_be64p(x) htobe64(*((uint64_t *)x)) 61219820Sjeff#define be64_to_cpup(x) be64toh(*((uint64_t *)x)) 62219820Sjeff#define cpu_to_be32p(x) htobe32(*((uint32_t *)x)) 63219820Sjeff#define be32_to_cpup(x) be32toh(*((uint32_t *)x)) 64219820Sjeff#define cpu_to_be16p(x) htobe16(*((uint16_t *)x)) 65219820Sjeff#define be16_to_cpup(x) be16toh(*((uint16_t *)x)) 66219820Sjeff 67219820Sjeff#define cpu_to_le64s(x) do { *((uint64_t *)x) = cpu_to_le64p((x)) } while (0) 68219820Sjeff#define le64_to_cpus(x) do { *((uint64_t *)x) = le64_to_cpup((x)) } while (0) 69219820Sjeff#define cpu_to_le32s(x) do { *((uint32_t *)x) = cpu_to_le32p((x)) } while (0) 70219820Sjeff#define le32_to_cpus(x) do { *((uint32_t *)x) = le32_to_cpup((x)) } while (0) 71219820Sjeff#define cpu_to_le16s(x) do { *((uint16_t *)x) = cpu_to_le16p((x)) } while (0) 72219820Sjeff#define le16_to_cpus(x) do { *((uint16_t *)x) = le16_to_cpup((x)) } while (0) 73219820Sjeff#define cpu_to_be64s(x) do { *((uint64_t *)x) = cpu_to_be64p((x)) } while (0) 74219820Sjeff#define be64_to_cpus(x) do { *((uint64_t *)x) = be64_to_cpup((x)) } while (0) 75219820Sjeff#define cpu_to_be32s(x) do { *((uint32_t *)x) = cpu_to_be32p((x)) } while (0) 76219820Sjeff#define be32_to_cpus(x) do { *((uint32_t *)x) = be32_to_cpup((x)) } while (0) 77219820Sjeff#define cpu_to_be16s(x) do { *((uint16_t *)x) = cpu_to_be16p((x)) } while (0) 78219820Sjeff#define be16_to_cpus(x) do { *((uint16_t *)x) = be16_to_cpup((x)) } while (0) 79219820Sjeff 80219820Sjeff#define swab16 bswap16 81219820Sjeff#define swab32 bswap32 82219820Sjeff#define swab64 bswap64 83219820Sjeff 84219820Sjeffstatic inline void 85219820Sjeffbe16_add_cpu(u16 *var, u16 val) 86219820Sjeff{ 87219820Sjeff *var = cpu_to_be16(be16_to_cpu(*var) + val); 88219820Sjeff} 89219820Sjeff 90219820Sjeff#endif /* _ASM_BYTEORDER_H_ */ 91