From: Guenter Roeck <groeck@google.com>
To: Patryk Duda <pdk@semihalf.com>
Cc: Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
"open list:CHROME HARDWARE PLATFORM SUPPORT"
<chrome-platform@lists.linux.dev>,
linux-kernel <linux-kernel@vger.kernel.org>,
upstream@semihalf.com
Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure
Date: Thu, 14 Jul 2022 09:31:25 -0700 [thread overview]
Message-ID: <CABXOdTck1VSxf8r-NGW_YCvpMdLe7hx=7sGFzQVH9Ok51hfbQg@mail.gmail.com> (raw)
In-Reply-To: <20220714160951.9364-1-pdk@semihalf.com>
On Thu, Jul 14, 2022 at 9:09 AM Patryk Duda <pdk@semihalf.com> wrote:
>
> Some EC based devices (e.g. Fingerpint MCU) can jump to RO part of the
> firmware (intentionally or due to device reboot). The RO part doesn't
> change during the device lifecycle, so it won't support newer version
> of EC_CMD_GET_NEXT_EVENT command.
>
> Function cros_ec_query_all() is responsible for finding maximum
> supported MKBP event version. It's usually called when the device is
> running RW part of the firmware, so the command version can be
> potentially higher than version supported by the RO.
>
> The problem was fixed by updating maximum supported version when the
> device returns EC_RES_INVALID_VERSION (mapped to -ENOPROTOOPT). That way
> the kernel will use highest common version supported by RO and RW.
>
> Fixes: 3300fdd630d4 ("platform/chrome: cros_ec: handle MKBP more events flag")
> Cc: <stable@vger.kernel.org> # 5.10+
> Signed-off-by: Patryk Duda <pdk@semihalf.com>
Nice catch. That may explain some hung task issues. observed in
EC_CMD_GET_NEXT_EVENT handling
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> When Fingerprint MCU is rebooted (e.g. as a part of tests) it jumps to
> the RO image and performs RW image signature check. If kernel calls
> EC_CMD_GET_NEXT_EVENT FPMCU RO will respond with EC_RES_INVALID_VERSION
> because it's older than RW and supports up to version 1 of the command.
> As a result kernel keeps trying to get MKBP events and effectively
> blocks FPMCU from jumping to RW image.
>
> Before patch 3300fdd630d4 the driver called version 1 of the command.
> If the device responded with EC_RES_INVALID_VERSION, the driver would
> use version 0 of the command.
>
> Best regards,
> Patryk
>
> drivers/platform/chrome/cros_ec_proto.c | 32 +++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index ff767dccdf0f6..0a131045d50a9 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -750,6 +750,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
> u8 event_type;
> u32 host_event;
> int ret;
> + u32 ver_mask = 0;
>
> /*
> * Default value for wake_event.
> @@ -771,6 +772,37 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
> return get_keyboard_state_event(ec_dev);
>
> ret = get_next_event(ec_dev);
> + /*
> + * -ENOPROTOOPT is returned when EC returns EC_RES_INVALID_VERSION.
> + * This can occur when EC based device (e.g. Fingerprint MCU) jumps to
> + * the RO image which doesn't support newer version of the command. In
> + * this case we will attempt to update maximum supported version of the
> + * EC_CMD_GET_NEXT_EVENT.
> + */
> + if (ret == -ENOPROTOOPT) {
> + dev_dbg(ec_dev->dev,
> + "GET_NEXT_EVENT returned invalid version error.\n");
> + ret = cros_ec_get_host_command_version_mask(ec_dev,
> + EC_CMD_GET_NEXT_EVENT,
> + &ver_mask);
> + if (ret < 0 || ver_mask == 0)
> + /*
> + * Do not change the MKBP supported version if we can't
> + * obtain supported version correctly. Please note that
> + * calling EC_CMD_GET_NEXT_EVENT returned
> + * EC_RES_INVALID_VERSION which means that the command
> + * is present.
> + */
> + return -ENOPROTOOPT;
> +
> + ec_dev->mkbp_event_supported = fls(ver_mask);
> + dev_dbg(ec_dev->dev, "MKBP support version changed to %u\n",
> + ec_dev->mkbp_event_supported - 1);
> +
> + /* Try to get next event with new MKBP support version set. */
> + ret = get_next_event(ec_dev);
> + }
> +
> if (ret <= 0)
> return ret;
>
> --
> 2.31.0
>
next prev parent reply other threads:[~2022-07-14 16:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 16:09 [PATCH] platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure Patryk Duda
2022-07-14 16:31 ` Guenter Roeck [this message]
2022-07-18 3:20 ` Tzung-Bi Shih
2022-08-02 15:41 ` [PATCH v1] " Patryk Duda
2022-08-04 9:00 ` Tzung-Bi Shih
2022-08-04 10:59 ` Patryk Duda
2022-08-05 2:40 ` patchwork-bot+chrome-platform
2022-08-15 3:44 ` patchwork-bot+chrome-platform
2022-08-15 3:55 ` patchwork-bot+chrome-platform
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='CABXOdTck1VSxf8r-NGW_YCvpMdLe7hx=7sGFzQVH9Ok51hfbQg@mail.gmail.com' \
--to=groeck@google.com \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=groeck@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pdk@semihalf.com \
--cc=upstream@semihalf.com \
/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;
as well as URLs for NNTP newsgroup(s).