4 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
6 * This driver is based on work from Andreas Busse, but most of
7 * the code is rewritten.
9 * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
11 * A driver for the onboard Sonic ethernet controller on Mips Jazz
12 * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and
13 * perhaps others, too)
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/fcntl.h>
19 #include <linux/interrupt.h>
20 #include <linux/init.h>
21 #include <linux/ioport.h>
23 #include <linux/slab.h>
24 #include <linux/string.h>
25 #include <linux/delay.h>
26 #include <linux/errno.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/skbuff.h>
31 #include <asm/bootinfo.h>
32 #include <asm/system.h>
33 #include <asm/bitops.h>
34 #include <asm/pgtable.h>
38 #include <asm/jazzdma.h>
40 #define SREGS_PAD(n) u16 n;
45 * Macros to access SONIC registers
47 #define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg))
49 #define SONIC_WRITE(reg,val) \
51 *((volatile unsigned int *)base_addr+reg) = val; \
55 /* use 0 for production, 1 for verification, >2 for debug */
57 static unsigned int sonic_debug = SONIC_DEBUG;
59 static unsigned int sonic_debug = 1;
63 * Base address and interrupt of the SONIC controller on JAZZ boards
68 } sonic_portlist[] = { {JAZZ_ETHERNET_BASE, JAZZ_ETHERNET_IRQ}, {0, 0}};
71 * We cannot use station (ethernet) address prefixes to detect the
72 * sonic controller since these are board manufacturer depended.
73 * So we check for known Silicon Revision IDs instead.
75 static unsigned short known_revisions[] =
77 0x04, /* Mips Magnum 4000 */
78 0xffff /* end of list */
81 /* Index to functions, as function prototypes. */
83 static int sonic_probe1(struct net_device *dev, unsigned int base_addr,
88 * Probe for a SONIC ethernet controller on a Mips Jazz board.
89 * Actually probing is superfluous but we're paranoid.
91 struct net_device * __init sonic_probe(int unit)
93 struct net_device *dev;
94 struct sonic_local *lp;
95 unsigned int base_addr;
100 * Don't probe if we're not running on a Jazz board.
102 if (mips_machgroup != MACH_GROUP_JAZZ)
103 return ERR_PTR(-ENODEV);
105 dev = alloc_etherdev(0);
107 return ERR_PTR(-ENOMEM);
109 sprintf(dev->name, "eth%d", unit);
110 netdev_boot_setup_check(dev);
111 base_addr = dev->base_addr;
113 if (base_addr >= KSEG0) { /* Check a single specified location. */
114 err = sonic_probe1(dev, base_addr, dev->irq);
115 } else if (base_addr != 0) { /* Don't probe at all. */
118 for (i = 0; sonic_portlist[i].port; i++) {
119 int io = sonic_portlist[i].port;
120 if (sonic_probe1(dev, io, sonic_portlist[i].irq) == 0)
123 if (!sonic_portlist[i].port)
128 err = register_netdev(dev);
134 vdma_free(lp->rba_laddr);
136 vdma_free(lp->cda_laddr);
138 release_region(dev->base_addr, 0x100);
144 static int __init sonic_probe1(struct net_device *dev, unsigned int base_addr,
147 static unsigned version_printed;
148 unsigned int silicon_revision;
150 struct sonic_local *lp;
154 if (!request_region(base_addr, 0x100, dev->name))
157 * get the Silicon Revision ID. If this is one of the known
158 * one assume that we found a SONIC ethernet controller at
159 * the expected location.
161 silicon_revision = SONIC_READ(SONIC_SR);
163 printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
166 while (known_revisions[i] != 0xffff
167 && known_revisions[i] != silicon_revision)
170 if (known_revisions[i] == 0xffff) {
171 printk("SONIC ethernet controller not found (0x%4x)\n",
176 if (sonic_debug && version_printed++ == 0)
179 printk("%s: Sonic ethernet found at 0x%08lx, ", dev->name, base_addr);
181 /* Fill in the 'dev' fields. */
182 dev->base_addr = base_addr;
186 * Put the sonic into software reset, then
187 * retrieve and print the ethernet address.
189 SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
190 SONIC_WRITE(SONIC_CEP,0);
191 for (i=0; i<3; i++) {
192 val = SONIC_READ(SONIC_CAP0-i);
193 dev->dev_addr[i*2] = val;
194 dev->dev_addr[i*2+1] = val >> 8;
197 printk("HW Address ");
198 for (i = 0; i < 6; i++) {
199 printk("%2.2x", dev->dev_addr[i]);
204 printk(" IRQ %d\n", irq);
208 /* Initialize the device structure. */
209 if (dev->priv == NULL) {
211 * the memory be located in the same 64kb segment
216 lp = kmalloc(sizeof(*lp), GFP_KERNEL);
217 if ((unsigned long) lp >> 16
218 != ((unsigned long)lp + sizeof(*lp) ) >> 16) {
219 /* FIXME, free the memory later */
223 } while (lp == NULL && i++ < 20);
226 printk("%s: couldn't allocate memory for descriptors\n",
231 memset(lp, 0, sizeof(struct sonic_local));
233 /* get the virtual dma address */
234 lp->cda_laddr = vdma_alloc(PHYSADDR(lp),sizeof(*lp));
235 if (lp->cda_laddr == ~0UL) {
236 printk("%s: couldn't get DMA page entry for "
237 "descriptors\n", dev->name);
241 lp->tda_laddr = lp->cda_laddr + sizeof (lp->cda);
242 lp->rra_laddr = lp->tda_laddr + sizeof (lp->tda);
243 lp->rda_laddr = lp->rra_laddr + sizeof (lp->rra);
245 /* allocate receive buffer area */
246 /* FIXME, maybe we should use skbs */
247 lp->rba = kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL);
249 printk("%s: couldn't allocate receive buffers\n",
254 /* get virtual dma address */
255 lp->rba_laddr = vdma_alloc(PHYSADDR(lp->rba),
256 SONIC_NUM_RRS * SONIC_RBSIZE);
257 if (lp->rba_laddr == ~0UL) {
258 printk("%s: couldn't get DMA page entry for receive "
259 "buffers\n",dev->name);
263 /* now convert pointer to KSEG1 pointer */
264 lp->rba = (char *)KSEG1ADDR(lp->rba);
266 dev->priv = (struct sonic_local *)KSEG1ADDR(lp);
269 lp = (struct sonic_local *)dev->priv;
270 dev->open = sonic_open;
271 dev->stop = sonic_close;
272 dev->hard_start_xmit = sonic_send_packet;
273 dev->get_stats = sonic_get_stats;
274 dev->set_multicast_list = &sonic_multicast_list;
275 dev->watchdog_timeo = TX_TIMEOUT;
278 * clear tally counter
280 SONIC_WRITE(SONIC_CRCT,0xffff);
281 SONIC_WRITE(SONIC_FAET,0xffff);
282 SONIC_WRITE(SONIC_MPT,0xffff);
288 vdma_free(lp->cda_laddr);
292 release_region(base_addr, 0x100);
297 * SONIC uses a normal IRQ
299 #define sonic_request_irq request_irq
300 #define sonic_free_irq free_irq
302 #define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x))