Lines Matching +full:broken +full:- +full:save +full:- +full:restore +full:- +full:fw

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
26 #include <linux/dma-mapping.h>
38 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw"
39 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw"
40 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw"
41 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw"
42 #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw"
43 #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw"
44 #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw"
45 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw"
46 #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw"
47 #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw"
48 #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw"
49 #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw"
50 #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw"
51 #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw"
52 #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw"
53 #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw"
54 #define FIRMWARE_8168FP_3 "rtl_nic/rtl8168fp-3.fw"
55 #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw"
56 #define FIRMWARE_8125A_3 "rtl_nic/rtl8125a-3.fw"
57 #define FIRMWARE_8125B_2 "rtl_nic/rtl8125b-2.fw"
58 #define FIRMWARE_8126A_2 "rtl_nic/rtl8126a-2.fw"
59 #define FIRMWARE_8126A_3 "rtl_nic/rtl8126a-3.fw"
65 #define R8169_RX_BUF_SIZE (SZ_16K - 1)
78 #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg))
79 #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg))
80 #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg))
81 #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg))
82 #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg))
83 #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg))
85 #define JUMBO_4K (4 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
86 #define JUMBO_6K (6 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
87 #define JUMBO_7K (7 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
88 #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
100 /* PCI-E devices. */
190 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */
191 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */
407 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
426 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
644 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
645 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
687 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
715 return &tp->pci_dev->dev; in tp_to_dev()
722 raw_spin_lock_irqsave(&tp->cfg9346_usage_lock, flags); in rtl_lock_config_regs()
723 if (!--tp->cfg9346_usage_count) in rtl_lock_config_regs()
725 raw_spin_unlock_irqrestore(&tp->cfg9346_usage_lock, flags); in rtl_lock_config_regs()
732 raw_spin_lock_irqsave(&tp->cfg9346_usage_lock, flags); in rtl_unlock_config_regs()
733 if (!tp->cfg9346_usage_count++) in rtl_unlock_config_regs()
735 raw_spin_unlock_irqrestore(&tp->cfg9346_usage_lock, flags); in rtl_unlock_config_regs()
749 raw_spin_lock_irqsave(&tp->config25_lock, flags); in rtl_mod_config2()
752 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in rtl_mod_config2()
760 raw_spin_lock_irqsave(&tp->config25_lock, flags); in rtl_mod_config5()
763 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in rtl_mod_config5()
768 return tp->mac_version >= RTL_GIGA_MAC_VER_61; in rtl_is_8125()
773 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_is_8168evl_up()
774 tp->mac_version != RTL_GIGA_MAC_VER_39 && in rtl_is_8168evl_up()
775 tp->mac_version <= RTL_GIGA_MAC_VER_53; in rtl_is_8168evl_up()
780 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_supports_eee()
781 tp->mac_version != RTL_GIGA_MAC_VER_37 && in rtl_supports_eee()
782 tp->mac_version != RTL_GIGA_MAC_VER_39; in rtl_supports_eee()
804 if (c->check(tp) == high) in rtl_loop_wait()
810 netdev_err(tp->dev, "%s == %d (loop: %d, delay: %lu).\n", in rtl_loop_wait()
811 c->msg, !high, n, usecs); in rtl_loop_wait()
848 mutex_lock(&tp->led_lock); in rtl8168_led_mod_ctrl()
850 mutex_unlock(&tp->led_lock); in rtl8168_led_mod_ctrl()
891 mutex_lock(&tp->led_lock); in rtl8125_set_led_mode()
894 mutex_unlock(&tp->led_lock); in rtl8125_set_led_mode()
921 struct pci_dev *pdev = tp->pci_dev; in r8169_get_led_name()
925 domain = pci_domain_nr(pdev->bus); in r8169_get_led_name()
931 if (pdev->multifunction) in r8169_get_led_name()
932 snprintf(pfun, sizeof(pfun), "f%d", PCI_FUNC(pdev->devfn)); in r8169_get_led_name()
936 snprintf(buf, buf_len, "en%sp%ds%d%s-%d::lan", pdom, pdev->bus->number, in r8169_get_led_name()
937 PCI_SLOT(pdev->devfn), pfun, idx); in r8169_get_led_name()
944 (tp->mac_version == RTL_GIGA_MAC_VER_52 || in r8168fp_adjust_ocp_cmd()
945 tp->mac_version == RTL_GIGA_MAC_VER_53)) in r8168fp_adjust_ocp_cmd()
1036 (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT; in r8168_phy_ocp_read()
1051 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
1053 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
1071 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
1073 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
1084 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
1087 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
1091 * PHY MCU interrupts before PHY power-down.
1095 switch (tp->mac_version) { in rtl8168g_phy_suspend_quirk()
1110 tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; in r8168g_mdio_write()
1114 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_write()
1115 reg -= 0x10; in r8168g_mdio_write()
1117 if (tp->ocp_base == OCP_STD_PHY_BASE && reg == MII_BMCR) in r8168g_mdio_write()
1120 r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); in r8168g_mdio_write()
1126 return tp->ocp_base == OCP_STD_PHY_BASE ? 0 : tp->ocp_base >> 4; in r8168g_mdio_read()
1128 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_read()
1129 reg -= 0x10; in r8168g_mdio_read()
1131 return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); in r8168g_mdio_read()
1137 tp->ocp_base = value << 4; in mac_mcu_write()
1141 r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); in mac_mcu_write()
1146 return r8168_mac_ocp_read(tp, tp->ocp_base + reg); in mac_mcu_read()
1173 RTL_R32(tp, PHYAR) & 0xffff : -ETIMEDOUT; in r8169_mdio_read()
1229 switch (tp->mac_version) { in rtl_writephy()
1245 switch (tp->mac_version) { in rtl_readphy()
1319 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; in rtl8168_get_ocp_reg()
1353 if (!tp->dash_enabled) in rtl_dash_loop_wait()
1387 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_start()
1409 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_stop()
1429 switch (tp->dash_type) { in rtl_dash_is_enabled()
1441 switch (tp->mac_version) { in rtl_get_dash_type()
1454 switch (tp->mac_version) { in rtl_set_d3_pll_down()
1515 RTL_W32(tp, IntrMask_8125, tp->irq_mask); in rtl_irq_enable()
1517 RTL_W16(tp, IntrMask, tp->irq_mask); in rtl_irq_enable()
1529 struct phy_device *phydev = tp->phydev; in rtl_link_chg_patch()
1531 if (tp->mac_version == RTL_GIGA_MAC_VER_34 || in rtl_link_chg_patch()
1532 tp->mac_version == RTL_GIGA_MAC_VER_38) { in rtl_link_chg_patch()
1533 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1536 } else if (phydev->speed == SPEED_100) { in rtl_link_chg_patch()
1544 } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || in rtl_link_chg_patch()
1545 tp->mac_version == RTL_GIGA_MAC_VER_36) { in rtl_link_chg_patch()
1546 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1553 } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { in rtl_link_chg_patch()
1554 if (phydev->speed == SPEED_10) { in rtl_link_chg_patch()
1569 wol->supported = WAKE_ANY; in rtl8169_get_wol()
1570 wol->wolopts = tp->saved_wolopts; in rtl8169_get_wol()
1594 tmp--; in __rtl8169_set_wol()
1600 tmp--; in __rtl8169_set_wol()
1607 raw_spin_lock_irqsave(&tp->config25_lock, flags); in __rtl8169_set_wol()
1614 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in __rtl8169_set_wol()
1616 switch (tp->mac_version) { in __rtl8169_set_wol()
1639 if (!tp->dash_enabled) { in __rtl8169_set_wol()
1641 tp->dev->ethtool->wol_enabled = wolopts ? 1 : 0; in __rtl8169_set_wol()
1649 if (wol->wolopts & ~WAKE_ANY) in rtl8169_set_wol()
1650 return -EINVAL; in rtl8169_set_wol()
1652 tp->saved_wolopts = wol->wolopts; in rtl8169_set_wol()
1653 __rtl8169_set_wol(tp, tp->saved_wolopts); in rtl8169_set_wol()
1662 struct rtl_fw *rtl_fw = tp->rtl_fw; in rtl8169_get_drvinfo()
1664 strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); in rtl8169_get_drvinfo()
1665 strscpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); in rtl8169_get_drvinfo()
1666 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); in rtl8169_get_drvinfo()
1668 strscpy(info->fw_version, rtl_fw->version, in rtl8169_get_drvinfo()
1669 sizeof(info->fw_version)); in rtl8169_get_drvinfo()
1682 if (dev->mtu > TD_MSS_MAX) in rtl8169_fix_features()
1685 if (dev->mtu > ETH_DATA_LEN && in rtl8169_fix_features()
1686 tp->mac_version > RTL_GIGA_MAC_VER_06) in rtl8169_fix_features()
1720 tp->cp_cmd |= RxChkSum; in rtl8169_set_features()
1722 tp->cp_cmd &= ~RxChkSum; in rtl8169_set_features()
1726 tp->cp_cmd |= RxVlan; in rtl8169_set_features()
1728 tp->cp_cmd &= ~RxVlan; in rtl8169_set_features()
1731 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl8169_set_features()
1745 u32 opts2 = le32_to_cpu(desc->opts2); in rtl8169_rx_vlan_tag()
1755 u32 __iomem *data = tp->mmio_addr; in rtl8169_get_regs()
1785 return -EOPNOTSUPP; in rtl8169_get_sset_count()
1796 u32 cmd = lower_32_bits(tp->counters_phys_addr); in rtl8169_do_counters()
1798 RTL_W32(tp, CounterAddrHigh, upper_32_bits(tp->counters_phys_addr)); in rtl8169_do_counters()
1812 * is disabled. If 0xff chip may be in a PCI power-save state. in rtl8169_update_counters()
1820 struct rtl8169_counters *counters = tp->counters; in rtl8169_init_counter_offsets()
1837 if (tp->tc_offset.inited) in rtl8169_init_counter_offsets()
1840 if (tp->mac_version >= RTL_GIGA_MAC_VER_19) { in rtl8169_init_counter_offsets()
1844 tp->tc_offset.tx_errors = counters->tx_errors; in rtl8169_init_counter_offsets()
1845 tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; in rtl8169_init_counter_offsets()
1846 tp->tc_offset.tx_aborted = counters->tx_aborted; in rtl8169_init_counter_offsets()
1847 tp->tc_offset.rx_missed = counters->rx_missed; in rtl8169_init_counter_offsets()
1850 tp->tc_offset.inited = true; in rtl8169_init_counter_offsets()
1859 counters = tp->counters; in rtl8169_get_ethtool_stats()
1862 data[0] = le64_to_cpu(counters->tx_packets); in rtl8169_get_ethtool_stats()
1863 data[1] = le64_to_cpu(counters->rx_packets); in rtl8169_get_ethtool_stats()
1864 data[2] = le64_to_cpu(counters->tx_errors); in rtl8169_get_ethtool_stats()
1865 data[3] = le32_to_cpu(counters->rx_errors); in rtl8169_get_ethtool_stats()
1866 data[4] = le16_to_cpu(counters->rx_missed); in rtl8169_get_ethtool_stats()
1867 data[5] = le16_to_cpu(counters->align_errors); in rtl8169_get_ethtool_stats()
1868 data[6] = le32_to_cpu(counters->tx_one_collision); in rtl8169_get_ethtool_stats()
1869 data[7] = le32_to_cpu(counters->tx_multi_collision); in rtl8169_get_ethtool_stats()
1870 data[8] = le64_to_cpu(counters->rx_unicast); in rtl8169_get_ethtool_stats()
1871 data[9] = le64_to_cpu(counters->rx_broadcast); in rtl8169_get_ethtool_stats()
1872 data[10] = le32_to_cpu(counters->rx_multicast); in rtl8169_get_ethtool_stats()
1873 data[11] = le16_to_cpu(counters->tx_aborted); in rtl8169_get_ethtool_stats()
1874 data[12] = le16_to_cpu(counters->tx_underrun); in rtl8169_get_ethtool_stats()
1889 * > 1 - the availability of the IntrMitigate (0xe2) register through the
1894 * > 2 - the Tx timer unit at gigabit speed
1944 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_coalesce_info()
1950 if (tp->phydev->speed == SPEED_UNKNOWN) in rtl_coalesce_info()
1953 for (; ci->speed; ci++) { in rtl_coalesce_info()
1954 if (tp->phydev->speed == ci->speed) in rtl_coalesce_info()
1958 return ERR_PTR(-ELNRNG); in rtl_coalesce_info()
1972 return -EOPNOTSUPP; in rtl_get_coalesce()
1981 scale = ci->scale_nsecs[tp->cp_cmd & INTT_MASK]; in rtl_get_coalesce()
1986 ec->tx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1990 ec->tx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
1993 ec->rx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1996 ec->rx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
2013 if (usec <= ci->scale_nsecs[i] * RTL_COALESCE_T_MAX / 1000U) { in rtl_coalesce_choose_scale()
2015 return ci->scale_nsecs[i]; in rtl_coalesce_choose_scale()
2019 return -ERANGE; in rtl_coalesce_choose_scale()
2028 u32 tx_fr = ec->tx_max_coalesced_frames; in rtl_set_coalesce()
2029 u32 rx_fr = ec->rx_max_coalesced_frames; in rtl_set_coalesce()
2035 return -EOPNOTSUPP; in rtl_set_coalesce()
2038 return -ERANGE; in rtl_set_coalesce()
2040 coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs); in rtl_set_coalesce()
2048 * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) in rtl_set_coalesce()
2049 * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 in rtl_set_coalesce()
2050 * - then user does `ethtool -C eth0 rx-usecs 100` in rtl_set_coalesce()
2061 if ((tx_fr && !ec->tx_coalesce_usecs) || in rtl_set_coalesce()
2062 (rx_fr && !ec->rx_coalesce_usecs)) in rtl_set_coalesce()
2063 return -EINVAL; in rtl_set_coalesce()
2068 units = DIV_ROUND_UP(ec->tx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
2070 units = DIV_ROUND_UP(ec->rx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
2075 /* Meaning of PktCntrDisable bit changed from RTL8168e-vl */ in rtl_set_coalesce()
2079 tp->cp_cmd |= PktCntrDisable; in rtl_set_coalesce()
2081 tp->cp_cmd &= ~PktCntrDisable; in rtl_set_coalesce()
2084 tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; in rtl_set_coalesce()
2085 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_set_coalesce()
2093 unsigned int timer_val = READ_ONCE(tp->dev->mtu) + ETH_HLEN + 0x20; in rtl_set_eee_txidle_timer()
2095 switch (tp->mac_version) { in rtl_set_eee_txidle_timer()
2098 tp->tx_lpi_timer = timer_val; in rtl_set_eee_txidle_timer()
2105 tp->tx_lpi_timer = timer_val; in rtl_set_eee_txidle_timer()
2115 unsigned int speed = tp->phydev->speed; in r8169_get_tx_lpi_timer_us()
2116 unsigned int timer = tp->tx_lpi_timer; in r8169_get_tx_lpi_timer_us()
2131 return -EOPNOTSUPP; in rtl8169_get_eee()
2133 ret = phy_ethtool_get_eee(tp->phydev, data); in rtl8169_get_eee()
2137 data->tx_lpi_timer = r8169_get_tx_lpi_timer_us(tp); in rtl8169_get_eee()
2147 return -EOPNOTSUPP; in rtl8169_set_eee()
2149 return phy_ethtool_set_eee(tp->phydev, data); in rtl8169_set_eee()
2157 data->rx_max_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
2158 data->rx_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
2159 data->tx_max_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
2160 data->tx_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
2169 phy_get_pause(tp->phydev, &tx_pause, &rx_pause); in rtl8169_get_pauseparam()
2171 data->autoneg = tp->phydev->autoneg; in rtl8169_get_pauseparam()
2172 data->tx_pause = tx_pause ? 1 : 0; in rtl8169_get_pauseparam()
2173 data->rx_pause = rx_pause ? 1 : 0; in rtl8169_get_pauseparam()
2181 if (dev->mtu > ETH_DATA_LEN) in rtl8169_set_pauseparam()
2182 return -EOPNOTSUPP; in rtl8169_set_pauseparam()
2184 phy_set_asym_pause(tp->phydev, data->rx_pause, data->tx_pause); in rtl8169_set_pauseparam()
2334 /* Catch-all */ in rtl8169_get_mac_version()
2340 while ((xid & p->mask) != p->val) in rtl8169_get_mac_version()
2342 ver = p->ver; in rtl8169_get_mac_version()
2356 if (tp->rtl_fw) { in rtl_release_firmware()
2357 rtl_fw_release_firmware(tp->rtl_fw); in rtl_release_firmware()
2358 kfree(tp->rtl_fw); in rtl_release_firmware()
2359 tp->rtl_fw = NULL; in rtl_release_firmware()
2368 if (tp->rtl_fw) { in r8169_apply_firmware()
2369 rtl_fw_write_firmware(tp, tp->rtl_fw); in r8169_apply_firmware()
2370 /* At least one firmware doesn't reset tp->ocp_base. */ in r8169_apply_firmware()
2371 tp->ocp_base = OCP_STD_PHY_BASE; in r8169_apply_firmware()
2374 phy_read_poll_timeout(tp->phydev, MII_BMCR, val, in r8169_apply_firmware()
2383 if (tp->mac_version != RTL_GIGA_MAC_VER_38) in rtl8168_config_eee_mac()
2426 if (!test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) in rtl_schedule_task()
2429 set_bit(flag, tp->wk.flags); in rtl_schedule_task()
2430 schedule_work(&tp->wk.work); in rtl_schedule_task()
2435 r8169_hw_phy_config(tp, tp->phydev, tp->mac_version); in rtl8169_init_phy()
2437 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { in rtl8169_init_phy()
2438 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); in rtl8169_init_phy()
2439 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); in rtl8169_init_phy()
2444 if (tp->mac_version == RTL_GIGA_MAC_VER_05 && in rtl8169_init_phy()
2445 tp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_GIGABYTE && in rtl8169_init_phy()
2446 tp->pci_dev->subsystem_device == 0xe000) in rtl8169_init_phy()
2447 phy_write_paged(tp->phydev, 0x0001, 0x10, 0xf01b); in rtl8169_init_phy()
2450 phy_speed_up(tp->phydev); in rtl8169_init_phy()
2452 genphy_soft_reset(tp->phydev); in rtl8169_init_phy()
2465 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl_rar_set()
2480 rtl_rar_set(tp, dev->dev_addr); in rtl_set_mac_address()
2487 switch (tp->mac_version) { in rtl_init_rxcfg()
2517 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; in rtl8169_init_ring_indexes()
2568 bool jumbo = tp->dev->mtu > ETH_DATA_LEN; in rtl_jumbo_config()
2572 switch (tp->mac_version) { in rtl_jumbo_config()
2606 if (pci_is_pcie(tp->pci_dev) && tp->supports_gmii) in rtl_jumbo_config()
2607 pcie_set_readrq(tp->pci_dev, readrq); in rtl_jumbo_config()
2612 tp->phydev->advertising); in rtl_jumbo_config()
2614 tp->phydev->advertising); in rtl_jumbo_config()
2615 phy_start_aneg(tp->phydev); in rtl_jumbo_config()
2636 if (tp->rtl_fw || !tp->fw_name) in rtl_request_firmware()
2643 rtl_fw->phy_write = rtl_writephy; in rtl_request_firmware()
2644 rtl_fw->phy_read = rtl_readphy; in rtl_request_firmware()
2645 rtl_fw->mac_mcu_write = mac_mcu_write; in rtl_request_firmware()
2646 rtl_fw->mac_mcu_read = mac_mcu_read; in rtl_request_firmware()
2647 rtl_fw->fw_name = tp->fw_name; in rtl_request_firmware()
2648 rtl_fw->dev = tp_to_dev(tp); in rtl_request_firmware()
2653 tp->rtl_fw = rtl_fw; in rtl_request_firmware()
2684 switch (tp->mac_version) { in rtl_wait_txrx_fifo_empty()
2716 if (tp->mac_version >= RTL_GIGA_MAC_VER_25) in rtl_wol_enable_rx()
2720 if (tp->mac_version >= RTL_GIGA_MAC_VER_40) in rtl_wol_enable_rx()
2726 if (tp->dash_enabled) in rtl_prepare_power_down()
2729 if (tp->mac_version == RTL_GIGA_MAC_VER_32 || in rtl_prepare_power_down()
2730 tp->mac_version == RTL_GIGA_MAC_VER_33) in rtl_prepare_power_down()
2734 phy_speed_down(tp->phydev, false); in rtl_prepare_power_down()
2763 RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); in rtl_set_rx_tx_desc_registers()
2764 RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); in rtl_set_rx_tx_desc_registers()
2765 RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); in rtl_set_rx_tx_desc_registers()
2766 RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); in rtl_set_rx_tx_desc_registers()
2773 if (tp->mac_version == RTL_GIGA_MAC_VER_05) in rtl8169_set_magic_reg()
2775 else if (tp->mac_version == RTL_GIGA_MAC_VER_06) in rtl8169_set_magic_reg()
2794 if (dev->flags & IFF_PROMISC) { in rtl_set_rx_mode()
2796 } else if (!(dev->flags & IFF_MULTICAST)) { in rtl_set_rx_mode()
2798 } else if (dev->flags & IFF_ALLMULTI || in rtl_set_rx_mode()
2799 tp->mac_version == RTL_GIGA_MAC_VER_35) { in rtl_set_rx_mode()
2812 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { in rtl_set_rx_mode()
2833 u32 func = PCI_FUNC(tp->pci_dev->devfn); in rtl_csi_write()
2844 u32 func = PCI_FUNC(tp->pci_dev->devfn); in rtl_csi_read()
2855 struct pci_dev *pdev = tp->pci_dev; in rtl_set_aspm_entry_latency()
2864 if (pdev->cfg_size > 0x070f && in rtl_set_aspm_entry_latency()
2868 netdev_notice_once(tp->dev, in rtl_set_aspm_entry_latency()
2891 while (len-- > 0) { in __rtl_ephy_init()
2892 w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; in __rtl_ephy_init()
2893 rtl_ephy_write(tp, e->offset, w); in __rtl_ephy_init()
2902 pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, in rtl_disable_clock_request()
2908 pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, in rtl_enable_clock_request()
2928 switch (tp->mac_version) { in rtl_enable_exit_l1()
2945 switch (tp->mac_version) { in rtl_disable_exit_l1()
2961 if (tp->mac_version < RTL_GIGA_MAC_VER_32) in rtl_hw_aspm_clkreq_enable()
2965 if (enable && tp->aspm_manageable) { in rtl_hw_aspm_clkreq_enable()
2969 if (tp->mac_version == RTL_GIGA_MAC_VER_42 || in rtl_hw_aspm_clkreq_enable()
2970 tp->mac_version == RTL_GIGA_MAC_VER_43) in rtl_hw_aspm_clkreq_enable()
2974 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
2985 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
2997 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
3006 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
3341 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in rtl8411b_fix_phy_down()
3344 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in rtl8411b_fix_phy_down()
3366 /* The following Realtek-provided magic fixes an issue with the RX unit in rtl_hw_start_8411_2()
3367 * getting confused after the PHY having been powered-down. in rtl_hw_start_8411_2()
3434 rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; in rtl_hw_start_8168h_1()
3540 rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; in rtl_hw_start_8117()
3689 /* L0 7us, L1 32us - needed to avoid issues with link-up detection */ in rtl_hw_start_8106()
3728 if (tp->mac_version == RTL_GIGA_MAC_VER_65 || in rtl_hw_start_8125_common()
3729 tp->mac_version == RTL_GIGA_MAC_VER_66) in rtl_hw_start_8125_common()
3732 if (tp->mac_version == RTL_GIGA_MAC_VER_65 || in rtl_hw_start_8125_common()
3733 tp->mac_version == RTL_GIGA_MAC_VER_66) in rtl_hw_start_8125_common()
3735 else if (tp->mac_version == RTL_GIGA_MAC_VER_63) in rtl_hw_start_8125_common()
3740 if (tp->mac_version == RTL_GIGA_MAC_VER_63) in rtl_hw_start_8125_common()
3751 if (tp->mac_version == RTL_GIGA_MAC_VER_65 || in rtl_hw_start_8125_common()
3752 tp->mac_version == RTL_GIGA_MAC_VER_66) in rtl_hw_start_8125_common()
3770 if (tp->mac_version == RTL_GIGA_MAC_VER_61) in rtl_hw_start_8125_common()
3869 if (hw_configs[tp->mac_version]) in rtl_hw_config()
3870 hw_configs[tp->mac_version](tp); in rtl_hw_config()
3880 switch (tp->mac_version) { in rtl_hw_start_8125()
3916 tp->cp_cmd |= PCIMulRW; in rtl_hw_start_8169()
3918 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || in rtl_hw_start_8169()
3919 tp->mac_version == RTL_GIGA_MAC_VER_03) in rtl_hw_start_8169()
3920 tp->cp_cmd |= EnAnaPLL; in rtl_hw_start_8169()
3922 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start_8169()
3935 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start()
3939 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_hw_start()
3954 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ in rtl_hw_start()
3960 rtl_set_rx_config_features(tp, tp->dev->features); in rtl_hw_start()
3961 rtl_set_rx_mode(tp->dev); in rtl_hw_start()
3969 WRITE_ONCE(dev->mtu, new_mtu); in rtl8169_change_mtu()
3979 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; in rtl8169_mark_to_asic()
3981 desc->opts2 = 0; in rtl8169_mark_to_asic()
3984 WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); in rtl8169_mark_to_asic()
4001 netdev_err(tp->dev, "Failed to map RX DMA!\n"); in rtl8169_alloc_rx_data()
4006 desc->addr = cpu_to_le64(mapping); in rtl8169_alloc_rx_data()
4016 for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { in rtl8169_rx_clear()
4018 le64_to_cpu(tp->RxDescArray[i].addr), in rtl8169_rx_clear()
4020 __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); in rtl8169_rx_clear()
4021 tp->Rx_databuff[i] = NULL; in rtl8169_rx_clear()
4022 tp->RxDescArray[i].addr = 0; in rtl8169_rx_clear()
4023 tp->RxDescArray[i].opts1 = 0; in rtl8169_rx_clear()
4034 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); in rtl8169_rx_fill()
4037 return -ENOMEM; in rtl8169_rx_fill()
4039 tp->Rx_databuff[i] = data; in rtl8169_rx_fill()
4043 tp->RxDescArray[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); in rtl8169_rx_fill()
4052 memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); in rtl8169_init_ring()
4053 memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); in rtl8169_init_ring()
4060 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_unmap_tx_skb()
4061 struct TxDesc *desc = tp->TxDescArray + entry; in rtl8169_unmap_tx_skb()
4063 dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), tx_skb->len, in rtl8169_unmap_tx_skb()
4076 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_tx_clear_range()
4077 unsigned int len = tx_skb->len; in rtl8169_tx_clear_range()
4080 struct sk_buff *skb = tx_skb->skb; in rtl8169_tx_clear_range()
4091 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); in rtl8169_tx_clear()
4092 netdev_reset_queue(tp->dev); in rtl8169_tx_clear()
4097 napi_disable(&tp->napi); in rtl8169_cleanup()
4107 switch (tp->mac_version) { in rtl8169_cleanup()
4136 netif_stop_queue(tp->dev); in rtl_reset_work()
4141 rtl8169_mark_to_asic(tp->RxDescArray + i); in rtl_reset_work()
4143 napi_enable(&tp->napi); in rtl_reset_work()
4157 struct TxDesc *txd = tp->TxDescArray + entry; in rtl8169_tx_map()
4167 netdev_err(tp->dev, "Failed to map TX data!\n"); in rtl8169_tx_map()
4171 txd->addr = cpu_to_le64(mapping); in rtl8169_tx_map()
4172 txd->opts2 = cpu_to_le32(opts[1]); in rtl8169_tx_map()
4175 if (entry == NUM_TX_DESC - 1) in rtl8169_tx_map()
4179 txd->opts1 = cpu_to_le32(opts1); in rtl8169_tx_map()
4181 tp->tx_skb[entry].len = len; in rtl8169_tx_map()
4192 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { in rtl8169_xmit_frags()
4193 const skb_frag_t *frag = info->frags + cur_frag; in rtl8169_xmit_frags()
4206 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); in rtl8169_xmit_frags()
4207 return -EIO; in rtl8169_xmit_frags()
4219 return ih && ih->protocol == IPPROTO_UDP; in rtl_skb_is_udp()
4222 return i6h && i6h->nexthdr == IPPROTO_UDP; in rtl_skb_is_udp()
4234 unsigned int padto = 0, len = skb->len; in rtl8125_quirk_udp_padto()
4238 unsigned int trans_data_len = skb_tail_pointer(skb) - in rtl8125_quirk_udp_padto()
4243 u16 dest = ntohs(udp_hdr(skb)->dest); in rtl8125_quirk_udp_padto()
4247 padto = len + RTL_MIN_PATCH_LEN - trans_data_len; in rtl8125_quirk_udp_padto()
4252 len + sizeof(struct udphdr) - trans_data_len); in rtl8125_quirk_udp_padto()
4265 switch (tp->mac_version) { in rtl_quirk_packet_padto()
4279 u32 mss = skb_shinfo(skb)->gso_size; in rtl8169_tso_csum_v1()
4284 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v1()
4287 if (ip->protocol == IPPROTO_TCP) in rtl8169_tso_csum_v1()
4289 else if (ip->protocol == IPPROTO_UDP) in rtl8169_tso_csum_v1()
4300 u32 mss = shinfo->gso_size; in rtl8169_tso_csum_v2()
4303 if (shinfo->gso_type & SKB_GSO_TCPV4) { in rtl8169_tso_csum_v2()
4305 } else if (shinfo->gso_type & SKB_GSO_TCPV6) { in rtl8169_tso_csum_v2()
4317 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v2()
4323 ip_protocol = ip_hdr(skb)->protocol; in rtl8169_tso_csum_v2()
4328 ip_protocol = ipv6_hdr(skb)->nexthdr; in rtl8169_tso_csum_v2()
4356 return READ_ONCE(tp->dirty_tx) + NUM_TX_DESC - READ_ONCE(tp->cur_tx); in rtl_tx_slots_avail()
4362 switch (tp->mac_version) { in rtl_chip_supports_csum_v2()
4383 unsigned int entry = tp->cur_tx % NUM_TX_DESC; in rtl8169_start_xmit()
4404 if (unlikely(rtl8169_tx_map(tp, opts, skb_headlen(skb), skb->data, in rtl8169_start_xmit()
4408 txd_first = tp->TxDescArray + entry; in rtl8169_start_xmit()
4410 frags = skb_shinfo(skb)->nr_frags; in rtl8169_start_xmit()
4417 txd_last = tp->TxDescArray + entry; in rtl8169_start_xmit()
4418 txd_last->opts1 |= cpu_to_le32(LastFrag); in rtl8169_start_xmit()
4419 tp->tx_skb[entry].skb = skb; in rtl8169_start_xmit()
4426 door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more()); in rtl8169_start_xmit()
4428 txd_first->opts1 |= cpu_to_le32(DescOwn | FirstFrag); in rtl8169_start_xmit()
4430 /* rtl_tx needs to see descriptor changes before updated tp->cur_tx */ in rtl8169_start_xmit()
4433 WRITE_ONCE(tp->cur_tx, tp->cur_tx + frags + 1); in rtl8169_start_xmit()
4447 dev->stats.tx_dropped++; in rtl8169_start_xmit()
4454 unsigned int nr_frags = info->nr_frags; in rtl_last_frag_len()
4459 return skb_frag_size(info->frags + nr_frags - 1); in rtl_last_frag_len()
4472 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 && in rtl8168evl_fix_tso()
4489 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl8169_features_check()
4495 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_features_check()
4497 if (skb->len < ETH_ZLEN) in rtl8169_features_check()
4514 struct pci_dev *pdev = tp->pci_dev; in rtl8169_pcierr_interrupt()
4535 dirty_tx = tp->dirty_tx; in rtl_tx()
4537 while (READ_ONCE(tp->cur_tx) != dirty_tx) { in rtl_tx()
4541 status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1)); in rtl_tx()
4545 skb = tp->tx_skb[entry].skb; in rtl_tx()
4550 bytes_compl += skb->len; in rtl_tx()
4556 if (tp->dirty_tx != dirty_tx) { in rtl_tx()
4558 WRITE_ONCE(tp->dirty_tx, dirty_tx); in rtl_tx()
4567 * it is slow enough). -- FR in rtl_tx()
4571 if (READ_ONCE(tp->cur_tx) != dirty_tx && skb) in rtl_tx()
4586 skb->ip_summed = CHECKSUM_UNNECESSARY; in rtl8169_rx_csum()
4596 for (count = 0; count < budget; count++, tp->cur_rx++) { in rtl_rx()
4597 unsigned int pkt_size, entry = tp->cur_rx % NUM_RX_DESC; in rtl_rx()
4598 struct RxDesc *desc = tp->RxDescArray + entry; in rtl_rx()
4604 status = le32_to_cpu(READ_ONCE(desc->opts1)); in rtl_rx()
4618 dev->stats.rx_errors++; in rtl_rx()
4620 dev->stats.rx_length_errors++; in rtl_rx()
4622 dev->stats.rx_crc_errors++; in rtl_rx()
4624 if (!(dev->features & NETIF_F_RXALL)) in rtl_rx()
4631 if (likely(!(dev->features & NETIF_F_RXFCS))) in rtl_rx()
4632 pkt_size -= ETH_FCS_LEN; in rtl_rx()
4635 * They are seen as a symptom of over-mtu sized frames. in rtl_rx()
4638 dev->stats.rx_dropped++; in rtl_rx()
4639 dev->stats.rx_length_errors++; in rtl_rx()
4643 skb = napi_alloc_skb(&tp->napi, pkt_size); in rtl_rx()
4645 dev->stats.rx_dropped++; in rtl_rx()
4649 addr = le64_to_cpu(desc->addr); in rtl_rx()
4650 rx_buf = page_address(tp->Rx_databuff[entry]); in rtl_rx()
4655 skb->tail += pkt_size; in rtl_rx()
4656 skb->len = pkt_size; in rtl_rx()
4660 skb->protocol = eth_type_trans(skb, dev); in rtl_rx()
4664 if (skb->pkt_type == PACKET_MULTICAST) in rtl_rx()
4665 dev->stats.multicast++; in rtl_rx()
4667 napi_gro_receive(&tp->napi, skb); in rtl_rx()
4682 if ((status & 0xffff) == 0xffff || !(status & tp->irq_mask)) in rtl8169_interrupt()
4687 tp->mac_version <= RTL_GIGA_MAC_VER_06)) { in rtl8169_interrupt()
4688 rtl8169_pcierr_interrupt(tp->dev); in rtl8169_interrupt()
4693 phy_mac_interrupt(tp->phydev); in rtl8169_interrupt()
4696 tp->mac_version == RTL_GIGA_MAC_VER_11)) { in rtl8169_interrupt()
4697 netif_stop_queue(tp->dev); in rtl8169_interrupt()
4702 napi_schedule(&tp->napi); in rtl8169_interrupt()
4717 if (!test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) in rtl_task()
4720 if (test_and_clear_bit(RTL_FLAG_TASK_TX_TIMEOUT, tp->wk.flags)) { in rtl_task()
4723 ret = pci_reset_bus(tp->pci_dev); in rtl_task()
4725 netdev_err(tp->dev, "Can't reset secondary PCI bus, detach NIC\n"); in rtl_task()
4726 netif_device_detach(tp->dev); in rtl_task()
4732 ret = pci_disable_link_state(tp->pci_dev, PCIE_LINK_STATE_L1 | in rtl_task()
4735 netdev_warn_once(tp->dev, "ASPM disabled on Tx timeout\n"); in rtl_task()
4739 if (test_and_clear_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags)) { in rtl_task()
4742 netif_wake_queue(tp->dev); in rtl_task()
4743 } else if (test_and_clear_bit(RTL_FLAG_TASK_RESET_NO_QUEUE_WAKE, tp->wk.flags)) { in rtl_task()
4753 struct net_device *dev = tp->dev; in rtl8169_poll()
4774 netif_wake_queue(tp->dev); in r8169_phylink_handler()
4776 /* In few cases rx is broken after link-down otherwise */ in r8169_phylink_handler()
4782 phy_print_status(tp->phydev); in r8169_phylink_handler()
4787 struct phy_device *phydev = tp->phydev; in r8169_phy_connect()
4791 phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : in r8169_phy_connect()
4794 ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, in r8169_phy_connect()
4799 if (!tp->supports_gmii) in r8169_phy_connect()
4810 bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); in rtl8169_down()
4812 phy_stop(tp->phydev); in rtl8169_down()
4816 pci_clear_master(tp->pci_dev); in rtl8169_down()
4823 if (tp->dash_type != RTL_DASH_NONE) in rtl8169_down()
4829 if (tp->dash_type != RTL_DASH_NONE) in rtl8169_up()
4832 pci_set_master(tp->pci_dev); in rtl8169_up()
4833 phy_init_hw(tp->phydev); in rtl8169_up()
4834 phy_resume(tp->phydev); in rtl8169_up()
4836 napi_enable(&tp->napi); in rtl8169_up()
4837 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); in rtl8169_up()
4840 phy_start(tp->phydev); in rtl8169_up()
4846 struct pci_dev *pdev = tp->pci_dev; in rtl8169_close()
4848 pm_runtime_get_sync(&pdev->dev); in rtl8169_close()
4854 cancel_work(&tp->wk.work); in rtl8169_close()
4856 free_irq(tp->irq, tp); in rtl8169_close()
4858 phy_disconnect(tp->phydev); in rtl8169_close()
4860 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, in rtl8169_close()
4861 tp->RxPhyAddr); in rtl8169_close()
4862 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, in rtl8169_close()
4863 tp->TxPhyAddr); in rtl8169_close()
4864 tp->TxDescArray = NULL; in rtl8169_close()
4865 tp->RxDescArray = NULL; in rtl8169_close()
4867 pm_runtime_put_sync(&pdev->dev); in rtl8169_close()
4877 rtl8169_interrupt(tp->irq, tp); in rtl8169_netpoll()
4884 struct pci_dev *pdev = tp->pci_dev; in rtl_open()
4886 int retval = -ENOMEM; in rtl_open()
4888 pm_runtime_get_sync(&pdev->dev); in rtl_open()
4894 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, in rtl_open()
4895 &tp->TxPhyAddr, GFP_KERNEL); in rtl_open()
4896 if (!tp->TxDescArray) in rtl_open()
4899 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, in rtl_open()
4900 &tp->RxPhyAddr, GFP_KERNEL); in rtl_open()
4901 if (!tp->RxDescArray) in rtl_open()
4911 retval = request_irq(tp->irq, rtl8169_interrupt, irqflags, dev->name, tp); in rtl_open()
4923 pm_runtime_put_sync(&pdev->dev); in rtl_open()
4928 free_irq(tp->irq, tp); in rtl_open()
4933 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, in rtl_open()
4934 tp->RxPhyAddr); in rtl_open()
4935 tp->RxDescArray = NULL; in rtl_open()
4937 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, in rtl_open()
4938 tp->TxPhyAddr); in rtl_open()
4939 tp->TxDescArray = NULL; in rtl_open()
4947 struct pci_dev *pdev = tp->pci_dev; in rtl8169_get_stats64()
4948 struct rtl8169_counters *counters = tp->counters; in rtl8169_get_stats64()
4950 pm_runtime_get_noresume(&pdev->dev); in rtl8169_get_stats64()
4952 netdev_stats_to_stats64(stats, &dev->stats); in rtl8169_get_stats64()
4953 dev_fetch_sw_netstats(stats, dev->tstats); in rtl8169_get_stats64()
4959 if (pm_runtime_active(&pdev->dev)) in rtl8169_get_stats64()
4966 stats->tx_errors = le64_to_cpu(counters->tx_errors) - in rtl8169_get_stats64()
4967 le64_to_cpu(tp->tc_offset.tx_errors); in rtl8169_get_stats64()
4968 stats->collisions = le32_to_cpu(counters->tx_multi_collision) - in rtl8169_get_stats64()
4969 le32_to_cpu(tp->tc_offset.tx_multi_collision); in rtl8169_get_stats64()
4970 stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - in rtl8169_get_stats64()
4971 le16_to_cpu(tp->tc_offset.tx_aborted); in rtl8169_get_stats64()
4972 stats->rx_missed_errors = le16_to_cpu(counters->rx_missed) - in rtl8169_get_stats64()
4973 le16_to_cpu(tp->tc_offset.rx_missed); in rtl8169_get_stats64()
4975 pm_runtime_put_noidle(&pdev->dev); in rtl8169_get_stats64()
4980 netif_device_detach(tp->dev); in rtl8169_net_suspend()
4982 if (netif_running(tp->dev)) in rtl8169_net_suspend()
4990 rtl_rar_set(tp, tp->dev->dev_addr); in rtl8169_runtime_resume()
4991 __rtl8169_set_wol(tp, tp->saved_wolopts); in rtl8169_runtime_resume()
4993 if (tp->TxDescArray) in rtl8169_runtime_resume()
4996 netif_device_attach(tp->dev); in rtl8169_runtime_resume()
5008 clk_disable_unprepare(tp->clk); in rtl8169_suspend()
5019 clk_prepare_enable(tp->clk); in rtl8169_resume()
5022 if (tp->mac_version == RTL_GIGA_MAC_VER_37) in rtl8169_resume()
5032 if (!tp->TxDescArray) { in rtl8169_runtime_suspend()
5033 netif_device_detach(tp->dev); in rtl8169_runtime_suspend()
5049 if (tp->dash_enabled) in rtl8169_runtime_idle()
5050 return -EBUSY; in rtl8169_runtime_idle()
5052 if (!netif_running(tp->dev) || !netif_carrier_ok(tp->dev)) in rtl8169_runtime_idle()
5055 return -EBUSY; in rtl8169_runtime_idle()
5072 /* Restore original MAC address */ in rtl_shutdown()
5073 rtl_rar_set(tp, tp->dev->perm_addr); in rtl_shutdown()
5075 if (system_state == SYSTEM_POWER_OFF && !tp->dash_enabled) { in rtl_shutdown()
5076 pci_wake_from_d3(pdev, tp->saved_wolopts); in rtl_shutdown()
5086 pm_runtime_get_noresume(&pdev->dev); in rtl_remove_one()
5088 cancel_work_sync(&tp->wk.work); in rtl_remove_one()
5091 r8169_remove_leds(tp->leds); in rtl_remove_one()
5093 unregister_netdev(tp->dev); in rtl_remove_one()
5095 if (tp->dash_type != RTL_DASH_NONE) in rtl_remove_one()
5100 /* restore original MAC address */ in rtl_remove_one()
5101 rtl_rar_set(tp, tp->dev->perm_addr); in rtl_remove_one()
5126 tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg; in rtl_set_irq_mask()
5128 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_set_irq_mask()
5129 tp->irq_mask |= SYSErr | RxFIFOOver; in rtl_set_irq_mask()
5130 else if (tp->mac_version == RTL_GIGA_MAC_VER_11) in rtl_set_irq_mask()
5132 tp->irq_mask |= RxFIFOOver; in rtl_set_irq_mask()
5139 switch (tp->mac_version) { in rtl_alloc_irq()
5153 return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); in rtl_alloc_irq()
5160 if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) { in rtl_read_mac_address()
5184 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_read_reg()
5187 return -ENODEV; in r8169_mdio_read_reg()
5195 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_write_reg()
5198 return -ENODEV; in r8169_mdio_write_reg()
5207 struct pci_dev *pdev = tp->pci_dev; in r8169_mdio_register()
5216 if (tp->mac_version == RTL_GIGA_MAC_VER_25 || in r8169_mdio_register()
5217 tp->mac_version == RTL_GIGA_MAC_VER_26) in r8169_mdio_register()
5220 new_bus = devm_mdiobus_alloc(&pdev->dev); in r8169_mdio_register()
5222 return -ENOMEM; in r8169_mdio_register()
5224 new_bus->name = "r8169"; in r8169_mdio_register()
5225 new_bus->priv = tp; in r8169_mdio_register()
5226 new_bus->parent = &pdev->dev; in r8169_mdio_register()
5227 new_bus->irq[0] = PHY_MAC_INTERRUPT; in r8169_mdio_register()
5228 snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x-%x", in r8169_mdio_register()
5229 pci_domain_nr(pdev->bus), pci_dev_id(pdev)); in r8169_mdio_register()
5231 new_bus->read = r8169_mdio_read_reg; in r8169_mdio_register()
5232 new_bus->write = r8169_mdio_write_reg; in r8169_mdio_register()
5234 ret = devm_mdiobus_register(&pdev->dev, new_bus); in r8169_mdio_register()
5238 tp->phydev = mdiobus_get_phy(new_bus, 0); in r8169_mdio_register()
5239 if (!tp->phydev) { in r8169_mdio_register()
5240 return -ENODEV; in r8169_mdio_register()
5241 } else if (!tp->phydev->drv) { in r8169_mdio_register()
5245 …dev_err(&pdev->dev, "no dedicated PHY driver found for PHY ID 0x%08x, maybe realtek.ko needs to be… in r8169_mdio_register()
5246 tp->phydev->phy_id); in r8169_mdio_register()
5247 return -EUNATCH; in r8169_mdio_register()
5250 tp->phydev->mac_managed_pm = true; in r8169_mdio_register()
5252 phy_support_eee(tp->phydev); in r8169_mdio_register()
5253 phy_support_asym_pause(tp->phydev); in r8169_mdio_register()
5256 phy_suspend(tp->phydev); in r8169_mdio_register()
5295 switch (tp->mac_version) { in rtl_hw_initialize()
5312 /* Non-GBit versions don't support jumbo frames */ in rtl_jumbo_max()
5313 if (!tp->supports_gmii) in rtl_jumbo_max()
5316 switch (tp->mac_version) { in rtl_jumbo_max()
5335 struct net_device *dev = tp->dev; in rtl_init_mac_address()
5351 dev->addr_assign_type = NET_ADDR_RANDOM; in rtl_init_mac_address()
5361 if (tp->mac_version >= RTL_GIGA_MAC_VER_61 && in rtl_aspm_is_safe()
5377 dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); in rtl_init_one()
5379 return -ENOMEM; in rtl_init_one()
5381 SET_NETDEV_DEV(dev, &pdev->dev); in rtl_init_one()
5382 dev->netdev_ops = &rtl_netdev_ops; in rtl_init_one()
5384 tp->dev = dev; in rtl_init_one()
5385 tp->pci_dev = pdev; in rtl_init_one()
5386 tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1; in rtl_init_one()
5387 tp->ocp_base = OCP_STD_PHY_BASE; in rtl_init_one()
5389 raw_spin_lock_init(&tp->cfg9346_usage_lock); in rtl_init_one()
5390 raw_spin_lock_init(&tp->config25_lock); in rtl_init_one()
5391 raw_spin_lock_init(&tp->mac_ocp_lock); in rtl_init_one()
5392 mutex_init(&tp->led_lock); in rtl_init_one()
5395 tp->clk = devm_clk_get_optional_enabled(&pdev->dev, "ether_clk"); in rtl_init_one()
5396 if (IS_ERR(tp->clk)) in rtl_init_one()
5397 return dev_err_probe(&pdev->dev, PTR_ERR(tp->clk), "failed to get ether_clk\n"); in rtl_init_one()
5402 return dev_err_probe(&pdev->dev, rc, "enable failure\n"); in rtl_init_one()
5405 dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); in rtl_init_one()
5408 region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; in rtl_init_one()
5410 return dev_err_probe(&pdev->dev, -ENODEV, "no MMIO resource found\n"); in rtl_init_one()
5414 return dev_err_probe(&pdev->dev, rc, "cannot remap MMIO, aborting\n"); in rtl_init_one()
5416 tp->mmio_addr = pcim_iomap_table(pdev)[region]; in rtl_init_one()
5420 return dev_err_probe(&pdev->dev, -EIO, "PCI read failed\n"); in rtl_init_one()
5425 chipset = rtl8169_get_mac_version(xid, tp->supports_gmii); in rtl_init_one()
5427 return dev_err_probe(&pdev->dev, -ENODEV, in rtl_init_one()
5430 tp->mac_version = chipset; in rtl_init_one()
5439 tp->aspm_manageable = !rc; in rtl_init_one()
5441 tp->dash_type = rtl_get_dash_type(tp); in rtl_init_one()
5442 tp->dash_enabled = rtl_dash_is_enabled(tp); in rtl_init_one()
5444 tp->cp_cmd = RTL_R16(tp, CPlusCmd) & CPCMD_MASK; in rtl_init_one()
5446 if (sizeof(dma_addr_t) > 4 && tp->mac_version >= RTL_GIGA_MAC_VER_18 && in rtl_init_one()
5447 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) in rtl_init_one()
5448 dev->features |= NETIF_F_HIGHDMA; in rtl_init_one()
5460 return dev_err_probe(&pdev->dev, rc, "Can't allocate interrupt\n"); in rtl_init_one()
5462 tp->irq = pci_irq_vector(pdev, 0); in rtl_init_one()
5464 INIT_WORK(&tp->wk.work, rtl_task); in rtl_init_one()
5468 dev->ethtool_ops = &rtl8169_ethtool_ops; in rtl_init_one()
5470 netif_napi_add(dev, &tp->napi, rtl8169_poll); in rtl_init_one()
5472 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | in rtl_init_one()
5474 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; in rtl_init_one()
5475 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; in rtl_init_one()
5481 if (tp->mac_version == RTL_GIGA_MAC_VER_05) in rtl_init_one()
5483 dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; in rtl_init_one()
5486 dev->hw_features |= NETIF_F_IPV6_CSUM; in rtl_init_one()
5488 dev->features |= dev->hw_features; in rtl_init_one()
5496 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6; in rtl_init_one()
5500 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO; in rtl_init_one()
5505 dev->hw_features |= NETIF_F_RXALL; in rtl_init_one()
5506 dev->hw_features |= NETIF_F_RXFCS; in rtl_init_one()
5508 dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; in rtl_init_one()
5513 rtl8169_set_features(dev, dev->features); in rtl_init_one()
5515 if (!tp->dash_enabled) { in rtl_init_one()
5519 dev->ethtool->wol_enabled = 1; in rtl_init_one()
5524 dev->max_mtu = jumbo_max; in rtl_init_one()
5528 tp->fw_name = rtl_chip_infos[chipset].fw_name; in rtl_init_one()
5530 tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), in rtl_init_one()
5531 &tp->counters_phys_addr, in rtl_init_one()
5533 if (!tp->counters) in rtl_init_one()
5534 return -ENOMEM; in rtl_init_one()
5548 tp->leds = rtl8125_init_leds(dev); in rtl_init_one()
5549 else if (tp->mac_version > RTL_GIGA_MAC_VER_06) in rtl_init_one()
5550 tp->leds = rtl8168_init_leds(dev); in rtl_init_one()
5554 rtl_chip_infos[chipset].name, dev->dev_addr, xid, tp->irq); in rtl_init_one()
5558 jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? in rtl_init_one()
5561 if (tp->dash_type != RTL_DASH_NONE) { in rtl_init_one()
5563 tp->dash_enabled ? "enabled" : "disabled"); in rtl_init_one()
5568 pm_runtime_put_sync(&pdev->dev); in rtl_init_one()