mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Even Xu <even.xu@intel.com>
To: bentiss@kernel.org, jikos@kernel.org
Cc: srinivas.pandruvada@linux.intel.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, Even Xu <even.xu@intel.com>,
	Rui Zhang <rui1.zhang@intel.com>
Subject: [PATCH 2/4] HID: Intel-thc-hid: Intel-quickspi: Use safe RXDMA reads
Date: Mon, 16 Nov 2026 16:27:58 +0800	[thread overview]
Message-ID: <20261116082805.3986615-3-even.xu@intel.com> (raw)
In-Reply-To: <20261116082805.3986615-1-even.xu@intel.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3041 bytes --]

Use thc_rxdma_read_safe() and pass the full input_buf allocation,
including the body header. Handle -EMSGSIZE in the receive loop by
skipping the discarded frame and continuing pending reports instead
of scheduling a full RXDMA recovery.

Fixes: 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPI driver")
Signed-off-by: Even Xu <even.xu@intel.com>
Tested-by: Rui Zhang <rui1.zhang@intel.com>
---
 .../hid/intel-thc-hid/intel-quickspi/pci-quickspi.c  | 12 ++++++++----
 .../hid/intel-thc-hid/intel-quickspi/quickspi-dev.h  |  7 +++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
index ec974d549a92..703ba238c02a 100644
--- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
+++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
@@ -324,8 +324,12 @@ static irqreturn_t quickspi_irq_thread_handler(int irq, void *dev_id)
 
 	if (int_mask & BIT(THC_RXDMA2_INT)) {
 		while (!read_finished) {
-			ret = thc_rxdma_read(qsdev->thc_hw, THC_RXDMA2, qsdev->input_buf,
-					     &input_len, &read_finished);
+			ret = thc_rxdma_read_safe(qsdev->thc_hw, THC_RXDMA2, qsdev->input_buf,
+						  HIDSPI_INPUT_BODY_SIZE(qsdev->input_len),
+						  &input_len, &read_finished);
+			if (ret == -EMSGSIZE)
+				continue;
+
 			if (ret) {
 				err_recover = 1;
 				goto end;
@@ -550,7 +554,7 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
 		return -ENOMEM;
 
 	max_input_len = max(le16_to_cpu(qsdev->dev_desc.rep_desc_len),
-			    le16_to_cpu(qsdev->dev_desc.max_input_len));
+			    le16_to_cpu(qsdev->dev_desc.max_input_len)) + QUICKSPI_DMA_EXTRA_BYTE;
 
 	qsdev->input_buf = devm_kzalloc(qsdev->dev,
 					HIDSPI_INPUT_BODY_SIZE(max_input_len), GFP_KERNEL);
@@ -560,7 +564,7 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
 	qsdev->input_len = max_input_len;
 
 	max_report_len = max(le16_to_cpu(qsdev->dev_desc.max_output_len),
-			     le16_to_cpu(qsdev->dev_desc.max_input_len));
+			     le16_to_cpu(qsdev->dev_desc.max_input_len)) + QUICKSPI_DMA_EXTRA_BYTE;
 
 	qsdev->report_buf = devm_kzalloc(qsdev->dev,
 					 HIDSPI_OUTPUT_REPORT_SIZE(max_report_len), GFP_KERNEL);
diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
index 4362ac568bda..e8ddb504ccc7 100644
--- a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
+++ b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
@@ -54,6 +54,13 @@
 #define MAX_PACKET_SIZE_VALUE_MTL			128
 #define MAX_PACKET_SIZE_VALUE_LNL			256
 
+/*
+ * During HID-over-SPI transfers, THC DMA may also read bytes that aren’t
+ * part of the actual data, such as a placeholder byte used for timing
+ * control (8 clock cycles).
+ */
+#define QUICKSPI_DMA_EXTRA_BYTE				1
+
 /*
  * THC uses runtime auto suspend to dynamically switch between THC active LTR
  * and low power LTR to save CPU power.
-- 
2.43.0


  parent reply	other threads:[~2026-11-16  8:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  8:27 [PATCH 0/4] Fix potential THC DMA issues Even Xu
2026-11-16  8:27 ` [PATCH 1/4] HID: Intel-thc-hid: Intel-thc: Add safe DMA read interfaces Even Xu
2026-11-16  8:27 ` Even Xu [this message]
2026-11-16  8:27 ` [PATCH 3/4] HID: Intel-thc-hid: Intel-quicki2c: Use safe DMA reads Even Xu
2026-11-16  8:28 ` [PATCH 4/4] HID: Intel-thc-hid: Intel-thc: Restore RXDMA after SWDMA operation errors Even Xu

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=20261116082805.3986615-3-even.xu@intel.com \
    --to=even.xu@intel.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rui1.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.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 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®