]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bng_en: implement ndo_get_stats64
authorBhargava Marreddy <bhargava.marreddy@broadcom.com>
Mon, 6 Apr 2026 18:04:18 +0000 (23:34 +0530)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 18:09:37 +0000 (11:09 -0700)
Implement the ndo_get_stats64 callback to report aggregate network
statistics. The driver gathers these by accumulating the per-ring
counters into the provided rtnl_link_stats64 structure.

Signed-off-by: Bhargava Marreddy <bhargava.marreddy@broadcom.com>
Reviewed-by: Vikas Gupta <vikas.gupta@broadcom.com>
Link: https://patch.msgid.link/20260406180420.279470-9-bhargava.marreddy@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c

index 6f41dff3fbcba8a8718c634cbd98b56acc691bd8..4148a9ec6d23e5b4a5b4e170445301d577442272 100644 (file)
@@ -2898,6 +2898,46 @@ static int bnge_shutdown_nic(struct bnge_net *bn)
        return 0;
 }
 
+static void bnge_get_port_stats64(struct bnge_net *bn,
+                                 struct rtnl_link_stats64 *stats)
+{
+       unsigned int start;
+       u64 *tx, *rx;
+
+       rx = bn->port_stats.sw_stats;
+       tx = bn->port_stats.sw_stats + BNGE_TX_PORT_STATS_BYTE_OFFSET / 8;
+
+       do {
+               start = u64_stats_fetch_begin(&bn->port_stats.syncp);
+
+               stats->rx_crc_errors =
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_fcs_err_frames);
+               stats->rx_frame_errors =
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_align_err_frames);
+               stats->rx_length_errors =
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_undrsz_frames) +
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_ovrsz_frames) +
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_runt_frames);
+               stats->rx_errors =
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_false_carrier_frames) +
+                       BNGE_GET_RX_PORT_STATS64(rx, rx_jbr_frames);
+               stats->collisions =
+                       BNGE_GET_TX_PORT_STATS64(tx, tx_total_collisions);
+               stats->tx_fifo_errors =
+                       BNGE_GET_TX_PORT_STATS64(tx, tx_fifo_underruns);
+               stats->tx_errors = BNGE_GET_TX_PORT_STATS64(tx, tx_err);
+       } while (u64_stats_fetch_retry(&bn->port_stats.syncp, start));
+}
+
+static void bnge_get_stats64(struct net_device *dev,
+                            struct rtnl_link_stats64 *stats)
+{
+       struct bnge_net *bn = netdev_priv(dev);
+
+       if (bn->flags & BNGE_FLAG_PORT_STATS)
+               bnge_get_port_stats64(bn, stats);
+}
+
 static void bnge_close_core(struct bnge_net *bn)
 {
        struct bnge_dev *bd = bn->bd;
@@ -2931,6 +2971,7 @@ static const struct net_device_ops bnge_netdev_ops = {
        .ndo_open               = bnge_open,
        .ndo_stop               = bnge_close,
        .ndo_start_xmit         = bnge_start_xmit,
+       .ndo_get_stats64        = bnge_get_stats64,
        .ndo_features_check     = bnge_features_check,
 };