components/open-fabrics/libibumad/patches/base.patch
author boris.chiu@oracle.com
Fri, 23 Jan 2015 08:29:14 -0800
branchs11-update
changeset 3679 c058dce9610f
parent 900 63d3bf696d85
child 4395 94cac541ae13
permissions -rw-r--r--
18117487 saquery -m -t 50000 failed with multiple VFs created 18247164 SUNBT7167127 Some OFED tools print errors with a connect-x VPI card (userland) 18368329 Should use snprintf to convert numeric link_layer to string for ibstat to work 19187537 iberror() of open-fabrics dumps core because of buffer overrun 19195181 wrong handling of getaddrinfo() retval in open-fabrics dumps core 19448949 libibverbs cleanup incomplete

# This patch was developed in-house. Since it is Solaris-specific,
# it is not suitable for upstream.
#
diff -r -u /tmp/libibumad-1.3.7/Makefile.in libibumad-1.3.7/Makefile.in
--- /tmp/libibumad-1.3.7/Makefile.in	Mon Feb 14 06:18:00 2011
+++ libibumad-1.3.7/Makefile.in	Fri Feb 25 03:11:40 2011
@@ -367,8 +367,8 @@
 	  else :; fi; \
 	done; \
 	test -z "$$list2" || { \
-	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
-	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) -m 755 $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) -m 755 $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
 	}
 
 uninstall-libLTLIBRARIES:
diff -r -u /tmp/libibumad-1.3.7/include/infiniband/umad.h libibumad-1.3.7/include/infiniband/umad.h
--- /tmp/libibumad-1.3.7/include/infiniband/umad.h	Mon Feb 14 01:08:29 2011
+++ libibumad-1.3.7/include/infiniband/umad.h	Fri May 13 04:28:12 2011
@@ -45,7 +45,15 @@
 #endif				/* __cplusplus */
 
 BEGIN_C_DECLS
-#define UMAD_MAX_DEVICES 32
+/* To accomodate max. of 16 PCIe slots and 63 VFs per HCA, */
+/* we define	MAX_HCAS = (63VFs + 1PF) * 16HCAs */
+/* 		MAX_PORTS = MAX_HCAS * 2ports per HCA */
+#define MAX_HCAS	(64*16)
+#define MAX_PORTS	(MAX_HCAS*2)
+#define UMAD_MAX_DEVICES MAX_HCAS
+#define	UMAD_MAX_HCAS	MAX_HCAS
+#define	UMAD_MAX_PORTS	MAX_PORTS
+
 #define UMAD_ANY_PORT	0
 typedef struct ib_mad_addr {
 	uint32_t qpn;
@@ -94,9 +102,13 @@
 #define SYS_IB_MAD_PORT		"port"
 #define SYS_IB_MAD_DEV		"ibdev"
 
-#define UMAD_MAX_PORTS		64
+#define UMAD_MAX_PORTS		MAX_PORTS
 
+#if defined(__SVR4) && defined(__sun)
+#define	UMAD_DEV_DIR		"/dev/infiniband/ofs"
+#else
 #define UMAD_DEV_DIR		"/dev/infiniband"
+#endif
 
 #define SYS_CA_PORTS_DIR	"ports"
 
diff -r -u /tmp/libibumad-1.3.7/configure libibumad-1.3.7/configure
--- /tmp/libibumad-1.3.7/configure	Mon Feb 14 06:18:01 2011
+++ libibumad-1.3.7/configure	Thu Feb 24 11:27:18 2011
@@ -8713,6 +8713,7 @@
 	;;
       esac
       link_all_deplibs=yes
+      hardcode_libdir_flag_spec=
       ;;
 
     sunos4*)
diff -r -u /tmp/libibumad-1.3.7/src/sysfs.c libibumad-1.3.7/src/sysfs.c
--- /tmp/libibumad-1.3.7/src/sysfs.c	Mon Feb 14 01:08:29 2011
+++ libibumad-1.3.7/src/sysfs.c	Thu Feb 24 11:27:30 2011
@@ -46,9 +46,14 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#if !(defined(__SVR4) && defined(__sun))
 #include <endian.h>
 #include <byteswap.h>
+#endif
 #include <netinet/in.h>
+#if defined(__SVR4) && defined(__sun)
+#include <infiniband/driver.h>
+#endif
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define htonll(x) bswap_64(x)
@@ -70,6 +75,16 @@
 	char path[256], *s;
 	int fd, r;
 
+#if defined(__SVR4) && defined(__sun)
+	if ((r = ibv_read_sysfs_file(dir_name, file_name, str, max_len)) < 0) {
+		return -EINVAL;
+	}
+
+	str[(r < max_len) ? r : max_len - 1] = 0;
+
+	if ((s = strrchr(str, '\n')))
+		*s = 0;
+#else
 	snprintf(path, sizeof(path), "%s/%s", dir_name, file_name);
 
 	if ((fd = open(path, O_RDONLY)) < 0)
@@ -88,6 +103,7 @@
 		*s = 0;
 
 	close(fd);
+#endif
 	return 0;
 }
 
diff -r -u /tmp/libibumad-1.3.7/src/umad.c libibumad-1.3.7/src/umad.c
--- /tmp/libibumad-1.3.7/src/umad.c	Mon Feb 14 01:08:29 2011
+++ libibumad-1.3.7/src/umad.c	Fri May  6 05:18:47 2011
@@ -50,6 +50,10 @@
 
 #include "umad.h"
 
+#if defined(__SVR4) && defined(__sun)
+#include <infiniband/verbs.h>
+#endif
+
 #define IB_OPENIB_OUI                 (0x001405)
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
@@ -82,7 +86,7 @@
 extern int sys_read_uint64(char *dir_name, char *file_name, uint64_t * u);
 extern int sys_read_uint(char *dir_name, char *file_name, unsigned *u);
 
-#define IBWARN(fmt, args...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", getpid(), __func__, ## args)
+#define IBWARN(fmt, args...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", (int)getpid(), __func__, ## args)
 
 #define TRACE	if (umaddebug)	IBWARN
 #define DEBUG	if (umaddebug)	IBWARN
@@ -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_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");
+			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);
+			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;
+		}
+
+		/* 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;
+		}
+
+		ca->numports = 0;
+		memset(ca->ports, 0, sizeof ca->ports);
+
+		for (portnum = 1; portnum <= dev_attr.phys_port_cnt; portnum++) {
+
+		        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;
+		}
+	}
+#endif
+
 	put_ca(ca);
 	return 0;
 
 clean:
+#if !(defined(__SVR4) && defined(__sun))
 	for (i = 0; i < r; i++)
 		free(namelist[i]);
 	free(namelist);
+#endif
 error:
+#if !(defined(__SVR4) && defined(__sun))
 	closedir(dir);
+#endif
 	release_ca(ca);
 
 	return ret;
@@ -484,6 +605,11 @@
 int umad_init(void)
 {
 	TRACE("umad_init");
+	struct ibv_device **devlist = ibv_get_device_list(NULL);
+	if (devlist == NULL) {
+		IBWARN("No IB devices found");
+		return -1;
+	}
 	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 +648,28 @@
 
 int umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max)
 {
+#if defined(__SVR4) && defined(__sun)
+	struct ibv_device **devlist = ibv_get_device_list(NULL);
+	int j = 0;
+
+	TRACE("max %d", max);
+
+	if (devlist) {
+		while (devlist[j] && j < max) {
+			strncpy(cas[j], ibv_get_device_name(devlist[j]),
+						UMAD_CA_NAME_LEN);
+			j++;
+		}
+		ibv_free_device_list(devlist);
+		DEBUG("return %d cas", j);
+	}
+	if (j == 0 && max > 0) {
+		/* Is this still needed ? */
+		strncpy((char *)cas, def_ca_name, UMAD_CA_NAME_LEN);
+		DEBUG("return 1 ca");
+		j = 1;
+	}
+#else
 	struct dirent **namelist;
 	int n, i, j = 0;
 
@@ -547,6 +695,7 @@
 	}
 	if (n >= 0)
 		free(namelist);
+#endif
 	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)