Skip to content

Commit

Permalink
nvme: Add support for get-reg and set-reg commands
Browse files Browse the repository at this point in the history
The get-reg command is to output single register.
The set-reg command is to write nvme register.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Feb 5, 2024
1 parent 3def2b7 commit 3a721cd
Show file tree
Hide file tree
Showing 7 changed files with 779 additions and 206 deletions.
21 changes: 21 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _COMMON_H

#include <string.h>
#include <stdbool.h>

#include "ccan/endian/endian.h"

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

static inline void mmio_write32(void *addr, uint32_t value)
{
leint32_t *p = addr;

*p = cpu_to_le32(value);
}

/* Access 64-bit registers as 2 32-bit if write32 flag set; Some devices fail 64-bit MMIO. */
static inline void mmio_write64(void *addr, uint64_t value, bool write32)
{
uint64_t *p = addr;

if (write32) {
mmio_write32(addr, value);
mmio_write32((uint32_t *)addr + 1, value >> 32);
return;
}

*p = cpu_to_le64(value);
}
#endif
2 changes: 2 additions & 0 deletions nvme-builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ COMMAND_LIST(
ENTRY("subsystem-reset", "Resets the subsystem", subsystem_reset)
ENTRY("ns-rescan", "Rescans the NVME namespaces", ns_rescan)
ENTRY("show-regs", "Shows the controller registers or properties. Requires character device", show_registers)
ENTRY("set-reg", "Set a register and show the resulting value", set_register)
ENTRY("get-reg", "Get a register and show the resulting value", get_register)
ENTRY("discover", "Discover NVMeoF subsystems", discover_cmd)
ENTRY("connect-all", "Discover and Connect to NVMeoF subsystems", connect_all_cmd)
ENTRY("connect", "Connect to NVMeoF subsystem", connect_cmd)
Expand Down
Loading

0 comments on commit 3a721cd

Please sign in to comment.