22e26e7698571b1e7e8b57f863b69eef26b9478e
[openwrt/staging/svanheule.git] / package / kernel / mac80211 / patches / brcm / 865-brcmfmac-Read-alternative-firmware-names-from-DT.patch
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
5
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.
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 ---
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(-)
16
17 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
18 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
19 @@ -11,6 +11,7 @@
20 #include "debug.h"
21 #include "core.h"
22 #include "common.h"
23 +#include "firmware.h"
24 #include "of.h"
25
26 static int brcmf_of_get_country_codes(struct device *dev,
27 @@ -175,3 +176,38 @@ void brcmf_of_probe(struct device *dev,
28 sdio->oob_irq_nr = irq;
29 sdio->oob_irq_flags = irqf;
30 }
31 +
32 +struct brcmf_firmware_mapping *
33 +brcmf_of_fwnames(struct device *dev, u32 *fwname_count)
34 +{
35 + struct device_node *np = dev->of_node;
36 + struct brcmf_firmware_mapping *fwnames;
37 + struct device_node *map_np, *fw_np;
38 + int of_count;
39 + int count = 0;
40 +
41 + map_np = of_get_child_by_name(np, "firmwares");
42 + of_count = of_get_child_count(map_np);
43 + if (!of_count)
44 + return NULL;
45 +
46 + fwnames = devm_kcalloc(dev, of_count,
47 + sizeof(struct brcmf_firmware_mapping),
48 + GFP_KERNEL);
49 +
50 + for_each_child_of_node(map_np, fw_np)
51 + {
52 + struct brcmf_firmware_mapping *cur = &fwnames[count];
53 +
54 + if (of_property_read_u32(fw_np, "chipid", &cur->chipid) ||
55 + of_property_read_u32(fw_np, "revmask", &cur->revmask))
56 + continue;
57 + cur->fw_base = of_get_property(fw_np, "fw_base", NULL);
58 + if (cur->fw_base)
59 + count++;
60 + }
61 +
62 + *fwname_count = count;
63 +
64 + return count ? fwnames : NULL;
65 +}
66 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.h
67 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.h
68 @@ -5,9 +5,20 @@
69 #ifdef CONFIG_OF
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);
75 +#endif
76 #else
77 static void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
78 struct brcmf_mp_device *settings)
79 {
80 }
81 +#ifdef CPTCFG_BRCMFMAC_SDIO
82 +static struct brcmf_firmware_mapping *
83 +brcmf_of_fwnames(struct device *dev, u32 *map_count)
84 +{
85 + return NULL;
86 +}
87 +#endif
88 #endif /* CONFIG_OF */
89 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
90 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
91 @@ -35,6 +35,7 @@
92 #include "core.h"
93 #include "common.h"
94 #include "bcdc.h"
95 +#include "of.h"
96
97 #define DCMD_RESP_TIMEOUT msecs_to_jiffies(2500)
98 #define CTL_DONE_TIMEOUT msecs_to_jiffies(2500)
99 @@ -632,7 +633,7 @@ MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "b
100 /* per-board firmware binaries */
101 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.bin");
102
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 @@ -660,6 +661,9 @@ static const struct brcmf_firmware_mappi
109 BRCMF_FW_ENTRY(CY_CC_43752_CHIP_ID, 0xFFFFFFFF, 43752)
110 };
111
112 +static const struct brcmf_firmware_mapping *brcmf_sdio_fwnames = sdio_fwnames;
113 +static u32 brcmf_sdio_fwnames_count = ARRAY_SIZE(sdio_fwnames);
114 +
115 #define TXCTL_CREDITS 2
116
117 static void pkt_align(struct sk_buff *p, int len, int align)
118 @@ -4201,6 +4205,9 @@ static const struct brcmf_bus_ops brcmf_
119 #define BRCMF_SDIO_FW_NVRAM 1
120 #define BRCMF_SDIO_FW_CLM 2
121
122 +static struct brcmf_fw_request *
123 +brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus);
124 +
125 static void brcmf_sdio_firmware_callback(struct device *dev, int err,
126 struct brcmf_fw_request *fwreq)
127 {
128 @@ -4216,6 +4223,22 @@ static void brcmf_sdio_firmware_callback
129
130 brcmf_dbg(TRACE, "Enter: dev=%s, err=%d\n", dev_name(dev), err);
131
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);
136 + kfree(fwreq);
137 + fwreq = brcmf_sdio_prepare_fw_request(bus);
138 + if (!fwreq) {
139 + err = -ENOMEM;
140 + goto fail;
141 + }
142 + err = brcmf_fw_get_firmwares(dev, fwreq,
143 + brcmf_sdio_firmware_callback);
144 + if (!err)
145 + return;
146 + }
147 +
148 if (err)
149 goto fail;
150
151 @@ -4426,7 +4449,7 @@ brcmf_sdio_prepare_fw_request(struct brc
152
153 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev,
154 brcmf_sdio_fwnames,
155 - ARRAY_SIZE(brcmf_sdio_fwnames),
156 + brcmf_sdio_fwnames_count,
157 fwnames, ARRAY_SIZE(fwnames));
158 if (!fwreq)
159 return NULL;
160 @@ -4446,6 +4469,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);
166 + u32 of_fw_count;
167
168 brcmf_dbg(TRACE, "Enter\n");
169
170 @@ -4528,6 +4554,21 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
171
172 brcmf_dbg(INFO, "completed!!\n");
173
174 + of_fwnames = brcmf_of_fwnames(sdiodev->dev, &of_fw_count);
175 + if (of_fwnames)
176 + fwnames = devm_kcalloc(sdiodev->dev,
177 + of_fw_count + brcmf_sdio_fwnames_count,
178 + fwname_size, GFP_KERNEL);
179 +
180 + if (fwnames) {
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;
187 + }
188 +
189 fwreq = brcmf_sdio_prepare_fw_request(bus);
190 if (!fwreq) {
191 ret = -ENOMEM;