1 /* tulip_core.c: A DEC 21x4x-family ethernet driver for Linux. */
4 Maintained by Jeff Garzik <jgarzik@pobox.com>
5 Copyright 2000,2001 The Linux Kernel Team
6 Written/copyright 1994-2001 by Donald Becker.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
12 for more information on this driver, or visit the project
13 Web page at http://sourceforge.net/projects/tulip/
17 #include <linux/config.h>
19 #define DRV_NAME "tulip"
20 #ifdef CONFIG_TULIP_NAPI
21 #define DRV_VERSION "1.1.13-NAPI" /* Keep at least for test */
23 #define DRV_VERSION "1.1.13"
25 #define DRV_RELDATE "May 11, 2002"
28 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/init.h>
32 #include <linux/etherdevice.h>
33 #include <linux/delay.h>
34 #include <linux/mii.h>
35 #include <linux/ethtool.h>
36 #include <linux/crc32.h>
37 #include <asm/unaligned.h>
38 #include <asm/uaccess.h>
44 static char version[] __devinitdata =
45 "Linux Tulip driver version " DRV_VERSION " (" DRV_RELDATE ")\n";
48 /* A few user-configurable values. */
50 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
51 static unsigned int max_interrupt_work = 25;
54 /* Used to pass the full-duplex flag, etc. */
55 static int full_duplex[MAX_UNITS];
56 static int options[MAX_UNITS];
57 static int mtu[MAX_UNITS]; /* Jumbo MTU for interfaces. */
59 /* The possible media types that can be set in options[] are: */
60 const char * const medianame[32] = {
61 "10baseT", "10base2", "AUI", "100baseTx",
62 "10baseT-FDX", "100baseTx-FDX", "100baseT4", "100baseFx",
63 "100baseFx-FDX", "MII 10baseT", "MII 10baseT-FDX", "MII",
64 "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FDX", "MII 100baseT4",
65 "MII 100baseFx-HDX", "MII 100baseFx-FDX", "Home-PNA 1Mbps", "Invalid-19",
66 "","","","", "","","","", "","","","Transceiver reset",
69 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
70 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
71 || defined(__sparc_) || defined(__ia64__) \
72 || defined(__sh__) || defined(__mips__)
73 static int rx_copybreak = 1518;
75 static int rx_copybreak = 100;
79 Set the bus performance register.
80 Typical: Set 16 longword cache alignment, no burst limit.
81 Cache alignment bits 15:14 Burst length 13:8
82 0000 No alignment 0x00000000 unlimited 0800 8 longwords
83 4000 8 longwords 0100 1 longword 1000 16 longwords
84 8000 16 longwords 0200 2 longwords 2000 32 longwords
85 C000 32 longwords 0400 4 longwords
86 Warning: many older 486 systems are broken and require setting 0x00A04800
87 8 longword cache alignment, 8 longword burst.
88 ToDo: Non-Intel setting could be better.
91 #if defined(__alpha__) || defined(__ia64__) || defined(__x86_64__)
92 static int csr0 = 0x01A00000 | 0xE000;
93 #elif defined(__i386__) || defined(__powerpc__)
94 static int csr0 = 0x01A00000 | 0x8000;
95 #elif defined(__sparc__) || defined(__hppa__)
96 /* The UltraSparc PCI controllers will disconnect at every 64-byte
97 * crossing anyways so it makes no sense to tell Tulip to burst
100 static int csr0 = 0x01A00000 | 0x9000;
101 #elif defined(__arm__) || defined(__sh__)
102 static int csr0 = 0x01A00000 | 0x4800;
103 #elif defined(__mips__)
104 static int csr0 = 0x00200000 | 0x4000;
106 #warning Processor architecture undefined!
107 static int csr0 = 0x00A00000 | 0x4800;
110 /* Operational parameters that usually are not changed. */
111 /* Time in jiffies before concluding the transmitter is hung. */
112 #define TX_TIMEOUT (4*HZ)
115 MODULE_AUTHOR("The Linux Kernel Team");
116 MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
117 MODULE_LICENSE("GPL");
118 MODULE_PARM(tulip_debug, "i");
119 MODULE_PARM(max_interrupt_work, "i");
120 MODULE_PARM(rx_copybreak, "i");
121 MODULE_PARM(csr0, "i");
122 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
123 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
125 #define PFX DRV_NAME ": "
128 int tulip_debug = TULIP_DEBUG;
136 * This table use during operation for capabilities and media timer.
138 * It is indexed via the values in 'enum chips'
141 struct tulip_chip_table tulip_tbl[] = {
142 { }, /* placeholder for array, slot unused currently */
143 { }, /* placeholder for array, slot unused currently */
146 { "Digital DS21140 Tulip", 128, 0x0001ebef,
147 HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | HAS_PCI_MWI, tulip_timer },
149 /* DC21142, DC21143 */
150 { "Digital DS21143 Tulip", 128, 0x0801fbff,
151 HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_ACPI | HAS_NWAY
152 | HAS_INTR_MITIGATION | HAS_PCI_MWI, t21142_timer },
155 { "Lite-On 82c168 PNIC", 256, 0x0001fbef,
156 HAS_MII | HAS_PNICNWAY, pnic_timer },
159 { "Macronix 98713 PMAC", 128, 0x0001ebef,
160 HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer },
163 { "Macronix 98715 PMAC", 256, 0x0001ebef,
164 HAS_MEDIA_TABLE, mxic_timer },
167 { "Macronix 98725 PMAC", 256, 0x0001ebef,
168 HAS_MEDIA_TABLE, mxic_timer },
171 { "ASIX AX88140", 128, 0x0001fbff,
172 HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY
173 | IS_ASIX, tulip_timer },
176 { "Lite-On PNIC-II", 256, 0x0801fbff,
177 HAS_MII | HAS_NWAY | HAS_8023X | HAS_PCI_MWI, pnic2_timer },
180 { "ADMtek Comet", 256, 0x0001abef,
181 HAS_MII | MC_HASH_ONLY | COMET_MAC_ADDR, comet_timer },
184 { "Compex 9881 PMAC", 128, 0x0001ebef,
185 HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer },
188 { "Intel DS21145 Tulip", 128, 0x0801fbff,
189 HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_ACPI
190 | HAS_NWAY | HAS_PCI_MWI, t21142_timer },
193 { "Davicom DM9102/DM9102A", 128, 0x0001ebef,
194 HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | HAS_ACPI,
198 { "Conexant LANfinity", 256, 0x0001ebef,
199 HAS_MII | HAS_ACPI, tulip_timer },
203 static struct pci_device_id tulip_pci_tbl[] = {
204 { 0x1011, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21140 },
205 { 0x1011, 0x0019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21143 },
206 { 0x11AD, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, LC82C168 },
207 { 0x10d9, 0x0512, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98713 },
208 { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98715 },
209 /* { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98725 },*/
210 { 0x125B, 0x1400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AX88140 },
211 { 0x11AD, 0xc115, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PNIC2 },
212 { 0x1317, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
213 { 0x1317, 0x0985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
214 { 0x1317, 0x1985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
215 { 0x1317, 0x9511, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
216 { 0x13D1, 0xAB02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
217 { 0x13D1, 0xAB03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
218 { 0x13D1, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
219 { 0x104A, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
220 { 0x104A, 0x2774, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
221 { 0x1259, 0xa120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
222 { 0x11F6, 0x9881, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMPEX9881 },
223 { 0x8086, 0x0039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, I21145 },
224 { 0x1282, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DM910X },
225 { 0x1282, 0x9102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DM910X },
226 { 0x1113, 0x1216, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
227 { 0x1113, 0x1217, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98715 },
228 { 0x1113, 0x9511, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
229 { 0x14f1, 0x1803, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CONEXANT },
230 { 0x1186, 0x1561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
231 { 0x1626, 0x8410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
232 { 0x1737, 0xAB09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
233 { 0x1737, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
234 { 0x17B3, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
235 { 0x10b9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DM910X }, /* ALi 1563 integrated ethernet */
236 { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */
237 { } /* terminate list */
239 MODULE_DEVICE_TABLE(pci, tulip_pci_tbl);
242 /* A full-duplex map for media types. */
243 const char tulip_media_cap[32] =
244 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 28,31,0,0, };
246 static void tulip_tx_timeout(struct net_device *dev);
247 static void tulip_init_ring(struct net_device *dev);
248 static int tulip_start_xmit(struct sk_buff *skb, struct net_device *dev);
249 static int tulip_open(struct net_device *dev);
250 static int tulip_close(struct net_device *dev);
251 static void tulip_up(struct net_device *dev);
252 static void tulip_down(struct net_device *dev);
253 static struct net_device_stats *tulip_get_stats(struct net_device *dev);
254 static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
255 static void set_rx_mode(struct net_device *dev);
256 #ifdef CONFIG_NET_POLL_CONTROLLER
257 static void poll_tulip(struct net_device *dev);
260 static void tulip_set_power_state (struct tulip_private *tp,
261 int sleep, int snooze)
263 if (tp->flags & HAS_ACPI) {
265 pci_read_config_dword (tp->pdev, CFDD, &tmp);
266 newtmp = tmp & ~(CFDD_Sleep | CFDD_Snooze);
268 newtmp |= CFDD_Sleep;
270 newtmp |= CFDD_Snooze;
272 pci_write_config_dword (tp->pdev, CFDD, newtmp);
278 static void tulip_up(struct net_device *dev)
280 struct tulip_private *tp = netdev_priv(dev);
281 long ioaddr = dev->base_addr;
282 int next_tick = 3*HZ;
285 /* Wake the chip from sleep/snooze mode. */
286 tulip_set_power_state (tp, 0, 0);
288 /* On some chip revs we must set the MII/SYM port before the reset!? */
289 if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii))
290 outl(0x00040000, ioaddr + CSR6);
292 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
293 outl(0x00000001, ioaddr + CSR0);
297 Wait the specified 50 PCI cycles after a reset by initializing
298 Tx and Rx queues and the address filter list. */
299 outl(tp->csr0, ioaddr + CSR0);
303 printk(KERN_DEBUG "%s: tulip_up(), irq==%d.\n", dev->name, dev->irq);
305 outl(tp->rx_ring_dma, ioaddr + CSR3);
306 outl(tp->tx_ring_dma, ioaddr + CSR4);
307 tp->cur_rx = tp->cur_tx = 0;
308 tp->dirty_rx = tp->dirty_tx = 0;
310 if (tp->flags & MC_HASH_ONLY) {
311 u32 addr_low = le32_to_cpu(get_unaligned((u32 *)dev->dev_addr));
312 u32 addr_high = le16_to_cpu(get_unaligned((u16 *)(dev->dev_addr+4)));
313 if (tp->chip_id == AX88140) {
314 outl(0, ioaddr + CSR13);
315 outl(addr_low, ioaddr + CSR14);
316 outl(1, ioaddr + CSR13);
317 outl(addr_high, ioaddr + CSR14);
318 } else if (tp->flags & COMET_MAC_ADDR) {
319 outl(addr_low, ioaddr + 0xA4);
320 outl(addr_high, ioaddr + 0xA8);
321 outl(0, ioaddr + 0xAC);
322 outl(0, ioaddr + 0xB0);
325 /* This is set_rx_mode(), but without starting the transmitter. */
326 u16 *eaddrs = (u16 *)dev->dev_addr;
327 u16 *setup_frm = &tp->setup_frame[15*6];
330 /* 21140 bug: you must add the broadcast address. */
331 memset(tp->setup_frame, 0xff, sizeof(tp->setup_frame));
332 /* Fill the final entry of the table with our physical address. */
333 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
334 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
335 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
337 mapping = pci_map_single(tp->pdev, tp->setup_frame,
338 sizeof(tp->setup_frame),
340 tp->tx_buffers[tp->cur_tx].skb = NULL;
341 tp->tx_buffers[tp->cur_tx].mapping = mapping;
343 /* Put the setup frame on the Tx list. */
344 tp->tx_ring[tp->cur_tx].length = cpu_to_le32(0x08000000 | 192);
345 tp->tx_ring[tp->cur_tx].buffer1 = cpu_to_le32(mapping);
346 tp->tx_ring[tp->cur_tx].status = cpu_to_le32(DescOwned);
351 tp->saved_if_port = dev->if_port;
352 if (dev->if_port == 0)
353 dev->if_port = tp->default_port;
355 /* Allow selecting a default media. */
357 if (tp->mtable == NULL)
360 int looking_for = tulip_media_cap[dev->if_port] & MediaIsMII ? 11 :
361 (dev->if_port == 12 ? 0 : dev->if_port);
362 for (i = 0; i < tp->mtable->leafcount; i++)
363 if (tp->mtable->mleaf[i].media == looking_for) {
364 printk(KERN_INFO "%s: Using user-specified media %s.\n",
365 dev->name, medianame[dev->if_port]);
369 if ((tp->mtable->defaultmedia & 0x0800) == 0) {
370 int looking_for = tp->mtable->defaultmedia & MEDIA_MASK;
371 for (i = 0; i < tp->mtable->leafcount; i++)
372 if (tp->mtable->mleaf[i].media == looking_for) {
373 printk(KERN_INFO "%s: Using EEPROM-set media %s.\n",
374 dev->name, medianame[looking_for]);
378 /* Start sensing first non-full-duplex media. */
379 for (i = tp->mtable->leafcount - 1;
380 (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
389 if (tp->chip_id == DC21143 &&
390 (tulip_media_cap[dev->if_port] & MediaIsMII)) {
391 /* We must reset the media CSRs when we force-select MII mode. */
392 outl(0x0000, ioaddr + CSR13);
393 outl(0x0000, ioaddr + CSR14);
394 outl(0x0008, ioaddr + CSR15);
396 tulip_select_media(dev, 1);
397 } else if (tp->chip_id == DC21142) {
399 tulip_select_media(dev, 1);
401 printk(KERN_INFO "%s: Using MII transceiver %d, status "
403 dev->name, tp->phys[0], tulip_mdio_read(dev, tp->phys[0], 1));
404 outl(csr6_mask_defstate, ioaddr + CSR6);
405 tp->csr6 = csr6_mask_hdcap;
407 outl(0x0000, ioaddr + CSR13);
408 outl(0x0000, ioaddr + CSR14);
410 t21142_start_nway(dev);
411 } else if (tp->chip_id == PNIC2) {
412 /* for initial startup advertise 10/100 Full and Half */
413 tp->sym_advertise = 0x01E0;
414 /* enable autonegotiate end interrupt */
415 outl(inl(ioaddr+CSR5)| 0x00008010, ioaddr + CSR5);
416 outl(inl(ioaddr+CSR7)| 0x00008010, ioaddr + CSR7);
417 pnic2_start_nway(dev);
418 } else if (tp->chip_id == LC82C168 && ! tp->medialock) {
421 tp->csr6 = 0x814C0000 | (tp->full_duplex ? 0x0200 : 0);
422 outl(0x0001, ioaddr + CSR15);
423 } else if (inl(ioaddr + CSR5) & TPLnkPass)
426 /* Start with 10mbps to do autonegotiation. */
427 outl(0x32, ioaddr + CSR12);
428 tp->csr6 = 0x00420000;
429 outl(0x0001B078, ioaddr + 0xB8);
430 outl(0x0201B078, ioaddr + 0xB8);
433 } else if ((tp->chip_id == MX98713 || tp->chip_id == COMPEX9881)
434 && ! tp->medialock) {
436 tp->csr6 = 0x01880000 | (tp->full_duplex ? 0x0200 : 0);
437 outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
438 } else if (tp->chip_id == MX98715 || tp->chip_id == MX98725) {
439 /* Provided by BOLO, Macronix - 12/10/1998. */
441 tp->csr6 = 0x01a80200;
442 outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80);
443 outl(0x11000 | inw(ioaddr + 0xa0), ioaddr + 0xa0);
444 } else if (tp->chip_id == COMET || tp->chip_id == CONEXANT) {
445 /* Enable automatic Tx underrun recovery. */
446 outl(inl(ioaddr + 0x88) | 1, ioaddr + 0x88);
447 dev->if_port = tp->mii_cnt ? 11 : 0;
448 tp->csr6 = 0x00040000;
449 } else if (tp->chip_id == AX88140) {
450 tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
452 tulip_select_media(dev, 1);
454 /* Start the chip's Tx to process setup frame. */
458 outl(tp->csr6 | TxOn, ioaddr + CSR6);
460 /* Enable interrupts by setting the interrupt mask. */
461 outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
462 outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
463 tulip_start_rxtx(tp);
464 outl(0, ioaddr + CSR2); /* Rx poll demand */
466 if (tulip_debug > 2) {
467 printk(KERN_DEBUG "%s: Done tulip_up(), CSR0 %8.8x, CSR5 %8.8x CSR6 %8.8x.\n",
468 dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR5),
472 /* Set the timer to switch to check for link beat and perhaps switch
473 to an alternate media type. */
474 tp->timer.expires = RUN_AT(next_tick);
475 add_timer(&tp->timer);
476 #ifdef CONFIG_TULIP_NAPI
477 init_timer(&tp->oom_timer);
478 tp->oom_timer.data = (unsigned long)dev;
479 tp->oom_timer.function = oom_timer;
484 tulip_open(struct net_device *dev)
488 if ((retval = request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)))
491 tulip_init_ring (dev);
495 netif_start_queue (dev);
501 static void tulip_tx_timeout(struct net_device *dev)
503 struct tulip_private *tp = netdev_priv(dev);
504 long ioaddr = dev->base_addr;
507 spin_lock_irqsave (&tp->lock, flags);
509 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
510 /* Do nothing -- the media monitor should handle this. */
512 printk(KERN_WARNING "%s: Transmit timeout using MII device.\n",
514 } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142
515 || tp->chip_id == MX98713 || tp->chip_id == COMPEX9881
516 || tp->chip_id == DM910X) {
517 printk(KERN_WARNING "%s: 21140 transmit timed out, status %8.8x, "
518 "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
519 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12),
520 inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15));
521 if ( ! tp->medialock && tp->mtable) {
524 while (tp->cur_index >= 0
525 && (tulip_media_cap[tp->mtable->mleaf[tp->cur_index].media]
527 if (--tp->cur_index < 0) {
528 /* We start again, but should instead look for default. */
529 tp->cur_index = tp->mtable->leafcount - 1;
531 tulip_select_media(dev, 0);
532 printk(KERN_WARNING "%s: transmit timed out, switching to %s "
533 "media.\n", dev->name, medianame[dev->if_port]);
535 } else if (tp->chip_id == PNIC2) {
536 printk(KERN_WARNING "%s: PNIC2 transmit timed out, status %8.8x, "
537 "CSR6/7 %8.8x / %8.8x CSR12 %8.8x, resetting...\n",
538 dev->name, (int)inl(ioaddr + CSR5), (int)inl(ioaddr + CSR6),
539 (int)inl(ioaddr + CSR7), (int)inl(ioaddr + CSR12));
541 printk(KERN_WARNING "%s: Transmit timed out, status %8.8x, CSR12 "
542 "%8.8x, resetting...\n",
543 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12));
547 #if defined(way_too_many_messages)
548 if (tulip_debug > 3) {
550 for (i = 0; i < RX_RING_SIZE; i++) {
551 u8 *buf = (u8 *)(tp->rx_ring[i].buffer1);
553 printk(KERN_DEBUG "%2d: %8.8x %8.8x %8.8x %8.8x "
554 "%2.2x %2.2x %2.2x.\n",
555 i, (unsigned int)tp->rx_ring[i].status,
556 (unsigned int)tp->rx_ring[i].length,
557 (unsigned int)tp->rx_ring[i].buffer1,
558 (unsigned int)tp->rx_ring[i].buffer2,
559 buf[0], buf[1], buf[2]);
560 for (j = 0; buf[j] != 0xee && j < 1600; j++)
561 if (j < 100) printk(" %2.2x", buf[j]);
562 printk(" j=%d.\n", j);
564 printk(KERN_DEBUG " Rx ring %8.8x: ", (int)tp->rx_ring);
565 for (i = 0; i < RX_RING_SIZE; i++)
566 printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
567 printk("\n" KERN_DEBUG " Tx ring %8.8x: ", (int)tp->tx_ring);
568 for (i = 0; i < TX_RING_SIZE; i++)
569 printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
574 /* Stop and restart the chip's Tx processes . */
576 tulip_restart_rxtx(tp);
577 /* Trigger an immediate transmit demand. */
578 outl(0, ioaddr + CSR1);
580 tp->stats.tx_errors++;
582 spin_unlock_irqrestore (&tp->lock, flags);
583 dev->trans_start = jiffies;
584 netif_wake_queue (dev);
588 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
589 static void tulip_init_ring(struct net_device *dev)
591 struct tulip_private *tp = netdev_priv(dev);
598 for (i = 0; i < RX_RING_SIZE; i++) {
599 tp->rx_ring[i].status = 0x00000000;
600 tp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ);
601 tp->rx_ring[i].buffer2 = cpu_to_le32(tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * (i + 1));
602 tp->rx_buffers[i].skb = NULL;
603 tp->rx_buffers[i].mapping = 0;
605 /* Mark the last entry as wrapping the ring. */
606 tp->rx_ring[i-1].length = cpu_to_le32(PKT_BUF_SZ | DESC_RING_WRAP);
607 tp->rx_ring[i-1].buffer2 = cpu_to_le32(tp->rx_ring_dma);
609 for (i = 0; i < RX_RING_SIZE; i++) {
612 /* Note the receive buffer must be longword aligned.
613 dev_alloc_skb() provides 16 byte alignment. But do *not*
614 use skb_reserve() to align the IP header! */
615 struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ);
616 tp->rx_buffers[i].skb = skb;
619 mapping = pci_map_single(tp->pdev, skb->tail,
620 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
621 tp->rx_buffers[i].mapping = mapping;
622 skb->dev = dev; /* Mark as being used by this device. */
623 tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */
624 tp->rx_ring[i].buffer1 = cpu_to_le32(mapping);
626 tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
628 /* The Tx buffer descriptor is filled in as needed, but we
629 do need to clear the ownership bit. */
630 for (i = 0; i < TX_RING_SIZE; i++) {
631 tp->tx_buffers[i].skb = NULL;
632 tp->tx_buffers[i].mapping = 0;
633 tp->tx_ring[i].status = 0x00000000;
634 tp->tx_ring[i].buffer2 = cpu_to_le32(tp->tx_ring_dma + sizeof(struct tulip_tx_desc) * (i + 1));
636 tp->tx_ring[i-1].buffer2 = cpu_to_le32(tp->tx_ring_dma);
640 tulip_start_xmit(struct sk_buff *skb, struct net_device *dev)
642 struct tulip_private *tp = netdev_priv(dev);
647 spin_lock_irq(&tp->lock);
649 /* Calculate the next Tx descriptor entry. */
650 entry = tp->cur_tx % TX_RING_SIZE;
652 tp->tx_buffers[entry].skb = skb;
653 mapping = pci_map_single(tp->pdev, skb->data,
654 skb->len, PCI_DMA_TODEVICE);
655 tp->tx_buffers[entry].mapping = mapping;
656 tp->tx_ring[entry].buffer1 = cpu_to_le32(mapping);
658 if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
659 flag = 0x60000000; /* No interrupt */
660 } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) {
661 flag = 0xe0000000; /* Tx-done intr. */
662 } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) {
663 flag = 0x60000000; /* No Tx-done intr. */
664 } else { /* Leave room for set_rx_mode() to fill entries. */
665 flag = 0xe0000000; /* Tx-done intr. */
666 netif_stop_queue(dev);
668 if (entry == TX_RING_SIZE-1)
669 flag = 0xe0000000 | DESC_RING_WRAP;
671 tp->tx_ring[entry].length = cpu_to_le32(skb->len | flag);
672 /* if we were using Transmit Automatic Polling, we would need a
674 tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
679 /* Trigger an immediate transmit demand. */
680 outl(0, dev->base_addr + CSR1);
682 spin_unlock_irq(&tp->lock);
684 dev->trans_start = jiffies;
689 static void tulip_clean_tx_ring(struct tulip_private *tp)
691 unsigned int dirty_tx;
693 for (dirty_tx = tp->dirty_tx ; tp->cur_tx - dirty_tx > 0;
695 int entry = dirty_tx % TX_RING_SIZE;
696 int status = le32_to_cpu(tp->tx_ring[entry].status);
699 tp->stats.tx_errors++; /* It wasn't Txed */
700 tp->tx_ring[entry].status = 0;
703 /* Check for Tx filter setup frames. */
704 if (tp->tx_buffers[entry].skb == NULL) {
705 /* test because dummy frames not mapped */
706 if (tp->tx_buffers[entry].mapping)
707 pci_unmap_single(tp->pdev,
708 tp->tx_buffers[entry].mapping,
709 sizeof(tp->setup_frame),
714 pci_unmap_single(tp->pdev, tp->tx_buffers[entry].mapping,
715 tp->tx_buffers[entry].skb->len,
718 /* Free the original skb. */
719 dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
720 tp->tx_buffers[entry].skb = NULL;
721 tp->tx_buffers[entry].mapping = 0;
725 static void tulip_down (struct net_device *dev)
727 long ioaddr = dev->base_addr;
728 struct tulip_private *tp = netdev_priv(dev);
731 del_timer_sync (&tp->timer);
732 #ifdef CONFIG_TULIP_NAPI
733 del_timer_sync (&tp->oom_timer);
735 spin_lock_irqsave (&tp->lock, flags);
737 /* Disable interrupts by clearing the interrupt mask. */
738 outl (0x00000000, ioaddr + CSR7);
740 /* Stop the Tx and Rx processes. */
743 /* prepare receive buffers */
744 tulip_refill_rx(dev);
746 /* release any unconsumed transmit buffers */
747 tulip_clean_tx_ring(tp);
749 if (inl (ioaddr + CSR6) != 0xffffffff)
750 tp->stats.rx_missed_errors += inl (ioaddr + CSR8) & 0xffff;
752 spin_unlock_irqrestore (&tp->lock, flags);
754 init_timer(&tp->timer);
755 tp->timer.data = (unsigned long)dev;
756 tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
758 dev->if_port = tp->saved_if_port;
760 /* Leave the driver in snooze, not sleep, mode. */
761 tulip_set_power_state (tp, 0, 1);
765 static int tulip_close (struct net_device *dev)
767 long ioaddr = dev->base_addr;
768 struct tulip_private *tp = netdev_priv(dev);
771 netif_stop_queue (dev);
776 printk (KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
777 dev->name, inl (ioaddr + CSR5));
779 free_irq (dev->irq, dev);
781 /* Free all the skbuffs in the Rx queue. */
782 for (i = 0; i < RX_RING_SIZE; i++) {
783 struct sk_buff *skb = tp->rx_buffers[i].skb;
784 dma_addr_t mapping = tp->rx_buffers[i].mapping;
786 tp->rx_buffers[i].skb = NULL;
787 tp->rx_buffers[i].mapping = 0;
789 tp->rx_ring[i].status = 0; /* Not owned by Tulip chip. */
790 tp->rx_ring[i].length = 0;
791 tp->rx_ring[i].buffer1 = 0xBADF00D0; /* An invalid address. */
793 pci_unmap_single(tp->pdev, mapping, PKT_BUF_SZ,
798 for (i = 0; i < TX_RING_SIZE; i++) {
799 struct sk_buff *skb = tp->tx_buffers[i].skb;
802 pci_unmap_single(tp->pdev, tp->tx_buffers[i].mapping,
803 skb->len, PCI_DMA_TODEVICE);
806 tp->tx_buffers[i].skb = NULL;
807 tp->tx_buffers[i].mapping = 0;
813 static struct net_device_stats *tulip_get_stats(struct net_device *dev)
815 struct tulip_private *tp = netdev_priv(dev);
816 long ioaddr = dev->base_addr;
818 if (netif_running(dev)) {
821 spin_lock_irqsave (&tp->lock, flags);
823 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
825 spin_unlock_irqrestore(&tp->lock, flags);
832 static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr)
834 struct tulip_private *np = netdev_priv(dev);
837 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
841 case ETHTOOL_GDRVINFO: {
842 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
843 strcpy(info.driver, DRV_NAME);
844 strcpy(info.version, DRV_VERSION);
845 strcpy(info.bus_info, pci_name(np->pdev));
846 if (copy_to_user(useraddr, &info, sizeof(info)))
856 /* Provide ioctl() calls to examine the MII xcvr state. */
857 static int private_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
859 struct tulip_private *tp = netdev_priv(dev);
860 long ioaddr = dev->base_addr;
861 struct mii_ioctl_data *data = (struct mii_ioctl_data *) & rq->ifr_data;
862 const unsigned int phy_idx = 0;
863 int phy = tp->phys[phy_idx] & 0x1f;
864 unsigned int regnum = data->reg_num;
868 return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
870 case SIOCGMIIPHY: /* Get address of MII PHY in use. */
873 else if (tp->flags & HAS_NWAY)
875 else if (tp->chip_id == COMET)
880 case SIOCGMIIREG: /* Read MII PHY register. */
881 if (data->phy_id == 32 && (tp->flags & HAS_NWAY)) {
882 int csr12 = inl (ioaddr + CSR12);
883 int csr14 = inl (ioaddr + CSR14);
886 if (((csr14<<5) & 0x1000) ||
887 (dev->if_port == 5 && tp->nwayset))
888 data->val_out = 0x1000;
890 data->val_out = (tulip_media_cap[dev->if_port]&MediaIs100 ? 0x2000 : 0)
891 | (tulip_media_cap[dev->if_port]&MediaIsFD ? 0x0100 : 0);
896 ((csr12&0x7000) == 0x5000 ? 0x20 : 0) +
897 ((csr12&0x06) == 6 ? 0 : 4);
898 data->val_out |= 0x6048;
901 /* Advertised value, bogus 10baseTx-FD value from CSR6. */
903 ((inl(ioaddr + CSR6) >> 3) & 0x0040) +
904 ((csr14 >> 1) & 0x20) + 1;
905 data->val_out |= ((csr14 >> 9) & 0x03C0);
907 case 5: data->val_out = tp->lpar; break;
908 default: data->val_out = 0; break;
911 data->val_out = tulip_mdio_read (dev, data->phy_id & 0x1f, regnum);
915 case SIOCSMIIREG: /* Write MII PHY register. */
916 if (!capable (CAP_NET_ADMIN))
920 if (data->phy_id == phy) {
921 u16 value = data->val_in;
923 case 0: /* Check for autonegotiation on or reset. */
924 tp->full_duplex_lock = (value & 0x9000) ? 0 : 1;
925 if (tp->full_duplex_lock)
926 tp->full_duplex = (value & 0x0100) ? 1 : 0;
929 tp->advertising[phy_idx] =
930 tp->mii_advertise = data->val_in;
934 if (data->phy_id == 32 && (tp->flags & HAS_NWAY)) {
935 u16 value = data->val_in;
937 if ((value & 0x1200) == 0x1200) {
938 if (tp->chip_id == PNIC2) {
939 pnic2_start_nway (dev);
941 t21142_start_nway (dev);
944 } else if (regnum == 4)
945 tp->sym_advertise = value;
947 tulip_mdio_write (dev, data->phy_id & 0x1f, regnum, data->val_in);
958 /* Set or clear the multicast filter for this adaptor.
959 Note that we only use exclusion around actually queueing the
960 new frame, not around filling tp->setup_frame. This is non-deterministic
961 when re-entered but still correct. */
964 #define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0)
966 static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
968 struct tulip_private *tp = netdev_priv(dev);
970 struct dev_mc_list *mclist;
974 memset(hash_table, 0, sizeof(hash_table));
975 set_bit_le(255, hash_table); /* Broadcast entry */
976 /* This should work on big-endian machines as well. */
977 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
978 i++, mclist = mclist->next) {
979 int index = ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff;
981 set_bit_le(index, hash_table);
984 for (i = 0; i < 32; i++) {
985 *setup_frm++ = hash_table[i];
986 *setup_frm++ = hash_table[i];
988 setup_frm = &tp->setup_frame[13*6];
990 /* Fill the final entry with our physical address. */
991 eaddrs = (u16 *)dev->dev_addr;
992 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
993 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
994 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
997 static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
999 struct tulip_private *tp = netdev_priv(dev);
1000 struct dev_mc_list *mclist;
1004 /* We have <= 14 addresses so we can use the wonderful
1005 16 address perfect filtering of the Tulip. */
1006 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
1007 i++, mclist = mclist->next) {
1008 eaddrs = (u16 *)mclist->dmi_addr;
1009 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1010 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1011 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1013 /* Fill the unused entries with the broadcast address. */
1014 memset(setup_frm, 0xff, (15-i)*12);
1015 setup_frm = &tp->setup_frame[15*6];
1017 /* Fill the final entry with our physical address. */
1018 eaddrs = (u16 *)dev->dev_addr;
1019 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
1020 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
1021 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
1025 static void set_rx_mode(struct net_device *dev)
1027 struct tulip_private *tp = netdev_priv(dev);
1028 long ioaddr = dev->base_addr;
1031 csr6 = inl(ioaddr + CSR6) & ~0x00D5;
1033 tp->csr6 &= ~0x00D5;
1034 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
1035 tp->csr6 |= AcceptAllMulticast | AcceptAllPhys;
1036 csr6 |= AcceptAllMulticast | AcceptAllPhys;
1037 /* Unconditionally log net taps. */
1038 printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name);
1039 } else if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) {
1040 /* Too many to filter well -- accept all multicasts. */
1041 tp->csr6 |= AcceptAllMulticast;
1042 csr6 |= AcceptAllMulticast;
1043 } else if (tp->flags & MC_HASH_ONLY) {
1044 /* Some work-alikes have only a 64-entry hash filter table. */
1045 /* Should verify correctness on big-endian/__powerpc__ */
1046 struct dev_mc_list *mclist;
1048 if (dev->mc_count > 64) { /* Arbitrary non-effective limit. */
1049 tp->csr6 |= AcceptAllMulticast;
1050 csr6 |= AcceptAllMulticast;
1052 u32 mc_filter[2] = {0, 0}; /* Multicast hash filter */
1054 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1055 i++, mclist = mclist->next) {
1056 if (tp->flags & COMET_MAC_ADDR)
1057 filterbit = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
1059 filterbit = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
1061 mc_filter[filterbit >> 5] |= cpu_to_le32(1 << (filterbit & 31));
1062 if (tulip_debug > 2) {
1063 printk(KERN_INFO "%s: Added filter for %2.2x:%2.2x:%2.2x:"
1064 "%2.2x:%2.2x:%2.2x %8.8x bit %d.\n", dev->name,
1065 mclist->dmi_addr[0], mclist->dmi_addr[1],
1066 mclist->dmi_addr[2], mclist->dmi_addr[3],
1067 mclist->dmi_addr[4], mclist->dmi_addr[5],
1068 ether_crc(ETH_ALEN, mclist->dmi_addr), filterbit);
1071 if (mc_filter[0] == tp->mc_filter[0] &&
1072 mc_filter[1] == tp->mc_filter[1])
1074 else if (tp->flags & IS_ASIX) {
1075 outl(2, ioaddr + CSR13);
1076 outl(mc_filter[0], ioaddr + CSR14);
1077 outl(3, ioaddr + CSR13);
1078 outl(mc_filter[1], ioaddr + CSR14);
1079 } else if (tp->flags & COMET_MAC_ADDR) {
1080 outl(mc_filter[0], ioaddr + 0xAC);
1081 outl(mc_filter[1], ioaddr + 0xB0);
1083 tp->mc_filter[0] = mc_filter[0];
1084 tp->mc_filter[1] = mc_filter[1];
1087 unsigned long flags;
1088 u32 tx_flags = 0x08000000 | 192;
1090 /* Note that only the low-address shortword of setup_frame is valid!
1091 The values are doubled for big-endian architectures. */
1092 if (dev->mc_count > 14) { /* Must use a multicast hash table. */
1093 build_setup_frame_hash(tp->setup_frame, dev);
1094 tx_flags = 0x08400000 | 192;
1096 build_setup_frame_perfect(tp->setup_frame, dev);
1099 spin_lock_irqsave(&tp->lock, flags);
1101 if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
1102 /* Same setup recently queued, we need not add it. */
1107 /* Now add this frame to the Tx list. */
1109 entry = tp->cur_tx++ % TX_RING_SIZE;
1112 /* Avoid a chip errata by prefixing a dummy entry. */
1113 tp->tx_buffers[entry].skb = NULL;
1114 tp->tx_buffers[entry].mapping = 0;
1115 tp->tx_ring[entry].length =
1116 (entry == TX_RING_SIZE-1) ? cpu_to_le32(DESC_RING_WRAP) : 0;
1117 tp->tx_ring[entry].buffer1 = 0;
1118 /* Must set DescOwned later to avoid race with chip */
1120 entry = tp->cur_tx++ % TX_RING_SIZE;
1123 tp->tx_buffers[entry].skb = NULL;
1124 tp->tx_buffers[entry].mapping =
1125 pci_map_single(tp->pdev, tp->setup_frame,
1126 sizeof(tp->setup_frame),
1128 /* Put the setup frame on the Tx list. */
1129 if (entry == TX_RING_SIZE-1)
1130 tx_flags |= DESC_RING_WRAP; /* Wrap ring. */
1131 tp->tx_ring[entry].length = cpu_to_le32(tx_flags);
1132 tp->tx_ring[entry].buffer1 =
1133 cpu_to_le32(tp->tx_buffers[entry].mapping);
1134 tp->tx_ring[entry].status = cpu_to_le32(DescOwned);
1136 tp->tx_ring[dummy].status = cpu_to_le32(DescOwned);
1137 if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2)
1138 netif_stop_queue(dev);
1140 /* Trigger an immediate transmit demand. */
1141 outl(0, ioaddr + CSR1);
1144 spin_unlock_irqrestore(&tp->lock, flags);
1147 outl(csr6, ioaddr + CSR6);
1150 #ifdef CONFIG_TULIP_MWI
1151 static void __devinit tulip_mwi_config (struct pci_dev *pdev,
1152 struct net_device *dev)
1154 struct tulip_private *tp = netdev_priv(dev);
1159 if (tulip_debug > 3)
1160 printk(KERN_DEBUG "%s: tulip_mwi_config()\n", pci_name(pdev));
1162 tp->csr0 = csr0 = 0;
1164 /* if we have any cache line size at all, we can do MRM */
1167 /* ...and barring hardware bugs, MWI */
1168 if (!(tp->chip_id == DC21143 && tp->revision == 65))
1171 /* set or disable MWI in the standard PCI command bit.
1172 * Check for the case where mwi is desired but not available
1174 if (csr0 & MWI) pci_set_mwi(pdev);
1175 else pci_clear_mwi(pdev);
1177 /* read result from hardware (in case bit refused to enable) */
1178 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
1179 if ((csr0 & MWI) && (!(pci_command & PCI_COMMAND_INVALIDATE)))
1182 /* if cache line size hardwired to zero, no MWI */
1183 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache);
1184 if ((csr0 & MWI) && (cache == 0)) {
1186 pci_clear_mwi(pdev);
1189 /* assign per-cacheline-size cache alignment and
1190 * burst length values
1194 csr0 |= MRL | (1 << CALShift) | (16 << BurstLenShift);
1197 csr0 |= MRL | (2 << CALShift) | (16 << BurstLenShift);
1200 csr0 |= MRL | (3 << CALShift) | (32 << BurstLenShift);
1207 /* if we have a good cache line size, we by now have a good
1208 * csr0, so save it and exit
1213 /* we don't have a good csr0 or cache line size, disable MWI */
1215 pci_clear_mwi(pdev);
1219 /* sane defaults for burst length and cache alignment
1220 * originally from de4x5 driver
1222 csr0 |= (8 << BurstLenShift) | (1 << CALShift);
1226 if (tulip_debug > 2)
1227 printk(KERN_DEBUG "%s: MWI config cacheline=%d, csr0=%08x\n",
1228 pci_name(pdev), cache, csr0);
1232 static int __devinit tulip_init_one (struct pci_dev *pdev,
1233 const struct pci_device_id *ent)
1235 struct tulip_private *tp;
1236 /* See note below on the multiport cards. */
1237 static unsigned char last_phys_addr[6] = {0x00, 'L', 'i', 'n', 'u', 'x'};
1238 static int last_irq;
1239 static int multiport_cnt; /* For four-port boards w/one EEPROM */
1243 unsigned char *ee_data;
1244 struct net_device *dev;
1246 static int board_idx = -1;
1247 int chip_idx = ent->driver_data;
1248 unsigned int eeprom_missing = 0;
1249 unsigned int force_csr0 = 0;
1252 static int did_version; /* Already printed version info. */
1253 if (tulip_debug > 0 && did_version++ == 0)
1254 printk (KERN_INFO "%s", version);
1260 * Lan media wire a tulip chip to a wan interface. Needs a very
1261 * different driver (lmc driver)
1264 if (pdev->subsystem_vendor == PCI_VENDOR_ID_LMC) {
1265 printk (KERN_ERR PFX "skipping LMC card.\n");
1270 * Early DM9100's need software CRC and the DMFE driver
1273 if (pdev->vendor == 0x1282 && pdev->device == 0x9100)
1276 /* Read Chip revision */
1277 pci_read_config_dword(pdev, PCI_REVISION_ID, &dev_rev);
1278 if(dev_rev < 0x02000030)
1280 printk(KERN_ERR PFX "skipping early DM9100 with Crc bug (use dmfe)\n");
1286 * Looks for early PCI chipsets where people report hangs
1287 * without the workarounds being on.
1290 /* Intel Saturn. Switch to 8 long words burst, 8 long word cache aligned
1291 Aries might need this too. The Saturn errata are not pretty reading but
1292 thankfully it's an old 486 chipset.
1295 if (pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82424, NULL)) {
1296 csr0 = MRL | MRM | (8 << BurstLenShift) | (1 << CALShift);
1299 /* The dreaded SiS496 486 chipset. Same workaround as above. */
1300 if (pci_find_device(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, NULL)) {
1301 csr0 = MRL | MRM | (8 << BurstLenShift) | (1 << CALShift);
1305 /* bugfix: the ASIX must have a burst limit or horrible things happen. */
1306 if (chip_idx == AX88140) {
1307 if ((csr0 & 0x3f00) == 0)
1311 /* PNIC doesn't have MWI/MRL/MRM... */
1312 if (chip_idx == LC82C168)
1313 csr0 &= ~0xfff10000; /* zero reserved bits 31:20, 16 */
1315 /* DM9102A has troubles with MRM & clear reserved bits 24:22, 20, 16, 7:1 */
1316 if ((pdev->vendor == 0x1282 && pdev->device == 0x9102)
1317 || (pdev->vendor == 0x10b9 && pdev->device == 0x5261))
1318 csr0 &= ~0x01f100ff;
1320 #if defined(__sparc__)
1321 /* DM9102A needs 32-dword alignment/burst length on sparc - chip bug? */
1322 if ((pdev->vendor == 0x1282 && pdev->device == 0x9102)
1323 || (pdev->vendor == 0x10b9 && pdev->device == 0x5261))
1324 csr0 = (csr0 & ~0xff00) | 0xe000;
1328 * And back to business
1331 i = pci_enable_device(pdev);
1333 printk (KERN_ERR PFX
1334 "Cannot enable tulip board #%d, aborting\n",
1339 ioaddr = pci_resource_start (pdev, 0);
1342 /* alloc_etherdev ensures aligned and zeroed private structures */
1343 dev = alloc_etherdev (sizeof (*tp));
1345 printk (KERN_ERR PFX "ether device alloc failed, aborting\n");
1349 SET_MODULE_OWNER(dev);
1350 SET_NETDEV_DEV(dev, &pdev->dev);
1351 if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) {
1352 printk (KERN_ERR PFX "%s: I/O region (0x%lx@0x%lx) too small, "
1353 "aborting\n", pci_name(pdev),
1354 pci_resource_len (pdev, 0),
1355 pci_resource_start (pdev, 0));
1356 goto err_out_free_netdev;
1359 /* grab all resources from both PIO and MMIO regions, as we
1360 * don't want anyone else messing around with our hardware */
1361 if (pci_request_regions (pdev, "tulip"))
1362 goto err_out_free_netdev;
1365 ioaddr = (unsigned long) ioremap (pci_resource_start (pdev, 1),
1366 tulip_tbl[chip_idx].io_size);
1368 goto err_out_free_res;
1371 pci_read_config_byte (pdev, PCI_REVISION_ID, &chip_rev);
1374 * initialize private data structure 'tp'
1375 * it is zeroed and aligned in alloc_etherdev
1377 tp = netdev_priv(dev);
1379 tp->rx_ring = pci_alloc_consistent(pdev,
1380 sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
1381 sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
1384 goto err_out_mtable;
1385 tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
1386 tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE;
1388 tp->chip_id = chip_idx;
1389 tp->flags = tulip_tbl[chip_idx].flags;
1391 tp->base_addr = ioaddr;
1392 tp->revision = chip_rev;
1394 spin_lock_init(&tp->lock);
1395 spin_lock_init(&tp->mii_lock);
1396 init_timer(&tp->timer);
1397 tp->timer.data = (unsigned long)dev;
1398 tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
1400 dev->base_addr = ioaddr;
1402 #ifdef CONFIG_TULIP_MWI
1403 if (!force_csr0 && (tp->flags & HAS_PCI_MWI))
1404 tulip_mwi_config (pdev, dev);
1406 /* MWI is broken for DC21143 rev 65... */
1407 if (chip_idx == DC21143 && chip_rev == 65)
1411 /* Stop the chip's Tx and Rx processes. */
1412 tulip_stop_rxtx(tp);
1414 pci_set_master(pdev);
1416 /* Clear the missed-packet counter. */
1419 /* The station address ROM is read byte serially. The register must
1420 be polled, waiting for the value to be read bit serially from the
1423 ee_data = tp->eeprom;
1425 if (chip_idx == LC82C168) {
1426 for (i = 0; i < 3; i++) {
1427 int value, boguscnt = 100000;
1428 outl(0x600 | i, ioaddr + 0x98);
1430 value = inl(ioaddr + CSR9);
1431 while (value < 0 && --boguscnt > 0);
1432 put_unaligned(le16_to_cpu(value), ((u16*)dev->dev_addr) + i);
1433 sum += value & 0xffff;
1435 } else if (chip_idx == COMET) {
1436 /* No need to read the EEPROM. */
1437 put_unaligned(cpu_to_le32(inl(ioaddr + 0xA4)), (u32 *)dev->dev_addr);
1438 put_unaligned(cpu_to_le16(inl(ioaddr + 0xA8)), (u16 *)(dev->dev_addr + 4));
1439 for (i = 0; i < 6; i ++)
1440 sum += dev->dev_addr[i];
1442 /* A serial EEPROM interface, we read now and sort it out later. */
1444 int ee_addr_size = tulip_read_eeprom(ioaddr, 0xff, 8) & 0x40000 ? 8 : 6;
1446 for (i = 0; i < sizeof(tp->eeprom)/2; i++)
1447 ((u16 *)ee_data)[i] =
1448 le16_to_cpu(tulip_read_eeprom(ioaddr, i, ee_addr_size));
1450 /* DEC now has a specification (see Notes) but early board makers
1451 just put the address in the first EEPROM locations. */
1452 /* This does memcmp(ee_data, ee_data+16, 8) */
1453 for (i = 0; i < 8; i ++)
1454 if (ee_data[i] != ee_data[16+i])
1456 if (chip_idx == CONEXANT) {
1457 /* Check that the tuple type and length is correct. */
1458 if (ee_data[0x198] == 0x04 && ee_data[0x199] == 6)
1460 } else if (ee_data[0] == 0xff && ee_data[1] == 0xff &&
1462 sa_offset = 2; /* Grrr, damn Matrox boards. */
1465 #ifdef CONFIG_DDB5476
1466 if ((pdev->bus->number == 0) && (PCI_SLOT(pdev->devfn) == 6)) {
1467 /* DDB5476 MAC address in first EEPROM locations. */
1469 /* No media table either */
1470 tp->flags &= ~HAS_MEDIA_TABLE;
1473 #ifdef CONFIG_DDB5477
1474 if ((pdev->bus->number == 0) && (PCI_SLOT(pdev->devfn) == 4)) {
1475 /* DDB5477 MAC address in first EEPROM locations. */
1477 /* No media table either */
1478 tp->flags &= ~HAS_MEDIA_TABLE;
1481 #ifdef CONFIG_MIPS_COBALT
1482 if ((pdev->bus->number == 0) &&
1483 ((PCI_SLOT(pdev->devfn) == 7) ||
1484 (PCI_SLOT(pdev->devfn) == 12))) {
1485 /* Cobalt MAC address in first EEPROM locations. */
1487 /* No media table either */
1488 tp->flags &= ~HAS_MEDIA_TABLE;
1492 /* 3x5 HSC (J3514A) has a broken srom */
1493 if(ee_data[0] == 0x61 && ee_data[1] == 0x10) {
1494 /* pci_vendor_id and subsystem_id are swapped */
1495 ee_data[0] = ee_data[2];
1496 ee_data[1] = ee_data[3];
1500 /* srom need to be byte-swaped and shifted up 1 word.
1501 * This shift needs to happen at the end of the MAC
1502 * first because of the 2 byte overlap.
1504 for(i = 4; i >= 0; i -= 2) {
1505 ee_data[17 + i + 3] = ee_data[17 + i];
1506 ee_data[16 + i + 5] = ee_data[16 + i];
1510 for (i = 0; i < 6; i ++) {
1511 dev->dev_addr[i] = ee_data[i + sa_offset];
1512 sum += ee_data[i + sa_offset];
1515 /* Lite-On boards have the address byte-swapped. */
1516 if ((dev->dev_addr[0] == 0xA0 || dev->dev_addr[0] == 0xC0)
1517 && dev->dev_addr[1] == 0x00)
1518 for (i = 0; i < 6; i+=2) {
1519 char tmp = dev->dev_addr[i];
1520 dev->dev_addr[i] = dev->dev_addr[i+1];
1521 dev->dev_addr[i+1] = tmp;
1523 /* On the Zynx 315 Etherarray and other multiport boards only the
1524 first Tulip has an EEPROM.
1525 On Sparc systems the mac address is held in the OBP property
1526 "local-mac-address".
1527 The addresses of the subsequent ports are derived from the first.
1528 Many PCI BIOSes also incorrectly report the IRQ line, so we correct
1529 that here as well. */
1530 if (sum == 0 || sum == 6*0xff) {
1531 #if defined(__sparc__)
1532 struct pcidev_cookie *pcp = pdev->sysdata;
1535 for (i = 0; i < 5; i++)
1536 dev->dev_addr[i] = last_phys_addr[i];
1537 dev->dev_addr[i] = last_phys_addr[i] + 1;
1538 #if defined(__sparc__)
1539 if ((pcp != NULL) && prom_getproplen(pcp->prom_node,
1540 "local-mac-address") == 6) {
1541 prom_getproperty(pcp->prom_node, "local-mac-address",
1545 #if defined(__i386__) /* Patch up x86 BIOS bug. */
1551 for (i = 0; i < 6; i++)
1552 last_phys_addr[i] = dev->dev_addr[i];
1556 /* The lower four bits are the media type. */
1557 if (board_idx >= 0 && board_idx < MAX_UNITS) {
1558 if (options[board_idx] & MEDIA_MASK)
1559 tp->default_port = options[board_idx] & MEDIA_MASK;
1560 if ((options[board_idx] & FullDuplex) || full_duplex[board_idx] > 0)
1561 tp->full_duplex = 1;
1562 if (mtu[board_idx] > 0)
1563 dev->mtu = mtu[board_idx];
1565 if (dev->mem_start & MEDIA_MASK)
1566 tp->default_port = dev->mem_start & MEDIA_MASK;
1567 if (tp->default_port) {
1568 printk(KERN_INFO "tulip%d: Transceiver selection forced to %s.\n",
1569 board_idx, medianame[tp->default_port & MEDIA_MASK]);
1571 if (tulip_media_cap[tp->default_port] & MediaAlwaysFD)
1572 tp->full_duplex = 1;
1574 if (tp->full_duplex)
1575 tp->full_duplex_lock = 1;
1577 if (tulip_media_cap[tp->default_port] & MediaIsMII) {
1578 u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
1579 tp->mii_advertise = media2advert[tp->default_port - 9];
1580 tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */
1583 if (tp->flags & HAS_MEDIA_TABLE) {
1584 sprintf(dev->name, "tulip%d", board_idx); /* hack */
1585 tulip_parse_eeprom(dev);
1586 strcpy(dev->name, "eth%d"); /* un-hack */
1589 if ((tp->flags & ALWAYS_CHECK_MII) ||
1590 (tp->mtable && tp->mtable->has_mii) ||
1591 ( ! tp->mtable && (tp->flags & HAS_MII))) {
1592 if (tp->mtable && tp->mtable->has_mii) {
1593 for (i = 0; i < tp->mtable->leafcount; i++)
1594 if (tp->mtable->mleaf[i].media == 11) {
1596 tp->saved_if_port = dev->if_port;
1597 tulip_select_media(dev, 2);
1598 dev->if_port = tp->saved_if_port;
1603 /* Find the connected MII xcvrs.
1604 Doing this in open() would allow detecting external xcvrs
1605 later, but takes much time. */
1606 tulip_find_mii (dev, board_idx);
1609 /* The Tulip-specific entries in the device structure. */
1610 dev->open = tulip_open;
1611 dev->hard_start_xmit = tulip_start_xmit;
1612 dev->tx_timeout = tulip_tx_timeout;
1613 dev->watchdog_timeo = TX_TIMEOUT;
1614 #ifdef CONFIG_TULIP_NAPI
1615 dev->poll = tulip_poll;
1618 dev->stop = tulip_close;
1619 dev->get_stats = tulip_get_stats;
1620 dev->do_ioctl = private_ioctl;
1621 dev->set_multicast_list = set_rx_mode;
1622 #ifdef CONFIG_NET_POLL_CONTROLLER
1623 dev->poll_controller = &poll_tulip;
1626 if (register_netdev(dev))
1627 goto err_out_free_ring;
1629 printk(KERN_INFO "%s: %s rev %d at %#3lx,",
1630 dev->name, tulip_tbl[chip_idx].chip_name, chip_rev, ioaddr);
1631 pci_set_drvdata(pdev, dev);
1634 printk(" EEPROM not present,");
1635 for (i = 0; i < 6; i++)
1636 printk("%c%2.2X", i ? ':' : ' ', dev->dev_addr[i]);
1637 printk(", IRQ %d.\n", irq);
1639 if (tp->chip_id == PNIC2)
1640 tp->link_change = pnic2_lnk_change;
1641 else if (tp->flags & HAS_NWAY)
1642 tp->link_change = t21142_lnk_change;
1643 else if (tp->flags & HAS_PNICNWAY)
1644 tp->link_change = pnic_lnk_change;
1646 /* Reset the xcvr interface and turn on heartbeat. */
1652 outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12);
1655 if (tp->mii_cnt || tulip_media_cap[dev->if_port] & MediaIsMII) {
1656 outl(csr6_mask_defstate, ioaddr + CSR6);
1657 outl(0x0000, ioaddr + CSR13);
1658 outl(0x0000, ioaddr + CSR14);
1659 outl(csr6_mask_hdcap, ioaddr + CSR6);
1661 t21142_start_nway(dev);
1664 /* just do a reset for sanity sake */
1665 outl(0x0000, ioaddr + CSR13);
1666 outl(0x0000, ioaddr + CSR14);
1669 if ( ! tp->mii_cnt) {
1672 outl(csr6_ttm | csr6_ca, ioaddr + CSR6);
1673 outl(0x30, ioaddr + CSR12);
1674 outl(0x0001F078, ioaddr + CSR6);
1675 outl(0x0201F078, ioaddr + CSR6); /* Turn on autonegotiation. */
1680 outl(0x00000000, ioaddr + CSR6);
1681 outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */
1682 outl(0x00000001, ioaddr + CSR13);
1686 outl(0x01a80000, ioaddr + CSR6);
1687 outl(0xFFFFFFFF, ioaddr + CSR14);
1688 outl(0x00001000, ioaddr + CSR12);
1691 /* No initialization necessary. */
1695 /* put the chip in snooze mode until opened */
1696 tulip_set_power_state (tp, 0, 1);
1701 pci_free_consistent (pdev,
1702 sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
1703 sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
1704 tp->rx_ring, tp->rx_ring_dma);
1710 iounmap((void *)ioaddr);
1714 pci_release_regions (pdev);
1716 err_out_free_netdev:
1724 static int tulip_suspend (struct pci_dev *pdev, u32 state)
1726 struct net_device *dev = pci_get_drvdata(pdev);
1728 if (dev && netif_running (dev) && netif_device_present (dev)) {
1729 netif_device_detach (dev);
1731 /* pci_power_off(pdev, -1); */
1737 static int tulip_resume(struct pci_dev *pdev)
1739 struct net_device *dev = pci_get_drvdata(pdev);
1741 if (dev && netif_running (dev) && !netif_device_present (dev)) {
1743 pci_enable_device (pdev);
1745 /* pci_power_on(pdev); */
1747 netif_device_attach (dev);
1752 #endif /* CONFIG_PM */
1755 static void __devexit tulip_remove_one (struct pci_dev *pdev)
1757 struct net_device *dev = pci_get_drvdata (pdev);
1758 struct tulip_private *tp;
1763 tp = netdev_priv(dev);
1764 unregister_netdev(dev);
1765 pci_free_consistent (pdev,
1766 sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
1767 sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
1768 tp->rx_ring, tp->rx_ring_dma);
1772 iounmap((void *)dev->base_addr);
1775 pci_release_regions (pdev);
1776 pci_set_drvdata (pdev, NULL);
1778 /* pci_power_off (pdev, -1); */
1781 #ifdef CONFIG_NET_POLL_CONTROLLER
1783 * Polling 'interrupt' - used by things like netconsole to send skbs
1784 * without having to re-enable interrupts. It's not called while
1785 * the interrupt routine is executing.
1788 static void poll_tulip (struct net_device *dev)
1790 /* disable_irq here is not very nice, but with the lockless
1791 interrupt handler we have no other choice. */
1792 disable_irq(dev->irq);
1793 tulip_interrupt (dev->irq, dev, NULL);
1794 enable_irq(dev->irq);
1798 static struct pci_driver tulip_driver = {
1800 .id_table = tulip_pci_tbl,
1801 .probe = tulip_init_one,
1802 .remove = __devexit_p(tulip_remove_one),
1804 .suspend = tulip_suspend,
1805 .resume = tulip_resume,
1806 #endif /* CONFIG_PM */
1810 static int __init tulip_init (void)
1813 printk (KERN_INFO "%s", version);
1816 /* copy module parms into globals */
1817 tulip_rx_copybreak = rx_copybreak;
1818 tulip_max_interrupt_work = max_interrupt_work;
1820 /* probe for and init boards */
1821 return pci_module_init (&tulip_driver);
1825 static void __exit tulip_cleanup (void)
1827 pci_unregister_driver (&tulip_driver);
1831 module_init(tulip_init);
1832 module_exit(tulip_cleanup);