Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3727493imu; Fri, 18 Jan 2019 16:16:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN5e2eq6iMSDU2xXk02KD7ey/Sab9u6Xnfzujpt5uKUxapG1kka8pFTQNZ6y8f8lQ5SAHcYy X-Received: by 2002:a17:902:7481:: with SMTP id h1mr21313195pll.341.1547856979807; Fri, 18 Jan 2019 16:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547856979; cv=none; d=google.com; s=arc-20160816; b=LwvvIfTo1DZaY3EYeBGB073MHHAmZWMKGZNNUqE0TgeNYr42wJuse7r9jTgvPv1x13 xOHj+OTd6eUBkcuu/+icSto36sPkzHDRVf1GB/T0x52ovC29XE9tFHKe0TqiflGZKfzO wyZ1PXgDiiPGPFmLeq7o3zRLcEpLjuOqWrnbpPNE1djevDYxIiSyQMw7E4RjGWNxPcad xoXolX4FotOYRqYN05xGsoBdY18Nm4X+HEM5mYr6anMmYX55vDz0hFGDWwXUkVaUMQek jfJUd+sxFy9PlPABFL4o3UuLvxOey0n6g2GQg/+sQ+qVW2eSnU94X8Ps+CegnCxgeG99 CmOw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t/c4/Iv0gdmINcdL9FFr/Gx7jYVIbDl5QbzWWve07+k=; b=NXO46dB3kgbbMnOFKwOEPsfXGZlhV1XOkStij0Z7AtbNWzxu85WjGXOLg/xKGe4k/P yZBBQtlapDkiwMDoPCPy62ZxnQZH1fr3EqiWjGoZkEIhhR/az6eZVH6QHX3fXq4lFt06 JKt/b5xx+pnoR/zn0a4+DzxRGZf8Cf+l3/yDpBKUk+eobZlHKzRBBSD/UTGF58xrq9Mw t9pdo3x8jEQ/1nlIA8PDtj4Xj6SuwRit23T1Deq0Swuytm4bK5DYdGiSy4F1AM/daq58 tLxbQIXVe6zknaiCzJcyXyhjoELkbQbTF2quB0G6icaJiqXMZpXCL5wz3s8oytUSmjY2 GjEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="P01fC/zq"; 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 i16si5778602pgk.445.2019.01.18.16.16.04; Fri, 18 Jan 2019 16:16:19 -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="P01fC/zq"; 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 S1730401AbfASAOr (ORCPT + 99 others); Fri, 18 Jan 2019 19:14:47 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:35554 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730334AbfASAOn (ORCPT ); Fri, 18 Jan 2019 19:14:43 -0500 Received: by mail-it1-f196.google.com with SMTP id p197so8157322itp.0 for ; Fri, 18 Jan 2019 16:14:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t/c4/Iv0gdmINcdL9FFr/Gx7jYVIbDl5QbzWWve07+k=; b=P01fC/zqqAj6WdVrpaKRD9Fp903LapjK1xRrpOhThjQAE9vjEsTKyfHXoh7gqHYgj1 yiaIDS4BafDmp6sHDkSi1m3c2t4NuYmlVDc/OxTGPkMOQ6gmnHm/BsA+eQ/grH/TW440 5CIwpSIWyHTNl3vkW+TSrEbJD6zdElw6PNKRI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t/c4/Iv0gdmINcdL9FFr/Gx7jYVIbDl5QbzWWve07+k=; b=L/3u8gcl6kF3zjt8YudmSLYXPrXRNBZjpMswceUrZH9hKeLDddsKOuxKRppfp/cs6V juv+HNem6r2mxD3dGBZJlnVA52KzAGGGgEHRKWumOnyYVxzWHeA4D3zN7Hnog5EOe/5M O06LUwU/vjnEFWI8GN6KcEUWs3H34X/dnq9EVe2TQ72tDd9EkgnGdjBffWRqftHlMbVb cREWmBAGxM9Xv6V5q/rDwXORzsoYS0oE0VYDRZQ7o/iC6p2FIPum2l1M8h9vuPVaT423 J2H3rVb2tcNMxbCXQLTlqfN1vaSDr5yITbCehnZLZgz7cziYa5A0cvfgV4Kc9XNu82qI Fd6g== X-Gm-Message-State: AJcUukfXipkS2VxwvhB4odUXQGI3vdaiNhGuy3FywXC1UZLu6jd4+p3C 0S9RmGh2MybSJsb0hZ8Qb2kPzXfRuAc= X-Received: by 2002:a24:af0a:: with SMTP id t10mr13224270ite.159.1547856881941; Fri, 18 Jan 2019 16:14:41 -0800 (PST) Received: from ncrews2.bld.corp.google.com ([2620:15c:183:200:8140:8e3f:aea5:bcdf]) by smtp.gmail.com with ESMTPSA id e22sm2382062iod.47.2019.01.18.16.14.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 16:14:40 -0800 (PST) From: Nick Crews To: linux-kernel@vger.kernel.org Cc: groeck@chromium.org, sjg@chromium.org, djkurtz@google.com, dlaurie@chromium.org, Nick Crews , Nick Crews , Duncan Laurie , Enric Balletbo i Serra , Benson Leung Subject: [PATCH v3 9/9] platform/chrome: Add binary telemetry attributes Date: Fri, 18 Jan 2019 17:14:22 -0700 Message-Id: <20190119001422.48186-10-ncrews@chromium.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190119001422.48186-1-ncrews@chromium.org> References: <20190119001422.48186-1-ncrews@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Crews The Wilco Embedded Controller is able to send telemetry data which is useful for enterprise applications. A daemon running on the OS sends a command (possibly with args) to the EC via this sysfs interface, and the EC responds over the sysfs interface with the response. Both the request and the response are in an opaque binary format so that information which is proprietary to the enterprise service provider is secure. At this point, the Wilco EC does not implement this telemetry functionality, so any request using the WILCO_EC_MSG_TELEMETRY command returns an error. This is just an initial change for comments, until the EC code is implemented. Signed-off-by: Nick Crews Signed-off-by: Nick Crews --- Changes in v3: - add err check on returned data size - add check on read request offset and size Changes in v2: None drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 2 +- drivers/platform/chrome/wilco_ec/sysfs.c | 7 ++ drivers/platform/chrome/wilco_ec/telemetry.c | 73 ++++++++++++++++++++ drivers/platform/chrome/wilco_ec/telemetry.h | 41 +++++++++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.c create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.h diff --git a/drivers/platform/chrome/wilco_ec/Makefile b/drivers/platform/chrome/wilco_ec/Makefile index 23378d9469a8..00683c96bf78 100644 --- a/drivers/platform/chrome/wilco_ec/Makefile +++ b/drivers/platform/chrome/wilco_ec/Makefile @@ -2,5 +2,5 @@ wilco_ec-objs := core.o mailbox.o debugfs.o sysfs.o \ legacy.o event.o properties.o \ - adv_power.o + adv_power.o telemetry.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o diff --git a/drivers/platform/chrome/wilco_ec/core.c b/drivers/platform/chrome/wilco_ec/core.c index 65588cfcc7a2..a6bda44e30e4 100644 --- a/drivers/platform/chrome/wilco_ec/core.c +++ b/drivers/platform/chrome/wilco_ec/core.c @@ -90,7 +90,7 @@ static int wilco_ec_probe(struct platform_device *pdev) * dev is unregistered. */ child_pdev = platform_device_register_data(dev, "rtc-wilco-ec", - PLATFORM_DEVID_AUTO, + PLATFORM_DEVID_NONE, NULL, 0); if (IS_ERR(child_pdev)) { dev_err(dev, "Failed to create RTC platform device\n"); diff --git a/drivers/platform/chrome/wilco_ec/sysfs.c b/drivers/platform/chrome/wilco_ec/sysfs.c index 83de0daef265..f01d782b4c96 100644 --- a/drivers/platform/chrome/wilco_ec/sysfs.c +++ b/drivers/platform/chrome/wilco_ec/sysfs.c @@ -17,6 +17,7 @@ #include "legacy.h" #include "properties.h" #include "adv_power.h" +#include "telemetry.h" #define WILCO_EC_ATTR_RO(_name) \ __ATTR(_name, 0444, wilco_ec_##_name##_show, NULL) @@ -42,8 +43,14 @@ static struct attribute *wilco_ec_toplevel_attrs[] = { &stealth_attr.attr, NULL }; +static struct bin_attribute telem_attr = TELEMETRY_BIN_ATTR(telemetry); +static struct bin_attribute *telem_attrs[] = { + &telem_attr, + NULL +}; static const struct attribute_group wilco_ec_toplevel_group = { .attrs = wilco_ec_toplevel_attrs, + .bin_attrs = telem_attrs, }; static const struct attribute_group *wilco_ec_toplevel_groups[] = { &wilco_ec_toplevel_group, diff --git a/drivers/platform/chrome/wilco_ec/telemetry.c b/drivers/platform/chrome/wilco_ec/telemetry.c new file mode 100644 index 000000000000..b577a22654cf --- /dev/null +++ b/drivers/platform/chrome/wilco_ec/telemetry.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Telemetry sysfs attributes for Wilco EC + * + * Copyright 2018 Google LLC + * + * The Wilco Embedded Controller is able to send telemetry data + * which is useful for enterprise applications. A daemon running on + * the OS sends a command (possibly with args) to the EC via + * this sysfs interface, and the EC responds over the sysfs interface + * with the response. Both the request and the response are in an opaque + * binary format so that information which is proprietary to the + * enterprise service provider is secure. + */ + +#include +#include +#include +#include +#include +#include + +#include "util.h" + +/* Data buffer for holding EC's response for telemtry data */ +static u8 telemetry_data[EC_MAILBOX_DATA_SIZE_EXTENDED]; + +ssize_t wilco_ec_telem_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, loff_t loff, + size_t count) +{ + struct wilco_ec_message msg; + int ret; + struct device *dev = device_from_kobject(kobj); + struct wilco_ec_device *ec = dev_get_drvdata(dev); + + if (count < 1 || count > EC_MAILBOX_DATA_SIZE_EXTENDED) + return -EINVAL; + + /* Clear response data buffer */ + memset(telemetry_data, 0, EC_MAILBOX_DATA_SIZE_EXTENDED); + + msg.type = WILCO_EC_MSG_TELEMETRY; + msg.flags = WILCO_EC_FLAG_RAW | WILCO_EC_FLAG_EXTENDED_DATA; + msg.command = buf[0]; + msg.request_data = buf + 1; + msg.request_size = EC_MAILBOX_DATA_SIZE; + msg.response_data = &telemetry_data; + msg.response_size = EC_MAILBOX_DATA_SIZE_EXTENDED; + + /* Send the requested command + data as raw transaction */ + ret = wilco_ec_mailbox(ec, &msg); + if (ret < 0) + return ret; + if (ret != EC_MAILBOX_DATA_SIZE_EXTENDED) + return -EBADMSG; + + return count; +} + +ssize_t wilco_ec_telem_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, loff_t off, + size_t count) +{ + if (off) + return -EINVAL; + if (count != EC_MAILBOX_DATA_SIZE_EXTENDED) + return -EINVAL; + + memcpy(buf, telemetry_data, count); + + return count; +} diff --git a/drivers/platform/chrome/wilco_ec/telemetry.h b/drivers/platform/chrome/wilco_ec/telemetry.h new file mode 100644 index 000000000000..d68cc067b97a --- /dev/null +++ b/drivers/platform/chrome/wilco_ec/telemetry.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Telemetry sysfs attributes for Wilco EC + * + * Copyright 2018 Google LLC + * + * The Wilco Embedded Controller is able to send telemetry data + * which is useful for enterprise applications. A daemon running on + * the OS sends a command (possibly with args) to the EC via + * this sysfs interface, and the EC responds over the sysfs interface + * with the response. Both the request and the response are in an opaque + * binary format so that information which is proprietary to the + * enterprise service provider is secure. + */ + +#ifndef WILCO_EC_TELEMETRY_H +#define WILCO_EC_TELEMETRY_H + +#include +#include +#include +#include +#include + +ssize_t wilco_ec_telem_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, loff_t loff, + size_t count); + +ssize_t wilco_ec_telem_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, loff_t off, + size_t count); + +#define TELEMETRY_BIN_ATTR(_name) { \ + .attr = {.name = __stringify(_name), \ + .mode = VERIFY_OCTAL_PERMISSIONS(0644) }, \ + .size = EC_MAILBOX_DATA_SIZE_EXTENDED, \ + .read = wilco_ec_telem_read, \ + .write = wilco_ec_telem_write, \ +} + +#endif /* WILCO_EC_TELEMETRY_H */ -- 2.20.1.321.g9e740568ce-goog