From patchwork Mon Sep 9 20:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 827327 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DD6617D8A9 for ; Mon, 9 Sep 2024 20:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725913914; cv=none; b=nB0jsKHNuloPChLZ1i+chiCicahS2M64FHN9f7V+sH9m4IydXlCw4x2xiKfk6/GORsO2Dc51oe5zvZcJ5lmTdWHj6qTnkM3RxXK5CRio1stcxIsRvLmRZgbv9YE+aeSdqayq0Xi2itlVbDk0zumhn40ls3m+aBVQryLE1gPqz/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725913914; c=relaxed/simple; bh=6kwBrf6cnR4u9VGNPHFz4LIjfe3hSI/PPkDiRahVRbI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AmrBaRduYVnWLKEzZzHbrsA1ts9lXk3HujLSJwCG7DHWTDrBXtYKwIx+Ks/qt0tvE1LM5cFVjil1hvgjF/RhC5PS9vzR9tMhGXaXLp8pnMq0smqsKBdf97DuUH2S4gtWyQ9QQ2K9ojuRdO4h46oj5FJtPdhot+CcqEE07XputVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=DXlqVzkg; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="DXlqVzkg" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 043FB88972; Mon, 9 Sep 2024 22:31:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1725913910; bh=zRssSffz0RBd4v+doVhdCvIu+HD1AodBYL7gqi2sMHg=; h=From:To:Cc:Subject:Date:From; b=DXlqVzkg/sjEryu9sWoxfeDa1BCKBCpvTGVpMm6MwGvdNmCNSrCBxqPX6j1l8LJTl 8Pmw7U20FnXKKhrXluqxu74JQUSAX3abozikLftWCzgFkduxTMTuRaMKiA6LnzhAwG 1Mqb+95mP1SqSTwAv9TmQP5S5jWwvtAroSHDjcDv4eNm39Eqf9qVJ/92u41NioF4+Z aqIcv4rDMoRqRa49Z/gqe0hWRHHO0jrRNrSNM0/7Q9FSd68ViZn4lBYDoe657M9Xak zicpMqGzW1pceyIa0RY3tWDurz/gYTZKa2OCAulDhzM6p7Bg9PcNmJrV+5fMzegFpC HPtDZE7770/yA== From: Marek Vasut To: linux-wireless@vger.kernel.org Cc: Chung-Hsien Hsu , Chung-Hsien Hsu , Marek Vasut , "Dr. David Alan Gilbert" , "Gustavo A. R. Silva" , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , Arend van Spriel , Bjorn Helgaas , Carter Chen , Double Lo , Duoming Zhou , Erick Archer , Kalle Valo , Kees Cook , Krzysztof Kozlowski , Mathias Krause , Matthias Brugger , Owen Huang , Ulf Hansson , brcm80211-dev-list.pdl@broadcom.com, brcm80211@lists.linux.dev Subject: [PATCH v2 1/2] wifi: brcmfmac: add support for TRX firmware download Date: Mon, 9 Sep 2024 22:31:28 +0200 Message-ID: <20240909203133.74777-1-marex@denx.de> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Chung-Hsien Hsu Add support to download TRX firmware for PCIe and SDIO. Signed-off-by: Chung-Hsien Hsu Signed-off-by: Chung-Hsien Hsu Signed-off-by: Marek Vasut # Upport to current linux-next Reviewed-by: Arend van Spriel --- 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" Cc: "Gustavo A. R. Silva" Cc: "Rafał Miłecki" Cc: Arend van Spriel Cc: Bjorn Helgaas Cc: Carter Chen Cc: Chung-Hsien Hsu Cc: Double Lo Cc: Duoming Zhou Cc: Erick Archer Cc: Kalle Valo Cc: Kees Cook Cc: Krzysztof Kozlowski Cc: Mathias Krause Cc: Matthias Brugger Cc: Owen Huang Cc: Ulf Hansson Cc: brcm80211-dev-list.pdl@broadcom.com Cc: brcm80211@lists.linux.dev Cc: linux-wireless@vger.kernel.org --- 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" 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); + } + 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); + } + 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 @@ +/* SPDX-License-Identifier: ISC */ +/* Copyright (c) 2020 Cypress Semiconductor Corporation */ + +#ifndef BRCMFMAC_TRXHDR_H +#define BRCMFMAC_TRXHDR_H + +/* Bootloader makes special use of trx header "offsets" array */ +enum { + TRX_OFFSET_SIGN_INFO_IDX = 0, + TRX_OFFSET_DATA_FOR_SIGN1_IDX = 1, + TRX_OFFSET_DATA_FOR_SIGN2_IDX = 2, + TRX_OFFSET_ROOT_MODULUS_IDX = 3, + TRX_OFFSET_ROOT_EXPONENT_IDX = 67, + TRX_OFFSET_CONT_MODULUS_IDX = 68, + TRX_OFFSET_CONT_EXPONENT_IDX = 132, + TRX_OFFSET_HASH_FW_IDX = 133, + TRX_OFFSET_FW_LEN_IDX = 149, + TRX_OFFSET_TR_RST_IDX = 150, + TRX_OFFSET_FW_VER_FOR_ANTIROOLBACK_IDX = 151, + TRX_OFFSET_IV_IDX = 152, + TRX_OFFSET_NONCE_IDX = 160, + TRX_OFFSET_SIGN_INFO2_IDX = 168, + TRX_OFFSET_MAX_IDX +}; + +#define TRX_MAGIC 0x30524448 /* "HDR0" */ +#define TRX_VERSION 4 /* Version 4 */ +#define TRX_MAX_OFFSET TRX_OFFSET_MAX_IDX /* Max number of file offsets */ + +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 */ + __le32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions */ +}; + +#endif /* BRCMFMAC_TRXHDR_H */