diff mbox series

[net-next,1/2] net: phy: Support set_loopback override

Message ID 20210818122736.4877-2-gerhard@engleder-embedded.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Add Xilinx GMII2RGMII loopback support | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: davem@davemloft.net kuba@kernel.org linux@armlinux.org.uk hkallweit1@gmail.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Gerhard Engleder Aug. 18, 2021, 12:27 p.m. UTC
phy_read_status and various other PHY functions support PHY specific
overriding of driver functions by using a PHY specific pointer to the
PHY driver. Add support of PHY specific override to phy_loopback too.

Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
 drivers/net/phy/phy_device.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Andrew Lunn Aug. 18, 2021, 3:03 p.m. UTC | #1
On Wed, Aug 18, 2021 at 02:27:35PM +0200, Gerhard Engleder wrote:
> phy_read_status and various other PHY functions support PHY specific
> overriding of driver functions by using a PHY specific pointer to the
> PHY driver. Add support of PHY specific override to phy_loopback too.
> 
> Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
> ---
>  drivers/net/phy/phy_device.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 107aa6d7bc6b..ba5ad86ec826 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1821,11 +1821,10 @@ EXPORT_SYMBOL(phy_resume);
>  
>  int phy_loopback(struct phy_device *phydev, bool enable)
>  {
> -	struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
>  	int ret = 0;
>  
> -	if (!phydrv)
> -		return -ENODEV;
> +	if (!phydev->drv)
> +		return -EIO;

Humm, we need to take a closer look at what uses to_phy_driver() and
what uses phydev->drv. Do they need to be different? Can we make it
uniform?

	Andrew
Gerhard Engleder Aug. 18, 2021, 8:11 p.m. UTC | #2
On Wed, Aug 18, 2021 at 5:03 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Wed, Aug 18, 2021 at 02:27:35PM +0200, Gerhard Engleder wrote:
> > phy_read_status and various other PHY functions support PHY specific
> > overriding of driver functions by using a PHY specific pointer to the
> > PHY driver. Add support of PHY specific override to phy_loopback too.
> >
> > Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
> > ---
> >  drivers/net/phy/phy_device.c | 9 ++++-----
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 107aa6d7bc6b..ba5ad86ec826 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -1821,11 +1821,10 @@ EXPORT_SYMBOL(phy_resume);
> >
> >  int phy_loopback(struct phy_device *phydev, bool enable)
> >  {
> > -     struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
> >       int ret = 0;
> >
> > -     if (!phydrv)
> > -             return -ENODEV;
> > +     if (!phydev->drv)
> > +             return -EIO;
>
> Humm, we need to take a closer look at what uses to_phy_driver() and
> what uses phydev->drv. Do they need to be different? Can we make it
> uniform?
>
>         Andrew

I saw only 4 references for to_phy_driver():
- phy_loopback() of course
- phy_probe() which uses it to initialize phydev->drv 3 lines later
- mdio_bus_phy_may_suspend() which checks only for valid suspend function
  pointer, but later phy_suspend() uses phydev->drv, so this is at
least inconsistent
- phy_bus_match() which casts from struct device_driver to struct phy_driver

phydev->drv is used much more often and seems to be the right way. I suggest to
also fix mdio_bus_phy_may_suspend(). phy_probe() and phy_bus_match() are
valid uses, because phydev->drv is not available for them.

Do you agree?

Gerhard
Andrew Lunn Aug. 18, 2021, 9:20 p.m. UTC | #3
> I saw only 4 references for to_phy_driver():
> - phy_loopback() of course
> - phy_probe() which uses it to initialize phydev->drv 3 lines later

This is correct. The driver core will set dev.driver to what it thinks
is the correct driver to use, before calling probe.

> - mdio_bus_phy_may_suspend() which checks only for valid suspend function
>   pointer, but later phy_suspend() uses phydev->drv, so this is at
>   least inconsistent

I guess the real question here is, can a device be suspended before it
is probed? It would seem rather odd. So i expect phydev->drv is safe
to use.

> - phy_bus_match() which casts from struct device_driver to struct phy_driver

This is used by the driver core when trying to find a matching
driver. So it is used before phy_probe(). So this is correct.

> 
> phydev->drv is used much more often and seems to be the right way. I suggest to
> also fix mdio_bus_phy_may_suspend(). phy_probe() and phy_bus_match() are
> valid uses, because phydev->drv is not available for them.
> 
> Do you agree?

Agreed. Thanks for spending the time to look at this. I was expecting
there to be more problems than just loopback.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 107aa6d7bc6b..ba5ad86ec826 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1821,11 +1821,10 @@  EXPORT_SYMBOL(phy_resume);
 
 int phy_loopback(struct phy_device *phydev, bool enable)
 {
-	struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
 	int ret = 0;
 
-	if (!phydrv)
-		return -ENODEV;
+	if (!phydev->drv)
+		return -EIO;
 
 	mutex_lock(&phydev->lock);
 
@@ -1839,8 +1838,8 @@  int phy_loopback(struct phy_device *phydev, bool enable)
 		goto out;
 	}
 
-	if (phydrv->set_loopback)
-		ret = phydrv->set_loopback(phydev, enable);
+	if (phydev->drv->set_loopback)
+		ret = phydev->drv->set_loopback(phydev, enable);
 	else
 		ret = genphy_loopback(phydev, enable);