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"
58 #define FIRMWARE_8125D_1 "rtl_nic/rtl8125d-1.fw"
59 #define FIRMWARE_8125D_2 "rtl_nic/rtl8125d-2.fw"
60 #define FIRMWARE_8125BP_2 "rtl_nic/rtl8125bp-2.fw"
61 #define FIRMWARE_8126A_2 "rtl_nic/rtl8126a-2.fw"
62 #define FIRMWARE_8126A_3 "rtl_nic/rtl8126a-3.fw"
68 #define R8169_RX_BUF_SIZE (SZ_16K - 1)
81 #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg))
82 #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg))
83 #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg))
84 #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg))
85 #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg))
86 #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg))
88 #define JUMBO_4K (4 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
89 #define JUMBO_6K (6 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
90 #define JUMBO_7K (7 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
91 #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
103 /* PCI-E devices. */
195 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */
196 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */
414 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
433 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
650 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
651 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
689 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
720 return &tp->pci_dev->dev; in tp_to_dev()
771 return tp->mac_version >= RTL_GIGA_MAC_VER_61; in rtl_is_8125()
776 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_is_8168evl_up()
777 tp->mac_version != RTL_GIGA_MAC_VER_39 && in rtl_is_8168evl_up()
778 tp->mac_version <= RTL_GIGA_MAC_VER_53; in rtl_is_8168evl_up()
783 return tp->mac_version >= RTL_GIGA_MAC_VER_34 && in rtl_supports_eee()
784 tp->mac_version != RTL_GIGA_MAC_VER_37 && in rtl_supports_eee()
785 tp->mac_version != RTL_GIGA_MAC_VER_39; in rtl_supports_eee()
807 if (c->check(tp) == high) in rtl_loop_wait()
813 netdev_err(tp->dev, "%s == %d (loop: %d, delay: %lu).\n", in rtl_loop_wait()
814 c->msg, !high, n, usecs); in rtl_loop_wait()
851 mutex_lock(&tp->led_lock); in rtl8168_led_mod_ctrl()
853 mutex_unlock(&tp->led_lock); in rtl8168_led_mod_ctrl()
894 mutex_lock(&tp->led_lock); in rtl8125_set_led_mode()
897 mutex_unlock(&tp->led_lock); in rtl8125_set_led_mode()
924 struct pci_dev *pdev = tp->pci_dev; in r8169_get_led_name()
928 domain = pci_domain_nr(pdev->bus); in r8169_get_led_name()
934 if (pdev->multifunction) in r8169_get_led_name()
935 snprintf(pfun, sizeof(pfun), "f%d", PCI_FUNC(pdev->devfn)); in r8169_get_led_name()
939 snprintf(buf, buf_len, "en%sp%ds%d%s-%d::lan", pdom, pdev->bus->number, in r8169_get_led_name()
940 PCI_SLOT(pdev->devfn), pfun, idx); in r8169_get_led_name()
945 /* based on RTL8168FP_OOBMAC_BASE in vendor driver */ in r8168fp_adjust_ocp_cmd()
947 (tp->mac_version == RTL_GIGA_MAC_VER_52 || in r8168fp_adjust_ocp_cmd()
948 tp->mac_version == RTL_GIGA_MAC_VER_53)) in r8168fp_adjust_ocp_cmd()
1039 (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT; in r8168_phy_ocp_read()
1054 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
1056 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_write()
1074 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
1076 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_read()
1087 raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
1090 raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); in r8168_mac_ocp_modify()
1094 * PHY MCU interrupts before PHY power-down.
1098 switch (tp->mac_version) { in rtl8168g_phy_suspend_quirk()
1113 tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; in r8168g_mdio_write()
1117 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_write()
1118 reg -= 0x10; in r8168g_mdio_write()
1120 if (tp->ocp_base == OCP_STD_PHY_BASE && reg == MII_BMCR) in r8168g_mdio_write()
1123 r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); in r8168g_mdio_write()
1129 return tp->ocp_base == OCP_STD_PHY_BASE ? 0 : tp->ocp_base >> 4; in r8168g_mdio_read()
1131 if (tp->ocp_base != OCP_STD_PHY_BASE) in r8168g_mdio_read()
1132 reg -= 0x10; in r8168g_mdio_read()
1134 return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); in r8168g_mdio_read()
1140 tp->ocp_base = value << 4; in mac_mcu_write()
1144 r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); in mac_mcu_write()
1149 return r8168_mac_ocp_read(tp, tp->ocp_base + reg); in mac_mcu_read()
1176 RTL_R32(tp, PHYAR) & 0xffff : -ETIMEDOUT; in r8169_mdio_read()
1232 switch (tp->mac_version) { in rtl_writephy()
1248 switch (tp->mac_version) { in rtl_readphy()
1322 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; in rtl8168_get_ocp_reg()
1355 if (tp->dash_enabled) in rtl8168dp_driver_start()
1363 if (tp->dash_enabled) in rtl8168ep_driver_start()
1376 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_start()
1378 else if (tp->dash_type == RTL_DASH_25_BP) in rtl8168_driver_start()
1387 if (tp->dash_enabled) in rtl8168dp_driver_stop()
1396 if (tp->dash_enabled) in rtl8168ep_driver_stop()
1409 if (tp->dash_type == RTL_DASH_DP) in rtl8168_driver_stop()
1411 else if (tp->dash_type == RTL_DASH_25_BP) in rtl8168_driver_stop()
1431 switch (tp->dash_type) { in rtl_dash_is_enabled()
1444 switch (tp->mac_version) { in rtl_get_dash_type()
1459 if (tp->mac_version >= RTL_GIGA_MAC_VER_25 && in rtl_set_d3_pll_down()
1460 tp->mac_version != RTL_GIGA_MAC_VER_28 && in rtl_set_d3_pll_down()
1461 tp->mac_version != RTL_GIGA_MAC_VER_31 && in rtl_set_d3_pll_down()
1462 tp->mac_version != RTL_GIGA_MAC_VER_38) in rtl_set_d3_pll_down()
1512 RTL_W32(tp, IntrMask_8125, tp->irq_mask); in rtl_irq_enable()
1514 RTL_W16(tp, IntrMask, tp->irq_mask); in rtl_irq_enable()
1526 struct phy_device *phydev = tp->phydev; in rtl_link_chg_patch()
1528 if (tp->mac_version == RTL_GIGA_MAC_VER_34 || in rtl_link_chg_patch()
1529 tp->mac_version == RTL_GIGA_MAC_VER_38) { in rtl_link_chg_patch()
1530 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1533 } else if (phydev->speed == SPEED_100) { in rtl_link_chg_patch()
1541 } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || in rtl_link_chg_patch()
1542 tp->mac_version == RTL_GIGA_MAC_VER_36) { in rtl_link_chg_patch()
1543 if (phydev->speed == SPEED_1000) { in rtl_link_chg_patch()
1550 } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { in rtl_link_chg_patch()
1551 if (phydev->speed == SPEED_10) { in rtl_link_chg_patch()
1566 wol->supported = WAKE_ANY; in rtl8169_get_wol()
1567 wol->wolopts = tp->saved_wolopts; in rtl8169_get_wol()
1598 switch (tp->mac_version) { in __rtl8169_set_wol()
1615 if (!tp->dash_enabled) { in __rtl8169_set_wol()
1617 tp->dev->ethtool->wol_enabled = wolopts ? 1 : 0; in __rtl8169_set_wol()
1625 if (wol->wolopts & ~WAKE_ANY) in rtl8169_set_wol()
1626 return -EINVAL; in rtl8169_set_wol()
1628 tp->saved_wolopts = wol->wolopts; in rtl8169_set_wol()
1629 __rtl8169_set_wol(tp, tp->saved_wolopts); in rtl8169_set_wol()
1638 struct rtl_fw *rtl_fw = tp->rtl_fw; in rtl8169_get_drvinfo()
1640 strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); in rtl8169_get_drvinfo()
1641 strscpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); in rtl8169_get_drvinfo()
1642 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); in rtl8169_get_drvinfo()
1644 strscpy(info->fw_version, rtl_fw->version, in rtl8169_get_drvinfo()
1645 sizeof(info->fw_version)); in rtl8169_get_drvinfo()
1658 if (dev->mtu > TD_MSS_MAX) in rtl8169_fix_features()
1661 if (dev->mtu > ETH_DATA_LEN && in rtl8169_fix_features()
1662 tp->mac_version > RTL_GIGA_MAC_VER_06) in rtl8169_fix_features()
1696 tp->cp_cmd |= RxChkSum; in rtl8169_set_features()
1698 tp->cp_cmd &= ~RxChkSum; in rtl8169_set_features()
1702 tp->cp_cmd |= RxVlan; in rtl8169_set_features()
1704 tp->cp_cmd &= ~RxVlan; in rtl8169_set_features()
1707 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl8169_set_features()
1721 u32 opts2 = le32_to_cpu(desc->opts2); in rtl8169_rx_vlan_tag()
1731 u32 __iomem *data = tp->mmio_addr; in rtl8169_get_regs()
1761 return -EOPNOTSUPP; in rtl8169_get_sset_count()
1772 u32 cmd = lower_32_bits(tp->counters_phys_addr); in rtl8169_do_counters()
1774 RTL_W32(tp, CounterAddrHigh, upper_32_bits(tp->counters_phys_addr)); in rtl8169_do_counters()
1788 * is disabled. If 0xff chip may be in a PCI power-save state. in rtl8169_update_counters()
1796 struct rtl8169_counters *counters = tp->counters; in rtl8169_init_counter_offsets()
1813 if (tp->tc_offset.inited) in rtl8169_init_counter_offsets()
1816 if (tp->mac_version >= RTL_GIGA_MAC_VER_19) { in rtl8169_init_counter_offsets()
1820 tp->tc_offset.tx_errors = counters->tx_errors; in rtl8169_init_counter_offsets()
1821 tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; in rtl8169_init_counter_offsets()
1822 tp->tc_offset.tx_aborted = counters->tx_aborted; in rtl8169_init_counter_offsets()
1823 tp->tc_offset.rx_missed = counters->rx_missed; in rtl8169_init_counter_offsets()
1826 tp->tc_offset.inited = true; in rtl8169_init_counter_offsets()
1835 counters = tp->counters; in rtl8169_get_ethtool_stats()
1838 data[0] = le64_to_cpu(counters->tx_packets); in rtl8169_get_ethtool_stats()
1839 data[1] = le64_to_cpu(counters->rx_packets); in rtl8169_get_ethtool_stats()
1840 data[2] = le64_to_cpu(counters->tx_errors); in rtl8169_get_ethtool_stats()
1841 data[3] = le32_to_cpu(counters->rx_errors); in rtl8169_get_ethtool_stats()
1842 data[4] = le16_to_cpu(counters->rx_missed); in rtl8169_get_ethtool_stats()
1843 data[5] = le16_to_cpu(counters->align_errors); in rtl8169_get_ethtool_stats()
1844 data[6] = le32_to_cpu(counters->tx_one_collision); in rtl8169_get_ethtool_stats()
1845 data[7] = le32_to_cpu(counters->tx_multi_collision); in rtl8169_get_ethtool_stats()
1846 data[8] = le64_to_cpu(counters->rx_unicast); in rtl8169_get_ethtool_stats()
1847 data[9] = le64_to_cpu(counters->rx_broadcast); in rtl8169_get_ethtool_stats()
1848 data[10] = le32_to_cpu(counters->rx_multicast); in rtl8169_get_ethtool_stats()
1849 data[11] = le16_to_cpu(counters->tx_aborted); in rtl8169_get_ethtool_stats()
1850 data[12] = le16_to_cpu(counters->tx_underrun); in rtl8169_get_ethtool_stats()
1865 * > 1 - the availability of the IntrMitigate (0xe2) register through the
1870 * > 2 - the Tx timer unit at gigabit speed
1920 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_coalesce_info()
1926 if (tp->phydev->speed == SPEED_UNKNOWN) in rtl_coalesce_info()
1929 for (; ci->speed; ci++) { in rtl_coalesce_info()
1930 if (tp->phydev->speed == ci->speed) in rtl_coalesce_info()
1934 return ERR_PTR(-ELNRNG); in rtl_coalesce_info()
1948 return -EOPNOTSUPP; in rtl_get_coalesce()
1957 scale = ci->scale_nsecs[tp->cp_cmd & INTT_MASK]; in rtl_get_coalesce()
1962 ec->tx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1966 ec->tx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
1969 ec->rx_coalesce_usecs = DIV_ROUND_UP(c_us * scale, 1000); in rtl_get_coalesce()
1972 ec->rx_max_coalesced_frames = (c_us || c_fr) ? c_fr * 4 : 1; in rtl_get_coalesce()
1989 if (usec <= ci->scale_nsecs[i] * RTL_COALESCE_T_MAX / 1000U) { in rtl_coalesce_choose_scale()
1991 return ci->scale_nsecs[i]; in rtl_coalesce_choose_scale()
1995 return -ERANGE; in rtl_coalesce_choose_scale()
2004 u32 tx_fr = ec->tx_max_coalesced_frames; in rtl_set_coalesce()
2005 u32 rx_fr = ec->rx_max_coalesced_frames; in rtl_set_coalesce()
2011 return -EOPNOTSUPP; in rtl_set_coalesce()
2014 return -ERANGE; in rtl_set_coalesce()
2016 coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs); in rtl_set_coalesce()
2024 * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) in rtl_set_coalesce()
2025 * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 in rtl_set_coalesce()
2026 * - then user does `ethtool -C eth0 rx-usecs 100` in rtl_set_coalesce()
2037 if ((tx_fr && !ec->tx_coalesce_usecs) || in rtl_set_coalesce()
2038 (rx_fr && !ec->rx_coalesce_usecs)) in rtl_set_coalesce()
2039 return -EINVAL; in rtl_set_coalesce()
2044 units = DIV_ROUND_UP(ec->tx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
2046 units = DIV_ROUND_UP(ec->rx_coalesce_usecs * 1000U, scale); in rtl_set_coalesce()
2051 /* Meaning of PktCntrDisable bit changed from RTL8168e-vl */ in rtl_set_coalesce()
2055 tp->cp_cmd |= PktCntrDisable; in rtl_set_coalesce()
2057 tp->cp_cmd &= ~PktCntrDisable; in rtl_set_coalesce()
2060 tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; in rtl_set_coalesce()
2061 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_set_coalesce()
2069 unsigned int timer_val = READ_ONCE(tp->dev->mtu) + ETH_HLEN + 0x20; in rtl_set_eee_txidle_timer()
2071 switch (tp->mac_version) { in rtl_set_eee_txidle_timer()
2074 tp->tx_lpi_timer = timer_val; in rtl_set_eee_txidle_timer()
2078 tp->tx_lpi_timer = timer_val; in rtl_set_eee_txidle_timer()
2088 unsigned int speed = tp->phydev->speed; in r8169_get_tx_lpi_timer_us()
2089 unsigned int timer = tp->tx_lpi_timer; in r8169_get_tx_lpi_timer_us()
2104 return -EOPNOTSUPP; in rtl8169_get_eee()
2106 ret = phy_ethtool_get_eee(tp->phydev, data); in rtl8169_get_eee()
2110 data->tx_lpi_timer = r8169_get_tx_lpi_timer_us(tp); in rtl8169_get_eee()
2120 return -EOPNOTSUPP; in rtl8169_set_eee()
2122 return phy_ethtool_set_eee(tp->phydev, data); in rtl8169_set_eee()
2130 data->rx_max_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
2131 data->rx_pending = NUM_RX_DESC; in rtl8169_get_ringparam()
2132 data->tx_max_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
2133 data->tx_pending = NUM_TX_DESC; in rtl8169_get_ringparam()
2145 pause_stats->tx_pause_frames = le32_to_cpu(tp->counters->tx_pause_on); in rtl8169_get_pause_stats()
2146 pause_stats->rx_pause_frames = le32_to_cpu(tp->counters->rx_pause_on); in rtl8169_get_pause_stats()
2155 phy_get_pause(tp->phydev, &tx_pause, &rx_pause); in rtl8169_get_pauseparam()
2157 data->autoneg = tp->phydev->autoneg; in rtl8169_get_pauseparam()
2158 data->tx_pause = tx_pause ? 1 : 0; in rtl8169_get_pauseparam()
2159 data->rx_pause = rx_pause ? 1 : 0; in rtl8169_get_pauseparam()
2167 if (dev->mtu > ETH_DATA_LEN) in rtl8169_set_pauseparam()
2168 return -EOPNOTSUPP; in rtl8169_set_pauseparam()
2170 phy_set_asym_pause(tp->phydev, data->rx_pause, data->tx_pause); in rtl8169_set_pauseparam()
2182 mac_stats->FramesTransmittedOK = in rtl8169_get_eth_mac_stats()
2183 le64_to_cpu(tp->counters->tx_packets); in rtl8169_get_eth_mac_stats()
2184 mac_stats->SingleCollisionFrames = in rtl8169_get_eth_mac_stats()
2185 le32_to_cpu(tp->counters->tx_one_collision); in rtl8169_get_eth_mac_stats()
2186 mac_stats->MultipleCollisionFrames = in rtl8169_get_eth_mac_stats()
2187 le32_to_cpu(tp->counters->tx_multi_collision); in rtl8169_get_eth_mac_stats()
2188 mac_stats->FramesReceivedOK = in rtl8169_get_eth_mac_stats()
2189 le64_to_cpu(tp->counters->rx_packets); in rtl8169_get_eth_mac_stats()
2190 mac_stats->AlignmentErrors = in rtl8169_get_eth_mac_stats()
2191 le16_to_cpu(tp->counters->align_errors); in rtl8169_get_eth_mac_stats()
2192 mac_stats->FramesLostDueToIntMACXmitError = in rtl8169_get_eth_mac_stats()
2193 le64_to_cpu(tp->counters->tx_errors); in rtl8169_get_eth_mac_stats()
2194 mac_stats->BroadcastFramesReceivedOK = in rtl8169_get_eth_mac_stats()
2195 le64_to_cpu(tp->counters->rx_broadcast); in rtl8169_get_eth_mac_stats()
2196 mac_stats->MulticastFramesReceivedOK = in rtl8169_get_eth_mac_stats()
2197 le32_to_cpu(tp->counters->rx_multicast); in rtl8169_get_eth_mac_stats()
2202 mac_stats->AlignmentErrors = in rtl8169_get_eth_mac_stats()
2203 le32_to_cpu(tp->counters->align_errors32); in rtl8169_get_eth_mac_stats()
2204 mac_stats->OctetsTransmittedOK = in rtl8169_get_eth_mac_stats()
2205 le64_to_cpu(tp->counters->tx_octets); in rtl8169_get_eth_mac_stats()
2206 mac_stats->LateCollisions = in rtl8169_get_eth_mac_stats()
2207 le32_to_cpu(tp->counters->tx_late_collision); in rtl8169_get_eth_mac_stats()
2208 mac_stats->FramesAbortedDueToXSColls = in rtl8169_get_eth_mac_stats()
2209 le32_to_cpu(tp->counters->tx_aborted32); in rtl8169_get_eth_mac_stats()
2210 mac_stats->OctetsReceivedOK = in rtl8169_get_eth_mac_stats()
2211 le64_to_cpu(tp->counters->rx_octets); in rtl8169_get_eth_mac_stats()
2212 mac_stats->FramesLostDueToIntMACRcvError = in rtl8169_get_eth_mac_stats()
2213 le32_to_cpu(tp->counters->rx_mac_error); in rtl8169_get_eth_mac_stats()
2214 mac_stats->MulticastFramesXmittedOK = in rtl8169_get_eth_mac_stats()
2215 le64_to_cpu(tp->counters->tx_multicast64); in rtl8169_get_eth_mac_stats()
2216 mac_stats->BroadcastFramesXmittedOK = in rtl8169_get_eth_mac_stats()
2217 le64_to_cpu(tp->counters->tx_broadcast64); in rtl8169_get_eth_mac_stats()
2218 mac_stats->MulticastFramesReceivedOK = in rtl8169_get_eth_mac_stats()
2219 le64_to_cpu(tp->counters->rx_multicast64); in rtl8169_get_eth_mac_stats()
2220 mac_stats->FrameTooLongErrors = in rtl8169_get_eth_mac_stats()
2221 le32_to_cpu(tp->counters->rx_frame_too_long); in rtl8169_get_eth_mac_stats()
2234 ctrl_stats->UnsupportedOpcodesReceived = in rtl8169_get_eth_ctrl_stats()
2235 le32_to_cpu(tp->counters->rx_unknown_opcode); in rtl8169_get_eth_ctrl_stats()
2393 /* Catch-all */ in rtl8169_get_mac_version()
2399 while ((xid & p->mask) != p->val) in rtl8169_get_mac_version()
2401 ver = p->ver; in rtl8169_get_mac_version()
2415 if (tp->rtl_fw) { in rtl_release_firmware()
2416 rtl_fw_release_firmware(tp->rtl_fw); in rtl_release_firmware()
2417 kfree(tp->rtl_fw); in rtl_release_firmware()
2418 tp->rtl_fw = NULL; in rtl_release_firmware()
2427 if (tp->rtl_fw) { in r8169_apply_firmware()
2428 rtl_fw_write_firmware(tp, tp->rtl_fw); in r8169_apply_firmware()
2429 /* At least one firmware doesn't reset tp->ocp_base. */ in r8169_apply_firmware()
2430 tp->ocp_base = OCP_STD_PHY_BASE; in r8169_apply_firmware()
2433 phy_read_poll_timeout(tp->phydev, MII_BMCR, val, in r8169_apply_firmware()
2442 if (tp->mac_version != RTL_GIGA_MAC_VER_38) in rtl8168_config_eee_mac()
2485 set_bit(flag, tp->wk.flags); in rtl_schedule_task()
2486 if (!schedule_work(&tp->wk.work)) in rtl_schedule_task()
2487 clear_bit(flag, tp->wk.flags); in rtl_schedule_task()
2492 r8169_hw_phy_config(tp, tp->phydev, tp->mac_version); in rtl8169_init_phy()
2494 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { in rtl8169_init_phy()
2495 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); in rtl8169_init_phy()
2496 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); in rtl8169_init_phy()
2501 if (tp->mac_version == RTL_GIGA_MAC_VER_05 && in rtl8169_init_phy()
2502 tp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_GIGABYTE && in rtl8169_init_phy()
2503 tp->pci_dev->subsystem_device == 0xe000) in rtl8169_init_phy()
2504 phy_write_paged(tp->phydev, 0x0001, 0x10, 0xf01b); in rtl8169_init_phy()
2507 phy_speed_up(tp->phydev); in rtl8169_init_phy()
2509 genphy_soft_reset(tp->phydev); in rtl8169_init_phy()
2522 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl_rar_set()
2537 rtl_rar_set(tp, dev->dev_addr); in rtl_set_mac_address()
2544 switch (tp->mac_version) { in rtl_init_rxcfg()
2572 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; in rtl8169_init_ring_indexes()
2577 bool jumbo = tp->dev->mtu > ETH_DATA_LEN; in rtl_jumbo_config()
2580 if (jumbo && tp->mac_version >= RTL_GIGA_MAC_VER_17 && in rtl_jumbo_config()
2581 tp->mac_version <= RTL_GIGA_MAC_VER_26) in rtl_jumbo_config()
2585 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()
2859 * controls the L0s/L1 entrance latency. We try standard ECAM access 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_70 || in rtl_hw_start_8125_common()
3729 tp->mac_version == RTL_GIGA_MAC_VER_71) in rtl_hw_start_8125_common()
3732 if (tp->mac_version == RTL_GIGA_MAC_VER_70 || in rtl_hw_start_8125_common()
3733 tp->mac_version == RTL_GIGA_MAC_VER_71) 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_70 || in rtl_hw_start_8125_common()
3752 tp->mac_version == RTL_GIGA_MAC_VER_71) in rtl_hw_start_8125_common()
3770 if (tp->mac_version == RTL_GIGA_MAC_VER_61) in rtl_hw_start_8125_common()
3877 if (hw_configs[tp->mac_version]) in rtl_hw_config()
3878 hw_configs[tp->mac_version](tp); in rtl_hw_config()
3888 switch (tp->mac_version) { in rtl_hw_start_8125()
3930 tp->cp_cmd |= PCIMulRW; in rtl_hw_start_8169()
3932 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || in rtl_hw_start_8169()
3933 tp->mac_version == RTL_GIGA_MAC_VER_03) in rtl_hw_start_8169()
3934 tp->cp_cmd |= EnAnaPLL; in rtl_hw_start_8169()
3936 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start_8169()
3949 RTL_W16(tp, CPlusCmd, tp->cp_cmd); in rtl_hw_start()
3953 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) in rtl_hw_start()
3968 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ in rtl_hw_start()
3974 rtl_set_rx_config_features(tp, tp->dev->features); in rtl_hw_start()
3975 rtl_set_rx_mode(tp->dev); in rtl_hw_start()
3983 WRITE_ONCE(dev->mtu, new_mtu); in rtl8169_change_mtu()
3993 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; in rtl8169_mark_to_asic()
3995 desc->opts2 = 0; in rtl8169_mark_to_asic()
3998 WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); in rtl8169_mark_to_asic()
4015 netdev_err(tp->dev, "Failed to map RX DMA!\n"); in rtl8169_alloc_rx_data()
4020 desc->addr = cpu_to_le64(mapping); in rtl8169_alloc_rx_data()
4030 for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { in rtl8169_rx_clear()
4032 le64_to_cpu(tp->RxDescArray[i].addr), in rtl8169_rx_clear()
4034 __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); in rtl8169_rx_clear()
4035 tp->Rx_databuff[i] = NULL; in rtl8169_rx_clear()
4036 tp->RxDescArray[i].addr = 0; in rtl8169_rx_clear()
4037 tp->RxDescArray[i].opts1 = 0; in rtl8169_rx_clear()
4048 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); in rtl8169_rx_fill()
4051 return -ENOMEM; in rtl8169_rx_fill()
4053 tp->Rx_databuff[i] = data; in rtl8169_rx_fill()
4057 tp->RxDescArray[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); in rtl8169_rx_fill()
4066 memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); in rtl8169_init_ring()
4067 memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); in rtl8169_init_ring()
4074 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_unmap_tx_skb()
4075 struct TxDesc *desc = tp->TxDescArray + entry; in rtl8169_unmap_tx_skb()
4077 dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), tx_skb->len, in rtl8169_unmap_tx_skb()
4090 struct ring_info *tx_skb = tp->tx_skb + entry; in rtl8169_tx_clear_range()
4091 unsigned int len = tx_skb->len; in rtl8169_tx_clear_range()
4094 struct sk_buff *skb = tx_skb->skb; in rtl8169_tx_clear_range()
4105 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); in rtl8169_tx_clear()
4106 netdev_reset_queue(tp->dev); in rtl8169_tx_clear()
4111 napi_disable(&tp->napi); in rtl8169_cleanup()
4121 switch (tp->mac_version) { in rtl8169_cleanup()
4150 netif_stop_queue(tp->dev); in rtl_reset_work()
4155 rtl8169_mark_to_asic(tp->RxDescArray + i); in rtl_reset_work()
4157 napi_enable(&tp->napi); in rtl_reset_work()
4171 struct TxDesc *txd = tp->TxDescArray + entry; in rtl8169_tx_map()
4181 netdev_err(tp->dev, "Failed to map TX data!\n"); in rtl8169_tx_map()
4185 txd->addr = cpu_to_le64(mapping); in rtl8169_tx_map()
4186 txd->opts2 = cpu_to_le32(opts[1]); in rtl8169_tx_map()
4189 if (entry == NUM_TX_DESC - 1) in rtl8169_tx_map()
4193 txd->opts1 = cpu_to_le32(opts1); in rtl8169_tx_map()
4195 tp->tx_skb[entry].len = len; in rtl8169_tx_map()
4206 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { in rtl8169_xmit_frags()
4207 const skb_frag_t *frag = info->frags + cur_frag; in rtl8169_xmit_frags()
4220 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); in rtl8169_xmit_frags()
4221 return -EIO; in rtl8169_xmit_frags()
4233 return ih && ih->protocol == IPPROTO_UDP; in rtl_skb_is_udp()
4236 return i6h && i6h->nexthdr == IPPROTO_UDP; in rtl_skb_is_udp()
4248 unsigned int padto = 0, len = skb->len; in rtl8125_quirk_udp_padto()
4252 unsigned int trans_data_len = skb_tail_pointer(skb) - in rtl8125_quirk_udp_padto()
4257 u16 dest = ntohs(udp_hdr(skb)->dest); in rtl8125_quirk_udp_padto()
4261 padto = len + RTL_MIN_PATCH_LEN - trans_data_len; in rtl8125_quirk_udp_padto()
4266 len + sizeof(struct udphdr) - trans_data_len); in rtl8125_quirk_udp_padto()
4277 switch (tp->mac_version) { in rtl_quirk_packet_padto()
4285 switch (tp->mac_version) { in rtl_quirk_packet_padto()
4299 u32 mss = skb_shinfo(skb)->gso_size; in rtl8169_tso_csum_v1()
4304 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v1()
4307 if (ip->protocol == IPPROTO_TCP) in rtl8169_tso_csum_v1()
4309 else if (ip->protocol == IPPROTO_UDP) in rtl8169_tso_csum_v1()
4320 u32 mss = shinfo->gso_size; in rtl8169_tso_csum_v2()
4323 if (shinfo->gso_type & SKB_GSO_TCPV4) { in rtl8169_tso_csum_v2()
4325 } else if (shinfo->gso_type & SKB_GSO_TCPV6) { in rtl8169_tso_csum_v2()
4337 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_tso_csum_v2()
4343 ip_protocol = ip_hdr(skb)->protocol; in rtl8169_tso_csum_v2()
4348 ip_protocol = ipv6_hdr(skb)->nexthdr; in rtl8169_tso_csum_v2()
4376 return READ_ONCE(tp->dirty_tx) + NUM_TX_DESC - READ_ONCE(tp->cur_tx); in rtl_tx_slots_avail()
4382 switch (tp->mac_version) { in rtl_chip_supports_csum_v2()
4403 unsigned int entry = tp->cur_tx % NUM_TX_DESC; in rtl8169_start_xmit()
4424 if (unlikely(rtl8169_tx_map(tp, opts, skb_headlen(skb), skb->data, in rtl8169_start_xmit()
4428 txd_first = tp->TxDescArray + entry; in rtl8169_start_xmit()
4430 frags = skb_shinfo(skb)->nr_frags; in rtl8169_start_xmit()
4437 txd_last = tp->TxDescArray + entry; in rtl8169_start_xmit()
4438 txd_last->opts1 |= cpu_to_le32(LastFrag); in rtl8169_start_xmit()
4439 tp->tx_skb[entry].skb = skb; in rtl8169_start_xmit()
4446 door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more()); in rtl8169_start_xmit()
4448 txd_first->opts1 |= cpu_to_le32(DescOwn | FirstFrag); in rtl8169_start_xmit()
4450 /* rtl_tx needs to see descriptor changes before updated tp->cur_tx */ in rtl8169_start_xmit()
4453 WRITE_ONCE(tp->cur_tx, tp->cur_tx + frags + 1); in rtl8169_start_xmit()
4467 dev->stats.tx_dropped++; in rtl8169_start_xmit()
4474 unsigned int nr_frags = info->nr_frags; in rtl_last_frag_len()
4479 return skb_frag_size(info->frags + nr_frags - 1); in rtl_last_frag_len()
4492 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 && in rtl8168evl_fix_tso()
4509 if (tp->mac_version == RTL_GIGA_MAC_VER_34) in rtl8169_features_check()
4515 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in rtl8169_features_check()
4517 if (skb->len < ETH_ZLEN) in rtl8169_features_check()
4534 struct pci_dev *pdev = tp->pci_dev; in rtl8169_pcierr_interrupt()
4555 dirty_tx = tp->dirty_tx; in rtl_tx()
4557 while (READ_ONCE(tp->cur_tx) != dirty_tx) { in rtl_tx()
4561 status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1)); in rtl_tx()
4565 skb = tp->tx_skb[entry].skb; in rtl_tx()
4570 bytes_compl += skb->len; in rtl_tx()
4576 if (tp->dirty_tx != dirty_tx) { in rtl_tx()
4578 WRITE_ONCE(tp->dirty_tx, dirty_tx); in rtl_tx()
4587 * it is slow enough). -- FR in rtl_tx()
4591 if (READ_ONCE(tp->cur_tx) != dirty_tx && skb) in rtl_tx()
4606 skb->ip_summed = CHECKSUM_UNNECESSARY; in rtl8169_rx_csum()
4616 for (count = 0; count < budget; count++, tp->cur_rx++) { in rtl_rx()
4617 unsigned int pkt_size, entry = tp->cur_rx % NUM_RX_DESC; in rtl_rx()
4618 struct RxDesc *desc = tp->RxDescArray + entry; in rtl_rx()
4624 status = le32_to_cpu(READ_ONCE(desc->opts1)); in rtl_rx()
4638 dev->stats.rx_errors++; in rtl_rx()
4640 dev->stats.rx_length_errors++; in rtl_rx()
4642 dev->stats.rx_crc_errors++; in rtl_rx()
4644 if (!(dev->features & NETIF_F_RXALL)) in rtl_rx()
4651 if (likely(!(dev->features & NETIF_F_RXFCS))) in rtl_rx()
4652 pkt_size -= ETH_FCS_LEN; in rtl_rx()
4655 * They are seen as a symptom of over-mtu sized frames. in rtl_rx()
4658 dev->stats.rx_dropped++; in rtl_rx()
4659 dev->stats.rx_length_errors++; in rtl_rx()
4663 skb = napi_alloc_skb(&tp->napi, pkt_size); in rtl_rx()
4665 dev->stats.rx_dropped++; in rtl_rx()
4669 addr = le64_to_cpu(desc->addr); in rtl_rx()
4670 rx_buf = page_address(tp->Rx_databuff[entry]); in rtl_rx()
4675 skb->tail += pkt_size; in rtl_rx()
4676 skb->len = pkt_size; in rtl_rx()
4680 skb->protocol = eth_type_trans(skb, dev); in rtl_rx()
4684 if (skb->pkt_type == PACKET_MULTICAST) in rtl_rx()
4685 dev->stats.multicast++; in rtl_rx()
4687 napi_gro_receive(&tp->napi, skb); in rtl_rx()
4702 if ((status & 0xffff) == 0xffff || !(status & tp->irq_mask)) in rtl8169_interrupt()
4707 tp->mac_version <= RTL_GIGA_MAC_VER_06)) { in rtl8169_interrupt()
4708 rtl8169_pcierr_interrupt(tp->dev); in rtl8169_interrupt()
4713 phy_mac_interrupt(tp->phydev); in rtl8169_interrupt()
4716 napi_schedule(&tp->napi); in rtl8169_interrupt()
4729 if (test_and_clear_bit(RTL_FLAG_TASK_TX_TIMEOUT, tp->wk.flags)) { in rtl_task()
4732 ret = pci_reset_bus(tp->pci_dev); in rtl_task()
4734 netdev_err(tp->dev, "Can't reset secondary PCI bus, detach NIC\n"); in rtl_task()
4735 netif_device_detach(tp->dev); in rtl_task()
4741 ret = pci_disable_link_state(tp->pci_dev, PCIE_LINK_STATE_L1 | in rtl_task()
4744 netdev_warn_once(tp->dev, "ASPM disabled on Tx timeout\n"); in rtl_task()
4748 if (test_and_clear_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags)) { in rtl_task()
4751 netif_wake_queue(tp->dev); in rtl_task()
4758 struct net_device *dev = tp->dev; in rtl8169_poll()
4783 phy_print_status(tp->phydev); in r8169_phylink_handler()
4788 struct phy_device *phydev = tp->phydev; in r8169_phy_connect()
4792 phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : in r8169_phy_connect()
4795 ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, in r8169_phy_connect()
4800 if (!tp->supports_gmii) in r8169_phy_connect()
4810 disable_work_sync(&tp->wk.work); in rtl8169_down()
4812 bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); in rtl8169_down()
4814 phy_stop(tp->phydev); in rtl8169_down()
4818 pci_clear_master(tp->pci_dev); in rtl8169_down()
4825 if (tp->dash_type != RTL_DASH_NONE) in rtl8169_down()
4831 if (tp->dash_type != RTL_DASH_NONE) in rtl8169_up()
4834 pci_set_master(tp->pci_dev); in rtl8169_up()
4835 phy_init_hw(tp->phydev); in rtl8169_up()
4836 phy_resume(tp->phydev); in rtl8169_up()
4838 napi_enable(&tp->napi); in rtl8169_up()
4839 enable_work(&tp->wk.work); in rtl8169_up()
4842 phy_start(tp->phydev); in rtl8169_up()
4848 struct pci_dev *pdev = tp->pci_dev; in rtl8169_close()
4850 pm_runtime_get_sync(&pdev->dev); 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()
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 disable_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()
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()
5136 switch (tp->mac_version) { in rtl_alloc_irq()
5150 return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); in rtl_alloc_irq()
5157 if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) { in rtl_read_mac_address()
5181 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_read_reg()
5184 return -ENODEV; in r8169_mdio_read_reg()
5192 struct rtl8169_private *tp = mii_bus->priv; in r8169_mdio_write_reg()
5195 return -ENODEV; in r8169_mdio_write_reg()
5204 struct pci_dev *pdev = tp->pci_dev; in r8169_mdio_register()
5213 if (tp->mac_version == RTL_GIGA_MAC_VER_25 || in r8169_mdio_register()
5214 tp->mac_version == RTL_GIGA_MAC_VER_26) in r8169_mdio_register()
5217 new_bus = devm_mdiobus_alloc(&pdev->dev); in r8169_mdio_register()
5219 return -ENOMEM; in r8169_mdio_register()
5221 new_bus->name = "r8169"; in r8169_mdio_register()
5222 new_bus->priv = tp; in r8169_mdio_register()
5223 new_bus->parent = &pdev->dev; in r8169_mdio_register()
5224 new_bus->irq[0] = PHY_MAC_INTERRUPT; in r8169_mdio_register()
5225 snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x-%x", in r8169_mdio_register()
5226 pci_domain_nr(pdev->bus), pci_dev_id(pdev)); in r8169_mdio_register()
5228 new_bus->read = r8169_mdio_read_reg; in r8169_mdio_register()
5229 new_bus->write = r8169_mdio_write_reg; in r8169_mdio_register()
5231 ret = devm_mdiobus_register(&pdev->dev, new_bus); in r8169_mdio_register()
5235 tp->phydev = mdiobus_get_phy(new_bus, 0); in r8169_mdio_register()
5236 if (!tp->phydev) { in r8169_mdio_register()
5237 return -ENODEV; in r8169_mdio_register()
5238 } else if (!tp->phydev->drv) { in r8169_mdio_register()
5242 …dev_err(&pdev->dev, "no dedicated PHY driver found for PHY ID 0x%08x, maybe realtek.ko needs to be… in r8169_mdio_register()
5243 tp->phydev->phy_id); in r8169_mdio_register()
5244 return -EUNATCH; in r8169_mdio_register()
5247 tp->phydev->mac_managed_pm = true; in r8169_mdio_register()
5249 phy_support_eee(tp->phydev); in r8169_mdio_register()
5250 phy_support_asym_pause(tp->phydev); in r8169_mdio_register()
5253 if (tp->mac_version == RTL_GIGA_MAC_VER_61) in r8169_mdio_register()
5254 phy_set_eee_broken(tp->phydev, in r8169_mdio_register()
5256 phy_set_eee_broken(tp->phydev, ETHTOOL_LINK_MODE_5000baseT_Full_BIT); in r8169_mdio_register()
5259 phy_suspend(tp->phydev); in r8169_mdio_register()
5298 switch (tp->mac_version) { in rtl_hw_initialize()
5315 /* Non-GBit versions don't support jumbo frames */ in rtl_jumbo_max()
5316 if (!tp->supports_gmii) in rtl_jumbo_max()
5319 switch (tp->mac_version) { in rtl_jumbo_max()
5337 struct net_device *dev = tp->dev; in rtl_init_mac_address()
5353 dev->addr_assign_type = NET_ADDR_RANDOM; in rtl_init_mac_address()
5363 if (tp->mac_version >= RTL_GIGA_MAC_VER_61 && in rtl_aspm_is_safe()
5379 dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); in rtl_init_one()
5381 return -ENOMEM; in rtl_init_one()
5383 SET_NETDEV_DEV(dev, &pdev->dev); in rtl_init_one()
5384 dev->netdev_ops = &rtl_netdev_ops; in rtl_init_one()
5386 tp->dev = dev; in rtl_init_one()
5387 tp->pci_dev = pdev; in rtl_init_one()
5388 tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1; in rtl_init_one()
5389 tp->ocp_base = OCP_STD_PHY_BASE; 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()
5465 disable_work(&tp->wk.work); in rtl_init_one()
5469 dev->ethtool_ops = &rtl8169_ethtool_ops; in rtl_init_one()
5471 netif_napi_add(dev, &tp->napi, rtl8169_poll); in rtl_init_one()
5473 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | in rtl_init_one()
5475 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; in rtl_init_one()
5476 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; in rtl_init_one()
5482 if (tp->mac_version == RTL_GIGA_MAC_VER_05) in rtl_init_one()
5484 dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; in rtl_init_one()
5487 dev->hw_features |= NETIF_F_IPV6_CSUM; in rtl_init_one()
5489 dev->features |= dev->hw_features; in rtl_init_one()
5492 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6; in rtl_init_one()
5496 dev->hw_features |= NETIF_F_SG | NETIF_F_TSO; in rtl_init_one()
5508 if (tp->mac_version >= RTL_GIGA_MAC_VER_46 && in rtl_init_one()
5509 tp->mac_version != RTL_GIGA_MAC_VER_61) in rtl_init_one()
5510 dev->features |= dev->hw_features; in rtl_init_one()
5512 dev->hw_features |= NETIF_F_RXALL; in rtl_init_one()
5513 dev->hw_features |= NETIF_F_RXFCS; in rtl_init_one()
5515 dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; in rtl_init_one()
5520 rtl8169_set_features(dev, dev->features); in rtl_init_one()
5522 if (!tp->dash_enabled) { in rtl_init_one()
5526 dev->ethtool->wol_enabled = 1; in rtl_init_one()
5531 dev->max_mtu = jumbo_max; in rtl_init_one()
5535 tp->fw_name = rtl_chip_infos[chipset].fw_name; in rtl_init_one()
5537 tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), in rtl_init_one()
5538 &tp->counters_phys_addr, in rtl_init_one()
5540 if (!tp->counters) in rtl_init_one()
5541 return -ENOMEM; in rtl_init_one()
5555 tp->leds = rtl8125_init_leds(dev); in rtl_init_one()
5556 else if (tp->mac_version > RTL_GIGA_MAC_VER_06) in rtl_init_one()
5557 tp->leds = rtl8168_init_leds(dev); in rtl_init_one()
5561 rtl_chip_infos[chipset].name, dev->dev_addr, xid, tp->irq); in rtl_init_one()
5565 jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? in rtl_init_one()
5568 if (tp->dash_type != RTL_DASH_NONE) { in rtl_init_one()
5570 tp->dash_enabled ? "enabled" : "disabled"); in rtl_init_one()
5575 pm_runtime_put_sync(&pdev->dev); in rtl_init_one()