[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231130075844.52932-1-zhoufeng.zf@bytedance.com>
Date: Thu, 30 Nov 2023 15:58:44 +0800
From: Feng zhou <zhoufeng.zf@...edance.com>
To: daniel@...earbox.net,
razor@...ckwall.org,
davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com
Cc: bpf@...r.kernel.org,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
yangzhenze@...edance.com,
wangdongdong.6@...edance.com,
tangchen.1@...edance.com,
zhoufeng.zf@...edance.com
Subject: [PATCH bpf-next] netkit: Add some ethtool ops to provide information to user
From: Feng Zhou <zhoufeng.zf@...edance.com>
Add get_strings, get_sset_count, get_ethtool_stats to get peer
ifindex.
ethtool -S nk1
NIC statistics:
peer_ifindex: 36
Add get_link, get_link_ksettings to get link stat.
ethtool nk1
Settings for nk1:
...
Link detected: yes
Add get_ts_info.
ethtool -T nk1
Time stamping parameters for nk1:
...
Signed-off-by: Feng Zhou <zhoufeng.zf@...edance.com>
---
drivers/net/netkit.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c
index 97bd6705c241..1a5199568a07 100644
--- a/drivers/net/netkit.c
+++ b/drivers/net/netkit.c
@@ -34,6 +34,12 @@ struct netkit_link {
u32 location;
};
+static struct {
+ const char string[ETH_GSTRING_LEN];
+} ethtool_stats_keys[] = {
+ { "peer_ifindex" },
+};
+
static __always_inline int
netkit_run(const struct bpf_mprog_entry *entry, struct sk_buff *skb,
enum netkit_action ret)
@@ -211,8 +217,55 @@ static void netkit_get_drvinfo(struct net_device *dev,
strscpy(info->driver, DRV_NAME, sizeof(info->driver));
}
+static void netkit_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
+{
+ u8 *p = buf;
+
+ switch (stringset) {
+ case ETH_SS_STATS:
+ memcpy(p, ðtool_stats_keys, sizeof(ethtool_stats_keys));
+ p += sizeof(ethtool_stats_keys);
+ break;
+ }
+}
+
+static int netkit_get_sset_count(struct net_device *dev, int sset)
+{
+ switch (sset) {
+ case ETH_SS_STATS:
+ return ARRAY_SIZE(ethtool_stats_keys);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static void netkit_get_ethtool_stats(struct net_device *dev,
+ struct ethtool_stats *stats, u64 *data)
+{
+ struct netkit *nk = netkit_priv(dev);
+ struct net_device *peer = rtnl_dereference(nk->peer);
+
+ data[0] = peer ? peer->ifindex : 0;
+}
+
+static int netkit_get_link_ksettings(struct net_device *dev,
+ struct ethtool_link_ksettings *cmd)
+{
+ cmd->base.speed = SPEED_10000;
+ cmd->base.duplex = DUPLEX_FULL;
+ cmd->base.port = PORT_TP;
+ cmd->base.autoneg = AUTONEG_DISABLE;
+ return 0;
+}
+
static const struct ethtool_ops netkit_ethtool_ops = {
.get_drvinfo = netkit_get_drvinfo,
+ .get_link = ethtool_op_get_link,
+ .get_strings = netkit_get_strings,
+ .get_sset_count = netkit_get_sset_count,
+ .get_ethtool_stats = netkit_get_ethtool_stats,
+ .get_link_ksettings = netkit_get_link_ksettings,
+ .get_ts_info = ethtool_op_get_ts_info,
};
static void netkit_setup(struct net_device *dev)
--
2.30.2
Powered by blists - more mailing lists