]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/r8169.c
r8169: add hw start helpers for the 8168 and the 8101
[linux-2.6-omap-h63xx.git] / drivers / net / r8169.c
index af8030981f10a6fd9e34e4760ab182b081594f69..f4ad9ff268690ba4c46cea6ee97ef17d8c15944a 100644 (file)
 #include <asm/io.h>
 #include <asm/irq.h>
 
-#ifdef CONFIG_R8169_NAPI
-#define NAPI_SUFFIX    "-NAPI"
-#else
-#define NAPI_SUFFIX    ""
-#endif
-
-#define RTL8169_VERSION "2.2LK" NAPI_SUFFIX
+#define RTL8169_VERSION "2.3LK-NAPI"
 #define MODULENAME "r8169"
 #define PFX MODULENAME ": "
 
 #define TX_BUFFS_AVAIL(tp) \
        (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
 
-#ifdef CONFIG_R8169_NAPI
-#define rtl8169_rx_skb                 netif_receive_skb
-#define rtl8169_rx_hwaccel_skb         vlan_hwaccel_receive_skb
-#define rtl8169_rx_quota(count, quota) min(count, quota)
-#else
-#define rtl8169_rx_skb                 netif_rx
-#define rtl8169_rx_hwaccel_skb         vlan_hwaccel_rx
-#define rtl8169_rx_quota(count, quota) count
-#endif
-
 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
 static const int max_interrupt_work = 20;
 
@@ -77,6 +61,7 @@ static const int multicast_filter_limit = 32;
 /* MAC address length */
 #define MAC_ADDR_LEN   6
 
+#define MAX_READ_REQUEST_SHIFT 12
 #define RX_FIFO_THRESH 7       /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
 #define RX_DMA_BURST   6       /* Maximum PCI burst, '6' is 1024 */
 #define TX_DMA_BURST   6       /* Maximum PCI burst, '6' is 1024 */
@@ -212,9 +197,6 @@ enum rtl_registers {
        Config5         = 0x56,
        MultiIntr       = 0x5c,
        PHYAR           = 0x60,
-       TBICSR          = 0x64,
-       TBI_ANAR        = 0x68,
-       TBI_LPAR        = 0x6a,
        PHYstatus       = 0x6c,
        RxMaxSize       = 0xda,
        CPlusCmd        = 0xe0,
@@ -228,6 +210,32 @@ enum rtl_registers {
        FuncForceEvent  = 0xfc,
 };
 
+enum rtl8110_registers {
+       TBICSR                  = 0x64,
+       TBI_ANAR                = 0x68,
+       TBI_LPAR                = 0x6a,
+};
+
+enum rtl8168_8101_registers {
+       CSIDR                   = 0x64,
+       CSIAR                   = 0x68,
+#define        CSIAR_FLAG                      0x80000000
+#define        CSIAR_WRITE_CMD                 0x80000000
+#define        CSIAR_BYTE_ENABLE               0x0f
+#define        CSIAR_BYTE_ENABLE_SHIFT         12
+#define        CSIAR_ADDR_MASK                 0x0fff
+
+       EPHYAR                  = 0x80,
+#define        EPHYAR_FLAG                     0x80000000
+#define        EPHYAR_WRITE_CMD                0x80000000
+#define        EPHYAR_REG_MASK                 0x1f
+#define        EPHYAR_REG_SHIFT                16
+#define        EPHYAR_DATA_MASK                0xffff
+       DBG_REG                 = 0xd1,
+#define        FIX_NAK_1                       (1 << 4)
+#define        FIX_NAK_2                       (1 << 3)
+};
+
 enum rtl_register_content {
        /* InterruptStatusBits */
        SYSErr          = 0x8000,
@@ -281,7 +289,13 @@ enum rtl_register_content {
        TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
 
        /* Config1 register p.24 */
+       LEDS1           = (1 << 7),
+       LEDS0           = (1 << 6),
        MSIEnable       = (1 << 5),     /* Enable Message Signaled Interrupt */
+       Speed_down      = (1 << 4),
+       MEMMAP          = (1 << 3),
+       IOMAP           = (1 << 2),
+       VPD             = (1 << 1),
        PMEnable        = (1 << 0),     /* Power Management Enable */
 
        /* Config2 register p. 25 */
@@ -291,6 +305,7 @@ enum rtl_register_content {
        /* Config3 register p.25 */
        MagicPacket     = (1 << 5),     /* Wake up when receives a Magic Packet */
        LinkUp          = (1 << 4),     /* Wake up when the cable connection is re-established */
+       Beacon_en       = (1 << 0),     /* 8168 only. Reserved in the 8168b */
 
        /* Config5 register p.27 */
        BWF             = (1 << 6),     /* Accept Broadcast wakeup frame */
@@ -308,7 +323,16 @@ enum rtl_register_content {
        TBINwComplete   = 0x01000000,
 
        /* CPlusCmd p.31 */
-       PktCntrDisable  = (1 << 7),     // 8168
+       EnableBist      = (1 << 15),    // 8168 8101
+       Mac_dbgo_oe     = (1 << 14),    // 8168 8101
+       Normal_mode     = (1 << 13),    // unused
+       Force_half_dup  = (1 << 12),    // 8168 8101
+       Force_rxflow_en = (1 << 11),    // 8168 8101
+       Force_txflow_en = (1 << 10),    // 8168 8101
+       Cxpl_dbg_sel    = (1 << 9),     // 8168 8101
+       ASF             = (1 << 8),     // 8168 8101
+       PktCntrDisable  = (1 << 7),     // 8168 8101
+       Mac_dbgo_sel    = 0x001c,       // 8168
        RxVlan          = (1 << 6),
        RxChkSum        = (1 << 5),
        PCIDAC          = (1 << 4),
@@ -386,17 +410,16 @@ struct ring_info {
 };
 
 enum features {
-       RTL_FEATURE_WOL = (1 << 0),
-       RTL_FEATURE_MSI = (1 << 1),
+       RTL_FEATURE_WOL         = (1 << 0),
+       RTL_FEATURE_MSI         = (1 << 1),
+       RTL_FEATURE_GMII        = (1 << 2),
 };
 
 struct rtl8169_private {
        void __iomem *mmio_addr;        /* memory map physical address */
        struct pci_dev *pci_dev;        /* Index of PCI device */
        struct net_device *dev;
-#ifdef CONFIG_R8169_NAPI
        struct napi_struct napi;
-#endif
        spinlock_t lock;                /* spin lock flag */
        u32 msg_enable;
        int chipset;
@@ -424,13 +447,16 @@ struct rtl8169_private {
        struct vlan_group *vlgrp;
 #endif
        int (*set_speed)(struct net_device *, u8 autoneg, u16 speed, u8 duplex);
-       void (*get_settings)(struct net_device *, struct ethtool_cmd *);
+       int (*get_settings)(struct net_device *, struct ethtool_cmd *);
        void (*phy_reset_enable)(void __iomem *);
        void (*hw_start)(struct net_device *);
        unsigned int (*phy_reset_pending)(void __iomem *);
        unsigned int (*link_ok)(void __iomem *);
+       int pcie_cap;
        struct delayed_work task;
        unsigned features;
+
+       struct mii_if_info mii;
 };
 
 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
@@ -458,10 +484,7 @@ static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
 static void rtl8169_down(struct net_device *dev);
 static void rtl8169_rx_clear(struct rtl8169_private *tp);
-
-#ifdef CONFIG_R8169_NAPI
 static int rtl8169_poll(struct napi_struct *napi, int budget);
-#endif
 
 static const unsigned int rtl8169_rx_config =
        (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
@@ -503,6 +526,94 @@ static int mdio_read(void __iomem *ioaddr, int reg_addr)
        return value;
 }
 
+static void mdio_patch(void __iomem *ioaddr, int reg_addr, int value)
+{
+       mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value);
+}
+
+static void rtl_mdio_write(struct net_device *dev, int phy_id, int location,
+                          int val)
+{
+       struct rtl8169_private *tp = netdev_priv(dev);
+       void __iomem *ioaddr = tp->mmio_addr;
+
+       mdio_write(ioaddr, location, val);
+}
+
+static int rtl_mdio_read(struct net_device *dev, int phy_id, int location)
+{
+       struct rtl8169_private *tp = netdev_priv(dev);
+       void __iomem *ioaddr = tp->mmio_addr;
+
+       return mdio_read(ioaddr, location);
+}
+
+static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value)
+{
+       unsigned int i;
+
+       RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
+               (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
+
+       for (i = 0; i < 100; i++) {
+               if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG))
+                       break;
+               udelay(10);
+       }
+}
+
+static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr)
+{
+       u16 value = 0xffff;
+       unsigned int i;
+
+       RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
+
+       for (i = 0; i < 100; i++) {
+               if (RTL_R32(EPHYAR) & EPHYAR_FLAG) {
+                       value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK;
+                       break;
+               }
+               udelay(10);
+       }
+
+       return value;
+}
+
+static void rtl_csi_write(void __iomem *ioaddr, int addr, int value)
+{
+       unsigned int i;
+
+       RTL_W32(CSIDR, value);
+       RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
+               CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
+
+       for (i = 0; i < 100; i++) {
+               if (!(RTL_R32(CSIAR) & CSIAR_FLAG))
+                       break;
+               udelay(10);
+       }
+}
+
+static u32 rtl_csi_read(void __iomem *ioaddr, int addr)
+{
+       u32 value = ~0x00;
+       unsigned int i;
+
+       RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) |
+               CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
+
+       for (i = 0; i < 100; i++) {
+               if (RTL_R32(CSIAR) & CSIAR_FLAG) {
+                       value = RTL_R32(CSIDR);
+                       break;
+               }
+               udelay(10);
+       }
+
+       return value;
+}
+
 static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
 {
        RTL_W16(IntrMask, 0x0000);
@@ -843,10 +954,11 @@ static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
                               struct sk_buff *skb)
 {
        u32 opts2 = le32_to_cpu(desc->opts2);
+       struct vlan_group *vlgrp = tp->vlgrp;
        int ret;
 
-       if (tp->vlgrp && (opts2 & RxVlanTag)) {
-               rtl8169_rx_hwaccel_skb(skb, tp->vlgrp, swab16(opts2 & 0xffff));
+       if (vlgrp && (opts2 & RxVlanTag)) {
+               vlan_hwaccel_receive_skb(skb, vlgrp, swab16(opts2 & 0xffff));
                ret = 0;
        } else
                ret = -1;
@@ -870,7 +982,7 @@ static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
 
 #endif
 
-static void rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
+static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
        void __iomem *ioaddr = tp->mmio_addr;
@@ -887,65 +999,29 @@ static void rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
 
        cmd->speed = SPEED_1000;
        cmd->duplex = DUPLEX_FULL; /* Always set */
+
+       return 0;
 }
 
-static void rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
+static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
-       u8 status;
-
-       cmd->supported = SUPPORTED_10baseT_Half |
-                        SUPPORTED_10baseT_Full |
-                        SUPPORTED_100baseT_Half |
-                        SUPPORTED_100baseT_Full |
-                        SUPPORTED_1000baseT_Full |
-                        SUPPORTED_Autoneg |
-                        SUPPORTED_TP;
-
-       cmd->autoneg = 1;
-       cmd->advertising = ADVERTISED_TP | ADVERTISED_Autoneg;
-
-       if (tp->phy_auto_nego_reg & ADVERTISE_10HALF)
-               cmd->advertising |= ADVERTISED_10baseT_Half;
-       if (tp->phy_auto_nego_reg & ADVERTISE_10FULL)
-               cmd->advertising |= ADVERTISED_10baseT_Full;
-       if (tp->phy_auto_nego_reg & ADVERTISE_100HALF)
-               cmd->advertising |= ADVERTISED_100baseT_Half;
-       if (tp->phy_auto_nego_reg & ADVERTISE_100FULL)
-               cmd->advertising |= ADVERTISED_100baseT_Full;
-       if (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)
-               cmd->advertising |= ADVERTISED_1000baseT_Full;
-
-       status = RTL_R8(PHYstatus);
-
-       if (status & _1000bpsF)
-               cmd->speed = SPEED_1000;
-       else if (status & _100bps)
-               cmd->speed = SPEED_100;
-       else if (status & _10bps)
-               cmd->speed = SPEED_10;
-
-       if (status & TxFlowCtrl)
-               cmd->advertising |= ADVERTISED_Asym_Pause;
-       if (status & RxFlowCtrl)
-               cmd->advertising |= ADVERTISED_Pause;
-
-       cmd->duplex = ((status & _1000bpsF) || (status & FullDup)) ?
-                     DUPLEX_FULL : DUPLEX_HALF;
+
+       return mii_ethtool_gset(&tp->mii, cmd);
 }
 
 static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
        unsigned long flags;
+       int rc;
 
        spin_lock_irqsave(&tp->lock, flags);
 
-       tp->get_settings(dev, cmd);
+       rc = tp->get_settings(dev, cmd);
 
        spin_unlock_irqrestore(&tp->lock, flags);
-       return 0;
+       return rc;
 }
 
 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
@@ -1438,8 +1514,10 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
 
        rtl_hw_phy_config(dev);
 
-       dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
-       RTL_W8(0x82, 0x01);
+       if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
+               dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
+               RTL_W8(0x82, 0x01);
+       }
 
        pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
 
@@ -1531,7 +1609,7 @@ static const struct rtl_cfg_info {
        unsigned int align;
        u16 intr_event;
        u16 napi_event;
-       unsigned msi;
+       unsigned features;
 } rtl_cfg_infos [] = {
        [RTL_CFG_0] = {
                .hw_start       = rtl_hw_start_8169,
@@ -1540,7 +1618,7 @@ static const struct rtl_cfg_info {
                .intr_event     = SYSErr | LinkChg | RxOverflow |
                                  RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
                .napi_event     = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
-               .msi            = 0
+               .features       = RTL_FEATURE_GMII
        },
        [RTL_CFG_1] = {
                .hw_start       = rtl_hw_start_8168,
@@ -1549,7 +1627,7 @@ static const struct rtl_cfg_info {
                .intr_event     = SYSErr | LinkChg | RxOverflow |
                                  TxErr | TxOK | RxOK | RxErr,
                .napi_event     = TxErr | TxOK | RxOK | RxOverflow,
-               .msi            = RTL_FEATURE_MSI
+               .features       = RTL_FEATURE_GMII | RTL_FEATURE_MSI
        },
        [RTL_CFG_2] = {
                .hw_start       = rtl_hw_start_8101,
@@ -1558,7 +1636,7 @@ static const struct rtl_cfg_info {
                .intr_event     = SYSErr | LinkChg | RxOverflow | PCSTimeout |
                                  RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
                .napi_event     = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
-               .msi            = RTL_FEATURE_MSI
+               .features       = RTL_FEATURE_MSI
        }
 };
 
@@ -1570,7 +1648,7 @@ static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr,
        u8 cfg2;
 
        cfg2 = RTL_R8(Config2) & ~MSIEnable;
-       if (cfg->msi) {
+       if (cfg->features & RTL_FEATURE_MSI) {
                if (pci_enable_msi(pdev)) {
                        dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
                } else {
@@ -1596,6 +1674,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
        const unsigned int region = cfg->region;
        struct rtl8169_private *tp;
+       struct mii_if_info *mii;
        struct net_device *dev;
        void __iomem *ioaddr;
        unsigned int i;
@@ -1617,8 +1696,17 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        SET_NETDEV_DEV(dev, &pdev->dev);
        tp = netdev_priv(dev);
        tp->dev = dev;
+       tp->pci_dev = pdev;
        tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
 
+       mii = &tp->mii;
+       mii->dev = dev;
+       mii->mdio_read = rtl_mdio_read;
+       mii->mdio_write = rtl_mdio_write;
+       mii->phy_id_mask = 0x1f;
+       mii->reg_num_mask = 0x1f;
+       mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
+
        /* enable device (incl. PCI PM wakeup and hotplug setup) */
        rc = pci_enable_device(pdev);
        if (rc < 0) {
@@ -1687,6 +1775,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_out_free_res_4;
        }
 
+       tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
+       if (!tp->pcie_cap && netif_msg_probe(tp))
+               dev_info(&pdev->dev, "no PCI Express capability\n");
+
        /* Unneeded ? Don't mess with Mrs. Murphy. */
        rtl8169_irq_mask_and_ack(ioaddr);
 
@@ -1705,18 +1797,18 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        rtl8169_print_mac_version(tp);
 
-       for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--) {
+       for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) {
                if (tp->mac_version == rtl_chip_info[i].mac_version)
                        break;
        }
-       if (i < 0) {
+       if (i == ARRAY_SIZE(rtl_chip_info)) {
                /* Unknown chip: assume array element #0, original RTL-8169 */
                if (netif_msg_probe(tp)) {
                        dev_printk(KERN_DEBUG, &pdev->dev,
                                "unknown chip version, assuming %s\n",
                                rtl_chip_info[0].name);
                }
-               i++;
+               i = 0;
        }
        tp->chipset = i;
 
@@ -1763,9 +1855,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        dev->change_mtu = rtl8169_change_mtu;
        dev->set_mac_address = rtl_set_mac_address;
 
-#ifdef CONFIG_R8169_NAPI
        netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
-#endif
 
 #ifdef CONFIG_R8169_VLAN
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
@@ -1777,7 +1867,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #endif
 
        tp->intr_mask = 0xffff;
-       tp->pci_dev = pdev;
        tp->mmio_addr = ioaddr;
        tp->align = cfg->align;
        tp->hw_start = cfg->hw_start;
@@ -1887,9 +1976,7 @@ static int rtl8169_open(struct net_device *dev)
        if (retval < 0)
                goto err_release_ring_2;
 
-#ifdef CONFIG_R8169_NAPI
        napi_enable(&tp->napi);
-#endif
 
        rtl_hw_start(dev);
 
@@ -2002,7 +2089,7 @@ static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
        u32 clk;
 
        clk = RTL_R8(Config2) & PCI_Clock_66MHz;
-       for (i = 0; i < ARRAY_SIZE(cfg2_info); i++) {
+       for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
                if ((p->mac_version == mac_version) && (p->clk == clk)) {
                        RTL_W32(0x7c, p->val);
                        break;
@@ -2083,12 +2170,51 @@ static void rtl_hw_start_8169(struct net_device *dev)
        RTL_W16(IntrMask, tp->intr_event);
 }
 
+static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+       struct rtl8169_private *tp = netdev_priv(dev);
+       int cap = tp->pcie_cap;
+
+       if (cap) {
+               u16 ctl;
+
+               pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
+               ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force;
+               pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl);
+       }
+}
+
+static void rtl_csi_access_enable(void __iomem *ioaddr)
+{
+       u32 csi;
+
+       csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff;
+       rtl_csi_write(ioaddr, 0x070c, csi | 0x27000000);
+}
+
+struct ephy_info {
+       unsigned int offset;
+       u16 mask;
+       u16 bits;
+};
+
+static void rtl_ephy_init(void __iomem *ioaddr, struct ephy_info *e, int len)
+{
+       u16 w;
+
+       while (len-- > 0) {
+               w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits;
+               rtl_ephy_write(ioaddr, e->offset, w);
+               e++;
+       }
+}
+
 static void rtl_hw_start_8168(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
        void __iomem *ioaddr = tp->mmio_addr;
        struct pci_dev *pdev = tp->pci_dev;
-       u8 ctl;
 
        RTL_W8(Cfg9346, Cfg9346_Unlock);
 
@@ -2102,10 +2228,7 @@ static void rtl_hw_start_8168(struct net_device *dev)
 
        RTL_W16(CPlusCmd, tp->cp_cmd);
 
-       /* Tx performance tweak. */
-       pci_read_config_byte(pdev, 0x69, &ctl);
-       ctl = (ctl & ~0x70) | 0x50;
-       pci_write_config_byte(pdev, 0x69, ctl);
+       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
 
        RTL_W16(IntrMitigate, 0x5151);
 
@@ -2140,8 +2263,12 @@ static void rtl_hw_start_8101(struct net_device *dev)
 
        if ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
            (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
-               pci_write_config_word(pdev, 0x68, 0x00);
-               pci_write_config_word(pdev, 0x69, 0x08);
+               int cap = tp->pcie_cap;
+
+               if (cap) {
+                       pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL,
+                                             PCI_EXP_DEVCTL_NOSNOOP_EN);
+               }
        }
 
        RTL_W8(Cfg9346, Cfg9346_Unlock);
@@ -2197,9 +2324,7 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
        if (ret < 0)
                goto out;
 
-#ifdef CONFIG_R8169_NAPI
        napi_enable(&tp->napi);
-#endif
 
        rtl_hw_start(dev);
 
@@ -2391,17 +2516,13 @@ static void rtl8169_wait_for_quiescence(struct net_device *dev)
        synchronize_irq(dev->irq);
 
        /* Wait for any pending NAPI task to complete */
-#ifdef CONFIG_R8169_NAPI
        napi_disable(&tp->napi);
-#endif
 
        rtl8169_irq_mask_and_ack(ioaddr);
 
-#ifdef CONFIG_R8169_NAPI
        tp->intr_mask = 0xffff;
        RTL_W16(IntrMask, tp->intr_event);
        napi_enable(&tp->napi);
-#endif
 }
 
 static void rtl8169_reinit_task(struct work_struct *work)
@@ -2767,7 +2888,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
 
        cur_rx = tp->cur_rx;
        rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx;
-       rx_left = rtl8169_rx_quota(rx_left, budget);
+       rx_left = min(rx_left, budget);
 
        for (; rx_left > 0; rx_left--, cur_rx++) {
                unsigned int entry = cur_rx % NUM_RX_DESC;
@@ -2829,7 +2950,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
                        skb->protocol = eth_type_trans(skb, dev);
 
                        if (rtl8169_rx_vlan_skb(tp, desc, skb) < 0)
-                               rtl8169_rx_skb(skb);
+                               netif_receive_skb(skb);
 
                        dev->last_rx = jiffies;
                        dev->stats.rx_bytes += pkt_size;
@@ -2869,87 +2990,61 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct rtl8169_private *tp = netdev_priv(dev);
-       int boguscnt = max_interrupt_work;
        void __iomem *ioaddr = tp->mmio_addr;
-       int status;
        int handled = 0;
+       int status;
 
-       do {
-               status = RTL_R16(IntrStatus);
+       status = RTL_R16(IntrStatus);
 
-               /* hotplug/major error/no more work/shared irq */
-               if ((status == 0xFFFF) || !status)
-                       break;
+       /* hotplug/major error/no more work/shared irq */
+       if ((status == 0xffff) || !status)
+               goto out;
 
-               handled = 1;
+       handled = 1;
 
-               if (unlikely(!netif_running(dev))) {
-                       rtl8169_asic_down(ioaddr);
-                       goto out;
-               }
+       if (unlikely(!netif_running(dev))) {
+               rtl8169_asic_down(ioaddr);
+               goto out;
+       }
 
-               status &= tp->intr_mask;
-               RTL_W16(IntrStatus,
-                       (status & RxFIFOOver) ? (status | RxOverflow) : status);
+       status &= tp->intr_mask;
+       RTL_W16(IntrStatus,
+               (status & RxFIFOOver) ? (status | RxOverflow) : status);
 
-               if (!(status & tp->intr_event))
-                       break;
+       if (!(status & tp->intr_event))
+               goto out;
 
-                /* Work around for rx fifo overflow */
-                if (unlikely(status & RxFIFOOver) &&
-                   (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
-                       netif_stop_queue(dev);
-                       rtl8169_tx_timeout(dev);
-                       break;
-               }
+       /* Work around for rx fifo overflow */
+       if (unlikely(status & RxFIFOOver) &&
+           (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
+               netif_stop_queue(dev);
+               rtl8169_tx_timeout(dev);
+               goto out;
+       }
 
-               if (unlikely(status & SYSErr)) {
-                       rtl8169_pcierr_interrupt(dev);
-                       break;
-               }
+       if (unlikely(status & SYSErr)) {
+               rtl8169_pcierr_interrupt(dev);
+               goto out;
+       }
 
-               if (status & LinkChg)
-                       rtl8169_check_link_status(dev, tp, ioaddr);
+       if (status & LinkChg)
+               rtl8169_check_link_status(dev, tp, ioaddr);
 
-#ifdef CONFIG_R8169_NAPI
-               if (status & tp->napi_event) {
-                       RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
-                       tp->intr_mask = ~tp->napi_event;
+       if (status & tp->napi_event) {
+               RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
+               tp->intr_mask = ~tp->napi_event;
 
                if (likely(netif_rx_schedule_prep(dev, &tp->napi)))
                        __netif_rx_schedule(dev, &tp->napi);
-                       else if (netif_msg_intr(tp)) {
-                               printk(KERN_INFO "%s: interrupt %04x in poll\n",
-                                      dev->name, status);
-                       }
-               }
-               break;
-#else
-               /* Rx interrupt */
-               if (status & (RxOK | RxOverflow | RxFIFOOver))
-                       rtl8169_rx_interrupt(dev, tp, ioaddr, ~(u32)0);
-
-               /* Tx interrupt */
-               if (status & (TxOK | TxErr))
-                       rtl8169_tx_interrupt(dev, tp, ioaddr);
-#endif
-
-               boguscnt--;
-       } while (boguscnt > 0);
-
-       if (boguscnt <= 0) {
-               if (netif_msg_intr(tp) && net_ratelimit() ) {
-                       printk(KERN_WARNING
-                              "%s: Too much work at interrupt!\n", dev->name);
+               else if (netif_msg_intr(tp)) {
+                       printk(KERN_INFO "%s: interrupt %04x in poll\n",
+                              dev->name, status);
                }
-               /* Clear all interrupt sources. */
-               RTL_W16(IntrStatus, 0xffff);
        }
 out:
        return IRQ_RETVAL(handled);
 }
 
-#ifdef CONFIG_R8169_NAPI
 static int rtl8169_poll(struct napi_struct *napi, int budget)
 {
        struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
@@ -2975,7 +3070,6 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
 
        return work_done;
 }
-#endif
 
 static void rtl8169_down(struct net_device *dev)
 {
@@ -2987,9 +3081,7 @@ static void rtl8169_down(struct net_device *dev)
 
        netif_stop_queue(dev);
 
-#ifdef CONFIG_R8169_NAPI
        napi_disable(&tp->napi);
-#endif
 
 core_down:
        spin_lock_irq(&tp->lock);
@@ -3091,15 +3183,11 @@ static void rtl_set_rx_mode(struct net_device *dev)
        tmp = rtl8169_rx_config | rx_mode |
              (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
 
-       if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_13) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_14) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_15) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_16) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_17)) {
-               mc_filter[0] = 0xffffffff;
-               mc_filter[1] = 0xffffffff;
+       if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
+               u32 data = mc_filter[0];
+
+               mc_filter[0] = swab32(mc_filter[1]);
+               mc_filter[1] = swab32(data);
        }
 
        RTL_W32(MAR0 + 0, mc_filter[0]);