From: Klaus Jensen Date: Wed, 29 Sep 2021 19:07:41 +0000 (+0200) Subject: types: remove endian/mmio helpers X-Git-Tag: v1.0-rc0~73^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2e3616eaf0ed3c76ad2e5e51bfbaabe14d338173;p=users%2Fsagi%2Flibnvme.git types: remove endian/mmio helpers The endian/mmio helpers do not belong in types.h. Since we are already using ccan and have ccan/endian available, just include that where needed. The implementation is 100% equivalent, even with sparse annotations. Signed-off-by: Klaus Jensen --- diff --git a/examples/Makefile b/examples/Makefile index 7e310985..db06f386 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,5 +1,5 @@ CFLAGS ?= -g -O2 -override CFLAGS += -Wall -D_GNU_SOURCE -I ../src -L ../src +override CFLAGS += -Wall -D_GNU_SOURCE -I ../src -L ../src -I../ccan include ../Makefile.quiet diff --git a/examples/discover-loop.c b/examples/discover-loop.c index 599edd20..c2a23850 100644 --- a/examples/discover-loop.c +++ b/examples/discover-loop.c @@ -18,6 +18,8 @@ #include #include +#include + static void print_discover_log(struct nvmf_discovery_log *log) { int i, numrec = le64_to_cpu(log->numrec); diff --git a/examples/meson.build b/examples/meson.build index 0bf911d5..54ebbdac 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -7,7 +7,7 @@ # executable( 'telemetry-listen', - ['telemetry-listen.c'], + ['telemetry-listen.c', ccan_config_h], link_with: libnvme, include_directories: incdir) @@ -19,7 +19,7 @@ executable( executable( 'discover-loop', - ['discover-loop.c'], + ['discover-loop.c', ccan_config_h], link_with: libnvme, include_directories: incdir) diff --git a/examples/telemetry-listen.c b/examples/telemetry-listen.c index 374ffa4d..d3dcfb0b 100644 --- a/examples/telemetry-listen.c +++ b/examples/telemetry-listen.c @@ -20,6 +20,8 @@ #include #include +#include + struct events { nvme_ctrl_t c; int uevent_fd; diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index d96f09e9..94cecd06 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 8fbed440..5e8066cf 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -18,6 +18,7 @@ #include #include +#include #include "ioctl.h" #include "util.h" diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 90b9b5ce..f7668ac6 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -17,6 +17,8 @@ #include #include +#include + #include "linux.h" #include "tree.h" #include "log.h" diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 552496d8..0f72320f 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -21,7 +21,9 @@ #include #include +#include #include + #include "ioctl.h" #include "linux.h" #include "filters.h" diff --git a/src/nvme/types.h b/src/nvme/types.h index 6b0b1471..5e5936e9 100644 --- a/src/nvme/types.h +++ b/src/nvme/types.h @@ -10,18 +10,11 @@ #ifndef _LIBNVME_TYPES_H #define _LIBNVME_TYPES_H -#include #include #include #include -#ifdef __CHECKER__ -#define __force __attribute__((force)) -#else -#define __force -#endif - /** * NVME_GET() - extract field from complex value * @value: The original value of a complex field @@ -46,60 +39,6 @@ #define NVME_SET(value, name) \ (((value) & NVME_##name##_MASK) << NVME_##name##_SHIFT) -/** - * cpu_to_le16() - - * @x: 16-bit CPU value to turn to little endian. - */ -static inline __le16 cpu_to_le16(uint16_t x) -{ - return (__force __le16)htole16(x); -} - -/** - * cpu_to_le32() - - * @x: 32-bit CPU value to turn little endian. - */ -static inline __le32 cpu_to_le32(uint32_t x) -{ - return (__force __le32)htole32(x); -} - -/** - * cpu_to_le64() - - * @x: 64-bit CPU value to turn little endian. - */ -static inline __le64 cpu_to_le64(uint64_t x) -{ - return (__force __le64)htole64(x); -} - -/** - * le16_to_cpu() - - * @x: 16-bit little endian value to turn to CPU. - */ -static inline uint16_t le16_to_cpu(__le16 x) -{ - return le16toh((__force __u16)x); -} - -/** - * le32_to_cpu() - - * @x: 32-bit little endian value to turn to CPU. - */ -static inline uint32_t le32_to_cpu(__le32 x) -{ - return le32toh((__force __u32)x); -} - -/** - * le64_to_cpu() - - * @x: 64-bit little endian value to turn to CPU. - */ -static inline uint64_t le64_to_cpu(__le64 x) -{ - return le64toh((__force __u64)x); -} - /** * enum nvme_constants - A place to stash various constant nvme values * @NVME_NSID_ALL: A broadcast value that is used to specify all @@ -251,24 +190,6 @@ static inline bool nvme_is_64bit_reg(__u32 offset) } } -static inline uint32_t nvme_mmio_read32(volatile void *addr) -{ - uint32_t *p = (__le32 *)addr; - - return le32_to_cpu(*p); -} - -static inline uint64_t nvme_mmio_read64(volatile void *addr) -{ - volatile __u32 *p = (__u32 *)addr; - uint32_t low, high; - - low = nvme_mmio_read32(p); - high = nvme_mmio_read32(p + 1); - - return low + ((uint64_t)high << 32); -} - enum nvme_cap { NVME_CAP_MQES_SHIFT = 0, NVME_CAP_CQR_SHIFT = 16, diff --git a/src/nvme/util.c b/src/nvme/util.c index 3fd78490..dab6c02b 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -12,6 +12,8 @@ #include +#include + #include "util.h" static inline __u8 nvme_generic_status_to_errno(__u16 status) diff --git a/test/Makefile b/test/Makefile index 0c4eb361..b7fc2b8b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ CFLAGS ?= -g -O2 -override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/ +override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/ -I../ccan include ../Makefile.quiet diff --git a/test/meson.build b/test/meson.build index e89d8778..6b776aa4 100644 --- a/test/meson.build +++ b/test/meson.build @@ -7,7 +7,7 @@ # main = executable( 'main-test', - ['test.c'], + ['test.c', ccan_config_h], dependencies: libuuid, link_with: libnvme, include_directories: incdir @@ -22,14 +22,14 @@ cpp = executable( register = executable( 'test-register', - ['register.c'], + ['register.c', ccan_config_h], link_with: libnvme, include_directories: incdir ) zns = executable( 'test-zns', - ['zns.c'], + ['zns.c', ccan_config_h], link_with: libnvme, include_directories: incdir ) diff --git a/test/register.c b/test/register.c index 06244dfd..8791083e 100644 --- a/test/register.c +++ b/test/register.c @@ -21,6 +21,26 @@ #include +#include + +static inline uint32_t nvme_mmio_read32(volatile void *addr) +{ + uint32_t *p = (__le32 *)addr; + + return le32_to_cpu(*p); +} + +static inline uint64_t nvme_mmio_read64(volatile void *addr) +{ + volatile __u32 *p = (__u32 *)addr; + uint32_t low, high; + + low = nvme_mmio_read32(p); + high = nvme_mmio_read32(p + 1); + + return low + ((uint64_t)high << 32); +} + void nvme_print_registers(void *regs) { __u64 cap = nvme_mmio_read64(regs + NVME_REG_CAP); diff --git a/test/test.c b/test/test.c index 7c6a5cb8..34d7c7da 100644 --- a/test/test.c +++ b/test/test.c @@ -23,6 +23,8 @@ #endif #include +#include + static char *nqn_match; static bool nvme_match_subsysnqn_filter(nvme_subsystem_t s) diff --git a/test/zns.c b/test/zns.c index 3ca55dfc..54a6779a 100644 --- a/test/zns.c +++ b/test/zns.c @@ -16,6 +16,8 @@ #include #include +#include + static void show_zns_properties(nvme_ns_t n) { struct nvme_zns_id_ns zns_ns;