From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751145AbdKTJrc (ORCPT ); Mon, 20 Nov 2017 04:47:32 -0500 Received: from mail-he1eur01on0072.outbound.protection.outlook.com ([104.47.0.72]:4992 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750932AbdKTJra (ORCPT ); Mon, 20 Nov 2017 04:47:30 -0500 From: Andy Duan To: Richard Leitner , "f.fainelli@gmail.com" , "andrew@lunn.ch" CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "richard.leitner@skidata.com" Subject: RE: [PATCH v2 3/3] net: ethernet: fec: fix refclk enable for SMSC LAN8710/20 Thread-Topic: [PATCH v2 3/3] net: ethernet: fec: fix refclk enable for SMSC LAN8710/20 Thread-Index: AQHTYdqLtDAETl+kAkyRZvb+CXISyKMdAmew Date: Mon, 20 Nov 2017 09:47:26 +0000 Message-ID: References: <20171120083417.32558-1-dev@g0hl1n.net> <20171120083417.32558-4-dev@g0hl1n.net> In-Reply-To: <20171120083417.32558-4-dev@g0hl1n.net> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=fugang.duan@nxp.com; x-originating-ip: [199.59.231.64] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM4PR0401MB2257;6:UN3j4s4ZWlIP1Blic8vNp/VOHZg/i1k1vciF7HgPZGvOEQIAqJ1e1XjjMeD+i8jdiSH0aL0hsgHEZhwXKeDKJzxE8iB6B50HXjLAq1foOd+j1wNE5ExUYhtEmYFA/FhqKkx/E1dG049xPLacwYEyJkx1+kcsjPnQLrxOokh2+0AAWJTseUj0C75llCaN9mYoZCQIpuMVsTdO596c4b6zZtK89CBCRsHi2hskTKQU7AaXGTrOOuzF631c1booTl7K2v9dixNISDWJKsWUWZ0ac4A0txaGRTLt+PVlskgwWWE7OyFVWqi7o6ale/fvNKYdoRMbdUA82DSNHYifozH8kJroc418S9ytex5MWP8haCM=;5:Q9MW8jDsvNrU684Te83q8D00i06T6PKI4BxiWdKjaisYsltwG+SX4qymEu9LyaBJyzePZrp4c6pw+0Mvbd0UKB9/0ZSMB6TpXO08cTwrPt3M8dY+SJePkAGOCpj+lcRPIjy4oIXHBrD1vz9b7XIjOXMfK24kM7pyBLjYnEB3VLE=;24:w6FZHmeZgS6Cn9jexCAsnrRTHzQgGRHzzJ3q7SpZMON9ZIpgZoQwIU7aTY4vzyC1PSEn63mu85BHty3Ao/j+SDuCqbLcH9P2UJ7AcSTfGHs=;7:wFwZZe5goEVzLOHs6ZC/k+WQgFu0igslUT5osqi9DlMgpBqvNFXgv9XsAJs6P0oXKW69vlBqQf4fqtq2xGf+zpmIimPDOo5NP2yL/x+whGrsTVXfC8Dgw50t2iEZ4zjXFoloTqoIsLnrV5LhEpn8bY4JvwDt5Z50utOCXtj51pqlzXDAKGWsG4C5rkkGdObef8MOW8RoC8G1zMwUc5XCBotyh5H8JtZWOejWoxevKIl9N048z2EGf4MFbHpZ7W0U x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 4d30406d-665d-4e3e-5a44-08d52ffbb578 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603258);SRVR:AM4PR0401MB2257; x-ms-traffictypediagnostic: AM4PR0401MB2257: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(189930954265078)(185117386973197)(45079756050767); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(3231022)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:AM4PR0401MB2257;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:AM4PR0401MB2257; x-forefront-prvs: 04976078F0 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(376002)(39860400002)(346002)(199003)(189002)(50986999)(106356001)(105586002)(33656002)(54356999)(76176999)(5890100001)(55016002)(2501003)(54906003)(110136005)(25786009)(8936002)(99286004)(478600001)(45080400002)(86362001)(6436002)(14454004)(316002)(7696004)(6506006)(575784001)(66066001)(101416001)(229853002)(68736007)(5660300001)(6246003)(6116002)(39060400002)(189998001)(2950100002)(53936002)(9686003)(6306002)(3660700001)(3280700002)(102836003)(3846002)(4326008)(2906002)(5250100002)(81166006)(81156014)(8676002)(74316002)(305945005)(2900100001)(2201001)(97736004)(7736002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR0401MB2257;H:AM4PR0401MB2260.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d30406d-665d-4e3e-5a44-08d52ffbb578 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Nov 2017 09:47:26.9872 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2257 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vAK9laxL019344 From: Richard Leitner Sent: Monday, November 20, 2017 4:34 PM >To: f.fainelli@gmail.com; Andy Duan ; >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 > >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://emea01.safelinks.protection.outlook.com/?url=https%3A%2F >%2Fcommunity.nxp.com%2Fthread%2F389902&data=02%7C01%7Cfugang.du >an%40nxp.com%7C507c7aafbd4744f81ebf08d52ff1acff%7C686ea1d3bc2b4c6f >a92cd99c5c301635%7C0%7C0%7C636467637399145483&sdata=RNXVGpPrlrcyL >0SoQl8%2BI0k8Oc8BM0Iwykd1O%2Bjmvcc%3D&reserved=0 > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F >%2Fcommunity.nxp.com%2Fmessage%2F309354&data=02%7C01%7Cfugang.d >uan%40nxp.com%7C507c7aafbd4744f81ebf08d52ff1acff%7C686ea1d3bc2b4c6 >fa92cd99c5c301635%7C0%7C0%7C636467637399145483&sdata=pjeJEZGuBpb9 >uCMKGr70qa%2FmsNoak6v3nCID2vbNAeg%3D&reserved=0 >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 */ Don't hard code here... I believe there have many other phys also do such operation, hardcode is unacceptable... And these code can be put into phy_device.c as common interface. >+ 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); >+ No need blank line here... > netif_tx_start_all_queues(ndev); > > device_set_wakeup_enable(&ndev->dev, fep->wol_flag & >-- >2.11.0