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