Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.4-rc5 432 lines 9.8 kB view raw
1/* 2 * skisa.c: A network driver for SK-NET TMS380-based ISA token ring cards. 3 * 4 * Based on tmspci written 1999 by Adam Fritzler 5 * 6 * Written 2000 by Jochen Friedrich 7 * Dedicated to my girlfriend Steffi Bopp 8 * 9 * This software may be used and distributed according to the terms 10 * of the GNU General Public License, incorporated herein by reference. 11 * 12 * This driver module supports the following cards: 13 * - SysKonnect TR4/16(+) ISA (SK-4190) 14 * 15 * Maintainer(s): 16 * AF Adam Fritzler 17 * JF Jochen Friedrich jochen@scram.de 18 * 19 * Modification History: 20 * 14-Jan-01 JF Created 21 * 28-Oct-02 JF Fixed probe of card for static compilation. 22 * Fixed module init to not make hotplug go wild. 23 * 09-Nov-02 JF Fixed early bail out on out of memory 24 * situations if multiple cards are found. 25 * Cleaned up some unnecessary console SPAM. 26 * 09-Dec-02 JF Fixed module reference counting. 27 * 02-Jan-03 JF Renamed to skisa.c 28 * 29 */ 30static const char version[] = "skisa.c: v1.03 09/12/2002 by Jochen Friedrich\n"; 31 32#include <linux/module.h> 33#include <linux/kernel.h> 34#include <linux/errno.h> 35#include <linux/pci.h> 36#include <linux/init.h> 37#include <linux/netdevice.h> 38#include <linux/trdevice.h> 39#include <linux/platform_device.h> 40 41#include <asm/io.h> 42#include <asm/irq.h> 43#include <asm/pci.h> 44#include <asm/dma.h> 45 46#include "tms380tr.h" 47 48#define SK_ISA_IO_EXTENT 32 49 50/* A zero-terminated list of I/O addresses to be probed. */ 51static unsigned int portlist[] __initdata = { 52 0x0A20, 0x1A20, 0x0B20, 0x1B20, 0x0980, 0x1980, 0x0900, 0x1900,// SK 53 0 54}; 55 56/* A zero-terminated list of IRQs to be probed. 57 * Used again after initial probe for sktr_chipset_init, called from sktr_open. 58 */ 59static const unsigned short irqlist[] = { 60 3, 5, 9, 10, 11, 12, 15, 61 0 62}; 63 64/* A zero-terminated list of DMAs to be probed. */ 65static int dmalist[] __initdata = { 66 5, 6, 7, 67 0 68}; 69 70static char isa_cardname[] = "SK NET TR 4/16 ISA\0"; 71static u64 dma_mask = ISA_MAX_ADDRESS; 72static int sk_isa_open(struct net_device *dev); 73static void sk_isa_read_eeprom(struct net_device *dev); 74static unsigned short sk_isa_setnselout_pins(struct net_device *dev); 75 76static unsigned short sk_isa_sifreadb(struct net_device *dev, unsigned short reg) 77{ 78 return inb(dev->base_addr + reg); 79} 80 81static unsigned short sk_isa_sifreadw(struct net_device *dev, unsigned short reg) 82{ 83 return inw(dev->base_addr + reg); 84} 85 86static void sk_isa_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg) 87{ 88 outb(val, dev->base_addr + reg); 89} 90 91static void sk_isa_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg) 92{ 93 outw(val, dev->base_addr + reg); 94} 95 96 97static int __init sk_isa_probe1(struct net_device *dev, int ioaddr) 98{ 99 unsigned char old, chk1, chk2; 100 101 if (!request_region(ioaddr, SK_ISA_IO_EXTENT, isa_cardname)) 102 return -ENODEV; 103 104 old = inb(ioaddr + SIFADR); /* Get the old SIFADR value */ 105 106 chk1 = 0; /* Begin with check value 0 */ 107 do { 108 /* Write new SIFADR value */ 109 outb(chk1, ioaddr + SIFADR); 110 111 /* Read, invert and write */ 112 chk2 = inb(ioaddr + SIFADD); 113 chk2 ^= 0x0FE; 114 outb(chk2, ioaddr + SIFADR); 115 116 /* Read, invert and compare */ 117 chk2 = inb(ioaddr + SIFADD); 118 chk2 ^= 0x0FE; 119 120 if(chk1 != chk2) { 121 release_region(ioaddr, SK_ISA_IO_EXTENT); 122 return -ENODEV; 123 } 124 125 chk1 -= 2; 126 } while(chk1 != 0); /* Repeat 128 times (all byte values) */ 127 128 /* Restore the SIFADR value */ 129 outb(old, ioaddr + SIFADR); 130 131 dev->base_addr = ioaddr; 132 return 0; 133} 134 135static struct net_device_ops sk_isa_netdev_ops __read_mostly; 136 137static int __init setup_card(struct net_device *dev, struct device *pdev) 138{ 139 struct net_local *tp; 140 static int versionprinted; 141 const unsigned *port; 142 int j, err = 0; 143 144 if (!dev) 145 return -ENOMEM; 146 147 if (dev->base_addr) /* probe specific location */ 148 err = sk_isa_probe1(dev, dev->base_addr); 149 else { 150 for (port = portlist; *port; port++) { 151 err = sk_isa_probe1(dev, *port); 152 if (!err) 153 break; 154 } 155 } 156 if (err) 157 goto out5; 158 159 /* At this point we have found a valid card. */ 160 161 if (versionprinted++ == 0) 162 printk(KERN_DEBUG "%s", version); 163 164 err = -EIO; 165 pdev->dma_mask = &dma_mask; 166 if (tmsdev_init(dev, pdev)) 167 goto out4; 168 169 dev->base_addr &= ~3; 170 171 sk_isa_read_eeprom(dev); 172 173 printk(KERN_DEBUG "skisa.c: Ring Station Address: %pM\n", 174 dev->dev_addr); 175 176 tp = netdev_priv(dev); 177 tp->setnselout = sk_isa_setnselout_pins; 178 179 tp->sifreadb = sk_isa_sifreadb; 180 tp->sifreadw = sk_isa_sifreadw; 181 tp->sifwriteb = sk_isa_sifwriteb; 182 tp->sifwritew = sk_isa_sifwritew; 183 184 memcpy(tp->ProductID, isa_cardname, PROD_ID_SIZE + 1); 185 186 tp->tmspriv = NULL; 187 188 dev->netdev_ops = &sk_isa_netdev_ops; 189 190 if (dev->irq == 0) 191 { 192 for(j = 0; irqlist[j] != 0; j++) 193 { 194 dev->irq = irqlist[j]; 195 if (!request_irq(dev->irq, tms380tr_interrupt, 0, 196 isa_cardname, dev)) 197 break; 198 } 199 200 if(irqlist[j] == 0) 201 { 202 printk(KERN_INFO "skisa.c: AutoSelect no IRQ available\n"); 203 goto out3; 204 } 205 } 206 else 207 { 208 for(j = 0; irqlist[j] != 0; j++) 209 if (irqlist[j] == dev->irq) 210 break; 211 if (irqlist[j] == 0) 212 { 213 printk(KERN_INFO "skisa.c: Illegal IRQ %d specified\n", 214 dev->irq); 215 goto out3; 216 } 217 if (request_irq(dev->irq, tms380tr_interrupt, 0, 218 isa_cardname, dev)) 219 { 220 printk(KERN_INFO "skisa.c: Selected IRQ %d not available\n", 221 dev->irq); 222 goto out3; 223 } 224 } 225 226 if (dev->dma == 0) 227 { 228 for(j = 0; dmalist[j] != 0; j++) 229 { 230 dev->dma = dmalist[j]; 231 if (!request_dma(dev->dma, isa_cardname)) 232 break; 233 } 234 235 if(dmalist[j] == 0) 236 { 237 printk(KERN_INFO "skisa.c: AutoSelect no DMA available\n"); 238 goto out2; 239 } 240 } 241 else 242 { 243 for(j = 0; dmalist[j] != 0; j++) 244 if (dmalist[j] == dev->dma) 245 break; 246 if (dmalist[j] == 0) 247 { 248 printk(KERN_INFO "skisa.c: Illegal DMA %d specified\n", 249 dev->dma); 250 goto out2; 251 } 252 if (request_dma(dev->dma, isa_cardname)) 253 { 254 printk(KERN_INFO "skisa.c: Selected DMA %d not available\n", 255 dev->dma); 256 goto out2; 257 } 258 } 259 260 err = register_netdev(dev); 261 if (err) 262 goto out; 263 264 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", 265 dev->name, dev->base_addr, dev->irq, dev->dma); 266 267 return 0; 268out: 269 free_dma(dev->dma); 270out2: 271 free_irq(dev->irq, dev); 272out3: 273 tmsdev_term(dev); 274out4: 275 release_region(dev->base_addr, SK_ISA_IO_EXTENT); 276out5: 277 return err; 278} 279 280/* 281 * Reads MAC address from adapter RAM, which should've read it from 282 * the onboard ROM. 283 * 284 * Calling this on a board that does not support it can be a very 285 * dangerous thing. The Madge board, for instance, will lock your 286 * machine hard when this is called. Luckily, its supported in a 287 * separate driver. --ASF 288 */ 289static void sk_isa_read_eeprom(struct net_device *dev) 290{ 291 int i; 292 293 /* Address: 0000:0000 */ 294 sk_isa_sifwritew(dev, 0, SIFADX); 295 sk_isa_sifwritew(dev, 0, SIFADR); 296 297 /* Read six byte MAC address data */ 298 dev->addr_len = 6; 299 for(i = 0; i < 6; i++) 300 dev->dev_addr[i] = sk_isa_sifreadw(dev, SIFINC) >> 8; 301} 302 303static unsigned short sk_isa_setnselout_pins(struct net_device *dev) 304{ 305 return 0; 306} 307 308static int sk_isa_open(struct net_device *dev) 309{ 310 struct net_local *tp = netdev_priv(dev); 311 unsigned short val = 0; 312 unsigned short oldval; 313 int i; 314 315 val = 0; 316 for(i = 0; irqlist[i] != 0; i++) 317 { 318 if(irqlist[i] == dev->irq) 319 break; 320 } 321 322 val |= CYCLE_TIME << 2; 323 val |= i << 4; 324 i = dev->dma - 5; 325 val |= i; 326 if(tp->DataRate == SPEED_4) 327 val |= LINE_SPEED_BIT; 328 else 329 val &= ~LINE_SPEED_BIT; 330 oldval = sk_isa_sifreadb(dev, POSREG); 331 /* Leave cycle bits alone */ 332 oldval |= 0xf3; 333 val &= oldval; 334 sk_isa_sifwriteb(dev, val, POSREG); 335 336 return tms380tr_open(dev); 337} 338 339#define ISATR_MAX_ADAPTERS 3 340 341static int io[ISATR_MAX_ADAPTERS]; 342static int irq[ISATR_MAX_ADAPTERS]; 343static int dma[ISATR_MAX_ADAPTERS]; 344 345MODULE_LICENSE("GPL"); 346 347module_param_array(io, int, NULL, 0); 348module_param_array(irq, int, NULL, 0); 349module_param_array(dma, int, NULL, 0); 350 351static struct platform_device *sk_isa_dev[ISATR_MAX_ADAPTERS]; 352 353static struct platform_driver sk_isa_driver = { 354 .driver = { 355 .name = "skisa", 356 }, 357}; 358 359static int __init sk_isa_init(void) 360{ 361 struct net_device *dev; 362 struct platform_device *pdev; 363 int i, num = 0, err = 0; 364 365 sk_isa_netdev_ops = tms380tr_netdev_ops; 366 sk_isa_netdev_ops.ndo_open = sk_isa_open; 367 sk_isa_netdev_ops.ndo_stop = tms380tr_close; 368 369 err = platform_driver_register(&sk_isa_driver); 370 if (err) 371 return err; 372 373 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { 374 dev = alloc_trdev(sizeof(struct net_local)); 375 if (!dev) 376 continue; 377 378 dev->base_addr = io[i]; 379 dev->irq = irq[i]; 380 dev->dma = dma[i]; 381 pdev = platform_device_register_simple("skisa", 382 i, NULL, 0); 383 if (IS_ERR(pdev)) { 384 free_netdev(dev); 385 continue; 386 } 387 err = setup_card(dev, &pdev->dev); 388 if (!err) { 389 sk_isa_dev[i] = pdev; 390 platform_set_drvdata(sk_isa_dev[i], dev); 391 ++num; 392 } else { 393 platform_device_unregister(pdev); 394 free_netdev(dev); 395 } 396 } 397 398 printk(KERN_NOTICE "skisa.c: %d cards found.\n", num); 399 /* Probe for cards. */ 400 if (num == 0) { 401 printk(KERN_NOTICE "skisa.c: No cards found.\n"); 402 platform_driver_unregister(&sk_isa_driver); 403 return -ENODEV; 404 } 405 return 0; 406} 407 408static void __exit sk_isa_cleanup(void) 409{ 410 struct net_device *dev; 411 int i; 412 413 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { 414 struct platform_device *pdev = sk_isa_dev[i]; 415 416 if (!pdev) 417 continue; 418 dev = platform_get_drvdata(pdev); 419 unregister_netdev(dev); 420 release_region(dev->base_addr, SK_ISA_IO_EXTENT); 421 free_irq(dev->irq, dev); 422 free_dma(dev->dma); 423 tmsdev_term(dev); 424 free_netdev(dev); 425 platform_set_drvdata(pdev, NULL); 426 platform_device_unregister(pdev); 427 } 428 platform_driver_unregister(&sk_isa_driver); 429} 430 431module_init(sk_isa_init); 432module_exit(sk_isa_cleanup);