Skip to content

Commit 9f2959b

Browse files
hkallweitdavem330
authored andcommitted
net: phy: improve handling delayed work
Using mod_delayed_work() allows to simplify handling delayed work and removes the need for the sync parameter in phy_trigger_machine(). Also introduce a helper phy_queue_state_machine() to encapsulate the low-level delayed work calls. No functional change intended. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a0651d8 commit 9f2959b

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

drivers/net/phy/phy.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ static int phy_start_aneg_priv(struct phy_device *phydev, bool sync)
537537
mutex_unlock(&phydev->lock);
538538

539539
if (trigger)
540-
phy_trigger_machine(phydev, sync);
540+
phy_trigger_machine(phydev);
541541

542542
return err;
543543
}
@@ -635,6 +635,13 @@ int phy_speed_up(struct phy_device *phydev)
635635
}
636636
EXPORT_SYMBOL_GPL(phy_speed_up);
637637

638+
static void phy_queue_state_machine(struct phy_device *phydev,
639+
unsigned int secs)
640+
{
641+
mod_delayed_work(system_power_efficient_wq, &phydev->state_queue,
642+
secs * HZ);
643+
}
644+
638645
/**
639646
* phy_start_machine - start PHY state machine tracking
640647
* @phydev: the phy_device struct
@@ -647,27 +654,22 @@ EXPORT_SYMBOL_GPL(phy_speed_up);
647654
*/
648655
void phy_start_machine(struct phy_device *phydev)
649656
{
650-
queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, HZ);
657+
phy_queue_state_machine(phydev, 1);
651658
}
652659
EXPORT_SYMBOL_GPL(phy_start_machine);
653660

654661
/**
655662
* phy_trigger_machine - trigger the state machine to run
656663
*
657664
* @phydev: the phy_device struct
658-
* @sync: indicate whether we should wait for the workqueue cancelation
659665
*
660666
* Description: There has been a change in state which requires that the
661667
* state machine runs.
662668
*/
663669

664-
void phy_trigger_machine(struct phy_device *phydev, bool sync)
670+
void phy_trigger_machine(struct phy_device *phydev)
665671
{
666-
if (sync)
667-
cancel_delayed_work_sync(&phydev->state_queue);
668-
else
669-
cancel_delayed_work(&phydev->state_queue);
670-
queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 0);
672+
phy_queue_state_machine(phydev, 0);
671673
}
672674

673675
/**
@@ -703,7 +705,7 @@ static void phy_error(struct phy_device *phydev)
703705
phydev->state = PHY_HALTED;
704706
mutex_unlock(&phydev->lock);
705707

706-
phy_trigger_machine(phydev, false);
708+
phy_trigger_machine(phydev);
707709
}
708710

709711
/**
@@ -745,7 +747,7 @@ static irqreturn_t phy_change(struct phy_device *phydev)
745747
mutex_unlock(&phydev->lock);
746748

747749
/* reschedule state queue work to run as soon as possible */
748-
phy_trigger_machine(phydev, true);
750+
phy_trigger_machine(phydev);
749751

750752
if (phy_interrupt_is_valid(phydev) && phy_clear_interrupt(phydev))
751753
goto phy_err;
@@ -911,7 +913,7 @@ void phy_start(struct phy_device *phydev)
911913
}
912914
mutex_unlock(&phydev->lock);
913915

914-
phy_trigger_machine(phydev, true);
916+
phy_trigger_machine(phydev);
915917
}
916918
EXPORT_SYMBOL(phy_start);
917919

@@ -1130,8 +1132,7 @@ void phy_state_machine(struct work_struct *work)
11301132
* called from phy_disconnect() synchronously.
11311133
*/
11321134
if (phy_polling_mode(phydev) && old_state != PHY_HALTED)
1133-
queue_delayed_work(system_power_efficient_wq, &phydev->state_queue,
1134-
PHY_STATE_TIME * HZ);
1135+
phy_queue_state_machine(phydev, PHY_STATE_TIME);
11351136
}
11361137

11371138
/**

include/linux/phy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ void phy_change_work(struct work_struct *work);
10541054
void phy_mac_interrupt(struct phy_device *phydev);
10551055
void phy_start_machine(struct phy_device *phydev);
10561056
void phy_stop_machine(struct phy_device *phydev);
1057-
void phy_trigger_machine(struct phy_device *phydev, bool sync);
1057+
void phy_trigger_machine(struct phy_device *phydev);
10581058
int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
10591059
void phy_ethtool_ksettings_get(struct phy_device *phydev,
10601060
struct ethtool_link_ksettings *cmd);

0 commit comments

Comments
 (0)