--- a/components/open-fabrics/libibumad/patches/base.patch Thu Jun 28 21:48:14 2012 -0700
+++ b/components/open-fabrics/libibumad/patches/base.patch Fri Jun 29 12:23:11 2012 -0700
@@ -104,22 +104,92 @@
#define TRACE if (umaddebug) IBWARN
#define DEBUG if (umaddebug) IBWARN
-@@ -172,6 +176,73 @@
+@@ -126,7 +130,12 @@
+ return *p ? 0 : 1;
+ }
+
++#if defined(__SVR4) && defined(__sun)
++static int get_port(char *ca_name, char *dir, int portnum,
++ struct ibv_context *ctx, umad_port_t * port)
++#else
+ static int get_port(char *ca_name, char *dir, int portnum, umad_port_t * port)
++#endif
+ {
+ char port_dir[256];
+ uint8_t gid[16];
+@@ -172,6 +181,39 @@
memcpy(&port->port_guid, gid + 8, sizeof port->port_guid);
snprintf(port_dir + len, sizeof(port_dir) - len, "/pkeys");
+
+#if defined(__SVR4) && defined(__sun)
+ {
++ struct ibv_port_attr port_attr;
++
++ if (ibv_query_port(ctx, portnum, &port_attr)) {
++ IBWARN("Could not query \"%s\" port %d", ca_name,
++ portnum);
++ goto clean;
++ }
++
++ port->pkeys =
++ malloc(sizeof (uint16_t) * port_attr.pkey_tbl_len);
++
++ if (!port->pkeys) {
++ IBWARN("Could not retrieve pkeys for \"%s\"", ca_name);
++ goto clean;
++ }
++
++ /*
++ * set high bit of port_num, and try get all pkeys in one go.
++ */
++ portnum |= 0x80;
++ num_pkeys = ibv_query_pkey(ctx, portnum, port_attr.pkey_tbl_len,
++ port->pkeys);
++ if (num_pkeys != 0) {
++ IBWARN("get_port: ibv_query_pkey() failed for \"%s\"",
++ ca_name);
++ goto clean;
++ }
++ port->pkeys_size = port_attr.pkey_tbl_len;
++ }
++#else
+ num_pkeys = scandir(port_dir, &namelist, check_for_digit_name, NULL);
+ if (num_pkeys <= 0) {
+ IBWARN("no pkeys found for %s:%u (at dir %s)...",
+@@ -193,6 +235,8 @@
+ port->pkeys_size = num_pkeys;
+ free(namelist);
+ namelist = NULL;
++#endif
++
+ port_dir[len] = '\0';
+
+ /* FIXME: handle gids */
+@@ -384,6 +428,7 @@
+ snprintf(dir_name, sizeof(dir_name), "%s/%s/%s",
+ SYS_INFINIBAND, ca->ca_name, SYS_CA_PORTS_DIR);
+
++#if !(defined(__SVR4) && defined(__sun))
+ if (!(dir = opendir(dir_name)))
+ return -ENOENT;
+
+@@ -425,15 +470,91 @@
+ free(namelist);
+
+ closedir(dir);
++#else
++ {
+ struct ibv_device **root_dev_list, **dev_list = NULL;
+ struct ibv_context *ctx = NULL;
-+ struct ibv_port_attr port_attr;
++ struct ibv_device_attr dev_attr;
+ int num_dev;
++ int ret;
+
+ root_dev_list = dev_list = ibv_get_device_list(&num_dev);
+ if (!dev_list) {
+ IBWARN("No HCA devices found");
-+ goto clean;
++ return -EIO;
+ }
+
+ for (i = 0; i < num_dev; i++, dev_list++) {
@@ -132,92 +202,51 @@
+ if (i == num_dev) {
+ IBWARN("Could not find \"%s\"", ca_name);
+ ibv_free_device_list(root_dev_list);
++ ret = -EIO;
+ goto clean;
+ }
+
+ if (!(ctx = ibv_open_device(*dev_list))) {
+ IBWARN("failed to open device \"%s\"", ca_name);
+ ibv_free_device_list(root_dev_list);
++ ret = -EIO;
+ goto clean;
+ }
+
-+ if (ibv_query_port(ctx, portnum, &port_attr)) {
-+ IBWARN("Could not query \"%s\" port %d", ca_name,
-+ portnum);
++ /* Get port count */
++ memset(&dev_attr, 0, sizeof (struct ibv_device_attr));
++ if (ibv_query_device(ctx, &dev_attr) != 0) {
++ IBWARN("failed to query device \"%s\"", ca_name);
+ ibv_close_device(ctx);
+ ibv_free_device_list(root_dev_list);
++ ret = -EIO;
+ goto clean;
+ }
+
-+ port->pkeys =
-+ malloc(sizeof (uint16_t) * port_attr.pkey_tbl_len);
++ ca->numports = 0;
++ memset(ca->ports, 0, sizeof ca->ports);
+
-+ if (!port->pkeys) {
-+ IBWARN("Could not retrieve pkeys for \"%s\"", ca_name);
-+ ibv_close_device(ctx);
-+ ibv_free_device_list(root_dev_list);
-+ goto clean;
-+ }
-+
-+ /*
-+ * set high bit of port_num, and try get all pkeys in one go.
-+ */
-+ portnum |= 0x80;
-+ num_pkeys = ibv_query_pkey(ctx, portnum, port_attr.pkey_tbl_len,
-+ port->pkeys);
-+ if (num_pkeys != 0) {
-+ IBWARN("get_port: ibv_query_pkey() failed for \"%s\"",
-+ ca_name);
-+ ibv_close_device(ctx);
-+ ibv_free_device_list(root_dev_list);
-+ goto clean;
-+ }
-+ port->pkeys_size = port_attr.pkey_tbl_len;
-+ }
-+#else
- num_pkeys = scandir(port_dir, &namelist, check_for_digit_name, NULL);
- if (num_pkeys <= 0) {
- IBWARN("no pkeys found for %s:%u (at dir %s)...",
-@@ -193,6 +264,8 @@
- port->pkeys_size = num_pkeys;
- free(namelist);
- namelist = NULL;
-+#endif
++ for (portnum = 1; portnum <= dev_attr.phys_port_cnt; portnum++) {
+
- port_dir[len] = '\0';
-
- /* FIXME: handle gids */
-@@ -384,6 +457,7 @@
- snprintf(dir_name, sizeof(dir_name), "%s/%s/%s",
- SYS_INFINIBAND, ca->ca_name, SYS_CA_PORTS_DIR);
-
-+#if !(defined(__SVR4) && defined(__sun))
- if (!(dir = opendir(dir_name)))
- return -ENOENT;
-
-@@ -425,15 +499,41 @@
- free(namelist);
-
- closedir(dir);
-+#else
-+ // TODO: hardcoded 2 ports
-+ ca->numports = 0;
-+ memset(ca->ports, 0, sizeof ca->ports);
-+
-+ for (portnum = 1 /* HERE */; portnum <= 2 /* HERE */; portnum++) {
-+
-+ if (!(ca->ports[portnum] = calloc(1, sizeof(*ca->ports[portnum])))) {
-+ ret = -ENOMEM;
-+ goto clean;
++ if (!(ca->ports[portnum] = calloc(1,
++ sizeof(*ca->ports[portnum])))) {
++ ret = -ENOMEM;
++ ibv_close_device(ctx);
++ ibv_free_device_list(root_dev_list);
++ goto clean;
++ }
++ if (get_port(ca_name, dir_name, portnum, ctx,
++ ca->ports[portnum]) < 0) {
++ free(ca->ports[portnum]);
++ ca->ports[portnum] = NULL;
++ ret = -EIO;
++ ibv_close_device(ctx);
++ ibv_free_device_list(root_dev_list);
++ goto clean;
++ }
++ if (ca->numports < portnum)
++ ca->numports = portnum;
+ }
-+ if (get_port(ca_name, dir_name, portnum, ca->ports[portnum]) < 0) {
-+ free(ca->ports[portnum]);
-+ ca->ports[portnum] = NULL;
-+ ret = -EIO;
-+ goto clean;
-+ }
-+ if (ca->numports < portnum)
-+ ca->numports = portnum;
+ }
+#endif
+
@@ -237,7 +266,7 @@
release_ca(ca);
return ret;
-@@ -484,6 +584,11 @@
+@@ -484,6 +605,11 @@
int umad_init(void)
{
TRACE("umad_init");
@@ -249,7 +278,7 @@
if (sys_read_uint(IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, &abi_version) < 0) {
IBWARN
("can't read ABI version from %s/%s (%m): is ib_umad module loaded?",
-@@ -522,6 +627,28 @@
+@@ -522,6 +648,28 @@
int umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max)
{
@@ -278,7 +307,7 @@
struct dirent **namelist;
int n, i, j = 0;
-@@ -547,6 +674,7 @@
+@@ -547,6 +695,7 @@
}
if (n >= 0)
free(namelist);
@@ -286,3 +315,50 @@
return j;
}
+@@ -673,7 +822,46 @@
+ snprintf(dir_name, sizeof(dir_name), "%s/%s/%s",
+ SYS_INFINIBAND, ca_name, SYS_CA_PORTS_DIR);
+
++#if defined(__SVR4) && defined(__sun)
++ {
++ struct ibv_device **root_dev_list, **dev_list = NULL;
++ struct ibv_context *ctx = NULL;
++ int num_dev, ret, i;
++
++ root_dev_list = dev_list = ibv_get_device_list(&num_dev);
++ if (!dev_list) {
++ IBWARN("No HCA devices found");
++ return -EIO;
++ }
++
++ for (i = 0; i < num_dev; i++, dev_list++) {
++ if (strcmp(ibv_get_device_name(*dev_list), ca_name)
++ == 0) {
++ break;
++ }
++ }
++
++ if (i == num_dev) {
++ IBWARN("Could not find \"%s\"", ca_name);
++ ibv_free_device_list(root_dev_list);
++ return -EIO;
++ }
++
++ if (!(ctx = ibv_open_device(*dev_list))) {
++ IBWARN("failed to open device \"%s\"", ca_name);
++ ibv_free_device_list(root_dev_list);
++ return -EIO;
++ }
++
++ if ((ret = get_port(ca_name, dir_name, portnum, ctx, port)) != 0) {
++ ibv_close_device(ctx);
++ ibv_free_device_list(root_dev_list);
++ }
++ return ret;
++ }
++#else
+ return get_port(ca_name, dir_name, portnum, port);
++#endif
+ }
+
+ int umad_release_port(umad_port_t * port)