RE: [PATCH v2] wifi: rtw88: sdio: Honor the host max_req_size in the RX path

From: Ping-Ke Shih
Date: Sun Aug 06 2023 - 20:41:54 EST




> -----Original Message-----
> From: Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>
> Sent: Monday, August 7, 2023 2:17 AM
> To: linux-wireless@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx; jernej.skrabec@xxxxxxxxx; Ping-Ke Shih <pkshih@xxxxxxxxxxx>;
> ulf.hansson@xxxxxxxxxx; kvalo@xxxxxxxxxx; tony0620emma@xxxxxxxxx; Martin Blumenstingl
> <martin.blumenstingl@xxxxxxxxxxxxxx>; Lukas F . Hartmann <lukas@xxxxxxxxx>
> Subject: [PATCH v2] wifi: rtw88: sdio: Honor the host max_req_size in the RX path
>

[...]

>
>
> drivers/net/wireless/realtek/rtw88/sdio.c | 30 +++++++++++++++++------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
> index 2c1fb2dabd40..553b7e68ca3b 100644
> --- a/drivers/net/wireless/realtek/rtw88/sdio.c
> +++ b/drivers/net/wireless/realtek/rtw88/sdio.c
> @@ -500,19 +500,35 @@ static u32 rtw_sdio_get_tx_addr(struct rtw_dev *rtwdev, size_t size,
> static int rtw_sdio_read_port(struct rtw_dev *rtwdev, u8 *buf, size_t count)
> {
> struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
> + struct mmc_host *host = rtwsdio->sdio_func->card->host;
> bool bus_claim = rtw_sdio_bus_claim_needed(rtwsdio);
> u32 rxaddr = rtwsdio->rx_addr++;
> - int ret;
> + int ret = 0, err = 0;

nit: no need initializer of 'err'

> + size_t bytes;
>
> if (bus_claim)
> sdio_claim_host(rtwsdio->sdio_func);
>
> - ret = sdio_memcpy_fromio(rtwsdio->sdio_func, buf,
> - RTW_SDIO_ADDR_RX_RX0FF_GEN(rxaddr), count);
> - if (ret)
> - rtw_warn(rtwdev,
> - "Failed to read %zu byte(s) from SDIO port 0x%08x",
> - count, rxaddr);
> + while (count > 0) {
> + bytes = min_t(size_t, host->max_req_size, count);
> +
> + err = sdio_memcpy_fromio(rtwsdio->sdio_func, buf,
> + RTW_SDIO_ADDR_RX_RX0FF_GEN(rxaddr),
> + bytes);
> + if (err) {
> + rtw_warn(rtwdev,
> + "Failed to read %zu byte(s) from SDIO port 0x%08x: %d",
> + bytes, rxaddr, err);
> + ret = err;

I think this intends to return an error to callers if one error presents among
N times read. Would you like to point out this in comment as well? Because I want
to say we don't need 'err' at first glance, but this is indeed needed.

> + /* Don't stop here - instead drain the remaining data
> + * from the card's buffer, else the card will return
> + * corrupt data for the next rtw_sdio_read_port() call.
> + */
> + }
> +
> + count -= bytes;
> + buf += bytes;
> + }
>
> if (bus_claim)
> sdio_release_host(rtwsdio->sdio_func);
> --
> 2.41.0