Annotation of Gnu-Mach/linux/pcmcia-cs/clients/axnet_cs.c, revision 1.1

1.1     ! root        1: /*======================================================================
        !             2: 
        !             3:     A PCMCIA ethernet driver for Asix AX88190-based cards
        !             4: 
        !             5:     The Asix AX88190 is a NS8390-derived chipset with a few nasty
        !             6:     idiosyncracies that make it very inconvenient to support with a
        !             7:     standard 8390 driver.  This driver is based on pcnet_cs, with the
        !             8:     tweaked 8390 code grafted on the end.  Much of what I did was to
        !             9:     clean up and update a similar driver supplied by Asix, which was
        !            10:     adapted by William Lee, [email protected].
        !            11: 
        !            12:     Copyright (C) 2001 David A. Hinds -- [email protected]
        !            13: 
        !            14:     axnet_cs.c 1.31 2003/08/25 15:57:40
        !            15: 
        !            16:     The network driver code is based on Donald Becker's NE2000 code:
        !            17: 
        !            18:     Written 1992,1993 by Donald Becker.
        !            19:     Copyright 1993 United States Government as represented by the
        !            20:     Director, National Security Agency.  This software may be used and
        !            21:     distributed according to the terms of the GNU General Public License,
        !            22:     incorporated herein by reference.
        !            23:     Donald Becker may be reached at [email protected]
        !            24: 
        !            25: ======================================================================*/
        !            26: 
        !            27: #include <linux/kernel.h>
        !            28: #include <linux/module.h>
        !            29: #include <linux/init.h>
        !            30: #include <linux/sched.h>
        !            31: #include <linux/ptrace.h>
        !            32: #include <linux/slab.h>
        !            33: #include <linux/string.h>
        !            34: #include <linux/timer.h>
        !            35: #include <linux/delay.h>
        !            36: #include <linux/spinlock.h>
        !            37: #include <asm/io.h>
        !            38: #include <asm/system.h>
        !            39: #include <asm/byteorder.h>
        !            40: #include <asm/uaccess.h>
        !            41: 
        !            42: #include <linux/netdevice.h>
        !            43: #include "ax8390.h"
        !            44: 
        !            45: #include <pcmcia/version.h>
        !            46: #include <pcmcia/cs_types.h>
        !            47: #include <pcmcia/cs.h>
        !            48: #include <pcmcia/cistpl.h>
        !            49: #include <pcmcia/ciscode.h>
        !            50: #include <pcmcia/ds.h>
        !            51: #include <pcmcia/cisreg.h>
        !            52: 
        !            53: #define AXNET_CMD      0x00
        !            54: #define AXNET_DATAPORT 0x10    /* NatSemi-defined port window offset. */
        !            55: #define AXNET_RESET    0x1f    /* Issue a read to reset, a write to clear. */
        !            56: #define AXNET_MII_EEP  0x14    /* Offset of MII access port */
        !            57: #define AXNET_TEST     0x15    /* Offset of TEST Register port */
        !            58: #define AXNET_GPIO     0x17    /* Offset of General Purpose Register Port */
        !            59: 
        !            60: #define AXNET_START_PG 0x40    /* First page of TX buffer */
        !            61: #define AXNET_STOP_PG  0x80    /* Last page +1 of RX ring */
        !            62: 
        !            63: #define AXNET_RDC_TIMEOUT 0x02 /* Max wait in jiffies for Tx RDC */
        !            64: 
        !            65: #define IS_AX88190     0x0001
        !            66: #define IS_AX88790     0x0002
        !            67: 
        !            68: /*====================================================================*/
        !            69: 
        !            70: /* Module parameters */
        !            71: 
        !            72: MODULE_AUTHOR("David Hinds <[email protected]>");
        !            73: MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver");
        !            74: MODULE_LICENSE("GPL");
        !            75: 
        !            76: #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
        !            77: 
        !            78: /* Bit map of interrupts to choose from */
        !            79: INT_MODULE_PARM(irq_mask,      0xdeb8);
        !            80: static int irq_list[4] = { -1 };
        !            81: MODULE_PARM(irq_list, "1-4i");
        !            82: 
        !            83: #ifdef PCMCIA_DEBUG
        !            84: INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
        !            85: #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
        !            86: static char *version =
        !            87: "axnet_cs.c 1.31 2003/08/25 15:57:40 (David Hinds)";
        !            88: #else
        !            89: #define DEBUG(n, args...)
        !            90: #endif
        !            91: 
        !            92: /*====================================================================*/
        !            93: 
        !            94: static void axnet_config(dev_link_t *link);
        !            95: static void axnet_release(u_long arg);
        !            96: static int axnet_event(event_t event, int priority,
        !            97:                       event_callback_args_t *args);
        !            98: static int axnet_open(struct net_device *dev);
        !            99: static int axnet_close(struct net_device *dev);
        !           100: static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
        !           101: static void ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs);
        !           102: static void ei_watchdog(u_long arg);
        !           103: static void axnet_reset_8390(struct net_device *dev);
        !           104: 
        !           105: static int mdio_read(ioaddr_t addr, int phy_id, int loc);
        !           106: static void mdio_write(ioaddr_t addr, int phy_id, int loc, int value);
        !           107: 
        !           108: static void get_8390_hdr(struct net_device *,
        !           109:                         struct e8390_pkt_hdr *, int);
        !           110: static void block_input(struct net_device *dev, int count,
        !           111:                        struct sk_buff *skb, int ring_offset);
        !           112: static void block_output(struct net_device *dev, int count,
        !           113:                         const u_char *buf, const int start_page);
        !           114: 
        !           115: static dev_link_t *axnet_attach(void);
        !           116: static void axnet_detach(dev_link_t *);
        !           117: 
        !           118: static dev_info_t dev_info = "axnet_cs";
        !           119: static dev_link_t *dev_list;
        !           120: 
        !           121: static int axdev_init(struct net_device *dev);
        !           122: static void AX88190_init(struct net_device *dev, int startp);
        !           123: static int ax_open(struct net_device *dev);
        !           124: static int ax_close(struct net_device *dev);
        !           125: static void ax_interrupt(int irq, void *dev_id, struct pt_regs *regs);
        !           126: 
        !           127: /*====================================================================*/
        !           128: 
        !           129: typedef struct axnet_dev_t {
        !           130:     struct net_device  dev;    /* so &dev == &axnet_dev_t */
        !           131:     dev_link_t         link;
        !           132:     dev_node_t         node;
        !           133:     caddr_t            base;
        !           134:     struct timer_list  watchdog;
        !           135:     int                        stale, fast_poll;
        !           136:     u_short            link_status;
        !           137:     u_char             duplex_flag;
        !           138:     int                        phy_id;
        !           139:     int                        flags;
        !           140: } axnet_dev_t;
        !           141: 
        !           142: /*======================================================================
        !           143: 
        !           144:     This bit of code is used to avoid unregistering network devices
        !           145:     at inappropriate times.  2.2 and later kernels are fairly picky
        !           146:     about when this can happen.
        !           147:     
        !           148: ======================================================================*/
        !           149: 
        !           150: static void flush_stale_links(void)
        !           151: {
        !           152:     dev_link_t *link, *next;
        !           153:     for (link = dev_list; link; link = next) {
        !           154:        next = link->next;
        !           155:        if (link->state & DEV_STALE_LINK)
        !           156:            axnet_detach(link);
        !           157:     }
        !           158: }
        !           159: 
        !           160: /*====================================================================*/
        !           161: 
        !           162: static void cs_error(client_handle_t handle, int func, int ret)
        !           163: {
        !           164:     error_info_t err = { func, ret };
        !           165:     CardServices(ReportError, handle, &err);
        !           166: }
        !           167: 
        !           168: /*======================================================================
        !           169: 
        !           170:     We never need to do anything when a axnet device is "initialized"
        !           171:     by the net software, because we only register already-found cards.
        !           172: 
        !           173: ======================================================================*/
        !           174: 
        !           175: static int axnet_init(struct net_device *dev)
        !           176: {
        !           177:     return 0;
        !           178: }
        !           179: 
        !           180: /*======================================================================
        !           181: 
        !           182:     axnet_attach() creates an "instance" of the driver, allocating
        !           183:     local data structures for one device.  The device is registered
        !           184:     with Card Services.
        !           185: 
        !           186: ======================================================================*/
        !           187: 
        !           188: static dev_link_t *axnet_attach(void)
        !           189: {
        !           190:     axnet_dev_t *info;
        !           191:     dev_link_t *link;
        !           192:     struct net_device *dev;
        !           193:     client_reg_t client_reg;
        !           194:     int i, ret;
        !           195: 
        !           196:     DEBUG(0, "axnet_attach()\n");
        !           197:     flush_stale_links();
        !           198: 
        !           199:     /* Create new ethernet device */
        !           200:     info = kmalloc(sizeof(*info), GFP_KERNEL);
        !           201:     if (!info) return NULL;
        !           202:     memset(info, 0, sizeof(*info));
        !           203:     link = &info->link; dev = &info->dev;
        !           204:     link->priv = info;
        !           205: 
        !           206:     init_timer(&link->release);
        !           207:     link->release.function = &axnet_release;
        !           208:     link->release.data = (u_long)link;
        !           209:     link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
        !           210:     link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
        !           211:     if (irq_list[0] == -1)
        !           212:        link->irq.IRQInfo2 = irq_mask;
        !           213:     else
        !           214:        for (i = 0; i < 4; i++)
        !           215:            link->irq.IRQInfo2 |= 1 << irq_list[i];
        !           216:     link->conf.Attributes = CONF_ENABLE_IRQ;
        !           217:     link->conf.IntType = INT_MEMORY_AND_IO;
        !           218: 
        !           219:     axdev_init(dev);
        !           220:     init_dev_name(dev, info->node);
        !           221:     dev->init = &axnet_init;
        !           222:     dev->open = &axnet_open;
        !           223:     dev->stop = &axnet_close;
        !           224:     dev->do_ioctl = &axnet_ioctl;
        !           225: 
        !           226:     /* Register with Card Services */
        !           227:     link->next = dev_list;
        !           228:     dev_list = link;
        !           229:     client_reg.dev_info = &dev_info;
        !           230:     client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
        !           231:     client_reg.EventMask =
        !           232:        CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
        !           233:        CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
        !           234:        CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
        !           235:     client_reg.event_handler = &axnet_event;
        !           236:     client_reg.Version = 0x0210;
        !           237:     client_reg.event_callback_args.client_data = link;
        !           238:     ret = CardServices(RegisterClient, &link->handle, &client_reg);
        !           239:     if (ret != CS_SUCCESS) {
        !           240:        cs_error(link->handle, RegisterClient, ret);
        !           241:        axnet_detach(link);
        !           242:        return NULL;
        !           243:     }
        !           244: 
        !           245:     return link;
        !           246: } /* axnet_attach */
        !           247: 
        !           248: /*======================================================================
        !           249: 
        !           250:     This deletes a driver "instance".  The device is de-registered
        !           251:     with Card Services.  If it has been released, all local data
        !           252:     structures are freed.  Otherwise, the structures will be freed
        !           253:     when the device is released.
        !           254: 
        !           255: ======================================================================*/
        !           256: 
        !           257: static void axnet_detach(dev_link_t *link)
        !           258: {
        !           259:     axnet_dev_t *info = link->priv;
        !           260:     dev_link_t **linkp;
        !           261: 
        !           262:     DEBUG(0, "axnet_detach(0x%p)\n", link);
        !           263: 
        !           264:     /* Locate device structure */
        !           265:     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
        !           266:        if (*linkp == link) break;
        !           267:     if (*linkp == NULL)
        !           268:        return;
        !           269: 
        !           270:     del_timer(&link->release);
        !           271:     if (link->state & DEV_CONFIG) {
        !           272:        axnet_release((u_long)link);
        !           273:        if (link->state & DEV_STALE_CONFIG) {
        !           274:            link->state |= DEV_STALE_LINK;
        !           275:            return;
        !           276:        }
        !           277:     }
        !           278: 
        !           279:     if (link->handle)
        !           280:        CardServices(DeregisterClient, link->handle);
        !           281: 
        !           282:     /* Unlink device structure, free bits */
        !           283:     *linkp = link->next;
        !           284:     if (link->dev)
        !           285:        unregister_netdev(&info->dev);
        !           286:     kfree(info);
        !           287: 
        !           288: } /* axnet_detach */
        !           289: 
        !           290: /*======================================================================
        !           291: 
        !           292:     This probes for a card's hardware address by reading the PROM.
        !           293: 
        !           294: ======================================================================*/
        !           295: 
        !           296: static int get_prom(dev_link_t *link)
        !           297: {
        !           298:     struct net_device *dev = link->priv;
        !           299:     ioaddr_t ioaddr = dev->base_addr;
        !           300:     int i, j;
        !           301: 
        !           302:     /* This is based on drivers/net/ne.c */
        !           303:     struct {
        !           304:        u_char value, offset;
        !           305:     } program_seq[] = {
        !           306:        {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
        !           307:        {0x01,  EN0_DCFG},      /* Set word-wide access. */
        !           308:        {0x00,  EN0_RCNTLO},    /* Clear the count regs. */
        !           309:        {0x00,  EN0_RCNTHI},
        !           310:        {0x00,  EN0_IMR},       /* Mask completion irq. */
        !           311:        {0xFF,  EN0_ISR},
        !           312:        {E8390_RXOFF|0x40, EN0_RXCR},   /* 0x60  Set to monitor */
        !           313:        {E8390_TXOFF, EN0_TXCR},        /* 0x02  and loopback mode. */
        !           314:        {0x10,  EN0_RCNTLO},
        !           315:        {0x00,  EN0_RCNTHI},
        !           316:        {0x00,  EN0_RSARLO},    /* DMA starting at 0x0400. */
        !           317:        {0x04,  EN0_RSARHI},
        !           318:        {E8390_RREAD+E8390_START, E8390_CMD},
        !           319:     };
        !           320: 
        !           321:     /* Not much of a test, but the alternatives are messy */
        !           322:     if (link->conf.ConfigBase != 0x03c0)
        !           323:        return 0;
        !           324: 
        !           325:     axnet_reset_8390(dev);
        !           326:     mdelay(10);
        !           327: 
        !           328:     for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
        !           329:        outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
        !           330: 
        !           331:     for (i = 0; i < 6; i += 2) {
        !           332:        j = inw(ioaddr + AXNET_DATAPORT);
        !           333:        dev->dev_addr[i] = j & 0xff;
        !           334:        dev->dev_addr[i+1] = j >> 8;
        !           335:     }
        !           336:     return 1;
        !           337: } /* get_prom */
        !           338: 
        !           339: /*======================================================================
        !           340: 
        !           341:     axnet_config() is scheduled to run after a CARD_INSERTION event
        !           342:     is received, to configure the PCMCIA socket, and to make the
        !           343:     ethernet device available to the system.
        !           344: 
        !           345: ======================================================================*/
        !           346: 
        !           347: #define CS_CHECK(fn, args...) \
        !           348: while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
        !           349: 
        !           350: #define CFG_CHECK(fn, args...) \
        !           351: if (CardServices(fn, args) != 0) goto next_entry
        !           352: 
        !           353: static int try_io_port(dev_link_t *link)
        !           354: {
        !           355:     int j, ret;
        !           356:     if (link->io.NumPorts1 == 32) {
        !           357:        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        !           358:        if (link->io.NumPorts2 > 0) {
        !           359:            /* for master/slave multifunction cards */
        !           360:            link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
        !           361:            link->irq.Attributes = 
        !           362:                IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
        !           363:        }
        !           364:     } else {
        !           365:        /* This should be two 16-port windows */
        !           366:        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        !           367:        link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
        !           368:     }
        !           369:     if (link->io.BasePort1 == 0) {
        !           370:        link->io.IOAddrLines = 16;
        !           371:        for (j = 0; j < 0x400; j += 0x20) {
        !           372:            link->io.BasePort1 = j ^ 0x300;
        !           373:            link->io.BasePort2 = (j ^ 0x300) + 0x10;
        !           374:            ret = CardServices(RequestIO, link->handle, &link->io);
        !           375:            if (ret == CS_SUCCESS) return ret;
        !           376:        }
        !           377:        return ret;
        !           378:     } else {
        !           379:        return CardServices(RequestIO, link->handle, &link->io);
        !           380:     }
        !           381: }
        !           382: 
        !           383: static void axnet_config(dev_link_t *link)
        !           384: {
        !           385:     client_handle_t handle = link->handle;
        !           386:     axnet_dev_t *info = link->priv;
        !           387:     struct net_device *dev = &info->dev;
        !           388:     tuple_t tuple;
        !           389:     cisparse_t parse;
        !           390:     int i, j, last_ret, last_fn;
        !           391:     u_short buf[64];
        !           392:     config_info_t conf;
        !           393: 
        !           394:     DEBUG(0, "axnet_config(0x%p)\n", link);
        !           395: 
        !           396:     tuple.Attributes = 0;
        !           397:     tuple.TupleData = (cisdata_t *)buf;
        !           398:     tuple.TupleDataMax = sizeof(buf);
        !           399:     tuple.TupleOffset = 0;
        !           400:     tuple.DesiredTuple = CISTPL_CONFIG;
        !           401:     CS_CHECK(GetFirstTuple, handle, &tuple);
        !           402:     CS_CHECK(GetTupleData, handle, &tuple);
        !           403:     CS_CHECK(ParseTuple, handle, &tuple, &parse);
        !           404:     link->conf.ConfigBase = parse.config.base;
        !           405:     /* don't trust the CIS on this; Linksys got it wrong */
        !           406:     link->conf.Present = 0x63;
        !           407: 
        !           408:     /* Configure card */
        !           409:     link->state |= DEV_CONFIG;
        !           410: 
        !           411:     /* Look up current Vcc */
        !           412:     CS_CHECK(GetConfigurationInfo, handle, &conf);
        !           413:     link->conf.Vcc = conf.Vcc;
        !           414: 
        !           415:     tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
        !           416:     tuple.Attributes = 0;
        !           417:     CS_CHECK(GetFirstTuple, handle, &tuple);
        !           418:     while (last_ret == CS_SUCCESS) {
        !           419:        cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
        !           420:        cistpl_io_t *io = &(parse.cftable_entry.io);
        !           421:        
        !           422:        CFG_CHECK(GetTupleData, handle, &tuple);
        !           423:        CFG_CHECK(ParseTuple, handle, &tuple, &parse);
        !           424:        if ((cfg->index == 0) || (cfg->io.nwin == 0))
        !           425:            goto next_entry;
        !           426:        
        !           427:        link->conf.ConfigIndex = 0x05;
        !           428:        /* For multifunction cards, by convention, we configure the
        !           429:           network function with window 0, and serial with window 1 */
        !           430:        if (io->nwin > 1) {
        !           431:            i = (io->win[1].len > io->win[0].len);
        !           432:            link->io.BasePort2 = io->win[1-i].base;
        !           433:            link->io.NumPorts2 = io->win[1-i].len;
        !           434:        } else {
        !           435:            i = link->io.NumPorts2 = 0;
        !           436:        }
        !           437:        link->io.BasePort1 = io->win[i].base;
        !           438:        link->io.NumPorts1 = io->win[i].len;
        !           439:        link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
        !           440:        if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
        !           441:            last_ret = try_io_port(link);
        !           442:            if (last_ret == CS_SUCCESS) break;
        !           443:        }
        !           444:     next_entry:
        !           445:        last_ret = CardServices(GetNextTuple, handle, &tuple);
        !           446:     }
        !           447:     if (last_ret != CS_SUCCESS) {
        !           448:        cs_error(handle, RequestIO, last_ret);
        !           449:        goto failed;
        !           450:     }
        !           451: 
        !           452:     CS_CHECK(RequestIRQ, handle, &link->irq);
        !           453:     
        !           454:     if (link->io.NumPorts2 == 8) {
        !           455:        link->conf.Attributes |= CONF_ENABLE_SPKR;
        !           456:        link->conf.Status = CCSR_AUDIO_ENA;
        !           457:     }
        !           458:     
        !           459:     CS_CHECK(RequestConfiguration, handle, &link->conf);
        !           460:     dev->irq = link->irq.AssignedIRQ;
        !           461:     dev->base_addr = link->io.BasePort1;
        !           462:     if (register_netdev(dev) != 0) {
        !           463:        printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
        !           464:        goto failed;
        !           465:     }
        !           466: 
        !           467:     if (!get_prom(link)) {
        !           468:        printk(KERN_NOTICE "axnet_cs: this is not an AX88190 card!\n");
        !           469:        printk(KERN_NOTICE "axnet_cs: use pcnet_cs instead.\n");
        !           470:        unregister_netdev(dev);
        !           471:        goto failed;
        !           472:     }
        !           473: 
        !           474:     ei_status.name = "AX88190";
        !           475:     ei_status.word16 = 1;
        !           476:     ei_status.tx_start_page = AXNET_START_PG;
        !           477:     ei_status.rx_start_page = AXNET_START_PG + TX_PAGES;
        !           478:     ei_status.stop_page = AXNET_STOP_PG;
        !           479:     ei_status.reset_8390 = &axnet_reset_8390;
        !           480:     ei_status.get_8390_hdr = &get_8390_hdr;
        !           481:     ei_status.block_input = &block_input;
        !           482:     ei_status.block_output = &block_output;
        !           483: 
        !           484:     copy_dev_name(info->node, dev);
        !           485:     link->dev = &info->node;
        !           486: 
        !           487:     if (inb(dev->base_addr + AXNET_TEST) != 0)
        !           488:        info->flags |= IS_AX88790;
        !           489:     else
        !           490:        info->flags |= IS_AX88190;
        !           491: 
        !           492:     printk(KERN_INFO "%s: Asix AX88%d90: io %#3lx, irq %d, hw_addr ",
        !           493:           dev->name, ((info->flags & IS_AX88790) ? 7 : 1),
        !           494:           dev->base_addr, dev->irq);
        !           495:     for (i = 0; i < 6; i++)
        !           496:        printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
        !           497: 
        !           498:     if (info->flags & IS_AX88790)
        !           499:        outb(0x10, dev->base_addr + AXNET_GPIO);  /* select Internal PHY */
        !           500: 
        !           501:     for (i = 0; i < 32; i++) {
        !           502:        j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
        !           503:        if ((j != 0) && (j != 0xffff)) break;
        !           504:     }
        !           505: 
        !           506: 
        !           507:     /* Maybe PHY is in power down mode. (PPD_SET = 1) 
        !           508:        Bit 2 of CCSR is active low. */ 
        !           509:     if (i == 32) {
        !           510:        conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 };
        !           511:        CardServices(AccessConfigurationRegister, link->handle, &reg);
        !           512:        for (i = 0; i < 32; i++) {
        !           513:            j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
        !           514:            if ((j != 0) && (j != 0xffff)) break;
        !           515:        }
        !           516:     }
        !           517: 
        !           518:     info->phy_id = (i < 32) ? i : -1;
        !           519:     if (i < 32) {
        !           520:        DEBUG(0, "  MII transceiver at index %d, status %x.\n", i, j);
        !           521:     } else {
        !           522:        printk(KERN_NOTICE "  No MII transceivers found!\n");
        !           523:     }
        !           524: 
        !           525:     link->state &= ~DEV_CONFIG_PENDING;
        !           526:     return;
        !           527: 
        !           528: cs_failed:
        !           529:     cs_error(link->handle, last_fn, last_ret);
        !           530: failed:
        !           531:     axnet_release((u_long)link);
        !           532:     link->state &= ~DEV_CONFIG_PENDING;
        !           533:     return;
        !           534: } /* axnet_config */
        !           535: 
        !           536: /*======================================================================
        !           537: 
        !           538:     After a card is removed, axnet_release() will unregister the net
        !           539:     device, and release the PCMCIA configuration.  If the device is
        !           540:     still open, this will be postponed until it is closed.
        !           541: 
        !           542: ======================================================================*/
        !           543: 
        !           544: static void axnet_release(u_long arg)
        !           545: {
        !           546:     dev_link_t *link = (dev_link_t *)arg;
        !           547: 
        !           548:     DEBUG(0, "axnet_release(0x%p)\n", link);
        !           549: 
        !           550:     if (link->open) {
        !           551:        DEBUG(1, "axnet_cs: release postponed, '%s' still open\n",
        !           552:              ((axnet_dev_t *)(link->priv))->node.dev_name);
        !           553:        link->state |= DEV_STALE_CONFIG;
        !           554:        return;
        !           555:     }
        !           556: 
        !           557:     CardServices(ReleaseConfiguration, link->handle);
        !           558:     CardServices(ReleaseIO, link->handle, &link->io);
        !           559:     CardServices(ReleaseIRQ, link->handle, &link->irq);
        !           560: 
        !           561:     link->state &= ~DEV_CONFIG;
        !           562: 
        !           563: } /* axnet_release */
        !           564: 
        !           565: /*======================================================================
        !           566: 
        !           567:     The card status event handler.  Mostly, this schedules other
        !           568:     stuff to run after an event is received.  A CARD_REMOVAL event
        !           569:     also sets some flags to discourage the net drivers from trying
        !           570:     to talk to the card any more.
        !           571: 
        !           572: ======================================================================*/
        !           573: 
        !           574: static int axnet_event(event_t event, int priority,
        !           575:                       event_callback_args_t *args)
        !           576: {
        !           577:     dev_link_t *link = args->client_data;
        !           578:     axnet_dev_t *info = link->priv;
        !           579: 
        !           580:     DEBUG(2, "axnet_event(0x%06x)\n", event);
        !           581: 
        !           582:     switch (event) {
        !           583:     case CS_EVENT_CARD_REMOVAL:
        !           584:        link->state &= ~DEV_PRESENT;
        !           585:        if (link->state & DEV_CONFIG) {
        !           586:            netif_device_detach(&info->dev);
        !           587:            mod_timer(&link->release, jiffies + HZ/20);
        !           588:        }
        !           589:        break;
        !           590:     case CS_EVENT_CARD_INSERTION:
        !           591:        link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
        !           592:        axnet_config(link);
        !           593:        break;
        !           594:     case CS_EVENT_PM_SUSPEND:
        !           595:        link->state |= DEV_SUSPEND;
        !           596:        /* Fall through... */
        !           597:     case CS_EVENT_RESET_PHYSICAL:
        !           598:        if (link->state & DEV_CONFIG) {
        !           599:            if (link->open)
        !           600:                netif_device_detach(&info->dev);
        !           601:            CardServices(ReleaseConfiguration, link->handle);
        !           602:        }
        !           603:        break;
        !           604:     case CS_EVENT_PM_RESUME:
        !           605:        link->state &= ~DEV_SUSPEND;
        !           606:        /* Fall through... */
        !           607:     case CS_EVENT_CARD_RESET:
        !           608:        if (link->state & DEV_CONFIG) {
        !           609:            CardServices(RequestConfiguration, link->handle, &link->conf);
        !           610:            if (link->open) {
        !           611:                axnet_reset_8390(&info->dev);
        !           612:                AX88190_init(&info->dev, 1);
        !           613:                netif_device_attach(&info->dev);
        !           614:            }
        !           615:        }
        !           616:        break;
        !           617:     }
        !           618:     return 0;
        !           619: } /* axnet_event */
        !           620: 
        !           621: /*======================================================================
        !           622: 
        !           623:     MII interface support
        !           624: 
        !           625: ======================================================================*/
        !           626: 
        !           627: #define MDIO_SHIFT_CLK         0x01
        !           628: #define MDIO_DATA_WRITE0       0x00
        !           629: #define MDIO_DATA_WRITE1       0x08
        !           630: #define MDIO_DATA_READ         0x04
        !           631: #define MDIO_MASK              0x0f
        !           632: #define MDIO_ENB_IN            0x02
        !           633: 
        !           634: static void mdio_sync(ioaddr_t addr)
        !           635: {
        !           636:     int bits;
        !           637:     for (bits = 0; bits < 32; bits++) {
        !           638:        outb_p(MDIO_DATA_WRITE1, addr);
        !           639:        outb_p(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
        !           640:     }
        !           641: }
        !           642: 
        !           643: static int mdio_read(ioaddr_t addr, int phy_id, int loc)
        !           644: {
        !           645:     u_int cmd = (0xf6<<10)|(phy_id<<5)|loc;
        !           646:     int i, retval = 0;
        !           647: 
        !           648:     mdio_sync(addr);
        !           649:     for (i = 14; i >= 0; i--) {
        !           650:        int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
        !           651:        outb_p(dat, addr);
        !           652:        outb_p(dat | MDIO_SHIFT_CLK, addr);
        !           653:     }
        !           654:     for (i = 19; i > 0; i--) {
        !           655:        outb_p(MDIO_ENB_IN, addr);
        !           656:        retval = (retval << 1) | ((inb_p(addr) & MDIO_DATA_READ) != 0);
        !           657:        outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
        !           658:     }
        !           659:     return (retval>>1) & 0xffff;
        !           660: }
        !           661: 
        !           662: static void mdio_write(ioaddr_t addr, int phy_id, int loc, int value)
        !           663: {
        !           664:     u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
        !           665:     int i;
        !           666: 
        !           667:     mdio_sync(addr);
        !           668:     for (i = 31; i >= 0; i--) {
        !           669:        int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
        !           670:        outb_p(dat, addr);
        !           671:        outb_p(dat | MDIO_SHIFT_CLK, addr);
        !           672:     }
        !           673:     for (i = 1; i >= 0; i--) {
        !           674:        outb_p(MDIO_ENB_IN, addr);
        !           675:        outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
        !           676:     }
        !           677: }
        !           678: 
        !           679: /*====================================================================*/
        !           680: 
        !           681: static int axnet_open(struct net_device *dev)
        !           682: {
        !           683:     axnet_dev_t *info = (axnet_dev_t *)dev;
        !           684:     dev_link_t *link = &info->link;
        !           685:     
        !           686:     DEBUG(2, "axnet_open('%s')\n", dev->name);
        !           687: 
        !           688:     if (!DEV_OK(link))
        !           689:        return -ENODEV;
        !           690: 
        !           691:     link->open++;
        !           692:     MOD_INC_USE_COUNT;
        !           693: 
        !           694:     request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
        !           695: 
        !           696:     info->link_status = 0x00;
        !           697:     info->watchdog.function = &ei_watchdog;
        !           698:     info->watchdog.data = (u_long)info;
        !           699:     info->watchdog.expires = jiffies + HZ;
        !           700:     add_timer(&info->watchdog);
        !           701: 
        !           702:     return ax_open(dev);
        !           703: } /* axnet_open */
        !           704: 
        !           705: /*====================================================================*/
        !           706: 
        !           707: static int axnet_close(struct net_device *dev)
        !           708: {
        !           709:     axnet_dev_t *info = (axnet_dev_t *)dev;
        !           710:     dev_link_t *link = &info->link;
        !           711: 
        !           712:     DEBUG(2, "axnet_close('%s')\n", dev->name);
        !           713: 
        !           714:     ax_close(dev);
        !           715:     free_irq(dev->irq, dev);
        !           716:     
        !           717:     link->open--;
        !           718:     netif_stop_queue(dev);
        !           719:     netif_mark_down(dev);
        !           720:     del_timer(&info->watchdog);
        !           721:     if (link->state & DEV_STALE_CONFIG)
        !           722:        mod_timer(&link->release, jiffies + HZ/20);
        !           723: 
        !           724:     MOD_DEC_USE_COUNT;
        !           725: 
        !           726:     return 0;
        !           727: } /* axnet_close */
        !           728: 
        !           729: /*======================================================================
        !           730: 
        !           731:     Hard reset the card.  This used to pause for the same period that
        !           732:     a 8390 reset command required, but that shouldn't be necessary.
        !           733: 
        !           734: ======================================================================*/
        !           735: 
        !           736: static void axnet_reset_8390(struct net_device *dev)
        !           737: {
        !           738:     ioaddr_t nic_base = dev->base_addr;
        !           739:     int i;
        !           740: 
        !           741:     ei_status.txing = ei_status.dmaing = 0;
        !           742: 
        !           743:     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
        !           744: 
        !           745:     outb(inb(nic_base + AXNET_RESET), nic_base + AXNET_RESET);
        !           746: 
        !           747:     for (i = 0; i < 100; i++) {
        !           748:        if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
        !           749:            break;
        !           750:        udelay(100);
        !           751:     }
        !           752:     outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
        !           753:     
        !           754:     if (i == 100)
        !           755:        printk(KERN_ERR "%s: axnet_reset_8390() did not complete.\n",
        !           756:               dev->name);
        !           757:     
        !           758: } /* axnet_reset_8390 */
        !           759: 
        !           760: /*====================================================================*/
        !           761: 
        !           762: static void ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
        !           763: {
        !           764:     axnet_dev_t *info = dev_id;
        !           765:     info->stale = 0;
        !           766:     ax_interrupt(irq, dev_id, regs);
        !           767: }
        !           768: 
        !           769: static void ei_watchdog(u_long arg)
        !           770: {
        !           771:     axnet_dev_t *info = (axnet_dev_t *)(arg);
        !           772:     struct net_device *dev = &info->dev;
        !           773:     ioaddr_t nic_base = dev->base_addr;
        !           774:     ioaddr_t mii_addr = nic_base + AXNET_MII_EEP;
        !           775:     u_short link;
        !           776: 
        !           777:     if (!netif_device_present(dev)) goto reschedule;
        !           778: 
        !           779:     /* Check for pending interrupt with expired latency timer: with
        !           780:        this, we can limp along even if the interrupt is blocked */
        !           781:     if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
        !           782:        if (!info->fast_poll)
        !           783:            printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
        !           784:        ei_irq_wrapper(dev->irq, dev, NULL);
        !           785:        info->fast_poll = HZ;
        !           786:     }
        !           787:     if (info->fast_poll) {
        !           788:        info->fast_poll--;
        !           789:        info->watchdog.expires = jiffies + 1;
        !           790:        add_timer(&info->watchdog);
        !           791:        return;
        !           792:     }
        !           793: 
        !           794:     if (info->phy_id < 0)
        !           795:        goto reschedule;
        !           796:     link = mdio_read(mii_addr, info->phy_id, 1);
        !           797:     if (!link || (link == 0xffff)) {
        !           798:        printk(KERN_INFO "%s: MII is missing!\n", dev->name);
        !           799:        info->phy_id = -1;
        !           800:        goto reschedule;
        !           801:     }
        !           802: 
        !           803:     link &= 0x0004;
        !           804:     if (link != info->link_status) {
        !           805:        u_short p = mdio_read(mii_addr, info->phy_id, 5);
        !           806:        printk(KERN_INFO "%s: %s link beat\n", dev->name,
        !           807:               (link) ? "found" : "lost");
        !           808:        if (link) {
        !           809:            info->duplex_flag = (p & 0x0140) ? 0x80 : 0x00;
        !           810:            if (p)
        !           811:                printk(KERN_INFO "%s: autonegotiation complete: "
        !           812:                       "%sbaseT-%cD selected\n", dev->name,
        !           813:                       ((p & 0x0180) ? "100" : "10"),
        !           814:                       ((p & 0x0140) ? 'F' : 'H'));
        !           815:            else
        !           816:                printk(KERN_INFO "%s: link partner did not autonegotiate\n",
        !           817:                       dev->name);
        !           818:            AX88190_init(dev, 1);
        !           819:        }
        !           820:        info->link_status = link;
        !           821:     }
        !           822: 
        !           823: reschedule:
        !           824:     info->watchdog.expires = jiffies + HZ;
        !           825:     add_timer(&info->watchdog);
        !           826: }
        !           827: 
        !           828: /*====================================================================*/
        !           829: 
        !           830: static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        !           831: {
        !           832:     axnet_dev_t *info = (axnet_dev_t *)dev;
        !           833:     u16 *data = (u16 *)&rq->ifr_data;
        !           834:     ioaddr_t mii_addr = dev->base_addr + AXNET_MII_EEP;
        !           835:     switch (cmd) {
        !           836:     case SIOCDEVPRIVATE:
        !           837:        data[0] = info->phy_id;
        !           838:     case SIOCDEVPRIVATE+1:
        !           839:        data[3] = mdio_read(mii_addr, data[0], data[1] & 0x1f);
        !           840:        return 0;
        !           841:     case SIOCDEVPRIVATE+2:
        !           842:        if (!capable(CAP_NET_ADMIN))
        !           843:            return -EPERM;
        !           844:        mdio_write(mii_addr, data[0], data[1] & 0x1f, data[2]);
        !           845:        return 0;
        !           846:     }
        !           847:     return -EOPNOTSUPP;
        !           848: }
        !           849: 
        !           850: /*====================================================================*/
        !           851: 
        !           852: static void get_8390_hdr(struct net_device *dev,
        !           853:                         struct e8390_pkt_hdr *hdr,
        !           854:                         int ring_page)
        !           855: {
        !           856:     ioaddr_t nic_base = dev->base_addr;
        !           857: 
        !           858:     outb_p(0, nic_base + EN0_RSARLO);          /* On page boundary */
        !           859:     outb_p(ring_page, nic_base + EN0_RSARHI);
        !           860:     outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
        !           861: 
        !           862:     insw(nic_base + AXNET_DATAPORT, hdr,
        !           863:         sizeof(struct e8390_pkt_hdr)>>1);
        !           864:     /* Fix for big endian systems */
        !           865:     hdr->count = le16_to_cpu(hdr->count);
        !           866: 
        !           867: }
        !           868: 
        !           869: /*====================================================================*/
        !           870: 
        !           871: static void block_input(struct net_device *dev, int count,
        !           872:                        struct sk_buff *skb, int ring_offset)
        !           873: {
        !           874:     ioaddr_t nic_base = dev->base_addr;
        !           875:     int xfer_count = count;
        !           876:     char *buf = skb->data;
        !           877: 
        !           878: #ifdef PCMCIA_DEBUG
        !           879:     if ((ei_debug > 4) && (count != 4))
        !           880:        printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);
        !           881: #endif
        !           882:     outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
        !           883:     outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
        !           884:     outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
        !           885: 
        !           886:     insw(nic_base + AXNET_DATAPORT,buf,count>>1);
        !           887:     if (count & 0x01)
        !           888:        buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++;
        !           889: 
        !           890: }
        !           891: 
        !           892: /*====================================================================*/
        !           893: 
        !           894: static void block_output(struct net_device *dev, int count,
        !           895:                         const u_char *buf, const int start_page)
        !           896: {
        !           897:     ioaddr_t nic_base = dev->base_addr;
        !           898: 
        !           899: #ifdef PCMCIA_DEBUG
        !           900:     if (ei_debug > 4)
        !           901:        printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
        !           902: #endif
        !           903: 
        !           904:     /* Round the count up for word writes.  Do we need to do this?
        !           905:        What effect will an odd byte count have on the 8390?
        !           906:        I should check someday. */
        !           907:     if (count & 0x01)
        !           908:        count++;
        !           909: 
        !           910:     outb_p(0x00, nic_base + EN0_RSARLO);
        !           911:     outb_p(start_page, nic_base + EN0_RSARHI);
        !           912:     outb_p(E8390_RWRITE+E8390_START, nic_base + AXNET_CMD);
        !           913:     outsw(nic_base + AXNET_DATAPORT, buf, count>>1);
        !           914: }
        !           915: 
        !           916: /*====================================================================*/
        !           917: 
        !           918: static int __init init_axnet_cs(void)
        !           919: {
        !           920:     servinfo_t serv;
        !           921:     DEBUG(0, "%s\n", version);
        !           922:     CardServices(GetCardServicesInfo, &serv);
        !           923:     if (serv.Revision != CS_RELEASE_CODE) {
        !           924:        printk(KERN_NOTICE "axnet_cs: Card Services release "
        !           925:               "does not match!\n");
        !           926:        return -EINVAL;
        !           927:     }
        !           928:     register_pccard_driver(&dev_info, &axnet_attach, &axnet_detach);
        !           929:     return 0;
        !           930: }
        !           931: 
        !           932: static void __exit exit_axnet_cs(void)
        !           933: {
        !           934:     DEBUG(0, "axnet_cs: unloading\n");
        !           935:     unregister_pccard_driver(&dev_info);
        !           936:     while (dev_list != NULL)
        !           937:        axnet_detach(dev_list);
        !           938: }
        !           939: 
        !           940: module_init(init_axnet_cs);
        !           941: module_exit(exit_axnet_cs);
        !           942: 
        !           943: /*====================================================================*/
        !           944: 
        !           945: /* 8390.c: A general NS8390 ethernet driver core for linux. */
        !           946: /*
        !           947:        Written 1992-94 by Donald Becker.
        !           948:   
        !           949:        Copyright 1993 United States Government as represented by the
        !           950:        Director, National Security Agency.
        !           951: 
        !           952:        This software may be used and distributed according to the terms
        !           953:        of the GNU General Public License, incorporated herein by reference.
        !           954: 
        !           955:        The author may be reached as [email protected], or C/O
        !           956:        Scyld Computing Corporation
        !           957:        410 Severn Ave., Suite 210
        !           958:        Annapolis MD 21403
        !           959: 
        !           960:   This is the chip-specific code for many 8390-based ethernet adaptors.
        !           961:   This is not a complete driver, it must be combined with board-specific
        !           962:   code such as ne.c, wd.c, 3c503.c, etc.
        !           963: 
        !           964:   Seeing how at least eight drivers use this code, (not counting the
        !           965:   PCMCIA ones either) it is easy to break some card by what seems like
        !           966:   a simple innocent change. Please contact me or Donald if you think
        !           967:   you have found something that needs changing. -- PG
        !           968: 
        !           969:   Changelog:
        !           970: 
        !           971:   Paul Gortmaker       : remove set_bit lock, other cleanups.
        !           972:   Paul Gortmaker       : add ei_get_8390_hdr() so we can pass skb's to 
        !           973:                          ei_block_input() for eth_io_copy_and_sum().
        !           974:   Paul Gortmaker       : exchange static int ei_pingpong for a #define,
        !           975:                          also add better Tx error handling.
        !           976:   Paul Gortmaker       : rewrite Rx overrun handling as per NS specs.
        !           977:   Alexey Kuznetsov     : use the 8390's six bit hash multicast filter.
        !           978:   Paul Gortmaker       : tweak ANK's above multicast changes a bit.
        !           979:   Paul Gortmaker       : update packet statistics for v2.1.x
        !           980:   Alan Cox             : support arbitary stupid port mappings on the
        !           981:                          68K Macintosh. Support >16bit I/O spaces
        !           982:   Paul Gortmaker       : add kmod support for auto-loading of the 8390
        !           983:                          module by all drivers that require it.
        !           984:   Alan Cox             : Spinlocking work, added 'BUG_83C690'
        !           985:   Paul Gortmaker       : Separate out Tx timeout code from Tx path.
        !           986: 
        !           987:   Sources:
        !           988:   The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
        !           989: 
        !           990:   */
        !           991: 
        !           992: static const char *version_8390 =
        !           993:     "8390.c:v1.10cvs 9/23/94 Donald Becker ([email protected])\n";
        !           994: 
        !           995: #include <asm/uaccess.h>
        !           996: #include <asm/bitops.h>
        !           997: #include <asm/irq.h>
        !           998: #include <linux/fcntl.h>
        !           999: #include <linux/in.h>
        !          1000: #include <linux/interrupt.h>
        !          1001: 
        !          1002: #include <linux/etherdevice.h>
        !          1003: 
        !          1004: #define BUG_83C690
        !          1005: 
        !          1006: /* These are the operational function interfaces to board-specific
        !          1007:    routines.
        !          1008:        void reset_8390(struct net_device *dev)
        !          1009:                Resets the board associated with DEV, including a hardware reset of
        !          1010:                the 8390.  This is only called when there is a transmit timeout, and
        !          1011:                it is always followed by 8390_init().
        !          1012:        void block_output(struct net_device *dev, int count, const unsigned char *buf,
        !          1013:                                          int start_page)
        !          1014:                Write the COUNT bytes of BUF to the packet buffer at START_PAGE.  The
        !          1015:                "page" value uses the 8390's 256-byte pages.
        !          1016:        void get_8390_hdr(struct net_device *dev, struct e8390_hdr *hdr, int ring_page)
        !          1017:                Read the 4 byte, page aligned 8390 header. *If* there is a
        !          1018:                subsequent read, it will be of the rest of the packet.
        !          1019:        void block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
        !          1020:                Read COUNT bytes from the packet buffer into the skb data area. Start 
        !          1021:                reading from RING_OFFSET, the address as the 8390 sees it.  This will always
        !          1022:                follow the read of the 8390 header. 
        !          1023: */
        !          1024: #define ei_reset_8390 (ei_local->reset_8390)
        !          1025: #define ei_block_output (ei_local->block_output)
        !          1026: #define ei_block_input (ei_local->block_input)
        !          1027: #define ei_get_8390_hdr (ei_local->get_8390_hdr)
        !          1028: 
        !          1029: /* use 0 for production, 1 for verification, >2 for debug */
        !          1030: #ifndef ei_debug
        !          1031: int ei_debug = 1;
        !          1032: #endif
        !          1033: 
        !          1034: /* Index to functions. */
        !          1035: static void ei_tx_intr(struct net_device *dev);
        !          1036: static void ei_tx_err(struct net_device *dev);
        !          1037: static void ei_tx_timeout(struct net_device *dev);
        !          1038: static void ei_receive(struct net_device *dev);
        !          1039: static void ei_rx_overrun(struct net_device *dev);
        !          1040: 
        !          1041: /* Routines generic to NS8390-based boards. */
        !          1042: static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
        !          1043:                                                                int start_page);
        !          1044: static void set_multicast_list(struct net_device *dev);
        !          1045: static void do_set_multicast_list(struct net_device *dev);
        !          1046: 
        !          1047: /*
        !          1048:  *     SMP and the 8390 setup.
        !          1049:  *
        !          1050:  *     The 8390 isnt exactly designed to be multithreaded on RX/TX. There is
        !          1051:  *     a page register that controls bank and packet buffer access. We guard
        !          1052:  *     this with ei_local->page_lock. Nobody should assume or set the page other
        !          1053:  *     than zero when the lock is not held. Lock holders must restore page 0
        !          1054:  *     before unlocking. Even pure readers must take the lock to protect in 
        !          1055:  *     page 0.
        !          1056:  *
        !          1057:  *     To make life difficult the chip can also be very slow. We therefore can't
        !          1058:  *     just use spinlocks. For the longer lockups we disable the irq the device
        !          1059:  *     sits on and hold the lock. We must hold the lock because there is a dual
        !          1060:  *     processor case other than interrupts (get stats/set multicast list in
        !          1061:  *     parallel with each other and transmit).
        !          1062:  *
        !          1063:  *     Note: in theory we can just disable the irq on the card _but_ there is
        !          1064:  *     a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs"
        !          1065:  *     enter lock, take the queued irq. So we waddle instead of flying.
        !          1066:  *
        !          1067:  *     Finally by special arrangement for the purpose of being generally 
        !          1068:  *     annoying the transmit function is called bh atomic. That places
        !          1069:  *     restrictions on the user context callers as disable_irq won't save
        !          1070:  *     them.
        !          1071:  */
        !          1072:  
        !          1073: /**
        !          1074:  * ax_open - Open/initialize the board.
        !          1075:  * @dev: network device to initialize
        !          1076:  *
        !          1077:  * This routine goes all-out, setting everything
        !          1078:  * up anew at each open, even though many of these registers should only
        !          1079:  * need to be set once at boot.
        !          1080:  */
        !          1081: static int ax_open(struct net_device *dev)
        !          1082: {
        !          1083:        unsigned long flags;
        !          1084:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1085: 
        !          1086:        /* This can't happen unless somebody forgot to call axdev_init(). */
        !          1087:        if (ei_local == NULL) 
        !          1088:        {
        !          1089:                printk(KERN_EMERG "%s: ax_open passed a non-existent device!\n", dev->name);
        !          1090:                return -ENXIO;
        !          1091:        }
        !          1092: 
        !          1093: #ifdef HAVE_TX_TIMEOUT
        !          1094:        /* The card I/O part of the driver (e.g. 3c503) can hook a Tx timeout
        !          1095:            wrapper that does e.g. media check & then calls ei_tx_timeout. */
        !          1096:        if (dev->tx_timeout == NULL)
        !          1097:                 dev->tx_timeout = ei_tx_timeout;
        !          1098:        if (dev->watchdog_timeo <= 0)
        !          1099:                 dev->watchdog_timeo = TX_TIMEOUT;
        !          1100: #endif
        !          1101: 
        !          1102:        /*
        !          1103:         *      Grab the page lock so we own the register set, then call
        !          1104:         *      the init function.
        !          1105:         */
        !          1106:       
        !          1107:        spin_lock_irqsave(&ei_local->page_lock, flags);
        !          1108:        AX88190_init(dev, 1);
        !          1109:        /* Set the flag before we drop the lock, That way the IRQ arrives
        !          1110:           after its set and we get no silly warnings */
        !          1111:        netif_mark_up(dev);
        !          1112:        netif_start_queue(dev);
        !          1113:        spin_unlock_irqrestore(&ei_local->page_lock, flags);
        !          1114:        ei_local->irqlock = 0;
        !          1115:        return 0;
        !          1116: }
        !          1117: 
        !          1118: #define dev_lock(dev) (((struct ei_device *)(dev)->priv)->page_lock)
        !          1119: 
        !          1120: /**
        !          1121:  * ax_close - shut down network device
        !          1122:  * @dev: network device to close
        !          1123:  *
        !          1124:  * Opposite of ax_open(). Only used when "ifconfig <devname> down" is done.
        !          1125:  */
        !          1126: int ax_close(struct net_device *dev)
        !          1127: {
        !          1128:        unsigned long flags;
        !          1129: 
        !          1130:        /*
        !          1131:         *      Hold the page lock during close
        !          1132:         */
        !          1133: 
        !          1134:        spin_lock_irqsave(&dev_lock(dev), flags);
        !          1135:        AX88190_init(dev, 0);
        !          1136:        spin_unlock_irqrestore(&dev_lock(dev), flags);
        !          1137:        netif_stop_queue(dev);
        !          1138:        return 0;
        !          1139: }
        !          1140: 
        !          1141: /**
        !          1142:  * ei_tx_timeout - handle transmit time out condition
        !          1143:  * @dev: network device which has apparently fallen asleep
        !          1144:  *
        !          1145:  * Called by kernel when device never acknowledges a transmit has
        !          1146:  * completed (or failed) - i.e. never posted a Tx related interrupt.
        !          1147:  */
        !          1148: 
        !          1149: void ei_tx_timeout(struct net_device *dev)
        !          1150: {
        !          1151:        long e8390_base = dev->base_addr;
        !          1152:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1153:        int txsr, isr, tickssofar = jiffies - dev->trans_start;
        !          1154:        unsigned long flags;
        !          1155: 
        !          1156:        ei_local->stat.tx_errors++;
        !          1157: 
        !          1158:        spin_lock_irqsave(&ei_local->page_lock, flags);
        !          1159:        txsr = inb(e8390_base+EN0_TSR);
        !          1160:        isr = inb(e8390_base+EN0_ISR);
        !          1161:        spin_unlock_irqrestore(&ei_local->page_lock, flags);
        !          1162: 
        !          1163:        printk(KERN_DEBUG "%s: Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
        !          1164:                dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
        !          1165:                (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
        !          1166: 
        !          1167:        if (!isr && !ei_local->stat.tx_packets) 
        !          1168:        {
        !          1169:                /* The 8390 probably hasn't gotten on the cable yet. */
        !          1170:                ei_local->interface_num ^= 1;   /* Try a different xcvr.  */
        !          1171:        }
        !          1172: 
        !          1173:        /* Ugly but a reset can be slow, yet must be protected */
        !          1174:                
        !          1175:        disable_irq_nosync(dev->irq);
        !          1176:        spin_lock(&ei_local->page_lock);
        !          1177:                
        !          1178:        /* Try to restart the card.  Perhaps the user has fixed something. */
        !          1179:        ei_reset_8390(dev);
        !          1180:        AX88190_init(dev, 1);
        !          1181:                
        !          1182:        spin_unlock(&ei_local->page_lock);
        !          1183:        enable_irq(dev->irq);
        !          1184:        netif_wake_queue(dev);
        !          1185: }
        !          1186:     
        !          1187: /**
        !          1188:  * ei_start_xmit - begin packet transmission
        !          1189:  * @skb: packet to be sent
        !          1190:  * @dev: network device to which packet is sent
        !          1191:  *
        !          1192:  * Sends a packet to an 8390 network device.
        !          1193:  */
        !          1194:  
        !          1195: static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
        !          1196: {
        !          1197:        long e8390_base = dev->base_addr;
        !          1198:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1199:        int length, send_length, output_page;
        !          1200:        unsigned long flags;
        !          1201: 
        !          1202:        tx_timeout_check(dev, ei_tx_timeout);
        !          1203:        skb_tx_check(dev, skb);
        !          1204: 
        !          1205:        length = skb->len;
        !          1206: 
        !          1207:        /* Mask interrupts from the ethercard. 
        !          1208:           SMP: We have to grab the lock here otherwise the IRQ handler
        !          1209:           on another CPU can flip window and race the IRQ mask set. We end
        !          1210:           up trashing the mcast filter not disabling irqs if we dont lock */
        !          1211:           
        !          1212:        spin_lock_irqsave(&ei_local->page_lock, flags);
        !          1213:        outb_p(0x00, e8390_base + EN0_IMR);
        !          1214:        spin_unlock_irqrestore(&ei_local->page_lock, flags);
        !          1215:        
        !          1216:        /*
        !          1217:         *      Slow phase with lock held.
        !          1218:         */
        !          1219:         
        !          1220:        disable_irq_nosync(dev->irq);
        !          1221:        
        !          1222:        spin_lock(&ei_local->page_lock);
        !          1223:        
        !          1224:        ei_local->irqlock = 1;
        !          1225: 
        !          1226:        send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
        !          1227:     
        !          1228:        /*
        !          1229:         * We have two Tx slots available for use. Find the first free
        !          1230:         * slot, and then perform some sanity checks. With two Tx bufs,
        !          1231:         * you get very close to transmitting back-to-back packets. With
        !          1232:         * only one Tx buf, the transmitter sits idle while you reload the
        !          1233:         * card, leaving a substantial gap between each transmitted packet.
        !          1234:         */
        !          1235: 
        !          1236:        if (ei_local->tx1 == 0) 
        !          1237:        {
        !          1238:                output_page = ei_local->tx_start_page;
        !          1239:                ei_local->tx1 = send_length;
        !          1240:                if (ei_debug  &&  ei_local->tx2 > 0)
        !          1241:                        printk(KERN_DEBUG "%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
        !          1242:                                dev->name, ei_local->tx2, ei_local->lasttx, ei_local->txing);
        !          1243:        }
        !          1244:        else if (ei_local->tx2 == 0) 
        !          1245:        {
        !          1246:                output_page = ei_local->tx_start_page + TX_1X_PAGES;
        !          1247:                ei_local->tx2 = send_length;
        !          1248:                if (ei_debug  &&  ei_local->tx1 > 0)
        !          1249:                        printk(KERN_DEBUG "%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
        !          1250:                                dev->name, ei_local->tx1, ei_local->lasttx, ei_local->txing);
        !          1251:        }
        !          1252:        else
        !          1253:        {       /* We should never get here. */
        !          1254:                if (ei_debug)
        !          1255:                        printk(KERN_DEBUG "%s: No Tx buffers free! tx1=%d tx2=%d last=%d\n",
        !          1256:                                dev->name, ei_local->tx1, ei_local->tx2, ei_local->lasttx);
        !          1257:                ei_local->irqlock = 0;
        !          1258:                netif_stop_queue(dev);
        !          1259:                outb_p(ENISR_ALL, e8390_base + EN0_IMR);
        !          1260:                spin_unlock(&ei_local->page_lock);
        !          1261:                enable_irq(dev->irq);
        !          1262:                ei_local->stat.tx_errors++;
        !          1263:                return 1;
        !          1264:        }
        !          1265: 
        !          1266:        /*
        !          1267:         * Okay, now upload the packet and trigger a send if the transmitter
        !          1268:         * isn't already sending. If it is busy, the interrupt handler will
        !          1269:         * trigger the send later, upon receiving a Tx done interrupt.
        !          1270:         */
        !          1271: 
        !          1272:        ei_block_output(dev, length, skb->data, output_page);
        !          1273:        if (! ei_local->txing) 
        !          1274:        {
        !          1275:                ei_local->txing = 1;
        !          1276:                NS8390_trigger_send(dev, send_length, output_page);
        !          1277:                dev->trans_start = jiffies;
        !          1278:                if (output_page == ei_local->tx_start_page) 
        !          1279:                {
        !          1280:                        ei_local->tx1 = -1;
        !          1281:                        ei_local->lasttx = -1;
        !          1282:                }
        !          1283:                else 
        !          1284:                {
        !          1285:                        ei_local->tx2 = -1;
        !          1286:                        ei_local->lasttx = -2;
        !          1287:                }
        !          1288:        }
        !          1289:        else ei_local->txqueue++;
        !          1290: 
        !          1291:        if (ei_local->tx1  &&  ei_local->tx2)
        !          1292:                netif_stop_queue(dev);
        !          1293:        else
        !          1294:                netif_start_queue(dev);
        !          1295: 
        !          1296:        /* Turn 8390 interrupts back on. */
        !          1297:        ei_local->irqlock = 0;
        !          1298:        outb_p(ENISR_ALL, e8390_base + EN0_IMR);
        !          1299:        
        !          1300:        spin_unlock(&ei_local->page_lock);
        !          1301:        enable_irq(dev->irq);
        !          1302: 
        !          1303:        DEV_KFREE_SKB (skb);
        !          1304:        add_tx_bytes(&ei_local->stat, send_length);
        !          1305:     
        !          1306:        return 0;
        !          1307: }
        !          1308: 
        !          1309: /**
        !          1310:  * ax_interrupt - handle the interrupts from an 8390
        !          1311:  * @irq: interrupt number
        !          1312:  * @dev_id: a pointer to the net_device
        !          1313:  * @regs: unused
        !          1314:  *
        !          1315:  * Handle the ether interface interrupts. We pull packets from
        !          1316:  * the 8390 via the card specific functions and fire them at the networking
        !          1317:  * stack. We also handle transmit completions and wake the transmit path if
        !          1318:  * neccessary. We also update the counters and do other housekeeping as
        !          1319:  * needed.
        !          1320:  */
        !          1321: 
        !          1322: static void ax_interrupt(int irq, void *dev_id, struct pt_regs * regs)
        !          1323: {
        !          1324:        struct net_device *dev = dev_id;
        !          1325:        long e8390_base;
        !          1326:        int interrupts, nr_serviced = 0, i;
        !          1327:        struct ei_device *ei_local;
        !          1328:     
        !          1329:        if (dev == NULL) 
        !          1330:        {
        !          1331:                printk ("net_interrupt(): irq %d for unknown device.\n", irq);
        !          1332:                return;
        !          1333:        }
        !          1334:     
        !          1335:        e8390_base = dev->base_addr;
        !          1336:        ei_local = (struct ei_device *) dev->priv;
        !          1337: 
        !          1338:        /*
        !          1339:         *      Protect the irq test too.
        !          1340:         */
        !          1341:         
        !          1342:        spin_lock(&ei_local->page_lock);
        !          1343: 
        !          1344:        if (ei_local->irqlock) 
        !          1345:        {
        !          1346: #if 1 /* This might just be an interrupt for a PCI device sharing this line */
        !          1347:                /* The "irqlock" check is only for testing. */
        !          1348:                printk(ei_local->irqlock
        !          1349:                           ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
        !          1350:                           : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
        !          1351:                           dev->name, inb_p(e8390_base + EN0_ISR),
        !          1352:                           inb_p(e8390_base + EN0_IMR));
        !          1353: #endif
        !          1354:                spin_unlock(&ei_local->page_lock);
        !          1355:                return;
        !          1356:        }
        !          1357:     
        !          1358:        if (ei_debug > 3)
        !          1359:                printk(KERN_DEBUG "%s: interrupt(isr=%#2.2x).\n", dev->name,
        !          1360:                           inb_p(e8390_base + EN0_ISR));
        !          1361: 
        !          1362:        outb_p(0x00, e8390_base + EN0_ISR);
        !          1363:        ei_local->irqlock = 1;
        !          1364:    
        !          1365:        /* !!Assumption!! -- we stay in page 0.  Don't break this. */
        !          1366:        while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
        !          1367:                   && ++nr_serviced < MAX_SERVICE) 
        !          1368:        {
        !          1369:                if (!netif_running(dev) || (interrupts == 0xff)) {
        !          1370:                        if (ei_debug > 1)
        !          1371:                                printk(KERN_WARNING "%s: interrupt from stopped card\n", dev->name);
        !          1372:                        outb_p(interrupts, e8390_base + EN0_ISR);
        !          1373:                        interrupts = 0;
        !          1374:                        break;
        !          1375:                }
        !          1376:                /* AX88190 bug fix. */
        !          1377:                outb_p(interrupts, e8390_base + EN0_ISR);
        !          1378:                for (i = 0; i < 10; i++) {
        !          1379:                        if (!(inb(e8390_base + EN0_ISR) & interrupts))
        !          1380:                                break;
        !          1381:                        outb_p(0, e8390_base + EN0_ISR);
        !          1382:                        outb_p(interrupts, e8390_base + EN0_ISR);
        !          1383:                }
        !          1384:                if (interrupts & ENISR_OVER) 
        !          1385:                        ei_rx_overrun(dev);
        !          1386:                else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) 
        !          1387:                {
        !          1388:                        /* Got a good (?) packet. */
        !          1389:                        ei_receive(dev);
        !          1390:                }
        !          1391:                /* Push the next to-transmit packet through. */
        !          1392:                if (interrupts & ENISR_TX)
        !          1393:                        ei_tx_intr(dev);
        !          1394:                else if (interrupts & ENISR_TX_ERR)
        !          1395:                        ei_tx_err(dev);
        !          1396: 
        !          1397:                if (interrupts & ENISR_COUNTERS) 
        !          1398:                {
        !          1399:                        ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
        !          1400:                        ei_local->stat.rx_crc_errors   += inb_p(e8390_base + EN0_COUNTER1);
        !          1401:                        ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
        !          1402:                }
        !          1403:        }
        !          1404:     
        !          1405:        if (interrupts && ei_debug) 
        !          1406:        {
        !          1407:                if (nr_serviced >= MAX_SERVICE) 
        !          1408:                {
        !          1409:                        /* 0xFF is valid for a card removal */
        !          1410:                        if(interrupts!=0xFF)
        !          1411:                                printk(KERN_WARNING "%s: Too much work at interrupt, status %#2.2x\n",
        !          1412:                                   dev->name, interrupts);
        !          1413:                        outb_p(ENISR_ALL, e8390_base + EN0_ISR); /* Ack. most intrs. */
        !          1414:                } else {
        !          1415:                        printk(KERN_WARNING "%s: unknown interrupt %#2x\n", dev->name, interrupts);
        !          1416:                        outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
        !          1417:                }
        !          1418:        }
        !          1419: 
        !          1420:        /* Turn 8390 interrupts back on. */
        !          1421:        ei_local->irqlock = 0;
        !          1422:        outb_p(ENISR_ALL, e8390_base + EN0_IMR);
        !          1423: 
        !          1424:        spin_unlock(&ei_local->page_lock);
        !          1425:        return;
        !          1426: }
        !          1427: 
        !          1428: /**
        !          1429:  * ei_tx_err - handle transmitter error
        !          1430:  * @dev: network device which threw the exception
        !          1431:  *
        !          1432:  * A transmitter error has happened. Most likely excess collisions (which
        !          1433:  * is a fairly normal condition). If the error is one where the Tx will
        !          1434:  * have been aborted, we try and send another one right away, instead of
        !          1435:  * letting the failed packet sit and collect dust in the Tx buffer. This
        !          1436:  * is a much better solution as it avoids kernel based Tx timeouts, and
        !          1437:  * an unnecessary card reset.
        !          1438:  *
        !          1439:  * Called with lock held.
        !          1440:  */
        !          1441: 
        !          1442: static void ei_tx_err(struct net_device *dev)
        !          1443: {
        !          1444:        long e8390_base = dev->base_addr;
        !          1445:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1446:        unsigned char txsr = inb_p(e8390_base+EN0_TSR);
        !          1447:        unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
        !          1448: 
        !          1449: #ifdef VERBOSE_ERROR_DUMP
        !          1450:        printk(KERN_DEBUG "%s: transmitter error (%#2x): ", dev->name, txsr);
        !          1451:        if (txsr & ENTSR_ABT)
        !          1452:                printk("excess-collisions ");
        !          1453:        if (txsr & ENTSR_ND)
        !          1454:                printk("non-deferral ");
        !          1455:        if (txsr & ENTSR_CRS)
        !          1456:                printk("lost-carrier ");
        !          1457:        if (txsr & ENTSR_FU)
        !          1458:                printk("FIFO-underrun ");
        !          1459:        if (txsr & ENTSR_CDH)
        !          1460:                printk("lost-heartbeat ");
        !          1461:        printk("\n");
        !          1462: #endif
        !          1463: 
        !          1464:        if (tx_was_aborted)
        !          1465:                ei_tx_intr(dev);
        !          1466:        else 
        !          1467:        {
        !          1468:                ei_local->stat.tx_errors++;
        !          1469:                if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
        !          1470:                if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
        !          1471:                if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++;
        !          1472:        }
        !          1473: }
        !          1474: 
        !          1475: /**
        !          1476:  * ei_tx_intr - transmit interrupt handler
        !          1477:  * @dev: network device for which tx intr is handled
        !          1478:  *
        !          1479:  * We have finished a transmit: check for errors and then trigger the next
        !          1480:  * packet to be sent. Called with lock held.
        !          1481:  */
        !          1482: 
        !          1483: static void ei_tx_intr(struct net_device *dev)
        !          1484: {
        !          1485:        long e8390_base = dev->base_addr;
        !          1486:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1487:        int status = inb(e8390_base + EN0_TSR);
        !          1488:     
        !          1489:        /*
        !          1490:         * There are two Tx buffers, see which one finished, and trigger
        !          1491:         * the send of another one if it exists.
        !          1492:         */
        !          1493:        ei_local->txqueue--;
        !          1494: 
        !          1495:        if (ei_local->tx1 < 0) 
        !          1496:        {
        !          1497:                if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
        !          1498:                        printk(KERN_ERR "%s: bogus last_tx_buffer %d, tx1=%d.\n",
        !          1499:                                ei_local->name, ei_local->lasttx, ei_local->tx1);
        !          1500:                ei_local->tx1 = 0;
        !          1501:                if (ei_local->tx2 > 0) 
        !          1502:                {
        !          1503:                        ei_local->txing = 1;
        !          1504:                        NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
        !          1505:                        dev->trans_start = jiffies;
        !          1506:                        ei_local->tx2 = -1,
        !          1507:                        ei_local->lasttx = 2;
        !          1508:                }
        !          1509:                else ei_local->lasttx = 20, ei_local->txing = 0;        
        !          1510:        }
        !          1511:        else if (ei_local->tx2 < 0) 
        !          1512:        {
        !          1513:                if (ei_local->lasttx != 2  &&  ei_local->lasttx != -2)
        !          1514:                        printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
        !          1515:                                ei_local->name, ei_local->lasttx, ei_local->tx2);
        !          1516:                ei_local->tx2 = 0;
        !          1517:                if (ei_local->tx1 > 0) 
        !          1518:                {
        !          1519:                        ei_local->txing = 1;
        !          1520:                        NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
        !          1521:                        dev->trans_start = jiffies;
        !          1522:                        ei_local->tx1 = -1;
        !          1523:                        ei_local->lasttx = 1;
        !          1524:                }
        !          1525:                else
        !          1526:                        ei_local->lasttx = 10, ei_local->txing = 0;
        !          1527:        }
        !          1528: //     else printk(KERN_WARNING "%s: unexpected TX-done interrupt, lasttx=%d.\n",
        !          1529: //                     dev->name, ei_local->lasttx);
        !          1530: 
        !          1531:        /* Minimize Tx latency: update the statistics after we restart TXing. */
        !          1532:        if (status & ENTSR_COL)
        !          1533:                ei_local->stat.collisions++;
        !          1534:        if (status & ENTSR_PTX)
        !          1535:                ei_local->stat.tx_packets++;
        !          1536:        else 
        !          1537:        {
        !          1538:                ei_local->stat.tx_errors++;
        !          1539:                if (status & ENTSR_ABT) 
        !          1540:                {
        !          1541:                        ei_local->stat.tx_aborted_errors++;
        !          1542:                        ei_local->stat.collisions += 16;
        !          1543:                }
        !          1544:                if (status & ENTSR_CRS) 
        !          1545:                        ei_local->stat.tx_carrier_errors++;
        !          1546:                if (status & ENTSR_FU) 
        !          1547:                        ei_local->stat.tx_fifo_errors++;
        !          1548:                if (status & ENTSR_CDH)
        !          1549:                        ei_local->stat.tx_heartbeat_errors++;
        !          1550:                if (status & ENTSR_OWC)
        !          1551:                        ei_local->stat.tx_window_errors++;
        !          1552:        }
        !          1553:        netif_wake_queue(dev);
        !          1554: }
        !          1555: 
        !          1556: /**
        !          1557:  * ei_receive - receive some packets
        !          1558:  * @dev: network device with which receive will be run
        !          1559:  *
        !          1560:  * We have a good packet(s), get it/them out of the buffers. 
        !          1561:  * Called with lock held.
        !          1562:  */
        !          1563: 
        !          1564: static void ei_receive(struct net_device *dev)
        !          1565: {
        !          1566:        long e8390_base = dev->base_addr;
        !          1567:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1568:        unsigned char rxing_page, this_frame, next_frame;
        !          1569:        unsigned short current_offset;
        !          1570:        int rx_pkt_count = 0;
        !          1571:        struct e8390_pkt_hdr rx_frame;
        !          1572:     
        !          1573:        while (++rx_pkt_count < 10) 
        !          1574:        {
        !          1575:                int pkt_len, pkt_stat;
        !          1576:                
        !          1577:                /* Get the rx page (incoming packet pointer). */
        !          1578:                rxing_page = inb_p(e8390_base + EN1_CURPAG -1);
        !          1579:                
        !          1580:                /* Remove one frame from the ring.  Boundary is always a page behind. */
        !          1581:                this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
        !          1582:                if (this_frame >= ei_local->stop_page)
        !          1583:                        this_frame = ei_local->rx_start_page;
        !          1584:                
        !          1585:                /* Someday we'll omit the previous, iff we never get this message.
        !          1586:                   (There is at least one clone claimed to have a problem.)  
        !          1587:                   
        !          1588:                   Keep quiet if it looks like a card removal. One problem here
        !          1589:                   is that some clones crash in roughly the same way.
        !          1590:                 */
        !          1591:                if (ei_debug > 0  &&  this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF))
        !          1592:                        printk(KERN_ERR "%s: mismatched read page pointers %2x vs %2x.\n",
        !          1593:                                   dev->name, this_frame, ei_local->current_page);
        !          1594:                
        !          1595:                if (this_frame == rxing_page)   /* Read all the frames? */
        !          1596:                        break;                          /* Done for now */
        !          1597:                
        !          1598:                current_offset = this_frame << 8;
        !          1599:                ei_get_8390_hdr(dev, &rx_frame, this_frame);
        !          1600:                
        !          1601:                pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr);
        !          1602:                pkt_stat = rx_frame.status;
        !          1603:                
        !          1604:                next_frame = this_frame + 1 + ((pkt_len+4)>>8);
        !          1605:                
        !          1606:                if (pkt_len < 60  ||  pkt_len > 1518) 
        !          1607:                {
        !          1608:                        if (ei_debug)
        !          1609:                                printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
        !          1610:                                           dev->name, rx_frame.count, rx_frame.status,
        !          1611:                                           rx_frame.next);
        !          1612:                        ei_local->stat.rx_errors++;
        !          1613:                        ei_local->stat.rx_length_errors++;
        !          1614:                }
        !          1615:                 else if ((pkt_stat & 0x0F) == ENRSR_RXOK) 
        !          1616:                {
        !          1617:                        struct sk_buff *skb;
        !          1618:                        
        !          1619:                        skb = dev_alloc_skb(pkt_len+2);
        !          1620:                        if (skb == NULL) 
        !          1621:                        {
        !          1622:                                if (ei_debug > 1)
        !          1623:                                        printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
        !          1624:                                                   dev->name, pkt_len);
        !          1625:                                ei_local->stat.rx_dropped++;
        !          1626:                                break;
        !          1627:                        }
        !          1628:                        else
        !          1629:                        {
        !          1630:                                skb_reserve(skb,2);     /* IP headers on 16 byte boundaries */
        !          1631:                                skb->dev = dev;
        !          1632:                                skb_put(skb, pkt_len);  /* Make room */
        !          1633:                                ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame));
        !          1634:                                skb->protocol=eth_type_trans(skb,dev);
        !          1635:                                netif_rx(skb);
        !          1636:                                dev->last_rx = jiffies;
        !          1637:                                ei_local->stat.rx_packets++;
        !          1638:                                add_rx_bytes(&ei_local->stat, pkt_len);
        !          1639:                                if (pkt_stat & ENRSR_PHY)
        !          1640:                                        ei_local->stat.multicast++;
        !          1641:                        }
        !          1642:                } 
        !          1643:                else 
        !          1644:                {
        !          1645:                        if (ei_debug)
        !          1646:                                printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
        !          1647:                                           dev->name, rx_frame.status, rx_frame.next,
        !          1648:                                           rx_frame.count);
        !          1649:                        ei_local->stat.rx_errors++;
        !          1650:                        /* NB: The NIC counts CRC, frame and missed errors. */
        !          1651:                        if (pkt_stat & ENRSR_FO)
        !          1652:                                ei_local->stat.rx_fifo_errors++;
        !          1653:                }
        !          1654:                next_frame = rx_frame.next;
        !          1655:                
        !          1656:                /* This _should_ never happen: it's here for avoiding bad clones. */
        !          1657:                if (next_frame >= ei_local->stop_page) {
        !          1658:                        printk("%s: next frame inconsistency, %#2x\n", dev->name,
        !          1659:                                   next_frame);
        !          1660:                        next_frame = ei_local->rx_start_page;
        !          1661:                }
        !          1662:                ei_local->current_page = next_frame;
        !          1663:                outb_p(next_frame-1, e8390_base+EN0_BOUNDARY);
        !          1664:        }
        !          1665: 
        !          1666:        return;
        !          1667: }
        !          1668: 
        !          1669: /**
        !          1670:  * ei_rx_overrun - handle receiver overrun
        !          1671:  * @dev: network device which threw exception
        !          1672:  *
        !          1673:  * We have a receiver overrun: we have to kick the 8390 to get it started
        !          1674:  * again. Problem is that you have to kick it exactly as NS prescribes in
        !          1675:  * the updated datasheets, or "the NIC may act in an unpredictable manner."
        !          1676:  * This includes causing "the NIC to defer indefinitely when it is stopped
        !          1677:  * on a busy network."  Ugh.
        !          1678:  * Called with lock held. Don't call this with the interrupts off or your
        !          1679:  * computer will hate you - it takes 10ms or so. 
        !          1680:  */
        !          1681: 
        !          1682: static void ei_rx_overrun(struct net_device *dev)
        !          1683: {
        !          1684:        axnet_dev_t *info = (axnet_dev_t *)dev;
        !          1685:        long e8390_base = dev->base_addr;
        !          1686:        unsigned char was_txing, must_resend = 0;
        !          1687:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1688:     
        !          1689:        /*
        !          1690:         * Record whether a Tx was in progress and then issue the
        !          1691:         * stop command.
        !          1692:         */
        !          1693:        was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS;
        !          1694:        outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
        !          1695:     
        !          1696:        if (ei_debug > 1)
        !          1697:                printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
        !          1698:        ei_local->stat.rx_over_errors++;
        !          1699:     
        !          1700:        /* 
        !          1701:         * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
        !          1702:         * Early datasheets said to poll the reset bit, but now they say that
        !          1703:         * it "is not a reliable indicator and subsequently should be ignored."
        !          1704:         * We wait at least 10ms.
        !          1705:         */
        !          1706: 
        !          1707:        mdelay(10);
        !          1708: 
        !          1709:        /*
        !          1710:         * Reset RBCR[01] back to zero as per magic incantation.
        !          1711:         */
        !          1712:        outb_p(0x00, e8390_base+EN0_RCNTLO);
        !          1713:        outb_p(0x00, e8390_base+EN0_RCNTHI);
        !          1714: 
        !          1715:        /*
        !          1716:         * See if any Tx was interrupted or not. According to NS, this
        !          1717:         * step is vital, and skipping it will cause no end of havoc.
        !          1718:         */
        !          1719: 
        !          1720:        if (was_txing)
        !          1721:        { 
        !          1722:                unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR);
        !          1723:                if (!tx_completed)
        !          1724:                        must_resend = 1;
        !          1725:        }
        !          1726: 
        !          1727:        /*
        !          1728:         * Have to enter loopback mode and then restart the NIC before
        !          1729:         * you are allowed to slurp packets up off the ring.
        !          1730:         */
        !          1731:        outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
        !          1732:        outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
        !          1733: 
        !          1734:        /*
        !          1735:         * Clear the Rx ring of all the debris, and ack the interrupt.
        !          1736:         */
        !          1737:        ei_receive(dev);
        !          1738: 
        !          1739:        /*
        !          1740:         * Leave loopback mode, and resend any packet that got stopped.
        !          1741:         */
        !          1742:        outb_p(E8390_TXCONFIG | info->duplex_flag, e8390_base + EN0_TXCR); 
        !          1743:        if (must_resend)
        !          1744:                outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD);
        !          1745: }
        !          1746: 
        !          1747: /*
        !          1748:  *     Collect the stats. This is called unlocked and from several contexts.
        !          1749:  */
        !          1750:  
        !          1751: static struct net_device_stats *get_stats(struct net_device *dev)
        !          1752: {
        !          1753:        long ioaddr = dev->base_addr;
        !          1754:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1755:        unsigned long flags;
        !          1756:     
        !          1757:        /* If the card is stopped, just return the present stats. */
        !          1758:        if (!netif_running(dev))
        !          1759:                return &ei_local->stat;
        !          1760: 
        !          1761:        spin_lock_irqsave(&ei_local->page_lock,flags);
        !          1762:        /* Read the counter registers, assuming we are in page 0. */
        !          1763:        ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
        !          1764:        ei_local->stat.rx_crc_errors   += inb_p(ioaddr + EN0_COUNTER1);
        !          1765:        ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
        !          1766:        spin_unlock_irqrestore(&ei_local->page_lock, flags);
        !          1767:     
        !          1768:        return &ei_local->stat;
        !          1769: }
        !          1770: 
        !          1771: /**
        !          1772:  * do_set_multicast_list - set/clear multicast filter
        !          1773:  * @dev: net device for which multicast filter is adjusted
        !          1774:  *
        !          1775:  *     Set or clear the multicast filter for this adaptor. May be called
        !          1776:  *     from a BH in 2.1.x. Must be called with lock held. 
        !          1777:  */
        !          1778:  
        !          1779: static void do_set_multicast_list(struct net_device *dev)
        !          1780: {
        !          1781:        long e8390_base = dev->base_addr;
        !          1782: 
        !          1783:        if(dev->flags&IFF_PROMISC)
        !          1784:                outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR);
        !          1785:        else if(dev->flags&IFF_ALLMULTI || dev->mc_list)
        !          1786:                outb_p(E8390_RXCONFIG | 0x48, e8390_base + EN0_RXCR);
        !          1787:        else
        !          1788:                outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR);
        !          1789: }
        !          1790: 
        !          1791: /*
        !          1792:  *     Called without lock held. This is invoked from user context and may
        !          1793:  *     be parallel to just about everything else. Its also fairly quick and
        !          1794:  *     not called too often. Must protect against both bh and irq users
        !          1795:  */
        !          1796: 
        !          1797: static void set_multicast_list(struct net_device *dev)
        !          1798: {
        !          1799:        unsigned long flags;
        !          1800: 
        !          1801:        spin_lock_irqsave(&dev_lock(dev), flags);
        !          1802:        do_set_multicast_list(dev);
        !          1803:        spin_unlock_irqrestore(&dev_lock(dev), flags);
        !          1804: }      
        !          1805: 
        !          1806: /**
        !          1807:  * axdev_init - init rest of 8390 device struct
        !          1808:  * @dev: network device structure to init
        !          1809:  *
        !          1810:  * Initialize the rest of the 8390 device structure.  Do NOT __init
        !          1811:  * this, as it is used by 8390 based modular drivers too.
        !          1812:  */
        !          1813: 
        !          1814: static int axdev_init(struct net_device *dev)
        !          1815: {
        !          1816:        if (ei_debug > 1)
        !          1817:                printk(version_8390);
        !          1818:     
        !          1819:        if (dev->priv == NULL) 
        !          1820:        {
        !          1821:                struct ei_device *ei_local;
        !          1822:                
        !          1823:                dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
        !          1824:                if (dev->priv == NULL)
        !          1825:                        return -ENOMEM;
        !          1826:                memset(dev->priv, 0, sizeof(struct ei_device));
        !          1827:                ei_local = (struct ei_device *)dev->priv;
        !          1828:                spin_lock_init(&ei_local->page_lock);
        !          1829:        }
        !          1830:     
        !          1831:        dev->hard_start_xmit = &ei_start_xmit;
        !          1832:        dev->get_stats  = get_stats;
        !          1833:        dev->set_multicast_list = &set_multicast_list;
        !          1834: 
        !          1835:        ether_setup(dev);
        !          1836:         
        !          1837:        return 0;
        !          1838: }
        !          1839: 
        !          1840: /* This page of functions should be 8390 generic */
        !          1841: /* Follow National Semi's recommendations for initializing the "NIC". */
        !          1842: 
        !          1843: /**
        !          1844:  * AX88190_init - initialize 8390 hardware
        !          1845:  * @dev: network device to initialize
        !          1846:  * @startp: boolean.  non-zero value to initiate chip processing
        !          1847:  *
        !          1848:  *     Must be called with lock held.
        !          1849:  */
        !          1850: 
        !          1851: static void AX88190_init(struct net_device *dev, int startp)
        !          1852: {
        !          1853:        axnet_dev_t *info = (axnet_dev_t *)dev;
        !          1854:        long e8390_base = dev->base_addr;
        !          1855:        struct ei_device *ei_local = (struct ei_device *) dev->priv;
        !          1856:        int i;
        !          1857:        int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
        !          1858:     
        !          1859:        if(sizeof(struct e8390_pkt_hdr)!=4)
        !          1860:                panic("8390.c: header struct mispacked\n");    
        !          1861:        /* Follow National Semi's recommendations for initing the DP83902. */
        !          1862:        outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */
        !          1863:        outb_p(endcfg, e8390_base + EN0_DCFG);  /* 0x48 or 0x49 */
        !          1864:        /* Clear the remote byte count registers. */
        !          1865:        outb_p(0x00,  e8390_base + EN0_RCNTLO);
        !          1866:        outb_p(0x00,  e8390_base + EN0_RCNTHI);
        !          1867:        /* Set to monitor and loopback mode -- this is vital!. */
        !          1868:        outb_p(E8390_RXOFF|0x40, e8390_base + EN0_RXCR); /* 0x60 */
        !          1869:        outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
        !          1870:        /* Set the transmit page and receive ring. */
        !          1871:        outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
        !          1872:        ei_local->tx1 = ei_local->tx2 = 0;
        !          1873:        outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
        !          1874:        outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY);       /* 3c503 says 0x3f,NS0x26*/
        !          1875:        ei_local->current_page = ei_local->rx_start_page;               /* assert boundary+1 */
        !          1876:        outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
        !          1877:        /* Clear the pending interrupts and mask. */
        !          1878:        outb_p(0xFF, e8390_base + EN0_ISR);
        !          1879:        outb_p(0x00,  e8390_base + EN0_IMR);
        !          1880:     
        !          1881:        /* Copy the station address into the DS8390 registers. */
        !          1882: 
        !          1883:        outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD); /* 0x61 */
        !          1884:        for(i = 0; i < 6; i++) 
        !          1885:        {
        !          1886:                outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i));
        !          1887:                if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
        !          1888:                        printk(KERN_ERR "Hw. address read/write mismap %d\n",i);
        !          1889:        }
        !          1890:        /*
        !          1891:         * Initialize the multicast list to accept-all.  If we enable multicast
        !          1892:         * the higher levels can do the filtering.
        !          1893:         */
        !          1894:        for (i = 0; i < 8; i++)
        !          1895:                outb_p(0xff, e8390_base + EN1_MULT + i);
        !          1896: 
        !          1897:        outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
        !          1898:        outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
        !          1899: 
        !          1900:        netif_start_queue(dev);
        !          1901:        ei_local->tx1 = ei_local->tx2 = 0;
        !          1902:        ei_local->txing = 0;
        !          1903: 
        !          1904:        if (startp) 
        !          1905:        {
        !          1906:                outb_p(0xff,  e8390_base + EN0_ISR);
        !          1907:                outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
        !          1908:                outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
        !          1909:                outb_p(E8390_TXCONFIG | info->duplex_flag,
        !          1910:                       e8390_base + EN0_TXCR); /* xmit on. */
        !          1911:                /* 3c503 TechMan says rxconfig only after the NIC is started. */
        !          1912:                outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR); /* rx on, */
        !          1913:                do_set_multicast_list(dev);     /* (re)load the mcast table */
        !          1914:        }
        !          1915: }
        !          1916: 
        !          1917: /* Trigger a transmit start, assuming the length is valid. 
        !          1918:    Always called with the page lock held */
        !          1919:    
        !          1920: static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
        !          1921:                                                                int start_page)
        !          1922: {
        !          1923:        long e8390_base = dev->base_addr;
        !          1924:        struct ei_device *ei_local __attribute((unused)) = (struct ei_device *) dev->priv;
        !          1925:     
        !          1926:        if (inb_p(e8390_base) & E8390_TRANS) 
        !          1927:        {
        !          1928:                printk(KERN_WARNING "%s: trigger_send() called with the transmitter busy.\n",
        !          1929:                        dev->name);
        !          1930:                return;
        !          1931:        }
        !          1932:        outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
        !          1933:        outb_p(length >> 8, e8390_base + EN0_TCNTHI);
        !          1934:        outb_p(start_page, e8390_base + EN0_TPSR);
        !          1935:        outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD);
        !          1936: }

unix.superglobalmegacorp.com

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