From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: include/rdma/ib_verbs.h

Change-Id: I110a02ea48f0476b6d20223bb55337fc858b33e0
---
 include/rdma/ib_verbs.h | 69 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)

--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -12,6 +12,8 @@
 #ifndef IB_VERBS_H
 #define IB_VERBS_H
 
+#include "../../compat/config.h"
+
 #include <linux/ethtool.h>
 #include <linux/types.h>
 #include <linux/device.h>
@@ -84,10 +86,13 @@ void ibdev_notice(const struct ib_device
 __printf(2, 3) __cold
 void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
 
-#if defined(CONFIG_DYNAMIC_DEBUG) || \
+#if defined(CONFIG_DYNAMIC_DEBUG) && defined(dynamic_ibdev_dbg)
+#define ibdev_dbg(__dev, format, args...)                       \
+	        dynamic_ibdev_dbg(__dev, format, ##args)
+#elif defined(DEBUG)
 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
 #define ibdev_dbg(__dev, format, args...)                       \
-	dynamic_ibdev_dbg(__dev, format, ##args)
+	        ibdev_printk(KERN_DEBUG, __dev, format, ##args)
 #else
 __printf(2, 3) __cold
 static inline
@@ -1543,7 +1548,12 @@ struct ib_ucontext {
 	struct ib_device       *device;
 	struct ib_uverbs_file  *ufile;
 
-	struct ib_rdmacg_object	cg_obj;
+#ifndef HAVE_MMU_NOTIFIER_OPS_HAS_FREE_NOTIFIER
+	struct mutex per_mm_list_lock;
+	struct list_head per_mm_list;
+#endif
+
+       struct ib_rdmacg_object	cg_obj;
 	/*
 	 * Implementation details of the RDMA core, don't use in drivers:
 	 */
@@ -1631,7 +1641,9 @@ struct ib_cq {
 	struct ib_wc		*wc;
 	struct list_head        pool_entry;
 	union {
+#if IS_ENABLED(CONFIG_IRQ_POLL)
 		struct irq_poll		iop;
+#endif
 		struct work_struct	work;
 	};
 	struct workqueue_struct *comp_wq;
@@ -2226,7 +2238,9 @@ struct ib_port_data {
 	struct ib_port_cache cache;
 
 	struct net_device __rcu *netdev;
+#ifdef HAVE_NETDEV_PUT_AND_HOLD
 	netdevice_tracker netdev_tracker;
+#endif
 	struct hlist_node ndev_hash_link;
 	struct rdma_port_counter port_counter;
 	struct ib_port *sysfs;
@@ -2539,6 +2553,10 @@ struct ib_device_ops {
 			       struct ib_mr_status *mr_status);
 	int (*alloc_mw)(struct ib_mw *mw, struct ib_udata *udata);
 	int (*dealloc_mw)(struct ib_mw *mw);
+#ifndef HAVE_MMU_INTERVAL_NOTIFIER
+	void (*invalidate_range)(struct ib_umem_odp *umem_odp,
+				 unsigned long start, unsigned long end);
+#endif
 	int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
 	int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
 	int (*alloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
@@ -4097,7 +4115,11 @@ static inline bool ib_dma_pci_p2p_dma_su
 	if (ib_uses_virt_dma(dev))
 		return false;
 
+#ifdef HAVE_DMA_PCI_P2PDMA_SUPPORTED
 	return dma_pci_p2pdma_supported(dev->dma_device);
+#else
+	return false;
+#endif
 }
 
 /**
@@ -4243,6 +4265,7 @@ static inline void ib_dma_unmap_sg_attrs
  * @direction: The direction of the DMA
  * @attrs: Optional DMA attributes for the map operation
  */
+#ifdef HAVE_DMA_MAP_SGTABLE
 static inline int ib_dma_map_sgtable_attrs(struct ib_device *dev,
 					   struct sg_table *sgt,
 					   enum dma_data_direction direction,
@@ -4268,6 +4291,7 @@ static inline void ib_dma_unmap_sgtable_
 	if (!ib_uses_virt_dma(dev))
 		dma_unmap_sgtable(dev->dma_device, sgt, direction, dma_attrs);
 }
+#endif
 
 /**
  * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
@@ -4431,6 +4455,45 @@ struct ib_xrcd *ib_alloc_xrcd_user(struc
 				   struct inode *inode, struct ib_udata *udata);
 int ib_dealloc_xrcd_user(struct ib_xrcd *xrcd, struct ib_udata *udata);
 
+#ifdef HAVE_ETHTOOL_GET_SET_SETTINGS
+static inline int ib_active_speed_enum_to_rate(enum ib_port_speed active_speed,
+                                               int *rate,
+                                               char **speed)
+{
+        switch (active_speed) {
+        case IB_SPEED_DDR:
+                *speed = " DDR";
+                *rate = 50;
+                break;
+        case IB_SPEED_QDR:
+                *speed = " QDR";
+                *rate = 100;
+                break;
+        case IB_SPEED_FDR10:
+                *speed = " FDR10";
+                *rate = 100;
+                break;
+        case IB_SPEED_FDR:
+                *speed = " FDR";
+                *rate = 140;
+                break;
+        case IB_SPEED_EDR:
+                *speed = " EDR";
+                *rate = 250;
+                break;
+        case IB_SPEED_HDR:
+                *speed = " HDR";
+                *rate = 500;
+                break;
+        case IB_SPEED_SDR:
+        default:                /* default to SDR for invalid rates */
+                *rate = 25;
+                break;
+        }
+        return 0;
+}
+#endif
+
 static inline int ib_check_mr_access(struct ib_device *ib_dev,
 				     unsigned int flags)
 {
