Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@meta.com>
To: <linux-nvme@lists.infradead.org>
Cc: <hch@lst.de>, <m@bjorling.me>, <matias.bjorling@wdc.com>,
	<kch@nvidia.com>, <kanie@linux.alibaba.com>,
	Keith Busch <kbusch@kernel.org>
Subject: [PATCHv4 08/13] nvmet: implement rotational media information log
Date: Thu, 7 Nov 2024 11:38:43 -0800	[thread overview]
Message-ID: <20241107193849.995554-9-kbusch@meta.com> (raw)
In-Reply-To: <20241107193849.995554-1-kbusch@meta.com>

From: Keith Busch <kbusch@kernel.org>

Most of the information is stubbed. Supporting this log is a requirement
for supporting rotational media.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 drivers/nvme/host/core.c        |  1 +
 drivers/nvme/target/admin-cmd.c | 42 +++++++++++++++++++++++++++++++++
 include/linux/nvme.h            | 15 +++++++++++-
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 426d4b90ecd7e..279b0f445904d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -5002,6 +5002,7 @@ static inline void _nvme_check_size(void)
 	BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64);
 	BUILD_BUG_ON(sizeof(struct nvme_smart_log) != 512);
 	BUILD_BUG_ON(sizeof(struct nvme_endurance_group_log) != 512);
+	BUILD_BUG_ON(sizeof(struct nvme_rotational_media_log) != 512);
 	BUILD_BUG_ON(sizeof(struct nvme_dbbuf) != 64);
 	BUILD_BUG_ON(sizeof(struct nvme_directive_cmd) != 64);
 	BUILD_BUG_ON(sizeof(struct nvme_feat_host_behavior) != 512);
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index db26cd50be909..6d3a1d2103bf3 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -91,6 +91,7 @@ static void nvmet_execute_get_supported_log_pages(struct nvmet_req *req)
 	logs->lids[NVME_LOG_ENDURANCE_GROUP] = cpu_to_le32(NVME_LIDS_LSUPP);
 	logs->lids[NVME_LOG_ANA] = cpu_to_le32(NVME_LIDS_LSUPP);
 	logs->lids[NVME_LOG_FEATURES] = cpu_to_le32(NVME_LIDS_LSUPP);
+	logs->lids[NVME_LOG_RMI] = cpu_to_le32(NVME_LIDS_LSUPP);
 
 	status = nvmet_copy_to_sgl(req, 0, logs, sizeof(*logs));
 	kfree(logs);
@@ -157,6 +158,45 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,
 	return NVME_SC_SUCCESS;
 }
 
+static void nvmet_execute_get_log_page_rmi(struct nvmet_req *req)
+{
+	struct nvme_rotational_media_log *log;
+	struct gendisk *disk;
+	u16 status;
+
+	req->cmd->common.nsid = cpu_to_le32(le16_to_cpu(
+					    req->cmd->get_log_page.lsi));
+	status = nvmet_req_find_ns(req);
+	if (status)
+		goto out;
+
+	if (!req->ns->bdev || bdev_nonrot(req->ns->bdev)) {
+		status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
+		goto out;
+	}
+
+	if (req->transfer_len != sizeof(*log)) {
+		status = NVME_SC_SGL_INVALID_DATA | NVME_STATUS_DNR;
+		goto out;
+	}
+
+	log = kzalloc(sizeof(*log), GFP_KERNEL);
+	if (!log)
+		goto out;
+
+	log->endgid = req->cmd->get_log_page.lsi;
+	disk = req->ns->bdev->bd_disk;
+	if (disk && disk->ia_ranges)
+		log->numa = cpu_to_le16(disk->ia_ranges->nr_ia_ranges);
+	else
+		log->numa = cpu_to_le16(1);
+
+	status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));
+	kfree(log);
+out:
+	nvmet_req_complete(req, status);
+}
+
 static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
 {
 	struct nvme_smart_log *log;
@@ -444,6 +484,8 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)
 		return nvmet_execute_get_log_page_ana(req);
 	case NVME_LOG_FEATURES:
 		return nvmet_execute_get_log_page_features(req);
+	case NVME_LOG_RMI:
+		return nvmet_execute_get_log_page_rmi(req);
 	}
 	pr_debug("unhandled lid %d on qid %d\n",
 	       req->cmd->get_log_page.lid, req->sq->qid);
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 9b5867f1aa591..93a0abfab5b0e 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -642,6 +642,18 @@ struct nvme_endurance_group_log {
 	__u8	rsvd192[320];
 };
 
+struct nvme_rotational_media_log {
+	__le16	endgid;
+	__le16	numa;
+	__le16	nrs;
+	__u8	rsvd6[2];
+	__le32	spinc;
+	__le32	fspinc;
+	__le32	ldc;
+	__le32	fldc;
+	__u8	rsvd24[488];
+};
+
 struct nvme_smart_log {
 	__u8			critical_warning;
 	__u8			temperature[2];
@@ -1281,6 +1293,7 @@ enum {
 	NVME_LOG_ENDURANCE_GROUP = 0x09,
 	NVME_LOG_ANA		= 0x0c,
 	NVME_LOG_FEATURES	= 0x12,
+	NVME_LOG_RMI		= 0x16,
 	NVME_LOG_DISC		= 0x70,
 	NVME_LOG_RESERVATION	= 0x80,
 	NVME_FWACT_REPL		= (0 << 3),
@@ -1435,7 +1448,7 @@ struct nvme_get_log_page_command {
 	__u8			lsp; /* upper 4 bits reserved */
 	__le16			numdl;
 	__le16			numdu;
-	__u16			rsvd11;
+	__le16			lsi;
 	union {
 		struct {
 			__le32 lpol;
-- 
2.43.5



  parent reply	other threads:[~2024-11-07 19:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 19:38 [PATCHv4 00/13] nvme target 2.1 and independent identify ns Keith Busch
2024-11-07 19:38 ` [PATCHv4 01/13] nvmet: implement id ns for nvm command set Keith Busch
2024-11-08 12:01   ` Matias Bjørling
2024-11-08 14:21   ` Christoph Hellwig
2024-11-07 19:38 ` [PATCHv4 02/13] nvmet: implement active command set ns list Keith Busch
2024-11-08 12:10   ` Matias Bjørling
2024-11-07 19:38 ` [PATCHv4 03/13] nvmet: implement supported log pages Keith Busch
2024-11-08 12:16   ` Matias Bjørling
2024-11-08 14:22   ` Christoph Hellwig
2024-11-11  1:57   ` Chaitanya Kulkarni
2024-11-07 19:38 ` [PATCHv4 04/13] nvmet: implement supported features log Keith Busch
2024-11-08 12:24   ` Matias Bjørling
2024-11-08 14:24   ` Christoph Hellwig
2024-11-07 19:38 ` [PATCHv4 05/13] nvmet: implement crto property Keith Busch
2024-11-08 12:34   ` Matias Bjørling
2024-11-07 19:38 ` [PATCHv4 06/13] nvmet: declare 2.1 version compliance Keith Busch
2024-11-08 12:37   ` Matias Bjørling
2024-11-07 19:38 ` [PATCHv4 07/13] nvmet: implement endurance groups Keith Busch
2024-11-08 14:26   ` Christoph Hellwig
2024-11-07 19:38 ` Keith Busch [this message]
2024-11-07 19:38 ` [PATCHv4 09/13] nvmet: implement csi identify ns Keith Busch
2024-11-08  1:42   ` Guixin Liu
2024-11-08 14:26   ` Christoph Hellwig
2024-11-07 19:38 ` [PATCHv4 10/13] nvme: use command set independent id ns if available Keith Busch
2024-11-08 14:26   ` Christoph Hellwig
2024-11-07 19:38 ` [PATCHv4 11/13] nvme: add rotational support Keith Busch
2024-11-09 15:01   ` Guixin Liu
2024-11-07 19:38 ` [PATCHv4 12/13] nvme: check ns's volatile write cache not present Keith Busch
2024-11-07 19:38 ` [PATCHv4 13/13] nvmet: report ns's vwc " Keith Busch
2024-11-08 14:27   ` Christoph Hellwig
2024-11-08 16:15     ` Keith Busch
2024-11-09 14:59       ` Guixin Liu
2024-11-09 15:00         ` Guixin Liu
2024-11-12 22:49           ` Keith Busch
2024-11-13  1:51             ` Guixin Liu
2024-11-11  5:42         ` Christoph Hellwig
2024-11-11  5:41       ` Christoph Hellwig
2024-11-08 16:50 ` [PATCHv4 00/13] nvme target 2.1 and independent identify ns 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=20241107193849.995554-9-kbusch@meta.com \
    --to=kbusch@meta.com \
    --cc=hch@lst.de \
    --cc=kanie@linux.alibaba.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=m@bjorling.me \
    --cc=matias.bjorling@wdc.com \
    /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