]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: wangxun: replace busy-wait reset flag with kernel mutex
authorJiawen Wu <jiawenwu@trustnetic.com>
Tue, 7 Apr 2026 02:56:11 +0000 (10:56 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 15:42:28 +0000 (08:42 -0700)
Replace the busy-wait loop using test_and_set_bit(WX_STATE_RESETTING)
with a proper per-device mutex to serialize reset operations.

The reset flag is reserved for other code paths (like watchdog), which
need tocheck if a reset is in process.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Link: https://patch.msgid.link/20260407025616.33652-5-jiawenwu@trustnetic.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/wangxun/libwx/wx_hw.c
drivers/net/ethernet/wangxun/libwx/wx_type.h
drivers/net/ethernet/wangxun/libwx/wx_vf_common.c
drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c
drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c

index bee9e245e7927b4b1e3559c5525d262784b63def..05731a50d85ffbeeeef5d052a551f48cc0a9b3ab 100644 (file)
@@ -2513,6 +2513,7 @@ int wx_sw_init(struct wx *wx)
                return -ENOMEM;
        }
 
+       mutex_init(&wx->reset_lock);
        bitmap_zero(wx->state, WX_STATE_NBITS);
        bitmap_zero(wx->flags, WX_PF_FLAGS_NBITS);
        wx->misc_irq_domain = false;
index 29e5c5470c94beef85f9b43ea24a6bc6a309b2f9..0fbdda63b1419cbfe9f9c40474ae72be6e5ba94f 100644 (file)
@@ -1400,6 +1400,7 @@ struct wx {
 
        struct timer_list service_timer;
        struct work_struct service_task;
+       struct mutex reset_lock; /* mutex for reset */
 };
 
 #define WX_INTR_ALL (~0ULL)
@@ -1478,21 +1479,6 @@ static inline struct wx *phylink_to_wx(struct phylink_config *config)
        return container_of(config, struct wx, phylink_config);
 }
 
-static inline int wx_set_state_reset(struct wx *wx)
-{
-       u8 timeout = 50;
-
-       while (test_and_set_bit(WX_STATE_RESETTING, wx->state)) {
-               timeout--;
-               if (!timeout)
-                       return -EBUSY;
-
-               usleep_range(1000, 2000);
-       }
-
-       return 0;
-}
-
 static inline unsigned int wx_rx_pg_order(struct wx_ring *ring)
 {
 #if (PAGE_SIZE < 8192)
index ade2bfe563aaac9f9ca6d6e8e55adefd81e51347..75a6f0898afe1234524ec77eb0ee11655b99b999 100644 (file)
@@ -339,14 +339,16 @@ static void wxvf_down(struct wx *wx)
 
 static void wxvf_reinit_locked(struct wx *wx)
 {
-       while (test_and_set_bit(WX_STATE_RESETTING, wx->state))
-               usleep_range(1000, 2000);
+       mutex_lock(&wx->reset_lock);
+       set_bit(WX_STATE_RESETTING, wx->state);
+
        wxvf_down(wx);
        wx_free_irq(wx);
        wx_configure_vf(wx);
        wx_request_msix_irqs_vf(wx);
        wxvf_up_complete(wx);
        clear_bit(WX_STATE_RESETTING, wx->state);
+       mutex_unlock(&wx->reset_lock);
 }
 
 static void wxvf_reset_subtask(struct wx *wx)
index 2b6356622a13ecace9321e12e6c6d5f1f3b33379..1b76ad897e97e00bf3a50c3b6a027d0505f51f81 100644 (file)
@@ -32,9 +32,8 @@ static int ngbe_set_ringparam(struct net_device *netdev,
            new_rx_count == wx->rx_ring_count)
                return 0;
 
-       err = wx_set_state_reset(wx);
-       if (err)
-               return err;
+       mutex_lock(&wx->reset_lock);
+       set_bit(WX_STATE_RESETTING, wx->state);
 
        if (!netif_running(wx->netdev)) {
                for (i = 0; i < wx->num_tx_queues; i++)
@@ -65,6 +64,7 @@ static int ngbe_set_ringparam(struct net_device *netdev,
 
 clear_reset:
        clear_bit(WX_STATE_RESETTING, wx->state);
+       mutex_unlock(&wx->reset_lock);
        return err;
 }
 
index 9157b8275be1f7ff2c5d8bde56c02860423ee7cd..46375799d057ecc12ef47c0ec542b233bbe22185 100644 (file)
@@ -56,9 +56,8 @@ static int txgbe_set_ringparam(struct net_device *netdev,
            new_rx_count == wx->rx_ring_count)
                return 0;
 
-       err = wx_set_state_reset(wx);
-       if (err)
-               return err;
+       mutex_lock(&wx->reset_lock);
+       set_bit(WX_STATE_RESETTING, wx->state);
 
        if (!netif_running(wx->netdev)) {
                for (i = 0; i < wx->num_tx_queues; i++)
@@ -88,6 +87,7 @@ static int txgbe_set_ringparam(struct net_device *netdev,
 
 clear_reset:
        clear_bit(WX_STATE_RESETTING, wx->state);
+       mutex_unlock(&wx->reset_lock);
        return err;
 }
 
index 0de051450a82377c9b28b846f46ac2fb5308e204..00726605628b9a358532babefa6c466091d9218f 100644 (file)
@@ -598,20 +598,16 @@ int txgbe_setup_tc(struct net_device *dev, u8 tc)
 
 static void txgbe_reinit_locked(struct wx *wx)
 {
-       int err = 0;
-
        netif_trans_update(wx->netdev);
 
-       err = wx_set_state_reset(wx);
-       if (err) {
-               wx_err(wx, "wait device reset timeout\n");
-               return;
-       }
+       mutex_lock(&wx->reset_lock);
+       set_bit(WX_STATE_RESETTING, wx->state);
 
        txgbe_down(wx);
        txgbe_up(wx);
 
        clear_bit(WX_STATE_RESETTING, wx->state);
+       mutex_unlock(&wx->reset_lock);
 }
 
 void txgbe_do_reset(struct net_device *netdev)