Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2624266imn; Tue, 2 Aug 2022 09:45:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR6aaTuN+JGbZUJ2sUzk8AGzxGiQma/sN9fTbjGHm2vD26KiYg0Tat3mqccwsoGuPZpSVFsg X-Received: by 2002:a17:90b:3141:b0:1f2:c6d9:6bc4 with SMTP id ip1-20020a17090b314100b001f2c6d96bc4mr401827pjb.30.1659458705412; Tue, 02 Aug 2022 09:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659458705; cv=none; d=google.com; s=arc-20160816; b=04oppyJbHvEa/9l3ynS3u2mpbCx//phRfgmDdiNsUgW8/3sORThecICuDfPMyZPWUk s7rUT+A1tAUm5Ygc3MsQq/8tZ66qYFCDUS38duR/A0XBZAwqoDjjxBPZwCYfVGh0YfsH DrAEoV4cXAUYNmCxmdQMcAV1rF0iotGYM5l2ohMcNHBfZ5Hf5CnsQz6akcr1NV89P82l TbEAesREwMgeoHfbmGyQomPedyQWDpbFFqdYK23aZ9x6keVrqEiFSlaGVGBM2fzS8QcI OoiMyc8i4o6h1KEb3nVkJDY2Md6Nwi2pQTUEWDqreAyv23wdM01ToUyLtdWdXwZjIbqh IA/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3lh5+NDK8urhSXXnABP31QYe2HngTKZ+2NZLHLYtY/E=; b=skgBQee6uJMjsw3K0Rw4WCV63Tn5RNzfWisUeg3Dhn3i7bUTfYudObpT4Q41ignipm 1tTQkegaYRFGpz7OqrY+yNUvyoZ2DinIw82I8oph9FmyVUR44gh4J5Ed6YvSG2jyx+B1 DUPQzSgmxSgw8FR7I+2P1HXImrhaXPAdu2sO4oIRo874fAmQ7VIJDQBXN4iepMwBRDX5 E6nu6Jl0+Mu+psDn+kLRSz6L0Vyk+nBGsS9AKFd+6Etc2DecwncPQhozVsRd++zQ0EdM G2OyYBD5SKxuuz3jphKyd8yFWkqi6HA8IGyiQl4wGkQAHx3iX3EtYtQC9ryoMlW8rDPU 2JeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=VBlTac0+; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 130-20020a630188000000b0041b8a07a6fcsi3947277pgb.673.2022.08.02.09.44.51; Tue, 02 Aug 2022 09:45:05 -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=@semihalf.com header.s=google header.b=VBlTac0+; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232190AbiHBPlw (ORCPT + 99 others); Tue, 2 Aug 2022 11:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231539AbiHBPli (ORCPT ); Tue, 2 Aug 2022 11:41:38 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76A172713 for ; Tue, 2 Aug 2022 08:41:36 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id z20so8917714ljq.3 for ; Tue, 02 Aug 2022 08:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3lh5+NDK8urhSXXnABP31QYe2HngTKZ+2NZLHLYtY/E=; b=VBlTac0+eLNkOx8fS58zP9Gq+9N19XfcbKIcwUGy1r6R//BvK+/12ohliAH9/U7su+ axV5laSlVYkKOuorL0lNAjkj87Wwm0T+OdWdmCjbhKNh9sI5+eocDQSfmWP1JGqOH9mW XbiU+kukMK2x/p0auilmuEN2nWoqt1Zcriq0OUYnD33TtkwnWBF8FSGd4f8ZWg71NMSS d7cyejhTVYsBVly1SyQ17qdpU9e7ZtKNyIrKPVNIqs+bJU+UZoTa8Ob+UFgHoME9ddoG 1VJKd9Hs8DbvAFjxutvDkdyXGa0s2nlziYRr0VaswnhiPy1V2FoH5ulw9y403y+Vcp0I 08ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3lh5+NDK8urhSXXnABP31QYe2HngTKZ+2NZLHLYtY/E=; b=WGjTmbp7FEVaDScfEH/voD5iq2A2DTHY5pBdwpZaQcb5gtlkngi5GRL7B3toGGYVag czk/LpN53Vw4yKsrW7WZpBNzaduJuIe7HYN4cEt6GrrvarfVcGgJebbvJbcgOk1pD01o ofsUeXjkuRsaB1gXHqiJ82HMwTaeZdzDb/Ow0ZNynHwk8xJoqkhqeZwwC8b904pn6W0Y cBtCzGXTZJZBRUlvx9nYuLQ3xgZ0V1dxn37fKNJz7SBJ1t/GPWxH58R8Ek3j7v1k8wWG VJNq/YOHmZeZCTLeL3EDRUs3TGAgdYmYHgLEiD9p32KresX1QP6fGjWCQOwTFj5IjjvM TkIg== X-Gm-Message-State: ACgBeo1dKCvzGfjv6Duk10nCCbPYnoJR/yn6vg4YMYsJrr+bvLn44iu7 7Y0NMGjrqVjzgagOUF792+iACA== X-Received: by 2002:a2e:a168:0:b0:25e:4dbc:2ac0 with SMTP id u8-20020a2ea168000000b0025e4dbc2ac0mr3437928ljl.187.1659454894796; Tue, 02 Aug 2022 08:41:34 -0700 (PDT) Received: from pdkmachine.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p3-20020a2e7403000000b0025e0b9ea91csm1932193ljc.84.2022.08.02.08.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:41:34 -0700 (PDT) From: Patryk Duda To: Benson Leung Cc: Guenter Roeck , Gwendal Grignou , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, upstream@semihalf.com, Patryk Duda Subject: [PATCH v1] platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure Date: Tue, 2 Aug 2022 17:41:28 +0200 Message-Id: <20220802154128.21175-1-pdk@semihalf.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220714160951.9364-1-pdk@semihalf.com> References: <20220714160951.9364-1-pdk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 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 --- 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 v0 -> v1 - Dropped `ver_mask` initialization. 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 ff767dccdf0f..c1df8e7e48af 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; /* * 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.35.1