Skip to contentSkip to conversation

eth: bnxt: report TX HW GSO queue stats

PATCH Applied Narcisa Vasile 4 participants 5 messages Nov 16 – Nov 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eth: bnxt: report TX HW GSO queue stats

Expose counters for HW GSO skbs and the wire packets they produce through netdev queue statistics. Update the counters when TX completions are processed.

The tso.py selftests are skipped for drivers that don't report these counters, so this also lets them run on bnxt.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 28 ++++++++++++++++++++---
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  6 +++++
 2 files changed, 31 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +25 -3
index 6846a27bfef4c..1a7a93bf684ac 100644
@@ -869,6 +869,11 @@ static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
 		cons = NEXT_TX(cons);
 		tx_pkts++;
 		tx_bytes += skb->len;
+		if (skb_is_gso(skb) && !tx_buf->is_sw_gso) {
+			txr->tx_hw_gso_packets++;
+			txr->tx_hw_gso_wire_packets +=
+				skb_shinfo(skb)->gso_segs;
+		}
 		tx_buf->skb = NULL;
 		tx_buf->is_ts_pkt = 0;
 
@@ -13820,6 +13825,17 @@ void bnxt_get_ring_drv_stats(struct bnxt *bp,
 
 	for (i = 0; i < bp->cp_nr_rings; i++)
 		bnxt_get_one_ring_drv_stats(bp, stats, &bp->bnapi[i]->cp_ring);
+
+	if (!bp->tx_ring)
+		return;
+
+	for (i = 0; i < bp->tx_nr_rings; i++) {
+		struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
+
+		stats->tx_total_hw_gso_packets += txr->tx_hw_gso_packets;
+		stats->tx_total_hw_gso_wire_packets +=
+			txr->tx_hw_gso_wire_packets;
+	}
 }
 
 static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask,
@@ -16350,15 +16366,15 @@ static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
 				    struct netdev_queue_stats_tx *stats)
 {
 	struct bnxt *bp = netdev_priv(dev);
-	struct bnxt_napi *bnapi;
+	struct bnxt_tx_ring_info *txr;
 	u64 *sw;
 
 	if (!bp->tx_ring)
 		return;
 
 	bnxt_sync_ring_stats(bp);
-	bnapi = bp->tx_ring[bp->tx_ring_map[i]].bnapi;
-	sw = bnapi->cp_ring.stats.sw_stats;
+	txr = &bp->tx_ring[bp->tx_ring_map[i]];
+	sw = txr->bnapi->cp_ring.stats.sw_stats;
 
 	stats->packets = 0;
 	stats->packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
@@ -16369,6 +16385,9 @@ static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
+
+	stats->hw_gso_packets = txr->tx_hw_gso_packets;
+	stats->hw_gso_wire_packets = txr->tx_hw_gso_wire_packets;
 }
 
 static void bnxt_get_base_stats(struct net_device *dev,
@@ -16385,6 +16404,9 @@ static void bnxt_get_base_stats(struct net_device *dev,
 
 	tx->packets = bp->net_stats_prev.tx_packets;
 	tx->bytes = bp->net_stats_prev.tx_bytes;
+	tx->hw_gso_packets = bp->ring_drv_stats_prev.tx_total_hw_gso_packets;
+	tx->hw_gso_wire_packets =
+		bp->ring_drv_stats_prev.tx_total_hw_gso_wire_packets;
 }
 
 static const struct netdev_stat_ops bnxt_stat_ops = {
drivers/net/ethernet/broadcom/bnxt/bnxt.h +6 -0
index 41d05efd6307a..51c1568432b67 100644
@@ -1016,6 +1016,10 @@ struct bnxt_tx_ring_info {
 	struct bnxt_ring_struct	tx_ring_struct;
 	/* Synchronize simultaneous xdp_xmit on same ring */
 	spinlock_t		xdp_tx_lock;
+
+	/* Updated on TX completion, kept per ring */
+	u64			tx_hw_gso_packets;
+	u64			tx_hw_gso_wire_packets;
 };
 
 #define BNXT_LEGACY_COAL_CMPL_PARAMS					\
@@ -1176,6 +1180,8 @@ struct bnxt_total_ring_drv_stats {
 	/* end of ethtool -S stats */
 	u64			rx_total_hw_gro_packets;
 	u64			rx_total_hw_gro_wire_packets;
+	u64			tx_total_hw_gso_packets;
+	u64			tx_total_hw_gso_wire_packets;
 };
 
 struct bnxt_stats_mem {
Signature · 1 line
2.53.1-Meta
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] __bnxt_tx_int() treats every completed skb with skb_is_gso() && !tx_buf->is_sw_gso as segmented by the NIC into gso_segs wire…
- [Low] The patch adds per-ring TX HW GSO counters (txr->tx_hw_gso_packets, txr->tx_hw_gso_wire_packets) to struct…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but bnxt_start_xmit() lets a GSO skb (gso_size != 0) take the TX push path…

--

eth: bnxt: report TX HW GSO queue stats

This commit adds per-ring counters to bnxt for HW GSO skbs and for the wire packets they produce. The counters are updated in the TX completion path and reported through the netdev queue stats ops. Aggregated totals are also folded into the base stats so the tso.py selftests can run on bnxt.

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index 6846a27bfef4c..1a7a93bf684ac 100644

drivers/net/ethernet/broadcom/bnxt/bnxt.c static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr, · line 878

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -0
@@ -869,6 +869,11 @@ static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
 		cons = NEXT_TX(cons);
 		tx_pkts++;
 		tx_bytes += skb->len;
+		if (skb_is_gso(skb) && !tx_buf->is_sw_gso) {
+			txr->tx_hw_gso_packets++;
+			txr->tx_hw_gso_wire_packets +=
+				skb_shinfo(skb)->gso_segs;
+		}
 		tx_buf->skb = NULL;
 		tx_buf->is_ts_pkt = 0;

[Severity: Medium]
Can this over-count wire packets for GSO skbs that were sent through the TX push path?

This block runs before the is_push early-out. It treats every completed skb with skb_is_gso() && !is_sw_gso as segmented by the hardware. However, the push path gate in bnxt_start_xmit() does not exclude GSO skbs:

	if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh &&
	    skb_frags_readable(skb) && !lflags) {

The push BDs never set TX_BD_FLAGS_LSO or tx_bd_mss, so the NIC sends the skb as a single frame.

Take an idle ring with tx_push_thresh at 164 and a GSO skb of 164 bytes or less. Two examples are TCP with a peer-advertised MSS of 48 and 96 bytes of payload, or UDP_SEGMENT with gso_size=8 and 80 bytes of payload. Either skb would be counted as 1 hw_gso_packet plus gso_segs hw_gso_wire_packets, even though only one frame went on the wire.

tso.py reads these counters, so could this give misleading results there? Fixing the push path issue described below would also fix this.

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but should bnxt_start_xmit() keep GSO skbs out of the push path?

The push path only sets the checksum flag and then skips the LSO setup:

bnxt_start_xmit() {
    ...
		if (skb->ip_summed == CHECKSUM_PARTIAL)
			tx_push1->tx_bd_hsize_lflags =
					cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
		else
			tx_push1->tx_bd_hsize_lflags = 0;
    ...
		goto tx_done;
    ...
}

LSO is only programmed in the normal_tx path:

	if (skb_is_gso(skb)) {
		...
		txbd1->tx_bd_hsize_lflags |= cpu_to_le32(TX_BD_FLAGS_LSO |
					TX_BD_FLAGS_T_IPID |
					(hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
		length = skb_shinfo(skb)->gso_size;
		txbd1->tx_bd_mss = cpu_to_le32(length);

So a small GSO skb that takes the push path goes out unsegmented.

With HW USO (BNXT_FLAG_UDP_GSO_CAP), wouldn't the receiver get one UDP datagram holding the concatenated payload, instead of gso_segs separate datagrams? For TCP, a segment larger than the peer's MSS would be sent.

Neither bnxt_features_check() nor gso_features_check() seems to strip GSO for skbs this small. Would adding a !skb_is_gso(skb) check to the push gate be enough to fix this?

[ ... ]

drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_get_queue_stats_tx(struct net_device *dev, int i, · line 16391

Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -0
@@ -16369,6 +16385,9 @@ static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
 	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
+
+	stats->hw_gso_packets = txr->tx_hw_gso_packets;
+	stats->hw_gso_wire_packets = txr->tx_hw_gso_wire_packets;
 }

[Severity: Low]
Are these reads safe against the writer in __bnxt_tx_int()?

txr->tx_hw_gso_packets and txr->tx_hw_gso_wire_packets are plain u64 fields. They are updated with ++ and += from NAPI context.

They are read here, and in bnxt_get_ring_drv_stats() through bnxt_get_ethtool_stats(), from process context while NAPI can be running on another CPU.

bnxt_sync_ring_stats() only takes bp->stats_lock around the HW ring stats accumulation, so these fields are not covered.

BNXT does not depend on 64BIT. On 32-bit builds, could a reader see a torn value when the low word wraps? On 64-bit this is still an unannotated data race that KCSAN would report.

Would it make sense to use u64_stats_t with a u64_stats_sync here, with a fetch_begin/fetch_retry loop on the reader side? The existing rx_hw_gro_packets counters use the same unsynchronized pattern.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116204313.23023-1-narcisav.kernel%40gmail.com
#2 lore raw
Quoted 36 lines · On Wed, Nov 18, 2026 at 08:44:00AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index 6846a27bfef4c..1a7a93bf684ac 100644

drivers/net/ethernet/broadcom/bnxt/bnxt.c static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr, · line 878

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -0
@@ -869,6 +869,11 @@ static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
 		cons = NEXT_TX(cons);
 		tx_pkts++;
 		tx_bytes += skb->len;
+		if (skb_is_gso(skb) && !tx_buf->is_sw_gso) {
+			txr->tx_hw_gso_packets++;
+			txr->tx_hw_gso_wire_packets +=
+				skb_shinfo(skb)->gso_segs;
+		}
 		tx_buf->skb = NULL;
 		tx_buf->is_ts_pkt = 0;

[Severity: Medium]
Can this over-count wire packets for GSO skbs that were sent through the TX push path?

This block runs before the is_push early-out. It treats every completed skb with skb_is_gso() && !is_sw_gso as segmented by the hardware. However, the push path gate in bnxt_start_xmit() does not exclude GSO skbs:

	if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh &&
	    skb_frags_readable(skb) && !lflags) {

The push BDs never set TX_BD_FLAGS_LSO or tx_bd_mss, so the NIC sends the skb as a single frame.

Quoted 9 lines

Take an idle ring with tx_push_thresh at 164 and a GSO skb of 164 bytes or less. Two examples are TCP with a peer-advertised MSS of 48 and 96 bytes of payload, or UDP_SEGMENT with gso_size=8 and 80 bytes of payload. Either skb would be counted as 1 hw_gso_packet plus gso_segs hw_gso_wire_packets, even though only one frame went on the wire.

tso.py reads these counters, so could this give misleading results there? Fixing the push path issue described below would also fix this.

This couldn't give misleading results there, since no GSO skb in tso.py can be 164 bytes or less, so none can take the push path.

Quoted 4 lines

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but should bnxt_start_xmit() keep GSO skbs out of the push path?

This patch doesn't introduce the push path issue (the high severity one). The medium severity issue is a symptom of this pre-existing high one. Both need a GSO skb of 164 bytes or less sent on an idle TX ring to manifest. If the preexisting push path bug is ever hit, the stats added by this patch would cause hw_gso_wire_packets to be over-reported by gso_segs - 1 for the skbs which take the push path.

I think this patch can be merged as is.
If it's worth fixing, the push path issue can be addressed independently with a one line change in bnxt_start_xmit(). With that fix in place, the stats would also report correctly, with no other change needed.

Quoted 3 lines
Signature · 2 lines
-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116204313.23023-1-narcisav.kernel%40gmail.com
maintainer
#3 lore raw
Quoted 21 lines · On Thu, 19 Nov 2026 20:48:03 -0800 Narcisa Vasile wrote:
Quoted 21 lines

[Severity: Medium]
Can this over-count wire packets for GSO skbs that were sent through the TX push path?

This block runs before the is_push early-out. It treats every completed skb with skb_is_gso() && !is_sw_gso as segmented by the hardware. However, the push path gate in bnxt_start_xmit() does not exclude GSO skbs:

	if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh &&
	    skb_frags_readable(skb) && !lflags) {

The push BDs never set TX_BD_FLAGS_LSO or tx_bd_mss, so the NIC sends the skb as a single frame.

Take an idle ring with tx_push_thresh at 164 and a GSO skb of 164 bytes or less. Two examples are TCP with a peer-advertised MSS of 48 and 96 bytes of payload, or UDP_SEGMENT with gso_size=8 and 80 bytes of payload. Either skb would be counted as 1 hw_gso_packet plus gso_segs hw_gso_wire_packets, even though only one frame went on the wire.

Quoted 5 lines
Quoted 2 lines

tso.py reads these counters, so could this give misleading results there? Fixing the push path issue described below would also fix this.

This couldn't give misleading results there, since no GSO skb in tso.py can be 164 bytes or less, so none can take the push path.

Fair, but UDP segmentation may sneak in there. I will check with Joe. Either way, I agree that this is orthogonal.

#4 lore raw
In reply to Narcisa Vasile
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 16 Nov 2026 12:43:13 -0800 you wrote:

Expose counters for HW GSO skbs and the wire packets they produce through netdev queue statistics. Update the counters when TX completions are processed.

The tso.py selftests are skipped for drivers that don't report these counters, so this also lets them run on bnxt.

[...]

Here is the summary with links:
- [net-next] eth: bnxt: report TX HW GSO queue stats

    https://git.kernel.org/netdev/net-next/c/04c6b6c90e32

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html