* [PATCH net-next v2 1/3] net: phy: Support set_loopback override
2021-08-19 13:11 [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support Gerhard Engleder
@ 2021-08-19 13:11 ` Gerhard Engleder
2021-08-19 13:11 ` [PATCH net-next v2 2/3] net: phy: Uniform PHY driver access Gerhard Engleder
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Gerhard Engleder @ 2021-08-19 13:11 UTC (permalink / raw)
To: andrew; +Cc: netdev, Gerhard Engleder
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;
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);
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v2 2/3] net: phy: Uniform PHY driver access
2021-08-19 13:11 [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support Gerhard Engleder
2021-08-19 13:11 ` [PATCH net-next v2 1/3] net: phy: Support set_loopback override Gerhard Engleder
@ 2021-08-19 13:11 ` Gerhard Engleder
2021-08-19 13:11 ` [PATCH net-next v2 3/3] net: phy: gmii2rgmii: Support PHY loopback Gerhard Engleder
2021-08-20 13:40 ` [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Gerhard Engleder @ 2021-08-19 13:11 UTC (permalink / raw)
To: andrew; +Cc: netdev, Gerhard Engleder
struct phy_device contains a pointer to the PHY driver and nearly
everywhere this pointer is used to access the PHY driver. Only
mdio_bus_phy_may_suspend() is still using to_phy_driver() instead of the
PHY driver pointer. Uniform PHY driver access by eliminating
to_phy_driver() use in mdio_bus_phy_may_suspend().
Only phy_bus_match() and phy_probe() are still using to_phy_driver(),
because PHY driver pointer is not available there.
Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
drivers/net/phy/phy_device.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ba5ad86ec826..9e2891d8e8dd 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -233,11 +233,9 @@ static DEFINE_MUTEX(phy_fixup_lock);
static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
{
- struct device_driver *drv = phydev->mdio.dev.driver;
- struct phy_driver *phydrv = to_phy_driver(drv);
struct net_device *netdev = phydev->attached_dev;
- if (!drv || !phydrv->suspend)
+ if (!phydev->drv->suspend)
return false;
/* PHY not attached? May suspend if the PHY has not already been
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v2 3/3] net: phy: gmii2rgmii: Support PHY loopback
2021-08-19 13:11 [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support Gerhard Engleder
2021-08-19 13:11 ` [PATCH net-next v2 1/3] net: phy: Support set_loopback override Gerhard Engleder
2021-08-19 13:11 ` [PATCH net-next v2 2/3] net: phy: Uniform PHY driver access Gerhard Engleder
@ 2021-08-19 13:11 ` Gerhard Engleder
2021-08-20 13:40 ` [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Gerhard Engleder @ 2021-08-19 13:11 UTC (permalink / raw)
To: andrew; +Cc: netdev, Gerhard Engleder
Configure speed if loopback is used. read_status is not called for
loopback.
Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
drivers/net/phy/xilinx_gmii2rgmii.c | 46 ++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 11 deletions(-)
diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c
index 151c2a3f0b3a..8dcb49ed1f3d 100644
--- a/drivers/net/phy/xilinx_gmii2rgmii.c
+++ b/drivers/net/phy/xilinx_gmii2rgmii.c
@@ -27,12 +27,28 @@ struct gmii2rgmii {
struct mdio_device *mdio;
};
-static int xgmiitorgmii_read_status(struct phy_device *phydev)
+static void xgmiitorgmii_configure(struct gmii2rgmii *priv, int speed)
{
- struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio);
struct mii_bus *bus = priv->mdio->bus;
int addr = priv->mdio->addr;
- u16 val = 0;
+ u16 val;
+
+ val = mdiobus_read(bus, addr, XILINX_GMII2RGMII_REG);
+ val &= ~XILINX_GMII2RGMII_SPEED_MASK;
+
+ if (speed == SPEED_1000)
+ val |= BMCR_SPEED1000;
+ else if (speed == SPEED_100)
+ val |= BMCR_SPEED100;
+ else
+ val |= BMCR_SPEED10;
+
+ mdiobus_write(bus, addr, XILINX_GMII2RGMII_REG, val);
+}
+
+static int xgmiitorgmii_read_status(struct phy_device *phydev)
+{
+ struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio);
int err;
if (priv->phy_drv->read_status)
@@ -42,17 +58,24 @@ static int xgmiitorgmii_read_status(struct phy_device *phydev)
if (err < 0)
return err;
- val = mdiobus_read(bus, addr, XILINX_GMII2RGMII_REG);
- val &= ~XILINX_GMII2RGMII_SPEED_MASK;
+ xgmiitorgmii_configure(priv, phydev->speed);
- if (phydev->speed == SPEED_1000)
- val |= BMCR_SPEED1000;
- else if (phydev->speed == SPEED_100)
- val |= BMCR_SPEED100;
+ return 0;
+}
+
+static int xgmiitorgmii_set_loopback(struct phy_device *phydev, bool enable)
+{
+ struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio);
+ int err;
+
+ if (priv->phy_drv->set_loopback)
+ err = priv->phy_drv->set_loopback(phydev, enable);
else
- val |= BMCR_SPEED10;
+ err = genphy_loopback(phydev, enable);
+ if (err < 0)
+ return err;
- mdiobus_write(bus, addr, XILINX_GMII2RGMII_REG, val);
+ xgmiitorgmii_configure(priv, phydev->speed);
return 0;
}
@@ -90,6 +113,7 @@ static int xgmiitorgmii_probe(struct mdio_device *mdiodev)
memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
sizeof(struct phy_driver));
priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
+ priv->conv_phy_drv.set_loopback = xgmiitorgmii_set_loopback;
mdiodev_set_drvdata(&priv->phy_dev->mdio, priv);
priv->phy_dev->drv = &priv->conv_phy_drv;
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support
2021-08-19 13:11 [PATCH net-next v2 0/3] Add Xilinx GMII2RGMII loopback support Gerhard Engleder
` (2 preceding siblings ...)
2021-08-19 13:11 ` [PATCH net-next v2 3/3] net: phy: gmii2rgmii: Support PHY loopback Gerhard Engleder
@ 2021-08-20 13:40 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-20 13:40 UTC (permalink / raw)
To: Gerhard Engleder; +Cc: andrew, netdev
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
On Thu, 19 Aug 2021 15:11:51 +0200 you wrote:
> The Xilinx GMII2RGMII driver overrides PHY driver functions in order to
> configure the device according to the link speed of the PHY attached to
> it. This is implemented for a normal link but not for loopback.
>
> Andrew told me to use phy_loopback and this changes make phy_loopback
> work in combination with Xilinx GMII2RGMII.
>
> [...]
Here is the summary with links:
- [net-next,v2,1/3] net: phy: Support set_loopback override
https://git.kernel.org/netdev/net-next/c/4ed311b08a91
- [net-next,v2,2/3] net: phy: Uniform PHY driver access
https://git.kernel.org/netdev/net-next/c/3ac8eed62596
- [net-next,v2,3/3] net: phy: gmii2rgmii: Support PHY loopback
https://git.kernel.org/netdev/net-next/c/ceaeaafc8b62
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] 5+ messages in thread