Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755614AbbLACcJ (ORCPT ); Mon, 30 Nov 2015 21:32:09 -0500 Received: from mail-by2on0117.outbound.protection.outlook.com ([207.46.100.117]:55338 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755445AbbLACbx (ORCPT ); Mon, 30 Nov 2015 21:31:53 -0500 X-Greylist: delayed 88254 seconds by postgrey-1.27 at vger.kernel.org; Mon, 30 Nov 2015 21:31:53 EST From: Duan Andy To: =?utf-8?B?TG90aGFyIFdhw59tYW5u?= , Andrew Lunn , "David S. Miller" , Fabio Estevam , Greg Ungerer , Kevin Hao , Lucas Stach , Philippe Reynes , Richard Cochran , Russell King , Sascha Hauer , "Stefan Agner" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , Jeff Kirsher , "Uwe Kleine-K?nig" Subject: RE: [PATCH 3/3] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Thread-Topic: [PATCH 3/3] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Thread-Index: AQHRK2LoHYelbxGpF0eFbLH6uzIG+561ZhTQ Date: Tue, 1 Dec 2015 02:31:50 +0000 Message-ID: References: <1448883168-30742-1-git-send-email-LW@KARO-electronics.de> <1448883168-30742-2-git-send-email-LW@KARO-electronics.de> <1448883168-30742-3-git-send-email-LW@KARO-electronics.de> <1448883168-30742-4-git-send-email-LW@KARO-electronics.de> In-Reply-To: <1448883168-30742-4-git-send-email-LW@KARO-electronics.de> Accept-Language: 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@freescale.com; x-originating-ip: [123.151.195.51] x-microsoft-exchange-diagnostics: 1;BLUPR03MB1425;5:lSuKMFRPh5qGlszf55cUoLBuXkPFbUfwi9Bx/sO5SiUQgA4qfJuWDdvbFcqrfsK7LxLnN1xxgwcbvpZ9Kwt2PIT7Nso/5Q7/egvwbKXI5S59PTyaYNkquSoE28YnK4wvkcMDGcnd/1zrp/TS40KEGw==;24:eP/8GXNsqVn1P/eG8uposi0uwOXj6FeCsPuZprpLOwVJTl00aoDGr04Khq/e5KT/zeBU/9v7kbZjxAeYeKG/jLV0LCRmmigkNqEsyLFMLx4= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1425; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001)(10201501046);SRVR:BLUPR03MB1425;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1425; x-forefront-prvs: 07778E4001 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(377454003)(99286002)(107886002)(86362001)(106356001)(93886004)(5001770100001)(19580405001)(105586002)(2900100001)(77096005)(50986999)(1096002)(92566002)(97736004)(2201001)(6116002)(586003)(40100003)(122556002)(189998001)(5001960100002)(76576001)(19580395003)(5004730100002)(5003600100002)(11100500001)(2950100001)(5002640100001)(3846002)(2501003)(102836003)(81156007)(10400500002)(74316001)(101416001)(66066001)(76176999)(33656002)(54356999)(87936001)(1220700001)(5008740100001)(106116001)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB1425;H:BN3PR0301MB1219.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2015 02:31:50.3738 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1425 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 base64 to 8bit by mail.home.local id tB12WMSe024322 Content-Length: 5115 Lines: 150 From: Lothar Waßmann Sent: Monday, November 30, 2015 7:33 PM > To: Andrew Lunn; David S. Miller; Estevam Fabio-R49496; Greg Ungerer; > Kevin Hao; Lothar Waßmann; Lucas Stach; Duan Fugang-B38611; Philippe > Reynes; Richard Cochran; Russell King; Sascha Hauer; Stefan Agner; linux- > kernel@vger.kernel.org; netdev@vger.kernel.org; Jeff Kirsher; Uwe Kleine- > König > Subject: [PATCH 3/3] net: fec: Reset ethernet PHY whenever the enet_out > clock is being enabled > > If a PHY uses ENET_OUT as reference clock, it may need a RESET to get > functional after the clock had been disabled. > > Failure to do this results in the link state constantly toggling between > up and down: > fec 02188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control > rx/tx fec 02188000.ethernet eth0: Link is Down fec 02188000.ethernet eth0: > Link is Up - 100Mbps/Full - flow control rx/tx fec 02188000.ethernet eth0: > Link is Down [...] > > Signed-off-by: Lothar Waßmann > --- > drivers/net/ethernet/freescale/fec.h | 1 + > drivers/net/ethernet/freescale/fec_main.c | 46 ++++++++++++++++++++++++- > ------ > 2 files changed, 37 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/ethernet/freescale/fec.h > b/drivers/net/ethernet/freescale/fec.h > index 99d33e2..8ab4f7f 100644 > --- a/drivers/net/ethernet/freescale/fec.h > +++ b/drivers/net/ethernet/freescale/fec.h > @@ -519,6 +519,7 @@ struct fec_enet_private { > int pause_flag; > int wol_flag; > u32 quirks; > + struct gpio_desc *phy_reset; > > 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 1a983fc..7ba2bbb 100644 > --- a/drivers/net/ethernet/freescale/fec_main.c > +++ b/drivers/net/ethernet/freescale/fec_main.c > @@ -66,6 +66,7 @@ > > static void set_multicast_list(struct net_device *ndev); static void > fec_enet_itr_coal_init(struct net_device *ndev); > +static void fec_reset_phy(struct platform_device *pdev); > > #define DRIVER_NAME "fec" > > @@ -1861,6 +1862,8 @@ static int fec_enet_clk_enable(struct net_device > *ndev, bool enable) > ret = clk_prepare_enable(fep->clk_enet_out); > if (ret) > goto failed_clk_enet_out; > + > + fec_reset_phy(fep->pdev); > } > if (fep->clk_ptp) { > mutex_lock(&fep->ptp_clk_mutex); > @@ -3231,13 +3234,32 @@ static int fec_enet_init(struct net_device > *ndev) } > > #ifdef CONFIG_OF > -static void fec_reset_phy(struct platform_device *pdev) > +static struct gpio_desc *fec_get_reset_gpio(struct platform_device > +*pdev) > { > struct gpio_desc *phy_reset; > - int msec = 1; > struct device_node *np = pdev->dev.of_node; > > if (!np) > + return ERR_PTR(-ENODEV); No need to check device node. > + > + phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset", > + GPIOD_OUT_LOW); > + if (IS_ERR(phy_reset)) > + dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n", > + PTR_ERR(phy_reset)); > + return phy_reset; > +} > + > +static void fec_reset_phy(struct platform_device *pdev) { > + struct device_node *np = pdev->dev.of_node; > + struct net_device *ndev = platform_get_drvdata(pdev); > + struct fec_enet_private *fep = netdev_priv(ndev); > + int msec = 1; > + > + if (!fep->phy_reset) > + return; > + if (!np) > return; No need to check device node. > > of_property_read_u32(np, "phy-reset-duration", &msec); @@ -3245,17 > +3267,16 @@ static void fec_reset_phy(struct platform_device *pdev) > if (msec > 1000) > msec = 1; > > - phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset", > - GPIOD_OUT_LOW); > - if (IS_ERR(phy_reset)) { > - dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n", > - PTR_ERR(phy_reset)); > - return; > - } > + gpiod_set_value_cansleep(fep->phy_reset, 0); > msleep(msec); > - gpiod_set_value_cansleep(phy_reset, 1); > + gpiod_set_value_cansleep(fep->phy_reset, 1); > } > #else /* CONFIG_OF */ > +static void fec_get_reset_gpio(struct platform_device *pdev) { > + return -EINVAL; > +} > + > static void fec_reset_phy(struct platform_device *pdev) { > /* > @@ -3309,8 +3330,12 @@ fec_probe(struct platform_device *pdev) > struct device_node *np = pdev->dev.of_node, *phy_node; > int num_tx_qs; > int num_rx_qs; > + struct gpio_desc *phy_reset; > > fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs); > + phy_reset = fec_get_reset_gpio(pdev); > + if (IS_ERR(phy_reset) && PTR_ERR(phy_reset) == -EPROBE_DEFER) > + return -EPROBE_DEFER; > > /* Init network device */ > ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private), @@ - > 3331,6 +3356,7 @@ fec_probe(struct platform_device *pdev) > fep->netdev = ndev; > fep->num_rx_queues = num_rx_qs; > fep->num_tx_queues = num_tx_qs; > + fep->phy_reset = phy_reset; > > #if !defined(CONFIG_M5272) > /* default enable pause frame auto negotiation */ > -- > 2.1.4 ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?