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 pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #define DRV_NAME "de2104x"
33 #define DRV_VERSION "0.7"
34 #define DRV_RELDATE "Mar 17, 2004"
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/init.h>
41 #include <linux/pci.h>
42 #include <linux/delay.h>
43 #include <linux/ethtool.h>
44 #include <linux/compiler.h>
45 #include <linux/rtnetlink.h>
46 #include <linux/crc32.h>
47 #include <linux/slab.h>
51 #include <asm/uaccess.h>
52 #include <asm/unaligned.h>
54 /* These identify the driver base version and may not be removed. */
55 static char version
[] =
56 KERN_INFO DRV_NAME
" PCI Ethernet driver v" DRV_VERSION
" (" DRV_RELDATE
")\n";
58 MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
59 MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver");
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(DRV_VERSION
);
63 static int debug
= -1;
64 module_param (debug
, int, 0);
65 MODULE_PARM_DESC (debug
, "de2104x bitmapped message enable number");
67 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
68 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
69 defined(CONFIG_SPARC) || defined(__ia64__) || \
70 defined(__sh__) || defined(__mips__)
71 static int rx_copybreak
= 1518;
73 static int rx_copybreak
= 100;
75 module_param (rx_copybreak
, int, 0);
76 MODULE_PARM_DESC (rx_copybreak
, "de2104x Breakpoint at which Rx packets are copied");
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 netif_printk(de
, rx_err
, KERN_DEBUG
, de
->dev
,
381 "rx err, slot %d status 0x%x len %d\n",
382 rx_tail
, status
, len
);
384 if ((status
& 0x38000300) != 0x0300) {
385 /* Ingore earlier buffers. */
386 if ((status
& 0xffff) != 0x7fff) {
387 netif_warn(de
, rx_err
, de
->dev
,
388 "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
390 de
->net_stats
.rx_length_errors
++;
392 } else if (status
& RxError
) {
393 /* There was a fatal error. */
394 de
->net_stats
.rx_errors
++; /* end of a packet.*/
395 if (status
& 0x0890) de
->net_stats
.rx_length_errors
++;
396 if (status
& RxErrCRC
) de
->net_stats
.rx_crc_errors
++;
397 if (status
& RxErrFIFO
) de
->net_stats
.rx_fifo_errors
++;
401 static void de_rx (struct de_private
*de
)
403 unsigned rx_tail
= de
->rx_tail
;
404 unsigned rx_work
= DE_RX_RING_SIZE
;
411 struct sk_buff
*skb
, *copy_skb
;
412 unsigned copying_skb
, buflen
;
414 skb
= de
->rx_skb
[rx_tail
].skb
;
417 status
= le32_to_cpu(de
->rx_ring
[rx_tail
].opts1
);
418 if (status
& DescOwn
)
421 len
= ((status
>> 16) & 0x7ff) - 4;
422 mapping
= de
->rx_skb
[rx_tail
].mapping
;
424 if (unlikely(drop
)) {
425 de
->net_stats
.rx_dropped
++;
429 if (unlikely((status
& 0x38008300) != 0x0300)) {
430 de_rx_err_acct(de
, rx_tail
, status
, len
);
434 copying_skb
= (len
<= rx_copybreak
);
436 if (unlikely(netif_msg_rx_status(de
)))
437 printk(KERN_DEBUG
"%s: rx slot %d status 0x%x len %d copying? %d\n",
438 de
->dev
->name
, rx_tail
, status
, len
,
441 buflen
= copying_skb
? (len
+ RX_OFFSET
) : de
->rx_buf_sz
;
442 copy_skb
= dev_alloc_skb (buflen
);
443 if (unlikely(!copy_skb
)) {
444 de
->net_stats
.rx_dropped
++;
451 pci_unmap_single(de
->pdev
, mapping
,
452 buflen
, PCI_DMA_FROMDEVICE
);
456 de
->rx_skb
[rx_tail
].mapping
=
457 pci_map_single(de
->pdev
, copy_skb
->data
,
458 buflen
, PCI_DMA_FROMDEVICE
);
459 de
->rx_skb
[rx_tail
].skb
= copy_skb
;
461 pci_dma_sync_single_for_cpu(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
462 skb_reserve(copy_skb
, RX_OFFSET
);
463 skb_copy_from_linear_data(skb
, skb_put(copy_skb
, len
),
465 pci_dma_sync_single_for_device(de
->pdev
, mapping
, len
, PCI_DMA_FROMDEVICE
);
467 /* We'll reuse the original ring buffer. */
471 skb
->protocol
= eth_type_trans (skb
, de
->dev
);
473 de
->net_stats
.rx_packets
++;
474 de
->net_stats
.rx_bytes
+= skb
->len
;
476 if (rc
== NET_RX_DROP
)
480 if (rx_tail
== (DE_RX_RING_SIZE
- 1))
481 de
->rx_ring
[rx_tail
].opts2
=
482 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
484 de
->rx_ring
[rx_tail
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
485 de
->rx_ring
[rx_tail
].addr1
= cpu_to_le32(mapping
);
487 de
->rx_ring
[rx_tail
].opts1
= cpu_to_le32(DescOwn
);
488 rx_tail
= NEXT_RX(rx_tail
);
492 netdev_warn(de
->dev
, "rx work limit reached\n");
494 de
->rx_tail
= rx_tail
;
497 static irqreturn_t
de_interrupt (int irq
, void *dev_instance
)
499 struct net_device
*dev
= dev_instance
;
500 struct de_private
*de
= netdev_priv(dev
);
503 status
= dr32(MacStatus
);
504 if ((!(status
& (IntrOK
|IntrErr
))) || (status
== 0xFFFF))
507 if (netif_msg_intr(de
))
508 printk(KERN_DEBUG
"%s: intr, status %08x mode %08x desc %u/%u/%u\n",
509 dev
->name
, status
, dr32(MacMode
),
510 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
512 dw32(MacStatus
, status
);
514 if (status
& (RxIntr
| RxEmpty
)) {
516 if (status
& RxEmpty
)
517 dw32(RxPoll
, NormalRxPoll
);
520 spin_lock(&de
->lock
);
522 if (status
& (TxIntr
| TxEmpty
))
525 if (status
& (LinkPass
| LinkFail
))
526 de_media_interrupt(de
, status
);
528 spin_unlock(&de
->lock
);
530 if (status
& PciErr
) {
533 pci_read_config_word(de
->pdev
, PCI_STATUS
, &pci_status
);
534 pci_write_config_word(de
->pdev
, PCI_STATUS
, pci_status
);
536 "PCI bus error, status=%08x, PCI status=%04x\n",
543 static void de_tx (struct de_private
*de
)
545 unsigned tx_head
= de
->tx_head
;
546 unsigned tx_tail
= de
->tx_tail
;
548 while (tx_tail
!= tx_head
) {
553 status
= le32_to_cpu(de
->tx_ring
[tx_tail
].opts1
);
554 if (status
& DescOwn
)
557 skb
= de
->tx_skb
[tx_tail
].skb
;
559 if (unlikely(skb
== DE_DUMMY_SKB
))
562 if (unlikely(skb
== DE_SETUP_SKB
)) {
563 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
564 sizeof(de
->setup_frame
), PCI_DMA_TODEVICE
);
568 pci_unmap_single(de
->pdev
, de
->tx_skb
[tx_tail
].mapping
,
569 skb
->len
, PCI_DMA_TODEVICE
);
571 if (status
& LastFrag
) {
572 if (status
& TxError
) {
573 if (netif_msg_tx_err(de
))
574 printk(KERN_DEBUG
"%s: tx err, status 0x%x\n",
575 de
->dev
->name
, status
);
576 de
->net_stats
.tx_errors
++;
578 de
->net_stats
.tx_window_errors
++;
579 if (status
& TxMaxCol
)
580 de
->net_stats
.tx_aborted_errors
++;
581 if (status
& TxLinkFail
)
582 de
->net_stats
.tx_carrier_errors
++;
583 if (status
& TxFIFOUnder
)
584 de
->net_stats
.tx_fifo_errors
++;
586 de
->net_stats
.tx_packets
++;
587 de
->net_stats
.tx_bytes
+= skb
->len
;
588 if (netif_msg_tx_done(de
))
589 printk(KERN_DEBUG
"%s: tx done, slot %d\n",
590 de
->dev
->name
, tx_tail
);
592 dev_kfree_skb_irq(skb
);
596 de
->tx_skb
[tx_tail
].skb
= NULL
;
598 tx_tail
= NEXT_TX(tx_tail
);
601 de
->tx_tail
= tx_tail
;
603 if (netif_queue_stopped(de
->dev
) && (TX_BUFFS_AVAIL(de
) > (DE_TX_RING_SIZE
/ 4)))
604 netif_wake_queue(de
->dev
);
607 static netdev_tx_t
de_start_xmit (struct sk_buff
*skb
,
608 struct net_device
*dev
)
610 struct de_private
*de
= netdev_priv(dev
);
611 unsigned int entry
, tx_free
;
612 u32 mapping
, len
, flags
= FirstFrag
| LastFrag
;
615 spin_lock_irq(&de
->lock
);
617 tx_free
= TX_BUFFS_AVAIL(de
);
619 netif_stop_queue(dev
);
620 spin_unlock_irq(&de
->lock
);
621 return NETDEV_TX_BUSY
;
627 txd
= &de
->tx_ring
[entry
];
630 mapping
= pci_map_single(de
->pdev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
631 if (entry
== (DE_TX_RING_SIZE
- 1))
633 if (!tx_free
|| (tx_free
== (DE_TX_RING_SIZE
/ 2)))
636 txd
->opts2
= cpu_to_le32(flags
);
637 txd
->addr1
= cpu_to_le32(mapping
);
639 de
->tx_skb
[entry
].skb
= skb
;
640 de
->tx_skb
[entry
].mapping
= mapping
;
643 txd
->opts1
= cpu_to_le32(DescOwn
);
646 de
->tx_head
= NEXT_TX(entry
);
647 if (netif_msg_tx_queued(de
))
648 printk(KERN_DEBUG
"%s: tx queued, slot %d, skblen %d\n",
649 dev
->name
, entry
, skb
->len
);
652 netif_stop_queue(dev
);
654 spin_unlock_irq(&de
->lock
);
656 /* Trigger an immediate transmit demand. */
657 dw32(TxPoll
, NormalTxPoll
);
662 /* Set or clear the multicast filter for this adaptor.
663 Note that we only use exclusion around actually queueing the
664 new frame, not around filling de->setup_frame. This is non-deterministic
665 when re-entered but still correct. */
668 #define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0)
670 static void build_setup_frame_hash(u16
*setup_frm
, struct net_device
*dev
)
672 struct de_private
*de
= netdev_priv(dev
);
674 struct netdev_hw_addr
*ha
;
678 memset(hash_table
, 0, sizeof(hash_table
));
679 set_bit_le(255, hash_table
); /* Broadcast entry */
680 /* This should work on big-endian machines as well. */
681 netdev_for_each_mc_addr(ha
, dev
) {
682 int index
= ether_crc_le(ETH_ALEN
, ha
->addr
) & 0x1ff;
684 set_bit_le(index
, hash_table
);
687 for (i
= 0; i
< 32; i
++) {
688 *setup_frm
++ = hash_table
[i
];
689 *setup_frm
++ = hash_table
[i
];
691 setup_frm
= &de
->setup_frame
[13*6];
693 /* Fill the final entry with our physical address. */
694 eaddrs
= (u16
*)dev
->dev_addr
;
695 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
696 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
697 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
700 static void build_setup_frame_perfect(u16
*setup_frm
, struct net_device
*dev
)
702 struct de_private
*de
= netdev_priv(dev
);
703 struct netdev_hw_addr
*ha
;
706 /* We have <= 14 addresses so we can use the wonderful
707 16 address perfect filtering of the Tulip. */
708 netdev_for_each_mc_addr(ha
, dev
) {
709 eaddrs
= (u16
*) ha
->addr
;
710 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
711 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
712 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
714 /* Fill the unused entries with the broadcast address. */
715 memset(setup_frm
, 0xff, (15 - netdev_mc_count(dev
)) * 12);
716 setup_frm
= &de
->setup_frame
[15*6];
718 /* Fill the final entry with our physical address. */
719 eaddrs
= (u16
*)dev
->dev_addr
;
720 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
721 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
722 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
726 static void __de_set_rx_mode (struct net_device
*dev
)
728 struct de_private
*de
= netdev_priv(dev
);
733 struct de_desc
*dummy_txd
= NULL
;
735 macmode
= dr32(MacMode
) & ~(AcceptAllMulticast
| AcceptAllPhys
);
737 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
738 macmode
|= AcceptAllMulticast
| AcceptAllPhys
;
742 if ((netdev_mc_count(dev
) > 1000) || (dev
->flags
& IFF_ALLMULTI
)) {
743 /* Too many to filter well -- accept all multicasts. */
744 macmode
|= AcceptAllMulticast
;
748 /* Note that only the low-address shortword of setup_frame is valid!
749 The values are doubled for big-endian architectures. */
750 if (netdev_mc_count(dev
) > 14) /* Must use a multicast hash table. */
751 build_setup_frame_hash (de
->setup_frame
, dev
);
753 build_setup_frame_perfect (de
->setup_frame
, dev
);
756 * Now add this frame to the Tx list.
761 /* Avoid a chip errata by prefixing a dummy entry. */
763 de
->tx_skb
[entry
].skb
= DE_DUMMY_SKB
;
765 dummy_txd
= &de
->tx_ring
[entry
];
766 dummy_txd
->opts2
= (entry
== (DE_TX_RING_SIZE
- 1)) ?
767 cpu_to_le32(RingEnd
) : 0;
768 dummy_txd
->addr1
= 0;
770 /* Must set DescOwned later to avoid race with chip */
772 entry
= NEXT_TX(entry
);
775 de
->tx_skb
[entry
].skb
= DE_SETUP_SKB
;
776 de
->tx_skb
[entry
].mapping
= mapping
=
777 pci_map_single (de
->pdev
, de
->setup_frame
,
778 sizeof (de
->setup_frame
), PCI_DMA_TODEVICE
);
780 /* Put the setup frame on the Tx list. */
781 txd
= &de
->tx_ring
[entry
];
782 if (entry
== (DE_TX_RING_SIZE
- 1))
783 txd
->opts2
= cpu_to_le32(SetupFrame
| RingEnd
| sizeof (de
->setup_frame
));
785 txd
->opts2
= cpu_to_le32(SetupFrame
| sizeof (de
->setup_frame
));
786 txd
->addr1
= cpu_to_le32(mapping
);
789 txd
->opts1
= cpu_to_le32(DescOwn
);
793 dummy_txd
->opts1
= cpu_to_le32(DescOwn
);
797 de
->tx_head
= NEXT_TX(entry
);
799 if (TX_BUFFS_AVAIL(de
) == 0)
800 netif_stop_queue(dev
);
802 /* Trigger an immediate transmit demand. */
803 dw32(TxPoll
, NormalTxPoll
);
806 if (macmode
!= dr32(MacMode
))
807 dw32(MacMode
, macmode
);
810 static void de_set_rx_mode (struct net_device
*dev
)
813 struct de_private
*de
= netdev_priv(dev
);
815 spin_lock_irqsave (&de
->lock
, flags
);
816 __de_set_rx_mode(dev
);
817 spin_unlock_irqrestore (&de
->lock
, flags
);
820 static inline void de_rx_missed(struct de_private
*de
, u32 rx_missed
)
822 if (unlikely(rx_missed
& RxMissedOver
))
823 de
->net_stats
.rx_missed_errors
+= RxMissedMask
;
825 de
->net_stats
.rx_missed_errors
+= (rx_missed
& RxMissedMask
);
828 static void __de_get_stats(struct de_private
*de
)
830 u32 tmp
= dr32(RxMissed
); /* self-clearing */
832 de_rx_missed(de
, tmp
);
835 static struct net_device_stats
*de_get_stats(struct net_device
*dev
)
837 struct de_private
*de
= netdev_priv(dev
);
839 /* The chip only need report frame silently dropped. */
840 spin_lock_irq(&de
->lock
);
841 if (netif_running(dev
) && netif_device_present(dev
))
843 spin_unlock_irq(&de
->lock
);
845 return &de
->net_stats
;
848 static inline int de_is_running (struct de_private
*de
)
850 return (dr32(MacStatus
) & (RxState
| TxState
)) ? 1 : 0;
853 static void de_stop_rxtx (struct de_private
*de
)
856 unsigned int i
= 1300/100;
858 macmode
= dr32(MacMode
);
859 if (macmode
& RxTx
) {
860 dw32(MacMode
, macmode
& ~RxTx
);
864 /* wait until in-flight frame completes.
865 * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
866 * Typically expect this loop to end in < 50 us on 100BT.
869 if (!de_is_running(de
))
874 netdev_warn(de
->dev
, "timeout expired, stopping DMA\n");
877 static inline void de_start_rxtx (struct de_private
*de
)
881 macmode
= dr32(MacMode
);
882 if ((macmode
& RxTx
) != RxTx
) {
883 dw32(MacMode
, macmode
| RxTx
);
888 static void de_stop_hw (struct de_private
*de
)
896 dw32(MacStatus
, dr32(MacStatus
));
901 de
->tx_head
= de
->tx_tail
= 0;
904 static void de_link_up(struct de_private
*de
)
906 if (!netif_carrier_ok(de
->dev
)) {
907 netif_carrier_on(de
->dev
);
908 netif_info(de
, link
, de
->dev
, "link up, media %s\n",
909 media_name
[de
->media_type
]);
913 static void de_link_down(struct de_private
*de
)
915 if (netif_carrier_ok(de
->dev
)) {
916 netif_carrier_off(de
->dev
);
917 netif_info(de
, link
, de
->dev
, "link down\n");
921 static void de_set_media (struct de_private
*de
)
923 unsigned media
= de
->media_type
;
924 u32 macmode
= dr32(MacMode
);
926 if (de_is_running(de
))
927 netdev_warn(de
->dev
, "chip is running while changing media!\n");
930 dw32(CSR11
, FULL_DUPLEX_MAGIC
);
931 dw32(CSR13
, 0); /* Reset phy */
932 dw32(CSR14
, de
->media
[media
].csr14
);
933 dw32(CSR15
, de
->media
[media
].csr15
);
934 dw32(CSR13
, de
->media
[media
].csr13
);
936 /* must delay 10ms before writing to other registers,
941 if (media
== DE_MEDIA_TP_FD
)
942 macmode
|= FullDuplex
;
944 macmode
&= ~FullDuplex
;
946 netif_info(de
, link
, de
->dev
, "set link %s\n", media_name
[media
]);
947 netif_info(de
, hw
, de
->dev
, "mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n",
948 dr32(MacMode
), dr32(SIAStatus
),
949 dr32(CSR13
), dr32(CSR14
), dr32(CSR15
));
950 netif_info(de
, hw
, de
->dev
, "set mode 0x%x, set sia 0x%x,0x%x,0x%x\n",
951 macmode
, de
->media
[media
].csr13
,
952 de
->media
[media
].csr14
, de
->media
[media
].csr15
);
953 if (macmode
!= dr32(MacMode
))
954 dw32(MacMode
, macmode
);
957 static void de_next_media (struct de_private
*de
, const u32
*media
,
958 unsigned int n_media
)
962 for (i
= 0; i
< n_media
; i
++) {
963 if (de_ok_to_advertise(de
, media
[i
])) {
964 de
->media_type
= media
[i
];
970 static void de21040_media_timer (unsigned long data
)
972 struct de_private
*de
= (struct de_private
*) data
;
973 struct net_device
*dev
= de
->dev
;
974 u32 status
= dr32(SIAStatus
);
975 unsigned int carrier
;
978 carrier
= (status
& NetCxnErr
) ? 0 : 1;
981 if (de
->media_type
!= DE_MEDIA_AUI
&& (status
& LinkFailStatus
))
984 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
985 add_timer(&de
->media_timer
);
986 if (!netif_carrier_ok(dev
))
989 netif_info(de
, timer
, dev
, "%s link ok, status %x\n",
990 media_name
[de
->media_type
], status
);
999 if (de
->media_type
== DE_MEDIA_AUI
) {
1000 static const u32 next_state
= DE_MEDIA_TP
;
1001 de_next_media(de
, &next_state
, 1);
1003 static const u32 next_state
= DE_MEDIA_AUI
;
1004 de_next_media(de
, &next_state
, 1);
1007 spin_lock_irqsave(&de
->lock
, flags
);
1009 spin_unlock_irqrestore(&de
->lock
, flags
);
1014 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1015 add_timer(&de
->media_timer
);
1017 netif_info(de
, timer
, dev
, "no link, trying media %s, status %x\n",
1018 media_name
[de
->media_type
], status
);
1021 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
)
1023 switch (new_media
) {
1024 case DE_MEDIA_TP_AUTO
:
1025 if (!(de
->media_advertise
& ADVERTISED_Autoneg
))
1027 if (!(de
->media_advertise
& (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
)))
1031 if (!(de
->media_advertise
& ADVERTISED_BNC
))
1035 if (!(de
->media_advertise
& ADVERTISED_AUI
))
1039 if (!(de
->media_advertise
& ADVERTISED_10baseT_Half
))
1042 case DE_MEDIA_TP_FD
:
1043 if (!(de
->media_advertise
& ADVERTISED_10baseT_Full
))
1051 static void de21041_media_timer (unsigned long data
)
1053 struct de_private
*de
= (struct de_private
*) data
;
1054 struct net_device
*dev
= de
->dev
;
1055 u32 status
= dr32(SIAStatus
);
1056 unsigned int carrier
;
1057 unsigned long flags
;
1059 /* clear port active bits */
1060 dw32(SIAStatus
, NonselPortActive
| SelPortActive
);
1062 carrier
= (status
& NetCxnErr
) ? 0 : 1;
1065 if ((de
->media_type
== DE_MEDIA_TP_AUTO
||
1066 de
->media_type
== DE_MEDIA_TP
||
1067 de
->media_type
== DE_MEDIA_TP_FD
) &&
1068 (status
& LinkFailStatus
))
1071 de
->media_timer
.expires
= jiffies
+ DE_TIMER_LINK
;
1072 add_timer(&de
->media_timer
);
1073 if (!netif_carrier_ok(dev
))
1076 netif_info(de
, timer
, dev
,
1077 "%s link ok, mode %x status %x\n",
1078 media_name
[de
->media_type
],
1079 dr32(MacMode
), status
);
1085 /* if media type locked, don't switch media */
1089 /* if activity detected, use that as hint for new media type */
1090 if (status
& NonselPortActive
) {
1091 unsigned int have_media
= 1;
1093 /* if AUI/BNC selected, then activity is on TP port */
1094 if (de
->media_type
== DE_MEDIA_AUI
||
1095 de
->media_type
== DE_MEDIA_BNC
) {
1096 if (de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
))
1097 de
->media_type
= DE_MEDIA_TP_AUTO
;
1102 /* TP selected. If there is only TP and BNC, then it's BNC */
1103 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_BNC
) &&
1104 de_ok_to_advertise(de
, DE_MEDIA_BNC
))
1105 de
->media_type
= DE_MEDIA_BNC
;
1107 /* TP selected. If there is only TP and AUI, then it's AUI */
1108 else if (((de
->media_supported
& DE_AUI_BNC
) == SUPPORTED_AUI
) &&
1109 de_ok_to_advertise(de
, DE_MEDIA_AUI
))
1110 de
->media_type
= DE_MEDIA_AUI
;
1112 /* otherwise, ignore the hint */
1121 * Absent or ambiguous activity hint, move to next advertised
1122 * media state. If de->media_type is left unchanged, this
1123 * simply resets the PHY and reloads the current media settings.
1125 if (de
->media_type
== DE_MEDIA_AUI
) {
1126 static const u32 next_states
[] = {
1127 DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1129 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1130 } else if (de
->media_type
== DE_MEDIA_BNC
) {
1131 static const u32 next_states
[] = {
1132 DE_MEDIA_TP_AUTO
, DE_MEDIA_AUI
1134 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1136 static const u32 next_states
[] = {
1137 DE_MEDIA_AUI
, DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1139 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1143 spin_lock_irqsave(&de
->lock
, flags
);
1145 spin_unlock_irqrestore(&de
->lock
, flags
);
1150 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1151 add_timer(&de
->media_timer
);
1153 netif_info(de
, timer
, dev
, "no link, trying media %s, status %x\n",
1154 media_name
[de
->media_type
], status
);
1157 static void de_media_interrupt (struct de_private
*de
, u32 status
)
1159 if (status
& LinkPass
) {
1160 /* Ignore if current media is AUI or BNC and we can't use TP */
1161 if ((de
->media_type
== DE_MEDIA_AUI
||
1162 de
->media_type
== DE_MEDIA_BNC
) &&
1164 !de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
)))
1166 /* If current media is not TP, change it to TP */
1167 if ((de
->media_type
== DE_MEDIA_AUI
||
1168 de
->media_type
== DE_MEDIA_BNC
)) {
1169 de
->media_type
= DE_MEDIA_TP_AUTO
;
1175 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_LINK
);
1179 BUG_ON(!(status
& LinkFail
));
1180 /* Mark the link as down only if current media is TP */
1181 if (netif_carrier_ok(de
->dev
) && de
->media_type
!= DE_MEDIA_AUI
&&
1182 de
->media_type
!= DE_MEDIA_BNC
) {
1184 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1188 static int de_reset_mac (struct de_private
*de
)
1193 * Reset MAC. de4x5.c and tulip.c examined for "advice"
1197 if (dr32(BusMode
) == 0xffffffff)
1200 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1201 dw32 (BusMode
, CmdReset
);
1204 dw32 (BusMode
, de_bus_mode
);
1207 for (tmp
= 0; tmp
< 5; tmp
++) {
1214 status
= dr32(MacStatus
);
1215 if (status
& (RxState
| TxState
))
1217 if (status
== 0xffffffff)
1222 static void de_adapter_wake (struct de_private
*de
)
1229 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1230 if (pmctl
& PM_Mask
) {
1232 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1234 /* de4x5.c delays, so we do too */
1239 static void de_adapter_sleep (struct de_private
*de
)
1246 dw32(CSR13
, 0); /* Reset phy */
1247 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1249 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1252 static int de_init_hw (struct de_private
*de
)
1254 struct net_device
*dev
= de
->dev
;
1258 de_adapter_wake(de
);
1260 macmode
= dr32(MacMode
) & ~MacModeClear
;
1262 rc
= de_reset_mac(de
);
1266 de_set_media(de
); /* reset phy */
1268 dw32(RxRingAddr
, de
->ring_dma
);
1269 dw32(TxRingAddr
, de
->ring_dma
+ (sizeof(struct de_desc
) * DE_RX_RING_SIZE
));
1271 dw32(MacMode
, RxTx
| macmode
);
1273 dr32(RxMissed
); /* self-clearing */
1275 dw32(IntrMask
, de_intr_mask
);
1277 de_set_rx_mode(dev
);
1282 static int de_refill_rx (struct de_private
*de
)
1286 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1287 struct sk_buff
*skb
;
1289 skb
= dev_alloc_skb(de
->rx_buf_sz
);
1295 de
->rx_skb
[i
].mapping
= pci_map_single(de
->pdev
,
1296 skb
->data
, de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1297 de
->rx_skb
[i
].skb
= skb
;
1299 de
->rx_ring
[i
].opts1
= cpu_to_le32(DescOwn
);
1300 if (i
== (DE_RX_RING_SIZE
- 1))
1301 de
->rx_ring
[i
].opts2
=
1302 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
1304 de
->rx_ring
[i
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
1305 de
->rx_ring
[i
].addr1
= cpu_to_le32(de
->rx_skb
[i
].mapping
);
1306 de
->rx_ring
[i
].addr2
= 0;
1316 static int de_init_rings (struct de_private
*de
)
1318 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1319 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1322 de
->tx_head
= de
->tx_tail
= 0;
1324 return de_refill_rx (de
);
1327 static int de_alloc_rings (struct de_private
*de
)
1329 de
->rx_ring
= pci_alloc_consistent(de
->pdev
, DE_RING_BYTES
, &de
->ring_dma
);
1332 de
->tx_ring
= &de
->rx_ring
[DE_RX_RING_SIZE
];
1333 return de_init_rings(de
);
1336 static void de_clean_rings (struct de_private
*de
)
1340 memset(de
->rx_ring
, 0, sizeof(struct de_desc
) * DE_RX_RING_SIZE
);
1341 de
->rx_ring
[DE_RX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1343 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1344 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1347 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1348 if (de
->rx_skb
[i
].skb
) {
1349 pci_unmap_single(de
->pdev
, de
->rx_skb
[i
].mapping
,
1350 de
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1351 dev_kfree_skb(de
->rx_skb
[i
].skb
);
1355 for (i
= 0; i
< DE_TX_RING_SIZE
; i
++) {
1356 struct sk_buff
*skb
= de
->tx_skb
[i
].skb
;
1357 if ((skb
) && (skb
!= DE_DUMMY_SKB
)) {
1358 if (skb
!= DE_SETUP_SKB
) {
1359 de
->net_stats
.tx_dropped
++;
1360 pci_unmap_single(de
->pdev
,
1361 de
->tx_skb
[i
].mapping
,
1362 skb
->len
, PCI_DMA_TODEVICE
);
1365 pci_unmap_single(de
->pdev
,
1366 de
->tx_skb
[i
].mapping
,
1367 sizeof(de
->setup_frame
),
1373 memset(&de
->rx_skb
, 0, sizeof(struct ring_info
) * DE_RX_RING_SIZE
);
1374 memset(&de
->tx_skb
, 0, sizeof(struct ring_info
) * DE_TX_RING_SIZE
);
1377 static void de_free_rings (struct de_private
*de
)
1380 pci_free_consistent(de
->pdev
, DE_RING_BYTES
, de
->rx_ring
, de
->ring_dma
);
1385 static int de_open (struct net_device
*dev
)
1387 struct de_private
*de
= netdev_priv(dev
);
1390 netif_printk(de
, ifup
, KERN_DEBUG
, dev
, "enabling interface\n");
1392 de
->rx_buf_sz
= (dev
->mtu
<= 1500 ? PKT_BUF_SZ
: dev
->mtu
+ 32);
1394 rc
= de_alloc_rings(de
);
1396 netdev_err(dev
, "ring allocation failure, err=%d\n", rc
);
1402 rc
= request_irq(dev
->irq
, de_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
1404 netdev_err(dev
, "IRQ %d request failure, err=%d\n",
1409 rc
= de_init_hw(de
);
1411 netdev_err(dev
, "h/w init failure, err=%d\n", rc
);
1412 goto err_out_free_irq
;
1415 netif_start_queue(dev
);
1416 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1421 free_irq(dev
->irq
, dev
);
1427 static int de_close (struct net_device
*dev
)
1429 struct de_private
*de
= netdev_priv(dev
);
1430 unsigned long flags
;
1432 netif_printk(de
, ifdown
, KERN_DEBUG
, dev
, "disabling interface\n");
1434 del_timer_sync(&de
->media_timer
);
1436 spin_lock_irqsave(&de
->lock
, flags
);
1438 netif_stop_queue(dev
);
1439 netif_carrier_off(dev
);
1440 spin_unlock_irqrestore(&de
->lock
, flags
);
1442 free_irq(dev
->irq
, dev
);
1445 de_adapter_sleep(de
);
1449 static void de_tx_timeout (struct net_device
*dev
)
1451 struct de_private
*de
= netdev_priv(dev
);
1453 netdev_printk(KERN_DEBUG
, dev
,
1454 "NIC status %08x mode %08x sia %08x desc %u/%u/%u\n",
1455 dr32(MacStatus
), dr32(MacMode
), dr32(SIAStatus
),
1456 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
1458 del_timer_sync(&de
->media_timer
);
1460 disable_irq(dev
->irq
);
1461 spin_lock_irq(&de
->lock
);
1464 netif_stop_queue(dev
);
1465 netif_carrier_off(dev
);
1467 spin_unlock_irq(&de
->lock
);
1468 enable_irq(dev
->irq
);
1470 /* Update the error counts. */
1473 synchronize_irq(dev
->irq
);
1480 netif_wake_queue(dev
);
1483 static void __de_get_regs(struct de_private
*de
, u8
*buf
)
1486 u32
*rbuf
= (u32
*)buf
;
1489 for (i
= 0; i
< DE_NUM_REGS
; i
++)
1490 rbuf
[i
] = dr32(i
* 8);
1492 /* handle self-clearing RxMissed counter, CSR8 */
1493 de_rx_missed(de
, rbuf
[8]);
1496 static int __de_get_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1498 ecmd
->supported
= de
->media_supported
;
1499 ecmd
->transceiver
= XCVR_INTERNAL
;
1500 ecmd
->phy_address
= 0;
1501 ecmd
->advertising
= de
->media_advertise
;
1503 switch (de
->media_type
) {
1505 ecmd
->port
= PORT_AUI
;
1508 ecmd
->port
= PORT_BNC
;
1511 ecmd
->port
= PORT_TP
;
1515 ethtool_cmd_speed_set(ecmd
, 10);
1517 if (dr32(MacMode
) & FullDuplex
)
1518 ecmd
->duplex
= DUPLEX_FULL
;
1520 ecmd
->duplex
= DUPLEX_HALF
;
1523 ecmd
->autoneg
= AUTONEG_DISABLE
;
1525 ecmd
->autoneg
= AUTONEG_ENABLE
;
1527 /* ignore maxtxpkt, maxrxpkt for now */
1532 static int __de_set_settings(struct de_private
*de
, struct ethtool_cmd
*ecmd
)
1535 unsigned int media_lock
;
1537 if (ethtool_cmd_speed(ecmd
) != 10)
1539 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
1541 if (ecmd
->port
!= PORT_TP
&& ecmd
->port
!= PORT_AUI
&& ecmd
->port
!= PORT_BNC
)
1543 if (de
->de21040
&& ecmd
->port
== PORT_BNC
)
1545 if (ecmd
->transceiver
!= XCVR_INTERNAL
)
1547 if (ecmd
->autoneg
!= AUTONEG_DISABLE
&& ecmd
->autoneg
!= AUTONEG_ENABLE
)
1549 if (ecmd
->advertising
& ~de
->media_supported
)
1551 if (ecmd
->autoneg
== AUTONEG_ENABLE
&&
1552 (!(ecmd
->advertising
& ADVERTISED_Autoneg
)))
1555 switch (ecmd
->port
) {
1557 new_media
= DE_MEDIA_AUI
;
1558 if (!(ecmd
->advertising
& ADVERTISED_AUI
))
1562 new_media
= DE_MEDIA_BNC
;
1563 if (!(ecmd
->advertising
& ADVERTISED_BNC
))
1567 if (ecmd
->autoneg
== AUTONEG_ENABLE
)
1568 new_media
= DE_MEDIA_TP_AUTO
;
1569 else if (ecmd
->duplex
== DUPLEX_FULL
)
1570 new_media
= DE_MEDIA_TP_FD
;
1572 new_media
= DE_MEDIA_TP
;
1573 if (!(ecmd
->advertising
& ADVERTISED_TP
))
1575 if (!(ecmd
->advertising
& (ADVERTISED_10baseT_Full
| ADVERTISED_10baseT_Half
)))
1580 media_lock
= (ecmd
->autoneg
== AUTONEG_ENABLE
) ? 0 : 1;
1582 if ((new_media
== de
->media_type
) &&
1583 (media_lock
== de
->media_lock
) &&
1584 (ecmd
->advertising
== de
->media_advertise
))
1585 return 0; /* nothing to change */
1588 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1591 de
->media_type
= new_media
;
1592 de
->media_lock
= media_lock
;
1593 de
->media_advertise
= ecmd
->advertising
;
1595 if (netif_running(de
->dev
))
1601 static void de_get_drvinfo (struct net_device
*dev
,struct ethtool_drvinfo
*info
)
1603 struct de_private
*de
= netdev_priv(dev
);
1605 strcpy (info
->driver
, DRV_NAME
);
1606 strcpy (info
->version
, DRV_VERSION
);
1607 strcpy (info
->bus_info
, pci_name(de
->pdev
));
1608 info
->eedump_len
= DE_EEPROM_SIZE
;
1611 static int de_get_regs_len(struct net_device
*dev
)
1613 return DE_REGS_SIZE
;
1616 static int de_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1618 struct de_private
*de
= netdev_priv(dev
);
1621 spin_lock_irq(&de
->lock
);
1622 rc
= __de_get_settings(de
, ecmd
);
1623 spin_unlock_irq(&de
->lock
);
1628 static int de_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1630 struct de_private
*de
= netdev_priv(dev
);
1633 spin_lock_irq(&de
->lock
);
1634 rc
= __de_set_settings(de
, ecmd
);
1635 spin_unlock_irq(&de
->lock
);
1640 static u32
de_get_msglevel(struct net_device
*dev
)
1642 struct de_private
*de
= netdev_priv(dev
);
1644 return de
->msg_enable
;
1647 static void de_set_msglevel(struct net_device
*dev
, u32 msglvl
)
1649 struct de_private
*de
= netdev_priv(dev
);
1651 de
->msg_enable
= msglvl
;
1654 static int de_get_eeprom(struct net_device
*dev
,
1655 struct ethtool_eeprom
*eeprom
, u8
*data
)
1657 struct de_private
*de
= netdev_priv(dev
);
1661 if ((eeprom
->offset
!= 0) || (eeprom
->magic
!= 0) ||
1662 (eeprom
->len
!= DE_EEPROM_SIZE
))
1664 memcpy(data
, de
->ee_data
, eeprom
->len
);
1669 static int de_nway_reset(struct net_device
*dev
)
1671 struct de_private
*de
= netdev_priv(dev
);
1674 if (de
->media_type
!= DE_MEDIA_TP_AUTO
)
1676 if (netif_carrier_ok(de
->dev
))
1679 status
= dr32(SIAStatus
);
1680 dw32(SIAStatus
, (status
& ~NWayState
) | NWayRestart
);
1681 netif_info(de
, link
, dev
, "link nway restart, status %x,%x\n",
1682 status
, dr32(SIAStatus
));
1686 static void de_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
1689 struct de_private
*de
= netdev_priv(dev
);
1691 regs
->version
= (DE_REGS_VER
<< 2) | de
->de21040
;
1693 spin_lock_irq(&de
->lock
);
1694 __de_get_regs(de
, data
);
1695 spin_unlock_irq(&de
->lock
);
1698 static const struct ethtool_ops de_ethtool_ops
= {
1699 .get_link
= ethtool_op_get_link
,
1700 .get_drvinfo
= de_get_drvinfo
,
1701 .get_regs_len
= de_get_regs_len
,
1702 .get_settings
= de_get_settings
,
1703 .set_settings
= de_set_settings
,
1704 .get_msglevel
= de_get_msglevel
,
1705 .set_msglevel
= de_set_msglevel
,
1706 .get_eeprom
= de_get_eeprom
,
1707 .nway_reset
= de_nway_reset
,
1708 .get_regs
= de_get_regs
,
1711 static void __devinit
de21040_get_mac_address (struct de_private
*de
)
1715 dw32 (ROMCmd
, 0); /* Reset the pointer with a dummy write. */
1718 for (i
= 0; i
< 6; i
++) {
1719 int value
, boguscnt
= 100000;
1721 value
= dr32(ROMCmd
);
1723 } while (value
< 0 && --boguscnt
> 0);
1724 de
->dev
->dev_addr
[i
] = value
;
1727 pr_warn("timeout reading 21040 MAC address byte %u\n",
1732 static void __devinit
de21040_get_media_info(struct de_private
*de
)
1736 de
->media_type
= DE_MEDIA_TP
;
1737 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
|
1738 SUPPORTED_10baseT_Half
| SUPPORTED_AUI
;
1739 de
->media_advertise
= de
->media_supported
;
1741 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1745 case DE_MEDIA_TP_FD
:
1746 de
->media
[i
].type
= i
;
1747 de
->media
[i
].csr13
= t21040_csr13
[i
];
1748 de
->media
[i
].csr14
= t21040_csr14
[i
];
1749 de
->media
[i
].csr15
= t21040_csr15
[i
];
1752 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1758 /* Note: this routine returns extra data bits for size detection. */
1759 static unsigned __devinit
tulip_read_eeprom(void __iomem
*regs
, int location
, int addr_len
)
1762 unsigned retval
= 0;
1763 void __iomem
*ee_addr
= regs
+ ROMCmd
;
1764 int read_cmd
= location
| (EE_READ_CMD
<< addr_len
);
1766 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1767 writel(EE_ENB
, ee_addr
);
1769 /* Shift the read command bits out. */
1770 for (i
= 4 + addr_len
; i
>= 0; i
--) {
1771 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
1772 writel(EE_ENB
| dataval
, ee_addr
);
1774 writel(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
1776 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1778 writel(EE_ENB
, ee_addr
);
1781 for (i
= 16; i
> 0; i
--) {
1782 writel(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
1784 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1785 writel(EE_ENB
, ee_addr
);
1789 /* Terminate the EEPROM access. */
1790 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1794 static void __devinit
de21041_get_srom_info (struct de_private
*de
)
1796 unsigned i
, sa_offset
= 0, ofs
;
1797 u8 ee_data
[DE_EEPROM_SIZE
+ 6] = {};
1798 unsigned ee_addr_size
= tulip_read_eeprom(de
->regs
, 0xff, 8) & 0x40000 ? 8 : 6;
1799 struct de_srom_info_leaf
*il
;
1802 /* download entire eeprom */
1803 for (i
= 0; i
< DE_EEPROM_WORDS
; i
++)
1804 ((__le16
*)ee_data
)[i
] =
1805 cpu_to_le16(tulip_read_eeprom(de
->regs
, i
, ee_addr_size
));
1807 /* DEC now has a specification but early board makers
1808 just put the address in the first EEPROM locations. */
1809 /* This does memcmp(eedata, eedata+16, 8) */
1811 #ifndef CONFIG_MIPS_COBALT
1813 for (i
= 0; i
< 8; i
++)
1814 if (ee_data
[i
] != ee_data
[16+i
])
1819 /* store MAC address */
1820 for (i
= 0; i
< 6; i
++)
1821 de
->dev
->dev_addr
[i
] = ee_data
[i
+ sa_offset
];
1823 /* get offset of controller 0 info leaf. ignore 2nd byte. */
1824 ofs
= ee_data
[SROMC0InfoLeaf
];
1825 if (ofs
>= (sizeof(ee_data
) - sizeof(struct de_srom_info_leaf
) - sizeof(struct de_srom_media_block
)))
1828 /* get pointer to info leaf */
1829 il
= (struct de_srom_info_leaf
*) &ee_data
[ofs
];
1831 /* paranoia checks */
1832 if (il
->n_blocks
== 0)
1834 if ((sizeof(ee_data
) - ofs
) <
1835 (sizeof(struct de_srom_info_leaf
) + (sizeof(struct de_srom_media_block
) * il
->n_blocks
)))
1838 /* get default media type */
1839 switch (get_unaligned(&il
->default_media
)) {
1840 case 0x0001: de
->media_type
= DE_MEDIA_BNC
; break;
1841 case 0x0002: de
->media_type
= DE_MEDIA_AUI
; break;
1842 case 0x0204: de
->media_type
= DE_MEDIA_TP_FD
; break;
1843 default: de
->media_type
= DE_MEDIA_TP_AUTO
; break;
1846 if (netif_msg_probe(de
))
1847 pr_info("de%d: SROM leaf offset %u, default media %s\n",
1848 de
->board_idx
, ofs
, media_name
[de
->media_type
]);
1850 /* init SIA register values to defaults */
1851 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1852 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1853 de
->media
[i
].csr13
= 0xffff;
1854 de
->media
[i
].csr14
= 0xffff;
1855 de
->media
[i
].csr15
= 0xffff;
1858 /* parse media blocks to see what medias are supported,
1859 * and if any custom CSR values are provided
1861 bufp
= ((void *)il
) + sizeof(*il
);
1862 for (i
= 0; i
< il
->n_blocks
; i
++) {
1863 struct de_srom_media_block
*ib
= bufp
;
1866 /* index based on media type in media block */
1867 switch(ib
->opts
& MediaBlockMask
) {
1868 case 0: /* 10baseT */
1869 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Half
1870 | SUPPORTED_Autoneg
;
1872 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1875 de
->media_supported
|= SUPPORTED_BNC
;
1879 de
->media_supported
|= SUPPORTED_AUI
;
1882 case 4: /* 10baseT-FD */
1883 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
1884 | SUPPORTED_Autoneg
;
1885 idx
= DE_MEDIA_TP_FD
;
1886 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1892 de
->media
[idx
].type
= idx
;
1894 if (netif_msg_probe(de
))
1895 pr_info("de%d: media block #%u: %s",
1897 media_name
[de
->media
[idx
].type
]);
1899 bufp
+= sizeof (ib
->opts
);
1901 if (ib
->opts
& MediaCustomCSRs
) {
1902 de
->media
[idx
].csr13
= get_unaligned(&ib
->csr13
);
1903 de
->media
[idx
].csr14
= get_unaligned(&ib
->csr14
);
1904 de
->media
[idx
].csr15
= get_unaligned(&ib
->csr15
);
1905 bufp
+= sizeof(ib
->csr13
) + sizeof(ib
->csr14
) +
1908 if (netif_msg_probe(de
))
1909 pr_cont(" (%x,%x,%x)\n",
1910 de
->media
[idx
].csr13
,
1911 de
->media
[idx
].csr14
,
1912 de
->media
[idx
].csr15
);
1915 if (netif_msg_probe(de
))
1919 if (bufp
> ((void *)&ee_data
[DE_EEPROM_SIZE
- 3]))
1923 de
->media_advertise
= de
->media_supported
;
1926 /* fill in defaults, for cases where custom CSRs not used */
1927 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1928 if (de
->media
[i
].csr13
== 0xffff)
1929 de
->media
[i
].csr13
= t21041_csr13
[i
];
1930 if (de
->media
[i
].csr14
== 0xffff) {
1931 /* autonegotiation is broken at least on some chip
1932 revisions - rev. 0x21 works, 0x11 does not */
1933 if (de
->pdev
->revision
< 0x20)
1934 de
->media
[i
].csr14
= t21041_csr14_brk
[i
];
1936 de
->media
[i
].csr14
= t21041_csr14
[i
];
1938 if (de
->media
[i
].csr15
== 0xffff)
1939 de
->media
[i
].csr15
= t21041_csr15
[i
];
1942 de
->ee_data
= kmemdup(&ee_data
[0], DE_EEPROM_SIZE
, GFP_KERNEL
);
1947 /* for error cases, it's ok to assume we support all these */
1948 for (i
= 0; i
< DE_MAX_MEDIA
; i
++)
1949 de
->media
[i
].type
= i
;
1950 de
->media_supported
=
1951 SUPPORTED_10baseT_Half
|
1952 SUPPORTED_10baseT_Full
|
1960 static const struct net_device_ops de_netdev_ops
= {
1961 .ndo_open
= de_open
,
1962 .ndo_stop
= de_close
,
1963 .ndo_set_multicast_list
= de_set_rx_mode
,
1964 .ndo_start_xmit
= de_start_xmit
,
1965 .ndo_get_stats
= de_get_stats
,
1966 .ndo_tx_timeout
= de_tx_timeout
,
1967 .ndo_change_mtu
= eth_change_mtu
,
1968 .ndo_set_mac_address
= eth_mac_addr
,
1969 .ndo_validate_addr
= eth_validate_addr
,
1972 static int __devinit
de_init_one (struct pci_dev
*pdev
,
1973 const struct pci_device_id
*ent
)
1975 struct net_device
*dev
;
1976 struct de_private
*de
;
1979 unsigned long pciaddr
;
1980 static int board_idx
= -1;
1986 printk("%s", version
);
1989 /* allocate a new ethernet device structure, and fill in defaults */
1990 dev
= alloc_etherdev(sizeof(struct de_private
));
1994 dev
->netdev_ops
= &de_netdev_ops
;
1995 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1996 dev
->ethtool_ops
= &de_ethtool_ops
;
1997 dev
->watchdog_timeo
= TX_TIMEOUT
;
1999 de
= netdev_priv(dev
);
2000 de
->de21040
= ent
->driver_data
== 0 ? 1 : 0;
2003 de
->msg_enable
= (debug
< 0 ? DE_DEF_MSG_ENABLE
: debug
);
2004 de
->board_idx
= board_idx
;
2005 spin_lock_init (&de
->lock
);
2006 init_timer(&de
->media_timer
);
2008 de
->media_timer
.function
= de21040_media_timer
;
2010 de
->media_timer
.function
= de21041_media_timer
;
2011 de
->media_timer
.data
= (unsigned long) de
;
2013 netif_carrier_off(dev
);
2015 /* wake up device, assign resources */
2016 rc
= pci_enable_device(pdev
);
2020 /* reserve PCI resources to ensure driver atomicity */
2021 rc
= pci_request_regions(pdev
, DRV_NAME
);
2023 goto err_out_disable
;
2025 /* check for invalid IRQ value */
2026 if (pdev
->irq
< 2) {
2028 pr_err("invalid irq (%d) for pci dev %s\n",
2029 pdev
->irq
, pci_name(pdev
));
2033 dev
->irq
= pdev
->irq
;
2035 /* obtain and check validity of PCI I/O address */
2036 pciaddr
= pci_resource_start(pdev
, 1);
2039 pr_err("no MMIO resource for pci dev %s\n", pci_name(pdev
));
2042 if (pci_resource_len(pdev
, 1) < DE_REGS_SIZE
) {
2044 pr_err("MMIO resource (%llx) too small on pci dev %s\n",
2045 (unsigned long long)pci_resource_len(pdev
, 1),
2050 /* remap CSR registers */
2051 regs
= ioremap_nocache(pciaddr
, DE_REGS_SIZE
);
2054 pr_err("Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
2055 (unsigned long long)pci_resource_len(pdev
, 1),
2056 pciaddr
, pci_name(pdev
));
2059 dev
->base_addr
= (unsigned long) regs
;
2062 de_adapter_wake(de
);
2064 /* make sure hardware is not running */
2065 rc
= de_reset_mac(de
);
2067 pr_err("Cannot reset MAC, pci dev %s\n", pci_name(pdev
));
2071 /* get MAC address, initialize default media type and
2072 * get list of supported media
2075 de21040_get_mac_address(de
);
2076 de21040_get_media_info(de
);
2078 de21041_get_srom_info(de
);
2081 /* register new network interface with kernel */
2082 rc
= register_netdev(dev
);
2086 /* print info about board and interface just registered */
2087 netdev_info(dev
, "%s at 0x%lx, %pM, IRQ %d\n",
2088 de
->de21040
? "21040" : "21041",
2093 pci_set_drvdata(pdev
, dev
);
2095 /* enable busmastering */
2096 pci_set_master(pdev
);
2098 /* put adapter to sleep */
2099 de_adapter_sleep(de
);
2107 pci_release_regions(pdev
);
2109 pci_disable_device(pdev
);
2115 static void __devexit
de_remove_one (struct pci_dev
*pdev
)
2117 struct net_device
*dev
= pci_get_drvdata(pdev
);
2118 struct de_private
*de
= netdev_priv(dev
);
2121 unregister_netdev(dev
);
2124 pci_release_regions(pdev
);
2125 pci_disable_device(pdev
);
2126 pci_set_drvdata(pdev
, NULL
);
2132 static int de_suspend (struct pci_dev
*pdev
, pm_message_t state
)
2134 struct net_device
*dev
= pci_get_drvdata (pdev
);
2135 struct de_private
*de
= netdev_priv(dev
);
2138 if (netif_running (dev
)) {
2139 del_timer_sync(&de
->media_timer
);
2141 disable_irq(dev
->irq
);
2142 spin_lock_irq(&de
->lock
);
2145 netif_stop_queue(dev
);
2146 netif_device_detach(dev
);
2147 netif_carrier_off(dev
);
2149 spin_unlock_irq(&de
->lock
);
2150 enable_irq(dev
->irq
);
2152 /* Update the error counts. */
2155 synchronize_irq(dev
->irq
);
2158 de_adapter_sleep(de
);
2159 pci_disable_device(pdev
);
2161 netif_device_detach(dev
);
2167 static int de_resume (struct pci_dev
*pdev
)
2169 struct net_device
*dev
= pci_get_drvdata (pdev
);
2170 struct de_private
*de
= netdev_priv(dev
);
2174 if (netif_device_present(dev
))
2176 if (!netif_running(dev
))
2178 if ((retval
= pci_enable_device(pdev
))) {
2179 netdev_err(dev
, "pci_enable_device failed in resume\n");
2182 pci_set_master(pdev
);
2186 netif_device_attach(dev
);
2192 #endif /* CONFIG_PM */
2194 static struct pci_driver de_driver
= {
2196 .id_table
= de_pci_tbl
,
2197 .probe
= de_init_one
,
2198 .remove
= __devexit_p(de_remove_one
),
2200 .suspend
= de_suspend
,
2201 .resume
= de_resume
,
2205 static int __init
de_init (void)
2208 printk("%s", version
);
2210 return pci_register_driver(&de_driver
);
2213 static void __exit
de_exit (void)
2215 pci_unregister_driver (&de_driver
);
2218 module_init(de_init
);
2219 module_exit(de_exit
);