Patchwork netdev/fec: fix ifconfig eth0 down hang issue

login
register
mail settings
Submitter Bryan Wu
Date April 19, 2010, 10:29 a.m.
Message ID <1271672981-6748-1-git-send-email-bryan.wu@canonical.com>
Download mbox | patch
Permalink /patch/50440/
State Superseded
Delegated to: Andy Whitcroft
Headers show

Comments

Bryan Wu - April 19, 2010, 10:29 a.m.
BugLink: http://bugs.launchpad.net/bugs/559065

In ethernet connection open/close function, we need to use phy_connect
and phy_disconnect operation before we start/stop phy. Otherwise it will
cause system hang. Also suspend/resume needs the same fix.

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/net/fec.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
Bryan Wu - April 19, 2010, 10:32 a.m.
Andy and Stephan:

This patch is OK for both Karmic and Lucid.

Thanks,
-Bryan


Bryan Wu wrote:
> BugLink: http://bugs.launchpad.net/bugs/559065
>
> In ethernet connection open/close function, we need to use phy_connect
> and phy_disconnect operation before we start/stop phy. Otherwise it will
> cause system hang. Also suspend/resume needs the same fix.
>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/net/fec.c |   15 +++++++++++++--
>  1 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 2280373..8953379 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -929,7 +929,10 @@ fec_enet_open(struct net_device *dev)
>  		return ret;
>  
>  	/* schedule a link state check */
> -	phy_start(fep->phy_dev);
> +	fec_enet_mii_probe(dev);
> +	if (fep->phy_dev)
> +		phy_start(fep->phy_dev);
> +
>  	netif_start_queue(dev);
>  	fep->opened = 1;
>  	return 0;
> @@ -942,10 +945,13 @@ fec_enet_close(struct net_device *dev)
>  
>  	/* Don't know what to do yet. */
>  	fep->opened = 0;
> -	phy_stop(fep->phy_dev);
>  	netif_stop_queue(dev);
> +
>  	fec_stop(dev);
>  
> +	if (fep->phy_dev)
> +		phy_disconnect(fep->phy_dev);
> +
>          fec_enet_free_buffers(dev);
>  	clk_disable(fep->clk);
>  
> @@ -1396,6 +1402,8 @@ fec_suspend(struct platform_device *dev, pm_message_t state)
>  		fep = netdev_priv(ndev);
>  		if (netif_running(ndev)) {
>  			netif_device_detach(ndev);
> +			if (fep->phy_dev)
> +				phy_disconnect(fep->phy_dev);
>  			fec_stop(ndev);
>  			clk_disable(fep->clk);
>  		}
> @@ -1415,6 +1423,9 @@ fec_resume(struct platform_device *dev)
>  		if (netif_running(ndev)) {
>  			clk_enable(fep->clk);
>  			fec_restart(ndev, 1);
> +			fec_enet_mii_probe(dev);
> +			if (fep->phy_dev)
> +				phy_start(fep->phy_dev);
>  			netif_device_attach(ndev);
>  		}
>  	}
>
Tim Gardner - April 19, 2010, 2:04 p.m.
On 04/19/2010 04:29 AM, Bryan Wu wrote:
> BugLink: http://bugs.launchpad.net/bugs/559065
>
> In ethernet connection open/close function, we need to use phy_connect
> and phy_disconnect operation before we start/stop phy. Otherwise it will
> cause system hang. Also suspend/resume needs the same fix.
>
> Signed-off-by: Bryan Wu<bryan.wu@canonical.com>
> ---
>   drivers/net/fec.c |   15 +++++++++++++--
>   1 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 2280373..8953379 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -929,7 +929,10 @@ fec_enet_open(struct net_device *dev)
>   		return ret;
>
>   	/* schedule a link state check */
> -	phy_start(fep->phy_dev);
> +	fec_enet_mii_probe(dev);
> +	if (fep->phy_dev)
> +		phy_start(fep->phy_dev);
> +

Why would you continue the open if fec_enet_mii_probe() fails to connect 
to a phy_dev ? If you exit with an error here, then you won't have to 
check for 'if (fep->phy_dev)' later on.

>   	netif_start_queue(dev);
>   	fep->opened = 1;
>   	return 0;
> @@ -942,10 +945,13 @@ fec_enet_close(struct net_device *dev)
>
>   	/* Don't know what to do yet. */
>   	fep->opened = 0;
> -	phy_stop(fep->phy_dev);
>   	netif_stop_queue(dev);
> +
>   	fec_stop(dev);
>
> +	if (fep->phy_dev)
> +		phy_disconnect(fep->phy_dev);
> +
>           fec_enet_free_buffers(dev);
>   	clk_disable(fep->clk);
>
> @@ -1396,6 +1402,8 @@ fec_suspend(struct platform_device *dev, pm_message_t state)
>   		fep = netdev_priv(ndev);
>   		if (netif_running(ndev)) {
>   			netif_device_detach(ndev);
> +			if (fep->phy_dev)
> +				phy_disconnect(fep->phy_dev);
>   			fec_stop(ndev);
>   			clk_disable(fep->clk);
>   		}
> @@ -1415,6 +1423,9 @@ fec_resume(struct platform_device *dev)
>   		if (netif_running(ndev)) {
>   			clk_enable(fep->clk);
>   			fec_restart(ndev, 1);
> +			fec_enet_mii_probe(dev);
> +			if (fep->phy_dev)
> +				phy_start(fep->phy_dev);
>   			netif_device_attach(ndev);
>   		}
>   	}

rtg

Patch

diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 2280373..8953379 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -929,7 +929,10 @@  fec_enet_open(struct net_device *dev)
 		return ret;
 
 	/* schedule a link state check */
-	phy_start(fep->phy_dev);
+	fec_enet_mii_probe(dev);
+	if (fep->phy_dev)
+		phy_start(fep->phy_dev);
+
 	netif_start_queue(dev);
 	fep->opened = 1;
 	return 0;
@@ -942,10 +945,13 @@  fec_enet_close(struct net_device *dev)
 
 	/* Don't know what to do yet. */
 	fep->opened = 0;
-	phy_stop(fep->phy_dev);
 	netif_stop_queue(dev);
+
 	fec_stop(dev);
 
+	if (fep->phy_dev)
+		phy_disconnect(fep->phy_dev);
+
         fec_enet_free_buffers(dev);
 	clk_disable(fep->clk);
 
@@ -1396,6 +1402,8 @@  fec_suspend(struct platform_device *dev, pm_message_t state)
 		fep = netdev_priv(ndev);
 		if (netif_running(ndev)) {
 			netif_device_detach(ndev);
+			if (fep->phy_dev)
+				phy_disconnect(fep->phy_dev);
 			fec_stop(ndev);
 			clk_disable(fep->clk);
 		}
@@ -1415,6 +1423,9 @@  fec_resume(struct platform_device *dev)
 		if (netif_running(ndev)) {
 			clk_enable(fep->clk);
 			fec_restart(ndev, 1);
+			fec_enet_mii_probe(dev);
+			if (fep->phy_dev)
+				phy_start(fep->phy_dev);
 			netif_device_attach(ndev);
 		}
 	}