iPXE
Functions | Variables
ib_sma.c File Reference

Infiniband Subnet Management Agent. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <byteswap.h>
#include <ipxe/settings.h>
#include <ipxe/infiniband.h>
#include <ipxe/iobuf.h>
#include <ipxe/ib_mi.h>
#include <ipxe/ib_sma.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ib_sma_node_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Node information.
static void ib_sma_node_desc (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Node description.
static void ib_sma_guid_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 GUID information.
static int ib_sma_set_port_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
 Set port information.
static void ib_sma_port_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Port information.
static int ib_sma_set_pkey_table (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
 Set partition key table.
static void ib_sma_pkey_table (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Partition key table.
int ib_create_sma (struct ib_device *ibdev, struct ib_mad_interface *mi)
 Create subnet management agent and interface.
void ib_destroy_sma (struct ib_device *ibdev __unused, struct ib_mad_interface *mi __unused)
 Destroy subnet management agent and interface.

Variables

struct ib_mad_agent ib_sma_agent[] __ib_mad_agent
 Subnet management agent.

Detailed Description

Infiniband Subnet Management Agent.

Definition in file ib_sma.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void ib_sma_node_info ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad,
struct ib_address_vector av 
) [static]

Node information.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 54 of file ib_sma.c.

References ib_node_info::base_version, ib_node_info::class_version, DBGC, ib_device::gid, ib_gid::guid, ib_mad::hdr, htons, ib_count_ports(), IB_MGMT_BASE_VERSION, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), IB_NODE_TYPE_HCA, IB_SMP_CLASS_VERSION, ib_node_info::local_port_num, memcpy(), memset(), ib_mad_hdr::method, ib_node_info::node_guid, ib_device::node_guid, ib_smp_data::node_info, node_info, ib_node_info::node_type, ib_node_info::num_ports, ib_node_info::partition_cap, ib_device::port, ib_node_info::port_guid, rc, ib_gid::s, ib_mad::smp, ib_mad_smp::smp_data, strerror(), and ib_node_info::sys_guid.

                                                              {
        struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
        int rc;

        /* Fill in information */
        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;
        node_info->num_ports = ib_count_ports ( ibdev );
        memcpy ( &node_info->sys_guid, &ibdev->node_guid,
                 sizeof ( node_info->sys_guid ) );
        memcpy ( &node_info->node_guid, &ibdev->node_guid,
                 sizeof ( node_info->node_guid ) );
        memcpy ( &node_info->port_guid, &ibdev->gid.s.guid,
                 sizeof ( node_info->port_guid ) );
        node_info->partition_cap = htons ( 1 );
        node_info->local_port_num = ibdev->port;

        /* Send GetResponse */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not send NodeInfo GetResponse: %s\n",
                       mi, strerror ( rc ) );
                return;
        }
}
static void ib_sma_node_desc ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad,
struct ib_address_vector av 
) [static]

Node description.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 93 of file ib_sma.c.

References ib_guid::bytes, DBGC, ib_device::dev, fetch_string_setting(), guid, ib_mad::hdr, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), memset(), ib_mad_hdr::method, device::name, ib_smp_data::node_desc, node_desc, ib_device::node_guid, ib_node_desc::node_string, NULL, rc, ib_mad::smp, ib_mad_smp::smp_data, snprintf(), and strerror().

                                                              {
        struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
        union ib_guid *guid = &ibdev->node_guid;
        char hostname[ sizeof ( node_desc->node_string ) ];
        int hostname_len;
        int rc;

        /* Fill in information */
        memset ( node_desc, 0, sizeof ( *node_desc ) );
        hostname_len = fetch_string_setting ( NULL, &hostname_setting,
                                              hostname, sizeof ( hostname ) );
        snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
                   "iPXE %s%s%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
                   hostname, ( ( hostname_len >= 0 ) ? " " : "" ),
                   guid->bytes[0], guid->bytes[1], guid->bytes[2],
                   guid->bytes[3], guid->bytes[4], guid->bytes[5],
                   guid->bytes[6], guid->bytes[7], ibdev->dev->name );

        /* Send GetResponse */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not send NodeDesc GetResponse: %s\n",
                       mi, strerror ( rc ) );
                return;
        }
}
static void ib_sma_guid_info ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad,
struct ib_address_vector av 
) [static]

GUID information.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 131 of file ib_sma.c.

References DBGC, ib_device::gid, ib_gid::guid, ib_guid_info::guid, ib_smp_data::guid_info, guid_info, ib_mad::hdr, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), memcpy(), memset(), ib_mad_hdr::method, rc, ib_gid::s, ib_mad::smp, ib_mad_smp::smp_data, and strerror().

                                                              {
        struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
        int rc;

        /* Fill in information */
        memset ( guid_info, 0, sizeof ( *guid_info ) );
        memcpy ( guid_info->guid[0], &ibdev->gid.s.guid,
                 sizeof ( guid_info->guid[0] ) );

        /* Send GetResponse */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not send GuidInfo GetResponse: %s\n",
                       mi, strerror ( rc ) );
                return;
        }
}
static int ib_sma_set_port_info ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad 
) [static]

Set port information.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
Return values:
rcReturn status code

Definition at line 160 of file ib_sma.c.

References DBGC, ib_device::gid, ib_port_info::gid_prefix, ib_set_port_info(), ib_port_info::lid, ib_device::lid, ib_port_info::link_speed_active__link_speed_enabled, ib_device::link_speed_enabled, ib_port_info::link_width_enabled, link_width_enabled, ib_device::link_width_enabled, ib_port_info::mastersm_lid, memcpy(), ib_port_info::neighbour_mtu__mastersm_sl, ntohs, ib_smp_data::port_info, port_info, ib_gid::prefix, rc, ib_gid::s, ib_device::sm_lid, ib_device::sm_sl, ib_mad::smp, ib_mad_smp::smp_data, and strerror().

Referenced by ib_sma_port_info().

                                                      {
        const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
        unsigned int link_width_enabled;
        unsigned int link_speed_enabled;
        int rc;

        /* Set parameters */
        memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
                 sizeof ( ibdev->gid.s.prefix ) );
        ibdev->lid = ntohs ( port_info->lid );
        ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
        if ( ( link_width_enabled = port_info->link_width_enabled ) )
                ibdev->link_width_enabled = link_width_enabled;
        if ( ( link_speed_enabled =
               ( port_info->link_speed_active__link_speed_enabled & 0xf ) ) )
                ibdev->link_speed_enabled = link_speed_enabled;
        ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
        DBGC ( mi, "SMA %p set LID %d SMLID %d link width %d speed %d\n",
               mi, ibdev->lid, ibdev->sm_lid, ibdev->link_width_enabled,
               ibdev->link_speed_enabled );

        /* Update parameters on device */
        if ( ( rc = ib_set_port_info ( ibdev, mad ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not set port information: %s\n",
                       mi, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static void ib_sma_port_info ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad,
struct ib_address_vector av 
) [static]

Port information.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 201 of file ib_sma.c.

References DBGC, ib_device::gid, ib_port_info::gid_prefix, ib_port_info::guid_cap, ib_mad::hdr, htons, IB_MGMT_METHOD_GET_RESP, IB_MGMT_METHOD_SET, IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR, ib_mi_send(), IB_MTU_2048, IB_PORT_PHYS_STATE_POLLING, ib_sma_set_port_info(), IB_VL_0, ib_port_info::init_type_reply__mtu_cap, ib_port_info::lid, ib_device::lid, ib_device::link_speed_active, ib_port_info::link_speed_active__link_speed_enabled, ib_device::link_speed_enabled, ib_device::link_speed_supported, ib_port_info::link_speed_supported__port_state, ib_port_info::link_width_active, ib_device::link_width_active, ib_port_info::link_width_enabled, ib_device::link_width_enabled, ib_port_info::link_width_supported, ib_device::link_width_supported, ib_port_info::local_port_num, ib_port_info::mastersm_lid, memcpy(), memset(), ib_mad_hdr::method, ib_port_info::neighbour_mtu__mastersm_sl, ntohs, ib_port_info::operational_vls__enforcement, ib_device::port, ib_smp_data::port_info, port_info, ib_port_info::port_phys_state__link_down_def_state, ib_device::port_state, ib_gid::prefix, rc, ib_gid::s, ib_device::sm_lid, ib_device::sm_sl, ib_mad::smp, ib_mad_smp::smp_data, ib_mad_hdr::status, strerror(), and ib_port_info::vl_cap__init_type.

                                                              {
        struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
        int rc;

        /* Set parameters if applicable */
        if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
                if ( ( rc = ib_sma_set_port_info ( ibdev, mi, mad ) ) != 0 ) {
                        mad->hdr.status =
                              htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
                        /* Fall through to generate GetResponse */
                }
        }

        /* Fill in information */
        memset ( port_info, 0, sizeof ( *port_info ) );
        memcpy ( port_info->gid_prefix, &ibdev->gid.s.prefix,
                 sizeof ( port_info->gid_prefix ) );
        port_info->lid = ntohs ( ibdev->lid );
        port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
        port_info->local_port_num = ibdev->port;
        port_info->link_width_enabled = ibdev->link_width_enabled;
        port_info->link_width_supported = ibdev->link_width_supported;
        port_info->link_width_active = ibdev->link_width_active;
        port_info->link_speed_supported__port_state =
                ( ( ibdev->link_speed_supported << 4 ) | ibdev->port_state );
        port_info->port_phys_state__link_down_def_state =
                ( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
                  IB_PORT_PHYS_STATE_POLLING );
        port_info->link_speed_active__link_speed_enabled =
                ( ( ibdev->link_speed_active << 4 ) |
                  ibdev->link_speed_enabled );
        port_info->neighbour_mtu__mastersm_sl =
                ( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
        port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
        port_info->init_type_reply__mtu_cap = IB_MTU_2048;
        port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
        port_info->guid_cap = 1;

        /* Send GetResponse */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not send PortInfo GetResponse: %s\n",
                       mi, strerror ( rc ) );
                return;
        }
}
static int ib_sma_set_pkey_table ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad 
) [static]

Set partition key table.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
Return values:
rcReturn status code

Definition at line 259 of file ib_sma.c.

References DBGC, ib_set_pkey_table(), ntohs, ib_pkey_table::pkey, ib_device::pkey, ib_smp_data::pkey_table, pkey_table, rc, ib_mad::smp, ib_mad_smp::smp_data, and strerror().

Referenced by ib_sma_pkey_table().

                                                       {
        struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
        int rc;

        /* Set parameters */
        ibdev->pkey = ntohs ( pkey_table->pkey[0] );
        DBGC ( mi, "SMA %p set pkey %04x\n", mi, ibdev->pkey );

        /* Update parameters on device */
        if ( ( rc = ib_set_pkey_table ( ibdev, mad ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not set pkey table: %s\n",
                       mi, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static void ib_sma_pkey_table ( struct ib_device ibdev,
struct ib_mad_interface mi,
union ib_mad mad,
struct ib_address_vector av 
) [static]

Partition key table.

Parameters:
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 287 of file ib_sma.c.

References DBGC, ib_mad::hdr, htons, IB_MGMT_METHOD_GET_RESP, IB_MGMT_METHOD_SET, IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR, ib_mi_send(), ib_sma_set_pkey_table(), memset(), ib_mad_hdr::method, ib_pkey_table::pkey, ib_device::pkey, ib_smp_data::pkey_table, pkey_table, rc, ib_mad::smp, ib_mad_smp::smp_data, ib_mad_hdr::status, and strerror().

                                                               {
        struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
        int rc;

        /* Set parameters, if applicable */
        if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
                if ( ( rc = ib_sma_set_pkey_table ( ibdev, mi, mad ) ) != 0 ) {
                        mad->hdr.status =
                              htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
                        /* Fall through to generate GetResponse */
                }
        }

        /* Fill in information */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        memset ( pkey_table, 0, sizeof ( *pkey_table ) );
        pkey_table->pkey[0] = htons ( ibdev->pkey );

        /* Send GetResponse */
        mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
        if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
                DBGC ( mi, "SMA %p could not send PKeyTable GetResponse: %s\n",
                       mi, strerror ( rc ) );
                return;
        }
}
int ib_create_sma ( struct ib_device ibdev,
struct ib_mad_interface mi 
)

Create subnet management agent and interface.

Parameters:
ibdevInfiniband device
miManagement interface
Return values:
rcReturn status code

Definition at line 358 of file ib_sma.c.

References DBGC, and ib_device::name.

Referenced by ib_open().

                                                                           {

        /* Nothing to do */
        DBGC ( ibdev, "IBDEV %s SMA using SMI %p\n", ibdev->name, mi );

        return 0;
}
void ib_destroy_sma ( struct ib_device *ibdev  __unused,
struct ib_mad_interface *mi  __unused 
)

Destroy subnet management agent and interface.

Parameters:
ibdevInfiniband device
miManagement interface

Definition at line 372 of file ib_sma.c.

Referenced by ib_close(), and ib_open().

                                                             {
        /* Nothing to do */
}

Variable Documentation

struct ib_mad_agent ib_sma_agent [] __ib_mad_agent

Subnet management agent.

Definition at line 318 of file ib_sma.c.