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 register(s), it's possible to show
several registers when register name are used as command line option.

The set-reg command is to write nvme register(s). Again, the command is
able to set several registers when the register name are used.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t authored and igaw committed Apr 9, 2024
1 parent 5d6fbb4 commit 293e622
Show file tree
Hide file tree
Showing 8 changed files with 1,050 additions and 76 deletions.
138 changes: 138 additions & 0 deletions Documentation/nvme-get-reg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
nvme-get-reg(1)
===============

NAME
----
nvme-get-reg - Read and show the defined NVMe controller register

SYNOPSIS
--------
[verse]
'nvme get-reg' <device> [--offset=<offset>, -O <offset>] [--human-readable | -H]
[--cap] [--vs] [--cmbloc] [--cmbsz] [--bpinfo]
[--cmbsts] [--cmbebs] [--cmbswtp] [--crto] [--pmrcap]
[--pmrsts] [--pmrebs] [--pmrswtp] [--intms] [--intmc]
[--cc] [--csts] [--nssr] [--aqa] [--asq] [--acq]
[--bprsel] [--bpmbl] [--cmbmsc] [--nssd] [--pmrctl]
[--pmrmscl] [--pmrmscu]
[--output-format=<fmt> | -o <fmt>] [--verbose | -v]

DESCRIPTION
-----------
Read and show the defined NVMe controller register.

OPTIONS
-------
-O <offset>::
--offset=<offset>::
offset of the requested register

-H::
--human-readable::
show register in readable format

--cap::
CAP=0x0 register offset

--vs::
VS=0x8 register offset

--cmbloc::
CMBLOC=0x38 register offset

--cmbsz::
CMBSZ=0x3c register offset

--bpinfo::
BPINFO=0x40 register offset

--cmbsts::
CMBSTS=0x58 register offset

--cmbebs::
CMBEBS=0x5c register offset

--cmbswtp::
CMBSWTP=0x60 register offset

--crto::
CRTO=0x68 register offset

--pmrcap::
PMRCAP=0xe00 register offset

--pmrsts::
PMRSTS=0xe08 register offset

--pmrebs::
PMREBS=0xe0c register offset

--pmrswtp::
PMRSWTP=0xe10 register offset

--intms::
INTMS=0xc register offset

--intmc::
INTMC=0x10 register offset

--cc::
CC=0x14 register offset

--csts::
CSTS=0x1c register offset

--nssr::
NSSR=0x20 register offset

--aqa::
AQA=0x24 register offset

--asq::
ASQ=0x28 register offset

--acq::
ACQ=0x30 register offset

--bprsel::
BPRSEL=0x44 register offset

--bpmbl::
BPMBL=0x48 register offset

--cmbmsc::
CMBMSC=0x50 register offset

--nssd::
NSSD=0x64 register offset

--pmrctl::
PMRCTL=0xe04 register offset

--pmrmscl::
PMRMSCL=0xe14 register offset

--pmrmscu::
PMRMSCU=0xe18 register offset

-o <fmt>::
--output-format=<fmt>::
Set the reporting format to 'normal', 'json' or 'binary'. Only one
output format can be used at a time.

-v::
--verbose::
Increase the information detail in the output.

EXAMPLES
--------
* The following will run the get-reg command with CC=0x14 register offset
+
------------
# nvme get-reg /dev/nvme0 --cc
register: 0x0014 (Controller Configuration), value: 0x460001
------------

NVME
----
Part of the nvme-user suite.
102 changes: 102 additions & 0 deletions Documentation/nvme-set-reg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
nvme-set-reg(1)
===============

NAME
----
nvme-set-reg - Writes and shows the defined NVMe controller register

SYNOPSIS
--------
[verse]
'nvme set-reg' <device> [--offset=<offset>, -O <offset>]
[--value=<val> | -V <val>] [--mmio32 | -m]
[--intms=<val>] [--intmc=<val>] [--cc=<val>]
[--csts=<val>] [--nssr=<val>] [--aqa=<val>]
[--asq=<val>] [--acq=<val>] [--bprsel=<val>]
[--bpmbl=<val>] [--cmbmsc=<val>] [--nssd=<val>]
[--pmrctl=<val>] [--pmrmscl=<val>] [--pmrmscu=<val>]
[--output-format=<fmt> | -o <fmt>] [--verbose | -v]

DESCRIPTION
-----------
Writes and shows the defined NVMe controller register.

OPTIONS
-------
-O <offset>::
--offset=<offset>::
offset of the requested register

-V <val>::
--value=<val>::
the value of the register to be set

--mmio32::
-m::
Access 64-bit registers as 2 32-bit

--intms=<val>::
INTMS=0xc register offset

--intmc=<val>::
INTMC=0x10 register offset

--cc=<val>::
CC=0x14 register offset

--csts=<val>::
CSTS=0x1c register offset

--nssr=<val>::
NSSR=0x20 register offset

--aqa=<val>::
AQA=0x24 register offset

--asq=<val>::
ASQ=0x28 register offset

--acq=<val>::
ACQ=0x30 register offset

--bprsel=<val>::
BPRSEL=0x44 register offset

--bpmbl=<val>::
BPMBL=0x48 register offset

--cmbmsc=<val>::
CMBMSC=0x50 register offset

--nssd=<val>::
NSSD=0x64 register offset

--pmrctl=<val>::
PMRCTL=0xe04 register offset

--pmrmscl=<val>::
PMRMSCL=0xe14 register offset

--pmrmscu=<val>::
PMRMSCU=0xe18 register offset

-o <fmt>::
--output-format=<fmt>::
Set the reporting format to 'normal', 'json' or 'binary'. Only one
output format can be used at a time.

-v::
--verbose::
Increase the information detail in the output.

EXAMPLES
--------
* The following will run the set-reg command with offset 0x14 and value 0x460000
+
------------
# nvme set-reg /dev/nvme0 -O 0x14 -V 0x460000
------------

NVME
----
Part of the nvme-user suite.
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
77 changes: 77 additions & 0 deletions completions/_nvme
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ _nvme () {
'show-topology:show subsystem topology'
'nvme-mi-recv:send a NVMe-MI receive command'
'nvme-mi-send:send a NVMe-MI send command'
'get-reg:read and show the defined NVMe controller register'
'set-seg:write and show the defined NVMe controller register'
'version:show the program version'
'ocp:OCP cloud SSD extensions'
'solidigm:Solidigm plug-in extensions'
Expand Down Expand Up @@ -2244,6 +2246,81 @@ _nvme () {
_arguments '*:: :->subcmds'
_describe -t commands "nvme nvme-mi-send options" _nvme_mi_send
;;
(get-reg)
local _get_reg
_get_reg=(
--offset=':offset of the requested register'
-O':alias for --offset'
--human-readable':show register in readable format'
-H':alias for --human-readable'
--cap':CAP=0x0 register offset'
--vs':VS=0x8 register offset'
--cmbloc':CMBLOC=0x38 register offset'
--cmbsz':CMBSZ=0x3c register offset'
--bpinfo':BPINFO=0x40 register offset'
--cmbsts':CMBSTS=0x58 register offset'
--cmbebs':CMBEBS=0x5c register offset'
--cmbswtp':CMBSWTP=0x60 register offset'
--crto':CRTO=0x68 register offset'
--pmrcap':PMRCAP=0xe00 register offset'
--pmrsts':PMRSTS=0xe08 register offset'
--pmrebs':PMREBS=0xe0c register offset'
--pmrswtp':PMRSWTP=0xe10 register offset'
--intms':INTMS=0xc register offset'
--intmc':INTMC=0x10 register offset'
--cc':CC=0x14 register offset'
--csts':CSTS=0x1c register offset'
--nssr':NSSR=0x20 register offset'
--aqa':AQA=0x24 register offset'
--asq':ASQ=0x28 register offset'
--acq':ACQ=0x30 register offset'
--bprsel':BPRSEL=0x44 register offset'
--bpmbl':BPMBL=0x48 register offset'
--cmbmsc':CMBMSC=0x50 register offset'
--nssd':NSSD=0x64 register offset'
--pmrctl':PMRCTL=0xe04 register offset'
--pmrmscl':PMRMSCL=0xe14 register offset'
--pmrmscu':PMRMSCU=0xe18 register offset'
--output-format=':Output format: normal|json|binary'
-o ':alias for --output-format'
--verbose':Increase the information detail in the output.'
-v':alias for --verbose'
)
_arguments '*:: :->subcmds'
_describe -t commands "nvme get-reg options" _get_reg
;;
(set-reg)
local _set_reg
_set_reg=(
--offset=':offset of the requested register'
-O':alias for --offset'
--value=':the value of the register to be set'
-V':alias for --value'
--mmio32':Access 64-bit registers as 2 32-bit'
-m':alias for --mmio32'
--intms=':INTMS=0xc register offset'
--intmc=':INTMC=0x10 register offset'
--cc=':CC=0x14 register offset'
--csts=':CSTS=0x1c register offset'
--nssr=':NSSR=0x20 register offset'
--aqa=':AQA=0x24 register offset'
--asq=':ASQ=0x28 register offset'
--acq=':ACQ=0x30 register offset'
--bprsel=':BPRSEL=0x44 register offset'
--bpmbl=':BPMBL=0x48 register offset'
--cmbmsc=':CMBMSC=0x50 register offset'
--nssd=':NSSD=0x64 register offset'
--pmrctl=':PMRCTL=0xe04 register offset'
--pmrmscl=':PMRMSCL=0xe14 register offset'
--pmrmscu=':PMRMSCU=0xe18 register offset'
--output-format=':Output format: normal|json|binary'
-o ':alias for --output-format'
--verbose':Increase the information detail in the output.'
-v':alias for --verbose'
)
_arguments '*:: :->subcmds'
_describe -t commands "nvme set-reg options" _set_reg
;;
(version)
local _version
_version=(
Expand Down
16 changes: 15 additions & 1 deletion completions/bash-nvme-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ nvme_list_opts () {
opts+=" --opcode= -O --namespace-id= -n --data-len= -l \
--nmimt= -m --nmd0= -0 --nmd1= -1 --input-file= -i"
;;
"get-reg")
opts+=" --offset, -O --human-readable -H --cap --vs --cmbloc \
--cmbsz --bpinfo --cmbsts --cmbebs --cmbswtp --crto \
--pmrcap --pmrsts --pmrebs --pmrswtp --intms --intmc \
--cc --csts --nssr --aqa --asq --acq --bprsel --bpmbl \
--cmbmsc --nssd --pmrctl --pmrmscl --pmrmscu \
--output-format -o --verbose -v"
;;
"set-reg")
opts+=" --offset, -O --value= -V --mmio32 -m --intms= --intmc= \
--cc= --csts= --nssr= --aqa= --asq= --acq= --bprsel= \
--bpmbl= --cmbmsc= --nssd= --pmrctl= --pmrmscl= \
--pmrmscu= --output-format= -o --verbose= -v"
;;
"version")
opts+=$NO_OPTS
;;
Expand Down Expand Up @@ -1575,7 +1589,7 @@ _nvme_subcmds () {
rpmb boot-part-log fid-support-effects-log \
supported-log-pages lockdown media-unit-stat-log \
supported-cap-config-log dim show-topology list-endgrp \
nvme-mi-recv nvme-mi-send"
nvme-mi-recv nvme-mi-send get-reg set-reg"

# Add plugins:
for plugin in "${!_plugin_subcmds[@]}"; do
Expand Down
Loading

0 comments on commit 293e622

Please sign in to comment.