[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211123163955.154512-8-alexandr.lobakin@intel.com>
Date: Tue, 23 Nov 2021 17:39:36 +0100
From: Alexander Lobakin <alexandr.lobakin@...el.com>
To: "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: Alexander Lobakin <alexandr.lobakin@...el.com>,
Jesse Brandeburg <jesse.brandeburg@...el.com>,
Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
Jonathan Corbet <corbet@....net>,
Shay Agroskin <shayagr@...zon.com>,
Arthur Kiyanovski <akiyano@...zon.com>,
David Arinzon <darinzon@...zon.com>,
Noam Dagan <ndagan@...zon.com>,
Saeed Bishara <saeedb@...zon.com>,
Ioana Ciornei <ioana.ciornei@....com>,
Claudiu Manoil <claudiu.manoil@....com>,
Tony Nguyen <anthony.l.nguyen@...el.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
Marcin Wojtas <mw@...ihalf.com>,
Russell King <linux@...linux.org.uk>,
Saeed Mahameed <saeedm@...dia.com>,
Leon Romanovsky <leon@...nel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
Toke Høiland-Jørgensen <toke@...hat.com>,
John Fastabend <john.fastabend@...il.com>,
Edward Cree <ecree.xilinx@...il.com>,
Martin Habets <habetsm.xilinx@...il.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
KP Singh <kpsingh@...nel.org>,
Lorenzo Bianconi <lorenzo@...nel.org>,
Yajun Deng <yajun.deng@...ux.dev>,
Sergey Ryazanov <ryazanov.s.a@...il.com>,
David Ahern <dsahern@...nel.org>,
Andrei Vagin <avagin@...il.com>,
Johannes Berg <johannes.berg@...el.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Cong Wang <cong.wang@...edance.com>, netdev@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-rdma@...r.kernel.org, bpf@...r.kernel.org,
virtualization@...ts.linux-foundation.org
Subject: [PATCH v2 net-next 07/26] mvneta: add .ndo_get_xdp_stats() callback
mvneta driver implements 7 per-cpu counters which means we can
only provide them as a global sum across CPUs.
Implement a callback for querying them using generic XDP stats
infra.
Signed-off-by: Alexander Lobakin <alexandr.lobakin@...el.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@...el.com>
---
drivers/net/ethernet/marvell/mvneta.c | 54 +++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index 7c30417a0464..5bb0bbfa1ee6 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -802,6 +802,59 @@ mvneta_get_stats64(struct net_device *dev,
stats->tx_dropped = dev->stats.tx_dropped;
}
+static int mvneta_get_xdp_stats(const struct net_device *dev, u32 attr_id,
+ void *attr_data)
+{
+ const struct mvneta_port *pp = netdev_priv(dev);
+ struct ifla_xdp_stats *xdp_stats = attr_data;
+ u32 cpu;
+
+ switch (attr_id) {
+ case IFLA_XDP_XSTATS_TYPE_XDP:
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ for_each_possible_cpu(cpu) {
+ const struct mvneta_pcpu_stats *stats;
+ const struct mvneta_stats *ps;
+ u64 xdp_xmit_err;
+ u64 xdp_redirect;
+ u64 xdp_tx_err;
+ u64 xdp_pass;
+ u64 xdp_drop;
+ u64 xdp_xmit;
+ u64 xdp_tx;
+ u32 start;
+
+ stats = per_cpu_ptr(pp->stats, cpu);
+ ps = &stats->es.ps;
+
+ do {
+ start = u64_stats_fetch_begin_irq(&stats->syncp);
+
+ xdp_drop = ps->xdp_drop;
+ xdp_pass = ps->xdp_pass;
+ xdp_redirect = ps->xdp_redirect;
+ xdp_tx = ps->xdp_tx;
+ xdp_tx_err = ps->xdp_tx_err;
+ xdp_xmit = ps->xdp_xmit;
+ xdp_xmit_err = ps->xdp_xmit_err;
+ } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
+
+ xdp_stats->drop += xdp_drop;
+ xdp_stats->pass += xdp_pass;
+ xdp_stats->redirect += xdp_redirect;
+ xdp_stats->tx += xdp_tx;
+ xdp_stats->tx_errors += xdp_tx_err;
+ xdp_stats->xmit_packets += xdp_xmit;
+ xdp_stats->xmit_errors += xdp_xmit_err;
+ }
+
+ return 0;
+}
+
/* Rx descriptors helper methods */
/* Checks whether the RX descriptor having this status is both the first
@@ -4957,6 +5010,7 @@ static const struct net_device_ops mvneta_netdev_ops = {
.ndo_change_mtu = mvneta_change_mtu,
.ndo_fix_features = mvneta_fix_features,
.ndo_get_stats64 = mvneta_get_stats64,
+ .ndo_get_xdp_stats = mvneta_get_xdp_stats,
.ndo_eth_ioctl = mvneta_ioctl,
.ndo_bpf = mvneta_xdp,
.ndo_xdp_xmit = mvneta_xdp_xmit,
--
2.33.1
Powered by blists - more mailing lists