* [PATCH net-next v2 0/3] net: wangxun: improve statistics support
@ 2026-11-30 8:34 Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration Mengyuan Lou
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mengyuan Lou @ 2026-11-30 8:34 UTC (permalink / raw)
To: netdev
Cc: jiawenwu, duanqiangwen, linglingzhang, andrew+netdev, davem,
edumazet, kuba, pabeni, Mengyuan Lou
This series improves statistics support for the Wangxun drivers.
The legacy counters are aggregated from the queue rings, so they lose
their history whenever a queue vector is freed: an ethtool -L channel
change, enabling or disabling SR-IOV VFs, or a suspend/resume cycle, all
of which tear down and rebuild the queue vectors. The VF drivers neither
expose per-queue statistics through netdev-genl nor provide
ndo_get_stats64(), so ip -s link reports zero counters for them.
Patch 1 keeps the per-ring counters in qstats_base_* accumulators when a
queue vector is torn down. Folding a ring and clearing its pointer happen
under hw_stats_lock, and every read that pairs the rings with the base
values takes the same lock: wx_get_stats64() and wx_update_stats() hold it
across their ring walk, and wx_get_base_stats() takes it for the base
reads. A snapshot therefore cannot mix a ring with its retained value or
count a ring twice. The software aggregates are refreshed on every
update, but the hardware register reads are skipped while the device is
down or resetting, so retained values stay visible through ethtool -S
after queue teardown.
Patch 2 implements netdev_stat_ops in libwx and registers them for ngbe,
ngbevf, txgbe and txgbevf. The per-queue callbacks report the live rings;
get_base_stats() reports the counters retained by patch 1, so netdev-genl
totals keep including the traffic of queues that no longer exist, and a
plain sum over the current queues no longer adds up to them.
Patch 3 registers ndo_get_stats64() for ngbevf and txgbevf. A VF must not
read the PF-only statistics registers: they sit in the PF register block
where an access from a VF hangs the system, as commit 694de316f607
("net: libwx: fix VF illegal register access") records for WX_CFG_PORT_ST,
so wx_update_stats() skips them for a VF. The drivers record the role in
wx->is_vf instead of relying on pci_dev::is_virtfn, which is only set for
the VFs the host's SR-IOV implementation enumerates and stays clear for a
VF probed inside a guest.
Testing:
tools/testing/selftests/drivers/net/stats.py, run with NETIF set to the
interface under test. All four interfaces are on the same host, with the
VFs enabled through SR-IOV on it:
enp6s0f0 (ngbe) pass: 6, fail: 0, skip: 2
enp4s0f0 (txgbe) pass: 6, fail: 0, skip: 2
enp6s0f0v0 (ngbevf) pass: 4, fail: 1, skip: 3
enp4s0f0v0 (txgbevf) pass: 4, fail: 1, skip: 3
The skipped subtests are pause (VFs only) and the two FEC subtests (all
four), features the devices do not support. On the VFs the only failure is
procfs_downup_hammer, which starts by querying the channel counts: the VF
ethtool ops do not implement get_channels/set_channels, since ethtool -L
is not supported on a VF, so the subtest cannot run there. Every other
subtest, including qstat_by_ifindex, pkt_byte_sum, check_down and
procfs_hammer, passes on both VFs.
Changes in v2:
- Drop patch 1 ("net: libwx: fix suspend/resume for wxvf"): upstream
as commit a6c3e4c1f7032 ("net: libwx: fix VF PM suspend/resume flow").
- Retain the ring counters across a queue teardown instead of only
tolerating missing ring pointers: add the qstats_base_* accumulators,
fold a ring into them in wx_free_q_vector(), and report them through
get_base_stats(), ndo_get_stats64() and ethtool -S, rather than
returning zero from get_base_stats().
- Split the per-ring seqcount into napi_syncp and xmit_syncp, and count
the transmit queue stops, so every counter has a single writer under
the matching lock.
- Report the RX checksum counters of the ring that received the packets
instead of the device-wide values on every queue, and expose
csum_unnecessary, which is the counter the driver actually maintains,
in place of csum_complete.
- Merge the per-queue stat ops and the per-driver registration into a
single patch.
- Drop the early return for VFs in wx_get_stats64() as asked by Breno:
the PF-only register reads in wx_update_stats() are what a VF must
skip, not the rest of the statistics.
- Track the device role in wx->is_vf, set by the VF drivers before the
hardware is touched, and convert the libwx checks from
pci_dev::is_virtfn, which a VF probed inside a guest does not have.
- Refresh the VF statistics on demand from the readers; the VF service
task no longer calls wx_update_stats().
- Add the stats.py selftest results and the environment, as asked by
Jakub.
Link to v1:
https://lore.kernel.org/netdev/20260731074958.19333-1-mengyuanlou@net-swift.com/
Mengyuan Lou (3):
net: libwx: preserve queue stats across reconfiguration
net: wangxun: expose queue stats via netdev-genl
net: wangxun: expose VF stats through ndo_get_stats64
.../net/ethernet/wangxun/libwx/wx_ethtool.c | 21 +-
drivers/net/ethernet/wangxun/libwx/wx_hw.c | 80 +++---
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 254 ++++++++++++++----
drivers/net/ethernet/wangxun/libwx/wx_lib.h | 1 +
drivers/net/ethernet/wangxun/libwx/wx_type.h | 88 +++++-
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 1 +
.../net/ethernet/wangxun/ngbevf/ngbevf_main.c | 6 +
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c | 1 +
.../ethernet/wangxun/txgbevf/txgbevf_main.c | 6 +
9 files changed, 356 insertions(+), 102 deletions(-)
--
2.30.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration
2026-11-30 8:34 [PATCH net-next v2 0/3] net: wangxun: improve statistics support Mengyuan Lou
@ 2026-11-30 8:34 ` Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
2026-11-30 8:34 ` [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64 Mengyuan Lou
2 siblings, 1 reply; 7+ messages in thread
From: Mengyuan Lou @ 2026-11-30 8:34 UTC (permalink / raw)
To: netdev
Cc: jiawenwu, duanqiangwen, linglingzhang, andrew+netdev, davem,
edumazet, kuba, pabeni, Mengyuan Lou
Retain the per-ring packet, byte and error counters when queue vectors
are freed, so that the legacy statistics keep their history across an
ethtool -L, a reset or a resume. Fold the retained values into the
aggregates through the qstats_base_* accumulators and protect the
ring-to-base handoff with hw_stats_lock.
The accumulators are read under that same lock, which wx_free_q_vector()
holds while it folds a ring and clears its pointer, so a reader cannot
mix a ring with its retained value. Clear the queue counts only after
every ring has been folded, so that a reader which pairs the counts with
the base values cannot skip a ring that is still waiting to be folded;
that keeps base plus live rings invariant at every instant. The
per-queue counters reported by ethtool -S keep describing the live
queues only, so after a reconfiguration they no longer add up to the
aggregates.
Initialize each ring's u64_stats_sync instances and serialize the
per-ring counter updates and reads. Name them after the writer they
protect: napi_syncp for the counters updated from NAPI, xmit_syncp for
the ones updated from the xmit path, so that a new writer goes under the
matching lock by name and the two producers never hold the same
seqcount odd at the same time. The xmit-side lock is only taken when the
transmit queue is stopped and when a full ring defers a packet, not on
the normal transmit path, so the 32-bit preemption and seqcount cost is
paid at queue-stop boundaries rather than per packet.
Rename rx_stats.csum_good_cnt and its accumulator to use
csum_unnecessary_cnt; the local snapshot uses the same wording. The
counter reflects the packets that wx_rx_checksum() hands to the stack
with CHECKSUM_UNNECESSARY.
Count the transmit queue stops in the ring, next to restart_queue, and
report both as retained stop and wake counters. A stop is counted when
wx_maybe_stop_tx() leaves the queue stopped; the reprieve path only
adds a wake. The snapshot type is named after what it holds,
wx_tx_retained_stats, and its wake member already includes the NAPI
wake-ups, so a consumer cannot lose them by adding up only one of the
two producers.
Refresh software aggregates while the device is down or resetting,
while skipping hardware register reads. This keeps retained values
visible through ethtool -S after queue teardown. Use shared ring
snapshots in the aggregation, teardown, stats64 and ethtool readers.
Clearing the ring pointers stays under the lock as well, but the teardown
itself does not stop the device: every caller has already disabled NAPI
and the TX queues, and vectors from a partially failed allocation were
never enabled, so no writer races the fold.
Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
---
.../net/ethernet/wangxun/libwx/wx_ethtool.c | 19 +--
drivers/net/ethernet/wangxun/libwx/wx_hw.c | 74 ++++----
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 158 ++++++++++++------
drivers/net/ethernet/wangxun/libwx/wx_type.h | 82 ++++++++-
4 files changed, 238 insertions(+), 95 deletions(-)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
index 05f915e778645..8f0bbdbb4cf23 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
@@ -127,8 +127,9 @@ void wx_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats *stats, u64 *data)
{
struct wx *wx = netdev_priv(netdev);
+ struct wx_tx_ring_stats tx_stats;
+ struct wx_rx_ring_stats rx_stats;
struct wx_ring *ring;
- unsigned int start;
int i, j, k;
char *p;
@@ -163,11 +164,9 @@ void wx_get_ethtool_stats(struct net_device *netdev,
continue;
}
- do {
- start = u64_stats_fetch_begin(&ring->syncp);
- data[i] = ring->stats.packets;
- data[i + 1] = ring->stats.bytes;
- } while (u64_stats_fetch_retry(&ring->syncp, start));
+ wx_ring_get_tx_stats(ring, &tx_stats);
+ data[i] = tx_stats.queue.packets;
+ data[i + 1] = tx_stats.queue.bytes;
i += 2;
}
for (j = 0; j < WX_NUM_RX_QUEUES; j++) {
@@ -178,11 +177,9 @@ void wx_get_ethtool_stats(struct net_device *netdev,
continue;
}
- do {
- start = u64_stats_fetch_begin(&ring->syncp);
- data[i] = ring->stats.packets;
- data[i + 1] = ring->stats.bytes;
- } while (u64_stats_fetch_retry(&ring->syncp, start));
+ wx_ring_get_rx_stats(ring, &rx_stats);
+ data[i] = rx_stats.queue.packets;
+ data[i + 1] = rx_stats.queue.bytes;
i += 2;
}
rcu_read_unlock();
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
index c285c1de24ba9..a367ed45fc127 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
@@ -2920,13 +2920,13 @@ void wx_update_stats(struct wx *wx)
u64 hw_csum_rx_good = 0, hw_csum_rx_error = 0;
u64 restart_queue = 0, tx_busy = 0;
int num_rx_queues, num_tx_queues;
+ u64 rsc_count = 0, rsc_flush = 0;
+ bool update_hw_stats;
u32 i;
- if (test_bit(WX_STATE_DOWN, wx->state) ||
- test_bit(WX_STATE_RESETTING, wx->state))
- return;
-
spin_lock(&wx->hw_stats_lock);
+ update_hw_stats = !test_bit(WX_STATE_DOWN, wx->state) &&
+ !test_bit(WX_STATE_RESETTING, wx->state);
num_rx_queues = READ_ONCE(wx->num_rx_queues);
num_tx_queues = READ_ONCE(wx->num_tx_queues);
@@ -2934,48 +2934,55 @@ void wx_update_stats(struct wx *wx)
/* gather some stats to the wx struct that are per queue */
for (i = 0; i < num_rx_queues; i++) {
struct wx_ring *rx_ring = rcu_dereference(wx->rx_ring[i]);
+ struct wx_rx_ring_stats ring_stats;
if (!rx_ring)
continue;
- non_eop_descs += rx_ring->rx_stats.non_eop_descs;
- alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
- hw_csum_rx_good += rx_ring->rx_stats.csum_good_cnt;
- hw_csum_rx_error += rx_ring->rx_stats.csum_err;
- }
- wx->non_eop_descs = non_eop_descs;
- wx->alloc_rx_buff_failed = alloc_rx_buff_failed;
- wx->hw_csum_rx_error = hw_csum_rx_error;
- wx->hw_csum_rx_good = hw_csum_rx_good;
-
- if (test_bit(WX_FLAG_RSC_ENABLED, wx->flags)) {
- u64 rsc_count = 0;
- u64 rsc_flush = 0;
- for (i = 0; i < num_rx_queues; i++) {
- struct wx_ring *rx_ring = rcu_dereference(wx->rx_ring[i]);
-
- if (!rx_ring)
- continue;
-
- rsc_count += rx_ring->rx_stats.rsc_count;
- rsc_flush += rx_ring->rx_stats.rsc_flush;
- }
- wx->rsc_count = rsc_count;
- wx->rsc_flush = rsc_flush;
- }
+ wx_ring_get_rx_stats(rx_ring, &ring_stats);
+
+ non_eop_descs += ring_stats.rx.non_eop_descs;
+ alloc_rx_buff_failed += ring_stats.rx.alloc_rx_buff_failed;
+ hw_csum_rx_good += ring_stats.rx.csum_unnecessary_cnt;
+ hw_csum_rx_error += ring_stats.rx.csum_err;
+ rsc_count += ring_stats.rx.rsc_count;
+ rsc_flush += ring_stats.rx.rsc_flush;
+ }
+ wx->non_eop_descs =
+ wx->qstats_base_rx_stats.non_eop_descs + non_eop_descs;
+ wx->alloc_rx_buff_failed =
+ wx->qstats_base_rx_stats.alloc_rx_buff_failed +
+ alloc_rx_buff_failed;
+ wx->hw_csum_rx_error =
+ wx->qstats_base_rx_stats.csum_err + hw_csum_rx_error;
+ wx->hw_csum_rx_good =
+ wx->qstats_base_rx_stats.csum_unnecessary_cnt + hw_csum_rx_good;
+
+ /* The ring counters are folded into this value when they are freed,
+ * so keep it current even while RSC is turned off and no ring can
+ * add to it.
+ */
+ wx->rsc_count = wx->qstats_base_rx_stats.rsc_count + rsc_count;
+ wx->rsc_flush = wx->qstats_base_rx_stats.rsc_flush + rsc_flush;
for (i = 0; i < num_tx_queues; i++) {
struct wx_ring *tx_ring = rcu_dereference(wx->tx_ring[i]);
+ struct wx_tx_ring_stats ring_stats;
if (!tx_ring)
continue;
- restart_queue += tx_ring->tx_stats.restart_queue;
- tx_busy += tx_ring->tx_stats.tx_busy;
+ wx_ring_get_tx_stats(tx_ring, &ring_stats);
+
+ restart_queue += ring_stats.tx.wake;
+ tx_busy += ring_stats.tx.tx_busy;
}
rcu_read_unlock();
- wx->restart_queue = restart_queue;
- wx->tx_busy = tx_busy;
+ wx->restart_queue = wx->qstats_base_tx_stats.wake + restart_queue;
+ wx->tx_busy = wx->qstats_base_tx_stats.tx_busy + tx_busy;
+
+ if (!update_hw_stats)
+ goto skip_hw_stats;
wx_update_xoff_rx_lfc(wx);
@@ -3016,6 +3023,7 @@ void wx_update_stats(struct wx *wx)
hwstats->qmprc += rd32_wrap(wx, WX_PX_MPRC(i),
&wx->last_stats.qmprc[i]);
+skip_hw_stats:
spin_unlock(&wx->hw_stats_lock);
}
EXPORT_SYMBOL(wx_update_stats);
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 10f095fb7085c..2868232792588 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -387,6 +387,7 @@ u16 wx_desc_unused(struct wx_ring *ring)
* @rx_ring: Rx ring being processed
* @rx_desc: Rx descriptor for current buffer
* @skb: Current socket buffer containing buffer in progress
+ * @stats: RX counters accumulated for this NAPI poll
*
* This function updates next to clean. If the buffer is an EOP buffer
* this function exits returning false, otherwise it will place the
@@ -395,7 +396,8 @@ u16 wx_desc_unused(struct wx_ring *ring)
**/
static bool wx_is_non_eop(struct wx_ring *rx_ring,
union wx_rx_desc *rx_desc,
- struct sk_buff *skb)
+ struct sk_buff *skb,
+ struct wx_rx_queue_stats *stats)
{
struct wx *wx = rx_ring->q_vector->wx;
u32 ntc = rx_ring->next_to_clean + 1;
@@ -429,7 +431,7 @@ static bool wx_is_non_eop(struct wx_ring *rx_ring,
return false;
rx_ring->rx_buffer_info[ntc].skb = skb;
- rx_ring->rx_stats.non_eop_descs++;
+ stats->non_eop_descs++;
return true;
}
@@ -529,10 +531,12 @@ static void wx_rx_hash(struct wx_ring *ring,
* @ring: structure containing ring specific data
* @rx_desc: current Rx descriptor being processed
* @skb: skb currently being received and modified
+ * @stats: RX counters accumulated for this NAPI poll
**/
static void wx_rx_checksum(struct wx_ring *ring,
union wx_rx_desc *rx_desc,
- struct sk_buff *skb)
+ struct sk_buff *skb,
+ struct wx_rx_queue_stats *stats)
{
struct wx_dec_ptype dptype = wx_decode_ptype(WX_RXD_PKTTYPE(rx_desc));
@@ -546,7 +550,7 @@ static void wx_rx_checksum(struct wx_ring *ring,
wx_test_staterr(rx_desc, WX_RXD_ERR_IPE)) ||
(wx_test_staterr(rx_desc, WX_RXD_STAT_OUTERIPCS) &&
wx_test_staterr(rx_desc, WX_RXD_ERR_OUTERIPER))) {
- ring->rx_stats.csum_err++;
+ stats->csum_err++;
return;
}
@@ -561,7 +565,7 @@ static void wx_rx_checksum(struct wx_ring *ring,
/* if L4 checksum error */
if (wx_test_staterr(rx_desc, WX_RXD_ERR_TCPE)) {
- ring->rx_stats.csum_err++;
+ stats->csum_err++;
return;
}
@@ -574,7 +578,7 @@ static void wx_rx_checksum(struct wx_ring *ring,
*/
if (dptype.etype >= WX_DEC_PTYPE_ETYPE_IG)
__skb_incr_checksum_unnecessary(skb);
- ring->rx_stats.csum_good_cnt++;
+ stats->csum_unnecessary_cnt++;
}
static void wx_rx_vlan(struct wx_ring *ring, union wx_rx_desc *rx_desc,
@@ -606,14 +610,15 @@ static void wx_set_rsc_gso_size(struct wx_ring *ring,
}
static void wx_update_rsc_stats(struct wx_ring *rx_ring,
- struct sk_buff *skb)
+ struct sk_buff *skb,
+ struct wx_rx_queue_stats *stats)
{
/* if append_cnt is 0 then frame is not RSC */
if (!WX_CB(skb)->append_cnt)
return;
- rx_ring->rx_stats.rsc_count += WX_CB(skb)->append_cnt;
- rx_ring->rx_stats.rsc_flush++;
+ stats->rsc_count += WX_CB(skb)->append_cnt;
+ stats->rsc_flush++;
wx_set_rsc_gso_size(rx_ring, skb);
@@ -626,6 +631,7 @@ static void wx_update_rsc_stats(struct wx_ring *rx_ring,
* @rx_ring: rx descriptor ring packet is being transacted on
* @rx_desc: pointer to the EOP Rx descriptor
* @skb: pointer to current skb being populated
+ * @stats: RX counters accumulated for this NAPI poll
*
* This function checks the ring, descriptor, and packet information in
* order to populate the hash, checksum, protocol, and
@@ -633,15 +639,16 @@ static void wx_update_rsc_stats(struct wx_ring *rx_ring,
**/
static void wx_process_skb_fields(struct wx_ring *rx_ring,
union wx_rx_desc *rx_desc,
- struct sk_buff *skb)
+ struct sk_buff *skb,
+ struct wx_rx_queue_stats *stats)
{
struct wx *wx = netdev_priv(rx_ring->netdev);
if (test_bit(WX_FLAG_RSC_CAPABLE, wx->flags))
- wx_update_rsc_stats(rx_ring, skb);
+ wx_update_rsc_stats(rx_ring, skb, stats);
wx_rx_hash(rx_ring, rx_desc, skb);
- wx_rx_checksum(rx_ring, rx_desc, skb);
+ wx_rx_checksum(rx_ring, rx_desc, skb, stats);
if (unlikely(test_bit(WX_FLAG_RX_HWTSTAMP_ENABLED, wx->flags)) &&
unlikely(wx_test_staterr(rx_desc, WX_RXD_STAT_TS))) {
@@ -673,6 +680,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector,
{
unsigned int total_rx_bytes = 0, total_rx_packets = 0;
u16 cleaned_count = wx_desc_unused(rx_ring);
+ struct wx_rx_queue_stats rx_stats = {};
do {
struct wx_rx_buffer *rx_buffer;
@@ -702,7 +710,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector,
/* exit if we failed to retrieve a buffer */
if (!skb) {
- rx_ring->rx_stats.alloc_rx_buff_failed++;
+ rx_stats.alloc_rx_buff_failed++;
break;
}
@@ -710,7 +718,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector,
cleaned_count++;
/* place incomplete frames back on ring for completion */
- if (wx_is_non_eop(rx_ring, rx_desc, skb))
+ if (wx_is_non_eop(rx_ring, rx_desc, skb, &rx_stats))
continue;
/* verify the packet layout is correct */
@@ -721,17 +729,25 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector,
total_rx_bytes += skb->len;
/* populate checksum, timestamp, VLAN, and protocol */
- wx_process_skb_fields(rx_ring, rx_desc, skb);
+ wx_process_skb_fields(rx_ring, rx_desc, skb, &rx_stats);
napi_gro_receive(&q_vector->napi, skb);
/* update budget accounting */
total_rx_packets++;
} while (likely(total_rx_packets < budget));
- u64_stats_update_begin(&rx_ring->syncp);
+ u64_stats_update_begin(&rx_ring->napi_syncp);
rx_ring->stats.packets += total_rx_packets;
rx_ring->stats.bytes += total_rx_bytes;
- u64_stats_update_end(&rx_ring->syncp);
+ rx_ring->rx_stats.non_eop_descs += rx_stats.non_eop_descs;
+ rx_ring->rx_stats.csum_unnecessary_cnt +=
+ rx_stats.csum_unnecessary_cnt;
+ rx_ring->rx_stats.csum_err += rx_stats.csum_err;
+ rx_ring->rx_stats.alloc_rx_buff_failed +=
+ rx_stats.alloc_rx_buff_failed;
+ rx_ring->rx_stats.rsc_count += rx_stats.rsc_count;
+ rx_ring->rx_stats.rsc_flush += rx_stats.rsc_flush;
+ u64_stats_update_end(&rx_ring->napi_syncp);
q_vector->rx.total_packets += total_rx_packets;
q_vector->rx.total_bytes += total_rx_bytes;
@@ -888,10 +904,10 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector,
i += tx_ring->count;
tx_ring->next_to_clean = i;
- u64_stats_update_begin(&tx_ring->syncp);
+ u64_stats_update_begin(&tx_ring->napi_syncp);
tx_ring->stats.bytes += total_bytes;
tx_ring->stats.packets += total_packets;
- u64_stats_update_end(&tx_ring->syncp);
+ u64_stats_update_end(&tx_ring->napi_syncp);
q_vector->tx.total_bytes += total_bytes;
q_vector->tx.total_packets += total_packets;
@@ -916,7 +932,9 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector,
!test_bit(WX_STATE_DOWN, wx->state)) {
netif_wake_subqueue(tx_ring->netdev,
tx_ring->queue_index);
- ++tx_ring->tx_stats.restart_queue;
+ u64_stats_update_begin(&tx_ring->napi_syncp);
+ ++tx_ring->tx_stats.restart_queue_napi;
+ u64_stats_update_end(&tx_ring->napi_syncp);
}
}
@@ -1021,12 +1039,18 @@ static int wx_maybe_stop_tx(struct wx_ring *tx_ring, u16 size)
/* We need to check again in a case another CPU has just
* made room available.
*/
- if (likely(wx_desc_unused(tx_ring) < size))
+ if (likely(wx_desc_unused(tx_ring) < size)) {
+ u64_stats_update_begin(&tx_ring->xmit_syncp);
+ ++tx_ring->tx_stats.stop_queue;
+ u64_stats_update_end(&tx_ring->xmit_syncp);
return -EBUSY;
+ }
/* A reprieve! - use start_queue because it doesn't call schedule */
netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
+ u64_stats_update_begin(&tx_ring->xmit_syncp);
++tx_ring->tx_stats.restart_queue;
+ u64_stats_update_end(&tx_ring->xmit_syncp);
return 0;
}
@@ -1631,7 +1655,9 @@ static netdev_tx_t wx_xmit_frame_ring(struct sk_buff *skb,
frags[f]));
if (wx_maybe_stop_tx(tx_ring, count + 3)) {
+ u64_stats_update_begin(&tx_ring->xmit_syncp);
tx_ring->tx_stats.tx_busy++;
+ u64_stats_update_end(&tx_ring->xmit_syncp);
return NETDEV_TX_BUSY;
}
@@ -2182,6 +2208,8 @@ static int wx_alloc_q_vector(struct wx *wx,
/* apply Tx specific ring traits */
ring->count = wx->tx_ring_count;
+ u64_stats_init(&ring->napi_syncp);
+ u64_stats_init(&ring->xmit_syncp);
ring->queue_index = txr_idx;
ring->reg_idx = wx_get_reg_idx(wx, txr_idx, false);
@@ -2210,6 +2238,7 @@ static int wx_alloc_q_vector(struct wx *wx,
/* apply Rx specific ring traits */
ring->count = wx->rx_ring_count;
+ u64_stats_init(&ring->napi_syncp);
ring->queue_index = rxr_idx;
ring->reg_idx = wx_get_reg_idx(wx, rxr_idx, true);
@@ -2241,11 +2270,37 @@ static void wx_free_q_vector(struct wx *wx, int v_idx)
struct wx_q_vector *q_vector = wx->q_vector[v_idx];
struct wx_ring *ring;
- wx_for_each_ring(ring, q_vector->tx)
+ spin_lock(&wx->hw_stats_lock);
+ wx_for_each_ring(ring, q_vector->tx) {
+ struct wx_tx_ring_stats ring_stats;
+
+ wx_ring_get_tx_stats(ring, &ring_stats);
+ wx->qstats_base_tx.packets += ring_stats.queue.packets;
+ wx->qstats_base_tx.bytes += ring_stats.queue.bytes;
+ wx->qstats_base_tx_stats.stop += ring_stats.tx.stop;
+ wx->qstats_base_tx_stats.wake += ring_stats.tx.wake;
+ wx->qstats_base_tx_stats.tx_busy += ring_stats.tx.tx_busy;
rcu_assign_pointer(wx->tx_ring[ring->queue_index], NULL);
+ }
- wx_for_each_ring(ring, q_vector->rx)
+ wx_for_each_ring(ring, q_vector->rx) {
+ struct wx_rx_ring_stats ring_stats;
+
+ wx_ring_get_rx_stats(ring, &ring_stats);
+ wx->qstats_base_rx.packets += ring_stats.queue.packets;
+ wx->qstats_base_rx.bytes += ring_stats.queue.bytes;
+ wx->qstats_base_rx_stats.non_eop_descs +=
+ ring_stats.rx.non_eop_descs;
+ wx->qstats_base_rx_stats.alloc_rx_buff_failed +=
+ ring_stats.rx.alloc_rx_buff_failed;
+ wx->qstats_base_rx_stats.csum_unnecessary_cnt +=
+ ring_stats.rx.csum_unnecessary_cnt;
+ wx->qstats_base_rx_stats.csum_err += ring_stats.rx.csum_err;
+ wx->qstats_base_rx_stats.rsc_count += ring_stats.rx.rsc_count;
+ wx->qstats_base_rx_stats.rsc_flush += ring_stats.rx.rsc_flush;
rcu_assign_pointer(wx->rx_ring[ring->queue_index], NULL);
+ }
+ spin_unlock(&wx->hw_stats_lock);
wx->q_vector[v_idx] = NULL;
netif_napi_del(&q_vector->napi);
@@ -2288,13 +2343,13 @@ static int wx_alloc_q_vectors(struct wx *wx)
return 0;
err_out:
+ while (v_idx--)
+ wx_free_q_vector(wx, v_idx);
+
WRITE_ONCE(wx->num_tx_queues, 0);
WRITE_ONCE(wx->num_rx_queues, 0);
wx->num_q_vectors = 0;
- while (v_idx--)
- wx_free_q_vector(wx, v_idx);
-
return -ENOMEM;
}
@@ -2310,12 +2365,16 @@ static void wx_free_q_vectors(struct wx *wx)
{
int v_idx = wx->num_q_vectors;
+ while (v_idx--)
+ wx_free_q_vector(wx, v_idx);
+
+ /* Publish the zeroed counts only once every ring has been folded into
+ * the base values, so a reader that pairs the counts with the base
+ * cannot miss a ring that is still waiting to be folded.
+ */
WRITE_ONCE(wx->num_tx_queues, 0);
WRITE_ONCE(wx->num_rx_queues, 0);
wx->num_q_vectors = 0;
-
- while (v_idx--)
- wx_free_q_vector(wx, v_idx);
}
void wx_reset_interrupt_capability(struct wx *wx)
@@ -3087,39 +3146,42 @@ void wx_get_stats64(struct net_device *netdev,
num_rx_queues = READ_ONCE(wx->num_rx_queues);
num_tx_queues = READ_ONCE(wx->num_tx_queues);
+ /* Pair with kfree_rcu() in wx_free_q_vector(). */
rcu_read_lock();
+ /* wx_free_q_vector() folds a ring into the base values under the same
+ * lock, so the snapshot cannot mix a ring with its retained value.
+ * The lock has to span the ring walk: the base values are read after
+ * it, and a ring folded in between would be counted twice.
+ */
+ spin_lock(&wx->hw_stats_lock);
for (i = 0; i < num_rx_queues; i++) {
struct wx_ring *ring = rcu_dereference(wx->rx_ring[i]);
- u64 bytes, packets;
- unsigned int start;
if (ring) {
- do {
- start = u64_stats_fetch_begin(&ring->syncp);
- packets = ring->stats.packets;
- bytes = ring->stats.bytes;
- } while (u64_stats_fetch_retry(&ring->syncp, start));
- stats->rx_packets += packets;
- stats->rx_bytes += bytes;
+ struct wx_rx_ring_stats ring_stats;
+
+ wx_ring_get_rx_stats(ring, &ring_stats);
+ stats->rx_packets += ring_stats.queue.packets;
+ stats->rx_bytes += ring_stats.queue.bytes;
}
}
for (i = 0; i < num_tx_queues; i++) {
struct wx_ring *ring = rcu_dereference(wx->tx_ring[i]);
- u64 bytes, packets;
- unsigned int start;
if (ring) {
- do {
- start = u64_stats_fetch_begin(&ring->syncp);
- packets = ring->stats.packets;
- bytes = ring->stats.bytes;
- } while (u64_stats_fetch_retry(&ring->syncp,
- start));
- stats->tx_packets += packets;
- stats->tx_bytes += bytes;
+ struct wx_tx_ring_stats ring_stats;
+
+ wx_ring_get_tx_stats(ring, &ring_stats);
+ stats->tx_packets += ring_stats.queue.packets;
+ stats->tx_bytes += ring_stats.queue.bytes;
}
}
+ stats->rx_packets += wx->qstats_base_rx.packets;
+ stats->rx_bytes += wx->qstats_base_rx.bytes;
+ stats->tx_packets += wx->qstats_base_tx.packets;
+ stats->tx_bytes += wx->qstats_base_tx.bytes;
+ spin_unlock(&wx->hw_stats_lock);
rcu_read_unlock();
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index f376c0b22da52..c343831c1dd0a 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -8,6 +8,7 @@
#include <linux/timecounter.h>
#include <linux/bitfield.h>
#include <linux/netdevice.h>
+#include <linux/u64_stats_sync.h>
#include <linux/if_vlan.h>
#include <linux/phylink.h>
#include <linux/dim.h>
@@ -1044,13 +1045,26 @@ struct wx_queue_stats {
struct wx_tx_queue_stats {
u64 restart_queue;
+ u64 restart_queue_napi;
+ u64 stop_queue;
u64 tx_busy;
u32 tx_done_old;
};
+/* TX counters that survive a queue teardown, named after what netdev-genl
+ * reports: stop counts the times the queue was stopped because it was
+ * full, wake counts every restart, both from the xmit reprieve path and
+ * from NAPI.
+ */
+struct wx_tx_retained_stats {
+ u64 stop;
+ u64 wake;
+ u64 tx_busy;
+};
+
struct wx_rx_queue_stats {
u64 non_eop_descs;
- u64 csum_good_cnt;
+ u64 csum_unnecessary_cnt;
u64 csum_err;
u64 alloc_rx_buff_failed;
u64 rsc_count;
@@ -1114,13 +1128,65 @@ struct wx_ring {
};
struct wx_queue_stats stats;
- struct u64_stats_sync syncp;
+ /* Guards the counters updated from NAPI: stats and rx_stats on an RX
+ * ring, stats and tx_stats.restart_queue_napi on a TX ring.
+ */
+ struct u64_stats_sync napi_syncp;
+ /* Guards the counters updated from the xmit path on a TX ring:
+ * tx_stats.restart_queue, tx_stats.stop_queue and tx_stats.tx_busy.
+ * Keep it separate from napi_syncp so that the two producers never
+ * hold the same seqcount odd at the same time.
+ */
+ struct u64_stats_sync xmit_syncp;
union {
struct wx_tx_queue_stats tx_stats;
struct wx_rx_queue_stats rx_stats;
};
} ____cacheline_internodealigned_in_smp;
+struct wx_rx_ring_stats {
+ struct wx_queue_stats queue;
+ struct wx_rx_queue_stats rx;
+};
+
+struct wx_tx_ring_stats {
+ struct wx_queue_stats queue;
+ struct wx_tx_retained_stats tx;
+};
+
+static inline void wx_ring_get_rx_stats(struct wx_ring *ring,
+ struct wx_rx_ring_stats *stats)
+{
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin(&ring->napi_syncp);
+ stats->queue = ring->stats;
+ stats->rx = ring->rx_stats;
+ } while (u64_stats_fetch_retry(&ring->napi_syncp, start));
+}
+
+static inline void wx_ring_get_tx_stats(struct wx_ring *ring,
+ struct wx_tx_ring_stats *stats)
+{
+ u64 restart_queue_napi;
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin(&ring->napi_syncp);
+ stats->queue = ring->stats;
+ restart_queue_napi = ring->tx_stats.restart_queue_napi;
+ } while (u64_stats_fetch_retry(&ring->napi_syncp, start));
+
+ do {
+ start = u64_stats_fetch_begin(&ring->xmit_syncp);
+ stats->tx.stop = ring->tx_stats.stop_queue;
+ stats->tx.wake = ring->tx_stats.restart_queue +
+ restart_queue_napi;
+ stats->tx.tx_busy = ring->tx_stats.tx_busy;
+ } while (u64_stats_fetch_retry(&ring->xmit_syncp, start));
+}
+
struct wx_q_vector {
struct wx *wx;
int cpu; /* CPU for DCA */
@@ -1371,6 +1437,10 @@ struct wx {
struct wx_ring __rcu *tx_ring[64] ____cacheline_aligned_in_smp;
struct wx_ring __rcu *rx_ring[64];
struct wx_q_vector *q_vector[64];
+ struct wx_queue_stats qstats_base_rx;
+ struct wx_queue_stats qstats_base_tx;
+ struct wx_rx_queue_stats qstats_base_rx_stats;
+ struct wx_tx_retained_stats qstats_base_tx_stats;
int num_rx_pools;
int num_rx_queues_per_pool;
@@ -1401,7 +1471,13 @@ struct wx {
struct wx_hw_stats stats;
struct wx_last_stats last_stats;
- spinlock_t hw_stats_lock; /* spinlock for accessing to hw stats */
+ /* Protects the read-modify-write updates of wx->stats, including the
+ * hardware counters sampled in wx_update_stats(), the qstats_base_*
+ * accumulators and the hand-off of a ring into them when a queue
+ * vector is freed. Readers hold it while they pair the live rings
+ * with the retained values.
+ */
+ spinlock_t hw_stats_lock;
u64 tx_busy;
u64 non_eop_descs;
u64 restart_queue;
--
2.30.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl
2026-11-30 8:34 [PATCH net-next v2 0/3] net: wangxun: improve statistics support Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration Mengyuan Lou
@ 2026-11-30 8:34 ` Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
2026-11-30 8:34 ` [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64 Mengyuan Lou
2 siblings, 1 reply; 7+ messages in thread
From: Mengyuan Lou @ 2026-11-30 8:34 UTC (permalink / raw)
To: netdev
Cc: jiawenwu, duanqiangwen, linglingzhang, andrew+netdev, davem,
edumazet, kuba, pabeni, Mengyuan Lou
Implement the netdev_stat_ops callbacks in libwx and register them for
the ngbe, ngbevf, txgbe and txgbevf netdevs, so that the queue statistics
already collected by the driver are available through the standard
netdev-genl interface instead of growing more driver-private ethtool -S
strings.
The per-queue callbacks read the live rings: packet and byte counters for
both directions, the RX allocation failure and checksum counters that
netdev-genl has attributes for, and the transmit queue stop and wake
counts. The tx_busy counter is not reported, as it counts packets
deferred because the ring was full rather than queue state changes.
get_base_stats() reports the counters retained when a queue vector is
torn down, and netdev-genl adds the live queue statistics on top of
them. A device total therefore keeps including the traffic of queues
that no longer exist and does not drop when the ring count is lowered,
while a plain sum over the current queues no longer adds up to that
total.
The PF-only hardware counters that have no netdev-genl attribute stay
available through ethtool -S, among them rdmdrop, which the driver
reports as rx_no_dma_resources; a VF does not read them at all. The error
counters and qmprc, as multicast, are also exported through
rtnl_link_stats64. csum_err is reported as RX csum_bad, which is the
counter that ethtool -S calls rx_csum_offload_errors.
Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
---
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 90 +++++++++++++++++++
drivers/net/ethernet/wangxun/libwx/wx_lib.h | 1 +
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 1 +
.../net/ethernet/wangxun/ngbevf/ngbevf_main.c | 1 +
.../net/ethernet/wangxun/txgbe/txgbe_main.c | 1 +
.../ethernet/wangxun/txgbevf/txgbevf_main.c | 1 +
6 files changed, 95 insertions(+)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 2868232792588..0502b5d8e96e8 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -5,6 +5,7 @@
#include <net/ip6_checksum.h>
#include <net/page_pool/helpers.h>
#include <net/inet_ecn.h>
+#include <net/netdev_queues.h>
#include <linux/workqueue.h>
#include <linux/iopoll.h>
#include <linux/sctp.h>
@@ -3193,6 +3194,95 @@ void wx_get_stats64(struct net_device *netdev,
}
EXPORT_SYMBOL(wx_get_stats64);
+static void wx_get_queue_stats_rx(struct net_device *dev, int idx,
+ struct netdev_queue_stats_rx *stats)
+{
+ struct wx_rx_ring_stats ring_stats;
+ struct wx *wx = netdev_priv(dev);
+ struct wx_ring *ring;
+
+ /* The ring pointer is published and cleared with RCU primitives, so
+ * a ring that a teardown has already cleared is simply skipped.
+ */
+ if (idx < 0 || idx >= READ_ONCE(wx->num_rx_queues))
+ return;
+
+ rcu_read_lock();
+ ring = rcu_dereference(wx->rx_ring[idx]);
+ if (!ring)
+ goto out;
+
+ wx_ring_get_rx_stats(ring, &ring_stats);
+ stats->packets = ring_stats.queue.packets;
+ stats->bytes = ring_stats.queue.bytes;
+ stats->alloc_fail = ring_stats.rx.alloc_rx_buff_failed;
+ stats->csum_unnecessary = ring_stats.rx.csum_unnecessary_cnt;
+ stats->csum_bad = ring_stats.rx.csum_err;
+
+out:
+ rcu_read_unlock();
+}
+
+static void wx_get_queue_stats_tx(struct net_device *dev, int idx,
+ struct netdev_queue_stats_tx *stats)
+{
+ struct wx_tx_ring_stats ring_stats;
+ struct wx *wx = netdev_priv(dev);
+ struct wx_ring *ring;
+
+ if (idx < 0 || idx >= READ_ONCE(wx->num_tx_queues))
+ return;
+
+ rcu_read_lock();
+ ring = rcu_dereference(wx->tx_ring[idx]);
+ if (!ring)
+ goto out;
+
+ wx_ring_get_tx_stats(ring, &ring_stats);
+ stats->packets = ring_stats.queue.packets;
+ stats->bytes = ring_stats.queue.bytes;
+ stats->stop = ring_stats.tx.stop;
+ stats->wake = ring_stats.tx.wake;
+
+out:
+ rcu_read_unlock();
+}
+
+static void wx_get_base_stats(struct net_device *dev,
+ struct netdev_queue_stats_rx *rx,
+ struct netdev_queue_stats_tx *tx)
+{
+ struct wx *wx = netdev_priv(dev);
+
+ /* Read the retained values the same way as wx_get_stats64(), so that
+ * they cannot be updated while they are being gathered.
+ */
+ spin_lock(&wx->hw_stats_lock);
+ rx->bytes = wx->qstats_base_rx.bytes;
+ rx->packets = wx->qstats_base_rx.packets;
+ rx->alloc_fail = wx->qstats_base_rx_stats.alloc_rx_buff_failed;
+ rx->csum_unnecessary =
+ wx->qstats_base_rx_stats.csum_unnecessary_cnt;
+ rx->csum_bad = wx->qstats_base_rx_stats.csum_err;
+ tx->bytes = wx->qstats_base_tx.bytes;
+ tx->packets = wx->qstats_base_tx.packets;
+ tx->stop = wx->qstats_base_tx_stats.stop;
+ tx->wake = wx->qstats_base_tx_stats.wake;
+ spin_unlock(&wx->hw_stats_lock);
+}
+
+static const struct netdev_stat_ops wx_stat_ops = {
+ .get_queue_stats_rx = wx_get_queue_stats_rx,
+ .get_queue_stats_tx = wx_get_queue_stats_tx,
+ .get_base_stats = wx_get_base_stats,
+};
+
+void wx_set_stat_ops(struct net_device *netdev)
+{
+ netdev->stat_ops = &wx_stat_ops;
+}
+EXPORT_SYMBOL(wx_set_stat_ops);
+
int wx_set_features(struct net_device *netdev, netdev_features_t features)
{
netdev_features_t changed = netdev->features ^ features;
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.h b/drivers/net/ethernet/wangxun/libwx/wx_lib.h
index 9d85d399e17f4..f9ce79ba350b7 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.h
@@ -30,6 +30,7 @@ void wx_free_resources(struct wx *wx);
int wx_setup_resources(struct wx *wx);
void wx_get_stats64(struct net_device *netdev,
struct rtnl_link_stats64 *stats);
+void wx_set_stat_ops(struct net_device *netdev);
int wx_set_features(struct net_device *netdev, netdev_features_t features);
netdev_features_t wx_fix_features(struct net_device *netdev,
netdev_features_t features);
diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
index bef7089d0e47e..cdfb6e61f70af 100644
--- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
+++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
@@ -771,6 +771,7 @@ static int ngbe_probe(struct pci_dev *pdev,
wx->driver_name = ngbe_driver_name;
ngbe_set_ethtool_ops(netdev);
netdev->netdev_ops = &ngbe_netdev_ops;
+ wx_set_stat_ops(netdev);
netdev->features = NETIF_F_SG | NETIF_F_IP_CSUM |
NETIF_F_TSO | NETIF_F_TSO6 |
diff --git a/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c b/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
index c40b64564d41f..2df781150cc0e 100644
--- a/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
+++ b/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
@@ -190,6 +190,7 @@ static int ngbevf_probe(struct pci_dev *pdev,
wx->driver_name = KBUILD_MODNAME;
wx_set_ethtool_ops_vf(netdev);
netdev->netdev_ops = &ngbevf_netdev_ops;
+ wx_set_stat_ops(netdev);
/* setup the private structure */
err = ngbevf_sw_init(wx);
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
index 3111409861590..f3c37609710d7 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
@@ -790,6 +790,7 @@ static int txgbe_probe(struct pci_dev *pdev,
wx->driver_name = txgbe_driver_name;
txgbe_set_ethtool_ops(netdev);
netdev->netdev_ops = &txgbe_netdev_ops;
+ wx_set_stat_ops(netdev);
netdev->udp_tunnel_nic_info = &txgbe_udp_tunnels;
/* setup the private structure */
diff --git a/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c b/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
index f1784c0ed114d..984ccb52bd6de 100644
--- a/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
+++ b/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
@@ -255,6 +255,7 @@ static int txgbevf_probe(struct pci_dev *pdev,
wx->driver_name = KBUILD_MODNAME;
wx_set_ethtool_ops_vf(netdev);
netdev->netdev_ops = &txgbevf_netdev_ops;
+ wx_set_stat_ops(netdev);
/* setup the private structure */
err = txgbevf_sw_init(wx);
--
2.30.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64
2026-11-30 8:34 [PATCH net-next v2 0/3] net: wangxun: improve statistics support Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl Mengyuan Lou
@ 2026-11-30 8:34 ` Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
2 siblings, 1 reply; 7+ messages in thread
From: Mengyuan Lou @ 2026-11-30 8:34 UTC (permalink / raw)
To: netdev
Cc: jiawenwu, duanqiangwen, linglingzhang, andrew+netdev, davem,
edumazet, kuba, pabeni, Mengyuan Lou
Register wx_get_stats64() as ndo_get_stats64 for ngbevf and txgbevf, so
their standard network statistics include aggregate RX/TX packet and
byte totals summed from the queue rings, including values retained
across queue-vector reconfiguration.
wx_update_stats() must not touch the PF-only statistics registers when it
runs on a VF: they sit in the PF register block where an access from a VF
hangs the system, as commit 694de316f607 ("net: libwx: fix VF illegal
register access") records for WX_CFG_PORT_ST. Record the device role in a
wx field that the VF drivers set before touching the hardware, instead of
relying on pci_dev::is_virtfn, which only the host's SR-IOV implementation
sets: a VF enumerated inside a guest does not have it. Convert the other
VF checks in libwx to the same field so that every path agrees on the
role.
Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
---
drivers/net/ethernet/wangxun/libwx/wx_ethtool.c | 2 +-
drivers/net/ethernet/wangxun/libwx/wx_hw.c | 8 ++++----
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 6 +++---
drivers/net/ethernet/wangxun/libwx/wx_type.h | 6 ++++++
drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c | 5 +++++
drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c | 5 +++++
6 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
index 8f0bbdbb4cf23..b4ee424604e75 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
@@ -488,7 +488,7 @@ int wx_set_coalesce(struct net_device *netdev,
else
/* rx only or mixed */
q_vector->itr = rx_itr_param;
- if (wx->pdev->is_virtfn)
+ if (wx->is_vf)
wx_write_eitr_vf(q_vector);
else
wx_write_eitr(q_vector);
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
index a367ed45fc127..5463ca426fc33 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
@@ -125,7 +125,7 @@ void wx_intr_enable(struct wx *wx, u64 qmask)
{
u32 mask;
- if (wx->pdev->is_virtfn) {
+ if (wx->is_vf) {
wr32(wx, WX_VXIMC, qmask);
return;
}
@@ -2492,14 +2492,14 @@ int wx_sw_init(struct wx *wx)
wx->oem_svid = pdev->subsystem_vendor;
wx->oem_ssid = pdev->subsystem_device;
wx->bus.device = PCI_SLOT(pdev->devfn);
- if (pdev->is_virtfn)
+ if (wx->is_vf)
wx->bus.func = PCI_FUNC(pdev->devfn);
else
wx->bus.func = FIELD_GET(WX_CFG_PORT_ST_LANID,
rd32(wx, WX_CFG_PORT_ST));
if (wx->oem_svid == PCI_VENDOR_ID_WANGXUN ||
- pdev->is_virtfn) {
+ wx->is_vf) {
wx->subsystem_vendor_id = pdev->subsystem_vendor;
wx->subsystem_device_id = pdev->subsystem_device;
} else {
@@ -2981,7 +2981,7 @@ void wx_update_stats(struct wx *wx)
wx->restart_queue = wx->qstats_base_tx_stats.wake + restart_queue;
wx->tx_busy = wx->qstats_base_tx_stats.tx_busy + tx_busy;
- if (!update_hw_stats)
+ if (!update_hw_stats || wx->is_vf)
goto skip_hw_stats;
wx_update_xoff_rx_lfc(wx);
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 0502b5d8e96e8..4808363f844dc 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -1796,7 +1796,7 @@ static void wx_set_itr(struct wx_q_vector *q_vector)
/* save the algorithm value here */
q_vector->itr = new_itr;
- if (wx->pdev->is_virtfn)
+ if (wx->is_vf)
wx_write_eitr_vf(q_vector);
else
wx_write_eitr(q_vector);
@@ -2067,7 +2067,7 @@ static int wx_set_interrupt_capability(struct wx *wx)
/* We will try to get MSI-X interrupts first */
ret = wx_acquire_msix_vectors(wx);
- if (ret == 0 || (ret == -ENOMEM) || pdev->is_virtfn)
+ if (ret == 0 || (ret == -ENOMEM) || wx->is_vf)
return ret;
/* Disable VMDq support */
@@ -2414,7 +2414,7 @@ int wx_init_interrupt_scheme(struct wx *wx)
int ret;
/* Number of supported queues */
- if (wx->pdev->is_virtfn) {
+ if (wx->is_vf) {
if (wx->set_num_queues)
wx->set_num_queues(wx);
} else {
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index c343831c1dd0a..c37e6cbb05c50 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -1370,6 +1370,12 @@ struct wx {
u8 __iomem *hw_addr;
u8 __iomem *b4_addr; /* vf only */
struct pci_dev *pdev;
+ /* Whether this instance drives a VF. Set by the VF drivers before the
+ * hardware is touched: pci_dev::is_virtfn is only set for the VFs the
+ * host's SR-IOV implementation enumerates, so it stays clear for a VF
+ * probed inside a guest.
+ */
+ bool is_vf;
struct net_device *netdev;
struct wx_bus_info bus;
struct wx_mbx_info mbx;
diff --git a/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c b/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
index 2df781150cc0e..44b8d4d4f3acc 100644
--- a/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
+++ b/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
@@ -48,6 +48,7 @@ static const struct net_device_ops ngbevf_netdev_ops = {
.ndo_start_xmit = wx_xmit_frame,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = wx_set_mac_vf,
+ .ndo_get_stats64 = wx_get_stats64,
};
static void ngbevf_set_num_queues(struct wx *wx)
@@ -176,6 +177,10 @@ static int ngbevf_probe(struct pci_dev *pdev,
wx = netdev_priv(netdev);
wx->netdev = netdev;
wx->pdev = pdev;
+ /* Record the role before the hardware is touched: pci_dev::is_virtfn
+ * is not set for a VF that the guest enumerated itself.
+ */
+ wx->is_vf = true;
wx->msg_enable = netif_msg_init(-1, NETIF_MSG_DRV |
NETIF_MSG_PROBE | NETIF_MSG_LINK);
diff --git a/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c b/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
index 984ccb52bd6de..0391c8232ef04 100644
--- a/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
+++ b/drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
@@ -44,6 +44,7 @@ static const struct net_device_ops txgbevf_netdev_ops = {
.ndo_start_xmit = wx_xmit_frame,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = wx_set_mac_vf,
+ .ndo_get_stats64 = wx_get_stats64,
};
static void txgbevf_set_num_queues(struct wx *wx)
@@ -233,6 +234,10 @@ static int txgbevf_probe(struct pci_dev *pdev,
wx = netdev_priv(netdev);
wx->netdev = netdev;
wx->pdev = pdev;
+ /* Record the role before the hardware is touched: pci_dev::is_virtfn
+ * is not set for a VF that the guest enumerated itself.
+ */
+ wx->is_vf = true;
wx->msg_enable = netif_msg_init(-1, NETIF_MSG_DRV |
NETIF_MSG_PROBE | NETIF_MSG_LINK);
--
2.30.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration
2026-11-30 8:34 ` [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration Mengyuan Lou
@ 2026-12-01 8:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 8:36 UTC (permalink / raw)
To: mengyuanlou
Cc: netdev, jiawenwu, duanqiangwen, linglingzhang, andrew+netdev,
davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] wx_get_stats64()
(drivers/net/ethernet/wangxun/libwx/wx_lib.c:3147-3148) reads…
- [Low] The new TX stop counter and the existing wake counter do not
count the same events, so wake can be larger than stop.
- [Low] This feature patch also carries an unannounced fix for an
existing bug.
--
net: libwx: preserve queue stats across reconfiguration
When queue vectors are freed, this patch keeps the per-ring packet, byte
and error counters in new qstats_base_* accumulators, protected by
hw_stats_lock. It also splits the ring u64_stats_sync into napi_syncp and
xmit_syncp, initializes both, and moves the rx/tx error counters under the
seqcounts. A new stop_queue counter is added next to restart_queue, and
the pair is reported as retained stop/wake counters.
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> index 10f095fb7085c..2868232792588 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
[ ... ]
> @@ -1021,12 +1039,18 @@ static int wx_maybe_stop_tx(struct wx_ring *tx_ring, u16 size)
> /* We need to check again in a case another CPU has just
> * made room available.
> */
> - if (likely(wx_desc_unused(tx_ring) < size))
> + if (likely(wx_desc_unused(tx_ring) < size)) {
> + u64_stats_update_begin(&tx_ring->xmit_syncp);
> + ++tx_ring->tx_stats.stop_queue;
> + u64_stats_update_end(&tx_ring->xmit_syncp);
> return -EBUSY;
> + }
>
> /* A reprieve! - use start_queue because it doesn't call schedule */
> netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
> + u64_stats_update_begin(&tx_ring->xmit_syncp);
> ++tx_ring->tx_stats.restart_queue;
> + u64_stats_update_end(&tx_ring->xmit_syncp);
>
> return 0;
> }
[Severity: Low]
Can tx wake end up larger than tx stop here?
On the reprieve path, netif_stop_subqueue() has already stopped the queue
because the ring was full, and netif_start_subqueue() restarts it. That
increments restart_queue but not stop_queue. wx_ring_get_tx_stats() then
reports:
stats->tx.stop = ring->tx_stats.stop_queue;
stats->tx.wake = ring->tx_stats.restart_queue +
restart_queue_napi;
wx_free_q_vector() folds both values into qstats_base_tx_stats, so each
reprieve adds a wake with no matching stop.
The comment on struct wx_tx_retained_stats says these counters are "named
after what netdev-genl reports". The later patch "net: wangxun: expose
queue stats via netdev-genl" reports them as tx-stop and tx-wake through
wx_get_queue_stats_tx() and wx_get_base_stats(). netdev.yaml defines
tx-stop as the number of times the driver paused accepting new tx packets
because the queue was full, and the reprieve path does pause the queue.
Other drivers that use netif_subqueue_maybe_stop(), such as fbnic, count
neither a stop nor a wake for the reprieve result, so the two counters
stay paired.
The commit message states "the reprieve path only adds a wake". Should the
reprieve either count a stop as well, or not be counted as a wake?
[ ... ]
> @@ -2182,6 +2208,8 @@ static int wx_alloc_q_vector(struct wx *wx,
>
> /* apply Tx specific ring traits */
> ring->count = wx->tx_ring_count;
> + u64_stats_init(&ring->napi_syncp);
> + u64_stats_init(&ring->xmit_syncp);
>
> ring->queue_index = txr_idx;
> ring->reg_idx = wx_get_reg_idx(wx, txr_idx, false);
[Severity: Low]
This isn't a regression, but these u64_stats_init() calls, and the one
added for RX rings, seem to also fix an existing bug.
Before this patch, ring->syncp was never initialized. The rings come from
kzalloc_flex() in wx_alloc_q_vector(), and there is no u64_stats_init()
anywhere under drivers/net/ethernet/wangxun at the baseline.
On 32-bit SMP kernels with CONFIG_DEBUG_LOCK_ALLOC, the first
u64_stats_update_begin(&ring->syncp) in wx_clean_rx_irq() or
wx_clean_tx_irq() runs seqcount_acquire() on a zeroed lockdep_map. That
prints "INFO: trying to register non-static key" and turns lockdep off.
The baseline also updated the 64-bit rx_stats/tx_stats counters
(non_eop_descs, csum_err, csum_good_cnt, alloc_rx_buff_failed, rsc_*,
restart_queue, tx_busy) outside any syncp section. wx_update_stats() read
them without fetch_begin/retry, so 32-bit readers could see torn values.
Could the initialization and the move under the seqcount go into a
separate patch with a Fixes: tag? That would let them go to net and
stable instead of riding along with this feature change.
[ ... ]
> @@ -3087,39 +3146,42 @@ void wx_get_stats64(struct net_device *netdev,
>
> num_rx_queues = READ_ONCE(wx->num_rx_queues);
> num_tx_queues = READ_ONCE(wx->num_tx_queues);
> + /* Pair with kfree_rcu() in wx_free_q_vector(). */
> rcu_read_lock();
> + /* wx_free_q_vector() folds a ring into the base values under the same
> + * lock, so the snapshot cannot mix a ring with its retained value.
> + * The lock has to span the ring walk: the base values are read after
> + * it, and a ring folded in between would be counted twice.
> + */
> + spin_lock(&wx->hw_stats_lock);
[Severity: Medium]
Can the queue counts read here be stale by the time hw_stats_lock is
taken?
num_rx_queues and num_tx_queues are read before the lock. The ring walk
and the qstats_base_* values are only consistent under the lock. The new
counts and ring pointers are also published without hw_stats_lock:
wx_set_num_queues() sets the counts, then wx_alloc_q_vector() calls
rcu_assign_pointer().
Consider a /proc/net/dev reader, which holds only RCU and not RTNL:
CPU1
wx_get_stats64()
num_tx_queues = READ_ONCE(wx->num_tx_queues); /* 4 */
<preempted>
CPU2 (ethtool -L 8 under RTNL)
wx_clear_interrupt_scheme()
wx_free_q_vectors() /* folds rings 0..3 into qstats_base_* */
wx_init_interrupt_scheme()
wx_set_num_queues() /* 8 */
wx_alloc_q_vectors() /* publishes rings 0..7 */
open, traffic flows on rings 4..7
CPU1 resumes
spin_lock(&wx->hw_stats_lock);
walks only i < 4, then adds the full qstats_base_*
The reader leaves out the live counters of rings 4..7. Its rx/tx packets
and bytes can then be lower than an earlier snapshot. The same happens if
CPU1 reads 0 just after wx_free_q_vectors().
The commit message says the ordering "keeps base plus live rings
invariant at every instant" and that "a reader which pairs the counts
with the base values cannot skip a ring". wx_get_stats64() is unchanged
later in the series.
wx_update_stats() already reads the counts after spin_lock(). Would moving
these two READ_ONCE() calls after spin_lock(&wx->hw_stats_lock) be enough
to make wx_get_stats64() match that claim?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130083407.78429-1-mengyuanlou%40net-swift.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl
2026-11-30 8:34 ` [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl Mengyuan Lou
@ 2026-12-01 8:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 8:36 UTC (permalink / raw)
To: mengyuanlou
Cc: netdev, jiawenwu, duanqiangwen, linglingzhang, andrew+netdev,
davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] wx_get_queue_stats_tx() and wx_get_base_stats() export TX
stop/wake counters through netdev-genl, but the two counters are not…
- [Low] The commit message says the PF-only hardware counters left in
ethtool -S "have no netdev-genl attribute" and names rdmdrop…
- [Low] wx_get_queue_stats_rx() and wx_get_base_stats() fill the netdev-
genl rx-alloc-fail attribute from rx_stats.alloc_rx_buff_failed.
--
net: wangxun: expose queue stats via netdev-genl
This patch implements netdev_stat_ops in libwx and registers them for the
ngbe, ngbevf, txgbe and txgbevf netdevs. Per-queue packet, byte, RX
allocation failure, checksum and TX stop/wake counters become available
through netdev-genl. get_base_stats() reports the counters kept when a
queue vector is torn down.
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> index 2868232792588..0502b5d8e96e8 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
[ ... ]
> @@ -3193,6 +3194,95 @@ void wx_get_stats64(struct net_device *netdev,
> }
> EXPORT_SYMBOL(wx_get_stats64);
>
> +static void wx_get_queue_stats_rx(struct net_device *dev, int idx,
> + struct netdev_queue_stats_rx *stats)
> +{
[ ... ]
> + wx_ring_get_rx_stats(ring, &ring_stats);
> + stats->packets = ring_stats.queue.packets;
> + stats->bytes = ring_stats.queue.bytes;
> + stats->alloc_fail = ring_stats.rx.alloc_rx_buff_failed;
[Severity: Low]
Does rx_stats.alloc_rx_buff_failed cover everything rx-alloc-fail is
defined to count?
netdev.yaml describes rx-alloc-fail as "Number of times skb or buffer
allocation failed on the Rx datapath". The only place that increments
alloc_rx_buff_failed is wx_clean_rx_irq(), when wx_build_skb() fails to
allocate an skb:
skb = wx_build_skb(rx_ring, rx_buffer, rx_desc);
/* exit if we failed to retrieve a buffer */
if (!skb) {
rx_stats.alloc_rx_buff_failed++;
break;
}
When a page pool refill fails in wx_alloc_mapped_page(), the function
returns without updating any counter:
page = page_pool_dev_alloc_pages(rx_ring->page_pool);
if (unlikely(!page))
return false;
wx_alloc_rx_buffers() then just stops refilling.
Under memory pressure, could rx-alloc-fail read 0 while ring refills are
failing? wx_get_base_stats() exports the same counter through
qstats_base_rx_stats.alloc_rx_buff_failed. The rest of the series does
not change this.
> + stats->csum_unnecessary = ring_stats.rx.csum_unnecessary_cnt;
> + stats->csum_bad = ring_stats.rx.csum_err;
> +
> +out:
> + rcu_read_unlock();
> +}
> +
> +static void wx_get_queue_stats_tx(struct net_device *dev, int idx,
> + struct netdev_queue_stats_tx *stats)
> +{
[ ... ]
> + wx_ring_get_tx_stats(ring, &ring_stats);
> + stats->packets = ring_stats.queue.packets;
> + stats->bytes = ring_stats.queue.bytes;
> + stats->stop = ring_stats.tx.stop;
> + stats->wake = ring_stats.tx.wake;
[Severity: Medium]
Can tx-wake end up larger than tx-stop here?
wx_maybe_stop_tx() always stops the queue with netif_stop_subqueue().
However, it only increments stop_queue when the re-check still finds too
few descriptors. On the reprieve path it counts a restart but not the
stop that came just before it:
netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
...
if (likely(wx_desc_unused(tx_ring) < size)) {
...
++tx_ring->tx_stats.stop_queue;
...
return -EBUSY;
}
/* A reprieve! - use start_queue because it doesn't call schedule */
netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
...
++tx_ring->tx_stats.restart_queue;
wx_ring_get_tx_stats() then reports:
stats->tx.stop = ring->tx_stats.stop_queue;
stats->tx.wake = ring->tx_stats.restart_queue +
restart_queue_napi;
A race with TX completion can make the gap larger:
CPU1 (xmit) CPU2 (NAPI)
wx_maybe_stop_tx()
netif_stop_subqueue()
wx_clean_tx_irq()
__netif_subqueue_stopped()
netif_wake_subqueue()
++restart_queue_napi
wx_desc_unused() >= size
netif_start_subqueue()
++restart_queue
That is one real pause, zero counted stops and two counted wakes.
netdev.yaml defines tx-stop as the number of times the driver paused
accepting packets and tx-wake as the number of times it restarted, so
consumers would expect wake <= stop. For comparison, gve_tx_dqo.c counts a
stop before the reprieve check and a wake on the reprieve.
The earlier "net: libwx: preserve queue stats across reconfiguration"
commit chose this deliberately ("the reprieve path only adds a wake").
Once the counters are mapped to the tx-stop/tx-wake uAPI, though, the
pair no longer balances.
Would it make sense to count the stop unconditionally after
netif_stop_subqueue() in wx_maybe_stop_tx()?
The retained totals that wx_get_base_stats() reports in tx->stop and
tx->wake have the same asymmetry. The later "net: wangxun: expose VF
stats through ndo_get_stats64" commit in the series does not touch
wx_maybe_stop_tx() or the stat_ops.
> +
> +out:
> + rcu_read_unlock();
> +}
> +
> +static void wx_get_base_stats(struct net_device *dev,
> + struct netdev_queue_stats_rx *rx,
> + struct netdev_queue_stats_tx *tx)
> +{
> + struct wx *wx = netdev_priv(dev);
> +
> + /* Read the retained values the same way as wx_get_stats64(), so that
> + * they cannot be updated while they are being gathered.
> + */
> + spin_lock(&wx->hw_stats_lock);
> + rx->bytes = wx->qstats_base_rx.bytes;
> + rx->packets = wx->qstats_base_rx.packets;
> + rx->alloc_fail = wx->qstats_base_rx_stats.alloc_rx_buff_failed;
> + rx->csum_unnecessary =
> + wx->qstats_base_rx_stats.csum_unnecessary_cnt;
> + rx->csum_bad = wx->qstats_base_rx_stats.csum_err;
[Severity: Low]
The commit message says:
The PF-only hardware counters that have no netdev-genl attribute stay
available through ethtool -S, among them rdmdrop, which the driver
reports as rx_no_dma_resources;
Is that accurate for rdmdrop? wx_update_stats() adds in the
clear-on-read WX_RDM_DRP_PKT register:
hwstats->rdmdrop += rd32(wx, WX_RDM_DRP_PKT);
ethtool -S labels this counter rx_no_dma_resources.
netdev.yaml defines rx-hw-drop-overruns as "Number of packets dropped
due to transient lack of resources, such as buffer space, host
descriptors etc.". rx-hw-drops also covers packets that entered the
device but never left it.
include/net/netdev_queues.h allows get_base_stats() to report
device-level counters that belong to no queue. sfc and bnge already
report similar counters as hw_drop_overruns.
Could wx_get_base_stats() fill rx->hw_drop_overruns from rdmdrop on the
PF (!wx->is_vf)?
WX_RDM_DRP_PKT may also count drops on VF pools when SR-IOV is enabled.
If that is the reason to leave it out, could the commit message say so
instead? The rest of the series does not change this.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130083407.78429-1-mengyuanlou%40net-swift.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64
2026-11-30 8:34 ` [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64 Mengyuan Lou
@ 2026-12-01 8:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 8:36 UTC (permalink / raw)
To: mengyuanlou
Cc: netdev, jiawenwu, duanqiangwen, linglingzhang, andrew+netdev,
davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] This patch fixes a real bug that users can hit today, but it
is packaged as part of a feature patch.
--
net: wangxun: expose VF stats through ndo_get_stats64
This registers wx_get_stats64() as ndo_get_stats64 for ngbevf and txgbevf,
and makes wx_update_stats() skip the PF-only statistics registers on a VF.
It also adds a wx->is_vf field that the VF drivers set at probe time. All
the pci_dev::is_virtfn checks in libwx are converted to use it.
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> index a367ed45fc127..5463ca426fc33 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
[ ... ]
> @@ -2492,14 +2492,14 @@ int wx_sw_init(struct wx *wx)
> wx->oem_svid = pdev->subsystem_vendor;
> wx->oem_ssid = pdev->subsystem_device;
> wx->bus.device = PCI_SLOT(pdev->devfn);
> - if (pdev->is_virtfn)
> + if (wx->is_vf)
> wx->bus.func = PCI_FUNC(pdev->devfn);
> else
> wx->bus.func = FIELD_GET(WX_CFG_PORT_ST_LANID,
> rd32(wx, WX_CFG_PORT_ST));
>
> if (wx->oem_svid == PCI_VENDOR_ID_WANGXUN ||
> - pdev->is_virtfn) {
> + wx->is_vf) {
> wx->subsystem_vendor_id = pdev->subsystem_vendor;
> wx->subsystem_device_id = pdev->subsystem_device;
> } else {
[Severity: Medium]
Is this conversion part of the ndo_get_stats64 feature? It looks like a
standalone fix that could go to net with Fixes: tags.
pci_dev::is_virtfn is only set in pci_iov_add_virtfn(). So it is clear
for an ngbevf/txgbevf VF that is passed through to a guest. Before this
patch, a guest VF took the PF branch of every check converted here:
wx_sw_init() read WX_CFG_PORT_ST. Commit 694de316f607 ("net: libwx:
fix VF illegal register access") says that read hangs the system.
wx_sw_init() could also call wx_flash_read_dword() for non-Wangxun
subsystem vendors.
wx_intr_enable() wrote WX_PX_IMC(0/1) instead of WX_VXIMC.
wx_set_itr() and wx_set_coalesce() wrote WX_PX_ITR through
wx_write_eitr() instead of using wx_write_eitr_vf().
wx_init_interrupt_scheme() ran the PF wx_set_num_queues() instead of
the wx->set_num_queues callback.
wx_set_interrupt_capability() fell back to MSI/INTx instead of
returning the MSI-X error.
Most of these checks came from commit fd0a2e03bf6083 ("net: txgbevf: init
interrupts and request irqs"). The wx_sw_init() check came from
694de316f607.
The commit message describes this change as:
"Convert the other VF checks in libwx to the same field so that every
path agrees on the role."
It does not say that guest VFs currently hang or write the wrong
registers.
Only the new wx->is_vf check in wx_update_stats() depends on the
feature. Before this patch, wx_update_stats() was only called from
ngbe_service_task() and txgbe_service_task().
Could the is_virtfn to is_vf conversion be split into its own patch for
net? It could carry Fixes: 694de316f607, Fixes: fd0a2e03bf6083 and
Cc: stable, with the ndo_get_stats64 part sent to net-next. As it
stands, stable kernels that carry 694de316f607 keep the guest VF hang.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130083407.78429-1-mengyuanlou%40net-swift.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-01 8:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 8:34 [PATCH net-next v2 0/3] net: wangxun: improve statistics support Mengyuan Lou
2026-11-30 8:34 ` [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
2026-11-30 8:34 ` [PATCH net-next v2 2/3] net: wangxun: expose queue stats via netdev-genl Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
2026-11-30 8:34 ` [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64 Mengyuan Lou
2026-12-01 8:36 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox