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