[openib-general] [PATCH][2/5] ib_get_dma_mr(): mthca implementation

Roland Dreier roland at topspin.com
Wed Oct 20 16:04:44 PDT 2004


Index: infiniband/hw/mthca/mthca_dev.h
===================================================================
--- infiniband/hw/mthca/mthca_dev.h	(revision 1023)
+++ infiniband/hw/mthca/mthca_dev.h	(working copy)
@@ -287,7 +287,7 @@
 void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
 
 int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
-			   struct mthca_mr *mr);
+			   u32 access, struct mthca_mr *mr);
 int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
 			u64 *buffer_list, int buffer_size_shift,
 			int list_len, u64 iova, u64 total_size,
Index: infiniband/hw/mthca/mthca_provider.c
===================================================================
--- infiniband/hw/mthca/mthca_provider.c	(revision 987)
+++ infiniband/hw/mthca/mthca_provider.c	(working copy)
@@ -398,6 +398,36 @@
 	return 0;
 }
 
+static inline u32 convert_access(int acc)
+{
+	return (acc & IB_ACCESS_REMOTE_ATOMIC ? MTHCA_MPT_FLAG_ATOMIC       : 0) |
+	       (acc & IB_ACCESS_REMOTE_WRITE  ? MTHCA_MPT_FLAG_REMOTE_WRITE : 0) |
+	       (acc & IB_ACCESS_REMOTE_READ   ? MTHCA_MPT_FLAG_REMOTE_READ  : 0) |
+	       (acc & IB_ACCESS_LOCAL_WRITE   ? MTHCA_MPT_FLAG_LOCAL_WRITE  : 0) |
+	       MTHCA_MPT_FLAG_LOCAL_READ;
+}
+
+static struct ib_mr *mthca_get_dma_mr(struct ib_pd *pd, int acc)
+{
+	struct mthca_mr *mr;
+	int err;
+
+	mr = kmalloc(sizeof *mr, GFP_KERNEL);
+	if (!mr)
+		return ERR_PTR(-ENOMEM);
+
+	err = mthca_mr_alloc_notrans(to_mdev(pd->device),
+				     to_mpd(pd)->pd_num,
+				     convert_access(acc), mr);
+
+	if (err) {
+		kfree(mr);
+		return ERR_PTR(err);
+	}
+
+	return &mr->ibmr;
+}
+
 static struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
 				       struct ib_phys_buf *buffer_list,
 				       int                 num_phys_buf,
@@ -410,8 +440,7 @@
 	u64 mask;
 	int shift;
 	int npages;
-	u32 access;
-	int err = -ENOMEM;
+	int err;
 	int i, j, n;
 
 	/* First check that we have enough alignment */
@@ -475,13 +504,6 @@
 		     ++j)
 			page_list[n++] = buffer_list[i].addr + ((u64) j << shift);
 
-	access =
-		(acc & IB_ACCESS_REMOTE_ATOMIC ? MTHCA_MPT_FLAG_ATOMIC       : 0) |
-		(acc & IB_ACCESS_REMOTE_WRITE  ? MTHCA_MPT_FLAG_REMOTE_WRITE : 0) |
-		(acc & IB_ACCESS_REMOTE_READ   ? MTHCA_MPT_FLAG_REMOTE_READ  : 0) |
-		(acc & IB_ACCESS_LOCAL_WRITE   ? MTHCA_MPT_FLAG_LOCAL_WRITE  : 0) |
-		MTHCA_MPT_FLAG_LOCAL_READ;
-
 	mthca_dbg(to_mdev(pd->device), "Registering memory at %llx (iova %llx) "
 		  "in PD %x; shift %d, npages %d.\n",
 		  (unsigned long long) buffer_list[0].addr,
@@ -493,15 +515,13 @@
 				  to_mpd(pd)->pd_num,
 				  page_list, shift, npages,
 				  *iova_start, total_size,
-				  access, mr);
+				  convert_access(acc), mr);
 
 	if (err) {
 		kfree(mr);
-		mr = ERR_PTR(err);
-		goto out;
+		return ERR_PTR(err);
 	}
 
-out:
 	kfree(page_list);
 	return &mr->ibmr;
 }
@@ -576,6 +596,7 @@
 	dev->ib_dev.destroy_cq           = mthca_destroy_cq;
 	dev->ib_dev.poll_cq              = mthca_poll_cq;
 	dev->ib_dev.req_notify_cq        = mthca_req_notify_cq;
+	dev->ib_dev.get_dma_mr           = mthca_get_dma_mr;
 	dev->ib_dev.reg_phys_mr          = mthca_reg_phys_mr;
 	dev->ib_dev.dereg_mr             = mthca_dereg_mr;
 	dev->ib_dev.attach_mcast         = mthca_multicast_attach;
Index: infiniband/hw/mthca/mthca_pd.c
===================================================================
--- infiniband/hw/mthca/mthca_pd.c	(revision 915)
+++ infiniband/hw/mthca/mthca_pd.c	(working copy)
@@ -37,7 +37,10 @@
 	if (pd->pd_num == -1)
 		return -ENOMEM;
 
-	err = mthca_mr_alloc_notrans(dev, pd->pd_num, &pd->ntmr);
+	err = mthca_mr_alloc_notrans(dev, pd->pd_num,
+				     MTHCA_MPT_FLAG_LOCAL_READ |
+				     MTHCA_MPT_FLAG_LOCAL_WRITE,
+				     &pd->ntmr);
 	if (err)
 		mthca_free(&dev->pd_table.alloc, pd->pd_num);
 
Index: infiniband/hw/mthca/mthca_mr.c
===================================================================
--- infiniband/hw/mthca/mthca_mr.c	(revision 915)
+++ infiniband/hw/mthca/mthca_mr.c	(working copy)
@@ -108,7 +108,7 @@
 }
 
 int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
-			   struct mthca_mr *mr)
+			   u32 access, struct mthca_mr *mr)
 {
 	void *mailbox;
 	struct mthca_mpt_entry *mpt_entry;
@@ -133,10 +133,9 @@
 
 	mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS     |
 				       MTHCA_MPT_FLAG_MIO         |
-				       MTHCA_MPT_FLAG_LOCAL_WRITE |
-				       MTHCA_MPT_FLAG_LOCAL_READ  |
 				       MTHCA_MPT_FLAG_PHYSICAL    |
-				       MTHCA_MPT_FLAG_REGION);
+				       MTHCA_MPT_FLAG_REGION      |
+				       access);
 	mpt_entry->page_size = 0;
 	mpt_entry->key       = cpu_to_be32(mr->ibmr.lkey);
 	mpt_entry->pd        = cpu_to_be32(pd);




More information about the general mailing list