wangxun: improve service task synchronization
Subsystems (3)
Jiawen Wu
maintainerv2 cover wangxun: improve service task synchronization
This series improves synchronization between asynchronous service work, device teardown, and module event handling in the Wangxun drivers.
---
v2:
- Check WX_STATE_DOWN before setting WX_STATE_SERVICE_SCHED.
v1: https://lore.kernel.org/all/[email protected]
---
Jiawen Wu (3):
net: wangxun: introduce WX_STATE_DOWN to serialize device shutdown
state
net: wangxun: avoid statistics updates during device teardown
net: txgbe: rework service event handling
drivers/net/ethernet/wangxun/libwx/wx_hw.c | 3 ++- drivers/net/ethernet/wangxun/libwx/wx_lib.c | 9 ++++--- drivers/net/ethernet/wangxun/libwx/wx_sriov.c | 2 +- drivers/net/ethernet/wangxun/libwx/wx_type.h | 1 + .../net/ethernet/wangxun/libwx/wx_vf_common.c | 8 ++++-- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 14 ++++++----- .../net/ethernet/wangxun/txgbe/txgbe_aml.c | 10 +++----- .../net/ethernet/wangxun/txgbe/txgbe_aml.h | 2 +- .../net/ethernet/wangxun/txgbe/txgbe_irq.c | 2 +- .../net/ethernet/wangxun/txgbe/txgbe_main.c | 25 ++++++++----------- 10 files changed, 39 insertions(+), 37 deletions(-)
Signature · 1 line
2.51.0
Jiawen Wu
maintainerPATCH v2 1/3 net: wangxun: introduce WX_STATE_DOWN to serialize device shutdown state
Replace various netif_running() checks with an explicit WX_STATE_DOWN state bit to track whether the device datapath and interrupt handling are operational.
The previous logic relied on netif_running() to gate interrupt reenablement, queue wakeups, statistics updates, and service task execution. However, netif_running() only reflects the administrative state of the netdevice and does not fully serialize against teardown and reset paths. During device shutdown and reset flows, asynchronous contexts such as interrupt handlers, NAPI poll, and service work could still observe netif_running() as true while device resources were already being disabled or freed.
--- drivers/net/ethernet/wangxun/libwx/wx_hw.c | 3 ++- drivers/net/ethernet/wangxun/libwx/wx_lib.c | 9 ++++++--- drivers/net/ethernet/wangxun/libwx/wx_sriov.c | 2 +- drivers/net/ethernet/wangxun/libwx/wx_type.h | 1 + drivers/net/ethernet/wangxun/libwx/wx_vf_common.c | 8 ++++++-- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 12 ++++++++---- drivers/net/ethernet/wangxun/txgbe/txgbe_irq.c | 2 +- drivers/net/ethernet/wangxun/txgbe/txgbe_main.c | 4 ++++ 8 files changed, 29 insertions(+), 12 deletions(-)
drivers/net/ethernet/wangxun/libwx/wx_hw.c +2 -1
@@ -2520,6 +2520,7 @@ int wx_sw_init(struct wx *wx)mutex_init (&wx->reset_lock);bitmap_zero (wx->state,WX_STATE_NBITS );bitmap_zero (wx->flags,WX_PF_FLAGS_NBITS ); +set_bit (WX_STATE_DOWN , wx->state); wx->misc_irq_domain = false;return 0 ;
@@ -2875,7 +2876,7 @@ void wx_update_stats(struct wx *wx)u64 restart_queue =0 , tx_busy =0 ;u32 i; -if (!netif_running (wx->netdev) || +if (test_bit (WX_STATE_DOWN , wx->state) ||test_bit (WX_STATE_RESETTING , wx->state))return ;
drivers/net/ethernet/wangxun/libwx/wx_lib.c +6 -3
@@ -876,7 +876,7 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector,if (__netif_subqueue_stopped (tx_ring->netdev, tx_ring->queue_index) && -netif_running (tx_ring->netdev)) { + !test_bit (WX_STATE_DOWN , wx->state)) {netif_wake_subqueue (tx_ring->netdev, tx_ring->queue_index); ++tx_ring->tx_stats.restart_queue;
@@ -964,7 +964,7 @@ static int wx_poll(struct napi_struct *napi, int budget)if (likely (napi_complete_done (napi, work_done))) {if (wx->adaptive_itr)wx_update_dim_sample (q_vector); -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))wx_intr_enable (wx,WX_INTR_Q (q_vector->v_idx)); }
@@ -2341,6 +2341,8 @@ int wx_init_interrupt_scheme(struct wx *wx)wx_cache_ring_rss (wx); +set_bit (WX_STATE_DOWN , wx->state); +return 0 ; }EXPORT_SYMBOL (wx_init_interrupt_scheme);
@@ -3314,7 +3316,8 @@ EXPORT_SYMBOL(wx_set_ring);void wx_service_event_schedule (struct wx *wx) { -if (!test_and_set_bit (WX_STATE_SERVICE_SCHED , wx->state)) +if (!test_bit (WX_STATE_DOWN , wx->state) && + !test_and_set_bit (WX_STATE_SERVICE_SCHED , wx->state))queue_work (system_power_efficient_wq, &wx->service_task); }EXPORT_SYMBOL (wx_service_event_schedule);
drivers/net/ethernet/wangxun/libwx/wx_sriov.c +1 -1
@@ -898,7 +898,7 @@ static void wx_set_vf_link_state(struct wx *wx, int vf, int state) wx->vfinfo[vf].link_state = state;switch (state) {case IFLA_VF_LINK_STATE_AUTO : -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state)) wx->vfinfo[vf].link_enable = true;else wx->vfinfo[vf].link_enable = false;
drivers/net/ethernet/wangxun/libwx/wx_type.h +1 -0
@@ -1202,6 +1202,7 @@ struct wx_last_stats { };enum wx_state { +WX_STATE_DOWN ,WX_STATE_RESETTING ,WX_STATE_SWFW_BUSY ,WX_STATE_PTP_RUNNING ,
drivers/net/ethernet/wangxun/libwx/wx_vf_common.c +6 -2
@@ -68,7 +68,7 @@ static irqreturn_t wx_msix_misc_vf(int __always_unused irq, void *data)set_bit (WX_FLAG_NEED_UPDATE_LINK , wx->flags);/* Clear the interrupt */ -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))wr32 (wx,WX_VXIMC , wx->eims_other);return IRQ_HANDLED ;
@@ -278,6 +278,7 @@ static void wxvf_up_complete(struct wx *wx)wx_configure_msix_vf (wx);smp_mb__before_atomic (); +clear_bit (WX_STATE_DOWN , wx->state);wx_napi_enable_all (wx);/* clear any pending interrupts, may auto mask */
@@ -327,6 +328,9 @@ static void wxvf_down(struct wx *wx) {struct net_device *netdev = wx->netdev; +if (test_and_set_bit (WX_STATE_DOWN , wx->state)) +return ; +timer_delete_sync (&wx->service_timer);netif_tx_stop_all_queues (netdev);netif_tx_disable (netdev);
@@ -360,7 +364,7 @@ static void wxvf_reset_subtask(struct wx *wx)rtnl_lock ();if (test_bit (WX_STATE_RESETTING , wx->state) || - !(netif_running (wx->netdev))) { +test_bit (WX_STATE_DOWN , wx->state)) {rtnl_unlock ();return ; }
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +8 -4
@@ -204,7 +204,7 @@ static irqreturn_t ngbe_intr(int __always_unused irq, void *data)/* shared interrupt alert! * the interrupt that we masked before the EICR read. */ -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))ngbe_irq_enable (wx, true);return IRQ_NONE ;/* Not our interrupt */ }
@@ -220,7 +220,7 @@ static irqreturn_t ngbe_intr(int __always_unused irq, void *data)/* would disable interrupts here but it is auto disabled */ napi_schedule_irqoff (&q_vector->napi); -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))ngbe_irq_enable (wx, false);return IRQ_HANDLED ;
@@ -235,7 +235,7 @@ static irqreturn_t __ngbe_msix_misc(struct wx *wx, u32 eicr)wx_ptp_check_pps_event (wx);/* re-enable the original interrupt state, no lsc, no queues */ -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))ngbe_irq_enable (wx, false);return IRQ_HANDLED ;
@@ -262,7 +262,7 @@ static irqreturn_t ngbe_misc_and_queue(int __always_unused irq, void *data)/* queue */ q_vector = wx->q_vector[0 ];napi_schedule_irqoff (&q_vector->napi); -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))ngbe_irq_enable (wx, true);return IRQ_HANDLED ; }
@@ -363,6 +363,9 @@ static void ngbe_disable_device(struct wx *wx)struct net_device *netdev = wx->netdev;u32 i; +if (test_and_set_bit (WX_STATE_DOWN , wx->state)) +return ; +if (wx->num_vfs) {/* Clear EITR Select mapping */ wr32 (wx,WX_PX_ITRSEL ,0 );
@@ -428,6 +431,7 @@ void ngbe_up(struct wx *wx)/* make sure to complete pre-operations */ smp_mb__before_atomic (); +clear_bit (WX_STATE_DOWN , wx->state);wx_napi_enable_all (wx);/* enable transmits */ netif_tx_start_all_queues (wx->netdev);
drivers/net/ethernet/wangxun/txgbe/txgbe_irq.c +1 -1
@@ -141,7 +141,7 @@ static irqreturn_t txgbe_misc_irq_handle(int irq, void *data)/* shared interrupt alert! * the interrupt that we masked before the ICR read. */ -if (netif_running (wx->netdev)) +if (!test_bit (WX_STATE_DOWN , wx->state))txgbe_irq_enable (wx, true);return IRQ_NONE ;/* Not our interrupt */ }
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +4 -0
@@ -151,6 +151,7 @@ static void txgbe_up_complete(struct wx *wx)/* make sure to complete pre-operations */ smp_mb__before_atomic (); +clear_bit (WX_STATE_DOWN , wx->state);wx_napi_enable_all (wx);switch (wx->mac.type) {
@@ -213,6 +214,9 @@ static void txgbe_disable_device(struct wx *wx)struct net_device *netdev = wx->netdev;u32 i; +if (test_and_set_bit (WX_STATE_DOWN , wx->state)) +return ; +wx_disable_pcie_master (wx);/* disable receives */ wx_disable_rx (wx);
Signature · 1 line
2.51.0
Jiawen Wu
maintainerPATCH v2 2/3 net: wangxun: avoid statistics updates during device teardown
In reply to Jiawen WuAfter introducing WX_STATE_DOWN, wx_update_stats() now explicitly skips statistics collection while the device is in teardown or reset state. Calling wx_update_stats() from the device disable path therefore becomes redundant.
Remove wx_update_stats() calls from ngbe_disable_device() and txgbe_disable_device().
--- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 2 -- drivers/net/ethernet/wangxun/txgbe/txgbe_main.c | 2 -- 2 files changed, 4 deletions(-)
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +0 -2
@@ -404,8 +404,6 @@ static void ngbe_disable_device(struct wx *wx)wr32 (wx,WX_PX_TR_CFG (reg_idx),WX_PX_TR_CFG_SWFLSH ); } - -wx_update_stats (wx); }static void ngbe_reset (struct wx *wx)
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +0 -2
@@ -265,8 +265,6 @@ static void txgbe_disable_device(struct wx *wx)/* Disable the Tx DMA engine */ wr32m (wx,WX_TDM_CTL ,WX_TDM_CTL_TE ,0 ); - -wx_update_stats (wx); }void txgbe_down (struct wx *wx)
Signature · 1 line
2.51.0
Jiawen Wu
maintainerPATCH v2 3/3 net: txgbe: rework service event handling
In reply to Jiawen WuConvert to use test_and_clear_bit() for link event subtasks. Only re-arm the WX_FLAG_NEED_MODULE_RESET flag when module is absent. Unsupported or invalid modules no longer cause the service task to continuously retry module identification.
Additionally, explicitly cancel service_task during device teardown to ensure no pending asynchronous service work survives after the device has entered the DOWN state.
--- .../net/ethernet/wangxun/txgbe/txgbe_aml.c | 10 +++------- .../net/ethernet/wangxun/txgbe/txgbe_aml.h | 2 +- .../net/ethernet/wangxun/txgbe/txgbe_main.c | 19 ++++++------------- 3 files changed, 10 insertions(+), 21 deletions(-)
drivers/net/ethernet/wangxun/txgbe/txgbe_aml.c +3 -7
@@ -186,19 +186,15 @@ static void txgbe_get_mac_link(struct wx *wx, int *speed) *speed =SPEED_UNKNOWN ; } -int txgbe_set_phy_link (struct wx *wx) +void txgbe_set_phy_link (struct wx *wx) {int speed, autoneg, duplex, err;txgbe_get_link_capabilities (wx, &speed, &autoneg, &duplex); err =txgbe_set_phy_link_hostif (wx, speed, autoneg, duplex); -if (err) { +if (err)wx_err (wx,"Failed to setup link\n" ); -return err; - } - -return 0 ; }static int txgbe_sfp_to_linkmodes (struct wx *wx,struct txgbe_sff_id *id)
@@ -362,7 +358,7 @@ int txgbe_identify_module(struct wx *wx) id->identifier != TXGBE_SFF_IDENTIFIER_QSFP_PLUS && id->identifier != TXGBE_SFF_IDENTIFIER_QSFP28) {wx_err (wx,"Invalid module\n" ); -return -ENODEV ; +return -EINVAL ; }if (id->transceiver_type ==0xFF )
drivers/net/ethernet/wangxun/txgbe/txgbe_aml.h +1 -1
@@ -10,7 +10,7 @@ int txgbe_test_hostif(struct wx *wx);int txgbe_read_eeprom_hostif (struct wx *wx,struct txgbe_hic_i2c_read *buffer,u32 length,u8 *data); -int txgbe_set_phy_link (struct wx *wx); +void txgbe_set_phy_link (struct wx *wx);int txgbe_identify_module (struct wx *wx);void txgbe_setup_link (struct wx *wx);int txgbe_phylink_init_aml (struct txgbe *txgbe);
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +6 -13
@@ -93,31 +93,23 @@ static void txgbe_module_detection_subtask(struct wx *wx) {int err; -if (!test_bit (WX_FLAG_NEED_MODULE_RESET , wx->flags)) +if (!test_and_clear_bit (WX_FLAG_NEED_MODULE_RESET , wx->flags))return ;/* wait for SFF module ready */ msleep (200 ); err =txgbe_identify_module (wx); -if (err) -return ; - -clear_bit (WX_FLAG_NEED_MODULE_RESET , wx->flags); +if (err == -ENODEV ) +set_bit (WX_FLAG_NEED_MODULE_RESET , wx->flags); }static void txgbe_link_config_subtask (struct wx *wx) { -int err; - -if (!test_bit (WX_FLAG_NEED_LINK_CONFIG , wx->flags)) +if (!test_and_clear_bit (WX_FLAG_NEED_LINK_CONFIG , wx->flags))return ; - err =txgbe_set_phy_link (wx); -if (err) -return ; - -clear_bit (WX_FLAG_NEED_LINK_CONFIG , wx->flags); +txgbe_set_phy_link (wx); }/**
@@ -233,6 +225,7 @@ static void txgbe_disable_device(struct wx *wx)wx_napi_disable_all (wx);timer_delete_sync (&wx->service_timer); +cancel_work_sync (&wx->service_task);if (wx->bus.func <2 )wr32m (wx,TXGBE_MIS_PRB_CTL ,TXGBE_MIS_PRB_CTL_LAN_UP (wx->bus.func),0 );
Signature · 1 line
2.51.0
Simon Horman
reviewerQuoted 8 lines · Jiawen Wu
This series improves synchronization between asynchronous service work, device teardown, and module event handling in the Wangxun drivers.
---
v2:
- CheckWX_STATE_DOWNbefore settingWX_STATE_SERVICE_SCHED.
Hi Jiawen,
There are AI-generated reviews of this patch-set available at
https://netdev-ai.bots.linux.dev/ and https://sashiko.dev/
I would appreciate it if you could look over them and address any issues that are either introduced by this patch-set, or directly impact it.
I would not suggest expanding this patchset to address any other pre-existing issues, but rather address them separately as appropriate.
Jiawen Wu
maintainerQuoted 15 lines · Simon Horman
Quoted 8 lines · Jiawen Wu
This series improves synchronization between asynchronous service work, device teardown, and module event handling in the Wangxun drivers.
---
v2:
- CheckWX_STATE_DOWNbefore settingWX_STATE_SERVICE_SCHED.Hi Jiawen,
There are AI-generated reviews of this patch-set available at
https://netdev-ai.bots.linux.dev/ and https://sashiko.dev/
Quoted 6 lines
I would appreciate it if you could look over them and address any issues that are either introduced by this patch-set, or directly impact it.
I would not suggest expanding this patchset to address any other pre-existing issues, but rather address them separately as appropriate.
Hi,
Looked over AI-generated reviews, there are some issues need to be clarified.
Sashiko-nipa exposes an existing issue in the wxvf resume flow. The VF PM resume path currently calls wx_init_interrupt_scheme() followed by netif_device_attach(), but does not reopen the device when the interface was running before suspend. I plan to address this separately by fixing the wxvf resume flow.
Sashiko-gemini exposes some issues but none of them were introduced by this patch set. And one issue I've clarified in the previous version.
Paolo Abeni
maintainerQuoted 27 lines · Jiawen Wu
Quoted 15 lines · Simon Horman
Quoted 8 lines · Jiawen Wu
This series improves synchronization between asynchronous service work, device teardown, and module event handling in the Wangxun drivers.
---
v2:
- CheckWX_STATE_DOWNbefore settingWX_STATE_SERVICE_SCHED.Hi Jiawen,
There are AI-generated reviews of this patch-set available at
https://netdev-ai.bots.linux.dev/ and https://sashiko.dev/Quoted 6 lines
I would appreciate it if you could look over them and address any issues that are either introduced by this patch-set, or directly impact it.
I would not suggest expanding this patchset to address any other pre-existing issues, but rather address them separately as appropriate.
Hi,
Looked over AI-generated reviews, there are some issues need to be clarified.
Quoted 8 lines
Sashiko-nipa exposes an existing issue in the wxvf resume flow. The VF PM resume path currently calls
wx_init_interrupt_scheme()followed bynetif_device_attach(), but does not reopen the device when the interface was running before suspend. I plan to address this separately by fixing the wxvf resume flow.Sashiko-gemini exposes some issues but none of them were introduced by this patch set. And one issue I've clarified in the previous version.
IMHO makes sense. I see the commit message somehow touches that point, but for future memory a more verbose/explicit wording would have been helpful.
Thanks,
Paolo
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Mon, 25 May 2026 18:05:40 +0800 you wrote:
This series improves synchronization between asynchronous service work, device teardown, and module event handling in the Wangxun drivers.
---
v2:
- CheckWX_STATE_DOWNbefore settingWX_STATE_SERVICE_SCHED.[...]
Here is the summary with links:
- [net-next,v2,1/3] net: wangxun: introduce WX_STATE_DOWN to serialize device shutdown state
https://git.kernel.org/netdev/net-next/c/7116ffb48ad0 - [net-next,v2,2/3] net: wangxun: avoid statistics updates during device teardown https://git.kernel.org/netdev/net-next/c/58ac2f8eb050 - [net-next,v2,3/3] net: txgbe: rework service event handling https://git.kernel.org/netdev/net-next/c/f67aead16e85
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html