[PATCH 1/1] nvme: Export CSTS register via sysfs

Alan Adamson alan.adamson at oracle.com
Wed Mar 17 20:46:15 GMT 2021


This exposes a sysfs method a user can invoke to request read-only
access to a NVMe Controller's CSTS (Controller Status) Register.

Signed-off-by: Alan Adamson <alan.adamson at oracle.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani at oracle.com>
---
 drivers/nvme/host/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e68a8c4ac5a6..7736b8b0891c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3683,9 +3683,24 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev,
 	ctrl->opts->reconnect_delay = v;
 	return count;
 }
+
+static ssize_t nvme_ctrl_csts_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	u32 csts;
+
+	ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts);
+
+	return sprintf(buf, "%d\n", csts);
+}
+
 static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
 	nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store);
 
+static DEVICE_ATTR(csts, S_IRUGO | S_IWUSR,
+	nvme_ctrl_csts_show, NULL);
+
 static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_reset_controller.attr,
 	&dev_attr_rescan_controller.attr,
@@ -3705,6 +3720,7 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_hostid.attr,
 	&dev_attr_ctrl_loss_tmo.attr,
 	&dev_attr_reconnect_delay.attr,
+	&dev_attr_csts.attr,
 	NULL
 };
 
-- 
2.18.4




More information about the Linux-nvme mailing list