root/drivers/net/3c503.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. el2_probe
  2. el2_pio_probe
  3. el2_probe1
  4. el2_open
  5. el2_close
  6. el2_reset_8390
  7. el2_init_card
  8. el2_block_output
  9. el2_get_8390_hdr
  10. el2_block_input
  11. init_module
  12. cleanup_module

   1 /* 3c503.c: A shared-memory NS8390 ethernet driver for linux. */
   2 /*
   3     Written 1992-94 by Donald Becker.
   4 
   5     Copyright 1993 United States Government as represented by the
   6     Director, National Security Agency.  This software may be used and
   7     distributed according to the terms of the GNU Public License,
   8     incorporated herein by reference.
   9 
  10     The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  11     Center of Excellence in Space Data and Information Sciences
  12        Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  13 
  14     This driver should work with the 3c503 and 3c503/16.  It should be used
  15     in shared memory mode for best performance, although it may also work
  16     in programmed-I/O mode.
  17 
  18     Sources:
  19     EtherLink II Technical Reference Manual,
  20     EtherLink II/16 Technical Reference Manual Supplement,
  21     3Com Corporation, 5400 Bayfront Plaza, Santa Clara CA 95052-8145
  22     
  23     The Crynwr 3c503 packet driver.
  24 
  25     Changelog:
  26 
  27     Paul Gortmaker      : add support for the 2nd 8kB of RAM on 16 bit cards.
  28     Paul Gortmaker      : multiple card support for module users.
  29 
  30 */
  31 
  32 static const char *version =
  33     "3c503.c:v1.10 9/23/93  Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  34 
  35 #include <linux/module.h>
  36 
  37 #include <linux/kernel.h>
  38 #include <linux/sched.h>
  39 #include <linux/errno.h>
  40 #include <linux/string.h>
  41 #include <linux/delay.h>
  42 #include <linux/netdevice.h>
  43 #include <linux/etherdevice.h>
  44 
  45 #include <asm/io.h>
  46 #include <asm/system.h>
  47 
  48 #include "8390.h"
  49 #include "3c503.h"
  50 
  51 
  52 int el2_probe(struct device *dev);
  53 int el2_pio_probe(struct device *dev);
  54 int el2_probe1(struct device *dev, int ioaddr);
  55 
  56 /* A zero-terminated list of I/O addresses to be probed in PIO mode. */
  57 static unsigned int netcard_portlist[] =
  58         { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
  59 
  60 #define EL2_IO_EXTENT   16
  61 
  62 #ifdef HAVE_DEVLIST
  63 /* The 3c503 uses two entries, one for the safe memory-mapped probe and
  64    the other for the typical I/O probe. */
  65 struct netdev_entry el2_drv =
  66 {"3c503", el2_probe, EL1_IO_EXTENT, 0};
  67 struct netdev_entry el2pio_drv =
  68 {"3c503pio", el2_pioprobe1, EL1_IO_EXTENT, netcard_portlist};
  69 #endif
  70 
  71 static int el2_open(struct device *dev);
  72 static int el2_close(struct device *dev);
  73 static void el2_reset_8390(struct device *dev);
  74 static void el2_init_card(struct device *dev);
  75 static void el2_block_output(struct device *dev, int count,
  76                              const unsigned char *buf, const start_page);
  77 static void el2_block_input(struct device *dev, int count, struct sk_buff *skb,
  78                            int ring_offset);
  79 static void el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
  80                          int ring_page);
  81 
  82 
  83 /* This routine probes for a memory-mapped 3c503 board by looking for
  84    the "location register" at the end of the jumpered boot PROM space.
  85    This works even if a PROM isn't there.
  86 
  87    If the ethercard isn't found there is an optional probe for
  88    ethercard jumpered to programmed-I/O mode.
  89    */
  90 int
  91 el2_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93     int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
  94     int base_addr = dev->base_addr;
  95 
  96     if (base_addr > 0x1ff)      /* Check a single specified location. */
  97         return el2_probe1(dev, base_addr);
  98     else if (base_addr != 0)            /* Don't probe at all. */
  99         return ENXIO;
 100 
 101     for (addr = addrs; *addr; addr++) {
 102         int i;
 103         unsigned int base_bits = readb(*addr);
 104         /* Find first set bit. */
 105         for(i = 7; i >= 0; i--, base_bits >>= 1)
 106             if (base_bits & 0x1)
 107                 break;
 108         if (base_bits != 1)
 109             continue;
 110         if (check_region(netcard_portlist[i], EL2_IO_EXTENT))
 111             continue;
 112         if (el2_probe1(dev, netcard_portlist[i]) == 0)
 113             return 0;
 114     }
 115 #if ! defined(no_probe_nonshared_memory) && ! defined (HAVE_DEVLIST)
 116     return el2_pio_probe(dev);
 117 #else
 118     return ENODEV;
 119 #endif
 120 }
 121 
 122 #ifndef HAVE_DEVLIST
 123 /*  Try all of the locations that aren't obviously empty.  This touches
 124     a lot of locations, and is much riskier than the code above. */
 125 int
 126 el2_pio_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128     int i;
 129     int base_addr = dev ? dev->base_addr : 0;
 130 
 131     if (base_addr > 0x1ff)      /* Check a single specified location. */
 132         return el2_probe1(dev, base_addr);
 133     else if (base_addr != 0)    /* Don't probe at all. */
 134         return ENXIO;
 135 
 136     for (i = 0; netcard_portlist[i]; i++) {
 137         int ioaddr = netcard_portlist[i];
 138         if (check_region(ioaddr, EL2_IO_EXTENT))
 139             continue;
 140         if (el2_probe1(dev, ioaddr) == 0)
 141             return 0;
 142     }
 143 
 144     return ENODEV;
 145 }
 146 #endif
 147 
 148 /* Probe for the Etherlink II card at I/O port base IOADDR,
 149    returning non-zero on success.  If found, set the station
 150    address and memory parameters in DEVICE. */
 151 int
 152 el2_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154     int i, iobase_reg, membase_reg, saved_406, wordlength;
 155     static unsigned version_printed = 0;
 156     unsigned long vendor_id;
 157 
 158     /* Reset and/or avoid any lurking NE2000 */
 159     if (inb(ioaddr + 0x408) == 0xff) {
 160         udelay(1000);
 161         return ENODEV;
 162     }
 163 
 164     /* We verify that it's a 3C503 board by checking the first three octets
 165        of its ethernet address. */
 166     iobase_reg = inb(ioaddr+0x403);
 167     membase_reg = inb(ioaddr+0x404);
 168     /* ASIC location registers should be 0 or have only a single bit set. */
 169     if (   (iobase_reg  & (iobase_reg - 1))
 170         || (membase_reg & (membase_reg - 1))) {
 171         return ENODEV;
 172     }
 173     saved_406 = inb_p(ioaddr + 0x406);
 174     outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */
 175     outb_p(ECNTRL_THIN, ioaddr + 0x406);
 176     /* Map the station addr PROM into the lower I/O ports. We now check
 177        for both the old and new 3Com prefix */
 178     outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
 179     vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
 180     if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
 181         /* Restore the register we frobbed. */
 182         outb(saved_406, ioaddr + 0x406);
 183         return ENODEV;
 184     }
 185 
 186     /* We should have a "dev" from Space.c or the static module table. */
 187     if (dev == NULL) {
 188         printk("3c503.c: Passed a NULL device.\n");
 189         dev = init_etherdev(0, 0);
 190     }
 191 
 192     if (ei_debug  &&  version_printed++ == 0)
 193         printk(version);
 194 
 195     dev->base_addr = ioaddr;
 196 
 197     /* Allocate dev->priv and fill in 8390 specific dev fields. */
 198     if (ethdev_init(dev)) {
 199         printk ("3c503: unable to allocate memory for dev->priv.\n");
 200         return -ENOMEM;
 201      }
 202 
 203     printk("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr);
 204 
 205     /* Retrieve and print the ethernet address. */
 206     for (i = 0; i < 6; i++)
 207         printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
 208 
 209     /* Map the 8390 back into the window. */
 210     outb(ECNTRL_THIN, ioaddr + 0x406);
 211 
 212     /* Check for EL2/16 as described in tech. man. */
 213     outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
 214     outb_p(0, ioaddr + EN0_DCFG);
 215     outb_p(E8390_PAGE2, ioaddr + E8390_CMD);
 216     wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS;
 217     outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
 218 
 219     /* Probe for, turn on and clear the board's shared memory. */
 220     if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg);
 221     outb(EGACFR_NORM, ioaddr + 0x405);  /* Enable RAM */
 222 
 223     /* This should be probed for (or set via an ioctl()) at run-time.
 224        Right now we use a sleazy hack to pass in the interface number
 225        at boot-time via the low bits of the mem_end field.  That value is
 226        unused, and the low bits would be discarded even if it was used. */
 227 #if defined(EI8390_THICK) || defined(EL2_AUI)
 228     ei_status.interface_num = 1;
 229 #else
 230     ei_status.interface_num = dev->mem_end & 0xf;
 231 #endif
 232     printk(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex");
 233 
 234     if ((membase_reg & 0xf0) == 0) {
 235         dev->mem_start = 0;
 236         ei_status.name = "3c503-PIO";
 237     } else {
 238         dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
 239             ((membase_reg & 0xA0) ? 0x4000 : 0);
 240 
 241 #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256
 242 #ifdef EL2MEMTEST
 243         /* This has never found an error, but someone might care.
 244            Note that it only tests the 2nd 8kB on 16kB 3c503/16
 245            cards between card addr. 0x2000 and 0x3fff. */
 246         {                       /* Check the card's memory. */
 247             unsigned long mem_base = dev->mem_start;
 248             unsigned int test_val = 0xbbadf00d;
 249             writel(0xba5eba5e, mem_base);
 250             for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
 251                 writel(test_val, mem_base + i);
 252                 if (readl(mem_base) != 0xba5eba5e
 253                     || readl(mem_base + i) != test_val) {
 254                     printk("3c503.c: memory failure or memory address conflict.\n");
 255                     dev->mem_start = 0;
 256                     ei_status.name = "3c503-PIO";
 257                     break;
 258                 }
 259                 test_val += 0x55555555;
 260                 writel(0, mem_base + i);
 261             }
 262         }
 263 #endif  /* EL2MEMTEST */
 264 
 265         dev->mem_end = dev->rmem_end = dev->mem_start + EL2_MEMSIZE;
 266 
 267         if (wordlength) {       /* No Tx pages to skip over to get to Rx */
 268                 dev->rmem_start = dev->mem_start;
 269                 ei_status.name = "3c503/16";
 270         } else {
 271                 dev->rmem_start = TX_PAGES*256 + dev->mem_start;
 272                 ei_status.name = "3c503";
 273         }
 274     }
 275 
 276     /*
 277         Divide up the memory on the card. This is the same regardless of
 278         whether shared-mem or PIO is used. For 16 bit cards (16kB RAM),
 279         we use the entire 8k of bank1 for an Rx ring. We only use 3k 
 280         of the bank0 for 2 full size Tx packet slots. For 8 bit cards,
 281         (8kB RAM) we use 3kB of bank1 for two Tx slots, and the remaining 
 282         5kB for an Rx ring.  */
 283 
 284     if (wordlength) {
 285         ei_status.tx_start_page = EL2_MB0_START_PG;
 286         ei_status.rx_start_page = EL2_MB1_START_PG;
 287     } else {
 288         ei_status.tx_start_page = EL2_MB1_START_PG;
 289         ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
 290     }
 291 
 292     /* Finish setting the board's parameters. */
 293     ei_status.stop_page = EL2_MB1_STOP_PG;
 294     ei_status.word16 = wordlength;
 295     ei_status.reset_8390 = &el2_reset_8390;
 296     ei_status.get_8390_hdr = &el2_get_8390_hdr;
 297     ei_status.block_input = &el2_block_input;
 298     ei_status.block_output = &el2_block_output;
 299 
 300     request_region(ioaddr, EL2_IO_EXTENT, ei_status.name);
 301 
 302     if (dev->irq == 2)
 303         dev->irq = 9;
 304     else if (dev->irq > 5 && dev->irq != 9) {
 305         printk("3c503: configured interrupt %d invalid, will use autoIRQ.\n",
 306                dev->irq);
 307         dev->irq = 0;
 308     }
 309 
 310     ei_status.saved_irq = dev->irq;
 311 
 312     dev->start = 0;
 313     dev->open = &el2_open;
 314     dev->stop = &el2_close;
 315 
 316     if (dev->mem_start)
 317         printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
 318                 dev->name, ei_status.name, (wordlength+1)<<3,
 319                 dev->mem_start, dev->mem_end-1);
 320 
 321     else
 322         printk("\n%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n",
 323                dev->name, ei_status.name, (wordlength+1)<<3);
 324 
 325     return 0;
 326 }
 327 
 328 static int
 329 el2_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 330 {
 331 
 332     if (dev->irq < 2) {
 333         int irqlist[] = {5, 9, 3, 4, 0};
 334         int *irqp = irqlist;
 335 
 336         outb(EGACFR_NORM, E33G_GACFR);  /* Enable RAM and interrupts. */
 337         do {
 338             if (request_irq (*irqp, NULL, 0, "bogus") != -EBUSY) {
 339                 /* Twinkle the interrupt, and check if it's seen. */
 340                 autoirq_setup(0);
 341                 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
 342                 outb_p(0x00, E33G_IDCFR);
 343                 if (*irqp == autoirq_report(0)   /* It's a good IRQ line! */
 344                     && request_irq (dev->irq = *irqp, &ei_interrupt, 0, ei_status.name) == 0)
 345                     break;
 346             }
 347         } while (*++irqp);
 348         if (*irqp == 0) {
 349             outb(EGACFR_IRQOFF, E33G_GACFR);    /* disable interrupts. */
 350             return -EAGAIN;
 351         }
 352     } else {
 353         if (request_irq(dev->irq, &ei_interrupt, 0, ei_status.name)) {
 354             return -EAGAIN;
 355         }
 356     }
 357 
 358     el2_init_card(dev);
 359     ei_open(dev);
 360     MOD_INC_USE_COUNT;
 361     return 0;
 362 }
 363 
 364 static int
 365 el2_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 366 {
 367     free_irq(dev->irq);
 368     dev->irq = ei_status.saved_irq;
 369     irq2dev_map[dev->irq] = NULL;
 370     outb(EGACFR_IRQOFF, E33G_GACFR);    /* disable interrupts. */
 371 
 372     ei_close(dev);
 373     MOD_DEC_USE_COUNT;
 374     return 0;
 375 }
 376 
 377 /* This is called whenever we have a unrecoverable failure:
 378        transmit timeout
 379        Bad ring buffer packet header
 380  */
 381 static void
 382 el2_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 383 {
 384     if (ei_debug > 1) {
 385         printk("%s: Resetting the 3c503 board...", dev->name);
 386         printk("%#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
 387                E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
 388     }
 389     outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
 390     ei_status.txing = 0;
 391     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 392     el2_init_card(dev);
 393     if (ei_debug > 1) printk("done\n");
 394 }
 395 
 396 /* Initialize the 3c503 GA registers after a reset. */
 397 static void
 398 el2_init_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 399 {
 400     /* Unmap the station PROM and select the DIX or BNC connector. */
 401     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 402 
 403     /* Set ASIC copy of rx's first and last+1 buffer pages */
 404     /* These must be the same as in the 8390. */
 405     outb(ei_status.rx_start_page, E33G_STARTPG);
 406     outb(ei_status.stop_page,  E33G_STOPPG);
 407 
 408     /* Point the vector pointer registers somewhere ?harmless?. */
 409     outb(0xff, E33G_VP2);       /* Point at the ROM restart location 0xffff0 */
 410     outb(0xff, E33G_VP1);
 411     outb(0x00, E33G_VP0);
 412     /* Turn off all interrupts until we're opened. */
 413     outb_p(0x00,  dev->base_addr + EN0_IMR);
 414     /* Enable IRQs iff started. */
 415     outb(EGACFR_NORM, E33G_GACFR);
 416 
 417     /* Set the interrupt line. */
 418     outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
 419     outb_p(8, E33G_DRQCNT);             /* Set burst size to 8 */
 420     outb_p(0x20, E33G_DMAAH);   /* Put a valid addr in the GA DMA */
 421     outb_p(0x00, E33G_DMAAL);
 422     return;                     /* We always succeed */
 423 }
 424 
 425 /* Either use the shared memory (if enabled on the board) or put the packet
 426    out through the ASIC FIFO.  The latter is probably much slower. */
 427 static void
 428 el2_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 429                  const unsigned char *buf, const start_page)
 430 {
 431     int i;                              /* Buffer index */
 432     int boguscount = 0;         /* timeout counter */
 433 
 434     if (ei_status.word16)      /* Tx packets go into bank 0 on EL2/16 card */
 435         outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR);
 436     else 
 437         outb(EGACFR_NORM, E33G_GACFR);
 438 
 439     if (dev->mem_start) {       /* Shared memory transfer */
 440         unsigned long dest_addr = dev->mem_start +
 441             ((start_page - ei_status.tx_start_page) << 8);
 442         memcpy_toio(dest_addr, buf, count);
 443         outb(EGACFR_NORM, E33G_GACFR);  /* Back to bank1 in case on bank0 */
 444         return;
 445     }
 446     /* No shared memory, put the packet out the slow way. */
 447     /* Set up then start the internal memory transfer to Tx Start Page */
 448     outb(0x00, E33G_DMAAL);
 449     outb_p(start_page, E33G_DMAAH);
 450     outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
 451            | ECNTRL_START, E33G_CNTRL);
 452 
 453     /* This is the byte copy loop: it should probably be tuned for
 454        speed once everything is working.  I think it is possible
 455        to output 8 bytes between each check of the status bit. */
 456     for(i = 0; i < count; i++) {
 457         if (i % 8 == 0)
 458             while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
 459                 if (++boguscount > (i<<3) + 32) {
 460                     printk("%s: FIFO blocked in el2_block_output (at %d of %d, bc=%d).\n",
 461                            dev->name, i, count, boguscount);
 462                     outb(EGACFR_NORM, E33G_GACFR);      /* To MB1 for EL2/16 */
 463                     return;
 464                 }
 465         outb(buf[i], E33G_FIFOH);
 466     }
 467     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 468     outb(EGACFR_NORM, E33G_GACFR);      /* Back to bank1 in case on bank0 */
 469     return;
 470 }
 471 
 472 /* Read the 4 byte, page aligned 8390 specific header. */
 473 static void
 474 el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
     /* [previous][next][first][last][top][bottom][index][help] */
 475 {
 476     unsigned int i;
 477     unsigned long hdr_start = dev->mem_start + ((ring_page - EL2_MB1_START_PG)<<8);
 478 
 479     if (dev->mem_start) {       /* Use the shared memory. */
 480 #ifdef notdef
 481         /* Officially this is what we are doing, but the readl() is faster */
 482         memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
 483 #else
 484         ((unsigned int*)hdr)[0] = readl(hdr_start);
 485 #endif
 486         return;
 487     }
 488 
 489     /* No shared memory, use programmed I/O. Ugh. */
 490     outb(0, E33G_DMAAL);
 491     outb_p(ring_page & 0xff, E33G_DMAAH);
 492     outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
 493            | ECNTRL_START, E33G_CNTRL);
 494 
 495     /* Header is less than 8 bytes, so we can ignore the FIFO. */
 496     for(i = 0; i < sizeof(struct e8390_pkt_hdr); i++)
 497         ((char *)(hdr))[i] = inb_p(E33G_FIFOH);
 498 
 499     outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 500 }
 501 
 502 /* Returns the new ring pointer. */
 503 static void
 504 el2_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 505 {
 506     int boguscount = 0;
 507     int end_of_ring = dev->rmem_end;
 508     unsigned int i;
 509 
 510     /* Maybe enable shared memory just be to be safe... nahh.*/
 511     if (dev->mem_start) {       /* Use the shared memory. */
 512         ring_offset -= (EL2_MB1_START_PG<<8);
 513         if (dev->mem_start + ring_offset + count > end_of_ring) {
 514             /* We must wrap the input move. */
 515             int semi_count = end_of_ring - (dev->mem_start + ring_offset);
 516             memcpy_fromio(skb->data, dev->mem_start + ring_offset, semi_count);
 517             count -= semi_count;
 518             memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
 519         } else {
 520                 /* Packet is in one chunk -- we can copy + cksum. */
 521                 eth_io_copy_and_sum(skb, dev->mem_start + ring_offset, count, 0);
 522         }
 523         return;
 524     }
 525     /* No shared memory, use programmed I/O. */
 526     outb(ring_offset & 0xff, E33G_DMAAL);
 527     outb_p((ring_offset >> 8) & 0xff, E33G_DMAAH);
 528     outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
 529            | ECNTRL_START, E33G_CNTRL);
 530 
 531     /* This is the byte copy loop: it should probably be tuned for
 532        speed once everything is working. */
 533     for(i = 0; i < count; i++) {
 534         if (i % 8 == 0)
 535             while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
 536                 if (++boguscount > (i<<3) + 32) {
 537                     printk("%s: FIFO blocked in el2_block_input() (at %d of %d, bc=%d).\n",
 538                            dev->name, i, count, boguscount);
 539                     boguscount = 0;
 540                     break;
 541                 }
 542         (skb->data)[i] = inb_p(E33G_FIFOH);
 543     }
 544     outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 545 }
 546 
 547 
 548 #ifdef MODULE
 549 #define MAX_EL2_CARDS   4       /* Max number of EL2 cards per module */
 550 #define NAMELEN         8       /* # of chars for storing dev->name */
 551 static char namelist[NAMELEN * MAX_EL2_CARDS] = { 0, };
 552 static struct device dev_el2[MAX_EL2_CARDS] = {
 553         {
 554                 NULL,           /* assign a chunk of namelist[] below */
 555                 0, 0, 0, 0,
 556                 0, 0,
 557                 0, 0, 0, NULL, NULL
 558         },
 559 };
 560 
 561 static int io[MAX_EL2_CARDS] = { 0, };
 562 static int irq[MAX_EL2_CARDS]  = { 0, };
 563 static int xcvr[MAX_EL2_CARDS] = { 0, };        /* choose int. or ext. xcvr */
 564 
 565 /* This is set up so that only a single autoprobe takes place per call.
 566 ISA device autoprobes on a running machine are not recommended. */
 567 int
 568 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 569 {
 570         int this_dev, found = 0;
 571 
 572         for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
 573                 struct device *dev = &dev_el2[this_dev];
 574                 dev->name = namelist+(NAMELEN*this_dev);
 575                 dev->irq = irq[this_dev];
 576                 dev->base_addr = io[this_dev];
 577                 dev->mem_end = xcvr[this_dev];  /* low 4bits = xcvr sel. */
 578                 dev->init = el2_probe;
 579                 if (io[this_dev] == 0)  {
 580                         if (this_dev != 0) break; /* only autoprobe 1st one */
 581                         printk(KERN_NOTICE "3c503.c: Presently autoprobing (not recommended) for a single card.\n");
 582                 }
 583                 if (register_netdev(dev) != 0) {
 584                         printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
 585                         if (found != 0) return 0;       /* Got at least one. */
 586                         return -ENXIO;
 587                 }
 588                 found++;
 589         }
 590 
 591         return 0;
 592 }
 593 
 594 void
 595 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 596 {
 597         int this_dev;
 598 
 599         for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
 600                 struct device *dev = &dev_el2[this_dev];
 601                 if (dev->priv != NULL) {
 602                         /* NB: el2_close() handles free_irq + irq2dev map */
 603                         kfree(dev->priv);
 604                         dev->priv = NULL;
 605                         release_region(dev->base_addr, EL2_IO_EXTENT);
 606                         unregister_netdev(dev);
 607                 }
 608         }
 609 }
 610 #endif /* MODULE */
 611 
 612 /*
 613  * Local variables:
 614  *  version-control: t
 615  *  kept-new-versions: 5
 616  *  c-indent-level: 4
 617  * End:
 618  */

/* [previous][next][first][last][top][bottom][index][help] */