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/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: infiniband/include/rdma/ib_verbs.h
===================================================================
--- infiniband/include/rdma/ib_verbs.h  (revision 3432)
+++ infiniband/include/rdma/ib_verbs.h  (working copy)
@@ -223,11 +223,13 @@ struct ib_port_attr {
 };
 
 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 {
@@ -952,6 +954,8 @@ struct ib_device {
                IB_DEV_UNREGISTERED
        }                            reg_state;
 
+       char                         node_desc[64];
+       __be64                       node_guid;
        u8                           node_type;
        u8                           phys_port_cnt;
 };
Index: infiniband/core/sysfs.c
===================================================================
--- infiniband/core/sysfs.c     (revision 3432)
+++ infiniband/core/sysfs.c     (working copy)
@@ -609,28 +609,50 @@ static ssize_t show_sys_image_guid(struc
 static ssize_t show_node_guid(struct class_device *cdev, char *buf)
 {
        struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
-       struct ib_device_attr attr;
-       ssize_t ret;
 
-       ret = ib_query_device(dev, &attr);
+       return sprintf(buf, "%04x:%04x:%04x:%04x\n",
+                      be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
+                      be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
+                      be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
+                      be16_to_cpu(((__be16 *) &dev->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 sprintf(buf, "%04x:%04x:%04x:%04x\n",
-                      be16_to_cpu(((__be16 *) &attr.node_guid)[0]),
-                      be16_to_cpu(((__be16 *) &attr.node_guid)[1]),
-                      be16_to_cpu(((__be16 *) &attr.node_guid)[2]),
-                      be16_to_cpu(((__be16 *) &attr.node_guid)[3]));
+       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: infiniband/hw/mthca/mthca_dev.h
===================================================================
--- infiniband/hw/mthca/mthca_dev.h     (revision 3432)
+++ infiniband/hw/mthca/mthca_dev.h     (working copy)
@@ -283,7 +283,7 @@ struct mthca_dev {
        u64              ddr_end;
 
        MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
-       struct semaphore cap_mask_mutex;
+       struct semaphore dev_attr_mutex;
 
        void __iomem    *hcr;
        void __iomem    *kar;
@@ -517,4 +517,17 @@ static inline int mthca_is_memfree(struc
        return dev->mthca_flags & MTHCA_FLAG_MEMFREE;
 }
 
+/*
+ * XXX remove once 2.6.14 is released.
+ */
+static inline void *mthca_kzalloc(size_t size, unsigned int __nocast flags)
+{
+       void *ret = kmalloc(size, flags);
+       if (ret)
+               memset(ret, 0, size);
+       return ret;
+}
+#undef kzalloc
+#define kzalloc(s, f) mthca_kzalloc(s, f);
+
 #endif /* MTHCA_DEV_H */
Index: infiniband/hw/mthca/mthca_provider.c
===================================================================
--- infiniband/hw/mthca/mthca_provider.c        (revision 3432)
+++ infiniband/hw/mthca/mthca_provider.c        (working copy)
@@ -44,6 +44,14 @@
 #include "mthca_user.h"
 #include "mthca_memfree.h"
 
+static void init_query_mad(struct ib_smp *mad)
+{
+       mad->base_version  = 1;
+       mad->mgmt_class    = IB_MGMT_CLASS_SUBN_LID_ROUTED;
+       mad->class_version = 1;
+       mad->method        = IB_MGMT_METHOD_GET;
+}
+
 static int mthca_query_device(struct ib_device *ibdev,
                              struct ib_device_attr *props)
 {
@@ -54,7 +62,7 @@ static int mthca_query_device(struct ib_
 
        u8 status;
 
-       in_mad  = kmalloc(sizeof *in_mad, GFP_KERNEL);
+       in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
                goto out;
@@ -63,12 +71,8 @@ static int mthca_query_device(struct ib_
 
        props->fw_ver              = mdev->fw_ver;
 
-       memset(in_mad, 0, sizeof *in_mad);
-       in_mad->base_version       = 1;
-       in_mad->mgmt_class         = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-       in_mad->class_version      = 1;
-       in_mad->method             = IB_MGMT_METHOD_GET;
-       in_mad->attr_id            = IB_SMP_ATTR_NODE_INFO;
+       init_query_mad(in_mad);
+       in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
 
        err = mthca_MAD_IFC(mdev, 1, 1,
                            1, NULL, NULL, in_mad, out_mad,
@@ -115,20 +119,16 @@ static int mthca_query_port(struct ib_de
        int err = -ENOMEM;
        u8 status;
 
-       in_mad  = kmalloc(sizeof *in_mad, GFP_KERNEL);
+       in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
                goto out;
 
        memset(props, 0, sizeof *props);
 
-       memset(in_mad, 0, sizeof *in_mad);
-       in_mad->base_version       = 1;
-       in_mad->mgmt_class         = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-       in_mad->class_version      = 1;
-       in_mad->method             = IB_MGMT_METHOD_GET;
-       in_mad->attr_id            = IB_SMP_ATTR_PORT_INFO;
-       in_mad->attr_mod           = cpu_to_be32(port);
+       init_query_mad(in_mad);
+       in_mad->attr_id  = IB_SMP_ATTR_PORT_INFO;
+       in_mad->attr_mod = cpu_to_be32(port);
 
        err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
                            port, NULL, NULL, in_mad, out_mad,
@@ -160,6 +160,23 @@ static int mthca_query_port(struct ib_de
        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)->dev_attr_mutex))
+                       return -ERESTARTSYS;
+               memcpy(ibdev->node_desc, props->node_desc, 64);
+               up(&to_mdev(ibdev)->dev_attr_mutex);
+       }
+
+       return 0;
+}
+
 static int mthca_modify_port(struct ib_device *ibdev,
                             u8 port, int port_modify_mask,
                             struct ib_port_modify *props)
@@ -169,7 +186,7 @@ static int mthca_modify_port(struct ib_d
        int err;
        u8 status;
 
-       if (down_interruptible(&to_mdev(ibdev)->cap_mask_mutex))
+       if (down_interruptible(&to_mdev(ibdev)->dev_attr_mutex))
                return -ERESTARTSYS;
 
        err = mthca_query_port(ibdev, port, &attr);
@@ -191,7 +208,7 @@ static int mthca_modify_port(struct ib_d
        }
 
 out:
-       up(&to_mdev(ibdev)->cap_mask_mutex);
+       up(&to_mdev(ibdev)->dev_attr_mutex);
        return err;
 }
 
@@ -203,18 +220,14 @@ static int mthca_query_pkey(struct ib_de
        int err = -ENOMEM;
        u8 status;
 
-       in_mad  = kmalloc(sizeof *in_mad, GFP_KERNEL);
+       in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
                goto out;
 
-       memset(in_mad, 0, sizeof *in_mad);
-       in_mad->base_version       = 1;
-       in_mad->mgmt_class         = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-       in_mad->class_version      = 1;
-       in_mad->method             = IB_MGMT_METHOD_GET;
-       in_mad->attr_id            = IB_SMP_ATTR_PKEY_TABLE;
-       in_mad->attr_mod           = cpu_to_be32(index / 32);
+       init_query_mad(in_mad);
+       in_mad->attr_id  = IB_SMP_ATTR_PKEY_TABLE;
+       in_mad->attr_mod = cpu_to_be32(index / 32);
 
        err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
                            port, NULL, NULL, in_mad, out_mad,
@@ -242,18 +255,14 @@ static int mthca_query_gid(struct ib_dev
        int err = -ENOMEM;
        u8 status;
 
-       in_mad  = kmalloc(sizeof *in_mad, GFP_KERNEL);
+       in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
                goto out;
 
-       memset(in_mad, 0, sizeof *in_mad);
-       in_mad->base_version       = 1;
-       in_mad->mgmt_class         = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-       in_mad->class_version      = 1;
-       in_mad->method             = IB_MGMT_METHOD_GET;
-       in_mad->attr_id            = IB_SMP_ATTR_PORT_INFO;
-       in_mad->attr_mod           = cpu_to_be32(port);
+       init_query_mad(in_mad);
+       in_mad->attr_id  = IB_SMP_ATTR_PORT_INFO;
+       in_mad->attr_mod = cpu_to_be32(port);
 
        err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
                            port, NULL, NULL, in_mad, out_mad,
@@ -267,13 +276,9 @@ static int mthca_query_gid(struct ib_dev
 
        memcpy(gid->raw, out_mad->data + 8, 8);
 
-       memset(in_mad, 0, sizeof *in_mad);
-       in_mad->base_version       = 1;
-       in_mad->mgmt_class         = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-       in_mad->class_version      = 1;
-       in_mad->method             = IB_MGMT_METHOD_GET;
-       in_mad->attr_id            = IB_SMP_ATTR_GUID_INFO;
-       in_mad->attr_mod           = cpu_to_be32(index / 8);
+       init_query_mad(in_mad);
+       in_mad->attr_id  = IB_SMP_ATTR_GUID_INFO;
+       in_mad->attr_mod = cpu_to_be32(index / 8);
 
        err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
                            port, NULL, NULL, in_mad, out_mad,
@@ -1050,11 +1055,62 @@ static struct class_device_attribute *mt
        &class_device_attr_board_id
 };
 
+static int mthca_init_node_data(struct mthca_dev *dev)
+{
+       struct ib_smp *in_mad  = NULL;
+       struct ib_smp *out_mad = NULL;
+       int err = -ENOMEM;
+       u8 status;
+
+       in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
+       out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
+       if (!in_mad || !out_mad)
+               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,
+                           1, NULL, NULL, in_mad, out_mad,
+                           &status);
+       if (err)
+               goto out;
+       if (status) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
+
+out:
+       kfree(in_mad);
+       kfree(out_mad);
+       return err;
+}
+
 int mthca_register_device(struct mthca_dev *dev)
 {
        int ret;
        int i;
 
+       ret = mthca_init_node_data(dev);
+       if (ret)
+               return ret;
+
        strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
        dev->ib_dev.owner                = THIS_MODULE;
 
@@ -1064,6 +1120,7 @@ int mthca_register_device(struct mthca_d
        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;
@@ -1120,7 +1177,7 @@ int mthca_register_device(struct mthca_d
                dev->ib_dev.post_recv     = mthca_tavor_post_receive;
        }
 
-       init_MUTEX(&dev->cap_mask_mutex);
+       init_MUTEX(&dev->dev_attr_mutex);
 
        ret = ib_register_device(&dev->ib_dev);
        if (ret)
Index: infiniband/hw/mthca/mthca_mad.c
===================================================================
--- infiniband/hw/mthca/mthca_mad.c     (revision 3432)
+++ infiniband/hw/mthca/mthca_mad.c     (working copy)
@@ -111,6 +111,19 @@ static void smp_snoop(struct ib_device *
        }
 }
 
+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)->dev_attr_mutex);
+               memcpy(((struct ib_smp *) mad)->data, dev->node_desc, 64);
+               up(&to_mdev(dev)->dev_attr_mutex);
+       }
+}
+
 static void forward_trap(struct mthca_dev *dev,
                         u8 port_num,
                         struct ib_mad *mad)
@@ -250,8 +263,10 @@ int mthca_process_mad(struct ib_device *
                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)
_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to