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>

authored by

Sean Hefty and committed by
Roland Dreier
cf311cd4 87635b71

+54 -64
+5 -24
drivers/infiniband/core/cm.c
··· 3163 } 3164 EXPORT_SYMBOL(ib_cm_init_qp_attr); 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 static void cm_add_one(struct ib_device *device) 3183 { 3184 struct cm_device *cm_dev; ··· 3184 return; 3185 3186 cm_dev->device = device; 3187 - cm_dev->ca_guid = cm_get_ca_guid(device); 3188 - if (!cm_dev->ca_guid) 3189 - goto error1; 3190 3191 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); 3192 for (i = 1; i <= device->phys_port_cnt; i++) { ··· 3199 cm_recv_handler, 3200 port); 3201 if (IS_ERR(port->mad_agent)) 3202 - goto error2; 3203 3204 ret = ib_modify_port(device, i, 0, &port_modify); 3205 if (ret) 3206 - goto error3; 3207 } 3208 ib_set_client_data(device, &cm_client, cm_dev); 3209 ··· 3212 write_unlock_irqrestore(&cm.device_lock, flags); 3213 return; 3214 3215 - error3: 3216 - ib_unregister_mad_agent(port->mad_agent); 3217 error2: 3218 port_modify.set_port_cap_mask = 0; 3219 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; 3220 while (--i) { ··· 3222 ib_modify_port(device, port->port_num, 0, &port_modify); 3223 ib_unregister_mad_agent(port->mad_agent); 3224 } 3225 - error1: 3226 kfree(cm_dev); 3227 } 3228
··· 3163 } 3164 EXPORT_SYMBOL(ib_cm_init_qp_attr); 3165 3166 static void cm_add_one(struct ib_device *device) 3167 { 3168 struct cm_device *cm_dev; ··· 3200 return; 3201 3202 cm_dev->device = device; 3203 + cm_dev->ca_guid = device->node_guid; 3204 3205 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); 3206 for (i = 1; i <= device->phys_port_cnt; i++) { ··· 3217 cm_recv_handler, 3218 port); 3219 if (IS_ERR(port->mad_agent)) 3220 + goto error1; 3221 3222 ret = ib_modify_port(device, i, 0, &port_modify); 3223 if (ret) 3224 + goto error2; 3225 } 3226 ib_set_client_data(device, &cm_client, cm_dev); 3227 ··· 3230 write_unlock_irqrestore(&cm.device_lock, flags); 3231 return; 3232 3233 error2: 3234 + ib_unregister_mad_agent(port->mad_agent); 3235 + error1: 3236 port_modify.set_port_cap_mask = 0; 3237 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; 3238 while (--i) { ··· 3240 ib_modify_port(device, port->port_num, 0, &port_modify); 3241 ib_unregister_mad_agent(port->mad_agent); 3242 } 3243 kfree(cm_dev); 3244 } 3245
+5 -17
drivers/infiniband/core/sysfs.c
··· 445 return -ENOMEM; 446 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. 455 */ 456 457 envp[i] = NULL; ··· 617 static ssize_t show_node_guid(struct class_device *cdev, char *buf) 618 { 619 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 620 - struct ib_device_attr attr; 621 - ssize_t ret; 622 623 if (!ibdev_is_alive(dev)) 624 return -ENODEV; 625 626 - ret = ib_query_device(dev, &attr); 627 - if (ret) 628 - return ret; 629 - 630 return sprintf(buf, "%04x:%04x:%04x:%04x\n", 631 - be16_to_cpu(((__be16 *) &attr.node_guid)[0]), 632 - be16_to_cpu(((__be16 *) &attr.node_guid)[1]), 633 - be16_to_cpu(((__be16 *) &attr.node_guid)[2]), 634 - be16_to_cpu(((__be16 *) &attr.node_guid)[3])); 635 } 636 637 static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
··· 445 return -ENOMEM; 446 447 /* 448 + * It would be nice to pass the node GUID with the event... 449 */ 450 451 envp[i] = NULL; ··· 623 static ssize_t show_node_guid(struct class_device *cdev, char *buf) 624 { 625 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 626 627 if (!ibdev_is_alive(dev)) 628 return -ENODEV; 629 630 return sprintf(buf, "%04x:%04x:%04x:%04x\n", 631 + be16_to_cpu(((__be16 *) &dev->node_guid)[0]), 632 + be16_to_cpu(((__be16 *) &dev->node_guid)[1]), 633 + be16_to_cpu(((__be16 *) &dev->node_guid)[2]), 634 + be16_to_cpu(((__be16 *) &dev->node_guid)[3])); 635 } 636 637 static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
+1 -1
drivers/infiniband/core/uverbs_cmd.c
··· 157 memset(&resp, 0, sizeof resp); 158 159 resp.fw_ver = attr.fw_ver; 160 - resp.node_guid = attr.node_guid; 161 resp.sys_image_guid = attr.sys_image_guid; 162 resp.max_mr_size = attr.max_mr_size; 163 resp.page_size_cap = attr.page_size_cap;
··· 157 memset(&resp, 0, sizeof resp); 158 159 resp.fw_ver = attr.fw_ver; 160 + resp.node_guid = file->device->ib_dev->node_guid; 161 resp.sys_image_guid = attr.sys_image_guid; 162 resp.max_mr_size = attr.max_mr_size; 163 resp.page_size_cap = attr.page_size_cap;
+38 -2
drivers/infiniband/hw/mthca/mthca_provider.c
··· 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34 * SOFTWARE. 35 * 36 - * $Id: mthca_provider.c 1397 2004-12-28 05:09:00Z roland $ 37 */ 38 39 #include <rdma/ib_smi.h> ··· 91 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); 92 props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); 93 memcpy(&props->sys_image_guid, out_mad->data + 4, 8); 94 - memcpy(&props->node_guid, out_mad->data + 12, 8); 95 96 props->max_mr_size = ~0ull; 97 props->page_size_cap = mdev->limits.page_size_cap; ··· 1053 &class_device_attr_board_id 1054 }; 1055 1056 int mthca_register_device(struct mthca_dev *dev) 1057 { 1058 int ret; 1059 int i; 1060 1061 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 1062 dev->ib_dev.owner = THIS_MODULE;
··· 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34 * SOFTWARE. 35 * 36 + * $Id: mthca_provider.c 4859 2006-01-09 21:55:10Z roland $ 37 */ 38 39 #include <rdma/ib_smi.h> ··· 91 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); 92 props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); 93 memcpy(&props->sys_image_guid, out_mad->data + 4, 8); 94 95 props->max_mr_size = ~0ull; 96 props->page_size_cap = mdev->limits.page_size_cap; ··· 1054 &class_device_attr_board_id 1055 }; 1056 1057 + static int mthca_init_node_data(struct mthca_dev *dev) 1058 + { 1059 + struct ib_smp *in_mad = NULL; 1060 + struct ib_smp *out_mad = NULL; 1061 + int err = -ENOMEM; 1062 + u8 status; 1063 + 1064 + in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); 1065 + out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); 1066 + if (!in_mad || !out_mad) 1067 + goto out; 1068 + 1069 + init_query_mad(in_mad); 1070 + in_mad->attr_id = IB_SMP_ATTR_NODE_INFO; 1071 + 1072 + err = mthca_MAD_IFC(dev, 1, 1, 1073 + 1, NULL, NULL, in_mad, out_mad, 1074 + &status); 1075 + if (err) 1076 + goto out; 1077 + if (status) { 1078 + err = -EINVAL; 1079 + goto out; 1080 + } 1081 + 1082 + memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8); 1083 + 1084 + out: 1085 + kfree(in_mad); 1086 + kfree(out_mad); 1087 + return err; 1088 + } 1089 + 1090 int mthca_register_device(struct mthca_dev *dev) 1091 { 1092 int ret; 1093 int i; 1094 + 1095 + ret = mthca_init_node_data(dev); 1096 + if (ret) 1097 + return ret; 1098 1099 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 1100 dev->ib_dev.owner = THIS_MODULE;
+4 -19
drivers/infiniband/ulp/srp/ib_srp.c
··· 1516 1517 static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 1518 1519 - static struct srp_host *srp_add_port(struct ib_device *device, 1520 - __be64 node_guid, u8 port) 1521 { 1522 struct srp_host *host; 1523 ··· 1531 host->port = port; 1532 1533 host->initiator_port_id[7] = port; 1534 - memcpy(host->initiator_port_id + 8, &node_guid, 8); 1535 1536 host->pd = ib_alloc_pd(device); 1537 if (IS_ERR(host->pd)) ··· 1579 { 1580 struct list_head *dev_list; 1581 struct srp_host *host; 1582 - struct ib_device_attr *dev_attr; 1583 int s, e, p; 1584 - 1585 - dev_attr = kmalloc(sizeof *dev_attr, GFP_KERNEL); 1586 - if (!dev_attr) 1587 - return; 1588 - 1589 - if (ib_query_device(device, dev_attr)) { 1590 - printk(KERN_WARNING PFX "Couldn't query node GUID for %s.\n", 1591 - device->name); 1592 - goto out; 1593 - } 1594 1595 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); 1596 if (!dev_list) 1597 - goto out; 1598 1599 INIT_LIST_HEAD(dev_list); 1600 ··· 1596 } 1597 1598 for (p = s; p <= e; ++p) { 1599 - host = srp_add_port(device, dev_attr->node_guid, p); 1600 if (host) 1601 list_add_tail(&host->list, dev_list); 1602 } 1603 1604 ib_set_client_data(device, &srp_client, dev_list); 1605 - 1606 - out: 1607 - kfree(dev_attr); 1608 } 1609 1610 static void srp_remove_one(struct ib_device *device)
··· 1516 1517 static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 1518 1519 + static struct srp_host *srp_add_port(struct ib_device *device, u8 port) 1520 { 1521 struct srp_host *host; 1522 ··· 1532 host->port = port; 1533 1534 host->initiator_port_id[7] = port; 1535 + memcpy(host->initiator_port_id + 8, &device->node_guid, 8); 1536 1537 host->pd = ib_alloc_pd(device); 1538 if (IS_ERR(host->pd)) ··· 1580 { 1581 struct list_head *dev_list; 1582 struct srp_host *host; 1583 int s, e, p; 1584 1585 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); 1586 if (!dev_list) 1587 + return; 1588 1589 INIT_LIST_HEAD(dev_list); 1590 ··· 1608 } 1609 1610 for (p = s; p <= e; ++p) { 1611 + host = srp_add_port(device, p); 1612 if (host) 1613 list_add_tail(&host->list, dev_list); 1614 } 1615 1616 ib_set_client_data(device, &srp_client, dev_list); 1617 } 1618 1619 static void srp_remove_one(struct ib_device *device)
+1 -1
include/rdma/ib_verbs.h
··· 88 89 struct ib_device_attr { 90 u64 fw_ver; 91 - __be64 node_guid; 92 __be64 sys_image_guid; 93 u64 max_mr_size; 94 u64 page_size_cap; ··· 950 u64 uverbs_cmd_mask; 951 int uverbs_abi_ver; 952 953 u8 node_type; 954 u8 phys_port_cnt; 955 };
··· 88 89 struct ib_device_attr { 90 u64 fw_ver; 91 __be64 sys_image_guid; 92 u64 max_mr_size; 93 u64 page_size_cap; ··· 951 u64 uverbs_cmd_mask; 952 int uverbs_abi_ver; 953 954 + __be64 node_guid; 955 u8 node_type; 956 u8 phys_port_cnt; 957 };