linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>,
	Keith Busch <keith.busch@wdc.com>,
	Chaitanya Kulkarni <chaitanyak@nvidia.com>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>,
	Chaitanya Kulkarni <kch@nvidia.com>
Subject: [PATCH 5/7] nvme: expose subsystem type in sysfs attribute 'subtype'
Date: Wed, 22 Sep 2021 08:35:23 +0200	[thread overview]
Message-ID: <20210922063525.143045-6-hare@suse.de> (raw)
In-Reply-To: <20210922063525.143045-1-hare@suse.de>

With unique discovery controller NQNs we cannot distinguish the
subsystem type by the NQN alone, but need to check the subsystem
type, too.
So expose the subsystem type in a new sysfs attribute 'subtype'.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/core.c | 27 +++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 28 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e486845d2c7e..1ed1b7be2812 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2598,6 +2598,24 @@ static ssize_t nvme_subsys_show_nqn(struct device *dev,
 }
 static SUBSYS_ATTR_RO(subsysnqn, S_IRUGO, nvme_subsys_show_nqn);
 
+static ssize_t nvme_subsys_show_subtype(struct device *dev,
+				    struct device_attribute *attr,
+				    char *buf)
+{
+	struct nvme_subsystem *subsys =
+		container_of(dev, struct nvme_subsystem, dev);
+
+	switch (subsys->subtype) {
+	case NVME_NQN_DISC:
+		return sysfs_emit(buf, "discovery\n");
+	case NVME_NQN_NVME:
+		return sysfs_emit(buf, "nvm\n");
+	default:
+		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static SUBSYS_ATTR_RO(subtype, S_IRUGO, nvme_subsys_show_subtype);
+
 #define nvme_subsys_show_str_function(field)				\
 static ssize_t subsys_##field##_show(struct device *dev,		\
 			    struct device_attribute *attr, char *buf)	\
@@ -2618,6 +2636,7 @@ static struct attribute *nvme_subsys_attrs[] = {
 	&subsys_attr_serial.attr,
 	&subsys_attr_firmware_rev.attr,
 	&subsys_attr_subsysnqn.attr,
+	&subsys_attr_subtype.attr,
 #ifdef CONFIG_NVME_MULTIPATH
 	&subsys_attr_iopolicy.attr,
 #endif
@@ -2688,6 +2707,14 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 	memcpy(subsys->firmware_rev, id->fr, sizeof(subsys->firmware_rev));
 	subsys->vendor_id = le16_to_cpu(id->vid);
 	subsys->cmic = id->cmic;
+
+	/* Versions prior to 1.4 don't necessarily report a valid type */
+	if (id->cntrltype == NVME_CTRL_DISC ||
+	    !strcmp(subsys->subnqn, NVME_DISC_SUBSYS_NAME))
+		subsys->subtype = NVME_NQN_DISC;
+	else
+		subsys->subtype = NVME_NQN_NVME;
+
 	subsys->awupf = le16_to_cpu(id->awupf);
 #ifdef CONFIG_NVME_MULTIPATH
 	subsys->iopolicy = NVME_IOPOLICY_NUMA;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 9871c0c9374c..2c7a77f600f8 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -366,6 +366,7 @@ struct nvme_subsystem {
 	char			model[40];
 	char			firmware_rev[8];
 	u8			cmic;
+	enum nvme_subsys_type	subtype;
 	u16			vendor_id;
 	u16			awupf;	/* 0's based awupf value. */
 	struct ida		ns_ida;
-- 
2.29.2


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

  parent reply	other threads:[~2021-09-22  6:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  6:35 [PATCHv3 0/7] nvme: support unique discovery controller NQN Hannes Reinecke
2021-09-22  6:35 ` [PATCH 1/7] nvmet: make discovery NQN configurable Hannes Reinecke
2021-09-22  7:07   ` Chaitanya Kulkarni
2021-09-22 13:36   ` Himanshu Madhani
2021-09-22  6:35 ` [PATCH 2/7] nvme: add CNTRLTYPE definitions for 'identify controller' Hannes Reinecke
2021-09-22 13:37   ` Himanshu Madhani
2021-09-22  6:35 ` [PATCH 3/7] nvmet: add nvmet_is_disc_subsys() helper Hannes Reinecke
2021-09-22  7:06   ` Chaitanya Kulkarni
2021-09-22 13:36   ` Himanshu Madhani
2021-09-22  6:35 ` [PATCH 4/7] nvmet: set 'CNTRLTYPE' in the identify controller data Hannes Reinecke
2021-09-22  7:08   ` Chaitanya Kulkarni
2021-09-22  6:35 ` Hannes Reinecke [this message]
2021-09-22  8:02   ` [PATCH 5/7] nvme: expose subsystem type in sysfs attribute 'subtype' Daniel Wagner
2021-10-12 13:10     ` Christoph Hellwig
2021-10-12 13:43       ` Hannes Reinecke
2021-10-12 13:44         ` Christoph Hellwig
2021-09-22  6:35 ` [PATCH 6/7] nvme: Add connect option 'discovery' Hannes Reinecke
2021-09-22 16:59   ` James Smart
2021-09-23  6:11     ` Hannes Reinecke
2021-09-22  6:35 ` [PATCH 7/7] nvme: display correct subsystem NQN Hannes Reinecke
2021-10-12 13:10 ` [PATCHv3 0/7] nvme: support unique discovery controller NQN Christoph Hellwig

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=20210922063525.143045-6-hare@suse.de \
    --to=hare@suse.de \
    --cc=chaitanyak@nvidia.com \
    --cc=hch@lst.de \
    --cc=kch@nvidia.com \
    --cc=keith.busch@wdc.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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).