@@ -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)) {
@@ -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)
{
@@ -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);
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.fainelli@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(-)