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

1.1     ! root        1: /* tulip.c: A DEC 21040-family ethernet driver for Linux. */
        !             2: /*
        !             3:        Written 1994-1998 by Donald Becker.
        !             4: 
        !             5:        This software may be used and distributed according to the terms
        !             6:        of the GNU Public License, incorporated herein by reference.
        !             7: 
        !             8:        This driver is for the Digital "Tulip" ethernet adapter interface.
        !             9:        It should work with most DEC 21*4*-based chips/ethercards, as well as
        !            10:        PNIC and MXIC chips.
        !            11: 
        !            12:        The author may be reached as [email protected], or C/O
        !            13:        Center of Excellence in Space Data and Information Sciences
        !            14:           Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
        !            15: 
        !            16:        Support and updates available at
        !            17:        http://cesdis.gsfc.nasa.gov/linux/drivers/tulip.html
        !            18: */
        !            19: 
        !            20: #define SMP_CHECK
        !            21: static const char version[] = "tulip.c:v0.89H 5/23/98 [email protected]\n";
        !            22: 
        !            23: /* A few user-configurable values. */
        !            24: 
        !            25: /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
        !            26: static int max_interrupt_work = 25;
        !            27: 
        !            28: #define MAX_UNITS 8
        !            29: /* Used to pass the full-duplex flag, etc. */
        !            30: static int full_duplex[MAX_UNITS] = {0, };
        !            31: static int options[MAX_UNITS] = {0, };
        !            32: static int mtu[MAX_UNITS] = {0, };                     /* Jumbo MTU for interfaces. */
        !            33: 
        !            34: /*  The possible media types that can be set in options[] are: */
        !            35: static const char * const medianame[] = {
        !            36:        "10baseT", "10base2", "AUI", "100baseTx",
        !            37:        "10baseT-FD", "100baseTx-FD", "100baseT4", "100baseFx",
        !            38:        "100baseFx-FD", "MII 10baseT", "MII 10baseT-FD", "MII",
        !            39:        "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FD", "MII 100baseT4",
        !            40: };
        !            41: 
        !            42: /* Set if the PCI BIOS detects the chips on a multiport board backwards. */
        !            43: #ifdef REVERSE_PROBE_ORDER
        !            44: static int reverse_probe = 1;
        !            45: #else
        !            46: static int reverse_probe = 0;
        !            47: #endif
        !            48: 
        !            49: /* Keep the ring sizes a power of two for efficiency.
        !            50:    Making the Tx ring too large decreases the effectiveness of channel
        !            51:    bonding and packet priority.
        !            52:    There are no ill effects from too-large receive rings. */
        !            53: #define TX_RING_SIZE   16
        !            54: #define RX_RING_SIZE   32
        !            55: 
        !            56: /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
        !            57: #ifdef __alpha__
        !            58: static int rx_copybreak = 1518;
        !            59: #else
        !            60: static int rx_copybreak = 100;
        !            61: #endif
        !            62: 
        !            63: /* Operational parameters that usually are not changed. */
        !            64: /* Time in jiffies before concluding the transmitter is hung. */
        !            65: #define TX_TIMEOUT  (4*HZ)
        !            66: 
        !            67: #include <linux/config.h>
        !            68: #ifdef MODULE
        !            69: #ifdef MODVERSIONS
        !            70: #include <linux/modversions.h>
        !            71: #endif
        !            72: #include <linux/module.h>
        !            73: #include <linux/version.h>
        !            74: #else
        !            75: #define MOD_INC_USE_COUNT
        !            76: #define MOD_DEC_USE_COUNT
        !            77: #endif
        !            78: 
        !            79: #include <linux/kernel.h>
        !            80: #include <linux/sched.h>
        !            81: #include <linux/string.h>
        !            82: #include <linux/timer.h>
        !            83: #include <linux/ptrace.h>
        !            84: #include <linux/errno.h>
        !            85: #include <linux/ioport.h>
        !            86: #include <linux/malloc.h>
        !            87: #include <linux/interrupt.h>
        !            88: #include <linux/pci.h>
        !            89: #include <linux/bios32.h>
        !            90: #include <asm/processor.h>             /* Processor type for cache alignment. */
        !            91: #include <asm/bitops.h>
        !            92: #include <asm/io.h>
        !            93: #include <asm/dma.h>
        !            94: 
        !            95: #include <linux/netdevice.h>
        !            96: #include <linux/etherdevice.h>
        !            97: #include <linux/skbuff.h>
        !            98: 
        !            99: /* Kernel compatibility defines, common to David Hind's PCMCIA package.
        !           100:    This is only in the support-all-kernels source code. */
        !           101: #include <linux/version.h>             /* Evil, but neccessary */
        !           102: 
        !           103: #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x10300
        !           104: #define RUN_AT(x) (x)                  /* What to put in timer->expires.  */
        !           105: #define DEV_ALLOC_SKB(len) alloc_skb(len, GFP_ATOMIC)
        !           106: #define virt_to_bus(addr)  ((unsigned long)addr)
        !           107: #define bus_to_virt(addr) ((void*)addr)
        !           108: 
        !           109: #else  /* 1.3.0 and later */
        !           110: #define RUN_AT(x) (jiffies + (x))
        !           111: #define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)
        !           112: #endif
        !           113: 
        !           114: #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x10338
        !           115: #ifdef MODULE
        !           116: #if !defined(CONFIG_MODVERSIONS) && !defined(__NO_VERSION__)
        !           117: char kernel_version[] = UTS_RELEASE;
        !           118: #endif
        !           119: #else
        !           120: #undef MOD_INC_USE_COUNT
        !           121: #define MOD_INC_USE_COUNT
        !           122: #undef MOD_DEC_USE_COUNT
        !           123: #define MOD_DEC_USE_COUNT
        !           124: #endif
        !           125: #endif /* 1.3.38 */
        !           126: 
        !           127: #if (LINUX_VERSION_CODE >= 0x10344)
        !           128: #define NEW_MULTICAST
        !           129: #include <linux/delay.h>
        !           130: #endif
        !           131: #if (LINUX_VERSION_CODE >= 0x20100)
        !           132: char kernel_version[] = UTS_RELEASE;
        !           133: #endif
        !           134: #ifdef SA_SHIRQ
        !           135: #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
        !           136: #else
        !           137: #define IRQ(irq, dev_id, pt_regs) (irq, pt_regs)
        !           138: #endif
        !           139: 
        !           140: #if (LINUX_VERSION_CODE < 0x20123)
        !           141: #define hard_smp_processor_id() smp_processor_id()
        !           142: #define test_and_set_bit(val, addr) set_bit(val, addr)
        !           143: #endif
        !           144: 
        !           145: /* This my implementation of shared IRQs, now only used for 1.2.13. */
        !           146: #ifdef HAVE_SHARED_IRQ
        !           147: #define USE_SHARED_IRQ
        !           148: #include <linux/shared_irq.h>
        !           149: #endif
        !           150: 
        !           151: /* The total size is unusually large: The 21040 aligns each of its 16
        !           152:    longword-wide registers on a quadword boundary. */
        !           153: #define TULIP_TOTAL_SIZE 0x80
        !           154: 
        !           155: #ifdef HAVE_DEVLIST
        !           156: struct netdev_entry tulip_drv =
        !           157: {"Tulip", tulip_pci_probe, TULIP_TOTAL_SIZE, NULL};
        !           158: #endif
        !           159: 
        !           160: #ifdef TULIP_DEBUG
        !           161: int tulip_debug = TULIP_DEBUG;
        !           162: #else
        !           163: int tulip_debug = 1;
        !           164: #endif
        !           165: 
        !           166: /*
        !           167:                                Theory of Operation
        !           168: 
        !           169: I. Board Compatibility
        !           170: 
        !           171: This device driver is designed for the DECchip "Tulip", Digital's
        !           172: single-chip ethernet controllers for PCI.  Supported members of the family
        !           173: are the 21040, 21041, 21140, 21140A, 21142, and 21143.  These chips are used on
        !           174: many PCI boards including the SMC EtherPower series.
        !           175: 
        !           176: 
        !           177: II. Board-specific settings
        !           178: 
        !           179: PCI bus devices are configured by the system at boot time, so no jumpers
        !           180: need to be set on the board.  The system BIOS preferably should assign the
        !           181: PCI INTA signal to an otherwise unused system IRQ line.
        !           182: Note: Kernel versions earlier than 1.3.73 do not support shared PCI
        !           183: interrupt lines.
        !           184: 
        !           185: III. Driver operation
        !           186: 
        !           187: IIIa. Ring buffers
        !           188: 
        !           189: The Tulip can use either ring buffers or lists of Tx and Rx descriptors.
        !           190: This driver uses statically allocated rings of Rx and Tx descriptors, set at
        !           191: compile time by RX/TX_RING_SIZE.  This version of the driver allocates skbuffs
        !           192: for the Rx ring buffers at open() time and passes the skb->data field to the
        !           193: Tulip as receive data buffers.  When an incoming frame is less than
        !           194: RX_COPYBREAK bytes long, a fresh skbuff is allocated and the frame is
        !           195: copied to the new skbuff.  When the incoming frame is larger, the skbuff is
        !           196: passed directly up the protocol stack and replaced by a newly allocated
        !           197: skbuff.
        !           198: 
        !           199: The RX_COPYBREAK value is chosen to trade-off the memory wasted by
        !           200: using a full-sized skbuff for small frames vs. the copying costs of larger
        !           201: frames.  For small frames the copying cost is negligible (esp. considering
        !           202: that we are pre-loading the cache with immediately useful header
        !           203: information).  For large frames the copying cost is non-trivial, and the
        !           204: larger copy might flush the cache of useful data.  A subtle aspect of this
        !           205: choice is that the Tulip only receives into longword aligned buffers, thus
        !           206: the IP header at offset 14 isn't longword aligned for further processing.
        !           207: Copied frames are put into the new skbuff at an offset of "+2", thus copying
        !           208: has the beneficial effect of aligning the IP header and preloading the
        !           209: cache.
        !           210: 
        !           211: IIIC. Synchronization
        !           212: The driver runs as two independent, single-threaded flows of control.  One
        !           213: is the send-packet routine, which enforces single-threaded use by the
        !           214: dev->tbusy flag.  The other thread is the interrupt handler, which is single
        !           215: threaded by the hardware and other software.
        !           216: 
        !           217: The send packet thread has partial control over the Tx ring and 'dev->tbusy'
        !           218: flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
        !           219: queue slot is empty, it clears the tbusy flag when finished otherwise it sets
        !           220: the 'tp->tx_full' flag.
        !           221: 
        !           222: The interrupt handler has exclusive control over the Rx ring and records stats
        !           223: from the Tx ring.  (The Tx-done interrupt can't be selectively turned off, so
        !           224: we can't avoid the interrupt overhead by having the Tx routine reap the Tx
        !           225: stats.)         After reaping the stats, it marks the queue entry as empty by setting
        !           226: the 'base' to zero.     Iff the 'tp->tx_full' flag is set, it clears both the
        !           227: tx_full and tbusy flags.
        !           228: 
        !           229: IV. Notes
        !           230: 
        !           231: Thanks to Duke Kamstra of SMC for providing an EtherPower board.
        !           232: 
        !           233: IVb. References
        !           234: 
        !           235: http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
        !           236: http://www.digital.com  (search for current 21*4* datasheets and "21X4 SROM")
        !           237: http://www.national.com/pf/DP/DP83840.html
        !           238: 
        !           239: IVc. Errata
        !           240: 
        !           241: The DEC databook doesn't document which Rx filter settings accept broadcast
        !           242: packets.  Nor does it document how to configure the part to configure the
        !           243: serial subsystem for normal (vs. loopback) operation or how to have it
        !           244: autoswitch between internal 10baseT, SIA and AUI transceivers.
        !           245: 
        !           246: The 21040 databook claims that CSR13, CSR14, and CSR15 should each be the last
        !           247: register of the set CSR12-15 written.  Hmmm, now how is that possible?  */
        !           248: 
        !           249: 
        !           250: /* A few values that may be tweaked. */
        !           251: #define PKT_BUF_SZ             1536                    /* Size of each temporary Rx buffer.*/
        !           252: 
        !           253: /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
        !           254:    to support a pre-NWay full-duplex signaling mechanism using short frames.
        !           255:    No one knows what it should be, but if left at its default value some
        !           256:    10base2(!) packets trigger a full-duplex-request interrupt. */
        !           257: #define FULL_DUPLEX_MAGIC      0x6969
        !           258: 
        !           259: #ifndef PCI_VENDOR_ID_DEC              /* Now defined in linux/pci.h */
        !           260: #define PCI_VENDOR_ID_DEC                      0x1011
        !           261: #define PCI_DEVICE_ID_TULIP                    0x0002          /* 21040. */
        !           262: #define PCI_DEVICE_ID_TULIP_FAST       0x0009          /* 21140. */
        !           263: #endif
        !           264: 
        !           265: #ifndef PCI_DEVICE_ID_DEC_TULIP_PLUS
        !           266: #define PCI_DEVICE_ID_DEC_TULIP_PLUS   0x0014          /* 21041. */
        !           267: #endif
        !           268: #ifndef PCI_DEVICE_ID_DEC_TULIP_21142
        !           269: #define PCI_DEVICE_ID_DEC_TULIP_21142  0x0019
        !           270: #endif
        !           271: 
        !           272: #ifndef PCI_VENDOR_ID_LITEON
        !           273: #define PCI_VENDOR_ID_LITEON   0x11AD
        !           274: #endif
        !           275: 
        !           276: #ifndef PCI_VENDOR_ID_MXIC
        !           277: #define        PCI_VENDOR_ID_MXIC              0x10d9
        !           278: #define PCI_DEVICE_ID_MX98713  0x0512
        !           279: #define PCI_DEVICE_ID_MX98715  0x0531
        !           280: #define PCI_DEVICE_ID_MX98725  0x0531
        !           281: #endif
        !           282: 
        !           283: /* The rest of these values should never change. */
        !           284: 
        !           285: static void tulip_timer(unsigned long data);
        !           286: static void t21142_timer(unsigned long data);
        !           287: static void mxic_timer(unsigned long data);
        !           288: static void pnic_timer(unsigned long data);
        !           289: 
        !           290: /* A table describing the chip types. */
        !           291: enum tbl_flag { HAS_MII=1, HAS_MEDIA_TABLE = 2, CSR12_IN_SROM = 4,};
        !           292: static struct tulip_chip_table {
        !           293:        int vendor_id, device_id;
        !           294:        char *chip_name;
        !           295:        int io_size;
        !           296:        int valid_intrs;                        /* CSR7 interrupt enable settings */
        !           297:        int flags;
        !           298:        void (*media_timer)(unsigned long data);
        !           299: } tulip_tbl[] = {
        !           300:   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP,
        !           301:        "Digital DC21040 Tulip", 128, 0x0001ebef, 0, tulip_timer },
        !           302:   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_PLUS,
        !           303:        "Digital DC21041 Tulip", 128, 0x0001ebef, HAS_MEDIA_TABLE, tulip_timer },
        !           304:   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
        !           305:        "Digital DS21140 Tulip", 128, 0x0001ebef,
        !           306:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM,
        !           307:        tulip_timer },
        !           308:   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_21142,
        !           309:        "Digital DS21142/3 Tulip", 256, 0x0801fbff,
        !           310:        HAS_MII | HAS_MEDIA_TABLE, t21142_timer },
        !           311:   { PCI_VENDOR_ID_LITEON, 0x0002,
        !           312:        "Lite-On 82c168 PNIC", 256, 0x0001ebef, HAS_MII, pnic_timer },
        !           313:   { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98713,
        !           314:        "Macronix 98713 PMAC", 128, 0x0001ebef,
        !           315:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, tulip_timer /* Tulip-like! */ },
        !           316:   { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98715,
        !           317:        "Macronix 98715 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE, mxic_timer },
        !           318:   { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98725,
        !           319:        "Macronix 98725 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE, mxic_timer },
        !           320:   { 0x125B, 0x1400, "ASIX AX88140", 128, 0x0001fbff,
        !           321:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, tulip_timer },
        !           322:   {0, 0, 0, 0},
        !           323: };
        !           324: /* This matches the table above. */
        !           325: enum chips { DC21040=0, DC21041=1, DC21140=2, DC21142=3, DC21143=3,
        !           326:                         LC82C168, MX98713, MX98715, MX98725};
        !           327: 
        !           328: /* A full-duplex map for media types. */
        !           329: enum MediaIs {MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8,
        !           330:                  MediaIs100=16};
        !           331: static const char media_cap[] =
        !           332: {0,0,0,16,  3,19,16,24,  27,4,7,5, 0,20,23,20 };
        !           333: /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD*/
        !           334: static u16 t21041_csr13[] = { 0xEF05, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
        !           335: static u16 t21041_csr14[] = { 0x7F3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
        !           336: static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
        !           337: 
        !           338: static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
        !           339: static u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
        !           340: static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
        !           341: 
        !           342: /* Offsets to the Command and Status Registers, "CSRs".  All accesses
        !           343:    must be longword instructions and quadword aligned. */
        !           344: enum tulip_offsets {
        !           345:        CSR0=0,    CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
        !           346:        CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
        !           347:        CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78 };
        !           348: 
        !           349: /* The bits in the CSR5 status registers, mostly interrupt sources. */
        !           350: enum status_bits {
        !           351:        TimerInt=0x800, TPLnkFail=0x1000, TPLnkPass=0x10,
        !           352:        NormalIntr=0x10000, AbnormalIntr=0x8000,
        !           353:        RxJabber=0x200, RxDied=0x100, RxNoBuf=0x80, RxIntr=0x40,
        !           354:        TxFIFOUnderflow=0x20, TxJabber=0x08, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01,
        !           355: };
        !           356: 
        !           357: /* The Tulip Rx and Tx buffer descriptors. */
        !           358: struct tulip_rx_desc {
        !           359:        s32 status;
        !           360:        s32 length;
        !           361:        u32 buffer1, buffer2;
        !           362: };
        !           363: 
        !           364: struct tulip_tx_desc {
        !           365:        s32 status;
        !           366:        s32 length;
        !           367:        u32 buffer1, buffer2;                           /* We use only buffer 1.  */
        !           368: };
        !           369: 
        !           370: struct medialeaf {
        !           371:        u8 type;
        !           372:        u8 media;
        !           373:        unsigned char *leafdata;
        !           374: };
        !           375: 
        !           376: struct mediatable {
        !           377:        u16 defaultmedia;
        !           378:        u8 leafcount, csr12dir;                         /* General purpose pin directions. */
        !           379:        unsigned has_mii:1, has_nonmii:1;
        !           380:        struct medialeaf mleaf[0];
        !           381: };
        !           382: 
        !           383: struct mediainfo {
        !           384:        struct mediainfo *next;
        !           385:        int info_type;
        !           386:        int index;
        !           387:        unsigned char *info;
        !           388: };
        !           389: 
        !           390: struct tulip_private {
        !           391:        char devname[8];                        /* Used only for kernel debugging. */
        !           392:        const char *product_name;
        !           393:        struct device *next_module;
        !           394:        struct tulip_rx_desc rx_ring[RX_RING_SIZE];
        !           395:        struct tulip_tx_desc tx_ring[TX_RING_SIZE];
        !           396:        /* The saved address of a sent-in-place packet/buffer, for skfree(). */
        !           397:        struct sk_buff* tx_skbuff[TX_RING_SIZE];
        !           398:        /* The addresses of receive-in-place skbuffs. */
        !           399:        struct sk_buff* rx_skbuff[RX_RING_SIZE];
        !           400:        char *rx_buffs;                         /* Address of temporary Rx buffers. */
        !           401:        u32 setup_frame[48];            /* Pseudo-Tx frame to init address table. */
        !           402:        int chip_id;
        !           403:        int revision;
        !           404: #if LINUX_VERSION_CODE > 0x20139
        !           405:        struct net_device_stats stats;
        !           406: #else
        !           407:        struct enet_statistics stats;
        !           408: #endif
        !           409:        struct timer_list timer;        /* Media selection timer. */
        !           410:        int interrupt;                          /* In-interrupt flag. */
        !           411: #ifdef SMP_CHECK
        !           412:        int smp_proc_id;                        /* Which processor in IRQ handler. */
        !           413: #endif
        !           414:        unsigned int cur_rx, cur_tx;            /* The next free ring entry */
        !           415:        unsigned int dirty_rx, dirty_tx;        /* The ring entries to be free()ed. */
        !           416:        unsigned int tx_full:1;                         /* The Tx queue is full. */
        !           417:        unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
        !           418:        unsigned int full_duplex_lock:1;
        !           419:        unsigned int fake_addr:1;                       /* Multiport board faked address. */
        !           420:        unsigned int default_port:4;            /* Last dev->if_port value. */
        !           421:        unsigned int media2:4;                          /* Secondary monitored media port. */
        !           422:        unsigned int medialock:1;                       /* Don't sense media type. */
        !           423:        unsigned int mediasense:1;                      /* Media sensing in progress. */
        !           424:        unsigned int csr6;                                      /* Current CSR6 control settings. */
        !           425:        unsigned char eeprom[128];                      /* Serial EEPROM contents. */
        !           426:        u16 to_advertise;                                       /* NWay capabilities advertised.  */
        !           427:        u16 advertising[4];
        !           428:        signed char phys[4], mii_cnt;           /* MII device addresses. */
        !           429:        struct mediatable *mtable;
        !           430:        int cur_index;                                          /* Current media index. */
        !           431:        unsigned char pci_bus, pci_dev_fn;
        !           432:        int pad0, pad1;                                         /* Used for 8-byte alignment */
        !           433: };
        !           434: 
        !           435: static struct device *tulip_probe1(int pci_bus, int pci_devfn,
        !           436:                                                                   struct device *dev,
        !           437:                                                                   int chip_id, int options);
        !           438: static void parse_eeprom(struct device *dev);
        !           439: static int read_eeprom(long ioaddr, int location);
        !           440: static int mdio_read(struct device *dev, int phy_id, int location);
        !           441: static void mdio_write(struct device *dev, int phy_id, int location, int value);
        !           442: static void select_media(struct device *dev, int startup);
        !           443: static int tulip_open(struct device *dev);
        !           444: static void tulip_timer(unsigned long data);
        !           445: static void tulip_tx_timeout(struct device *dev);
        !           446: static void tulip_init_ring(struct device *dev);
        !           447: static int tulip_start_xmit(struct sk_buff *skb, struct device *dev);
        !           448: static int tulip_rx(struct device *dev);
        !           449: static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs);
        !           450: static int tulip_close(struct device *dev);
        !           451: static struct enet_statistics *tulip_get_stats(struct device *dev);
        !           452: #ifdef HAVE_PRIVATE_IOCTL
        !           453: static int private_ioctl(struct device *dev, struct ifreq *rq, int cmd);
        !           454: #endif
        !           455: #ifdef NEW_MULTICAST
        !           456: static void set_rx_mode(struct device *dev);
        !           457: #else
        !           458: static void set_rx_mode(struct device *dev, int num_addrs, void *addrs);
        !           459: #endif
        !           460: 
        !           461: 
        !           462: 
        !           463: /* A list of all installed Tulip devices, for removing the driver module. */
        !           464: static struct device *root_tulip_dev = NULL;
        !           465: 
        !           466: /* This 21040 probe no longer uses a large fixed contiguous Rx buffer region,
        !           467:    but now receives directly into full-sized skbuffs that are allocated
        !           468:    at open() time.
        !           469:    This allows the probe routine to use the old driver initialization
        !           470:    interface. */
        !           471: 
        !           472: int tulip_probe(struct device *dev)
        !           473: {
        !           474:        int cards_found = 0;
        !           475:        static int pci_index = 0;       /* Static, for multiple probe calls. */
        !           476:        unsigned char pci_bus, pci_device_fn;
        !           477: 
        !           478:        /* Ideally we would detect all network cards in slot order.  That would
        !           479:           be best done a central PCI probe dispatch, which wouldn't work
        !           480:           well with the current structure.  So instead we detect just the
        !           481:           Tulip cards in slot order. */
        !           482: 
        !           483: #if LINUX_VERSION_CODE >= 0x20155
        !           484:        if (! pci_present())
        !           485:                return -ENODEV;
        !           486: #else
        !           487:        if (! pcibios_present())
        !           488:                return -ENODEV;
        !           489: #endif
        !           490:        for (;pci_index < 0xff; pci_index++) {
        !           491:                u16 vendor, device, pci_command, new_command;
        !           492:                u32 pci_ioaddr;
        !           493:                int chip_idx = 0;
        !           494: 
        !           495:                if (pcibios_find_class
        !           496:                        (PCI_CLASS_NETWORK_ETHERNET << 8,
        !           497:                         reverse_probe ? 0xfe - pci_index : pci_index,
        !           498:                         &pci_bus, &pci_device_fn) != PCIBIOS_SUCCESSFUL)
        !           499:                        if (reverse_probe)
        !           500:                                continue;
        !           501:                        else
        !           502:                                break;
        !           503:                pcibios_read_config_word(pci_bus, pci_device_fn,
        !           504:                                                                 PCI_VENDOR_ID, &vendor);
        !           505:                pcibios_read_config_word(pci_bus, pci_device_fn,
        !           506:                                                                 PCI_DEVICE_ID, &device);
        !           507: 
        !           508:                for (chip_idx = 0; tulip_tbl[chip_idx].chip_name; chip_idx++)
        !           509:                        if (vendor == tulip_tbl[chip_idx].vendor_id  &&
        !           510:                                device == tulip_tbl[chip_idx].device_id)
        !           511:                                break;
        !           512:                if (tulip_tbl[chip_idx].chip_name == 0) {
        !           513:                        if (vendor == PCI_VENDOR_ID_DEC  ||
        !           514:                                vendor == PCI_VENDOR_ID_LITEON)
        !           515:                                printk(KERN_INFO "Unknown Tulip-style PCI ethernet chip type"
        !           516:                                           " %4.4x %4.4x"" detected: not configured.\n",
        !           517:                                           vendor, device);
        !           518:                        continue;
        !           519:                }
        !           520: #if LINUX_VERSION_CODE >= 0x20155
        !           521:                pci_ioaddr = pci_find_slot(pci_bus, pci_device_fn)->base_address[0];
        !           522: #else
        !           523:                pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_0,
        !           524:                                                                  &pci_ioaddr);
        !           525: #endif
        !           526:                /* Remove I/O space marker in bit 0. */
        !           527:                pci_ioaddr &= ~3;
        !           528: 
        !           529:                if (tulip_debug > 2)
        !           530:                        printk(KERN_DEBUG "Found %s at I/O %#x.\n",
        !           531:                                   tulip_tbl[chip_idx].chip_name, pci_ioaddr);
        !           532: 
        !           533:                if (check_region(pci_ioaddr, tulip_tbl[chip_idx].io_size))
        !           534:                        continue;
        !           535: 
        !           536:                pcibios_read_config_word(pci_bus, pci_device_fn,
        !           537:                                                                 PCI_COMMAND, &pci_command);
        !           538:                new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
        !           539:                if (pci_command != new_command) {
        !           540:                        printk(KERN_INFO "  The PCI BIOS has not enabled this"
        !           541:                                   " device!  Updating PCI command %4.4x->%4.4x.\n",
        !           542:                                   pci_command, new_command);
        !           543:                        pcibios_write_config_word(pci_bus, pci_device_fn,
        !           544:                                                                          PCI_COMMAND, new_command);
        !           545:                }
        !           546: 
        !           547:                dev = tulip_probe1(pci_bus, pci_device_fn, dev, chip_idx, cards_found);
        !           548: 
        !           549:                /* Get and check the bus-master and latency values. */
        !           550:                if (dev) {
        !           551:                        unsigned char pci_latency;
        !           552:                        pcibios_read_config_byte(pci_bus, pci_device_fn,
        !           553:                                                                         PCI_LATENCY_TIMER, &pci_latency);
        !           554:                        if (pci_latency < 10) {
        !           555:                                printk(KERN_INFO "  PCI latency timer (CFLT) is "
        !           556:                                           "unreasonably low at %d.  Setting to 64 clocks.\n",
        !           557:                                           pci_latency);
        !           558:                                pcibios_write_config_byte(pci_bus, pci_device_fn,
        !           559:                                                                                  PCI_LATENCY_TIMER, 64);
        !           560:                        } else if (tulip_debug > 1)
        !           561:                                printk(KERN_INFO "  PCI latency timer (CFLT) is %#x, "
        !           562:                                           " PCI command is %4.4x.\n",
        !           563:                                           pci_latency, new_command);
        !           564:                        /* Bring the 21143 out power-down mode. */
        !           565:                        if (device == PCI_DEVICE_ID_DEC_TULIP_21142)
        !           566:                                pcibios_write_config_dword(pci_bus, pci_device_fn,
        !           567:                                                                                   0x40, 0x40000000);
        !           568:                        dev = 0;
        !           569:                        cards_found++;
        !           570:                }
        !           571:        }
        !           572: 
        !           573:        return cards_found ? 0 : -ENODEV;
        !           574: }
        !           575: 
        !           576: static struct device *tulip_probe1(int pci_bus, int pci_device_fn,
        !           577:                                                                   struct device *dev,
        !           578:                                                                   int chip_id, int board_idx)
        !           579: {
        !           580:        static int did_version = 0;                     /* Already printed version info. */
        !           581:        struct tulip_private *tp;
        !           582:        long ioaddr;
        !           583:        int irq;
        !           584:        /* See note below on the multiport cards. */
        !           585:        static unsigned char last_phys_addr[6] = {0x00, 'L', 'i', 'n', 'u', 'x'};
        !           586:        static int last_irq = 0;
        !           587:        static int multiport_cnt = 0;           /* For four-port boards w/one EEPROM */
        !           588:        int i;
        !           589:        unsigned short sum;
        !           590: 
        !           591:        if (tulip_debug > 0  &&  did_version++ == 0)
        !           592:                printk(KERN_INFO "%s", version);
        !           593: 
        !           594:        dev = init_etherdev(dev, 0);
        !           595: 
        !           596: #if LINUX_VERSION_CODE >= 0x20155
        !           597:        irq = pci_find_slot(pci_bus, pci_device_fn)->irq;
        !           598:        ioaddr = pci_find_slot(pci_bus, pci_device_fn)->base_address[0];
        !           599: #else
        !           600:        {
        !           601:                u8 pci_irq_line;
        !           602:                u32 pci_ioaddr;
        !           603:                pcibios_read_config_byte(pci_bus, pci_device_fn,
        !           604:                                                                 PCI_INTERRUPT_LINE, &pci_irq_line);
        !           605:                pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_0,
        !           606:                                                                  &pci_ioaddr);
        !           607:                irq = pci_irq_line;
        !           608:                ioaddr = pci_ioaddr;
        !           609:        }
        !           610: #endif
        !           611:        /* Remove I/O space marker in bit 0. */
        !           612:        ioaddr &= ~3;
        !           613: 
        !           614:        printk(KERN_INFO "%s: %s at %#3lx,",
        !           615:                   dev->name, tulip_tbl[chip_id].chip_name, ioaddr);
        !           616: 
        !           617:        /* Stop the chip's Tx and Rx processes. */
        !           618:        outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
        !           619:        /* Clear the missed-packet counter. */
        !           620:        (volatile int)inl(ioaddr + CSR8);
        !           621: 
        !           622:        if (chip_id == DC21041) {
        !           623:                if (inl(ioaddr + CSR9) & 0x8000) {
        !           624:                        printk(" 21040 compatible mode,");
        !           625:                        chip_id = DC21040;
        !           626:                } else {
        !           627:                        printk(" 21041 mode,");
        !           628:                }
        !           629:        }
        !           630: 
        !           631:        /* The station address ROM is read byte serially.  The register must
        !           632:           be polled, waiting for the value to be read bit serially from the
        !           633:           EEPROM.
        !           634:           */
        !           635:        sum = 0;
        !           636:        if (chip_id == DC21040) {
        !           637:                outl(0, ioaddr + CSR9);         /* Reset the pointer with a dummy write. */
        !           638:                for (i = 0; i < 6; i++) {
        !           639:                        int value, boguscnt = 100000;
        !           640:                        do
        !           641:                                value = inl(ioaddr + CSR9);
        !           642:                        while (value < 0  && --boguscnt > 0);
        !           643:                        dev->dev_addr[i] = value;
        !           644:                        sum += value & 0xff;
        !           645:                }
        !           646:        } else if (chip_id == LC82C168) {
        !           647:                for (i = 0; i < 3; i++) {
        !           648:                        int value, boguscnt = 100000;
        !           649:                        outl(0x600 | i, ioaddr + 0x98);
        !           650:                        do
        !           651:                                value = inl(ioaddr + CSR9);
        !           652:                        while (value < 0  && --boguscnt > 0);
        !           653:                        ((u16*)dev->dev_addr)[i] = value;
        !           654:                        sum += value & 0xffff;
        !           655:                }
        !           656:        } else {        /* Must be a new chip, with a serial EEPROM interface. */
        !           657:                /* We read the whole EEPROM, and sort it out later.  DEC has a
        !           658:                   specification _Digital Semiconductor 21X4 Serial ROM Format_
        !           659:                   but early vendor boards just put the address in the first six
        !           660:                   EEPROM locations. */
        !           661:                unsigned char ee_data[128];
        !           662:                int sa_offset = 0;
        !           663: 
        !           664:                for (i = 0; i < sizeof(ee_data)/2; i++)
        !           665:                        ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i);
        !           666: 
        !           667:                /* Detect the simple EEPROM format by the duplicated station addr. */
        !           668:                for (i = 0; i < 8; i ++)
        !           669:                        if (ee_data[i] != ee_data[16+i])
        !           670:                                sa_offset = 20;
        !           671:                if (ee_data[0] == 0xff  &&  ee_data[1] == 0xff &&  ee_data[2] == 0) {
        !           672:                        sa_offset = 2;          /* Grrr, damn Matrox boards. */
        !           673:                        multiport_cnt = 4;
        !           674:                }
        !           675:                for (i = 0; i < 6; i ++) {
        !           676:                        dev->dev_addr[i] = ee_data[i + sa_offset];
        !           677:                        sum += ee_data[i + sa_offset];
        !           678:                }
        !           679:        }
        !           680:        /* Lite-On boards have the address byte-swapped. */
        !           681:        if (dev->dev_addr[0] == 0xA0  &&  dev->dev_addr[1] == 0x00)
        !           682:                for (i = 0; i < 6; i+=2) {
        !           683:                        char tmp = dev->dev_addr[i];
        !           684:                        dev->dev_addr[i] = dev->dev_addr[i+1];
        !           685:                        dev->dev_addr[i+1] = tmp;
        !           686:                }
        !           687:        /* On the Zynx 315 Etherarray and other multiport boards only the
        !           688:           first Tulip has an EEPROM.
        !           689:           The addresses of the subsequent ports are derived from the first.
        !           690:           Many PCI BIOSes also incorrectly report the IRQ line, so we correct
        !           691:           that here as well. */
        !           692:        if (sum == 0  || sum == 6*0xff) {
        !           693:                printk(" EEPROM not present,");
        !           694:                for (i = 0; i < 5; i++)
        !           695:                        dev->dev_addr[i] = last_phys_addr[i];
        !           696:                dev->dev_addr[i] = last_phys_addr[i] + 1;
        !           697: #if defined(__i386__)          /* This BIOS bug doesn't exist on Alphas. */
        !           698:                irq = last_irq;
        !           699: #endif
        !           700:        }
        !           701: 
        !           702:        for (i = 0; i < 6; i++)
        !           703:                printk(" %2.2x", last_phys_addr[i] = dev->dev_addr[i]);
        !           704:        printk(", IRQ %d.\n", irq);
        !           705:        last_irq = irq;
        !           706: 
        !           707:        /* We do a request_region() only to register /proc/ioports info. */
        !           708:        /* Note that proper size is tulip_tbl[chip_id].chip_name, but... */
        !           709:        request_region(ioaddr, TULIP_TOTAL_SIZE, dev->name);
        !           710: 
        !           711:        dev->base_addr = ioaddr;
        !           712:        dev->irq = irq;
        !           713: 
        !           714:        /* Make certain the data structures are quadword aligned. */
        !           715:        tp = (void *)(((long)kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA) + 7) & ~7);
        !           716:        memset(tp, 0, sizeof(*tp));
        !           717:        dev->priv = tp;
        !           718: 
        !           719:        tp->next_module = root_tulip_dev;
        !           720:        root_tulip_dev = dev;
        !           721: 
        !           722:        tp->pci_bus = pci_bus;
        !           723:        tp->pci_dev_fn = pci_device_fn;
        !           724:        tp->chip_id = chip_id;
        !           725: 
        !           726: #ifdef TULIP_FULL_DUPLEX
        !           727:        tp->full_duplex = 1;
        !           728:        tp->full_duplex_lock = 1;
        !           729: #endif
        !           730: #ifdef TULIP_DEFAULT_MEDIA
        !           731:        tp->default_port = TULIP_DEFAULT_MEDIA;
        !           732: #endif
        !           733: #ifdef TULIP_NO_MEDIA_SWITCH
        !           734:        tp->medialock = 1;
        !           735: #endif
        !           736: 
        !           737:        /* The lower four bits are the media type. */
        !           738:        if (board_idx >= 0  &&  board_idx < MAX_UNITS) {
        !           739:                tp->default_port = options[board_idx] & 15;
        !           740:                if ((options[board_idx] & 0x90) || full_duplex[board_idx] > 0)
        !           741:                        tp->full_duplex = 1;
        !           742:                if (mtu[board_idx] > 0)
        !           743:                        dev->mtu = mtu[board_idx];
        !           744:        }
        !           745:        if (dev->mem_start)
        !           746:                tp->default_port = dev->mem_start;
        !           747:        if (tp->default_port) {
        !           748:                tp->medialock = 1;
        !           749:                if (media_cap[tp->default_port] & MediaAlwaysFD)
        !           750:                        tp->full_duplex = 1;
        !           751:        }
        !           752:        if (tp->full_duplex)
        !           753:                tp->full_duplex_lock = 1;
        !           754: 
        !           755:        /* This is logically part of probe1(), but too complex to write inline. */
        !           756:        if (tulip_tbl[chip_id].flags & HAS_MEDIA_TABLE)
        !           757:                parse_eeprom(dev);
        !           758: 
        !           759:        if (media_cap[tp->default_port] & MediaIsMII) {
        !           760:                u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
        !           761:                tp->to_advertise = media2advert[tp->default_port - 9];
        !           762:        } else
        !           763:                tp->to_advertise = 0x03e1;
        !           764: 
        !           765:        if ((tp->mtable  &&  tp->mtable->has_mii) ||
        !           766:                ( ! tp->mtable  &&  (tulip_tbl[tp->chip_id].flags & HAS_MII))) {
        !           767:                int phy, phy_idx;
        !           768:                /* Find the connected MII xcvrs.
        !           769:                   Doing this in open() would allow detecting external xcvrs later,
        !           770:                   but takes much time. */
        !           771:                for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys);
        !           772:                         phy++) {
        !           773:                        int mii_status = mdio_read(dev, phy, 1);
        !           774:                        if (mii_status != 0xffff  &&  mii_status != 0x0000) {
        !           775:                                int mii_reg0 = mdio_read(dev, phy, 0);
        !           776:                                int reg4 = ((mii_status>>6) & tp->to_advertise) | 1;
        !           777:                                tp->phys[phy_idx] = phy;
        !           778:                                tp->advertising[phy_idx++] = reg4;
        !           779:                                printk(KERN_INFO "%s:  MII transceiver found at MDIO address "
        !           780:                                           "%d, config %4.4x status %4.4x.\n",
        !           781:                                           dev->name, phy, mii_reg0, mii_status);
        !           782:                                if (1 || (media_cap[tp->default_port] & MediaIsMII)) {
        !           783:                                        printk(KERN_DEBUG "%s:  Advertising %4.4x on PHY %d,"
        !           784:                                                   " previously advertising %4.4x.\n",
        !           785:                                                   dev->name, reg4, phy, mdio_read(dev, phy, 4));
        !           786:                                        mdio_write(dev, phy, 4, reg4);
        !           787:                                }
        !           788:                                /* Enable autonegotiation: some boards default to off. */
        !           789:                                mdio_write(dev, phy, 0, mii_reg0 |
        !           790:                                                   (tp->full_duplex ? 0x1100 : 0x1000) |
        !           791:                                                   (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0));
        !           792:                        }
        !           793:                }
        !           794:                tp->mii_cnt = phy_idx;
        !           795:                if (tp->mtable  &&  tp->mtable->has_mii  &&  phy_idx == 0) {
        !           796:                        printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n",
        !           797:                                   dev->name);
        !           798:                        tp->phys[0] = 1;
        !           799:                }
        !           800:        }
        !           801: 
        !           802:        /* The Tulip-specific entries in the device structure. */
        !           803:        dev->open = &tulip_open;
        !           804:        dev->hard_start_xmit = &tulip_start_xmit;
        !           805:        dev->stop = &tulip_close;
        !           806:        dev->get_stats = &tulip_get_stats;
        !           807: #ifdef HAVE_PRIVATE_IOCTL
        !           808:        dev->do_ioctl = &private_ioctl;
        !           809: #endif
        !           810: #ifdef HAVE_MULTICAST
        !           811:        dev->set_multicast_list = &set_rx_mode;
        !           812: #endif
        !           813: 
        !           814:        /* Reset the xcvr interface and turn on heartbeat. */
        !           815:        switch (chip_id) {
        !           816:        case DC21041:
        !           817:                outl(0x00000000, ioaddr + CSR13);
        !           818:                outl(0xFFFFFFFF, ioaddr + CSR14);
        !           819:                outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */
        !           820:                outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6);
        !           821:                outl(0x0000EF05, ioaddr + CSR13);
        !           822:                break;
        !           823:        case DC21040:
        !           824:                outl(0x00000000, ioaddr + CSR13);
        !           825:                outl(0x00000004, ioaddr + CSR13);
        !           826:                break;
        !           827:        case DC21140: default:
        !           828:                if (tp->mtable)
        !           829:                        outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
        !           830:                break;
        !           831:        case DC21142:
        !           832:                outl(0x82420200, ioaddr + CSR6);
        !           833:                outl(0x0001, ioaddr + CSR13);
        !           834:                outl(0x0003FFFF, ioaddr + CSR14);
        !           835:                outl(0x0008, ioaddr + CSR15);
        !           836:                outl(0x0001, ioaddr + CSR13);
        !           837:                outl(0x1301, ioaddr + CSR12); /* Start NWay. */
        !           838:                break;
        !           839:        case LC82C168:
        !           840:                if ( ! tp->mii_cnt) {
        !           841:                        outl(0x00420000, ioaddr + CSR6);
        !           842:                        outl(0x30, ioaddr + CSR12);
        !           843:                        outl(0x0001F078, ioaddr + 0xB8);
        !           844:                        outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
        !           845:                }
        !           846:                break;
        !           847:        case MX98713: case MX98715: case MX98725:
        !           848:                outl(0x00000000, ioaddr + CSR6);
        !           849:                outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
        !           850:                outl(0x00000001, ioaddr + CSR13);
        !           851:                break;
        !           852:        }
        !           853: 
        !           854:        return dev;
        !           855: }
        !           856: 
        !           857: /* Serial EEPROM section. */
        !           858: /* The main routine to parse the very complicated SROM structure.
        !           859:    Search www.digital.com for "21X4 SROM" to get details.
        !           860:    This code is very complex, and will require changes to support
        !           861:    additional cards, so I'll be verbose about what is going on.
        !           862:    */
        !           863: 
        !           864: /* Known cards that have old-style EEPROMs. */
        !           865: static struct fixups {
        !           866:   char *name;
        !           867:   unsigned char addr0, addr1, addr2;
        !           868:   u16 newtable[32];                            /* Max length below. */
        !           869: } eeprom_fixups[] = {
        !           870:   {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
        !           871:                                                  0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
        !           872:   {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x021f,
        !           873:                                                           0x0000, 0x009E, /* 10baseT */
        !           874:                                                           0x0903, 0x006D, /* 100baseTx */ }},
        !           875:   {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x033f,
        !           876:                                                                 0x0107, 0x8021, /* 100baseFx */
        !           877:                                                                 0x0108, 0x8021, /* 100baseFx-FD */
        !           878:                                                                 0x0103, 0x006D, /* 100baseTx */ }},
        !           879:   {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0313,
        !           880:                                                           0x1001, 0x009E, /* 10base2, CSR12 0x10*/
        !           881:                                                           0x0000, 0x009E, /* 10baseT */
        !           882:                                                           0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ }},
        !           883:   {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x031F,
        !           884:                                                        0x1B01, 0x0000, /* 10base2,   CSR12 0x1B */
        !           885:                                                        0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */ 
        !           886:                                                        0x0B00, 0x009E, /* 10baseT,   CSR12 0x0B */
        !           887:    }},
        !           888:   {0, 0, 0, 0, {}}};
        !           889: 
        !           890: static const char * block_name[] = {"21140 non-MII", "21140 MII PHY",
        !           891:  "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
        !           892: 
        !           893: #define EEPROM_SIZE 128
        !           894: #if defined(__i386__)
        !           895: #define get_u16(ptr) (*(u16 *)(ptr))
        !           896: #else
        !           897: #define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8))
        !           898: #endif
        !           899: 
        !           900: static void parse_eeprom(struct device *dev)
        !           901: {
        !           902:        /* The last media info list parsed, for multiport boards.  */
        !           903:        static struct mediatable *last_mediatable = NULL;
        !           904:        static unsigned char *last_ee_data = NULL;
        !           905:        static int controller_index = 0;
        !           906:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !           907:        long ioaddr = dev->base_addr;
        !           908:        unsigned char *ee_data = tp->eeprom;
        !           909:        int i;
        !           910: 
        !           911:        tp->mtable = 0;
        !           912:        for (i = 0; i < EEPROM_SIZE/2; i++)
        !           913:                ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i);
        !           914: 
        !           915:        /* Detect an old-style (SA only) EEPROM layout:
        !           916:           memcmp(eedata, eedata+16, 8). */
        !           917:        for (i = 0; i < 8; i ++)
        !           918:                if (ee_data[i] != ee_data[16+i])
        !           919:                        break;
        !           920:        if (i >= 8) {
        !           921:                if (ee_data[0] == 0xff) {
        !           922:                        if (last_mediatable) {
        !           923:                                controller_index++;
        !           924:                                printk(KERN_INFO "%s:  Controller %d of multiport board.\n",
        !           925:                                           dev->name, controller_index);
        !           926:                                tp->mtable = last_mediatable;
        !           927:                                ee_data = last_ee_data;
        !           928:                                goto subsequent_board;
        !           929:                        } else
        !           930:                                printk(KERN_INFO "%s:  Missing EEPROM, this interface may "
        !           931:                                           "not work correctly!\n",
        !           932:                           dev->name);
        !           933:                        return;
        !           934:                }
        !           935:          /* Do a fix-up based on the vendor half of the station address prefix. */
        !           936:          for (i = 0; eeprom_fixups[i].name; i++) {
        !           937:                if (dev->dev_addr[0] == eeprom_fixups[i].addr0
        !           938:                        &&  dev->dev_addr[1] == eeprom_fixups[i].addr1
        !           939:                        &&  dev->dev_addr[2] == eeprom_fixups[i].addr2) {
        !           940:                  if (dev->dev_addr[2] == 0xE8  &&  ee_data[0x1a] == 0x55)
        !           941:                          i++;                  /* An Accton EN1207, not an outlaw Maxtech. */
        !           942:                  memcpy(ee_data + 26, eeprom_fixups[i].newtable,
        !           943:                                 sizeof(eeprom_fixups[i].newtable));
        !           944:                  printk(KERN_INFO "%s: Old format EEPROM on '%s' board.  Using"
        !           945:                                 " substitute media control info.\n",
        !           946:                                 dev->name, eeprom_fixups[i].name);
        !           947:                  break;
        !           948:                }
        !           949:          }
        !           950:          if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
        !           951:                printk(KERN_INFO "%s: Old style EEPROM -- no media selection information.\n",
        !           952:                           dev->name);
        !           953:                return;
        !           954:          }
        !           955:        }
        !           956:        if (tulip_debug > 1) {
        !           957:          printk(KERN_DEBUG "read_eeprom:");
        !           958:          for (i = 0; i < 64; i++) {
        !           959:                printk("%s%4.4x", (i & 7) == 0 ? "\n" KERN_DEBUG : " ",
        !           960:                           read_eeprom(ioaddr, i));
        !           961:          }
        !           962:          printk("\n");
        !           963:        }
        !           964:        
        !           965:        controller_index = 0;
        !           966:        if (ee_data[19] > 1) {          /* Multiport board. */
        !           967:                last_ee_data = ee_data;
        !           968:        }
        !           969: subsequent_board:
        !           970: 
        !           971:        if (ee_data[27] == 0) {         /* No valid media table. */
        !           972:        } else if (tp->chip_id == DC21041) {
        !           973:                unsigned char *p = (void *)ee_data + ee_data[27 + controller_index*3];
        !           974:                short media;
        !           975:                int count;
        !           976: 
        !           977:                media = get_u16(p);
        !           978:                p += 2;
        !           979:                count = *p++;
        !           980: 
        !           981:                printk(KERN_INFO "%s:21041 Media information at %d, default media "
        !           982:                           "%4.4x (%s).\n", dev->name, ee_data[27], media,
        !           983:                           media & 0x0800 ? "Autosense" : medianame[media & 15]);
        !           984:                for (i = 0; i < count; i++) {
        !           985:                        unsigned char media_code = *p++;
        !           986:                        u16 csrvals[3];
        !           987:                        int idx;
        !           988:                        for (idx = 0; idx < 3; idx++) {
        !           989:                                csrvals[idx] = get_u16(p);
        !           990:                                p += 2;
        !           991:                        }
        !           992:                        if (media_code & 0x40) {
        !           993:                                printk(KERN_INFO "%s:  21041 media %2.2x (%s),"
        !           994:                                           " csr13 %4.4x csr14 %4.4x csr15 %4.4x.\n",
        !           995:                                           dev->name, media_code & 15, medianame[media_code & 15],
        !           996:                                           csrvals[0], csrvals[1], csrvals[2]);
        !           997:                        } else
        !           998:                                printk(KERN_INFO "%s:  21041 media #%d, %s.\n",
        !           999:                                           dev->name, media_code & 15, medianame[media_code & 15]);
        !          1000:                }
        !          1001:        } else {
        !          1002:                unsigned char *p = (void *)ee_data + ee_data[27];
        !          1003:                unsigned char csr12dir = 0;
        !          1004:                int count;
        !          1005:                struct mediatable *mtable;
        !          1006:                u16 media = get_u16(p);
        !          1007: 
        !          1008:                p += 2;
        !          1009:                if (tulip_tbl[tp->chip_id].flags & CSR12_IN_SROM)
        !          1010:                        csr12dir = *p++;
        !          1011:                count = *p++;
        !          1012:                mtable = (struct mediatable *)
        !          1013:                        kmalloc(sizeof(struct mediatable) + count*sizeof(struct medialeaf),
        !          1014:                                        GFP_KERNEL);
        !          1015:                if (mtable == NULL)
        !          1016:                        return;                         /* Horrible, impossible failure. */
        !          1017:                last_mediatable = tp->mtable = mtable;
        !          1018:                mtable->defaultmedia = media;
        !          1019:                mtable->leafcount = count;
        !          1020:                mtable->csr12dir = csr12dir;
        !          1021:                mtable->has_nonmii = mtable->has_mii = 0;
        !          1022: 
        !          1023:                printk(KERN_INFO "%s:  EEPROM default media type %s.\n", dev->name,
        !          1024:                           media & 0x0800 ? "Autosense" : medianame[media & 15]);
        !          1025:                for (i = 0; i < count; i++) {
        !          1026:                        struct medialeaf *leaf = &mtable->mleaf[i];
        !          1027:                        
        !          1028:                        if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
        !          1029:                                leaf->type = 0;
        !          1030:                                leaf->media = p[0] & 0x3f;
        !          1031:                                leaf->leafdata = p;
        !          1032:                                if ((p[2] & 0x61) == 0x01)      /* Bogus, but Znyx boards do it. */
        !          1033:                                        mtable->has_mii = 1;
        !          1034:                                p += 4;
        !          1035:                        } else {
        !          1036:                                leaf->type = p[1];
        !          1037:                                if (p[1] & 1) {
        !          1038:                                        mtable->has_mii = 1;
        !          1039:                                        leaf->media = 11;
        !          1040:                                } else {
        !          1041:                                        mtable->has_nonmii = 1;
        !          1042:                                        leaf->media = p[2] & 0x0f;
        !          1043:                                }
        !          1044:                                leaf->leafdata = p + 2;
        !          1045:                                p += (p[0] & 0x3f) + 1;
        !          1046:                        }
        !          1047:                        if (tulip_debug > 1  &&  leaf->media == 11) {
        !          1048:                                unsigned char *bp = leaf->leafdata;
        !          1049:                                printk(KERN_INFO "%s:  MII interface PHY %d, setup/reset "
        !          1050:                                           "sequences %d/%d long, capabilities %2.2x %2.2x.\n",
        !          1051:                                           dev->name, bp[0], bp[1], bp[1 + bp[1]*2],
        !          1052:                                           bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]);
        !          1053:                        }
        !          1054:                        printk(KERN_INFO "%s:  Index #%d - Media %s (#%d) described "
        !          1055:                                   "by a %s (%d) block.\n",
        !          1056:                                   dev->name, i, medianame[leaf->media], leaf->media,
        !          1057:                                   block_name[leaf->type], leaf->type);
        !          1058:                }
        !          1059:        }
        !          1060: }
        !          1061: /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/
        !          1062: 
        !          1063: /*  EEPROM_Ctrl bits. */
        !          1064: #define EE_SHIFT_CLK   0x02    /* EEPROM shift clock. */
        !          1065: #define EE_CS                  0x01    /* EEPROM chip select. */
        !          1066: #define EE_DATA_WRITE  0x04    /* EEPROM chip data in. */
        !          1067: #define EE_WRITE_0             0x01
        !          1068: #define EE_WRITE_1             0x05
        !          1069: #define EE_DATA_READ   0x08    /* EEPROM chip data out. */
        !          1070: #define EE_ENB                 (0x4800 | EE_CS)
        !          1071: 
        !          1072: /* Delay between EEPROM clock transitions.
        !          1073:    The 1.2 code is a "nasty" timing loop, but PC compatible machines are
        !          1074:    *supposed* to delay an ISA-compatible period for the SLOW_DOWN_IO macro.  */
        !          1075: #ifdef _LINUX_DELAY_H
        !          1076: #define eeprom_delay(nanosec)  udelay((nanosec + 999)/1000)
        !          1077: #else
        !          1078: #define eeprom_delay(nanosec)  do { int _i = 3; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
        !          1079: #endif
        !          1080: 
        !          1081: /* The EEPROM commands include the alway-set leading bit. */
        !          1082: #define EE_WRITE_CMD   (5 << 6)
        !          1083: #define EE_READ_CMD            (6 << 6)
        !          1084: #define EE_ERASE_CMD   (7 << 6)
        !          1085: 
        !          1086: static int read_eeprom(long ioaddr, int location)
        !          1087: {
        !          1088:        int i;
        !          1089:        unsigned short retval = 0;
        !          1090:        long ee_addr = ioaddr + CSR9;
        !          1091:        int read_cmd = location | EE_READ_CMD;
        !          1092:        
        !          1093:        outl(EE_ENB & ~EE_CS, ee_addr);
        !          1094:        outl(EE_ENB, ee_addr);
        !          1095:        
        !          1096:        /* Shift the read command bits out. */
        !          1097:        for (i = 10; i >= 0; i--) {
        !          1098:                short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
        !          1099:                outl(EE_ENB | dataval, ee_addr);
        !          1100:                eeprom_delay(100);
        !          1101:                outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
        !          1102:                eeprom_delay(150);
        !          1103:                outl(EE_ENB | dataval, ee_addr);        /* Finish EEPROM a clock tick. */
        !          1104:                eeprom_delay(250);
        !          1105:        }
        !          1106:        outl(EE_ENB, ee_addr);
        !          1107:        
        !          1108:        for (i = 16; i > 0; i--) {
        !          1109:                outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
        !          1110:                eeprom_delay(100);
        !          1111:                retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
        !          1112:                outl(EE_ENB, ee_addr);
        !          1113:                eeprom_delay(100);
        !          1114:        }
        !          1115: 
        !          1116:        /* Terminate the EEPROM access. */
        !          1117:        outl(EE_ENB & ~EE_CS, ee_addr);
        !          1118:        return retval;
        !          1119: }
        !          1120: 
        !          1121: /* MII transceiver control section.
        !          1122:    Read and write the MII registers using software-generated serial
        !          1123:    MDIO protocol.  See the MII specifications or DP83840A data sheet
        !          1124:    for details. */
        !          1125: 
        !          1126: /* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
        !          1127:    met by back-to-back PCI I/O cycles, but we insert a delay to avoid
        !          1128:    "overclocking" issues or future 66Mhz PCI. */
        !          1129: #define mdio_delay() inl(mdio_addr)
        !          1130: 
        !          1131: /* Read and write the MII registers using software-generated serial
        !          1132:    MDIO protocol.  It is just different enough from the EEPROM protocol
        !          1133:    to not share code.  The maxium data clock rate is 2.5 Mhz. */
        !          1134: #define MDIO_SHIFT_CLK 0x10000
        !          1135: #define MDIO_DATA_WRITE0 0x00000
        !          1136: #define MDIO_DATA_WRITE1 0x20000
        !          1137: #define MDIO_ENB               0x00000         /* Ignore the 0x02000 databook setting. */
        !          1138: #define MDIO_ENB_IN            0x40000
        !          1139: #define MDIO_DATA_READ 0x80000
        !          1140: 
        !          1141: static int mdio_read(struct device *dev, int phy_id, int location)
        !          1142: {
        !          1143:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1144:        int i;
        !          1145:        int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
        !          1146:        int retval = 0;
        !          1147:        long mdio_addr = dev->base_addr + CSR9;
        !          1148: 
        !          1149:        if (tp->chip_id == LC82C168) {
        !          1150:                long ioaddr = dev->base_addr;
        !          1151:                int i = 1000;
        !          1152:                outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
        !          1153:                while (--i > 0)
        !          1154:                        if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
        !          1155:                                return retval & 0xffff;
        !          1156:                return 0xffff;
        !          1157:        }
        !          1158: 
        !          1159:        /* Establish sync by sending at least 32 logic ones. */ 
        !          1160:        for (i = 32; i >= 0; i--) {
        !          1161:                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
        !          1162:                mdio_delay();
        !          1163:                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
        !          1164:                mdio_delay();
        !          1165:        }
        !          1166:        /* Shift the read command bits out. */
        !          1167:        for (i = 15; i >= 0; i--) {
        !          1168:                int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
        !          1169: 
        !          1170:                outl(MDIO_ENB | dataval, mdio_addr);
        !          1171:                mdio_delay();
        !          1172:                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
        !          1173:                mdio_delay();
        !          1174:        }
        !          1175:        /* Read the two transition, 16 data, and wire-idle bits. */
        !          1176:        for (i = 19; i > 0; i--) {
        !          1177:                outl(MDIO_ENB_IN, mdio_addr);
        !          1178:                mdio_delay();
        !          1179:                retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
        !          1180:                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
        !          1181:                mdio_delay();
        !          1182:        }
        !          1183:        return (retval>>1) & 0xffff;
        !          1184: }
        !          1185: 
        !          1186: static void mdio_write(struct device *dev, int phy_id, int location, int value)
        !          1187: {
        !          1188:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1189:        int i;
        !          1190:        int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
        !          1191:        long mdio_addr = dev->base_addr + CSR9;
        !          1192: 
        !          1193:        if (tp->chip_id == LC82C168) {
        !          1194:                long ioaddr = dev->base_addr;
        !          1195:                int i = 1000;
        !          1196:                outl(cmd, ioaddr + 0xA0);
        !          1197:                do
        !          1198:                        if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
        !          1199:                                break;
        !          1200:                while (--i > 0);
        !          1201:                return;
        !          1202:        }
        !          1203: 
        !          1204:        /* Establish sync by sending 32 logic ones. */ 
        !          1205:        for (i = 32; i >= 0; i--) {
        !          1206:                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
        !          1207:                mdio_delay();
        !          1208:                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
        !          1209:                mdio_delay();
        !          1210:        }
        !          1211:        /* Shift the command bits out. */
        !          1212:        for (i = 31; i >= 0; i--) {
        !          1213:                int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
        !          1214:                outl(MDIO_ENB | dataval, mdio_addr);
        !          1215:                mdio_delay();
        !          1216:                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
        !          1217:                mdio_delay();
        !          1218:        }
        !          1219:        /* Clear out extra bits. */
        !          1220:        for (i = 2; i > 0; i--) {
        !          1221:                outl(MDIO_ENB_IN, mdio_addr);
        !          1222:                mdio_delay();
        !          1223:                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
        !          1224:                mdio_delay();
        !          1225:        }
        !          1226:        return;
        !          1227: }
        !          1228: 
        !          1229: 
        !          1230: static int
        !          1231: tulip_open(struct device *dev)
        !          1232: {
        !          1233:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1234:        long ioaddr = dev->base_addr;
        !          1235:        int i = 0;
        !          1236: 
        !          1237:        /* On some chip revs we must set the MII/SYM port before the reset!? */
        !          1238:        if (tp->mii_cnt  ||  (tp->mtable  &&  tp->mtable->has_mii))
        !          1239:                outl(0x00040000, ioaddr + CSR6);
        !          1240: 
        !          1241:        /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
        !          1242:        outl(0x00000001, ioaddr + CSR0);
        !          1243: #ifdef _LINUX_DELAY_H
        !          1244:        udelay(2);
        !          1245: #else
        !          1246:        SLOW_DOWN_IO;
        !          1247: #endif
        !          1248:        /* Deassert reset.
        !          1249:           486: Set 8 longword cache alignment, 8 longword burst.
        !          1250:           586: Set 16 longword cache alignment, no burst limit.
        !          1251:           Cache alignment bits 15:14        Burst length 13:8
        !          1252:                0000    No alignment  0x00000000 unlimited              0800 8 longwords
        !          1253:                4000    8  longwords            0100 1 longword         1000 16 longwords
        !          1254:                8000    16 longwords            0200 2 longwords        2000 32 longwords
        !          1255:                C000    32  longwords           0400 4 longwords
        !          1256:           Wait the specified 50 PCI cycles after a reset by initializing
        !          1257:           Tx and Rx queues and the address filter list. */
        !          1258: #if defined(__alpha__)
        !          1259:        /* ToDo: Alpha setting could be better. */
        !          1260:        outl(0x01A00000 | 0xE000, ioaddr + CSR0);
        !          1261: #elif defined(__powerpc__)
        !          1262:        outl(0x01A00080 | 0x8000, ioaddr + CSR0);
        !          1263: #elif defined(__i386__)
        !          1264: #if defined(MODULE)
        !          1265:        /* When a module we don't have 'x86' to check. */
        !          1266:        outl(0x01A00000 | 0x4800, ioaddr + CSR0);
        !          1267: #else
        !          1268: #if (LINUX_VERSION_CODE > 0x2014c)
        !          1269: #define x86 boot_cpu_data.x86
        !          1270: #endif
        !          1271:        outl(0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000), ioaddr + CSR0);
        !          1272:        if (x86 <= 4)
        !          1273:          printk(KERN_INFO "%s: This is a 386/486 PCI system, setting cache "
        !          1274:                         "alignment to %x.\n", dev->name,
        !          1275:                         0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000));
        !          1276: #endif
        !          1277: #else
        !          1278:        outl(0x01A00000 | 0x4800, ioaddr + CSR0);
        !          1279: #warning Processor architecture undefined!
        !          1280: #endif
        !          1281: 
        !          1282: #ifdef SA_SHIRQ
        !          1283:        if (request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)) {
        !          1284:                return -EAGAIN;
        !          1285:        }
        !          1286: #else
        !          1287:        if (irq2dev_map[dev->irq] != NULL
        !          1288:                || (irq2dev_map[dev->irq] = dev) == NULL
        !          1289:                || dev->irq == 0
        !          1290:                || request_irq(dev->irq, &tulip_interrupt, 0,
        !          1291:                                           tulip_tbl[tp->chip_id].chip_name)) {
        !          1292:                return -EAGAIN;
        !          1293:        }
        !          1294: #endif
        !          1295: 
        !          1296:        if (tulip_debug > 1)
        !          1297:                printk(KERN_DEBUG "%s: tulip_open() irq %d.\n", dev->name, dev->irq);
        !          1298: 
        !          1299:        MOD_INC_USE_COUNT;
        !          1300: 
        !          1301:        tulip_init_ring(dev);
        !          1302: 
        !          1303:        /* This is set_rx_mode(), but without starting the transmitter. */
        !          1304:        /* Fill the whole address filter table with our physical address. */
        !          1305:        {
        !          1306:                u16 *eaddrs = (u16 *)dev->dev_addr;
        !          1307:                u32 *setup_frm = tp->setup_frame, i;
        !          1308: 
        !          1309:                /* You must add the broadcast address when doing perfect filtering! */
        !          1310:                *setup_frm++ = 0xffff;
        !          1311:                *setup_frm++ = 0xffff;
        !          1312:                *setup_frm++ = 0xffff;
        !          1313:                /* Fill the rest of the accept table with our physical address. */
        !          1314:                for (i = 1; i < 16; i++) {
        !          1315:                        *setup_frm++ = eaddrs[0];
        !          1316:                        *setup_frm++ = eaddrs[1];
        !          1317:                        *setup_frm++ = eaddrs[2];
        !          1318:                }
        !          1319:                /* Put the setup frame on the Tx list. */
        !          1320:                tp->tx_ring[0].length = 0x08000000 | 192;
        !          1321:                tp->tx_ring[0].buffer1 = virt_to_bus(tp->setup_frame);
        !          1322:                tp->tx_ring[0].status = 0x80000000;
        !          1323: 
        !          1324:                tp->cur_tx++;
        !          1325:        }
        !          1326: 
        !          1327:        outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3);
        !          1328:        outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4);
        !          1329: 
        !          1330:        if (dev->if_port == 0)
        !          1331:                dev->if_port = tp->default_port;
        !          1332:        if (tp->chip_id == DC21041  &&  dev->if_port > 4)
        !          1333:                /* Invalid: Select initial TP, autosense, autonegotiate.  */
        !          1334:                dev->if_port = 4;
        !          1335: 
        !          1336:        /* Allow selecting a default media. */
        !          1337:        if (tp->mtable == NULL)
        !          1338:                goto media_picked;
        !          1339:        if (dev->if_port) {
        !          1340:                int looking_for = media_cap[dev->if_port] & MediaIsMII ? 11 :
        !          1341:                        (dev->if_port == 12 ? 0 : dev->if_port);
        !          1342:                for (i = 0; i < tp->mtable->leafcount; i++)
        !          1343:                        if (tp->mtable->mleaf[i].media == looking_for) {
        !          1344:                                printk(KERN_INFO "%s: Using user-specified media %s.\n",
        !          1345:                                           dev->name, medianame[dev->if_port]);
        !          1346:                                goto media_picked;
        !          1347:                        }
        !          1348:        }
        !          1349:        if ((tp->mtable->defaultmedia & 0x0800) == 0)
        !          1350:                for (i = 0; i < tp->mtable->leafcount; i++)
        !          1351:                  if (tp->mtable->mleaf[i].media == (tp->mtable->defaultmedia & 15)) {
        !          1352:                        printk(KERN_INFO "%s: Using EEPROM-set media %s.\n",
        !          1353:                                   dev->name, medianame[tp->mtable->mleaf[i].media]);
        !          1354:                        goto media_picked;
        !          1355:                  }
        !          1356:        /* Start sensing first non-full-duplex media. */
        !          1357:        for (i = tp->mtable->leafcount - 1;
        !          1358:                 (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
        !          1359:          ;
        !          1360: media_picked:
        !          1361: 
        !          1362:        tp->csr6 = 0;
        !          1363:        tp->cur_index = i;
        !          1364:        if (dev->if_port == 0  &&  tp->chip_id == DC21142) {
        !          1365:                tp->csr6 = 0x82420200;
        !          1366:                outl(0x0003FFFF, ioaddr + CSR14);
        !          1367:                outl(0x0008, ioaddr + CSR15);
        !          1368:                outl(0x0001, ioaddr + CSR13);
        !          1369:                outl(0x1301, ioaddr + CSR12);
        !          1370:        } else if (tp->chip_id == LC82C168  &&  tp->mii_cnt && ! tp->medialock) {
        !          1371:                dev->if_port = 11;
        !          1372:                tp->csr6 = 0x816C0000 | (tp->full_duplex ? 0x0200 : 0);
        !          1373:                outl(0x0001, ioaddr + CSR15);
        !          1374:        } else
        !          1375:                select_media(dev, 1);
        !          1376: 
        !          1377:        /* Start the chip's Tx to process setup frame. */
        !          1378:        outl(tp->csr6, ioaddr + CSR6);
        !          1379:        outl(tp->csr6 | 0x2000, ioaddr + CSR6);
        !          1380: 
        !          1381:        dev->tbusy = 0;
        !          1382:        tp->interrupt = 0;
        !          1383:        dev->start = 1;
        !          1384: 
        !          1385:        /* Enable interrupts by setting the interrupt mask. */
        !          1386:        outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
        !          1387:        outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
        !          1388:        outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1389:        outl(0, ioaddr + CSR2);         /* Rx poll demand */
        !          1390: 
        !          1391:        if (tulip_debug > 2) {
        !          1392:                printk(KERN_DEBUG "%s: Done tulip_open(), CSR0 %8.8x, CSR5 %8.8x CSR6 %8.8x.\n",
        !          1393:                           dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR5),
        !          1394:                           inl(ioaddr + CSR6));
        !          1395:        }
        !          1396:        /* Set the timer to switch to check for link beat and perhaps switch
        !          1397:           to an alternate media type. */
        !          1398:        init_timer(&tp->timer);
        !          1399:        tp->timer.expires = RUN_AT(5*HZ);
        !          1400:        tp->timer.data = (unsigned long)dev;
        !          1401:        tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
        !          1402:        add_timer(&tp->timer);
        !          1403: 
        !          1404:        return 0;
        !          1405: }
        !          1406: 
        !          1407: /* Set up the transceiver control registers for the selected media type. */
        !          1408: static void select_media(struct device *dev, int startup)
        !          1409: {
        !          1410:        long ioaddr = dev->base_addr;
        !          1411:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1412:        struct mediatable *mtable = tp->mtable;
        !          1413:        u32 new_csr6;
        !          1414:        int check_mii =0, i;
        !          1415: 
        !          1416:        if (mtable) {
        !          1417:                struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
        !          1418:                unsigned char *p = mleaf->leafdata;
        !          1419:                switch (mleaf->type) {
        !          1420:                case 0:                                 /* 21140 non-MII xcvr. */
        !          1421:                        if (tulip_debug > 1)
        !          1422:                                printk(KERN_DEBUG "%s: Using a 21140 non-MII transceiver"
        !          1423:                                           " with control setting %2.2x.\n",
        !          1424:                                           dev->name, p[1]);
        !          1425:                        dev->if_port = p[0];
        !          1426:                        if (startup)
        !          1427:                                outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
        !          1428:                        outl(p[1], ioaddr + CSR12);
        !          1429:                        new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
        !          1430:                        break;
        !          1431:                case 2: case 4: {
        !          1432:                        u16 setup[3];
        !          1433:                        for (i = 0; i < 3; i++)
        !          1434:                                setup[i] = get_u16(&p[i*2 + 1]);
        !          1435: 
        !          1436:                        dev->if_port = p[0] & 15;
        !          1437:                        if (tulip_debug > 1)
        !          1438:                                printk(KERN_DEBUG "%s: 21142 non-MII %s transceiver control %4.4x/%4.4x.\n",
        !          1439:                                           dev->name, medianame[dev->if_port], setup[0], setup[1]);
        !          1440:                        if (p[0] & 0x40) {      /* SIA (CSR13-15) setup values are provided. */
        !          1441:                                outl(0, ioaddr + CSR13);
        !          1442:                                outl(setup[1], ioaddr + CSR14);
        !          1443:                                outl(setup[2], ioaddr + CSR15);
        !          1444:                                outl(setup[0], ioaddr + CSR13);
        !          1445:                                for (i = 0; i < 3; i++)                 /* Re-fill setup[]  */
        !          1446:                                        setup[i] = get_u16(&p[i*2 + 7]);
        !          1447:                        } else if (dev->if_port <= 4) {
        !          1448:                                outl(0, ioaddr + CSR13);
        !          1449:                                outl(t21142_csr14[dev->if_port], ioaddr + CSR14);
        !          1450:                                outl(t21142_csr15[dev->if_port], ioaddr + CSR15);
        !          1451:                                outl(t21142_csr13[dev->if_port], ioaddr + CSR13);
        !          1452:                        } else {
        !          1453:                                outl(0, ioaddr + CSR14);
        !          1454:                                outl(8, ioaddr + CSR15);
        !          1455:                                outl(0, ioaddr + CSR13);
        !          1456:                        }
        !          1457:                        outl(setup[0]<<16, ioaddr + CSR15);     /* Direction */
        !          1458:                        outl(setup[1]<<16, ioaddr + CSR15);     /* Data */
        !          1459:                        if (mleaf->type == 4)
        !          1460:                                new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
        !          1461:                        else
        !          1462:                                new_csr6 = 0x82420000;
        !          1463:                        break;
        !          1464:                }
        !          1465:                case 1: case 3: {
        !          1466:                        int phy_num = p[0];
        !          1467:                        int init_length = p[1];
        !          1468:                        u16 *misc_info;
        !          1469:                        u16 to_advertise;
        !          1470: 
        !          1471:                        dev->if_port = 11;
        !          1472:                        check_mii = 1;
        !          1473:                        new_csr6 = 0x020E0000;
        !          1474:                        if (mleaf->type == 3) { /* 21142 */
        !          1475:                                u16 *init_sequence = (u16*)(p+2);
        !          1476:                                u16 *reset_sequence = &((u16*)(p+3))[init_length];
        !          1477:                                int reset_length = p[2 + init_length*2];
        !          1478:                                misc_info = reset_sequence + reset_length;
        !          1479:                                if (startup)
        !          1480:                                        for (i = 0; i < reset_length; i++)
        !          1481:                                                outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
        !          1482:                                for (i = 0; i < init_length; i++)
        !          1483:                                        outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
        !          1484:                        } else {
        !          1485:                                u8 *init_sequence = p + 2;
        !          1486:                                u8 *reset_sequence = p + 3 + init_length;
        !          1487:                                int reset_length = p[2 + init_length];
        !          1488:                                misc_info = (u16*)(reset_sequence + reset_length);
        !          1489:                                if (startup) {
        !          1490:                                        outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
        !          1491:                                        for (i = 0; i < reset_length; i++)
        !          1492:                                                outl(reset_sequence[i], ioaddr + CSR12);
        !          1493:                                }
        !          1494:                                for (i = 0; i < init_length; i++)
        !          1495:                                        outl(init_sequence[i], ioaddr + CSR12);
        !          1496:                        }
        !          1497:                        to_advertise = (get_u16(&misc_info[1]) & tp->to_advertise) | 1;
        !          1498:                        tp->advertising[phy_num] = to_advertise;
        !          1499:                        if (tulip_debug > 1 || 1)
        !          1500:                                printk(KERN_DEBUG "%s:  Advertising %4.4x on PHY %d (%d).\n",
        !          1501:                                           dev->name, to_advertise, phy_num, tp->phys[phy_num]);
        !          1502:                        /* Bogus: put in by a committee?  */
        !          1503:                        mdio_write(dev, tp->phys[phy_num], 4, to_advertise);
        !          1504:                        break;
        !          1505:                }
        !          1506:                default:
        !          1507:                  new_csr6 = 0x020E0000;
        !          1508:                }
        !          1509:                if (tulip_debug > 1)
        !          1510:                        printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n",
        !          1511:                                   dev->name, medianame[dev->if_port],
        !          1512:                                   inl(ioaddr + CSR12) & 0xff);
        !          1513:        } else if (tp->chip_id == DC21041) {
        !          1514:                if (tulip_debug > 1)
        !          1515:                        printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n",
        !          1516:                                   dev->name, medianame[dev->if_port & 15],
        !          1517:                                   inl(ioaddr + CSR12) & 0xffff);
        !          1518:                outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
        !          1519:                outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
        !          1520:                outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
        !          1521:                outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
        !          1522:                new_csr6 = 0x80020000;
        !          1523:        } else if (tp->chip_id == LC82C168) {
        !          1524:                if (startup && ! tp->medialock)
        !          1525:                        dev->if_port = tp->mii_cnt ? 11 : 0;
        !          1526:                if (tulip_debug > 1)
        !          1527:                        printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, CSR12 %4.4x,"
        !          1528:                                   " media %s.\n",
        !          1529:                                   dev->name, inl(ioaddr + 0xB8), inl(ioaddr + CSR12),
        !          1530:                                   medianame[dev->if_port]);
        !          1531:                if (tp->mii_cnt) {
        !          1532:                        new_csr6 = 0x812C0000;
        !          1533:                        outl(0x0001, ioaddr + CSR15);
        !          1534:                        outl(0x0201B07A, ioaddr + 0xB8);
        !          1535:                } else if (startup) {
        !          1536:                        /* Start with 10mbps to do autonegotiation. */
        !          1537:                        outl(0x32, ioaddr + CSR12);
        !          1538:                        new_csr6 = 0x00420000;
        !          1539:                        outl(0x0001B078, ioaddr + 0xB8);
        !          1540:                        outl(0x0201B078, ioaddr + 0xB8);
        !          1541:                } else if (dev->if_port == 3  ||  dev->if_port == 5) {
        !          1542:                        outl(0x33, ioaddr + CSR12);
        !          1543:                        new_csr6 = 0x01860000;
        !          1544:                        if (startup)
        !          1545:                                outl(0x0201F868, ioaddr + 0xB8); /* Trigger autonegotiation. */
        !          1546:                        else
        !          1547:                                outl(0x1F868, ioaddr + 0xB8);
        !          1548:                } else {
        !          1549:                        outl(0x32, ioaddr + CSR12);
        !          1550:                        new_csr6 = 0x00420000;
        !          1551:                        outl(0x1F078, ioaddr + 0xB8);
        !          1552:                }
        !          1553:        } else if (tp->chip_id == DC21040) {                                    /* 21040 */
        !          1554:                /* Turn on the xcvr interface. */
        !          1555:                int csr12 = inl(ioaddr + CSR12);
        !          1556:                if (tulip_debug > 1)
        !          1557:                        printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n",
        !          1558:                                   dev->name, dev->if_port ? "AUI" : "10baseT", csr12);
        !          1559:                new_csr6 = (dev->if_port ? 0x01860000 : 0x00420000);
        !          1560:                /* Set the full duplux match frame. */
        !          1561:                outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
        !          1562:                outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
        !          1563:                outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
        !          1564:        } else {                                        /* Unknown chip type with no media table. */
        !          1565:                if (tp->default_port == 0)
        !          1566:                        if (tp->mii_cnt) {
        !          1567:                                dev->if_port = 11;
        !          1568:                        } else
        !          1569:                                dev->if_port = 3;
        !          1570:                if (media_cap[dev->if_port] & MediaIsMII) {
        !          1571:                        new_csr6 = 0x020E0000;
        !          1572:                } else if (media_cap[dev->if_port] & MediaIsFx) {
        !          1573:                        new_csr6 = 0x028600000;
        !          1574:                } else
        !          1575:                        new_csr6 = 0x038600000;
        !          1576:                if (tulip_debug > 1)
        !          1577:                        printk(KERN_DEBUG "%s: No media description table, assuming "
        !          1578:                                   "%s transceiver, CSR12 %2.2x.\n",
        !          1579:                                   dev->name, medianame[dev->if_port],
        !          1580:                                   inl(ioaddr + CSR12));
        !          1581:        }
        !          1582: 
        !          1583:        tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
        !          1584:        return;
        !          1585: }
        !          1586: 
        !          1587: static void tulip_timer(unsigned long data)
        !          1588: {
        !          1589:        struct device *dev = (struct device *)data;
        !          1590:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1591:        long ioaddr = dev->base_addr;
        !          1592:        u32 csr12 = inl(ioaddr + CSR12);
        !          1593:        int next_tick = 0;
        !          1594: 
        !          1595:        if (tulip_debug > 3) {
        !          1596:                printk(KERN_DEBUG "%s: Media selection tick, status %8.8x mode %8.8x "
        !          1597:                           "SIA %8.8x %8.8x %8.8x %8.8x.\n",
        !          1598:                           dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR6),
        !          1599:                           csr12, inl(ioaddr + CSR13),
        !          1600:                           inl(ioaddr + CSR14), inl(ioaddr + CSR15));
        !          1601:        }
        !          1602:        switch (tp->chip_id) {
        !          1603:        case DC21040:
        !          1604:                if (csr12 & 0x0002) { /* Network error */
        !          1605:                        printk(KERN_INFO "%s: No 10baseT link beat found, switching to %s media.\n",
        !          1606:                                   dev->name, dev->if_port ? "10baseT" : "AUI");
        !          1607:                        dev->if_port ^= 1;
        !          1608:                        outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
        !          1609:                        dev->trans_start = jiffies;
        !          1610:                }
        !          1611:                break;
        !          1612:        case DC21041:
        !          1613:                if (tulip_debug > 2)
        !          1614:                        printk(KERN_DEBUG "%s: 21041 media tick  CSR12 %8.8x.\n",
        !          1615:                                   dev->name, csr12);
        !          1616:                switch (dev->if_port) {
        !          1617:                case 0: case 3: case 4:
        !          1618:                  if (csr12 & 0x0004) { /*LnkFail */
        !          1619:                        /* 10baseT is dead.  Check for activity on alternate port. */
        !          1620:                        tp->mediasense = 1;
        !          1621:                        if (csr12 & 0x0200)
        !          1622:                                dev->if_port = 2;
        !          1623:                        else
        !          1624:                                dev->if_port = 1;
        !          1625:                        printk(KERN_INFO "%s: No 21041 10baseT link beat, Media switched to %s.\n",
        !          1626:                                   dev->name, medianame[dev->if_port]);
        !          1627:                        outl(0, ioaddr + CSR13); /* Reset */
        !          1628:                        outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
        !          1629:                        outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
        !          1630:                        outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
        !          1631:                        next_tick = 10*HZ;                      /* 2.4 sec. */
        !          1632:                  } else
        !          1633:                        next_tick = 30*HZ;
        !          1634:                  break;
        !          1635:                case 1:                                 /* 10base2 */
        !          1636:                case 2:                                 /* AUI */
        !          1637:                  if (csr12 & 0x0100) {
        !          1638:                        next_tick = (30*HZ);                    /* 30 sec. */
        !          1639:                        tp->mediasense = 0;
        !          1640:                  } else if ((csr12 & 0x0004) == 0) {
        !          1641:                        printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n", dev->name);
        !          1642:                        dev->if_port = 0;
        !          1643:                        select_media(dev, 0);
        !          1644:                        next_tick = (24*HZ)/10;                         /* 2.4 sec. */
        !          1645:                  } else if (tp->mediasense || (csr12 & 0x0002)) {
        !          1646:                        dev->if_port = 3 - dev->if_port; /* Swap ports. */
        !          1647:                        select_media(dev, 0);
        !          1648:                        next_tick = 20*HZ;
        !          1649:                  } else {
        !          1650:                        next_tick = 20*HZ;
        !          1651:                  }
        !          1652:                  break;
        !          1653:                }
        !          1654:                break;
        !          1655:        case DC21140:  case DC21142: case MX98713: default: {
        !          1656:                struct medialeaf *mleaf;
        !          1657:                unsigned char *p;
        !          1658:                if (tp->mtable == NULL) {       /* No EEPROM info, use generic code. */
        !          1659:                        /* Not much that can be done.
        !          1660:                           Assume this a generic MII or SYM transceiver. */
        !          1661:                        next_tick = 60*HZ;
        !          1662:                        if (tulip_debug > 2)
        !          1663:                                printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x "
        !          1664:                                           "CSR12 0x%2.2x.\n",
        !          1665:                                           dev->name, inl(ioaddr + CSR6), csr12 & 0xff);
        !          1666:                        break;
        !          1667:                }
        !          1668:                mleaf = &tp->mtable->mleaf[tp->cur_index];
        !          1669:                p = mleaf->leafdata;
        !          1670:                switch (mleaf->type) {
        !          1671:                case 0: case 4: {
        !          1672:                        /* Type 0 serial or 4 SYM transceiver.  Check the link beat bit. */
        !          1673:                        int offset = mleaf->type == 4 ? 5 : 2;
        !          1674:                        s8 bitnum = p[offset];
        !          1675:                        if (p[offset+1] & 0x80) {
        !          1676:                                if (tulip_debug > 1)
        !          1677:                                        printk(KERN_DEBUG"%s: Transceiver monitor tick "
        !          1678:                                                   "CSR12=%#2.2x, no media sense.\n",
        !          1679:                                                   dev->name, csr12);
        !          1680:                                if (mleaf->type == 4) {
        !          1681:                                        if (mleaf->media == 3 && (csr12 & 0x02))
        !          1682:                                                goto select_next_media;
        !          1683:                                }
        !          1684:                                break;
        !          1685:                        }
        !          1686:                        if (tulip_debug > 2)
        !          1687:                                printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x"
        !          1688:                                           " bit %d is %d, expecting %d.\n",
        !          1689:                                           dev->name, csr12, (bitnum >> 1) & 7,
        !          1690:                                           (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,
        !          1691:                                           (bitnum >= 0));
        !          1692:                        /* Check that the specified bit has the proper value. */
        !          1693:                        if ((bitnum < 0) !=
        !          1694:                                ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {
        !          1695:                                if (tulip_debug > 1)
        !          1696:                                        printk(KERN_DEBUG "%s: Link beat detected for %s.\n", dev->name,
        !          1697:                                                   medianame[mleaf->media]);
        !          1698:                                if ((p[2] & 0x61) == 0x01)      /* Bogus Znyx board. */
        !          1699:                                        goto actually_mii;
        !          1700:                                break;
        !          1701:                        }
        !          1702:                        if (tp->medialock)
        !          1703:                                break;
        !          1704:          select_next_media:
        !          1705:                        if (--tp->cur_index < 0) {
        !          1706:                                /* We start again, but should instead look for default. */
        !          1707:                                tp->cur_index = tp->mtable->leafcount - 1;
        !          1708:                        }
        !          1709:                        dev->if_port = tp->mtable->mleaf[tp->cur_index].media;
        !          1710:                        if (media_cap[dev->if_port] & MediaIsFD)
        !          1711:                                goto select_next_media; /* Skip FD entries. */
        !          1712:                        if (tulip_debug > 1)
        !          1713:                                printk(KERN_DEBUG "%s: No link beat on media %s,"
        !          1714:                                           " trying transceiver type %s.\n",
        !          1715:                                           dev->name, medianame[mleaf->media & 15],
        !          1716:                                           medianame[tp->mtable->mleaf[tp->cur_index].media]);
        !          1717:                        select_media(dev, 0);
        !          1718:                        /* Restart the transmit process. */
        !          1719:                        outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          1720:                        outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1721:                        next_tick = (24*HZ)/10;
        !          1722:                        break;
        !          1723:                }
        !          1724:                case 1:  case 3: {              /* 21140, 21142 MII */
        !          1725:                        int mii_reg1, mii_reg5;
        !          1726:                actually_mii:
        !          1727:                        mii_reg1 = mdio_read(dev, tp->phys[0], 1);
        !          1728:                        mii_reg5 = mdio_read(dev, tp->phys[0], 5);
        !          1729:                        if (tulip_debug > 1)
        !          1730:                                printk(KERN_INFO "%s: MII status %4.4x, Link partner report "
        !          1731:                                           "%4.4x, CSR12 %2.2x, %cD.\n",
        !          1732:                                           dev->name, mii_reg1, mii_reg5, csr12,
        !          1733:                                           tp->full_duplex ? 'F' : 'H');
        !          1734:                        if (mii_reg1 != 0xffff  &&  (mii_reg1 & 0x0004) == 0) {
        !          1735:                                int new_reg1 = mdio_read(dev, tp->phys[0], 1);
        !          1736:                                if ((new_reg1 & 0x0004) == 0) {
        !          1737:                                        printk(KERN_INFO "%s: No link beat on the MII interface,"
        !          1738:                                                   " status then %4.4x now %4.4x.\n",
        !          1739:                                                   dev->name, mii_reg1, new_reg1);
        !          1740:                                        if (tp->mtable  &&  tp->mtable->has_nonmii)
        !          1741:                                                goto select_next_media;
        !          1742:                                }
        !          1743:                        }
        !          1744:                        if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000)
        !          1745:                                ;                               /* No MII device or no link partner report */
        !          1746:                        else if (tp->full_duplex_lock)
        !          1747:                                ;
        !          1748:                        else {
        !          1749:                                int negotiated = mii_reg5 & tp->advertising[0];
        !          1750:                                int duplex = ((negotiated & 0x0100) != 0
        !          1751:                                                          || (negotiated & 0x00C0) == 0x0040);
        !          1752:                                /* 100baseTx-FD  or  10T-FD, but not 100-HD */
        !          1753:                                if (tp->full_duplex != duplex) {
        !          1754:                                        tp->full_duplex = duplex;
        !          1755:                                        if (tp->full_duplex)
        !          1756:                                                tp->csr6 |= 0x0200;
        !          1757:                                        else
        !          1758:                                                tp->csr6 &= ~0x0200;
        !          1759:                                        outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          1760:                                        outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1761:                                        if (tulip_debug > 0) /* Gurppp, should be >1 */
        !          1762:                                                printk(KERN_INFO "%s: Setting %s-duplex based on MII"
        !          1763:                                                           " Xcvr #%d parter capability of %4.4x.\n",
        !          1764:                                                           dev->name, tp->full_duplex ? "full" : "half",
        !          1765:                                                           tp->phys[0], mii_reg5);
        !          1766:                                }
        !          1767:                        }
        !          1768:                        next_tick = 60*HZ;
        !          1769:                        break;
        !          1770:                }
        !          1771:                case 2:                                 /* 21142 serial block has no link beat. */
        !          1772:                default:
        !          1773:                        break;
        !          1774:                }
        !          1775:        }
        !          1776:        break;
        !          1777:        }
        !          1778:        if (next_tick) {
        !          1779:                tp->timer.expires = RUN_AT(next_tick);
        !          1780:                add_timer(&tp->timer);
        !          1781:        }
        !          1782: }
        !          1783: 
        !          1784: /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
        !          1785:    of available transceivers.  */
        !          1786: static void t21142_timer(unsigned long data)
        !          1787: {
        !          1788:        struct device *dev = (struct device *)data;
        !          1789:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1790:        long ioaddr = dev->base_addr;
        !          1791:        int csr12 = inl(ioaddr + CSR12);
        !          1792:        int next_tick = 60*HZ;
        !          1793:        int new_csr6 = 0;
        !          1794: 
        !          1795:        if (tulip_debug > 1)
        !          1796:                printk(KERN_INFO"%s: 21142 negotiation status %8.8x, %s.\n",
        !          1797:                           dev->name, csr12, medianame[dev->if_port]);
        !          1798:        if (dev->if_port == 3) {
        !          1799:                if (csr12 & 2) {                /* No 100mbps link beat, revert to 10mbps. */
        !          1800:                        new_csr6 = 0x82420200;
        !          1801:                        outl(new_csr6, ioaddr + CSR6);
        !          1802:                        outl(0x0000, ioaddr + CSR13);
        !          1803:                        outl(0x0003FFFF, ioaddr + CSR14);
        !          1804:                        outl(0x0008, ioaddr + CSR15);
        !          1805:                        outl(0x0001, ioaddr + CSR13);
        !          1806:                        outl(0x1301, ioaddr + CSR12); /* Start NWay. */
        !          1807:                }
        !          1808:        } else if ((csr12 & 0x7000) != 0x5000) {
        !          1809:                /* Negotiation failed.  Search media types. */
        !          1810:                if (tulip_debug > 1)
        !          1811:                        printk(KERN_INFO"%s: 21142 negotiation failed, status %8.8x.\n",
        !          1812:                                   dev->name, csr12);
        !          1813:                if (!(csr12 & 4)) {             /* 10mbps link beat good. */
        !          1814:                        new_csr6 = 0x82420000;
        !          1815:                        dev->if_port = 0;
        !          1816:                        outl(0, ioaddr + CSR13);
        !          1817:                        outl(0x0003FFFF, ioaddr + CSR14);
        !          1818:                        outl(t21142_csr15[dev->if_port], ioaddr + CSR15);
        !          1819:                        outl(t21142_csr13[dev->if_port], ioaddr + CSR13);
        !          1820:                } else if (csr12 & 0x100) {
        !          1821:                        new_csr6 = 0x82420200;
        !          1822:                        dev->if_port = 2;
        !          1823:                        outl(0, ioaddr + CSR13);
        !          1824:                        outl(0x0003FFFF, ioaddr + CSR14);
        !          1825:                        outl(0x0008, ioaddr + CSR15);
        !          1826:                        outl(0x0001, ioaddr + CSR13);
        !          1827:                } else {
        !          1828:                        /* Select 100mbps port to check for link beat. */
        !          1829:                        new_csr6 = 0x83860000;
        !          1830:                        dev->if_port = 3;
        !          1831:                        outl(0, ioaddr + CSR13);
        !          1832:                        outl(0x0003FF7F, ioaddr + CSR14);
        !          1833:                        outl(8, ioaddr + CSR15);
        !          1834:                        outl(1, ioaddr + CSR13);
        !          1835:                }
        !          1836:                if (tulip_debug > 1)
        !          1837:                        printk(KERN_INFO"%s: Testing new 21142 media %s.\n",
        !          1838:                                   dev->name, medianame[dev->if_port]);
        !          1839:                if (new_csr6 != (tp->csr6 & ~0x00D5)) {
        !          1840:                        tp->csr6 &= 0x00D5;
        !          1841:                        tp->csr6 |= new_csr6;
        !          1842:                        outl(0x0301, ioaddr + CSR12);
        !          1843:                        outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          1844:                        outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1845:                }
        !          1846:        }
        !          1847:        tp->timer.expires = RUN_AT(next_tick);
        !          1848:        add_timer(&tp->timer);
        !          1849: }
        !          1850: 
        !          1851: static void t21142_lnk_change( struct device *dev)
        !          1852: {
        !          1853:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1854:        long ioaddr = dev->base_addr;
        !          1855:        int csr12 = inl(ioaddr + CSR12);
        !          1856: 
        !          1857:        if (tulip_debug > 1)
        !          1858:                printk(KERN_INFO"%s: 21142 link status interrupt %8.8x, CSR5 %x.\n",
        !          1859:                           dev->name, csr12, inl(ioaddr + CSR5));
        !          1860: 
        !          1861:        if ((csr12 & 0x7000) == 0x5000) {
        !          1862:                if (csr12 & 0x01800000) {
        !          1863:                        /* Switch to 100mbps mode. */
        !          1864:                        outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          1865:                        if (csr12 & 0x01000000) {
        !          1866:                                dev->if_port = 5;
        !          1867:                                tp->csr6 = 0x83860200;
        !          1868:                        } else {
        !          1869:                                dev->if_port = 3;
        !          1870:                                tp->csr6 = 0x83860000;
        !          1871:                        }
        !          1872:                        outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1873:                } /* Else 10baseT-FD is handled automatically. */
        !          1874:        } else if (dev->if_port == 3) {
        !          1875:                if (!(csr12 & 2))
        !          1876:                        printk(KERN_INFO"%s: 21142 100baseTx link beat good.\n",
        !          1877:                                   dev->name);
        !          1878:                else
        !          1879:                        dev->if_port = 0;
        !          1880:        } else if (dev->if_port == 0) {
        !          1881:                if (!(csr12 & 4))
        !          1882:                        printk(KERN_INFO"%s: 21142 10baseT link beat good.\n",
        !          1883:                                   dev->name);
        !          1884:        } else if (!(csr12 & 4)) {              /* 10mbps link beat good. */
        !          1885:                        printk(KERN_INFO"%s: 21142 10mpbs sensed media.\n",
        !          1886:                                   dev->name);
        !          1887:                        dev->if_port = 0;
        !          1888:        } else  {               /* 100mbps link beat good. */
        !          1889:                printk(KERN_INFO"%s: 21142 100baseTx sensed media.\n",
        !          1890:                           dev->name);
        !          1891:                dev->if_port = 3;
        !          1892:                tp->csr6 = 0x83860000;
        !          1893:                outl(0x0003FF7F, ioaddr + CSR14);
        !          1894:                outl(0x0301, ioaddr + CSR12);
        !          1895:                outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          1896:                outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1897:        }
        !          1898: }
        !          1899:        
        !          1900: 
        !          1901: static void mxic_timer(unsigned long data)
        !          1902: {
        !          1903:        struct device *dev = (struct device *)data;
        !          1904:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1905:        long ioaddr = dev->base_addr;
        !          1906:        int next_tick = 60*HZ;
        !          1907: 
        !          1908:        if (tulip_debug > 3) {
        !          1909:                printk(KERN_INFO"%s: MXIC negotiation status %8.8x.\n", dev->name,
        !          1910:                           inl(ioaddr + CSR12));
        !          1911:        }
        !          1912:        if (next_tick) {
        !          1913:                tp->timer.expires = RUN_AT(next_tick);
        !          1914:                add_timer(&tp->timer);
        !          1915:        }
        !          1916: }
        !          1917: 
        !          1918: static void pnic_timer(unsigned long data)
        !          1919: {
        !          1920:        struct device *dev = (struct device *)data;
        !          1921:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1922:        long ioaddr = dev->base_addr;
        !          1923:        int csr12 = inl(ioaddr + CSR12);
        !          1924:        int next_tick = 60*HZ;
        !          1925:        int new_csr6 = tp->csr6 & ~0x40C40200;
        !          1926: 
        !          1927:        if (media_cap[dev->if_port] & MediaIsMII) {
        !          1928:                int negotiated = mdio_read(dev, tp->phys[0], 5) & tp->advertising[0];
        !          1929: 
        !          1930:                if (tulip_debug > 1)
        !          1931:                        printk(KERN_DEBUG "%s: LC82C168 negotiated capability %8.8x, "
        !          1932:                                   "CSR5 %8.8x.\n",
        !          1933:                                   dev->name, negotiated, inl(ioaddr + CSR5));
        !          1934: 
        !          1935:                if (negotiated & 0x0380)                                /* 10 vs 100mbps */
        !          1936:                        new_csr6 |= 0x812E0000;
        !          1937:                else
        !          1938:                        new_csr6 |= 0x816E0000;
        !          1939:                if (((negotiated & 0x0300) == 0x0100)                   /* Duplex */
        !          1940:                        || (negotiated & 0x00C0) == 0x0040
        !          1941:                        || tp->full_duplex_lock) {
        !          1942:                        tp->full_duplex = 1;
        !          1943:                        new_csr6 |= 0x0200;
        !          1944:                }
        !          1945:                if (tulip_debug > 1)
        !          1946:                        printk(KERN_DEBUG "%s: LC82C168 MII PHY status %4.4x, Link "
        !          1947:                                   "partner report %4.4x, csr6 %8.8x/%8.8x.\n",
        !          1948:                           dev->name, mdio_read(dev, tp->phys[0], 1), negotiated,
        !          1949:                                   tp->csr6, inl(ioaddr + CSR6));
        !          1950:        } else {
        !          1951:                int phy_reg = inl(ioaddr + 0xB8);
        !          1952:                int csr5 = inl(ioaddr + CSR5);
        !          1953: 
        !          1954:                if (tulip_debug > 1)
        !          1955:                        printk(KERN_DEBUG "%s: LC82C168 phy status %8.8x, CSR5 %8.8x.\n",
        !          1956:                                   dev->name, phy_reg, csr5);
        !          1957: 
        !          1958:                if (phy_reg & 0x04000000) {     /* Remote link fault */
        !          1959:                        /*outl(0x0201F078, ioaddr + 0xB8);*/
        !          1960:                        next_tick = 3*HZ;
        !          1961:                }
        !          1962:                if (inl(ioaddr + CSR5) & TPLnkFail) { /* 100baseTx link beat */
        !          1963:                        if (tulip_debug > 1)
        !          1964:                                printk(KERN_DEBUG "%s: %s link beat failed, CSR12 %4.4x, "
        !          1965:                                           "CSR5 %8.8x, PHY %3.3x.\n",
        !          1966:                                           dev->name, medianame[dev->if_port], csr12,
        !          1967:                                           inl(ioaddr + CSR5), inl(ioaddr + 0xB8));
        !          1968:                        if (tp->medialock) {
        !          1969:                        } else if (dev->if_port == 0) {
        !          1970:                                dev->if_port = 3;
        !          1971:                                outl(0x33, ioaddr + CSR12);
        !          1972:                                new_csr6 = 0x01860000;
        !          1973:                                outl(0x1F868, ioaddr + 0xB8);
        !          1974:                        } else {
        !          1975:                                dev->if_port = 0;
        !          1976:                                outl(0x32, ioaddr + CSR12);
        !          1977:                                new_csr6 = 0x00420000;
        !          1978:                                outl(0x1F078, ioaddr + 0xB8);
        !          1979:                        }
        !          1980:                        new_csr6 |= (tp->csr6 & 0xfdff);
        !          1981:                        next_tick = 3*HZ;
        !          1982:                } else
        !          1983:                        new_csr6 = tp->csr6;
        !          1984:                if (tp->full_duplex_lock  ||  (phy_reg & 0x30000000) != 0) {
        !          1985:                        tp->full_duplex = 1;
        !          1986:                        new_csr6 |= 0x00000200;
        !          1987:                }
        !          1988:        }
        !          1989:        if (tp->csr6 != new_csr6) {
        !          1990:                tp->csr6 = new_csr6;
        !          1991:                outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */
        !          1992:                outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          1993:                dev->trans_start = jiffies;
        !          1994:                if (tulip_debug > 0) /* Gurppp, should be >1 */
        !          1995:                        printk(KERN_INFO "%s: Changing PNIC configuration to %s-duplex, "
        !          1996:                                   "CSR6 %8.8x.\n",
        !          1997:                                   dev->name, tp->full_duplex ? "full" : "half", new_csr6);
        !          1998:        }
        !          1999:        tp->timer.expires = RUN_AT(next_tick);
        !          2000:        add_timer(&tp->timer);
        !          2001: }
        !          2002: 
        !          2003: static void tulip_tx_timeout(struct device *dev)
        !          2004: {
        !          2005:   struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2006:   long ioaddr = dev->base_addr;
        !          2007: 
        !          2008:   if (media_cap[dev->if_port] & MediaIsMII) {
        !          2009:          /* Do nothing -- the media monitor should handle this. */
        !          2010:          if (tulip_debug > 1)
        !          2011:                  printk(KERN_WARNING "%s: Transmit timeout using MII device.\n",
        !          2012:                                 dev->name);
        !          2013:          dev->trans_start = jiffies;
        !          2014:          return;
        !          2015:   } else if (tp->chip_id == DC21040) {
        !          2016:          if (inl(ioaddr + CSR12) & 0x0002) {
        !          2017:                  printk(KERN_INFO "%s: transmit timed out, switching to %s media.\n",
        !          2018:                                 dev->name, dev->if_port ? "10baseT" : "AUI");
        !          2019:                  dev->if_port ^= 1;
        !          2020:                  outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
        !          2021:          }
        !          2022:          dev->trans_start = jiffies;
        !          2023:          return;
        !          2024:   } else if (tp->chip_id == DC21041) {
        !          2025:        u32 csr12 = inl(ioaddr + CSR12);
        !          2026: 
        !          2027:        printk(KERN_WARNING "%s: 21041 transmit timed out, status %8.8x, CSR12 %8.8x,"
        !          2028:                   " CSR13 %8.8x, CSR14 %8.8x, resetting...\n",
        !          2029:                   dev->name, inl(ioaddr + CSR5), csr12,
        !          2030:                   inl(ioaddr + CSR13), inl(ioaddr + CSR14));
        !          2031:        tp->mediasense = 1;
        !          2032:        if (dev->if_port == 1 || dev->if_port == 2)
        !          2033:                if (csr12 & 0x0004) {
        !          2034:                        dev->if_port = 2 - dev->if_port;
        !          2035:                } else
        !          2036:                        dev->if_port = 0;
        !          2037:        else
        !          2038:                dev->if_port = 1;
        !          2039:        select_media(dev, 0);
        !          2040:        tp->stats.tx_errors++;
        !          2041:        dev->trans_start = jiffies;
        !          2042:        return;
        !          2043:   } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142
        !          2044:                         || tp->chip_id == MX98713) {
        !          2045:          /* Stop the transmit process. */
        !          2046:          outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          2047:          printk(KERN_WARNING "%s: 21140 transmit timed out, status %8.8x, "
        !          2048:                         "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
        !          2049:                         dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12),
        !          2050:                         inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15));
        !          2051:          if (tp->mtable) {
        !          2052:                  if (--tp->cur_index < 0) {
        !          2053:                          /* We start again, but should instead look for default. */
        !          2054:                          tp->cur_index = tp->mtable->leafcount - 1;
        !          2055:                  }
        !          2056:                  select_media(dev, 0);
        !          2057:                  printk(KERN_WARNING "%s: transmit timed out, switching to %s media.\n",
        !          2058:                                 dev->name, dev->if_port ? "100baseTx" : "10baseT");
        !          2059:          }
        !          2060:          outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          2061:          tp->stats.tx_errors++;
        !          2062:          dev->trans_start = jiffies;
        !          2063:          return;
        !          2064:   } else
        !          2065:        printk(KERN_WARNING "%s: transmit timed out, status %8.8x, CSR12 %8.8x,"
        !          2066:                   " resetting...\n",
        !          2067:                   dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12));
        !          2068: #ifdef way_too_many_messages
        !          2069:   printk("  Rx ring %8.8x: ", (int)tp->rx_ring);
        !          2070:   for (i = 0; i < RX_RING_SIZE; i++)
        !          2071:        printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
        !          2072:   printk("\n  Tx ring %8.8x: ", (int)tp->tx_ring);
        !          2073:   for (i = 0; i < TX_RING_SIZE; i++)
        !          2074:        printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
        !          2075:   printk("\n");
        !          2076: #endif
        !          2077: 
        !          2078:   /* Perhaps we should reinitialize the hardware here. */
        !          2079:   dev->if_port = 0;
        !          2080:   /* Stop and restart the chip's Tx processes . */
        !          2081:   outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          2082:   outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          2083:   /* Trigger an immediate transmit demand. */
        !          2084:   outl(0, ioaddr + CSR1);
        !          2085: 
        !          2086:   dev->trans_start = jiffies;
        !          2087:   tp->stats.tx_errors++;
        !          2088:   return;
        !          2089: }
        !          2090: 
        !          2091: 
        !          2092: /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
        !          2093: static void
        !          2094: tulip_init_ring(struct device *dev)
        !          2095: {
        !          2096:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2097:        int i;
        !          2098: 
        !          2099:        tp->tx_full = 0;
        !          2100:        tp->cur_rx = tp->cur_tx = 0;
        !          2101:        tp->dirty_rx = tp->dirty_tx = 0;
        !          2102: 
        !          2103:        for (i = 0; i < RX_RING_SIZE; i++) {
        !          2104:                tp->rx_ring[i].status = 0x80000000;     /* Owned by Tulip chip */
        !          2105:                tp->rx_ring[i].length = PKT_BUF_SZ;
        !          2106:                {
        !          2107:                        /* Note the receive buffer must be longword aligned.
        !          2108:                           dev_alloc_skb() provides 16 byte alignment.  But do *not*
        !          2109:                           use skb_reserve() to align the IP header! */
        !          2110:                        struct sk_buff *skb;
        !          2111:                        skb = DEV_ALLOC_SKB(PKT_BUF_SZ);
        !          2112:                        tp->rx_skbuff[i] = skb;
        !          2113:                        if (skb == NULL)
        !          2114:                                break;                  /* Bad news!  */
        !          2115:                        skb->dev = dev;                 /* Mark as being used by this device. */
        !          2116: #if LINUX_VERSION_CODE > 0x10300
        !          2117:                        tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail);
        !          2118: #else
        !          2119:                        tp->rx_ring[i].buffer1 = virt_to_bus(skb->data);
        !          2120: #endif
        !          2121:                }
        !          2122:                tp->rx_ring[i].buffer2 = virt_to_bus(&tp->rx_ring[i+1]);
        !          2123:        }
        !          2124:        /* Mark the last entry as wrapping the ring. */
        !          2125:        tp->rx_ring[i-1].length = PKT_BUF_SZ | 0x02000000;
        !          2126:        tp->rx_ring[i-1].buffer2 = virt_to_bus(&tp->rx_ring[0]);
        !          2127: 
        !          2128:        /* The Tx buffer descriptor is filled in as needed, but we
        !          2129:           do need to clear the ownership bit. */
        !          2130:        for (i = 0; i < TX_RING_SIZE; i++) {
        !          2131:                tp->tx_skbuff[i] = 0;
        !          2132:                tp->tx_ring[i].status = 0x00000000;
        !          2133:                tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]);
        !          2134:        }
        !          2135:        tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]);
        !          2136: }
        !          2137: 
        !          2138: static int
        !          2139: tulip_start_xmit(struct sk_buff *skb, struct device *dev)
        !          2140: {
        !          2141:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2142:        int entry;
        !          2143:        u32 flag;
        !          2144: 
        !          2145:        /* Block a timer-based transmit from overlapping.  This could better be
        !          2146:           done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
        !          2147:        if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
        !          2148:                if (jiffies - dev->trans_start < TX_TIMEOUT)
        !          2149:                        return 1;
        !          2150:                tulip_tx_timeout(dev);
        !          2151:                return 1;
        !          2152:        }
        !          2153: 
        !          2154:        /* Caution: the write order is important here, set the base address
        !          2155:           with the "ownership" bits last. */
        !          2156: 
        !          2157:        /* Calculate the next Tx descriptor entry. */
        !          2158:        entry = tp->cur_tx % TX_RING_SIZE;
        !          2159: 
        !          2160:        tp->tx_skbuff[entry] = skb;
        !          2161:        tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data);
        !          2162: 
        !          2163:        if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
        !          2164:          flag = 0x60000000; /* No interrupt */
        !          2165:          dev->tbusy = 0;
        !          2166:        } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) {
        !          2167:          flag = 0xe0000000; /* Tx-done intr. */
        !          2168:          dev->tbusy = 0;
        !          2169:        } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) {
        !          2170:          flag = 0x60000000; /* No Tx-done intr. */
        !          2171:          dev->tbusy = 0;
        !          2172:        } else {
        !          2173:          /* Leave room for set_rx_mode() to fill entries. */
        !          2174:          flag = 0xe0000000; /* Tx-done intr. */
        !          2175:          tp->tx_full = 1;
        !          2176:        }
        !          2177:        if (entry == TX_RING_SIZE-1)
        !          2178:                flag |= 0xe2000000;
        !          2179: 
        !          2180:        tp->tx_ring[entry].length = skb->len | flag;
        !          2181:        tp->tx_ring[entry].status = 0x80000000; /* Pass ownership to the chip. */
        !          2182:        tp->cur_tx++;
        !          2183:        /* Trigger an immediate transmit demand. */
        !          2184:        outl(0, dev->base_addr + CSR1);
        !          2185: 
        !          2186:        dev->trans_start = jiffies;
        !          2187: 
        !          2188:        return 0;
        !          2189: }
        !          2190: 
        !          2191: /* The interrupt handler does all of the Rx thread work and cleans up
        !          2192:    after the Tx thread. */
        !          2193: static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs)
        !          2194: {
        !          2195: #ifdef SA_SHIRQ                /* Use the now-standard shared IRQ implementation. */
        !          2196:        struct device *dev = (struct device *)dev_instance;
        !          2197: #else
        !          2198:        struct device *dev = (struct device *)(irq2dev_map[irq]);
        !          2199: #endif
        !          2200: 
        !          2201:        struct tulip_private *tp;
        !          2202:        long ioaddr;
        !          2203:        int csr5, work_budget = max_interrupt_work;
        !          2204: 
        !          2205:        if (dev == NULL) {
        !          2206:                printk (KERN_ERR" tulip_interrupt(): irq %d for unknown device.\n",
        !          2207:                                irq);
        !          2208:                return;
        !          2209:        }
        !          2210: 
        !          2211:        ioaddr = dev->base_addr;
        !          2212:        tp = (struct tulip_private *)dev->priv;
        !          2213:        if (test_and_set_bit(0, (void*)&tp->interrupt)) {
        !          2214: #ifdef SMP_CHECK
        !          2215:                printk(KERN_ERR "%s: Re-entering the interrupt handler with proc %d,"
        !          2216:                           " proc %d already handling.\n", dev->name,
        !          2217:                           tp->smp_proc_id, hard_smp_processor_id());
        !          2218: #else
        !          2219:                printk(KERN_ERR "%s: Re-entering the interrupt handler.\n", dev->name);
        !          2220: #endif
        !          2221:                return;
        !          2222:        }
        !          2223:        dev->interrupt = 1;
        !          2224: #ifdef SMP_CHECK
        !          2225:        tp->smp_proc_id = hard_smp_processor_id();
        !          2226: #endif
        !          2227: 
        !          2228:        do {
        !          2229:                csr5 = inl(ioaddr + CSR5);
        !          2230:                /* Acknowledge all of the current interrupt sources ASAP. */
        !          2231:                outl(csr5 & 0x0001ffff, ioaddr + CSR5);
        !          2232: 
        !          2233:                if (tulip_debug > 4)
        !          2234:                        printk(KERN_DEBUG "%s: interrupt  csr5=%#8.8x new csr5=%#8.8x.\n",
        !          2235:                                   dev->name, csr5, inl(dev->base_addr + CSR5));
        !          2236: 
        !          2237:                if ((csr5 & (NormalIntr|AbnormalIntr)) == 0)
        !          2238:                        break;
        !          2239: 
        !          2240:                if (csr5 & (RxIntr | RxNoBuf))
        !          2241:                        work_budget -= tulip_rx(dev);
        !          2242: 
        !          2243:                if (csr5 & (TxNoBuf | TxDied | TxIntr)) {
        !          2244:                        unsigned int dirty_tx;
        !          2245: 
        !          2246:                        for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0;
        !          2247:                                 dirty_tx++) {
        !          2248:                                int entry = dirty_tx % TX_RING_SIZE;
        !          2249:                                int status = tp->tx_ring[entry].status;
        !          2250: 
        !          2251:                                if (status < 0)
        !          2252:                                        break;                  /* It still hasn't been Txed */
        !          2253:                                /* Check for Rx filter setup frames. */
        !          2254:                                if (tp->tx_skbuff[entry] == NULL)
        !          2255:                                  continue;
        !          2256: 
        !          2257:                                if (status & 0x8000) {
        !          2258:                                        /* There was an major error, log it. */
        !          2259: #ifndef final_version
        !          2260:                                        if (tulip_debug > 1)
        !          2261:                                                printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
        !          2262:                                                           dev->name, status);
        !          2263: #endif
        !          2264:                                        tp->stats.tx_errors++;
        !          2265:                                        if (status & 0x4104) tp->stats.tx_aborted_errors++;
        !          2266:                                        if (status & 0x0C00) tp->stats.tx_carrier_errors++;
        !          2267:                                        if (status & 0x0200) tp->stats.tx_window_errors++;
        !          2268:                                        if (status & 0x0002) tp->stats.tx_fifo_errors++;
        !          2269:                                        if ((status & 0x0080) && tp->full_duplex == 0)
        !          2270:                                                tp->stats.tx_heartbeat_errors++;
        !          2271: #ifdef ETHER_STATS
        !          2272:                                        if (status & 0x0100) tp->stats.collisions16++;
        !          2273: #endif
        !          2274:                                } else {
        !          2275: #ifdef ETHER_STATS
        !          2276:                                        if (status & 0x0001) tp->stats.tx_deferred++;
        !          2277: #endif
        !          2278: #if LINUX_VERSION_CODE > 0x20127
        !          2279:                                        tp->stats.tx_bytes += tp->tx_ring[entry].length & 0x7ff;
        !          2280: #endif
        !          2281:                                        tp->stats.collisions += (status >> 3) & 15;
        !          2282:                                        tp->stats.tx_packets++;
        !          2283:                                }
        !          2284: 
        !          2285:                                /* Free the original skb. */
        !          2286: #if (LINUX_VERSION_CODE > 0x20155)
        !          2287:                                dev_kfree_skb(tp->tx_skbuff[entry]);
        !          2288: #else
        !          2289:                                dev_kfree_skb(tp->tx_skbuff[entry], FREE_WRITE);
        !          2290: #endif
        !          2291:                                tp->tx_skbuff[entry] = 0;
        !          2292:                        }
        !          2293: 
        !          2294: #ifndef final_version
        !          2295:                        if (tp->cur_tx - dirty_tx > TX_RING_SIZE) {
        !          2296:                                printk(KERN_ERR "%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
        !          2297:                                           dev->name, dirty_tx, tp->cur_tx, tp->tx_full);
        !          2298:                                dirty_tx += TX_RING_SIZE;
        !          2299:                        }
        !          2300: #endif
        !          2301: 
        !          2302:                        if (tp->tx_full && dev->tbusy
        !          2303:                                && tp->cur_tx - dirty_tx  < TX_RING_SIZE - 2) {
        !          2304:                                /* The ring is no longer full, clear tbusy. */
        !          2305:                                tp->tx_full = 0;
        !          2306:                                dev->tbusy = 0;
        !          2307:                                mark_bh(NET_BH);
        !          2308:                        }
        !          2309: 
        !          2310:                        tp->dirty_tx = dirty_tx;
        !          2311:                        if (csr5 & TxDied) {
        !          2312:                                if (tulip_debug > 1)
        !          2313:                                        printk(KERN_WARNING "%s: The transmitter stopped!"
        !          2314:                                                   "  CSR5 is %x, CSR6 %x.\n",
        !          2315:                                                   dev->name, csr5, inl(ioaddr + CSR6));
        !          2316:                                outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          2317:                                outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          2318:                        }
        !          2319:                }
        !          2320: 
        !          2321:                /* Log errors. */
        !          2322:                if (csr5 & AbnormalIntr) {      /* Abnormal error summary bit. */
        !          2323:                        if (csr5 & TxJabber) tp->stats.tx_errors++;
        !          2324:                        if (csr5 & TxFIFOUnderflow) {
        !          2325:                                if ((tp->csr6 & 0xC000) != 0xC000)
        !          2326:                                        tp->csr6 += 0x4000;     /* Bump up the Tx threshold */
        !          2327:                                else
        !          2328:                                        tp->csr6 |= 0x00200000;  /* Store-n-forward. */
        !          2329:                                /* Restart the transmit process. */
        !          2330:                                outl(tp->csr6 | 0x0002, ioaddr + CSR6);
        !          2331:                                outl(tp->csr6 | 0x2002, ioaddr + CSR6);
        !          2332:                        }
        !          2333:                        if (csr5 & RxDied) {            /* Missed a Rx frame. */
        !          2334:                                tp->stats.rx_errors++;
        !          2335:                                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
        !          2336:                        }
        !          2337:                        if (csr5 & TimerInt) {
        !          2338:                                printk(KERN_ERR "%s: Something Wicked happened! %8.8x.\n",
        !          2339:                                           dev->name, csr5);
        !          2340:                                /* Hmmmmm, it's not clear what to do here. */
        !          2341:                        }
        !          2342:                        if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)
        !          2343:                                && tp->chip_id == DC21142) {
        !          2344:                                if (tulip_debug > 1)
        !          2345:                                        printk(KERN_INFO"%s: 21142 link change, CSR5 = %8.8x.\n",
        !          2346:                                                   dev->name, csr5);
        !          2347:                                t21142_lnk_change(dev);
        !          2348:                        }
        !          2349:                        /* Clear all error sources, included undocumented ones! */
        !          2350:                        outl(0x0800f7ba, ioaddr + CSR5);
        !          2351:                }
        !          2352:                if (--work_budget < 0) {
        !          2353:                        if (tulip_debug > 1)
        !          2354:                                printk(KERN_WARNING "%s: Too much work at interrupt, "
        !          2355:                                           "csr5=0x%8.8x.\n", dev->name, csr5);
        !          2356:                        /* Acknowledge all interrupt sources. */
        !          2357:                        outl(0x8001ffff, ioaddr + CSR5);
        !          2358: #ifdef notdef
        !          2359:                        /* Clear all but standard interrupt sources. */
        !          2360:                        outl((~csr5) & 0x0001ebef, ioaddr + CSR7);
        !          2361: #endif
        !          2362:                        break;
        !          2363:                }
        !          2364:        } while (1);
        !          2365: 
        !          2366:        if (tulip_debug > 3)
        !          2367:                printk(KERN_DEBUG "%s: exiting interrupt, csr5=%#4.4x.\n",
        !          2368:                           dev->name, inl(ioaddr + CSR5));
        !          2369: 
        !          2370:        dev->interrupt = 0;
        !          2371:        clear_bit(0, (void*)&tp->interrupt);
        !          2372:        return;
        !          2373: }
        !          2374: 
        !          2375: static int
        !          2376: tulip_rx(struct device *dev)
        !          2377: {
        !          2378:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2379:        int entry = tp->cur_rx % RX_RING_SIZE;
        !          2380:        int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
        !          2381:        int work_done = 0;
        !          2382: 
        !          2383:        if (tulip_debug > 4)
        !          2384:                printk(KERN_DEBUG " In tulip_rx(), entry %d %8.8x.\n", entry,
        !          2385:                           tp->rx_ring[entry].status);
        !          2386:        /* If we own the next entry, it's a new packet. Send it up. */
        !          2387:        while (tp->rx_ring[entry].status >= 0) {
        !          2388:                s32 status = tp->rx_ring[entry].status;
        !          2389: 
        !          2390:                if (--rx_work_limit < 0)
        !          2391:                        break;
        !          2392:                if ((status & 0x0300) != 0x0300) {
        !          2393:                        if ((status & 0xffff) != 0x7fff) { /* Ingore earlier buffers. */
        !          2394:                                if (tulip_debug > 1)
        !          2395:                                        printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
        !          2396:                                                   "multiple buffers, status %8.8x!\n",
        !          2397:                                                   dev->name, status);
        !          2398:                          tp->stats.rx_length_errors++;
        !          2399:                        }
        !          2400:                } else if (status & 0x8000) {
        !          2401:                        /* There was a fatal error. */
        !          2402:                        if (tulip_debug > 2)
        !          2403:                                printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",
        !          2404:                                           dev->name, status);
        !          2405:                        tp->stats.rx_errors++; /* end of a packet.*/
        !          2406:                        if (status & 0x0890) tp->stats.rx_length_errors++;
        !          2407:                        if (status & 0x0004) tp->stats.rx_frame_errors++;
        !          2408:                        if (status & 0x0002) tp->stats.rx_crc_errors++;
        !          2409:                        if (status & 0x0001) tp->stats.rx_fifo_errors++;
        !          2410:                } else {
        !          2411:                        /* Omit the four octet CRC from the length. */
        !          2412:                        short pkt_len = ((status >> 16) & 0x7FF) - 4;
        !          2413:                        struct sk_buff *skb;
        !          2414: 
        !          2415:                        /* Check if the packet is long enough to just accept without
        !          2416:                           copying to a properly sized skbuff. */
        !          2417:                        if (pkt_len < rx_copybreak
        !          2418:                                && (skb = DEV_ALLOC_SKB(pkt_len+2)) != NULL) {
        !          2419:                                skb->dev = dev;
        !          2420:                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
        !          2421: #if LINUX_VERSION_CODE < 0x10300
        !          2422:                                memcpy(skb->data, tp->rx_ring[entry].buffer1, pkt_len);
        !          2423: #elif LINUX_VERSION_CODE < 0x20200  || defined(__alpha__)
        !          2424:                                memcpy(skb_put(skb, pkt_len),
        !          2425:                                           bus_to_virt(tp->rx_ring[entry].buffer1), pkt_len);
        !          2426: #else
        !          2427: #warning Code untested
        !          2428:                                eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1),
        !          2429:                                                                 pkt_len, 0);
        !          2430:                                skb_put(skb, pkt_len);
        !          2431: #endif
        !          2432:                                work_done++;
        !          2433:                        } else {        /* Pass up the skb already on the Rx ring. */
        !          2434:                                skb = tp->rx_skbuff[entry];
        !          2435:                                tp->rx_skbuff[entry] = NULL;
        !          2436: #ifndef final_version
        !          2437:                                {
        !          2438:                                        void *temp = skb_put(skb, pkt_len);
        !          2439:                                        if (bus_to_virt(tp->rx_ring[entry].buffer1) != temp)
        !          2440:                                                printk(KERN_ERR "%s: Internal consistency error! The "
        !          2441:                                                   "skbuff addresses do not match in tulip_rx:"
        !          2442:                                                           " %p vs. %p / %p.\n", dev->name,
        !          2443:                                                           bus_to_virt(tp->rx_ring[entry].buffer1),
        !          2444:                                                           skb->head, temp);
        !          2445:                                }
        !          2446: #else
        !          2447:                                skb_put(skb, pkt_len);
        !          2448: #endif
        !          2449:                        }
        !          2450: #if LINUX_VERSION_CODE > 0x10300
        !          2451:                        skb->protocol = eth_type_trans(skb, dev);
        !          2452: #else
        !          2453:                        skb->len = pkt_len;
        !          2454: #endif
        !          2455:                        netif_rx(skb);
        !          2456:                        dev->last_rx = jiffies;
        !          2457:                        tp->stats.rx_packets++;
        !          2458: #if LINUX_VERSION_CODE > 0x20127
        !          2459:                        tp->stats.rx_bytes += pkt_len;
        !          2460: #endif
        !          2461:                }
        !          2462:                entry = (++tp->cur_rx) % RX_RING_SIZE;
        !          2463:        }
        !          2464: 
        !          2465:        /* Refill the Rx ring buffers. */
        !          2466:        for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {
        !          2467:                entry = tp->dirty_rx % RX_RING_SIZE;
        !          2468:                if (tp->rx_skbuff[entry] == NULL) {
        !          2469:                        struct sk_buff *skb;
        !          2470:                        skb = tp->rx_skbuff[entry] = DEV_ALLOC_SKB(PKT_BUF_SZ);
        !          2471:                        if (skb == NULL)
        !          2472:                                break;
        !          2473:                        skb->dev = dev;                 /* Mark as being used by this device. */
        !          2474: #if LINUX_VERSION_CODE > 0x10300
        !          2475:                        tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail);
        !          2476: #else
        !          2477:                        tp->rx_ring[entry].buffer1 = virt_to_bus(skb->data);
        !          2478: #endif
        !          2479:                        work_done++;
        !          2480:                }
        !          2481:                tp->rx_ring[entry].status = 0x80000000;
        !          2482:        }
        !          2483: 
        !          2484:        return work_done;
        !          2485: }
        !          2486: 
        !          2487: static int
        !          2488: tulip_close(struct device *dev)
        !          2489: {
        !          2490:        long ioaddr = dev->base_addr;
        !          2491:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2492:        int i;
        !          2493: 
        !          2494:        dev->start = 0;
        !          2495:        dev->tbusy = 1;
        !          2496: 
        !          2497:        if (tulip_debug > 1)
        !          2498:                printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
        !          2499:                           dev->name, inl(ioaddr + CSR5));
        !          2500: 
        !          2501:        /* Disable interrupts by clearing the interrupt mask. */
        !          2502:        outl(0x00000000, ioaddr + CSR7);
        !          2503:        /* Stop the chip's Tx and Rx processes. */
        !          2504:        outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
        !          2505:        /* 21040 -- Leave the card in 10baseT state. */
        !          2506:        if (tp->chip_id == DC21040)
        !          2507:                outl(0x00000004, ioaddr + CSR13);
        !          2508: 
        !          2509:        tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
        !          2510: 
        !          2511:        del_timer(&tp->timer);
        !          2512: 
        !          2513: #ifdef SA_SHIRQ
        !          2514:        free_irq(dev->irq, dev);
        !          2515: #else
        !          2516:        free_irq(dev->irq);
        !          2517:        irq2dev_map[dev->irq] = 0;
        !          2518: #endif
        !          2519: 
        !          2520:        /* Free all the skbuffs in the Rx queue. */
        !          2521:        for (i = 0; i < RX_RING_SIZE; i++) {
        !          2522:                struct sk_buff *skb = tp->rx_skbuff[i];
        !          2523:                tp->rx_skbuff[i] = 0;
        !          2524:                tp->rx_ring[i].status = 0;              /* Not owned by Tulip chip. */
        !          2525:                tp->rx_ring[i].length = 0;
        !          2526:                tp->rx_ring[i].buffer1 = 0xBADF00D0; /* An invalid address. */
        !          2527:                if (skb) {
        !          2528: #if LINUX_VERSION_CODE < 0x20100
        !          2529:                        skb->free = 1;
        !          2530: #endif
        !          2531: #if (LINUX_VERSION_CODE > 0x20155)
        !          2532:                        dev_kfree_skb(skb);
        !          2533: #else
        !          2534:                        dev_kfree_skb(skb, FREE_WRITE);
        !          2535: #endif
        !          2536:                }
        !          2537:        }
        !          2538:        for (i = 0; i < TX_RING_SIZE; i++) {
        !          2539:                if (tp->tx_skbuff[i])
        !          2540: #if (LINUX_VERSION_CODE > 0x20155)
        !          2541:                        dev_kfree_skb(tp->tx_skbuff[i]);
        !          2542: #else
        !          2543:                        dev_kfree_skb(tp->tx_skbuff[i], FREE_WRITE);
        !          2544: #endif
        !          2545:                tp->tx_skbuff[i] = 0;
        !          2546:        }
        !          2547: 
        !          2548: 
        !          2549:        MOD_DEC_USE_COUNT;
        !          2550: 
        !          2551:        return 0;
        !          2552: }
        !          2553: 
        !          2554: static struct enet_statistics *
        !          2555: tulip_get_stats(struct device *dev)
        !          2556: {
        !          2557:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2558:        long ioaddr = dev->base_addr;
        !          2559: 
        !          2560:        if (dev->start)
        !          2561:                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
        !          2562: 
        !          2563:        return &tp->stats;
        !          2564: }
        !          2565: 
        !          2566: #ifdef HAVE_PRIVATE_IOCTL
        !          2567: /* Provide ioctl() calls to examine the MII xcvr state. */
        !          2568: static int private_ioctl(struct device *dev, struct ifreq *rq, int cmd)
        !          2569: {
        !          2570:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2571:        long ioaddr = dev->base_addr;
        !          2572:        u16 *data = (u16 *)&rq->ifr_data;
        !          2573:        int phy = tp->phys[0] & 0x1f;
        !          2574:        long flags;
        !          2575: 
        !          2576:        switch(cmd) {
        !          2577:        case SIOCDEVPRIVATE:            /* Get the address of the PHY in use. */
        !          2578:                if (tp->mtable  &&  tp->mtable->has_mii)
        !          2579:                        data[0] = phy;
        !          2580:                else if (tp->chip_id == DC21142)
        !          2581:                        data[0] = 32;
        !          2582:                else
        !          2583:                        return -ENODEV;
        !          2584:                return 0;
        !          2585:        case SIOCDEVPRIVATE+1:          /* Read the specified MII register. */
        !          2586:                if (data[0] == 32) {  /* 21142 pseudo-MII */
        !          2587:                        int csr12 = inl(ioaddr + CSR12);
        !          2588:                        int csr14 = inl(ioaddr + CSR14);
        !          2589:                        switch (data[1]) {
        !          2590:                        case 0: {
        !          2591:                                data[3] = ((csr14<<13)&0x4000) + ((csr14<<5)&0x1000);
        !          2592:                                break; }
        !          2593:                        case 1:
        !          2594:                                data[3] = 0x7848 + ((csr12&0x7000) == 0x5000 ? 0x20 : 0)
        !          2595:                                        + (csr12&0x06 ? 0x04 : 0);
        !          2596:                                break;
        !          2597:                        case 4: {
        !          2598:                                int csr14 = inl(ioaddr + CSR14);
        !          2599:                                data[3] = ((csr14>>9)&0x0380) + ((csr14>>1)&0x20) + 1;
        !          2600:                                break;
        !          2601:                        }
        !          2602:                        case 5: data[3] = inl(ioaddr + CSR12) >> 16; break;
        !          2603:                        default: data[3] = 0; break;
        !          2604:                        }
        !          2605:                } else {
        !          2606:                        save_flags(flags);
        !          2607:                        cli();
        !          2608:                        data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f);
        !          2609:                        restore_flags(flags);
        !          2610:                }
        !          2611:                return 0;
        !          2612:        case SIOCDEVPRIVATE+2:          /* Write the specified MII register */
        !          2613:                if (!suser())
        !          2614:                        return -EPERM;
        !          2615:                if (data[0] == 32) {  /* 21142 pseudo-MII */
        !          2616:                } else {
        !          2617:                        save_flags(flags);
        !          2618:                        cli();
        !          2619:                        mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
        !          2620:                        restore_flags(flags);
        !          2621:                }
        !          2622:                return 0;
        !          2623:        default:
        !          2624:                return -EOPNOTSUPP;
        !          2625:        }
        !          2626: 
        !          2627:        return -EOPNOTSUPP;
        !          2628: }
        !          2629: #endif  /* HAVE_PRIVATE_IOCTL */
        !          2630: 
        !          2631: /* Set or clear the multicast filter for this adaptor.
        !          2632:    Note that we only use exclusion around actually queueing the
        !          2633:    new frame, not around filling tp->setup_frame.  This is non-deterministic
        !          2634:    when re-entered but still correct. */
        !          2635: 
        !          2636: /* The little-endian AUTODIN32 ethernet CRC calculation.
        !          2637:    N.B. Do not use for bulk data, use a table-based routine instead.
        !          2638:    This is common code and should be moved to net/core/crc.c */
        !          2639: static unsigned const ethernet_polynomial_le = 0xedb88320U;
        !          2640: static inline unsigned ether_crc_le(int length, unsigned char *data)
        !          2641: {
        !          2642:        unsigned int crc = 0xffffffff;  /* Initial value. */
        !          2643:        while(--length >= 0) {
        !          2644:                unsigned char current_octet = *data++;
        !          2645:                int bit;
        !          2646:                for (bit = 8; --bit >= 0; current_octet >>= 1) {
        !          2647:                        if ((crc ^ current_octet) & 1) {
        !          2648:                                crc >>= 1;
        !          2649:                                crc ^= ethernet_polynomial_le;
        !          2650:                        } else
        !          2651:                                crc >>= 1;
        !          2652:                }
        !          2653:        }
        !          2654:        return crc;
        !          2655: }
        !          2656: 
        !          2657: #ifdef NEW_MULTICAST
        !          2658: static void set_rx_mode(struct device *dev)
        !          2659: #else
        !          2660: static void set_rx_mode(struct device *dev, int num_addrs, void *addrs)
        !          2661: #endif
        !          2662: {
        !          2663:        long ioaddr = dev->base_addr;
        !          2664:        int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
        !          2665:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          2666: 
        !          2667:        tp->csr6 &= ~0x00D5;
        !          2668:        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
        !          2669:                outl(csr6 | 0x00C0, ioaddr + CSR6);
        !          2670:                /* Unconditionally log net taps. */
        !          2671:                printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name);
        !          2672:                tp->csr6 |= 0xC0;
        !          2673:        } else if ((dev->mc_count > 1000)  ||  (dev->flags & IFF_ALLMULTI)) {
        !          2674:                /* Too many to filter perfectly -- accept all multicasts. */
        !          2675:                outl(csr6 | 0x0080, ioaddr + CSR6);
        !          2676:                tp->csr6 |= 0x80;
        !          2677:        } else {
        !          2678:                u32 *setup_frm = tp->setup_frame;
        !          2679:                struct dev_mc_list *mclist;
        !          2680:                u16 *eaddrs;
        !          2681:                u32 tx_flags;
        !          2682:                int i;
        !          2683: 
        !          2684:                if (dev->mc_count > 14) { /* Must use a multicast hash table. */
        !          2685:                  u16 hash_table[32];
        !          2686:                  memset(hash_table, 0, sizeof(hash_table));
        !          2687:                  /* This should work on big-endian machines as well. */
        !          2688:                  for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
        !          2689:                           i++, mclist = mclist->next)
        !          2690:                          set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
        !          2691:                                          hash_table);
        !          2692:                  /* Copy the hash table to the setup frame.
        !          2693:                         NOTE that only the LOW SHORTWORD of setup_frame[] is valid! */
        !          2694:                  for (i = 0; i < 32; i++)
        !          2695:                        *setup_frm++ = hash_table[i];
        !          2696:                  setup_frm += 7;
        !          2697:                  tx_flags = 0x08400000 | 192;
        !          2698:                  /* Too clever: i > 15 for fall-though. */
        !          2699:                } else {
        !          2700:                  /* We have <= 15 addresses so we can use the wonderful
        !          2701:                         16 address perfect filtering of the Tulip. */
        !          2702:                  for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
        !          2703:                           i++, mclist = mclist->next) {
        !          2704:                        /* Note that only the low shortword of setup_frame[] is valid!
        !          2705:                           This code may require tweaking for non-x86 architectures! */
        !          2706:                        eaddrs = (u16 *)mclist->dmi_addr;
        !          2707:                        *setup_frm++ = *eaddrs++;
        !          2708:                        *setup_frm++ = *eaddrs++;
        !          2709:                        *setup_frm++ = *eaddrs++;
        !          2710:                  }
        !          2711:                  /* Fill the rest of the table with our physical address.
        !          2712:                         Once again, only the low shortword or setup_frame[] is valid! */
        !          2713:                  *setup_frm++ = 0xffff;
        !          2714:                  *setup_frm++ = 0xffff;
        !          2715:                  *setup_frm++ = 0xffff;
        !          2716:                  tx_flags = 0x08000000 | 192;
        !          2717:                }
        !          2718:                eaddrs = (u16 *)dev->dev_addr;
        !          2719:                do {
        !          2720:                        *setup_frm++ = eaddrs[0];
        !          2721:                        *setup_frm++ = eaddrs[1];
        !          2722:                        *setup_frm++ = eaddrs[2];
        !          2723:                } while (++i < 15);
        !          2724:                /* Now add this frame to the Tx list. */
        !          2725:                if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
        !          2726:                        /* Same setup recently queued, we need not add it. */
        !          2727:                } else {
        !          2728:                        unsigned long flags;
        !          2729:                        unsigned int entry;
        !          2730:                        
        !          2731:                        save_flags(flags); cli();
        !          2732:                        entry = tp->cur_tx++ % TX_RING_SIZE;
        !          2733: 
        !          2734:                        if (entry != 0) {
        !          2735:                                /* Avoid a chip errata by prefixing a dummy entry. */
        !          2736:                                tp->tx_skbuff[entry] = 0;
        !          2737:                                tp->tx_ring[entry].length =
        !          2738:                                        (entry == TX_RING_SIZE-1) ? 0x02000000 : 0;
        !          2739:                                tp->tx_ring[entry].buffer1 = 0;
        !          2740:                                tp->tx_ring[entry].status = 0x80000000;
        !          2741:                                entry = tp->cur_tx++ % TX_RING_SIZE;
        !          2742:                        }
        !          2743: 
        !          2744:                        tp->tx_skbuff[entry] = 0;
        !          2745:                        /* Put the setup frame on the Tx list. */
        !          2746:                        if (entry == TX_RING_SIZE-1)
        !          2747:                                tx_flags |= 0x02000000;         /* Wrap ring. */
        !          2748:                        tp->tx_ring[entry].length = tx_flags;
        !          2749:                        tp->tx_ring[entry].buffer1 = virt_to_bus(tp->setup_frame);
        !          2750:                        tp->tx_ring[entry].status = 0x80000000;
        !          2751:                        if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2) {
        !          2752:                                dev->tbusy = 1;
        !          2753:                                tp->tx_full = 1;
        !          2754:                        }
        !          2755:                        restore_flags(flags);
        !          2756:                        /* Trigger an immediate transmit demand. */
        !          2757:                        outl(0, ioaddr + CSR1);
        !          2758:                }
        !          2759:                outl(csr6 | 0x0000, ioaddr + CSR6);
        !          2760:        }
        !          2761: }
        !          2762: 
        !          2763: #ifdef CARDBUS
        !          2764: 
        !          2765: #include <pcmcia/driver_ops.h>
        !          2766: 
        !          2767: static dev_node_t *tulip_attach(dev_locator_t *loc)
        !          2768: {
        !          2769:        u16 dev_id;
        !          2770:        u32 io;
        !          2771:        u8 bus, devfn;
        !          2772:        struct device *dev;
        !          2773: 
        !          2774:        if (loc->bus != LOC_PCI) return NULL;
        !          2775:        bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
        !          2776:        printk(KERN_INFO "tulip_attach(bus %d, function %d)\n", bus, devfn);
        !          2777:        pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &io);
        !          2778:        pcibios_read_config_word(bus, devfn, PCI_DEVICE_ID, &dev_id);
        !          2779:        io &= ~3;
        !          2780:        dev = tulip_probe1(bus, devfn, NULL, DC21142, -1);
        !          2781:        if (dev) {
        !          2782:                dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
        !          2783:                strcpy(node->dev_name, dev->name);
        !          2784:                node->major = node->minor = 0;
        !          2785:                node->next = NULL;
        !          2786:                MOD_INC_USE_COUNT;
        !          2787:                return node;
        !          2788:        }
        !          2789:        return NULL;
        !          2790: }
        !          2791: 
        !          2792: static void tulip_detach(dev_node_t *node)
        !          2793: {
        !          2794:        struct device **devp, **next;
        !          2795:        printk(KERN_INFO "tulip_detach(%s)\n", node->dev_name);
        !          2796:        for (devp = &root_tulip_dev; *devp; devp = next) {
        !          2797:                next = &((struct tulip_private *)(*devp)->priv)->next_module;
        !          2798:                if (strcmp((*devp)->name, node->dev_name) == 0) break;
        !          2799:        }
        !          2800:        if (*devp) {
        !          2801:                unregister_netdev(*devp);
        !          2802:                kfree(*devp);
        !          2803:                *devp = *next;
        !          2804:                kfree(node);
        !          2805:                MOD_DEC_USE_COUNT;
        !          2806:        }
        !          2807: }
        !          2808: 
        !          2809: struct driver_operations tulip_ops = {
        !          2810:        "tulip_cb", tulip_attach, NULL, NULL, tulip_detach
        !          2811: };
        !          2812: 
        !          2813: #endif  /* Cardbus support */
        !          2814: 
        !          2815: 
        !          2816: #ifdef MODULE
        !          2817: #if LINUX_VERSION_CODE > 0x20118
        !          2818: MODULE_AUTHOR("Donald Becker <[email protected]>");
        !          2819: MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
        !          2820: MODULE_PARM(debug, "i");
        !          2821: MODULE_PARM(max_interrupt_work, "i");
        !          2822: MODULE_PARM(reverse_probe, "i");
        !          2823: MODULE_PARM(rx_copybreak, "i");
        !          2824: MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !          2825: MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !          2826: #endif
        !          2827: 
        !          2828: /* An additional parameter that may be passed in... */
        !          2829: static int debug = -1;
        !          2830: 
        !          2831: int
        !          2832: init_module(void)
        !          2833: {
        !          2834:        if (debug >= 0)
        !          2835:                tulip_debug = debug;
        !          2836: 
        !          2837: #ifdef CARDBUS
        !          2838:        register_driver(&tulip_ops);
        !          2839:        return 0;
        !          2840: #else
        !          2841:        return tulip_probe(NULL);
        !          2842: #endif
        !          2843: }
        !          2844: 
        !          2845: void
        !          2846: cleanup_module(void)
        !          2847: {
        !          2848:        struct device *next_dev;
        !          2849: 
        !          2850: #ifdef CARDBUS
        !          2851:        unregister_driver(&tulip_ops);
        !          2852: #endif
        !          2853: 
        !          2854:        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
        !          2855:        while (root_tulip_dev) {
        !          2856:                next_dev = ((struct tulip_private *)root_tulip_dev->priv)->next_module;
        !          2857:                unregister_netdev(root_tulip_dev);
        !          2858:                release_region(root_tulip_dev->base_addr, TULIP_TOTAL_SIZE);
        !          2859:                kfree(root_tulip_dev);
        !          2860:                root_tulip_dev = next_dev;
        !          2861:        }
        !          2862: }
        !          2863: 
        !          2864: #endif  /* MODULE */
        !          2865: 
        !          2866: /*
        !          2867:  * Local variables:
        !          2868:  *  SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
        !          2869:  *  compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
        !          2870:  *  c-indent-level: 4
        !          2871:  *  c-basic-offset: 4
        !          2872:  *  tab-width: 4
        !          2873:  * End:
        !          2874:  */

unix.superglobalmegacorp.com

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