Olaf Hering c9d12f
From: Haiyang Zhang <haiyangz@microsoft.com>
Olaf Hering c9d12f
Date: Fri, 28 Jan 2022 18:03:36 -0800
Olaf Hering c9d12f
Patch-mainline: v5.18-rc1
Olaf Hering c9d12f
Subject: net: mana: Add counter for packet dropped by XDP
Olaf Hering c9d12f
Git-commit: f90f84201edde2bca25a73226ff0ebe765273890
Olaf Hering c9d12f
References: bsc#1195651
Olaf Hering c9d12f
Olaf Hering c9d12f
This counter will show up in ethtool stat data.
Olaf Hering c9d12f
Olaf Hering c9d12f
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Olaf Hering c9d12f
Signed-off-by: David S. Miller <davem@davemloft.net>
Olaf Hering c9d12f
Acked-by: Olaf Hering <ohering@suse.de>
Olaf Hering c9d12f
---
Olaf Hering c9d12f
 drivers/net/ethernet/microsoft/mana/mana.h         | 13 ++++++--
Olaf Hering c9d12f
 drivers/net/ethernet/microsoft/mana/mana_en.c      | 35 +++++++++++++---------
Olaf Hering c9d12f
 drivers/net/ethernet/microsoft/mana/mana_ethtool.c | 30 +++++++++++--------
Olaf Hering c9d12f
 3 files changed, 49 insertions(+), 29 deletions(-)
Olaf Hering c9d12f
Olaf Hering c9d12f
diff --git a/drivers/net/ethernet/microsoft/mana/mana.h b/drivers/net/ethernet/microsoft/mana/mana.h
Olaf Hering c9d12f
--- a/drivers/net/ethernet/microsoft/mana/mana.h
Olaf Hering c9d12f
+++ b/drivers/net/ethernet/microsoft/mana/mana.h
Olaf Hering c9d12f
@@ -48,7 +48,14 @@ enum TRI_STATE {
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 #define MAX_PORTS_IN_MANA_DEV 256
Olaf Hering c9d12f
 
Olaf Hering c9d12f
-struct mana_stats {
Olaf Hering c9d12f
+struct mana_stats_rx {
Olaf Hering c9d12f
+	u64 packets;
Olaf Hering c9d12f
+	u64 bytes;
Olaf Hering c9d12f
+	u64 xdp_drop;
Olaf Hering c9d12f
+	struct u64_stats_sync syncp;
Olaf Hering c9d12f
+};
Olaf Hering c9d12f
+
Olaf Hering c9d12f
+struct mana_stats_tx {
Olaf Hering c9d12f
 	u64 packets;
Olaf Hering c9d12f
 	u64 bytes;
Olaf Hering c9d12f
 	struct u64_stats_sync syncp;
Olaf Hering c9d12f
@@ -76,7 +83,7 @@ struct mana_txq {
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	atomic_t pending_sends;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
-	struct mana_stats stats;
Olaf Hering c9d12f
+	struct mana_stats_tx stats;
Olaf Hering c9d12f
 };
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 /* skb data and frags dma mappings */
Olaf Hering c9d12f
@@ -298,7 +305,7 @@ struct mana_rxq {
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	u32 buf_index;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
-	struct mana_stats stats;
Olaf Hering c9d12f
+	struct mana_stats_rx stats;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	struct bpf_prog __rcu *bpf_prog;
Olaf Hering c9d12f
 	struct xdp_rxq_info xdp_rxq;
Olaf Hering c9d12f
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
Olaf Hering c9d12f
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
Olaf Hering c9d12f
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
Olaf Hering c9d12f
@@ -136,7 +136,7 @@ int mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)
Olaf Hering c9d12f
 	bool ipv4 = false, ipv6 = false;
Olaf Hering c9d12f
 	struct mana_tx_package pkg = {};
Olaf Hering c9d12f
 	struct netdev_queue *net_txq;
Olaf Hering c9d12f
-	struct mana_stats *tx_stats;
Olaf Hering c9d12f
+	struct mana_stats_tx *tx_stats;
Olaf Hering c9d12f
 	struct gdma_queue *gdma_sq;
Olaf Hering c9d12f
 	unsigned int csum_type;
Olaf Hering c9d12f
 	struct mana_txq *txq;
Olaf Hering c9d12f
@@ -299,7 +299,8 @@ static void mana_get_stats64(struct net_device *ndev,
Olaf Hering c9d12f
 {
Olaf Hering c9d12f
 	struct mana_port_context *apc = netdev_priv(ndev);
Olaf Hering c9d12f
 	unsigned int num_queues = apc->num_queues;
Olaf Hering c9d12f
-	struct mana_stats *stats;
Olaf Hering c9d12f
+	struct mana_stats_rx *rx_stats;
Olaf Hering c9d12f
+	struct mana_stats_tx *tx_stats;
Olaf Hering c9d12f
 	unsigned int start;
Olaf Hering c9d12f
 	u64 packets, bytes;
Olaf Hering c9d12f
 	int q;
Olaf Hering c9d12f
@@ -310,26 +311,26 @@ static void mana_get_stats64(struct net_device *ndev,
Olaf Hering c9d12f
 	netdev_stats_to_stats64(st, &ndev->stats);
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	for (q = 0; q < num_queues; q++) {
Olaf Hering c9d12f
-		stats = &apc->rxqs[q]->stats;
Olaf Hering c9d12f
+		rx_stats = &apc->rxqs[q]->stats;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		do {
Olaf Hering c9d12f
-			start = u64_stats_fetch_begin_irq(&stats->syncp);
Olaf Hering c9d12f
-			packets = stats->packets;
Olaf Hering c9d12f
-			bytes = stats->bytes;
Olaf Hering c9d12f
-		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));
Olaf Hering c9d12f
+			start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
Olaf Hering c9d12f
+			packets = rx_stats->packets;
Olaf Hering c9d12f
+			bytes = rx_stats->bytes;
Olaf Hering c9d12f
+		} while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		st->rx_packets += packets;
Olaf Hering c9d12f
 		st->rx_bytes += bytes;
Olaf Hering c9d12f
 	}
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	for (q = 0; q < num_queues; q++) {
Olaf Hering c9d12f
-		stats = &apc->tx_qp[q].txq.stats;
Olaf Hering c9d12f
+		tx_stats = &apc->tx_qp[q].txq.stats;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		do {
Olaf Hering c9d12f
-			start = u64_stats_fetch_begin_irq(&stats->syncp);
Olaf Hering c9d12f
-			packets = stats->packets;
Olaf Hering c9d12f
-			bytes = stats->bytes;
Olaf Hering c9d12f
-		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));
Olaf Hering c9d12f
+			start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
Olaf Hering c9d12f
+			packets = tx_stats->packets;
Olaf Hering c9d12f
+			bytes = tx_stats->bytes;
Olaf Hering c9d12f
+		} while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		st->tx_packets += packets;
Olaf Hering c9d12f
 		st->tx_bytes += bytes;
Olaf Hering c9d12f
@@ -986,7 +987,7 @@ static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len,
Olaf Hering c9d12f
 static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
Olaf Hering c9d12f
 			struct mana_rxq *rxq)
Olaf Hering c9d12f
 {
Olaf Hering c9d12f
-	struct mana_stats *rx_stats = &rxq->stats;
Olaf Hering c9d12f
+	struct mana_stats_rx *rx_stats = &rxq->stats;
Olaf Hering c9d12f
 	struct net_device *ndev = rxq->ndev;
Olaf Hering c9d12f
 	uint pkt_len = cqe->ppi[0].pkt_len;
Olaf Hering c9d12f
 	u16 rxq_idx = rxq->rxq_idx;
Olaf Hering c9d12f
@@ -1007,7 +1008,7 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
Olaf Hering c9d12f
 	act = mana_run_xdp(ndev, rxq, &xdp, buf_va, pkt_len);
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	if (act != XDP_PASS && act != XDP_TX)
Olaf Hering c9d12f
-		goto drop;
Olaf Hering c9d12f
+		goto drop_xdp;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	skb = mana_build_skb(buf_va, pkt_len, &xdp;;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
@@ -1048,9 +1049,15 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
Olaf Hering c9d12f
 	u64_stats_update_end(&rx_stats->syncp);
Olaf Hering c9d12f
 	return;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
+drop_xdp:
Olaf Hering c9d12f
+	u64_stats_update_begin(&rx_stats->syncp);
Olaf Hering c9d12f
+	rx_stats->xdp_drop++;
Olaf Hering c9d12f
+	u64_stats_update_end(&rx_stats->syncp);
Olaf Hering c9d12f
+
Olaf Hering c9d12f
 drop:
Olaf Hering c9d12f
 	free_page((unsigned long)buf_va);
Olaf Hering c9d12f
 	++ndev->stats.rx_dropped;
Olaf Hering c9d12f
+
Olaf Hering c9d12f
 	return;
Olaf Hering c9d12f
 }
Olaf Hering c9d12f
 
Olaf Hering c9d12f
diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
Olaf Hering c9d12f
--- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
Olaf Hering c9d12f
+++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
Olaf Hering c9d12f
@@ -23,7 +23,7 @@ static int mana_get_sset_count(struct net_device *ndev, int stringset)
Olaf Hering c9d12f
 	if (stringset != ETH_SS_STATS)
Olaf Hering c9d12f
 		return -EINVAL;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
-	return ARRAY_SIZE(mana_eth_stats) + num_queues * 4;
Olaf Hering c9d12f
+	return ARRAY_SIZE(mana_eth_stats) + num_queues * 5;
Olaf Hering c9d12f
 }
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
Olaf Hering c9d12f
@@ -46,6 +46,8 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
Olaf Hering c9d12f
 		p += ETH_GSTRING_LEN;
Olaf Hering c9d12f
 		sprintf(p, "rx_%d_bytes", i);
Olaf Hering c9d12f
 		p += ETH_GSTRING_LEN;
Olaf Hering c9d12f
+		sprintf(p, "rx_%d_xdp_drop", i);
Olaf Hering c9d12f
+		p += ETH_GSTRING_LEN;
Olaf Hering c9d12f
 	}
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	for (i = 0; i < num_queues; i++) {
Olaf Hering c9d12f
@@ -62,9 +64,11 @@ static void mana_get_ethtool_stats(struct net_device *ndev,
Olaf Hering c9d12f
 	struct mana_port_context *apc = netdev_priv(ndev);
Olaf Hering c9d12f
 	unsigned int num_queues = apc->num_queues;
Olaf Hering c9d12f
 	void *eth_stats = &apc->eth_stats;
Olaf Hering c9d12f
-	struct mana_stats *stats;
Olaf Hering c9d12f
+	struct mana_stats_rx *rx_stats;
Olaf Hering c9d12f
+	struct mana_stats_tx *tx_stats;
Olaf Hering c9d12f
 	unsigned int start;
Olaf Hering c9d12f
 	u64 packets, bytes;
Olaf Hering c9d12f
+	u64 xdp_drop;
Olaf Hering c9d12f
 	int q, i = 0;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	if (!apc->port_is_up)
Olaf Hering c9d12f
@@ -74,26 +78,28 @@ static void mana_get_ethtool_stats(struct net_device *ndev,
Olaf Hering c9d12f
 		data[i++] = *(u64 *)(eth_stats + mana_eth_stats[q].offset);
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	for (q = 0; q < num_queues; q++) {
Olaf Hering c9d12f
-		stats = &apc->rxqs[q]->stats;
Olaf Hering c9d12f
+		rx_stats = &apc->rxqs[q]->stats;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		do {
Olaf Hering c9d12f
-			start = u64_stats_fetch_begin_irq(&stats->syncp);
Olaf Hering c9d12f
-			packets = stats->packets;
Olaf Hering c9d12f
-			bytes = stats->bytes;
Olaf Hering c9d12f
-		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));
Olaf Hering c9d12f
+			start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
Olaf Hering c9d12f
+			packets = rx_stats->packets;
Olaf Hering c9d12f
+			bytes = rx_stats->bytes;
Olaf Hering c9d12f
+			xdp_drop = rx_stats->xdp_drop;
Olaf Hering c9d12f
+		} while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		data[i++] = packets;
Olaf Hering c9d12f
 		data[i++] = bytes;
Olaf Hering c9d12f
+		data[i++] = xdp_drop;
Olaf Hering c9d12f
 	}
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 	for (q = 0; q < num_queues; q++) {
Olaf Hering c9d12f
-		stats = &apc->tx_qp[q].txq.stats;
Olaf Hering c9d12f
+		tx_stats = &apc->tx_qp[q].txq.stats;
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		do {
Olaf Hering c9d12f
-			start = u64_stats_fetch_begin_irq(&stats->syncp);
Olaf Hering c9d12f
-			packets = stats->packets;
Olaf Hering c9d12f
-			bytes = stats->bytes;
Olaf Hering c9d12f
-		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));
Olaf Hering c9d12f
+			start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
Olaf Hering c9d12f
+			packets = tx_stats->packets;
Olaf Hering c9d12f
+			bytes = tx_stats->bytes;
Olaf Hering c9d12f
+		} while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
Olaf Hering c9d12f
 
Olaf Hering c9d12f
 		data[i++] = packets;
Olaf Hering c9d12f
 		data[i++] = bytes;