Pull vector-domain into release branch
[sfrench/cifs-2.6.git] / drivers / net / tokenring / madgemc.c
1 /*
2  *  madgemc.c: Driver for the Madge Smart 16/4 MC16 MCA token ring card.
3  *
4  *  Written 2000 by Adam Fritzler
5  *
6  *  This software may be used and distributed according to the terms
7  *  of the GNU General Public License, incorporated herein by reference.
8  *
9  *  This driver module supports the following cards:
10  *      - Madge Smart 16/4 Ringnode MC16
11  *      - Madge Smart 16/4 Ringnode MC32 (??)
12  *
13  *  Maintainer(s):
14  *    AF        Adam Fritzler           mid@auk.cx
15  *
16  *  Modification History:
17  *      16-Jan-00       AF      Created
18  *
19  */
20 static const char version[] = "madgemc.c: v0.91 23/01/2000 by Adam Fritzler\n";
21
22 #include <linux/module.h>
23 #include <linux/mca.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/init.h>
27 #include <linux/netdevice.h>
28 #include <linux/trdevice.h>
29
30 #include <asm/system.h>
31 #include <asm/io.h>
32 #include <asm/irq.h>
33
34 #include "tms380tr.h"
35 #include "madgemc.h"            /* Madge-specific constants */
36
37 #define MADGEMC_IO_EXTENT 32
38 #define MADGEMC_SIF_OFFSET 0x08
39
40 struct card_info {
41         /*
42          * These are read from the BIA ROM.
43          */
44         unsigned int manid;
45         unsigned int cardtype;
46         unsigned int cardrev;
47         unsigned int ramsize;
48         
49         /*
50          * These are read from the MCA POS registers.  
51          */
52         unsigned int burstmode:2;
53         unsigned int fairness:1; /* 0 = Fair, 1 = Unfair */
54         unsigned int arblevel:4;
55         unsigned int ringspeed:2; /* 0 = 4mb, 1 = 16, 2 = Auto/none */
56         unsigned int cabletype:1; /* 0 = RJ45, 1 = DB9 */
57 };
58
59 static int madgemc_open(struct net_device *dev);
60 static int madgemc_close(struct net_device *dev);
61 static int madgemc_chipset_init(struct net_device *dev);
62 static void madgemc_read_rom(struct net_device *dev, struct card_info *card);
63 static unsigned short madgemc_setnselout_pins(struct net_device *dev);
64 static void madgemc_setcabletype(struct net_device *dev, int type);
65
66 static int madgemc_mcaproc(char *buf, int slot, void *d);
67
68 static void madgemc_setregpage(struct net_device *dev, int page);
69 static void madgemc_setsifsel(struct net_device *dev, int val);
70 static void madgemc_setint(struct net_device *dev, int val);
71
72 static irqreturn_t madgemc_interrupt(int irq, void *dev_id);
73
74 /*
75  * These work around paging, however they don't guarentee you're on the
76  * right page.
77  */
78 #define SIFREADB(reg) (inb(dev->base_addr + ((reg<0x8)?reg:reg-0x8)))
79 #define SIFWRITEB(val, reg) (outb(val, dev->base_addr + ((reg<0x8)?reg:reg-0x8)))
80 #define SIFREADW(reg) (inw(dev->base_addr + ((reg<0x8)?reg:reg-0x8)))
81 #define SIFWRITEW(val, reg) (outw(val, dev->base_addr + ((reg<0x8)?reg:reg-0x8)))
82
83 /*
84  * Read a byte-length value from the register.
85  */
86 static unsigned short madgemc_sifreadb(struct net_device *dev, unsigned short reg)
87 {
88         unsigned short ret;
89         if (reg<0x8)    
90                 ret = SIFREADB(reg);
91         else {
92                 madgemc_setregpage(dev, 1);     
93                 ret = SIFREADB(reg);
94                 madgemc_setregpage(dev, 0);
95         }
96         return ret;
97 }
98
99 /*
100  * Write a byte-length value to a register.
101  */
102 static void madgemc_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
103 {
104         if (reg<0x8)
105                 SIFWRITEB(val, reg);
106         else {
107                 madgemc_setregpage(dev, 1);
108                 SIFWRITEB(val, reg);
109                 madgemc_setregpage(dev, 0);
110         }
111         return;
112 }
113
114 /*
115  * Read a word-length value from a register
116  */
117 static unsigned short madgemc_sifreadw(struct net_device *dev, unsigned short reg)
118 {
119         unsigned short ret;
120         if (reg<0x8)    
121                 ret = SIFREADW(reg);
122         else {
123                 madgemc_setregpage(dev, 1);     
124                 ret = SIFREADW(reg);
125                 madgemc_setregpage(dev, 0);
126         }
127         return ret;
128 }
129
130 /*
131  * Write a word-length value to a register.
132  */
133 static void madgemc_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
134 {
135         if (reg<0x8)
136                 SIFWRITEW(val, reg);
137         else {
138                 madgemc_setregpage(dev, 1);
139                 SIFWRITEW(val, reg);
140                 madgemc_setregpage(dev, 0);
141         }
142         return;
143 }
144
145
146
147 static int __devinit madgemc_probe(struct device *device)
148 {       
149         static int versionprinted;
150         struct net_device *dev;
151         struct net_local *tp;
152         struct card_info *card;
153         struct mca_device *mdev = to_mca_device(device);
154         int ret = 0, i = 0;
155
156         if (versionprinted++ == 0)
157                 printk("%s", version);
158
159         if(mca_device_claimed(mdev))
160                 return -EBUSY;
161         mca_device_set_claim(mdev, 1);
162
163         dev = alloc_trdev(sizeof(struct net_local));
164         if (!dev) {
165                 printk("madgemc: unable to allocate dev space\n");
166                 mca_device_set_claim(mdev, 0);
167                 ret = -ENOMEM;
168                 goto getout;
169         }
170
171         SET_MODULE_OWNER(dev);
172         dev->dma = 0;
173
174         card = kmalloc(sizeof(struct card_info), GFP_KERNEL);
175         if (card==NULL) {
176                 printk("madgemc: unable to allocate card struct\n");
177                 ret = -ENOMEM;
178                 goto getout1;
179         }
180
181         /*
182          * Parse configuration information.  This all comes
183          * directly from the publicly available @002d.ADF.
184          * Get it from Madge or your local ADF library.
185          */
186
187         /*
188          * Base address 
189          */
190         dev->base_addr = 0x0a20 + 
191                 ((mdev->pos[2] & MC16_POS2_ADDR2)?0x0400:0) +
192                 ((mdev->pos[0] & MC16_POS0_ADDR1)?0x1000:0) +
193                 ((mdev->pos[3] & MC16_POS3_ADDR3)?0x2000:0);
194
195         /*
196          * Interrupt line
197          */
198         switch(mdev->pos[0] >> 6) { /* upper two bits */
199                 case 0x1: dev->irq = 3; break;
200                 case 0x2: dev->irq = 9; break; /* IRQ 2 = IRQ 9 */
201                 case 0x3: dev->irq = 10; break;
202                 default: dev->irq = 0; break;
203         }
204
205         if (dev->irq == 0) {
206                 printk("%s: invalid IRQ\n", dev->name);
207                 ret = -EBUSY;
208                 goto getout2;
209         }
210
211         if (!request_region(dev->base_addr, MADGEMC_IO_EXTENT, 
212                            "madgemc")) {
213                 printk(KERN_INFO "madgemc: unable to setup Smart MC in slot %d because of I/O base conflict at 0x%04lx\n", mdev->slot, dev->base_addr);
214                 dev->base_addr += MADGEMC_SIF_OFFSET;
215                 ret = -EBUSY;
216                 goto getout2;
217         }
218         dev->base_addr += MADGEMC_SIF_OFFSET;
219         
220         /*
221          * Arbitration Level
222          */
223         card->arblevel = ((mdev->pos[0] >> 1) & 0x7) + 8;
224
225         /*
226          * Burst mode and Fairness
227          */
228         card->burstmode = ((mdev->pos[2] >> 6) & 0x3);
229         card->fairness = ((mdev->pos[2] >> 4) & 0x1);
230
231         /*
232          * Ring Speed
233          */
234         if ((mdev->pos[1] >> 2)&0x1)
235                 card->ringspeed = 2; /* not selected */
236         else if ((mdev->pos[2] >> 5) & 0x1)
237                 card->ringspeed = 1; /* 16Mb */
238         else
239                 card->ringspeed = 0; /* 4Mb */
240
241         /* 
242          * Cable type
243          */
244         if ((mdev->pos[1] >> 6)&0x1)
245                 card->cabletype = 1; /* STP/DB9 */
246         else
247                 card->cabletype = 0; /* UTP/RJ-45 */
248
249
250         /* 
251          * ROM Info. This requires us to actually twiddle
252          * bits on the card, so we must ensure above that 
253          * the base address is free of conflict (request_region above).
254          */
255         madgemc_read_rom(dev, card);
256                 
257         if (card->manid != 0x4d) { /* something went wrong */
258                 printk(KERN_INFO "%s: Madge MC ROM read failed (unknown manufacturer ID %02x)\n", dev->name, card->manid);
259                 goto getout3;
260         }
261                 
262         if ((card->cardtype != 0x08) && (card->cardtype != 0x0d)) {
263                 printk(KERN_INFO "%s: Madge MC ROM read failed (unknown card ID %02x)\n", dev->name, card->cardtype);
264                 ret = -EIO;
265                 goto getout3;
266         }
267                
268         /* All cards except Rev 0 and 1 MC16's have 256kb of RAM */
269         if ((card->cardtype == 0x08) && (card->cardrev <= 0x01))
270                 card->ramsize = 128;
271         else
272                 card->ramsize = 256;
273
274         printk("%s: %s Rev %d at 0x%04lx IRQ %d\n", 
275                dev->name, 
276                (card->cardtype == 0x08)?MADGEMC16_CARDNAME:
277                MADGEMC32_CARDNAME, card->cardrev, 
278                dev->base_addr, dev->irq);
279
280         if (card->cardtype == 0x0d)
281                 printk("%s:     Warning: MC32 support is experimental and highly untested\n", dev->name);
282         
283         if (card->ringspeed==2) { /* Unknown */
284                 printk("%s:     Warning: Ring speed not set in POS -- Please run the reference disk and set it!\n", dev->name);
285                 card->ringspeed = 1; /* default to 16mb */
286         }
287                 
288         printk("%s:     RAM Size: %dKB\n", dev->name, card->ramsize);
289
290         printk("%s:     Ring Speed: %dMb/sec on %s\n", dev->name, 
291                (card->ringspeed)?16:4, 
292                card->cabletype?"STP/DB9":"UTP/RJ-45");
293         printk("%s:     Arbitration Level: %d\n", dev->name, 
294                card->arblevel);
295
296         printk("%s:     Burst Mode: ", dev->name);
297         switch(card->burstmode) {
298                 case 0: printk("Cycle steal"); break;
299                 case 1: printk("Limited burst"); break;
300                 case 2: printk("Delayed release"); break;
301                 case 3: printk("Immediate release"); break;
302         }
303         printk(" (%s)\n", (card->fairness)?"Unfair":"Fair");
304
305
306         /* 
307          * Enable SIF before we assign the interrupt handler,
308          * just in case we get spurious interrupts that need
309          * handling.
310          */ 
311         outb(0, dev->base_addr + MC_CONTROL_REG0); /* sanity */
312         madgemc_setsifsel(dev, 1);
313         if (request_irq(dev->irq, madgemc_interrupt, IRQF_SHARED,
314                        "madgemc", dev)) {
315                 ret = -EBUSY;
316                 goto getout3;
317         }
318
319         madgemc_chipset_init(dev); /* enables interrupts! */
320         madgemc_setcabletype(dev, card->cabletype);
321
322         /* Setup MCA structures */
323         mca_device_set_name(mdev, (card->cardtype == 0x08)?MADGEMC16_CARDNAME:MADGEMC32_CARDNAME);
324         mca_set_adapter_procfn(mdev->slot, madgemc_mcaproc, dev);
325
326         printk("%s:     Ring Station Address: ", dev->name);
327         printk("%2.2x", dev->dev_addr[0]);
328         for (i = 1; i < 6; i++)
329                 printk(":%2.2x", dev->dev_addr[i]);
330         printk("\n");
331
332         if (tmsdev_init(dev, device)) {
333                 printk("%s: unable to get memory for dev->priv.\n", 
334                        dev->name);
335                 ret = -ENOMEM;
336                 goto getout4;
337         }
338         tp = netdev_priv(dev);
339
340         /* 
341          * The MC16 is physically a 32bit card.  However, Madge
342          * insists on calling it 16bit, so I'll assume here that
343          * they know what they're talking about.  Cut off DMA
344          * at 16mb.
345          */
346         tp->setnselout = madgemc_setnselout_pins;
347         tp->sifwriteb = madgemc_sifwriteb;
348         tp->sifreadb = madgemc_sifreadb;
349         tp->sifwritew = madgemc_sifwritew;
350         tp->sifreadw = madgemc_sifreadw;
351         tp->DataRate = (card->ringspeed)?SPEED_16:SPEED_4;
352
353         memcpy(tp->ProductID, "Madge MCA 16/4    ", PROD_ID_SIZE + 1);
354
355         dev->open = madgemc_open;
356         dev->stop = madgemc_close;
357
358         tp->tmspriv = card;
359         dev_set_drvdata(device, dev);
360
361         if (register_netdev(dev) == 0)
362                 return 0;
363
364         dev_set_drvdata(device, NULL);
365         ret = -ENOMEM;
366 getout4:
367         free_irq(dev->irq, dev);
368 getout3:
369         release_region(dev->base_addr-MADGEMC_SIF_OFFSET, 
370                        MADGEMC_IO_EXTENT); 
371 getout2:
372         kfree(card);
373 getout1:
374         free_netdev(dev);
375 getout:
376         mca_device_set_claim(mdev, 0);
377         return ret;
378 }
379
380 /*
381  * Handle interrupts generated by the card
382  *
383  * The MicroChannel Madge cards need slightly more handling
384  * after an interrupt than other TMS380 cards do.
385  *
386  * First we must make sure it was this card that generated the
387  * interrupt (since interrupt sharing is allowed).  Then,
388  * because we're using level-triggered interrupts (as is
389  * standard on MCA), we must toggle the interrupt line
390  * on the card in order to claim and acknowledge the interrupt.
391  * Once that is done, the interrupt should be handlable in
392  * the normal tms380tr_interrupt() routine.
393  *
394  * There's two ways we can check to see if the interrupt is ours,
395  * both with their own disadvantages...
396  *
397  * 1)   Read in the SIFSTS register from the TMS controller.  This
398  *      is guarenteed to be accurate, however, there's a fairly
399  *      large performance penalty for doing so: the Madge chips
400  *      must request the register from the Eagle, the Eagle must
401  *      read them from its internal bus, and then take the route
402  *      back out again, for a 16bit read.  
403  *
404  * 2)   Use the MC_CONTROL_REG0_SINTR bit from the Madge ASICs.
405  *      The major disadvantage here is that the accuracy of the
406  *      bit is in question.  However, it cuts out the extra read
407  *      cycles it takes to read the Eagle's SIF, as its only an
408  *      8bit read, and theoretically the Madge bit is directly
409  *      connected to the interrupt latch coming out of the Eagle
410  *      hardware (that statement is not verified).  
411  *
412  * I can't determine which of these methods has the best win.  For now,
413  * we make a compromise.  Use the Madge way for the first interrupt,
414  * which should be the fast-path, and then once we hit the first 
415  * interrupt, keep on trying using the SIF method until we've
416  * exhausted all contiguous interrupts.
417  *
418  */
419 static irqreturn_t madgemc_interrupt(int irq, void *dev_id)
420 {
421         int pending,reg1;
422         struct net_device *dev;
423
424         if (!dev_id) {
425                 printk("madgemc_interrupt: was not passed a dev_id!\n");
426                 return IRQ_NONE;
427         }
428
429         dev = (struct net_device *)dev_id;
430
431         /* Make sure its really us. -- the Madge way */
432         pending = inb(dev->base_addr + MC_CONTROL_REG0);
433         if (!(pending & MC_CONTROL_REG0_SINTR))
434                 return IRQ_NONE; /* not our interrupt */
435
436         /*
437          * Since we're level-triggered, we may miss the rising edge
438          * of the next interrupt while we're off handling this one,
439          * so keep checking until the SIF verifies that it has nothing
440          * left for us to do.
441          */
442         pending = STS_SYSTEM_IRQ;
443         do {
444                 if (pending & STS_SYSTEM_IRQ) {
445
446                         /* Toggle the interrupt to reset the latch on card */
447                         reg1 = inb(dev->base_addr + MC_CONTROL_REG1);
448                         outb(reg1 ^ MC_CONTROL_REG1_SINTEN, 
449                              dev->base_addr + MC_CONTROL_REG1);
450                         outb(reg1, dev->base_addr + MC_CONTROL_REG1);
451
452                         /* Continue handling as normal */
453                         tms380tr_interrupt(irq, dev_id);
454
455                         pending = SIFREADW(SIFSTS); /* restart - the SIF way */
456
457                 } else
458                         return IRQ_HANDLED; 
459         } while (1);
460
461         return IRQ_HANDLED; /* not reachable */
462 }
463
464 /*
465  * Set the card to the prefered ring speed.
466  *
467  * Unlike newer cards, the MC16/32 have their speed selection
468  * circuit connected to the Madge ASICs and not to the TMS380
469  * NSELOUT pins. Set the ASIC bits correctly here, and return 
470  * zero to leave the TMS NSELOUT bits unaffected.
471  *
472  */
473 unsigned short madgemc_setnselout_pins(struct net_device *dev)
474 {
475         unsigned char reg1;
476         struct net_local *tp = netdev_priv(dev);
477         
478         reg1 = inb(dev->base_addr + MC_CONTROL_REG1);
479
480         if(tp->DataRate == SPEED_16)
481                 reg1 |= MC_CONTROL_REG1_SPEED_SEL; /* add for 16mb */
482         else if (reg1 & MC_CONTROL_REG1_SPEED_SEL)
483                 reg1 ^= MC_CONTROL_REG1_SPEED_SEL; /* remove for 4mb */
484         outb(reg1, dev->base_addr + MC_CONTROL_REG1);
485
486         return 0; /* no change */
487 }
488
489 /*
490  * Set the register page.  This equates to the SRSX line
491  * on the TMS380Cx6.
492  *
493  * Register selection is normally done via three contiguous
494  * bits.  However, some boards (such as the MC16/32) use only
495  * two bits, plus a separate bit in the glue chip.  This
496  * sets the SRSX bit (the top bit).  See page 4-17 in the
497  * Yellow Book for which registers are affected.
498  *
499  */
500 static void madgemc_setregpage(struct net_device *dev, int page)
501 {       
502         static int reg1;
503
504         reg1 = inb(dev->base_addr + MC_CONTROL_REG1);
505         if ((page == 0) && (reg1 & MC_CONTROL_REG1_SRSX)) {
506                 outb(reg1 ^ MC_CONTROL_REG1_SRSX, 
507                      dev->base_addr + MC_CONTROL_REG1);
508         }
509         else if (page == 1) {
510                 outb(reg1 | MC_CONTROL_REG1_SRSX, 
511                      dev->base_addr + MC_CONTROL_REG1);
512         }
513         reg1 = inb(dev->base_addr + MC_CONTROL_REG1);
514
515         return;
516 }
517
518 /*
519  * The SIF registers are not mapped into register space by default
520  * Set this to 1 to map them, 0 to map the BIA ROM.
521  *
522  */
523 static void madgemc_setsifsel(struct net_device *dev, int val)
524 {
525         unsigned int reg0;
526
527         reg0 = inb(dev->base_addr + MC_CONTROL_REG0);
528         if ((val == 0) && (reg0 & MC_CONTROL_REG0_SIFSEL)) {
529                 outb(reg0 ^ MC_CONTROL_REG0_SIFSEL, 
530                      dev->base_addr + MC_CONTROL_REG0);
531         } else if (val == 1) {
532                 outb(reg0 | MC_CONTROL_REG0_SIFSEL, 
533                      dev->base_addr + MC_CONTROL_REG0);
534         }       
535         reg0 = inb(dev->base_addr + MC_CONTROL_REG0);
536
537         return;
538 }
539
540 /*
541  * Enable SIF interrupts
542  *
543  * This does not enable interrupts in the SIF, but rather
544  * enables SIF interrupts to be passed onto the host.
545  *
546  */
547 static void madgemc_setint(struct net_device *dev, int val)
548 {
549         unsigned int reg1;
550
551         reg1 = inb(dev->base_addr + MC_CONTROL_REG1);
552         if ((val == 0) && (reg1 & MC_CONTROL_REG1_SINTEN)) {
553                 outb(reg1 ^ MC_CONTROL_REG1_SINTEN, 
554                      dev->base_addr + MC_CONTROL_REG1);
555         } else if (val == 1) {
556                 outb(reg1 | MC_CONTROL_REG1_SINTEN, 
557                      dev->base_addr + MC_CONTROL_REG1);
558         }
559
560         return;
561 }
562
563 /*
564  * Cable type is set via control register 7. Bit zero high
565  * for UTP, low for STP.
566  */
567 static void madgemc_setcabletype(struct net_device *dev, int type)
568 {
569         outb((type==0)?MC_CONTROL_REG7_CABLEUTP:MC_CONTROL_REG7_CABLESTP,
570              dev->base_addr + MC_CONTROL_REG7);
571 }
572
573 /*
574  * Enable the functions of the Madge chipset needed for
575  * full working order. 
576  */
577 static int madgemc_chipset_init(struct net_device *dev)
578 {
579         outb(0, dev->base_addr + MC_CONTROL_REG1); /* pull SRESET low */
580         tms380tr_wait(100); /* wait for card to reset */
581
582         /* bring back into normal operating mode */
583         outb(MC_CONTROL_REG1_NSRESET, dev->base_addr + MC_CONTROL_REG1);
584
585         /* map SIF registers */
586         madgemc_setsifsel(dev, 1);
587
588         /* enable SIF interrupts */
589         madgemc_setint(dev, 1); 
590
591         return 0;
592 }
593
594 /*
595  * Disable the board, and put back into power-up state.
596  */
597 static void madgemc_chipset_close(struct net_device *dev)
598 {
599         /* disable interrupts */
600         madgemc_setint(dev, 0);
601         /* unmap SIF registers */
602         madgemc_setsifsel(dev, 0);
603
604         return;
605 }
606
607 /*
608  * Read the card type (MC16 or MC32) from the card.
609  *
610  * The configuration registers are stored in two separate
611  * pages.  Pages are flipped by clearing bit 3 of CONTROL_REG0 (PAGE)
612  * for page zero, or setting bit 3 for page one.
613  *
614  * Page zero contains the following data:
615  *      Byte 0: Manufacturer ID (0x4D -- ASCII "M")
616  *      Byte 1: Card type:
617  *                      0x08 for MC16
618  *                      0x0D for MC32
619  *      Byte 2: Card revision
620  *      Byte 3: Mirror of POS config register 0
621  *      Byte 4: Mirror of POS 1
622  *      Byte 5: Mirror of POS 2
623  *
624  * Page one contains the following data:
625  *      Byte 0: Unused
626  *      Byte 1-6: BIA, MSB to LSB.
627  *
628  * Note that to read the BIA, we must unmap the SIF registers
629  * by clearing bit 2 of CONTROL_REG0 (SIFSEL), as the data
630  * will reside in the same logical location.  For this reason,
631  * _never_ read the BIA while the Eagle processor is running!
632  * The SIF will be completely inaccessible until the BIA operation
633  * is complete.
634  *
635  */
636 static void madgemc_read_rom(struct net_device *dev, struct card_info *card)
637 {
638         unsigned long ioaddr;
639         unsigned char reg0, reg1, tmpreg0, i;
640
641         ioaddr = dev->base_addr;
642
643         reg0 = inb(ioaddr + MC_CONTROL_REG0);
644         reg1 = inb(ioaddr + MC_CONTROL_REG1);
645
646         /* Switch to page zero and unmap SIF */
647         tmpreg0 = reg0 & ~(MC_CONTROL_REG0_PAGE + MC_CONTROL_REG0_SIFSEL);
648         outb(tmpreg0, ioaddr + MC_CONTROL_REG0);
649         
650         card->manid = inb(ioaddr + MC_ROM_MANUFACTURERID);
651         card->cardtype = inb(ioaddr + MC_ROM_ADAPTERID);
652         card->cardrev = inb(ioaddr + MC_ROM_REVISION);
653
654         /* Switch to rom page one */
655         outb(tmpreg0 | MC_CONTROL_REG0_PAGE, ioaddr + MC_CONTROL_REG0);
656
657         /* Read BIA */
658         dev->addr_len = 6;
659         for (i = 0; i < 6; i++)
660                 dev->dev_addr[i] = inb(ioaddr + MC_ROM_BIA_START + i);
661         
662         /* Restore original register values */
663         outb(reg0, ioaddr + MC_CONTROL_REG0);
664         outb(reg1, ioaddr + MC_CONTROL_REG1);
665         
666         return;
667 }
668
669 static int madgemc_open(struct net_device *dev)
670 {  
671         /*
672          * Go ahead and reinitialize the chipset again, just to 
673          * make sure we didn't get left in a bad state.
674          */
675         madgemc_chipset_init(dev);
676         tms380tr_open(dev);
677         return 0;
678 }
679
680 static int madgemc_close(struct net_device *dev)
681 {
682         tms380tr_close(dev);
683         madgemc_chipset_close(dev);
684         return 0;
685 }
686
687 /*
688  * Give some details available from /proc/mca/slotX
689  */
690 static int madgemc_mcaproc(char *buf, int slot, void *d) 
691 {       
692         struct net_device *dev = (struct net_device *)d;
693         struct net_local *tp = dev->priv;
694         struct card_info *curcard = tp->tmspriv;
695         int len = 0;
696         
697         len += sprintf(buf+len, "-------\n");
698         if (curcard) {
699                 struct net_local *tp = netdev_priv(dev);
700                 int i;
701                 
702                 len += sprintf(buf+len, "Card Revision: %d\n", curcard->cardrev);
703                 len += sprintf(buf+len, "RAM Size: %dkb\n", curcard->ramsize);
704                 len += sprintf(buf+len, "Cable type: %s\n", (curcard->cabletype)?"STP/DB9":"UTP/RJ-45");
705                 len += sprintf(buf+len, "Configured ring speed: %dMb/sec\n", (curcard->ringspeed)?16:4);
706                 len += sprintf(buf+len, "Running ring speed: %dMb/sec\n", (tp->DataRate==SPEED_16)?16:4);
707                 len += sprintf(buf+len, "Device: %s\n", dev->name);
708                 len += sprintf(buf+len, "IO Port: 0x%04lx\n", dev->base_addr);
709                 len += sprintf(buf+len, "IRQ: %d\n", dev->irq);
710                 len += sprintf(buf+len, "Arbitration Level: %d\n", curcard->arblevel);
711                 len += sprintf(buf+len, "Burst Mode: ");
712                 switch(curcard->burstmode) {
713                 case 0: len += sprintf(buf+len, "Cycle steal"); break;
714                 case 1: len += sprintf(buf+len, "Limited burst"); break;
715                 case 2: len += sprintf(buf+len, "Delayed release"); break;
716                 case 3: len += sprintf(buf+len, "Immediate release"); break;
717                 }
718                 len += sprintf(buf+len, " (%s)\n", (curcard->fairness)?"Unfair":"Fair");
719                 
720                 len += sprintf(buf+len, "Ring Station Address: ");
721                 len += sprintf(buf+len, "%2.2x", dev->dev_addr[0]);
722                 for (i = 1; i < 6; i++)
723                         len += sprintf(buf+len, " %2.2x", dev->dev_addr[i]);
724                 len += sprintf(buf+len, "\n");
725         } else 
726                 len += sprintf(buf+len, "Card not configured\n");
727
728         return len;
729 }
730
731 static int __devexit madgemc_remove(struct device *device)
732 {
733         struct net_device *dev = dev_get_drvdata(device);
734         struct net_local *tp;
735         struct card_info *card;
736
737         BUG_ON(!dev);
738
739         tp = dev->priv;
740         card = tp->tmspriv;
741         kfree(card);
742         tp->tmspriv = NULL;
743
744         unregister_netdev(dev);
745         release_region(dev->base_addr-MADGEMC_SIF_OFFSET, MADGEMC_IO_EXTENT);
746         free_irq(dev->irq, dev);
747         tmsdev_term(dev);
748         free_netdev(dev);
749         dev_set_drvdata(device, NULL);
750
751         return 0;
752 }
753
754 static short madgemc_adapter_ids[] __initdata = {
755         0x002d,
756         0x0000
757 };
758
759 static struct mca_driver madgemc_driver = {
760         .id_table = madgemc_adapter_ids,
761         .driver = {
762                 .name = "madgemc",
763                 .bus = &mca_bus_type,
764                 .probe = madgemc_probe,
765                 .remove = __devexit_p(madgemc_remove),
766         },
767 };
768
769 static int __init madgemc_init (void)
770 {
771         return mca_register_driver (&madgemc_driver);
772 }
773
774 static void __exit madgemc_exit (void)
775 {
776         mca_unregister_driver (&madgemc_driver);
777 }
778
779 module_init(madgemc_init);
780 module_exit(madgemc_exit);
781
782 MODULE_LICENSE("GPL");
783