mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* mii patches
@ 2013-12-11 11:41 Sascha Hauer
  2013-12-11 11:41 ` [PATCH 1/9] net: phy: cleanup attached device handling Sascha Hauer
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

This makes mii phys found on mii buses available independently of
networks devices. Also it makes all phy devices visible to the
user, not only the one attached to an ethernet device. This makes
the miitool command (or simpler: md -w -s /dev/phyx) more useful

The current mii code allows to only register a phy device when
there's an ethernet device around. This dependency is removed so
that it's possible to register phys without ethernet devices.

With this series the miitool gets a -s option to scan all registered
mii buses for devices which can be examined afterwards. This is
implemented with the device 'detect' mechanism, so a 'detect -a'
or 'detect miibus0' is also possible to detect phys.

Sascha

----------------------------------------------------------------
Sascha Hauer (9):
      net: phy: cleanup attached device handling
      net: phy: bail out early in phy_device_connect
      net: phy: move duplicated code out of if/else
      net: phy: check if a phy already has an ethernet device
      net: phy: track registered state of a phy device
      net: phy: move phy_init_hw to phy_device_connect
      net: phy: Track mii buses on a list
      net: phy: implement detect callback for miibus devices
      miitool: Add option to scan mii buses

 commands/miitool.c         |  12 ++++-
 drivers/net/phy/mdio_bus.c |  49 ++++++++++++++++-----
 drivers/net/phy/phy.c      | 106 ++++++++++++++++++++++++++-------------------
 include/linux/phy.h        |  12 +++++
 4 files changed, 120 insertions(+), 59 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/9] net: phy: cleanup attached device handling
  2013-12-11 11:41 mii patches Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 2/9] net: phy: bail out early in phy_device_connect Sascha Hauer
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

phy_register_device() currently requires an attached ethernet device.
This is not needed, a phy device can equally well be registered as
a standalone device without an ethernet device. Remove the need
for an attached ethernet device in phy_register_device. Also, make
the edev <-> phy connection on a registered device which simplifies
the code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c |  4 ----
 drivers/net/phy/phy.c      | 14 +++-----------
 2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 87072be..b0fbf2d 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -153,8 +153,6 @@ static int mdio_bus_probe(struct device_d *_dev)
 
 	int ret;
 
-	dev->attached_dev->phydev = dev;
-
 	if (drv->probe) {
 		ret = drv->probe(dev);
 		if (ret)
@@ -204,8 +202,6 @@ static int mdio_bus_probe(struct device_d *_dev)
 	return 0;
 
 err:
-	dev->attached_dev->phydev = NULL;
-	dev->attached_dev = NULL;
 	return ret;
 }
 
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 2a33054..d8966cd 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -228,7 +228,7 @@ static int phy_register_device(struct phy_device* dev)
 {
 	int ret;
 
-	dev->dev.parent = &dev->attached_dev->dev;
+	dev->dev.parent = &dev->bus->dev;
 
 	ret = register_device(&dev->dev);
 	if (ret)
@@ -259,7 +259,6 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 				goto fail;
 			}
 
-			dev->attached_dev = edev;
 			dev->interface = interface;
 			dev->dev_flags = flags;
 
@@ -276,7 +275,6 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 				if (IS_ERR(dev) || dev->attached_dev)
 					continue;
 
-				dev->attached_dev = edev;
 				dev->interface = interface;
 				dev->dev_flags = flags;
 
@@ -287,14 +285,10 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 				break;
 			}
 		}
-
-		if (!edev->phydev) {
-			ret = -EIO;
-			goto fail;
-		}
 	}
 
-	dev = edev->phydev;
+	edev->phydev = dev;
+	dev->attached_dev = edev;
 	drv = to_phy_driver(dev->dev.driver);
 
 	drv->config_aneg(dev);
@@ -304,8 +298,6 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 	return 0;
 
 fail:
-	if (!IS_ERR(dev))
-		dev->attached_dev = NULL;
 	puts("Unable to find a PHY (unknown ID?)\n");
 	return ret;
 }
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/9] net: phy: bail out early in phy_device_connect
  2013-12-11 11:41 mii patches Sascha Hauer
  2013-12-11 11:41 ` [PATCH 1/9] net: phy: cleanup attached device handling Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 3/9] net: phy: move duplicated code out of if/else Sascha Hauer
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

If an ethernet device already has a phy in phy_device_connect all we
have to do is to start autonegotiation. Do this early and bail out
so that for the rest of the code it's clear that we have to search for
a phy device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/phy.c | 66 +++++++++++++++++++++++++++++----------------------
 include/linux/phy.h   |  1 -
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d8966cd..a83b35c 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -224,6 +224,14 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr)
 	return dev;
 }
 
+static void phy_config_aneg(struct phy_device *phydev)
+{
+	struct phy_driver *drv;
+
+	drv = to_phy_driver(phydev->dev.driver);
+	drv->config_aneg(phydev);
+}
+
 static int phy_register_device(struct phy_device* dev)
 {
 	int ret;
@@ -246,18 +254,37 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 		       void (*adjust_link) (struct eth_device *edev),
 		       u32 flags, phy_interface_t interface)
 {
-	struct phy_driver* drv;
 	struct phy_device* dev = NULL;
 	unsigned int i;
 	int ret = -EINVAL;
 
-	if (!edev->phydev) {
-		if (addr >= 0) {
-			dev = mdiobus_scan(bus, addr);
-			if (IS_ERR(dev)) {
-				ret = -EIO;
-				goto fail;
-			}
+	if (edev->phydev) {
+		phy_config_aneg(edev->phydev);
+		return 0;
+	}
+
+	if (addr >= 0) {
+		dev = mdiobus_scan(bus, addr);
+		if (IS_ERR(dev)) {
+			ret = -EIO;
+			goto fail;
+		}
+
+		dev->interface = interface;
+		dev->dev_flags = flags;
+
+		ret = phy_register_device(dev);
+		if (ret)
+			goto fail;
+	} else {
+		for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+			/* skip masked out PHY addresses */
+			if (bus->phy_mask & (1 << i))
+				continue;
+
+			dev = mdiobus_scan(bus, i);
+			if (IS_ERR(dev) || dev->attached_dev)
+				continue;
 
 			dev->interface = interface;
 			dev->dev_flags = flags;
@@ -265,33 +292,14 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 			ret = phy_register_device(dev);
 			if (ret)
 				goto fail;
-		} else {
-			for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
-				/* skip masked out PHY addresses */
-				if (bus->phy_mask & (1 << i))
-					continue;
 
-				dev = mdiobus_scan(bus, i);
-				if (IS_ERR(dev) || dev->attached_dev)
-					continue;
-
-				dev->interface = interface;
-				dev->dev_flags = flags;
-
-				ret = phy_register_device(dev);
-				if (ret)
-					goto fail;
-
-				break;
-			}
+			break;
 		}
 	}
 
 	edev->phydev = dev;
 	dev->attached_dev = edev;
-	drv = to_phy_driver(dev->dev.driver);
-
-	drv->config_aneg(dev);
+	phy_config_aneg(edev->phydev);
 
 	dev->adjust_link = adjust_link;
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 94f631b..a1c629e 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -161,7 +161,6 @@ struct phy_device {
 	int autoneg;
 	int force;
 
-
 	/* private data pointer */
 	/* For use by PHYs to maintain extra state */
 	void *priv;
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/9] net: phy: move duplicated code out of if/else
  2013-12-11 11:41 mii patches Sascha Hauer
  2013-12-11 11:41 ` [PATCH 1/9] net: phy: cleanup attached device handling Sascha Hauer
  2013-12-11 11:41 ` [PATCH 2/9] net: phy: bail out early in phy_device_connect Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 4/9] net: phy: check if a phy already has an ethernet device Sascha Hauer
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/phy.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index a83b35c..fb4cb11 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -269,13 +269,6 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 			ret = -EIO;
 			goto fail;
 		}
-
-		dev->interface = interface;
-		dev->dev_flags = flags;
-
-		ret = phy_register_device(dev);
-		if (ret)
-			goto fail;
 	} else {
 		for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
 			/* skip masked out PHY addresses */
@@ -283,20 +276,18 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 				continue;
 
 			dev = mdiobus_scan(bus, i);
-			if (IS_ERR(dev) || dev->attached_dev)
-				continue;
-
-			dev->interface = interface;
-			dev->dev_flags = flags;
-
-			ret = phy_register_device(dev);
-			if (ret)
-				goto fail;
-
-			break;
+			if (!IS_ERR(dev) && !dev->attached_dev)
+                                break;
 		}
 	}
 
+	dev->interface = interface;
+	dev->dev_flags = flags;
+
+	ret = phy_register_device(dev);
+	if (ret)
+		goto fail;
+
 	edev->phydev = dev;
 	dev->attached_dev = edev;
 	phy_config_aneg(edev->phydev);
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/9] net: phy: check if a phy already has an ethernet device
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 3/9] net: phy: move duplicated code out of if/else Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 5/9] net: phy: track registered state of a phy device Sascha Hauer
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

If during a phy_device_connect a phy already has an ehternet device
this can only mean it's already attached to another device. return -EBUSY
in this case.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/phy.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fb4cb11..37f6647 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -281,6 +281,9 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 		}
 	}
 
+	if (dev->attached_dev)
+		return -EBUSY;
+
 	dev->interface = interface;
 	dev->dev_flags = flags;
 
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/9] net: phy: track registered state of a phy device
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 4/9] net: phy: check if a phy already has an ethernet device Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 6/9] net: phy: move phy_init_hw to phy_device_connect Sascha Hauer
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

With this phy_device_connect only registers a phy device if it wasn't
registered already. This allows us to register phy devices outside
of ethernet drivers. phy_device_connect will now pick up an already
registered phy given that it's not attached to another ethernet device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/phy.c | 21 +++++++++++++++++----
 include/linux/phy.h   |  2 ++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 37f6647..74ef3d9 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -236,17 +236,28 @@ static int phy_register_device(struct phy_device* dev)
 {
 	int ret;
 
+	if (dev->registered)
+		return -EBUSY;
+
 	dev->dev.parent = &dev->bus->dev;
 
 	ret = register_device(&dev->dev);
 	if (ret)
 		return ret;
 
+	dev->registered = 1;
+
 	if (dev->dev.driver)
 		return 0;
 
 	dev->dev.driver = &genphy_driver.drv;
-	return device_probe(&dev->dev);
+	ret = device_probe(&dev->dev);
+	if (ret) {
+		unregister_device(&dev->dev);
+		dev->registered = 0;
+	}
+
+	return ret;
 }
 
 /* Automatically gets and returns the PHY device */
@@ -287,9 +298,11 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 	dev->interface = interface;
 	dev->dev_flags = flags;
 
-	ret = phy_register_device(dev);
-	if (ret)
-		goto fail;
+	if (!dev->registered) {
+		ret = phy_register_device(dev);
+		if (ret)
+			goto fail;
+	}
 
 	edev->phydev = dev;
 	dev->attached_dev = edev;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index a1c629e..19e4d20 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -161,6 +161,8 @@ struct phy_device {
 	int autoneg;
 	int force;
 
+	int registered;
+
 	/* private data pointer */
 	/* For use by PHYs to maintain extra state */
 	void *priv;
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/9] net: phy: move phy_init_hw to phy_device_connect
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 5/9] net: phy: track registered state of a phy device Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 7/9] net: phy: Track mii buses on a list Sascha Hauer
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

This is needed when a phy gets registered outsize of phy_device_connect
but has to be attached to an ethernet device later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 8 --------
 drivers/net/phy/phy.c      | 9 +++++++++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index b0fbf2d..84c05ad 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -181,14 +181,6 @@ static int mdio_bus_probe(struct device_d *_dev)
 	dev->supported = drv->features;
 	dev->advertising = drv->features;
 
-	ret = phy_init_hw(dev);
-	if (ret)
-		goto err;
-
-	/* Sanitize settings based on PHY capabilities */
-	if ((dev->supported & SUPPORTED_Autoneg) == 0)
-		dev->autoneg = AUTONEG_DISABLE;
-
 	dev_add_param_int_ro(&dev->dev, "phy_addr", dev->addr, "%d");
 	dev_add_param_int_ro(&dev->dev, "phy_id", dev->phy_id, "0x%08x");
 
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 74ef3d9..b05a313 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -306,6 +306,15 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 
 	edev->phydev = dev;
 	dev->attached_dev = edev;
+
+	ret = phy_init_hw(dev);
+	if (ret)
+		goto fail;
+
+	/* Sanitize settings based on PHY capabilities */
+	if ((dev->supported & SUPPORTED_Autoneg) == 0)
+		dev->autoneg = AUTONEG_DISABLE;
+
 	phy_config_aneg(edev->phydev);
 
 	dev->adjust_link = adjust_link;
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 7/9] net: phy: Track mii buses on a list
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 6/9] net: phy: move phy_init_hw to phy_device_connect Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 8/9] net: phy: implement detect callback for miibus devices Sascha Hauer
  2013-12-11 11:41 ` [PATCH 9/9] miitool: Add option to scan mii buses Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

To be able to iterate over registered mii buses

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 6 ++++++
 include/linux/phy.h        | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 84c05ad..56cb9b2 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -25,6 +25,8 @@
 #include <linux/phy.h>
 #include <linux/err.h>
 
+LIST_HEAD(mii_bus_list);
+
 /**
  * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
  * @bus: target mii_bus
@@ -57,6 +59,8 @@ int mdiobus_register(struct mii_bus *bus)
 	if (bus->reset)
 		bus->reset(bus);
 
+	list_add_tail(&bus->list, &mii_bus_list);
+
 	pr_info("%s: probed\n", dev_name(&bus->dev));
 	return 0;
 }
@@ -71,6 +75,8 @@ void mdiobus_unregister(struct mii_bus *bus)
 			unregister_device(&bus->phy_map[i]->dev);
 		bus->phy_map[i] = NULL;
 	}
+
+	list_del(&bus->list);
 }
 EXPORT_SYMBOL(mdiobus_unregister);
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 19e4d20..5f3b33f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -85,6 +85,8 @@ struct mii_bus {
 
 	/* PHY addresses to be ignored when probing */
 	u32 phy_mask;
+
+	struct list_head list;
 };
 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
 
@@ -92,6 +94,11 @@ int mdiobus_register(struct mii_bus *bus);
 void mdiobus_unregister(struct mii_bus *bus);
 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
 
+extern struct list_head mii_bus_list;
+
+#define for_each_mii_bus(mii) \
+	list_for_each_entry(mii, &mii_bus_list, list)
+
 /**
  * mdiobus_read - Convenience function for reading a given MII mgmt register
  * @bus: the mii_bus struct
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 8/9] net: phy: implement detect callback for miibus devices
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 7/9] net: phy: Track mii buses on a list Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  2013-12-11 11:41 ` [PATCH 9/9] miitool: Add option to scan mii buses Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 31 +++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c      |  2 +-
 include/linux/phy.h        |  4 ++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 56cb9b2..b29a980 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -27,6 +27,36 @@
 
 LIST_HEAD(mii_bus_list);
 
+static int mdiobus_detect(struct device_d *dev)
+{
+	struct mii_bus *mii = to_mii_bus(dev);
+	int i, ret;
+
+	for (i = 0; i < PHY_MAX_ADDR; i++) {
+		struct phy_device *phydev;
+
+		phydev = mdiobus_scan(mii, i);
+		if (IS_ERR(phydev))
+			continue;
+		if (phydev->registered)
+			continue;
+		ret = phy_register_device(phydev);
+		if (ret)
+			dev_err(dev, "failed to register phy: %s\n", strerror(-ret));
+		dev_info(dev, "registered phy as /dev/%s\n", phydev->cdev.name);
+	}
+
+	return 0;
+}
+
+void mdiobus_detect_all(void)
+{
+	struct mii_bus *mii;
+
+	for_each_mii_bus(mii)
+		mdiobus_detect(&mii->dev);
+}
+
 /**
  * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
  * @bus: target mii_bus
@@ -49,6 +79,7 @@ int mdiobus_register(struct mii_bus *bus)
 	bus->dev.id = DEVICE_ID_DYNAMIC;
 	strcpy(bus->dev.name, "miibus");
 	bus->dev.parent = bus->parent;
+	bus->dev.detect = mdiobus_detect;
 
 	err = register_device(&bus->dev);
 	if (err) {
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index b05a313..681fb51 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -232,7 +232,7 @@ static void phy_config_aneg(struct phy_device *phydev)
 	drv->config_aneg(phydev);
 }
 
-static int phy_register_device(struct phy_device* dev)
+int phy_register_device(struct phy_device* dev)
 {
 	int ret;
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 5f3b33f..6c9d090 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -94,6 +94,8 @@ int mdiobus_register(struct mii_bus *bus);
 void mdiobus_unregister(struct mii_bus *bus);
 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
 
+void mdiobus_detect_all(void);
+
 extern struct list_head mii_bus_list;
 
 #define for_each_mii_bus(mii) \
@@ -251,6 +253,8 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr);
 int phy_init(void);
 int phy_init_hw(struct phy_device *phydev);
 
+int phy_register_device(struct phy_device* dev);
+
 /**
  * phy_read - Convenience function for reading a given PHY register
  * @phydev: the phy_device struct
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 9/9] miitool: Add option to scan mii buses
  2013-12-11 11:41 mii patches Sascha Hauer
                   ` (7 preceding siblings ...)
  2013-12-11 11:41 ` [PATCH 8/9] net: phy: implement detect callback for miibus devices Sascha Hauer
@ 2013-12-11 11:41 ` Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-12-11 11:41 UTC (permalink / raw)
  To: barebox

With the -s option all mii buses can be scanned for devices so
that they are available without doing network operations. Also,
now *all* phy devices on a mii bus can be examined, not only
the one attached to an ethernet device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/miitool.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/commands/miitool.c b/commands/miitool.c
index 3a9ac45..a00514d 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -37,6 +37,7 @@
 #include <linux/stat.h>
 #include <xfuncs.h>
 #include <linux/mii.h>
+#include <linux/phy.h>
 
 static u16 mdio_read(int fd, int offset)
 {
@@ -218,13 +219,17 @@ static int do_miitool(int argc, char *argv[])
 	int argc_min;
 	int fd;
 	int verbose;
+	int scan = 0;
 
 	verbose = 0;
-	while ((opt = getopt(argc, argv, "v")) > 0) {
+	while ((opt = getopt(argc, argv, "vs")) > 0) {
 		switch (opt) {
 		case 'v':
 			verbose++;
 			break;
+		case 's':
+			scan = 1;
+			break;
 		default:
 			return COMMAND_ERROR_USAGE;
 		}
@@ -232,8 +237,11 @@ static int do_miitool(int argc, char *argv[])
 
 	argc_min = optind + 1;
 
+	if (scan)
+		mdiobus_detect_all();
+
 	if (argc < argc_min)
-		return COMMAND_ERROR_USAGE;
+		return scan ? 0 : COMMAND_ERROR_USAGE;
 
 	filename = argv[optind];
 
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-12-11 11:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 11:41 mii patches Sascha Hauer
2013-12-11 11:41 ` [PATCH 1/9] net: phy: cleanup attached device handling Sascha Hauer
2013-12-11 11:41 ` [PATCH 2/9] net: phy: bail out early in phy_device_connect Sascha Hauer
2013-12-11 11:41 ` [PATCH 3/9] net: phy: move duplicated code out of if/else Sascha Hauer
2013-12-11 11:41 ` [PATCH 4/9] net: phy: check if a phy already has an ethernet device Sascha Hauer
2013-12-11 11:41 ` [PATCH 5/9] net: phy: track registered state of a phy device Sascha Hauer
2013-12-11 11:41 ` [PATCH 6/9] net: phy: move phy_init_hw to phy_device_connect Sascha Hauer
2013-12-11 11:41 ` [PATCH 7/9] net: phy: Track mii buses on a list Sascha Hauer
2013-12-11 11:41 ` [PATCH 8/9] net: phy: implement detect callback for miibus devices Sascha Hauer
2013-12-11 11:41 ` [PATCH 9/9] miitool: Add option to scan mii buses Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox