iPXE
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., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdint.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <errno.h>
00030 #include <unistd.h>
00031 #include <byteswap.h>
00032 #include <ipxe/infiniband.h>
00033 #include <ipxe/ib_smc.h>
00034 
00035 /**
00036  * @file
00037  *
00038  * Infiniband Subnet Management Client
00039  *
00040  */
00041 
00042 /**
00043  * Issue local MAD
00044  *
00045  * @v ibdev             Infiniband device
00046  * @v attr_id           Attribute ID, in network byte order
00047  * @v attr_mod          Attribute modifier, in network byte order
00048  * @v local_mad         Method for issuing local MADs
00049  * @v mad               Management datagram to fill in
00050  * @ret rc              Return status code
00051  */
00052 static int ib_smc_mad ( struct ib_device *ibdev, uint16_t attr_id,
00053                         uint32_t attr_mod, ib_local_mad_t local_mad,
00054                         union ib_mad *mad ) {
00055         int rc;
00056 
00057         /* Construct MAD */
00058         memset ( mad, 0, sizeof ( *mad ) );
00059         mad->hdr.base_version = IB_MGMT_BASE_VERSION;
00060         mad->hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
00061         mad->hdr.class_version = 1;
00062         mad->hdr.method = IB_MGMT_METHOD_GET;
00063         mad->hdr.attr_id = attr_id;
00064         mad->hdr.attr_mod = attr_mod;
00065 
00066         /* Issue MAD */
00067         if ( ( rc = local_mad ( ibdev, mad ) ) != 0 )
00068                 return rc;
00069 
00070         return 0;
00071 }
00072 
00073 /**
00074  * Get node information
00075  *
00076  * @v ibdev             Infiniband device
00077  * @v local_mad         Method for issuing local MADs
00078  * @v mad               Management datagram to fill in
00079  * @ret rc              Return status code
00080  */
00081 static int ib_smc_get_node_info ( struct ib_device *ibdev,
00082                                   ib_local_mad_t local_mad,
00083                                   union ib_mad *mad ) {
00084         int rc;
00085 
00086         /* Issue MAD */
00087         if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_NODE_INFO ), 0,
00088                                  local_mad, mad ) ) != 0 ) {
00089                 DBGC ( ibdev, "IBDEV %s could not get node info: %s\n",
00090                        ibdev->name, strerror ( rc ) );
00091                 return rc;
00092         }
00093         return 0;
00094 }
00095 
00096 /**
00097  * Get port information
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_port_info ( struct ib_device *ibdev,
00105                                   ib_local_mad_t local_mad,
00106                                   union ib_mad *mad ) {
00107         int rc;
00108 
00109         /* Issue MAD */
00110         if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PORT_INFO ),
00111                                  htonl ( ibdev->port ), local_mad, mad )) !=0){
00112                 DBGC ( ibdev, "IBDEV %s could not get port info: %s\n",
00113                        ibdev->name, strerror ( rc ) );
00114                 return rc;
00115         }
00116         return 0;
00117 }
00118 
00119 /**
00120  * Get GUID information
00121  *
00122  * @v ibdev             Infiniband device
00123  * @v local_mad         Method for issuing local MADs
00124  * @v mad               Management datagram to fill in
00125  * @ret rc              Return status code
00126  */
00127 static int ib_smc_get_guid_info ( struct ib_device *ibdev,
00128                                   ib_local_mad_t local_mad,
00129                                   union ib_mad *mad ) {
00130         int rc;
00131 
00132         /* Issue MAD */
00133         if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_GUID_INFO ), 0,
00134                                  local_mad, mad ) ) != 0 ) {
00135                 DBGC ( ibdev, "IBDEV %s could not get GUID info: %s\n",
00136                        ibdev->name, strerror ( rc ) );
00137                 return rc;
00138         }
00139         return 0;
00140 }
00141 
00142 /**
00143  * Get partition key table
00144  *
00145  * @v ibdev             Infiniband device
00146  * @v local_mad         Method for issuing local MADs
00147  * @v mad               Management datagram to fill in
00148  * @ret rc              Return status code
00149  */
00150 static int ib_smc_get_pkey_table ( struct ib_device *ibdev,
00151                                    ib_local_mad_t local_mad,
00152                                    union ib_mad *mad ) {
00153         int rc;
00154 
00155         /* Issue MAD */
00156         if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PKEY_TABLE ), 0,
00157                                  local_mad, mad ) ) != 0 ) {
00158                 DBGC ( ibdev, "IBDEV %s could not get pkey table: %s\n",
00159                        ibdev->name, strerror ( rc ) );
00160                 return rc;
00161         }
00162         return 0;
00163 }
00164 
00165 /**
00166  * Get Infiniband parameters using SMC
00167  *
00168  * @v ibdev             Infiniband device
00169  * @v local_mad         Method for issuing local MADs
00170  * @ret rc              Return status code
00171  */
00172 static int ib_smc_get ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
00173         union ib_mad mad;
00174         struct ib_node_info *node_info = &mad.smp.smp_data.node_info;
00175         struct ib_port_info *port_info = &mad.smp.smp_data.port_info;
00176         struct ib_guid_info *guid_info = &mad.smp.smp_data.guid_info;
00177         struct ib_pkey_table *pkey_table = &mad.smp.smp_data.pkey_table;
00178         int rc;
00179 
00180         /* Node info gives us the node GUID */
00181         if ( ( rc = ib_smc_get_node_info ( ibdev, local_mad, &mad ) ) != 0 )
00182                 return rc;
00183         memcpy ( &ibdev->node_guid, &node_info->node_guid,
00184                  sizeof ( ibdev->node_guid ) );
00185 
00186         /* Port info gives us the link state, the first half of the
00187          * port GID and the SM LID.
00188          */
00189         if ( ( rc = ib_smc_get_port_info ( ibdev, local_mad, &mad ) ) != 0 )
00190                 return rc;
00191         memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
00192                  sizeof ( ibdev->gid.s.prefix ) );
00193         ibdev->lid = ntohs ( port_info->lid );
00194         ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
00195         ibdev->link_width_enabled = port_info->link_width_enabled;
00196         ibdev->link_width_supported = port_info->link_width_supported;
00197         ibdev->link_width_active = port_info->link_width_active;
00198         ibdev->link_speed_supported =
00199                 ( port_info->link_speed_supported__port_state >> 4 );
00200         ibdev->port_state =
00201                 ( port_info->link_speed_supported__port_state & 0xf );
00202         ibdev->link_speed_active =
00203                 ( port_info->link_speed_active__link_speed_enabled >> 4 );
00204         ibdev->link_speed_enabled =
00205                 ( port_info->link_speed_active__link_speed_enabled & 0xf );
00206         ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
00207 
00208         /* GUID info gives us the second half of the port GID */
00209         if ( ( rc = ib_smc_get_guid_info ( ibdev, local_mad, &mad ) ) != 0 )
00210                 return rc;
00211         memcpy ( &ibdev->gid.s.guid, guid_info->guid[0],
00212                  sizeof ( ibdev->gid.s.guid ) );
00213 
00214         /* Get partition key */
00215         if ( ( rc = ib_smc_get_pkey_table ( ibdev, local_mad, &mad ) ) != 0 )
00216                 return rc;
00217         ibdev->pkey = ntohs ( pkey_table->pkey[0] );
00218 
00219         DBGC ( ibdev, "IBDEV %s port GID is " IB_GID_FMT "\n",
00220                ibdev->name, IB_GID_ARGS ( &ibdev->gid ) );
00221 
00222         return 0;
00223 }
00224 
00225 /**
00226  * Initialise Infiniband parameters using SMC
00227  *
00228  * @v ibdev             Infiniband device
00229  * @v local_mad         Method for issuing local MADs
00230  * @ret rc              Return status code
00231  */
00232 int ib_smc_init ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
00233         int rc;
00234 
00235         /* Get MAD parameters */
00236         if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
00237                 return rc;
00238 
00239         return 0;
00240 }
00241 
00242 /**
00243  * Update Infiniband parameters using SMC
00244  *
00245  * @v ibdev             Infiniband device
00246  * @v local_mad         Method for issuing local MADs
00247  * @ret rc              Return status code
00248  */
00249 int ib_smc_update ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
00250         int rc;
00251 
00252         /* Get MAD parameters */
00253         if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
00254                 return rc;
00255 
00256         /* Notify Infiniband core of potential link state change */
00257         ib_link_state_changed ( ibdev );
00258 
00259         return 0;
00260 }