In order to untangle the ethtool/cabletest feature with the PHY library,
make the PHY library functions take a net_device argument and derive the
phy_device reference from there.

No functional changes introduced.

Signed-off-by: Florian Fainelli <f.faine...@gmail.com>
---
 drivers/net/phy/phy.c   | 18 ++++++++++++++----
 include/linux/phy.h     |  8 ++++----
 net/ethtool/cabletest.c |  4 ++--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 56cfae950472..fbb74f37b961 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -489,12 +489,17 @@ static void phy_abort_cable_test(struct phy_device 
*phydev)
                phydev_err(phydev, "Error while aborting cable test");
 }
 
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
                         struct netlink_ext_ack *extack)
 {
-       struct net_device *dev = phydev->attached_dev;
+       struct phy_device *phydev = dev->phydev;
        int err = -ENOMEM;
 
+       if (!dev->phydev) {
+               NL_SET_ERR_MSG(extack, "Network device not attached to a PHY");
+               return -EOPNOTSUPP;
+       }
+
        if (!(phydev->drv &&
              phydev->drv->cable_test_start &&
              phydev->drv->cable_test_get_status)) {
@@ -552,13 +557,18 @@ int phy_start_cable_test(struct phy_device *phydev,
 }
 EXPORT_SYMBOL(phy_start_cable_test);
 
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
                             struct netlink_ext_ack *extack,
                             const struct phy_tdr_config *config)
 {
-       struct net_device *dev = phydev->attached_dev;
+       struct phy_device *phydev = dev->phydev;
        int err = -ENOMEM;
 
+       if (!dev->phydev) {
+               NL_SET_ERR_MSG(extack, "Network device not attached to a PHY");
+               return -EOPNOTSUPP;
+       }
+
        if (!(phydev->drv &&
              phydev->drv->cable_test_tdr_start &&
              phydev->drv->cable_test_get_status)) {
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 101a48fa6750..53b95c52869d 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1266,21 +1266,21 @@ int phy_restart_aneg(struct phy_device *phydev);
 int phy_reset_after_clk_enable(struct phy_device *phydev);
 
 #if IS_ENABLED(CONFIG_PHYLIB)
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
                         struct netlink_ext_ack *extack);
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
                             struct netlink_ext_ack *extack,
                             const struct phy_tdr_config *config);
 #else
 static inline
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
                         struct netlink_ext_ack *extack)
 {
        NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
        return -EOPNOTSUPP;
 }
 static inline
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
                             struct netlink_ext_ack *extack,
                             const struct phy_tdr_config *config)
 {
diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c
index 7194956aa09e..0d940a91493b 100644
--- a/net/ethtool/cabletest.c
+++ b/net/ethtool/cabletest.c
@@ -85,7 +85,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct 
genl_info *info)
        if (ret < 0)
                goto out_rtnl;
 
-       ret = phy_start_cable_test(dev->phydev, info->extack);
+       ret = phy_start_cable_test(dev, info->extack);
 
        ethnl_ops_complete(dev);
 
@@ -341,7 +341,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct 
genl_info *info)
        if (ret < 0)
                goto out_rtnl;
 
-       ret = phy_start_cable_test_tdr(dev->phydev, info->extack, &cfg);
+       ret = phy_start_cable_test_tdr(dev, info->extack, &cfg);
 
        ethnl_ops_complete(dev);
 
-- 
2.25.1

Reply via email to