From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Benson Leung <bleung@chromium.org>
Cc: tzungbi@kernel.org, chrome-platform@lists.linux.dev
Subject: [PATCH 5/9] platform/chrome: cros_ec_proto: Guard protocol v2 fallback
Date: Tue, 24 Nov 2026 08:21:08 +0000 [thread overview]
Message-ID: <20261124082112.3361229-6-tzungbi@kernel.org> (raw)
In-Reply-To: <20261124082112.3361229-1-tzungbi@kernel.org>
cros_ec_query_all() falls back to cros_ec_get_proto_info_legacy()
whenever cros_ec_get_proto_info() returned any error. Because
cros_ec_get_proto_info_legacy() clears `ec_dev->pkt_xfer`, a transient
failure during initial probe or a runtime re-query can permanently
downgrade a v3 EC to v2, or mask the real error with -EIO on v3-only
transports without `cmd_xfer`.
Add cros_ec_proto_can_fallback_to_v2() to avoid falling back when:
- The device is already registered with `pkt_xfer` (known v3+ EC).
- `ec_dev->cmd_xfer` is not supported (doesn't support v2).
- The v3 query failed with a transient error (-ENOMEM or -EAGAIN).
Also skip the v3 probe and call cros_ec_get_proto_info_legacy() directly
when `ec_dev->pkt_xfer` is already NULL (known v2-only EC).
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto.c | 55 ++++++++++++++++++-------
1 file changed, 40 insertions(+), 15 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index d48d3c73ca0b..d8ab82154c92 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -595,6 +595,24 @@ static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev,
return ret;
}
+static bool cros_ec_proto_can_fallback_to_v2(struct cros_ec_device *ec_dev,
+ int ret)
+{
+ /* The EC does support v3. */
+ if (ec_dev->registered && ec_dev->pkt_xfer)
+ return false;
+
+ /* The transport doesn't support v2. */
+ if (!ec_dev->cmd_xfer)
+ return false;
+
+ /* The system or EC is encountering transient failures. */
+ if (ret == -ENOMEM || ret == -EAGAIN)
+ return false;
+
+ return true;
+}
+
/**
* cros_ec_query_all() - Query the protocol version supported by the
* ChromeOS EC.
@@ -607,23 +625,30 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
u32 ver_mask;
int ret;
- /* First try sending with proto v3. */
- if (!cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_EC_INDEX)) {
- /* Check for PD. */
- cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_PD_INDEX);
+ if (ec_dev->pkt_xfer) {
+ /* First try sending with proto v3. */
+ ret = cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_EC_INDEX);
+
+ if (!ret) {
+ /* Check for optional PD chip; ignore errors. */
+ cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_PD_INDEX);
+ } else if (cros_ec_proto_can_fallback_to_v2(ec_dev, ret)) {
+ /* Fall back to querying with a v2 hello message. */
+ ret = cros_ec_get_proto_info_legacy(ec_dev);
+ }
} else {
- /* Try querying with a v2 hello message. */
+ /* pkt_xfer is NULL (v2-only EC); query with v2 directly. */
ret = cros_ec_get_proto_info_legacy(ec_dev);
- if (ret) {
- /*
- * It's possible for a test to occur too early when
- * the EC isn't listening. If this happens, we'll
- * test later when the first command is run.
- */
- ec_dev->proto_version = EC_PROTO_VERSION_UNKNOWN;
- dev_dbg(ec_dev->dev, "EC query failed: %d\n", ret);
- return ret;
- }
+ }
+ if (ret) {
+ /*
+ * It's possible for a test to occur too early when
+ * the EC isn't listening. If this happens, we'll
+ * test later when the first command is run.
+ */
+ ec_dev->proto_version = EC_PROTO_VERSION_UNKNOWN;
+ dev_dbg(ec_dev->dev, "EC query failed: %d\n", ret);
+ return ret;
}
/* Probe if MKBP event is supported */
--
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 ` [PATCH 2/9] platform/chrome: cros_ec_proto: Retry sending command on -EAGAIN Tzung-Bi Shih
2026-11-24 8:21 ` [PATCH 3/9] platform/chrome: KUnit: Add tests for retrying commands " 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 ` Tzung-Bi Shih [this message]
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-6-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