Skip to content

Commit 411460a

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA/cma: Introduce API to read GIDs for multiple transports
This patch introduces an API that allows legacy applications to query GIDs for a rdma_cm_id which is used during connection establishment. GIDs are stored and created differently for iWarp, IB and RoCE transports. Therefore rdma_read_gids() returns GID for all the transports hiding such internal details to caller. It is usable for client side and server side connections. In general continued use of GID based addressing outside of IB is discouraged, so rdma_read_gids() should not be used by any new ULPs. Signed-off-by: Parav Pandit <[email protected]> Reviewed-by: Daniel Jurgens <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 2ffcf04 commit 411460a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/infiniband/core/cma.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,33 @@ __be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr)
20362036
}
20372037
EXPORT_SYMBOL(rdma_get_service_id);
20382038

2039+
void rdma_read_gids(struct rdma_cm_id *cm_id, union ib_gid *sgid,
2040+
union ib_gid *dgid)
2041+
{
2042+
struct rdma_addr *addr = &cm_id->route.addr;
2043+
2044+
if (!cm_id->device) {
2045+
if (sgid)
2046+
memset(sgid, 0, sizeof(*sgid));
2047+
if (dgid)
2048+
memset(dgid, 0, sizeof(*dgid));
2049+
return;
2050+
}
2051+
2052+
if (rdma_protocol_roce(cm_id->device, cm_id->port_num)) {
2053+
if (sgid)
2054+
rdma_ip2gid((struct sockaddr *)&addr->src_addr, sgid);
2055+
if (dgid)
2056+
rdma_ip2gid((struct sockaddr *)&addr->dst_addr, dgid);
2057+
} else {
2058+
if (sgid)
2059+
rdma_addr_get_sgid(&addr->dev_addr, sgid);
2060+
if (dgid)
2061+
rdma_addr_get_dgid(&addr->dev_addr, dgid);
2062+
}
2063+
}
2064+
EXPORT_SYMBOL(rdma_read_gids);
2065+
20392066
static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
20402067
{
20412068
struct rdma_id_private *id_priv = iw_id->context;

include/rdma/rdma_cm.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,23 @@ bool rdma_is_consumer_reject(struct rdma_cm_id *id, int reason);
413413
const void *rdma_consumer_reject_data(struct rdma_cm_id *id,
414414
struct rdma_cm_event *ev, u8 *data_len);
415415

416+
/**
417+
* rdma_read_gids - Return the SGID and DGID used for establishing
418+
* connection. This can be used after rdma_resolve_addr()
419+
* on client side. This can be use on new connection
420+
* on server side. This is applicable to IB, RoCE, iWarp.
421+
* If cm_id is not bound yet to the RDMA device, it doesn't
422+
* copy and SGID or DGID to the given pointers.
423+
* @id: Communication identifier whose GIDs are queried.
424+
* @sgid: Pointer to SGID where SGID will be returned. It is optional.
425+
* @dgid: Pointer to DGID where DGID will be returned. It is optional.
426+
* Note: This API should not be used by any new ULPs or new code.
427+
* Instead, users interested in querying GIDs should refer to path record
428+
* of the rdma_cm_id to query the GIDs.
429+
* This API is provided for compatibility for existing users.
430+
*/
431+
432+
void rdma_read_gids(struct rdma_cm_id *cm_id, union ib_gid *sgid,
433+
union ib_gid *dgid);
434+
416435
#endif /* RDMA_CM_H */

0 commit comments

Comments
 (0)