[PATCH 5/5] HID: intel-thc-hid: intel-thc: budget the receive drain
From: Emfox Zhou
Date: Mon Nov 16 2026 - 08:32:41 EST
thc_wait_for_dma_pause() gives every engine 10 ms to report idle, but a
receive engine can be draining a whole frame. Its buffer comes from the
HIDSPI device descriptor's max_input_len, rounded up to 4 KB and capped at
16 PRD entries, so up to 64 KB; at the 2.23 MHz gear that takes about
235 ms, and a timed out pause makes thc_rxdma_reset() return before the
engines are reconfigured, leaving the controller quiesced with the
interrupts off.
Let the callers pass the budget. thc_rxdma_reset() gets one that covers a
full frame at the slowest gear. The SWDMA path keeps the old one: it
pauses the receive engines with the bus lock held and the interrupts
quiesced, and its frames are small.
Fixes: 1d46b8d40655 ("HID: Intel-thc-hid: Intel-thc: Add API to reset read DMA")
Signed-off-by: Emfox Zhou <emfox@xxxxxxxxxx>
---
.../intel-thc-hid/intel-thc/intel-thc-dma.c | 20 +++++++++++++------
.../intel-thc-hid/intel-thc/intel-thc-dma.h | 5 +++++
2 files changed, 19 insertions(+), 6 deletions(-)
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 41efdfaf0..1e68b8845 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
@@ -536,7 +536,9 @@ void thc_dma_unconfigure(struct thc_device *dev)
}
EXPORT_SYMBOL_NS_GPL(thc_dma_unconfigure, "INTEL_THC");
-static int thc_wait_for_dma_pause(struct thc_device *dev, enum thc_dma_channel channel)
+static int thc_wait_for_dma_pause(struct thc_device *dev,
+ enum thc_dma_channel channel,
+ u32 timeout_us)
{
u32 ctrl_reg, sts_reg, sts;
int ret;
@@ -554,7 +556,7 @@ static int thc_wait_for_dma_pause(struct thc_device *dev, enum thc_dma_channel c
ret = regmap_read_poll_timeout(dev->thc_regmap, sts_reg, sts,
!(sts & THC_M_PRT_READ_DMA_INT_STS_ACTIVE),
THC_DEFAULT_RXDMA_POLLING_US_INTERVAL,
- THC_DEFAULT_RXDMA_POLLING_US_TIMEOUT);
+ timeout_us);
if (ret) {
dev_err_once(dev->dev,
@@ -588,13 +590,15 @@ int thc_rxdma_reset(struct thc_device *dev)
goto end;
}
- ret = thc_wait_for_dma_pause(dev, THC_RXDMA1);
+ ret = thc_wait_for_dma_pause(dev, THC_RXDMA1,
+ THC_RXDMA_DRAIN_US_TIMEOUT);
if (ret) {
dev_err(dev->dev, "Wait for RxDMA1 pause failed during RxDMA reset\n");
goto end;
}
- ret = thc_wait_for_dma_pause(dev, THC_RXDMA2);
+ ret = thc_wait_for_dma_pause(dev, THC_RXDMA2,
+ THC_RXDMA_DRAIN_US_TIMEOUT);
if (ret) {
dev_err(dev->dev, "Wait for RxDMA2 pause failed during RxDMA reset\n");
goto end;
@@ -769,7 +773,10 @@ static int thc_swdma_read_start(struct thc_device *dev, void *write_buff,
if (ret)
return ret;
- if (thc_wait_for_dma_pause(dev, THC_RXDMA1) || thc_wait_for_dma_pause(dev, THC_RXDMA2))
+ if (thc_wait_for_dma_pause(dev, THC_RXDMA1,
+ THC_DEFAULT_RXDMA_POLLING_US_TIMEOUT) ||
+ thc_wait_for_dma_pause(dev, THC_RXDMA2,
+ THC_DEFAULT_RXDMA_POLLING_US_TIMEOUT))
return -EIO;
thc_reset_dma_settings(dev);
@@ -834,7 +841,8 @@ static int thc_swdma_read_completion(struct thc_device *dev)
{
int ret;
- ret = thc_wait_for_dma_pause(dev, THC_SWDMA);
+ ret = thc_wait_for_dma_pause(dev, THC_SWDMA,
+ THC_DEFAULT_RXDMA_POLLING_US_TIMEOUT);
if (ret)
return ret;
diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
index 715423453..fccaac122 100644
--- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
+++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
@@ -19,6 +19,11 @@
#define THC_DEFAULT_RXDMA_POLLING_US_INTERVAL 100
#define THC_DEFAULT_RXDMA_POLLING_US_TIMEOUT (10 * USEC_PER_MSEC)
+/*
+ * 235 ms for a 64 KB frame at the slowest gear, so this covers a whole one.
+ */
+#define THC_RXDMA_DRAIN_US_TIMEOUT (500 * USEC_PER_MSEC)
+
/*
* THC needs 1KB aligned address, dest_addr is 54 bits, not 64,
* so don't need to send the lower 10-bits of address.