aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/realtek
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
committerJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
commite75d660672ddd11704b7f0fdb8ff21968587b266 (patch)
treeccb9c107744c10b553c0373e450bee3971d16c00 /drivers/net/ethernet/realtek
parent61282f37927143e45b03153f3e7b48d6b702147a (diff)
parent0034102808e0dbbf3a2394b82b1bb40b5778de9e (diff)
Merge branch 'master' into for-next
Merge with latest Linus' tree, as I have incoming patches that fix code that is newer than current HEAD of for-next. Conflicts: drivers/net/ethernet/realtek/r8169.c
Diffstat (limited to 'drivers/net/ethernet/realtek')
-rw-r--r--drivers/net/ethernet/realtek/8139too.c109
-rw-r--r--drivers/net/ethernet/realtek/Kconfig10
-rw-r--r--drivers/net/ethernet/realtek/atp.c3
-rw-r--r--drivers/net/ethernet/realtek/r8169.c1611
4 files changed, 952 insertions, 781 deletions
diff --git a/drivers/net/ethernet/realtek/8139too.c b/drivers/net/ethernet/realtek/8139too.c
index a8779bedb3d9..df7fd8d083dc 100644
--- a/drivers/net/ethernet/realtek/8139too.c
+++ b/drivers/net/ethernet/realtek/8139too.c
@@ -565,6 +565,12 @@ struct rtl_extra_stats {
565 unsigned long rx_lost_in_ring; 565 unsigned long rx_lost_in_ring;
566}; 566};
567 567
568struct rtl8139_stats {
569 u64 packets;
570 u64 bytes;
571 struct u64_stats_sync syncp;
572};
573
568struct rtl8139_private { 574struct rtl8139_private {
569 void __iomem *mmio_addr; 575 void __iomem *mmio_addr;
570 int drv_flags; 576 int drv_flags;
@@ -575,11 +581,13 @@ struct rtl8139_private {
575 581
576 unsigned char *rx_ring; 582 unsigned char *rx_ring;
577 unsigned int cur_rx; /* RX buf index of next pkt */ 583 unsigned int cur_rx; /* RX buf index of next pkt */
584 struct rtl8139_stats rx_stats;
578 dma_addr_t rx_ring_dma; 585 dma_addr_t rx_ring_dma;
579 586
580 unsigned int tx_flag; 587 unsigned int tx_flag;
581 unsigned long cur_tx; 588 unsigned long cur_tx;
582 unsigned long dirty_tx; 589 unsigned long dirty_tx;
590 struct rtl8139_stats tx_stats;
583 unsigned char *tx_buf[NUM_TX_DESC]; /* Tx bounce buffers */ 591 unsigned char *tx_buf[NUM_TX_DESC]; /* Tx bounce buffers */
584 unsigned char *tx_bufs; /* Tx bounce buffer region. */ 592 unsigned char *tx_bufs; /* Tx bounce buffer region. */
585 dma_addr_t tx_bufs_dma; 593 dma_addr_t tx_bufs_dma;
@@ -641,7 +649,9 @@ static int rtl8139_poll(struct napi_struct *napi, int budget);
641static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance); 649static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance);
642static int rtl8139_close (struct net_device *dev); 650static int rtl8139_close (struct net_device *dev);
643static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd); 651static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
644static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); 652static struct rtnl_link_stats64 *rtl8139_get_stats64(struct net_device *dev,
653 struct rtnl_link_stats64
654 *stats);
645static void rtl8139_set_rx_mode (struct net_device *dev); 655static void rtl8139_set_rx_mode (struct net_device *dev);
646static void __set_rx_mode (struct net_device *dev); 656static void __set_rx_mode (struct net_device *dev);
647static void rtl8139_hw_start (struct net_device *dev); 657static void rtl8139_hw_start (struct net_device *dev);
@@ -754,10 +764,9 @@ static __devinit struct net_device * rtl8139_init_board (struct pci_dev *pdev)
754 764
755 /* dev and priv zeroed in alloc_etherdev */ 765 /* dev and priv zeroed in alloc_etherdev */
756 dev = alloc_etherdev (sizeof (*tp)); 766 dev = alloc_etherdev (sizeof (*tp));
757 if (dev == NULL) { 767 if (dev == NULL)
758 dev_err(&pdev->dev, "Unable to alloc new net device\n");
759 return ERR_PTR(-ENOMEM); 768 return ERR_PTR(-ENOMEM);
760 } 769
761 SET_NETDEV_DEV(dev, &pdev->dev); 770 SET_NETDEV_DEV(dev, &pdev->dev);
762 771
763 tp = netdev_priv(dev); 772 tp = netdev_priv(dev);
@@ -908,10 +917,37 @@ err_out:
908 return ERR_PTR(rc); 917 return ERR_PTR(rc);
909} 918}
910 919
920static int rtl8139_set_features(struct net_device *dev, netdev_features_t features)
921{
922 struct rtl8139_private *tp = netdev_priv(dev);
923 unsigned long flags;
924 netdev_features_t changed = features ^ dev->features;
925 void __iomem *ioaddr = tp->mmio_addr;
926
927 if (!(changed & (NETIF_F_RXALL)))
928 return 0;
929
930 spin_lock_irqsave(&tp->lock, flags);
931
932 if (changed & NETIF_F_RXALL) {
933 int rx_mode = tp->rx_config;
934 if (features & NETIF_F_RXALL)
935 rx_mode |= (AcceptErr | AcceptRunt);
936 else
937 rx_mode &= ~(AcceptErr | AcceptRunt);
938 tp->rx_config = rtl8139_rx_config | rx_mode;
939 RTL_W32_F(RxConfig, tp->rx_config);
940 }
941
942 spin_unlock_irqrestore(&tp->lock, flags);
943
944 return 0;
945}
946
911static const struct net_device_ops rtl8139_netdev_ops = { 947static const struct net_device_ops rtl8139_netdev_ops = {
912 .ndo_open = rtl8139_open, 948 .ndo_open = rtl8139_open,
913 .ndo_stop = rtl8139_close, 949 .ndo_stop = rtl8139_close,
914 .ndo_get_stats = rtl8139_get_stats, 950 .ndo_get_stats64 = rtl8139_get_stats64,
915 .ndo_change_mtu = eth_change_mtu, 951 .ndo_change_mtu = eth_change_mtu,
916 .ndo_validate_addr = eth_validate_addr, 952 .ndo_validate_addr = eth_validate_addr,
917 .ndo_set_mac_address = rtl8139_set_mac_address, 953 .ndo_set_mac_address = rtl8139_set_mac_address,
@@ -922,6 +958,7 @@ static const struct net_device_ops rtl8139_netdev_ops = {
922#ifdef CONFIG_NET_POLL_CONTROLLER 958#ifdef CONFIG_NET_POLL_CONTROLLER
923 .ndo_poll_controller = rtl8139_poll_controller, 959 .ndo_poll_controller = rtl8139_poll_controller,
924#endif 960#endif
961 .ndo_set_features = rtl8139_set_features,
925}; 962};
926 963
927static int __devinit rtl8139_init_one (struct pci_dev *pdev, 964static int __devinit rtl8139_init_one (struct pci_dev *pdev,
@@ -995,6 +1032,9 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
995 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA; 1032 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA;
996 dev->vlan_features = dev->features; 1033 dev->vlan_features = dev->features;
997 1034
1035 dev->hw_features |= NETIF_F_RXALL;
1036 dev->hw_features |= NETIF_F_RXFCS;
1037
998 dev->irq = pdev->irq; 1038 dev->irq = pdev->irq;
999 1039
1000 /* tp zeroed and aligned in alloc_etherdev */ 1040 /* tp zeroed and aligned in alloc_etherdev */
@@ -1777,8 +1817,10 @@ static void rtl8139_tx_interrupt (struct net_device *dev,
1777 dev->stats.tx_fifo_errors++; 1817 dev->stats.tx_fifo_errors++;
1778 } 1818 }
1779 dev->stats.collisions += (txstatus >> 24) & 15; 1819 dev->stats.collisions += (txstatus >> 24) & 15;
1780 dev->stats.tx_bytes += txstatus & 0x7ff; 1820 u64_stats_update_begin(&tp->tx_stats.syncp);
1781 dev->stats.tx_packets++; 1821 tp->tx_stats.packets++;
1822 tp->tx_stats.bytes += txstatus & 0x7ff;
1823 u64_stats_update_end(&tp->tx_stats.syncp);
1782 } 1824 }
1783 1825
1784 dirty_tx++; 1826 dirty_tx++;
@@ -1941,7 +1983,10 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
1941 /* read size+status of next frame from DMA ring buffer */ 1983 /* read size+status of next frame from DMA ring buffer */
1942 rx_status = le32_to_cpu (*(__le32 *) (rx_ring + ring_offset)); 1984 rx_status = le32_to_cpu (*(__le32 *) (rx_ring + ring_offset));
1943 rx_size = rx_status >> 16; 1985 rx_size = rx_status >> 16;
1944 pkt_size = rx_size - 4; 1986 if (likely(!(dev->features & NETIF_F_RXFCS)))
1987 pkt_size = rx_size - 4;
1988 else
1989 pkt_size = rx_size;
1945 1990
1946 netif_dbg(tp, rx_status, dev, "%s() status %04x, size %04x, cur %04x\n", 1991 netif_dbg(tp, rx_status, dev, "%s() status %04x, size %04x, cur %04x\n",
1947 __func__, rx_status, rx_size, cur_rx); 1992 __func__, rx_status, rx_size, cur_rx);
@@ -1979,11 +2024,30 @@ no_early_rx:
1979 if (unlikely((rx_size > (MAX_ETH_FRAME_SIZE+4)) || 2024 if (unlikely((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
1980 (rx_size < 8) || 2025 (rx_size < 8) ||
1981 (!(rx_status & RxStatusOK)))) { 2026 (!(rx_status & RxStatusOK)))) {
2027 if ((dev->features & NETIF_F_RXALL) &&
2028 (rx_size <= (MAX_ETH_FRAME_SIZE + 4)) &&
2029 (rx_size >= 8) &&
2030 (!(rx_status & RxStatusOK))) {
2031 /* Length is at least mostly OK, but pkt has
2032 * error. I'm hoping we can handle some of these
2033 * errors without resetting the chip. --Ben
2034 */
2035 dev->stats.rx_errors++;
2036 if (rx_status & RxCRCErr) {
2037 dev->stats.rx_crc_errors++;
2038 goto keep_pkt;
2039 }
2040 if (rx_status & RxRunt) {
2041 dev->stats.rx_length_errors++;
2042 goto keep_pkt;
2043 }
2044 }
1982 rtl8139_rx_err (rx_status, dev, tp, ioaddr); 2045 rtl8139_rx_err (rx_status, dev, tp, ioaddr);
1983 received = -1; 2046 received = -1;
1984 goto out; 2047 goto out;
1985 } 2048 }
1986 2049
2050keep_pkt:
1987 /* Malloc up new buffer, compatible with net-2e. */ 2051 /* Malloc up new buffer, compatible with net-2e. */
1988 /* Omit the four octet CRC from the length. */ 2052 /* Omit the four octet CRC from the length. */
1989 2053
@@ -1998,8 +2062,10 @@ no_early_rx:
1998 2062
1999 skb->protocol = eth_type_trans (skb, dev); 2063 skb->protocol = eth_type_trans (skb, dev);
2000 2064
2001 dev->stats.rx_bytes += pkt_size; 2065 u64_stats_update_begin(&tp->rx_stats.syncp);
2002 dev->stats.rx_packets++; 2066 tp->rx_stats.packets++;
2067 tp->rx_stats.bytes += pkt_size;
2068 u64_stats_update_end(&tp->rx_stats.syncp);
2003 2069
2004 netif_receive_skb (skb); 2070 netif_receive_skb (skb);
2005 } else { 2071 } else {
@@ -2463,11 +2529,13 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2463} 2529}
2464 2530
2465 2531
2466static struct net_device_stats *rtl8139_get_stats (struct net_device *dev) 2532static struct rtnl_link_stats64 *
2533rtl8139_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
2467{ 2534{
2468 struct rtl8139_private *tp = netdev_priv(dev); 2535 struct rtl8139_private *tp = netdev_priv(dev);
2469 void __iomem *ioaddr = tp->mmio_addr; 2536 void __iomem *ioaddr = tp->mmio_addr;
2470 unsigned long flags; 2537 unsigned long flags;
2538 unsigned int start;
2471 2539
2472 if (netif_running(dev)) { 2540 if (netif_running(dev)) {
2473 spin_lock_irqsave (&tp->lock, flags); 2541 spin_lock_irqsave (&tp->lock, flags);
@@ -2476,7 +2544,21 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)
2476 spin_unlock_irqrestore (&tp->lock, flags); 2544 spin_unlock_irqrestore (&tp->lock, flags);
2477 } 2545 }
2478 2546
2479 return &dev->stats; 2547 netdev_stats_to_stats64(stats, &dev->stats);
2548
2549 do {
2550 start = u64_stats_fetch_begin_bh(&tp->rx_stats.syncp);
2551 stats->rx_packets = tp->rx_stats.packets;
2552 stats->rx_bytes = tp->rx_stats.bytes;
2553 } while (u64_stats_fetch_retry_bh(&tp->rx_stats.syncp, start));
2554
2555 do {
2556 start = u64_stats_fetch_begin_bh(&tp->tx_stats.syncp);
2557 stats->tx_packets = tp->tx_stats.packets;
2558 stats->tx_bytes = tp->tx_stats.bytes;
2559 } while (u64_stats_fetch_retry_bh(&tp->tx_stats.syncp, start));
2560
2561 return stats;
2480} 2562}
2481 2563
2482/* Set or clear the multicast filter for this adaptor. 2564/* Set or clear the multicast filter for this adaptor.
@@ -2516,6 +2598,9 @@ static void __set_rx_mode (struct net_device *dev)
2516 } 2598 }
2517 } 2599 }
2518 2600
2601 if (dev->features & NETIF_F_RXALL)
2602 rx_mode |= (AcceptErr | AcceptRunt);
2603
2519 /* We can safely update without stopping the chip. */ 2604 /* We can safely update without stopping the chip. */
2520 tmp = rtl8139_rx_config | rx_mode; 2605 tmp = rtl8139_rx_config | rx_mode;
2521 if (tp->rx_config != tmp) { 2606 if (tp->rx_config != tmp) {
diff --git a/drivers/net/ethernet/realtek/Kconfig b/drivers/net/ethernet/realtek/Kconfig
index 0578859a3c73..5821966f9f28 100644
--- a/drivers/net/ethernet/realtek/Kconfig
+++ b/drivers/net/ethernet/realtek/Kconfig
@@ -24,11 +24,11 @@ config ATP
24 select CRC32 24 select CRC32
25 ---help--- 25 ---help---
26 This is a network (Ethernet) device which attaches to your parallel 26 This is a network (Ethernet) device which attaches to your parallel
27 port. Read <file:drivers/net/atp.c> as well as the Ethernet-HOWTO, 27 port. Read <file:drivers/net/ethernet/realtek/atp.c> as well as the
28 available from <http://www.tldp.org/docs.html#howto>, if you 28 Ethernet-HOWTO, available from <http://www.tldp.org/docs.html#howto>,
29 want to use this. If you intend to use this driver, you should have 29 if you want to use this. If you intend to use this driver, you
30 said N to the "Parallel printer support", because the two drivers 30 should have said N to the "Parallel printer support", because the two
31 don't like each other. 31 drivers don't like each other.
32 32
33 To compile this driver as a module, choose M here: the module 33 To compile this driver as a module, choose M here: the module
34 will be called atp. 34 will be called atp.
diff --git a/drivers/net/ethernet/realtek/atp.c b/drivers/net/ethernet/realtek/atp.c
index e3f57fdbf0ea..e02f04d7f3ad 100644
--- a/drivers/net/ethernet/realtek/atp.c
+++ b/drivers/net/ethernet/realtek/atp.c
@@ -140,7 +140,6 @@ static int xcvr[NUM_UNITS]; /* The data transfer mode. */
140#include <linux/delay.h> 140#include <linux/delay.h>
141#include <linux/bitops.h> 141#include <linux/bitops.h>
142 142
143#include <asm/system.h>
144#include <asm/io.h> 143#include <asm/io.h>
145#include <asm/dma.h> 144#include <asm/dma.h>
146 145
@@ -783,7 +782,7 @@ static void net_rx(struct net_device *dev)
783 int pkt_len = (rx_head.rx_count & 0x7ff) - 4; 782 int pkt_len = (rx_head.rx_count & 0x7ff) - 4;
784 struct sk_buff *skb; 783 struct sk_buff *skb;
785 784
786 skb = dev_alloc_skb(pkt_len + 2); 785 skb = netdev_alloc_skb(dev, pkt_len + 2);
787 if (skb == NULL) { 786 if (skb == NULL) {
788 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", 787 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n",
789 dev->name); 788 dev->name);
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 7f06508df9ff..a2d39d2e5cde 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -29,7 +29,6 @@
29#include <linux/pci-aspm.h> 29#include <linux/pci-aspm.h>
30#include <linux/prefetch.h> 30#include <linux/prefetch.h>
31 31
32#include <asm/system.h>
33#include <asm/io.h> 32#include <asm/io.h>
34#include <asm/irq.h> 33#include <asm/irq.h>
35 34
@@ -255,10 +254,6 @@ enum cfg_version {
255 RTL_CFG_2 254 RTL_CFG_2
256}; 255};
257 256
258static void rtl_hw_start_8169(struct net_device *);
259static void rtl_hw_start_8168(struct net_device *);
260static void rtl_hw_start_8101(struct net_device *);
261
262static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { 257static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = {
263 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, 258 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
264 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, 259 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
@@ -667,12 +662,25 @@ struct rtl8169_counters {
667 __le16 tx_underun; 662 __le16 tx_underun;
668}; 663};
669 664
665enum rtl_flag {
666 RTL_FLAG_TASK_ENABLED,
667 RTL_FLAG_TASK_SLOW_PENDING,
668 RTL_FLAG_TASK_RESET_PENDING,
669 RTL_FLAG_TASK_PHY_PENDING,
670 RTL_FLAG_MAX
671};
672
673struct rtl8169_stats {
674 u64 packets;
675 u64 bytes;
676 struct u64_stats_sync syncp;
677};
678
670struct rtl8169_private { 679struct rtl8169_private {
671 void __iomem *mmio_addr; /* memory map physical address */ 680 void __iomem *mmio_addr; /* memory map physical address */
672 struct pci_dev *pci_dev; 681 struct pci_dev *pci_dev;
673 struct net_device *dev; 682 struct net_device *dev;
674 struct napi_struct napi; 683 struct napi_struct napi;
675 spinlock_t lock;
676 u32 msg_enable; 684 u32 msg_enable;
677 u16 txd_version; 685 u16 txd_version;
678 u16 mac_version; 686 u16 mac_version;
@@ -680,6 +688,8 @@ struct rtl8169_private {
680 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ 688 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
681 u32 dirty_rx; 689 u32 dirty_rx;
682 u32 dirty_tx; 690 u32 dirty_tx;
691 struct rtl8169_stats rx_stats;
692 struct rtl8169_stats tx_stats;
683 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ 693 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
684 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ 694 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
685 dma_addr_t TxPhyAddr; 695 dma_addr_t TxPhyAddr;
@@ -688,9 +698,8 @@ struct rtl8169_private {
688 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ 698 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
689 struct timer_list timer; 699 struct timer_list timer;
690 u16 cp_cmd; 700 u16 cp_cmd;
691 u16 intr_event; 701
692 u16 napi_event; 702 u16 event_slow;
693 u16 intr_mask;
694 703
695 struct mdio_ops { 704 struct mdio_ops {
696 void (*write)(void __iomem *, int, int); 705 void (*write)(void __iomem *, int, int);
@@ -714,7 +723,13 @@ struct rtl8169_private {
714 unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); 723 unsigned int (*phy_reset_pending)(struct rtl8169_private *tp);
715 unsigned int (*link_ok)(void __iomem *); 724 unsigned int (*link_ok)(void __iomem *);
716 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); 725 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd);
717 struct delayed_work task; 726
727 struct {
728 DECLARE_BITMAP(flags, RTL_FLAG_MAX);
729 struct mutex mutex;
730 struct work_struct work;
731 } wk;
732
718 unsigned features; 733 unsigned features;
719 734
720 struct mii_if_info mii; 735 struct mii_if_info mii;
@@ -754,22 +769,15 @@ MODULE_FIRMWARE(FIRMWARE_8105E_1);
754MODULE_FIRMWARE(FIRMWARE_8168F_1); 769MODULE_FIRMWARE(FIRMWARE_8168F_1);
755MODULE_FIRMWARE(FIRMWARE_8168F_2); 770MODULE_FIRMWARE(FIRMWARE_8168F_2);
756 771
757static int rtl8169_open(struct net_device *dev); 772static void rtl_lock_work(struct rtl8169_private *tp)
758static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, 773{
759 struct net_device *dev); 774 mutex_lock(&tp->wk.mutex);
760static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); 775}
761static int rtl8169_init_ring(struct net_device *dev); 776
762static void rtl_hw_start(struct net_device *dev); 777static void rtl_unlock_work(struct rtl8169_private *tp)
763static int rtl8169_close(struct net_device *dev); 778{
764static void rtl_set_rx_mode(struct net_device *dev); 779 mutex_unlock(&tp->wk.mutex);
765static void rtl8169_tx_timeout(struct net_device *dev); 780}
766static struct net_device_stats *rtl8169_get_stats(struct net_device *dev);
767static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
768 void __iomem *, u32 budget);
769static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
770static void rtl8169_down(struct net_device *dev);
771static void rtl8169_rx_clear(struct rtl8169_private *tp);
772static int rtl8169_poll(struct napi_struct *napi, int budget);
773 781
774static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) 782static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
775{ 783{
@@ -1180,12 +1188,51 @@ static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr)
1180 return value; 1188 return value;
1181} 1189}
1182 1190
1191static u16 rtl_get_events(struct rtl8169_private *tp)
1192{
1193 void __iomem *ioaddr = tp->mmio_addr;
1194
1195 return RTL_R16(IntrStatus);
1196}
1197
1198static void rtl_ack_events(struct rtl8169_private *tp, u16 bits)
1199{
1200 void __iomem *ioaddr = tp->mmio_addr;
1201
1202 RTL_W16(IntrStatus, bits);
1203 mmiowb();
1204}
1205
1206static void rtl_irq_disable(struct rtl8169_private *tp)
1207{
1208 void __iomem *ioaddr = tp->mmio_addr;
1209
1210 RTL_W16(IntrMask, 0);
1211 mmiowb();
1212}
1213
1214static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits)
1215{
1216 void __iomem *ioaddr = tp->mmio_addr;
1217
1218 RTL_W16(IntrMask, bits);
1219}
1220
1221#define RTL_EVENT_NAPI_RX (RxOK | RxErr)
1222#define RTL_EVENT_NAPI_TX (TxOK | TxErr)
1223#define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX)
1224
1225static void rtl_irq_enable_all(struct rtl8169_private *tp)
1226{
1227 rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow);
1228}
1229
1183static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) 1230static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp)
1184{ 1231{
1185 void __iomem *ioaddr = tp->mmio_addr; 1232 void __iomem *ioaddr = tp->mmio_addr;
1186 1233
1187 RTL_W16(IntrMask, 0x0000); 1234 rtl_irq_disable(tp);
1188 RTL_W16(IntrStatus, tp->intr_event); 1235 rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow);
1189 RTL_R8(ChipCmd); 1236 RTL_R8(ChipCmd);
1190} 1237}
1191 1238
@@ -1276,9 +1323,6 @@ static void __rtl8169_check_link_status(struct net_device *dev,
1276 struct rtl8169_private *tp, 1323 struct rtl8169_private *tp,
1277 void __iomem *ioaddr, bool pm) 1324 void __iomem *ioaddr, bool pm)
1278{ 1325{
1279 unsigned long flags;
1280
1281 spin_lock_irqsave(&tp->lock, flags);
1282 if (tp->link_ok(ioaddr)) { 1326 if (tp->link_ok(ioaddr)) {
1283 rtl_link_chg_patch(tp); 1327 rtl_link_chg_patch(tp);
1284 /* This is to cancel a scheduled suspend if there's one. */ 1328 /* This is to cancel a scheduled suspend if there's one. */
@@ -1293,7 +1337,6 @@ static void __rtl8169_check_link_status(struct net_device *dev,
1293 if (pm) 1337 if (pm)
1294 pm_schedule_suspend(&tp->pci_dev->dev, 5000); 1338 pm_schedule_suspend(&tp->pci_dev->dev, 5000);
1295 } 1339 }
1296 spin_unlock_irqrestore(&tp->lock, flags);
1297} 1340}
1298 1341
1299static void rtl8169_check_link_status(struct net_device *dev, 1342static void rtl8169_check_link_status(struct net_device *dev,
@@ -1336,12 +1379,12 @@ static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1336{ 1379{
1337 struct rtl8169_private *tp = netdev_priv(dev); 1380 struct rtl8169_private *tp = netdev_priv(dev);
1338 1381
1339 spin_lock_irq(&tp->lock); 1382 rtl_lock_work(tp);
1340 1383
1341 wol->supported = WAKE_ANY; 1384 wol->supported = WAKE_ANY;
1342 wol->wolopts = __rtl8169_get_wol(tp); 1385 wol->wolopts = __rtl8169_get_wol(tp);
1343 1386
1344 spin_unlock_irq(&tp->lock); 1387 rtl_unlock_work(tp);
1345} 1388}
1346 1389
1347static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) 1390static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
@@ -1378,14 +1421,15 @@ static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1378{ 1421{
1379 struct rtl8169_private *tp = netdev_priv(dev); 1422 struct rtl8169_private *tp = netdev_priv(dev);
1380 1423
1381 spin_lock_irq(&tp->lock); 1424 rtl_lock_work(tp);
1382 1425
1383 if (wol->wolopts) 1426 if (wol->wolopts)
1384 tp->features |= RTL_FEATURE_WOL; 1427 tp->features |= RTL_FEATURE_WOL;
1385 else 1428 else
1386 tp->features &= ~RTL_FEATURE_WOL; 1429 tp->features &= ~RTL_FEATURE_WOL;
1387 __rtl8169_set_wol(tp, wol->wolopts); 1430 __rtl8169_set_wol(tp, wol->wolopts);
1388 spin_unlock_irq(&tp->lock); 1431
1432 rtl_unlock_work(tp);
1389 1433
1390 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); 1434 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
1391 1435
@@ -1540,15 +1584,14 @@ out:
1540static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 1584static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1541{ 1585{
1542 struct rtl8169_private *tp = netdev_priv(dev); 1586 struct rtl8169_private *tp = netdev_priv(dev);
1543 unsigned long flags;
1544 int ret; 1587 int ret;
1545 1588
1546 del_timer_sync(&tp->timer); 1589 del_timer_sync(&tp->timer);
1547 1590
1548 spin_lock_irqsave(&tp->lock, flags); 1591 rtl_lock_work(tp);
1549 ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), 1592 ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd),
1550 cmd->duplex, cmd->advertising); 1593 cmd->duplex, cmd->advertising);
1551 spin_unlock_irqrestore(&tp->lock, flags); 1594 rtl_unlock_work(tp);
1552 1595
1553 return ret; 1596 return ret;
1554} 1597}
@@ -1568,33 +1611,51 @@ static netdev_features_t rtl8169_fix_features(struct net_device *dev,
1568 return features; 1611 return features;
1569} 1612}
1570 1613
1571static int rtl8169_set_features(struct net_device *dev, 1614static void __rtl8169_set_features(struct net_device *dev,
1572 netdev_features_t features) 1615 netdev_features_t features)
1573{ 1616{
1574 struct rtl8169_private *tp = netdev_priv(dev); 1617 struct rtl8169_private *tp = netdev_priv(dev);
1618 netdev_features_t changed = features ^ dev->features;
1575 void __iomem *ioaddr = tp->mmio_addr; 1619 void __iomem *ioaddr = tp->mmio_addr;
1576 unsigned long flags;
1577 1620
1578 spin_lock_irqsave(&tp->lock, flags); 1621 if (!(changed & (NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX)))
1622 return;
1579 1623
1580 if (features & NETIF_F_RXCSUM) 1624 if (changed & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX)) {
1581 tp->cp_cmd |= RxChkSum; 1625 if (features & NETIF_F_RXCSUM)
1582 else 1626 tp->cp_cmd |= RxChkSum;
1583 tp->cp_cmd &= ~RxChkSum; 1627 else
1628 tp->cp_cmd &= ~RxChkSum;
1584 1629
1585 if (dev->features & NETIF_F_HW_VLAN_RX) 1630 if (dev->features & NETIF_F_HW_VLAN_RX)
1586 tp->cp_cmd |= RxVlan; 1631 tp->cp_cmd |= RxVlan;
1587 else 1632 else
1588 tp->cp_cmd &= ~RxVlan; 1633 tp->cp_cmd &= ~RxVlan;
1589 1634
1590 RTL_W16(CPlusCmd, tp->cp_cmd); 1635 RTL_W16(CPlusCmd, tp->cp_cmd);
1591 RTL_R16(CPlusCmd); 1636 RTL_R16(CPlusCmd);
1637 }
1638 if (changed & NETIF_F_RXALL) {
1639 int tmp = (RTL_R32(RxConfig) & ~(AcceptErr | AcceptRunt));
1640 if (features & NETIF_F_RXALL)
1641 tmp |= (AcceptErr | AcceptRunt);
1642 RTL_W32(RxConfig, tmp);
1643 }
1644}
1592 1645
1593 spin_unlock_irqrestore(&tp->lock, flags); 1646static int rtl8169_set_features(struct net_device *dev,
1647 netdev_features_t features)
1648{
1649 struct rtl8169_private *tp = netdev_priv(dev);
1650
1651 rtl_lock_work(tp);
1652 __rtl8169_set_features(dev, features);
1653 rtl_unlock_work(tp);
1594 1654
1595 return 0; 1655 return 0;
1596} 1656}
1597 1657
1658
1598static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, 1659static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
1599 struct sk_buff *skb) 1660 struct sk_buff *skb)
1600{ 1661{
@@ -1643,14 +1704,12 @@ static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
1643static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 1704static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1644{ 1705{
1645 struct rtl8169_private *tp = netdev_priv(dev); 1706 struct rtl8169_private *tp = netdev_priv(dev);
1646 unsigned long flags;
1647 int rc; 1707 int rc;
1648 1708
1649 spin_lock_irqsave(&tp->lock, flags); 1709 rtl_lock_work(tp);
1650
1651 rc = tp->get_settings(dev, cmd); 1710 rc = tp->get_settings(dev, cmd);
1711 rtl_unlock_work(tp);
1652 1712
1653 spin_unlock_irqrestore(&tp->lock, flags);
1654 return rc; 1713 return rc;
1655} 1714}
1656 1715
@@ -1658,14 +1717,13 @@ static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1658 void *p) 1717 void *p)
1659{ 1718{
1660 struct rtl8169_private *tp = netdev_priv(dev); 1719 struct rtl8169_private *tp = netdev_priv(dev);
1661 unsigned long flags;
1662 1720
1663 if (regs->len > R8169_REGS_SIZE) 1721 if (regs->len > R8169_REGS_SIZE)
1664 regs->len = R8169_REGS_SIZE; 1722 regs->len = R8169_REGS_SIZE;
1665 1723
1666 spin_lock_irqsave(&tp->lock, flags); 1724 rtl_lock_work(tp);
1667 memcpy_fromio(p, tp->mmio_addr, regs->len); 1725 memcpy_fromio(p, tp->mmio_addr, regs->len);
1668 spin_unlock_irqrestore(&tp->lock, flags); 1726 rtl_unlock_work(tp);
1669} 1727}
1670 1728
1671static u32 rtl8169_get_msglevel(struct net_device *dev) 1729static u32 rtl8169_get_msglevel(struct net_device *dev)
@@ -3182,18 +3240,14 @@ static void rtl_hw_phy_config(struct net_device *dev)
3182 } 3240 }
3183} 3241}
3184 3242
3185static void rtl8169_phy_timer(unsigned long __opaque) 3243static void rtl_phy_work(struct rtl8169_private *tp)
3186{ 3244{
3187 struct net_device *dev = (struct net_device *)__opaque;
3188 struct rtl8169_private *tp = netdev_priv(dev);
3189 struct timer_list *timer = &tp->timer; 3245 struct timer_list *timer = &tp->timer;
3190 void __iomem *ioaddr = tp->mmio_addr; 3246 void __iomem *ioaddr = tp->mmio_addr;
3191 unsigned long timeout = RTL8169_PHY_TIMEOUT; 3247 unsigned long timeout = RTL8169_PHY_TIMEOUT;
3192 3248
3193 assert(tp->mac_version > RTL_GIGA_MAC_VER_01); 3249 assert(tp->mac_version > RTL_GIGA_MAC_VER_01);
3194 3250
3195 spin_lock_irq(&tp->lock);
3196
3197 if (tp->phy_reset_pending(tp)) { 3251 if (tp->phy_reset_pending(tp)) {
3198 /* 3252 /*
3199 * A busy loop could burn quite a few cycles on nowadays CPU. 3253 * A busy loop could burn quite a few cycles on nowadays CPU.
@@ -3204,34 +3258,29 @@ static void rtl8169_phy_timer(unsigned long __opaque)
3204 } 3258 }
3205 3259
3206 if (tp->link_ok(ioaddr)) 3260 if (tp->link_ok(ioaddr))
3207 goto out_unlock; 3261 return;
3208 3262
3209 netif_warn(tp, link, dev, "PHY reset until link up\n"); 3263 netif_warn(tp, link, tp->dev, "PHY reset until link up\n");
3210 3264
3211 tp->phy_reset_enable(tp); 3265 tp->phy_reset_enable(tp);
3212 3266
3213out_mod_timer: 3267out_mod_timer:
3214 mod_timer(timer, jiffies + timeout); 3268 mod_timer(timer, jiffies + timeout);
3215out_unlock:
3216 spin_unlock_irq(&tp->lock);
3217} 3269}
3218 3270
3219#ifdef CONFIG_NET_POLL_CONTROLLER 3271static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag)
3220/*
3221 * Polling 'interrupt' - used by things like netconsole to send skbs
3222 * without having to re-enable interrupts. It's not called while
3223 * the interrupt routine is executing.
3224 */
3225static void rtl8169_netpoll(struct net_device *dev)
3226{ 3272{
3273 if (!test_and_set_bit(flag, tp->wk.flags))
3274 schedule_work(&tp->wk.work);
3275}
3276
3277static void rtl8169_phy_timer(unsigned long __opaque)
3278{
3279 struct net_device *dev = (struct net_device *)__opaque;
3227 struct rtl8169_private *tp = netdev_priv(dev); 3280 struct rtl8169_private *tp = netdev_priv(dev);
3228 struct pci_dev *pdev = tp->pci_dev;
3229 3281
3230 disable_irq(pdev->irq); 3282 rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING);
3231 rtl8169_interrupt(pdev->irq, dev);
3232 enable_irq(pdev->irq);
3233} 3283}
3234#endif
3235 3284
3236static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, 3285static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev,
3237 void __iomem *ioaddr) 3286 void __iomem *ioaddr)
@@ -3310,7 +3359,7 @@ static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
3310 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); 3359 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24);
3311 high = addr[4] | (addr[5] << 8); 3360 high = addr[4] | (addr[5] << 8);
3312 3361
3313 spin_lock_irq(&tp->lock); 3362 rtl_lock_work(tp);
3314 3363
3315 RTL_W8(Cfg9346, Cfg9346_Unlock); 3364 RTL_W8(Cfg9346, Cfg9346_Unlock);
3316 3365
@@ -3334,7 +3383,7 @@ static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
3334 3383
3335 RTL_W8(Cfg9346, Cfg9346_Lock); 3384 RTL_W8(Cfg9346, Cfg9346_Lock);
3336 3385
3337 spin_unlock_irq(&tp->lock); 3386 rtl_unlock_work(tp);
3338} 3387}
3339 3388
3340static int rtl_set_mac_address(struct net_device *dev, void *p) 3389static int rtl_set_mac_address(struct net_device *dev, void *p)
@@ -3384,69 +3433,6 @@ static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data
3384 return -EOPNOTSUPP; 3433 return -EOPNOTSUPP;
3385} 3434}
3386 3435
3387static const struct rtl_cfg_info {
3388 void (*hw_start)(struct net_device *);
3389 unsigned int region;
3390 unsigned int align;
3391 u16 intr_event;
3392 u16 napi_event;
3393 unsigned features;
3394 u8 default_ver;
3395} rtl_cfg_infos [] = {
3396 [RTL_CFG_0] = {
3397 .hw_start = rtl_hw_start_8169,
3398 .region = 1,
3399 .align = 0,
3400 .intr_event = SYSErr | LinkChg | RxOverflow |
3401 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
3402 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
3403 .features = RTL_FEATURE_GMII,
3404 .default_ver = RTL_GIGA_MAC_VER_01,
3405 },
3406 [RTL_CFG_1] = {
3407 .hw_start = rtl_hw_start_8168,
3408 .region = 2,
3409 .align = 8,
3410 .intr_event = SYSErr | LinkChg | RxOverflow |
3411 TxErr | TxOK | RxOK | RxErr,
3412 .napi_event = TxErr | TxOK | RxOK | RxOverflow,
3413 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
3414 .default_ver = RTL_GIGA_MAC_VER_11,
3415 },
3416 [RTL_CFG_2] = {
3417 .hw_start = rtl_hw_start_8101,
3418 .region = 2,
3419 .align = 8,
3420 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
3421 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
3422 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
3423 .features = RTL_FEATURE_MSI,
3424 .default_ver = RTL_GIGA_MAC_VER_13,
3425 }
3426};
3427
3428/* Cfg9346_Unlock assumed. */
3429static unsigned rtl_try_msi(struct rtl8169_private *tp,
3430 const struct rtl_cfg_info *cfg)
3431{
3432 void __iomem *ioaddr = tp->mmio_addr;
3433 unsigned msi = 0;
3434 u8 cfg2;
3435
3436 cfg2 = RTL_R8(Config2) & ~MSIEnable;
3437 if (cfg->features & RTL_FEATURE_MSI) {
3438 if (pci_enable_msi(tp->pci_dev)) {
3439 netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n");
3440 } else {
3441 cfg2 |= MSIEnable;
3442 msi = RTL_FEATURE_MSI;
3443 }
3444 }
3445 if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
3446 RTL_W8(Config2, cfg2);
3447 return msi;
3448}
3449
3450static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) 3436static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
3451{ 3437{
3452 if (tp->features & RTL_FEATURE_MSI) { 3438 if (tp->features & RTL_FEATURE_MSI) {
@@ -3455,25 +3441,6 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
3455 } 3441 }
3456} 3442}
3457 3443
3458static const struct net_device_ops rtl8169_netdev_ops = {
3459 .ndo_open = rtl8169_open,
3460 .ndo_stop = rtl8169_close,
3461 .ndo_get_stats = rtl8169_get_stats,
3462 .ndo_start_xmit = rtl8169_start_xmit,
3463 .ndo_tx_timeout = rtl8169_tx_timeout,
3464 .ndo_validate_addr = eth_validate_addr,
3465 .ndo_change_mtu = rtl8169_change_mtu,
3466 .ndo_fix_features = rtl8169_fix_features,
3467 .ndo_set_features = rtl8169_set_features,
3468 .ndo_set_mac_address = rtl_set_mac_address,
3469 .ndo_do_ioctl = rtl8169_ioctl,
3470 .ndo_set_rx_mode = rtl_set_rx_mode,
3471#ifdef CONFIG_NET_POLL_CONTROLLER
3472 .ndo_poll_controller = rtl8169_netpoll,
3473#endif
3474
3475};
3476
3477static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) 3444static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp)
3478{ 3445{
3479 struct mdio_ops *ops = &tp->mdio_ops; 3446 struct mdio_ops *ops = &tp->mdio_ops;
@@ -3781,12 +3748,20 @@ static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
3781 3748
3782static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) 3749static void rtl_hw_jumbo_enable(struct rtl8169_private *tp)
3783{ 3750{
3751 void __iomem *ioaddr = tp->mmio_addr;
3752
3753 RTL_W8(Cfg9346, Cfg9346_Unlock);
3784 rtl_generic_op(tp, tp->jumbo_ops.enable); 3754 rtl_generic_op(tp, tp->jumbo_ops.enable);
3755 RTL_W8(Cfg9346, Cfg9346_Lock);
3785} 3756}
3786 3757
3787static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) 3758static void rtl_hw_jumbo_disable(struct rtl8169_private *tp)
3788{ 3759{
3760 void __iomem *ioaddr = tp->mmio_addr;
3761
3762 RTL_W8(Cfg9346, Cfg9346_Unlock);
3789 rtl_generic_op(tp, tp->jumbo_ops.disable); 3763 rtl_generic_op(tp, tp->jumbo_ops.disable);
3764 RTL_W8(Cfg9346, Cfg9346_Lock);
3790} 3765}
3791 3766
3792static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) 3767static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp)
@@ -3824,23 +3799,21 @@ static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp)
3824static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) 3799static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
3825{ 3800{
3826 void __iomem *ioaddr = tp->mmio_addr; 3801 void __iomem *ioaddr = tp->mmio_addr;
3827 struct pci_dev *pdev = tp->pci_dev;
3828 3802
3829 RTL_W8(MaxTxPacketSize, 0x3f); 3803 RTL_W8(MaxTxPacketSize, 0x3f);
3830 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); 3804 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0);
3831 RTL_W8(Config4, RTL_R8(Config4) | 0x01); 3805 RTL_W8(Config4, RTL_R8(Config4) | 0x01);
3832 pci_write_config_byte(pdev, 0x79, 0x20); 3806 rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT);
3833} 3807}
3834 3808
3835static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) 3809static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp)
3836{ 3810{
3837 void __iomem *ioaddr = tp->mmio_addr; 3811 void __iomem *ioaddr = tp->mmio_addr;
3838 struct pci_dev *pdev = tp->pci_dev;
3839 3812
3840 RTL_W8(MaxTxPacketSize, 0x0c); 3813 RTL_W8(MaxTxPacketSize, 0x0c);
3841 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); 3814 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0);
3842 RTL_W8(Config4, RTL_R8(Config4) & ~0x01); 3815 RTL_W8(Config4, RTL_R8(Config4) & ~0x01);
3843 pci_write_config_byte(pdev, 0x79, 0x50); 3816 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT);
3844} 3817}
3845 3818
3846static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) 3819static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp)
@@ -3939,280 +3912,6 @@ static void rtl_hw_reset(struct rtl8169_private *tp)
3939 } 3912 }
3940} 3913}
3941 3914
3942static int __devinit
3943rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
3944{
3945 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
3946 const unsigned int region = cfg->region;
3947 struct rtl8169_private *tp;
3948 struct mii_if_info *mii;
3949 struct net_device *dev;
3950 void __iomem *ioaddr;
3951 int chipset, i;
3952 int rc;
3953
3954 if (netif_msg_drv(&debug)) {
3955 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
3956 MODULENAME, RTL8169_VERSION);
3957 }
3958
3959 dev = alloc_etherdev(sizeof (*tp));
3960 if (!dev) {
3961 if (netif_msg_drv(&debug))
3962 dev_err(&pdev->dev, "unable to alloc new ethernet\n");
3963 rc = -ENOMEM;
3964 goto out;
3965 }
3966
3967 SET_NETDEV_DEV(dev, &pdev->dev);
3968 dev->netdev_ops = &rtl8169_netdev_ops;
3969 tp = netdev_priv(dev);
3970 tp->dev = dev;
3971 tp->pci_dev = pdev;
3972 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
3973
3974 mii = &tp->mii;
3975 mii->dev = dev;
3976 mii->mdio_read = rtl_mdio_read;
3977 mii->mdio_write = rtl_mdio_write;
3978 mii->phy_id_mask = 0x1f;
3979 mii->reg_num_mask = 0x1f;
3980 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
3981
3982 /* disable ASPM completely as that cause random device stop working
3983 * problems as well as full system hangs for some PCIe devices users */
3984 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
3985 PCIE_LINK_STATE_CLKPM);
3986
3987 /* enable device (incl. PCI PM wakeup and hotplug setup) */
3988 rc = pci_enable_device(pdev);
3989 if (rc < 0) {
3990 netif_err(tp, probe, dev, "enable failure\n");
3991 goto err_out_free_dev_1;
3992 }
3993
3994 if (pci_set_mwi(pdev) < 0)
3995 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n");
3996
3997 /* make sure PCI base addr 1 is MMIO */
3998 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
3999 netif_err(tp, probe, dev,
4000 "region #%d not an MMIO resource, aborting\n",
4001 region);
4002 rc = -ENODEV;
4003 goto err_out_mwi_2;
4004 }
4005
4006 /* check for weird/broken PCI region reporting */
4007 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
4008 netif_err(tp, probe, dev,
4009 "Invalid PCI region size(s), aborting\n");
4010 rc = -ENODEV;
4011 goto err_out_mwi_2;
4012 }
4013
4014 rc = pci_request_regions(pdev, MODULENAME);
4015 if (rc < 0) {
4016 netif_err(tp, probe, dev, "could not request regions\n");
4017 goto err_out_mwi_2;
4018 }
4019
4020 tp->cp_cmd = RxChkSum;
4021
4022 if ((sizeof(dma_addr_t) > 4) &&
4023 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) {
4024 tp->cp_cmd |= PCIDAC;
4025 dev->features |= NETIF_F_HIGHDMA;
4026 } else {
4027 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4028 if (rc < 0) {
4029 netif_err(tp, probe, dev, "DMA configuration failed\n");
4030 goto err_out_free_res_3;
4031 }
4032 }
4033
4034 /* ioremap MMIO region */
4035 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
4036 if (!ioaddr) {
4037 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n");
4038 rc = -EIO;
4039 goto err_out_free_res_3;
4040 }
4041 tp->mmio_addr = ioaddr;
4042
4043 if (!pci_is_pcie(pdev))
4044 netif_info(tp, probe, dev, "not PCI Express\n");
4045
4046 /* Identify chip attached to board */
4047 rtl8169_get_mac_version(tp, dev, cfg->default_ver);
4048
4049 rtl_init_rxcfg(tp);
4050
4051 RTL_W16(IntrMask, 0x0000);
4052
4053 rtl_hw_reset(tp);
4054
4055 RTL_W16(IntrStatus, 0xffff);
4056
4057 pci_set_master(pdev);
4058
4059 /*
4060 * Pretend we are using VLANs; This bypasses a nasty bug where
4061 * Interrupts stop flowing on high load on 8110SCd controllers.
4062 */
4063 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
4064 tp->cp_cmd |= RxVlan;
4065
4066 rtl_init_mdio_ops(tp);
4067 rtl_init_pll_power_ops(tp);
4068 rtl_init_jumbo_ops(tp);
4069
4070 rtl8169_print_mac_version(tp);
4071
4072 chipset = tp->mac_version;
4073 tp->txd_version = rtl_chip_infos[chipset].txd_version;
4074
4075 RTL_W8(Cfg9346, Cfg9346_Unlock);
4076 RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
4077 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
4078 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
4079 tp->features |= RTL_FEATURE_WOL;
4080 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
4081 tp->features |= RTL_FEATURE_WOL;
4082 tp->features |= rtl_try_msi(tp, cfg);
4083 RTL_W8(Cfg9346, Cfg9346_Lock);
4084
4085 if (rtl_tbi_enabled(tp)) {
4086 tp->set_speed = rtl8169_set_speed_tbi;
4087 tp->get_settings = rtl8169_gset_tbi;
4088 tp->phy_reset_enable = rtl8169_tbi_reset_enable;
4089 tp->phy_reset_pending = rtl8169_tbi_reset_pending;
4090 tp->link_ok = rtl8169_tbi_link_ok;
4091 tp->do_ioctl = rtl_tbi_ioctl;
4092 } else {
4093 tp->set_speed = rtl8169_set_speed_xmii;
4094 tp->get_settings = rtl8169_gset_xmii;
4095 tp->phy_reset_enable = rtl8169_xmii_reset_enable;
4096 tp->phy_reset_pending = rtl8169_xmii_reset_pending;
4097 tp->link_ok = rtl8169_xmii_link_ok;
4098 tp->do_ioctl = rtl_xmii_ioctl;
4099 }
4100
4101 spin_lock_init(&tp->lock);
4102
4103 /* Get MAC address */
4104 for (i = 0; i < ETH_ALEN; i++)
4105 dev->dev_addr[i] = RTL_R8(MAC0 + i);
4106 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4107
4108 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops);
4109 dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
4110 dev->irq = pdev->irq;
4111 dev->base_addr = (unsigned long) ioaddr;
4112
4113 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
4114
4115 /* don't enable SG, IP_CSUM and TSO by default - it might not work
4116 * properly for all devices */
4117 dev->features |= NETIF_F_RXCSUM |
4118 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
4119
4120 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
4121 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
4122 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
4123 NETIF_F_HIGHDMA;
4124
4125 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
4126 /* 8110SCd requires hardware Rx VLAN - disallow toggling */
4127 dev->hw_features &= ~NETIF_F_HW_VLAN_RX;
4128
4129 tp->intr_mask = 0xffff;
4130 tp->hw_start = cfg->hw_start;
4131 tp->intr_event = cfg->intr_event;
4132 tp->napi_event = cfg->napi_event;
4133
4134 tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ?
4135 ~(RxBOVF | RxFOVF) : ~0;
4136
4137 init_timer(&tp->timer);
4138 tp->timer.data = (unsigned long) dev;
4139 tp->timer.function = rtl8169_phy_timer;
4140
4141 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
4142
4143 rc = register_netdev(dev);
4144 if (rc < 0)
4145 goto err_out_msi_4;
4146
4147 pci_set_drvdata(pdev, dev);
4148
4149 netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n",
4150 rtl_chip_infos[chipset].name, dev->base_addr, dev->dev_addr,
4151 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq);
4152 if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) {
4153 netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, "
4154 "tx checksumming: %s]\n",
4155 rtl_chip_infos[chipset].jumbo_max,
4156 rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko");
4157 }
4158
4159 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
4160 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
4161 tp->mac_version == RTL_GIGA_MAC_VER_31) {
4162 rtl8168_driver_start(tp);
4163 }
4164
4165 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
4166
4167 if (pci_dev_run_wake(pdev))
4168 pm_runtime_put_noidle(&pdev->dev);
4169
4170 netif_carrier_off(dev);
4171
4172out:
4173 return rc;
4174
4175err_out_msi_4:
4176 rtl_disable_msi(pdev, tp);
4177 iounmap(ioaddr);
4178err_out_free_res_3:
4179 pci_release_regions(pdev);
4180err_out_mwi_2:
4181 pci_clear_mwi(pdev);
4182 pci_disable_device(pdev);
4183err_out_free_dev_1:
4184 free_netdev(dev);
4185 goto out;
4186}
4187
4188static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
4189{
4190 struct net_device *dev = pci_get_drvdata(pdev);
4191 struct rtl8169_private *tp = netdev_priv(dev);
4192
4193 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
4194 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
4195 tp->mac_version == RTL_GIGA_MAC_VER_31) {
4196 rtl8168_driver_stop(tp);
4197 }
4198
4199 cancel_delayed_work_sync(&tp->task);
4200
4201 unregister_netdev(dev);
4202
4203 rtl_release_firmware(tp);
4204
4205 if (pci_dev_run_wake(pdev))
4206 pm_runtime_get_noresume(&pdev->dev);
4207
4208 /* restore original MAC address */
4209 rtl_rar_set(tp, dev->perm_addr);
4210
4211 rtl_disable_msi(pdev, tp);
4212 rtl8169_release_board(pdev, dev, tp->mmio_addr);
4213 pci_set_drvdata(pdev, NULL);
4214}
4215
4216static void rtl_request_uncached_firmware(struct rtl8169_private *tp) 3915static void rtl_request_uncached_firmware(struct rtl8169_private *tp)
4217{ 3916{
4218 struct rtl_fw *rtl_fw; 3917 struct rtl_fw *rtl_fw;
@@ -4257,78 +3956,6 @@ static void rtl_request_firmware(struct rtl8169_private *tp)
4257 rtl_request_uncached_firmware(tp); 3956 rtl_request_uncached_firmware(tp);
4258} 3957}
4259 3958
4260static int rtl8169_open(struct net_device *dev)
4261{
4262 struct rtl8169_private *tp = netdev_priv(dev);
4263 void __iomem *ioaddr = tp->mmio_addr;
4264 struct pci_dev *pdev = tp->pci_dev;
4265 int retval = -ENOMEM;
4266
4267 pm_runtime_get_sync(&pdev->dev);
4268
4269 /*
4270 * Rx and Tx descriptors needs 256 bytes alignment.
4271 * dma_alloc_coherent provides more.
4272 */
4273 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
4274 &tp->TxPhyAddr, GFP_KERNEL);
4275 if (!tp->TxDescArray)
4276 goto err_pm_runtime_put;
4277
4278 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
4279 &tp->RxPhyAddr, GFP_KERNEL);
4280 if (!tp->RxDescArray)
4281 goto err_free_tx_0;
4282
4283 retval = rtl8169_init_ring(dev);
4284 if (retval < 0)
4285 goto err_free_rx_1;
4286
4287 INIT_DELAYED_WORK(&tp->task, NULL);
4288
4289 smp_mb();
4290
4291 rtl_request_firmware(tp);
4292
4293 retval = request_irq(dev->irq, rtl8169_interrupt,
4294 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
4295 dev->name, dev);
4296 if (retval < 0)
4297 goto err_release_fw_2;
4298
4299 napi_enable(&tp->napi);
4300
4301 rtl8169_init_phy(dev, tp);
4302
4303 rtl8169_set_features(dev, dev->features);
4304
4305 rtl_pll_power_up(tp);
4306
4307 rtl_hw_start(dev);
4308
4309 tp->saved_wolopts = 0;
4310 pm_runtime_put_noidle(&pdev->dev);
4311
4312 rtl8169_check_link_status(dev, tp, ioaddr);
4313out:
4314 return retval;
4315
4316err_release_fw_2:
4317 rtl_release_firmware(tp);
4318 rtl8169_rx_clear(tp);
4319err_free_rx_1:
4320 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
4321 tp->RxPhyAddr);
4322 tp->RxDescArray = NULL;
4323err_free_tx_0:
4324 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
4325 tp->TxPhyAddr);
4326 tp->TxDescArray = NULL;
4327err_pm_runtime_put:
4328 pm_runtime_put_noidle(&pdev->dev);
4329 goto out;
4330}
4331
4332static void rtl_rx_close(struct rtl8169_private *tp) 3959static void rtl_rx_close(struct rtl8169_private *tp)
4333{ 3960{
4334 void __iomem *ioaddr = tp->mmio_addr; 3961 void __iomem *ioaddr = tp->mmio_addr;
@@ -4379,7 +4006,7 @@ static void rtl_hw_start(struct net_device *dev)
4379 4006
4380 tp->hw_start(dev); 4007 tp->hw_start(dev);
4381 4008
4382 netif_start_queue(dev); 4009 rtl_irq_enable_all(tp);
4383} 4010}
4384 4011
4385static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, 4012static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
@@ -4436,6 +4063,56 @@ static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
4436 } 4063 }
4437} 4064}
4438 4065
4066static void rtl_set_rx_mode(struct net_device *dev)
4067{
4068 struct rtl8169_private *tp = netdev_priv(dev);
4069 void __iomem *ioaddr = tp->mmio_addr;
4070 u32 mc_filter[2]; /* Multicast hash filter */
4071 int rx_mode;
4072 u32 tmp = 0;
4073
4074 if (dev->flags & IFF_PROMISC) {
4075 /* Unconditionally log net taps. */
4076 netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
4077 rx_mode =
4078 AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
4079 AcceptAllPhys;
4080 mc_filter[1] = mc_filter[0] = 0xffffffff;
4081 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
4082 (dev->flags & IFF_ALLMULTI)) {
4083 /* Too many to filter perfectly -- accept all multicasts. */
4084 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
4085 mc_filter[1] = mc_filter[0] = 0xffffffff;
4086 } else {
4087 struct netdev_hw_addr *ha;
4088
4089 rx_mode = AcceptBroadcast | AcceptMyPhys;
4090 mc_filter[1] = mc_filter[0] = 0;
4091 netdev_for_each_mc_addr(ha, dev) {
4092 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
4093 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
4094 rx_mode |= AcceptMulticast;
4095 }
4096 }
4097
4098 if (dev->features & NETIF_F_RXALL)
4099 rx_mode |= (AcceptErr | AcceptRunt);
4100
4101 tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode;
4102
4103 if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
4104 u32 data = mc_filter[0];
4105
4106 mc_filter[0] = swab32(mc_filter[1]);
4107 mc_filter[1] = swab32(data);
4108 }
4109
4110 RTL_W32(MAR0 + 4, mc_filter[1]);
4111 RTL_W32(MAR0 + 0, mc_filter[0]);
4112
4113 RTL_W32(RxConfig, tmp);
4114}
4115
4439static void rtl_hw_start_8169(struct net_device *dev) 4116static void rtl_hw_start_8169(struct net_device *dev)
4440{ 4117{
4441 struct rtl8169_private *tp = netdev_priv(dev); 4118 struct rtl8169_private *tp = netdev_priv(dev);
@@ -4506,9 +4183,6 @@ static void rtl_hw_start_8169(struct net_device *dev)
4506 4183
4507 /* no early-rx interrupts */ 4184 /* no early-rx interrupts */
4508 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); 4185 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
4509
4510 /* Enable all known interrupts by setting the interrupt mask. */
4511 RTL_W16(IntrMask, tp->intr_event);
4512} 4186}
4513 4187
4514static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits) 4188static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits)
@@ -4888,8 +4562,8 @@ static void rtl_hw_start_8168(struct net_device *dev)
4888 4562
4889 /* Work around for RxFIFO overflow. */ 4563 /* Work around for RxFIFO overflow. */
4890 if (tp->mac_version == RTL_GIGA_MAC_VER_11) { 4564 if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
4891 tp->intr_event |= RxFIFOOver | PCSTimeout; 4565 tp->event_slow |= RxFIFOOver | PCSTimeout;
4892 tp->intr_event &= ~RxOverflow; 4566 tp->event_slow &= ~RxOverflow;
4893 } 4567 }
4894 4568
4895 rtl_set_rx_tx_desc_registers(tp, ioaddr); 4569 rtl_set_rx_tx_desc_registers(tp, ioaddr);
@@ -4977,8 +4651,6 @@ static void rtl_hw_start_8168(struct net_device *dev)
4977 RTL_W8(Cfg9346, Cfg9346_Lock); 4651 RTL_W8(Cfg9346, Cfg9346_Lock);
4978 4652
4979 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); 4653 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
4980
4981 RTL_W16(IntrMask, tp->intr_event);
4982} 4654}
4983 4655
4984#define R810X_CPCMD_QUIRK_MASK (\ 4656#define R810X_CPCMD_QUIRK_MASK (\
@@ -5077,10 +4749,8 @@ static void rtl_hw_start_8101(struct net_device *dev)
5077 void __iomem *ioaddr = tp->mmio_addr; 4749 void __iomem *ioaddr = tp->mmio_addr;
5078 struct pci_dev *pdev = tp->pci_dev; 4750 struct pci_dev *pdev = tp->pci_dev;
5079 4751
5080 if (tp->mac_version >= RTL_GIGA_MAC_VER_30) { 4752 if (tp->mac_version >= RTL_GIGA_MAC_VER_30)
5081 tp->intr_event &= ~RxFIFOOver; 4753 tp->event_slow &= ~RxFIFOOver;
5082 tp->napi_event &= ~RxFIFOOver;
5083 }
5084 4754
5085 if (tp->mac_version == RTL_GIGA_MAC_VER_13 || 4755 if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
5086 tp->mac_version == RTL_GIGA_MAC_VER_16) { 4756 tp->mac_version == RTL_GIGA_MAC_VER_16) {
@@ -5136,8 +4806,6 @@ static void rtl_hw_start_8101(struct net_device *dev)
5136 rtl_set_rx_mode(dev); 4806 rtl_set_rx_mode(dev);
5137 4807
5138 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); 4808 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
5139
5140 RTL_W16(IntrMask, tp->intr_event);
5141} 4809}
5142 4810
5143static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) 4811static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
@@ -5328,94 +4996,37 @@ static void rtl8169_tx_clear(struct rtl8169_private *tp)
5328{ 4996{
5329 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); 4997 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC);
5330 tp->cur_tx = tp->dirty_tx = 0; 4998 tp->cur_tx = tp->dirty_tx = 0;
4999 netdev_reset_queue(tp->dev);
5331} 5000}
5332 5001
5333static void rtl8169_schedule_work(struct net_device *dev, work_func_t task) 5002static void rtl_reset_work(struct rtl8169_private *tp)
5334{
5335 struct rtl8169_private *tp = netdev_priv(dev);
5336
5337 PREPARE_DELAYED_WORK(&tp->task, task);
5338 schedule_delayed_work(&tp->task, 4);
5339}
5340
5341static void rtl8169_wait_for_quiescence(struct net_device *dev)
5342{
5343 struct rtl8169_private *tp = netdev_priv(dev);
5344 void __iomem *ioaddr = tp->mmio_addr;
5345
5346 synchronize_irq(dev->irq);
5347
5348 /* Wait for any pending NAPI task to complete */
5349 napi_disable(&tp->napi);
5350
5351 rtl8169_irq_mask_and_ack(tp);
5352
5353 tp->intr_mask = 0xffff;
5354 RTL_W16(IntrMask, tp->intr_event);
5355 napi_enable(&tp->napi);
5356}
5357
5358static void rtl8169_reinit_task(struct work_struct *work)
5359{ 5003{
5360 struct rtl8169_private *tp =
5361 container_of(work, struct rtl8169_private, task.work);
5362 struct net_device *dev = tp->dev;
5363 int ret;
5364
5365 rtnl_lock();
5366
5367 if (!netif_running(dev))
5368 goto out_unlock;
5369
5370 rtl8169_wait_for_quiescence(dev);
5371 rtl8169_close(dev);
5372
5373 ret = rtl8169_open(dev);
5374 if (unlikely(ret < 0)) {
5375 if (net_ratelimit())
5376 netif_err(tp, drv, dev,
5377 "reinit failure (status = %d). Rescheduling\n",
5378 ret);
5379 rtl8169_schedule_work(dev, rtl8169_reinit_task);
5380 }
5381
5382out_unlock:
5383 rtnl_unlock();
5384}
5385
5386static void rtl8169_reset_task(struct work_struct *work)
5387{
5388 struct rtl8169_private *tp =
5389 container_of(work, struct rtl8169_private, task.work);
5390 struct net_device *dev = tp->dev; 5004 struct net_device *dev = tp->dev;
5391 int i; 5005 int i;
5392 5006
5393 rtnl_lock(); 5007 napi_disable(&tp->napi);
5394 5008 netif_stop_queue(dev);
5395 if (!netif_running(dev)) 5009 synchronize_sched();
5396 goto out_unlock;
5397 5010
5398 rtl8169_hw_reset(tp); 5011 rtl8169_hw_reset(tp);
5399 5012
5400 rtl8169_wait_for_quiescence(dev);
5401
5402 for (i = 0; i < NUM_RX_DESC; i++) 5013 for (i = 0; i < NUM_RX_DESC; i++)
5403 rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); 5014 rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz);
5404 5015
5405 rtl8169_tx_clear(tp); 5016 rtl8169_tx_clear(tp);
5406 rtl8169_init_ring_indexes(tp); 5017 rtl8169_init_ring_indexes(tp);
5407 5018
5019 napi_enable(&tp->napi);
5408 rtl_hw_start(dev); 5020 rtl_hw_start(dev);
5409 netif_wake_queue(dev); 5021 netif_wake_queue(dev);
5410 rtl8169_check_link_status(dev, tp, tp->mmio_addr); 5022 rtl8169_check_link_status(dev, tp, tp->mmio_addr);
5411
5412out_unlock:
5413 rtnl_unlock();
5414} 5023}
5415 5024
5416static void rtl8169_tx_timeout(struct net_device *dev) 5025static void rtl8169_tx_timeout(struct net_device *dev)
5417{ 5026{
5418 rtl8169_schedule_work(dev, rtl8169_reset_task); 5027 struct rtl8169_private *tp = netdev_priv(dev);
5028
5029 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
5419} 5030}
5420 5031
5421static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, 5032static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
@@ -5540,6 +5151,10 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
5540 5151
5541 txd->opts2 = cpu_to_le32(opts[1]); 5152 txd->opts2 = cpu_to_le32(opts[1]);
5542 5153
5154 netdev_sent_queue(dev, skb->len);
5155
5156 skb_tx_timestamp(skb);
5157
5543 wmb(); 5158 wmb();
5544 5159
5545 /* Anti gcc 2.95.3 bugware (sic) */ 5160 /* Anti gcc 2.95.3 bugware (sic) */
@@ -5552,9 +5167,22 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
5552 5167
5553 RTL_W8(TxPoll, NPQ); 5168 RTL_W8(TxPoll, NPQ);
5554 5169
5170 mmiowb();
5171
5555 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { 5172 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
5173 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
5174 * not miss a ring update when it notices a stopped queue.
5175 */
5176 smp_wmb();
5556 netif_stop_queue(dev); 5177 netif_stop_queue(dev);
5557 smp_rmb(); 5178 /* Sync with rtl_tx:
5179 * - publish queue status and cur_tx ring index (write barrier)
5180 * - refresh dirty_tx ring index (read barrier).
5181 * May the current thread have a pessimistic view of the ring
5182 * status and forget to wake up queue, a racing rtl_tx thread
5183 * can't.
5184 */
5185 smp_mb();
5558 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) 5186 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
5559 netif_wake_queue(dev); 5187 netif_wake_queue(dev);
5560 } 5188 }
@@ -5618,14 +5246,19 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev)
5618 5246
5619 rtl8169_hw_reset(tp); 5247 rtl8169_hw_reset(tp);
5620 5248
5621 rtl8169_schedule_work(dev, rtl8169_reinit_task); 5249 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
5622} 5250}
5623 5251
5624static void rtl8169_tx_interrupt(struct net_device *dev, 5252struct rtl_txc {
5625 struct rtl8169_private *tp, 5253 int packets;
5626 void __iomem *ioaddr) 5254 int bytes;
5255};
5256
5257static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
5627{ 5258{
5259 struct rtl8169_stats *tx_stats = &tp->tx_stats;
5628 unsigned int dirty_tx, tx_left; 5260 unsigned int dirty_tx, tx_left;
5261 struct rtl_txc txc = { 0, 0 };
5629 5262
5630 dirty_tx = tp->dirty_tx; 5263 dirty_tx = tp->dirty_tx;
5631 smp_rmb(); 5264 smp_rmb();
@@ -5644,18 +5277,34 @@ static void rtl8169_tx_interrupt(struct net_device *dev,
5644 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, 5277 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
5645 tp->TxDescArray + entry); 5278 tp->TxDescArray + entry);
5646 if (status & LastFrag) { 5279 if (status & LastFrag) {
5647 dev->stats.tx_packets++; 5280 struct sk_buff *skb = tx_skb->skb;
5648 dev->stats.tx_bytes += tx_skb->skb->len; 5281
5649 dev_kfree_skb(tx_skb->skb); 5282 txc.packets++;
5283 txc.bytes += skb->len;
5284 dev_kfree_skb(skb);
5650 tx_skb->skb = NULL; 5285 tx_skb->skb = NULL;
5651 } 5286 }
5652 dirty_tx++; 5287 dirty_tx++;
5653 tx_left--; 5288 tx_left--;
5654 } 5289 }
5655 5290
5291 u64_stats_update_begin(&tx_stats->syncp);
5292 tx_stats->packets += txc.packets;
5293 tx_stats->bytes += txc.bytes;
5294 u64_stats_update_end(&tx_stats->syncp);
5295
5296 netdev_completed_queue(dev, txc.packets, txc.bytes);
5297
5656 if (tp->dirty_tx != dirty_tx) { 5298 if (tp->dirty_tx != dirty_tx) {
5657 tp->dirty_tx = dirty_tx; 5299 tp->dirty_tx = dirty_tx;
5658 smp_wmb(); 5300 /* Sync with rtl8169_start_xmit:
5301 * - publish dirty_tx ring index (write barrier)
5302 * - refresh cur_tx ring index and queue status (read barrier)
5303 * May the current thread miss the stopped queue condition,
5304 * a racing xmit thread can only have a right view of the
5305 * ring status.
5306 */
5307 smp_mb();
5659 if (netif_queue_stopped(dev) && 5308 if (netif_queue_stopped(dev) &&
5660 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { 5309 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
5661 netif_wake_queue(dev); 5310 netif_wake_queue(dev);
@@ -5666,9 +5315,11 @@ static void rtl8169_tx_interrupt(struct net_device *dev,
5666 * of start_xmit activity is detected (if it is not detected, 5315 * of start_xmit activity is detected (if it is not detected,
5667 * it is slow enough). -- FR 5316 * it is slow enough). -- FR
5668 */ 5317 */
5669 smp_rmb(); 5318 if (tp->cur_tx != dirty_tx) {
5670 if (tp->cur_tx != dirty_tx) 5319 void __iomem *ioaddr = tp->mmio_addr;
5320
5671 RTL_W8(TxPoll, NPQ); 5321 RTL_W8(TxPoll, NPQ);
5322 }
5672 } 5323 }
5673} 5324}
5674 5325
@@ -5707,9 +5358,7 @@ static struct sk_buff *rtl8169_try_rx_copy(void *data,
5707 return skb; 5358 return skb;
5708} 5359}
5709 5360
5710static int rtl8169_rx_interrupt(struct net_device *dev, 5361static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget)
5711 struct rtl8169_private *tp,
5712 void __iomem *ioaddr, u32 budget)
5713{ 5362{
5714 unsigned int cur_rx, rx_left; 5363 unsigned int cur_rx, rx_left;
5715 unsigned int count; 5364 unsigned int count;
@@ -5737,14 +5386,26 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
5737 if (status & RxCRC) 5386 if (status & RxCRC)
5738 dev->stats.rx_crc_errors++; 5387 dev->stats.rx_crc_errors++;
5739 if (status & RxFOVF) { 5388 if (status & RxFOVF) {
5740 rtl8169_schedule_work(dev, rtl8169_reset_task); 5389 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
5741 dev->stats.rx_fifo_errors++; 5390 dev->stats.rx_fifo_errors++;
5742 } 5391 }
5392 if ((status & (RxRUNT | RxCRC)) &&
5393 !(status & (RxRWT | RxFOVF)) &&
5394 (dev->features & NETIF_F_RXALL))
5395 goto process_pkt;
5396
5743 rtl8169_mark_to_asic(desc, rx_buf_sz); 5397 rtl8169_mark_to_asic(desc, rx_buf_sz);
5744 } else { 5398 } else {
5745 struct sk_buff *skb; 5399 struct sk_buff *skb;
5746 dma_addr_t addr = le64_to_cpu(desc->addr); 5400 dma_addr_t addr;
5747 int pkt_size = (status & 0x00003fff) - 4; 5401 int pkt_size;
5402
5403process_pkt:
5404 addr = le64_to_cpu(desc->addr);
5405 if (likely(!(dev->features & NETIF_F_RXFCS)))
5406 pkt_size = (status & 0x00003fff) - 4;
5407 else
5408 pkt_size = status & 0x00003fff;
5748 5409
5749 /* 5410 /*
5750 * The driver does not support incoming fragmented 5411 * The driver does not support incoming fragmented
@@ -5774,8 +5435,10 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
5774 5435
5775 napi_gro_receive(&tp->napi, skb); 5436 napi_gro_receive(&tp->napi, skb);
5776 5437
5777 dev->stats.rx_bytes += pkt_size; 5438 u64_stats_update_begin(&tp->rx_stats.syncp);
5778 dev->stats.rx_packets++; 5439 tp->rx_stats.packets++;
5440 tp->rx_stats.bytes += pkt_size;
5441 u64_stats_update_end(&tp->rx_stats.syncp);
5779 } 5442 }
5780 5443
5781 /* Work around for AMD plateform. */ 5444 /* Work around for AMD plateform. */
@@ -5798,101 +5461,120 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
5798{ 5461{
5799 struct net_device *dev = dev_instance; 5462 struct net_device *dev = dev_instance;
5800 struct rtl8169_private *tp = netdev_priv(dev); 5463 struct rtl8169_private *tp = netdev_priv(dev);
5801 void __iomem *ioaddr = tp->mmio_addr;
5802 int handled = 0; 5464 int handled = 0;
5803 int status; 5465 u16 status;
5804 5466
5805 /* loop handling interrupts until we have no new ones or 5467 status = rtl_get_events(tp);
5806 * we hit a invalid/hotplug case. 5468 if (status && status != 0xffff) {
5807 */ 5469 status &= RTL_EVENT_NAPI | tp->event_slow;
5808 status = RTL_R16(IntrStatus); 5470 if (status) {
5809 while (status && status != 0xffff) { 5471 handled = 1;
5810 status &= tp->intr_event;
5811 if (!status)
5812 break;
5813 5472
5814 handled = 1; 5473 rtl_irq_disable(tp);
5474 napi_schedule(&tp->napi);
5475 }
5476 }
5477 return IRQ_RETVAL(handled);
5478}
5815 5479
5816 /* Handle all of the error cases first. These will reset 5480/*
5817 * the chip, so just exit the loop. 5481 * Workqueue context.
5818 */ 5482 */
5819 if (unlikely(!netif_running(dev))) { 5483static void rtl_slow_event_work(struct rtl8169_private *tp)
5820 rtl8169_hw_reset(tp); 5484{
5485 struct net_device *dev = tp->dev;
5486 u16 status;
5487
5488 status = rtl_get_events(tp) & tp->event_slow;
5489 rtl_ack_events(tp, status);
5490
5491 if (unlikely(status & RxFIFOOver)) {
5492 switch (tp->mac_version) {
5493 /* Work around for rx fifo overflow */
5494 case RTL_GIGA_MAC_VER_11:
5495 netif_stop_queue(dev);
5496 /* XXX - Hack alert. See rtl_task(). */
5497 set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags);
5498 default:
5821 break; 5499 break;
5822 } 5500 }
5501 }
5823 5502
5824 if (unlikely(status & RxFIFOOver)) { 5503 if (unlikely(status & SYSErr))
5825 switch (tp->mac_version) { 5504 rtl8169_pcierr_interrupt(dev);
5826 /* Work around for rx fifo overflow */
5827 case RTL_GIGA_MAC_VER_11:
5828 netif_stop_queue(dev);
5829 rtl8169_tx_timeout(dev);
5830 goto done;
5831 default:
5832 break;
5833 }
5834 }
5835 5505
5836 if (unlikely(status & SYSErr)) { 5506 if (status & LinkChg)
5837 rtl8169_pcierr_interrupt(dev); 5507 __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true);
5838 break; 5508
5839 } 5509 napi_disable(&tp->napi);
5510 rtl_irq_disable(tp);
5840 5511
5841 if (status & LinkChg) 5512 napi_enable(&tp->napi);
5842 __rtl8169_check_link_status(dev, tp, ioaddr, true); 5513 napi_schedule(&tp->napi);
5514}
5843 5515
5844 /* We need to see the lastest version of tp->intr_mask to 5516static void rtl_task(struct work_struct *work)
5845 * avoid ignoring an MSI interrupt and having to wait for 5517{
5846 * another event which may never come. 5518 static const struct {
5847 */ 5519 int bitnr;
5848 smp_rmb(); 5520 void (*action)(struct rtl8169_private *);
5849 if (status & tp->intr_mask & tp->napi_event) { 5521 } rtl_work[] = {
5850 RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); 5522 /* XXX - keep rtl_slow_event_work() as first element. */
5851 tp->intr_mask = ~tp->napi_event; 5523 { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work },
5524 { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work },
5525 { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work }
5526 };
5527 struct rtl8169_private *tp =
5528 container_of(work, struct rtl8169_private, wk.work);
5529 struct net_device *dev = tp->dev;
5530 int i;
5852 5531
5853 if (likely(napi_schedule_prep(&tp->napi))) 5532 rtl_lock_work(tp);
5854 __napi_schedule(&tp->napi);
5855 else
5856 netif_info(tp, intr, dev,
5857 "interrupt %04x in poll\n", status);
5858 }
5859 5533
5860 /* We only get a new MSI interrupt when all active irq 5534 if (!netif_running(dev) ||
5861 * sources on the chip have been acknowledged. So, ack 5535 !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags))
5862 * everything we've seen and check if new sources have become 5536 goto out_unlock;
5863 * active to avoid blocking all interrupts from the chip. 5537
5864 */ 5538 for (i = 0; i < ARRAY_SIZE(rtl_work); i++) {
5865 RTL_W16(IntrStatus, 5539 bool pending;
5866 (status & RxFIFOOver) ? (status | RxOverflow) : status); 5540
5867 status = RTL_R16(IntrStatus); 5541 pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags);
5542 if (pending)
5543 rtl_work[i].action(tp);
5868 } 5544 }
5869done: 5545
5870 return IRQ_RETVAL(handled); 5546out_unlock:
5547 rtl_unlock_work(tp);
5871} 5548}
5872 5549
5873static int rtl8169_poll(struct napi_struct *napi, int budget) 5550static int rtl8169_poll(struct napi_struct *napi, int budget)
5874{ 5551{
5875 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); 5552 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
5876 struct net_device *dev = tp->dev; 5553 struct net_device *dev = tp->dev;
5877 void __iomem *ioaddr = tp->mmio_addr; 5554 u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
5878 int work_done; 5555 int work_done= 0;
5556 u16 status;
5557
5558 status = rtl_get_events(tp);
5559 rtl_ack_events(tp, status & ~tp->event_slow);
5560
5561 if (status & RTL_EVENT_NAPI_RX)
5562 work_done = rtl_rx(dev, tp, (u32) budget);
5563
5564 if (status & RTL_EVENT_NAPI_TX)
5565 rtl_tx(dev, tp);
5879 5566
5880 work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget); 5567 if (status & tp->event_slow) {
5881 rtl8169_tx_interrupt(dev, tp, ioaddr); 5568 enable_mask &= ~tp->event_slow;
5569
5570 rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING);
5571 }
5882 5572
5883 if (work_done < budget) { 5573 if (work_done < budget) {
5884 napi_complete(napi); 5574 napi_complete(napi);
5885 5575
5886 /* We need for force the visibility of tp->intr_mask 5576 rtl_irq_enable(tp, enable_mask);
5887 * for other CPUs, as we can loose an MSI interrupt 5577 mmiowb();
5888 * and potentially wait for a retransmit timeout if we don't.
5889 * The posted write to IntrMask is safe, as it will
5890 * eventually make it to the chip and we won't loose anything
5891 * until it does.
5892 */
5893 tp->intr_mask = 0xffff;
5894 wmb();
5895 RTL_W16(IntrMask, tp->intr_event);
5896 } 5578 }
5897 5579
5898 return work_done; 5580 return work_done;
@@ -5916,26 +5598,19 @@ static void rtl8169_down(struct net_device *dev)
5916 5598
5917 del_timer_sync(&tp->timer); 5599 del_timer_sync(&tp->timer);
5918 5600
5919 netif_stop_queue(dev);
5920
5921 napi_disable(&tp->napi); 5601 napi_disable(&tp->napi);
5922 5602 netif_stop_queue(dev);
5923 spin_lock_irq(&tp->lock);
5924 5603
5925 rtl8169_hw_reset(tp); 5604 rtl8169_hw_reset(tp);
5926 /* 5605 /*
5927 * At this point device interrupts can not be enabled in any function, 5606 * At this point device interrupts can not be enabled in any function,
5928 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task, 5607 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task)
5929 * rtl8169_reinit_task) and napi is disabled (rtl8169_poll). 5608 * and napi is disabled (rtl8169_poll).
5930 */ 5609 */
5931 rtl8169_rx_missed(dev, ioaddr); 5610 rtl8169_rx_missed(dev, ioaddr);
5932 5611
5933 spin_unlock_irq(&tp->lock);
5934
5935 synchronize_irq(dev->irq);
5936
5937 /* Give a racing hard_start_xmit a few cycles to complete. */ 5612 /* Give a racing hard_start_xmit a few cycles to complete. */
5938 synchronize_sched(); /* FIXME: should this be synchronize_irq()? */ 5613 synchronize_sched();
5939 5614
5940 rtl8169_tx_clear(tp); 5615 rtl8169_tx_clear(tp);
5941 5616
@@ -5954,9 +5629,13 @@ static int rtl8169_close(struct net_device *dev)
5954 /* Update counters before going down */ 5629 /* Update counters before going down */
5955 rtl8169_update_counters(dev); 5630 rtl8169_update_counters(dev);
5956 5631
5632 rtl_lock_work(tp);
5633 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
5634
5957 rtl8169_down(dev); 5635 rtl8169_down(dev);
5636 rtl_unlock_work(tp);
5958 5637
5959 free_irq(dev->irq, dev); 5638 free_irq(pdev->irq, dev);
5960 5639
5961 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, 5640 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
5962 tp->RxPhyAddr); 5641 tp->RxPhyAddr);
@@ -5970,77 +5649,127 @@ static int rtl8169_close(struct net_device *dev)
5970 return 0; 5649 return 0;
5971} 5650}
5972 5651
5973static void rtl_set_rx_mode(struct net_device *dev) 5652#ifdef CONFIG_NET_POLL_CONTROLLER
5653static void rtl8169_netpoll(struct net_device *dev)
5654{
5655 struct rtl8169_private *tp = netdev_priv(dev);
5656
5657 rtl8169_interrupt(tp->pci_dev->irq, dev);
5658}
5659#endif
5660
5661static int rtl_open(struct net_device *dev)
5974{ 5662{
5975 struct rtl8169_private *tp = netdev_priv(dev); 5663 struct rtl8169_private *tp = netdev_priv(dev);
5976 void __iomem *ioaddr = tp->mmio_addr; 5664 void __iomem *ioaddr = tp->mmio_addr;
5977 unsigned long flags; 5665 struct pci_dev *pdev = tp->pci_dev;
5978 u32 mc_filter[2]; /* Multicast hash filter */ 5666 int retval = -ENOMEM;
5979 int rx_mode;
5980 u32 tmp = 0;
5981 5667
5982 if (dev->flags & IFF_PROMISC) { 5668 pm_runtime_get_sync(&pdev->dev);
5983 /* Unconditionally log net taps. */
5984 netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
5985 rx_mode =
5986 AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
5987 AcceptAllPhys;
5988 mc_filter[1] = mc_filter[0] = 0xffffffff;
5989 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
5990 (dev->flags & IFF_ALLMULTI)) {
5991 /* Too many to filter perfectly -- accept all multicasts. */
5992 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
5993 mc_filter[1] = mc_filter[0] = 0xffffffff;
5994 } else {
5995 struct netdev_hw_addr *ha;
5996 5669
5997 rx_mode = AcceptBroadcast | AcceptMyPhys; 5670 /*
5998 mc_filter[1] = mc_filter[0] = 0; 5671 * Rx and Tx descriptors needs 256 bytes alignment.
5999 netdev_for_each_mc_addr(ha, dev) { 5672 * dma_alloc_coherent provides more.
6000 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; 5673 */
6001 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); 5674 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
6002 rx_mode |= AcceptMulticast; 5675 &tp->TxPhyAddr, GFP_KERNEL);
6003 } 5676 if (!tp->TxDescArray)
6004 } 5677 goto err_pm_runtime_put;
6005 5678
6006 spin_lock_irqsave(&tp->lock, flags); 5679 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
5680 &tp->RxPhyAddr, GFP_KERNEL);
5681 if (!tp->RxDescArray)
5682 goto err_free_tx_0;
6007 5683
6008 tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; 5684 retval = rtl8169_init_ring(dev);
5685 if (retval < 0)
5686 goto err_free_rx_1;
6009 5687
6010 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { 5688 INIT_WORK(&tp->wk.work, rtl_task);
6011 u32 data = mc_filter[0];
6012 5689
6013 mc_filter[0] = swab32(mc_filter[1]); 5690 smp_mb();
6014 mc_filter[1] = swab32(data);
6015 }
6016 5691
6017 RTL_W32(MAR0 + 4, mc_filter[1]); 5692 rtl_request_firmware(tp);
6018 RTL_W32(MAR0 + 0, mc_filter[0]);
6019 5693
6020 RTL_W32(RxConfig, tmp); 5694 retval = request_irq(pdev->irq, rtl8169_interrupt,
5695 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
5696 dev->name, dev);
5697 if (retval < 0)
5698 goto err_release_fw_2;
5699
5700 rtl_lock_work(tp);
5701
5702 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
5703
5704 napi_enable(&tp->napi);
6021 5705
6022 spin_unlock_irqrestore(&tp->lock, flags); 5706 rtl8169_init_phy(dev, tp);
5707
5708 __rtl8169_set_features(dev, dev->features);
5709
5710 rtl_pll_power_up(tp);
5711
5712 rtl_hw_start(dev);
5713
5714 netif_start_queue(dev);
5715
5716 rtl_unlock_work(tp);
5717
5718 tp->saved_wolopts = 0;
5719 pm_runtime_put_noidle(&pdev->dev);
5720
5721 rtl8169_check_link_status(dev, tp, ioaddr);
5722out:
5723 return retval;
5724
5725err_release_fw_2:
5726 rtl_release_firmware(tp);
5727 rtl8169_rx_clear(tp);
5728err_free_rx_1:
5729 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
5730 tp->RxPhyAddr);
5731 tp->RxDescArray = NULL;
5732err_free_tx_0:
5733 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
5734 tp->TxPhyAddr);
5735 tp->TxDescArray = NULL;
5736err_pm_runtime_put:
5737 pm_runtime_put_noidle(&pdev->dev);
5738 goto out;
6023} 5739}
6024 5740
6025/** 5741static struct rtnl_link_stats64 *
6026 * rtl8169_get_stats - Get rtl8169 read/write statistics 5742rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6027 * @dev: The Ethernet Device to get statistics for
6028 *
6029 * Get TX/RX statistics for rtl8169
6030 */
6031static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
6032{ 5743{
6033 struct rtl8169_private *tp = netdev_priv(dev); 5744 struct rtl8169_private *tp = netdev_priv(dev);
6034 void __iomem *ioaddr = tp->mmio_addr; 5745 void __iomem *ioaddr = tp->mmio_addr;
6035 unsigned long flags; 5746 unsigned int start;
6036 5747
6037 if (netif_running(dev)) { 5748 if (netif_running(dev))
6038 spin_lock_irqsave(&tp->lock, flags);
6039 rtl8169_rx_missed(dev, ioaddr); 5749 rtl8169_rx_missed(dev, ioaddr);
6040 spin_unlock_irqrestore(&tp->lock, flags);
6041 }
6042 5750
6043 return &dev->stats; 5751 do {
5752 start = u64_stats_fetch_begin_bh(&tp->rx_stats.syncp);
5753 stats->rx_packets = tp->rx_stats.packets;
5754 stats->rx_bytes = tp->rx_stats.bytes;
5755 } while (u64_stats_fetch_retry_bh(&tp->rx_stats.syncp, start));
5756
5757
5758 do {
5759 start = u64_stats_fetch_begin_bh(&tp->tx_stats.syncp);
5760 stats->tx_packets = tp->tx_stats.packets;
5761 stats->tx_bytes = tp->tx_stats.bytes;
5762 } while (u64_stats_fetch_retry_bh(&tp->tx_stats.syncp, start));
5763
5764 stats->rx_dropped = dev->stats.rx_dropped;
5765 stats->tx_dropped = dev->stats.tx_dropped;
5766 stats->rx_length_errors = dev->stats.rx_length_errors;
5767 stats->rx_errors = dev->stats.rx_errors;
5768 stats->rx_crc_errors = dev->stats.rx_crc_errors;
5769 stats->rx_fifo_errors = dev->stats.rx_fifo_errors;
5770 stats->rx_missed_errors = dev->stats.rx_missed_errors;
5771
5772 return stats;
6044} 5773}
6045 5774
6046static void rtl8169_net_suspend(struct net_device *dev) 5775static void rtl8169_net_suspend(struct net_device *dev)
@@ -6050,10 +5779,15 @@ static void rtl8169_net_suspend(struct net_device *dev)
6050 if (!netif_running(dev)) 5779 if (!netif_running(dev))
6051 return; 5780 return;
6052 5781
6053 rtl_pll_power_down(tp);
6054
6055 netif_device_detach(dev); 5782 netif_device_detach(dev);
6056 netif_stop_queue(dev); 5783 netif_stop_queue(dev);
5784
5785 rtl_lock_work(tp);
5786 napi_disable(&tp->napi);
5787 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
5788 rtl_unlock_work(tp);
5789
5790 rtl_pll_power_down(tp);
6057} 5791}
6058 5792
6059#ifdef CONFIG_PM 5793#ifdef CONFIG_PM
@@ -6076,7 +5810,12 @@ static void __rtl8169_resume(struct net_device *dev)
6076 5810
6077 rtl_pll_power_up(tp); 5811 rtl_pll_power_up(tp);
6078 5812
6079 rtl8169_schedule_work(dev, rtl8169_reset_task); 5813 rtl_lock_work(tp);
5814 napi_enable(&tp->napi);
5815 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
5816 rtl_unlock_work(tp);
5817
5818 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
6080} 5819}
6081 5820
6082static int rtl8169_resume(struct device *device) 5821static int rtl8169_resume(struct device *device)
@@ -6102,10 +5841,10 @@ static int rtl8169_runtime_suspend(struct device *device)
6102 if (!tp->TxDescArray) 5841 if (!tp->TxDescArray)
6103 return 0; 5842 return 0;
6104 5843
6105 spin_lock_irq(&tp->lock); 5844 rtl_lock_work(tp);
6106 tp->saved_wolopts = __rtl8169_get_wol(tp); 5845 tp->saved_wolopts = __rtl8169_get_wol(tp);
6107 __rtl8169_set_wol(tp, WAKE_ANY); 5846 __rtl8169_set_wol(tp, WAKE_ANY);
6108 spin_unlock_irq(&tp->lock); 5847 rtl_unlock_work(tp);
6109 5848
6110 rtl8169_net_suspend(dev); 5849 rtl8169_net_suspend(dev);
6111 5850
@@ -6121,10 +5860,10 @@ static int rtl8169_runtime_resume(struct device *device)
6121 if (!tp->TxDescArray) 5860 if (!tp->TxDescArray)
6122 return 0; 5861 return 0;
6123 5862
6124 spin_lock_irq(&tp->lock); 5863 rtl_lock_work(tp);
6125 __rtl8169_set_wol(tp, tp->saved_wolopts); 5864 __rtl8169_set_wol(tp, tp->saved_wolopts);
6126 tp->saved_wolopts = 0; 5865 tp->saved_wolopts = 0;
6127 spin_unlock_irq(&tp->lock); 5866 rtl_unlock_work(tp);
6128 5867
6129 rtl8169_init_phy(dev, tp); 5868 rtl8169_init_phy(dev, tp);
6130 5869
@@ -6186,18 +5925,17 @@ static void rtl_shutdown(struct pci_dev *pdev)
6186{ 5925{
6187 struct net_device *dev = pci_get_drvdata(pdev); 5926 struct net_device *dev = pci_get_drvdata(pdev);
6188 struct rtl8169_private *tp = netdev_priv(dev); 5927 struct rtl8169_private *tp = netdev_priv(dev);
5928 struct device *d = &pdev->dev;
5929
5930 pm_runtime_get_sync(d);
6189 5931
6190 rtl8169_net_suspend(dev); 5932 rtl8169_net_suspend(dev);
6191 5933
6192 /* Restore original MAC address */ 5934 /* Restore original MAC address */
6193 rtl_rar_set(tp, dev->perm_addr); 5935 rtl_rar_set(tp, dev->perm_addr);
6194 5936
6195 spin_lock_irq(&tp->lock);
6196
6197 rtl8169_hw_reset(tp); 5937 rtl8169_hw_reset(tp);
6198 5938
6199 spin_unlock_irq(&tp->lock);
6200
6201 if (system_state == SYSTEM_POWER_OFF) { 5939 if (system_state == SYSTEM_POWER_OFF) {
6202 if (__rtl8169_get_wol(tp) & WAKE_ANY) { 5940 if (__rtl8169_get_wol(tp) & WAKE_ANY) {
6203 rtl_wol_suspend_quirk(tp); 5941 rtl_wol_suspend_quirk(tp);
@@ -6207,13 +5945,362 @@ static void rtl_shutdown(struct pci_dev *pdev)
6207 pci_wake_from_d3(pdev, true); 5945 pci_wake_from_d3(pdev, true);
6208 pci_set_power_state(pdev, PCI_D3hot); 5946 pci_set_power_state(pdev, PCI_D3hot);
6209 } 5947 }
5948
5949 pm_runtime_put_noidle(d);
5950}
5951
5952static void __devexit rtl_remove_one(struct pci_dev *pdev)
5953{
5954 struct net_device *dev = pci_get_drvdata(pdev);
5955 struct rtl8169_private *tp = netdev_priv(dev);
5956
5957 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
5958 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
5959 tp->mac_version == RTL_GIGA_MAC_VER_31) {
5960 rtl8168_driver_stop(tp);
5961 }
5962
5963 cancel_work_sync(&tp->wk.work);
5964
5965 unregister_netdev(dev);
5966
5967 rtl_release_firmware(tp);
5968
5969 if (pci_dev_run_wake(pdev))
5970 pm_runtime_get_noresume(&pdev->dev);
5971
5972 /* restore original MAC address */
5973 rtl_rar_set(tp, dev->perm_addr);
5974
5975 rtl_disable_msi(pdev, tp);
5976 rtl8169_release_board(pdev, dev, tp->mmio_addr);
5977 pci_set_drvdata(pdev, NULL);
5978}
5979
5980static const struct net_device_ops rtl_netdev_ops = {
5981 .ndo_open = rtl_open,
5982 .ndo_stop = rtl8169_close,
5983 .ndo_get_stats64 = rtl8169_get_stats64,
5984 .ndo_start_xmit = rtl8169_start_xmit,
5985 .ndo_tx_timeout = rtl8169_tx_timeout,
5986 .ndo_validate_addr = eth_validate_addr,
5987 .ndo_change_mtu = rtl8169_change_mtu,
5988 .ndo_fix_features = rtl8169_fix_features,
5989 .ndo_set_features = rtl8169_set_features,
5990 .ndo_set_mac_address = rtl_set_mac_address,
5991 .ndo_do_ioctl = rtl8169_ioctl,
5992 .ndo_set_rx_mode = rtl_set_rx_mode,
5993#ifdef CONFIG_NET_POLL_CONTROLLER
5994 .ndo_poll_controller = rtl8169_netpoll,
5995#endif
5996
5997};
5998
5999static const struct rtl_cfg_info {
6000 void (*hw_start)(struct net_device *);
6001 unsigned int region;
6002 unsigned int align;
6003 u16 event_slow;
6004 unsigned features;
6005 u8 default_ver;
6006} rtl_cfg_infos [] = {
6007 [RTL_CFG_0] = {
6008 .hw_start = rtl_hw_start_8169,
6009 .region = 1,
6010 .align = 0,
6011 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver,
6012 .features = RTL_FEATURE_GMII,
6013 .default_ver = RTL_GIGA_MAC_VER_01,
6014 },
6015 [RTL_CFG_1] = {
6016 .hw_start = rtl_hw_start_8168,
6017 .region = 2,
6018 .align = 8,
6019 .event_slow = SYSErr | LinkChg | RxOverflow,
6020 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
6021 .default_ver = RTL_GIGA_MAC_VER_11,
6022 },
6023 [RTL_CFG_2] = {
6024 .hw_start = rtl_hw_start_8101,
6025 .region = 2,
6026 .align = 8,
6027 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver |
6028 PCSTimeout,
6029 .features = RTL_FEATURE_MSI,
6030 .default_ver = RTL_GIGA_MAC_VER_13,
6031 }
6032};
6033
6034/* Cfg9346_Unlock assumed. */
6035static unsigned rtl_try_msi(struct rtl8169_private *tp,
6036 const struct rtl_cfg_info *cfg)
6037{
6038 void __iomem *ioaddr = tp->mmio_addr;
6039 unsigned msi = 0;
6040 u8 cfg2;
6041
6042 cfg2 = RTL_R8(Config2) & ~MSIEnable;
6043 if (cfg->features & RTL_FEATURE_MSI) {
6044 if (pci_enable_msi(tp->pci_dev)) {
6045 netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n");
6046 } else {
6047 cfg2 |= MSIEnable;
6048 msi = RTL_FEATURE_MSI;
6049 }
6050 }
6051 if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
6052 RTL_W8(Config2, cfg2);
6053 return msi;
6054}
6055
6056static int __devinit
6057rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6058{
6059 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
6060 const unsigned int region = cfg->region;
6061 struct rtl8169_private *tp;
6062 struct mii_if_info *mii;
6063 struct net_device *dev;
6064 void __iomem *ioaddr;
6065 int chipset, i;
6066 int rc;
6067
6068 if (netif_msg_drv(&debug)) {
6069 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
6070 MODULENAME, RTL8169_VERSION);
6071 }
6072
6073 dev = alloc_etherdev(sizeof (*tp));
6074 if (!dev) {
6075 rc = -ENOMEM;
6076 goto out;
6077 }
6078
6079 SET_NETDEV_DEV(dev, &pdev->dev);
6080 dev->netdev_ops = &rtl_netdev_ops;
6081 tp = netdev_priv(dev);
6082 tp->dev = dev;
6083 tp->pci_dev = pdev;
6084 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
6085
6086 mii = &tp->mii;
6087 mii->dev = dev;
6088 mii->mdio_read = rtl_mdio_read;
6089 mii->mdio_write = rtl_mdio_write;
6090 mii->phy_id_mask = 0x1f;
6091 mii->reg_num_mask = 0x1f;
6092 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
6093
6094 /* disable ASPM completely as that cause random device stop working
6095 * problems as well as full system hangs for some PCIe devices users */
6096 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
6097 PCIE_LINK_STATE_CLKPM);
6098
6099 /* enable device (incl. PCI PM wakeup and hotplug setup) */
6100 rc = pci_enable_device(pdev);
6101 if (rc < 0) {
6102 netif_err(tp, probe, dev, "enable failure\n");
6103 goto err_out_free_dev_1;
6104 }
6105
6106 if (pci_set_mwi(pdev) < 0)
6107 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n");
6108
6109 /* make sure PCI base addr 1 is MMIO */
6110 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
6111 netif_err(tp, probe, dev,
6112 "region #%d not an MMIO resource, aborting\n",
6113 region);
6114 rc = -ENODEV;
6115 goto err_out_mwi_2;
6116 }
6117
6118 /* check for weird/broken PCI region reporting */
6119 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
6120 netif_err(tp, probe, dev,
6121 "Invalid PCI region size(s), aborting\n");
6122 rc = -ENODEV;
6123 goto err_out_mwi_2;
6124 }
6125
6126 rc = pci_request_regions(pdev, MODULENAME);
6127 if (rc < 0) {
6128 netif_err(tp, probe, dev, "could not request regions\n");
6129 goto err_out_mwi_2;
6130 }
6131
6132 tp->cp_cmd = RxChkSum;
6133
6134 if ((sizeof(dma_addr_t) > 4) &&
6135 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) {
6136 tp->cp_cmd |= PCIDAC;
6137 dev->features |= NETIF_F_HIGHDMA;
6138 } else {
6139 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
6140 if (rc < 0) {
6141 netif_err(tp, probe, dev, "DMA configuration failed\n");
6142 goto err_out_free_res_3;
6143 }
6144 }
6145
6146 /* ioremap MMIO region */
6147 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
6148 if (!ioaddr) {
6149 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n");
6150 rc = -EIO;
6151 goto err_out_free_res_3;
6152 }
6153 tp->mmio_addr = ioaddr;
6154
6155 if (!pci_is_pcie(pdev))
6156 netif_info(tp, probe, dev, "not PCI Express\n");
6157
6158 /* Identify chip attached to board */
6159 rtl8169_get_mac_version(tp, dev, cfg->default_ver);
6160
6161 rtl_init_rxcfg(tp);
6162
6163 rtl_irq_disable(tp);
6164
6165 rtl_hw_reset(tp);
6166
6167 rtl_ack_events(tp, 0xffff);
6168
6169 pci_set_master(pdev);
6170
6171 /*
6172 * Pretend we are using VLANs; This bypasses a nasty bug where
6173 * Interrupts stop flowing on high load on 8110SCd controllers.
6174 */
6175 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
6176 tp->cp_cmd |= RxVlan;
6177
6178 rtl_init_mdio_ops(tp);
6179 rtl_init_pll_power_ops(tp);
6180 rtl_init_jumbo_ops(tp);
6181
6182 rtl8169_print_mac_version(tp);
6183
6184 chipset = tp->mac_version;
6185 tp->txd_version = rtl_chip_infos[chipset].txd_version;
6186
6187 RTL_W8(Cfg9346, Cfg9346_Unlock);
6188 RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
6189 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
6190 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
6191 tp->features |= RTL_FEATURE_WOL;
6192 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
6193 tp->features |= RTL_FEATURE_WOL;
6194 tp->features |= rtl_try_msi(tp, cfg);
6195 RTL_W8(Cfg9346, Cfg9346_Lock);
6196
6197 if (rtl_tbi_enabled(tp)) {
6198 tp->set_speed = rtl8169_set_speed_tbi;
6199 tp->get_settings = rtl8169_gset_tbi;
6200 tp->phy_reset_enable = rtl8169_tbi_reset_enable;
6201 tp->phy_reset_pending = rtl8169_tbi_reset_pending;
6202 tp->link_ok = rtl8169_tbi_link_ok;
6203 tp->do_ioctl = rtl_tbi_ioctl;
6204 } else {
6205 tp->set_speed = rtl8169_set_speed_xmii;
6206 tp->get_settings = rtl8169_gset_xmii;
6207 tp->phy_reset_enable = rtl8169_xmii_reset_enable;
6208 tp->phy_reset_pending = rtl8169_xmii_reset_pending;
6209 tp->link_ok = rtl8169_xmii_link_ok;
6210 tp->do_ioctl = rtl_xmii_ioctl;
6211 }
6212
6213 mutex_init(&tp->wk.mutex);
6214
6215 /* Get MAC address */
6216 for (i = 0; i < ETH_ALEN; i++)
6217 dev->dev_addr[i] = RTL_R8(MAC0 + i);
6218 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
6219
6220 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops);
6221 dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
6222
6223 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
6224
6225 /* don't enable SG, IP_CSUM and TSO by default - it might not work
6226 * properly for all devices */
6227 dev->features |= NETIF_F_RXCSUM |
6228 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6229
6230 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
6231 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6232 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
6233 NETIF_F_HIGHDMA;
6234
6235 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
6236 /* 8110SCd requires hardware Rx VLAN - disallow toggling */
6237 dev->hw_features &= ~NETIF_F_HW_VLAN_RX;
6238
6239 dev->hw_features |= NETIF_F_RXALL;
6240 dev->hw_features |= NETIF_F_RXFCS;
6241
6242 tp->hw_start = cfg->hw_start;
6243 tp->event_slow = cfg->event_slow;
6244
6245 tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ?
6246 ~(RxBOVF | RxFOVF) : ~0;
6247
6248 init_timer(&tp->timer);
6249 tp->timer.data = (unsigned long) dev;
6250 tp->timer.function = rtl8169_phy_timer;
6251
6252 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
6253
6254 rc = register_netdev(dev);
6255 if (rc < 0)
6256 goto err_out_msi_4;
6257
6258 pci_set_drvdata(pdev, dev);
6259
6260 netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n",
6261 rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr,
6262 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq);
6263 if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) {
6264 netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, "
6265 "tx checksumming: %s]\n",
6266 rtl_chip_infos[chipset].jumbo_max,
6267 rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko");
6268 }
6269
6270 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
6271 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
6272 tp->mac_version == RTL_GIGA_MAC_VER_31) {
6273 rtl8168_driver_start(tp);
6274 }
6275
6276 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
6277
6278 if (pci_dev_run_wake(pdev))
6279 pm_runtime_put_noidle(&pdev->dev);
6280
6281 netif_carrier_off(dev);
6282
6283out:
6284 return rc;
6285
6286err_out_msi_4:
6287 rtl_disable_msi(pdev, tp);
6288 iounmap(ioaddr);
6289err_out_free_res_3:
6290 pci_release_regions(pdev);
6291err_out_mwi_2:
6292 pci_clear_mwi(pdev);
6293 pci_disable_device(pdev);
6294err_out_free_dev_1:
6295 free_netdev(dev);
6296 goto out;
6210} 6297}
6211 6298
6212static struct pci_driver rtl8169_pci_driver = { 6299static struct pci_driver rtl8169_pci_driver = {
6213 .name = MODULENAME, 6300 .name = MODULENAME,
6214 .id_table = rtl8169_pci_tbl, 6301 .id_table = rtl8169_pci_tbl,
6215 .probe = rtl8169_init_one, 6302 .probe = rtl_init_one,
6216 .remove = __devexit_p(rtl8169_remove_one), 6303 .remove = __devexit_p(rtl_remove_one),
6217 .shutdown = rtl_shutdown, 6304 .shutdown = rtl_shutdown,
6218 .driver.pm = RTL8169_PM_OPS, 6305 .driver.pm = RTL8169_PM_OPS,
6219}; 6306};