Skip to contentSkip to conversation

spi: spi-ti-qspi: finalize message on transfer error

PATCH Superseded Joseph CT Chan 1 participant 3 messages Nov 3

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover spi: spi-ti-qspi: finalize message on transfer error

From: Joseph CT Chan <[email protected]>

Hi Mark,

When a transfer fails in ti_qspi_start_transfer_one(), for example on a write completion timeout, the driver returns without finalizing the message and without writing QSPI_INVAL to end the frame. A queued caller then waits forever, and a spi_sync() that took the no-queue path gets -EINPROGRESS instead of the error. Patch 1 sends the error through the existing exit path, which ends the frame, sets the status and finalizes the message. Patch 2 adds a KUnit test that emulates the controller registers with logic_iomem on ARCH=um.

Tested with KUnit on ARCH=um: ti_qspi_test passes with patch 1 and fails without it. Not tested on hardware.

Changes in v2:
- Split out of the v1 14-patch series, as David suggested.
- Patch 2: trimmed the comments in the test.
- Moved the AI assistance note from an Assisted-by tag into the commit message.

v1: https://lore.kernel.org/all/[email protected]/

This series depends on the SPI core series ("spi: unoptimize message when queuing it fails" v2), which adds drivers/spi/tests/.kunitconfig and the KUnit Makefile lines that patch 2 extends. Patch 1 applies on its own.

SPI core series v2: https://lore.kernel.org/linux-spi/[email protected]/

Please consider this patch series for the next merge window.

Thanks,
Joseph

Joseph CT Chan (2):
spi: spi-ti-qspi: finalize message on transfer error
spi: spi-ti-qspi: add KUnit tests for transfer error finalization

 drivers/spi/Kconfig                   |  12 ++
 drivers/spi/Makefile                  |   1 +
 drivers/spi/spi-ti-qspi.c             |   4 +-
 drivers/spi/tests/.kunitconfig        |   4 +
 drivers/spi/tests/Makefile            |   1 +
 drivers/spi/tests/spi-ti-qspi-kunit.c | 188 ++++++++++++++++++++++++++
 6 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 drivers/spi/tests/spi-ti-qspi-kunit.c

base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
prerequisite-patch-id: 6999a3baa2d32de8fa42f2626a845fe3cb63b0b2
prerequisite-patch-id: 686a62b9223209bf1e83740a0874e20d7607f69a

Signature · 1 line
2.56.0.385.gac671c819a-goog
#1 lore raw

PATCH v2 1/2 spi: spi-ti-qspi: finalize message on transfer error

From: Joseph CT Chan <[email protected]>

When ti_qspi_start_transfer_one() hits an error in qspi_transfer_msg(), such as a transfer timeout (-ETIMEDOUT), it unlocks qspi->list_lock and returns ret directly without writing QSPI_INVAL to QSPI_SPI_CMD_REG, setting m->status, or calling spi_finalize_current_message(host). Because the message is never finalized, spi_sync() or the spi_async() callback waits forever on queued transfers. If spi_sync() took the no-queue path, it returns -EINPROGRESS instead of the error, and the message's optimize state is never released. The frame is also left open, because the QSPI_INVAL write that ends it is skipped.

Set status to the transfer error and leave the transfer loop, so the error goes through the existing tail: unlock list_lock, write QSPI_INVAL, set m->status, and finalize the message. This fixes both paths, and the caller now gets the error from qspi_transfer_msg() instead of -EINVAL or -EINPROGRESS.

Tested at runtime with KUnit (spi_ti_qspi, ti_qspi_test, added later in this series) by injecting a QSPI_SPI_STATUS_REG WC poll timeout (-ETIMEDOUT) via logic_iomem emulated MMIO on ARCH=um.

Developed with help from the Claude and Gemini AI assistants.

Fixes 505a14954e2d ("spi/qspi: Add qspi flash controller")
---
 drivers/spi/spi-ti-qspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +2 -2
index 091a8b8842f5..7360ee6bd122 100644
@@ -708,8 +708,8 @@ static int ti_qspi_start_transfer_one(struct spi_controller *host,
 		ret = qspi_transfer_msg(qspi, t, transfer_len_words * wlen);
 		if (ret) {
 			dev_dbg(qspi->dev, "transfer message failed\n");
-			mutex_unlock(&qspi->list_lock);
-			return -EINVAL;
+			status = ret;
+			break;
 		}
 
 		m->actual_length += transfer_len_words * wlen;
Signature · 1 line
2.56.0.385.gac671c819a-goog
#2 lore raw

PATCH v2 2/2 spi: spi-ti-qspi: add KUnit tests for transfer error finalization

In reply to Joseph CT Chan

From: Joseph CT Chan <[email protected]>

Add KUnit tests for ti_qspi_start_transfer_one() covering the transfer error handling path.

On ARCH=um, emulate the TI QSPI controller MMIO via logic_iomem:
- ti_qspi_test: verify that queued and synchronous transfers hitting a ti_qspi_poll_wc() write completion timeout complete with -ETIMEDOUT, that QSPI_INVAL is written to end the frame, and that subsequent transfers succeed cleanly once QSPI_SPI_STATUS_REG reports QSPI_WC.

Developed with help from the Claude and Gemini AI assistants.

---
v2: Trimmed the comments.

 drivers/spi/Kconfig                   |  12 ++
 drivers/spi/Makefile                  |   1 +
 drivers/spi/tests/.kunitconfig        |   4 +
 drivers/spi/tests/Makefile            |   1 +
 drivers/spi/tests/spi-ti-qspi-kunit.c | 188 ++++++++++++++++++++++++++
 5 files changed, 206 insertions(+)
 create mode 100644 drivers/spi/tests/spi-ti-qspi-kunit.c
drivers/spi/Kconfig +12 -0
index a7b343d124a9..feb9265b7d0f 100644
@@ -1258,6 +1258,18 @@ config SPI_TI_QSPI
 	  This device supports single, dual and quad read support, while
 	  it only supports single write mode.
 
+config SPI_TI_QSPI_KUNIT_TEST
+	bool "KUnit test for TI QSPI controller driver" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && SPI_TI_QSPI=y && INDIRECT_IOMEM && !HAVE_CLK
+	default KUNIT_ALL_TESTS
+	help
+	  This option builds the KUnit test suite for the TI QSPI controller
+	  driver. It verifies that transfer timeout errors are properly
+	  finalized with -ETIMEDOUT and that QSPI_INVAL is written to the
+	  command register.
+
+	  If unsure, say N.
+
 config SPI_TLE62X0
 	tristate "Infineon TLE62X0 (for power switching)"
 	depends on SYSFS
drivers/spi/Makefile +1 -0
index d4a806b46b2c..24497d3936f6 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SPI_SPIDEV)		+= spidev.o
 obj-$(CONFIG_SPI_LOOPBACK_TEST)		+= spi-loopback-test.o
 obj-$(CONFIG_SPI_DMA_KUNIT_TEST)	+= tests/
 obj-$(CONFIG_SPI_CORE_KUNIT_TEST)	+= tests/
+obj-$(CONFIG_SPI_TI_QSPI_KUNIT_TEST)	+= tests/
 
 # SPI master controller drivers (bus)
 obj-$(CONFIG_SPI_AIROHA_SNFI)		+= spi-airoha-snfi.o
drivers/spi/tests/.kunitconfig +4 -0
index f781425d258e..354bafc42c2b 100644
@@ -1,4 +1,8 @@
 CONFIG_KUNIT=y
+CONFIG_KUNIT_UML_PCI=y
 CONFIG_SPI=y
 CONFIG_SPI_MASTER=y
 CONFIG_SPI_CORE_KUNIT_TEST=y
+CONFIG_COMPILE_TEST=y
+CONFIG_SPI_TI_QSPI=y
+CONFIG_SPI_TI_QSPI_KUNIT_TEST=y
drivers/spi/tests/Makefile +1 -0
index 6dbf53643619..a5a8fc9435d4 100644
@@ -2,3 +2,4 @@
 
 obj-$(CONFIG_SPI_DMA_KUNIT_TEST) += spi-dma-kunit.o
 obj-$(CONFIG_SPI_CORE_KUNIT_TEST) += spi-core-kunit.o
+obj-$(CONFIG_SPI_TI_QSPI_KUNIT_TEST) += spi-ti-qspi-kunit.o
drivers/spi/tests/spi-ti-qspi-kunit.c new file +188 -0

188 lines not on this page · raw message

Signature · 1 line
2.56.0.385.gac671c819a-goog