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>
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;
struct timer_list service_timer;
struct work_struct service_task;
+ struct mutex reset_lock; /* mutex for reset */
};
#define WX_INTR_ALL (~0ULL)
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)
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)
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++)
clear_reset:
clear_bit(WX_STATE_RESETTING, wx->state);
+ mutex_unlock(&wx->reset_lock);
return err;
}
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++)
clear_reset:
clear_bit(WX_STATE_RESETTING, wx->state);
+ mutex_unlock(&wx->reset_lock);
return err;
}
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)