iPXE
Data Structures | Defines | Enumerations | Functions | Variables
ib_packet.h File Reference

Infiniband packet format. More...

Go to the source code of this file.

Data Structures

union  ib_guid
 An Infiniband Globally Unique Identifier. More...
union  ib_gid
 An Infiniband Global Identifier. More...
struct  ib_local_route_header
 An Infiniband Local Route Header. More...
struct  ib_global_route_header
 An Infiniband Global Route Header. More...
struct  ib_base_transport_header
 An Infiniband Base Transport Header. More...
struct  ib_datagram_extended_transport_header
 An Infiniband Datagram Extended Transport Header. More...
union  ib_headers
 All known IB header formats. More...

Defines

#define IB_GUID_FMT   "%08x:%08x"
 Infiniband Globally Unique Identifier debug message format.
#define IB_GUID_ARGS(guid)   ntohl ( (guid)->dwords[0] ), ntohl ( (guid)->dwords[1] )
 Infiniband Globally Unique Identifier debug message arguments.
#define IB_GID_FMT   IB_GUID_FMT ":" IB_GUID_FMT
 Infiniband Global Identifier debug message format.
#define IB_GID_ARGS(gid)   IB_GUID_ARGS ( &(gid)->s.prefix ), IB_GUID_ARGS ( &(gid)->s.guid )
 Infiniband Global Identifier debug message arguments.
#define IB_GID_MULTICAST(gid)   ( (gid)->bytes[0] == 0xff )
 Test for multicast GID.
#define IB_LID_NONE   0xffff
 Default Infiniband LID.
#define IB_LID_MULTICAST(lid)   ( ( (lid) >= 0xc000 ) && ( (lid) <= 0xfffe ) )
 Test for multicast LID.
#define IB_GRH_IPVER_IPv6   0x06
#define IB_GRH_NXTHDR_IBA   0x1b
#define IB_MAX_HEADER_SIZE   sizeof ( union ib_headers )
 Maximum size required for IB headers.

Enumerations

enum  ib_vl { IB_VL_DEFAULT = 0, IB_VL_SMP = 15 }
 Infiniband virtual lanes. More...
enum  ib_lnh { IB_LNH_RAW = 0, IB_LNH_IPv6 = 1, IB_LNH_BTH = 2, IB_LNH_GRH = 3 }
 An Infiniband Link Next Header value. More...
enum  ib_bth_opcode { BTH_OPCODE_UD_SEND = 0x64 }
 An Infiniband BTH opcode. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
struct ib_local_route_header __attribute__ ((packed))
int ib_push (struct ib_device *ibdev, struct io_buffer *iobuf, struct ib_queue_pair *qp, size_t payload_len, const struct ib_address_vector *dest)
 Add IB headers.
int ib_pull (struct ib_device *ibdev, struct io_buffer *iobuf, struct ib_queue_pair **qp, size_t *payload_len, struct ib_address_vector *dest, struct ib_address_vector *source)
 Remove IB headers.

Variables

uint8_t vl__lver
 Virtual lane and link version.
uint8_t sl__lnh
 Service level and next link header.
uint16_t dlid
 Destination LID.
uint16_t length
 Packet length.
uint16_t slid
 Source LID.
enum ib_vl __attribute__
uint32_t ipver__tclass__flowlabel
 IP version, traffic class, and flow label.
uint16_t paylen
 Payload length.
uint8_t nxthdr
 Next header.
uint8_t hoplmt
 Hop limit.
union ib_gid sgid
 Source GID.
union ib_gid dgid
 Destiniation GID.
uint8_t opcode
 Opcode.
uint8_t se__m__padcnt__tver
 Transport header version, pad count, migration and solicitation.
uint16_t pkey
 Partition key.
uint32_t dest_qp
 Destination queue pair.
uint32_t ack__psn
 Packet sequence number and acknowledge request.
uint32_t qkey
 Queue key.
uint32_t src_qp
 Source queue pair.
struct ib_local_route_header lrh
struct ib_global_route_header grh
struct ib_base_transport_header bth
struct
ib_datagram_extended_transport_header 
deth

Detailed Description

Infiniband packet format.

Definition in file ib_packet.h.


Define Documentation

#define IB_GUID_FMT   "%08x:%08x"
#define IB_GUID_ARGS (   guid)    ntohl ( (guid)->dwords[0] ), ntohl ( (guid)->dwords[1] )
#define IB_GID_ARGS (   gid)    IB_GUID_ARGS ( &(gid)->s.prefix ), IB_GUID_ARGS ( &(gid)->s.guid )
#define IB_GID_MULTICAST (   gid)    ( (gid)->bytes[0] == 0xff )

Test for multicast GID.

Definition at line 52 of file ib_packet.h.

Referenced by ipoib_complete_recv().

#define IB_LID_NONE   0xffff

Default Infiniband LID.

Definition at line 83 of file ib_packet.h.

Referenced by alloc_ibdev().

#define IB_LID_MULTICAST (   lid)    ( ( (lid) >= 0xc000 ) && ( (lid) <= 0xfffe ) )

Test for multicast LID.

Definition at line 86 of file ib_packet.h.

Referenced by ib_pull().

#define IB_GRH_IPVER_IPv6   0x06

Definition at line 109 of file ib_packet.h.

Referenced by ib_push().

#define IB_GRH_NXTHDR_IBA   0x1b

Definition at line 110 of file ib_packet.h.

Referenced by ib_push().

#define IB_MAX_HEADER_SIZE   sizeof ( union ib_headers )

Maximum size required for IB headers.

Definition at line 156 of file ib_packet.h.

Referenced by linda_post_send(), and qib7322_post_send().


Enumeration Type Documentation

enum ib_vl

Infiniband virtual lanes.

Enumerator:
IB_VL_DEFAULT 
IB_VL_SMP 

Definition at line 69 of file ib_packet.h.

           {
        IB_VL_DEFAULT = 0,
        IB_VL_SMP = 15,
};
enum ib_lnh

An Infiniband Link Next Header value.

Enumerator:
IB_LNH_RAW 
IB_LNH_IPv6 
IB_LNH_BTH 
IB_LNH_GRH 

Definition at line 75 of file ib_packet.h.

            {
        IB_LNH_RAW = 0,
        IB_LNH_IPv6 = 1,
        IB_LNH_BTH = 2,
        IB_LNH_GRH = 3
};

An Infiniband BTH opcode.

Enumerator:
BTH_OPCODE_UD_SEND 

Definition at line 127 of file ib_packet.h.

                   {
        BTH_OPCODE_UD_SEND = 0x64,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct ib_local_route_header __attribute__ ( (packed)  )
int ib_push ( struct ib_device ibdev,
struct io_buffer iobuf,
struct ib_queue_pair qp,
size_t  payload_len,
const struct ib_address_vector dest 
)

Add IB headers.

Parameters:
ibdevInfiniband device
iobufI/O buffer to contain headers
qpQueue pair
payload_lenPayload length
destDestination address vector
Return values:
rcReturn status code

Definition at line 52 of file ib_packet.c.

References ib_base_transport_header::ack__psn, bth, BTH_OPCODE_UD_SEND, io_buffer::data, DBGC2, DBGCP_HDA, ib_base_transport_header::dest_qp, deth, ib_global_route_header::dgid, ib_local_route_header::dlid, ib_queue_pair::ext_qpn, ib_address_vector::gid, ib_device::gid, ib_address_vector::gid_present, grh, ib_global_route_header::hoplmt, htonl, htons, IB_GRH_IPVER_IPv6, IB_GRH_NXTHDR_IBA, IB_LNH_BTH, IB_LNH_GRH, IB_QPN_SMI, IB_VL_DEFAULT, IB_VL_SMP, iob_len(), iob_push, ib_global_route_header::ipver__tclass__flowlabel, ib_local_route_header::length, ib_address_vector::lid, ib_device::lid, lrh, memcpy(), ib_device::name, NULL, ib_global_route_header::nxthdr, ib_base_transport_header::opcode, ib_global_route_header::paylen, ib_base_transport_header::pkey, ib_device::pkey, ib_work_queue::psn, ib_address_vector::qkey, ib_datagram_extended_transport_header::qkey, ib_address_vector::qpn, ib_base_transport_header::se__m__padcnt__tver, ib_queue_pair::send, ib_global_route_header::sgid, ib_address_vector::sl, ib_local_route_header::sl__lnh, ib_local_route_header::slid, ib_datagram_extended_transport_header::src_qp, and ib_local_route_header::vl__lver.

Referenced by arbel_fill_mlx_send_wqe(), hermon_fill_mlx_send_wqe(), linda_post_send(), and qib7322_post_send().

                                                     {
        struct ib_local_route_header *lrh;
        struct ib_global_route_header *grh;
        struct ib_base_transport_header *bth;
        struct ib_datagram_extended_transport_header *deth;
        size_t orig_iob_len = iob_len ( iobuf );
        size_t pad_len;
        size_t lrh_len;
        size_t grh_len;
        unsigned int vl;
        unsigned int lnh;

        DBGC2 ( ibdev, "IBDEV %s TX %04x:%08lx => %04x:%08lx (key %08lx)\n",
                ibdev->name, ibdev->lid, qp->ext_qpn, dest->lid, dest->qpn,
                dest->qkey );

        /* Calculate packet length */
        pad_len = ( (-payload_len) & 0x3 );
        payload_len += pad_len;
        payload_len += 4; /* ICRC */

        /* Reserve space for headers */
        orig_iob_len = iob_len ( iobuf );
        deth = iob_push ( iobuf, sizeof ( *deth ) );
        bth = iob_push ( iobuf, sizeof ( *bth ) );
        grh_len = ( payload_len + iob_len ( iobuf ) - orig_iob_len );
        grh = ( dest->gid_present ?
                iob_push ( iobuf, sizeof ( *grh ) ) : NULL );
        lrh = iob_push ( iobuf, sizeof ( *lrh ) );
        lrh_len = ( payload_len + iob_len ( iobuf ) - orig_iob_len );

        /* Construct LRH */
        vl = ( ( qp->ext_qpn == IB_QPN_SMI ) ? IB_VL_SMP : IB_VL_DEFAULT );
        lrh->vl__lver = ( vl << 4 );
        lnh = ( grh ? IB_LNH_GRH : IB_LNH_BTH );
        lrh->sl__lnh = ( ( dest->sl << 4 ) | lnh );
        lrh->dlid = htons ( dest->lid );
        lrh->length = htons ( lrh_len >> 2 );
        lrh->slid = htons ( ibdev->lid );

        /* Construct GRH, if required */
        if ( grh ) {
                grh->ipver__tclass__flowlabel =
                        htonl ( IB_GRH_IPVER_IPv6 << 28 );
                grh->paylen = htons ( grh_len );
                grh->nxthdr = IB_GRH_NXTHDR_IBA;
                grh->hoplmt = 0;
                memcpy ( &grh->sgid, &ibdev->gid, sizeof ( grh->sgid ) );
                memcpy ( &grh->dgid, &dest->gid, sizeof ( grh->dgid ) );
        }

        /* Construct BTH */
        bth->opcode = BTH_OPCODE_UD_SEND;
        bth->se__m__padcnt__tver = ( pad_len << 4 );
        bth->pkey = htons ( ibdev->pkey );
        bth->dest_qp = htonl ( dest->qpn );
        bth->ack__psn = htonl ( ( qp->send.psn++ ) & 0xffffffUL );

        /* Construct DETH */
        deth->qkey = htonl ( dest->qkey );
        deth->src_qp = htonl ( qp->ext_qpn );

        DBGCP_HDA ( ibdev, 0, iobuf->data,
                    ( iob_len ( iobuf ) - orig_iob_len ) );

        return 0;
}
int ib_pull ( struct ib_device ibdev,
struct io_buffer iobuf,
struct ib_queue_pair **  qp,
size_t payload_len,
struct ib_address_vector dest,
struct ib_address_vector source 
)

Remove IB headers.

Parameters:
ibdevInfiniband device
iobufI/O buffer containing headers
qpQueue pair to fill in, or NULL
payload_lenPayload length to fill in, or NULL
destDestination address vector to fill in
sourceSource address vector to fill in
Return values:
rcReturn status code

Definition at line 133 of file ib_packet.c.

References assert, bth, BTH_OPCODE_UD_SEND, io_buffer::data, DBGC, DBGC2, DBGCP_HDA, ib_base_transport_header::dest_qp, deth, ib_global_route_header::dgid, ib_local_route_header::dlid, EINVAL, ENODEV, ENOTSUP, ib_queue_pair::ext_qpn, ib_address_vector::gid, ib_address_vector::gid_present, grh, ib_find_qp_mgid(), ib_find_qp_qpn(), IB_GID_ARGS, IB_GID_FMT, IB_LID_MULTICAST, IB_LNH_BTH, IB_LNH_GRH, iob_len(), iob_pull, ib_local_route_header::length, ib_address_vector::lid, lrh, memcpy(), memset(), ib_device::name, ntohl, ntohs, NULL, ib_base_transport_header::opcode, ib_address_vector::qkey, ib_datagram_extended_transport_header::qkey, ib_address_vector::qpn, ib_base_transport_header::se__m__padcnt__tver, ib_global_route_header::sgid, ib_address_vector::sl, ib_local_route_header::sl__lnh, ib_local_route_header::slid, and ib_datagram_extended_transport_header::src_qp.

Referenced by linda_complete_recv(), and qib7322_complete_recv().

                                                 {
        struct ib_local_route_header *lrh;
        struct ib_global_route_header *grh;
        struct ib_base_transport_header *bth;
        struct ib_datagram_extended_transport_header *deth;
        size_t orig_iob_len = iob_len ( iobuf );
        unsigned int lnh;
        size_t pad_len;

        /* Clear return values */
        if ( qp )
                *qp = NULL;
        if ( payload_len )
                *payload_len = 0;
        memset ( dest, 0, sizeof ( *dest ) );
        memset ( source, 0, sizeof ( *source ) );

        /* Extract LRH */
        if ( iob_len ( iobuf ) < sizeof ( *lrh ) ) {
                DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for LRH\n",
                       ibdev->name, iob_len ( iobuf ) );
                return -EINVAL;
        }
        lrh = iobuf->data;
        iob_pull ( iobuf, sizeof ( *lrh ) );
        dest->lid = ntohs ( lrh->dlid );
        dest->sl = ( lrh->sl__lnh >> 4 );
        source->lid = ntohs ( lrh->slid );
        source->sl = ( lrh->sl__lnh >> 4 );
        lnh = ( lrh->sl__lnh & 0x3 );

        /* Reject unsupported packets */
        if ( ! ( ( lnh == IB_LNH_BTH ) || ( lnh == IB_LNH_GRH ) ) ) {
                DBGC ( ibdev, "IBDEV %s RX unsupported LNH %x\n",
                       ibdev->name, lnh );
                return -ENOTSUP;
        }

        /* Extract GRH, if present */
        if ( lnh == IB_LNH_GRH ) {
                if ( iob_len ( iobuf ) < sizeof ( *grh ) ) {
                        DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) "
                               "for GRH\n", ibdev->name, iob_len ( iobuf ) );
                        return -EINVAL;
                }
                grh = iobuf->data;
                iob_pull ( iobuf, sizeof ( *grh ) );
                dest->gid_present = 1;
                memcpy ( &dest->gid, &grh->dgid, sizeof ( dest->gid ) );
                source->gid_present = 1;
                memcpy ( &source->gid, &grh->sgid, sizeof ( source->gid ) );
        } else {
                grh = NULL;
        }

        /* Extract BTH */
        if ( iob_len ( iobuf ) < sizeof ( *bth ) ) {
                DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for BTH\n",
                       ibdev->name, iob_len ( iobuf ) );
                return -EINVAL;
        }
        bth = iobuf->data;
        iob_pull ( iobuf, sizeof ( *bth ) );
        if ( bth->opcode != BTH_OPCODE_UD_SEND ) {
                DBGC ( ibdev, "IBDEV %s unsupported BTH opcode %x\n",
                       ibdev->name, bth->opcode );
                return -ENOTSUP;
        }
        dest->qpn = ntohl ( bth->dest_qp );

        /* Extract DETH */
        if ( iob_len ( iobuf ) < sizeof ( *deth ) ) {
                DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for DETH\n",
                       ibdev->name, iob_len ( iobuf ) );
                return -EINVAL;
        }
        deth = iobuf->data;
        iob_pull ( iobuf, sizeof ( *deth ) );
        source->qpn = ntohl ( deth->src_qp );
        source->qkey = ntohl ( deth->qkey );

        /* Calculate payload length, if applicable */
        if ( payload_len ) {
                pad_len = ( ( bth->se__m__padcnt__tver >> 4 ) & 0x3 );
                *payload_len = ( ( ntohs ( lrh->length ) << 2 )
                                 - ( orig_iob_len - iob_len ( iobuf ) )
                                 - pad_len - 4 /* ICRC */ );
        }

        /* Determine destination QP, if applicable */
        if ( qp ) {
                if ( IB_LID_MULTICAST ( dest->lid ) && grh ) {
                        if ( ! ( *qp = ib_find_qp_mgid ( ibdev, &grh->dgid ))){
                                DBGC ( ibdev, "IBDEV %s RX for unknown MGID "
                                       IB_GID_FMT "\n", ibdev->name,
                                       IB_GID_ARGS ( &grh->dgid ) );
                                return -ENODEV;
                        }
                } else {
                        if ( ! ( *qp = ib_find_qp_qpn ( ibdev, dest->qpn ) ) ) {
                                DBGC ( ibdev, "IBDEV %s RX for nonexistent "
                                       "QPN %#lx\n", ibdev->name, dest->qpn );
                                return -ENODEV;
                        }
                }
                assert ( *qp );
        }

        DBGC2 ( ibdev, "IBDEV %s RX %04x:%08lx <= %04x:%08lx (key %08x)\n",
                ibdev->name, dest->lid,
                ( IB_LID_MULTICAST ( dest->lid ) ?
                  ( qp ? (*qp)->ext_qpn : -1UL ) : dest->qpn ),
                source->lid, source->qpn, ntohl ( deth->qkey ) );
        DBGCP_HDA ( ibdev, 0,
                    ( iobuf->data - ( orig_iob_len - iob_len ( iobuf ) ) ),
                    ( orig_iob_len - iob_len ( iobuf ) ) );

        return 0;
}

Variable Documentation

Virtual lane and link version.

Definition at line 68 of file ib_packet.h.

Service level and next link header.

Definition at line 70 of file ib_packet.h.

Destination LID.

Definition at line 72 of file ib_packet.h.

Packet length.

Definition at line 74 of file ib_packet.h.

Source LID.

Definition at line 76 of file ib_packet.h.

IP version, traffic class, and flow label.

4 bits : Version of the GRH 8 bits : Traffic class 20 bits : Flow label

Definition at line 114 of file ib_packet.h.

Payload length.

Definition at line 116 of file ib_packet.h.

Next header.

Definition at line 118 of file ib_packet.h.

Hop limit.

Definition at line 120 of file ib_packet.h.

union ib_gid sgid

Source GID.

Definition at line 122 of file ib_packet.h.

union ib_gid dgid

Destiniation GID.

Definition at line 124 of file ib_packet.h.

Opcode.

Definition at line 126 of file ib_packet.h.

Transport header version, pad count, migration and solicitation.

Definition at line 128 of file ib_packet.h.

Partition key.

Definition at line 130 of file ib_packet.h.

Destination queue pair.

Definition at line 132 of file ib_packet.h.

Packet sequence number and acknowledge request.

Definition at line 134 of file ib_packet.h.

Queue key.

Definition at line 139 of file ib_packet.h.

Source queue pair.

Definition at line 141 of file ib_packet.h.

Definition at line 148 of file ib_packet.h.

Referenced by ib_pull(), and ib_push().

Definition at line 150 of file ib_packet.h.

Referenced by ib_pull(), and ib_push().

Definition at line 151 of file ib_packet.h.

Referenced by ib_pull(), and ib_push().