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 11 Apr 2001 mdc [patch to etherboot 4.7.24]
52 Major rewrite to include Linux tulip driver media detection
53 code. This driver should support a lot more cards now.
54 16 Jul 2000 mdc 0.75b11
55 Added support for ADMtek 0985 Centaur-P, a "Comet" tulip clone
56 which is used on the LinkSYS LNE100TX v4.x cards. We already
57 support LNE100TX v2.0 cards, which use a different controller.
59 Added test of status after receiving a packet from the card.
60 Also uncommented the tulip_disable routine. Stray packets
61 seemed to be causing problems.
63 29 Feb 2000 mdc 0.75b7
64 Increased reset delay to 3 seconds because Macronix cards seem to
65 need more reset time before card comes back to a usable state.
66 26 Feb 2000 mdc 0.75b6
67 Added a 1 second delay after initializing the transmitter because
68 some cards seem to need the time or they drop the first packet
70 23 Feb 2000 mdc 0.75b5
71 removed udelay code and used currticks() for more reliable delay
72 code in reset pause and sanity timeouts. Added function prototypes
73 and TX debugging code.
74 21 Feb 2000 mdc patch to Etherboot 4.4.3
75 Incorporated patches from Bob Edwards and Paul Mackerras of
76 Linuxcare's OZLabs to deal with inefficiencies in tulip_transmit
77 and udelay. We now wait for packet transmission to complete
79 04 Feb 2000 Robert.Edwards@anu.edu.au patch to Etherboot 4.4.2
80 patch to tulip.c that implements the automatic selection of the MII
81 interface on cards using the Intel/DEC 21143 reference design, in
82 particular, the TRENDnet TE100-PCIA NIC which uses a genuine Intel
84 11 Jan 2000 mdc 0.75b4
85 Added support for NetGear FA310TX card based on the LC82C168
86 chip. This should also support Lite-On LC82C168 boards.
87 Added simple MII support. Re-arranged code to better modularize
89 04 Dec 1999 mdc 0.75b3
90 Added preliminary support for LNE100TX PCI cards. Should work for
91 PNIC2 cards. No MII support, but single interface (RJ45) tulip
92 cards seem to not care.
93 03 Dec 1999 mdc 0.75b2
94 Renamed from mx987x5 to tulip, merged in original tulip init code
95 from tulip.c to support other tulip compatible cards.
96 02 Dec 1999 mdc 0.75b1
97 Released Beta MX987x5 Driver for code review and testing to netboot
98 and thinguin mailing lists.
102 /*********************************************************************/
104 /*********************************************************************/
106 #include "etherboot.h"
111 /* User settable parameters */
114 #undef TULIP_DEBUG_WHERE
115 static int tulip_debug
= 2; /* 1 normal messages, 0 quiet .. 7 verbose. */
117 #define TX_TIME_OUT 2*TICKS_PER_SEC
119 typedef unsigned char u8
;
120 typedef signed char s8
;
121 typedef unsigned short u16
;
122 typedef signed short s16
;
123 typedef unsigned int u32
;
124 typedef signed int s32
;
126 /* helpful macros if on a big_endian machine for changing byte order.
127 not strictly needed on Intel */
128 #define le16_to_cpu(val) (val)
129 #define cpu_to_le32(val) (val)
130 #define get_unaligned(ptr) (*(ptr))
131 #define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
132 #define get_u16(ptr) (*(u16 *)(ptr))
133 #define virt_to_bus(x) ((unsigned long)x)
134 #define virt_to_le32desc(addr) virt_to_bus(addr)
136 #define TULIP_IOTYPE PCI_USES_MASTER | PCI_USES_IO | PCI_ADDR0
137 #define TULIP_SIZE 0x80
139 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
140 to support a pre-NWay full-duplex signaling mechanism using short frames.
141 No one knows what it should be, but if left at its default value some
142 10base2(!) packets trigger a full-duplex-request interrupt. */
143 #define FULL_DUPLEX_MAGIC 0x6969
145 static const int csr0
= 0x01A00000 | 0x8000;
147 /* The possible media types that can be set in options[] are: */
148 #define MEDIA_MASK 31
149 static const char * const medianame
[32] = {
150 "10baseT", "10base2", "AUI", "100baseTx",
151 "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
152 "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
153 "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
154 "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
157 /* This much match tulip_tbl[]! Note 21142 == 21143. */
159 DC21040
=0, DC21041
=1, DC21140
=2, DC21142
=3, DC21143
=3,
160 LC82C168
, MX98713
, MX98715
, MX98725
, AX88141
, AX88140
, PNIC2
, COMET
,
161 COMPEX9881
, I21145
, XIRCOM
164 enum pci_id_flags_bits
{
165 /* Set PCI command register bits before calling probe1(). */
166 PCI_USES_IO
=1, PCI_USES_MEM
=2, PCI_USES_MASTER
=4,
167 /* Read and map the single following PCI BAR. */
168 PCI_ADDR0
=0<<4, PCI_ADDR1
=1<<4, PCI_ADDR2
=2<<4, PCI_ADDR3
=3<<4,
169 PCI_ADDR_64BITS
=0x100, PCI_NO_ACPI_WAKE
=0x200, PCI_NO_MIN_LATENCY
=0x400,
170 PCI_UNUSED_IRQ
=0x800,
176 u32 pci
, pci_mask
, subsystem
, subsystem_mask
;
177 u32 revision
, revision_mask
; /* Only 8 bits. */
179 enum pci_id_flags_bits pci_flags
;
180 int io_size
; /* Needed for I/O region check or ioremap(). */
181 int drv_flags
; /* Driver use, intended as capability flags. */
184 static struct pci_id_info pci_id_tbl
[] = {
185 { "Digital DC21040 Tulip", { 0x00021011, 0xffffffff, 0, 0, 0, 0 },
186 TULIP_IOTYPE
, 0x80, DC21040
},
187 { "Digital DC21041 Tulip", { 0x00141011, 0xffffffff, 0, 0, 0, 0 },
188 TULIP_IOTYPE
, 0x80, DC21041
},
189 { "Digital DS21140A Tulip", { 0x00091011, 0xffffffff, 0,0, 0x20,0xf0 },
190 TULIP_IOTYPE
, 0x80, DC21140
},
191 { "Digital DS21140 Tulip", { 0x00091011, 0xffffffff, 0, 0, 0, 0 },
192 TULIP_IOTYPE
, 0x80, DC21140
},
193 { "Digital DS21143 Tulip", { 0x00191011, 0xffffffff, 0,0, 65,0xff },
194 TULIP_IOTYPE
, TULIP_SIZE
, DC21142
},
195 { "Digital DS21142 Tulip", { 0x00191011, 0xffffffff, 0, 0, 0, 0 },
196 TULIP_IOTYPE
, TULIP_SIZE
, DC21142
},
197 { "Kingston KNE110tx (PNIC)", { 0x000211AD, 0xffffffff, 0xf0022646, 0xffffffff, 0, 0 },
198 TULIP_IOTYPE
, 256, LC82C168
},
199 { "Lite-On 82c168 PNIC", { 0x000211AD, 0xffffffff, 0, 0, 0, 0 },
200 TULIP_IOTYPE
, 256, LC82C168
},
201 { "Macronix 98713 PMAC", { 0x051210d9, 0xffffffff, 0, 0, 0, 0 },
202 TULIP_IOTYPE
, 256, MX98713
},
203 { "Macronix 98715 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
204 TULIP_IOTYPE
, 256, MX98715
},
205 { "Macronix 98725 PMAC", { 0x053110d9, 0xffffffff, 0, 0, 0, 0 },
206 TULIP_IOTYPE
, 256, MX98725
},
207 { "ASIX AX88141", { 0x1400125B, 0xffffffff, 0,0, 0x10, 0xf0 },
208 TULIP_IOTYPE
, 128, AX88141
},
209 { "ASIX AX88140", { 0x1400125B, 0xffffffff, 0, 0, 0, 0 },
210 TULIP_IOTYPE
, 128, AX88140
},
211 { "Lite-On LC82C115 PNIC-II", { 0xc11511AD, 0xffffffff, 0, 0, 0, 0 },
212 TULIP_IOTYPE
, 256, PNIC2
},
213 { "ADMtek AN981 Comet", { 0x09811317, 0xffffffff, 0, 0, 0, 0 },
214 TULIP_IOTYPE
, 256, COMET
},
215 { "ADMtek Centaur-P", { 0x09851317, 0xffffffff, 0, 0, 0, 0 },
216 TULIP_IOTYPE
, 256, COMET
},
217 { "ADMtek Centaur-C", { 0x19851317, 0xffffffff, 0, 0, 0, 0 },
218 TULIP_IOTYPE
, 256, COMET
},
219 { "Compex RL100-TX", { 0x988111F6, 0xffffffff, 0, 0, 0, 0 },
220 TULIP_IOTYPE
, 128, COMPEX9881
},
221 { "Intel 21145 Tulip", { 0x00398086, 0xffffffff, 0, 0, 0, 0 },
222 TULIP_IOTYPE
, 128, I21145
},
223 { "Xircom Tulip clone", { 0x0003115d, 0xffffffff, 0, 0, 0, 0 },
224 TULIP_IOTYPE
, 128, XIRCOM
},
225 { "Davicom DM9102", { 0x91021282, 0xffffffff, 0, 0, 0, 0 },
226 TULIP_IOTYPE
, 0x80, DC21140
},
227 { "Davicom DM9100", { 0x91001282, 0xffffffff, 0, 0, 0, 0 },
228 TULIP_IOTYPE
, 0x80, DC21140
},
229 { "Macronix mxic-98715 (EN1217)", { 0x12171113, 0xffffffff, 0, 0, 0, 0 },
230 TULIP_IOTYPE
, 256, MX98715
},
231 { 0, { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 },
235 HAS_MII
=1, HAS_MEDIA_TABLE
=2, CSR12_IN_SROM
=4, ALWAYS_CHECK_MII
=8,
236 HAS_PWRDWN
=0x10, MC_HASH_ONLY
=0x20, /* Hash-only multicast filter. */
237 HAS_PNICNWAY
=0x80, HAS_NWAY
=0x40, /* Uses internal NWay xcvr. */
238 HAS_INTR_MITIGATION
=0x100, IS_ASIX
=0x200, HAS_8023X
=0x400,
241 /* Note: this table must match enum tulip_chips above. */
242 static struct tulip_chip_table
{
246 { "Digital DC21040 Tulip", 0},
247 { "Digital DC21041 Tulip", HAS_MEDIA_TABLE
| HAS_NWAY
},
248 { "Digital DS21140 Tulip", HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
},
249 { "Digital DS21143 Tulip", HAS_MII
| HAS_MEDIA_TABLE
| ALWAYS_CHECK_MII
250 | HAS_PWRDWN
| HAS_NWAY
| HAS_INTR_MITIGATION
},
251 { "Lite-On 82c168 PNIC", HAS_MII
| HAS_PNICNWAY
},
252 { "Macronix 98713 PMAC", HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
},
253 { "Macronix 98715 PMAC", HAS_MEDIA_TABLE
},
254 { "Macronix 98725 PMAC", HAS_MEDIA_TABLE
},
255 { "ASIX AX88140", HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
256 | MC_HASH_ONLY
| IS_ASIX
},
257 { "ASIX AX88141", HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
| MC_HASH_ONLY
259 { "Lite-On PNIC-II", HAS_MII
| HAS_NWAY
| HAS_8023X
},
260 { "ADMtek Comet", MC_HASH_ONLY
},
261 { "Compex 9881 PMAC", HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
},
262 { "Intel DS21145 Tulip", HAS_MII
| HAS_MEDIA_TABLE
| ALWAYS_CHECK_MII
263 | HAS_PWRDWN
| HAS_NWAY
},
264 { "Xircom tulip work-alike", HAS_MII
| HAS_MEDIA_TABLE
| ALWAYS_CHECK_MII
265 | HAS_PWRDWN
| HAS_NWAY
},
269 /* A full-duplex map for media types. */
271 MediaIsFD
= 1, MediaAlwaysFD
=2, MediaIsMII
=4, MediaIsFx
=8,
274 static const char media_cap
[32] =
275 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 20,31,0,0, };
276 static u8 t21040_csr13
[] = {2,0x0C,8,4, 4,0,0,0, 0,0,0,0, 4,0,0,0};
278 /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD */
279 static u16 t21041_csr13
[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
280 static u16 t21041_csr14
[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
281 static u16 t21041_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
283 static u16 t21142_csr13
[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
284 static u16 t21142_csr14
[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
285 static u16 t21142_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
287 /* Offsets to the Command and Status Registers, "CSRs". All accesses
288 must be longword instructions and quadword aligned. */
290 CSR0
=0, CSR1
=0x08, CSR2
=0x10, CSR3
=0x18, CSR4
=0x20, CSR5
=0x28,
291 CSR6
=0x30, CSR7
=0x38, CSR8
=0x40, CSR9
=0x48, CSR10
=0x50, CSR11
=0x58,
292 CSR12
=0x60, CSR13
=0x68, CSR14
=0x70, CSR15
=0x78, CSR16
=0x80, CSR20
=0xA0
295 /* The bits in the CSR5 status registers, mostly interrupt sources. */
297 TimerInt
=0x800, TPLnkFail
=0x1000, TPLnkPass
=0x10,
298 NormalIntr
=0x10000, AbnormalIntr
=0x8000,
299 RxJabber
=0x200, RxDied
=0x100, RxNoBuf
=0x80, RxIntr
=0x40,
300 TxFIFOUnderflow
=0x20, TxJabber
=0x08, TxNoBuf
=0x04, TxDied
=0x02, TxIntr
=0x01,
303 enum desc_status_bits
{
304 DescOwnded
=0x80000000, RxDescFatalErr
=0x8000, RxWholePkt
=0x0300,
310 unsigned char *leafdata
;
315 u8 leafcount
, csr12dir
; /* General purpose pin directions. */
316 unsigned has_mii
:1, has_nonmii
:1, has_reset
:6;
317 u32 csr15dir
, csr15val
; /* 21143 NWay setting. */
318 struct medialeaf mleaf
[0];
322 struct mediainfo
*next
;
328 /* EEPROM Address width definitions */
329 #define EEPROM_ADDRLEN 6
330 #define EEPROM_SIZE 128 /* 2 << EEPROM_ADDRLEN */
332 /* The EEPROM commands include the alway-set leading bit. */
333 #define EE_WRITE_CMD (5 << addr_len)
334 #define EE_READ_CMD (6 << addr_len)
335 #define EE_ERASE_CMD (7 << addr_len)
337 /* EEPROM_Ctrl bits. */
338 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
339 #define EE_CS 0x01 /* EEPROM chip select. */
340 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
341 #define EE_WRITE_0 0x01
342 #define EE_WRITE_1 0x05
343 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
344 #define EE_ENB (0x4800 | EE_CS)
346 /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
347 implementations don't overrun the EEPROM clock. We add a bus
348 turn-around to insure that this remains true. */
349 #define eeprom_delay() inl(ee_addr)
351 /* Size of transmit and receive buffers */
354 /* Ring-wrap flag in length field, use for last ring entry.
355 0x01000000 means chain on buffer2 address,
356 0x02000000 means use the ring start address in CSR2/3.
357 Note: Some work-alike chips do not function correctly in chained mode.
358 The ASIX chip works only in chained mode.
359 Thus we indicate ring mode, but always write the 'next' field for
360 chained mode as well. */
361 #define DESC_RING_WRAP 0x02000000
363 /* transmit and receive descriptor format */
364 struct tulip_rx_desc
{
367 u32 buffer1
, buffer2
;
370 struct tulip_tx_desc
{
373 u32 buffer1
, buffer2
;
376 /*********************************************************************/
378 /*********************************************************************/
382 /* Note: transmit and receive buffers must be longword aligned and
383 longword divisable */
385 #define TX_RING_SIZE 2
386 static struct tulip_tx_desc tx_ring
[TX_RING_SIZE
] __attribute__ ((aligned(4)));
388 #ifdef USE_LOWMEM_BUFFER
389 #define txb ((char *)0x10000 - BUFLEN)
391 static unsigned char txb
[BUFLEN
] __attribute__ ((aligned(4)));
394 #define RX_RING_SIZE 4
395 static struct tulip_rx_desc rx_ring
[RX_RING_SIZE
] __attribute__ ((aligned(4)));
397 #ifdef USE_LOWMEM_BUFFER
398 #define rxb ((char *)0x10000 - RX_RING_SIZE * BUFLEN - BUFLEN)
400 static unsigned char rxb
[RX_RING_SIZE
* BUFLEN
] __attribute__ ((aligned(4)));
403 static struct tulip_private
{
405 int chip_id
; /* index into tulip_tbl[] */
406 int pci_id_idx
; /* index into pci_id_tbl[] */
409 unsigned short vendor_id
; /* PCI card vendor code */
410 unsigned short dev_id
; /* PCI card device code */
411 unsigned char ehdr
[ETH_HLEN
]; /* buffer for ethernet header */
412 const char *nic_name
;
413 unsigned int csr0
, csr6
; /* Current CSR0, CSR6 settings. */
414 unsigned int if_port
;
415 unsigned int full_duplex
; /* Full-duplex operation requested. */
416 unsigned int full_duplex_lock
;
417 unsigned int medialock
; /* Do not sense media type. */
418 unsigned int mediasense
; /* Media sensing in progress. */
419 unsigned int nway
, nwayset
; /* 21143 internal NWay. */
420 unsigned int default_port
;
421 unsigned char eeprom
[EEPROM_SIZE
]; /* Serial EEPROM contents. */
422 u8 media_table_storage
[(sizeof(struct mediatable
) + 32*sizeof(struct medialeaf
))];
423 u16 sym_advertise
, mii_advertise
; /* NWay to-advertise. */
424 struct mediatable
*mtable
;
425 u16 lpar
; /* 21143 Link partner ability. */
426 u16 advertising
[4]; /* MII advertise, from SROM table. */
427 signed char phys
[4], mii_cnt
; /* MII device addresses. */
428 int cur_index
; /* Current media index. */
432 static struct tulip_private
*tp
;
434 /* Known cards that have old-style EEPROMs.
435 Writing this table is described at
436 http://cesdis.gsfc.nasa.gov/linux/drivers/tulip-drivers/tulip-media.html */
437 static struct fixups
{
439 unsigned char addr0
, addr1
, addr2
;
440 u16 newtable
[32]; /* Max length below. */
441 } eeprom_fixups
[] = {
442 {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
443 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
444 {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f,
445 0x0000, 0x009E, /* 10baseT */
446 0x0004, 0x009E, /* 10baseT-FD */
447 0x0903, 0x006D, /* 100baseTx */
448 0x0905, 0x006D, /* 100baseTx-FD */ }},
449 {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f,
450 0x0107, 0x8021, /* 100baseFx */
451 0x0108, 0x8021, /* 100baseFx-FD */
452 0x0100, 0x009E, /* 10baseT */
453 0x0104, 0x009E, /* 10baseT-FD */
454 0x0103, 0x006D, /* 100baseTx */
455 0x0105, 0x006D, /* 100baseTx-FD */ }},
456 {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513,
457 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
458 0x0000, 0x009E, /* 10baseT */
459 0x0004, 0x009E, /* 10baseT-FD */
460 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */
461 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}},
462 {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F,
463 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
464 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
465 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */
466 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
467 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */
471 static const char * block_name
[] = {"21140 non-MII", "21140 MII PHY",
472 "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
475 /*********************************************************************/
476 /* Function Prototypes */
477 /*********************************************************************/
478 static int mdio_read(struct nic
*nic
, int phy_id
, int location
);
479 static void mdio_write(struct nic
*nic
, int phy_id
, int location
, int value
);
480 static int read_eeprom(unsigned long ioaddr
, int location
, int addr_len
);
481 static void parse_eeprom(struct nic
*nic
);
482 struct nic
*tulip_probe(struct nic
*nic
, unsigned short *io_addrs
,
483 struct pci_device
*pci
);
484 static void tulip_init_ring(struct nic
*nic
);
485 static void tulip_reset(struct nic
*nic
);
486 static void tulip_transmit(struct nic
*nic
, const char *d
, unsigned int t
,
487 unsigned int s
, const char *p
);
488 static int tulip_poll(struct nic
*nic
);
489 static void tulip_disable(struct nic
*nic
);
490 static void nway_start(struct nic
*nic
);
491 static void pnic_do_nway(struct nic
*nic
);
492 static void select_media(struct nic
*nic
, int startup
);
493 static void init_media(struct nic
*nic
);
494 static void start_link(struct nic
*nic
);
495 static int tulip_check_duplex(struct nic
*nic
);
497 static void tulip_wait(unsigned int nticks
);
499 #ifdef TULIP_DEBUG_WHERE
500 static void whereami(const char *str
);
504 static void tulip_more(void);
508 /*********************************************************************/
509 /* Utility Routines */
510 /*********************************************************************/
512 #ifdef TULIP_DEBUG_WHERE
513 static void whereami (const char *str
)
515 printf("%s: %s\n", tp
->nic_name
, str
);
521 static void tulip_more(void)
523 printf("\n\n-- more --");
529 #endif /* TULIP_DEBUG */
531 static void tulip_wait(unsigned int nticks
)
533 unsigned int to
= currticks() + nticks
;
534 while (currticks() < to
)
539 /*********************************************************************/
540 /* Media Descriptor Code */
541 /*********************************************************************/
543 /* MII transceiver control section.
544 Read and write the MII registers using software-generated serial
545 MDIO protocol. See the MII specifications or DP83840A data sheet
548 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
549 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
550 "overclocking" issues or future 66Mhz PCI. */
551 #define mdio_delay() inl(mdio_addr)
553 /* Read and write the MII registers using software-generated serial
554 MDIO protocol. It is just different enough from the EEPROM protocol
555 to not share code. The maxium data clock rate is 2.5 Mhz. */
556 #define MDIO_SHIFT_CLK 0x10000
557 #define MDIO_DATA_WRITE0 0x00000
558 #define MDIO_DATA_WRITE1 0x20000
559 #define MDIO_ENB 0x00000 /* Ignore the 0x02000 databook setting. */
560 #define MDIO_ENB_IN 0x40000
561 #define MDIO_DATA_READ 0x80000
563 /* MII transceiver control section.
564 Read and write the MII registers using software-generated serial
565 MDIO protocol. See the MII specifications or DP83840A data sheet
568 int mdio_read(struct nic
*nic
, int phy_id
, int location
)
571 int read_cmd
= (0xf6 << 10) | (phy_id
<< 5) | location
;
573 long mdio_addr
= ioaddr
+ CSR9
;
575 #ifdef TULIP_DEBUG_WHERE
576 whereami("mdio_read\n");
579 if (tp
->chip_id
== LC82C168
) {
581 outl(0x60020000 + (phy_id
<<23) + (location
<<18), ioaddr
+ 0xA0);
585 if ( ! ((retval
= inl(ioaddr
+ 0xA0)) & 0x80000000))
586 return retval
& 0xffff;
590 if (tp
->chip_id
== COMET
) {
593 return inl(ioaddr
+ 0xB4 + (location
<<2));
594 else if (location
== 17)
595 return inl(ioaddr
+ 0xD0);
596 else if (location
>= 29 && location
<= 31)
597 return inl(ioaddr
+ 0xD4 + ((location
-29)<<2));
602 /* Establish sync by sending at least 32 logic ones. */
603 for (i
= 32; i
>= 0; i
--) {
604 outl(MDIO_ENB
| MDIO_DATA_WRITE1
, mdio_addr
);
606 outl(MDIO_ENB
| MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, mdio_addr
);
609 /* Shift the read command bits out. */
610 for (i
= 15; i
>= 0; i
--) {
611 int dataval
= (read_cmd
& (1 << i
)) ? MDIO_DATA_WRITE1
: 0;
613 outl(MDIO_ENB
| dataval
, mdio_addr
);
615 outl(MDIO_ENB
| dataval
| MDIO_SHIFT_CLK
, mdio_addr
);
618 /* Read the two transition, 16 data, and wire-idle bits. */
619 for (i
= 19; i
> 0; i
--) {
620 outl(MDIO_ENB_IN
, mdio_addr
);
622 retval
= (retval
<< 1) | ((inl(mdio_addr
) & MDIO_DATA_READ
) ? 1 : 0);
623 outl(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
);
626 return (retval
>>1) & 0xffff;
629 void mdio_write(struct nic
*nic
, int phy_id
, int location
, int value
)
632 int cmd
= (0x5002 << 16) | (phy_id
<< 23) | (location
<<18) | value
;
633 long mdio_addr
= ioaddr
+ CSR9
;
635 #ifdef TULIP_DEBUG_WHERE
636 whereami("mdio_write\n");
639 if (tp
->chip_id
== LC82C168
) {
641 outl(cmd
, ioaddr
+ 0xA0);
643 if ( ! (inl(ioaddr
+ 0xA0) & 0x80000000))
649 if (tp
->chip_id
== COMET
) {
653 outl(value
, ioaddr
+ 0xB4 + (location
<<2));
654 else if (location
== 17)
655 outl(value
, ioaddr
+ 0xD0);
656 else if (location
>= 29 && location
<= 31)
657 outl(value
, ioaddr
+ 0xD4 + ((location
-29)<<2));
661 /* Establish sync by sending 32 logic ones. */
662 for (i
= 32; i
>= 0; i
--) {
663 outl(MDIO_ENB
| MDIO_DATA_WRITE1
, mdio_addr
);
665 outl(MDIO_ENB
| MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, mdio_addr
);
668 /* Shift the command bits out. */
669 for (i
= 31; i
>= 0; i
--) {
670 int dataval
= (cmd
& (1 << i
)) ? MDIO_DATA_WRITE1
: 0;
671 outl(MDIO_ENB
| dataval
, mdio_addr
);
673 outl(MDIO_ENB
| dataval
| MDIO_SHIFT_CLK
, mdio_addr
);
676 /* Clear out extra bits. */
677 for (i
= 2; i
> 0; i
--) {
678 outl(MDIO_ENB_IN
, mdio_addr
);
680 outl(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
);
686 /*********************************************************************/
687 /* EEPROM Reading Code */
688 /*********************************************************************/
689 /* EEPROM routines adapted from the Linux Tulip Code */
690 /* Reading a serial EEPROM is a "bit" grungy, but we work our way
693 static int read_eeprom(unsigned long ioaddr
, int location
, int addr_len
)
696 unsigned short retval
= 0;
697 long ee_addr
= ioaddr
+ CSR9
;
698 int read_cmd
= location
| EE_READ_CMD
;
700 #ifdef TULIP_DEBUG_WHERE
701 whereami("read_eeprom\n");
704 outl(EE_ENB
& ~EE_CS
, ee_addr
);
705 outl(EE_ENB
, ee_addr
);
707 /* Shift the read command bits out. */
708 for (i
= 4 + addr_len
; i
>= 0; i
--) {
709 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
710 outl(EE_ENB
| dataval
, ee_addr
);
712 outl(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
715 outl(EE_ENB
, ee_addr
);
717 for (i
= 16; i
> 0; i
--) {
718 outl(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
720 retval
= (retval
<< 1) | ((inl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
721 outl(EE_ENB
, ee_addr
);
725 /* Terminate the EEPROM access. */
726 outl(EE_ENB
& ~EE_CS
, ee_addr
);
731 /*********************************************************************/
732 /* EEPROM Parsing Code */
733 /*********************************************************************/
734 static void parse_eeprom(struct nic
*nic
)
736 unsigned char *p
, *ee_data
= tp
->eeprom
;
737 int new_advertise
= 0;
740 #ifdef TULIP_DEBUG_WHERE
741 whereami("parse_eeprom\n");
745 /* Detect an old-style (SA only) EEPROM layout:
746 memcmp(ee_data, ee_data+16, 8). */
747 for (i
= 0; i
< 8; i
++)
748 if (ee_data
[i
] != ee_data
[16+i
])
751 /* Do a fix-up based on the vendor half of the station address. */
752 for (i
= 0; eeprom_fixups
[i
].name
; i
++) {
753 if (nic
->node_addr
[0] == eeprom_fixups
[i
].addr0
754 && nic
->node_addr
[1] == eeprom_fixups
[i
].addr1
755 && nic
->node_addr
[2] == eeprom_fixups
[i
].addr2
) {
756 if (nic
->node_addr
[2] == 0xE8 && ee_data
[0x1a] == 0x55)
757 i
++; /* An Accton EN1207, not an outlaw Maxtech. */
758 memcpy(ee_data
+ 26, eeprom_fixups
[i
].newtable
,
759 sizeof(eeprom_fixups
[i
].newtable
));
761 printf("%s: Old format EEPROM on '%s' board.\n%s: Using substitute media control info.\n",
762 tp
->nic_name
, eeprom_fixups
[i
].name
, tp
->nic_name
);
767 if (eeprom_fixups
[i
].name
== NULL
) { /* No fixup found. */
769 printf("%s: Old style EEPROM with no media selection information.\n",
776 if (ee_data
[19] > 1) {
778 printf("%s: Multiport cards (%d ports) may not work correctly.\n",
779 tp
->nic_name
, ee_data
[19]);
783 p
= (void *)ee_data
+ ee_data
[27];
785 if (ee_data
[27] == 0) { /* No valid media table. */
787 if (tulip_debug
> 1) {
788 printf("%s: No Valid Media Table. ee_data[27] = %hhX\n",
789 tp
->nic_name
, ee_data
[27]);
792 } else if (tp
->chip_id
== DC21041
) {
793 int media
= get_u16(p
);
797 printf("%s: 21041 Media table, default media %hX (%s).\n",
799 media
& 0x0800 ? "Autosense" : medianame
[media
& 15]);
800 for (i
= 0; i
< count
; i
++) {
801 unsigned char media_block
= *p
++;
802 int media_code
= media_block
& MEDIA_MASK
;
803 if (media_block
& 0x40)
806 case 0: new_advertise
|= 0x0020; break;
807 case 4: new_advertise
|= 0x0040; break;
809 printf("%s: 21041 media #%d, %s.\n",
810 tp
->nic_name
, media_code
, medianame
[media_code
]);
813 unsigned char csr12dir
= 0;
815 struct mediatable
*mtable
;
816 u16 media
= get_u16(p
);
819 if (tp
->flags
& CSR12_IN_SROM
)
823 tp
->mtable
= mtable
= (struct mediatable
*)&tp
->media_table_storage
[0];
825 mtable
->defaultmedia
= media
;
826 mtable
->leafcount
= count
;
827 mtable
->csr12dir
= csr12dir
;
828 mtable
->has_nonmii
= mtable
->has_mii
= mtable
->has_reset
= 0;
829 mtable
->csr15dir
= mtable
->csr15val
= 0;
831 printf("%s: EEPROM default media type %s.\n", tp
->nic_name
,
832 media
& 0x0800 ? "Autosense" : medianame
[media
& MEDIA_MASK
]);
834 for (i
= 0; i
< count
; i
++) {
835 struct medialeaf
*leaf
= &mtable
->mleaf
[i
];
837 if ((p
[0] & 0x80) == 0) { /* 21140 Compact block. */
839 leaf
->media
= p
[0] & 0x3f;
841 if ((p
[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
845 switch(leaf
->type
= p
[1]) {
847 mtable
->has_reset
= i
;
848 leaf
->media
= p
[2] & 0x0f;
855 if ((p
[2] & 0x3f) == 0) {
856 u32 base15
= (p
[2] & 0x40) ? get_u16(p
+ 7) : 0x0008;
857 u16
*p1
= (u16
*)(p
+ (p
[2] & 0x40 ? 9 : 3));
858 mtable
->csr15dir
= (get_unaligned(p1
+ 0)<<16) + base15
;
859 mtable
->csr15val
= (get_unaligned(p1
+ 1)<<16) + base15
;
863 mtable
->has_nonmii
= 1;
864 leaf
->media
= p
[2] & MEDIA_MASK
;
865 switch (leaf
->media
) {
866 case 0: new_advertise
|= 0x0020; break;
867 case 4: new_advertise
|= 0x0040; break;
868 case 3: new_advertise
|= 0x0080; break;
869 case 5: new_advertise
|= 0x0100; break;
870 case 6: new_advertise
|= 0x0200; break;
876 leaf
->leafdata
= p
+ 2;
877 p
+= (p
[0] & 0x3f) + 1;
880 if (tulip_debug
> 1 && leaf
->media
== 11) {
881 unsigned char *bp
= leaf
->leafdata
;
882 printf("%s: MII interface PHY %d, setup/reset sequences %d/%d long, capabilities %hhX %hhX.\n",
883 tp
->nic_name
, bp
[0], bp
[1], bp
[2 + bp
[1]*2],
884 bp
[5 + bp
[2 + bp
[1]*2]*2], bp
[4 + bp
[2 + bp
[1]*2]*2]);
887 printf("%s: Index #%d - Media %s (#%d) described "
888 "by a %s (%d) block.\n",
889 tp
->nic_name
, i
, medianame
[leaf
->media
], leaf
->media
,
890 leaf
->type
< 6 ? block_name
[leaf
->type
] : "UNKNOWN",
894 tp
->sym_advertise
= new_advertise
;
899 /*********************************************************************/
900 /* tulip_init_ring - setup the tx and rx descriptors */
901 /*********************************************************************/
902 static void tulip_init_ring(struct nic
*nic
)
906 #ifdef TULIP_DEBUG_WHERE
907 whereami("tulip_init_ring\n");
912 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
913 rx_ring
[i
].status
= cpu_to_le32(0x80000000);
914 rx_ring
[i
].length
= cpu_to_le32(BUFLEN
);
915 rx_ring
[i
].buffer1
= virt_to_le32desc(&rxb
[i
* BUFLEN
]);
916 rx_ring
[i
].buffer2
= virt_to_le32desc(&rx_ring
[i
+1]);
918 /* Mark the last entry as wrapping the ring. */
919 rx_ring
[i
-1].length
= cpu_to_le32(DESC_RING_WRAP
| BUFLEN
);
920 rx_ring
[i
-1].buffer2
= virt_to_le32desc(&rx_ring
[0]);
922 /* We only use 1 transmit buffer, but we use 2 descriptors so
923 transmit engines have somewhere to point to if they feel the need */
925 tx_ring
[0].status
= 0x00000000;
926 tx_ring
[0].buffer1
= virt_to_le32desc(&txb
[0]);
927 tx_ring
[0].buffer2
= virt_to_le32desc(&tx_ring
[1]);
929 /* this descriptor should never get used, since it will never be owned
930 by the machine (status will always == 0) */
931 tx_ring
[1].status
= 0x00000000;
932 tx_ring
[1].buffer1
= virt_to_le32desc(&txb
[0]);
933 tx_ring
[1].buffer2
= virt_to_le32desc(&tx_ring
[0]);
935 /* Mark the last entry as wrapping the ring, though this should never happen */
936 tx_ring
[1].length
= cpu_to_le32(DESC_RING_WRAP
| BUFLEN
);
939 /*********************************************************************/
940 /* eth_reset - Reset adapter */
941 /*********************************************************************/
942 static void tulip_reset(struct nic
*nic
)
946 u32 addr_low
, addr_high
;
948 #ifdef TULIP_DEBUG_WHERE
949 whereami("tulip_reset\n");
953 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
955 /* On some chip revs we must set the MII/SYM port before the reset!? */
956 if (tp
->mii_cnt
|| (tp
->mtable
&& tp
->mtable
->has_mii
)) {
957 outl(0x814C0000, ioaddr
+ CSR6
);
960 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
961 outl(0x00000001, ioaddr
+ CSR0
);
964 /* turn off reset and set cache align=16lword, burst=unlimit */
965 outl(tp
->csr0
, ioaddr
+ CSR0
);
967 /* Wait the specified 50 PCI cycles after a reset */
970 /* set up transmit and receive descriptors */
971 tulip_init_ring(nic
);
973 if (tp
->chip_id
== PNIC2
) {
974 u32 addr_high
= (nic
->node_addr
[1]<<8) + (nic
->node_addr
[0]<<0);
975 /* This address setting does not appear to impact chip operation?? */
976 outl((nic
->node_addr
[5]<<8) + nic
->node_addr
[4] +
977 (nic
->node_addr
[3]<<24) + (nic
->node_addr
[2]<<16),
979 outl(addr_high
+ (addr_high
<<16), ioaddr
+ 0xB8);
982 /* MC_HASH_ONLY boards don't support setup packets */
983 if (tp
->flags
& MC_HASH_ONLY
) {
984 u32 addr_low
= cpu_to_le32(get_unaligned((u32
*)nic
->node_addr
));
985 u32 addr_high
= cpu_to_le32(get_unaligned((u16
*)(nic
->node_addr
+4)));
987 /* clear multicast hash filters and setup MAC address filters */
988 if (tp
->flags
& IS_ASIX
) {
989 outl(0, ioaddr
+ CSR13
);
990 outl(addr_low
, ioaddr
+ CSR14
);
991 outl(1, ioaddr
+ CSR13
);
992 outl(addr_high
, ioaddr
+ CSR14
);
993 outl(2, ioaddr
+ CSR13
);
994 outl(0, ioaddr
+ CSR14
);
995 outl(3, ioaddr
+ CSR13
);
996 outl(0, ioaddr
+ CSR14
);
997 } else if (tp
->chip_id
== COMET
) {
998 outl(addr_low
, ioaddr
+ 0xA4);
999 outl(addr_high
, ioaddr
+ 0xA8);
1000 outl(0, ioaddr
+ 0xAC);
1001 outl(0, ioaddr
+ 0xB0);
1004 /* for other boards we send a setup packet to initialize
1006 u32 tx_flags
= 0x08000000 | 192;
1008 /* construct perfect filter frame with mac address as first match
1009 and broadcast address for all others */
1010 for (i
=0; i
<192; i
++)
1012 txb
[0] = nic
->node_addr
[0];
1013 txb
[1] = nic
->node_addr
[1];
1014 txb
[4] = nic
->node_addr
[2];
1015 txb
[5] = nic
->node_addr
[3];
1016 txb
[8] = nic
->node_addr
[4];
1017 txb
[9] = nic
->node_addr
[5];
1019 tx_ring
[0].length
= cpu_to_le32(tx_flags
);
1020 tx_ring
[0].buffer1
= virt_to_le32desc(&txb
[0]);
1021 tx_ring
[0].status
= cpu_to_le32(0x80000000);
1024 /* Point to rx and tx descriptors */
1025 outl((unsigned long)&rx_ring
[0], ioaddr
+ CSR3
);
1026 outl((unsigned long)&tx_ring
[0], ioaddr
+ CSR4
);
1030 /* set the chip's operating mode (but don't turn on xmit and recv yet) */
1031 outl((tp
->csr6
& ~0x00002002), ioaddr
+ CSR6
);
1033 /* send setup packet for cards that support it */
1034 if (!(tp
->flags
& MC_HASH_ONLY
)) {
1035 /* enable transmit wait for completion */
1036 outl(tp
->csr6
| 0x00002000, ioaddr
+ CSR6
);
1037 /* immediate transmit demand */
1038 outl(0, ioaddr
+ CSR1
);
1040 to
= currticks() + TX_TIME_OUT
;
1041 while ((tx_ring
[0].status
& 0x80000000) && (currticks() < to
))
1044 if (currticks() >= to
) {
1045 printf ("%s: TX Setup Timeout.\n", tp
->nic_name
);
1049 if (tp
->chip_id
== LC82C168
)
1050 tulip_check_duplex(nic
);
1052 /* enable transmit and receive */
1053 outl(tp
->csr6
| 0x00002002, ioaddr
+ CSR6
);
1057 /*********************************************************************/
1058 /* eth_transmit - Transmit a frame */
1059 /*********************************************************************/
1060 static void tulip_transmit(struct nic
*nic
, const char *d
, unsigned int t
,
1061 unsigned int s
, const char *p
)
1065 u32 csr6
= inl(ioaddr
+ CSR6
);
1067 #ifdef TULIP_DEBUG_WHERE
1068 whereami("tulip_transmit\n");
1072 outl(csr6
& ~0x00002000, ioaddr
+ CSR6
);
1074 memcpy(txb
, d
, ETH_ALEN
);
1075 memcpy(txb
+ ETH_ALEN
, nic
->node_addr
, ETH_ALEN
);
1076 nstype
= htons((u16
) t
);
1077 memcpy(txb
+ 2 * ETH_ALEN
, (u8
*)&nstype
, 2);
1078 memcpy(txb
+ ETH_HLEN
, p
, s
);
1083 /* pad to minimum packet size */
1084 while (s
< ETH_ZLEN
)
1088 if (tulip_debug
> 1)
1089 printf("%s: sending %d bytes ethtype %hX\n", tp
->nic_name
, s
, t
);
1092 /* setup the transmit descriptor */
1093 /* 0x60000000 = no interrupt on completion */
1094 tx_ring
[0].length
= cpu_to_le32(0x60000000 | s
);
1095 tx_ring
[0].status
= cpu_to_le32(0x80000000);
1097 /* Point to transmit descriptor */
1098 outl((u32
)&tx_ring
[0], ioaddr
+ CSR4
);
1101 outl(csr6
| 0x00002000, ioaddr
+ CSR6
);
1102 /* immediate transmit demand */
1103 outl(0, ioaddr
+ CSR1
);
1105 to
= currticks() + TX_TIME_OUT
;
1106 while ((tx_ring
[0].status
& 0x80000000) && (currticks() < to
))
1109 if (currticks() >= to
) {
1110 printf ("TX Timeout!\n");
1114 outl(csr6
& ~0x00002000, ioaddr
+ CSR6
);
1117 /*********************************************************************/
1118 /* eth_poll - Wait for a frame */
1119 /*********************************************************************/
1120 static int tulip_poll(struct nic
*nic
)
1123 #ifdef TULIP_DEBUG_WHERE
1124 whereami("tulip_poll\n");
1127 /* no packet waiting. packet still owned by NIC */
1128 if (rx_ring
[tp
->cur_rx
].status
& 0x80000000)
1131 #ifdef TULIP_DEBUG_WHERE
1132 whereami("tulip_poll got one\n");
1135 nic
->packetlen
= (rx_ring
[tp
->cur_rx
].status
& 0x3FFF0000) >> 16;
1137 /* if we get a corrupted packet. throw it away and move on */
1138 if (rx_ring
[tp
->cur_rx
].status
& 0x00008000) {
1139 /* return the descriptor and buffer to receive ring */
1140 rx_ring
[tp
->cur_rx
].status
= 0x80000000;
1141 tp
->cur_rx
= (++tp
->cur_rx
) % RX_RING_SIZE
;
1145 /* copy packet to working buffer */
1146 memcpy(nic
->packet
, rxb
+ tp
->cur_rx
* BUFLEN
, nic
->packetlen
);
1148 /* return the descriptor and buffer to receive ring */
1149 rx_ring
[tp
->cur_rx
].status
= 0x80000000;
1150 tp
->cur_rx
= (++tp
->cur_rx
) % RX_RING_SIZE
;
1155 /*********************************************************************/
1156 /* eth_disable - Disable the interface */
1157 /*********************************************************************/
1158 static void tulip_disable(struct nic
*nic
)
1161 #ifdef TULIP_DEBUG_WHERE
1162 whereami("tulip_disable\n");
1165 /* disable interrupts */
1166 outl(0x00000000, ioaddr
+ CSR7
);
1168 /* Stop the chip's Tx and Rx processes. */
1169 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
1171 /* Clear the missed-packet counter. */
1172 (volatile unsigned long)inl(ioaddr
+ CSR8
);
1175 /*********************************************************************/
1176 /* eth_probe - Look for an adapter */
1177 /*********************************************************************/
1178 struct nic
*tulip_probe(struct nic
*nic
, unsigned short *io_addrs
,
1179 struct pci_device
*pci
)
1183 u8 ee_data
[EEPROM_SIZE
];
1186 static unsigned char last_phys_addr
[ETH_ALEN
] = {0x00, 'L', 'i', 'n', 'u', 'x'};
1188 if (io_addrs
== 0 || *io_addrs
== 0)
1193 /* point to private storage */
1196 tp
->vendor_id
= pci
->vendor
;
1197 tp
->dev_id
= pci
->dev_id
;
1198 tp
->nic_name
= pci
->name
;
1201 tp
->default_port
= 0;
1203 adjust_pci_device(pci
);
1205 /* disable interrupts */
1206 outl(0x00000000, ioaddr
+ CSR7
);
1208 /* Stop the chip's Tx and Rx processes. */
1209 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
1211 /* Clear the missed-packet counter. */
1212 (volatile unsigned long)inl(ioaddr
+ CSR8
);
1214 printf("\n"); /* so we start on a fresh line */
1215 #ifdef TULIP_DEBUG_WHERE
1216 whereami("tulip_probe\n");
1220 if (tulip_debug
> 1)
1221 printf ("%s: Looking for Tulip Chip: Vendor=%hX Device=%hX\n", tp
->nic_name
,
1222 tp
->vendor_id
, tp
->dev_id
);
1225 /* Figure out which chip we're dealing with */
1229 while (pci_id_tbl
[i
].name
) {
1230 if ( (((u32
) tp
->dev_id
<< 16) | tp
->vendor_id
) ==
1231 (pci_id_tbl
[i
].id
.pci
& pci_id_tbl
[i
].id
.pci_mask
) ) {
1232 chip_idx
= pci_id_tbl
[i
].drv_flags
;
1238 if (chip_idx
== -1) {
1239 printf ("%s: Unknown Tulip Chip: Vendor=%hX Device=%hX\n", tp
->nic_name
,
1240 tp
->vendor_id
, tp
->dev_id
);
1245 tp
->flags
= tulip_tbl
[chip_idx
].flags
;
1248 if (tulip_debug
> 1) {
1249 printf ("%s: tp->pci_id_idx == %d, name == %s\n", tp
->nic_name
,
1250 tp
->pci_id_idx
, pci_id_tbl
[tp
->pci_id_idx
].name
);
1251 printf ("%s: chip_idx == %d, name == %s\n", tp
->nic_name
, chip_idx
,
1252 tulip_tbl
[chip_idx
].chip_name
);
1256 /* Bring the 21041/21143 out of sleep mode.
1257 Caution: Snooze mode does not work with some boards! */
1258 if (tp
->flags
& HAS_PWRDWN
)
1259 pcibios_write_config_dword(pci
->bus
, pci
->devfn
, 0x40, 0x00000000);
1261 if (inl(ioaddr
+ CSR5
) == 0xFFFFFFFF) {
1262 printf("%s: The Tulip chip at %X is not functioning.\n",
1263 tp
->nic_name
, ioaddr
);
1267 pcibios_read_config_byte(pci
->bus
, pci
->devfn
, PCI_REVISION
, &chip_rev
);
1269 printf("%s: [chip: %s] rev %d at %hX\n", tp
->nic_name
,
1270 tulip_tbl
[chip_idx
].chip_name
, chip_rev
, ioaddr
);
1271 printf("%s: Vendor=%hX Device=%hX", tp
->nic_name
, tp
->vendor_id
, tp
->dev_id
);
1273 if (chip_idx
== DC21041
&& inl(ioaddr
+ CSR9
) & 0x8000) {
1274 printf(" 21040 compatible mode.");
1280 /* The SROM/EEPROM interface varies dramatically. */
1282 if (chip_idx
== DC21040
) {
1283 outl(0, ioaddr
+ CSR9
); /* Reset the pointer with a dummy write. */
1284 for (i
= 0; i
< ETH_ALEN
; i
++) {
1285 int value
, boguscnt
= 100000;
1287 value
= inl(ioaddr
+ CSR9
);
1288 while (value
< 0 && --boguscnt
> 0);
1289 nic
->node_addr
[i
] = value
;
1290 sum
+= value
& 0xff;
1292 } else if (chip_idx
== LC82C168
) {
1293 for (i
= 0; i
< 3; i
++) {
1294 int value
, boguscnt
= 100000;
1295 outl(0x600 | i
, ioaddr
+ 0x98);
1297 value
= inl(ioaddr
+ CSR9
);
1298 while (value
< 0 && --boguscnt
> 0);
1299 put_unaligned(le16_to_cpu(value
), ((u16
*)nic
->node_addr
) + i
);
1300 sum
+= value
& 0xffff;
1302 } else if (chip_idx
== COMET
) {
1303 /* No need to read the EEPROM. */
1304 put_unaligned(inl(ioaddr
+ 0xA4), (u32
*)nic
->node_addr
);
1305 put_unaligned(inl(ioaddr
+ 0xA8), (u16
*)(nic
->node_addr
+ 4));
1306 for (i
= 0; i
< ETH_ALEN
; i
++)
1307 sum
+= nic
->node_addr
[i
];
1309 /* A serial EEPROM interface, we read now and sort it out later. */
1311 int ee_addr_size
= read_eeprom(ioaddr
, 0xff, 8) & 0x40000 ? 8 : 6;
1313 for (i
= 0; i
< sizeof(ee_data
)/2; i
++)
1314 ((u16
*)ee_data
)[i
] =
1315 le16_to_cpu(read_eeprom(ioaddr
, i
, ee_addr_size
));
1317 /* DEC now has a specification (see Notes) but early board makers
1318 just put the address in the first EEPROM locations. */
1319 /* This does memcmp(eedata, eedata+16, 8) */
1320 for (i
= 0; i
< 8; i
++)
1321 if (ee_data
[i
] != ee_data
[16+i
])
1323 if (ee_data
[0] == 0xff && ee_data
[1] == 0xff && ee_data
[2] == 0) {
1324 sa_offset
= 2; /* Grrr, damn Matrox boards. */
1326 for (i
= 0; i
< ETH_ALEN
; i
++) {
1327 nic
->node_addr
[i
] = ee_data
[i
+ sa_offset
];
1328 sum
+= ee_data
[i
+ sa_offset
];
1331 /* Lite-On boards have the address byte-swapped. */
1332 if ((nic
->node_addr
[0] == 0xA0 || nic
->node_addr
[0] == 0xC0)
1333 && nic
->node_addr
[1] == 0x00)
1334 for (i
= 0; i
< ETH_ALEN
; i
+=2) {
1335 char tmp
= nic
->node_addr
[i
];
1336 nic
->node_addr
[i
] = nic
->node_addr
[i
+1];
1337 nic
->node_addr
[i
+1] = tmp
;
1340 if (sum
== 0 || sum
== ETH_ALEN
*0xff) {
1341 printf("%s: EEPROM not present!\n", tp
->nic_name
);
1342 for (i
= 0; i
< ETH_ALEN
-1; i
++)
1343 nic
->node_addr
[i
] = last_phys_addr
[i
];
1344 nic
->node_addr
[i
] = last_phys_addr
[i
] + 1;
1347 for (i
= 0; i
< ETH_ALEN
; i
++)
1348 last_phys_addr
[i
] = nic
->node_addr
[i
];
1350 printf("%s: %! at ioaddr %hX\n", tp
->nic_name
, nic
->node_addr
, ioaddr
);
1352 tp
->chip_id
= chip_idx
;
1353 tp
->revision
= chip_rev
;
1356 /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles.
1357 And the ASIX must have a burst limit or horrible things happen. */
1358 if (chip_idx
== DC21143
&& chip_rev
== 65)
1359 tp
->csr0
&= ~0x01000000;
1360 else if (tp
->flags
& IS_ASIX
)
1363 if (media_cap
[tp
->default_port
] & MediaIsMII
) {
1364 u16 media2advert
[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
1365 tp
->mii_advertise
= media2advert
[tp
->default_port
- 9];
1366 tp
->mii_advertise
|= (tp
->flags
& HAS_8023X
); /* Matching bits! */
1369 /* This is logically part of the probe routine, but too complex
1371 if (tp
->flags
& HAS_MEDIA_TABLE
) {
1372 memcpy(tp
->eeprom
, ee_data
, sizeof(tp
->eeprom
));
1378 /* reset the device and make ready for tx and rx of packets */
1381 nic
->reset
= tulip_reset
;
1382 nic
->poll
= tulip_poll
;
1383 nic
->transmit
= tulip_transmit
;
1384 nic
->disable
= tulip_disable
;
1386 /* give the board a chance to reset before returning */
1387 tulip_wait(4*TICKS_PER_SEC
);
1392 static void start_link(struct nic
*nic
)
1396 #ifdef TULIP_DEBUG_WHERE
1397 whereami("start_link\n");
1400 if ((tp
->flags
& ALWAYS_CHECK_MII
) ||
1401 (tp
->mtable
&& tp
->mtable
->has_mii
) ||
1402 ( ! tp
->mtable
&& (tp
->flags
& HAS_MII
))) {
1403 unsigned int phy
, phy_idx
;
1404 if (tp
->mtable
&& tp
->mtable
->has_mii
) {
1405 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
1406 if (tp
->mtable
->mleaf
[i
].media
== 11) {
1408 tp
->saved_if_port
= tp
->if_port
;
1409 select_media(nic
, 2);
1410 tp
->if_port
= tp
->saved_if_port
;
1415 /* Find the connected MII xcvrs. */
1416 for (phy
= 0, phy_idx
= 0; phy
< 32 && phy_idx
< sizeof(tp
->phys
);
1418 int mii_status
= mdio_read(nic
, phy
, 1);
1419 if ((mii_status
& 0x8301) == 0x8001 ||
1420 ((mii_status
& 0x8000) == 0 && (mii_status
& 0x7800) != 0)) {
1421 int mii_reg0
= mdio_read(nic
, phy
, 0);
1422 int mii_advert
= mdio_read(nic
, phy
, 4);
1425 if (tp
->mii_advertise
)
1426 to_advert
= tp
->mii_advertise
;
1427 else if (tp
->advertising
[phy_idx
])
1428 to_advert
= tp
->advertising
[phy_idx
];
1429 else /* Leave unchanged. */
1430 tp
->mii_advertise
= to_advert
= mii_advert
;
1432 tp
->phys
[phy_idx
++] = phy
;
1433 printf("%s: MII transceiver %d config %hX status %hX advertising %hX.\n",
1434 tp
->nic_name
, phy
, mii_reg0
, mii_status
, mii_advert
);
1435 /* Fixup for DLink with miswired PHY. */
1436 if (mii_advert
!= to_advert
) {
1437 printf("%s: Advertising %hX on PHY %d previously advertising %hX.\n",
1438 tp
->nic_name
, to_advert
, phy
, mii_advert
);
1439 mdio_write(nic
, phy
, 4, to_advert
);
1441 /* Enable autonegotiation: some boards default to off. */
1442 mdio_write(nic
, phy
, 0, mii_reg0
|
1443 (tp
->full_duplex
? 0x1100 : 0x1000) |
1444 (media_cap
[tp
->default_port
]&MediaIs100
? 0x2000:0));
1447 tp
->mii_cnt
= phy_idx
;
1448 if (tp
->mtable
&& tp
->mtable
->has_mii
&& phy_idx
== 0) {
1449 printf("%s: ***WARNING***: No MII transceiver found!\n",
1455 /* Reset the xcvr interface and turn on heartbeat. */
1456 switch (tp
->chip_id
) {
1458 outl(0x00000000, ioaddr
+ CSR13
);
1459 outl(0x00000004, ioaddr
+ CSR13
);
1462 /* This is nway_start(). */
1463 if (tp
->sym_advertise
== 0)
1464 tp
->sym_advertise
= 0x0061;
1465 outl(0x00000000, ioaddr
+ CSR13
);
1466 outl(0xFFFFFFFF, ioaddr
+ CSR14
);
1467 outl(0x00000008, ioaddr
+ CSR15
); /* Listen on AUI also. */
1468 outl(inl(ioaddr
+ CSR6
) | 0x0200, ioaddr
+ CSR6
);
1469 outl(0x0000EF01, ioaddr
+ CSR13
);
1471 case DC21140
: default:
1473 outl(tp
->mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
1477 if (tp
->mii_cnt
|| media_cap
[tp
->if_port
] & MediaIsMII
) {
1478 outl(0x82020000, ioaddr
+ CSR6
);
1479 outl(0x0000, ioaddr
+ CSR13
);
1480 outl(0x0000, ioaddr
+ CSR14
);
1481 outl(0x820E0000, ioaddr
+ CSR6
);
1486 if ( ! tp
->mii_cnt
) {
1489 outl(0x00420000, ioaddr
+ CSR6
);
1490 outl(0x30, ioaddr
+ CSR12
);
1491 outl(0x0001F078, ioaddr
+ 0xB8);
1492 outl(0x0201F078, ioaddr
+ 0xB8); /* Turn on autonegotiation. */
1495 case MX98713
: case COMPEX9881
:
1496 outl(0x00000000, ioaddr
+ CSR6
);
1497 outl(0x000711C0, ioaddr
+ CSR14
); /* Turn on NWay. */
1498 outl(0x00000001, ioaddr
+ CSR13
);
1500 case MX98715
: case MX98725
:
1501 outl(0x01a80000, ioaddr
+ CSR6
);
1502 outl(0xFFFFFFFF, ioaddr
+ CSR14
);
1503 outl(0x00001000, ioaddr
+ CSR12
);
1506 /* No initialization necessary. */
1511 static void nway_start(struct nic
*nic
)
1513 int csr14
= ((tp
->sym_advertise
& 0x0780) << 9) |
1514 ((tp
->sym_advertise
&0x0020)<<1) | 0xffbf;
1516 #ifdef TULIP_DEBUG_WHERE
1517 whereami("nway_start\n");
1521 tp
->nway
= tp
->mediasense
= 1;
1522 tp
->nwayset
= tp
->lpar
= 0;
1523 if (tp
->chip_id
== PNIC2
) {
1524 tp
->csr6
= 0x01000000 | (tp
->sym_advertise
& 0x0040 ? 0x0200 : 0);
1528 if (tulip_debug
> 1)
1529 printf("%s: Restarting internal NWay autonegotiation, %X.\n",
1530 tp
->nic_name
, csr14
);
1532 outl(0x0001, ioaddr
+ CSR13
);
1533 outl(csr14
, ioaddr
+ CSR14
);
1534 tp
->csr6
= 0x82420000 | (tp
->sym_advertise
& 0x0040 ? 0x0200 : 0);
1535 outl(tp
->csr6
, ioaddr
+ CSR6
);
1536 if (tp
->mtable
&& tp
->mtable
->csr15dir
) {
1537 outl(tp
->mtable
->csr15dir
, ioaddr
+ CSR15
);
1538 outl(tp
->mtable
->csr15val
, ioaddr
+ CSR15
);
1539 } else if (tp
->chip_id
!= PNIC2
)
1540 outw(0x0008, ioaddr
+ CSR15
);
1541 if (tp
->chip_id
== DC21041
) /* Trigger NWAY. */
1542 outl(0xEF01, ioaddr
+ CSR12
);
1544 outl(0x1301, ioaddr
+ CSR12
);
1547 static void init_media(struct nic
*nic
)
1551 #ifdef TULIP_DEBUG_WHERE
1552 whereami("init_media\n");
1555 tp
->saved_if_port
= tp
->if_port
;
1556 if (tp
->if_port
== 0)
1557 tp
->if_port
= tp
->default_port
;
1559 /* Allow selecting a default media. */
1561 if (tp
->mtable
== NULL
)
1564 int looking_for
= media_cap
[tp
->if_port
] & MediaIsMII
? 11 :
1565 (tp
->if_port
== 12 ? 0 : tp
->if_port
);
1566 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
1567 if (tp
->mtable
->mleaf
[i
].media
== looking_for
) {
1568 printf("%s: Using user-specified media %s.\n",
1569 tp
->nic_name
, medianame
[tp
->if_port
]);
1573 if ((tp
->mtable
->defaultmedia
& 0x0800) == 0) {
1574 int looking_for
= tp
->mtable
->defaultmedia
& 15;
1575 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
1576 if (tp
->mtable
->mleaf
[i
].media
== looking_for
) {
1577 printf("%s: Using EEPROM-set media %s.\n",
1578 tp
->nic_name
, medianame
[looking_for
]);
1582 /* Start sensing first non-full-duplex media. */
1583 for (i
= tp
->mtable
->leafcount
- 1;
1584 (media_cap
[tp
->mtable
->mleaf
[i
].media
] & MediaAlwaysFD
) && i
> 0; i
--)
1593 if (tp
->chip_id
== DC21143
&& media_cap
[tp
->if_port
] & MediaIsMII
) {
1594 /* We must reset the media CSRs when we force-select MII mode. */
1595 outl(0x0000, ioaddr
+ CSR13
);
1596 outl(0x0000, ioaddr
+ CSR14
);
1597 outl(0x0008, ioaddr
+ CSR15
);
1599 select_media(nic
, 1);
1602 switch(tp
->chip_id
) {
1609 select_media(nic
, 1);
1611 if (tulip_debug
> 1)
1612 printf("%s: Using MII transceiver %d, status %hX.\n",
1613 tp
->nic_name
, tp
->phys
[0], mdio_read(nic
, tp
->phys
[0], 1));
1615 outl(0x82020000, ioaddr
+ CSR6
);
1616 tp
->csr6
= 0x820E0000;
1618 outl(0x0000, ioaddr
+ CSR13
);
1619 outl(0x0000, ioaddr
+ CSR14
);
1629 tp
->csr6
= 0x814C0000 | (tp
->full_duplex
? 0x0200 : 0);
1630 outl(0x0001, ioaddr
+ CSR15
);
1631 } else if (inl(ioaddr
+ CSR5
) & TPLnkPass
)
1634 /* Start with 10mbps to do autonegotiation. */
1635 outl(0x32, ioaddr
+ CSR12
);
1636 tp
->csr6
= 0x00420000;
1637 outl(0x0001B078, ioaddr
+ 0xB8);
1638 outl(0x0201B078, ioaddr
+ 0xB8);
1641 case MX98713
: case COMPEX9881
:
1643 tp
->csr6
= 0x01880000 | (tp
->full_duplex
? 0x0200 : 0);
1644 outl(0x0f370000 | inw(ioaddr
+ 0x80), ioaddr
+ 0x80);
1646 case MX98715
: case MX98725
:
1647 /* Provided by BOLO, Macronix - 12/10/1998. */
1649 tp
->csr6
= 0x01a80200;
1650 outl(0x0f370000 | inw(ioaddr
+ 0x80), ioaddr
+ 0x80);
1651 outl(0x11000 | inw(ioaddr
+ 0xa0), ioaddr
+ 0xa0);
1655 tp
->csr6
= 0x00040000;
1657 case AX88140
: case AX88141
:
1658 tp
->csr6
= tp
->mii_cnt
? 0x00040100 : 0x00000100;
1661 select_media(nic
, 1);
1665 static void pnic_do_nway(struct nic
*nic
)
1667 u32 phy_reg
= inl(ioaddr
+ 0xB8);
1668 u32 new_csr6
= tp
->csr6
& ~0x40C40200;
1670 #ifdef TULIP_DEBUG_WHERE
1671 whereami("pnic_do_nway\n");
1674 if (phy_reg
& 0x78000000) { /* Ignore baseT4 */
1675 if (phy_reg
& 0x20000000) tp
->if_port
= 5;
1676 else if (phy_reg
& 0x40000000) tp
->if_port
= 3;
1677 else if (phy_reg
& 0x10000000) tp
->if_port
= 4;
1678 else if (phy_reg
& 0x08000000) tp
->if_port
= 0;
1680 new_csr6
= (tp
->if_port
& 1) ? 0x01860000 : 0x00420000;
1681 outl(0x32 | (tp
->if_port
& 1), ioaddr
+ CSR12
);
1682 if (tp
->if_port
& 1)
1683 outl(0x1F868, ioaddr
+ 0xB8);
1684 if (phy_reg
& 0x30000000) {
1685 tp
->full_duplex
= 1;
1686 new_csr6
|= 0x00000200;
1689 if (tulip_debug
> 1)
1690 printf("%s: PNIC autonegotiated status %X, %s.\n",
1691 tp
->nic_name
, phy_reg
, medianame
[tp
->if_port
]);
1693 if (tp
->csr6
!= new_csr6
) {
1694 tp
->csr6
= new_csr6
;
1695 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
); /* Restart Tx */
1696 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1701 /* Set up the transceiver control registers for the selected media type. */
1702 static void select_media(struct nic
*nic
, int startup
)
1704 struct mediatable
*mtable
= tp
->mtable
;
1708 #ifdef TULIP_DEBUG_WHERE
1709 whereami("select_media\n");
1713 struct medialeaf
*mleaf
= &mtable
->mleaf
[tp
->cur_index
];
1714 unsigned char *p
= mleaf
->leafdata
;
1715 switch (mleaf
->type
) {
1716 case 0: /* 21140 non-MII xcvr. */
1718 if (tulip_debug
> 1)
1719 printf("%s: Using a 21140 non-MII transceiver"
1720 " with control setting %hhX.\n",
1721 tp
->nic_name
, p
[1]);
1725 outl(mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
1726 outl(p
[1], ioaddr
+ CSR12
);
1727 new_csr6
= 0x02000000 | ((p
[2] & 0x71) << 18);
1731 u32 csr13val
, csr14val
, csr15dir
, csr15val
;
1732 for (i
= 0; i
< 5; i
++)
1733 setup
[i
] = get_u16(&p
[i
*2 + 1]);
1735 tp
->if_port
= p
[0] & 15;
1736 if (media_cap
[tp
->if_port
] & MediaAlwaysFD
)
1737 tp
->full_duplex
= 1;
1739 if (startup
&& mtable
->has_reset
) {
1740 struct medialeaf
*rleaf
= &mtable
->mleaf
[mtable
->has_reset
];
1741 unsigned char *rst
= rleaf
->leafdata
;
1743 if (tulip_debug
> 1)
1744 printf("%s: Resetting the transceiver.\n",
1747 for (i
= 0; i
< rst
[0]; i
++)
1748 outl(get_u16(rst
+ 1 + (i
<<1)) << 16, ioaddr
+ CSR15
);
1751 if (tulip_debug
> 1)
1752 printf("%s: 21143 non-MII %s transceiver control "
1754 tp
->nic_name
, medianame
[tp
->if_port
], setup
[0], setup
[1]);
1756 if (p
[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */
1757 csr13val
= setup
[0];
1758 csr14val
= setup
[1];
1759 csr15dir
= (setup
[3]<<16) | setup
[2];
1760 csr15val
= (setup
[4]<<16) | setup
[2];
1761 outl(0, ioaddr
+ CSR13
);
1762 outl(csr14val
, ioaddr
+ CSR14
);
1763 outl(csr15dir
, ioaddr
+ CSR15
); /* Direction */
1764 outl(csr15val
, ioaddr
+ CSR15
); /* Data */
1765 outl(csr13val
, ioaddr
+ CSR13
);
1768 csr14val
= 0x0003FF7F;
1769 csr15dir
= (setup
[0]<<16) | 0x0008;
1770 csr15val
= (setup
[1]<<16) | 0x0008;
1771 if (tp
->if_port
<= 4)
1772 csr14val
= t21142_csr14
[tp
->if_port
];
1774 outl(0, ioaddr
+ CSR13
);
1775 outl(csr14val
, ioaddr
+ CSR14
);
1777 outl(csr15dir
, ioaddr
+ CSR15
); /* Direction */
1778 outl(csr15val
, ioaddr
+ CSR15
); /* Data */
1779 if (startup
) outl(csr13val
, ioaddr
+ CSR13
);
1782 if (tulip_debug
> 1)
1783 printf("%s: Setting CSR15 to %X/%X.\n",
1784 tp
->nic_name
, csr15dir
, csr15val
);
1786 if (mleaf
->type
== 4)
1787 new_csr6
= 0x82020000 | ((setup
[2] & 0x71) << 18);
1789 new_csr6
= 0x82420000;
1794 int init_length
= p
[1];
1798 new_csr6
= 0x020E0000;
1799 if (mleaf
->type
== 3) { /* 21142 */
1800 u16
*init_sequence
= (u16
*)(p
+2);
1801 u16
*reset_sequence
= &((u16
*)(p
+3))[init_length
];
1802 int reset_length
= p
[2 + init_length
*2];
1803 misc_info
= reset_sequence
+ reset_length
;
1805 for (i
= 0; i
< reset_length
; i
++)
1806 outl(get_u16(&reset_sequence
[i
]) << 16, ioaddr
+ CSR15
);
1807 for (i
= 0; i
< init_length
; i
++)
1808 outl(get_u16(&init_sequence
[i
]) << 16, ioaddr
+ CSR15
);
1810 u8
*init_sequence
= p
+ 2;
1811 u8
*reset_sequence
= p
+ 3 + init_length
;
1812 int reset_length
= p
[2 + init_length
];
1813 misc_info
= (u16
*)(reset_sequence
+ reset_length
);
1815 outl(mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
1816 for (i
= 0; i
< reset_length
; i
++)
1817 outl(reset_sequence
[i
], ioaddr
+ CSR12
);
1819 for (i
= 0; i
< init_length
; i
++)
1820 outl(init_sequence
[i
], ioaddr
+ CSR12
);
1822 tp
->advertising
[phy_num
] = get_u16(&misc_info
[1]) | 1;
1824 if (tp
->mii_advertise
== 0)
1825 tp
->mii_advertise
= tp
->advertising
[phy_num
];
1827 if (tulip_debug
> 1)
1828 printf("%s: Advertising %hX on MII %d.\n",
1829 tp
->nic_name
, tp
->mii_advertise
, tp
->phys
[phy_num
]);
1831 mdio_write(nic
, tp
->phys
[phy_num
], 4, tp
->mii_advertise
);
1836 printf("%s: Invalid media table selection %d.\n",
1837 tp
->nic_name
, mleaf
->type
);
1838 new_csr6
= 0x020E0000;
1841 if (tulip_debug
> 1)
1842 printf("%s: Using media type %s, CSR12 is %hhX.\n",
1843 tp
->nic_name
, medianame
[tp
->if_port
],
1844 inl(ioaddr
+ CSR12
) & 0xff);
1846 } else if (tp
->chip_id
== DC21041
) {
1847 int port
= tp
->if_port
<= 4 ? tp
->if_port
: 0;
1849 if (tulip_debug
> 1)
1850 printf("%s: 21041 using media %s, CSR12 is %hX.\n",
1851 tp
->nic_name
, medianame
[port
== 3 ? 12: port
],
1852 inl(ioaddr
+ CSR12
));
1854 outl(0x00000000, ioaddr
+ CSR13
); /* Reset the serial interface */
1855 outl(t21041_csr14
[port
], ioaddr
+ CSR14
);
1856 outl(t21041_csr15
[port
], ioaddr
+ CSR15
);
1857 outl(t21041_csr13
[port
], ioaddr
+ CSR13
);
1858 new_csr6
= 0x80020000;
1859 } else if (tp
->chip_id
== LC82C168
) {
1860 if (startup
&& ! tp
->medialock
)
1861 tp
->if_port
= tp
->mii_cnt
? 11 : 0;
1863 if (tulip_debug
> 1)
1864 printf("%s: PNIC PHY status is %hX, media %s.\n",
1865 tp
->nic_name
, inl(ioaddr
+ 0xB8), medianame
[tp
->if_port
]);
1868 new_csr6
= 0x810C0000;
1869 outl(0x0001, ioaddr
+ CSR15
);
1870 outl(0x0201B07A, ioaddr
+ 0xB8);
1871 } else if (startup
) {
1872 /* Start with 10mbps to do autonegotiation. */
1873 outl(0x32, ioaddr
+ CSR12
);
1874 new_csr6
= 0x00420000;
1875 outl(0x0001B078, ioaddr
+ 0xB8);
1876 outl(0x0201B078, ioaddr
+ 0xB8);
1877 } else if (tp
->if_port
== 3 || tp
->if_port
== 5) {
1878 outl(0x33, ioaddr
+ CSR12
);
1879 new_csr6
= 0x01860000;
1880 /* Trigger autonegotiation. */
1881 outl(startup
? 0x0201F868 : 0x0001F868, ioaddr
+ 0xB8);
1883 outl(0x32, ioaddr
+ CSR12
);
1884 new_csr6
= 0x00420000;
1885 outl(0x1F078, ioaddr
+ 0xB8);
1887 } else if (tp
->chip_id
== DC21040
) { /* 21040 */
1888 /* Turn on the xcvr interface. */
1889 int csr12
= inl(ioaddr
+ CSR12
);
1891 if (tulip_debug
> 1)
1892 printf("%s: 21040 media type is %s, CSR12 is %hhX.\n",
1893 tp
->nic_name
, medianame
[tp
->if_port
], csr12
);
1895 if (media_cap
[tp
->if_port
] & MediaAlwaysFD
)
1896 tp
->full_duplex
= 1;
1898 /* Set the full duplux match frame. */
1899 outl(FULL_DUPLEX_MAGIC
, ioaddr
+ CSR11
);
1900 outl(0x00000000, ioaddr
+ CSR13
); /* Reset the serial interface */
1901 if (t21040_csr13
[tp
->if_port
] & 8) {
1902 outl(0x0705, ioaddr
+ CSR14
);
1903 outl(0x0006, ioaddr
+ CSR15
);
1905 outl(0xffff, ioaddr
+ CSR14
);
1906 outl(0x0000, ioaddr
+ CSR15
);
1908 outl(0x8f01 | t21040_csr13
[tp
->if_port
], ioaddr
+ CSR13
);
1909 } else { /* Unknown chip type with no media table. */
1910 if (tp
->default_port
== 0)
1911 tp
->if_port
= tp
->mii_cnt
? 11 : 3;
1912 if (media_cap
[tp
->if_port
] & MediaIsMII
) {
1913 new_csr6
= 0x020E0000;
1914 } else if (media_cap
[tp
->if_port
] & MediaIsFx
) {
1915 new_csr6
= 0x028600000;
1917 new_csr6
= 0x038600000;
1919 if (tulip_debug
> 1)
1920 printf("%s: No media description table, assuming "
1921 "%s transceiver, CSR12 %hhX.\n",
1922 tp
->nic_name
, medianame
[tp
->if_port
],
1923 inl(ioaddr
+ CSR12
));
1927 tp
->csr6
= new_csr6
| (tp
->csr6
& 0xfdff) | (tp
->full_duplex
? 0x0200 : 0);
1932 Check the MII negotiated duplex and change the CSR6 setting if
1934 Return 0 if everything is OK.
1935 Return < 0 if the transceiver is missing or has no link beat.
1937 static int tulip_check_duplex(struct nic
*nic
)
1939 unsigned int bmsr
, lpa
, negotiated
, new_csr6
;
1941 bmsr
= mdio_read(nic
, tp
->phys
[0], 1);
1942 lpa
= mdio_read(nic
, tp
->phys
[0], 5);
1945 if (tulip_debug
> 1)
1946 printf("%s: MII status %#x, Link partner report "
1947 "%#x.\n", tp
->nic_name
, bmsr
, lpa
);
1952 if ((bmsr
& 4) == 0) {
1953 int new_bmsr
= mdio_read(nic
, tp
->phys
[0], 1);
1954 if ((new_bmsr
& 4) == 0) {
1956 if (tulip_debug
> 1)
1957 printf("%s: No link beat on the MII interface,"
1958 " status %#x.\n", tp
->nic_name
,
1964 tp
->full_duplex
= lpa
& 0x140;
1966 new_csr6
= tp
->csr6
;
1967 negotiated
= lpa
& tp
->advertising
[0];
1969 if(negotiated
& 0x380) new_csr6
&= ~0x400000;
1970 else new_csr6
|= 0x400000;
1971 if (tp
->full_duplex
) new_csr6
|= 0x200;
1972 else new_csr6
&= ~0x200;
1974 if (new_csr6
!= tp
->csr6
) {
1975 tp
->csr6
= new_csr6
;
1978 if (tulip_debug
> 0)
1979 printf("%s: Setting %s-duplex based on MII"
1980 "#%d link partner capability of %#x.\n",
1982 tp
->full_duplex
? "full" : "half",