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 DRV_NAME "jazzsonic"
42 #define SREGS_PAD(n) u16 n;
47 * Macros to access SONIC registers
49 #define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg))
51 #define SONIC_WRITE(reg,val) \
53 *((volatile unsigned int *)base_addr+reg) = val; \
57 /* use 0 for production, 1 for verification, >2 for debug */
59 static unsigned int sonic_debug
= SONIC_DEBUG
;
61 static unsigned int sonic_debug
= 1;
65 * Base address and interrupt of the SONIC controller on JAZZ boards
70 } sonic_portlist
[] = { {JAZZ_ETHERNET_BASE
, JAZZ_ETHERNET_IRQ
}, {0, 0}};
73 * We cannot use station (ethernet) address prefixes to detect the
74 * sonic controller since these are board manufacturer depended.
75 * So we check for known Silicon Revision IDs instead.
77 static unsigned short known_revisions
[] =
79 0x04, /* Mips Magnum 4000 */
80 0xffff /* end of list */
83 /* Index to functions, as function prototypes. */
85 static int sonic_probe1(struct net_device
*dev
, unsigned int base_addr
,
90 * Probe for a SONIC ethernet controller on a Mips Jazz board.
91 * Actually probing is superfluous but we're paranoid.
93 struct net_device
* __init
sonic_probe(int unit
)
95 struct net_device
*dev
;
96 struct sonic_local
*lp
;
97 unsigned int base_addr
;
102 * Don't probe if we're not running on a Jazz board.
104 if (mips_machgroup
!= MACH_GROUP_JAZZ
)
105 return ERR_PTR(-ENODEV
);
107 dev
= alloc_etherdev(0);
109 return ERR_PTR(-ENOMEM
);
111 sprintf(dev
->name
, "eth%d", unit
);
112 netdev_boot_setup_check(dev
);
113 base_addr
= dev
->base_addr
;
115 if (base_addr
>= KSEG0
) { /* Check a single specified location. */
116 err
= sonic_probe1(dev
, base_addr
, dev
->irq
);
117 } else if (base_addr
!= 0) { /* Don't probe at all. */
120 for (i
= 0; sonic_portlist
[i
].port
; i
++) {
121 int io
= sonic_portlist
[i
].port
;
122 if (sonic_probe1(dev
, io
, sonic_portlist
[i
].irq
) == 0)
125 if (!sonic_portlist
[i
].port
)
130 err
= register_netdev(dev
);
136 vdma_free(lp
->rba_laddr
);
138 vdma_free(lp
->cda_laddr
);
140 release_region(dev
->base_addr
, 0x100);
146 static int __init
sonic_probe1(struct net_device
*dev
, unsigned int base_addr
,
149 static unsigned version_printed
;
150 unsigned int silicon_revision
;
152 struct sonic_local
*lp
;
156 if (!request_region(base_addr
, 0x100, DRV_NAME
))
159 * get the Silicon Revision ID. If this is one of the known
160 * one assume that we found a SONIC ethernet controller at
161 * the expected location.
163 silicon_revision
= SONIC_READ(SONIC_SR
);
165 printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision
);
168 while (known_revisions
[i
] != 0xffff
169 && known_revisions
[i
] != silicon_revision
)
172 if (known_revisions
[i
] == 0xffff) {
173 printk("SONIC ethernet controller not found (0x%4x)\n",
178 if (sonic_debug
&& version_printed
++ == 0)
181 printk("%s: Sonic ethernet found at 0x%08lx, ", dev
->name
, base_addr
);
183 /* Fill in the 'dev' fields. */
184 dev
->base_addr
= base_addr
;
188 * Put the sonic into software reset, then
189 * retrieve and print the ethernet address.
191 SONIC_WRITE(SONIC_CMD
,SONIC_CR_RST
);
192 SONIC_WRITE(SONIC_CEP
,0);
193 for (i
=0; i
<3; i
++) {
194 val
= SONIC_READ(SONIC_CAP0
-i
);
195 dev
->dev_addr
[i
*2] = val
;
196 dev
->dev_addr
[i
*2+1] = val
>> 8;
199 printk("HW Address ");
200 for (i
= 0; i
< 6; i
++) {
201 printk("%2.2x", dev
->dev_addr
[i
]);
206 printk(" IRQ %d\n", irq
);
210 /* Initialize the device structure. */
211 if (dev
->priv
== NULL
) {
213 * the memory be located in the same 64kb segment
218 lp
= kmalloc(sizeof(*lp
), GFP_KERNEL
);
219 if ((unsigned long) lp
>> 16
220 != ((unsigned long)lp
+ sizeof(*lp
) ) >> 16) {
221 /* FIXME, free the memory later */
225 } while (lp
== NULL
&& i
++ < 20);
228 printk("%s: couldn't allocate memory for descriptors\n",
233 memset(lp
, 0, sizeof(struct sonic_local
));
235 /* get the virtual dma address */
236 lp
->cda_laddr
= vdma_alloc(PHYSADDR(lp
),sizeof(*lp
));
237 if (lp
->cda_laddr
== ~0UL) {
238 printk("%s: couldn't get DMA page entry for "
239 "descriptors\n", dev
->name
);
243 lp
->tda_laddr
= lp
->cda_laddr
+ sizeof (lp
->cda
);
244 lp
->rra_laddr
= lp
->tda_laddr
+ sizeof (lp
->tda
);
245 lp
->rda_laddr
= lp
->rra_laddr
+ sizeof (lp
->rra
);
247 /* allocate receive buffer area */
248 /* FIXME, maybe we should use skbs */
249 lp
->rba
= kmalloc(SONIC_NUM_RRS
* SONIC_RBSIZE
, GFP_KERNEL
);
251 printk("%s: couldn't allocate receive buffers\n",
256 /* get virtual dma address */
257 lp
->rba_laddr
= vdma_alloc(PHYSADDR(lp
->rba
),
258 SONIC_NUM_RRS
* SONIC_RBSIZE
);
259 if (lp
->rba_laddr
== ~0UL) {
260 printk("%s: couldn't get DMA page entry for receive "
261 "buffers\n",dev
->name
);
265 /* now convert pointer to KSEG1 pointer */
266 lp
->rba
= (char *)KSEG1ADDR(lp
->rba
);
268 dev
->priv
= (struct sonic_local
*)KSEG1ADDR(lp
);
271 lp
= (struct sonic_local
*)dev
->priv
;
272 dev
->open
= sonic_open
;
273 dev
->stop
= sonic_close
;
274 dev
->hard_start_xmit
= sonic_send_packet
;
275 dev
->get_stats
= sonic_get_stats
;
276 dev
->set_multicast_list
= &sonic_multicast_list
;
277 dev
->watchdog_timeo
= TX_TIMEOUT
;
280 * clear tally counter
282 SONIC_WRITE(SONIC_CRCT
,0xffff);
283 SONIC_WRITE(SONIC_FAET
,0xffff);
284 SONIC_WRITE(SONIC_MPT
,0xffff);
290 vdma_free(lp
->cda_laddr
);
294 release_region(base_addr
, 0x100);
299 * SONIC uses a normal IRQ
301 #define sonic_request_irq request_irq
302 #define sonic_free_irq free_irq
304 #define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x))