Commit f90f8420 authored by Haiyang Zhang's avatar Haiyang Zhang Committed by David S. Miller

net: mana: Add counter for packet dropped by XDP

This counter will show up in ethtool stat data.
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 780bf05f
...@@ -48,7 +48,14 @@ enum TRI_STATE { ...@@ -48,7 +48,14 @@ enum TRI_STATE {
#define MAX_PORTS_IN_MANA_DEV 256 #define MAX_PORTS_IN_MANA_DEV 256
struct mana_stats { struct mana_stats_rx {
u64 packets;
u64 bytes;
u64 xdp_drop;
struct u64_stats_sync syncp;
};
struct mana_stats_tx {
u64 packets; u64 packets;
u64 bytes; u64 bytes;
struct u64_stats_sync syncp; struct u64_stats_sync syncp;
...@@ -76,7 +83,7 @@ struct mana_txq { ...@@ -76,7 +83,7 @@ struct mana_txq {
atomic_t pending_sends; atomic_t pending_sends;
struct mana_stats stats; struct mana_stats_tx stats;
}; };
/* skb data and frags dma mappings */ /* skb data and frags dma mappings */
...@@ -298,7 +305,7 @@ struct mana_rxq { ...@@ -298,7 +305,7 @@ struct mana_rxq {
u32 buf_index; u32 buf_index;
struct mana_stats stats; struct mana_stats_rx stats;
struct bpf_prog __rcu *bpf_prog; struct bpf_prog __rcu *bpf_prog;
struct xdp_rxq_info xdp_rxq; struct xdp_rxq_info xdp_rxq;
......
...@@ -136,7 +136,7 @@ int mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -136,7 +136,7 @@ int mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)
bool ipv4 = false, ipv6 = false; bool ipv4 = false, ipv6 = false;
struct mana_tx_package pkg = {}; struct mana_tx_package pkg = {};
struct netdev_queue *net_txq; struct netdev_queue *net_txq;
struct mana_stats *tx_stats; struct mana_stats_tx *tx_stats;
struct gdma_queue *gdma_sq; struct gdma_queue *gdma_sq;
unsigned int csum_type; unsigned int csum_type;
struct mana_txq *txq; struct mana_txq *txq;
...@@ -299,7 +299,8 @@ static void mana_get_stats64(struct net_device *ndev, ...@@ -299,7 +299,8 @@ static void mana_get_stats64(struct net_device *ndev,
{ {
struct mana_port_context *apc = netdev_priv(ndev); struct mana_port_context *apc = netdev_priv(ndev);
unsigned int num_queues = apc->num_queues; unsigned int num_queues = apc->num_queues;
struct mana_stats *stats; struct mana_stats_rx *rx_stats;
struct mana_stats_tx *tx_stats;
unsigned int start; unsigned int start;
u64 packets, bytes; u64 packets, bytes;
int q; int q;
...@@ -310,26 +311,26 @@ static void mana_get_stats64(struct net_device *ndev, ...@@ -310,26 +311,26 @@ static void mana_get_stats64(struct net_device *ndev,
netdev_stats_to_stats64(st, &ndev->stats); netdev_stats_to_stats64(st, &ndev->stats);
for (q = 0; q < num_queues; q++) { for (q = 0; q < num_queues; q++) {
stats = &apc->rxqs[q]->stats; rx_stats = &apc->rxqs[q]->stats;
do { do {
start = u64_stats_fetch_begin_irq(&stats->syncp); start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
packets = stats->packets; packets = rx_stats->packets;
bytes = stats->bytes; bytes = rx_stats->bytes;
} while (u64_stats_fetch_retry_irq(&stats->syncp, start)); } while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
st->rx_packets += packets; st->rx_packets += packets;
st->rx_bytes += bytes; st->rx_bytes += bytes;
} }
for (q = 0; q < num_queues; q++) { for (q = 0; q < num_queues; q++) {
stats = &apc->tx_qp[q].txq.stats; tx_stats = &apc->tx_qp[q].txq.stats;
do { do {
start = u64_stats_fetch_begin_irq(&stats->syncp); start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
packets = stats->packets; packets = tx_stats->packets;
bytes = stats->bytes; bytes = tx_stats->bytes;
} while (u64_stats_fetch_retry_irq(&stats->syncp, start)); } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
st->tx_packets += packets; st->tx_packets += packets;
st->tx_bytes += bytes; st->tx_bytes += bytes;
...@@ -986,7 +987,7 @@ static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len, ...@@ -986,7 +987,7 @@ static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len,
static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe, static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
struct mana_rxq *rxq) struct mana_rxq *rxq)
{ {
struct mana_stats *rx_stats = &rxq->stats; struct mana_stats_rx *rx_stats = &rxq->stats;
struct net_device *ndev = rxq->ndev; struct net_device *ndev = rxq->ndev;
uint pkt_len = cqe->ppi[0].pkt_len; uint pkt_len = cqe->ppi[0].pkt_len;
u16 rxq_idx = rxq->rxq_idx; u16 rxq_idx = rxq->rxq_idx;
...@@ -1007,7 +1008,7 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe, ...@@ -1007,7 +1008,7 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
act = mana_run_xdp(ndev, rxq, &xdp, buf_va, pkt_len); act = mana_run_xdp(ndev, rxq, &xdp, buf_va, pkt_len);
if (act != XDP_PASS && act != XDP_TX) if (act != XDP_PASS && act != XDP_TX)
goto drop; goto drop_xdp;
skb = mana_build_skb(buf_va, pkt_len, &xdp); skb = mana_build_skb(buf_va, pkt_len, &xdp);
...@@ -1048,9 +1049,15 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe, ...@@ -1048,9 +1049,15 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
u64_stats_update_end(&rx_stats->syncp); u64_stats_update_end(&rx_stats->syncp);
return; return;
drop_xdp:
u64_stats_update_begin(&rx_stats->syncp);
rx_stats->xdp_drop++;
u64_stats_update_end(&rx_stats->syncp);
drop: drop:
free_page((unsigned long)buf_va); free_page((unsigned long)buf_va);
++ndev->stats.rx_dropped; ++ndev->stats.rx_dropped;
return; return;
} }
......
...@@ -23,7 +23,7 @@ static int mana_get_sset_count(struct net_device *ndev, int stringset) ...@@ -23,7 +23,7 @@ static int mana_get_sset_count(struct net_device *ndev, int stringset)
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return -EINVAL; return -EINVAL;
return ARRAY_SIZE(mana_eth_stats) + num_queues * 4; return ARRAY_SIZE(mana_eth_stats) + num_queues * 5;
} }
static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
...@@ -46,6 +46,8 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) ...@@ -46,6 +46,8 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
p += ETH_GSTRING_LEN; p += ETH_GSTRING_LEN;
sprintf(p, "rx_%d_bytes", i); sprintf(p, "rx_%d_bytes", i);
p += ETH_GSTRING_LEN; p += ETH_GSTRING_LEN;
sprintf(p, "rx_%d_xdp_drop", i);
p += ETH_GSTRING_LEN;
} }
for (i = 0; i < num_queues; i++) { for (i = 0; i < num_queues; i++) {
...@@ -62,9 +64,11 @@ static void mana_get_ethtool_stats(struct net_device *ndev, ...@@ -62,9 +64,11 @@ static void mana_get_ethtool_stats(struct net_device *ndev,
struct mana_port_context *apc = netdev_priv(ndev); struct mana_port_context *apc = netdev_priv(ndev);
unsigned int num_queues = apc->num_queues; unsigned int num_queues = apc->num_queues;
void *eth_stats = &apc->eth_stats; void *eth_stats = &apc->eth_stats;
struct mana_stats *stats; struct mana_stats_rx *rx_stats;
struct mana_stats_tx *tx_stats;
unsigned int start; unsigned int start;
u64 packets, bytes; u64 packets, bytes;
u64 xdp_drop;
int q, i = 0; int q, i = 0;
if (!apc->port_is_up) if (!apc->port_is_up)
...@@ -74,26 +78,28 @@ static void mana_get_ethtool_stats(struct net_device *ndev, ...@@ -74,26 +78,28 @@ static void mana_get_ethtool_stats(struct net_device *ndev,
data[i++] = *(u64 *)(eth_stats + mana_eth_stats[q].offset); data[i++] = *(u64 *)(eth_stats + mana_eth_stats[q].offset);
for (q = 0; q < num_queues; q++) { for (q = 0; q < num_queues; q++) {
stats = &apc->rxqs[q]->stats; rx_stats = &apc->rxqs[q]->stats;
do { do {
start = u64_stats_fetch_begin_irq(&stats->syncp); start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
packets = stats->packets; packets = rx_stats->packets;
bytes = stats->bytes; bytes = rx_stats->bytes;
} while (u64_stats_fetch_retry_irq(&stats->syncp, start)); xdp_drop = rx_stats->xdp_drop;
} while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
data[i++] = packets; data[i++] = packets;
data[i++] = bytes; data[i++] = bytes;
data[i++] = xdp_drop;
} }
for (q = 0; q < num_queues; q++) { for (q = 0; q < num_queues; q++) {
stats = &apc->tx_qp[q].txq.stats; tx_stats = &apc->tx_qp[q].txq.stats;
do { do {
start = u64_stats_fetch_begin_irq(&stats->syncp); start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
packets = stats->packets; packets = tx_stats->packets;
bytes = stats->bytes; bytes = tx_stats->bytes;
} while (u64_stats_fetch_retry_irq(&stats->syncp, start)); } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
data[i++] = packets; data[i++] = packets;
data[i++] = bytes; data[i++] = bytes;
......
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