]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fix mmio accesses
authorKeith Busch <kbusch@kernel.org>
Tue, 9 Jun 2020 20:45:44 +0000 (13:45 -0700)
committerKeith Busch <kbusch@kernel.org>
Tue, 9 Jun 2020 20:45:44 +0000 (13:45 -0700)
64-bit access needs to ensure no reorder or combining.

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/types.h

index e1333b3cec07e4a9b4d1c8b154c4e4eb85f37dfa..219ea6a147bdbc2a41bdb72506107ae5b2ef868a 100644 (file)
@@ -248,22 +248,22 @@ static inline bool nvme_is_64bit_reg(__u32 offset)
        }
 }
 
-static inline __u32 nvme_mmio_read32(void *addr)
+static inline uint32_t nvme_mmio_read32(volatile void *addr)
 {
-        __le32 *p = (__le32 *)addr;
+        uint32_t *p = (__le32 *)addr;
 
         return le32_to_cpu(*p);
 }
 
-static inline __u64 nvme_mmio_read64(void *addr)
+static inline uint64_t nvme_mmio_read64(volatile void *addr)
 {
-        __le32 *p = (__le32 *)addr;
+        volatile __u32 *p = (__u32 *)addr;
+        uint32_t low, high;
 
-       /*
-        * Some devices fail 64-bit MMIO, and at least one 64-bit register is
-        * not aligned to 64-bit. Access 64-bit registers as two 32-bit.
-        */
-        return le32_to_cpu(*p) | ((uint64_t)le32_to_cpu(*(p + 1)) << 32);
+        low = nvme_mmio_read32(p);
+        high = nvme_mmio_read32(p + 1);
+
+        return low + ((uint64_t)high << 32);
 }
 
 enum nvme_cap {