From patchwork Tue May 5 00:18:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 219911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABFF1C3A5A9 for ; Tue, 5 May 2020 00:18:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8715F20661 for ; Tue, 5 May 2020 00:18:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="lvojK9zx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728536AbgEEASw (ORCPT ); Mon, 4 May 2020 20:18:52 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41328 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgEEASv (ORCPT ); Mon, 4 May 2020 20:18:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=EIpxeB+42IFr3LLeA3jPsueGvg4ER04tOUSPmds9F8w=; b=lvojK9zx/OUmq7+SLpt/vy+4yJ aJV05xkdmM3z/IAWwySFZbbK0ZCavp077WawTH9oJF1u7SQvUypBIa6k/TYoD/wsF/orsZF4ykBQZ CocNBKBKU4TfvsFv9Mcx8437hcyw088rXwRlF7B2I6lRb3fe/3jNtEhdLPSOFyYXPNfk=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVlID-000sGE-C7; Tue, 05 May 2020 02:18:37 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , Michal Kubecek , michael@walle.cc, Andrew Lunn Subject: [PATCH net-next v2 01/10] net: phy: Add cable test support to state machine Date: Tue, 5 May 2020 02:18:12 +0200 Message-Id: <20200505001821.208534-2-andrew@lunn.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200505001821.208534-1-andrew@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Running a cable test is desruptive to normal operation of the PHY and can take a 5 to 10 seconds to complete. The RTNL lock cannot be held for this amount of time, and add a new state to the state machine for running a cable test. The driver is expected to implement two functions. The first is used to start a cable test. Once the test has started, it should return. The second function is called once per second, or on interrupt to check if the cable test is complete, and to allow the PHY to report the status. v2: Rename phy_cable_test_abort to phy_abort_cable_test Return different extack when already running test Use phy_init_hw() to reset the PHY Reviewed-by: Florian Fainelli Signed-off-by: Andrew Lunn --- drivers/net/phy/phy.c | 76 +++++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 28 ++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 72c69a9c8a98..4f95e605080e 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ static const char *phy_state_to_str(enum phy_state st) PHY_STATE_STR(UP) PHY_STATE_STR(RUNNING) PHY_STATE_STR(NOLINK) + PHY_STATE_STR(CABLETEST) PHY_STATE_STR(HALTED) } @@ -470,6 +472,62 @@ static void phy_trigger_machine(struct phy_device *phydev) phy_queue_state_machine(phydev, 0); } +static void phy_abort_cable_test(struct phy_device *phydev) +{ + int err; + + err = phy_init_hw(phydev); + if (err) + phydev_err(phydev, "Error while aborting cable test"); +} + +int phy_start_cable_test(struct phy_device *phydev, + struct netlink_ext_ack *extack) +{ + int err; + + if (!(phydev->drv && + phydev->drv->cable_test_start && + phydev->drv->cable_test_get_status)) { + NL_SET_ERR_MSG(extack, + "PHY driver does not support cable testing"); + 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; + } + + /* Mark the carrier down until the test is complete */ + phy_link_down(phydev, true); + + err = phydev->drv->cable_test_start(phydev); + if (err) { + phy_link_up(phydev); + goto out; + } + + phydev->state = PHY_CABLETEST; + +out: + mutex_unlock(&phydev->lock); + + return err; +} +EXPORT_SYMBOL(phy_start_cable_test); + static int phy_config_aneg(struct phy_device *phydev) { if (phydev->drv->config_aneg) @@ -808,6 +866,9 @@ void phy_stop(struct phy_device *phydev) mutex_lock(&phydev->lock); + if (phydev->state == PHY_CABLETEST) + phy_abort_cable_test(phydev); + if (phydev->sfp_bus) sfp_upstream_stop(phydev->sfp_bus); @@ -870,6 +931,7 @@ void phy_state_machine(struct work_struct *work) container_of(dwork, struct phy_device, state_queue); bool needs_aneg = false, do_suspend = false; enum phy_state old_state; + bool finished = false; int err = 0; mutex_lock(&phydev->lock); @@ -888,6 +950,20 @@ void phy_state_machine(struct work_struct *work) case PHY_RUNNING: err = phy_check_link_status(phydev); break; + case PHY_CABLETEST: + err = phydev->drv->cable_test_get_status(phydev, &finished); + if (err) { + phy_abort_cable_test(phydev); + needs_aneg = true; + phydev->state = PHY_UP; + break; + } + + if (finished) { + needs_aneg = true; + phydev->state = PHY_UP; + } + break; case PHY_HALTED: if (phydev->link) { phydev->link = 0; diff --git a/include/linux/phy.h b/include/linux/phy.h index e2bfb9240587..916a5eb969a1 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -343,6 +344,12 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); * - irq or timer will set NOLINK if link goes down * - phy_stop moves to HALTED * + * CABLETEST: PHY is performing a cable test. Packet reception/sending + * is not expected to work, carrier will be indicated as down. PHY will be + * poll once per second, or on interrupt for it current state. + * Once complete, move to UP to restart the PHY. + * - phy_stop aborts the running test and moves to HALTED + * * HALTED: PHY is up, but no polling or interrupts are done. Or * PHY is in an error state. * - phy_start moves to UP @@ -354,6 +361,7 @@ enum phy_state { PHY_UP, PHY_RUNNING, PHY_NOLINK, + PHY_CABLETEST, }; /** @@ -653,6 +661,13 @@ struct phy_driver { int (*module_eeprom)(struct phy_device *dev, struct ethtool_eeprom *ee, u8 *data); + /* Start a cable test */ + int (*cable_test_start)(struct phy_device *dev); + /* Once per second, or on interrupt, request the status of the + * test. + */ + int (*cable_test_get_status)(struct phy_device *dev, bool *finished); + /* Get statistics from the phy using ethtool */ int (*get_sset_count)(struct phy_device *dev); void (*get_strings)(struct phy_device *dev, u8 *data); @@ -1191,6 +1206,19 @@ int phy_speed_up(struct phy_device *phydev); 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, + struct netlink_ext_ack *extack); +#else +static inline +int phy_start_cable_test(struct phy_device *phydev, + struct netlink_ext_ack *extack) +{ + NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support"); + return -EOPNOTSUPP; +} +#endif + static inline void phy_device_reset(struct phy_device *phydev, int value) { mdio_device_reset(&phydev->mdio, value); From patchwork Tue May 5 00:18:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 219913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D924C47254 for ; Tue, 5 May 2020 00:18:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 736ED20661 for ; Tue, 5 May 2020 00:18:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="v3U5q6hU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728470AbgEEASm (ORCPT ); Mon, 4 May 2020 20:18:42 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41266 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728258AbgEEASl (ORCPT ); Mon, 4 May 2020 20:18:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=YLzA7K4y2n52yn3k9/OFNCN5fbIyAtCofRSwZ57UsrM=; b=v3U5q6hUh+8ixvl9eT55GdfDay //hLpp8F8RRyj9rUfdCuFlwKir9Qgpi0e9HJ367LZp9tebQTdXK8u3GCqOkbAlzcvLXBVjA7ophTb aA935/92rEZWvtCVoOallgYyi3xTotth1MhKXWMNloBz0ho49nHFEm3EjTGlIrLlfNvM=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVlID-000sGJ-DP; Tue, 05 May 2020 02:18:37 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , Michal Kubecek , michael@walle.cc, Andrew Lunn Subject: [PATCH net-next v2 02/10] net: phy: Add support for polling cable test Date: Tue, 5 May 2020 02:18:13 +0200 Message-Id: <20200505001821.208534-3-andrew@lunn.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200505001821.208534-1-andrew@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some PHYs are not capable of generating interrupts when a cable test finished. They do however support interrupts for normal operations, like link up/down. As such, the PHY state machine would normally not poll the PHY. Add support for indicating the PHY state machine must poll the PHY when performing a cable test. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy.c | 2 ++ include/linux/phy.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 4f95e605080e..cea89785bcd4 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -521,6 +521,8 @@ int phy_start_cable_test(struct phy_device *phydev, phydev->state = PHY_CABLETEST; + if (phy_polling_mode(phydev)) + phy_trigger_machine(phydev); out: mutex_unlock(&phydev->lock); diff --git a/include/linux/phy.h b/include/linux/phy.h index 916a5eb969a1..593da2c6041d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -78,6 +78,7 @@ extern const int phy_10gbit_features_array[1]; #define PHY_IS_INTERNAL 0x00000001 #define PHY_RST_AFTER_CLK_EN 0x00000002 +#define PHY_POLL_CABLE_TEST 0x00000004 #define MDIO_DEVICE_IS_PHY 0x80000000 /* Interface Mode definitions */ @@ -1025,6 +1026,10 @@ static inline bool phy_interrupt_is_valid(struct phy_device *phydev) */ static inline bool phy_polling_mode(struct phy_device *phydev) { + if (phydev->state == PHY_CABLETEST) + if (phydev->drv->flags & PHY_POLL_CABLE_TEST) + return true; + return phydev->irq == PHY_POLL; } From patchwork Tue May 5 00:18:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 219912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1450C3A5A9 for ; Tue, 5 May 2020 00:18:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFC4F20661 for ; Tue, 5 May 2020 00:18:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="K8Z+V2h0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728501AbgEEASq (ORCPT ); Mon, 4 May 2020 20:18:46 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41276 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728258AbgEEASn (ORCPT ); Mon, 4 May 2020 20:18:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bfNKjJWlaled4Ss3zCwwy8GfHI11+f2ul0ZnQA3aspw=; b=K8Z+V2h0iSxkbsg7KXJPOpkaVH XhCgRKemPkuRE8Fwp2FBQFo8+upBdrWtmqQm0P/LEvydazKmU4czqfzkYCZKefZq+O1nMK48JGv5F e9Wz/YbRoPmFBkun0VXy7lfTjXbx18cQgv1jnFlePkXJsIWiyC/xJmv1DuN+Z5vqhgP4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVlID-000sGi-Ij; Tue, 05 May 2020 02:18:37 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , Michal Kubecek , michael@walle.cc, Andrew Lunn Subject: [PATCH net-next v2 07/10] net: ethtool: Add helpers for reporting test results Date: Tue, 5 May 2020 02:18:18 +0200 Message-Id: <20200505001821.208534-8-andrew@lunn.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200505001821.208534-1-andrew@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The PHY drivers can use these helpers for reporting the results. The results get translated into netlink attributes which are added to the pre-allocated skbuf. Signed-off-by: Andrew Lunn --- include/linux/ethtool_netlink.h | 13 +++++++++ include/linux/phy.h | 4 +++ net/ethtool/cabletest.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/include/linux/ethtool_netlink.h b/include/linux/ethtool_netlink.h index 7d763ba22f6f..0d12abbdf3c3 100644 --- a/include/linux/ethtool_netlink.h +++ b/include/linux/ethtool_netlink.h @@ -20,6 +20,8 @@ struct phy_device; int ethnl_cable_test_alloc(struct phy_device *phydev); void ethnl_cable_test_free(struct phy_device *phydev); void ethnl_cable_test_finished(struct phy_device *phydev); +int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u16 result); +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm); #else static inline int ethnl_cable_test_alloc(struct phy_device *phydev) { @@ -33,5 +35,16 @@ static inline void ethnl_cable_test_free(struct phy_device *phydev) static inline void ethnl_cable_test_finished(struct phy_device *phydev) { } +static inline int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, + u16 result) +{ + return -ENOTSUPP; +} + +static inline int ethnl_cable_test_fault_length(struct phy_device *phydev, + u8 pair, u16 cm) +{ + return -ENOTSUPP; +} #endif /* IS_ENABLED(ETHTOOL_NETLINK) */ #endif /* _LINUX_ETHTOOL_NETLINK_H_ */ diff --git a/include/linux/phy.h b/include/linux/phy.h index ee69f781995a..856b4293a645 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1229,6 +1229,10 @@ int phy_start_cable_test(struct phy_device *phydev, } #endif +int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result); +int phy_cable_test_fault_length(struct phy_device *phydev, u8 pair, + u16 cm); + static inline void phy_device_reset(struct phy_device *phydev, int value) { mdio_device_reset(&phydev->mdio, value); diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index 4c888db33ef0..f500454a54eb 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -114,3 +114,50 @@ void ethnl_cable_test_finished(struct phy_device *phydev) ethnl_multicast(phydev->skb, phydev->attached_dev); } EXPORT_SYMBOL_GPL(ethnl_cable_test_finished); + +int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u16 result) +{ + struct nlattr *nest; + int ret = -EMSGSIZE; + + nest = nla_nest_start(phydev->skb, ETHTOOL_A_CABLE_TEST_NTF_RESULT); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_PAIR, pair)) + goto err; + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_CODE, result)) + goto err; + + nla_nest_end(phydev->skb, nest); + return 0; + +err: + nla_nest_cancel(phydev->skb, nest); + return ret; +} +EXPORT_SYMBOL_GPL(ethnl_cable_test_result); + +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) +{ + struct nlattr *nest; + int ret = -EMSGSIZE; + + nest = nla_nest_start(phydev->skb, + ETHTOOL_A_CABLE_TEST_NTF_FAULT_LENGTH); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR, pair)) + goto err; + if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) + goto err; + + nla_nest_end(phydev->skb, nest); + return 0; + +err: + nla_nest_cancel(phydev->skb, nest); + return ret; +} +EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length); From patchwork Tue May 5 00:18:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 219910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C66BC47258 for ; Tue, 5 May 2020 00:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0541420661 for ; Tue, 5 May 2020 00:18:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="tJD6Jm9J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728557AbgEEASy (ORCPT ); Mon, 4 May 2020 20:18:54 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41338 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728535AbgEEASw (ORCPT ); Mon, 4 May 2020 20:18:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iDZnrfNOcH+h7WoVKj40uEfYqakSG2WnWKKuRG6XJLc=; b=tJD6Jm9J2zGjRrfpvgj1C+4iI2 thtBczSEiLi+TNWb8X4G74Dm774dnX1UWbmcJ4c1XbdLFtiG2UYA/zuzLmcjuTgAYhLkxppiS+CbX o8JVHQ9fcWjqvEg5fhDWh7kBo1exNQuAeJyWv/Sf7krWC5mjQ6CWAP9NrtK9ZPNZw2XU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVlID-000sGs-Kv; Tue, 05 May 2020 02:18:37 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , Michal Kubecek , michael@walle.cc, Andrew Lunn Subject: [PATCH net-next v2 09/10] net: phy: Put interface into oper testing during cable test Date: Tue, 5 May 2020 02:18:20 +0200 Message-Id: <20200505001821.208534-10-andrew@lunn.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200505001821.208534-1-andrew@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since running a cable test is disruptive, put the interface into operative state testing while the test is running. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 039e41e15c7e..2117e3347d59 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -490,6 +490,7 @@ static void phy_abort_cable_test(struct phy_device *phydev) 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 && @@ -523,8 +524,10 @@ int phy_start_cable_test(struct phy_device *phydev, /* 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; } @@ -877,6 +880,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)); @@ -885,8 +890,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); @@ -948,6 +955,7 @@ void phy_state_machine(struct work_struct *work) 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; @@ -973,6 +981,7 @@ void phy_state_machine(struct work_struct *work) 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; @@ -980,6 +989,7 @@ void phy_state_machine(struct work_struct *work) if (finished) { ethnl_cable_test_finished(phydev); + netif_testing_off(dev); needs_aneg = true; phydev->state = PHY_UP; } From patchwork Tue May 5 00:18:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 219909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF67EC47247 for ; Tue, 5 May 2020 00:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F05020661 for ; Tue, 5 May 2020 00:19:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="VOYPltAN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728573AbgEEATB (ORCPT ); Mon, 4 May 2020 20:19:01 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41378 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728535AbgEEATB (ORCPT ); Mon, 4 May 2020 20:19:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Cs7gXRieqA/hKSrbcwQ6bI1VZ2XfhrWkA6NiAbRUtOY=; b=VOYPltANrkC8gNgSMrhLy2Q4PN muhN9gKnrMPGZva68qyJ1/GTReoRvQEf19Y4Y+nbfJbxHhS+le/PLJbYoMcZfVSzHJbeWtWaNJrEr yqZ/o0NlHKMBkb5DUjrmF5NXJXDcWpSTd+D+PTstnTmaoRlkgzebMu6WTpZ03+6O9AFU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVlID-000sGx-Lz; Tue, 05 May 2020 02:18:37 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , Michal Kubecek , michael@walle.cc, Andrew Lunn Subject: [PATCH net-next v2 10/10] net: phy: Send notifier when starting the cable test Date: Tue, 5 May 2020 02:18:21 +0200 Message-Id: <20200505001821.208534-11-andrew@lunn.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200505001821.208534-1-andrew@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Given that it takes time to run a cable test, send a notify message at the start, as well as when it is completed. Signed-off-by: Andrew Lunn --- net/ethtool/cabletest.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index f500454a54eb..e59f570494c0 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -20,6 +20,41 @@ cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, }; +static int ethnl_cable_test_started(struct phy_device *phydev) +{ + struct sk_buff *skb; + int err = -ENOMEM; + void *ehdr; + + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb) + goto out; + + ehdr = ethnl_bcastmsg_put(skb, ETHTOOL_MSG_CABLE_TEST_NTF); + if (!ehdr) { + err = -EINVAL; + goto out; + } + + err = ethnl_fill_reply_header(skb, phydev->attached_dev, + ETHTOOL_A_CABLE_TEST_NTF_HEADER); + if (err) + goto out; + + err = nla_put_u8(skb, ETHTOOL_A_CABLE_TEST_NTF_STATUS, + ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED); + if (err) + goto out; + + genlmsg_end(skb, ehdr); + + return ethnl_multicast(skb, phydev->attached_dev); + +out: + nlmsg_free(skb); + return err; +} + int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) { struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX + 1]; @@ -54,6 +89,10 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ret = phy_start_cable_test(dev->phydev, info->extack); ethnl_ops_complete(dev); + + if (!ret) + ethnl_cable_test_started(dev->phydev); + out_rtnl: rtnl_unlock(); out_dev_put: