[openib-general] [PATCH] GSI: Use ib_reg_phys_mr rather than ib_reg_mr

Hal Rosenstock halr at voltaire.com
Mon Aug 23 09:34:11 PDT 2004


Use ib_reg_phys_mr rather than ib_reg_mr as ib_reg_mr is no longer a
kernel supported function

Index: access/ib_verbs_priv.h
===================================================================
--- access/ib_verbs_priv.h	(revision 634)
+++ access/ib_verbs_priv.h	(working copy)
@@ -38,8 +38,4 @@
 			 int proc_mad_opts,
 			 struct mad_t *mad_in, struct mad_t *mad_out);
 
-/* temporary !!! */
-struct ib_mr *ib_reg_mr(struct ib_pd *pd,
-			void *addr,
-			u64 size, int mr_access_flags, u32 * lkey, u32 * rkey);
 #endif				/* IB_VERBS_PRIV_H */
Index: access/TODO
===================================================================
--- access/TODO	(revision 647)
+++ access/TODO	(working copy)
@@ -1,6 +1,5 @@
-8/13/04
+8/23/04
 
-Replace ib_reg_mr with ib_reg_phys_mr
 Makefile needs to use standard kbuild 
 Migrate from /proc to /sysfs
 
Index: access/gsi_main.c
===================================================================
--- access/gsi_main.c	(revision 669)
+++ access/gsi_main.c	(working copy)
@@ -60,6 +60,7 @@
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
 #include <linux/smp_lock.h>
+#include <linux/pci.h>
 #include <asm/io.h>
 #include <asm/atomic.h>
 
@@ -353,6 +354,10 @@
 		dtgrm =
 		    (struct gsi_dtgrm_priv_st *) hca->rcv_posted_dtgrm_list.
 		    next;
+		pci_unmap_single(hca->handle->dma_device,
+				 pci_unmap_addr(&dtgrm->grh, mapping),
+				 MAD_BLOCK_SIZE + IB_GRH_LEN, 
+				 PCI_DMA_FROMDEVICE);
 		v_list_del((struct list_head *) dtgrm);
 
 		gsi_dtgrm_pool_put((struct gsi_dtgrm_t *) dtgrm);
@@ -373,7 +378,9 @@
 		dtgrm_priv =
 		    (struct gsi_dtgrm_priv_st *) class_info->
 		    snd_posted_dtgrm_list.next;
-
+		pci_unmap_single(class_info->hca->handle->dma_device,
+				 pci_unmap_addr(&dtgrm_priv->mad, mapping),
+				 MAD_BLOCK_SIZE, PCI_DMA_TODEVICE);
 		/*
 		 * Remove the datagram from the posted datagram list
 		 * class_info->snd_posted_dtgrm_list
@@ -458,7 +465,6 @@
 gsi_post_receive_dtgrms(struct gsi_hca_info_st *hca)
 {
 	int ret;
-	u32 rkey;
 	struct ib_recv_wr wr;
 	struct ib_recv_wr *bad_wr;
 	struct gsi_dtgrm_priv_st *dtgrm_priv;
@@ -470,24 +476,19 @@
 	 */
 	while (gsi_dtgrm_pool_get(hca->rcv_dtgrm_pool,
 				  (struct gsi_dtgrm_t **) &dtgrm_priv) == 0) {
-		dtgrm_priv->v_mem_h = ib_reg_mr(hca->pd,
-						dtgrm_priv->grh,
-						MAD_BLOCK_SIZE + IB_GRH_LEN,
-						IB_ACCESS_LOCAL_WRITE,
-						&dtgrm_priv->sg.lkey, &rkey);
-		if (IS_ERR(dtgrm_priv->v_mem_h)) {
-			printk(KERN_ERR \
-				 "Could not get general memory region\n");
-			ret = PTR_ERR(dtgrm_priv->v_mem_h);
-			goto error1;
-		}
 
 		/*              
 		 * Setup scatter-gather list
 		 */
-		dtgrm_priv->sg.addr = (unsigned long) dtgrm_priv->grh;
+		dtgrm_priv->sg.addr = pci_map_single(hca->handle->dma_device,
+						     dtgrm_priv->grh,
+						     MAD_BLOCK_SIZE + IB_GRH_LEN,
+						     PCI_DMA_FROMDEVICE);
 		dtgrm_priv->sg.length = MAD_BLOCK_SIZE + IB_GRH_LEN;
+		dtgrm_priv->sg.lkey = hca->mr->lkey;
 
+		pci_unmap_addr_set(dtgrm_priv->grh, mapping, dtgrm_priv->sg.addr);
+
 		memset(&wr, 0, sizeof (wr));
 		wr.wr_id = (unsigned long) dtgrm_priv;
 		wr.sg_list = &dtgrm_priv->sg;
@@ -500,18 +501,20 @@
 
 		if (!(ret = ib_post_recv(hca->qp, &wr, &bad_wr))) {
 			printk(KERN_ERR "Could not post receive request\n");
-			goto error2;
+			goto error1;
 		}
 		hca->stat.rcv_posted_cnt++;
 	}
 
 	return 0;
 
-error2:
+error1:
+	pci_unmap_single(hca->handle->dma_device,
+			 pci_unmap_addr(&dtgrm_priv->grh, mapping),
+			 MAD_BLOCK_SIZE + IB_GRH_LEN, PCI_DMA_FROMDEVICE);
 	GSI_RCV_LIST_LOCK(hca);
 	v_list_del((struct list_head *) dtgrm_priv);
 	GSI_RCV_LIST_UNLOCK(hca);
-error1:
 	gsi_dtgrm_pool_put((struct gsi_dtgrm_t *) dtgrm_priv);
 
 	printk(KERN_DEBUG "ret = %d\n", ret);
@@ -669,6 +672,11 @@
 	    (struct gsi_hca_info_st *) &gsi_hca_list, *entry;
 	int ret;
 	int cq_size;
+	u64 iova = 0;
+	struct ib_phys_buf buf_list = {
+		.addr = 0,
+		.size = (unsigned long) high_memory - PAGE_OFFSET
+	};
 	struct ib_qp_init_attr qp_init_attr;
 	struct ib_qp_cap qp_cap;
 	GSI_HCA_LIST_LOCK_VAR;
@@ -731,6 +739,14 @@
 		goto error4;
 	}
 
+	hca->mr = ib_reg_phys_mr(hca->pd, &buf_list, 1, 
+				 IB_ACCESS_LOCAL_WRITE, &iova);
+	if (IS_ERR(hca->mr)) {
+		printk(KERN_ERR "Could not register MR.\n");
+		ret = PTR_ERR(hca->mr);
+		goto error5;
+	}
+
 	memset(&qp_init_attr, 0, sizeof (qp_init_attr));
 	qp_init_attr.send_cq = hca->cq;
 	qp_init_attr.recv_cq = hca->cq;
@@ -1217,6 +1233,10 @@
 	struct mad_t *mad = (struct mad_t *) &dtgrm_priv->mad;
 	GSI_SND_LIST_LOCK_VAR;
 
+	pci_unmap_single(hca->handle->dma_device,
+			 pci_unmap_addr(&dtgrm_priv->mad, mapping),
+		 	 MAD_BLOCK_SIZE, PCI_DMA_TODEVICE);
+
 #if 0				/* GSI_ADDRESS_HNDL_POOL_SUPPORT */
 	ib_put_ah(dtgrm_priv->addr_hndl);
 #else
@@ -1634,11 +1654,14 @@
 	hca->stat.rcv_cnt++;
 	hca->stat.rcv_posted_cnt--;
 
+	pci_unmap_single(hca->handle->dma_device,
+			 pci_unmap_addr(&dtgrm_priv->grh, mapping),
+			 MAD_BLOCK_SIZE + IB_GRH_LEN, PCI_DMA_FROMDEVICE);
+
 	/*      
 	 * Remove the datagram from the posted datagram list
 	 * hca->rcv_posted_dtgrm_list
 	 */
-
 	GSI_RCV_LIST_LOCK(hca);
 	v_list_del((struct list_head *) dtgrm_priv);
 	GSI_RCV_LIST_UNLOCK(hca);
@@ -1898,7 +1921,6 @@
 {
 	struct ib_ah_attr addr_vec;
 	struct ib_ah *addr_hndl;
-	u32 rkey;
 	struct ib_send_wr wr;
 	struct ib_send_wr *bad_wr;
 	struct mad_t *mad = (struct mad_t *) dtgrm->mad;
@@ -1925,20 +1947,11 @@
 	}
 #endif
 
-	dtgrm_priv->v_mem_h = ib_reg_mr(hca->pd,
-					mad,
-					MAD_BLOCK_SIZE,
-					IB_ACCESS_LOCAL_WRITE,
-					&dtgrm_priv->sg.lkey, &rkey);
-	if (IS_ERR(dtgrm_priv->v_mem_h)) {
-		printk(KERN_ERR "Could not get general memory attr.\n");
-		ret = PTR_ERR(dtgrm_priv->v_mem_h);
-		goto error2;
-	}
-
 	wr.wr_id = (unsigned long) dtgrm_priv;
 	wr.sg_list = &dtgrm_priv->sg;
-	wr.sg_list->addr = (unsigned long) mad;
+	wr.sg_list->addr = pci_map_single(hca->handle->dma_device,
+					  mad, MAD_BLOCK_SIZE,
+					  PCI_DMA_TODEVICE);
 	wr.sg_list->length = MAD_BLOCK_SIZE;
 	wr.sg_list->lkey = dtgrm_priv->sg.lkey;
 	wr.num_sge = 1;
@@ -1953,6 +1966,8 @@
 
 	mad_swap_header(mad);
 
+	pci_unmap_addr_set(&dtgrm_priv->mad, mapping, wr.sg_list->addr);
+
 	dtgrm_priv->posted++;
 	dtgrm_priv->addr_hndl = addr_hndl;
 
@@ -1971,18 +1986,20 @@
 
 	if ((ret = ib_post_send(hca->qp, &wr, &bad_wr))) {
 		printk(KERN_ERR "Could not post send request\n");
-		goto error3;
+		goto error2;
 	}
 
 	class_info->stat.snd_cnt++;
 	return 0;
 
-error3:
+error2:
+	pci_unmap_single(hca->handle->dma_device,
+			 pci_unmap_addr(&dtgrm_priv->mad, mapping),
+			 MAD_BLOCK_SIZE, PCI_DMA_TODEVICE);
 	GSI_SND_LIST_LOCK(class_info->hca);
 	v_list_del((struct list_head *) dtgrm_priv);
 	dtgrm_priv->posted--;
 	GSI_SND_LIST_UNLOCK(class_info->hca);
-error2:
 #if 0				/* GSI_ADDRESS_HNDL_POOL_SUPPORT */
 	ib_put_ah(addr_hndl);
 #else
@@ -2031,7 +2048,6 @@
 {
 	struct ib_ah_attr addr_vec;
 	struct ib_ah *addr_hndl;
-	u32 rkey;
 	struct ib_send_wr wr;
 	struct ib_send_wr *bad_wr;
 	struct mad_t *mad = (struct mad_t *) dtgrm->mad;
@@ -2076,19 +2092,12 @@
 		goto error1;
 	}
 #endif
-	dtgrm_priv->v_mem_h = ib_reg_mr(hca->pd,
-					mad,
-					MAD_BLOCK_SIZE,
-					IB_ACCESS_LOCAL_WRITE,
-					&dtgrm_priv->sg.lkey, &rkey);
-	if (IS_ERR(dtgrm_priv->v_mem_h)) {
-		printk(KERN_ERR "Could not get general memory attr.\n");
-		goto error2;
-	}
 
 	wr.wr_id = (unsigned long) dtgrm_priv;
 	wr.sg_list = &dtgrm_priv->sg;
-	wr.sg_list->addr = (unsigned long) mad;
+        wr.sg_list->addr = pci_map_single(hca->handle->dma_device,
+					  mad, MAD_BLOCK_SIZE,
+					  PCI_DMA_TODEVICE);
 	wr.sg_list->length = MAD_BLOCK_SIZE;
 	wr.sg_list->lkey = dtgrm_priv->sg.lkey;
 	wr.num_sge = 1;
@@ -2103,6 +2112,8 @@
 
 	mad_swap_header(mad);
 
+	pci_unmap_addr_set(&dtgrm_priv->mad, mapping, wr.sg_list->addr);
+
 	dtgrm_priv->posted++;
 	dtgrm_priv->addr_hndl = addr_hndl;
 
@@ -2122,6 +2133,9 @@
 	return 0;
 
 error2:
+	pci_unmap_single(hca->handle->dma_device,
+			 pci_unmap_addr(&dtgrm_priv->mad, mapping),
+			 MAD_BLOCK_SIZE, PCI_DMA_TODEVICE);
 #if 0				/* GSI_ADDRESS_HNDL_POOL_SUPPORT */
 	ib_put_ah(addr_hndl);
 #else
Index: access/gsi_priv.h
===================================================================
--- access/gsi_priv.h	(revision 644)
+++ access/gsi_priv.h	(working copy)
@@ -88,7 +88,6 @@
 	struct gsi_dtgrm_priv_st *prev;
 	void *pool;
 	struct ib_sge sg;
-	struct ib_mr *v_mem_h;
 	int owner;		/* 0 - gsi pool, 1 - user */
 } __attribute__ ((packed));
 
@@ -97,7 +96,6 @@
 	struct gsi_dtgrm_priv_st *prev;
 	void *pool;
 	struct ib_sge sg;
-	struct ib_mr *v_mem_h;
 	int owner;		/* 0 - gsi pool, 1 - user */
 
 	/*
@@ -116,7 +114,6 @@
 	struct gsi_dtgrm_priv_st *prev;
 	void *pool;
 	struct ib_sge sg;
-	struct ib_mr *v_mem_h;
 	int owner;		/* 0 - gsi pool, 1 - user */
 
 	/*
@@ -194,8 +191,9 @@
 	u8 port;
 
 	struct ib_qp *qp;	/* QP */
-	struct ib_cq *cq;	/* Complete queue */
+	struct ib_cq *cq;	/* Completion queue */
 	struct ib_pd *pd;	/* Protection domain */
+	struct ib_mr *mr;	/* Memory region */
 
 #if 0				/* GSI_AH_CACHE_SUPPORT */
 #define GSI_AH_CACHE_ENTRY_EMPTY 0







More information about the general mailing list