lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 25 Mar 2015 10:51:52 +0100
From:	Holger Dengler <dengler@...utronix.de>
To:	linux-kernel@...r.kernel.org
Cc:	Peter Mahler <mahler@...ug.com>, Juergen Bubeck <bubeck@...ug.com>,
	Benedikt Spranger <b.spranger@...utronix.de>,
	Holger Dengler <dengler@...utronix.de>,
	Samuel Ortiz <sameo@...ux.intel.com>,
	Lee Jones <lee.jones@...aro.org>
Subject: [PATCH 03/11] mfd: flexcard: add device attributes

From: Benedikt Spranger <b.spranger@...utronix.de>

Add device attributes for common flexcard information access. The
attribiutes are read-only execpt "uid" (user ID register).
The "uid" attribute can also be used to change the user-defined ID of a
Flexcard.

Signed-off-by: Holger Dengler <dengler@...utronix.de>
Signed-off-by: Benedikt Spranger <b.spranger@...utronix.de>
cc: Samuel Ortiz <sameo@...ux.intel.com>
cc: Lee Jones <lee.jones@...aro.org>
---
 drivers/mfd/flexcard/Makefile   |   2 +-
 drivers/mfd/flexcard/attr.c     | 215 ++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/flexcard/core.c     |  11 ++
 drivers/mfd/flexcard/flexcard.h |   7 ++
 4 files changed, 234 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mfd/flexcard/attr.c
 create mode 100644 drivers/mfd/flexcard/flexcard.h

diff --git a/drivers/mfd/flexcard/Makefile b/drivers/mfd/flexcard/Makefile
index 6606ebb..101000f 100644
--- a/drivers/mfd/flexcard/Makefile
+++ b/drivers/mfd/flexcard/Makefile
@@ -1,2 +1,2 @@
 obj-$(CONFIG_MFD_FLEXCARD)	+= flexcard.o
-flexcard-objs			:= core.o
+flexcard-objs			:= core.o attr.o
diff --git a/drivers/mfd/flexcard/attr.c b/drivers/mfd/flexcard/attr.c
new file mode 100644
index 0000000..c91c884
--- /dev/null
+++ b/drivers/mfd/flexcard/attr.c
@@ -0,0 +1,215 @@
+/*
+ * Eberspaecher Flexcard PMC II Carrier Board PCI Driver - device attributes
+ *
+ * Copyright (c) 2014,2015 Linutronix GmbH
+ * Author: Holger Dengler
+ *         Benedikt Spranger
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+#include <linux/device.h>
+#include <linux/flexcard.h>
+#include <linux/kref.h>
+#include <linux/miscdevice.h>
+#include <linux/pci.h>
+#include <linux/mfd/flexcard.h>
+
+static ssize_t fw_version_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%02x.%02x.%02x\n", priv->conf->fc_fw_ver.maj,
+		       priv->conf->fc_fw_ver.min, priv->conf->fc_fw_ver.dev);
+}
+static DEVICE_ATTR_RO(fw_version);
+
+static ssize_t hw_version_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%02x.%02x.%02x\n", priv->conf->fc_hw_ver.maj,
+		       priv->conf->fc_hw_ver.min, priv->conf->fc_hw_ver.dev);
+}
+static DEVICE_ATTR_RO(hw_version);
+
+static ssize_t serialno_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%lld\n", priv->conf->fc_sn);
+}
+static DEVICE_ATTR_RO(serialno);
+
+static ssize_t tiny_stat_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "0x%x\n", priv->conf->tiny_stat);
+}
+static DEVICE_ATTR_RO(tiny_stat);
+
+static ssize_t can_dat_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->can_dat_cnt);
+}
+static DEVICE_ATTR_RO(can_dat);
+
+static ssize_t can_err_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->can_err_cnt);
+}
+static DEVICE_ATTR_RO(can_err);
+
+static ssize_t fc_data_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->fc_data_cnt);
+}
+static DEVICE_ATTR_RO(fc_data);
+
+static ssize_t fr_rx_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->fr_rx_cnt);
+}
+static DEVICE_ATTR_RO(fr_rx);
+
+static ssize_t fr_tx_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->fr_tx_cnt);
+}
+static DEVICE_ATTR_RO(fr_tx);
+
+static ssize_t nmv_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->nmv_cnt);
+}
+static DEVICE_ATTR_RO(nmv);
+
+static ssize_t info_show(struct device *dev,
+			 struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->info_cnt);
+}
+static DEVICE_ATTR_RO(info);
+
+static ssize_t stat_trg_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->stat_trg_cnt);
+}
+static DEVICE_ATTR_RO(stat_trg);
+
+static ssize_t nf_show(struct device *dev,
+		       struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", priv->conf->nf_cnt);
+}
+static DEVICE_ATTR_RO(nf);
+
+static ssize_t uid_store(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t count)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+	unsigned long uid;
+	int ret;
+
+	ret = kstrtou32(buf, 0, &uid);
+	if (ret)
+		return ret;
+
+	priv->conf->fc_uid = uid;
+	return count;
+}
+
+static ssize_t uid_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	struct flexcard_device *priv = pci_get_drvdata(pdev);
+
+	return sprintf(buf, "%u\n", priv->conf->fc_uid);
+}
+static DEVICE_ATTR(uid, S_IRUGO|S_IWUSR, uid_show, uid_store);
+
+static struct attribute *flexcard_misc_dev_attrs[] = {
+	&dev_attr_fw_version.attr,
+	&dev_attr_hw_version.attr,
+	&dev_attr_serialno.attr,
+	&dev_attr_tiny_stat.attr,
+	&dev_attr_can_dat.attr,
+	&dev_attr_can_err.attr,
+	&dev_attr_fc_data.attr,
+	&dev_attr_fr_rx.attr,
+	&dev_attr_fr_tx.attr,
+	&dev_attr_nmv.attr,
+	&dev_attr_info.attr,
+	&dev_attr_stat_trg.attr,
+	&dev_attr_nf.attr,
+	&dev_attr_uid.attr,
+	NULL,
+};
+
+static const struct attribute_group flexcard_misc_dev_group = {
+	.attrs = flexcard_misc_dev_attrs,
+};
+
+int flexcard_misc_add_attrs(struct device *dev)
+{
+	int ret;
+
+	ret = sysfs_create_group(&dev->kobj,
+				 &flexcard_misc_dev_group);
+
+	if (ret)
+		dev_err(dev, "failed to create sysfs attributes: %d\n", ret);
+
+	return ret;
+}
+
+void flexcard_misc_del_attrs(struct device *dev)
+{
+	sysfs_remove_group(&dev->kobj, &flexcard_misc_dev_group);
+}
diff --git a/drivers/mfd/flexcard/core.c b/drivers/mfd/flexcard/core.c
index 1e7fb0f..6477019 100644
--- a/drivers/mfd/flexcard/core.c
+++ b/drivers/mfd/flexcard/core.c
@@ -22,6 +22,8 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/flexcard.h>
 
+#include "flexcard.h"
+
 static DEFINE_IDA(flexcard_ida);
 
 static const char drv_name[] = "flexcard";
@@ -237,6 +239,12 @@ static int flexcard_probe(struct pci_dev *pdev,
 		goto out_remove;
 	}
 
+	ret = flexcard_misc_add_attrs(priv->dev.this_device);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to register miscdevice: %d\n", ret);
+		goto out_deregister;
+	}
+
 	dev_info(&pdev->dev, "HW %02x.%02x.%02x FW %02x.%02x.%02x\n",
 		 priv->conf->fc_hw_ver.maj, priv->conf->fc_hw_ver.min,
 		 priv->conf->fc_hw_ver.dev, priv->conf->fc_fw_ver.maj,
@@ -244,6 +252,8 @@ static int flexcard_probe(struct pci_dev *pdev,
 
 	return 0;
 
+out_deregister:
+	misc_deregister(&priv->dev);
 out_remove:
 	mfd_remove_devices(&pdev->dev);
 out_unmap:
@@ -264,6 +274,7 @@ static void flexcard_remove(struct pci_dev *pdev)
 {
 	struct flexcard_device *priv = pci_get_drvdata(pdev);
 
+	flexcard_misc_del_attrs(priv->dev.this_device);
 	misc_deregister(&priv->dev);
 	mfd_remove_devices(&pdev->dev);
 	iounmap(priv->conf);
diff --git a/drivers/mfd/flexcard/flexcard.h b/drivers/mfd/flexcard/flexcard.h
new file mode 100644
index 0000000..1fe451e
--- /dev/null
+++ b/drivers/mfd/flexcard/flexcard.h
@@ -0,0 +1,7 @@
+#ifndef __FLEXCARD_H
+#define  __FLEXCARD_H
+
+int flexcard_misc_add_attrs(struct device *dev);
+void flexcard_misc_del_attrs(struct device *dev);
+
+#endif /* __FLEXCARD_H */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ