More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / jazzsonic.c
blobc554db39ee03f917df25531aa0938aba3335e812
1 /*
2 * sonic.c
4 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
5 *
6 * This driver is based on work from Andreas Busse, but most of
7 * the code is rewritten.
8 *
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>
22 #include <linux/in.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>
35 #include <asm/io.h>
36 #include <asm/dma.h>
37 #include <asm/jazz.h>
38 #include <asm/jazzdma.h>
40 #define SREGS_PAD(n) u16 n;
42 #include "sonic.h"
45 * Macros to access SONIC registers
47 #define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg))
49 #define SONIC_WRITE(reg,val) \
50 do { \
51 *((volatile unsigned int *)base_addr+reg) = val; \
55 /* use 0 for production, 1 for verification, >2 for debug */
56 #ifdef SONIC_DEBUG
57 static unsigned int sonic_debug = SONIC_DEBUG;
58 #else
59 static unsigned int sonic_debug = 1;
60 #endif
63 * Base address and interrupt of the SONIC controller on JAZZ boards
65 static struct {
66 unsigned int port;
67 unsigned int irq;
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 extern int sonic_probe(struct net_device *dev);
84 static int sonic_probe1(struct net_device *dev, unsigned int base_addr,
85 unsigned int irq);
89 * Probe for a SONIC ethernet controller on a Mips Jazz board.
90 * Actually probing is superfluous but we're paranoid.
92 int __init sonic_probe(struct net_device *dev)
94 unsigned int base_addr = dev ? dev->base_addr : 0;
95 int i;
98 * Don't probe if we're not running on a Jazz board.
100 if (mips_machgroup != MACH_GROUP_JAZZ)
101 return -ENODEV;
102 if (base_addr >= KSEG0) /* Check a single specified location. */
103 return sonic_probe1(dev, base_addr, dev->irq);
104 else if (base_addr != 0) /* Don't probe at all. */
105 return -ENXIO;
107 for (i = 0; sonic_portlist[i].port; i++) {
108 int base_addr = sonic_portlist[i].port;
109 if (check_region(base_addr, 0x100))
110 continue;
111 if (sonic_probe1(dev, base_addr, sonic_portlist[i].irq) == 0)
112 return 0;
114 return -ENODEV;
117 static int __init sonic_probe1(struct net_device *dev, unsigned int base_addr,
118 unsigned int irq)
120 static unsigned version_printed;
121 unsigned int silicon_revision;
122 unsigned int val;
123 struct sonic_local *lp;
124 int i;
127 * get the Silicon Revision ID. If this is one of the known
128 * one assume that we found a SONIC ethernet controller at
129 * the expected location.
131 silicon_revision = SONIC_READ(SONIC_SR);
132 if (sonic_debug > 1)
133 printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
135 i = 0;
136 while (known_revisions[i] != 0xffff
137 && known_revisions[i] != silicon_revision)
138 i++;
140 if (known_revisions[i] == 0xffff) {
141 printk("SONIC ethernet controller not found (0x%4x)\n",
142 silicon_revision);
143 return -ENODEV;
146 if (!request_region(base_addr, 0x100, dev->name))
147 return -EBUSY;
149 if (sonic_debug && version_printed++ == 0)
150 printk(version);
152 printk("%s: Sonic ethernet found at 0x%08lx, ", dev->name, base_addr);
154 /* Fill in the 'dev' fields. */
155 dev->base_addr = base_addr;
156 dev->irq = irq;
159 * Put the sonic into software reset, then
160 * retrieve and print the ethernet address.
162 SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
163 SONIC_WRITE(SONIC_CEP,0);
164 for (i=0; i<3; i++) {
165 val = SONIC_READ(SONIC_CAP0-i);
166 dev->dev_addr[i*2] = val;
167 dev->dev_addr[i*2+1] = val >> 8;
170 printk("HW Address ");
171 for (i = 0; i < 6; i++) {
172 printk("%2.2x", dev->dev_addr[i]);
173 if (i<5)
174 printk(":");
177 printk(" IRQ %d\n", irq);
179 /* Initialize the device structure. */
180 if (dev->priv == NULL) {
182 * the memory be located in the same 64kb segment
184 lp = NULL;
185 i = 0;
186 do {
187 lp = kmalloc(sizeof(*lp), GFP_KERNEL);
188 if ((unsigned long) lp >> 16
189 != ((unsigned long)lp + sizeof(*lp) ) >> 16) {
190 /* FIXME, free the memory later */
191 kfree(lp);
192 lp = NULL;
194 } while (lp == NULL && i++ < 20);
196 if (lp == NULL) {
197 printk("%s: couldn't allocate memory for descriptors\n",
198 dev->name);
199 return -ENOMEM;
202 memset(lp, 0, sizeof(struct sonic_local));
204 /* get the virtual dma address */
205 lp->cda_laddr = vdma_alloc(PHYSADDR(lp),sizeof(*lp));
206 if (lp->cda_laddr == ~0UL) {
207 printk("%s: couldn't get DMA page entry for "
208 "descriptors\n", dev->name);
209 return -ENOMEM;
212 lp->tda_laddr = lp->cda_laddr + sizeof (lp->cda);
213 lp->rra_laddr = lp->tda_laddr + sizeof (lp->tda);
214 lp->rda_laddr = lp->rra_laddr + sizeof (lp->rra);
216 /* allocate receive buffer area */
217 /* FIXME, maybe we should use skbs */
218 lp->rba = kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL);
219 if (!lp->rba) {
220 printk("%s: couldn't allocate receive buffers\n",
221 dev->name);
222 return -ENOMEM;
225 /* get virtual dma address */
226 lp->rba_laddr = vdma_alloc(PHYSADDR(lp->rba),
227 SONIC_NUM_RRS * SONIC_RBSIZE);
228 if (lp->rba_laddr == ~0UL) {
229 printk("%s: couldn't get DMA page entry for receive "
230 "buffers\n",dev->name);
231 return -ENOMEM;
234 /* now convert pointer to KSEG1 pointer */
235 lp->rba = (char *)KSEG1ADDR(lp->rba);
236 flush_cache_all();
237 dev->priv = (struct sonic_local *)KSEG1ADDR(lp);
240 lp = (struct sonic_local *)dev->priv;
241 dev->open = sonic_open;
242 dev->stop = sonic_close;
243 dev->hard_start_xmit = sonic_send_packet;
244 dev->get_stats = sonic_get_stats;
245 dev->set_multicast_list = &sonic_multicast_list;
246 dev->watchdog_timeo = TX_TIMEOUT;
249 * clear tally counter
251 SONIC_WRITE(SONIC_CRCT,0xffff);
252 SONIC_WRITE(SONIC_FAET,0xffff);
253 SONIC_WRITE(SONIC_MPT,0xffff);
255 /* Fill in the fields of the device structure with ethernet values. */
256 ether_setup(dev);
257 return 0;
261 * SONIC uses a normal IRQ
263 #define sonic_request_irq request_irq
264 #define sonic_free_irq free_irq
266 #define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x))
268 #include "sonic.c"