Commit 5c5f626b authored by Heiner Kallweit's avatar Heiner Kallweit Committed by David S. Miller

net: phy: improve handling link_change_notify callback

Currently the Phy driver's link_change_notify callback is called
whenever the state machine is run (every second if polling), no matter
whether the state changed or not. This isn't needed and may confuse
users considering the name of the callback. Actually it contradicts
its kernel-doc description. Therefore let's change the behavior and
call this callback only in case of an actual state change.

This requires changes to the at803x and rockchip drivers.
at803x can be simplified so that it reacts on a state change to
PHY_NOLINK only.
The rockchip driver can also be much simplified. We simply re-init
the AFE/DSP registers whenever we change to PHY_RUNNING and speed
is 100Mbps. This causes very small overhead because we do this even
if the speed was 100Mbps already. But this is negligible and
I think justified by the much simpler code.

Changes are compile-tested only.

A little bit problematic seems to be to find somebody with the
hardware to test the changes to the two PHY drivers. See also [0].
David may be able to test the Rockchip driver.

[0] https://marc.info/?t=153782508800006&r=1&w=2Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0b8515ed
...@@ -324,8 +324,6 @@ static int at803x_config_intr(struct phy_device *phydev) ...@@ -324,8 +324,6 @@ static int at803x_config_intr(struct phy_device *phydev)
static void at803x_link_change_notify(struct phy_device *phydev) static void at803x_link_change_notify(struct phy_device *phydev)
{ {
struct at803x_priv *priv = phydev->priv;
/* /*
* Conduct a hardware reset for AT8030 every time a link loss is * Conduct a hardware reset for AT8030 every time a link loss is
* signalled. This is necessary to circumvent a hardware bug that * signalled. This is necessary to circumvent a hardware bug that
...@@ -333,25 +331,19 @@ static void at803x_link_change_notify(struct phy_device *phydev) ...@@ -333,25 +331,19 @@ static void at803x_link_change_notify(struct phy_device *phydev)
* in the FIFO. In such cases, the FIFO enters an error mode it * in the FIFO. In such cases, the FIFO enters an error mode it
* cannot recover from by software. * cannot recover from by software.
*/ */
if (phydev->state == PHY_NOLINK) { if (phydev->state == PHY_NOLINK && phydev->mdio.reset) {
if (phydev->mdio.reset && !priv->phy_reset) { struct at803x_context context;
struct at803x_context context;
at803x_context_save(phydev, &context); at803x_context_save(phydev, &context);
phy_device_reset(phydev, 1); phy_device_reset(phydev, 1);
msleep(1); msleep(1);
phy_device_reset(phydev, 0); phy_device_reset(phydev, 0);
msleep(1); msleep(1);
at803x_context_restore(phydev, &context); at803x_context_restore(phydev, &context);
phydev_dbg(phydev, "%s(): phy was reset\n", phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
__func__);
priv->phy_reset = true;
}
} else {
priv->phy_reset = false;
} }
} }
......
...@@ -891,9 +891,6 @@ void phy_state_machine(struct work_struct *work) ...@@ -891,9 +891,6 @@ void phy_state_machine(struct work_struct *work)
old_state = phydev->state; old_state = phydev->state;
if (phydev->drv && phydev->drv->link_change_notify)
phydev->drv->link_change_notify(phydev);
switch (phydev->state) { switch (phydev->state) {
case PHY_DOWN: case PHY_DOWN:
case PHY_READY: case PHY_READY:
...@@ -940,10 +937,13 @@ void phy_state_machine(struct work_struct *work) ...@@ -940,10 +937,13 @@ void phy_state_machine(struct work_struct *work)
if (err < 0) if (err < 0)
phy_error(phydev); phy_error(phydev);
if (old_state != phydev->state) if (old_state != phydev->state) {
phydev_dbg(phydev, "PHY state change %s -> %s\n", phydev_dbg(phydev, "PHY state change %s -> %s\n",
phy_state_to_str(old_state), phy_state_to_str(old_state),
phy_state_to_str(phydev->state)); phy_state_to_str(phydev->state));
if (phydev->drv && phydev->drv->link_change_notify)
phydev->drv->link_change_notify(phydev);
}
/* Only re-schedule a PHY state machine change if we are polling the /* Only re-schedule a PHY state machine change if we are polling the
* PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving * PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving
......
...@@ -104,41 +104,14 @@ static int rockchip_integrated_phy_config_init(struct phy_device *phydev) ...@@ -104,41 +104,14 @@ static int rockchip_integrated_phy_config_init(struct phy_device *phydev)
static void rockchip_link_change_notify(struct phy_device *phydev) static void rockchip_link_change_notify(struct phy_device *phydev)
{ {
int speed = SPEED_10;
if (phydev->autoneg == AUTONEG_ENABLE) {
int reg = phy_read(phydev, MII_SPECIAL_CONTROL_STATUS);
if (reg < 0) {
phydev_err(phydev, "phy_read err: %d.\n", reg);
return;
}
if (reg & MII_SPEED_100)
speed = SPEED_100;
else if (reg & MII_SPEED_10)
speed = SPEED_10;
} else {
int bmcr = phy_read(phydev, MII_BMCR);
if (bmcr < 0) {
phydev_err(phydev, "phy_read err: %d.\n", bmcr);
return;
}
if (bmcr & BMCR_SPEED100)
speed = SPEED_100;
else
speed = SPEED_10;
}
/* /*
* If mode switch happens from 10BT to 100BT, all DSP/AFE * If mode switch happens from 10BT to 100BT, all DSP/AFE
* registers are set to default values. So any AFE/DSP * registers are set to default values. So any AFE/DSP
* registers have to be re-initialized in this case. * registers have to be re-initialized in this case.
*/ */
if ((phydev->speed == SPEED_10) && (speed == SPEED_100)) { if (phydev->state == PHY_RUNNING && phydev->speed == SPEED_100) {
int ret = rockchip_integrated_phy_analog_init(phydev); int ret = rockchip_integrated_phy_analog_init(phydev);
if (ret) if (ret)
phydev_err(phydev, "rockchip_integrated_phy_analog_init err: %d.\n", phydev_err(phydev, "rockchip_integrated_phy_analog_init err: %d.\n",
ret); ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment