Skip to contentSkip to conversation

PCI: add AMD PCIe quirk for nvme shutdown opt

PATCH In review Prike Liang 2 participants 4 messages Apr 14, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 PCI: add AMD PCIe quirk for nvme shutdown opt

The NVME device pluged in some AMD PCIE root port will resume timeout from s2idle which caused by NVME power CFG lost in the SMU FW restore. This issue can be workaround by using PCIe power set with simple suspend/resume process path instead of APST. In the onwards ASIC will try do the NVME shutdown save and restore in the BIOS and still need PCIe power setting to resume from RTD3 for s2idle.

In this preparation patch add a PCIe quirk for the AMD.

[ck: split patches for nvme and pcie]
---
 drivers/pci/quirks.c | 10 ++++++++++
 include/linux/pci.h  |  2 ++
 2 files changed, 12 insertions(+)
drivers/pci/quirks.c +10 -0
index 653660e3..f95c8b2 100644
@@ -312,6 +312,16 @@ static void quirk_nopciamd(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,	PCI_DEVICE_ID_AMD_8151_0,	quirk_nopciamd);
 
+static void quirk_amd_nvme_fixup(struct pci_dev *dev)
+{
+	struct pci_dev *rdev;
+
+	dev->dev_flags |= PCI_DEV_FLAGS_AMD_NVME_SIMPLE_SUSPEND;
+	pci_info(dev, "AMD simple suspend opt enabled\n");
+
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1630, quirk_amd_nvme_fixup);
+
 /* Triton requires workarounds to be used by the drivers */
 static void quirk_triton(struct pci_dev *dev)
 {
include/linux/pci.h +2 -0
index 53f4904..a6e1b1b 100644
@@ -227,6 +227,8 @@ enum pci_dev_flags {
 	PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 << 10),
 	/* Don't use Relaxed Ordering for TLPs directed at this device */
 	PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 11),
+	/* AMD simple suspend opt quirk */
+	PCI_DEV_FLAGS_AMD_NVME_SIMPLE_SUSPEND = (__force pci_dev_flags_t) (1 << 12),
 };
 
 enum pci_irq_reroute_variant {
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 nvme-pci: add AMD PCIe quirk for suspend/resume

The NVME device pluged in some AMD PCIE root port will resume timeout from s2idle which caused by NVME power CFG lost in the SMU FW restore. This issue can be workaround by using PCIe power set with simple suspend/resume process path instead of APST. In the onwards ASIC will try do the NVME shutdown save and restore in the BIOS and still need PCIe power setting to resume from RTD3 for s2idle.

Update the nvme_acpi_storage_d3() _with previously added quirk.

---
 drivers/nvme/host/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/host/pci.c +5 -0
index 6bad4d4..dd46d9e 100644
@@ -2832,6 +2832,7 @@ static bool nvme_acpi_storage_d3(struct pci_dev *dev)
 {
 	struct acpi_device *adev;
 	struct pci_dev *root;
+	struct pci_dev *rdev;
 	acpi_handle handle;
 	acpi_status status;
 	u8 val;
@@ -2845,6 +2846,10 @@ static bool nvme_acpi_storage_d3(struct pci_dev *dev)
 	if (!root)
 		return false;
 
+	rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
+	if (rdev->dev_flags & PCI_DEV_FLAGS_AMD_NVME_SIMPLE_SUSPEND)
+		return NVME_QUIRK_SIMPLE_SUSPEND;
+
 	adev = ACPI_COMPANION(&root->dev);
 	if (!adev)
 		return false;
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH 2/2] nvme-pci: add AMD PCIe quirk for suspend/resume

Quoted 32 lines · Prike Liang

The NVME device pluged in some AMD PCIE root port will resume timeout from s2idle which caused by NVME power CFG lost in the SMU FW restore. This issue can be workaround by using PCIe power set with simple suspend/resume process path instead of APST. In the onwards ASIC will try do the NVME shutdown save and restore in the BIOS and still need PCIe power setting to resume from RTD3 for s2idle.

Update the nvme_acpi_storage_d3() _with previously added quirk.

---
 drivers/nvme/host/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/host/pci.c +1 -0
index 6bad4d4..dd46d9e 100644
@@ -2832,6 +2832,7 @@ static bool nvme_acpi_storage_d3(struct pci_dev *dev)
 {
 	struct acpi_device *adev;
 	struct pci_dev *root;
+	struct pci_dev *rdev;
 	acpi_handle handle;
 	acpi_status status;
 	u8 val;

drivers/nvme/host/pci.c static bool nvme_acpi_storage_d3(struct pci_dev *dev) · line 2852

Quoted 7 lines
drivers/nvme/host/pci.c +4 -0
@@ -2845,6 +2846,10 @@ static bool nvme_acpi_storage_d3(struct pci_dev *dev)
 	if (!root)
 		return false;
 
+	rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
+	if (rdev->dev_flags & PCI_DEV_FLAGS_AMD_NVME_SIMPLE_SUSPEND)
+		return NVME_QUIRK_SIMPLE_SUSPEND;
+

You just leaked a reference count :(

And what if rdev is NULL?

#3 lore raw

RE: [PATCH 2/2] nvme-pci: add AMD PCIe quirk for suspend/resume

[AMD Public Use]

Quoted 49 lines

From: Greg KH <[email protected]>
Sent: Wednesday, April 14, 2021 1:34 PM
To: Liang, Prike <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; S-k, Shyam-sundar <[email protected]>; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 2/2] nvme-pci: add AMD PCIe quirk for suspend/resume

drivers/nvme/host/pci.c static bool nvme_acpi_storage_d3(struct

Quoted 32 lines · Prike Liang

The NVME device pluged in some AMD PCIE root port will resume timeout from s2idle which caused by NVME power CFG lost in the SMU FW restore. This issue can be workaround by using PCIe power set with simple suspend/resume process path instead of APST. In the onwards ASIC will try do the NVME shutdown save and restore in the BIOS and still need PCIe power setting to resume from RTD3 for s2idle.

Update the nvme_acpi_storage_d3() _with previously added quirk.

---
 drivers/nvme/host/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/host/pci.c index renamed from drivers/nvme/host/pci.c +0 -0

6bad4d4..dd46d9e 100644

drivers/nvme/host/pci.c +1 -0
@@ -2832,6 +2832,7 @@ static bool nvme_acpi_storage_d3(struct pci_dev
 *dev)  {
 struct acpi_device *adev;
 struct pci_dev *root;
+struct pci_dev *rdev;
 acpi_handle handle;
 acpi_status status;
 u8 val;
@@ -2845,6 +2846,10 @@ static bool nvme_acpi_storage_d3(struct

pci_dev *dev)

drivers/nvme/host/pci.c static bool nvme_acpi_storage_d3(struct pci_dev *dev)

Quoted 5 lines
drivers/nvme/host/pci.c +2 -0
 if (!root)
 return false;
 
+rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
+if (rdev->dev_flags &

PCI_DEV_FLAGS_AMD_NVME_SIMPLE_SUSPEND)

Quoted 6 lines

drivers/nvme/host/pci.c static bool nvme_acpi_storage_d3(struct pci_dev *dev) · line 2852

Quoted 2 lines
drivers/nvme/host/pci.c +2 -0
+return NVME_QUIRK_SIMPLE_SUSPEND;
+

You just leaked a reference count :(

And what if rdev is NULL?

That seems the root complex entity not likely inexistence but have a null point check will be more safe. Thanks point out and will update the patch.

Thanks,
Prike