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>
48 #include <asm/uaccess.h>
49 #include <asm/unaligned.h>
51 /* These identify the driver base version and may not be removed. */
52 static char version
[] =
53 KERN_INFO DRV_NAME
" PCI Ethernet driver v" DRV_VERSION
" (" DRV_RELDATE
")\n";
55 MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
56 MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver");
57 MODULE_LICENSE("GPL");
58 MODULE_VERSION(DRV_VERSION
);
60 static int debug
= -1;
61 module_param (debug
, int, 0);
62 MODULE_PARM_DESC (debug
, "de2104x bitmapped message enable number");
64 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
65 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
66 || defined(CONFIG_SPARC) || defined(__ia64__) \
67 || defined(__sh__) || defined(__mips__)
68 static int rx_copybreak
= 1518;
70 static int rx_copybreak
= 100;
72 module_param (rx_copybreak
, int, 0);
73 MODULE_PARM_DESC (rx_copybreak
, "de2104x Breakpoint at which Rx packets are copied");
75 #define PFX DRV_NAME ": "
77 #define DE_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
85 #define DE_RX_RING_SIZE 64
86 #define DE_TX_RING_SIZE 64
87 #define DE_RING_BYTES \
88 ((sizeof(struct de_desc) * DE_RX_RING_SIZE) + \
89 (sizeof(struct de_desc) * DE_TX_RING_SIZE))
90 #define NEXT_TX(N) (((N) + 1) & (DE_TX_RING_SIZE - 1))
91 #define NEXT_RX(N) (((N) + 1) & (DE_RX_RING_SIZE - 1))
92 #define TX_BUFFS_AVAIL(CP) \
93 (((CP)->tx_tail <= (CP)->tx_head) ? \
94 (CP)->tx_tail + (DE_TX_RING_SIZE - 1) - (CP)->tx_head : \
95 (CP)->tx_tail - (CP)->tx_head - 1)
97 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
100 #define DE_SETUP_SKB ((struct sk_buff *) 1)
101 #define DE_DUMMY_SKB ((struct sk_buff *) 2)
102 #define DE_SETUP_FRAME_WORDS 96
103 #define DE_EEPROM_WORDS 256
104 #define DE_EEPROM_SIZE (DE_EEPROM_WORDS * sizeof(u16))
105 #define DE_MAX_MEDIA 5
107 #define DE_MEDIA_TP_AUTO 0
108 #define DE_MEDIA_BNC 1
109 #define DE_MEDIA_AUI 2
110 #define DE_MEDIA_TP 3
111 #define DE_MEDIA_TP_FD 4
112 #define DE_MEDIA_INVALID DE_MAX_MEDIA
113 #define DE_MEDIA_FIRST 0
114 #define DE_MEDIA_LAST (DE_MAX_MEDIA - 1)
115 #define DE_AUI_BNC (SUPPORTED_AUI | SUPPORTED_BNC)
117 #define DE_TIMER_LINK (60 * HZ)
118 #define DE_TIMER_NO_LINK (5 * HZ)
120 #define DE_NUM_REGS 16
121 #define DE_REGS_SIZE (DE_NUM_REGS * sizeof(u32))
122 #define DE_REGS_VER 1
124 /* Time in jiffies before concluding the transmitter is hung. */
125 #define TX_TIMEOUT (6*HZ)
127 #define DE_UNALIGNED_16(a) (u16)(get_unaligned((u16 *)(a)))
129 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
130 to support a pre-NWay full-duplex signaling mechanism using short frames.
131 No one knows what it should be, but if left at its default value some
132 10base2(!) packets trigger a full-duplex-request interrupt. */
133 #define FULL_DUPLEX_MAGIC 0x6969
156 CacheAlign16
= 0x00008000,
157 BurstLen4
= 0x00000400,
160 NormalTxPoll
= (1 << 0),
161 NormalRxPoll
= (1 << 0),
163 /* Tx/Rx descriptor status bits */
166 RxErrLong
= (1 << 7),
168 RxErrFIFO
= (1 << 0),
169 RxErrRunt
= (1 << 11),
170 RxErrFrame
= (1 << 14),
172 FirstFrag
= (1 << 29),
173 LastFrag
= (1 << 30),
175 TxFIFOUnder
= (1 << 1),
176 TxLinkFail
= (1 << 2) | (1 << 10) | (1 << 11),
179 TxJabber
= (1 << 14),
180 SetupFrame
= (1 << 27),
191 TxState
= (1 << 22) | (1 << 21) | (1 << 20),
192 RxState
= (1 << 19) | (1 << 18) | (1 << 17),
193 LinkFail
= (1 << 12),
195 RxStopped
= (1 << 8),
196 TxStopped
= (1 << 1),
199 TxEnable
= (1 << 13),
201 RxTx
= TxEnable
| RxEnable
,
202 FullDuplex
= (1 << 9),
203 AcceptAllMulticast
= (1 << 7),
204 AcceptAllPhys
= (1 << 6),
206 MacModeClear
= (1<<12) | (1<<11) | (1<<10) | (1<<8) | (1<<3) |
207 RxTx
| BOCnt
| AcceptAllPhys
| AcceptAllMulticast
,
210 EE_SHIFT_CLK
= 0x02, /* EEPROM shift clock. */
211 EE_CS
= 0x01, /* EEPROM chip select. */
212 EE_DATA_WRITE
= 0x04, /* Data from the Tulip to EEPROM. */
215 EE_DATA_READ
= 0x08, /* Data from the EEPROM chip. */
216 EE_ENB
= (0x4800 | EE_CS
),
218 /* The EEPROM commands include the alway-set leading bit. */
222 RxMissedOver
= (1 << 16),
223 RxMissedMask
= 0xffff,
225 /* SROM-related bits */
227 MediaBlockMask
= 0x3f,
228 MediaCustomCSRs
= (1 << 6),
231 PM_Sleep
= (1 << 31),
232 PM_Snooze
= (1 << 30),
233 PM_Mask
= PM_Sleep
| PM_Snooze
,
236 NWayState
= (1 << 14) | (1 << 13) | (1 << 12),
237 NWayRestart
= (1 << 12),
238 NonselPortActive
= (1 << 9),
239 LinkFailStatus
= (1 << 2),
240 NetCxnErr
= (1 << 1),
243 static const u32 de_intr_mask
=
244 IntrOK
| IntrErr
| RxIntr
| RxEmpty
| TxIntr
| TxEmpty
|
245 LinkPass
| LinkFail
| PciErr
;
248 * Set the programmable burst length to 4 longwords for all:
249 * DMA errors result without these values. Cache align 16 long.
251 static const u32 de_bus_mode
= CacheAlign16
| BurstLen4
;
253 struct de_srom_media_block
{
258 } __attribute__((packed
));
260 struct de_srom_info_leaf
{
264 } __attribute__((packed
));
274 u16 type
; /* DE_MEDIA_xxx */
291 struct net_device
*dev
;
294 struct de_desc
*rx_ring
;
295 struct de_desc
*tx_ring
;
296 struct ring_info tx_skb
[DE_TX_RING_SIZE
];
297 struct ring_info rx_skb
[DE_RX_RING_SIZE
];
303 struct net_device_stats net_stats
;
305 struct pci_dev
*pdev
;
307 u16 setup_frame
[DE_SETUP_FRAME_WORDS
];
312 struct media_info media
[DE_MAX_MEDIA
];
313 struct timer_list media_timer
;
317 unsigned de21040
: 1;
318 unsigned media_lock
: 1;
322 static void de_set_rx_mode (struct net_device
*dev
);
323 static void de_tx (struct de_private
*de
);
324 static void de_clean_rings (struct de_private
*de
);
325 static void de_media_interrupt (struct de_private
*de
, u32 status
);
326 static void de21040_media_timer (unsigned long data
);
327 static void de21041_media_timer (unsigned long data
);
328 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
);
331 static struct pci_device_id de_pci_tbl
[] = {
332 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP
,
333 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
334 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_PLUS
,
335 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
338 MODULE_DEVICE_TABLE(pci
, de_pci_tbl
);
340 static const char * const media_name
[DE_MAX_MEDIA
] = {
348 /* 21040 transceiver register settings:
349 * TP AUTO(unused), BNC(unused), AUI, TP, TP FD*/
350 static u16 t21040_csr13
[] = { 0, 0, 0x8F09, 0x8F01, 0x8F01, };
351 static u16 t21040_csr14
[] = { 0, 0, 0x0705, 0xFFFF, 0xFFFD, };
352 static u16 t21040_csr15
[] = { 0, 0, 0x0006, 0x0000, 0x0000, };
354 /* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/
355 static u16 t21041_csr13
[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
356 static u16 t21041_csr14
[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x6F3F, 0x6F3D, };
357 static u16 t21041_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
360 #define dr32(reg) readl(de->regs + (reg))
361 #define dw32(reg,val) writel((val), de->regs + (reg))
364 static void de_rx_err_acct (struct de_private
*de
, unsigned rx_tail
,
367 if (netif_msg_rx_err (de
))
369 "%s: rx err, slot %d status 0x%x len %d\n",
370 de
->dev
->name
, rx_tail
, status
, len
);
372 if ((status
& 0x38000300) != 0x0300) {
373 /* Ingore earlier buffers. */
374 if ((status
& 0xffff) != 0x7fff) {
375 if (netif_msg_rx_err(de
))
376 printk(KERN_WARNING
"%s: Oversized Ethernet frame "
377 "spanned multiple buffers, status %8.8x!\n",
378 de
->dev
->name
, status
);
379 de
->net_stats
.rx_length_errors
++;
381 } else if (status
& RxError
) {
382 /* There was a fatal error. */
383 de
->net_stats
.rx_errors
++; /* end of a packet.*/
384 if (status
& 0x0890) de
->net_stats
.rx_length_errors
++;
385 if (status
& RxErrCRC
) de
->net_stats
.rx_crc_errors
++;
386 if (status
& RxErrFIFO
) de
->net_stats
.rx_fifo_errors
++;
390 static void de_rx (struct de_private
*de
)
392 unsigned rx_tail
= de
->rx_tail
;
393 unsigned rx_work
= DE_RX_RING_SIZE
;
400 struct sk_buff
*skb
, *copy_skb
;
401 unsigned copying_skb
, buflen
;
403 skb
= de
->rx_skb
[rx_tail
].skb
;
406 status
= le32_to_cpu(de
->rx_ring
[rx_tail
].opts1
);
407 if (status
& DescOwn
)
410 len
= ((status
>> 16) & 0x7ff) - 4;
411 mapping
= de
->rx_skb
[rx_tail
].mapping
;
413 if (unlikely(drop
)) {
414 de
->net_stats
.rx_dropped
++;
418 if (unlikely((status
& 0x38008300) != 0x0300)) {
419 de_rx_err_acct(de
, rx_tail
, status
, len
);
423 copying_skb
= (len
<= rx_copybreak
);
425 if (unlikely(netif_msg_rx_status(de
)))
426 printk(KERN_DEBUG
"%s: rx slot %d status 0x%x len %d copying? %d\n",
427 de
->dev
->name
, rx_tail
, status
, len
,
430 buflen
= copying_skb
? (len
+ RX_OFFSET
) : de
->rx_buf_sz
;
431 copy_skb
= dev_alloc_skb (buflen
);
432 if (unlikely(!copy_skb
)) {
433 de
->net_stats
.rx_dropped
++;
440 pci_unmap_single(de
->pdev
, mapping
,
441 buflen
, PCI_DMA_FROMDEVICE
);
445 de
->rx_skb
[rx_tail
].mapping
=
446 pci_map_single(de
->pdev
, copy_skb
->data
,
447 buflen
, PCI_DMA_FROMDEVICE
);
448 de
->rx_skb
[rx_tail
].skb
= copy_skb
;
450 pci_dma_sync_single_for_cpu(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
451 skb_reserve(copy_skb
, RX_OFFSET
);
452 skb_copy_from_linear_data(skb
, skb_put(copy_skb
, len
),
454 pci_dma_sync_single_for_device(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
456 /* We'll reuse the original ring buffer. */
460 skb
->protocol
= eth_type_trans (skb
, de
->dev
);
462 de
->net_stats
.rx_packets
++;
463 de
->net_stats
.rx_bytes
+= skb
->len
;
464 de
->dev
->last_rx
= jiffies
;
466 if (rc
== NET_RX_DROP
)
470 de
->rx_ring
[rx_tail
].opts1
= cpu_to_le32(DescOwn
);
471 if (rx_tail
== (DE_RX_RING_SIZE
- 1))
472 de
->rx_ring
[rx_tail
].opts2
=
473 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
475 de
->rx_ring
[rx_tail
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
476 de
->rx_ring
[rx_tail
].addr1
= cpu_to_le32(mapping
);
477 rx_tail
= NEXT_RX(rx_tail
);
481 printk(KERN_WARNING
"%s: rx work limit reached\n", de
->dev
->name
);
483 de
->rx_tail
= rx_tail
;
486 static irqreturn_t
de_interrupt (int irq
, void *dev_instance
)
488 struct net_device
*dev
= dev_instance
;
489 struct de_private
*de
= dev
->priv
;
492 status
= dr32(MacStatus
);
493 if ((!(status
& (IntrOK
|IntrErr
))) || (status
== 0xFFFF))
496 if (netif_msg_intr(de
))
497 printk(KERN_DEBUG
"%s: intr, status %08x mode %08x desc %u/%u/%u\n",
498 dev
->name
, status
, dr32(MacMode
), de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
500 dw32(MacStatus
, status
);
502 if (status
& (RxIntr
| RxEmpty
)) {
504 if (status
& RxEmpty
)
505 dw32(RxPoll
, NormalRxPoll
);
508 spin_lock(&de
->lock
);
510 if (status
& (TxIntr
| TxEmpty
))
513 if (status
& (LinkPass
| LinkFail
))
514 de_media_interrupt(de
, status
);
516 spin_unlock(&de
->lock
);
518 if (status
& PciErr
) {
521 pci_read_config_word(de
->pdev
, PCI_STATUS
, &pci_status
);
522 pci_write_config_word(de
->pdev
, PCI_STATUS
, pci_status
);
523 printk(KERN_ERR
"%s: PCI bus error, status=%08x, PCI status=%04x\n",
524 dev
->name
, status
, pci_status
);
530 static void de_tx (struct de_private
*de
)
532 unsigned tx_head
= de
->tx_head
;
533 unsigned tx_tail
= de
->tx_tail
;
535 while (tx_tail
!= tx_head
) {
540 status
= le32_to_cpu(de
->tx_ring
[tx_tail
].opts1
);
541 if (status
& DescOwn
)
544 skb
= de
->tx_skb
[tx_tail
].skb
;
546 if (unlikely(skb
== DE_DUMMY_SKB
))
549 if (unlikely(skb
== DE_SETUP_SKB
)) {
550 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
551 sizeof(de
->setup_frame
), PCI_DMA_TODEVICE
);
555 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
556 skb
->len
, PCI_DMA_TODEVICE
);
558 if (status
& LastFrag
) {
559 if (status
& TxError
) {
560 if (netif_msg_tx_err(de
))
561 printk(KERN_DEBUG
"%s: tx err, status 0x%x\n",
562 de
->dev
->name
, status
);
563 de
->net_stats
.tx_errors
++;
565 de
->net_stats
.tx_window_errors
++;
566 if (status
& TxMaxCol
)
567 de
->net_stats
.tx_aborted_errors
++;
568 if (status
& TxLinkFail
)
569 de
->net_stats
.tx_carrier_errors
++;
570 if (status
& TxFIFOUnder
)
571 de
->net_stats
.tx_fifo_errors
++;
573 de
->net_stats
.tx_packets
++;
574 de
->net_stats
.tx_bytes
+= skb
->len
;
575 if (netif_msg_tx_done(de
))
576 printk(KERN_DEBUG
"%s: tx done, slot %d\n", de
->dev
->name
, tx_tail
);
578 dev_kfree_skb_irq(skb
);
582 de
->tx_skb
[tx_tail
].skb
= NULL
;
584 tx_tail
= NEXT_TX(tx_tail
);
587 de
->tx_tail
= tx_tail
;
589 if (netif_queue_stopped(de
->dev
) && (TX_BUFFS_AVAIL(de
) > (DE_TX_RING_SIZE
/ 4)))
590 netif_wake_queue(de
->dev
);
593 static int de_start_xmit (struct sk_buff
*skb
, struct net_device
*dev
)
595 struct de_private
*de
= dev
->priv
;
596 unsigned int entry
, tx_free
;
597 u32 mapping
, len
, flags
= FirstFrag
| LastFrag
;
600 spin_lock_irq(&de
->lock
);
602 tx_free
= TX_BUFFS_AVAIL(de
);
604 netif_stop_queue(dev
);
605 spin_unlock_irq(&de
->lock
);
612 txd
= &de
->tx_ring
[entry
];
615 mapping
= pci_map_single(de
->pdev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
616 if (entry
== (DE_TX_RING_SIZE
- 1))
618 if (!tx_free
|| (tx_free
== (DE_TX_RING_SIZE
/ 2)))
621 txd
->opts2
= cpu_to_le32(flags
);
622 txd
->addr1
= cpu_to_le32(mapping
);
624 de
->tx_skb
[entry
].skb
= skb
;
625 de
->tx_skb
[entry
].mapping
= mapping
;
628 txd
->opts1
= cpu_to_le32(DescOwn
);
631 de
->tx_head
= NEXT_TX(entry
);
632 if (netif_msg_tx_queued(de
))
633 printk(KERN_DEBUG
"%s: tx queued, slot %d, skblen %d\n",
634 dev
->name
, entry
, skb
->len
);
637 netif_stop_queue(dev
);
639 spin_unlock_irq(&de
->lock
);
641 /* Trigger an immediate transmit demand. */
642 dw32(TxPoll
, NormalTxPoll
);
643 dev
->trans_start
= jiffies
;
648 /* Set or clear the multicast filter for this adaptor.
649 Note that we only use exclusion around actually queueing the
650 new frame, not around filling de->setup_frame. This is non-deterministic
651 when re-entered but still correct. */
654 #define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0)
656 static void build_setup_frame_hash(u16
*setup_frm
, struct net_device
*dev
)
658 struct de_private
*de
= dev
->priv
;
660 struct dev_mc_list
*mclist
;
664 memset(hash_table
, 0, sizeof(hash_table
));
665 set_bit_le(255, hash_table
); /* Broadcast entry */
666 /* This should work on big-endian machines as well. */
667 for (i
= 0, mclist
= dev
->mc_list
; mclist
&& i
< dev
->mc_count
;
668 i
++, mclist
= mclist
->next
) {
669 int index
= ether_crc_le(ETH_ALEN
, mclist
->dmi_addr
) & 0x1ff;
671 set_bit_le(index
, hash_table
);
673 for (i
= 0; i
< 32; i
++) {
674 *setup_frm
++ = hash_table
[i
];
675 *setup_frm
++ = hash_table
[i
];
677 setup_frm
= &de
->setup_frame
[13*6];
680 /* Fill the final entry with our physical address. */
681 eaddrs
= (u16
*)dev
->dev_addr
;
682 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
683 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
684 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
687 static void build_setup_frame_perfect(u16
*setup_frm
, struct net_device
*dev
)
689 struct de_private
*de
= dev
->priv
;
690 struct dev_mc_list
*mclist
;
694 /* We have <= 14 addresses so we can use the wonderful
695 16 address perfect filtering of the Tulip. */
696 for (i
= 0, mclist
= dev
->mc_list
; i
< dev
->mc_count
;
697 i
++, mclist
= mclist
->next
) {
698 eaddrs
= (u16
*)mclist
->dmi_addr
;
699 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
700 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
701 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
703 /* Fill the unused entries with the broadcast address. */
704 memset(setup_frm
, 0xff, (15-i
)*12);
705 setup_frm
= &de
->setup_frame
[15*6];
707 /* Fill the final entry with our physical address. */
708 eaddrs
= (u16
*)dev
->dev_addr
;
709 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
710 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
711 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
715 static void __de_set_rx_mode (struct net_device
*dev
)
717 struct de_private
*de
= dev
->priv
;
722 struct de_desc
*dummy_txd
= NULL
;
724 macmode
= dr32(MacMode
) & ~(AcceptAllMulticast
| AcceptAllPhys
);
726 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
727 macmode
|= AcceptAllMulticast
| AcceptAllPhys
;
731 if ((dev
->mc_count
> 1000) || (dev
->flags
& IFF_ALLMULTI
)) {
732 /* Too many to filter well -- accept all multicasts. */
733 macmode
|= AcceptAllMulticast
;
737 /* Note that only the low-address shortword of setup_frame is valid!
738 The values are doubled for big-endian architectures. */
739 if (dev
->mc_count
> 14) /* Must use a multicast hash table. */
740 build_setup_frame_hash (de
->setup_frame
, dev
);
742 build_setup_frame_perfect (de
->setup_frame
, dev
);
745 * Now add this frame to the Tx list.
750 /* Avoid a chip errata by prefixing a dummy entry. */
752 de
->tx_skb
[entry
].skb
= DE_DUMMY_SKB
;
754 dummy_txd
= &de
->tx_ring
[entry
];
755 dummy_txd
->opts2
= (entry
== (DE_TX_RING_SIZE
- 1)) ?
756 cpu_to_le32(RingEnd
) : 0;
757 dummy_txd
->addr1
= 0;
759 /* Must set DescOwned later to avoid race with chip */
761 entry
= NEXT_TX(entry
);
764 de
->tx_skb
[entry
].skb
= DE_SETUP_SKB
;
765 de
->tx_skb
[entry
].mapping
= mapping
=
766 pci_map_single (de
->pdev
, de
->setup_frame
,
767 sizeof (de
->setup_frame
), PCI_DMA_TODEVICE
);
769 /* Put the setup frame on the Tx list. */
770 txd
= &de
->tx_ring
[entry
];
771 if (entry
== (DE_TX_RING_SIZE
- 1))
772 txd
->opts2
= cpu_to_le32(SetupFrame
| RingEnd
| sizeof (de
->setup_frame
));
774 txd
->opts2
= cpu_to_le32(SetupFrame
| sizeof (de
->setup_frame
));
775 txd
->addr1
= cpu_to_le32(mapping
);
778 txd
->opts1
= cpu_to_le32(DescOwn
);
782 dummy_txd
->opts1
= cpu_to_le32(DescOwn
);
786 de
->tx_head
= NEXT_TX(entry
);
788 if (TX_BUFFS_AVAIL(de
) == 0)
789 netif_stop_queue(dev
);
791 /* Trigger an immediate transmit demand. */
792 dw32(TxPoll
, NormalTxPoll
);
795 if (macmode
!= dr32(MacMode
))
796 dw32(MacMode
, macmode
);
799 static void de_set_rx_mode (struct net_device
*dev
)
802 struct de_private
*de
= dev
->priv
;
804 spin_lock_irqsave (&de
->lock
, flags
);
805 __de_set_rx_mode(dev
);
806 spin_unlock_irqrestore (&de
->lock
, flags
);
809 static inline void de_rx_missed(struct de_private
*de
, u32 rx_missed
)
811 if (unlikely(rx_missed
& RxMissedOver
))
812 de
->net_stats
.rx_missed_errors
+= RxMissedMask
;
814 de
->net_stats
.rx_missed_errors
+= (rx_missed
& RxMissedMask
);
817 static void __de_get_stats(struct de_private
*de
)
819 u32 tmp
= dr32(RxMissed
); /* self-clearing */
821 de_rx_missed(de
, tmp
);
824 static struct net_device_stats
*de_get_stats(struct net_device
*dev
)
826 struct de_private
*de
= dev
->priv
;
828 /* The chip only need report frame silently dropped. */
829 spin_lock_irq(&de
->lock
);
830 if (netif_running(dev
) && netif_device_present(dev
))
832 spin_unlock_irq(&de
->lock
);
834 return &de
->net_stats
;
837 static inline int de_is_running (struct de_private
*de
)
839 return (dr32(MacStatus
) & (RxState
| TxState
)) ? 1 : 0;
842 static void de_stop_rxtx (struct de_private
*de
)
845 unsigned int i
= 1300/100;
847 macmode
= dr32(MacMode
);
848 if (macmode
& RxTx
) {
849 dw32(MacMode
, macmode
& ~RxTx
);
853 /* wait until in-flight frame completes.
854 * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
855 * Typically expect this loop to end in < 50 us on 100BT.
858 if (!de_is_running(de
))
863 printk(KERN_WARNING
"%s: timeout expired stopping DMA\n", de
->dev
->name
);
866 static inline void de_start_rxtx (struct de_private
*de
)
870 macmode
= dr32(MacMode
);
871 if ((macmode
& RxTx
) != RxTx
) {
872 dw32(MacMode
, macmode
| RxTx
);
877 static void de_stop_hw (struct de_private
*de
)
885 dw32(MacStatus
, dr32(MacStatus
));
890 de
->tx_head
= de
->tx_tail
= 0;
893 static void de_link_up(struct de_private
*de
)
895 if (!netif_carrier_ok(de
->dev
)) {
896 netif_carrier_on(de
->dev
);
897 if (netif_msg_link(de
))
898 printk(KERN_INFO
"%s: link up, media %s\n",
899 de
->dev
->name
, media_name
[de
->media_type
]);
903 static void de_link_down(struct de_private
*de
)
905 if (netif_carrier_ok(de
->dev
)) {
906 netif_carrier_off(de
->dev
);
907 if (netif_msg_link(de
))
908 printk(KERN_INFO
"%s: link down\n", de
->dev
->name
);
912 static void de_set_media (struct de_private
*de
)
914 unsigned media
= de
->media_type
;
915 u32 macmode
= dr32(MacMode
);
917 if (de_is_running(de
))
918 printk(KERN_WARNING
"%s: chip is running while changing media!\n", de
->dev
->name
);
921 dw32(CSR11
, FULL_DUPLEX_MAGIC
);
922 dw32(CSR13
, 0); /* Reset phy */
923 dw32(CSR14
, de
->media
[media
].csr14
);
924 dw32(CSR15
, de
->media
[media
].csr15
);
925 dw32(CSR13
, de
->media
[media
].csr13
);
927 /* must delay 10ms before writing to other registers,
932 if (media
== DE_MEDIA_TP_FD
)
933 macmode
|= FullDuplex
;
935 macmode
&= ~FullDuplex
;
937 if (netif_msg_link(de
)) {
938 printk(KERN_INFO
"%s: set link %s\n"
939 KERN_INFO
"%s: mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n"
940 KERN_INFO
"%s: set mode 0x%x, set sia 0x%x,0x%x,0x%x\n",
941 de
->dev
->name
, media_name
[media
],
942 de
->dev
->name
, dr32(MacMode
), dr32(SIAStatus
),
943 dr32(CSR13
), dr32(CSR14
), dr32(CSR15
),
944 de
->dev
->name
, macmode
, de
->media
[media
].csr13
,
945 de
->media
[media
].csr14
, de
->media
[media
].csr15
);
947 if (macmode
!= dr32(MacMode
))
948 dw32(MacMode
, macmode
);
951 static void de_next_media (struct de_private
*de
, u32
*media
,
952 unsigned int n_media
)
956 for (i
= 0; i
< n_media
; i
++) {
957 if (de_ok_to_advertise(de
, media
[i
])) {
958 de
->media_type
= media
[i
];
964 static void de21040_media_timer (unsigned long data
)
966 struct de_private
*de
= (struct de_private
*) data
;
967 struct net_device
*dev
= de
->dev
;
968 u32 status
= dr32(SIAStatus
);
969 unsigned int carrier
;
972 carrier
= (status
& NetCxnErr
) ? 0 : 1;
975 if (de
->media_type
!= DE_MEDIA_AUI
&& (status
& LinkFailStatus
))
978 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
979 add_timer(&de
->media_timer
);
980 if (!netif_carrier_ok(dev
))
983 if (netif_msg_timer(de
))
984 printk(KERN_INFO
"%s: %s link ok, status %x\n",
985 dev
->name
, media_name
[de
->media_type
],
995 if (de
->media_type
== DE_MEDIA_AUI
) {
996 u32 next_state
= DE_MEDIA_TP
;
997 de_next_media(de
, &next_state
, 1);
999 u32 next_state
= DE_MEDIA_AUI
;
1000 de_next_media(de
, &next_state
, 1);
1003 spin_lock_irqsave(&de
->lock
, flags
);
1005 spin_unlock_irqrestore(&de
->lock
, flags
);
1010 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1011 add_timer(&de
->media_timer
);
1013 if (netif_msg_timer(de
))
1014 printk(KERN_INFO
"%s: no link, trying media %s, status %x\n",
1015 dev
->name
, media_name
[de
->media_type
], status
);
1018 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
)
1020 switch (new_media
) {
1021 case DE_MEDIA_TP_AUTO
:
1022 if (!(de
->media_advertise
& ADVERTISED_Autoneg
))
1024 if (!(de
->media_advertise
& (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
)))
1028 if (!(de
->media_advertise
& ADVERTISED_BNC
))
1032 if (!(de
->media_advertise
& ADVERTISED_AUI
))
1036 if (!(de
->media_advertise
& ADVERTISED_10baseT_Half
))
1039 case DE_MEDIA_TP_FD
:
1040 if (!(de
->media_advertise
& ADVERTISED_10baseT_Full
))
1048 static void de21041_media_timer (unsigned long data
)
1050 struct de_private
*de
= (struct de_private
*) data
;
1051 struct net_device
*dev
= de
->dev
;
1052 u32 status
= dr32(SIAStatus
);
1053 unsigned int carrier
;
1054 unsigned long flags
;
1056 carrier
= (status
& NetCxnErr
) ? 0 : 1;
1059 if ((de
->media_type
== DE_MEDIA_TP_AUTO
||
1060 de
->media_type
== DE_MEDIA_TP
||
1061 de
->media_type
== DE_MEDIA_TP_FD
) &&
1062 (status
& LinkFailStatus
))
1065 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
1066 add_timer(&de
->media_timer
);
1067 if (!netif_carrier_ok(dev
))
1070 if (netif_msg_timer(de
))
1071 printk(KERN_INFO
"%s: %s link ok, mode %x status %x\n",
1072 dev
->name
, media_name
[de
->media_type
],
1073 dr32(MacMode
), status
);
1079 /* if media type locked, don't switch media */
1083 /* if activity detected, use that as hint for new media type */
1084 if (status
& NonselPortActive
) {
1085 unsigned int have_media
= 1;
1087 /* if AUI/BNC selected, then activity is on TP port */
1088 if (de
->media_type
== DE_MEDIA_AUI
||
1089 de
->media_type
== DE_MEDIA_BNC
) {
1090 if (de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
))
1091 de
->media_type
= DE_MEDIA_TP_AUTO
;
1096 /* TP selected. If there is only TP and BNC, then it's BNC */
1097 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_BNC
) &&
1098 de_ok_to_advertise(de
, DE_MEDIA_BNC
))
1099 de
->media_type
= DE_MEDIA_BNC
;
1101 /* TP selected. If there is only TP and AUI, then it's AUI */
1102 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_AUI
) &&
1103 de_ok_to_advertise(de
, DE_MEDIA_AUI
))
1104 de
->media_type
= DE_MEDIA_AUI
;
1106 /* otherwise, ignore the hint */
1115 * Absent or ambiguous activity hint, move to next advertised
1116 * media state. If de->media_type is left unchanged, this
1117 * simply resets the PHY and reloads the current media settings.
1119 if (de
->media_type
== DE_MEDIA_AUI
) {
1120 u32 next_states
[] = { DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
};
1121 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1122 } else if (de
->media_type
== DE_MEDIA_BNC
) {
1123 u32 next_states
[] = { DE_MEDIA_TP_AUTO
, DE_MEDIA_AUI
};
1124 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1126 u32 next_states
[] = { DE_MEDIA_AUI
, DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
};
1127 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1131 spin_lock_irqsave(&de
->lock
, flags
);
1133 spin_unlock_irqrestore(&de
->lock
, flags
);
1138 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1139 add_timer(&de
->media_timer
);
1141 if (netif_msg_timer(de
))
1142 printk(KERN_INFO
"%s: no link, trying media %s, status %x\n",
1143 dev
->name
, media_name
[de
->media_type
], status
);
1146 static void de_media_interrupt (struct de_private
*de
, u32 status
)
1148 if (status
& LinkPass
) {
1150 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_LINK
);
1154 BUG_ON(!(status
& LinkFail
));
1156 if (netif_carrier_ok(de
->dev
)) {
1158 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1162 static int de_reset_mac (struct de_private
*de
)
1167 * Reset MAC. de4x5.c and tulip.c examined for "advice"
1171 if (dr32(BusMode
) == 0xffffffff)
1174 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1175 dw32 (BusMode
, CmdReset
);
1178 dw32 (BusMode
, de_bus_mode
);
1181 for (tmp
= 0; tmp
< 5; tmp
++) {
1188 status
= dr32(MacStatus
);
1189 if (status
& (RxState
| TxState
))
1191 if (status
== 0xffffffff)
1196 static void de_adapter_wake (struct de_private
*de
)
1203 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1204 if (pmctl
& PM_Mask
) {
1206 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1208 /* de4x5.c delays, so we do too */
1213 static void de_adapter_sleep (struct de_private
*de
)
1220 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1222 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1225 static int de_init_hw (struct de_private
*de
)
1227 struct net_device
*dev
= de
->dev
;
1231 de_adapter_wake(de
);
1233 macmode
= dr32(MacMode
) & ~MacModeClear
;
1235 rc
= de_reset_mac(de
);
1239 de_set_media(de
); /* reset phy */
1241 dw32(RxRingAddr
, de
->ring_dma
);
1242 dw32(TxRingAddr
, de
->ring_dma
+ (sizeof(struct de_desc
) * DE_RX_RING_SIZE
));
1244 dw32(MacMode
, RxTx
| macmode
);
1246 dr32(RxMissed
); /* self-clearing */
1248 dw32(IntrMask
, de_intr_mask
);
1250 de_set_rx_mode(dev
);
1255 static int de_refill_rx (struct de_private
*de
)
1259 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1260 struct sk_buff
*skb
;
1262 skb
= dev_alloc_skb(de
->rx_buf_sz
);
1268 de
->rx_skb
[i
].mapping
= pci_map_single(de
->pdev
,
1269 skb
->data
, de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1270 de
->rx_skb
[i
].skb
= skb
;
1272 de
->rx_ring
[i
].opts1
= cpu_to_le32(DescOwn
);
1273 if (i
== (DE_RX_RING_SIZE
- 1))
1274 de
->rx_ring
[i
].opts2
=
1275 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
1277 de
->rx_ring
[i
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
1278 de
->rx_ring
[i
].addr1
= cpu_to_le32(de
->rx_skb
[i
].mapping
);
1279 de
->rx_ring
[i
].addr2
= 0;
1289 static int de_init_rings (struct de_private
*de
)
1291 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1292 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1295 de
->tx_head
= de
->tx_tail
= 0;
1297 return de_refill_rx (de
);
1300 static int de_alloc_rings (struct de_private
*de
)
1302 de
->rx_ring
= pci_alloc_consistent(de
->pdev
, DE_RING_BYTES
, &de
->ring_dma
);
1305 de
->tx_ring
= &de
->rx_ring
[DE_RX_RING_SIZE
];
1306 return de_init_rings(de
);
1309 static void de_clean_rings (struct de_private
*de
)
1313 memset(de
->rx_ring
, 0, sizeof(struct de_desc
) * DE_RX_RING_SIZE
);
1314 de
->rx_ring
[DE_RX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1316 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1317 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1320 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1321 if (de
->rx_skb
[i
].skb
) {
1322 pci_unmap_single(de
->pdev
, de
->rx_skb
[i
].mapping
,
1323 de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1324 dev_kfree_skb(de
->rx_skb
[i
].skb
);
1328 for (i
= 0; i
< DE_TX_RING_SIZE
; i
++) {
1329 struct sk_buff
*skb
= de
->tx_skb
[i
].skb
;
1330 if ((skb
) && (skb
!= DE_DUMMY_SKB
)) {
1331 if (skb
!= DE_SETUP_SKB
) {
1332 de
->net_stats
.tx_dropped
++;
1333 pci_unmap_single(de
->pdev
,
1334 de
->tx_skb
[i
].mapping
,
1335 skb
->len
, PCI_DMA_TODEVICE
);
1338 pci_unmap_single(de
->pdev
,
1339 de
->tx_skb
[i
].mapping
,
1340 sizeof(de
->setup_frame
),
1346 memset(&de
->rx_skb
, 0, sizeof(struct ring_info
) * DE_RX_RING_SIZE
);
1347 memset(&de
->tx_skb
, 0, sizeof(struct ring_info
) * DE_TX_RING_SIZE
);
1350 static void de_free_rings (struct de_private
*de
)
1353 pci_free_consistent(de
->pdev
, DE_RING_BYTES
, de
->rx_ring
, de
->ring_dma
);
1358 static int de_open (struct net_device
*dev
)
1360 struct de_private
*de
= dev
->priv
;
1363 if (netif_msg_ifup(de
))
1364 printk(KERN_DEBUG
"%s: enabling interface\n", dev
->name
);
1366 de
->rx_buf_sz
= (dev
->mtu
<= 1500 ? PKT_BUF_SZ
: dev
->mtu
+ 32);
1368 rc
= de_alloc_rings(de
);
1370 printk(KERN_ERR
"%s: ring allocation failure, err=%d\n",
1377 rc
= request_irq(dev
->irq
, de_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
1379 printk(KERN_ERR
"%s: IRQ %d request failure, err=%d\n",
1380 dev
->name
, dev
->irq
, rc
);
1384 rc
= de_init_hw(de
);
1386 printk(KERN_ERR
"%s: h/w init failure, err=%d\n",
1388 goto err_out_free_irq
;
1391 netif_start_queue(dev
);
1392 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1397 free_irq(dev
->irq
, dev
);
1403 static int de_close (struct net_device
*dev
)
1405 struct de_private
*de
= dev
->priv
;
1406 unsigned long flags
;
1408 if (netif_msg_ifdown(de
))
1409 printk(KERN_DEBUG
"%s: disabling interface\n", dev
->name
);
1411 del_timer_sync(&de
->media_timer
);
1413 spin_lock_irqsave(&de
->lock
, flags
);
1415 netif_stop_queue(dev
);
1416 netif_carrier_off(dev
);
1417 spin_unlock_irqrestore(&de
->lock
, flags
);
1419 free_irq(dev
->irq
, dev
);
1422 de_adapter_sleep(de
);
1423 pci_disable_device(de
->pdev
);
1427 static void de_tx_timeout (struct net_device
*dev
)
1429 struct de_private
*de
= dev
->priv
;
1431 printk(KERN_DEBUG
"%s: NIC status %08x mode %08x sia %08x desc %u/%u/%u\n",
1432 dev
->name
, dr32(MacStatus
), dr32(MacMode
), dr32(SIAStatus
),
1433 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
1435 del_timer_sync(&de
->media_timer
);
1437 disable_irq(dev
->irq
);
1438 spin_lock_irq(&de
->lock
);
1441 netif_stop_queue(dev
);
1442 netif_carrier_off(dev
);
1444 spin_unlock_irq(&de
->lock
);
1445 enable_irq(dev
->irq
);
1447 /* Update the error counts. */
1450 synchronize_irq(dev
->irq
);
1457 netif_wake_queue(dev
);
1460 static void __de_get_regs(struct de_private
*de
, u8
*buf
)
1463 u32
*rbuf
= (u32
*)buf
;
1466 for (i
= 0; i
< DE_NUM_REGS
; i
++)
1467 rbuf
[i
] = dr32(i
* 8);
1469 /* handle self-clearing RxMissed counter, CSR8 */
1470 de_rx_missed(de
, rbuf
[8]);
1473 static int __de_get_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1475 ecmd
->supported
= de
->media_supported
;
1476 ecmd
->transceiver
= XCVR_INTERNAL
;
1477 ecmd
->phy_address
= 0;
1478 ecmd
->advertising
= de
->media_advertise
;
1480 switch (de
->media_type
) {
1482 ecmd
->port
= PORT_AUI
;
1486 ecmd
->port
= PORT_BNC
;
1490 ecmd
->port
= PORT_TP
;
1491 ecmd
->speed
= SPEED_10
;
1495 if (dr32(MacMode
) & FullDuplex
)
1496 ecmd
->duplex
= DUPLEX_FULL
;
1498 ecmd
->duplex
= DUPLEX_HALF
;
1501 ecmd
->autoneg
= AUTONEG_DISABLE
;
1503 ecmd
->autoneg
= AUTONEG_ENABLE
;
1505 /* ignore maxtxpkt, maxrxpkt for now */
1510 static int __de_set_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1513 unsigned int media_lock
;
1515 if (ecmd
->speed
!= SPEED_10
&& ecmd
->speed
!= 5 && ecmd
->speed
!= 2)
1517 if (de
->de21040
&& ecmd
->speed
== 2)
1519 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
1521 if (ecmd
->port
!= PORT_TP
&& ecmd
->port
!= PORT_AUI
&& ecmd
->port
!= PORT_BNC
)
1523 if (de
->de21040
&& ecmd
->port
== PORT_BNC
)
1525 if (ecmd
->transceiver
!= XCVR_INTERNAL
)
1527 if (ecmd
->autoneg
!= AUTONEG_DISABLE
&& ecmd
->autoneg
!= AUTONEG_ENABLE
)
1529 if (ecmd
->advertising
& ~de
->media_supported
)
1531 if (ecmd
->autoneg
== AUTONEG_ENABLE
&&
1532 (!(ecmd
->advertising
& ADVERTISED_Autoneg
)))
1535 switch (ecmd
->port
) {
1537 new_media
= DE_MEDIA_AUI
;
1538 if (!(ecmd
->advertising
& ADVERTISED_AUI
))
1542 new_media
= DE_MEDIA_BNC
;
1543 if (!(ecmd
->advertising
& ADVERTISED_BNC
))
1547 if (ecmd
->autoneg
== AUTONEG_ENABLE
)
1548 new_media
= DE_MEDIA_TP_AUTO
;
1549 else if (ecmd
->duplex
== DUPLEX_FULL
)
1550 new_media
= DE_MEDIA_TP_FD
;
1552 new_media
= DE_MEDIA_TP
;
1553 if (!(ecmd
->advertising
& ADVERTISED_TP
))
1555 if (!(ecmd
->advertising
& (ADVERTISED_10baseT_Full
| ADVERTISED_10baseT_Half
)))
1560 media_lock
= (ecmd
->autoneg
== AUTONEG_ENABLE
) ? 0 : 1;
1562 if ((new_media
== de
->media_type
) &&
1563 (media_lock
== de
->media_lock
) &&
1564 (ecmd
->advertising
== de
->media_advertise
))
1565 return 0; /* nothing to change */
1570 de
->media_type
= new_media
;
1571 de
->media_lock
= media_lock
;
1572 de
->media_advertise
= ecmd
->advertising
;
1578 static void de_get_drvinfo (struct net_device
*dev
,struct ethtool_drvinfo
*info
)
1580 struct de_private
*de
= dev
->priv
;
1582 strcpy (info
->driver
, DRV_NAME
);
1583 strcpy (info
->version
, DRV_VERSION
);
1584 strcpy (info
->bus_info
, pci_name(de
->pdev
));
1585 info
->eedump_len
= DE_EEPROM_SIZE
;
1588 static int de_get_regs_len(struct net_device
*dev
)
1590 return DE_REGS_SIZE
;
1593 static int de_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1595 struct de_private
*de
= dev
->priv
;
1598 spin_lock_irq(&de
->lock
);
1599 rc
= __de_get_settings(de
, ecmd
);
1600 spin_unlock_irq(&de
->lock
);
1605 static int de_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1607 struct de_private
*de
= dev
->priv
;
1610 spin_lock_irq(&de
->lock
);
1611 rc
= __de_set_settings(de
, ecmd
);
1612 spin_unlock_irq(&de
->lock
);
1617 static u32
de_get_msglevel(struct net_device
*dev
)
1619 struct de_private
*de
= dev
->priv
;
1621 return de
->msg_enable
;
1624 static void de_set_msglevel(struct net_device
*dev
, u32 msglvl
)
1626 struct de_private
*de
= dev
->priv
;
1628 de
->msg_enable
= msglvl
;
1631 static int de_get_eeprom(struct net_device
*dev
,
1632 struct ethtool_eeprom
*eeprom
, u8
*data
)
1634 struct de_private
*de
= dev
->priv
;
1638 if ((eeprom
->offset
!= 0) || (eeprom
->magic
!= 0) ||
1639 (eeprom
->len
!= DE_EEPROM_SIZE
))
1641 memcpy(data
, de
->ee_data
, eeprom
->len
);
1646 static int de_nway_reset(struct net_device
*dev
)
1648 struct de_private
*de
= dev
->priv
;
1651 if (de
->media_type
!= DE_MEDIA_TP_AUTO
)
1653 if (netif_carrier_ok(de
->dev
))
1656 status
= dr32(SIAStatus
);
1657 dw32(SIAStatus
, (status
& ~NWayState
) | NWayRestart
);
1658 if (netif_msg_link(de
))
1659 printk(KERN_INFO
"%s: link nway restart, status %x,%x\n",
1660 de
->dev
->name
, status
, dr32(SIAStatus
));
1664 static void de_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
1667 struct de_private
*de
= dev
->priv
;
1669 regs
->version
= (DE_REGS_VER
<< 2) | de
->de21040
;
1671 spin_lock_irq(&de
->lock
);
1672 __de_get_regs(de
, data
);
1673 spin_unlock_irq(&de
->lock
);
1676 static const struct ethtool_ops de_ethtool_ops
= {
1677 .get_link
= ethtool_op_get_link
,
1678 .get_drvinfo
= de_get_drvinfo
,
1679 .get_regs_len
= de_get_regs_len
,
1680 .get_settings
= de_get_settings
,
1681 .set_settings
= de_set_settings
,
1682 .get_msglevel
= de_get_msglevel
,
1683 .set_msglevel
= de_set_msglevel
,
1684 .get_eeprom
= de_get_eeprom
,
1685 .nway_reset
= de_nway_reset
,
1686 .get_regs
= de_get_regs
,
1689 static void __devinit
de21040_get_mac_address (struct de_private
*de
)
1693 dw32 (ROMCmd
, 0); /* Reset the pointer with a dummy write. */
1695 for (i
= 0; i
< 6; i
++) {
1696 int value
, boguscnt
= 100000;
1698 value
= dr32(ROMCmd
);
1699 while (value
< 0 && --boguscnt
> 0);
1700 de
->dev
->dev_addr
[i
] = value
;
1703 printk(KERN_WARNING PFX
"timeout reading 21040 MAC address byte %u\n", i
);
1707 static void __devinit
de21040_get_media_info(struct de_private
*de
)
1711 de
->media_type
= DE_MEDIA_TP
;
1712 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
|
1713 SUPPORTED_10baseT_Half
| SUPPORTED_AUI
;
1714 de
->media_advertise
= de
->media_supported
;
1716 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1720 case DE_MEDIA_TP_FD
:
1721 de
->media
[i
].type
= i
;
1722 de
->media
[i
].csr13
= t21040_csr13
[i
];
1723 de
->media
[i
].csr14
= t21040_csr14
[i
];
1724 de
->media
[i
].csr15
= t21040_csr15
[i
];
1727 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1733 /* Note: this routine returns extra data bits for size detection. */
1734 static unsigned __devinit
tulip_read_eeprom(void __iomem
*regs
, int location
, int addr_len
)
1737 unsigned retval
= 0;
1738 void __iomem
*ee_addr
= regs
+ ROMCmd
;
1739 int read_cmd
= location
| (EE_READ_CMD
<< addr_len
);
1741 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1742 writel(EE_ENB
, ee_addr
);
1744 /* Shift the read command bits out. */
1745 for (i
= 4 + addr_len
; i
>= 0; i
--) {
1746 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
1747 writel(EE_ENB
| dataval
, ee_addr
);
1749 writel(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
1751 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1753 writel(EE_ENB
, ee_addr
);
1756 for (i
= 16; i
> 0; i
--) {
1757 writel(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
1759 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1760 writel(EE_ENB
, ee_addr
);
1764 /* Terminate the EEPROM access. */
1765 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1769 static void __devinit
de21041_get_srom_info (struct de_private
*de
)
1771 unsigned i
, sa_offset
= 0, ofs
;
1772 u8 ee_data
[DE_EEPROM_SIZE
+ 6] = {};
1773 unsigned ee_addr_size
= tulip_read_eeprom(de
->regs
, 0xff, 8) & 0x40000 ? 8 : 6;
1774 struct de_srom_info_leaf
*il
;
1777 /* download entire eeprom */
1778 for (i
= 0; i
< DE_EEPROM_WORDS
; i
++)
1779 ((__le16
*)ee_data
)[i
] =
1780 cpu_to_le16(tulip_read_eeprom(de
->regs
, i
, ee_addr_size
));
1782 /* DEC now has a specification but early board makers
1783 just put the address in the first EEPROM locations. */
1784 /* This does memcmp(eedata, eedata+16, 8) */
1786 #ifndef CONFIG_MIPS_COBALT
1788 for (i
= 0; i
< 8; i
++)
1789 if (ee_data
[i
] != ee_data
[16+i
])
1794 /* store MAC address */
1795 for (i
= 0; i
< 6; i
++)
1796 de
->dev
->dev_addr
[i
] = ee_data
[i
+ sa_offset
];
1798 /* get offset of controller 0 info leaf. ignore 2nd byte. */
1799 ofs
= ee_data
[SROMC0InfoLeaf
];
1800 if (ofs
>= (sizeof(ee_data
) - sizeof(struct de_srom_info_leaf
) - sizeof(struct de_srom_media_block
)))
1803 /* get pointer to info leaf */
1804 il
= (struct de_srom_info_leaf
*) &ee_data
[ofs
];
1806 /* paranoia checks */
1807 if (il
->n_blocks
== 0)
1809 if ((sizeof(ee_data
) - ofs
) <
1810 (sizeof(struct de_srom_info_leaf
) + (sizeof(struct de_srom_media_block
) * il
->n_blocks
)))
1813 /* get default media type */
1814 switch (DE_UNALIGNED_16(&il
->default_media
)) {
1815 case 0x0001: de
->media_type
= DE_MEDIA_BNC
; break;
1816 case 0x0002: de
->media_type
= DE_MEDIA_AUI
; break;
1817 case 0x0204: de
->media_type
= DE_MEDIA_TP_FD
; break;
1818 default: de
->media_type
= DE_MEDIA_TP_AUTO
; break;
1821 if (netif_msg_probe(de
))
1822 printk(KERN_INFO
"de%d: SROM leaf offset %u, default media %s\n",
1824 media_name
[de
->media_type
]);
1826 /* init SIA register values to defaults */
1827 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1828 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1829 de
->media
[i
].csr13
= 0xffff;
1830 de
->media
[i
].csr14
= 0xffff;
1831 de
->media
[i
].csr15
= 0xffff;
1834 /* parse media blocks to see what medias are supported,
1835 * and if any custom CSR values are provided
1837 bufp
= ((void *)il
) + sizeof(*il
);
1838 for (i
= 0; i
< il
->n_blocks
; i
++) {
1839 struct de_srom_media_block
*ib
= bufp
;
1842 /* index based on media type in media block */
1843 switch(ib
->opts
& MediaBlockMask
) {
1844 case 0: /* 10baseT */
1845 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Half
1846 | SUPPORTED_Autoneg
;
1848 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1851 de
->media_supported
|= SUPPORTED_BNC
;
1855 de
->media_supported
|= SUPPORTED_AUI
;
1858 case 4: /* 10baseT-FD */
1859 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
1860 | SUPPORTED_Autoneg
;
1861 idx
= DE_MEDIA_TP_FD
;
1862 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1868 de
->media
[idx
].type
= idx
;
1870 if (netif_msg_probe(de
))
1871 printk(KERN_INFO
"de%d: media block #%u: %s",
1873 media_name
[de
->media
[idx
].type
]);
1875 bufp
+= sizeof (ib
->opts
);
1877 if (ib
->opts
& MediaCustomCSRs
) {
1878 de
->media
[idx
].csr13
= DE_UNALIGNED_16(&ib
->csr13
);
1879 de
->media
[idx
].csr14
= DE_UNALIGNED_16(&ib
->csr14
);
1880 de
->media
[idx
].csr15
= DE_UNALIGNED_16(&ib
->csr15
);
1881 bufp
+= sizeof(ib
->csr13
) + sizeof(ib
->csr14
) +
1884 if (netif_msg_probe(de
))
1885 printk(" (%x,%x,%x)\n",
1886 de
->media
[idx
].csr13
,
1887 de
->media
[idx
].csr14
,
1888 de
->media
[idx
].csr15
);
1890 } else if (netif_msg_probe(de
))
1893 if (bufp
> ((void *)&ee_data
[DE_EEPROM_SIZE
- 3]))
1897 de
->media_advertise
= de
->media_supported
;
1900 /* fill in defaults, for cases where custom CSRs not used */
1901 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1902 if (de
->media
[i
].csr13
== 0xffff)
1903 de
->media
[i
].csr13
= t21041_csr13
[i
];
1904 if (de
->media
[i
].csr14
== 0xffff)
1905 de
->media
[i
].csr14
= t21041_csr14
[i
];
1906 if (de
->media
[i
].csr15
== 0xffff)
1907 de
->media
[i
].csr15
= t21041_csr15
[i
];
1910 de
->ee_data
= kmemdup(&ee_data
[0], DE_EEPROM_SIZE
, GFP_KERNEL
);
1915 /* for error cases, it's ok to assume we support all these */
1916 for (i
= 0; i
< DE_MAX_MEDIA
; i
++)
1917 de
->media
[i
].type
= i
;
1918 de
->media_supported
=
1919 SUPPORTED_10baseT_Half
|
1920 SUPPORTED_10baseT_Full
|
1928 static int __devinit
de_init_one (struct pci_dev
*pdev
,
1929 const struct pci_device_id
*ent
)
1931 struct net_device
*dev
;
1932 struct de_private
*de
;
1935 unsigned long pciaddr
;
1936 static int board_idx
= -1;
1937 DECLARE_MAC_BUF(mac
);
1943 printk("%s", version
);
1946 /* allocate a new ethernet device structure, and fill in defaults */
1947 dev
= alloc_etherdev(sizeof(struct de_private
));
1951 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1952 dev
->open
= de_open
;
1953 dev
->stop
= de_close
;
1954 dev
->set_multicast_list
= de_set_rx_mode
;
1955 dev
->hard_start_xmit
= de_start_xmit
;
1956 dev
->get_stats
= de_get_stats
;
1957 dev
->ethtool_ops
= &de_ethtool_ops
;
1958 dev
->tx_timeout
= de_tx_timeout
;
1959 dev
->watchdog_timeo
= TX_TIMEOUT
;
1962 de
->de21040
= ent
->driver_data
== 0 ? 1 : 0;
1965 de
->msg_enable
= (debug
< 0 ? DE_DEF_MSG_ENABLE
: debug
);
1966 de
->board_idx
= board_idx
;
1967 spin_lock_init (&de
->lock
);
1968 init_timer(&de
->media_timer
);
1970 de
->media_timer
.function
= de21040_media_timer
;
1972 de
->media_timer
.function
= de21041_media_timer
;
1973 de
->media_timer
.data
= (unsigned long) de
;
1975 netif_carrier_off(dev
);
1976 netif_stop_queue(dev
);
1978 /* wake up device, assign resources */
1979 rc
= pci_enable_device(pdev
);
1983 /* reserve PCI resources to ensure driver atomicity */
1984 rc
= pci_request_regions(pdev
, DRV_NAME
);
1986 goto err_out_disable
;
1988 /* check for invalid IRQ value */
1989 if (pdev
->irq
< 2) {
1991 printk(KERN_ERR PFX
"invalid irq (%d) for pci dev %s\n",
1992 pdev
->irq
, pci_name(pdev
));
1996 dev
->irq
= pdev
->irq
;
1998 /* obtain and check validity of PCI I/O address */
1999 pciaddr
= pci_resource_start(pdev
, 1);
2002 printk(KERN_ERR PFX
"no MMIO resource for pci dev %s\n",
2006 if (pci_resource_len(pdev
, 1) < DE_REGS_SIZE
) {
2008 printk(KERN_ERR PFX
"MMIO resource (%llx) too small on pci dev %s\n",
2009 (unsigned long long)pci_resource_len(pdev
, 1), pci_name(pdev
));
2013 /* remap CSR registers */
2014 regs
= ioremap_nocache(pciaddr
, DE_REGS_SIZE
);
2017 printk(KERN_ERR PFX
"Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
2018 (unsigned long long)pci_resource_len(pdev
, 1),
2019 pciaddr
, pci_name(pdev
));
2022 dev
->base_addr
= (unsigned long) regs
;
2025 de_adapter_wake(de
);
2027 /* make sure hardware is not running */
2028 rc
= de_reset_mac(de
);
2030 printk(KERN_ERR PFX
"Cannot reset MAC, pci dev %s\n",
2035 /* get MAC address, initialize default media type and
2036 * get list of supported media
2039 de21040_get_mac_address(de
);
2040 de21040_get_media_info(de
);
2042 de21041_get_srom_info(de
);
2045 /* register new network interface with kernel */
2046 rc
= register_netdev(dev
);
2050 /* print info about board and interface just registered */
2051 printk (KERN_INFO
"%s: %s at 0x%lx, %s, IRQ %d\n",
2053 de
->de21040
? "21040" : "21041",
2055 print_mac(mac
, dev
->dev_addr
),
2058 pci_set_drvdata(pdev
, dev
);
2060 /* enable busmastering */
2061 pci_set_master(pdev
);
2063 /* put adapter to sleep */
2064 de_adapter_sleep(de
);
2072 pci_release_regions(pdev
);
2074 pci_disable_device(pdev
);
2080 static void __devexit
de_remove_one (struct pci_dev
*pdev
)
2082 struct net_device
*dev
= pci_get_drvdata(pdev
);
2083 struct de_private
*de
= dev
->priv
;
2086 unregister_netdev(dev
);
2089 pci_release_regions(pdev
);
2090 pci_disable_device(pdev
);
2091 pci_set_drvdata(pdev
, NULL
);
2097 static int de_suspend (struct pci_dev
*pdev
, pm_message_t state
)
2099 struct net_device
*dev
= pci_get_drvdata (pdev
);
2100 struct de_private
*de
= dev
->priv
;
2103 if (netif_running (dev
)) {
2104 del_timer_sync(&de
->media_timer
);
2106 disable_irq(dev
->irq
);
2107 spin_lock_irq(&de
->lock
);
2110 netif_stop_queue(dev
);
2111 netif_device_detach(dev
);
2112 netif_carrier_off(dev
);
2114 spin_unlock_irq(&de
->lock
);
2115 enable_irq(dev
->irq
);
2117 /* Update the error counts. */
2120 synchronize_irq(dev
->irq
);
2123 de_adapter_sleep(de
);
2124 pci_disable_device(pdev
);
2126 netif_device_detach(dev
);
2132 static int de_resume (struct pci_dev
*pdev
)
2134 struct net_device
*dev
= pci_get_drvdata (pdev
);
2135 struct de_private
*de
= dev
->priv
;
2139 if (netif_device_present(dev
))
2141 if (!netif_running(dev
))
2143 if ((retval
= pci_enable_device(pdev
))) {
2144 printk (KERN_ERR
"%s: pci_enable_device failed in resume\n",
2150 netif_device_attach(dev
);
2156 #endif /* CONFIG_PM */
2158 static struct pci_driver de_driver
= {
2160 .id_table
= de_pci_tbl
,
2161 .probe
= de_init_one
,
2162 .remove
= __devexit_p(de_remove_one
),
2164 .suspend
= de_suspend
,
2165 .resume
= de_resume
,
2169 static int __init
de_init (void)
2172 printk("%s", version
);
2174 return pci_register_driver(&de_driver
);
2177 static void __exit
de_exit (void)
2179 pci_unregister_driver (&de_driver
);
2182 module_init(de_init
);
2183 module_exit(de_exit
);