Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v2.6.29-rc4 421 lines 12 kB view raw
1/* ac3200.c: A driver for the Ansel Communications EISA ethernet adaptor. */ 2/* 3 Written 1993, 1994 by Donald Becker. 4 Copyright 1993 United States Government as represented by the Director, 5 National Security Agency. This software may only be used and distributed 6 according to the terms of the GNU General Public License as modified by SRC, 7 incorporated herein by reference. 8 9 The author may be reached as becker@scyld.com, or C/O 10 Scyld Computing Corporation 11 410 Severn Ave., Suite 210 12 Annapolis MD 21403 13 14 This is driver for the Ansel Communications Model 3200 EISA Ethernet LAN 15 Adapter. The programming information is from the users manual, as related 16 by glee@ardnassak.math.clemson.edu. 17 18 Changelog: 19 20 Paul Gortmaker 05/98 : add support for shared mem above 1MB. 21 22 */ 23 24static const char version[] = 25 "ac3200.c:v1.01 7/1/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; 26 27#include <linux/module.h> 28#include <linux/eisa.h> 29#include <linux/kernel.h> 30#include <linux/errno.h> 31#include <linux/string.h> 32#include <linux/netdevice.h> 33#include <linux/etherdevice.h> 34#include <linux/init.h> 35 36#include <asm/system.h> 37#include <asm/io.h> 38#include <asm/irq.h> 39 40#include "8390.h" 41 42#define DRV_NAME "ac3200" 43 44/* Offsets from the base address. */ 45#define AC_NIC_BASE 0x00 46#define AC_SA_PROM 0x16 /* The station address PROM. */ 47#define AC_ADDR0 0x00 /* Prefix station address values. */ 48#define AC_ADDR1 0x40 49#define AC_ADDR2 0x90 50#define AC_ID_PORT 0xC80 51#define AC_EISA_ID 0x0110d305 52#define AC_RESET_PORT 0xC84 53#define AC_RESET 0x00 54#define AC_ENABLE 0x01 55#define AC_CONFIG 0xC90 /* The configuration port. */ 56 57#define AC_IO_EXTENT 0x20 58 /* Actually accessed is: 59 * AC_NIC_BASE (0-15) 60 * AC_SA_PROM (0-5) 61 * AC_ID_PORT (0-3) 62 * AC_RESET_PORT 63 * AC_CONFIG 64 */ 65 66/* Decoding of the configuration register. */ 67static unsigned char config2irqmap[8] __initdata = {15, 12, 11, 10, 9, 7, 5, 3}; 68static int addrmap[8] = 69{0xFF0000, 0xFE0000, 0xFD0000, 0xFFF0000, 0xFFE0000, 0xFFC0000, 0xD0000, 0 }; 70static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"}; 71 72#define config2irq(configval) config2irqmap[((configval) >> 3) & 7] 73#define config2mem(configval) addrmap[(configval) & 7] 74#define config2name(configval) port_name[((configval) >> 6) & 3] 75 76/* First and last 8390 pages. */ 77#define AC_START_PG 0x00 /* First page of 8390 TX buffer */ 78#define AC_STOP_PG 0x80 /* Last page +1 of the 8390 RX ring */ 79 80static int ac_probe1(int ioaddr, struct net_device *dev); 81 82static int ac_open(struct net_device *dev); 83static void ac_reset_8390(struct net_device *dev); 84static void ac_block_input(struct net_device *dev, int count, 85 struct sk_buff *skb, int ring_offset); 86static void ac_block_output(struct net_device *dev, const int count, 87 const unsigned char *buf, const int start_page); 88static void ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, 89 int ring_page); 90 91static int ac_close_card(struct net_device *dev); 92 93 94/* Probe for the AC3200. 95 96 The AC3200 can be identified by either the EISA configuration registers, 97 or the unique value in the station address PROM. 98 */ 99 100static int __init do_ac3200_probe(struct net_device *dev) 101{ 102 unsigned short ioaddr = dev->base_addr; 103 int irq = dev->irq; 104 int mem_start = dev->mem_start; 105 106 if (ioaddr > 0x1ff) /* Check a single specified location. */ 107 return ac_probe1(ioaddr, dev); 108 else if (ioaddr > 0) /* Don't probe at all. */ 109 return -ENXIO; 110 111 if ( ! EISA_bus) 112 return -ENXIO; 113 114 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) { 115 if (ac_probe1(ioaddr, dev) == 0) 116 return 0; 117 dev->irq = irq; 118 dev->mem_start = mem_start; 119 } 120 121 return -ENODEV; 122} 123 124#ifndef MODULE 125struct net_device * __init ac3200_probe(int unit) 126{ 127 struct net_device *dev = alloc_ei_netdev(); 128 int err; 129 130 if (!dev) 131 return ERR_PTR(-ENOMEM); 132 133 sprintf(dev->name, "eth%d", unit); 134 netdev_boot_setup_check(dev); 135 136 err = do_ac3200_probe(dev); 137 if (err) 138 goto out; 139 return dev; 140out: 141 free_netdev(dev); 142 return ERR_PTR(err); 143} 144#endif 145 146static int __init ac_probe1(int ioaddr, struct net_device *dev) 147{ 148 int i, retval; 149 150 if (!request_region(ioaddr, AC_IO_EXTENT, DRV_NAME)) 151 return -EBUSY; 152 153 if (inb_p(ioaddr + AC_ID_PORT) == 0xff) { 154 retval = -ENODEV; 155 goto out; 156 } 157 158 if (inl(ioaddr + AC_ID_PORT) != AC_EISA_ID) { 159 retval = -ENODEV; 160 goto out; 161 } 162 163#ifndef final_version 164 printk(KERN_DEBUG "AC3200 ethercard configuration register is %#02x," 165 " EISA ID %02x %02x %02x %02x.\n", inb(ioaddr + AC_CONFIG), 166 inb(ioaddr + AC_ID_PORT + 0), inb(ioaddr + AC_ID_PORT + 1), 167 inb(ioaddr + AC_ID_PORT + 2), inb(ioaddr + AC_ID_PORT + 3)); 168#endif 169 170 for (i = 0; i < 6; i++) 171 dev->dev_addr[i] = inb(ioaddr + AC_SA_PROM + i); 172 173 printk(KERN_DEBUG "AC3200 in EISA slot %d, node %pM", 174 ioaddr/0x1000, dev->dev_addr); 175#if 0 176 /* Check the vendor ID/prefix. Redundant after checking the EISA ID */ 177 if (inb(ioaddr + AC_SA_PROM + 0) != AC_ADDR0 178 || inb(ioaddr + AC_SA_PROM + 1) != AC_ADDR1 179 || inb(ioaddr + AC_SA_PROM + 2) != AC_ADDR2 ) { 180 printk(", not found (invalid prefix).\n"); 181 retval = -ENODEV; 182 goto out; 183 } 184#endif 185 186 /* Assign and allocate the interrupt now. */ 187 if (dev->irq == 0) { 188 dev->irq = config2irq(inb(ioaddr + AC_CONFIG)); 189 printk(", using"); 190 } else { 191 dev->irq = irq_canonicalize(dev->irq); 192 printk(", assigning"); 193 } 194 195 retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev); 196 if (retval) { 197 printk (" nothing! Unable to get IRQ %d.\n", dev->irq); 198 goto out1; 199 } 200 201 printk(" IRQ %d, %s port\n", dev->irq, port_name[dev->if_port]); 202 203 dev->base_addr = ioaddr; 204 205#ifdef notyet 206 if (dev->mem_start) { /* Override the value from the board. */ 207 for (i = 0; i < 7; i++) 208 if (addrmap[i] == dev->mem_start) 209 break; 210 if (i >= 7) 211 i = 0; 212 outb((inb(ioaddr + AC_CONFIG) & ~7) | i, ioaddr + AC_CONFIG); 213 } 214#endif 215 216 dev->if_port = inb(ioaddr + AC_CONFIG) >> 6; 217 dev->mem_start = config2mem(inb(ioaddr + AC_CONFIG)); 218 219 printk("%s: AC3200 at %#3x with %dkB memory at physical address %#lx.\n", 220 dev->name, ioaddr, AC_STOP_PG/4, dev->mem_start); 221 222 /* 223 * BEWARE!! Some dain-bramaged EISA SCUs will allow you to put 224 * the card mem within the region covered by `normal' RAM !!! 225 * 226 * ioremap() will fail in that case. 227 */ 228 ei_status.mem = ioremap(dev->mem_start, AC_STOP_PG*0x100); 229 if (!ei_status.mem) { 230 printk(KERN_ERR "ac3200.c: Unable to remap card memory above 1MB !!\n"); 231 printk(KERN_ERR "ac3200.c: Try using EISA SCU to set memory below 1MB.\n"); 232 printk(KERN_ERR "ac3200.c: Driver NOT installed.\n"); 233 retval = -EINVAL; 234 goto out1; 235 } 236 printk("ac3200.c: remapped %dkB card memory to virtual address %p\n", 237 AC_STOP_PG/4, ei_status.mem); 238 239 dev->mem_start = (unsigned long)ei_status.mem; 240 dev->mem_end = dev->mem_start + (AC_STOP_PG - AC_START_PG)*256; 241 242 ei_status.name = "AC3200"; 243 ei_status.tx_start_page = AC_START_PG; 244 ei_status.rx_start_page = AC_START_PG + TX_PAGES; 245 ei_status.stop_page = AC_STOP_PG; 246 ei_status.word16 = 1; 247 248 if (ei_debug > 0) 249 printk(version); 250 251 ei_status.reset_8390 = &ac_reset_8390; 252 ei_status.block_input = &ac_block_input; 253 ei_status.block_output = &ac_block_output; 254 ei_status.get_8390_hdr = &ac_get_8390_hdr; 255 256 dev->open = &ac_open; 257 dev->stop = &ac_close_card; 258#ifdef CONFIG_NET_POLL_CONTROLLER 259 dev->poll_controller = ei_poll; 260#endif 261 NS8390_init(dev, 0); 262 263 retval = register_netdev(dev); 264 if (retval) 265 goto out2; 266 return 0; 267out2: 268 if (ei_status.reg0) 269 iounmap(ei_status.mem); 270out1: 271 free_irq(dev->irq, dev); 272out: 273 release_region(ioaddr, AC_IO_EXTENT); 274 return retval; 275} 276 277static int ac_open(struct net_device *dev) 278{ 279#ifdef notyet 280 /* Someday we may enable the IRQ and shared memory here. */ 281 int ioaddr = dev->base_addr; 282#endif 283 284 ei_open(dev); 285 return 0; 286} 287 288static void ac_reset_8390(struct net_device *dev) 289{ 290 ushort ioaddr = dev->base_addr; 291 292 outb(AC_RESET, ioaddr + AC_RESET_PORT); 293 if (ei_debug > 1) printk("resetting AC3200, t=%ld...", jiffies); 294 295 ei_status.txing = 0; 296 outb(AC_ENABLE, ioaddr + AC_RESET_PORT); 297 if (ei_debug > 1) printk("reset done\n"); 298 299 return; 300} 301 302/* Grab the 8390 specific header. Similar to the block_input routine, but 303 we don't need to be concerned with ring wrap as the header will be at 304 the start of a page, so we optimize accordingly. */ 305 306static void 307ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) 308{ 309 void __iomem *hdr_start = ei_status.mem + ((ring_page - AC_START_PG)<<8); 310 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr)); 311} 312 313/* Block input and output are easy on shared memory ethercards, the only 314 complication is when the ring buffer wraps. */ 315 316static void ac_block_input(struct net_device *dev, int count, struct sk_buff *skb, 317 int ring_offset) 318{ 319 void __iomem *start = ei_status.mem + ring_offset - AC_START_PG*256; 320 321 if (ring_offset + count > AC_STOP_PG*256) { 322 /* We must wrap the input move. */ 323 int semi_count = AC_STOP_PG*256 - ring_offset; 324 memcpy_fromio(skb->data, start, semi_count); 325 count -= semi_count; 326 memcpy_fromio(skb->data + semi_count, 327 ei_status.mem + TX_PAGES*256, count); 328 } else { 329 memcpy_fromio(skb->data, start, count); 330 } 331} 332 333static void ac_block_output(struct net_device *dev, int count, 334 const unsigned char *buf, int start_page) 335{ 336 void __iomem *shmem = ei_status.mem + ((start_page - AC_START_PG)<<8); 337 338 memcpy_toio(shmem, buf, count); 339} 340 341static int ac_close_card(struct net_device *dev) 342{ 343 if (ei_debug > 1) 344 printk("%s: Shutting down ethercard.\n", dev->name); 345 346#ifdef notyet 347 /* We should someday disable shared memory and interrupts. */ 348 outb(0x00, ioaddr + 6); /* Disable interrupts. */ 349 free_irq(dev->irq, dev); 350#endif 351 352 ei_close(dev); 353 return 0; 354} 355 356#ifdef MODULE 357#define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */ 358static struct net_device *dev_ac32[MAX_AC32_CARDS]; 359static int io[MAX_AC32_CARDS]; 360static int irq[MAX_AC32_CARDS]; 361static int mem[MAX_AC32_CARDS]; 362module_param_array(io, int, NULL, 0); 363module_param_array(irq, int, NULL, 0); 364module_param_array(mem, int, NULL, 0); 365MODULE_PARM_DESC(io, "I/O base address(es)"); 366MODULE_PARM_DESC(irq, "IRQ number(s)"); 367MODULE_PARM_DESC(mem, "Memory base address(es)"); 368MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver"); 369MODULE_LICENSE("GPL"); 370 371static int __init ac3200_module_init(void) 372{ 373 struct net_device *dev; 374 int this_dev, found = 0; 375 376 for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) { 377 if (io[this_dev] == 0 && this_dev != 0) 378 break; 379 dev = alloc_ei_netdev(); 380 if (!dev) 381 break; 382 dev->irq = irq[this_dev]; 383 dev->base_addr = io[this_dev]; 384 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */ 385 if (do_ac3200_probe(dev) == 0) { 386 dev_ac32[found++] = dev; 387 continue; 388 } 389 free_netdev(dev); 390 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]); 391 break; 392 } 393 if (found) 394 return 0; 395 return -ENXIO; 396} 397 398static void cleanup_card(struct net_device *dev) 399{ 400 /* Someday free_irq may be in ac_close_card() */ 401 free_irq(dev->irq, dev); 402 release_region(dev->base_addr, AC_IO_EXTENT); 403 iounmap(ei_status.mem); 404} 405 406static void __exit ac3200_module_exit(void) 407{ 408 int this_dev; 409 410 for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) { 411 struct net_device *dev = dev_ac32[this_dev]; 412 if (dev) { 413 unregister_netdev(dev); 414 cleanup_card(dev); 415 free_netdev(dev); 416 } 417 } 418} 419module_init(ac3200_module_init); 420module_exit(ac3200_module_exit); 421#endif /* MODULE */