Skip to content

Commit 4b50b9f

Browse files
committed
nvme: Add support for get-reg and set-reg commands
The get-reg command is to output single register. The set-reg command is to write nvme register. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 3def2b7 commit 4b50b9f

8 files changed

+1388
-436
lines changed

common.h

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _COMMON_H
44

55
#include <string.h>
6+
#include <stdbool.h>
67

78
#include "ccan/endian/endian.h"
89

@@ -35,4 +36,24 @@ static inline uint64_t mmio_read64(void *addr)
3536
return ((uint64_t)high << 32) | low;
3637
}
3738

39+
static inline void mmio_write32(void *addr, uint32_t value)
40+
{
41+
leint32_t *p = addr;
42+
43+
*p = cpu_to_le32(value);
44+
}
45+
46+
/* Access 64-bit registers as 2 32-bit if write32 flag set; Some devices fail 64-bit MMIO. */
47+
static inline void mmio_write64(void *addr, uint64_t value, bool write32)
48+
{
49+
uint64_t *p = addr;
50+
51+
if (write32) {
52+
mmio_write32(addr, value);
53+
mmio_write32((uint32_t *)addr + 1, value >> 32);
54+
return;
55+
}
56+
57+
*p = cpu_to_le64(value);
58+
}
3859
#endif

nvme-builtin.h

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ COMMAND_LIST(
8989
ENTRY("subsystem-reset", "Resets the subsystem", subsystem_reset)
9090
ENTRY("ns-rescan", "Rescans the NVME namespaces", ns_rescan)
9191
ENTRY("show-regs", "Shows the controller registers or properties. Requires character device", show_registers)
92+
ENTRY("set-reg", "Set a register and show the resulting value", set_register)
93+
ENTRY("get-reg", "Get a register and show the resulting value", get_register)
9294
ENTRY("discover", "Discover NVMeoF subsystems", discover_cmd)
9395
ENTRY("connect-all", "Discover and Connect to NVMeoF subsystems", connect_all_cmd)
9496
ENTRY("connect", "Connect to NVMeoF subsystem", connect_cmd)

0 commit comments

Comments
 (0)