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