From: Andrew Lunn <andrew@lunn.ch>
Date: Sun, 10 May 2020 21:12:39 +0200
Subject: net: phy: Put interface into oper testing during cable test
Patch-mainline: v5.8-rc1
Git-commit: 4a459bdc7472b0e6bea6d0dd8df66253ac4f3fe2
References: bsc#1176447
Since running a cable test is disruptive, put the interface into
operative state testing while the test is running.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
drivers/net/phy/phy.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -466,6 +466,7 @@ static void phy_abort_cable_test(struct
int phy_start_cable_test(struct phy_device *phydev,
struct netlink_ext_ack *extack)
{
+ struct net_device *dev = phydev->attached_dev;
int err = -ENOMEM;
if (!(phydev->drv &&
@@ -499,8 +500,10 @@ int phy_start_cable_test(struct phy_devi
/* Mark the carrier down until the test is complete */
phy_link_down(phydev, true);
+ netif_testing_on(dev);
err = phydev->drv->cable_test_start(phydev);
if (err) {
+ netif_testing_off(dev);
phy_link_up(phydev);
goto out_free;
}
@@ -876,6 +879,8 @@ EXPORT_SYMBOL(phy_free_interrupt);
*/
void phy_stop(struct phy_device *phydev)
{
+ struct net_device *dev = phydev->attached_dev;
+
if (!phy_is_started(phydev)) {
WARN(1, "called from state %s\n",
phy_state_to_str(phydev->state));
@@ -884,8 +889,10 @@ void phy_stop(struct phy_device *phydev)
mutex_lock(&phydev->lock);
- if (phydev->state == PHY_CABLETEST)
+ if (phydev->state == PHY_CABLETEST) {
phy_abort_cable_test(phydev);
+ netif_testing_off(dev);
+ }
if (phydev->sfp_bus)
sfp_upstream_stop(phydev->sfp_bus);
@@ -947,6 +954,7 @@ void phy_state_machine(struct work_struc
struct delayed_work *dwork = to_delayed_work(work);
struct phy_device *phydev =
container_of(dwork, struct phy_device, state_queue);
+ struct net_device *dev = phydev->attached_dev;
bool needs_aneg = false, do_suspend = false;
enum phy_state old_state;
bool finished = false;
@@ -972,6 +980,7 @@ void phy_state_machine(struct work_struc
err = phydev->drv->cable_test_get_status(phydev, &finished);
if (err) {
phy_abort_cable_test(phydev);
+ netif_testing_off(dev);
needs_aneg = true;
phydev->state = PHY_UP;
break;
@@ -979,6 +988,7 @@ void phy_state_machine(struct work_struc
if (finished) {
ethnl_cable_test_finished(phydev);
+ netif_testing_off(dev);
needs_aneg = true;
phydev->state = PHY_UP;
}