Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1707929ybl; Tue, 3 Dec 2019 11:22:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyRkKSNo5GyWZfHWI4gv/luSdaEBw2BqFTKkKQYCrHOZGbbjsNeaOSx3BWZG59GwEC6SAXV X-Received: by 2002:a05:6808:6cc:: with SMTP id m12mr4703485oih.111.1575400964161; Tue, 03 Dec 2019 11:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575400964; cv=none; d=google.com; s=arc-20160816; b=GqujVMJ4domYtIj9DkD+mT6MH0H2r4gmIDljrih8g4G67ESVj/9Y6VgwpYTOMtn9Bd pMzkWwmLzSL6/ah39KFT5IARrFp57rfD3UUCZ67E+bcOk+FII8LR0y73EA068uQx7Ki8 3vFnGtiYy/CrFWtY16pbFtlIqfD0GPa0h64CKPcSFl2YhkfNZXXLA7w+CbpCD+hgK8Co 5CQZUQ34FuEyqhN2nGVdxqJ0uzla1NiowSQrLgWKfv8wkhIWibWdAIxwlnovG7Qdr77m V+TnNVGWvjVXm79bpiA+HMIq68zBXuNmpCXS7sjTjnK/REWfllgQr7MTc6tfeGiMVFlL KpCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TvP+g3uBvcOeVSsYMJC2xWkgAecurGtEzVkTlid2Ttg=; b=VMlpQJwlVNrqrcGhxpQz2FGRwCx6VxpaaKobEYFsl3H5KDiHmHBHHEZrRz36sYNmPt Ah/K2e2W7Nruw+z8WGDo6Dt404Dvudi5YLbTnuiOgsn7SeOwZ2oKy7+3MOL5A3pdqcQQ foYgSGD5st3Tgf7Vqp100Ik8wJOBHdkjlyXLTNVynnuLMPnq7E12hPARRsBAUKf6gu6+ +cR7BvhRM5ev9iJYelmmkykrG2QCxOOgDyE1UCr1w/vyb5HefzvKbZdNtZQxxxXa6MAn xyGX0IYkZJ8O+laKv2u6IkWi1mKTgoPQRQdZXH4hdND6toHQbtLZIdjlvqaYR8sLsz3t meDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YglsSYyh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si1828999otr.45.2019.12.03.11.22.30; Tue, 03 Dec 2019 11:22:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YglsSYyh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727356AbfLCTUd (ORCPT + 99 others); Tue, 3 Dec 2019 14:20:33 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:38520 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbfLCTUd (ORCPT ); Tue, 3 Dec 2019 14:20:33 -0500 Received: by mail-io1-f67.google.com with SMTP id u7so2541177iop.5 for ; Tue, 03 Dec 2019 11:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TvP+g3uBvcOeVSsYMJC2xWkgAecurGtEzVkTlid2Ttg=; b=YglsSYyhj3CbWpRQaNc1+jdSd4UFPkeL0FrBUG3JFYVDt6ZHcp4GHgOgfjFW63CeSq wjcVRMQypFrlxk43qsWO7E4gnvcN1jL4Or+j3wn/mnT2KNl8OODpzOsyjYkxJKKz1aPC rqou8VsOjXZa653rs/6OVRGcX3IuVVAG1nLWQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TvP+g3uBvcOeVSsYMJC2xWkgAecurGtEzVkTlid2Ttg=; b=Qnoe1upZCQygiuKjg44q3wQZtq+2XvodjhN+fWKMPygtzE0zu9iTVJtWMYUiFFX3Hn +JhxmduBvUDKruPTrW4u9pVjBVKvBuQP65ooE9L8nwhm8KqpzKtY5XTMm7nXCDZPFwP7 x3fEvbkSsxcEsOix0E3FeyZmMI+CSgBQE5D0peq1F+wfpC9mdFQM3gsre604nnvBi5gB BvJ6vrSGGMFidw2AjAYfTSvgB6MWqlNXpqJzVYXkPvhsvyn2BXxmN5gQcIbWKVGYREk6 6h52koUaxgJysGoh60ICW39GjT7rMnEXiibYBqzS5PKfYE8Ldv3IbcQ4hORhLqEC8JmK ARcQ== X-Gm-Message-State: APjAAAV63E5AKBR/dcOKkZ3H5H0gSHhNHiLLJ1scq8U9v5zIVzMB2Yek NqrPACFoG0Yx2LTF78FS2h4fPn/2oKTchnb4AimKvA== X-Received: by 2002:a02:334b:: with SMTP id k11mr1805276jak.51.1575400831955; Tue, 03 Dec 2019 11:20:31 -0800 (PST) MIME-Version: 1.0 References: <0f223903-ec93-a5ec-e858-fa0e2e282cf3@collabora.com> <20191125221517.91611-1-yichengli@chromium.org> <5fd3e86c-21ac-82fb-c3c5-4ff1f43e0219@collabora.com> In-Reply-To: <5fd3e86c-21ac-82fb-c3c5-4ff1f43e0219@collabora.com> From: Gwendal Grignou Date: Tue, 3 Dec 2019 11:20:21 -0800 Message-ID: Subject: Re: [PATCH v4] mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW To: Enric Balletbo i Serra Cc: Yicheng Li , linux-kernel , Benson Leung Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 26, 2019 at 1:56 AM Enric Balletbo i Serra wrote: > > Hi Yicheng, > > I looked at this patch deeply and I have a question. > > On 25/11/19 23:15, Yicheng Li wrote: > > RO and RW of EC may have different EC protocol version. If EC transitions > > between RO and RW, but AP does not reboot (this is true for fingerprint > > microcontroller / cros_fp, but not true for main ec / cros_ec), the AP > > still uses the protocol version queried before transition, which can > > cause problems. In the case of fingerprint microcontroller, this causes > > AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the > > interrupt handler, which in turn prevents RO to clear the interrupt > > line to AP, in an infinite loop. > > > > Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there > > might have been a transition between RO and RW, so re-query the protocol. > > > > Signed-off-by: Yicheng Li > > --- > > drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ > > include/linux/platform_data/cros_ec_proto.h | 3 +++ > > 2 files changed, 27 insertions(+) > > > > diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c > > index 9b2d07422e17..38ec1fb409a5 100644 > > --- a/drivers/platform/chrome/cros_ec.c > > +++ b/drivers/platform/chrome/cros_ec.c > > @@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) > > return ret; > > } > > > > +static int cros_ec_ready_event(struct notifier_block *nb, > > + unsigned long queued_during_suspend, void *_notify) > > +{ > > + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, > > + notifier_ready); > > + u32 host_event = cros_ec_get_host_event(ec_dev); > > + > > + if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INTERFACE_READY)) { > > + mutex_lock(&ec_dev->lock); > > + cros_ec_query_all(ec_dev); > > I am wondering if instead of calling cros_ec_query_all we can just set the proto > version to unknown: > > ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN > > and let the cros_ec_cmd_xfer function do its magic. This has actually been used in cros_ec_query_all itself, when the EC is not responding: when cros_ec_cmd_xfer is called, cros_ec_query_all() is called again. This is used when cros_ec_query_all() is called cros_ec_register(), but this is not working properly anymore, because the irq and device driver will not be registered anymore. See in cros_ec_register when cros_ec_query_all is called and set _UNKNOWN, ret is not 0 and cros_ec_register() will bail. I will work on it later. (crbug.com/1030373 for reference). For our case at hand, we can not wait for a command coming from user space to unlock us. Internal commands could use send_command directly, if a new interrupt comes up for instance). Let's put all the check code from cros_ec_cmd_xfer() in send_command() and indeed reset the proto_version. Gwendal. > > Should that work? > > Thanks, > Enric > > > + mutex_unlock(&ec_dev->lock); > > + return NOTIFY_OK; > > + } > > + > > + return NOTIFY_DONE; > > +} > > + > > /** > > * cros_ec_register() - Register a new ChromeOS EC, using the provided info. > > * @ec_dev: Device to register. > > @@ -201,6 +218,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev) > > dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", > > err); > > > > + /* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ > > + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; > > + err = blocking_notifier_chain_register(&ec_dev->event_notifier, > > + &ec_dev->notifier_ready); > > + if (err) > > + return err; > > + > > dev_info(dev, "Chrome EC device registered\n"); > > > > return 0; > > diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h > > index 0d4e4aaed37a..a1c545c464e7 100644 > > --- a/include/linux/platform_data/cros_ec_proto.h > > +++ b/include/linux/platform_data/cros_ec_proto.h > > @@ -121,6 +121,8 @@ struct cros_ec_command { > > * @event_data: Raw payload transferred with the MKBP event. > > * @event_size: Size in bytes of the event data. > > * @host_event_wake_mask: Mask of host events that cause wake from suspend. > > + * @notifier_ready: The notifier_block to let the kernel re-query EC > > + * communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. > > * @ec: The platform_device used by the mfd driver to interface with the > > * main EC. > > * @pd: The platform_device used by the mfd driver to interface with the > > @@ -161,6 +163,7 @@ struct cros_ec_device { > > int event_size; > > u32 host_event_wake_mask; > > u32 last_resume_result; > > + struct notifier_block notifier_ready; > > > > /* The platform devices used by the mfd driver */ > > struct platform_device *ec; > >