All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emfox Zhou <emfox@debian.org>
To: Even Xu <even.xu@intel.com>, Xinpeng Sun <xinpeng.sun@intel.com>,
	Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] HID: intel-thc-hid: intel-thc: restore PRD table capacity
Date: Sun, 15 Nov 2026 08:11:00 +0800	[thread overview]
Message-ID: <20261115001100.313270-1-emfox@debian.org> (raw)

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.

Restore the receive tables where the pointers are rewound, which covers
the RxDMA reset, the resume path and the SWDMA round trips in one place.
Every caller has the engines paused: the reset and the SWDMA paths wait
for them, a resume finds them stopped by the suspend, and a probe has
just rebuilt the tables anyway. thc_copy_sgls_to_prd() returns early for
a channel that has no tables.

Fixes: 1d46b8d40655 ("HID: Intel-thc-hid: Intel-thc: Add API to reset read DMA")
Signed-off-by: Emfox Zhou <emfox@debian.org>
---
Changes in v2:
  - Move the restore into thc_reset_dma_settings() so every pointer rewind
    is covered, and add the Fixes tag.

Link: https://lore.kernel.org/r/20261114231733.3916070-1-emfox@debian.org
---
 drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 13 +++++++++++++
 1 file changed, 13 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..544bf3a6b 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)
+		return;
+
 	memset(config->prd_tbls, 0, array_size(PRD_TABLE_SIZE, config->prd_tbl_num));
 
 	for (i = 0; i < config->prd_tbl_num; i++)
@@ -285,6 +288,16 @@ static void thc_reset_dma_settings(struct thc_device *dev)
 	regmap_write_bits(dev->thc_regmap, THC_M_PRT_READ_DMA_CNTRL_SW_OFFSET,
 			  THC_M_PRT_READ_DMA_CNTRL_TPCPR,
 			  THC_M_PRT_READ_DMA_CNTRL_TPCPR);
+
+	if (!dev->dma_ctx)
+		return;
+
+	/*
+	 * Pointers back at the start while the entries keep the lengths the
+	 * controller wrote: restore the capacity for the frames that follow.
+	 */
+	thc_copy_sgls_to_prd(dev, &dev->dma_ctx->dma_config[THC_RXDMA1]);
+	thc_copy_sgls_to_prd(dev, &dev->dma_ctx->dma_config[THC_RXDMA2]);
 }
 
 static void release_dma_buffers(struct thc_device *dev,

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb

             reply	other threads:[~2026-11-15  0:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  0:11 Emfox Zhou [this message]
2026-11-15  0:32 ` [PATCH v2] HID: intel-thc-hid: intel-thc: restore PRD table capacity sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261115001100.313270-1-emfox@debian.org \
    --to=emfox@debian.org \
    --cc=bentiss@kernel.org \
    --cc=even.xu@intel.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xinpeng.sun@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.