Skip to contentSkip to conversation

net: phy: relax PHY and MDIO reset handling

PATCH In review Bartosz Golaszewski 3 participants 11 messages Jun 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: phy: relax PHY and MDIO reset handling

From: Bartosz Golaszewski <[email protected]>

Previously these patches were submitted as part of a larger series[1] but since the approach in it will have to be reworked I'm resending the ones that were non-controversial and have been reviewed for upstream.

Florian suggested a better solution for managing multiple resets. While I will definitely try to implement something at the driver model's bus level (together with regulator support), the 'resets' and 'reset-gpios' DT property is a stable ABI defined in mdio.yaml so improving its support is in order as we'll have to stick with it anyway. Current implementation contains an unnecessary limitation where drivers without probe() can't define resets.

Changes from the previous version:
- order forward declarations in patch 4 alphabetically
- collect review tags

[1] https://lkml.org/lkml/2020/6/22/253

Bartosz Golaszewski (6):
net: phy: arrange headers in mdio_bus.c alphabetically
net: phy: arrange headers in mdio_device.c alphabetically
net: phy: arrange headers in phy_device.c alphabetically
net: mdio: add a forward declaration for reset_control to mdio.h
net: phy: reset the PHY even if probe() is not implemented
net: phy: mdio: reset MDIO devices even if probe() is not implemented

 drivers/net/phy/mdio_bus.c    | 32 +++++++++++-----------
 drivers/net/phy/mdio_device.c | 15 +++++------
 drivers/net/phy/phy_device.c  | 51 ++++++++++++++++++-----------------
 include/linux/mdio.h          |  1 +
 4 files changed, 50 insertions(+), 49 deletions(-)
Signature · 1 line
2.26.1
#1 lore raw

PATCH 1/6 net: phy: arrange headers in mdio_bus.c alphabetically

From: Bartosz Golaszewski <[email protected]>

Keeping the headers in alphabetical order is better for readability and allows to easily see if given header is already included.

---
 drivers/net/phy/mdio_bus.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/net/phy/mdio_bus.c +16 -16
index 6ceee82b2839..296cf9771483 100644
@@ -8,32 +8,32 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/unistd.h>
-#include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mii.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
 #include <linux/of_device.h>
-#include <linux/of_mdio.h>
 #include <linux/of_gpio.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
+#include <linux/of_mdio.h>
+#include <linux/phy.h>
 #include <linux/reset.h>
 #include <linux/skbuff.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/mm.h>
-#include <linux/module.h>
-#include <linux/mii.h>
-#include <linux/ethtool.h>
-#include <linux/phy.h>
-#include <linux/io.h>
+#include <linux/string.h>
 #include <linux/uaccess.h>
+#include <linux/unistd.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/mdio.h>
Signature · 1 line
2.26.1
#2 lore raw

PATCH 2/6 net: phy: arrange headers in mdio_device.c alphabetically

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Keeping the headers in alphabetical order is better for readability and allows to easily see if given header is already included.

---
 drivers/net/phy/mdio_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/mdio_device.c +1 -1
index c1d345c3cab3..f60443e48622 100644
@@ -6,6 +6,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
@@ -20,7 +21,6 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/unistd.h>
-#include <linux/delay.h>
 
 void mdio_device_free(struct mdio_device *mdiodev)
 {
Signature · 1 line
2.26.1
#3 lore raw

PATCH 3/6 net: phy: arrange headers in phy_device.c alphabetically

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Keeping the headers in alphabetical order is better for readability and allows to easily see if given header is already included.

---
 drivers/net/phy/phy_device.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/net/phy/phy_device.c +14 -14
index 04946de74fa0..1b4df12c70ad 100644
@@ -9,28 +9,28 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/unistd.h>
-#include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
+#include <linux/bitmap.h>
 #include <linux/delay.h>
-#include <linux/netdevice.h>
+#include <linux/errno.h>
 #include <linux/etherdevice.h>
-#include <linux/skbuff.h>
+#include <linux/ethtool.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mdio.h>
+#include <linux/mii.h>
 #include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/mii.h>
-#include <linux/ethtool.h>
-#include <linux/bitmap.h>
+#include <linux/netdevice.h>
 #include <linux/phy.h>
 #include <linux/phy_led_triggers.h>
 #include <linux/sfp.h>
-#include <linux/mdio.h>
-#include <linux/io.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/uaccess.h>
+#include <linux/unistd.h>
 
 MODULE_DESCRIPTION("PHY library");
 MODULE_AUTHOR("Andy Fleming");
Signature · 1 line
2.26.1
#4 lore raw

PATCH 4/6 net: mdio: add a forward declaration for reset_control to mdio.h

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

This header refers to struct reset_control but doesn't include any reset header. The structure definition is probably somehow indirectly pulled in since no warnings are reported but for the sake of correctness add the forward declaration for struct reset_control.

---
 include/linux/mdio.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/mdio.h +1 -0
index 36d2e0673d03..898cbf00332a 100644
@@ -18,6 +18,7 @@
 
 struct gpio_desc;
 struct mii_bus;
+struct reset_control;
 
 /* Multiple levels of nesting are possible. However typically this is
  * limited to nested DSA like layer, a MUX layer, and the normal
Signature · 1 line
2.26.1
Reviewed-by on v1 4/6
#5 lore raw

Re: [PATCH 4/6] net: mdio: add a forward declaration for reset_control to mdio.h

Quoted 9 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

This header refers to struct reset_control but doesn't include any reset header. The structure definition is probably somehow indirectly pulled in since no warnings are reported but for the sake of correctness add the forward declaration for struct reset_control.

Signature · 1 line
Florian
#6 lore raw

PATCH 5/6 net: phy: reset the PHY even if probe() is not implemented

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Currently we only call phy_device_reset() if the PHY driver implements the probe() callback. This is not mandatory and many drivers (e.g. realtek) don't need probe() for most devices but still can have reset GPIOs defined. There's no reason to depend on the presence of probe() here so pull the reset code out of the if clause.

---
 drivers/net/phy/phy_device.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/net/phy/phy_device.c +12 -11
index 1b4df12c70ad..f6985db08340 100644
@@ -2690,16 +2690,13 @@ static int phy_probe(struct device *dev)
 
 	mutex_lock(&phydev->lock);
 
-	if (phydev->drv->probe) {
-		/* Deassert the reset signal */
-		phy_device_reset(phydev, 0);
+	/* Deassert the reset signal */
+	phy_device_reset(phydev, 0);
 
+	if (phydev->drv->probe) {
 		err = phydev->drv->probe(phydev);
-		if (err) {
-			/* Assert the reset signal */
-			phy_device_reset(phydev, 1);
+		if (err)
 			goto out;
-		}
 	}
 
 	/* Start out supporting everything. Eventually,
@@ -2761,6 +2758,10 @@ static int phy_probe(struct device *dev)
 	phydev->state = PHY_READY;
 
 out:
+	/* Assert the reset signal */
+	if (err)
+		phy_device_reset(phydev, 1);
+
 	mutex_unlock(&phydev->lock);
 
 	return err;
@@ -2779,12 +2780,12 @@ static int phy_remove(struct device *dev)
 	sfp_bus_del_upstream(phydev->sfp_bus);
 	phydev->sfp_bus = NULL;
 
-	if (phydev->drv && phydev->drv->remove) {
+	if (phydev->drv && phydev->drv->remove)
 		phydev->drv->remove(phydev);
 
-		/* Assert the reset signal */
-		phy_device_reset(phydev, 1);
-	}
+	/* Assert the reset signal */
+	phy_device_reset(phydev, 1);
+
 	phydev->drv = NULL;
 
 	return 0;
Signature · 1 line
2.26.1
Reviewed-by on v1 5/6
#7 lore raw

Re: [PATCH 5/6] net: phy: reset the PHY even if probe() is not implemented

Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Currently we only call phy_device_reset() if the PHY driver implements the probe() callback. This is not mandatory and many drivers (e.g. realtek) don't need probe() for most devices but still can have reset GPIOs defined. There's no reason to depend on the presence of probe() here so pull the reset code out of the if clause.

OK we can always add support for letting PHY drivers manage their own reset line(s) during probe in a later changeset.

Signature · 1 line
Florian
#8 lore raw

PATCH 6/6 net: phy: mdio: reset MDIO devices even if probe() is not implemented

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Similarily to PHY drivers - there's no reason to require probe() to be implemented in order to call mdio_device_reset(). MDIO devices can have resets defined without needing to do anything in probe().

---
 drivers/net/phy/mdio_device.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/phy/mdio_device.c +6 -7
index f60443e48622..be615504b829 100644
@@ -150,10 +150,10 @@ static int mdio_probe(struct device *dev)
 	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
 	int err = 0;
 
-	if (mdiodrv->probe) {
-		/* Deassert the reset signal */
-		mdio_device_reset(mdiodev, 0);
+	/* Deassert the reset signal */
+	mdio_device_reset(mdiodev, 0);
 
+	if (mdiodrv->probe) {
 		err = mdiodrv->probe(mdiodev);
 		if (err) {
 			/* Assert the reset signal */
@@ -170,12 +170,11 @@ static int mdio_remove(struct device *dev)
 	struct device_driver *drv = mdiodev->dev.driver;
 	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
 
-	if (mdiodrv->remove) {
+	if (mdiodrv->remove)
 		mdiodrv->remove(mdiodev);
 
-		/* Assert the reset signal */
-		mdio_device_reset(mdiodev, 1);
-	}
+	/* Assert the reset signal */
+	mdio_device_reset(mdiodev, 1);
 
 	return 0;
 }
Signature · 1 line
2.26.1
Reviewed-by on v1 6/6
#9 lore raw

Re: [PATCH 6/6] net: phy: mdio: reset MDIO devices even if probe() is not implemented

Quoted 8 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Similarily to PHY drivers - there's no reason to require probe() to be implemented in order to call mdio_device_reset(). MDIO devices can have resets defined without needing to do anything in probe().

Signature · 1 line
Florian
maintainer
#10 lore raw
In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>
Date: Fri, 26 Jun 2020 17:53:19 +0200

Quoted 14 lines

From: Bartosz Golaszewski <[email protected]>

Previously these patches were submitted as part of a larger series[1] but since the approach in it will have to be reworked I'm resending the ones that were non-controversial and have been reviewed for upstream.

Florian suggested a better solution for managing multiple resets. While I will definitely try to implement something at the driver model's bus level (together with regulator support), the 'resets' and 'reset-gpios' DT property is a stable ABI defined in mdio.yaml so improving its support is in order as we'll have to stick with it anyway. Current implementation contains an unnecessary limitation where drivers without probe() can't define resets.

Quoted 5 lines

Changes from the previous version:
- order forward declarations in patch 4 alphabetically
- collect review tags

[1] https://lkml.org/lkml/2020/6/22/253

Series applied, thank you.