Skip to content

Commit 79d3b59

Browse files
rjarzmikdavem330
authored andcommitted
net: smc911x: convert pxa dma to dmaengine
Convert the dma transfers to be dmaengine based, now pxa has a dmaengine slave driver. This makes this driver a bit more PXA agnostic. The driver was only compile tested. The risk is quite small as no current PXA platform I'm aware of is using smc911x driver. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Tested-by: Fabio Estevam <fabio.estevam@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c9d0bc5 commit 79d3b59

File tree

2 files changed

+82
-66
lines changed

2 files changed

+82
-66
lines changed

drivers/net/ethernet/smsc/smc911x.c

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ static const char version[] =
7373
#include <linux/etherdevice.h>
7474
#include <linux/skbuff.h>
7575

76+
#include <linux/dmaengine.h>
77+
#include <linux/dma/pxa-dma.h>
78+
7679
#include <asm/io.h>
7780

7881
#include "smc911x.h"
@@ -1174,18 +1177,16 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
11741177

11751178
#ifdef SMC_USE_DMA
11761179
static void
1177-
smc911x_tx_dma_irq(int dma, void *data)
1180+
smc911x_tx_dma_irq(void *data)
11781181
{
1179-
struct net_device *dev = (struct net_device *)data;
1180-
struct smc911x_local *lp = netdev_priv(dev);
1182+
struct smc911x_local *lp = data;
1183+
struct net_device *dev = lp->netdev;
11811184
struct sk_buff *skb = lp->current_tx_skb;
11821185
unsigned long flags;
11831186

11841187
DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
11851188

11861189
DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev, "TX DMA irq handler\n");
1187-
/* Clear the DMA interrupt sources */
1188-
SMC_DMA_ACK_IRQ(dev, dma);
11891190
BUG_ON(skb == NULL);
11901191
dma_unmap_single(NULL, tx_dmabuf, tx_dmalen, DMA_TO_DEVICE);
11911192
dev->trans_start = jiffies;
@@ -1208,18 +1209,16 @@ smc911x_tx_dma_irq(int dma, void *data)
12081209
"TX DMA irq completed\n");
12091210
}
12101211
static void
1211-
smc911x_rx_dma_irq(int dma, void *data)
1212+
smc911x_rx_dma_irq(void *data)
12121213
{
1213-
struct net_device *dev = (struct net_device *)data;
1214-
struct smc911x_local *lp = netdev_priv(dev);
1214+
struct smc911x_local *lp = data;
1215+
struct net_device *dev = lp->netdev;
12151216
struct sk_buff *skb = lp->current_rx_skb;
12161217
unsigned long flags;
12171218
unsigned int pkts;
12181219

12191220
DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
12201221
DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, dev, "RX DMA irq handler\n");
1221-
/* Clear the DMA interrupt sources */
1222-
SMC_DMA_ACK_IRQ(dev, dma);
12231222
dma_unmap_single(NULL, rx_dmabuf, rx_dmalen, DMA_FROM_DEVICE);
12241223
BUG_ON(skb == NULL);
12251224
lp->current_rx_skb = NULL;
@@ -1792,6 +1791,9 @@ static int smc911x_probe(struct net_device *dev)
17921791
unsigned int val, chip_id, revision;
17931792
const char *version_string;
17941793
unsigned long irq_flags;
1794+
struct dma_slave_config config;
1795+
dma_cap_mask_t mask;
1796+
struct pxad_param param;
17951797

17961798
DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
17971799

@@ -1963,11 +1965,40 @@ static int smc911x_probe(struct net_device *dev)
19631965
goto err_out;
19641966

19651967
#ifdef SMC_USE_DMA
1966-
lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq);
1967-
lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq);
1968+
1969+
dma_cap_zero(mask);
1970+
dma_cap_set(DMA_SLAVE, mask);
1971+
param.prio = PXAD_PRIO_LOWEST;
1972+
param.drcmr = -1UL;
1973+
1974+
lp->rxdma =
1975+
dma_request_slave_channel_compat(mask, pxad_filter_fn,
1976+
&param, &dev->dev, "rx");
1977+
lp->txdma =
1978+
dma_request_slave_channel_compat(mask, pxad_filter_fn,
1979+
&param, &dev->dev, "tx");
19681980
lp->rxdma_active = 0;
19691981
lp->txdma_active = 0;
1970-
dev->dma = lp->rxdma;
1982+
1983+
memset(&config, 0, sizeof(config));
1984+
config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1985+
config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1986+
config.src_addr = lp->physaddr + RX_DATA_FIFO;
1987+
config.dst_addr = lp->physaddr + TX_DATA_FIFO;
1988+
config.src_maxburst = 32;
1989+
config.dst_maxburst = 32;
1990+
retval = dmaengine_slave_config(lp->rxdma, &config);
1991+
if (retval) {
1992+
dev_err(lp->dev, "dma rx channel configuration failed: %d\n",
1993+
retval);
1994+
goto err_out;
1995+
}
1996+
retval = dmaengine_slave_config(lp->txdma, &config);
1997+
if (retval) {
1998+
dev_err(lp->dev, "dma tx channel configuration failed: %d\n",
1999+
retval);
2000+
goto err_out;
2001+
}
19712002
#endif
19722003

19732004
retval = register_netdev(dev);
@@ -1978,11 +2009,11 @@ static int smc911x_probe(struct net_device *dev)
19782009
dev->base_addr, dev->irq);
19792010

19802011
#ifdef SMC_USE_DMA
1981-
if (lp->rxdma != -1)
1982-
pr_cont(" RXDMA %d", lp->rxdma);
2012+
if (lp->rxdma)
2013+
pr_cont(" RXDMA %p", lp->rxdma);
19832014

1984-
if (lp->txdma != -1)
1985-
pr_cont(" TXDMA %d", lp->txdma);
2015+
if (lp->txdma)
2016+
pr_cont(" TXDMA %p", lp->txdma);
19862017
#endif
19872018
pr_cont("\n");
19882019
if (!is_valid_ether_addr(dev->dev_addr)) {
@@ -2005,12 +2036,10 @@ static int smc911x_probe(struct net_device *dev)
20052036
err_out:
20062037
#ifdef SMC_USE_DMA
20072038
if (retval) {
2008-
if (lp->rxdma != -1) {
2009-
SMC_DMA_FREE(dev, lp->rxdma);
2010-
}
2011-
if (lp->txdma != -1) {
2012-
SMC_DMA_FREE(dev, lp->txdma);
2013-
}
2039+
if (lp->rxdma)
2040+
dma_release_channel(lp->rxdma);
2041+
if (lp->txdma)
2042+
dma_release_channel(lp->txdma);
20142043
}
20152044
#endif
20162045
return retval;
@@ -2112,12 +2141,10 @@ static int smc911x_drv_remove(struct platform_device *pdev)
21122141

21132142
#ifdef SMC_USE_DMA
21142143
{
2115-
if (lp->rxdma != -1) {
2116-
SMC_DMA_FREE(dev, lp->rxdma);
2117-
}
2118-
if (lp->txdma != -1) {
2119-
SMC_DMA_FREE(dev, lp->txdma);
2120-
}
2144+
if (lp->rxdma)
2145+
dma_release_channel(lp->rxdma);
2146+
if (lp->txdma)
2147+
dma_release_channel(lp->txdma);
21212148
}
21222149
#endif
21232150
iounmap(lp->base);

drivers/net/ethernet/smsc/smc911x.h

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct smc911x_local {
101101
#ifdef SMC_USE_DMA
102102
/* DMA needs the physical address of the chip */
103103
u_long physaddr;
104-
int rxdma;
105-
int txdma;
104+
struct dma_chan *rxdma;
105+
struct dma_chan *txdma;
106106
int rxdma_active;
107107
int txdma_active;
108108
struct sk_buff *current_rx_skb;
@@ -210,34 +210,15 @@ static inline void SMC_outsl(struct smc911x_local *lp, int reg,
210210

211211
#ifdef SMC_USE_PXA_DMA
212212

213-
#include <mach/dma.h>
214-
215-
/*
216-
* Define the request and free functions
217-
* These are unfortunately architecture specific as no generic allocation
218-
* mechanism exits
219-
*/
220-
#define SMC_DMA_REQUEST(dev, handler) \
221-
pxa_request_dma(dev->name, DMA_PRIO_LOW, handler, dev)
222-
223-
#define SMC_DMA_FREE(dev, dma) \
224-
pxa_free_dma(dma)
225-
226-
#define SMC_DMA_ACK_IRQ(dev, dma) \
227-
{ \
228-
if (DCSR(dma) & DCSR_BUSERR) { \
229-
netdev_err(dev, "DMA %d bus error!\n", dma); \
230-
} \
231-
DCSR(dma) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR; \
232-
}
233-
234213
/*
235214
* Use a DMA for RX and TX packets.
236215
*/
237216
#include <linux/dma-mapping.h>
238217

239218
static dma_addr_t rx_dmabuf, tx_dmabuf;
240219
static int rx_dmalen, tx_dmalen;
220+
static void smc911x_rx_dma_irq(void *data);
221+
static void smc911x_tx_dma_irq(void *data);
241222

242223
#ifdef SMC_insl
243224
#undef SMC_insl
@@ -246,8 +227,10 @@ static int rx_dmalen, tx_dmalen;
246227

247228
static inline void
248229
smc_pxa_dma_insl(struct smc911x_local *lp, u_long physaddr,
249-
int reg, int dma, u_char *buf, int len)
230+
int reg, struct dma_chan *dma, u_char *buf, int len)
250231
{
232+
struct dma_async_tx_descriptor *tx;
233+
251234
/* 64 bit alignment is required for memory to memory DMA */
252235
if ((long)buf & 4) {
253236
*((u32 *)buf) = SMC_inl(lp, reg);
@@ -258,12 +241,14 @@ smc_pxa_dma_insl(struct smc911x_local *lp, u_long physaddr,
258241
len *= 4;
259242
rx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_FROM_DEVICE);
260243
rx_dmalen = len;
261-
DCSR(dma) = DCSR_NODESC;
262-
DTADR(dma) = rx_dmabuf;
263-
DSADR(dma) = physaddr + reg;
264-
DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
265-
DCMD_WIDTH4 | DCMD_ENDIRQEN | (DCMD_LENGTH & rx_dmalen));
266-
DCSR(dma) = DCSR_NODESC | DCSR_RUN;
244+
tx = dmaengine_prep_slave_single(dma, rx_dmabuf, rx_dmalen,
245+
DMA_DEV_TO_MEM, 0);
246+
if (tx) {
247+
tx->callback = smc911x_rx_dma_irq;
248+
tx->callback_param = lp;
249+
dmaengine_submit(tx);
250+
dma_async_issue_pending(dma);
251+
}
267252
}
268253
#endif
269254

@@ -274,8 +259,10 @@ smc_pxa_dma_insl(struct smc911x_local *lp, u_long physaddr,
274259

275260
static inline void
276261
smc_pxa_dma_outsl(struct smc911x_local *lp, u_long physaddr,
277-
int reg, int dma, u_char *buf, int len)
262+
int reg, struct dma_chan *dma, u_char *buf, int len)
278263
{
264+
struct dma_async_tx_descriptor *tx;
265+
279266
/* 64 bit alignment is required for memory to memory DMA */
280267
if ((long)buf & 4) {
281268
SMC_outl(*((u32 *)buf), lp, reg);
@@ -286,12 +273,14 @@ smc_pxa_dma_outsl(struct smc911x_local *lp, u_long physaddr,
286273
len *= 4;
287274
tx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_TO_DEVICE);
288275
tx_dmalen = len;
289-
DCSR(dma) = DCSR_NODESC;
290-
DSADR(dma) = tx_dmabuf;
291-
DTADR(dma) = physaddr + reg;
292-
DCMD(dma) = (DCMD_INCSRCADDR | DCMD_BURST32 |
293-
DCMD_WIDTH4 | DCMD_ENDIRQEN | (DCMD_LENGTH & tx_dmalen));
294-
DCSR(dma) = DCSR_NODESC | DCSR_RUN;
276+
tx = dmaengine_prep_slave_single(dma, tx_dmabuf, tx_dmalen,
277+
DMA_DEV_TO_MEM, 0);
278+
if (tx) {
279+
tx->callback = smc911x_tx_dma_irq;
280+
tx->callback_param = lp;
281+
dmaengine_submit(tx);
282+
dma_async_issue_pending(dma);
283+
}
295284
}
296285
#endif
297286
#endif /* SMC_USE_PXA_DMA */

0 commit comments

Comments
 (0)