Patchwork [21/27] UBUNTU: SAUCE: net/phy: abort genphy_read_status when link changes during speed and duplex reading

login
register
mail settings
Submitter Benjamin Collins
Date Oct. 6, 2011, 10:27 p.m.
Message ID <abe2183b4c33f55228adc9a401d8603163930432.1339455422.git.bcollins@ubuntu.com>
Download mbox | patch
Permalink /patch/164282/
State New
Headers show

Comments

Benjamin Collins - Oct. 6, 2011, 10:27 p.m.
If the link changes during speed and duplex reading the values may be out of sync;
abort the update if the link state changes during the read

This patch is being maintained and will eventually be merged upstream by
Freescale directly. The powerpc-e500mc flavour uses this.

Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
Signed-off-by: Ben Collins <bcollins@ubuntu.com>
---
 drivers/net/phy/phy_device.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f53bc32..163e1e7 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -808,6 +808,16 @@  int genphy_read_status(struct phy_device *phydev)
 
 		lpa &= adv;
 
+		err = phy_read(phydev, MII_BMSR);
+
+		if (err < 0)
+			return err;
+
+		/* if the link changed while reading speed and duplex
+		 * abort the speed and duplex update */
+		if (((err & BMSR_LSTATUS) == 0) != (phydev->link == 0))
+			return 0;
+
 		phydev->speed = SPEED_10;
 		phydev->duplex = DUPLEX_HALF;
 		phydev->pause = phydev->asym_pause = 0;