OSDN Git Service

r8169: remove calls to rtl_set_rx_mode
[uclinux-h8/linux.git] / drivers / net / ethernet / realtek / r8169.c
index b4779ac..c7b9301 100644 (file)
    The RTL chips use a 64 element hash table based on the Ethernet CRC. */
 static const int multicast_filter_limit = 32;
 
-#define MAX_READ_REQUEST_SHIFT 12
 #define TX_DMA_BURST   7       /* Maximum PCI burst, '7' is unlimited */
 #define InterFrameGap  0x03    /* 3 means InterFrameGap = the shortest one */
 
 #define R8169_REGS_SIZE                256
-#define R8169_NAPI_WEIGHT      64
+#define R8169_RX_BUF_SIZE      (SZ_16K - 1)
 #define NUM_TX_DESC    64      /* Number of Tx descriptor registers */
 #define NUM_RX_DESC    256U    /* Number of Rx descriptor registers */
 #define R8169_TX_RING_BYTES    (NUM_TX_DESC * sizeof(struct TxDesc))
@@ -99,12 +98,12 @@ static const int multicast_filter_limit = 32;
 #define RTL8169_PHY_TIMEOUT    (10*HZ)
 
 /* write/read MMIO register */
-#define RTL_W8(reg, val8)      writeb ((val8), ioaddr + (reg))
-#define RTL_W16(reg, val16)    writew ((val16), ioaddr + (reg))
-#define RTL_W32(reg, val32)    writel ((val32), ioaddr + (reg))
-#define RTL_R8(reg)            readb (ioaddr + (reg))
-#define RTL_R16(reg)           readw (ioaddr + (reg))
-#define RTL_R32(reg)           readl (ioaddr + (reg))
+#define RTL_W8(tp, reg, val8)  writeb((val8), tp->mmio_addr + (reg))
+#define RTL_W16(tp, reg, val16)        writew((val16), tp->mmio_addr + (reg))
+#define RTL_W32(tp, reg, val32)        writel((val32), tp->mmio_addr + (reg))
+#define RTL_R8(tp, reg)                readb(tp->mmio_addr + (reg))
+#define RTL_R16(tp, reg)               readw(tp->mmio_addr + (reg))
+#define RTL_R32(tp, reg)               readl(tp->mmio_addr + (reg))
 
 enum mac_version {
        RTL_GIGA_MAC_VER_01 = 0,
@@ -172,12 +171,11 @@ enum rtl_tx_desc_version {
 #define JUMBO_7K       (7*1024 - ETH_HLEN - 2)
 #define JUMBO_9K       (9*1024 - ETH_HLEN - 2)
 
-#define _R(NAME,TD,FW,SZ,B) {  \
+#define _R(NAME,TD,FW,SZ) {    \
        .name = NAME,           \
        .txd_version = TD,      \
        .fw_name = FW,          \
        .jumbo_max = SZ,        \
-       .jumbo_tx_csum = B      \
 }
 
 static const struct {
@@ -185,135 +183,111 @@ static const struct {
        enum rtl_tx_desc_version txd_version;
        const char *fw_name;
        u16 jumbo_max;
-       bool jumbo_tx_csum;
 } rtl_chip_infos[] = {
        /* PCI devices. */
        [RTL_GIGA_MAC_VER_01] =
-               _R("RTL8169",           RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8169",           RTL_TD_0, NULL, JUMBO_7K),
        [RTL_GIGA_MAC_VER_02] =
-               _R("RTL8169s",          RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8169s",          RTL_TD_0, NULL, JUMBO_7K),
        [RTL_GIGA_MAC_VER_03] =
-               _R("RTL8110s",          RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8110s",          RTL_TD_0, NULL, JUMBO_7K),
        [RTL_GIGA_MAC_VER_04] =
-               _R("RTL8169sb/8110sb",  RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8169sb/8110sb",  RTL_TD_0, NULL, JUMBO_7K),
        [RTL_GIGA_MAC_VER_05] =
-               _R("RTL8169sc/8110sc",  RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8169sc/8110sc",  RTL_TD_0, NULL, JUMBO_7K),
        [RTL_GIGA_MAC_VER_06] =
-               _R("RTL8169sc/8110sc",  RTL_TD_0, NULL, JUMBO_7K, true),
+               _R("RTL8169sc/8110sc",  RTL_TD_0, NULL, JUMBO_7K),
        /* PCI-E devices. */
        [RTL_GIGA_MAC_VER_07] =
-               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K, true),
+               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_08] =
-               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K, true),
+               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_09] =
-               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K, true),
+               _R("RTL8102e",          RTL_TD_1, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_10] =
-               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K, true),
+               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_11] =
-               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K, false),
+               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K),
        [RTL_GIGA_MAC_VER_12] =
-               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K, false),
+               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K),
        [RTL_GIGA_MAC_VER_13] =
-               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K, true),
+               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_14] =
-               _R("RTL8100e",          RTL_TD_0, NULL, JUMBO_1K, true),
+               _R("RTL8100e",          RTL_TD_0, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_15] =
-               _R("RTL8100e",          RTL_TD_0, NULL, JUMBO_1K, true),
+               _R("RTL8100e",          RTL_TD_0, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_16] =
-               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K, true),
+               _R("RTL8101e",          RTL_TD_0, NULL, JUMBO_1K),
        [RTL_GIGA_MAC_VER_17] =
-               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K, false),
+               _R("RTL8168b/8111b",    RTL_TD_0, NULL, JUMBO_4K),
        [RTL_GIGA_MAC_VER_18] =
-               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_19] =
-               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_20] =
-               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_21] =
-               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_22] =
-               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168c/8111c",    RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_23] =
-               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_24] =
-               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K, false),
+               _R("RTL8168cp/8111cp",  RTL_TD_1, NULL, JUMBO_6K),
        [RTL_GIGA_MAC_VER_25] =
-               _R("RTL8168d/8111d",    RTL_TD_1, FIRMWARE_8168D_1,
-                                                       JUMBO_9K, false),
+               _R("RTL8168d/8111d",    RTL_TD_1, FIRMWARE_8168D_1, JUMBO_9K),
        [RTL_GIGA_MAC_VER_26] =
-               _R("RTL8168d/8111d",    RTL_TD_1, FIRMWARE_8168D_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8168d/8111d",    RTL_TD_1, FIRMWARE_8168D_2, JUMBO_9K),
        [RTL_GIGA_MAC_VER_27] =
-               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K, false),
+               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_28] =
-               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K, false),
+               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_29] =
-               _R("RTL8105e",          RTL_TD_1, FIRMWARE_8105E_1,
-                                                       JUMBO_1K, true),
+               _R("RTL8105e",          RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K),
        [RTL_GIGA_MAC_VER_30] =
-               _R("RTL8105e",          RTL_TD_1, FIRMWARE_8105E_1,
-                                                       JUMBO_1K, true),
+               _R("RTL8105e",          RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K),
        [RTL_GIGA_MAC_VER_31] =
-               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K, false),
+               _R("RTL8168dp/8111dp",  RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_32] =
-               _R("RTL8168e/8111e",    RTL_TD_1, FIRMWARE_8168E_1,
-                                                       JUMBO_9K, false),
+               _R("RTL8168e/8111e",    RTL_TD_1, FIRMWARE_8168E_1, JUMBO_9K),
        [RTL_GIGA_MAC_VER_33] =
-               _R("RTL8168e/8111e",    RTL_TD_1, FIRMWARE_8168E_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8168e/8111e",    RTL_TD_1, FIRMWARE_8168E_2, JUMBO_9K),
        [RTL_GIGA_MAC_VER_34] =
-               _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3,
-                                                       JUMBO_9K, false),
+               _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, JUMBO_9K),
        [RTL_GIGA_MAC_VER_35] =
-               _R("RTL8168f/8111f",    RTL_TD_1, FIRMWARE_8168F_1,
-                                                       JUMBO_9K, false),
+               _R("RTL8168f/8111f",    RTL_TD_1, FIRMWARE_8168F_1, JUMBO_9K),
        [RTL_GIGA_MAC_VER_36] =
-               _R("RTL8168f/8111f",    RTL_TD_1, FIRMWARE_8168F_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8168f/8111f",    RTL_TD_1, FIRMWARE_8168F_2, JUMBO_9K),
        [RTL_GIGA_MAC_VER_37] =
-               _R("RTL8402",           RTL_TD_1, FIRMWARE_8402_1,
-                                                       JUMBO_1K, true),
+               _R("RTL8402",           RTL_TD_1, FIRMWARE_8402_1,  JUMBO_1K),
        [RTL_GIGA_MAC_VER_38] =
-               _R("RTL8411",           RTL_TD_1, FIRMWARE_8411_1,
-                                                       JUMBO_9K, false),
+               _R("RTL8411",           RTL_TD_1, FIRMWARE_8411_1,  JUMBO_9K),
        [RTL_GIGA_MAC_VER_39] =
-               _R("RTL8106e",          RTL_TD_1, FIRMWARE_8106E_1,
-                                                       JUMBO_1K, true),
+               _R("RTL8106e",          RTL_TD_1, FIRMWARE_8106E_1, JUMBO_1K),
        [RTL_GIGA_MAC_VER_40] =
-               _R("RTL8168g/8111g",    RTL_TD_1, FIRMWARE_8168G_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8168g/8111g",    RTL_TD_1, FIRMWARE_8168G_2, JUMBO_9K),
        [RTL_GIGA_MAC_VER_41] =
-               _R("RTL8168g/8111g",    RTL_TD_1, NULL, JUMBO_9K, false),
+               _R("RTL8168g/8111g",    RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_42] =
-               _R("RTL8168g/8111g",    RTL_TD_1, FIRMWARE_8168G_3,
-                                                       JUMBO_9K, false),
+               _R("RTL8168g/8111g",    RTL_TD_1, FIRMWARE_8168G_3, JUMBO_9K),
        [RTL_GIGA_MAC_VER_43] =
-               _R("RTL8106e",          RTL_TD_1, FIRMWARE_8106E_2,
-                                                       JUMBO_1K, true),
+               _R("RTL8106e",          RTL_TD_1, FIRMWARE_8106E_2, JUMBO_1K),
        [RTL_GIGA_MAC_VER_44] =
-               _R("RTL8411",           RTL_TD_1, FIRMWARE_8411_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8411",           RTL_TD_1, FIRMWARE_8411_2,  JUMBO_9K),
        [RTL_GIGA_MAC_VER_45] =
-               _R("RTL8168h/8111h",    RTL_TD_1, FIRMWARE_8168H_1,
-                                                       JUMBO_9K, false),
+               _R("RTL8168h/8111h",    RTL_TD_1, FIRMWARE_8168H_1, JUMBO_9K),
        [RTL_GIGA_MAC_VER_46] =
-               _R("RTL8168h/8111h",    RTL_TD_1, FIRMWARE_8168H_2,
-                                                       JUMBO_9K, false),
+               _R("RTL8168h/8111h",    RTL_TD_1, FIRMWARE_8168H_2, JUMBO_9K),
        [RTL_GIGA_MAC_VER_47] =
-               _R("RTL8107e",          RTL_TD_1, FIRMWARE_8107E_1,
-                                                       JUMBO_1K, false),
+               _R("RTL8107e",          RTL_TD_1, FIRMWARE_8107E_1, JUMBO_1K),
        [RTL_GIGA_MAC_VER_48] =
-               _R("RTL8107e",          RTL_TD_1, FIRMWARE_8107E_2,
-                                                       JUMBO_1K, false),
+               _R("RTL8107e",          RTL_TD_1, FIRMWARE_8107E_2, JUMBO_1K),
        [RTL_GIGA_MAC_VER_49] =
-               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL,
-                                                       JUMBO_9K, false),
+               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_50] =
-               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL,
-                                                       JUMBO_9K, false),
+               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL, JUMBO_9K),
        [RTL_GIGA_MAC_VER_51] =
-               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL,
-                                                       JUMBO_9K, false),
+               _R("RTL8168ep/8111ep",  RTL_TD_1, NULL, JUMBO_9K),
 };
 #undef _R
 
@@ -345,7 +319,6 @@ static const struct pci_device_id rtl8169_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
 
-static int rx_buf_sz = 16383;
 static int use_dac = -1;
 static struct {
        u32 msg_enable;
@@ -626,6 +599,7 @@ enum rtl_register_content {
        RxChkSum        = (1 << 5),
        PCIDAC          = (1 << 4),
        PCIMulRW        = (1 << 3),
+#define INTT_MASK      GENMASK(1, 0)
        INTT_0          = 0x0000,       // 8168
        INTT_1          = 0x0001,       // 8168
        INTT_2          = 0x0002,       // 8168
@@ -716,6 +690,7 @@ enum rtl_rx_desc_bit {
 };
 
 #define RsvdMask       0x3fffc000
+#define CPCMD_QUIRK_MASK       (Normal_mode | RxVlan | RxChkSum | INTT_MASK)
 
 struct TxDesc {
        __le32 opts1;
@@ -735,12 +710,6 @@ struct ring_info {
        u8              __pad[sizeof(void *) - sizeof(u32)];
 };
 
-enum features {
-       RTL_FEATURE_WOL         = (1 << 0),
-       RTL_FEATURE_MSI         = (1 << 1),
-       RTL_FEATURE_GMII        = (1 << 2),
-};
-
 struct rtl8169_counters {
        __le64  tx_packets;
        __le64  rx_packets;
@@ -784,7 +753,6 @@ struct rtl8169_private {
        struct net_device *dev;
        struct napi_struct napi;
        u32 msg_enable;
-       u16 txd_version;
        u16 mac_version;
        u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
        u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
@@ -827,9 +795,9 @@ struct rtl8169_private {
        int (*get_link_ksettings)(struct net_device *,
                                  struct ethtool_link_ksettings *);
        void (*phy_reset_enable)(struct rtl8169_private *tp);
-       void (*hw_start)(struct net_device *);
+       void (*hw_start)(struct rtl8169_private *tp);
        unsigned int (*phy_reset_pending)(struct rtl8169_private *tp);
-       unsigned int (*link_ok)(void __iomem *);
+       unsigned int (*link_ok)(struct rtl8169_private *tp);
        int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd);
        bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *);
 
@@ -839,14 +807,11 @@ struct rtl8169_private {
                struct work_struct work;
        } wk;
 
-       unsigned features;
-
        struct mii_if_info mii;
        dma_addr_t counters_phys_addr;
        struct rtl8169_counters *counters;
        struct rtl8169_tc_offsets tc_offset;
        u32 saved_wolopts;
-       u32 opts1_mask;
 
        struct rtl_fw {
                const struct firmware *fw;
@@ -893,6 +858,11 @@ MODULE_FIRMWARE(FIRMWARE_8168H_2);
 MODULE_FIRMWARE(FIRMWARE_8107E_1);
 MODULE_FIRMWARE(FIRMWARE_8107E_2);
 
+static inline struct device *tp_to_dev(struct rtl8169_private *tp)
+{
+       return &tp->pci_dev->dev;
+}
+
 static void rtl_lock_work(struct rtl8169_private *tp)
 {
        mutex_lock(&tp->wk.mutex);
@@ -903,9 +873,9 @@ static void rtl_unlock_work(struct rtl8169_private *tp)
        mutex_unlock(&tp->wk.mutex);
 }
 
-static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
+static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force)
 {
-       pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
+       pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
                                           PCI_EXP_DEVCTL_READRQ, force);
 }
 
@@ -984,56 +954,46 @@ static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg)
 
 DECLARE_RTL_COND(rtl_ocp_gphy_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(GPHY_OCP) & OCPAR_FLAG;
+       return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG;
 }
 
 static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        if (rtl_ocp_reg_failure(tp, reg))
                return;
 
-       RTL_W32(GPHY_OCP, OCPAR_FLAG | (reg << 15) | data);
+       RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data);
 
        rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10);
 }
 
 static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        if (rtl_ocp_reg_failure(tp, reg))
                return 0;
 
-       RTL_W32(GPHY_OCP, reg << 15);
+       RTL_W32(tp, GPHY_OCP, reg << 15);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ?
-               (RTL_R32(GPHY_OCP) & 0xffff) : ~0;
+               (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0;
 }
 
 static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        if (rtl_ocp_reg_failure(tp, reg))
                return;
 
-       RTL_W32(OCPDR, OCPAR_FLAG | (reg << 15) | data);
+       RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data);
 }
 
 static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        if (rtl_ocp_reg_failure(tp, reg))
                return 0;
 
-       RTL_W32(OCPDR, reg << 15);
+       RTL_W32(tp, OCPDR, reg << 15);
 
-       return RTL_R32(OCPDR);
+       return RTL_R32(tp, OCPDR);
 }
 
 #define OCP_STD_PHY_BASE       0xa400
@@ -1076,16 +1036,12 @@ static int mac_mcu_read(struct rtl8169_private *tp, int reg)
 
 DECLARE_RTL_COND(rtl_phyar_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(PHYAR) & 0x80000000;
+       return RTL_R32(tp, PHYAR) & 0x80000000;
 }
 
 static void r8169_mdio_write(struct rtl8169_private *tp, int reg, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff));
+       RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff));
 
        rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20);
        /*
@@ -1097,13 +1053,12 @@ static void r8169_mdio_write(struct rtl8169_private *tp, int reg, int value)
 
 static int r8169_mdio_read(struct rtl8169_private *tp, int reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        int value;
 
-       RTL_W32(PHYAR, 0x0 | (reg & 0x1f) << 16);
+       RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16);
 
        value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ?
-               RTL_R32(PHYAR) & 0xffff : ~0;
+               RTL_R32(tp, PHYAR) & 0xffff : ~0;
 
        /*
         * According to hardware specs a 20us delay is required after read
@@ -1116,18 +1071,14 @@ static int r8169_mdio_read(struct rtl8169_private *tp, int reg)
 
 DECLARE_RTL_COND(rtl_ocpar_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(OCPAR) & OCPAR_FLAG;
+       return RTL_R32(tp, OCPAR) & OCPAR_FLAG;
 }
 
 static void r8168dp_1_mdio_access(struct rtl8169_private *tp, int reg, u32 data)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT));
-       RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD);
-       RTL_W32(EPHY_RXER_NUM, 0);
+       RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT));
+       RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD);
+       RTL_W32(tp, EPHY_RXER_NUM, 0);
 
        rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100);
 }
@@ -1140,51 +1091,46 @@ static void r8168dp_1_mdio_write(struct rtl8169_private *tp, int reg, int value)
 
 static int r8168dp_1_mdio_read(struct rtl8169_private *tp, int reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD);
 
        mdelay(1);
-       RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD);
-       RTL_W32(EPHY_RXER_NUM, 0);
+       RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD);
+       RTL_W32(tp, EPHY_RXER_NUM, 0);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ?
-               RTL_R32(OCPDR) & OCPDR_DATA_MASK : ~0;
+               RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0;
 }
 
 #define R8168DP_1_MDIO_ACCESS_BIT      0x00020000
 
-static void r8168dp_2_mdio_start(void __iomem *ioaddr)
+static void r8168dp_2_mdio_start(struct rtl8169_private *tp)
 {
-       RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT);
+       RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT);
 }
 
-static void r8168dp_2_mdio_stop(void __iomem *ioaddr)
+static void r8168dp_2_mdio_stop(struct rtl8169_private *tp)
 {
-       RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT);
+       RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) | R8168DP_1_MDIO_ACCESS_BIT);
 }
 
 static void r8168dp_2_mdio_write(struct rtl8169_private *tp, int reg, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       r8168dp_2_mdio_start(ioaddr);
+       r8168dp_2_mdio_start(tp);
 
        r8169_mdio_write(tp, reg, value);
 
-       r8168dp_2_mdio_stop(ioaddr);
+       r8168dp_2_mdio_stop(tp);
 }
 
 static int r8168dp_2_mdio_read(struct rtl8169_private *tp, int reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        int value;
 
-       r8168dp_2_mdio_start(ioaddr);
+       r8168dp_2_mdio_start(tp);
 
        value = r8169_mdio_read(tp, reg);
 
-       r8168dp_2_mdio_stop(ioaddr);
+       r8168dp_2_mdio_stop(tp);
 
        return value;
 }
@@ -1229,16 +1175,12 @@ static int rtl_mdio_read(struct net_device *dev, int phy_id, int location)
 
 DECLARE_RTL_COND(rtl_ephyar_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(EPHYAR) & EPHYAR_FLAG;
+       return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG;
 }
 
 static void rtl_ephy_write(struct rtl8169_private *tp, int reg_addr, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
+       RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
                (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
 
        rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100);
@@ -1248,41 +1190,33 @@ static void rtl_ephy_write(struct rtl8169_private *tp, int reg_addr, int value)
 
 static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
+       RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ?
-               RTL_R32(EPHYAR) & EPHYAR_DATA_MASK : ~0;
+               RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0;
 }
 
 DECLARE_RTL_COND(rtl_eriar_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(ERIAR) & ERIAR_FLAG;
+       return RTL_R32(tp, ERIAR) & ERIAR_FLAG;
 }
 
 static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask,
                          u32 val, int type)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        BUG_ON((addr & 3) || (mask == 0));
-       RTL_W32(ERIDR, val);
-       RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr);
+       RTL_W32(tp, ERIDR, val);
+       RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr);
 
        rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100);
 }
 
 static u32 rtl_eri_read(struct rtl8169_private *tp, int addr, int type)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr);
+       RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ?
-               RTL_R32(ERIDR) : ~0;
+               RTL_R32(tp, ERIDR) : ~0;
 }
 
 static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p,
@@ -1296,11 +1230,9 @@ static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p,
 
 static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
+       RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
        return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ?
-               RTL_R32(OCPDR) : ~0;
+               RTL_R32(tp, OCPDR) : ~0;
 }
 
 static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
@@ -1328,10 +1260,8 @@ static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
 static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg,
                              u32 data)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(OCPDR, data);
-       RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
+       RTL_W32(tp, OCPDR, data);
+       RTL_W32(tp, OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
        rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20);
 }
 
@@ -1393,19 +1323,15 @@ DECLARE_RTL_COND(rtl_ep_ocp_read_cond)
 
 DECLARE_RTL_COND(rtl_ocp_tx_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R8(IBISR0) & 0x20;
+       return RTL_R8(tp, IBISR0) & 0x20;
 }
 
 static void rtl8168ep_stop_cmac(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(IBCR2, RTL_R8(IBCR2) & ~0x01);
+       RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01);
        rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000);
-       RTL_W8(IBISR0, RTL_R8(IBISR0) | 0x20);
-       RTL_W8(IBCR0, RTL_R8(IBCR0) & ~0x01);
+       RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20);
+       RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01);
 }
 
 static void rtl8168dp_driver_start(struct rtl8169_private *tp)
@@ -1473,19 +1399,19 @@ static void rtl8168_driver_stop(struct rtl8169_private *tp)
        }
 }
 
-static int r8168dp_check_dash(struct rtl8169_private *tp)
+static bool r8168dp_check_dash(struct rtl8169_private *tp)
 {
        u16 reg = rtl8168_get_ocp_reg(tp);
 
-       return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0;
+       return !!(ocp_read(tp, 0x0f, reg) & 0x00008000);
 }
 
-static int r8168ep_check_dash(struct rtl8169_private *tp)
+static bool r8168ep_check_dash(struct rtl8169_private *tp)
 {
-       return (ocp_read(tp, 0x0f, 0x128) & 0x00000001) ? 1 : 0;
+       return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001);
 }
 
-static int r8168_check_dash(struct rtl8169_private *tp)
+static bool r8168_check_dash(struct rtl8169_private *tp)
 {
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_27:
@@ -1497,7 +1423,7 @@ static int r8168_check_dash(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_51:
                return r8168ep_check_dash(tp);
        default:
-               return 0;
+               return false;
        }
 }
 
@@ -1518,49 +1444,37 @@ static void rtl_write_exgmac_batch(struct rtl8169_private *tp,
 
 DECLARE_RTL_COND(rtl_efusear_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(EFUSEAR) & EFUSEAR_FLAG;
+       return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG;
 }
 
 static u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
+       RTL_W32(tp, EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ?
-               RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK : ~0;
+               RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0;
 }
 
 static u16 rtl_get_events(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R16(IntrStatus);
+       return RTL_R16(tp, IntrStatus);
 }
 
 static void rtl_ack_events(struct rtl8169_private *tp, u16 bits)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W16(IntrStatus, bits);
+       RTL_W16(tp, IntrStatus, bits);
        mmiowb();
 }
 
 static void rtl_irq_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W16(IntrMask, 0);
+       RTL_W16(tp, IntrMask, 0);
        mmiowb();
 }
 
 static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W16(IntrMask, bits);
+       RTL_W16(tp, IntrMask, bits);
 }
 
 #define RTL_EVENT_NAPI_RX      (RxOK | RxErr)
@@ -1574,18 +1488,14 @@ static void rtl_irq_enable_all(struct rtl8169_private *tp)
 
 static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        rtl_irq_disable(tp);
        rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow);
-       RTL_R8(ChipCmd);
+       RTL_R8(tp, ChipCmd);
 }
 
 static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(TBICSR) & TBIReset;
+       return RTL_R32(tp, TBICSR) & TBIReset;
 }
 
 static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp)
@@ -1593,21 +1503,19 @@ static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp)
        return rtl_readphy(tp, MII_BMCR) & BMCR_RESET;
 }
 
-static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr)
+static unsigned int rtl8169_tbi_link_ok(struct rtl8169_private *tp)
 {
-       return RTL_R32(TBICSR) & TBILinkOk;
+       return RTL_R32(tp, TBICSR) & TBILinkOk;
 }
 
-static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr)
+static unsigned int rtl8169_xmii_link_ok(struct rtl8169_private *tp)
 {
-       return RTL_R8(PHYstatus) & LinkStatus;
+       return RTL_R8(tp, PHYstatus) & LinkStatus;
 }
 
 static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset);
+       RTL_W32(tp, TBICSR, RTL_R32(tp, TBICSR) | TBIReset);
 }
 
 static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp)
@@ -1620,7 +1528,6 @@ static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp)
 
 static void rtl_link_chg_patch(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        struct net_device *dev = tp->dev;
 
        if (!netif_running(dev))
@@ -1628,12 +1535,12 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
 
        if (tp->mac_version == RTL_GIGA_MAC_VER_34 ||
            tp->mac_version == RTL_GIGA_MAC_VER_38) {
-               if (RTL_R8(PHYstatus) & _1000bpsF) {
+               if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
                        rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011,
                                      ERIAR_EXGMAC);
                        rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
                                      ERIAR_EXGMAC);
-               } else if (RTL_R8(PHYstatus) & _100bps) {
+               } else if (RTL_R8(tp, PHYstatus) & _100bps) {
                        rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f,
                                      ERIAR_EXGMAC);
                        rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
@@ -1651,7 +1558,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
                             ERIAR_EXGMAC);
        } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 ||
                   tp->mac_version == RTL_GIGA_MAC_VER_36) {
-               if (RTL_R8(PHYstatus) & _1000bpsF) {
+               if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
                        rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011,
                                      ERIAR_EXGMAC);
                        rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
@@ -1663,7 +1570,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
                                      ERIAR_EXGMAC);
                }
        } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) {
-               if (RTL_R8(PHYstatus) & _10bps) {
+               if (RTL_R8(tp, PHYstatus) & _10bps) {
                        rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02,
                                      ERIAR_EXGMAC);
                        rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060,
@@ -1676,20 +1583,21 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
 }
 
 static void rtl8169_check_link_status(struct net_device *dev,
-                                     struct rtl8169_private *tp,
-                                     void __iomem *ioaddr)
+                                     struct rtl8169_private *tp)
 {
-       if (tp->link_ok(ioaddr)) {
+       struct device *d = tp_to_dev(tp);
+
+       if (tp->link_ok(tp)) {
                rtl_link_chg_patch(tp);
                /* This is to cancel a scheduled suspend if there's one. */
-               pm_request_resume(&tp->pci_dev->dev);
+               pm_request_resume(d);
                netif_carrier_on(dev);
                if (net_ratelimit())
                        netif_info(tp, ifup, dev, "link up\n");
        } else {
                netif_carrier_off(dev);
                netif_info(tp, ifdown, dev, "link down\n");
-               pm_runtime_idle(&tp->pci_dev->dev);
+               pm_runtime_idle(d);
        }
 }
 
@@ -1697,15 +1605,14 @@ static void rtl8169_check_link_status(struct net_device *dev,
 
 static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        u8 options;
        u32 wolopts = 0;
 
-       options = RTL_R8(Config1);
+       options = RTL_R8(tp, Config1);
        if (!(options & PMEnable))
                return 0;
 
-       options = RTL_R8(Config3);
+       options = RTL_R8(tp, Config3);
        if (options & LinkUp)
                wolopts |= WAKE_PHY;
        switch (tp->mac_version) {
@@ -1735,7 +1642,7 @@ static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
                break;
        }
 
-       options = RTL_R8(Config5);
+       options = RTL_R8(tp, Config5);
        if (options & UWF)
                wolopts |= WAKE_UCAST;
        if (options & BWF)
@@ -1749,7 +1656,7 @@ static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
 
        pm_runtime_get_noresume(d);
 
@@ -1768,7 +1675,6 @@ static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 
 static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        unsigned int i, tmp;
        static const struct {
                u32 opt;
@@ -1784,7 +1690,7 @@ static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
        };
        u8 options;
 
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_34:
@@ -1826,43 +1732,39 @@ static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
        }
 
        for (i = 0; i < tmp; i++) {
-               options = RTL_R8(cfg[i].reg) & ~cfg[i].mask;
+               options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask;
                if (wolopts & cfg[i].opt)
                        options |= cfg[i].mask;
-               RTL_W8(cfg[i].reg, options);
+               RTL_W8(tp, cfg[i].reg, options);
        }
 
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17:
-               options = RTL_R8(Config1) & ~PMEnable;
+               options = RTL_R8(tp, Config1) & ~PMEnable;
                if (wolopts)
                        options |= PMEnable;
-               RTL_W8(Config1, options);
+               RTL_W8(tp, Config1, options);
                break;
        default:
-               options = RTL_R8(Config2) & ~PME_SIGNAL;
+               options = RTL_R8(tp, Config2) & ~PME_SIGNAL;
                if (wolopts)
                        options |= PME_SIGNAL;
-               RTL_W8(Config2, options);
+               RTL_W8(tp, Config2, options);
                break;
        }
 
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 }
 
 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
 
        pm_runtime_get_noresume(d);
 
        rtl_lock_work(tp);
 
-       if (wol->wolopts)
-               tp->features |= RTL_FEATURE_WOL;
-       else
-               tp->features &= ~RTL_FEATURE_WOL;
        if (pm_runtime_active(d))
                __rtl8169_set_wol(tp, wol->wolopts);
        else
@@ -1870,7 +1772,7 @@ static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 
        rtl_unlock_work(tp);
 
-       device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
+       device_set_wakeup_enable(d, wol->wolopts);
 
        pm_runtime_put_noidle(d);
 
@@ -1906,16 +1808,15 @@ static int rtl8169_set_speed_tbi(struct net_device *dev,
                                 u8 autoneg, u16 speed, u8 duplex, u32 ignored)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        int ret = 0;
        u32 reg;
 
-       reg = RTL_R32(TBICSR);
+       reg = RTL_R32(tp, TBICSR);
        if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) &&
            (duplex == DUPLEX_FULL)) {
-               RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart));
+               RTL_W32(tp, TBICSR, reg & ~(TBINwEnable | TBINwRestart));
        } else if (autoneg == AUTONEG_ENABLE)
-               RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart);
+               RTL_W32(tp, TBICSR, reg | TBINwEnable | TBINwRestart);
        else {
                netif_warn(tp, link, dev,
                           "incorrect speed setting refused in TBI mode\n");
@@ -2030,26 +1931,27 @@ static netdev_features_t rtl8169_fix_features(struct net_device *dev,
                features &= ~NETIF_F_ALL_TSO;
 
        if (dev->mtu > JUMBO_1K &&
-           !rtl_chip_infos[tp->mac_version].jumbo_tx_csum)
+           tp->mac_version > RTL_GIGA_MAC_VER_06)
                features &= ~NETIF_F_IP_CSUM;
 
        return features;
 }
 
-static void __rtl8169_set_features(struct net_device *dev,
-                                  netdev_features_t features)
+static int rtl8169_set_features(struct net_device *dev,
+                               netdev_features_t features)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        u32 rx_config;
 
-       rx_config = RTL_R32(RxConfig);
+       rtl_lock_work(tp);
+
+       rx_config = RTL_R32(tp, RxConfig);
        if (features & NETIF_F_RXALL)
                rx_config |= (AcceptErr | AcceptRunt);
        else
                rx_config &= ~(AcceptErr | AcceptRunt);
 
-       RTL_W32(RxConfig, rx_config);
+       RTL_W32(tp, RxConfig, rx_config);
 
        if (features & NETIF_F_RXCSUM)
                tp->cp_cmd |= RxChkSum;
@@ -2061,28 +1963,14 @@ static void __rtl8169_set_features(struct net_device *dev,
        else
                tp->cp_cmd &= ~RxVlan;
 
-       tp->cp_cmd |= RTL_R16(CPlusCmd) & ~(RxVlan | RxChkSum);
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
+       RTL_R16(tp, CPlusCmd);
 
-       RTL_W16(CPlusCmd, tp->cp_cmd);
-       RTL_R16(CPlusCmd);
-}
-
-static int rtl8169_set_features(struct net_device *dev,
-                               netdev_features_t features)
-{
-       struct rtl8169_private *tp = netdev_priv(dev);
-
-       features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX;
-
-       rtl_lock_work(tp);
-       if (features ^ dev->features)
-               __rtl8169_set_features(dev, features);
        rtl_unlock_work(tp);
 
        return 0;
 }
 
-
 static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb)
 {
        return (skb_vlan_tag_present(skb)) ?
@@ -2101,7 +1989,6 @@ static int rtl8169_get_link_ksettings_tbi(struct net_device *dev,
                                          struct ethtool_link_ksettings *cmd)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        u32 status;
        u32 supported, advertising;
 
@@ -2109,7 +1996,7 @@ static int rtl8169_get_link_ksettings_tbi(struct net_device *dev,
                SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE;
        cmd->base.port = PORT_FIBRE;
 
-       status = RTL_R32(TBICSR);
+       status = RTL_R32(tp, TBICSR);
        advertising = (status & TBINwEnable) ?  ADVERTISED_Autoneg : 0;
        cmd->base.autoneg = !!(status & TBINwEnable);
 
@@ -2224,31 +2111,25 @@ static int rtl8169_get_sset_count(struct net_device *dev, int sset)
 
 DECLARE_RTL_COND(rtl_counters_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(CounterAddrLow) & (CounterReset | CounterDump);
+       return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump);
 }
 
-static bool rtl8169_do_counters(struct net_device *dev, u32 counter_cmd)
+static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        dma_addr_t paddr = tp->counters_phys_addr;
        u32 cmd;
 
-       RTL_W32(CounterAddrHigh, (u64)paddr >> 32);
-       RTL_R32(CounterAddrHigh);
+       RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
+       RTL_R32(tp, CounterAddrHigh);
        cmd = (u64)paddr & DMA_BIT_MASK(32);
-       RTL_W32(CounterAddrLow, cmd);
-       RTL_W32(CounterAddrLow, cmd | counter_cmd);
+       RTL_W32(tp, CounterAddrLow, cmd);
+       RTL_W32(tp, CounterAddrLow, cmd | counter_cmd);
 
        return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000);
 }
 
-static bool rtl8169_reset_counters(struct net_device *dev)
+static bool rtl8169_reset_counters(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-
        /*
         * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the
         * tally counters.
@@ -2256,27 +2137,23 @@ static bool rtl8169_reset_counters(struct net_device *dev)
        if (tp->mac_version < RTL_GIGA_MAC_VER_19)
                return true;
 
-       return rtl8169_do_counters(dev, CounterReset);
+       return rtl8169_do_counters(tp, CounterReset);
 }
 
-static bool rtl8169_update_counters(struct net_device *dev)
+static bool rtl8169_update_counters(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
-
        /*
         * Some chips are unable to dump tally counters when the receiver
         * is disabled.
         */
-       if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
+       if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0)
                return true;
 
-       return rtl8169_do_counters(dev, CounterDump);
+       return rtl8169_do_counters(tp, CounterDump);
 }
 
-static bool rtl8169_init_counter_offsets(struct net_device *dev)
+static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
        struct rtl8169_counters *counters = tp->counters;
        bool ret = false;
 
@@ -2299,10 +2176,10 @@ static bool rtl8169_init_counter_offsets(struct net_device *dev)
                return true;
 
        /* If both, reset and update fail, propagate to caller. */
-       if (rtl8169_reset_counters(dev))
+       if (rtl8169_reset_counters(tp))
                ret = true;
 
-       if (rtl8169_update_counters(dev))
+       if (rtl8169_update_counters(tp))
                ret = true;
 
        tp->tc_offset.tx_errors = counters->tx_errors;
@@ -2317,7 +2194,7 @@ static void rtl8169_get_ethtool_stats(struct net_device *dev,
                                      struct ethtool_stats *stats, u64 *data)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
        struct rtl8169_counters *counters = tp->counters;
 
        ASSERT_RTNL();
@@ -2325,7 +2202,7 @@ static void rtl8169_get_ethtool_stats(struct net_device *dev,
        pm_runtime_get_noresume(d);
 
        if (pm_runtime_active(d))
-               rtl8169_update_counters(dev);
+               rtl8169_update_counters(tp);
 
        pm_runtime_put_noidle(d);
 
@@ -2448,7 +2325,6 @@ static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev)
 static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        const struct rtl_coalesce_info *ci;
        const struct rtl_coalesce_scale *scale;
        struct {
@@ -2468,10 +2344,10 @@ static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
        if (IS_ERR(ci))
                return PTR_ERR(ci);
 
-       scale = &ci->scalev[RTL_R16(CPlusCmd) & 3];
+       scale = &ci->scalev[tp->cp_cmd & INTT_MASK];
 
        /* read IntrMitigate and adjust according to scale */
-       for (w = RTL_R16(IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) {
+       for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) {
                *p->max_frames = (w & RTL_COALESCE_MASK) << 2;
                w >>= RTL_COALESCE_SHIFT;
                *p->usecs = w & RTL_COALESCE_MASK;
@@ -2518,7 +2394,6 @@ static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale(
 static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        const struct rtl_coalesce_scale *scale;
        struct {
                u32 frames;
@@ -2566,11 +2441,11 @@ static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
 
        rtl_lock_work(tp);
 
-       RTL_W16(IntrMitigate, swab16(w));
+       RTL_W16(tp, IntrMitigate, swab16(w));
 
-       tp->cp_cmd = (tp->cp_cmd & ~3) | cp01;
-       RTL_W16(CPlusCmd, tp->cp_cmd);
-       RTL_R16(CPlusCmd);
+       tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
+       RTL_R16(tp, CPlusCmd);
 
        rtl_unlock_work(tp);
 
@@ -2598,19 +2473,18 @@ static const struct ethtool_ops rtl8169_ethtool_ops = {
 };
 
 static void rtl8169_get_mac_version(struct rtl8169_private *tp,
-                                   struct net_device *dev, u8 default_version)
+                                   u8 default_version)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        /*
         * The driver currently handles the 8168Bf and the 8168Be identically
         * but they can be identified more specifically through the test below
         * if needed:
         *
-        * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
+        * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
         *
         * Same thing for the 8101Eb and the 8101Ec:
         *
-        * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
+        * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
         */
        static const struct rtl_mac_info {
                u32 mask;
@@ -2639,12 +2513,10 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
 
                /* 8168E family. */
                { 0x7c800000, 0x2c800000,       RTL_GIGA_MAC_VER_34 },
-               { 0x7cf00000, 0x2c200000,       RTL_GIGA_MAC_VER_33 },
                { 0x7cf00000, 0x2c100000,       RTL_GIGA_MAC_VER_32 },
                { 0x7c800000, 0x2c000000,       RTL_GIGA_MAC_VER_33 },
 
                /* 8168D family. */
-               { 0x7cf00000, 0x28300000,       RTL_GIGA_MAC_VER_26 },
                { 0x7cf00000, 0x28100000,       RTL_GIGA_MAC_VER_25 },
                { 0x7c800000, 0x28000000,       RTL_GIGA_MAC_VER_26 },
 
@@ -2654,32 +2526,24 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
                { 0x7cf00000, 0x28b00000,       RTL_GIGA_MAC_VER_31 },
 
                /* 8168C family. */
-               { 0x7cf00000, 0x3cb00000,       RTL_GIGA_MAC_VER_24 },
                { 0x7cf00000, 0x3c900000,       RTL_GIGA_MAC_VER_23 },
                { 0x7cf00000, 0x3c800000,       RTL_GIGA_MAC_VER_18 },
                { 0x7c800000, 0x3c800000,       RTL_GIGA_MAC_VER_24 },
                { 0x7cf00000, 0x3c000000,       RTL_GIGA_MAC_VER_19 },
                { 0x7cf00000, 0x3c200000,       RTL_GIGA_MAC_VER_20 },
                { 0x7cf00000, 0x3c300000,       RTL_GIGA_MAC_VER_21 },
-               { 0x7cf00000, 0x3c400000,       RTL_GIGA_MAC_VER_22 },
                { 0x7c800000, 0x3c000000,       RTL_GIGA_MAC_VER_22 },
 
                /* 8168B family. */
                { 0x7cf00000, 0x38000000,       RTL_GIGA_MAC_VER_12 },
-               { 0x7cf00000, 0x38500000,       RTL_GIGA_MAC_VER_17 },
                { 0x7c800000, 0x38000000,       RTL_GIGA_MAC_VER_17 },
                { 0x7c800000, 0x30000000,       RTL_GIGA_MAC_VER_11 },
 
                /* 8101 family. */
-               { 0x7cf00000, 0x44900000,       RTL_GIGA_MAC_VER_39 },
                { 0x7c800000, 0x44800000,       RTL_GIGA_MAC_VER_39 },
                { 0x7c800000, 0x44000000,       RTL_GIGA_MAC_VER_37 },
-               { 0x7cf00000, 0x40b00000,       RTL_GIGA_MAC_VER_30 },
-               { 0x7cf00000, 0x40a00000,       RTL_GIGA_MAC_VER_30 },
                { 0x7cf00000, 0x40900000,       RTL_GIGA_MAC_VER_29 },
                { 0x7c800000, 0x40800000,       RTL_GIGA_MAC_VER_30 },
-               { 0x7cf00000, 0x34a00000,       RTL_GIGA_MAC_VER_09 },
-               { 0x7cf00000, 0x24a00000,       RTL_GIGA_MAC_VER_09 },
                { 0x7cf00000, 0x34900000,       RTL_GIGA_MAC_VER_08 },
                { 0x7cf00000, 0x24900000,       RTL_GIGA_MAC_VER_08 },
                { 0x7cf00000, 0x34800000,       RTL_GIGA_MAC_VER_07 },
@@ -2708,14 +2572,14 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
        const struct rtl_mac_info *p = mac_info;
        u32 reg;
 
-       reg = RTL_R32(TxConfig);
+       reg = RTL_R32(tp, TxConfig);
        while ((reg & p->mask) != p->val)
                p++;
        tp->mac_version = p->mac_version;
 
        if (tp->mac_version == RTL_GIGA_MAC_NONE) {
-               netif_notice(tp, probe, dev,
-                            "unknown MAC, using family default\n");
+               dev_notice(tp_to_dev(tp),
+                          "unknown MAC, using family default\n");
                tp->mac_version = default_version;
        } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) {
                tp->mac_version = tp->mii.supports_gmii ?
@@ -3805,8 +3669,6 @@ static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp)
        rtl_writephy(tp, 0x1f, 0x0005);
        rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000);
        rtl_writephy(tp, 0x1f, 0x0000);
-       /* soft-reset phy */
-       rtl_writephy(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART);
 
        /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */
        rtl_rar_exgmac_set(tp, tp->dev->dev_addr);
@@ -4591,7 +4453,6 @@ static void rtl_hw_phy_config(struct net_device *dev)
 static void rtl_phy_work(struct rtl8169_private *tp)
 {
        struct timer_list *timer = &tp->timer;
-       void __iomem *ioaddr = tp->mmio_addr;
        unsigned long timeout = RTL8169_PHY_TIMEOUT;
 
        assert(tp->mac_version > RTL_GIGA_MAC_VER_01);
@@ -4605,7 +4466,7 @@ static void rtl_phy_work(struct rtl8169_private *tp)
                goto out_mod_timer;
        }
 
-       if (tp->link_ok(ioaddr))
+       if (tp->link_ok(tp))
                return;
 
        netif_dbg(tp, link, tp->dev, "PHY reset until link up\n");
@@ -4643,21 +4504,17 @@ static void rtl8169_phy_reset(struct net_device *dev,
 
 static bool rtl_tbi_enabled(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        return (tp->mac_version == RTL_GIGA_MAC_VER_01) &&
-           (RTL_R8(PHYstatus) & TBI_Enable);
+           (RTL_R8(tp, PHYstatus) & TBI_Enable);
 }
 
 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        rtl_hw_phy_config(dev);
 
        if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
                dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
-               RTL_W8(0x82, 0x01);
+               RTL_W8(tp, 0x82, 0x01);
        }
 
        pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
@@ -4667,7 +4524,7 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
 
        if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
                dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
-               RTL_W8(0x82, 0x01);
+               RTL_W8(tp, 0x82, 0x01);
                dprintk("Set PHY Reg 0x0bh = 0x00h\n");
                rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0
        }
@@ -4687,22 +4544,20 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
 
 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        rtl_lock_work(tp);
 
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 
-       RTL_W32(MAC4, addr[4] | addr[5] << 8);
-       RTL_R32(MAC4);
+       RTL_W32(tp, MAC4, addr[4] | addr[5] << 8);
+       RTL_R32(tp, MAC4);
 
-       RTL_W32(MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24);
-       RTL_R32(MAC0);
+       RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24);
+       RTL_R32(tp, MAC0);
 
        if (tp->mac_version == RTL_GIGA_MAC_VER_34)
                rtl_rar_exgmac_set(tp, addr);
 
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 
        rtl_unlock_work(tp);
 }
@@ -4710,13 +4565,12 @@ static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
 static int rtl_set_mac_address(struct net_device *dev, void *p)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       struct device *d = &tp->pci_dev->dev;
-       struct sockaddr *addr = p;
-
-       if (!is_valid_ether_addr(addr->sa_data))
-               return -EADDRNOTAVAIL;
+       struct device *d = tp_to_dev(tp);
+       int ret;
 
-       memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+       ret = eth_mac_addr(dev, p);
+       if (ret)
+               return ret;
 
        pm_runtime_get_noresume(d);
 
@@ -4822,8 +4676,6 @@ static void rtl_speed_down(struct rtl8169_private *tp)
 
 static void rtl_wol_suspend_quirk(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_25:
        case RTL_GIGA_MAC_VER_26:
@@ -4847,7 +4699,7 @@ static void rtl_wol_suspend_quirk(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_49:
        case RTL_GIGA_MAC_VER_50:
        case RTL_GIGA_MAC_VER_51:
-               RTL_W32(RxConfig, RTL_R32(RxConfig) |
+               RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) |
                        AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
                break;
        default:
@@ -4880,8 +4732,6 @@ static void r810x_phy_power_up(struct rtl8169_private *tp)
 
 static void r810x_pll_power_down(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        if (rtl_wol_pll_power_down(tp))
                return;
 
@@ -4896,15 +4746,13 @@ static void r810x_pll_power_down(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_16:
                break;
        default:
-               RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80);
                break;
        }
 }
 
 static void r810x_pll_power_up(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        r810x_phy_power_up(tp);
 
        switch (tp->mac_version) {
@@ -4917,10 +4765,10 @@ static void r810x_pll_power_up(struct rtl8169_private *tp)
                break;
        case RTL_GIGA_MAC_VER_47:
        case RTL_GIGA_MAC_VER_48:
-               RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0);
                break;
        default:
-               RTL_W8(PMCH, RTL_R8(PMCH) | 0x80);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80);
                break;
        }
 }
@@ -4987,21 +4835,12 @@ static void r8168_phy_power_down(struct rtl8169_private *tp)
 
 static void r8168_pll_power_down(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       if ((tp->mac_version == RTL_GIGA_MAC_VER_27 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_28 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_31 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_49 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_50 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_51) &&
-           r8168_check_dash(tp)) {
+       if (r8168_check_dash(tp))
                return;
-       }
 
        if ((tp->mac_version == RTL_GIGA_MAC_VER_23 ||
             tp->mac_version == RTL_GIGA_MAC_VER_24) &&
-           (RTL_R16(CPlusCmd) & ASF)) {
+           (tp->cp_cmd & ASF)) {
                return;
        }
 
@@ -5027,22 +4866,20 @@ static void r8168_pll_power_down(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_46:
        case RTL_GIGA_MAC_VER_50:
        case RTL_GIGA_MAC_VER_51:
-               RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80);
                break;
        case RTL_GIGA_MAC_VER_40:
        case RTL_GIGA_MAC_VER_41:
        case RTL_GIGA_MAC_VER_49:
                rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000,
                             0xfc000000, ERIAR_EXGMAC);
-               RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80);
                break;
        }
 }
 
 static void r8168_pll_power_up(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_25:
        case RTL_GIGA_MAC_VER_26:
@@ -5051,19 +4888,19 @@ static void r8168_pll_power_up(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_31:
        case RTL_GIGA_MAC_VER_32:
        case RTL_GIGA_MAC_VER_33:
-               RTL_W8(PMCH, RTL_R8(PMCH) | 0x80);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80);
                break;
        case RTL_GIGA_MAC_VER_44:
        case RTL_GIGA_MAC_VER_45:
        case RTL_GIGA_MAC_VER_46:
        case RTL_GIGA_MAC_VER_50:
        case RTL_GIGA_MAC_VER_51:
-               RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0);
                break;
        case RTL_GIGA_MAC_VER_40:
        case RTL_GIGA_MAC_VER_41:
        case RTL_GIGA_MAC_VER_49:
-               RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0);
+               RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0);
                rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000,
                             0x00000000, ERIAR_EXGMAC);
                break;
@@ -5153,8 +4990,6 @@ static void rtl_init_pll_power_ops(struct rtl8169_private *tp)
 
 static void rtl_init_rxcfg(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_01:
        case RTL_GIGA_MAC_VER_02:
@@ -5170,7 +5005,7 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_15:
        case RTL_GIGA_MAC_VER_16:
        case RTL_GIGA_MAC_VER_17:
-               RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST);
+               RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST);
                break;
        case RTL_GIGA_MAC_VER_18:
        case RTL_GIGA_MAC_VER_19:
@@ -5181,7 +5016,7 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_24:
        case RTL_GIGA_MAC_VER_34:
        case RTL_GIGA_MAC_VER_35:
-               RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST);
+               RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST);
                break;
        case RTL_GIGA_MAC_VER_40:
        case RTL_GIGA_MAC_VER_41:
@@ -5195,10 +5030,10 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_49:
        case RTL_GIGA_MAC_VER_50:
        case RTL_GIGA_MAC_VER_51:
-               RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF);
+               RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF);
                break;
        default:
-               RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST);
+               RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST);
                break;
        }
 }
@@ -5210,102 +5045,82 @@ static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
 
 static void rtl_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
        rtl_generic_op(tp, tp->jumbo_ops.enable);
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 }
 
 static void rtl_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
        rtl_generic_op(tp, tp->jumbo_ops.disable);
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 }
 
 static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0);
-       RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1);
-       rtl_tx_performance_tweak(tp->pci_dev, PCI_EXP_DEVCTL_READRQ_512B);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B);
 }
 
 static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0);
-       RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1);
-       rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 }
 
 static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
 }
 
 static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
 }
 
 static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(MaxTxPacketSize, 0x3f);
-       RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0);
-       RTL_W8(Config4, RTL_R8(Config4) | 0x01);
-       rtl_tx_performance_tweak(tp->pci_dev, PCI_EXP_DEVCTL_READRQ_512B);
+       RTL_W8(tp, MaxTxPacketSize, 0x3f);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B);
 }
 
 static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(MaxTxPacketSize, 0x0c);
-       RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0);
-       RTL_W8(Config4, RTL_R8(Config4) & ~0x01);
-       rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       RTL_W8(tp, MaxTxPacketSize, 0x0c);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 }
 
 static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       rtl_tx_performance_tweak(tp->pci_dev,
+       rtl_tx_performance_tweak(tp,
                PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN);
 }
 
 static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       rtl_tx_performance_tweak(tp->pci_dev,
-               (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN);
+       rtl_tx_performance_tweak(tp,
+               PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN);
 }
 
 static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        r8168b_0_hw_jumbo_enable(tp);
 
-       RTL_W8(Config4, RTL_R8(Config4) | (1 << 0));
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0));
 }
 
 static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        r8168b_0_hw_jumbo_disable(tp);
 
-       RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0));
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
 }
 
 static void rtl_init_jumbo_ops(struct rtl8169_private *tp)
@@ -5372,16 +5187,12 @@ static void rtl_init_jumbo_ops(struct rtl8169_private *tp)
 
 DECLARE_RTL_COND(rtl_chipcmd_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R8(ChipCmd) & CmdReset;
+       return RTL_R8(tp, ChipCmd) & CmdReset;
 }
 
 static void rtl_hw_reset(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(ChipCmd, CmdReset);
+       RTL_W8(tp, ChipCmd, CmdReset);
 
        rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100);
 }
@@ -5400,7 +5211,7 @@ static void rtl_request_uncached_firmware(struct rtl8169_private *tp)
        if (!rtl_fw)
                goto err_warn;
 
-       rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev);
+       rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp));
        if (rc < 0)
                goto err_free;
 
@@ -5432,29 +5243,21 @@ static void rtl_request_firmware(struct rtl8169_private *tp)
 
 static void rtl_rx_close(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK);
+       RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK);
 }
 
 DECLARE_RTL_COND(rtl_npq_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R8(TxPoll) & NPQ;
+       return RTL_R8(tp, TxPoll) & NPQ;
 }
 
 DECLARE_RTL_COND(rtl_txcfg_empty_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(TxConfig) & TXCFG_EMPTY;
+       return RTL_R32(tp, TxConfig) & TXCFG_EMPTY;
 }
 
 static void rtl8169_hw_reset(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        /* Disable interrupts */
        rtl8169_irq_mask_and_ack(tp);
 
@@ -5481,10 +5284,10 @@ static void rtl8169_hw_reset(struct rtl8169_private *tp)
                   tp->mac_version == RTL_GIGA_MAC_VER_49 ||
                   tp->mac_version == RTL_GIGA_MAC_VER_50 ||
                   tp->mac_version == RTL_GIGA_MAC_VER_51) {
-               RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq);
+               RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
                rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666);
        } else {
-               RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq);
+               RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
                udelay(100);
        }
 
@@ -5493,52 +5296,37 @@ static void rtl8169_hw_reset(struct rtl8169_private *tp)
 
 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        /* Set DMA burst size and Interframe Gap Time */
-       RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
+       RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) |
                (InterFrameGap << TxInterFrameGapShift));
 }
 
-static void rtl_hw_start(struct net_device *dev)
+static void rtl_hw_start(struct  rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-
-       tp->hw_start(dev);
-
+       tp->hw_start(tp);
        rtl_irq_enable_all(tp);
 }
 
-static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
-                                        void __iomem *ioaddr)
+static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp)
 {
        /*
         * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
         * register to be written before TxDescAddrLow to work.
         * Switching from MMIO to I/O access fixes the issue as well.
         */
-       RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
-       RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32));
-       RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
-       RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
+       RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
+       RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32));
+       RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
+       RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
 }
 
-static u16 rtl_rw_cpluscmd(void __iomem *ioaddr)
-{
-       u16 cmd;
-
-       cmd = RTL_R16(CPlusCmd);
-       RTL_W16(CPlusCmd, cmd);
-       return cmd;
-}
-
-static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz)
+static void rtl_set_rx_max_size(struct rtl8169_private *tp)
 {
        /* Low hurts. Let's disable the filtering. */
-       RTL_W16(RxMaxSize, rx_buf_sz + 1);
+       RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1);
 }
 
-static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
+static void rtl8169_set_magic_reg(struct rtl8169_private *tp, unsigned mac_version)
 {
        static const struct rtl_cfg2_info {
                u32 mac_version;
@@ -5554,10 +5342,10 @@ static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
        unsigned int i;
        u32 clk;
 
-       clk = RTL_R8(Config2) & PCI_Clock_66MHz;
+       clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz;
        for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
                if ((p->mac_version == mac_version) && (p->clk == clk)) {
-                       RTL_W32(0x7c, p->val);
+                       RTL_W32(tp, 0x7c, p->val);
                        break;
                }
        }
@@ -5566,7 +5354,6 @@ static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
 static void rtl_set_rx_mode(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        u32 mc_filter[2];       /* Multicast hash filter */
        int rx_mode;
        u32 tmp = 0;
@@ -5598,7 +5385,7 @@ static void rtl_set_rx_mode(struct net_device *dev)
        if (dev->features & NETIF_F_RXALL)
                rx_mode |= (AcceptErr | AcceptRunt);
 
-       tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode;
+       tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode;
 
        if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
                u32 data = mc_filter[0];
@@ -5610,43 +5397,24 @@ static void rtl_set_rx_mode(struct net_device *dev)
        if (tp->mac_version == RTL_GIGA_MAC_VER_35)
                mc_filter[1] = mc_filter[0] = 0xffffffff;
 
-       RTL_W32(MAR0 + 4, mc_filter[1]);
-       RTL_W32(MAR0 + 0, mc_filter[0]);
+       RTL_W32(tp, MAR0 + 4, mc_filter[1]);
+       RTL_W32(tp, MAR0 + 0, mc_filter[0]);
 
-       RTL_W32(RxConfig, tmp);
+       RTL_W32(tp, RxConfig, tmp);
 }
 
-static void rtl_hw_start_8169(struct net_device *dev)
+static void rtl_hw_start_8169(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
-       if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
-               RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW);
-               pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
-       }
-
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
-       if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_02 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_03 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_04)
-               RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
-
-       rtl_init_rxcfg(tp);
+       if (tp->mac_version == RTL_GIGA_MAC_VER_05)
+               pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
 
-       RTL_W8(EarlyTxThres, NoEarlyTx);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 
-       rtl_set_rx_max_size(ioaddr, rx_buf_sz);
+       RTL_W8(tp, EarlyTxThres, NoEarlyTx);
 
-       if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_02 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_03 ||
-           tp->mac_version == RTL_GIGA_MAC_VER_04)
-               rtl_set_rx_tx_config_registers(tp);
+       rtl_set_rx_max_size(tp);
 
-       tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
+       tp->cp_cmd |= PCIMulRW;
 
        if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
            tp->mac_version == RTL_GIGA_MAC_VER_03) {
@@ -5655,37 +5423,30 @@ static void rtl_hw_start_8169(struct net_device *dev)
                tp->cp_cmd |= (1 << 14);
        }
 
-       RTL_W16(CPlusCmd, tp->cp_cmd);
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 
-       rtl8169_set_magic_reg(ioaddr, tp->mac_version);
+       rtl8169_set_magic_reg(tp, tp->mac_version);
 
        /*
         * Undocumented corner. Supposedly:
         * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
         */
-       RTL_W16(IntrMitigate, 0x0000);
+       RTL_W16(tp, IntrMitigate, 0x0000);
 
-       rtl_set_rx_tx_desc_registers(tp, ioaddr);
+       rtl_set_rx_tx_desc_registers(tp);
+       rtl_set_rx_tx_config_registers(tp);
 
-       if (tp->mac_version != RTL_GIGA_MAC_VER_01 &&
-           tp->mac_version != RTL_GIGA_MAC_VER_02 &&
-           tp->mac_version != RTL_GIGA_MAC_VER_03 &&
-           tp->mac_version != RTL_GIGA_MAC_VER_04) {
-               RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
-               rtl_set_rx_tx_config_registers(tp);
-       }
+       RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
 
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 
        /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
-       RTL_R8(IntrMask);
-
-       RTL_W32(RxMissed, 0);
+       RTL_R8(tp, IntrMask);
 
-       rtl_set_rx_mode(dev);
+       RTL_W32(tp, RxMissed, 0);
 
        /* no early-rx interrupts */
-       RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
+       RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
 }
 
 static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value)
@@ -5719,17 +5480,13 @@ static void rtl_csi_access_enable_2(struct rtl8169_private *tp)
 
 DECLARE_RTL_COND(rtl_csiar_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R32(CSIAR) & CSIAR_FLAG;
+       return RTL_R32(tp, CSIAR) & CSIAR_FLAG;
 }
 
 static void r8169_csi_write(struct rtl8169_private *tp, int addr, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIDR, value);
-       RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
+       RTL_W32(tp, CSIDR, value);
+       RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
 
        rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100);
@@ -5737,21 +5494,17 @@ static void r8169_csi_write(struct rtl8169_private *tp, int addr, int value)
 
 static u32 r8169_csi_read(struct rtl8169_private *tp, int addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) |
+       RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
-               RTL_R32(CSIDR) : ~0;
+               RTL_R32(tp, CSIDR) : ~0;
 }
 
 static void r8402_csi_write(struct rtl8169_private *tp, int addr, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIDR, value);
-       RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
+       RTL_W32(tp, CSIDR, value);
+       RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT |
                CSIAR_FUNC_NIC);
 
@@ -5760,21 +5513,17 @@ static void r8402_csi_write(struct rtl8169_private *tp, int addr, int value)
 
 static u32 r8402_csi_read(struct rtl8169_private *tp, int addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC |
+       RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
-               RTL_R32(CSIDR) : ~0;
+               RTL_R32(tp, CSIDR) : ~0;
 }
 
 static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIDR, value);
-       RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
+       RTL_W32(tp, CSIDR, value);
+       RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT |
                CSIAR_FUNC_NIC2);
 
@@ -5783,13 +5532,11 @@ static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value)
 
 static u32 r8411_csi_read(struct rtl8169_private *tp, int addr)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 |
+       RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 |
                CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
 
        return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
-               RTL_R32(CSIDR) : ~0;
+               RTL_R32(tp, CSIDR) : ~0;
 }
 
 static void rtl_init_csi_ops(struct rtl8169_private *tp)
@@ -5851,85 +5598,67 @@ static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e,
        }
 }
 
-static void rtl_disable_clock_request(struct pci_dev *pdev)
+static void rtl_disable_clock_request(struct rtl8169_private *tp)
 {
-       pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL,
+       pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL,
                                   PCI_EXP_LNKCTL_CLKREQ_EN);
 }
 
-static void rtl_enable_clock_request(struct pci_dev *pdev)
+static void rtl_enable_clock_request(struct rtl8169_private *tp)
 {
-       pcie_capability_set_word(pdev, PCI_EXP_LNKCTL,
+       pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL,
                                 PCI_EXP_LNKCTL_CLKREQ_EN);
 }
 
 static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        u8 data;
 
-       data = RTL_R8(Config3);
+       data = RTL_R8(tp, Config3);
 
        if (enable)
                data |= Rdy_to_L23;
        else
                data &= ~Rdy_to_L23;
 
-       RTL_W8(Config3, data);
+       RTL_W8(tp, Config3, data);
 }
 
-#define R8168_CPCMD_QUIRK_MASK (\
-       EnableBist | \
-       Mac_dbgo_oe | \
-       Force_half_dup | \
-       Force_rxflow_en | \
-       Force_txflow_en | \
-       Cxpl_dbg_sel | \
-       ASF | \
-       PktCntrDisable | \
-       Mac_dbgo_sel)
-
 static void rtl_hw_start_8168bb(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 
-       RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 
        if (tp->dev->mtu <= ETH_DATA_LEN) {
-               rtl_tx_performance_tweak(pdev, (0x5 << MAX_READ_REQUEST_SHIFT) |
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B |
                                         PCI_EXP_DEVCTL_NOSNOOP_EN);
        }
 }
 
 static void rtl_hw_start_8168bef(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        rtl_hw_start_8168bb(tp);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
-       RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0));
+       RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
 }
 
 static void __rtl_hw_start_8168cp(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
+       RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down);
 
-       RTL_W8(Config1, RTL_R8(Config1) | Speed_down);
-
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 
-       RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 }
 
 static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp)
@@ -5951,42 +5680,37 @@ static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_2(tp);
 
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 }
 
 static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_2(tp);
 
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 
        /* Magic. */
-       RTL_W8(DBG_REG, 0x20);
+       RTL_W8(tp, DBG_REG, 0x20);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 }
 
 static void rtl_hw_start_8168c_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168c_1[] = {
                { 0x02, 0x0800, 0x1000 },
                { 0x03, 0,      0x0002 },
@@ -5995,7 +5719,7 @@ static void rtl_hw_start_8168c_1(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_2(tp);
 
-       RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
+       RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
 
        rtl_ephy_init(tp, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1));
 
@@ -6030,40 +5754,33 @@ static void rtl_hw_start_8168c_4(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168d(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_2(tp);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 }
 
 static void rtl_hw_start_8168dp(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_1(tp);
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 }
 
 static void rtl_hw_start_8168d_4(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
        static const struct ephy_info e_info_8168d_4[] = {
                { 0x0b, 0x0000, 0x0048 },
                { 0x19, 0x0020, 0x0050 },
@@ -6072,19 +5789,17 @@ static void rtl_hw_start_8168d_4(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_1(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
        rtl_ephy_init(tp, e_info_8168d_4, ARRAY_SIZE(e_info_8168d_4));
 
-       rtl_enable_clock_request(pdev);
+       rtl_enable_clock_request(tp);
 }
 
 static void rtl_hw_start_8168e_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
        static const struct ephy_info e_info_8168e_1[] = {
                { 0x00, 0x0200, 0x0100 },
                { 0x00, 0x0000, 0x0004 },
@@ -6106,23 +5821,21 @@ static void rtl_hw_start_8168e_1(struct rtl8169_private *tp)
        rtl_ephy_init(tp, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1));
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 
        /* Reset tx FIFO pointer */
-       RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST);
-       RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST);
 
-       RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
 }
 
 static void rtl_hw_start_8168e_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
        static const struct ephy_info e_info_8168e_2[] = {
                { 0x09, 0x0000, 0x0080 },
                { 0x19, 0x0000, 0x0224 }
@@ -6133,7 +5846,7 @@ static void rtl_hw_start_8168e_2(struct rtl8169_private *tp)
        rtl_ephy_init(tp, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2));
 
        if (tp->dev->mtu <= ETH_DATA_LEN)
-               rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+               rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
@@ -6144,29 +5857,26 @@ static void rtl_hw_start_8168e_2(struct rtl8169_private *tp)
        rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC);
        rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC);
 
-       RTL_W8(MaxTxPacketSize, EarlySize);
+       RTL_W8(tp, MaxTxPacketSize, EarlySize);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
-       RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
 
        /* Adjust EEE LED frequency */
-       RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07);
+       RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN);
-       RTL_W32(MISC, RTL_R32(MISC) | PWM_EN);
-       RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
 }
 
 static void rtl_hw_start_8168f(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_2(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
@@ -6179,20 +5889,19 @@ static void rtl_hw_start_8168f(struct rtl8169_private *tp)
        rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC);
 
-       RTL_W8(MaxTxPacketSize, EarlySize);
+       RTL_W8(tp, MaxTxPacketSize, EarlySize);
 
-       rtl_disable_clock_request(pdev);
+       rtl_disable_clock_request(tp);
 
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
-       RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB);
-       RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN);
-       RTL_W32(MISC, RTL_R32(MISC) | PWM_EN);
-       RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
 }
 
 static void rtl_hw_start_8168f_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168f_1[] = {
                { 0x06, 0x00c0, 0x0020 },
                { 0x08, 0x0001, 0x0002 },
@@ -6207,7 +5916,7 @@ static void rtl_hw_start_8168f_1(struct rtl8169_private *tp)
        rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC);
 
        /* Adjust EEE LED frequency */
-       RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07);
+       RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
 }
 
 static void rtl_hw_start_8411(struct rtl8169_private *tp)
@@ -6229,10 +5938,7 @@ static void rtl_hw_start_8411(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168g(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
 
        rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC);
@@ -6241,20 +5947,20 @@ static void rtl_hw_start_8168g(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_1(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC);
 
-       RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN);
-       RTL_W8(MaxTxPacketSize, EarlySize);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
+       RTL_W8(tp, MaxTxPacketSize, EarlySize);
 
        rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
 
        /* Adjust EEE LED frequency */
-       RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07);
+       RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
 
        rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC);
        rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC);
@@ -6264,7 +5970,6 @@ static void rtl_hw_start_8168g(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168g_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168g_1[] = {
                { 0x00, 0x0000, 0x0008 },
                { 0x0c, 0x37d0, 0x0820 },
@@ -6275,14 +5980,13 @@ static void rtl_hw_start_8168g_1(struct rtl8169_private *tp)
        rtl_hw_start_8168g(tp);
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1));
 }
 
 static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168g_2[] = {
                { 0x00, 0x0000, 0x0008 },
                { 0x0c, 0x3df0, 0x0200 },
@@ -6293,14 +5997,13 @@ static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
        rtl_hw_start_8168g(tp);
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2));
 }
 
 static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8411_2[] = {
                { 0x00, 0x0000, 0x0008 },
                { 0x0c, 0x3df0, 0x0200 },
@@ -6312,15 +6015,13 @@ static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
        rtl_hw_start_8168g(tp);
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2));
 }
 
 static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
        int rg_saw_cnt;
        u32 data;
        static const struct ephy_info e_info_8168h_1[] = {
@@ -6333,11 +6034,11 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
        };
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1));
 
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
 
        rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC);
@@ -6346,7 +6047,7 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_1(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
@@ -6357,19 +6058,19 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
 
        rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC);
 
-       RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN);
-       RTL_W8(MaxTxPacketSize, EarlySize);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
+       RTL_W8(tp, MaxTxPacketSize, EarlySize);
 
        rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
 
        /* Adjust EEE LED frequency */
-       RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07);
+       RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN);
-       RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
+       RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~TX_10M_PS_EN);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN);
 
        rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC);
 
@@ -6417,12 +6118,9 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168ep(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl8168ep_stop_cmac(tp);
 
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
 
        rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC);
@@ -6431,7 +6129,7 @@ static void rtl_hw_start_8168ep(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_1(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
        rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
@@ -6440,25 +6138,24 @@ static void rtl_hw_start_8168ep(struct rtl8169_private *tp)
 
        rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC);
 
-       RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN);
-       RTL_W8(MaxTxPacketSize, EarlySize);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
+       RTL_W8(tp, MaxTxPacketSize, EarlySize);
 
        rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
 
        /* Adjust EEE LED frequency */
-       RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07);
+       RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
 
        rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~TX_10M_PS_EN);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN);
 
        rtl_pcie_state_l2l3_enable(tp, false);
 }
 
 static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168ep_1[] = {
                { 0x00, 0xffff, 0x10ab },
                { 0x06, 0xffff, 0xf030 },
@@ -6468,8 +6165,8 @@ static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp)
        };
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1));
 
        rtl_hw_start_8168ep(tp);
@@ -6477,7 +6174,6 @@ static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8168ep_2[] = {
                { 0x00, 0xffff, 0x10a3 },
                { 0x19, 0xffff, 0xfc00 },
@@ -6485,19 +6181,18 @@ static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp)
        };
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2));
 
        rtl_hw_start_8168ep(tp);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN);
-       RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
+       RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
 }
 
 static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        u32 data;
        static const struct ephy_info e_info_8168ep_3[] = {
                { 0x00, 0xffff, 0x10a3 },
@@ -6507,14 +6202,14 @@ static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
        };
 
        /* disable aspm and clock request before access ephy */
-       RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn);
-       RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en);
+       RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
+       RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
        rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3));
 
        rtl_hw_start_8168ep(tp);
 
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN);
-       RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
+       RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
 
        data = r8168_mac_ocp_read(tp, 0xd3e2);
        data &= 0xf000;
@@ -6530,22 +6225,19 @@ static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
        r8168_mac_ocp_write(tp, 0xe860, data);
 }
 
-static void rtl_hw_start_8168(struct net_device *dev)
+static void rtl_hw_start_8168(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
-       rtl_set_rx_max_size(ioaddr, rx_buf_sz);
+       rtl_set_rx_max_size(tp);
 
-       tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1;
+       tp->cp_cmd &= ~INTT_MASK;
+       tp->cp_cmd |= PktCntrDisable | INTT_1;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 
-       RTL_W16(CPlusCmd, tp->cp_cmd);
-
-       RTL_W16(IntrMitigate, 0x5151);
+       RTL_W16(tp, IntrMitigate, 0x5151);
 
        /* Work around for RxFIFO overflow. */
        if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
@@ -6553,11 +6245,11 @@ static void rtl_hw_start_8168(struct net_device *dev)
                tp->event_slow &= ~RxOverflow;
        }
 
-       rtl_set_rx_tx_desc_registers(tp, ioaddr);
+       rtl_set_rx_tx_desc_registers(tp);
 
        rtl_set_rx_tx_config_registers(tp);
 
-       RTL_R8(IntrMask);
+       RTL_R8(tp, IntrMask);
 
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_11:
@@ -6659,34 +6351,19 @@ static void rtl_hw_start_8168(struct net_device *dev)
 
        default:
                printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n",
-                       dev->name, tp->mac_version);
+                      tp->dev->name, tp->mac_version);
                break;
        }
 
-       RTL_W8(Cfg9346, Cfg9346_Lock);
-
-       RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 
-       rtl_set_rx_mode(dev);
+       RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
 
-       RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
+       RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
 }
 
-#define R810X_CPCMD_QUIRK_MASK (\
-       EnableBist | \
-       Mac_dbgo_oe | \
-       Force_half_dup | \
-       Force_rxflow_en | \
-       Force_txflow_en | \
-       Cxpl_dbg_sel | \
-       ASF | \
-       PktCntrDisable | \
-       Mac_dbgo_sel)
-
 static void rtl_hw_start_8102e_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
        static const struct ephy_info e_info_8102e_1[] = {
                { 0x01, 0, 0x6e65 },
                { 0x02, 0, 0x091f },
@@ -6701,32 +6378,29 @@ static void rtl_hw_start_8102e_1(struct rtl8169_private *tp)
 
        rtl_csi_access_enable_2(tp);
 
-       RTL_W8(DBG_REG, FIX_NAK_1);
+       RTL_W8(tp, DBG_REG, FIX_NAK_1);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W8(Config1,
+       RTL_W8(tp, Config1,
               LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable);
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 
-       cfg1 = RTL_R8(Config1);
+       cfg1 = RTL_R8(tp, Config1);
        if ((cfg1 & LEDS0) && (cfg1 & LEDS1))
-               RTL_W8(Config1, cfg1 & ~LEDS0);
+               RTL_W8(tp, Config1, cfg1 & ~LEDS0);
 
        rtl_ephy_init(tp, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1));
 }
 
 static void rtl_hw_start_8102e_2(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        rtl_csi_access_enable_2(tp);
 
-       rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
-       RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable);
-       RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
+       RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable);
+       RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
 }
 
 static void rtl_hw_start_8102e_3(struct rtl8169_private *tp)
@@ -6738,7 +6412,6 @@ static void rtl_hw_start_8102e_3(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8105e_1(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8105e_1[] = {
                { 0x07, 0, 0x4000 },
                { 0x19, 0, 0x0200 },
@@ -6751,13 +6424,13 @@ static void rtl_hw_start_8105e_1(struct rtl8169_private *tp)
        };
 
        /* Force LAN exit from ASPM if Rx/Tx are not idle */
-       RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800);
+       RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
 
        /* Disable Early Tally Counter */
-       RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000);
+       RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000);
 
-       RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET);
-       RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
 
        rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1));
 
@@ -6772,7 +6445,6 @@ static void rtl_hw_start_8105e_2(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8402(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        static const struct ephy_info e_info_8402[] = {
                { 0x19, 0xffff, 0xff64 },
                { 0x1e, 0, 0x4000 }
@@ -6781,14 +6453,14 @@ static void rtl_hw_start_8402(struct rtl8169_private *tp)
        rtl_csi_access_enable_2(tp);
 
        /* Force LAN exit from ASPM if Rx/Tx are not idle */
-       RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800);
+       RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
 
-       RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO);
-       RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB);
+       RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
 
        rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402));
 
-       rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT);
+       rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
 
        rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC);
        rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC);
@@ -6803,42 +6475,36 @@ static void rtl_hw_start_8402(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8106(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        /* Force LAN exit from ASPM if Rx/Tx are not idle */
-       RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800);
+       RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
 
-       RTL_W32(MISC, (RTL_R32(MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN);
-       RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET);
-       RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN);
+       RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET);
+       RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
 
        rtl_pcie_state_l2l3_enable(tp, false);
 }
 
-static void rtl_hw_start_8101(struct net_device *dev)
+static void rtl_hw_start_8101(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct pci_dev *pdev = tp->pci_dev;
-
        if (tp->mac_version >= RTL_GIGA_MAC_VER_30)
                tp->event_slow &= ~RxFIFOOver;
 
        if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
            tp->mac_version == RTL_GIGA_MAC_VER_16)
-               pcie_capability_set_word(pdev, PCI_EXP_DEVCTL,
+               pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
                                         PCI_EXP_DEVCTL_NOSNOOP_EN);
 
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
 
-       RTL_W8(MaxTxPacketSize, TxPacketMax);
+       RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
 
-       rtl_set_rx_max_size(ioaddr, rx_buf_sz);
+       rtl_set_rx_max_size(tp);
 
-       tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK;
-       RTL_W16(CPlusCmd, tp->cp_cmd);
+       tp->cp_cmd &= CPCMD_QUIRK_MASK;
+       RTL_W16(tp, CPlusCmd, tp->cp_cmd);
 
-       rtl_set_rx_tx_desc_registers(tp, ioaddr);
+       rtl_set_rx_tx_desc_registers(tp);
 
        rtl_set_rx_tx_config_registers(tp);
 
@@ -6878,17 +6544,15 @@ static void rtl_hw_start_8101(struct net_device *dev)
                break;
        }
 
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+       RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 
-       RTL_W16(IntrMitigate, 0x0000);
+       RTL_W16(tp, IntrMitigate, 0x0000);
 
-       RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
+       RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
 
-       rtl_set_rx_mode(dev);
+       RTL_R8(tp, IntrMask);
 
-       RTL_R8(IntrMask);
-
-       RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
+       RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
 }
 
 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
@@ -6915,29 +6579,22 @@ static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
 static void rtl8169_free_rx_databuff(struct rtl8169_private *tp,
                                     void **data_buff, struct RxDesc *desc)
 {
-       dma_unmap_single(&tp->pci_dev->dev, le64_to_cpu(desc->addr), rx_buf_sz,
-                        DMA_FROM_DEVICE);
+       dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr),
+                        R8169_RX_BUF_SIZE, DMA_FROM_DEVICE);
 
        kfree(*data_buff);
        *data_buff = NULL;
        rtl8169_make_unusable_by_asic(desc);
 }
 
-static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz)
+static inline void rtl8169_mark_to_asic(struct RxDesc *desc)
 {
        u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
 
        /* Force memory writes to complete before releasing descriptor */
        dma_wmb();
 
-       desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz);
-}
-
-static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
-                                      u32 rx_buf_sz)
-{
-       desc->addr = cpu_to_le64(mapping);
-       rtl8169_mark_to_asic(desc, rx_buf_sz);
+       desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE);
 }
 
 static inline void *rtl8169_align(void *data)
@@ -6950,22 +6607,21 @@ static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
 {
        void *data;
        dma_addr_t mapping;
-       struct device *d = &tp->pci_dev->dev;
-       struct net_device *dev = tp->dev;
-       int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1;
+       struct device *d = tp_to_dev(tp);
+       int node = dev_to_node(d);
 
-       data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
+       data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node);
        if (!data)
                return NULL;
 
        if (rtl8169_align(data) != data) {
                kfree(data);
-               data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node);
+               data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node);
                if (!data)
                        return NULL;
        }
 
-       mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz,
+       mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE,
                                 DMA_FROM_DEVICE);
        if (unlikely(dma_mapping_error(d, mapping))) {
                if (net_ratelimit())
@@ -6973,7 +6629,8 @@ static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
                goto err_out;
        }
 
-       rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
+       desc->addr = cpu_to_le64(mapping);
+       rtl8169_mark_to_asic(desc);
        return data;
 
 err_out:
@@ -7005,9 +6662,6 @@ static int rtl8169_rx_fill(struct rtl8169_private *tp)
        for (i = 0; i < NUM_RX_DESC; i++) {
                void *data;
 
-               if (tp->Rx_databuff[i])
-                       continue;
-
                data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i);
                if (!data) {
                        rtl8169_make_unusable_by_asic(tp->RxDescArray + i);
@@ -7024,14 +6678,12 @@ err_out:
        return -ENOMEM;
 }
 
-static int rtl8169_init_ring(struct net_device *dev)
+static int rtl8169_init_ring(struct rtl8169_private *tp)
 {
-       struct rtl8169_private *tp = netdev_priv(dev);
-
        rtl8169_init_ring_indexes(tp);
 
-       memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
-       memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *));
+       memset(tp->tx_skb, 0, sizeof(tp->tx_skb));
+       memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff));
 
        return rtl8169_rx_fill(tp);
 }
@@ -7062,7 +6714,7 @@ static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start,
                if (len) {
                        struct sk_buff *skb = tx_skb->skb;
 
-                       rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
+                       rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb,
                                             tp->TxDescArray + entry);
                        if (skb) {
                                dev_consume_skb_any(skb);
@@ -7090,15 +6742,15 @@ static void rtl_reset_work(struct rtl8169_private *tp)
        rtl8169_hw_reset(tp);
 
        for (i = 0; i < NUM_RX_DESC; i++)
-               rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz);
+               rtl8169_mark_to_asic(tp->RxDescArray + i);
 
        rtl8169_tx_clear(tp);
        rtl8169_init_ring_indexes(tp);
 
        napi_enable(&tp->napi);
-       rtl_hw_start(dev);
+       rtl_hw_start(tp);
        netif_wake_queue(dev);
-       rtl8169_check_link_status(dev, tp, tp->mmio_addr);
+       rtl8169_check_link_status(dev, tp);
 }
 
 static void rtl8169_tx_timeout(struct net_device *dev)
@@ -7114,7 +6766,7 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
        struct skb_shared_info *info = skb_shinfo(skb);
        unsigned int cur_frag, entry;
        struct TxDesc *uninitialized_var(txd);
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
 
        entry = tp->cur_tx;
        for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
@@ -7346,8 +6998,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
        struct rtl8169_private *tp = netdev_priv(dev);
        unsigned int entry = tp->cur_tx % NUM_TX_DESC;
        struct TxDesc *txd = tp->TxDescArray + entry;
-       void __iomem *ioaddr = tp->mmio_addr;
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
        dma_addr_t mapping;
        u32 status, len;
        u32 opts[2];
@@ -7406,7 +7057,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 
        tp->cur_tx += frags + 1;
 
-       RTL_W8(TxPoll, NPQ);
+       RTL_W8(tp, TxPoll, NPQ);
 
        mmiowb();
 
@@ -7477,11 +7128,9 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev)
 
        /* The infamous DAC f*ckup only happens at boot time */
        if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) {
-               void __iomem *ioaddr = tp->mmio_addr;
-
                netif_info(tp, intr, dev, "disabling PCI DAC\n");
                tp->cp_cmd &= ~PCIDAC;
-               RTL_W16(CPlusCmd, tp->cp_cmd);
+               RTL_W16(tp, CPlusCmd, tp->cp_cmd);
                dev->features &= ~NETIF_F_HIGHDMA;
        }
 
@@ -7513,7 +7162,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
                 */
                dma_rmb();
 
-               rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
+               rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb,
                                     tp->TxDescArray + entry);
                if (status & LastFrag) {
                        u64_stats_update_begin(&tp->tx_stats.syncp);
@@ -7547,11 +7196,8 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
                 * of start_xmit activity is detected (if it is not detected,
                 * it is slow enough). -- FR
                 */
-               if (tp->cur_tx != dirty_tx) {
-                       void __iomem *ioaddr = tp->mmio_addr;
-
-                       RTL_W8(TxPoll, NPQ);
-               }
+               if (tp->cur_tx != dirty_tx)
+                       RTL_W8(tp, TxPoll, NPQ);
        }
 }
 
@@ -7577,14 +7223,14 @@ static struct sk_buff *rtl8169_try_rx_copy(void *data,
                                           dma_addr_t addr)
 {
        struct sk_buff *skb;
-       struct device *d = &tp->pci_dev->dev;
+       struct device *d = tp_to_dev(tp);
 
        data = rtl8169_align(data);
        dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
        prefetch(data);
        skb = napi_alloc_skb(&tp->napi, pkt_size);
        if (skb)
-               memcpy(skb->data, data, pkt_size);
+               skb_copy_to_linear_data(skb, data, pkt_size);
        dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE);
 
        return skb;
@@ -7602,7 +7248,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget
                struct RxDesc *desc = tp->RxDescArray + entry;
                u32 status;
 
-               status = le32_to_cpu(desc->opts1) & tp->opts1_mask;
+               status = le32_to_cpu(desc->opts1);
                if (status & DescOwn)
                        break;
 
@@ -7620,14 +7266,16 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget
                                dev->stats.rx_length_errors++;
                        if (status & RxCRC)
                                dev->stats.rx_crc_errors++;
-                       if (status & RxFOVF) {
+                       /* RxFOVF is a reserved bit on later chip versions */
+                       if (tp->mac_version == RTL_GIGA_MAC_VER_01 &&
+                           status & RxFOVF) {
                                rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
                                dev->stats.rx_fifo_errors++;
-                       }
-                       if ((status & (RxRUNT | RxCRC)) &&
-                           !(status & (RxRWT | RxFOVF)) &&
-                           (dev->features & NETIF_F_RXALL))
+                       } else if (status & (RxRUNT | RxCRC) &&
+                                  !(status & RxRWT) &&
+                                  dev->features & NETIF_F_RXALL) {
                                goto process_pkt;
+                       }
                } else {
                        struct sk_buff *skb;
                        dma_addr_t addr;
@@ -7676,7 +7324,7 @@ process_pkt:
                }
 release_descriptor:
                desc->opts2 = 0;
-               rtl8169_mark_to_asic(desc, rx_buf_sz);
+               rtl8169_mark_to_asic(desc);
        }
 
        count = cur_rx - tp->cur_rx;
@@ -7687,8 +7335,7 @@ release_descriptor:
 
 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 {
-       struct net_device *dev = dev_instance;
-       struct rtl8169_private *tp = netdev_priv(dev);
+       struct rtl8169_private *tp = dev_instance;
        int handled = 0;
        u16 status;
 
@@ -7699,7 +7346,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
                        handled = 1;
 
                        rtl_irq_disable(tp);
-                       napi_schedule(&tp->napi);
+                       napi_schedule_irqoff(&tp->napi);
                }
        }
        return IRQ_RETVAL(handled);
@@ -7732,7 +7379,7 @@ static void rtl_slow_event_work(struct rtl8169_private *tp)
                rtl8169_pcierr_interrupt(dev);
 
        if (status & LinkChg)
-               rtl8169_check_link_status(dev, tp, tp->mmio_addr);
+               rtl8169_check_link_status(dev, tp);
 
        rtl_irq_enable_all(tp);
 }
@@ -7804,21 +7451,20 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
        return work_done;
 }
 
-static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr)
+static void rtl8169_rx_missed(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
 
        if (tp->mac_version > RTL_GIGA_MAC_VER_06)
                return;
 
-       dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff);
-       RTL_W32(RxMissed, 0);
+       dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff;
+       RTL_W32(tp, RxMissed, 0);
 }
 
 static void rtl8169_down(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
 
        del_timer_sync(&tp->timer);
 
@@ -7831,7 +7477,7 @@ static void rtl8169_down(struct net_device *dev)
         * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task)
         * and napi is disabled (rtl8169_poll).
         */
-       rtl8169_rx_missed(dev, ioaddr);
+       rtl8169_rx_missed(dev);
 
        /* Give a racing hard_start_xmit a few cycles to complete. */
        synchronize_sched();
@@ -7851,7 +7497,7 @@ static int rtl8169_close(struct net_device *dev)
        pm_runtime_get_sync(&pdev->dev);
 
        /* Update counters before going down */
-       rtl8169_update_counters(dev);
+       rtl8169_update_counters(tp);
 
        rtl_lock_work(tp);
        clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
@@ -7861,7 +7507,7 @@ static int rtl8169_close(struct net_device *dev)
 
        cancel_work_sync(&tp->wk.work);
 
-       free_irq(pdev->irq, dev);
+       pci_free_irq(pdev, 0, tp);
 
        dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
                          tp->RxPhyAddr);
@@ -7880,14 +7526,13 @@ static void rtl8169_netpoll(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
 
-       rtl8169_interrupt(tp->pci_dev->irq, dev);
+       rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), dev);
 }
 #endif
 
 static int rtl_open(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        struct pci_dev *pdev = tp->pci_dev;
        int retval = -ENOMEM;
 
@@ -7907,7 +7552,7 @@ static int rtl_open(struct net_device *dev)
        if (!tp->RxDescArray)
                goto err_free_tx_0;
 
-       retval = rtl8169_init_ring(dev);
+       retval = rtl8169_init_ring(tp);
        if (retval < 0)
                goto err_free_rx_1;
 
@@ -7917,9 +7562,8 @@ static int rtl_open(struct net_device *dev)
 
        rtl_request_firmware(tp);
 
-       retval = request_irq(pdev->irq, rtl8169_interrupt,
-                            (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
-                            dev->name, dev);
+       retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp,
+                                dev->name);
        if (retval < 0)
                goto err_release_fw_2;
 
@@ -7931,13 +7575,11 @@ static int rtl_open(struct net_device *dev)
 
        rtl8169_init_phy(dev, tp);
 
-       __rtl8169_set_features(dev, dev->features);
-
        rtl_pll_power_up(tp);
 
-       rtl_hw_start(dev);
+       rtl_hw_start(tp);
 
-       if (!rtl8169_init_counter_offsets(dev))
+       if (!rtl8169_init_counter_offsets(tp))
                netif_warn(tp, hw, dev, "counter reset/update failed\n");
 
        netif_start_queue(dev);
@@ -7947,7 +7589,7 @@ static int rtl_open(struct net_device *dev)
        tp->saved_wolopts = 0;
        pm_runtime_put_sync(&pdev->dev);
 
-       rtl8169_check_link_status(dev, tp, ioaddr);
+       rtl8169_check_link_status(dev, tp);
 out:
        return retval;
 
@@ -7971,7 +7613,6 @@ static void
 rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
-       void __iomem *ioaddr = tp->mmio_addr;
        struct pci_dev *pdev = tp->pci_dev;
        struct rtl8169_counters *counters = tp->counters;
        unsigned int start;
@@ -7979,7 +7620,7 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
        pm_runtime_get_noresume(&pdev->dev);
 
        if (netif_running(dev) && pm_runtime_active(&pdev->dev))
-               rtl8169_rx_missed(dev, ioaddr);
+               rtl8169_rx_missed(dev);
 
        do {
                start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp);
@@ -8007,7 +7648,7 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
         * from tally counters.
         */
        if (pm_runtime_active(&pdev->dev))
-               rtl8169_update_counters(dev);
+               rtl8169_update_counters(tp);
 
        /*
         * Subtract values fetched during initalization.
@@ -8102,8 +7743,8 @@ static int rtl8169_runtime_suspend(struct device *device)
        rtl8169_net_suspend(dev);
 
        /* Update counters before going runtime suspend */
-       rtl8169_rx_missed(dev, tp->mmio_addr);
-       rtl8169_update_counters(dev);
+       rtl8169_rx_missed(dev);
+       rtl8169_update_counters(tp);
 
        return 0;
 }
@@ -8163,8 +7804,6 @@ static const struct dev_pm_ops rtl8169_pm_ops = {
 
 static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
        /* WoL fails with 8168b when the receiver is disabled. */
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_11:
@@ -8172,9 +7811,9 @@ static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp)
        case RTL_GIGA_MAC_VER_17:
                pci_clear_master(tp->pci_dev);
 
-               RTL_W8(ChipCmd, CmdRxEnb);
+               RTL_W8(tp, ChipCmd, CmdRxEnb);
                /* PCI commit */
-               RTL_R8(ChipCmd);
+               RTL_R8(tp, ChipCmd);
                break;
        default:
                break;
@@ -8209,15 +7848,8 @@ static void rtl_remove_one(struct pci_dev *pdev)
        struct net_device *dev = pci_get_drvdata(pdev);
        struct rtl8169_private *tp = netdev_priv(dev);
 
-       if ((tp->mac_version == RTL_GIGA_MAC_VER_27 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_28 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_31 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_49 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_50 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_51) &&
-           r8168_check_dash(tp)) {
+       if (r8168_check_dash(tp))
                rtl8168_driver_stop(tp);
-       }
 
        netif_napi_del(&tp->napi);
 
@@ -8252,88 +7884,68 @@ static const struct net_device_ops rtl_netdev_ops = {
 };
 
 static const struct rtl_cfg_info {
-       void (*hw_start)(struct net_device *);
-       unsigned int region;
-       unsigned int align;
+       void (*hw_start)(struct rtl8169_private *tp);
        u16 event_slow;
-       unsigned features;
+       unsigned int has_gmii:1;
        const struct rtl_coalesce_info *coalesce_info;
        u8 default_ver;
 } rtl_cfg_infos [] = {
        [RTL_CFG_0] = {
                .hw_start       = rtl_hw_start_8169,
-               .region         = 1,
-               .align          = 0,
                .event_slow     = SYSErr | LinkChg | RxOverflow | RxFIFOOver,
-               .features       = RTL_FEATURE_GMII,
+               .has_gmii       = 1,
                .coalesce_info  = rtl_coalesce_info_8169,
                .default_ver    = RTL_GIGA_MAC_VER_01,
        },
        [RTL_CFG_1] = {
                .hw_start       = rtl_hw_start_8168,
-               .region         = 2,
-               .align          = 8,
                .event_slow     = SYSErr | LinkChg | RxOverflow,
-               .features       = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
+               .has_gmii       = 1,
                .coalesce_info  = rtl_coalesce_info_8168_8136,
                .default_ver    = RTL_GIGA_MAC_VER_11,
        },
        [RTL_CFG_2] = {
                .hw_start       = rtl_hw_start_8101,
-               .region         = 2,
-               .align          = 8,
                .event_slow     = SYSErr | LinkChg | RxOverflow | RxFIFOOver |
                                  PCSTimeout,
-               .features       = RTL_FEATURE_MSI,
                .coalesce_info  = rtl_coalesce_info_8168_8136,
                .default_ver    = RTL_GIGA_MAC_VER_13,
        }
 };
 
-/* Cfg9346_Unlock assumed. */
-static unsigned rtl_try_msi(struct rtl8169_private *tp,
-                           const struct rtl_cfg_info *cfg)
+static int rtl_alloc_irq(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-       unsigned msi = 0;
-       u8 cfg2;
+       unsigned int flags;
 
-       cfg2 = RTL_R8(Config2) & ~MSIEnable;
-       if (cfg->features & RTL_FEATURE_MSI) {
-               if (pci_enable_msi(tp->pci_dev)) {
-                       netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n");
-               } else {
-                       cfg2 |= MSIEnable;
-                       msi = RTL_FEATURE_MSI;
-               }
+       if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
+               RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
+               RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
+               RTL_W8(tp, Cfg9346, Cfg9346_Lock);
+               flags = PCI_IRQ_LEGACY;
+       } else {
+               flags = PCI_IRQ_ALL_TYPES;
        }
-       if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
-               RTL_W8(Config2, cfg2);
-       return msi;
+
+       return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags);
 }
 
 DECLARE_RTL_COND(rtl_link_list_ready_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return RTL_R8(MCU) & LINK_LIST_RDY;
+       return RTL_R8(tp, MCU) & LINK_LIST_RDY;
 }
 
 DECLARE_RTL_COND(rtl_rxtx_empty_cond)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
-
-       return (RTL_R8(MCU) & RXTX_EMPTY) == RXTX_EMPTY;
+       return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY;
 }
 
 static void rtl_hw_init_8168g(struct rtl8169_private *tp)
 {
-       void __iomem *ioaddr = tp->mmio_addr;
        u32 data;
 
        tp->ocp_base = OCP_STD_PHY_BASE;
 
-       RTL_W32(MISC, RTL_R32(MISC) | RXDV_GATED_EN);
+       RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
 
        if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42))
                return;
@@ -8341,9 +7953,9 @@ static void rtl_hw_init_8168g(struct rtl8169_private *tp)
        if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
                return;
 
-       RTL_W8(ChipCmd, RTL_R8(ChipCmd) & ~(CmdTxEnb | CmdRxEnb));
+       RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb));
        msleep(1);
-       RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB);
+       RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
 
        data = r8168_mac_ocp_read(tp, 0xe8de);
        data &= ~(1 << 14);
@@ -8393,12 +8005,10 @@ static void rtl_hw_initialize(struct rtl8169_private *tp)
 static int rtl_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;
-       int chipset, i;
+       int chipset, region, i;
        int rc;
 
        if (netif_msg_drv(&debug)) {
@@ -8423,7 +8033,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        mii->mdio_write = rtl_mdio_write;
        mii->phy_id_mask = 0x1f;
        mii->reg_num_mask = 0x1f;
-       mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
+       mii->supports_gmii = cfg->has_gmii;
 
        /* disable ASPM completely as that cause random device stop working
         * problems as well as full system hangs for some PCIe devices users */
@@ -8433,50 +8043,41 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        /* enable device (incl. PCI PM wakeup and hotplug setup) */
        rc = pcim_enable_device(pdev);
        if (rc < 0) {
-               netif_err(tp, probe, dev, "enable failure\n");
+               dev_err(&pdev->dev, "enable failure\n");
                return rc;
        }
 
        if (pcim_set_mwi(pdev) < 0)
-               netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n");
+               dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n");
 
-       /* make sure PCI base addr 1 is MMIO */
-       if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
-               netif_err(tp, probe, dev,
-                         "region #%d not an MMIO resource, aborting\n",
-                         region);
+       /* use first MMIO region */
+       region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1;
+       if (region < 0) {
+               dev_err(&pdev->dev, "no MMIO resource found\n");
                return -ENODEV;
        }
 
        /* check for weird/broken PCI region reporting */
        if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
-               netif_err(tp, probe, dev,
-                         "Invalid PCI region size(s), aborting\n");
+               dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n");
                return -ENODEV;
        }
 
-       rc = pci_request_regions(pdev, MODULENAME);
+       rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME);
        if (rc < 0) {
-               netif_err(tp, probe, dev, "could not request regions\n");
+               dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
                return rc;
        }
 
-       /* ioremap MMIO region */
-       ioaddr = devm_ioremap(&pdev->dev, pci_resource_start(pdev, region),
-                             R8169_REGS_SIZE);
-       if (!ioaddr) {
-               netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n");
-               return -EIO;
-       }
-       tp->mmio_addr = ioaddr;
+       tp->mmio_addr = pcim_iomap_table(pdev)[region];
 
        if (!pci_is_pcie(pdev))
-               netif_info(tp, probe, dev, "not PCI Express\n");
+               dev_info(&pdev->dev, "not PCI Express\n");
 
        /* Identify chip attached to board */
-       rtl8169_get_mac_version(tp, dev, cfg->default_ver);
+       rtl8169_get_mac_version(tp, cfg->default_ver);
 
-       tp->cp_cmd = 0;
+       tp->cp_cmd = RTL_R16(tp, CPlusCmd);
 
        if ((sizeof(dma_addr_t) > 4) &&
            (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) &&
@@ -8491,7 +8092,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        } else {
                rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (rc < 0) {
-                       netif_err(tp, probe, dev, "DMA configuration failed\n");
+                       dev_err(&pdev->dev, "DMA configuration failed\n");
                        return rc;
                }
        }
@@ -8516,43 +8117,15 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        rtl8169_print_mac_version(tp);
 
        chipset = tp->mac_version;
-       tp->txd_version = rtl_chip_infos[chipset].txd_version;
 
-       RTL_W8(Cfg9346, Cfg9346_Unlock);
-       RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
-       RTL_W8(Config5, RTL_R8(Config5) & (BWF | MWF | UWF | LanWake | PMEStatus));
-       switch (tp->mac_version) {
-       case RTL_GIGA_MAC_VER_34:
-       case RTL_GIGA_MAC_VER_35:
-       case RTL_GIGA_MAC_VER_36:
-       case RTL_GIGA_MAC_VER_37:
-       case RTL_GIGA_MAC_VER_38:
-       case RTL_GIGA_MAC_VER_40:
-       case RTL_GIGA_MAC_VER_41:
-       case RTL_GIGA_MAC_VER_42:
-       case RTL_GIGA_MAC_VER_43:
-       case RTL_GIGA_MAC_VER_44:
-       case RTL_GIGA_MAC_VER_45:
-       case RTL_GIGA_MAC_VER_46:
-       case RTL_GIGA_MAC_VER_47:
-       case RTL_GIGA_MAC_VER_48:
-       case RTL_GIGA_MAC_VER_49:
-       case RTL_GIGA_MAC_VER_50:
-       case RTL_GIGA_MAC_VER_51:
-               if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2)
-                       tp->features |= RTL_FEATURE_WOL;
-               if ((RTL_R8(Config3) & LinkUp) != 0)
-                       tp->features |= RTL_FEATURE_WOL;
-               break;
-       default:
-               if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
-                       tp->features |= RTL_FEATURE_WOL;
-               break;
+       rc = rtl_alloc_irq(tp);
+       if (rc < 0) {
+               dev_err(&pdev->dev, "Can't allocate interrupt\n");
+               return rc;
        }
-       if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
-               tp->features |= RTL_FEATURE_WOL;
-       tp->features |= rtl_try_msi(tp, cfg);
-       RTL_W8(Cfg9346, Cfg9346_Lock);
+
+       /* override BIOS settings, use userspace tools to enable WOL */
+       __rtl8169_set_wol(tp, 0);
 
        if (rtl_tbi_enabled(tp)) {
                tp->set_speed = rtl8169_set_speed_tbi;
@@ -8600,12 +8173,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                        rtl_rar_set(tp, (u8 *)mac_addr);
        }
        for (i = 0; i < ETH_ALEN; i++)
-               dev->dev_addr[i] = RTL_R8(MAC0 + i);
+               dev->dev_addr[i] = RTL_R8(tp, MAC0 + i);
 
        dev->ethtool_ops = &rtl8169_ethtool_ops;
        dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
 
-       netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
+       netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT);
 
        /* don't enable SG, IP_CSUM and TSO by default - it might not work
         * properly for all devices */
@@ -8628,13 +8201,17 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                /* Disallow toggling */
                dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX;
 
-       if (tp->txd_version == RTL_TD_0)
+       switch (rtl_chip_infos[chipset].txd_version) {
+       case RTL_TD_0:
                tp->tso_csum = rtl8169_tso_csum_v1;
-       else if (tp->txd_version == RTL_TD_1) {
+               break;
+       case RTL_TD_1:
                tp->tso_csum = rtl8169_tso_csum_v2;
                dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
-       } else
+               break;
+       default:
                WARN_ON_ONCE(1);
+       }
 
        dev->hw_features |= NETIF_F_RXALL;
        dev->hw_features |= NETIF_F_RXFCS;
@@ -8647,9 +8224,6 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        tp->event_slow = cfg->event_slow;
        tp->coalesce_info = cfg->coalesce_info;
 
-       tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ?
-               ~(RxBOVF | RxFOVF) : ~0;
-
        timer_setup(&tp->timer, rtl8169_phy_timer, 0);
 
        tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
@@ -8666,25 +8240,19 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc < 0)
                return rc;
 
-       netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n",
-                  rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr,
-                  (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq);
+       netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n",
+                  rtl_chip_infos[chipset].name, dev->dev_addr,
+                  (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff),
+                  pci_irq_vector(pdev, 0));
        if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) {
                netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, "
                           "tx checksumming: %s]\n",
                           rtl_chip_infos[chipset].jumbo_max,
-                          rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko");
+                         tp->mac_version <= RTL_GIGA_MAC_VER_06 ? "ok" : "ko");
        }
 
-       if ((tp->mac_version == RTL_GIGA_MAC_VER_27 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_28 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_31 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_49 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_50 ||
-            tp->mac_version == RTL_GIGA_MAC_VER_51) &&
-           r8168_check_dash(tp)) {
+       if (r8168_check_dash(tp))
                rtl8168_driver_start(tp);
-       }
 
        netif_carrier_off(dev);