Skip to contentSkip to conversation

net: davinci_emac: fix suspend/resume (both a regression and a common clk problem)

PATCH Superseded Bartosz Golaszewski 3 participants 9 messages Jun 19, 2018 – Jun 20, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net: davinci_emac: fix suspend/resume (both a regression and a common clk problem)

From: Bartosz Golaszewski <[email protected]>

Earlier today I sent the first patch as a solution to a regression introduced during the v4.16 merge window, but after testing David's common clock series on top of 4.18-rc1 + this patch it turned out that the problem persisted.

This is a follow-up containing the regression fix and two additional patches that make suspend/resume work with David's changes.

Bartosz Golaszewski (3):
net: ethernet: fix suspend/resume in davinci_emac
net: phy: set the of_node in the mdiodev's struct device
net: davinci_emac: match the mdio device against its compatible if
possible

 drivers/net/ethernet/ti/davinci_emac.c | 19 +++++++++++++++++--
 drivers/net/phy/phy_device.c           |  1 +
 2 files changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 net: ethernet: fix suspend/resume in davinci_emac

From: Bartosz Golaszewski <[email protected]>

This patch reverts commit 3243ff2a05ec ("net: ethernet: davinci_emac:
Deduplicate bus_find_device() by name matching") and adds a comment which should stop anyone from reintroducing the same "fix" in the future.

We can't use bus_find_device_by_name() here because the device name is not guaranteed to be 'davinci_mdio'. On some systems it can be 'davinci_mdio.0' so we need to use strncmp() against the first part of the string to correctly match it.

Fixes 3243ff2a05ec ("net: ethernet: davinci_emac: Deduplicate bus_find_device() by name matching")
---
 drivers/net/ethernet/ti/davinci_emac.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +13 -2
index 06d7c9e4dcda..a1a6445b5a7e 100644
@@ -1385,6 +1385,11 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 		return -EOPNOTSUPP;
 }
 
+static int match_first_device(struct device *dev, void *data)
+{
+	return !strncmp(dev_name(dev), "davinci_mdio", 12);
+}
+
 /**
  * emac_dev_open - EMAC device open
  * @ndev: The DaVinci EMAC network adapter
@@ -1484,8 +1489,14 @@ static int emac_dev_open(struct net_device *ndev)
 
 	/* use the first phy on the bus if pdata did not give us a phy id */
 	if (!phydev && !priv->phy_id) {
-		phy = bus_find_device_by_name(&mdio_bus_type, NULL,
-					      "davinci_mdio");
+		/* NOTE: we can't use bus_find_device_by_name() here because
+		 * the device name is not guaranteed to be 'davinci_mdio'. On
+		 * some systems it can be 'davinci_mdio.0' so we need to use
+		 * strncmp() against the first part of the string to correctly
+		 * match it.
+		 */
+		phy = bus_find_device(&mdio_bus_type, NULL, NULL,
+				      match_first_device);
 		if (phy) {
 			priv->phy_id = dev_name(phy);
 			if (!priv->phy_id || !*priv->phy_id)
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/3] net: ethernet: fix suspend/resume in davinci_emac

Quoted 23 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

This patch reverts commit 3243ff2a05ec ("net: ethernet: davinci_emac:
Deduplicate bus_find_device() by name matching") and adds a comment which should stop anyone from reintroducing the same "fix" in the future.

We can't use bus_find_device_by_name() here because the device name is not guaranteed to be 'davinci_mdio'. On some systems it can be 'davinci_mdio.0' so we need to use strncmp() against the first part of the string to correctly match it.

Fixes 3243ff2a05ec ("net: ethernet: davinci_emac: Deduplicate bus_find_device() by name matching")
---
 drivers/net/ethernet/ti/davinci_emac.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +0 -0
index 06d7c9e4dcda..a1a6445b5a7e 100644

drivers/net/ethernet/ti/davinci_emac.c static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd) · line 1390

Quoted 6 lines
drivers/net/ethernet/ti/davinci_emac.c +3 -0
@@ -1385,6 +1385,11 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 		return -EOPNOTSUPP;
 }
 
+static int match_first_device(struct device *dev, void *data)
+{
+	return !strncmp(dev_name(dev), "davinci_mdio", 12);
	const char *bus_name = "davinci_mdio";

	return !strncmp(dev_name(dev), bus_name, strlen(bus_name));

Or even better yet, if you want to make sure this really is a PHY device that you are trying to match, you could try to use sscanf() with PHY_ID_FMT.

Signature · 1 line
Florian
#3 lore raw

Re: [PATCH 1/3] net: ethernet: fix suspend/resume in davinci_emac

2018-06-19 18:55 GMT+02:00 Florian Fainelli <[email protected]>:

Quoted 35 lines · Bartosz Golaszewski
Quoted 23 lines

From: Bartosz Golaszewski <[email protected]>

This patch reverts commit 3243ff2a05ec ("net: ethernet: davinci_emac:
Deduplicate bus_find_device() by name matching") and adds a comment which should stop anyone from reintroducing the same "fix" in the future.

We can't use bus_find_device_by_name() here because the device name is not guaranteed to be 'davinci_mdio'. On some systems it can be 'davinci_mdio.0' so we need to use strncmp() against the first part of the string to correctly match it.

Fixes 3243ff2a05ec ("net: ethernet: davinci_emac: Deduplicate bus_find_device() by name matching")
---
 drivers/net/ethernet/ti/davinci_emac.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +0 -0
index 06d7c9e4dcda..a1a6445b5a7e 100644

drivers/net/ethernet/ti/davinci_emac.c static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd) · line 1390

Quoted 6 lines
drivers/net/ethernet/ti/davinci_emac.c +3 -0
@@ -1385,6 +1385,11 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
              return -EOPNOTSUPP;
 }
 
+static int match_first_device(struct device *dev, void *data)
+{
+     return !strncmp(dev_name(dev), "davinci_mdio", 12);
        const char *bus_name = "davinci_mdio";

        return !strncmp(dev_name(dev), bus_name, strlen(bus_name));
Quoted 4 lines

Or even better yet, if you want to make sure this really is a PHY device that you are trying to match, you could try to use sscanf() with PHY_ID_FMT. --
Florian

I don't think this is necessary. This simple function would get too complicated with the additional buffer for the sscanf'ed phy name etc.

Thanks,
Bart

Acked-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] net: ethernet: fix suspend/resume in davinci_emac

In reply to Bartosz Golaszewski
Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

This patch reverts commit 3243ff2a05ec ("net: ethernet: davinci_emac:
Deduplicate bus_find_device() by name matching") and adds a comment which should stop anyone from reintroducing the same "fix" in the future.

Quoted 8 lines

We can't use bus_find_device_by_name() here because the device name is not guaranteed to be 'davinci_mdio'. On some systems it can be 'davinci_mdio.0' so we need to use strncmp() against the first part of the string to correctly match it.

Fixes 3243ff2a05ec ("net: ethernet: davinci_emac: Deduplicate bus_find_device() by name matching")

This is still

given that my patch which is reverted here seems to have been incorrect. Feel free to keep the ack if you respin in response to Florian Fainelli's comments.

Thanks,

Lukas

Quoted 40 lines
---
 drivers/net/ethernet/ti/davinci_emac.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +13 -2
index 06d7c9e4dcda..a1a6445b5a7e 100644
@@ -1385,6 +1385,11 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 		return -EOPNOTSUPP;
 }
 
+static int match_first_device(struct device *dev, void *data)
+{
+	return !strncmp(dev_name(dev), "davinci_mdio", 12);
+}
+
 /**
  * emac_dev_open - EMAC device open
  * @ndev: The DaVinci EMAC network adapter
@@ -1484,8 +1489,14 @@ static int emac_dev_open(struct net_device *ndev)
 
 	/* use the first phy on the bus if pdata did not give us a phy id */
 	if (!phydev && !priv->phy_id) {
-		phy = bus_find_device_by_name(&mdio_bus_type, NULL,
-					      "davinci_mdio");
+		/* NOTE: we can't use bus_find_device_by_name() here because
+		 * the device name is not guaranteed to be 'davinci_mdio'. On
+		 * some systems it can be 'davinci_mdio.0' so we need to use
+		 * strncmp() against the first part of the string to correctly
+		 * match it.
+		 */
+		phy = bus_find_device(&mdio_bus_type, NULL, NULL,
+				      match_first_device);
 		if (phy) {
 			priv->phy_id = dev_name(phy);
 			if (!priv->phy_id || !*priv->phy_id)
Signature · 1 line
2.17.1
#5 lore raw

PATCH 2/3 net: phy: set the of_node in the mdiodev's struct device

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Copy the of_node over from mii_bus's struct device. This is needed for device-tree systems to be able to check the mdio device's compatible string.

---
 drivers/net/phy/phy_device.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phy_device.c +1 -0
index bd0f339f69fd..a92d5ee61813 100644
@@ -411,6 +411,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 	mdiodev->dev.parent = &bus->dev;
 	mdiodev->dev.bus = &mdio_bus_type;
 	mdiodev->dev.type = &mdio_bus_phy_type;
+	mdiodev->dev.of_node = bus->dev.of_node;
 	mdiodev->bus = bus;
 	mdiodev->bus_match = phy_bus_match;
 	mdiodev->addr = addr;
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH 2/3] net: phy: set the of_node in the mdiodev's struct device

Quoted 16 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Copy the of_node over from mii_bus's struct device. This is needed for device-tree systems to be able to check the mdio device's compatible string.

---
 drivers/net/phy/phy_device.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phy_device.c +0 -0
index bd0f339f69fd..a92d5ee61813 100644

drivers/net/phy/phy_device.c struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, · line 414

Quoted 4 lines
drivers/net/phy/phy_device.c +1 -0
@@ -411,6 +411,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 	mdiodev->dev.parent = &bus->dev;
 	mdiodev->dev.bus = &mdio_bus_type;
 	mdiodev->dev.type = &mdio_bus_phy_type;
+	mdiodev->dev.of_node = bus->dev.of_node;

That does not quite make sense to me, the mdio device's parent already points to &bus->dev, which would get you the correct of_node. You are breaking the parent/child relationship here. From patch 3, see my comments there, it does not look like you are matching on the right device level.

Quoted 4 lines
drivers/net/phy/phy_device.c +0 -0
 	mdiodev->bus = bus;
 	mdiodev->bus_match = phy_bus_match;
 	mdiodev->addr = addr;
Signature · 1 line
Florian
#7 lore raw

PATCH 3/3 net: davinci_emac: match the mdio device against its compatible if possible

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Device tree based systems without of_dev_auxdata will have the mdio device named differently than "davinci_mdio(.0)". In this case use the device's compatible string for matching.

---
 drivers/net/ethernet/ti/davinci_emac.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/ti/davinci_emac.c +4 -0
index a1a6445b5a7e..c28a35bb852f 100644
@@ -1387,6 +1387,10 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 
 static int match_first_device(struct device *dev, void *data)
 {
+	if (dev->of_node)
+		return of_device_is_compatible(dev->of_node,
+					       "ti,davinci_mdio");
+
 	return !strncmp(dev_name(dev), "davinci_mdio", 12);
 }
 
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH 3/3] net: davinci_emac: match the mdio device against its compatible if possible

Quoted 16 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Device tree based systems without of_dev_auxdata will have the mdio device named differently than "davinci_mdio(.0)". In this case use the device's compatible string for matching.

---
 drivers/net/ethernet/ti/davinci_emac.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/ti/davinci_emac.c +0 -0
index a1a6445b5a7e..c28a35bb852f 100644

drivers/net/ethernet/ti/davinci_emac.c static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd) · line 1392

Quoted 6 lines
drivers/net/ethernet/ti/davinci_emac.c +3 -0
@@ -1387,6 +1387,10 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 
 static int match_first_device(struct device *dev, void *data)
 {
+	if (dev->of_node)
+		return of_device_is_compatible(dev->of_node,
+					       "ti,davinci_mdio");

Why would we be matching the PHY device with the MDIO controller compatibe string? Why not check dev->parent.of_node instead which would make more sense?

Signature · 1 line
Florian