ib_smc.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <stdint.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <errno.h>
00025 #include <unistd.h>
00026 #include <byteswap.h>
00027 #include <gpxe/infiniband.h>
00028 #include <gpxe/ib_smc.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static int ib_smc_get_port_info ( struct ib_device *ibdev,
00046 ib_local_mad_t local_mad,
00047 union ib_mad *mad ) {
00048 int rc;
00049
00050
00051 memset ( mad, 0, sizeof ( *mad ) );
00052 mad->hdr.base_version = IB_MGMT_BASE_VERSION;
00053 mad->hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
00054 mad->hdr.class_version = 1;
00055 mad->hdr.method = IB_MGMT_METHOD_GET;
00056 mad->hdr.attr_id = htons ( IB_SMP_ATTR_PORT_INFO );
00057 mad->hdr.attr_mod = htonl ( ibdev->port );
00058
00059 if ( ( rc = local_mad ( ibdev, mad ) ) != 0 ) {
00060 DBGC ( ibdev, "IBDEV %p could not get port info: %s\n",
00061 ibdev, strerror ( rc ) );
00062 return rc;
00063 }
00064 return 0;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 static int ib_smc_get_guid_info ( struct ib_device *ibdev,
00076 ib_local_mad_t local_mad,
00077 union ib_mad *mad ) {
00078 int rc;
00079
00080
00081 memset ( mad, 0, sizeof ( *mad ) );
00082 mad->hdr.base_version = IB_MGMT_BASE_VERSION;
00083 mad->hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
00084 mad->hdr.class_version = 1;
00085 mad->hdr.method = IB_MGMT_METHOD_GET;
00086 mad->hdr.attr_id = htons ( IB_SMP_ATTR_GUID_INFO );
00087
00088 if ( ( rc = local_mad ( ibdev, mad ) ) != 0 ) {
00089 DBGC ( ibdev, "IBDEV %p could not get GUID info: %s\n",
00090 ibdev, strerror ( rc ) );
00091 return rc;
00092 }
00093 return 0;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 static int ib_smc_get_pkey_table ( struct ib_device *ibdev,
00105 ib_local_mad_t local_mad,
00106 union ib_mad *mad ) {
00107 int rc;
00108
00109
00110 memset ( mad, 0, sizeof ( *mad ) );
00111 mad->hdr.base_version = IB_MGMT_BASE_VERSION;
00112 mad->hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
00113 mad->hdr.class_version = 1;
00114 mad->hdr.method = IB_MGMT_METHOD_GET;
00115 mad->hdr.attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE );
00116
00117 if ( ( rc = local_mad ( ibdev, mad ) ) != 0 ) {
00118 DBGC ( ibdev, "IBDEV %p could not get pkey table: %s\n",
00119 ibdev, strerror ( rc ) );
00120 return rc;
00121 }
00122 return 0;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 int ib_smc_update ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
00133 union ib_mad mad;
00134 struct ib_port_info *port_info = &mad.smp.smp_data.port_info;
00135 struct ib_guid_info *guid_info = &mad.smp.smp_data.guid_info;
00136 struct ib_pkey_table *pkey_table = &mad.smp.smp_data.pkey_table;
00137 int rc;
00138
00139
00140
00141
00142 if ( ( rc = ib_smc_get_port_info ( ibdev, local_mad, &mad ) ) != 0 )
00143 return rc;
00144 memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
00145 sizeof ( ibdev->gid.u.half[0] ) );
00146 ibdev->lid = ntohs ( port_info->lid );
00147 ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
00148 ibdev->link_width_enabled = port_info->link_width_enabled;
00149 ibdev->link_width_supported = port_info->link_width_supported;
00150 ibdev->link_width_active = port_info->link_width_active;
00151 ibdev->link_speed_supported =
00152 ( port_info->link_speed_supported__port_state >> 4 );
00153 ibdev->port_state =
00154 ( port_info->link_speed_supported__port_state & 0xf );
00155 ibdev->link_speed_active =
00156 ( port_info->link_speed_active__link_speed_enabled >> 4 );
00157 ibdev->link_speed_enabled =
00158 ( port_info->link_speed_active__link_speed_enabled & 0xf );
00159 ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
00160
00161
00162 if ( ( rc = ib_smc_get_guid_info ( ibdev, local_mad, &mad ) ) != 0 )
00163 return rc;
00164 memcpy ( &ibdev->gid.u.half[1], guid_info->guid[0],
00165 sizeof ( ibdev->gid.u.half[1] ) );
00166
00167
00168 if ( ( rc = ib_smc_get_pkey_table ( ibdev, local_mad, &mad ) ) != 0 )
00169 return rc;
00170 ibdev->pkey = ntohs ( pkey_table->pkey[0] );
00171
00172 DBGC ( ibdev, "IBDEV %p port GID is %08x:%08x:%08x:%08x\n", ibdev,
00173 htonl ( ibdev->gid.u.dwords[0] ),
00174 htonl ( ibdev->gid.u.dwords[1] ),
00175 htonl ( ibdev->gid.u.dwords[2] ),
00176 htonl ( ibdev->gid.u.dwords[3] ) );
00177
00178 return 0;
00179 }