Commit 8be1bd91 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Jakub Kicinski

eth: fbnic: add support for basic qstats

Implement netdev_stat_ops and export the basic per-queue stats.

This interface expect users to set the values that are used
either to zero or to some other preserved value (they are 0xff by
default). So here we export bytes/packets/drops from tx and rx_stats
plus set some of the values that are exposed by queue stats
to zero.

  $ cd tools/testing/selftests/drivers/net && ./stats.py
  [...]
  Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0
Reviewed-by: default avatarJoe Damato <jdamato@fastly.com>
Signed-off-by: default avatarStanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20240810054322.2766421-3-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 45d84008
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/ipv6.h> #include <linux/ipv6.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/netdev_queues.h>
#include "fbnic.h" #include "fbnic.h"
#include "fbnic_netdev.h" #include "fbnic_netdev.h"
...@@ -395,6 +396,71 @@ static const struct net_device_ops fbnic_netdev_ops = { ...@@ -395,6 +396,71 @@ static const struct net_device_ops fbnic_netdev_ops = {
.ndo_get_stats64 = fbnic_get_stats64, .ndo_get_stats64 = fbnic_get_stats64,
}; };
static void fbnic_get_queue_stats_rx(struct net_device *dev, int idx,
struct netdev_queue_stats_rx *rx)
{
struct fbnic_net *fbn = netdev_priv(dev);
struct fbnic_ring *rxr = fbn->rx[idx];
struct fbnic_queue_stats *stats;
unsigned int start;
u64 bytes, packets;
if (!rxr)
return;
stats = &rxr->stats;
do {
start = u64_stats_fetch_begin(&stats->syncp);
bytes = stats->bytes;
packets = stats->packets;
} while (u64_stats_fetch_retry(&stats->syncp, start));
rx->bytes = bytes;
rx->packets = packets;
}
static void fbnic_get_queue_stats_tx(struct net_device *dev, int idx,
struct netdev_queue_stats_tx *tx)
{
struct fbnic_net *fbn = netdev_priv(dev);
struct fbnic_ring *txr = fbn->tx[idx];
struct fbnic_queue_stats *stats;
unsigned int start;
u64 bytes, packets;
if (!txr)
return;
stats = &txr->stats;
do {
start = u64_stats_fetch_begin(&stats->syncp);
bytes = stats->bytes;
packets = stats->packets;
} while (u64_stats_fetch_retry(&stats->syncp, start));
tx->bytes = bytes;
tx->packets = packets;
}
static void fbnic_get_base_stats(struct net_device *dev,
struct netdev_queue_stats_rx *rx,
struct netdev_queue_stats_tx *tx)
{
struct fbnic_net *fbn = netdev_priv(dev);
tx->bytes = fbn->tx_stats.bytes;
tx->packets = fbn->tx_stats.packets;
rx->bytes = fbn->rx_stats.bytes;
rx->packets = fbn->rx_stats.packets;
}
static const struct netdev_stat_ops fbnic_stat_ops = {
.get_queue_stats_rx = fbnic_get_queue_stats_rx,
.get_queue_stats_tx = fbnic_get_queue_stats_tx,
.get_base_stats = fbnic_get_base_stats,
};
void fbnic_reset_queues(struct fbnic_net *fbn, void fbnic_reset_queues(struct fbnic_net *fbn,
unsigned int tx, unsigned int rx) unsigned int tx, unsigned int rx)
{ {
...@@ -453,6 +519,7 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd) ...@@ -453,6 +519,7 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
fbd->netdev = netdev; fbd->netdev = netdev;
netdev->netdev_ops = &fbnic_netdev_ops; netdev->netdev_ops = &fbnic_netdev_ops;
netdev->stat_ops = &fbnic_stat_ops;
fbn = netdev_priv(netdev); fbn = netdev_priv(netdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment