linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: <tsutomu.owa@kioxia.com>
To: <linux-nvme@lists.infradead.org>, <sagi@grimberg.me>,
	<kbusch@kernel.org>,  <hch@infradead.org>
Cc: tsutomu.owa@kioxia.com
Subject: [RFC PATCH 5/5] nvme: to add support for nvme queue level reset
Date: Wed, 11 Dec 2019 02:34:56 +0000	[thread overview]
Message-ID: <ea9caff8d3b242c3b2bd7f10e3f063a3@tgxml778.toshiba.local> (raw)

This patch adds support for queue level reset function described in NVMe
spec 1.3c "7.3.3 Queue Level".

Signed-off-by: Tsutomu OWA <tsutomu.owa@kioxia.com>
---
 drivers/nvme/host/core.c        | 39 +++++++++++++++++++--
 drivers/nvme/host/nvme.h        |  5 +++
 drivers/nvme/host/pci.c         | 62 +++++++++++++++++++++++++++++++++
 include/uapi/linux/nvme_ioctl.h |  8 +++++
 4 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 65e3ef820..b4bd90ef6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -94,13 +94,44 @@ static void nvme_put_subsystem(struct nvme_subsystem *subsys);
 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
 					   unsigned nsid);
 
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+static int queue_level_reset(struct nvme_ctrl *ctrl, unsigned int cmd)
+{
+	dev_info(ctrl->device, "reset %s\n", get_nvme_ioctl_name(cmd));
+
+	/* sanity check */
+	if (!ctrl->ops || !ctrl->ops->disable_io_queues ||
+	    !ctrl->ops->suspend_io_queues || !ctrl->ops->create_io_queues)
+		return -ENOTTY;
+
+	mutex_lock(&ctrl->scan_lock);
+	nvme_start_freeze(ctrl);
+	nvme_wait_freeze(ctrl);
+
+	/* delete sq/cq */
+	ctrl->ops->disable_io_queues(ctrl);
+
+	/* free irq. */
+	ctrl->ops->suspend_io_queues(ctrl);
+
+	/* alloc sq/cq, enable irq */
+	ctrl->ops->create_io_queues(ctrl);
+
+	nvme_unfreeze(ctrl);
+	mutex_unlock(&ctrl->scan_lock);
+
+	return 0;
+}
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
+
 #ifdef CONFIG_NVME_PCI_RESET
 static int nvme_conventional_hot_reset(struct pci_dev *bridge)
 {
 	return pci_bridge_secondary_bus_reset(bridge);
 }
 
-#define PCIE_RESET_READY_POLL_MS	60000
+/* value 60000 taken from drivers/pci/pci.c. */
+#define NVME_PCIE_RESET_READY_LNK_MS	60000
 static int nvme_link_down_reset(struct pci_dev *pdev, struct pci_dev *bridge)
 {
 	/* link down */
@@ -111,7 +142,7 @@ static int nvme_link_down_reset(struct pci_dev *pdev, struct pci_dev *bridge)
 	/* link up */
 	pcie_capability_clear_word(bridge, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_LD);
 
-	return pci_dev_wait(pdev, "LNK", PCIE_RESET_READY_POLL_MS);
+	return pci_dev_wait(pdev, "LNK", NVME_PCIE_RESET_READY_LNK_MS);
 }
 
 static int __pci_reset_dev_locked(struct nvme_ctrl *ctrl,
@@ -3101,6 +3132,10 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd,
 	case NVME_IOCTL_FUNCTION_LEVEL_RESET:
 		return nvme_pci_reset_common(ctrl, cmd);
 #endif /* CONFIG_NVME_PCI_RESET */
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+	case NVME_IOCTL_QUEUE_LEVEL_RESET:
+		return queue_level_reset(ctrl, cmd);
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
 	default:
 		return -ENOTTY;
 	}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 0b5f59b50..c342a4c5c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -405,6 +405,11 @@ struct nvme_ctrl_ops {
 #ifdef CONFIG_NVME_PCI_RESET
 	struct pci_dev *(*pci_dev)(struct nvme_ctrl *ctrl);
 #endif /* CONFIG_NVME_PCI_RESET */
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+	int (*create_io_queues)(struct nvme_ctrl *ctrl);
+	void (*suspend_io_queues)(struct nvme_ctrl *ctrl);
+	void (*disable_io_queues)(struct nvme_ctrl *ctrl);
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
 };
 
 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 5a78165ec..6b199b082 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1399,6 +1399,15 @@ static void nvme_suspend_io_queues(struct nvme_dev *dev)
 		nvme_suspend_queue(&dev->queues[i]);
 }
 
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+static void nvme_pci_suspend_io_queues(struct nvme_ctrl *ctrl)
+{
+	struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+	nvme_suspend_io_queues(dev);
+}
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
+
 static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
 {
 	struct nvme_queue *nvmeq = &dev->queues[0];
@@ -1751,6 +1760,45 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
 	return ret >= 0 ? 0 : ret;
 }
 
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+/*
+ * code taken from nvme_create_io_queues()
+ * it could be better to cleanup nvme_create_io_queues() and
+ * nvme_pci_create_io_queues() to use common code if this
+ * queue level reset implementation is basically accepted.
+ *
+ */
+static int nvme_pci_create_io_queues(struct nvme_ctrl *ctrl)
+{
+	int i, max, rw_queues;
+	int ret = 0;
+	struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+	max = min(dev->max_qid, dev->ctrl.queue_count - 1);
+	if (max != 1 && dev->io_queues[HCTX_TYPE_POLL]) {
+		rw_queues = dev->io_queues[HCTX_TYPE_DEFAULT] +
+				dev->io_queues[HCTX_TYPE_READ];
+	} else {
+		rw_queues = max;
+	}
+
+	for (i = dev->online_queues; i <= max; i++) {
+		bool polled = i > rw_queues;
+
+
+		ret = nvme_create_queue(&dev->queues[i], i, polled);
+		if (ret)
+			break;
+	}
+
+	if (ret)
+		dev_warn(ctrl->device,
+			"%s: err (i=%d, ret=%d)\n", __func__, i, ret);
+
+	return ret >= 0 ? 0 : ret;
+}
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
+
 static ssize_t nvme_cmb_show(struct device *dev,
 			     struct device_attribute *attr,
 			     char *buf)
@@ -2097,6 +2145,15 @@ static void nvme_disable_io_queues(struct nvme_dev *dev)
 		__nvme_disable_io_queues(dev, nvme_admin_delete_cq);
 }
 
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+static void nvme_pci_disable_io_queues(struct nvme_ctrl *ctrl)
+{
+	struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+	nvme_disable_io_queues(dev);
+}
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
+
 static int nvme_setup_io_queues(struct nvme_dev *dev)
 {
 	struct nvme_queue *adminq = &dev->queues[0];
@@ -2716,6 +2773,11 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
 #ifdef CONFIG_NVME_PCI_RESET
 	.pci_dev		= nvme_pci_to_pci_dev,
 #endif /* CONFIG_NVME_PCI_RESET */
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+	.create_io_queues	= nvme_pci_create_io_queues,
+	.suspend_io_queues	= nvme_pci_suspend_io_queues,
+	.disable_io_queues	= nvme_pci_disable_io_queues,
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
 };
 
 static int nvme_dev_map(struct nvme_dev *dev)
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index 36a77ff75..9f102397e 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -85,6 +85,10 @@ struct nvme_passthru_cmd64 {
 #define NVME_IOCTL_FUNCTION_LEVEL_RESET		_IO('N', 0x4b)
 #endif /* CONFIG_NVME_PCI_RESET */
 
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+#define NVME_IOCTL_QUEUE_LEVEL_RESET		_IO('N', 0x4c)
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
+
 static inline char *get_nvme_ioctl_name(unsigned int cmd)
 {
 	switch (cmd) {
@@ -114,6 +118,10 @@ static inline char *get_nvme_ioctl_name(unsigned int cmd)
 	case NVME_IOCTL_FUNCTION_LEVEL_RESET:
 		return "function level reset";
 #endif /* CONFIG_NVME_PCI_RESET */
+#ifdef CONFIG_NVME_QUEUE_LEVEL_RESET
+	case NVME_IOCTL_QUEUE_LEVEL_RESET:
+		return "queue level reset";
+#endif /* CONFIG_NVME_QUEUE_LEVEL_RESET */
 	default:
 		return "Unknown";
 	}
-- 
2.17.1


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

                 reply	other threads:[~2019-12-11  2:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ea9caff8d3b242c3b2bd7f10e3f063a3@tgxml778.toshiba.local \
    --to=tsutomu.owa@kioxia.com \
    --cc=hch@infradead.org \
    --cc=kbusch@kernel.org \
    --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).