root/drivers/net/ne.c

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

DEFINITIONS

This source file includes following definitions.
  1. ne_probe
  2. ne_probe1
  3. ne_open
  4. ne_close
  5. ne_reset_8390
  6. ne_get_8390_hdr
  7. ne_block_input
  8. ne_block_output
  9. init_module
  10. cleanup_module

   1 /* ne.c: A general non-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.
   7 
   8     This software may be used and distributed according to the terms
   9     of the GNU Public License, incorporated herein by reference.
  10 
  11     The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  12     Center of Excellence in Space Data and Information Sciences
  13         Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  14 
  15     This driver should work with many programmed-I/O 8390-based ethernet
  16     boards.  Currently it supports the NE1000, NE2000, many clones,
  17     and some Cabletron products.
  18 
  19     Changelog:
  20 
  21     Paul Gortmaker      : use ENISR_RDC to monitor Tx PIO uploads, made
  22                           sanity checks and bad clone support optional.
  23     Paul Gortmaker      : new reset code, reset card after probe at boot.
  24     Paul Gortmaker      : multiple card support for module users.
  25     Paul Gortmaker      : Support for PCI ne2k clones, similar to lance.c
  26 
  27 */
  28 
  29 /* Routines for the NatSemi-based designs (NE[12]000). */
  30 
  31 static const char *version =
  32     "ne.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  33 
  34 
  35 #include <linux/module.h>
  36 #include <linux/config.h>
  37 #include <linux/kernel.h>
  38 #include <linux/sched.h>
  39 #include <linux/errno.h>
  40 #include <linux/pci.h>
  41 #include <linux/bios32.h>
  42 #include <asm/system.h>
  43 #include <asm/io.h>
  44 
  45 #include <linux/netdevice.h>
  46 #include <linux/etherdevice.h>
  47 #include "8390.h"
  48 
  49 /* Some defines that people can play with if so inclined. */
  50 
  51 /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
  52 #define SUPPORT_NE_BAD_CLONES
  53 
  54 /* Do we perform extra sanity checks on stuff ? */
  55 /* #define NE_SANITY_CHECK */
  56 
  57 /* Do we implement the read before write bugfix ? */
  58 /* #define NE_RW_BUGFIX */
  59 
  60 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
  61 /* #define PACKETBUF_MEMSIZE    0x40 */
  62 
  63 /* ---- No user-serviceable parts below ---- */
  64 
  65 /* A zero-terminated list of I/O addresses to be probed. */
  66 static unsigned int netcard_portlist[] =
  67 { 0x300, 0x280, 0x320, 0x340, 0x360, 0};
  68 
  69 #ifdef SUPPORT_NE_BAD_CLONES
  70 /* A list of bad clones that we none-the-less recognize. */
  71 static struct { const char *name8, *name16; unsigned char SAprefix[4];}
  72 bad_clone_list[] = {
  73     {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
  74     {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
  75     {"DFI1000", "DFI2000", {'D', 'F', 'I',}}, /* Original, eh?  */
  76     {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
  77     {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}}, /* Ancient real NE1000. */
  78     {"NN1000", "NN2000",  {0x08, 0x03, 0x08}}, /* Outlaw no-name clone. */
  79     {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}},  /* Outlaw 4-Dimension cards. */
  80     {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}}, /* Connect Int'nl */
  81     {0,}
  82 };
  83 #endif
  84 
  85 #define NE_BASE  (dev->base_addr)
  86 #define NE_CMD          0x00
  87 #define NE_DATAPORT     0x10    /* NatSemi-defined port window offset. */
  88 #define NE_RESET        0x1f    /* Issue a read to reset, a write to clear. */
  89 #define NE_IO_EXTENT    0x20
  90 
  91 #define NE1SM_START_PG  0x20    /* First page of TX buffer */
  92 #define NE1SM_STOP_PG   0x40    /* Last page +1 of RX ring */
  93 #define NESM_START_PG   0x40    /* First page of TX buffer */
  94 #define NESM_STOP_PG    0x80    /* Last page +1 of RX ring */
  95 
  96 /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */
  97 static unsigned char pci_irq_line = 0;
  98 
  99 int ne_probe(struct device *dev);
 100 static int ne_probe1(struct device *dev, int ioaddr);
 101 
 102 static int ne_open(struct device *dev);
 103 static int ne_close(struct device *dev);
 104 
 105 static void ne_reset_8390(struct device *dev);
 106 static void ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
 107                           int ring_page);
 108 static void ne_block_input(struct device *dev, int count,
 109                           struct sk_buff *skb, int ring_offset);
 110 static void ne_block_output(struct device *dev, const int count,
 111                 const unsigned char *buf, const int start_page);
 112 
 113 
 114 /*  Probe for various non-shared-memory ethercards.
 115 
 116    NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
 117    buffer memory space.  NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
 118    the SAPROM, while other supposed NE2000 clones must be detected by their
 119    SA prefix.
 120 
 121    Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
 122    mode results in doubled values, which can be detected and compensated for.
 123 
 124    The probe is also responsible for initializing the card and filling
 125    in the 'dev' and 'ei_status' structures.
 126 
 127    We use the minimum memory size for some ethercard product lines, iff we can't
 128    distinguish models.  You can increase the packet buffer size by setting
 129    PACKETBUF_MEMSIZE.  Reported Cabletron packet buffer locations are:
 130         E1010   starts at 0x100 and ends at 0x2000.
 131         E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
 132         E2010    starts at 0x100 and ends at 0x4000.
 133         E2010-x starts at 0x100 and ends at 0xffff.  */
 134 
 135 #ifdef HAVE_DEVLIST
 136 struct netdev_entry netcard_drv =
 137 {"ne", ne_probe1, NE_IO_EXTENT, netcard_portlist};
 138 #else
 139 
 140 /*  Note that this probe only picks up one card at a time, even for multiple
 141     PCI ne2k cards. Use "ether=0,0,eth1" if you have a second PCI ne2k card.
 142     This keeps things consistent regardless of the bus type of the card. */
 143 
 144 int ne_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146     int i;
 147     int base_addr = dev ? dev->base_addr : 0;
 148 
 149     /* First check any supplied i/o locations. User knows best. <cough> */
 150     if (base_addr > 0x1ff)      /* Check a single specified location. */
 151         return ne_probe1(dev, base_addr);
 152     else if (base_addr != 0)    /* Don't probe at all. */
 153         return ENXIO;
 154 
 155     /* Then look for any installed PCI clones */
 156 #if defined(CONFIG_PCI)
 157     if (pcibios_present()) {
 158         int pci_index;
 159         for (pci_index = 0; pci_index < 8; pci_index++) {
 160                 unsigned char pci_bus, pci_device_fn;
 161                 unsigned int pci_ioaddr;
 162 
 163                 /* Currently only Realtek are making PCI ne2k clones. */
 164                 if (pcibios_find_device (PCI_VENDOR_ID_REALTEK,
 165                                 PCI_DEVICE_ID_REALTEK_8029, pci_index,
 166                                 &pci_bus, &pci_device_fn) != 0)
 167                         break;  /* OK, now try to probe for std. ISA card */
 168                 pcibios_read_config_byte(pci_bus, pci_device_fn,
 169                                 PCI_INTERRUPT_LINE, &pci_irq_line);
 170                 pcibios_read_config_dword(pci_bus, pci_device_fn,
 171                                 PCI_BASE_ADDRESS_0, &pci_ioaddr);
 172                 /* Strip the I/O address out of the returned value */
 173                 pci_ioaddr &= PCI_BASE_ADDRESS_IO_MASK;
 174                 /* Avoid already found cards from previous ne_probe() calls */
 175                 if (check_region(pci_ioaddr, NE_IO_EXTENT))
 176                         continue;
 177                 printk("ne.c: PCI BIOS reports ne2000 clone at i/o %#x, irq %d.\n",
 178                                 pci_ioaddr, pci_irq_line);
 179                 if (ne_probe1(dev, pci_ioaddr) != 0) {  /* Shouldn't happen. */
 180                         printk(KERN_ERR "ne.c: Probe of PCI card at %#x failed.\n", pci_ioaddr);
 181                         break;  /* Hrmm, try to probe for ISA card... */
 182                 }
 183                 pci_irq_line = 0;
 184                 return 0;
 185         }
 186     }
 187 #endif  /* defined(CONFIG_PCI) */
 188 
 189     /* Last resort. The semi-risky ISA auto-probe. */
 190     for (i = 0; netcard_portlist[i]; i++) {
 191         int ioaddr = netcard_portlist[i];
 192         if (check_region(ioaddr, NE_IO_EXTENT))
 193             continue;
 194         if (ne_probe1(dev, ioaddr) == 0)
 195             return 0;
 196     }
 197 
 198     return ENODEV;
 199 }
 200 #endif
 201 
 202 static int ne_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 203 {
 204     int i;
 205     unsigned char SA_prom[32];
 206     int wordlength = 2;
 207     const char *name = NULL;
 208     int start_page, stop_page;
 209     int neX000, ctron;
 210     int reg0 = inb_p(ioaddr);
 211     static unsigned version_printed = 0;
 212 
 213     if (reg0 == 0xFF)
 214         return ENODEV;
 215 
 216     /* Do a preliminary verification that we have a 8390. */
 217     {   int regd;
 218         outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
 219         regd = inb_p(ioaddr + 0x0d);
 220         outb_p(0xff, ioaddr + 0x0d);
 221         outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
 222         inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
 223         if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
 224             outb_p(reg0, ioaddr);
 225             outb_p(regd, ioaddr + 0x0d);        /* Restore the old values. */
 226             return ENODEV;
 227         }
 228     }
 229 
 230     if (ei_debug  &&  version_printed++ == 0)
 231         printk(version);
 232 
 233     printk("NE*000 ethercard probe at %#3x:", ioaddr);
 234 
 235     /* Reset card. Who knows what dain-bramaged state it was left in. */
 236     {   unsigned long reset_start_time = jiffies;
 237 
 238         /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
 239         outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
 240 
 241         while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
 242                 if (jiffies - reset_start_time > 2*HZ/100) {
 243                         printk(" not found (no reset ack).\n");
 244                         return ENODEV;
 245                 }
 246 
 247         outb_p(0xff, ioaddr + EN0_ISR);         /* Ack all intr. */
 248     }
 249 
 250     /* Read the 16 bytes of station address PROM.
 251        We must first initialize registers, similar to NS8390_init(eifdev, 0).
 252        We can't reliably read the SAPROM address without this.
 253        (I learned the hard way!). */
 254     {
 255         struct {unsigned char value, offset; } program_seq[] = {
 256             {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
 257             {0x48,      EN0_DCFG},      /* Set byte-wide (0x48) access. */
 258             {0x00,      EN0_RCNTLO},    /* Clear the count regs. */
 259             {0x00,      EN0_RCNTHI},
 260             {0x00,      EN0_IMR},       /* Mask completion irq. */
 261             {0xFF,      EN0_ISR},
 262             {E8390_RXOFF, EN0_RXCR},    /* 0x20  Set to monitor */
 263             {E8390_TXOFF, EN0_TXCR},    /* 0x02  and loopback mode. */
 264             {32,        EN0_RCNTLO},
 265             {0x00,      EN0_RCNTHI},
 266             {0x00,      EN0_RSARLO},    /* DMA starting at 0x0000. */
 267             {0x00,      EN0_RSARHI},
 268             {E8390_RREAD+E8390_START, E8390_CMD},
 269         };
 270         for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
 271             outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 272 
 273     }
 274     for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
 275         SA_prom[i] = inb(ioaddr + NE_DATAPORT);
 276         SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
 277         if (SA_prom[i] != SA_prom[i+1])
 278             wordlength = 1;
 279     }
 280 
 281     if (wordlength == 2) {
 282         /* We must set the 8390 for word mode. */
 283         outb_p(0x49, ioaddr + EN0_DCFG);
 284         /* We used to reset the ethercard here, but it doesn't seem
 285            to be necessary. */
 286         /* Un-double the SA_prom values. */
 287         for (i = 0; i < 16; i++)
 288             SA_prom[i] = SA_prom[i+i];
 289         start_page = NESM_START_PG;
 290         stop_page = NESM_STOP_PG;
 291     } else {
 292         start_page = NE1SM_START_PG;
 293         stop_page = NE1SM_STOP_PG;
 294     }
 295 
 296     neX000 = (SA_prom[14] == 0x57  &&  SA_prom[15] == 0x57);
 297     ctron =  (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
 298 
 299     /* Set up the rest of the parameters. */
 300     if (neX000) {
 301         name = (wordlength == 2) ? "NE2000" : "NE1000";
 302     } else if (ctron) {
 303         name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
 304         start_page = 0x01;
 305         stop_page = (wordlength == 2) ? 0x40 : 0x20;
 306     } else {
 307 #ifdef SUPPORT_NE_BAD_CLONES
 308         /* Ack!  Well, there might be a *bad* NE*000 clone there.
 309            Check for total bogus addresses. */
 310         for (i = 0; bad_clone_list[i].name8; i++) {
 311             if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
 312                 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
 313                 SA_prom[2] == bad_clone_list[i].SAprefix[2]) {
 314                 if (wordlength == 2) {
 315                     name = bad_clone_list[i].name16;
 316                 } else {
 317                     name = bad_clone_list[i].name8;
 318                 }
 319                 break;
 320             }
 321         }
 322         if (bad_clone_list[i].name8 == NULL) {
 323             printk(" not found (invalid signature %2.2x %2.2x).\n",
 324                    SA_prom[14], SA_prom[15]);
 325             return ENXIO;
 326         }
 327 #else
 328         printk(" not found.\n");
 329         return ENXIO;
 330 #endif
 331 
 332     }
 333 
 334     /* We should have a "dev" from Space.c or the static module table. */
 335     if (dev == NULL) {
 336         printk("ne.c: Passed a NULL device.\n");
 337         dev = init_etherdev(0, 0);
 338     }
 339 
 340     if (pci_irq_line) {
 341         dev->irq = pci_irq_line;
 342     }
 343 
 344     if (dev->irq < 2) {
 345         autoirq_setup(0);
 346         outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
 347         outb_p(0x00, ioaddr + EN0_RCNTLO);
 348         outb_p(0x00, ioaddr + EN0_RCNTHI);
 349         outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
 350         outb_p(0x00, ioaddr + EN0_IMR);                 /* Mask it again. */
 351         dev->irq = autoirq_report(0);
 352         if (ei_debug > 2)
 353             printk(" autoirq is %d\n", dev->irq);
 354     } else if (dev->irq == 2)
 355         /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
 356            or don't know which one to set. */
 357         dev->irq = 9;
 358 
 359     if (! dev->irq) {
 360         printk(" failed to detect IRQ line.\n");
 361         return EAGAIN;
 362     }
 363     
 364     /* Snarf the interrupt now.  There's no point in waiting since we cannot
 365        share and the board will usually be enabled. */
 366     {
 367         int irqval = request_irq(dev->irq, ei_interrupt, 0, name, NULL);
 368         if (irqval) {
 369             printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
 370             return EAGAIN;
 371         }
 372     }
 373 
 374     dev->base_addr = ioaddr;
 375 
 376     /* Allocate dev->priv and fill in 8390 specific dev fields. */
 377     if (ethdev_init(dev)) {
 378         printk (" unable to get memory for dev->priv.\n");
 379         free_irq(dev->irq, NULL);
 380         return -ENOMEM;
 381     }
 382  
 383     request_region(ioaddr, NE_IO_EXTENT, name);
 384 
 385     for(i = 0; i < ETHER_ADDR_LEN; i++) {
 386         printk(" %2.2x", SA_prom[i]);
 387         dev->dev_addr[i] = SA_prom[i];
 388     }
 389 
 390     printk("\n%s: %s found at %#x, using IRQ %d.\n",
 391            dev->name, name, ioaddr, dev->irq);
 392 
 393     ei_status.name = name;
 394     ei_status.tx_start_page = start_page;
 395     ei_status.stop_page = stop_page;
 396     ei_status.word16 = (wordlength == 2);
 397 
 398     ei_status.rx_start_page = start_page + TX_PAGES;
 399 #ifdef PACKETBUF_MEMSIZE
 400     /* Allow the packet buffer size to be overridden by know-it-alls. */
 401     ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
 402 #endif
 403 
 404     ei_status.reset_8390 = &ne_reset_8390;
 405     ei_status.block_input = &ne_block_input;
 406     ei_status.block_output = &ne_block_output;
 407     ei_status.get_8390_hdr = &ne_get_8390_hdr;
 408     dev->open = &ne_open;
 409     dev->stop = &ne_close;
 410     NS8390_init(dev, 0);
 411     return 0;
 412 }
 413 
 414 static int
 415 ne_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417     ei_open(dev);
 418     MOD_INC_USE_COUNT;
 419     return 0;
 420 }
 421 
 422 static int
 423 ne_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 424 {
 425     if (ei_debug > 1)
 426         printk("%s: Shutting down ethercard.\n", dev->name);
 427     ei_close(dev);
 428     MOD_DEC_USE_COUNT;
 429     return 0;
 430 }
 431 
 432 /* Hard reset the card.  This used to pause for the same period that a
 433    8390 reset command required, but that shouldn't be necessary. */
 434 static void
 435 ne_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 436 {
 437     unsigned long reset_start_time = jiffies;
 438 
 439     if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
 440 
 441     /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
 442     outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
 443 
 444     ei_status.txing = 0;
 445     ei_status.dmaing = 0;
 446 
 447     /* This check _should_not_ be necessary, omit eventually. */
 448     while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
 449         if (jiffies - reset_start_time > 2*HZ/100) {
 450             printk("%s: ne_reset_8390() did not complete.\n", dev->name);
 451             break;
 452         }
 453     outb_p(ENISR_RESET, NE_BASE + EN0_ISR);     /* Ack intr. */
 454 }
 455 
 456 /* Grab the 8390 specific header. Similar to the block_input routine, but
 457    we don't need to be concerned with ring wrap as the header will be at
 458    the start of a page, so we optimize accordingly. */
 459 
 460 static void
 461 ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
     /* [previous][next][first][last][top][bottom][index][help] */
 462 {
 463 
 464     int nic_base = dev->base_addr;
 465 
 466     /* This *shouldn't* happen. If it does, it's the last thing you'll see */
 467     if (ei_status.dmaing) {
 468         printk("%s: DMAing conflict in ne_get_8390_hdr "
 469            "[DMAstat:%d][irqlock:%d][intr:%d].\n",
 470            dev->name, ei_status.dmaing, ei_status.irqlock,
 471            dev->interrupt);
 472         return;
 473     }
 474 
 475     ei_status.dmaing |= 0x01;
 476     outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
 477     outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
 478     outb_p(0, nic_base + EN0_RCNTHI);
 479     outb_p(0, nic_base + EN0_RSARLO);           /* On page boundary */
 480     outb_p(ring_page, nic_base + EN0_RSARHI);
 481     outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
 482 
 483     if (ei_status.word16)
 484         insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
 485     else
 486         insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
 487 
 488     outb_p(ENISR_RDC, nic_base + EN0_ISR);      /* Ack intr. */
 489     ei_status.dmaing &= ~0x01;
 490 }
 491 
 492 /* Block input and output, similar to the Crynwr packet driver.  If you
 493    are porting to a new ethercard, look at the packet driver source for hints.
 494    The NEx000 doesn't share the on-board packet memory -- you have to put
 495    the packet out through the "remote DMA" dataport using outb. */
 496 
 497 static void
 498 ne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 499 {
 500 #ifdef NE_SANITY_CHECK
 501     int xfer_count = count;
 502 #endif
 503     int nic_base = dev->base_addr;
 504     char *buf = skb->data;
 505 
 506     /* This *shouldn't* happen. If it does, it's the last thing you'll see */
 507     if (ei_status.dmaing) {
 508         printk("%s: DMAing conflict in ne_block_input "
 509            "[DMAstat:%d][irqlock:%d][intr:%d].\n",
 510            dev->name, ei_status.dmaing, ei_status.irqlock,
 511            dev->interrupt);
 512         return;
 513     }
 514     ei_status.dmaing |= 0x01;
 515     outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
 516     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 517     outb_p(count >> 8, nic_base + EN0_RCNTHI);
 518     outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
 519     outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
 520     outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
 521     if (ei_status.word16) {
 522       insw(NE_BASE + NE_DATAPORT,buf,count>>1);
 523       if (count & 0x01) {
 524         buf[count-1] = inb(NE_BASE + NE_DATAPORT);
 525 #ifdef NE_SANITY_CHECK
 526         xfer_count++;
 527 #endif
 528       }
 529     } else {
 530         insb(NE_BASE + NE_DATAPORT, buf, count);
 531     }
 532 
 533 #ifdef NE_SANITY_CHECK
 534     /* This was for the ALPHA version only, but enough people have
 535        been encountering problems so it is still here.  If you see
 536        this message you either 1) have a slightly incompatible clone
 537        or 2) have noise/speed problems with your bus. */
 538     if (ei_debug > 1) {         /* DMA termination address check... */
 539         int addr, tries = 20;
 540         do {
 541             /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
 542                -- it's broken for Rx on some cards! */
 543             int high = inb_p(nic_base + EN0_RSARHI);
 544             int low = inb_p(nic_base + EN0_RSARLO);
 545             addr = (high << 8) + low;
 546             if (((ring_offset + xfer_count) & 0xff) == low)
 547                 break;
 548         } while (--tries > 0);
 549         if (tries <= 0)
 550             printk("%s: RX transfer address mismatch,"
 551                    "%#4.4x (expected) vs. %#4.4x (actual).\n",
 552                    dev->name, ring_offset + xfer_count, addr);
 553     }
 554 #endif
 555     outb_p(ENISR_RDC, nic_base + EN0_ISR);      /* Ack intr. */
 556     ei_status.dmaing &= ~0x01;
 557 }
 558 
 559 static void
 560 ne_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 561                 const unsigned char *buf, const int start_page)
 562 {
 563     int nic_base = NE_BASE;
 564     unsigned long dma_start;
 565 #ifdef NE_SANITY_CHECK
 566     int retries = 0;
 567 #endif
 568 
 569     /* Round the count up for word writes.  Do we need to do this?
 570        What effect will an odd byte count have on the 8390?
 571        I should check someday. */
 572     if (ei_status.word16 && (count & 0x01))
 573       count++;
 574 
 575     /* This *shouldn't* happen. If it does, it's the last thing you'll see */
 576     if (ei_status.dmaing) {
 577         printk("%s: DMAing conflict in ne_block_output."
 578            "[DMAstat:%d][irqlock:%d][intr:%d]\n",
 579            dev->name, ei_status.dmaing, ei_status.irqlock,
 580            dev->interrupt);
 581         return;
 582     }
 583     ei_status.dmaing |= 0x01;
 584     /* We should already be in page 0, but to be safe... */
 585     outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
 586 
 587 #ifdef NE_SANITY_CHECK
 588  retry:
 589 #endif
 590 
 591 #ifdef NE8390_RW_BUGFIX
 592     /* Handle the read-before-write bug the same way as the
 593        Crynwr packet driver -- the NatSemi method doesn't work.
 594        Actually this doesn't always work either, but if you have
 595        problems with your NEx000 this is better than nothing! */
 596     outb_p(0x42, nic_base + EN0_RCNTLO);
 597     outb_p(0x00,   nic_base + EN0_RCNTHI);
 598     outb_p(0x42, nic_base + EN0_RSARLO);
 599     outb_p(0x00, nic_base + EN0_RSARHI);
 600     outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
 601     /* Make certain that the dummy read has occurred. */
 602     SLOW_DOWN_IO;
 603     SLOW_DOWN_IO;
 604     SLOW_DOWN_IO;
 605 #endif
 606 
 607     outb_p(ENISR_RDC, nic_base + EN0_ISR);
 608 
 609    /* Now the normal output. */
 610     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 611     outb_p(count >> 8,   nic_base + EN0_RCNTHI);
 612     outb_p(0x00, nic_base + EN0_RSARLO);
 613     outb_p(start_page, nic_base + EN0_RSARHI);
 614 
 615     outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
 616     if (ei_status.word16) {
 617         outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
 618     } else {
 619         outsb(NE_BASE + NE_DATAPORT, buf, count);
 620     }
 621 
 622     dma_start = jiffies;
 623 
 624 #ifdef NE_SANITY_CHECK
 625     /* This was for the ALPHA version only, but enough people have
 626        been encountering problems so it is still here. */
 627     if (ei_debug > 1) {         /* DMA termination address check... */
 628         int addr, tries = 20;
 629         do {
 630             int high = inb_p(nic_base + EN0_RSARHI);
 631             int low = inb_p(nic_base + EN0_RSARLO);
 632             addr = (high << 8) + low;
 633             if ((start_page << 8) + count == addr)
 634                 break;
 635         } while (--tries > 0);
 636         if (tries <= 0) {
 637             printk("%s: Tx packet transfer address mismatch,"
 638                    "%#4.4x (expected) vs. %#4.4x (actual).\n",
 639                    dev->name, (start_page << 8) + count, addr);
 640             if (retries++ == 0)
 641                 goto retry;
 642         }
 643     }
 644 #endif
 645 
 646     while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
 647         if (jiffies - dma_start > 2*HZ/100) {           /* 20ms */
 648                 printk("%s: timeout waiting for Tx RDC.\n", dev->name);
 649                 ne_reset_8390(dev);
 650                 NS8390_init(dev,1);
 651                 break;
 652         }
 653 
 654     outb_p(ENISR_RDC, nic_base + EN0_ISR);      /* Ack intr. */
 655     ei_status.dmaing &= ~0x01;
 656     return;
 657 }
 658 
 659 
 660 #ifdef MODULE
 661 #define MAX_NE_CARDS    4       /* Max number of NE cards per module */
 662 #define NAMELEN         8       /* # of chars for storing dev->name */
 663 static char namelist[NAMELEN * MAX_NE_CARDS] = { 0, };
 664 static struct device dev_ne[MAX_NE_CARDS] = {
 665         {
 666                 NULL,           /* assign a chunk of namelist[] below */
 667                 0, 0, 0, 0,
 668                 0, 0,
 669                 0, 0, 0, NULL, NULL
 670         },
 671 };
 672 
 673 static int io[MAX_NE_CARDS] = { 0, };
 674 static int irq[MAX_NE_CARDS]  = { 0, };
 675 
 676 /* This is set up so that no autoprobe takes place. We can't guarantee
 677 that the ne2k probe is the last 8390 based probe to take place (as it
 678 is at boot) and so the probe will get confused by any other 8390 cards.
 679 ISA device autoprobes on a running machine are not recommended anyway. */
 680 
 681 int
 682 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 683 {
 684         int this_dev, found = 0;
 685 
 686         for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
 687                 struct device *dev = &dev_ne[this_dev];
 688                 dev->name = namelist+(NAMELEN*this_dev);
 689                 dev->irq = irq[this_dev];
 690                 dev->base_addr = io[this_dev];
 691                 dev->init = ne_probe;
 692                 if (io[this_dev] == 0)  {
 693                         if (this_dev != 0) break; /* only complain once */
 694                         printk(KERN_NOTICE "ne.c: Module autoprobing not allowed. Append \"io=0xNNN\" value(s).\n");
 695                         return -EPERM;
 696                 }
 697                 if (register_netdev(dev) != 0) {
 698                         printk(KERN_WARNING "ne.c: No NE*000 card found (i/o = 0x%x).\n", io[this_dev]);
 699                         if (found != 0) return 0;       /* Got at least one. */
 700                         return -ENXIO;
 701                 }
 702                 found++;
 703         }
 704 
 705         return 0;
 706 }
 707 
 708 void
 709 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 710 {
 711         int this_dev;
 712 
 713         for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
 714                 struct device *dev = &dev_ne[this_dev];
 715                 if (dev->priv != NULL) {
 716                         kfree(dev->priv);
 717                         dev->priv = NULL;
 718                         free_irq(dev->irq, NULL);
 719                         irq2dev_map[dev->irq] = NULL;
 720                         release_region(dev->base_addr, NE_IO_EXTENT);
 721                         unregister_netdev(dev);
 722                 }
 723         }
 724 }
 725 #endif /* MODULE */
 726 
 727 /*
 728  * Local variables:
 729  *  compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c ne.c"
 730  *  version-control: t
 731  *  kept-new-versions: 5
 732  * End:
 733  */

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