[openib-general] [PATCH] Convert from pci_xxx to dma_xxx functions

Roland Dreier roland at topspin.com
Mon Nov 22 19:33:21 PST 2004


Christoph Hellwig suggested we might as well put a generic struct
device *dma_device and use the generic dma_map functions rather than
assuming we're dealing with a PCI device.  (There's no dma_xxx
equivalent of pci_unmap_addr_set() and friends, so I left that stuff--
Christoph agrees this is OK for now).

Look OK to commit?

Thanks,
  Roland

Index: infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_main.c	(revision 1273)
+++ infiniband/ulp/ipoib/ipoib_main.c	(working copy)
@@ -773,7 +773,7 @@
 	if (!priv)
 		goto alloc_mem_failed;
 
-	SET_NETDEV_DEV(priv->dev, &hca->dma_device->dev);
+	SET_NETDEV_DEV(priv->dev, hca->dma_device);
 
 	result = ib_query_pkey(hca, port, 0, &priv->pkey);
 	if (result) {
Index: infiniband/ulp/ipoib/ipoib_ib.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_ib.c	(revision 1272)
+++ infiniband/ulp/ipoib/ipoib_ib.c	(working copy)
@@ -107,9 +107,9 @@
 	}
 	skb_reserve(skb, 4);	/* 16 byte align IP header */
 	priv->rx_ring[id].skb = skb;
-	addr = pci_map_single(priv->ca->dma_device,
+	addr = dma_map_single(priv->ca->dma_device,
 			      skb->data, IPOIB_BUF_SIZE,
-			      PCI_DMA_FROMDEVICE);
+			      DMA_FROM_DEVICE);
 	pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr);
 
 	ret = ipoib_ib_receive(priv, id, addr);
@@ -154,11 +154,11 @@
 
 			priv->rx_ring[wr_id].skb = NULL;
 
-			pci_unmap_single(priv->ca->dma_device,
+			dma_unmap_single(priv->ca->dma_device,
 					 pci_unmap_addr(&priv->rx_ring[wr_id],
 							mapping),
 					 IPOIB_BUF_SIZE,
-					 PCI_DMA_FROMDEVICE);
+					 DMA_FROM_DEVICE);
 
 			if (wc->status != IB_WC_SUCCESS) {
 				if (wc->status != IB_WC_WR_FLUSH_ERR)
@@ -216,10 +216,10 @@
 
 		tx_req = &priv->tx_ring[wr_id];
 
-		pci_unmap_single(priv->ca->dma_device,
+		dma_unmap_single(priv->ca->dma_device,
 				 pci_unmap_addr(tx_req, mapping),
 				 tx_req->skb->len,
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 
 		++priv->stats.tx_packets;
 		priv->stats.tx_bytes += tx_req->skb->len;
@@ -318,9 +318,9 @@
 	 */
 	tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)];
 	tx_req->skb = skb;
-	addr = pci_map_single(priv->ca->dma_device,
+	addr = dma_map_single(priv->ca->dma_device,
 			      skb->data, skb->len,
-			      PCI_DMA_TODEVICE);
+			      DMA_TO_DEVICE);
 	pci_unmap_addr_set(tx_req, mapping, addr);
 
 	if (post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1),
Index: infiniband/include/ib_verbs.h
===================================================================
--- infiniband/include/ib_verbs.h	(revision 1272)
+++ infiniband/include/ib_verbs.h	(working copy)
@@ -679,7 +679,7 @@
 };
 
 struct ib_device {
-	struct pci_dev               *dma_device;
+	struct device                *dma_device;
 
 	char                          name[IB_DEVICE_NAME_MAX];
 
Index: infiniband/core/agent.c
===================================================================
--- infiniband/core/agent.c	(revision 1272)
+++ infiniband/core/agent.c	(working copy)
@@ -23,11 +23,15 @@
   Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
 */
 
+#include <linux/dma-mapping.h>
+
+#include <asm/bug.h>
+
 #include <ib_smi.h>
+
 #include "smi.h"
 #include "agent_priv.h"
 #include "mad_priv.h"
-#include <asm/bug.h>
 
 
 spinlock_t ib_agent_port_list_lock;
@@ -117,10 +121,10 @@
 	agent_send_wr->mad = mad;
 
 	/* PCI mapping */
-	gather_list.addr = pci_map_single(mad_agent->device->dma_device,
+	gather_list.addr = dma_map_single(mad_agent->device->dma_device,
 					  &mad->mad,
 					  sizeof(mad->mad),
-					  PCI_DMA_TODEVICE);
+					  DMA_TO_DEVICE);
 	gather_list.length = sizeof(mad->mad);
 	gather_list.lkey = (*port_priv->mr).lkey;
 
@@ -182,10 +186,10 @@
 	spin_lock_irqsave(&port_priv->send_list_lock, flags);
 	if (ib_post_send_mad(mad_agent, &send_wr, &bad_send_wr)) {
 		spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
-		pci_unmap_single(mad_agent->device->dma_device,
+		dma_unmap_single(mad_agent->device->dma_device,
 				 pci_unmap_addr(agent_send_wr, mapping),
 				 sizeof(mad->mad),
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 		ib_destroy_ah(agent_send_wr->ah);
 		kfree(agent_send_wr);
 	} else {
@@ -255,10 +259,10 @@
 	spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
 
 	/* Unmap PCI */
-	pci_unmap_single(mad_agent->device->dma_device,
+	dma_unmap_single(mad_agent->device->dma_device,
 			 pci_unmap_addr(agent_send_wr, mapping),
 			 sizeof(agent_send_wr->mad->mad),
-			 PCI_DMA_TODEVICE);
+			 DMA_TO_DEVICE);
 
 	ib_destroy_ah(agent_send_wr->ah);
 
Index: infiniband/core/user_mad.c
===================================================================
--- infiniband/core/user_mad.c	(revision 1272)
+++ infiniband/core/user_mad.c	(working copy)
@@ -115,10 +115,10 @@
 	struct ib_umad_packet *packet =
 		(void *) (unsigned long) send_wc->wr_id;
 
-	pci_unmap_single(agent->device->dma_device,
+	dma_unmap_single(agent->device->dma_device,
 			 pci_unmap_addr(packet, mapping),
 			 sizeof packet->mad.data,
-			 PCI_DMA_TODEVICE);
+			 DMA_TO_DEVICE);
 	ib_destroy_ah(packet->ah);
 
 	if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
@@ -267,10 +267,10 @@
 		goto err_up;
 	}
 
-	gather_list.addr = pci_map_single(agent->device->dma_device,
+	gather_list.addr = dma_map_single(agent->device->dma_device,
 					  packet->mad.data,
 					  sizeof packet->mad.data,
-					  PCI_DMA_TODEVICE);
+					  DMA_TO_DEVICE);
 	gather_list.length = sizeof packet->mad.data;
 	gather_list.lkey   = file->mr[packet->mad.id]->lkey;
 	pci_unmap_addr_set(packet, mapping, gather_list.addr);
@@ -285,10 +285,10 @@
 
 	ret = ib_post_send_mad(agent, &wr, &bad_wr);
 	if (ret) {
-		pci_unmap_single(agent->device->dma_device,
+		dma_unmap_single(agent->device->dma_device,
 				 pci_unmap_addr(packet, mapping),
 				 sizeof packet->mad.data,
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 		goto err_up;
 	}
 
@@ -549,7 +549,7 @@
 		umad_dev->port[i - s].class_dev =
 			class_simple_device_add(umad_class,
 						umad_dev->port[i - s].dev.dev,
-						&device->dma_device->dev,
+						device->dma_device,
 						"umad%d", umad_dev->port[i - s].devnum);
 		if (IS_ERR(umad_dev->port[i - s].class_dev))
 			goto err_class;
Index: infiniband/core/mad.c
===================================================================
--- infiniband/core/mad.c	(revision 1272)
+++ infiniband/core/mad.c	(working copy)
@@ -53,16 +53,16 @@
  * and/or other materials provided with the distribution.
  */
 
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
 
 #include <ib_mad.h>
+
 #include "mad_priv.h"
 #include "smi.h"
 #include "agent.h"
 
-#include <linux/smp_lock.h>
-#include <linux/interrupt.h>
 
-
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("kernel IB MAD API");
 MODULE_AUTHOR("Hal Rosenstock");
@@ -1094,11 +1094,11 @@
 	mad_priv_hdr = container_of(mad_list, struct ib_mad_private_header,
 				    mad_list);
 	recv = container_of(mad_priv_hdr, struct ib_mad_private, header);
-	pci_unmap_single(port_priv->device->dma_device,
+	dma_unmap_single(port_priv->device->dma_device,
 			 pci_unmap_addr(&recv->header, mapping),
 			 sizeof(struct ib_mad_private) -
 			 sizeof(struct ib_mad_private_header),
-			 PCI_DMA_FROMDEVICE);
+			 DMA_FROM_DEVICE);
 
 	/* Setup MAD receive work completion from "normal" work completion */
 	recv->header.recv_wc.wc = wc;
@@ -1627,12 +1627,12 @@
 				break;
 			}
 		}
-		sg_list.addr = pci_map_single(qp_info->port_priv->
+		sg_list.addr = dma_map_single(qp_info->port_priv->
 						device->dma_device,
 					&mad_priv->grh,
 					sizeof *mad_priv -
 						sizeof mad_priv->header,
-					PCI_DMA_FROMDEVICE);
+					DMA_FROM_DEVICE);
 		pci_unmap_addr_set(&mad_priv->header, mapping, sg_list.addr);
 		recv_wr.wr_id = (unsigned long)&mad_priv->header.mad_list;
 		mad_priv->header.mad_list.mad_queue = recv_queue;
@@ -1648,12 +1648,12 @@
 			list_del(&mad_priv->header.mad_list.list);
 			recv_queue->count--;
 			spin_unlock_irqrestore(&recv_queue->lock, flags);
-			pci_unmap_single(qp_info->port_priv->device->dma_device,
+			dma_unmap_single(qp_info->port_priv->device->dma_device,
 					 pci_unmap_addr(&mad_priv->header,
 							mapping),
 					 sizeof *mad_priv -
 					   sizeof mad_priv->header,
-					 PCI_DMA_FROMDEVICE);
+					 DMA_FROM_DEVICE);
 			kmem_cache_free(ib_mad_cache, mad_priv);
 			printk(KERN_ERR PFX "ib_post_recv failed: %d\n", ret);
 			break;
@@ -1686,11 +1686,11 @@
 		list_del(&mad_list->list);
 
 		/* Undo PCI mapping */
-		pci_unmap_single(qp_info->port_priv->device->dma_device,
+		dma_unmap_single(qp_info->port_priv->device->dma_device,
 				 pci_unmap_addr(&recv->header, mapping),
 				 sizeof(struct ib_mad_private) -
 				 sizeof(struct ib_mad_private_header),
-				 PCI_DMA_FROMDEVICE);
+				 DMA_FROM_DEVICE);
 		kmem_cache_free(ib_mad_cache, recv);
 	}
 
Index: infiniband/core/sa_query.c
===================================================================
--- infiniband/core/sa_query.c	(revision 1276)
+++ infiniband/core/sa_query.c	(working copy)
@@ -28,6 +28,7 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <linux/kref.h>
 #include <linux/idr.h>
 
@@ -43,14 +44,14 @@
 	u16			attr_offset;
 	u16			reserved;
 	ib_sa_comp_mask		comp_mask;
-} __attribute__((packed));
+} __attribute__ ((packed));
 
 struct ib_sa_mad {
 	struct ib_mad_hdr	mad_hdr;
 	struct ib_rmpp_hdr	rmpp_hdr;
 	struct ib_sa_hdr	sa_hdr;
 	u8			data[200];
-} __attribute__((packed));
+} __attribute__ ((packed));
 
 struct ib_sa_sm_ah {
 	struct ib_ah        *ah;
@@ -460,20 +461,20 @@
 	wr.wr.ud.ah  = port->sm_ah->ah;
 	spin_unlock_irqrestore(&port->ah_lock, flags);
 
-	gather_list.addr   = pci_map_single(port->agent->device->dma_device,
+	gather_list.addr   = dma_map_single(port->agent->device->dma_device,
 					    query->mad,
 					    sizeof (struct ib_sa_mad),
-					    PCI_DMA_TODEVICE);
+					    DMA_TO_DEVICE);
 	gather_list.length = sizeof (struct ib_sa_mad);
 	gather_list.lkey   = port->mr->lkey;
 	pci_unmap_addr_set(query, mapping, gather_list.addr);
 
 	ret = ib_post_send_mad(port->agent, &wr, &bad_wr);
 	if (ret) {
-		pci_unmap_single(port->agent->device->dma_device,
+		dma_unmap_single(port->agent->device->dma_device,
 				 pci_unmap_addr(query, mapping),
 				 sizeof (struct ib_sa_mad),
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 		kref_put(&query->sm_ah->ref, free_sm_ah);
 		spin_lock_irqsave(&idr_lock, flags);
 		idr_remove(&query_idr, query->id);
@@ -662,10 +663,10 @@
 		break;
 	}
 
-	pci_unmap_single(agent->device->dma_device,
+	dma_unmap_single(agent->device->dma_device,
 			 pci_unmap_addr(query, mapping),
 			 sizeof (struct ib_sa_mad),
-			 PCI_DMA_TODEVICE);
+			 DMA_TO_DEVICE);
 	kref_put(&query->sm_ah->ref, free_sm_ah);
 
 	query->release(query);
Index: infiniband/hw/mthca/mthca_dev.h
===================================================================
--- infiniband/hw/mthca/mthca_dev.h	(revision 1272)
+++ infiniband/hw/mthca/mthca_dev.h	(working copy)
@@ -27,6 +27,7 @@
 #include <linux/spinlock.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <asm/semaphore.h>
 #include <asm/scatterlist.h>
 
Index: infiniband/hw/mthca/mthca_main.c
===================================================================
--- infiniband/hw/mthca/mthca_main.c	(revision 1272)
+++ infiniband/hw/mthca/mthca_main.c	(working copy)
@@ -28,7 +28,6 @@
 #include <linux/errno.h>
 #include <linux/pci.h>
 #include <linux/interrupt.h>
-#include <linux/dma-mapping.h>
 
 #ifdef CONFIG_INFINIBAND_MTHCA_SSE_DOORBELL
 #include <asm/cpufeature.h>
Index: infiniband/hw/mthca/mthca_provider.c
===================================================================
--- infiniband/hw/mthca/mthca_provider.c	(revision 1272)
+++ infiniband/hw/mthca/mthca_provider.c	(working copy)
@@ -573,7 +573,7 @@
 	strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
 	dev->ib_dev.node_type            = IB_NODE_CA;
 	dev->ib_dev.phys_port_cnt        = dev->limits.num_ports;
-	dev->ib_dev.dma_device           = dev->pdev;
+	dev->ib_dev.dma_device           = &dev->pdev->dev;
 	dev->ib_dev.class_dev.dev        = &dev->pdev->dev;
 	dev->ib_dev.query_device         = mthca_query_device;
 	dev->ib_dev.query_port           = mthca_query_port;
Index: infiniband/hw/mthca/mthca_mad.c
===================================================================
--- infiniband/hw/mthca/mthca_mad.c	(revision 1272)
+++ infiniband/hw/mthca/mthca_mad.c	(working copy)
@@ -144,10 +144,10 @@
 		wr.wr.ud.mad_hdr = &tmad->mad->mad_hdr;
 		wr.wr_id         = (unsigned long) tmad;
 
-		gather_list.addr   = pci_map_single(agent->device->dma_device,
+		gather_list.addr   = dma_map_single(agent->device->dma_device,
 						    tmad->mad,
 						    sizeof *tmad->mad,
-						    PCI_DMA_TODEVICE);
+						    DMA_TO_DEVICE);
 		gather_list.length = sizeof *tmad->mad;
 		gather_list.lkey   = to_mpd(agent->qp->pd)->ntmr.ibmr.lkey;
 		pci_unmap_addr_set(tmad, mapping, gather_list.addr);
@@ -167,10 +167,10 @@
 		spin_unlock_irqrestore(&dev->sm_lock, flags);
 
 		if (ret) {
-			pci_unmap_single(agent->device->dma_device,
+			dma_unmap_single(agent->device->dma_device,
 					 pci_unmap_addr(tmad, mapping),
 					 sizeof *tmad->mad,
-					 PCI_DMA_TODEVICE);
+					 DMA_TO_DEVICE);
 			kfree(tmad->mad);
 			kfree(tmad);
 		}
@@ -259,10 +259,10 @@
 	struct mthca_trap_mad *tmad =
 		(void *) (unsigned long) mad_send_wc->wr_id;
 
-	pci_unmap_single(agent->device->dma_device,
+	dma_unmap_single(agent->device->dma_device,
 			 pci_unmap_addr(tmad, mapping),
 			 sizeof *tmad->mad,
-			 PCI_DMA_TODEVICE);
+			 DMA_TO_DEVICE);
 	kfree(tmad->mad);
 	kfree(tmad);
 }



More information about the general mailing list