linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net v2 0/1] net: usb: smsc95xx: fix external PHY reset
@ 2022-11-15 11:44 Alexandru Tachici
  2022-11-15 11:44 ` [net v2 1/1] " Alexandru Tachici
  2022-11-17  9:50 ` [net v2 0/1] " patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandru Tachici @ 2022-11-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: andrew, linux, davem, edumazet, kuba, pabeni, netdev,
	steve.glendinning, UNGLinuxDriver, andre.edich, linux-usb

An external PHY needs settling time after power up or reset.
In the bind() function an mdio bus is registered. If at this point
the external PHY is still initialising, no valid PHY ID will be
read and on phy_find_first() the bind() function will fail.

If an external PHY is present, wait the maximum time specified
in 802.3 45.2.7.1.1.

Alexandru Tachici (1):
  net: usb: smsc95xx: fix external PHY reset

Changelog v1 -> v2:
  - fixed typo in commit message
  - added reset() callback to the mii_bus
  - moved fsleep() call to smsc95xx_mdiobus_reset()
  - moved is_internal_phy bool in struct smsc95xx_priv
  - added an explicit PHY_RST_ command to PM_CTRL in smsc95xx_mdiobus_reset()

 drivers/net/usb/smsc95xx.c | 46 ++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

-- 
2.34.1


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

* [net v2 1/1] net: usb: smsc95xx: fix external PHY reset
  2022-11-15 11:44 [net v2 0/1] net: usb: smsc95xx: fix external PHY reset Alexandru Tachici
@ 2022-11-15 11:44 ` Alexandru Tachici
  2022-11-16 13:46   ` Andrew Lunn
  2022-11-17  9:50 ` [net v2 0/1] " patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandru Tachici @ 2022-11-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: andrew, linux, davem, edumazet, kuba, pabeni, netdev,
	steve.glendinning, UNGLinuxDriver, andre.edich, linux-usb

An external PHY needs settling time after power up or reset.
In the bind() function an mdio bus is registered. If at this point
the external PHY is still initialising, no valid PHY ID will be
read and on phy_find_first() the bind() function will fail.

If an external PHY is present, wait the maximum time specified
in 802.3 45.2.7.1.1.

Fixes: 05b35e7eb9a1 ("smsc95xx: add phylib support")
Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
 drivers/net/usb/smsc95xx.c | 46 ++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index bfb58c91db04..32d2c60d334d 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -66,6 +66,7 @@ struct smsc95xx_priv {
 	spinlock_t mac_cr_lock;
 	u8 features;
 	u8 suspend_flags;
+	bool is_internal_phy;
 	struct irq_chip irqchip;
 	struct irq_domain *irqdomain;
 	struct fwnode_handle *irqfwnode;
@@ -252,6 +253,43 @@ static void smsc95xx_mdio_write(struct usbnet *dev, int phy_id, int idx,
 	mutex_unlock(&dev->phy_mutex);
 }
 
+static int smsc95xx_mdiobus_reset(struct mii_bus *bus)
+{
+	struct smsc95xx_priv *pdata;
+	struct usbnet *dev;
+	u32 val;
+	int ret;
+
+	dev = bus->priv;
+	pdata = dev->driver_priv;
+
+	if (pdata->is_internal_phy)
+		return 0;
+
+	mutex_lock(&dev->phy_mutex);
+
+	ret = smsc95xx_read_reg(dev, PM_CTRL, &val);
+	if (ret < 0)
+		goto reset_out;
+
+	val |= PM_CTL_PHY_RST_;
+
+	ret = smsc95xx_write_reg(dev, PM_CTRL, val);
+	if (ret < 0)
+		goto reset_out;
+
+	/* Driver has no knowledge at this point about the external PHY.
+	 * The 802.3 specifies that the reset process shall
+	 * be completed within 0.5 s.
+	 */
+	fsleep(500000);
+
+reset_out:
+	mutex_unlock(&dev->phy_mutex);
+
+	return 0;
+}
+
 static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
 {
 	struct usbnet *dev = bus->priv;
@@ -1052,7 +1090,6 @@ static void smsc95xx_handle_link_change(struct net_device *net)
 static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 {
 	struct smsc95xx_priv *pdata;
-	bool is_internal_phy;
 	char usb_path[64];
 	int ret, phy_irq;
 	u32 val;
@@ -1133,13 +1170,14 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 	if (ret < 0)
 		goto free_mdio;
 
-	is_internal_phy = !(val & HW_CFG_PSEL_);
-	if (is_internal_phy)
+	pdata->is_internal_phy = !(val & HW_CFG_PSEL_);
+	if (pdata->is_internal_phy)
 		pdata->mdiobus->phy_mask = ~(1u << SMSC95XX_INTERNAL_PHY_ID);
 
 	pdata->mdiobus->priv = dev;
 	pdata->mdiobus->read = smsc95xx_mdiobus_read;
 	pdata->mdiobus->write = smsc95xx_mdiobus_write;
+	pdata->mdiobus->reset = smsc95xx_mdiobus_reset;
 	pdata->mdiobus->name = "smsc95xx-mdiobus";
 	pdata->mdiobus->parent = &dev->udev->dev;
 
@@ -1160,7 +1198,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
 	}
 
 	pdata->phydev->irq = phy_irq;
-	pdata->phydev->is_internal = is_internal_phy;
+	pdata->phydev->is_internal = pdata->is_internal_phy;
 
 	/* detect device revision as different features may be available */
 	ret = smsc95xx_read_reg(dev, ID_REV, &val);
-- 
2.34.1


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

* Re: [net v2 1/1] net: usb: smsc95xx: fix external PHY reset
  2022-11-15 11:44 ` [net v2 1/1] " Alexandru Tachici
@ 2022-11-16 13:46   ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2022-11-16 13:46 UTC (permalink / raw)
  To: Alexandru Tachici
  Cc: linux-kernel, linux, davem, edumazet, kuba, pabeni, netdev,
	steve.glendinning, UNGLinuxDriver, andre.edich, linux-usb

On Tue, Nov 15, 2022 at 01:44:34PM +0200, Alexandru Tachici wrote:
> An external PHY needs settling time after power up or reset.
> In the bind() function an mdio bus is registered. If at this point
> the external PHY is still initialising, no valid PHY ID will be
> read and on phy_find_first() the bind() function will fail.
> 
> If an external PHY is present, wait the maximum time specified
> in 802.3 45.2.7.1.1.
> 
> Fixes: 05b35e7eb9a1 ("smsc95xx: add phylib support")
> Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>

Thanks for making Russell suggested change.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [net v2 0/1] net: usb: smsc95xx: fix external PHY reset
  2022-11-15 11:44 [net v2 0/1] net: usb: smsc95xx: fix external PHY reset Alexandru Tachici
  2022-11-15 11:44 ` [net v2 1/1] " Alexandru Tachici
@ 2022-11-17  9:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-17  9:50 UTC (permalink / raw)
  To: Alexandru Tachici
  Cc: linux-kernel, andrew, linux, davem, edumazet, kuba, pabeni,
	netdev, steve.glendinning, UNGLinuxDriver, andre.edich, linux-usb

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Tue, 15 Nov 2022 13:44:33 +0200 you wrote:
> An external PHY needs settling time after power up or reset.
> In the bind() function an mdio bus is registered. If at this point
> the external PHY is still initialising, no valid PHY ID will be
> read and on phy_find_first() the bind() function will fail.
> 
> If an external PHY is present, wait the maximum time specified
> in 802.3 45.2.7.1.1.
> 
> [...]

Here is the summary with links:
  - [net,v2,1/1] net: usb: smsc95xx: fix external PHY reset
    https://git.kernel.org/netdev/net/c/809ff97a677f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-11-17  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-15 11:44 [net v2 0/1] net: usb: smsc95xx: fix external PHY reset Alexandru Tachici
2022-11-15 11:44 ` [net v2 1/1] " Alexandru Tachici
2022-11-16 13:46   ` Andrew Lunn
2022-11-17  9:50 ` [net v2 0/1] " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).