From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: jikos@kernel.org, bentiss@kernel.org
Cc: linux-input@vger.kernel.org,
kernel@lists.opengamingcollective.org,
gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
pgriffais@valvesoftware.com, derekjohn.clark@gmail.com,
stable@vger.kernel.org
Subject: [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend
Date: Thu, 3 Dec 2026 16:18:43 -0800 [thread overview]
Message-ID: <20261204001846.3801336-6-derekjohn.clark@gmail.com> (raw)
In-Reply-To: <20261204001846.3801336-1-derekjohn.clark@gmail.com>
Four write paths upstream end with SYNC_TO_ROM, a command sent with no
timeout, so the MCU can still owe an ACK at any moment. Suspend only
cancelled work items. A store issued against the suspending interface
armed a command, waited its full 25 ms and returned -EBUSY, the same
code a missing reply used, and a profile sequence could be cut between
two reports, leaving the MCU working copy and the driver cache
describing different profiles.
Gate commands on a suspended flag. Suspend and resume take rom_mutex
along with it, so a write sequence is indivisible with respect to the
transition, and the 500 ms the driver already documents for the MCU to
come back is now enforced. Commands fail until cfg_resume_fn opens the
gate. A missing reply reports -ETIMEDOUT, since -EBUSY now means
suspended. Suspend waits out an outstanding orphan ACK so no reply
expectation is carried across the transition. That wait covers an ACK
the MCU gives straight away. A device that answers a commit only when
the flash write finishes runs past it.
Fixes: a9517958e828 ("HID: hid-msi: Add MSI Claw configuration driver")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index 606ff7d65276..d6134ff310f3 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -344,6 +344,7 @@ struct claw_drvdata {
spinlock_t cmd_lock; /* Lock for cmd data read/write */
u8 waiting_cmd;
int cmd_status;
+ bool suspended;
u16 bcd_device;
bool resync; /* Re-read MCU state, set on resume after a device reset */
u8 ep;
@@ -576,6 +577,9 @@ static int __claw_hw_output_report(struct hid_device *hdev, u8 index, u8 *data,
lockdep_assert_held(&drvdata->cfg_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
/* If expecting an orphan ack, hold next event until MCU has time to clear it */
scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
orphaned = drvdata->orphan_ack_pending;
@@ -627,7 +631,7 @@ static int __claw_hw_output_report(struct hid_device *hdev, u8 index, u8 *data,
msecs_to_jiffies(timeout));
dev_dbg(&hdev->dev, "Remaining timeout: %u\n", ret);
- ret = ret > 0 ? drvdata->cmd_status : ret ?: -EBUSY;
+ ret = ret > 0 ? drvdata->cmd_status : ret ?: -ETIMEDOUT;
if (ret)
goto err;
}
@@ -877,6 +881,8 @@ static ssize_t apply_store(struct device *dev, struct device_attribute *attr,
flush_delayed_work(&drvdata->rgb_queue);
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
if (ret)
@@ -948,6 +954,9 @@ static int claw_mkey_store(struct device *dev, const char *buf, u8 mkey)
set_buttons:
scoped_guard(mutex, &drvdata->rom_mutex) {
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1077,6 +1086,9 @@ static ssize_t rumble_intensity_left_store(struct device *dev,
report.intensity = val;
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1142,6 +1154,9 @@ static ssize_t rumble_intensity_right_store(struct device *dev,
report.intensity = val;
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1290,6 +1305,9 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
}
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
/* Loop through (up to) 8 pages of RGB data */
for (f = 0; f < drvdata->rgb_frame_count; f++) {
scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
@@ -1818,6 +1836,10 @@ static void cfg_resume_fn(struct work_struct *work)
struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
bool gp_registered, rgb_registered, resync;
+ scoped_guard(mutex, &drvdata->rom_mutex)
+ scoped_guard(mutex, &drvdata->cfg_mutex)
+ drvdata->suspended = false;
+
/* Pairs with smp_store_release from claw_resume in process context */
resync = smp_load_acquire(&drvdata->resync);
@@ -2027,7 +2049,7 @@ static int claw_resume(struct hid_device *hdev, bool resync)
smp_store_release(&drvdata->resync, true);
}
- /* MCU can take up to 500ms to be ready after resume */
+ /* Give the MCU time to come back, cfg_resume_fn clears the gate */
schedule_delayed_work(&drvdata->cfg_resume, msecs_to_jiffies(500));
return 0;
}
@@ -2062,6 +2084,7 @@ static int msi_reset_resume(struct hid_device *hdev)
static int claw_suspend(struct hid_device *hdev)
{
struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
+ bool orphaned;
if (!drvdata)
return -ENODEV;
@@ -2070,6 +2093,22 @@ static int claw_suspend(struct hid_device *hdev)
cancel_delayed_work_sync(&drvdata->cfg_setup);
cancel_delayed_work_sync(&drvdata->rgb_queue);
+ guard(mutex)(&drvdata->rom_mutex);
+ guard(mutex)(&drvdata->cfg_mutex);
+ drvdata->suspended = true;
+
+ scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
+ orphaned = drvdata->orphan_ack_pending;
+
+ if (orphaned) {
+ if (!wait_for_completion_timeout(&drvdata->orphan_ack_complete,
+ msecs_to_jiffies(25)))
+ dev_dbg(&hdev->dev, "Timed out waiting for orphan ACK\n");
+
+ scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
+ drvdata->orphan_ack_pending = false;
+ }
+
return 0;
}
--
2.56.0
next prev parent reply other threads:[~2026-12-04 0:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
2026-12-04 0:18 ` [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute Derek J. Clark
2026-12-04 0:18 ` [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock Derek J. Clark
2026-12-04 0:18 ` [PATCH 4/8] HID: hid-msi: Re-init on reset during resume Derek J. Clark
2026-12-04 0:18 ` Derek J. Clark [this message]
2026-12-04 0:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
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=20261204001846.3801336-6-derekjohn.clark@gmail.com \
--to=derekjohn.clark@gmail.com \
--cc=bentiss@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jikos@kernel.org \
--cc=kernel@lists.opengamingcollective.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pgriffais@valvesoftware.com \
--cc=stable@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