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> |
1da177e4 LT |
24 | #include <linux/kernel.h> |
25 | #include <linux/errno.h> | |
1da177e4 LT |
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 | ||
84c3ea01 | 40 | struct card_info { |
1da177e4 LT |
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 */ | |
1da177e4 | 57 | }; |
1da177e4 LT |
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); | |
84c3ea01 | 62 | static void madgemc_read_rom(struct net_device *dev, struct card_info *card); |
1da177e4 LT |
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 | ||
7d12e780 | 72 | static irqreturn_t madgemc_interrupt(int irq, void *dev_id); |
1da177e4 LT |
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 | ||
84c3ea01 | 147 | static int __devinit madgemc_probe(struct device *device) |
1da177e4 LT |
148 | { |
149 | static int versionprinted; | |
150 | struct net_device *dev; | |
151 | struct net_local *tp; | |
84c3ea01 JF |
152 | struct card_info *card; |
153 | struct mca_device *mdev = to_mca_device(device); | |
0795af57 JP |
154 | int ret = 0; |
155 | DECLARE_MAC_BUF(mac); | |
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 | |
84c3ea01 | 172 | dev->dma = 0; |
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 | ||
0795af57 JP |
326 | printk("%s: Ring Station Address: %s\n", |
327 | dev->name, print_mac(mac, 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 | ||
352 | dev->open = madgemc_open; | |
353 | dev->stop = madgemc_close; | |
354 | ||
355 | tp->tmspriv = card; | |
356 | dev_set_drvdata(device, dev); | |
357 | ||
358 | if (register_netdev(dev) == 0) | |
1da177e4 | 359 | return 0; |
84c3ea01 JF |
360 | |
361 | dev_set_drvdata(device, NULL); | |
362 | ret = -ENOMEM; | |
363 | getout4: | |
364 | free_irq(dev->irq, dev); | |
365 | getout3: | |
366 | release_region(dev->base_addr-MADGEMC_SIF_OFFSET, | |
367 | MADGEMC_IO_EXTENT); | |
368 | getout2: | |
369 | kfree(card); | |
370 | getout1: | |
371 | free_netdev(dev); | |
372 | getout: | |
373 | mca_device_set_claim(mdev, 0); | |
374 | return ret; | |
1da177e4 LT |
375 | } |
376 | ||
377 | /* | |
378 | * Handle interrupts generated by the card | |
379 | * | |
380 | * The MicroChannel Madge cards need slightly more handling | |
381 | * after an interrupt than other TMS380 cards do. | |
382 | * | |
383 | * First we must make sure it was this card that generated the | |
384 | * interrupt (since interrupt sharing is allowed). Then, | |
385 | * because we're using level-triggered interrupts (as is | |
386 | * standard on MCA), we must toggle the interrupt line | |
387 | * on the card in order to claim and acknowledge the interrupt. | |
388 | * Once that is done, the interrupt should be handlable in | |
389 | * the normal tms380tr_interrupt() routine. | |
390 | * | |
391 | * There's two ways we can check to see if the interrupt is ours, | |
392 | * both with their own disadvantages... | |
393 | * | |
394 | * 1) Read in the SIFSTS register from the TMS controller. This | |
395 | * is guarenteed to be accurate, however, there's a fairly | |
396 | * large performance penalty for doing so: the Madge chips | |
397 | * must request the register from the Eagle, the Eagle must | |
398 | * read them from its internal bus, and then take the route | |
399 | * back out again, for a 16bit read. | |
400 | * | |
401 | * 2) Use the MC_CONTROL_REG0_SINTR bit from the Madge ASICs. | |
402 | * The major disadvantage here is that the accuracy of the | |
403 | * bit is in question. However, it cuts out the extra read | |
404 | * cycles it takes to read the Eagle's SIF, as its only an | |
405 | * 8bit read, and theoretically the Madge bit is directly | |
406 | * connected to the interrupt latch coming out of the Eagle | |
407 | * hardware (that statement is not verified). | |
408 | * | |
409 | * I can't determine which of these methods has the best win. For now, | |
410 | * we make a compromise. Use the Madge way for the first interrupt, | |
411 | * which should be the fast-path, and then once we hit the first | |
412 | * interrupt, keep on trying using the SIF method until we've | |
413 | * exhausted all contiguous interrupts. | |
414 | * | |
415 | */ | |
7d12e780 | 416 | static irqreturn_t madgemc_interrupt(int irq, void *dev_id) |
1da177e4 LT |
417 | { |
418 | int pending,reg1; | |
419 | struct net_device *dev; | |
420 | ||
421 | if (!dev_id) { | |
422 | printk("madgemc_interrupt: was not passed a dev_id!\n"); | |
423 | return IRQ_NONE; | |
424 | } | |
425 | ||
426 | dev = (struct net_device *)dev_id; | |
427 | ||
428 | /* Make sure its really us. -- the Madge way */ | |
429 | pending = inb(dev->base_addr + MC_CONTROL_REG0); | |
430 | if (!(pending & MC_CONTROL_REG0_SINTR)) | |
431 | return IRQ_NONE; /* not our interrupt */ | |
432 | ||
433 | /* | |
434 | * Since we're level-triggered, we may miss the rising edge | |
435 | * of the next interrupt while we're off handling this one, | |
436 | * so keep checking until the SIF verifies that it has nothing | |
437 | * left for us to do. | |
438 | */ | |
439 | pending = STS_SYSTEM_IRQ; | |
440 | do { | |
441 | if (pending & STS_SYSTEM_IRQ) { | |
442 | ||
443 | /* Toggle the interrupt to reset the latch on card */ | |
444 | reg1 = inb(dev->base_addr + MC_CONTROL_REG1); | |
445 | outb(reg1 ^ MC_CONTROL_REG1_SINTEN, | |
446 | dev->base_addr + MC_CONTROL_REG1); | |
447 | outb(reg1, dev->base_addr + MC_CONTROL_REG1); | |
448 | ||
449 | /* Continue handling as normal */ | |
7d12e780 | 450 | tms380tr_interrupt(irq, dev_id); |
1da177e4 LT |
451 | |
452 | pending = SIFREADW(SIFSTS); /* restart - the SIF way */ | |
453 | ||
454 | } else | |
455 | return IRQ_HANDLED; | |
456 | } while (1); | |
457 | ||
458 | return IRQ_HANDLED; /* not reachable */ | |
459 | } | |
460 | ||
461 | /* | |
462 | * Set the card to the prefered ring speed. | |
463 | * | |
464 | * Unlike newer cards, the MC16/32 have their speed selection | |
465 | * circuit connected to the Madge ASICs and not to the TMS380 | |
466 | * NSELOUT pins. Set the ASIC bits correctly here, and return | |
467 | * zero to leave the TMS NSELOUT bits unaffected. | |
468 | * | |
469 | */ | |
470 | unsigned short madgemc_setnselout_pins(struct net_device *dev) | |
471 | { | |
472 | unsigned char reg1; | |
473 | struct net_local *tp = netdev_priv(dev); | |
474 | ||
475 | reg1 = inb(dev->base_addr + MC_CONTROL_REG1); | |
476 | ||
477 | if(tp->DataRate == SPEED_16) | |
478 | reg1 |= MC_CONTROL_REG1_SPEED_SEL; /* add for 16mb */ | |
479 | else if (reg1 & MC_CONTROL_REG1_SPEED_SEL) | |
480 | reg1 ^= MC_CONTROL_REG1_SPEED_SEL; /* remove for 4mb */ | |
481 | outb(reg1, dev->base_addr + MC_CONTROL_REG1); | |
482 | ||
483 | return 0; /* no change */ | |
484 | } | |
485 | ||
486 | /* | |
487 | * Set the register page. This equates to the SRSX line | |
488 | * on the TMS380Cx6. | |
489 | * | |
490 | * Register selection is normally done via three contiguous | |
491 | * bits. However, some boards (such as the MC16/32) use only | |
492 | * two bits, plus a separate bit in the glue chip. This | |
493 | * sets the SRSX bit (the top bit). See page 4-17 in the | |
494 | * Yellow Book for which registers are affected. | |
495 | * | |
496 | */ | |
497 | static void madgemc_setregpage(struct net_device *dev, int page) | |
498 | { | |
499 | static int reg1; | |
500 | ||
501 | reg1 = inb(dev->base_addr + MC_CONTROL_REG1); | |
502 | if ((page == 0) && (reg1 & MC_CONTROL_REG1_SRSX)) { | |
503 | outb(reg1 ^ MC_CONTROL_REG1_SRSX, | |
504 | dev->base_addr + MC_CONTROL_REG1); | |
505 | } | |
506 | else if (page == 1) { | |
507 | outb(reg1 | MC_CONTROL_REG1_SRSX, | |
508 | dev->base_addr + MC_CONTROL_REG1); | |
509 | } | |
510 | reg1 = inb(dev->base_addr + MC_CONTROL_REG1); | |
511 | ||
512 | return; | |
513 | } | |
514 | ||
515 | /* | |
516 | * The SIF registers are not mapped into register space by default | |
517 | * Set this to 1 to map them, 0 to map the BIA ROM. | |
518 | * | |
519 | */ | |
520 | static void madgemc_setsifsel(struct net_device *dev, int val) | |
521 | { | |
522 | unsigned int reg0; | |
523 | ||
524 | reg0 = inb(dev->base_addr + MC_CONTROL_REG0); | |
525 | if ((val == 0) && (reg0 & MC_CONTROL_REG0_SIFSEL)) { | |
526 | outb(reg0 ^ MC_CONTROL_REG0_SIFSEL, | |
527 | dev->base_addr + MC_CONTROL_REG0); | |
528 | } else if (val == 1) { | |
529 | outb(reg0 | MC_CONTROL_REG0_SIFSEL, | |
530 | dev->base_addr + MC_CONTROL_REG0); | |
531 | } | |
532 | reg0 = inb(dev->base_addr + MC_CONTROL_REG0); | |
533 | ||
534 | return; | |
535 | } | |
536 | ||
537 | /* | |
538 | * Enable SIF interrupts | |
539 | * | |
540 | * This does not enable interrupts in the SIF, but rather | |
541 | * enables SIF interrupts to be passed onto the host. | |
542 | * | |
543 | */ | |
544 | static void madgemc_setint(struct net_device *dev, int val) | |
545 | { | |
546 | unsigned int reg1; | |
547 | ||
548 | reg1 = inb(dev->base_addr + MC_CONTROL_REG1); | |
549 | if ((val == 0) && (reg1 & MC_CONTROL_REG1_SINTEN)) { | |
550 | outb(reg1 ^ MC_CONTROL_REG1_SINTEN, | |
551 | dev->base_addr + MC_CONTROL_REG1); | |
552 | } else if (val == 1) { | |
553 | outb(reg1 | MC_CONTROL_REG1_SINTEN, | |
554 | dev->base_addr + MC_CONTROL_REG1); | |
555 | } | |
556 | ||
557 | return; | |
558 | } | |
559 | ||
560 | /* | |
561 | * Cable type is set via control register 7. Bit zero high | |
562 | * for UTP, low for STP. | |
563 | */ | |
564 | static void madgemc_setcabletype(struct net_device *dev, int type) | |
565 | { | |
566 | outb((type==0)?MC_CONTROL_REG7_CABLEUTP:MC_CONTROL_REG7_CABLESTP, | |
567 | dev->base_addr + MC_CONTROL_REG7); | |
568 | } | |
569 | ||
570 | /* | |
571 | * Enable the functions of the Madge chipset needed for | |
572 | * full working order. | |
573 | */ | |
574 | static int madgemc_chipset_init(struct net_device *dev) | |
575 | { | |
576 | outb(0, dev->base_addr + MC_CONTROL_REG1); /* pull SRESET low */ | |
577 | tms380tr_wait(100); /* wait for card to reset */ | |
578 | ||
579 | /* bring back into normal operating mode */ | |
580 | outb(MC_CONTROL_REG1_NSRESET, dev->base_addr + MC_CONTROL_REG1); | |
581 | ||
582 | /* map SIF registers */ | |
583 | madgemc_setsifsel(dev, 1); | |
584 | ||
585 | /* enable SIF interrupts */ | |
586 | madgemc_setint(dev, 1); | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
591 | /* | |
592 | * Disable the board, and put back into power-up state. | |
593 | */ | |
de70b4c8 | 594 | static void madgemc_chipset_close(struct net_device *dev) |
1da177e4 LT |
595 | { |
596 | /* disable interrupts */ | |
597 | madgemc_setint(dev, 0); | |
598 | /* unmap SIF registers */ | |
599 | madgemc_setsifsel(dev, 0); | |
600 | ||
601 | return; | |
602 | } | |
603 | ||
604 | /* | |
605 | * Read the card type (MC16 or MC32) from the card. | |
606 | * | |
607 | * The configuration registers are stored in two separate | |
608 | * pages. Pages are flipped by clearing bit 3 of CONTROL_REG0 (PAGE) | |
609 | * for page zero, or setting bit 3 for page one. | |
610 | * | |
611 | * Page zero contains the following data: | |
612 | * Byte 0: Manufacturer ID (0x4D -- ASCII "M") | |
613 | * Byte 1: Card type: | |
614 | * 0x08 for MC16 | |
615 | * 0x0D for MC32 | |
616 | * Byte 2: Card revision | |
617 | * Byte 3: Mirror of POS config register 0 | |
618 | * Byte 4: Mirror of POS 1 | |
619 | * Byte 5: Mirror of POS 2 | |
620 | * | |
621 | * Page one contains the following data: | |
622 | * Byte 0: Unused | |
623 | * Byte 1-6: BIA, MSB to LSB. | |
624 | * | |
625 | * Note that to read the BIA, we must unmap the SIF registers | |
626 | * by clearing bit 2 of CONTROL_REG0 (SIFSEL), as the data | |
627 | * will reside in the same logical location. For this reason, | |
628 | * _never_ read the BIA while the Eagle processor is running! | |
629 | * The SIF will be completely inaccessible until the BIA operation | |
630 | * is complete. | |
631 | * | |
632 | */ | |
84c3ea01 | 633 | static void madgemc_read_rom(struct net_device *dev, struct card_info *card) |
1da177e4 LT |
634 | { |
635 | unsigned long ioaddr; | |
636 | unsigned char reg0, reg1, tmpreg0, i; | |
637 | ||
84c3ea01 | 638 | ioaddr = dev->base_addr; |
1da177e4 LT |
639 | |
640 | reg0 = inb(ioaddr + MC_CONTROL_REG0); | |
641 | reg1 = inb(ioaddr + MC_CONTROL_REG1); | |
642 | ||
643 | /* Switch to page zero and unmap SIF */ | |
644 | tmpreg0 = reg0 & ~(MC_CONTROL_REG0_PAGE + MC_CONTROL_REG0_SIFSEL); | |
645 | outb(tmpreg0, ioaddr + MC_CONTROL_REG0); | |
646 | ||
647 | card->manid = inb(ioaddr + MC_ROM_MANUFACTURERID); | |
648 | card->cardtype = inb(ioaddr + MC_ROM_ADAPTERID); | |
649 | card->cardrev = inb(ioaddr + MC_ROM_REVISION); | |
650 | ||
651 | /* Switch to rom page one */ | |
652 | outb(tmpreg0 | MC_CONTROL_REG0_PAGE, ioaddr + MC_CONTROL_REG0); | |
653 | ||
654 | /* Read BIA */ | |
84c3ea01 | 655 | dev->addr_len = 6; |
1da177e4 | 656 | for (i = 0; i < 6; i++) |
84c3ea01 | 657 | dev->dev_addr[i] = inb(ioaddr + MC_ROM_BIA_START + i); |
1da177e4 LT |
658 | |
659 | /* Restore original register values */ | |
660 | outb(reg0, ioaddr + MC_CONTROL_REG0); | |
661 | outb(reg1, ioaddr + MC_CONTROL_REG1); | |
662 | ||
663 | return; | |
664 | } | |
665 | ||
666 | static int madgemc_open(struct net_device *dev) | |
667 | { | |
668 | /* | |
669 | * Go ahead and reinitialize the chipset again, just to | |
670 | * make sure we didn't get left in a bad state. | |
671 | */ | |
672 | madgemc_chipset_init(dev); | |
673 | tms380tr_open(dev); | |
674 | return 0; | |
675 | } | |
676 | ||
677 | static int madgemc_close(struct net_device *dev) | |
678 | { | |
679 | tms380tr_close(dev); | |
680 | madgemc_chipset_close(dev); | |
681 | return 0; | |
682 | } | |
683 | ||
684 | /* | |
685 | * Give some details available from /proc/mca/slotX | |
686 | */ | |
687 | static int madgemc_mcaproc(char *buf, int slot, void *d) | |
688 | { | |
689 | struct net_device *dev = (struct net_device *)d; | |
eda10531 | 690 | struct net_local *tp = netdev_priv(dev); |
84c3ea01 | 691 | struct card_info *curcard = tp->tmspriv; |
1da177e4 | 692 | int len = 0; |
0795af57 | 693 | DECLARE_MAC_BUF(mac); |
1da177e4 | 694 | |
1da177e4 LT |
695 | len += sprintf(buf+len, "-------\n"); |
696 | if (curcard) { | |
697 | struct net_local *tp = netdev_priv(dev); | |
1da177e4 LT |
698 | |
699 | len += sprintf(buf+len, "Card Revision: %d\n", curcard->cardrev); | |
700 | len += sprintf(buf+len, "RAM Size: %dkb\n", curcard->ramsize); | |
701 | len += sprintf(buf+len, "Cable type: %s\n", (curcard->cabletype)?"STP/DB9":"UTP/RJ-45"); | |
702 | len += sprintf(buf+len, "Configured ring speed: %dMb/sec\n", (curcard->ringspeed)?16:4); | |
703 | len += sprintf(buf+len, "Running ring speed: %dMb/sec\n", (tp->DataRate==SPEED_16)?16:4); | |
704 | len += sprintf(buf+len, "Device: %s\n", dev->name); | |
705 | len += sprintf(buf+len, "IO Port: 0x%04lx\n", dev->base_addr); | |
706 | len += sprintf(buf+len, "IRQ: %d\n", dev->irq); | |
707 | len += sprintf(buf+len, "Arbitration Level: %d\n", curcard->arblevel); | |
708 | len += sprintf(buf+len, "Burst Mode: "); | |
709 | switch(curcard->burstmode) { | |
710 | case 0: len += sprintf(buf+len, "Cycle steal"); break; | |
711 | case 1: len += sprintf(buf+len, "Limited burst"); break; | |
712 | case 2: len += sprintf(buf+len, "Delayed release"); break; | |
713 | case 3: len += sprintf(buf+len, "Immediate release"); break; | |
714 | } | |
715 | len += sprintf(buf+len, " (%s)\n", (curcard->fairness)?"Unfair":"Fair"); | |
716 | ||
0795af57 JP |
717 | len += sprintf(buf+len, "Ring Station Address: %s\n", |
718 | print_mac(mac, dev->dev_addr)); | |
1da177e4 LT |
719 | } else |
720 | len += sprintf(buf+len, "Card not configured\n"); | |
721 | ||
722 | return len; | |
723 | } | |
724 | ||
84c3ea01 | 725 | static int __devexit madgemc_remove(struct device *device) |
1da177e4 | 726 | { |
84c3ea01 JF |
727 | struct net_device *dev = dev_get_drvdata(device); |
728 | struct net_local *tp; | |
729 | struct card_info *card; | |
730 | ||
5d9428de | 731 | BUG_ON(!dev); |
84c3ea01 | 732 | |
eda10531 | 733 | tp = netdev_priv(dev); |
84c3ea01 JF |
734 | card = tp->tmspriv; |
735 | kfree(card); | |
736 | tp->tmspriv = NULL; | |
737 | ||
738 | unregister_netdev(dev); | |
739 | release_region(dev->base_addr-MADGEMC_SIF_OFFSET, MADGEMC_IO_EXTENT); | |
740 | free_irq(dev->irq, dev); | |
741 | tmsdev_term(dev); | |
742 | free_netdev(dev); | |
743 | dev_set_drvdata(device, NULL); | |
744 | ||
745 | return 0; | |
746 | } | |
747 | ||
748 | static short madgemc_adapter_ids[] __initdata = { | |
749 | 0x002d, | |
750 | 0x0000 | |
751 | }; | |
752 | ||
753 | static struct mca_driver madgemc_driver = { | |
754 | .id_table = madgemc_adapter_ids, | |
755 | .driver = { | |
756 | .name = "madgemc", | |
757 | .bus = &mca_bus_type, | |
758 | .probe = madgemc_probe, | |
759 | .remove = __devexit_p(madgemc_remove), | |
760 | }, | |
761 | }; | |
762 | ||
763 | static int __init madgemc_init (void) | |
764 | { | |
765 | return mca_register_driver (&madgemc_driver); | |
766 | } | |
767 | ||
768 | static void __exit madgemc_exit (void) | |
769 | { | |
770 | mca_unregister_driver (&madgemc_driver); | |
1da177e4 LT |
771 | } |
772 | ||
84c3ea01 | 773 | module_init(madgemc_init); |
1da177e4 LT |
774 | module_exit(madgemc_exit); |
775 | ||
776 | MODULE_LICENSE("GPL"); | |
777 |