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

1.1.1.3 ! root        1: /* tulip.c: A DEC 21040 family ethernet driver for Linux. */
1.1       root        2: /*
1.1.1.3 ! root        3:        Written/copyright 1994-2003 by Donald Becker.
1.1       root        4: 
1.1.1.3 ! root        5:        This software may be used and distributed according to the terms of
        !             6:        the GNU General Public License (GPL), incorporated herein by reference.
        !             7:        Drivers based on or derived from this code fall under the GPL and must
        !             8:        retain the authorship, copyright and license notice.  This file is not
        !             9:        a complete program and may only be used when the entire operating
        !            10:        system is licensed under the GPL.
1.1       root       11: 
1.1.1.2   root       12:        This driver is for the Digital "Tulip" Ethernet adapter interface.
1.1       root       13:        It should work with most DEC 21*4*-based chips/ethercards, as well as
1.1.1.2   root       14:        with work-alike chips from Lite-On (PNIC) and Macronix (MXIC) and ASIX.
1.1       root       15: 
1.1.1.3 ! root       16:        The author may be reached as [email protected], or C/O
        !            17:        Scyld Computing Corporation
        !            18:        914 Bay Ridge Road, Suite 220
        !            19:        Annapolis MD 21403
1.1       root       20: 
                     21:        Support and updates available at
1.1.1.3 ! root       22:        http://www.scyld.com/network/tulip.html
1.1       root       23: */
                     24: 
1.1.1.3 ! root       25: /* These identify the driver base version and may not be removed. */
        !            26: static const char version1[] =
        !            27: "tulip.c:v0.97 7/22/2003  Written by Donald Becker <[email protected]>\n";
        !            28: static const char version2[] =
        !            29: "  http://www.scyld.com/network/tulip.html\n";
        !            30: 
1.1       root       31: #define SMP_CHECK
                     32: 
1.1.1.3 ! root       33: /* The user-configurable values.
        !            34:    These may be modified when a driver module is loaded.*/
        !            35: 
        !            36: static int debug = 2;                  /* Message enable: 0..31 = no..all messages. */
1.1       root       37: 
                     38: /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
                     39: static int max_interrupt_work = 25;
                     40: 
                     41: #define MAX_UNITS 8
                     42: /* Used to pass the full-duplex flag, etc. */
                     43: static int full_duplex[MAX_UNITS] = {0, };
                     44: static int options[MAX_UNITS] = {0, };
                     45: static int mtu[MAX_UNITS] = {0, };                     /* Jumbo MTU for interfaces. */
                     46: 
                     47: /*  The possible media types that can be set in options[] are: */
1.1.1.3 ! root       48: #define MEDIA_MASK 31
        !            49: static const char * const medianame[32] = {
1.1       root       50:        "10baseT", "10base2", "AUI", "100baseTx",
1.1.1.3 ! root       51:        "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
        !            52:        "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
        !            53:        "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
        !            54:        "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
        !            55:        "","","","", "","","","",  "","","","Transceiver reset",
1.1       root       56: };
                     57: 
                     58: /* Set if the PCI BIOS detects the chips on a multiport board backwards. */
                     59: #ifdef REVERSE_PROBE_ORDER
                     60: static int reverse_probe = 1;
                     61: #else
                     62: static int reverse_probe = 0;
                     63: #endif
                     64: 
                     65: /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
1.1.1.3 ! root       66: #ifdef __alpha__                               /* Always copy to aligned IP headers. */
1.1       root       67: static int rx_copybreak = 1518;
                     68: #else
                     69: static int rx_copybreak = 100;
                     70: #endif
                     71: 
1.1.1.2   root       72: /*
                     73:   Set the bus performance register.
                     74:        Typical: Set 16 longword cache alignment, no burst limit.
                     75:        Cache alignment bits 15:14           Burst length 13:8
                     76:                0000    No alignment  0x00000000 unlimited              0800 8 longwords
                     77:                4000    8  longwords            0100 1 longword         1000 16 longwords
                     78:                8000    16 longwords            0200 2 longwords        2000 32 longwords
                     79:                C000    32  longwords           0400 4 longwords
                     80:        Warning: many older 486 systems are broken and require setting 0x00A04800
                     81:           8 longword cache alignment, 8 longword burst.
                     82:        ToDo: Non-Intel setting could be better.
                     83: */
                     84: 
1.1.1.3 ! root       85: #if defined(__alpha__) || defined(__x86_64) || defined(__ia64)
1.1.1.2   root       86: static int csr0 = 0x01A00000 | 0xE000;
                     87: #elif defined(__i386__) || defined(__powerpc__) || defined(__sparc__)
1.1.1.3 ! root       88: /* Do *not* rely on hardware endian correction for big-endian machines! */
1.1.1.2   root       89: static int csr0 = 0x01A00000 | 0x8000;
                     90: #else
                     91: #warning Processor architecture undefined!
                     92: static int csr0 = 0x00A00000 | 0x4800;
                     93: #endif
                     94: 
1.1.1.3 ! root       95: /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
        !            96:    Typical is a 64 element hash table based on the Ethernet CRC.
        !            97:    This value does not apply to the 512 bit table chips.
        !            98: */
        !            99: static int multicast_filter_limit = 32;
        !           100: 
        !           101: /* Operational parameters that are set at compile time. */
        !           102: 
        !           103: /* Keep the descriptor ring sizes a power of two for efficiency.
        !           104:    The Tx queue length limits transmit packets to a portion of the available
        !           105:    ring entries.  It should be at least one element less to allow multicast
        !           106:    filter setup frames to be queued.  It must be at least four for hysteresis.
        !           107:    Making the Tx queue too long decreases the effectiveness of channel
        !           108:    bonding and packet priority.
        !           109:    Large receive rings waste memory and confound network buffer limits.
        !           110:    These values have been carefully studied: changing these might mask a
        !           111:    problem, it won't fix it.
        !           112: */
        !           113: #define TX_RING_SIZE   16
        !           114: #define TX_QUEUE_LEN   10
        !           115: #define RX_RING_SIZE   32
        !           116: 
1.1       root      117: /* Operational parameters that usually are not changed. */
                    118: /* Time in jiffies before concluding the transmitter is hung. */
1.1.1.3 ! root      119: #define TX_TIMEOUT  (6*HZ)
        !           120: /* Preferred skbuff allocation size. */
        !           121: #define PKT_BUF_SZ             1536
1.1.1.2   root      122: /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
                    123:    to support a pre-NWay full-duplex signaling mechanism using short frames.
                    124:    No one knows what it should be, but if left at its default value some
                    125:    10base2(!) packets trigger a full-duplex-request interrupt. */
                    126: #define FULL_DUPLEX_MAGIC      0x6969
                    127: 
1.1.1.3 ! root      128: /* The include file section.  We start by doing checks and fix-ups for
        !           129:    missing compile flags. */
        !           130: #ifndef __KERNEL__
        !           131: #define __KERNEL__
        !           132: #endif
        !           133: #if !defined(__OPTIMIZE__)
1.1.1.2   root      134: #warning  You must compile this file with the correct options!
                    135: #warning  See the last lines of the source file.
                    136: #error You must compile this driver with "-O".
                    137: #endif
1.1       root      138: 
                    139: #include <linux/config.h>
1.1.1.3 ! root      140: #if defined(CONFIG_SMP)  &&  ! defined(__SMP__)
        !           141: #define __SMP__
        !           142: #endif
        !           143: #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && ! defined(MODVERSIONS)
        !           144: #define MODVERSIONS
        !           145: #endif
        !           146: 
1.1.1.2   root      147: #include <linux/version.h>
1.1.1.3 ! root      148: #if defined(MODVERSIONS)
1.1       root      149: #include <linux/modversions.h>
                    150: #endif
                    151: #include <linux/module.h>
1.1.1.3 ! root      152: 
1.1       root      153: 
                    154: #include <linux/kernel.h>
                    155: #include <linux/string.h>
                    156: #include <linux/timer.h>
                    157: #include <linux/errno.h>
                    158: #include <linux/ioport.h>
1.1.1.3 ! root      159: #if LINUX_VERSION_CODE >= 0x20400
        !           160: #include <linux/slab.h>
        !           161: #else
1.1       root      162: #include <linux/malloc.h>
1.1.1.3 ! root      163: #endif
1.1       root      164: #include <linux/interrupt.h>
                    165: #include <linux/pci.h>
                    166: #include <linux/netdevice.h>
                    167: #include <linux/etherdevice.h>
                    168: #include <linux/skbuff.h>
1.1.1.2   root      169: #include <asm/processor.h>             /* Processor type for cache alignment. */
                    170: #include <asm/bitops.h>
                    171: #include <asm/io.h>
                    172: #include <asm/unaligned.h>
1.1       root      173: 
1.1.1.3 ! root      174: #ifdef INLINE_PCISCAN
        !           175: #include "k_compat.h"
        !           176: #else
        !           177: #include "pci-scan.h"
        !           178: #include "kern_compat.h"
        !           179: #endif
        !           180: 
        !           181: /* Condensed operations for readability. */
        !           182: #define virt_to_le32desc(addr)  cpu_to_le32(virt_to_bus(addr))
        !           183: 
        !           184: #if (LINUX_VERSION_CODE >= 0x20100)  &&  defined(MODULE)
        !           185: char kernel_version[] = UTS_RELEASE;
        !           186: #endif
1.1       root      187: 
1.1.1.3 ! root      188: MODULE_AUTHOR("Donald Becker <[email protected]>");
1.1.1.2   root      189: MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
1.1.1.3 ! root      190: MODULE_LICENSE("GPL");
1.1.1.2   root      191: MODULE_PARM(debug, "i");
                    192: MODULE_PARM(max_interrupt_work, "i");
                    193: MODULE_PARM(reverse_probe, "i");
                    194: MODULE_PARM(rx_copybreak, "i");
                    195: MODULE_PARM(csr0, "i");
                    196: MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
                    197: MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
1.1.1.3 ! root      198: MODULE_PARM(multicast_filter_limit, "i");
        !           199: #ifdef MODULE_PARM_DESC
        !           200: MODULE_PARM_DESC(debug, "Tulip driver message level (0-31)");
        !           201: MODULE_PARM_DESC(options,
        !           202:                                 "Tulip: force transceiver type or fixed speed+duplex");
        !           203: MODULE_PARM_DESC(max_interrupt_work,
        !           204:                                 "Tulip driver maximum events handled per interrupt");
        !           205: MODULE_PARM_DESC(full_duplex, "Tulip: non-zero to set forced full duplex.");
        !           206: MODULE_PARM_DESC(rx_copybreak,
        !           207:                                 "Tulip breakpoint in bytes for copy-only-tiny-frames");
        !           208: MODULE_PARM_DESC(multicast_filter_limit,
        !           209:                                 "Tulip breakpoint for switching to Rx-all-multicast");
        !           210: MODULE_PARM_DESC(reverse_probe, "Search PCI devices in reverse order to work "
        !           211:                                 "around misordered multiport NICS.");
        !           212: MODULE_PARM_DESC(csr0, "Special setting for the CSR0 PCI bus parameter "
        !           213:                                 "register.");
        !           214: #endif
        !           215: 
        !           216: /* This driver was originally written to use I/O space access, but now
        !           217:    uses memory space by default. Override this this with -DUSE_IO_OPS. */
        !           218: #if (LINUX_VERSION_CODE < 0x20100)  ||  ! defined(MODULE)
        !           219: #define USE_IO_OPS
        !           220: #endif
        !           221: #ifndef USE_IO_OPS
        !           222: #undef inb
        !           223: #undef inw
        !           224: #undef inl
        !           225: #undef outb
        !           226: #undef outw
        !           227: #undef outl
        !           228: #define inb readb
        !           229: #define inw readw
        !           230: #define inl readl
        !           231: #define outb writeb
        !           232: #define outw writew
        !           233: #define outl writel
1.1       root      234: #endif
                    235: 
                    236: /*
                    237:                                Theory of Operation
                    238: 
                    239: I. Board Compatibility
                    240: 
                    241: This device driver is designed for the DECchip "Tulip", Digital's
                    242: single-chip ethernet controllers for PCI.  Supported members of the family
1.1.1.2   root      243: are the 21040, 21041, 21140, 21140A, 21142, and 21143.  Similar work-alike
                    244: chips from Lite-On, Macronics, ASIX, Compex and other listed below are also
1.1.1.3 ! root      245: supported.
1.1.1.2   root      246: 
                    247: These chips are used on at least 140 unique PCI board designs.  The great
                    248: number of chips and board designs supported is the reason for the
                    249: driver size and complexity.  Almost of the increasing complexity is in the
                    250: board configuration and media selection code.  There is very little
                    251: increasing in the operational critical path length.
1.1       root      252: 
                    253: II. Board-specific settings
                    254: 
                    255: PCI bus devices are configured by the system at boot time, so no jumpers
                    256: need to be set on the board.  The system BIOS preferably should assign the
                    257: PCI INTA signal to an otherwise unused system IRQ line.
1.1.1.2   root      258: 
                    259: Some boards have EEPROMs tables with default media entry.  The factory default
                    260: is usually "autoselect".  This should only be overridden when using
                    261: transceiver connections without link beat e.g. 10base2 or AUI, or (rarely!)
                    262: for forcing full-duplex when used with old link partners that do not do
1.1.1.3 ! root      263: autonegotiation.
1.1       root      264: 
                    265: III. Driver operation
                    266: 
                    267: IIIa. Ring buffers
                    268: 
                    269: The Tulip can use either ring buffers or lists of Tx and Rx descriptors.
                    270: This driver uses statically allocated rings of Rx and Tx descriptors, set at
                    271: compile time by RX/TX_RING_SIZE.  This version of the driver allocates skbuffs
                    272: for the Rx ring buffers at open() time and passes the skb->data field to the
                    273: Tulip as receive data buffers.  When an incoming frame is less than
                    274: RX_COPYBREAK bytes long, a fresh skbuff is allocated and the frame is
                    275: copied to the new skbuff.  When the incoming frame is larger, the skbuff is
                    276: passed directly up the protocol stack and replaced by a newly allocated
                    277: skbuff.
                    278: 
                    279: The RX_COPYBREAK value is chosen to trade-off the memory wasted by
                    280: using a full-sized skbuff for small frames vs. the copying costs of larger
                    281: frames.  For small frames the copying cost is negligible (esp. considering
                    282: that we are pre-loading the cache with immediately useful header
                    283: information).  For large frames the copying cost is non-trivial, and the
                    284: larger copy might flush the cache of useful data.  A subtle aspect of this
                    285: choice is that the Tulip only receives into longword aligned buffers, thus
1.1.1.3 ! root      286: the IP header at offset 14 is not longword aligned for further processing.
1.1       root      287: Copied frames are put into the new skbuff at an offset of "+2", thus copying
                    288: has the beneficial effect of aligning the IP header and preloading the
                    289: cache.
                    290: 
                    291: IIIC. Synchronization
                    292: The driver runs as two independent, single-threaded flows of control.  One
                    293: is the send-packet routine, which enforces single-threaded use by the
                    294: dev->tbusy flag.  The other thread is the interrupt handler, which is single
                    295: threaded by the hardware and other software.
                    296: 
                    297: The send packet thread has partial control over the Tx ring and 'dev->tbusy'
1.1.1.3 ! root      298: flag.  It sets the tbusy flag whenever it is queuing a Tx packet. If the next
1.1       root      299: queue slot is empty, it clears the tbusy flag when finished otherwise it sets
                    300: the 'tp->tx_full' flag.
                    301: 
                    302: The interrupt handler has exclusive control over the Rx ring and records stats
1.1.1.3 ! root      303: from the Tx ring.  (The Tx-done interrupt can not be selectively turned off, so
        !           304: we cannot avoid the interrupt overhead by having the Tx routine reap the Tx
1.1       root      305: stats.)         After reaping the stats, it marks the queue entry as empty by setting
                    306: the 'base' to zero.     Iff the 'tp->tx_full' flag is set, it clears both the
                    307: tx_full and tbusy flags.
                    308: 
                    309: IV. Notes
                    310: 
1.1.1.2   root      311: Thanks to Duke Kamstra of SMC for long ago providing an EtherPower board.
                    312: Greg LaPolla at Linksys provided PNIC and other Linksys boards.
                    313: Znyx provided a four-port card for testing.
1.1       root      314: 
                    315: IVb. References
                    316: 
1.1.1.3 ! root      317: http://scyld.com/expert/NWay.html
1.1       root      318: http://www.digital.com  (search for current 21*4* datasheets and "21X4 SROM")
1.1.1.2   root      319: http://www.national.com/pf/DP/DP83840A.html
                    320: http://www.asix.com.tw/pmac.htm
                    321: http://www.admtek.com.tw/
1.1       root      322: 
                    323: IVc. Errata
                    324: 
1.1.1.2   root      325: The old DEC databooks were light on details.
1.1       root      326: The 21040 databook claims that CSR13, CSR14, and CSR15 should each be the last
1.1.1.2   root      327: register of the set CSR12-15 written.  Hmmm, now how is that possible?
1.1       root      328: 
1.1.1.2   root      329: The DEC SROM format is very badly designed not precisely defined, leading to
                    330: part of the media selection junkheap below.  Some boards do not have EEPROM
                    331: media tables and need to be patched up.  Worse, other boards use the DEC
1.1.1.3 ! root      332: design kit media table when it is not correct for their design.
1.1       root      333: 
1.1.1.2   root      334: We cannot use MII interrupts because there is no defined GPIO pin to attach
                    335: them.  The MII transceiver status is polled using an kernel timer.
1.1       root      336: 
1.1.1.2   root      337: */
1.1       root      338: 
1.1.1.3 ! root      339: static void *tulip_probe1(struct pci_dev *pdev, void *init_dev,
        !           340:                                                  long ioaddr, int irq, int chip_idx, int find_cnt);
        !           341: static int tulip_pwr_event(void *dev_instance, int event);
        !           342: 
        !           343: #ifdef USE_IO_OPS
        !           344: #define TULIP_IOTYPE  PCI_USES_MASTER | PCI_USES_IO | PCI_ADDR0
        !           345: #define TULIP_SIZE 0x80
        !           346: #define TULIP_SIZE1 0x100
        !           347: #else
        !           348: #define TULIP_IOTYPE  PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR1
        !           349: #define TULIP_SIZE   0x400             /* New PCI v2.1 recommends 4K min mem size. */
        !           350: #define TULIP_SIZE1    0x400           /* New PCI v2.1 recommends 4K min mem size. */
        !           351: #endif
1.1       root      352: 
1.1.1.3 ! root      353: /* This much match tulip_tbl[]!  Note 21142 == 21143. */
        !           354: enum tulip_chips {
        !           355:        DC21040=0, DC21041=1, DC21140=2, DC21142=3, DC21143=3,
        !           356:        LC82C168, MX98713, MX98715, MX98725, AX88141, AX88140, PNIC2, COMET,
        !           357:        COMPEX9881, I21145, XIRCOM, CONEXANT,
        !           358:        /* These flags may be added to the chip type. */
        !           359:        HAS_VLAN=0x100,
1.1.1.2   root      360: };
1.1.1.3 ! root      361: 
        !           362: static struct pci_id_info pci_id_tbl[] = {
        !           363:        { "Digital DC21040 Tulip", { 0x00021011, 0xffffffff },
        !           364:          TULIP_IOTYPE, 0x80, DC21040 },
        !           365:        { "Digital DC21041 Tulip", { 0x00141011, 0xffffffff },
        !           366:          TULIP_IOTYPE, 0x80, DC21041 },
        !           367:        { "Digital DS21140A Tulip", { 0x00091011, 0xffffffff, 0,0, 0x20,0xf0 },
        !           368:          TULIP_IOTYPE, 0x80, DC21140 },
        !           369:        { "Digital DS21140 Tulip", { 0x00091011, 0xffffffff },
        !           370:          TULIP_IOTYPE, 0x80, DC21140 },
        !           371:        { "Digital DS21143-xD Tulip", { 0x00191011, 0xffffffff, 0,0, 0x40,0xf0 },
        !           372:          TULIP_IOTYPE, TULIP_SIZE, DC21142 | HAS_VLAN },
        !           373:        { "Digital DS21143-xC Tulip", { 0x00191011, 0xffffffff, 0,0, 0x30,0xf0 },
        !           374:          TULIP_IOTYPE, TULIP_SIZE, DC21142 },
        !           375:        { "Digital DS21142 Tulip", { 0x00191011, 0xffffffff },
        !           376:          TULIP_IOTYPE, TULIP_SIZE, DC21142 },
        !           377:        { "Kingston KNE110tx (PNIC)",
        !           378:          { 0x000211AD, 0xffffffff, 0xf0022646, 0xffffffff },
        !           379:          TULIP_IOTYPE, 256, LC82C168 },
        !           380:        { "Linksys LNE100TX (82c168 PNIC)",                             /*  w/SYM */
        !           381:          { 0x000211AD, 0xffffffff, 0xffff11ad, 0xffffffff, 17,0xff },
        !           382:          TULIP_IOTYPE, 256, LC82C168 },
        !           383:        { "Linksys LNE100TX (82c169 PNIC)",                             /* w/ MII */
        !           384:          { 0x000211AD, 0xffffffff, 0xf00311ad, 0xffffffff, 32,0xff },
        !           385:          TULIP_IOTYPE, 256, LC82C168 },
        !           386:        { "Lite-On 82c168 PNIC", { 0x000211AD, 0xffffffff },
        !           387:          TULIP_IOTYPE, 256, LC82C168 },
        !           388:        { "Macronix 98713 PMAC", { 0x051210d9, 0xffffffff },
        !           389:          TULIP_IOTYPE, 256, MX98713 },
        !           390:        { "Macronix 98715 PMAC", { 0x053110d9, 0xffffffff },
        !           391:          TULIP_IOTYPE, 256, MX98715 },
        !           392:        { "Macronix 98725 PMAC", { 0x053110d9, 0xffffffff },
        !           393:          TULIP_IOTYPE, 256, MX98725 },
        !           394:        { "ASIX AX88141", { 0x1400125B, 0xffffffff, 0,0, 0x10, 0xf0 },
        !           395:          TULIP_IOTYPE, 128, AX88141 },
        !           396:        { "ASIX AX88140", { 0x1400125B, 0xffffffff },
        !           397:          TULIP_IOTYPE, 128, AX88140 },
        !           398:        { "Lite-On LC82C115 PNIC-II", { 0xc11511AD, 0xffffffff },
        !           399:          TULIP_IOTYPE, 256, PNIC2 },
        !           400:        { "ADMtek AN981 Comet", { 0x09811317, 0xffffffff },
        !           401:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           402:        { "ADMtek Centaur-P", { 0x09851317, 0xffffffff },
        !           403:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           404:        { "ADMtek Centaur-C", { 0x19851317, 0xffffffff },
        !           405:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           406:        { "D-Link DFE-680TXD v1.0 (ADMtek Centaur-C)", { 0x15411186, 0xffffffff },
        !           407:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           408:        { "ADMtek Centaur-C (Linksys v2)", { 0xab0213d1, 0xffffffff },
        !           409:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           410:        { "ADMtek Centaur-C (Linksys)", { 0xab0313d1, 0xffffffff },
        !           411:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           412:        { "ADMtek Centaur-C (Linksys)", { 0xab0813d1, 0xffffffff },
        !           413:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           414:        { "ADMtek Centaur-C (Linksys PCM200 v3)", { 0xab081737, 0xffffffff },
        !           415:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           416:        { "ADMtek Centaur-C (Linksys PCM200 v3)", { 0xab091737, 0xffffffff },
        !           417:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           418:        { "STMicro STE10/100 Comet", { 0x0981104a, 0xffffffff },
        !           419:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           420:        { "STMicro STE10/100A Comet", { 0x2774104a, 0xffffffff },
        !           421:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           422:        { "ADMtek Comet-II", { 0x95111317, 0xffffffff },
        !           423:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           424:        { "ADMtek Comet-II (9513)", { 0x95131317, 0xffffffff },
        !           425:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           426:        { "SMC1255TX (ADMtek Comet)",
        !           427:          { 0x12161113, 0xffffffff, 0x125510b8, 0xffffffff },
        !           428:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           429:        { "Accton EN1217/EN2242 (ADMtek Comet)", { 0x12161113, 0xffffffff },
        !           430:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           431:        { "SMC1255TX (ADMtek Comet-II)", { 0x125510b8, 0xffffffff },
        !           432:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           433:        { "ADMtek Comet-II (model 1020)", { 0x1020111a, 0xffffffff },
        !           434:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           435:        { "Allied Telesyn A120 (ADMtek Comet)", { 0xa1201259, 0xffffffff },
        !           436:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           437:        { "Compex RL100-TX", { 0x988111F6, 0xffffffff },
        !           438:          TULIP_IOTYPE, 128, COMPEX9881 },
        !           439:        { "Intel 21145 Tulip", { 0x00398086, 0xffffffff },
        !           440:          TULIP_IOTYPE, 128, I21145 },
        !           441:        { "Xircom Tulip clone", { 0x0003115d, 0xffffffff },
        !           442:          TULIP_IOTYPE, 128, XIRCOM },
        !           443:        { "Davicom DM9102", { 0x91021282, 0xffffffff },
        !           444:          TULIP_IOTYPE, 0x80, DC21140 },
        !           445:        { "Davicom DM9100", { 0x91001282, 0xffffffff },
        !           446:          TULIP_IOTYPE, 0x80, DC21140 },
        !           447:        { "Macronix mxic-98715 (EN1217)", { 0x12171113, 0xffffffff },
        !           448:          TULIP_IOTYPE, 256, MX98715 },
        !           449:        { "Conexant LANfinity", { 0x180314f1, 0xffffffff },
        !           450:          TULIP_IOTYPE, TULIP_SIZE1, CONEXANT },
        !           451:        { "3Com 3cSOHO100B-TX (ADMtek Centaur)", { 0x930010b7, 0xffffffff },
        !           452:          TULIP_IOTYPE, TULIP_SIZE1, COMET },
        !           453:        { 0},
1.1.1.2   root      454: };
1.1       root      455: 
1.1.1.3 ! root      456: struct drv_id_info tulip_drv_id = {
        !           457:        "tulip", PCI_HOTSWAP, PCI_CLASS_NETWORK_ETHERNET<<8, pci_id_tbl,
        !           458:        tulip_probe1, tulip_pwr_event };
        !           459: 
        !           460: /* This table is used during operation for capabilities and media timer. */
1.1       root      461: 
                    462: static void tulip_timer(unsigned long data);
1.1.1.3 ! root      463: static void nway_timer(unsigned long data);
1.1       root      464: static void mxic_timer(unsigned long data);
                    465: static void pnic_timer(unsigned long data);
1.1.1.2   root      466: static void comet_timer(unsigned long data);
1.1       root      467: 
1.1.1.2   root      468: enum tbl_flag {
                    469:        HAS_MII=1, HAS_MEDIA_TABLE=2, CSR12_IN_SROM=4, ALWAYS_CHECK_MII=8,
                    470:        HAS_PWRDWN=0x10, MC_HASH_ONLY=0x20, /* Hash-only multicast filter. */
1.1.1.3 ! root      471:        HAS_PNICNWAY=0x80, HAS_NWAY=0x40,       /* Uses internal NWay xcvr. */
        !           472:        HAS_INTR_MITIGATION=0x100, IS_ASIX=0x200, HAS_8023X=0x400,
        !           473:        COMET_MAC_ADDR=0x0800,
1.1.1.2   root      474: };
1.1.1.3 ! root      475: 
        !           476: /* Note: this table must match  enum tulip_chips  above. */
1.1       root      477: static struct tulip_chip_table {
                    478:        char *chip_name;
1.1.1.3 ! root      479:        int io_size;                            /* Unused */
1.1       root      480:        int valid_intrs;                        /* CSR7 interrupt enable settings */
                    481:        int flags;
                    482:        void (*media_timer)(unsigned long data);
                    483: } tulip_tbl[] = {
1.1.1.2   root      484:   { "Digital DC21040 Tulip", 128, 0x0001ebef, 0, tulip_timer },
1.1.1.3 ! root      485:   { "Digital DC21041 Tulip", 128, 0x0001ebff,
        !           486:        HAS_MEDIA_TABLE | HAS_NWAY, tulip_timer },
1.1.1.2   root      487:   { "Digital DS21140 Tulip", 128, 0x0001ebef,
1.1       root      488:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, tulip_timer },
1.1.1.2   root      489:   { "Digital DS21143 Tulip", 128, 0x0801fbff,
1.1.1.3 ! root      490:        HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY
        !           491:        | HAS_INTR_MITIGATION, nway_timer },
1.1.1.2   root      492:   { "Lite-On 82c168 PNIC", 256, 0x0001ebef,
                    493:        HAS_MII | HAS_PNICNWAY, pnic_timer },
                    494:   { "Macronix 98713 PMAC", 128, 0x0001ebef,
                    495:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer },
                    496:   { "Macronix 98715 PMAC", 256, 0x0001ebef,
                    497:        HAS_MEDIA_TABLE, mxic_timer },
                    498:   { "Macronix 98725 PMAC", 256, 0x0001ebef,
                    499:        HAS_MEDIA_TABLE, mxic_timer },
                    500:   { "ASIX AX88140", 128, 0x0001fbff,
1.1.1.3 ! root      501:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY | IS_ASIX, tulip_timer },
        !           502:   { "ASIX AX88141", 128, 0x0001fbff,
        !           503:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY | IS_ASIX, tulip_timer },
1.1.1.2   root      504:   { "Lite-On PNIC-II", 256, 0x0801fbff,
1.1.1.3 ! root      505:        HAS_MII | HAS_NWAY | HAS_8023X, nway_timer },
1.1.1.2   root      506:   { "ADMtek Comet", 256, 0x0001abef,
1.1.1.3 ! root      507:        HAS_MII | MC_HASH_ONLY | COMET_MAC_ADDR, comet_timer },
1.1.1.2   root      508:   { "Compex 9881 PMAC", 128, 0x0001ebef,
                    509:        HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer },
                    510:   { "Intel DS21145 Tulip", 128, 0x0801fbff,
1.1.1.3 ! root      511:        HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY,
        !           512:        nway_timer },
1.1.1.2   root      513:   { "Xircom tulip work-alike", 128, 0x0801fbff,
1.1.1.3 ! root      514:        HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY,
        !           515:        nway_timer },
        !           516:   { "Conexant LANfinity", 256, 0x0001ebef,
        !           517:        HAS_MII | HAS_PWRDWN, tulip_timer },
1.1.1.2   root      518:   {0},
                    519: };
1.1       root      520: 
                    521: /* A full-duplex map for media types. */
1.1.1.2   root      522: enum MediaIs {
                    523:        MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8,
                    524:        MediaIs100=16};
1.1.1.3 ! root      525: static const char media_cap[32] =
        !           526: {0,0,0,16,  3,19,16,24,  27,4,7,5, 0,20,23,20,  28,31,0,0, };
1.1.1.2   root      527: static u8 t21040_csr13[] = {2,0x0C,8,4,  4,0,0,0, 0,0,0,0, 4,0,0,0};
1.1.1.3 ! root      528: 
1.1       root      529: /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD*/
1.1.1.3 ! root      530: static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
        !           531: static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x6F3F, 0x6F3D, };
1.1       root      532: static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
                    533: 
                    534: static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
                    535: static u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
                    536: static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
                    537: 
                    538: /* Offsets to the Command and Status Registers, "CSRs".  All accesses
                    539:    must be longword instructions and quadword aligned. */
                    540: enum tulip_offsets {
                    541:        CSR0=0,    CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
                    542:        CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
                    543:        CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78 };
                    544: 
                    545: /* The bits in the CSR5 status registers, mostly interrupt sources. */
                    546: enum status_bits {
1.1.1.3 ! root      547:        TimerInt=0x800, TPLnkFail=0x1000, TPLnkPass=0x10,
        !           548:        NormalIntr=0x10000, AbnormalIntr=0x8000, PCIBusError=0x2000,
        !           549:        RxJabber=0x200, RxStopped=0x100, RxNoBuf=0x80, RxIntr=0x40,
1.1       root      550:        TxFIFOUnderflow=0x20, TxJabber=0x08, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01,
                    551: };
                    552: 
1.1.1.3 ! root      553: /* The configuration bits in CSR6. */
        !           554: enum csr6_mode_bits {
        !           555:        TxOn=0x2000, RxOn=0x0002, FullDuplex=0x0200,
        !           556:        AcceptBroadcast=0x0100, AcceptAllMulticast=0x0080,
        !           557:        AcceptAllPhys=0x0040, AcceptRunt=0x0008,
        !           558: };
        !           559: 
        !           560: 
1.1       root      561: /* The Tulip Rx and Tx buffer descriptors. */
                    562: struct tulip_rx_desc {
                    563:        s32 status;
                    564:        s32 length;
                    565:        u32 buffer1, buffer2;
                    566: };
                    567: 
                    568: struct tulip_tx_desc {
                    569:        s32 status;
                    570:        s32 length;
                    571:        u32 buffer1, buffer2;                           /* We use only buffer 1.  */
                    572: };
                    573: 
1.1.1.2   root      574: enum desc_status_bits {
                    575:        DescOwned=0x80000000, RxDescFatalErr=0x8000, RxWholePkt=0x0300,
                    576: };
                    577: 
                    578: /* Ring-wrap flag in length field, use for last ring entry.
                    579:        0x01000000 means chain on buffer2 address,
                    580:        0x02000000 means use the ring start address in CSR2/3.
                    581:    Note: Some work-alike chips do not function correctly in chained mode.
                    582:    The ASIX chip works only in chained mode.
                    583:    Thus we indicates ring mode, but always write the 'next' field for
                    584:    chained mode as well.
                    585: */
                    586: #define DESC_RING_WRAP 0x02000000
                    587: 
1.1.1.3 ! root      588: #define EEPROM_SIZE 512                /* support 256*16 EEPROMs */
1.1.1.2   root      589: 
1.1       root      590: struct medialeaf {
                    591:        u8 type;
                    592:        u8 media;
                    593:        unsigned char *leafdata;
                    594: };
                    595: 
                    596: struct mediatable {
                    597:        u16 defaultmedia;
                    598:        u8 leafcount, csr12dir;                         /* General purpose pin directions. */
1.1.1.2   root      599:        unsigned has_mii:1, has_nonmii:1, has_reset:6;
                    600:        u32 csr15dir, csr15val;                         /* 21143 NWay setting. */
1.1       root      601:        struct medialeaf mleaf[0];
                    602: };
                    603: 
                    604: struct mediainfo {
                    605:        struct mediainfo *next;
                    606:        int info_type;
                    607:        int index;
                    608:        unsigned char *info;
                    609: };
                    610: 
1.1.1.3 ! root      611: #define PRIV_ALIGN     15      /* Required alignment mask */
1.1       root      612: struct tulip_private {
                    613:        struct tulip_rx_desc rx_ring[RX_RING_SIZE];
                    614:        struct tulip_tx_desc tx_ring[TX_RING_SIZE];
1.1.1.3 ! root      615:        /* The saved addresses of Rx/Tx-in-place packet buffers. */
1.1       root      616:        struct sk_buff* tx_skbuff[TX_RING_SIZE];
                    617:        struct sk_buff* rx_skbuff[RX_RING_SIZE];
1.1.1.3 ! root      618:        struct net_device *next_module;
        !           619:        void *priv_addr;                        /* Unaligned address of dev->priv for kfree */
        !           620:        /* Multicast filter control. */
1.1.1.2   root      621:        u16 setup_frame[96];            /* Pseudo-Tx frame to init address table. */
1.1.1.3 ! root      622:        u32 mc_filter[2];                       /* Multicast hash filter */
        !           623:        int multicast_filter_limit;
        !           624:        struct pci_dev *pci_dev;
        !           625:        int chip_id, revision;
1.1.1.2   root      626:        int flags;
1.1.1.3 ! root      627:        int max_interrupt_work;
        !           628:        int msg_level;
        !           629:        unsigned int csr0, csr6;                        /* Current CSR0, CSR6 settings. */
        !           630:        /* Note: cache line pairing and isolation of Rx vs. Tx indicies. */
        !           631:        unsigned int cur_rx, dirty_rx;          /* Producer/consumer ring indices */
        !           632:        unsigned int rx_buf_sz;                         /* Based on MTU+slack. */
        !           633:        int rx_copybreak;
        !           634:        unsigned int rx_dead:1;                         /* We have no Rx buffers. */
        !           635: 
1.1       root      636:        struct net_device_stats stats;
1.1.1.3 ! root      637:        unsigned int cur_tx, dirty_tx;
1.1       root      638:        unsigned int tx_full:1;                         /* The Tx queue is full. */
1.1.1.3 ! root      639: 
        !           640:        /* Media selection state. */
1.1       root      641:        unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
                    642:        unsigned int full_duplex_lock:1;
                    643:        unsigned int fake_addr:1;                       /* Multiport board faked address. */
                    644:        unsigned int media2:4;                          /* Secondary monitored media port. */
1.1.1.3 ! root      645:        unsigned int medialock:1;                       /* Do not sense media type. */
1.1       root      646:        unsigned int mediasense:1;                      /* Media sensing in progress. */
1.1.1.2   root      647:        unsigned int nway:1, nwayset:1;         /* 21143 internal NWay. */
1.1.1.3 ! root      648:        unsigned int default_port;                      /* Last dev->if_port value. */
1.1.1.2   root      649:        unsigned char eeprom[EEPROM_SIZE];      /* Serial EEPROM contents. */
1.1.1.3 ! root      650:        struct timer_list timer;                        /* Media selection timer. */
        !           651:        void (*link_change)(struct net_device *dev, int csr5);
1.1.1.2   root      652:        u16 lpar;                                                       /* 21143 Link partner ability. */
1.1.1.3 ! root      653:        u16 sym_advertise, mii_advertise;       /* NWay to-advertise. */
        !           654:        u16 advertising[4];                                     /* MII advertise, from SROM table. */
1.1       root      655:        signed char phys[4], mii_cnt;           /* MII device addresses. */
1.1.1.3 ! root      656:        spinlock_t mii_lock;
1.1       root      657:        struct mediatable *mtable;
                    658:        int cur_index;                                          /* Current media index. */
1.1.1.2   root      659:        int saved_if_port;
1.1       root      660: };
                    661: 
1.1.1.3 ! root      662: static void start_link(struct net_device *dev);
        !           663: static void parse_eeprom(struct net_device *dev);
1.1.1.2   root      664: static int read_eeprom(long ioaddr, int location, int addr_len);
1.1.1.3 ! root      665: static int mdio_read(struct net_device *dev, int phy_id, int location);
        !           666: static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
        !           667: static int tulip_open(struct net_device *dev);
1.1.1.2   root      668: /* Chip-specific media selection (timer functions prototyped above). */
1.1.1.3 ! root      669: static int  check_duplex(struct net_device *dev);
        !           670: static void select_media(struct net_device *dev, int startup);
        !           671: static void init_media(struct net_device *dev);
        !           672: static void nway_lnk_change(struct net_device *dev, int csr5);
        !           673: static void nway_start(struct net_device *dev);
        !           674: static void pnic_lnk_change(struct net_device *dev, int csr5);
        !           675: static void pnic_do_nway(struct net_device *dev);
        !           676: 
        !           677: static void tulip_tx_timeout(struct net_device *dev);
        !           678: static void tulip_init_ring(struct net_device *dev);
        !           679: static int tulip_start_xmit(struct sk_buff *skb, struct net_device *dev);
        !           680: static int tulip_rx(struct net_device *dev);
1.1.1.2   root      681: static void tulip_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
1.1.1.3 ! root      682: static int tulip_close(struct net_device *dev);
        !           683: static struct net_device_stats *tulip_get_stats(struct net_device *dev);
1.1       root      684: #ifdef HAVE_PRIVATE_IOCTL
1.1.1.3 ! root      685: static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1.1       root      686: #endif
1.1.1.3 ! root      687: static void set_rx_mode(struct net_device *dev);
1.1       root      688: 
                    689: 
                    690: 
1.1.1.2   root      691: /* A list of all installed Tulip devices. */
1.1.1.3 ! root      692: static struct net_device *root_tulip_dev = NULL;
1.1       root      693: 
1.1.1.3 ! root      694: static void *tulip_probe1(struct pci_dev *pdev, void *init_dev,
        !           695:                                                  long ioaddr, int irq, int pci_tbl_idx, int find_cnt)
1.1       root      696: {
1.1.1.3 ! root      697:        struct net_device *dev;
1.1       root      698:        struct tulip_private *tp;
1.1.1.3 ! root      699:        void *priv_mem;
1.1       root      700:        /* See note below on the multiport cards. */
1.1.1.3 ! root      701:        static unsigned char last_phys_addr[6] = {0x02, 'L', 'i', 'n', 'u', 'x'};
1.1       root      702:        static int last_irq = 0;
                    703:        static int multiport_cnt = 0;           /* For four-port boards w/one EEPROM */
1.1.1.2   root      704:        u8 chip_rev;
1.1.1.3 ! root      705:        int i, chip_idx = pci_id_tbl[pci_tbl_idx].drv_flags & 0xff;
1.1       root      706:        unsigned short sum;
1.1.1.2   root      707:        u8 ee_data[EEPROM_SIZE];
1.1       root      708: 
1.1.1.3 ! root      709:        /* Bring the 21041/21143 out of sleep mode.
        !           710:           Caution: Snooze mode does not work with some boards! */
        !           711:        if (tulip_tbl[chip_idx].flags & HAS_PWRDWN)
        !           712:                pci_write_config_dword(pdev, 0x40, 0x00000000);
        !           713: 
        !           714:        if (inl(ioaddr + CSR5) == 0xffffffff) {
        !           715:                printk(KERN_ERR "The Tulip chip at %#lx is not functioning.\n", ioaddr);
        !           716:                return 0;
        !           717:        }
1.1       root      718: 
1.1.1.3 ! root      719:        dev = init_etherdev(init_dev, 0);
        !           720:        if (!dev)
        !           721:                return NULL;
1.1       root      722: 
1.1.1.2   root      723:        /* Make certain the data structures are quadword aligned. */
1.1.1.3 ! root      724:        priv_mem = kmalloc(sizeof(*tp) + PRIV_ALIGN, GFP_KERNEL);
        !           725:        /* Check for the very unlikely case of no memory. */
        !           726:        if (priv_mem == NULL)
        !           727:                return NULL;
        !           728:        dev->priv = tp = (void *)(((long)priv_mem + PRIV_ALIGN) & ~PRIV_ALIGN);
1.1.1.2   root      729:        memset(tp, 0, sizeof(*tp));
1.1.1.3 ! root      730:        tp->mii_lock = (spinlock_t) SPIN_LOCK_UNLOCKED;
        !           731:        tp->priv_addr = priv_mem;
1.1.1.2   root      732: 
                    733:        tp->next_module = root_tulip_dev;
                    734:        root_tulip_dev = dev;
                    735: 
1.1.1.3 ! root      736:        pci_read_config_byte(pdev, PCI_REVISION_ID, &chip_rev);
1.1       root      737: 
1.1.1.2   root      738:        printk(KERN_INFO "%s: %s rev %d at %#3lx,",
1.1.1.3 ! root      739:                   dev->name, pci_id_tbl[pci_tbl_idx].name, chip_rev, ioaddr);
1.1       root      740: 
1.1.1.3 ! root      741:        /* Stop the Tx and Rx processes. */
        !           742:        outl(inl(ioaddr + CSR6) & ~TxOn & ~RxOn, ioaddr + CSR6);
1.1       root      743:        /* Clear the missed-packet counter. */
1.1.1.3 ! root      744:        inl(ioaddr + CSR8);
1.1       root      745: 
1.1.1.2   root      746:        if (chip_idx == DC21041  &&  inl(ioaddr + CSR9) & 0x8000) {
                    747:                printk(" 21040 compatible mode,");
                    748:                chip_idx = DC21040;
1.1       root      749:        }
                    750: 
1.1.1.3 ! root      751:        /* The SROM/EEPROM interface varies dramatically. */
1.1       root      752:        sum = 0;
1.1.1.2   root      753:        if (chip_idx == DC21040) {
1.1       root      754:                outl(0, ioaddr + CSR9);         /* Reset the pointer with a dummy write. */
                    755:                for (i = 0; i < 6; i++) {
                    756:                        int value, boguscnt = 100000;
                    757:                        do
                    758:                                value = inl(ioaddr + CSR9);
                    759:                        while (value < 0  && --boguscnt > 0);
                    760:                        dev->dev_addr[i] = value;
                    761:                        sum += value & 0xff;
                    762:                }
1.1.1.2   root      763:        } else if (chip_idx == LC82C168) {
1.1       root      764:                for (i = 0; i < 3; i++) {
                    765:                        int value, boguscnt = 100000;
                    766:                        outl(0x600 | i, ioaddr + 0x98);
                    767:                        do
                    768:                                value = inl(ioaddr + CSR9);
                    769:                        while (value < 0  && --boguscnt > 0);
1.1.1.2   root      770:                        put_unaligned(le16_to_cpu(value), ((u16*)dev->dev_addr) + i);
1.1       root      771:                        sum += value & 0xffff;
                    772:                }
1.1.1.2   root      773:        } else if (chip_idx == COMET) {
                    774:                /* No need to read the EEPROM. */
1.1.1.3 ! root      775:                put_unaligned(le32_to_cpu(inl(ioaddr + 0xA4)), (u32 *)dev->dev_addr);
        !           776:                put_unaligned(le16_to_cpu(inl(ioaddr + 0xA8)),
        !           777:                                          (u16 *)(dev->dev_addr + 4));
1.1.1.2   root      778:                for (i = 0; i < 6; i ++)
                    779:                        sum += dev->dev_addr[i];
                    780:        } else {
                    781:                /* A serial EEPROM interface, we read now and sort it out later. */
1.1       root      782:                int sa_offset = 0;
1.1.1.2   root      783:                int ee_addr_size = read_eeprom(ioaddr, 0xff, 8) & 0x40000 ? 8 : 6;
1.1.1.3 ! root      784:                int eeprom_word_cnt = 1 << ee_addr_size;
1.1       root      785: 
1.1.1.3 ! root      786:                for (i = 0; i < eeprom_word_cnt; i++)
1.1.1.2   root      787:                        ((u16 *)ee_data)[i] =
                    788:                                le16_to_cpu(read_eeprom(ioaddr, i, ee_addr_size));
1.1       root      789: 
1.1.1.2   root      790:                /* DEC now has a specification (see Notes) but early board makers
                    791:                   just put the address in the first EEPROM locations. */
                    792:                /* This does  memcmp(eedata, eedata+16, 8) */
1.1       root      793:                for (i = 0; i < 8; i ++)
                    794:                        if (ee_data[i] != ee_data[16+i])
                    795:                                sa_offset = 20;
1.1.1.3 ! root      796:                if (chip_idx == CONEXANT) {
        !           797:                        /* Check that the tuple type and length is correct. */
        !           798:                        if (ee_data[0x198] == 0x04  &&  ee_data[0x199] == 6)
        !           799:                                sa_offset = 0x19A;
        !           800:                } else if (ee_data[0] == 0xff  &&  ee_data[1] == 0xff &&
        !           801:                                   ee_data[2] == 0) {
1.1       root      802:                        sa_offset = 2;          /* Grrr, damn Matrox boards. */
                    803:                        multiport_cnt = 4;
                    804:                }
                    805:                for (i = 0; i < 6; i ++) {
                    806:                        dev->dev_addr[i] = ee_data[i + sa_offset];
                    807:                        sum += ee_data[i + sa_offset];
                    808:                }
                    809:        }
                    810:        /* Lite-On boards have the address byte-swapped. */
1.1.1.2   root      811:        if ((dev->dev_addr[0] == 0xA0  ||  dev->dev_addr[0] == 0xC0)
                    812:                &&  dev->dev_addr[1] == 0x00)
1.1       root      813:                for (i = 0; i < 6; i+=2) {
                    814:                        char tmp = dev->dev_addr[i];
                    815:                        dev->dev_addr[i] = dev->dev_addr[i+1];
                    816:                        dev->dev_addr[i+1] = tmp;
                    817:                }
                    818:        /* On the Zynx 315 Etherarray and other multiport boards only the
                    819:           first Tulip has an EEPROM.
                    820:           The addresses of the subsequent ports are derived from the first.
                    821:           Many PCI BIOSes also incorrectly report the IRQ line, so we correct
                    822:           that here as well. */
                    823:        if (sum == 0  || sum == 6*0xff) {
                    824:                printk(" EEPROM not present,");
                    825:                for (i = 0; i < 5; i++)
                    826:                        dev->dev_addr[i] = last_phys_addr[i];
                    827:                dev->dev_addr[i] = last_phys_addr[i] + 1;
1.1.1.2   root      828: #if defined(__i386__)          /* Patch up x86 BIOS bug. */
                    829:                if (last_irq)
                    830:                        irq = last_irq;
1.1       root      831: #endif
                    832:        }
                    833: 
                    834:        for (i = 0; i < 6; i++)
1.1.1.2   root      835:                printk("%c%2.2X", i ? ':' : ' ', last_phys_addr[i] = dev->dev_addr[i]);
1.1       root      836:        printk(", IRQ %d.\n", irq);
                    837:        last_irq = irq;
                    838: 
1.1.1.3 ! root      839: #ifdef USE_IO_OPS
        !           840:        /* We do a request_region() to register /proc/ioports info. */
        !           841:        request_region(ioaddr, pci_id_tbl[chip_idx].io_size, dev->name);
        !           842: #endif
1.1       root      843: 
                    844:        dev->base_addr = ioaddr;
                    845:        dev->irq = irq;
                    846: 
1.1.1.3 ! root      847:        tp->pci_dev = pdev;
        !           848:        tp->msg_level = (1 << debug) - 1;
1.1.1.2   root      849:        tp->chip_id = chip_idx;
                    850:        tp->revision = chip_rev;
1.1.1.3 ! root      851:        tp->flags = tulip_tbl[chip_idx].flags
        !           852:                | (pci_id_tbl[pci_tbl_idx].drv_flags & 0xffffff00);
        !           853:        tp->rx_copybreak = rx_copybreak;
        !           854:        tp->max_interrupt_work = max_interrupt_work;
        !           855:        tp->multicast_filter_limit = multicast_filter_limit;
1.1.1.2   root      856:        tp->csr0 = csr0;
                    857: 
                    858:        /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles.
                    859:           And the ASIX must have a burst limit or horrible things happen. */
                    860:        if (chip_idx == DC21143  &&  chip_rev == 65)
                    861:                tp->csr0 &= ~0x01000000;
1.1.1.3 ! root      862:        else if (tp->flags & IS_ASIX)
1.1.1.2   root      863:                tp->csr0 |= 0x2000;
1.1       root      864: 
1.1.1.3 ! root      865:        /* We support a zillion ways to set the media type. */
1.1       root      866: #ifdef TULIP_FULL_DUPLEX
                    867:        tp->full_duplex = 1;
                    868:        tp->full_duplex_lock = 1;
                    869: #endif
                    870: #ifdef TULIP_DEFAULT_MEDIA
                    871:        tp->default_port = TULIP_DEFAULT_MEDIA;
                    872: #endif
                    873: #ifdef TULIP_NO_MEDIA_SWITCH
                    874:        tp->medialock = 1;
                    875: #endif
                    876: 
                    877:        /* The lower four bits are the media type. */
1.1.1.3 ! root      878:        if (find_cnt >= 0  &&  find_cnt < MAX_UNITS) {
        !           879:                if (options[find_cnt] & 0x1f)
        !           880:                        tp->default_port = options[find_cnt] & 0x1f;
        !           881:                if ((options[find_cnt] & 0x200) || full_duplex[find_cnt] > 0)
1.1       root      882:                        tp->full_duplex = 1;
1.1.1.3 ! root      883:                if (mtu[find_cnt] > 0)
        !           884:                        dev->mtu = mtu[find_cnt];
1.1       root      885:        }
                    886:        if (dev->mem_start)
1.1.1.3 ! root      887:                tp->default_port = dev->mem_start & 0x1f;
1.1       root      888:        if (tp->default_port) {
1.1.1.3 ! root      889:                printk(KERN_INFO "%s: Transceiver selection forced to %s.\n",
        !           890:                           dev->name, medianame[tp->default_port & MEDIA_MASK]);
1.1       root      891:                tp->medialock = 1;
                    892:                if (media_cap[tp->default_port] & MediaAlwaysFD)
                    893:                        tp->full_duplex = 1;
                    894:        }
                    895:        if (tp->full_duplex)
                    896:                tp->full_duplex_lock = 1;
                    897: 
                    898:        if (media_cap[tp->default_port] & MediaIsMII) {
                    899:                u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
1.1.1.3 ! root      900:                tp->mii_advertise = media2advert[tp->default_port - 9];
        !           901:                tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */
        !           902:        }
1.1.1.2   root      903: 
                    904:        /* This is logically part of probe1(), but too complex to write inline. */
                    905:        if (tp->flags & HAS_MEDIA_TABLE) {
                    906:                memcpy(tp->eeprom, ee_data, sizeof(tp->eeprom));
                    907:                parse_eeprom(dev);
                    908:        }
1.1       root      909: 
1.1.1.3 ! root      910:        /* The Tulip-specific entries in the device structure. */
        !           911:        dev->open = &tulip_open;
        !           912:        dev->hard_start_xmit = &tulip_start_xmit;
        !           913:        dev->stop = &tulip_close;
        !           914:        dev->get_stats = &tulip_get_stats;
        !           915: #ifdef HAVE_PRIVATE_IOCTL
        !           916:        dev->do_ioctl = &private_ioctl;
        !           917: #endif
        !           918: #ifdef HAVE_MULTICAST
        !           919:        dev->set_multicast_list = &set_rx_mode;
        !           920: #endif
        !           921: 
        !           922:        if (tp->flags & HAS_NWAY)
        !           923:                tp->link_change = nway_lnk_change;
        !           924:        else if (tp->flags & HAS_PNICNWAY)
        !           925:                tp->link_change = pnic_lnk_change;
        !           926:        start_link(dev);
        !           927:        if (chip_idx == COMET) {
        !           928:                /* Set the Comet LED configuration. */
        !           929:                outl(0xf0000000, ioaddr + CSR9);
        !           930:        }
        !           931: 
        !           932:        return dev;
        !           933: }
        !           934: 
        !           935: /* Start the link, typically called at probe1() time but sometimes later with
        !           936:    multiport cards. */
        !           937: static void start_link(struct net_device *dev)
        !           938: {
        !           939:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !           940:        long ioaddr = dev->base_addr;
        !           941:        int i;
        !           942: 
1.1.1.2   root      943:        if ((tp->flags & ALWAYS_CHECK_MII) ||
                    944:                (tp->mtable  &&  tp->mtable->has_mii) ||
                    945:                ( ! tp->mtable  &&  (tp->flags & HAS_MII))) {
1.1.1.3 ! root      946:                int phyn, phy_idx = 0;
1.1.1.2   root      947:                if (tp->mtable  &&  tp->mtable->has_mii) {
                    948:                        for (i = 0; i < tp->mtable->leafcount; i++)
                    949:                                if (tp->mtable->mleaf[i].media == 11) {
                    950:                                        tp->cur_index = i;
                    951:                                        tp->saved_if_port = dev->if_port;
1.1.1.3 ! root      952:                                        select_media(dev, 2);
1.1.1.2   root      953:                                        dev->if_port = tp->saved_if_port;
                    954:                                        break;
                    955:                                }
                    956:                }
1.1       root      957:                /* Find the connected MII xcvrs.
                    958:                   Doing this in open() would allow detecting external xcvrs later,
                    959:                   but takes much time. */
1.1.1.3 ! root      960:                for (phyn = 1; phyn <= 32 && phy_idx < sizeof(tp->phys); phyn++) {
        !           961:                        int phy = phyn & 0x1f;
1.1       root      962:                        int mii_status = mdio_read(dev, phy, 1);
1.1.1.2   root      963:                        if ((mii_status & 0x8301) == 0x8001 ||
                    964:                                ((mii_status & 0x8000) == 0  && (mii_status & 0x7800) != 0)) {
1.1       root      965:                                int mii_reg0 = mdio_read(dev, phy, 0);
1.1.1.2   root      966:                                int mii_advert = mdio_read(dev, phy, 4);
1.1.1.3 ! root      967:                                int to_advert;
        !           968: 
        !           969:                                if (tp->mii_advertise)
        !           970:                                        to_advert = tp->mii_advertise;
        !           971:                                else if (tp->advertising[phy_idx])
        !           972:                                        to_advert = tp->advertising[phy_idx];
        !           973:                                else                    /* Leave unchanged. */
        !           974:                                        tp->mii_advertise = to_advert = mii_advert;
        !           975: 
        !           976:                                tp->phys[phy_idx++] = phy;
1.1.1.2   root      977:                                printk(KERN_INFO "%s:  MII transceiver #%d "
                    978:                                           "config %4.4x status %4.4x advertising %4.4x.\n",
                    979:                                           dev->name, phy, mii_reg0, mii_status, mii_advert);
                    980:                                /* Fixup for DLink with miswired PHY. */
1.1.1.3 ! root      981:                                if (mii_advert != to_advert) {
1.1       root      982:                                        printk(KERN_DEBUG "%s:  Advertising %4.4x on PHY %d,"
                    983:                                                   " previously advertising %4.4x.\n",
1.1.1.3 ! root      984:                                                   dev->name, to_advert, phy, mii_advert);
        !           985:                                        mdio_write(dev, phy, 4, to_advert);
1.1       root      986:                                }
                    987:                                /* Enable autonegotiation: some boards default to off. */
1.1.1.3 ! root      988:                                mdio_write(dev, phy, 0, (mii_reg0 & ~0x3000) |
        !           989:                                                   (tp->full_duplex ? 0x0100 : 0x0000) |
        !           990:                                                   ((media_cap[tp->default_port] & MediaIs100) ?
        !           991:                                                        0x2000 : 0x1000));
1.1       root      992:                        }
                    993:                }
                    994:                tp->mii_cnt = phy_idx;
                    995:                if (tp->mtable  &&  tp->mtable->has_mii  &&  phy_idx == 0) {
                    996:                        printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n",
                    997:                                   dev->name);
                    998:                        tp->phys[0] = 1;
                    999:                }
                   1000:        }
                   1001: 
                   1002:        /* Reset the xcvr interface and turn on heartbeat. */
1.1.1.3 ! root     1003:        switch (tp->chip_id) {
        !          1004:        case DC21040:
        !          1005:                outl(0x00000000, ioaddr + CSR13);
        !          1006:                outl(0x00000004, ioaddr + CSR13);
        !          1007:                break;
1.1       root     1008:        case DC21041:
1.1.1.3 ! root     1009:                /* This is nway_start(). */
        !          1010:                if (tp->sym_advertise == 0)
        !          1011:                        tp->sym_advertise = 0x0061;
1.1       root     1012:                outl(0x00000000, ioaddr + CSR13);
                   1013:                outl(0xFFFFFFFF, ioaddr + CSR14);
                   1014:                outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */
1.1.1.3 ! root     1015:                outl(inl(ioaddr + CSR6) | FullDuplex, ioaddr + CSR6);
        !          1016:                outl(0x0000EF01, ioaddr + CSR13);
1.1       root     1017:                break;
                   1018:        case DC21140: default:
                   1019:                if (tp->mtable)
                   1020:                        outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
                   1021:                break;
                   1022:        case DC21142:
1.1.1.2   root     1023:        case PNIC2:
                   1024:                if (tp->mii_cnt  ||  media_cap[dev->if_port] & MediaIsMII) {
                   1025:                        outl(0x82020000, ioaddr + CSR6);
                   1026:                        outl(0x0000, ioaddr + CSR13);
                   1027:                        outl(0x0000, ioaddr + CSR14);
                   1028:                        outl(0x820E0000, ioaddr + CSR6);
                   1029:                } else
1.1.1.3 ! root     1030:                        nway_start(dev);
1.1       root     1031:                break;
                   1032:        case LC82C168:
                   1033:                if ( ! tp->mii_cnt) {
1.1.1.2   root     1034:                        tp->nway = 1;
                   1035:                        tp->nwayset = 0;
1.1       root     1036:                        outl(0x00420000, ioaddr + CSR6);
                   1037:                        outl(0x30, ioaddr + CSR12);
                   1038:                        outl(0x0001F078, ioaddr + 0xB8);
                   1039:                        outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
                   1040:                }
                   1041:                break;
1.1.1.3 ! root     1042:        case COMPEX9881:
1.1       root     1043:                outl(0x00000000, ioaddr + CSR6);
                   1044:                outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
                   1045:                outl(0x00000001, ioaddr + CSR13);
                   1046:                break;
1.1.1.3 ! root     1047:        case MX98713: case MX98715: case MX98725:
1.1.1.2   root     1048:                outl(0x01a80000, ioaddr + CSR6);
                   1049:                outl(0xFFFFFFFF, ioaddr + CSR14);
                   1050:                outl(0x00001000, ioaddr + CSR12);
                   1051:                break;
                   1052:        case COMET:
                   1053:                break;
1.1       root     1054:        }
                   1055: 
1.1.1.3 ! root     1056:        if (tp->flags & HAS_PWRDWN)
        !          1057:                pci_write_config_dword(tp->pci_dev, 0x40, 0x40000000);
1.1       root     1058: }
1.1.1.3 ! root     1059: 
1.1       root     1060: 
                   1061: /* Serial EEPROM section. */
                   1062: /* The main routine to parse the very complicated SROM structure.
                   1063:    Search www.digital.com for "21X4 SROM" to get details.
                   1064:    This code is very complex, and will require changes to support
1.1.1.3 ! root     1065:    additional cards, so I will be verbose about what is going on.
1.1       root     1066:    */
                   1067: 
1.1.1.3 ! root     1068: /* Known cards that have old-style EEPROMs.
        !          1069:    Writing this table is described at
        !          1070:    http://www.scyld.com/network/tulip-media.html
        !          1071: */
1.1       root     1072: static struct fixups {
                   1073:   char *name;
                   1074:   unsigned char addr0, addr1, addr2;
                   1075:   u16 newtable[32];                            /* Max length below. */
                   1076: } eeprom_fixups[] = {
                   1077:   {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
                   1078:                                                  0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
1.1.1.2   root     1079:   {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f,
1.1       root     1080:                                                           0x0000, 0x009E, /* 10baseT */
1.1.1.2   root     1081:                                                           0x0004, 0x009E, /* 10baseT-FD */
                   1082:                                                           0x0903, 0x006D, /* 100baseTx */
                   1083:                                                           0x0905, 0x006D, /* 100baseTx-FD */ }},
                   1084:   {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f,
1.1       root     1085:                                                                 0x0107, 0x8021, /* 100baseFx */
                   1086:                                                                 0x0108, 0x8021, /* 100baseFx-FD */
1.1.1.2   root     1087:                                                                 0x0100, 0x009E, /* 10baseT */
                   1088:                                                                 0x0104, 0x009E, /* 10baseT-FD */
                   1089:                                                                 0x0103, 0x006D, /* 100baseTx */
                   1090:                                                                 0x0105, 0x006D, /* 100baseTx-FD */ }},
                   1091:   {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513,
1.1       root     1092:                                                           0x1001, 0x009E, /* 10base2, CSR12 0x10*/
                   1093:                                                           0x0000, 0x009E, /* 10baseT */
1.1.1.2   root     1094:                                                           0x0004, 0x009E, /* 10baseT-FD */
                   1095:                                                           0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */
                   1096:                                                           0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}},
                   1097:   {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F,
                   1098:                                                                  0x1B01, 0x0000, /* 10base2,   CSR12 0x1B */
                   1099:                                                                  0x0B00, 0x009E, /* 10baseT,   CSR12 0x0B */
                   1100:                                                                  0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */
                   1101:                                                                  0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
                   1102:                                                                  0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */
1.1       root     1103:    }},
                   1104:   {0, 0, 0, 0, {}}};
                   1105: 
                   1106: static const char * block_name[] = {"21140 non-MII", "21140 MII PHY",
                   1107:  "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
                   1108: 
1.1.1.2   root     1109: #if defined(__i386__)                  /* AKA get_unaligned() */
1.1       root     1110: #define get_u16(ptr) (*(u16 *)(ptr))
                   1111: #else
                   1112: #define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8))
                   1113: #endif
                   1114: 
1.1.1.3 ! root     1115: static void parse_eeprom(struct net_device *dev)
1.1       root     1116: {
                   1117:        /* The last media info list parsed, for multiport boards.  */
                   1118:        static struct mediatable *last_mediatable = NULL;
                   1119:        static unsigned char *last_ee_data = NULL;
                   1120:        static int controller_index = 0;
                   1121:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
1.1.1.3 ! root     1122:        unsigned char *p, *ee_data = tp->eeprom;
        !          1123:        int new_advertise = 0;
1.1       root     1124:        int i;
                   1125: 
                   1126:        tp->mtable = 0;
                   1127:        /* Detect an old-style (SA only) EEPROM layout:
                   1128:           memcmp(eedata, eedata+16, 8). */
                   1129:        for (i = 0; i < 8; i ++)
                   1130:                if (ee_data[i] != ee_data[16+i])
                   1131:                        break;
                   1132:        if (i >= 8) {
                   1133:                if (ee_data[0] == 0xff) {
                   1134:                        if (last_mediatable) {
                   1135:                                controller_index++;
                   1136:                                printk(KERN_INFO "%s:  Controller %d of multiport board.\n",
                   1137:                                           dev->name, controller_index);
                   1138:                                tp->mtable = last_mediatable;
                   1139:                                ee_data = last_ee_data;
                   1140:                                goto subsequent_board;
                   1141:                        } else
                   1142:                                printk(KERN_INFO "%s:  Missing EEPROM, this interface may "
                   1143:                                           "not work correctly!\n",
1.1.1.3 ! root     1144:                                           dev->name);
1.1       root     1145:                        return;
                   1146:                }
1.1.1.3 ! root     1147:                /* Do a fix-up based on the vendor half of the station address. */
        !          1148:                for (i = 0; eeprom_fixups[i].name; i++) {
        !          1149:                        if (dev->dev_addr[0] == eeprom_fixups[i].addr0
        !          1150:                                &&  dev->dev_addr[1] == eeprom_fixups[i].addr1
        !          1151:                                &&  dev->dev_addr[2] == eeprom_fixups[i].addr2) {
        !          1152:                                if (dev->dev_addr[2] == 0xE8  &&  ee_data[0x1a] == 0x55)
        !          1153:                                        i++;            /* An Accton EN1207, not an outlaw Maxtech. */
        !          1154:                                memcpy(ee_data + 26, eeprom_fixups[i].newtable,
        !          1155:                                           sizeof(eeprom_fixups[i].newtable));
        !          1156:                                printk(KERN_INFO "%s: Old format EEPROM on '%s' board.\n"
        !          1157:                                           KERN_INFO "%s: Using substitute media control info.\n",
        !          1158:                                           dev->name, eeprom_fixups[i].name, dev->name);
        !          1159:                                break;
        !          1160:                        }
        !          1161:                }
        !          1162:                if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
        !          1163:                        printk(KERN_INFO "%s: Old style EEPROM with no media selection "
        !          1164:                                   "information.\n",
        !          1165:                                   dev->name);
        !          1166:                        return;
1.1       root     1167:                }
                   1168:        }
1.1.1.2   root     1169: 
1.1       root     1170:        controller_index = 0;
1.1.1.3 ! root     1171:        if (ee_data[19] > 1) {
        !          1172:                struct net_device *prev_dev;
        !          1173:                struct tulip_private *otp;
        !          1174:                /* This is a multiport board.  The probe order may be "backwards", so
        !          1175:                   we patch up already found devices. */
1.1       root     1176:                last_ee_data = ee_data;
1.1.1.3 ! root     1177:                for (prev_dev = tp->next_module; prev_dev; prev_dev = otp->next_module) {
        !          1178:                        otp = (struct tulip_private *)prev_dev->priv;
        !          1179:                        if (otp->eeprom[0] == 0xff  &&  otp->mtable == 0) {
        !          1180:                                parse_eeprom(prev_dev);
        !          1181:                                start_link(prev_dev);
        !          1182:                        } else
        !          1183:                                break;
        !          1184:                }
        !          1185:                controller_index = 0;
1.1       root     1186:        }
                   1187: subsequent_board:
                   1188: 
1.1.1.3 ! root     1189:        p = (void *)ee_data + ee_data[27 + controller_index*3];
1.1       root     1190:        if (ee_data[27] == 0) {         /* No valid media table. */
                   1191:        } else if (tp->chip_id == DC21041) {
1.1.1.2   root     1192:                int media = get_u16(p);
                   1193:                int count = p[2];
                   1194:                p += 3;
1.1       root     1195: 
1.1.1.2   root     1196:                printk(KERN_INFO "%s: 21041 Media table, default media %4.4x (%s).\n",
                   1197:                           dev->name, media,
1.1.1.3 ! root     1198:                           media & 0x0800 ? "Autosense" : medianame[media & MEDIA_MASK]);
1.1       root     1199:                for (i = 0; i < count; i++) {
1.1.1.3 ! root     1200:                        unsigned char media_block = *p++;
        !          1201:                        int media_code = media_block & MEDIA_MASK;
        !          1202:                        if (media_block & 0x40)
1.1.1.2   root     1203:                                p += 6;
1.1.1.3 ! root     1204:                        switch(media_code) {
        !          1205:                        case 0: new_advertise |= 0x0020; break;
        !          1206:                        case 4: new_advertise |= 0x0040; break;
        !          1207:                        }
1.1.1.2   root     1208:                        printk(KERN_INFO "%s:  21041 media #%d, %s.\n",
1.1.1.3 ! root     1209:                                   dev->name, media_code, medianame[media_code]);
1.1       root     1210:                }
                   1211:        } else {
                   1212:                unsigned char csr12dir = 0;
1.1.1.3 ! root     1213:                int count;
1.1       root     1214:                struct mediatable *mtable;
                   1215:                u16 media = get_u16(p);
                   1216: 
                   1217:                p += 2;
1.1.1.2   root     1218:                if (tp->flags & CSR12_IN_SROM)
1.1       root     1219:                        csr12dir = *p++;
                   1220:                count = *p++;
                   1221:                mtable = (struct mediatable *)
                   1222:                        kmalloc(sizeof(struct mediatable) + count*sizeof(struct medialeaf),
                   1223:                                        GFP_KERNEL);
                   1224:                if (mtable == NULL)
                   1225:                        return;                         /* Horrible, impossible failure. */
                   1226:                last_mediatable = tp->mtable = mtable;
                   1227:                mtable->defaultmedia = media;
                   1228:                mtable->leafcount = count;
                   1229:                mtable->csr12dir = csr12dir;
1.1.1.2   root     1230:                mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0;
                   1231:                mtable->csr15dir = mtable->csr15val = 0;
1.1       root     1232: 
                   1233:                printk(KERN_INFO "%s:  EEPROM default media type %s.\n", dev->name,
1.1.1.3 ! root     1234:                           media & 0x0800 ? "Autosense" : medianame[media & MEDIA_MASK]);
1.1       root     1235:                for (i = 0; i < count; i++) {
                   1236:                        struct medialeaf *leaf = &mtable->mleaf[i];
1.1.1.2   root     1237: 
1.1       root     1238:                        if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
                   1239:                                leaf->type = 0;
                   1240:                                leaf->media = p[0] & 0x3f;
                   1241:                                leaf->leafdata = p;
                   1242:                                if ((p[2] & 0x61) == 0x01)      /* Bogus, but Znyx boards do it. */
                   1243:                                        mtable->has_mii = 1;
                   1244:                                p += 4;
                   1245:                        } else {
1.1.1.3 ! root     1246:                                switch(leaf->type = p[1]) {
        !          1247:                                case 5:
        !          1248:                                        mtable->has_reset = i + 1; /* Assure non-zero */
        !          1249:                                        /* Fall through */
        !          1250:                                case 6:
        !          1251:                                        leaf->media = 31;
        !          1252:                                        break;
        !          1253:                                case 1: case 3:
1.1       root     1254:                                        mtable->has_mii = 1;
                   1255:                                        leaf->media = 11;
1.1.1.3 ! root     1256:                                        break;
        !          1257:                                case 2:
        !          1258:                                        if ((p[2] & 0x3f) == 0) {
        !          1259:                                                u32 base15 = (p[2] & 0x40) ? get_u16(p + 7) : 0x0008;
        !          1260:                                                u16 *p1 = (u16 *)(p + (p[2] & 0x40 ? 9 : 3));
        !          1261:                                                mtable->csr15dir = (get_unaligned(p1 + 0)<<16) + base15;
        !          1262:                                                mtable->csr15val = (get_unaligned(p1 + 1)<<16) + base15;
        !          1263:                                        }
        !          1264:                                        /* Fall through. */
        !          1265:                                case 0: case 4:
1.1       root     1266:                                        mtable->has_nonmii = 1;
1.1.1.3 ! root     1267:                                        leaf->media = p[2] & MEDIA_MASK;
1.1.1.2   root     1268:                                        switch (leaf->media) {
                   1269:                                        case 0: new_advertise |= 0x0020; break;
                   1270:                                        case 4: new_advertise |= 0x0040; break;
                   1271:                                        case 3: new_advertise |= 0x0080; break;
                   1272:                                        case 5: new_advertise |= 0x0100; break;
                   1273:                                        case 6: new_advertise |= 0x0200; break;
                   1274:                                        }
1.1.1.3 ! root     1275:                                        break;
        !          1276:                                default:
        !          1277:                                        leaf->media = 19;
1.1       root     1278:                                }
                   1279:                                leaf->leafdata = p + 2;
                   1280:                                p += (p[0] & 0x3f) + 1;
                   1281:                        }
1.1.1.3 ! root     1282:                        if ((tp->msg_level & NETIF_MSG_LINK) &&
        !          1283:                                leaf->media == 11) {
1.1       root     1284:                                unsigned char *bp = leaf->leafdata;
                   1285:                                printk(KERN_INFO "%s:  MII interface PHY %d, setup/reset "
                   1286:                                           "sequences %d/%d long, capabilities %2.2x %2.2x.\n",
1.1.1.2   root     1287:                                           dev->name, bp[0], bp[1], bp[2 + bp[1]*2],
1.1       root     1288:                                           bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]);
                   1289:                        }
1.1.1.3 ! root     1290:                        if (tp->msg_level & NETIF_MSG_PROBE)
        !          1291:                                printk(KERN_INFO "%s:  Index #%d - Media %s (#%d) described "
        !          1292:                                           "by a %s (%d) block.\n",
        !          1293:                                           dev->name, i, medianame[leaf->media], leaf->media,
        !          1294:                                           leaf->type < 6 ? block_name[leaf->type] : "UNKNOWN",
        !          1295:                                           leaf->type);
1.1       root     1296:                }
1.1.1.2   root     1297:                if (new_advertise)
1.1.1.3 ! root     1298:                        tp->sym_advertise = new_advertise;
1.1       root     1299:        }
                   1300: }
                   1301: /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/
                   1302: 
                   1303: /*  EEPROM_Ctrl bits. */
                   1304: #define EE_SHIFT_CLK   0x02    /* EEPROM shift clock. */
                   1305: #define EE_CS                  0x01    /* EEPROM chip select. */
1.1.1.2   root     1306: #define EE_DATA_WRITE  0x04    /* Data from the Tulip to EEPROM. */
1.1       root     1307: #define EE_WRITE_0             0x01
                   1308: #define EE_WRITE_1             0x05
1.1.1.2   root     1309: #define EE_DATA_READ   0x08    /* Data from the EEPROM chip. */
1.1       root     1310: #define EE_ENB                 (0x4800 | EE_CS)
                   1311: 
                   1312: /* Delay between EEPROM clock transitions.
1.1.1.3 ! root     1313:    Even at 33Mhz current PCI implementations do not overrun the EEPROM clock.
1.1.1.2   root     1314:    We add a bus turn-around to insure that this remains true. */
                   1315: #define eeprom_delay() inl(ee_addr)
1.1       root     1316: 
                   1317: /* The EEPROM commands include the alway-set leading bit. */
1.1.1.2   root     1318: #define EE_READ_CMD            (6)
1.1       root     1319: 
1.1.1.2   root     1320: /* Note: this routine returns extra data bits for size detection. */
                   1321: static int read_eeprom(long ioaddr, int location, int addr_len)
1.1       root     1322: {
                   1323:        int i;
1.1.1.2   root     1324:        unsigned retval = 0;
1.1       root     1325:        long ee_addr = ioaddr + CSR9;
1.1.1.2   root     1326:        int read_cmd = location | (EE_READ_CMD << addr_len);
                   1327: 
1.1       root     1328:        outl(EE_ENB & ~EE_CS, ee_addr);
                   1329:        outl(EE_ENB, ee_addr);
1.1.1.2   root     1330: 
1.1       root     1331:        /* Shift the read command bits out. */
1.1.1.2   root     1332:        for (i = 4 + addr_len; i >= 0; i--) {
1.1       root     1333:                short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
                   1334:                outl(EE_ENB | dataval, ee_addr);
1.1.1.2   root     1335:                eeprom_delay();
1.1       root     1336:                outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1.1.1.2   root     1337:                eeprom_delay();
                   1338:                retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
1.1       root     1339:        }
                   1340:        outl(EE_ENB, ee_addr);
1.1.1.3 ! root     1341:        eeprom_delay();
1.1.1.2   root     1342: 
1.1       root     1343:        for (i = 16; i > 0; i--) {
                   1344:                outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
1.1.1.2   root     1345:                eeprom_delay();
1.1       root     1346:                retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
                   1347:                outl(EE_ENB, ee_addr);
1.1.1.2   root     1348:                eeprom_delay();
1.1       root     1349:        }
                   1350: 
                   1351:        /* Terminate the EEPROM access. */
                   1352:        outl(EE_ENB & ~EE_CS, ee_addr);
                   1353:        return retval;
                   1354: }
                   1355: 
                   1356: /* MII transceiver control section.
                   1357:    Read and write the MII registers using software-generated serial
                   1358:    MDIO protocol.  See the MII specifications or DP83840A data sheet
                   1359:    for details. */
                   1360: 
                   1361: /* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
                   1362:    met by back-to-back PCI I/O cycles, but we insert a delay to avoid
                   1363:    "overclocking" issues or future 66Mhz PCI. */
                   1364: #define mdio_delay() inl(mdio_addr)
                   1365: 
                   1366: /* Read and write the MII registers using software-generated serial
                   1367:    MDIO protocol.  It is just different enough from the EEPROM protocol
                   1368:    to not share code.  The maxium data clock rate is 2.5 Mhz. */
                   1369: #define MDIO_SHIFT_CLK 0x10000
                   1370: #define MDIO_DATA_WRITE0 0x00000
                   1371: #define MDIO_DATA_WRITE1 0x20000
                   1372: #define MDIO_ENB               0x00000         /* Ignore the 0x02000 databook setting. */
                   1373: #define MDIO_ENB_IN            0x40000
                   1374: #define MDIO_DATA_READ 0x80000
                   1375: 
1.1.1.3 ! root     1376: static const unsigned char comet_miireg2offset[32] = {
        !          1377:        0xB4, 0xB8, 0xBC, 0xC0,  0xC4, 0xC8, 0xCC, 0,  0,0,0,0,  0,0,0,0,
        !          1378:        0,0xD0,0,0,  0,0,0,0,  0,0,0,0, 0, 0xD4, 0xD8, 0xDC, };
        !          1379: 
        !          1380: static int mdio_read(struct net_device *dev, int phy_id, int location)
1.1       root     1381: {
                   1382:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1383:        int i;
1.1.1.3 ! root     1384:        int read_cmd = (0xf6 << 10) | ((phy_id & 0x1f) << 5) | location;
1.1       root     1385:        int retval = 0;
1.1.1.2   root     1386:        long ioaddr = dev->base_addr;
                   1387:        long mdio_addr = ioaddr + CSR9;
1.1.1.3 ! root     1388:        unsigned long flags;
        !          1389: 
        !          1390:        if (location & ~0x1f)
        !          1391:                return 0xffff;
        !          1392: 
        !          1393:        if (tp->chip_id == COMET  &&  phy_id == 30) {
        !          1394:                if (comet_miireg2offset[location])
        !          1395:                        return inl(ioaddr + comet_miireg2offset[location]);
        !          1396:                return 0xffff;
        !          1397:        }
1.1       root     1398: 
1.1.1.3 ! root     1399:        spin_lock_irqsave(&tp->mii_lock, flags);
1.1       root     1400:        if (tp->chip_id == LC82C168) {
                   1401:                int i = 1000;
                   1402:                outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
1.1.1.2   root     1403:                inl(ioaddr + 0xA0);
                   1404:                inl(ioaddr + 0xA0);
1.1.1.3 ! root     1405:                inl(ioaddr + 0xA0);
        !          1406:                inl(ioaddr + 0xA0);
1.1       root     1407:                while (--i > 0)
                   1408:                        if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
1.1.1.3 ! root     1409:                                break;
        !          1410:                spin_unlock_irqrestore(&tp->mii_lock, flags);
        !          1411:                return retval & 0xffff;
1.1.1.2   root     1412:        }
                   1413: 
                   1414:        /* Establish sync by sending at least 32 logic ones. */
1.1       root     1415:        for (i = 32; i >= 0; i--) {
                   1416:                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
                   1417:                mdio_delay();
                   1418:                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
                   1419:                mdio_delay();
                   1420:        }
                   1421:        /* Shift the read command bits out. */
                   1422:        for (i = 15; i >= 0; i--) {
                   1423:                int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
                   1424: 
                   1425:                outl(MDIO_ENB | dataval, mdio_addr);
                   1426:                mdio_delay();
                   1427:                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
                   1428:                mdio_delay();
                   1429:        }
                   1430:        /* Read the two transition, 16 data, and wire-idle bits. */
                   1431:        for (i = 19; i > 0; i--) {
                   1432:                outl(MDIO_ENB_IN, mdio_addr);
                   1433:                mdio_delay();
                   1434:                retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
                   1435:                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
                   1436:                mdio_delay();
                   1437:        }
1.1.1.3 ! root     1438:        spin_unlock_irqrestore(&tp->mii_lock, flags);
1.1       root     1439:        return (retval>>1) & 0xffff;
                   1440: }
                   1441: 
1.1.1.3 ! root     1442: static void mdio_write(struct net_device *dev, int phy_id, int location, int val)
1.1       root     1443: {
                   1444:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1445:        int i;
1.1.1.3 ! root     1446:        int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | (val & 0xffff);
1.1.1.2   root     1447:        long ioaddr = dev->base_addr;
                   1448:        long mdio_addr = ioaddr + CSR9;
1.1.1.3 ! root     1449:        unsigned long flags;
        !          1450: 
        !          1451:        if (location & ~0x1f)
        !          1452:                return;
        !          1453: 
        !          1454:        if (tp->chip_id == COMET  &&  phy_id == 30) {
        !          1455:                if (comet_miireg2offset[location])
        !          1456:                        outl(val, ioaddr + comet_miireg2offset[location]);
        !          1457:                return;
        !          1458:        }
1.1       root     1459: 
1.1.1.3 ! root     1460:        spin_lock_irqsave(&tp->mii_lock, flags);
1.1       root     1461:        if (tp->chip_id == LC82C168) {
                   1462:                int i = 1000;
                   1463:                outl(cmd, ioaddr + 0xA0);
                   1464:                do
                   1465:                        if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
                   1466:                                break;
                   1467:                while (--i > 0);
1.1.1.3 ! root     1468:                spin_unlock_irqrestore(&tp->mii_lock, flags);
1.1.1.2   root     1469:                return;
                   1470:        }
                   1471: 
                   1472:        /* Establish sync by sending 32 logic ones. */
1.1       root     1473:        for (i = 32; i >= 0; i--) {
                   1474:                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
                   1475:                mdio_delay();
                   1476:                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
                   1477:                mdio_delay();
                   1478:        }
                   1479:        /* Shift the command bits out. */
                   1480:        for (i = 31; i >= 0; i--) {
                   1481:                int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
                   1482:                outl(MDIO_ENB | dataval, mdio_addr);
                   1483:                mdio_delay();
                   1484:                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
                   1485:                mdio_delay();
                   1486:        }
                   1487:        /* Clear out extra bits. */
                   1488:        for (i = 2; i > 0; i--) {
                   1489:                outl(MDIO_ENB_IN, mdio_addr);
                   1490:                mdio_delay();
                   1491:                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
                   1492:                mdio_delay();
                   1493:        }
1.1.1.3 ! root     1494:        spin_unlock_irqrestore(&tp->mii_lock, flags);
1.1       root     1495:        return;
                   1496: }
                   1497: 
                   1498: 
                   1499: static int
1.1.1.3 ! root     1500: tulip_open(struct net_device *dev)
1.1       root     1501: {
                   1502:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1503:        long ioaddr = dev->base_addr;
1.1.1.2   root     1504:        int next_tick = 3*HZ;
                   1505: 
                   1506:        /* Wake the chip from sleep/snooze mode. */
                   1507:        if (tp->flags & HAS_PWRDWN)
1.1.1.3 ! root     1508:                pci_write_config_dword(tp->pci_dev, 0x40, 0);
1.1       root     1509: 
                   1510:        /* On some chip revs we must set the MII/SYM port before the reset!? */
                   1511:        if (tp->mii_cnt  ||  (tp->mtable  &&  tp->mtable->has_mii))
                   1512:                outl(0x00040000, ioaddr + CSR6);
                   1513: 
                   1514:        /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
                   1515:        outl(0x00000001, ioaddr + CSR0);
1.1.1.2   root     1516: 
                   1517:        MOD_INC_USE_COUNT;
                   1518: 
1.1.1.3 ! root     1519:        /* This would be done after interrupts are initialized, but we do not want
        !          1520:           to frob the transceiver only to fail later. */
        !          1521:        if (request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)) {
        !          1522:                MOD_DEC_USE_COUNT;
        !          1523:                return -EAGAIN;
        !          1524:        }
        !          1525: 
1.1       root     1526:        /* Deassert reset.
                   1527:           Wait the specified 50 PCI cycles after a reset by initializing
                   1528:           Tx and Rx queues and the address filter list. */
1.1.1.2   root     1529:        outl(tp->csr0, ioaddr + CSR0);
1.1       root     1530: 
1.1.1.3 ! root     1531:        if (tp->msg_level & NETIF_MSG_IFUP)
1.1       root     1532:                printk(KERN_DEBUG "%s: tulip_open() irq %d.\n", dev->name, dev->irq);
                   1533: 
                   1534:        tulip_init_ring(dev);
                   1535: 
1.1.1.2   root     1536:        if (tp->chip_id == PNIC2) {
1.1.1.3 ! root     1537:                u32 addr_high = (dev->dev_addr[1]<<8) + (dev->dev_addr[0]<<0);
        !          1538:                /* This address setting does not appear to impact chip operation?? */
        !          1539:                outl((dev->dev_addr[5]<<8) + dev->dev_addr[4] +
        !          1540:                         (dev->dev_addr[3]<<24) + (dev->dev_addr[2]<<16),
1.1.1.2   root     1541:                         ioaddr + 0xB0);
                   1542:                outl(addr_high + (addr_high<<16), ioaddr + 0xB8);
                   1543:        }
                   1544:        if (tp->flags & MC_HASH_ONLY) {
                   1545:                u32 addr_low = cpu_to_le32(get_unaligned((u32 *)dev->dev_addr));
1.1.1.3 ! root     1546:                u32 addr_high = cpu_to_le16(get_unaligned((u16 *)(dev->dev_addr+4)));
        !          1547:                if (tp->flags & IS_ASIX) {
1.1.1.2   root     1548:                        outl(0, ioaddr + CSR13);
                   1549:                        outl(addr_low,  ioaddr + CSR14);
                   1550:                        outl(1, ioaddr + CSR13);
                   1551:                        outl(addr_high, ioaddr + CSR14);
1.1.1.3 ! root     1552:                } else if (tp->flags & COMET_MAC_ADDR) {
1.1.1.2   root     1553:                        outl(addr_low,  ioaddr + 0xA4);
                   1554:                        outl(addr_high, ioaddr + 0xA8);
                   1555:                        outl(0, ioaddr + 0xAC);
                   1556:                        outl(0, ioaddr + 0xB0);
                   1557:                }
1.1       root     1558:        }
                   1559: 
                   1560:        outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3);
                   1561:        outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4);
                   1562: 
1.1.1.3 ! root     1563:        if ( ! tp->full_duplex_lock)
        !          1564:                tp->full_duplex = 0;
        !          1565:        init_media(dev);
        !          1566:        if (media_cap[dev->if_port] & MediaIsMII)
        !          1567:                check_duplex(dev);
        !          1568:        set_rx_mode(dev);
        !          1569: 
        !          1570:        /* Start the Tx to process setup frame. */
        !          1571:        outl(tp->csr6, ioaddr + CSR6);
        !          1572:        outl(tp->csr6 | TxOn, ioaddr + CSR6);
        !          1573: 
        !          1574:        netif_start_tx_queue(dev);
        !          1575: 
        !          1576:        /* Enable interrupts by setting the interrupt mask. */
        !          1577:        outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
        !          1578:        outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
        !          1579:        outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
        !          1580:        outl(0, ioaddr + CSR2);         /* Rx poll demand */
        !          1581: 
        !          1582:        if (tp->msg_level & NETIF_MSG_IFUP)
        !          1583:                printk(KERN_DEBUG "%s: Done tulip_open(), CSR0 %8.8x, CSR5 %8.8x CSR6 "
        !          1584:                           "%8.8x.\n", dev->name, (int)inl(ioaddr + CSR0),
        !          1585:                           (int)inl(ioaddr + CSR5), (int)inl(ioaddr + CSR6));
        !          1586: 
        !          1587:        /* Set the timer to switch to check for link beat and perhaps switch
        !          1588:           to an alternate media type. */
        !          1589:        init_timer(&tp->timer);
        !          1590:        tp->timer.expires = jiffies + next_tick;
        !          1591:        tp->timer.data = (unsigned long)dev;
        !          1592:        tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
        !          1593:        add_timer(&tp->timer);
        !          1594: 
        !          1595:        return 0;
        !          1596: }
        !          1597: 
        !          1598: static void init_media(struct net_device *dev)
        !          1599: {
        !          1600:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          1601:        long ioaddr = dev->base_addr;
        !          1602:        int i;
        !          1603: 
1.1.1.2   root     1604:        tp->saved_if_port = dev->if_port;
1.1       root     1605:        if (dev->if_port == 0)
                   1606:                dev->if_port = tp->default_port;
                   1607: 
                   1608:        /* Allow selecting a default media. */
1.1.1.2   root     1609:        i = 0;
1.1       root     1610:        if (tp->mtable == NULL)
                   1611:                goto media_picked;
                   1612:        if (dev->if_port) {
                   1613:                int looking_for = media_cap[dev->if_port] & MediaIsMII ? 11 :
                   1614:                        (dev->if_port == 12 ? 0 : dev->if_port);
                   1615:                for (i = 0; i < tp->mtable->leafcount; i++)
                   1616:                        if (tp->mtable->mleaf[i].media == looking_for) {
                   1617:                                printk(KERN_INFO "%s: Using user-specified media %s.\n",
                   1618:                                           dev->name, medianame[dev->if_port]);
                   1619:                                goto media_picked;
                   1620:                        }
                   1621:        }
1.1.1.2   root     1622:        if ((tp->mtable->defaultmedia & 0x0800) == 0) {
1.1.1.3 ! root     1623:                int looking_for = tp->mtable->defaultmedia & MEDIA_MASK;
1.1       root     1624:                for (i = 0; i < tp->mtable->leafcount; i++)
1.1.1.2   root     1625:                        if (tp->mtable->mleaf[i].media == looking_for) {
                   1626:                                printk(KERN_INFO "%s: Using EEPROM-set media %s.\n",
                   1627:                                           dev->name, medianame[looking_for]);
                   1628:                                goto media_picked;
                   1629:                        }
                   1630:        }
1.1       root     1631:        /* Start sensing first non-full-duplex media. */
                   1632:        for (i = tp->mtable->leafcount - 1;
                   1633:                 (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
1.1.1.2   root     1634:                ;
1.1       root     1635: media_picked:
                   1636: 
                   1637:        tp->csr6 = 0;
                   1638:        tp->cur_index = i;
1.1.1.2   root     1639:        tp->nwayset = 0;
1.1.1.3 ! root     1640: 
        !          1641:        if (dev->if_port) {
        !          1642:                if (tp->chip_id == DC21143  &&
        !          1643:                        (media_cap[dev->if_port] & MediaIsMII)) {
        !          1644:                        /* We must reset the media CSRs when we force-select MII mode. */
        !          1645:                        outl(0x0000, ioaddr + CSR13);
        !          1646:                        outl(0x0000, ioaddr + CSR14);
        !          1647:                        outl(0x0008, ioaddr + CSR15);
        !          1648:                }
        !          1649:                select_media(dev, 1);
        !          1650:                return;
1.1.1.2   root     1651:        }
1.1.1.3 ! root     1652:        switch(tp->chip_id) {
        !          1653:        case DC21041:
        !          1654:                /* tp->nway = 1;*/
        !          1655:                nway_start(dev);
        !          1656:                break;
        !          1657:        case DC21142:
1.1.1.2   root     1658:                if (tp->mii_cnt) {
                   1659:                        select_media(dev, 1);
1.1.1.3 ! root     1660:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     1661:                                printk(KERN_INFO "%s: Using MII transceiver %d, status "
                   1662:                                           "%4.4x.\n",
                   1663:                                           dev->name, tp->phys[0], mdio_read(dev, tp->phys[0], 1));
                   1664:                        outl(0x82020000, ioaddr + CSR6);
                   1665:                        tp->csr6 = 0x820E0000;
                   1666:                        dev->if_port = 11;
                   1667:                        outl(0x0000, ioaddr + CSR13);
                   1668:                        outl(0x0000, ioaddr + CSR14);
                   1669:                } else
1.1.1.3 ! root     1670:                        nway_start(dev);
        !          1671:                break;
        !          1672:        case PNIC2:
        !          1673:                nway_start(dev);
        !          1674:                break;
        !          1675:        case LC82C168:
1.1.1.2   root     1676:                if (tp->mii_cnt) {
                   1677:                        dev->if_port = 11;
1.1.1.3 ! root     1678:                        tp->csr6 = 0x814C0000 | (tp->full_duplex ? FullDuplex : 0);
1.1.1.2   root     1679:                        outl(0x0001, ioaddr + CSR15);
                   1680:                } else if (inl(ioaddr + CSR5) & TPLnkPass)
                   1681:                        pnic_do_nway(dev);
                   1682:                else {
                   1683:                        /* Start with 10mbps to do autonegotiation. */
                   1684:                        outl(0x32, ioaddr + CSR12);
                   1685:                        tp->csr6 = 0x00420000;
                   1686:                        outl(0x0001B078, ioaddr + 0xB8);
                   1687:                        outl(0x0201B078, ioaddr + 0xB8);
                   1688:                }
1.1.1.3 ! root     1689:                break;
        !          1690:        case MX98713: case COMPEX9881:
1.1.1.2   root     1691:                dev->if_port = 0;
1.1.1.3 ! root     1692:                tp->csr6 = 0x01880000 | (tp->full_duplex ? FullDuplex : 0);
1.1.1.2   root     1693:                outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
1.1.1.3 ! root     1694:                break;
        !          1695:        case MX98715: case MX98725:
1.1.1.2   root     1696:                /* Provided by BOLO, Macronix - 12/10/1998. */
                   1697:                dev->if_port = 0;
1.1.1.3 ! root     1698:                tp->csr6 = 0x01a80000 | FullDuplex;
1.1.1.2   root     1699:                outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
                   1700:                outl(0x11000 | inw(ioaddr + 0xa0), ioaddr + 0xa0);
1.1.1.3 ! root     1701:                break;
        !          1702:        case COMET: case CONEXANT:
        !          1703:                /* Enable automatic Tx underrun recovery. */
        !          1704:                outl(inl(ioaddr + 0x88) | 1, ioaddr + 0x88);
        !          1705:                dev->if_port = tp->mii_cnt ? 11 : 0;
1.1.1.2   root     1706:                tp->csr6 = 0x00040000;
1.1.1.3 ! root     1707:                break;
        !          1708:        case AX88140: case AX88141:
1.1.1.2   root     1709:                tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
1.1.1.3 ! root     1710:                break;
        !          1711:        default:
1.1       root     1712:                select_media(dev, 1);
                   1713:        }
                   1714: }
                   1715: 
1.1.1.3 ! root     1716: /* Set up the transceiver control registers for the selected media type.
        !          1717:    STARTUP indicates to reset the transceiver.  It is set to '2' for
        !          1718:    the initial card detection, and '1' during resume or open().
        !          1719: */
        !          1720: static void select_media(struct net_device *dev, int startup)
1.1       root     1721: {
                   1722:        long ioaddr = dev->base_addr;
                   1723:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1724:        struct mediatable *mtable = tp->mtable;
                   1725:        u32 new_csr6;
1.1.1.2   root     1726:        int i;
1.1       root     1727: 
                   1728:        if (mtable) {
                   1729:                struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
                   1730:                unsigned char *p = mleaf->leafdata;
1.1.1.3 ! root     1731:                if (tp->msg_level & NETIF_MSG_LINK)
        !          1732:                        printk(KERN_DEBUG "%s:  Media table type %d.\n",
        !          1733:                                   dev->name, mleaf->type);
1.1       root     1734:                switch (mleaf->type) {
                   1735:                case 0:                                 /* 21140 non-MII xcvr. */
1.1.1.3 ! root     1736:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     1737:                                printk(KERN_DEBUG "%s: Using a 21140 non-MII transceiver"
                   1738:                                           " with control setting %2.2x.\n",
                   1739:                                           dev->name, p[1]);
                   1740:                        dev->if_port = p[0];
                   1741:                        if (startup)
                   1742:                                outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
                   1743:                        outl(p[1], ioaddr + CSR12);
                   1744:                        new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
                   1745:                        break;
                   1746:                case 2: case 4: {
1.1.1.2   root     1747:                        u16 setup[5];
                   1748:                        u32 csr13val, csr14val, csr15dir, csr15val;
                   1749:                        for (i = 0; i < 5; i++)
1.1       root     1750:                                setup[i] = get_u16(&p[i*2 + 1]);
                   1751: 
1.1.1.3 ! root     1752:                        dev->if_port = p[0] & MEDIA_MASK;
1.1.1.2   root     1753:                        if (media_cap[dev->if_port] & MediaAlwaysFD)
                   1754:                                tp->full_duplex = 1;
                   1755: 
                   1756:                        if (startup && mtable->has_reset) {
1.1.1.3 ! root     1757:                                struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset-1];
1.1.1.2   root     1758:                                unsigned char *rst = rleaf->leafdata;
1.1.1.3 ! root     1759:                                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     1760:                                        printk(KERN_DEBUG "%s: Resetting the transceiver.\n",
                   1761:                                                   dev->name);
                   1762:                                for (i = 0; i < rst[0]; i++)
                   1763:                                        outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);
                   1764:                        }
1.1.1.3 ! root     1765:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     1766:                                printk(KERN_DEBUG "%s: 21143 non-MII %s transceiver control "
                   1767:                                           "%4.4x/%4.4x.\n",
1.1       root     1768:                                           dev->name, medianame[dev->if_port], setup[0], setup[1]);
                   1769:                        if (p[0] & 0x40) {      /* SIA (CSR13-15) setup values are provided. */
1.1.1.2   root     1770:                                csr13val = setup[0];
                   1771:                                csr14val = setup[1];
                   1772:                                csr15dir = (setup[3]<<16) | setup[2];
                   1773:                                csr15val = (setup[4]<<16) | setup[2];
1.1       root     1774:                                outl(0, ioaddr + CSR13);
1.1.1.2   root     1775:                                outl(csr14val, ioaddr + CSR14);
                   1776:                                outl(csr15dir, ioaddr + CSR15); /* Direction */
                   1777:                                outl(csr15val, ioaddr + CSR15); /* Data */
                   1778:                                outl(csr13val, ioaddr + CSR13);
1.1       root     1779:                        } else {
1.1.1.2   root     1780:                                csr13val = 1;
1.1.1.3 ! root     1781:                                csr14val = 0x0003FFFF;
1.1.1.2   root     1782:                                csr15dir = (setup[0]<<16) | 0x0008;
                   1783:                                csr15val = (setup[1]<<16) | 0x0008;
                   1784:                                if (dev->if_port <= 4)
                   1785:                                        csr14val = t21142_csr14[dev->if_port];
                   1786:                                if (startup) {
                   1787:                                        outl(0, ioaddr + CSR13);
                   1788:                                        outl(csr14val, ioaddr + CSR14);
                   1789:                                }
                   1790:                                outl(csr15dir, ioaddr + CSR15); /* Direction */
                   1791:                                outl(csr15val, ioaddr + CSR15); /* Data */
                   1792:                                if (startup) outl(csr13val, ioaddr + CSR13);
1.1       root     1793:                        }
1.1.1.3 ! root     1794:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     1795:                                printk(KERN_DEBUG "%s:  Setting CSR15 to %8.8x/%8.8x.\n",
                   1796:                                           dev->name, csr15dir, csr15val);
1.1       root     1797:                        if (mleaf->type == 4)
1.1.1.3 ! root     1798:                                new_csr6 = 0x820A0000 | ((setup[2] & 0x71) << 18);
1.1       root     1799:                        else
                   1800:                                new_csr6 = 0x82420000;
                   1801:                        break;
                   1802:                }
                   1803:                case 1: case 3: {
                   1804:                        int phy_num = p[0];
                   1805:                        int init_length = p[1];
                   1806:                        u16 *misc_info;
                   1807: 
                   1808:                        dev->if_port = 11;
                   1809:                        new_csr6 = 0x020E0000;
                   1810:                        if (mleaf->type == 3) { /* 21142 */
                   1811:                                u16 *init_sequence = (u16*)(p+2);
                   1812:                                u16 *reset_sequence = &((u16*)(p+3))[init_length];
                   1813:                                int reset_length = p[2 + init_length*2];
                   1814:                                misc_info = reset_sequence + reset_length;
                   1815:                                if (startup)
                   1816:                                        for (i = 0; i < reset_length; i++)
                   1817:                                                outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
                   1818:                                for (i = 0; i < init_length; i++)
                   1819:                                        outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
                   1820:                        } else {
                   1821:                                u8 *init_sequence = p + 2;
                   1822:                                u8 *reset_sequence = p + 3 + init_length;
                   1823:                                int reset_length = p[2 + init_length];
                   1824:                                misc_info = (u16*)(reset_sequence + reset_length);
                   1825:                                if (startup) {
                   1826:                                        outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
                   1827:                                        for (i = 0; i < reset_length; i++)
                   1828:                                                outl(reset_sequence[i], ioaddr + CSR12);
                   1829:                                }
                   1830:                                for (i = 0; i < init_length; i++)
                   1831:                                        outl(init_sequence[i], ioaddr + CSR12);
                   1832:                        }
1.1.1.3 ! root     1833:                        tp->advertising[phy_num] = get_u16(&misc_info[1]) | 1;
        !          1834:                        if (startup < 2) {
        !          1835:                                if (tp->mii_advertise == 0)
        !          1836:                                        tp->mii_advertise = tp->advertising[phy_num];
        !          1837:                                if (tp->msg_level & NETIF_MSG_LINK)
        !          1838:                                        printk(KERN_DEBUG "%s:  Advertising %4.4x on MII %d.\n",
        !          1839:                                                   dev->name, tp->mii_advertise, tp->phys[phy_num]);
        !          1840:                                mdio_write(dev, tp->phys[phy_num], 4, tp->mii_advertise);
        !          1841:                        }
1.1       root     1842:                        break;
                   1843:                }
                   1844:                default:
1.1.1.2   root     1845:                        printk(KERN_DEBUG "%s:  Invalid media table selection %d.\n",
                   1846:                                           dev->name, mleaf->type);
                   1847:                        new_csr6 = 0x020E0000;
1.1       root     1848:                }
1.1.1.3 ! root     1849:                if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     1850:                        printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n",
                   1851:                                   dev->name, medianame[dev->if_port],
1.1.1.3 ! root     1852:                                   (int)inl(ioaddr + CSR12) & 0xff);
1.1       root     1853:        } else if (tp->chip_id == DC21041) {
1.1.1.2   root     1854:                int port = dev->if_port <= 4 ? dev->if_port : 0;
1.1.1.3 ! root     1855:                if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     1856:                        printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n",
1.1.1.2   root     1857:                                   dev->name, medianame[port == 3 ? 12: port],
1.1.1.3 ! root     1858:                                   (int)inl(ioaddr + CSR12));
1.1       root     1859:                outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1.1.1.2   root     1860:                outl(t21041_csr14[port], ioaddr + CSR14);
                   1861:                outl(t21041_csr15[port], ioaddr + CSR15);
                   1862:                outl(t21041_csr13[port], ioaddr + CSR13);
1.1       root     1863:                new_csr6 = 0x80020000;
                   1864:        } else if (tp->chip_id == LC82C168) {
                   1865:                if (startup && ! tp->medialock)
                   1866:                        dev->if_port = tp->mii_cnt ? 11 : 0;
1.1.1.3 ! root     1867:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     1868:                        printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, media %s.\n",
1.1.1.3 ! root     1869:                                   dev->name, (int)inl(ioaddr + 0xB8),
        !          1870:                                   medianame[dev->if_port]);
1.1       root     1871:                if (tp->mii_cnt) {
1.1.1.2   root     1872:                        new_csr6 = 0x810C0000;
1.1       root     1873:                        outl(0x0001, ioaddr + CSR15);
                   1874:                        outl(0x0201B07A, ioaddr + 0xB8);
                   1875:                } else if (startup) {
                   1876:                        /* Start with 10mbps to do autonegotiation. */
                   1877:                        outl(0x32, ioaddr + CSR12);
                   1878:                        new_csr6 = 0x00420000;
                   1879:                        outl(0x0001B078, ioaddr + 0xB8);
                   1880:                        outl(0x0201B078, ioaddr + 0xB8);
                   1881:                } else if (dev->if_port == 3  ||  dev->if_port == 5) {
                   1882:                        outl(0x33, ioaddr + CSR12);
                   1883:                        new_csr6 = 0x01860000;
1.1.1.2   root     1884:                        /* Trigger autonegotiation. */
                   1885:                        outl(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);
1.1       root     1886:                } else {
                   1887:                        outl(0x32, ioaddr + CSR12);
                   1888:                        new_csr6 = 0x00420000;
                   1889:                        outl(0x1F078, ioaddr + 0xB8);
                   1890:                }
                   1891:        } else if (tp->chip_id == DC21040) {                                    /* 21040 */
                   1892:                /* Turn on the xcvr interface. */
                   1893:                int csr12 = inl(ioaddr + CSR12);
1.1.1.3 ! root     1894:                if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     1895:                        printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n",
1.1.1.2   root     1896:                                   dev->name, medianame[dev->if_port], csr12);
                   1897:                if (media_cap[dev->if_port] & MediaAlwaysFD)
                   1898:                        tp->full_duplex = 1;
                   1899:                new_csr6 = 0x20000;
1.1       root     1900:                /* Set the full duplux match frame. */
                   1901:                outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
                   1902:                outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1.1.1.2   root     1903:                if (t21040_csr13[dev->if_port] & 8) {
                   1904:                        outl(0x0705, ioaddr + CSR14);
                   1905:                        outl(0x0006, ioaddr + CSR15);
                   1906:                } else {
                   1907:                        outl(0xffff, ioaddr + CSR14);
                   1908:                        outl(0x0000, ioaddr + CSR15);
                   1909:                }
                   1910:                outl(0x8f01 | t21040_csr13[dev->if_port], ioaddr + CSR13);
                   1911:        } else {                                        /* Unknown chip type with no media table. */
1.1       root     1912:                if (tp->default_port == 0)
1.1.1.2   root     1913:                        dev->if_port = tp->mii_cnt ? 11 : 3;
1.1       root     1914:                if (media_cap[dev->if_port] & MediaIsMII) {
                   1915:                        new_csr6 = 0x020E0000;
                   1916:                } else if (media_cap[dev->if_port] & MediaIsFx) {
1.1.1.3 ! root     1917:                        new_csr6 = 0x02860000;
1.1       root     1918:                } else
1.1.1.3 ! root     1919:                        new_csr6 = 0x038E0000;
        !          1920:                if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     1921:                        printk(KERN_DEBUG "%s: No media description table, assuming "
                   1922:                                   "%s transceiver, CSR12 %2.2x.\n",
                   1923:                                   dev->name, medianame[dev->if_port],
1.1.1.3 ! root     1924:                                   (int)inl(ioaddr + CSR12));
1.1       root     1925:        }
                   1926: 
1.1.1.3 ! root     1927:        tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) |
        !          1928:                (tp->full_duplex ? FullDuplex : 0);
1.1       root     1929:        return;
                   1930: }
                   1931: 
1.1.1.2   root     1932: /*
                   1933:   Check the MII negotiated duplex, and change the CSR6 setting if
                   1934:   required.
                   1935:   Return 0 if everything is OK.
                   1936:   Return < 0 if the transceiver is missing or has no link beat.
                   1937:   */
1.1.1.3 ! root     1938: static int check_duplex(struct net_device *dev)
1.1.1.2   root     1939: {
                   1940:        long ioaddr = dev->base_addr;
                   1941:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1942:        int mii_reg1, mii_reg5, negotiated, duplex;
                   1943: 
                   1944:        if (tp->full_duplex_lock)
                   1945:                return 0;
                   1946:        mii_reg5 = mdio_read(dev, tp->phys[0], 5);
1.1.1.3 ! root     1947:        negotiated = mii_reg5 & tp->mii_advertise;
        !          1948: 
        !          1949:        if (tp->msg_level & NETIF_MSG_TIMER)
        !          1950:                printk(KERN_INFO "%s: MII link partner %4.4x, negotiated %4.4x.\n",
        !          1951:                           dev->name, mii_reg5, negotiated);
        !          1952:        if (mii_reg5 == 0xffff)
1.1.1.2   root     1953:                return -2;
1.1.1.3 ! root     1954:        if ((mii_reg5 & 0x4000) == 0  &&                        /* No negotiation. */
        !          1955:                ((mii_reg1 = mdio_read(dev, tp->phys[0], 1)) & 0x0004) == 0) {
1.1.1.2   root     1956:                int new_reg1 = mdio_read(dev, tp->phys[0], 1);
                   1957:                if ((new_reg1 & 0x0004) == 0) {
1.1.1.3 ! root     1958:                        if (tp->msg_level & NETIF_MSG_TIMER)
1.1.1.2   root     1959:                                printk(KERN_INFO "%s: No link beat on the MII interface,"
                   1960:                                           " status %4.4x.\n", dev->name, new_reg1);
                   1961:                        return -1;
                   1962:                }
                   1963:        }
                   1964:        duplex = ((negotiated & 0x0300) == 0x0100
                   1965:                          || (negotiated & 0x00C0) == 0x0040);
                   1966:        /* 100baseTx-FD  or  10T-FD, but not 100-HD */
                   1967:        if (tp->full_duplex != duplex) {
                   1968:                tp->full_duplex = duplex;
1.1.1.3 ! root     1969:                if (negotiated & 0x0380)        /* 100mbps. */
1.1.1.2   root     1970:                        tp->csr6 &= ~0x00400000;
1.1.1.3 ! root     1971:                if (tp->full_duplex) tp->csr6 |= FullDuplex;
        !          1972:                else                             tp->csr6 &= ~FullDuplex;
        !          1973:                outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          1974:                outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
        !          1975:                if (tp->msg_level & NETIF_MSG_LINK)
        !          1976:                        printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1.1.1.2   root     1977:                                   "#%d link partner capability of %4.4x.\n",
                   1978:                                   dev->name, tp->full_duplex ? "full" : "half",
                   1979:                                   tp->phys[0], mii_reg5);
                   1980:                return 1;
                   1981:        }
                   1982:        return 0;
                   1983: }
                   1984: 
1.1       root     1985: static void tulip_timer(unsigned long data)
                   1986: {
1.1.1.3 ! root     1987:        struct net_device *dev = (struct net_device *)data;
1.1       root     1988:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   1989:        long ioaddr = dev->base_addr;
                   1990:        u32 csr12 = inl(ioaddr + CSR12);
1.1.1.2   root     1991:        int next_tick = 2*HZ;
1.1       root     1992: 
1.1.1.3 ! root     1993:        if (tp->msg_level & NETIF_MSG_TIMER)
1.1.1.2   root     1994:                printk(KERN_DEBUG "%s: Media selection tick, %s, status %8.8x mode"
                   1995:                           " %8.8x SIA %8.8x %8.8x %8.8x %8.8x.\n",
1.1.1.3 ! root     1996:                           dev->name, medianame[dev->if_port], (int)inl(ioaddr + CSR5),
        !          1997:                           (int)inl(ioaddr + CSR6), csr12, (int)inl(ioaddr + CSR13),
        !          1998:                           (int)inl(ioaddr + CSR14), (int)inl(ioaddr + CSR15));
        !          1999: 
1.1       root     2000:        switch (tp->chip_id) {
                   2001:        case DC21040:
1.1.1.3 ! root     2002:                if (!tp->medialock  &&  (csr12 & 0x0002)) { /* Network error */
        !          2003:                        if (tp->msg_level & NETIF_MSG_TIMER)
        !          2004:                                printk(KERN_INFO "%s: No link beat found.\n",
        !          2005:                                           dev->name);
1.1.1.2   root     2006:                        dev->if_port = (dev->if_port == 2 ? 0 : 2);
                   2007:                        select_media(dev, 0);
1.1       root     2008:                        dev->trans_start = jiffies;
                   2009:                }
                   2010:                break;
                   2011:        case DC21041:
1.1.1.3 ! root     2012:                if (tp->msg_level & NETIF_MSG_TIMER)
1.1       root     2013:                        printk(KERN_DEBUG "%s: 21041 media tick  CSR12 %8.8x.\n",
                   2014:                                   dev->name, csr12);
1.1.1.2   root     2015:                if (tp->medialock) break;
1.1       root     2016:                switch (dev->if_port) {
                   2017:                case 0: case 3: case 4:
                   2018:                  if (csr12 & 0x0004) { /*LnkFail */
                   2019:                        /* 10baseT is dead.  Check for activity on alternate port. */
                   2020:                        tp->mediasense = 1;
                   2021:                        if (csr12 & 0x0200)
                   2022:                                dev->if_port = 2;
                   2023:                        else
                   2024:                                dev->if_port = 1;
1.1.1.3 ! root     2025:                        if (tp->msg_level & NETIF_MSG_LINK)
        !          2026:                                printk(KERN_INFO "%s: No 21041 10baseT link beat, Media "
        !          2027:                                           "switched to %s.\n",
        !          2028:                                           dev->name, medianame[dev->if_port]);
1.1       root     2029:                        outl(0, ioaddr + CSR13); /* Reset */
                   2030:                        outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
                   2031:                        outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
                   2032:                        outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
                   2033:                        next_tick = 10*HZ;                      /* 2.4 sec. */
                   2034:                  } else
                   2035:                        next_tick = 30*HZ;
                   2036:                  break;
                   2037:                case 1:                                 /* 10base2 */
                   2038:                case 2:                                 /* AUI */
1.1.1.2   root     2039:                        if (csr12 & 0x0100) {
                   2040:                                next_tick = (30*HZ);                    /* 30 sec. */
                   2041:                                tp->mediasense = 0;
                   2042:                        } else if ((csr12 & 0x0004) == 0) {
1.1.1.3 ! root     2043:                                if (tp->msg_level & NETIF_MSG_LINK)
        !          2044:                                        printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n",
        !          2045:                                                   dev->name);
1.1.1.2   root     2046:                                dev->if_port = 0;
                   2047:                                select_media(dev, 0);
                   2048:                                next_tick = (24*HZ)/10;                         /* 2.4 sec. */
                   2049:                        } else if (tp->mediasense || (csr12 & 0x0002)) {
                   2050:                                dev->if_port = 3 - dev->if_port; /* Swap ports. */
                   2051:                                select_media(dev, 0);
                   2052:                                next_tick = 20*HZ;
                   2053:                        } else {
                   2054:                                next_tick = 20*HZ;
                   2055:                        }
                   2056:                        break;
1.1       root     2057:                }
                   2058:                break;
1.1.1.2   root     2059:        case DC21140:  case DC21142: case MX98713: case COMPEX9881: default: {
1.1       root     2060:                struct medialeaf *mleaf;
                   2061:                unsigned char *p;
                   2062:                if (tp->mtable == NULL) {       /* No EEPROM info, use generic code. */
                   2063:                        /* Not much that can be done.
                   2064:                           Assume this a generic MII or SYM transceiver. */
                   2065:                        next_tick = 60*HZ;
1.1.1.3 ! root     2066:                        if (tp->msg_level & NETIF_MSG_TIMER)
1.1       root     2067:                                printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x "
                   2068:                                           "CSR12 0x%2.2x.\n",
1.1.1.3 ! root     2069:                                           dev->name, (int)inl(ioaddr + CSR6), csr12 & 0xff);
1.1       root     2070:                        break;
                   2071:                }
                   2072:                mleaf = &tp->mtable->mleaf[tp->cur_index];
                   2073:                p = mleaf->leafdata;
                   2074:                switch (mleaf->type) {
                   2075:                case 0: case 4: {
                   2076:                        /* Type 0 serial or 4 SYM transceiver.  Check the link beat bit. */
                   2077:                        int offset = mleaf->type == 4 ? 5 : 2;
                   2078:                        s8 bitnum = p[offset];
                   2079:                        if (p[offset+1] & 0x80) {
1.1.1.3 ! root     2080:                                if (tp->msg_level & NETIF_MSG_TIMER)
1.1       root     2081:                                        printk(KERN_DEBUG"%s: Transceiver monitor tick "
                   2082:                                                   "CSR12=%#2.2x, no media sense.\n",
                   2083:                                                   dev->name, csr12);
                   2084:                                if (mleaf->type == 4) {
                   2085:                                        if (mleaf->media == 3 && (csr12 & 0x02))
                   2086:                                                goto select_next_media;
                   2087:                                }
                   2088:                                break;
                   2089:                        }
1.1.1.3 ! root     2090:                        if (tp->msg_level & NETIF_MSG_TIMER)
1.1       root     2091:                                printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x"
                   2092:                                           " bit %d is %d, expecting %d.\n",
                   2093:                                           dev->name, csr12, (bitnum >> 1) & 7,
                   2094:                                           (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,
                   2095:                                           (bitnum >= 0));
                   2096:                        /* Check that the specified bit has the proper value. */
                   2097:                        if ((bitnum < 0) !=
                   2098:                                ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {
1.1.1.3 ! root     2099:                                if (tp->msg_level & NETIF_MSG_LINK)
        !          2100:                                        printk(KERN_DEBUG "%s: Link beat detected for %s.\n",
        !          2101:                                                   dev->name, medianame[mleaf->media & MEDIA_MASK]);
1.1       root     2102:                                if ((p[2] & 0x61) == 0x01)      /* Bogus Znyx board. */
                   2103:                                        goto actually_mii;
                   2104:                                break;
                   2105:                        }
                   2106:                        if (tp->medialock)
                   2107:                                break;
                   2108:          select_next_media:
                   2109:                        if (--tp->cur_index < 0) {
                   2110:                                /* We start again, but should instead look for default. */
                   2111:                                tp->cur_index = tp->mtable->leafcount - 1;
                   2112:                        }
                   2113:                        dev->if_port = tp->mtable->mleaf[tp->cur_index].media;
                   2114:                        if (media_cap[dev->if_port] & MediaIsFD)
                   2115:                                goto select_next_media; /* Skip FD entries. */
1.1.1.3 ! root     2116:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     2117:                                printk(KERN_DEBUG "%s: No link beat on media %s,"
                   2118:                                           " trying transceiver type %s.\n",
1.1.1.3 ! root     2119:                                           dev->name, medianame[mleaf->media & MEDIA_MASK],
1.1       root     2120:                                           medianame[tp->mtable->mleaf[tp->cur_index].media]);
                   2121:                        select_media(dev, 0);
                   2122:                        /* Restart the transmit process. */
1.1.1.3 ! root     2123:                        outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          2124:                        outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
1.1       root     2125:                        next_tick = (24*HZ)/10;
                   2126:                        break;
                   2127:                }
1.1.1.2   root     2128:                case 1:  case 3:                /* 21140, 21142 MII */
1.1       root     2129:                actually_mii:
1.1.1.2   root     2130:                        check_duplex(dev);
1.1       root     2131:                        next_tick = 60*HZ;
                   2132:                        break;
                   2133:                case 2:                                 /* 21142 serial block has no link beat. */
                   2134:                default:
                   2135:                        break;
                   2136:                }
                   2137:        }
                   2138:        break;
                   2139:        }
1.1.1.3 ! root     2140:        tp->timer.expires = jiffies + next_tick;
1.1.1.2   root     2141:        add_timer(&tp->timer);
1.1       root     2142: }
                   2143: 
1.1.1.3 ! root     2144: /* Handle internal NWay transceivers uniquely.
        !          2145:    These exist on the 21041, 21143 (in SYM mode) and the PNIC2.
        !          2146:    */
        !          2147: static void nway_timer(unsigned long data)
1.1       root     2148: {
1.1.1.3 ! root     2149:        struct net_device *dev = (struct net_device *)data;
1.1       root     2150:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2151:        long ioaddr = dev->base_addr;
                   2152:        int csr12 = inl(ioaddr + CSR12);
                   2153:        int next_tick = 60*HZ;
                   2154:        int new_csr6 = 0;
                   2155: 
1.1.1.3 ! root     2156:        if (tp->msg_level & NETIF_MSG_TIMER)
        !          2157:                printk(KERN_INFO"%s: N-Way autonegotiation status %8.8x, %s.\n",
1.1       root     2158:                           dev->name, csr12, medianame[dev->if_port]);
1.1.1.2   root     2159:        if (media_cap[dev->if_port] & MediaIsMII) {
                   2160:                check_duplex(dev);
                   2161:        } else if (tp->nwayset) {
1.1.1.3 ! root     2162:                /* Do not screw up a negotiated session! */
        !          2163:                if (tp->msg_level & NETIF_MSG_TIMER)
1.1.1.2   root     2164:                        printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n",
                   2165:                                   dev->name, medianame[dev->if_port], csr12);
                   2166:        } else if (tp->medialock) {
                   2167:                        ;
                   2168:        } else if (dev->if_port == 3) {
                   2169:                if (csr12 & 2) {        /* No 100mbps link beat, revert to 10mbps. */
1.1.1.3 ! root     2170:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2171:                                printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
                   2172:                                           "trying NWay.\n", dev->name, csr12);
1.1.1.3 ! root     2173:                        nway_start(dev);
1.1.1.2   root     2174:                        next_tick = 3*HZ;
1.1       root     2175:                }
                   2176:        } else if ((csr12 & 0x7000) != 0x5000) {
                   2177:                /* Negotiation failed.  Search media types. */
1.1.1.3 ! root     2178:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2179:                        printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
1.1       root     2180:                                   dev->name, csr12);
                   2181:                if (!(csr12 & 4)) {             /* 10mbps link beat good. */
                   2182:                        new_csr6 = 0x82420000;
                   2183:                        dev->if_port = 0;
                   2184:                        outl(0, ioaddr + CSR13);
                   2185:                        outl(0x0003FFFF, ioaddr + CSR14);
1.1.1.2   root     2186:                        outw(t21142_csr15[dev->if_port], ioaddr + CSR15);
1.1       root     2187:                        outl(t21142_csr13[dev->if_port], ioaddr + CSR13);
                   2188:                } else {
                   2189:                        /* Select 100mbps port to check for link beat. */
                   2190:                        new_csr6 = 0x83860000;
                   2191:                        dev->if_port = 3;
                   2192:                        outl(0, ioaddr + CSR13);
                   2193:                        outl(0x0003FF7F, ioaddr + CSR14);
1.1.1.2   root     2194:                        outw(8, ioaddr + CSR15);
1.1       root     2195:                        outl(1, ioaddr + CSR13);
                   2196:                }
1.1.1.3 ! root     2197:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2198:                        printk(KERN_INFO"%s: Testing new 21143 media %s.\n",
1.1       root     2199:                                   dev->name, medianame[dev->if_port]);
1.1.1.3 ! root     2200:                if (new_csr6 != (tp->csr6 & ~0x20D7)) {
        !          2201:                        tp->csr6 &= 0x20D7;
1.1       root     2202:                        tp->csr6 |= new_csr6;
                   2203:                        outl(0x0301, ioaddr + CSR12);
1.1.1.3 ! root     2204:                        outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          2205:                        outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
1.1       root     2206:                }
1.1.1.2   root     2207:                next_tick = 3*HZ;
                   2208:        }
                   2209:        if (tp->cur_tx - tp->dirty_tx > 0  &&
                   2210:                jiffies - dev->trans_start > TX_TIMEOUT) {
                   2211:                printk(KERN_WARNING "%s: Tx hung, %d vs. %d.\n",
                   2212:                           dev->name, tp->cur_tx, tp->dirty_tx);
                   2213:                tulip_tx_timeout(dev);
1.1       root     2214:        }
1.1.1.2   root     2215: 
1.1.1.3 ! root     2216:        tp->timer.expires = jiffies + next_tick;
1.1       root     2217:        add_timer(&tp->timer);
                   2218: }
                   2219: 
1.1.1.3 ! root     2220: static void nway_start(struct net_device *dev)
1.1.1.2   root     2221: {
                   2222:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2223:        long ioaddr = dev->base_addr;
1.1.1.3 ! root     2224:        int csr14 = ((tp->sym_advertise & 0x0780) << 9)  |
        !          2225:                ((tp->sym_advertise&0x0020)<<1) | 0xffbf;
1.1.1.2   root     2226: 
                   2227:        dev->if_port = 0;
                   2228:        tp->nway = tp->mediasense = 1;
                   2229:        tp->nwayset = tp->lpar = 0;
1.1.1.3 ! root     2230:        if (tp->chip_id == PNIC2) {
        !          2231:                tp->csr6 = 0x01000000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
        !          2232:                return;
        !          2233:        }
        !          2234:        if (tp->msg_level & NETIF_MSG_LINK)
        !          2235:                printk(KERN_DEBUG "%s: Restarting internal NWay autonegotiation, "
        !          2236:                           "%8.8x.\n", dev->name, csr14);
1.1.1.2   root     2237:        outl(0x0001, ioaddr + CSR13);
                   2238:        outl(csr14, ioaddr + CSR14);
1.1.1.3 ! root     2239:        tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0)
        !          2240:                | (tp->csr6 & 0x20ff);
1.1.1.2   root     2241:        outl(tp->csr6, ioaddr + CSR6);
                   2242:        if (tp->mtable  &&  tp->mtable->csr15dir) {
                   2243:                outl(tp->mtable->csr15dir, ioaddr + CSR15);
                   2244:                outl(tp->mtable->csr15val, ioaddr + CSR15);
1.1.1.3 ! root     2245:        } else if (tp->chip_id != PNIC2)
1.1.1.2   root     2246:                outw(0x0008, ioaddr + CSR15);
1.1.1.3 ! root     2247:        if (tp->chip_id == DC21041)                     /* Trigger NWAY. */
        !          2248:                outl(0xEF01, ioaddr + CSR12);
        !          2249:        else
        !          2250:                outl(0x1301, ioaddr + CSR12);
1.1.1.2   root     2251: }
                   2252: 
1.1.1.3 ! root     2253: static void nway_lnk_change(struct net_device *dev, int csr5)
1.1       root     2254: {
                   2255:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2256:        long ioaddr = dev->base_addr;
                   2257:        int csr12 = inl(ioaddr + CSR12);
                   2258: 
1.1.1.3 ! root     2259:        if (tp->chip_id == PNIC2) {
        !          2260:                if (tp->msg_level & NETIF_MSG_LINK)
        !          2261:                        printk(KERN_INFO"%s: PNIC-2 link status changed, CSR5/12/14 %8.8x"
        !          2262:                                   " %8.8x, %8.8x.\n",
        !          2263:                                   dev->name, csr12, csr5, (int)inl(ioaddr + CSR14));
        !          2264:                dev->if_port = 5;
        !          2265:                tp->lpar = csr12 >> 16;
        !          2266:                tp->nwayset = 1;
        !          2267:                tp->csr6 = 0x01000000 | (tp->csr6 & 0xffff);
        !          2268:                outl(tp->csr6, ioaddr + CSR6);
        !          2269:                return;
        !          2270:        }
        !          2271:        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2272:                printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
1.1.1.3 ! root     2273:                           "%8.8x.\n", dev->name, csr12, csr5, (int)inl(ioaddr + CSR14));
1.1       root     2274: 
1.1.1.2   root     2275:        /* If NWay finished and we have a negotiated partner capability. */
                   2276:        if (tp->nway  &&  !tp->nwayset  &&  (csr12 & 0x7000) == 0x5000) {
                   2277:                int setup_done = 0;
1.1.1.3 ! root     2278:                int negotiated = tp->sym_advertise & (csr12 >> 16);
1.1.1.2   root     2279:                tp->lpar = csr12 >> 16;
                   2280:                tp->nwayset = 1;
                   2281:                if (negotiated & 0x0100)                dev->if_port = 5;
                   2282:                else if (negotiated & 0x0080)   dev->if_port = 3;
                   2283:                else if (negotiated & 0x0040)   dev->if_port = 4;
                   2284:                else if (negotiated & 0x0020)   dev->if_port = 0;
                   2285:                else {
                   2286:                        tp->nwayset = 0;
1.1.1.3 ! root     2287:                        if ((csr12 & 2) == 0  &&  (tp->sym_advertise & 0x0180))
1.1       root     2288:                                dev->if_port = 3;
1.1.1.2   root     2289:                }
                   2290:                tp->full_duplex = (media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
                   2291: 
1.1.1.3 ! root     2292:                if (tp->msg_level & NETIF_MSG_LINK) {
1.1.1.2   root     2293:                        if (tp->nwayset)
                   2294:                                printk(KERN_INFO "%s: Switching to %s based on link "
                   2295:                                           "negotiation %4.4x & %4.4x = %4.4x.\n",
1.1.1.3 ! root     2296:                                           dev->name, medianame[dev->if_port], tp->sym_advertise,
1.1.1.2   root     2297:                                           tp->lpar, negotiated);
                   2298:                        else
                   2299:                                printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
                   2300:                                           " link beat status %4.4x.\n",
                   2301:                                           dev->name, medianame[dev->if_port], csr12);
                   2302:                }
                   2303: 
                   2304:                if (tp->mtable) {
                   2305:                        int i;
                   2306:                        for (i = 0; i < tp->mtable->leafcount; i++)
                   2307:                                if (tp->mtable->mleaf[i].media == dev->if_port) {
                   2308:                                        tp->cur_index = i;
                   2309:                                        select_media(dev, 0);
                   2310:                                        setup_done = 1;
                   2311:                                        break;
                   2312:                                }
                   2313:                }
                   2314:                if ( ! setup_done) {
1.1.1.3 ! root     2315:                        tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000)
        !          2316:                                | (tp->csr6 & 0x20ff);
1.1.1.2   root     2317:                        if (tp->full_duplex)
1.1.1.3 ! root     2318:                                tp->csr6 |= FullDuplex;
1.1.1.2   root     2319:                        outl(1, ioaddr + CSR13);
                   2320:                }
1.1.1.3 ! root     2321: #if 0                                                  /* Restart should not be needed. */
1.1.1.2   root     2322:                outl(tp->csr6 | 0x0000, ioaddr + CSR6);
1.1.1.3 ! root     2323:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2324:                        printk(KERN_DEBUG "%s:  Restarting Tx and Rx, CSR5 is %8.8x.\n",
                   2325:                                   dev->name, inl(ioaddr + CSR5));
                   2326: #endif
1.1.1.3 ! root     2327:                outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
        !          2328:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2329:                        printk(KERN_DEBUG "%s:  Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
1.1.1.3 ! root     2330:                                   dev->name, tp->csr6, (int)inl(ioaddr + CSR6),
        !          2331:                                   (int)inl(ioaddr + CSR12));
1.1.1.2   root     2332:        } else if ((tp->nwayset  &&  (csr5 & 0x08000000)
                   2333:                                && (dev->if_port == 3  ||  dev->if_port == 5)
                   2334:                                && (csr12 & 2) == 2) ||
                   2335:                           (tp->nway && (csr5 & (TPLnkFail)))) {
                   2336:                /* Link blew? Maybe restart NWay. */
                   2337:                del_timer(&tp->timer);
1.1.1.3 ! root     2338:                nway_start(dev);
        !          2339:                tp->timer.expires = jiffies + 3*HZ;
1.1.1.2   root     2340:                add_timer(&tp->timer);
                   2341:        } else if (dev->if_port == 3  ||  dev->if_port == 5) {
1.1.1.3 ! root     2342:                if (tp->msg_level & NETIF_MSG_LINK)     /* TIMER? */
1.1.1.2   root     2343:                        printk(KERN_INFO"%s: 21143 %s link beat %s.\n",
                   2344:                                   dev->name, medianame[dev->if_port],
                   2345:                                   (csr12 & 2) ? "failed" : "good");
                   2346:                if ((csr12 & 2)  &&  ! tp->medialock) {
                   2347:                        del_timer(&tp->timer);
1.1.1.3 ! root     2348:                        nway_start(dev);
        !          2349:                        tp->timer.expires = jiffies + 3*HZ;
1.1.1.2   root     2350:                        add_timer(&tp->timer);
1.1.1.3 ! root     2351:                } else if (dev->if_port == 5)
        !          2352:                        outl(inl(ioaddr + CSR14) & ~0x080, ioaddr + CSR14);
1.1.1.2   root     2353:        } else if (dev->if_port == 0  ||  dev->if_port == 4) {
                   2354:                if ((csr12 & 4) == 0)
                   2355:                        printk(KERN_INFO"%s: 21143 10baseT link beat good.\n",
1.1       root     2356:                                   dev->name);
                   2357:        } else if (!(csr12 & 4)) {              /* 10mbps link beat good. */
1.1.1.3 ! root     2358:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2359:                        printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
                   2360:                                   dev->name);
                   2361:                dev->if_port = 0;
                   2362:        } else if (tp->nwayset) {
1.1.1.3 ! root     2363:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2364:                        printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
                   2365:                                   dev->name, medianame[dev->if_port], tp->csr6);
                   2366:        } else {                /* 100mbps link beat good. */
1.1.1.3 ! root     2367:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2368:                        printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
1.1       root     2369:                                   dev->name);
                   2370:                dev->if_port = 3;
1.1.1.3 ! root     2371:                tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
1.1       root     2372:                outl(0x0003FF7F, ioaddr + CSR14);
                   2373:                outl(0x0301, ioaddr + CSR12);
1.1.1.3 ! root     2374:                outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          2375:                outl(tp->csr6 | RxOn | TxOn, ioaddr + CSR6);
1.1       root     2376:        }
                   2377: }
                   2378: 
                   2379: static void mxic_timer(unsigned long data)
                   2380: {
1.1.1.3 ! root     2381:        struct net_device *dev = (struct net_device *)data;
1.1       root     2382:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2383:        long ioaddr = dev->base_addr;
                   2384:        int next_tick = 60*HZ;
                   2385: 
1.1.1.3 ! root     2386:        if (tp->msg_level & NETIF_MSG_TIMER) {
1.1       root     2387:                printk(KERN_INFO"%s: MXIC negotiation status %8.8x.\n", dev->name,
1.1.1.3 ! root     2388:                           (int)inl(ioaddr + CSR12));
1.1       root     2389:        }
1.1.1.3 ! root     2390:        tp->timer.expires = jiffies + next_tick;
        !          2391:        add_timer(&tp->timer);
1.1       root     2392: }
                   2393: 
1.1.1.3 ! root     2394: static void pnic_do_nway(struct net_device *dev)
1.1.1.2   root     2395: {
                   2396:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2397:        long ioaddr = dev->base_addr;
                   2398:        u32 phy_reg = inl(ioaddr + 0xB8);
                   2399:        u32 new_csr6 = tp->csr6 & ~0x40C40200;
                   2400: 
                   2401:        if (phy_reg & 0x78000000) { /* Ignore baseT4 */
                   2402:                if (phy_reg & 0x20000000)               dev->if_port = 5;
                   2403:                else if (phy_reg & 0x40000000)  dev->if_port = 3;
                   2404:                else if (phy_reg & 0x10000000)  dev->if_port = 4;
                   2405:                else if (phy_reg & 0x08000000)  dev->if_port = 0;
                   2406:                tp->nwayset = 1;
                   2407:                new_csr6 = (dev->if_port & 1) ? 0x01860000 : 0x00420000;
                   2408:                outl(0x32 | (dev->if_port & 1), ioaddr + CSR12);
                   2409:                if (dev->if_port & 1)
                   2410:                        outl(0x1F868, ioaddr + 0xB8);
                   2411:                if (phy_reg & 0x30000000) {
                   2412:                        tp->full_duplex = 1;
1.1.1.3 ! root     2413:                        new_csr6 |= FullDuplex;
1.1.1.2   root     2414:                }
1.1.1.3 ! root     2415:                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2416:                        printk(KERN_DEBUG "%s: PNIC autonegotiated status %8.8x, %s.\n",
                   2417:                                   dev->name, phy_reg, medianame[dev->if_port]);
                   2418:                if (tp->csr6 != new_csr6) {
                   2419:                        tp->csr6 = new_csr6;
1.1.1.3 ! root     2420:                        outl(tp->csr6 | RxOn, ioaddr + CSR6);   /* Restart Tx */
        !          2421:                        outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
1.1.1.2   root     2422:                        dev->trans_start = jiffies;
                   2423:                }
                   2424:        }
                   2425: }
1.1.1.3 ! root     2426: 
        !          2427: static void pnic_lnk_change(struct net_device *dev, int csr5)
1.1.1.2   root     2428: {
                   2429:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2430:        long ioaddr = dev->base_addr;
                   2431:        int phy_reg = inl(ioaddr + 0xB8);
                   2432: 
1.1.1.3 ! root     2433:        if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2434:                printk(KERN_DEBUG "%s: PNIC link changed state %8.8x, CSR5 %8.8x.\n",
                   2435:                           dev->name, phy_reg, csr5);
                   2436:        if (inl(ioaddr + CSR5) & TPLnkFail) {
                   2437:                outl((inl(ioaddr + CSR7) & ~TPLnkFail) | TPLnkPass, ioaddr + CSR7);
                   2438:                if (! tp->nwayset  ||  jiffies - dev->trans_start > 1*HZ) {
                   2439:                        tp->csr6 = 0x00420000 | (tp->csr6 & 0x0000fdff);
                   2440:                        outl(tp->csr6, ioaddr + CSR6);
                   2441:                        outl(0x30, ioaddr + CSR12);
                   2442:                        outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
                   2443:                        dev->trans_start = jiffies;
                   2444:                }
                   2445:        } else if (inl(ioaddr + CSR5) & TPLnkPass) {
                   2446:                pnic_do_nway(dev);
                   2447:                outl((inl(ioaddr + CSR7) & ~TPLnkPass) | TPLnkFail, ioaddr + CSR7);
                   2448:        }
                   2449: }
1.1       root     2450: static void pnic_timer(unsigned long data)
                   2451: {
1.1.1.3 ! root     2452:        struct net_device *dev = (struct net_device *)data;
1.1       root     2453:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2454:        long ioaddr = dev->base_addr;
                   2455:        int next_tick = 60*HZ;
                   2456: 
                   2457:        if (media_cap[dev->if_port] & MediaIsMII) {
1.1.1.2   root     2458:                if (check_duplex(dev) > 0)
                   2459:                        next_tick = 3*HZ;
1.1       root     2460:        } else {
1.1.1.2   root     2461:                int csr12 = inl(ioaddr + CSR12);
                   2462:                int new_csr6 = tp->csr6 & ~0x40C40200;
1.1       root     2463:                int phy_reg = inl(ioaddr + 0xB8);
                   2464:                int csr5 = inl(ioaddr + CSR5);
                   2465: 
1.1.1.3 ! root     2466:                if (tp->msg_level & NETIF_MSG_TIMER)
1.1.1.2   root     2467:                        printk(KERN_DEBUG "%s: PNIC timer PHY status %8.8x, %s "
                   2468:                                   "CSR5 %8.8x.\n",
                   2469:                                   dev->name, phy_reg, medianame[dev->if_port], csr5);
1.1       root     2470:                if (phy_reg & 0x04000000) {     /* Remote link fault */
1.1.1.2   root     2471:                        outl(0x0201F078, ioaddr + 0xB8);
                   2472:                        next_tick = 1*HZ;
                   2473:                        tp->nwayset = 0;
                   2474:                } else if (phy_reg & 0x78000000) { /* Ignore baseT4 */
                   2475:                        pnic_do_nway(dev);
                   2476:                        next_tick = 60*HZ;
                   2477:                } else if (csr5 & TPLnkFail) { /* 100baseTx link beat */
1.1.1.3 ! root     2478:                        if (tp->msg_level & NETIF_MSG_LINK)
1.1       root     2479:                                printk(KERN_DEBUG "%s: %s link beat failed, CSR12 %4.4x, "
                   2480:                                           "CSR5 %8.8x, PHY %3.3x.\n",
                   2481:                                           dev->name, medianame[dev->if_port], csr12,
1.1.1.3 ! root     2482:                                           (int)inl(ioaddr + CSR5), (int)inl(ioaddr + 0xB8));
1.1.1.2   root     2483:                        next_tick = 3*HZ;
1.1       root     2484:                        if (tp->medialock) {
1.1.1.2   root     2485:                        } else if (tp->nwayset  &&  (dev->if_port & 1)) {
                   2486:                                next_tick = 1*HZ;
1.1       root     2487:                        } else if (dev->if_port == 0) {
                   2488:                                dev->if_port = 3;
                   2489:                                outl(0x33, ioaddr + CSR12);
                   2490:                                new_csr6 = 0x01860000;
                   2491:                                outl(0x1F868, ioaddr + 0xB8);
                   2492:                        } else {
                   2493:                                dev->if_port = 0;
                   2494:                                outl(0x32, ioaddr + CSR12);
                   2495:                                new_csr6 = 0x00420000;
                   2496:                                outl(0x1F078, ioaddr + 0xB8);
                   2497:                        }
1.1.1.2   root     2498:                        if (tp->csr6 != new_csr6) {
                   2499:                                tp->csr6 = new_csr6;
1.1.1.3 ! root     2500:                                outl(tp->csr6 | RxOn, ioaddr + CSR6);   /* Restart Tx */
        !          2501:                                outl(tp->csr6 | RxOn | TxOn, ioaddr + CSR6);
1.1.1.2   root     2502:                                dev->trans_start = jiffies;
1.1.1.3 ! root     2503:                                if (tp->msg_level & NETIF_MSG_LINK)
1.1.1.2   root     2504:                                        printk(KERN_INFO "%s: Changing PNIC configuration to %s "
                   2505:                                                   "%s-duplex, CSR6 %8.8x.\n",
                   2506:                                                   dev->name, medianame[dev->if_port],
                   2507:                                                   tp->full_duplex ? "full" : "half", new_csr6);
                   2508:                        }
1.1       root     2509:                }
                   2510:        }
1.1.1.3 ! root     2511:        tp->timer.expires = jiffies + next_tick;
1.1.1.2   root     2512:        add_timer(&tp->timer);
                   2513: }
                   2514: 
                   2515: static void comet_timer(unsigned long data)
                   2516: {
1.1.1.3 ! root     2517:        struct net_device *dev = (struct net_device *)data;
1.1.1.2   root     2518:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2519:        int next_tick = 60*HZ;
                   2520: 
1.1.1.3 ! root     2521:        if (tp->msg_level & NETIF_MSG_TIMER)
1.1.1.2   root     2522:                printk(KERN_DEBUG "%s: Comet link status %4.4x partner capability "
                   2523:                           "%4.4x.\n",
1.1.1.3 ! root     2524:                           dev->name, mdio_read(dev, tp->phys[0], 1),
        !          2525:                           mdio_read(dev, tp->phys[0], 5));
        !          2526:        check_duplex(dev);
        !          2527:        tp->timer.expires = jiffies + next_tick;
1.1       root     2528:        add_timer(&tp->timer);
                   2529: }
                   2530: 
1.1.1.3 ! root     2531: static void tulip_tx_timeout(struct net_device *dev)
1.1       root     2532: {
1.1.1.2   root     2533:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2534:        long ioaddr = dev->base_addr;
1.1       root     2535: 
1.1.1.2   root     2536:        if (media_cap[dev->if_port] & MediaIsMII) {
                   2537:                /* Do nothing -- the media monitor should handle this. */
1.1.1.3 ! root     2538:                int mii_bmsr = mdio_read(dev, tp->phys[0], 1);
        !          2539:                if (tp->msg_level & NETIF_MSG_LINK)
        !          2540:                        printk(KERN_WARNING "%s: Transmit timeout using MII device,"
        !          2541:                                   " status %4.4x.\n",
        !          2542:                                   dev->name, mii_bmsr);
        !          2543:                if ( ! (mii_bmsr & 0x0004)) {           /* No link beat present */
        !          2544:                        dev->trans_start = jiffies;
        !          2545:                        netif_link_down(dev);
        !          2546:                        return;
        !          2547:                }
        !          2548:        } else switch (tp->chip_id) {
        !          2549:        case DC21040:
1.1.1.2   root     2550:                if ( !tp->medialock  &&  inl(ioaddr + CSR12) & 0x0002) {
                   2551:                        dev->if_port = (dev->if_port == 2 ? 0 : 2);
                   2552:                        printk(KERN_INFO "%s: transmit timed out, switching to "
                   2553:                                   "%s.\n",
                   2554:                                   dev->name, medianame[dev->if_port]);
                   2555:                        select_media(dev, 0);
                   2556:                }
                   2557:                dev->trans_start = jiffies;
1.1.1.3 ! root     2558:                return;                                 /* Note: not break! */
        !          2559:        case DC21041: {
1.1.1.2   root     2560:                int csr12 = inl(ioaddr + CSR12);
                   2561: 
                   2562:                printk(KERN_WARNING "%s: 21041 transmit timed out, status %8.8x, "
                   2563:                           "CSR12 %8.8x, CSR13 %8.8x, CSR14 %8.8x, resetting...\n",
1.1.1.3 ! root     2564:                           dev->name, (int)inl(ioaddr + CSR5), csr12,
        !          2565:                           (int)inl(ioaddr + CSR13), (int)inl(ioaddr + CSR14));
1.1.1.2   root     2566:                tp->mediasense = 1;
                   2567:                if ( ! tp->medialock) {
                   2568:                        if (dev->if_port == 1 || dev->if_port == 2)
1.1.1.3 ! root     2569:                                dev->if_port = (csr12 & 0x0004) ? 2 - dev->if_port : 0;
1.1.1.2   root     2570:                        else
                   2571:                                dev->if_port = 1;
                   2572:                        select_media(dev, 0);
                   2573:                }
1.1.1.3 ! root     2574:                break;
        !          2575:        }
        !          2576:        case DC21142:
        !          2577:                if (tp->nwayset) {
        !          2578:                        printk(KERN_WARNING "%s: Transmit timed out, status %8.8x, "
        !          2579:                                   "SIA %8.8x %8.8x %8.8x %8.8x, restarting NWay .\n",
        !          2580:                                   dev->name, (int)inl(ioaddr + CSR5),
        !          2581:                                   (int)inl(ioaddr + CSR12), (int)inl(ioaddr + CSR13),
        !          2582:                                   (int)inl(ioaddr + CSR14), (int)inl(ioaddr + CSR15));
        !          2583:                        nway_start(dev);
        !          2584:                        break;
        !          2585:                }
        !          2586:                /* Fall through. */
        !          2587:        case DC21140: case MX98713: case COMPEX9881:
        !          2588:                printk(KERN_WARNING "%s: %s transmit timed out, status %8.8x, "
1.1.1.2   root     2589:                           "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
1.1.1.3 ! root     2590:                           dev->name, tulip_tbl[tp->chip_id].chip_name,
        !          2591:                           (int)inl(ioaddr + CSR5), (int)inl(ioaddr + CSR12),
        !          2592:                           (int)inl(ioaddr + CSR13), (int)inl(ioaddr + CSR14),
        !          2593:                           (int)inl(ioaddr + CSR15));
1.1.1.2   root     2594:                if ( ! tp->medialock  &&  tp->mtable) {
                   2595:                        do
                   2596:                                --tp->cur_index;
                   2597:                        while (tp->cur_index >= 0
                   2598:                                   && (media_cap[tp->mtable->mleaf[tp->cur_index].media]
                   2599:                                           & MediaIsFD));
1.1.1.3 ! root     2600:                        if (tp->cur_index < 0) {
1.1.1.2   root     2601:                                /* We start again, but should instead look for default. */
                   2602:                                tp->cur_index = tp->mtable->leafcount - 1;
                   2603:                        }
                   2604:                        select_media(dev, 0);
                   2605:                        printk(KERN_WARNING "%s: transmit timed out, switching to %s "
                   2606:                                   "media.\n", dev->name, medianame[dev->if_port]);
                   2607:                }
1.1.1.3 ! root     2608:                break;
        !          2609:        case PNIC2:
        !          2610:                printk(KERN_WARNING "%s: PNIC2 transmit timed out, status %8.8x, "
        !          2611:                           "CSR6/7 %8.8x / %8.8x CSR12 %8.8x, resetting...\n",
        !          2612:                           dev->name, (int)inl(ioaddr + CSR5), (int)inl(ioaddr + CSR6),
        !          2613:                           (int)inl(ioaddr + CSR7), (int)inl(ioaddr + CSR12));
        !          2614:                break;
        !          2615:        default:
1.1.1.2   root     2616:                printk(KERN_WARNING "%s: Transmit timed out, status %8.8x, CSR12 "
                   2617:                           "%8.8x, resetting...\n",
1.1.1.3 ! root     2618:                           dev->name, (int)inl(ioaddr + CSR5), (int)inl(ioaddr + CSR12));
1.1.1.2   root     2619:        }
                   2620: 
1.1.1.3 ! root     2621: #if defined(way_too_many_messages)  &&  defined(__i386__)
        !          2622:        if (tp->msg_level & NETIF_MSG_TXERR) {
1.1.1.2   root     2623:                int i;
                   2624:                for (i = 0; i < RX_RING_SIZE; i++) {
                   2625:                        u8 *buf = (u8 *)(tp->rx_ring[i].buffer1);
                   2626:                        int j;
                   2627:                        printk(KERN_DEBUG "%2d: %8.8x %8.8x %8.8x %8.8x  "
                   2628:                                   "%2.2x %2.2x %2.2x.\n",
                   2629:                                   i, (unsigned int)tp->rx_ring[i].status,
                   2630:                                   (unsigned int)tp->rx_ring[i].length,
                   2631:                                   (unsigned int)tp->rx_ring[i].buffer1,
                   2632:                                   (unsigned int)tp->rx_ring[i].buffer2,
                   2633:                                   buf[0], buf[1], buf[2]);
                   2634:                        for (j = 0; buf[j] != 0xee && j < 1600; j++)
                   2635:                                if (j < 100) printk(" %2.2x", buf[j]);
                   2636:                        printk(" j=%d.\n", j);
                   2637:                }
                   2638:                printk(KERN_DEBUG "  Rx ring %8.8x: ", (int)tp->rx_ring);
                   2639:                for (i = 0; i < RX_RING_SIZE; i++)
                   2640:                        printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
                   2641:                printk("\n" KERN_DEBUG "  Tx ring %8.8x: ", (int)tp->tx_ring);
                   2642:                for (i = 0; i < TX_RING_SIZE; i++)
                   2643:                        printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
                   2644:                printk("\n");
                   2645:        }
                   2646: #endif
                   2647: 
1.1.1.3 ! root     2648:        /* Stop and restart the Tx process.
        !          2649:           The pwr_event approach of empty/init_rings() may be better... */
        !          2650:        outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          2651:        outl(tp->csr6 | RxOn | TxOn, ioaddr + CSR6);
1.1.1.2   root     2652:        /* Trigger an immediate transmit demand. */
                   2653:        outl(0, ioaddr + CSR1);
1.1.1.3 ! root     2654:        outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
1.1       root     2655: 
                   2656:        dev->trans_start = jiffies;
1.1.1.2   root     2657:        tp->stats.tx_errors++;
1.1       root     2658:        return;
                   2659: }
                   2660: 
                   2661: 
                   2662: /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
1.1.1.3 ! root     2663: static void tulip_init_ring(struct net_device *dev)
1.1       root     2664: {
                   2665:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2666:        int i;
                   2667: 
1.1.1.3 ! root     2668:        tp->rx_dead = tp->tx_full = 0;
1.1       root     2669:        tp->cur_rx = tp->cur_tx = 0;
                   2670:        tp->dirty_rx = tp->dirty_tx = 0;
1.1.1.3 ! root     2671: 
        !          2672:        tp->rx_buf_sz = dev->mtu + 18;
        !          2673:        if (tp->rx_buf_sz < PKT_BUF_SZ)
        !          2674:                tp->rx_buf_sz = PKT_BUF_SZ;
1.1       root     2675: 
                   2676:        for (i = 0; i < RX_RING_SIZE; i++) {
1.1.1.2   root     2677:                tp->rx_ring[i].status = 0x00000000;
1.1.1.3 ! root     2678:                tp->rx_ring[i].length = cpu_to_le32(tp->rx_buf_sz);
1.1.1.2   root     2679:                tp->rx_ring[i].buffer2 = virt_to_le32desc(&tp->rx_ring[i+1]);
                   2680:                tp->rx_skbuff[i] = NULL;
1.1       root     2681:        }
                   2682:        /* Mark the last entry as wrapping the ring. */
1.1.1.3 ! root     2683:        tp->rx_ring[i-1].length |= cpu_to_le32(DESC_RING_WRAP);
1.1.1.2   root     2684:        tp->rx_ring[i-1].buffer2 = virt_to_le32desc(&tp->rx_ring[0]);
                   2685: 
                   2686:        for (i = 0; i < RX_RING_SIZE; i++) {
                   2687:                /* Note the receive buffer must be longword aligned.
                   2688:                   dev_alloc_skb() provides 16 byte alignment.  But do *not*
                   2689:                   use skb_reserve() to align the IP header! */
1.1.1.3 ! root     2690:                struct sk_buff *skb = dev_alloc_skb(tp->rx_buf_sz);
1.1.1.2   root     2691:                tp->rx_skbuff[i] = skb;
                   2692:                if (skb == NULL)
                   2693:                        break;
                   2694:                skb->dev = dev;                 /* Mark as being used by this device. */
1.1.1.3 ! root     2695:                tp->rx_ring[i].status = cpu_to_le32(DescOwned);
1.1.1.2   root     2696:                tp->rx_ring[i].buffer1 = virt_to_le32desc(skb->tail);
                   2697:        }
                   2698:        tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
1.1       root     2699: 
                   2700:        /* The Tx buffer descriptor is filled in as needed, but we
                   2701:           do need to clear the ownership bit. */
                   2702:        for (i = 0; i < TX_RING_SIZE; i++) {
                   2703:                tp->tx_skbuff[i] = 0;
                   2704:                tp->tx_ring[i].status = 0x00000000;
1.1.1.2   root     2705:                tp->tx_ring[i].buffer2 = virt_to_le32desc(&tp->tx_ring[i+1]);
1.1       root     2706:        }
1.1.1.2   root     2707:        tp->tx_ring[i-1].buffer2 = virt_to_le32desc(&tp->tx_ring[0]);
1.1       root     2708: }
                   2709: 
                   2710: static int
1.1.1.3 ! root     2711: tulip_start_xmit(struct sk_buff *skb, struct net_device *dev)
1.1       root     2712: {
                   2713:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
1.1.1.3 ! root     2714:        int entry, q_used_cnt;
1.1       root     2715:        u32 flag;
                   2716: 
1.1.1.3 ! root     2717:        /* Block a timer-based transmit from overlapping.  This happens when
        !          2718:           packets are presumed lost, and we use this check the Tx status. */
        !          2719:        if (netif_pause_tx_queue(dev) != 0) {
        !          2720:                /* This watchdog code is redundant with the media monitor timer. */
        !          2721:                if (jiffies - dev->trans_start > TX_TIMEOUT)
        !          2722:                        tulip_tx_timeout(dev);
1.1       root     2723:                return 1;
                   2724:        }
                   2725: 
1.1.1.2   root     2726:        /* Caution: the write order is important here, set the field
                   2727:           with the ownership bits last. */
1.1       root     2728: 
                   2729:        /* Calculate the next Tx descriptor entry. */
                   2730:        entry = tp->cur_tx % TX_RING_SIZE;
1.1.1.3 ! root     2731:        q_used_cnt = tp->cur_tx - tp->dirty_tx;
1.1       root     2732: 
                   2733:        tp->tx_skbuff[entry] = skb;
1.1.1.2   root     2734:        tp->tx_ring[entry].buffer1 = virt_to_le32desc(skb->data);
1.1       root     2735: 
1.1.1.3 ! root     2736:        if (q_used_cnt < TX_QUEUE_LEN/2) {/* Typical path */
1.1.1.2   root     2737:                flag = 0x60000000; /* No interrupt */
1.1.1.3 ! root     2738:        } else if (q_used_cnt == TX_QUEUE_LEN/2) {
1.1.1.2   root     2739:                flag = 0xe0000000; /* Tx-done intr. */
1.1.1.3 ! root     2740:        } else if (q_used_cnt < TX_QUEUE_LEN) {
1.1.1.2   root     2741:                flag = 0x60000000; /* No Tx-done intr. */
                   2742:        } else {                /* Leave room for set_rx_mode() to fill entries. */
                   2743:                tp->tx_full = 1;
                   2744:                flag = 0xe0000000; /* Tx-done intr. */
1.1       root     2745:        }
                   2746:        if (entry == TX_RING_SIZE-1)
1.1.1.2   root     2747:                flag = 0xe0000000 | DESC_RING_WRAP;
1.1       root     2748: 
1.1.1.2   root     2749:        tp->tx_ring[entry].length = cpu_to_le32(skb->len | flag);
                   2750:        tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
1.1       root     2751:        tp->cur_tx++;
1.1.1.2   root     2752:        if ( ! tp->tx_full)
1.1.1.3 ! root     2753:                netif_unpause_tx_queue(dev);
        !          2754:        else {
        !          2755:                netif_stop_tx_queue(dev);
        !          2756:                /* Check for a just-cleared queue race.
        !          2757:                   Note that this code path differs from other drivers because we
        !          2758:                   set the tx_full flag early. */
        !          2759:                if ( ! tp->tx_full)
        !          2760:                        netif_resume_tx_queue(dev);
        !          2761:        }
1.1       root     2762: 
                   2763:        dev->trans_start = jiffies;
1.1.1.2   root     2764:        /* Trigger an immediate transmit demand. */
                   2765:        outl(0, dev->base_addr + CSR1);
1.1       root     2766: 
                   2767:        return 0;
                   2768: }
                   2769: 
                   2770: /* The interrupt handler does all of the Rx thread work and cleans up
                   2771:    after the Tx thread. */
1.1.1.2   root     2772: static void tulip_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
1.1       root     2773: {
1.1.1.3 ! root     2774:        struct net_device *dev = (struct net_device *)dev_instance;
1.1.1.2   root     2775:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2776:        long ioaddr = dev->base_addr;
1.1.1.3 ! root     2777:        int csr5, work_budget = tp->max_interrupt_work;
1.1.1.2   root     2778: 
1.1       root     2779:        do {
                   2780:                csr5 = inl(ioaddr + CSR5);
                   2781:                if ((csr5 & (NormalIntr|AbnormalIntr)) == 0)
                   2782:                        break;
                   2783: 
1.1.1.3 ! root     2784:                if (tp->msg_level & NETIF_MSG_INTR)
        !          2785:                        printk(KERN_DEBUG "%s: interrupt  csr5=%#8.8x new csr5=%#8.8x.\n",
        !          2786:                                   dev->name, csr5, (int)inl(dev->base_addr + CSR5));
        !          2787:                /* Acknowledge all of the current interrupt sources ASAP. */
        !          2788:                outl(csr5 & 0x0001ffff, ioaddr + CSR5);
        !          2789: 
        !          2790:                if (csr5 & (RxIntr | RxNoBuf))
        !          2791:                        work_budget -= tulip_rx(dev);
1.1       root     2792: 
1.1.1.3 ! root     2793:                if (csr5 & (TxNoBuf | TxDied | TxIntr)) {
1.1       root     2794:                        unsigned int dirty_tx;
                   2795: 
                   2796:                        for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0;
                   2797:                                 dirty_tx++) {
                   2798:                                int entry = dirty_tx % TX_RING_SIZE;
1.1.1.2   root     2799:                                int status = le32_to_cpu(tp->tx_ring[entry].status);
1.1       root     2800: 
                   2801:                                if (status < 0)
1.1.1.2   root     2802:                                        break;                  /* It still has not been Txed */
1.1       root     2803:                                /* Check for Rx filter setup frames. */
                   2804:                                if (tp->tx_skbuff[entry] == NULL)
                   2805:                                  continue;
1.1.1.3 ! root     2806: 
1.1       root     2807:                                if (status & 0x8000) {
                   2808:                                        /* There was an major error, log it. */
1.1.1.3 ! root     2809:                                        if (tp->msg_level & NETIF_MSG_TX_ERR)
1.1       root     2810:                                                printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
                   2811:                                                           dev->name, status);
                   2812:                                        tp->stats.tx_errors++;
                   2813:                                        if (status & 0x4104) tp->stats.tx_aborted_errors++;
                   2814:                                        if (status & 0x0C00) tp->stats.tx_carrier_errors++;
                   2815:                                        if (status & 0x0200) tp->stats.tx_window_errors++;
                   2816:                                        if (status & 0x0002) tp->stats.tx_fifo_errors++;
                   2817:                                        if ((status & 0x0080) && tp->full_duplex == 0)
                   2818:                                                tp->stats.tx_heartbeat_errors++;
                   2819: #ifdef ETHER_STATS
                   2820:                                        if (status & 0x0100) tp->stats.collisions16++;
                   2821: #endif
                   2822:                                } else {
1.1.1.3 ! root     2823:                                        if (tp->msg_level & NETIF_MSG_TX_DONE)
        !          2824:                                                printk(KERN_DEBUG "%s: Transmit complete, status "
        !          2825:                                                           "%8.8x.\n", dev->name, status);
1.1       root     2826: #ifdef ETHER_STATS
                   2827:                                        if (status & 0x0001) tp->stats.tx_deferred++;
                   2828: #endif
                   2829: #if LINUX_VERSION_CODE > 0x20127
1.1.1.2   root     2830:                                        tp->stats.tx_bytes += tp->tx_skbuff[entry]->len;
1.1       root     2831: #endif
                   2832:                                        tp->stats.collisions += (status >> 3) & 15;
                   2833:                                        tp->stats.tx_packets++;
                   2834:                                }
                   2835: 
                   2836:                                /* Free the original skb. */
1.1.1.3 ! root     2837:                                dev_free_skb_irq(tp->tx_skbuff[entry]);
1.1       root     2838:                                tp->tx_skbuff[entry] = 0;
                   2839:                        }
                   2840: 
                   2841: #ifndef final_version
                   2842:                        if (tp->cur_tx - dirty_tx > TX_RING_SIZE) {
                   2843:                                printk(KERN_ERR "%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
                   2844:                                           dev->name, dirty_tx, tp->cur_tx, tp->tx_full);
                   2845:                                dirty_tx += TX_RING_SIZE;
                   2846:                        }
                   2847: #endif
                   2848: 
1.1.1.3 ! root     2849:                        if (tp->tx_full && tp->cur_tx - dirty_tx  < TX_QUEUE_LEN - 4) {
1.1       root     2850:                                /* The ring is no longer full, clear tbusy. */
                   2851:                                tp->tx_full = 0;
1.1.1.3 ! root     2852:                                netif_resume_tx_queue(dev);
1.1       root     2853:                        }
                   2854: 
                   2855:                        tp->dirty_tx = dirty_tx;
1.1.1.3 ! root     2856:                }
        !          2857: 
        !          2858:                if (tp->rx_dead) {
        !          2859:                        tulip_rx(dev);
        !          2860:                        if (tp->cur_rx - tp->dirty_rx < RX_RING_SIZE - 3) {
        !          2861:                                printk(KERN_ERR "%s: Restarted Rx at %d / %d.\n",
        !          2862:                                           dev->name, tp->cur_rx, tp->dirty_rx);
        !          2863:                                outl(0, ioaddr + CSR2);         /* Rx poll demand */
        !          2864:                                tp->rx_dead = 0;
1.1       root     2865:                        }
                   2866:                }
                   2867: 
                   2868:                /* Log errors. */
                   2869:                if (csr5 & AbnormalIntr) {      /* Abnormal error summary bit. */
1.1.1.2   root     2870:                        if (csr5 == 0xffffffff)
                   2871:                                break;
1.1       root     2872:                        if (csr5 & TxJabber) tp->stats.tx_errors++;
1.1.1.3 ! root     2873:                        if (csr5 & PCIBusError) {
        !          2874:                                printk(KERN_ERR "%s: PCI Fatal Bus Error, %8.8x.\n",
        !          2875:                                           dev->name, csr5);
        !          2876:                        }
1.1       root     2877:                        if (csr5 & TxFIFOUnderflow) {
                   2878:                                if ((tp->csr6 & 0xC000) != 0xC000)
                   2879:                                        tp->csr6 += 0x4000;     /* Bump up the Tx threshold */
                   2880:                                else
                   2881:                                        tp->csr6 |= 0x00200000;  /* Store-n-forward. */
1.1.1.3 ! root     2882:                                if (tp->msg_level & NETIF_MSG_TX_ERR)
        !          2883:                                        printk(KERN_WARNING "%s: Tx threshold increased, "
        !          2884:                                                   "new CSR6 %x.\n", dev->name, tp->csr6);
        !          2885:                        }
        !          2886:                        if (csr5 & TxDied) {
        !          2887:                                /* This is normal when changing Tx modes. */
        !          2888:                                if (tp->msg_level & NETIF_MSG_LINK)
        !          2889:                                        printk(KERN_WARNING "%s: The transmitter stopped."
        !          2890:                                                   "  CSR5 is %x, CSR6 %x, new CSR6 %x.\n",
        !          2891:                                                   dev->name, csr5, (int)inl(ioaddr + CSR6), tp->csr6);
        !          2892:                        }
        !          2893:                        if (csr5 & (TxDied | TxFIFOUnderflow | PCIBusError)) {
1.1       root     2894:                                /* Restart the transmit process. */
1.1.1.3 ! root     2895:                                outl(tp->csr6 | RxOn, ioaddr + CSR6);
        !          2896:                                outl(tp->csr6 | RxOn | TxOn, ioaddr + CSR6);
1.1       root     2897:                        }
1.1.1.3 ! root     2898:                        if (csr5 & (RxStopped | RxNoBuf)) {
        !          2899:                                /* Missed a Rx frame or mode change. */
1.1       root     2900:                                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
1.1.1.3 ! root     2901:                                if (tp->flags & COMET_MAC_ADDR) {
        !          2902:                                        outl(tp->mc_filter[0], ioaddr + 0xAC);
        !          2903:                                        outl(tp->mc_filter[1], ioaddr + 0xB0);
        !          2904:                                }
        !          2905:                                tulip_rx(dev);
        !          2906:                                if (csr5 & RxNoBuf)
        !          2907:                                        tp->rx_dead = 1;
        !          2908:                                outl(tp->csr6 | RxOn | TxOn, ioaddr + CSR6);
        !          2909:                        }
        !          2910:                        if (csr5 & TimerInt) {
        !          2911:                                if (tp->msg_level & NETIF_MSG_INTR)
        !          2912:                                        printk(KERN_ERR "%s: Re-enabling interrupts, %8.8x.\n",
        !          2913:                                                   dev->name, csr5);
        !          2914:                                outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
1.1       root     2915:                        }
1.1.1.2   root     2916:                        if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)) {
                   2917:                                if (tp->link_change)
                   2918:                                        (tp->link_change)(dev, csr5);
1.1       root     2919:                        }
                   2920:                        /* Clear all error sources, included undocumented ones! */
                   2921:                        outl(0x0800f7ba, ioaddr + CSR5);
1.1.1.2   root     2922:                }
1.1.1.3 ! root     2923:                if (--work_budget < 0) {
        !          2924:                        if (tp->msg_level & NETIF_MSG_DRV)
1.1.1.2   root     2925:                                printk(KERN_WARNING "%s: Too much work during an interrupt, "
1.1.1.3 ! root     2926:                                           "csr5=0x%8.8x.\n", dev->name, csr5);
1.1       root     2927:                        /* Acknowledge all interrupt sources. */
1.1.1.3 ! root     2928:                        outl(0x8001ffff, ioaddr + CSR5);
        !          2929:                        if (tp->flags & HAS_INTR_MITIGATION) {
        !          2930:                                /* Josip Loncaric at ICASE did extensive experimentation
        !          2931:                                   to develop a good interrupt mitigation setting.*/
        !          2932:                                outl(0x8b240000, ioaddr + CSR11);
        !          2933:                        } else {
        !          2934:                                /* Mask all interrupting sources, set timer to re-enable. */
        !          2935:                                outl(((~csr5) & 0x0001ebef) | AbnormalIntr | TimerInt,
        !          2936:                                         ioaddr + CSR7);
        !          2937:                                outl(0x0012, ioaddr + CSR11);
        !          2938:                        }
1.1       root     2939:                        break;
                   2940:                }
                   2941:        } while (1);
                   2942: 
1.1.1.3 ! root     2943:        if (tp->msg_level & NETIF_MSG_INTR)
1.1       root     2944:                printk(KERN_DEBUG "%s: exiting interrupt, csr5=%#4.4x.\n",
1.1.1.3 ! root     2945:                           dev->name, (int)inl(ioaddr + CSR5));
1.1       root     2946: 
                   2947:        return;
                   2948: }
                   2949: 
1.1.1.3 ! root     2950: static int tulip_rx(struct net_device *dev)
1.1       root     2951: {
                   2952:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   2953:        int entry = tp->cur_rx % RX_RING_SIZE;
                   2954:        int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
1.1.1.3 ! root     2955:        int work_done = 0;
1.1       root     2956: 
1.1.1.3 ! root     2957:        if (tp->msg_level & NETIF_MSG_RX_STATUS)
1.1       root     2958:                printk(KERN_DEBUG " In tulip_rx(), entry %d %8.8x.\n", entry,
                   2959:                           tp->rx_ring[entry].status);
1.1.1.2   root     2960:        /* If we own the next entry, it is a new packet. Send it up. */
                   2961:        while ( ! (tp->rx_ring[entry].status & cpu_to_le32(DescOwned))) {
                   2962:                s32 status = le32_to_cpu(tp->rx_ring[entry].status);
                   2963: 
1.1.1.3 ! root     2964:                if (tp->msg_level & NETIF_MSG_RX_STATUS)
1.1.1.2   root     2965:                        printk(KERN_DEBUG "%s: In tulip_rx(), entry %d %8.8x.\n",
                   2966:                                   dev->name, entry, status);
1.1       root     2967:                if (--rx_work_limit < 0)
                   2968:                        break;
1.1.1.2   root     2969:                if ((status & 0x38008300) != 0x0300) {
                   2970:                        if ((status & 0x38000300) != 0x0300) {
                   2971:                                /* Ingore earlier buffers. */
                   2972:                                if ((status & 0xffff) != 0x7fff) {
1.1.1.3 ! root     2973:                                        if (tp->msg_level & NETIF_MSG_RX_ERR)
1.1.1.2   root     2974:                                                printk(KERN_WARNING "%s: Oversized Ethernet frame "
                   2975:                                                           "spanned multiple buffers, status %8.8x!\n",
                   2976:                                                           dev->name, status);
                   2977:                                        tp->stats.rx_length_errors++;
                   2978:                                }
                   2979:                        } else if (status & RxDescFatalErr) {
                   2980:                                /* There was a fatal error. */
1.1.1.3 ! root     2981:                                if (tp->msg_level & NETIF_MSG_RX_ERR)
1.1.1.2   root     2982:                                        printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",
1.1       root     2983:                                                   dev->name, status);
1.1.1.2   root     2984:                                tp->stats.rx_errors++; /* end of a packet.*/
                   2985:                                if (status & 0x0890) tp->stats.rx_length_errors++;
                   2986:                                if (status & 0x0004) tp->stats.rx_frame_errors++;
                   2987:                                if (status & 0x0002) tp->stats.rx_crc_errors++;
                   2988:                                if (status & 0x0001) tp->stats.rx_fifo_errors++;
1.1       root     2989:                        }
                   2990:                } else {
                   2991:                        /* Omit the four octet CRC from the length. */
1.1.1.2   root     2992:                        short pkt_len = ((status >> 16) & 0x7ff) - 4;
1.1       root     2993:                        struct sk_buff *skb;
                   2994: 
1.1.1.2   root     2995: #ifndef final_version
                   2996:                        if (pkt_len > 1518) {
                   2997:                                printk(KERN_WARNING "%s: Bogus packet size of %d (%#x).\n",
                   2998:                                           dev->name, pkt_len, pkt_len);
                   2999:                                pkt_len = 1518;
                   3000:                                tp->stats.rx_length_errors++;
                   3001:                        }
                   3002: #endif
                   3003:                        /* Check if the packet is long enough to accept without copying
                   3004:                           to a minimally-sized skbuff. */
1.1.1.3 ! root     3005:                        if (pkt_len < tp->rx_copybreak
1.1.1.2   root     3006:                                && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1.1       root     3007:                                skb->dev = dev;
                   3008:                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
1.1.1.3 ! root     3009: #if (LINUX_VERSION_CODE >= 0x20100)
1.1.1.2   root     3010:                                eth_copy_and_sum(skb, tp->rx_skbuff[entry]->tail, pkt_len, 0);
1.1       root     3011:                                skb_put(skb, pkt_len);
1.1.1.2   root     3012: #else
                   3013:                                memcpy(skb_put(skb, pkt_len), tp->rx_skbuff[entry]->tail,
                   3014:                                           pkt_len);
1.1       root     3015: #endif
1.1.1.3 ! root     3016:                                work_done++;
        !          3017:                        } else {        /* Pass up the skb already on the Rx ring. */
        !          3018:                                skb_put(skb = tp->rx_skbuff[entry], pkt_len);
1.1       root     3019:                                tp->rx_skbuff[entry] = NULL;
                   3020:                        }
                   3021:                        skb->protocol = eth_type_trans(skb, dev);
                   3022:                        netif_rx(skb);
                   3023:                        dev->last_rx = jiffies;
                   3024:                        tp->stats.rx_packets++;
                   3025: #if LINUX_VERSION_CODE > 0x20127
                   3026:                        tp->stats.rx_bytes += pkt_len;
                   3027: #endif
                   3028:                }
                   3029:                entry = (++tp->cur_rx) % RX_RING_SIZE;
                   3030:        }
                   3031: 
1.1.1.3 ! root     3032:        /* Refill the Rx ring buffers. */
        !          3033:        for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {
        !          3034:                entry = tp->dirty_rx % RX_RING_SIZE;
        !          3035:                if (tp->rx_skbuff[entry] == NULL) {
        !          3036:                        struct sk_buff *skb;
        !          3037:                        skb = tp->rx_skbuff[entry] = dev_alloc_skb(tp->rx_buf_sz);
        !          3038:                        if (skb == NULL) {
        !          3039:                                if (tp->cur_rx - tp->dirty_rx == RX_RING_SIZE)
        !          3040:                                        printk(KERN_ERR "%s: No kernel memory to allocate "
        !          3041:                                                   "receive buffers.\n", dev->name);
        !          3042:                                break;
        !          3043:                        }
        !          3044:                        skb->dev = dev;                 /* Mark as being used by this device. */
        !          3045:                        tp->rx_ring[entry].buffer1 = virt_to_le32desc(skb->tail);
        !          3046:                        work_done++;
        !          3047:                }
        !          3048:                tp->rx_ring[entry].status = cpu_to_le32(DescOwned);
        !          3049:        }
        !          3050: 
        !          3051:        return work_done;
1.1       root     3052: }
                   3053: 
1.1.1.3 ! root     3054: static void empty_rings(struct net_device *dev)
1.1       root     3055: {
                   3056:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   3057:        int i;
                   3058: 
                   3059:        /* Free all the skbuffs in the Rx queue. */
                   3060:        for (i = 0; i < RX_RING_SIZE; i++) {
                   3061:                struct sk_buff *skb = tp->rx_skbuff[i];
                   3062:                tp->rx_skbuff[i] = 0;
                   3063:                tp->rx_ring[i].status = 0;              /* Not owned by Tulip chip. */
                   3064:                tp->rx_ring[i].length = 0;
                   3065:                tp->rx_ring[i].buffer1 = 0xBADF00D0; /* An invalid address. */
                   3066:                if (skb) {
                   3067: #if LINUX_VERSION_CODE < 0x20100
                   3068:                        skb->free = 1;
                   3069: #endif
1.1.1.2   root     3070:                        dev_free_skb(skb);
1.1       root     3071:                }
                   3072:        }
                   3073:        for (i = 0; i < TX_RING_SIZE; i++) {
                   3074:                if (tp->tx_skbuff[i])
1.1.1.2   root     3075:                        dev_free_skb(tp->tx_skbuff[i]);
1.1       root     3076:                tp->tx_skbuff[i] = 0;
                   3077:        }
1.1.1.3 ! root     3078: }
        !          3079: 
        !          3080: static int tulip_close(struct net_device *dev)
        !          3081: {
        !          3082:        long ioaddr = dev->base_addr;
        !          3083:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          3084: 
        !          3085:        netif_stop_tx_queue(dev);
        !          3086: 
        !          3087:        if (tp->msg_level & NETIF_MSG_IFDOWN)
        !          3088:                printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
        !          3089:                           dev->name, (int)inl(ioaddr + CSR5));
1.1       root     3090: 
1.1.1.3 ! root     3091:        /* Disable interrupts by clearing the interrupt mask. */
        !          3092:        outl(0x00000000, ioaddr + CSR7);
        !          3093:        /* Stop the Tx and Rx processes. */
        !          3094:        outl(inl(ioaddr + CSR6) & ~TxOn & ~RxOn, ioaddr + CSR6);
        !          3095:        /* 21040 -- Leave the card in 10baseT state. */
        !          3096:        if (tp->chip_id == DC21040)
        !          3097:                outl(0x00000004, ioaddr + CSR13);
        !          3098: 
        !          3099:        if (inl(ioaddr + CSR6) != 0xffffffff)
        !          3100:                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
        !          3101: 
        !          3102:        del_timer(&tp->timer);
        !          3103: 
        !          3104:        free_irq(dev->irq, dev);
        !          3105: 
        !          3106:        dev->if_port = tp->saved_if_port;
        !          3107: 
        !          3108:        empty_rings(dev);
1.1.1.2   root     3109:        /* Leave the driver in snooze, not sleep, mode. */
                   3110:        if (tp->flags & HAS_PWRDWN)
1.1.1.3 ! root     3111:                pci_write_config_dword(tp->pci_dev, 0x40, 0x40000000);
1.1       root     3112: 
                   3113:        MOD_DEC_USE_COUNT;
                   3114: 
                   3115:        return 0;
                   3116: }
                   3117: 
1.1.1.3 ! root     3118: static struct net_device_stats *tulip_get_stats(struct net_device *dev)
1.1       root     3119: {
                   3120:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   3121:        long ioaddr = dev->base_addr;
1.1.1.3 ! root     3122:        int csr8 = inl(ioaddr + CSR8);
1.1       root     3123: 
1.1.1.3 ! root     3124:        if (netif_running(dev)  &&  csr8 != 0xffffffff)
        !          3125:                tp->stats.rx_missed_errors += (u16)csr8;
1.1       root     3126: 
                   3127:        return &tp->stats;
                   3128: }
                   3129: 
                   3130: #ifdef HAVE_PRIVATE_IOCTL
1.1.1.3 ! root     3131: /* Provide ioctl() calls to examine the MII xcvr state.
        !          3132:    We emulate a MII management registers for chips without MII.
        !          3133:    The two numeric constants are because some clueless person
        !          3134:    changed value for the symbolic name.
        !          3135:  */
        !          3136: static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1.1       root     3137: {
                   3138:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
                   3139:        long ioaddr = dev->base_addr;
                   3140:        u16 *data = (u16 *)&rq->ifr_data;
1.1.1.3 ! root     3141:        u32 *data32 = (void *)&rq->ifr_data;
        !          3142:        unsigned int phy = tp->phys[0];
        !          3143:        unsigned int regnum = data[1];
1.1       root     3144: 
                   3145:        switch(cmd) {
1.1.1.3 ! root     3146:        case 0x8947: case 0x89F0:
        !          3147:                /* SIOCGMIIPHY: Get the address of the PHY in use. */
1.1.1.2   root     3148:                if (tp->mii_cnt)
1.1       root     3149:                        data[0] = phy;
1.1.1.3 ! root     3150:                else if (tp->flags & HAS_NWAY)
1.1       root     3151:                        data[0] = 32;
1.1.1.2   root     3152:                else if (tp->chip_id == COMET)
                   3153:                        data[0] = 1;
1.1       root     3154:                else
                   3155:                        return -ENODEV;
1.1.1.3 ! root     3156:        case 0x8948: case 0x89F1:
        !          3157:                /* SIOCGMIIREG: Read the specified MII register. */
        !          3158:                if (data[0] == 32  &&  (tp->flags & HAS_NWAY)) {
1.1       root     3159:                        int csr12 = inl(ioaddr + CSR12);
                   3160:                        int csr14 = inl(ioaddr + CSR14);
1.1.1.3 ! root     3161:                        switch (regnum) {
        !          3162:                        case 0:
        !          3163:                                if (((csr14<<5) & 0x1000) ||
        !          3164:                                        (dev->if_port == 5 && tp->nwayset))
        !          3165:                                        data[3] = 0x1000;
        !          3166:                                else
        !          3167:                                        data[3] = (media_cap[dev->if_port]&MediaIs100 ? 0x2000 : 0)
        !          3168:                                                | (media_cap[dev->if_port]&MediaIsFD ? 0x0100 : 0);
        !          3169:                                break;
1.1       root     3170:                        case 1:
1.1.1.3 ! root     3171:                                data[3] = 0x1848 + ((csr12&0x7000) == 0x5000 ? 0x20 : 0)
        !          3172:                                        + ((csr12&0x06) == 6 ? 0 : 4);
        !          3173:                                if (tp->chip_id != DC21041)
        !          3174:                                        data[3] |= 0x6048;
1.1       root     3175:                                break;
                   3176:                        case 4: {
1.1.1.3 ! root     3177:                                /* Advertised value, bogus 10baseTx-FD value from CSR6. */
        !          3178:                                data[3] = ((inl(ioaddr + CSR6)>>3)&0x0040)+((csr14>>1)&0x20)+1;
        !          3179:                                if (tp->chip_id != DC21041)
        !          3180:                                         data[3] |= ((csr14>>9)&0x03C0);
1.1       root     3181:                                break;
                   3182:                        }
1.1.1.3 ! root     3183:                        case 5: data[3] = tp->lpar; break;
1.1       root     3184:                        default: data[3] = 0; break;
                   3185:                        }
                   3186:                } else {
1.1.1.3 ! root     3187:                        data[3] = mdio_read(dev, data[0] & 0x1f, regnum);
1.1       root     3188:                }
                   3189:                return 0;
1.1.1.3 ! root     3190:        case 0x8949: case 0x89F2:
        !          3191:                /* SIOCSMIIREG: Write the specified MII register */
1.1.1.2   root     3192:                if (!capable(CAP_NET_ADMIN))
1.1       root     3193:                        return -EPERM;
1.1.1.3 ! root     3194:                if (regnum & ~0x1f)
        !          3195:                        return -EINVAL;
        !          3196:                if (data[0] == phy) {
        !          3197:                        u16 value = data[2];
        !          3198:                        switch (regnum) {
        !          3199:                        case 0: /* Check for autonegotiation on or reset. */
        !          3200:                                tp->full_duplex_lock = (value & 0x9000) ? 0 : 1;
        !          3201:                                if (tp->full_duplex_lock)
        !          3202:                                        tp->full_duplex = (value & 0x0100) ? 1 : 0;
        !          3203:                                break;
        !          3204:                        case 4: tp->mii_advertise = data[2]; break;
        !          3205:                        }
        !          3206:                }
        !          3207:                if (data[0] == 32  &&  (tp->flags & HAS_NWAY)) {
        !          3208:                        u16 value = data[2];
        !          3209:                        if (regnum == 0) {
        !          3210:                                if ((value & 0x1200) == 0x1200)
        !          3211:                                        nway_start(dev);
        !          3212:                        } else if (regnum == 4)
        !          3213:                                tp->sym_advertise = value;
1.1       root     3214:                } else {
1.1.1.3 ! root     3215:                        mdio_write(dev, data[0] & 0x1f, regnum, data[2]);
        !          3216:                }
        !          3217:                return 0;
        !          3218:        case SIOCGPARAMS:
        !          3219:                data32[0] = tp->msg_level;
        !          3220:                data32[1] = tp->multicast_filter_limit;
        !          3221:                data32[2] = tp->max_interrupt_work;
        !          3222:                data32[3] = tp->rx_copybreak;
        !          3223:                data32[4] = inl(ioaddr + CSR11);
        !          3224:                return 0;
        !          3225:        case SIOCSPARAMS:
        !          3226:                if (!capable(CAP_NET_ADMIN))
        !          3227:                        return -EPERM;
        !          3228:                tp->msg_level = data32[0];
        !          3229:                tp->multicast_filter_limit = data32[1];
        !          3230:                tp->max_interrupt_work = data32[2];
        !          3231:                tp->rx_copybreak = data32[3];
        !          3232:                if (tp->flags & HAS_INTR_MITIGATION) {
        !          3233:                        u32 *d = (u32 *)&rq->ifr_data;
        !          3234:                        outl(data32[4], ioaddr + CSR11);
        !          3235:                        printk(KERN_NOTICE "%s: Set interrupt mitigate paramters %8.8x.\n",
        !          3236:                                   dev->name, d[0]);
1.1       root     3237:                }
                   3238:                return 0;
                   3239:        default:
                   3240:                return -EOPNOTSUPP;
                   3241:        }
                   3242: 
                   3243:        return -EOPNOTSUPP;
                   3244: }
                   3245: #endif  /* HAVE_PRIVATE_IOCTL */
                   3246: 
                   3247: /* Set or clear the multicast filter for this adaptor.
                   3248:    Note that we only use exclusion around actually queueing the
                   3249:    new frame, not around filling tp->setup_frame.  This is non-deterministic
                   3250:    when re-entered but still correct. */
                   3251: 
                   3252: /* The little-endian AUTODIN32 ethernet CRC calculation.
                   3253:    N.B. Do not use for bulk data, use a table-based routine instead.
                   3254:    This is common code and should be moved to net/core/crc.c */
                   3255: static unsigned const ethernet_polynomial_le = 0xedb88320U;
1.1.1.2   root     3256: static inline u32 ether_crc_le(int length, unsigned char *data)
1.1       root     3257: {
1.1.1.2   root     3258:        u32 crc = 0xffffffff;   /* Initial value. */
1.1       root     3259:        while(--length >= 0) {
                   3260:                unsigned char current_octet = *data++;
                   3261:                int bit;
                   3262:                for (bit = 8; --bit >= 0; current_octet >>= 1) {
                   3263:                        if ((crc ^ current_octet) & 1) {
                   3264:                                crc >>= 1;
                   3265:                                crc ^= ethernet_polynomial_le;
                   3266:                        } else
                   3267:                                crc >>= 1;
                   3268:                }
                   3269:        }
                   3270:        return crc;
                   3271: }
1.1.1.2   root     3272: static unsigned const ethernet_polynomial = 0x04c11db7U;
                   3273: static inline u32 ether_crc(int length, unsigned char *data)
                   3274: {
1.1.1.3 ! root     3275:        int crc = -1;
1.1.1.2   root     3276: 
1.1.1.3 ! root     3277:        while(--length >= 0) {
1.1.1.2   root     3278:                unsigned char current_octet = *data++;
                   3279:                int bit;
                   3280:                for (bit = 0; bit < 8; bit++, current_octet >>= 1)
                   3281:                        crc = (crc << 1) ^
                   3282:                                ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1.1.1.3 ! root     3283:        }
        !          3284:        return crc;
1.1.1.2   root     3285: }
1.1       root     3286: 
1.1.1.3 ! root     3287: static void set_rx_mode(struct net_device *dev)
1.1       root     3288: {
1.1.1.2   root     3289:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
1.1       root     3290:        long ioaddr = dev->base_addr;
                   3291:        int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
                   3292: 
                   3293:        tp->csr6 &= ~0x00D5;
                   3294:        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
1.1.1.3 ! root     3295:                tp->csr6 |= AcceptAllMulticast | AcceptAllPhys;
        !          3296:                csr6 |= AcceptAllMulticast | AcceptAllPhys;
1.1       root     3297:                /* Unconditionally log net taps. */
                   3298:                printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name);
1.1.1.3 ! root     3299:        } else if ((dev->mc_count > tp->multicast_filter_limit)  ||
        !          3300:                           (dev->flags & IFF_ALLMULTI)) {
1.1.1.2   root     3301:                /* Too many to filter well -- accept all multicasts. */
1.1.1.3 ! root     3302:                tp->csr6 |= AcceptAllMulticast;
        !          3303:                csr6 |= AcceptAllMulticast;
1.1.1.2   root     3304:        } else  if (tp->flags & MC_HASH_ONLY) {
                   3305:                /* Some work-alikes have only a 64-entry hash filter table. */
                   3306:                /* Should verify correctness on big-endian/__powerpc__ */
                   3307:                struct dev_mc_list *mclist;
                   3308:                int i;
1.1.1.3 ! root     3309:                if (dev->mc_count > tp->multicast_filter_limit) {
        !          3310:                        tp->csr6 |= AcceptAllMulticast;
        !          3311:                        csr6 |= AcceptAllMulticast;
1.1.1.2   root     3312:                } else {
1.1.1.3 ! root     3313:                        u32 mc_filter[2] = {0, 0};               /* Multicast hash filter */
        !          3314:                        int filterbit;
1.1.1.2   root     3315:                        for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1.1.1.3 ! root     3316:                                 i++, mclist = mclist->next) {
        !          3317:                                if (tp->flags & COMET_MAC_ADDR)
        !          3318:                                        filterbit = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
        !          3319:                                else
        !          3320:                                        filterbit = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
        !          3321:                                filterbit &= 0x3f;
        !          3322:                                set_bit(filterbit, mc_filter);
        !          3323:                                if (tp->msg_level & NETIF_MSG_RXFILTER)
        !          3324:                                        printk(KERN_INFO "%s: Added filter for %2.2x:%2.2x:%2.2x:"
        !          3325:                                                   "%2.2x:%2.2x:%2.2x  %8.8x bit %d.\n", dev->name,
        !          3326:                                                   mclist->dmi_addr[0], mclist->dmi_addr[1],
        !          3327:                                                   mclist->dmi_addr[2], mclist->dmi_addr[3],
        !          3328:                                                   mclist->dmi_addr[4], mclist->dmi_addr[5],
        !          3329:                                                   ether_crc(ETH_ALEN, mclist->dmi_addr), filterbit);
        !          3330:                        }
        !          3331:                        if (mc_filter[0] == tp->mc_filter[0]  &&
        !          3332:                                mc_filter[1] == tp->mc_filter[1])
        !          3333:                                ;                               /* No change. */
        !          3334:                        else if (tp->flags & IS_ASIX) {
1.1.1.2   root     3335:                                outl(2, ioaddr + CSR13);
                   3336:                                outl(mc_filter[0], ioaddr + CSR14);
                   3337:                                outl(3, ioaddr + CSR13);
                   3338:                                outl(mc_filter[1], ioaddr + CSR14);
1.1.1.3 ! root     3339:                        } else if (tp->flags & COMET_MAC_ADDR) {
1.1.1.2   root     3340:                                outl(mc_filter[0], ioaddr + 0xAC);
                   3341:                                outl(mc_filter[1], ioaddr + 0xB0);
                   3342:                        }
1.1.1.3 ! root     3343:                        tp->mc_filter[0] = mc_filter[0];
        !          3344:                        tp->mc_filter[1] = mc_filter[1];
1.1.1.2   root     3345:                }
1.1       root     3346:        } else {
1.1.1.2   root     3347:                u16 *eaddrs, *setup_frm = tp->setup_frame;
1.1       root     3348:                struct dev_mc_list *mclist;
1.1.1.2   root     3349:                u32 tx_flags = 0x08000000 | 192;
1.1       root     3350:                int i;
                   3351: 
1.1.1.2   root     3352:                /* Note that only the low-address shortword of setup_frame is valid!
                   3353:                   The values are doubled for big-endian architectures. */
1.1       root     3354:                if (dev->mc_count > 14) { /* Must use a multicast hash table. */
1.1.1.2   root     3355:                        u16 hash_table[32];
                   3356:                        tx_flags = 0x08400000 | 192;            /* Use hash filter. */
                   3357:                        memset(hash_table, 0, sizeof(hash_table));
1.1.1.3 ! root     3358:                        set_bit(255, hash_table);                       /* Broadcast entry */
1.1.1.2   root     3359:                        /* This should work on big-endian machines as well. */
                   3360:                        for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
                   3361:                                 i++, mclist = mclist->next)
                   3362:                                set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
                   3363:                                                hash_table);
1.1.1.3 ! root     3364:                        for (i = 0; i < 32; i++) {
        !          3365:                                *setup_frm++ = hash_table[i];
        !          3366:                                *setup_frm++ = hash_table[i];
        !          3367:                        }
1.1.1.2   root     3368:                        setup_frm = &tp->setup_frame[13*6];
1.1       root     3369:                } else {
1.1.1.2   root     3370:                        /* We have <= 14 addresses so we can use the wonderful
                   3371:                           16 address perfect filtering of the Tulip. */
                   3372:                        for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
                   3373:                                 i++, mclist = mclist->next) {
                   3374:                                eaddrs = (u16 *)mclist->dmi_addr;
1.1.1.3 ! root     3375:                                *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
        !          3376:                                *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
        !          3377:                                *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1.1.1.2   root     3378:                        }
                   3379:                        /* Fill the unused entries with the broadcast address. */
                   3380:                        memset(setup_frm, 0xff, (15-i)*12);
                   3381:                        setup_frm = &tp->setup_frame[15*6];
1.1       root     3382:                }
1.1.1.2   root     3383:                /* Fill the final entry with our physical address. */
1.1       root     3384:                eaddrs = (u16 *)dev->dev_addr;
1.1.1.3 ! root     3385:                *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
        !          3386:                *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
        !          3387:                *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
1.1       root     3388:                /* Now add this frame to the Tx list. */
                   3389:                if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
                   3390:                        /* Same setup recently queued, we need not add it. */
                   3391:                } else {
                   3392:                        unsigned long flags;
                   3393:                        unsigned int entry;
1.1.1.2   root     3394: 
1.1.1.3 ! root     3395:                        spin_lock_irqsave(&tp->mii_lock, flags);
1.1       root     3396:                        entry = tp->cur_tx++ % TX_RING_SIZE;
                   3397: 
                   3398:                        if (entry != 0) {
                   3399:                                /* Avoid a chip errata by prefixing a dummy entry. */
                   3400:                                tp->tx_skbuff[entry] = 0;
                   3401:                                tp->tx_ring[entry].length =
1.1.1.3 ! root     3402:                                        (entry == TX_RING_SIZE-1) ? cpu_to_le32(DESC_RING_WRAP):0;
1.1       root     3403:                                tp->tx_ring[entry].buffer1 = 0;
1.1.1.2   root     3404:                                tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
1.1       root     3405:                                entry = tp->cur_tx++ % TX_RING_SIZE;
                   3406:                        }
                   3407: 
                   3408:                        tp->tx_skbuff[entry] = 0;
                   3409:                        /* Put the setup frame on the Tx list. */
                   3410:                        if (entry == TX_RING_SIZE-1)
1.1.1.2   root     3411:                                tx_flags |= DESC_RING_WRAP;             /* Wrap ring. */
                   3412:                        tp->tx_ring[entry].length = cpu_to_le32(tx_flags);
                   3413:                        tp->tx_ring[entry].buffer1 = virt_to_le32desc(tp->setup_frame);
                   3414:                        tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
1.1       root     3415:                        if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2) {
1.1.1.3 ! root     3416:                                netif_stop_tx_queue(dev);
1.1       root     3417:                                tp->tx_full = 1;
                   3418:                        }
1.1.1.3 ! root     3419:                        spin_unlock_irqrestore(&tp->mii_lock, flags);
1.1       root     3420:                        /* Trigger an immediate transmit demand. */
                   3421:                        outl(0, ioaddr + CSR1);
                   3422:                }
                   3423:        }
1.1.1.3 ! root     3424:        outl(csr6, ioaddr + CSR6);
1.1       root     3425: }
                   3426: 
1.1.1.3 ! root     3427: 
        !          3428: static int tulip_pwr_event(void *dev_instance, int event)
        !          3429: {
        !          3430:        struct net_device *dev = dev_instance;
        !          3431:        struct tulip_private *tp = (struct tulip_private *)dev->priv;
        !          3432:        long ioaddr = dev->base_addr;
        !          3433:        if (tp->msg_level & NETIF_MSG_LINK)
        !          3434:                printk("%s: Handling power event %d.\n", dev->name, event);
        !          3435:        switch(event) {
        !          3436:        case DRV_ATTACH:
        !          3437:                MOD_INC_USE_COUNT;
        !          3438:                break;
        !          3439:        case DRV_SUSPEND: {
        !          3440:                int csr6 = inl(ioaddr + CSR6);
        !          3441:                /* Disable interrupts, stop the chip, gather stats. */
        !          3442:                if (csr6 != 0xffffffff) {
        !          3443:                        int csr8 = inl(ioaddr + CSR8);
        !          3444:                        outl(0x00000000, ioaddr + CSR7);
        !          3445:                        outl(csr6 & ~TxOn & ~RxOn, ioaddr + CSR6);
        !          3446:                        tp->stats.rx_missed_errors += (unsigned short)csr8;
        !          3447:                }
        !          3448:                empty_rings(dev);
        !          3449:                /* Put the 21143 into sleep mode. */
        !          3450:                if (tp->flags & HAS_PWRDWN)
        !          3451:                        pci_write_config_dword(tp->pci_dev, 0x40,0x80000000);
        !          3452:                break;
        !          3453:        }
        !          3454:        case DRV_RESUME:
        !          3455:                if (tp->flags & HAS_PWRDWN)
        !          3456:                        pci_write_config_dword(tp->pci_dev, 0x40, 0x0000);
        !          3457:                outl(tp->csr0, ioaddr + CSR0);
        !          3458:                tulip_init_ring(dev);
        !          3459:                outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3);
        !          3460:                outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4);
        !          3461:                if (tp->mii_cnt) {
        !          3462:                        dev->if_port = 11;
        !          3463:                        if (tp->mtable  &&  tp->mtable->has_mii)
        !          3464:                                select_media(dev, 1);
        !          3465:                        tp->csr6 = 0x820E0000;
        !          3466:                        dev->if_port = 11;
        !          3467:                        outl(0x0000, ioaddr + CSR13);
        !          3468:                        outl(0x0000, ioaddr + CSR14);
        !          3469:                } else if (! tp->medialock)
        !          3470:                        nway_start(dev);
        !          3471:                else
        !          3472:                        select_media(dev, 1);
        !          3473:                outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
        !          3474:                outl(tp->csr6 | TxOn | RxOn, ioaddr + CSR6);
        !          3475:                outl(0, ioaddr + CSR2);         /* Rx poll demand */
        !          3476:                set_rx_mode(dev);
        !          3477:                break;
        !          3478:        case DRV_DETACH: {
        !          3479:                struct net_device **devp, **next;
        !          3480:                if (dev->flags & IFF_UP) {
        !          3481:                        printk(KERN_ERR "%s: Tulip CardBus interface was detached while "
        !          3482:                                   "still active.\n", dev->name);
        !          3483:                        dev_close(dev);
        !          3484:                        dev->flags &= ~(IFF_UP|IFF_RUNNING);
        !          3485:                }
        !          3486:                if (tp->msg_level & NETIF_MSG_DRV)
        !          3487:                        printk(KERN_DEBUG "%s: Unregistering device.\n", dev->name);
        !          3488:                unregister_netdev(dev);
        !          3489: #ifdef USE_IO_OPS
        !          3490:                release_region(dev->base_addr, pci_id_tbl[tp->chip_id].io_size);
        !          3491: #else
        !          3492:                iounmap((char *)dev->base_addr);
        !          3493: #endif
        !          3494:                for (devp = &root_tulip_dev; *devp; devp = next) {
        !          3495:                        next = &((struct tulip_private *)(*devp)->priv)->next_module;
        !          3496:                        if (*devp == dev) {
        !          3497:                                *devp = *next;
        !          3498:                                break;
        !          3499:                        }
        !          3500:                }
        !          3501:                if (tp->priv_addr)
        !          3502:                        kfree(tp->priv_addr);
        !          3503:                kfree(dev);
        !          3504:                MOD_DEC_USE_COUNT;
        !          3505:                break;
        !          3506:        }
        !          3507:        default:
        !          3508:                break;
        !          3509:        }
        !          3510: 
        !          3511:        return 0;
        !          3512: }
        !          3513: 
1.1       root     3514: #ifdef CARDBUS
                   3515: 
                   3516: #include <pcmcia/driver_ops.h>
                   3517: 
                   3518: static dev_node_t *tulip_attach(dev_locator_t *loc)
                   3519: {
1.1.1.3 ! root     3520:        struct net_device *dev;
        !          3521:        long ioaddr;
        !          3522:        struct pci_dev *pdev;
1.1.1.2   root     3523:        u8 bus, devfn, irq;
1.1.1.3 ! root     3524:        u32 dev_id;
        !          3525:        u32 pciaddr;
        !          3526:        int i, chip_id = 4;                     /* DC21143 */
1.1       root     3527: 
                   3528:        if (loc->bus != LOC_PCI) return NULL;
                   3529:        bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
                   3530:        printk(KERN_INFO "tulip_attach(bus %d, function %d)\n", bus, devfn);
1.1.1.3 ! root     3531:        pdev = pci_find_slot(bus, devfn);
        !          3532: #ifdef USE_IO_OPS
        !          3533:        pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &pciaddr);
        !          3534:        ioaddr = pciaddr & PCI_BASE_ADDRESS_IO_MASK;
        !          3535: #else
        !          3536:        pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1, &pciaddr);
        !          3537:        ioaddr = (long)ioremap(pciaddr & PCI_BASE_ADDRESS_MEM_MASK,
        !          3538:                                                   pci_id_tbl[DC21142].io_size);
        !          3539: #endif
        !          3540:        pci_read_config_dword(pdev, 0, &dev_id);
        !          3541:        pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &irq);
        !          3542:        if (ioaddr == 0 || irq == 0) {
        !          3543:                printk(KERN_ERR "The Tulip CardBus Ethernet interface at %d/%d was "
        !          3544:                           "not assigned an %s.\n"
        !          3545:                           KERN_ERR "  It will not be activated.\n",
        !          3546:                           bus, devfn, ioaddr == 0 ? "address" : "IRQ");
        !          3547:                return NULL;
        !          3548:        }
        !          3549:        for (i = 0; pci_id_tbl[i].id.pci; i++) {
        !          3550:                if (pci_id_tbl[i].id.pci == (dev_id & pci_id_tbl[i].id.pci_mask)) {
        !          3551:                        chip_id = i; break;
        !          3552:                }
        !          3553:        }
        !          3554:        dev = tulip_probe1(pdev, NULL, ioaddr, irq, chip_id, 0);
1.1       root     3555:        if (dev) {
                   3556:                dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
                   3557:                strcpy(node->dev_name, dev->name);
                   3558:                node->major = node->minor = 0;
                   3559:                node->next = NULL;
                   3560:                MOD_INC_USE_COUNT;
                   3561:                return node;
                   3562:        }
                   3563:        return NULL;
                   3564: }
                   3565: 
1.1.1.2   root     3566: static void tulip_suspend(dev_node_t *node)
                   3567: {
1.1.1.3 ! root     3568:        struct net_device **devp, **next;
1.1.1.2   root     3569:        printk(KERN_INFO "tulip_suspend(%s)\n", node->dev_name);
                   3570:        for (devp = &root_tulip_dev; *devp; devp = next) {
                   3571:                next = &((struct tulip_private *)(*devp)->priv)->next_module;
1.1.1.3 ! root     3572:                if (strcmp((*devp)->name, node->dev_name) == 0) {
        !          3573:                        tulip_pwr_event(*devp, DRV_SUSPEND);
        !          3574:                        break;
1.1.1.2   root     3575:                }
                   3576:        }
                   3577: }
                   3578: 
                   3579: static void tulip_resume(dev_node_t *node)
                   3580: {
1.1.1.3 ! root     3581:        struct net_device **devp, **next;
1.1.1.2   root     3582:        printk(KERN_INFO "tulip_resume(%s)\n", node->dev_name);
                   3583:        for (devp = &root_tulip_dev; *devp; devp = next) {
                   3584:                next = &((struct tulip_private *)(*devp)->priv)->next_module;
1.1.1.3 ! root     3585:                if (strcmp((*devp)->name, node->dev_name) == 0) {
        !          3586:                        tulip_pwr_event(*devp, DRV_RESUME);
        !          3587:                        break;
        !          3588:                }
1.1.1.2   root     3589:        }
                   3590: }
                   3591: 
1.1       root     3592: static void tulip_detach(dev_node_t *node)
                   3593: {
1.1.1.3 ! root     3594:        struct net_device **devp, **next;
1.1       root     3595:        printk(KERN_INFO "tulip_detach(%s)\n", node->dev_name);
                   3596:        for (devp = &root_tulip_dev; *devp; devp = next) {
                   3597:                next = &((struct tulip_private *)(*devp)->priv)->next_module;
                   3598:                if (strcmp((*devp)->name, node->dev_name) == 0) break;
                   3599:        }
                   3600:        if (*devp) {
1.1.1.3 ! root     3601:                struct tulip_private *tp = (struct tulip_private *)(*devp)->priv;
1.1       root     3602:                unregister_netdev(*devp);
1.1.1.3 ! root     3603: #ifdef USE_IO_OPS
        !          3604:                release_region((*devp)->base_addr, pci_id_tbl[DC21142].io_size);
        !          3605: #else
        !          3606:                iounmap((char *)(*devp)->base_addr);
        !          3607: #endif
1.1       root     3608:                kfree(*devp);
1.1.1.3 ! root     3609:                if (tp->priv_addr)
        !          3610:                        kfree(tp->priv_addr);
1.1       root     3611:                *devp = *next;
                   3612:                kfree(node);
                   3613:                MOD_DEC_USE_COUNT;
                   3614:        }
                   3615: }
                   3616: 
                   3617: struct driver_operations tulip_ops = {
1.1.1.2   root     3618:        "tulip_cb", tulip_attach, tulip_suspend, tulip_resume, tulip_detach
1.1       root     3619: };
                   3620: 
                   3621: #endif  /* Cardbus support */
                   3622: 
                   3623: 
                   3624: #ifdef MODULE
1.1.1.2   root     3625: int init_module(void)
1.1       root     3626: {
1.1.1.3 ! root     3627:        if (debug >= NETIF_MSG_DRV)     /* Emit version even if no cards detected. */
        !          3628:                printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
1.1       root     3629: #ifdef CARDBUS
                   3630:        register_driver(&tulip_ops);
                   3631:        return 0;
                   3632: #else
1.1.1.3 ! root     3633:        return pci_drv_register(&tulip_drv_id, NULL);
1.1       root     3634: #endif
1.1.1.3 ! root     3635:        reverse_probe = 0;                      /* Not used. */
1.1       root     3636: }
                   3637: 
1.1.1.2   root     3638: void cleanup_module(void)
1.1       root     3639: {
1.1.1.3 ! root     3640:        struct net_device *next_dev;
1.1       root     3641: 
                   3642: #ifdef CARDBUS
                   3643:        unregister_driver(&tulip_ops);
1.1.1.3 ! root     3644: #else
        !          3645:        pci_drv_unregister(&tulip_drv_id);
1.1       root     3646: #endif
                   3647: 
                   3648:        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
                   3649:        while (root_tulip_dev) {
1.1.1.3 ! root     3650:                struct tulip_private *tp = (struct tulip_private*)root_tulip_dev->priv;
1.1       root     3651:                unregister_netdev(root_tulip_dev);
1.1.1.3 ! root     3652: #ifdef USE_IO_OPS
1.1.1.2   root     3653:                release_region(root_tulip_dev->base_addr,
1.1.1.3 ! root     3654:                                           pci_id_tbl[tp->chip_id].io_size);
        !          3655: #else
        !          3656:                iounmap((char *)root_tulip_dev->base_addr);
        !          3657: #endif
        !          3658:                next_dev = tp->next_module;
        !          3659:                if (tp->priv_addr)
        !          3660:                        kfree(tp->priv_addr);
1.1       root     3661:                kfree(root_tulip_dev);
                   3662:                root_tulip_dev = next_dev;
                   3663:        }
                   3664: }
1.1.1.3 ! root     3665: #else
        !          3666: int tulip_probe(struct net_device *dev)
        !          3667: {
        !          3668:        if (pci_drv_register(&tulip_drv_id, dev) < 0)
        !          3669:                return -ENODEV;
        !          3670:        printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
        !          3671:        return 0;
        !          3672:        reverse_probe = 0;                      /* Not used. */
        !          3673: }
1.1       root     3674: #endif  /* MODULE */
                   3675: 
                   3676: /*
                   3677:  * Local variables:
1.1.1.3 ! root     3678:  *  compile-command: "make KERNVER=`uname -r` tulip.o"
        !          3679:  *  compile-cmd: "gcc -DMODULE -Wall -Wstrict-prototypes -O6 -c tulip.c"
        !          3680:  *  cardbus-compile-command: "gcc -DCARDBUS -DMODULE -Wall -Wstrict-prototypes -O6 -c tulip.c -o tulip_cb.o -I/usr/src/pcmcia/include/"
1.1       root     3681:  *  c-indent-level: 4
                   3682:  *  c-basic-offset: 4
                   3683:  *  tab-width: 4
                   3684:  * End:
                   3685:  */

unix.superglobalmegacorp.com

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