diff mbox

[-mm,4/4] RapidIO: Add new sysfs attributes

Message ID 1292013498-31406-5-git-send-email-alexandre.bounine@idt.com (mailing list archive)
State Superseded
Delegated to: Alexandre Bounine
Headers show

Commit Message

Bounine, Alexandre Dec. 10, 2010, 8:38 p.m. UTC
Add new sysfs attributes.

1. Routing information required to to reach the RIO device:
destid - device destination ID (real for for endpoint, route for switch)
hopcount - hopcount for maintenance requests (switches only)

2. device linking information:
lprev - name of device that precedes the given device in the enumeration
        or discovery order (displayed along with of the port to which it
        is attached).
lnext - names of devices (with corresponding port numbers) that are
        attached to the given device as next in the enumeration or
        discovery order (switches only)

Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com>
Cc: Kumar Gala <galak@kernel.crashing.org>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Li Yang <leoli@freescale.com>
Cc: Thomas Moll <thomas.moll@sysgo.com>
Cc: Micha Nelissen <micha@neli.hopto.org>
---
 drivers/rapidio/rio-sysfs.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)

Comments

Andrew Morton Dec. 10, 2010, 11:22 p.m. UTC | #1
On Fri, 10 Dec 2010 15:38:18 -0500
Alexandre Bounine <alexandre.bounine@idt.com> wrote:

> Add new sysfs attributes.

One would like to see documentation updates along with sysfs API
updates.  But one fears that this entire interface wasn't documented
anyway :(

Please at least fully describe the proposed interface in the changelog
so others can review the proposal.

The proposed new sysfs files appear to break the
one-value-per-sysfs-file rule.
Bounine, Alexandre Dec. 11, 2010, 6:49 p.m. UTC | #2
Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> One would like to see documentation updates along with sysfs API
> updates.  But one fears that this entire interface wasn't documented
> anyway :(

I think I have to find a time for that. I am adding it into my TODO
list.
 
> Please at least fully describe the proposed interface in the changelog
> so others can review the proposal.

Will do.
 
> The proposed new sysfs files appear to break the
> one-value-per-sysfs-file rule.

This is true for two of them. I was trying to find a better format for
them and at the end decided to break a rule and use port-device format
for this first version.
I may use just device name but "lnext" has to show multiple devices
anyway.
I decided the one-value-per-sysfs-file rule because it was broken once
already by the "routes" attribute (lprev and lnext have a similar
format).
Greg KH Dec. 12, 2010, 6:48 p.m. UTC | #3
On Fri, Dec 10, 2010 at 03:38:18PM -0500, Alexandre Bounine wrote:
> Add new sysfs attributes.

Like Andrew pointed out, all sysfs files are required to have entries in
Documentation/ABI.  If the existing rapidio sysfs files are not
documented, please document them in there _before_ adding new ones.

thanks,

greg k-h
Bounine, Alexandre Dec. 13, 2010, 1:55 p.m. UTC | #4
Greg KH wrote:
> 
> Like Andrew pointed out, all sysfs files are required to have entries
in
> Documentation/ABI.  If the existing rapidio sysfs files are not
> documented, please document them in there _before_ adding new ones.
> 
I included RapidIO documentation update into my plan for next set of
RapidIO patches. Until than this patch may be safely dropped without
affecting other patches in this set.

Alex.
diff mbox

Patch

diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 76b4185..b8d9eaf 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -33,6 +33,8 @@  rio_config_attr(device_rev, "0x%08x\n");
 rio_config_attr(asm_did, "0x%04x\n");
 rio_config_attr(asm_vid, "0x%04x\n");
 rio_config_attr(asm_rev, "0x%04x\n");
+rio_config_attr(destid, "0x%04x\n");
+rio_config_attr(hopcount, "0x%02x\n");
 
 static ssize_t routes_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -52,6 +54,33 @@  static ssize_t routes_show(struct device *dev, struct device_attribute *attr, ch
 	return (str - buf);
 }
 
+static ssize_t lprev_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct rio_dev *rdev = to_rio_dev(dev);
+
+	return sprintf(buf, "%02d %s\n", RIO_GET_PORT_NUM(rdev->swpinfo),
+		       (rdev->prev) ? rio_name(rdev->prev) : "host");
+}
+
+static ssize_t lnext_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct rio_dev *rdev = to_rio_dev(dev);
+	char *str = buf;
+	int i;
+
+	if (rdev->pef & RIO_PEF_SWITCH) {
+		for (i = 0; i < RIO_GET_TOTAL_PORTS(rdev->swpinfo); i++) {
+			if (rdev->rswitch->nextdev[i])
+				str += sprintf(str, "%02d %s\n", i,
+					rio_name(rdev->rswitch->nextdev[i]));
+		}
+	}
+
+	return str - buf;
+}
+
 struct device_attribute rio_dev_attrs[] = {
 	__ATTR_RO(did),
 	__ATTR_RO(vid),
@@ -59,10 +88,14 @@  struct device_attribute rio_dev_attrs[] = {
 	__ATTR_RO(asm_did),
 	__ATTR_RO(asm_vid),
 	__ATTR_RO(asm_rev),
+	__ATTR_RO(lprev),
+	__ATTR_RO(destid),
 	__ATTR_NULL,
 };
 
 static DEVICE_ATTR(routes, S_IRUGO, routes_show, NULL);
+static DEVICE_ATTR(lnext, S_IRUGO, lnext_show, NULL);
+static DEVICE_ATTR(hopcount, S_IRUGO, hopcount_show, NULL);
 
 static ssize_t
 rio_read_config(struct file *filp, struct kobject *kobj,
@@ -218,7 +251,9 @@  int rio_create_sysfs_dev_files(struct rio_dev *rdev)
 	err = device_create_bin_file(&rdev->dev, &rio_config_attr);
 
 	if (!err && (rdev->pef & RIO_PEF_SWITCH)) {
-		err = device_create_file(&rdev->dev, &dev_attr_routes);
+		err |= device_create_file(&rdev->dev, &dev_attr_routes);
+		err |= device_create_file(&rdev->dev, &dev_attr_lnext);
+		err |= device_create_file(&rdev->dev, &dev_attr_hopcount);
 		if (!err && rdev->rswitch->sw_sysfs)
 			err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
 	}
@@ -241,6 +276,8 @@  void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
 	device_remove_bin_file(&rdev->dev, &rio_config_attr);
 	if (rdev->pef & RIO_PEF_SWITCH) {
 		device_remove_file(&rdev->dev, &dev_attr_routes);
+		device_remove_file(&rdev->dev, &dev_attr_lnext);
+		device_remove_file(&rdev->dev, &dev_attr_hopcount);
 		if (rdev->rswitch->sw_sysfs)
 			rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
 	}