From ae824f42784f80ba3ec4e76b224577cf8439590b Mon Sep 17 00:00:00 2001 From: Amir Nir Date: Thu, 28 Sep 2023 12:28:01 +0000 Subject: [PATCH] Add a utility function that converts LID routed portid to direct route In planarized fabrics, all SMPs must be sent by direct route. convert_portid_to_dr converts a portid object to direct route. Signed-off-by: Amir Nir --- debian/libibnetdisc5.symbols | 1 + libibnetdisc/ibnetdisc.c | 35 +++++++++++++++++++++++++++++++++++ libibnetdisc/ibnetdisc.h | 12 ++++++++++++ libibnetdisc/libibnetdisc.map | 1 + 4 files changed, 49 insertions(+) diff --git a/debian/libibnetdisc5.symbols b/debian/libibnetdisc5.symbols index 756379418..4af848a21 100644 --- a/debian/libibnetdisc5.symbols +++ b/debian/libibnetdisc5.symbols @@ -29,3 +29,4 @@ libibnetdisc.so.5 libibnetdisc5 #MINVER# ibnd_dump_agg_linkspeedextsup@IBNETDISC_1.1 1.6.1 ibnd_ext_umad_get_cas@IBNETDISC_1.2 1.6.1 ibnd_ext_umad_get_ca_by_name@IBNETDISC_1.2 1.6.1 + ibnd_convert_portid_to_dr@IBNETDISC_1.2 1.6.1 diff --git a/libibnetdisc/ibnetdisc.c b/libibnetdisc/ibnetdisc.c index 81ae5a503..074caac51 100644 --- a/libibnetdisc/ibnetdisc.c +++ b/libibnetdisc/ibnetdisc.c @@ -996,6 +996,41 @@ ibnd_port_t *ibnd_find_port_dr(ibnd_fabric_t * fabric, char *dr_str) return rc; } +int ibnd_convert_portid_to_dr(ibnd_fabric_t *fabric, ib_portid_t *portid, enum MAD_DEST dest_type) +{ + ibnd_port_t *found_port = NULL; + ib_portid_t new_portid; + + if (dest_type == IB_DEST_DRPATH || dest_type == IB_DEST_DRSLID) + return 0; + // copy portid, reset all destination fields + memcpy(&new_portid, portid, sizeof(ib_portid_t)); + new_portid.lid = 0; + memset(&new_portid.drpath, 0, sizeof(ib_dr_path_t)); + if (!fabric) + return -1; + + switch (dest_type) { + case IB_DEST_LID: + case IB_DEST_GID: + case IB_DEST_GUID: + found_port = ibnd_find_port_lid(fabric, portid->lid); + if (!found_port || !found_port->node) + return -1; + memcpy(&new_portid.drpath, &found_port->node->path_portid.drpath, + sizeof(ib_dr_path_t)); + break; + case IB_DEST_DRPATH: + case IB_DEST_DRSLID: + return 0; + default: + return -1; + } + + memcpy(portid, &new_portid, sizeof(ib_portid_t)); + return 0; +} + void ibnd_iter_ports(ibnd_fabric_t * fabric, ibnd_iter_port_func_t func, void *user_data) { diff --git a/libibnetdisc/ibnetdisc.h b/libibnetdisc/ibnetdisc.h index ec3a9ad0c..b7f52c574 100644 --- a/libibnetdisc/ibnetdisc.h +++ b/libibnetdisc/ibnetdisc.h @@ -228,6 +228,18 @@ typedef void (*ibnd_iter_port_func_t) (ibnd_port_t * port, void *user_data); void ibnd_iter_ports(ibnd_fabric_t *fabric, ibnd_iter_port_func_t func, void *user_data); +/** ========================================================================= + * Port operations + */ +int ibnd_convert_portid_to_dr(ibnd_fabric_t *fabric, ib_portid_t *portid, enum MAD_DEST dest_type); + /** + * Convert a portid's destination type to direct route. + * + * fabric: [input] discovered fabric + * portid: [input/output] portid object, to be converted to direct route + * dest_type: current destination type + */ + /** ========================================================================= * Chassis queries */ diff --git a/libibnetdisc/libibnetdisc.map b/libibnetdisc/libibnetdisc.map index 154c30109..de051e1da 100644 --- a/libibnetdisc/libibnetdisc.map +++ b/libibnetdisc/libibnetdisc.map @@ -38,4 +38,5 @@ IBNETDISC_1.2 { global: ibnd_ext_umad_get_cas; ibnd_ext_umad_get_ca_by_name; + ibnd_convert_portid_to_dr; } IBNETDISC_1.1;