Skip to contentSkip to conversation

PCI: Add device-specific reset for Qualcomm devices

PATCH Superseded Jose Ignacio Tornos Martinez 3 participants 6 messages Jun 30 – Jul 21

Subsystems (4)

v12 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

PATCH v12 1/1 PCI: Add device-specific reset for Qualcomm devices

Some Qualcomm PCIe devices (WCN6855/WCN7850 WLAN cards, SDX62/SDX65 modems) lack working reset methods for VFIO passthrough scenarios. These devices have no FLR capability, advertise NoSoftRst+ (blocking PM reset), and have broken bus reset.

The problem manifests in VFIO passthrough scenarios:

- WCN6855 (17cb:1103) and WCN7850 (17cb:1107) WLAN devices:
Normal VM operation works fine, including clean shutdown/reboot. However, when the VM terminates uncleanly (crash, force-off), VFIO attempts to reset the device before it can be assigned to another VM. Without a working reset method, the device remains in an undefined state, preventing reuse.

- SDX62/SDX65 (17cb:0308) 5G modems: Never successfully initialize even on first VM assignment without proper reset capability.

Add device-specific reset methods using BAR-space hardware reset registers that exist in these devices:

- WCN6855/WCN7850 WLAN devices use SoC global reset via BAR0 (sequence from ath11k/ath12k driver: ath11k_pci_soc_global_reset(), ath11k_pci_sw_reset(), ath11k_mhi_set_mhictrl_reset()):
- Write/clear reset bit at offset 0x3008
- Wait for PCIe link recovery (up to 5 seconds)
- Clear MHI controller SYSERR status at offset 0x38

- SDX62/SDX65 modem devices use MHI SoC reset via BAR0 (sequence from MHI
driver: mhi_soc_reset(), mhi_pci_reset_prepare()):
- Write reset request to offset 0xb0
- Wait 2 seconds for reset completion

These are true hardware reset mechanisms (not power management or firmware error recovery), providing proper device reset for VFIO scenarios.

Testing was performed on desktop platforms with M.2 WLAN and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.

---
v12: Address Manivannan Sadhasivam feedback:
- Use WLAN instead of WiFi (Qualcomm's preferred terminology)
- Fix link recovery check: use !PCI_POSSIBLE_ERROR(val) instead of

    val != PCI_ERROR_RESPONSE (fixes type promotion bug)

v11: https://lore.kernel.org/all/[email protected]/

 drivers/pci/quirks.c | 117 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
drivers/pci/quirks.c +117 -0
index 431c021d7414..0de606366200 100644
@@ -4240,6 +4240,120 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)
 	return 0;
 }
 
+#define QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET	0x3008
+#define QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET_V	BIT(0)
+#define QUALCOMM_WLAN_MHICTRL			0x38
+#define QUALCOMM_WLAN_MHICTRL_RESET_MASK	0x2
+
+/*
+ * Qualcomm WLAN device-specific reset using SoC global reset via BAR0
+ * registers.
+ */
+static int reset_qualcomm_wlan(struct pci_dev *pdev, bool probe)
+{
+	bool link_recovered = false;
+	unsigned long timeout;
+	void __iomem *bar;
+	u32 val;
+	u16 cmd;
+
+	if (probe)
+		return 0;
+
+	if (pdev->current_state != PCI_D0)
+		return -EINVAL;
+
+	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
+	pci_write_config_word(pdev, PCI_COMMAND, cmd | PCI_COMMAND_MEMORY);
+
+	bar = pci_iomap(pdev, 0, 0);
+	if (!bar) {
+		pci_write_config_word(pdev, PCI_COMMAND, cmd);
+		return -ENODEV;
+	}
+
+	val = ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+	val |= QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET_V;
+	iowrite32(val, bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+	ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+
+	msleep(10);
+
+	val &= ~QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET_V;
+	iowrite32(val, bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+	ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+
+	msleep(10);
+
+	timeout = jiffies + msecs_to_jiffies(5000);
+	while (time_before(jiffies, timeout)) {
+		val = ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+		if (!PCI_POSSIBLE_ERROR(val)) {
+			link_recovered = true;
+			break;
+		}
+		msleep(20);
+	}
+
+	if (!link_recovered) {
+		pci_err(pdev, "PCIe link failed to recover after reset\n");
+		goto out_restore;
+	}
+
+	/* After SOC_GLOBAL_RESET, MHISTATUS may still have SYSERR bit set
+	 * and thus need to set MHICTRL_RESET to clear SYSERR.
+	 */
+	iowrite32(QUALCOMM_WLAN_MHICTRL_RESET_MASK, bar + QUALCOMM_WLAN_MHICTRL);
+	ioread32(bar + QUALCOMM_WLAN_MHICTRL);
+
+	msleep(10);
+
+out_restore:
+	pci_iounmap(pdev, bar);
+	pci_write_config_word(pdev, PCI_COMMAND, cmd);
+
+	return link_recovered ? 0 : -ETIMEDOUT;
+}
+
+#define MHI_SOC_RESET_REQ_OFFSET		0xb0
+#define MHI_SOC_RESET_REQ			BIT(0)
+
+/*
+ * Qualcomm modem device-specific reset using MHI SoC reset via BAR0
+ * register.
+ */
+static int reset_qualcomm_modem(struct pci_dev *pdev, bool probe)
+{
+	void __iomem *bar;
+	u16 cmd;
+
+	if (probe)
+		return 0;
+
+	if (pdev->current_state != PCI_D0)
+		return -EINVAL;
+
+	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
+	pci_write_config_word(pdev, PCI_COMMAND, cmd | PCI_COMMAND_MEMORY);
+
+	bar = pci_iomap(pdev, 0, 0);
+	if (!bar) {
+		pci_write_config_word(pdev, PCI_COMMAND, cmd);
+		return -ENODEV;
+	}
+
+	iowrite32(MHI_SOC_RESET_REQ, bar + MHI_SOC_RESET_REQ_OFFSET);
+	ioread32(bar + MHI_SOC_RESET_REQ_OFFSET);
+
+	/* Be sure device reset has been executed */
+	msleep(2000);
+
+	pci_iounmap(pdev, bar);
+	pci_write_config_word(pdev, PCI_COMMAND, cmd);
+
+	return 0;
+}
+
 static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {
 	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82599_SFP_VF,
 		 reset_intel_82599_sfp_virtfn },
@@ -4255,6 +4369,9 @@ static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {
 		reset_chelsio_generic_dev },
 	{ PCI_VENDOR_ID_HUAWEI, PCI_DEVICE_ID_HINIC_VF,
 		reset_hinic_vf_dev },
+	{ PCI_VENDOR_ID_QCOM, 0x0308, reset_qualcomm_modem }, /* SDX62/SDX65 modems */
+	{ PCI_VENDOR_ID_QCOM, 0x1103, reset_qualcomm_wlan },  /* WCN6855 WLAN */
+	{ PCI_VENDOR_ID_QCOM, 0x1107, reset_qualcomm_wlan },  /* WCN7850 WLAN */
 	{ 0 }
 };
 
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The polling loop for PCIe link recovery lacks a final condition check, making it vulnerable to…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The polling loop for PCIe link recovery lacks a final condition check, making it vulnerable to spurious timeouts if the executing thread is delayed or preempted.
- [Medium] Read-modify-write operation on the SoC global reset register does not handle 0xFFFFFFFF (PCI_ERROR_RESPONSE), potentially writing an invalid state to the device. --

commit 6f0f5be433a0e989c17f01ae046c3574dc1fbf77
Author: Jose Ignacio Tornos Martinez <[email protected]>

PCI: Add device-specific reset for Qualcomm devices

This commit adds device-specific hardware reset methods via BAR0 for specific Qualcomm PCIe devices (WCN6855/WCN7850 WLAN cards and SDX62/SDX65 modems). These resets are intended to fix issues during VFIO passthrough scenarios where the devices lack a working FLR or standard reset mechanism.

Quoted 4 lines
drivers/pci/quirks.c +0 -0
index b09f27f7846fc..6d465f6d43054 100644

[ ... ]

Quoted 16 lines
drivers/pci/quirks.c +16 -0
+static int reset_qualcomm_wlan(struct pci_dev *pdev, bool probe)
+{
+	bool link_recovered = false;
+	unsigned long timeout;
+	void __iomem *bar;
+	u32 val;
+	u16 cmd;
+
+	if (probe)
+		return 0;
+
+	if (pdev->current_state != PCI_D0)
+		return -EINVAL;
+
+	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
+	pci_write_config_word(pdev, PCI_COMMAND, cmd | PCI_COMMAND_MEMORY);

drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4277

Quoted 10 lines
drivers/pci/quirks.c +10 -0
+
+	bar = pci_iomap(pdev, 0, 0);
+	if (!bar) {
+		pci_write_config_word(pdev, PCI_COMMAND, cmd);
+		return -ENODEV;
+	}
+
+	val = ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+	val |= QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET_V;
+	iowrite32(val, bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);

[Severity: Medium]
If the device is hung or the link is temporarily unresponsive, could the initial ioread32() return PCI_ERROR_RESPONSE (0xFFFFFFFF)?

If it does, this read-modify-write operation would write 0xFFFFFFFF (and later 0xFFFFFFFE) back to the device. Could writing these values trigger unintended resets across the SoC or leave the hardware in an invalid state?

Would it be safer to verify !PCI_POSSIBLE_ERROR(val) before modifying and writing it back?

Quoted 9 lines
drivers/pci/quirks.c +9 -0
+	ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+
+	msleep(10);
+
+	val &= ~QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET_V;
+	iowrite32(val, bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+	ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+
+	msleep(10);

drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4296

Quoted 10 lines
drivers/pci/quirks.c +10 -0
+
+	timeout = jiffies + msecs_to_jiffies(5000);
+	while (time_before(jiffies, timeout)) {
+		val = ioread32(bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);
+		if (!PCI_POSSIBLE_ERROR(val)) {
+			link_recovered = true;
+			break;
+		}
+		msleep(20);
+	}

[Severity: Medium]
Is this polling loop vulnerable to false timeouts due to scheduling delays?

If the thread is preempted during msleep(20) and delayed for more than 5 seconds, time_before(jiffies, timeout) will evaluate to false upon waking up. The loop will exit without a final check of the register, returning -ETIMEDOUT even if the link successfully recovered during the delay.

Should there be a final condition check after the loop, or perhaps use read_poll_timeout() instead to handle preemption robustly?

Quoted 9 lines
drivers/pci/quirks.c +9 -0
+
+	if (!link_recovered) {
+		pci_err(pdev, "PCIe link failed to recover after reset\n");
+		goto out_restore;
+	}
+
+	/* After SOC_GLOBAL_RESET, MHISTATUS may still have SYSERR bit set
+	 * and thus need to set MHICTRL_RESET to clear SYSERR.
+	 */

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 10 lines

[Severity: Medium]
If the device is hung or the link is temporarily unresponsive, could the initial ioread32() return PCI_ERROR_RESPONSE (0xFFFFFFFF)?

If it does, this read-modify-write operation would write 0xFFFFFFFF (and later 0xFFFFFFFE) back to the device. Could writing these values trigger unintended resets across the SoC or leave the hardware in an invalid state?

Would it be safer to verify !PCI_POSSIBLE_ERROR(val) before modifying and writing it back?

The read-modify-write on the SOC_GLOBAL_RESET register replicates the existing ath11k/ath12k driver reset sequence (ath11k_pci_soc_global_reset()). If the device already returns 0xFFFFFFFF at this point, it is unresponsive and writing to it will not make things worse - the purpose of this function is precisely to reset a device in a bad state. The link recovery loop below already handles the case where the device remains unresponsive after the reset attempt.

Quoted 10 lines

[Severity: Medium]
Is this polling loop vulnerable to false timeouts due to scheduling delays?

If the thread is preempted during msleep(20) and delayed for more than 5 seconds, time_before(jiffies, timeout) will evaluate to false upon waking up. The loop will exit without a final check of the register, returning -ETIMEDOUT even if the link successfully recovered during the delay.

Should there be a final condition check after the loop, or perhaps use read_poll_timeout() instead to handle preemption robustly?

The time_before()/msleep() polling pattern replicates the existing driver recovery logic and is standard kernel practice, used throughout drivers/pci/quirks.c and PCI core. A scheduling delay exceeding 5 seconds would indicate a severe system issue beyond the scope of this reset function. The 5-second timeout is generous for what typically recovers in under 1 second.

Since the implementation replicates existing driver behavior, both points were already discussed during review with the subsystem maintainer, and are handled in the code, no changes are needed.

#3 lore raw
Quoted 11 lines · On Mon, 13 Jul 2026 10:52:32 +0200 Jose Ignacio Tornos Martinez…
Quoted 10 lines

[Severity: Medium]
If the device is hung or the link is temporarily unresponsive, could the initial ioread32() return PCI_ERROR_RESPONSE (0xFFFFFFFF)?

If it does, this read-modify-write operation would write 0xFFFFFFFF (and later 0xFFFFFFFE) back to the device. Could writing these values trigger unintended resets across the SoC or leave the hardware in an invalid state?

Would it be safer to verify !PCI_POSSIBLE_ERROR(val) before modifying and writing it back?

Quoted 8 lines

The read-modify-write on the SOC_GLOBAL_RESET register replicates the existing ath11k/ath12k driver reset sequence (ath11k_pci_soc_global_reset()). If the device already returns 0xFFFFFFFF at this point, it is unresponsive and writing to it will not make things worse - the purpose of this function is precisely to reset a device in a bad state. The link recovery loop below already handles the case where the device remains unresponsive after the reset attempt.

The "will not make things worse" claim is really the best case scenario, there are platforms that won't silently swallow the write error and could escalate this to a platform level APEI/GHES error. Testing the initial ioread() value is a valid improvement in robustness.

Quoted 11 lines
Quoted 10 lines

[Severity: Medium]
Is this polling loop vulnerable to false timeouts due to scheduling delays?

If the thread is preempted during msleep(20) and delayed for more than 5 seconds, time_before(jiffies, timeout) will evaluate to false upon waking up. The loop will exit without a final check of the register, returning -ETIMEDOUT even if the link successfully recovered during the delay.

Should there be a final condition check after the loop, or perhaps use read_poll_timeout() instead to handle preemption robustly?

Quoted 6 lines

The time_before()/msleep() polling pattern replicates the existing driver recovery logic and is standard kernel practice, used throughout drivers/pci/quirks.c and PCI core. A scheduling delay exceeding 5 seconds would indicate a severe system issue beyond the scope of this reset function. The 5-second timeout is generous for what typically recovers in under 1 second.

IMO, this is also a valid finding and the suggestion to use read_poll_timeout() actually simplifies the code. The entire loop just becomes something like:

	ret = read_poll_timeout(ioread32, val, !PCI_POSSIBLE_ERROR(val),
				20 * USEC_PER_MSEC, 5 * USEC_PER_SEC, false,
				bar + QUALCOMM_WLAN_PCIE_SOC_GLOBAL_RESET);

It might indeed only be a pathological case that behaves exactly as sashiko identifies, but in fact any exit from the loop due to timeout returns with a stale value in val. The similar use cases in quirks.c might well be improved in the same way.

Quoted 4 lines

Since the implementation replicates existing driver behavior, both points were already discussed during review with the subsystem maintainer, and are handled in the code, no changes are needed.

Likewise, maybe an opportunity to improve the driver code. Thanks,

Alex

#5 lore raw
In reply to Jose Ignacio Tornos Martinez

Hi Bjorn,

Gentle ping on this patch. It has Mani's Reviewed-by and has been tested over 100+ VM reset cycles for both WLAN and modem devices.

This patch adds device-specific reset for Qualcomm PCIe devices (WCN6855, WCN7850 WLAN and SDX62/SDX65 modems) that lack working reset methods for VFIO passthrough. The reset uses BAR-space hardware registers, replicating the sequences from ath11k/ath12k and MHI drivers. Without this, these devices cannot be reused after an unclean VM termination.

The approach follows Alex's guidance through the series:
device-specific reset via pci_dev_reset_methods[] (suggested in v5), and BAR-space hardware reset registers instead of D3hot power cycling (refined with Mani from v10 onwards).

The quirk_no_bus_reset part was already merged for v7.2, and this device-specific reset completes the solution.

Is there anything else needed for this to be considered?

Thanks,
Jose Ignacio