[PATCH net-next v4 08/10] net: ntb_netdev: Factor out RX statistics update

From: Koichiro Den

Date: Mon Sep 14 2026 - 05:05:39 EST


Move RX packet and byte accounting into a helper for the packet-header
handling added by the next patch.

No functional change.

Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
---
Changes in v4:
- New patch.

For reviewers: I split this out for easier review, but I'm happy to fold
it into the next patch if preferred.

drivers/net/ntb_netdev.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ntb_netdev.c b/drivers/net/ntb_netdev.c
index 84fdd81ebd16..cddfe8d63fc1 100644
--- a/drivers/net/ntb_netdev.c
+++ b/drivers/net/ntb_netdev.c
@@ -122,15 +122,25 @@ static void ntb_netdev_event_handler(void *data, int link_is_up, u32 peer_caps)
ntb_netdev_update_carrier(dev);
}

+static void ntb_netdev_rx_stats_add(struct net_device *ndev,
+ unsigned int len)
+{
+ struct pcpu_sw_netstats *tstats = this_cpu_ptr(ndev->tstats);
+ unsigned long flags;
+
+ flags = u64_stats_update_begin_irqsave(&tstats->syncp);
+ u64_stats_inc(&tstats->rx_packets);
+ u64_stats_add(&tstats->rx_bytes, len);
+ u64_stats_update_end_irqrestore(&tstats->syncp, flags);
+}
+
static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
void *data, int len, unsigned int meta)
{
struct ntb_netdev_queue *q = qp_data;
struct ntb_netdev *dev = q->ntdev;
- struct pcpu_sw_netstats *tstats;
struct sk_buff *skb, *new_skb;
struct net_device *ndev;
- unsigned long flags;
int rc;

ndev = dev->ndev;
@@ -146,11 +156,7 @@ static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
goto enqueue_again;
}

- tstats = this_cpu_ptr(ndev->tstats);
- flags = u64_stats_update_begin_irqsave(&tstats->syncp);
- u64_stats_inc(&tstats->rx_packets);
- u64_stats_add(&tstats->rx_bytes, len);
- u64_stats_update_end_irqrestore(&tstats->syncp, flags);
+ ntb_netdev_rx_stats_add(ndev, len);

new_skb = netdev_alloc_skb(ndev, ndev->mtu + ETH_HLEN);
if (!new_skb) {
--
2.51.0