Received: by 10.223.164.202 with SMTP id h10csp3543308wrb; Mon, 20 Nov 2017 00:37:36 -0800 (PST) X-Google-Smtp-Source: AGs4zMYSjAu6dP6EcXYqwXoeLV4fl0bMieRI5cCO8Xr3mBro4L4vS+ZT7vEExATi3qAn2UIFJiRh X-Received: by 10.101.100.148 with SMTP id e20mr12890401pgv.248.1511167056091; Mon, 20 Nov 2017 00:37:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511167056; cv=none; d=google.com; s=arc-20160816; b=r3ucRn3ZXQPouIDMv2DhCDvkCzlJga7Z+QlBqR/z4r/7vVGDky6vwPQUafkWz8cYyZ dPRWuhnyWY0eq1IqQhJqfk0mDuHijko0U6GCTknsh8jJTHLN8YyHQvZk3MXi6pmwpqxd 5wNWqcjRw6TLE/tMfxfu8kmzkYuBoroQJYa8uF9LHP6iFSYRC81abPwBEC2AdHMFlxvF 6j+lOVGGr17ddwLCaq/lMwwEj/KMva+qdXG5dpfjF0KnWdc9inLwnUXwFvFVuZscxyAX 7hLix3O13Rbq42BZjPhGo6UjIosIszZDFDipNMtl5sSazXq0e0Qprw6tAcXHzAWfmYsL Cr9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=u/EAqTfEeH4+2pMDbzfuazdCWvwiIK+BmOqRF/s0peI=; b=xX0lbuK3Tt0/OD/Epb5f8JwsNlODWuHbt9OgqZfQnetPQfUk0SXEfOMPl1BnZ8UDCb jRJE/gGpwgSEfejV1Qnw2pXnIhSPZDJvXZUb/slsxl9SBz7c/K/bgFFq8KaK//zPq15X FtSaJPPVtRjmVA5Ar7Uz8NqDcdkMjT3AOfyy2+AREjnqcfssdmOEC57b4rzrXHe81OnN unXwUyxK2cq/3fPbomNVbBO46DpgBhbBwnk1mkDyFZmO1VyhEv+oE9I/GynB5/kXhNrz FSLQYhzFSravswLQzCPAWX2yppTUpGlyNmVRMc9ysgMKioXfhjWu/7RIzTMyDhfXD/Lr HghQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si7764474plg.615.2017.11.20.00.37.25; Mon, 20 Nov 2017 00:37:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751253AbdKTIgZ (ORCPT + 68 others); Mon, 20 Nov 2017 03:36:25 -0500 Received: from relay14.alfahosting-server.de ([109.237.142.228]:23631 "EHLO relay14.alfahosting-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751138AbdKTIfg (ORCPT ); Mon, 20 Nov 2017 03:35:36 -0500 Received: by relay01.alfahosting-server.de (Postfix, from userid 1001) id 8AADB32C3209; Mon, 20 Nov 2017 09:35:34 +0100 (CET) X-Spam-DCC: : X-Spam-Level: X-Spam-Status: No, score=-1000.0 required=7.0 tests=BAYES_50,D_SENT_WITH_SASL autolearn=disabled version=3.2.5 Received: from alfa3028.alfahosting-server.de (alfa3028.alfahosting-server.de [109.237.138.38]) by relay01.alfahosting-server.de (Postfix) with ESMTPS id 6C2B032C3207; Mon, 20 Nov 2017 09:35:32 +0100 (CET) Received: from localhost.localdomain (unknown [91.230.2.244]) (Authenticated sender: yes) by alfa3028.alfahosting-server.de (Postfix) with ESMTPA id 32692430D437; Mon, 20 Nov 2017 09:35:32 +0100 (CET) From: Richard Leitner To: f.fainelli@gmail.com, fugang.duan@nxp.com, andrew@lunn.ch Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, richard.leitner@skidata.com Subject: [PATCH v2 3/3] net: ethernet: fec: fix refclk enable for SMSC LAN8710/20 Date: Mon, 20 Nov 2017 09:34:17 +0100 Message-Id: <20171120083417.32558-4-dev@g0hl1n.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171120083417.32558-1-dev@g0hl1n.net> References: <20171120083417.32558-1-dev@g0hl1n.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Leitner Some PHYs (for example the SMSC LAN8710/LAN8720) doesn't allow turning the refclk on and off again during operation (according to their datasheet). Nonetheless exactly this behaviour was introduced for power saving reasons by commit e8fcfcd5684a ("net: fec: optimize the clock management to save power"). Therefore after enabling the refclk we detect if an affected PHY is attached. If so reset and initialize it again. For a better understanding here's a outline of the time response of the clock and reset lines before and after this patch: v--fec_probe() v--fec_enet_open() v v w/o patch eCLK: ___||||||||____________________||||||||||||||||| w/o patch nRST: ----__------------------------------------------ w/o patch CONF: _______XX_______________________________________ w/ patch eCLK: ___||||||||____________________||||||||||||||||| w/ patch nRST: ----__-----------------------------__----------- w/ patch CONF: _______XX_____________________________XX________ ^ ^ ^--fec_probe() ^--fec_enet_open() Generally speaking this issue is only relevant if the ref clk for the PHY is generated by the SoC. In our specific case (PCB) this problem does occur at about every 10th to 50th POR of an LAN8710 connected to an i.MX6DL SoC. The typical symptom of this problem is a "swinging" ethernet link. Similar issues were reported by users of the NXP forum: https://community.nxp.com/thread/389902 https://community.nxp.com/message/309354 With this patch applied the issue didn't occur for at least a few hundret PORs of our board. Fixes: e8fcfcd5684a ("net: fec: optimize the clock management to save power") Signed-off-by: Richard Leitner --- drivers/net/ethernet/freescale/fec_main.c | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 06a7caca0cee..52ec9b29a70e 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -68,6 +68,7 @@ static void set_multicast_list(struct net_device *ndev); static void fec_enet_itr_coal_init(struct net_device *ndev); +static int fec_reset_phy(struct net_device *ndev); #define DRIVER_NAME "fec" @@ -1833,6 +1834,32 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum, return ret; } +static int fec_enet_clk_ref_enable_reset_phy_quirk(struct net_device *ndev) +{ + struct phy_device *phy_dev = ndev->phydev; + u32 real_phy_id; + int ret; + + /* some PHYs need a reset after the refclk was enabled, so we + * reset them here + */ + if (!phy_dev) + return 0; + if (!phy_dev->drv) + return 0; + real_phy_id = phy_dev->drv->phy_id & phy_dev->drv->phy_id_mask; + switch (real_phy_id) { + case 0x0007c0f0: /* SMSC LAN8710/LAN8720 */ + ret = fec_reset_phy(ndev); + if (ret) + return ret; + ret = phy_init_hw(phy_dev); + if (ret) + return ret; + } + return 0; +} + static int fec_enet_clk_enable(struct net_device *ndev, bool enable) { struct fec_enet_private *fep = netdev_priv(ndev); @@ -1862,6 +1889,10 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable) ret = clk_prepare_enable(fep->clk_ref); if (ret) goto failed_clk_ref; + + ret = fec_enet_clk_ref_enable_reset_phy_quirk(ndev); + if (ret) + netdev_warn(ndev, "Resetting PHY failed, connection may be unstable\n"); } else { clk_disable_unprepare(fep->clk_ahb); clk_disable_unprepare(fep->clk_enet_out); @@ -2860,11 +2891,17 @@ fec_enet_open(struct net_device *ndev) if (ret) goto err_enet_mii_probe; + /* as the PHY is connected now, trigger the reset quirk again */ + ret = fec_enet_clk_ref_enable_reset_phy_quirk(ndev); + if (ret) + netdev_warn(ndev, "Resetting PHY failed, connection may be unstable\n"); + if (fep->quirks & FEC_QUIRK_ERR006687) imx6q_cpuidle_fec_irqs_used(); napi_enable(&fep->napi); phy_start(ndev->phydev); + netif_tx_start_all_queues(ndev); device_set_wakeup_enable(&ndev->dev, fep->wol_flag & -- 2.11.0 From 1584573446575200827@xxx Mon Nov 20 08:36:38 +0000 2017 X-GM-THRID: 1584573446575200827 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread