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