net: ethtool: Add generic parts of cable test TDR

Add the generic parts of the code used to trigger a cable test and
return raw TDR data. Any PHY driver which support this must implement
the new driver op.

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

v2
Update nxp-tja11xx for API change.

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Andrew Lunn
2020-05-27 00:21:38 +02:00
committed by David S. Miller
parent a331172b15
commit 1a644de29f
7 changed files with 144 additions and 10 deletions

View File

@@ -519,7 +519,7 @@ int phy_start_cable_test(struct phy_device *phydev,
goto out;
}
err = ethnl_cable_test_alloc(phydev);
err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_NTF);
if (err)
goto out;
@@ -552,6 +552,69 @@ out:
}
EXPORT_SYMBOL(phy_start_cable_test);
int phy_start_cable_test_tdr(struct phy_device *phydev,
struct netlink_ext_ack *extack)
{
struct net_device *dev = phydev->attached_dev;
int err = -ENOMEM;
if (!(phydev->drv &&
phydev->drv->cable_test_tdr_start &&
phydev->drv->cable_test_get_status)) {
NL_SET_ERR_MSG(extack,
"PHY driver does not support cable test TDR");
return -EOPNOTSUPP;
}
mutex_lock(&phydev->lock);
if (phydev->state == PHY_CABLETEST) {
NL_SET_ERR_MSG(extack,
"PHY already performing a test");
err = -EBUSY;
goto out;
}
if (phydev->state < PHY_UP ||
phydev->state > PHY_CABLETEST) {
NL_SET_ERR_MSG(extack,
"PHY not configured. Try setting interface up");
err = -EBUSY;
goto out;
}
err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_TDR_NTF);
if (err)
goto out;
/* Mark the carrier down until the test is complete */
phy_link_down(phydev);
netif_testing_on(dev);
err = phydev->drv->cable_test_tdr_start(phydev);
if (err) {
netif_testing_off(dev);
phy_link_up(phydev);
goto out_free;
}
phydev->state = PHY_CABLETEST;
if (phy_polling_mode(phydev))
phy_trigger_machine(phydev);
mutex_unlock(&phydev->lock);
return 0;
out_free:
ethnl_cable_test_free(phydev);
out:
mutex_unlock(&phydev->lock);
return err;
}
EXPORT_SYMBOL(phy_start_cable_test_tdr);
static int phy_config_aneg(struct phy_device *phydev)
{
if (phydev->drv->config_aneg)