From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
Philo Lu <lulie@linux.alibaba.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Dong Yibo <dong100@mucse.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@redhat.com>,
Dust Li <dust.li@linux.alibaba.com>
Subject: [PATCH net-next v27 8/8] eea: introduce callback for ndo_get_stats64
Date: Fri, 27 Feb 2026 09:55:46 +0800 [thread overview]
Message-ID: <20260227015546.47336-9-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20260227015546.47336-1-xuanzhuo@linux.alibaba.com>
This commit introduces ndo_get_stats64 support.
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
Reviewed-by: Philo Lu <lulie@linux.alibaba.com>
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
drivers/net/ethernet/alibaba/eea/eea_net.c | 55 ++++++++++++++++++++++
drivers/net/ethernet/alibaba/eea/eea_net.h | 5 ++
2 files changed, 60 insertions(+)
diff --git a/drivers/net/ethernet/alibaba/eea/eea_net.c b/drivers/net/ethernet/alibaba/eea/eea_net.c
index 67bacd295693..182a57add015 100644
--- a/drivers/net/ethernet/alibaba/eea/eea_net.c
+++ b/drivers/net/ethernet/alibaba/eea/eea_net.c
@@ -107,6 +107,8 @@ static void eea_bind_q_and_cfg(struct eea_net *enet,
struct eea_net_tx *tx;
int i;
+ spin_lock(&enet->stats_lock);
+
enet->cfg = ctx->cfg;
enet->rx = ctx->rx;
enet->tx = ctx->tx;
@@ -126,6 +128,8 @@ static void eea_bind_q_and_cfg(struct eea_net *enet,
blk->rx = rx;
}
+
+ spin_unlock(&enet->stats_lock);
}
static void eea_unbind_q_and_cfg(struct eea_net *enet,
@@ -135,6 +139,8 @@ static void eea_unbind_q_and_cfg(struct eea_net *enet,
struct eea_net_rx *rx;
int i;
+ spin_lock(&enet->stats_lock);
+
ctx->cfg = enet->cfg;
ctx->rx = enet->rx;
ctx->tx = enet->tx;
@@ -151,6 +157,8 @@ static void eea_unbind_q_and_cfg(struct eea_net *enet,
blk->rx = NULL;
}
+
+ spin_unlock(&enet->stats_lock);
}
static void eea_free_rxtx_q_mem(struct eea_net_init_ctx *ctx)
@@ -337,6 +345,50 @@ static int eea_netdev_open(struct net_device *netdev)
return err;
}
+static void eea_stats(struct net_device *netdev, struct rtnl_link_stats64 *tot)
+{
+ struct eea_net *enet = netdev_priv(netdev);
+ u64 packets, bytes;
+ u32 start;
+ int i;
+
+ spin_lock(&enet->stats_lock);
+
+ if (enet->rx) {
+ for (i = 0; i < enet->cfg.rx_ring_num; i++) {
+ struct eea_net_rx *rx = enet->rx[i];
+
+ do {
+ start = u64_stats_fetch_begin(&rx->stats.syncp);
+ packets = u64_stats_read(&rx->stats.packets);
+ bytes = u64_stats_read(&rx->stats.bytes);
+ } while (u64_stats_fetch_retry(&rx->stats.syncp,
+ start));
+
+ tot->rx_packets += packets;
+ tot->rx_bytes += bytes;
+ }
+ }
+
+ if (enet->tx) {
+ for (i = 0; i < enet->cfg.tx_ring_num; i++) {
+ struct eea_net_tx *tx = &enet->tx[i];
+
+ do {
+ start = u64_stats_fetch_begin(&tx->stats.syncp);
+ packets = u64_stats_read(&tx->stats.packets);
+ bytes = u64_stats_read(&tx->stats.bytes);
+ } while (u64_stats_fetch_retry(&tx->stats.syncp,
+ start));
+
+ tot->tx_packets += packets;
+ tot->tx_bytes += bytes;
+ }
+ }
+
+ spin_unlock(&enet->stats_lock);
+}
+
/* resources: ring, buffers, irq */
int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx)
{
@@ -567,6 +619,7 @@ static const struct net_device_ops eea_netdev = {
.ndo_stop = eea_netdev_stop,
.ndo_start_xmit = eea_tx_xmit,
.ndo_validate_addr = eth_validate_addr,
+ .ndo_get_stats64 = eea_stats,
.ndo_features_check = passthru_features_check,
};
@@ -600,6 +653,8 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
return NULL;
}
+ spin_lock_init(&enet->stats_lock);
+
return enet;
}
diff --git a/drivers/net/ethernet/alibaba/eea/eea_net.h b/drivers/net/ethernet/alibaba/eea/eea_net.h
index fa14976aa335..cbfba365ad2a 100644
--- a/drivers/net/ethernet/alibaba/eea/eea_net.h
+++ b/drivers/net/ethernet/alibaba/eea/eea_net.h
@@ -162,6 +162,11 @@ struct eea_net {
u32 speed;
u64 hw_ts_offset;
+
+ /* Protect the tx and rx of struct eea_net, when eea_stats accesses the
+ * stats from rx and tx queues.
+ */
+ spinlock_t stats_lock;
};
int eea_net_probe(struct eea_device *edev);
--
2.32.0.3.g01195cf9f
prev parent reply other threads:[~2026-02-27 1:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 1:55 [PATCH net-next v27 0/8] eea: Add basic driver framework for Alibaba Elastic Ethernet Adaptor Xuan Zhuo
2026-02-27 1:55 ` [PATCH net-next v27 1/8] eea: introduce PCI framework Xuan Zhuo
2026-02-27 1:55 ` [PATCH net-next v27 2/8] eea: introduce ring and descriptor structures Xuan Zhuo
2026-02-27 1:55 ` [PATCH net-next v27 3/8] eea: probe the netdevice and create adminq Xuan Zhuo
2026-02-27 1:55 ` [PATCH net-next v27 4/8] eea: create/destroy rx,tx queues for netdevice open and stop Xuan Zhuo
2026-02-28 23:55 ` [net-next,v27,4/8] " Jakub Kicinski
2026-02-27 1:55 ` [PATCH net-next v27 5/8] eea: implement packet receive logic Xuan Zhuo
2026-02-28 23:55 ` [net-next,v27,5/8] " Jakub Kicinski
2026-02-27 1:55 ` [PATCH net-next v27 6/8] eea: implement packet transmit logic Xuan Zhuo
2026-02-27 1:55 ` [PATCH net-next v27 7/8] eea: introduce ethtool support Xuan Zhuo
2026-02-27 1:55 ` Xuan Zhuo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260227015546.47336-9-xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dong100@mucse.com \
--cc=dust.li@linux.alibaba.com \
--cc=edumazet@google.com \
--cc=guwen@linux.alibaba.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=lorenzo@kernel.org \
--cc=lukas.bulwahn@redhat.com \
--cc=lulie@linux.alibaba.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox