spi: spi-ti-qspi: finalize message on transfer error
Subsystems (2)
v3 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 (with the message's optimize state left unreleased). 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 and calls kunit_skip() on configurations without CONFIG_INDIRECT_IOMEM or with CONFIG_HAVE_CLK enabled. The test is not added to drivers/spi/.kunitconfig because building SPI_TI_QSPI on UML or x86_64 requires CONFIG_COMPILE_TEST=y, which would change many unrelated options for every SPI KUnit run. Run it with:
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/spi \
--kconfig_add CONFIG_COMPILE_TEST=y \
--kconfig_add CONFIG_SPI_TI_QSPI=y \
--kconfig_add CONFIG_SPI_TI_QSPI_KUNIT_TEST=yTested with KUnit:
- (a) Plain ARCH=um (./tools/testing/kunit/kunit.py run --kunitconfig=drivers/spi):
11/11 passed (spi_ti_qspi not enabled).
- (b) ARCH=um with the --kconfig_add options, patch 2 only:
11 passed, 1 failed (ti_qspi_test fails on all three checks).
- (c) ARCH=um with the --kconfig_add options, both patches:
12/12 passed.
- (d) x86_64 with the --kconfig_add options: 11 passed, 1 skipped (ti_qspi_test skipped with reason); plain x86_64: 11/11 passed.
- W=1 builds of drivers/spi/ on ARCH=um and x86_64: 0 warnings.
- Not tested on hardware.
Changes in v3:
- Rebased on spi/for-7.5 now that the SPI core series is applied there.
- Patch 1: fixed the commit message to state that the old code returns -EINVAL directly rather than ret.
- Patch 2: dropped the drivers/spi/Makefile change (already includes tests/) and left drivers/spi/.kunitconfig unmodified because enabling CONFIG_COMPILE_TEST=y in it would alter many unrelated options for every SPI KUnit run (pass the three options via --kconfig_add); moved logic_iomem checks out of Kconfig depends and skipped via kunit_skip() when !INDIRECT_IOMEM || HAVE_CLK; removed the stale pm_runtime_get_noresume() calls (ti_qspi_remove() no longer calls pm_runtime_put_sync() after commit 8b8678d3e894); reduced the test to one fast KUNIT_CASE checking spi_sync() == -ETIMEDOUT, !msg.optimized, and QSPI_INVAL (removed the async, recovery, and tautological m->status checks and the optional second MEM resource).
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.
v2: https://lore.kernel.org/linux-spi/[email protected]/
v1: https://lore.kernel.org/all/[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 a KUnit test for transfer error finalization
drivers/spi/Kconfig | 12 ++ drivers/spi/spi-ti-qspi.c | 4 +- drivers/spi/tests/Makefile | 1 + drivers/spi/tests/spi-ti-qspi-kunit.c | 172 ++++++++++++++++++++++++++ 4 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 drivers/spi/tests/spi-ti-qspi-kunit.c
base-commit: 0877b0b54a4c186ea9acca25ae79efd8516176ba
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH v3 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 -EINVAL 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.
---
v3: Rebased on spi/for-7.5. Fixed the commit message: the old code returns -EINVAL, not ret.
drivers/spi/spi-ti-qspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +2 -2
@@ -718,8 +718,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.679.gc527c65306-goog
PATCH v3 2/2 spi: spi-ti-qspi: add a KUnit test for transfer error finalization
In reply to Joseph CT ChanFrom: Joseph CT Chan <[email protected]>
Add a KUnit test for ti_qspi_start_transfer_one() covering the transfer error handling path.
On ARCH=um, the test emulates the TI QSPI controller MMIO registers with logic_iomem and leaves QSPI_SPI_STATUS_REG returning zero so that ti_qspi_poll_wc() times out with -ETIMEDOUT. A single spi_sync() call verifies that:
- spi_sync() returns -ETIMEDOUT,
- msg.optimized is false (the message was finalized), and
- QSPI_INVAL was written to QSPI_SPI_CMD_REG (the frame was ended).
On configurations without CONFIG_INDIRECT_IOMEM or with CONFIG_HAVE_CLK enabled, the test calls kunit_skip() without registering any device.
The test is not added to drivers/spi/.kunitconfig because building SPI_TI_QSPI on UML or x86_64 requires CONFIG_COMPILE_TEST=y, which would enable and alter many unrelated config options for every SPI KUnit run. Run it with:
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/spi \
--kconfig_add CONFIG_COMPILE_TEST=y \
--kconfig_add CONFIG_SPI_TI_QSPI=y \
--kconfig_add CONFIG_SPI_TI_QSPI_KUNIT_TEST=yDeveloped with help from the Claude and Gemini AI assistants.
---
v3: Rebased on spi/for-7.5; dropped the drivers/spi/Makefile change (already
includes tests/) and left drivers/spi/.kunitconfig unmodified (pass CONFIG_COMPILE_TEST=y, CONFIG_SPI_TI_QSPI=y, and CONFIG_SPI_TI_QSPI_KUNIT_TEST=y via --kconfig_add instead); moved logic_iomem checks out of Kconfig depends and skipped via kunit_skip() when !INDIRECT_IOMEM || HAVE_CLK; removed the stale pm_runtime_get_noresume() calls (ti_qspi_remove() no longer calls pm_runtime_put_sync() after commit 8b8678d3e894); reduced the test to one fast KUNIT_CASE checking spi_sync() == -ETIMEDOUT, !msg.optimized, and QSPI_INVAL (removed async, recovery, and tautological m->status checks and the optional second MEM resource).
v2: Trimmed the comments.
drivers/spi/Kconfig | 12 ++ drivers/spi/tests/Makefile | 1 + drivers/spi/tests/spi-ti-qspi-kunit.c | 172 ++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/spi/tests/spi-ti-qspi-kunit.c
drivers/spi/Kconfig +12 -0
@@ -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 + default KUNIT_ALL_TESTS + help + This option builds the KUnit test suite for the TI QSPI controller + driver. It verifies that a transfer timeout finalizes the message + with -ETIMEDOUT and writes QSPI_INVAL to end the frame. The test + runs only where MMIO can be emulated (UML) and is skipped elsewhere. + + If unsure, say N. + config SPI_TLE62X0 tristate "Infineon TLE62X0 (for power switching)" depends on SYSFS
drivers/spi/tests/Makefile +1 -0
@@ -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 +172 -0
172 lines not on this page · raw message
Signature · 1 line
2.56.0.679.gc527c65306-goog