[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vf+xcn7SJX3RaeDJC2gK0xWVgwMQ33n_988PkDcTp4LpA@mail.gmail.com>
Date: Thu, 20 Jan 2022 12:17:13 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Hector Martin <marcan@...can.st>
Cc: Kalle Valo <kvalo@...eaurora.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>,
Arend van Spriel <aspriel@...il.com>,
Franky Lin <franky.lin@...adcom.com>,
Hante Meuleman <hante.meuleman@...adcom.com>,
Chi-hsien Lin <chi-hsien.lin@...ineon.com>,
Wright Feng <wright.feng@...ineon.com>,
Dmitry Osipenko <digetx@...il.com>,
Sven Peter <sven@...npeter.dev>,
Alyssa Rosenzweig <alyssa@...enzweig.io>,
Mark Kettenis <kettenis@...nbsd.org>,
Rafał Miłecki <zajec5@...il.com>,
Pieter-Paul Giesberts <pieter-paul.giesberts@...adcom.com>,
Linus Walleij <linus.walleij@...aro.org>,
Hans de Goede <hdegoede@...hat.com>,
"John W. Linville" <linville@...driver.com>,
"brian m. carlson" <sandals@...stytoothpaste.net>,
"open list:TI WILINK WIRELES..." <linux-wireless@...r.kernel.org>,
netdev <netdev@...r.kernel.org>,
devicetree <devicetree@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
ACPI Devel Maling List <linux-acpi@...r.kernel.org>,
"open list:BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER"
<brcm80211-dev-list.pdl@...adcom.com>,
SHA-cyfmac-dev-list@...ineon.com
Subject: Re: [PATCH v3 5/9] brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev
with memcpy_toio
On Mon, Jan 17, 2022 at 4:31 PM Hector Martin <marcan@...can.st> wrote:
>
> The alignment check was wrong (e.g. & 4 instead of & 3), and the logic
> was also inefficient if the length was not a multiple of 4, since it
> would needlessly fall back to copying the entire buffer bytewise.
>
> We already have a perfectly good memcpy_toio function, so just call that
> instead of rolling our own copy logic here. brcmf_pcie_init_ringbuffers
> was already using it anyway.
My gosh, what a nice fix!
Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
> Fixes: 9e37f045d5e7 ("brcmfmac: Adding PCIe bus layer support.")
> Reviewed-by: Linus Walleij <linus.walleij@...aro.org>
> Signed-off-by: Hector Martin <marcan@...can.st>
> ---
> .../broadcom/brcm80211/brcmfmac/pcie.c | 48 ++-----------------
> 1 file changed, 4 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
> index b1ae6c41013f..c25f48db1f60 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
> @@ -12,6 +12,7 @@
> #include <linux/interrupt.h>
> #include <linux/bcma/bcma.h>
> #include <linux/sched.h>
> +#include <linux/io.h>
> #include <asm/unaligned.h>
>
> #include <soc.h>
> @@ -454,47 +455,6 @@ brcmf_pcie_write_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
> }
>
>
> -static void
> -brcmf_pcie_copy_mem_todev(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
> - void *srcaddr, u32 len)
> -{
> - void __iomem *address = devinfo->tcm + mem_offset;
> - __le32 *src32;
> - __le16 *src16;
> - u8 *src8;
> -
> - if (((ulong)address & 4) || ((ulong)srcaddr & 4) || (len & 4)) {
> - if (((ulong)address & 2) || ((ulong)srcaddr & 2) || (len & 2)) {
> - src8 = (u8 *)srcaddr;
> - while (len) {
> - iowrite8(*src8, address);
> - address++;
> - src8++;
> - len--;
> - }
> - } else {
> - len = len / 2;
> - src16 = (__le16 *)srcaddr;
> - while (len) {
> - iowrite16(le16_to_cpu(*src16), address);
> - address += 2;
> - src16++;
> - len--;
> - }
> - }
> - } else {
> - len = len / 4;
> - src32 = (__le32 *)srcaddr;
> - while (len) {
> - iowrite32(le32_to_cpu(*src32), address);
> - address += 4;
> - src32++;
> - len--;
> - }
> - }
> -}
> -
> -
> static void
> brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
> void *dstaddr, u32 len)
> @@ -1570,8 +1530,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
> return err;
>
> brcmf_dbg(PCIE, "Download FW %s\n", devinfo->fw_name);
> - brcmf_pcie_copy_mem_todev(devinfo, devinfo->ci->rambase,
> - (void *)fw->data, fw->size);
> + memcpy_toio(devinfo->tcm + devinfo->ci->rambase,
> + (void *)fw->data, fw->size);
>
> resetintr = get_unaligned_le32(fw->data);
> release_firmware(fw);
> @@ -1585,7 +1545,7 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
> brcmf_dbg(PCIE, "Download NVRAM %s\n", devinfo->nvram_name);
> address = devinfo->ci->rambase + devinfo->ci->ramsize -
> nvram_len;
> - brcmf_pcie_copy_mem_todev(devinfo, address, nvram, nvram_len);
> + memcpy_toio(devinfo->tcm + address, nvram, nvram_len);
> brcmf_fw_nvram_free(nvram);
> } else {
> brcmf_dbg(PCIE, "No matching NVRAM file found %s\n",
> --
> 2.33.0
>
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists