Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp797868img; Thu, 21 Mar 2019 09:08:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVBmp4PiPAhUHQ9J4WytFqHAh2v/uLRCnIrVp3wfTXmIz1tFGA0DyPS8bayRzyJg0ZOnGj X-Received: by 2002:a62:69c3:: with SMTP id e186mr3943514pfc.169.1553184497845; Thu, 21 Mar 2019 09:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553184497; cv=none; d=google.com; s=arc-20160816; b=msmAs/nzFoHg6NwwYbk6R0bM18eqSM55dWctGkvUztEkVNgV3wQvEUUxqEndGjiQuY Q7+/7h+2ARBvl7VV0v6o/Hnc5bUzC6BOR+t3YnAYArmbnlesrlXyhNJ+wvOHHvyCJ5q8 1ShRv/sBd4oPhxwLPLDAiK7bS4G47vvMa/cCFXEJjT3zm7Da5WF+FQ2BGUtSy/CaJcEP UoQxqFKIF7FcYCaHWkV4+wFy6yVLCMs34aoeBl0Fa5ThHOC4vOB+/ymlV98W2B19K6IK Rymh2tOofiaPQpL35WnX94hEQfTJiGChldRb0XO1j1PwOrpe3HNEbIJlLbxrMxTXZ0Og Sbqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bKA785beao5hOykthPgzrgxeN4zmg34B2DzLO4cEfgw=; b=dc/Tf0Vy4R4prE8gPUHBaWBk/bPb/agndsc91OHgK9kw1V4OC56fnjPUeO7Fm96wYq P3l0KyyaRLnlpnw8LnDS70IIL4xi2ILQMWklWb4p1ofLQt0lhHgylHUUDk/mOTum3RxG WOAQ2L44KOODen6LnpREXUa1EI3o93A0gXQlLmRfibCiOQdLBtSe8joPe14t8ZzBGC0B Pt7gnt2BDEc1ldpD+X57lrfd25xPxZuRz5HTQsRuxA1/dX+CcALOiyA3LhH2ZRtFy8hU wL5Darai6Kaq/rP0FumS/H1tPsRmD+U8seSKBXfV7UywnwW7QDzEWWedwG4Zf/3YYZ2X kDFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="mI/8LhGS"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16si4468798pfe.152.2019.03.21.09.08.00; Thu, 21 Mar 2019 09:08:17 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b="mI/8LhGS"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728231AbfCUQF0 (ORCPT + 99 others); Thu, 21 Mar 2019 12:05:26 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:35441 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbfCUQF0 (ORCPT ); Thu, 21 Mar 2019 12:05:26 -0400 Received: by mail-qk1-f195.google.com with SMTP id z13so16611964qki.2 for ; Thu, 21 Mar 2019 09:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bKA785beao5hOykthPgzrgxeN4zmg34B2DzLO4cEfgw=; b=mI/8LhGSl7puk3MVLQ+0EqzC/RJqwt4n7cqIK8qMOKmzPOHgpKErJRGqb6V9iIKY/9 7sxzebsghyJyHU6bIfMpI654Sh/P8jxDLF5ifamEoikfU1mYf6PZUyTm9kPqohBU1fqv edkTmmlhHA8nCOeAiEabdyPz5Gs/hgPPPDKxns4qD0iVvm9zH31lFLQixnMmol5qM4df KJtzF5IAYVu8UCOFo8MA8JhVNPQRe10DWuioE5db/xL+tMqXBfnu4HEXhmwnRqxR43Gr sw0xCx/qaZmIah1gylsyAwUrdkskqtXGVCnCpet5FUSaBO/yBgb3ZPi4qL/VAmLlgz7A xFVQ== 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:content-transfer-encoding; bh=bKA785beao5hOykthPgzrgxeN4zmg34B2DzLO4cEfgw=; b=F4QO0XhnwizP5YKcjeAnnh6/RsFrt0q0DLmC5jJ/xxb1S9BeZcfAm7bjp+ugSqMC7c InhI4NmBGthGbK0NuKxVYN99JU+l8+Y2tWxpdwCmdkqLwjmK91kTNm5e0IXcF4oU2wk+ apg34JyHXHOvhDBAh33Y6IunrO3eyv4Uu8Rvqm3snU81aARZO9+nSj6Q6ExWPwBXqNtB sQBnQhgxm6qm+Jtu5cdm9at54Ihuni2xfKNYHZ/RQfQ1NvFT8Fykwphwk4aj58xPFqjq zruWGDSxz5xpcQvk4YJM4hUm7swvisM3YBHv9xCxaXSUhpNj01rkKDMwhkvCzwyQYCml 9yhQ== X-Gm-Message-State: APjAAAX+UjQxz+zGCOCXtHonasSn8+HhcFcsyGcchVbv7T1ELlSAEkmM bdrmVM9IKM14V1bakxZP4VS0qmd71vhh3lz14G4= X-Received: by 2002:a05:620a:1597:: with SMTP id d23mr3483942qkk.226.1553184324592; Thu, 21 Mar 2019 09:05:24 -0700 (PDT) MIME-Version: 1.0 References: <20190315170413.108114-1-twawrzynczak@chromium.org> <20190315170413.108114-2-twawrzynczak@chromium.org> In-Reply-To: <20190315170413.108114-2-twawrzynczak@chromium.org> From: Enric Balletbo Serra Date: Thu, 21 Mar 2019 17:05:13 +0100 Message-ID: Subject: Re: [PATCH] platform/chrome: mfd/cros_ec_sysfs: Add sysfs entry to retrieve EC uptime. To: Tim Wawrzynczak Cc: Benson Leung , Olof Johansson , Lee Jones , linux-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tim, Thanks for sending this upstream, some comments below Missatge de Tim Wawrzynczak del dia dv., 15 de mar=C3=A7 2019 a les 18:07: > > Adds a new sysfs node under the cros_ec device which contains the uptime > of the EC in milliseconds since boot. > > Signed-off-by: Tim Wawrzynczak > --- > drivers/platform/chrome/cros_ec_sysfs.c | 34 +++++++++++++++++++++++++ > include/linux/mfd/cros_ec_commands.h | 15 +++++++++++ All this is already included in the following patch so it's not really needed, rebase your patch on top of this and just resend the patch without these modifications and tell that depends on that patch. https://lore.kernel.org/patchwork/patch/1046363/ > 2 files changed, 49 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/c= hrome/cros_ec_sysfs.c > index 5a6db3fe213a..7e5ca1e2900b 100644 > --- a/drivers/platform/chrome/cros_ec_sysfs.c > +++ b/drivers/platform/chrome/cros_ec_sysfs.c > @@ -123,6 +123,38 @@ static ssize_t reboot_store(struct device *dev, > return count; > } > > +static ssize_t uptime_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct ec_response_uptime_info *resp; > + struct cros_ec_command *msg; > + int ret; > + struct cros_ec_dev *ec =3D to_cros_ec_dev(dev); > + u32 time_since_ec_boot_ms; > + nit: Reversed X-mas tree order if you don't mind. > + msg =3D kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL); > + if (!msg) > + return -ENOMEM; > + > + /* Get EC uptime information */ > + msg->version =3D 0; > + msg->command =3D EC_CMD_GET_UPTIME_INFO + ec->cmd_offset; > + msg->insize =3D sizeof(*resp); > + msg->outsize =3D 0; > + ret =3D cros_ec_cmd_xfer_status(ec->ec_dev, msg); > + if (ret < 0) { > + time_since_ec_boot_ms =3D 0; That's an error (because the command is not supported or other reason). Just goto the and exit label, free the memory and return the error. > + } else { else not needed > + resp =3D (struct ec_response_uptime_info *)msg->data; > + time_since_ec_boot_ms =3D resp->time_since_ec_boot_ms; > + } > + > + ret =3D scnprintf(buf, PAGE_SIZE, "%u\n", time_since_ec_boot_ms); > + > + kfree(msg); > + return ret; > +} > + > static ssize_t version_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > @@ -330,12 +362,14 @@ static DEVICE_ATTR_RW(reboot); > static DEVICE_ATTR_RO(version); > static DEVICE_ATTR_RO(flashinfo); > static DEVICE_ATTR_RW(kb_wake_angle); > +static DEVICE_ATTR_RO(uptime); > The time is stored in u32 which means that 2^32 in ms is less than 50 days. Overflow this counter doesn't seem too complicated. What happens when overflows just starts from 0 again? I'm curious why is this really useful show this in sysfs? There is a use case for that or is just information. > static struct attribute *__ec_attrs[] =3D { > &dev_attr_kb_wake_angle.attr, > &dev_attr_reboot.attr, > &dev_attr_version.attr, > &dev_attr_flashinfo.attr, > + &dev_attr_uptime.attr, Is the EC_CMD_GET_UPTIME_INFO supported by all the Cros EC|PD|FP|TP etc.? I tested on my Samsung Chromebook Plus and seems to be not supported (ectool fails) If there is a way to filter if the command is supported or not will be good only show the attribute when it is supposed to work. > NULL, > }; > > diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cro= s_ec_commands.h > index a8c882b5c222..38e7e6dcca97 100644 > --- a/include/linux/mfd/cros_ec_commands.h > +++ b/include/linux/mfd/cros_ec_commands.h > @@ -4697,6 +4697,21 @@ struct __ec_align4 ec_params_rwsig_action { > uint32_t action; > }; > > +/* For getting EC uptime & AP reset information */ > +#define EC_CMD_GET_UPTIME_INFO 0x0121 > + > +struct __ec_align4 ec_response_uptime_info { > + uint32_t time_since_ec_boot_ms; /* uptime in ms */ > + uint32_t ap_resets_since_ec_boot; /* AP resets recorded by EC */ > + uint32_t ec_reset_flags; /* RESET_* flags */ > + /* Empty log entries have cause and timestamp set to zero */ > + struct ap_reset_log_entry { > + uint16_t reset_cause; /* enum chipset_*_reason */ > + uint16_t reserved; /* reserved for protocol growth= */ > + uint32_t reset_time_ms; /* time of reset assertion */ > + } recent_ap_reset[4]; > +}; > + > /***********************************************************************= ******/ > /* The command range 0x200-0x2FF is reserved for Rotor. */ > > -- > 2.20.1 > Thanks, Enric