[PATCH] nvme-pci: Avoid to go into d3cold if device can't use npss.

From: Koba Ko
Date: Wed May 19 2021 - 23:33:22 EST


During suspend, if the device can't use npss, driver would put
controller to shutdown simply and let host to control power management.
After resume, host can't change power state of the closed controller
from D3cold to D0.
For these devices, just avoid to go deeper than d3hot.

Tested-by: Henrik Juul Hansen <hjhansen2020@xxxxxxxxx>
Signed-off-by: Koba Ko <koba.ko@xxxxxxxxxxxxx>
---
drivers/nvme/host/pci.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index a29b170701fc..caaf52051689 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -26,6 +26,7 @@
#include <linux/io-64-nonatomic-hi-lo.h>
#include <linux/sed-opal.h>
#include <linux/pci-p2pdma.h>
+#include <linux/pm_runtime.h>

#include "trace.h"
#include "nvme.h"
@@ -2958,6 +2959,15 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)

dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));

+ if (pm_suspend_via_firmware() || !dev->ctrl.npss ||
+ !pcie_aspm_enabled(pdev) ||
+ dev->nr_host_mem_descs ||
+ (dev->ctrl.quirks & NVME_QUIRK_SIMPLE_SUSPEND)) {
+ pdev->d3cold_allowed = false;
+ pci_d3cold_disable(pdev);
+ pm_runtime_resume(&pdev->dev);
+ }
+
nvme_reset_ctrl(&dev->ctrl);
async_schedule(nvme_async_probe, dev);

--
2.25.1