From: Bhargava Marreddy <bhargava.marreddy@broadcom.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
michael.chan@broadcom.com, pavan.chebbi@broadcom.com,
vsrama-krishna.nemani@broadcom.com, vikas.gupta@broadcom.com,
Bhargava Marreddy <bhargava.marreddy@broadcom.com>
Subject: [PATCH net-next v6 09/10] bng_en: implement netdev_stat_ops
Date: Tue, 10 Mar 2026 20:10:43 +0530 [thread overview]
Message-ID: <20260310144044.21672-10-bhargava.marreddy@broadcom.com> (raw)
In-Reply-To: <20260310144044.21672-1-bhargava.marreddy@broadcom.com>
Implement netdev_stat_ops to provide standardized per-queue
statistics via the Netlink API.
The implementation was verified using the ynl tool:
$ ./cli.py --spec netlink/specs/netdev.yaml --dump \
qstats-get --json '{"ifindex":5, "scope":"queue"}'
[{'ifindex': 5, 'queue-id': 0, 'queue-type': 'rx',
'rx-alloc-fail': 0, 'rx-bytes': 1024, 'rx-packets': 10},
{'ifindex': 5, 'queue-id': 1, 'queue-type': 'rx',
'rx-alloc-fail': 0, 'rx-bytes': 2048, 'rx-packets': 20},
{'ifindex': 5, 'queue-id': 0, 'queue-type': 'tx',
'tx-bytes': 512, 'tx-packets': 5},
{'ifindex': 5, 'queue-id': 1, 'queue-type': 'tx',
'tx-bytes': 1536, 'tx-packets': 15}]
Signed-off-by: Bhargava Marreddy <bhargava.marreddy@broadcom.com>
Reviewed-by: Vikas Gupta <vikas.gupta@broadcom.com>
---
.../net/ethernet/broadcom/bnge/bnge_netdev.c | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
index 03872bde4cd0..4925d31fc152 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
@@ -3071,6 +3071,76 @@ void bnge_get_ring_err_stats(struct bnge_net *bn,
&bn->bnapi[i]->nq_ring);
}
+static void bnge_get_queue_stats_rx(struct net_device *dev, int i,
+ struct netdev_queue_stats_rx *stats)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+ struct bnge_nq_ring_info *nqr;
+ u64 *sw;
+
+ if (!bn->bnapi)
+ return;
+
+ nqr = &bn->bnapi[i]->nq_ring;
+ sw = nqr->stats.sw_stats;
+
+ stats->packets = 0;
+ stats->packets += BNGE_GET_RING_STATS64(sw, rx_ucast_pkts);
+ stats->packets += BNGE_GET_RING_STATS64(sw, rx_mcast_pkts);
+ stats->packets += BNGE_GET_RING_STATS64(sw, rx_bcast_pkts);
+
+ stats->bytes = 0;
+ stats->bytes += BNGE_GET_RING_STATS64(sw, rx_ucast_bytes);
+ stats->bytes += BNGE_GET_RING_STATS64(sw, rx_mcast_bytes);
+ stats->bytes += BNGE_GET_RING_STATS64(sw, rx_bcast_bytes);
+
+ stats->alloc_fail = nqr->sw_stats->rx.rx_oom_discards;
+}
+
+static void bnge_get_queue_stats_tx(struct net_device *dev, int i,
+ struct netdev_queue_stats_tx *stats)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+ struct bnge_napi *bnapi;
+ u64 *sw;
+
+ if (!bn->tx_ring)
+ return;
+
+ bnapi = bn->tx_ring[bn->tx_ring_map[i]].bnapi;
+ sw = bnapi->nq_ring.stats.sw_stats;
+
+ stats->packets = 0;
+ stats->packets += BNGE_GET_RING_STATS64(sw, tx_ucast_pkts);
+ stats->packets += BNGE_GET_RING_STATS64(sw, tx_mcast_pkts);
+ stats->packets += BNGE_GET_RING_STATS64(sw, tx_bcast_pkts);
+
+ stats->bytes = 0;
+ stats->bytes += BNGE_GET_RING_STATS64(sw, tx_ucast_bytes);
+ stats->bytes += BNGE_GET_RING_STATS64(sw, tx_mcast_bytes);
+ stats->bytes += BNGE_GET_RING_STATS64(sw, tx_bcast_bytes);
+}
+
+static void bnge_get_base_stats(struct net_device *dev,
+ struct netdev_queue_stats_rx *rx,
+ struct netdev_queue_stats_tx *tx)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+
+ rx->packets = bn->net_stats_prev.rx_packets;
+ rx->bytes = bn->net_stats_prev.rx_bytes;
+ rx->alloc_fail = bn->ring_err_stats_prev.rx_total_oom_discards;
+
+ tx->packets = bn->net_stats_prev.tx_packets;
+ tx->bytes = bn->net_stats_prev.tx_bytes;
+}
+
+static const struct netdev_stat_ops bnge_stat_ops = {
+ .get_queue_stats_rx = bnge_get_queue_stats_rx,
+ .get_queue_stats_tx = bnge_get_queue_stats_tx,
+ .get_base_stats = bnge_get_base_stats,
+};
+
static const struct net_device_ops bnge_netdev_ops = {
.ndo_open = bnge_open,
.ndo_stop = bnge_close,
@@ -3234,6 +3304,7 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs)
bd->netdev = netdev;
netdev->netdev_ops = &bnge_netdev_ops;
+ netdev->stat_ops = &bnge_stat_ops;
bnge_set_ethtool_ops(netdev);
--
2.47.3
next prev parent reply other threads:[~2026-03-10 14:42 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 14:40 [PATCH net-next v6 00/10] bng_en: add link management and statistics support Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 01/10] bng_en: add per-PF workqueue, timer, and slow-path task Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 02/10] bng_en: query PHY capabilities and report link status Bhargava Marreddy
2026-03-11 15:44 ` ALOK TIWARI
2026-03-13 2:18 ` [net-next,v6,02/10] " Jakub Kicinski
2026-03-10 14:40 ` [PATCH net-next v6 03/10] bng_en: add ethtool link settings, get_link, and nway_reset Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 04/10] bng_en: implement ethtool pauseparam operations Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 05/10] bng_en: add support for link async events Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 06/10] bng_en: add HW stats infra and structured ethtool ops Bhargava Marreddy
2026-03-18 7:47 ` Dan Carpenter
2026-03-10 14:40 ` [PATCH net-next v6 07/10] bng_en: periodically fetch and accumulate hardware statistics Bhargava Marreddy
2026-03-10 14:40 ` [PATCH net-next v6 08/10] bng_en: implement ndo_get_stats64 Bhargava Marreddy
2026-03-10 14:40 ` Bhargava Marreddy [this message]
2026-03-10 14:40 ` [PATCH net-next v6 10/10] bng_en: add support for ethtool -S stats display Bhargava Marreddy
2026-03-12 7:01 ` ALOK TIWARI
2026-03-13 2:22 ` Jakub Kicinski
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=20260310144044.21672-10-bhargava.marreddy@broadcom.com \
--to=bhargava.marreddy@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=vikas.gupta@broadcom.com \
--cc=vsrama-krishna.nemani@broadcom.com \
/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