From patchwork Mon Nov 28 15:50:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9449725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 531B8600CB for ; Mon, 28 Nov 2016 15:54:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4143727D7F for ; Mon, 28 Nov 2016 15:54:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3477527DA4; Mon, 28 Nov 2016 15:54:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 96BE827D7F for ; Mon, 28 Nov 2016 15:54:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cBOEy-0006s2-Vq; Mon, 28 Nov 2016 15:53:13 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cBOCw-0005lj-AY for linux-arm-kernel@lists.infradead.org; Mon, 28 Nov 2016 15:51:10 +0000 Received: by mail-wm0-x22d.google.com with SMTP id u144so41677526wmu.1 for ; Mon, 28 Nov 2016 07:50:45 -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 :mime-version:content-transfer-encoding; bh=/U+VnJogG68c3cfPzy0tEY/eOOcERZMSIEJAbfyUEFo=; b=rZ5xukc/dudIXL0aVP4Qw8GFm2yFUulKNJZqQrB0F2xJ0Pv9AhPU4oAH4BMD9Us/Ia cxRRAK363qeKSsdl1rAf3a8tEpjsN6qiWdMzKTcz41Dyj5aJoC5CLspl33Me2I2aZnj9 z1iUkLvKNyG73ExMU675bFTway97cT1/swpuPizJVC4Hq7gyFRjrsMXrcVfRDzLjOnPw p9dm7n2bN1ppqsDTacxiBr7Qk7M0nX8M/vuRh+1z/ubsXpV53u6GuA9Mtfp43LbrPRZk qLJO+/GajFn2GgbM/LhxLK7h5zhV0hYVA+h+5KuU5lV5C8O8EOh/PUIVZIAjg+FwbwKE wQ5A== 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:mime-version:content-transfer-encoding; bh=/U+VnJogG68c3cfPzy0tEY/eOOcERZMSIEJAbfyUEFo=; b=KK1NQ7Gmm6tQ1rSV2KdsYhigxZ8gL4cD4t8WrmFzEdD1eO/Q0UrNMs/FakCRZykGq2 katjLBBSzTt1p/PsDzI0cTNCpn4fLuqh49Dm7y90qQosn2FiqB7ltJm7pRzYZ3K6Vo63 hTe7vjP/BqVdJ5B7lrgGOt6GbJtQDROXZlVEieS7iYJjjJT+2kCMKCG4PcsgGw2qG/pO L5ybogkC1ZvN25bpQip6m5Bw4bwhw26vwxt+DXJu+GQ1IYvJDQStnDIf4XbDbE+Zq8y/ cBmnjMAqGBGvnuwiIpSWobyDgzh+SR0ZEEJYyay6Cq7gpJ26WPe1KCd2hAGLtcWSqBvX 9bVA== X-Gm-Message-State: AKaTC02JCsVlcJsLNWNIUh8lYttoaDyVws9prpQBBeuqOKisL0x/160n9/kwd50b8xsvPTr5 X-Received: by 10.28.214.84 with SMTP id n81mr18619602wmg.120.1480348244285; Mon, 28 Nov 2016 07:50:44 -0800 (PST) Received: from boomer.baylibre.com ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id k11sm29465848wmb.18.2016.11.28.07.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2016 07:50:43 -0800 (PST) From: Jerome Brunet To: netdev@vger.kernel.org, devicetree@vger.kernel.org, Florian Fainelli Subject: [PATCH net-next v4 1/4] net: phy: add an option to disable EEE advertisement Date: Mon, 28 Nov 2016 16:50:25 +0100 Message-Id: <1480348229-25672-2-git-send-email-jbrunet@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480348229-25672-1-git-send-email-jbrunet@baylibre.com> References: <1480348229-25672-1-git-send-email-jbrunet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161128_075106_655065_A3C98C45 X-CRM114-Status: GOOD ( 21.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Alexandre TORGUE , Neil Armstrong , Martin Blumenstingl , Kevin Hilman , linux-kernel@vger.kernel.org, Yegor Yefremov , Julia Lawall , Andre Roth , linux-amlogic@lists.infradead.org, Carlo Caione , Giuseppe Cavallaro , =?UTF-8?q?Andreas=20F=C3=A4rber?= , linux-arm-kernel@lists.infradead.org, Jerome Brunet Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Yegor Yefremov Tested-by: Andreas Färber Tested-by: Neil Armstrong --- 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 73adbaa9ac86..a3981cc6448a 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1396,6 +1396,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_broken_modes; + 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 ba86c191a13e..cb4aca205cf8 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1121,6 +1121,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) +{ + int broken = phydev->eee_broken_modes; + int old_adv, adv; + + /* Nothing to disable */ + if (!broken) + 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 &= ~broken; + + /* Advertising remains unchanged with the broken mask */ + 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 * @@ -1178,15 +1215,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? */ @@ -1196,16 +1238,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); @@ -1563,6 +1605,21 @@ static void of_set_phy_supported(struct phy_device *phydev) __set_phy_supported(phydev, max_speed); } +static void of_set_phy_eee_broken(struct phy_device *phydev) +{ + struct device_node *node = phydev->mdio.dev.of_node; + u32 broken; + + if (!IS_ENABLED(CONFIG_OF_MDIO)) + return; + + if (!node) + return; + + if (!of_property_read_u32(node, "eee-broken-modes", &broken)) + phydev->eee_broken_modes = broken; +} + /** * phy_probe - probe and init a PHY device * @dev: device to probe and init @@ -1600,6 +1657,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_broken(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 edde28ce163a..b53177fd38af 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -417,6 +417,9 @@ struct phy_device { u32 advertising; u32 lp_advertising; + /* Energy efficient ethernet modes which should be prohibited */ + u32 eee_broken_modes; + int autoneg; int link_timeout;