IB/rdmavt: Move memory registration into rdmavt

Use the memory registration routines in hfi1 and move them to rdmavt.
A follow on patch will address removing the duplicated code in the
hfi1 and qib drivers.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
diff --git a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
index b44ac17..9a47957 100644
--- a/include/rdma/rdma_vt.h
+++ b/include/rdma/rdma_vt.h
@@ -391,6 +391,7 @@
 	 * Anything driver specific that is not covered by props
 	 * For instance special module parameters. Goes here.
 	 */
+	unsigned int lkey_table_size;
 };
 
 /*
@@ -416,6 +417,8 @@
 };
 
 struct rvt_dev_info {
+	struct ib_device ibdev; /* Keep this first. Nothing above here */
+
 	/*
 	 * Prior to calling for registration the driver will be responsible for
 	 * allocating space for this structure.
@@ -423,7 +426,6 @@
 	 * The driver will also be responsible for filling in certain members of
 	 * dparms.props
 	 */
-	struct ib_device ibdev;
 
 	/* Driver specific properties */
 	struct rvt_driver_params dparms;
@@ -453,7 +455,22 @@
 	return  container_of(ibdev, struct rvt_dev_info, ibdev);
 }
 
+static inline void rvt_put_mr(struct rvt_mregion *mr)
+{
+	if (unlikely(atomic_dec_and_test(&mr->refcount)))
+		complete(&mr->comp);
+}
+
+static inline void rvt_get_mr(struct rvt_mregion *mr)
+{
+	atomic_inc(&mr->refcount);
+}
+
 int rvt_register_device(struct rvt_dev_info *rvd);
 void rvt_unregister_device(struct rvt_dev_info *rvd);
+int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
+		u32 len, u64 vaddr, u32 rkey, int acc);
+int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
+		struct rvt_sge *isge, struct ib_sge *sge, int acc);
 
 #endif          /* DEF_RDMA_VT_H */