gem_xdp_run() returns an action. Wrt stats, we land in three different cases: - Packet is handed to the stack (XDP_PASS), turns into an SKB and gets accounted for below in gem_rx(). No fix here. - Packet is dropped (XDP_DROP|ABORTED), we must increment the dropped counter. Missing; add it. - Packet is passed along (XDP_TX|REDIRECT), we must increment bytes & packets counters. Missing; add it. Along the way, use local variables to store rx_bytes, rx_packets and rx_dropped. Then increase stats only once at the end of gem_rx(). This is simpler because all three stats must modified on a per interface and per queue basis. Signed-off-by: Théo Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 37 +++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 05bbbaf260ce..01b4299dc34b 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1548,6 +1548,7 @@ static u32 gem_xdp_run(struct macb_queue *queue, void *buff_head, static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + unsigned int packets = 0, dropped = 0, bytes = 0; struct skb_shared_info *shinfo; struct macb *bp = queue->bp; struct macb_dma_desc *desc; @@ -1595,8 +1596,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, if (unlikely(!buff_head)) { netdev_err(bp->dev, "inconsistent Rx descriptor chain\n"); - bp->dev->stats.rx_dropped++; - queue->stats.rx_dropped++; + dropped++; break; } @@ -1613,10 +1613,21 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, if (first_frame && last_frame) { ret = gem_xdp_run(queue, buff_head, data_len, addr); - if (ret == XDP_REDIRECT) - xdp_flush = true; - if (ret != XDP_PASS) { + switch (ret) { + case XDP_PASS: + break; /* fallthrough to SKB handling */ + case XDP_ABORTED: + case XDP_DROP: + dropped++; + queue->rx_buff[entry] = NULL; + continue; + case XDP_REDIRECT: + xdp_flush = true; + fallthrough; + case XDP_TX: + packets++; + bytes += data_len; queue->rx_buff[entry] = NULL; continue; } @@ -1672,10 +1683,8 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, /* now everything is ready for receiving packet */ if (last_frame) { - bp->dev->stats.rx_packets++; - queue->stats.rx_packets++; - bp->dev->stats.rx_bytes += queue->skb->len; - queue->stats.rx_bytes += queue->skb->len; + packets++; + bytes += queue->skb->len; gem_ptp_do_rxstamp(bp, queue->skb, desc); #if defined(DEBUG) && defined(VERBOSE_DEBUG) @@ -1704,11 +1713,17 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, false); } - bp->dev->stats.rx_dropped++; - queue->stats.rx_dropped++; + dropped++; queue->rx_buff[entry] = NULL; } + bp->dev->stats.rx_packets += packets; + queue->stats.rx_packets += packets; + bp->dev->stats.rx_dropped += dropped; + queue->stats.rx_dropped += dropped; + bp->dev->stats.rx_bytes += bytes; + queue->stats.rx_bytes += bytes; + if (xdp_flush) xdp_do_flush(); -- 2.53.0