Skip to content

Commit af7b3b4

Browse files
committed
eth: bnxt: support per-queue statistics
Support per-queue statistics API in bnxt. $ ethtool -S eth0 NIC statistics: [0]: rx_ucast_packets: 1418 [0]: rx_mcast_packets: 178 [0]: rx_bcast_packets: 0 [0]: rx_discards: 0 [0]: rx_errors: 0 [0]: rx_ucast_bytes: 1141815 [0]: rx_mcast_bytes: 16766 [0]: rx_bcast_bytes: 0 [0]: tx_ucast_packets: 1734 ... $ ./cli.py --spec netlink/specs/netdev.yaml \ --dump qstats-get --json '{"scope": "queue"}' [{'ifindex': 2, 'queue-id': 0, 'queue-type': 'rx', 'rx-alloc-fail': 0, 'rx-bytes': 1164931, 'rx-packets': 1641}, ... {'ifindex': 2, 'queue-id': 0, 'queue-type': 'tx', 'tx-bytes': 631494, 'tx-packets': 1771}, ... Reset the per queue counters: $ ethtool -L eth0 combined 4 Inspect again: $ ./cli.py --spec netlink/specs/netdev.yaml \ --dump qstats-get --json '{"scope": "queue"}' [{'ifindex': 2, 'queue-id': 0, 'queue-type': 'rx', 'rx-alloc-fail': 0, 'rx-bytes': 32397, 'rx-packets': 145}, ... {'ifindex': 2, 'queue-id': 0, 'queue-type': 'tx', 'tx-bytes': 37481, 'tx-packets': 196}, ... $ ethtool -S eth0 | head NIC statistics: [0]: rx_ucast_packets: 174 [0]: rx_mcast_packets: 3 [0]: rx_bcast_packets: 0 [0]: rx_discards: 0 [0]: rx_errors: 0 [0]: rx_ucast_bytes: 37151 [0]: rx_mcast_bytes: 267 [0]: rx_bcast_bytes: 0 [0]: tx_ucast_packets: 267 ... Totals are still correct: $ ./cli.py --spec netlink/specs/netdev.yaml --dump qstats-get [{'ifindex': 2, 'rx-alloc-fail': 0, 'rx-bytes': 281949995, 'rx-packets': 216524, 'tx-bytes': 52694905, 'tx-packets': 75546}] $ ip -s link show dev eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 14:23:f2:61:05:40 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped missed mcast 282519546 218100 0 0 0 516 TX: bytes packets errors dropped carrier collsns 53323054 77674 0 0 0 0 Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Amritha Nambiar <[email protected]> Reviewed-by: Michael Chan <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 92f8b1f commit af7b3b4

File tree

1 file changed

+65
-0
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+65
-0
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14523,6 +14523,70 @@ static const struct net_device_ops bnxt_netdev_ops = {
1452314523
.ndo_bridge_setlink = bnxt_bridge_setlink,
1452414524
};
1452514525

14526+
static void bnxt_get_queue_stats_rx(struct net_device *dev, int i,
14527+
struct netdev_queue_stats_rx *stats)
14528+
{
14529+
struct bnxt *bp = netdev_priv(dev);
14530+
struct bnxt_cp_ring_info *cpr;
14531+
u64 *sw;
14532+
14533+
cpr = &bp->bnapi[i]->cp_ring;
14534+
sw = cpr->stats.sw_stats;
14535+
14536+
stats->packets = 0;
14537+
stats->packets += BNXT_GET_RING_STATS64(sw, rx_ucast_pkts);
14538+
stats->packets += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
14539+
stats->packets += BNXT_GET_RING_STATS64(sw, rx_bcast_pkts);
14540+
14541+
stats->bytes = 0;
14542+
stats->bytes += BNXT_GET_RING_STATS64(sw, rx_ucast_bytes);
14543+
stats->bytes += BNXT_GET_RING_STATS64(sw, rx_mcast_bytes);
14544+
stats->bytes += BNXT_GET_RING_STATS64(sw, rx_bcast_bytes);
14545+
14546+
stats->alloc_fail = cpr->sw_stats.rx.rx_oom_discards;
14547+
}
14548+
14549+
static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
14550+
struct netdev_queue_stats_tx *stats)
14551+
{
14552+
struct bnxt *bp = netdev_priv(dev);
14553+
struct bnxt_napi *bnapi;
14554+
u64 *sw;
14555+
14556+
bnapi = bp->tx_ring[bp->tx_ring_map[i]].bnapi;
14557+
sw = bnapi->cp_ring.stats.sw_stats;
14558+
14559+
stats->packets = 0;
14560+
stats->packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
14561+
stats->packets += BNXT_GET_RING_STATS64(sw, tx_mcast_pkts);
14562+
stats->packets += BNXT_GET_RING_STATS64(sw, tx_bcast_pkts);
14563+
14564+
stats->bytes = 0;
14565+
stats->bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
14566+
stats->bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
14567+
stats->bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
14568+
}
14569+
14570+
static void bnxt_get_base_stats(struct net_device *dev,
14571+
struct netdev_queue_stats_rx *rx,
14572+
struct netdev_queue_stats_tx *tx)
14573+
{
14574+
struct bnxt *bp = netdev_priv(dev);
14575+
14576+
rx->packets = bp->net_stats_prev.rx_packets;
14577+
rx->bytes = bp->net_stats_prev.rx_bytes;
14578+
rx->alloc_fail = bp->ring_err_stats_prev.rx_total_oom_discards;
14579+
14580+
tx->packets = bp->net_stats_prev.tx_packets;
14581+
tx->bytes = bp->net_stats_prev.tx_bytes;
14582+
}
14583+
14584+
static const struct netdev_stat_ops bnxt_stat_ops = {
14585+
.get_queue_stats_rx = bnxt_get_queue_stats_rx,
14586+
.get_queue_stats_tx = bnxt_get_queue_stats_tx,
14587+
.get_base_stats = bnxt_get_base_stats,
14588+
};
14589+
1452614590
static void bnxt_remove_one(struct pci_dev *pdev)
1452714591
{
1452814592
struct net_device *dev = pci_get_drvdata(pdev);
@@ -14970,6 +15034,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1497015034
goto init_err_free;
1497115035

1497215036
dev->netdev_ops = &bnxt_netdev_ops;
15037+
dev->stat_ops = &bnxt_stat_ops;
1497315038
dev->watchdog_timeo = BNXT_TX_TIMEOUT;
1497415039
dev->ethtool_ops = &bnxt_ethtool_ops;
1497515040
pci_set_drvdata(pdev, dev);

0 commit comments

Comments
 (0)