From nobody Tue Dec 16 20:33:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A100C4167B for ; Fri, 8 Dec 2023 09:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573513AbjLHJsv (ORCPT ); Fri, 8 Dec 2023 04:48:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573474AbjLHJsL (ORCPT ); Fri, 8 Dec 2023 04:48:11 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58142D5B; Fri, 8 Dec 2023 01:48:16 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3B89ltxqF802644, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3B89ltxqF802644 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 8 Dec 2023 17:47:55 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Fri, 8 Dec 2023 17:47:55 +0800 Received: from RTDOMAIN (172.21.210.160) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 8 Dec 2023 17:47:54 +0800 From: Justin Lai To: CC: , , , , , , , , Justin Lai Subject: [PATCH net-next v14 10/13] rtase: Implement ethtool function Date: Fri, 8 Dec 2023 17:47:30 +0800 Message-ID: <20231208094733.1671296-11-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208094733.1671296-1-justinlai0215@realtek.com> References: <20231208094733.1671296-1-justinlai0215@realtek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.21.210.160] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 a set of strings that describe the requested objects, Get number of strings that @get_strings will write, Return extended statistics about the device. Signed-off-by: Justin Lai --- .../net/ethernet/realtek/rtase/rtase_main.c | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/= ethernet/realtek/rtase/rtase_main.c index 1f71ed89e043..c3a9a1e65ac3 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -1742,9 +1742,153 @@ static void rtase_get_mac_address(struct net_device= *dev) rtase_rar_set(tp, dev->dev_addr); } =20 +static void rtase_get_drvinfo(struct net_device *dev, + struct ethtool_drvinfo *drvinfo) +{ + const struct rtase_private *tp =3D netdev_priv(dev); + + strscpy(drvinfo->driver, KBUILD_MODNAME, 32); + strscpy(drvinfo->bus_info, pci_name(tp->pdev), 32); +} + +static int rtase_get_settings(struct net_device *dev, + struct ethtool_link_ksettings *cmd) +{ + u32 supported =3D SUPPORTED_MII | SUPPORTED_Pause | SUPPORTED_Asym_Pause; + + ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, + supported); + cmd->base.speed =3D SPEED_5000; + cmd->base.duplex =3D DUPLEX_FULL; + cmd->base.port =3D PORT_MII; + cmd->base.autoneg =3D AUTONEG_DISABLE; + + return 0; +} + +static void rtase_get_pauseparam(struct net_device *dev, + struct ethtool_pauseparam *pause) +{ + const struct rtase_private *tp =3D netdev_priv(dev); + u16 value =3D rtase_r16(tp, RTASE_CPLUS_CMD); + + pause->autoneg =3D AUTONEG_DISABLE; + + if ((value & (FORCE_TXFLOW_EN | FORCE_RXFLOW_EN)) =3D=3D + (FORCE_TXFLOW_EN | FORCE_RXFLOW_EN)) { + pause->rx_pause =3D 1; + pause->tx_pause =3D 1; + } else if ((value & FORCE_TXFLOW_EN)) { + pause->tx_pause =3D 1; + } else if ((value & FORCE_RXFLOW_EN)) { + pause->rx_pause =3D 1; + } +} + +static int rtase_set_pauseparam(struct net_device *dev, + struct ethtool_pauseparam *pause) +{ + const struct rtase_private *tp =3D netdev_priv(dev); + u16 value =3D rtase_r16(tp, RTASE_CPLUS_CMD); + + if (pause->autoneg) + return -EOPNOTSUPP; + + value &=3D ~(FORCE_TXFLOW_EN | FORCE_RXFLOW_EN); + + if (pause->tx_pause) + value |=3D FORCE_TXFLOW_EN; + + if (pause->rx_pause) + value |=3D FORCE_RXFLOW_EN; + + rtase_w16(tp, RTASE_CPLUS_CMD, value); + return 0; +} + +static const char rtase_gstrings[][ETH_GSTRING_LEN] =3D { + "tx_packets", + "rx_packets", + "tx_errors", + "rx_errors", + "rx_missed", + "align_errors", + "tx_single_collisions", + "tx_multi_collisions", + "unicast", + "broadcast", + "multicast", + "tx_aborted", + "tx_underrun", +}; + +static void rtase_get_strings(struct net_device *dev, u32 stringset, u8 *d= ata) +{ + switch (stringset) { + case ETH_SS_STATS: + memcpy(data, rtase_gstrings, sizeof(rtase_gstrings)); + break; + } +} + +static int rtase_get_sset_count(struct net_device *dev, int sset) +{ + int ret =3D -EOPNOTSUPP; + + switch (sset) { + case ETH_SS_STATS: + ret =3D ARRAY_SIZE(rtase_gstrings); + break; + } + + return ret; +} + +static void rtase_get_ethtool_stats(struct net_device *dev, + struct ethtool_stats *stats, u64 *data) +{ + struct rtase_private *tp =3D netdev_priv(dev); + const struct rtase_counters *counters; + + ASSERT_RTNL(); + + counters =3D tp->tally_vaddr; + if (!counters) + return; + + rtase_dump_tally_counter(tp); + + data[0] =3D le64_to_cpu(counters->tx_packets); + data[1] =3D le64_to_cpu(counters->rx_packets); + data[2] =3D le64_to_cpu(counters->tx_errors); + data[3] =3D le32_to_cpu(counters->rx_errors); + data[4] =3D le16_to_cpu(counters->rx_missed); + data[5] =3D le16_to_cpu(counters->align_errors); + data[6] =3D le32_to_cpu(counters->tx_one_collision); + data[7] =3D le32_to_cpu(counters->tx_multi_collision); + data[8] =3D le64_to_cpu(counters->rx_unicast); + data[9] =3D le64_to_cpu(counters->rx_broadcast); + data[10] =3D le32_to_cpu(counters->rx_multicast); + data[11] =3D le16_to_cpu(counters->tx_aborted); + data[12] =3D le16_to_cpu(counters->tx_underun); +} + +static const struct ethtool_ops rtase_ethtool_ops =3D { + .get_drvinfo =3D rtase_get_drvinfo, + .get_link =3D ethtool_op_get_link, + .get_link_ksettings =3D rtase_get_settings, + .get_pauseparam =3D rtase_get_pauseparam, + .set_pauseparam =3D rtase_set_pauseparam, + .get_strings =3D rtase_get_strings, + .get_sset_count =3D rtase_get_sset_count, + .get_ethtool_stats =3D rtase_get_ethtool_stats, + .get_ts_info =3D ethtool_op_get_ts_info, +}; + static void rtase_init_netdev_ops(struct net_device *dev) { dev->netdev_ops =3D &rtase_netdev_ops; + dev->ethtool_ops =3D &rtase_ethtool_ops; } =20 static void rtase_reset_interrupt(struct pci_dev *pdev, --=20 2.34.1