@@ -1,7 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o \
- event.o properties.o adv_power.o
+ event.o properties.o adv_power.o \
+ telemetry.o
obj-$(CONFIG_WILCO_EC) += wilco_ec.o
wilco_ec_debugfs-objs := debugfs.o
obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
@@ -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,
new file mode 100644
@@ -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 <linux/fs.h>
+#include <linux/kobject.h>
+#include <linux/device.h>
+#include <linux/platform_data/wilco-ec.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+
+#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;
+}
new file mode 100644
@@ -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 <linux/fs.h>
+#include <linux/kobject.h>
+#include <linux/platform_data/wilco-ec.h>
+#include <linux/sysfs.h>
+#include <linux/types.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 */