Linux Input/HID development
 help / color / mirror / Atom feed
From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: Kenhou Iijima <kenhou@kenhou.net>
Cc: linux-input@vger.kernel.org, Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Ana Veto <green.koala2979@fastmail.com>
Subject: Re: [PATCH v3] HID: hid-msi: Ignore unexpected 0x06 ACKs outside WRITE_PROFILE_DATA
Date: Mon, 30 Nov 2026 17:25:05 -0800	[thread overview]
Message-ID: <20261201012506.2313913-1-derekjohn.clark@gmail.com> (raw)
In-Reply-To: <20261116134633.5498-1-kenhou@kenhou.net>

On Mon, 16 Nov 2026, Kenhou Iijima wrote:
> 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, ...

Kenhou,

Dropping the drain work and the .reset_resume hook deconflicts my pending
series that uses it to re-read the gamepad mode and the RGB profile after
a bus reset. Thank you for that.

The guard can still be completed by a subsequent WRITE_PROFILE_DATA within
the ACK window.

  t=0      store: WRITE_PROFILE_DATA, then SYNC_TO_ROM with timeout 0
  t=4ms    ACK 1 arrives, consumed by the orphan_ack_pending path
  t=10ms   next store: WRITE_PROFILE_DATA is the outstanding command
  t=560ms  ACK 2, the commit ACK for the command sent at t=0, arrives.
           With your guard it matches waiting_cmd == WRITE_PROFILE_DATA,
           so it completes that write. The store returns success for a
           write the MCU has not acknowledged, and the write's own ACK is
           then discarded because waiting_cmd is NONE by then.

If we add a counter of the ACK's incremented when the command that
produces it is sent, and drop it wherever it lands, then we can satisfy an
arbitrary number of sequential calls. Something like:

<8>
---
 drivers/hid/hid-msi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -339,6 +339,7 @@
 	spinlock_t profile_lock; /* Lock for profile_pending read/write */
 	struct hid_device *hdev;
 	bool orphan_ack_pending;
+	u8 late_acks; /* Second generic ACK the MCU still owes, guarded by cmd_lock */
 	struct mutex cfg_mutex; /* mutex for synchronous data */
 	struct mutex rom_mutex; /* mutex for SYNC_TO_ROM calls */
 	spinlock_t cmd_lock; /* Lock for cmd data read/write */
@@ -531,6 +532,12 @@
 			break;
 		}
 
+		if (drvdata->late_acks) {
+			drvdata->late_acks--;
+			dev_dbg(&drvdata->hdev->dev, "Dropped a counted MCU ACK\n");
+			break;
+		}
+
 		if (drvdata->waiting_cmd != CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA) {
 			/*
 			 * Only WRITE_PROFILE_DATA waits for a generic 0x06 ACK;
@@ -619,6 +626,15 @@
 			reinit_completion(&drvdata->orphan_ack_complete);
 			drvdata->waiting_cmd = CLAW_COMMAND_TYPE_NONE;
 			drvdata->orphan_ack_pending = true;
+			/*
+			 * SYNC_TO_ROM and SWITCH_MODE answer a second time, long after
+			 * the transfer that produced it. Count the extra ACK so it is
+			 * dropped wherever it lands rather than taken for the reply of
+			 * whatever command is pending when it arrives.
+			 */
+			if (index == CLAW_COMMAND_TYPE_SYNC_TO_ROM ||
+			    index == CLAW_COMMAND_TYPE_SWITCH_MODE)
+				drvdata->late_acks++;
 		}
 	}
 
@@ -652,6 +668,7 @@
 	scoped_guard(spinlock_irqsave, &drvdata->cmd_lock) {
 		drvdata->waiting_cmd = CLAW_COMMAND_TYPE_NONE;
 		drvdata->orphan_ack_pending = false;
+		drvdata->late_acks = 0;
 	}
 	return ret;
 }
@@ -2028,6 +2045,10 @@
 	cancel_delayed_work_sync(&drvdata->cfg_setup);
 	cancel_delayed_work_sync(&drvdata->rgb_queue);
 
+	/* A counted ACK can be overtaken by suspend and never arrive. */
+	scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
+		drvdata->late_acks = 0;
+
 	return 0;
 }
 

</8>

If you apply this on top for v4, please add these before your SOB:

  Co-developed-by: "Derek J. Clark" <derekjohn.clark@gmail.com>
  Signed-off-by: "Derek J. Clark" <derekjohn.clark@gmail.com>

Thanks,
Derek

      reply	other threads:[~2026-12-01  1:25 UTC|newest]

Thread overview: 5+ 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 10:29 ` sashiko-bot
2026-11-14 12:50 ` [PATCH v2] " Kenhou Iijima
2026-11-16 13:46   ` [PATCH v3] HID: hid-msi: Ignore unexpected 0x06 ACKs outside WRITE_PROFILE_DATA Kenhou Iijima
2026-12-01  1:25     ` Derek J. Clark [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=20261201012506.2313913-1-derekjohn.clark@gmail.com \
    --to=derekjohn.clark@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=green.koala2979@fastmail.com \
    --cc=jikos@kernel.org \
    --cc=kenhou@kenhou.net \
    --cc=linux-input@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