Skip to content

Commit efcce83

Browse files
Finn Thainjgarzik
authored andcommitted
[PATCH] macsonic/jazzsonic network drivers update
The purpose of this patch: - Adopt the DMA API (jazzsonic, macsonic & core driver). - Adopt the driver model (macsonic). This part was cribbed from jazzsonic. As a consequence, macsonic once again works as a module. Driver model is also used by the DMA calls. - Support 16 bit cards (macsonic & core driver, also affects jazzsonic) This code was adapted from the mac68k linux 2.2 kernel, where it has languished for a long time. - Support more 32-bit mac cards (macsonic) Also from mac68k repo. - Zero-copy buffer handling (core driver) Provides a nice performance improvement. The new algorithm incidentally helped to replace the old Jazz DMA code. The patch was tested on a variety of macs (several 32-bit quadra built-in NICs, a 16-bit LC PDS NIC and a 16-bit comm-slot NIC), and also on MIPS Jazz. Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
1 parent 2600636 commit efcce83

5 files changed

Lines changed: 972 additions & 892 deletions

File tree

‎drivers/net/Space.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ extern struct net_device *mvme147lance_probe(int unit);
8787
extern struct net_device *tc515_probe(int unit);
8888
extern struct net_device *lance_probe(int unit);
8989
extern struct net_device *mace_probe(int unit);
90-
extern struct net_device *macsonic_probe(int unit);
9190
extern struct net_device *mac8390_probe(int unit);
9291
extern struct net_device *mac89x0_probe(int unit);
9392
extern struct net_device *mc32_probe(int unit);
@@ -284,9 +283,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
284283
#ifdef CONFIG_MACMACE /* Mac 68k Quadra AV builtin Ethernet */
285284
{mace_probe, 0},
286285
#endif
287-
#ifdef CONFIG_MACSONIC /* Mac SONIC-based Ethernet of all sorts */
288-
{macsonic_probe, 0},
289-
#endif
290286
#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
291287
{mac8390_probe, 0},
292288
#endif

‎drivers/net/jazzsonic.c‎

Lines changed: 74 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/*
2-
* sonic.c
2+
* jazzsonic.c
3+
*
4+
* (C) 2005 Finn Thain
5+
*
6+
* Converted to DMA API, and (from the mac68k project) introduced
7+
* dhd's support for 16-bit cards.
38
*
49
* (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
510
*
@@ -28,8 +33,8 @@
2833
#include <linux/netdevice.h>
2934
#include <linux/etherdevice.h>
3035
#include <linux/skbuff.h>
31-
#include <linux/bitops.h>
3236
#include <linux/device.h>
37+
#include <linux/dma-mapping.h>
3338

3439
#include <asm/bootinfo.h>
3540
#include <asm/system.h>
@@ -44,22 +49,20 @@ static struct platform_device *jazz_sonic_device;
4449

4550
#define SONIC_MEM_SIZE 0x100
4651

47-
#define SREGS_PAD(n) u16 n;
48-
4952
#include "sonic.h"
5053

5154
/*
5255
* Macros to access SONIC registers
5356
*/
54-
#define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg))
57+
#define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
5558

5659
#define SONIC_WRITE(reg,val) \
5760
do { \
58-
*((volatile unsigned int *)base_addr+(reg)) = (val); \
61+
*((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
5962
} while (0)
6063

6164

62-
/* use 0 for production, 1 for verification, >2 for debug */
65+
/* use 0 for production, 1 for verification, >1 for debug */
6366
#ifdef SONIC_DEBUG
6467
static unsigned int sonic_debug = SONIC_DEBUG;
6568
#else
@@ -85,18 +88,18 @@ static unsigned short known_revisions[] =
8588
0xffff /* end of list */
8689
};
8790

88-
static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
89-
unsigned int irq)
91+
static int __init sonic_probe1(struct net_device *dev)
9092
{
9193
static unsigned version_printed;
9294
unsigned int silicon_revision;
9395
unsigned int val;
94-
struct sonic_local *lp;
96+
struct sonic_local *lp = netdev_priv(dev);
9597
int err = -ENODEV;
9698
int i;
9799

98-
if (!request_mem_region(base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
100+
if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
99101
return -EBUSY;
102+
100103
/*
101104
* get the Silicon Revision ID. If this is one of the known
102105
* one assume that we found a SONIC ethernet controller at
@@ -120,11 +123,7 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
120123
if (sonic_debug && version_printed++ == 0)
121124
printk(version);
122125

123-
printk("%s: Sonic ethernet found at 0x%08lx, ", dev->name, base_addr);
124-
125-
/* Fill in the 'dev' fields. */
126-
dev->base_addr = base_addr;
127-
dev->irq = irq;
126+
printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr);
128127

129128
/*
130129
* Put the sonic into software reset, then
@@ -138,84 +137,44 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
138137
dev->dev_addr[i*2+1] = val >> 8;
139138
}
140139

141-
printk("HW Address ");
142-
for (i = 0; i < 6; i++) {
143-
printk("%2.2x", dev->dev_addr[i]);
144-
if (i<5)
145-
printk(":");
146-
}
147-
148-
printk(" IRQ %d\n", irq);
149-
150140
err = -ENOMEM;
151141

152142
/* Initialize the device structure. */
153-
if (dev->priv == NULL) {
154-
/*
155-
* the memory be located in the same 64kb segment
156-
*/
157-
lp = NULL;
158-
i = 0;
159-
do {
160-
lp = kmalloc(sizeof(*lp), GFP_KERNEL);
161-
if ((unsigned long) lp >> 16
162-
!= ((unsigned long)lp + sizeof(*lp) ) >> 16) {
163-
/* FIXME, free the memory later */
164-
kfree(lp);
165-
lp = NULL;
166-
}
167-
} while (lp == NULL && i++ < 20);
168-
169-
if (lp == NULL) {
170-
printk("%s: couldn't allocate memory for descriptors\n",
171-
dev->name);
172-
goto out;
173-
}
174143

175-
memset(lp, 0, sizeof(struct sonic_local));
176-
177-
/* get the virtual dma address */
178-
lp->cda_laddr = vdma_alloc(CPHYSADDR(lp),sizeof(*lp));
179-
if (lp->cda_laddr == ~0UL) {
180-
printk("%s: couldn't get DMA page entry for "
181-
"descriptors\n", dev->name);
182-
goto out1;
183-
}
184-
185-
lp->tda_laddr = lp->cda_laddr + sizeof (lp->cda);
186-
lp->rra_laddr = lp->tda_laddr + sizeof (lp->tda);
187-
lp->rda_laddr = lp->rra_laddr + sizeof (lp->rra);
188-
189-
/* allocate receive buffer area */
190-
/* FIXME, maybe we should use skbs */
191-
lp->rba = kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL);
192-
if (!lp->rba) {
193-
printk("%s: couldn't allocate receive buffers\n",
194-
dev->name);
195-
goto out2;
196-
}
144+
lp->dma_bitmode = SONIC_BITMODE32;
197145

198-
/* get virtual dma address */
199-
lp->rba_laddr = vdma_alloc(CPHYSADDR(lp->rba),
200-
SONIC_NUM_RRS * SONIC_RBSIZE);
201-
if (lp->rba_laddr == ~0UL) {
202-
printk("%s: couldn't get DMA page entry for receive "
203-
"buffers\n",dev->name);
204-
goto out3;
205-
}
206-
207-
/* now convert pointer to KSEG1 pointer */
208-
lp->rba = (char *)KSEG1ADDR(lp->rba);
209-
flush_cache_all();
210-
dev->priv = (struct sonic_local *)KSEG1ADDR(lp);
146+
/* Allocate the entire chunk of memory for the descriptors.
147+
Note that this cannot cross a 64K boundary. */
148+
if ((lp->descriptors = dma_alloc_coherent(lp->device,
149+
SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
150+
&lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
151+
printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id);
152+
goto out;
211153
}
212154

213-
lp = (struct sonic_local *)dev->priv;
155+
/* Now set up the pointers to point to the appropriate places */
156+
lp->cda = lp->descriptors;
157+
lp->tda = lp->cda + (SIZEOF_SONIC_CDA
158+
* SONIC_BUS_SCALE(lp->dma_bitmode));
159+
lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
160+
* SONIC_BUS_SCALE(lp->dma_bitmode));
161+
lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
162+
* SONIC_BUS_SCALE(lp->dma_bitmode));
163+
164+
lp->cda_laddr = lp->descriptors_laddr;
165+
lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
166+
* SONIC_BUS_SCALE(lp->dma_bitmode));
167+
lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
168+
* SONIC_BUS_SCALE(lp->dma_bitmode));
169+
lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
170+
* SONIC_BUS_SCALE(lp->dma_bitmode));
171+
214172
dev->open = sonic_open;
215173
dev->stop = sonic_close;
216174
dev->hard_start_xmit = sonic_send_packet;
217-
dev->get_stats = sonic_get_stats;
175+
dev->get_stats = sonic_get_stats;
218176
dev->set_multicast_list = &sonic_multicast_list;
177+
dev->tx_timeout = sonic_tx_timeout;
219178
dev->watchdog_timeo = TX_TIMEOUT;
220179

221180
/*
@@ -226,14 +185,8 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
226185
SONIC_WRITE(SONIC_MPT,0xffff);
227186

228187
return 0;
229-
out3:
230-
kfree(lp->rba);
231-
out2:
232-
vdma_free(lp->cda_laddr);
233-
out1:
234-
kfree(lp);
235188
out:
236-
release_region(base_addr, SONIC_MEM_SIZE);
189+
release_region(dev->base_addr, SONIC_MEM_SIZE);
237190
return err;
238191
}
239192

@@ -245,7 +198,6 @@ static int __init jazz_sonic_probe(struct device *device)
245198
{
246199
struct net_device *dev;
247200
struct sonic_local *lp;
248-
unsigned long base_addr;
249201
int err = 0;
250202
int i;
251203

@@ -255,21 +207,26 @@ static int __init jazz_sonic_probe(struct device *device)
255207
if (mips_machgroup != MACH_GROUP_JAZZ)
256208
return -ENODEV;
257209

258-
dev = alloc_etherdev(0);
210+
dev = alloc_etherdev(sizeof(struct sonic_local));
259211
if (!dev)
260212
return -ENOMEM;
261213

214+
lp = netdev_priv(dev);
215+
lp->device = device;
216+
SET_NETDEV_DEV(dev, device);
217+
SET_MODULE_OWNER(dev);
218+
262219
netdev_boot_setup_check(dev);
263-
base_addr = dev->base_addr;
264220

265-
if (base_addr >= KSEG0) { /* Check a single specified location. */
266-
err = sonic_probe1(dev, base_addr, dev->irq);
267-
} else if (base_addr != 0) { /* Don't probe at all. */
221+
if (dev->base_addr >= KSEG0) { /* Check a single specified location. */
222+
err = sonic_probe1(dev);
223+
} else if (dev->base_addr != 0) { /* Don't probe at all. */
268224
err = -ENXIO;
269225
} else {
270226
for (i = 0; sonic_portlist[i].port; i++) {
271-
int io = sonic_portlist[i].port;
272-
if (sonic_probe1(dev, io, sonic_portlist[i].irq) == 0)
227+
dev->base_addr = sonic_portlist[i].port;
228+
dev->irq = sonic_portlist[i].irq;
229+
if (sonic_probe1(dev) == 0)
273230
break;
274231
}
275232
if (!sonic_portlist[i].port)
@@ -281,36 +238,40 @@ static int __init jazz_sonic_probe(struct device *device)
281238
if (err)
282239
goto out1;
283240

241+
printk("%s: MAC ", dev->name);
242+
for (i = 0; i < 6; i++) {
243+
printk("%2.2x", dev->dev_addr[i]);
244+
if (i < 5)
245+
printk(":");
246+
}
247+
printk(" IRQ %d\n", dev->irq);
248+
284249
return 0;
285250

286251
out1:
287-
lp = dev->priv;
288-
vdma_free(lp->rba_laddr);
289-
kfree(lp->rba);
290-
vdma_free(lp->cda_laddr);
291-
kfree(lp);
292252
release_region(dev->base_addr, SONIC_MEM_SIZE);
293253
out:
294254
free_netdev(dev);
295255

296256
return err;
297257
}
298258

299-
/*
300-
* SONIC uses a normal IRQ
301-
*/
302-
#define sonic_request_irq request_irq
303-
#define sonic_free_irq free_irq
259+
MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
260+
module_param(sonic_debug, int, 0);
261+
MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
304262

305-
#define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x))
263+
#define SONIC_IRQ_FLAG SA_INTERRUPT
306264

307265
#include "sonic.c"
308266

309267
static int __devexit jazz_sonic_device_remove (struct device *device)
310268
{
311269
struct net_device *dev = device->driver_data;
270+
struct sonic_local* lp = netdev_priv(dev);
312271

313272
unregister_netdev (dev);
273+
dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
274+
lp->descriptors, lp->descriptors_laddr);
314275
release_region (dev->base_addr, SONIC_MEM_SIZE);
315276
free_netdev (dev);
316277

@@ -323,7 +284,7 @@ static struct device_driver jazz_sonic_driver = {
323284
.probe = jazz_sonic_probe,
324285
.remove = __devexit_p(jazz_sonic_device_remove),
325286
};
326-
287+
327288
static void jazz_sonic_platform_release (struct device *device)
328289
{
329290
struct platform_device *pldev;
@@ -336,10 +297,11 @@ static void jazz_sonic_platform_release (struct device *device)
336297
static int __init jazz_sonic_init_module(void)
337298
{
338299
struct platform_device *pldev;
300+
int err;
339301

340-
if (driver_register(&jazz_sonic_driver)) {
302+
if ((err = driver_register(&jazz_sonic_driver))) {
341303
printk(KERN_ERR "Driver registration failed\n");
342-
return -ENOMEM;
304+
return err;
343305
}
344306

345307
jazz_sonic_device = NULL;

0 commit comments

Comments
 (0)