[openib-general] [PATCH] ibsrpdm: use the proper HCA and port with non-default umad device
Alexander Beyn
abeyn at datadirectnet.com
Tue Dec 13 19:07:53 PST 2005
In srptools-0.0.2, ibsrpdm gets the LID of the first port of the first HCA to do
discovery. This means ibsrpdm can't find SRP targets connected to other ports,
even if the proper umad device is passed with the -d option.
With the following patch, ibsrpdm uses the HCA and port associated with the umad
device to get the LID. It was tested with 2 dual-port HCAs directly connected to
our Infiniband array, properly finding SRP targets on all four ports.
Alexander Beyn
DataDirect Networks
--- srp-dm.c.orig 2005-12-13 15:32:52.000000000 -0800
+++ srp-dm.c 2005-12-13 18:22:10.000000000 -0800
@@ -44,6 +44,7 @@
static const uint8_t topspin_oui[3] = { 0x00, 0x05, 0xad };
static char *umad_dev = "/dev/infiniband/umad0";
+static char *port_sysfs_path;
static int timeout_ms = 2500;
static uint16_t sm_lid;
static uint32_t tid = 1;
@@ -77,6 +78,47 @@
fprintf(stderr, "Usage: %s [-gGvc] [-d <umad device>]\n", argv0);
}
+int setup_port_sysfs_path(void) {
+ char path[256];
+ char ibport[16];
+ char ibdev[16];
+ char *umad_dev_name;
+ struct sysfs_class_device *umad_sysfs_dev;
+ struct sysfs_attribute *umad_attr;
+
+ if (sysfs_get_mnt_path(path, sizeof path)) {
+ fprintf(stderr, "Couldn't find sysfs mount.\n");
+ return -1;
+ }
+ if((umad_dev_name = rindex(umad_dev, '/'))) {
+ umad_dev_name++;
+ }
+ umad_sysfs_dev = sysfs_open_class_device("infiniband_mad",
+ umad_dev_name);
+ if(!umad_sysfs_dev) {
+ fprintf(stderr, "Couldn't open umad sysfs entry named: %s\n",
+ umad_dev_name);
+ return -1;
+ }
+ umad_attr = sysfs_get_classdev_attr(umad_sysfs_dev, "ibdev");
+ if(sysfs_read_attribute(umad_attr)) {
+ fprintf(stderr, "Couldn't read ibdev attribute.\n");
+ return -1;
+ }
+ sscanf(umad_attr->value, "%15s", ibdev);
+
+ umad_attr = sysfs_get_classdev_attr(umad_sysfs_dev, "port");
+ if(sysfs_read_attribute(umad_attr)) {
+ fprintf(stderr, "Couldn't read port attribute.\n");
+ return -1;
+ }
+ sscanf(umad_attr->value, "%15s", ibport);
+
+ asprintf(&port_sysfs_path, "%s/class/infiniband/%s/ports/%s",
+ path, ibdev, ibport);
+ return 0;
+}
+
int create_agent(int fd, uint32_t agent[2])
{
struct ib_user_mad_reg_req req;
@@ -196,7 +238,6 @@
struct ib_user_mad in_mad, out_mad;
struct srp_dm_mad *out_dm_mad, *in_dm_mad;
struct srp_dm_class_port_info *cpi;
- char path[256];
char val[64];
char *name;
int i;
@@ -208,12 +249,7 @@
cpi = (void *) out_dm_mad->data;
- if (sysfs_get_mnt_path(path, sizeof path)) {
- fprintf(stderr, "Couldn't find sysfs mount.\n");
- return -1;
- }
-
- asprintf(&name, "%s/class/infiniband/mthca0/ports/1/lid", path);
+ asprintf(&name, "%s/lid", port_sysfs_path);
if (sysfs_read_attribute_value(name, val, sizeof val)) {
fprintf(stderr, "Couldn't read LID at %s\n", name);
@@ -222,7 +258,7 @@
cpi->trap_lid = htons(strtol(val, NULL, 0));
- asprintf(&name, "%s/class/infiniband/mthca0/ports/1/gids/0", path);
+ asprintf(&name, "%s/gids/0", port_sysfs_path);
if (sysfs_read_attribute_value(name, val, sizeof val)) {
fprintf(stderr, "Couldn't read GID at %s\n", name);
@@ -473,19 +509,13 @@
struct srp_dm_rmpp_sa_mad *out_sa_mad, *in_sa_mad;
struct srp_sa_port_info_rec *port_info;
ssize_t len;
- char path[256];
char val[64];
char *name;
int pn;
int size;
int i;
- if (sysfs_get_mnt_path(path, sizeof path)) {
- fprintf(stderr, "Couldn't find sysfs mount.\n");
- return -1;
- }
-
- asprintf(&name, "%s/class/infiniband/mthca0/ports/1/sm_lid", path);
+ asprintf(&name, "%s/sm_lid", port_sysfs_path);
if (sysfs_read_attribute_value(name, val, sizeof val)) {
fprintf(stderr, "Couldn't read LID at %s\n", name);
@@ -585,6 +615,8 @@
perror("open");
return 1;
}
+ if(setup_port_sysfs_path())
+ return 1;
if (create_agent(fd, agent))
return 1;
More information about the general
mailing list