Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffe7704d authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe
Browse files

NVMe: Unify controller probe and resume



This unifies probe and resume so they both may be scheduled in the same
way. This is necessary for error handling that may occur during device
initialization since the task to cleanup the device wouldn't be able to
run if it is blocked on device initialization.

Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 17188bb4
Loading
Loading
Loading
Loading
+29 −23
Original line number Original line Diff line number Diff line
@@ -2361,6 +2361,7 @@ static int nvme_dev_add(struct nvme_dev *dev)
	}
	}
	kfree(ctrl);
	kfree(ctrl);


	if (!dev->tagset.tags) {
		dev->tagset.ops = &nvme_mq_ops;
		dev->tagset.ops = &nvme_mq_ops;
		dev->tagset.nr_hw_queues = dev->online_queues - 1;
		dev->tagset.nr_hw_queues = dev->online_queues - 1;
		dev->tagset.timeout = NVME_IO_TIMEOUT;
		dev->tagset.timeout = NVME_IO_TIMEOUT;
@@ -2373,7 +2374,7 @@ static int nvme_dev_add(struct nvme_dev *dev)


		if (blk_mq_alloc_tag_set(&dev->tagset))
		if (blk_mq_alloc_tag_set(&dev->tagset))
			return 0;
			return 0;

	}
	schedule_work(&dev->scan_work);
	schedule_work(&dev->scan_work);
	return 0;
	return 0;
}
}
@@ -2924,7 +2925,7 @@ static int nvme_dev_resume(struct nvme_dev *dev)
		spin_unlock(&dev_list_lock);
		spin_unlock(&dev_list_lock);
	} else {
	} else {
		nvme_unfreeze_queues(dev);
		nvme_unfreeze_queues(dev);
		schedule_work(&dev->scan_work);
		nvme_dev_add(dev);
		nvme_set_irq_hints(dev);
		nvme_set_irq_hints(dev);
	}
	}
	return 0;
	return 0;
@@ -2932,8 +2933,17 @@ static int nvme_dev_resume(struct nvme_dev *dev)


static void nvme_dev_reset(struct nvme_dev *dev)
static void nvme_dev_reset(struct nvme_dev *dev)
{
{
	bool in_probe = work_busy(&dev->probe_work);

	nvme_dev_shutdown(dev);
	nvme_dev_shutdown(dev);
	if (nvme_dev_resume(dev)) {

	/* Synchronize with device probe so that work will see failure status
	 * and exit gracefully without trying to schedule another reset */
	flush_work(&dev->probe_work);

	/* Fail this device if reset occured during probe to avoid
	 * infinite initialization loops. */
	if (in_probe) {
		dev_warn(dev->dev, "Device failed to resume\n");
		dev_warn(dev->dev, "Device failed to resume\n");
		kref_get(&dev->kref);
		kref_get(&dev->kref);
		if (IS_ERR(kthread_run(nvme_remove_dead_ctrl, dev, "nvme%d",
		if (IS_ERR(kthread_run(nvme_remove_dead_ctrl, dev, "nvme%d",
@@ -2942,7 +2952,11 @@ static void nvme_dev_reset(struct nvme_dev *dev)
				"Failed to start controller remove task\n");
				"Failed to start controller remove task\n");
			kref_put(&dev->kref, nvme_free_dev);
			kref_put(&dev->kref, nvme_free_dev);
		}
		}
		return;
	}
	}
	/* Schedule device resume asynchronously so the reset work is available
	 * to cleanup errors that may occur during reinitialization */
	schedule_work(&dev->probe_work);
}
}


static void nvme_reset_failed_dev(struct work_struct *ws)
static void nvme_reset_failed_dev(struct work_struct *ws)
@@ -2974,6 +2988,7 @@ static int nvme_reset(struct nvme_dev *dev)


	if (!ret) {
	if (!ret) {
		flush_work(&dev->reset_work);
		flush_work(&dev->reset_work);
		flush_work(&dev->probe_work);
		return 0;
		return 0;
	}
	}


@@ -3070,18 +3085,9 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
static void nvme_async_probe(struct work_struct *work)
static void nvme_async_probe(struct work_struct *work)
{
{
	struct nvme_dev *dev = container_of(work, struct nvme_dev, probe_work);
	struct nvme_dev *dev = container_of(work, struct nvme_dev, probe_work);
	int result;

	result = nvme_dev_start(dev);
	if (result)
		goto reset;


	if (dev->online_queues > 1)
	if (nvme_dev_resume(dev))
		result = nvme_dev_add(dev);
	if (result)
		goto reset;
		goto reset;

	nvme_set_irq_hints(dev);
	return;
	return;
 reset:
 reset:
	spin_lock(&dev_list_lock);
	spin_lock(&dev_list_lock);