1 From 4e32024cbb14230af3048e249e84f8c2b25ce45a Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Thu, 28 Oct 2021 15:03:16 +0100
4 Subject: [PATCH] brcmfmac: Read alternative firmware names from DT
6 Add the ability to load the names of alternative firmwares from the
7 Device Tree node. This permits separate firmwares for 43436s and 43438
8 and allows downstream firmwares to coexist with upstream.
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
12 .../wireless/broadcom/brcm80211/brcmfmac/of.c | 36 ++++++++++++++
13 .../wireless/broadcom/brcm80211/brcmfmac/of.h | 7 +++
14 .../broadcom/brcm80211/brcmfmac/sdio.c | 47 +++++++++++++++++--
15 3 files changed, 87 insertions(+), 3 deletions(-)
17 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
18 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
23 +#include "firmware.h"
26 static int brcmf_of_get_country_codes(struct device *dev,
27 @@ -168,3 +169,38 @@ void brcmf_of_probe(struct device *dev,
28 sdio->oob_irq_nr = irq;
29 sdio->oob_irq_flags = irqf;
32 +struct brcmf_firmware_mapping *
33 +brcmf_of_fwnames(struct device *dev, u32 *fwname_count)
35 + struct device_node *np = dev->of_node;
36 + struct brcmf_firmware_mapping *fwnames;
37 + struct device_node *map_np, *fw_np;
41 + map_np = of_get_child_by_name(np, "firmwares");
42 + of_count = of_get_child_count(map_np);
46 + fwnames = devm_kcalloc(dev, of_count,
47 + sizeof(struct brcmf_firmware_mapping),
50 + for_each_child_of_node(map_np, fw_np)
52 + struct brcmf_firmware_mapping *cur = &fwnames[count];
54 + if (of_property_read_u32(fw_np, "chipid", &cur->chipid) ||
55 + of_property_read_u32(fw_np, "revmask", &cur->revmask))
57 + cur->fw_base = of_get_property(fw_np, "fw_base", NULL);
62 + *fwname_count = count;
64 + return count ? fwnames : NULL;
66 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.h
67 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.h
70 void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
71 struct brcmf_mp_device *settings);
72 +#ifdef CPTCFG_BRCMFMAC_SDIO
73 +struct brcmf_firmware_mapping *
74 +brcmf_of_fwnames(struct device *dev, u32 *map_count);
77 static void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
78 struct brcmf_mp_device *settings)
81 +#ifdef CPTCFG_BRCMFMAC_SDIO
82 +static struct brcmf_firmware_mapping *
83 +brcmf_of_fwnames(struct device *dev, u32 *map_count)
88 #endif /* CONFIG_OF */
89 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
90 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
97 #define DCMD_RESP_TIMEOUT msecs_to_jiffies(2500)
98 #define CTL_DONE_TIMEOUT msecs_to_jiffies(2500)
99 @@ -634,7 +635,7 @@ MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "b
100 /* per-board firmware binaries */
101 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.bin");
103 -static const struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = {
104 +static const struct brcmf_firmware_mapping sdio_fwnames[] = {
105 BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, 43143),
106 BRCMF_FW_ENTRY(BRCM_CC_43241_CHIP_ID, 0x0000001F, 43241B0),
107 BRCMF_FW_ENTRY(BRCM_CC_43241_CHIP_ID, 0x00000020, 43241B4),
108 @@ -662,6 +663,9 @@ static const struct brcmf_firmware_mappi
109 BRCMF_FW_ENTRY(CY_CC_43752_CHIP_ID, 0xFFFFFFFF, 43752)
112 +static const struct brcmf_firmware_mapping *brcmf_sdio_fwnames = sdio_fwnames;
113 +static u32 brcmf_sdio_fwnames_count = ARRAY_SIZE(sdio_fwnames);
115 #define TXCTL_CREDITS 2
117 static void pkt_align(struct sk_buff *p, int len, int align)
118 @@ -4193,6 +4197,9 @@ static const struct brcmf_bus_ops brcmf_
119 #define BRCMF_SDIO_FW_NVRAM 1
120 #define BRCMF_SDIO_FW_CLM 2
122 +static struct brcmf_fw_request *
123 +brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus);
125 static void brcmf_sdio_firmware_callback(struct device *dev, int err,
126 struct brcmf_fw_request *fwreq)
128 @@ -4208,6 +4215,22 @@ static void brcmf_sdio_firmware_callback
130 brcmf_dbg(TRACE, "Enter: dev=%s, err=%d\n", dev_name(dev), err);
132 + if (err && brcmf_sdio_fwnames != sdio_fwnames) {
133 + /* Try again with the standard firmware names */
134 + brcmf_sdio_fwnames = sdio_fwnames;
135 + brcmf_sdio_fwnames_count = ARRAY_SIZE(sdio_fwnames);
137 + fwreq = brcmf_sdio_prepare_fw_request(bus);
142 + err = brcmf_fw_get_firmwares(dev, fwreq,
143 + brcmf_sdio_firmware_callback);
151 @@ -4418,7 +4441,7 @@ brcmf_sdio_prepare_fw_request(struct brc
153 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev,
155 - ARRAY_SIZE(brcmf_sdio_fwnames),
156 + brcmf_sdio_fwnames_count,
157 fwnames, ARRAY_SIZE(fwnames));
160 @@ -4438,6 +4461,9 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
161 struct brcmf_sdio *bus;
162 struct workqueue_struct *wq;
163 struct brcmf_fw_request *fwreq;
164 + struct brcmf_firmware_mapping *of_fwnames, *fwnames = NULL;
165 + const int fwname_size = sizeof(struct brcmf_firmware_mapping);
168 brcmf_dbg(TRACE, "Enter\n");
170 @@ -4520,6 +4546,21 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
172 brcmf_dbg(INFO, "completed!!\n");
174 + of_fwnames = brcmf_of_fwnames(sdiodev->dev, &of_fw_count);
176 + fwnames = devm_kcalloc(sdiodev->dev,
177 + of_fw_count + brcmf_sdio_fwnames_count,
178 + fwname_size, GFP_KERNEL);
181 + /* The array is scanned in order, so overrides come first */
182 + memcpy(fwnames, of_fwnames, of_fw_count * fwname_size);
183 + memcpy(fwnames + of_fw_count, sdio_fwnames,
184 + brcmf_sdio_fwnames_count * fwname_size);
185 + brcmf_sdio_fwnames = fwnames;
186 + brcmf_sdio_fwnames_count += of_fw_count;
189 fwreq = brcmf_sdio_prepare_fw_request(bus);