@@ -881,7 +881,10 @@ struct bnxt_sw_tx_bd {
struct page *page;
DEFINE_DMA_UNMAP_ADDR(mapping);
DEFINE_DMA_UNMAP_LEN(len);
- u16 extra_segs;
+ union {
+ u16 extra_segs;
+ u16 xdp_len;
+ };
u8 extra_bytes;
u8 hdr_size;
u8 is_ts_pkt;
@@ -1134,8 +1137,8 @@ struct bnxt_rx_sw_stats {
struct bnxt_tx_sw_stats {
u64 tx_resets;
/* non-ethtool stats follow */
- u64 tx_packets;
- u64 tx_bytes;
+ u64 tx_packets; /* for XDP_TX, under rx syncp */
+ u64 tx_bytes; /* for XDP_TX, under rx syncp */
struct u64_stats_sync syncp;
};
@@ -15685,6 +15685,7 @@ static void bnxt_get_base_stats(struct net_device *dev,
struct netdev_queue_stats_tx *tx)
{
struct bnxt *bp = netdev_priv(dev);
+ int i;
rx->packets = bp->ring_drv_stats_prev.rx_total_packets;
rx->bytes = bp->ring_drv_stats_prev.rx_total_bytes;
@@ -15692,6 +15693,21 @@ static void bnxt_get_base_stats(struct net_device *dev,
tx->packets = bp->ring_drv_stats_prev.tx_total_packets;
tx->bytes = bp->ring_drv_stats_prev.tx_total_bytes;
+
+ for (i = 0; i < bp->tx_nr_rings_xdp; i++) {
+ struct bnxt_sw_stats *sw_stats = bp->bnapi[i]->cp_ring.sw_stats;
+ unsigned int seq;
+ u64 pkts, bytes;
+
+ do {
+ seq = u64_stats_fetch_begin(&sw_stats->rx.syncp);
+ pkts = sw_stats->tx.tx_packets;
+ bytes = sw_stats->tx.tx_bytes;
+ } while (u64_stats_fetch_retry(&sw_stats->rx.syncp, seq));
+
+ tx->packets += pkts;
+ tx->bytes += bytes;
+ }
}
static const struct netdev_stat_ops bnxt_stat_ops = {
@@ -35,14 +35,17 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
u16 prod;
int i;
- if (xdp && xdp_buff_has_frags(xdp)) {
- sinfo = xdp_get_shared_info_from_buff(xdp);
- num_frags = sinfo->nr_frags;
- }
-
/* fill up the first buffer */
prod = txr->tx_prod;
tx_buf = &txr->tx_buf_ring[RING_TX(bp, prod)];
+ tx_buf->xdp_len = len;
+
+ if (xdp && xdp_buff_has_frags(xdp)) {
+ sinfo = xdp_get_shared_info_from_buff(xdp);
+ tx_buf->xdp_len += sinfo->xdp_frags_size;
+ num_frags = sinfo->nr_frags;
+ }
+
tx_buf->nr_frags = num_frags;
if (xdp)
tx_buf->page = virt_to_head_page(xdp->data);
@@ -120,9 +123,11 @@ static void __bnxt_xmit_xdp_redirect(struct bnxt *bp,
void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
{
+ struct bnxt_sw_stats *sw_stats = bnapi->cp_ring.sw_stats;
struct bnxt_tx_ring_info *txr = bnapi->tx_ring[0];
struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
u16 tx_hw_cons = txr->tx_hw_cons;
+ unsigned int pkts = 0, bytes = 0;
bool rx_doorbell_needed = false;
struct bnxt_sw_tx_bd *tx_buf;
u16 tx_cons = txr->tx_cons;
@@ -135,6 +140,10 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
while (RING_TX(bp, tx_cons) != tx_hw_cons) {
tx_buf = &txr->tx_buf_ring[RING_TX(bp, tx_cons)];
+ pkts++;
+ bytes += tx_buf->xdp_len;
+ tx_buf->xdp_len = 0;
+
if (tx_buf->action == XDP_REDIRECT) {
struct pci_dev *pdev = bp->pdev;
@@ -163,6 +172,12 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
tx_cons = NEXT_TX(tx_cons);
}
+ /* Note: Rx sync here, because Rx == NAPI context */
+ u64_stats_update_begin(&sw_stats->rx.syncp);
+ sw_stats->tx.tx_packets += pkts;
+ sw_stats->tx.tx_bytes += bytes;
+ u64_stats_update_end(&sw_stats->rx.syncp);
+
bnapi->events &= ~BNXT_TX_CMP_EVENT;
WRITE_ONCE(txr->tx_cons, tx_cons);
if (rx_doorbell_needed) {
Count XDP_TX and XDP_REDIRECT packets. Since the Tx rings are separate we count the packets sent to the base stats, not per-queues stats. The XDP stats are protected by the Rx syncp since they are in NAPI context. Feels slightly less ugly than having a Tx stats in Rx struct. But neither is ideal. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- v3: - count XDP on same members as Tx v2: https://lore.kernel.org/20250228012534.3460918-10-kuba@kernel.org - move tx_buf init sooner so that shinfo handling can access it v1: https://lore.kernel.org/20250226211003.2790916-10-kuba@kernel.org --- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 9 ++++--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 16 ++++++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 25 +++++++++++++++---- 3 files changed, 42 insertions(+), 8 deletions(-)