Skip to content

Commit

Permalink
net: phy: Encapsulate actions performed during link state changes int…
Browse files Browse the repository at this point in the history
…o function phy_adjust_link

During phy state machine state transitions some set of actions should
occur whenever the link state changes. These actions should be
encapsulated into a single function

This patch adds the phy_adjust_link function, which is called whenever
phydev->adjust_link would have been called before. Actions that should
occur whenever the phy link is adjusted can now be added to the
phy_adjust_link function.

Signed-off-by: Zach Brown <zach.brown@ni.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Zach Brown authored and David S. Miller committed Oct 18, 2016
1 parent 0e0f27d commit 61a1796
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions drivers/net/phy/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ void phy_start(struct phy_device *phydev)
}
EXPORT_SYMBOL(phy_start);

static void phy_adjust_link(struct phy_device *phydev)
{
phydev->adjust_link(phydev->attached_dev);
}

/**
* phy_state_machine - Handle the state machine
* @work: work_struct that describes the work to be done
Expand Down Expand Up @@ -950,7 +955,7 @@ void phy_state_machine(struct work_struct *work)
if (!phydev->link) {
phydev->state = PHY_NOLINK;
netif_carrier_off(phydev->attached_dev);
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
break;
}

Expand All @@ -963,7 +968,7 @@ void phy_state_machine(struct work_struct *work)
if (err > 0) {
phydev->state = PHY_RUNNING;
netif_carrier_on(phydev->attached_dev);
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);

} else if (0 == phydev->link_timeout--)
needs_aneg = true;
Expand All @@ -990,7 +995,7 @@ void phy_state_machine(struct work_struct *work)
}
phydev->state = PHY_RUNNING;
netif_carrier_on(phydev->attached_dev);
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
}
break;
case PHY_FORCING:
Expand All @@ -1006,7 +1011,7 @@ void phy_state_machine(struct work_struct *work)
needs_aneg = true;
}

phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
break;
case PHY_RUNNING:
/* Only register a CHANGE if we are polling and link changed
Expand Down Expand Up @@ -1035,7 +1040,7 @@ void phy_state_machine(struct work_struct *work)
netif_carrier_off(phydev->attached_dev);
}

phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);

if (phy_interrupt_is_valid(phydev))
err = phy_config_interrupt(phydev,
Expand All @@ -1045,7 +1050,7 @@ void phy_state_machine(struct work_struct *work)
if (phydev->link) {
phydev->link = 0;
netif_carrier_off(phydev->attached_dev);
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
do_suspend = true;
}
break;
Expand All @@ -1069,7 +1074,7 @@ void phy_state_machine(struct work_struct *work)
} else {
phydev->state = PHY_NOLINK;
}
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
} else {
phydev->state = PHY_AN;
phydev->link_timeout = PHY_AN_TIMEOUT;
Expand All @@ -1085,7 +1090,7 @@ void phy_state_machine(struct work_struct *work)
} else {
phydev->state = PHY_NOLINK;
}
phydev->adjust_link(phydev->attached_dev);
phy_adjust_link(phydev);
}
break;
}
Expand Down

0 comments on commit 61a1796

Please sign in to comment.