2.2.0-final
[davej-history.git] / drivers / net / tulip.c
blob555776826cad644d8219e2de9e216b7b29f973ab
1 /* tulip.c: A DEC 21040-family ethernet driver for Linux. */
2 /*
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
10 PNIC and MXIC chips.
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
20 #define SMP_CHECK
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;
28 #define MAX_UNITS 8
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;
45 #else
46 static int reverse_probe = 0;
47 #endif
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. */
57 #ifdef __alpha__
58 static int rx_copybreak = 1518;
59 #else
60 static int rx_copybreak = 100;
61 #endif
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>
81 #include <asm/io.h>
82 #include <asm/dma.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)
101 #endif
103 #if (LINUX_VERSION_CODE >= 0x10344)
104 #define NEW_MULTICAST
105 #include <linux/delay.h>
106 #endif
107 #ifdef SA_SHIRQ
108 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
109 #else
110 #define IRQ(irq, dev_id, pt_regs) (irq, pt_regs)
111 #endif
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)
116 #endif
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>
122 #endif
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
128 #ifdef HAVE_DEVLIST
129 struct netdev_entry tulip_drv =
130 {"Tulip", tulip_pci_probe, TULIP_TOTAL_SIZE, NULL};
131 #endif
133 #ifdef TULIP_DEBUG
134 int tulip_debug = TULIP_DEBUG;
135 #else
136 int tulip_debug = 1;
137 #endif
140 Theory of Operation
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
156 interrupt lines.
158 III. Driver operation
160 IIIa. Ring buffers
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
170 skbuff.
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
182 cache.
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.
202 IV. Notes
204 Thanks to Duke Kamstra of SMC for providing an EtherPower board.
206 IVb. References
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
212 IVc. Errata
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. */
236 #endif
238 #ifndef PCI_DEVICE_ID_DEC_TULIP_PLUS
239 #define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014 /* 21041. */
240 #endif
241 #ifndef PCI_DEVICE_ID_DEC_TULIP_21142
242 #define PCI_DEVICE_ID_DEC_TULIP_21142 0x0019
243 #endif
245 #ifndef PCI_VENDOR_ID_LITEON
246 #define PCI_VENDOR_ID_LITEON 0x11AD
247 #endif
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
254 #endif
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;
267 char *chip_name;
268 int io_size;
269 int valid_intrs; /* CSR7 interrupt enable settings */
270 int flags;
271 void (*media_timer)(unsigned long data);
272 } tulip_tbl[] = {
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,
280 tulip_timer },
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 },
295 {0, 0, 0, 0},
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,
303 MediaIs100=16};
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. */
317 enum tulip_offsets {
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. */
323 enum status_bits {
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 /* The Tulip Rx and Tx buffer descriptors. */
331 struct tulip_rx_desc {
332 s32 status;
333 s32 length;
334 u32 buffer1, buffer2;
337 struct tulip_tx_desc {
338 s32 status;
339 s32 length;
340 u32 buffer1, buffer2; /* We use only buffer 1. */
343 struct medialeaf {
344 u8 type;
345 u8 media;
346 unsigned char *leafdata;
349 struct mediatable {
350 u16 defaultmedia;
351 u8 leafcount, csr12dir; /* General purpose pin directions. */
352 unsigned has_mii:1, has_nonmii:1;
353 struct medialeaf mleaf[0];
356 struct mediainfo {
357 struct mediainfo *next;
358 int info_type;
359 int index;
360 unsigned char *info;
363 struct tulip_private {
364 char devname[8]; /* Used only for kernel debugging. */
365 const char *product_name;
366 struct device *next_module;
367 struct tulip_rx_desc rx_ring[RX_RING_SIZE];
368 struct tulip_tx_desc tx_ring[TX_RING_SIZE];
369 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
370 struct sk_buff* tx_skbuff[TX_RING_SIZE];
371 /* The addresses of receive-in-place skbuffs. */
372 struct sk_buff* rx_skbuff[RX_RING_SIZE];
373 char *rx_buffs; /* Address of temporary Rx buffers. */
374 u32 setup_frame[48]; /* Pseudo-Tx frame to init address table. */
375 int chip_id;
376 int revision;
377 #if LINUX_VERSION_CODE > 0x20139
378 struct net_device_stats stats;
379 #else
380 struct enet_statistics stats;
381 #endif
382 struct timer_list timer; /* Media selection timer. */
383 int interrupt; /* In-interrupt flag. */
384 #ifdef SMP_CHECK
385 int smp_proc_id; /* Which processor in IRQ handler. */
386 #endif
387 unsigned int cur_rx, cur_tx; /* The next free ring entry */
388 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
389 unsigned int tx_full:1; /* The Tx queue is full. */
390 unsigned int full_duplex:1; /* Full-duplex operation requested. */
391 unsigned int full_duplex_lock:1;
392 unsigned int fake_addr:1; /* Multiport board faked address. */
393 unsigned int default_port:4; /* Last dev->if_port value. */
394 unsigned int media2:4; /* Secondary monitored media port. */
395 unsigned int medialock:1; /* Don't sense media type. */
396 unsigned int mediasense:1; /* Media sensing in progress. */
397 unsigned int csr6; /* Current CSR6 control settings. */
398 unsigned char eeprom[128]; /* Serial EEPROM contents. */
399 u16 to_advertise; /* NWay capabilities advertised. */
400 u16 advertising[4];
401 signed char phys[4], mii_cnt; /* MII device addresses. */
402 struct mediatable *mtable;
403 int cur_index; /* Current media index. */
404 unsigned char pci_bus, pci_dev_fn;
405 int pad0, pad1; /* Used for 8-byte alignment */
408 static struct device *tulip_probe1(int pci_bus, int pci_devfn,
409 struct device *dev,
410 int chip_id, int options);
411 static void parse_eeprom(struct device *dev);
412 static int read_eeprom(long ioaddr, int location);
413 static int mdio_read(struct device *dev, int phy_id, int location);
414 static void mdio_write(struct device *dev, int phy_id, int location, int value);
415 static void select_media(struct device *dev, int startup);
416 static int tulip_open(struct device *dev);
417 static void tulip_timer(unsigned long data);
418 static void tulip_tx_timeout(struct device *dev);
419 static void tulip_init_ring(struct device *dev);
420 static int tulip_start_xmit(struct sk_buff *skb, struct device *dev);
421 static int tulip_rx(struct device *dev);
422 static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs);
423 static int tulip_close(struct device *dev);
424 static struct enet_statistics *tulip_get_stats(struct device *dev);
425 #ifdef HAVE_PRIVATE_IOCTL
426 static int private_ioctl(struct device *dev, struct ifreq *rq, int cmd);
427 #endif
428 #ifdef NEW_MULTICAST
429 static void set_rx_mode(struct device *dev);
430 #else
431 static void set_rx_mode(struct device *dev, int num_addrs, void *addrs);
432 #endif
436 /* A list of all installed Tulip devices, for removing the driver module. */
437 static struct device *root_tulip_dev = NULL;
439 /* This 21040 probe no longer uses a large fixed contiguous Rx buffer region,
440 but now receives directly into full-sized skbuffs that are allocated
441 at open() time.
442 This allows the probe routine to use the old driver initialization
443 interface. */
445 int tulip_probe(struct device *dev)
447 int cards_found = 0;
448 static int pci_index = 0; /* Static, for multiple probe calls. */
449 unsigned char pci_bus, pci_device_fn;
451 /* Ideally we would detect all network cards in slot order. That would
452 be best done a central PCI probe dispatch, which wouldn't work
453 well with the current structure. So instead we detect just the
454 Tulip cards in slot order. */
456 #if LINUX_VERSION_CODE >= 0x20155
457 if (! pci_present())
458 return -ENODEV;
459 #else
460 if (! pcibios_present())
461 return -ENODEV;
462 #endif
463 for (;pci_index < 0xff; pci_index++) {
464 u16 vendor, device, pci_command, new_command;
465 unsigned long pci_ioaddr = 0;
466 int chip_idx = 0;
468 if (pcibios_find_class
469 (PCI_CLASS_NETWORK_ETHERNET << 8,
470 reverse_probe ? 0xfe - pci_index : pci_index,
471 &pci_bus, &pci_device_fn) != PCIBIOS_SUCCESSFUL)
472 if (reverse_probe)
473 continue;
474 else
475 break;
476 pcibios_read_config_word(pci_bus, pci_device_fn,
477 PCI_VENDOR_ID, &vendor);
478 pcibios_read_config_word(pci_bus, pci_device_fn,
479 PCI_DEVICE_ID, &device);
481 for (chip_idx = 0; tulip_tbl[chip_idx].chip_name; chip_idx++)
482 if (vendor == tulip_tbl[chip_idx].vendor_id &&
483 device == tulip_tbl[chip_idx].device_id)
484 break;
485 if (tulip_tbl[chip_idx].chip_name == 0) {
486 if (vendor == PCI_VENDOR_ID_DEC ||
487 vendor == PCI_VENDOR_ID_LITEON)
488 printk(KERN_INFO "Unknown Tulip-style PCI ethernet chip type"
489 " %4.4x %4.4x"" detected: not configured.\n",
490 vendor, device);
491 continue;
493 #if LINUX_VERSION_CODE >= 0x20155
494 pci_ioaddr = pci_find_slot(pci_bus, pci_device_fn)->base_address[0];
495 #else
496 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_0,
497 &pci_ioaddr);
498 #endif
499 /* Remove I/O space marker in bit 0. */
500 pci_ioaddr &= ~3;
502 if (tulip_debug > 2)
503 printk(KERN_DEBUG "Found %s at I/O %#lx.\n",
504 tulip_tbl[chip_idx].chip_name, pci_ioaddr);
506 if (check_region(pci_ioaddr, tulip_tbl[chip_idx].io_size))
507 continue;
509 pcibios_read_config_word(pci_bus, pci_device_fn,
510 PCI_COMMAND, &pci_command);
511 new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
512 if (pci_command != new_command) {
513 printk(KERN_INFO " The PCI BIOS has not enabled this"
514 " device! Updating PCI command %4.4x->%4.4x.\n",
515 pci_command, new_command);
516 pcibios_write_config_word(pci_bus, pci_device_fn,
517 PCI_COMMAND, new_command);
520 dev = tulip_probe1(pci_bus, pci_device_fn, dev, chip_idx, cards_found);
522 /* Get and check the bus-master and latency values. */
523 if (dev) {
524 unsigned char pci_latency;
525 pcibios_read_config_byte(pci_bus, pci_device_fn,
526 PCI_LATENCY_TIMER, &pci_latency);
527 if (pci_latency < 10) {
528 printk(KERN_INFO " PCI latency timer (CFLT) is "
529 "unreasonably low at %d. Setting to 64 clocks.\n",
530 pci_latency);
531 pcibios_write_config_byte(pci_bus, pci_device_fn,
532 PCI_LATENCY_TIMER, 64);
533 } else if (tulip_debug > 1)
534 printk(KERN_INFO " PCI latency timer (CFLT) is %#x, "
535 " PCI command is %4.4x.\n",
536 pci_latency, new_command);
537 /* Bring the 21143 out power-down mode. */
538 if (device == PCI_DEVICE_ID_DEC_TULIP_21142)
539 pcibios_write_config_dword(pci_bus, pci_device_fn,
540 0x40, 0x40000000);
541 dev = 0;
542 cards_found++;
546 return cards_found ? 0 : -ENODEV;
549 static struct device *tulip_probe1(int pci_bus, int pci_device_fn,
550 struct device *dev,
551 int chip_id, int board_idx)
553 static int did_version = 0; /* Already printed version info. */
554 struct tulip_private *tp;
555 long ioaddr;
556 int irq;
557 /* See note below on the multiport cards. */
558 static unsigned char last_phys_addr[6] = {0x00, 'L', 'i', 'n', 'u', 'x'};
559 static int last_irq = 0;
560 static int multiport_cnt = 0; /* For four-port boards w/one EEPROM */
561 int i;
562 unsigned short sum;
564 if (tulip_debug > 0 && did_version++ == 0)
565 printk(KERN_INFO "%s", version);
567 dev = init_etherdev(dev, 0);
569 #if LINUX_VERSION_CODE >= 0x20155
570 irq = pci_find_slot(pci_bus, pci_device_fn)->irq;
571 ioaddr = pci_find_slot(pci_bus, pci_device_fn)->base_address[0];
572 #else
574 u8 pci_irq_line;
575 u32 pci_ioaddr;
576 pcibios_read_config_byte(pci_bus, pci_device_fn,
577 PCI_INTERRUPT_LINE, &pci_irq_line);
578 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_0,
579 &pci_ioaddr);
580 irq = pci_irq_line;
581 ioaddr = pci_ioaddr;
583 #endif
584 /* Remove I/O space marker in bit 0. */
585 ioaddr &= ~3;
587 printk(KERN_INFO "%s: %s at %#3lx,",
588 dev->name, tulip_tbl[chip_id].chip_name, ioaddr);
590 /* Stop the chip's Tx and Rx processes. */
591 outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
592 /* Clear the missed-packet counter. */
593 (volatile int)inl(ioaddr + CSR8);
595 if (chip_id == DC21041) {
596 if (inl(ioaddr + CSR9) & 0x8000) {
597 printk(" 21040 compatible mode,");
598 chip_id = DC21040;
599 } else {
600 printk(" 21041 mode,");
604 /* The station address ROM is read byte serially. The register must
605 be polled, waiting for the value to be read bit serially from the
606 EEPROM.
608 sum = 0;
609 if (chip_id == DC21040) {
610 outl(0, ioaddr + CSR9); /* Reset the pointer with a dummy write. */
611 for (i = 0; i < 6; i++) {
612 int value, boguscnt = 100000;
614 value = inl(ioaddr + CSR9);
615 while (value < 0 && --boguscnt > 0);
616 dev->dev_addr[i] = value;
617 sum += value & 0xff;
619 } else if (chip_id == LC82C168) {
620 for (i = 0; i < 3; i++) {
621 int value, boguscnt = 100000;
622 outl(0x600 | i, ioaddr + 0x98);
624 value = inl(ioaddr + CSR9);
625 while (value < 0 && --boguscnt > 0);
626 ((u16*)dev->dev_addr)[i] = value;
627 sum += value & 0xffff;
629 } else { /* Must be a new chip, with a serial EEPROM interface. */
630 /* We read the whole EEPROM, and sort it out later. DEC has a
631 specification _Digital Semiconductor 21X4 Serial ROM Format_
632 but early vendor boards just put the address in the first six
633 EEPROM locations. */
634 unsigned char ee_data[128];
635 int sa_offset = 0;
637 for (i = 0; i < sizeof(ee_data)/2; i++)
638 ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i);
640 /* Detect the simple EEPROM format by the duplicated station addr. */
641 for (i = 0; i < 8; i ++)
642 if (ee_data[i] != ee_data[16+i])
643 sa_offset = 20;
644 if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) {
645 sa_offset = 2; /* Grrr, damn Matrox boards. */
646 multiport_cnt = 4;
648 for (i = 0; i < 6; i ++) {
649 dev->dev_addr[i] = ee_data[i + sa_offset];
650 sum += ee_data[i + sa_offset];
653 /* Lite-On boards have the address byte-swapped. */
654 if (dev->dev_addr[0] == 0xA0 && dev->dev_addr[1] == 0x00)
655 for (i = 0; i < 6; i+=2) {
656 char tmp = dev->dev_addr[i];
657 dev->dev_addr[i] = dev->dev_addr[i+1];
658 dev->dev_addr[i+1] = tmp;
660 /* On the Zynx 315 Etherarray and other multiport boards only the
661 first Tulip has an EEPROM.
662 The addresses of the subsequent ports are derived from the first.
663 Many PCI BIOSes also incorrectly report the IRQ line, so we correct
664 that here as well. */
665 if (sum == 0 || sum == 6*0xff) {
666 printk(" EEPROM not present,");
667 for (i = 0; i < 5; i++)
668 dev->dev_addr[i] = last_phys_addr[i];
669 dev->dev_addr[i] = last_phys_addr[i] + 1;
670 #if defined(__i386__) /* This BIOS bug doesn't exist on Alphas. */
671 irq = last_irq;
672 #endif
675 for (i = 0; i < 6; i++)
676 printk(" %2.2x", last_phys_addr[i] = dev->dev_addr[i]);
677 printk(", IRQ %d.\n", irq);
678 last_irq = irq;
680 /* We do a request_region() only to register /proc/ioports info. */
681 /* Note that proper size is tulip_tbl[chip_id].chip_name, but... */
682 request_region(ioaddr, TULIP_TOTAL_SIZE, dev->name);
684 dev->base_addr = ioaddr;
685 dev->irq = irq;
687 /* Make certain the data structures are quadword aligned. */
688 tp = (void *)(((long)kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA) + 7) & ~7);
689 memset(tp, 0, sizeof(*tp));
690 dev->priv = tp;
692 tp->next_module = root_tulip_dev;
693 root_tulip_dev = dev;
695 tp->pci_bus = pci_bus;
696 tp->pci_dev_fn = pci_device_fn;
697 tp->chip_id = chip_id;
699 #ifdef TULIP_FULL_DUPLEX
700 tp->full_duplex = 1;
701 tp->full_duplex_lock = 1;
702 #endif
703 #ifdef TULIP_DEFAULT_MEDIA
704 tp->default_port = TULIP_DEFAULT_MEDIA;
705 #endif
706 #ifdef TULIP_NO_MEDIA_SWITCH
707 tp->medialock = 1;
708 #endif
710 /* The lower four bits are the media type. */
711 if (board_idx >= 0 && board_idx < MAX_UNITS) {
712 tp->default_port = options[board_idx] & 15;
713 if ((options[board_idx] & 0x90) || full_duplex[board_idx] > 0)
714 tp->full_duplex = 1;
715 if (mtu[board_idx] > 0)
716 dev->mtu = mtu[board_idx];
718 if (dev->mem_start)
719 tp->default_port = dev->mem_start;
720 if (tp->default_port) {
721 tp->medialock = 1;
722 if (media_cap[tp->default_port] & MediaAlwaysFD)
723 tp->full_duplex = 1;
725 if (tp->full_duplex)
726 tp->full_duplex_lock = 1;
728 /* This is logically part of probe1(), but too complex to write inline. */
729 if (tulip_tbl[chip_id].flags & HAS_MEDIA_TABLE)
730 parse_eeprom(dev);
732 if (media_cap[tp->default_port] & MediaIsMII) {
733 u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
734 tp->to_advertise = media2advert[tp->default_port - 9];
735 } else
736 tp->to_advertise = 0x03e1;
738 if ((tp->mtable && tp->mtable->has_mii) ||
739 ( ! tp->mtable && (tulip_tbl[tp->chip_id].flags & HAS_MII))) {
740 int phy, phy_idx;
741 /* Find the connected MII xcvrs.
742 Doing this in open() would allow detecting external xcvrs later,
743 but takes much time. */
744 for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys);
745 phy++) {
746 int mii_status = mdio_read(dev, phy, 1);
747 if (mii_status != 0xffff && mii_status != 0x0000) {
748 int mii_reg0 = mdio_read(dev, phy, 0);
749 int reg4 = ((mii_status>>6) & tp->to_advertise) | 1;
750 tp->phys[phy_idx] = phy;
751 tp->advertising[phy_idx++] = reg4;
752 printk(KERN_INFO "%s: MII transceiver found at MDIO address "
753 "%d, config %4.4x status %4.4x.\n",
754 dev->name, phy, mii_reg0, mii_status);
755 if (1 || (media_cap[tp->default_port] & MediaIsMII)) {
756 printk(KERN_DEBUG "%s: Advertising %4.4x on PHY %d,"
757 " previously advertising %4.4x.\n",
758 dev->name, reg4, phy, mdio_read(dev, phy, 4));
759 mdio_write(dev, phy, 4, reg4);
761 /* Enable autonegotiation: some boards default to off. */
762 mdio_write(dev, phy, 0, mii_reg0 |
763 (tp->full_duplex ? 0x1100 : 0x1000) |
764 (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0));
767 tp->mii_cnt = phy_idx;
768 if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) {
769 printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n",
770 dev->name);
771 tp->phys[0] = 1;
775 /* The Tulip-specific entries in the device structure. */
776 dev->open = &tulip_open;
777 dev->hard_start_xmit = &tulip_start_xmit;
778 dev->stop = &tulip_close;
779 dev->get_stats = &tulip_get_stats;
780 #ifdef HAVE_PRIVATE_IOCTL
781 dev->do_ioctl = &private_ioctl;
782 #endif
783 #ifdef HAVE_MULTICAST
784 dev->set_multicast_list = &set_rx_mode;
785 #endif
787 /* Reset the xcvr interface and turn on heartbeat. */
788 switch (chip_id) {
789 case DC21041:
790 outl(0x00000000, ioaddr + CSR13);
791 outl(0xFFFFFFFF, ioaddr + CSR14);
792 outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */
793 outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6);
794 outl(0x0000EF05, ioaddr + CSR13);
795 break;
796 case DC21040:
797 outl(0x00000000, ioaddr + CSR13);
798 outl(0x00000004, ioaddr + CSR13);
799 break;
800 case DC21140: default:
801 if (tp->mtable)
802 outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
803 break;
804 case DC21142:
805 outl(0x82420200, ioaddr + CSR6);
806 outl(0x0001, ioaddr + CSR13);
807 outl(0x0003FFFF, ioaddr + CSR14);
808 outl(0x0008, ioaddr + CSR15);
809 outl(0x0001, ioaddr + CSR13);
810 outl(0x1301, ioaddr + CSR12); /* Start NWay. */
811 break;
812 case LC82C168:
813 if ( ! tp->mii_cnt) {
814 outl(0x00420000, ioaddr + CSR6);
815 outl(0x30, ioaddr + CSR12);
816 outl(0x0001F078, ioaddr + 0xB8);
817 outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */
819 break;
820 case MX98713: case MX98715: case MX98725:
821 outl(0x00000000, ioaddr + CSR6);
822 outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
823 outl(0x00000001, ioaddr + CSR13);
824 break;
827 return dev;
830 /* Serial EEPROM section. */
831 /* The main routine to parse the very complicated SROM structure.
832 Search www.digital.com for "21X4 SROM" to get details.
833 This code is very complex, and will require changes to support
834 additional cards, so I'll be verbose about what is going on.
837 /* Known cards that have old-style EEPROMs. */
838 static struct fixups {
839 char *name;
840 unsigned char addr0, addr1, addr2;
841 u16 newtable[32]; /* Max length below. */
842 } eeprom_fixups[] = {
843 {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
844 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
845 {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x021f,
846 0x0000, 0x009E, /* 10baseT */
847 0x0903, 0x006D, /* 100baseTx */ }},
848 {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x033f,
849 0x0107, 0x8021, /* 100baseFx */
850 0x0108, 0x8021, /* 100baseFx-FD */
851 0x0103, 0x006D, /* 100baseTx */ }},
852 {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0313,
853 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
854 0x0000, 0x009E, /* 10baseT */
855 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ }},
856 {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x031F,
857 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
858 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
859 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
861 {0, 0, 0, 0, {}}};
863 static const char * block_name[] = {"21140 non-MII", "21140 MII PHY",
864 "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"};
866 #define EEPROM_SIZE 128
867 #if defined(__i386__)
868 #define get_u16(ptr) (*(u16 *)(ptr))
869 #else
870 #define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8))
871 #endif
873 static void parse_eeprom(struct device *dev)
875 /* The last media info list parsed, for multiport boards. */
876 static struct mediatable *last_mediatable = NULL;
877 static unsigned char *last_ee_data = NULL;
878 static int controller_index = 0;
879 struct tulip_private *tp = (struct tulip_private *)dev->priv;
880 long ioaddr = dev->base_addr;
881 unsigned char *ee_data = tp->eeprom;
882 int i;
884 tp->mtable = 0;
885 for (i = 0; i < EEPROM_SIZE/2; i++)
886 ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i);
888 /* Detect an old-style (SA only) EEPROM layout:
889 memcmp(eedata, eedata+16, 8). */
890 for (i = 0; i < 8; i ++)
891 if (ee_data[i] != ee_data[16+i])
892 break;
893 if (i >= 8) {
894 if (ee_data[0] == 0xff) {
895 if (last_mediatable) {
896 controller_index++;
897 printk(KERN_INFO "%s: Controller %d of multiport board.\n",
898 dev->name, controller_index);
899 tp->mtable = last_mediatable;
900 ee_data = last_ee_data;
901 goto subsequent_board;
902 } else
903 printk(KERN_INFO "%s: Missing EEPROM, this interface may "
904 "not work correctly!\n",
905 dev->name);
906 return;
908 /* Do a fix-up based on the vendor half of the station address prefix. */
909 for (i = 0; eeprom_fixups[i].name; i++) {
910 if (dev->dev_addr[0] == eeprom_fixups[i].addr0
911 && dev->dev_addr[1] == eeprom_fixups[i].addr1
912 && dev->dev_addr[2] == eeprom_fixups[i].addr2) {
913 if (dev->dev_addr[2] == 0xE8 && ee_data[0x1a] == 0x55)
914 i++; /* An Accton EN1207, not an outlaw Maxtech. */
915 memcpy(ee_data + 26, eeprom_fixups[i].newtable,
916 sizeof(eeprom_fixups[i].newtable));
917 printk(KERN_INFO "%s: Old format EEPROM on '%s' board. Using"
918 " substitute media control info.\n",
919 dev->name, eeprom_fixups[i].name);
920 break;
923 if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
924 printk(KERN_INFO "%s: Old style EEPROM -- no media selection information.\n",
925 dev->name);
926 return;
929 if (tulip_debug > 1) {
930 printk(KERN_DEBUG "read_eeprom:");
931 for (i = 0; i < 64; i++) {
932 printk("%s%4.4x", (i & 7) == 0 ? "\n" KERN_DEBUG : " ",
933 read_eeprom(ioaddr, i));
935 printk("\n");
938 controller_index = 0;
939 if (ee_data[19] > 1) { /* Multiport board. */
940 last_ee_data = ee_data;
942 subsequent_board:
944 if (ee_data[27] == 0) { /* No valid media table. */
945 } else if (tp->chip_id == DC21041) {
946 unsigned char *p = (void *)ee_data + ee_data[27 + controller_index*3];
947 short media;
948 int count;
950 media = get_u16(p);
951 p += 2;
952 count = *p++;
954 printk(KERN_INFO "%s:21041 Media information at %d, default media "
955 "%4.4x (%s).\n", dev->name, ee_data[27], media,
956 media & 0x0800 ? "Autosense" : medianame[media & 15]);
957 for (i = 0; i < count; i++) {
958 unsigned char media_code = *p++;
959 u16 csrvals[3];
960 int idx;
961 for (idx = 0; idx < 3; idx++) {
962 csrvals[idx] = get_u16(p);
963 p += 2;
965 if (media_code & 0x40) {
966 printk(KERN_INFO "%s: 21041 media %2.2x (%s),"
967 " csr13 %4.4x csr14 %4.4x csr15 %4.4x.\n",
968 dev->name, media_code & 15, medianame[media_code & 15],
969 csrvals[0], csrvals[1], csrvals[2]);
970 } else
971 printk(KERN_INFO "%s: 21041 media #%d, %s.\n",
972 dev->name, media_code & 15, medianame[media_code & 15]);
974 } else {
975 unsigned char *p = (void *)ee_data + ee_data[27];
976 unsigned char csr12dir = 0;
977 int count;
978 struct mediatable *mtable;
979 u16 media = get_u16(p);
981 p += 2;
982 if (tulip_tbl[tp->chip_id].flags & CSR12_IN_SROM)
983 csr12dir = *p++;
984 count = *p++;
985 mtable = (struct mediatable *)
986 kmalloc(sizeof(struct mediatable) + count*sizeof(struct medialeaf),
987 GFP_KERNEL);
988 if (mtable == NULL)
989 return; /* Horrible, impossible failure. */
990 last_mediatable = tp->mtable = mtable;
991 mtable->defaultmedia = media;
992 mtable->leafcount = count;
993 mtable->csr12dir = csr12dir;
994 mtable->has_nonmii = mtable->has_mii = 0;
996 printk(KERN_INFO "%s: EEPROM default media type %s.\n", dev->name,
997 media & 0x0800 ? "Autosense" : medianame[media & 15]);
998 for (i = 0; i < count; i++) {
999 struct medialeaf *leaf = &mtable->mleaf[i];
1001 if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
1002 leaf->type = 0;
1003 leaf->media = p[0] & 0x3f;
1004 leaf->leafdata = p;
1005 if ((p[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
1006 mtable->has_mii = 1;
1007 p += 4;
1008 } else {
1009 leaf->type = p[1];
1010 if (p[1] & 1) {
1011 mtable->has_mii = 1;
1012 leaf->media = 11;
1013 } else {
1014 mtable->has_nonmii = 1;
1015 leaf->media = p[2] & 0x0f;
1017 leaf->leafdata = p + 2;
1018 p += (p[0] & 0x3f) + 1;
1020 if (tulip_debug > 1 && leaf->media == 11) {
1021 unsigned char *bp = leaf->leafdata;
1022 printk(KERN_INFO "%s: MII interface PHY %d, setup/reset "
1023 "sequences %d/%d long, capabilities %2.2x %2.2x.\n",
1024 dev->name, bp[0], bp[1], bp[1 + bp[1]*2],
1025 bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]);
1027 printk(KERN_INFO "%s: Index #%d - Media %s (#%d) described "
1028 "by a %s (%d) block.\n",
1029 dev->name, i, medianame[leaf->media], leaf->media,
1030 block_name[leaf->type], leaf->type);
1034 /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/
1036 /* EEPROM_Ctrl bits. */
1037 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
1038 #define EE_CS 0x01 /* EEPROM chip select. */
1039 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
1040 #define EE_WRITE_0 0x01
1041 #define EE_WRITE_1 0x05
1042 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
1043 #define EE_ENB (0x4800 | EE_CS)
1045 /* Delay between EEPROM clock transitions.
1046 The 1.2 code is a "nasty" timing loop, but PC compatible machines are
1047 *supposed* to delay an ISA-compatible period for the SLOW_DOWN_IO macro. */
1048 #ifdef _LINUX_DELAY_H
1049 #define eeprom_delay(nanosec) udelay((nanosec + 999)/1000)
1050 #else
1051 #define eeprom_delay(nanosec) do { int _i = 3; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
1052 #endif
1054 /* The EEPROM commands include the alway-set leading bit. */
1055 #define EE_WRITE_CMD (5 << 6)
1056 #define EE_READ_CMD (6 << 6)
1057 #define EE_ERASE_CMD (7 << 6)
1059 static int read_eeprom(long ioaddr, int location)
1061 int i;
1062 unsigned short retval = 0;
1063 long ee_addr = ioaddr + CSR9;
1064 int read_cmd = location | EE_READ_CMD;
1066 outl(EE_ENB & ~EE_CS, ee_addr);
1067 outl(EE_ENB, ee_addr);
1069 /* Shift the read command bits out. */
1070 for (i = 10; i >= 0; i--) {
1071 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
1072 outl(EE_ENB | dataval, ee_addr);
1073 eeprom_delay(100);
1074 outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1075 eeprom_delay(150);
1076 outl(EE_ENB | dataval, ee_addr); /* Finish EEPROM a clock tick. */
1077 eeprom_delay(250);
1079 outl(EE_ENB, ee_addr);
1081 for (i = 16; i > 0; i--) {
1082 outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
1083 eeprom_delay(100);
1084 retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
1085 outl(EE_ENB, ee_addr);
1086 eeprom_delay(100);
1089 /* Terminate the EEPROM access. */
1090 outl(EE_ENB & ~EE_CS, ee_addr);
1091 return retval;
1094 /* MII transceiver control section.
1095 Read and write the MII registers using software-generated serial
1096 MDIO protocol. See the MII specifications or DP83840A data sheet
1097 for details. */
1099 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
1100 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
1101 "overclocking" issues or future 66Mhz PCI. */
1102 #define mdio_delay() inl(mdio_addr)
1104 /* Read and write the MII registers using software-generated serial
1105 MDIO protocol. It is just different enough from the EEPROM protocol
1106 to not share code. The maxium data clock rate is 2.5 Mhz. */
1107 #define MDIO_SHIFT_CLK 0x10000
1108 #define MDIO_DATA_WRITE0 0x00000
1109 #define MDIO_DATA_WRITE1 0x20000
1110 #define MDIO_ENB 0x00000 /* Ignore the 0x02000 databook setting. */
1111 #define MDIO_ENB_IN 0x40000
1112 #define MDIO_DATA_READ 0x80000
1114 static int mdio_read(struct device *dev, int phy_id, int location)
1116 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1117 int i;
1118 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
1119 int retval = 0;
1120 long mdio_addr = dev->base_addr + CSR9;
1122 if (tp->chip_id == LC82C168) {
1123 long ioaddr = dev->base_addr;
1124 int i = 1000;
1125 outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
1126 while (--i > 0)
1127 if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
1128 return retval & 0xffff;
1129 return 0xffff;
1132 /* Establish sync by sending at least 32 logic ones. */
1133 for (i = 32; i >= 0; i--) {
1134 outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
1135 mdio_delay();
1136 outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
1137 mdio_delay();
1139 /* Shift the read command bits out. */
1140 for (i = 15; i >= 0; i--) {
1141 int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
1143 outl(MDIO_ENB | dataval, mdio_addr);
1144 mdio_delay();
1145 outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
1146 mdio_delay();
1148 /* Read the two transition, 16 data, and wire-idle bits. */
1149 for (i = 19; i > 0; i--) {
1150 outl(MDIO_ENB_IN, mdio_addr);
1151 mdio_delay();
1152 retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
1153 outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
1154 mdio_delay();
1156 return (retval>>1) & 0xffff;
1159 static void mdio_write(struct device *dev, int phy_id, int location, int value)
1161 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1162 int i;
1163 int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
1164 long mdio_addr = dev->base_addr + CSR9;
1166 if (tp->chip_id == LC82C168) {
1167 long ioaddr = dev->base_addr;
1168 int i = 1000;
1169 outl(cmd, ioaddr + 0xA0);
1171 if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
1172 break;
1173 while (--i > 0);
1174 return;
1177 /* Establish sync by sending 32 logic ones. */
1178 for (i = 32; i >= 0; i--) {
1179 outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
1180 mdio_delay();
1181 outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
1182 mdio_delay();
1184 /* Shift the command bits out. */
1185 for (i = 31; i >= 0; i--) {
1186 int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
1187 outl(MDIO_ENB | dataval, mdio_addr);
1188 mdio_delay();
1189 outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
1190 mdio_delay();
1192 /* Clear out extra bits. */
1193 for (i = 2; i > 0; i--) {
1194 outl(MDIO_ENB_IN, mdio_addr);
1195 mdio_delay();
1196 outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
1197 mdio_delay();
1199 return;
1203 static int
1204 tulip_open(struct device *dev)
1206 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1207 long ioaddr = dev->base_addr;
1208 int i = 0;
1210 /* On some chip revs we must set the MII/SYM port before the reset!? */
1211 if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii))
1212 outl(0x00040000, ioaddr + CSR6);
1214 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1215 outl(0x00000001, ioaddr + CSR0);
1216 #ifdef _LINUX_DELAY_H
1217 udelay(2);
1218 #else
1219 SLOW_DOWN_IO;
1220 #endif
1221 /* Deassert reset.
1222 486: Set 8 longword cache alignment, 8 longword burst.
1223 586: Set 16 longword cache alignment, no burst limit.
1224 Cache alignment bits 15:14 Burst length 13:8
1225 0000 No alignment 0x00000000 unlimited 0800 8 longwords
1226 4000 8 longwords 0100 1 longword 1000 16 longwords
1227 8000 16 longwords 0200 2 longwords 2000 32 longwords
1228 C000 32 longwords 0400 4 longwords
1229 Wait the specified 50 PCI cycles after a reset by initializing
1230 Tx and Rx queues and the address filter list. */
1231 #if defined(__alpha__)
1232 /* ToDo: Alpha setting could be better. */
1233 outl(0x01A00000 | 0xE000, ioaddr + CSR0);
1234 #elif defined(__powerpc__)
1235 outl(0x01A00080 | 0x8000, ioaddr + CSR0);
1236 #elif defined(__i386__)
1237 #if defined(MODULE)
1238 /* When a module we don't have 'x86' to check. */
1239 outl(0x01A00000 | 0x4800, ioaddr + CSR0);
1240 #else
1241 #if (LINUX_VERSION_CODE > 0x2014c)
1242 #define x86 boot_cpu_data.x86
1243 #endif
1244 outl(0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000), ioaddr + CSR0);
1245 if (x86 <= 4)
1246 printk(KERN_INFO "%s: This is a 386/486 PCI system, setting cache "
1247 "alignment to %x.\n", dev->name,
1248 0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000));
1249 #endif
1250 #else
1251 outl(0x01A00000 | 0x4800, ioaddr + CSR0);
1252 #warning Processor architecture undefined!
1253 #endif
1255 #ifdef SA_SHIRQ
1256 if (request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)) {
1257 return -EAGAIN;
1259 #else
1260 if (irq2dev_map[dev->irq] != NULL
1261 || (irq2dev_map[dev->irq] = dev) == NULL
1262 || dev->irq == 0
1263 || request_irq(dev->irq, &tulip_interrupt, 0,
1264 tulip_tbl[tp->chip_id].chip_name)) {
1265 return -EAGAIN;
1267 #endif
1269 if (tulip_debug > 1)
1270 printk(KERN_DEBUG "%s: tulip_open() irq %d.\n", dev->name, dev->irq);
1272 MOD_INC_USE_COUNT;
1274 tulip_init_ring(dev);
1276 /* This is set_rx_mode(), but without starting the transmitter. */
1277 /* Fill the whole address filter table with our physical address. */
1279 u16 *eaddrs = (u16 *)dev->dev_addr;
1280 u32 *setup_frm = tp->setup_frame, i;
1282 /* You must add the broadcast address when doing perfect filtering! */
1283 *setup_frm++ = 0xffff;
1284 *setup_frm++ = 0xffff;
1285 *setup_frm++ = 0xffff;
1286 /* Fill the rest of the accept table with our physical address. */
1287 for (i = 1; i < 16; i++) {
1288 *setup_frm++ = eaddrs[0];
1289 *setup_frm++ = eaddrs[1];
1290 *setup_frm++ = eaddrs[2];
1292 /* Put the setup frame on the Tx list. */
1293 tp->tx_ring[0].length = 0x08000000 | 192;
1294 tp->tx_ring[0].buffer1 = virt_to_bus(tp->setup_frame);
1295 tp->tx_ring[0].status = 0x80000000;
1297 tp->cur_tx++;
1300 outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3);
1301 outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4);
1303 if (dev->if_port == 0)
1304 dev->if_port = tp->default_port;
1305 if (tp->chip_id == DC21041 && dev->if_port > 4)
1306 /* Invalid: Select initial TP, autosense, autonegotiate. */
1307 dev->if_port = 4;
1309 /* Allow selecting a default media. */
1310 if (tp->mtable == NULL)
1311 goto media_picked;
1312 if (dev->if_port) {
1313 int looking_for = media_cap[dev->if_port] & MediaIsMII ? 11 :
1314 (dev->if_port == 12 ? 0 : dev->if_port);
1315 for (i = 0; i < tp->mtable->leafcount; i++)
1316 if (tp->mtable->mleaf[i].media == looking_for) {
1317 printk(KERN_INFO "%s: Using user-specified media %s.\n",
1318 dev->name, medianame[dev->if_port]);
1319 goto media_picked;
1322 if ((tp->mtable->defaultmedia & 0x0800) == 0)
1323 for (i = 0; i < tp->mtable->leafcount; i++)
1324 if (tp->mtable->mleaf[i].media == (tp->mtable->defaultmedia & 15)) {
1325 printk(KERN_INFO "%s: Using EEPROM-set media %s.\n",
1326 dev->name, medianame[tp->mtable->mleaf[i].media]);
1327 goto media_picked;
1329 /* Start sensing first non-full-duplex media. */
1330 for (i = tp->mtable->leafcount - 1;
1331 (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
1333 media_picked:
1335 tp->csr6 = 0;
1336 tp->cur_index = i;
1337 if (dev->if_port == 0 && tp->chip_id == DC21142) {
1338 tp->csr6 = 0x82420200;
1339 outl(0x0003FFFF, ioaddr + CSR14);
1340 outl(0x0008, ioaddr + CSR15);
1341 outl(0x0001, ioaddr + CSR13);
1342 outl(0x1301, ioaddr + CSR12);
1343 } else if (tp->chip_id == LC82C168 && tp->mii_cnt && ! tp->medialock) {
1344 dev->if_port = 11;
1345 tp->csr6 = 0x816C0000 | (tp->full_duplex ? 0x0200 : 0);
1346 outl(0x0001, ioaddr + CSR15);
1347 } else
1348 select_media(dev, 1);
1350 /* Start the chip's Tx to process setup frame. */
1351 outl(tp->csr6, ioaddr + CSR6);
1352 outl(tp->csr6 | 0x2000, ioaddr + CSR6);
1354 dev->tbusy = 0;
1355 tp->interrupt = 0;
1356 dev->start = 1;
1358 /* Enable interrupts by setting the interrupt mask. */
1359 outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
1360 outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
1361 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1362 outl(0, ioaddr + CSR2); /* Rx poll demand */
1364 if (tulip_debug > 2) {
1365 printk(KERN_DEBUG "%s: Done tulip_open(), CSR0 %8.8x, CSR5 %8.8x CSR6 %8.8x.\n",
1366 dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR5),
1367 inl(ioaddr + CSR6));
1369 /* Set the timer to switch to check for link beat and perhaps switch
1370 to an alternate media type. */
1371 init_timer(&tp->timer);
1372 tp->timer.expires = RUN_AT(5*HZ);
1373 tp->timer.data = (unsigned long)dev;
1374 tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
1375 add_timer(&tp->timer);
1377 return 0;
1380 /* Set up the transceiver control registers for the selected media type. */
1381 static void select_media(struct device *dev, int startup)
1383 long ioaddr = dev->base_addr;
1384 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1385 struct mediatable *mtable = tp->mtable;
1386 u32 new_csr6;
1387 int check_mii =0, i;
1389 if (mtable) {
1390 struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
1391 unsigned char *p = mleaf->leafdata;
1392 switch (mleaf->type) {
1393 case 0: /* 21140 non-MII xcvr. */
1394 if (tulip_debug > 1)
1395 printk(KERN_DEBUG "%s: Using a 21140 non-MII transceiver"
1396 " with control setting %2.2x.\n",
1397 dev->name, p[1]);
1398 dev->if_port = p[0];
1399 if (startup)
1400 outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
1401 outl(p[1], ioaddr + CSR12);
1402 new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
1403 break;
1404 case 2: case 4: {
1405 u16 setup[3];
1406 for (i = 0; i < 3; i++)
1407 setup[i] = get_u16(&p[i*2 + 1]);
1409 dev->if_port = p[0] & 15;
1410 if (tulip_debug > 1)
1411 printk(KERN_DEBUG "%s: 21142 non-MII %s transceiver control %4.4x/%4.4x.\n",
1412 dev->name, medianame[dev->if_port], setup[0], setup[1]);
1413 if (p[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */
1414 outl(0, ioaddr + CSR13);
1415 outl(setup[1], ioaddr + CSR14);
1416 outl(setup[2], ioaddr + CSR15);
1417 outl(setup[0], ioaddr + CSR13);
1418 for (i = 0; i < 3; i++) /* Re-fill setup[] */
1419 setup[i] = get_u16(&p[i*2 + 7]);
1420 } else if (dev->if_port <= 4) {
1421 outl(0, ioaddr + CSR13);
1422 outl(t21142_csr14[dev->if_port], ioaddr + CSR14);
1423 outl(t21142_csr15[dev->if_port], ioaddr + CSR15);
1424 outl(t21142_csr13[dev->if_port], ioaddr + CSR13);
1425 } else {
1426 outl(0, ioaddr + CSR14);
1427 outl(8, ioaddr + CSR15);
1428 outl(0, ioaddr + CSR13);
1430 outl(setup[0]<<16, ioaddr + CSR15); /* Direction */
1431 outl(setup[1]<<16, ioaddr + CSR15); /* Data */
1432 if (mleaf->type == 4)
1433 new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
1434 else
1435 new_csr6 = 0x82420000;
1436 break;
1438 case 1: case 3: {
1439 int phy_num = p[0];
1440 int init_length = p[1];
1441 u16 *misc_info;
1442 u16 to_advertise;
1444 dev->if_port = 11;
1445 check_mii = 1;
1446 new_csr6 = 0x020E0000;
1447 if (mleaf->type == 3) { /* 21142 */
1448 u16 *init_sequence = (u16*)(p+2);
1449 u16 *reset_sequence = &((u16*)(p+3))[init_length];
1450 int reset_length = p[2 + init_length*2];
1451 misc_info = reset_sequence + reset_length;
1452 if (startup)
1453 for (i = 0; i < reset_length; i++)
1454 outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
1455 for (i = 0; i < init_length; i++)
1456 outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
1457 } else {
1458 u8 *init_sequence = p + 2;
1459 u8 *reset_sequence = p + 3 + init_length;
1460 int reset_length = p[2 + init_length];
1461 misc_info = (u16*)(reset_sequence + reset_length);
1462 if (startup) {
1463 outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
1464 for (i = 0; i < reset_length; i++)
1465 outl(reset_sequence[i], ioaddr + CSR12);
1467 for (i = 0; i < init_length; i++)
1468 outl(init_sequence[i], ioaddr + CSR12);
1470 to_advertise = (get_u16(&misc_info[1]) & tp->to_advertise) | 1;
1471 tp->advertising[phy_num] = to_advertise;
1472 if (tulip_debug > 1 || 1)
1473 printk(KERN_DEBUG "%s: Advertising %4.4x on PHY %d (%d).\n",
1474 dev->name, to_advertise, phy_num, tp->phys[phy_num]);
1475 /* Bogus: put in by a committee? */
1476 mdio_write(dev, tp->phys[phy_num], 4, to_advertise);
1477 break;
1479 default:
1480 new_csr6 = 0x020E0000;
1482 if (tulip_debug > 1)
1483 printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n",
1484 dev->name, medianame[dev->if_port],
1485 inl(ioaddr + CSR12) & 0xff);
1486 } else if (tp->chip_id == DC21041) {
1487 if (tulip_debug > 1)
1488 printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n",
1489 dev->name, medianame[dev->if_port & 15],
1490 inl(ioaddr + CSR12) & 0xffff);
1491 outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1492 outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
1493 outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
1494 outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
1495 new_csr6 = 0x80020000;
1496 } else if (tp->chip_id == LC82C168) {
1497 if (startup && ! tp->medialock)
1498 dev->if_port = tp->mii_cnt ? 11 : 0;
1499 if (tulip_debug > 1)
1500 printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, CSR12 %4.4x,"
1501 " media %s.\n",
1502 dev->name, inl(ioaddr + 0xB8), inl(ioaddr + CSR12),
1503 medianame[dev->if_port]);
1504 if (tp->mii_cnt) {
1505 new_csr6 = 0x812C0000;
1506 outl(0x0001, ioaddr + CSR15);
1507 outl(0x0201B07A, ioaddr + 0xB8);
1508 } else if (startup) {
1509 /* Start with 10mbps to do autonegotiation. */
1510 outl(0x32, ioaddr + CSR12);
1511 new_csr6 = 0x00420000;
1512 outl(0x0001B078, ioaddr + 0xB8);
1513 outl(0x0201B078, ioaddr + 0xB8);
1514 } else if (dev->if_port == 3 || dev->if_port == 5) {
1515 outl(0x33, ioaddr + CSR12);
1516 new_csr6 = 0x01860000;
1517 if (startup)
1518 outl(0x0201F868, ioaddr + 0xB8); /* Trigger autonegotiation. */
1519 else
1520 outl(0x1F868, ioaddr + 0xB8);
1521 } else {
1522 outl(0x32, ioaddr + CSR12);
1523 new_csr6 = 0x00420000;
1524 outl(0x1F078, ioaddr + 0xB8);
1526 } else if (tp->chip_id == DC21040) { /* 21040 */
1527 /* Turn on the xcvr interface. */
1528 int csr12 = inl(ioaddr + CSR12);
1529 if (tulip_debug > 1)
1530 printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n",
1531 dev->name, dev->if_port ? "AUI" : "10baseT", csr12);
1532 new_csr6 = (dev->if_port ? 0x01860000 : 0x00420000);
1533 /* Set the full duplux match frame. */
1534 outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
1535 outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
1536 outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
1537 } else { /* Unknown chip type with no media table. */
1538 if (tp->default_port == 0)
1539 if (tp->mii_cnt) {
1540 dev->if_port = 11;
1541 } else
1542 dev->if_port = 3;
1543 if (media_cap[dev->if_port] & MediaIsMII) {
1544 new_csr6 = 0x020E0000;
1545 } else if (media_cap[dev->if_port] & MediaIsFx) {
1546 new_csr6 = 0x028600000;
1547 } else
1548 new_csr6 = 0x038600000;
1549 if (tulip_debug > 1)
1550 printk(KERN_DEBUG "%s: No media description table, assuming "
1551 "%s transceiver, CSR12 %2.2x.\n",
1552 dev->name, medianame[dev->if_port],
1553 inl(ioaddr + CSR12));
1556 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
1557 return;
1560 static void tulip_timer(unsigned long data)
1562 struct device *dev = (struct device *)data;
1563 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1564 long ioaddr = dev->base_addr;
1565 u32 csr12 = inl(ioaddr + CSR12);
1566 int next_tick = 0;
1568 if (tulip_debug > 3) {
1569 printk(KERN_DEBUG "%s: Media selection tick, status %8.8x mode %8.8x "
1570 "SIA %8.8x %8.8x %8.8x %8.8x.\n",
1571 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR6),
1572 csr12, inl(ioaddr + CSR13),
1573 inl(ioaddr + CSR14), inl(ioaddr + CSR15));
1575 switch (tp->chip_id) {
1576 case DC21040:
1577 if (csr12 & 0x0002) { /* Network error */
1578 printk(KERN_INFO "%s: No 10baseT link beat found, switching to %s media.\n",
1579 dev->name, dev->if_port ? "10baseT" : "AUI");
1580 dev->if_port ^= 1;
1581 outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
1582 dev->trans_start = jiffies;
1584 break;
1585 case DC21041:
1586 if (tulip_debug > 2)
1587 printk(KERN_DEBUG "%s: 21041 media tick CSR12 %8.8x.\n",
1588 dev->name, csr12);
1589 switch (dev->if_port) {
1590 case 0: case 3: case 4:
1591 if (csr12 & 0x0004) { /*LnkFail */
1592 /* 10baseT is dead. Check for activity on alternate port. */
1593 tp->mediasense = 1;
1594 if (csr12 & 0x0200)
1595 dev->if_port = 2;
1596 else
1597 dev->if_port = 1;
1598 printk(KERN_INFO "%s: No 21041 10baseT link beat, Media switched to %s.\n",
1599 dev->name, medianame[dev->if_port]);
1600 outl(0, ioaddr + CSR13); /* Reset */
1601 outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
1602 outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
1603 outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
1604 next_tick = 10*HZ; /* 2.4 sec. */
1605 } else
1606 next_tick = 30*HZ;
1607 break;
1608 case 1: /* 10base2 */
1609 case 2: /* AUI */
1610 if (csr12 & 0x0100) {
1611 next_tick = (30*HZ); /* 30 sec. */
1612 tp->mediasense = 0;
1613 } else if ((csr12 & 0x0004) == 0) {
1614 printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n", dev->name);
1615 dev->if_port = 0;
1616 select_media(dev, 0);
1617 next_tick = (24*HZ)/10; /* 2.4 sec. */
1618 } else if (tp->mediasense || (csr12 & 0x0002)) {
1619 dev->if_port = 3 - dev->if_port; /* Swap ports. */
1620 select_media(dev, 0);
1621 next_tick = 20*HZ;
1622 } else {
1623 next_tick = 20*HZ;
1625 break;
1627 break;
1628 case DC21140: case DC21142: case MX98713: default: {
1629 struct medialeaf *mleaf;
1630 unsigned char *p;
1631 if (tp->mtable == NULL) { /* No EEPROM info, use generic code. */
1632 /* Not much that can be done.
1633 Assume this a generic MII or SYM transceiver. */
1634 next_tick = 60*HZ;
1635 if (tulip_debug > 2)
1636 printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x "
1637 "CSR12 0x%2.2x.\n",
1638 dev->name, inl(ioaddr + CSR6), csr12 & 0xff);
1639 break;
1641 mleaf = &tp->mtable->mleaf[tp->cur_index];
1642 p = mleaf->leafdata;
1643 switch (mleaf->type) {
1644 case 0: case 4: {
1645 /* Type 0 serial or 4 SYM transceiver. Check the link beat bit. */
1646 int offset = mleaf->type == 4 ? 5 : 2;
1647 s8 bitnum = p[offset];
1648 if (p[offset+1] & 0x80) {
1649 if (tulip_debug > 1)
1650 printk(KERN_DEBUG"%s: Transceiver monitor tick "
1651 "CSR12=%#2.2x, no media sense.\n",
1652 dev->name, csr12);
1653 if (mleaf->type == 4) {
1654 if (mleaf->media == 3 && (csr12 & 0x02))
1655 goto select_next_media;
1657 break;
1659 if (tulip_debug > 2)
1660 printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x"
1661 " bit %d is %d, expecting %d.\n",
1662 dev->name, csr12, (bitnum >> 1) & 7,
1663 (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,
1664 (bitnum >= 0));
1665 /* Check that the specified bit has the proper value. */
1666 if ((bitnum < 0) !=
1667 ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {
1668 if (tulip_debug > 1)
1669 printk(KERN_DEBUG "%s: Link beat detected for %s.\n", dev->name,
1670 medianame[mleaf->media]);
1671 if ((p[2] & 0x61) == 0x01) /* Bogus Znyx board. */
1672 goto actually_mii;
1673 break;
1675 if (tp->medialock)
1676 break;
1677 select_next_media:
1678 if (--tp->cur_index < 0) {
1679 /* We start again, but should instead look for default. */
1680 tp->cur_index = tp->mtable->leafcount - 1;
1682 dev->if_port = tp->mtable->mleaf[tp->cur_index].media;
1683 if (media_cap[dev->if_port] & MediaIsFD)
1684 goto select_next_media; /* Skip FD entries. */
1685 if (tulip_debug > 1)
1686 printk(KERN_DEBUG "%s: No link beat on media %s,"
1687 " trying transceiver type %s.\n",
1688 dev->name, medianame[mleaf->media & 15],
1689 medianame[tp->mtable->mleaf[tp->cur_index].media]);
1690 select_media(dev, 0);
1691 /* Restart the transmit process. */
1692 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
1693 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1694 next_tick = (24*HZ)/10;
1695 break;
1697 case 1: case 3: { /* 21140, 21142 MII */
1698 int mii_reg1, mii_reg5;
1699 actually_mii:
1700 mii_reg1 = mdio_read(dev, tp->phys[0], 1);
1701 mii_reg5 = mdio_read(dev, tp->phys[0], 5);
1702 if (tulip_debug > 1)
1703 printk(KERN_INFO "%s: MII status %4.4x, Link partner report "
1704 "%4.4x, CSR12 %2.2x, %cD.\n",
1705 dev->name, mii_reg1, mii_reg5, csr12,
1706 tp->full_duplex ? 'F' : 'H');
1707 if (mii_reg1 != 0xffff && (mii_reg1 & 0x0004) == 0) {
1708 int new_reg1 = mdio_read(dev, tp->phys[0], 1);
1709 if ((new_reg1 & 0x0004) == 0) {
1710 printk(KERN_INFO "%s: No link beat on the MII interface,"
1711 " status then %4.4x now %4.4x.\n",
1712 dev->name, mii_reg1, new_reg1);
1713 if (tp->mtable && tp->mtable->has_nonmii)
1714 goto select_next_media;
1717 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000)
1718 ; /* No MII device or no link partner report */
1719 else if (tp->full_duplex_lock)
1721 else {
1722 int negotiated = mii_reg5 & tp->advertising[0];
1723 int duplex = ((negotiated & 0x0100) != 0
1724 || (negotiated & 0x00C0) == 0x0040);
1725 /* 100baseTx-FD or 10T-FD, but not 100-HD */
1726 if (tp->full_duplex != duplex) {
1727 tp->full_duplex = duplex;
1728 if (tp->full_duplex)
1729 tp->csr6 |= 0x0200;
1730 else
1731 tp->csr6 &= ~0x0200;
1732 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
1733 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1734 if (tulip_debug > 0) /* Gurppp, should be >1 */
1735 printk(KERN_INFO "%s: Setting %s-duplex based on MII"
1736 " Xcvr #%d parter capability of %4.4x.\n",
1737 dev->name, tp->full_duplex ? "full" : "half",
1738 tp->phys[0], mii_reg5);
1741 next_tick = 60*HZ;
1742 break;
1744 case 2: /* 21142 serial block has no link beat. */
1745 default:
1746 break;
1749 break;
1751 if (next_tick) {
1752 tp->timer.expires = RUN_AT(next_tick);
1753 add_timer(&tp->timer);
1757 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
1758 of available transceivers. */
1759 static void t21142_timer(unsigned long data)
1761 struct device *dev = (struct device *)data;
1762 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1763 long ioaddr = dev->base_addr;
1764 int csr12 = inl(ioaddr + CSR12);
1765 int next_tick = 60*HZ;
1766 int new_csr6 = 0;
1768 if (tulip_debug > 1)
1769 printk(KERN_INFO"%s: 21142 negotiation status %8.8x, %s.\n",
1770 dev->name, csr12, medianame[dev->if_port]);
1771 if (dev->if_port == 3) {
1772 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
1773 new_csr6 = 0x82420200;
1774 outl(new_csr6, ioaddr + CSR6);
1775 outl(0x0000, ioaddr + CSR13);
1776 outl(0x0003FFFF, ioaddr + CSR14);
1777 outl(0x0008, ioaddr + CSR15);
1778 outl(0x0001, ioaddr + CSR13);
1779 outl(0x1301, ioaddr + CSR12); /* Start NWay. */
1781 } else if ((csr12 & 0x7000) != 0x5000) {
1782 /* Negotiation failed. Search media types. */
1783 if (tulip_debug > 1)
1784 printk(KERN_INFO"%s: 21142 negotiation failed, status %8.8x.\n",
1785 dev->name, csr12);
1786 if (!(csr12 & 4)) { /* 10mbps link beat good. */
1787 new_csr6 = 0x82420000;
1788 dev->if_port = 0;
1789 outl(0, ioaddr + CSR13);
1790 outl(0x0003FFFF, ioaddr + CSR14);
1791 outl(t21142_csr15[dev->if_port], ioaddr + CSR15);
1792 outl(t21142_csr13[dev->if_port], ioaddr + CSR13);
1793 } else if (csr12 & 0x100) {
1794 new_csr6 = 0x82420200;
1795 dev->if_port = 2;
1796 outl(0, ioaddr + CSR13);
1797 outl(0x0003FFFF, ioaddr + CSR14);
1798 outl(0x0008, ioaddr + CSR15);
1799 outl(0x0001, ioaddr + CSR13);
1800 } else {
1801 /* Select 100mbps port to check for link beat. */
1802 new_csr6 = 0x83860000;
1803 dev->if_port = 3;
1804 outl(0, ioaddr + CSR13);
1805 outl(0x0003FF7F, ioaddr + CSR14);
1806 outl(8, ioaddr + CSR15);
1807 outl(1, ioaddr + CSR13);
1809 if (tulip_debug > 1)
1810 printk(KERN_INFO"%s: Testing new 21142 media %s.\n",
1811 dev->name, medianame[dev->if_port]);
1812 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
1813 tp->csr6 &= 0x00D5;
1814 tp->csr6 |= new_csr6;
1815 outl(0x0301, ioaddr + CSR12);
1816 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
1817 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1820 tp->timer.expires = RUN_AT(next_tick);
1821 add_timer(&tp->timer);
1824 static void t21142_lnk_change( struct device *dev)
1826 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1827 long ioaddr = dev->base_addr;
1828 int csr12 = inl(ioaddr + CSR12);
1830 if (tulip_debug > 1)
1831 printk(KERN_INFO"%s: 21142 link status interrupt %8.8x, CSR5 %x.\n",
1832 dev->name, csr12, inl(ioaddr + CSR5));
1834 if ((csr12 & 0x7000) == 0x5000) {
1835 if (csr12 & 0x01800000) {
1836 /* Switch to 100mbps mode. */
1837 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
1838 if (csr12 & 0x01000000) {
1839 dev->if_port = 5;
1840 tp->csr6 = 0x83860200;
1841 } else {
1842 dev->if_port = 3;
1843 tp->csr6 = 0x83860000;
1845 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1846 } /* Else 10baseT-FD is handled automatically. */
1847 } else if (dev->if_port == 3) {
1848 if (!(csr12 & 2))
1849 printk(KERN_INFO"%s: 21142 100baseTx link beat good.\n",
1850 dev->name);
1851 else
1852 dev->if_port = 0;
1853 } else if (dev->if_port == 0) {
1854 if (!(csr12 & 4))
1855 printk(KERN_INFO"%s: 21142 10baseT link beat good.\n",
1856 dev->name);
1857 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
1858 printk(KERN_INFO"%s: 21142 10mpbs sensed media.\n",
1859 dev->name);
1860 dev->if_port = 0;
1861 } else { /* 100mbps link beat good. */
1862 printk(KERN_INFO"%s: 21142 100baseTx sensed media.\n",
1863 dev->name);
1864 dev->if_port = 3;
1865 tp->csr6 = 0x83860000;
1866 outl(0x0003FF7F, ioaddr + CSR14);
1867 outl(0x0301, ioaddr + CSR12);
1868 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
1869 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1874 static void mxic_timer(unsigned long data)
1876 struct device *dev = (struct device *)data;
1877 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1878 long ioaddr = dev->base_addr;
1879 int next_tick = 60*HZ;
1881 if (tulip_debug > 3) {
1882 printk(KERN_INFO"%s: MXIC negotiation status %8.8x.\n", dev->name,
1883 inl(ioaddr + CSR12));
1885 if (next_tick) {
1886 tp->timer.expires = RUN_AT(next_tick);
1887 add_timer(&tp->timer);
1891 static void pnic_timer(unsigned long data)
1893 struct device *dev = (struct device *)data;
1894 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1895 long ioaddr = dev->base_addr;
1896 int csr12 = inl(ioaddr + CSR12);
1897 int next_tick = 60*HZ;
1898 int new_csr6 = tp->csr6 & ~0x40C40200;
1900 if (media_cap[dev->if_port] & MediaIsMII) {
1901 int negotiated = mdio_read(dev, tp->phys[0], 5) & tp->advertising[0];
1903 if (tulip_debug > 1)
1904 printk(KERN_DEBUG "%s: LC82C168 negotiated capability %8.8x, "
1905 "CSR5 %8.8x.\n",
1906 dev->name, negotiated, inl(ioaddr + CSR5));
1908 if (negotiated & 0x0380) /* 10 vs 100mbps */
1909 new_csr6 |= 0x812E0000;
1910 else
1911 new_csr6 |= 0x816E0000;
1912 if (((negotiated & 0x0300) == 0x0100) /* Duplex */
1913 || (negotiated & 0x00C0) == 0x0040
1914 || tp->full_duplex_lock) {
1915 tp->full_duplex = 1;
1916 new_csr6 |= 0x0200;
1918 if (tulip_debug > 1)
1919 printk(KERN_DEBUG "%s: LC82C168 MII PHY status %4.4x, Link "
1920 "partner report %4.4x, csr6 %8.8x/%8.8x.\n",
1921 dev->name, mdio_read(dev, tp->phys[0], 1), negotiated,
1922 tp->csr6, inl(ioaddr + CSR6));
1923 } else {
1924 int phy_reg = inl(ioaddr + 0xB8);
1925 int csr5 = inl(ioaddr + CSR5);
1927 if (tulip_debug > 1)
1928 printk(KERN_DEBUG "%s: LC82C168 phy status %8.8x, CSR5 %8.8x.\n",
1929 dev->name, phy_reg, csr5);
1931 if (phy_reg & 0x04000000) { /* Remote link fault */
1932 /*outl(0x0201F078, ioaddr + 0xB8);*/
1933 next_tick = 3*HZ;
1935 if (inl(ioaddr + CSR5) & TPLnkFail) { /* 100baseTx link beat */
1936 if (tulip_debug > 1)
1937 printk(KERN_DEBUG "%s: %s link beat failed, CSR12 %4.4x, "
1938 "CSR5 %8.8x, PHY %3.3x.\n",
1939 dev->name, medianame[dev->if_port], csr12,
1940 inl(ioaddr + CSR5), inl(ioaddr + 0xB8));
1941 if (tp->medialock) {
1942 } else if (dev->if_port == 0) {
1943 dev->if_port = 3;
1944 outl(0x33, ioaddr + CSR12);
1945 new_csr6 = 0x01860000;
1946 outl(0x1F868, ioaddr + 0xB8);
1947 } else {
1948 dev->if_port = 0;
1949 outl(0x32, ioaddr + CSR12);
1950 new_csr6 = 0x00420000;
1951 outl(0x1F078, ioaddr + 0xB8);
1953 new_csr6 |= (tp->csr6 & 0xfdff);
1954 next_tick = 3*HZ;
1955 } else
1956 new_csr6 = tp->csr6;
1957 if (tp->full_duplex_lock || (phy_reg & 0x30000000) != 0) {
1958 tp->full_duplex = 1;
1959 new_csr6 |= 0x00000200;
1962 if (tp->csr6 != new_csr6) {
1963 tp->csr6 = new_csr6;
1964 outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */
1965 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
1966 dev->trans_start = jiffies;
1967 if (tulip_debug > 0) /* Gurppp, should be >1 */
1968 printk(KERN_INFO "%s: Changing PNIC configuration to %s-duplex, "
1969 "CSR6 %8.8x.\n",
1970 dev->name, tp->full_duplex ? "full" : "half", new_csr6);
1972 tp->timer.expires = RUN_AT(next_tick);
1973 add_timer(&tp->timer);
1976 static void tulip_tx_timeout(struct device *dev)
1978 struct tulip_private *tp = (struct tulip_private *)dev->priv;
1979 long ioaddr = dev->base_addr;
1981 if (media_cap[dev->if_port] & MediaIsMII) {
1982 /* Do nothing -- the media monitor should handle this. */
1983 if (tulip_debug > 1)
1984 printk(KERN_WARNING "%s: Transmit timeout using MII device.\n",
1985 dev->name);
1986 dev->trans_start = jiffies;
1987 return;
1988 } else if (tp->chip_id == DC21040) {
1989 if (inl(ioaddr + CSR12) & 0x0002) {
1990 printk(KERN_INFO "%s: transmit timed out, switching to %s media.\n",
1991 dev->name, dev->if_port ? "10baseT" : "AUI");
1992 dev->if_port ^= 1;
1993 outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13);
1995 dev->trans_start = jiffies;
1996 return;
1997 } else if (tp->chip_id == DC21041) {
1998 u32 csr12 = inl(ioaddr + CSR12);
2000 printk(KERN_WARNING "%s: 21041 transmit timed out, status %8.8x, CSR12 %8.8x,"
2001 " CSR13 %8.8x, CSR14 %8.8x, resetting...\n",
2002 dev->name, inl(ioaddr + CSR5), csr12,
2003 inl(ioaddr + CSR13), inl(ioaddr + CSR14));
2004 tp->mediasense = 1;
2005 if (dev->if_port == 1 || dev->if_port == 2)
2006 if (csr12 & 0x0004) {
2007 dev->if_port = 2 - dev->if_port;
2008 } else
2009 dev->if_port = 0;
2010 else
2011 dev->if_port = 1;
2012 select_media(dev, 0);
2013 tp->stats.tx_errors++;
2014 dev->trans_start = jiffies;
2015 return;
2016 } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142
2017 || tp->chip_id == MX98713) {
2018 /* Stop the transmit process. */
2019 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
2020 printk(KERN_WARNING "%s: 21140 transmit timed out, status %8.8x, "
2021 "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
2022 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12),
2023 inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15));
2024 if (tp->mtable) {
2025 if (--tp->cur_index < 0) {
2026 /* We start again, but should instead look for default. */
2027 tp->cur_index = tp->mtable->leafcount - 1;
2029 select_media(dev, 0);
2030 printk(KERN_WARNING "%s: transmit timed out, switching to %s media.\n",
2031 dev->name, dev->if_port ? "100baseTx" : "10baseT");
2033 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
2034 tp->stats.tx_errors++;
2035 dev->trans_start = jiffies;
2036 return;
2037 } else
2038 printk(KERN_WARNING "%s: transmit timed out, status %8.8x, CSR12 %8.8x,"
2039 " resetting...\n",
2040 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12));
2041 #ifdef way_too_many_messages
2042 printk(" Rx ring %8.8x: ", (int)tp->rx_ring);
2043 for (i = 0; i < RX_RING_SIZE; i++)
2044 printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
2045 printk("\n Tx ring %8.8x: ", (int)tp->tx_ring);
2046 for (i = 0; i < TX_RING_SIZE; i++)
2047 printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
2048 printk("\n");
2049 #endif
2051 /* Perhaps we should reinitialize the hardware here. */
2052 dev->if_port = 0;
2053 /* Stop and restart the chip's Tx processes . */
2054 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
2055 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
2056 /* Trigger an immediate transmit demand. */
2057 outl(0, ioaddr + CSR1);
2059 dev->trans_start = jiffies;
2060 tp->stats.tx_errors++;
2061 return;
2065 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
2066 static void
2067 tulip_init_ring(struct device *dev)
2069 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2070 int i;
2072 tp->tx_full = 0;
2073 tp->cur_rx = tp->cur_tx = 0;
2074 tp->dirty_rx = tp->dirty_tx = 0;
2076 for (i = 0; i < RX_RING_SIZE; i++) {
2077 tp->rx_ring[i].status = 0x80000000; /* Owned by Tulip chip */
2078 tp->rx_ring[i].length = PKT_BUF_SZ;
2080 /* Note the receive buffer must be longword aligned.
2081 dev_alloc_skb() provides 16 byte alignment. But do *not*
2082 use skb_reserve() to align the IP header! */
2083 struct sk_buff *skb;
2084 skb = DEV_ALLOC_SKB(PKT_BUF_SZ);
2085 tp->rx_skbuff[i] = skb;
2086 if (skb == NULL)
2087 break; /* Bad news! */
2088 skb->dev = dev; /* Mark as being used by this device. */
2089 #if LINUX_VERSION_CODE > 0x10300
2090 tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail);
2091 #else
2092 tp->rx_ring[i].buffer1 = virt_to_bus(skb->data);
2093 #endif
2095 tp->rx_ring[i].buffer2 = virt_to_bus(&tp->rx_ring[i+1]);
2097 /* Mark the last entry as wrapping the ring. */
2098 tp->rx_ring[i-1].length = PKT_BUF_SZ | 0x02000000;
2099 tp->rx_ring[i-1].buffer2 = virt_to_bus(&tp->rx_ring[0]);
2101 /* The Tx buffer descriptor is filled in as needed, but we
2102 do need to clear the ownership bit. */
2103 for (i = 0; i < TX_RING_SIZE; i++) {
2104 tp->tx_skbuff[i] = 0;
2105 tp->tx_ring[i].status = 0x00000000;
2106 tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]);
2108 tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]);
2111 static int
2112 tulip_start_xmit(struct sk_buff *skb, struct device *dev)
2114 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2115 int entry;
2116 u32 flag;
2118 /* Block a timer-based transmit from overlapping. This could better be
2119 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
2120 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
2121 if (jiffies - dev->trans_start < TX_TIMEOUT)
2122 return 1;
2123 tulip_tx_timeout(dev);
2124 return 1;
2127 /* Caution: the write order is important here, set the base address
2128 with the "ownership" bits last. */
2130 /* Calculate the next Tx descriptor entry. */
2131 entry = tp->cur_tx % TX_RING_SIZE;
2133 tp->tx_skbuff[entry] = skb;
2134 tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data);
2136 if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
2137 flag = 0x60000000; /* No interrupt */
2138 dev->tbusy = 0;
2139 } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) {
2140 flag = 0xe0000000; /* Tx-done intr. */
2141 dev->tbusy = 0;
2142 } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) {
2143 flag = 0x60000000; /* No Tx-done intr. */
2144 dev->tbusy = 0;
2145 } else {
2146 /* Leave room for set_rx_mode() to fill entries. */
2147 flag = 0xe0000000; /* Tx-done intr. */
2148 tp->tx_full = 1;
2150 if (entry == TX_RING_SIZE-1)
2151 flag |= 0xe2000000;
2153 tp->tx_ring[entry].length = skb->len | flag;
2154 tp->tx_ring[entry].status = 0x80000000; /* Pass ownership to the chip. */
2155 tp->cur_tx++;
2156 /* Trigger an immediate transmit demand. */
2157 outl(0, dev->base_addr + CSR1);
2159 dev->trans_start = jiffies;
2161 return 0;
2164 /* The interrupt handler does all of the Rx thread work and cleans up
2165 after the Tx thread. */
2166 static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs)
2168 #ifdef SA_SHIRQ /* Use the now-standard shared IRQ implementation. */
2169 struct device *dev = (struct device *)dev_instance;
2170 #else
2171 struct device *dev = (struct device *)(irq2dev_map[irq]);
2172 #endif
2174 struct tulip_private *tp;
2175 long ioaddr;
2176 int csr5, work_budget = max_interrupt_work;
2178 if (dev == NULL) {
2179 printk (KERN_ERR" tulip_interrupt(): irq %d for unknown device.\n",
2180 irq);
2181 return;
2184 ioaddr = dev->base_addr;
2185 tp = (struct tulip_private *)dev->priv;
2186 if (test_and_set_bit(0, (void*)&tp->interrupt)) {
2187 #ifdef SMP_CHECK
2188 printk(KERN_ERR "%s: Re-entering the interrupt handler with proc %d,"
2189 " proc %d already handling.\n", dev->name,
2190 tp->smp_proc_id, hard_smp_processor_id());
2191 #else
2192 printk(KERN_ERR "%s: Re-entering the interrupt handler.\n", dev->name);
2193 #endif
2194 return;
2196 dev->interrupt = 1;
2197 #ifdef SMP_CHECK
2198 tp->smp_proc_id = hard_smp_processor_id();
2199 #endif
2201 do {
2202 csr5 = inl(ioaddr + CSR5);
2203 /* Acknowledge all of the current interrupt sources ASAP. */
2204 outl(csr5 & 0x0001ffff, ioaddr + CSR5);
2206 if (tulip_debug > 4)
2207 printk(KERN_DEBUG "%s: interrupt csr5=%#8.8x new csr5=%#8.8x.\n",
2208 dev->name, csr5, inl(dev->base_addr + CSR5));
2210 if ((csr5 & (NormalIntr|AbnormalIntr)) == 0)
2211 break;
2213 if (csr5 & (RxIntr | RxNoBuf))
2214 work_budget -= tulip_rx(dev);
2216 if (csr5 & (TxNoBuf | TxDied | TxIntr)) {
2217 unsigned int dirty_tx;
2219 for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0;
2220 dirty_tx++) {
2221 int entry = dirty_tx % TX_RING_SIZE;
2222 int status = tp->tx_ring[entry].status;
2224 if (status < 0)
2225 break; /* It still hasn't been Txed */
2226 /* Check for Rx filter setup frames. */
2227 if (tp->tx_skbuff[entry] == NULL)
2228 continue;
2230 if (status & 0x8000) {
2231 /* There was an major error, log it. */
2232 #ifndef final_version
2233 if (tulip_debug > 1)
2234 printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
2235 dev->name, status);
2236 #endif
2237 tp->stats.tx_errors++;
2238 if (status & 0x4104) tp->stats.tx_aborted_errors++;
2239 if (status & 0x0C00) tp->stats.tx_carrier_errors++;
2240 if (status & 0x0200) tp->stats.tx_window_errors++;
2241 if (status & 0x0002) tp->stats.tx_fifo_errors++;
2242 if ((status & 0x0080) && tp->full_duplex == 0)
2243 tp->stats.tx_heartbeat_errors++;
2244 #ifdef ETHER_STATS
2245 if (status & 0x0100) tp->stats.collisions16++;
2246 #endif
2247 } else {
2248 #ifdef ETHER_STATS
2249 if (status & 0x0001) tp->stats.tx_deferred++;
2250 #endif
2251 #if LINUX_VERSION_CODE > 0x20127
2252 tp->stats.tx_bytes += tp->tx_ring[entry].length & 0x7ff;
2253 #endif
2254 tp->stats.collisions += (status >> 3) & 15;
2255 tp->stats.tx_packets++;
2258 /* Free the original skb. */
2259 #if (LINUX_VERSION_CODE > 0x20155)
2260 dev_kfree_skb(tp->tx_skbuff[entry]);
2261 #else
2262 dev_kfree_skb(tp->tx_skbuff[entry], FREE_WRITE);
2263 #endif
2264 tp->tx_skbuff[entry] = 0;
2267 #ifndef final_version
2268 if (tp->cur_tx - dirty_tx > TX_RING_SIZE) {
2269 printk(KERN_ERR "%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
2270 dev->name, dirty_tx, tp->cur_tx, tp->tx_full);
2271 dirty_tx += TX_RING_SIZE;
2273 #endif
2275 if (tp->tx_full && dev->tbusy
2276 && tp->cur_tx - dirty_tx < TX_RING_SIZE - 2) {
2277 /* The ring is no longer full, clear tbusy. */
2278 tp->tx_full = 0;
2279 dev->tbusy = 0;
2280 mark_bh(NET_BH);
2283 tp->dirty_tx = dirty_tx;
2284 if (csr5 & TxDied) {
2285 if (tulip_debug > 1)
2286 printk(KERN_WARNING "%s: The transmitter stopped!"
2287 " CSR5 is %x, CSR6 %x.\n",
2288 dev->name, csr5, inl(ioaddr + CSR6));
2289 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
2290 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
2294 /* Log errors. */
2295 if (csr5 & AbnormalIntr) { /* Abnormal error summary bit. */
2296 if (csr5 & TxJabber) tp->stats.tx_errors++;
2297 if (csr5 & TxFIFOUnderflow) {
2298 if ((tp->csr6 & 0xC000) != 0xC000)
2299 tp->csr6 += 0x4000; /* Bump up the Tx threshold */
2300 else
2301 tp->csr6 |= 0x00200000; /* Store-n-forward. */
2302 /* Restart the transmit process. */
2303 outl(tp->csr6 | 0x0002, ioaddr + CSR6);
2304 outl(tp->csr6 | 0x2002, ioaddr + CSR6);
2306 if (csr5 & RxDied) { /* Missed a Rx frame. */
2307 tp->stats.rx_errors++;
2308 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
2310 if (csr5 & TimerInt) {
2311 printk(KERN_ERR "%s: Something Wicked happened! %8.8x.\n",
2312 dev->name, csr5);
2313 /* Hmmmmm, it's not clear what to do here. */
2315 if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)
2316 && tp->chip_id == DC21142) {
2317 if (tulip_debug > 1)
2318 printk(KERN_INFO"%s: 21142 link change, CSR5 = %8.8x.\n",
2319 dev->name, csr5);
2320 t21142_lnk_change(dev);
2322 /* Clear all error sources, included undocumented ones! */
2323 outl(0x0800f7ba, ioaddr + CSR5);
2325 if (--work_budget < 0) {
2326 if (tulip_debug > 1)
2327 printk(KERN_WARNING "%s: Too much work at interrupt, "
2328 "csr5=0x%8.8x.\n", dev->name, csr5);
2329 /* Acknowledge all interrupt sources. */
2330 outl(0x8001ffff, ioaddr + CSR5);
2331 #ifdef notdef
2332 /* Clear all but standard interrupt sources. */
2333 outl((~csr5) & 0x0001ebef, ioaddr + CSR7);
2334 #endif
2335 break;
2337 } while (1);
2339 if (tulip_debug > 3)
2340 printk(KERN_DEBUG "%s: exiting interrupt, csr5=%#4.4x.\n",
2341 dev->name, inl(ioaddr + CSR5));
2343 dev->interrupt = 0;
2344 clear_bit(0, (void*)&tp->interrupt);
2345 return;
2348 static int
2349 tulip_rx(struct device *dev)
2351 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2352 int entry = tp->cur_rx % RX_RING_SIZE;
2353 int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
2354 int work_done = 0;
2356 if (tulip_debug > 4)
2357 printk(KERN_DEBUG " In tulip_rx(), entry %d %8.8x.\n", entry,
2358 tp->rx_ring[entry].status);
2359 /* If we own the next entry, it's a new packet. Send it up. */
2360 while (tp->rx_ring[entry].status >= 0) {
2361 s32 status = tp->rx_ring[entry].status;
2363 if (--rx_work_limit < 0)
2364 break;
2365 if ((status & 0x0300) != 0x0300) {
2366 if ((status & 0xffff) != 0x7fff) { /* Ingore earlier buffers. */
2367 if (tulip_debug > 1)
2368 printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
2369 "multiple buffers, status %8.8x!\n",
2370 dev->name, status);
2371 tp->stats.rx_length_errors++;
2373 } else if (status & 0x8000) {
2374 /* There was a fatal error. */
2375 if (tulip_debug > 2)
2376 printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",
2377 dev->name, status);
2378 tp->stats.rx_errors++; /* end of a packet.*/
2379 if (status & 0x0890) tp->stats.rx_length_errors++;
2380 if (status & 0x0004) tp->stats.rx_frame_errors++;
2381 if (status & 0x0002) tp->stats.rx_crc_errors++;
2382 if (status & 0x0001) tp->stats.rx_fifo_errors++;
2383 } else {
2384 /* Omit the four octet CRC from the length. */
2385 short pkt_len = (status >> 16) - 4;
2386 struct sk_buff *skb;
2388 /* Check if the packet is long enough to just accept without
2389 copying to a properly sized skbuff. */
2390 if (pkt_len < rx_copybreak
2391 && (skb = DEV_ALLOC_SKB(pkt_len+2)) != NULL) {
2392 skb->dev = dev;
2393 skb_reserve(skb, 2); /* 16 byte align the IP header */
2394 #if LINUX_VERSION_CODE < 0x10300
2395 memcpy(skb->data, tp->rx_ring[entry].buffer1, pkt_len);
2396 #elif LINUX_VERSION_CODE < 0x20200 || defined(__alpha__)
2397 memcpy(skb_put(skb, pkt_len),
2398 bus_to_virt(tp->rx_ring[entry].buffer1), pkt_len);
2399 #else
2400 eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1),
2401 pkt_len, 0);
2402 skb_put(skb, pkt_len);
2403 #endif
2404 work_done++;
2405 } else { /* Pass up the skb already on the Rx ring. */
2406 skb = tp->rx_skbuff[entry];
2407 tp->rx_skbuff[entry] = NULL;
2408 #ifndef final_version
2410 void *temp = skb_put(skb, pkt_len);
2411 if (bus_to_virt(tp->rx_ring[entry].buffer1) != temp)
2412 printk(KERN_ERR "%s: Internal consistency error! The "
2413 "skbuff addresses do not match in tulip_rx:"
2414 " %p vs. %p / %p.\n", dev->name,
2415 bus_to_virt(tp->rx_ring[entry].buffer1),
2416 skb->head, temp);
2418 #else
2419 skb_put(skb, pkt_len);
2420 #endif
2422 #if LINUX_VERSION_CODE > 0x10300
2423 skb->protocol = eth_type_trans(skb, dev);
2424 #else
2425 skb->len = pkt_len;
2426 #endif
2427 netif_rx(skb);
2428 dev->last_rx = jiffies;
2429 tp->stats.rx_packets++;
2430 #if LINUX_VERSION_CODE > 0x20127
2431 tp->stats.rx_bytes += pkt_len;
2432 #endif
2434 entry = (++tp->cur_rx) % RX_RING_SIZE;
2437 /* Refill the Rx ring buffers. */
2438 for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {
2439 entry = tp->dirty_rx % RX_RING_SIZE;
2440 if (tp->rx_skbuff[entry] == NULL) {
2441 struct sk_buff *skb;
2442 skb = tp->rx_skbuff[entry] = DEV_ALLOC_SKB(PKT_BUF_SZ);
2443 if (skb == NULL)
2444 break;
2445 skb->dev = dev; /* Mark as being used by this device. */
2446 #if LINUX_VERSION_CODE > 0x10300
2447 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail);
2448 #else
2449 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->data);
2450 #endif
2451 work_done++;
2453 tp->rx_ring[entry].status = 0x80000000;
2456 return work_done;
2459 static int
2460 tulip_close(struct device *dev)
2462 long ioaddr = dev->base_addr;
2463 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2464 int i;
2466 dev->start = 0;
2467 dev->tbusy = 1;
2469 if (tulip_debug > 1)
2470 printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
2471 dev->name, inl(ioaddr + CSR5));
2473 /* Disable interrupts by clearing the interrupt mask. */
2474 outl(0x00000000, ioaddr + CSR7);
2475 /* Stop the chip's Tx and Rx processes. */
2476 outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
2477 /* 21040 -- Leave the card in 10baseT state. */
2478 if (tp->chip_id == DC21040)
2479 outl(0x00000004, ioaddr + CSR13);
2481 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
2483 del_timer(&tp->timer);
2485 #ifdef SA_SHIRQ
2486 free_irq(dev->irq, dev);
2487 #else
2488 free_irq(dev->irq);
2489 irq2dev_map[dev->irq] = 0;
2490 #endif
2492 /* Free all the skbuffs in the Rx queue. */
2493 for (i = 0; i < RX_RING_SIZE; i++) {
2494 struct sk_buff *skb = tp->rx_skbuff[i];
2495 tp->rx_skbuff[i] = 0;
2496 tp->rx_ring[i].status = 0; /* Not owned by Tulip chip. */
2497 tp->rx_ring[i].length = 0;
2498 tp->rx_ring[i].buffer1 = 0xBADF00D0; /* An invalid address. */
2499 if (skb) {
2500 #if LINUX_VERSION_CODE < 0x20100
2501 skb->free = 1;
2502 #endif
2503 #if (LINUX_VERSION_CODE > 0x20155)
2504 dev_kfree_skb(skb);
2505 #else
2506 dev_kfree_skb(skb, FREE_WRITE);
2507 #endif
2510 for (i = 0; i < TX_RING_SIZE; i++) {
2511 if (tp->tx_skbuff[i])
2512 #if (LINUX_VERSION_CODE > 0x20155)
2513 dev_kfree_skb(tp->tx_skbuff[i]);
2514 #else
2515 dev_kfree_skb(tp->tx_skbuff[i], FREE_WRITE);
2516 #endif
2517 tp->tx_skbuff[i] = 0;
2521 MOD_DEC_USE_COUNT;
2523 return 0;
2526 static struct enet_statistics *
2527 tulip_get_stats(struct device *dev)
2529 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2530 long ioaddr = dev->base_addr;
2532 if (dev->start)
2533 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
2535 return &tp->stats;
2538 #ifdef HAVE_PRIVATE_IOCTL
2539 /* Provide ioctl() calls to examine the MII xcvr state. */
2540 static int private_ioctl(struct device *dev, struct ifreq *rq, int cmd)
2542 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2543 long ioaddr = dev->base_addr;
2544 u16 *data = (u16 *)&rq->ifr_data;
2545 int phy = tp->phys[0] & 0x1f;
2546 long flags;
2548 switch(cmd) {
2549 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
2550 if (tp->mtable && tp->mtable->has_mii)
2551 data[0] = phy;
2552 else if (tp->chip_id == DC21142)
2553 data[0] = 32;
2554 else
2555 return -ENODEV;
2556 return 0;
2557 case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
2558 if (data[0] == 32) { /* 21142 pseudo-MII */
2559 int csr12 = inl(ioaddr + CSR12);
2560 int csr14 = inl(ioaddr + CSR14);
2561 switch (data[1]) {
2562 case 0: {
2563 data[3] = ((csr14<<13)&0x4000) + ((csr14<<5)&0x1000);
2564 break; }
2565 case 1:
2566 data[3] = 0x7848 + ((csr12&0x7000) == 0x5000 ? 0x20 : 0)
2567 + (csr12&0x06 ? 0x04 : 0);
2568 break;
2569 case 4: {
2570 int csr14 = inl(ioaddr + CSR14);
2571 data[3] = ((csr14>>9)&0x0380) + ((csr14>>1)&0x20) + 1;
2572 break;
2574 case 5: data[3] = inl(ioaddr + CSR12) >> 16; break;
2575 default: data[3] = 0; break;
2577 } else {
2578 save_flags(flags);
2579 cli();
2580 data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f);
2581 restore_flags(flags);
2583 return 0;
2584 case SIOCDEVPRIVATE+2: /* Write the specified MII register */
2585 if (!suser())
2586 return -EPERM;
2587 if (data[0] == 32) { /* 21142 pseudo-MII */
2588 } else {
2589 save_flags(flags);
2590 cli();
2591 mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
2592 restore_flags(flags);
2594 return 0;
2595 default:
2596 return -EOPNOTSUPP;
2599 return -EOPNOTSUPP;
2601 #endif /* HAVE_PRIVATE_IOCTL */
2603 /* Set or clear the multicast filter for this adaptor.
2604 Note that we only use exclusion around actually queueing the
2605 new frame, not around filling tp->setup_frame. This is non-deterministic
2606 when re-entered but still correct. */
2608 /* The little-endian AUTODIN32 ethernet CRC calculation.
2609 N.B. Do not use for bulk data, use a table-based routine instead.
2610 This is common code and should be moved to net/core/crc.c */
2611 static unsigned const ethernet_polynomial_le = 0xedb88320U;
2612 static inline unsigned ether_crc_le(int length, unsigned char *data)
2614 unsigned int crc = 0xffffffff; /* Initial value. */
2615 while(--length >= 0) {
2616 unsigned char current_octet = *data++;
2617 int bit;
2618 for (bit = 8; --bit >= 0; current_octet >>= 1) {
2619 if ((crc ^ current_octet) & 1) {
2620 crc >>= 1;
2621 crc ^= ethernet_polynomial_le;
2622 } else
2623 crc >>= 1;
2626 return crc;
2629 #ifdef NEW_MULTICAST
2630 static void set_rx_mode(struct device *dev)
2631 #else
2632 static void set_rx_mode(struct device *dev, int num_addrs, void *addrs)
2633 #endif
2635 long ioaddr = dev->base_addr;
2636 int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
2637 struct tulip_private *tp = (struct tulip_private *)dev->priv;
2639 tp->csr6 &= ~0x00D5;
2640 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2641 outl(csr6 | 0x00C0, ioaddr + CSR6);
2642 /* Unconditionally log net taps. */
2643 printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name);
2644 tp->csr6 |= 0xC0;
2645 } else if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) {
2646 /* Too many to filter perfectly -- accept all multicasts. */
2647 outl(csr6 | 0x0080, ioaddr + CSR6);
2648 tp->csr6 |= 0x80;
2649 } else {
2650 u32 *setup_frm = tp->setup_frame;
2651 struct dev_mc_list *mclist;
2652 u16 *eaddrs;
2653 u32 tx_flags;
2654 int i;
2656 if (dev->mc_count > 14) { /* Must use a multicast hash table. */
2657 u16 hash_table[32];
2658 memset(hash_table, 0, sizeof(hash_table));
2659 /* This should work on big-endian machines as well. */
2660 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
2661 i++, mclist = mclist->next)
2662 set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
2663 hash_table);
2664 /* Copy the hash table to the setup frame.
2665 NOTE that only the LOW SHORTWORD of setup_frame[] is valid! */
2666 for (i = 0; i < 32; i++)
2667 *setup_frm++ = hash_table[i];
2668 setup_frm += 7;
2669 tx_flags = 0x08400000 | 192;
2670 /* Too clever: i > 15 for fall-though. */
2671 } else {
2672 /* We have <= 15 addresses so we can use the wonderful
2673 16 address perfect filtering of the Tulip. */
2674 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
2675 i++, mclist = mclist->next) {
2676 /* Note that only the low shortword of setup_frame[] is valid!
2677 This code may require tweaking for non-x86 architectures! */
2678 eaddrs = (u16 *)mclist->dmi_addr;
2679 *setup_frm++ = *eaddrs++;
2680 *setup_frm++ = *eaddrs++;
2681 *setup_frm++ = *eaddrs++;
2683 /* Fill the rest of the table with our physical address.
2684 Once again, only the low shortword or setup_frame[] is valid! */
2685 *setup_frm++ = 0xffff;
2686 *setup_frm++ = 0xffff;
2687 *setup_frm++ = 0xffff;
2688 tx_flags = 0x08000000 | 192;
2690 eaddrs = (u16 *)dev->dev_addr;
2691 do {
2692 *setup_frm++ = eaddrs[0];
2693 *setup_frm++ = eaddrs[1];
2694 *setup_frm++ = eaddrs[2];
2695 } while (++i < 15);
2696 /* Now add this frame to the Tx list. */
2697 if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
2698 /* Same setup recently queued, we need not add it. */
2699 } else {
2700 unsigned long flags;
2701 unsigned int entry;
2703 save_flags(flags); cli();
2704 entry = tp->cur_tx++ % TX_RING_SIZE;
2706 if (entry != 0) {
2707 /* Avoid a chip errata by prefixing a dummy entry. */
2708 tp->tx_skbuff[entry] = 0;
2709 tp->tx_ring[entry].length =
2710 (entry == TX_RING_SIZE-1) ? 0x02000000 : 0;
2711 tp->tx_ring[entry].buffer1 = 0;
2712 tp->tx_ring[entry].status = 0x80000000;
2713 entry = tp->cur_tx++ % TX_RING_SIZE;
2716 tp->tx_skbuff[entry] = 0;
2717 /* Put the setup frame on the Tx list. */
2718 if (entry == TX_RING_SIZE-1)
2719 tx_flags |= 0x02000000; /* Wrap ring. */
2720 tp->tx_ring[entry].length = tx_flags;
2721 tp->tx_ring[entry].buffer1 = virt_to_bus(tp->setup_frame);
2722 tp->tx_ring[entry].status = 0x80000000;
2723 if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2) {
2724 dev->tbusy = 1;
2725 tp->tx_full = 1;
2727 restore_flags(flags);
2728 /* Trigger an immediate transmit demand. */
2729 outl(0, ioaddr + CSR1);
2731 outl(csr6 | 0x0000, ioaddr + CSR6);
2735 #ifdef CARDBUS
2737 #include <pcmcia/driver_ops.h>
2739 static dev_node_t *tulip_attach(dev_locator_t *loc)
2741 u16 dev_id;
2742 u32 io;
2743 u8 bus, devfn;
2744 struct device *dev;
2746 if (loc->bus != LOC_PCI) return NULL;
2747 bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
2748 printk(KERN_INFO "tulip_attach(bus %d, function %d)\n", bus, devfn);
2749 pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &io);
2750 pcibios_read_config_word(bus, devfn, PCI_DEVICE_ID, &dev_id);
2751 io &= ~3;
2752 dev = tulip_probe1(bus, devfn, NULL, DC21142, -1);
2753 if (dev) {
2754 dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
2755 strcpy(node->dev_name, dev->name);
2756 node->major = node->minor = 0;
2757 node->next = NULL;
2758 MOD_INC_USE_COUNT;
2759 return node;
2761 return NULL;
2764 static void tulip_detach(dev_node_t *node)
2766 struct device **devp, **next;
2767 printk(KERN_INFO "tulip_detach(%s)\n", node->dev_name);
2768 for (devp = &root_tulip_dev; *devp; devp = next) {
2769 next = &((struct tulip_private *)(*devp)->priv)->next_module;
2770 if (strcmp((*devp)->name, node->dev_name) == 0) break;
2772 if (*devp) {
2773 unregister_netdev(*devp);
2774 kfree(*devp);
2775 *devp = *next;
2776 kfree(node);
2777 MOD_DEC_USE_COUNT;
2781 struct driver_operations tulip_ops = {
2782 "tulip_cb", tulip_attach, NULL, NULL, tulip_detach
2785 #endif /* Cardbus support */
2788 #ifdef MODULE
2789 #if LINUX_VERSION_CODE > 0x20118
2790 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
2791 MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
2792 MODULE_PARM(debug, "i");
2793 MODULE_PARM(max_interrupt_work, "i");
2794 MODULE_PARM(reverse_probe, "i");
2795 MODULE_PARM(rx_copybreak, "i");
2796 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
2797 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
2798 #endif
2800 /* An additional parameter that may be passed in... */
2801 static int debug = -1;
2804 init_module(void)
2806 if (debug >= 0)
2807 tulip_debug = debug;
2809 #ifdef CARDBUS
2810 register_driver(&tulip_ops);
2811 return 0;
2812 #else
2813 return tulip_probe(NULL);
2814 #endif
2817 void
2818 cleanup_module(void)
2820 struct device *next_dev;
2822 #ifdef CARDBUS
2823 unregister_driver(&tulip_ops);
2824 #endif
2826 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
2827 while (root_tulip_dev) {
2828 next_dev = ((struct tulip_private *)root_tulip_dev->priv)->next_module;
2829 unregister_netdev(root_tulip_dev);
2830 release_region(root_tulip_dev->base_addr, TULIP_TOTAL_SIZE);
2831 kfree(root_tulip_dev);
2832 root_tulip_dev = next_dev;
2836 #endif /* MODULE */
2839 * Local variables:
2840 * 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`"
2841 * 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`"
2842 * c-indent-level: 4
2843 * c-basic-offset: 4
2844 * tab-width: 4
2845 * End: