phylib: Fix auto-negotiation restart avoidance

A previous patch, 51e2a3846eab18711f4eb59cd0a4c33054e2980a, made
genphy_config_aneg() not restart aneg by calling genphy_restart_aneg() if
the advertisement hadn't changed.

But, genphy_restart_aneg() doesn't just restart aneg, it may also *enable*
aneg or un-isolate the PHY from the MII (those functions are controlled by
the same register). The code to avoid calling genphy_restart_aneg() didn't
consider this.

So, modify genphy_config_aneg() to also check if the PHY needs to have aneg
enabled or be un-isolated before deciding not to restart aneg.

This caused a problem with certain Davicom PHYs, as that driver isolates
the PHY (why?) before calling genphy_config_aneg() and expects the PHY to
be un-isolated by that function.

Signed-off-by: Trent Piepho <tpiepho@freescale.com>
Reported-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Trent Piepho and committed by David S. Miller de339c2a 31c221c4

+23 -11
+23 -11
drivers/net/phy/phy_device.c
··· 564 */ 565 int genphy_config_aneg(struct phy_device *phydev) 566 { 567 - int result = 0; 568 569 - if (AUTONEG_ENABLE == phydev->autoneg) { 570 - int result = genphy_config_advert(phydev); 571 572 - if (result < 0) /* error */ 573 - return result; 574 575 - /* Only restart aneg if we are advertising something different 576 - * than we were before. */ 577 - if (result > 0) 578 - result = genphy_restart_aneg(phydev); 579 - } else 580 - result = genphy_setup_forced(phydev); 581 582 return result; 583 }
··· 564 */ 565 int genphy_config_aneg(struct phy_device *phydev) 566 { 567 + int result; 568 569 + if (AUTONEG_ENABLE != phydev->autoneg) 570 + return genphy_setup_forced(phydev); 571 572 + result = genphy_config_advert(phydev); 573 574 + if (result < 0) /* error */ 575 + return result; 576 + 577 + if (result == 0) { 578 + /* Advertisment hasn't changed, but maybe aneg was never on to 579 + * begin with? Or maybe phy was isolated? */ 580 + int ctl = phy_read(phydev, MII_BMCR); 581 + 582 + if (ctl < 0) 583 + return ctl; 584 + 585 + if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) 586 + result = 1; /* do restart aneg */ 587 + } 588 + 589 + /* Only restart aneg if we are advertising something different 590 + * than we were before. */ 591 + if (result > 0) 592 + result = genphy_restart_aneg(phydev); 593 594 return result; 595 }