Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changhuang Liang" <changhuang.liang@starfivetech.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 08/11] spi: dw: use irq handler for enhanced spi
Date: Mon, 03 Aug 2026 12:59:01 +0000	[thread overview]
Message-ID: <20260803125901.83AB71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803124044.156998-9-changhuang.liang@starfivetech.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The SPI controller's FIFO threshold registers are modified while the controller is active, and a hardcoded delay introduces a race condition leading to silent RX FIFO overflows.
- [High] dw_spi_exec_enh_mem_op() unconditionally relies on interrupts, breaking SPI operations on systems without an IRQ line.
--

--- Patch [8]: [PATCH v2 08/11] spi: dw: use irq handler for enhanced spi ---
commit e91a45b5a4fd49e726c98b12e74d1f4306f85fe7
Author: Sudip Mukherjee <sudip.mukherjee@sifive.com>

spi: dw: use irq handler for enhanced spi

This commit introduces an interrupt handler for enhanced SPI read/write
operations. It utilizes the controller's xfer_completion to wait for
transfer completion or timeout from the IRQ handler. It also adjusts
RXFTLR dynamically based on the expected data length.

> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
[ ... ]
> @@ -920,11 +979,54 @@ static int dw_spi_exec_enh_mem_op(...)
>  
>  	dw_spi_update_config(dws, mem->spi, &cfg, &enh_cfg);
>  
> +	dw_spi_mask_intr(dws, 0xff);
> +	reinit_completion(&ctlr->xfer_completion);
>  	dw_spi_enable_chip(dws, 1);
>  
>  	dw_spi_enh_write_cmd_addr(dws, op);
> +	dw_spi_set_cs(mem->spi, false);
>  
> -	return 0;
> +	/*
> +	 * FIXME: The exact reason for this delay is not fully understood,
> +	 * but empirical testing shows it significantly improves the stability
> +	 * of read/write operations. Without this delay, occasional transfer
> +	 * errors or timeouts may occur under certain conditions.
> +	 * Keeping it as a safeguard based on practical validation.
> +	 */
> +	udelay(5);
> +
> +	dw_spi_enh_irq_setup(dws);

[Severity: High]
Does modifying the SPI controller's FIFO threshold registers inside
dw_spi_enh_irq_setup() while the controller is active (after calling
dw_spi_enable_chip()) violate the DW APB SSI hardware specifications?

Additionally, with this 5us delay between starting the transfer and unmasking
interrupts, could the RX FIFO overflow before dw_spi_enh_irq_setup() prepares
the IRQ handler to drain it?

At typical SPI frequencies (e.g., 50MHz), 5us is enough time to clock in
more data than a small RX FIFO can hold, which might lead to silent data loss
and immediate -EIO timeouts.

> +
> +	/* Use timeout calculation from spi_transfer_wait() */
> +	ms = 8LL * MSEC_PER_SEC * (dws->rx_len ? dws->rx_len : dws->tx_len);
> +	do_div(ms, dws->current_freq);
> +
> +	/*
> +	 * Increase it twice and add 200 ms tolerance, use
> +	 * predefined maximum in case of overflow.
> +	 */
> +	ms += ms + 200;
> +	if (ms > UINT_MAX)
> +		ms = UINT_MAX;
> +
> +	ms = wait_for_completion_timeout(&ctlr->xfer_completion,
> +					 msecs_to_jiffies(ms));
> +	if (ms == 0) {

[Severity: High]
Will this wait unconditionally time out on platforms without a connected IRQ?

Unlike the standard dw_spi_exec_mem_op() which falls back to polling, this
appears to rely solely on the interrupt handler to signal completion. If a
system uses polling mode (no dedicated SPI IRQ), it seems enhanced memory
operations will always result in an -EIO timeout here.

> +		dw_spi_mask_intr(dws, 0xff);
> +		synchronize_irq(dws->irq);
> +		dws->rx = NULL;
> +		dws->tx = NULL;
> +		dws->rx_len = 0;
> +		dws->tx_len = 0;
> +		dw_spi_stop_mem_op(dws, mem->spi);
> +		return -EIO;
> +	}
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803124044.156998-1-changhuang.liang@starfivetech.com?part=8

  reply	other threads:[~2026-08-03 12:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 12:40 [PATCH v2 00/11] Add support for StarFive JHB100 SFC Changhuang Liang
2026-08-03 12:40 ` [PATCH v2 01/11] spi: dw: Introduce spi_frf and STD_SPI Changhuang Liang
2026-08-03 12:40 ` [PATCH v2 02/11] spi: dw: update SPI_CTRLR0 register Changhuang Liang
2026-08-03 12:40 ` [PATCH v2 03/11] spi: dw: add check for support of enhanced spi Changhuang Liang
2026-08-03 12:53   ` sashiko-bot
2026-08-03 12:40 ` [PATCH v2 04/11] spi: dw: adjust size of mem_op Changhuang Liang
2026-08-03 12:40 ` [PATCH v2 05/11] spi: dw: update NDF while using enhanced spi mode Changhuang Liang
2026-08-03 13:02   ` sashiko-bot
2026-08-03 12:40 ` [PATCH v2 06/11] spi: dw: Introduce enhanced single/dual/quad/octal spi Changhuang Liang
2026-08-03 12:58   ` sashiko-bot
2026-08-03 12:40 ` [PATCH v2 07/11] spi: dw: send cmd and addr to start the spi transfer Changhuang Liang
2026-08-03 12:59   ` sashiko-bot
2026-08-03 12:40 ` [PATCH v2 08/11] spi: dw: use irq handler for enhanced spi Changhuang Liang
2026-08-03 12:59   ` sashiko-bot [this message]
2026-08-03 12:40 ` [PATCH v2 09/11] spi: dw: detect enhanced spi mode Changhuang Liang
2026-08-03 13:07   ` sashiko-bot
2026-08-03 12:40 ` [PATCH v2 10/11] spi: dt-bindings: snps,dw-apb-ssi: Add starfive,jhb100-sfc Changhuang Liang
2026-08-03 12:40 ` [PATCH v2 11/11] spi: dw: Add support for StarFive JHB100 SoC SFC Changhuang Liang
2026-08-03 13:07   ` sashiko-bot
2026-08-04 12:53 ` [PATCH v2 00/11] Add support for StarFive JHB100 SFC Mark Brown

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=20260803125901.83AB71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=changhuang.liang@starfivetech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox