diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/macsonic.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/net/macsonic.c')
-rw-r--r-- | drivers/net/macsonic.c | 657 |
1 files changed, 657 insertions, 0 deletions
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c new file mode 100644 index 000000000000..be28c65de729 --- /dev/null +++ b/drivers/net/macsonic.c | |||
@@ -0,0 +1,657 @@ | |||
1 | /* | ||
2 | * macsonic.c | ||
3 | * | ||
4 | * (C) 1998 Alan Cox | ||
5 | * | ||
6 | * Debugging Andreas Ehliar, Michael Schmitz | ||
7 | * | ||
8 | * Based on code | ||
9 | * (C) 1996 by Thomas Bogendoerfer (tsbogend@bigbug.franken.de) | ||
10 | * | ||
11 | * This driver is based on work from Andreas Busse, but most of | ||
12 | * the code is rewritten. | ||
13 | * | ||
14 | * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de) | ||
15 | * | ||
16 | * A driver for the Mac onboard Sonic ethernet chip. | ||
17 | * | ||
18 | * 98/12/21 MSch: judged from tests on Q800, it's basically working, | ||
19 | * but eating up both receive and transmit resources | ||
20 | * and duplicating packets. Needs more testing. | ||
21 | * | ||
22 | * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed. | ||
23 | * | ||
24 | * 00/10/31 sammy@oh.verio.com: Updated driver for 2.4 kernels, fixed problems | ||
25 | * on centris. | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/ctype.h> | ||
31 | #include <linux/fcntl.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/init.h> | ||
34 | #include <linux/ioport.h> | ||
35 | #include <linux/in.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/string.h> | ||
38 | #include <linux/delay.h> | ||
39 | #include <linux/nubus.h> | ||
40 | #include <linux/errno.h> | ||
41 | #include <linux/netdevice.h> | ||
42 | #include <linux/etherdevice.h> | ||
43 | #include <linux/skbuff.h> | ||
44 | #include <linux/module.h> | ||
45 | #include <linux/bitops.h> | ||
46 | |||
47 | #include <asm/bootinfo.h> | ||
48 | #include <asm/system.h> | ||
49 | #include <asm/pgtable.h> | ||
50 | #include <asm/io.h> | ||
51 | #include <asm/hwtest.h> | ||
52 | #include <asm/dma.h> | ||
53 | #include <asm/macintosh.h> | ||
54 | #include <asm/macints.h> | ||
55 | #include <asm/mac_via.h> | ||
56 | |||
57 | #define SREGS_PAD(n) u16 n; | ||
58 | |||
59 | #include "sonic.h" | ||
60 | |||
61 | #define SONIC_READ(reg) \ | ||
62 | nubus_readl(base_addr+(reg)) | ||
63 | #define SONIC_WRITE(reg,val) \ | ||
64 | nubus_writel((val), base_addr+(reg)) | ||
65 | #define sonic_read(dev, reg) \ | ||
66 | nubus_readl((dev)->base_addr+(reg)) | ||
67 | #define sonic_write(dev, reg, val) \ | ||
68 | nubus_writel((val), (dev)->base_addr+(reg)) | ||
69 | |||
70 | |||
71 | static int sonic_debug; | ||
72 | static int sonic_version_printed; | ||
73 | |||
74 | static int reg_offset; | ||
75 | |||
76 | extern int mac_onboard_sonic_probe(struct net_device* dev); | ||
77 | extern int mac_nubus_sonic_probe(struct net_device* dev); | ||
78 | |||
79 | /* For onboard SONIC */ | ||
80 | #define ONBOARD_SONIC_REGISTERS 0x50F0A000 | ||
81 | #define ONBOARD_SONIC_PROM_BASE 0x50f08000 | ||
82 | |||
83 | enum macsonic_type { | ||
84 | MACSONIC_DUODOCK, | ||
85 | MACSONIC_APPLE, | ||
86 | MACSONIC_APPLE16, | ||
87 | MACSONIC_DAYNA, | ||
88 | MACSONIC_DAYNALINK | ||
89 | }; | ||
90 | |||
91 | /* For the built-in SONIC in the Duo Dock */ | ||
92 | #define DUODOCK_SONIC_REGISTERS 0xe10000 | ||
93 | #define DUODOCK_SONIC_PROM_BASE 0xe12000 | ||
94 | |||
95 | /* For Apple-style NuBus SONIC */ | ||
96 | #define APPLE_SONIC_REGISTERS 0 | ||
97 | #define APPLE_SONIC_PROM_BASE 0x40000 | ||
98 | |||
99 | /* Daynalink LC SONIC */ | ||
100 | #define DAYNALINK_PROM_BASE 0x400000 | ||
101 | |||
102 | /* For Dayna-style NuBus SONIC (haven't seen one yet) */ | ||
103 | #define DAYNA_SONIC_REGISTERS 0x180000 | ||
104 | /* This is what OpenBSD says. However, this is definitely in NuBus | ||
105 | ROM space so we should be able to get it by walking the NuBus | ||
106 | resource directories */ | ||
107 | #define DAYNA_SONIC_MAC_ADDR 0xffe004 | ||
108 | |||
109 | #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr) | ||
110 | |||
111 | struct net_device * __init macsonic_probe(int unit) | ||
112 | { | ||
113 | struct net_device *dev = alloc_etherdev(0); | ||
114 | int err; | ||
115 | |||
116 | if (!dev) | ||
117 | return ERR_PTR(-ENOMEM); | ||
118 | |||
119 | if (unit >= 0) | ||
120 | sprintf(dev->name, "eth%d", unit); | ||
121 | |||
122 | SET_MODULE_OWNER(dev); | ||
123 | |||
124 | /* This will catch fatal stuff like -ENOMEM as well as success */ | ||
125 | err = mac_onboard_sonic_probe(dev); | ||
126 | if (err == 0) | ||
127 | goto found; | ||
128 | if (err != -ENODEV) | ||
129 | goto out; | ||
130 | err = mac_nubus_sonic_probe(dev); | ||
131 | if (err) | ||
132 | goto out; | ||
133 | found: | ||
134 | err = register_netdev(dev); | ||
135 | if (err) | ||
136 | goto out1; | ||
137 | return dev; | ||
138 | out1: | ||
139 | kfree(dev->priv); | ||
140 | out: | ||
141 | free_netdev(dev); | ||
142 | return ERR_PTR(err); | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * For reversing the PROM address | ||
147 | */ | ||
148 | |||
149 | static unsigned char nibbletab[] = {0, 8, 4, 12, 2, 10, 6, 14, | ||
150 | 1, 9, 5, 13, 3, 11, 7, 15}; | ||
151 | |||
152 | static inline void bit_reverse_addr(unsigned char addr[6]) | ||
153 | { | ||
154 | int i; | ||
155 | |||
156 | for(i = 0; i < 6; i++) | ||
157 | addr[i] = ((nibbletab[addr[i] & 0xf] << 4) | | ||
158 | nibbletab[(addr[i] >> 4) &0xf]); | ||
159 | } | ||
160 | |||
161 | int __init macsonic_init(struct net_device* dev) | ||
162 | { | ||
163 | struct sonic_local* lp = NULL; | ||
164 | int i; | ||
165 | |||
166 | /* Allocate the entire chunk of memory for the descriptors. | ||
167 | Note that this cannot cross a 64K boundary. */ | ||
168 | for (i = 0; i < 20; i++) { | ||
169 | unsigned long desc_base, desc_top; | ||
170 | if((lp = kmalloc(sizeof(struct sonic_local), GFP_KERNEL | GFP_DMA)) == NULL) { | ||
171 | printk(KERN_ERR "%s: couldn't allocate descriptor buffers\n", dev->name); | ||
172 | return -ENOMEM; | ||
173 | } | ||
174 | |||
175 | desc_base = (unsigned long) lp; | ||
176 | desc_top = desc_base + sizeof(struct sonic_local); | ||
177 | if ((desc_top & 0xffff) >= (desc_base & 0xffff)) | ||
178 | break; | ||
179 | /* Hmm. try again (FIXME: does this actually work?) */ | ||
180 | kfree(lp); | ||
181 | printk(KERN_DEBUG | ||
182 | "%s: didn't get continguous chunk [%08lx - %08lx], trying again\n", | ||
183 | dev->name, desc_base, desc_top); | ||
184 | } | ||
185 | |||
186 | if (lp == NULL) { | ||
187 | printk(KERN_ERR "%s: tried 20 times to allocate descriptor buffers, giving up.\n", | ||
188 | dev->name); | ||
189 | return -ENOMEM; | ||
190 | } | ||
191 | |||
192 | dev->priv = lp; | ||
193 | |||
194 | #if 0 | ||
195 | /* this code is only here as a curiousity... mainly, where the | ||
196 | fuck did SONIC_BUS_SCALE come from, and what was it supposed | ||
197 | to do? the normal allocation works great for 32 bit stuffs.. */ | ||
198 | |||
199 | /* Now set up the pointers to point to the appropriate places */ | ||
200 | lp->cda = lp->sonic_desc; | ||
201 | lp->tda = lp->cda + (SIZEOF_SONIC_CDA * SONIC_BUS_SCALE(lp->dma_bitmode)); | ||
202 | lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS | ||
203 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | ||
204 | lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS | ||
205 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | ||
206 | |||
207 | #endif | ||
208 | |||
209 | memset(lp, 0, sizeof(struct sonic_local)); | ||
210 | |||
211 | lp->cda_laddr = (unsigned int)&(lp->cda); | ||
212 | lp->tda_laddr = (unsigned int)lp->tda; | ||
213 | lp->rra_laddr = (unsigned int)lp->rra; | ||
214 | lp->rda_laddr = (unsigned int)lp->rda; | ||
215 | |||
216 | /* FIXME, maybe we should use skbs */ | ||
217 | if ((lp->rba = (char *) | ||
218 | kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL | GFP_DMA)) == NULL) { | ||
219 | printk(KERN_ERR "%s: couldn't allocate receive buffers\n", dev->name); | ||
220 | dev->priv = NULL; | ||
221 | kfree(lp); | ||
222 | return -ENOMEM; | ||
223 | } | ||
224 | |||
225 | lp->rba_laddr = (unsigned int)lp->rba; | ||
226 | |||
227 | { | ||
228 | int rs, ds; | ||
229 | |||
230 | /* almost always 12*4096, but let's not take chances */ | ||
231 | rs = ((SONIC_NUM_RRS * SONIC_RBSIZE + 4095) / 4096) * 4096; | ||
232 | /* almost always under a page, but let's not take chances */ | ||
233 | ds = ((sizeof(struct sonic_local) + 4095) / 4096) * 4096; | ||
234 | kernel_set_cachemode(lp->rba, rs, IOMAP_NOCACHE_SER); | ||
235 | kernel_set_cachemode(lp, ds, IOMAP_NOCACHE_SER); | ||
236 | } | ||
237 | |||
238 | #if 0 | ||
239 | flush_cache_all(); | ||
240 | #endif | ||
241 | |||
242 | dev->open = sonic_open; | ||
243 | dev->stop = sonic_close; | ||
244 | dev->hard_start_xmit = sonic_send_packet; | ||
245 | dev->get_stats = sonic_get_stats; | ||
246 | dev->set_multicast_list = &sonic_multicast_list; | ||
247 | |||
248 | /* | ||
249 | * clear tally counter | ||
250 | */ | ||
251 | sonic_write(dev, SONIC_CRCT, 0xffff); | ||
252 | sonic_write(dev, SONIC_FAET, 0xffff); | ||
253 | sonic_write(dev, SONIC_MPT, 0xffff); | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev) | ||
259 | { | ||
260 | const int prom_addr = ONBOARD_SONIC_PROM_BASE; | ||
261 | int i; | ||
262 | |||
263 | /* On NuBus boards we can sometimes look in the ROM resources. | ||
264 | No such luck for comm-slot/onboard. */ | ||
265 | for(i = 0; i < 6; i++) | ||
266 | dev->dev_addr[i] = SONIC_READ_PROM(i); | ||
267 | |||
268 | /* Most of the time, the address is bit-reversed. The NetBSD | ||
269 | source has a rather long and detailed historical account of | ||
270 | why this is so. */ | ||
271 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && | ||
272 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && | ||
273 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) | ||
274 | bit_reverse_addr(dev->dev_addr); | ||
275 | else | ||
276 | return 0; | ||
277 | |||
278 | /* If we still have what seems to be a bogus address, we'll | ||
279 | look in the CAM. The top entry should be ours. */ | ||
280 | /* Danger! This only works if MacOS has already initialized | ||
281 | the card... */ | ||
282 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && | ||
283 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && | ||
284 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) | ||
285 | { | ||
286 | unsigned short val; | ||
287 | |||
288 | printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n"); | ||
289 | |||
290 | sonic_write(dev, SONIC_CMD, SONIC_CR_RST); | ||
291 | sonic_write(dev, SONIC_CEP, 15); | ||
292 | |||
293 | val = sonic_read(dev, SONIC_CAP2); | ||
294 | dev->dev_addr[5] = val >> 8; | ||
295 | dev->dev_addr[4] = val & 0xff; | ||
296 | val = sonic_read(dev, SONIC_CAP1); | ||
297 | dev->dev_addr[3] = val >> 8; | ||
298 | dev->dev_addr[2] = val & 0xff; | ||
299 | val = sonic_read(dev, SONIC_CAP0); | ||
300 | dev->dev_addr[1] = val >> 8; | ||
301 | dev->dev_addr[0] = val & 0xff; | ||
302 | |||
303 | printk(KERN_INFO "HW Address from CAM 15: "); | ||
304 | for (i = 0; i < 6; i++) { | ||
305 | printk("%2.2x", dev->dev_addr[i]); | ||
306 | if (i < 5) | ||
307 | printk(":"); | ||
308 | } | ||
309 | printk("\n"); | ||
310 | } else return 0; | ||
311 | |||
312 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && | ||
313 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && | ||
314 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) | ||
315 | { | ||
316 | /* | ||
317 | * Still nonsense ... messed up someplace! | ||
318 | */ | ||
319 | printk(KERN_ERR "macsonic: ERROR (INVALID MAC)\n"); | ||
320 | return -EIO; | ||
321 | } else return 0; | ||
322 | } | ||
323 | |||
324 | int __init mac_onboard_sonic_probe(struct net_device* dev) | ||
325 | { | ||
326 | /* Bwahahaha */ | ||
327 | static int once_is_more_than_enough; | ||
328 | int i; | ||
329 | int dma_bitmode; | ||
330 | |||
331 | if (once_is_more_than_enough) | ||
332 | return -ENODEV; | ||
333 | once_is_more_than_enough = 1; | ||
334 | |||
335 | if (!MACH_IS_MAC) | ||
336 | return -ENODEV; | ||
337 | |||
338 | printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); | ||
339 | |||
340 | if (macintosh_config->ether_type != MAC_ETHER_SONIC) | ||
341 | { | ||
342 | printk("none.\n"); | ||
343 | return -ENODEV; | ||
344 | } | ||
345 | |||
346 | /* Bogus probing, on the models which may or may not have | ||
347 | Ethernet (BTW, the Ethernet *is* always at the same | ||
348 | address, and nothing else lives there, at least if Apple's | ||
349 | documentation is to be believed) */ | ||
350 | if (macintosh_config->ident == MAC_MODEL_Q630 || | ||
351 | macintosh_config->ident == MAC_MODEL_P588 || | ||
352 | macintosh_config->ident == MAC_MODEL_C610) { | ||
353 | unsigned long flags; | ||
354 | int card_present; | ||
355 | |||
356 | local_irq_save(flags); | ||
357 | card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS); | ||
358 | local_irq_restore(flags); | ||
359 | |||
360 | if (!card_present) { | ||
361 | printk("none.\n"); | ||
362 | return -ENODEV; | ||
363 | } | ||
364 | } | ||
365 | |||
366 | printk("yes\n"); | ||
367 | |||
368 | /* Danger! My arms are flailing wildly! You *must* set this | ||
369 | before using sonic_read() */ | ||
370 | |||
371 | dev->base_addr = ONBOARD_SONIC_REGISTERS; | ||
372 | if (via_alt_mapping) | ||
373 | dev->irq = IRQ_AUTO_3; | ||
374 | else | ||
375 | dev->irq = IRQ_NUBUS_9; | ||
376 | |||
377 | if (!sonic_version_printed) { | ||
378 | printk(KERN_INFO "%s", version); | ||
379 | sonic_version_printed = 1; | ||
380 | } | ||
381 | printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n", | ||
382 | dev->name, dev->base_addr); | ||
383 | |||
384 | /* Now do a song and dance routine in an attempt to determine | ||
385 | the bus width */ | ||
386 | |||
387 | /* The PowerBook's SONIC is 16 bit always. */ | ||
388 | if (macintosh_config->ident == MAC_MODEL_PB520) { | ||
389 | reg_offset = 0; | ||
390 | dma_bitmode = 0; | ||
391 | } else if (macintosh_config->ident == MAC_MODEL_C610) { | ||
392 | reg_offset = 0; | ||
393 | dma_bitmode = 1; | ||
394 | } else { | ||
395 | /* Some of the comm-slot cards are 16 bit. But some | ||
396 | of them are not. The 32-bit cards use offset 2 and | ||
397 | pad with zeroes or sometimes ones (I think...) | ||
398 | Therefore, if we try offset 0 and get a silicon | ||
399 | revision of 0, we assume 16 bit. */ | ||
400 | int sr; | ||
401 | |||
402 | /* Technically this is not necessary since we zeroed | ||
403 | it above */ | ||
404 | reg_offset = 0; | ||
405 | dma_bitmode = 0; | ||
406 | sr = sonic_read(dev, SONIC_SR); | ||
407 | if (sr == 0 || sr == 0xffff) { | ||
408 | reg_offset = 2; | ||
409 | /* 83932 is 0x0004, 83934 is 0x0100 or 0x0101 */ | ||
410 | sr = sonic_read(dev, SONIC_SR); | ||
411 | dma_bitmode = 1; | ||
412 | |||
413 | } | ||
414 | printk(KERN_INFO | ||
415 | "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", | ||
416 | dev->name, sr, dma_bitmode?32:16, reg_offset); | ||
417 | } | ||
418 | |||
419 | |||
420 | /* this carries my sincere apologies -- by the time I got to updating | ||
421 | the driver, support for "reg_offsets" appeares nowhere in the sonic | ||
422 | code, going back for over a year. Fortunately, my Mac does't seem | ||
423 | to use whatever this was. | ||
424 | |||
425 | If you know how this is supposed to be implemented, either fix it, | ||
426 | or contact me (sammy@oh.verio.com) to explain what it is. --Sam */ | ||
427 | |||
428 | if(reg_offset) { | ||
429 | printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name); | ||
430 | return -ENODEV; | ||
431 | } | ||
432 | |||
433 | /* Software reset, then initialize control registers. */ | ||
434 | sonic_write(dev, SONIC_CMD, SONIC_CR_RST); | ||
435 | sonic_write(dev, SONIC_DCR, SONIC_DCR_BMS | | ||
436 | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_EXBUS | | ||
437 | (dma_bitmode ? SONIC_DCR_DW : 0)); | ||
438 | |||
439 | /* This *must* be written back to in order to restore the | ||
440 | extended programmable output bits */ | ||
441 | sonic_write(dev, SONIC_DCR2, 0); | ||
442 | |||
443 | /* Clear *and* disable interrupts to be on the safe side */ | ||
444 | sonic_write(dev, SONIC_ISR,0x7fff); | ||
445 | sonic_write(dev, SONIC_IMR,0); | ||
446 | |||
447 | /* Now look for the MAC address. */ | ||
448 | if (mac_onboard_sonic_ethernet_addr(dev) != 0) | ||
449 | return -ENODEV; | ||
450 | |||
451 | printk(KERN_INFO "MAC "); | ||
452 | for (i = 0; i < 6; i++) { | ||
453 | printk("%2.2x", dev->dev_addr[i]); | ||
454 | if (i < 5) | ||
455 | printk(":"); | ||
456 | } | ||
457 | |||
458 | printk(" IRQ %d\n", dev->irq); | ||
459 | |||
460 | /* Shared init code */ | ||
461 | return macsonic_init(dev); | ||
462 | } | ||
463 | |||
464 | int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev, | ||
465 | unsigned long prom_addr, | ||
466 | int id) | ||
467 | { | ||
468 | int i; | ||
469 | for(i = 0; i < 6; i++) | ||
470 | dev->dev_addr[i] = SONIC_READ_PROM(i); | ||
471 | /* For now we are going to assume that they're all bit-reversed */ | ||
472 | bit_reverse_addr(dev->dev_addr); | ||
473 | |||
474 | return 0; | ||
475 | } | ||
476 | |||
477 | int __init macsonic_ident(struct nubus_dev* ndev) | ||
478 | { | ||
479 | if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC && | ||
480 | ndev->dr_sw == NUBUS_DRSW_SONIC_LC) | ||
481 | return MACSONIC_DAYNALINK; | ||
482 | if (ndev->dr_hw == NUBUS_DRHW_SONIC && | ||
483 | ndev->dr_sw == NUBUS_DRSW_APPLE) { | ||
484 | /* There has to be a better way to do this... */ | ||
485 | if (strstr(ndev->board->name, "DuoDock")) | ||
486 | return MACSONIC_DUODOCK; | ||
487 | else | ||
488 | return MACSONIC_APPLE; | ||
489 | } | ||
490 | return -1; | ||
491 | } | ||
492 | |||
493 | int __init mac_nubus_sonic_probe(struct net_device* dev) | ||
494 | { | ||
495 | static int slots; | ||
496 | struct nubus_dev* ndev = NULL; | ||
497 | unsigned long base_addr, prom_addr; | ||
498 | u16 sonic_dcr; | ||
499 | int id; | ||
500 | int i; | ||
501 | int dma_bitmode; | ||
502 | |||
503 | /* Find the first SONIC that hasn't been initialized already */ | ||
504 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, | ||
505 | NUBUS_TYPE_ETHERNET, ndev)) != NULL) | ||
506 | { | ||
507 | /* Have we seen it already? */ | ||
508 | if (slots & (1<<ndev->board->slot)) | ||
509 | continue; | ||
510 | slots |= 1<<ndev->board->slot; | ||
511 | |||
512 | /* Is it one of ours? */ | ||
513 | if ((id = macsonic_ident(ndev)) != -1) | ||
514 | break; | ||
515 | } | ||
516 | |||
517 | if (ndev == NULL) | ||
518 | return -ENODEV; | ||
519 | |||
520 | switch (id) { | ||
521 | case MACSONIC_DUODOCK: | ||
522 | base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS; | ||
523 | prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE; | ||
524 | sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 | ||
525 | | SONIC_DCR_TFT0; | ||
526 | reg_offset = 2; | ||
527 | dma_bitmode = 1; | ||
528 | break; | ||
529 | case MACSONIC_APPLE: | ||
530 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; | ||
531 | prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; | ||
532 | sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0; | ||
533 | reg_offset = 0; | ||
534 | dma_bitmode = 1; | ||
535 | break; | ||
536 | case MACSONIC_APPLE16: | ||
537 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; | ||
538 | prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; | ||
539 | sonic_dcr = SONIC_DCR_EXBUS | ||
540 | | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | ||
541 | | SONIC_DCR_PO1 | SONIC_DCR_BMS; | ||
542 | reg_offset = 0; | ||
543 | dma_bitmode = 0; | ||
544 | break; | ||
545 | case MACSONIC_DAYNALINK: | ||
546 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; | ||
547 | prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE; | ||
548 | sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | ||
549 | | SONIC_DCR_PO1 | SONIC_DCR_BMS; | ||
550 | reg_offset = 0; | ||
551 | dma_bitmode = 0; | ||
552 | break; | ||
553 | case MACSONIC_DAYNA: | ||
554 | base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS; | ||
555 | prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR; | ||
556 | sonic_dcr = SONIC_DCR_BMS | ||
557 | | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1; | ||
558 | reg_offset = 0; | ||
559 | dma_bitmode = 0; | ||
560 | break; | ||
561 | default: | ||
562 | printk(KERN_ERR "macsonic: WTF, id is %d\n", id); | ||
563 | return -ENODEV; | ||
564 | } | ||
565 | |||
566 | /* Danger! My arms are flailing wildly! You *must* set this | ||
567 | before using sonic_read() */ | ||
568 | dev->base_addr = base_addr; | ||
569 | dev->irq = SLOT2IRQ(ndev->board->slot); | ||
570 | |||
571 | if (!sonic_version_printed) { | ||
572 | printk(KERN_INFO "%s", version); | ||
573 | sonic_version_printed = 1; | ||
574 | } | ||
575 | printk(KERN_INFO "%s: %s in slot %X\n", | ||
576 | dev->name, ndev->board->name, ndev->board->slot); | ||
577 | printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", | ||
578 | dev->name, sonic_read(dev, SONIC_SR), dma_bitmode?32:16, reg_offset); | ||
579 | |||
580 | if(reg_offset) { | ||
581 | printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name); | ||
582 | return -ENODEV; | ||
583 | } | ||
584 | |||
585 | /* Software reset, then initialize control registers. */ | ||
586 | sonic_write(dev, SONIC_CMD, SONIC_CR_RST); | ||
587 | sonic_write(dev, SONIC_DCR, sonic_dcr | ||
588 | | (dma_bitmode ? SONIC_DCR_DW : 0)); | ||
589 | |||
590 | /* Clear *and* disable interrupts to be on the safe side */ | ||
591 | sonic_write(dev, SONIC_ISR,0x7fff); | ||
592 | sonic_write(dev, SONIC_IMR,0); | ||
593 | |||
594 | /* Now look for the MAC address. */ | ||
595 | if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0) | ||
596 | return -ENODEV; | ||
597 | |||
598 | printk(KERN_INFO "MAC "); | ||
599 | for (i = 0; i < 6; i++) { | ||
600 | printk("%2.2x", dev->dev_addr[i]); | ||
601 | if (i < 5) | ||
602 | printk(":"); | ||
603 | } | ||
604 | printk(" IRQ %d\n", dev->irq); | ||
605 | |||
606 | /* Shared init code */ | ||
607 | return macsonic_init(dev); | ||
608 | } | ||
609 | |||
610 | #ifdef MODULE | ||
611 | static struct net_device *dev_macsonic; | ||
612 | |||
613 | MODULE_PARM(sonic_debug, "i"); | ||
614 | MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)"); | ||
615 | |||
616 | int | ||
617 | init_module(void) | ||
618 | { | ||
619 | dev_macsonic = macsonic_probe(-1); | ||
620 | if (IS_ERR(dev_macsonic)) { | ||
621 | printk(KERN_WARNING "macsonic.c: No card found\n"); | ||
622 | return PTR_ERR(dev_macsonic); | ||
623 | } | ||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | void | ||
628 | cleanup_module(void) | ||
629 | { | ||
630 | unregister_netdev(dev_macsonic); | ||
631 | kfree(dev_macsonic->priv); | ||
632 | free_netdev(dev_macsonic); | ||
633 | } | ||
634 | #endif /* MODULE */ | ||
635 | |||
636 | |||
637 | #define vdma_alloc(foo, bar) ((u32)foo) | ||
638 | #define vdma_free(baz) | ||
639 | #define sonic_chiptomem(bat) (bat) | ||
640 | #define PHYSADDR(quux) (quux) | ||
641 | #define CPHYSADDR(quux) (quux) | ||
642 | |||
643 | #define sonic_request_irq request_irq | ||
644 | #define sonic_free_irq free_irq | ||
645 | |||
646 | #include "sonic.c" | ||
647 | |||
648 | /* | ||
649 | * Local variables: | ||
650 | * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -c -o macsonic.o macsonic.c" | ||
651 | * version-control: t | ||
652 | * kept-new-versions: 5 | ||
653 | * c-indent-level: 8 | ||
654 | * tab-width: 8 | ||
655 | * End: | ||
656 | * | ||
657 | */ | ||