Search Linux Wireless

Re: [PATCH v2 1/2] wifi: brcmfmac: add support for TRX firmware download

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/9/2024 10:31 PM, Marek Vasut wrote:
From: Chung-Hsien Hsu <stanley.hsu@xxxxxxxxxxx>

Add support to download TRX firmware for PCIe and SDIO.

Reviewed-by: Arend van Spriel <arend.vanspriel@xxxxxxxxxxxx>
Signed-off-by: Chung-Hsien Hsu <stanley.hsu@xxxxxxxxxxx>

The sob tag is a certification by that person so strictly speaking you can not add this line. Don't know what is best here. I will leave it to Kalle to decide.

Signed-off-by: Chung-Hsien Hsu <chung-hsien.hsu@xxxxxxxxxxxx>
Signed-off-by: Marek Vasut <marex@xxxxxxx> # Upport to current linux-next
---
NOTE: This is downstream upport from
       https://github.com/Infineon/ifx-wireless-drivers/
       branch RTM/v5.15.58-Indrik / tag release-v5.15.58-2024_0514
- ba34bf4816f9 ("brcmfmac: add support for TRX firmware download")
---
Cc: "Dr. David Alan Gilbert" <linux@xxxxxxxxxxx>
Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
Cc: "Rafał Miłecki" <zajec5@xxxxxxxxx>
Cc: Arend van Spriel <arend.vanspriel@xxxxxxxxxxxx>
Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Cc: Carter Chen <carter.chen@xxxxxxxxxxxx>
Cc: Chung-Hsien Hsu <stanley.hsu@xxxxxxxxxxx>
Cc: Double Lo <Double.Lo@xxxxxxxxxxxx>
Cc: Duoming Zhou <duoming@xxxxxxxxxx>
Cc: Erick Archer <erick.archer@xxxxxxxxxxx>
Cc: Kalle Valo <kvalo@xxxxxxxxxx>
Cc: Kees Cook <kees@xxxxxxxxxx>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
Cc: Mathias Krause <minipli@xxxxxxxxxxxxxx>
Cc: Matthias Brugger <mbrugger@xxxxxxxx>
Cc: Owen Huang <Owen.Huang@xxxxxxxxxxxx>
Cc: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
Cc: brcm80211-dev-list.pdl@xxxxxxxxxxxx
Cc: brcm80211@xxxxxxxxxxxxxxx
Cc: linux-wireless@xxxxxxxxxxxxxxx
---
V2: Include SoB line from Chung-Hsien with both cypress and infineon address
---
  .../broadcom/brcm80211/brcmfmac/pcie.c        | 12 +++++-
  .../broadcom/brcm80211/brcmfmac/sdio.c        | 20 +++++++---
  .../broadcom/brcm80211/brcmfmac/trxhdr.h      | 38 +++++++++++++++++++
  3 files changed, 63 insertions(+), 7 deletions(-)
  create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/trxhdr.h

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index ce482a3877e90..058a742d17eda 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -42,6 +42,7 @@
  #include "chip.h"
  #include "core.h"
  #include "common.h"
+#include "trxhdr.h"

Maybe the definitions can simply be put in firmware.h as it is closely related.

enum brcmf_pcie_state {
@@ -1684,6 +1685,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
  					u32 nvram_len)
  {
  	struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev);
+	struct trx_header_le *trx = (struct trx_header_le *)fw->data;
+	u32 fw_size;
  	u32 sharedram_addr;
  	u32 sharedram_addr_written;
  	u32 loop_counter;
@@ -1697,8 +1700,13 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
  		return err;
brcmf_dbg(PCIE, "Download FW %s\n", devinfo->fw_name);
-	memcpy_toio(devinfo->tcm + devinfo->ci->rambase,
-		    (void *)fw->data, fw->size);
+	address = devinfo->ci->rambase;
+	fw_size = fw->size;
+	if (trx->magic == cpu_to_le32(TRX_MAGIC)) {
+		address -= sizeof(struct trx_header_le);
+		fw_size = le32_to_cpu(trx->len);

trx->len needs to be validated against fw->size and return an error, eg. -EINVAL, if it fails.

+	}
+	memcpy_toio(devinfo->tcm + address, (void *)fw->data, fw_size);
resetintr = get_unaligned_le32(fw->data);
  	release_firmware(fw);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 1461dc453ac22..08881e366cae2 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -35,6 +35,7 @@
  #include "core.h"
  #include "common.h"
  #include "bcdc.h"
+#include "trxhdr.h"
#define DCMD_RESP_TIMEOUT msecs_to_jiffies(2500)
  #define CTL_DONE_TIMEOUT	msecs_to_jiffies(2500)
@@ -3346,17 +3347,26 @@ brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr,
  static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus,
  					 const struct firmware *fw)
  {
+	struct trx_header_le *trx = (struct trx_header_le *)fw->data;
+	u32 fw_size;
+	u32 address;
  	int err;
brcmf_dbg(TRACE, "Enter\n"); - err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase,
-				(u8 *)fw->data, fw->size);
+	address = bus->ci->rambase;
+	fw_size = fw->size;
+	if (trx->magic == cpu_to_le32(TRX_MAGIC)) {
+		address -= sizeof(struct trx_header_le);
+		fw_size = le32_to_cpu(trx->len);

same here.

+	}
+	err = brcmf_sdiod_ramrw(bus->sdiodev, true, address,
+				(u8 *)fw->data, fw_size);
  	if (err)
  		brcmf_err("error %d on writing %d membytes at 0x%08x\n",
-			  err, (int)fw->size, bus->ci->rambase);
-	else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase,
-					  (u8 *)fw->data, fw->size))
+			  err, (int)fw_size, address);
+	else if (!brcmf_sdio_verifymemory(bus->sdiodev, address,
+					  (u8 *)fw->data, fw_size))
  		err = -EIO;
return err;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/trxhdr.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/trxhdr.h
new file mode 100644
index 0000000000000..0411c7c7ffb99
--- /dev/null
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/trxhdr.h
@@ -0,0 +1,38 @@

[...]

+struct trx_header_le {
+	__le32 magic;		/* "HDR0" */
+	__le32 len;		/* Length of file including header */
+	__le32 crc32;		/* CRC from flag_version to end of file */
+	__le32 flag_version;	/* 0:15 flags, 16:31 version */

Let's make this two separate __le16 fields as the comment does.

+	__le32 offsets[TRX_MAX_OFFSET];	/* Offsets of partitions */
+};
+
+#endif /* BRCMFMAC_TRXHDR_H */





[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux