iPXE
Data Structures | Defines | Functions | Variables
ib_pathrec.c File Reference

Infiniband path lookups. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/infiniband.h>
#include <ipxe/ib_mi.h>
#include <ipxe/ib_pathrec.h>

Go to the source code of this file.

Data Structures

struct  ib_cached_path
 A cached path. More...

Defines

#define IB_NUM_CACHED_PATHS   4
 Number of path cache entries.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ib_path_complete (struct ib_device *ibdev, struct ib_mad_interface *mi, struct ib_mad_transaction *madx, int rc, union ib_mad *mad, struct ib_address_vector *av __unused)
 Handle path transaction completion.
struct ib_pathib_create_path (struct ib_device *ibdev, struct ib_address_vector *av, struct ib_path_operations *op)
 Create path.
void ib_destroy_path (struct ib_device *ibdev, struct ib_path *path)
 Destroy path.
static struct ib_cached_pathib_find_path_cache_entry (struct ib_device *ibdev, union ib_gid *dgid)
 Find path cache entry.
static void ib_cached_path_complete (struct ib_device *ibdev, struct ib_path *path, int rc, struct ib_address_vector *av __unused)
 Handle cached path transaction completion.
int ib_resolve_path (struct ib_device *ibdev, struct ib_address_vector *av)
 Resolve path.

Variables

static struct
ib_mad_transaction_operations 
ib_path_op
 Path transaction completion operations.
static struct ib_cached_path ib_path_cache [IB_NUM_CACHED_PATHS]
 Path cache.
static unsigned int ib_path_cache_idx
 Oldest path cache entry index.
static struct ib_path_operations ib_cached_path_op
 Cached path transaction completion operations.

Detailed Description

Infiniband path lookups.

Definition in file ib_pathrec.c.


Define Documentation

#define IB_NUM_CACHED_PATHS   4

Number of path cache entries.

Must be a power of two.

Definition at line 167 of file ib_pathrec.c.

Referenced by ib_find_path_cache_entry(), and ib_resolve_path().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void ib_path_complete ( struct ib_device ibdev,
struct ib_mad_interface mi,
struct ib_mad_transaction madx,
int  rc,
union ib_mad mad,
struct ib_address_vector *av  __unused 
) [static]

Handle path transaction completion.

Parameters:
ibdevInfiniband device
miManagement interface
madxManagement transaction
rcStatus code
madReceived MAD (or NULL on error)
avSource address vector (or NULL on error)

Definition at line 51 of file ib_pathrec.c.

References ib_path::av, ib_path_operations::complete, DBGC, dgid, ib_path_record::dlid, ENETUNREACH, ib_address_vector::gid, ib_device::gid, ib_address_vector::gid_present, ib_mad::hdr, htons, ib_destroy_madx(), IB_GID_ARGS, IB_GID_FMT, ib_madx_get_ownerdata(), IB_MGMT_STATUS_OK, ib_address_vector::lid, ib_path::madx, memcmp(), ib_device::name, ntohs, NULL, ib_path::op, out, ib_sa_data::path_record, ib_gid::prefix, ib_address_vector::rate, ib_path_record::rate_selector__rate, ib_path_record::reserved__sl, ib_gid::s, ib_mad::sa, ib_mad_sa::sa_data, ib_address_vector::sl, ib_mad_hdr::status, and strerror().

                                                                       {
        struct ib_path *path = ib_madx_get_ownerdata ( madx );
        union ib_gid *dgid = &path->av.gid;
        struct ib_path_record *pathrec = &mad->sa.sa_data.path_record;

        /* Report failures */
        if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ))
                rc = -ENETUNREACH;
        if ( rc != 0 ) {
                DBGC ( ibdev, "IBDEV %s path lookup for " IB_GID_FMT
                       " failed: %s\n",
                       ibdev->name, IB_GID_ARGS ( dgid ), strerror ( rc ) );
                goto out;
        }

        /* Extract values from MAD */
        path->av.lid = ntohs ( pathrec->dlid );
        path->av.sl = ( pathrec->reserved__sl & 0x0f );
        path->av.rate = ( pathrec->rate_selector__rate & 0x3f );
        DBGC ( ibdev, "IBDEV %s path to " IB_GID_FMT " lid %d sl %d rate "
               "%d\n", ibdev->name, IB_GID_ARGS ( dgid ), path->av.lid,
               path->av.sl, path->av.rate );

        /* Use only the LID if no GRH is needed for this path */
        if ( memcmp ( &path->av.gid.s.prefix, &ibdev->gid.s.prefix,
                      sizeof ( path->av.gid.s.prefix ) ) == 0 ) {
                path->av.gid_present = 0;
        }

 out:
        /* Destroy the completed transaction */
        ib_destroy_madx ( ibdev, mi, madx );
        path->madx = NULL;

        /* Hand off to upper completion handler */
        path->op->complete ( ibdev, path, rc, &path->av );
}
struct ib_path* ib_create_path ( struct ib_device ibdev,
struct ib_address_vector av,
struct ib_path_operations op 
) [read]

Create path.

Parameters:
ibdevInfiniband device
avAddress vector to complete
opPath operations
Return values:
pathPath

Definition at line 107 of file ib_pathrec.c.

References ib_mad_hdr::attr_id, ib_path::av, ib_mad_hdr::class_version, ib_sa_hdr::comp_mask, ib_path_record::dgid, free, ib_address_vector::gid, ib_device::gid, ib_device::gsi, htonl, htons, ib_create_madx(), ib_destroy_madx(), ib_madx_set_ownerdata(), IB_MGMT_CLASS_SUBN_ADM, IB_MGMT_METHOD_GET, IB_SA_ATTR_PATH_REC, IB_SA_CLASS_VERSION, IB_SA_PATH_REC_DGID, IB_SA_PATH_REC_SGID, ib_path::ibdev, ib_mad_sa::mad_hdr, ib_path::madx, memcpy(), memset(), ib_mad_hdr::method, ib_mad_hdr::mgmt_class, NULL, ib_path::op, op, ib_sa_data::path_record, sa, ib_mad::sa, ib_mad_sa::sa_data, ib_mad_sa::sa_hdr, ib_path_record::sgid, and zalloc().

Referenced by ib_create_conn(), and ib_resolve_path().

                                                 {
        struct ib_path *path;
        union ib_mad mad;
        struct ib_mad_sa *sa = &mad.sa;

        /* Allocate and initialise structure */
        path = zalloc ( sizeof ( *path ) );
        if ( ! path )
                goto err_alloc_path;
        path->ibdev = ibdev;
        memcpy ( &path->av, av, sizeof ( path->av ) );
        path->op = op;

        /* Construct path request */
        memset ( sa, 0, sizeof ( *sa ) );
        sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
        sa->mad_hdr.class_version = IB_SA_CLASS_VERSION;
        sa->mad_hdr.method = IB_MGMT_METHOD_GET;
        sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_PATH_REC );
        sa->sa_hdr.comp_mask[1] =
                htonl ( IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID );
        memcpy ( &sa->sa_data.path_record.dgid, &path->av.gid,
                 sizeof ( sa->sa_data.path_record.dgid ) );
        memcpy ( &sa->sa_data.path_record.sgid, &ibdev->gid,
                 sizeof ( sa->sa_data.path_record.sgid ) );

        /* Create management transaction */
        path->madx = ib_create_madx ( ibdev, ibdev->gsi, &mad, NULL,
                                      &ib_path_op );
        if ( ! path->madx )
                goto err_create_madx;
        ib_madx_set_ownerdata ( path->madx, path );

        return path;

        ib_destroy_madx ( ibdev, ibdev->gsi, path->madx );
 err_create_madx:
        free ( path );
 err_alloc_path:
        return NULL;
}
void ib_destroy_path ( struct ib_device ibdev,
struct ib_path path 
)

Destroy path.

Parameters:
ibdevInfiniband device
pathPath

Definition at line 156 of file ib_pathrec.c.

References free, ib_device::gsi, ib_destroy_madx(), and ib_path::madx.

Referenced by ib_cached_path_complete(), ib_cm_path_complete(), ib_create_conn(), ib_destroy_conn(), and ib_resolve_path().

                                                                       {

        if ( path->madx )
                ib_destroy_madx ( ibdev, ibdev->gsi, path->madx );
        free ( path );
}
static struct ib_cached_path* ib_find_path_cache_entry ( struct ib_device ibdev,
union ib_gid dgid 
) [static, read]

Find path cache entry.

Parameters:
ibdevInfiniband device
dgidDestination GID
Return values:
pathPath cache entry, or NULL

Definition at line 189 of file ib_pathrec.c.

References ib_path::av, ib_address_vector::gid, IB_NUM_CACHED_PATHS, ib_path_cache, ib_path::ibdev, memcmp(), NULL, and ib_cached_path::path.

Referenced by ib_resolve_path().

                                                                         {
        struct ib_cached_path *cached;
        unsigned int i;

        for ( i = 0 ; i < IB_NUM_CACHED_PATHS ; i++ ) {
                cached = &ib_path_cache[i];
                if ( ! cached->path )
                        continue;
                if ( cached->path->ibdev != ibdev )
                        continue;
                if ( memcmp ( &cached->path->av.gid, dgid,
                              sizeof ( cached->path->av.gid ) ) != 0 )
                        continue;
                return cached;
        }

        return NULL;
}
static void ib_cached_path_complete ( struct ib_device ibdev,
struct ib_path path,
int  rc,
struct ib_address_vector *av  __unused 
) [static]

Handle cached path transaction completion.

Parameters:
ibdevInfiniband device
pathPath
rcStatus code
avAddress vector, or NULL on error

Definition at line 216 of file ib_pathrec.c.

References ib_destroy_path(), ib_path_get_ownerdata(), and memset().

                                                                              {
        struct ib_cached_path *cached = ib_path_get_ownerdata ( path );

        /* If the transaction failed, erase the cache entry */
        if ( rc != 0 ) {
                /* Destroy the old cache entry */
                ib_destroy_path ( ibdev, path );
                memset ( cached, 0, sizeof ( *cached ) );
                return;
        }

        /* Do not destroy the completed transaction; we still need to
         * refer to the resolved path.
         */
}
int ib_resolve_path ( struct ib_device ibdev,
struct ib_address_vector av 
)

Resolve path.

Parameters:
ibdevInfiniband device
avAddress vector to complete
Return values:
rcReturn status code

This provides a non-transactional way to resolve a path, via a cache similar to ARP.

Definition at line 249 of file ib_pathrec.c.

References ib_path::av, DBGC, DBGC2, ENOENT, ENOMEM, ib_address_vector::gid, gid, ib_address_vector::gid_present, ib_create_path(), ib_destroy_path(), ib_find_path_cache_entry(), IB_GID_ARGS, IB_GID_FMT, IB_NUM_CACHED_PATHS, ib_path_cache, ib_path_cache_idx, ib_path_set_ownerdata(), ib_address_vector::lid, memset(), ib_device::name, ib_cached_path::path, ib_address_vector::rate, and ib_address_vector::sl.

Referenced by eoib_duplicate(), eoib_tx_av(), and ipoib_transmit().

                                                                              {
        union ib_gid *gid = &av->gid;
        struct ib_cached_path *cached;
        unsigned int cache_idx;

        /* Look in cache for a matching entry */
        cached = ib_find_path_cache_entry ( ibdev, gid );
        if ( cached && cached->path->av.lid ) {
                /* Populated entry found */
                av->lid = cached->path->av.lid;
                av->rate = cached->path->av.rate;
                av->sl = cached->path->av.sl;
                av->gid_present = cached->path->av.gid_present;
                DBGC2 ( ibdev, "IBDEV %s cache hit for " IB_GID_FMT "\n",
                        ibdev->name, IB_GID_ARGS ( gid ) );
                return 0;
        }
        DBGC ( ibdev, "IBDEV %s cache miss for " IB_GID_FMT "%s\n", ibdev->name,
               IB_GID_ARGS ( gid ), ( cached ? " (in progress)" : "" ) );

        /* If lookup is already in progress, do nothing */
        if ( cached )
                return -ENOENT;

        /* Locate a new cache entry to use */
        cache_idx = ( (ib_path_cache_idx++) % IB_NUM_CACHED_PATHS );
        cached = &ib_path_cache[cache_idx];

        /* Destroy the old cache entry */
        if ( cached->path )
                ib_destroy_path ( ibdev, cached->path );
        memset ( cached, 0, sizeof ( *cached ) );

        /* Create new path */
        cached->path = ib_create_path ( ibdev, av, &ib_cached_path_op );
        if ( ! cached->path ) {
                DBGC ( ibdev, "IBDEV %s could not create path\n",
                       ibdev->name );
                return -ENOMEM;
        }
        ib_path_set_ownerdata ( cached->path, cached );

        /* Not found yet */
        return -ENOENT;
}

Variable Documentation

Initial value:
 {
        .complete = ib_path_complete,
}

Path transaction completion operations.

Definition at line 94 of file ib_pathrec.c.

Path cache.

Definition at line 176 of file ib_pathrec.c.

Referenced by ib_find_path_cache_entry(), and ib_resolve_path().

unsigned int ib_path_cache_idx [static]

Oldest path cache entry index.

Definition at line 179 of file ib_pathrec.c.

Referenced by ib_resolve_path().

Initial value:
 {
        .complete = ib_cached_path_complete,
}

Cached path transaction completion operations.

Definition at line 235 of file ib_pathrec.c.