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

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