ib_smc.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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  * @file
00032  *
00033  * Infiniband Subnet Management Client
00034  *
00035  */
00036 
00037 /**
00038  * Get port information
00039  *
00040  * @v ibdev             Infiniband device
00041  * @v local_mad         Method for issuing local MADs
00042  * @v mad               Management datagram to fill in
00043  * @ret rc              Return status code
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         /* Construct MAD */
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  * Get GUID information
00069  *
00070  * @v ibdev             Infiniband device
00071  * @v local_mad         Method for issuing local MADs
00072  * @v mad               Management datagram to fill in
00073  * @ret rc              Return status code
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         /* Construct MAD */
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  * Get partition key table
00098  *
00099  * @v ibdev             Infiniband device
00100  * @v local_mad         Method for issuing local MADs
00101  * @v mad               Management datagram to fill in
00102  * @ret rc              Return status code
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         /* Construct MAD */
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  * Get MAD parameters
00127  *
00128  * @v ibdev             Infiniband device
00129  * @v local_mad         Method for issuing local MADs
00130  * @ret rc              Return status code
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         /* Port info gives us the link state, the first half of the
00140          * port GID and the SM LID.
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         /* GUID info gives us the second half of the port GID */
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         /* Get partition key */
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 }

Generated on Tue Apr 6 20:01:10 2010 for gPXE by  doxygen 1.5.7.1