From 63ae1ee08574389c33e01e419b95ea4eddee11cc Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Tue, 12 Nov 2024 16:06:20 +0200 Subject: [PATCH 1/6] rdma-core/libibumad: Add all pair SMI&GSI support Added 2 new methods to libibumad: - umad_get_cas_pairs - umad_get_ca_pair_by_name Also 2 new strucures to represent smi/gsi pairs: - umad_ca_pair - umad_ca_pair_item_t Signed-off-by: Asaf Mazor --- libibumad/libibumad.map | 2 + libibumad/man/umad_get_ca_pair_by_name.3 | 59 +++++ libibumad/man/umad_get_cas_pairs.3 | 56 ++++ libibumad/umad.c | 310 +++++++++++++++++++++++ libibumad/umad.h | 15 ++ 5 files changed, 442 insertions(+) create mode 100644 libibumad/man/umad_get_ca_pair_by_name.3 create mode 100644 libibumad/man/umad_get_cas_pairs.3 diff --git a/libibumad/libibumad.map b/libibumad/libibumad.map index 694d1dd2a..e93fc1264 100644 --- a/libibumad/libibumad.map +++ b/libibumad/libibumad.map @@ -54,4 +54,6 @@ IBUMAD_1.2 { IBUMAD_1.3 { global: umad_open_smi_port; + umad_get_cas_pairs; + umad_get_ca_pair_by_name; } IBUMAD_1.2; diff --git a/libibumad/man/umad_get_ca_pair_by_name.3 b/libibumad/man/umad_get_ca_pair_by_name.3 new file mode 100644 index 000000000..eb07ef82a --- /dev/null +++ b/libibumad/man/umad_get_ca_pair_by_name.3 @@ -0,0 +1,59 @@ +.\" -*- nroff -*- +.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md +.\" +.TH UMAD_GET_CAS_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.SH "NAME" +umad_get_ca_pair_by_name \- get SMI/GSI pair ca and port nums based on device name and portnum. + the given portnum addresses a port in the given device name (might be smi or gsi). +.SH "SYNOPSIS" +.nf +.B #include +.sp +.BI "int umad_get_ca_pair_by_name(const char * " "devname" ", uint8_t " "portnum" ", umad_ca_pair_t " "*ca" ); +.fi +.SH "DESCRIPTION" +.B umad_get_ca_pair_by_name() +fills argument +.I ca +with found ca according to name and portnum given in +.I devname +and +.I portnum +arguments +.I portnum +is the port number of a port in +.I dev name. +.nf +.I umad_ca_pair_t as specified in . +.PP +.nf +typedef struct umad_ca_pair { +.in +1 +umad_ca_pair_item_t smi; +.in +0 +umad_ca_pair_item_t gsi; +.in -2 +} umad_ca_pair; +.nf +.nf +typedef struct umad_ca_pair_item { +.in +1 + char name[UMAD_CA_NAME_LEN]; +.in +0 + uint32_t ports[UMAD_CA_MAX_PORTS]; +.in +0 + uint32_t numports; +.in +0 + uint32_t preferred_port; +.in -2 +} umad_ca_pair_item_t; +.fi +.PP + +.SH "RETURN VALUE" +.B umad_get_ca_pair_by_name() +returns 0 if a device and ports were found, 1 otherwise + +.SH "AUTHORS" +.TP +Asaf Mazor diff --git a/libibumad/man/umad_get_cas_pairs.3 b/libibumad/man/umad_get_cas_pairs.3 new file mode 100644 index 000000000..2bfa6c911 --- /dev/null +++ b/libibumad/man/umad_get_cas_pairs.3 @@ -0,0 +1,56 @@ +.\" -*- nroff -*- +.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md +.\" +.TH UMAD_GET_CAS_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.SH "NAME" +umad_get_cas_pairs \- get cas as SMI/GSI pairs +.SH "SYNOPSIS" +.nf +.B #include +.sp +.BI "int umad_get_cas_pairs(umad_ca_pair_t " "cas[]" ", size_t " "max" ); +.fi +.SH "DESCRIPTION" +.B umad_get_cas_pairs() +fill a user allocated array of struct +.I umad_ca_pair\fr +it fills up to +.I max +devices +The argument +.I cas +is an array of +.I umad_ca_pair_t as specified in . +.PP +.nf +typedef struct umad_ca_pair { +.in +1 +umad_ca_pair_item_t smi; +.in +0 +umad_ca_pair_item_t gsi; +.in -2 +} umad_ca_pair; +.nf +.nf +typedef struct umad_ca_pair_item { +.in +1 + char name[UMAD_CA_NAME_LEN]; +.in +0 + uint32_t ports[UMAD_CA_MAX_PORTS]; +.in +0 + uint32_t numports; +.in +0 + uint32_t preferred_port; +.in -2 +} umad_ca_pair_item_t; +.fi +.PP + +.SH "RETURN VALUE" +.B umad_get_cas_pairs() +returns the number of devices filled, +or -1 on error. + +.SH "AUTHORS" +.TP +Asaf Mazor diff --git a/libibumad/umad.c b/libibumad/umad.c index 9de39c7ea..4188f342a 100644 --- a/libibumad/umad.c +++ b/libibumad/umad.c @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -79,6 +80,16 @@ struct ib_user_mad_reg_req2 { uint8_t reserved[3]; }; +struct port_guid_port_count { + __be64 port_guid; + uint8_t count; +}; + +struct guid_ca_pairs_mapping { + __be64 port_guid; + umad_ca_pair_t *ca_pair; +}; + #define IBWARN(fmt, args...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", getpid(), __func__, ## args) #define TRACE if (umaddebug) IBWARN @@ -1354,3 +1365,302 @@ void umad_free_ca_device_list(struct umad_device_node *head) free(node); } } + +static void add_new_port(umad_ca_pair_item_t *dev, umad_port_t *p_port) +{ + if (!dev->name[0]) { + memcpy(dev->name, p_port->ca_name, UMAD_CA_NAME_LEN); + dev->numports = 0; + } + + if (dev->numports < UMAD_CA_MAX_PORTS) + dev->ports[dev->numports++] = p_port->portnum; +} + +static umad_ca_pair_t *get_ca_pair_from_arr_by_guid(__be64 port_guid, + struct guid_ca_pairs_mapping mapping[], + size_t map_max, size_t *map_added, + umad_ca_pair_t devs[], + size_t devs_max, size_t *devs_added) +{ + umad_ca_pair_t *dev = NULL; + // attempt to find the port guid in the mapping + size_t i = 0; + + for (i = 0; i < *map_added; ++i) { + if (mapping[i].port_guid == port_guid) + return mapping[i].ca_pair; + } + + // attempt to add a new mapping/device + if (*map_added >= map_max || *devs_added >= devs_max) + return NULL; + + dev = &devs[*devs_added]; + mapping[*map_added].port_guid = port_guid; + mapping[*map_added].ca_pair = dev; + (*devs_added)++; + (*map_added)++; + + return dev; +} + +static uint8_t get_port_guid_count(__be64 guid, const struct port_guid_port_count counts[], + size_t max_guids) +{ + size_t i = 0; + + for (i = 0; i < max_guids; ++i) { + if (counts[i].port_guid == guid) + return counts[i].count; + } + + return 0; +} + + +static bool find_port_guid_count(struct port_guid_port_count counts[], size_t max, + __be64 port_guid, size_t *index) +{ + size_t i = 0; + + for (i = 0; i < max; ++i) { + if (counts[i].port_guid == 0) { + *index = i; + return false; + } + if (counts[i].port_guid == port_guid) { + *index = i; + return true; + } + } + + *index = max; + return false; +} + +static int count_ports_by_guid(char legacy_ca_names[][UMAD_CA_NAME_LEN], size_t num_cas, + struct port_guid_port_count counts[], size_t max) +{ + // how many unique port GUIDs were added + size_t num_of_guid = 0; + + memset(counts, 0, max * sizeof(struct port_guid_port_count)); + + size_t c_idx = 0; + + for (c_idx = 0; c_idx < num_cas; ++c_idx) { + umad_ca_t curr_ca; + + if (umad_get_ca(legacy_ca_names[c_idx], &curr_ca) < 0) + continue; + + size_t p_idx = 1; + + for (p_idx = 1; p_idx < (size_t)curr_ca.numports + 1; ++p_idx) { + umad_port_t *p_port = curr_ca.ports[p_idx]; + size_t count_idx = 0; + + if (!p_port) + continue; + + if (find_port_guid_count(counts, max, p_port->port_guid, &count_idx)) { + // port GUID already has a count struct + ++counts[count_idx].count; + } else { + // add a new count struct for this GUID. + // if the maximum amount was already added, do nothing. + if (count_idx != max) { + counts[count_idx].port_guid = p_port->port_guid; + counts[count_idx].count = 1; + ++num_of_guid; + } + } + } + + umad_release_ca(&curr_ca); + } + + return num_of_guid; +} + +int umad_get_cas_pairs(umad_ca_pair_t cas[], size_t max) +{ + size_t added_devices = 0, added_mappings = 0; + char legacy_ca_names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN] = {}; + struct port_guid_port_count counts[UMAD_MAX_PORTS] = {}; + struct guid_ca_pairs_mapping mapping[UMAD_MAX_PORTS] = {}; + + memset(cas, 0, sizeof(umad_ca_pair_t) * max); + int cas_found = umad_get_cas_names(legacy_ca_names, UMAD_MAX_DEVICES); + + if (cas_found < 0) + return 0; + + count_ports_by_guid(legacy_ca_names, cas_found, counts, UMAD_MAX_PORTS); + + size_t c_idx = 0; + + for (c_idx = 0; c_idx < (size_t)cas_found; ++c_idx) { + umad_ca_t curr_ca; + + if (umad_get_ca(legacy_ca_names[c_idx], &curr_ca) < 0) + continue; + + size_t p_idx = 1; + + for (p_idx = 1; p_idx < (size_t)curr_ca.numports + 1; ++p_idx) { + umad_port_t *p_port = curr_ca.ports[p_idx]; + uint8_t guid_count = 0; + + if (!p_port) + continue; + + guid_count = get_port_guid_count(curr_ca.ports[p_idx]->port_guid, + counts, UMAD_MAX_PORTS); + umad_ca_pair_t *dev = get_ca_pair_from_arr_by_guid(p_port->port_guid, + mapping, UMAD_MAX_PORTS, + &added_mappings, cas, + max, &added_devices); + if (!dev) + continue; + if (guid_count > 1) { + // planarized port + add_new_port(is_smi_disabled(p_port) ? + &dev->gsi : &dev->smi, p_port); + } else if (guid_count == 1) { + if (!is_smi_disabled(p_port)) + add_new_port(&dev->smi, p_port); + + // all ports are GSI ports in legacy HCAs + add_new_port(&dev->gsi, p_port); + } else { + return -1; + } + } + + umad_release_ca(&curr_ca); + } + + return added_devices; +} + +static int umad_check_active(umad_ca_pair_item_t *dev, int prefered) +{ + umad_ca_t ca; + + if (!dev) + return 1; + + // check if candidate is active + if (umad_get_ca(dev->name, &ca) < 0) + return 2; + + int state = ca.ports[prefered]->state; + + umad_release_ca(&ca); + + return !(state > 1); +} + +static int umad_find_active(umad_ca_pair_item_t *dev) +{ + int i; + + if (!dev) + return 1; + + for (i = 0; i < dev->numports; ++i) + if (!umad_check_active(dev, dev->ports[i])) { + dev->preferred_port = dev->ports[i]; + return 0; + } + + return 1; +} + +int umad_get_ca_pair_by_name(const char *name, uint8_t portnum, umad_ca_pair_t *ca) +{ + int rc = 1; + size_t i = 0; + int num_cas = 0; + size_t port_idx = 0; + bool is_gsi = false; + bool found_port = false; + + umad_ca_pair_item_t *dev = NULL; + umad_ca_pair_t cas_pair[UMAD_MAX_PORTS] = {}; + + if (!ca) + return -1; + + memset(cas_pair, 0, sizeof(cas_pair)); + memset(ca, 0, sizeof(*ca)); + + num_cas = umad_get_cas_pairs(cas_pair, UMAD_MAX_PORTS); + + if (num_cas <= 0) + return num_cas; + + for (i = 0; i < (size_t)num_cas; ++i) { + if (!cas_pair[i].gsi.name[0] || !cas_pair[i].smi.name[0] || + !cas_pair[i].gsi.numports || !cas_pair[i].smi.numports) + continue; + + if (name) + // name doesn't match - keep searching + if (strncmp(cas_pair[i].gsi.name, name, UMAD_CA_NAME_LEN) + && strncmp(cas_pair[i].smi.name, name, UMAD_CA_NAME_LEN)) { + continue; + } + + // check that the device given by "name" has a port number "portnum" + // (if name doesn't exist, assume SMI port is given) + is_gsi = (name && !strncmp(name, cas_pair[i].gsi.name, UMAD_CA_NAME_LEN)); + + if (portnum) { + dev = is_gsi ? &cas_pair[i].gsi : &cas_pair[i].smi; + + found_port = false; + + for (port_idx = 0; port_idx < dev->numports; ++port_idx) { + + if (!dev->ports[port_idx]) + break; + + if (dev->ports[port_idx] == portnum) + found_port = true; + } + + // couldn't find portnum - keep searching + if (!found_port) + continue; + } + + // fill candidate + *ca = cas_pair[i]; + + if (portnum) + if (is_gsi) + rc = umad_find_active(&ca->smi) + + umad_check_active(&ca->gsi, portnum); + else + rc = umad_check_active(&ca->smi, portnum) + + umad_find_active(&ca->gsi); + else { + rc = umad_find_active(&ca->smi) + + umad_find_active(&ca->gsi); + } + + if (!rc) + break; + } + + if (rc) { + errno = ENODEV; + return -errno; + } + + return rc; +} + diff --git a/libibumad/umad.h b/libibumad/umad.h index 195216e1b..73beb9819 100644 --- a/libibumad/umad.h +++ b/libibumad/umad.h @@ -169,6 +169,19 @@ typedef struct umad_ca { umad_port_t *ports[UMAD_CA_MAX_PORTS]; } umad_ca_t; +typedef struct umad_ca_pair_item { + char name[UMAD_CA_NAME_LEN]; + uint32_t ports[UMAD_CA_MAX_PORTS]; + uint32_t numports; + uint32_t preferred_port; +} umad_ca_pair_item_t; + +typedef struct umad_ca_pair { + umad_ca_pair_item_t smi; + umad_ca_pair_item_t gsi; +} umad_ca_pair_t; + + struct umad_device_node { struct umad_device_node *next; /* next umad device node */ const char *ca_name; /* ca name */ @@ -237,6 +250,8 @@ int umad_register2(int port_fd, struct umad_reg_attr *attr, int umad_debug(int level); void umad_addr_dump(ib_mad_addr_t * addr); void umad_dump(void *umad); +int umad_get_cas_pairs(umad_ca_pair_t cas[], size_t max); +int umad_get_ca_pair_by_name(const char *devname, uint8_t portnum, umad_ca_pair_t *ca); static inline void *umad_alloc(int num, size_t size) { /* alloc array of umad buffers */ From 323a959d6f60eae627d4d929c1c14459dcd15db7 Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Tue, 19 Nov 2024 15:02:17 +0000 Subject: [PATCH 2/6] - Change symbol names - update ABI version in CMakeLists.txt to 4 - update libibumad.map file - update libibumad3.symbols file Signed-off-by: Asaf Mazor --- debian/libibumad3.symbols | 2 ++ libibumad/CMakeLists.txt | 2 +- libibumad/libibumad.map | 9 +++++++-- libibumad/man/umad_get_ca_pair_by_name.3 | 10 +++++----- libibumad/man/umad_get_cas_pairs.3 | 10 +++++----- libibumad/umad.c | 6 +++--- libibumad/umad.h | 4 ++-- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/debian/libibumad3.symbols b/debian/libibumad3.symbols index 9b6e74682..42b4cf28f 100644 --- a/debian/libibumad3.symbols +++ b/debian/libibumad3.symbols @@ -44,3 +44,5 @@ libibumad.so.3 libibumad3 #MINVER# umad_sort_ca_device_list@IBUMAD_1.2 3.2.30 umad_status@IBUMAD_1.0 1.3.9 umad_unregister@IBUMAD_1.0 1.3.9 + umad_get_smi_gsi_pairs@IBUMAD_1.4 3.4.55 + umad_get_smi_gsi_pair_by_ca_name@@IBUMAD_1.4 3.4.55 diff --git a/libibumad/CMakeLists.txt b/libibumad/CMakeLists.txt index 3ee12c83d..dcb030e16 100644 --- a/libibumad/CMakeLists.txt +++ b/libibumad/CMakeLists.txt @@ -10,7 +10,7 @@ publish_headers(infiniband rdma_library(ibumad libibumad.map # See Documentation/versioning.md - 3 3.3.${PACKAGE_VERSION} + 3 3.4.${PACKAGE_VERSION} sysfs.c umad.c umad_str.c diff --git a/libibumad/libibumad.map b/libibumad/libibumad.map index e93fc1264..0fb572f24 100644 --- a/libibumad/libibumad.map +++ b/libibumad/libibumad.map @@ -54,6 +54,11 @@ IBUMAD_1.2 { IBUMAD_1.3 { global: umad_open_smi_port; - umad_get_cas_pairs; - umad_get_ca_pair_by_name; } IBUMAD_1.2; + +IBUMAD_1.4 { + global: + umad_get_smi_gsi_pairs; + umad_get_smi_gsi_pair_by_ca_name; +} IBUMAD_1.3; + diff --git a/libibumad/man/umad_get_ca_pair_by_name.3 b/libibumad/man/umad_get_ca_pair_by_name.3 index eb07ef82a..a90918736 100644 --- a/libibumad/man/umad_get_ca_pair_by_name.3 +++ b/libibumad/man/umad_get_ca_pair_by_name.3 @@ -1,18 +1,18 @@ .\" -*- nroff -*- .\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md .\" -.TH UMAD_GET_CAS_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.TH UMAD_GET_SMI_GSI_PAIR_BY_CA_NAME 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" .SH "NAME" -umad_get_ca_pair_by_name \- get SMI/GSI pair ca and port nums based on device name and portnum. +umad_get_smi_gsi_pair_by_ca_name \- get SMI/GSI pair ca and port nums based on device name and portnum. the given portnum addresses a port in the given device name (might be smi or gsi). .SH "SYNOPSIS" .nf .B #include .sp -.BI "int umad_get_ca_pair_by_name(const char * " "devname" ", uint8_t " "portnum" ", umad_ca_pair_t " "*ca" ); +.BI "int umad_get_smi_gsi_pair_by_ca_name(const char * " "devname" ", uint8_t " "portnum" ", umad_ca_pair_t " "*ca" ); .fi .SH "DESCRIPTION" -.B umad_get_ca_pair_by_name() +.B umad_get_smi_gsi_pair_by_ca_name() fills argument .I ca with found ca according to name and portnum given in @@ -51,7 +51,7 @@ typedef struct umad_ca_pair_item { .PP .SH "RETURN VALUE" -.B umad_get_ca_pair_by_name() +.B umad_get_smi_gsi_pair_by_ca_name() returns 0 if a device and ports were found, 1 otherwise .SH "AUTHORS" diff --git a/libibumad/man/umad_get_cas_pairs.3 b/libibumad/man/umad_get_cas_pairs.3 index 2bfa6c911..b8f8428f8 100644 --- a/libibumad/man/umad_get_cas_pairs.3 +++ b/libibumad/man/umad_get_cas_pairs.3 @@ -1,17 +1,17 @@ .\" -*- nroff -*- .\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md .\" -.TH UMAD_GET_CAS_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.TH UMAD_GET_SMI_GSI_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" .SH "NAME" -umad_get_cas_pairs \- get cas as SMI/GSI pairs +umad_get_smi_gsi_pairs \- get cas as SMI/GSI pairs .SH "SYNOPSIS" .nf .B #include .sp -.BI "int umad_get_cas_pairs(umad_ca_pair_t " "cas[]" ", size_t " "max" ); +.BI "int umad_get_smi_gsi_pairs(umad_ca_pair_t " "cas[]" ", size_t " "max" ); .fi .SH "DESCRIPTION" -.B umad_get_cas_pairs() +.B umad_get_smi_gsi_pairs() fill a user allocated array of struct .I umad_ca_pair\fr it fills up to @@ -47,7 +47,7 @@ typedef struct umad_ca_pair_item { .PP .SH "RETURN VALUE" -.B umad_get_cas_pairs() +.B umad_get_smi_gsi_pairs() returns the number of devices filled, or -1 on error. diff --git a/libibumad/umad.c b/libibumad/umad.c index 4188f342a..a689f268c 100644 --- a/libibumad/umad.c +++ b/libibumad/umad.c @@ -1484,7 +1484,7 @@ static int count_ports_by_guid(char legacy_ca_names[][UMAD_CA_NAME_LEN], size_t return num_of_guid; } -int umad_get_cas_pairs(umad_ca_pair_t cas[], size_t max) +int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max) { size_t added_devices = 0, added_mappings = 0; char legacy_ca_names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN] = {}; @@ -1579,7 +1579,7 @@ static int umad_find_active(umad_ca_pair_item_t *dev) return 1; } -int umad_get_ca_pair_by_name(const char *name, uint8_t portnum, umad_ca_pair_t *ca) +int umad_get_smi_gsi_pair_by_ca_name(const char *name, uint8_t portnum, umad_ca_pair_t *ca) { int rc = 1; size_t i = 0; @@ -1597,7 +1597,7 @@ int umad_get_ca_pair_by_name(const char *name, uint8_t portnum, umad_ca_pair_t * memset(cas_pair, 0, sizeof(cas_pair)); memset(ca, 0, sizeof(*ca)); - num_cas = umad_get_cas_pairs(cas_pair, UMAD_MAX_PORTS); + num_cas = umad_get_smi_gsi_pairs(cas_pair, UMAD_MAX_PORTS); if (num_cas <= 0) return num_cas; diff --git a/libibumad/umad.h b/libibumad/umad.h index 73beb9819..b85d42158 100644 --- a/libibumad/umad.h +++ b/libibumad/umad.h @@ -250,8 +250,8 @@ int umad_register2(int port_fd, struct umad_reg_attr *attr, int umad_debug(int level); void umad_addr_dump(ib_mad_addr_t * addr); void umad_dump(void *umad); -int umad_get_cas_pairs(umad_ca_pair_t cas[], size_t max); -int umad_get_ca_pair_by_name(const char *devname, uint8_t portnum, umad_ca_pair_t *ca); +int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max); +int umad_get_smi_gsi_pair_by_ca_name(const char *devname, uint8_t portnum, umad_ca_pair_t *ca); static inline void *umad_alloc(int num, size_t size) { /* alloc array of umad buffers */ From b976b3aceb4edc0bafc4bef6751f40779c0e5001 Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Tue, 19 Nov 2024 15:36:22 +0000 Subject: [PATCH 3/6] fix typo in symbol file Signed-off-by: Asaf Mazor --- debian/libibumad3.symbols | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/libibumad3.symbols b/debian/libibumad3.symbols index 42b4cf28f..471d81dba 100644 --- a/debian/libibumad3.symbols +++ b/debian/libibumad3.symbols @@ -45,4 +45,4 @@ libibumad.so.3 libibumad3 #MINVER# umad_status@IBUMAD_1.0 1.3.9 umad_unregister@IBUMAD_1.0 1.3.9 umad_get_smi_gsi_pairs@IBUMAD_1.4 3.4.55 - umad_get_smi_gsi_pair_by_ca_name@@IBUMAD_1.4 3.4.55 + umad_get_smi_gsi_pair_by_ca_name@IBUMAD_1.4 3.4.55 From 9cf1fdc2ed35e7f4b4bf862d33971f774ecd15e3 Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Wed, 27 Nov 2024 16:14:42 +0000 Subject: [PATCH 4/6] Refactor : simplify umad_ca_pair details. we only need smi/gsi names and preffered ports Also made some refactor in the code Signed-off-by: Asaf Mazor --- libibumad/umad.c | 143 +++++++++++++++++++++-------------------------- libibumad/umad.h | 21 +++---- 2 files changed, 72 insertions(+), 92 deletions(-) diff --git a/libibumad/umad.c b/libibumad/umad.c index a689f268c..359ce019e 100644 --- a/libibumad/umad.c +++ b/libibumad/umad.c @@ -87,7 +87,7 @@ struct port_guid_port_count { struct guid_ca_pairs_mapping { __be64 port_guid; - umad_ca_pair_t *ca_pair; + struct umad_ca_pair *ca_pair; }; #define IBWARN(fmt, args...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", getpid(), __func__, ## args) @@ -1366,24 +1366,13 @@ void umad_free_ca_device_list(struct umad_device_node *head) } } -static void add_new_port(umad_ca_pair_item_t *dev, umad_port_t *p_port) -{ - if (!dev->name[0]) { - memcpy(dev->name, p_port->ca_name, UMAD_CA_NAME_LEN); - dev->numports = 0; - } - - if (dev->numports < UMAD_CA_MAX_PORTS) - dev->ports[dev->numports++] = p_port->portnum; -} - -static umad_ca_pair_t *get_ca_pair_from_arr_by_guid(__be64 port_guid, +static struct umad_ca_pair *get_ca_pair_from_arr_by_guid(__be64 port_guid, struct guid_ca_pairs_mapping mapping[], size_t map_max, size_t *map_added, - umad_ca_pair_t devs[], + struct umad_ca_pair devs[], size_t devs_max, size_t *devs_added) { - umad_ca_pair_t *dev = NULL; + struct umad_ca_pair *dev = NULL; // attempt to find the port guid in the mapping size_t i = 0; @@ -1484,14 +1473,14 @@ static int count_ports_by_guid(char legacy_ca_names[][UMAD_CA_NAME_LEN], size_t return num_of_guid; } -int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max) +int umad_get_smi_gsi_pairs(struct umad_ca_pair cas[], size_t max) { size_t added_devices = 0, added_mappings = 0; char legacy_ca_names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN] = {}; struct port_guid_port_count counts[UMAD_MAX_PORTS] = {}; struct guid_ca_pairs_mapping mapping[UMAD_MAX_PORTS] = {}; - memset(cas, 0, sizeof(umad_ca_pair_t) * max); + memset(cas, 0, sizeof(struct umad_ca_pair) * max); int cas_found = umad_get_cas_names(legacy_ca_names, UMAD_MAX_DEVICES); if (cas_found < 0) @@ -1518,7 +1507,7 @@ int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max) guid_count = get_port_guid_count(curr_ca.ports[p_idx]->port_guid, counts, UMAD_MAX_PORTS); - umad_ca_pair_t *dev = get_ca_pair_from_arr_by_guid(p_port->port_guid, + struct umad_ca_pair *dev = get_ca_pair_from_arr_by_guid(p_port->port_guid, mapping, UMAD_MAX_PORTS, &added_mappings, cas, max, &added_devices); @@ -1526,15 +1515,16 @@ int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max) continue; if (guid_count > 1) { // planarized port - add_new_port(is_smi_disabled(p_port) ? - &dev->gsi : &dev->smi, p_port); + char *dev_name = is_smi_disabled(p_port) ? dev->gsi_name : dev->smi_name; + strncpy(dev_name, curr_ca.ca_name, UMAD_CA_NAME_LEN); + break; } else if (guid_count == 1) { if (!is_smi_disabled(p_port)) - add_new_port(&dev->smi, p_port); - - // all ports are GSI ports in legacy HCAs - add_new_port(&dev->gsi, p_port); + strncpy(dev->smi_name, curr_ca.ca_name, UMAD_CA_NAME_LEN); + strncpy(dev->gsi_name, curr_ca.ca_name, UMAD_CA_NAME_LEN); + break; } else { + umad_release_ca(&curr_ca); return -1; } } @@ -1545,57 +1535,72 @@ int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max) return added_devices; } -static int umad_check_active(umad_ca_pair_item_t *dev, int prefered) +static int umad_check_active(const umad_ca_t *ca, int prefered_portnum) { - umad_ca_t ca; - - if (!dev) + if (!ca) return 1; - // check if candidate is active - if (umad_get_ca(dev->name, &ca) < 0) - return 2; - - int state = ca.ports[prefered]->state; + if (!ca->ports[prefered_portnum]) + return 1; - umad_release_ca(&ca); + int state = ca->ports[prefered_portnum]->state; return !(state > 1); } -static int umad_find_active(umad_ca_pair_item_t *dev) +static int umad_find_active(struct umad_ca_pair *ca_pair, const umad_ca_t *ca, bool is_gsi) { - int i; + size_t i = 1; + uint32_t *portnum_to_set = is_gsi ? + &ca_pair->gsi_preferred_port : + &ca_pair->smi_preferred_port; - if (!dev) + if (!ca_pair) return 1; - for (i = 0; i < dev->numports; ++i) - if (!umad_check_active(dev, dev->ports[i])) { - dev->preferred_port = dev->ports[i]; + for (i = 1; i < (size_t)ca->numports + 1; ++i) { + if (!umad_check_active(ca, i)) { + *portnum_to_set = ca->ports[i]->portnum; return 0; } + } return 1; } -int umad_get_smi_gsi_pair_by_ca_name(const char *name, uint8_t portnum, umad_ca_pair_t *ca) +static int find_preferred_ports(struct umad_ca_pair *ca_pair, const umad_ca_t *ca, bool is_gsi, int portnum) +{ + if (portnum) { + uint32_t *port_to_set = is_gsi ? + &ca_pair->gsi_preferred_port : + &ca_pair->smi_preferred_port; + if (!umad_check_active(ca, portnum)) { + *port_to_set = portnum; + return umad_find_active(ca_pair, ca, !is_gsi); + } + return 1; + } + + return umad_find_active(ca_pair, ca, false) + + umad_find_active(ca_pair, ca, true); + +} + +int umad_get_smi_gsi_pair_by_ca_name(const char *name, uint8_t portnum, struct umad_ca_pair *ca_pair) { int rc = 1; size_t i = 0; int num_cas = 0; - size_t port_idx = 0; bool is_gsi = false; - bool found_port = false; - umad_ca_pair_item_t *dev = NULL; - umad_ca_pair_t cas_pair[UMAD_MAX_PORTS] = {}; + umad_ca_t ca; + struct umad_ca_pair cas_pair[UMAD_MAX_PORTS] = {}; - if (!ca) + if (!ca_pair) return -1; memset(cas_pair, 0, sizeof(cas_pair)); - memset(ca, 0, sizeof(*ca)); + memset(ca_pair, 0, sizeof(*ca_pair)); num_cas = umad_get_smi_gsi_pairs(cas_pair, UMAD_MAX_PORTS); @@ -1603,54 +1608,34 @@ int umad_get_smi_gsi_pair_by_ca_name(const char *name, uint8_t portnum, umad_ca_ return num_cas; for (i = 0; i < (size_t)num_cas; ++i) { - if (!cas_pair[i].gsi.name[0] || !cas_pair[i].smi.name[0] || - !cas_pair[i].gsi.numports || !cas_pair[i].smi.numports) + if (!cas_pair[i].gsi_name[0] || !cas_pair[i].smi_name[0]) continue; if (name) // name doesn't match - keep searching - if (strncmp(cas_pair[i].gsi.name, name, UMAD_CA_NAME_LEN) - && strncmp(cas_pair[i].smi.name, name, UMAD_CA_NAME_LEN)) { + if (strncmp(cas_pair[i].gsi_name, name, UMAD_CA_NAME_LEN) + && strncmp(cas_pair[i].smi_name, name, UMAD_CA_NAME_LEN)) { continue; } // check that the device given by "name" has a port number "portnum" // (if name doesn't exist, assume SMI port is given) - is_gsi = (name && !strncmp(name, cas_pair[i].gsi.name, UMAD_CA_NAME_LEN)); + is_gsi = (name && !strncmp(name, cas_pair[i].gsi_name, UMAD_CA_NAME_LEN)); if (portnum) { - dev = is_gsi ? &cas_pair[i].gsi : &cas_pair[i].smi; - - found_port = false; - - for (port_idx = 0; port_idx < dev->numports; ++port_idx) { - - if (!dev->ports[port_idx]) - break; - - if (dev->ports[port_idx] == portnum) - found_port = true; - } + if (umad_get_ca(is_gsi ? cas_pair[i].gsi_name : cas_pair[i].smi_name, &ca) < 0) + continue; - // couldn't find portnum - keep searching - if (!found_port) + if (!ca.ports[portnum]) { + umad_release_ca(&ca); continue; + } } // fill candidate - *ca = cas_pair[i]; - - if (portnum) - if (is_gsi) - rc = umad_find_active(&ca->smi) - + umad_check_active(&ca->gsi, portnum); - else - rc = umad_check_active(&ca->smi, portnum) - + umad_find_active(&ca->gsi); - else { - rc = umad_find_active(&ca->smi) - + umad_find_active(&ca->gsi); - } + *ca_pair = cas_pair[i]; + rc = find_preferred_ports(ca_pair, &ca, is_gsi, portnum); + umad_release_ca(&ca); if (!rc) break; diff --git a/libibumad/umad.h b/libibumad/umad.h index b85d42158..851a97bf9 100644 --- a/libibumad/umad.h +++ b/libibumad/umad.h @@ -169,17 +169,12 @@ typedef struct umad_ca { umad_port_t *ports[UMAD_CA_MAX_PORTS]; } umad_ca_t; -typedef struct umad_ca_pair_item { - char name[UMAD_CA_NAME_LEN]; - uint32_t ports[UMAD_CA_MAX_PORTS]; - uint32_t numports; - uint32_t preferred_port; -} umad_ca_pair_item_t; - -typedef struct umad_ca_pair { - umad_ca_pair_item_t smi; - umad_ca_pair_item_t gsi; -} umad_ca_pair_t; +struct umad_ca_pair { + char smi_name[UMAD_CA_NAME_LEN]; + uint32_t smi_preferred_port; + char gsi_name[UMAD_CA_NAME_LEN]; + uint32_t gsi_preferred_port; +}; struct umad_device_node { @@ -250,8 +245,8 @@ int umad_register2(int port_fd, struct umad_reg_attr *attr, int umad_debug(int level); void umad_addr_dump(ib_mad_addr_t * addr); void umad_dump(void *umad); -int umad_get_smi_gsi_pairs(umad_ca_pair_t cas[], size_t max); -int umad_get_smi_gsi_pair_by_ca_name(const char *devname, uint8_t portnum, umad_ca_pair_t *ca); +int umad_get_smi_gsi_pairs(struct umad_ca_pair cas[], size_t max); +int umad_get_smi_gsi_pair_by_ca_name(const char *devname, uint8_t portnum, struct umad_ca_pair *ca_pair); static inline void *umad_alloc(int num, size_t size) { /* alloc array of umad buffers */ From 198421a08e2f2d07fb1406bb2e7d60b70e9d0329 Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Sun, 1 Dec 2024 13:07:36 +0000 Subject: [PATCH 5/6] fix man pages Signed-off-by: Asaf Mazor --- libibumad/man/umad_get_ca_pair_by_name.3 | 59 ---------------- .../man/umad_get_smi_gsi_pair_by_ca_name.3 | 70 +++++++++++++++++++ ...t_cas_pairs.3 => umad_get_smi_gsi_pairs.3} | 30 ++++---- 3 files changed, 82 insertions(+), 77 deletions(-) delete mode 100644 libibumad/man/umad_get_ca_pair_by_name.3 create mode 100644 libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 rename libibumad/man/{umad_get_cas_pairs.3 => umad_get_smi_gsi_pairs.3} (54%) diff --git a/libibumad/man/umad_get_ca_pair_by_name.3 b/libibumad/man/umad_get_ca_pair_by_name.3 deleted file mode 100644 index a90918736..000000000 --- a/libibumad/man/umad_get_ca_pair_by_name.3 +++ /dev/null @@ -1,59 +0,0 @@ -.\" -*- nroff -*- -.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md -.\" -.TH UMAD_GET_SMI_GSI_PAIR_BY_CA_NAME 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" -.SH "NAME" -umad_get_smi_gsi_pair_by_ca_name \- get SMI/GSI pair ca and port nums based on device name and portnum. - the given portnum addresses a port in the given device name (might be smi or gsi). -.SH "SYNOPSIS" -.nf -.B #include -.sp -.BI "int umad_get_smi_gsi_pair_by_ca_name(const char * " "devname" ", uint8_t " "portnum" ", umad_ca_pair_t " "*ca" ); -.fi -.SH "DESCRIPTION" -.B umad_get_smi_gsi_pair_by_ca_name() -fills argument -.I ca -with found ca according to name and portnum given in -.I devname -and -.I portnum -arguments -.I portnum -is the port number of a port in -.I dev name. -.nf -.I umad_ca_pair_t as specified in . -.PP -.nf -typedef struct umad_ca_pair { -.in +1 -umad_ca_pair_item_t smi; -.in +0 -umad_ca_pair_item_t gsi; -.in -2 -} umad_ca_pair; -.nf -.nf -typedef struct umad_ca_pair_item { -.in +1 - char name[UMAD_CA_NAME_LEN]; -.in +0 - uint32_t ports[UMAD_CA_MAX_PORTS]; -.in +0 - uint32_t numports; -.in +0 - uint32_t preferred_port; -.in -2 -} umad_ca_pair_item_t; -.fi -.PP - -.SH "RETURN VALUE" -.B umad_get_smi_gsi_pair_by_ca_name() -returns 0 if a device and ports were found, 1 otherwise - -.SH "AUTHORS" -.TP -Asaf Mazor diff --git a/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 b/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 new file mode 100644 index 000000000..30681f940 --- /dev/null +++ b/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 @@ -0,0 +1,70 @@ +.\" -*- nroff -*- +.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md +.\" +.TH UMAD_GET_SMI_GSI_PAIR_BY_CA_NAME 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.SH NAME +.B umad_get_smi_gsi_pair_by_ca_name \- +Retrieve SMI/GSI pair information based on device name and port number +.SH SYNOPSIS +.nf +.B #include +.sp +.BI "int umad_get_smi_gsi_pair_by_ca_name(const char * " "devname" ", uint8_t " "portnum" ", struct umad_ca_pair " "*ca" ); +.fi +.SH DESCRIPTION +.B umad_get_smi_gsi_pair_by_ca_name() +fills the provided +.I ca +structure with the SMI and GSI pair information for the specified device name and port number. + +The +.I devname +parameter specifies the name of the device, and +.I portnum +is the associated port number. + +The +.I struct umad_ca_pair +is defined in +.I +and includes the following members: +.PP +.nf +struct umad_ca_pair { +.in +4 +char smi_name[UMAD_CA_NAME_LEN]; +.in +4 +\" Name of the SMI +.in -4 +uint32_t smi_preferred_port; +.in +4 +\" Preferred port for the SMI +.in -4 +char gsi_name[UMAD_CA_NAME_LEN]; +.in +4 +\" Name of the GSI +.in -4 +uint32_t gsi_preferred_port; +.in +4 +\" Preferred port for the GSI +.in -8 +}; +.fi +.PP +The function populates this structure with the relevant data for the given +.I devname +and +.I portnum. +.SH RETURN VALUE +.B umad_get_smi_gsi_pair_by_ca_name() +returns: +.TP +0 +If the specified device and port are found and the structure is successfully populated. +.TP +1 +If no matching device or port is found. +.SH AUTHORS +.TP +Asaf Mazor + diff --git a/libibumad/man/umad_get_cas_pairs.3 b/libibumad/man/umad_get_smi_gsi_pairs.3 similarity index 54% rename from libibumad/man/umad_get_cas_pairs.3 rename to libibumad/man/umad_get_smi_gsi_pairs.3 index b8f8428f8..be3fb38ca 100644 --- a/libibumad/man/umad_get_cas_pairs.3 +++ b/libibumad/man/umad_get_smi_gsi_pairs.3 @@ -1,14 +1,14 @@ .\" -*- nroff -*- .\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md .\" -.TH UMAD_GET_SMI_GSI_PAIRS 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" +.TH UMAD_GET_SMI_GSI_PAIRS 3 "Dec 1, 2024" "OpenIB" "OpenIB Programmer's Manual" .SH "NAME" umad_get_smi_gsi_pairs \- get cas as SMI/GSI pairs .SH "SYNOPSIS" .nf .B #include .sp -.BI "int umad_get_smi_gsi_pairs(umad_ca_pair_t " "cas[]" ", size_t " "max" ); +.BI "int umad_get_smi_gsi_pairs(struct umad_ca_pair " "cas[]" ", size_t " "max" ); .fi .SH "DESCRIPTION" .B umad_get_smi_gsi_pairs() @@ -20,32 +20,26 @@ devices The argument .I cas is an array of -.I umad_ca_pair_t as specified in . +.I struct umad_ca_pair as specified in . .PP .nf -typedef struct umad_ca_pair { +struct umad_ca_pair { .in +1 -umad_ca_pair_item_t smi; +char smi_name[UMAD_CA_NAME_LEN]; .in +0 -umad_ca_pair_item_t gsi; -.in -2 -} umad_ca_pair; -.nf -.nf -typedef struct umad_ca_pair_item { -.in +1 - char name[UMAD_CA_NAME_LEN]; +uint32_t smi_preferred_port; .in +0 - uint32_t ports[UMAD_CA_MAX_PORTS]; +char gsi_name[UMAD_CA_NAME_LEN]; .in +0 - uint32_t numports; -.in +0 - uint32_t preferred_port; +uint32_t gsi_preferred_port; .in -2 -} umad_ca_pair_item_t; +} umad_ca_pair; +.nf .fi .PP +smi_preferred_port/gsi_preferred_port are the first ports found active for SMI/GSI device + .SH "RETURN VALUE" .B umad_get_smi_gsi_pairs() returns the number of devices filled, From 67d43aa9cb97159022b60214dbde1d91afcd1c2b Mon Sep 17 00:00:00 2001 From: Asaf Mazor Date: Tue, 10 Dec 2024 11:11:53 +0000 Subject: [PATCH 6/6] change man page from roff to rst format Signed-off-by: Asaf Mazor --- .../man/umad_get_smi_gsi_pair_by_ca_name.3 | 122 ++++++++---------- libibumad/man/umad_get_smi_gsi_pairs.3 | 100 +++++++------- 2 files changed, 103 insertions(+), 119 deletions(-) diff --git a/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 b/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 index 30681f940..c70042e33 100644 --- a/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 +++ b/libibumad/man/umad_get_smi_gsi_pair_by_ca_name.3 @@ -1,70 +1,54 @@ -.\" -*- nroff -*- -.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md -.\" -.TH UMAD_GET_SMI_GSI_PAIR_BY_CA_NAME 3 "May 21, 2007" "OpenIB" "OpenIB Programmer's Manual" -.SH NAME -.B umad_get_smi_gsi_pair_by_ca_name \- -Retrieve SMI/GSI pair information based on device name and port number -.SH SYNOPSIS -.nf -.B #include -.sp -.BI "int umad_get_smi_gsi_pair_by_ca_name(const char * " "devname" ", uint8_t " "portnum" ", struct umad_ca_pair " "*ca" ); -.fi -.SH DESCRIPTION -.B umad_get_smi_gsi_pair_by_ca_name() -fills the provided -.I ca -structure with the SMI and GSI pair information for the specified device name and port number. - -The -.I devname -parameter specifies the name of the device, and -.I portnum -is the associated port number. - -The -.I struct umad_ca_pair -is defined in -.I -and includes the following members: -.PP -.nf -struct umad_ca_pair { -.in +4 -char smi_name[UMAD_CA_NAME_LEN]; -.in +4 -\" Name of the SMI -.in -4 -uint32_t smi_preferred_port; -.in +4 -\" Preferred port for the SMI -.in -4 -char gsi_name[UMAD_CA_NAME_LEN]; -.in +4 -\" Name of the GSI -.in -4 -uint32_t gsi_preferred_port; -.in +4 -\" Preferred port for the GSI -.in -8 -}; -.fi -.PP -The function populates this structure with the relevant data for the given -.I devname -and -.I portnum. -.SH RETURN VALUE -.B umad_get_smi_gsi_pair_by_ca_name() -returns: -.TP -0 -If the specified device and port are found and the structure is successfully populated. -.TP -1 -If no matching device or port is found. -.SH AUTHORS -.TP -Asaf Mazor +.. -*- rst -*- +.. Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md +umad_get_smi_gsi_pair_by_ca_name(3) +=================================== + +Retrieve SMI/GSI pair information based on device name and port number. + +Synopsis +-------- + +.. code-block:: c + + #include + + int umad_get_smi_gsi_pair_by_ca_name(const char *devname, uint8_t portnum, struct umad_ca_pair *ca); + +Description +----------- + +``umad_get_smi_gsi_pair_by_ca_name()`` fills the provided ``ca`` structure with the SMI and GSI pair information +for the specified device name and port number. + +The ``devname`` parameter specifies the name of the device, and ``portnum`` is the associated port number. + +The ``struct umad_ca_pair`` is defined in ```` and includes the following members: + +.. code-block:: c + + struct umad_ca_pair { + char smi_name[UMAD_CA_NAME_LEN]; + /* Name of the SMI */ + uint32_t smi_preferred_port; + /* Preferred port for the SMI */ + char gsi_name[UMAD_CA_NAME_LEN]; + /* Name of the GSI */ + uint32_t gsi_preferred_port; + /* Preferred port for the GSI */ + }; + +The function populates this structure with the relevant data for the given ``devname`` and ``portnum``. + +Return Value +------------ + +``umad_get_smi_gsi_pair_by_ca_name()`` returns: + +- **0**: If the specified device and port are found and the structure is successfully populated. +- **1**: If no matching device or port is found. + +Authors +------- + +- Asaf Mazor diff --git a/libibumad/man/umad_get_smi_gsi_pairs.3 b/libibumad/man/umad_get_smi_gsi_pairs.3 index be3fb38ca..ae746df19 100644 --- a/libibumad/man/umad_get_smi_gsi_pairs.3 +++ b/libibumad/man/umad_get_smi_gsi_pairs.3 @@ -1,50 +1,50 @@ -.\" -*- nroff -*- -.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md -.\" -.TH UMAD_GET_SMI_GSI_PAIRS 3 "Dec 1, 2024" "OpenIB" "OpenIB Programmer's Manual" -.SH "NAME" -umad_get_smi_gsi_pairs \- get cas as SMI/GSI pairs -.SH "SYNOPSIS" -.nf -.B #include -.sp -.BI "int umad_get_smi_gsi_pairs(struct umad_ca_pair " "cas[]" ", size_t " "max" ); -.fi -.SH "DESCRIPTION" -.B umad_get_smi_gsi_pairs() -fill a user allocated array of struct -.I umad_ca_pair\fr -it fills up to -.I max -devices -The argument -.I cas -is an array of -.I struct umad_ca_pair as specified in . -.PP -.nf -struct umad_ca_pair { -.in +1 -char smi_name[UMAD_CA_NAME_LEN]; -.in +0 -uint32_t smi_preferred_port; -.in +0 -char gsi_name[UMAD_CA_NAME_LEN]; -.in +0 -uint32_t gsi_preferred_port; -.in -2 -} umad_ca_pair; -.nf -.fi -.PP - -smi_preferred_port/gsi_preferred_port are the first ports found active for SMI/GSI device - -.SH "RETURN VALUE" -.B umad_get_smi_gsi_pairs() -returns the number of devices filled, -or -1 on error. - -.SH "AUTHORS" -.TP -Asaf Mazor +.. -*- rst -*- +.. Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md + +umad_get_smi_gsi_pairs(3) +========================= + +Get CAs as SMI/GSI pairs. + +Synopsis +-------- + +.. code-block:: c + + #include + + int umad_get_smi_gsi_pairs(struct umad_ca_pair cas[], size_t max); + +Description +----------- + +``umad_get_smi_gsi_pairs()`` fills a user-allocated array of ``struct umad_ca_pair``. +It fills up to ``max`` devices. + +The argument ``cas`` is an array of ``struct umad_ca_pair`` as specified in ````: + +.. code-block:: c + + struct umad_ca_pair { + char smi_name[UMAD_CA_NAME_LEN]; + /* Name of the SMI */ + uint32_t smi_preferred_port; + /* Preferred port for the SMI */ + char gsi_name[UMAD_CA_NAME_LEN]; + /* Name of the GSI */ + uint32_t gsi_preferred_port; + /* Preferred port for the GSI */ + }; + +The ``smi_preferred_port`` and ``gsi_preferred_port`` fields represent the first ports found active +for the corresponding SMI/GSI device. + +Return Value +------------ + +``umad_get_smi_gsi_pairs()`` returns the number of devices filled, or **-1** on error. + +Authors +------- + +- Asaf Mazor