* [PATCH] spi: omap2-mcspi: skip the TX drain wait in duplex
@ 2026-11-25 16:20 Markus Klotzbuecher
0 siblings, 0 replies; only message in thread
From: Markus Klotzbuecher @ 2026-11-25 16:20 UTC (permalink / raw)
To: Mark Brown
Cc: linux-spi, linux-kernel, linux-omap, Vignesh Raghavendra,
dmaengine, Peter Ujfalusi
k3-udma completes a transfer towards a PDMA peer only once the peer has
drained (udma_is_desc_really_done()). If it has not at the ring
interrupt, k3-udma defers that check to a delayed work on the system
workqueue. The McSPI depends on this: it prepares TX with
DMA_PREP_INTERRUPT, and its TX callback clears the DMA write request,
which has to stay set until the PDMA has passed on every byte. On
PREEMPT_RT the kworker runs at normal priority, so each DMA transfer
waits behind other tasks, for several ms under load.
Commit e8e2f92b1553 ("dmaengine: ti: k3-udma: Respond TX done if
DMA_PREP_INTERRUPT is not requested") lets a consumer skip that check
when it knows by other means that TX is done. Its first version was
posted together with a McSPI change that waited for EOW instead [1],
which was not applied.
In host mode full duplex the RX completion proves that every TX word
has been shifted out, so once omap2_mcspi_rx_dma() has returned the
PDMA holds no TX data. That is what k3-udma requires of a consumer that
does not set DMA_PREP_INTERRUPT. Prepare TX there with DMA_CTRL_ACK
only and without a callback, clear the write request after RX, and do
not wait for the TX completion. Target mode and TX-only transfers keep
the callback and the drain check.
On an AM625 with PREEMPT_RT, a device on McSPI2 at 50 MHz and four
transfers every 2 ms, two of them, 344 and 367 bytes, via DMA: the
cyclic thread missed its deadline 217 times in 10 minutes idle and 1864
times in 30 minutes under load without this change, and 0 and 1 times
with it. No data errors in about 893k checked loopback updates.
Link: https://lore.kernel.org/r/20220822091531.27827-1-vaishnav.a@ti.com [1]
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
---
Notes:
- Tested on 6.18.56 PREEMPT_RT with commit c126e07bde21 ("spi:
omap2-mcspi: handle DMA setup failures") backported and with the DMA
request bit lock patch:
https://lore.kernel.org/r/20261125161340.1218564-1-mk@mkio.de
On spi for-next the callback is set through
dmaengine_desc_set_callback() (commit 29fcd5d436c4); compile-tested
there.
- Independent of that lock patch; applies to 266ae6df1980 alone.
- The 2022 thread asked about TX data left in the PDMA when the IP stops
transmitting (externally clocked bus, delays). In host full duplex the
RX completion means every word was shifted out, whatever the delay;
an externally clocked bus is target mode, which keeps the drain check.
RX EOW is not used as the signal because RX data may still be in
flight to memory then.
- omap-dma and edma complete a slave_sg descriptor regardless of
DMA_PREP_INTERRUPT; there the only change is that the write request is
cleared after RX instead of from the TX callback. Not tested on those.
- As far as I can tell this is the first user of the k3-udma opt-out
from e8e2f92b1553, whose message gives the McSPI as the example.
- On AM625, PEER_BCNT wraps below zero after the early decrement and is
back at 0 once the PDMA has drained, so a following transfer starts
from clean counters.
drivers/spi/spi-omap2-mcspi.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 061d50c65dfd..1eaa86c8d892 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -413,6 +413,18 @@ static void omap2_mcspi_tx_callback(void *data)
complete(&mcspi_dma->dma_tx_completion);
}
+/*
+ * In host full duplex the RX completion proves that every TX word was
+ * shifted out, so TX needs neither a callback nor k3-udma's peer drain
+ * check, which it defers to a kworker.
+ */
+static bool omap2_mcspi_tx_duplex(struct spi_device *spi,
+ struct spi_transfer *xfer)
+{
+ return xfer->tx_buf && xfer->rx_buf &&
+ !spi_controller_is_target(spi->controller);
+}
+
static int omap2_mcspi_tx_dma(struct spi_device *spi,
struct spi_transfer *xfer,
struct dma_slave_config cfg)
@@ -421,6 +433,7 @@ static int omap2_mcspi_tx_dma(struct spi_device *spi,
struct omap2_mcspi *mcspi;
struct omap2_mcspi_dma *mcspi_dma;
struct dma_async_tx_descriptor *tx;
+ unsigned long flags = DMA_PREP_INTERRUPT | DMA_CTRL_ACK;
mcspi = spi_controller_get_devdata(spi->controller);
mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)];
@@ -429,14 +442,18 @@ static int omap2_mcspi_tx_dma(struct spi_device *spi,
if (ret)
return ret;
+ if (omap2_mcspi_tx_duplex(spi, xfer))
+ flags = DMA_CTRL_ACK;
+
tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, xfer->tx_sg.sgl,
xfer->tx_sg.nents,
- DMA_MEM_TO_DEV,
- DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+ DMA_MEM_TO_DEV, flags);
if (!tx)
return -EIO;
- dmaengine_desc_set_callback(tx, omap2_mcspi_tx_callback, NULL, spi);
+ if (flags & DMA_PREP_INTERRUPT)
+ dmaengine_desc_set_callback(tx, omap2_mcspi_tx_callback, NULL,
+ spi);
return dma_submit_error(dmaengine_submit(tx));
}
@@ -672,6 +689,8 @@ static int omap2_mcspi_txrx_dma(struct spi_device *spi,
&rx_submitted, &dma_started);
if (ret)
goto out;
+ if (omap2_mcspi_tx_duplex(spi, xfer))
+ omap2_mcspi_set_dma_req(spi, 0, 0);
} else if (tx) {
if (mcspi->target_aborted) {
ret = -EINTR;
@@ -686,9 +705,12 @@ static int omap2_mcspi_txrx_dma(struct spi_device *spi,
}
if (tx) {
- ret = mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_tx_completion);
- if (ret || mcspi->target_aborted)
- goto out;
+ if (!omap2_mcspi_tx_duplex(spi, xfer)) {
+ ret = mcspi_wait_for_completion(mcspi,
+ &mcspi_dma->dma_tx_completion);
+ if (ret || mcspi->target_aborted)
+ goto out;
+ }
if (spi_controller_is_target(mcspi->ctlr)) {
ret = mcspi_wait_for_completion(mcspi, &mcspi->txdone);
base-commit: 266ae6df1980a5a5c58735ae114ae62a2acad8db
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 16:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 16:20 [PATCH] spi: omap2-mcspi: skip the TX drain wait in duplex Markus Klotzbuecher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®