Skip to content

Commit 257a824

Browse files
pkitszelanguy11
authored andcommitted
iavf: extract iavf_watchdog_step() out of iavf_watchdog_task()
Finish up easy refactor of watchdog_task, total for this + prev two commits is: 1 file changed, 47 insertions(+), 82 deletions(-) Signed-off-by: Przemek Kitszel <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent ecb4cd0 commit 257a824

File tree

1 file changed

+39
-48
lines changed

1 file changed

+39
-48
lines changed

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,77 +2913,53 @@ static void iavf_init_config_adapter(struct iavf_adapter *adapter)
29132913

29142914
static const int IAVF_NO_RESCHED = -1;
29152915

2916-
/**
2917-
* iavf_watchdog_task - Periodic call-back task
2918-
* @work: pointer to work_struct
2919-
**/
2920-
static void iavf_watchdog_task(struct work_struct *work)
2916+
/* return: msec delay for requeueing itself */
2917+
static int iavf_watchdog_step(struct iavf_adapter *adapter)
29212918
{
2922-
struct iavf_adapter *adapter = container_of(work,
2923-
struct iavf_adapter,
2924-
watchdog_task.work);
2925-
struct net_device *netdev = adapter->netdev;
29262919
struct iavf_hw *hw = &adapter->hw;
2927-
int msec_delay;
29282920
u32 reg_val;
29292921

2930-
netdev_lock(netdev);
2931-
if (!mutex_trylock(&adapter->crit_lock)) {
2932-
if (adapter->state == __IAVF_REMOVE) {
2933-
netdev_unlock(netdev);
2934-
return;
2935-
}
2936-
2937-
msec_delay = 20;
2938-
goto restart_watchdog;
2939-
}
2922+
netdev_assert_locked(adapter->netdev);
2923+
lockdep_assert_held(&adapter->crit_lock);
29402924

29412925
if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
29422926
iavf_change_state(adapter, __IAVF_COMM_FAILED);
29432927

29442928
switch (adapter->state) {
29452929
case __IAVF_STARTUP:
29462930
iavf_startup(adapter);
2947-
msec_delay = 30;
2948-
goto watchdog_done;
2931+
return 30;
29492932
case __IAVF_INIT_VERSION_CHECK:
29502933
iavf_init_version_check(adapter);
2951-
msec_delay = 30;
2952-
goto watchdog_done;
2934+
return 30;
29532935
case __IAVF_INIT_GET_RESOURCES:
29542936
iavf_init_get_resources(adapter);
2955-
msec_delay = 1;
2956-
goto watchdog_done;
2937+
return 1;
29572938
case __IAVF_INIT_EXTENDED_CAPS:
29582939
iavf_init_process_extended_caps(adapter);
2959-
msec_delay = 1;
2960-
goto watchdog_done;
2940+
return 1;
29612941
case __IAVF_INIT_CONFIG_ADAPTER:
29622942
iavf_init_config_adapter(adapter);
2963-
msec_delay = 1;
2964-
goto watchdog_done;
2943+
return 1;
29652944
case __IAVF_INIT_FAILED:
29662945
if (test_bit(__IAVF_IN_REMOVE_TASK,
29672946
&adapter->crit_section)) {
29682947
/* Do not update the state and do not reschedule
29692948
* watchdog task, iavf_remove should handle this state
29702949
* as it can loop forever
29712950
*/
2972-
msec_delay = IAVF_NO_RESCHED;
2973-
goto watchdog_done;
2951+
return IAVF_NO_RESCHED;
29742952
}
29752953
if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) {
29762954
dev_err(&adapter->pdev->dev,
29772955
"Failed to communicate with PF; waiting before retry\n");
29782956
adapter->flags |= IAVF_FLAG_PF_COMMS_FAILED;
29792957
iavf_shutdown_adminq(hw);
2980-
msec_delay = 5000;
2981-
goto watchdog_done;
2958+
return 5000;
29822959
}
29832960
/* Try again from failed step*/
29842961
iavf_change_state(adapter, adapter->last_state);
2985-
msec_delay = 1000;
2986-
goto watchdog_done;
2962+
return 1000;
29872963
case __IAVF_COMM_FAILED:
29882964
if (test_bit(__IAVF_IN_REMOVE_TASK,
29892965
&adapter->crit_section)) {
@@ -2993,8 +2969,7 @@ static void iavf_watchdog_task(struct work_struct *work)
29932969
*/
29942970
iavf_change_state(adapter, __IAVF_INIT_FAILED);
29952971
adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED;
2996-
msec_delay = IAVF_NO_RESCHED;
2997-
goto watchdog_done;
2972+
return IAVF_NO_RESCHED;
29982973
}
29992974
reg_val = rd32(hw, IAVF_VFGEN_RSTAT) &
30002975
IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
@@ -3012,11 +2987,9 @@ static void iavf_watchdog_task(struct work_struct *work)
30122987
}
30132988
adapter->aq_required = 0;
30142989
adapter->current_op = VIRTCHNL_OP_UNKNOWN;
3015-
msec_delay = 10;
3016-
goto watchdog_done;
2990+
return 10;
30172991
case __IAVF_RESETTING:
3018-
msec_delay = 2000;
3019-
goto watchdog_done;
2992+
return 2000;
30202993
case __IAVF_DOWN:
30212994
case __IAVF_DOWN_PENDING:
30222995
case __IAVF_TESTING:
@@ -3043,8 +3016,7 @@ static void iavf_watchdog_task(struct work_struct *work)
30433016
break;
30443017
case __IAVF_REMOVE:
30453018
default:
3046-
msec_delay = IAVF_NO_RESCHED;
3047-
goto watchdog_done;
3019+
return IAVF_NO_RESCHED;
30483020
}
30493021

30503022
/* check for hw reset */
@@ -3055,12 +3027,31 @@ static void iavf_watchdog_task(struct work_struct *work)
30553027
dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
30563028
iavf_schedule_reset(adapter, IAVF_FLAG_RESET_PENDING);
30573029
}
3058-
if (adapter->aq_required)
3030+
3031+
return adapter->aq_required ? 20 : 2000;
3032+
}
3033+
3034+
static void iavf_watchdog_task(struct work_struct *work)
3035+
{
3036+
struct iavf_adapter *adapter = container_of(work,
3037+
struct iavf_adapter,
3038+
watchdog_task.work);
3039+
struct net_device *netdev = adapter->netdev;
3040+
int msec_delay;
3041+
3042+
netdev_lock(netdev);
3043+
if (!mutex_trylock(&adapter->crit_lock)) {
3044+
if (adapter->state == __IAVF_REMOVE) {
3045+
netdev_unlock(netdev);
3046+
return;
3047+
}
3048+
30593049
msec_delay = 20;
3060-
else
3061-
msec_delay = 2000;
3050+
goto restart_watchdog;
3051+
}
3052+
3053+
msec_delay = iavf_watchdog_step(adapter);
30623054

3063-
watchdog_done:
30643055
mutex_unlock(&adapter->crit_lock);
30653056
restart_watchdog:
30663057
netdev_unlock(netdev);

0 commit comments

Comments
 (0)