* [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