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_RELDATE "Mar 17, 2004"
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.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 <linux/uaccess.h>
52 #include <asm/unaligned.h>
54 MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
55 MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver");
56 MODULE_LICENSE("GPL");
58 static int debug
= -1;
59 module_param (debug
, int, 0);
60 MODULE_PARM_DESC (debug
, "de2104x bitmapped message enable number");
62 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
63 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
64 defined(CONFIG_SPARC) || defined(__ia64__) || \
65 defined(__sh__) || defined(__mips__)
66 static int rx_copybreak
= 1518;
68 static int rx_copybreak
= 100;
70 module_param (rx_copybreak
, int, 0);
71 MODULE_PARM_DESC (rx_copybreak
, "de2104x Breakpoint at which Rx packets are copied");
73 #define DE_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
81 /* Descriptor skip length in 32 bit longwords. */
82 #ifndef CONFIG_DE2104X_DSL
85 #define DSL CONFIG_DE2104X_DSL
88 #define DE_RX_RING_SIZE 128
89 #define DE_TX_RING_SIZE 64
90 #define DE_RING_BYTES \
91 ((sizeof(struct de_desc) * DE_RX_RING_SIZE) + \
92 (sizeof(struct de_desc) * DE_TX_RING_SIZE))
93 #define NEXT_TX(N) (((N) + 1) & (DE_TX_RING_SIZE - 1))
94 #define NEXT_RX(N) (((N) + 1) & (DE_RX_RING_SIZE - 1))
95 #define TX_BUFFS_AVAIL(CP) \
96 (((CP)->tx_tail <= (CP)->tx_head) ? \
97 (CP)->tx_tail + (DE_TX_RING_SIZE - 1) - (CP)->tx_head : \
98 (CP)->tx_tail - (CP)->tx_head - 1)
100 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
103 #define DE_SETUP_SKB ((struct sk_buff *) 1)
104 #define DE_DUMMY_SKB ((struct sk_buff *) 2)
105 #define DE_SETUP_FRAME_WORDS 96
106 #define DE_EEPROM_WORDS 256
107 #define DE_EEPROM_SIZE (DE_EEPROM_WORDS * sizeof(u16))
108 #define DE_MAX_MEDIA 5
110 #define DE_MEDIA_TP_AUTO 0
111 #define DE_MEDIA_BNC 1
112 #define DE_MEDIA_AUI 2
113 #define DE_MEDIA_TP 3
114 #define DE_MEDIA_TP_FD 4
115 #define DE_MEDIA_INVALID DE_MAX_MEDIA
116 #define DE_MEDIA_FIRST 0
117 #define DE_MEDIA_LAST (DE_MAX_MEDIA - 1)
118 #define DE_AUI_BNC (SUPPORTED_AUI | SUPPORTED_BNC)
120 #define DE_TIMER_LINK (60 * HZ)
121 #define DE_TIMER_NO_LINK (5 * HZ)
123 #define DE_NUM_REGS 16
124 #define DE_REGS_SIZE (DE_NUM_REGS * sizeof(u32))
125 #define DE_REGS_VER 1
127 /* Time in jiffies before concluding the transmitter is hung. */
128 #define TX_TIMEOUT (6*HZ)
130 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
131 to support a pre-NWay full-duplex signaling mechanism using short frames.
132 No one knows what it should be, but if left at its default value some
133 10base2(!) packets trigger a full-duplex-request interrupt. */
134 #define FULL_DUPLEX_MAGIC 0x6969
157 CacheAlign16
= 0x00008000,
158 BurstLen4
= 0x00000400,
159 DescSkipLen
= (DSL
<< 2),
162 NormalTxPoll
= (1 << 0),
163 NormalRxPoll
= (1 << 0),
165 /* Tx/Rx descriptor status bits */
168 RxErrLong
= (1 << 7),
170 RxErrFIFO
= (1 << 0),
171 RxErrRunt
= (1 << 11),
172 RxErrFrame
= (1 << 14),
174 FirstFrag
= (1 << 29),
175 LastFrag
= (1 << 30),
177 TxFIFOUnder
= (1 << 1),
178 TxLinkFail
= (1 << 2) | (1 << 10) | (1 << 11),
181 TxJabber
= (1 << 14),
182 SetupFrame
= (1 << 27),
193 TxState
= (1 << 22) | (1 << 21) | (1 << 20),
194 RxState
= (1 << 19) | (1 << 18) | (1 << 17),
195 LinkFail
= (1 << 12),
197 RxStopped
= (1 << 8),
198 TxStopped
= (1 << 1),
201 TxEnable
= (1 << 13),
203 RxTx
= TxEnable
| RxEnable
,
204 FullDuplex
= (1 << 9),
205 AcceptAllMulticast
= (1 << 7),
206 AcceptAllPhys
= (1 << 6),
208 MacModeClear
= (1<<12) | (1<<11) | (1<<10) | (1<<8) | (1<<3) |
209 RxTx
| BOCnt
| AcceptAllPhys
| AcceptAllMulticast
,
212 EE_SHIFT_CLK
= 0x02, /* EEPROM shift clock. */
213 EE_CS
= 0x01, /* EEPROM chip select. */
214 EE_DATA_WRITE
= 0x04, /* Data from the Tulip to EEPROM. */
217 EE_DATA_READ
= 0x08, /* Data from the EEPROM chip. */
218 EE_ENB
= (0x4800 | EE_CS
),
220 /* The EEPROM commands include the alway-set leading bit. */
224 RxMissedOver
= (1 << 16),
225 RxMissedMask
= 0xffff,
227 /* SROM-related bits */
229 MediaBlockMask
= 0x3f,
230 MediaCustomCSRs
= (1 << 6),
233 PM_Sleep
= (1 << 31),
234 PM_Snooze
= (1 << 30),
235 PM_Mask
= PM_Sleep
| PM_Snooze
,
238 NWayState
= (1 << 14) | (1 << 13) | (1 << 12),
239 NWayRestart
= (1 << 12),
240 NonselPortActive
= (1 << 9),
241 SelPortActive
= (1 << 8),
242 LinkFailStatus
= (1 << 2),
243 NetCxnErr
= (1 << 1),
246 static const u32 de_intr_mask
=
247 IntrOK
| IntrErr
| RxIntr
| RxEmpty
| TxIntr
| TxEmpty
|
248 LinkPass
| LinkFail
| PciErr
;
251 * Set the programmable burst length to 4 longwords for all:
252 * DMA errors result without these values. Cache align 16 long.
254 static const u32 de_bus_mode
= CacheAlign16
| BurstLen4
| DescSkipLen
;
256 struct de_srom_media_block
{
263 struct de_srom_info_leaf
{
280 u16 type
; /* DE_MEDIA_xxx */
297 struct net_device
*dev
;
300 struct de_desc
*rx_ring
;
301 struct de_desc
*tx_ring
;
302 struct ring_info tx_skb
[DE_TX_RING_SIZE
];
303 struct ring_info rx_skb
[DE_RX_RING_SIZE
];
309 struct pci_dev
*pdev
;
311 u16 setup_frame
[DE_SETUP_FRAME_WORDS
];
316 struct media_info media
[DE_MAX_MEDIA
];
317 struct timer_list media_timer
;
321 unsigned de21040
: 1;
322 unsigned media_lock
: 1;
326 static void de_set_rx_mode (struct net_device
*dev
);
327 static void de_tx (struct de_private
*de
);
328 static void de_clean_rings (struct de_private
*de
);
329 static void de_media_interrupt (struct de_private
*de
, u32 status
);
330 static void de21040_media_timer (struct timer_list
*t
);
331 static void de21041_media_timer (struct timer_list
*t
);
332 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
);
335 static const struct pci_device_id de_pci_tbl
[] = {
336 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP
,
337 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
338 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_PLUS
,
339 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
342 MODULE_DEVICE_TABLE(pci
, de_pci_tbl
);
344 static const char * const media_name
[DE_MAX_MEDIA
] = {
352 /* 21040 transceiver register settings:
353 * TP AUTO(unused), BNC(unused), AUI, TP, TP FD*/
354 static u16 t21040_csr13
[] = { 0, 0, 0x8F09, 0x8F01, 0x8F01, };
355 static u16 t21040_csr14
[] = { 0, 0, 0x0705, 0xFFFF, 0xFFFD, };
356 static u16 t21040_csr15
[] = { 0, 0, 0x0006, 0x0000, 0x0000, };
358 /* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/
359 static u16 t21041_csr13
[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
360 static u16 t21041_csr14
[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
361 /* If on-chip autonegotiation is broken, use half-duplex (FF3F) instead */
362 static u16 t21041_csr14_brk
[] = { 0xFF3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
363 static u16 t21041_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
366 #define dr32(reg) ioread32(de->regs + (reg))
367 #define dw32(reg, val) iowrite32((val), de->regs + (reg))
370 static void de_rx_err_acct (struct de_private
*de
, unsigned rx_tail
,
373 netif_dbg(de
, rx_err
, de
->dev
,
374 "rx err, slot %d status 0x%x len %d\n",
375 rx_tail
, status
, len
);
377 if ((status
& 0x38000300) != 0x0300) {
378 /* Ingore earlier buffers. */
379 if ((status
& 0xffff) != 0x7fff) {
380 netif_warn(de
, rx_err
, de
->dev
,
381 "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
383 de
->dev
->stats
.rx_length_errors
++;
385 } else if (status
& RxError
) {
386 /* There was a fatal error. */
387 de
->dev
->stats
.rx_errors
++; /* end of a packet.*/
388 if (status
& 0x0890) de
->dev
->stats
.rx_length_errors
++;
389 if (status
& RxErrCRC
) de
->dev
->stats
.rx_crc_errors
++;
390 if (status
& RxErrFIFO
) de
->dev
->stats
.rx_fifo_errors
++;
394 static void de_rx (struct de_private
*de
)
396 unsigned rx_tail
= de
->rx_tail
;
397 unsigned rx_work
= DE_RX_RING_SIZE
;
404 struct sk_buff
*skb
, *copy_skb
;
405 unsigned copying_skb
, buflen
;
407 skb
= de
->rx_skb
[rx_tail
].skb
;
410 status
= le32_to_cpu(de
->rx_ring
[rx_tail
].opts1
);
411 if (status
& DescOwn
)
414 /* the length is actually a 15 bit value here according
415 * to Table 4-1 in the DE2104x spec so mask is 0x7fff
417 len
= ((status
>> 16) & 0x7fff) - 4;
418 mapping
= de
->rx_skb
[rx_tail
].mapping
;
420 if (unlikely(drop
)) {
421 de
->dev
->stats
.rx_dropped
++;
425 if (unlikely((status
& 0x38008300) != 0x0300)) {
426 de_rx_err_acct(de
, rx_tail
, status
, len
);
430 copying_skb
= (len
<= rx_copybreak
);
432 netif_dbg(de
, rx_status
, de
->dev
,
433 "rx slot %d status 0x%x len %d copying? %d\n",
434 rx_tail
, status
, len
, copying_skb
);
436 buflen
= copying_skb
? (len
+ RX_OFFSET
) : de
->rx_buf_sz
;
437 copy_skb
= netdev_alloc_skb(de
->dev
, buflen
);
438 if (unlikely(!copy_skb
)) {
439 de
->dev
->stats
.rx_dropped
++;
446 dma_unmap_single(&de
->pdev
->dev
, mapping
, buflen
,
451 de
->rx_skb
[rx_tail
].mapping
=
452 dma_map_single(&de
->pdev
->dev
, copy_skb
->data
,
453 buflen
, DMA_FROM_DEVICE
);
454 de
->rx_skb
[rx_tail
].skb
= copy_skb
;
456 dma_sync_single_for_cpu(&de
->pdev
->dev
, mapping
, len
,
458 skb_reserve(copy_skb
, RX_OFFSET
);
459 skb_copy_from_linear_data(skb
, skb_put(copy_skb
, len
),
461 dma_sync_single_for_device(&de
->pdev
->dev
, mapping
,
462 len
, DMA_FROM_DEVICE
);
464 /* We'll reuse the original ring buffer. */
468 skb
->protocol
= eth_type_trans (skb
, de
->dev
);
470 de
->dev
->stats
.rx_packets
++;
471 de
->dev
->stats
.rx_bytes
+= skb
->len
;
473 if (rc
== NET_RX_DROP
)
477 if (rx_tail
== (DE_RX_RING_SIZE
- 1))
478 de
->rx_ring
[rx_tail
].opts2
=
479 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
481 de
->rx_ring
[rx_tail
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
482 de
->rx_ring
[rx_tail
].addr1
= cpu_to_le32(mapping
);
484 de
->rx_ring
[rx_tail
].opts1
= cpu_to_le32(DescOwn
);
485 rx_tail
= NEXT_RX(rx_tail
);
489 netdev_warn(de
->dev
, "rx work limit reached\n");
491 de
->rx_tail
= rx_tail
;
494 static irqreturn_t
de_interrupt (int irq
, void *dev_instance
)
496 struct net_device
*dev
= dev_instance
;
497 struct de_private
*de
= netdev_priv(dev
);
500 status
= dr32(MacStatus
);
501 if ((!(status
& (IntrOK
|IntrErr
))) || (status
== 0xFFFF))
504 netif_dbg(de
, intr
, dev
, "intr, status %08x mode %08x desc %u/%u/%u\n",
505 status
, dr32(MacMode
),
506 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
508 dw32(MacStatus
, status
);
510 if (status
& (RxIntr
| RxEmpty
)) {
512 if (status
& RxEmpty
)
513 dw32(RxPoll
, NormalRxPoll
);
516 spin_lock(&de
->lock
);
518 if (status
& (TxIntr
| TxEmpty
))
521 if (status
& (LinkPass
| LinkFail
))
522 de_media_interrupt(de
, status
);
524 spin_unlock(&de
->lock
);
526 if (status
& PciErr
) {
529 pci_read_config_word(de
->pdev
, PCI_STATUS
, &pci_status
);
530 pci_write_config_word(de
->pdev
, PCI_STATUS
, pci_status
);
532 "PCI bus error, status=%08x, PCI status=%04x\n",
539 static void de_tx (struct de_private
*de
)
541 unsigned tx_head
= de
->tx_head
;
542 unsigned tx_tail
= de
->tx_tail
;
544 while (tx_tail
!= tx_head
) {
549 status
= le32_to_cpu(de
->tx_ring
[tx_tail
].opts1
);
550 if (status
& DescOwn
)
553 skb
= de
->tx_skb
[tx_tail
].skb
;
555 if (unlikely(skb
== DE_DUMMY_SKB
))
558 if (unlikely(skb
== DE_SETUP_SKB
)) {
559 dma_unmap_single(&de
->pdev
->dev
,
560 de
->tx_skb
[tx_tail
].mapping
,
561 sizeof(de
->setup_frame
),
566 dma_unmap_single(&de
->pdev
->dev
, de
->tx_skb
[tx_tail
].mapping
,
567 skb
->len
, DMA_TO_DEVICE
);
569 if (status
& LastFrag
) {
570 if (status
& TxError
) {
571 netif_dbg(de
, tx_err
, de
->dev
,
572 "tx err, status 0x%x\n",
574 de
->dev
->stats
.tx_errors
++;
576 de
->dev
->stats
.tx_window_errors
++;
577 if (status
& TxMaxCol
)
578 de
->dev
->stats
.tx_aborted_errors
++;
579 if (status
& TxLinkFail
)
580 de
->dev
->stats
.tx_carrier_errors
++;
581 if (status
& TxFIFOUnder
)
582 de
->dev
->stats
.tx_fifo_errors
++;
584 de
->dev
->stats
.tx_packets
++;
585 de
->dev
->stats
.tx_bytes
+= skb
->len
;
586 netif_dbg(de
, tx_done
, de
->dev
,
587 "tx done, slot %d\n", tx_tail
);
589 dev_consume_skb_irq(skb
);
593 de
->tx_skb
[tx_tail
].skb
= NULL
;
595 tx_tail
= NEXT_TX(tx_tail
);
598 de
->tx_tail
= tx_tail
;
600 if (netif_queue_stopped(de
->dev
) && (TX_BUFFS_AVAIL(de
) > (DE_TX_RING_SIZE
/ 4)))
601 netif_wake_queue(de
->dev
);
604 static netdev_tx_t
de_start_xmit (struct sk_buff
*skb
,
605 struct net_device
*dev
)
607 struct de_private
*de
= netdev_priv(dev
);
608 unsigned int entry
, tx_free
;
609 u32 mapping
, len
, flags
= FirstFrag
| LastFrag
;
612 spin_lock_irq(&de
->lock
);
614 tx_free
= TX_BUFFS_AVAIL(de
);
616 netif_stop_queue(dev
);
617 spin_unlock_irq(&de
->lock
);
618 return NETDEV_TX_BUSY
;
624 txd
= &de
->tx_ring
[entry
];
627 mapping
= dma_map_single(&de
->pdev
->dev
, skb
->data
, len
,
629 if (entry
== (DE_TX_RING_SIZE
- 1))
631 if (!tx_free
|| (tx_free
== (DE_TX_RING_SIZE
/ 2)))
634 txd
->opts2
= cpu_to_le32(flags
);
635 txd
->addr1
= cpu_to_le32(mapping
);
637 de
->tx_skb
[entry
].skb
= skb
;
638 de
->tx_skb
[entry
].mapping
= mapping
;
641 txd
->opts1
= cpu_to_le32(DescOwn
);
644 de
->tx_head
= NEXT_TX(entry
);
645 netif_dbg(de
, tx_queued
, dev
, "tx queued, slot %d, skblen %d\n",
649 netif_stop_queue(dev
);
651 spin_unlock_irq(&de
->lock
);
653 /* Trigger an immediate transmit demand. */
654 dw32(TxPoll
, NormalTxPoll
);
659 /* Set or clear the multicast filter for this adaptor.
660 Note that we only use exclusion around actually queueing the
661 new frame, not around filling de->setup_frame. This is non-deterministic
662 when re-entered but still correct. */
664 static void build_setup_frame_hash(u16
*setup_frm
, struct net_device
*dev
)
666 struct de_private
*de
= netdev_priv(dev
);
668 struct netdev_hw_addr
*ha
;
672 memset(hash_table
, 0, sizeof(hash_table
));
673 __set_bit_le(255, hash_table
); /* Broadcast entry */
674 /* This should work on big-endian machines as well. */
675 netdev_for_each_mc_addr(ha
, dev
) {
676 int index
= ether_crc_le(ETH_ALEN
, ha
->addr
) & 0x1ff;
678 __set_bit_le(index
, hash_table
);
681 for (i
= 0; i
< 32; i
++) {
682 *setup_frm
++ = hash_table
[i
];
683 *setup_frm
++ = hash_table
[i
];
685 setup_frm
= &de
->setup_frame
[13*6];
687 /* Fill the final entry with our physical address. */
688 eaddrs
= (u16
*)dev
->dev_addr
;
689 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
690 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
691 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
694 static void build_setup_frame_perfect(u16
*setup_frm
, struct net_device
*dev
)
696 struct de_private
*de
= netdev_priv(dev
);
697 struct netdev_hw_addr
*ha
;
700 /* We have <= 14 addresses so we can use the wonderful
701 16 address perfect filtering of the Tulip. */
702 netdev_for_each_mc_addr(ha
, dev
) {
703 eaddrs
= (u16
*) ha
->addr
;
704 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
705 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
706 *setup_frm
++ = *eaddrs
; *setup_frm
++ = *eaddrs
++;
708 /* Fill the unused entries with the broadcast address. */
709 memset(setup_frm
, 0xff, (15 - netdev_mc_count(dev
)) * 12);
710 setup_frm
= &de
->setup_frame
[15*6];
712 /* Fill the final entry with our physical address. */
713 eaddrs
= (u16
*)dev
->dev_addr
;
714 *setup_frm
++ = eaddrs
[0]; *setup_frm
++ = eaddrs
[0];
715 *setup_frm
++ = eaddrs
[1]; *setup_frm
++ = eaddrs
[1];
716 *setup_frm
++ = eaddrs
[2]; *setup_frm
++ = eaddrs
[2];
720 static void __de_set_rx_mode (struct net_device
*dev
)
722 struct de_private
*de
= netdev_priv(dev
);
727 struct de_desc
*dummy_txd
= NULL
;
729 macmode
= dr32(MacMode
) & ~(AcceptAllMulticast
| AcceptAllPhys
);
731 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
732 macmode
|= AcceptAllMulticast
| AcceptAllPhys
;
736 if ((netdev_mc_count(dev
) > 1000) || (dev
->flags
& IFF_ALLMULTI
)) {
737 /* Too many to filter well -- accept all multicasts. */
738 macmode
|= AcceptAllMulticast
;
742 /* Note that only the low-address shortword of setup_frame is valid!
743 The values are doubled for big-endian architectures. */
744 if (netdev_mc_count(dev
) > 14) /* Must use a multicast hash table. */
745 build_setup_frame_hash (de
->setup_frame
, dev
);
747 build_setup_frame_perfect (de
->setup_frame
, dev
);
750 * Now add this frame to the Tx list.
755 /* Avoid a chip errata by prefixing a dummy entry. */
757 de
->tx_skb
[entry
].skb
= DE_DUMMY_SKB
;
759 dummy_txd
= &de
->tx_ring
[entry
];
760 dummy_txd
->opts2
= (entry
== (DE_TX_RING_SIZE
- 1)) ?
761 cpu_to_le32(RingEnd
) : 0;
762 dummy_txd
->addr1
= 0;
764 /* Must set DescOwned later to avoid race with chip */
766 entry
= NEXT_TX(entry
);
769 de
->tx_skb
[entry
].skb
= DE_SETUP_SKB
;
770 de
->tx_skb
[entry
].mapping
= mapping
=
771 dma_map_single(&de
->pdev
->dev
, de
->setup_frame
,
772 sizeof(de
->setup_frame
), DMA_TO_DEVICE
);
774 /* Put the setup frame on the Tx list. */
775 txd
= &de
->tx_ring
[entry
];
776 if (entry
== (DE_TX_RING_SIZE
- 1))
777 txd
->opts2
= cpu_to_le32(SetupFrame
| RingEnd
| sizeof (de
->setup_frame
));
779 txd
->opts2
= cpu_to_le32(SetupFrame
| sizeof (de
->setup_frame
));
780 txd
->addr1
= cpu_to_le32(mapping
);
783 txd
->opts1
= cpu_to_le32(DescOwn
);
787 dummy_txd
->opts1
= cpu_to_le32(DescOwn
);
791 de
->tx_head
= NEXT_TX(entry
);
793 if (TX_BUFFS_AVAIL(de
) == 0)
794 netif_stop_queue(dev
);
796 /* Trigger an immediate transmit demand. */
797 dw32(TxPoll
, NormalTxPoll
);
800 if (macmode
!= dr32(MacMode
))
801 dw32(MacMode
, macmode
);
804 static void de_set_rx_mode (struct net_device
*dev
)
807 struct de_private
*de
= netdev_priv(dev
);
809 spin_lock_irqsave (&de
->lock
, flags
);
810 __de_set_rx_mode(dev
);
811 spin_unlock_irqrestore (&de
->lock
, flags
);
814 static inline void de_rx_missed(struct de_private
*de
, u32 rx_missed
)
816 if (unlikely(rx_missed
& RxMissedOver
))
817 de
->dev
->stats
.rx_missed_errors
+= RxMissedMask
;
819 de
->dev
->stats
.rx_missed_errors
+= (rx_missed
& RxMissedMask
);
822 static void __de_get_stats(struct de_private
*de
)
824 u32 tmp
= dr32(RxMissed
); /* self-clearing */
826 de_rx_missed(de
, tmp
);
829 static struct net_device_stats
*de_get_stats(struct net_device
*dev
)
831 struct de_private
*de
= netdev_priv(dev
);
833 /* The chip only need report frame silently dropped. */
834 spin_lock_irq(&de
->lock
);
835 if (netif_running(dev
) && netif_device_present(dev
))
837 spin_unlock_irq(&de
->lock
);
842 static inline int de_is_running (struct de_private
*de
)
844 return (dr32(MacStatus
) & (RxState
| TxState
)) ? 1 : 0;
847 static void de_stop_rxtx (struct de_private
*de
)
850 unsigned int i
= 1300/100;
852 macmode
= dr32(MacMode
);
853 if (macmode
& RxTx
) {
854 dw32(MacMode
, macmode
& ~RxTx
);
858 /* wait until in-flight frame completes.
859 * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
860 * Typically expect this loop to end in < 50 us on 100BT.
863 if (!de_is_running(de
))
868 netdev_warn(de
->dev
, "timeout expired, stopping DMA\n");
871 static inline void de_start_rxtx (struct de_private
*de
)
875 macmode
= dr32(MacMode
);
876 if ((macmode
& RxTx
) != RxTx
) {
877 dw32(MacMode
, macmode
| RxTx
);
882 static void de_stop_hw (struct de_private
*de
)
890 dw32(MacStatus
, dr32(MacStatus
));
895 de
->tx_head
= de
->tx_tail
= 0;
898 static void de_link_up(struct de_private
*de
)
900 if (!netif_carrier_ok(de
->dev
)) {
901 netif_carrier_on(de
->dev
);
902 netif_info(de
, link
, de
->dev
, "link up, media %s\n",
903 media_name
[de
->media_type
]);
907 static void de_link_down(struct de_private
*de
)
909 if (netif_carrier_ok(de
->dev
)) {
910 netif_carrier_off(de
->dev
);
911 netif_info(de
, link
, de
->dev
, "link down\n");
915 static void de_set_media (struct de_private
*de
)
917 unsigned media
= de
->media_type
;
918 u32 macmode
= dr32(MacMode
);
920 if (de_is_running(de
))
921 netdev_warn(de
->dev
, "chip is running while changing media!\n");
924 dw32(CSR11
, FULL_DUPLEX_MAGIC
);
925 dw32(CSR13
, 0); /* Reset phy */
926 dw32(CSR14
, de
->media
[media
].csr14
);
927 dw32(CSR15
, de
->media
[media
].csr15
);
928 dw32(CSR13
, de
->media
[media
].csr13
);
930 /* must delay 10ms before writing to other registers,
935 if (media
== DE_MEDIA_TP_FD
)
936 macmode
|= FullDuplex
;
938 macmode
&= ~FullDuplex
;
940 netif_info(de
, link
, de
->dev
, "set link %s\n", media_name
[media
]);
941 netif_info(de
, hw
, de
->dev
, "mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n",
942 dr32(MacMode
), dr32(SIAStatus
),
943 dr32(CSR13
), dr32(CSR14
), dr32(CSR15
));
944 netif_info(de
, hw
, de
->dev
, "set mode 0x%x, set sia 0x%x,0x%x,0x%x\n",
945 macmode
, de
->media
[media
].csr13
,
946 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
, const 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 (struct timer_list
*t
)
966 struct de_private
*de
= from_timer(de
, t
, media_timer
);
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 netif_info(de
, timer
, dev
, "%s link ok, status %x\n",
984 media_name
[de
->media_type
], status
);
993 if (de
->media_type
== DE_MEDIA_AUI
) {
994 static const u32 next_state
= DE_MEDIA_TP
;
995 de_next_media(de
, &next_state
, 1);
997 static const u32 next_state
= DE_MEDIA_AUI
;
998 de_next_media(de
, &next_state
, 1);
1001 spin_lock_irqsave(&de
->lock
, flags
);
1003 spin_unlock_irqrestore(&de
->lock
, flags
);
1008 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1009 add_timer(&de
->media_timer
);
1011 netif_info(de
, timer
, dev
, "no link, trying media %s, status %x\n",
1012 media_name
[de
->media_type
], status
);
1015 static unsigned int de_ok_to_advertise (struct de_private
*de
, u32 new_media
)
1017 switch (new_media
) {
1018 case DE_MEDIA_TP_AUTO
:
1019 if (!(de
->media_advertise
& ADVERTISED_Autoneg
))
1021 if (!(de
->media_advertise
& (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
)))
1025 if (!(de
->media_advertise
& ADVERTISED_BNC
))
1029 if (!(de
->media_advertise
& ADVERTISED_AUI
))
1033 if (!(de
->media_advertise
& ADVERTISED_10baseT_Half
))
1036 case DE_MEDIA_TP_FD
:
1037 if (!(de
->media_advertise
& ADVERTISED_10baseT_Full
))
1045 static void de21041_media_timer (struct timer_list
*t
)
1047 struct de_private
*de
= from_timer(de
, t
, media_timer
);
1048 struct net_device
*dev
= de
->dev
;
1049 u32 status
= dr32(SIAStatus
);
1050 unsigned int carrier
;
1051 unsigned long flags
;
1053 /* clear port active bits */
1054 dw32(SIAStatus
, NonselPortActive
| SelPortActive
);
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 netif_info(de
, timer
, dev
,
1071 "%s link ok, mode %x status %x\n",
1072 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 static const u32 next_states
[] = {
1121 DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1123 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1124 } else if (de
->media_type
== DE_MEDIA_BNC
) {
1125 static const u32 next_states
[] = {
1126 DE_MEDIA_TP_AUTO
, DE_MEDIA_AUI
1128 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1130 static const u32 next_states
[] = {
1131 DE_MEDIA_AUI
, DE_MEDIA_BNC
, DE_MEDIA_TP_AUTO
1133 de_next_media(de
, next_states
, ARRAY_SIZE(next_states
));
1137 spin_lock_irqsave(&de
->lock
, flags
);
1139 spin_unlock_irqrestore(&de
->lock
, flags
);
1144 de
->media_timer
.expires
= jiffies
+ DE_TIMER_NO_LINK
;
1145 add_timer(&de
->media_timer
);
1147 netif_info(de
, timer
, dev
, "no link, trying media %s, status %x\n",
1148 media_name
[de
->media_type
], status
);
1151 static void de_media_interrupt (struct de_private
*de
, u32 status
)
1153 if (status
& LinkPass
) {
1154 /* Ignore if current media is AUI or BNC and we can't use TP */
1155 if ((de
->media_type
== DE_MEDIA_AUI
||
1156 de
->media_type
== DE_MEDIA_BNC
) &&
1158 !de_ok_to_advertise(de
, DE_MEDIA_TP_AUTO
)))
1160 /* If current media is not TP, change it to TP */
1161 if ((de
->media_type
== DE_MEDIA_AUI
||
1162 de
->media_type
== DE_MEDIA_BNC
)) {
1163 de
->media_type
= DE_MEDIA_TP_AUTO
;
1169 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_LINK
);
1173 BUG_ON(!(status
& LinkFail
));
1174 /* Mark the link as down only if current media is TP */
1175 if (netif_carrier_ok(de
->dev
) && de
->media_type
!= DE_MEDIA_AUI
&&
1176 de
->media_type
!= DE_MEDIA_BNC
) {
1178 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1182 static int de_reset_mac (struct de_private
*de
)
1187 * Reset MAC. de4x5.c and tulip.c examined for "advice"
1191 if (dr32(BusMode
) == 0xffffffff)
1194 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1195 dw32 (BusMode
, CmdReset
);
1198 dw32 (BusMode
, de_bus_mode
);
1201 for (tmp
= 0; tmp
< 5; tmp
++) {
1208 status
= dr32(MacStatus
);
1209 if (status
& (RxState
| TxState
))
1211 if (status
== 0xffffffff)
1216 static void de_adapter_wake (struct de_private
*de
)
1223 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1224 if (pmctl
& PM_Mask
) {
1226 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1228 /* de4x5.c delays, so we do too */
1233 static void de_adapter_sleep (struct de_private
*de
)
1240 dw32(CSR13
, 0); /* Reset phy */
1241 pci_read_config_dword(de
->pdev
, PCIPM
, &pmctl
);
1243 pci_write_config_dword(de
->pdev
, PCIPM
, pmctl
);
1246 static int de_init_hw (struct de_private
*de
)
1248 struct net_device
*dev
= de
->dev
;
1252 de_adapter_wake(de
);
1254 macmode
= dr32(MacMode
) & ~MacModeClear
;
1256 rc
= de_reset_mac(de
);
1260 de_set_media(de
); /* reset phy */
1262 dw32(RxRingAddr
, de
->ring_dma
);
1263 dw32(TxRingAddr
, de
->ring_dma
+ (sizeof(struct de_desc
) * DE_RX_RING_SIZE
));
1265 dw32(MacMode
, RxTx
| macmode
);
1267 dr32(RxMissed
); /* self-clearing */
1269 dw32(IntrMask
, de_intr_mask
);
1271 de_set_rx_mode(dev
);
1276 static int de_refill_rx (struct de_private
*de
)
1280 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1281 struct sk_buff
*skb
;
1283 skb
= netdev_alloc_skb(de
->dev
, de
->rx_buf_sz
);
1287 de
->rx_skb
[i
].mapping
= dma_map_single(&de
->pdev
->dev
,
1291 de
->rx_skb
[i
].skb
= skb
;
1293 de
->rx_ring
[i
].opts1
= cpu_to_le32(DescOwn
);
1294 if (i
== (DE_RX_RING_SIZE
- 1))
1295 de
->rx_ring
[i
].opts2
=
1296 cpu_to_le32(RingEnd
| de
->rx_buf_sz
);
1298 de
->rx_ring
[i
].opts2
= cpu_to_le32(de
->rx_buf_sz
);
1299 de
->rx_ring
[i
].addr1
= cpu_to_le32(de
->rx_skb
[i
].mapping
);
1300 de
->rx_ring
[i
].addr2
= 0;
1310 static int de_init_rings (struct de_private
*de
)
1312 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1313 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1316 de
->tx_head
= de
->tx_tail
= 0;
1318 return de_refill_rx (de
);
1321 static int de_alloc_rings (struct de_private
*de
)
1323 de
->rx_ring
= dma_alloc_coherent(&de
->pdev
->dev
, DE_RING_BYTES
,
1324 &de
->ring_dma
, GFP_KERNEL
);
1327 de
->tx_ring
= &de
->rx_ring
[DE_RX_RING_SIZE
];
1328 return de_init_rings(de
);
1331 static void de_clean_rings (struct de_private
*de
)
1335 memset(de
->rx_ring
, 0, sizeof(struct de_desc
) * DE_RX_RING_SIZE
);
1336 de
->rx_ring
[DE_RX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1338 memset(de
->tx_ring
, 0, sizeof(struct de_desc
) * DE_TX_RING_SIZE
);
1339 de
->tx_ring
[DE_TX_RING_SIZE
- 1].opts2
= cpu_to_le32(RingEnd
);
1342 for (i
= 0; i
< DE_RX_RING_SIZE
; i
++) {
1343 if (de
->rx_skb
[i
].skb
) {
1344 dma_unmap_single(&de
->pdev
->dev
,
1345 de
->rx_skb
[i
].mapping
, de
->rx_buf_sz
,
1347 dev_kfree_skb(de
->rx_skb
[i
].skb
);
1351 for (i
= 0; i
< DE_TX_RING_SIZE
; i
++) {
1352 struct sk_buff
*skb
= de
->tx_skb
[i
].skb
;
1353 if ((skb
) && (skb
!= DE_DUMMY_SKB
)) {
1354 if (skb
!= DE_SETUP_SKB
) {
1355 de
->dev
->stats
.tx_dropped
++;
1356 dma_unmap_single(&de
->pdev
->dev
,
1357 de
->tx_skb
[i
].mapping
,
1358 skb
->len
, DMA_TO_DEVICE
);
1361 dma_unmap_single(&de
->pdev
->dev
,
1362 de
->tx_skb
[i
].mapping
,
1363 sizeof(de
->setup_frame
),
1369 memset(&de
->rx_skb
, 0, sizeof(struct ring_info
) * DE_RX_RING_SIZE
);
1370 memset(&de
->tx_skb
, 0, sizeof(struct ring_info
) * DE_TX_RING_SIZE
);
1373 static void de_free_rings (struct de_private
*de
)
1376 dma_free_coherent(&de
->pdev
->dev
, DE_RING_BYTES
, de
->rx_ring
,
1382 static int de_open (struct net_device
*dev
)
1384 struct de_private
*de
= netdev_priv(dev
);
1385 const int irq
= de
->pdev
->irq
;
1388 netif_dbg(de
, ifup
, dev
, "enabling interface\n");
1390 de
->rx_buf_sz
= (dev
->mtu
<= 1500 ? PKT_BUF_SZ
: dev
->mtu
+ 32);
1392 rc
= de_alloc_rings(de
);
1394 netdev_err(dev
, "ring allocation failure, err=%d\n", rc
);
1400 rc
= request_irq(irq
, de_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
1402 netdev_err(dev
, "IRQ %d request failure, err=%d\n", irq
, rc
);
1406 rc
= de_init_hw(de
);
1408 netdev_err(dev
, "h/w init failure, err=%d\n", rc
);
1409 goto err_out_free_irq
;
1412 netif_start_queue(dev
);
1413 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1424 static int de_close (struct net_device
*dev
)
1426 struct de_private
*de
= netdev_priv(dev
);
1427 unsigned long flags
;
1429 netif_dbg(de
, ifdown
, dev
, "disabling interface\n");
1431 del_timer_sync(&de
->media_timer
);
1433 spin_lock_irqsave(&de
->lock
, flags
);
1435 netif_stop_queue(dev
);
1436 netif_carrier_off(dev
);
1437 spin_unlock_irqrestore(&de
->lock
, flags
);
1439 free_irq(de
->pdev
->irq
, dev
);
1442 de_adapter_sleep(de
);
1446 static void de_tx_timeout (struct net_device
*dev
, unsigned int txqueue
)
1448 struct de_private
*de
= netdev_priv(dev
);
1449 const int irq
= de
->pdev
->irq
;
1451 netdev_dbg(dev
, "NIC status %08x mode %08x sia %08x desc %u/%u/%u\n",
1452 dr32(MacStatus
), dr32(MacMode
), dr32(SIAStatus
),
1453 de
->rx_tail
, de
->tx_head
, de
->tx_tail
);
1455 del_timer_sync(&de
->media_timer
);
1458 spin_lock_irq(&de
->lock
);
1461 netif_stop_queue(dev
);
1462 netif_carrier_off(dev
);
1464 spin_unlock_irq(&de
->lock
);
1467 /* Update the error counts. */
1470 synchronize_irq(irq
);
1477 netif_wake_queue(dev
);
1480 static void __de_get_regs(struct de_private
*de
, u8
*buf
)
1483 u32
*rbuf
= (u32
*)buf
;
1486 for (i
= 0; i
< DE_NUM_REGS
; i
++)
1487 rbuf
[i
] = dr32(i
* 8);
1489 /* handle self-clearing RxMissed counter, CSR8 */
1490 de_rx_missed(de
, rbuf
[8]);
1493 static void __de_get_link_ksettings(struct de_private
*de
,
1494 struct ethtool_link_ksettings
*cmd
)
1496 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
1497 de
->media_supported
);
1498 cmd
->base
.phy_address
= 0;
1499 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
1500 de
->media_advertise
);
1502 switch (de
->media_type
) {
1504 cmd
->base
.port
= PORT_AUI
;
1507 cmd
->base
.port
= PORT_BNC
;
1510 cmd
->base
.port
= PORT_TP
;
1514 cmd
->base
.speed
= 10;
1516 if (dr32(MacMode
) & FullDuplex
)
1517 cmd
->base
.duplex
= DUPLEX_FULL
;
1519 cmd
->base
.duplex
= DUPLEX_HALF
;
1522 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
1524 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
1526 /* ignore maxtxpkt, maxrxpkt for now */
1529 static int __de_set_link_ksettings(struct de_private
*de
,
1530 const struct ethtool_link_ksettings
*cmd
)
1533 unsigned int media_lock
;
1534 u8 duplex
= cmd
->base
.duplex
;
1535 u8 port
= cmd
->base
.port
;
1536 u8 autoneg
= cmd
->base
.autoneg
;
1539 ethtool_convert_link_mode_to_legacy_u32(&advertising
,
1540 cmd
->link_modes
.advertising
);
1542 if (cmd
->base
.speed
!= 10)
1544 if (duplex
!= DUPLEX_HALF
&& duplex
!= DUPLEX_FULL
)
1546 if (port
!= PORT_TP
&& port
!= PORT_AUI
&& port
!= PORT_BNC
)
1548 if (de
->de21040
&& port
== PORT_BNC
)
1550 if (autoneg
!= AUTONEG_DISABLE
&& autoneg
!= AUTONEG_ENABLE
)
1552 if (advertising
& ~de
->media_supported
)
1554 if (autoneg
== AUTONEG_ENABLE
&&
1555 (!(advertising
& ADVERTISED_Autoneg
)))
1560 new_media
= DE_MEDIA_AUI
;
1561 if (!(advertising
& ADVERTISED_AUI
))
1565 new_media
= DE_MEDIA_BNC
;
1566 if (!(advertising
& ADVERTISED_BNC
))
1570 if (autoneg
== AUTONEG_ENABLE
)
1571 new_media
= DE_MEDIA_TP_AUTO
;
1572 else if (duplex
== DUPLEX_FULL
)
1573 new_media
= DE_MEDIA_TP_FD
;
1575 new_media
= DE_MEDIA_TP
;
1576 if (!(advertising
& ADVERTISED_TP
))
1578 if (!(advertising
& (ADVERTISED_10baseT_Full
|
1579 ADVERTISED_10baseT_Half
)))
1584 media_lock
= (autoneg
== AUTONEG_ENABLE
) ? 0 : 1;
1586 if ((new_media
== de
->media_type
) &&
1587 (media_lock
== de
->media_lock
) &&
1588 (advertising
== de
->media_advertise
))
1589 return 0; /* nothing to change */
1592 mod_timer(&de
->media_timer
, jiffies
+ DE_TIMER_NO_LINK
);
1595 de
->media_type
= new_media
;
1596 de
->media_lock
= media_lock
;
1597 de
->media_advertise
= advertising
;
1599 if (netif_running(de
->dev
))
1605 static void de_get_drvinfo (struct net_device
*dev
,struct ethtool_drvinfo
*info
)
1607 struct de_private
*de
= netdev_priv(dev
);
1609 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
1610 strlcpy(info
->bus_info
, pci_name(de
->pdev
), sizeof(info
->bus_info
));
1613 static int de_get_regs_len(struct net_device
*dev
)
1615 return DE_REGS_SIZE
;
1618 static int de_get_link_ksettings(struct net_device
*dev
,
1619 struct ethtool_link_ksettings
*cmd
)
1621 struct de_private
*de
= netdev_priv(dev
);
1623 spin_lock_irq(&de
->lock
);
1624 __de_get_link_ksettings(de
, cmd
);
1625 spin_unlock_irq(&de
->lock
);
1630 static int de_set_link_ksettings(struct net_device
*dev
,
1631 const struct ethtool_link_ksettings
*cmd
)
1633 struct de_private
*de
= netdev_priv(dev
);
1636 spin_lock_irq(&de
->lock
);
1637 rc
= __de_set_link_ksettings(de
, cmd
);
1638 spin_unlock_irq(&de
->lock
);
1643 static u32
de_get_msglevel(struct net_device
*dev
)
1645 struct de_private
*de
= netdev_priv(dev
);
1647 return de
->msg_enable
;
1650 static void de_set_msglevel(struct net_device
*dev
, u32 msglvl
)
1652 struct de_private
*de
= netdev_priv(dev
);
1654 de
->msg_enable
= msglvl
;
1657 static int de_get_eeprom(struct net_device
*dev
,
1658 struct ethtool_eeprom
*eeprom
, u8
*data
)
1660 struct de_private
*de
= netdev_priv(dev
);
1664 if ((eeprom
->offset
!= 0) || (eeprom
->magic
!= 0) ||
1665 (eeprom
->len
!= DE_EEPROM_SIZE
))
1667 memcpy(data
, de
->ee_data
, eeprom
->len
);
1672 static int de_nway_reset(struct net_device
*dev
)
1674 struct de_private
*de
= netdev_priv(dev
);
1677 if (de
->media_type
!= DE_MEDIA_TP_AUTO
)
1679 if (netif_carrier_ok(de
->dev
))
1682 status
= dr32(SIAStatus
);
1683 dw32(SIAStatus
, (status
& ~NWayState
) | NWayRestart
);
1684 netif_info(de
, link
, dev
, "link nway restart, status %x,%x\n",
1685 status
, dr32(SIAStatus
));
1689 static void de_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
1692 struct de_private
*de
= netdev_priv(dev
);
1694 regs
->version
= (DE_REGS_VER
<< 2) | de
->de21040
;
1696 spin_lock_irq(&de
->lock
);
1697 __de_get_regs(de
, data
);
1698 spin_unlock_irq(&de
->lock
);
1701 static const struct ethtool_ops de_ethtool_ops
= {
1702 .get_link
= ethtool_op_get_link
,
1703 .get_drvinfo
= de_get_drvinfo
,
1704 .get_regs_len
= de_get_regs_len
,
1705 .get_msglevel
= de_get_msglevel
,
1706 .set_msglevel
= de_set_msglevel
,
1707 .get_eeprom
= de_get_eeprom
,
1708 .nway_reset
= de_nway_reset
,
1709 .get_regs
= de_get_regs
,
1710 .get_link_ksettings
= de_get_link_ksettings
,
1711 .set_link_ksettings
= de_set_link_ksettings
,
1714 static void de21040_get_mac_address(struct de_private
*de
)
1718 dw32 (ROMCmd
, 0); /* Reset the pointer with a dummy write. */
1721 for (i
= 0; i
< 6; i
++) {
1722 int value
, boguscnt
= 100000;
1724 value
= dr32(ROMCmd
);
1726 } while (value
< 0 && --boguscnt
> 0);
1727 de
->dev
->dev_addr
[i
] = value
;
1730 pr_warn("timeout reading 21040 MAC address byte %u\n",
1735 static void de21040_get_media_info(struct de_private
*de
)
1739 de
->media_type
= DE_MEDIA_TP
;
1740 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
|
1741 SUPPORTED_10baseT_Half
| SUPPORTED_AUI
;
1742 de
->media_advertise
= de
->media_supported
;
1744 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1748 case DE_MEDIA_TP_FD
:
1749 de
->media
[i
].type
= i
;
1750 de
->media
[i
].csr13
= t21040_csr13
[i
];
1751 de
->media
[i
].csr14
= t21040_csr14
[i
];
1752 de
->media
[i
].csr15
= t21040_csr15
[i
];
1755 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1761 /* Note: this routine returns extra data bits for size detection. */
1762 static unsigned tulip_read_eeprom(void __iomem
*regs
, int location
,
1766 unsigned retval
= 0;
1767 void __iomem
*ee_addr
= regs
+ ROMCmd
;
1768 int read_cmd
= location
| (EE_READ_CMD
<< addr_len
);
1770 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1771 writel(EE_ENB
, ee_addr
);
1773 /* Shift the read command bits out. */
1774 for (i
= 4 + addr_len
; i
>= 0; i
--) {
1775 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
1776 writel(EE_ENB
| dataval
, ee_addr
);
1778 writel(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
1780 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1782 writel(EE_ENB
, ee_addr
);
1785 for (i
= 16; i
> 0; i
--) {
1786 writel(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
1788 retval
= (retval
<< 1) | ((readl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
1789 writel(EE_ENB
, ee_addr
);
1793 /* Terminate the EEPROM access. */
1794 writel(EE_ENB
& ~EE_CS
, ee_addr
);
1798 static void de21041_get_srom_info(struct de_private
*de
)
1800 unsigned i
, sa_offset
= 0, ofs
;
1801 u8 ee_data
[DE_EEPROM_SIZE
+ 6] = {};
1802 unsigned ee_addr_size
= tulip_read_eeprom(de
->regs
, 0xff, 8) & 0x40000 ? 8 : 6;
1803 struct de_srom_info_leaf
*il
;
1806 /* download entire eeprom */
1807 for (i
= 0; i
< DE_EEPROM_WORDS
; i
++)
1808 ((__le16
*)ee_data
)[i
] =
1809 cpu_to_le16(tulip_read_eeprom(de
->regs
, i
, ee_addr_size
));
1811 /* DEC now has a specification but early board makers
1812 just put the address in the first EEPROM locations. */
1813 /* This does memcmp(eedata, eedata+16, 8) */
1815 #ifndef CONFIG_MIPS_COBALT
1817 for (i
= 0; i
< 8; i
++)
1818 if (ee_data
[i
] != ee_data
[16+i
])
1823 /* store MAC address */
1824 for (i
= 0; i
< 6; i
++)
1825 de
->dev
->dev_addr
[i
] = ee_data
[i
+ sa_offset
];
1827 /* get offset of controller 0 info leaf. ignore 2nd byte. */
1828 ofs
= ee_data
[SROMC0InfoLeaf
];
1829 if (ofs
>= (sizeof(ee_data
) - sizeof(struct de_srom_info_leaf
) - sizeof(struct de_srom_media_block
)))
1832 /* get pointer to info leaf */
1833 il
= (struct de_srom_info_leaf
*) &ee_data
[ofs
];
1835 /* paranoia checks */
1836 if (il
->n_blocks
== 0)
1838 if ((sizeof(ee_data
) - ofs
) <
1839 (sizeof(struct de_srom_info_leaf
) + (sizeof(struct de_srom_media_block
) * il
->n_blocks
)))
1842 /* get default media type */
1843 switch (get_unaligned(&il
->default_media
)) {
1844 case 0x0001: de
->media_type
= DE_MEDIA_BNC
; break;
1845 case 0x0002: de
->media_type
= DE_MEDIA_AUI
; break;
1846 case 0x0204: de
->media_type
= DE_MEDIA_TP_FD
; break;
1847 default: de
->media_type
= DE_MEDIA_TP_AUTO
; break;
1850 if (netif_msg_probe(de
))
1851 pr_info("de%d: SROM leaf offset %u, default media %s\n",
1852 de
->board_idx
, ofs
, media_name
[de
->media_type
]);
1854 /* init SIA register values to defaults */
1855 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1856 de
->media
[i
].type
= DE_MEDIA_INVALID
;
1857 de
->media
[i
].csr13
= 0xffff;
1858 de
->media
[i
].csr14
= 0xffff;
1859 de
->media
[i
].csr15
= 0xffff;
1862 /* parse media blocks to see what medias are supported,
1863 * and if any custom CSR values are provided
1865 bufp
= ((void *)il
) + sizeof(*il
);
1866 for (i
= 0; i
< il
->n_blocks
; i
++) {
1867 struct de_srom_media_block
*ib
= bufp
;
1870 /* index based on media type in media block */
1871 switch(ib
->opts
& MediaBlockMask
) {
1872 case 0: /* 10baseT */
1873 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Half
1874 | SUPPORTED_Autoneg
;
1876 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1879 de
->media_supported
|= SUPPORTED_BNC
;
1883 de
->media_supported
|= SUPPORTED_AUI
;
1886 case 4: /* 10baseT-FD */
1887 de
->media_supported
|= SUPPORTED_TP
| SUPPORTED_10baseT_Full
1888 | SUPPORTED_Autoneg
;
1889 idx
= DE_MEDIA_TP_FD
;
1890 de
->media
[DE_MEDIA_TP_AUTO
].type
= DE_MEDIA_TP_AUTO
;
1896 de
->media
[idx
].type
= idx
;
1898 if (netif_msg_probe(de
))
1899 pr_info("de%d: media block #%u: %s",
1901 media_name
[de
->media
[idx
].type
]);
1903 bufp
+= sizeof (ib
->opts
);
1905 if (ib
->opts
& MediaCustomCSRs
) {
1906 de
->media
[idx
].csr13
= get_unaligned(&ib
->csr13
);
1907 de
->media
[idx
].csr14
= get_unaligned(&ib
->csr14
);
1908 de
->media
[idx
].csr15
= get_unaligned(&ib
->csr15
);
1909 bufp
+= sizeof(ib
->csr13
) + sizeof(ib
->csr14
) +
1912 if (netif_msg_probe(de
))
1913 pr_cont(" (%x,%x,%x)\n",
1914 de
->media
[idx
].csr13
,
1915 de
->media
[idx
].csr14
,
1916 de
->media
[idx
].csr15
);
1919 if (netif_msg_probe(de
))
1923 if (bufp
> ((void *)&ee_data
[DE_EEPROM_SIZE
- 3]))
1927 de
->media_advertise
= de
->media_supported
;
1930 /* fill in defaults, for cases where custom CSRs not used */
1931 for (i
= 0; i
< DE_MAX_MEDIA
; i
++) {
1932 if (de
->media
[i
].csr13
== 0xffff)
1933 de
->media
[i
].csr13
= t21041_csr13
[i
];
1934 if (de
->media
[i
].csr14
== 0xffff) {
1935 /* autonegotiation is broken at least on some chip
1936 revisions - rev. 0x21 works, 0x11 does not */
1937 if (de
->pdev
->revision
< 0x20)
1938 de
->media
[i
].csr14
= t21041_csr14_brk
[i
];
1940 de
->media
[i
].csr14
= t21041_csr14
[i
];
1942 if (de
->media
[i
].csr15
== 0xffff)
1943 de
->media
[i
].csr15
= t21041_csr15
[i
];
1946 de
->ee_data
= kmemdup(&ee_data
[0], DE_EEPROM_SIZE
, GFP_KERNEL
);
1951 /* for error cases, it's ok to assume we support all these */
1952 for (i
= 0; i
< DE_MAX_MEDIA
; i
++)
1953 de
->media
[i
].type
= i
;
1954 de
->media_supported
=
1955 SUPPORTED_10baseT_Half
|
1956 SUPPORTED_10baseT_Full
|
1964 static const struct net_device_ops de_netdev_ops
= {
1965 .ndo_open
= de_open
,
1966 .ndo_stop
= de_close
,
1967 .ndo_set_rx_mode
= de_set_rx_mode
,
1968 .ndo_start_xmit
= de_start_xmit
,
1969 .ndo_get_stats
= de_get_stats
,
1970 .ndo_tx_timeout
= de_tx_timeout
,
1971 .ndo_set_mac_address
= eth_mac_addr
,
1972 .ndo_validate_addr
= eth_validate_addr
,
1975 static int de_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1977 struct net_device
*dev
;
1978 struct de_private
*de
;
1981 unsigned long pciaddr
;
1982 static int board_idx
= -1;
1986 /* allocate a new ethernet device structure, and fill in defaults */
1987 dev
= alloc_etherdev(sizeof(struct de_private
));
1991 dev
->netdev_ops
= &de_netdev_ops
;
1992 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1993 dev
->ethtool_ops
= &de_ethtool_ops
;
1994 dev
->watchdog_timeo
= TX_TIMEOUT
;
1996 de
= netdev_priv(dev
);
1997 de
->de21040
= ent
->driver_data
== 0 ? 1 : 0;
2000 de
->msg_enable
= (debug
< 0 ? DE_DEF_MSG_ENABLE
: debug
);
2001 de
->board_idx
= board_idx
;
2002 spin_lock_init (&de
->lock
);
2003 timer_setup(&de
->media_timer
,
2004 de
->de21040
? de21040_media_timer
: de21041_media_timer
,
2007 netif_carrier_off(dev
);
2009 /* wake up device, assign resources */
2010 rc
= pci_enable_device(pdev
);
2014 /* reserve PCI resources to ensure driver atomicity */
2015 rc
= pci_request_regions(pdev
, DRV_NAME
);
2017 goto err_out_disable
;
2019 /* check for invalid IRQ value */
2020 if (pdev
->irq
< 2) {
2022 pr_err("invalid irq (%d) for pci dev %s\n",
2023 pdev
->irq
, pci_name(pdev
));
2027 /* obtain and check validity of PCI I/O address */
2028 pciaddr
= pci_resource_start(pdev
, 1);
2031 pr_err("no MMIO resource for pci dev %s\n", pci_name(pdev
));
2034 if (pci_resource_len(pdev
, 1) < DE_REGS_SIZE
) {
2036 pr_err("MMIO resource (%llx) too small on pci dev %s\n",
2037 (unsigned long long)pci_resource_len(pdev
, 1),
2042 /* remap CSR registers */
2043 regs
= ioremap(pciaddr
, DE_REGS_SIZE
);
2046 pr_err("Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
2047 (unsigned long long)pci_resource_len(pdev
, 1),
2048 pciaddr
, pci_name(pdev
));
2053 de_adapter_wake(de
);
2055 /* make sure hardware is not running */
2056 rc
= de_reset_mac(de
);
2058 pr_err("Cannot reset MAC, pci dev %s\n", pci_name(pdev
));
2062 /* get MAC address, initialize default media type and
2063 * get list of supported media
2066 de21040_get_mac_address(de
);
2067 de21040_get_media_info(de
);
2069 de21041_get_srom_info(de
);
2072 /* register new network interface with kernel */
2073 rc
= register_netdev(dev
);
2077 /* print info about board and interface just registered */
2078 netdev_info(dev
, "%s at %p, %pM, IRQ %d\n",
2079 de
->de21040
? "21040" : "21041",
2080 regs
, dev
->dev_addr
, pdev
->irq
);
2082 pci_set_drvdata(pdev
, dev
);
2084 /* enable busmastering */
2085 pci_set_master(pdev
);
2087 /* put adapter to sleep */
2088 de_adapter_sleep(de
);
2096 pci_release_regions(pdev
);
2098 pci_disable_device(pdev
);
2104 static void de_remove_one(struct pci_dev
*pdev
)
2106 struct net_device
*dev
= pci_get_drvdata(pdev
);
2107 struct de_private
*de
= netdev_priv(dev
);
2110 unregister_netdev(dev
);
2113 pci_release_regions(pdev
);
2114 pci_disable_device(pdev
);
2118 static int __maybe_unused
de_suspend(struct device
*dev_d
)
2120 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
2121 struct net_device
*dev
= pci_get_drvdata(pdev
);
2122 struct de_private
*de
= netdev_priv(dev
);
2125 if (netif_running (dev
)) {
2126 const int irq
= pdev
->irq
;
2128 del_timer_sync(&de
->media_timer
);
2131 spin_lock_irq(&de
->lock
);
2134 netif_stop_queue(dev
);
2135 netif_device_detach(dev
);
2136 netif_carrier_off(dev
);
2138 spin_unlock_irq(&de
->lock
);
2141 /* Update the error counts. */
2144 synchronize_irq(irq
);
2147 de_adapter_sleep(de
);
2149 netif_device_detach(dev
);
2155 static int __maybe_unused
de_resume(struct device
*dev_d
)
2157 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
2158 struct net_device
*dev
= pci_get_drvdata(pdev
);
2159 struct de_private
*de
= netdev_priv(dev
);
2162 if (netif_device_present(dev
))
2164 if (!netif_running(dev
))
2166 pci_set_master(pdev
);
2170 netif_device_attach(dev
);
2176 static SIMPLE_DEV_PM_OPS(de_pm_ops
, de_suspend
, de_resume
);
2178 static void de_shutdown(struct pci_dev
*pdev
)
2180 struct net_device
*dev
= pci_get_drvdata(pdev
);
2187 static struct pci_driver de_driver
= {
2189 .id_table
= de_pci_tbl
,
2190 .probe
= de_init_one
,
2191 .remove
= de_remove_one
,
2192 .shutdown
= de_shutdown
,
2193 .driver
.pm
= &de_pm_ops
,
2196 static int __init
de_init (void)
2198 return pci_register_driver(&de_driver
);
2201 static void __exit
de_exit (void)
2203 pci_unregister_driver (&de_driver
);
2206 module_init(de_init
);
2207 module_exit(de_exit
);