Re: [PATCH] spi: cadence: recover the controller after a failed transfer

From: Mark Brown

Date: Sun Nov 15 2026 - 13:35:08 EST


> When a transfer times out, the bytes it clocked in are still in the RX
> FIFO: the interrupt that would have read them did not run in time, and
> the host path never drains the FIFO between transfers (only the target
> path does, in cdns_unprepare_transfer_hardware). Every later transfer
> then reads the stale bytes first and returns shifted data, and the
> device behind the controller looks dead until the system is rebooted.

> +static void cdns_spi_handle_err(struct spi_controller *ctlr,
> + struct spi_message *msg)
> +{
> + struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
> +
> + cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_ALL);

This is missing a synchronize_irq() to make sure that already pending
interrupts are done; mask the interrupts and then synchronize. You'll
also need some handling in the interrupt to make sure that it doesn't
reenable anything.

> + cdns_spi_init_hw(xspi, spi_controller_is_target(ctlr));

We should reset xspi->speed_hz as well, otherwise it'll be out of sync
with what's programmed in the hardware.

--
Mark Brown <broonie@xxxxxxxxxx>