ib_srp.c File Reference

SCSI RDMA Protocol over Infiniband. More...

#include <stdlib.h>
#include <errno.h>
#include <gpxe/srp.h>
#include <gpxe/infiniband.h>
#include <gpxe/ib_cmrc.h>
#include <gpxe/ib_srp.h>

Go to the source code of this file.

Data Structures

struct  ib_srp_root_path
 IB SRP root path parameters. More...
struct  ib_srp_root_path_parser
 IB SRP root path component parser. More...

Defines

#define EINVAL_BYTE_STRING_LEN   ( EINVAL | EUNIQ_01 )
#define EINVAL_BYTE_STRING   ( EINVAL | EUNIQ_02 )
#define EINVAL_INTEGER   ( EINVAL | EUNIQ_03 )
#define EINVAL_RP_TOO_SHORT   ( EINVAL | EUNIQ_04 )
#define IB_SRP_NUM_RP_COMPONENTS   ( sizeof ( ib_srp_rp_parser ) / sizeof ( ib_srp_rp_parser[0] ) )
 Number of IB SRP root path components.

Enumerations

enum  ib_srp_parse_flags { IB_SRP_PARSE_REQUIRED = 0x0000, IB_SRP_PARSE_OPTIONAL = 0x8000, IB_SRP_PARSE_FLAG_MASK = 0xf000 }
 IB SRP parse flags. More...

Functions

 FILE_LICENCE (BSD2)
static int ib_srp_parse_byte_string (const char *rp_comp, uint8_t *bytes, unsigned int size_flags)
 Parse IB SRP root path byte-string value.
static int ib_srp_parse_integer (const char *rp_comp, int default_value)
 Parse IB SRP root path integer value.
static int ib_srp_parse_literal (const char *rp_comp __unused, struct ib_srp_root_path *rp __unused)
 Parse IB SRP root path literal component.
static int ib_srp_parse_sgid (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path source GID.
static int ib_srp_parse_initiator_id_ext (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path initiator identifier extension.
static int ib_srp_parse_initiator_hca_guid (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path initiator HCA GUID.
static int ib_srp_parse_dgid (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path destination GID.
static int ib_srp_parse_pkey (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path partition key.
static int ib_srp_parse_service_id (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path service ID.
static int ib_srp_parse_lun (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path LUN.
static int ib_srp_parse_target_id_ext (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path target identifier extension.
static int ib_srp_parse_target_ioc_guid (const char *rp_comp, struct ib_srp_root_path *rp)
 Parse IB SRP root path target I/O controller GUID.
static int ib_srp_parse_root_path (struct srp_device *srp, const char *rp_string)
 Parse IB SRP root path.
static int ib_srp_connect (struct srp_device *srp)
 Connect IB SRP session.

Variables

static struct
ib_srp_root_path_parser 
ib_srp_rp_parser []
 IB SRP root path components.
struct srp_transport_type ib_srp_transport
 IB SRP transport type.


Detailed Description

SCSI RDMA Protocol over Infiniband.

Definition in file ib_srp.c.


Define Documentation

#define EINVAL_BYTE_STRING_LEN   ( EINVAL | EUNIQ_01 )

Definition at line 48 of file ib_srp.c.

Referenced by ib_srp_parse_byte_string().

#define EINVAL_BYTE_STRING   ( EINVAL | EUNIQ_02 )

Definition at line 49 of file ib_srp.c.

Referenced by ib_srp_parse_byte_string().

#define EINVAL_INTEGER   ( EINVAL | EUNIQ_03 )

Definition at line 50 of file ib_srp.c.

Referenced by ib_srp_parse_integer().

#define EINVAL_RP_TOO_SHORT   ( EINVAL | EUNIQ_04 )

Definition at line 51 of file ib_srp.c.

Referenced by ib_srp_parse_root_path().

#define IB_SRP_NUM_RP_COMPONENTS   ( sizeof ( ib_srp_rp_parser ) / sizeof ( ib_srp_rp_parser[0] ) )

Number of IB SRP root path components.

Definition at line 314 of file ib_srp.c.

Referenced by ib_srp_parse_root_path().


Enumeration Type Documentation

IB SRP parse flags.

Enumerator:
IB_SRP_PARSE_REQUIRED 
IB_SRP_PARSE_OPTIONAL 
IB_SRP_PARSE_FLAG_MASK 

Definition at line 54 of file ib_srp.c.

00054                         {
00055         IB_SRP_PARSE_REQUIRED = 0x0000,
00056         IB_SRP_PARSE_OPTIONAL = 0x8000,
00057         IB_SRP_PARSE_FLAG_MASK = 0xf000,
00058 };


Function Documentation

FILE_LICENCE ( BSD2   ) 

static int ib_srp_parse_byte_string ( const char *  rp_comp,
uint8_t bytes,
unsigned int  size_flags 
) [static]

Parse IB SRP root path byte-string value.

Parameters:
rp_comp Root path component string
default_value Default value to use if component string is empty
Return values:
value Value

Definition at line 77 of file ib_srp.c.

References EINVAL_BYTE_STRING, EINVAL_BYTE_STRING_LEN, IB_SRP_PARSE_FLAG_MASK, IB_SRP_PARSE_OPTIONAL, memcpy, size, strlen(), and strtoul().

Referenced by ib_srp_parse_dgid(), ib_srp_parse_initiator_hca_guid(), ib_srp_parse_initiator_id_ext(), ib_srp_parse_service_id(), ib_srp_parse_sgid(), ib_srp_parse_target_id_ext(), and ib_srp_parse_target_ioc_guid().

00078                                                                 {
00079         size_t size = ( size_flags & ~IB_SRP_PARSE_FLAG_MASK );
00080         size_t rp_comp_len = strlen ( rp_comp );
00081         char buf[3];
00082         char *buf_end;
00083 
00084         /* Allow optional components to be empty */
00085         if ( ( rp_comp_len == 0 ) &&
00086              ( size_flags & IB_SRP_PARSE_OPTIONAL ) )
00087                 return 0;
00088 
00089         /* Check string length */
00090         if ( rp_comp_len != ( 2 * size ) )
00091                 return -EINVAL_BYTE_STRING_LEN;
00092 
00093         /* Parse byte string */
00094         for ( ; size ; size--, rp_comp += 2, bytes++ ) {
00095                 memcpy ( buf, rp_comp, 2 );
00096                 buf[2] = '\0';
00097                 *bytes = strtoul ( buf, &buf_end, 16 );
00098                 if ( buf_end != &buf[2] )
00099                         return -EINVAL_BYTE_STRING;
00100         }
00101         return 0;
00102 }

static int ib_srp_parse_integer ( const char *  rp_comp,
int  default_value 
) [static]

Parse IB SRP root path integer value.

Parameters:
rp_comp Root path component string
default_value Default value to use if component string is empty
Return values:
value Value

Definition at line 111 of file ib_srp.c.

References EINVAL_INTEGER, and strtoul().

Referenced by ib_srp_parse_pkey().

00111                                                                            {
00112         int value;
00113         char *end;
00114 
00115         value = strtoul ( rp_comp, &end, 16 );
00116         if ( *end )
00117                 return -EINVAL_INTEGER;
00118 
00119         if ( end == rp_comp )
00120                 return default_value;
00121 
00122         return value;
00123 }

static int ib_srp_parse_literal ( const char *rp_comp  __unused,
struct ib_srp_root_path *rp  __unused 
) [static]

Parse IB SRP root path literal component.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 132 of file ib_srp.c.

00133                                                                          {
00134         /* Ignore */
00135         return 0;
00136 }

static int ib_srp_parse_sgid ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path source GID.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 145 of file ib_srp.c.

References ib_gid::bytes, ib_device::gid, ib_srp_root_path::ib, ib_srp_parse_byte_string(), IB_SRP_PARSE_OPTIONAL, last_opened_ibdev(), memcpy, NULL, ib_srp_parameters::sgid, and ib_gid::u.

00146                                                              {
00147         struct ib_device *ibdev;
00148 
00149         /* Default to the GID of the last opened Infiniband device */
00150         if ( ( ibdev = last_opened_ibdev() ) != NULL )
00151                 memcpy ( &rp->ib->sgid, &ibdev->gid, sizeof ( rp->ib->sgid ) );
00152 
00153         return ib_srp_parse_byte_string ( rp_comp, rp->ib->sgid.u.bytes,
00154                                           ( sizeof ( rp->ib->sgid ) |
00155                                             IB_SRP_PARSE_OPTIONAL ) );
00156 }

static int ib_srp_parse_initiator_id_ext ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path initiator identifier extension.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 165 of file ib_srp.c.

References ib_gid_half::bytes, ib_srp_initiator_port_id(), ib_srp_parse_byte_string(), IB_SRP_PARSE_OPTIONAL, ib_srp_initiator_port_id::id_ext, ib_srp_root_path::port_ids, and ib_gid_half::u.

00166                                                                          {
00167         struct ib_srp_initiator_port_id *port_id =
00168                 ib_srp_initiator_port_id ( rp->port_ids );
00169 
00170         return ib_srp_parse_byte_string ( rp_comp, port_id->id_ext.u.bytes,
00171                                           ( sizeof ( port_id->id_ext ) |
00172                                             IB_SRP_PARSE_OPTIONAL ) );
00173 }

static int ib_srp_parse_initiator_hca_guid ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path initiator HCA GUID.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 182 of file ib_srp.c.

References ib_gid_half::bytes, ib_gid::half, ib_srp_initiator_port_id::hca_guid, ib_srp_root_path::ib, ib_srp_initiator_port_id(), ib_srp_parse_byte_string(), IB_SRP_PARSE_OPTIONAL, memcpy, ib_srp_root_path::port_ids, ib_srp_parameters::sgid, ib_gid_half::u, and ib_gid::u.

00183                                                                            {
00184         struct ib_srp_initiator_port_id *port_id =
00185                 ib_srp_initiator_port_id ( rp->port_ids );
00186 
00187         /* Default to the GUID portion of the source GID */
00188         memcpy ( &port_id->hca_guid, &rp->ib->sgid.u.half[1],
00189                  sizeof ( port_id->hca_guid ) );
00190 
00191         return ib_srp_parse_byte_string ( rp_comp, port_id->hca_guid.u.bytes,
00192                                           ( sizeof ( port_id->hca_guid ) |
00193                                             IB_SRP_PARSE_OPTIONAL ) );
00194 }

static int ib_srp_parse_dgid ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path destination GID.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 203 of file ib_srp.c.

References ib_gid::bytes, ib_srp_parameters::dgid, ib_srp_root_path::ib, ib_srp_parse_byte_string(), IB_SRP_PARSE_REQUIRED, and ib_gid::u.

00204                                                              {
00205         return ib_srp_parse_byte_string ( rp_comp, rp->ib->dgid.u.bytes,
00206                                           ( sizeof ( rp->ib->dgid ) |
00207                                             IB_SRP_PARSE_REQUIRED ) );
00208 }

static int ib_srp_parse_pkey ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path partition key.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 217 of file ib_srp.c.

References ib_srp_root_path::ib, IB_PKEY_DEFAULT, ib_srp_parse_integer(), and ib_srp_parameters::pkey.

00218                                                              {
00219         int pkey;
00220 
00221         if ( ( pkey = ib_srp_parse_integer ( rp_comp, IB_PKEY_DEFAULT ) ) < 0 )
00222                 return pkey;
00223         rp->ib->pkey = pkey;
00224         return 0;
00225 }

static int ib_srp_parse_service_id ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path service ID.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 234 of file ib_srp.c.

References ib_gid_half::bytes, ib_srp_root_path::ib, ib_srp_parse_byte_string(), IB_SRP_PARSE_REQUIRED, ib_srp_parameters::service_id, and ib_gid_half::u.

00235                                                                    {
00236         return ib_srp_parse_byte_string ( rp_comp, rp->ib->service_id.u.bytes,
00237                                           ( sizeof ( rp->ib->service_id ) |
00238                                             IB_SRP_PARSE_REQUIRED ) );
00239 }

static int ib_srp_parse_lun ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path LUN.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 248 of file ib_srp.c.

References ib_srp_root_path::lun, and scsi_parse_lun().

00249                                                             {
00250         return scsi_parse_lun ( rp_comp, rp->lun );
00251 }

static int ib_srp_parse_target_id_ext ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path target identifier extension.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 260 of file ib_srp.c.

References ib_gid_half::bytes, ib_srp_parse_byte_string(), IB_SRP_PARSE_REQUIRED, ib_srp_target_port_id(), ib_srp_target_port_id::id_ext, ib_srp_root_path::port_ids, and ib_gid_half::u.

00261                                                                       {
00262         struct ib_srp_target_port_id *port_id =
00263                 ib_srp_target_port_id ( rp->port_ids );
00264 
00265         return ib_srp_parse_byte_string ( rp_comp, port_id->id_ext.u.bytes,
00266                                           ( sizeof ( port_id->id_ext ) |
00267                                             IB_SRP_PARSE_REQUIRED ) );
00268 }

static int ib_srp_parse_target_ioc_guid ( const char *  rp_comp,
struct ib_srp_root_path rp 
) [static]

Parse IB SRP root path target I/O controller GUID.

Parameters:
rp_comp Root path component string
rp IB SRP root path
Return values:
rc Return status code

Definition at line 277 of file ib_srp.c.

References ib_gid_half::bytes, ib_srp_parse_byte_string(), IB_SRP_PARSE_REQUIRED, ib_srp_target_port_id(), ib_srp_target_port_id::ioc_guid, ib_srp_root_path::port_ids, and ib_gid_half::u.

00278                                                                         {
00279         struct ib_srp_target_port_id *port_id =
00280                 ib_srp_target_port_id ( rp->port_ids );
00281 
00282         return ib_srp_parse_byte_string ( rp_comp, port_id->ioc_guid.u.bytes,
00283                                           ( sizeof ( port_id->ioc_guid ) |
00284                                             IB_SRP_PARSE_REQUIRED ) );
00285 }

static int ib_srp_parse_root_path ( struct srp_device srp,
const char *  rp_string 
) [static]

Parse IB SRP root path.

Parameters:
srp SRP device
rp_string Root path
Return values:
rc Return status code

Definition at line 324 of file ib_srp.c.

References DBGC, EINVAL_RP_TOO_SHORT, IB_SRP_NUM_RP_COMPONENTS, ib_srp_params(), srp_device::lun, ib_srp_root_path::lun, srp_device::port_ids, strcpy(), strerror(), and strlen().

00325                                                             {
00326         struct ib_srp_parameters *ib_params = ib_srp_params ( srp );
00327         struct ib_srp_root_path rp = {
00328                 .lun = &srp->lun,
00329                 .port_ids = &srp->port_ids,
00330                 .ib = ib_params,
00331         };
00332         char rp_string_copy[ strlen ( rp_string ) + 1 ];
00333         char *rp_comp[IB_SRP_NUM_RP_COMPONENTS];
00334         char *rp_string_tmp = rp_string_copy;
00335         unsigned int i = 0;
00336         int rc;
00337 
00338         /* Split root path into component parts */
00339         strcpy ( rp_string_copy, rp_string );
00340         while ( 1 ) {
00341                 rp_comp[i++] = rp_string_tmp;
00342                 if ( i == IB_SRP_NUM_RP_COMPONENTS )
00343                         break;
00344                 for ( ; *rp_string_tmp != ':' ; rp_string_tmp++ ) {
00345                         if ( ! *rp_string_tmp ) {
00346                                 DBGC ( srp, "SRP %p root path \"%s\" too "
00347                                        "short\n", srp, rp_string );
00348                                 return -EINVAL_RP_TOO_SHORT;
00349                         }
00350                 }
00351                 *(rp_string_tmp++) = '\0';
00352         }
00353 
00354         /* Parse root path components */
00355         for ( i = 0 ; i < IB_SRP_NUM_RP_COMPONENTS ; i++ ) {
00356                 if ( ( rc = ib_srp_rp_parser[i].parse ( rp_comp[i],
00357                                                         &rp ) ) != 0 ) {
00358                         DBGC ( srp, "SRP %p could not parse \"%s\" in root "
00359                                "path \"%s\": %s\n", srp, rp_comp[i],
00360                                rp_string, strerror ( rc ) );
00361                         return rc;
00362                 }
00363         }
00364 
00365         return 0;
00366 }

static int ib_srp_connect ( struct srp_device srp  )  [static]

Connect IB SRP session.

Parameters:
srp SRP device
Return values:
rc Return status code

Definition at line 374 of file ib_srp.c.

References DBGC, ib_srp_parameters::dgid, ENODEV, find_ibdev(), ib_cmrc_open(), ib_srp_params(), srp_device::memory_handle, ib_device::rdma_key, ib_srp_parameters::service_id, ib_srp_parameters::sgid, srp_device::socket, and strerror().

00374                                                      {
00375         struct ib_srp_parameters *ib_params = ib_srp_params ( srp );
00376         struct ib_device *ibdev;
00377         int rc;
00378 
00379         /* Identify Infiniband device */
00380         ibdev = find_ibdev ( &ib_params->sgid );
00381         if ( ! ibdev ) {
00382                 DBGC ( srp, "SRP %p could not identify Infiniband device\n",
00383                        srp );
00384                 return -ENODEV;
00385         }
00386 
00387         /* Configure remaining SRP parameters */
00388         srp->memory_handle = ibdev->rdma_key;
00389 
00390         /* Open CMRC socket */
00391         if ( ( rc = ib_cmrc_open ( &srp->socket, ibdev, &ib_params->dgid,
00392                                    &ib_params->service_id ) ) != 0 ) {
00393                 DBGC ( srp, "SRP %p could not open CMRC socket: %s\n",
00394                        srp, strerror ( rc ) );
00395                 return rc;
00396         }
00397 
00398         return 0;
00399 }


Variable Documentation

Initial value:

 {
        .priv_len = sizeof ( struct ib_srp_parameters ),
        .parse_root_path = ib_srp_parse_root_path,
        .connect = ib_srp_connect,
}
IB SRP transport type.

Definition at line 402 of file ib_srp.c.

Referenced by sbft_fill_data(), and srp_attach().


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