linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: zonque@gmail.com (Daniel Mack)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 11/20] net: smc91x.c: switch to generic buf-to-buf DMA offload
Date: Wed,  7 Aug 2013 17:34:00 +0200	[thread overview]
Message-ID: <1375889649-14638-12-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1375889649-14638-1-git-send-email-zonque@gmail.com>

Drop all PXA-DMA specific implementation details and rely on
dma_async_memcpy_buf_to_buf().

This patch is only compile-tested.

Signed-off-by: Daniel Mack <zonque@gmail.com>
---
 drivers/net/ethernet/smsc/smc91x.c | 40 +++++++--------------
 drivers/net/ethernet/smsc/smc91x.h | 71 ++++++++++++++------------------------
 2 files changed, 38 insertions(+), 73 deletions(-)

diff --git a/drivers/net/ethernet/smsc/smc91x.c b/drivers/net/ethernet/smsc/smc91x.c
index cde13be..2d1e073 100644
--- a/drivers/net/ethernet/smsc/smc91x.c
+++ b/drivers/net/ethernet/smsc/smc91x.c
@@ -2015,17 +2015,17 @@ static int smc_probe(struct net_device *dev, void __iomem *ioaddr,
       	if (retval)
       		goto err_out;
 
-#ifdef CONFIG_ARCH_PXA
-#  ifdef SMC_USE_PXA_DMA
-	lp->cfg.flags |= SMC91X_USE_DMA;
-#  endif
 	if (lp->cfg.flags & SMC91X_USE_DMA) {
-		int dma = pxa_request_dma(dev->name, DMA_PRIO_LOW,
-					  smc_pxa_dma_irq, NULL);
-		if (dma >= 0)
-			dev->dma = dma;
+		dma_cap_mask_t mask;
+
+		dma_cap_zero(mask);
+		dma_cap_set(DMA_MEMCPY, mask);
+		lp->dma_channel = dma_request_channel(mask, NULL, NULL);
+
+		if (!lp->dma_channel)
+			printk("%s(): request of DMA channel failed\n",
+				__func__);
 	}
-#endif
 
 	retval = register_netdev(dev);
 	if (retval == 0) {
@@ -2034,9 +2034,6 @@ static int smc_probe(struct net_device *dev, void __iomem *ioaddr,
 			dev->name, version_string, revision_register & 0x0f,
 			lp->base, dev->irq);
 
-		if (dev->dma != (unsigned char)-1)
-			printk(" DMA %d", dev->dma);
-
 		printk("%s%s\n",
 			lp->cfg.flags & SMC91X_NOWAIT ? " [nowait]" : "",
 			THROTTLE_TX_PKTS ? " [throttle_tx]" : "");
@@ -2060,10 +2057,6 @@ static int smc_probe(struct net_device *dev, void __iomem *ioaddr,
 	}
 
 err_out:
-#ifdef CONFIG_ARCH_PXA
-	if (retval && dev->dma != (unsigned char)-1)
-		pxa_free_dma(dev->dma);
-#endif
 	return retval;
 }
 
@@ -2282,14 +2275,6 @@ static int smc_drv_probe(struct platform_device *pdev)
 		goto out_release_attrib;
 	}
 
-#ifdef CONFIG_ARCH_PXA
-	{
-		struct smc_local *lp = netdev_priv(ndev);
-		lp->device = &pdev->dev;
-		lp->physaddr = res->start;
-	}
-#endif
-
 	ret = smc_probe(ndev, addr, irq_flags);
 	if (ret != 0)
 		goto out_iounmap;
@@ -2320,12 +2305,11 @@ static int smc_drv_remove(struct platform_device *pdev)
 
 	unregister_netdev(ndev);
 
+	if (lp->dma_channel)
+		dma_release_channel(lp->dma_channel);
+
 	free_irq(ndev->irq, ndev);
 
-#ifdef CONFIG_ARCH_PXA
-	if (ndev->dma != (unsigned char)-1)
-		pxa_free_dma(ndev->dma);
-#endif
 	iounmap(lp->base);
 
 	smc_release_datacs(pdev,ndev);
diff --git a/drivers/net/ethernet/smsc/smc91x.h b/drivers/net/ethernet/smsc/smc91x.h
index 370e13d..cf51366 100644
--- a/drivers/net/ethernet/smsc/smc91x.h
+++ b/drivers/net/ethernet/smsc/smc91x.h
@@ -34,6 +34,7 @@
 #ifndef _SMC91X_H_
 #define _SMC91X_H_
 
+#include <linux/dmaengine.h>
 #include <linux/smc91x.h>
 
 /*
@@ -338,11 +339,8 @@ struct smc_local {
 
 	spinlock_t lock;
 
-#ifdef CONFIG_ARCH_PXA
-	/* DMA needs the physical address of the chip */
-	u_long physaddr;
-	struct device *device;
-#endif
+	struct dma_chan	*dma_channel;
+
 	void __iomem *base;
 	void __iomem *datacs;
 
@@ -358,13 +356,29 @@ struct smc_local {
 
 #ifdef CONFIG_ARCH_PXA
 /*
- * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
+ * Let's use the generic DMA buffer-to-buffer offload mechanism. This is
  * always happening in irq context so no need to worry about races.  TX is
  * different and probably not worth it for that reason, and not as critical
  * as RX which can overrun memory and lose packets.
  */
-#include <linux/dma-mapping.h>
-#include <mach/dma.h>
+
+static void smc_dma_copy(struct smc_local *lp, void *dest, void *src,
+			 unsigned int len)
+{
+	dma_cookie_t cookie;
+	cookie = dma_async_memcpy_buf_to_buf(lp->dma_channel, dest, src, len);
+
+	while (1) {
+		struct dma_tx_state state;
+		enum dma_status status;
+
+		status = dmaengine_tx_status(lp->dma_channel, cookie, &state);
+		if (status != DMA_IN_PROGRESS)
+			break;
+
+		cpu_relax();
+	}
+}
 
 #ifdef SMC_insl
 #undef SMC_insl
@@ -374,11 +388,8 @@ static inline void
 smc_pxa_dma_insl(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
 		 u_char *buf, int len)
 {
-	u_long physaddr = lp->physaddr;
-	dma_addr_t dmabuf;
-
 	/* fallback if no DMA available */
-	if (dma == (unsigned char)-1) {
+	if (lp->dma_channel == NULL) {
 		readsl(ioaddr + reg, buf, len);
 		return;
 	}
@@ -390,18 +401,7 @@ smc_pxa_dma_insl(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
 		len--;
 	}
 
-	len *= 4;
-	dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
-	DCSR(dma) = DCSR_NODESC;
-	DTADR(dma) = dmabuf;
-	DSADR(dma) = physaddr + reg;
-	DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
-		     DCMD_WIDTH4 | (DCMD_LENGTH & len));
-	DCSR(dma) = DCSR_NODESC | DCSR_RUN;
-	while (!(DCSR(dma) & DCSR_STOPSTATE))
-		cpu_relax();
-	DCSR(dma) = 0;
-	dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
+	smc_dma_copy(lp, buf, (__u32 *) ioaddr + reg, len * 4);
 }
 #endif
 
@@ -413,11 +413,8 @@ static inline void
 smc_pxa_dma_insw(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
 		 u_char *buf, int len)
 {
-	u_long physaddr = lp->physaddr;
-	dma_addr_t dmabuf;
-
 	/* fallback if no DMA available */
-	if (dma == (unsigned char)-1) {
+	if (lp->dma_channel == NULL) {
 		readsw(ioaddr + reg, buf, len);
 		return;
 	}
@@ -429,26 +426,10 @@ smc_pxa_dma_insw(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
 		len--;
 	}
 
-	len *= 2;
-	dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
-	DCSR(dma) = DCSR_NODESC;
-	DTADR(dma) = dmabuf;
-	DSADR(dma) = physaddr + reg;
-	DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
-		     DCMD_WIDTH2 | (DCMD_LENGTH & len));
-	DCSR(dma) = DCSR_NODESC | DCSR_RUN;
-	while (!(DCSR(dma) & DCSR_STOPSTATE))
-		cpu_relax();
-	DCSR(dma) = 0;
-	dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
+	smc_dma_copy(lp, buf, (__u32 *) ioaddr + reg, len * 2);
 }
 #endif
 
-static void
-smc_pxa_dma_irq(int dma, void *dummy)
-{
-	DCSR(dma) = 0;
-}
 #endif  /* CONFIG_ARCH_PXA */
 
 
-- 
1.8.3.1

  parent reply	other threads:[~2013-08-07 15:34 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-07 15:33 [PATCH 00/20] ARM: pxa: move core and drivers to dmaengine Daniel Mack
2013-08-07 15:33 ` [PATCH 01/20] mtd: pxa3xx-nand: replace pxa_request_dma with dmaengine Daniel Mack
2013-08-07 17:46   ` Ezequiel Garcia
2013-08-08  6:42     ` Daniel Mack
2013-08-08 10:12       ` Ezequiel Garcia
2013-08-08 10:14         ` Daniel Mack
2013-08-07 15:33 ` [PATCH 02/20] mtd: pxa3xx-nand: use mmp_pdma_filter_fn and dma_request_slave_channel_compat Daniel Mack
2013-08-07 15:33 ` [PATCH 03/20] ARM: pxa: ssp: add shortcut for &pdev->dev Daniel Mack
2013-08-08  7:32   ` Brian Norris
2013-08-08  7:52     ` Artem Bityutskiy
2013-08-08  8:20       ` Daniel Mack
2013-08-07 15:33 ` [PATCH 04/20] ARM: pxa: ssp: add DT bindings Daniel Mack
2013-08-07 15:54   ` Arnd Bergmann
2013-08-07 15:33 ` [PATCH 05/20] ARM: pxa: ssp: use devm_ functions Daniel Mack
2013-08-07 15:33 ` [PATCH 06/20] tty: serial: pxa: remove old cruft Daniel Mack
2013-08-12  8:19   ` Daniel Mack
2013-08-12 18:08     ` Greg KH
2013-08-07 15:33 ` [PATCH 07/20] spi: spi-pxa2xx: remove legacy PXA DMA bits Daniel Mack
2013-08-07 15:55   ` Mark Brown
2013-08-07 15:59     ` Daniel Mack
2013-08-07 16:41       ` Mark Brown
2013-08-07 15:33 ` [PATCH 08/20] mmc: host: pxamci: switch over to dmaengine use Daniel Mack
2014-10-15 18:32   ` Vasily Khoruzhick
2014-10-16 17:57     ` Vasily Khoruzhick
2013-08-07 15:33 ` [PATCH 09/20] ata: pdata_pxa: migrate over to dmaengine usage Daniel Mack
2013-08-07 15:59   ` Arnd Bergmann
2013-08-07 15:33 ` [PATCH 10/20] net: irda: pxaficp_ir: switch to dmaengine Daniel Mack
2013-08-07 15:34 ` Daniel Mack [this message]
2013-08-07 15:34 ` [PATCH 12/20] net: smc911x.c: switch to dmaengine API Daniel Mack
2013-08-07 15:34 ` [PATCH 13/20] ASoC: pxa: pxa-ssp: add DT bindings Daniel Mack
2013-08-07 16:40   ` Mark Brown
2013-08-08  9:39     ` Daniel Mack
2013-08-08 13:20       ` Mark Brown
2013-08-09 13:03         ` Daniel Mack
2013-08-07 15:34 ` [PATCH 14/20] ASoC: pxa: use snd_dmaengine_dai_dma_data Daniel Mack
2013-08-07 15:57   ` Mark Brown
2013-08-07 15:34 ` [PATCH 15/20] ASoC: pxa: pxa-ssp: set dma filter data from startup hook Daniel Mack
2013-08-07 15:58   ` Mark Brown
2013-08-07 15:34 ` [PATCH 16/20] ASoC: pxa: add DT bindings for pxa2xx-pcm Daniel Mack
2013-08-07 16:06   ` Mark Brown
2013-08-07 15:34 ` [PATCH 17/20] ASoC: pxa: pxa-pcm-lib: switch over to snd-soc-dmaengine-pcm Daniel Mack
2013-08-07 16:07   ` Mark Brown
2013-08-07 16:10     ` Daniel Mack
2013-08-07 16:32       ` Mark Brown
2013-08-08  8:18         ` Daniel Mack
2013-08-08  8:44           ` Lars-Peter Clausen
2013-08-08  9:03             ` Daniel Mack
2013-08-08  9:36               ` Mark Brown
2013-08-08  9:43                 ` Daniel Mack
2013-08-08 10:35                   ` Mark Brown
2013-08-08 10:39                     ` Daniel Mack
2013-08-08 11:03                       ` Mark Brown
2013-08-08 10:25                 ` Russell King - ARM Linux
2013-08-07 15:34 ` [PATCH 18/20] ARM: pxa: register static mmp_pdma device Daniel Mack
2013-08-07 15:34 ` [PATCH 19/20] ARM: mmp: " Daniel Mack
2013-08-07 15:34 ` [PATCH 20/20] ARM: pxa: remove old DMA implementation Daniel Mack
2013-08-07 16:08 ` [PATCH 00/20] ARM: pxa: move core and drivers to dmaengine Arnd Bergmann
2013-08-09 22:50 ` Robert Jarzmik
2013-08-10 10:56   ` Daniel Mack
2013-08-11 20:05     ` Robert Jarzmik
2013-08-14 10:00     ` Vinod Koul
2013-08-15 15:22       ` Robert Jarzmik
2013-08-15 15:30         ` Daniel Mack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1375889649-14638-12-git-send-email-zonque@gmail.com \
    --to=zonque@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).