[PATCH] PCI: Add quirk for ID mutation of MSI Claw A8 cardreader

Lukas Wunner <[email protected]>
Newsgroups org.kernel.vger.linux-pci
Message-ID <36578f6e0829bbcdf68659ffad27b65715a97768.1786698126.git.lukas@wunner.de>
Derek reports a lockup on resume of the MSI Claw A8 if a card is inserted
into the onboard Realtek RTS525A cardreader.  He has root-caused it to a
mutation of the cardreader's Subsystem Vendor and Device ID:  Firmware
sets an MSI-specific ID on boot, but neglects to reset it on resume.
The ID thus changes to the generic Realtek Vendor and Device ID.

The firmware also incorrectly sets the Hot-Plug Capable bit on the Root
Port and the PCIe hotplug driver interprets the ID mutation as removal of
the cardreader during system sleep (see pciehp_device_replaced()).

The lockup is caused by the block layer being unaware of the hot-removal
and waiting indefinitely in sync_filesystem().  That is fixed with a
separate commit for the cardreader driver.  However despite that other
commit, the cardreader is still hot-removed and re-enumerated the first
time the system is put to sleep.  This is undesirable because it prevents
using an MMC card as root filesystem.

Avoid hot-removal of the cardreader by mutating the cached copy of the
Subsystem Vendor and Device ID.  This needs to be done before going to
sleep, not afterwards, because pci_pm_resume_noirq() is executed top-down
across the hierarchy and hence a pci_fixup_resume_early quirk of the
cardreader would run after hot-removal at its parent Root Port.

In the unlikely event that a fixed firmware becomes available, the quirk
can either be reverted or constrained to specific BIOS versions by way of
a dmi_get_date() conditional.

Reported-by: Derek J. Clark <[email protected]>
Tested-by: Derek J. Clark <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]/
Link: https://github.com/ValveSoftware/SteamOS/issues/2473
Signed-off-by: Lukas Wunner <[email protected]>
Cc: [email protected]
Cc: Matthew Schwartz <[email protected]>
---
 arch/x86/pci/fixup.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
index b301c6c..9da7ae0 100644
--- a/arch/x86/pci/fixup.c
+++ b/arch/x86/pci/fixup.c
@@ -1080,4 +1080,20 @@ static void quirk_tuxeo_rp_d3(struct pci_dev *pdev)
 	}
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1502, quirk_tuxeo_rp_d3);
+
+/*
+ * MSI Claw A8 firmware initializes the onboard Realtek RTS525A cardreader
+ * with an MSI-specific Subsystem Vendor and Device ID on boot, but neglects
+ * to re-initialize it on resume.  Avoid hot-removal of the cardreader due to
+ * the spurious ID change.
+ */
+static void quirk_msi_claw_cardreader(struct pci_dev *pdev)
+{
+	if (pdev->subsystem_vendor == 0x1462 &&
+	    pdev->subsystem_device == 0x14af) {
+		pdev->subsystem_vendor = pdev->vendor;
+		pdev->subsystem_device = pdev->device;
+	}
+}
+DECLARE_PCI_FIXUP_SUSPEND_LATE(PCI_VENDOR_ID_REALTEK, 0x525a, quirk_msi_claw_cardreader);
 #endif /* CONFIG_SUSPEND */
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.