Lines Matching +full:ecam +full:- +full:based
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"
59 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
60 The RTL chips use a 64 element hash table based on the Ethernet CRC. */
67 #define R8169_RX_BUF_SIZE (SZ_16K - 1)
80 #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg))
81 #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg))
82 #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg))
83 #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg))
84 #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg))
85 #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg))
87 #define JUMBO_4K (4 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
88 #define JUMBO_6K (6 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
89 #define JUMBO_7K (7 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
90 #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
102 /* PCI-E devices. */
189 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */
190 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */
394 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
413 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
603 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
604 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
642 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
668 return &tp->pci_dev->dev; in tp_to_dev()
675 raw_spin_lock_irqsave(&tp->cfg9346_usage_lock, flags); in rtl_lock_config_regs()
676 if (!--tp->cfg9346_usage_count) in rtl_lock_config_regs()
678 raw_spin_unlock_irqrestore(&tp->cfg9346_usage_lock, flags); in rtl_lock_config_regs()
685 raw_spin_lock_irqsave(&tp->cfg9346_usage_lock, flags); in rtl_unlock_config_regs()
686 if (!tp->cfg9346_usage_count++) in rtl_unlock_config_regs()
688 raw_spin_unlock_irqrestore(&tp->cfg9346_usage_lock, flags); in rtl_unlock_config_regs()
702 raw_spin_lock_irqsave(&tp->config25_lock, flags); in rtl_mod_config2()
705 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in rtl_mod_config2()
713 raw_spin_lock_irqsave(&tp->config25_lock, flags); in rtl_mod_config5()
716 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in rtl_mod_config5()
721 return tp->mac_version >= RTL_GIGA_MAC_VER_61; in rtl_is_8125()
726 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_is_8168evl_up()
727 tp->mac_version != RTL_GIGA_MAC_VER_39 && in rtl_is_8168evl_up()
728 tp->mac_version <= RTL_GIGA_MAC_VER_53; in rtl_is_8168evl_up()
733 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_supports_eee()
734 tp->mac_version != RTL_GIGA_MAC_VER_37 && in rtl_supports_eee()
735 tp->mac_version != RTL_GIGA_MAC_VER_39; in rtl_supports_eee()
757 if (c->check(tp) == high) in rtl_loop_wait()
763 netdev_err(tp->dev, "%s == %d (loop: %d, delay: %lu).\n", in rtl_loop_wait()
764 c->msg, !high, n, usecs); in rtl_loop_wait()
794 /* based on RTL8168FP_OOBMAC_BASE in vendor driver */ in r8168fp_adjust_ocp_cmd()
796 (tp->mac_version == RTL_GIGA_MAC_VER_52 || in r8168fp_adjust_ocp_cmd()
797 tp->mac_version == RTL_GIGA_MAC_VER_53)) in r8168fp_adjust_ocp_cmd()
888 (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT; in r8168_phy_ocp_read()
903 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
905 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
923 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
925 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
936 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
939 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
943 * PHY MCU interrupts before PHY power-down.
947 switch (tp->mac_version) { in rtl8168g_phy_suspend_quirk()
962 tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; in r8168g_mdio_write()
966 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_write()
967 reg -= 0x10; in r8168g_mdio_write()
969 if (tp->ocp_base == OCP_STD_PHY_BASE && reg == MII_BMCR) in r8168g_mdio_write()
972 r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); in r8168g_mdio_write()
978 return tp->ocp_base == OCP_STD_PHY_BASE ? 0 : tp->ocp_base >> 4; in r8168g_mdio_read()
980 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_read()
981 reg -= 0x10; in r8168g_mdio_read()
983 return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); in r8168g_mdio_read()
989 tp->ocp_base = value << 4; in mac_mcu_write()
993 r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); in mac_mcu_write()
998 return r8168_mac_ocp_read(tp, tp->ocp_base + reg); in mac_mcu_read()
1025 RTL_R32(tp, PHYAR) & 0xffff : -ETIMEDOUT; in r8169_mdio_read()
1081 switch (tp->mac_version) { in rtl_writephy()
1097 switch (tp->mac_version) { in rtl_readphy()
1171 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; in rtl8168_get_ocp_reg()
1216 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_start()
1238 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_stop()
1258 switch (tp->mac_version) { in rtl_check_dash()
1271 switch (tp->mac_version) { in rtl_set_d3_pll_down()
1332 RTL_W32(tp, IntrMask_8125, tp->irq_mask); in rtl_irq_enable()
1334 RTL_W16(tp, IntrMask, tp->irq_mask); in rtl_irq_enable()
1346 struct phy_device *phydev = tp->phydev; in rtl_link_chg_patch()
1348 if (tp->mac_version == RTL_GIGA_MAC_VER_34 || in rtl_link_chg_patch()
1349 tp->mac_version == RTL_GIGA_MAC_VER_38) { in rtl_link_chg_patch()
1350 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1353 } else if (phydev->speed == SPEED_100) { in rtl_link_chg_patch()
1361 } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || in rtl_link_chg_patch()
1362 tp->mac_version == RTL_GIGA_MAC_VER_36) { in rtl_link_chg_patch()
1363 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1370 } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { in rtl_link_chg_patch()
1371 if (phydev->speed == SPEED_10) { in rtl_link_chg_patch()
1386 wol->supported = WAKE_ANY; in rtl8169_get_wol()
1387 wol->wolopts = tp->saved_wolopts; in rtl8169_get_wol()
1411 tmp--; in __rtl8169_set_wol()
1417 tmp--; in __rtl8169_set_wol()
1424 raw_spin_lock_irqsave(&tp->config25_lock, flags); in __rtl8169_set_wol()
1431 raw_spin_unlock_irqrestore(&tp->config25_lock, flags); in __rtl8169_set_wol()
1433 switch (tp->mac_version) { in __rtl8169_set_wol()
1456 if (tp->dash_type == RTL_DASH_NONE) { in __rtl8169_set_wol()
1458 tp->dev->wol_enabled = wolopts ? 1 : 0; in __rtl8169_set_wol()
1466 if (wol->wolopts & ~WAKE_ANY) in rtl8169_set_wol()
1467 return -EINVAL; in rtl8169_set_wol()
1469 tp->saved_wolopts = wol->wolopts; in rtl8169_set_wol()
1470 __rtl8169_set_wol(tp, tp->saved_wolopts); in rtl8169_set_wol()
1479 struct rtl_fw *rtl_fw = tp->rtl_fw; in rtl8169_get_drvinfo()
1481 strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); in rtl8169_get_drvinfo()
1482 strscpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); in rtl8169_get_drvinfo()
1483 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); in rtl8169_get_drvinfo()
1485 strscpy(info->fw_version, rtl_fw->version, in rtl8169_get_drvinfo()
1486 sizeof(info->fw_version)); in rtl8169_get_drvinfo()
1499 if (dev->mtu > TD_MSS_MAX) in rtl8169_fix_features()
1502 if (dev->mtu > ETH_DATA_LEN && in rtl8169_fix_features()
1503 tp->mac_version > RTL_GIGA_MAC_VER_06) in rtl8169_fix_features()
1537 tp->cp_cmd |= RxChkSum; in rtl8169_set_features()
1539 tp->cp_cmd &= ~RxChkSum; in rtl8169_set_features()
1543 tp->cp_cmd |= RxVlan; in rtl8169_set_features()
1545 tp->cp_cmd &= ~RxVlan; in rtl8169_set_features()
1548 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl8169_set_features()
1562 u32 opts2 = le32_to_cpu(desc->opts2); in rtl8169_rx_vlan_tag()
1572 u32 __iomem *data = tp->mmio_addr; in rtl8169_get_regs()
1602 return -EOPNOTSUPP; in rtl8169_get_sset_count()
1613 u32 cmd = lower_32_bits(tp->counters_phys_addr); in rtl8169_do_counters()
1615 RTL_W32(tp, CounterAddrHigh, upper_32_bits(tp->counters_phys_addr)); in rtl8169_do_counters()
1629 * is disabled. If 0xff chip may be in a PCI power-save state. in rtl8169_update_counters()
1637 struct rtl8169_counters *counters = tp->counters; in rtl8169_init_counter_offsets()
1654 if (tp->tc_offset.inited) in rtl8169_init_counter_offsets()
1657 if (tp->mac_version >= RTL_GIGA_MAC_VER_19) { in rtl8169_init_counter_offsets()
1661 tp->tc_offset.tx_errors = counters->tx_errors; in rtl8169_init_counter_offsets()
1662 tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; in rtl8169_init_counter_offsets()
1663 tp->tc_offset.tx_aborted = counters->tx_aborted; in rtl8169_init_counter_offsets()
1664 tp->tc_offset.rx_missed = counters->rx_missed; in rtl8169_init_counter_offsets()
1667 tp->tc_offset.inited = true; in rtl8169_init_counter_offsets()
1676 counters = tp->counters; in rtl8169_get_ethtool_stats()
1679 data[0] = le64_to_cpu(counters->tx_packets); in rtl8169_get_ethtool_stats()
1680 data[1] = le64_to_cpu(counters->rx_packets); in rtl8169_get_ethtool_stats()
1681 data[2] = le64_to_cpu(counters->tx_errors); in rtl8169_get_ethtool_stats()
1682 data[3] = le32_to_cpu(counters->rx_errors); in rtl8169_get_ethtool_stats()
1683 data[4] = le16_to_cpu(counters->rx_missed); in rtl8169_get_ethtool_stats()
1684 data[5] = le16_to_cpu(counters->align_errors); in rtl8169_get_ethtool_stats()
1685 data[6] = le32_to_cpu(counters->tx_one_collision); in rtl8169_get_ethtool_stats()
1686 data[7] = le32_to_cpu(counters->tx_multi_collision); in rtl8169_get_ethtool_stats()
1687 data[8] = le64_to_cpu(counters->rx_unicast); in rtl8169_get_ethtool_stats()
1688 data[9] = le64_to_cpu(counters->rx_broadcast); in rtl8169_get_ethtool_stats()
1689 data[10] = le32_to_cpu(counters->rx_multicast); in rtl8169_get_ethtool_stats()
1690 data[11] = le16_to_cpu(counters->tx_aborted); in rtl8169_get_ethtool_stats()
1691 data[12] = le16_to_cpu(counters->tx_underun); in rtl8169_get_ethtool_stats()
1706 * > 1 - the availability of the IntrMitigate (0xe2) register through the
1711 * > 2 - the Tx timer unit at gigabit speed
1761 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_coalesce_info()
1767 if (tp->phydev->speed == SPEED_UNKNOWN) in rtl_coalesce_info()
1770 for (; ci->speed; ci++) { in rtl_coalesce_info()
1771 if (tp->phydev->speed == ci->speed) in rtl_coalesce_info()
1775 return ERR_PTR(-ELNRNG); in rtl_coalesce_info()
1789 return -EOPNOTSUPP; in rtl_get_coalesce()
1798 scale = ci->scale_nsecs[tp->cp_cmd & INTT_MASK]; in rtl_get_coalesce()
1803 ec->tx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1807 ec->tx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
1810 ec->rx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1813 ec->rx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
1830 if (usec <= ci->scale_nsecs[i] * RTL_COALESCE_T_MAX / 1000U) { in rtl_coalesce_choose_scale()
1832 return ci->scale_nsecs[i]; in rtl_coalesce_choose_scale()
1836 return -ERANGE; in rtl_coalesce_choose_scale()
1845 u32 tx_fr = ec->tx_max_coalesced_frames; in rtl_set_coalesce()
1846 u32 rx_fr = ec->rx_max_coalesced_frames; in rtl_set_coalesce()
1852 return -EOPNOTSUPP; in rtl_set_coalesce()
1855 return -ERANGE; in rtl_set_coalesce()
1857 coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs); in rtl_set_coalesce()
1865 * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) in rtl_set_coalesce()
1866 * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 in rtl_set_coalesce()
1867 * - then user does `ethtool -C eth0 rx-usecs 100` in rtl_set_coalesce()
1878 if ((tx_fr && !ec->tx_coalesce_usecs) || in rtl_set_coalesce()
1879 (rx_fr && !ec->rx_coalesce_usecs)) in rtl_set_coalesce()
1880 return -EINVAL; in rtl_set_coalesce()
1885 units = DIV_ROUND_UP(ec->tx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
1887 units = DIV_ROUND_UP(ec->rx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
1892 /* Meaning of PktCntrDisable bit changed from RTL8168e-vl */ in rtl_set_coalesce()
1896 tp->cp_cmd |= PktCntrDisable; in rtl_set_coalesce()
1898 tp->cp_cmd &= ~PktCntrDisable; in rtl_set_coalesce()
1901 tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; in rtl_set_coalesce()
1902 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_set_coalesce()
1913 return -EOPNOTSUPP; in rtl8169_get_eee()
1915 return phy_ethtool_get_eee(tp->phydev, data); in rtl8169_get_eee()
1924 return -EOPNOTSUPP; in rtl8169_set_eee()
1926 ret = phy_ethtool_set_eee(tp->phydev, data); in rtl8169_set_eee()
1929 tp->eee_adv = phy_read_mmd(dev->phydev, MDIO_MMD_AN, in rtl8169_set_eee()
1939 data->rx_max_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
1940 data->rx_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
1941 data->tx_max_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
1942 data->tx_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
1951 phy_get_pause(tp->phydev, &tx_pause, &rx_pause); in rtl8169_get_pauseparam()
1953 data->autoneg = tp->phydev->autoneg; in rtl8169_get_pauseparam()
1954 data->tx_pause = tx_pause ? 1 : 0; in rtl8169_get_pauseparam()
1955 data->rx_pause = rx_pause ? 1 : 0; in rtl8169_get_pauseparam()
1963 if (dev->mtu > ETH_DATA_LEN) in rtl8169_set_pauseparam()
1964 return -EOPNOTSUPP; in rtl8169_set_pauseparam()
1966 phy_set_asym_pause(tp->phydev, data->rx_pause, data->tx_pause); in rtl8169_set_pauseparam()
1998 struct phy_device *phydev = tp->phydev; in rtl_enable_eee()
2002 if (tp->eee_adv >= 0) in rtl_enable_eee()
2003 adv = tp->eee_adv; in rtl_enable_eee()
2123 /* Catch-all */ in rtl8169_get_mac_version()
2129 while ((xid & p->mask) != p->val) in rtl8169_get_mac_version()
2131 ver = p->ver; in rtl8169_get_mac_version()
2145 if (tp->rtl_fw) { in rtl_release_firmware()
2146 rtl_fw_release_firmware(tp->rtl_fw); in rtl_release_firmware()
2147 kfree(tp->rtl_fw); in rtl_release_firmware()
2148 tp->rtl_fw = NULL; in rtl_release_firmware()
2157 if (tp->rtl_fw) { in r8169_apply_firmware()
2158 rtl_fw_write_firmware(tp, tp->rtl_fw); in r8169_apply_firmware()
2159 /* At least one firmware doesn't reset tp->ocp_base. */ in r8169_apply_firmware()
2160 tp->ocp_base = OCP_STD_PHY_BASE; in r8169_apply_firmware()
2163 phy_read_poll_timeout(tp->phydev, MII_BMCR, val, in r8169_apply_firmware()
2172 if (tp->mac_version != RTL_GIGA_MAC_VER_38) in rtl8168_config_eee_mac()
2186 RTL_W16(tp, EEE_TXIDLE_TIMER_8125, tp->dev->mtu + ETH_HLEN + 0x20); in rtl8125_set_eee_txidle_timer()
2221 set_bit(flag, tp->wk.flags); in rtl_schedule_task()
2222 schedule_work(&tp->wk.work); in rtl_schedule_task()
2227 r8169_hw_phy_config(tp, tp->phydev, tp->mac_version); in rtl8169_init_phy()
2229 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { in rtl8169_init_phy()
2230 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); in rtl8169_init_phy()
2231 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); in rtl8169_init_phy()
2236 if (tp->mac_version == RTL_GIGA_MAC_VER_05 && in rtl8169_init_phy()
2237 tp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_GIGABYTE && in rtl8169_init_phy()
2238 tp->pci_dev->subsystem_device == 0xe000) in rtl8169_init_phy()
2239 phy_write_paged(tp->phydev, 0x0001, 0x10, 0xf01b); in rtl8169_init_phy()
2242 phy_speed_up(tp->phydev); in rtl8169_init_phy()
2247 genphy_soft_reset(tp->phydev); in rtl8169_init_phy()
2260 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl_rar_set()
2275 rtl_rar_set(tp, dev->dev_addr); in rtl_set_mac_address()
2282 switch (tp->mac_version) { in rtl_init_rxcfg()
2306 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; in rtl8169_init_ring_indexes()
2357 bool jumbo = tp->dev->mtu > ETH_DATA_LEN; in rtl_jumbo_config()
2361 switch (tp->mac_version) { in rtl_jumbo_config()
2395 if (pci_is_pcie(tp->pci_dev) && tp->supports_gmii) in rtl_jumbo_config()
2396 pcie_set_readrq(tp->pci_dev, readrq); in rtl_jumbo_config()
2401 tp->phydev->advertising); in rtl_jumbo_config()
2403 tp->phydev->advertising); in rtl_jumbo_config()
2404 phy_start_aneg(tp->phydev); in rtl_jumbo_config()
2425 if (tp->rtl_fw || !tp->fw_name) in rtl_request_firmware()
2432 rtl_fw->phy_write = rtl_writephy; in rtl_request_firmware()
2433 rtl_fw->phy_read = rtl_readphy; in rtl_request_firmware()
2434 rtl_fw->mac_mcu_write = mac_mcu_write; in rtl_request_firmware()
2435 rtl_fw->mac_mcu_read = mac_mcu_read; in rtl_request_firmware()
2436 rtl_fw->fw_name = tp->fw_name; in rtl_request_firmware()
2437 rtl_fw->dev = tp_to_dev(tp); in rtl_request_firmware()
2442 tp->rtl_fw = rtl_fw; in rtl_request_firmware()
2473 switch (tp->mac_version) { in rtl_wait_txrx_fifo_empty()
2505 if (tp->mac_version >= RTL_GIGA_MAC_VER_25) in rtl_wol_enable_rx()
2509 if (tp->mac_version >= RTL_GIGA_MAC_VER_40) in rtl_wol_enable_rx()
2515 if (tp->dash_type != RTL_DASH_NONE) in rtl_prepare_power_down()
2518 if (tp->mac_version == RTL_GIGA_MAC_VER_32 || in rtl_prepare_power_down()
2519 tp->mac_version == RTL_GIGA_MAC_VER_33) in rtl_prepare_power_down()
2523 phy_speed_down(tp->phydev, false); in rtl_prepare_power_down()
2552 RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); in rtl_set_rx_tx_desc_registers()
2553 RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); in rtl_set_rx_tx_desc_registers()
2554 RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); in rtl_set_rx_tx_desc_registers()
2555 RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); in rtl_set_rx_tx_desc_registers()
2562 if (tp->mac_version == RTL_GIGA_MAC_VER_05) in rtl8169_set_magic_reg()
2564 else if (tp->mac_version == RTL_GIGA_MAC_VER_06) in rtl8169_set_magic_reg()
2583 if (dev->flags & IFF_PROMISC) { in rtl_set_rx_mode()
2586 dev->flags & IFF_ALLMULTI || in rtl_set_rx_mode()
2587 tp->mac_version == RTL_GIGA_MAC_VER_35) { in rtl_set_rx_mode()
2600 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { in rtl_set_rx_mode()
2621 u32 func = PCI_FUNC(tp->pci_dev->devfn); in rtl_csi_write()
2632 u32 func = PCI_FUNC(tp->pci_dev->devfn); in rtl_csi_read()
2643 struct pci_dev *pdev = tp->pci_dev; in rtl_set_aspm_entry_latency()
2647 * controls the L0s/L1 entrance latency. We try standard ECAM access in rtl_set_aspm_entry_latency()
2652 if (pdev->cfg_size > 0x070f && in rtl_set_aspm_entry_latency()
2656 netdev_notice_once(tp->dev, in rtl_set_aspm_entry_latency()
2679 while (len-- > 0) { in __rtl_ephy_init()
2680 w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; in __rtl_ephy_init()
2681 rtl_ephy_write(tp, e->offset, w); in __rtl_ephy_init()
2690 pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, in rtl_disable_clock_request()
2696 pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, in rtl_enable_clock_request()
2716 switch (tp->mac_version) { in rtl_enable_exit_l1()
2733 switch (tp->mac_version) { in rtl_disable_exit_l1()
2747 if (tp->mac_version < RTL_GIGA_MAC_VER_32) in rtl_hw_aspm_clkreq_enable()
2751 if (enable && tp->aspm_manageable) { in rtl_hw_aspm_clkreq_enable()
2755 if (tp->mac_version == RTL_GIGA_MAC_VER_42 || in rtl_hw_aspm_clkreq_enable()
2756 tp->mac_version == RTL_GIGA_MAC_VER_43) in rtl_hw_aspm_clkreq_enable()
2762 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
2774 switch (tp->mac_version) { in rtl_hw_aspm_clkreq_enable()
3107 /* The following Realtek-provided magic fixes an issue with the RX unit in rtl_hw_start_8411_2()
3108 * getting confused after the PHY having been powered-down. in rtl_hw_start_8411_2()
3285 rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; in rtl_hw_start_8168h_1()
3391 rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; in rtl_hw_start_8117()
3540 /* L0 7us, L1 32us - needed to avoid issues with link-up detection */ in rtl_hw_start_8106()
3579 if (tp->mac_version == RTL_GIGA_MAC_VER_63) in rtl_hw_start_8125_common()
3584 if (tp->mac_version == RTL_GIGA_MAC_VER_63) in rtl_hw_start_8125_common()
3609 if (tp->mac_version == RTL_GIGA_MAC_VER_63) in rtl_hw_start_8125_common()
3700 if (hw_configs[tp->mac_version]) in rtl_hw_config()
3701 hw_configs[tp->mac_version](tp); in rtl_hw_config()
3732 tp->cp_cmd |= PCIMulRW; in rtl_hw_start_8169()
3734 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || in rtl_hw_start_8169()
3735 tp->mac_version == RTL_GIGA_MAC_VER_03) in rtl_hw_start_8169()
3736 tp->cp_cmd |= EnAnaPLL; in rtl_hw_start_8169()
3738 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start_8169()
3751 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start()
3753 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_hw_start()
3768 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ in rtl_hw_start()
3774 rtl_set_rx_config_features(tp, tp->dev->features); in rtl_hw_start()
3775 rtl_set_rx_mode(tp->dev); in rtl_hw_start()
3783 dev->mtu = new_mtu; in rtl8169_change_mtu()
3787 switch (tp->mac_version) { in rtl8169_change_mtu()
3801 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; in rtl8169_mark_to_asic()
3803 desc->opts2 = 0; in rtl8169_mark_to_asic()
3806 WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); in rtl8169_mark_to_asic()
3823 netdev_err(tp->dev, "Failed to map RX DMA!\n"); in rtl8169_alloc_rx_data()
3828 desc->addr = cpu_to_le64(mapping); in rtl8169_alloc_rx_data()
3838 for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { in rtl8169_rx_clear()
3840 le64_to_cpu(tp->RxDescArray[i].addr), in rtl8169_rx_clear()
3842 __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); in rtl8169_rx_clear()
3843 tp->Rx_databuff[i] = NULL; in rtl8169_rx_clear()
3844 tp->RxDescArray[i].addr = 0; in rtl8169_rx_clear()
3845 tp->RxDescArray[i].opts1 = 0; in rtl8169_rx_clear()
3856 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); in rtl8169_rx_fill()
3859 return -ENOMEM; in rtl8169_rx_fill()
3861 tp->Rx_databuff[i] = data; in rtl8169_rx_fill()
3865 tp->RxDescArray[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); in rtl8169_rx_fill()
3874 memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); in rtl8169_init_ring()
3875 memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); in rtl8169_init_ring()
3882 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_unmap_tx_skb()
3883 struct TxDesc *desc = tp->TxDescArray + entry; in rtl8169_unmap_tx_skb()
3885 dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), tx_skb->len, in rtl8169_unmap_tx_skb()
3898 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_tx_clear_range()
3899 unsigned int len = tx_skb->len; in rtl8169_tx_clear_range()
3902 struct sk_buff *skb = tx_skb->skb; in rtl8169_tx_clear_range()
3913 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); in rtl8169_tx_clear()
3914 netdev_reset_queue(tp->dev); in rtl8169_tx_clear()
3919 napi_disable(&tp->napi); in rtl8169_cleanup()
3929 switch (tp->mac_version) { in rtl8169_cleanup()
3958 netif_stop_queue(tp->dev); in rtl_reset_work()
3963 rtl8169_mark_to_asic(tp->RxDescArray + i); in rtl_reset_work()
3965 napi_enable(&tp->napi); in rtl_reset_work()
3979 struct TxDesc *txd = tp->TxDescArray + entry; in rtl8169_tx_map()
3989 netdev_err(tp->dev, "Failed to map TX data!\n"); in rtl8169_tx_map()
3993 txd->addr = cpu_to_le64(mapping); in rtl8169_tx_map()
3994 txd->opts2 = cpu_to_le32(opts[1]); in rtl8169_tx_map()
3997 if (entry == NUM_TX_DESC - 1) in rtl8169_tx_map()
4001 txd->opts1 = cpu_to_le32(opts1); in rtl8169_tx_map()
4003 tp->tx_skb[entry].len = len; in rtl8169_tx_map()
4014 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { in rtl8169_xmit_frags()
4015 const skb_frag_t *frag = info->frags + cur_frag; in rtl8169_xmit_frags()
4028 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); in rtl8169_xmit_frags()
4029 return -EIO; in rtl8169_xmit_frags()
4041 return ih && ih->protocol == IPPROTO_UDP; in rtl_skb_is_udp()
4044 return i6h && i6h->nexthdr == IPPROTO_UDP; in rtl_skb_is_udp()
4056 unsigned int padto = 0, len = skb->len; in rtl8125_quirk_udp_padto()
4060 unsigned int trans_data_len = skb_tail_pointer(skb) - in rtl8125_quirk_udp_padto()
4065 u16 dest = ntohs(udp_hdr(skb)->dest); in rtl8125_quirk_udp_padto()
4069 padto = len + RTL_MIN_PATCH_LEN - trans_data_len; in rtl8125_quirk_udp_padto()
4074 len + sizeof(struct udphdr) - trans_data_len); in rtl8125_quirk_udp_padto()
4087 switch (tp->mac_version) { in rtl_quirk_packet_padto()
4102 u32 mss = skb_shinfo(skb)->gso_size; in rtl8169_tso_csum_v1()
4107 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v1()
4110 if (ip->protocol == IPPROTO_TCP) in rtl8169_tso_csum_v1()
4112 else if (ip->protocol == IPPROTO_UDP) in rtl8169_tso_csum_v1()
4123 u32 mss = shinfo->gso_size; in rtl8169_tso_csum_v2()
4126 if (shinfo->gso_type & SKB_GSO_TCPV4) { in rtl8169_tso_csum_v2()
4128 } else if (shinfo->gso_type & SKB_GSO_TCPV6) { in rtl8169_tso_csum_v2()
4140 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v2()
4146 ip_protocol = ip_hdr(skb)->protocol; in rtl8169_tso_csum_v2()
4151 ip_protocol = ipv6_hdr(skb)->nexthdr; in rtl8169_tso_csum_v2()
4179 return READ_ONCE(tp->dirty_tx) + NUM_TX_DESC - READ_ONCE(tp->cur_tx); in rtl_tx_slots_avail()
4185 switch (tp->mac_version) { in rtl_chip_supports_csum_v2()
4205 unsigned int frags = skb_shinfo(skb)->nr_frags; in rtl8169_start_xmit()
4207 unsigned int entry = tp->cur_tx % NUM_TX_DESC; in rtl8169_start_xmit()
4226 if (unlikely(rtl8169_tx_map(tp, opts, skb_headlen(skb), skb->data, in rtl8169_start_xmit()
4230 txd_first = tp->TxDescArray + entry; in rtl8169_start_xmit()
4238 txd_last = tp->TxDescArray + entry; in rtl8169_start_xmit()
4239 txd_last->opts1 |= cpu_to_le32(LastFrag); in rtl8169_start_xmit()
4240 tp->tx_skb[entry].skb = skb; in rtl8169_start_xmit()
4247 door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more()); in rtl8169_start_xmit()
4249 txd_first->opts1 |= cpu_to_le32(DescOwn | FirstFrag); in rtl8169_start_xmit()
4251 /* rtl_tx needs to see descriptor changes before updated tp->cur_tx */ in rtl8169_start_xmit()
4254 WRITE_ONCE(tp->cur_tx, tp->cur_tx + frags + 1); in rtl8169_start_xmit()
4268 dev->stats.tx_dropped++; in rtl8169_start_xmit()
4273 dev->stats.tx_dropped++; in rtl8169_start_xmit()
4280 unsigned int nr_frags = info->nr_frags; in rtl_last_frag_len()
4285 return skb_frag_size(info->frags + nr_frags - 1); in rtl_last_frag_len()
4298 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 && in rtl8168evl_fix_tso()
4315 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl8169_features_check()
4321 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_features_check()
4323 if (skb->len < ETH_ZLEN) in rtl8169_features_check()
4340 struct pci_dev *pdev = tp->pci_dev; in rtl8169_pcierr_interrupt()
4361 dirty_tx = tp->dirty_tx; in rtl_tx()
4363 while (READ_ONCE(tp->cur_tx) != dirty_tx) { in rtl_tx()
4367 status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1)); in rtl_tx()
4371 skb = tp->tx_skb[entry].skb; in rtl_tx()
4376 bytes_compl += skb->len; in rtl_tx()
4382 if (tp->dirty_tx != dirty_tx) { in rtl_tx()
4384 WRITE_ONCE(tp->dirty_tx, dirty_tx); in rtl_tx()
4393 * it is slow enough). -- FR in rtl_tx()
4397 if (READ_ONCE(tp->cur_tx) != dirty_tx && skb) in rtl_tx()
4412 skb->ip_summed = CHECKSUM_UNNECESSARY; in rtl8169_rx_csum()
4422 for (count = 0; count < budget; count++, tp->cur_rx++) { in rtl_rx()
4423 unsigned int pkt_size, entry = tp->cur_rx % NUM_RX_DESC; in rtl_rx()
4424 struct RxDesc *desc = tp->RxDescArray + entry; in rtl_rx()
4430 status = le32_to_cpu(READ_ONCE(desc->opts1)); in rtl_rx()
4444 dev->stats.rx_errors++; in rtl_rx()
4446 dev->stats.rx_length_errors++; in rtl_rx()
4448 dev->stats.rx_crc_errors++; in rtl_rx()
4450 if (!(dev->features & NETIF_F_RXALL)) in rtl_rx()
4457 if (likely(!(dev->features & NETIF_F_RXFCS))) in rtl_rx()
4458 pkt_size -= ETH_FCS_LEN; in rtl_rx()
4461 * They are seen as a symptom of over-mtu sized frames. in rtl_rx()
4464 dev->stats.rx_dropped++; in rtl_rx()
4465 dev->stats.rx_length_errors++; in rtl_rx()
4469 skb = napi_alloc_skb(&tp->napi, pkt_size); in rtl_rx()
4471 dev->stats.rx_dropped++; in rtl_rx()
4475 addr = le64_to_cpu(desc->addr); in rtl_rx()
4476 rx_buf = page_address(tp->Rx_databuff[entry]); in rtl_rx()
4481 skb->tail += pkt_size; in rtl_rx()
4482 skb->len = pkt_size; in rtl_rx()
4486 skb->protocol = eth_type_trans(skb, dev); in rtl_rx()
4490 if (skb->pkt_type == PACKET_MULTICAST) in rtl_rx()
4491 dev->stats.multicast++; in rtl_rx()
4493 napi_gro_receive(&tp->napi, skb); in rtl_rx()
4508 if ((status & 0xffff) == 0xffff || !(status & tp->irq_mask)) in rtl8169_interrupt()
4512 rtl8169_pcierr_interrupt(tp->dev); in rtl8169_interrupt()
4517 phy_mac_interrupt(tp->phydev); in rtl8169_interrupt()
4520 tp->mac_version == RTL_GIGA_MAC_VER_11)) { in rtl8169_interrupt()
4521 netif_stop_queue(tp->dev); in rtl8169_interrupt()
4525 if (napi_schedule_prep(&tp->napi)) { in rtl8169_interrupt()
4527 __napi_schedule(&tp->napi); in rtl8169_interrupt()
4543 if (!netif_running(tp->dev) || in rtl_task()
4544 !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) in rtl_task()
4547 if (test_and_clear_bit(RTL_FLAG_TASK_TX_TIMEOUT, tp->wk.flags)) { in rtl_task()
4550 ret = pci_reset_bus(tp->pci_dev); in rtl_task()
4552 netdev_err(tp->dev, "Can't reset secondary PCI bus, detach NIC\n"); in rtl_task()
4553 netif_device_detach(tp->dev); in rtl_task()
4559 ret = pci_disable_link_state(tp->pci_dev, PCIE_LINK_STATE_L1 | in rtl_task()
4562 netdev_warn_once(tp->dev, "ASPM disabled on Tx timeout\n"); in rtl_task()
4566 if (test_and_clear_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags)) { in rtl_task()
4569 netif_wake_queue(tp->dev); in rtl_task()
4578 struct net_device *dev = tp->dev; in rtl8169_poll()
4603 phy_print_status(tp->phydev); in r8169_phylink_handler()
4608 struct phy_device *phydev = tp->phydev; in r8169_phy_connect()
4612 phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : in r8169_phy_connect()
4615 ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, in r8169_phy_connect()
4620 if (!tp->supports_gmii) in r8169_phy_connect()
4631 bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); in rtl8169_down()
4633 phy_stop(tp->phydev); in rtl8169_down()
4637 pci_clear_master(tp->pci_dev); in rtl8169_down()
4647 pci_set_master(tp->pci_dev); in rtl8169_up()
4648 phy_init_hw(tp->phydev); in rtl8169_up()
4649 phy_resume(tp->phydev); in rtl8169_up()
4651 napi_enable(&tp->napi); in rtl8169_up()
4652 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); in rtl8169_up()
4655 phy_start(tp->phydev); in rtl8169_up()
4661 struct pci_dev *pdev = tp->pci_dev; in rtl8169_close()
4663 pm_runtime_get_sync(&pdev->dev); in rtl8169_close()
4669 cancel_work_sync(&tp->wk.work); in rtl8169_close()
4671 free_irq(tp->irq, tp); in rtl8169_close()
4673 phy_disconnect(tp->phydev); in rtl8169_close()
4675 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, in rtl8169_close()
4676 tp->RxPhyAddr); in rtl8169_close()
4677 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, in rtl8169_close()
4678 tp->TxPhyAddr); in rtl8169_close()
4679 tp->TxDescArray = NULL; in rtl8169_close()
4680 tp->RxDescArray = NULL; in rtl8169_close()
4682 pm_runtime_put_sync(&pdev->dev); in rtl8169_close()
4692 rtl8169_interrupt(tp->irq, tp); in rtl8169_netpoll()
4699 struct pci_dev *pdev = tp->pci_dev; in rtl_open()
4701 int retval = -ENOMEM; in rtl_open()
4703 pm_runtime_get_sync(&pdev->dev); in rtl_open()
4709 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, in rtl_open()
4710 &tp->TxPhyAddr, GFP_KERNEL); in rtl_open()
4711 if (!tp->TxDescArray) in rtl_open()
4714 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, in rtl_open()
4715 &tp->RxPhyAddr, GFP_KERNEL); in rtl_open()
4716 if (!tp->RxDescArray) in rtl_open()
4726 retval = request_irq(tp->irq, rtl8169_interrupt, irqflags, dev->name, tp); in rtl_open()
4738 pm_runtime_put_sync(&pdev->dev); in rtl_open()
4743 free_irq(tp->irq, tp); in rtl_open()
4748 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, in rtl_open()
4749 tp->RxPhyAddr); in rtl_open()
4750 tp->RxDescArray = NULL; in rtl_open()
4752 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, in rtl_open()
4753 tp->TxPhyAddr); in rtl_open()
4754 tp->TxDescArray = NULL; in rtl_open()
4762 struct pci_dev *pdev = tp->pci_dev; in rtl8169_get_stats64()
4763 struct rtl8169_counters *counters = tp->counters; in rtl8169_get_stats64()
4765 pm_runtime_get_noresume(&pdev->dev); in rtl8169_get_stats64()
4767 netdev_stats_to_stats64(stats, &dev->stats); in rtl8169_get_stats64()
4768 dev_fetch_sw_netstats(stats, dev->tstats); in rtl8169_get_stats64()
4774 if (pm_runtime_active(&pdev->dev)) in rtl8169_get_stats64()
4781 stats->tx_errors = le64_to_cpu(counters->tx_errors) - in rtl8169_get_stats64()
4782 le64_to_cpu(tp->tc_offset.tx_errors); in rtl8169_get_stats64()
4783 stats->collisions = le32_to_cpu(counters->tx_multi_collision) - in rtl8169_get_stats64()
4784 le32_to_cpu(tp->tc_offset.tx_multi_collision); in rtl8169_get_stats64()
4785 stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - in rtl8169_get_stats64()
4786 le16_to_cpu(tp->tc_offset.tx_aborted); in rtl8169_get_stats64()
4787 stats->rx_missed_errors = le16_to_cpu(counters->rx_missed) - in rtl8169_get_stats64()
4788 le16_to_cpu(tp->tc_offset.rx_missed); in rtl8169_get_stats64()
4790 pm_runtime_put_noidle(&pdev->dev); in rtl8169_get_stats64()
4795 netif_device_detach(tp->dev); in rtl8169_net_suspend()
4797 if (netif_running(tp->dev)) in rtl8169_net_suspend()
4805 rtl_rar_set(tp, tp->dev->dev_addr); in rtl8169_runtime_resume()
4806 __rtl8169_set_wol(tp, tp->saved_wolopts); in rtl8169_runtime_resume()
4808 if (tp->TxDescArray) in rtl8169_runtime_resume()
4811 netif_device_attach(tp->dev); in rtl8169_runtime_resume()
4823 clk_disable_unprepare(tp->clk); in rtl8169_suspend()
4834 clk_prepare_enable(tp->clk); in rtl8169_resume()
4837 if (tp->mac_version == RTL_GIGA_MAC_VER_37) in rtl8169_resume()
4847 if (!tp->TxDescArray) { in rtl8169_runtime_suspend()
4848 netif_device_detach(tp->dev); in rtl8169_runtime_suspend()
4864 if (tp->dash_type != RTL_DASH_NONE) in rtl8169_runtime_idle()
4865 return -EBUSY; in rtl8169_runtime_idle()
4867 if (!netif_running(tp->dev) || !netif_carrier_ok(tp->dev)) in rtl8169_runtime_idle()
4870 return -EBUSY; in rtl8169_runtime_idle()
4888 rtl_rar_set(tp, tp->dev->perm_addr); in rtl_shutdown()
4891 tp->dash_type == RTL_DASH_NONE) { in rtl_shutdown()
4892 pci_wake_from_d3(pdev, tp->saved_wolopts); in rtl_shutdown()
4902 pm_runtime_get_noresume(&pdev->dev); in rtl_remove_one()
4904 unregister_netdev(tp->dev); in rtl_remove_one()
4906 if (tp->dash_type != RTL_DASH_NONE) in rtl_remove_one()
4912 rtl_rar_set(tp, tp->dev->perm_addr); in rtl_remove_one()
4937 tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg; in rtl_set_irq_mask()
4939 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_set_irq_mask()
4940 tp->irq_mask |= SYSErr | RxOverflow | RxFIFOOver; in rtl_set_irq_mask()
4941 else if (tp->mac_version == RTL_GIGA_MAC_VER_11) in rtl_set_irq_mask()
4943 tp->irq_mask |= RxFIFOOver; in rtl_set_irq_mask()
4945 tp->irq_mask |= RxOverflow; in rtl_set_irq_mask()
4952 switch (tp->mac_version) { in rtl_alloc_irq()
4966 return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); in rtl_alloc_irq()
4973 if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) { in rtl_read_mac_address()
4997 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_read_reg()
5000 return -ENODEV; in r8169_mdio_read_reg()
5008 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_write_reg()
5011 return -ENODEV; in r8169_mdio_write_reg()
5020 struct pci_dev *pdev = tp->pci_dev; in r8169_mdio_register()
5024 new_bus = devm_mdiobus_alloc(&pdev->dev); in r8169_mdio_register()
5026 return -ENOMEM; in r8169_mdio_register()
5028 new_bus->name = "r8169"; in r8169_mdio_register()
5029 new_bus->priv = tp; in r8169_mdio_register()
5030 new_bus->parent = &pdev->dev; in r8169_mdio_register()
5031 new_bus->irq[0] = PHY_MAC_INTERRUPT; in r8169_mdio_register()
5032 snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x-%x", in r8169_mdio_register()
5033 pci_domain_nr(pdev->bus), pci_dev_id(pdev)); in r8169_mdio_register()
5035 new_bus->read = r8169_mdio_read_reg; in r8169_mdio_register()
5036 new_bus->write = r8169_mdio_write_reg; in r8169_mdio_register()
5038 ret = devm_mdiobus_register(&pdev->dev, new_bus); in r8169_mdio_register()
5042 tp->phydev = mdiobus_get_phy(new_bus, 0); in r8169_mdio_register()
5043 if (!tp->phydev) { in r8169_mdio_register()
5044 return -ENODEV; in r8169_mdio_register()
5045 } else if (!tp->phydev->drv) { in r8169_mdio_register()
5049 …dev_err(&pdev->dev, "no dedicated PHY driver found for PHY ID 0x%08x, maybe realtek.ko needs to be… in r8169_mdio_register()
5050 tp->phydev->phy_id); in r8169_mdio_register()
5051 return -EUNATCH; in r8169_mdio_register()
5054 tp->phydev->mac_managed_pm = true; in r8169_mdio_register()
5056 phy_support_asym_pause(tp->phydev); in r8169_mdio_register()
5059 phy_suspend(tp->phydev); in r8169_mdio_register()
5098 switch (tp->mac_version) { in rtl_hw_initialize()
5115 /* Non-GBit versions don't support jumbo frames */ in rtl_jumbo_max()
5116 if (!tp->supports_gmii) in rtl_jumbo_max()
5119 switch (tp->mac_version) { in rtl_jumbo_max()
5138 struct net_device *dev = tp->dev; in rtl_init_mac_address()
5154 dev->addr_assign_type = NET_ADDR_RANDOM; in rtl_init_mac_address()
5164 if (tp->mac_version >= RTL_GIGA_MAC_VER_61 && in rtl_aspm_is_safe()
5180 dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); in rtl_init_one()
5182 return -ENOMEM; in rtl_init_one()
5184 SET_NETDEV_DEV(dev, &pdev->dev); in rtl_init_one()
5185 dev->netdev_ops = &rtl_netdev_ops; in rtl_init_one()
5187 tp->dev = dev; in rtl_init_one()
5188 tp->pci_dev = pdev; in rtl_init_one()
5189 tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1; in rtl_init_one()
5190 tp->eee_adv = -1; in rtl_init_one()
5191 tp->ocp_base = OCP_STD_PHY_BASE; in rtl_init_one()
5193 raw_spin_lock_init(&tp->cfg9346_usage_lock); in rtl_init_one()
5194 raw_spin_lock_init(&tp->config25_lock); in rtl_init_one()
5195 raw_spin_lock_init(&tp->mac_ocp_lock); in rtl_init_one()
5197 dev->tstats = devm_netdev_alloc_pcpu_stats(&pdev->dev, in rtl_init_one()
5199 if (!dev->tstats) in rtl_init_one()
5200 return -ENOMEM; in rtl_init_one()
5203 tp->clk = devm_clk_get_optional_enabled(&pdev->dev, "ether_clk"); in rtl_init_one()
5204 if (IS_ERR(tp->clk)) in rtl_init_one()
5205 return dev_err_probe(&pdev->dev, PTR_ERR(tp->clk), "failed to get ether_clk\n"); in rtl_init_one()
5210 return dev_err_probe(&pdev->dev, rc, "enable failure\n"); in rtl_init_one()
5213 dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); in rtl_init_one()
5216 region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; in rtl_init_one()
5218 return dev_err_probe(&pdev->dev, -ENODEV, "no MMIO resource found\n"); in rtl_init_one()
5222 return dev_err_probe(&pdev->dev, rc, "cannot remap MMIO, aborting\n"); in rtl_init_one()
5224 tp->mmio_addr = pcim_iomap_table(pdev)[region]; in rtl_init_one()
5228 return dev_err_probe(&pdev->dev, -EIO, "PCI read failed\n"); in rtl_init_one()
5233 chipset = rtl8169_get_mac_version(xid, tp->supports_gmii); in rtl_init_one()
5235 return dev_err_probe(&pdev->dev, -ENODEV, in rtl_init_one()
5238 tp->mac_version = chipset; in rtl_init_one()
5247 tp->aspm_manageable = !rc; in rtl_init_one()
5249 tp->dash_type = rtl_check_dash(tp); in rtl_init_one()
5251 tp->cp_cmd = RTL_R16(tp, CPlusCmd) & CPCMD_MASK; in rtl_init_one()
5253 if (sizeof(dma_addr_t) > 4 && tp->mac_version >= RTL_GIGA_MAC_VER_18 && in rtl_init_one()
5254 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) in rtl_init_one()
5255 dev->features |= NETIF_F_HIGHDMA; in rtl_init_one()
5267 return dev_err_probe(&pdev->dev, rc, "Can't allocate interrupt\n"); in rtl_init_one()
5269 tp->irq = pci_irq_vector(pdev, 0); in rtl_init_one()
5271 INIT_WORK(&tp->wk.work, rtl_task); in rtl_init_one()
5275 dev->ethtool_ops = &rtl8169_ethtool_ops; in rtl_init_one()
5277 netif_napi_add(dev, &tp->napi, rtl8169_poll); in rtl_init_one()
5279 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | in rtl_init_one()
5281 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; in rtl_init_one()
5282 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; in rtl_init_one()
5288 if (tp->mac_version == RTL_GIGA_MAC_VER_05) in rtl_init_one()
5290 dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; in rtl_init_one()
5293 dev->hw_features |= NETIF_F_IPV6_CSUM; in rtl_init_one()
5295 dev->features |= dev->hw_features; in rtl_init_one()
5303 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6; in rtl_init_one()
5307 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO; in rtl_init_one()
5312 dev->hw_features |= NETIF_F_RXALL; in rtl_init_one()
5313 dev->hw_features |= NETIF_F_RXFCS; in rtl_init_one()
5318 rtl8169_set_features(dev, dev->features); in rtl_init_one()
5320 if (tp->dash_type == RTL_DASH_NONE) { in rtl_init_one()
5324 dev->wol_enabled = 1; in rtl_init_one()
5329 dev->max_mtu = jumbo_max; in rtl_init_one()
5333 tp->fw_name = rtl_chip_infos[chipset].fw_name; in rtl_init_one()
5335 tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), in rtl_init_one()
5336 &tp->counters_phys_addr, in rtl_init_one()
5338 if (!tp->counters) in rtl_init_one()
5339 return -ENOMEM; in rtl_init_one()
5352 rtl_chip_infos[chipset].name, dev->dev_addr, xid, tp->irq); in rtl_init_one()
5356 jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? in rtl_init_one()
5359 if (tp->dash_type != RTL_DASH_NONE) { in rtl_init_one()
5365 pm_runtime_put_sync(&pdev->dev); in rtl_init_one()