From patchwork Mon Jul 29 06:21:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Lai X-Patchwork-Id: 13744380 X-Patchwork-Delegate: kuba@kernel.org Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26708287E; Mon, 29 Jul 2024 06:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722234383; cv=none; b=YYCjCW6Zd8HrGULXHJt/vG835U9GUMBLDmXujqqDl5C0+dAS4EfNPJQNkS9lYQydf/9Z5slJP4ZTh8yRu1QPPYOdsP9rqK8p8VAvuwcpeZeNa0U5SxHBV6mnCvtiyVv4logTn1E9yOV1ALU3ubAUT7P1lX4hKzNf9yVGaMHvKVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722234383; c=relaxed/simple; bh=ux2msqbQca/oRovnCL3NvqAwB4INXF+2uQ3wy43OTC0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L1uUCknEReaTq7ksDzTYB6uBY8+6acx/3ljFwHQNNF3Y/TZ1bY0yFDRg6U1RgVPz2w2Q4D2ea4dVQ54dB45A3KfAwUaHnV2kCHpRA0lvw2sY1CdXa/Q3v/Uh4kHZ5IQ01xf9drfJWb0I4dkjw2s2hzql/y7AI5Zd78KyoN0KX1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; dkim=temperror (0-bit key) header.d=realtek.com header.i=@realtek.com header.b=ESpZknmI; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com Authentication-Results: smtp.subspace.kernel.org; dkim=temperror (0-bit key) header.d=realtek.com header.i=@realtek.com header.b="ESpZknmI" X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 46T6PweG63600335, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=realtek.com; s=dkim; t=1722234359; bh=ux2msqbQca/oRovnCL3NvqAwB4INXF+2uQ3wy43OTC0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type; b=ESpZknmIC9Q21F50oJhL81QgzrCYN+dcXskhyyzaWt42/GV/Wr0rcfkuT8punpSzY IqfGSkzLUHkxoKYDl340VvpuGy/YlK7Zy648tFtIusMcpsi8BaGGIgur/xSAbk6i1j pVNQECpV3oFI/4odiPrvlX973Wc+Vj2O6JkERp4AW/jWMf4AZz/Y69Sfhp+a1OZhRs 4U6PgTd6iqL5cp3y3HkZ4WLB/P68nBvIUkiRuuwkHZb/benVvsuFYJcRyzLVroWTgW lI/lk7eULO0KsRcQgxxFBYR35Mhq/omObEkLzcCu2khIVDUrB0DKI2gfUJbcYPTwNG hxbGNZ9GAb7HQ== Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/3.02/5.92) with ESMTPS id 46T6PweG63600335 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Jul 2024 14:25:58 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 29 Jul 2024 14:25:58 +0800 Received: from RTDOMAIN (172.21.210.74) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 29 Jul 2024 14:25:57 +0800 From: Justin Lai To: CC: , , , , , , , , , , , , "Justin Lai" Subject: [PATCH net-next v25 10/13] rtase: Implement ethtool function Date: Mon, 29 Jul 2024 14:21:18 +0800 Message-ID: <20240729062121.335080-11-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240729062121.335080-1-justinlai0215@realtek.com> References: <20240729062121.335080-1-justinlai0215@realtek.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-Patchwork-Delegate: kuba@kernel.org 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 --- .../net/ethernet/realtek/rtase/rtase_main.c | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index 77cf6d383129..fe8e0487502e 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -1726,9 +1726,101 @@ static void rtase_get_mac_address(struct net_device *dev) rtase_rar_set(tp, dev->dev_addr); } +static void rtase_get_drvinfo(struct net_device *dev, + struct ethtool_drvinfo *info) +{ + const struct rtase_private *tp = netdev_priv(dev); + + strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); + strscpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); +} + +static int rtase_get_settings(struct net_device *dev, + struct ethtool_link_ksettings *cmd) +{ + u32 supported = SUPPORTED_MII | SUPPORTED_Pause | SUPPORTED_Asym_Pause; + + ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, + supported); + cmd->base.speed = SPEED_5000; + cmd->base.duplex = DUPLEX_FULL; + cmd->base.port = PORT_MII; + cmd->base.autoneg = AUTONEG_DISABLE; + + return 0; +} + +static void rtase_get_pauseparam(struct net_device *dev, + struct ethtool_pauseparam *pause) +{ + const struct rtase_private *tp = netdev_priv(dev); + u16 value = rtase_r16(tp, RTASE_CPLUS_CMD); + + pause->autoneg = AUTONEG_DISABLE; + + if ((value & (RTASE_FORCE_TXFLOW_EN | RTASE_FORCE_RXFLOW_EN)) == + (RTASE_FORCE_TXFLOW_EN | RTASE_FORCE_RXFLOW_EN)) { + pause->rx_pause = 1; + pause->tx_pause = 1; + } else if (value & RTASE_FORCE_TXFLOW_EN) { + pause->tx_pause = 1; + } else if (value & RTASE_FORCE_RXFLOW_EN) { + pause->rx_pause = 1; + } +} + +static int rtase_set_pauseparam(struct net_device *dev, + struct ethtool_pauseparam *pause) +{ + const struct rtase_private *tp = netdev_priv(dev); + u16 value = rtase_r16(tp, RTASE_CPLUS_CMD); + + if (pause->autoneg) + return -EOPNOTSUPP; + + value &= ~(RTASE_FORCE_TXFLOW_EN | RTASE_FORCE_RXFLOW_EN); + + if (pause->tx_pause) + value |= RTASE_FORCE_TXFLOW_EN; + + if (pause->rx_pause) + value |= RTASE_FORCE_RXFLOW_EN; + + rtase_w16(tp, RTASE_CPLUS_CMD, value); + return 0; +} + +static void rtase_get_eth_mac_stats(struct net_device *dev, + struct ethtool_eth_mac_stats *stats) +{ + struct rtase_private *tp = netdev_priv(dev); + const struct rtase_counters *counters; + + counters = tp->tally_vaddr; + + rtase_dump_tally_counter(tp); + + stats->FramesTransmittedOK = le64_to_cpu(counters->tx_packets); + stats->FramesReceivedOK = le64_to_cpu(counters->rx_packets); + stats->FramesLostDueToIntMACXmitError = + le64_to_cpu(counters->tx_errors); + stats->BroadcastFramesReceivedOK = le64_to_cpu(counters->rx_broadcast); +} + +static const struct ethtool_ops rtase_ethtool_ops = { + .get_drvinfo = rtase_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_link_ksettings = rtase_get_settings, + .get_pauseparam = rtase_get_pauseparam, + .set_pauseparam = rtase_set_pauseparam, + .get_eth_mac_stats = rtase_get_eth_mac_stats, + .get_ts_info = ethtool_op_get_ts_info, +}; + static void rtase_init_netdev_ops(struct net_device *dev) { dev->netdev_ops = &rtase_netdev_ops; + dev->ethtool_ops = &rtase_ethtool_ops; } static void rtase_reset_interrupt(struct pci_dev *pdev,