Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Mengyuan Lou
Mon, 30 Nov 2026 08:34
[PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64
Author: Mengyuan Lou
Date: Mon, 30 Nov 2026 08:34
Date: Mon, 30 Nov 2026 08:34
174 lines
15891 bytes
15891 bytes
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
Re: [PATCH net-next v2 3/3] net: wangxun: expose VF stats through ndo_get_stats64
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 08:36
Date: Tue, 01 Dec 2026 08:36
98 lines
11545 bytes
11545 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads