summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorDmitry Fomichev <dmitry.fomichev@wdc.com>2019-02-21 13:11:01 +0900
committerJens Axboe <axboe@kernel.dk>2019-02-23 21:19:01 -0700
commita824149a09e541c08e2236d8c6b828437e7781a7 (patch)
treef83667b511da24b95d02a032d9d1838857e8cf93 /os
parent02ae7bd8339435c982f134ca63ee9062c1d92b8e (diff)
downloadfio-a824149a09e541c08e2236d8c6b828437e7781a7.tar.gz
fio-a824149a09e541c08e2236d8c6b828437e7781a7.tar.bz2
sg: Clean up handling of big endian data fields
Getting and setting values in SCSI commands and descriptors, which are big endian, in SG driver can use a bit of cleanup. This patch simplifies SG driver code by introducing a set of accessor functions for reading raw big endian values from SCSI buffers and another set for properly storing the local values as big endian byte sequences. The patch also adds some missing endianness conversion macros in os.h. Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'os')
-rw-r--r--os/os.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/os/os.h b/os/os.h
index 0b182c4a..36b6bb2e 100644
--- a/os/os.h
+++ b/os/os.h
@@ -210,19 +210,27 @@ static inline uint64_t fio_swap64(uint64_t val)
#ifndef FIO_HAVE_BYTEORDER_FUNCS
#ifdef CONFIG_LITTLE_ENDIAN
+#define __be16_to_cpu(x) fio_swap16(x)
+#define __be32_to_cpu(x) fio_swap32(x)
#define __be64_to_cpu(x) fio_swap64(x)
#define __le16_to_cpu(x) (x)
#define __le32_to_cpu(x) (x)
#define __le64_to_cpu(x) (x)
+#define __cpu_to_be16(x) fio_swap16(x)
+#define __cpu_to_be32(x) fio_swap32(x)
#define __cpu_to_be64(x) fio_swap64(x)
#define __cpu_to_le16(x) (x)
#define __cpu_to_le32(x) (x)
#define __cpu_to_le64(x) (x)
#else
+#define __be16_to_cpu(x) (x)
+#define __be32_to_cpu(x) (x)
#define __be64_to_cpu(x) (x)
#define __le16_to_cpu(x) fio_swap16(x)
#define __le32_to_cpu(x) fio_swap32(x)
#define __le64_to_cpu(x) fio_swap64(x)
+#define __cpu_to_be16(x) (x)
+#define __cpu_to_be32(x) (x)
#define __cpu_to_be64(x) (x)
#define __cpu_to_le16(x) fio_swap16(x)
#define __cpu_to_le32(x) fio_swap32(x)
@@ -231,6 +239,14 @@ static inline uint64_t fio_swap64(uint64_t val)
#endif /* FIO_HAVE_BYTEORDER_FUNCS */
#ifdef FIO_INTERNAL
+#define be16_to_cpu(val) ({ \
+ typecheck(uint16_t, val); \
+ __be16_to_cpu(val); \
+})
+#define be32_to_cpu(val) ({ \
+ typecheck(uint32_t, val); \
+ __be32_to_cpu(val); \
+})
#define be64_to_cpu(val) ({ \
typecheck(uint64_t, val); \
__be64_to_cpu(val); \
@@ -249,6 +265,14 @@ static inline uint64_t fio_swap64(uint64_t val)
})
#endif
+#define cpu_to_be16(val) ({ \
+ typecheck(uint16_t, val); \
+ __cpu_to_be16(val); \
+})
+#define cpu_to_be32(val) ({ \
+ typecheck(uint32_t, val); \
+ __cpu_to_be32(val); \
+})
#define cpu_to_be64(val) ({ \
typecheck(uint64_t, val); \
__cpu_to_be64(val); \