All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Hector Martin <marcan@marcan.st>
Cc: "Kalle Valo" <kvalo@codeaurora.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Len Brown" <lenb@kernel.org>,
	"Arend van Spriel" <aspriel@gmail.com>,
	"Franky Lin" <franky.lin@broadcom.com>,
	"Hante Meuleman" <hante.meuleman@broadcom.com>,
	"Chi-hsien Lin" <chi-hsien.lin@infineon.com>,
	"Wright Feng" <wright.feng@infineon.com>,
	"Dmitry Osipenko" <digetx@gmail.com>,
	"Sven Peter" <sven@svenpeter.dev>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	"Mark Kettenis" <kettenis@openbsd.org>,
	"Rafał Miłecki" <zajec5@gmail.com>,
	"Pieter-Paul Giesberts" <pieter-paul.giesberts@broadcom.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"John W. Linville" <linville@tuxdriver.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	"open list:TI WILINK WIRELES..." <linux-wireless@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"ACPI Devel Maling List" <linux-acpi@vger.kernel.org>,
	"open list:BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER"
	<brcm80211-dev-list.pdl@broadcom.com>,
	SHA-cyfmac-dev-list@infineon.com
Subject: Re: [PATCH v3 5/9] brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio
Date: Thu, 20 Jan 2022 12:17:13 +0200	[thread overview]
Message-ID: <CAHp75Vf+xcn7SJX3RaeDJC2gK0xWVgwMQ33n_988PkDcTp4LpA@mail.gmail.com> (raw)
In-Reply-To: <20220117142919.207370-6-marcan@marcan.st>

On Mon, Jan 17, 2022 at 4:31 PM Hector Martin <marcan@marcan.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@gmail.com>

> Fixes: 9e37f045d5e7 ("brcmfmac: Adding PCIe bus layer support.")
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Hector Martin <marcan@marcan.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

  parent reply	other threads:[~2022-01-20 10:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 14:29 [PATCH v3 0/9] misc brcmfmac fixes (M1/T2 series spin-off) Hector Martin
2022-01-17 14:29 ` [PATCH v3 1/9] brcmfmac: pcie: Release firmwares in the brcmf_pcie_setup error path Hector Martin
2022-01-19 12:34   ` Arend van Spriel
2022-01-19 17:49   ` Andy Shevchenko
2022-01-19 21:22     ` Dmitry Osipenko
2022-01-19 21:31       ` Andy Shevchenko
2022-01-20 13:15         ` Dmitry Osipenko
2022-01-20  8:22     ` Arend van Spriel
2022-01-17 14:29 ` [PATCH v3 2/9] brcmfmac: firmware: Allocate space for default boardrev in nvram Hector Martin
2022-01-19 12:34   ` Arend van Spriel
2022-01-19 21:35   ` Andy Shevchenko
2022-01-20  6:08     ` Hector Martin
2022-01-17 14:29 ` [PATCH v3 3/9] brcmfmac: firmware: Do not crash on a NULL board_type Hector Martin
2022-01-19 12:34   ` Arend van Spriel
2022-01-19 21:45   ` Andy Shevchenko
2022-01-20  6:13     ` Hector Martin
2022-01-19 22:02   ` Dmitry Osipenko
2022-01-20  8:29     ` Arend van Spriel
2022-01-20 13:23       ` Dmitry Osipenko
2022-01-20 13:24         ` Dmitry Osipenko
2022-01-20 13:37           ` Arend van Spriel
2022-01-17 14:29 ` [PATCH v3 4/9] brcmfmac: pcie: Declare missing firmware files in pcie.c Hector Martin
2022-01-17 14:29 ` [PATCH v3 5/9] brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio Hector Martin
2022-01-19 12:34   ` Arend van Spriel
2022-01-20 10:17   ` Andy Shevchenko [this message]
2022-01-17 14:29 ` [PATCH v3 6/9] brcmfmac: pcie: Fix crashes due to early IRQs Hector Martin
2022-01-17 14:29 ` [PATCH v3 7/9] brcmfmac: of: Use devm_kstrdup for board_type & check for errors Hector Martin
2022-01-19 12:35   ` Arend van Spriel
2022-01-20 10:52   ` Andy Shevchenko
2022-01-17 14:29 ` [PATCH v3 8/9] brcmfmac: fwil: Constify iovar name arguments Hector Martin
2022-01-19 12:35   ` Arend van Spriel
2022-01-20 10:55   ` Andy Shevchenko
2022-01-17 14:29 ` [PATCH v3 9/9] brcmfmac: pcie: Read the console on init and shutdown Hector Martin
2022-01-19 12:35   ` Arend van Spriel
2022-01-18 10:43 ` [PATCH v3 0/9] misc brcmfmac fixes (M1/T2 series spin-off) Andy Shevchenko
2022-01-18 15:32   ` Hector Martin
2022-01-18 17:01     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHp75Vf+xcn7SJX3RaeDJC2gK0xWVgwMQ33n_988PkDcTp4LpA@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=SHA-cyfmac-dev-list@infineon.com \
    --cc=alyssa@rosenzweig.io \
    --cc=aspriel@gmail.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=chi-hsien.lin@infineon.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=franky.lin@broadcom.com \
    --cc=hante.meuleman@broadcom.com \
    --cc=hdegoede@redhat.com \
    --cc=kettenis@openbsd.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=lenb@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=marcan@marcan.st \
    --cc=netdev@vger.kernel.org \
    --cc=pieter-paul.giesberts@broadcom.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sandals@crustytoothpaste.net \
    --cc=sven@svenpeter.dev \
    --cc=wright.feng@infineon.com \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.