Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH v3] HID: intel-thc-hid: intel-thc: restore PRD table capacity
@ 2026-11-15  4:07 Emfox Zhou
  2026-11-15  4:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Emfox Zhou @ 2026-11-15  4:07 UTC (permalink / raw)
  To: Even Xu, Xinpeng Sun, Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel

The controller writes the frame length into the PRD entry it filled and
marks the end of the frame there; only the read path puts the capacity
back. thc_reset_dma_settings() rewinds the read pointers, so the ring
reads as empty while the entries keep those lengths, and the next frame
that does not fit runs past the end of its table: the controller reports
a buffer overrun, which is a transfer error and leads back into the same
reset, with the tables untouched.

Rebuild the receive tables in thc_dma_configure(), after the pointers are
rewound and before the engines are started again, which covers probe, the
RxDMA reset and the resume path. All four engines are stopped at that
point, so nothing reads the tables while they are written, and
thc_copy_sgls_to_prd() returns early for a channel whose tables are gone.

Fixes: a688404b2e20 ("HID: intel-thc-hid: intel-thc: Add THC DMA interfaces")
Signed-off-by: Emfox Zhou <emfox@debian.org>
---
Changes in v3:
  - Restore the tables from thc_dma_configure() rather than from
    thc_reset_dma_settings(): the reset also runs on the SWDMA path, where
    nothing stops a reader.
  - Do not touch a table that has already been released.
  - v1 was posted under an older subject.

Link: https://lore.kernel.org/r/20261115001100.313270-1-emfox@debian.org
---
 drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
index c80ef8c20..64fd890e5 100644
--- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
+++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
@@ -211,6 +211,9 @@ static void thc_copy_sgls_to_prd(struct thc_device *dev,
 {
 	unsigned int i;
 
+	if (!config->is_enabled || !config->prd_tbls)
+		return;
+
 	memset(config->prd_tbls, 0, array_size(PRD_TABLE_SIZE, config->prd_tbl_num));
 
 	for (i = 0; i < config->prd_tbl_num; i++)
@@ -491,6 +494,10 @@ int thc_dma_configure(struct thc_device *dev)
 		return -EINVAL;
 	}
 
+	/* Pointers rewound, entries still short: restore before restart. */
+	thc_copy_sgls_to_prd(dev, &dma_ctx->dma_config[THC_RXDMA1]);
+	thc_copy_sgls_to_prd(dev, &dma_ctx->dma_config[THC_RXDMA2]);
+
 	for (chan = 0; chan < MAX_THC_DMA_CHANNEL; chan++) {
 		dma_set_prd_base_addr(dev,
 				      dma_ctx->dma_config[chan].prd_tbls_dma_handle,

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-15  4:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15  4:07 [PATCH v3] HID: intel-thc-hid: intel-thc: restore PRD table capacity Emfox Zhou
2026-11-15  4:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox