Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libibumad: Add function that opens SMI ports #1474

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions debian/libibumad3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ libibumad.so.3 libibumad3 #MINVER#
IBUMAD_1.0@IBUMAD_1.0 1.3.9
IBUMAD_1.1@IBUMAD_1.1 3.1.26
IBUMAD_1.2@IBUMAD_1.2 3.2.30
IBUMAD_1.3@IBUMAD_1.3 3.3.53
umad_addr_dump@IBUMAD_1.0 1.3.9
umad_attribute_str@IBUMAD_1.0 1.3.10.2
umad_class_str@IBUMAD_1.0 1.3.10.2
Expand All @@ -25,6 +26,7 @@ libibumad.so.3 libibumad3 #MINVER#
umad_init@IBUMAD_1.0 1.3.9
umad_method_str@IBUMAD_1.0 1.3.10.2
umad_open_port@IBUMAD_1.0 1.3.9
umad_open_smi_port@IBUMAD_1.3 3.3.53
umad_poll@IBUMAD_1.0 1.3.9
umad_recv@IBUMAD_1.0 1.3.9
umad_register2@IBUMAD_1.0 1.3.10.2
Expand Down
2 changes: 1 addition & 1 deletion libibumad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish_headers(infiniband

rdma_library(ibumad libibumad.map
# See Documentation/versioning.md
3 3.2.${PACKAGE_VERSION}
3 3.3.${PACKAGE_VERSION}
sysfs.c
umad.c
umad_str.c
Expand Down
5 changes: 5 additions & 0 deletions libibumad/libibumad.map
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ IBUMAD_1.2 {
global:
umad_sort_ca_device_list;
} IBUMAD_1.1;

IBUMAD_1.3 {
global:
umad_open_smi_port;
} IBUMAD_1.2;
37 changes: 37 additions & 0 deletions libibumad/man/umad_open_smi_port.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.\" -*- nroff -*-
.\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md
.\"
.TH UMAD_OPEN_SMI_PORT 3 "June 18, 2024" "OpenIB" "OpenIB Programmer's Manual"
.SH "NAME"
umad_open_smi_port \- open InfiniBand device SMI port for umad access
.SH "SYNOPSIS"
.nf
.B #include <infiniband/umad.h>
.sp
.BI "int umad_open_smi_port(char " "*ca_name" ", int " "portnum" );
.fi
.SH "DESCRIPTION"
.B umad_open_smi_port()
opens the SMI port
.I portnum
of the IB device
.I ca_name
for umad access. The port is selected by the library if not all parameters
are provided (see
.B umad_get_port()
for details). Only SMI ports will be selected.
.fi
.SH "RETURN VALUE"
.B umad_open_smi_port()
returns 0 or an unique positive value of umad device descriptor on success, and a negative value on error as follows:
-EOPNOTSUPP ABI version doesn't match
-ENODEV IB device with SMI port can't be resolved
-EINVAL port is not valid (bad
.I portnum\fR
or no umad device)
-EIO umad device for this port can't be opened
.SH "SEE ALSO"
.BR umad_open_port (3),
.SH "AUTHOR"
.TP
Amir Nir <anir@nvidia.com>
45 changes: 35 additions & 10 deletions libibumad/umad.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <infiniband/umad.h>

#define IB_OPENIB_OUI (0x001405)
#define CAPMASK_IS_SM_DISABLED (0x400)

#include <valgrind/memcheck.h>
#include "sysfs.h"
Expand Down Expand Up @@ -128,6 +129,11 @@ static int put_ca(umad_ca_t * ca)
return 0; /* caching not implemented yet */
}

static unsigned is_smi_disabled(umad_port_t *port)
{
return (be32toh(port->capmask) & CAPMASK_IS_SM_DISABLED);
}

static int release_port(umad_port_t * port)
{
free(port->pkeys);
Expand Down Expand Up @@ -248,8 +254,9 @@ static int release_ca(umad_ca_t * ca)
* the first port that is active, and if such is not found, to
* the first port that is link up and if none are linkup, then
* the first port that is not disabled. Otherwise return -1.
* if enforce_smi > 0, only search smi ports. if none are found, return -1.
*/
static int resolve_ca_port(const char *ca_name, int *port)
static int resolve_ca_port(const char *ca_name, int *port, unsigned enforce_smi)
{
umad_ca_t ca;
int active = -1, up = -1;
Expand Down Expand Up @@ -280,6 +287,10 @@ static int resolve_ca_port(const char *ca_name, int *port)
ret = -1;
goto Exit;
}
if (enforce_smi && is_smi_disabled(ca.ports[*port])) {
ret = -1;
goto Exit;
}
if (ca.ports[*port]->state == 4) {
ret = 1;
goto Exit;
Expand All @@ -297,6 +308,8 @@ static int resolve_ca_port(const char *ca_name, int *port)
if (strcmp(ca.ports[i]->link_layer, "InfiniBand") &&
strcmp(ca.ports[i]->link_layer, "IB"))
continue;
if (enforce_smi && is_smi_disabled(ca.ports[i]))
continue;
if (up < 0 && ca.ports[i]->phys_state == 5)
up = *port = i;
if (ca.ports[i]->state == 4) {
Expand All @@ -311,6 +324,8 @@ static int resolve_ca_port(const char *ca_name, int *port)
DEBUG("checking port %d", i);
if (!ca.ports[i])
continue;
if (enforce_smi && is_smi_disabled(ca.ports[i]))
continue;
if (ca.ports[i]->phys_state != 3) {
up = *port = i;
break;
Expand All @@ -333,7 +348,7 @@ static int resolve_ca_port(const char *ca_name, int *port)
}

static int resolve_ca_name(const char *ca_in, int *best_port,
char **ca_name)
char **ca_name, unsigned enforce_smi)
{
struct umad_device_node *device_list;
struct umad_device_node *node;
Expand All @@ -350,7 +365,7 @@ static int resolve_ca_name(const char *ca_in, int *best_port,
}

if (ca_in) {
if (resolve_ca_port(ca_in, best_port) < 0)
if (resolve_ca_port(ca_in, best_port, enforce_smi) < 0)
return -1;
*ca_name = strdup(ca_in);
if (!(*ca_name))
Expand All @@ -370,7 +385,7 @@ static int resolve_ca_name(const char *ca_in, int *best_port,
TRACE("checking ca '%s'", name_found);

port = best_port ? *best_port : 0;
port_type = resolve_ca_port(name_found, &port);
port_type = resolve_ca_port(name_found, &port, enforce_smi);
if (port_type < 0)
continue;

Expand Down Expand Up @@ -626,7 +641,7 @@ int umad_get_ca_portguids(const char *ca_name, __be64 *portguids, int max)
char *found_ca_name;

TRACE("ca name %s max port guids %d", ca_name, max);
if (resolve_ca_name(ca_name, NULL, &found_ca_name) < 0) {
if (resolve_ca_name(ca_name, NULL, &found_ca_name, 0) < 0) {
result = -ENODEV;
goto exit;
}
Expand Down Expand Up @@ -665,7 +680,7 @@ int umad_get_issm_path(const char *ca_name, int portnum, char path[], int max)

TRACE("ca %s port %d", ca_name, portnum);

if (resolve_ca_name(ca_name, &portnum, &found_ca_name) < 0) {
if (resolve_ca_name(ca_name, &portnum, &found_ca_name, 0) < 0) {
result = -ENODEV;
goto exit;
}
Expand All @@ -685,7 +700,7 @@ int umad_get_issm_path(const char *ca_name, int portnum, char path[], int max)
return result;
}

int umad_open_port(const char *ca_name, int portnum)
static int do_umad_open_port(const char *ca_name, int portnum, unsigned enforce_smi)
{
char dev_file[UMAD_DEV_FILE_SZ];
int umad_id, fd, result;
Expand All @@ -699,7 +714,7 @@ int umad_open_port(const char *ca_name, int portnum)
goto exit;
}

if (resolve_ca_name(ca_name, &portnum, &found_ca_name) < 0) {
if (resolve_ca_name(ca_name, &portnum, &found_ca_name, enforce_smi) < 0) {
result = -ENODEV;
goto exit;
}
Expand Down Expand Up @@ -735,13 +750,23 @@ int umad_open_port(const char *ca_name, int portnum)
return result;
}

int umad_open_port(const char *ca_name, int portnum)
{
return do_umad_open_port(ca_name, portnum, 0);
}

int umad_open_smi_port(const char *ca_name, int portnum)
{
return do_umad_open_port(ca_name, portnum, 1);
}

int umad_get_ca(const char *ca_name, umad_ca_t *ca)
{
int r = 0;
char *found_ca_name;

TRACE("ca_name %s", ca_name);
if (resolve_ca_name(ca_name, NULL, &found_ca_name) < 0) {
if (resolve_ca_name(ca_name, NULL, &found_ca_name, 0) < 0) {
r = -ENODEV;
goto exit;
}
Expand Down Expand Up @@ -783,7 +808,7 @@ int umad_get_port(const char *ca_name, int portnum, umad_port_t *port)

TRACE("ca_name %s portnum %d", ca_name, portnum);

if (resolve_ca_name(ca_name, &portnum, &found_ca_name) < 0) {
if (resolve_ca_name(ca_name, &portnum, &found_ca_name, 0) < 0) {
result = -ENODEV;
goto exit;
}
Expand Down
1 change: 1 addition & 0 deletions libibumad/umad.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int umad_release_port(umad_port_t * port);
int umad_get_issm_path(const char *ca_name, int portnum, char path[], int max);

int umad_open_port(const char *ca_name, int portnum);
int umad_open_smi_port(const char *ca_name, int portnum);
int umad_close_port(int portid);

void *umad_get_mad(void *umad);
Expand Down