Add device-specific reset for Qualcomm devices
PATCH v10 1/1 Add device-specific reset for Qualcomm devices
Some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi 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) WiFi 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 WiFi 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 WiFi and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.
---
v10:
- Complete redesign based on maintainer feedback (Manivannan Sadhasivam, Alex Williamson): use actual hardware reset registers from device drivers instead of D3hot power cycling
v9: https://lore.kernel.org/all/[email protected]/
drivers/pci/quirks.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)
drivers/pci/quirks.c +118 -0
@@ -4240,6 +4240,121 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)return 0 ; } +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET 0x3008 +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V BIT(0) +#define QUALCOMM_WIFI_MHISTATUS 0x48 +#define QUALCOMM_WIFI_MHICTRL 0x38 +#define QUALCOMM_WIFI_MHICTRL_RESET_MASK 0x2 + +/* +* Qualcomm WiFi device-specific reset using SoC global reset via BAR0 +* registers. +*/ +static int reset_qualcomm_wifi (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_WIFI_PCIE_SOC_GLOBAL_RESET ); + val |=QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + val &= ~QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + timeout = jiffies +msecs_to_jiffies (5000 ); +while (time_before (jiffies, timeout)) { + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +if (val !=0xffffffff ) { + 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_WIFI_MHICTRL_RESET_MASK , bar +QUALCOMM_WIFI_MHICTRL ); +ioread32 (bar +QUALCOMM_WIFI_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 +4370,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, 0x1103, reset_qualcomm_wifi }, /* WCN6855 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x1107, reset_qualcomm_wifi }, /* WCN7850 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x0308, reset_qualcomm_modem }, /* SDX62/SDX65 modems */ { 0 } };
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Unvalidated BAR length allows an out-of-bounds MMIO access, leading to a kernel page fault.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unvalidated BAR length allows an out-of-bounds MMIO access, leading to a kernel page fault.
- [Medium] The polling loop for PCIe link recovery skips checking the register entirely if the thread is preempted or delayed, leading to a false timeout failure. --
commit 0bc922fa348200a554286ab131ffa7ae41d959f1
Author: Jose Ignacio Tornos Martinez <[email protected]>
Add device-specific reset for Qualcomm devices
This commit adds device-specific reset methods for some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi cards, SDX62/SDX65 modems) that lack working reset methods for VFIO passthrough scenarios. The new methods use BAR-space hardware reset registers to provide true hardware resets.
Quoted 4 lines
drivers/pci/quirks.c +0
-0
[ ... ]
Quoted 14 lines
drivers/pci/quirks.c +14
-0+static int reset_qualcomm_wifi (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 ; +
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4276
Quoted 10 lines
drivers/pci/quirks.c +10
-0+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_WIFI_PCIE_SOC_GLOBAL_RESET );
[Severity: High]
Can this lead to an out-of-bounds MMIO access if a spoofed device advertises a truncated BAR?
Since pci_iomap() is called without validating the length of BAR 0, if a malicious or malfunctioning device advertises a length shorter than the accessed offset (0x3008), reading from the unmapped memory could trigger a kernel page fault.
Should pci_resource_len(pdev, 0) be checked against the maximum offset before accessing the registers?
Quoted 13 lines
drivers/pci/quirks.c +13
-0+ val |=QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + val &= ~QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + timeout = jiffies +msecs_to_jiffies (5000 );
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4299
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while (time_before (jiffies, timeout)) { + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +if (val !=0xffffffff ) { + link_recovered = true; +break ; + } +msleep (20 ); + } + +if (!link_recovered) {
[Severity: Medium]
Could this loop return a false timeout if the thread is preempted?
If the scheduler delays the thread for longer than the timeout period just before the loop starts or during msleep(), time_before() would return false and the loop would exit without a final check of the hardware register.
Should there be a final register read after the loop (similar to what is done in reset_hinic_vf_dev()), or could read_poll_timeout() be used here instead?
[ ... ]
Quoted 11 lines
drivers/pci/quirks.c +11
-0+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 ; +
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4346
Quoted 10 lines
drivers/pci/quirks.c +10
-0+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 );
[Severity: High]
Is a BAR length check needed here as well to prevent out-of-bounds accesses for MHI_SOC_RESET_REQ_OFFSET (0xb0)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 82 lines · Jose Ignacio Tornos Martinez
Some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi 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) WiFi 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 WiFi 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 offset0x3008
- Wait for PCIe link recovery (up to 5 seconds)
- Clear MHI controller SYSERR status at offset0x38- 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 offset0xb0
- Wait 2 seconds for reset completionThese 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 WiFi and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v10:
- Complete redesign based on maintainer feedback (Manivannan Sadhasivam, Alex Williamson): use actual hardware reset registers from device drivers instead of D3hot power cycling
v9: https://lore.kernel.org/all/[email protected]/drivers/pci/quirks.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)drivers/pci/quirks.c +24
-0@@ -4240,6 +4240,121 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)return 0 ; } +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET 0x3008 +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V BIT(0) +#define QUALCOMM_WIFI_MHISTATUS 0x48 +#define QUALCOMM_WIFI_MHICTRL 0x38 +#define QUALCOMM_WIFI_MHICTRL_RESET_MASK 0x2 + +/* +* Qualcomm WiFi device-specific reset using SoC global reset via BAR0 +* registers. +*/ +static int reset_qualcomm_wifi (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 ; +
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4276
Quoted 10 lines
drivers/pci/quirks.c +10
-0+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_WIFI_PCIE_SOC_GLOBAL_RESET );
QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET is beyond the first 4K bar area hence requires MHI wakeup before accessing, see [1]. the wakeup callback for WCN6855 is ath11k_pci_bus_wake_up() which calls mhi_device_get_sync(). Not sure how this can be done here. Maybe Mani can provide some hints?
Quoted 94 lines
drivers/pci/quirks.c +84
-0+ val |=QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + val &= ~QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + timeout = jiffies +msecs_to_jiffies (5000 ); +while (time_before (jiffies, timeout)) { + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +if (val !=0xffffffff ) { + 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_WIFI_MHICTRL_RESET_MASK , bar +QUALCOMM_WIFI_MHICTRL ); +ioread32 (bar +QUALCOMM_WIFI_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 +4370,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, 0x1103, reset_qualcomm_wifi }, /* WCN6855 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x1107, reset_qualcomm_wifi }, /* WCN7850 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x0308, reset_qualcomm_modem }, /* SDX62/SDX65 modems */ { 0 } };
Hello Baochen and Mani,
Quoted 4 lines
QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESETis beyond the first 4K bar area hence requires MHI wakeup before accessing, see [1]. the wakeup callback for WCN6855 isath11k_pci_bus_wake_up()which callsmhi_device_get_sync(). Not sure how this can be done here. Maybe Mani can provide some hints?
I've analyzed the driver code and see that ath11k_pci_power_down() calls ath11k_pci_force_wake() before sw_reset().
I can add the same force_wake sequence to the WiFi quirk before accessing the reset register:
/* Force wake before accessing registers beyond 4K boundary */ iowrite32(1, bar + QUALCOMM_WIFI_PCIE_SOC_WAKE_PCIE_LOCAL_REG); // 0x3004ioread32(bar + QUALCOMM_WIFI_PCIE_SOC_WAKE_PCIE_LOCAL_REG); // Flush
msleep(5);
With this addition, both WCN6855 (ath11k) and WCN7850 (ath12k) show successful reset and shutdown cycles in VFIO scenarios, same stability as without it.
Do you consider this addition necessary, or is the current v10 implementation sufficient given that testing shows direct register access works without wakeup in VFIO scenarios (where no driver is loaded)?
If you recommend including it, I can send v11 with the force_wake sequence added.
Thanks
Best regards
Jose Ignacio
Manivannan Sadhasivam
maintainerQuoted 92 lines · Baochen Qiang
Quoted 89 lines · Jose Ignacio Tornos Martinez
Some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi 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) WiFi 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 WiFi 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 offset0x3008
- Wait for PCIe link recovery (up to 5 seconds)
- Clear MHI controller SYSERR status at offset0x38- 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 offset0xb0
- Wait 2 seconds for reset completionThese 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 WiFi and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v10:
- Complete redesign based on maintainer feedback (Manivannan Sadhasivam, Alex Williamson): use actual hardware reset registers from device drivers instead of D3hot power cycling
v9: https://lore.kernel.org/all/[email protected]/drivers/pci/quirks.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)drivers/pci/quirks.c +31
-0@@ -4240,6 +4240,121 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)return 0 ; } +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET 0x3008 +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V BIT(0) +#define QUALCOMM_WIFI_MHISTATUS 0x48 +#define QUALCOMM_WIFI_MHICTRL 0x38 +#define QUALCOMM_WIFI_MHICTRL_RESET_MASK 0x2 + +/* +* Qualcomm WiFi device-specific reset using SoC global reset via BAR0 +* registers. +*/ +static int reset_qualcomm_wifi (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 ;
Quoted 9 lines
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4276
Quoted 3 lines
drivers/pci/quirks.c +3
-0+ } + + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET );
QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESETis beyond the first 4K bar area hence requires MHI wakeup before accessing, see [1]. the wakeup callback for WCN6855 isath11k_pci_bus_wake_up()which callsmhi_device_get_sync(). Not sure how this can be done here. Maybe Mani can provide some hints?
I don't think the device needs to be waken up before QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET. ath11k driver wakes up the device for accessing the MHI interface I believe. Since this callback is not touching MHI, there is no need to wakeup the device, AFAIK.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Quoted 103 lines · Manivannan Sadhasivam
Quoted 92 lines · Baochen Qiang
Quoted 89 lines · Jose Ignacio Tornos Martinez
Some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi 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) WiFi 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 WiFi 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 offset0x3008
- Wait for PCIe link recovery (up to 5 seconds)
- Clear MHI controller SYSERR status at offset0x38- 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 offset0xb0
- Wait 2 seconds for reset completionThese 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 WiFi and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v10:
- Complete redesign based on maintainer feedback (Manivannan Sadhasivam, Alex Williamson): use actual hardware reset registers from device drivers instead of D3hot power cycling
v9: https://lore.kernel.org/all/[email protected]/drivers/pci/quirks.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)drivers/pci/quirks.c +31
-0@@ -4240,6 +4240,121 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)return 0 ; } +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET 0x3008 +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V BIT(0) +#define QUALCOMM_WIFI_MHISTATUS 0x48 +#define QUALCOMM_WIFI_MHICTRL 0x38 +#define QUALCOMM_WIFI_MHICTRL_RESET_MASK 0x2 + +/* +* Qualcomm WiFi device-specific reset using SoC global reset via BAR0 +* registers. +*/ +static int reset_qualcomm_wifi (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 ;Quoted 9 lines
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4276
Quoted 3 lines
drivers/pci/quirks.c +3
-0+ } + + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET );
QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESETis beyond the first 4K bar area hence requires MHI wakeup before accessing, see [1]. the wakeup callback for WCN6855 isath11k_pci_bus_wake_up()which callsmhi_device_get_sync(). Not sure how this can be done here. Maybe Mani can provide some hints?
Quoted 4 lines
I don't think the device needs to be waken up before
QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET. ath11k driver wakes up the device for accessing the MHI interface I believe. Since this callback is not touching MHI, there is no need to wakeup the device, AFAIK.
MHI register space is constitute with 3 segments, with mhi offset always being 0, bhi offset 0x100 and bhie offset 0x224 (the latter two offsets are for WCN7850, but I think also apply to other devices). That said the whole MHI register space does not go beyond the first 4K region, hence wakeup is not for accessing MHI interface.
Quoted 3 lines
- Mani
Manivannan Sadhasivam
maintainerQuoted 55 lines · Jose Ignacio Tornos Martinez
Some Qualcomm PCIe devices (WCN6855/WCN7850 WiFi 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) WiFi 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 WiFi 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 offset0x3008
- Wait for PCIe link recovery (up to 5 seconds)
- Clear MHI controller SYSERR status at offset0x38- 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 offset0xb0
- Wait 2 seconds for reset completionThese 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 WiFi and modem cards using M.2-to-PCIe adapters, including extensive force-reset cycling to verify stability.
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v10:
- Complete redesign based on maintainer feedback (Manivannan Sadhasivam, Alex Williamson): use actual hardware reset registers from device drivers instead of D3hot power cycling
v9: https://lore.kernel.org/all/[email protected]/drivers/pci/quirks.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)drivers/pci/quirks.c +0
-0
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4245
Quoted 6 lines
drivers/pci/quirks.c +3
-0@@ -4240,6 +4240,121 @@ static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)return 0 ; } +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET 0x3008 +#define QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V BIT(0) +#define QUALCOMM_WIFI_MHISTATUS 0x48
This macro is unused.
Quoted 37 lines
drivers/pci/quirks.c +37
-0+#define QUALCOMM_WIFI_MHICTRL 0x38 +#define QUALCOMM_WIFI_MHICTRL_RESET_MASK 0x2 + +/* +* Qualcomm WiFi device-specific reset using SoC global reset via BAR0 +* registers. +*/ +static int reset_qualcomm_wifi (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_WIFI_PCIE_SOC_GLOBAL_RESET ); + val |=QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); +
drivers/pci/quirks.c static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) · line 4292
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ val &= ~QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET_V ; +iowrite32 (val, bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); + +msleep (10 ); + + timeout = jiffies +msecs_to_jiffies (5000 ); +while (time_before (jiffies, timeout)) { + val =ioread32 (bar +QUALCOMM_WIFI_PCIE_SOC_GLOBAL_RESET ); +if (val !=0xffffffff ) {
s/0xffffffff/PCI_ERROR_RESPONSE
Quoted 69 lines
drivers/pci/quirks.c +65
-0+ 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_WIFI_MHICTRL_RESET_MASK , bar +QUALCOMM_WIFI_MHICTRL ); +ioread32 (bar +QUALCOMM_WIFI_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 },
drivers/pci/quirks.c static const struct pci_dev_reset_methods pci_dev_reset_methods[] = { · line 4375
Quoted 6 lines
drivers/pci/quirks.c +3
-0@@ -4255,6 +4370,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, 0x1103, reset_qualcomm_wifi }, /* WCN6855 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x1107, reset_qualcomm_wifi }, /* WCN7850 WiFi */ + { PCI_VENDOR_ID_QCOM, 0x0308, reset_qualcomm_modem }, /* SDX62/SDX65 modems */
Not an issue and the existing entries are not sorted, but can you atleast keep these IDs sorted in ascending order?
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்