[infiniband] Provide ib_get_hca_info() as a commonly-available function
authorMichael Brown <mcb30@etherboot.org>
Thu, 2 Jul 2009 11:54:36 +0000 (12:54 +0100)
committerMichael Brown <mcb30@etherboot.org>
Fri, 17 Jul 2009 22:06:33 +0000 (23:06 +0100)
src/include/gpxe/ib_mad.h
src/include/gpxe/infiniband.h
src/net/infiniband.c
src/net/infiniband/ib_sma.c

index 4544123..7d49799 100644 (file)
@@ -75,9 +75,9 @@ struct ib_node_info {
        uint8_t class_version;
        uint8_t node_type;
        uint8_t num_ports;
-       uint8_t sys_guid[8];
-       uint8_t node_guid[8];
-       uint8_t port_guid[8];
+       struct ib_gid_half sys_guid;
+       struct ib_gid_half node_guid;
+       struct ib_gid_half port_guid;
        uint16_t partition_cap;
        uint16_t device_id;
        uint32_t revision;
index 7d54423..406933b 100644 (file)
@@ -374,6 +374,8 @@ extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
                             struct ib_gid *gid );
 extern void ib_mcast_detach ( struct ib_device *ibdev,
                              struct ib_queue_pair *qp, struct ib_gid *gid );
+extern int ib_get_hca_info ( struct ib_device *ibdev,
+                            struct ib_gid_half *hca_guid );
 extern struct ib_device * alloc_ibdev ( size_t priv_size );
 extern int register_ibdev ( struct ib_device *ibdev );
 extern void unregister_ibdev ( struct ib_device *ibdev );
index 1c584d8..1c19fad 100644 (file)
@@ -488,6 +488,32 @@ void ib_mcast_detach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
        }
 }
 
+/**
+ * Get Infiniband HCA information
+ *
+ * @v ibdev            Infiniband device
+ * @ret hca_guid       HCA GUID
+ * @ret num_ports      Number of ports
+ */
+int ib_get_hca_info ( struct ib_device *ibdev,
+                     struct ib_gid_half *hca_guid ) {
+       struct ib_device *tmp;
+       int num_ports = 0;
+
+       /* Search for IB devices with the same physical device to
+        * identify port count and a suitable Node GUID.
+        */
+       for_each_ibdev ( tmp ) {
+               if ( tmp->dev != ibdev->dev )
+                       continue;
+               if ( num_ports == 0 ) {
+                       memcpy ( hca_guid, &tmp->gid.u.half[1],
+                                sizeof ( *hca_guid ) );
+               }
+               num_ports++;
+       }
+       return num_ports;
+}
 
 /***************************************************************************
  *
index 96cc37c..cfc881c 100644 (file)
@@ -47,27 +47,15 @@ static void ib_sma_get_node_info ( struct ib_sma *sma,
                                   union ib_smp_data *get ) {
        struct ib_device *ibdev = sma->ibdev;
        struct ib_node_info *node_info = &get->node_info;
-       struct ib_device *tmp;
 
        memset ( node_info, 0, sizeof ( *node_info ) );
        node_info->base_version = IB_MGMT_BASE_VERSION;
        node_info->class_version = IB_SMP_CLASS_VERSION;
        node_info->node_type = IB_NODE_TYPE_HCA;
-       /* Search for IB devices with the same physical device to
-        * identify port count and a suitable Node GUID.
-        */
-       for_each_ibdev ( tmp ) {
-               if ( tmp->dev != ibdev->dev )
-                       continue;
-               if ( node_info->num_ports == 0 ) {
-                       memcpy ( node_info->sys_guid, &tmp->gid.u.half[1],
-                                sizeof ( node_info->sys_guid ) );
-                       memcpy ( node_info->node_guid, &tmp->gid.u.half[1],
-                                sizeof ( node_info->node_guid ) );
-               }
-               node_info->num_ports++;
-       }
-       memcpy ( node_info->port_guid, &ibdev->gid.u.half[1],
+       node_info->num_ports = ib_get_hca_info ( ibdev, &node_info->sys_guid );
+       memcpy ( &node_info->node_guid, &node_info->sys_guid,
+                sizeof ( node_info->node_guid ) );
+       memcpy ( &node_info->port_guid, &ibdev->gid.u.half[1],
                 sizeof ( node_info->port_guid ) );
        node_info->partition_cap = htons ( 1 );
        node_info->local_port_num = ibdev->port;