Annotation of Gnu-Mach/linux/src/drivers/net/ne2k-pci.c, revision 1.1.1.1

1.1       root        1: /* ne2k-pci.c: A NE2000 clone on PCI bus driver for Linux. */
                      2: /*
                      3:        A Linux device driver for PCI NE2000 clones.
                      4: 
                      5:        Authorship and other copyrights:
                      6:        1992-1998 by Donald Becker, NE2000 core and various modifications.
                      7:        1995-1998 by Paul Gortmaker, core modifications and PCI support.
                      8: 
                      9:        Copyright 1993 assigned to the United States Government as represented
                     10:        by the Director, National Security Agency.
                     11: 
                     12:        This software may be used and distributed according to the terms
                     13:        of the GNU Public License, incorporated herein by reference.
                     14: 
                     15:        The author may be reached as [email protected], or C/O
                     16:        Center of Excellence in Space Data and Information Sciences
                     17:        Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
                     18: 
                     19:        People are making PCI ne2000 clones! Oh the horror, the horror...
                     20: 
                     21:        Issues remaining:
                     22:        No full-duplex support.
                     23: */
                     24: 
                     25: /* Our copyright info must remain in the binary. */
                     26: static const char *version =
                     27: "ne2k-pci.c:v0.99L 2/7/98 D. Becker/P. Gortmaker http://cesdis.gsfc.nasa.gov/linux/drivers/ne2k-pci.html\n";
                     28: 
                     29: #ifdef MODVERSIONS
                     30: #include <linux/modversions.h>
                     31: #endif
                     32: #include <linux/module.h>
                     33: #include <linux/kernel.h>
                     34: #include <linux/sched.h>
                     35: #include <linux/errno.h>
                     36: #include <linux/pci.h>
                     37: #include <linux/bios32.h>
                     38: #include <asm/system.h>
                     39: #include <asm/io.h>
                     40: #include <asm/irq.h>
                     41: 
                     42: #include <linux/netdevice.h>
                     43: #include <linux/etherdevice.h>
                     44: #include "8390.h"
                     45: 
                     46: /* Set statically or when loading the driver module. */
                     47: static int debug = 1;
                     48: 
                     49: /* Some defines that people can play with if so inclined. */
                     50: 
                     51: /* Do #define LOAD_8390_BY_KERNELD to automatically load 8390 support. */
                     52: #ifdef LOAD_8390_BY_KERNELD
                     53: #include <linux/kerneld.h>
                     54: #endif
                     55: /* Use 32 bit data-movement operations instead of 16 bit. */
                     56: #define USE_LONGIO
                     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: static struct {
                     65:        unsigned short vendor, dev_id;
                     66:        char *name;
                     67: }
                     68: pci_clone_list[] = {
                     69:        {0x10ec, 0x8029, "RealTek RTL-8029"},
                     70:        {0x1050, 0x0940, "Winbond 89C940"},
                     71:        {0x11f6, 0x1401, "Compex RL2000"},
                     72:        {0x8e2e, 0x3000, "KTI ET32P2"},
                     73:        {0x4a14, 0x5000, "NetVin NV5000SC"},
                     74:        {0x1106, 0x0926, "Via 82C926"},
                     75:        {0,}
                     76: };
                     77: 
                     78: /* ---- No user-serviceable parts below ---- */
                     79: 
                     80: #define NE_BASE         (dev->base_addr)
                     81: #define NE_CMD         0x00
                     82: #define NE_DATAPORT    0x10    /* NatSemi-defined port window offset. */
                     83: #define NE_RESET       0x1f    /* Issue a read to reset, a write to clear. */
                     84: #define NE_IO_EXTENT   0x20
                     85: 
                     86: #define NESM_START_PG  0x40    /* First page of TX buffer */
                     87: #define NESM_STOP_PG   0x80    /* Last page +1 of RX ring */
                     88: 
                     89: int ne2k_pci_probe(struct device *dev);
                     90: static struct device *ne2k_pci_probe1(struct device *dev, int ioaddr, int irq);
                     91: 
                     92: static int ne_open(struct device *dev);
                     93: static int ne_close(struct device *dev);
                     94: 
                     95: static void ne_reset_8390(struct device *dev);
                     96: static void ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
                     97:                          int ring_page);
                     98: static void ne_block_input(struct device *dev, int count,
                     99:                          struct sk_buff *skb, int ring_offset);
                    100: static void ne_block_output(struct device *dev, const int count,
                    101:                const unsigned char *buf, const int start_page);
                    102: 
                    103: 
                    104: 
                    105: /* No room in the standard 8390 structure for extra info we need. */
                    106: struct ne2k_pci_card {
                    107:        struct ne2k_pci_card *next;
                    108:        struct device *dev;
                    109:        unsigned char pci_bus, pci_device_fn;
                    110: };
                    111: /* A list of all installed devices, for removing the driver module. */
                    112: static struct ne2k_pci_card *ne2k_card_list = NULL;
                    113: 
                    114: #ifdef LOAD_8390_BY_KERNELD
                    115: static int (*Lethdev_init)(struct device *dev);
                    116: static void (*LNS8390_init)(struct device *dev, int startp);
                    117: static int (*Lei_open)(struct device *dev);
                    118: static int (*Lei_close)(struct device *dev);
                    119: static void (*Lei_interrupt)(int irq, void *dev_id, struct pt_regs *regs);
                    120: #else
                    121: #define Lethdev_init ethdev_init
                    122: #define LNS8390_init NS8390_init
                    123: #define Lei_open ei_open
                    124: #define Lei_close ei_close
                    125: #define Lei_interrupt ei_interrupt
                    126: #endif
                    127: 
                    128: #ifdef MODULE
                    129: 
                    130: int
                    131: init_module(void)
                    132: {
                    133:        /* We must emit version information. */
                    134:        if (debug)
                    135:                printk(KERN_INFO "%s", version);
                    136: 
                    137:        return ne2k_pci_probe(0);
                    138: }
                    139: 
                    140: void
                    141: cleanup_module(void)
                    142: {
                    143:        struct device *dev;
                    144:        struct ne2k_pci_card *this_card;
                    145: 
                    146:        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
                    147:        while (ne2k_card_list) {
                    148:                dev = ne2k_card_list->dev;
                    149:                unregister_netdev(dev);
                    150:                release_region(dev->base_addr, NE_IO_EXTENT);
                    151:                kfree(dev);
                    152:                this_card = ne2k_card_list;
                    153:                ne2k_card_list = ne2k_card_list->next;
                    154:                kfree(this_card);
                    155:        }
                    156: 
                    157: #ifdef LOAD_8390_BY_KERNELD
                    158:        release_module("8390", 0);
                    159: #endif
                    160: }
                    161: 
                    162: #endif  /* MODULE */
                    163: 
                    164: /*
                    165:   NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
                    166:   buffer memory space.  By-the-spec NE2000 clones have 0x57,0x57 in bytes
                    167:   0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
                    168:   detected by their SA prefix.
                    169: 
                    170:   Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
                    171:   mode results in doubled values, which can be detected and compensated for.
                    172: 
                    173:   The probe is also responsible for initializing the card and filling
                    174:   in the 'dev' and 'ei_status' structures.
                    175: */
                    176: 
                    177: #ifdef HAVE_DEVLIST
                    178: struct netdev_entry netcard_drv =
                    179: {"ne2k_pci", ne2k_pci_probe1, NE_IO_EXTENT, 0};
                    180: #endif
                    181: 
                    182: int ne2k_pci_probe(struct device *dev)
                    183: {
                    184:        static int pci_index = 0;       /* Static, for multiple calls. */
                    185:        int cards_found = 0;
                    186:        int i;
                    187: 
                    188:        if ( ! pcibios_present())
                    189:                return -ENODEV;
                    190: 
                    191:        for (;pci_index < 0xff; pci_index++) {
                    192:                unsigned char pci_bus, pci_device_fn;
                    193:                u8 pci_irq_line;
                    194:                u16 pci_command, new_command, vendor, device;
                    195:                u32 pci_ioaddr;
                    196: 
                    197:                if (pcibios_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, pci_index,
                    198:                                                                &pci_bus, &pci_device_fn)
                    199:                        != PCIBIOS_SUCCESSFUL)
                    200:                        break;
                    201:                pcibios_read_config_word(pci_bus, pci_device_fn,
                    202:                                                                 PCI_VENDOR_ID, &vendor);
                    203:                pcibios_read_config_word(pci_bus, pci_device_fn,
                    204:                                                                 PCI_DEVICE_ID, &device);
                    205: 
                    206:                /* Note: some vendor IDs (RealTek) have non-NE2k cards as well. */
                    207:                for (i = 0; pci_clone_list[i].vendor != 0; i++)
                    208:                        if (pci_clone_list[i].vendor == vendor
                    209:                                && pci_clone_list[i].dev_id == device)
                    210:                                break;
                    211:                if (pci_clone_list[i].vendor == 0)
                    212:                        continue;
                    213: 
                    214: #ifndef MODULE
                    215:                {
                    216:                        static unsigned version_printed = 0;
                    217:                        if (version_printed++ == 0)
                    218:                                printk(KERN_INFO "%s", version);
                    219:                }
                    220: #endif
                    221: 
                    222:                pcibios_read_config_dword(pci_bus, pci_device_fn,
                    223:                                                                  PCI_BASE_ADDRESS_0, &pci_ioaddr);
                    224:                pcibios_read_config_byte(pci_bus, pci_device_fn,
                    225:                                                                 PCI_INTERRUPT_LINE, &pci_irq_line);
                    226:                pcibios_read_config_word(pci_bus, pci_device_fn,
                    227:                                                                 PCI_COMMAND, &pci_command);
                    228: 
                    229:                /* Remove I/O space marker in bit 0. */
                    230:                pci_ioaddr &= PCI_BASE_ADDRESS_IO_MASK;
                    231: 
                    232:                /* Avoid already found cards from previous calls */
                    233:                if (check_region(pci_ioaddr, NE_IO_EXTENT))
                    234:                        continue;
                    235: 
                    236:                /* Activate the card: fix for brain-damaged Win98 BIOSes. */
                    237:                new_command = pci_command | PCI_COMMAND_IO;
                    238:                if (pci_command != new_command) {
                    239:                        printk(KERN_INFO "  The PCI BIOS has not enabled this"
                    240:                                   " NE2k clone!  Updating PCI command %4.4x->%4.4x.\n",
                    241:                                   pci_command, new_command);
                    242:                        pcibios_write_config_word(pci_bus, pci_device_fn,
                    243:                                                                          PCI_COMMAND, new_command);
                    244:                }
                    245: 
                    246:                if (pci_irq_line <= 0 || pci_irq_line >= NR_IRQS)
                    247:                        printk(KERN_WARNING " WARNING: The PCI BIOS assigned this PCI NE2k"
                    248:                                   " card to IRQ %d, which is unlikely to work!.\n"
                    249:                                   KERN_WARNING " You should use the PCI BIOS setup to assign"
                    250:                                   " a valid IRQ line.\n", pci_irq_line);
                    251: 
                    252:                printk("ne2k-pci.c: PCI NE2000 clone '%s' at I/O %#x, IRQ %d.\n",
                    253:                           pci_clone_list[i].name, pci_ioaddr, pci_irq_line);
                    254:                dev = ne2k_pci_probe1(dev, pci_ioaddr, pci_irq_line);
                    255:                if (dev == 0) {
                    256:                        /* Should not happen. */
                    257:                        printk(KERN_ERR "ne2k-pci: Probe of PCI card at %#x failed.\n",
                    258:                                   pci_ioaddr);
                    259:                        continue;
                    260:                } else {
                    261:                        struct ne2k_pci_card *ne2k_card =
                    262:                                kmalloc(sizeof(struct ne2k_pci_card), GFP_KERNEL);
                    263:                        ne2k_card->next = ne2k_card_list;
                    264:                        ne2k_card_list = ne2k_card;
                    265:                        ne2k_card->dev = dev;
                    266:                        ne2k_card->pci_bus = pci_bus;
                    267:                        ne2k_card->pci_device_fn = pci_device_fn;
                    268:                }
                    269:                dev = 0;
                    270: 
                    271:                cards_found++;
                    272:        }
                    273: 
                    274:        return cards_found ? 0 : -ENODEV;
                    275: }
                    276: 
                    277: static struct device *ne2k_pci_probe1(struct device *dev, int ioaddr, int irq)
                    278: {
                    279:        int i;
                    280:        unsigned char SA_prom[32];
                    281:        const char *name = NULL;
                    282:        int start_page, stop_page;
                    283:        int reg0 = inb(ioaddr);
                    284: 
                    285:        if (reg0 == 0xFF)
                    286:                return 0;
                    287: 
                    288:        /* Do a preliminary verification that we have a 8390. */
                    289:        {
                    290:                int regd;
                    291:                outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
                    292:                regd = inb(ioaddr + 0x0d);
                    293:                outb(0xff, ioaddr + 0x0d);
                    294:                outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
                    295:                inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
                    296:                if (inb(ioaddr + EN0_COUNTER0) != 0) {
                    297:                        outb(reg0, ioaddr);
                    298:                        outb(regd, ioaddr + 0x0d);      /* Restore the old values. */
                    299:                        return 0;
                    300:                }
                    301:        }
                    302: 
                    303:        dev = init_etherdev(dev, 0);
                    304: 
                    305:        /* Reset card. Who knows what dain-bramaged state it was left in. */
                    306:        {
                    307:                unsigned long reset_start_time = jiffies;
                    308: 
                    309:                outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
                    310: 
                    311:                /* This looks like a horrible timing loop, but it should never take
                    312:                   more than a few cycles.
                    313:                */
                    314:                while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
                    315:                        /* Limit wait: '2' avoids jiffy roll-over. */
                    316:                        if (jiffies - reset_start_time > 2) {
                    317:                                printk("ne2k-pci: Card failure (no reset ack).\n");
                    318:                                return 0;
                    319:                        }
                    320:                
                    321:                outb(0xff, ioaddr + EN0_ISR);           /* Ack all intr. */
                    322:        }
                    323: 
                    324: #if defined(LOAD_8390_BY_KERNELD)
                    325:        /* We are now certain the 8390 module is required. */
                    326:        if (request_module("8390")) {
                    327:                printk("ne2k-pci: Failed to load the 8390 core module.\n");
                    328:                return 0;
                    329:        }
                    330:        if ((Lethdev_init = (void*)get_module_symbol(0, "ethdev_init")) == 0 ||
                    331:                (LNS8390_init = (void*)get_module_symbol(0, "NS8390_init")) == 0 ||
                    332:                (Lei_open = (void*)get_module_symbol(0, "ei_open")) == 0 ||
                    333:                (Lei_close = (void*)get_module_symbol(0, "ei_close")) == 0 ||
                    334:                (Lei_interrupt = (void*)get_module_symbol(0, "ei_interrupt")) == 0 ) {
                    335:                printk("ne2k-pci: Failed to resolve an 8390 symbol.\n");
                    336:                release_module("8390", 0);
                    337:                return 0;
                    338:        }
                    339: #endif
                    340: 
                    341:        /* Read the 16 bytes of station address PROM.
                    342:           We must first initialize registers, similar to NS8390_init(eifdev, 0).
                    343:           We can't reliably read the SAPROM address without this.
                    344:           (I learned the hard way!). */
                    345:        {
                    346:                struct {unsigned char value, offset; } program_seq[] = {
                    347:                        {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
                    348:                        {0x49,  EN0_DCFG},      /* Set word-wide access. */
                    349:                        {0x00,  EN0_RCNTLO},    /* Clear the count regs. */
                    350:                        {0x00,  EN0_RCNTHI},
                    351:                        {0x00,  EN0_IMR},       /* Mask completion irq. */
                    352:                        {0xFF,  EN0_ISR},
                    353:                        {E8390_RXOFF, EN0_RXCR},        /* 0x20  Set to monitor */
                    354:                        {E8390_TXOFF, EN0_TXCR},        /* 0x02  and loopback mode. */
                    355:                        {32,    EN0_RCNTLO},
                    356:                        {0x00,  EN0_RCNTHI},
                    357:                        {0x00,  EN0_RSARLO},    /* DMA starting at 0x0000. */
                    358:                        {0x00,  EN0_RSARHI},
                    359:                        {E8390_RREAD+E8390_START, E8390_CMD},
                    360:                };
                    361:                for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
                    362:                        outb(program_seq[i].value, ioaddr + program_seq[i].offset);
                    363: 
                    364:        }
                    365: 
                    366: #ifdef notdef
                    367:        /* Some broken PCI cards don't respect the byte-wide
                    368:           request in program_seq above, and hence don't have doubled up values.
                    369:        */
                    370:        for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
                    371:                SA_prom[i] = inb(ioaddr + NE_DATAPORT);
                    372:                SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
                    373:                if (SA_prom[i] != SA_prom[i+1])
                    374:                        sa_prom_doubled = 0;
                    375:        }
                    376: 
                    377:        if (sa_prom_doubled)
                    378:                for (i = 0; i < 16; i++)
                    379:                        SA_prom[i] = SA_prom[i+i];
                    380: #else
                    381:        for(i = 0; i < 32 /*sizeof(SA_prom)*/; i++)
                    382:                SA_prom[i] = inb(ioaddr + NE_DATAPORT);
                    383: 
                    384: #endif
                    385: 
                    386:        /* We always set the 8390 registers for word mode. */
                    387:        outb(0x49, ioaddr + EN0_DCFG);
                    388:        start_page = NESM_START_PG;
                    389:        stop_page = NESM_STOP_PG;
                    390: 
                    391:        /* Set up the rest of the parameters. */
                    392:        name = "PCI NE2000";
                    393: 
                    394:        dev->irq = irq;
                    395:        dev->base_addr = ioaddr;
                    396: 
                    397:        /* Allocate dev->priv and fill in 8390 specific dev fields. */
                    398:        if (Lethdev_init(dev)) {
                    399:                printk ("%s: unable to get memory for dev->priv.\n", dev->name);
                    400:                return 0;
                    401:        }
                    402: 
                    403:        request_region(ioaddr, NE_IO_EXTENT, dev->name);
                    404: 
                    405:        printk("%s: %s found at %#x, IRQ %d, ",
                    406:                   dev->name, name, ioaddr, dev->irq);
                    407:        for(i = 0; i < 6; i++) {
                    408:                printk("%2.2X%s", SA_prom[i], i == 5 ? ".\n": ":");
                    409:                dev->dev_addr[i] = SA_prom[i];
                    410:        }
                    411: 
                    412:        ei_status.name = name;
                    413:        ei_status.tx_start_page = start_page;
                    414:        ei_status.stop_page = stop_page;
                    415:        ei_status.word16 = 1;
                    416: 
                    417:        ei_status.rx_start_page = start_page + TX_PAGES;
                    418: #ifdef PACKETBUF_MEMSIZE
                    419:        /* Allow the packet buffer size to be overridden by know-it-alls. */
                    420:        ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
                    421: #endif
                    422: 
                    423:        ei_status.reset_8390 = &ne_reset_8390;
                    424:        ei_status.block_input = &ne_block_input;
                    425:        ei_status.block_output = &ne_block_output;
                    426:        ei_status.get_8390_hdr = &ne_get_8390_hdr;
                    427:        dev->open = &ne_open;
                    428:        dev->stop = &ne_close;
                    429:        LNS8390_init(dev, 0);
                    430:        return dev;
                    431: }
                    432: 
                    433: static int
                    434: ne_open(struct device *dev)
                    435: {
                    436:        if (request_irq(dev->irq, Lei_interrupt, SA_SHIRQ, dev->name, dev))
                    437:                return -EAGAIN;
                    438:        Lei_open(dev);
                    439:        MOD_INC_USE_COUNT;
                    440:        return 0;
                    441: }
                    442: 
                    443: static int
                    444: ne_close(struct device *dev)
                    445: {
                    446:        Lei_close(dev);
                    447:        free_irq(dev->irq, dev);
                    448:        MOD_DEC_USE_COUNT;
                    449:        return 0;
                    450: }
                    451: 
                    452: /* Hard reset the card.  This used to pause for the same period that a
                    453:    8390 reset command required, but that shouldn't be necessary. */
                    454: static void
                    455: ne_reset_8390(struct device *dev)
                    456: {
                    457:        unsigned long reset_start_time = jiffies;
                    458: 
                    459:        if (debug > 1) printk("%s: Resetting the 8390 t=%ld...",
                    460:                                                  dev->name, jiffies);
                    461: 
                    462:        outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
                    463: 
                    464:        ei_status.txing = 0;
                    465:        ei_status.dmaing = 0;
                    466: 
                    467:        /* This check _should_not_ be necessary, omit eventually. */
                    468:        while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
                    469:                if (jiffies - reset_start_time > 2) {
                    470:                        printk("%s: ne_reset_8390() did not complete.\n", dev->name);
                    471:                        break;
                    472:                }
                    473:        outb(ENISR_RESET, NE_BASE + EN0_ISR);   /* Ack intr. */
                    474: }
                    475: 
                    476: /* Grab the 8390 specific header. Similar to the block_input routine, but
                    477:    we don't need to be concerned with ring wrap as the header will be at
                    478:    the start of a page, so we optimize accordingly. */
                    479: 
                    480: static void
                    481: ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
                    482: {
                    483: 
                    484:        int nic_base = dev->base_addr;
                    485: 
                    486:        /* This *shouldn't* happen. If it does, it's the last thing you'll see */
                    487:        if (ei_status.dmaing) {
                    488:                printk("%s: DMAing conflict in ne_get_8390_hdr "
                    489:                           "[DMAstat:%d][irqlock:%d][intr:%d].\n",
                    490:                           dev->name, ei_status.dmaing, ei_status.irqlock,
                    491:                           dev->interrupt);
                    492:                return;
                    493:        }
                    494: 
                    495:        ei_status.dmaing |= 0x01;
                    496:        outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
                    497:        outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
                    498:        outb(0, nic_base + EN0_RCNTHI);
                    499:        outb(0, nic_base + EN0_RSARLO);         /* On page boundary */
                    500:        outb(ring_page, nic_base + EN0_RSARHI);
                    501:        outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
                    502: 
                    503: #if defined(USE_LONGIO)
                    504:        *(u32*)hdr = inl(NE_BASE + NE_DATAPORT);
                    505: #else
                    506:        insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
                    507: #endif
                    508: 
                    509:        outb(ENISR_RDC, nic_base + EN0_ISR);    /* Ack intr. */
                    510:        ei_status.dmaing &= ~0x01;
                    511: }
                    512: 
                    513: /* Block input and output, similar to the Crynwr packet driver.  If you
                    514:    are porting to a new ethercard, look at the packet driver source for hints.
                    515:    The NEx000 doesn't share the on-board packet memory -- you have to put
                    516:    the packet out through the "remote DMA" dataport using outb. */
                    517: 
                    518: static void
                    519: ne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
                    520: {
                    521:        int nic_base = dev->base_addr;
                    522:        char *buf = skb->data;
                    523: 
                    524:        /* This *shouldn't* happen. If it does, it's the last thing you'll see */
                    525:        if (ei_status.dmaing) {
                    526:                printk("%s: DMAing conflict in ne_block_input "
                    527:                           "[DMAstat:%d][irqlock:%d][intr:%d].\n",
                    528:                           dev->name, ei_status.dmaing, ei_status.irqlock,
                    529:                           dev->interrupt);
                    530:                return;
                    531:        }
                    532:        ei_status.dmaing |= 0x01;
                    533:        outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
                    534:        outb(count & 0xff, nic_base + EN0_RCNTLO);
                    535:        outb(count >> 8, nic_base + EN0_RCNTHI);
                    536:        outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
                    537:        outb(ring_offset >> 8, nic_base + EN0_RSARHI);
                    538:        outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
                    539: 
                    540: #if defined(USE_LONGIO)
                    541:        insl(NE_BASE + NE_DATAPORT, buf, count>>2);
                    542:        if (count & 3) {
                    543:                buf += count & ~3;
                    544:                if (count & 2)
                    545:                        *((u16*)buf)++ = inw(NE_BASE + NE_DATAPORT);
                    546:                if (count & 1)
                    547:                        *buf = inb(NE_BASE + NE_DATAPORT);
                    548:        }
                    549: #else
                    550:        insw(NE_BASE + NE_DATAPORT,buf,count>>1);
                    551:        if (count & 0x01) {
                    552:                buf[count-1] = inb(NE_BASE + NE_DATAPORT);
                    553:        }
                    554: #endif
                    555: 
                    556:        outb(ENISR_RDC, nic_base + EN0_ISR);    /* Ack intr. */
                    557:        ei_status.dmaing &= ~0x01;
                    558: }
                    559: 
                    560: static void
                    561: ne_block_output(struct device *dev, int count,
                    562:                const unsigned char *buf, const int start_page)
                    563: {
                    564:        int nic_base = NE_BASE;
                    565:        unsigned long dma_start;
                    566: 
                    567:        /* On little-endian it's always safe to round the count up for
                    568:           word writes. */
                    569:        if (count & 0x01)
                    570:                count++;
                    571: 
                    572:        /* This *shouldn't* happen. If it does, it's the last thing you'll see */
                    573:        if (ei_status.dmaing) {
                    574:                printk("%s: DMAing conflict in ne_block_output."
                    575:                           "[DMAstat:%d][irqlock:%d][intr:%d]\n",
                    576:                           dev->name, ei_status.dmaing, ei_status.irqlock,
                    577:                           dev->interrupt);
                    578:                return;
                    579:        }
                    580:        ei_status.dmaing |= 0x01;
                    581:        /* We should already be in page 0, but to be safe... */
                    582:        outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
                    583: 
                    584: #ifdef NE8390_RW_BUGFIX
                    585:        /* Handle the read-before-write bug the same way as the
                    586:           Crynwr packet driver -- the NatSemi method doesn't work.
                    587:           Actually this doesn't always work either, but if you have
                    588:           problems with your NEx000 this is better than nothing! */
                    589:        outb(0x42, nic_base + EN0_RCNTLO);
                    590:        outb(0x00, nic_base + EN0_RCNTHI);
                    591:        outb(0x42, nic_base + EN0_RSARLO);
                    592:        outb(0x00, nic_base + EN0_RSARHI);
                    593:        outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
                    594: #endif
                    595:        outb(ENISR_RDC, nic_base + EN0_ISR);
                    596: 
                    597:    /* Now the normal output. */
                    598:        outb(count & 0xff, nic_base + EN0_RCNTLO);
                    599:        outb(count >> 8,   nic_base + EN0_RCNTHI);
                    600:        outb(0x00, nic_base + EN0_RSARLO);
                    601:        outb(start_page, nic_base + EN0_RSARHI);
                    602:        outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
                    603: #if defined(USE_LONGIO)
                    604:        outsl(NE_BASE + NE_DATAPORT, buf, count>>2);
                    605:        if (count & 3) {
                    606:                buf += count & ~3;
                    607:                if (count & 2)
                    608:                        outw(*((u16*)buf)++, NE_BASE + NE_DATAPORT);
                    609:        }
                    610: #else
                    611:        outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
                    612: #endif
                    613: 
                    614:        dma_start = jiffies;
                    615: 
                    616:        while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0)
                    617:                if (jiffies - dma_start > 2) {                  /* Avoid clock roll-over. */
                    618:                        printk("%s: timeout waiting for Tx RDC.\n", dev->name);
                    619:                        ne_reset_8390(dev);
                    620:                        LNS8390_init(dev,1);
                    621:                        break;
                    622:                }
                    623: 
                    624:        outb(ENISR_RDC, nic_base + EN0_ISR);    /* Ack intr. */
                    625:        ei_status.dmaing &= ~0x01;
                    626:        return;
                    627: }
                    628: 
                    629: 
                    630: /*
                    631:  * Local variables:
                    632:  *  compile-command: "gcc -DMODVERSIONS  -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/ -c ne2k-pci.c"
                    633:  *  alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/ -c ne2k-pci.c"
                    634:  *  c-indent-level: 4
                    635:  *  c-basic-offset: 4
                    636:  *  tab-width: 4
                    637:  *  version-control: t
                    638:  *  kept-new-versions: 5
                    639:  * End:
                    640:  */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.