iPXE
Functions | Variables
ib_mcast.c File Reference

Infiniband multicast groups. More...

#include <stdint.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/list.h>
#include <ipxe/infiniband.h>
#include <ipxe/ib_mi.h>
#include <ipxe/ib_mcast.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void ib_mcast_mad (struct ib_device *ibdev, struct ib_address_vector *av, unsigned int method, unsigned int mask, union ib_mad *mad)
 Generate multicast membership MAD. More...
 
static void ib_mcast_complete (struct ib_device *ibdev, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx, int rc, union ib_mad *mad, struct ib_address_vector *src __unused)
 Handle multicast membership record join response. More...
 
int ib_mcast_join (struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_mc_membership *membership, struct ib_address_vector *av, unsigned int mask, void(*complete)(struct ib_mc_membership *membership, int rc))
 Join multicast group. More...
 
void ib_mcast_leave (struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_mc_membership *membership)
 Leave multicast group. More...
 

Variables

static struct ib_mad_transaction_operations ib_mcast_op
 Multicast membership management transaction completion operations. More...
 

Detailed Description

Infiniband multicast groups.

Definition in file ib_mcast.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ib_mcast_mad()

static void ib_mcast_mad ( struct ib_device ibdev,
struct ib_address_vector av,
unsigned int  method,
unsigned int  mask,
union ib_mad mad 
)
static

Generate multicast membership MAD.

Parameters
ibdevInfiniband device
avAddress vector
methodMethod (IB_MGMT_METHOD_SET or IB_MGMT_METHOD_DELETE)
maskAdditional component mask
madMAD to fill in

Definition at line 50 of file ib_mcast.c.

53  {
54  struct ib_mad_sa *sa = &mad->sa;
55 
56  /* Construct multicast membership record request */
57  memset ( sa, 0, sizeof ( *sa ) );
58  sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
59  sa->mad_hdr.class_version = IB_SA_CLASS_VERSION;
60  sa->mad_hdr.method = method;
61  sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_MC_MEMBER_REC );
62  sa->sa_hdr.comp_mask[1] =
65  sa->sa_data.mc_member_record.qkey = htonl ( av->qkey );
66  sa->sa_data.mc_member_record.pkey =
67  htons ( ibdev->pkey | IB_PKEY_FULL );
68  sa->sa_data.mc_member_record.rate_selector__rate = av->rate;
69  sa->sa_data.mc_member_record.sl__flow_label__hop_limit =
70  htonl ( av->sl << 28 );
71  sa->sa_data.mc_member_record.scope__join_state = 0x01;
72  memcpy ( &sa->sa_data.mc_member_record.mgid, &av->gid,
73  sizeof ( sa->sa_data.mc_member_record.mgid ) );
74  memcpy ( &sa->sa_data.mc_member_record.port_gid, &ibdev->gid,
75  sizeof ( sa->sa_data.mc_member_record.port_gid ) );
76 }
#define IB_SA_CLASS_VERSION
Definition: ib_mad.h:207
#define IB_SA_ATTR_MC_MEMBER_REC
Definition: ib_mad.h:224
union ib_gid gid
Port GID (comprising GID prefix and port GUID)
Definition: infiniband.h:439
struct sockaddr sa
Definition: dns.c:68
#define IB_PKEY_FULL
Infiniband partition key full membership flag.
Definition: infiniband.h:42
#define IB_SA_MCMEMBER_REC_MGID
Definition: ib_mad.h:278
uint8_t method
Definition: ib_mad.h:14
#define htonl(value)
Definition: byteswap.h:133
enum ib_rate rate
Rate.
Definition: infiniband.h:86
void * memcpy(void *dest, const void *src, size_t len) __nonnull
unsigned long qkey
Queue key.
Definition: infiniband.h:79
#define IB_SA_MCMEMBER_REC_JOIN_STATE
Definition: ib_mad.h:294
struct ib_mad_sa sa
Definition: ib_mad.h:613
unsigned int sl
Service level.
Definition: infiniband.h:88
#define IB_MGMT_CLASS_SUBN_ADM
Definition: ib_mad.h:557
#define IB_SA_MCMEMBER_REC_PORT_GID
Definition: ib_mad.h:279
union ib_gid gid
GID, if present.
Definition: infiniband.h:92
uint16_t pkey
Partition key.
Definition: infiniband.h:447
A subnet administration MAD.
Definition: ib_mad.h:596
#define htons(value)
Definition: byteswap.h:135
union ib_mad mad
Definition: arbel.h:12
void * memset(void *dest, int character, size_t len) __nonnull

References ib_address_vector::gid, ib_device::gid, htonl, htons, IB_MGMT_CLASS_SUBN_ADM, IB_PKEY_FULL, IB_SA_ATTR_MC_MEMBER_REC, IB_SA_CLASS_VERSION, IB_SA_MCMEMBER_REC_JOIN_STATE, IB_SA_MCMEMBER_REC_MGID, IB_SA_MCMEMBER_REC_PORT_GID, mad, memcpy(), memset(), method, ib_device::pkey, ib_address_vector::qkey, ib_address_vector::rate, ib_mad::sa, sa, and ib_address_vector::sl.

Referenced by ib_mcast_join(), and ib_mcast_leave().

◆ ib_mcast_complete()

static void ib_mcast_complete ( struct ib_device ibdev,
struct ib_mad_interface *mi  __unused,
struct ib_mad_transaction madx,
int  rc,
union ib_mad mad,
struct ib_address_vector *src  __unused 
)
static

Handle multicast membership record join response.

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

Definition at line 88 of file ib_mcast.c.

92  {
93  struct ib_mc_membership *membership = ib_madx_get_ownerdata ( madx );
94  struct ib_queue_pair *qp = membership->qp;
95  struct ib_address_vector *av = membership->av;
98  int joined;
99 
100  /* Report failures */
101  if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ))
102  rc = -ENOTCONN;
103  if ( rc != 0 ) {
104  DBGC ( ibdev, "IBDEV %s QPN %#lx join failed: %s\n",
105  ibdev->name, qp->qpn, strerror ( rc ) );
106  goto out;
107  }
108 
109  /* Extract values from MAD */
110  joined = ( mad->hdr.method == IB_MGMT_METHOD_GET_RESP );
111  av->qkey = ntohl ( mc_member_record->qkey );
112  av->lid = ntohs ( mc_member_record->mlid );
113  av->rate = ( mc_member_record->rate_selector__rate & 0x3f );
115  >> 28 ) & 0x0f );
116  DBGC ( ibdev, "IBDEV %s QPN %#lx %s " IB_GID_FMT " qkey %#lx\n",
117  ibdev->name, qp->qpn, ( joined ? "joined" : "left" ),
118  IB_GID_ARGS ( &av->gid ), av->qkey );
119 
120  /* Set queue key */
121  qp->qkey = av->qkey;
122  if ( ( rc = ib_modify_qp ( ibdev, qp ) ) != 0 ) {
123  DBGC ( ibdev, "IBDEV %s QPN %#lx could not modify qkey: %s\n",
124  ibdev->name, qp->qpn, strerror ( rc ) );
125  goto out;
126  }
127 
128  out:
129  /* Destroy the completed transaction */
130  ib_destroy_madx ( ibdev, mi, madx );
131  membership->madx = NULL;
132 
133  /* Hand off to upper completion handler */
134  membership->complete ( membership, rc );
135 }
uint8_t method
Definition: ib_mad.h:542
struct ib_mad_transaction * madx
Multicast group join transaction.
Definition: ib_mcast.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[IBDEV_NAME_LEN]
Name of this Infiniband device.
Definition: infiniband.h:408
int ib_modify_qp(struct ib_device *ibdev, struct ib_queue_pair *qp)
Modify queue pair.
Definition: infiniband.c:294
#define DBGC(...)
Definition: compiler.h:505
struct ib_address_vector * av
Address vector.
Definition: ib_mcast.h:21
#define ntohl(value)
Definition: byteswap.h:134
#define ntohs(value)
Definition: byteswap.h:136
uint32_t sl__flow_label__hop_limit
Definition: ib_mad.h:271
enum ib_rate rate
Rate.
Definition: infiniband.h:86
unsigned long qkey
Queue key.
Definition: infiniband.h:79
union ib_sa_data sa_data
Definition: ib_mad.h:600
__be32 out[4]
Definition: CIB_PRM.h:36
An Infiniband multicast group membership.
Definition: ib_mcast.h:17
#define IB_MGMT_METHOD_GET_RESP
Definition: ib_mad.h:571
#define IB_GID_ARGS(gid)
Infiniband Global Identifier debug message arguments.
Definition: ib_packet.h:48
#define ENOTCONN
The socket is not connected.
Definition: errno.h:569
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t qkey
Definition: ib_mad.h:264
struct ib_mad_sa sa
Definition: ib_mad.h:613
static __always_inline void * ib_madx_get_ownerdata(struct ib_mad_transaction *madx)
Get Infiniband management transaction owner-private data.
Definition: ib_mi.h:117
struct ib_mc_member_record mc_member_record
Definition: ib_mad.h:300
An Infiniband Queue Pair.
Definition: infiniband.h:157
unsigned int sl
Service level.
Definition: infiniband.h:88
struct arbelprm_qp_db_record qp
Definition: arbel.h:13
struct ib_mad_hdr hdr
Definition: ib_mad.h:611
#define IB_MGMT_STATUS_OK
Definition: ib_mad.h:580
struct ib_queue_pair * qp
Queue pair.
Definition: ib_mcast.h:19
union ib_gid gid
GID, if present.
Definition: infiniband.h:92
void(* complete)(struct ib_mc_membership *membership, int rc)
Handle join success/failure.
Definition: ib_mcast.h:31
#define IB_GID_FMT
Infiniband Global Identifier debug message format.
Definition: ib_packet.h:45
struct ib_mc_member_record mc_member_record
Definition: ib_mad.h:13
An Infiniband Address Vector.
Definition: infiniband.h:72
unsigned int lid
Local ID.
Definition: infiniband.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint8_t rate_selector__rate
Definition: ib_mad.h:269
#define htons(value)
Definition: byteswap.h:135
uint16_t mlid
Definition: ib_mad.h:265
union ib_mad mad
Definition: arbel.h:12
uint16_t status
Definition: ib_mad.h:543
void ib_destroy_madx(struct ib_device *ibdev __unused, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx)
Destroy management transaction.
Definition: ib_mi.c:327

References ib_mc_membership::av, ib_mc_membership::complete, DBGC, ENOTCONN, ib_address_vector::gid, ib_mad::hdr, htons, ib_destroy_madx(), IB_GID_ARGS, IB_GID_FMT, ib_madx_get_ownerdata(), IB_MGMT_METHOD_GET_RESP, IB_MGMT_STATUS_OK, ib_modify_qp(), ib_address_vector::lid, mad, ib_mc_membership::madx, ib_sa_data::mc_member_record, mc_member_record, ib_mad_hdr::method, ib_mc_member_record::mlid, ib_device::name, ntohl, ntohs, NULL, out, ib_address_vector::qkey, ib_mc_member_record::qkey, ib_mc_membership::qp, qp, ib_address_vector::rate, ib_mc_member_record::rate_selector__rate, rc, ib_mad::sa, ib_mad_sa::sa_data, ib_address_vector::sl, ib_mc_member_record::sl__flow_label__hop_limit, ib_mad_hdr::status, and strerror().

◆ ib_mcast_join()

int ib_mcast_join ( struct ib_device ibdev,
struct ib_queue_pair qp,
struct ib_mc_membership membership,
struct ib_address_vector av,
unsigned int  mask,
void(*)(struct ib_mc_membership *membership, int rc complete 
)

Join multicast group.

Parameters
ibdevInfiniband device
qpQueue pair
membershipMulticast group membership
avAddress vector to fill in
joinedJoin completion handler
Return values
rcReturn status code

Definition at line 152 of file ib_mcast.c.

156  {
157  union ib_mad mad;
158  int rc;
159 
160  DBGC ( ibdev, "IBDEV %s QPN %#lx joining " IB_GID_FMT "\n",
161  ibdev->name, qp->qpn, IB_GID_ARGS ( &av->gid ) );
162 
163  /* Sanity checks */
164  assert ( qp != NULL );
165  assert ( ! membership->attached );
166 
167  /* Initialise structure */
168  membership->qp = qp;
169  membership->av = av;
170  membership->complete = complete;
171 
172  /* Attach queue pair to multicast GID */
173  if ( ( rc = ib_mcast_attach ( ibdev, qp, &av->gid ) ) != 0 ) {
174  DBGC ( ibdev, "IBDEV %s QPN %#lx could not attach: %s\n",
175  ibdev->name, qp->qpn, strerror ( rc ) );
176  goto err_mcast_attach;
177  }
178  membership->attached = 1;
179 
180  /* Initiate multicast membership join */
181  ib_mcast_mad ( ibdev, av, IB_MGMT_METHOD_SET, mask, &mad );
182  membership->madx = ib_create_madx ( ibdev, ibdev->gsi, &mad, NULL,
183  &ib_mcast_op );
184  if ( ! membership->madx ) {
185  DBGC ( ibdev, "IBDEV %s QPN %#lx could not create join "
186  "transaction\n", ibdev->name, qp->qpn );
187  rc = -ENOMEM;
188  goto err_create_madx;
189  }
190  ib_madx_set_ownerdata ( membership->madx, membership );
191 
192  return 0;
193 
194  ib_destroy_madx ( ibdev, ibdev->gsi, membership->madx );
195  err_create_madx:
196  ib_mcast_detach ( ibdev, qp, &av->gid );
197  membership->attached = 0;
198  err_mcast_attach:
199  return rc;
200 }
struct ib_mad_transaction * madx
Multicast group join transaction.
Definition: ib_mcast.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[IBDEV_NAME_LEN]
Name of this Infiniband device.
Definition: infiniband.h:408
static void ib_mcast_mad(struct ib_device *ibdev, struct ib_address_vector *av, unsigned int method, unsigned int mask, union ib_mad *mad)
Generate multicast membership MAD.
Definition: ib_mcast.c:50
#define DBGC(...)
Definition: compiler.h:505
struct ib_address_vector * av
Address vector.
Definition: ib_mcast.h:21
int ib_mcast_attach(struct ib_device *ibdev, struct ib_queue_pair *qp, union ib_gid *gid)
Attach to multicast group.
Definition: infiniband.c:752
struct ib_mad_interface * gsi
General services interface.
Definition: infiniband.h:459
#define IB_MGMT_METHOD_SET
Definition: ib_mad.h:570
int attached
Attached to multicast GID.
Definition: ib_mcast.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct ib_mad_transaction_operations ib_mcast_op
Multicast membership management transaction completion operations.
Definition: ib_mcast.c:138
struct ib_mad_transaction * ib_create_madx(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av, struct ib_mad_transaction_operations *op)
Create management transaction.
Definition: ib_mi.c:287
static __always_inline void ib_madx_set_ownerdata(struct ib_mad_transaction *madx, void *priv)
Set Infiniband management transaction owner-private data.
Definition: ib_mi.h:106
#define IB_GID_ARGS(gid)
Infiniband Global Identifier debug message arguments.
Definition: ib_packet.h:48
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void ib_mcast_detach(struct ib_device *ibdev, struct ib_queue_pair *qp, union ib_gid *gid)
Detach from multicast group.
Definition: infiniband.c:789
struct arbelprm_qp_db_record qp
Definition: arbel.h:13
struct ib_queue_pair * qp
Queue pair.
Definition: ib_mcast.h:19
union ib_gid gid
GID, if present.
Definition: infiniband.h:92
void(* complete)(struct ib_mc_membership *membership, int rc)
Handle join success/failure.
Definition: ib_mcast.h:31
#define IB_GID_FMT
Infiniband Global Identifier debug message format.
Definition: ib_packet.h:45
A management datagram.
Definition: ib_mad.h:610
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union ib_mad mad
Definition: arbel.h:12
void ib_destroy_madx(struct ib_device *ibdev __unused, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx)
Destroy management transaction.
Definition: ib_mi.c:327

References assert(), ib_mc_membership::attached, ib_mc_membership::av, ib_mc_membership::complete, DBGC, ENOMEM, ib_address_vector::gid, ib_device::gsi, ib_create_madx(), ib_destroy_madx(), IB_GID_ARGS, IB_GID_FMT, ib_madx_set_ownerdata(), ib_mcast_attach(), ib_mcast_detach(), ib_mcast_mad(), ib_mcast_op, IB_MGMT_METHOD_SET, mad, ib_mc_membership::madx, ib_device::name, NULL, qp, ib_mc_membership::qp, rc, and strerror().

Referenced by eoib_join_broadcast_group(), and ipoib_join_broadcast_group().

◆ ib_mcast_leave()

void ib_mcast_leave ( struct ib_device ibdev,
struct ib_queue_pair qp,
struct ib_mc_membership membership 
)

Leave multicast group.

Parameters
ibdevInfiniband device
qpQueue pair
membershipMulticast group membership

Definition at line 209 of file ib_mcast.c.

210  {
211  struct ib_address_vector *av = membership->av;
212  union ib_mad mad;
213  int rc;
214 
215  /* Do nothing if we are already detached from the multicast GID */
216  if ( ! membership->attached )
217  return;
218 
219  DBGC ( ibdev, "IBDEV %s QPN %#lx leaving " IB_GID_FMT "\n",
220  ibdev->name, qp->qpn, IB_GID_ARGS ( &av->gid ) );
221 
222  /* Sanity check */
223  assert ( qp != NULL );
224 
225  /* Detach from multicast GID */
226  ib_mcast_detach ( ibdev, qp, &av->gid );
227  membership->attached = 0;
228 
229  /* Cancel multicast membership join, if applicable */
230  if ( membership->madx ) {
231  ib_destroy_madx ( ibdev, ibdev->gsi, membership->madx );
232  membership->madx = NULL;
233  }
234 
235  /* Send a single group leave MAD */
236  ib_mcast_mad ( ibdev, av, IB_MGMT_METHOD_DELETE, 0, &mad );
237  if ( ( rc = ib_mi_send ( ibdev, ibdev->gsi, &mad, NULL ) ) != 0 ) {
238  DBGC ( ibdev, "IBDEV %s QPN %#lx could not send leave request: "
239  "%s\n", ibdev->name, qp->qpn, strerror ( rc ) );
240  }
241 }
struct ib_mad_transaction * madx
Multicast group join transaction.
Definition: ib_mcast.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define IB_MGMT_METHOD_DELETE
Definition: ib_mad.h:577
char name[IBDEV_NAME_LEN]
Name of this Infiniband device.
Definition: infiniband.h:408
static void ib_mcast_mad(struct ib_device *ibdev, struct ib_address_vector *av, unsigned int method, unsigned int mask, union ib_mad *mad)
Generate multicast membership MAD.
Definition: ib_mcast.c:50
#define DBGC(...)
Definition: compiler.h:505
struct ib_address_vector * av
Address vector.
Definition: ib_mcast.h:21
struct ib_mad_interface * gsi
General services interface.
Definition: infiniband.h:459
int attached
Attached to multicast GID.
Definition: ib_mcast.h:23
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define IB_GID_ARGS(gid)
Infiniband Global Identifier debug message arguments.
Definition: ib_packet.h:48
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void ib_mcast_detach(struct ib_device *ibdev, struct ib_queue_pair *qp, union ib_gid *gid)
Detach from multicast group.
Definition: infiniband.c:789
struct arbelprm_qp_db_record qp
Definition: arbel.h:13
union ib_gid gid
GID, if present.
Definition: infiniband.h:92
#define IB_GID_FMT
Infiniband Global Identifier debug message format.
Definition: ib_packet.h:45
A management datagram.
Definition: ib_mad.h:610
An Infiniband Address Vector.
Definition: infiniband.h:72
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int ib_mi_send(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Transmit MAD.
Definition: ib_mi.c:187
union ib_mad mad
Definition: arbel.h:12
void ib_destroy_madx(struct ib_device *ibdev __unused, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx)
Destroy management transaction.
Definition: ib_mi.c:327

References assert(), ib_mc_membership::attached, ib_mc_membership::av, DBGC, ib_address_vector::gid, ib_device::gsi, ib_destroy_madx(), IB_GID_ARGS, IB_GID_FMT, ib_mcast_detach(), ib_mcast_mad(), IB_MGMT_METHOD_DELETE, ib_mi_send(), mad, ib_mc_membership::madx, ib_device::name, NULL, qp, rc, and strerror().

Referenced by eoib_leave_broadcast_group(), and ipoib_leave_broadcast_group().

Variable Documentation

◆ ib_mcast_op

struct ib_mad_transaction_operations ib_mcast_op
static
Initial value:
= {
.complete = ib_mcast_complete,
}
static void ib_mcast_complete(struct ib_device *ibdev, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx, int rc, union ib_mad *mad, struct ib_address_vector *src __unused)
Handle multicast membership record join response.
Definition: ib_mcast.c:88

Multicast membership management transaction completion operations.

Definition at line 138 of file ib_mcast.c.

Referenced by ib_mcast_join().