From cf5e5204d976be00618f809b90c9c2156657903a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A1lez=20Cabanelas?= Date: Fri, 5 Feb 2021 19:59:54 +0100 Subject: [PATCH] bcm63xx: sprom: override the PCI device ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PCI device ID detected by the wifi drivers on devices using a fallback SPROM is wrong. Currently the chipnum is used for this parameter. Most SSB based Broadcom wifi chips are 2.4 and 5GHz capable. But on devices without a physical SPROM, the only one way to detect if the device suports both bands or only the 5GHz band, is by reading the device ID from the fallback SPROM. In some devices, this may lead to a non working wifi on a 5GHz-only card, or in the best case a working 2.4GHz-only in a dual band wifi card. The offset for the deviceid in SSB SPROMs is 0x0008, whereas in BCMA is 0x0060. This is true for any SPROM version. Override the PCI device ID with the one defined at the fallback SPROM, to detect the correct wifi card model and allow using the 5GHz band if supported. The patch has been tested with the following wifi radios: BCM43222: b43: both 2.4/5GHz working brcm-wl: both 2.4/5GHz working BCM43225: b43: 2.4GHz, working brcmsmac: working brcm-wl: it lacks support BCM43217: b43: 2.4GHz, working brcmsmac: it lacks support brcm-wl: it lacks support Signed-off-by: Daniel González Cabanelas Signed-off-by: Álvaro Fernández Rojas Backported from a0e0e621ca --- ...CM63XX-fallback-sprom-override-devid.patch | 78 +++++++++++++++++++ .../801-ssb_export_fallback_sprom.patch | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 target/linux/brcm63xx/patches-4.14/366-MIPS-BCM63XX-fallback-sprom-override-devid.patch diff --git a/target/linux/brcm63xx/patches-4.14/366-MIPS-BCM63XX-fallback-sprom-override-devid.patch b/target/linux/brcm63xx/patches-4.14/366-MIPS-BCM63XX-fallback-sprom-override-devid.patch new file mode 100644 index 00000000000..0587b7e33bb --- /dev/null +++ b/target/linux/brcm63xx/patches-4.14/366-MIPS-BCM63XX-fallback-sprom-override-devid.patch @@ -0,0 +1,78 @@ +--- a/arch/mips/bcm63xx/sprom.c ++++ b/arch/mips/bcm63xx/sprom.c +@@ -384,6 +384,7 @@ static __initconst u16 bcm4331_sprom[] = + struct fallback_sprom_match { + u8 pci_bus; + u8 pci_dev; ++ int override_devid; + struct ssb_sprom sprom; + }; + +@@ -399,6 +400,8 @@ int bcm63xx_get_fallback_ssb_sprom(struc + fallback_sprom.pci_bus, fallback_sprom.pci_dev, + bus->host_pci->bus->number, + PCI_SLOT(bus->host_pci->devfn)); ++ if (fallback_sprom.override_devid) ++ bus->host_pci->device = fallback_sprom.sprom.dev_id; + memcpy(out, &fallback_sprom.sprom, sizeof(struct ssb_sprom)); + return 0; + } else { +@@ -418,6 +421,8 @@ int bcm63xx_get_fallback_bcma_sprom(stru + fallback_sprom.pci_bus, fallback_sprom.pci_dev, + bus->host_pci->bus->number, + PCI_SLOT(bus->host_pci->devfn)); ++ if (fallback_sprom.override_devid) ++ bus->host_pci->device = fallback_sprom.sprom.dev_id; + memcpy(out, &fallback_sprom.sprom, sizeof(struct ssb_sprom)); + return 0; + } else { +@@ -901,6 +906,37 @@ static int sprom_extract(struct ssb_spro + return 0; + } + ++int sprom_override_devid(struct fallback_sprom_data *data, ++ struct ssb_sprom *out, const u16 *in) ++{ ++ switch (data->type) { ++#if defined(CONFIG_SSB_PCIHOST) ++ case SPROM_BCM4306: ++ case SPROM_BCM4318: ++ case SPROM_BCM4321: ++ case SPROM_BCM4322: ++ case SPROM_BCM43222: ++ SPEX(dev_id, SSB_SPROM1_PID, 0xFFFF, 0); ++ return !!out->dev_id; ++#endif /* CONFIG_SSB_PCIHOST */ ++#if defined(CONFIG_BCMA_HOST_PCI) ++ case SPROM_BCM4313: ++ case SPROM_BCM43131: ++ case SPROM_BCM43217: ++ case SPROM_BCM43225: ++ case SPROM_BCM43227: ++ case SPROM_BCM43228: ++ case SPROM_BCM4331: ++ SPEX(dev_id, 0x0060, 0xFFFF, 0); ++ return !!out->dev_id; ++#endif /* CONFIG_BCMA_HOST_PCI */ ++ case SPROM_DEFAULT: ++ return 0; ++ } ++ ++ return 0; ++} ++ + void sprom_apply_fixups(u16 *sprom, struct sprom_fixup *fixups, int n) + { + unsigned int i; +@@ -992,6 +1028,11 @@ int __init bcm63xx_register_fallback_spr + data->num_board_fixups); + + sprom_extract(&fallback_sprom.sprom, template_sprom, size); ++ ++ fallback_sprom.override_devid = ++ sprom_override_devid(data, &fallback_sprom.sprom, template_sprom); ++ } else { ++ fallback_sprom.override_devid = 0; + } + + memcpy(fallback_sprom.sprom.il0mac, data->mac_addr, ETH_ALEN); diff --git a/target/linux/brcm63xx/patches-4.14/801-ssb_export_fallback_sprom.patch b/target/linux/brcm63xx/patches-4.14/801-ssb_export_fallback_sprom.patch index 11a83536b78..6e4e05a63b6 100644 --- a/target/linux/brcm63xx/patches-4.14/801-ssb_export_fallback_sprom.patch +++ b/target/linux/brcm63xx/patches-4.14/801-ssb_export_fallback_sprom.patch @@ -8,7 +8,7 @@ #include #include #include -@@ -387,7 +388,19 @@ struct fallback_sprom_match { +@@ -388,7 +389,19 @@ struct fallback_sprom_match { struct ssb_sprom sprom; };