I just applied the patch below to svn:

---

Add a node_guid field to struct ib_device.  It is the responsibility
of the low-level driver to initialize this field before registering a
device with the midlayer.  Convert everyone to looking at this field
instead of calling ib_query_device() when all they want is the node
GUID, and remove the node_guid field from struct ib_device_attr.

Signed-off-by: Sean Hefty <[EMAIL PROTECTED]>
Signed-off-by: Roland Dreier <[EMAIL PROTECTED]>

--- infiniband/ulp/srp/ib_srp.c (revision 4929)
+++ infiniband/ulp/srp/ib_srp.c (working copy)
@@ -1516,8 +1516,7 @@ static ssize_t show_port(struct class_de
 
 static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
 
-static struct srp_host *srp_add_port(struct ib_device *device,
-                                    __be64 node_guid, u8 port)
+static struct srp_host *srp_add_port(struct ib_device *device, u8 port)
 {
        struct srp_host *host;
 
@@ -1532,7 +1531,7 @@ static struct srp_host *srp_add_port(str
        host->port = port;
 
        host->initiator_port_id[7] = port;
-       memcpy(host->initiator_port_id + 8, &node_guid, 8);
+       memcpy(host->initiator_port_id + 8, &device->node_guid, 8);
 
        host->pd   = ib_alloc_pd(device);
        if (IS_ERR(host->pd))
@@ -1580,22 +1579,11 @@ static void srp_add_one(struct ib_device
 {
        struct list_head *dev_list;
        struct srp_host *host;
-       struct ib_device_attr *dev_attr;
        int s, e, p;
 
-       dev_attr = kmalloc(sizeof *dev_attr, GFP_KERNEL);
-       if (!dev_attr)
-               return;
-
-       if (ib_query_device(device, dev_attr)) {
-               printk(KERN_WARNING PFX "Couldn't query node GUID for %s.\n",
-                      device->name);
-               goto out;
-       }
-
        dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
        if (!dev_list)
-               goto out;
+               return;
 
        INIT_LIST_HEAD(dev_list);
 
@@ -1608,15 +1596,12 @@ static void srp_add_one(struct ib_device
        }
 
        for (p = s; p <= e; ++p) {
-               host = srp_add_port(device, dev_attr->node_guid, p);
+               host = srp_add_port(device, p);
                if (host)
                        list_add_tail(&host->list, dev_list);
        }
 
        ib_set_client_data(device, &srp_client, dev_list);
-
-out:
-       kfree(dev_attr);
 }
 
 static void srp_remove_one(struct ib_device *device)
--- infiniband/include/rdma/ib_verbs.h  (revision 4929)
+++ infiniband/include/rdma/ib_verbs.h  (working copy)
@@ -88,7 +88,6 @@ enum ib_atomic_cap {
 
 struct ib_device_attr {
        u64                     fw_ver;
-       __be64                  node_guid;
        __be64                  sys_image_guid;
        u64                     max_mr_size;
        u64                     page_size_cap;
--- infiniband/core/cm.c        (revision 4929)
+++ infiniband/core/cm.c        (working copy)
@@ -3230,22 +3230,6 @@ int ib_cm_init_qp_attr(struct ib_cm_id *
 }
 EXPORT_SYMBOL(ib_cm_init_qp_attr);
 
-static __be64 cm_get_ca_guid(struct ib_device *device)
-{
-       struct ib_device_attr *device_attr;
-       __be64 guid;
-       int ret;
-
-       device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL);
-       if (!device_attr)
-               return 0;
-
-       ret = ib_query_device(device, device_attr);
-       guid = ret ? 0 : device_attr->node_guid;
-       kfree(device_attr);
-       return guid;
-}
-
 static void cm_add_one(struct ib_device *device)
 {
        struct cm_device *cm_dev;
@@ -3267,9 +3251,7 @@ static void cm_add_one(struct ib_device 
                return;
 
        cm_dev->device = device;
-       cm_dev->ca_guid = cm_get_ca_guid(device);
-       if (!cm_dev->ca_guid)
-               goto error1;
+       cm_dev->ca_guid = device->node_guid;
 
        set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
        for (i = 1; i <= device->phys_port_cnt; i++) {
@@ -3284,11 +3266,11 @@ static void cm_add_one(struct ib_device 
                                                        cm_recv_handler,
                                                        port);
                if (IS_ERR(port->mad_agent))
-                       goto error2;
+                       goto error1;
 
                ret = ib_modify_port(device, i, 0, &port_modify);
                if (ret)
-                       goto error3;
+                       goto error2;
        }
        ib_set_client_data(device, &cm_client, cm_dev);
 
@@ -3297,9 +3279,9 @@ static void cm_add_one(struct ib_device 
        write_unlock_irqrestore(&cm.device_lock, flags);
        return;
 
-error3:
-       ib_unregister_mad_agent(port->mad_agent);
 error2:
+       ib_unregister_mad_agent(port->mad_agent);
+error1:
        port_modify.set_port_cap_mask = 0;
        port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
        while (--i) {
@@ -3307,7 +3289,6 @@ error2:
                ib_modify_port(device, port->port_num, 0, &port_modify);
                ib_unregister_mad_agent(port->mad_agent);
        }
-error1:
        kfree(cm_dev);
 }
 
--- infiniband/core/sysfs.c     (revision 4929)
+++ infiniband/core/sysfs.c     (working copy)
@@ -449,13 +449,7 @@ static int ib_device_uevent(struct class
                return -ENOMEM;
 
        /*
-        * It might be nice to pass the node GUID with the event, but
-        * right now the only way to get it is to query the device
-        * provider, and this can crash during device removal because
-        * we are will be running after driver removal has started.
-        * We could add a node_guid field to struct ib_device, or we
-        * could just let userspace read the node GUID from sysfs when
-        * devices are added.
+        * It would be nice to pass the node GUID with the event...
         */
 
        envp[i] = NULL;
@@ -627,21 +621,15 @@ 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;
 
        if (!ibdev_is_alive(dev))
                return -ENODEV;
 
-       ret = ib_query_device(dev, &attr);
-       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]));
+                      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 CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
--- infiniband/core/uverbs_cmd.c        (revision 4929)
+++ infiniband/core/uverbs_cmd.c        (working copy)
@@ -157,7 +157,7 @@ ssize_t ib_uverbs_query_device(struct ib
        memset(&resp, 0, sizeof resp);
 
        resp.fw_ver                    = attr.fw_ver;
-       resp.node_guid                 = attr.node_guid;
+       resp.node_guid                 = file->device->ib_dev->node_guid;
        resp.sys_image_guid            = attr.sys_image_guid;
        resp.max_mr_size               = attr.max_mr_size;
        resp.page_size_cap             = attr.page_size_cap;
--- infiniband/hw/ipath/ipath_verbs.c   (revision 4929)
+++ infiniband/hw/ipath/ipath_verbs.c   (working copy)
@@ -5368,7 +5368,6 @@ static int ipath_query_device(struct ib_
        props->hw_ver = boardrev << 16 | majrev << 8 | minrev;
 
        props->sys_image_guid = dev->sys_image_guid;
-       props->node_guid = ipath_layer_get_guid(dev->ib_unit);
 
        props->max_mr_size = ~0ull;
        props->max_qp = 0xffff;
--- infiniband/hw/mthca/mthca_provider.c        (revision 4929)
+++ infiniband/hw/mthca/mthca_provider.c        (working copy)
@@ -91,7 +91,6 @@ static int mthca_query_device(struct ib_
        props->vendor_part_id      = be16_to_cpup((__be16 *) (out_mad->data + 
30));
        props->hw_ver              = be32_to_cpup((__be32 *) (out_mad->data + 
32));
        memcpy(&props->sys_image_guid, out_mad->data +  4, 8);
-       memcpy(&props->node_guid,      out_mad->data + 12, 8);
 
        props->max_mr_size         = ~0ull;
        props->page_size_cap       = mdev->limits.page_size_cap;
_______________________________________________
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