linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/4] nvme-cli: ioctl: support 64-bit ioctls
@ 2019-11-05  8:10 Marta Rybczynska
  2019-11-05 13:45 ` Keith Busch
  0 siblings, 1 reply; 5+ messages in thread
From: Marta Rybczynska @ 2019-11-05  8:10 UTC (permalink / raw)
  To: Keith Busch, linux-nvme

The existing ioctl passthru commands had a limit of 32-bit result.
Some commands (like get property for the CAP field) require 64
bits. A new added ioctl in the kernel allows this operation.

This patch adds usage of the 64-bit version for the get-property
command, falling back to 32-bit if necessary.

Signed-off-by: Marta Rybczynska <marta.rybczynska@kalray.eu>
---
 nvme-ioctl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 5 deletions(-)

diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index 35df04d..e9fc158 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -93,6 +93,24 @@ static int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd)
 	return ioctl(fd, NVME_IOCTL_ADMIN_CMD, cmd);
 }
 
+static int nvme_submit_admin_passthru64(int fd, struct nvme_passthru_cmd64 *cmd)
+{
+	int res;
+
+	res = ioctl(fd, NVME_IOCTL_ADMIN64_CMD, cmd);
+	if (res && (errno == EINVAL)) {
+		/* If the 64-bit command is not implemented in the system,
+		 * fallback to the 32-bit one. The structures differ only
+		 * in the result that is at the end.
+		 */
+		struct nvme_passthru_cmd cmd32;
+
+		memcpy(&cmd32, cmd, sizeof(cmd32));
+		res = ioctl(fd, NVME_IOCTL_ADMIN_CMD, cmd32);
+	}
+	return res;
+}
+
 static int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd)
 {
 	return ioctl(fd, NVME_IOCTL_IO_CMD, cmd);
@@ -600,9 +618,30 @@ static void nvme_to_passthru_cmd(struct nvme_passthru_cmd *pcmd,
 	pcmd->cdw15 = le32_to_cpu(ncmd->common.cdw10[5]);
 }
 
+static void nvme_to_passthru_cmd64(struct nvme_passthru_cmd64 *pcmd,
+				   const struct nvme_command *ncmd)
+{
+	assert(sizeof(*ncmd) < sizeof(*pcmd));
+	memset(pcmd, 0, sizeof(*pcmd));
+	pcmd->opcode = ncmd->common.opcode;
+	pcmd->flags = ncmd->common.flags;
+	pcmd->rsvd1 = ncmd->common.command_id;
+	pcmd->nsid = le32_to_cpu(ncmd->common.nsid);
+	pcmd->cdw2 = le32_to_cpu(ncmd->common.cdw2[0]);
+	pcmd->cdw3 = le32_to_cpu(ncmd->common.cdw2[1]);
+	/* Skip metadata and addr */
+	pcmd->cdw10 = le32_to_cpu(ncmd->common.cdw10[0]);
+	pcmd->cdw11 = le32_to_cpu(ncmd->common.cdw10[1]);
+	pcmd->cdw12 = le32_to_cpu(ncmd->common.cdw10[2]);
+	pcmd->cdw13 = le32_to_cpu(ncmd->common.cdw10[3]);
+	pcmd->cdw14 = le32_to_cpu(ncmd->common.cdw10[4]);
+	pcmd->cdw15 = le32_to_cpu(ncmd->common.cdw10[5]);
+}
+
+
 int nvme_get_property(int fd, int offset, uint64_t *value)
 {
-	struct nvme_passthru_cmd pcmd;
+	struct nvme_passthru_cmd64 pcmd;
 	struct nvmf_property_get_command pg = {
 		.opcode	= nvme_fabrics_command,
 		.fctype	= nvme_fabrics_type_property_get,
@@ -613,12 +652,14 @@ int nvme_get_property(int fd, int offset, uint64_t *value)
 	int err;
 
 	gcmd.prop_get = pg;
-	nvme_to_passthru_cmd(&pcmd, &gcmd);
-	err = nvme_submit_admin_passthru(fd, &pcmd);
+	nvme_to_passthru_cmd64(&pcmd, &gcmd);
+	err = nvme_submit_admin_passthru64(fd, &pcmd);
 	if (!err) {
 		/*
-		 * nvme_submit_admin_passthru() stores the lower 32 bits
-		 * of the property value in pcmd.result using CPU endianness.
+		 * If we have the 64-bit ioctl version, we got the
+		 * complete result. Otherwise nvme_submit_admin_passthru()
+		 * stores the lower 32 bits of the property value in
+		 * pcmd.result using CPU endianness.
 		 */
 		*value = pcmd.result;
 	}
-- 
1.8.3.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-11-05 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  8:10 [PATCH 4/4] nvme-cli: ioctl: support 64-bit ioctls Marta Rybczynska
2019-11-05 13:45 ` Keith Busch
2019-11-05 14:05   ` Marta Rybczynska
2019-11-05 14:58     ` Keith Busch
2019-11-05 15:13       ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).