diff mbox series

[RFT,v2] wifi: brcmfmac: add flag for random seed during firmware download

Message ID 20240728193904.35820-1-arend.vanspriel@broadcom.com
State Superseded
Headers show
Series [RFT,v2] wifi: brcmfmac: add flag for random seed during firmware download | expand

Commit Message

Arend van Spriel July 28, 2024, 7:39 p.m. UTC
Providing the random seed to firmware was tied to the fact that the
device has a valid OTP, which worked for some Apple chips. However,
it turns out the BCM43752 device also needs the random seed in order
to get firmware running. Suspect it is simply tied to the firmware
branch used for the device. Introducing a mechanism to allow setting
it for a device through the device table.

Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
---
V2:
 - fix the patch so it compiles :-(

Hi Jacobe,

Here is a quick patch introducing driver data table with the flag for the
random seed. So for the 43752 you would add:

@@ -2710,6 +2712,7 @@ static const struct pci_device_id
brcmf_pcie_devid_table[] = {
 BRCMF_PCIE_DEVICE(BRCM_PCIE_4366_5G_DEVICE_ID, BCA),
 BRCMF_PCIE_DEVICE(BRCM_PCIE_4371_DEVICE_ID, WCC),
 BRCMF_PCIE_DEVICE(BRCM_PCIE_43596_DEVICE_ID, CYW),
+ BRCMF_PCIE_DEVICE(BRCM_PCIE_43752_DEVICE_ID, WCC_SEED),
 BRCMF_PCIE_DEVICE(BRCM_PCIE_4377_DEVICE_ID, WCC_SEED),
 BRCMF_PCIE_DEVICE(BRCM_PCIE_4378_DEVICE_ID, WCC_SEED),
 BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC_SEED),

Please test if this works for you. If functional you may add this patch as
is in your series. Would also like to hear from the Apple chip users if this
approach works for them as well.

Regards,
Arend
---
 .../broadcom/brcm80211/brcmfmac/pcie.c        | 49 ++++++++++++++++---
 1 file changed, 41 insertions(+), 8 deletions(-)


base-commit: 338a93cf4a18c2036b567e9f613367f7a52f2511

Comments

Jacobe Zang July 29, 2024, 6:17 a.m. UTC | #1
Hi Arend, 
Thanks for your patch. It works well.

> +enum {
> +       BRCMF_DRVDATA_CYW,
> +       BRCMF_DRVDATA_BCA,
> +       BRCMF_DRVDATA_WCC,
> +       BRCMF_DRVDATA_WCC_SEED,
> +};

I found that in drivers/net/wirless/broadcom/brcm80211/brcmfmac/bus.h has already prepared an enumeration like these.
enum brcmf_fwvendor {
	BRCMF_FWVENDOR_WCC,
	BRCMF_FWVENDOR_CYW,
	BRCMF_FWVENDOR_BCA,
	/* keep last */
	BRCMF_FWVENDOR_NUM,
	BRCMF_FWVENDOR_INVALID
};
So should we delete them? Because you also changed BRCMF_FWVENDOR_ to BRCMF_DRVDATA_

---
Best Regards
Jacobe
Jacobe Zang July 29, 2024, 6:25 a.m. UTC | #2
> I found that in drivers/net/wirless/broadcom/brcm80211/brcmfmac/bus.h has already prepared an > enumeration like these.
> enum brcmf_fwvendor {
>         BRCMF_FWVENDOR_WCC,
>         BRCMF_FWVENDOR_CYW,
>         BRCMF_FWVENDOR_BCA,
>         /* keep last */
>         BRCMF_FWVENDOR_NUM,
>         BRCMF_FWVENDOR_INVALID
> };
> So should we delete them? Because you also changed BRCMF_FWVENDOR_ to BRCMF_DRVDATA_

Sorry, please ignore this comment, I didn't notice these were two enums with different purposes

---
Best Regards
Jacobe
Arend van Spriel July 29, 2024, 8:05 a.m. UTC | #3
On 7/29/2024 8:25 AM, Jacobe Zang wrote:
>> I found that in drivers/net/wirless/broadcom/brcm80211/brcmfmac/bus.h has already prepared an > enumeration like these.
>> enum brcmf_fwvendor {
>>          BRCMF_FWVENDOR_WCC,
>>          BRCMF_FWVENDOR_CYW,
>>          BRCMF_FWVENDOR_BCA,
>>          /* keep last */
>>          BRCMF_FWVENDOR_NUM,
>>          BRCMF_FWVENDOR_INVALID
>> };
>> So should we delete them? Because you also changed BRCMF_FWVENDOR_ to BRCMF_DRVDATA_
> 
> Sorry, please ignore this comment, I didn't notice these were two enums with different purposes

Ignored ;-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index ce482a3877e9..e93359b20748 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -353,6 +353,7 @@  struct brcmf_pciedev_info {
 			  u16 value);
 	struct brcmf_mp_device *settings;
 	struct brcmf_otp_params otp;
+	bool fwseed;
 #ifdef DEBUG
 	u32 console_interval;
 	bool console_active;
@@ -1715,14 +1716,14 @@  static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
 		memcpy_toio(devinfo->tcm + address, nvram, nvram_len);
 		brcmf_fw_nvram_free(nvram);
 
-		if (devinfo->otp.valid) {
+		if (devinfo->fwseed) {
 			size_t rand_len = BRCMF_RANDOM_SEED_LENGTH;
 			struct brcmf_random_seed_footer footer = {
 				.length = cpu_to_le32(rand_len),
 				.magic = cpu_to_le32(BRCMF_RANDOM_SEED_MAGIC),
 			};
 
-			/* Some Apple chips/firmwares expect a buffer of random
+			/* Some chips/firmwares expect a buffer of random
 			 * data to be present before NVRAM
 			 */
 			brcmf_dbg(PCIE, "Download random seed\n");
@@ -2394,6 +2395,37 @@  static void brcmf_pcie_debugfs_create(struct device *dev)
 }
 #endif
 
+struct brcmf_pcie_drvdata {
+	enum brcmf_fwvendor vendor;
+	bool fw_seed;
+};
+
+enum {
+	BRCMF_DRVDATA_CYW,
+	BRCMF_DRVDATA_BCA,
+	BRCMF_DRVDATA_WCC,
+	BRCMF_DRVDATA_WCC_SEED,
+};
+
+static const struct brcmf_pcie_drvdata drvdata[] = {
+	[BRCMF_DRVDATA_CYW] = {
+		.vendor = BRCMF_FWVENDOR_CYW,
+		.fw_seed = false,
+	},
+	[BRCMF_DRVDATA_BCA] = {
+		.vendor = BRCMF_FWVENDOR_BCA,
+		.fw_seed = false,
+	},
+	[BRCMF_DRVDATA_WCC] = {
+		.vendor = BRCMF_FWVENDOR_WCC,
+		.fw_seed = false,
+	},
+	[BRCMF_DRVDATA_WCC_SEED] = {
+		.vendor = BRCMF_FWVENDOR_WCC,
+		.fw_seed = true,
+	},
+};
+
 /* Forward declaration for pci_match_id() call */
 static const struct pci_device_id brcmf_pcie_devid_table[];
 
@@ -2472,9 +2504,10 @@  brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	bus->bus_priv.pcie = pcie_bus_dev;
 	bus->ops = &brcmf_pcie_bus_ops;
 	bus->proto_type = BRCMF_PROTO_MSGBUF;
-	bus->fwvid = id->driver_data;
 	bus->chip = devinfo->coreid;
 	bus->wowl_supported = pci_pme_capable(pdev, PCI_D3hot);
+	bus->fwvid = drvdata[id->driver_data].vendor;
+	devinfo->fwseed = drvdata[id->driver_data].fw_seed;
 	dev_set_drvdata(&pdev->dev, bus);
 
 	ret = brcmf_alloc(&devinfo->pdev->dev, devinfo->settings);
@@ -2660,14 +2693,14 @@  static const struct dev_pm_ops brcmf_pciedrvr_pm = {
 		BRCM_PCIE_VENDOR_ID_BROADCOM, (dev_id), \
 		PCI_ANY_ID, PCI_ANY_ID, \
 		PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, \
-		BRCMF_FWVENDOR_ ## fw_vend \
+		BRCMF_DRVDATA_ ## fw_vend \
 	}
 #define BRCMF_PCIE_DEVICE_SUB(dev_id, subvend, subdev, fw_vend) \
 	{ \
 		BRCM_PCIE_VENDOR_ID_BROADCOM, (dev_id), \
 		(subvend), (subdev), \
 		PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, \
-		BRCMF_FWVENDOR_ ## fw_vend \
+		BRCMF_DRVDATA_ ## fw_vend \
 	}
 
 static const struct pci_device_id brcmf_pcie_devid_table[] = {
@@ -2695,9 +2728,9 @@  static const struct pci_device_id brcmf_pcie_devid_table[] = {
 	BRCMF_PCIE_DEVICE(BRCM_PCIE_4366_5G_DEVICE_ID, BCA),
 	BRCMF_PCIE_DEVICE(BRCM_PCIE_4371_DEVICE_ID, WCC),
 	BRCMF_PCIE_DEVICE(BRCM_PCIE_43596_DEVICE_ID, CYW),
-	BRCMF_PCIE_DEVICE(BRCM_PCIE_4377_DEVICE_ID, WCC),
-	BRCMF_PCIE_DEVICE(BRCM_PCIE_4378_DEVICE_ID, WCC),
-	BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC),
+	BRCMF_PCIE_DEVICE(BRCM_PCIE_4377_DEVICE_ID, WCC_SEED),
+	BRCMF_PCIE_DEVICE(BRCM_PCIE_4378_DEVICE_ID, WCC_SEED),
+	BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC_SEED),
 
 	{ /* end: all zeroes */ }
 };