File libmlx4-Remove_compatibility_with_libibverbs-1.1.7.patch of Package libmlx4-rdmav2

From bcc5d064268073cb996bdbac1ae36728db3b2c96 Mon Sep 17 00:00:00 2001
From: Roland Dreier <roland@purestorage.com>
Date: Wed, 1 Jan 2014 00:23:43 -0800
Subject: [PATCH 2/4] Remove compatibility with libibverbs < 1.1.7

Since the changes to add verbs extensions / XRC support will break
compatibility with libibverbs < 1.1.8, take this chance to strip out all
the backwards compatibility code that won't make any sense once we do that.

Signed-off-by: Roland Dreier <roland@purestorage.com>
---
 Makefile.am     |   19 ++++++-------------
 configure.ac    |   20 ++++++++++----------
 libmlx4.spec.in |    2 +-
 src/buf.c       |   19 -------------------
 src/mlx4.c      |   22 ----------------------
 src/mlx4.h      |    4 ----
 src/verbs.c     |   28 +++++++---------------------
 7 files changed, 24 insertions(+), 90 deletions(-)

Index: libmlx4-1.0.5/Makefile.am
===================================================================
--- libmlx4-1.0.5.orig/Makefile.am	2011-03-08 18:56:59.000000000 +0100
+++ libmlx4-1.0.5/Makefile.am	2014-03-04 12:01:31.987367063 +0100
@@ -5,19 +5,12 @@ mlx4_version_script = @MLX4_VERSION_SCRI
 MLX4_SOURCES = src/buf.c src/cq.c src/dbrec.c src/mlx4.c src/qp.c \
     src/srq.c src/verbs.c
 
-if HAVE_IBV_DEVICE_LIBRARY_EXTENSION
-    lib_LTLIBRARIES = src/libmlx4.la
-    src_libmlx4_la_SOURCES = $(MLX4_SOURCES)
-    src_libmlx4_la_LDFLAGS = -avoid-version -release @IBV_DEVICE_LIBRARY_EXTENSION@ \
-        $(mlx4_version_script)
-    mlx4confdir = $(sysconfdir)/libibverbs.d
-    mlx4conf_DATA = mlx4.driver
-else
-    mlx4libdir = $(libdir)/infiniband
-    mlx4lib_LTLIBRARIES = src/mlx4.la
-    src_mlx4_la_SOURCES = $(MLX4_SOURCES)
-    src_mlx4_la_LDFLAGS = -avoid-version -module $(mlx4_version_script)
-endif
+lib_LTLIBRARIES = src/libmlx4.la
+src_libmlx4_la_SOURCES = $(MLX4_SOURCES)
+src_libmlx4_la_LDFLAGS = -avoid-version -release @IBV_DEVICE_LIBRARY_EXTENSION@ \
+    $(mlx4_version_script)
+mlx4confdir = $(sysconfdir)/libibverbs.d
+mlx4conf_DATA = mlx4.driver
 
 EXTRA_DIST = src/doorbell.h src/mlx4.h src/mlx4-abi.h src/wqe.h \
     src/mlx4.map libmlx4.spec.in mlx4.driver
Index: libmlx4-1.0.5/configure.ac
===================================================================
--- libmlx4-1.0.5.orig/configure.ac	2013-05-30 19:38:36.000000000 +0200
+++ libmlx4-1.0.5/configure.ac	2014-03-04 12:01:45.850045975 +0100
@@ -45,21 +45,20 @@ dnl Checks for typedefs, structures, and
 AC_C_CONST
 AC_CHECK_SIZEOF(long)
 
+dnl Checks for library functions
+AC_CHECK_FUNC(ibv_register_driver, [],
+    AC_MSG_ERROR([ibv_register_driver() not found.  libmlx4 requires libibverbs >= 1.1.7.]))
+
 AC_CACHE_CHECK([for IBV_QPT_RAW_PACKET],
                [ac_cv_ibv_qpt_raw_packet],
-               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <infiniband/verbs.h>],
                                                    [enum ibv_qp_type qpt = IBV_QPT_RAW_PACKET;])],
                                    [ac_cv_ibv_qpt_raw_packet=yes],
                                    [ac_cv_ibv_qpt_raw_packet=no])])
-if test $ac_cv_ibv_qpt_raw_packet = yes; then
-    AC_DEFINE([HAVE_IBV_QPT_RAW_PACKET], 1, [libibverbs has raw packet QP support])
+if test $ac_cv_ibv_qpt_raw_packet = no; then
+    AC_MSG_ERROR([IBV_QPT_RAW_PACKET not found.  libmlx4 requires libibverbs >= 1.1.7.])
 fi
 
-dnl Checks for library functions
-AC_CHECK_FUNC(ibv_read_sysfs_file, [],
-    AC_MSG_ERROR([ibv_read_sysfs_file() not found.  libmlx4 requires libibverbs >= 1.0.3.]))
-AC_CHECK_FUNCS(ibv_dontfork_range ibv_dofork_range ibv_register_driver)
-
 dnl Now check if for libibverbs 1.0 vs 1.1
 dummy=if$$
 cat <<IBV_VERSION > $dummy.c
@@ -68,8 +67,9 @@ IBV_DEVICE_LIBRARY_EXTENSION
 IBV_VERSION
 IBV_DEVICE_LIBRARY_EXTENSION=`$CC $CPPFLAGS -E $dummy.c 2> /dev/null | tail -1`
 rm -f $dummy.c
-AM_CONDITIONAL(HAVE_IBV_DEVICE_LIBRARY_EXTENSION,
-    test $IBV_DEVICE_LIBRARY_EXTENSION != IBV_DEVICE_LIBRARY_EXTENSION)
+if test $IBV_DEVICE_LIBRARY_EXTENSION = IBV_DEVICE_LIBRARY_EXTENSION; then
+    AC_MSG_ERROR([libibverbs does not define IBV_DEVICE_LIBRARY_EXTENSION.])
+fi
 AC_SUBST(IBV_DEVICE_LIBRARY_EXTENSION)
 
 AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
Index: libmlx4-1.0.5/libmlx4.spec.in
===================================================================
--- libmlx4-1.0.5.orig/libmlx4.spec.in	2013-05-30 19:39:14.000000000 +0200
+++ libmlx4-1.0.5/libmlx4.spec.in	2014-03-04 12:01:45.850045975 +0100
@@ -9,7 +9,7 @@ Url: http://openfabrics.org/
 Source: http://openfabrics.org/downloads/mlx4/libmlx4-1.0.5.tar.gz
 BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 
-BuildRequires: libibverbs-devel >= 1.1-0.1.rc2
+BuildRequires: libibverbs-devel >= 1.1.7
 
 %description
 libmlx4 provides a device-specific userspace driver for Mellanox
Index: libmlx4-1.0.5/src/buf.c
===================================================================
--- libmlx4-1.0.5.orig/src/buf.c	2011-03-08 18:56:59.000000000 +0100
+++ libmlx4-1.0.5/src/buf.c	2014-03-04 12:01:45.778047643 +0100
@@ -40,25 +40,6 @@
 
 #include "mlx4.h"
 
-#if !(defined(HAVE_IBV_DONTFORK_RANGE) && defined(HAVE_IBV_DOFORK_RANGE))
-
-/*
- * If libibverbs isn't exporting these functions, then there's no
- * point in doing it here, because the rest of libibverbs isn't going
- * to be fork-safe anyway.
- */
-static int ibv_dontfork_range(void *base, size_t size)
-{
-	return 0;
-}
-
-static int ibv_dofork_range(void *base, size_t size)
-{
-	return 0;
-}
-
-#endif /* HAVE_IBV_DONTFORK_RANGE && HAVE_IBV_DOFORK_RANGE */
-
 int mlx4_alloc_buf(struct mlx4_buf *buf, size_t size, int page_size)
 {
 	int ret;
Index: libmlx4-1.0.5/src/mlx4.c
===================================================================
--- libmlx4-1.0.5.orig/src/mlx4.c	2013-04-03 20:21:44.000000000 +0200
+++ libmlx4-1.0.5/src/mlx4.c	2014-03-04 12:01:45.850045975 +0100
@@ -42,10 +42,6 @@
 #include <pthread.h>
 #include <string.h>
 
-#ifndef HAVE_IBV_REGISTER_DRIVER
-#include <sysfs/libsysfs.h>
-#endif
-
 #include "mlx4.h"
 #include "mlx4-abi.h"
 
@@ -268,25 +264,7 @@ found:
 	return &dev->ibv_dev;
 }
 
-#ifdef HAVE_IBV_REGISTER_DRIVER
 static __attribute__((constructor)) void mlx4_register_driver(void)
 {
 	ibv_register_driver("mlx4", mlx4_driver_init);
 }
-#else
-/*
- * Export the old libsysfs sysfs_class_device-based driver entry point
- * if libibverbs does not export an ibv_register_driver() function.
- */
-struct ibv_device *openib_driver_init(struct sysfs_class_device *sysdev)
-{
-	int abi_version = 0;
-	char value[8];
-
-	if (ibv_read_sysfs_file(sysdev->path, "abi_version",
-				value, sizeof value) > 0)
-		abi_ver = strtol(value, NULL, 10);
-
-	return mlx4_driver_init(sysdev->path, abi_version);
-}
-#endif /* HAVE_IBV_REGISTER_DRIVER */
Index: libmlx4-1.0.5/src/mlx4.h
===================================================================
--- libmlx4-1.0.5.orig/src/mlx4.h	2013-04-03 20:40:27.000000000 +0200
+++ libmlx4-1.0.5/src/mlx4.h	2014-03-04 12:01:45.850045975 +0100
@@ -83,10 +83,6 @@
 
 #define PFX		"mlx4: "
 
-#ifndef HAVE_IBV_QPT_RAW_PACKET
-#define IBV_QPT_RAW_PACKET		8
-#endif
-
 enum {
 	MLX4_STAT_RATE_OFFSET		= 5
 };
Index: libmlx4-1.0.5/src/verbs.c
===================================================================
--- libmlx4-1.0.5.orig/src/verbs.c	2014-03-04 12:01:31.952367874 +0100
+++ libmlx4-1.0.5/src/verbs.c	2014-03-04 12:01:45.778047643 +0100
@@ -112,24 +112,16 @@ struct ibv_mr *mlx4_reg_mr(struct ibv_pd
 {
 	struct ibv_mr *mr;
 	struct ibv_reg_mr cmd;
+	struct ibv_reg_mr_resp resp;
 	int ret;
 
 	mr = malloc(sizeof *mr);
 	if (!mr)
 		return NULL;
 
-#ifdef IBV_CMD_REG_MR_HAS_RESP_PARAMS
-	{
-		struct ibv_reg_mr_resp resp;
-
-		ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr,
-				     access, mr, &cmd, sizeof cmd,
-				     &resp, sizeof resp);
-	}
-#else
-	ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, access, mr,
-			     &cmd, sizeof cmd);
-#endif
+	ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr,
+			     access, mr, &cmd, sizeof cmd,
+			     &resp, sizeof resp);
 	if (ret) {
 		free(mr);
 		return NULL;
@@ -227,6 +219,7 @@ int mlx4_resize_cq(struct ibv_cq *ibcq,
 {
 	struct mlx4_cq *cq = to_mcq(ibcq);
 	struct mlx4_resize_cq cmd;
+	struct ibv_resize_cq_resp resp;
 	struct mlx4_buf buf;
 	int old_cqe, outst_cqe, ret;
 
@@ -256,15 +249,8 @@ int mlx4_resize_cq(struct ibv_cq *ibcq,
 	old_cqe = ibcq->cqe;
 	cmd.buf_addr = (uintptr_t) buf.buf;
 
-#ifdef IBV_CMD_RESIZE_CQ_HAS_RESP_PARAMS
-	{
-		struct ibv_resize_cq_resp resp;
-		ret = ibv_cmd_resize_cq(ibcq, cqe - 1, &cmd.ibv_cmd, sizeof cmd,
-					&resp, sizeof resp);
-	}
-#else
-	ret = ibv_cmd_resize_cq(ibcq, cqe - 1, &cmd.ibv_cmd, sizeof cmd);
-#endif
+	ret = ibv_cmd_resize_cq(ibcq, cqe - 1, &cmd.ibv_cmd, sizeof cmd,
+				&resp, sizeof resp);
 	if (ret) {
 		mlx4_free_buf(&buf);
 		goto out;