Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp728036imw; Thu, 14 Jul 2022 09:44:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tEooVcaXdgbyJ3WvXhvf1PxVBFcD8QmRRm5KqF4jMMwEQEuoKwC4iBnqqdCAsmrQKamTF/ X-Received: by 2002:a17:903:32c3:b0:16b:fbc3:3269 with SMTP id i3-20020a17090332c300b0016bfbc33269mr9768002plr.117.1657817060409; Thu, 14 Jul 2022 09:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657817060; cv=none; d=google.com; s=arc-20160816; b=kiNbjkSKMQ9BBVIC+7DkBqAmGWZbFjTy85A4g0+XfSX2HSf0ZWW752yAgKIy7+e5nM cH/aDKzCc+CzVHq5Hy+LiWS+9ruItofFHPIUvkIKORKM0upU95Sh5vBT+TT0aGSC2SMJ gWuqCzxZiYSPby0g2X1k3CQycXQ94M6nkmdSBmlquGL0ZbtkE5CLfYBmBBHyl43RXFs6 m9/3AUCbMmwGgdyGNojNwY+dGWPKzK9fwH56Xea21YM5MSdIYtvwYOwKVCsbJvuOYx81 vsQ0RACWdrPxHAMM04DYtROEi7kl0TxX1zHGs+9HtwrN6Rbkvoq40t6hgFHj718LT36C Rw+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=p//OL3T6T+iN+FpDjfuUmP5riPz2KYcNknEDuB/63us=; b=K/N2bQdsiOXtylpqKeSIL6T0Dl2jrqATj6hK8c5hDfHwYK8Z8atH0ZKOybC07XdrsQ Mex7TV2G/LH3qKhXg5xRUry5ExduLVpIg/3NY2Nx5oJCbBPCBkYurHdsKLf+bldRQcYz soQk93jdmQF8DQyNM+CPTftkMMO4yxlKJqxR7jjfZuF13G0INQzellxJ8XqoELW33TAB MklyRT4fMVw4H2CnsslzpRh3NgN979FT4iGv2TfW0CHTDELHcLSMduHEhKADOM5jIVDi 0HCgMFBTp6GgFPdpPG26sIy69Fqq+STX72Zl/gjim7ua+eBVOXBZljZAsuuySrXx13i8 6KXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HF8nglO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a170903228200b0016c46ef4762si2482316plh.315.2022.07.14.09.44.04; Thu, 14 Jul 2022 09:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HF8nglO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231649AbiGNQbq (ORCPT + 99 others); Thu, 14 Jul 2022 12:31:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239522AbiGNQbj (ORCPT ); Thu, 14 Jul 2022 12:31:39 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C82C655BB for ; Thu, 14 Jul 2022 09:31:38 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id ez10so4326244ejc.13 for ; Thu, 14 Jul 2022 09:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p//OL3T6T+iN+FpDjfuUmP5riPz2KYcNknEDuB/63us=; b=HF8nglO6RLS42LhMGPwU417dT3o8bFVVjPZzDZcbanY06ClqopKuBKQQU1LZQUhO5S NEhS+aWaepXdOK0WvU3br7GmA/8ahc2XqAOmWNJ+LFIbL+RcEv2urYKmBw5ajgqOGkeh apYfB5DJYPJq5LTDksliy4vJFF53Ir7RVtrshF8wUK7A1xTELvEProa/y6yELs/e4LY8 frplHjzR2nOycNk1RBKZBPcLuBQPOnjMfoqY3Tv+yo2z3BpQYuCcDhyl7sYevwjJr30D tDtvZwENa5izGVrK9Y4Y5+tbAIjm7w7cgNiSAYiIYQsaLhAPt3qGABGzy2VDl5VFQ4E6 +uGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p//OL3T6T+iN+FpDjfuUmP5riPz2KYcNknEDuB/63us=; b=RDLtyWh4SSMNh+RLrh54z/uT7JCs81vz5nXBbXQjjBpcrRdTfRqV6DUUDvxmCH4tLg 6ChCKLG51V90fbWwX0Mxf2jan28MhQGhySKoKhVl07LlVRu+e7ZCXE+saFcWqOXuQX42 YBTl0lDpaES7sl+8JO8ZNnkDpp02TzWzKXAWRZiuR+/Di0WMUxcVBCT5FUgERyN12Q0l Zq8wPzgO1mHe29VBSFpweBfr3gvNd+41chzONUqkbAFGCcdi4ua8EyOWtOPBcASsEsr6 KVwnKTqA+yQQdBo92D/QNjtecIUllaD/22D+NxPoRYnRbhCMZHbG4DpKUG14Xn51i7xd rd5g== X-Gm-Message-State: AJIora88slSYk0ct8A5ypqZDG4Lc6KF3xbtx2VgTSnenz4Ry4Y2/0Rpp rkVwrnonRTf6b3q+ZCH9WCw6ZIe+NLnpEF0XtoHS3w== X-Received: by 2002:a17:906:9753:b0:722:f1e3:ec27 with SMTP id o19-20020a170906975300b00722f1e3ec27mr9415771ejy.355.1657816296819; Thu, 14 Jul 2022 09:31:36 -0700 (PDT) MIME-Version: 1.0 References: <20220714160951.9364-1-pdk@semihalf.com> In-Reply-To: <20220714160951.9364-1-pdk@semihalf.com> From: Guenter Roeck Date: Thu, 14 Jul 2022 09:31:25 -0700 Message-ID: Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure To: Patryk Duda Cc: Benson Leung , Guenter Roeck , "open list:CHROME HARDWARE PLATFORM SUPPORT" , linux-kernel , upstream@semihalf.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 14, 2022 at 9:09 AM Patryk Duda 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: # 5.10+ > Signed-off-by: Patryk Duda Nice catch. That may explain some hung task issues. observed in EC_CMD_GET_NEXT_EVENT handling Reviewed-by: Guenter Roeck > --- > 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 >