Skip to content

Commit dd7f17c

Browse files
Justin Laikuba-moo
authored andcommitted
rtase: Implement ethtool function
Implement the ethtool function to support users to obtain network card information, including obtaining various device settings, Report whether physical link is up, Report pause parameters, Set pause parameters, Return extended statistics about the device. Signed-off-by: Justin Lai <justinlai0215@realtek.com> Link: https://patch.msgid.link/20240904032114.247117-11-justinlai0215@realtek.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a25a0b0 commit dd7f17c

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

drivers/net/ethernet/realtek/rtase/rtase_main.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,9 +1710,83 @@ static void rtase_get_mac_address(struct net_device *dev)
17101710
rtase_rar_set(tp, dev->dev_addr);
17111711
}
17121712

1713+
static int rtase_get_settings(struct net_device *dev,
1714+
struct ethtool_link_ksettings *cmd)
1715+
{
1716+
u32 supported = SUPPORTED_MII | SUPPORTED_Pause | SUPPORTED_Asym_Pause;
1717+
1718+
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1719+
supported);
1720+
cmd->base.speed = SPEED_5000;
1721+
cmd->base.duplex = DUPLEX_FULL;
1722+
cmd->base.port = PORT_MII;
1723+
cmd->base.autoneg = AUTONEG_DISABLE;
1724+
1725+
return 0;
1726+
}
1727+
1728+
static void rtase_get_pauseparam(struct net_device *dev,
1729+
struct ethtool_pauseparam *pause)
1730+
{
1731+
const struct rtase_private *tp = netdev_priv(dev);
1732+
u16 value = rtase_r16(tp, RTASE_CPLUS_CMD);
1733+
1734+
pause->autoneg = AUTONEG_DISABLE;
1735+
pause->tx_pause = !!(value & RTASE_FORCE_TXFLOW_EN);
1736+
pause->rx_pause = !!(value & RTASE_FORCE_RXFLOW_EN);
1737+
}
1738+
1739+
static int rtase_set_pauseparam(struct net_device *dev,
1740+
struct ethtool_pauseparam *pause)
1741+
{
1742+
const struct rtase_private *tp = netdev_priv(dev);
1743+
u16 value = rtase_r16(tp, RTASE_CPLUS_CMD);
1744+
1745+
if (pause->autoneg)
1746+
return -EOPNOTSUPP;
1747+
1748+
value &= ~(RTASE_FORCE_TXFLOW_EN | RTASE_FORCE_RXFLOW_EN);
1749+
1750+
if (pause->tx_pause)
1751+
value |= RTASE_FORCE_TXFLOW_EN;
1752+
1753+
if (pause->rx_pause)
1754+
value |= RTASE_FORCE_RXFLOW_EN;
1755+
1756+
rtase_w16(tp, RTASE_CPLUS_CMD, value);
1757+
return 0;
1758+
}
1759+
1760+
static void rtase_get_eth_mac_stats(struct net_device *dev,
1761+
struct ethtool_eth_mac_stats *stats)
1762+
{
1763+
struct rtase_private *tp = netdev_priv(dev);
1764+
const struct rtase_counters *counters;
1765+
1766+
counters = tp->tally_vaddr;
1767+
1768+
rtase_dump_tally_counter(tp);
1769+
1770+
stats->FramesTransmittedOK = le64_to_cpu(counters->tx_packets);
1771+
stats->FramesReceivedOK = le64_to_cpu(counters->rx_packets);
1772+
stats->FramesLostDueToIntMACXmitError =
1773+
le64_to_cpu(counters->tx_errors);
1774+
stats->BroadcastFramesReceivedOK = le64_to_cpu(counters->rx_broadcast);
1775+
}
1776+
1777+
static const struct ethtool_ops rtase_ethtool_ops = {
1778+
.get_link = ethtool_op_get_link,
1779+
.get_link_ksettings = rtase_get_settings,
1780+
.get_pauseparam = rtase_get_pauseparam,
1781+
.set_pauseparam = rtase_set_pauseparam,
1782+
.get_eth_mac_stats = rtase_get_eth_mac_stats,
1783+
.get_ts_info = ethtool_op_get_ts_info,
1784+
};
1785+
17131786
static void rtase_init_netdev_ops(struct net_device *dev)
17141787
{
17151788
dev->netdev_ops = &rtase_netdev_ops;
1789+
dev->ethtool_ops = &rtase_ethtool_ops;
17161790
}
17171791

17181792
static void rtase_reset_interrupt(struct pci_dev *pdev,

0 commit comments

Comments
 (0)