From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/infiniband/hw/mlx5/mr.c

Change-Id: I0f3c1f3246c4113398ca4e550aad74521a637b18
---
 drivers/infiniband/hw/mlx5/mr.c | 56 ++++++++++++++++++++++++++-------
 1 file changed, 45 insertions(+), 11 deletions(-)

--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -40,7 +40,9 @@
 #include <linux/device.h>
 #include <linux/sysfs.h>
 #include <linux/dma-buf.h>
+#ifdef HAVE_DMA_RESV_H
 #include <linux/dma-resv.h>
+#endif
 #include <rdma/ib_umem_odp.h>
 #include "dm.h"
 #include "mlx5_ib.h"
@@ -618,10 +620,17 @@ static struct attribute *order_default_a
 	NULL
 };
 
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
 ATTRIBUTE_GROUPS(order_default);
-static const struct kobj_type order_type = {
-	.sysfs_ops     = &order_sysfs_ops,
-	.default_groups = order_default_groups
+#endif
+
+static struct kobj_type order_type = {
+        .sysfs_ops     = &order_sysfs_ops,
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
+        .default_groups = order_default_groups
+#else
+        .default_attrs = order_default_attrs
+#endif
 };
 
 static bool someone_releasing(struct mlx5_mkey_cache *cache)
@@ -925,8 +934,7 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(s
 
 static void delay_time_func(struct timer_list *t)
 {
-	struct mlx5_ib_dev *dev = from_timer(dev, t, delay_timer);
-
+        struct mlx5_ib_dev *dev = from_timer(dev, t, delay_timer);
 	WRITE_ONCE(dev->fill_delay, 0);
 }
 
@@ -1494,6 +1502,7 @@ static struct ib_mr *create_real_mr(stru
 	return &mr->ibmr;
 }
 
+#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
 static struct ib_mr *create_user_odp_mr(struct ib_pd *pd, u64 start, u64 length,
 					u64 iova, int access_flags,
 					struct ib_udata *udata)
@@ -1515,7 +1524,7 @@ static struct ib_mr *create_user_odp_mr(
 		if (!(dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT))
 			return ERR_PTR(-EINVAL);
 
-		mr = mlx5_ib_alloc_implicit_mr(to_mpd(pd), access_flags);
+		mr = mlx5_ib_alloc_implicit_mr(to_mpd(pd), udata, access_flags);
 		if (IS_ERR(mr))
 			return ERR_CAST(mr);
 		return &mr->ibmr;
@@ -1525,8 +1534,12 @@ static struct ib_mr *create_user_odp_mr(
 	if (!mlx5r_umr_can_load_pas(dev, length))
 		return ERR_PTR(-EINVAL);
 
+#ifdef HAVE_MMU_INTERVAL_NOTIFIER
 	odp = ib_umem_odp_get(&dev->ib_dev, start, length, access_flags,
 			      &mlx5_mn_ops);
+#else
+	odp = ib_umem_odp_get(udata, start, length, access_flags);
+#endif
 	if (IS_ERR(odp))
 		return ERR_CAST(odp);
 
@@ -1551,6 +1564,7 @@ err_dereg_mr:
 	mlx5_ib_dereg_mr(&mr->ibmr, NULL);
 	return ERR_PTR(err);
 }
+#endif
 
 struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 				  u64 iova, int access_flags,
@@ -1570,16 +1584,24 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct
 	if (err)
 		return ERR_PTR(err);
 
+#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
 	if ((access_flags & IB_ACCESS_ON_DEMAND) && (dev->profile != &raw_eth_profile))
 		return create_user_odp_mr(pd, start, length, iova, access_flags,
 					  udata);
+#endif
+#ifdef HAVE_MMU_INTERVAL_NOTIFIER
 	umem = ib_umem_get_peer(&dev->ib_dev, start, length, access_flags,
+#else
+	umem = ib_umem_get_peer(udata, start, length, access_flags,
+#endif
 				IB_PEER_MEM_INVAL_SUPP);
+
 	if (IS_ERR(umem))
 		return ERR_CAST(umem);
 	return create_real_mr(pd, umem, iova, access_flags);
 }
 
+#ifdef HAVE_DMA_BUF_DYNAMIC_ATTACH_GET_4_PARAMS
 static void mlx5_ib_dmabuf_invalidate_cb(struct dma_buf_attachment *attach)
 {
 	struct ib_umem_dmabuf *umem_dmabuf = attach->importer_priv;
@@ -1595,10 +1617,11 @@ static void mlx5_ib_dmabuf_invalidate_cb
 }
 
 static struct dma_buf_attach_ops mlx5_ib_dmabuf_attach_ops = {
+#ifdef HAVE_DMA_BUF_ATTACH_OPS_ALLOW_PEER2PEER
 	.allow_peer2peer = 1,
+#endif
 	.move_notify = mlx5_ib_dmabuf_invalidate_cb,
 };
-
 struct ib_mr *mlx5_ib_reg_user_mr_dmabuf(struct ib_pd *pd, u64 offset,
 					 u64 length, u64 virt_addr,
 					 int fd, int access_flags,
@@ -1658,6 +1681,7 @@ err_dereg_mr:
 	mlx5_ib_dereg_mr(&mr->ibmr, NULL);
 	return ERR_PTR(err);
 }
+#endif
 
 /*
  * True if the change in access flags can be done via UMR, only some access
@@ -1822,8 +1846,11 @@ struct ib_mr *mlx5_ib_rereg_user_mr(stru
 	    can_use_umr_rereg_access(dev, mr->access_flags, new_access_flags)) {
 		struct ib_umem *new_umem;
 		unsigned long page_size;
-
+#ifdef HAVE_MMU_INTERVAL_NOTIFIER
 		new_umem = ib_umem_get_peer(&dev->ib_dev, start, length,
+#else
+		new_umem = ib_umem_get_peer(udata, start, length,
+#endif
 					    new_access_flags,
 					    IB_PEER_MEM_INVAL_SUPP);
 		if (IS_ERR(new_umem))
@@ -2910,10 +2937,17 @@ static struct attribute *cache_default_a
 	NULL
 };
 
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
 ATTRIBUTE_GROUPS(cache_default);
-static const struct kobj_type cache_type = {
-	.sysfs_ops     = &cache_sysfs_ops,
-	.default_groups = cache_default_groups
+#endif
+
+static struct kobj_type cache_type = {
+        .sysfs_ops     = &cache_sysfs_ops,
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
+        .default_groups = cache_default_groups
+#else
+        .default_attrs = cache_default_attrs
+#endif
 };
 
 static int mlx5_mkey_cache_sysfs_init(struct mlx5_ib_dev *dev)
