6 * Converted to DMA API, and (from the mac68k project) introduced
7 * dhd's support for 16-bit cards.
9 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
11 * This driver is based on work from Andreas Busse, but most of
12 * the code is rewritten.
14 * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
16 * A driver for the onboard Sonic ethernet controller on Mips Jazz
17 * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and
18 * perhaps others, too)
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/fcntl.h>
25 #include <linux/interrupt.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
29 #include <linux/slab.h>
30 #include <linux/string.h>
31 #include <linux/delay.h>
32 #include <linux/errno.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/skbuff.h>
36 #include <linux/platform_device.h>
37 #include <linux/dma-mapping.h>
39 #include <asm/bootinfo.h>
40 #include <asm/system.h>
41 #include <asm/pgtable.h>
45 #include <asm/jazzdma.h>
47 static char jazz_sonic_string
[] = "jazzsonic";
48 static struct platform_device
*jazz_sonic_device
;
50 #define SONIC_MEM_SIZE 0x100
55 * Macros to access SONIC registers
57 #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
59 #define SONIC_WRITE(reg,val) \
61 *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
65 /* use 0 for production, 1 for verification, >1 for debug */
67 static unsigned int sonic_debug
= SONIC_DEBUG
;
69 static unsigned int sonic_debug
= 1;
73 * Base address and interrupt of the SONIC controller on JAZZ boards
78 } sonic_portlist
[] = { {JAZZ_ETHERNET_BASE
, JAZZ_ETHERNET_IRQ
}, {0, 0}};
81 * We cannot use station (ethernet) address prefixes to detect the
82 * sonic controller since these are board manufacturer depended.
83 * So we check for known Silicon Revision IDs instead.
85 static unsigned short known_revisions
[] =
87 0x04, /* Mips Magnum 4000 */
88 0xffff /* end of list */
91 static int jazzsonic_open(struct net_device
* dev
)
93 if (request_irq(dev
->irq
, &sonic_interrupt
, IRQF_DISABLED
, "sonic", dev
)) {
94 printk(KERN_ERR
"%s: unable to get IRQ %d.\n", dev
->name
, dev
->irq
);
97 return sonic_open(dev
);
100 static int jazzsonic_close(struct net_device
* dev
)
103 err
= sonic_close(dev
);
104 free_irq(dev
->irq
, dev
);
108 static int __init
sonic_probe1(struct net_device
*dev
)
110 static unsigned version_printed
;
111 unsigned int silicon_revision
;
113 struct sonic_local
*lp
= netdev_priv(dev
);
117 if (!request_mem_region(dev
->base_addr
, SONIC_MEM_SIZE
, jazz_sonic_string
))
121 * get the Silicon Revision ID. If this is one of the known
122 * one assume that we found a SONIC ethernet controller at
123 * the expected location.
125 silicon_revision
= SONIC_READ(SONIC_SR
);
127 printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision
);
130 while (known_revisions
[i
] != 0xffff
131 && known_revisions
[i
] != silicon_revision
)
134 if (known_revisions
[i
] == 0xffff) {
135 printk("SONIC ethernet controller not found (0x%4x)\n",
140 if (sonic_debug
&& version_printed
++ == 0)
143 printk(KERN_INFO
"%s: Sonic ethernet found at 0x%08lx, ", lp
->device
->bus_id
, dev
->base_addr
);
146 * Put the sonic into software reset, then
147 * retrieve and print the ethernet address.
149 SONIC_WRITE(SONIC_CMD
,SONIC_CR_RST
);
150 SONIC_WRITE(SONIC_CEP
,0);
151 for (i
=0; i
<3; i
++) {
152 val
= SONIC_READ(SONIC_CAP0
-i
);
153 dev
->dev_addr
[i
*2] = val
;
154 dev
->dev_addr
[i
*2+1] = val
>> 8;
159 /* Initialize the device structure. */
161 lp
->dma_bitmode
= SONIC_BITMODE32
;
163 /* Allocate the entire chunk of memory for the descriptors.
164 Note that this cannot cross a 64K boundary. */
165 if ((lp
->descriptors
= dma_alloc_coherent(lp
->device
,
166 SIZEOF_SONIC_DESC
* SONIC_BUS_SCALE(lp
->dma_bitmode
),
167 &lp
->descriptors_laddr
, GFP_KERNEL
)) == NULL
) {
168 printk(KERN_ERR
"%s: couldn't alloc DMA memory for descriptors.\n", lp
->device
->bus_id
);
172 /* Now set up the pointers to point to the appropriate places */
173 lp
->cda
= lp
->descriptors
;
174 lp
->tda
= lp
->cda
+ (SIZEOF_SONIC_CDA
175 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
176 lp
->rda
= lp
->tda
+ (SIZEOF_SONIC_TD
* SONIC_NUM_TDS
177 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
178 lp
->rra
= lp
->rda
+ (SIZEOF_SONIC_RD
* SONIC_NUM_RDS
179 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
181 lp
->cda_laddr
= lp
->descriptors_laddr
;
182 lp
->tda_laddr
= lp
->cda_laddr
+ (SIZEOF_SONIC_CDA
183 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
184 lp
->rda_laddr
= lp
->tda_laddr
+ (SIZEOF_SONIC_TD
* SONIC_NUM_TDS
185 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
186 lp
->rra_laddr
= lp
->rda_laddr
+ (SIZEOF_SONIC_RD
* SONIC_NUM_RDS
187 * SONIC_BUS_SCALE(lp
->dma_bitmode
));
189 dev
->open
= jazzsonic_open
;
190 dev
->stop
= jazzsonic_close
;
191 dev
->hard_start_xmit
= sonic_send_packet
;
192 dev
->get_stats
= sonic_get_stats
;
193 dev
->set_multicast_list
= &sonic_multicast_list
;
194 dev
->tx_timeout
= sonic_tx_timeout
;
195 dev
->watchdog_timeo
= TX_TIMEOUT
;
198 * clear tally counter
200 SONIC_WRITE(SONIC_CRCT
,0xffff);
201 SONIC_WRITE(SONIC_FAET
,0xffff);
202 SONIC_WRITE(SONIC_MPT
,0xffff);
206 release_region(dev
->base_addr
, SONIC_MEM_SIZE
);
211 * Probe for a SONIC ethernet controller on a Mips Jazz board.
212 * Actually probing is superfluous but we're paranoid.
214 static int __init
jazz_sonic_probe(struct platform_device
*pdev
)
216 struct net_device
*dev
;
217 struct sonic_local
*lp
;
222 * Don't probe if we're not running on a Jazz board.
224 if (mips_machgroup
!= MACH_GROUP_JAZZ
)
227 dev
= alloc_etherdev(sizeof(struct sonic_local
));
231 lp
= netdev_priv(dev
);
232 lp
->device
= &pdev
->dev
;
233 SET_NETDEV_DEV(dev
, &pdev
->dev
);
234 SET_MODULE_OWNER(dev
);
236 netdev_boot_setup_check(dev
);
238 if (dev
->base_addr
>= KSEG0
) { /* Check a single specified location. */
239 err
= sonic_probe1(dev
);
240 } else if (dev
->base_addr
!= 0) { /* Don't probe at all. */
243 for (i
= 0; sonic_portlist
[i
].port
; i
++) {
244 dev
->base_addr
= sonic_portlist
[i
].port
;
245 dev
->irq
= sonic_portlist
[i
].irq
;
246 if (sonic_probe1(dev
) == 0)
249 if (!sonic_portlist
[i
].port
)
254 err
= register_netdev(dev
);
258 printk("%s: MAC ", dev
->name
);
259 for (i
= 0; i
< 6; i
++) {
260 printk("%2.2x", dev
->dev_addr
[i
]);
264 printk(" IRQ %d\n", dev
->irq
);
269 release_region(dev
->base_addr
, SONIC_MEM_SIZE
);
276 MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
277 module_param(sonic_debug
, int, 0);
278 MODULE_PARM_DESC(sonic_debug
, "jazzsonic debug level (1-4)");
282 static int __devexit
jazz_sonic_device_remove (struct platform_device
*pdev
)
284 struct net_device
*dev
= platform_get_drvdata(pdev
);
285 struct sonic_local
* lp
= netdev_priv(dev
);
287 unregister_netdev(dev
);
288 dma_free_coherent(lp
->device
, SIZEOF_SONIC_DESC
* SONIC_BUS_SCALE(lp
->dma_bitmode
),
289 lp
->descriptors
, lp
->descriptors_laddr
);
290 release_region (dev
->base_addr
, SONIC_MEM_SIZE
);
296 static struct platform_driver jazz_sonic_driver
= {
297 .probe
= jazz_sonic_probe
,
298 .remove
= __devexit_p(jazz_sonic_device_remove
),
300 .name
= jazz_sonic_string
,
304 static int __init
jazz_sonic_init_module(void)
308 if ((err
= platform_driver_register(&jazz_sonic_driver
))) {
309 printk(KERN_ERR
"Driver registration failed\n");
313 jazz_sonic_device
= platform_device_alloc(jazz_sonic_string
, 0);
314 if (!jazz_sonic_device
)
317 if (platform_device_add(jazz_sonic_device
)) {
318 platform_device_put(jazz_sonic_device
);
319 jazz_sonic_device
= NULL
;
325 platform_driver_unregister(&jazz_sonic_driver
);
330 static void __exit
jazz_sonic_cleanup_module(void)
332 platform_driver_unregister(&jazz_sonic_driver
);
334 if (jazz_sonic_device
) {
335 platform_device_unregister(jazz_sonic_device
);
336 jazz_sonic_device
= NULL
;
340 module_init(jazz_sonic_init_module
);
341 module_exit(jazz_sonic_cleanup_module
);