From: Nick Crews <ncrews@google.com>
To: linux-kernel@vger.kernel.org
Cc: Nick Crews <ncrews@google.com>, Olof Johansson <olof@lixom.net>,
Benson Leung <bleung@chromium.org>
Subject: [RFC PATCH 10/10] CHROMIUM: wilco_ec: Add binary telemetry attributes
Date: Fri, 14 Dec 2018 17:18:43 -0700 [thread overview]
Message-ID: <20181215001843.62404-11-ncrews@google.com> (raw)
In-Reply-To: <20181215001843.62404-1-ncrews@google.com>
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 <ncrews@google.com>
---
drivers/platform/chrome/Makefile | 3 +-
drivers/platform/chrome/wilco_ec_sysfs.c | 17 ++++-
drivers/platform/chrome/wilco_ec_telemetry.c | 66 ++++++++++++++++++++
drivers/platform/chrome/wilco_ec_telemetry.h | 42 +++++++++++++
4 files changed, 126 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/Makefile b/drivers/platform/chrome/Makefile
index c9d3d44098f9..62444887ce18 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -17,5 +17,6 @@ wilco_ec-objs := wilco_ec_mailbox.o wilco_ec_event.o \
wilco_ec_rtc.o wilco_ec_legacy.o \
wilco_ec_sysfs.o \
wilco_ec_properties.o \
- wilco_ec_adv_power.o
+ wilco_ec_adv_power.o \
+ wilco_ec_telemetry.o
obj-$(CONFIG_WILCO_EC) += wilco_ec.o
diff --git a/drivers/platform/chrome/wilco_ec_sysfs.c b/drivers/platform/chrome/wilco_ec_sysfs.c
index 81dded951058..0019d17c0cf9 100644
--- a/drivers/platform/chrome/wilco_ec_sysfs.c
+++ b/drivers/platform/chrome/wilco_ec_sysfs.c
@@ -19,6 +19,7 @@
#include "wilco_ec_legacy.h"
#include "wilco_ec_properties.h"
#include "wilco_ec_adv_power.h"
+#include "wilco_ec_telemetry.h"
#define WILCO_EC_ATTR_RO(_name) \
__ATTR(_name, 0444, wilco_ec_##_name##_show, NULL)
@@ -46,7 +47,21 @@ static struct attribute *wilco_ec_toplevel_attrs[] = {
NULL
};
-ATTRIBUTE_GROUPS(wilco_ec_toplevel);
+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,
+ NULL,
+};
/* Make property attributes, which will live inside GOOG000C:00/properties/ */
diff --git a/drivers/platform/chrome/wilco_ec_telemetry.c b/drivers/platform/chrome/wilco_ec_telemetry.c
new file mode 100644
index 000000000000..5b8168754b43
--- /dev/null
+++ b/drivers/platform/chrome/wilco_ec_telemetry.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * wilco_ec_legacy - Telemetry sysfs attributes for Wilco EC
+ *
+ * Copyright 2018 Google LLC
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/fs.h>
+#include <linux/kobject.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include "wilco_ec.h"
+#include "wilco_ec_sysfs_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;
+
+ 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)
+{
+ memcpy(buf, telemetry_data, min_t(unsigned long, count,
+ EC_MAILBOX_DATA_SIZE_EXTENDED));
+ 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..874873284080
--- /dev/null
+++ b/drivers/platform/chrome/wilco_ec_telemetry.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * wilco_ec_telemetry - Telemetry sysfs attributes for Wilco EC
+ *
+ * Copyright 2018 Google LLC
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef WILCO_EC_TELEMETRY_H
+#define WILCO_EC_TELEMETRY_H
+
+#include <linux/fs.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include "wilco_ec.h"
+
+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.0.405.gbc1bbc6f85-goog
next prev parent reply other threads:[~2018-12-15 0:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-15 0:18 [RFC PATCH 00/10] cros_ec: Add support for Wilco EC Nick Crews
2018-12-15 0:18 ` [RFC PATCH 01/10] CHROMIUM: cros_ec: Remove cros_ec dependency in lpc_mec Nick Crews
2018-12-17 15:50 ` Enric Balletbo Serra
2018-12-15 0:18 ` [RFC PATCH 02/10] CHROMIUM: wilco_ec: Add new driver for Wilco EC Nick Crews
2018-12-17 15:50 ` Enric Balletbo Serra
2018-12-15 0:18 ` [RFC PATCH 03/10] CHROMIUM: wilco_ec: Add sysfs attributes Nick Crews
2018-12-17 16:45 ` Enric Balletbo Serra
2018-12-17 18:12 ` Guenter Roeck
2018-12-15 0:18 ` [RFC PATCH 04/10] CHROMIUM: wilco_ec: Add support for raw commands in sysfs Nick Crews
2018-12-15 0:18 ` [RFC PATCH 05/10] CHROMIUM: wilco_ec: Add RTC class driver Nick Crews
2018-12-15 0:18 ` [RFC PATCH 06/10] CHROMIUM: wilco_ec: Add event handling Nick Crews
2018-12-15 0:18 ` [RFC PATCH 07/10] CHROMIUM: wilco_ec: Move legacy attributes to separate file Nick Crews
2018-12-15 0:18 ` [RFC PATCH 08/10] CHROMIUM: wilco_ec: Add EC properties Nick Crews
2018-12-15 0:18 ` [RFC PATCH 09/10] CHROMIUM: wilco_ec: Add peakshift and adv_batt_charging Nick Crews
2018-12-15 0:18 ` Nick Crews [this message]
2018-12-17 16:15 ` [RFC PATCH 00/10] cros_ec: Add support for Wilco EC Enric Balletbo Serra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181215001843.62404-11-ncrews@google.com \
--to=ncrews@google.com \
--cc=bleung@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olof@lixom.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®