Skip to contentSkip to conversation

nvme-pci: try function level reset on init failure

PATCH Superseded Keith Busch 4 participants 4 messages Jul 14, 2025 – Jul 15, 2025 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-pci: try function level reset on init failure

From: Keith Busch <[email protected]>

I've encountered various nvme devices that for whatever reason are stuck in a reset state. Historically these have required a power cycle to make them usable again. Vendors don't report any problem with the device when we ship these for analysis.

In many cases, a PCIe FLR is sufficient to restart operation without a power cycle. Try it if controller reset fails the first time.

---
 drivers/nvme/host/pci.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +12 -2
index 4cf87fb5d8573..85749f19e3a23 100644
@@ -2067,8 +2067,18 @@ static int nvme_pci_configure_admin_queue(struct nvme_dev *dev)
 	 * might be pointing at!
 	 */
 	result = nvme_disable_ctrl(&dev->ctrl, false);
-	if (result < 0)
-		return result;
+	if (result < 0) {
+		struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+		result = pcie_flr(pdev);
+		if (result < 0)
+			return result;
+		pci_restore_state(pdev);
+
+		result = nvme_disable_ctrl(&dev->ctrl, false);
+		if (result < 0)
+			return result;
+	}
 
 	result = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH);
 	if (result)
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Keith Busch

From: Keith Busch <[email protected]>

I've encountered various nvme devices that for whatever reason are stuck in a reset state. Historically these have required a power cycle to make them usable again. Vendors don't report any problem with the device when we ship these for analysis.

In many cases, a PCIe FLR is sufficient to restart operation without a power cycle. Try it if controller reset fails the first time.

I hope there are no setups that are relying on this failure and okay with implicit PCIe FLR and any side-effects it might have, but I think that is okay, looks good.

-ck

Quoted 29 lines
---
  drivers/nvme/host/pci.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +12 -2
index 4cf87fb5d8573..85749f19e3a23 100644
@@ -2067,8 +2067,18 @@ static int nvme_pci_configure_admin_queue(struct nvme_dev *dev)
  	 * might be pointing at!
  	 */
  	result = nvme_disable_ctrl(&dev->ctrl, false);
-	if (result < 0)
-		return result;
+	if (result < 0) {
+		struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+		result = pcie_flr(pdev);
+		if (result < 0)
+			return result;
+		pci_restore_state(pdev);
+
+		result = nvme_disable_ctrl(&dev->ctrl, false);
+		if (result < 0)
+			return result;
+	}
 
  	result = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH);
  	if (result)
#2 lore raw
In reply to Keith Busch
Quoted 6 lines · Keith Busch

From: Keith Busch <[email protected]>

I've encountered various nvme devices that for whatever reason are stuck in a reset state. Historically these have required a power cycle to make them usable again. Vendors don't report any problem with the device when we ship these for analysis.

Who is the "we" here?

Quoted 2 lines

In many cases, a PCIe FLR is sufficient to restart operation without a power cycle. Try it if controller reset fails the first time.

Why is that only done in the probe path and not the runtime reset path?

drivers/nvme/host/pci.c static int nvme_pci_configure_admin_queue(struct nvme_dev *dev) · line 2081

Quoted 12 lines
drivers/nvme/host/pci.c +12 -0
+	if (result < 0) {
+		struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+		result = pcie_flr(pdev);
+		if (result < 0)
+			return result;
+		pci_restore_state(pdev);
+
+		result = nvme_disable_ctrl(&dev->ctrl, false);
+		if (result < 0)
+			return result;
+	}

Either way this warrants a big comment explaining what we are doing here.

maintainer
#3 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Keith Busch

From: Keith Busch <[email protected]>

I've encountered various nvme devices that for whatever reason are stuck in a reset state. Historically these have required a power cycle to make them usable again. Vendors don't report any problem with the device when we ship these for analysis.

Who is the "we" here?

Meta.

Quoted 4 lines
Quoted 2 lines

In many cases, a PCIe FLR is sufficient to restart operation without a power cycle. Try it if controller reset fails the first time.

Why is that only done in the probe path and not the runtime reset path?

nvme_pci_configure_admin_queue() is called for both probe and reset_work.

Is it because I wrote "fails the first time"? I mean the first reset for each initialization attempt, whether it happens during probe or a later reset. The code path will try an FLR on every single nvme reset if CSTS.RDY doesn't clear as expected.

Quoted 7 lines
Quoted 7 lines
drivers/nvme/host/pci.c +7 -0
+	if (result < 0) {
+		struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+		result = pcie_flr(pdev);
+		if (result < 0)
+			return result;
+		pci_restore_state(pdev);
Quoted 8 lines

drivers/nvme/host/pci.c static int nvme_pci_configure_admin_queue(struct nvme_dev *dev) · line 2081

Quoted 5 lines
drivers/nvme/host/pci.c +5 -0
+
+		result = nvme_disable_ctrl(&dev->ctrl, false);
+		if (result < 0)
+			return result;
+	}

Either way this warrants a big comment explaining what we are doing here.

Sure, no problem. I think also a dev_warn() if the 2nd disable_ctrl call was successful to indicate an FLR was needed to get an expected response.