From: Marta Rybczynska <mrybczyn@kalray.eu>
To: Keith Busch <keith.busch@intel.com>,
linux-nvme <linux-nvme@lists.infradead.org>
Subject: [PATCH 4/4] nvme-cli: ioctl: support 64-bit ioctls
Date: Tue, 5 Nov 2019 09:10:57 +0100 (CET) [thread overview]
Message-ID: <436860210.90381688.1572941457980.JavaMail.zimbra@kalray.eu> (raw)
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
next reply other threads:[~2019-11-05 8:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-05 8:10 Marta Rybczynska [this message]
2019-11-05 13:45 ` [PATCH 4/4] nvme-cli: ioctl: support 64-bit ioctls Keith Busch
2019-11-05 14:05 ` Marta Rybczynska
2019-11-05 14:58 ` Keith Busch
2019-11-05 15:13 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=436860210.90381688.1572941457980.JavaMail.zimbra@kalray.eu \
--to=mrybczyn@kalray.eu \
--cc=keith.busch@intel.com \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).