Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp472196lqo; Wed, 8 May 2024 05:48:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnKp74hVp+YgkH19Qt4rHtqZ8efGQnaMydfrGlWYayxMUuJT7kz2af907DSq8/iW3LpsrHffPjtxbkSle/bvQMTSzg6MhEUpYxUONGBw== X-Google-Smtp-Source: AGHT+IEGbNiHfpPhDweqY5P1GQnDHQGS1TlQdq3NB3ps4Je+oIIyvJjVwGUIhTdbf+t03yo2bCqr X-Received: by 2002:a05:6a00:80da:b0:6ea:bb00:dbb6 with SMTP id d2e1a72fcca58-6f49c20eb01mr2354853b3a.8.1715172482089; Wed, 08 May 2024 05:48:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715172482; cv=pass; d=google.com; s=arc-20160816; b=LtBOHoy5tdoj1c5emmnhVaZWzmCZmbjWSUh1wysO4LOQoXXR2fSgZuqcMaimHsgMFx l96sH2CBXCbG0R5R490XltFTNLeNqEeJKsNgIzy74E5m/9DLNwhQz02n67j+vET3tVjl EnNEvghgfk2DtAN0/XT0M0FcshKeV/qh1mqC8zIROfF/q2vS+txzHV5ztTe2y/qI3Xn7 JLK6XFkX/J94QAd7Lw43uvE/lABDa5iO5y6sEVZLjJmcLnaP2m4ZA0nLmX6Y7qg/FmSC t6EpsR84XfiwN66Z+fI6WOp/b8jyh4Nc8yA6o2ICJFthGuDwSTR/zN3GIBrTxNtLYUOh b1Sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=h1PEcF4otcncwEHPNU8yN4bpkyjmWTeUQ4RdnamdDcI=; fh=dvR/tTWg2OfrU+TdVNug7ZowrURi76OJYRbHXzqKj5w=; b=N09jlPBxRXJo7SzHDqxaLzaMykj7oxzJ3y54xwaw/iIQ2p/yqY+0DiklypkF//Px4s JPnhpczkMCadeA5Bce80AHS2zltH/iLVG0GMMAJzZSZJQS1vHzDRAP42KhzoURkEpqIK aNtKnJIVIwQ9JRyJtzCbAY/MOkbIHwEgGG9Lgg4f9N4rqmIMKK5xdi9pM5Ymz59U45yS AJ02fEdHeVMmbJjQlWmEHytNtlIDb4NBwQsnbviFRR2Jcc7ODxeUzeN/UStGQ6FiZDG1 KwDVIwJ057L/4dCwLLK91PPLlbrWhsNLEGxhLSG3v6TaU0NT9Y6gENSroI2UYOPbeZeE s8OQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-kernel+bounces-173248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173248-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ld3-20020a056a004f8300b006f4aa6f9401si1172178pfb.1.2024.05.08.05.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 05:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-kernel+bounces-173248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173248-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0B7F4287323 for ; Wed, 8 May 2024 12:46:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37BCD6A338; Wed, 8 May 2024 12:45:58 +0000 (UTC) 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 1D44C5491D; Wed, 8 May 2024 12:45:55 +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=1715172357; cv=none; b=DKKW/PhT/rFze4r/kztgF82odXwdCagu/sTDDNwziDjRzHyWIC0rIwyQuVCKLQrg4CyPA3lzF4eLeylDPLRSk2u7Q3LoAb+2oZyJF/rQb69SQo0U/SR5e6aEDHXAUFRW4xYQescHoL98C7HfTvQVmNreIcF3VIFYJo4xzNQ3BiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715172357; c=relaxed/simple; bh=k6jUUXRBzaiMT1m8Id3W62pKuOgfCCbm8YwCH9F2uck=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n0HxBQb1fivYMj637BZw2tz07M//5ngzOt/zcP+Dzyky+BIB4J69eQJRpd3q7BEiIqsq0J6F1nnXWkdfCj/zNGHDgAnOQJ9dJ4bsL6+p0ENWrMUkg/HYffrsUkPxM2/cnjcBPeItmlhPK3HxrtP0BMElynSqW26R8r2XohzVlGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 448CjaEnB468934, 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 448CjaEnB468934 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 May 2024 20:45:37 +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_256_GCM_SHA384) id 15.1.2507.35; Wed, 8 May 2024 20:45:37 +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_256_GCM_SHA384) id 15.1.2507.35; Wed, 8 May 2024 20:45:36 +0800 From: Justin Lai To: CC: , , , , , , , , , , Justin Lai Subject: [PATCH net-next v18 10/13] rtase: Implement ethtool function Date: Wed, 8 May 2024 20:39:42 +0800 Message-ID: <20240508123945.201524-11-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508123945.201524-1-justinlai0215@realtek.com> References: <20240508123945.201524-1-justinlai0215@realtek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: RTEXH36505.realtek.com.tw (172.21.6.25) To RTEXMBS04.realtek.com.tw (172.21.6.97) 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 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 | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index 4928397d88a5..143f0b8d357f 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -1754,9 +1754,113 @@ 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 *drvinfo) +{ + const struct rtase_private *tp = 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 = 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_ethtool_stats(struct net_device *dev, + struct ethtool_stats *stats, u64 *data) +{ + struct rtase_private *tp = netdev_priv(dev); + const struct rtase_counters *counters; + + ASSERT_RTNL(); + + counters = tp->tally_vaddr; + if (!counters) + return; + + rtase_dump_tally_counter(tp); + + data[0] = le64_to_cpu(counters->tx_packets); + data[1] = le64_to_cpu(counters->rx_packets); + data[2] = le64_to_cpu(counters->tx_errors); + data[3] = le32_to_cpu(counters->rx_errors); + data[4] = le16_to_cpu(counters->rx_missed); + data[5] = le16_to_cpu(counters->align_errors); + data[6] = le32_to_cpu(counters->tx_one_collision); + data[7] = le32_to_cpu(counters->tx_multi_collision); + data[8] = le64_to_cpu(counters->rx_unicast); + data[9] = le64_to_cpu(counters->rx_broadcast); + data[10] = le32_to_cpu(counters->rx_multicast); + data[11] = le16_to_cpu(counters->tx_aborted); + data[12] = le16_to_cpu(counters->tx_underun); +} + +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_ethtool_stats = rtase_get_ethtool_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, -- 2.34.1