Annotation of Gnu-Mach/linux/src/drivers/net/ns820.c, revision 1.1

1.1     ! root        1: /* ns820.c: A Linux Gigabit Ethernet driver for the NatSemi DP83820 series. */
        !             2: /*
        !             3:        Written/copyright 1999-2003 by Donald Becker.
        !             4:        Copyright 2002-2003 by Scyld Computing Corporation.
        !             5: 
        !             6:        This software may be used and distributed according to the terms of
        !             7:        the GNU General Public License (GPL), incorporated herein by reference.
        !             8:        Drivers based on or derived from this code fall under the GPL and must
        !             9:        retain the authorship, copyright and license notice.  This file is not
        !            10:        a complete program and may only be used when the entire operating
        !            11:        system is licensed under the GPL.  License for under other terms may be
        !            12:        available.  Contact the original author for details.
        !            13: 
        !            14:        The original author may be reached as [email protected], or at
        !            15:        Scyld Computing Corporation
        !            16:        914 Bay Ridge Road, Suite 220
        !            17:        Annapolis MD 21403
        !            18: 
        !            19:        Support information and updates available at
        !            20:                http://www.scyld.com/network/natsemi.html
        !            21:        The information and support mailing lists are based at
        !            22:                http://www.scyld.com/mailman/listinfo/
        !            23: */
        !            24: 
        !            25: /* These identify the driver base version and may not be removed. */
        !            26: static const char version1[] =
        !            27: "ns820.c:v1.03a 8/09/2003  Written by Donald Becker <[email protected]>\n";
        !            28: static const char version2[] =
        !            29: "  http://www.scyld.com/network/natsemi.html\n";
        !            30: /* Updated to recommendations in pci-skeleton v2.13. */
        !            31: 
        !            32: /* Automatically extracted configuration info:
        !            33: probe-func: ns820_probe
        !            34: config-in: tristate 'National Semiconductor DP8382x series PCI Ethernet support' CONFIG_NATSEMI820
        !            35: 
        !            36: c-help-name: National Semiconductor DP8382x series PCI Ethernet support
        !            37: c-help-symbol: CONFIG_NATSEMI820
        !            38: c-help: This driver is for the National Semiconductor DP83820 Gigabit Ethernet
        !            39: c-help: adapter series.
        !            40: c-help: More specific information and updates are available from
        !            41: c-help: http://www.scyld.com/network/natsemi.html
        !            42: */
        !            43: 
        !            44: /* The user-configurable values.
        !            45:    These may be modified when a driver module is loaded.*/
        !            46: 
        !            47: /* Message enable level: 0..31 = no..all messages.  See NETIF_MSG docs. */
        !            48: static int debug = 2;
        !            49: 
        !            50: /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
        !            51: static int max_interrupt_work = 20;
        !            52: 
        !            53: /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
        !            54:    This chip uses a 2048 element hash table based on the Ethernet CRC.
        !            55:    Previous natsemi chips had unreliable multicast filter circuitry.
        !            56:    To work around an observed problem set this value to '0',
        !            57:    which will immediately switch to Rx-all-multicast.
        !            58:   */
        !            59: static int multicast_filter_limit = 100;
        !            60: 
        !            61: /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
        !            62:    Setting to > 1518 effectively disables this feature.
        !            63:    This chip can only receive into aligned buffers, so architectures such
        !            64:    as the Alpha AXP might benefit from a copy-align.
        !            65: */
        !            66: static int rx_copybreak = 0;
        !            67: 
        !            68: /* Used to pass the media type, etc.
        !            69:    Both 'options[]' and 'full_duplex[]' should exist for driver
        !            70:    interoperability, however setting full_duplex[] is deprecated.
        !            71:    The media type is usually passed in 'options[]'.
        !            72:     The default is autonegotation for speed and duplex.
        !            73:        This should rarely be overridden.
        !            74:     Use option values 0x10/0x20 for 10Mbps, 0x100,0x200 for 100Mbps.
        !            75:     Use option values 0x10 and 0x100 for forcing half duplex fixed speed.
        !            76:     Use option values 0x20 and 0x200 for forcing full duplex operation.
        !            77:        Use 0x1000 or 0x2000 for gigabit.
        !            78: */
        !            79: #define MAX_UNITS 8            /* More are supported, limit only on options */
        !            80: static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
        !            81: static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
        !            82: 
        !            83: /* Operational parameters that are set at compile time. */
        !            84: 
        !            85: /* Keep the ring sizes a power of two for compile efficiency.
        !            86:    Understand the implications before changing these settings!
        !            87:    The compiler will convert <unsigned>'%'<2^N> into a bit mask.
        !            88:    Making the Tx ring too large decreases the effectiveness of channel
        !            89:    bonding and packet priority, confuses the system network buffer limits,
        !            90:    and wastes memory.
        !            91:    Too-large receive rings waste memory and confound network buffer limits.
        !            92: */
        !            93: #define TX_RING_SIZE   16
        !            94: #define TX_QUEUE_LEN   10              /* Limit ring entries actually used, min 4. */
        !            95: #define RX_RING_SIZE   64
        !            96: 
        !            97: /* Operational parameters that usually are not changed. */
        !            98: /* Time in jiffies before concluding the transmitter is hung.
        !            99:    Re-autonegotiation may take up to 3 seconds.
        !           100:  */
        !           101: #define TX_TIMEOUT  (6*HZ)
        !           102: 
        !           103: /* Allocation size of Rx buffers with normal sized Ethernet frames.
        !           104:    Do not change this value without good reason.  This is not a limit,
        !           105:    but a way to keep a consistent allocation size among drivers.
        !           106:  */
        !           107: #define PKT_BUF_SZ             1536
        !           108: 
        !           109: #ifndef __KERNEL__
        !           110: #define __KERNEL__
        !           111: #endif
        !           112: #if !defined(__OPTIMIZE__)
        !           113: #warning  You must compile this file with the correct options!
        !           114: #warning  See the last lines of the source file.
        !           115: #error You must compile this driver with "-O".
        !           116: #endif
        !           117: 
        !           118: /* Include files, designed to support most kernel versions 2.0.0 and later. */
        !           119: #include <linux/config.h>
        !           120: #if defined(CONFIG_SMP) && ! defined(__SMP__)
        !           121: #define __SMP__
        !           122: #endif
        !           123: #if defined(MODULE) && defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
        !           124: #define MODVERSIONS
        !           125: #endif
        !           126: 
        !           127: #include <linux/version.h>
        !           128: #if defined(MODVERSIONS)
        !           129: #include <linux/modversions.h>
        !           130: #endif
        !           131: #include <linux/module.h>
        !           132: 
        !           133: #include <linux/kernel.h>
        !           134: #include <linux/string.h>
        !           135: #include <linux/timer.h>
        !           136: #include <linux/errno.h>
        !           137: #include <linux/ioport.h>
        !           138: #if LINUX_VERSION_CODE >= 0x20400
        !           139: #include <linux/slab.h>
        !           140: #else
        !           141: #include <linux/malloc.h>
        !           142: #endif
        !           143: #include <linux/interrupt.h>
        !           144: #include <linux/pci.h>
        !           145: #include <linux/netdevice.h>
        !           146: #include <linux/etherdevice.h>
        !           147: #include <linux/skbuff.h>
        !           148: #include <asm/processor.h>             /* Processor type for cache alignment. */
        !           149: #include <asm/bitops.h>
        !           150: #include <asm/io.h>
        !           151: 
        !           152: #ifdef INLINE_PCISCAN
        !           153: #include "k_compat.h"
        !           154: #else
        !           155: #include "pci-scan.h"
        !           156: #include "kern_compat.h"
        !           157: #endif
        !           158: 
        !           159: #if (LINUX_VERSION_CODE >= 0x20100)  &&  defined(MODULE)
        !           160: char kernel_version[] = UTS_RELEASE;
        !           161: #endif
        !           162: 
        !           163: MODULE_AUTHOR("Donald Becker <[email protected]>");
        !           164: MODULE_DESCRIPTION("National Semiconductor DP83820 series PCI Ethernet driver");
        !           165: MODULE_LICENSE("GPL");
        !           166: MODULE_PARM(debug, "i");
        !           167: MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !           168: MODULE_PARM(max_interrupt_work, "i");
        !           169: MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !           170: MODULE_PARM(rx_copybreak, "i");
        !           171: MODULE_PARM(multicast_filter_limit, "i");
        !           172: MODULE_PARM_DESC(debug, "Driver message level (0-31)");
        !           173: MODULE_PARM_DESC(options, "Force transceiver type or fixed speed+duplex");
        !           174: MODULE_PARM_DESC(max_interrupt_work,
        !           175:                                 "Driver maximum events handled per interrupt");
        !           176: MODULE_PARM_DESC(full_duplex,
        !           177:                                 "Non-zero to force full duplex, non-negotiated link "
        !           178:                                 "(deprecated).");
        !           179: MODULE_PARM_DESC(rx_copybreak,
        !           180:                                 "Breakpoint in bytes for copy-only-tiny-frames");
        !           181: MODULE_PARM_DESC(multicast_filter_limit,
        !           182:                                 "Multicast addresses before switching to Rx-all-multicast");
        !           183: 
        !           184: /*
        !           185:                                Theory of Operation
        !           186: 
        !           187: I. Board Compatibility
        !           188: 
        !           189: This driver is designed for National Semiconductor DP83820 10/100/1000
        !           190: Ethernet NIC.  It is superficially similar to the 810 series "natsemi.c"
        !           191: driver, however the register layout, descriptor layout and element
        !           192: length of the new chip series is different.
        !           193: 
        !           194: II. Board-specific settings
        !           195: 
        !           196: This driver requires the PCI interrupt line to be configured.
        !           197: It honors the EEPROM-set values.
        !           198: 
        !           199: III. Driver operation
        !           200: 
        !           201: IIIa. Ring buffers
        !           202: 
        !           203: This driver uses two statically allocated fixed-size descriptor lists
        !           204: formed into rings by a branch from the final descriptor to the beginning of
        !           205: the list.  The ring sizes are set at compile time by RX/TX_RING_SIZE.
        !           206: The NatSemi design uses a 'next descriptor' pointer that the driver forms
        !           207: into a list, thus rings can be arbitrarily sized.  Before changing the
        !           208: ring sizes you should understand the flow and cache effects of the
        !           209: full/available/empty hysteresis.
        !           210: 
        !           211: IIIb/c. Transmit/Receive Structure
        !           212: 
        !           213: This driver uses a zero-copy receive and transmit scheme.
        !           214: The driver allocates full frame size skbuffs for the Rx ring buffers at
        !           215: open() time and passes the skb->data field to the chip as receive data
        !           216: buffers.  When an incoming frame is less than RX_COPYBREAK bytes long,
        !           217: a fresh skbuff is allocated and the frame is copied to the new skbuff.
        !           218: When the incoming frame is larger, the skbuff is passed directly up the
        !           219: protocol stack.  Buffers consumed this way are replaced by newly allocated
        !           220: skbuffs in a later phase of receives.
        !           221: 
        !           222: The RX_COPYBREAK value is chosen to trade-off the memory wasted by
        !           223: using a full-sized skbuff for small frames vs. the copying costs of larger
        !           224: frames.  New boards are typically used in generously configured machines
        !           225: and the underfilled buffers have negligible impact compared to the benefit of
        !           226: a single allocation size, so the default value of zero results in never
        !           227: copying packets.  When copying is done, the cost is usually mitigated by using
        !           228: a combined copy/checksum routine.  Copying also preloads the cache, which is
        !           229: most useful with small frames.
        !           230: 
        !           231: A subtle aspect of the operation is that unaligned buffers are not permitted
        !           232: by the hardware.  Thus the IP header at offset 14 in an ethernet frame isn't
        !           233: longword aligned for further processing.  On copies frames are put into the
        !           234: skbuff at an offset of "+2", 16-byte aligning the IP header.
        !           235: 
        !           236: IIId. Synchronization
        !           237: 
        !           238: The driver runs as two independent, single-threaded flows of control.  One
        !           239: is the send-packet routine, which enforces single-threaded use by the
        !           240: dev->tbusy flag.  The other thread is the interrupt handler, which is single
        !           241: threaded by the hardware and interrupt handling software.
        !           242: 
        !           243: The send packet thread has partial control over the Tx ring and 'dev->tbusy'
        !           244: flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
        !           245: queue slot is empty, it clears the tbusy flag when finished otherwise it sets
        !           246: the 'lp->tx_full' flag.
        !           247: 
        !           248: The interrupt handler has exclusive control over the Rx ring and records stats
        !           249: from the Tx ring.  After reaping the stats, it marks the Tx queue entry as
        !           250: empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
        !           251: clears both the tx_full and tbusy flags.
        !           252: 
        !           253: IV. Notes
        !           254: 
        !           255: The NatSemi 820 series PCI gigabit chips are very common on low-cost NICs.
        !           256: The '821 appears to be the same as '820 chip, only with pins for the upper
        !           257: 32 bits marked "N/C".
        !           258: 
        !           259: IVb. References
        !           260: 
        !           261: http://www.scyld.com/expert/100mbps.html
        !           262: http://www.scyld.com/expert/NWay.html
        !           263: The NatSemi dp83820 datasheet is available: search www.natsemi.com
        !           264: 
        !           265: IVc. Errata
        !           266: 
        !           267: None characterised.
        !           268: 
        !           269: */
        !           270: 
        !           271: 
        !           272: 
        !           273: static void *ns820_probe1(struct pci_dev *pdev, void *init_dev,
        !           274:                                                        long ioaddr, int irq, int chip_idx, int find_cnt);
        !           275: static int power_event(void *dev_instance, int event);
        !           276: enum chip_capability_flags {FDXActiveLow=1, InvertGbXcvrPwr=2, };
        !           277: #ifdef USE_IO_OPS
        !           278: #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_IO  | PCI_ADDR0)
        !           279: #else
        !           280: #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR1)
        !           281: #endif
        !           282: 
        !           283: static struct pci_id_info pci_id_tbl[] = {
        !           284:        { "D-Link DGE-500T (DP83820)",
        !           285:          { 0x0022100B, 0xffffffff, 0x49001186, 0xffffffff, },
        !           286:          PCI_IOTYPE, 256, FDXActiveLow},
        !           287:        {"NatSemi DP83820", { 0x0022100B, 0xffffffff },
        !           288:         PCI_IOTYPE, 256, 0},
        !           289:        {0,},                                           /* 0 terminated list. */
        !           290: };
        !           291: 
        !           292: struct drv_id_info ns820_drv_id = {
        !           293:        "ns820", PCI_HOTSWAP, PCI_CLASS_NETWORK_ETHERNET<<8, pci_id_tbl,
        !           294:        ns820_probe1, power_event };
        !           295: 
        !           296: /* Offsets to the device registers.
        !           297:    Unlike software-only systems, device drivers interact with complex hardware.
        !           298:    It's not useful to define symbolic names for every register bit in the
        !           299:    device.  Please do not change these names without good reason.
        !           300: */
        !           301: enum register_offsets {
        !           302:        ChipCmd=0x00, ChipConfig=0x04, EECtrl=0x08, PCIBusCfg=0x0C,
        !           303:        IntrStatus=0x10, IntrMask=0x14, IntrEnable=0x18, IntrHoldoff=0x1C,
        !           304:        TxRingPtr=0x20, TxRingPtrHi=0x24, TxConfig=0x28,
        !           305:        RxRingPtr=0x30, RxRingPtrHi=0x34, RxConfig=0x38,
        !           306:        WOLCmd=0x40, PauseCmd=0x44, RxFilterAddr=0x48, RxFilterData=0x4C,
        !           307:        BootRomAddr=0x50, BootRomData=0x54, ChipRevReg=0x58,
        !           308:        StatsCtrl=0x5C, RxPktErrs=0x60, RxMissed=0x68, RxCRCErrs=0x64,
        !           309: };
        !           310: 
        !           311: /* Bits in ChipCmd. */
        !           312: enum ChipCmdBits {
        !           313:        ChipReset=0x100, SoftIntr=0x80, RxReset=0x20, TxReset=0x10,
        !           314:        RxOff=0x08, RxOn=0x04, TxOff=0x02, TxOn=0x01,
        !           315: };
        !           316: 
        !           317: /* Bits in ChipConfig. */
        !           318: enum ChipConfigBits {
        !           319:        CfgLinkGood=0x80000000, CfgFDX=0x10000000,
        !           320:        CfgXcrReset=0x0400, CfgXcrOff=0x0200,
        !           321: };
        !           322: 
        !           323: /* Bits in the interrupt status/mask registers. */
        !           324: enum intr_status_bits {
        !           325:        IntrRxDone=0x0001, IntrRxIntr=0x0002, IntrRxErr=0x0004, IntrRxEarly=0x0008,
        !           326:        IntrRxIdle=0x0010, IntrRxOverrun=0x0020,
        !           327:        IntrTxDone=0x0040, IntrTxIntr=0x0080, IntrTxErr=0x0100,
        !           328:        IntrTxIdle=0x0200, IntrTxUnderrun=0x0400,
        !           329:        StatsMax=0x0800, IntrDrv=0x1000, WOLPkt=0x2000, LinkChange=0x4000,
        !           330:        RxStatusOverrun=0x10000,
        !           331:        RxResetDone=0x00200000, TxResetDone=0x00400000,
        !           332:        IntrPCIErr=0x001E0000,
        !           333:        IntrNormalSummary=0x0251, IntrAbnormalSummary=0xED20,
        !           334: };
        !           335: 
        !           336: /* Bits in the RxMode register. */
        !           337: enum rx_mode_bits {
        !           338:        AcceptErr=0x20, AcceptRunt=0x10,
        !           339:        AcceptBroadcast=0xC0000000,
        !           340:        AcceptMulticast=0x00200000, AcceptAllMulticast=0x20000000,
        !           341:        AcceptAllPhys=0x10000000, AcceptMyPhys=0x08000000,
        !           342: };
        !           343: 
        !           344: /* The Rx and Tx buffer descriptors. */
        !           345: /* Note that using only 32 bit fields simplifies conversion to big-endian
        !           346:    architectures. */
        !           347: struct netdev_desc {
        !           348: #if ADDRLEN == 64
        !           349:        u64 next_desc;
        !           350:        u64 buf_addr;
        !           351: #endif
        !           352:        u32 next_desc;
        !           353:        u32 buf_addr;
        !           354:        s32 cmd_status;
        !           355:        u32 vlan_status;
        !           356: };
        !           357: 
        !           358: /* Bits in network_desc.status */
        !           359: enum desc_status_bits {
        !           360:        DescOwn=0x80000000, DescMore=0x40000000, DescIntr=0x20000000,
        !           361:        DescNoCRC=0x10000000,
        !           362:        DescPktOK=0x08000000, RxTooLong=0x00400000,
        !           363: };
        !           364: 
        !           365: #define PRIV_ALIGN     15      /* Required alignment mask */
        !           366: struct netdev_private {
        !           367:        /* Descriptor rings first for alignment. */
        !           368:        struct netdev_desc rx_ring[RX_RING_SIZE];
        !           369:        struct netdev_desc tx_ring[TX_RING_SIZE];
        !           370:        struct net_device *next_module;         /* Link for devices of this type. */
        !           371:        void *priv_addr;                                        /* Unaligned address for kfree */
        !           372:        const char *product_name;
        !           373:        /* The addresses of receive-in-place skbuffs. */
        !           374:        struct sk_buff* rx_skbuff[RX_RING_SIZE];
        !           375:        /* The saved address of a sent-in-place packet/buffer, for later free(). */
        !           376:        struct sk_buff* tx_skbuff[TX_RING_SIZE];
        !           377:        struct net_device_stats stats;
        !           378:        struct timer_list timer;        /* Media monitoring timer. */
        !           379:        /* Frequently used values: keep some adjacent for cache effect. */
        !           380:        int msg_level;
        !           381:        int chip_id, drv_flags;
        !           382:        struct pci_dev *pci_dev;
        !           383:        long in_interrupt;                      /* Word-long for SMP locks. */
        !           384:        int max_interrupt_work;
        !           385:        int intr_enable;
        !           386:        unsigned int restore_intr_enable:1;     /* Set if temporarily masked.  */
        !           387:        unsigned int rx_q_empty:1;                      /* Set out-of-skbuffs.  */
        !           388: 
        !           389:        struct netdev_desc *rx_head_desc;
        !           390:        unsigned int cur_rx, dirty_rx;          /* Producer/consumer ring indices */
        !           391:        unsigned int rx_buf_sz;                         /* Based on MTU+slack. */
        !           392:        int rx_copybreak;
        !           393: 
        !           394:        unsigned int cur_tx, dirty_tx;
        !           395:        unsigned int tx_full:1;                         /* The Tx queue is full. */
        !           396:        /* These values keep track of the transceiver/media in use. */
        !           397:        unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
        !           398:        unsigned int duplex_lock:1;
        !           399:        unsigned int medialock:1;                       /* Do not sense media. */
        !           400:        unsigned int default_port;                      /* Last dev->if_port value. */
        !           401:        /* Rx filter. */
        !           402:        u32 cur_rx_mode;
        !           403:        u32 rx_filter[16];
        !           404:        int multicast_filter_limit;
        !           405:        /* FIFO and PCI burst thresholds. */
        !           406:        int tx_config, rx_config;
        !           407:        /* MII transceiver section. */
        !           408:        u16 advertising;                                        /* NWay media advertisement */
        !           409: };
        !           410: 
        !           411: static int  eeprom_read(long ioaddr, int location);
        !           412: static void mdio_sync(long mdio_addr);
        !           413: static int  mdio_read(struct net_device *dev, int phy_id, int location);
        !           414: static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
        !           415: static int  netdev_open(struct net_device *dev);
        !           416: static void check_duplex(struct net_device *dev);
        !           417: static void netdev_timer(unsigned long data);
        !           418: static void tx_timeout(struct net_device *dev);
        !           419: static int  rx_ring_fill(struct net_device *dev);
        !           420: static void init_ring(struct net_device *dev);
        !           421: static int  start_tx(struct sk_buff *skb, struct net_device *dev);
        !           422: static void intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
        !           423: static void netdev_error(struct net_device *dev, int intr_status);
        !           424: static int  netdev_rx(struct net_device *dev);
        !           425: static void netdev_error(struct net_device *dev, int intr_status);
        !           426: static void set_rx_mode(struct net_device *dev);
        !           427: static struct net_device_stats *get_stats(struct net_device *dev);
        !           428: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
        !           429: static int  netdev_close(struct net_device *dev);
        !           430: 
        !           431: 
        !           432: 
        !           433: /* A list of our installed devices, for removing the driver module. */
        !           434: static struct net_device *root_net_dev = NULL;
        !           435: 
        !           436: #ifndef MODULE
        !           437: int ns820_probe(struct net_device *dev)
        !           438: {
        !           439:        if (pci_drv_register(&ns820_drv_id, dev) < 0)
        !           440:                return -ENODEV;
        !           441:        printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
        !           442:        return 0;
        !           443: }
        !           444: #endif
        !           445: 
        !           446: static void *ns820_probe1(struct pci_dev *pdev, void *init_dev,
        !           447:                                                  long ioaddr, int irq, int chip_idx, int card_idx)
        !           448: {
        !           449:        struct net_device *dev;
        !           450:        struct netdev_private *np;
        !           451:        void *priv_mem;
        !           452:        int i, option = card_idx < MAX_UNITS ? options[card_idx] : 0;
        !           453: 
        !           454:        dev = init_etherdev(init_dev, 0);
        !           455:        if (!dev)
        !           456:                return NULL;
        !           457: 
        !           458:        /* Perhaps NETIF_MSG_PROBE */
        !           459:        printk(KERN_INFO "%s: %s at 0x%lx, ",
        !           460:                   dev->name, pci_id_tbl[chip_idx].name, ioaddr);
        !           461: 
        !           462:        for (i = 0; i < 3; i++)
        !           463:                ((u16 *)dev->dev_addr)[i] = le16_to_cpu(eeprom_read(ioaddr, 12 - i));
        !           464:        for (i = 0; i < 5; i++)
        !           465:                printk("%2.2x:", dev->dev_addr[i]);
        !           466:        printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
        !           467: 
        !           468:        /* Reset the chip to erase previous misconfiguration. */
        !           469:        writel(ChipReset, ioaddr + ChipCmd);
        !           470:        /* Power up Xcvr. */
        !           471:        writel(~CfgXcrOff & readl(ioaddr + ChipConfig), ioaddr + ChipConfig);
        !           472: 
        !           473:        /* Make certain elements e.g. descriptor lists are aligned. */
        !           474:        priv_mem = kmalloc(sizeof(*np) + PRIV_ALIGN, GFP_KERNEL);
        !           475:        /* Check for the very unlikely case of no memory. */
        !           476:        if (priv_mem == NULL)
        !           477:                return NULL;
        !           478: 
        !           479:        dev->base_addr = ioaddr;
        !           480:        dev->irq = irq;
        !           481: 
        !           482:        dev->priv = np = (void *)(((long)priv_mem + PRIV_ALIGN) & ~PRIV_ALIGN);
        !           483:        memset(np, 0, sizeof(*np));
        !           484:        np->priv_addr = priv_mem;
        !           485: 
        !           486:        np->next_module = root_net_dev;
        !           487:        root_net_dev = dev;
        !           488: 
        !           489:        np->pci_dev = pdev;
        !           490:        np->chip_id = chip_idx;
        !           491:        np->drv_flags = pci_id_tbl[chip_idx].drv_flags;
        !           492:        np->msg_level = (1 << debug) - 1;
        !           493:        np->rx_copybreak = rx_copybreak;
        !           494:        np->max_interrupt_work = max_interrupt_work;
        !           495:        np->multicast_filter_limit = multicast_filter_limit;
        !           496: 
        !           497:        if (dev->mem_start)
        !           498:                option = dev->mem_start;
        !           499: 
        !           500:        /* The lower four bits are the media type. */
        !           501:        if (option > 0) {
        !           502:                if (option & 0x220)
        !           503:                        np->full_duplex = 1;
        !           504:                np->default_port = option & 0x33ff;
        !           505:                if (np->default_port & 0x330)
        !           506:                        np->medialock = 1;
        !           507:        }
        !           508:        if (card_idx < MAX_UNITS  &&  full_duplex[card_idx] > 0)
        !           509:                np->full_duplex = 1;
        !           510: 
        !           511:        if (np->full_duplex) {
        !           512:                if (np->msg_level & NETIF_MSG_PROBE)
        !           513:                        printk(KERN_INFO "%s: Set to forced full duplex, autonegotiation"
        !           514:                                   " disabled.\n", dev->name);
        !           515:                np->duplex_lock = 1;
        !           516:        }
        !           517: 
        !           518:        /* The chip-specific entries in the device structure. */
        !           519:        dev->open = &netdev_open;
        !           520:        dev->hard_start_xmit = &start_tx;
        !           521:        dev->stop = &netdev_close;
        !           522:        dev->get_stats = &get_stats;
        !           523:        dev->set_multicast_list = &set_rx_mode;
        !           524:        dev->do_ioctl = &mii_ioctl;
        !           525: 
        !           526:        /* Allow forcing the media type. */
        !           527:        if (option > 0) {
        !           528:                if (option & 0x220)
        !           529:                        np->full_duplex = 1;
        !           530:                np->default_port = option & 0x3ff;
        !           531:                if (np->default_port & 0x330) {
        !           532:                        np->medialock = 1;
        !           533:                        if (np->msg_level & NETIF_MSG_PROBE)
        !           534:                                printk(KERN_INFO "  Forcing %dMbs %s-duplex operation.\n",
        !           535:                                           (option & 0x300 ? 100 : 10),
        !           536:                                           (np->full_duplex ? "full" : "half"));
        !           537:                        mdio_write(dev, 1, 0,
        !           538:                                           ((option & 0x300) ? 0x2000 : 0) |    /* 100mbps? */
        !           539:                                           (np->full_duplex ? 0x0100 : 0)); /* Full duplex? */
        !           540:                }
        !           541:        }
        !           542: 
        !           543:        return dev;
        !           544: }
        !           545: 
        !           546: 
        !           547: /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.
        !           548:    The EEPROM code is for the common 93c06/46 EEPROMs with 6 bit addresses.
        !           549:    Update to the code in other drivers for 8/10 bit addresses.
        !           550: */
        !           551: 
        !           552: /* Delay between EEPROM clock transitions.
        !           553:    This "delay" forces out buffered PCI writes, which is sufficient to meet
        !           554:    the timing requirements of most EEPROMs.
        !           555: */
        !           556: #define eeprom_delay(ee_addr)  readl(ee_addr)
        !           557: 
        !           558: enum EEPROM_Ctrl_Bits {
        !           559:        EE_ShiftClk=0x04, EE_DataIn=0x01, EE_ChipSelect=0x08, EE_DataOut=0x02,
        !           560: };
        !           561: #define EE_Write0 (EE_ChipSelect)
        !           562: #define EE_Write1 (EE_ChipSelect | EE_DataIn)
        !           563: 
        !           564: /* The EEPROM commands include the 01 preamble. */
        !           565: enum EEPROM_Cmds {
        !           566:        EE_WriteCmd=5, EE_ReadCmd=6, EE_EraseCmd=7,
        !           567: };
        !           568: 
        !           569: static int eeprom_read(long addr, int location)
        !           570: {
        !           571:        long eeprom_addr = addr + EECtrl;
        !           572:        int read_cmd = (EE_ReadCmd << 6) | location;
        !           573:        int retval = 0;
        !           574:        int i;
        !           575: 
        !           576:        writel(EE_Write0, eeprom_addr);
        !           577: 
        !           578:        /* Shift the read command bits out. */
        !           579:        for (i = 10; i >= 0; i--) {
        !           580:                int dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
        !           581:                writel(dataval, eeprom_addr);
        !           582:                eeprom_delay(eeprom_addr);
        !           583:                writel(dataval | EE_ShiftClk, eeprom_addr);
        !           584:                eeprom_delay(eeprom_addr);
        !           585:        }
        !           586:        writel(EE_ChipSelect, eeprom_addr);
        !           587:        eeprom_delay(eeprom_addr);
        !           588: 
        !           589:        for (i = 15; i >= 0; i--) {
        !           590:                writel(EE_ChipSelect | EE_ShiftClk, eeprom_addr);
        !           591:                eeprom_delay(eeprom_addr);
        !           592:                retval |= (readl(eeprom_addr) & EE_DataOut) ? 1 << i : 0;
        !           593:                writel(EE_ChipSelect, eeprom_addr);
        !           594:                eeprom_delay(eeprom_addr);
        !           595:        }
        !           596: 
        !           597:        /* Terminate the EEPROM access. */
        !           598:        writel(EE_Write0, eeprom_addr);
        !           599:        writel(0, eeprom_addr);
        !           600:        return retval;
        !           601: }
        !           602: 
        !           603: /*  MII transceiver control section.
        !           604:        Read and write MII registers using software-generated serial MDIO
        !           605:        protocol.  See the MII specifications or DP83840A data sheet for details.
        !           606: 
        !           607:        The maximum data clock rate is 2.5 Mhz.  To meet minimum timing we
        !           608:        must flush writes to the PCI bus with a PCI read. */
        !           609: #define mdio_delay(mdio_addr) readl(mdio_addr)
        !           610: 
        !           611: /* Set iff a MII transceiver on any interface requires mdio preamble.
        !           612:    This only set with older tranceivers, so the extra
        !           613:    code size of a per-interface flag is not worthwhile. */
        !           614: static char mii_preamble_required = 0;
        !           615: 
        !           616: enum mii_reg_bits {
        !           617:        MDIO_ShiftClk=0x0040, MDIO_Data=0x0010, MDIO_EnbOutput=0x0020,
        !           618: };
        !           619: #define MDIO_EnbIn  (0)
        !           620: #define MDIO_WRITE0 (MDIO_EnbOutput)
        !           621: #define MDIO_WRITE1 (MDIO_Data | MDIO_EnbOutput)
        !           622: 
        !           623: /* Generate the preamble required for initial synchronization and
        !           624:    a few older transceivers. */
        !           625: static void mdio_sync(long mdio_addr)
        !           626: {
        !           627:        int bits = 32;
        !           628: 
        !           629:        /* Establish sync by sending at least 32 logic ones. */
        !           630:        while (--bits >= 0) {
        !           631:                writel(MDIO_WRITE1, mdio_addr);
        !           632:                mdio_delay(mdio_addr);
        !           633:                writel(MDIO_WRITE1 | MDIO_ShiftClk, mdio_addr);
        !           634:                mdio_delay(mdio_addr);
        !           635:        }
        !           636: }
        !           637: 
        !           638: static int mdio_read(struct net_device *dev, int phy_id, int location)
        !           639: {
        !           640:        long mdio_addr = dev->base_addr + EECtrl;
        !           641:        int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
        !           642:        int i, retval = 0;
        !           643: 
        !           644:        if (mii_preamble_required)
        !           645:                mdio_sync(mdio_addr);
        !           646: 
        !           647:        /* Shift the read command bits out. */
        !           648:        for (i = 15; i >= 0; i--) {
        !           649:                int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
        !           650: 
        !           651:                writel(dataval, mdio_addr);
        !           652:                mdio_delay(mdio_addr);
        !           653:                writel(dataval | MDIO_ShiftClk, mdio_addr);
        !           654:                mdio_delay(mdio_addr);
        !           655:        }
        !           656:        /* Read the two transition, 16 data, and wire-idle bits. */
        !           657:        for (i = 19; i > 0; i--) {
        !           658:                writel(MDIO_EnbIn, mdio_addr);
        !           659:                mdio_delay(mdio_addr);
        !           660:                retval = (retval << 1) | ((readl(mdio_addr) & MDIO_Data) ? 1 : 0);
        !           661:                writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
        !           662:                mdio_delay(mdio_addr);
        !           663:        }
        !           664:        return (retval>>1) & 0xffff;
        !           665: }
        !           666: 
        !           667: static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
        !           668: {
        !           669:        long mdio_addr = dev->base_addr + EECtrl;
        !           670:        int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
        !           671:        int i;
        !           672: 
        !           673:        if (mii_preamble_required)
        !           674:                mdio_sync(mdio_addr);
        !           675: 
        !           676:        /* Shift the command bits out. */
        !           677:        for (i = 31; i >= 0; i--) {
        !           678:                int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
        !           679: 
        !           680:                writel(dataval, mdio_addr);
        !           681:                mdio_delay(mdio_addr);
        !           682:                writel(dataval | MDIO_ShiftClk, mdio_addr);
        !           683:                mdio_delay(mdio_addr);
        !           684:        }
        !           685:        /* Clear out extra bits. */
        !           686:        for (i = 2; i > 0; i--) {
        !           687:                writel(MDIO_EnbIn, mdio_addr);
        !           688:                mdio_delay(mdio_addr);
        !           689:                writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
        !           690:                mdio_delay(mdio_addr);
        !           691:        }
        !           692:        return;
        !           693: }
        !           694: 
        !           695: static int netdev_open(struct net_device *dev)
        !           696: {
        !           697:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           698:        long ioaddr = dev->base_addr;
        !           699:        int i;
        !           700:        u32 intr_status = readl(ioaddr + IntrStatus);
        !           701: 
        !           702:        /* We have not yet encountered a case where we need to reset the chip. */
        !           703: 
        !           704:        MOD_INC_USE_COUNT;
        !           705: 
        !           706:        if (request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev)) {
        !           707:                MOD_DEC_USE_COUNT;
        !           708:                return -EAGAIN;
        !           709:        }
        !           710: 
        !           711:        /* Power up Xcvr. */
        !           712:        writel((~CfgXcrOff & readl(ioaddr + ChipConfig)) | 0x00400000,
        !           713:                   ioaddr + ChipConfig);
        !           714:        if (np->msg_level & NETIF_MSG_IFUP)
        !           715:                printk(KERN_DEBUG "%s: netdev_open() irq %d intr_status %8.8x.\n",
        !           716:                           dev->name, dev->irq, intr_status);
        !           717: 
        !           718:        init_ring(dev);
        !           719: 
        !           720: #if defined(ADDR_64BITS) && defined(__alpha__)
        !           721:        writel(virt_to_bus(np->rx_ring) >> 32, ioaddr + RxRingPtrHi);
        !           722:        writel(virt_to_bus(np->tx_ring) >> 32, ioaddr + TxRingPtrHi);
        !           723: #else
        !           724:        writel(0, ioaddr + RxRingPtrHi);
        !           725:        writel(0, ioaddr + TxRingPtrHi);
        !           726: #endif
        !           727:        writel(virt_to_bus(np->rx_ring), ioaddr + RxRingPtr);
        !           728:        writel(virt_to_bus(np->tx_ring), ioaddr + TxRingPtr);
        !           729: 
        !           730:        for (i = 0; i < 6; i += 2) {
        !           731:                writel(i, ioaddr + RxFilterAddr);
        !           732:                writel(dev->dev_addr[i] + (dev->dev_addr[i+1] << 8),
        !           733:                           ioaddr + RxFilterData);
        !           734:        }
        !           735: 
        !           736:        /* Initialize other registers. */
        !           737:        /* Configure the PCI bus bursts and FIFO thresholds. */
        !           738:        /* Configure for standard, in-spec Ethernet. */
        !           739: 
        !           740:        if (np->full_duplex  ||
        !           741:                ((readl(ioaddr + ChipConfig) & CfgFDX) == 0) ^
        !           742:                ((np->drv_flags & FDXActiveLow) != 0)) {
        !           743:                np->tx_config = 0xD0801002;
        !           744:                np->rx_config = 0x10000020;
        !           745:        } else {
        !           746:                np->tx_config = 0x10801002;
        !           747:                np->rx_config = 0x0020;
        !           748:        }
        !           749:        if (dev->mtu > 1500)
        !           750:                np->rx_config |= 0x08000000;
        !           751:        writel(np->tx_config, ioaddr + TxConfig);
        !           752:        writel(np->rx_config, ioaddr + RxConfig);
        !           753:        if (np->msg_level & NETIF_MSG_IFUP)
        !           754:                printk(KERN_DEBUG "%s: Setting TxConfig to %8.8x.\n",
        !           755:                           dev->name, (int)readl(ioaddr + TxConfig));
        !           756: 
        !           757:        if (dev->if_port == 0)
        !           758:                dev->if_port = np->default_port;
        !           759: 
        !           760:        np->in_interrupt = 0;
        !           761: 
        !           762:        check_duplex(dev);
        !           763:        set_rx_mode(dev);
        !           764:        netif_start_tx_queue(dev);
        !           765: 
        !           766:        /* Enable interrupts by setting the interrupt mask. */
        !           767:        np->intr_enable = IntrNormalSummary | IntrAbnormalSummary | 0x1f;
        !           768:        writel(np->intr_enable, ioaddr + IntrMask);
        !           769:        writel(1, ioaddr + IntrEnable);
        !           770: 
        !           771:        writel(RxOn | TxOn, ioaddr + ChipCmd);
        !           772:        writel(4, ioaddr + StatsCtrl);                                  /* Clear Stats */
        !           773: 
        !           774:        if (np->msg_level & NETIF_MSG_IFUP)
        !           775:                printk(KERN_DEBUG "%s: Done netdev_open(), status: %x.\n",
        !           776:                           dev->name, (int)readl(ioaddr + ChipCmd));
        !           777: 
        !           778:        /* Set the timer to check for link beat. */
        !           779:        init_timer(&np->timer);
        !           780:        np->timer.expires = jiffies + 3*HZ;
        !           781:        np->timer.data = (unsigned long)dev;
        !           782:        np->timer.function = &netdev_timer;                             /* timer handler */
        !           783:        add_timer(&np->timer);
        !           784: 
        !           785:        return 0;
        !           786: }
        !           787: 
        !           788: static void check_duplex(struct net_device *dev)
        !           789: {
        !           790:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           791:        long ioaddr = dev->base_addr;
        !           792:        int duplex;
        !           793: 
        !           794:        if (np->duplex_lock)
        !           795:                return;
        !           796:        duplex = readl(ioaddr + ChipConfig) & CfgFDX ? 1 : 0;
        !           797:        if (np->full_duplex != duplex) {
        !           798:                np->full_duplex = duplex;
        !           799:                if (np->msg_level & NETIF_MSG_LINK)
        !           800:                        printk(KERN_INFO "%s: Setting %s-duplex based on negotiated link"
        !           801:                                   " capability.\n", dev->name,
        !           802:                                   duplex ? "full" : "half");
        !           803:                if (duplex) {
        !           804:                        np->rx_config |= 0x10000000;
        !           805:                        np->tx_config |= 0xC0000000;
        !           806:                } else {
        !           807:                        np->rx_config &= ~0x10000000;
        !           808:                        np->tx_config &= ~0xC0000000;
        !           809:                }
        !           810:                writel(np->tx_config, ioaddr + TxConfig);
        !           811:                writel(np->rx_config, ioaddr + RxConfig);
        !           812:                if (np->msg_level & NETIF_MSG_LINK)
        !           813:                        printk(KERN_DEBUG "%s: Setting TxConfig to %8.8x (%8.8x).\n",
        !           814:                                   dev->name, np->tx_config, (int)readl(ioaddr + TxConfig));
        !           815:        }
        !           816: }
        !           817: 
        !           818: static void netdev_timer(unsigned long data)
        !           819: {
        !           820:        struct net_device *dev = (struct net_device *)data;
        !           821:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           822:        long ioaddr = dev->base_addr;
        !           823:        int next_tick = 10*HZ;
        !           824: 
        !           825:        if (np->msg_level & NETIF_MSG_TIMER)
        !           826:                printk(KERN_DEBUG "%s: Driver monitor timer tick, status %8.8x.\n",
        !           827:                           dev->name, (int)readl(ioaddr + ChipConfig));
        !           828:        if (np->rx_q_empty) {
        !           829:                /* Trigger an interrupt to refill. */
        !           830:                writel(SoftIntr, ioaddr + ChipCmd);
        !           831:        }
        !           832:        if (netif_queue_paused(dev)  &&
        !           833:                np->cur_tx - np->dirty_tx > 1  &&
        !           834:                (jiffies - dev->trans_start) > TX_TIMEOUT) {
        !           835:                tx_timeout(dev);
        !           836:        }
        !           837:        check_duplex(dev);
        !           838:        np->timer.expires = jiffies + next_tick;
        !           839:        add_timer(&np->timer);
        !           840: }
        !           841: 
        !           842: static void tx_timeout(struct net_device *dev)
        !           843: {
        !           844:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           845:        long ioaddr = dev->base_addr;
        !           846: 
        !           847:        printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
        !           848:                   " resetting...\n", dev->name, (int)readl(ioaddr + TxRingPtr));
        !           849: 
        !           850:        if (np->msg_level & NETIF_MSG_TX_ERR) {
        !           851:                int i;
        !           852:                printk(KERN_DEBUG "  Rx ring %p: ", np->rx_ring);
        !           853:                for (i = 0; i < RX_RING_SIZE; i++)
        !           854:                        printk(" %8.8x", (unsigned int)np->rx_ring[i].cmd_status);
        !           855:                printk("\n"KERN_DEBUG"  Tx ring %p: ", np->tx_ring);
        !           856:                for (i = 0; i < TX_RING_SIZE; i++)
        !           857:                        printk(" %4.4x", np->tx_ring[i].cmd_status);
        !           858:                printk("\n");
        !           859:        }
        !           860: 
        !           861:        /* Perhaps we should reinitialize the hardware here. */
        !           862:        dev->if_port = 0;
        !           863:        /* Stop and restart the chip's Tx processes . */
        !           864: 
        !           865:        /* Trigger an immediate transmit demand. */
        !           866: 
        !           867:        dev->trans_start = jiffies;
        !           868:        np->stats.tx_errors++;
        !           869:        return;
        !           870: }
        !           871: 
        !           872: /* Refill the Rx ring buffers, returning non-zero if not full. */
        !           873: static int rx_ring_fill(struct net_device *dev)
        !           874: {
        !           875:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           876:        unsigned int entry;
        !           877: 
        !           878:        for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
        !           879:                entry = np->dirty_rx % RX_RING_SIZE;
        !           880:                if (np->rx_skbuff[entry] == NULL) {
        !           881:                        struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
        !           882:                        np->rx_skbuff[entry] = skb;
        !           883:                        if (skb == NULL)
        !           884:                                return 1;                               /* Better luck next time. */
        !           885:                        skb->dev = dev;                 /* Mark as being used by this device. */
        !           886:                        np->rx_ring[entry].buf_addr = virt_to_bus(skb->tail);
        !           887:                }
        !           888:                np->rx_ring[entry].cmd_status = cpu_to_le32(DescIntr | np->rx_buf_sz);
        !           889:        }
        !           890:        return 0;
        !           891: }
        !           892: 
        !           893: /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
        !           894: static void init_ring(struct net_device *dev)
        !           895: {
        !           896:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           897:        int i;
        !           898: 
        !           899:        np->tx_full = 0;
        !           900:        np->cur_rx = np->cur_tx = 0;
        !           901:        np->dirty_rx = np->dirty_tx = 0;
        !           902: 
        !           903:        /* MAX(PKT_BUF_SZ, dev->mtu + 8); */
        !           904:        /* I know you _want_ to change this without understanding it.  Don't. */
        !           905:        np->rx_buf_sz = (dev->mtu <= 1532 ? PKT_BUF_SZ : dev->mtu + 8);
        !           906:        np->rx_head_desc = &np->rx_ring[0];
        !           907: 
        !           908:        /* Initialize all Rx descriptors. */
        !           909:        for (i = 0; i < RX_RING_SIZE; i++) {
        !           910:                np->rx_ring[i].next_desc = virt_to_bus(&np->rx_ring[i+1]);
        !           911:                np->rx_ring[i].cmd_status = cpu_to_le32(DescOwn);
        !           912:                np->rx_skbuff[i] = 0;
        !           913:        }
        !           914:        /* Mark the last entry as wrapping the ring. */
        !           915:        np->rx_ring[i-1].next_desc = virt_to_bus(&np->rx_ring[0]);
        !           916: 
        !           917:        for (i = 0; i < TX_RING_SIZE; i++) {
        !           918:                np->tx_skbuff[i] = 0;
        !           919:                np->tx_ring[i].next_desc = virt_to_bus(&np->tx_ring[i+1]);
        !           920:                np->tx_ring[i].cmd_status = 0;
        !           921:        }
        !           922:        np->tx_ring[i-1].next_desc = virt_to_bus(&np->tx_ring[0]);
        !           923: 
        !           924:        /* Fill in the Rx buffers.
        !           925:           Allocation failure just leaves a "negative" np->dirty_rx. */
        !           926:        np->dirty_rx = (unsigned int)(0 - RX_RING_SIZE);
        !           927:        rx_ring_fill(dev);
        !           928: 
        !           929:        return;
        !           930: }
        !           931: 
        !           932: static int start_tx(struct sk_buff *skb, struct net_device *dev)
        !           933: {
        !           934:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !           935:        unsigned int entry;
        !           936: 
        !           937:        /* Block a timer-based transmit from overlapping.  This happens when
        !           938:           packets are presumed lost, and we use this check the Tx status. */
        !           939:        if (netif_pause_tx_queue(dev) != 0) {
        !           940:                /* This watchdog code is redundant with the media monitor timer. */
        !           941:                if (jiffies - dev->trans_start > TX_TIMEOUT)
        !           942:                        tx_timeout(dev);
        !           943:                return 1;
        !           944:        }
        !           945: 
        !           946:        /* Note: Ordering is important here, set the field with the
        !           947:           "ownership" bit last, and only then increment cur_tx.
        !           948:           No spinlock is needed for either Tx or Rx.
        !           949:        */
        !           950: 
        !           951:        /* Calculate the next Tx descriptor entry. */
        !           952:        entry = np->cur_tx % TX_RING_SIZE;
        !           953: 
        !           954:        np->tx_skbuff[entry] = skb;
        !           955: 
        !           956:        np->tx_ring[entry].buf_addr = virt_to_bus(skb->data);
        !           957:        np->tx_ring[entry].cmd_status = cpu_to_le32(DescOwn|DescIntr | skb->len);
        !           958:        np->cur_tx++;
        !           959: 
        !           960:        /* StrongARM: Explicitly cache flush np->tx_ring and skb->data,skb->len. */
        !           961: 
        !           962:        if (np->cur_tx - np->dirty_tx >= TX_QUEUE_LEN - 1) {
        !           963:                np->tx_full = 1;
        !           964:                /* Check for a just-cleared queue. */
        !           965:                if (np->cur_tx - (volatile unsigned int)np->dirty_tx
        !           966:                        < TX_QUEUE_LEN - 4) {
        !           967:                        np->tx_full = 0;
        !           968:                        netif_unpause_tx_queue(dev);
        !           969:                } else
        !           970:                        netif_stop_tx_queue(dev);
        !           971:        } else
        !           972:                netif_unpause_tx_queue(dev);            /* Typical path */
        !           973:        /* Wake the potentially-idle transmit channel. */
        !           974:        writel(TxOn, dev->base_addr + ChipCmd);
        !           975: 
        !           976:        dev->trans_start = jiffies;
        !           977: 
        !           978:        if (np->msg_level & NETIF_MSG_TX_QUEUED) {
        !           979:                printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
        !           980:                           dev->name, np->cur_tx, entry);
        !           981:        }
        !           982:        return 0;
        !           983: }
        !           984: 
        !           985: /* The interrupt handler does all of the Rx thread work and cleans up
        !           986:    after the Tx thread. */
        !           987: static void intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
        !           988: {
        !           989:        struct net_device *dev = (struct net_device *)dev_instance;
        !           990:        struct netdev_private *np;
        !           991:        long ioaddr;
        !           992:        int boguscnt;
        !           993: 
        !           994: #ifndef final_version                  /* Can never occur. */
        !           995:        if (dev == NULL) {
        !           996:                printk (KERN_ERR "Netdev interrupt handler(): IRQ %d for unknown "
        !           997:                                "device.\n", irq);
        !           998:                return;
        !           999:        }
        !          1000: #endif
        !          1001: 
        !          1002:        ioaddr = dev->base_addr;
        !          1003:        np = (struct netdev_private *)dev->priv;
        !          1004:        boguscnt = np->max_interrupt_work;
        !          1005: 
        !          1006: #if defined(__i386__)  &&  LINUX_VERSION_CODE < 0x020300
        !          1007:        /* A lock to prevent simultaneous entry bug on Intel SMP machines. */
        !          1008:        if (test_and_set_bit(0, (void*)&dev->interrupt)) {
        !          1009:                printk(KERN_ERR"%s: SMP simultaneous entry of an interrupt handler.\n",
        !          1010:                           dev->name);
        !          1011:                dev->interrupt = 0;     /* Avoid halting machine. */
        !          1012:                return;
        !          1013:        }
        !          1014: #endif
        !          1015: 
        !          1016:        do {
        !          1017:                u32 intr_status = readl(ioaddr + IntrStatus);
        !          1018: 
        !          1019:                if (np->msg_level & NETIF_MSG_INTR)
        !          1020:                        printk(KERN_DEBUG "%s: Interrupt, status %8.8x.\n",
        !          1021:                                   dev->name, intr_status);
        !          1022: 
        !          1023:                if (intr_status == 0 || intr_status == 0xffffffff)
        !          1024:                        break;
        !          1025: 
        !          1026:                /* Acknowledge all of the current interrupt sources ASAP.
        !          1027:                   Nominally the read above accomplishes this, but... */
        !          1028:                writel(intr_status & 0x001ffff, ioaddr + IntrStatus);
        !          1029: 
        !          1030:                if (intr_status & (IntrRxDone | IntrRxIntr)) {
        !          1031:                        netdev_rx(dev);
        !          1032:                        np->rx_q_empty = rx_ring_fill(dev);
        !          1033:                }
        !          1034: 
        !          1035:                if (intr_status & (IntrRxIdle | IntrDrv)) {
        !          1036:                        unsigned int old_dirty_rx = np->dirty_rx;
        !          1037:                        if (rx_ring_fill(dev) == 0)
        !          1038:                                np->rx_q_empty = 0;
        !          1039:                        /* Restart Rx engine iff we did add a buffer. */
        !          1040:                        if (np->dirty_rx != old_dirty_rx)
        !          1041:                                writel(RxOn, dev->base_addr + ChipCmd);
        !          1042:                }
        !          1043: 
        !          1044:                for (; np->cur_tx - np->dirty_tx > 0; np->dirty_tx++) {
        !          1045:                        int entry = np->dirty_tx % TX_RING_SIZE;
        !          1046:                        if (np->msg_level & NETIF_MSG_INTR)
        !          1047:                                printk(KERN_DEBUG "%s: Tx entry %d @%p status %8.8x.\n",
        !          1048:                                           dev->name, entry, &np->tx_ring[entry],
        !          1049:                                           np->tx_ring[entry].cmd_status);
        !          1050:                        if (np->tx_ring[entry].cmd_status & cpu_to_le32(DescOwn))
        !          1051:                                break;
        !          1052:                        if (np->tx_ring[entry].cmd_status & cpu_to_le32(0x08000000)) {
        !          1053:                                if (np->msg_level & NETIF_MSG_TX_DONE)
        !          1054:                                        printk(KERN_DEBUG "%s: Transmit done, Tx status %8.8x.\n",
        !          1055:                                                   dev->name, np->tx_ring[entry].cmd_status);
        !          1056:                                np->stats.tx_packets++;
        !          1057: #if LINUX_VERSION_CODE > 0x20127
        !          1058:                                np->stats.tx_bytes += np->tx_skbuff[entry]->len;
        !          1059: #endif
        !          1060:                        } else {                        /* Various Tx errors */
        !          1061:                                int tx_status = le32_to_cpu(np->tx_ring[entry].cmd_status);
        !          1062:                                if (tx_status & 0x04010000) np->stats.tx_aborted_errors++;
        !          1063:                                if (tx_status & 0x02000000) np->stats.tx_fifo_errors++;
        !          1064:                                if (tx_status & 0x01000000) np->stats.tx_carrier_errors++;
        !          1065:                                if (tx_status & 0x00200000) np->stats.tx_window_errors++;
        !          1066:                                if (np->msg_level & NETIF_MSG_TX_ERR)
        !          1067:                                        printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
        !          1068:                                                   dev->name, tx_status);
        !          1069:                                np->stats.tx_errors++;
        !          1070:                        }
        !          1071:                        /* Free the original skb. */
        !          1072:                        dev_free_skb_irq(np->tx_skbuff[entry]);
        !          1073:                        np->tx_skbuff[entry] = 0;
        !          1074:                }
        !          1075:                /* Note the 4 slot hysteresis to mark the queue non-full. */
        !          1076:                if (np->tx_full
        !          1077:                        && np->cur_tx - np->dirty_tx < TX_QUEUE_LEN - 4) {
        !          1078:                        /* The ring is no longer full, allow new TX entries. */
        !          1079:                        np->tx_full = 0;
        !          1080:                        netif_resume_tx_queue(dev);
        !          1081:                }
        !          1082: 
        !          1083:                /* Abnormal error summary/uncommon events handlers. */
        !          1084:                if (intr_status & IntrAbnormalSummary)
        !          1085:                        netdev_error(dev, intr_status);
        !          1086: 
        !          1087:                if (--boguscnt < 0) {
        !          1088:                        printk(KERN_WARNING "%s: Too much work at interrupt, "
        !          1089:                                   "status=0x%4.4x.\n",
        !          1090:                                   dev->name, intr_status);
        !          1091:                        np->restore_intr_enable = 1;
        !          1092:                        break;
        !          1093:                }
        !          1094:        } while (1);
        !          1095: 
        !          1096:        if (np->msg_level & NETIF_MSG_INTR)
        !          1097:                printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",
        !          1098:                           dev->name, (int)readl(ioaddr + IntrStatus));
        !          1099: 
        !          1100: #if defined(__i386__)  &&  LINUX_VERSION_CODE < 0x020300
        !          1101:        clear_bit(0, (void*)&dev->interrupt);
        !          1102: #endif
        !          1103:        return;
        !          1104: }
        !          1105: 
        !          1106: /* This routine is logically part of the interrupt handler, but separated
        !          1107:    for clarity and better register allocation. */
        !          1108: static int netdev_rx(struct net_device *dev)
        !          1109: {
        !          1110:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1111:        int entry = np->cur_rx % RX_RING_SIZE;
        !          1112:        int boguscnt = np->dirty_rx + RX_RING_SIZE - np->cur_rx;
        !          1113:        s32 desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
        !          1114: 
        !          1115:        /* If the driver owns the next entry it's a new packet. Send it up. */
        !          1116:        while (desc_status < 0) {        /* e.g. & DescOwn */
        !          1117:                if (np->msg_level & NETIF_MSG_RX_STATUS)
        !          1118:                        printk(KERN_DEBUG "  In netdev_rx() entry %d status was %8.8x.\n",
        !          1119:                                   entry, desc_status);
        !          1120:                if (--boguscnt < 0)
        !          1121:                        break;
        !          1122:                if ((desc_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK) {
        !          1123:                        if (desc_status & DescMore) {
        !          1124:                                printk(KERN_WARNING "%s: Oversized(?) Ethernet frame spanned "
        !          1125:                                           "multiple buffers, entry %#x status %x.\n",
        !          1126:                                           dev->name, np->cur_rx, desc_status);
        !          1127:                                np->stats.rx_length_errors++;
        !          1128:                        } else {
        !          1129:                                /* There was a error. */
        !          1130:                                if (np->msg_level & NETIF_MSG_RX_ERR)
        !          1131:                                        printk(KERN_DEBUG "  netdev_rx() Rx error was %8.8x.\n",
        !          1132:                                                   desc_status);
        !          1133:                                np->stats.rx_errors++;
        !          1134:                                if (desc_status & 0x06000000) np->stats.rx_over_errors++;
        !          1135:                                if (desc_status & 0x00600000) np->stats.rx_length_errors++;
        !          1136:                                if (desc_status & 0x00140000) np->stats.rx_frame_errors++;
        !          1137:                                if (desc_status & 0x00080000) np->stats.rx_crc_errors++;
        !          1138:                        }
        !          1139:                } else {
        !          1140:                        struct sk_buff *skb;
        !          1141:                        int pkt_len = (desc_status & 0x0fff) - 4;       /* Omit CRC size. */
        !          1142:                        /* Check if the packet is long enough to accept without copying
        !          1143:                           to a minimally-sized skbuff. */
        !          1144:                        if (pkt_len < np->rx_copybreak
        !          1145:                                && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
        !          1146:                                skb->dev = dev;
        !          1147:                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
        !          1148: #if HAS_IP_COPYSUM
        !          1149:                                eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0);
        !          1150:                                skb_put(skb, pkt_len);
        !          1151: #else
        !          1152:                                memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail,
        !          1153:                                           pkt_len);
        !          1154: #endif
        !          1155:                        } else {
        !          1156:                                skb_put(skb = np->rx_skbuff[entry], pkt_len);
        !          1157:                                np->rx_skbuff[entry] = NULL;
        !          1158:                        }
        !          1159: #ifndef final_version                          /* Remove after testing. */
        !          1160:                        /* You will want this info for the initial debug. */
        !          1161:                        if (np->msg_level & NETIF_MSG_PKTDATA)
        !          1162:                                printk(KERN_DEBUG "  Rx data %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:"
        !          1163:                                           "%2.2x %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x %2.2x%2.2x "
        !          1164:                                           "%d.%d.%d.%d.\n",
        !          1165:                                           skb->data[0], skb->data[1], skb->data[2], skb->data[3],
        !          1166:                                           skb->data[4], skb->data[5], skb->data[6], skb->data[7],
        !          1167:                                           skb->data[8], skb->data[9], skb->data[10],
        !          1168:                                           skb->data[11], skb->data[12], skb->data[13],
        !          1169:                                           skb->data[14], skb->data[15], skb->data[16],
        !          1170:                                           skb->data[17]);
        !          1171: #endif
        !          1172:                        skb->protocol = eth_type_trans(skb, dev);
        !          1173:                        /* W/ hardware checksum: skb->ip_summed = CHECKSUM_UNNECESSARY; */
        !          1174:                        netif_rx(skb);
        !          1175:                        dev->last_rx = jiffies;
        !          1176:                        np->stats.rx_packets++;
        !          1177: #if LINUX_VERSION_CODE > 0x20127
        !          1178:                        np->stats.rx_bytes += pkt_len;
        !          1179: #endif
        !          1180:                }
        !          1181:                entry = (++np->cur_rx) % RX_RING_SIZE;
        !          1182:                np->rx_head_desc = &np->rx_ring[entry];
        !          1183:                desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
        !          1184:        }
        !          1185: 
        !          1186:        /* Refill is now done in the main interrupt loop. */
        !          1187:        return 0;
        !          1188: }
        !          1189: 
        !          1190: static void netdev_error(struct net_device *dev, int intr_status)
        !          1191: {
        !          1192:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1193:        long ioaddr = dev->base_addr;
        !          1194: 
        !          1195:        if (intr_status & LinkChange) {
        !          1196:                int chip_config = readl(ioaddr + ChipConfig);
        !          1197:                if (np->msg_level & NETIF_MSG_LINK)
        !          1198:                        printk(KERN_NOTICE "%s: Link changed: Autonegotiation advertising"
        !          1199:                                   " %4.4x  partner %4.4x.\n", dev->name,
        !          1200:                                   (int)readl(ioaddr + 0x90), (int)readl(ioaddr + 0x94));
        !          1201:                if (chip_config & CfgLinkGood)
        !          1202:                        netif_link_up(dev);
        !          1203:                else
        !          1204:                        netif_link_down(dev);
        !          1205:                check_duplex(dev);
        !          1206:        }
        !          1207:        if (intr_status & StatsMax) {
        !          1208:                get_stats(dev);
        !          1209:        }
        !          1210:        if (intr_status & IntrTxUnderrun) {
        !          1211:                /* Increase the Tx threshold, 32 byte units. */
        !          1212:                if ((np->tx_config & 0x3f) < 62)
        !          1213:                        np->tx_config += 2;                     /* +64 bytes */
        !          1214:                writel(np->tx_config, ioaddr + TxConfig);
        !          1215:        }
        !          1216:        if (intr_status & WOLPkt) {
        !          1217:                int wol_status = readl(ioaddr + WOLCmd);
        !          1218:                printk(KERN_NOTICE "%s: Link wake-up event %8.8x",
        !          1219:                           dev->name, wol_status);
        !          1220:        }
        !          1221:        if (intr_status & (RxStatusOverrun | IntrRxOverrun)) {
        !          1222:                if (np->msg_level & NETIF_MSG_DRV)
        !          1223:                        printk(KERN_ERR "%s: Rx overflow! ns820 %8.8x.\n",
        !          1224:                                   dev->name, intr_status);
        !          1225:                np->stats.rx_fifo_errors++;
        !          1226:        }
        !          1227:        if (intr_status & ~(LinkChange|StatsMax|RxResetDone|TxResetDone|
        !          1228:                                                RxStatusOverrun|0xA7ff)) {
        !          1229:                if (np->msg_level & NETIF_MSG_DRV)
        !          1230:                        printk(KERN_ERR "%s: Something Wicked happened! ns820 %8.8x.\n",
        !          1231:                                   dev->name, intr_status);
        !          1232:        }
        !          1233:        /* Hmmmmm, it's not clear how to recover from PCI faults. */
        !          1234:        if (intr_status & IntrPCIErr) {
        !          1235:                np->stats.tx_fifo_errors++;
        !          1236:                np->stats.rx_fifo_errors++;
        !          1237:        }
        !          1238: }
        !          1239: 
        !          1240: static struct net_device_stats *get_stats(struct net_device *dev)
        !          1241: {
        !          1242:        long ioaddr = dev->base_addr;
        !          1243:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1244:        int crc_errs = readl(ioaddr + RxCRCErrs);
        !          1245: 
        !          1246:        if (crc_errs != 0xffffffff) {
        !          1247:                /* We need not lock this segment of code for SMP.
        !          1248:                   There is no atomic-add vulnerability for most CPUs,
        !          1249:                   and statistics are non-critical. */
        !          1250:                /* The chip only need report frame silently dropped. */
        !          1251:                np->stats.rx_crc_errors += crc_errs;
        !          1252:                np->stats.rx_missed_errors += readl(ioaddr + RxMissed);
        !          1253:        }
        !          1254: 
        !          1255:        return &np->stats;
        !          1256: }
        !          1257: 
        !          1258: /* The little-endian AUTODIN II ethernet CRC calculations.
        !          1259:    A big-endian version is also available.
        !          1260:    This is slow but compact code.  Do not use this routine for bulk data,
        !          1261:    use a table-based routine instead.
        !          1262:    This is common code and should be moved to net/core/crc.c.
        !          1263:    Chips may use the upper or lower CRC bits, and may reverse and/or invert
        !          1264:    them.  Select the endian-ness that results in minimal calculations.
        !          1265: */
        !          1266: static unsigned const ethernet_polynomial_le = 0xedb88320U;
        !          1267: static inline unsigned ether_crc_le(int length, unsigned char *data)
        !          1268: {
        !          1269:        unsigned int crc = 0xffffffff;  /* Initial value. */
        !          1270:        while(--length >= 0) {
        !          1271:                unsigned char current_octet = *data++;
        !          1272:                int bit;
        !          1273:                for (bit = 8; --bit >= 0; current_octet >>= 1) {
        !          1274:                        if ((crc ^ current_octet) & 1) {
        !          1275:                                crc >>= 1;
        !          1276:                                crc ^= ethernet_polynomial_le;
        !          1277:                        } else
        !          1278:                                crc >>= 1;
        !          1279:                }
        !          1280:        }
        !          1281:        return crc;
        !          1282: }
        !          1283: 
        !          1284: static void set_rx_mode(struct net_device *dev)
        !          1285: {
        !          1286:        long ioaddr = dev->base_addr;
        !          1287:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1288:        u8 mc_filter[64];                       /* Multicast hash filter */
        !          1289:        u32 rx_mode;
        !          1290: 
        !          1291:        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
        !          1292:                /* Unconditionally log net taps. */
        !          1293:                printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
        !          1294:                rx_mode = AcceptBroadcast | AcceptAllMulticast | AcceptAllPhys
        !          1295:                        | AcceptMyPhys;
        !          1296:        } else if ((dev->mc_count > np->multicast_filter_limit)
        !          1297:                           ||  (dev->flags & IFF_ALLMULTI)) {
        !          1298:                rx_mode = AcceptBroadcast | AcceptAllMulticast | AcceptMyPhys;
        !          1299:        } else {
        !          1300:                struct dev_mc_list *mclist;
        !          1301:                int i;
        !          1302:                memset(mc_filter, 0, sizeof(mc_filter));
        !          1303:                for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
        !          1304:                         i++, mclist = mclist->next) {
        !          1305:                        set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x7ff,
        !          1306:                                        mc_filter);
        !          1307:                }
        !          1308:                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
        !          1309:                for (i = 0; i < 64; i += 2) {
        !          1310:                        writel(rx_mode + 0x200 + i, ioaddr + RxFilterAddr);
        !          1311:                        writel((mc_filter[i+1]<<8) + mc_filter[i], ioaddr + RxFilterData);
        !          1312:                }
        !          1313:        }
        !          1314:        writel(rx_mode, ioaddr + RxFilterAddr);
        !          1315:        np->cur_rx_mode = rx_mode;
        !          1316: }
        !          1317: 
        !          1318: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        !          1319: {
        !          1320:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1321:        u16 *data = (u16 *)&rq->ifr_data;
        !          1322:        u32 *data32 = (void *)&rq->ifr_data;
        !          1323: 
        !          1324:        switch(cmd) {
        !          1325:        case 0x8947: case 0x89F0:
        !          1326:                /* SIOCGMIIPHY: Get the address of the PHY in use. */
        !          1327:                data[0] = 1;
        !          1328:                /* Fall Through */
        !          1329:        case 0x8948: case 0x89F1:
        !          1330:                /* SIOCGMIIREG: Read the specified MII register. */
        !          1331:                data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f);
        !          1332:                return 0;
        !          1333:        case 0x8949: case 0x89F2:
        !          1334:                /* SIOCSMIIREG: Write the specified MII register */
        !          1335:                if (!capable(CAP_NET_ADMIN))
        !          1336:                        return -EPERM;
        !          1337:                if (data[0] == 1) {
        !          1338:                        u16 miireg = data[1] & 0x1f;
        !          1339:                        u16 value = data[2];
        !          1340:                        switch (miireg) {
        !          1341:                        case 0:
        !          1342:                                /* Check for autonegotiation on or reset. */
        !          1343:                                np->duplex_lock = (value & 0x9000) ? 0 : 1;
        !          1344:                                if (np->duplex_lock)
        !          1345:                                        np->full_duplex = (value & 0x0100) ? 1 : 0;
        !          1346:                                break;
        !          1347:                        case 4: np->advertising = value; break;
        !          1348:                        }
        !          1349:                }
        !          1350:                mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
        !          1351:                return 0;
        !          1352:        case SIOCGPARAMS:
        !          1353:                data32[0] = np->msg_level;
        !          1354:                data32[1] = np->multicast_filter_limit;
        !          1355:                data32[2] = np->max_interrupt_work;
        !          1356:                data32[3] = np->rx_copybreak;
        !          1357:                return 0;
        !          1358:        case SIOCSPARAMS:
        !          1359:                if (!capable(CAP_NET_ADMIN))
        !          1360:                        return -EPERM;
        !          1361:                np->msg_level = data32[0];
        !          1362:                np->multicast_filter_limit = data32[1];
        !          1363:                np->max_interrupt_work = data32[2];
        !          1364:                np->rx_copybreak = data32[3];
        !          1365:                return 0;
        !          1366:        default:
        !          1367:                return -EOPNOTSUPP;
        !          1368:        }
        !          1369: }
        !          1370: 
        !          1371: static int netdev_close(struct net_device *dev)
        !          1372: {
        !          1373:        long ioaddr = dev->base_addr;
        !          1374:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1375:        int i;
        !          1376: 
        !          1377:        netif_stop_tx_queue(dev);
        !          1378: 
        !          1379:        if (np->msg_level & NETIF_MSG_IFDOWN) {
        !          1380:                printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x "
        !          1381:                           "Int %2.2x.\n",
        !          1382:                           dev->name, (int)readl(ioaddr + ChipCmd),
        !          1383:                           (int)readl(ioaddr + IntrStatus));
        !          1384:                printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d,  Rx %d / %d.\n",
        !          1385:                           dev->name, np->cur_tx, np->dirty_tx, np->cur_rx, np->dirty_rx);
        !          1386:        }
        !          1387: 
        !          1388:        /* We don't want the timer to re-start anything. */
        !          1389:        del_timer(&np->timer);
        !          1390: 
        !          1391:        /* Disable interrupts using the mask. */
        !          1392:        writel(0, ioaddr + IntrMask);
        !          1393:        writel(0, ioaddr + IntrEnable);
        !          1394:        writel(2, ioaddr + StatsCtrl);                                  /* Freeze Stats */
        !          1395: 
        !          1396:        /* Stop the chip's Tx and Rx processes. */
        !          1397:        writel(RxOff | TxOff, ioaddr + ChipCmd);
        !          1398: 
        !          1399:        get_stats(dev);
        !          1400: 
        !          1401: #ifdef __i386__
        !          1402:        if (np->msg_level & NETIF_MSG_IFDOWN) {
        !          1403:                printk("\n"KERN_DEBUG"  Tx ring at %8.8x:\n",
        !          1404:                           (int)virt_to_bus(np->tx_ring));
        !          1405:                for (i = 0; i < TX_RING_SIZE; i++)
        !          1406:                        printk(" #%d desc. %8.8x %8.8x.\n",
        !          1407:                                   i, np->tx_ring[i].cmd_status, (u32)np->tx_ring[i].buf_addr);
        !          1408:                printk("\n"KERN_DEBUG "  Rx ring %8.8x:\n",
        !          1409:                           (int)virt_to_bus(np->rx_ring));
        !          1410:                for (i = 0; i < RX_RING_SIZE; i++) {
        !          1411:                        printk(KERN_DEBUG " #%d desc. %8.8x %8.8x\n",
        !          1412:                                   i, np->rx_ring[i].cmd_status, (u32)np->rx_ring[i].buf_addr);
        !          1413:                }
        !          1414:        }
        !          1415: #endif /* __i386__ debugging only */
        !          1416: 
        !          1417:        free_irq(dev->irq, dev);
        !          1418: 
        !          1419:        /* Free all the skbuffs in the Rx queue. */
        !          1420:        for (i = 0; i < RX_RING_SIZE; i++) {
        !          1421:                np->rx_ring[i].cmd_status = 0;
        !          1422:                np->rx_ring[i].buf_addr = 0xBADF00D0; /* An invalid address. */
        !          1423:                if (np->rx_skbuff[i]) {
        !          1424: #if LINUX_VERSION_CODE < 0x20100
        !          1425:                        np->rx_skbuff[i]->free = 1;
        !          1426: #endif
        !          1427:                        dev_free_skb(np->rx_skbuff[i]);
        !          1428:                }
        !          1429:                np->rx_skbuff[i] = 0;
        !          1430:        }
        !          1431:        for (i = 0; i < TX_RING_SIZE; i++) {
        !          1432:                if (np->tx_skbuff[i])
        !          1433:                        dev_free_skb(np->tx_skbuff[i]);
        !          1434:                np->tx_skbuff[i] = 0;
        !          1435:        }
        !          1436: 
        !          1437:        /* Power down Xcvr. */
        !          1438:        writel(CfgXcrOff | readl(ioaddr + ChipConfig), ioaddr + ChipConfig);
        !          1439: 
        !          1440:        MOD_DEC_USE_COUNT;
        !          1441: 
        !          1442:        return 0;
        !          1443: }
        !          1444: 
        !          1445: static int power_event(void *dev_instance, int event)
        !          1446: {
        !          1447:        struct net_device *dev = dev_instance;
        !          1448:        struct netdev_private *np = (struct netdev_private *)dev->priv;
        !          1449:        long ioaddr = dev->base_addr;
        !          1450: 
        !          1451:        if (np->msg_level & NETIF_MSG_LINK)
        !          1452:                printk(KERN_DEBUG "%s: Handling power event %d.\n", dev->name, event);
        !          1453:        switch(event) {
        !          1454:        case DRV_ATTACH:
        !          1455:                MOD_INC_USE_COUNT;
        !          1456:                break;
        !          1457:        case DRV_SUSPEND:
        !          1458:                /* Disable interrupts, freeze stats, stop Tx and Rx. */
        !          1459:                writel(0, ioaddr + IntrEnable);
        !          1460:                writel(2, ioaddr + StatsCtrl);
        !          1461:                writel(RxOff | TxOff, ioaddr + ChipCmd);
        !          1462:                writel(CfgXcrOff | readl(ioaddr + ChipConfig), ioaddr + ChipConfig);
        !          1463:                break;
        !          1464:        case DRV_RESUME:
        !          1465:                /* This is incomplete: the open() actions should be repeated. */
        !          1466:                writel(~CfgXcrOff & readl(ioaddr + ChipConfig), ioaddr + ChipConfig);
        !          1467:                set_rx_mode(dev);
        !          1468:                writel(np->intr_enable, ioaddr + IntrEnable);
        !          1469:                writel(1, ioaddr + IntrEnable);
        !          1470:                writel(RxOn | TxOn, ioaddr + ChipCmd);
        !          1471:                break;
        !          1472:        case DRV_DETACH: {
        !          1473:                struct net_device **devp, **next;
        !          1474:                if (dev->flags & IFF_UP) {
        !          1475:                        /* Some, but not all, kernel versions close automatically. */
        !          1476:                        dev_close(dev);
        !          1477:                        dev->flags &= ~(IFF_UP|IFF_RUNNING);
        !          1478:                }
        !          1479:                unregister_netdev(dev);
        !          1480:                release_region(dev->base_addr, pci_id_tbl[np->chip_id].io_size);
        !          1481:                for (devp = &root_net_dev; *devp; devp = next) {
        !          1482:                        next = &((struct netdev_private *)(*devp)->priv)->next_module;
        !          1483:                        if (*devp == dev) {
        !          1484:                                *devp = *next;
        !          1485:                                break;
        !          1486:                        }
        !          1487:                }
        !          1488:                if (np->priv_addr)
        !          1489:                        kfree(np->priv_addr);
        !          1490:                kfree(dev);
        !          1491:                MOD_DEC_USE_COUNT;
        !          1492:                break;
        !          1493:        }
        !          1494:        }
        !          1495: 
        !          1496:        return 0;
        !          1497: }
        !          1498: 
        !          1499: 
        !          1500: #ifdef MODULE
        !          1501: int init_module(void)
        !          1502: {
        !          1503:        /* Emit version even if no cards detected. */
        !          1504:        printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
        !          1505: #ifdef CARDBUS
        !          1506:        register_driver(&etherdev_ops);
        !          1507:        return 0;
        !          1508: #else
        !          1509:        return pci_drv_register(&ns820_drv_id, NULL);
        !          1510: #endif
        !          1511: }
        !          1512: 
        !          1513: void cleanup_module(void)
        !          1514: {
        !          1515:        struct net_device *next_dev;
        !          1516: 
        !          1517: #ifdef CARDBUS
        !          1518:        unregister_driver(&etherdev_ops);
        !          1519: #else
        !          1520:        pci_drv_unregister(&ns820_drv_id);
        !          1521: #endif
        !          1522: 
        !          1523:        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
        !          1524:        while (root_net_dev) {
        !          1525:                struct netdev_private *np = (void *)(root_net_dev->priv);
        !          1526:                unregister_netdev(root_net_dev);
        !          1527:                iounmap((char *)root_net_dev->base_addr);
        !          1528:                next_dev = np->next_module;
        !          1529:                if (np->priv_addr)
        !          1530:                        kfree(np->priv_addr);
        !          1531:                kfree(root_net_dev);
        !          1532:                root_net_dev = next_dev;
        !          1533:        }
        !          1534: }
        !          1535: 
        !          1536: #endif  /* MODULE */
        !          1537: 
        !          1538: /*
        !          1539:  * Local variables:
        !          1540:  *  compile-command: "make KERNVER=`uname -r` ns820.o"
        !          1541:  *  compile-cmd: "gcc -DMODULE -Wall -Wstrict-prototypes -O6 -c ns820.c"
        !          1542:  *  simple-compile-command: "gcc -DMODULE -O6 -c ns820.c"
        !          1543:  *  c-indent-level: 4
        !          1544:  *  c-basic-offset: 4
        !          1545:  *  tab-width: 4
        !          1546:  * End:
        !          1547:  */

unix.superglobalmegacorp.com

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