Improve / simplify handling of states PHY_RUNNING and PHY_RESUMING in
phylib state machine.
Heiner Kallweit (2):
net: phy: improve handling of PHY_RUNNING in state machine
net: phy: simplify handling of PHY_RESUMING in state machine
drivers/net/phy/phy.c | 72 ++++++++++++++-----------------------------
1 file changed, 23 insertions(+), 49 deletions(-)
--
2.19.1
Handling of state PHY_RUNNING seems to be more complex than it needs
to be. If not polling, then we don't have to do anything, we'll
receive an interrupt and go to state PHY_CHANGELINK once the link
goes down. If polling and link is down, we don't have to go the
extra mile over PHY_CHANGELINK and call phy_read_status() again
but can set status PHY_NOLINK directly.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/phy.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
@@ -1025,26 +1024,16 @@ void phy_state_machine(struct work_struct *work)}break;casePHY_RUNNING:-/* Only register a CHANGE if we are polling and link changed-*sincelatestchecking.-*/-if(phy_polling_mode(phydev)){-old_link=phydev->link;-err=phy_read_status(phydev);-if(err)-break;+if(!phy_polling_mode(phydev))+break;-if(old_link!=phydev->link)-phydev->state=PHY_CHANGELINK;-}-/*-*Failsafe:checkthatnobodysetphydev->link=0betweentwo-*pollcycles,otherwisewewon'tleaveRUNNINGstateaslong-*aslinkremainsdown.-*/-if(!phydev->link&&phydev->state==PHY_RUNNING){-phydev->state=PHY_CHANGELINK;-phydev_err(phydev,"no link in PHY_RUNNING\n");+err=phy_read_status(phydev);+if(err)+break;++if(!phydev->link){+phydev->state=PHY_NOLINK;+phy_link_down(phydev,true);}break;casePHY_CHANGELINK:
@@ -1059,41 +1059,26 @@ void phy_state_machine(struct work_struct *work)casePHY_RESUMING:if(AUTONEG_ENABLE==phydev->autoneg){err=phy_aneg_done(phydev);-if(err<0)+if(err<0){break;--/* err > 0 if AN is done.-*Otherwise,it's0,andwe'restillwaitingforAN-*/-if(err>0){-err=phy_read_status(phydev);-if(err)-break;--if(phydev->link){-phydev->state=PHY_RUNNING;-phy_link_up(phydev);-}else{-phydev->state=PHY_NOLINK;-phy_link_down(phydev,false);-}-}else{+}elseif(!err){phydev->state=PHY_AN;phydev->link_timeout=PHY_AN_TIMEOUT;-}-}else{-err=phy_read_status(phydev);-if(err)break;--if(phydev->link){-phydev->state=PHY_RUNNING;-phy_link_up(phydev);-}else{-phydev->state=PHY_NOLINK;-phy_link_down(phydev,false);}}++err=phy_read_status(phydev);+if(err)+break;++if(phydev->link){+phydev->state=PHY_RUNNING;+phy_link_up(phydev);+}else{+phydev->state=PHY_NOLINK;+phy_link_down(phydev,false);+}break;}