Skip to content

Commit ae32b8e

Browse files
Ziyao LiMingcongBai
authored andcommitted
FROMLIST: PCI: loongson: Override PCIe bridge supported speeds for Loongson-3C6000 series
Older steppings of the Loongson-3C6000 series incorrectly report the supported link speeds on their PCIe bridges (device IDs 0x3c19, 0x3c29) as only 2.5 GT/s, despite the upstream bus supporting speeds from 2.5 GT/s up to 16 GT/s. As a result, since commit 774c71c ("PCI/bwctrl: Enable only if more than one speed is supported"), bwctrl will be disabled if there's only one 2.5 GT/s value in vector `supported_speeds`. Also, the amdgpu driver reads the value by pcie_get_speed_cap() in amdgpu_device_partner_bandwidth(), for its dynamic adjustment of PCIe clocks and lanes in power management. We hope this patch can prevent similar problems in future driver changes (similar checks may be implemented in other GPU, storage controller, NIC, etc. drivers). Manually override the `supported_speeds` field for affected PCIe bridges with those found on the upstream bus to correctly reflect the supported link speeds. This patch was originally found from AOSC OS[1]. Link: AOSC-Tracking#2 #1 Tested-by: Lain Fearyncess Yang <fsf@live.com> Tested-by: Ayden Meng <aydenmeng@yeah.net> Signed-off-by: Ayden Meng <aydenmeng@yeah.net> Signed-off-by: Mingcong Bai <jeffbai@aosc.io> Link: AOSC-Tracking@4392f44 [Ziyao Li: move from drivers/pci/quirks.c to drivers/pci/controller/pci-loongson.c] Signed-off-by: Ziyao Li <liziyao@uniontech.com> Tested-by: Mingcong Bai <jeffbai@aosc.io> Reviewed-by: Huacai Chen <chenhuacai@loongson.cn> [Xi Ruoyao: Fix falling through logic and add kernel log output; add Fixes tag and rebase to 7.0-rc7] Cc: stable@vger.kernel.org Fixes: cd89edd ("PCI: loongson: Add ACPI init support") Signed-off-by: Xi Ruoyao <xry111@xry111.site> Link: https://lore.kernel.org/loongarch/20260412101731.107059-1-xry111@xry111.site/ Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
1 parent 772c938 commit ae32b8e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

drivers/pci/controller/pci-loongson.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,42 @@ static void loongson_pci_msi_quirk(struct pci_dev *dev)
176176
}
177177
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON, DEV_LS7A_PCIE_PORT5, loongson_pci_msi_quirk);
178178

179+
/*
180+
* Older steppings of the Loongson-3C6000 series incorrectly report the
181+
* supported link speeds on their PCIe bridges (device IDs 0x3c19,
182+
* 0x3c29) as only 2.5 GT/s, despite the upstream bus supporting speeds
183+
* from 2.5 GT/s up to 16 GT/s.
184+
*/
185+
static void loongson_pci_bridge_speed_quirk(struct pci_dev *pdev)
186+
{
187+
u8 old_supported_speeds = pdev->supported_speeds;
188+
189+
switch (pdev->bus->max_bus_speed) {
190+
case PCIE_SPEED_16_0GT:
191+
pdev->supported_speeds |= PCI_EXP_LNKCAP2_SLS_16_0GB;
192+
fallthrough;
193+
case PCIE_SPEED_8_0GT:
194+
pdev->supported_speeds |= PCI_EXP_LNKCAP2_SLS_8_0GB;
195+
fallthrough;
196+
case PCIE_SPEED_5_0GT:
197+
pdev->supported_speeds |= PCI_EXP_LNKCAP2_SLS_5_0GB;
198+
fallthrough;
199+
case PCIE_SPEED_2_5GT:
200+
pdev->supported_speeds |= PCI_EXP_LNKCAP2_SLS_2_5GB;
201+
break;
202+
default:
203+
pci_warn(pdev, "unexpected max bus speed");
204+
205+
return;
206+
}
207+
208+
if (pdev->supported_speeds != old_supported_speeds)
209+
pci_info(pdev, "fixing up supported link speeds: 0x%x => 0x%x",
210+
old_supported_speeds, pdev->supported_speeds);
211+
}
212+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LOONGSON, 0x3c19, loongson_pci_bridge_speed_quirk);
213+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LOONGSON, 0x3c29, loongson_pci_bridge_speed_quirk);
214+
179215
static struct loongson_pci *pci_bus_to_loongson_pci(struct pci_bus *bus)
180216
{
181217
struct pci_config_window *cfg;

0 commit comments

Comments
 (0)