Commit cf311cd49a78f1e431787068cc31d29d06a415e6
Committed by
Roland Dreier
1 parent
87635b71b5
Exists in
master
and in
7 other branches
IB: Add node_guid to struct ib_device
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 <sean.hefty@intel.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
Showing 6 changed files with 54 additions and 64 deletions Side-by-side Diff
drivers/infiniband/core/cm.c
... | ... | @@ -3163,22 +3163,6 @@ |
3163 | 3163 | } |
3164 | 3164 | EXPORT_SYMBOL(ib_cm_init_qp_attr); |
3165 | 3165 | |
3166 | -static __be64 cm_get_ca_guid(struct ib_device *device) | |
3167 | -{ | |
3168 | - struct ib_device_attr *device_attr; | |
3169 | - __be64 guid; | |
3170 | - int ret; | |
3171 | - | |
3172 | - device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL); | |
3173 | - if (!device_attr) | |
3174 | - return 0; | |
3175 | - | |
3176 | - ret = ib_query_device(device, device_attr); | |
3177 | - guid = ret ? 0 : device_attr->node_guid; | |
3178 | - kfree(device_attr); | |
3179 | - return guid; | |
3180 | -} | |
3181 | - | |
3182 | 3166 | static void cm_add_one(struct ib_device *device) |
3183 | 3167 | { |
3184 | 3168 | struct cm_device *cm_dev; |
... | ... | @@ -3200,9 +3184,7 @@ |
3200 | 3184 | return; |
3201 | 3185 | |
3202 | 3186 | cm_dev->device = device; |
3203 | - cm_dev->ca_guid = cm_get_ca_guid(device); | |
3204 | - if (!cm_dev->ca_guid) | |
3205 | - goto error1; | |
3187 | + cm_dev->ca_guid = device->node_guid; | |
3206 | 3188 | |
3207 | 3189 | set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); |
3208 | 3190 | for (i = 1; i <= device->phys_port_cnt; i++) { |
3209 | 3191 | |
... | ... | @@ -3217,11 +3199,11 @@ |
3217 | 3199 | cm_recv_handler, |
3218 | 3200 | port); |
3219 | 3201 | if (IS_ERR(port->mad_agent)) |
3220 | - goto error2; | |
3202 | + goto error1; | |
3221 | 3203 | |
3222 | 3204 | ret = ib_modify_port(device, i, 0, &port_modify); |
3223 | 3205 | if (ret) |
3224 | - goto error3; | |
3206 | + goto error2; | |
3225 | 3207 | } |
3226 | 3208 | ib_set_client_data(device, &cm_client, cm_dev); |
3227 | 3209 | |
3228 | 3210 | |
... | ... | @@ -3230,9 +3212,9 @@ |
3230 | 3212 | write_unlock_irqrestore(&cm.device_lock, flags); |
3231 | 3213 | return; |
3232 | 3214 | |
3233 | -error3: | |
3234 | - ib_unregister_mad_agent(port->mad_agent); | |
3235 | 3215 | error2: |
3216 | + ib_unregister_mad_agent(port->mad_agent); | |
3217 | +error1: | |
3236 | 3218 | port_modify.set_port_cap_mask = 0; |
3237 | 3219 | port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; |
3238 | 3220 | while (--i) { |
... | ... | @@ -3240,7 +3222,6 @@ |
3240 | 3222 | ib_modify_port(device, port->port_num, 0, &port_modify); |
3241 | 3223 | ib_unregister_mad_agent(port->mad_agent); |
3242 | 3224 | } |
3243 | -error1: | |
3244 | 3225 | kfree(cm_dev); |
3245 | 3226 | } |
3246 | 3227 |
drivers/infiniband/core/sysfs.c
... | ... | @@ -445,13 +445,7 @@ |
445 | 445 | return -ENOMEM; |
446 | 446 | |
447 | 447 | /* |
448 | - * It might be nice to pass the node GUID with the event, but | |
449 | - * right now the only way to get it is to query the device | |
450 | - * provider, and this can crash during device removal because | |
451 | - * we are will be running after driver removal has started. | |
452 | - * We could add a node_guid field to struct ib_device, or we | |
453 | - * could just let userspace read the node GUID from sysfs when | |
454 | - * devices are added. | |
448 | + * It would be nice to pass the node GUID with the event... | |
455 | 449 | */ |
456 | 450 | |
457 | 451 | envp[i] = NULL; |
458 | 452 | |
459 | 453 | |
... | ... | @@ -623,21 +617,15 @@ |
623 | 617 | static ssize_t show_node_guid(struct class_device *cdev, char *buf) |
624 | 618 | { |
625 | 619 | struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); |
626 | - struct ib_device_attr attr; | |
627 | - ssize_t ret; | |
628 | 620 | |
629 | 621 | if (!ibdev_is_alive(dev)) |
630 | 622 | return -ENODEV; |
631 | 623 | |
632 | - ret = ib_query_device(dev, &attr); | |
633 | - if (ret) | |
634 | - return ret; | |
635 | - | |
636 | 624 | return sprintf(buf, "%04x:%04x:%04x:%04x\n", |
637 | - be16_to_cpu(((__be16 *) &attr.node_guid)[0]), | |
638 | - be16_to_cpu(((__be16 *) &attr.node_guid)[1]), | |
639 | - be16_to_cpu(((__be16 *) &attr.node_guid)[2]), | |
640 | - be16_to_cpu(((__be16 *) &attr.node_guid)[3])); | |
625 | + be16_to_cpu(((__be16 *) &dev->node_guid)[0]), | |
626 | + be16_to_cpu(((__be16 *) &dev->node_guid)[1]), | |
627 | + be16_to_cpu(((__be16 *) &dev->node_guid)[2]), | |
628 | + be16_to_cpu(((__be16 *) &dev->node_guid)[3])); | |
641 | 629 | } |
642 | 630 | |
643 | 631 | static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL); |
drivers/infiniband/core/uverbs_cmd.c
... | ... | @@ -157,7 +157,7 @@ |
157 | 157 | memset(&resp, 0, sizeof resp); |
158 | 158 | |
159 | 159 | resp.fw_ver = attr.fw_ver; |
160 | - resp.node_guid = attr.node_guid; | |
160 | + resp.node_guid = file->device->ib_dev->node_guid; | |
161 | 161 | resp.sys_image_guid = attr.sys_image_guid; |
162 | 162 | resp.max_mr_size = attr.max_mr_size; |
163 | 163 | resp.page_size_cap = attr.page_size_cap; |
drivers/infiniband/hw/mthca/mthca_provider.c
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
34 | 34 | * SOFTWARE. |
35 | 35 | * |
36 | - * $Id: mthca_provider.c 1397 2004-12-28 05:09:00Z roland $ | |
36 | + * $Id: mthca_provider.c 4859 2006-01-09 21:55:10Z roland $ | |
37 | 37 | */ |
38 | 38 | |
39 | 39 | #include <rdma/ib_smi.h> |
... | ... | @@ -91,7 +91,6 @@ |
91 | 91 | props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); |
92 | 92 | props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); |
93 | 93 | memcpy(&props->sys_image_guid, out_mad->data + 4, 8); |
94 | - memcpy(&props->node_guid, out_mad->data + 12, 8); | |
95 | 94 | |
96 | 95 | props->max_mr_size = ~0ull; |
97 | 96 | props->page_size_cap = mdev->limits.page_size_cap; |
98 | 97 | |
... | ... | @@ -1054,10 +1053,47 @@ |
1054 | 1053 | &class_device_attr_board_id |
1055 | 1054 | }; |
1056 | 1055 | |
1056 | +static int mthca_init_node_data(struct mthca_dev *dev) | |
1057 | +{ | |
1058 | + struct ib_smp *in_mad = NULL; | |
1059 | + struct ib_smp *out_mad = NULL; | |
1060 | + int err = -ENOMEM; | |
1061 | + u8 status; | |
1062 | + | |
1063 | + in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); | |
1064 | + out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); | |
1065 | + if (!in_mad || !out_mad) | |
1066 | + goto out; | |
1067 | + | |
1068 | + init_query_mad(in_mad); | |
1069 | + in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; | |
1070 | + | |
1071 | + err = mthca_MAD_IFC(dev, 1, 1, | |
1072 | + 1, NULL, NULL, in_mad, out_mad, | |
1073 | + &status); | |
1074 | + if (err) | |
1075 | + goto out; | |
1076 | + if (status) { | |
1077 | + err = -EINVAL; | |
1078 | + goto out; | |
1079 | + } | |
1080 | + | |
1081 | + memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8); | |
1082 | + | |
1083 | +out: | |
1084 | + kfree(in_mad); | |
1085 | + kfree(out_mad); | |
1086 | + return err; | |
1087 | +} | |
1088 | + | |
1057 | 1089 | int mthca_register_device(struct mthca_dev *dev) |
1058 | 1090 | { |
1059 | 1091 | int ret; |
1060 | 1092 | int i; |
1093 | + | |
1094 | + ret = mthca_init_node_data(dev); | |
1095 | + if (ret) | |
1096 | + return ret; | |
1061 | 1097 | |
1062 | 1098 | strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); |
1063 | 1099 | dev->ib_dev.owner = THIS_MODULE; |
drivers/infiniband/ulp/srp/ib_srp.c
... | ... | @@ -1516,8 +1516,7 @@ |
1516 | 1516 | |
1517 | 1517 | static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); |
1518 | 1518 | |
1519 | -static struct srp_host *srp_add_port(struct ib_device *device, | |
1520 | - __be64 node_guid, u8 port) | |
1519 | +static struct srp_host *srp_add_port(struct ib_device *device, u8 port) | |
1521 | 1520 | { |
1522 | 1521 | struct srp_host *host; |
1523 | 1522 | |
... | ... | @@ -1532,7 +1531,7 @@ |
1532 | 1531 | host->port = port; |
1533 | 1532 | |
1534 | 1533 | host->initiator_port_id[7] = port; |
1535 | - memcpy(host->initiator_port_id + 8, &node_guid, 8); | |
1534 | + memcpy(host->initiator_port_id + 8, &device->node_guid, 8); | |
1536 | 1535 | |
1537 | 1536 | host->pd = ib_alloc_pd(device); |
1538 | 1537 | if (IS_ERR(host->pd)) |
1539 | 1538 | |
1540 | 1539 | |
... | ... | @@ -1580,22 +1579,11 @@ |
1580 | 1579 | { |
1581 | 1580 | struct list_head *dev_list; |
1582 | 1581 | struct srp_host *host; |
1583 | - struct ib_device_attr *dev_attr; | |
1584 | 1582 | int s, e, p; |
1585 | 1583 | |
1586 | - dev_attr = kmalloc(sizeof *dev_attr, GFP_KERNEL); | |
1587 | - if (!dev_attr) | |
1588 | - return; | |
1589 | - | |
1590 | - if (ib_query_device(device, dev_attr)) { | |
1591 | - printk(KERN_WARNING PFX "Couldn't query node GUID for %s.\n", | |
1592 | - device->name); | |
1593 | - goto out; | |
1594 | - } | |
1595 | - | |
1596 | 1584 | dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); |
1597 | 1585 | if (!dev_list) |
1598 | - goto out; | |
1586 | + return; | |
1599 | 1587 | |
1600 | 1588 | INIT_LIST_HEAD(dev_list); |
1601 | 1589 | |
1602 | 1590 | |
... | ... | @@ -1608,15 +1596,12 @@ |
1608 | 1596 | } |
1609 | 1597 | |
1610 | 1598 | for (p = s; p <= e; ++p) { |
1611 | - host = srp_add_port(device, dev_attr->node_guid, p); | |
1599 | + host = srp_add_port(device, p); | |
1612 | 1600 | if (host) |
1613 | 1601 | list_add_tail(&host->list, dev_list); |
1614 | 1602 | } |
1615 | 1603 | |
1616 | 1604 | ib_set_client_data(device, &srp_client, dev_list); |
1617 | - | |
1618 | -out: | |
1619 | - kfree(dev_attr); | |
1620 | 1605 | } |
1621 | 1606 | |
1622 | 1607 | static void srp_remove_one(struct ib_device *device) |
include/rdma/ib_verbs.h
... | ... | @@ -88,7 +88,6 @@ |
88 | 88 | |
89 | 89 | struct ib_device_attr { |
90 | 90 | u64 fw_ver; |
91 | - __be64 node_guid; | |
92 | 91 | __be64 sys_image_guid; |
93 | 92 | u64 max_mr_size; |
94 | 93 | u64 page_size_cap; |
... | ... | @@ -951,6 +950,7 @@ |
951 | 950 | u64 uverbs_cmd_mask; |
952 | 951 | int uverbs_abi_ver; |
953 | 952 | |
953 | + __be64 node_guid; | |
954 | 954 | u8 node_type; |
955 | 955 | u8 phys_port_cnt; |
956 | 956 | }; |