[nvme-cli PATCH 2/2] nvme-ioctl: add command retry driver control flag to passthru

Minwoo Im minwoo.im.dev at gmail.com
Mon Feb 15 08:05:54 EST 2021


Replace existing reserved field in passthru ioctl command structures.
This patch also removed the `--rsvd` option from the passthru command
because even if it's given, it's not going to be passthrough to the
kernel driver: meaningless input.

This patch introduced the first flag value for command retry in case of
!DNR failure case from controller.  If `--retry` option is given to
passthru command, it will be retried by the driver itself rather than
returning error to the user-space direcly.

Signed-off-by: Minwoo Im <minwoo.im.dev at gmail.com>
---
 linux/nvme_ioctl.h | 12 +++++++++---
 nvme-ioctl.c       |  5 ++---
 nvme-ioctl.h       |  2 +-
 nvme.c             | 15 +++++++++------
 4 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/linux/nvme_ioctl.h b/linux/nvme_ioctl.h
index d569414211d1..17dde016cb5c 100644
--- a/linux/nvme_ioctl.h
+++ b/linux/nvme_ioctl.h
@@ -23,7 +23,7 @@ struct nvme_user_io {
 	__u8	flags;
 	__u16	control;
 	__u16	nblocks;
-	__u16	rsvd;
+	__u16	driver_ctrl;
 	__u64	metadata;
 	__u64	addr;
 	__u64	slba;
@@ -36,7 +36,7 @@ struct nvme_user_io {
 struct nvme_passthru_cmd {
 	__u8	opcode;
 	__u8	flags;
-	__u16	rsvd1;
+	__u16	driver_ctrl;
 	__u32	nsid;
 	__u32	cdw2;
 	__u32	cdw3;
@@ -57,7 +57,7 @@ struct nvme_passthru_cmd {
 struct nvme_passthru_cmd64 {
     __u8    opcode;
     __u8    flags;
-    __u16   rsvd1;
+    __u16   driver_ctrl;
     __u32   nsid;
     __u32   cdw2;
     __u32   cdw3;
@@ -88,4 +88,10 @@ struct nvme_passthru_cmd64 {
 #define NVME_IOCTL_ADMIN64_CMD  _IOWR('N', 0x47, struct nvme_passthru_cmd64)
 #define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct nvme_passthru_cmd64)
 
+enum nvme_driver_ctrl_bits {
+	/* Retry command if failed with !DNR for <= nvme_max_retries */
+	__NVME_DRIVER_CTRL_RETRY,	};
+
+#define NVME_DRIVER_CTRL_RETRY	(1 << __NVME_DRIVER_CTRL_RETRY)
+
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index 3e19023be890..2176fb3747ec 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -90,7 +90,7 @@ int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd)
 }
 
 int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode,
-		  __u8 flags, __u16 rsvd,
+		  __u8 flags, __u16 driver_ctrl,
 		  __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11,
 		  __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15,
 		  __u32 data_len, void *data, __u32 metadata_len,
@@ -99,7 +99,7 @@ int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode,
 	struct nvme_passthru_cmd cmd = {
 		.opcode		= opcode,
 		.flags		= flags,
-		.rsvd1		= rsvd,
+		.driver_ctrl	= driver_ctrl,
 		.nsid		= nsid,
 		.cdw2		= cdw2,
 		.cdw3		= cdw3,
@@ -133,7 +133,6 @@ int nvme_io(int fd, __u8 opcode, __u64 slba, __u16 nblocks, __u16 control,
 		.flags		= 0,
 		.control	= control,
 		.nblocks	= nblocks,
-		.rsvd		= 0,
 		.metadata	= (__u64)(uintptr_t) metadata,
 		.addr		= (__u64)(uintptr_t) data,
 		.slba		= slba,
diff --git a/nvme-ioctl.h b/nvme-ioctl.h
index 2b7640734398..a442da0275cc 100644
--- a/nvme-ioctl.h
+++ b/nvme-ioctl.h
@@ -17,7 +17,7 @@ int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd);
 int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd);
 
 int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode, __u8 flags,
-		  __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3,
+		  __u16 driver_ctrl, __u32 nsid, __u32 cdw2, __u32 cdw3,
 		  __u32 cdw10, __u32 cdw11, __u32 cdw12,
 		  __u32 cdw13, __u32 cdw14, __u32 cdw15,
 		  __u32 data_len, void *data, __u32 metadata_len,
diff --git a/nvme.c b/nvme.c
index 5324e8bbe79f..419b2ecbf30f 100644
--- a/nvme.c
+++ b/nvme.c
@@ -5060,11 +5060,11 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	int err = 0, wfd = STDIN_FILENO, fd;
 	__u32 result;
 	bool huge;
+	__u16 driver_ctrl = 0x0;
 
 	struct config {
 		__u8  opcode;
 		__u8  flags;
-		__u16 rsvd;
 		__u32 namespace_id;
 		__u32 data_len;
 		__u32 metadata_len;
@@ -5084,12 +5084,12 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		int   read;
 		int   write;
 		__u8  prefill;
+		bool  retry;
 	};
 
 	struct config cfg = {
 		.opcode       = 0,
 		.flags        = 0,
-		.rsvd         = 0,
 		.namespace_id = 0,
 		.data_len     = 0,
 		.metadata_len = 0,
@@ -5104,11 +5104,11 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		.cdw15        = 0,
 		.input_file   = "",
 		.prefill      = 0,
+		.retry        = false,
 	};
 
 	const char *opcode = "opcode (required)";
 	const char *flags = "command flags";
-	const char *rsvd = "value for reserved field";
 	const char *namespace_id = "desired namespace";
 	const char *data_len = "data I/O length (bytes)";
 	const char *metadata_len = "metadata seg. length (bytes)";
@@ -5128,12 +5128,12 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	const char *re = "set dataflow direction to receive";
 	const char *wr = "set dataflow direction to send";
 	const char *prefill = "prefill buffers with known byte-value, default 0";
+	const char *retry = "command retry if failed with !DNR";
 
 	OPT_ARGS(opts) = {
 		OPT_BYTE("opcode",       'o', &cfg.opcode,       opcode),
 		OPT_BYTE("flags",        'f', &cfg.flags,        flags),
 		OPT_BYTE("prefill",      'p', &cfg.prefill,      prefill),
-		OPT_SHRT("rsvd",         'R', &cfg.rsvd,         rsvd),
 		OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
 		OPT_UINT("data-len",     'l', &cfg.data_len,     data_len),
 		OPT_UINT("metadata-len", 'm', &cfg.metadata_len, metadata_len),
@@ -5152,6 +5152,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		OPT_FLAG("dry-run",      'd', &cfg.dry_run,      dry),
 		OPT_FLAG("read",         'r', &cfg.read,         re),
 		OPT_FLAG("write",        'w', &cfg.write,        wr),
+		OPT_FLAG("retry",        'R', &cfg.retry,        retry),
 		OPT_END()
 	};
 
@@ -5213,7 +5214,6 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	if (cfg.show_command) {
 		printf("opcode       : %02x\n", cfg.opcode);
 		printf("flags        : %02x\n", cfg.flags);
-		printf("rsvd1        : %04x\n", cfg.rsvd);
 		printf("nsid         : %08x\n", cfg.namespace_id);
 		printf("cdw2         : %08x\n", cfg.cdw2);
 		printf("cdw3         : %08x\n", cfg.cdw3);
@@ -5232,7 +5232,10 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	if (cfg.dry_run)
 		goto free_data;
 
-	err = nvme_passthru(fd, ioctl_cmd, cfg.opcode, cfg.flags, cfg.rsvd,
+	if (cfg.retry)
+		driver_ctrl |= NVME_DRIVER_CTRL_RETRY;
+
+	err = nvme_passthru(fd, ioctl_cmd, cfg.opcode, cfg.flags, driver_ctrl,
 				cfg.namespace_id, cfg.cdw2, cfg.cdw3, cfg.cdw10,
 				cfg.cdw11, cfg.cdw12, cfg.cdw13, cfg.cdw14, cfg.cdw15,
 				cfg.data_len, data, cfg.metadata_len, metadata,
-- 
2.17.1




More information about the Linux-nvme mailing list