Skip to contentSkip to conversation

NVMe: Added IOCTL to initiate subsystem resets

PATCH Superseded Jon Derrick 2 participants 2 messages May 29, 2015 – Jun 4, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NVMe: Added IOCTL to initiate subsystem resets

Controllers can perform optional subsystem resets as introduced in NVMe 1.1. This patch adds an IOCTL to trigger the subsystem reset by writing "NVMe" to the NSSR register.

Signed-off-by Jon Derrick <jonathan.derrick at intel.com>

---
This patch is contigent on the subsystem reset detection patch:
http://lists.infradead.org/pipermail/linux-nvme/2015-May/001779.html

 drivers/block/nvme-core.c | 11 +++++++++++
 include/linux/nvme.h      |  2 +-
 include/uapi/linux/nvme.h |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/block/nvme-core.c +11 -0
index 0cf18c2..039e1ea 100644
@@ -1846,6 +1846,15 @@ static int nvme_user_cmd(struct nvme_dev *dev, struct nvme_ns *ns,
 	return status;
 }
 
+static int nvme_subsys_reset(struct nvme_dev *dev)
+{
+	if (!dev->subsystem)
+		return -ENOTTY;
+
+	writel(0x4E564D65, &dev->bar->nssr); /* "NVMe" */
+	return 0;
+}
+
 static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 							unsigned long arg)
 {
@@ -1861,6 +1870,8 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 		return nvme_user_cmd(ns->dev, ns, (void __user *)arg);
 	case NVME_IOCTL_SUBMIT_IO:
 		return nvme_submit_io(ns, (void __user *)arg);
+	case NVME_IOCTL_SUBSYS_RESET:
+		return nvme_subsys_reset(ns->dev);
 	case SG_GET_VERSION_NUM:
 		return nvme_sg_get_version_num((void __user *)arg);
 	case SG_IO:
include/linux/nvme.h +1 -1
index 977b0b3..35f0ece 100644
@@ -28,7 +28,7 @@ struct nvme_bar {
 	__u32			cc;	/* Controller Configuration */
 	__u32			rsvd1;	/* Reserved */
 	__u32			csts;	/* Controller Status */
-	__u32			rsvd2;	/* Reserved */
+	__u32			nssr;	/* Subsystem Reset */
 	__u32			aqa;	/* Admin Queue Attributes */
 	__u64			asq;	/* Admin SQ Base Address */
 	__u64			acq;	/* Admin CQ Base Address */
include/uapi/linux/nvme.h +1 -0
index aef9a81..7d2907d 100644
@@ -579,5 +579,6 @@ struct nvme_passthru_cmd {
 #define NVME_IOCTL_ADMIN_CMD	_IOWR('N', 0x41, struct nvme_admin_cmd)
 #define NVME_IOCTL_SUBMIT_IO	_IOW('N', 0x42, struct nvme_user_io)
 #define NVME_IOCTL_IO_CMD	_IOWR('N', 0x43, struct nvme_passthru_cmd)
+#define NVME_IOCTL_SUBSYS_RESET	_IO('N', 0x44)
 
 #endif /* _UAPI_LINUX_NVME_H */
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 NVMe: Added IOCTL to initiate subsystem resets

Quoted 3 lines · Jon Derrick

Controllers can perform optional subsystem resets as introduced in NVMe 1.1. This patch adds an IOCTL to trigger the subsystem reset by writing "NVMe" to the NSSR register.

Hi Jon,

Looks good except for one issue below, and then need to merge-up for another conflict.

drivers/block/nvme-core.c static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, · line 1874

Quoted 8 lines
Signed-off-by Jon Derrick <jonathan.derrick at intel.com>

---

drivers/block/nvme-core.c +2 -0
@@ -1861,6 +1870,8 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 		return nvme_user_cmd(ns->dev, ns, (void __user *)arg);
 	case NVME_IOCTL_SUBMIT_IO:
 		return nvme_submit_io(ns, (void __user *)arg);
+	case NVME_IOCTL_SUBSYS_RESET:
+		return nvme_subsys_reset(ns->dev);

This IOCTL belongs only in the "nvme_dev_ioctl" version; we don't want this capability exposed through namespaces.

drivers/block/nvme-core.c struct nvme_passthru_cmd { · line 582

Quoted 9 lines
drivers/block/nvme-core.c +1 -0
 	case SG_GET_VERSION_NUM:
 		return nvme_sg_get_version_num((void __user *)arg);
 	case SG_IO:
@@ -579,5 +579,6 @@ struct nvme_passthru_cmd {
 #define NVME_IOCTL_ADMIN_CMD	_IOWR('N', 0x41, struct nvme_admin_cmd)
 #define NVME_IOCTL_SUBMIT_IO	_IOW('N', 0x42, struct nvme_user_io)
 #define NVME_IOCTL_IO_CMD	_IOWR('N', 0x43, struct nvme_passthru_cmd)
+#define NVME_IOCTL_SUBSYS_RESET	_IO('N', 0x44)

Will need to change the ioctl number once the single-controller reset is applied. That patch was in line first, anyway.