Skip to contentSkip to conversation

spi: xilinx: let transfers timeout in case of no IRQ

PATCH In review Vadim Fedorenko 3 participants 3 messages Jun 10 – Jun 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: xilinx: let transfers timeout in case of no IRQ

In case of failed HW the driver may not see an interrupt and will stuck in waiting forever. We can avoid such situation by timing out of transfers if the interrupt is not seen in a reasonable time.

This problem can be found on unload of ptp_ocp driver for TimeCard which uses Xilinx SPI AXI and SPI-NOR flash memory. During tear-down process spi-nor drivers send soft reset command which is not triggering an interrupt stalling the unload process completely.

---
 drivers/spi/spi-xilinx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi-xilinx.c +5 -1
index 9f065d4e27d1..471936a7bb75 100644
@@ -285,7 +285,11 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
 
 		if (use_irq) {
 			xspi->write_fn(cr, xspi->regs + XSPI_CR_OFFSET);
-			wait_for_completion(&xspi->done);
+			if (!wait_for_completion_timeout(&xspi->done, secs_to_jiffies(1))) {
+				dev_err(&spi->dev, "SPI transfer timed out\n");
+				xspi_init_hw(xspi);
+				return -ETIMEDOUT;
+			}
 			/* A transmit has just completed. Process received data
 			 * and check for more data to transmit. Always inhibit
 			 * the transmitter while the Isr refills the transmit
Signature · 1 line
2.47.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Vadim Fedorenko

In case of failed HW the driver may not see an interrupt and will stuck

will be stuck/will get stuck

Quoted 1 line

in waiting forever. We can avoid such situation by timing out of

Imperative mood please.

Quoted 19 lines

transfers if the interrupt is not seen in a reasonable time.

This problem can be found on unload of ptp_ocp driver for TimeCard which uses Xilinx SPI AXI and SPI-NOR flash memory. During tear-down process spi-nor drivers send soft reset command which is not triggering an interrupt stalling the unload process completely.

---
  drivers/spi/spi-xilinx.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi-xilinx.c +0 -0
index 9f065d4e27d1..471936a7bb75 100644
@@ -285,7 +285,11 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
 
  		if (use_irq) {

drivers/spi/spi-xilinx.c static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) · line 295

Quoted 10 lines
drivers/spi/spi-xilinx.c +5 -1
  			xspi->write_fn(cr, xspi->regs + XSPI_CR_OFFSET);
-			wait_for_completion(&xspi->done);
+			if (!wait_for_completion_timeout(&xspi->done, secs_to_jiffies(1))) {
+				dev_err(&spi->dev, "SPI transfer timed out\n");
+				xspi_init_hw(xspi);
+				return -ETIMEDOUT;
+			}
  			/* A transmit has just completed. Process received data
  			 * and check for more data to transmit. Always inhibit
  			 * the transmitter while the Isr refills the transmit

With changes in commit message feel free to add my

Thanks,
Michal

maintainer
#2 lore raw
In reply to Vadim Fedorenko
Quoted 1 line · Vadim Fedorenko

spi: xilinx: let transfers timeout in case of no IRQ

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2

Thanks!

[1/1] spi: xilinx: let transfers timeout in case of no IRQ

      https://git.kernel.org/broonie/spi/c/0f95264f49ac

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark