From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Benson Leung <bleung@chromium.org>
Cc: tzungbi@kernel.org, chrome-platform@lists.linux.dev
Subject: [PATCH 2/9] platform/chrome: cros_ec_proto: Retry sending command on -EAGAIN
Date: Tue, 24 Nov 2026 08:21:05 +0000 [thread overview]
Message-ID: <20261124082112.3361229-3-tzungbi@kernel.org> (raw)
In-Reply-To: <20261124082112.3361229-1-tzungbi@kernel.org>
Underlying transport mediums can be transiently unavailable and return
-EAGAIN. Retry sending the command in cros_ec_send_command() up to
EC_COMMAND_SEND_RETRIES times with a short delay between attempts.
Check `msg->result == EC_RES_IN_PROGRESS` before retrying so commands
that are already executing on the EC go directly to
cros_ec_wait_until_complete().
Similarly, continue polling in cros_ec_wait_until_complete() when
EC_CMD_RESEND_RESPONSE fails with -EAGAIN.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 0306bedd0f0f..135134a1e317 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -16,6 +16,7 @@
#include "cros_ec_trace.h"
#define EC_COMMAND_RETRIES 50
+#define EC_COMMAND_SEND_RETRIES 5
#define RWSIG_CONTINUE_RETRIES 8
#define RWSIG_CONTINUE_MAX_ERRORS_IN_ROW 3
@@ -194,6 +195,9 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev,
orig_msg->command = orig_cmd;
orig_msg->outsize = orig_outsize;
orig_msg->version = orig_version;
+
+ if (ret == -EAGAIN)
+ continue;
return ret;
}
}
@@ -203,10 +207,19 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev,
static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
{
- int ret = cros_ec_xfer_command(ec_dev, msg);
+ int retry_count = EC_COMMAND_SEND_RETRIES;
+ int ret;
+
+retry:
+ ret = cros_ec_xfer_command(ec_dev, msg);
if (msg->result == EC_RES_IN_PROGRESS)
- ret = cros_ec_wait_until_complete(ec_dev, msg);
+ return cros_ec_wait_until_complete(ec_dev, msg);
+
+ if (ret == -EAGAIN && retry_count--) {
+ usleep_range(10000, 11000);
+ goto retry;
+ }
return ret;
}
--
2.56.1.831.g720f3f5937-goog
next prev parent reply other threads:[~2026-11-24 8:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:21 [PATCH 0/9] platform/chrome: cros_ec_proto: Harden query_all() and retries Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 1/9] platform/chrome: cros_ec_proto: Reset msg->result before sending command Tzung-Bi Shih
2026-11-24 8:21 ` Tzung-Bi Shih [this message]
2026-11-24 8:21 ` [PATCH 3/9] platform/chrome: KUnit: Add tests for retrying commands on -EAGAIN Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 4/9] platform/chrome: cros_ec_proto: Reallocate din/dout buffers atomically Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 5/9] platform/chrome: cros_ec_proto: Guard protocol v2 fallback Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 6/9] platform/chrome: KUnit: Update test cases for protocol v2 Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 7/9] platform/chrome: KUnit: Add test cases for protocol fallback Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 8/9] platform/chrome: cros_ec_proto: Propagate feature probe errors Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 9/9] platform/chrome: KUnit: Add feature probe unsupported tests Tzung-Bi Shih
2026-11-27 5:03 ` [PATCH 0/9] platform/chrome: cros_ec_proto: Harden query_all() and retries Tzung-Bi Shih
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=20261124082112.3361229-3-tzungbi@kernel.org \
--to=tzungbi@kernel.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
/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