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

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