1 /* tulip.c: A DEC 21040-family ethernet driver for Linux. */
3 Written 1994-1998 by Donald Becker.
5 This software may be used and distributed according to the terms
6 of the GNU Public License, incorporated herein by reference.
8 This driver is for the Digital "Tulip" ethernet adapter interface.
9 It should work with most DEC 21*4*-based chips/ethercards, as well as
12 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
13 Center of Excellence in Space Data and Information Sciences
14 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
16 Support and updates available at
17 http://cesdis.gsfc.nasa.gov/linux/drivers/tulip.html
21 static const char version
[] = "tulip.c:v0.89H 5/23/98 becker@cesdis.gsfc.nasa.gov\n";
23 /* A few user-configurable values. */
25 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
26 static int max_interrupt_work
= 25;
29 /* Used to pass the full-duplex flag, etc. */
30 static int full_duplex
[MAX_UNITS
] = {0, };
31 static int options
[MAX_UNITS
] = {0, };
32 static int mtu
[MAX_UNITS
] = {0, }; /* Jumbo MTU for interfaces. */
34 /* The possible media types that can be set in options[] are: */
35 static const char * const medianame
[] = {
36 "10baseT", "10base2", "AUI", "100baseTx",
37 "10baseT-FD", "100baseTx-FD", "100baseT4", "100baseFx",
38 "100baseFx-FD", "MII 10baseT", "MII 10baseT-FD", "MII",
39 "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FD", "MII 100baseT4",
42 /* Set if the PCI BIOS detects the chips on a multiport board backwards. */
43 #ifdef REVERSE_PROBE_ORDER
44 static int reverse_probe
= 1;
46 static int reverse_probe
= 0;
49 /* Keep the ring sizes a power of two for efficiency.
50 Making the Tx ring too large decreases the effectiveness of channel
51 bonding and packet priority.
52 There are no ill effects from too-large receive rings. */
53 #define TX_RING_SIZE 16
54 #define RX_RING_SIZE 32
56 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
58 static int rx_copybreak
= 1518;
60 static int rx_copybreak
= 100;
63 /* Operational parameters that usually are not changed. */
64 /* Time in jiffies before concluding the transmitter is hung. */
65 #define TX_TIMEOUT (4*HZ)
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/sched.h>
70 #include <linux/string.h>
71 #include <linux/timer.h>
72 #include <linux/ptrace.h>
73 #include <linux/errno.h>
74 #include <linux/ioport.h>
75 #include <linux/malloc.h>
76 #include <linux/interrupt.h>
77 #include <linux/pci.h>
79 #include <asm/processor.h> /* Processor type for cache alignment. */
80 #include <asm/bitops.h>
84 #include <linux/netdevice.h>
85 #include <linux/etherdevice.h>
86 #include <linux/skbuff.h>
88 /* Kernel compatibility defines, common to David Hind's PCMCIA package.
89 This is only in the support-all-kernels source code. */
90 #include <linux/version.h> /* Evil, but neccessary */
92 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x10300
93 #define RUN_AT(x) (x) /* What to put in timer->expires. */
94 #define DEV_ALLOC_SKB(len) alloc_skb(len, GFP_ATOMIC)
95 #define virt_to_bus(addr) ((unsigned long)addr)
96 #define bus_to_virt(addr) ((void*)addr)
98 #else /* 1.3.0 and later */
99 #define RUN_AT(x) (jiffies + (x))
100 #define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)
103 #if (LINUX_VERSION_CODE >= 0x10344)
104 #define NEW_MULTICAST
105 #include <linux/delay.h>
108 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
110 #define IRQ(irq, dev_id, pt_regs) (irq, pt_regs)
113 #if (LINUX_VERSION_CODE < 0x20123)
114 #define hard_smp_processor_id() smp_processor_id()
115 #define test_and_set_bit(val, addr) set_bit(val, addr)
118 /* This my implementation of shared IRQs, now only used for 1.2.13. */
119 #ifdef HAVE_SHARED_IRQ
120 #define USE_SHARED_IRQ
121 #include <linux/shared_irq.h>
124 /* The total size is unusually large: The 21040 aligns each of its 16
125 longword-wide registers on a quadword boundary. */
126 #define TULIP_TOTAL_SIZE 0x80
129 struct netdev_entry tulip_drv
=
130 {"Tulip", tulip_pci_probe
, TULIP_TOTAL_SIZE
, NULL
};
134 int tulip_debug
= TULIP_DEBUG
;
142 I. Board Compatibility
144 This device driver is designed for the DECchip "Tulip", Digital's
145 single-chip ethernet controllers for PCI. Supported members of the family
146 are the 21040, 21041, 21140, 21140A, 21142, and 21143. These chips are used on
147 many PCI boards including the SMC EtherPower series.
150 II. Board-specific settings
152 PCI bus devices are configured by the system at boot time, so no jumpers
153 need to be set on the board. The system BIOS preferably should assign the
154 PCI INTA signal to an otherwise unused system IRQ line.
155 Note: Kernel versions earlier than 1.3.73 do not support shared PCI
158 III. Driver operation
162 The Tulip can use either ring buffers or lists of Tx and Rx descriptors.
163 This driver uses statically allocated rings of Rx and Tx descriptors, set at
164 compile time by RX/TX_RING_SIZE. This version of the driver allocates skbuffs
165 for the Rx ring buffers at open() time and passes the skb->data field to the
166 Tulip as receive data buffers. When an incoming frame is less than
167 RX_COPYBREAK bytes long, a fresh skbuff is allocated and the frame is
168 copied to the new skbuff. When the incoming frame is larger, the skbuff is
169 passed directly up the protocol stack and replaced by a newly allocated
172 The RX_COPYBREAK value is chosen to trade-off the memory wasted by
173 using a full-sized skbuff for small frames vs. the copying costs of larger
174 frames. For small frames the copying cost is negligible (esp. considering
175 that we are pre-loading the cache with immediately useful header
176 information). For large frames the copying cost is non-trivial, and the
177 larger copy might flush the cache of useful data. A subtle aspect of this
178 choice is that the Tulip only receives into longword aligned buffers, thus
179 the IP header at offset 14 isn't longword aligned for further processing.
180 Copied frames are put into the new skbuff at an offset of "+2", thus copying
181 has the beneficial effect of aligning the IP header and preloading the
184 IIIC. Synchronization
185 The driver runs as two independent, single-threaded flows of control. One
186 is the send-packet routine, which enforces single-threaded use by the
187 dev->tbusy flag. The other thread is the interrupt handler, which is single
188 threaded by the hardware and other software.
190 The send packet thread has partial control over the Tx ring and 'dev->tbusy'
191 flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next
192 queue slot is empty, it clears the tbusy flag when finished otherwise it sets
193 the 'tp->tx_full' flag.
195 The interrupt handler has exclusive control over the Rx ring and records stats
196 from the Tx ring. (The Tx-done interrupt can't be selectively turned off, so
197 we can't avoid the interrupt overhead by having the Tx routine reap the Tx
198 stats.) After reaping the stats, it marks the queue entry as empty by setting
199 the 'base' to zero. Iff the 'tp->tx_full' flag is set, it clears both the
200 tx_full and tbusy flags.
204 Thanks to Duke Kamstra of SMC for providing an EtherPower board.
208 http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
209 http://www.digital.com (search for current 21*4* datasheets and "21X4 SROM")
210 http://www.national.com/pf/DP/DP83840.html
214 The DEC databook doesn't document which Rx filter settings accept broadcast
215 packets. Nor does it document how to configure the part to configure the
216 serial subsystem for normal (vs. loopback) operation or how to have it
217 autoswitch between internal 10baseT, SIA and AUI transceivers.
219 The 21040 databook claims that CSR13, CSR14, and CSR15 should each be the last
220 register of the set CSR12-15 written. Hmmm, now how is that possible? */
223 /* A few values that may be tweaked. */
224 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
226 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
227 to support a pre-NWay full-duplex signaling mechanism using short frames.
228 No one knows what it should be, but if left at its default value some
229 10base2(!) packets trigger a full-duplex-request interrupt. */
230 #define FULL_DUPLEX_MAGIC 0x6969
232 #ifndef PCI_VENDOR_ID_DEC /* Now defined in linux/pci.h */
233 #define PCI_VENDOR_ID_DEC 0x1011
234 #define PCI_DEVICE_ID_TULIP 0x0002 /* 21040. */
235 #define PCI_DEVICE_ID_TULIP_FAST 0x0009 /* 21140. */
238 #ifndef PCI_DEVICE_ID_DEC_TULIP_PLUS
239 #define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014 /* 21041. */
241 #ifndef PCI_DEVICE_ID_DEC_TULIP_21142
242 #define PCI_DEVICE_ID_DEC_TULIP_21142 0x0019
245 #ifndef PCI_VENDOR_ID_LITEON
246 #define PCI_VENDOR_ID_LITEON 0x11AD
249 #ifndef PCI_VENDOR_ID_MXIC
250 #define PCI_VENDOR_ID_MXIC 0x10d9
251 #define PCI_DEVICE_ID_MX98713 0x0512
252 #define PCI_DEVICE_ID_MX98715 0x0531
253 #define PCI_DEVICE_ID_MX98725 0x0531
256 /* The rest of these values should never change. */
258 static void tulip_timer(unsigned long data
);
259 static void t21142_timer(unsigned long data
);
260 static void mxic_timer(unsigned long data
);
261 static void pnic_timer(unsigned long data
);
263 /* A table describing the chip types. */
264 enum tbl_flag
{ HAS_MII
=1, HAS_MEDIA_TABLE
= 2, CSR12_IN_SROM
= 4,};
265 static struct tulip_chip_table
{
266 int vendor_id
, device_id
;
269 int valid_intrs
; /* CSR7 interrupt enable settings */
271 void (*media_timer
)(unsigned long data
);
273 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP
,
274 "Digital DC21040 Tulip", 128, 0x0001ebef, 0, tulip_timer
},
275 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_PLUS
,
276 "Digital DC21041 Tulip", 128, 0x0001ebef, HAS_MEDIA_TABLE
, tulip_timer
},
277 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_FAST
,
278 "Digital DS21140 Tulip", 128, 0x0001ebef,
279 HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
,
281 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_21142
,
282 "Digital DS21142/3 Tulip", 128, 0x0801fbff,
283 HAS_MII
| HAS_MEDIA_TABLE
, t21142_timer
},
284 { PCI_VENDOR_ID_LITEON
, 0x0002,
285 "Lite-On 82c168 PNIC", 256, 0x0001ebef, HAS_MII
, pnic_timer
},
286 { PCI_VENDOR_ID_MXIC
, PCI_DEVICE_ID_MX98713
,
287 "Macronix 98713 PMAC", 128, 0x0001ebef,
288 HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
, tulip_timer
/* Tulip-like! */ },
289 { PCI_VENDOR_ID_MXIC
, PCI_DEVICE_ID_MX98715
,
290 "Macronix 98715 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE
, mxic_timer
},
291 { PCI_VENDOR_ID_MXIC
, PCI_DEVICE_ID_MX98725
,
292 "Macronix 98725 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE
, mxic_timer
},
293 { 0x125B, 0x1400, "ASIX AX88140", 128, 0x0001fbff,
294 HAS_MII
| HAS_MEDIA_TABLE
| CSR12_IN_SROM
, tulip_timer
},
297 /* This matches the table above. */
298 enum chips
{ DC21040
=0, DC21041
=1, DC21140
=2, DC21142
=3, DC21143
=3,
299 LC82C168
, MX98713
, MX98715
, MX98725
};
301 /* A full-duplex map for media types. */
302 enum MediaIs
{MediaIsFD
= 1, MediaAlwaysFD
=2, MediaIsMII
=4, MediaIsFx
=8,
304 static const char media_cap
[] =
305 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20 };
306 /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD*/
307 static u16 t21041_csr13
[] = { 0xEF05, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
308 static u16 t21041_csr14
[] = { 0x7F3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
309 static u16 t21041_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
311 static u16 t21142_csr13
[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
312 static u16 t21142_csr14
[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
313 static u16 t21142_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
315 /* Offsets to the Command and Status Registers, "CSRs". All accesses
316 must be longword instructions and quadword aligned. */
318 CSR0
=0, CSR1
=0x08, CSR2
=0x10, CSR3
=0x18, CSR4
=0x20, CSR5
=0x28,
319 CSR6
=0x30, CSR7
=0x38, CSR8
=0x40, CSR9
=0x48, CSR10
=0x50, CSR11
=0x58,
320 CSR12
=0x60, CSR13
=0x68, CSR14
=0x70, CSR15
=0x78 };
322 /* The bits in the CSR5 status registers, mostly interrupt sources. */
324 TimerInt
=0x800, TPLnkFail
=0x1000, TPLnkPass
=0x10,
325 NormalIntr
=0x10000, AbnormalIntr
=0x8000,
326 RxJabber
=0x200, RxDied
=0x100, RxNoBuf
=0x80, RxIntr
=0x40,
327 TxFIFOUnderflow
=0x20, TxJabber
=0x08, TxNoBuf
=0x04, TxDied
=0x02, TxIntr
=0x01,
330 enum desc_status_bits
{
331 DescOwned
=0x80000000, RxDescFatalErr
=0x8000, RxWholePkt
=0x0300,
334 /* The Tulip Rx and Tx buffer descriptors. */
335 struct tulip_rx_desc
{
338 u32 buffer1
, buffer2
;
341 struct tulip_tx_desc
{
344 u32 buffer1
, buffer2
; /* We use only buffer 1. */
350 unsigned char *leafdata
;
355 u8 leafcount
, csr12dir
; /* General purpose pin directions. */
356 unsigned has_mii
:1, has_nonmii
:1;
357 struct medialeaf mleaf
[0];
361 struct mediainfo
*next
;
367 struct tulip_private
{
368 char devname
[8]; /* Used only for kernel debugging. */
369 const char *product_name
;
370 struct net_device
*next_module
;
371 struct tulip_rx_desc rx_ring
[RX_RING_SIZE
];
372 struct tulip_tx_desc tx_ring
[TX_RING_SIZE
];
373 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
374 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
375 /* The addresses of receive-in-place skbuffs. */
376 struct sk_buff
* rx_skbuff
[RX_RING_SIZE
];
377 char *rx_buffs
; /* Address of temporary Rx buffers. */
378 u32 setup_frame
[48]; /* Pseudo-Tx frame to init address table. */
381 #if LINUX_VERSION_CODE > 0x20139
382 struct net_device_stats stats
;
384 struct enet_statistics stats
;
386 struct timer_list timer
; /* Media selection timer. */
387 int interrupt
; /* In-interrupt flag. */
389 int smp_proc_id
; /* Which processor in IRQ handler. */
391 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
392 unsigned int dirty_rx
, dirty_tx
; /* The ring entries to be free()ed. */
393 unsigned int tx_full
:1; /* The Tx queue is full. */
394 unsigned int full_duplex
:1; /* Full-duplex operation requested. */
395 unsigned int full_duplex_lock
:1;
396 unsigned int fake_addr
:1; /* Multiport board faked address. */
397 unsigned int default_port
:4; /* Last dev->if_port value. */
398 unsigned int media2
:4; /* Secondary monitored media port. */
399 unsigned int medialock
:1; /* Don't sense media type. */
400 unsigned int mediasense
:1; /* Media sensing in progress. */
401 unsigned int csr6
; /* Current CSR6 control settings. */
402 unsigned char eeprom
[128]; /* Serial EEPROM contents. */
403 u16 to_advertise
; /* NWay capabilities advertised. */
405 signed char phys
[4], mii_cnt
; /* MII device addresses. */
406 struct mediatable
*mtable
;
407 int cur_index
; /* Current media index. */
408 unsigned char pci_bus
, pci_dev_fn
;
409 int pad0
, pad1
; /* Used for 8-byte alignment */
412 static struct net_device
*tulip_probe1(int pci_bus
, int pci_devfn
,
413 struct net_device
*dev
,
414 int chip_id
, int options
);
415 static void parse_eeprom(struct net_device
*dev
);
416 static int read_eeprom(long ioaddr
, int location
);
417 static int mdio_read(struct net_device
*dev
, int phy_id
, int location
);
418 static void mdio_write(struct net_device
*dev
, int phy_id
, int location
, int value
);
419 static void select_media(struct net_device
*dev
, int startup
);
420 static int tulip_open(struct net_device
*dev
);
421 static void tulip_timer(unsigned long data
);
422 static void tulip_tx_timeout(struct net_device
*dev
);
423 static void tulip_init_ring(struct net_device
*dev
);
424 static int tulip_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
425 static int tulip_rx(struct net_device
*dev
);
426 static void tulip_interrupt
IRQ(int irq
, void *dev_instance
, struct pt_regs
*regs
);
427 static int tulip_close(struct net_device
*dev
);
428 static struct enet_statistics
*tulip_get_stats(struct net_device
*dev
);
429 #ifdef HAVE_PRIVATE_IOCTL
430 static int private_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
433 static void set_rx_mode(struct net_device
*dev
);
435 static void set_rx_mode(struct net_device
*dev
, int num_addrs
, void *addrs
);
440 /* A list of all installed Tulip devices, for removing the driver module. */
441 static struct net_device
*root_tulip_dev
= NULL
;
443 /* This 21040 probe no longer uses a large fixed contiguous Rx buffer region,
444 but now receives directly into full-sized skbuffs that are allocated
446 This allows the probe routine to use the old driver initialization
449 int tulip_probe(struct net_device
*dev
)
452 static int pci_index
= 0; /* Static, for multiple probe calls. */
453 unsigned char pci_bus
, pci_device_fn
;
455 /* Ideally we would detect all network cards in slot order. That would
456 be best done a central PCI probe dispatch, which wouldn't work
457 well with the current structure. So instead we detect just the
458 Tulip cards in slot order. */
460 #if LINUX_VERSION_CODE >= 0x20155
464 if (! pcibios_present())
467 for (;pci_index
< 0xff; pci_index
++) {
468 u16 vendor
, device
, pci_command
, new_command
;
469 unsigned long pci_ioaddr
= 0;
472 if (pcibios_find_class
473 (PCI_CLASS_NETWORK_ETHERNET
<< 8,
474 reverse_probe
? 0xfe - pci_index
: pci_index
,
475 &pci_bus
, &pci_device_fn
) != PCIBIOS_SUCCESSFUL
)
482 pcibios_read_config_word(pci_bus
, pci_device_fn
,
483 PCI_VENDOR_ID
, &vendor
);
484 pcibios_read_config_word(pci_bus
, pci_device_fn
,
485 PCI_DEVICE_ID
, &device
);
487 for (chip_idx
= 0; tulip_tbl
[chip_idx
].chip_name
; chip_idx
++)
488 if (vendor
== tulip_tbl
[chip_idx
].vendor_id
&&
489 device
== tulip_tbl
[chip_idx
].device_id
)
491 if (tulip_tbl
[chip_idx
].chip_name
== 0) {
492 if (vendor
== PCI_VENDOR_ID_DEC
||
493 vendor
== PCI_VENDOR_ID_LITEON
)
494 printk(KERN_INFO
"Unknown Tulip-style PCI ethernet chip type"
495 " %4.4x %4.4x"" detected: not configured.\n",
499 #if LINUX_VERSION_CODE >= 0x20155
500 pci_ioaddr
= pci_find_slot(pci_bus
, pci_device_fn
)->resource
[0].start
;
502 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_0
,
505 /* Remove I/O space marker in bit 0. */
509 printk(KERN_DEBUG
"Found %s at I/O %#lx.\n",
510 tulip_tbl
[chip_idx
].chip_name
, pci_ioaddr
);
512 if (check_region(pci_ioaddr
, tulip_tbl
[chip_idx
].io_size
))
515 pcibios_read_config_word(pci_bus
, pci_device_fn
,
516 PCI_COMMAND
, &pci_command
);
517 new_command
= pci_command
| PCI_COMMAND_MASTER
|PCI_COMMAND_IO
;
518 if (pci_command
!= new_command
) {
519 printk(KERN_INFO
" The PCI BIOS has not enabled this"
520 " device! Updating PCI command %4.4x->%4.4x.\n",
521 pci_command
, new_command
);
522 pcibios_write_config_word(pci_bus
, pci_device_fn
,
523 PCI_COMMAND
, new_command
);
526 dev
= tulip_probe1(pci_bus
, pci_device_fn
, dev
, chip_idx
, cards_found
);
528 /* Get and check the bus-master and latency values. */
530 unsigned char pci_latency
;
531 pcibios_read_config_byte(pci_bus
, pci_device_fn
,
532 PCI_LATENCY_TIMER
, &pci_latency
);
533 if (pci_latency
< 10) {
534 printk(KERN_INFO
" PCI latency timer (CFLT) is "
535 "unreasonably low at %d. Setting to 64 clocks.\n",
537 pcibios_write_config_byte(pci_bus
, pci_device_fn
,
538 PCI_LATENCY_TIMER
, 64);
539 } else if (tulip_debug
> 1)
540 printk(KERN_INFO
" PCI latency timer (CFLT) is %#x, "
541 " PCI command is %4.4x.\n",
542 pci_latency
, new_command
);
543 /* Bring the 21143 out power-down mode. */
544 if (device
== PCI_DEVICE_ID_DEC_TULIP_21142
)
545 pcibios_write_config_dword(pci_bus
, pci_device_fn
,
552 return cards_found
? 0 : -ENODEV
;
555 static struct net_device
*tulip_probe1(int pci_bus
, int pci_device_fn
,
556 struct net_device
*dev
,
557 int chip_id
, int board_idx
)
559 static int did_version
= 0; /* Already printed version info. */
560 struct tulip_private
*tp
;
563 /* See note below on the multiport cards. */
564 static unsigned char last_phys_addr
[6] = {0x00, 'L', 'i', 'n', 'u', 'x'};
565 static int last_irq
= 0;
566 static int multiport_cnt
= 0; /* For four-port boards w/one EEPROM */
570 if (tulip_debug
> 0 && did_version
++ == 0)
571 printk(KERN_INFO
"%s", version
);
573 dev
= init_etherdev(dev
, 0);
575 irq
= pci_find_slot(pci_bus
, pci_device_fn
)->irq
;
576 ioaddr
= pci_find_slot(pci_bus
, pci_device_fn
)->resource
[0].start
;
578 printk(KERN_INFO
"%s: %s at %#3lx,",
579 dev
->name
, tulip_tbl
[chip_id
].chip_name
, ioaddr
);
581 /* Stop the chip's Tx and Rx processes. */
582 outl(inl(ioaddr
+ CSR6
) & ~0x2002, ioaddr
+ CSR6
);
583 /* Clear the missed-packet counter. */
584 (volatile int)inl(ioaddr
+ CSR8
);
586 if (chip_id
== DC21041
) {
587 if (inl(ioaddr
+ CSR9
) & 0x8000) {
588 printk(" 21040 compatible mode,");
591 printk(" 21041 mode,");
595 /* The station address ROM is read byte serially. The register must
596 be polled, waiting for the value to be read bit serially from the
600 if (chip_id
== DC21040
) {
601 outl(0, ioaddr
+ CSR9
); /* Reset the pointer with a dummy write. */
602 for (i
= 0; i
< 6; i
++) {
603 int value
, boguscnt
= 100000;
605 value
= inl(ioaddr
+ CSR9
);
606 while (value
< 0 && --boguscnt
> 0);
607 dev
->dev_addr
[i
] = value
;
610 } else if (chip_id
== LC82C168
) {
611 for (i
= 0; i
< 3; i
++) {
612 int value
, boguscnt
= 100000;
613 outl(0x600 | i
, ioaddr
+ 0x98);
615 value
= inl(ioaddr
+ CSR9
);
616 while (value
< 0 && --boguscnt
> 0);
617 ((u16
*)dev
->dev_addr
)[i
] = value
;
618 sum
+= value
& 0xffff;
620 } else { /* Must be a new chip, with a serial EEPROM interface. */
621 /* We read the whole EEPROM, and sort it out later. DEC has a
622 specification _Digital Semiconductor 21X4 Serial ROM Format_
623 but early vendor boards just put the address in the first six
625 unsigned char ee_data
[128];
628 for (i
= 0; i
< sizeof(ee_data
)/2; i
++)
629 ((u16
*)ee_data
)[i
] = read_eeprom(ioaddr
, i
);
631 /* Detect the simple EEPROM format by the duplicated station addr. */
632 for (i
= 0; i
< 8; i
++)
633 if (ee_data
[i
] != ee_data
[16+i
])
635 if (ee_data
[0] == 0xff && ee_data
[1] == 0xff && ee_data
[2] == 0) {
636 sa_offset
= 2; /* Grrr, damn Matrox boards. */
639 for (i
= 0; i
< 6; i
++) {
640 dev
->dev_addr
[i
] = ee_data
[i
+ sa_offset
];
641 sum
+= ee_data
[i
+ sa_offset
];
644 /* Lite-On boards have the address byte-swapped. */
645 if (dev
->dev_addr
[0] == 0xA0 && dev
->dev_addr
[1] == 0x00)
646 for (i
= 0; i
< 6; i
+=2) {
647 char tmp
= dev
->dev_addr
[i
];
648 dev
->dev_addr
[i
] = dev
->dev_addr
[i
+1];
649 dev
->dev_addr
[i
+1] = tmp
;
651 /* On the Zynx 315 Etherarray and other multiport boards only the
652 first Tulip has an EEPROM.
653 The addresses of the subsequent ports are derived from the first.
654 Many PCI BIOSes also incorrectly report the IRQ line, so we correct
655 that here as well. */
656 if (sum
== 0 || sum
== 6*0xff) {
657 printk(" EEPROM not present,");
658 for (i
= 0; i
< 5; i
++)
659 dev
->dev_addr
[i
] = last_phys_addr
[i
];
660 dev
->dev_addr
[i
] = last_phys_addr
[i
] + 1;
661 #if defined(__i386__) /* This BIOS bug doesn't exist on Alphas. */
666 for (i
= 0; i
< 6; i
++)
667 printk(" %2.2x", last_phys_addr
[i
] = dev
->dev_addr
[i
]);
668 printk(", IRQ %d.\n", irq
);
671 /* We do a request_region() only to register /proc/ioports info. */
672 /* Note that proper size is tulip_tbl[chip_id].chip_name, but... */
673 request_region(ioaddr
, TULIP_TOTAL_SIZE
, dev
->name
);
675 dev
->base_addr
= ioaddr
;
678 /* Make certain the data structures are quadword aligned. */
679 tp
= (void *)(((long)kmalloc(sizeof(*tp
), GFP_KERNEL
| GFP_DMA
) + 7) & ~7);
680 memset(tp
, 0, sizeof(*tp
));
683 tp
->next_module
= root_tulip_dev
;
684 root_tulip_dev
= dev
;
686 tp
->pci_bus
= pci_bus
;
687 tp
->pci_dev_fn
= pci_device_fn
;
688 tp
->chip_id
= chip_id
;
690 #ifdef TULIP_FULL_DUPLEX
692 tp
->full_duplex_lock
= 1;
694 #ifdef TULIP_DEFAULT_MEDIA
695 tp
->default_port
= TULIP_DEFAULT_MEDIA
;
697 #ifdef TULIP_NO_MEDIA_SWITCH
701 /* The lower four bits are the media type. */
702 if (board_idx
>= 0 && board_idx
< MAX_UNITS
) {
703 tp
->default_port
= options
[board_idx
] & 15;
704 if ((options
[board_idx
] & 0x90) || full_duplex
[board_idx
] > 0)
706 if (mtu
[board_idx
] > 0)
707 dev
->mtu
= mtu
[board_idx
];
710 tp
->default_port
= dev
->mem_start
;
711 if (tp
->default_port
) {
713 if (media_cap
[tp
->default_port
] & MediaAlwaysFD
)
717 tp
->full_duplex_lock
= 1;
719 /* This is logically part of probe1(), but too complex to write inline. */
720 if (tulip_tbl
[chip_id
].flags
& HAS_MEDIA_TABLE
)
723 if (media_cap
[tp
->default_port
] & MediaIsMII
) {
724 u16 media2advert
[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
725 tp
->to_advertise
= media2advert
[tp
->default_port
- 9];
727 tp
->to_advertise
= 0x03e1;
729 if ((tp
->mtable
&& tp
->mtable
->has_mii
) ||
730 ( ! tp
->mtable
&& (tulip_tbl
[tp
->chip_id
].flags
& HAS_MII
))) {
732 /* Find the connected MII xcvrs.
733 Doing this in open() would allow detecting external xcvrs later,
734 but takes much time. */
735 for (phy
= 0, phy_idx
= 0; phy
< 32 && phy_idx
< sizeof(tp
->phys
);
737 int mii_status
= mdio_read(dev
, phy
, 1);
738 if (mii_status
!= 0xffff && mii_status
!= 0x0000) {
739 int mii_reg0
= mdio_read(dev
, phy
, 0);
740 int reg4
= ((mii_status
>>6) & tp
->to_advertise
) | 1;
741 tp
->phys
[phy_idx
] = phy
;
742 tp
->advertising
[phy_idx
++] = reg4
;
743 printk(KERN_INFO
"%s: MII transceiver found at MDIO address "
744 "%d, config %4.4x status %4.4x.\n",
745 dev
->name
, phy
, mii_reg0
, mii_status
);
746 if (1 || (media_cap
[tp
->default_port
] & MediaIsMII
)) {
747 printk(KERN_DEBUG
"%s: Advertising %4.4x on PHY %d,"
748 " previously advertising %4.4x.\n",
749 dev
->name
, reg4
, phy
, mdio_read(dev
, phy
, 4));
750 mdio_write(dev
, phy
, 4, reg4
);
752 /* Enable autonegotiation: some boards default to off. */
753 mdio_write(dev
, phy
, 0, mii_reg0
|
754 (tp
->full_duplex
? 0x1100 : 0x1000) |
755 (media_cap
[tp
->default_port
]&MediaIs100
? 0x2000:0));
758 tp
->mii_cnt
= phy_idx
;
759 if (tp
->mtable
&& tp
->mtable
->has_mii
&& phy_idx
== 0) {
760 printk(KERN_INFO
"%s: ***WARNING***: No MII transceiver found!\n",
766 /* The Tulip-specific entries in the device structure. */
767 dev
->open
= &tulip_open
;
768 dev
->hard_start_xmit
= &tulip_start_xmit
;
769 dev
->stop
= &tulip_close
;
770 dev
->get_stats
= &tulip_get_stats
;
771 #ifdef HAVE_PRIVATE_IOCTL
772 dev
->do_ioctl
= &private_ioctl
;
774 #ifdef HAVE_MULTICAST
775 dev
->set_multicast_list
= &set_rx_mode
;
778 /* Reset the xcvr interface and turn on heartbeat. */
781 outl(0x00000000, ioaddr
+ CSR13
);
782 outl(0xFFFFFFFF, ioaddr
+ CSR14
);
783 outl(0x00000008, ioaddr
+ CSR15
); /* Listen on AUI also. */
784 outl(inl(ioaddr
+ CSR6
) | 0x0200, ioaddr
+ CSR6
);
785 outl(0x0000EF05, ioaddr
+ CSR13
);
788 outl(0x00000000, ioaddr
+ CSR13
);
789 outl(0x00000004, ioaddr
+ CSR13
);
791 case DC21140
: default:
793 outl(tp
->mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
796 outl(0x82420200, ioaddr
+ CSR6
);
797 outl(0x0001, ioaddr
+ CSR13
);
798 outl(0x0003FFFF, ioaddr
+ CSR14
);
799 outl(0x0008, ioaddr
+ CSR15
);
800 outl(0x0001, ioaddr
+ CSR13
);
801 outl(0x1301, ioaddr
+ CSR12
); /* Start NWay. */
804 if ( ! tp
->mii_cnt
) {
805 outl(0x00420000, ioaddr
+ CSR6
);
806 outl(0x30, ioaddr
+ CSR12
);
807 outl(0x0001F078, ioaddr
+ 0xB8);
808 outl(0x0201F078, ioaddr
+ 0xB8); /* Turn on autonegotiation. */
811 case MX98713
: case MX98715
: case MX98725
:
812 outl(0x00000000, ioaddr
+ CSR6
);
813 outl(0x000711C0, ioaddr
+ CSR14
); /* Turn on NWay. */
814 outl(0x00000001, ioaddr
+ CSR13
);
821 /* Serial EEPROM section. */
822 /* The main routine to parse the very complicated SROM structure.
823 Search www.digital.com for "21X4 SROM" to get details.
824 This code is very complex, and will require changes to support
825 additional cards, so I'll be verbose about what is going on.
828 /* Known cards that have old-style EEPROMs. */
829 static struct fixups
{
831 unsigned char addr0
, addr1
, addr2
;
832 u16 newtable
[32]; /* Max length below. */
833 } eeprom_fixups
[] = {
834 {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
835 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
836 {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x021f,
837 0x0000, 0x009E, /* 10baseT */
838 0x0903, 0x006D, /* 100baseTx */ }},
839 {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x033f,
840 0x0107, 0x8021, /* 100baseFx */
841 0x0108, 0x8021, /* 100baseFx-FD */
842 0x0103, 0x006D, /* 100baseTx */ }},
843 {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0313,
844 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
845 0x0000, 0x009E, /* 10baseT */
846 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ }},
847 {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x031F,
848 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
849 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
850 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
854 static const char * block_name
[] = {"21140 non-MII", "21140 MII PHY",
855 "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
857 #define EEPROM_SIZE 128
858 #if defined(__i386__)
859 #define get_u16(ptr) (*(u16 *)(ptr))
861 #define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8))
864 static void parse_eeprom(struct net_device
*dev
)
866 /* The last media info list parsed, for multiport boards. */
867 static struct mediatable
*last_mediatable
= NULL
;
868 static unsigned char *last_ee_data
= NULL
;
869 static int controller_index
= 0;
870 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
871 long ioaddr
= dev
->base_addr
;
872 unsigned char *ee_data
= tp
->eeprom
;
876 for (i
= 0; i
< EEPROM_SIZE
/2; i
++)
877 ((u16
*)ee_data
)[i
] = read_eeprom(ioaddr
, i
);
879 /* Detect an old-style (SA only) EEPROM layout:
880 memcmp(eedata, eedata+16, 8). */
881 for (i
= 0; i
< 8; i
++)
882 if (ee_data
[i
] != ee_data
[16+i
])
885 if (ee_data
[0] == 0xff) {
886 if (last_mediatable
) {
888 printk(KERN_INFO
"%s: Controller %d of multiport board.\n",
889 dev
->name
, controller_index
);
890 tp
->mtable
= last_mediatable
;
891 ee_data
= last_ee_data
;
892 goto subsequent_board
;
894 printk(KERN_INFO
"%s: Missing EEPROM, this interface may "
895 "not work correctly!\n",
899 /* Do a fix-up based on the vendor half of the station address prefix. */
900 for (i
= 0; eeprom_fixups
[i
].name
; i
++) {
901 if (dev
->dev_addr
[0] == eeprom_fixups
[i
].addr0
902 && dev
->dev_addr
[1] == eeprom_fixups
[i
].addr1
903 && dev
->dev_addr
[2] == eeprom_fixups
[i
].addr2
) {
904 if (dev
->dev_addr
[2] == 0xE8 && ee_data
[0x1a] == 0x55)
905 i
++; /* An Accton EN1207, not an outlaw Maxtech. */
906 memcpy(ee_data
+ 26, eeprom_fixups
[i
].newtable
,
907 sizeof(eeprom_fixups
[i
].newtable
));
908 printk(KERN_INFO
"%s: Old format EEPROM on '%s' board. Using"
909 " substitute media control info.\n",
910 dev
->name
, eeprom_fixups
[i
].name
);
914 if (eeprom_fixups
[i
].name
== NULL
) { /* No fixup found. */
915 printk(KERN_INFO
"%s: Old style EEPROM -- no media selection information.\n",
920 if (tulip_debug
> 1) {
921 printk(KERN_DEBUG
"read_eeprom:");
922 for (i
= 0; i
< 64; i
++) {
923 printk("%s%4.4x", (i
& 7) == 0 ? "\n" KERN_DEBUG
: " ",
924 read_eeprom(ioaddr
, i
));
929 controller_index
= 0;
930 if (ee_data
[19] > 1) { /* Multiport board. */
931 last_ee_data
= ee_data
;
935 if (ee_data
[27] == 0) { /* No valid media table. */
936 } else if (tp
->chip_id
== DC21041
) {
937 unsigned char *p
= (void *)ee_data
+ ee_data
[27 + controller_index
*3];
945 printk(KERN_INFO
"%s:21041 Media information at %d, default media "
946 "%4.4x (%s).\n", dev
->name
, ee_data
[27], media
,
947 media
& 0x0800 ? "Autosense" : medianame
[media
& 15]);
948 for (i
= 0; i
< count
; i
++) {
949 unsigned char media_code
= *p
++;
952 for (idx
= 0; idx
< 3; idx
++) {
953 csrvals
[idx
] = get_u16(p
);
956 if (media_code
& 0x40) {
957 printk(KERN_INFO
"%s: 21041 media %2.2x (%s),"
958 " csr13 %4.4x csr14 %4.4x csr15 %4.4x.\n",
959 dev
->name
, media_code
& 15, medianame
[media_code
& 15],
960 csrvals
[0], csrvals
[1], csrvals
[2]);
962 printk(KERN_INFO
"%s: 21041 media #%d, %s.\n",
963 dev
->name
, media_code
& 15, medianame
[media_code
& 15]);
966 unsigned char *p
= (void *)ee_data
+ ee_data
[27];
967 unsigned char csr12dir
= 0;
969 struct mediatable
*mtable
;
970 u16 media
= get_u16(p
);
973 if (tulip_tbl
[tp
->chip_id
].flags
& CSR12_IN_SROM
)
976 mtable
= (struct mediatable
*)
977 kmalloc(sizeof(struct mediatable
) + count
*sizeof(struct medialeaf
),
980 return; /* Horrible, impossible failure. */
981 last_mediatable
= tp
->mtable
= mtable
;
982 mtable
->defaultmedia
= media
;
983 mtable
->leafcount
= count
;
984 mtable
->csr12dir
= csr12dir
;
985 mtable
->has_nonmii
= mtable
->has_mii
= 0;
987 printk(KERN_INFO
"%s: EEPROM default media type %s.\n", dev
->name
,
988 media
& 0x0800 ? "Autosense" : medianame
[media
& 15]);
989 for (i
= 0; i
< count
; i
++) {
990 struct medialeaf
*leaf
= &mtable
->mleaf
[i
];
992 if ((p
[0] & 0x80) == 0) { /* 21140 Compact block. */
994 leaf
->media
= p
[0] & 0x3f;
996 if ((p
[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
1002 mtable
->has_mii
= 1;
1005 mtable
->has_nonmii
= 1;
1006 leaf
->media
= p
[2] & 0x0f;
1008 leaf
->leafdata
= p
+ 2;
1009 p
+= (p
[0] & 0x3f) + 1;
1011 if (tulip_debug
> 1 && leaf
->media
== 11) {
1012 unsigned char *bp
= leaf
->leafdata
;
1013 printk(KERN_INFO
"%s: MII interface PHY %d, setup/reset "
1014 "sequences %d/%d long, capabilities %2.2x %2.2x.\n",
1015 dev
->name
, bp
[0], bp
[1], bp
[1 + bp
[1]*2],
1016 bp
[5 + bp
[2 + bp
[1]*2]*2], bp
[4 + bp
[2 + bp
[1]*2]*2]);
1018 printk(KERN_INFO
"%s: Index #%d - Media %s (#%d) described "
1019 "by a %s (%d) block.\n",
1020 dev
->name
, i
, medianame
[leaf
->media
], leaf
->media
,
1021 block_name
[leaf
->type
], leaf
->type
);
1025 /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/
1027 /* EEPROM_Ctrl bits. */
1028 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
1029 #define EE_CS 0x01 /* EEPROM chip select. */
1030 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
1031 #define EE_WRITE_0 0x01
1032 #define EE_WRITE_1 0x05
1033 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
1034 #define EE_ENB (0x4800 | EE_CS)
1036 /* Delay between EEPROM clock transitions.
1037 The 1.2 code is a "nasty" timing loop, but PC compatible machines are
1038 *supposed* to delay an ISA-compatible period for the SLOW_DOWN_IO macro. */
1039 #ifdef _LINUX_DELAY_H
1040 #define eeprom_delay(nanosec) udelay((nanosec + 999)/1000)
1042 #define eeprom_delay(nanosec) do { int _i = 3; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
1045 /* The EEPROM commands include the alway-set leading bit. */
1046 #define EE_WRITE_CMD (5 << 6)
1047 #define EE_READ_CMD (6 << 6)
1048 #define EE_ERASE_CMD (7 << 6)
1050 static int read_eeprom(long ioaddr
, int location
)
1053 unsigned short retval
= 0;
1054 long ee_addr
= ioaddr
+ CSR9
;
1055 int read_cmd
= location
| EE_READ_CMD
;
1057 outl(EE_ENB
& ~EE_CS
, ee_addr
);
1058 outl(EE_ENB
, ee_addr
);
1060 /* Shift the read command bits out. */
1061 for (i
= 10; i
>= 0; i
--) {
1062 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
1063 outl(EE_ENB
| dataval
, ee_addr
);
1065 outl(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
1067 outl(EE_ENB
| dataval
, ee_addr
); /* Finish EEPROM a clock tick. */
1070 outl(EE_ENB
, ee_addr
);
1072 for (i
= 16; i
> 0; i
--) {
1073 outl(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
1075 retval
= (retval
<< 1) | ((inl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1076 outl(EE_ENB
, ee_addr
);
1080 /* Terminate the EEPROM access. */
1081 outl(EE_ENB
& ~EE_CS
, ee_addr
);
1085 /* MII transceiver control section.
1086 Read and write the MII registers using software-generated serial
1087 MDIO protocol. See the MII specifications or DP83840A data sheet
1090 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
1091 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
1092 "overclocking" issues or future 66Mhz PCI. */
1093 #define mdio_delay() inl(mdio_addr)
1095 /* Read and write the MII registers using software-generated serial
1096 MDIO protocol. It is just different enough from the EEPROM protocol
1097 to not share code. The maxium data clock rate is 2.5 Mhz. */
1098 #define MDIO_SHIFT_CLK 0x10000
1099 #define MDIO_DATA_WRITE0 0x00000
1100 #define MDIO_DATA_WRITE1 0x20000
1101 #define MDIO_ENB 0x00000 /* Ignore the 0x02000 databook setting. */
1102 #define MDIO_ENB_IN 0x40000
1103 #define MDIO_DATA_READ 0x80000
1105 static int mdio_read(struct net_device
*dev
, int phy_id
, int location
)
1107 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1109 int read_cmd
= (0xf6 << 10) | (phy_id
<< 5) | location
;
1111 long mdio_addr
= dev
->base_addr
+ CSR9
;
1113 if (tp
->chip_id
== LC82C168
) {
1114 long ioaddr
= dev
->base_addr
;
1116 outl(0x60020000 + (phy_id
<<23) + (location
<<18), ioaddr
+ 0xA0);
1118 if ( ! ((retval
= inl(ioaddr
+ 0xA0)) & 0x80000000))
1119 return retval
& 0xffff;
1123 /* Establish sync by sending at least 32 logic ones. */
1124 for (i
= 32; i
>= 0; i
--) {
1125 outl(MDIO_ENB
| MDIO_DATA_WRITE1
, mdio_addr
);
1127 outl(MDIO_ENB
| MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, mdio_addr
);
1130 /* Shift the read command bits out. */
1131 for (i
= 15; i
>= 0; i
--) {
1132 int dataval
= (read_cmd
& (1 << i
)) ? MDIO_DATA_WRITE1
: 0;
1134 outl(MDIO_ENB
| dataval
, mdio_addr
);
1136 outl(MDIO_ENB
| dataval
| MDIO_SHIFT_CLK
, mdio_addr
);
1139 /* Read the two transition, 16 data, and wire-idle bits. */
1140 for (i
= 19; i
> 0; i
--) {
1141 outl(MDIO_ENB_IN
, mdio_addr
);
1143 retval
= (retval
<< 1) | ((inl(mdio_addr
) & MDIO_DATA_READ
) ? 1 : 0);
1144 outl(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
);
1147 return (retval
>>1) & 0xffff;
1150 static void mdio_write(struct net_device
*dev
, int phy_id
, int location
, int value
)
1152 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1154 int cmd
= (0x5002 << 16) | (phy_id
<< 23) | (location
<<18) | value
;
1155 long mdio_addr
= dev
->base_addr
+ CSR9
;
1157 if (tp
->chip_id
== LC82C168
) {
1158 long ioaddr
= dev
->base_addr
;
1160 outl(cmd
, ioaddr
+ 0xA0);
1162 if ( ! (inl(ioaddr
+ 0xA0) & 0x80000000))
1168 /* Establish sync by sending 32 logic ones. */
1169 for (i
= 32; i
>= 0; i
--) {
1170 outl(MDIO_ENB
| MDIO_DATA_WRITE1
, mdio_addr
);
1172 outl(MDIO_ENB
| MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, mdio_addr
);
1175 /* Shift the command bits out. */
1176 for (i
= 31; i
>= 0; i
--) {
1177 int dataval
= (cmd
& (1 << i
)) ? MDIO_DATA_WRITE1
: 0;
1178 outl(MDIO_ENB
| dataval
, mdio_addr
);
1180 outl(MDIO_ENB
| dataval
| MDIO_SHIFT_CLK
, mdio_addr
);
1183 /* Clear out extra bits. */
1184 for (i
= 2; i
> 0; i
--) {
1185 outl(MDIO_ENB_IN
, mdio_addr
);
1187 outl(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
);
1195 tulip_open(struct net_device
*dev
)
1197 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1198 long ioaddr
= dev
->base_addr
;
1201 /* On some chip revs we must set the MII/SYM port before the reset!? */
1202 if (tp
->mii_cnt
|| (tp
->mtable
&& tp
->mtable
->has_mii
))
1203 outl(0x00040000, ioaddr
+ CSR6
);
1205 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1206 outl(0x00000001, ioaddr
+ CSR0
);
1207 #ifdef _LINUX_DELAY_H
1213 486: Set 8 longword cache alignment, 8 longword burst.
1214 586: Set 16 longword cache alignment, no burst limit.
1215 Cache alignment bits 15:14 Burst length 13:8
1216 0000 No alignment 0x00000000 unlimited 0800 8 longwords
1217 4000 8 longwords 0100 1 longword 1000 16 longwords
1218 8000 16 longwords 0200 2 longwords 2000 32 longwords
1219 C000 32 longwords 0400 4 longwords
1220 Wait the specified 50 PCI cycles after a reset by initializing
1221 Tx and Rx queues and the address filter list. */
1222 #if defined(__alpha__)
1223 /* ToDo: Alpha setting could be better. */
1224 outl(0x01A00000 | 0xE000, ioaddr
+ CSR0
);
1225 #elif defined(__powerpc__)
1226 outl(0x01A00080 | 0x8000, ioaddr
+ CSR0
);
1227 #elif defined(__i386__)
1229 /* When a module we don't have 'x86' to check. */
1230 outl(0x01A00000 | 0x4800, ioaddr
+ CSR0
);
1232 #if (LINUX_VERSION_CODE > 0x2014c)
1233 #define x86 boot_cpu_data.x86
1235 outl(0x01A00000 | (x86
<= 4 ? 0x4800 : 0x8000), ioaddr
+ CSR0
);
1237 printk(KERN_INFO
"%s: This is a 386/486 PCI system, setting cache "
1238 "alignment to %x.\n", dev
->name
,
1239 0x01A00000 | (x86
<= 4 ? 0x4800 : 0x8000));
1242 outl(0x01A00000 | 0x4800, ioaddr
+ CSR0
);
1243 #warning Processor architecture undefined!
1247 if (request_irq(dev
->irq
, &tulip_interrupt
, SA_SHIRQ
, dev
->name
, dev
)) {
1251 if (irq2dev_map
[dev
->irq
] != NULL
1252 || (irq2dev_map
[dev
->irq
] = dev
) == NULL
1254 || request_irq(dev
->irq
, &tulip_interrupt
, 0,
1255 tulip_tbl
[tp
->chip_id
].chip_name
)) {
1260 if (tulip_debug
> 1)
1261 printk(KERN_DEBUG
"%s: tulip_open() irq %d.\n", dev
->name
, dev
->irq
);
1265 tulip_init_ring(dev
);
1267 /* This is set_rx_mode(), but without starting the transmitter. */
1268 /* Fill the whole address filter table with our physical address. */
1270 u16
*eaddrs
= (u16
*)dev
->dev_addr
;
1271 u32
*setup_frm
= tp
->setup_frame
, i
;
1273 /* You must add the broadcast address when doing perfect filtering! */
1274 *setup_frm
++ = 0xffff;
1275 *setup_frm
++ = 0xffff;
1276 *setup_frm
++ = 0xffff;
1277 /* Fill the rest of the accept table with our physical address. */
1278 for (i
= 1; i
< 16; i
++) {
1279 *setup_frm
++ = eaddrs
[0];
1280 *setup_frm
++ = eaddrs
[1];
1281 *setup_frm
++ = eaddrs
[2];
1283 /* Put the setup frame on the Tx list. */
1284 tp
->tx_ring
[0].length
= 0x08000000 | 192;
1285 tp
->tx_ring
[0].buffer1
= virt_to_bus(tp
->setup_frame
);
1286 tp
->tx_ring
[0].status
= 0x80000000;
1291 outl(virt_to_bus(tp
->rx_ring
), ioaddr
+ CSR3
);
1292 outl(virt_to_bus(tp
->tx_ring
), ioaddr
+ CSR4
);
1294 if (dev
->if_port
== 0)
1295 dev
->if_port
= tp
->default_port
;
1296 if (tp
->chip_id
== DC21041
&& dev
->if_port
> 4)
1297 /* Invalid: Select initial TP, autosense, autonegotiate. */
1300 /* Allow selecting a default media. */
1301 if (tp
->mtable
== NULL
)
1304 int looking_for
= media_cap
[dev
->if_port
] & MediaIsMII
? 11 :
1305 (dev
->if_port
== 12 ? 0 : dev
->if_port
);
1306 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
1307 if (tp
->mtable
->mleaf
[i
].media
== looking_for
) {
1308 printk(KERN_INFO
"%s: Using user-specified media %s.\n",
1309 dev
->name
, medianame
[dev
->if_port
]);
1313 if ((tp
->mtable
->defaultmedia
& 0x0800) == 0)
1314 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
1315 if (tp
->mtable
->mleaf
[i
].media
== (tp
->mtable
->defaultmedia
& 15)) {
1316 printk(KERN_INFO
"%s: Using EEPROM-set media %s.\n",
1317 dev
->name
, medianame
[tp
->mtable
->mleaf
[i
].media
]);
1320 /* Start sensing first non-full-duplex media. */
1321 for (i
= tp
->mtable
->leafcount
- 1;
1322 (media_cap
[tp
->mtable
->mleaf
[i
].media
] & MediaAlwaysFD
) && i
> 0; i
--)
1328 if (dev
->if_port
== 0 && tp
->chip_id
== DC21142
) {
1329 tp
->csr6
= 0x82420200;
1330 outl(0x0003FFFF, ioaddr
+ CSR14
);
1331 outl(0x0008, ioaddr
+ CSR15
);
1332 outl(0x0001, ioaddr
+ CSR13
);
1333 outl(0x1301, ioaddr
+ CSR12
);
1334 } else if (tp
->chip_id
== LC82C168
&& tp
->mii_cnt
&& ! tp
->medialock
) {
1336 tp
->csr6
= 0x816C0000 | (tp
->full_duplex
? 0x0200 : 0);
1337 outl(0x0001, ioaddr
+ CSR15
);
1339 select_media(dev
, 1);
1341 /* Start the chip's Tx to process setup frame. */
1342 outl(tp
->csr6
, ioaddr
+ CSR6
);
1343 outl(tp
->csr6
| 0x2000, ioaddr
+ CSR6
);
1349 /* Enable interrupts by setting the interrupt mask. */
1350 outl(tulip_tbl
[tp
->chip_id
].valid_intrs
, ioaddr
+ CSR5
);
1351 outl(tulip_tbl
[tp
->chip_id
].valid_intrs
, ioaddr
+ CSR7
);
1352 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1353 outl(0, ioaddr
+ CSR2
); /* Rx poll demand */
1355 if (tulip_debug
> 2) {
1356 printk(KERN_DEBUG
"%s: Done tulip_open(), CSR0 %8.8x, CSR5 %8.8x CSR6 %8.8x.\n",
1357 dev
->name
, inl(ioaddr
+ CSR0
), inl(ioaddr
+ CSR5
),
1358 inl(ioaddr
+ CSR6
));
1360 /* Set the timer to switch to check for link beat and perhaps switch
1361 to an alternate media type. */
1362 init_timer(&tp
->timer
);
1363 tp
->timer
.expires
= RUN_AT(5*HZ
);
1364 tp
->timer
.data
= (unsigned long)dev
;
1365 tp
->timer
.function
= tulip_tbl
[tp
->chip_id
].media_timer
;
1366 add_timer(&tp
->timer
);
1371 /* Set up the transceiver control registers for the selected media type. */
1372 static void select_media(struct net_device
*dev
, int startup
)
1374 long ioaddr
= dev
->base_addr
;
1375 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1376 struct mediatable
*mtable
= tp
->mtable
;
1378 int check_mii
=0, i
;
1381 struct medialeaf
*mleaf
= &mtable
->mleaf
[tp
->cur_index
];
1382 unsigned char *p
= mleaf
->leafdata
;
1383 switch (mleaf
->type
) {
1384 case 0: /* 21140 non-MII xcvr. */
1385 if (tulip_debug
> 1)
1386 printk(KERN_DEBUG
"%s: Using a 21140 non-MII transceiver"
1387 " with control setting %2.2x.\n",
1389 dev
->if_port
= p
[0];
1391 outl(mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
1392 outl(p
[1], ioaddr
+ CSR12
);
1393 new_csr6
= 0x02000000 | ((p
[2] & 0x71) << 18);
1397 for (i
= 0; i
< 3; i
++)
1398 setup
[i
] = get_u16(&p
[i
*2 + 1]);
1400 dev
->if_port
= p
[0] & 15;
1401 if (tulip_debug
> 1)
1402 printk(KERN_DEBUG
"%s: 21142 non-MII %s transceiver control %4.4x/%4.4x.\n",
1403 dev
->name
, medianame
[dev
->if_port
], setup
[0], setup
[1]);
1404 if (p
[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */
1405 outl(0, ioaddr
+ CSR13
);
1406 outl(setup
[1], ioaddr
+ CSR14
);
1407 outl(setup
[2], ioaddr
+ CSR15
);
1408 outl(setup
[0], ioaddr
+ CSR13
);
1409 for (i
= 0; i
< 3; i
++) /* Re-fill setup[] */
1410 setup
[i
] = get_u16(&p
[i
*2 + 7]);
1411 } else if (dev
->if_port
<= 4) {
1412 outl(0, ioaddr
+ CSR13
);
1413 outl(t21142_csr14
[dev
->if_port
], ioaddr
+ CSR14
);
1414 outl(t21142_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
1415 outl(t21142_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
1417 outl(0, ioaddr
+ CSR14
);
1418 outl(8, ioaddr
+ CSR15
);
1419 outl(0, ioaddr
+ CSR13
);
1421 outl(setup
[0]<<16, ioaddr
+ CSR15
); /* Direction */
1422 outl(setup
[1]<<16, ioaddr
+ CSR15
); /* Data */
1423 if (mleaf
->type
== 4)
1424 new_csr6
= 0x82020000 | ((setup
[2] & 0x71) << 18);
1426 new_csr6
= 0x82420000;
1431 int init_length
= p
[1];
1437 new_csr6
= 0x020E0000;
1438 if (mleaf
->type
== 3) { /* 21142 */
1439 u16
*init_sequence
= (u16
*)(p
+2);
1440 u16
*reset_sequence
= &((u16
*)(p
+3))[init_length
];
1441 int reset_length
= p
[2 + init_length
*2];
1442 misc_info
= reset_sequence
+ reset_length
;
1444 for (i
= 0; i
< reset_length
; i
++)
1445 outl(get_u16(&reset_sequence
[i
]) << 16, ioaddr
+ CSR15
);
1446 for (i
= 0; i
< init_length
; i
++)
1447 outl(get_u16(&init_sequence
[i
]) << 16, ioaddr
+ CSR15
);
1449 u8
*init_sequence
= p
+ 2;
1450 u8
*reset_sequence
= p
+ 3 + init_length
;
1451 int reset_length
= p
[2 + init_length
];
1452 misc_info
= (u16
*)(reset_sequence
+ reset_length
);
1454 outl(mtable
->csr12dir
| 0x100, ioaddr
+ CSR12
);
1455 for (i
= 0; i
< reset_length
; i
++)
1456 outl(reset_sequence
[i
], ioaddr
+ CSR12
);
1458 for (i
= 0; i
< init_length
; i
++)
1459 outl(init_sequence
[i
], ioaddr
+ CSR12
);
1461 to_advertise
= (get_u16(&misc_info
[1]) & tp
->to_advertise
) | 1;
1462 tp
->advertising
[phy_num
] = to_advertise
;
1463 if (tulip_debug
> 1 || 1)
1464 printk(KERN_DEBUG
"%s: Advertising %4.4x on PHY %d (%d).\n",
1465 dev
->name
, to_advertise
, phy_num
, tp
->phys
[phy_num
]);
1466 /* Bogus: put in by a committee? */
1467 mdio_write(dev
, tp
->phys
[phy_num
], 4, to_advertise
);
1471 new_csr6
= 0x020E0000;
1473 if (tulip_debug
> 1)
1474 printk(KERN_DEBUG
"%s: Using media type %s, CSR12 is %2.2x.\n",
1475 dev
->name
, medianame
[dev
->if_port
],
1476 inl(ioaddr
+ CSR12
) & 0xff);
1477 } else if (tp
->chip_id
== DC21041
) {
1478 if (tulip_debug
> 1)
1479 printk(KERN_DEBUG
"%s: 21041 using media %s, CSR12 is %4.4x.\n",
1480 dev
->name
, medianame
[dev
->if_port
& 15],
1481 inl(ioaddr
+ CSR12
) & 0xffff);
1482 outl(0x00000000, ioaddr
+ CSR13
); /* Reset the serial interface */
1483 outl(t21041_csr14
[dev
->if_port
], ioaddr
+ CSR14
);
1484 outl(t21041_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
1485 outl(t21041_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
1486 new_csr6
= 0x80020000;
1487 } else if (tp
->chip_id
== LC82C168
) {
1488 if (startup
&& ! tp
->medialock
)
1489 dev
->if_port
= tp
->mii_cnt
? 11 : 0;
1490 if (tulip_debug
> 1)
1491 printk(KERN_DEBUG
"%s: PNIC PHY status is %3.3x, CSR12 %4.4x,"
1493 dev
->name
, inl(ioaddr
+ 0xB8), inl(ioaddr
+ CSR12
),
1494 medianame
[dev
->if_port
]);
1496 new_csr6
= 0x812C0000;
1497 outl(0x0001, ioaddr
+ CSR15
);
1498 outl(0x0201B07A, ioaddr
+ 0xB8);
1499 } else if (startup
) {
1500 /* Start with 10mbps to do autonegotiation. */
1501 outl(0x32, ioaddr
+ CSR12
);
1502 new_csr6
= 0x00420000;
1503 outl(0x0001B078, ioaddr
+ 0xB8);
1504 outl(0x0201B078, ioaddr
+ 0xB8);
1505 } else if (dev
->if_port
== 3 || dev
->if_port
== 5) {
1506 outl(0x33, ioaddr
+ CSR12
);
1507 new_csr6
= 0x01860000;
1509 outl(0x0201F868, ioaddr
+ 0xB8); /* Trigger autonegotiation. */
1511 outl(0x1F868, ioaddr
+ 0xB8);
1513 outl(0x32, ioaddr
+ CSR12
);
1514 new_csr6
= 0x00420000;
1515 outl(0x1F078, ioaddr
+ 0xB8);
1517 } else if (tp
->chip_id
== DC21040
) { /* 21040 */
1518 /* Turn on the xcvr interface. */
1519 int csr12
= inl(ioaddr
+ CSR12
);
1520 if (tulip_debug
> 1)
1521 printk(KERN_DEBUG
"%s: 21040 media type is %s, CSR12 is %2.2x.\n",
1522 dev
->name
, dev
->if_port
? "AUI" : "10baseT", csr12
);
1523 new_csr6
= (dev
->if_port
? 0x01860000 : 0x00420000);
1524 /* Set the full duplux match frame. */
1525 outl(FULL_DUPLEX_MAGIC
, ioaddr
+ CSR11
);
1526 outl(0x00000000, ioaddr
+ CSR13
); /* Reset the serial interface */
1527 outl(dev
->if_port
? 0x0000000C : 0x00000004, ioaddr
+ CSR13
);
1528 } else { /* Unknown chip type with no media table. */
1529 if (tp
->default_port
== 0)
1536 if (media_cap
[dev
->if_port
] & MediaIsMII
) {
1537 new_csr6
= 0x020E0000;
1538 } else if (media_cap
[dev
->if_port
] & MediaIsFx
) {
1539 new_csr6
= 0x028600000;
1541 new_csr6
= 0x038600000;
1542 if (tulip_debug
> 1)
1543 printk(KERN_DEBUG
"%s: No media description table, assuming "
1544 "%s transceiver, CSR12 %2.2x.\n",
1545 dev
->name
, medianame
[dev
->if_port
],
1546 inl(ioaddr
+ CSR12
));
1549 tp
->csr6
= new_csr6
| (tp
->csr6
& 0xfdff) | (tp
->full_duplex
? 0x0200 : 0);
1553 static void tulip_timer(unsigned long data
)
1555 struct net_device
*dev
= (struct net_device
*)data
;
1556 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1557 long ioaddr
= dev
->base_addr
;
1558 u32 csr12
= inl(ioaddr
+ CSR12
);
1561 if (tulip_debug
> 3) {
1562 printk(KERN_DEBUG
"%s: Media selection tick, status %8.8x mode %8.8x "
1563 "SIA %8.8x %8.8x %8.8x %8.8x.\n",
1564 dev
->name
, inl(ioaddr
+ CSR5
), inl(ioaddr
+ CSR6
),
1565 csr12
, inl(ioaddr
+ CSR13
),
1566 inl(ioaddr
+ CSR14
), inl(ioaddr
+ CSR15
));
1568 switch (tp
->chip_id
) {
1570 if (csr12
& 0x0002) { /* Network error */
1571 printk(KERN_INFO
"%s: No 10baseT link beat found, switching to %s media.\n",
1572 dev
->name
, dev
->if_port
? "10baseT" : "AUI");
1574 outl(dev
->if_port
? 0x0000000C : 0x00000004, ioaddr
+ CSR13
);
1575 dev
->trans_start
= jiffies
;
1579 if (tulip_debug
> 2)
1580 printk(KERN_DEBUG
"%s: 21041 media tick CSR12 %8.8x.\n",
1582 switch (dev
->if_port
) {
1583 case 0: case 3: case 4:
1584 if (csr12
& 0x0004) { /*LnkFail */
1585 /* 10baseT is dead. Check for activity on alternate port. */
1591 printk(KERN_INFO
"%s: No 21041 10baseT link beat, Media switched to %s.\n",
1592 dev
->name
, medianame
[dev
->if_port
]);
1593 outl(0, ioaddr
+ CSR13
); /* Reset */
1594 outl(t21041_csr14
[dev
->if_port
], ioaddr
+ CSR14
);
1595 outl(t21041_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
1596 outl(t21041_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
1597 next_tick
= 10*HZ
; /* 2.4 sec. */
1601 case 1: /* 10base2 */
1603 if (csr12
& 0x0100) {
1604 next_tick
= (30*HZ
); /* 30 sec. */
1606 } else if ((csr12
& 0x0004) == 0) {
1607 printk(KERN_INFO
"%s: 21041 media switched to 10baseT.\n", dev
->name
);
1609 select_media(dev
, 0);
1610 next_tick
= (24*HZ
)/10; /* 2.4 sec. */
1611 } else if (tp
->mediasense
|| (csr12
& 0x0002)) {
1612 dev
->if_port
= 3 - dev
->if_port
; /* Swap ports. */
1613 select_media(dev
, 0);
1621 case DC21140
: case DC21142
: case MX98713
: default: {
1622 struct medialeaf
*mleaf
;
1624 if (tp
->mtable
== NULL
) { /* No EEPROM info, use generic code. */
1625 /* Not much that can be done.
1626 Assume this a generic MII or SYM transceiver. */
1628 if (tulip_debug
> 2)
1629 printk(KERN_DEBUG
"%s: network media monitor CSR6 %8.8x "
1631 dev
->name
, inl(ioaddr
+ CSR6
), csr12
& 0xff);
1634 mleaf
= &tp
->mtable
->mleaf
[tp
->cur_index
];
1635 p
= mleaf
->leafdata
;
1636 switch (mleaf
->type
) {
1638 /* Type 0 serial or 4 SYM transceiver. Check the link beat bit. */
1639 int offset
= mleaf
->type
== 4 ? 5 : 2;
1640 s8 bitnum
= p
[offset
];
1641 if (p
[offset
+1] & 0x80) {
1642 if (tulip_debug
> 1)
1643 printk(KERN_DEBUG
"%s: Transceiver monitor tick "
1644 "CSR12=%#2.2x, no media sense.\n",
1646 if (mleaf
->type
== 4) {
1647 if (mleaf
->media
== 3 && (csr12
& 0x02))
1648 goto select_next_media
;
1652 if (tulip_debug
> 2)
1653 printk(KERN_DEBUG
"%s: Transceiver monitor tick: CSR12=%#2.2x"
1654 " bit %d is %d, expecting %d.\n",
1655 dev
->name
, csr12
, (bitnum
>> 1) & 7,
1656 (csr12
& (1 << ((bitnum
>> 1) & 7))) != 0,
1658 /* Check that the specified bit has the proper value. */
1660 ((csr12
& (1 << ((bitnum
>> 1) & 7))) != 0)) {
1661 if (tulip_debug
> 1)
1662 printk(KERN_DEBUG
"%s: Link beat detected for %s.\n", dev
->name
,
1663 medianame
[mleaf
->media
]);
1664 if ((p
[2] & 0x61) == 0x01) /* Bogus Znyx board. */
1671 if (--tp
->cur_index
< 0) {
1672 /* We start again, but should instead look for default. */
1673 tp
->cur_index
= tp
->mtable
->leafcount
- 1;
1675 dev
->if_port
= tp
->mtable
->mleaf
[tp
->cur_index
].media
;
1676 if (media_cap
[dev
->if_port
] & MediaIsFD
)
1677 goto select_next_media
; /* Skip FD entries. */
1678 if (tulip_debug
> 1)
1679 printk(KERN_DEBUG
"%s: No link beat on media %s,"
1680 " trying transceiver type %s.\n",
1681 dev
->name
, medianame
[mleaf
->media
& 15],
1682 medianame
[tp
->mtable
->mleaf
[tp
->cur_index
].media
]);
1683 select_media(dev
, 0);
1684 /* Restart the transmit process. */
1685 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
1686 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1687 next_tick
= (24*HZ
)/10;
1690 case 1: case 3: { /* 21140, 21142 MII */
1691 int mii_reg1
, mii_reg5
;
1693 mii_reg1
= mdio_read(dev
, tp
->phys
[0], 1);
1694 mii_reg5
= mdio_read(dev
, tp
->phys
[0], 5);
1695 if (tulip_debug
> 1)
1696 printk(KERN_INFO
"%s: MII status %4.4x, Link partner report "
1697 "%4.4x, CSR12 %2.2x, %cD.\n",
1698 dev
->name
, mii_reg1
, mii_reg5
, csr12
,
1699 tp
->full_duplex
? 'F' : 'H');
1700 if (mii_reg1
!= 0xffff && (mii_reg1
& 0x0004) == 0) {
1701 int new_reg1
= mdio_read(dev
, tp
->phys
[0], 1);
1702 if ((new_reg1
& 0x0004) == 0) {
1703 printk(KERN_INFO
"%s: No link beat on the MII interface,"
1704 " status then %4.4x now %4.4x.\n",
1705 dev
->name
, mii_reg1
, new_reg1
);
1706 if (tp
->mtable
&& tp
->mtable
->has_nonmii
)
1707 goto select_next_media
;
1710 if (mii_reg5
== 0xffff || mii_reg5
== 0x0000)
1711 ; /* No MII device or no link partner report */
1712 else if (tp
->full_duplex_lock
)
1715 int negotiated
= mii_reg5
& tp
->advertising
[0];
1716 int duplex
= ((negotiated
& 0x0100) != 0
1717 || (negotiated
& 0x00C0) == 0x0040);
1718 /* 100baseTx-FD or 10T-FD, but not 100-HD */
1719 if (tp
->full_duplex
!= duplex
) {
1720 tp
->full_duplex
= duplex
;
1721 if (tp
->full_duplex
)
1724 tp
->csr6
&= ~0x0200;
1725 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
1726 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1727 if (tulip_debug
> 0) /* Gurppp, should be >1 */
1728 printk(KERN_INFO
"%s: Setting %s-duplex based on MII"
1729 " Xcvr #%d parter capability of %4.4x.\n",
1730 dev
->name
, tp
->full_duplex
? "full" : "half",
1731 tp
->phys
[0], mii_reg5
);
1737 case 2: /* 21142 serial block has no link beat. */
1745 tp
->timer
.expires
= RUN_AT(next_tick
);
1746 add_timer(&tp
->timer
);
1750 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
1751 of available transceivers. */
1752 static void t21142_timer(unsigned long data
)
1754 struct net_device
*dev
= (struct net_device
*)data
;
1755 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1756 long ioaddr
= dev
->base_addr
;
1757 int csr12
= inl(ioaddr
+ CSR12
);
1758 int next_tick
= 60*HZ
;
1761 if (tulip_debug
> 1)
1762 printk(KERN_INFO
"%s: 21142 negotiation status %8.8x, %s.\n",
1763 dev
->name
, csr12
, medianame
[dev
->if_port
]);
1764 if (dev
->if_port
== 3) {
1765 if (csr12
& 2) { /* No 100mbps link beat, revert to 10mbps. */
1766 new_csr6
= 0x82420200;
1767 outl(new_csr6
, ioaddr
+ CSR6
);
1768 outl(0x0000, ioaddr
+ CSR13
);
1769 outl(0x0003FFFF, ioaddr
+ CSR14
);
1770 outl(0x0008, ioaddr
+ CSR15
);
1771 outl(0x0001, ioaddr
+ CSR13
);
1772 outl(0x1301, ioaddr
+ CSR12
); /* Start NWay. */
1774 } else if ((csr12
& 0x7000) != 0x5000) {
1775 /* Negotiation failed. Search media types. */
1776 if (tulip_debug
> 1)
1777 printk(KERN_INFO
"%s: 21142 negotiation failed, status %8.8x.\n",
1779 if (!(csr12
& 4)) { /* 10mbps link beat good. */
1780 new_csr6
= 0x82420000;
1782 outl(0, ioaddr
+ CSR13
);
1783 outl(0x0003FFFF, ioaddr
+ CSR14
);
1784 outl(t21142_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
1785 outl(t21142_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
1786 } else if (csr12
& 0x100) {
1787 new_csr6
= 0x82420200;
1789 outl(0, ioaddr
+ CSR13
);
1790 outl(0x0003FFFF, ioaddr
+ CSR14
);
1791 outl(0x0008, ioaddr
+ CSR15
);
1792 outl(0x0001, ioaddr
+ CSR13
);
1794 /* Select 100mbps port to check for link beat. */
1795 new_csr6
= 0x83860000;
1797 outl(0, ioaddr
+ CSR13
);
1798 outl(0x0003FF7F, ioaddr
+ CSR14
);
1799 outl(8, ioaddr
+ CSR15
);
1800 outl(1, ioaddr
+ CSR13
);
1802 if (tulip_debug
> 1)
1803 printk(KERN_INFO
"%s: Testing new 21142 media %s.\n",
1804 dev
->name
, medianame
[dev
->if_port
]);
1805 if (new_csr6
!= (tp
->csr6
& ~0x00D5)) {
1807 tp
->csr6
|= new_csr6
;
1808 outl(0x0301, ioaddr
+ CSR12
);
1809 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
1810 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1813 tp
->timer
.expires
= RUN_AT(next_tick
);
1814 add_timer(&tp
->timer
);
1817 static void t21142_lnk_change( struct net_device
*dev
)
1819 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1820 long ioaddr
= dev
->base_addr
;
1821 int csr12
= inl(ioaddr
+ CSR12
);
1823 if (tulip_debug
> 1)
1824 printk(KERN_INFO
"%s: 21142 link status interrupt %8.8x, CSR5 %x.\n",
1825 dev
->name
, csr12
, inl(ioaddr
+ CSR5
));
1827 if ((csr12
& 0x7000) == 0x5000) {
1828 if (csr12
& 0x01800000) {
1829 /* Switch to 100mbps mode. */
1830 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
1831 if (csr12
& 0x01000000) {
1833 tp
->csr6
= 0x83860200;
1836 tp
->csr6
= 0x83860000;
1838 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1839 } /* Else 10baseT-FD is handled automatically. */
1840 } else if (dev
->if_port
== 3) {
1842 printk(KERN_INFO
"%s: 21142 100baseTx link beat good.\n",
1846 } else if (dev
->if_port
== 0) {
1848 printk(KERN_INFO
"%s: 21142 10baseT link beat good.\n",
1850 } else if (!(csr12
& 4)) { /* 10mbps link beat good. */
1851 printk(KERN_INFO
"%s: 21142 10mpbs sensed media.\n",
1854 } else { /* 100mbps link beat good. */
1855 printk(KERN_INFO
"%s: 21142 100baseTx sensed media.\n",
1858 tp
->csr6
= 0x83860000;
1859 outl(0x0003FF7F, ioaddr
+ CSR14
);
1860 outl(0x0301, ioaddr
+ CSR12
);
1861 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
1862 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1867 static void mxic_timer(unsigned long data
)
1869 struct net_device
*dev
= (struct net_device
*)data
;
1870 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1871 long ioaddr
= dev
->base_addr
;
1872 int next_tick
= 60*HZ
;
1874 if (tulip_debug
> 3) {
1875 printk(KERN_INFO
"%s: MXIC negotiation status %8.8x.\n", dev
->name
,
1876 inl(ioaddr
+ CSR12
));
1879 tp
->timer
.expires
= RUN_AT(next_tick
);
1880 add_timer(&tp
->timer
);
1884 static void pnic_timer(unsigned long data
)
1886 struct net_device
*dev
= (struct net_device
*)data
;
1887 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1888 long ioaddr
= dev
->base_addr
;
1889 int csr12
= inl(ioaddr
+ CSR12
);
1890 int next_tick
= 60*HZ
;
1891 int new_csr6
= tp
->csr6
& ~0x40C40200;
1893 if (media_cap
[dev
->if_port
] & MediaIsMII
) {
1894 int negotiated
= mdio_read(dev
, tp
->phys
[0], 5) & tp
->advertising
[0];
1896 if (tulip_debug
> 1)
1897 printk(KERN_DEBUG
"%s: LC82C168 negotiated capability %8.8x, "
1899 dev
->name
, negotiated
, inl(ioaddr
+ CSR5
));
1901 if (negotiated
& 0x0380) /* 10 vs 100mbps */
1902 new_csr6
|= 0x812E0000;
1904 new_csr6
|= 0x816E0000;
1905 if (((negotiated
& 0x0300) == 0x0100) /* Duplex */
1906 || (negotiated
& 0x00C0) == 0x0040
1907 || tp
->full_duplex_lock
) {
1908 tp
->full_duplex
= 1;
1911 if (tulip_debug
> 1)
1912 printk(KERN_DEBUG
"%s: LC82C168 MII PHY status %4.4x, Link "
1913 "partner report %4.4x, csr6 %8.8x/%8.8x.\n",
1914 dev
->name
, mdio_read(dev
, tp
->phys
[0], 1), negotiated
,
1915 tp
->csr6
, inl(ioaddr
+ CSR6
));
1917 int phy_reg
= inl(ioaddr
+ 0xB8);
1918 int csr5
= inl(ioaddr
+ CSR5
);
1920 if (tulip_debug
> 1)
1921 printk(KERN_DEBUG
"%s: LC82C168 phy status %8.8x, CSR5 %8.8x.\n",
1922 dev
->name
, phy_reg
, csr5
);
1924 if (phy_reg
& 0x04000000) { /* Remote link fault */
1925 /*outl(0x0201F078, ioaddr + 0xB8);*/
1928 if (inl(ioaddr
+ CSR5
) & TPLnkFail
) { /* 100baseTx link beat */
1929 if (tulip_debug
> 1)
1930 printk(KERN_DEBUG
"%s: %s link beat failed, CSR12 %4.4x, "
1931 "CSR5 %8.8x, PHY %3.3x.\n",
1932 dev
->name
, medianame
[dev
->if_port
], csr12
,
1933 inl(ioaddr
+ CSR5
), inl(ioaddr
+ 0xB8));
1934 if (tp
->medialock
) {
1935 } else if (dev
->if_port
== 0) {
1937 outl(0x33, ioaddr
+ CSR12
);
1938 new_csr6
= 0x01860000;
1939 outl(0x1F868, ioaddr
+ 0xB8);
1942 outl(0x32, ioaddr
+ CSR12
);
1943 new_csr6
= 0x00420000;
1944 outl(0x1F078, ioaddr
+ 0xB8);
1946 new_csr6
|= (tp
->csr6
& 0xfdff);
1949 new_csr6
= tp
->csr6
;
1950 if (tp
->full_duplex_lock
|| (phy_reg
& 0x30000000) != 0) {
1951 tp
->full_duplex
= 1;
1952 new_csr6
|= 0x00000200;
1955 if (tp
->csr6
!= new_csr6
) {
1956 tp
->csr6
= new_csr6
;
1957 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
); /* Restart Tx */
1958 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
1959 dev
->trans_start
= jiffies
;
1960 if (tulip_debug
> 0) /* Gurppp, should be >1 */
1961 printk(KERN_INFO
"%s: Changing PNIC configuration to %s-duplex, "
1963 dev
->name
, tp
->full_duplex
? "full" : "half", new_csr6
);
1965 tp
->timer
.expires
= RUN_AT(next_tick
);
1966 add_timer(&tp
->timer
);
1969 static void tulip_tx_timeout(struct net_device
*dev
)
1971 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
1972 long ioaddr
= dev
->base_addr
;
1974 if (media_cap
[dev
->if_port
] & MediaIsMII
) {
1975 /* Do nothing -- the media monitor should handle this. */
1976 if (tulip_debug
> 1)
1977 printk(KERN_WARNING
"%s: Transmit timeout using MII device.\n",
1979 dev
->trans_start
= jiffies
;
1981 } else if (tp
->chip_id
== DC21040
) {
1982 if (inl(ioaddr
+ CSR12
) & 0x0002) {
1983 printk(KERN_INFO
"%s: transmit timed out, switching to %s media.\n",
1984 dev
->name
, dev
->if_port
? "10baseT" : "AUI");
1986 outl(dev
->if_port
? 0x0000000C : 0x00000004, ioaddr
+ CSR13
);
1988 dev
->trans_start
= jiffies
;
1990 } else if (tp
->chip_id
== DC21041
) {
1991 u32 csr12
= inl(ioaddr
+ CSR12
);
1993 printk(KERN_WARNING
"%s: 21041 transmit timed out, status %8.8x, CSR12 %8.8x,"
1994 " CSR13 %8.8x, CSR14 %8.8x, resetting...\n",
1995 dev
->name
, inl(ioaddr
+ CSR5
), csr12
,
1996 inl(ioaddr
+ CSR13
), inl(ioaddr
+ CSR14
));
1998 if (dev
->if_port
== 1 || dev
->if_port
== 2)
1999 if (csr12
& 0x0004) {
2000 dev
->if_port
= 2 - dev
->if_port
;
2005 select_media(dev
, 0);
2006 tp
->stats
.tx_errors
++;
2007 dev
->trans_start
= jiffies
;
2009 } else if (tp
->chip_id
== DC21140
|| tp
->chip_id
== DC21142
2010 || tp
->chip_id
== MX98713
) {
2011 /* Stop the transmit process. */
2012 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
2013 printk(KERN_WARNING
"%s: 21140 transmit timed out, status %8.8x, "
2014 "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
2015 dev
->name
, inl(ioaddr
+ CSR5
), inl(ioaddr
+ CSR12
),
2016 inl(ioaddr
+ CSR13
), inl(ioaddr
+ CSR14
), inl(ioaddr
+ CSR15
));
2018 if (--tp
->cur_index
< 0) {
2019 /* We start again, but should instead look for default. */
2020 tp
->cur_index
= tp
->mtable
->leafcount
- 1;
2022 select_media(dev
, 0);
2023 printk(KERN_WARNING
"%s: transmit timed out, switching to %s media.\n",
2024 dev
->name
, dev
->if_port
? "100baseTx" : "10baseT");
2026 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
2027 tp
->stats
.tx_errors
++;
2028 dev
->trans_start
= jiffies
;
2031 printk(KERN_WARNING
"%s: transmit timed out, status %8.8x, CSR12 %8.8x,"
2033 dev
->name
, inl(ioaddr
+ CSR5
), inl(ioaddr
+ CSR12
));
2034 #ifdef way_too_many_messages
2035 printk(" Rx ring %8.8x: ", (int)tp
->rx_ring
);
2036 for (i
= 0; i
< RX_RING_SIZE
; i
++)
2037 printk(" %8.8x", (unsigned int)tp
->rx_ring
[i
].status
);
2038 printk("\n Tx ring %8.8x: ", (int)tp
->tx_ring
);
2039 for (i
= 0; i
< TX_RING_SIZE
; i
++)
2040 printk(" %8.8x", (unsigned int)tp
->tx_ring
[i
].status
);
2044 /* Perhaps we should reinitialize the hardware here. */
2046 /* Stop and restart the chip's Tx processes . */
2047 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
2048 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
2049 /* Trigger an immediate transmit demand. */
2050 outl(0, ioaddr
+ CSR1
);
2052 dev
->trans_start
= jiffies
;
2053 tp
->stats
.tx_errors
++;
2058 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
2060 tulip_init_ring(struct net_device
*dev
)
2062 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2066 tp
->cur_rx
= tp
->cur_tx
= 0;
2067 tp
->dirty_rx
= tp
->dirty_tx
= 0;
2069 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
2070 tp
->rx_ring
[i
].status
= 0x80000000; /* Owned by Tulip chip */
2071 tp
->rx_ring
[i
].length
= PKT_BUF_SZ
;
2073 /* Note the receive buffer must be longword aligned.
2074 dev_alloc_skb() provides 16 byte alignment. But do *not*
2075 use skb_reserve() to align the IP header! */
2076 struct sk_buff
*skb
;
2077 skb
= DEV_ALLOC_SKB(PKT_BUF_SZ
);
2078 tp
->rx_skbuff
[i
] = skb
;
2080 break; /* Bad news! */
2081 skb
->dev
= dev
; /* Mark as being used by this device. */
2082 #if LINUX_VERSION_CODE > 0x10300
2083 tp
->rx_ring
[i
].buffer1
= virt_to_bus(skb
->tail
);
2085 tp
->rx_ring
[i
].buffer1
= virt_to_bus(skb
->data
);
2088 tp
->rx_ring
[i
].buffer2
= virt_to_bus(&tp
->rx_ring
[i
+1]);
2090 /* Mark the last entry as wrapping the ring. */
2091 tp
->rx_ring
[i
-1].length
= PKT_BUF_SZ
| 0x02000000;
2092 tp
->rx_ring
[i
-1].buffer2
= virt_to_bus(&tp
->rx_ring
[0]);
2094 /* The Tx buffer descriptor is filled in as needed, but we
2095 do need to clear the ownership bit. */
2096 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
2097 tp
->tx_skbuff
[i
] = 0;
2098 tp
->tx_ring
[i
].status
= 0x00000000;
2099 tp
->tx_ring
[i
].buffer2
= virt_to_bus(&tp
->tx_ring
[i
+1]);
2101 tp
->tx_ring
[i
-1].buffer2
= virt_to_bus(&tp
->tx_ring
[0]);
2105 tulip_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2107 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2111 /* Block a timer-based transmit from overlapping. This could better be
2112 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
2113 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0) {
2114 if (jiffies
- dev
->trans_start
< TX_TIMEOUT
)
2116 tulip_tx_timeout(dev
);
2120 /* Caution: the write order is important here, set the base address
2121 with the "ownership" bits last. */
2123 /* Calculate the next Tx descriptor entry. */
2124 entry
= tp
->cur_tx
% TX_RING_SIZE
;
2126 tp
->tx_skbuff
[entry
] = skb
;
2127 tp
->tx_ring
[entry
].buffer1
= virt_to_bus(skb
->data
);
2129 if (tp
->cur_tx
- tp
->dirty_tx
< TX_RING_SIZE
/2) {/* Typical path */
2130 flag
= 0x60000000; /* No interrupt */
2132 } else if (tp
->cur_tx
- tp
->dirty_tx
== TX_RING_SIZE
/2) {
2133 flag
= 0xe0000000; /* Tx-done intr. */
2135 } else if (tp
->cur_tx
- tp
->dirty_tx
< TX_RING_SIZE
- 2) {
2136 flag
= 0x60000000; /* No Tx-done intr. */
2139 /* Leave room for set_rx_mode() to fill entries. */
2140 flag
= 0xe0000000; /* Tx-done intr. */
2143 if (entry
== TX_RING_SIZE
-1)
2146 tp
->tx_ring
[entry
].length
= skb
->len
| flag
;
2147 tp
->tx_ring
[entry
].status
= 0x80000000; /* Pass ownership to the chip. */
2149 /* Trigger an immediate transmit demand. */
2150 outl(0, dev
->base_addr
+ CSR1
);
2152 dev
->trans_start
= jiffies
;
2157 /* The interrupt handler does all of the Rx thread work and cleans up
2158 after the Tx thread. */
2159 static void tulip_interrupt
IRQ(int irq
, void *dev_instance
, struct pt_regs
*regs
)
2161 #ifdef SA_SHIRQ /* Use the now-standard shared IRQ implementation. */
2162 struct net_device
*dev
= (struct net_device
*)dev_instance
;
2164 struct net_device
*dev
= (struct net_device
*)(irq2dev_map
[irq
]);
2167 struct tulip_private
*tp
;
2169 int csr5
, work_budget
= max_interrupt_work
;
2172 printk (KERN_ERR
" tulip_interrupt(): irq %d for unknown device.\n",
2177 ioaddr
= dev
->base_addr
;
2178 tp
= (struct tulip_private
*)dev
->priv
;
2179 if (test_and_set_bit(0, (void*)&tp
->interrupt
)) {
2181 printk(KERN_ERR
"%s: Re-entering the interrupt handler with proc %d,"
2182 " proc %d already handling.\n", dev
->name
,
2183 tp
->smp_proc_id
, hard_smp_processor_id());
2185 printk(KERN_ERR
"%s: Re-entering the interrupt handler.\n", dev
->name
);
2191 tp
->smp_proc_id
= hard_smp_processor_id();
2195 csr5
= inl(ioaddr
+ CSR5
);
2196 /* Acknowledge all of the current interrupt sources ASAP. */
2197 outl(csr5
& 0x0001ffff, ioaddr
+ CSR5
);
2199 if (tulip_debug
> 4)
2200 printk(KERN_DEBUG
"%s: interrupt csr5=%#8.8x new csr5=%#8.8x.\n",
2201 dev
->name
, csr5
, inl(dev
->base_addr
+ CSR5
));
2203 if ((csr5
& (NormalIntr
|AbnormalIntr
)) == 0)
2206 if (csr5
& (RxIntr
| RxNoBuf
))
2207 work_budget
-= tulip_rx(dev
);
2209 if (csr5
& (TxNoBuf
| TxDied
| TxIntr
)) {
2210 unsigned int dirty_tx
;
2212 for (dirty_tx
= tp
->dirty_tx
; tp
->cur_tx
- dirty_tx
> 0;
2214 int entry
= dirty_tx
% TX_RING_SIZE
;
2215 int status
= tp
->tx_ring
[entry
].status
;
2218 break; /* It still hasn't been Txed */
2219 /* Check for Rx filter setup frames. */
2220 if (tp
->tx_skbuff
[entry
] == NULL
)
2223 if (status
& 0x8000) {
2224 /* There was an major error, log it. */
2225 #ifndef final_version
2226 if (tulip_debug
> 1)
2227 printk(KERN_DEBUG
"%s: Transmit error, Tx status %8.8x.\n",
2230 tp
->stats
.tx_errors
++;
2231 if (status
& 0x4104) tp
->stats
.tx_aborted_errors
++;
2232 if (status
& 0x0C00) tp
->stats
.tx_carrier_errors
++;
2233 if (status
& 0x0200) tp
->stats
.tx_window_errors
++;
2234 if (status
& 0x0002) tp
->stats
.tx_fifo_errors
++;
2235 if ((status
& 0x0080) && tp
->full_duplex
== 0)
2236 tp
->stats
.tx_heartbeat_errors
++;
2238 if (status
& 0x0100) tp
->stats
.collisions16
++;
2242 if (status
& 0x0001) tp
->stats
.tx_deferred
++;
2244 #if LINUX_VERSION_CODE > 0x20127
2245 tp
->stats
.tx_bytes
+= tp
->tx_ring
[entry
].length
& 0x7ff;
2247 tp
->stats
.collisions
+= (status
>> 3) & 15;
2248 tp
->stats
.tx_packets
++;
2251 /* Free the original skb. */
2252 #if (LINUX_VERSION_CODE > 0x20155)
2253 dev_kfree_skb(tp
->tx_skbuff
[entry
]);
2255 dev_kfree_skb(tp
->tx_skbuff
[entry
], FREE_WRITE
);
2257 tp
->tx_skbuff
[entry
] = 0;
2260 #ifndef final_version
2261 if (tp
->cur_tx
- dirty_tx
> TX_RING_SIZE
) {
2262 printk(KERN_ERR
"%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
2263 dev
->name
, dirty_tx
, tp
->cur_tx
, tp
->tx_full
);
2264 dirty_tx
+= TX_RING_SIZE
;
2268 if (tp
->tx_full
&& dev
->tbusy
2269 && tp
->cur_tx
- dirty_tx
< TX_RING_SIZE
- 2) {
2270 /* The ring is no longer full, clear tbusy. */
2276 tp
->dirty_tx
= dirty_tx
;
2277 if (csr5
& TxDied
) {
2278 if (tulip_debug
> 1)
2279 printk(KERN_WARNING
"%s: The transmitter stopped!"
2280 " CSR5 is %x, CSR6 %x.\n",
2281 dev
->name
, csr5
, inl(ioaddr
+ CSR6
));
2282 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
2283 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
2288 if (csr5
& AbnormalIntr
) { /* Abnormal error summary bit. */
2289 if (csr5
& TxJabber
) tp
->stats
.tx_errors
++;
2290 if (csr5
& TxFIFOUnderflow
) {
2291 if ((tp
->csr6
& 0xC000) != 0xC000)
2292 tp
->csr6
+= 0x4000; /* Bump up the Tx threshold */
2294 tp
->csr6
|= 0x00200000; /* Store-n-forward. */
2295 /* Restart the transmit process. */
2296 outl(tp
->csr6
| 0x0002, ioaddr
+ CSR6
);
2297 outl(tp
->csr6
| 0x2002, ioaddr
+ CSR6
);
2299 if (csr5
& RxDied
) { /* Missed a Rx frame. */
2300 tp
->stats
.rx_errors
++;
2301 tp
->stats
.rx_missed_errors
+= inl(ioaddr
+ CSR8
) & 0xffff;
2303 if (csr5
& TimerInt
) {
2304 printk(KERN_ERR
"%s: Something Wicked happened! %8.8x.\n",
2306 /* Hmmmmm, it's not clear what to do here. */
2308 if (csr5
& (TPLnkPass
| TPLnkFail
| 0x08000000)
2309 && tp
->chip_id
== DC21142
) {
2310 if (tulip_debug
> 1)
2311 printk(KERN_INFO
"%s: 21142 link change, CSR5 = %8.8x.\n",
2313 t21142_lnk_change(dev
);
2315 /* Clear all error sources, included undocumented ones! */
2316 outl(0x0800f7ba, ioaddr
+ CSR5
);
2318 if (--work_budget
< 0) {
2319 if (tulip_debug
> 1)
2320 printk(KERN_WARNING
"%s: Too much work at interrupt, "
2321 "csr5=0x%8.8x.\n", dev
->name
, csr5
);
2322 /* Acknowledge all interrupt sources. */
2323 outl(0x8001ffff, ioaddr
+ CSR5
);
2325 /* Clear all but standard interrupt sources. */
2326 outl((~csr5
) & 0x0001ebef, ioaddr
+ CSR7
);
2332 if (tulip_debug
> 3)
2333 printk(KERN_DEBUG
"%s: exiting interrupt, csr5=%#4.4x.\n",
2334 dev
->name
, inl(ioaddr
+ CSR5
));
2337 clear_bit(0, (void*)&tp
->interrupt
);
2342 tulip_rx(struct net_device
*dev
)
2344 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2345 int entry
= tp
->cur_rx
% RX_RING_SIZE
;
2346 int rx_work_limit
= tp
->dirty_rx
+ RX_RING_SIZE
- tp
->cur_rx
;
2349 if (tulip_debug
> 4)
2350 printk(KERN_DEBUG
" In tulip_rx(), entry %d %8.8x.\n", entry
,
2351 tp
->rx_ring
[entry
].status
);
2352 /* If we own the next entry, it's a new packet. Send it up. */
2353 while (tp
->rx_ring
[entry
].status
>= 0) {
2354 s32 status
= tp
->rx_ring
[entry
].status
;
2356 if (--rx_work_limit
< 0)
2358 if ((status
& 0x0300) != 0x0300) {
2359 if ((status
& 0xffff) != 0x7fff) { /* Ingore earlier buffers. */
2360 if (tulip_debug
> 1)
2361 printk(KERN_WARNING
"%s: Oversized Ethernet frame spanned "
2362 "multiple buffers, status %8.8x!\n",
2364 tp
->stats
.rx_length_errors
++;
2366 } else if (status
& 0x8000) {
2367 /* There was a fatal error. */
2368 if (tulip_debug
> 2)
2369 printk(KERN_DEBUG
"%s: Receive error, Rx status %8.8x.\n",
2371 tp
->stats
.rx_errors
++; /* end of a packet.*/
2372 if (status
& 0x0890) tp
->stats
.rx_length_errors
++;
2373 if (status
& 0x0004) tp
->stats
.rx_frame_errors
++;
2374 if (status
& 0x0002) tp
->stats
.rx_crc_errors
++;
2375 if (status
& 0x0001) tp
->stats
.rx_fifo_errors
++;
2377 /* Omit the four octet CRC from the length. */
2378 short pkt_len
= (status
>> 16) - 4;
2379 struct sk_buff
*skb
;
2381 /* Check if the packet is long enough to just accept without
2382 copying to a properly sized skbuff. */
2383 if (pkt_len
< rx_copybreak
2384 && (skb
= DEV_ALLOC_SKB(pkt_len
+2)) != NULL
) {
2386 skb_reserve(skb
, 2); /* 16 byte align the IP header */
2387 #if LINUX_VERSION_CODE < 0x10300
2388 memcpy(skb
->data
, tp
->rx_ring
[entry
].buffer1
, pkt_len
);
2389 #elif LINUX_VERSION_CODE < 0x20200 || defined(__alpha__)
2390 memcpy(skb_put(skb
, pkt_len
),
2391 bus_to_virt(tp
->rx_ring
[entry
].buffer1
), pkt_len
);
2393 eth_copy_and_sum(skb
, bus_to_virt(tp
->rx_ring
[entry
].buffer1
),
2395 skb_put(skb
, pkt_len
);
2398 } else { /* Pass up the skb already on the Rx ring. */
2399 skb
= tp
->rx_skbuff
[entry
];
2400 tp
->rx_skbuff
[entry
] = NULL
;
2401 #ifndef final_version
2403 void *temp
= skb_put(skb
, pkt_len
);
2404 if (bus_to_virt(tp
->rx_ring
[entry
].buffer1
) != temp
)
2405 printk(KERN_ERR
"%s: Internal consistency error! The "
2406 "skbuff addresses do not match in tulip_rx:"
2407 " %p vs. %p / %p.\n", dev
->name
,
2408 bus_to_virt(tp
->rx_ring
[entry
].buffer1
),
2412 skb_put(skb
, pkt_len
);
2415 #if LINUX_VERSION_CODE > 0x10300
2416 skb
->protocol
= eth_type_trans(skb
, dev
);
2421 dev
->last_rx
= jiffies
;
2422 tp
->stats
.rx_packets
++;
2423 #if LINUX_VERSION_CODE > 0x20127
2424 tp
->stats
.rx_bytes
+= pkt_len
;
2427 entry
= (++tp
->cur_rx
) % RX_RING_SIZE
;
2430 /* Refill the Rx ring buffers. */
2431 for (; tp
->cur_rx
- tp
->dirty_rx
> 0; tp
->dirty_rx
++) {
2432 entry
= tp
->dirty_rx
% RX_RING_SIZE
;
2433 if (tp
->rx_skbuff
[entry
] == NULL
) {
2434 struct sk_buff
*skb
;
2435 skb
= tp
->rx_skbuff
[entry
] = DEV_ALLOC_SKB(PKT_BUF_SZ
);
2438 skb
->dev
= dev
; /* Mark as being used by this device. */
2439 #if LINUX_VERSION_CODE > 0x10300
2440 tp
->rx_ring
[entry
].buffer1
= virt_to_bus(skb
->tail
);
2442 tp
->rx_ring
[entry
].buffer1
= virt_to_bus(skb
->data
);
2446 tp
->rx_ring
[entry
].status
= 0x80000000;
2453 tulip_close(struct net_device
*dev
)
2455 long ioaddr
= dev
->base_addr
;
2456 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2462 if (tulip_debug
> 1)
2463 printk(KERN_DEBUG
"%s: Shutting down ethercard, status was %2.2x.\n",
2464 dev
->name
, inl(ioaddr
+ CSR5
));
2466 /* Disable interrupts by clearing the interrupt mask. */
2467 outl(0x00000000, ioaddr
+ CSR7
);
2468 /* Stop the chip's Tx and Rx processes. */
2469 outl(inl(ioaddr
+ CSR6
) & ~0x2002, ioaddr
+ CSR6
);
2470 /* 21040 -- Leave the card in 10baseT state. */
2471 if (tp
->chip_id
== DC21040
)
2472 outl(0x00000004, ioaddr
+ CSR13
);
2474 tp
->stats
.rx_missed_errors
+= inl(ioaddr
+ CSR8
) & 0xffff;
2476 del_timer(&tp
->timer
);
2479 free_irq(dev
->irq
, dev
);
2482 irq2dev_map
[dev
->irq
] = 0;
2485 /* Free all the skbuffs in the Rx queue. */
2486 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
2487 struct sk_buff
*skb
= tp
->rx_skbuff
[i
];
2488 tp
->rx_skbuff
[i
] = 0;
2489 tp
->rx_ring
[i
].status
= 0; /* Not owned by Tulip chip. */
2490 tp
->rx_ring
[i
].length
= 0;
2491 tp
->rx_ring
[i
].buffer1
= 0xBADF00D0; /* An invalid address. */
2493 #if LINUX_VERSION_CODE < 0x20100
2496 #if (LINUX_VERSION_CODE > 0x20155)
2499 dev_kfree_skb(skb
, FREE_WRITE
);
2503 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
2504 if (tp
->tx_skbuff
[i
])
2505 #if (LINUX_VERSION_CODE > 0x20155)
2506 dev_kfree_skb(tp
->tx_skbuff
[i
]);
2508 dev_kfree_skb(tp
->tx_skbuff
[i
], FREE_WRITE
);
2510 tp
->tx_skbuff
[i
] = 0;
2519 static struct enet_statistics
*
2520 tulip_get_stats(struct net_device
*dev
)
2522 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2523 long ioaddr
= dev
->base_addr
;
2526 tp
->stats
.rx_missed_errors
+= inl(ioaddr
+ CSR8
) & 0xffff;
2531 #ifdef HAVE_PRIVATE_IOCTL
2532 /* Provide ioctl() calls to examine the MII xcvr state. */
2533 static int private_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2535 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2536 long ioaddr
= dev
->base_addr
;
2537 u16
*data
= (u16
*)&rq
->ifr_data
;
2538 int phy
= tp
->phys
[0] & 0x1f;
2542 case SIOCDEVPRIVATE
: /* Get the address of the PHY in use. */
2543 if (tp
->mtable
&& tp
->mtable
->has_mii
)
2545 else if (tp
->chip_id
== DC21142
)
2550 case SIOCDEVPRIVATE
+1: /* Read the specified MII register. */
2551 if (data
[0] == 32) { /* 21142 pseudo-MII */
2552 int csr12
= inl(ioaddr
+ CSR12
);
2553 int csr14
= inl(ioaddr
+ CSR14
);
2556 data
[3] = ((csr14
<<13)&0x4000) + ((csr14
<<5)&0x1000);
2559 data
[3] = 0x7848 + ((csr12
&0x7000) == 0x5000 ? 0x20 : 0)
2560 + (csr12
&0x06 ? 0x04 : 0);
2563 int csr14
= inl(ioaddr
+ CSR14
);
2564 data
[3] = ((csr14
>>9)&0x0380) + ((csr14
>>1)&0x20) + 1;
2567 case 5: data
[3] = inl(ioaddr
+ CSR12
) >> 16; break;
2568 default: data
[3] = 0; break;
2573 data
[3] = mdio_read(dev
, data
[0] & 0x1f, data
[1] & 0x1f);
2574 restore_flags(flags
);
2577 case SIOCDEVPRIVATE
+2: /* Write the specified MII register */
2580 if (data
[0] == 32) { /* 21142 pseudo-MII */
2584 mdio_write(dev
, data
[0] & 0x1f, data
[1] & 0x1f, data
[2]);
2585 restore_flags(flags
);
2594 #endif /* HAVE_PRIVATE_IOCTL */
2596 /* Set or clear the multicast filter for this adaptor.
2597 Note that we only use exclusion around actually queueing the
2598 new frame, not around filling tp->setup_frame. This is non-deterministic
2599 when re-entered but still correct. */
2601 /* The little-endian AUTODIN32 ethernet CRC calculation.
2602 N.B. Do not use for bulk data, use a table-based routine instead.
2603 This is common code and should be moved to net/core/crc.c */
2604 static unsigned const ethernet_polynomial_le
= 0xedb88320U
;
2605 static inline unsigned ether_crc_le(int length
, unsigned char *data
)
2607 unsigned int crc
= 0xffffffff; /* Initial value. */
2608 while(--length
>= 0) {
2609 unsigned char current_octet
= *data
++;
2611 for (bit
= 8; --bit
>= 0; current_octet
>>= 1) {
2612 if ((crc
^ current_octet
) & 1) {
2614 crc
^= ethernet_polynomial_le
;
2622 #ifdef NEW_MULTICAST
2623 static void set_rx_mode(struct net_device
*dev
)
2625 static void set_rx_mode(struct net_device
*dev
, int num_addrs
, void *addrs
)
2628 long ioaddr
= dev
->base_addr
;
2629 int csr6
= inl(ioaddr
+ CSR6
) & ~0x00D5;
2630 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
2632 tp
->csr6
&= ~0x00D5;
2633 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
2634 outl(csr6
| 0x00C0, ioaddr
+ CSR6
);
2635 /* Unconditionally log net taps. */
2636 printk(KERN_INFO
"%s: Promiscuous mode enabled.\n", dev
->name
);
2638 } else if ((dev
->mc_count
> 1000) || (dev
->flags
& IFF_ALLMULTI
)) {
2639 /* Too many to filter perfectly -- accept all multicasts. */
2640 outl(csr6
| 0x0080, ioaddr
+ CSR6
);
2643 u32
*setup_frm
= tp
->setup_frame
;
2644 struct dev_mc_list
*mclist
;
2649 if (dev
->mc_count
> 14) { /* Must use a multicast hash table. */
2651 memset(hash_table
, 0, sizeof(hash_table
));
2652 /* This should work on big-endian machines as well. */
2653 for (i
= 0, mclist
= dev
->mc_list
; mclist
&& i
< dev
->mc_count
;
2654 i
++, mclist
= mclist
->next
)
2655 set_bit(ether_crc_le(ETH_ALEN
, mclist
->dmi_addr
) & 0x1ff,
2657 /* Copy the hash table to the setup frame.
2658 NOTE that only the LOW SHORTWORD of setup_frame[] is valid! */
2659 for (i
= 0; i
< 32; i
++)
2660 *setup_frm
++ = hash_table
[i
];
2662 tx_flags
= 0x08400000 | 192;
2663 /* Too clever: i > 15 for fall-though. */
2665 /* We have <= 15 addresses so we can use the wonderful
2666 16 address perfect filtering of the Tulip. */
2667 for (i
= 0, mclist
= dev
->mc_list
; i
< dev
->mc_count
;
2668 i
++, mclist
= mclist
->next
) {
2669 /* Note that only the low shortword of setup_frame[] is valid!
2670 This code may require tweaking for non-x86 architectures! */
2671 eaddrs
= (u16
*)mclist
->dmi_addr
;
2672 *setup_frm
++ = *eaddrs
++;
2673 *setup_frm
++ = *eaddrs
++;
2674 *setup_frm
++ = *eaddrs
++;
2676 /* Fill the rest of the table with our physical address.
2677 Once again, only the low shortword or setup_frame[] is valid! */
2678 *setup_frm
++ = 0xffff;
2679 *setup_frm
++ = 0xffff;
2680 *setup_frm
++ = 0xffff;
2681 tx_flags
= 0x08000000 | 192;
2683 eaddrs
= (u16
*)dev
->dev_addr
;
2685 *setup_frm
++ = eaddrs
[0];
2686 *setup_frm
++ = eaddrs
[1];
2687 *setup_frm
++ = eaddrs
[2];
2689 /* Now add this frame to the Tx list. */
2690 if (tp
->cur_tx
- tp
->dirty_tx
> TX_RING_SIZE
- 2) {
2691 /* Same setup recently queued, we need not add it. */
2693 unsigned long flags
;
2694 unsigned int entry
, dummy
= 0;
2696 save_flags(flags
); cli();
2697 entry
= tp
->cur_tx
++ % TX_RING_SIZE
;
2700 /* Avoid a chip errata by prefixing a dummy entry. */
2701 tp
->tx_skbuff
[entry
] = 0;
2702 tp
->tx_ring
[entry
].length
=
2703 (entry
== TX_RING_SIZE
-1) ? 0x02000000 : 0;
2704 tp
->tx_ring
[entry
].buffer1
= 0;
2705 /* race with chip, set DescOwned later */
2707 entry
= tp
->cur_tx
++ % TX_RING_SIZE
;
2710 tp
->tx_skbuff
[entry
] = 0;
2711 /* Put the setup frame on the Tx list. */
2712 if (entry
== TX_RING_SIZE
-1)
2713 tx_flags
|= 0x02000000; /* Wrap ring. */
2714 tp
->tx_ring
[entry
].length
= tx_flags
;
2715 tp
->tx_ring
[entry
].buffer1
= virt_to_bus(tp
->setup_frame
);
2716 tp
->tx_ring
[entry
].status
= 0x80000000;
2717 if (tp
->cur_tx
- tp
->dirty_tx
>= TX_RING_SIZE
- 2) {
2722 tp
->tx_ring
[dummy
].status
= DescOwned
;
2723 restore_flags(flags
);
2724 /* Trigger an immediate transmit demand. */
2725 outl(0, ioaddr
+ CSR1
);
2727 outl(csr6
| 0x0000, ioaddr
+ CSR6
);
2733 #include <pcmcia/driver_ops.h>
2735 static dev_node_t
*tulip_attach(dev_locator_t
*loc
)
2740 struct net_device
*dev
;
2742 if (loc
->bus
!= LOC_PCI
) return NULL
;
2743 bus
= loc
->b
.pci
.bus
; devfn
= loc
->b
.pci
.devfn
;
2744 printk(KERN_INFO
"tulip_attach(bus %d, function %d)\n", bus
, devfn
);
2745 pcibios_read_config_dword(bus
, devfn
, PCI_BASE_ADDRESS_0
, &io
);
2746 pcibios_read_config_word(bus
, devfn
, PCI_DEVICE_ID
, &dev_id
);
2748 dev
= tulip_probe1(bus
, devfn
, NULL
, DC21142
, -1);
2750 dev_node_t
*node
= kmalloc(sizeof(dev_node_t
), GFP_KERNEL
);
2751 strcpy(node
->dev_name
, dev
->name
);
2752 node
->major
= node
->minor
= 0;
2760 static void tulip_detach(dev_node_t
*node
)
2762 struct net_device
**devp
, **next
;
2763 printk(KERN_INFO
"tulip_detach(%s)\n", node
->dev_name
);
2764 for (devp
= &root_tulip_dev
; *devp
; devp
= next
) {
2765 next
= &((struct tulip_private
*)(*devp
)->priv
)->next_module
;
2766 if (strcmp((*devp
)->name
, node
->dev_name
) == 0) break;
2769 unregister_netdev(*devp
);
2777 struct driver_operations tulip_ops
= {
2778 "tulip_cb", tulip_attach
, NULL
, NULL
, tulip_detach
2781 #endif /* Cardbus support */
2785 #if LINUX_VERSION_CODE > 0x20118
2786 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
2787 MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
2788 MODULE_PARM(debug
, "i");
2789 MODULE_PARM(max_interrupt_work
, "i");
2790 MODULE_PARM(reverse_probe
, "i");
2791 MODULE_PARM(rx_copybreak
, "i");
2792 MODULE_PARM(options
, "1-" __MODULE_STRING(MAX_UNITS
) "i");
2793 MODULE_PARM(full_duplex
, "1-" __MODULE_STRING(MAX_UNITS
) "i");
2796 /* An additional parameter that may be passed in... */
2797 static int debug
= -1;
2803 tulip_debug
= debug
;
2806 register_driver(&tulip_ops
);
2809 return tulip_probe(NULL
);
2814 cleanup_module(void)
2816 struct net_device
*next_dev
;
2819 unregister_driver(&tulip_ops
);
2822 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
2823 while (root_tulip_dev
) {
2824 next_dev
= ((struct tulip_private
*)root_tulip_dev
->priv
)->next_module
;
2825 unregister_netdev(root_tulip_dev
);
2826 release_region(root_tulip_dev
->base_addr
, TULIP_TOTAL_SIZE
);
2827 kfree(root_tulip_dev
);
2828 root_tulip_dev
= next_dev
;
2836 * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
2837 * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"