1 /* de2104x.c: A Linux PCI Ethernet driver for Intel/Digital 21040/1 chips. */
3 Copyright 2001,2003 Jeff Garzik <jgarzik@pobox.com>
5 Copyright 1994, 1995 Digital Equipment Corporation. [de4x5.c]
6 Written/copyright 1994-2001 by Donald Becker. [tulip.c]
8 This software may be used and distributed according to the terms of
9 the GNU General Public License (GPL), incorporated herein by reference.
10 Drivers based on or derived from this code fall under the GPL and must
11 retain the authorship, copyright and license notice. This file is not
12 a complete program and may only be used when the entire operating
13 system is licensed under the GPL.
15 See the file COPYING in this distribution for more information.
17 TODO, in rough priority order:
18 * Support forcing media type with a module parameter,
19 like dl2k.c/sundance.c
20 * Constants (module parms?) for Rx work limit
21 * Complete reset on PciErr
22 * Jumbo frames / dev->change_mtu
23 * Adjust Rx FIFO threshold and Max Rx DMA burst on Rx FIFO error
24 * Adjust Tx FIFO threshold and Max Tx DMA burst on Tx FIFO error
25 * Implement Tx software interrupt mitigation via
30 #define DRV_NAME "de2104x"
31 #define DRV_VERSION "0.7"
32 #define DRV_RELDATE "Mar 17, 2004"
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/init.h>
39 #include <linux/pci.h>
40 #include <linux/delay.h>
41 #include <linux/ethtool.h>
42 #include <linux/compiler.h>
43 #include <linux/rtnetlink.h>
44 #include <linux/crc32.h>
45 #include <linux/slab.h>
49 #include <asm/uaccess.h>
50 #include <asm/unaligned.h>
52 /* These identify the driver base version and may not be removed. */
53 static char version
[] =
54 KERN_INFO DRV_NAME
" PCI Ethernet driver v" DRV_VERSION
" (" DRV_RELDATE
")\n";
56 MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
57 MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver");
58 MODULE_LICENSE("GPL");
59 MODULE_VERSION(DRV_VERSION
);
61 static int debug
= -1;
62 module_param (debug
, int, 0);
63 MODULE_PARM_DESC (debug
, "de2104x bitmapped message enable number");
65 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
66 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
67 defined(CONFIG_SPARC) || defined(__ia64__) || \
68 defined(__sh__) || defined(__mips__)
69 static int rx_copybreak
= 1518;
71 static int rx_copybreak
= 100;
73 module_param (rx_copybreak
, int, 0);
74 MODULE_PARM_DESC (rx_copybreak
, "de2104x Breakpoint at which Rx packets are copied");
76 #define PFX DRV_NAME ": "
78 #define DE_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
86 /* Descriptor skip length in 32 bit longwords. */
87 #ifndef CONFIG_DE2104X_DSL
90 #define DSL CONFIG_DE2104X_DSL
93 #define DE_RX_RING_SIZE 64
94 #define DE_TX_RING_SIZE 64
95 #define DE_RING_BYTES \
96 ((sizeof(struct de_desc) * DE_RX_RING_SIZE) + \
97 (sizeof(struct de_desc) * DE_TX_RING_SIZE))
98 #define NEXT_TX(N) (((N) + 1) & (DE_TX_RING_SIZE - 1))
99 #define NEXT_RX(N) (((N) + 1) & (DE_RX_RING_SIZE - 1))
100 #define TX_BUFFS_AVAIL(CP) \
101 (((CP)->tx_tail <= (CP)->tx_head) ? \
102 (CP)->tx_tail + (DE_TX_RING_SIZE - 1) - (CP)->tx_head : \
103 (CP)->tx_tail - (CP)->tx_head - 1)
105 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
108 #define DE_SETUP_SKB ((struct sk_buff *) 1)
109 #define DE_DUMMY_SKB ((struct sk_buff *) 2)
110 #define DE_SETUP_FRAME_WORDS 96
111 #define DE_EEPROM_WORDS 256
112 #define DE_EEPROM_SIZE (DE_EEPROM_WORDS * sizeof(u16))
113 #define DE_MAX_MEDIA 5
115 #define DE_MEDIA_TP_AUTO 0
116 #define DE_MEDIA_BNC 1
117 #define DE_MEDIA_AUI 2
118 #define DE_MEDIA_TP 3
119 #define DE_MEDIA_TP_FD 4
120 #define DE_MEDIA_INVALID DE_MAX_MEDIA
121 #define DE_MEDIA_FIRST 0
122 #define DE_MEDIA_LAST (DE_MAX_MEDIA - 1)
123 #define DE_AUI_BNC (SUPPORTED_AUI | SUPPORTED_BNC)
125 #define DE_TIMER_LINK (60 * HZ)
126 #define DE_TIMER_NO_LINK (5 * HZ)
128 #define DE_NUM_REGS 16
129 #define DE_REGS_SIZE (DE_NUM_REGS * sizeof(u32))
130 #define DE_REGS_VER 1
132 /* Time in jiffies before concluding the transmitter is hung. */
133 #define TX_TIMEOUT (6*HZ)
135 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
136 to support a pre-NWay full-duplex signaling mechanism using short frames.
137 No one knows what it should be, but if left at its default value some
138 10base2(!) packets trigger a full-duplex-request interrupt. */
139 #define FULL_DUPLEX_MAGIC 0x6969
162 CacheAlign16
= 0x00008000,
163 BurstLen4
= 0x00000400,
164 DescSkipLen
= (DSL
<< 2),
167 NormalTxPoll
= (1 << 0),
168 NormalRxPoll
= (1 << 0),
170 /* Tx/Rx descriptor status bits */
173 RxErrLong
= (1 << 7),
175 RxErrFIFO
= (1 << 0),
176 RxErrRunt
= (1 << 11),
177 RxErrFrame
= (1 << 14),
179 FirstFrag
= (1 << 29),
180 LastFrag
= (1 << 30),
182 TxFIFOUnder
= (1 << 1),
183 TxLinkFail
= (1 << 2) | (1 << 10) | (1 << 11),
186 TxJabber
= (1 << 14),
187 SetupFrame
= (1 << 27),
198 TxState
= (1 << 22) | (1 << 21) | (1 << 20),
199 RxState
= (1 << 19) | (1 << 18) | (1 << 17),
200 LinkFail
= (1 << 12),
202 RxStopped
= (1 << 8),
203 TxStopped
= (1 << 1),
206 TxEnable
= (1 << 13),
208 RxTx
= TxEnable
| RxEnable
,
209 FullDuplex
= (1 << 9),
210 AcceptAllMulticast
= (1 << 7),
211 AcceptAllPhys
= (1 << 6),
213 MacModeClear
= (1<<12) | (1<<11) | (1<<10) | (1<<8) | (1<<3) |
214 RxTx
| BOCnt
| AcceptAllPhys
| AcceptAllMulticast
,
217 EE_SHIFT_CLK
= 0x02, /* EEPROM shift clock. */
218 EE_CS
= 0x01, /* EEPROM chip select. */
219 EE_DATA_WRITE
= 0x04, /* Data from the Tulip to EEPROM. */
222 EE_DATA_READ
= 0x08, /* Data from the EEPROM chip. */
223 EE_ENB
= (0x4800 | EE_CS
),
225 /* The EEPROM commands include the alway-set leading bit. */
229 RxMissedOver
= (1 << 16),
230 RxMissedMask
= 0xffff,
232 /* SROM-related bits */
234 MediaBlockMask
= 0x3f,
235 MediaCustomCSRs
= (1 << 6),
238 PM_Sleep
= (1 << 31),
239 PM_Snooze
= (1 << 30),
240 PM_Mask
= PM_Sleep
| PM_Snooze
,
243 NWayState
= (1 << 14) | (1 << 13) | (1 << 12),
244 NWayRestart
= (1 << 12),
245 NonselPortActive
= (1 << 9),
246 SelPortActive
= (1 << 8),
247 LinkFailStatus
= (1 << 2),
248 NetCxnErr
= (1 << 1),
251 static const u32 de_intr_mask
=
252 IntrOK
| IntrErr
| RxIntr
| RxEmpty
| TxIntr
| TxEmpty
|
253 LinkPass
| LinkFail
| PciErr
;
256 * Set the programmable burst length to 4 longwords for all:
257 * DMA errors result without these values. Cache align 16 long.
259 static const u32 de_bus_mode
= CacheAlign16
| BurstLen4
| DescSkipLen
;
261 struct de_srom_media_block
{
268 struct de_srom_info_leaf
{
285 u16 type
; /* DE_MEDIA_xxx */
302 struct net_device
*dev
;
305 struct de_desc
*rx_ring
;
306 struct de_desc
*tx_ring
;
307 struct ring_info tx_skb
[DE_TX_RING_SIZE
];
308 struct ring_info rx_skb
[DE_RX_RING_SIZE
];
314 struct net_device_stats net_stats
;
316 struct pci_dev
*pdev
;
318 u16 setup_frame
[DE_SETUP_FRAME_WORDS
];
323 struct media_info media
[DE_MAX_MEDIA
];
324 struct timer_list media_timer
;
328 unsigned de21040
: 1;
329 unsigned media_lock
: 1;
333 static void de_set_rx_mode (struct net_device
*dev
);
334 static void de_tx (struct de_private
*de
);
335 static void de_clean_rings (struct de_private
*de
);
336 static void de_media_interrupt (struct de_private
*de
, u32 status
);
337 static void de21040_media_timer (unsigned long data
);
338 static void de21041_media_timer (unsigned long data
);
339 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
);
342 static DEFINE_PCI_DEVICE_TABLE(de_pci_tbl
) = {
343 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP
,
344 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
345 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_PLUS
,
346 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
349 MODULE_DEVICE_TABLE(pci
, de_pci_tbl
);
351 static const char * const media_name
[DE_MAX_MEDIA
] = {
359 /* 21040 transceiver register settings:
360 * TP AUTO(unused), BNC(unused), AUI, TP, TP FD*/
361 static u16 t21040_csr13
[] = { 0, 0, 0x8F09, 0x8F01, 0x8F01, };
362 static u16 t21040_csr14
[] = { 0, 0, 0x0705, 0xFFFF, 0xFFFD, };
363 static u16 t21040_csr15
[] = { 0, 0, 0x0006, 0x0000, 0x0000, };
365 /* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/
366 static u16 t21041_csr13
[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
367 static u16 t21041_csr14
[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
368 /* If on-chip autonegotiation is broken, use half-duplex (FF3F) instead */
369 static u16 t21041_csr14_brk
[] = { 0xFF3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
370 static u16 t21041_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
373 #define dr32(reg) ioread32(de->regs + (reg))
374 #define dw32(reg, val) iowrite32((val), de->regs + (reg))
377 static void de_rx_err_acct (struct de_private
*de
, unsigned rx_tail
,
380 if (netif_msg_rx_err (de
))
382 "%s: rx err, slot %d status 0x%x len %d\n",
383 de
->dev
->name
, rx_tail
, status
, len
);
385 if ((status
& 0x38000300) != 0x0300) {
386 /* Ingore earlier buffers. */
387 if ((status
& 0xffff) != 0x7fff) {
388 if (netif_msg_rx_err(de
))
389 dev_warn(&de
->dev
->dev
,
390 "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
392 de
->net_stats
.rx_length_errors
++;
394 } else if (status
& RxError
) {
395 /* There was a fatal error. */
396 de
->net_stats
.rx_errors
++; /* end of a packet.*/
397 if (status
& 0x0890) de
->net_stats
.rx_length_errors
++;
398 if (status
& RxErrCRC
) de
->net_stats
.rx_crc_errors
++;
399 if (status
& RxErrFIFO
) de
->net_stats
.rx_fifo_errors
++;
403 static void de_rx (struct de_private
*de
)
405 unsigned rx_tail
= de
->rx_tail
;
406 unsigned rx_work
= DE_RX_RING_SIZE
;
413 struct sk_buff
*skb
, *copy_skb
;
414 unsigned copying_skb
, buflen
;
416 skb
= de
->rx_skb
[rx_tail
].skb
;
419 status
= le32_to_cpu(de
->rx_ring
[rx_tail
].opts1
);
420 if (status
& DescOwn
)
423 len
= ((status
>> 16) & 0x7ff) - 4;
424 mapping
= de
->rx_skb
[rx_tail
].mapping
;
426 if (unlikely(drop
)) {
427 de
->net_stats
.rx_dropped
++;
431 if (unlikely((status
& 0x38008300) != 0x0300)) {
432 de_rx_err_acct(de
, rx_tail
, status
, len
);
436 copying_skb
= (len
<= rx_copybreak
);
438 if (unlikely(netif_msg_rx_status(de
)))
439 printk(KERN_DEBUG
"%s: rx slot %d status 0x%x len %d copying? %d\n",
440 de
->dev
->name
, rx_tail
, status
, len
,
443 buflen
= copying_skb
? (len
+ RX_OFFSET
) : de
->rx_buf_sz
;
444 copy_skb
= dev_alloc_skb (buflen
);
445 if (unlikely(!copy_skb
)) {
446 de
->net_stats
.rx_dropped
++;
453 pci_unmap_single(de
->pdev
, mapping
,
454 buflen
, PCI_DMA_FROMDEVICE
);
458 de
->rx_skb
[rx_tail
].mapping
=
459 pci_map_single(de
->pdev
, copy_skb
->data
,
460 buflen
, PCI_DMA_FROMDEVICE
);
461 de
->rx_skb
[rx_tail
].skb
= copy_skb
;
463 pci_dma_sync_single_for_cpu(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
464 skb_reserve(copy_skb
, RX_OFFSET
);
465 skb_copy_from_linear_data(skb
, skb_put(copy_skb
, len
),
467 pci_dma_sync_single_for_device(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
469 /* We'll reuse the original ring buffer. */
473 skb
->protocol
= eth_type_trans (skb
, de
->dev
);
475 de
->net_stats
.rx_packets
++;
476 de
->net_stats
.rx_bytes
+= skb
->len
;
478 if (rc
== NET_RX_DROP
)
482 if (rx_tail
== (DE_RX_RING_SIZE
- 1))
483 de
->rx_ring
[rx_tail
].opts2
=
484 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
486 de
->rx_ring
[rx_tail
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
487 de
->rx_ring
[rx_tail
].addr1
= cpu_to_le32(mapping
);
489 de
->rx_ring
[rx_tail
].opts1
= cpu_to_le32(DescOwn
);
490 rx_tail
= NEXT_RX(rx_tail
);
494 dev_warn(&de
->dev
->dev
, "rx work limit reached\n");
496 de
->rx_tail
= rx_tail
;
499 static irqreturn_t
de_interrupt (int irq
, void *dev_instance
)
501 struct net_device
*dev
= dev_instance
;
502 struct de_private
*de
= netdev_priv(dev
);
505 status
= dr32(MacStatus
);
506 if ((!(status
& (IntrOK
|IntrErr
))) || (status
== 0xFFFF))
509 if (netif_msg_intr(de
))
510 printk(KERN_DEBUG
"%s: intr, status %08x mode %08x desc %u/%u/%u\n",
511 dev
->name
, status
, dr32(MacMode
),
512 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
514 dw32(MacStatus
, status
);
516 if (status
& (RxIntr
| RxEmpty
)) {
518 if (status
& RxEmpty
)
519 dw32(RxPoll
, NormalRxPoll
);
522 spin_lock(&de
->lock
);
524 if (status
& (TxIntr
| TxEmpty
))
527 if (status
& (LinkPass
| LinkFail
))
528 de_media_interrupt(de
, status
);
530 spin_unlock(&de
->lock
);
532 if (status
& PciErr
) {
535 pci_read_config_word(de
->pdev
, PCI_STATUS
, &pci_status
);
536 pci_write_config_word(de
->pdev
, PCI_STATUS
, pci_status
);
537 dev_err(&de
->dev
->dev
,
538 "PCI bus error, status=%08x, PCI status=%04x\n",
545 static void de_tx (struct de_private
*de
)
547 unsigned tx_head
= de
->tx_head
;
548 unsigned tx_tail
= de
->tx_tail
;
550 while (tx_tail
!= tx_head
) {
555 status
= le32_to_cpu(de
->tx_ring
[tx_tail
].opts1
);
556 if (status
& DescOwn
)
559 skb
= de
->tx_skb
[tx_tail
].skb
;
561 if (unlikely(skb
== DE_DUMMY_SKB
))
564 if (unlikely(skb
== DE_SETUP_SKB
)) {
565 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
566 sizeof(de
->setup_frame
), PCI_DMA_TODEVICE
);
570 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
571 skb
->len
, PCI_DMA_TODEVICE
);
573 if (status
& LastFrag
) {
574 if (status
& TxError
) {
575 if (netif_msg_tx_err(de
))
576 printk(KERN_DEBUG
"%s: tx err, status 0x%x\n",
577 de
->dev
->name
, status
);
578 de
->net_stats
.tx_errors
++;
580 de
->net_stats
.tx_window_errors
++;
581 if (status
& TxMaxCol
)
582 de
->net_stats
.tx_aborted_errors
++;
583 if (status
& TxLinkFail
)
584 de
->net_stats
.tx_carrier_errors
++;
585 if (status
& TxFIFOUnder
)
586 de
->net_stats
.tx_fifo_errors
++;
588 de
->net_stats
.tx_packets
++;
589 de
->net_stats
.tx_bytes
+= skb
->len
;
590 if (netif_msg_tx_done(de
))
591 printk(KERN_DEBUG
"%s: tx done, slot %d\n",
592 de
->dev
->name
, tx_tail
);
594 dev_kfree_skb_irq(skb
);
598 de
->tx_skb
[tx_tail
].skb
= NULL
;
600 tx_tail
= NEXT_TX(tx_tail
);
603 de
->tx_tail
= tx_tail
;
605 if (netif_queue_stopped(de
->dev
) && (TX_BUFFS_AVAIL(de
) > (DE_TX_RING_SIZE
/ 4)))
606 netif_wake_queue(de
->dev
);
609 static netdev_tx_t
de_start_xmit (struct sk_buff
*skb
,
610 struct net_device
*dev
)
612 struct de_private
*de
= netdev_priv(dev
);
613 unsigned int entry
, tx_free
;
614 u32 mapping
, len
, flags
= FirstFrag
| LastFrag
;
617 spin_lock_irq(&de
->lock
);
619 tx_free
= TX_BUFFS_AVAIL(de
);
621 netif_stop_queue(dev
);
622 spin_unlock_irq(&de
->lock
);
623 return NETDEV_TX_BUSY
;
629 txd
= &de
->tx_ring
[entry
];
632 mapping
= pci_map_single(de
->pdev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
633 if (entry
== (DE_TX_RING_SIZE
- 1))
635 if (!tx_free
|| (tx_free
== (DE_TX_RING_SIZE
/ 2)))
638 txd
->opts2
= cpu_to_le32(flags
);
639 txd
->addr1
= cpu_to_le32(mapping
);
641 de
->tx_skb
[entry
].skb
= skb
;
642 de
->tx_skb
[entry
].mapping
= mapping
;
645 txd
->opts1
= cpu_to_le32(DescOwn
);
648 de
->tx_head
= NEXT_TX(entry
);
649 if (netif_msg_tx_queued(de
))
650 printk(KERN_DEBUG
"%s: tx queued, slot %d, skblen %d\n",
651 dev
->name
, entry
, skb
->len
);
654 netif_stop_queue(dev
);
656 spin_unlock_irq(&de
->lock
);
658 /* Trigger an immediate transmit demand. */
659 dw32(TxPoll
, NormalTxPoll
);
664 /* Set or clear the multicast filter for this adaptor.
665 Note that we only use exclusion around actually queueing the
666 new frame, not around filling de->setup_frame. This is non-deterministic
667 when re-entered but still correct. */
670 #define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0)
672 static void build_setup_frame_hash(u16
*setup_frm
, struct net_device
*dev
)
674 struct de_private
*de
= netdev_priv(dev
);
676 struct netdev_hw_addr
*ha
;
680 memset(hash_table
, 0, sizeof(hash_table
));
681 set_bit_le(255, hash_table
); /* Broadcast entry */
682 /* This should work on big-endian machines as well. */
683 netdev_for_each_mc_addr(ha
, dev
) {
684 int index
= ether_crc_le(ETH_ALEN
, ha
->addr
) & 0x1ff;
686 set_bit_le(index
, hash_table
);
689 for (i
= 0; i
< 32; i
++) {
690 *setup_frm
++ = hash_table
[i
];
691 *setup_frm
++ = hash_table
[i
];
693 setup_frm
= &de
->setup_frame
[13*6];
695 /* Fill the final entry with our physical address. */
696 eaddrs
= (u16
*)dev
->dev_addr
;
697 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
698 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
699 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
702 static void build_setup_frame_perfect(u16
*setup_frm
, struct net_device
*dev
)
704 struct de_private
*de
= netdev_priv(dev
);
705 struct netdev_hw_addr
*ha
;
708 /* We have <= 14 addresses so we can use the wonderful
709 16 address perfect filtering of the Tulip. */
710 netdev_for_each_mc_addr(ha
, dev
) {
711 eaddrs
= (u16
*) ha
->addr
;
712 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
713 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
714 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
716 /* Fill the unused entries with the broadcast address. */
717 memset(setup_frm
, 0xff, (15 - netdev_mc_count(dev
)) * 12);
718 setup_frm
= &de
->setup_frame
[15*6];
720 /* Fill the final entry with our physical address. */
721 eaddrs
= (u16
*)dev
->dev_addr
;
722 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
723 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
724 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
728 static void __de_set_rx_mode (struct net_device
*dev
)
730 struct de_private
*de
= netdev_priv(dev
);
735 struct de_desc
*dummy_txd
= NULL
;
737 macmode
= dr32(MacMode
) & ~(AcceptAllMulticast
| AcceptAllPhys
);
739 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
740 macmode
|= AcceptAllMulticast
| AcceptAllPhys
;
744 if ((netdev_mc_count(dev
) > 1000) || (dev
->flags
& IFF_ALLMULTI
)) {
745 /* Too many to filter well -- accept all multicasts. */
746 macmode
|= AcceptAllMulticast
;
750 /* Note that only the low-address shortword of setup_frame is valid!
751 The values are doubled for big-endian architectures. */
752 if (netdev_mc_count(dev
) > 14) /* Must use a multicast hash table. */
753 build_setup_frame_hash (de
->setup_frame
, dev
);
755 build_setup_frame_perfect (de
->setup_frame
, dev
);
758 * Now add this frame to the Tx list.
763 /* Avoid a chip errata by prefixing a dummy entry. */
765 de
->tx_skb
[entry
].skb
= DE_DUMMY_SKB
;
767 dummy_txd
= &de
->tx_ring
[entry
];
768 dummy_txd
->opts2
= (entry
== (DE_TX_RING_SIZE
- 1)) ?
769 cpu_to_le32(RingEnd
) : 0;
770 dummy_txd
->addr1
= 0;
772 /* Must set DescOwned later to avoid race with chip */
774 entry
= NEXT_TX(entry
);
777 de
->tx_skb
[entry
].skb
= DE_SETUP_SKB
;
778 de
->tx_skb
[entry
].mapping
= mapping
=
779 pci_map_single (de
->pdev
, de
->setup_frame
,
780 sizeof (de
->setup_frame
), PCI_DMA_TODEVICE
);
782 /* Put the setup frame on the Tx list. */
783 txd
= &de
->tx_ring
[entry
];
784 if (entry
== (DE_TX_RING_SIZE
- 1))
785 txd
->opts2
= cpu_to_le32(SetupFrame
| RingEnd
| sizeof (de
->setup_frame
));
787 txd
->opts2
= cpu_to_le32(SetupFrame
| sizeof (de
->setup_frame
));
788 txd
->addr1
= cpu_to_le32(mapping
);
791 txd
->opts1
= cpu_to_le32(DescOwn
);
795 dummy_txd
->opts1
= cpu_to_le32(DescOwn
);
799 de
->tx_head
= NEXT_TX(entry
);
801 if (TX_BUFFS_AVAIL(de
) == 0)
802 netif_stop_queue(dev
);
804 /* Trigger an immediate transmit demand. */
805 dw32(TxPoll
, NormalTxPoll
);
808 if (macmode
!= dr32(MacMode
))
809 dw32(MacMode
, macmode
);
812 static void de_set_rx_mode (struct net_device
*dev
)
815 struct de_private
*de
= netdev_priv(dev
);
817 spin_lock_irqsave (&de
->lock
, flags
);
818 __de_set_rx_mode(dev
);
819 spin_unlock_irqrestore (&de
->lock
, flags
);
822 static inline void de_rx_missed(struct de_private
*de
, u32 rx_missed
)
824 if (unlikely(rx_missed
& RxMissedOver
))
825 de
->net_stats
.rx_missed_errors
+= RxMissedMask
;
827 de
->net_stats
.rx_missed_errors
+= (rx_missed
& RxMissedMask
);
830 static void __de_get_stats(struct de_private
*de
)
832 u32 tmp
= dr32(RxMissed
); /* self-clearing */
834 de_rx_missed(de
, tmp
);
837 static struct net_device_stats
*de_get_stats(struct net_device
*dev
)
839 struct de_private
*de
= netdev_priv(dev
);
841 /* The chip only need report frame silently dropped. */
842 spin_lock_irq(&de
->lock
);
843 if (netif_running(dev
) && netif_device_present(dev
))
845 spin_unlock_irq(&de
->lock
);
847 return &de
->net_stats
;
850 static inline int de_is_running (struct de_private
*de
)
852 return (dr32(MacStatus
) & (RxState
| TxState
)) ? 1 : 0;
855 static void de_stop_rxtx (struct de_private
*de
)
858 unsigned int i
= 1300/100;
860 macmode
= dr32(MacMode
);
861 if (macmode
& RxTx
) {
862 dw32(MacMode
, macmode
& ~RxTx
);
866 /* wait until in-flight frame completes.
867 * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
868 * Typically expect this loop to end in < 50 us on 100BT.
871 if (!de_is_running(de
))
876 dev_warn(&de
->dev
->dev
, "timeout expired stopping DMA\n");
879 static inline void de_start_rxtx (struct de_private
*de
)
883 macmode
= dr32(MacMode
);
884 if ((macmode
& RxTx
) != RxTx
) {
885 dw32(MacMode
, macmode
| RxTx
);
890 static void de_stop_hw (struct de_private
*de
)
898 dw32(MacStatus
, dr32(MacStatus
));
903 de
->tx_head
= de
->tx_tail
= 0;
906 static void de_link_up(struct de_private
*de
)
908 if (!netif_carrier_ok(de
->dev
)) {
909 netif_carrier_on(de
->dev
);
910 if (netif_msg_link(de
))
911 dev_info(&de
->dev
->dev
, "link up, media %s\n",
912 media_name
[de
->media_type
]);
916 static void de_link_down(struct de_private
*de
)
918 if (netif_carrier_ok(de
->dev
)) {
919 netif_carrier_off(de
->dev
);
920 if (netif_msg_link(de
))
921 dev_info(&de
->dev
->dev
, "link down\n");
925 static void de_set_media (struct de_private
*de
)
927 unsigned media
= de
->media_type
;
928 u32 macmode
= dr32(MacMode
);
930 if (de_is_running(de
))
931 dev_warn(&de
->dev
->dev
,
932 "chip is running while changing media!\n");
935 dw32(CSR11
, FULL_DUPLEX_MAGIC
);
936 dw32(CSR13
, 0); /* Reset phy */
937 dw32(CSR14
, de
->media
[media
].csr14
);
938 dw32(CSR15
, de
->media
[media
].csr15
);
939 dw32(CSR13
, de
->media
[media
].csr13
);
941 /* must delay 10ms before writing to other registers,
946 if (media
== DE_MEDIA_TP_FD
)
947 macmode
|= FullDuplex
;
949 macmode
&= ~FullDuplex
;
951 if (netif_msg_link(de
))
952 dev_info(&de
->dev
->dev
, "set link %s\n", media_name
[media
]);
953 if (netif_msg_hw(de
)) {
954 dev_info(&de
->dev
->dev
, "mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n",
955 dr32(MacMode
), dr32(SIAStatus
),
956 dr32(CSR13
), dr32(CSR14
), dr32(CSR15
));
958 dev_info(&de
->dev
->dev
,
959 "set mode 0x%x, set sia 0x%x,0x%x,0x%x\n",
960 macmode
, de
->media
[media
].csr13
,
961 de
->media
[media
].csr14
, de
->media
[media
].csr15
);
963 if (macmode
!= dr32(MacMode
))
964 dw32(MacMode
, macmode
);
967 static void de_next_media (struct de_private
*de
, const u32
*media
,
968 unsigned int n_media
)
972 for (i
= 0; i
< n_media
; i
++) {
973 if (de_ok_to_advertise(de
, media
[i
])) {
974 de
->media_type
= media
[i
];
980 static void de21040_media_timer (unsigned long data
)
982 struct de_private
*de
= (struct de_private
*) data
;
983 struct net_device
*dev
= de
->dev
;
984 u32 status
= dr32(SIAStatus
);
985 unsigned int carrier
;
988 carrier
= (status
& NetCxnErr
) ? 0 : 1;
991 if (de
->media_type
!= DE_MEDIA_AUI
&& (status
& LinkFailStatus
))
994 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
995 add_timer(&de
->media_timer
);
996 if (!netif_carrier_ok(dev
))
999 if (netif_msg_timer(de
))
1000 dev_info(&dev
->dev
, "%s link ok, status %x\n",
1001 media_name
[de
->media_type
], status
);
1010 if (de
->media_type
== DE_MEDIA_AUI
) {
1011 static const u32 next_state
= DE_MEDIA_TP
;
1012 de_next_media(de
, &next_state
, 1);
1014 static const u32 next_state
= DE_MEDIA_AUI
;
1015 de_next_media(de
, &next_state
, 1);
1018 spin_lock_irqsave(&de
->lock
, flags
);
1020 spin_unlock_irqrestore(&de
->lock
, flags
);
1025 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1026 add_timer(&de
->media_timer
);
1028 if (netif_msg_timer(de
))
1029 dev_info(&dev
->dev
, "no link, trying media %s, status %x\n",
1030 media_name
[de
->media_type
], status
);
1033 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
)
1035 switch (new_media
) {
1036 case DE_MEDIA_TP_AUTO
:
1037 if (!(de
->media_advertise
& ADVERTISED_Autoneg
))
1039 if (!(de
->media_advertise
& (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
)))
1043 if (!(de
->media_advertise
& ADVERTISED_BNC
))
1047 if (!(de
->media_advertise
& ADVERTISED_AUI
))
1051 if (!(de
->media_advertise
& ADVERTISED_10baseT_Half
))
1054 case DE_MEDIA_TP_FD
:
1055 if (!(de
->media_advertise
& ADVERTISED_10baseT_Full
))
1063 static void de21041_media_timer (unsigned long data
)
1065 struct de_private
*de
= (struct de_private
*) data
;
1066 struct net_device
*dev
= de
->dev
;
1067 u32 status
= dr32(SIAStatus
);
1068 unsigned int carrier
;
1069 unsigned long flags
;
1071 /* clear port active bits */
1072 dw32(SIAStatus
, NonselPortActive
| SelPortActive
);
1074 carrier
= (status
& NetCxnErr
) ? 0 : 1;
1077 if ((de
->media_type
== DE_MEDIA_TP_AUTO
||
1078 de
->media_type
== DE_MEDIA_TP
||
1079 de
->media_type
== DE_MEDIA_TP_FD
) &&
1080 (status
& LinkFailStatus
))
1083 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
1084 add_timer(&de
->media_timer
);
1085 if (!netif_carrier_ok(dev
))
1088 if (netif_msg_timer(de
))
1090 "%s link ok, mode %x status %x\n",
1091 media_name
[de
->media_type
],
1092 dr32(MacMode
), status
);
1098 /* if media type locked, don't switch media */
1102 /* if activity detected, use that as hint for new media type */
1103 if (status
& NonselPortActive
) {
1104 unsigned int have_media
= 1;
1106 /* if AUI/BNC selected, then activity is on TP port */
1107 if (de
->media_type
== DE_MEDIA_AUI
||
1108 de
->media_type
== DE_MEDIA_BNC
) {
1109 if (de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
))
1110 de
->media_type
= DE_MEDIA_TP_AUTO
;
1115 /* TP selected. If there is only TP and BNC, then it's BNC */
1116 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_BNC
) &&
1117 de_ok_to_advertise(de
, DE_MEDIA_BNC
))
1118 de
->media_type
= DE_MEDIA_BNC
;
1120 /* TP selected. If there is only TP and AUI, then it's AUI */
1121 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_AUI
) &&
1122 de_ok_to_advertise(de
, DE_MEDIA_AUI
))
1123 de
->media_type
= DE_MEDIA_AUI
;
1125 /* otherwise, ignore the hint */
1134 * Absent or ambiguous activity hint, move to next advertised
1135 * media state. If de->media_type is left unchanged, this
1136 * simply resets the PHY and reloads the current media settings.
1138 if (de
->media_type
== DE_MEDIA_AUI
) {
1139 static const u32 next_states
[] = {
1140 DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1142 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1143 } else if (de
->media_type
== DE_MEDIA_BNC
) {
1144 static const u32 next_states
[] = {
1145 DE_MEDIA_TP_AUTO
, DE_MEDIA_AUI
1147 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1149 static const u32 next_states
[] = {
1150 DE_MEDIA_AUI
, DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1152 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1156 spin_lock_irqsave(&de
->lock
, flags
);
1158 spin_unlock_irqrestore(&de
->lock
, flags
);
1163 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1164 add_timer(&de
->media_timer
);
1166 if (netif_msg_timer(de
))
1167 dev_info(&dev
->dev
, "no link, trying media %s, status %x\n",
1168 media_name
[de
->media_type
], status
);
1171 static void de_media_interrupt (struct de_private
*de
, u32 status
)
1173 if (status
& LinkPass
) {
1174 /* Ignore if current media is AUI or BNC and we can't use TP */
1175 if ((de
->media_type
== DE_MEDIA_AUI
||
1176 de
->media_type
== DE_MEDIA_BNC
) &&
1178 !de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
)))
1180 /* If current media is not TP, change it to TP */
1181 if ((de
->media_type
== DE_MEDIA_AUI
||
1182 de
->media_type
== DE_MEDIA_BNC
)) {
1183 de
->media_type
= DE_MEDIA_TP_AUTO
;
1189 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_LINK
);
1193 BUG_ON(!(status
& LinkFail
));
1194 /* Mark the link as down only if current media is TP */
1195 if (netif_carrier_ok(de
->dev
) && de
->media_type
!= DE_MEDIA_AUI
&&
1196 de
->media_type
!= DE_MEDIA_BNC
) {
1198 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1202 static int de_reset_mac (struct de_private
*de
)
1207 * Reset MAC. de4x5.c and tulip.c examined for "advice"
1211 if (dr32(BusMode
) == 0xffffffff)
1214 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1215 dw32 (BusMode
, CmdReset
);
1218 dw32 (BusMode
, de_bus_mode
);
1221 for (tmp
= 0; tmp
< 5; tmp
++) {
1228 status
= dr32(MacStatus
);
1229 if (status
& (RxState
| TxState
))
1231 if (status
== 0xffffffff)
1236 static void de_adapter_wake (struct de_private
*de
)
1243 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1244 if (pmctl
& PM_Mask
) {
1246 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1248 /* de4x5.c delays, so we do too */
1253 static void de_adapter_sleep (struct de_private
*de
)
1260 dw32(CSR13
, 0); /* Reset phy */
1261 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1263 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1266 static int de_init_hw (struct de_private
*de
)
1268 struct net_device
*dev
= de
->dev
;
1272 de_adapter_wake(de
);
1274 macmode
= dr32(MacMode
) & ~MacModeClear
;
1276 rc
= de_reset_mac(de
);
1280 de_set_media(de
); /* reset phy */
1282 dw32(RxRingAddr
, de
->ring_dma
);
1283 dw32(TxRingAddr
, de
->ring_dma
+ (sizeof(struct de_desc
) * DE_RX_RING_SIZE
));
1285 dw32(MacMode
, RxTx
| macmode
);
1287 dr32(RxMissed
); /* self-clearing */
1289 dw32(IntrMask
, de_intr_mask
);
1291 de_set_rx_mode(dev
);
1296 static int de_refill_rx (struct de_private
*de
)
1300 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1301 struct sk_buff
*skb
;
1303 skb
= dev_alloc_skb(de
->rx_buf_sz
);
1309 de
->rx_skb
[i
].mapping
= pci_map_single(de
->pdev
,
1310 skb
->data
, de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1311 de
->rx_skb
[i
].skb
= skb
;
1313 de
->rx_ring
[i
].opts1
= cpu_to_le32(DescOwn
);
1314 if (i
== (DE_RX_RING_SIZE
- 1))
1315 de
->rx_ring
[i
].opts2
=
1316 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
1318 de
->rx_ring
[i
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
1319 de
->rx_ring
[i
].addr1
= cpu_to_le32(de
->rx_skb
[i
].mapping
);
1320 de
->rx_ring
[i
].addr2
= 0;
1330 static int de_init_rings (struct de_private
*de
)
1332 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1333 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1336 de
->tx_head
= de
->tx_tail
= 0;
1338 return de_refill_rx (de
);
1341 static int de_alloc_rings (struct de_private
*de
)
1343 de
->rx_ring
= pci_alloc_consistent(de
->pdev
, DE_RING_BYTES
, &de
->ring_dma
);
1346 de
->tx_ring
= &de
->rx_ring
[DE_RX_RING_SIZE
];
1347 return de_init_rings(de
);
1350 static void de_clean_rings (struct de_private
*de
)
1354 memset(de
->rx_ring
, 0, sizeof(struct de_desc
) * DE_RX_RING_SIZE
);
1355 de
->rx_ring
[DE_RX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1357 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1358 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1361 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1362 if (de
->rx_skb
[i
].skb
) {
1363 pci_unmap_single(de
->pdev
, de
->rx_skb
[i
].mapping
,
1364 de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1365 dev_kfree_skb(de
->rx_skb
[i
].skb
);
1369 for (i
= 0; i
< DE_TX_RING_SIZE
; i
++) {
1370 struct sk_buff
*skb
= de
->tx_skb
[i
].skb
;
1371 if ((skb
) && (skb
!= DE_DUMMY_SKB
)) {
1372 if (skb
!= DE_SETUP_SKB
) {
1373 de
->net_stats
.tx_dropped
++;
1374 pci_unmap_single(de
->pdev
,
1375 de
->tx_skb
[i
].mapping
,
1376 skb
->len
, PCI_DMA_TODEVICE
);
1379 pci_unmap_single(de
->pdev
,
1380 de
->tx_skb
[i
].mapping
,
1381 sizeof(de
->setup_frame
),
1387 memset(&de
->rx_skb
, 0, sizeof(struct ring_info
) * DE_RX_RING_SIZE
);
1388 memset(&de
->tx_skb
, 0, sizeof(struct ring_info
) * DE_TX_RING_SIZE
);
1391 static void de_free_rings (struct de_private
*de
)
1394 pci_free_consistent(de
->pdev
, DE_RING_BYTES
, de
->rx_ring
, de
->ring_dma
);
1399 static int de_open (struct net_device
*dev
)
1401 struct de_private
*de
= netdev_priv(dev
);
1404 if (netif_msg_ifup(de
))
1405 printk(KERN_DEBUG
"%s: enabling interface\n", dev
->name
);
1407 de
->rx_buf_sz
= (dev
->mtu
<= 1500 ? PKT_BUF_SZ
: dev
->mtu
+ 32);
1409 rc
= de_alloc_rings(de
);
1411 dev_err(&dev
->dev
, "ring allocation failure, err=%d\n", rc
);
1417 rc
= request_irq(dev
->irq
, de_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
1419 dev_err(&dev
->dev
, "IRQ %d request failure, err=%d\n",
1424 rc
= de_init_hw(de
);
1426 dev_err(&dev
->dev
, "h/w init failure, err=%d\n", rc
);
1427 goto err_out_free_irq
;
1430 netif_start_queue(dev
);
1431 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1436 free_irq(dev
->irq
, dev
);
1442 static int de_close (struct net_device
*dev
)
1444 struct de_private
*de
= netdev_priv(dev
);
1445 unsigned long flags
;
1447 if (netif_msg_ifdown(de
))
1448 printk(KERN_DEBUG
"%s: disabling interface\n", dev
->name
);
1450 del_timer_sync(&de
->media_timer
);
1452 spin_lock_irqsave(&de
->lock
, flags
);
1454 netif_stop_queue(dev
);
1455 netif_carrier_off(dev
);
1456 spin_unlock_irqrestore(&de
->lock
, flags
);
1458 free_irq(dev
->irq
, dev
);
1461 de_adapter_sleep(de
);
1465 static void de_tx_timeout (struct net_device
*dev
)
1467 struct de_private
*de
= netdev_priv(dev
);
1469 printk(KERN_DEBUG
"%s: NIC status %08x mode %08x sia %08x desc %u/%u/%u\n",
1470 dev
->name
, dr32(MacStatus
), dr32(MacMode
), dr32(SIAStatus
),
1471 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
1473 del_timer_sync(&de
->media_timer
);
1475 disable_irq(dev
->irq
);
1476 spin_lock_irq(&de
->lock
);
1479 netif_stop_queue(dev
);
1480 netif_carrier_off(dev
);
1482 spin_unlock_irq(&de
->lock
);
1483 enable_irq(dev
->irq
);
1485 /* Update the error counts. */
1488 synchronize_irq(dev
->irq
);
1495 netif_wake_queue(dev
);
1498 static void __de_get_regs(struct de_private
*de
, u8
*buf
)
1501 u32
*rbuf
= (u32
*)buf
;
1504 for (i
= 0; i
< DE_NUM_REGS
; i
++)
1505 rbuf
[i
] = dr32(i
* 8);
1507 /* handle self-clearing RxMissed counter, CSR8 */
1508 de_rx_missed(de
, rbuf
[8]);
1511 static int __de_get_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1513 ecmd
->supported
= de
->media_supported
;
1514 ecmd
->transceiver
= XCVR_INTERNAL
;
1515 ecmd
->phy_address
= 0;
1516 ecmd
->advertising
= de
->media_advertise
;
1518 switch (de
->media_type
) {
1520 ecmd
->port
= PORT_AUI
;
1523 ecmd
->port
= PORT_BNC
;
1526 ecmd
->port
= PORT_TP
;
1530 ethtool_cmd_speed_set(ecmd
, 10);
1532 if (dr32(MacMode
) & FullDuplex
)
1533 ecmd
->duplex
= DUPLEX_FULL
;
1535 ecmd
->duplex
= DUPLEX_HALF
;
1538 ecmd
->autoneg
= AUTONEG_DISABLE
;
1540 ecmd
->autoneg
= AUTONEG_ENABLE
;
1542 /* ignore maxtxpkt, maxrxpkt for now */
1547 static int __de_set_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1550 unsigned int media_lock
;
1552 if (ethtool_cmd_speed(ecmd
) != 10)
1554 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
1556 if (ecmd
->port
!= PORT_TP
&& ecmd
->port
!= PORT_AUI
&& ecmd
->port
!= PORT_BNC
)
1558 if (de
->de21040
&& ecmd
->port
== PORT_BNC
)
1560 if (ecmd
->transceiver
!= XCVR_INTERNAL
)
1562 if (ecmd
->autoneg
!= AUTONEG_DISABLE
&& ecmd
->autoneg
!= AUTONEG_ENABLE
)
1564 if (ecmd
->advertising
& ~de
->media_supported
)
1566 if (ecmd
->autoneg
== AUTONEG_ENABLE
&&
1567 (!(ecmd
->advertising
& ADVERTISED_Autoneg
)))
1570 switch (ecmd
->port
) {
1572 new_media
= DE_MEDIA_AUI
;
1573 if (!(ecmd
->advertising
& ADVERTISED_AUI
))
1577 new_media
= DE_MEDIA_BNC
;
1578 if (!(ecmd
->advertising
& ADVERTISED_BNC
))
1582 if (ecmd
->autoneg
== AUTONEG_ENABLE
)
1583 new_media
= DE_MEDIA_TP_AUTO
;
1584 else if (ecmd
->duplex
== DUPLEX_FULL
)
1585 new_media
= DE_MEDIA_TP_FD
;
1587 new_media
= DE_MEDIA_TP
;
1588 if (!(ecmd
->advertising
& ADVERTISED_TP
))
1590 if (!(ecmd
->advertising
& (ADVERTISED_10baseT_Full
| ADVERTISED_10baseT_Half
)))
1595 media_lock
= (ecmd
->autoneg
== AUTONEG_ENABLE
) ? 0 : 1;
1597 if ((new_media
== de
->media_type
) &&
1598 (media_lock
== de
->media_lock
) &&
1599 (ecmd
->advertising
== de
->media_advertise
))
1600 return 0; /* nothing to change */
1603 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1606 de
->media_type
= new_media
;
1607 de
->media_lock
= media_lock
;
1608 de
->media_advertise
= ecmd
->advertising
;
1610 if (netif_running(de
->dev
))
1616 static void de_get_drvinfo (struct net_device
*dev
,struct ethtool_drvinfo
*info
)
1618 struct de_private
*de
= netdev_priv(dev
);
1620 strcpy (info
->driver
, DRV_NAME
);
1621 strcpy (info
->version
, DRV_VERSION
);
1622 strcpy (info
->bus_info
, pci_name(de
->pdev
));
1623 info
->eedump_len
= DE_EEPROM_SIZE
;
1626 static int de_get_regs_len(struct net_device
*dev
)
1628 return DE_REGS_SIZE
;
1631 static int de_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1633 struct de_private
*de
= netdev_priv(dev
);
1636 spin_lock_irq(&de
->lock
);
1637 rc
= __de_get_settings(de
, ecmd
);
1638 spin_unlock_irq(&de
->lock
);
1643 static int de_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1645 struct de_private
*de
= netdev_priv(dev
);
1648 spin_lock_irq(&de
->lock
);
1649 rc
= __de_set_settings(de
, ecmd
);
1650 spin_unlock_irq(&de
->lock
);
1655 static u32
de_get_msglevel(struct net_device
*dev
)
1657 struct de_private
*de
= netdev_priv(dev
);
1659 return de
->msg_enable
;
1662 static void de_set_msglevel(struct net_device
*dev
, u32 msglvl
)
1664 struct de_private
*de
= netdev_priv(dev
);
1666 de
->msg_enable
= msglvl
;
1669 static int de_get_eeprom(struct net_device
*dev
,
1670 struct ethtool_eeprom
*eeprom
, u8
*data
)
1672 struct de_private
*de
= netdev_priv(dev
);
1676 if ((eeprom
->offset
!= 0) || (eeprom
->magic
!= 0) ||
1677 (eeprom
->len
!= DE_EEPROM_SIZE
))
1679 memcpy(data
, de
->ee_data
, eeprom
->len
);
1684 static int de_nway_reset(struct net_device
*dev
)
1686 struct de_private
*de
= netdev_priv(dev
);
1689 if (de
->media_type
!= DE_MEDIA_TP_AUTO
)
1691 if (netif_carrier_ok(de
->dev
))
1694 status
= dr32(SIAStatus
);
1695 dw32(SIAStatus
, (status
& ~NWayState
) | NWayRestart
);
1696 if (netif_msg_link(de
))
1697 dev_info(&de
->dev
->dev
, "link nway restart, status %x,%x\n",
1698 status
, dr32(SIAStatus
));
1702 static void de_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
1705 struct de_private
*de
= netdev_priv(dev
);
1707 regs
->version
= (DE_REGS_VER
<< 2) | de
->de21040
;
1709 spin_lock_irq(&de
->lock
);
1710 __de_get_regs(de
, data
);
1711 spin_unlock_irq(&de
->lock
);
1714 static const struct ethtool_ops de_ethtool_ops
= {
1715 .get_link
= ethtool_op_get_link
,
1716 .get_drvinfo
= de_get_drvinfo
,
1717 .get_regs_len
= de_get_regs_len
,
1718 .get_settings
= de_get_settings
,
1719 .set_settings
= de_set_settings
,
1720 .get_msglevel
= de_get_msglevel
,
1721 .set_msglevel
= de_set_msglevel
,
1722 .get_eeprom
= de_get_eeprom
,
1723 .nway_reset
= de_nway_reset
,
1724 .get_regs
= de_get_regs
,
1727 static void __devinit
de21040_get_mac_address (struct de_private
*de
)
1731 dw32 (ROMCmd
, 0); /* Reset the pointer with a dummy write. */
1734 for (i
= 0; i
< 6; i
++) {
1735 int value
, boguscnt
= 100000;
1737 value
= dr32(ROMCmd
);
1739 } while (value
< 0 && --boguscnt
> 0);
1740 de
->dev
->dev_addr
[i
] = value
;
1743 pr_warning(PFX
"timeout reading 21040 MAC address byte %u\n", i
);
1747 static void __devinit
de21040_get_media_info(struct de_private
*de
)
1751 de
->media_type
= DE_MEDIA_TP
;
1752 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
|
1753 SUPPORTED_10baseT_Half
| SUPPORTED_AUI
;
1754 de
->media_advertise
= de
->media_supported
;
1756 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1760 case DE_MEDIA_TP_FD
:
1761 de
->media
[i
].type
= i
;
1762 de
->media
[i
].csr13
= t21040_csr13
[i
];
1763 de
->media
[i
].csr14
= t21040_csr14
[i
];
1764 de
->media
[i
].csr15
= t21040_csr15
[i
];
1767 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1773 /* Note: this routine returns extra data bits for size detection. */
1774 static unsigned __devinit
tulip_read_eeprom(void __iomem
*regs
, int location
, int addr_len
)
1777 unsigned retval
= 0;
1778 void __iomem
*ee_addr
= regs
+ ROMCmd
;
1779 int read_cmd
= location
| (EE_READ_CMD
<< addr_len
);
1781 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1782 writel(EE_ENB
, ee_addr
);
1784 /* Shift the read command bits out. */
1785 for (i
= 4 + addr_len
; i
>= 0; i
--) {
1786 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
1787 writel(EE_ENB
| dataval
, ee_addr
);
1789 writel(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
1791 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1793 writel(EE_ENB
, ee_addr
);
1796 for (i
= 16; i
> 0; i
--) {
1797 writel(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
1799 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1800 writel(EE_ENB
, ee_addr
);
1804 /* Terminate the EEPROM access. */
1805 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1809 static void __devinit
de21041_get_srom_info (struct de_private
*de
)
1811 unsigned i
, sa_offset
= 0, ofs
;
1812 u8 ee_data
[DE_EEPROM_SIZE
+ 6] = {};
1813 unsigned ee_addr_size
= tulip_read_eeprom(de
->regs
, 0xff, 8) & 0x40000 ? 8 : 6;
1814 struct de_srom_info_leaf
*il
;
1817 /* download entire eeprom */
1818 for (i
= 0; i
< DE_EEPROM_WORDS
; i
++)
1819 ((__le16
*)ee_data
)[i
] =
1820 cpu_to_le16(tulip_read_eeprom(de
->regs
, i
, ee_addr_size
));
1822 /* DEC now has a specification but early board makers
1823 just put the address in the first EEPROM locations. */
1824 /* This does memcmp(eedata, eedata+16, 8) */
1826 #ifndef CONFIG_MIPS_COBALT
1828 for (i
= 0; i
< 8; i
++)
1829 if (ee_data
[i
] != ee_data
[16+i
])
1834 /* store MAC address */
1835 for (i
= 0; i
< 6; i
++)
1836 de
->dev
->dev_addr
[i
] = ee_data
[i
+ sa_offset
];
1838 /* get offset of controller 0 info leaf. ignore 2nd byte. */
1839 ofs
= ee_data
[SROMC0InfoLeaf
];
1840 if (ofs
>= (sizeof(ee_data
) - sizeof(struct de_srom_info_leaf
) - sizeof(struct de_srom_media_block
)))
1843 /* get pointer to info leaf */
1844 il
= (struct de_srom_info_leaf
*) &ee_data
[ofs
];
1846 /* paranoia checks */
1847 if (il
->n_blocks
== 0)
1849 if ((sizeof(ee_data
) - ofs
) <
1850 (sizeof(struct de_srom_info_leaf
) + (sizeof(struct de_srom_media_block
) * il
->n_blocks
)))
1853 /* get default media type */
1854 switch (get_unaligned(&il
->default_media
)) {
1855 case 0x0001: de
->media_type
= DE_MEDIA_BNC
; break;
1856 case 0x0002: de
->media_type
= DE_MEDIA_AUI
; break;
1857 case 0x0204: de
->media_type
= DE_MEDIA_TP_FD
; break;
1858 default: de
->media_type
= DE_MEDIA_TP_AUTO
; break;
1861 if (netif_msg_probe(de
))
1862 pr_info("de%d: SROM leaf offset %u, default media %s\n",
1863 de
->board_idx
, ofs
, media_name
[de
->media_type
]);
1865 /* init SIA register values to defaults */
1866 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1867 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1868 de
->media
[i
].csr13
= 0xffff;
1869 de
->media
[i
].csr14
= 0xffff;
1870 de
->media
[i
].csr15
= 0xffff;
1873 /* parse media blocks to see what medias are supported,
1874 * and if any custom CSR values are provided
1876 bufp
= ((void *)il
) + sizeof(*il
);
1877 for (i
= 0; i
< il
->n_blocks
; i
++) {
1878 struct de_srom_media_block
*ib
= bufp
;
1881 /* index based on media type in media block */
1882 switch(ib
->opts
& MediaBlockMask
) {
1883 case 0: /* 10baseT */
1884 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Half
1885 | SUPPORTED_Autoneg
;
1887 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1890 de
->media_supported
|= SUPPORTED_BNC
;
1894 de
->media_supported
|= SUPPORTED_AUI
;
1897 case 4: /* 10baseT-FD */
1898 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
1899 | SUPPORTED_Autoneg
;
1900 idx
= DE_MEDIA_TP_FD
;
1901 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1907 de
->media
[idx
].type
= idx
;
1909 if (netif_msg_probe(de
))
1910 pr_info("de%d: media block #%u: %s",
1912 media_name
[de
->media
[idx
].type
]);
1914 bufp
+= sizeof (ib
->opts
);
1916 if (ib
->opts
& MediaCustomCSRs
) {
1917 de
->media
[idx
].csr13
= get_unaligned(&ib
->csr13
);
1918 de
->media
[idx
].csr14
= get_unaligned(&ib
->csr14
);
1919 de
->media
[idx
].csr15
= get_unaligned(&ib
->csr15
);
1920 bufp
+= sizeof(ib
->csr13
) + sizeof(ib
->csr14
) +
1923 if (netif_msg_probe(de
))
1924 pr_cont(" (%x,%x,%x)\n",
1925 de
->media
[idx
].csr13
,
1926 de
->media
[idx
].csr14
,
1927 de
->media
[idx
].csr15
);
1929 } else if (netif_msg_probe(de
))
1932 if (bufp
> ((void *)&ee_data
[DE_EEPROM_SIZE
- 3]))
1936 de
->media_advertise
= de
->media_supported
;
1939 /* fill in defaults, for cases where custom CSRs not used */
1940 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1941 if (de
->media
[i
].csr13
== 0xffff)
1942 de
->media
[i
].csr13
= t21041_csr13
[i
];
1943 if (de
->media
[i
].csr14
== 0xffff) {
1944 /* autonegotiation is broken at least on some chip
1945 revisions - rev. 0x21 works, 0x11 does not */
1946 if (de
->pdev
->revision
< 0x20)
1947 de
->media
[i
].csr14
= t21041_csr14_brk
[i
];
1949 de
->media
[i
].csr14
= t21041_csr14
[i
];
1951 if (de
->media
[i
].csr15
== 0xffff)
1952 de
->media
[i
].csr15
= t21041_csr15
[i
];
1955 de
->ee_data
= kmemdup(&ee_data
[0], DE_EEPROM_SIZE
, GFP_KERNEL
);
1960 /* for error cases, it's ok to assume we support all these */
1961 for (i
= 0; i
< DE_MAX_MEDIA
; i
++)
1962 de
->media
[i
].type
= i
;
1963 de
->media_supported
=
1964 SUPPORTED_10baseT_Half
|
1965 SUPPORTED_10baseT_Full
|
1973 static const struct net_device_ops de_netdev_ops
= {
1974 .ndo_open
= de_open
,
1975 .ndo_stop
= de_close
,
1976 .ndo_set_multicast_list
= de_set_rx_mode
,
1977 .ndo_start_xmit
= de_start_xmit
,
1978 .ndo_get_stats
= de_get_stats
,
1979 .ndo_tx_timeout
= de_tx_timeout
,
1980 .ndo_change_mtu
= eth_change_mtu
,
1981 .ndo_set_mac_address
= eth_mac_addr
,
1982 .ndo_validate_addr
= eth_validate_addr
,
1985 static int __devinit
de_init_one (struct pci_dev
*pdev
,
1986 const struct pci_device_id
*ent
)
1988 struct net_device
*dev
;
1989 struct de_private
*de
;
1992 unsigned long pciaddr
;
1993 static int board_idx
= -1;
1999 printk("%s", version
);
2002 /* allocate a new ethernet device structure, and fill in defaults */
2003 dev
= alloc_etherdev(sizeof(struct de_private
));
2007 dev
->netdev_ops
= &de_netdev_ops
;
2008 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2009 dev
->ethtool_ops
= &de_ethtool_ops
;
2010 dev
->watchdog_timeo
= TX_TIMEOUT
;
2012 de
= netdev_priv(dev
);
2013 de
->de21040
= ent
->driver_data
== 0 ? 1 : 0;
2016 de
->msg_enable
= (debug
< 0 ? DE_DEF_MSG_ENABLE
: debug
);
2017 de
->board_idx
= board_idx
;
2018 spin_lock_init (&de
->lock
);
2019 init_timer(&de
->media_timer
);
2021 de
->media_timer
.function
= de21040_media_timer
;
2023 de
->media_timer
.function
= de21041_media_timer
;
2024 de
->media_timer
.data
= (unsigned long) de
;
2026 netif_carrier_off(dev
);
2028 /* wake up device, assign resources */
2029 rc
= pci_enable_device(pdev
);
2033 /* reserve PCI resources to ensure driver atomicity */
2034 rc
= pci_request_regions(pdev
, DRV_NAME
);
2036 goto err_out_disable
;
2038 /* check for invalid IRQ value */
2039 if (pdev
->irq
< 2) {
2041 pr_err(PFX
"invalid irq (%d) for pci dev %s\n",
2042 pdev
->irq
, pci_name(pdev
));
2046 dev
->irq
= pdev
->irq
;
2048 /* obtain and check validity of PCI I/O address */
2049 pciaddr
= pci_resource_start(pdev
, 1);
2052 pr_err(PFX
"no MMIO resource for pci dev %s\n", pci_name(pdev
));
2055 if (pci_resource_len(pdev
, 1) < DE_REGS_SIZE
) {
2057 pr_err(PFX
"MMIO resource (%llx) too small on pci dev %s\n",
2058 (unsigned long long)pci_resource_len(pdev
, 1),
2063 /* remap CSR registers */
2064 regs
= ioremap_nocache(pciaddr
, DE_REGS_SIZE
);
2067 pr_err(PFX
"Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
2068 (unsigned long long)pci_resource_len(pdev
, 1),
2069 pciaddr
, pci_name(pdev
));
2072 dev
->base_addr
= (unsigned long) regs
;
2075 de_adapter_wake(de
);
2077 /* make sure hardware is not running */
2078 rc
= de_reset_mac(de
);
2080 pr_err(PFX
"Cannot reset MAC, pci dev %s\n", pci_name(pdev
));
2084 /* get MAC address, initialize default media type and
2085 * get list of supported media
2088 de21040_get_mac_address(de
);
2089 de21040_get_media_info(de
);
2091 de21041_get_srom_info(de
);
2094 /* register new network interface with kernel */
2095 rc
= register_netdev(dev
);
2099 /* print info about board and interface just registered */
2100 dev_info(&dev
->dev
, "%s at 0x%lx, %pM, IRQ %d\n",
2101 de
->de21040
? "21040" : "21041",
2106 pci_set_drvdata(pdev
, dev
);
2108 /* enable busmastering */
2109 pci_set_master(pdev
);
2111 /* put adapter to sleep */
2112 de_adapter_sleep(de
);
2120 pci_release_regions(pdev
);
2122 pci_disable_device(pdev
);
2128 static void __devexit
de_remove_one (struct pci_dev
*pdev
)
2130 struct net_device
*dev
= pci_get_drvdata(pdev
);
2131 struct de_private
*de
= netdev_priv(dev
);
2134 unregister_netdev(dev
);
2137 pci_release_regions(pdev
);
2138 pci_disable_device(pdev
);
2139 pci_set_drvdata(pdev
, NULL
);
2145 static int de_suspend (struct pci_dev
*pdev
, pm_message_t state
)
2147 struct net_device
*dev
= pci_get_drvdata (pdev
);
2148 struct de_private
*de
= netdev_priv(dev
);
2151 if (netif_running (dev
)) {
2152 del_timer_sync(&de
->media_timer
);
2154 disable_irq(dev
->irq
);
2155 spin_lock_irq(&de
->lock
);
2158 netif_stop_queue(dev
);
2159 netif_device_detach(dev
);
2160 netif_carrier_off(dev
);
2162 spin_unlock_irq(&de
->lock
);
2163 enable_irq(dev
->irq
);
2165 /* Update the error counts. */
2168 synchronize_irq(dev
->irq
);
2171 de_adapter_sleep(de
);
2172 pci_disable_device(pdev
);
2174 netif_device_detach(dev
);
2180 static int de_resume (struct pci_dev
*pdev
)
2182 struct net_device
*dev
= pci_get_drvdata (pdev
);
2183 struct de_private
*de
= netdev_priv(dev
);
2187 if (netif_device_present(dev
))
2189 if (!netif_running(dev
))
2191 if ((retval
= pci_enable_device(pdev
))) {
2192 dev_err(&dev
->dev
, "pci_enable_device failed in resume\n");
2195 pci_set_master(pdev
);
2199 netif_device_attach(dev
);
2205 #endif /* CONFIG_PM */
2207 static struct pci_driver de_driver
= {
2209 .id_table
= de_pci_tbl
,
2210 .probe
= de_init_one
,
2211 .remove
= __devexit_p(de_remove_one
),
2213 .suspend
= de_suspend
,
2214 .resume
= de_resume
,
2218 static int __init
de_init (void)
2221 printk("%s", version
);
2223 return pci_register_driver(&de_driver
);
2226 static void __exit
de_exit (void)
2228 pci_unregister_driver (&de_driver
);
2231 module_init(de_init
);
2232 module_exit(de_exit
);