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.

Add below to stop the checkpatch "does MAINTAINERS need updating?" message.
 MAINTAINERS |

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Feb 11, 2024
1 parent 461db32 commit 1e95aad
Show file tree
Hide file tree
Showing 17 changed files with 1,321 additions and 226 deletions.
Empty file modified Documentation/nvme-id-ns-granularity.txt
100755 → 100644
Empty file.
Empty file modified Documentation/nvme-id-uuid.txt
100755 → 100644
Empty file.
Empty file modified Documentation/nvme-list-secondary.txt
100755 → 100644
Empty file.
Empty file modified Documentation/nvme-nvme-mi-recv.txt
100755 → 100644
Empty file.
Empty file modified Documentation/nvme-nvme-mi-send.txt
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions Documentation/nvme-set-property.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ OPTIONS
--offset::
The offset of the property.

-V::
--value:
-V <val>::
--value=<val>::
The value of the property to be set.

-o <fmt>::
Expand Down
Empty file modified Documentation/nvme-virt-mgmt.txt
100755 → 100644
Empty file.
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
120 changes: 120 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 @@ -2234,6 +2236,124 @@ _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'
-c':alias for --cap'
--vs':VS=0x8 register offset'
-V':alias for --vs'
--cmbloc':CMBLOC=0x38 register offset'
-m':alias for --cmbloc'
--cmbsz':CMBSZ=0x3c register offset'
-M':alias for --cmbsz'
--bpinfo':BPINFO=0x40 register offset'
-b':alias for --bpinfo'
--cmbsts':CMBSTS=0x58 register offset'
-S':alias for --cmbsts'
--cmbebs':CMBEBS=0x5c register offset'
-E':alias for --cmbebs'
--cmbswtp':CMBSWTP=0x60 register offset'
-W':alias for --cmbswtp'
--crto':CRTO=0x68 register offset'
-r':alias for --crto'
--pmrcap':PMRCAP=0xe00 register offset'
-P':alias for --pmrcap'
--pmrsts':PMRSTS=0xe08 register offset'
-t':alias for --pmrsts'
--pmrebs':PMREBS=0xe0c register offset'
-e':alias for --pmrebs'
--pmrswtp':PMRSWTP=0xe10 register offset'
-w':alias for --pmrswtp'
--intms':INTMS=0xc register offset'
-i':alias for --intms'
--intmc':INTMC=0x10 register offset'
-I':alias for --intmc'
--cc':CC=0x14 register offset'
-C':alias for --cc'
--csts':CSTS=0x1c register offset'
-T':alias for --csts'
--nssr':NSSR=0x20 register offset'
-n':alias for --nssr'
--aqa':AQA=0x24 register offset'
-a':alias for --aqa'
--asq':ASQ=0x28 register offset'
-A':alias for --asq'
--acq':ACQ=0x30 register offset'
-q':alias for --acq'
--bprsel':BPRSEL=0x44 register offset'
-B':alias for --bprsel'
--bpmbl':BPMBL=0x48 register offset'
-p':alias for --bpmbl'
--cmbmsc':CMBMSC=0x50 register offset'
-s':alias for --cmbmsc'
--nssd':NSSD=0x64 register offset'
-N':alias for --nssd'
--pmrctl':PMRCTL=0xe04 register offset'
-R':alias for --pmrctl'
--pmrmscl':PMRMSCL=0xe14 register offset'
-l':alias for --pmrmscl'
--pmrmscu':PMRMSCU=0xe18 register offset'
-u':alias for --pmrmscu'
--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'
-i':alias for --intms'
--intmc=':INTMC=0x10 register offset'
-I':alias for --intmc'
--cc=':CC=0x14 register offset'
-C':alias for --cc'
--csts=':CSTS=0x1c register offset'
-T':alias for --csts'
--nssr=':NSSR=0x20 register offset'
-n':alias for --nssr'
--aqa=':AQA=0x24 register offset'
-a':alias for --aqa'
--asq=':ASQ=0x28 register offset'
-A':alias for --asq'
--acq=':ACQ=0x30 register offset'
-q':alias for --acq'
--bprsel=':BPRSEL=0x44 register offset'
-B':alias for --bprsel'
--bpmbl=':BPMBL=0x48 register offset'
-p':alias for --bpmbl'
--cmbmsc=':CMBMSC=0x50 register offset'
-s':alias for --cmbmsc'
--nssd=':NSSD=0x64 register offset'
-N':alias for --nssd'
--pmrctl=':PMRCTL=0xe04 register offset'
-R':alias for --pmrctl'
--pmrmscl=':PMRMSCL=0xe14 register offset'
-l':alias for --pmrmscl'
--pmrmscu=':PMRMSCU=0xe18 register offset'
-u':alias for --pmrmscu'
--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
19 changes: 18 additions & 1 deletion completions/bash-nvme-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,23 @@ 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 -c --vs -V \
--cmbloc -m --cmbsz -M --bpinfo -b --cmbsts -S \
--cmbebs -E --cmbswtp -W --crto -r --pmrcap -P \
--pmrsts -t --pmrebs -e --pmrswtp -w --intms -i \
--intmc -I --cc -C --csts -T --nssr -n --aqa -a \
--asq -A --acq -q --bprsel -B --bpmbl -p --cmbmsc -s \
--nssd -N --pmrctl -R --pmrmscl -l --pmrmscu -u \
--output-format -o --verbose -v"
;;
"set-reg")
opts+=" --offset, -O --value= -V --mmio32 -M --intms= -i \
--intmc= -I --cc= -C --csts= -T --nssr= -n --aqa= -a \
--asq= -A --acq= -q --bprsel= -B --bpmbl= -p \
--cmbmsc= -s --nssd= -N --pmrctl= -R --pmrmscl= -l \
--pmrmscu= -u --output-format= -o --verbose= -v"
;;
"version")
opts+=$NO_OPTS
;;
Expand Down Expand Up @@ -1571,7 +1588,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
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 1e95aad

Please sign in to comment.