1 /* -*- Mode:C; c-basic-offset:4; -*- */
4 Tulip and clone Etherboot Driver
6 By Marty Connor (mdc@thinguin.org)
7 Copyright (C) 2001 Entity Cyber, Inc.
9 This software may be used and distributed according to the terms
10 of the GNU Public License, incorporated herein by reference.
12 As of April 2001 this driver should support most tulip cards that
13 the Linux tulip driver supports because Donald Becker's Linux media
14 detection code is now included.
16 Based on Ken Yap's Tulip Etherboot Driver and Donald Becker's
17 Linux Tulip Driver. Supports N-Way speed auto-configuration on
18 MX98715, MX98715A and MX98725. Support inexpensive PCI 10/100 cards
19 based on the Macronix MX987x5 chip, such as the SOHOware Fast
20 model SFA110A, and the LinkSYS model LNE100TX. The NetGear
21 model FA310X, based on the LC82C168 chip is supported.
22 The TRENDnet TE100-PCIA NIC which uses a genuine Intel 21143-PD
23 chipset is supported. Also, Davicom DM9102's.
25 Documentation and source code used:
26 Source for Etherboot driver at
27 http://etherboot.sourceforge.net/
28 MX98715A Data Sheet and MX98715A Application Note
29 on http://www.macronix.com/ (PDF format files)
30 Source for Linux tulip driver at
31 http://cesdis.gsfc.nasa.gov/linux/drivers/tulip.html
33 Adapted by Ken Yap from
34 FreeBSD netboot DEC 21143 driver
38 Some code fragments were taken from verious places, Ken Yap's
39 etherboot, FreeBSD's if_de.c, and various Linux related files.
40 DEC's manuals for the 21143 and SROM format were very helpful.
41 The Linux de driver development page has a number of links to
42 useful related information. Have a look at:
43 ftp://cesdis.gsfc.nasa.gov/pub/linux/drivers/tulip-devel.html
46 /*********************************************************************/
47 /* Revision History */
48 /*********************************************************************/
51 08 Feb 2005 Ramesh Chander chhabaramesh at yahoo.co.in added table entries
52 for SGThomson STE10/100A
53 07 Sep 2003 timlegge Multicast Support Added
54 11 Apr 2001 mdc [patch to etherboot 4.7.24]
55 Major rewrite to include Linux tulip driver media detection
56 code. This driver should support a lot more cards now.
57 16 Jul 2000 mdc 0.75b11
58 Added support for ADMtek 0985 Centaur-P, a "Comet" tulip clone
59 which is used on the LinkSYS LNE100TX v4.x cards. We already
60 support LNE100TX v2.0 cards, which use a different controller.
62 Added test of status after receiving a packet from the card.
63 Also uncommented the tulip_disable routine. Stray packets
64 seemed to be causing problems.
66 29 Feb 2000 mdc 0.75b7
67 Increased reset delay to 3 seconds because Macronix cards seem to
68 need more reset time before card comes back to a usable state.
69 26 Feb 2000 mdc 0.75b6
70 Added a 1 second delay after initializing the transmitter because
71 some cards seem to need the time or they drop the first packet
73 23 Feb 2000 mdc 0.75b5
74 removed udelay code and used currticks() for more reliable delay
75 code in reset pause and sanity timeouts. Added function prototypes
76 and TX debugging code.
77 21 Feb 2000 mdc patch to Etherboot 4.4.3
78 Incorporated patches from Bob Edwards and Paul Mackerras of
79 Linuxcare's OZLabs to deal with inefficiencies in tulip_transmit
80 and udelay. We now wait for packet transmission to complete
82 04 Feb 2000 Robert.Edwards@anu.edu.au patch to Etherboot 4.4.2
83 patch to tulip.c that implements the automatic selection of the MII
84 interface on cards using the Intel/DEC 21143 reference design, in
85 particular, the TRENDnet TE100-PCIA NIC which uses a genuine Intel
87 11 Jan 2000 mdc 0.75b4
88 Added support for NetGear FA310TX card based on the LC82C168
89 chip. This should also support Lite-On LC82C168 boards.
90 Added simple MII support. Re-arranged code to better modularize
92 04 Dec 1999 mdc 0.75b3
93 Added preliminary support for LNE100TX PCI cards. Should work for
94 PNIC2 cards. No MII support, but single interface (RJ45) tulip
95 cards seem to not care.
96 03 Dec 1999 mdc 0.75b2
97 Renamed from mx987x5 to tulip, merged in original tulip init code
98 from tulip.c to support other tulip compatible cards.
99 02 Dec 1999 mdc 0.75b1
100 Released Beta MX987x5 Driver for code review and testing to netboot
101 and thinguin mailing lists.
105 /*********************************************************************/
107 /*********************************************************************/
109 #include "etherboot.h"
111 #include <gpxe/pci.h>
113 /* User settable parameters */
116 #undef TULIP_DEBUG_WHERE
118 static int tulip_debug = 2; /* 1 normal messages, 0 quiet .. 7 verbose. */
121 #define TX_TIME_OUT 2*TICKS_PER_SEC
123 /* helpful macros if on a big_endian machine for changing byte order.
124 not strictly needed on Intel */
125 #define get_unaligned(ptr) (*(ptr))
126 #define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
127 #define get_u16(ptr) (*(u16 *)(ptr))
128 #define virt_to_le32desc(addr) virt_to_bus(addr)
130 #define TULIP_IOTYPE PCI_USES_MASTER | PCI_USES_IO | PCI_ADDR0
131 #define TULIP_SIZE 0x80
133 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
134 to support a pre-NWay full-duplex signaling mechanism using short frames.
135 No one knows what it should be, but if left at its default value some
136 10base2(!) packets trigger a full-duplex-request interrupt. */
137 #define FULL_DUPLEX_MAGIC 0x6969
139 static const int csr0 = 0x01A00000 | 0x8000;
141 /* The possible media types that can be set in options[] are: */
142 #define MEDIA_MASK 31
143 static const char * const medianame[32] = {
144 "10baseT", "10base2", "AUI", "100baseTx",
145 "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
146 "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
147 "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
148 "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
151 /* This much match tulip_tbl[]! Note 21142 == 21143. */
153 DC21040=0, DC21041=1, DC21140=2, DC21142=3, DC21143=3,
154 LC82C168, MX98713, MX98715, MX98725, AX88141, AX88140, PNIC2, COMET,
155 COMPEX9881, I21145, XIRCOM, SGThomson, /*Ramesh Chander*/
158 enum pci_id_flags_bits {
159 /* Set PCI command register bits before calling probe1(). */
160 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
161 /* Read and map the single following PCI BAR. */
162 PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4,
163 PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,
164 PCI_UNUSED_IRQ=0x800,
170 u32 pci, pci_mask, subsystem, subsystem_mask;
171 u32 revision, revision_mask; /* Only 8 bits. */
173 enum pci_id_flags_bits pci_flags;
174 int io_size; /* Needed for I/O region check or ioremap(). */
175 int drv_flags; /* Driver use, intended as capability flags. */
178 static const struct pci_id_info pci_id_tbl[] = {
179 { "Digital DC21040 Tulip", { 0x00021011, 0xffffffff, 0, 0, 0, 0 },
180 TULIP_IOTYPE, 0x80, DC21040 },
181 { "Digital DC21041 Tulip", { 0x00141011, 0xffffffff, 0, 0, 0, 0 },
182 TULIP_IOTYPE, 0x80, DC21041 },
183 { "Digital DS21140A Tulip", { 0x00091011, 0xffffffff, 0,0, 0x20,0xf0 },
184 TULIP_IOTYPE, 0x80, DC21140 },
185 { "Digital DS21140 Tulip", { 0x00091011, 0xffffffff, 0, 0, 0, 0 },
186 TULIP_IOTYPE, 0x80, DC21140 },
187 { "Digital DS21143 Tulip", { 0x00191011, 0xffffffff, 0,0, 65,0xff },
188 TULIP_IOTYPE, TULIP_SIZE, DC21142 },
189 { "Digital DS21142 Tulip", { 0x00191011, 0xffffffff, 0, 0, 0, 0 },
190 TULIP_IOTYPE, TULIP_SIZE, DC21142 },
191 { "Kingston KNE110tx (PNIC)", { 0x000211AD, 0xffffffff, 0xf0022646, 0xffffffff, 0, 0 },
192 TULIP_IOTYPE, 256, LC82C168 },
193 { "Lite-On 82c168 PNIC", { 0x000211AD, 0xffffffff, 0, 0, 0, 0 },
194 TULIP_IOTYPE, 256, LC82C168 },
195 { "Macronix 98713 PMAC", { 0x051210d9, 0xffffffff, 0, 0, 0, 0 },
196 TULIP_IOTYPE, 256, MX98713 },
197 { "Macronix 98715 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
198 TULIP_IOTYPE, 256, MX98715 },
199 { "Macronix 98725 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
200 TULIP_IOTYPE, 256, MX98725 },
201 { "ASIX AX88141", { 0x1400125B, 0xffffffff, 0,0, 0x10, 0xf0 },
202 TULIP_IOTYPE, 128, AX88141 },
203 { "ASIX AX88140", { 0x1400125B, 0xffffffff, 0, 0, 0, 0 },
204 TULIP_IOTYPE, 128, AX88140 },
205 { "Lite-On LC82C115 PNIC-II", { 0xc11511AD, 0xffffffff, 0, 0, 0, 0 },
206 TULIP_IOTYPE, 256, PNIC2 },
207 { "ADMtek AN981 Comet", { 0x09811317, 0xffffffff, 0, 0, 0, 0 },
208 TULIP_IOTYPE, 256, COMET },
209 { "ADMTek AN983 Comet", { 0x12161113, 0xffffffff, 0, 0, 0, 0 },
210 TULIP_IOTYPE, 256, COMET },
211 { "ADMTek Comet AN983b", { 0x95111317, 0xffffffff, 0, 0, 0, 0 },
212 TULIP_IOTYPE, 256, COMET },
213 { "ADMtek Centaur-P", { 0x09851317, 0xffffffff, 0, 0, 0, 0 },
214 TULIP_IOTYPE, 256, COMET },
215 { "ADMtek Centaur-C", { 0x19851317, 0xffffffff, 0, 0, 0, 0 },
216 TULIP_IOTYPE, 256, COMET },
217 { "Compex RL100-TX", { 0x988111F6, 0xffffffff, 0, 0, 0, 0 },
218 TULIP_IOTYPE, 128, COMPEX9881 },
219 { "Intel 21145 Tulip", { 0x00398086, 0xffffffff, 0, 0, 0, 0 },
220 TULIP_IOTYPE, 128, I21145 },
221 { "Xircom Tulip clone", { 0x0003115d, 0xffffffff, 0, 0, 0, 0 },
222 TULIP_IOTYPE, 128, XIRCOM },
223 { "Davicom DM9102", { 0x91021282, 0xffffffff, 0, 0, 0, 0 },
224 TULIP_IOTYPE, 0x80, DC21140 },
225 { "Davicom DM9100", { 0x91001282, 0xffffffff, 0, 0, 0, 0 },
226 TULIP_IOTYPE, 0x80, DC21140 },
227 { "Macronix mxic-98715 (EN1217)", { 0x12171113, 0xffffffff, 0, 0, 0, 0 },
228 TULIP_IOTYPE, 256, MX98715 },
229 { "3Com 3cSOHO100B-TX (ADMtek Centuar)", { 0x930010b7, 0xffffffff, 0, 0, 0, 0 },
230 TULIP_IOTYPE, TULIP_SIZE, COMET },
231 { "SG Thomson STE10/100A", { 0x2774104a, 0xffffffff, 0, 0, 0, 0 },
232 TULIP_IOTYPE, 256, COMET }, /*Ramesh Chander*/
233 { 0, { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 },
237 HAS_MII=1, HAS_MEDIA_TABLE=2, CSR12_IN_SROM=4, ALWAYS_CHECK_MII=8,
238 HAS_PWRDWN=0x10, MC_HASH_ONLY=0x20, /* Hash-only multicast filter. */
239 HAS_PNICNWAY=0x80, HAS_NWAY=0x40, /* Uses internal NWay xcvr. */
240 HAS_INTR_MITIGATION=0x100, IS_ASIX=0x200, HAS_8023X=0x400,
243 /* Note: this table must match enum tulip_chips above. */
244 static struct tulip_chip_table {
248 { "Digital DC21040 Tulip", 0},
249 { "Digital DC21041 Tulip", HAS_MEDIA_TABLE | HAS_NWAY },
250 { "Digital DS21140 Tulip", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
251 { "Digital DS21143 Tulip", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
252 | HAS_PWRDWN | HAS_NWAY | HAS_INTR_MITIGATION },
253 { "Lite-On 82c168 PNIC", HAS_MII | HAS_PNICNWAY },
254 { "Macronix 98713 PMAC", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
255 { "Macronix 98715 PMAC", HAS_MEDIA_TABLE },
256 { "Macronix 98725 PMAC", HAS_MEDIA_TABLE },
257 { "ASIX AX88140", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM
258 | MC_HASH_ONLY | IS_ASIX },
259 { "ASIX AX88141", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY
261 { "Lite-On PNIC-II", HAS_MII | HAS_NWAY | HAS_8023X },
262 { "ADMtek Comet", HAS_MII | MC_HASH_ONLY },
263 { "Compex 9881 PMAC", HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM },
264 { "Intel DS21145 Tulip", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
265 | HAS_PWRDWN | HAS_NWAY },
266 { "Xircom tulip work-alike", HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII
267 | HAS_PWRDWN | HAS_NWAY },
268 { "SGThomson STE10/100A", HAS_MII | MC_HASH_ONLY }, /*Ramesh Chander*/
272 /* A full-duplex map for media types. */
274 MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8,
277 static const char media_cap[32] =
278 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 20,31,0,0, };
279 static u8 t21040_csr13[] = {2,0x0C,8,4, 4,0,0,0, 0,0,0,0, 4,0,0,0};
281 /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD */
282 static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
283 static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
284 static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
287 static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
289 static u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
291 static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
294 /* Offsets to the Command and Status Registers, "CSRs". All accesses
295 must be longword instructions and quadword aligned. */
297 CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
298 CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
299 CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
302 /* The bits in the CSR5 status registers, mostly interrupt sources. */
304 TimerInt=0x800, TPLnkFail=0x1000, TPLnkPass=0x10,
305 NormalIntr=0x10000, AbnormalIntr=0x8000,
306 RxJabber=0x200, RxDied=0x100, RxNoBuf=0x80, RxIntr=0x40,
307 TxFIFOUnderflow=0x20, TxJabber=0x08, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01,
310 /* The configuration bits in CSR6. */
311 enum csr6_mode_bits {
312 TxOn=0x2000, RxOn=0x0002, FullDuplex=0x0200,
313 AcceptBroadcast=0x0100, AcceptAllMulticast=0x0080,
314 AcceptAllPhys=0x0040, AcceptRunt=0x0008,
318 enum desc_status_bits {
319 DescOwnded=0x80000000, RxDescFatalErr=0x8000, RxWholePkt=0x0300,
325 unsigned char *leafdata;
330 u8 leafcount, csr12dir; /* General purpose pin directions. */
331 unsigned has_mii:1, has_nonmii:1, has_reset:6;
332 u32 csr15dir, csr15val; /* 21143 NWay setting. */
333 struct medialeaf mleaf[0];
337 struct mediainfo *next;
343 /* EEPROM Address width definitions */
344 #define EEPROM_ADDRLEN 6
345 #define EEPROM_SIZE 128 /* 2 << EEPROM_ADDRLEN */
347 /* The EEPROM commands include the alway-set leading bit. */
348 #define EE_WRITE_CMD (5 << addr_len)
349 #define EE_READ_CMD (6 << addr_len)
350 #define EE_ERASE_CMD (7 << addr_len)
352 /* EEPROM_Ctrl bits. */
353 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
354 #define EE_CS 0x01 /* EEPROM chip select. */
355 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
356 #define EE_WRITE_0 0x01
357 #define EE_WRITE_1 0x05
358 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
359 #define EE_ENB (0x4800 | EE_CS)
361 /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
362 implementations don't overrun the EEPROM clock. We add a bus
363 turn-around to insure that this remains true. */
364 #define eeprom_delay() inl(ee_addr)
366 /* Size of transmit and receive buffers */
369 /* Ring-wrap flag in length field, use for last ring entry.
370 0x01000000 means chain on buffer2 address,
371 0x02000000 means use the ring start address in CSR2/3.
372 Note: Some work-alike chips do not function correctly in chained mode.
373 The ASIX chip works only in chained mode.
374 Thus we indicate ring mode, but always write the 'next' field for
375 chained mode as well. */
376 #define DESC_RING_WRAP 0x02000000
378 /* transmit and receive descriptor format */
379 struct tulip_rx_desc {
382 u32 buffer1, buffer2;
385 struct tulip_tx_desc {
388 u32 buffer1, buffer2;
391 /*********************************************************************/
393 /*********************************************************************/
397 struct tulip_private {
399 int chip_id; /* index into tulip_tbl[] */
400 int pci_id_idx; /* index into pci_id_tbl[] */
403 unsigned short vendor_id; /* PCI card vendor code */
404 unsigned short dev_id; /* PCI card device code */
405 unsigned char ehdr[ETH_HLEN]; /* buffer for ethernet header */
406 const char *nic_name;
407 unsigned int csr0, csr6; /* Current CSR0, CSR6 settings. */
408 unsigned int if_port;
409 unsigned int full_duplex; /* Full-duplex operation requested. */
410 unsigned int full_duplex_lock;
411 unsigned int medialock; /* Do not sense media type. */
412 unsigned int mediasense; /* Media sensing in progress. */
413 unsigned int nway, nwayset; /* 21143 internal NWay. */
414 unsigned int default_port;
415 unsigned char eeprom[EEPROM_SIZE]; /* Serial EEPROM contents. */
416 u8 media_table_storage[(sizeof(struct mediatable) + 32*sizeof(struct medialeaf))];
417 u16 sym_advertise, mii_advertise; /* NWay to-advertise. */
418 struct mediatable *mtable;
419 u16 lpar; /* 21143 Link partner ability. */
420 u16 advertising[4]; /* MII advertise, from SROM table. */
421 signed char phys[4], mii_cnt; /* MII device addresses. */
422 int cur_index; /* Current media index. */
426 /* Note: transmit and receive buffers must be longword aligned and
427 longword divisable */
429 #define TX_RING_SIZE 2
430 #define RX_RING_SIZE 4
432 struct tulip_tx_desc tx_ring[TX_RING_SIZE];
433 unsigned char txb[BUFLEN];
434 struct tulip_rx_desc rx_ring[RX_RING_SIZE];
435 unsigned char rxb[RX_RING_SIZE * BUFLEN];
436 struct tulip_private tpx;
437 } tulip_bss __shared __attribute__ ((aligned(4)));
438 #define tx_ring tulip_bss.tx_ring
439 #define txb tulip_bss.txb
440 #define rx_ring tulip_bss.rx_ring
441 #define rxb tulip_bss.rxb
443 static struct tulip_private *tp;
445 /* Known cards that have old-style EEPROMs.
446 Writing this table is described at
447 http://cesdis.gsfc.nasa.gov/linux/drivers/tulip-drivers/tulip-media.html */
448 static struct fixups {
450 unsigned char addr0, addr1, addr2;
451 u16 newtable[32]; /* Max length below. */
452 } eeprom_fixups[] = {
453 {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
454 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
455 {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f,
456 0x0000, 0x009E, /* 10baseT */
457 0x0004, 0x009E, /* 10baseT-FD */
458 0x0903, 0x006D, /* 100baseTx */
459 0x0905, 0x006D, /* 100baseTx-FD */ }},
460 {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f,
461 0x0107, 0x8021, /* 100baseFx */
462 0x0108, 0x8021, /* 100baseFx-FD */
463 0x0100, 0x009E, /* 10baseT */
464 0x0104, 0x009E, /* 10baseT-FD */
465 0x0103, 0x006D, /* 100baseTx */
466 0x0105, 0x006D, /* 100baseTx-FD */ }},
467 {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513,
468 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
469 0x0000, 0x009E, /* 10baseT */
470 0x0004, 0x009E, /* 10baseT-FD */
471 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */
472 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}},
473 {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F,
474 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
475 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
476 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */
477 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
478 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */
482 static const char * block_name[] = {"21140 non-MII", "21140 MII PHY",
483 "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
486 /*********************************************************************/
487 /* Function Prototypes */
488 /*********************************************************************/
489 static int mdio_read(struct nic *nic, int phy_id, int location);
490 static void mdio_write(struct nic *nic, int phy_id, int location, int value);
491 static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
492 static void parse_eeprom(struct nic *nic);
493 static int tulip_probe(struct nic *nic,struct pci_device *pci);
494 static void tulip_init_ring(struct nic *nic);
495 static void tulip_reset(struct nic *nic);
496 static void tulip_transmit(struct nic *nic, const char *d, unsigned int t,
497 unsigned int s, const char *p);
498 static int tulip_poll(struct nic *nic, int retrieve);
499 static void tulip_disable(struct nic *nic, struct pci_device *pci);
500 static void nway_start(struct nic *nic);
501 static void pnic_do_nway(struct nic *nic);
502 static void select_media(struct nic *nic, int startup);
503 static void init_media(struct nic *nic);
504 static void start_link(struct nic *nic);
505 static int tulip_check_duplex(struct nic *nic);
507 static void tulip_wait(unsigned int nticks);
509 #ifdef TULIP_DEBUG_WHERE
510 static void whereami(const char *str);
514 static void tulip_more(void);
518 /*********************************************************************/
519 /* Utility Routines */
520 /*********************************************************************/
522 #ifdef TULIP_DEBUG_WHERE
523 static void whereami (const char *str, struct pci_device *pci)
525 printf("%s: %s\n", tp->nic_name, str);
531 static void tulip_more(void)
533 printf("\n\n-- more --");
539 #endif /* TULIP_DEBUG */
541 static void tulip_wait(unsigned int nticks)
543 unsigned int to = currticks() + nticks;
544 while (currticks() < to)
549 /*********************************************************************/
550 /* Media Descriptor Code */
551 /*********************************************************************/
553 /* MII transceiver control section.
554 Read and write the MII registers using software-generated serial
555 MDIO protocol. See the MII specifications or DP83840A data sheet
558 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
559 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
560 "overclocking" issues or future 66Mhz PCI. */
561 #define mdio_delay() inl(mdio_addr)
563 /* Read and write the MII registers using software-generated serial
564 MDIO protocol. It is just different enough from the EEPROM protocol
565 to not share code. The maxium data clock rate is 2.5 Mhz. */
566 #define MDIO_SHIFT_CLK 0x10000
567 #define MDIO_DATA_WRITE0 0x00000
568 #define MDIO_DATA_WRITE1 0x20000
569 #define MDIO_ENB 0x00000 /* Ignore the 0x02000 databook setting. */
570 #define MDIO_ENB_IN 0x40000
571 #define MDIO_DATA_READ 0x80000
573 /* MII transceiver control section.
574 Read and write the MII registers using software-generated serial
575 MDIO protocol. See the MII specifications or DP83840A data sheet
578 int mdio_read(struct nic *nic __unused, int phy_id, int location)
581 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
583 long mdio_addr = ioaddr + CSR9;
585 #ifdef TULIP_DEBUG_WHERE
586 whereami("mdio_read\n");
589 if (tp->chip_id == LC82C168) {
591 outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
595 if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
596 return retval & 0xffff;
600 if (tp->chip_id == COMET) {
603 return inl(ioaddr + 0xB4 + (location<<2));
604 else if (location == 17)
605 return inl(ioaddr + 0xD0);
606 else if (location >= 29 && location <= 31)
607 return inl(ioaddr + 0xD4 + ((location-29)<<2));
612 /* Establish sync by sending at least 32 logic ones. */
613 for (i = 32; i >= 0; i--) {
614 outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
616 outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
619 /* Shift the read command bits out. */
620 for (i = 15; i >= 0; i--) {
621 int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
623 outl(MDIO_ENB | dataval, mdio_addr);
625 outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
628 /* Read the two transition, 16 data, and wire-idle bits. */
629 for (i = 19; i > 0; i--) {
630 outl(MDIO_ENB_IN, mdio_addr);
632 retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
633 outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
636 return (retval>>1) & 0xffff;
639 void mdio_write(struct nic *nic __unused, int phy_id, int location, int value)
642 int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
643 long mdio_addr = ioaddr + CSR9;
645 #ifdef TULIP_DEBUG_WHERE
646 whereami("mdio_write\n");
649 if (tp->chip_id == LC82C168) {
651 outl(cmd, ioaddr + 0xA0);
653 if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
659 if (tp->chip_id == COMET) {
663 outl(value, ioaddr + 0xB4 + (location<<2));
664 else if (location == 17)
665 outl(value, ioaddr + 0xD0);
666 else if (location >= 29 && location <= 31)
667 outl(value, ioaddr + 0xD4 + ((location-29)<<2));
671 /* Establish sync by sending 32 logic ones. */
672 for (i = 32; i >= 0; i--) {
673 outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
675 outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
678 /* Shift the command bits out. */
679 for (i = 31; i >= 0; i--) {
680 int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
681 outl(MDIO_ENB | dataval, mdio_addr);
683 outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
686 /* Clear out extra bits. */
687 for (i = 2; i > 0; i--) {
688 outl(MDIO_ENB_IN, mdio_addr);
690 outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
696 /*********************************************************************/
697 /* EEPROM Reading Code */
698 /*********************************************************************/
699 /* EEPROM routines adapted from the Linux Tulip Code */
700 /* Reading a serial EEPROM is a "bit" grungy, but we work our way
703 static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
706 unsigned short retval = 0;
707 long ee_addr = ioaddr + CSR9;
708 int read_cmd = location | EE_READ_CMD;
710 #ifdef TULIP_DEBUG_WHERE
711 whereami("read_eeprom\n");
714 outl(EE_ENB & ~EE_CS, ee_addr);
715 outl(EE_ENB, ee_addr);
717 /* Shift the read command bits out. */
718 for (i = 4 + addr_len; i >= 0; i--) {
719 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
720 outl(EE_ENB | dataval, ee_addr);
722 outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
725 outl(EE_ENB, ee_addr);
727 for (i = 16; i > 0; i--) {
728 outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
730 retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
731 outl(EE_ENB, ee_addr);
735 /* Terminate the EEPROM access. */
736 outl(EE_ENB & ~EE_CS, ee_addr);
741 /*********************************************************************/
742 /* EEPROM Parsing Code */
743 /*********************************************************************/
744 static void parse_eeprom(struct nic *nic)
746 unsigned char *p, *ee_data = tp->eeprom;
747 int new_advertise = 0;
750 #ifdef TULIP_DEBUG_WHERE
751 whereami("parse_eeprom\n");
755 /* Detect an old-style (SA only) EEPROM layout:
756 memcmp(ee_data, ee_data+16, 8). */
757 for (i = 0; i < 8; i ++)
758 if (ee_data[i] != ee_data[16+i])
761 /* Do a fix-up based on the vendor half of the station address. */
762 for (i = 0; eeprom_fixups[i].name; i++) {
763 if (nic->node_addr[0] == eeprom_fixups[i].addr0
764 && nic->node_addr[1] == eeprom_fixups[i].addr1
765 && nic->node_addr[2] == eeprom_fixups[i].addr2) {
766 if (nic->node_addr[2] == 0xE8 && ee_data[0x1a] == 0x55)
767 i++; /* An Accton EN1207, not an outlaw Maxtech. */
768 memcpy(ee_data + 26, eeprom_fixups[i].newtable,
769 sizeof(eeprom_fixups[i].newtable));
771 printf("%s: Old format EEPROM on '%s' board.\n%s: Using substitute media control info.\n",
772 tp->nic_name, eeprom_fixups[i].name, tp->nic_name);
777 if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
779 printf("%s: Old style EEPROM with no media selection information.\n",
786 if (ee_data[19] > 1) {
788 printf("%s: Multiport cards (%d ports) may not work correctly.\n",
789 tp->nic_name, ee_data[19]);
793 p = (void *)ee_data + ee_data[27];
795 if (ee_data[27] == 0) { /* No valid media table. */
797 if (tulip_debug > 1) {
798 printf("%s: No Valid Media Table. ee_data[27] = %hhX\n",
799 tp->nic_name, ee_data[27]);
802 } else if (tp->chip_id == DC21041) {
803 int media = get_u16(p);
807 printf("%s: 21041 Media table, default media %hX (%s).\n",
809 media & 0x0800 ? "Autosense" : medianame[media & 15]);
810 for (i = 0; i < count; i++) {
811 unsigned char media_block = *p++;
812 int media_code = media_block & MEDIA_MASK;
813 if (media_block & 0x40)
816 case 0: new_advertise |= 0x0020; break;
817 case 4: new_advertise |= 0x0040; break;
819 printf("%s: 21041 media #%d, %s.\n",
820 tp->nic_name, media_code, medianame[media_code]);
823 unsigned char csr12dir = 0;
825 struct mediatable *mtable;
826 u16 media = get_u16(p);
829 if (tp->flags & CSR12_IN_SROM)
833 tp->mtable = mtable = (struct mediatable *)&tp->media_table_storage[0];
835 mtable->defaultmedia = media;
836 mtable->leafcount = count;
837 mtable->csr12dir = csr12dir;
838 mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0;
839 mtable->csr15dir = mtable->csr15val = 0;
841 printf("%s: EEPROM default media type %s.\n", tp->nic_name,
842 media & 0x0800 ? "Autosense" : medianame[media & MEDIA_MASK]);
844 for (i = 0; i < count; i++) {
845 struct medialeaf *leaf = &mtable->mleaf[i];
847 if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
849 leaf->media = p[0] & 0x3f;
851 if ((p[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
855 switch(leaf->type = p[1]) {
857 mtable->has_reset = i;
858 leaf->media = p[2] & 0x0f;
865 if ((p[2] & 0x3f) == 0) {
866 u32 base15 = (p[2] & 0x40) ? get_u16(p + 7) : 0x0008;
867 u16 *p1 = (u16 *)(p + (p[2] & 0x40 ? 9 : 3));
868 mtable->csr15dir = (get_unaligned(p1 + 0)<<16) + base15;
869 mtable->csr15val = (get_unaligned(p1 + 1)<<16) + base15;
873 mtable->has_nonmii = 1;
874 leaf->media = p[2] & MEDIA_MASK;
875 switch (leaf->media) {
876 case 0: new_advertise |= 0x0020; break;
877 case 4: new_advertise |= 0x0040; break;
878 case 3: new_advertise |= 0x0080; break;
879 case 5: new_advertise |= 0x0100; break;
880 case 6: new_advertise |= 0x0200; break;
886 leaf->leafdata = p + 2;
887 p += (p[0] & 0x3f) + 1;
890 if (tulip_debug > 1 && leaf->media == 11) {
891 unsigned char *bp = leaf->leafdata;
892 printf("%s: MII interface PHY %d, setup/reset sequences %d/%d long, capabilities %hhX %hhX.\n",
893 tp->nic_name, bp[0], bp[1], bp[2 + bp[1]*2],
894 bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]);
897 printf("%s: Index #%d - Media %s (#%d) described "
898 "by a %s (%d) block.\n",
899 tp->nic_name, i, medianame[leaf->media], leaf->media,
900 leaf->type < 6 ? block_name[leaf->type] : "UNKNOWN",
904 tp->sym_advertise = new_advertise;
909 /*********************************************************************/
910 /* tulip_init_ring - setup the tx and rx descriptors */
911 /*********************************************************************/
912 static void tulip_init_ring(struct nic *nic __unused)
916 #ifdef TULIP_DEBUG_WHERE
917 whereami("tulip_init_ring\n");
922 for (i = 0; i < RX_RING_SIZE; i++) {
923 rx_ring[i].status = cpu_to_le32(0x80000000);
924 rx_ring[i].length = cpu_to_le32(BUFLEN);
925 rx_ring[i].buffer1 = virt_to_le32desc(&rxb[i * BUFLEN]);
926 rx_ring[i].buffer2 = virt_to_le32desc(&rx_ring[i+1]);
928 /* Mark the last entry as wrapping the ring. */
929 rx_ring[i-1].length = cpu_to_le32(DESC_RING_WRAP | BUFLEN);
930 rx_ring[i-1].buffer2 = virt_to_le32desc(&rx_ring[0]);
932 /* We only use 1 transmit buffer, but we use 2 descriptors so
933 transmit engines have somewhere to point to if they feel the need */
935 tx_ring[0].status = 0x00000000;
936 tx_ring[0].buffer1 = virt_to_le32desc(&txb[0]);
937 tx_ring[0].buffer2 = virt_to_le32desc(&tx_ring[1]);
939 /* this descriptor should never get used, since it will never be owned
940 by the machine (status will always == 0) */
941 tx_ring[1].status = 0x00000000;
942 tx_ring[1].buffer1 = virt_to_le32desc(&txb[0]);
943 tx_ring[1].buffer2 = virt_to_le32desc(&tx_ring[0]);
945 /* Mark the last entry as wrapping the ring, though this should never happen */
946 tx_ring[1].length = cpu_to_le32(DESC_RING_WRAP | BUFLEN);
950 static void set_rx_mode(struct nic *nic __unused) {
951 int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
956 tp->csr6 |= AcceptAllMulticast;
957 csr6 |= AcceptAllMulticast;
959 outl(csr6, ioaddr + CSR6);
965 /*********************************************************************/
966 /* eth_reset - Reset adapter */
967 /*********************************************************************/
968 static void tulip_reset(struct nic *nic)
973 #ifdef TULIP_DEBUG_WHERE
974 whereami("tulip_reset\n");
978 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
980 /* On some chip revs we must set the MII/SYM port before the reset!? */
981 if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii)) {
982 outl(0x814C0000, ioaddr + CSR6);
985 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
986 outl(0x00000001, ioaddr + CSR0);
989 /* turn off reset and set cache align=16lword, burst=unlimit */
990 outl(tp->csr0, ioaddr + CSR0);
992 /* Wait the specified 50 PCI cycles after a reset */
995 /* set up transmit and receive descriptors */
996 tulip_init_ring(nic);
998 if (tp->chip_id == PNIC2) {
999 u32 addr_high = (nic->node_addr[1]<<8) + (nic->node_addr[0]<<0);
1000 /* This address setting does not appear to impact chip operation?? */
1001 outl((nic->node_addr[5]<<8) + nic->node_addr[4] +
1002 (nic->node_addr[3]<<24) + (nic->node_addr[2]<<16),
1004 outl(addr_high + (addr_high<<16), ioaddr + 0xB8);
1007 /* MC_HASH_ONLY boards don't support setup packets */
1008 if (tp->flags & MC_HASH_ONLY) {
1009 u32 addr_low = cpu_to_le32(get_unaligned((u32 *)nic->node_addr));
1010 u32 addr_high = cpu_to_le32(get_unaligned((u16 *)(nic->node_addr+4)));
1012 /* clear multicast hash filters and setup MAC address filters */
1013 if (tp->flags & IS_ASIX) {
1014 outl(0, ioaddr + CSR13);
1015 outl(addr_low, ioaddr + CSR14);
1016 outl(1, ioaddr + CSR13);
1017 outl(addr_high, ioaddr + CSR14);
1018 outl(2, ioaddr + CSR13);
1019 outl(0, ioaddr + CSR14);
1020 outl(3, ioaddr + CSR13);
1021 outl(0, ioaddr + CSR14);
1022 } else if (tp->chip_id == COMET) {
1023 outl(addr_low, ioaddr + 0xA4);
1024 outl(addr_high, ioaddr + 0xA8);
1025 outl(0, ioaddr + 0xAC);
1026 outl(0, ioaddr + 0xB0);
1029 /* for other boards we send a setup packet to initialize
1031 u32 tx_flags = 0x08000000 | 192;
1033 /* construct perfect filter frame with mac address as first match
1034 and broadcast address for all others */
1035 for (i=0; i<192; i++)
1037 txb[0] = nic->node_addr[0];
1038 txb[1] = nic->node_addr[1];
1039 txb[4] = nic->node_addr[2];
1040 txb[5] = nic->node_addr[3];
1041 txb[8] = nic->node_addr[4];
1042 txb[9] = nic->node_addr[5];
1044 tx_ring[0].length = cpu_to_le32(tx_flags);
1045 tx_ring[0].buffer1 = virt_to_le32desc(&txb[0]);
1046 tx_ring[0].status = cpu_to_le32(0x80000000);
1049 /* Point to rx and tx descriptors */
1050 outl(virt_to_le32desc(&rx_ring[0]), ioaddr + CSR3);
1051 outl(virt_to_le32desc(&tx_ring[0]), ioaddr + CSR4);
1055 /* set the chip's operating mode (but don't turn on xmit and recv yet) */
1056 outl((tp->csr6 & ~0x00002002), ioaddr + CSR6);
1058 /* send setup packet for cards that support it */
1059 if (!(tp->flags & MC_HASH_ONLY)) {
1060 /* enable transmit wait for completion */
1061 outl(tp->csr6 | 0x00002000, ioaddr + CSR6);
1062 /* immediate transmit demand */
1063 outl(0, ioaddr + CSR1);
1065 to = currticks() + TX_TIME_OUT;
1066 while ((tx_ring[0].status & 0x80000000) && (currticks() < to))
1069 if (currticks() >= to) {
1070 printf ("%s: TX Setup Timeout.\n", tp->nic_name);
1074 if (tp->chip_id == LC82C168)
1075 tulip_check_duplex(nic);
1079 /* enable transmit and receive */
1080 outl(tp->csr6 | 0x00002002, ioaddr + CSR6);
1084 /*********************************************************************/
1085 /* eth_transmit - Transmit a frame */
1086 /*********************************************************************/
1087 static void tulip_transmit(struct nic *nic, const char *d, unsigned int t,
1088 unsigned int s, const char *p)
1092 u32 csr6 = inl(ioaddr + CSR6);
1094 #ifdef TULIP_DEBUG_WHERE
1095 whereami("tulip_transmit\n");
1099 outl(csr6 & ~0x00002000, ioaddr + CSR6);
1101 memcpy(txb, d, ETH_ALEN);
1102 memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
1103 nstype = htons((u16) t);
1104 memcpy(txb + 2 * ETH_ALEN, (u8 *)&nstype, 2);
1105 memcpy(txb + ETH_HLEN, p, s);
1110 /* pad to minimum packet size */
1111 while (s < ETH_ZLEN)
1115 if (tulip_debug > 1)
1116 printf("%s: sending %d bytes ethtype %hX\n", tp->nic_name, s, t);
1119 /* setup the transmit descriptor */
1120 /* 0x60000000 = no interrupt on completion */
1121 tx_ring[0].length = cpu_to_le32(0x60000000 | s);
1122 tx_ring[0].status = cpu_to_le32(0x80000000);
1124 /* Point to transmit descriptor */
1125 outl(virt_to_le32desc(&tx_ring[0]), ioaddr + CSR4);
1128 outl(csr6 | 0x00002000, ioaddr + CSR6);
1129 /* immediate transmit demand */
1130 outl(0, ioaddr + CSR1);
1132 to = currticks() + TX_TIME_OUT;
1133 while ((tx_ring[0].status & 0x80000000) && (currticks() < to))
1136 if (currticks() >= to) {
1137 printf ("TX Timeout!\n");
1141 outl(csr6 & ~0x00002000, ioaddr + CSR6);
1144 /*********************************************************************/
1145 /* eth_poll - Wait for a frame */
1146 /*********************************************************************/
1147 static int tulip_poll(struct nic *nic, int retrieve)
1150 #ifdef TULIP_DEBUG_WHERE
1151 whereami("tulip_poll\n");
1154 /* no packet waiting. packet still owned by NIC */
1155 if (rx_ring[tp->cur_rx].status & 0x80000000)
1158 if ( ! retrieve ) return 1;
1160 #ifdef TULIP_DEBUG_WHERE
1161 whereami("tulip_poll got one\n");
1164 nic->packetlen = (rx_ring[tp->cur_rx].status & 0x3FFF0000) >> 16;
1166 /* if we get a corrupted packet. throw it away and move on */
1167 if (rx_ring[tp->cur_rx].status & 0x00008000) {
1168 /* return the descriptor and buffer to receive ring */
1169 rx_ring[tp->cur_rx].status = 0x80000000;
1170 tp->cur_rx = (++tp->cur_rx) % RX_RING_SIZE;
1174 /* copy packet to working buffer */
1175 memcpy(nic->packet, rxb + tp->cur_rx * BUFLEN, nic->packetlen);
1177 /* return the descriptor and buffer to receive ring */
1178 rx_ring[tp->cur_rx].status = 0x80000000;
1179 tp->cur_rx = (++tp->cur_rx) % RX_RING_SIZE;
1184 /*********************************************************************/
1185 /* eth_disable - Disable the interface */
1186 /*********************************************************************/
1187 static void tulip_disable ( struct nic *nic, struct pci_device *pci __unused ) {
1188 nic_disable ( nic );
1189 #ifdef TULIP_DEBUG_WHERE
1190 whereami("tulip_disable\n");
1193 /* merge reset and disable */
1196 /* disable interrupts */
1197 outl(0x00000000, ioaddr + CSR7);
1199 /* Stop the chip's Tx and Rx processes. */
1200 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
1202 /* Clear the missed-packet counter. */
1203 (volatile unsigned long)inl(ioaddr + CSR8);
1206 /*********************************************************************/
1207 /*IRQ - Enable, Disable, or Force interrupts */
1208 /*********************************************************************/
1209 static void tulip_irq(struct nic *nic __unused, irq_action_t action __unused)
1221 static struct nic_operations tulip_operations = {
1222 .connect = dummy_connect,
1224 .transmit = tulip_transmit,
1229 /*********************************************************************/
1230 /* eth_probe - Look for an adapter */
1231 /*********************************************************************/
1232 static int tulip_probe ( struct nic *nic, struct pci_device *pci ) {
1236 u8 ee_data[EEPROM_SIZE];
1239 static unsigned char last_phys_addr[ETH_ALEN] = {0x00, 'L', 'i', 'n', 'u', 'x'};
1241 if (pci->ioaddr == 0)
1244 ioaddr = pci->ioaddr;
1245 pci_fill_nic ( nic, pci );
1246 nic->ioaddr = pci->ioaddr & ~3;
1249 /* point to private storage */
1250 tp = &tulip_bss.tpx;
1252 tp->vendor_id = pci->vendor;
1253 tp->dev_id = pci->device;
1254 tp->nic_name = pci->name;
1257 tp->default_port = 0;
1259 adjust_pci_device(pci);
1261 /* disable interrupts */
1262 outl(0x00000000, ioaddr + CSR7);
1264 /* Stop the chip's Tx and Rx processes. */
1265 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
1267 /* Clear the missed-packet counter. */
1268 (volatile unsigned long)inl(ioaddr + CSR8);
1270 printf("\n"); /* so we start on a fresh line */
1271 #ifdef TULIP_DEBUG_WHERE
1272 whereami("tulip_probe\n");
1276 if (tulip_debug > 1)
1277 printf ("%s: Looking for Tulip Chip: Vendor=%hX Device=%hX\n", tp->nic_name,
1278 tp->vendor, tp->dev_id);
1281 /* Figure out which chip we're dealing with */
1285 while (pci_id_tbl[i].name) {
1286 if ( (((u32) tp->dev_id << 16) | tp->vendor_id) ==
1287 (pci_id_tbl[i].id.pci & pci_id_tbl[i].id.pci_mask) ) {
1288 chip_idx = pci_id_tbl[i].drv_flags;
1294 if (chip_idx == -1) {
1295 printf ("%s: Unknown Tulip Chip: Vendor=%hX Device=%hX\n", tp->nic_name,
1296 tp->vendor_id, tp->dev_id);
1301 tp->flags = tulip_tbl[chip_idx].flags;
1304 if (tulip_debug > 1) {
1305 printf ("%s: tp->pci_id_idx == %d, name == %s\n", tp->nic_name,
1306 tp->pci_id_idx, pci_id_tbl[tp->pci_id_idx].name);
1307 printf ("%s: chip_idx == %d, name == %s\n", tp->nic_name, chip_idx,
1308 tulip_tbl[chip_idx].chip_name);
1312 /* Bring the 21041/21143 out of sleep mode.
1313 Caution: Snooze mode does not work with some boards! */
1314 if (tp->flags & HAS_PWRDWN)
1315 pci_write_config_dword(pci, 0x40, 0x00000000);
1317 if (inl(ioaddr + CSR5) == 0xFFFFFFFF) {
1318 printf("%s: The Tulip chip at %X is not functioning.\n",
1319 tp->nic_name, ioaddr);
1323 pci_read_config_byte(pci, PCI_REVISION, &chip_rev);
1325 printf("%s: [chip: %s] rev %d at %hX\n", tp->nic_name,
1326 tulip_tbl[chip_idx].chip_name, chip_rev, ioaddr);
1327 printf("%s: Vendor=%hX Device=%hX", tp->nic_name, tp->vendor_id, tp->dev_id);
1329 if (chip_idx == DC21041 && inl(ioaddr + CSR9) & 0x8000) {
1330 printf(" 21040 compatible mode.");
1336 /* The SROM/EEPROM interface varies dramatically. */
1338 if (chip_idx == DC21040) {
1339 outl(0, ioaddr + CSR9); /* Reset the pointer with a dummy write. */
1340 for (i = 0; i < ETH_ALEN; i++) {
1341 int value, boguscnt = 100000;
1343 value = inl(ioaddr + CSR9);
1344 while (value < 0 && --boguscnt > 0);
1345 nic->node_addr[i] = value;
1346 sum += value & 0xff;
1348 } else if (chip_idx == LC82C168) {
1349 for (i = 0; i < 3; i++) {
1350 int value, boguscnt = 100000;
1351 outl(0x600 | i, ioaddr + 0x98);
1353 value = inl(ioaddr + CSR9);
1354 while (value < 0 && --boguscnt > 0);
1355 put_unaligned(le16_to_cpu(value), ((u16*)nic->node_addr) + i);
1356 sum += value & 0xffff;
1358 } else if (chip_idx == COMET) {
1359 /* No need to read the EEPROM. */
1360 put_unaligned(inl(ioaddr + 0xA4), (u32 *)nic->node_addr);
1361 put_unaligned(inl(ioaddr + 0xA8), (u16 *)(nic->node_addr + 4));
1362 for (i = 0; i < ETH_ALEN; i ++)
1363 sum += nic->node_addr[i];
1365 /* A serial EEPROM interface, we read now and sort it out later. */
1367 int ee_addr_size = read_eeprom(ioaddr, 0xff, 8) & 0x40000 ? 8 : 6;
1369 for (i = 0; i < sizeof(ee_data)/2; i++)
1370 ((u16 *)ee_data)[i] =
1371 le16_to_cpu(read_eeprom(ioaddr, i, ee_addr_size));
1373 /* DEC now has a specification (see Notes) but early board makers
1374 just put the address in the first EEPROM locations. */
1375 /* This does memcmp(eedata, eedata+16, 8) */
1376 for (i = 0; i < 8; i ++)
1377 if (ee_data[i] != ee_data[16+i])
1379 if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) {
1380 sa_offset = 2; /* Grrr, damn Matrox boards. */
1382 for (i = 0; i < ETH_ALEN; i ++) {
1383 nic->node_addr[i] = ee_data[i + sa_offset];
1384 sum += ee_data[i + sa_offset];
1387 /* Lite-On boards have the address byte-swapped. */
1388 if ((nic->node_addr[0] == 0xA0 || nic->node_addr[0] == 0xC0)
1389 && nic->node_addr[1] == 0x00)
1390 for (i = 0; i < ETH_ALEN; i+=2) {
1391 char tmp = nic->node_addr[i];
1392 nic->node_addr[i] = nic->node_addr[i+1];
1393 nic->node_addr[i+1] = tmp;
1396 if (sum == 0 || sum == ETH_ALEN*0xff) {
1397 printf("%s: EEPROM not present!\n", tp->nic_name);
1398 for (i = 0; i < ETH_ALEN-1; i++)
1399 nic->node_addr[i] = last_phys_addr[i];
1400 nic->node_addr[i] = last_phys_addr[i] + 1;
1403 for (i = 0; i < ETH_ALEN; i++)
1404 last_phys_addr[i] = nic->node_addr[i];
1406 printf("%s: %! at ioaddr %hX\n", tp->nic_name, nic->node_addr, ioaddr);
1408 tp->chip_id = chip_idx;
1409 tp->revision = chip_rev;
1412 /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles.
1413 And the ASIX must have a burst limit or horrible things happen. */
1414 if (chip_idx == DC21143 && chip_rev == 65)
1415 tp->csr0 &= ~0x01000000;
1416 else if (tp->flags & IS_ASIX)
1419 if (media_cap[tp->default_port] & MediaIsMII) {
1420 u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
1421 tp->mii_advertise = media2advert[tp->default_port - 9];
1422 tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */
1425 /* This is logically part of the probe routine, but too complex
1427 if (tp->flags & HAS_MEDIA_TABLE) {
1428 memcpy(tp->eeprom, ee_data, sizeof(tp->eeprom));
1434 /* reset the device and make ready for tx and rx of packets */
1436 nic->nic_op = &tulip_operations;
1438 /* give the board a chance to reset before returning */
1439 tulip_wait(4*TICKS_PER_SEC);
1444 static void start_link(struct nic *nic)
1448 #ifdef TULIP_DEBUG_WHERE
1449 whereami("start_link\n");
1452 if ((tp->flags & ALWAYS_CHECK_MII) ||
1453 (tp->mtable && tp->mtable->has_mii) ||
1454 ( ! tp->mtable && (tp->flags & HAS_MII))) {
1455 unsigned int phy, phy_idx;
1456 if (tp->mtable && tp->mtable->has_mii) {
1457 for (i = 0; i < tp->mtable->leafcount; i++)
1458 if (tp->mtable->mleaf[i].media == 11) {
1460 tp->saved_if_port = tp->if_port;
1461 select_media(nic, 2);
1462 tp->if_port = tp->saved_if_port;
1467 /* Find the connected MII xcvrs. */
1468 for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys);
1470 int mii_status = mdio_read(nic, phy, 1);
1471 if ((mii_status & 0x8301) == 0x8001 ||
1472 ((mii_status & 0x8000) == 0 && (mii_status & 0x7800) != 0)) {
1473 int mii_reg0 = mdio_read(nic, phy, 0);
1474 int mii_advert = mdio_read(nic, phy, 4);
1477 if (tp->mii_advertise)
1478 to_advert = tp->mii_advertise;
1479 else if (tp->advertising[phy_idx])
1480 to_advert = tp->advertising[phy_idx];
1481 else /* Leave unchanged. */
1482 tp->mii_advertise = to_advert = mii_advert;
1484 tp->phys[phy_idx++] = phy;
1485 printf("%s: MII transceiver %d config %hX status %hX advertising %hX.\n",
1486 tp->nic_name, phy, mii_reg0, mii_status, mii_advert);
1487 /* Fixup for DLink with miswired PHY. */
1488 if (mii_advert != to_advert) {
1489 printf("%s: Advertising %hX on PHY %d previously advertising %hX.\n",
1490 tp->nic_name, to_advert, phy, mii_advert);
1491 mdio_write(nic, phy, 4, to_advert);
1493 /* Enable autonegotiation: some boards default to off. */
1494 mdio_write(nic, phy, 0, mii_reg0 |
1495 (tp->full_duplex ? 0x1100 : 0x1000) |
1496 (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0));
1499 tp->mii_cnt = phy_idx;
1500 if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) {
1501 printf("%s: ***WARNING***: No MII transceiver found!\n",
1507 /* Reset the xcvr interface and turn on heartbeat. */
1508 switch (tp->chip_id) {
1510 outl(0x00000000, ioaddr + CSR13);
1511 outl(0x00000004, ioaddr + CSR13);
1514 /* This is nway_start(). */
1515 if (tp->sym_advertise == 0)
1516 tp->sym_advertise = 0x0061;
1517 outl(0x00000000, ioaddr + CSR13);
1518 outl(0xFFFFFFFF, ioaddr + CSR14);
1519 outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */
1520 outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6);
1521 outl(0x0000EF01, ioaddr + CSR13);
1523 case DC21140: default:
1525 outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
1529 if (tp->mii_cnt || media_cap[tp->if_port] & MediaIsMII) {
1530 outl(0x82020000, ioaddr + CSR6);
1531 outl(0x0000, ioaddr + CSR13);
1532 outl(0x0000, ioaddr + CSR14);
1533 outl(0x820E0000, ioaddr + CSR6);
1538 if ( ! tp->mii_cnt) {
1541 outl(0x00420000, ioaddr + CSR6);
1542 outl(0x30, ioaddr + CSR12);
1543 outl(0x0001F078, ioaddr + 0xB8);
1544 outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
1547 case MX98713: case COMPEX9881:
1548 outl(0x00000000, ioaddr + CSR6);
1549 outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
1550 outl(0x00000001, ioaddr + CSR13);
1552 case MX98715: case MX98725:
1553 outl(0x01a80000, ioaddr + CSR6);
1554 outl(0xFFFFFFFF, ioaddr + CSR14);
1555 outl(0x00001000, ioaddr + CSR12);
1558 /* No initialization necessary. */
1563 static void nway_start(struct nic *nic __unused)
1565 int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
1566 ((tp->sym_advertise&0x0020)<<1) | 0xffbf;
1568 #ifdef TULIP_DEBUG_WHERE
1569 whereami("nway_start\n");
1573 tp->nway = tp->mediasense = 1;
1574 tp->nwayset = tp->lpar = 0;
1575 if (tp->chip_id == PNIC2) {
1576 tp->csr6 = 0x01000000 | (tp->sym_advertise & 0x0040 ? 0x0200 : 0);
1580 if (tulip_debug > 1)
1581 printf("%s: Restarting internal NWay autonegotiation, %X.\n",
1582 tp->nic_name, csr14);
1584 outl(0x0001, ioaddr + CSR13);
1585 outl(csr14, ioaddr + CSR14);
1586 tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? 0x0200 : 0);
1587 outl(tp->csr6, ioaddr + CSR6);
1588 if (tp->mtable && tp->mtable->csr15dir) {
1589 outl(tp->mtable->csr15dir, ioaddr + CSR15);
1590 outl(tp->mtable->csr15val, ioaddr + CSR15);
1591 } else if (tp->chip_id != PNIC2)
1592 outw(0x0008, ioaddr + CSR15);
1593 if (tp->chip_id == DC21041) /* Trigger NWAY. */
1594 outl(0xEF01, ioaddr + CSR12);
1596 outl(0x1301, ioaddr + CSR12);
1599 static void init_media(struct nic *nic)
1603 #ifdef TULIP_DEBUG_WHERE
1604 whereami("init_media\n");
1607 tp->saved_if_port = tp->if_port;
1608 if (tp->if_port == 0)
1609 tp->if_port = tp->default_port;
1611 /* Allow selecting a default media. */
1613 if (tp->mtable == NULL)
1616 int looking_for = media_cap[tp->if_port] & MediaIsMII ? 11 :
1617 (tp->if_port == 12 ? 0 : tp->if_port);
1618 for (i = 0; i < tp->mtable->leafcount; i++)
1619 if (tp->mtable->mleaf[i].media == looking_for) {
1620 printf("%s: Using user-specified media %s.\n",
1621 tp->nic_name, medianame[tp->if_port]);
1625 if ((tp->mtable->defaultmedia & 0x0800) == 0) {
1626 int looking_for = tp->mtable->defaultmedia & 15;
1627 for (i = 0; i < tp->mtable->leafcount; i++)
1628 if (tp->mtable->mleaf[i].media == looking_for) {
1629 printf("%s: Using EEPROM-set media %s.\n",
1630 tp->nic_name, medianame[looking_for]);
1634 /* Start sensing first non-full-duplex media. */
1635 for (i = tp->mtable->leafcount - 1;
1636 (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
1645 if (tp->chip_id == DC21143 && media_cap[tp->if_port] & MediaIsMII) {
1646 /* We must reset the media CSRs when we force-select MII mode. */
1647 outl(0x0000, ioaddr + CSR13);
1648 outl(0x0000, ioaddr + CSR14);
1649 outl(0x0008, ioaddr + CSR15);
1651 select_media(nic, 1);
1654 switch(tp->chip_id) {
1661 select_media(nic, 1);
1663 if (tulip_debug > 1)
1664 printf("%s: Using MII transceiver %d, status %hX.\n",
1665 tp->nic_name, tp->phys[0], mdio_read(nic, tp->phys[0], 1));
1667 outl(0x82020000, ioaddr + CSR6);
1668 tp->csr6 = 0x820E0000;
1670 outl(0x0000, ioaddr + CSR13);
1671 outl(0x0000, ioaddr + CSR14);
1681 tp->csr6 = 0x814C0000 | (tp->full_duplex ? 0x0200 : 0);
1682 outl(0x0001, ioaddr + CSR15);
1683 } else if (inl(ioaddr + CSR5) & TPLnkPass)
1686 /* Start with 10mbps to do autonegotiation. */
1687 outl(0x32, ioaddr + CSR12);
1688 tp->csr6 = 0x00420000;
1689 outl(0x0001B078, ioaddr + 0xB8);
1690 outl(0x0201B078, ioaddr + 0xB8);
1693 case MX98713: case COMPEX9881:
1695 tp->csr6 = 0x01880000 | (tp->full_duplex ? 0x0200 : 0);
1696 outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
1698 case MX98715: case MX98725:
1699 /* Provided by BOLO, Macronix - 12/10/1998. */
1701 tp->csr6 = 0x01a80200;
1702 outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
1703 outl(0x11000 | inw(ioaddr + 0xa0), ioaddr + 0xa0);
1706 /* Enable automatic Tx underrun recovery */
1707 outl(inl(ioaddr + 0x88) | 1, ioaddr + 0x88);
1709 tp->csr6 = 0x00040000;
1711 case AX88140: case AX88141:
1712 tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
1715 select_media(nic, 1);
1719 static void pnic_do_nway(struct nic *nic __unused)
1721 u32 phy_reg = inl(ioaddr + 0xB8);
1722 u32 new_csr6 = tp->csr6 & ~0x40C40200;
1724 #ifdef TULIP_DEBUG_WHERE
1725 whereami("pnic_do_nway\n");
1728 if (phy_reg & 0x78000000) { /* Ignore baseT4 */
1729 if (phy_reg & 0x20000000) tp->if_port = 5;
1730 else if (phy_reg & 0x40000000) tp->if_port = 3;
1731 else if (phy_reg & 0x10000000) tp->if_port = 4;
1732 else if (phy_reg & 0x08000000) tp->if_port = 0;
1734 new_csr6 = (tp->if_port & 1) ? 0x01860000 : 0x00420000;
1735 outl(0x32 | (tp->if_port & 1), ioaddr + CSR12);
1736 if (tp->if_port & 1)
1737 outl(0x1F868, ioaddr + 0xB8);
1738 if (phy_reg & 0x30000000) {
1739 tp->full_duplex = 1;
1740 new_csr6 |= 0x00000200;
1743 if (tulip_debug > 1)
1744 printf("%s: PNIC autonegotiated status %X, %s.\n",
1745 tp->nic_name, phy_reg, medianame[tp->if_port]);
1747 if (tp->csr6 != new_csr6) {
1748 tp->csr6 = new_csr6;
1749 outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */
1750 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1755 /* Set up the transceiver control registers for the selected media type. */
1756 static void select_media(struct nic *nic, int startup)
1758 struct mediatable *mtable = tp->mtable;
1762 #ifdef TULIP_DEBUG_WHERE
1763 whereami("select_media\n");
1767 struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
1768 unsigned char *p = mleaf->leafdata;
1769 switch (mleaf->type) {
1770 case 0: /* 21140 non-MII xcvr. */
1772 if (tulip_debug > 1)
1773 printf("%s: Using a 21140 non-MII transceiver"
1774 " with control setting %hhX.\n",
1775 tp->nic_name, p[1]);
1779 outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
1780 outl(p[1], ioaddr + CSR12);
1781 new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
1785 u32 csr13val, csr14val, csr15dir, csr15val;
1786 for (i = 0; i < 5; i++)
1787 setup[i] = get_u16(&p[i*2 + 1]);
1789 tp->if_port = p[0] & 15;
1790 if (media_cap[tp->if_port] & MediaAlwaysFD)
1791 tp->full_duplex = 1;
1793 if (startup && mtable->has_reset) {
1794 struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];
1795 unsigned char *rst = rleaf->leafdata;
1797 if (tulip_debug > 1)
1798 printf("%s: Resetting the transceiver.\n",
1801 for (i = 0; i < rst[0]; i++)
1802 outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);
1805 if (tulip_debug > 1)
1806 printf("%s: 21143 non-MII %s transceiver control "
1808 tp->nic_name, medianame[tp->if_port], setup[0], setup[1]);
1810 if (p[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */
1811 csr13val = setup[0];
1812 csr14val = setup[1];
1813 csr15dir = (setup[3]<<16) | setup[2];
1814 csr15val = (setup[4]<<16) | setup[2];
1815 outl(0, ioaddr + CSR13);
1816 outl(csr14val, ioaddr + CSR14);
1817 outl(csr15dir, ioaddr + CSR15); /* Direction */
1818 outl(csr15val, ioaddr + CSR15); /* Data */
1819 outl(csr13val, ioaddr + CSR13);
1822 csr14val = 0x0003FF7F;
1823 csr15dir = (setup[0]<<16) | 0x0008;
1824 csr15val = (setup[1]<<16) | 0x0008;
1825 if (tp->if_port <= 4)
1826 csr14val = t21142_csr14[tp->if_port];
1828 outl(0, ioaddr + CSR13);
1829 outl(csr14val, ioaddr + CSR14);
1831 outl(csr15dir, ioaddr + CSR15); /* Direction */
1832 outl(csr15val, ioaddr + CSR15); /* Data */
1833 if (startup) outl(csr13val, ioaddr + CSR13);
1836 if (tulip_debug > 1)
1837 printf("%s: Setting CSR15 to %X/%X.\n",
1838 tp->nic_name, csr15dir, csr15val);
1840 if (mleaf->type == 4)
1841 new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
1843 new_csr6 = 0x82420000;
1848 int init_length = p[1];
1852 new_csr6 = 0x020E0000;
1853 if (mleaf->type == 3) { /* 21142 */
1854 u16 *init_sequence = (u16*)(p+2);
1855 u16 *reset_sequence = &((u16*)(p+3))[init_length];
1856 int reset_length = p[2 + init_length*2];
1857 misc_info = reset_sequence + reset_length;
1859 for (i = 0; i < reset_length; i++)
1860 outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
1861 for (i = 0; i < init_length; i++)
1862 outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
1864 u8 *init_sequence = p + 2;
1865 u8 *reset_sequence = p + 3 + init_length;
1866 int reset_length = p[2 + init_length];
1867 misc_info = (u16*)(reset_sequence + reset_length);
1869 outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
1870 for (i = 0; i < reset_length; i++)
1871 outl(reset_sequence[i], ioaddr + CSR12);
1873 for (i = 0; i < init_length; i++)
1874 outl(init_sequence[i], ioaddr + CSR12);
1876 tp->advertising[phy_num] = get_u16(&misc_info[1]) | 1;
1878 if (tp->mii_advertise == 0)
1879 tp->mii_advertise = tp->advertising[phy_num];
1881 if (tulip_debug > 1)
1882 printf("%s: Advertising %hX on MII %d.\n",
1883 tp->nic_name, tp->mii_advertise, tp->phys[phy_num]);
1885 mdio_write(nic, tp->phys[phy_num], 4, tp->mii_advertise);
1890 printf("%s: Invalid media table selection %d.\n",
1891 tp->nic_name, mleaf->type);
1892 new_csr6 = 0x020E0000;
1895 if (tulip_debug > 1)
1896 printf("%s: Using media type %s, CSR12 is %hhX.\n",
1897 tp->nic_name, medianame[tp->if_port],
1898 inl(ioaddr + CSR12) & 0xff);
1900 } else if (tp->chip_id == DC21041) {
1901 int port = tp->if_port <= 4 ? tp->if_port : 0;
1903 if (tulip_debug > 1)
1904 printf("%s: 21041 using media %s, CSR12 is %hX.\n",
1905 tp->nic_name, medianame[port == 3 ? 12: port],
1906 inl(ioaddr + CSR12));
1908 outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1909 outl(t21041_csr14[port], ioaddr + CSR14);
1910 outl(t21041_csr15[port], ioaddr + CSR15);
1911 outl(t21041_csr13[port], ioaddr + CSR13);
1912 new_csr6 = 0x80020000;
1913 } else if (tp->chip_id == LC82C168) {
1914 if (startup && ! tp->medialock)
1915 tp->if_port = tp->mii_cnt ? 11 : 0;
1917 if (tulip_debug > 1)
1918 printf("%s: PNIC PHY status is %hX, media %s.\n",
1919 tp->nic_name, inl(ioaddr + 0xB8), medianame[tp->if_port]);
1922 new_csr6 = 0x810C0000;
1923 outl(0x0001, ioaddr + CSR15);
1924 outl(0x0201B07A, ioaddr + 0xB8);
1925 } else if (startup) {
1926 /* Start with 10mbps to do autonegotiation. */
1927 outl(0x32, ioaddr + CSR12);
1928 new_csr6 = 0x00420000;
1929 outl(0x0001B078, ioaddr + 0xB8);
1930 outl(0x0201B078, ioaddr + 0xB8);
1931 } else if (tp->if_port == 3 || tp->if_port == 5) {
1932 outl(0x33, ioaddr + CSR12);
1933 new_csr6 = 0x01860000;
1934 /* Trigger autonegotiation. */
1935 outl(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);
1937 outl(0x32, ioaddr + CSR12);
1938 new_csr6 = 0x00420000;
1939 outl(0x1F078, ioaddr + 0xB8);
1941 } else if (tp->chip_id == DC21040) { /* 21040 */
1942 /* Turn on the xcvr interface. */
1944 int csr12 = inl(ioaddr + CSR12);
1945 if (tulip_debug > 1)
1946 printf("%s: 21040 media type is %s, CSR12 is %hhX.\n",
1947 tp->nic_name, medianame[tp->if_port], csr12);
1949 if (media_cap[tp->if_port] & MediaAlwaysFD)
1950 tp->full_duplex = 1;
1952 /* Set the full duplux match frame. */
1953 outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
1954 outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1955 if (t21040_csr13[tp->if_port] & 8) {
1956 outl(0x0705, ioaddr + CSR14);
1957 outl(0x0006, ioaddr + CSR15);
1959 outl(0xffff, ioaddr + CSR14);
1960 outl(0x0000, ioaddr + CSR15);
1962 outl(0x8f01 | t21040_csr13[tp->if_port], ioaddr + CSR13);
1963 } else { /* Unknown chip type with no media table. */
1964 if (tp->default_port == 0)
1965 tp->if_port = tp->mii_cnt ? 11 : 3;
1966 if (media_cap[tp->if_port] & MediaIsMII) {
1967 new_csr6 = 0x020E0000;
1968 } else if (media_cap[tp->if_port] & MediaIsFx) {
1969 new_csr6 = 0x028600000;
1971 new_csr6 = 0x038600000;
1973 if (tulip_debug > 1)
1974 printf("%s: No media description table, assuming "
1975 "%s transceiver, CSR12 %hhX.\n",
1976 tp->nic_name, medianame[tp->if_port],
1977 inl(ioaddr + CSR12));
1981 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
1986 Check the MII negotiated duplex and change the CSR6 setting if
1988 Return 0 if everything is OK.
1989 Return < 0 if the transceiver is missing or has no link beat.
1991 static int tulip_check_duplex(struct nic *nic)
1993 unsigned int bmsr, lpa, negotiated, new_csr6;
1995 bmsr = mdio_read(nic, tp->phys[0], 1);
1996 lpa = mdio_read(nic, tp->phys[0], 5);
1999 if (tulip_debug > 1)
2000 printf("%s: MII status %#x, Link partner report "
2001 "%#x.\n", tp->nic_name, bmsr, lpa);
2006 if ((bmsr & 4) == 0) {
2007 int new_bmsr = mdio_read(nic, tp->phys[0], 1);
2008 if ((new_bmsr & 4) == 0) {
2010 if (tulip_debug > 1)
2011 printf("%s: No link beat on the MII interface,"
2012 " status %#x.\n", tp->nic_name,
2018 tp->full_duplex = lpa & 0x140;
2020 new_csr6 = tp->csr6;
2021 negotiated = lpa & tp->advertising[0];
2023 if(negotiated & 0x380) new_csr6 &= ~0x400000;
2024 else new_csr6 |= 0x400000;
2025 if (tp->full_duplex) new_csr6 |= 0x200;
2026 else new_csr6 &= ~0x200;
2028 if (new_csr6 != tp->csr6) {
2029 tp->csr6 = new_csr6;
2032 if (tulip_debug > 0)
2033 printf("%s: Setting %s-duplex based on MII"
2034 "#%d link partner capability of %#x.\n",
2036 tp->full_duplex ? "full" : "half",
2045 static struct pci_device_id tulip_nics[] = {
2046 PCI_ROM(0x1011, 0x0002, "dc21040", "Digital Tulip"),
2047 PCI_ROM(0x1011, 0x0009, "ds21140", "Digital Tulip Fast"),
2048 PCI_ROM(0x1011, 0x0014, "dc21041", "Digital Tulip+"),
2049 PCI_ROM(0x1011, 0x0019, "ds21142", "Digital Tulip 21142"),
2050 PCI_ROM(0x10b7, 0x9300, "3csoho100b-tx","3ComSOHO100B-TX"),
2051 PCI_ROM(0x10b9, 0x5261, "ali1563", "ALi 1563 integrated ethernet"),
2052 PCI_ROM(0x10d9, 0x0512, "mx98713", "Macronix MX987x3"),
2053 PCI_ROM(0x10d9, 0x0531, "mx98715", "Macronix MX987x5"),
2054 PCI_ROM(0x1113, 0x1217, "mxic-98715", "Macronix MX987x5"),
2055 PCI_ROM(0x11ad, 0xc115, "lc82c115", "LinkSys LNE100TX"),
2056 PCI_ROM(0x11ad, 0x0002, "82c168", "Netgear FA310TX"),
2057 PCI_ROM(0x1282, 0x9100, "dm9100", "Davicom 9100"),
2058 PCI_ROM(0x1282, 0x9102, "dm9102", "Davicom 9102"),
2059 PCI_ROM(0x1282, 0x9009, "dm9009", "Davicom 9009"),
2060 PCI_ROM(0x1282, 0x9132, "dm9132", "Davicom 9132"),
2061 PCI_ROM(0x1317, 0x0985, "centaur-p", "ADMtek Centaur-P"),
2062 PCI_ROM(0x1317, 0x0981, "an981", "ADMtek AN981 Comet"), /* ADMTek Centaur-P (stmicro) */
2063 PCI_ROM(0x1113, 0x1216, "an983", "ADMTek AN983 Comet"),
2064 PCI_ROM(0x1317, 0x9511, "an983b", "ADMTek Comet 983b"),
2065 PCI_ROM(0x1317, 0x1985, "centaur-c", "ADMTek Centaur-C"),
2066 PCI_ROM(0x8086, 0x0039, "intel21145", "Intel Tulip"),
2067 PCI_ROM(0x125b, 0x1400, "ax88140", "ASIX AX88140"),
2068 PCI_ROM(0x11f6, 0x9881, "rl100tx", "Compex RL100-TX"),
2069 PCI_ROM(0x115d, 0x0003, "xircomtulip", "Xircom Tulip"),
2070 PCI_ROM(0x104a, 0x0981, "tulip-0981", "Tulip 0x104a 0x0981"),
2071 PCI_ROM(0x104a, 0x2774, "SGThomson-STE10100A", "Tulip 0x104a 0x2774"), /*Modified by Ramesh Chander*/
2072 PCI_ROM(0x1113, 0x9511, "tulip-9511", "Tulip 0x1113 0x9511"),
2073 PCI_ROM(0x1186, 0x1561, "tulip-1561", "Tulip 0x1186 0x1561"),
2074 PCI_ROM(0x1259, 0xa120, "tulip-a120", "Tulip 0x1259 0xa120"),
2075 PCI_ROM(0x13d1, 0xab02, "tulip-ab02", "Tulip 0x13d1 0xab02"),
2076 PCI_ROM(0x13d1, 0xab03, "tulip-ab03", "Tulip 0x13d1 0xab03"),
2077 PCI_ROM(0x13d1, 0xab08, "tulip-ab08", "Tulip 0x13d1 0xab08"),
2078 PCI_ROM(0x14f1, 0x1803, "lanfinity", "Conexant LANfinity"),
2079 PCI_ROM(0x1626, 0x8410, "tulip-8410", "Tulip 0x1626 0x8410"),
2080 PCI_ROM(0x1737, 0xab08, "tulip-1737-ab08","Tulip 0x1737 0xab08"),
2081 PCI_ROM(0x1737, 0xab09, "tulip-ab09", "Tulip 0x1737 0xab09"),
2084 PCI_DRIVER ( tulip_driver, tulip_nics, PCI_NO_CLASS );
2086 DRIVER ( "Tulip", nic_driver, pci_driver, tulip_driver,
2087 tulip_probe, tulip_disable );