Skip to contentSkip to conversation

nvme: send uevent on connection up

PATCH Superseded Martin Belanger 6 participants 19 messages Feb 2, 2022 – Feb 3, 2022 1 message not in the archive NVMe

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 nvme: send uevent on connection up

From: Martin Belanger <[email protected]>

When connectivity with a controller is lost, the driver will keep trying to reconnect once every 10 sec. When connection is restored, user-space apps need to be informed so that they can take proper action. For example, TP8010 introduces the DIM PDU, which is used to register with a discovery controller (DC). The DIM PDU is sent from user-space. The DIM PDU must be sent every time a connection is established with a DC. Therefore, the kernel must tell user-space apps when connection is restored so that registration can happen.

The uevent sent is a "change" uevent with environmental data set to: "NVME_EVENT=connected".

---
 drivers/nvme/host/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/nvme/host/core.c +9 -0
index 961a5f8a44d2..872c389dc6d3 100644
@@ -4231,6 +4231,13 @@ static int nvme_class_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return ret;
 }
 
+static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata)
+{
+	char *envp[2] = { envdata, NULL };
+
+	kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp);
+}
+
 static void nvme_aen_uevent(struct nvme_ctrl *ctrl)
 {
 	char *envp[2] = { NULL, NULL };
@@ -4405,6 +4412,8 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
 		nvme_queue_scan(ctrl);
 		nvme_start_queues(ctrl);
 	}
+
+	nvme_change_uevent(ctrl, "NVME_EVENT=connected");
 }
 EXPORT_SYMBOL_GPL(nvme_start_ctrl);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw
Quoted 38 lines · Martin Belanger

From: Martin Belanger <[email protected]>

When connectivity with a controller is lost, the driver will keep trying to reconnect once every 10 sec. When connection is restored, user-space apps need to be informed so that they can take proper action. For example, TP8010 introduces the DIM PDU, which is used to register with a discovery controller (DC). The DIM PDU is sent from user-space. The DIM PDU must be sent every time a connection is established with a DC. Therefore, the kernel must tell user-space apps when connection is restored so that registration can happen.

The uevent sent is a "change" uevent with environmental data set to: "NVME_EVENT=connected".

---
  drivers/nvme/host/core.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/nvme/host/core.c +7 -0
index 961a5f8a44d2..872c389dc6d3 100644
@@ -4231,6 +4231,13 @@ static int nvme_class_uevent(struct device *dev, struct kobj_uevent_env *env)
  	return ret;
  }
 
+static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata)
+{
+	char *envp[2] = { envdata, NULL };
+
+	kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp);
+}
+
  static void nvme_aen_uevent(struct nvme_ctrl *ctrl)
  {
  	char *envp[2] = { NULL, NULL };

drivers/nvme/host/core.c void nvme_start_ctrl(struct nvme_ctrl *ctrl) · line 4419

Quoted 8 lines
drivers/nvme/host/core.c +2 -0
@@ -4405,6 +4412,8 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
  		nvme_queue_scan(ctrl);
  		nvme_start_queues(ctrl);
  	}
+
+	nvme_change_uevent(ctrl, "NVME_EVENT=connected");
  }
  EXPORT_SYMBOL_GPL(nvme_start_ctrl);
 

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v1 1/2
#4 lore raw
In reply to Martin Belanger
Quoted 11 lines · Martin Belanger

From: Martin Belanger <[email protected]>

When connectivity with a controller is lost, the driver will keep trying to reconnect once every 10 sec. When connection is restored, user-space apps need to be informed so that they can take proper action. For example, TP8010 introduces the DIM PDU, which is used to register with a discovery controller (DC). The DIM PDU is sent from user-space. The DIM PDU must be sent every time a connection is established with a DC. Therefore, the kernel must tell user-space apps when connection is restored so that registration can happen.

Quoted 5 lines

The uevent sent is a "change" uevent with environmental data set to: "NVME_EVENT=connected".

---

Looks good.

#5 lore raw

PATCH 2/2 nvme: Expose cntrltype and dctype through sysfs.

In reply to a message not in the archive

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
 drivers/nvme/host/core.c | 35 +++++++++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h |  3 +++
 include/linux/nvme.h     | 10 +++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +35 -0
index 872c389dc6d3..c65d44fb65c4 100644
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
 	ctrl->max_namespaces = le32_to_cpu(id->mnan);
 	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
 	if (id->rtd3e) {
 		/* us -> s */
 		u32 transition_time = le32_to_cpu(id->rtd3e) / USEC_PER_SEC;
@@ -3525,6 +3528,34 @@ static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
 static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
 	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
 
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show, NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf, "nr\n");
+	case NVME_DCTYPE_DDC:		return sysfs_emit(buf, "ddc\n");
+	case NVME_DCTYPE_CDC:		return sysfs_emit(buf, "cdc\n");
+	default:			return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(dctype, S_IRUGO, nvme_ctrl_dctype_show, NULL);
+
 static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_reset_controller.attr,
 	&dev_attr_rescan_controller.attr,
@@ -3546,6 +3577,8 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_reconnect_delay.attr,
 	&dev_attr_fast_io_fail_tmo.attr,
 	&dev_attr_kato.attr,
+	&dev_attr_cntrltype.attr,
+	&dev_attr_dctype.attr,
 	NULL
 };
 
@@ -3569,6 +3602,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
 		return 0;
 	if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts)
 		return 0;
+	if (a == &dev_attr_dctype.attr && ctrl->cntrltype == NVME_CTRL_DISC)
+		return 0;
 
 	return a->mode;
 }
drivers/nvme/host/nvme.h +3 -0
index a162f6c6da6e..e30626c00791 100644
@@ -349,6 +349,9 @@ struct nvme_ctrl {
 	unsigned long discard_page_busy;
 
 	struct nvme_fault_inject fault_inject;
+
+	enum nvme_ctrl_type cntrltype;
+	enum nvme_dctype dctype;
 };
 
 enum nvme_iopolicy {
include/linux/nvme.h +9 -1
index 855dd9b3e84b..af1494d83a52 100644
@@ -43,6 +43,12 @@ enum nvme_ctrl_type {
 	NVME_CTRL_ADMIN	= 3,		/* Administrative controller */
 };
 
+enum nvme_dctype {
+	NVME_DCTYPE_NOT_REPORTED = 0,
+	NVME_DCTYPE_DDC = 1,		/* Direct Discovery Controller */
+	NVME_DCTYPE_CDC = 2,		/* Central Discovery Controller */
+};
+
 /* Address Family codes for Discovery Log Page entry ADRFAM field */
 enum {
 	NVMF_ADDR_FAMILY_PCI	= 0,	/* PCIe */
@@ -320,7 +326,9 @@ struct nvme_id_ctrl {
 	__le16			icdoff;
 	__u8			ctrattr;
 	__u8			msdbd;
-	__u8			rsvd1804[244];
+	__u8			rsvd1804[2];
+	__u8			dctype;
+	__u8			rsvd1807[241];
 	struct nvme_id_power_state	psd[32];
 	__u8			vs[1024];
 };
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 32 lines · Martin Belanger

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
  drivers/nvme/host/core.c | 35 +++++++++++++++++++++++++++++++++++
  drivers/nvme/host/nvme.h |  3 +++
  include/linux/nvme.h     | 10 +++++++++-
  3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +3 -0
index 872c389dc6d3..c65d44fb65c4 100644
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
  	ctrl->max_namespaces = le32_to_cpu(id->mnan);
  	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
  	if (id->rtd3e) {
  		/* us -> s */
  		u32 transition_time = le32_to_cpu(id->rtd3e) / USEC_PER_SEC;
@@ -3525,6 +3528,34 @@ static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
  static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3538

Quoted 10 lines
drivers/nvme/host/core.c +8 -0
  	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
 
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3551

Quoted 13 lines
drivers/nvme/host/core.c +13 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show, NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf, "nr\n");

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Quoted 60 lines
drivers/nvme/host/core.c +11 -0
+	case NVME_DCTYPE_DDC:		return sysfs_emit(buf, "ddc\n");
+	case NVME_DCTYPE_CDC:		return sysfs_emit(buf, "cdc\n");
+	default:			return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(dctype, S_IRUGO, nvme_ctrl_dctype_show, NULL);
+
  static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reset_controller.attr,
  	&dev_attr_rescan_controller.attr,
@@ -3546,6 +3577,8 @@ static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reconnect_delay.attr,
  	&dev_attr_fast_io_fail_tmo.attr,
  	&dev_attr_kato.attr,
+	&dev_attr_cntrltype.attr,
+	&dev_attr_dctype.attr,
  	NULL
  };
 
@@ -3569,6 +3602,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
  		return 0;
  	if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts)
  		return 0;
+	if (a == &dev_attr_dctype.attr && ctrl->cntrltype == NVME_CTRL_DISC)
+		return 0;
 
  	return a->mode;
  }
drivers/nvme/host/nvme.h +3 -0
index a162f6c6da6e..e30626c00791 100644
@@ -349,6 +349,9 @@ struct nvme_ctrl {
  	unsigned long discard_page_busy;
 
  	struct nvme_fault_inject fault_inject;
+
+	enum nvme_ctrl_type cntrltype;
+	enum nvme_dctype dctype;
  };
 
  enum nvme_iopolicy {
include/linux/nvme.h +6 -0
index 855dd9b3e84b..af1494d83a52 100644
@@ -43,6 +43,12 @@ enum nvme_ctrl_type {
  	NVME_CTRL_ADMIN	= 3,		/* Administrative controller */
  };
 
+enum nvme_dctype {
+	NVME_DCTYPE_NOT_REPORTED = 0,
+	NVME_DCTYPE_DDC = 1,		/* Direct Discovery Controller */
+	NVME_DCTYPE_CDC = 2,		/* Central Discovery Controller */
+};
+
  /* Address Family codes for Discovery Log Page entry ADRFAM field */
  enum {
  	NVMF_ADDR_FAMILY_PCI	= 0,	/* PCIe */

include/linux/nvme.h struct nvme_id_ctrl { · line 334

Quoted 10 lines
include/linux/nvme.h +3 -1
@@ -320,7 +326,9 @@ struct nvme_id_ctrl {
  	__le16			icdoff;
  	__u8			ctrattr;
  	__u8			msdbd;
-	__u8			rsvd1804[244];
+	__u8			rsvd1804[2];
+	__u8			dctype;
+	__u8			rsvd1807[241];
  	struct nvme_id_power_state	psd[32];
  	__u8			vs[1024];
  };

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
#7 lore raw

RE: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 64 lines · Martin Belanger
Quoted 11 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
  drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 9 lines
  drivers/nvme/host/nvme.h |  3 +++
  include/linux/nvme.h     | 10 +++++++++-
  3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c index renamed from drivers/nvme/host/core.c +0 -0

872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl)

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
  	ctrl->max_namespaces = le32_to_cpu(id->mnan);
  	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
  	if (id->rtd3e) {
  		/* us -> s */
  		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3538

Quoted 8 lines
drivers/nvme/host/core.c +7 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 13 lines
drivers/nvme/host/core.c +13 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Quoted 81 lines

drivers/nvme/host/core.c

Quoted 2 lines
drivers/nvme/host/core.c +1 -0
+	case NVME_DCTYPE_DDC:		return sysfs_emit(buf,

"ddc\n");

drivers/nvme/host/core.c

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	case NVME_DCTYPE_CDC:		return sysfs_emit(buf,

"cdc\n");

drivers/nvme/host/core.c static umode_t

Quoted 18 lines
drivers/nvme/host/core.c +7 -0
+	default:			return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(dctype, S_IRUGO, nvme_ctrl_dctype_show, NULL);
+
  static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reset_controller.attr,
  	&dev_attr_rescan_controller.attr,
@@ -3546,6 +3577,8 @@ static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reconnect_delay.attr,
  	&dev_attr_fast_io_fail_tmo.attr,
  	&dev_attr_kato.attr,
+	&dev_attr_cntrltype.attr,
+	&dev_attr_dctype.attr,
  	NULL
  };
 
@@ -3569,6 +3602,8 @@ static umode_t

nvme_dev_attrs_are_visible(struct kobject *kobj,

drivers/nvme/host/core.c static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,

Quoted 4 lines
drivers/nvme/host/core.c +1 -0
  		return 0;
  	if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts)
  		return 0;
+	if (a == &dev_attr_dctype.attr && ctrl->cntrltype ==

NVME_CTRL_DISC)

Quoted 23 lines
drivers/nvme/host/core.c +1 -0
+		return 0;
 
  	return a->mode;
  }
drivers/nvme/host/nvme.h index renamed from drivers/nvme/host/nvme.h +0 -0

a162f6c6da6e..e30626c00791 100644

drivers/nvme/host/nvme.h +3 -0
@@ -349,6 +349,9 @@ struct nvme_ctrl {
  	unsigned long discard_page_busy;
 
  	struct nvme_fault_inject fault_inject;
+
+	enum nvme_ctrl_type cntrltype;
+	enum nvme_dctype dctype;
  };
 
  enum nvme_iopolicy {
include/linux/nvme.h index renamed from include/linux/nvme.h +0 -0

855dd9b3e84b..af1494d83a52 100644

include/linux/nvme.h enum nvme_ctrl_type { · line 43

Quoted 1 line
include/linux/nvme.h +0 -0
@@ -43,6 +43,12 @@ enum nvme_ctrl_type {
  	NVME_CTRL_ADMIN	= 3,		/* Administrative controller

*/

include/linux/nvme.h enum nvme_ctrl_type {

Quoted 5 lines
include/linux/nvme.h +3 -0
  };
 
+enum nvme_dctype {
+	NVME_DCTYPE_NOT_REPORTED = 0,
+	NVME_DCTYPE_DDC = 1,		/* Direct Discovery Controller

*/

include/linux/nvme.h enum nvme_ctrl_type { · line 49

Quoted 1 line
include/linux/nvme.h +1 -0
+	NVME_DCTYPE_CDC = 2,		/* Central Discovery

Controller */

Quoted 6 lines
include/linux/nvme.h +2 -0
+};
+
  /* Address Family codes for Discovery Log Page entry ADRFAM field */
  enum {
  	NVMF_ADDR_FAMILY_PCI	= 0,	/* PCIe */

include/linux/nvme.h struct nvme_id_ctrl { · line 334

Quoted 10 lines
include/linux/nvme.h +3 -1
@@ -320,7 +326,9 @@ struct nvme_id_ctrl {
  	__le16			icdoff;
  	__u8			ctrattr;
  	__u8			msdbd;
-	__u8			rsvd1804[244];
+	__u8			rsvd1804[2];
+	__u8			dctype;
+	__u8			rsvd1807[241];
  	struct nvme_id_power_state	psd[32];
  	__u8			vs[1024];
  };

Cheers,

Quoted 6 lines

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

Internal Use - Confidential

#8 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 64 lines · Martin
Quoted 64 lines · Martin Belanger
Quoted 11 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
   drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 9 lines
   drivers/nvme/host/nvme.h |  3 +++
   include/linux/nvme.h     | 10 +++++++++-
   3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c index renamed from drivers/nvme/host/core.c +0 -0

872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl)

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
   	ctrl->max_namespaces = le32_to_cpu(id->mnan);
   	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
   	if (id->rtd3e) {
   		/* us -> s */
   		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3538

Quoted 8 lines
drivers/nvme/host/core.c +7 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 13 lines
drivers/nvme/host/core.c +13 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

Quoted 7 lines
Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Whole series, please. And gather up the reviews when resubmitting.

Quoted 7 lines

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype; then we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-ddc'.

Hmm?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		           Kernel Storage Architect
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
maintainer
#9 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 80 lines
Quoted 64 lines
Quoted 64 lines
Quoted 9 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

Quoted 3 lines

---
   drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 9 lines

   drivers/nvme/host/nvme.h |  3 +++
   include/linux/nvme.h     | 10 +++++++++-

   3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c index renamed from drivers/nvme/host/core.c +0 -0

872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
        ctrl->max_namespaces = le32_to_cpu(id->mnan);
        ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+    ctrl->cntrltype = id->cntrltype;
+    ctrl->dctype = id->dctype;
+
        if (id->rtd3e) {
            /* us -> s */

           u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

   static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3538

Quoted 8 lines
drivers/nvme/host/core.c +7 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+                     struct device_attribute *attr, char *buf) {
+    struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+    switch (ctrl->cntrltype) {
+    case NVME_CTRL_IO:    return sysfs_emit(buf, "io\n");
+    case NVME_CTRL_DISC:    return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 13 lines

+    case NVME_CTRL_ADMIN:    return sysfs_emit(buf, "admin\n"); +    default:        return sysfs_emit(buf, "reserved\n"); +    }

drivers/nvme/host/core.c +10 -0
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+                     struct device_attribute *attr, char *buf) {
+    struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+    switch (ctrl->dctype) {
+    case NVME_DCTYPE_NOT_REPORTED:    return sysfs_emit(buf,

"nr\n");

Quoted 7 lines
Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Whole series, please. And gather up the reviews when resubmitting.

Quoted 7 lines

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when  nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Quoted 6 lines

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype; then we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-ddc'.

Hmm?

We should really move the ctrl device node creation to nvme_init_ctrl_finish. I think this came up before...

#10 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Sagi,

Quoted 11 lines
Quoted 7 lines

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype; then we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-ddc'.

Hmm?

We should really move the ctrl device node creation to nvme_init_ctrl_finish. I think this came up before...

Unless I miss something all the transport rdma/pci/tcp/fc set ctrl state to NVME_CTRL_CONNECTING before calling nvme_init_ctrl_finish().

Are you referring to the call of cdev_device_add() we have in the nvme_init_ctrl() that needs to be moved into the nvme_init_ctrl_finish() so instead of ctrl holding NVME_CTRL_NEW state it will have NVME_CTRL_CONNECTING state ?

-ck

#11 lore raw

RE: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

In reply to Hannes Reinecke
Quoted 82 lines · Martin
Quoted 65 lines
Quoted 65 lines · Martin Belanger
Quoted 11 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
   drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 10 lines
   drivers/nvme/host/nvme.h |  3 +++
   include/linux/nvme.h     | 10 +++++++++-
   3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +0 -0

index
872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl)

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
   	ctrl->max_namespaces = le32_to_cpu(id->mnan);
   	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
   	if (id->rtd3e) {
   		/* us -> s */
   		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3538

Quoted 8 lines
drivers/nvme/host/core.c +7 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 13 lines
drivers/nvme/host/core.c +13 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

Quoted 7 lines
Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Whole series, please. And gather up the reviews when resubmitting.

Quoted 7 lines

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Quoted 6 lines

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype; then we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-ddc'.

Hmm?

I like that. I shall combine them into a single attribute. Thanks,
Martin

Quoted 9 lines

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

Internal Use - Confidential

maintainer
#12 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 81 lines
Quoted 81 lines
Quoted 65 lines
Quoted 65 lines
Quoted 9 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

Quoted 3 lines
---
    drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 10 lines
    drivers/nvme/host/nvme.h |  3 +++
    include/linux/nvme.h     | 10 +++++++++-
    3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +0 -0

index
872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl · line 3000

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
    	ctrl->max_namespaces = le32_to_cpu(id->mnan);
    	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
    	if (id->rtd3e) {
    		/* us -> s */
    		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c

Quoted 8 lines
drivers/nvme/host/core.c +7 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c

Quoted 13 lines
drivers/nvme/host/core.c +13 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

Quoted 7 lines
Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Whole series, please. And gather up the reviews when resubmitting.

Quoted 7 lines

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Quoted 8 lines
Quoted 6 lines

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype; then we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-ddc'.

Hmm?

I like that. I shall combine them into a single attribute.

I don't think this is a good approach.

There is already an interface to update sysfs groups, so in theory this should do the trick:
--

drivers/nvme/host/core.c +5 -0
index c11cd3a814fd..d86828cf7720 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                        return ret;
        }
 
+       ret = sysfs_update_groups(&ctrl->device->kobj, ctrl->device->groups);
+       if (ret)
+               return ret;
+
+
        ctrl->identified = true;
 
        return 0;

--

But probably we want add a nicer interface like
--

drivers/nvme/host/core.c +5 -0
index c11cd3a814fd..8fb94cb15fb0 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                        return ret;
        }
 
+       ret = device_update_groups(&ctrl->device);
+       if (ret)
+               return ret;
+
+
        ctrl->identified = true;
 
        return 0;

--

Where device_update_groups would be something like:
--
int device_update_groups(struct device *dev)

{
        struct class *class = dev->class;
        const struct device_type *type = dev->type;
        int error;

        if (class) {
                error = device_update_groups(dev, class->dev_groups);
                if (error)
                        return error;
        }

        if (type) {
                error = device_update_groups(dev, type->groups);
                if (error)
                        goto err_remove_class_groups;
        }

        error = device_update_groups(dev, dev->groups);
        if (error)
                goto err_remove_type_groups;
}

EXPORT_SYMBOL_GPL(device_update_groups);
--

#13 lore raw

RE: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 107 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype

depends

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

---
    drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

Quoted 4 lines
    drivers/nvme/host/nvme.h |  3 +++
    include/linux/nvme.h     | 10 +++++++++-
    3 files changed, 47 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/nvme/host/core.c static int nvme_init_identify(struct

Quoted 6 lines
drivers/nvme/host/core.c +0 -0

index
872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct

nvme_ctrl

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct · line 3000

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
    	ctrl->max_namespaces = le32_to_cpu(id->mnan);
    	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
    	if (id->rtd3e) {
    		/* us -> s */
    		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

drivers/nvme/host/core.c

Quoted 3 lines
drivers/nvme/host/core.c +2 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char

*buf) {

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/nvme/host/core.c

Quoted 5 lines
drivers/nvme/host/core.c +5 -0
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf,

"disc\n");

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

'discovery', please. 'disc' is misleading here.

drivers/nvme/host/core.c

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf,

"admin\n");

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/nvme/host/core.c

Quoted 8 lines
drivers/nvme/host/core.c +8 -0
+	default:		return sysfs_emit(buf, "reserved\n");
+	}
+}
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char

*buf) {

Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
Quoted 6 lines

drivers/nvme/host/core.c

Quoted 4 lines
drivers/nvme/host/core.c +4 -0
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

Quoted 7 lines
Quoted 1 line

Please use 'none' here; 'nr' is ambiguous ('Number'?)

Thanks for the review. I will apply the changes.

Question: Since this was part of a set of patches, do I need to resubmit the whole set or can I just resubmit this one patch?

Whole series, please. And gather up the reviews when resubmitting.

Quoted 7 lines

Also, Sagi mentioned that the dctype should only be exposed for Discovery Controllers, which makes sense. However, I found that when nvme_dev_attrs_are_visible() is invoked the ctrl object is not fully configured yet (i.e. the controller is not yet identified). Is there any other way to determine the controller type prior to receiving the response to the Identify command?

Quoted 3 lines
Quoted 3 lines

Nope, unfortunately.

But maybe we can lump both attributes together in to a single ctrltype;

then

Quoted 1 line
Quoted 1 line

we would have 'io', 'admin', 'discovery', 'discovery-cdc', and 'discovery-

ddc'.

Quoted 4 lines
Quoted 2 lines

Hmm?

I like that. I shall combine them into a single attribute.

I don't think this is a good approach.

There is already an interface to update sysfs groups, so in theory this should do the trick:
--

drivers/nvme/host/core.c +0 -0
index c11cd3a814fd..d86828cf7720 100644

drivers/nvme/host/core.c int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl) · line 3123

Quoted 9 lines
drivers/nvme/host/core.c +5 -0
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                         return ret;
         }
 
+       ret = sysfs_update_groups(&ctrl->device->kobj,
 ctrl->device->groups);
+       if (ret)
+               return ret;
+
+

I just tried this and it works.
Martin

Quoted 49 lines
drivers/nvme/host/core.c +0 -0
         ctrl->identified = true;
 
         return 0;

--

But probably we want add a nicer interface like
--

drivers/nvme/host/core.c +5 -1
index c11cd3a814fd..8fb94cb15fb0 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                         return ret;
         }
 
+       ret = device_update_groups(&ctrl->device);
+       if (ret)
+               return ret;
+
+
         ctrl->identified = true;
 
         return 0;
--

Where device_update_groups would be something like:
--
int device_update_groups(struct device *dev)

{
         struct class *class = dev->class;
         const struct device_type *type = dev->type;
         int error;

         if (class) {
                 error = device_update_groups(dev, class->dev_groups);
                 if (error)
                         return error;
         }

         if (type) {
                 error = device_update_groups(dev, type->groups);
                 if (error)
                         goto err_remove_class_groups;
         }

         error = device_update_groups(dev, dev->groups);
         if (error)
                 goto err_remove_type_groups;
}
Quoted 2 lines

EXPORT_SYMBOL_GPL(device_update_groups);
--

Sagi, would you add this function to drivers/base/core.c? Martin

Internal Use - Confidential

maintainer
#14 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 12 lines
Quoted 12 lines

There is already an interface to update sysfs groups, so in theory this should do the trick:
--

drivers/nvme/host/core.c +0 -0
index c11cd3a814fd..d86828cf7720 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                          return ret;
          }
 
Quoted 8 lines

drivers/nvme/host/core.c int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl) · line 3122

Quoted 6 lines
drivers/nvme/host/core.c +5 -0
+       ret = sysfs_update_groups(&ctrl->device->kobj,
 ctrl->device->groups);
+       if (ret)
+               return ret;
+
+

I just tried this and it works.

Makes sense.

Quoted 47 lines

Martin

Quoted 45 lines
drivers/nvme/host/core.c +0 -0
          ctrl->identified = true;
 
          return 0;

--

But probably we want add a nicer interface like
--

drivers/nvme/host/core.c +5 -1
index c11cd3a814fd..8fb94cb15fb0 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                          return ret;
          }
 
+       ret = device_update_groups(&ctrl->device);
+       if (ret)
+               return ret;
+
+
          ctrl->identified = true;
 
          return 0;
--

Where device_update_groups would be something like:
--
int device_update_groups(struct device *dev)

{
          struct class *class = dev->class;
          const struct device_type *type = dev->type;
          int error;

          if (class) {
                  error = device_update_groups(dev, class->dev_groups);
                  if (error)
                          return error;
          }

          if (type) {
                  error = device_update_groups(dev, type->groups);
                  if (error)
                          goto err_remove_class_groups;
          }
Quoted 3 lines
Quoted 3 lines
          error = device_update_groups(dev, dev->groups);
          if (error)
                  goto err_remove_type_groups;

This last hunk should probably be:

	return device_update_groups(dev, dev->groups);
Quoted 6 lines
Quoted 3 lines

}
EXPORT_SYMBOL_GPL(device_update_groups);
--

Sagi, would you add this function to drivers/base/core.c? Martin

Yes. This would need some more eyeballs though, maybe this should be extended to device_update_attrs?

#15 lore raw

RE: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 79 lines
Quoted 11 lines
Quoted 11 lines

There is already an interface to update sysfs groups, so in theory this should do the trick:
--

drivers/nvme/host/core.c +0 -0
index c11cd3a814fd..d86828cf7720 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                          return ret;
          }
 
Quoted 8 lines

drivers/nvme/host/core.c int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl) · line 3122

Quoted 6 lines
drivers/nvme/host/core.c +5 -0
+       ret = sysfs_update_groups(&ctrl->device->kobj,
 ctrl->device->groups);
+       if (ret)
+               return ret;
+
+

I just tried this and it works.

Makes sense.

Quoted 46 lines

Martin

Quoted 44 lines
drivers/nvme/host/core.c +0 -0
          ctrl->identified = true;
 
          return 0;

--

But probably we want add a nicer interface like
--

drivers/nvme/host/core.c +5 -1
index c11cd3a814fd..8fb94cb15fb0 100644
@@ -3115,6 +3115,11 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                          return ret;
          }
 
+       ret = device_update_groups(&ctrl->device);
+       if (ret)
+               return ret;
+
+
          ctrl->identified = true;
 
          return 0;
--

Where device_update_groups would be something like:
--

int device_update_groups(struct device *dev) {
          struct class *class = dev->class;
          const struct device_type *type = dev->type;
          int error;

          if (class) {
                  error = device_update_groups(dev, class->dev_groups);
                  if (error)
                          return error;
          }

          if (type) {
                  error = device_update_groups(dev, type->groups);
                  if (error)
                          goto err_remove_class_groups;
          }
Quoted 3 lines
Quoted 3 lines
          error = device_update_groups(dev, dev->groups);
          if (error)
                  goto err_remove_type_groups;

This last hunk should probably be:

	return device_update_groups(dev, dev->groups);
Quoted 4 lines
Quoted 3 lines

}
EXPORT_SYMBOL_GPL(device_update_groups);
--

Quoted 5 lines
Quoted 2 lines

Sagi, would you add this function to drivers/base/core.c? Martin

Yes. This would need some more eyeballs though, maybe this should be extended to device_update_attrs?

Is the linux-nvme repo even the right place to submit this change? This is a core kernel file and not just the nvme module.

Submitting this change will probably delay what I'm trying to release by weeks. Is it OK if I just submit the small change and leave this bigger change to someone that has more experience with the kernel?

Martin

Internal Use - Confidential

maintainer
#16 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Sagi, would you add this function to drivers/base/core.c? Martin

Yes. This would need some more eyeballs though, maybe this should be extended to device_update_attrs?

Quoted 7 lines

Is the linux-nvme repo even the right place to submit this change? This is a core kernel file and not just the nvme module.

Submitting this change will probably delay what I'm trying to release by weeks. Is it OK if I just submit the small change and leave this bigger change to someone that has more experience with the kernel?

I don't think it will take a long time we still have time for 5.18 which is where this is headed anyways.

I suggest to send a new patchset, make sure to cc Greg-kh and rafael (see MAINTAINERS file) and let's see what feedback comes.

maintainer
#17 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

In reply to Belanger, Martin
Quoted 2 lines · Martin

Internal Use - Confidential

This is not appropriate for public mailing lists. I assume it's some IT policy auto-appending it, but I'm sure there must be ways to remove it.

#18 lore raw

Re: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

In reply to Martin Belanger
Quoted 9 lines · Martin Belanger

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

above can be re aligned to 72 char per line :-

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

Quoted 25 lines
---
  drivers/nvme/host/core.c | 35 +++++++++++++++++++++++++++++++++++
  drivers/nvme/host/nvme.h |  3 +++
  include/linux/nvme.h     | 10 +++++++++-
  3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +3 -0
index 872c389dc6d3..c65d44fb65c4 100644
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
  	ctrl->max_namespaces = le32_to_cpu(id->mnan);
  	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
  	if (id->rtd3e) {
  		/* us -> s */
  		u32 transition_time = le32_to_cpu(id->rtd3e) / USEC_PER_SEC;
@@ -3525,6 +3528,34 @@ static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
  static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
  	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
 

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3540

Quoted 10 lines
drivers/nvme/host/core.c +10 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");

please keep the return on new line ...

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3542

Quoted 2 lines
drivers/nvme/host/core.c +2 -0
+	}
+}

with newline added to the switch for each new case we will be adding new case statement and a sysfs_emit() call, following style avoids current and future repetations of case ... sysfs_emit() calls and brings down to only two calls including any future ctrl type value (2 lines for each new value pf ctrltype vs 1 line in the array of string :-

static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
struct device_attribute *attr,
char *buf)

{
         const char *type[] = {
             [NVME_CTRL_IO], "io\n",
             [NVME_CTRL_DISC], "disc\n",
             [NVME_CTRL_ADMIN], "admin\n",
         };

         if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->ctrltype])
             return sysfs_emit(buf, "reserved\n");

         return sysfs_emit(buf, type[ctrl->ctrltype]);
}
Quoted 4 lines
drivers/nvme/host/core.c +4 -0
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show, NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3556

Quoted 10 lines
drivers/nvme/host/core.c +10 -0
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf, "nr\n");
+	case NVME_DCTYPE_DDC:		return sysfs_emit(buf, "ddc\n");
+	case NVME_DCTYPE_CDC:		return sysfs_emit(buf, "cdc\n");
+	default:			return sysfs_emit(buf, "reserved\n");
+	}
+}

same comment as above to use array of string unless there is any reason we should repeat the sysfs_emit() calls.

Quoted 42 lines
drivers/nvme/host/core.c +6 -0
+static DEVICE_ATTR(dctype, S_IRUGO, nvme_ctrl_dctype_show, NULL);
+
  static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reset_controller.attr,
  	&dev_attr_rescan_controller.attr,
@@ -3546,6 +3577,8 @@ static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reconnect_delay.attr,
  	&dev_attr_fast_io_fail_tmo.attr,
  	&dev_attr_kato.attr,
+	&dev_attr_cntrltype.attr,
+	&dev_attr_dctype.attr,
  	NULL
  };
 
@@ -3569,6 +3602,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
  		return 0;
  	if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts)
  		return 0;
+	if (a == &dev_attr_dctype.attr && ctrl->cntrltype == NVME_CTRL_DISC)
+		return 0;
 
  	return a->mode;
  }
drivers/nvme/host/nvme.h +3 -0
index a162f6c6da6e..e30626c00791 100644
@@ -349,6 +349,9 @@ struct nvme_ctrl {
  	unsigned long discard_page_busy;
 
  	struct nvme_fault_inject fault_inject;
+
+	enum nvme_ctrl_type cntrltype;
+	enum nvme_dctype dctype;
  };
 
  enum nvme_iopolicy {
include/linux/nvme.h +0 -0
index 855dd9b3e84b..af1494d83a52 100644

include/linux/nvme.h enum name_ctrl_type { · line 51

Quoted 9 lines
include/linux/nvme.h +6 -0
@@ -43,6 +43,12 @@ enum name_ctrl_type {
  	NVME_CTRL_ADMIN	= 3,		/* Administrative controller */
  };
 
+enum nvme_dctype {
+	NVME_DCTYPE_NOT_REPORTED = 0,
+	NVME_DCTYPE_DDC = 1,		/* Direct Discovery Controller */
+	NVME_DCTYPE_CDC = 2,		/* Central Discovery Controller */
+};
+

consider follwing with aligned initial values that also matches what we have in the include/linux/nvme.h for enums initialization :- enum nvme_dctype {
NVME_DCTYPE_NOT_REPORTED = 0,
NVME_DCTYPE_DDC = 1, /* Direct Discovery
Controller */
NVME_DCTYPE_CDC = 2, /* Central Discovery
Controller */
};

Quoted 15 lines
include/linux/nvme.h +3 -1
  /* Address Family codes for Discovery Log Page entry ADRFAM field */
  enum {
  	NVMF_ADDR_FAMILY_PCI	= 0,	/* PCIe */
@@ -320,7 +326,9 @@ struct nvme_id_ctrl {
  	__le16			icdoff;
  	__u8			ctrattr;
  	__u8			msdbd;
-	__u8			rsvd1804[244];
+	__u8			rsvd1804[2];
+	__u8			dctype;
+	__u8			rsvd1807[241];
  	struct nvme_id_power_state	psd[32];
  	__u8			vs[1024];
  };
#19 lore raw

RE: [PATCH 2/2] nvme: Expose cntrltype and dctype through sysfs.

Quoted 49 lines · Martin Belanger
Quoted 8 lines

From: Martin Belanger <[email protected]>

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

above can be re aligned to 72 char per line :-

TP8010 introduces the Discovery Controller Type (dctype) attribute. The dctype is returned in the response to the Identify command. This patch exposes the dctype through the sysfs. Since the dctype depends on the Controller Type (cntrltype), another attribute of the Identify response, the patch also exposes the cntrltype as well.

Quoted 3 lines
---
  drivers/nvme/host/core.c | 35

+++++++++++++++++++++++++++++++++++

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl

Quoted 9 lines
  drivers/nvme/host/nvme.h |  3 +++
  include/linux/nvme.h     | 10 +++++++++-
  3 files changed, 47 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c index renamed from drivers/nvme/host/core.c +0 -0

872c389dc6d3..c65d44fb65c4 100644

drivers/nvme/host/core.c +0 -0
@@ -2992,6 +2992,9 @@ static int nvme_init_identify(struct nvme_ctrl

*ctrl)

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl)

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
  	ctrl->max_namespaces = le32_to_cpu(id->mnan);
  	ctrl->ctratt = le32_to_cpu(id->ctratt);
 
+	ctrl->cntrltype = id->cntrltype;
+	ctrl->dctype = id->dctype;
+
  	if (id->rtd3e) {
  		/* us -> s */
  		u32 transition_time = le32_to_cpu(id->rtd3e) /

USEC_PER_SEC; @@

Quoted 1 line

-3525,6 +3528,34 @@ static ssize_t

nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 2 lines

static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
nvme_ctrl_fast_io_fail_tmo_show,

nvme_ctrl_fast_io_fail_tmo_store);

Quoted 1 line
Quoted 11 lines

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3540

Quoted 9 lines
drivers/nvme/host/core.c +9 -0
+static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->cntrltype) {
+	case NVME_CTRL_IO:	return sysfs_emit(buf, "io\n");
+	case NVME_CTRL_DISC:	return sysfs_emit(buf, "disc\n");
+	case NVME_CTRL_ADMIN:	return sysfs_emit(buf, "admin\n");
+	default:		return sysfs_emit(buf, "reserved\n");

please keep the return on new line ...

Hi Chaitanya,
Ok, I will keep the return on a separate line. BTW, is that specific to the NVMe driver. I see that in many places in the kernel they put the return on the same line as the case statement, as shown here:

$ git grep -E "case .*: *return" | wc -l
1676
Quoted 113 lines

drivers/nvme/host/core.c

Quoted 3 lines
drivers/nvme/host/core.c +2 -0
+	}
+}

with newline added to the switch for each new case we will be adding new case statement and a sysfs_emit() call, following style avoids current and future repetations of case ... sysfs_emit() calls and brings down to only two calls including any future ctrl type value (2 lines for each new value pf ctrltype vs 1 line in the array of string :-

static ssize_t nvme_ctrl_cntrltype_show(struct device *dev,

                                      struct device_attribute *attr, char *buf) {
         const char *type[] = {
             [NVME_CTRL_IO], "io\n",
             [NVME_CTRL_DISC], "disc\n",
             [NVME_CTRL_ADMIN], "admin\n",
         };

         if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->ctrltype])
             return sysfs_emit(buf, "reserved\n");

         return sysfs_emit(buf, type[ctrl->ctrltype]); }

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,

Quoted 9 lines
drivers/nvme/host/core.c +9 -0
+static DEVICE_ATTR(cntrltype, S_IRUGO, nvme_ctrl_cntrltype_show,
+NULL);
+
+static ssize_t nvme_ctrl_dctype_show(struct device *dev,
+				     struct device_attribute *attr, char *buf) {
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	switch (ctrl->dctype) {
+	case NVME_DCTYPE_NOT_REPORTED:	return sysfs_emit(buf,

"nr\n");

drivers/nvme/host/core.c

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	case NVME_DCTYPE_DDC:		return sysfs_emit(buf,

"ddc\n");

drivers/nvme/host/core.c

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	case NVME_DCTYPE_CDC:		return sysfs_emit(buf,

"cdc\n");

drivers/nvme/host/core.c static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, · line 3542

Quoted 3 lines
drivers/nvme/host/core.c +3 -0
+	default:			return sysfs_emit(buf, "reserved\n");
+	}
+}

same comment as above to use array of string unless there is any reason we should repeat the sysfs_emit() calls.

drivers/nvme/host/core.c static umode_t

Quoted 15 lines
drivers/nvme/host/core.c +4 -0
+static DEVICE_ATTR(dctype, S_IRUGO, nvme_ctrl_dctype_show, NULL);
+
  static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reset_controller.attr,
  	&dev_attr_rescan_controller.attr,
@@ -3546,6 +3577,8 @@ static struct attribute *nvme_dev_attrs[] = {
  	&dev_attr_reconnect_delay.attr,
  	&dev_attr_fast_io_fail_tmo.attr,
  	&dev_attr_kato.attr,
+	&dev_attr_cntrltype.attr,
+	&dev_attr_dctype.attr,
  	NULL
  };
 
@@ -3569,6 +3602,8 @@ static umode_t

nvme_dev_attrs_are_visible(struct kobject *kobj,

drivers/nvme/host/core.c static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,

Quoted 4 lines
drivers/nvme/host/core.c +1 -0
  		return 0;
  	if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts)
  		return 0;
+	if (a == &dev_attr_dctype.attr && ctrl->cntrltype ==

NVME_CTRL_DISC)

Quoted 23 lines
drivers/nvme/host/core.c +1 -0
+		return 0;
 
  	return a->mode;
  }
drivers/nvme/host/nvme.h index renamed from drivers/nvme/host/nvme.h +0 -0

a162f6c6da6e..e30626c00791 100644

drivers/nvme/host/nvme.h +3 -0
@@ -349,6 +349,9 @@ struct nvme_ctrl {
  	unsigned long discard_page_busy;
 
  	struct nvme_fault_inject fault_inject;
+
+	enum nvme_ctrl_type cntrltype;
+	enum nvme_dctype dctype;
  };
 
  enum nvme_iopolicy {
include/linux/nvme.h index renamed from include/linux/nvme.h +0 -0

855dd9b3e84b..af1494d83a52 100644

include/linux/nvme.h enum name_ctrl_type { · line 43

Quoted 1 line
include/linux/nvme.h +0 -0
@@ -43,6 +43,12 @@ enum name_ctrl_type {
  	NVME_CTRL_ADMIN	= 3,		/* Administrative controller

*/

include/linux/nvme.h enum nvme_ctrl_type {

Quoted 5 lines
include/linux/nvme.h +3 -0
  };
 
+enum nvme_dctype {
+	NVME_DCTYPE_NOT_REPORTED = 0,
+	NVME_DCTYPE_DDC = 1,		/* Direct Discovery Controller

*/

include/linux/nvme.h enum name_ctrl_type { · line 49

Quoted 1 line
include/linux/nvme.h +1 -0
+	NVME_DCTYPE_CDC = 2,		/* Central Discovery

Controller */

include/linux/nvme.h enum nvme_ctrl_type { · line 51

Quoted 2 lines
include/linux/nvme.h +2 -0
+};
+

consider follwing with aligned initial values that also matches what we have in the include/linux/nvme.h for enums initialization :- enum nvme_dctype {
NVME_DCTYPE_NOT_REPORTED = 0,
NVME_DCTYPE_DDC = 1, /* Direct Discovery
Controller */
NVME_DCTYPE_CDC = 2, /* Central Discovery
Controller */
};

Quoted 15 lines
Quoted 5 lines
include/linux/nvme.h +0 -0
  /* Address Family codes for Discovery Log Page entry ADRFAM field */
  enum {
  	NVMF_ADDR_FAMILY_PCI	= 0,	/* PCIe */

include/linux/nvme.h struct nvme_id_ctrl { · line 334

Quoted 10 lines
include/linux/nvme.h +3 -1
@@ -320,7 +326,9 @@ struct nvme_id_ctrl {
  	__le16			icdoff;
  	__u8			ctrattr;
  	__u8			msdbd;
-	__u8			rsvd1804[244];
+	__u8			rsvd1804[2];
+	__u8			dctype;
+	__u8			rsvd1807[241];
  	struct nvme_id_power_state	psd[32];
  	__u8			vs[1024];
  };

Internal Use - Confidential