mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kenhou Iijima <kenhou@kenhou.net>
To: "Derek J . Clark" <derekjohn.clark@gmail.com>,
	Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>
Cc: Denis Benato <denis.benato@linux.dev>,
	Zhouwang Huang <honjow311@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kenhou Iijima <kenhou@kenhou.net>
Subject: [PATCH v3] HID: hid-msi: Ignore unexpected 0x06 ACKs outside WRITE_PROFILE_DATA
Date: Mon, 16 Nov 2026 22:46:33 +0900	[thread overview]
Message-ID: <20261116134633.5498-1-kenhou@kenhou.net> (raw)
In-Reply-To: <20261114125059.17772-1-kenhou@kenhou.net>

On the MSI Claw handhelds (e.g. 0db0:1901), some timeout-0 commands
answer with more than one generic 0x06 ACK: SYNC_TO_ROM (0x22) sends an
immediate ACK plus a flash commit ACK about 560 ms later, and
SWITCH_MODE (0x24) can answer with a second ACK about 15 ms after the
command (~8 ms after the first ACK). The first ACK is consumed by the
orphan_ack_pending path; the delayed ones fall through to the rest of
the CLAW_COMMAND_TYPE_ACK handler.

That handler only ignores an ACK when waiting_cmd is
CLAW_COMMAND_TYPE_NONE. If a delayed 0x06 arrives while a read command
is in flight, e.g. READ_GAMEPAD_MODE after an RGB update sequence, the
ACK completes send_cmd_complete early without invoking the read response
handler: the caller returns stale cached data and the real 0x27 reply
arriving moments later is discarded. Reproduced on firmware 2.30: a
READ_GAMEPAD_MODE that normally takes about 6 ms completed in 1.56 ms
and returned the cached gamepad mode. The same fall-through also makes
every expected second ACK print a "Got unexpected ACK from MCU"
dev_warn during normal operation.

Only WRITE_PROFILE_DATA (0x21) waits for a generic 0x06 ACK; reads wait
for their own ACK command types. Complete send_cmd_complete on an ACK
only while WRITE_PROFILE_DATA is pending, and downgrade the rest to a
dev_dbg including the command being waited on so they can still be
traced when needed.

Fixes: a9517958e828 ("HID: hid-msi: Add MSI Claw configuration driver")
Signed-off-by: Kenhou Iijima <kenhou@kenhou.net>
---
Changes in v3:
- Apologies for the noise in v1/v2: the "MCU re-sends the 0x06 ACK
  every ~2 s" claim was my own misdiagnosis. A local userspace LED
  daemon on my test machine had a bug that kept re-writing the LED
  sysfs every ~2 s, and each write's trailing SYNC_TO_ROM produced its
  normal ~560 ms flash-commit ACK. Timestamped captures of the config
  interface on firmware 2.30 with local userspace helpers stopped
  confirm the firmware only ever sends the two ACKs described above.
  Drop orphan_ack_work, claw_orphan_ack_drain(), the
  disable_work_sync()/enable_work() pairing and the .reset_resume hook
  accordingly: there is nothing left to drain.
- Keep the core fix: complete send_cmd_complete on a generic 0x06 ACK
  only while WRITE_PROFILE_DATA is pending, and demote the
  ignored-ACK log to dev_dbg with the command being waited on.

- Link to v2: https://lore.kernel.org/linux-input/20261114125059.17772-1-kenhou@kenhou.net/
- Link to v1: https://lore.kernel.org/linux-input/20261114101045.21986-1-kenhou@kenhou.net/
 drivers/hid/hid-msi.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index 23d731f700..0c30846ac8 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -531,8 +531,20 @@ static int claw_raw_event(struct claw_drvdata *drvdata, struct hid_report *repor
 			break;
 		}
 
-		if (drvdata->waiting_cmd == CLAW_COMMAND_TYPE_NONE) {
-			dev_warn(&drvdata->hdev->dev, "Got unexpected ACK from MCU, ignoring\n");
+		if (drvdata->waiting_cmd != CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA) {
+			/*
+			 * Only WRITE_PROFILE_DATA waits for a generic 0x06 ACK;
+			 * reads wait for their own ACK command type. SYNC_TO_ROM
+			 * answers twice (an immediate ACK and a flash commit ACK
+			 * ~560 ms later) and SWITCH_MODE can answer with a second
+			 * delayed ACK as well; the first is consumed above, so any
+			 * 0x06 arriving here is a leftover of an already finished
+			 * command. Ignore it instead of completing the pending
+			 * read early.
+			 */
+			dev_dbg(&drvdata->hdev->dev,
+				"Got unexpected ACK from MCU, ignoring (waiting CMD: %x)\n",
+				drvdata->waiting_cmd);
 			break;
 		}
 
-- 
2.56.0


      reply	other threads:[~2026-11-16 13:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 10:10 [PATCH] HID: hid-msi: Drain orphan MCU ACKs by issuing a query Kenhou Iijima
2026-11-14 12:50 ` [PATCH v2] " Kenhou Iijima
2026-11-16 13:46   ` Kenhou Iijima [this message]

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=20261116134633.5498-1-kenhou@kenhou.net \
    --to=kenhou@kenhou.net \
    --cc=bentiss@kernel.org \
    --cc=denis.benato@linux.dev \
    --cc=derekjohn.clark@gmail.com \
    --cc=honjow311@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®