From patchwork Mon Nov 21 15:35:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 697285 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tMt3f3Bwlz9t2p for ; Tue, 22 Nov 2016 02:35:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="RDpQoLD8"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754825AbcKUPfv (ORCPT ); Mon, 21 Nov 2016 10:35:51 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:34770 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754744AbcKUPfs (ORCPT ); Mon, 21 Nov 2016 10:35:48 -0500 Received: by mail-wm0-f49.google.com with SMTP id u144so22377485wmu.1 for ; Mon, 21 Nov 2016 07:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Uttq6QXxfpMtsaotMm2CdeNTdaxbfQnbJgqUCusVj64=; b=RDpQoLD85M/yGlVHwJgQwggtvWm8K1XpLQo1Vo8deutdeIptnmO6YgQ5CBKHc6gihB naCbrz0Akkt7VyB/+YwHjCey7TnGCdY5nIF84wK+l8yqRGnAO/Dk78ldse1abTOwDBk+ LXvbIj1w5YFDgQABye7eOxs5yNGUzCRetydWY3aXPyT1+AaODZ61BD8pMTQDtBMyFbOt L5bUIksbI80Vt7J/ZwBlqBjUey0UB1VBktGj+SWsp/Cjpu+4mzG7Ox0P+NTOaxVqFayn HAeASHVqbbQZ3e5UZ4r25ruvqPM4HZWdNtW0mpRAEnhl4+o3Ac1V42onawx7/tZLtjOF ARdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Uttq6QXxfpMtsaotMm2CdeNTdaxbfQnbJgqUCusVj64=; b=G4PFBsJtnXbwzMTmuaC6oZTSa0kTyrK5YGkTu2BPg5Sos4vZNcgWLBpZtg5SKnJ/XA 6P0m8eCRnHBo6RSF+M3KIcfud+buizSt/8Ba+O89vfz+bkWE5y/R8/VXsUI8smNrU96q EXl8MdaVWBeE4i1a23Ct/BZeLWmo9HBbxUsILkILS7mdxwK4X4Lod5sU3Sny96nAlxB7 cwrxkc4dVdxJMLhezurf4kyS+2YY/pp1wZ1pZ6RV9iGFMkXUkc3fkiiz9XSaYg/LeMLC LvhUlUEHM3xhLhtIVTQnFkp68nr3HInGHGN1KyWJR/qI3NDBf/9VoEGSucFxkxboQypt Tzpw== X-Gm-Message-State: AKaTC00z0SVc7QnxiH4IOpYoyWShBmxSo0xxjheIEXmAAO2q1cRGZ1eboepJgnLHAEdhInpn X-Received: by 10.28.107.21 with SMTP id g21mr16532793wmc.131.1479742547056; Mon, 21 Nov 2016 07:35:47 -0800 (PST) Received: from boomer.baylibre.com ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id vr9sm25597909wjc.35.2016.11.21.07.35.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Nov 2016 07:35:46 -0800 (PST) From: Jerome Brunet To: netdev@vger.kernel.org, devicetree@vger.kernel.org, Florian Fainelli Cc: Jerome Brunet , Carlo Caione , Kevin Hilman , Giuseppe Cavallaro , Alexandre TORGUE , Martin Blumenstingl , Andre Roth , Neil Armstrong , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net v2 1/3] net: phy: add an option to disable EEE advertisement Date: Mon, 21 Nov 2016 16:35:22 +0100 Message-Id: <1479742524-30222-2-git-send-email-jbrunet@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479742524-30222-1-git-send-email-jbrunet@baylibre.com> References: <1479742524-30222-1-git-send-email-jbrunet@baylibre.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds an option to disable EEE advertisement in the generic PHY by providing a mask of prohibited modes corresponding to the value found in the MDIO_AN_EEE_ADV register. On some platforms, PHY Low power idle seems to be causing issues, even breaking the link some cases. The patch provides a convenient way for these platforms to disable EEE advertisement and work around the issue. Signed-off-by: Jerome Brunet --- drivers/net/phy/phy.c | 3 ++ drivers/net/phy/phy_device.c | 80 +++++++++++++++++++++++++++++++++++++++----- include/linux/phy.h | 3 ++ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index f424b867f73e..a44ee14bd953 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1348,6 +1348,9 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) { int val = ethtool_adv_to_mmd_eee_adv_t(data->advertised); + /* Mask prohibited EEE modes */ + val &= ~phydev->eee_advert_disabled; + phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, val); return 0; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1a4bf8acad78..74c628e046cb 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1116,6 +1116,43 @@ static int genphy_config_advert(struct phy_device *phydev) } /** + * genphy_config_eee_advert - disable unwanted eee mode advertisement + * @phydev: target phy_device struct + * + * Description: Writes MDIO_AN_EEE_ADV after disabling unsupported energy + * efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't + * changed, and 1 if it has changed. + */ +static int genphy_config_eee_advert(struct phy_device *phydev) +{ + u32 disabled = phydev->eee_advert_disabled; + u32 old_adv, adv; + + /* Nothing to disable */ + if (!disabled) + return 0; + + /* If the following call fails, we assume that EEE is not + * supported by the phy. If we read 0, EEE is not advertised + * In both case, we don't need to continue + */ + adv = phy_read_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN); + if (adv <= 0) + return 0; + + old_adv = adv; + adv &= ~disabled; + + /* Advertising remains unchanged with the ban */ + if (old_adv == adv) + return 0; + + phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, adv); + + return 1; +} + +/** * genphy_setup_forced - configures/forces speed/duplex from @phydev * @phydev: target phy_device struct * @@ -1173,15 +1210,20 @@ EXPORT_SYMBOL(genphy_restart_aneg); */ int genphy_config_aneg(struct phy_device *phydev) { - int result; + int err, changed; + + changed = genphy_config_eee_advert(phydev); if (AUTONEG_ENABLE != phydev->autoneg) return genphy_setup_forced(phydev); - result = genphy_config_advert(phydev); - if (result < 0) /* error */ - return result; - if (result == 0) { + err = genphy_config_advert(phydev); + if (err < 0) /* error */ + return err; + + changed |= err; + + if (changed == 0) { /* Advertisement hasn't changed, but maybe aneg was never on to * begin with? Or maybe phy was isolated? */ @@ -1191,16 +1233,16 @@ int genphy_config_aneg(struct phy_device *phydev) return ctl; if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) - result = 1; /* do restart aneg */ + changed = 1; /* do restart aneg */ } /* Only restart aneg if we are advertising something different * than we were before. */ - if (result > 0) - result = genphy_restart_aneg(phydev); + if (changed > 0) + return genphy_restart_aneg(phydev); - return result; + return 0; } EXPORT_SYMBOL(genphy_config_aneg); @@ -1558,6 +1600,21 @@ static void of_set_phy_supported(struct phy_device *phydev) __set_phy_supported(phydev, max_speed); } +static void of_set_phy_eee_disable(struct phy_device *phydev) +{ + struct device_node *node = phydev->mdio.dev.of_node; + u32 disabled; + + if (!IS_ENABLED(CONFIG_OF_MDIO)) + return; + + if (!node) + return; + + if (!of_property_read_u32(node, "eee-advert-disable", &disabled)) + phydev->eee_advert_disabled = disabled; +} + /** * phy_probe - probe and init a PHY device * @dev: device to probe and init @@ -1595,6 +1652,11 @@ static int phy_probe(struct device *dev) of_set_phy_supported(phydev); phydev->advertising = phydev->supported; + /* Get the EEE modes we want to prohibit. We will ask + * the PHY stop advertising these mode later on + */ + of_set_phy_eee_disable(phydev); + /* Set the state to READY by default */ phydev->state = PHY_READY; diff --git a/include/linux/phy.h b/include/linux/phy.h index e25f1830fbcf..7f2ea0af16d1 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -401,6 +401,9 @@ struct phy_device { u32 advertising; u32 lp_advertising; + /* Energy efficient ethernet modes which should be prohibited */ + u32 eee_advert_disabled; + int autoneg; int link_timeout;