]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
nvme: expose cntrltype and dctype through sysfs
authorMartin Belanger <martin.belanger@dell.com>
Tue, 21 Jun 2022 21:53:00 +0000 (23:53 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 12 Jul 2022 08:34:43 +0000 (10:34 +0200)
TP8010 introduces the Discovery Controller Type attribute (dctype).
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. The dctype will
only be displayed for discovery controllers.

A note about the naming of this attribute:
Although TP8010 calls this attribute the Discovery Controller Type,
note that the dctype is now part of the response to the Identify
command for all controller types. I/O, Discovery, and Admin controllers
all share the same Identify response PDU structure. Non-discovery
controllers as well as pre-TP8010 discovery controllers will continue
to set this field to 0 (which has always been the default for reserved
bytes). Per TP8010, the value 0 now means "Discovery controller type is
not reported" instead of "Reserved". One could argue that this
definition is correct even for non-discovery controllers, and by
extension, exposing it in the sysfs for non-discovery controllers is
appropriate.

BugLink: https://bugs.launchpad.net/bugs/1948626
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: John Meneghini <jmeneghi@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
(cherry picked from commit 86c2457a8e8112f16af8fd10a3e1dd7a302c3c3e)
Signed-off-by: Michael Reed <Michael.Reed@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
include/linux/nvme.h

index 3b7591d8ae5875b7e6ce3fa947ca4fe248df3d71..293ec5c01f080651641b1582598f29e1377392f7 100644 (file)
@@ -2933,6 +2933,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;
@@ -3466,6 +3469,40 @@ 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 cntrltype_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       static const char * const type[] = {
+               [NVME_CTRL_IO] = "io\n",
+               [NVME_CTRL_DISC] = "discovery\n",
+               [NVME_CTRL_ADMIN] = "admin\n",
+       };
+       struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+       if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype])
+               return sysfs_emit(buf, "reserved\n");
+
+       return sysfs_emit(buf, type[ctrl->cntrltype]);
+}
+static DEVICE_ATTR_RO(cntrltype);
+
+static ssize_t dctype_show(struct device *dev,
+                          struct device_attribute *attr, char *buf)
+{
+       static const char * const type[] = {
+               [NVME_DCTYPE_NOT_REPORTED] = "none\n",
+               [NVME_DCTYPE_DDC] = "ddc\n",
+               [NVME_DCTYPE_CDC] = "cdc\n",
+       };
+       struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+       if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype])
+               return sysfs_emit(buf, "reserved\n");
+
+       return sysfs_emit(buf, type[ctrl->dctype]);
+}
+static DEVICE_ATTR_RO(dctype);
+
 static struct attribute *nvme_dev_attrs[] = {
        &dev_attr_reset_controller.attr,
        &dev_attr_rescan_controller.attr,
@@ -3487,6 +3524,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
 };
 
index f1e5c7564cae6d3646c4ffc95b183b50564bd317..446fe29d2392a67fdc06da24f17633fd690f10c4 100644 (file)
@@ -353,6 +353,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 {
index 921c4ba0c4bc028c81b70ed98e72346c89abe631..4573e8a742e1328af1467241d2839bb7b092a031 100644 (file)
@@ -37,6 +37,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 */
@@ -314,7 +320,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];
 };