Commit bd06d14f authored by Keith Busch's avatar Keith Busch Committed by Tim Gardner

NVMe: Shutdown controller only for power-off

BugLink: http://bugs.launchpad.net/bugs/1531539

We don't need to shutdown a controller for a reset. A controller in a
shutdown state may take longer to become ready than one that was simply
disabled. This patch has the driver shut down a controller only if the
device is about to be powered off or being removed. When taking the
controller down for a reset reason, the controller will be disabled
instead.

Function names have been updated in this patch to reflect their changed
semantics.
Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
Reviewed-by: default avatarSagi Grimberg <sagig@mellanox.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
(cherry picked from commit a5cdb68c)
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>
parent 49b6964f
...@@ -87,7 +87,7 @@ struct nvme_queue; ...@@ -87,7 +87,7 @@ struct nvme_queue;
static int nvme_reset(struct nvme_dev *dev); static int nvme_reset(struct nvme_dev *dev);
static void nvme_process_cq(struct nvme_queue *nvmeq); static void nvme_process_cq(struct nvme_queue *nvmeq);
static void nvme_remove_dead_ctrl(struct nvme_dev *dev); static void nvme_remove_dead_ctrl(struct nvme_dev *dev);
static void nvme_dev_shutdown(struct nvme_dev *dev); static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown);
/* /*
* Represents an NVM Express device. Each nvme_dev is a PCI function. * Represents an NVM Express device. Each nvme_dev is a PCI function.
...@@ -932,7 +932,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) ...@@ -932,7 +932,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
dev_warn(dev->dev, dev_warn(dev->dev,
"I/O %d QID %d timeout, disable controller\n", "I/O %d QID %d timeout, disable controller\n",
req->tag, nvmeq->qid); req->tag, nvmeq->qid);
nvme_dev_shutdown(dev); nvme_dev_disable(dev, false);
req->errors = NVME_SC_CANCELLED; req->errors = NVME_SC_CANCELLED;
return BLK_EH_HANDLED; return BLK_EH_HANDLED;
} }
...@@ -946,7 +946,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) ...@@ -946,7 +946,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
dev_warn(dev->dev, dev_warn(dev->dev,
"I/O %d QID %d timeout, reset controller\n", "I/O %d QID %d timeout, reset controller\n",
req->tag, nvmeq->qid); req->tag, nvmeq->qid);
nvme_dev_shutdown(dev); nvme_dev_disable(dev, false);
queue_work(nvme_workq, &dev->reset_work); queue_work(nvme_workq, &dev->reset_work);
/* /*
...@@ -1065,21 +1065,20 @@ static void nvme_clear_queue(struct nvme_queue *nvmeq) ...@@ -1065,21 +1065,20 @@ static void nvme_clear_queue(struct nvme_queue *nvmeq)
spin_unlock_irq(&nvmeq->q_lock); spin_unlock_irq(&nvmeq->q_lock);
} }
static void nvme_disable_queue(struct nvme_dev *dev, int qid) static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
{ {
struct nvme_queue *nvmeq = dev->queues[qid]; struct nvme_queue *nvmeq = dev->queues[0];
if (!nvmeq) if (!nvmeq)
return; return;
if (nvme_suspend_queue(nvmeq)) if (nvme_suspend_queue(nvmeq))
return; return;
/* Don't tell the adapter to delete the admin queue. if (shutdown)
* Don't tell a removed adapter to delete IO queues. */ nvme_shutdown_ctrl(&dev->ctrl);
if (qid && readl(dev->bar + NVME_REG_CSTS) != -1) { else
adapter_delete_sq(dev, qid); nvme_disable_ctrl(&dev->ctrl, lo_hi_readq(
adapter_delete_cq(dev, qid); dev->bar + NVME_REG_CAP));
}
spin_lock_irq(&nvmeq->q_lock); spin_lock_irq(&nvmeq->q_lock);
nvme_process_cq(nvmeq); nvme_process_cq(nvmeq);
...@@ -1830,7 +1829,7 @@ static void nvme_dev_list_remove(struct nvme_dev *dev) ...@@ -1830,7 +1829,7 @@ static void nvme_dev_list_remove(struct nvme_dev *dev)
kthread_stop(tmp); kthread_stop(tmp);
} }
static void nvme_dev_shutdown(struct nvme_dev *dev) static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
{ {
int i; int i;
u32 csts = -1; u32 csts = -1;
...@@ -1849,8 +1848,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) ...@@ -1849,8 +1848,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
} }
} else { } else {
nvme_disable_io_queues(dev); nvme_disable_io_queues(dev);
nvme_shutdown_ctrl(&dev->ctrl); nvme_disable_admin_queue(dev, shutdown);
nvme_disable_queue(dev, 0);
} }
nvme_dev_unmap(dev); nvme_dev_unmap(dev);
...@@ -1909,7 +1907,7 @@ static void nvme_reset_work(struct work_struct *work) ...@@ -1909,7 +1907,7 @@ static void nvme_reset_work(struct work_struct *work)
* moving on. * moving on.
*/ */
if (dev->bar) if (dev->bar)
nvme_dev_shutdown(dev); nvme_dev_disable(dev, false);
set_bit(NVME_CTRL_RESETTING, &dev->flags); set_bit(NVME_CTRL_RESETTING, &dev->flags);
...@@ -1963,7 +1961,7 @@ static void nvme_reset_work(struct work_struct *work) ...@@ -1963,7 +1961,7 @@ static void nvme_reset_work(struct work_struct *work)
dev->ctrl.admin_q = NULL; dev->ctrl.admin_q = NULL;
dev->queues[0]->tags = NULL; dev->queues[0]->tags = NULL;
disable: disable:
nvme_disable_queue(dev, 0); nvme_disable_admin_queue(dev, false);
unmap: unmap:
nvme_dev_unmap(dev); nvme_dev_unmap(dev);
out: out:
...@@ -2098,7 +2096,7 @@ static void nvme_reset_notify(struct pci_dev *pdev, bool prepare) ...@@ -2098,7 +2096,7 @@ static void nvme_reset_notify(struct pci_dev *pdev, bool prepare)
struct nvme_dev *dev = pci_get_drvdata(pdev); struct nvme_dev *dev = pci_get_drvdata(pdev);
if (prepare) if (prepare)
nvme_dev_shutdown(dev); nvme_dev_disable(dev, false);
else else
queue_work(nvme_workq, &dev->reset_work); queue_work(nvme_workq, &dev->reset_work);
} }
...@@ -2106,7 +2104,7 @@ static void nvme_reset_notify(struct pci_dev *pdev, bool prepare) ...@@ -2106,7 +2104,7 @@ static void nvme_reset_notify(struct pci_dev *pdev, bool prepare)
static void nvme_shutdown(struct pci_dev *pdev) static void nvme_shutdown(struct pci_dev *pdev)
{ {
struct nvme_dev *dev = pci_get_drvdata(pdev); struct nvme_dev *dev = pci_get_drvdata(pdev);
nvme_dev_shutdown(dev); nvme_dev_disable(dev, true);
} }
static void nvme_remove(struct pci_dev *pdev) static void nvme_remove(struct pci_dev *pdev)
...@@ -2122,7 +2120,7 @@ static void nvme_remove(struct pci_dev *pdev) ...@@ -2122,7 +2120,7 @@ static void nvme_remove(struct pci_dev *pdev)
flush_work(&dev->scan_work); flush_work(&dev->scan_work);
nvme_remove_namespaces(&dev->ctrl); nvme_remove_namespaces(&dev->ctrl);
nvme_uninit_ctrl(&dev->ctrl); nvme_uninit_ctrl(&dev->ctrl);
nvme_dev_shutdown(dev); nvme_dev_disable(dev, true);
nvme_dev_remove_admin(dev); nvme_dev_remove_admin(dev);
nvme_free_queues(dev, 0); nvme_free_queues(dev, 0);
nvme_release_cmb(dev); nvme_release_cmb(dev);
...@@ -2136,7 +2134,7 @@ static int nvme_suspend(struct device *dev) ...@@ -2136,7 +2134,7 @@ static int nvme_suspend(struct device *dev)
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct nvme_dev *ndev = pci_get_drvdata(pdev); struct nvme_dev *ndev = pci_get_drvdata(pdev);
nvme_dev_shutdown(ndev); nvme_dev_disable(ndev, true);
return 0; return 0;
} }
...@@ -2167,7 +2165,7 @@ static pci_ers_result_t nvme_error_detected(struct pci_dev *pdev, ...@@ -2167,7 +2165,7 @@ static pci_ers_result_t nvme_error_detected(struct pci_dev *pdev,
case pci_channel_io_normal: case pci_channel_io_normal:
return PCI_ERS_RESULT_CAN_RECOVER; return PCI_ERS_RESULT_CAN_RECOVER;
case pci_channel_io_frozen: case pci_channel_io_frozen:
nvme_dev_shutdown(dev); nvme_dev_disable(dev, false);
return PCI_ERS_RESULT_NEED_RESET; return PCI_ERS_RESULT_NEED_RESET;
case pci_channel_io_perm_failure: case pci_channel_io_perm_failure:
return PCI_ERS_RESULT_DISCONNECT; return PCI_ERS_RESULT_DISCONNECT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment