Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbdGGFas (ORCPT ); Fri, 7 Jul 2017 01:30:48 -0400 Received: from mail-eopbgr20048.outbound.protection.outlook.com ([40.107.2.48]:63485 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752258AbdGGFap (ORCPT ); Fri, 7 Jul 2017 01:30:45 -0400 From: Andy Duan To: Richard Leitner , "robh+dt@kernel.org" , "mark.rutland@arm.com" CC: "netdev@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "dev@g0hl1n.net" Subject: RE: [PATCH 2/2] net: ethernet: fsl: add phy reset after clk enable option Thread-Topic: [PATCH 2/2] net: ethernet: fsl: add phy reset after clk enable option Thread-Index: AQHS9liVhz49Jf19SE+3rJ5oc5evWaJH0raA Date: Fri, 7 Jul 2017 05:30:41 +0000 Message-ID: References: <1499346330-12166-1-git-send-email-richard.leitner@skidata.com> <1499346330-12166-2-git-send-email-richard.leitner@skidata.com> In-Reply-To: <1499346330-12166-2-git-send-email-richard.leitner@skidata.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: skidata.com; dkim=none (message not signed) header.d=none;skidata.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [199.59.231.64] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM4PR0401MB2257;7:gCGqWgCbeeZAoZ60cGrSGnXmIAOl6il32WH1kajHG3MriJGjsnyrz6girotHXUXpCmv+hWUiUMgbcvrvGzSb5r3IMP1sJkq22ep9sHeM8iO2e7laefm+3b1wvp5kF1iSZbrLICciBCupZMYdHGt/AoU7SgYr7vZdQBykPjBMfk/duDkDUru+fnUq7vSNpJq2rUrHr6LZJHGtRRfu21qTJQHjSfUTEomK9uNp5K/SsXpMloymHGHXNrafF0gKsPEQ4g8aGE8kqF6oeaE45w3CpCMeccCNvoPB08eaCurZZfjafgLwmmSKCCo78B0eU6jqyObpAdL28wI5EoE4O/A0EDuzn3TmamdL9cZl6dITwi9ZUkrxGATAfelhHjdfJWKc45vteKveEX2epOWaTJjLI7QdZcPJ02Y+970mlU1UO7aFfrkrgThyeOWejejBn+of9q+OKKOjwHkFWWrBV7MlSGj8FS6htGpn4VgD0NKzifRm0GLfbw2gT1S+Jz9noGCakYyPujrfADIeA49Rm9lPAGvj3ENcEhE+XLjaLGc/AJKLfjZSY/7pra6OcryWcuf1H89hbnj1Df1vcAcV+78Yu44YvXr8tDCrjNyGlF/asBTdUPVwzKkx4IzTKGQ6Qx+QCtoRwJgJtE7dnntI0V03FxqxGe6DJTluYwVY83FBd9kjt8AN/bGYJwlK5rVlsMoKGLtgTbqL5/2JukInBjjKfcapJOuAqz6gZW/VqJ2FS2KM2FZiz79q6bYUhReYrYC+FbNByLEkwWgpxxxl7YOZiHTXZNcaX+7pN9YyzqPSjoc= x-ms-office365-filtering-correlation-id: abb56ee3-f38b-4111-131b-08d4c4f94f24 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:AM4PR0401MB2257; x-ms-traffictypediagnostic: AM4PR0401MB2257: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(236129657087228)(9452136761055)(185117386973197); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910058)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(20161123562025)(6072148)(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: 0361212EA8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39450400003)(39410400002)(39860400002)(39400400002)(39850400002)(39840400002)(377454003)(102836003)(3846002)(6116002)(66066001)(33656002)(81166006)(7736002)(8676002)(478600001)(76176999)(8936002)(50986999)(54356999)(14454004)(6306002)(5250100002)(38730400002)(6246003)(99286003)(54906002)(55016002)(9686003)(86362001)(6506006)(575784001)(25786009)(2501003)(305945005)(229853002)(74316002)(2900100001)(2950100002)(189998001)(5660300001)(3280700002)(3660700001)(7696004)(53936002)(6436002)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR0401MB2257;H:AM4PR0401MB2260.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;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-originalarrivaltime: 07 Jul 2017 05:30:41.8746 (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 v675UqaM028642 Content-Length: 5641 Lines: 152 From: Richard Leitner Sent: Thursday, July 06, 2017 9:06 PM >To: Andy Duan ; robh+dt@kernel.org; >mark.rutland@arm.com >Cc: netdev@vger.kernel.org; devicetree@vger.kernel.org; linux- >kernel@vger.kernel.org; dev@g0hl1n.net; Richard Leitner > >Subject: [PATCH 2/2] net: ethernet: fsl: add phy reset after clk enable option > >Some PHYs (for example the LAN8710) doesn't allow turning the clocks off and >on again without reset (according to their datasheet). Exactly this behaviour >was introduced for power saving reasons by commit e8fcfcd5684a >("net: fec: optimize the clock management to save power") Therefore add a >devictree option to perform a PHY reset and configuration after every clock >enable. > >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() > >In our case this problem does occur at about every 10th to 50th POR of an >LAN8710 connected to an i.MX6 SoC. The typical symptom of this problem is a >"swinging" ethernet link. Similar issues were experienced 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 hundred PORs >of our board. > >Fixes: e8fcfcd5684a ("net: fec: optimize the clock management to sa...") >Signed-off-by: Richard Leitner >--- > Documentation/devicetree/bindings/net/fsl-fec.txt | 3 +++ > drivers/net/ethernet/freescale/fec.h | 1 + > drivers/net/ethernet/freescale/fec_main.c | 16 ++++++++++++++++ > 3 files changed, 20 insertions(+) > >diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt >b/Documentation/devicetree/bindings/net/fsl-fec.txt >index 6f55bdd..1766579 100644 >--- a/Documentation/devicetree/bindings/net/fsl-fec.txt >+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt >@@ -23,6 +23,9 @@ Optional properties: > - phy-handle : phandle to the PHY device connected to this device. > - fixed-link : Assume a fixed link. See fixed-link.txt in the same directory. > Use instead of phy-handle. >+- phy-reset-after-clk-enable : If present then a phy reset and >+configuration >+ will be performed everytime after the clocks are enabled. This is >+required >+ for some PHYs to work properly. > - fsl,num-tx-queues : The property is valid for enet-avb IP, which supports > hw multi queues. Should specify the tx queue number, otherwise set tx >queue > number to 1. >diff --git a/drivers/net/ethernet/freescale/fec.h >b/drivers/net/ethernet/freescale/fec.h >index 3da8084..d4f658a 100644 >--- a/drivers/net/ethernet/freescale/fec.h >+++ b/drivers/net/ethernet/freescale/fec.h >@@ -538,6 +538,7 @@ struct fec_enet_private { > int phy_reset_duration; > int phy_reset_post_delay; > bool phy_reset_active_high; >+ bool phy_reset_after_clk_enable; > > struct napi_struct napi; > int csum_flags; >diff --git a/drivers/net/ethernet/freescale/fec_main.c >b/drivers/net/ethernet/freescale/fec_main.c >index cbbf7b8..4e744f3 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" > >@@ -1862,6 +1863,18 @@ 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; >+ >+ /* reset the phy after clk is enabled if it's configured */ >+ if (fep->phy_reset_after_clk_enable) { >+ ret = fec_reset_phy(ndev); >+ if (ret) >+ goto failed_reset; >+ if (ndev->phydev) { >+ ret = phy_init_hw(ndev->phydev); >+ if (ret) >+ goto failed_reset; >+ } >+ } Since it is common issue so long as using the PHY, can you move it into smsc phy driver like in .smsc_phy_reset() function ? And get the reset pin from phy dts node. Andy > } else { > clk_disable_unprepare(fep->clk_ahb); > clk_disable_unprepare(fep->clk_enet_out); >@@ -1876,6 +1889,7 @@ static int fec_enet_clk_enable(struct net_device >*ndev, bool enable) > > return 0; > >+failed_reset: > failed_clk_ref: > if (fep->clk_ref) > clk_disable_unprepare(fep->clk_ref); >@@ -3350,6 +3364,7 @@ fec_probe(struct platform_device *pdev) > fep->phy_reset_post_delay = 1; > > fep->phy_reset_active_high = of_property_read_bool(np, >"phy-reset-active-high"); >+ fep->phy_reset_after_clk_enable = >of_property_read_bool(np, >+"phy-reset-after-clk-enable"); > > ret = devm_gpio_request_one(&pdev->dev, fep->phy_reset, > fep->phy_reset_active_high ? >GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, @@ -3360,6 +3375,7 @@ >fec_probe(struct platform_device *pdev) > } > } else { > fep->phy_reset = 0; >+ fep->phy_reset_after_clk_enable = false; > } > > ret = of_get_phy_mode(pdev->dev.of_node); >-- >2.1.4