[ewg] [PATCH 6/9] [RFC] Add sysfs support for XCPM

Hal Rosenstock hrosenstock at xsigo.com
Fri Apr 4 06:19:02 PDT 2008


Add sysfs support for Xsigo configuration protocol (XCPM).

Signed-off-by: Hal Rosenstock <hal at xsigo.com>
---
 drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.c |  338 ++++++++++++++++++++++
 drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.h |   43 +++
 2 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.c
 create mode 100644 drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.h

diff --git a/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.c b/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.c
new file mode 100644
index 0000000..e726adc
--- /dev/null
+++ b/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright (c) 2006-2008 Xsigo Systems Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/version.h>
+
+#include "xsmp.h"
+#include "xcpm_priv.h"
+#include "xcpm_export.h"
+#include "xcpm_stats.h"
+#include "xs_core.h"
+
+extern struct xcpm_info *xcpm;
+
+static ssize_t show_link_state(struct class_device *class_dev, char *buf)
+{
+	int link_index, link_state;
+	struct link_info *plink;
+	char *state_str = NULL;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	link_state = plink->link_state;
+	if (link_state == LINK_INIT)
+		state_str = "Init";
+	else if (link_state == LINK_UP)
+		state_str = "Up";
+	else if (link_state == LINK_DISABLED)
+		state_str = "Disabled";
+	else if (link_state == LINK_DOWN)
+		state_str = "Down";
+	else
+		state_str = "Not valid";
+
+        return sprintf(buf, "%s", state_str);
+}
+
+static CLASS_DEVICE_ATTR(state, S_IRUGO, show_link_state, NULL);
+
+static ssize_t show_hello_interval(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d (secs)", plink->linkstate_timeout / 3);
+}
+
+static CLASS_DEVICE_ATTR(hello_interval, S_IRUGO, show_hello_interval, NULL);
+
+static ssize_t show_session_timeout(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d (secs)", plink->linkstate_timeout);
+}
+
+static CLASS_DEVICE_ATTR(session_timeout, S_IRUGO, show_session_timeout, NULL);
+
+static ssize_t show_num_session_timeouts(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->session_timeouts);
+}
+
+static CLASS_DEVICE_ATTR(num_session_timeouts, S_IRUGO,
+			 show_num_session_timeouts, NULL);
+
+static ssize_t show_hello_recv_count(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->hellos_received);
+}
+
+static CLASS_DEVICE_ATTR(hello_recv_count, S_IRUGO, show_hello_recv_count, NULL);
+
+static ssize_t show_hello_send_count(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->hellos_sent);
+}
+
+static CLASS_DEVICE_ATTR(hello_send_count, S_IRUGO, show_hello_send_count, NULL);
+
+static ssize_t show_datapath_timeout(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d (secs)", plink->datapath_timeout);
+}
+
+static CLASS_DEVICE_ATTR(datapath_timeout, S_IRUGO, show_datapath_timeout, NULL);
+
+static ssize_t show_handle(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->ib_link.handle);
+}
+
+static CLASS_DEVICE_ATTR(handle, S_IRUGO, show_handle, NULL);
+
+static ssize_t show_local_port(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->ib_link.port->port_num);
+}
+
+static CLASS_DEVICE_ATTR(local_port, S_IRUGO, show_local_port, NULL);
+
+static ssize_t show_local_lid(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->ib_link.port->lid);
+}
+
+static CLASS_DEVICE_ATTR(local_lid, S_IRUGO, show_local_lid, NULL);
+
+static ssize_t show_local_guid(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "0x%Lx", plink->ib_link.port->guid);
+}
+
+static CLASS_DEVICE_ATTR(local_guid, S_IRUGO, show_local_guid, NULL);
+
+static ssize_t show_remote_lid(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "%d", plink->ib_link.link_xcm.xcm_lid);
+}
+
+static CLASS_DEVICE_ATTR(remote_lid, S_IRUGO, show_remote_lid, NULL);
+
+static ssize_t show_remote_guid(struct class_device *class_dev, char *buf)
+{
+	int link_index;
+	struct link_info *plink;
+
+	if (!sscanf(class_dev->class_id, "link%d", &link_index))
+		return 0;
+	plink = &xcpm->links[link_index];
+	return sprintf(buf, "0x%Lx", cpu_to_be64(plink->ib_link.link_xcm.port_id));
+}
+
+static CLASS_DEVICE_ATTR(remote_guid, S_IRUGO, show_remote_guid, NULL);
+
+static struct attribute *xcpm_link_dev_attrs[] = {
+	&class_device_attr_state.attr,
+	&class_device_attr_hello_interval.attr,
+	&class_device_attr_session_timeout.attr,
+	&class_device_attr_num_session_timeouts.attr,
+	&class_device_attr_hello_recv_count.attr,
+	&class_device_attr_hello_send_count.attr,
+	&class_device_attr_datapath_timeout.attr,
+	&class_device_attr_handle.attr,
+	&class_device_attr_local_port.attr,
+	&class_device_attr_local_lid.attr,
+	&class_device_attr_local_guid.attr,
+	&class_device_attr_remote_lid.attr,
+	&class_device_attr_remote_guid.attr,
+	NULL
+};
+
+static struct attribute_group xcpm_link_dev_attr_group = {
+	.attrs = xcpm_link_dev_attrs,
+};
+
+extern struct class xscore_class;
+
+static struct class_device xcpm_class_dev;
+
+int xcpm_link_add_sysfs(int link_index)
+{
+	int ret;
+	struct link_info *plink = &xcpm->links[link_index];
+
+	plink->link_class_dev.class = &xscore_class;
+	plink->link_class_dev.parent = &xcpm_class_dev;
+	snprintf(plink->link_class_dev.class_id, BUS_ID_SIZE,
+		 "link%d", link_index);
+
+	ret = class_device_register(&plink->link_class_dev);
+	if (ret) {
+		printk(KERN_ERR PFX "xcpm_link_add_sysfs: error %d in registering"
+                          " link%d class dev\n", ret, link_index);
+		goto out;
+	}
+
+	ret = sysfs_create_group(&plink->link_class_dev.kobj,
+				 &xcpm_link_dev_attr_group);
+	if (!ret)
+		goto out;
+	printk(KERN_ERR PFX "xcpm_link_add_sysfs: error %d in creating"
+	       " xcpm link%d attr group\n", ret, link_index);
+	class_device_unregister(&plink->link_class_dev);
+
+out:
+	return ret;
+}
+
+void xcpm_link_remove_sysfs(int link_index)
+{
+	struct link_info *plink = &xcpm->links[link_index];
+
+	sysfs_remove_group(&plink->link_class_dev.kobj,
+			   &xcpm_link_dev_attr_group);
+	class_device_unregister(&plink->link_class_dev);
+}
+
+static ssize_t show_resource_flags(struct class_device *class_dev, char *buf)
+{
+	return sprintf(buf, "0x%x", xcpm->resource_flags);
+}
+
+static CLASS_DEVICE_ATTR(resource_flags, S_IRUGO, show_resource_flags, NULL);
+
+static struct attribute *xcpm_dev_attrs[] = {
+	&class_device_attr_resource_flags.attr,
+	NULL
+};
+
+static struct attribute_group xcpm_dev_attr_group = {
+	.attrs = xcpm_dev_attrs,
+};
+
+int xcpm_register_sysfs(void)
+{
+	int ret;
+
+	xcpm_class_dev.class = &xscore_class;
+	xcpm_class_dev.parent = NULL;
+	snprintf(xcpm_class_dev.class_id, BUS_ID_SIZE, "xcpm");
+
+	ret = class_device_register(&xcpm_class_dev);
+	if (ret) {
+		printk(KERN_ERR PFX "xcpm_register_sysfs: error %d in registering"
+		       " xcpm class dev\n", ret);
+		goto out;
+	}
+
+	ret = sysfs_create_group(&xcpm_class_dev.kobj, &xcpm_dev_attr_group);
+	if (!ret)
+		goto out;
+	printk(KERN_ERR PFX "xcpm_register_sysfs: error %d in creating"
+	       " xcpm attr group\n", ret);
+	class_device_unregister(&xcpm_class_dev);
+out:
+	return ret;
+}
+
+void xcpm_unregister_sysfs(void)
+{
+	sysfs_remove_group(&xcpm_class_dev.kobj, &xcpm_dev_attr_group);
+	class_device_unregister(&xcpm_class_dev);
+}
diff --git a/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.h b/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.h
new file mode 100644
index 0000000..b425fc0
--- /dev/null
+++ b/drivers/infiniband/ulp/xsigo/xscore/xcpm_stats.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006-2008 Xsigo Systems Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __XCPM_STATS_H__
+#define __XCPM_STATS_H__
+
+int xcpm_link_add_sysfs(int link_index);
+void xcpm_link_remove_sysfs(int link_index);
+
+int xcpm_register_sysfs(void);
+void xcpm_unregister_sysfs(void);
+
+#endif	/* __XCPM_STATS_H__ */
-- 
1.5.2






More information about the ewg mailing list