mac80211: update to v6.1.24
[openwrt/staging/dedeckeh.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 @@ -168,3 +169,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,16 @@
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 +struct brcmf_firmware_mapping *
73 +brcmf_of_fwnames(struct device *dev, u32 *map_count);
74 #else
75 static void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
76 struct brcmf_mp_device *settings)
77 {
78 }
79 +static struct brcmf_firmware_mapping *
80 +brcmf_of_fwnames(struct device *dev, u32 *map_count)
81 +{
82 + return NULL;
83 +}
84 #endif /* CONFIG_OF */
85 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
86 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
87 @@ -35,6 +35,7 @@
88 #include "core.h"
89 #include "common.h"
90 #include "bcdc.h"
91 +#include "of.h"
92
93 #define DCMD_RESP_TIMEOUT msecs_to_jiffies(2500)
94 #define CTL_DONE_TIMEOUT msecs_to_jiffies(2500)
95 @@ -634,7 +635,7 @@ MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "b
96 /* per-board firmware binaries */
97 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.bin");
98
99 -static const struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = {
100 +static const struct brcmf_firmware_mapping sdio_fwnames[] = {
101 BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, 43143),
102 BRCMF_FW_ENTRY(BRCM_CC_43241_CHIP_ID, 0x0000001F, 43241B0),
103 BRCMF_FW_ENTRY(BRCM_CC_43241_CHIP_ID, 0x00000020, 43241B4),
104 @@ -662,6 +663,9 @@ static const struct brcmf_firmware_mappi
105 BRCMF_FW_ENTRY(CY_CC_43752_CHIP_ID, 0xFFFFFFFF, 43752)
106 };
107
108 +static const struct brcmf_firmware_mapping *brcmf_sdio_fwnames = sdio_fwnames;
109 +static u32 brcmf_sdio_fwnames_count = ARRAY_SIZE(sdio_fwnames);
110 +
111 #define TXCTL_CREDITS 2
112
113 static void pkt_align(struct sk_buff *p, int len, int align)
114 @@ -4193,6 +4197,9 @@ static const struct brcmf_bus_ops brcmf_
115 #define BRCMF_SDIO_FW_NVRAM 1
116 #define BRCMF_SDIO_FW_CLM 2
117
118 +static struct brcmf_fw_request *
119 +brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus);
120 +
121 static void brcmf_sdio_firmware_callback(struct device *dev, int err,
122 struct brcmf_fw_request *fwreq)
123 {
124 @@ -4208,6 +4215,22 @@ static void brcmf_sdio_firmware_callback
125
126 brcmf_dbg(TRACE, "Enter: dev=%s, err=%d\n", dev_name(dev), err);
127
128 + if (err && brcmf_sdio_fwnames != sdio_fwnames) {
129 + /* Try again with the standard firmware names */
130 + brcmf_sdio_fwnames = sdio_fwnames;
131 + brcmf_sdio_fwnames_count = ARRAY_SIZE(sdio_fwnames);
132 + kfree(fwreq);
133 + fwreq = brcmf_sdio_prepare_fw_request(bus);
134 + if (!fwreq) {
135 + err = -ENOMEM;
136 + goto fail;
137 + }
138 + err = brcmf_fw_get_firmwares(dev, fwreq,
139 + brcmf_sdio_firmware_callback);
140 + if (!err)
141 + return;
142 + }
143 +
144 if (err)
145 goto fail;
146
147 @@ -4418,7 +4441,7 @@ brcmf_sdio_prepare_fw_request(struct brc
148
149 fwreq = brcmf_fw_alloc_request(bus->ci->chip, bus->ci->chiprev,
150 brcmf_sdio_fwnames,
151 - ARRAY_SIZE(brcmf_sdio_fwnames),
152 + brcmf_sdio_fwnames_count,
153 fwnames, ARRAY_SIZE(fwnames));
154 if (!fwreq)
155 return NULL;
156 @@ -4438,6 +4461,9 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
157 struct brcmf_sdio *bus;
158 struct workqueue_struct *wq;
159 struct brcmf_fw_request *fwreq;
160 + struct brcmf_firmware_mapping *of_fwnames, *fwnames = NULL;
161 + const int fwname_size = sizeof(struct brcmf_firmware_mapping);
162 + u32 of_fw_count;
163
164 brcmf_dbg(TRACE, "Enter\n");
165
166 @@ -4520,6 +4546,21 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
167
168 brcmf_dbg(INFO, "completed!!\n");
169
170 + of_fwnames = brcmf_of_fwnames(sdiodev->dev, &of_fw_count);
171 + if (of_fwnames)
172 + fwnames = devm_kcalloc(sdiodev->dev,
173 + of_fw_count + brcmf_sdio_fwnames_count,
174 + fwname_size, GFP_KERNEL);
175 +
176 + if (fwnames) {
177 + /* The array is scanned in order, so overrides come first */
178 + memcpy(fwnames, of_fwnames, of_fw_count * fwname_size);
179 + memcpy(fwnames + of_fw_count, sdio_fwnames,
180 + brcmf_sdio_fwnames_count * fwname_size);
181 + brcmf_sdio_fwnames = fwnames;
182 + brcmf_sdio_fwnames_count += of_fw_count;
183 + }
184 +
185 fwreq = brcmf_sdio_prepare_fw_request(bus);
186 if (!fwreq) {
187 ret = -ENOMEM;