[openib-general] [PATCH repost] option to set node description in sysfs
Michael S. Tsirkin
mst at mellanox.co.il
Tue Dec 20 04:55:13 PST 2005
Here's an updated version of the node description patch.
changes:
Updated to svn rev 4044
Make sure the whole 64 byte description is initialized before passing it to
hardware.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
This patch does a few things:
- Adds node_guid and node_desc fields to struct ib_device
- Has mthca set these fields on startup
- Extends modify_device method to handle setting node_desc
- Exposes node_desc in sysfs
- Allows userspace to set node_desc by writing into sysfs file, eg.
echo -n `hostname` >> /sys/class/linux-kernel/drivers/infiniband/mthca0/node_desc
This should probably be combined with Sean's work to get rid of
node_guid queries in ULPs.
Comments?
- R.
Index: linux-2.6.14/drivers/infiniband/core/sysfs.c
===================================================================
--- linux-2.6.14/drivers/infiniband/core/sysfs.c (revision 4042)
+++ linux-2.6.14/drivers/infiniband/core/sysfs.c (working copy)
@@ -637,14 +637,42 @@
be16_to_cpu(((__be16 *) &attr.node_guid)[3]));
}
+static ssize_t show_node_desc(struct class_device *cdev, char *buf)
+{
+ struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+
+ return sprintf(buf, "%.64s\n", dev->node_desc);
+}
+
+static ssize_t set_node_desc(struct class_device *cdev, const char *buf,
+ size_t count)
+{
+ struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+ struct ib_device_modify desc = {};
+ int ret;
+
+ if (!dev->modify_device)
+ return -EIO;
+
+ memcpy(desc.node_desc, buf, min_t(int, count, 64));
+ ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
static CLASS_DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
static CLASS_DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
+static CLASS_DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc,
+ set_node_desc);
static struct class_device_attribute *ib_class_attributes[] = {
&class_device_attr_node_type,
&class_device_attr_sys_image_guid,
- &class_device_attr_node_guid
+ &class_device_attr_node_guid,
+ &class_device_attr_node_desc
};
static struct class ib_class = {
Index: linux-2.6.14/drivers/infiniband/hw/mthca/mthca_provider.c
===================================================================
--- linux-2.6.14/drivers/infiniband/hw/mthca/mthca_provider.c (revision 4042)
+++ linux-2.6.14/drivers/infiniband/hw/mthca/mthca_provider.c (working copy)
@@ -177,6 +177,23 @@
return err;
}
+static int mthca_modify_device(struct ib_device *ibdev,
+ int mask,
+ struct ib_device_modify *props)
+{
+ if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
+ return -EOPNOTSUPP;
+
+ if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
+ if (down_interruptible(&to_mdev(ibdev)->cap_mask_mutex))
+ return -ERESTARTSYS;
+ memcpy(ibdev->node_desc, props->node_desc, 64);
+ up(&to_mdev(ibdev)->cap_mask_mutex);
+ }
+
+ return 0;
+}
+
static int mthca_modify_port(struct ib_device *ibdev,
u8 port, int port_modify_mask,
struct ib_port_modify *props)
@@ -1071,6 +1088,20 @@
goto out;
init_query_mad(in_mad);
+ in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
+
+ err = mthca_MAD_IFC(dev, 1, 1,
+ 1, NULL, NULL, in_mad, out_mad,
+ &status);
+ if (err)
+ goto out;
+ if (status) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ memcpy(dev->ib_dev.node_desc, out_mad->data, 64);
+
in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
err = mthca_MAD_IFC(dev, 1, 1,
@@ -1129,6 +1160,7 @@
dev->ib_dev.class_dev.dev = &dev->pdev->dev;
dev->ib_dev.query_device = mthca_query_device;
dev->ib_dev.query_port = mthca_query_port;
+ dev->ib_dev.modify_device = mthca_modify_device;
dev->ib_dev.modify_port = mthca_modify_port;
dev->ib_dev.query_pkey = mthca_query_pkey;
dev->ib_dev.query_gid = mthca_query_gid;
Index: linux-2.6.14/drivers/infiniband/hw/mthca/mthca_mad.c
===================================================================
--- linux-2.6.14/drivers/infiniband/hw/mthca/mthca_mad.c (revision 4042)
+++ linux-2.6.14/drivers/infiniband/hw/mthca/mthca_mad.c (working copy)
@@ -106,6 +106,19 @@
}
}
+static void node_desc_override(struct ib_device *dev,
+ struct ib_mad *mad)
+{
+ if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
+ mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
+ mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP &&
+ mad->mad_hdr.attr_id == IB_SMP_ATTR_NODE_DESC) {
+ down(&to_mdev(dev)->cap_mask_mutex);
+ memcpy(((struct ib_smp *) mad)->data, dev->node_desc, 64);
+ up(&to_mdev(dev)->cap_mask_mutex);
+ }
+}
+
static void forward_trap(struct mthca_dev *dev,
u8 port_num,
struct ib_mad *mad)
@@ -204,8 +217,10 @@
return IB_MAD_RESULT_FAILURE;
}
- if (!out_mad->mad_hdr.status)
+ if (!out_mad->mad_hdr.status) {
smp_snoop(ibdev, port_num, in_mad);
+ node_desc_override(ibdev, out_mad);
+ }
/* set return bit in status of directed route responses */
if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
Index: linux-2.6.14/drivers/infiniband/include/rdma/ib_verbs.h
===================================================================
--- linux-2.6.14/drivers/infiniband/include/rdma/ib_verbs.h (revision 4044)
+++ linux-2.6.14/drivers/infiniband/include/rdma/ib_verbs.h (working copy)
@@ -231,11 +231,13 @@
};
enum ib_device_modify_flags {
- IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1
+ IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
+ IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
};
struct ib_device_modify {
u64 sys_image_guid;
+ char node_desc[64];
};
enum ib_port_modify_flags {
@@ -959,6 +961,7 @@
u64 uverbs_cmd_mask;
int uverbs_abi_ver;
+ char node_desc[64];
__be64 node_guid;
u8 node_type;
u8 phys_port_cnt;
--
MST
More information about the general
mailing list