Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [net-next PATCH v2] net: gemini: Clean up phy registration
@ 2020-09-05 20:42 Linus Walleij
  2020-09-06 14:39 ` Andrew Lunn
  2020-09-06 17:25 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Linus Walleij @ 2020-09-05 20:42 UTC (permalink / raw)
  To: netdev, David S . Miller; +Cc: Hans Ulli Kroll, Linus Walleij, Andrew Lunn

It's nice if the phy is online before we register the netdev
so try to do that first.

Stop trying to do "second tried" to register the phy, it
works perfectly fine the first time.

Stop remvoving the phy in uninit. Remove it when the
driver is remove():d, symmetric to where it is added, in
probe().

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Reported-by: David Miller <davem@davemloft.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Do a deeper clean-up and remove the confusion around
  how the phy is registered.
---
 drivers/net/ethernet/cortina/gemini.c | 32 +++++++++------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index ffec0f3dd957..94707c9dda88 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -539,12 +539,6 @@ static int gmac_init(struct net_device *netdev)
 	return 0;
 }
 
-static void gmac_uninit(struct net_device *netdev)
-{
-	if (netdev->phydev)
-		phy_disconnect(netdev->phydev);
-}
-
 static int gmac_setup_txqs(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -1768,15 +1762,6 @@ static int gmac_open(struct net_device *netdev)
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	int err;
 
-	if (!netdev->phydev) {
-		err = gmac_setup_phy(netdev);
-		if (err) {
-			netif_err(port, ifup, netdev,
-				  "PHY init failed: %d\n", err);
-			return err;
-		}
-	}
-
 	err = request_irq(netdev->irq, gmac_irq,
 			  IRQF_SHARED, netdev->name, netdev);
 	if (err) {
@@ -2209,7 +2194,6 @@ static void gmac_get_drvinfo(struct net_device *netdev,
 
 static const struct net_device_ops gmac_351x_ops = {
 	.ndo_init		= gmac_init,
-	.ndo_uninit		= gmac_uninit,
 	.ndo_open		= gmac_open,
 	.ndo_stop		= gmac_stop,
 	.ndo_start_xmit		= gmac_start_xmit,
@@ -2295,8 +2279,10 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 
 static void gemini_port_remove(struct gemini_ethernet_port *port)
 {
-	if (port->netdev)
+	if (port->netdev) {
+		phy_disconnect(port->netdev->phydev);
 		unregister_netdev(port->netdev);
+	}
 	clk_disable_unprepare(port->pclk);
 	geth_cleanup_freeq(port->geth);
 }
@@ -2505,6 +2491,13 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	if (ret)
 		goto unprepare;
 
+	ret = gmac_setup_phy(netdev);
+	if (ret) {
+		netdev_err(netdev,
+			   "PHY init failed\n");
+		return ret;
+	}
+
 	ret = register_netdev(netdev);
 	if (ret)
 		goto unprepare;
@@ -2513,10 +2506,6 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 		    "irq %d, DMA @ 0x%pap, GMAC @ 0x%pap\n",
 		    port->irq, &dmares->start,
 		    &gmacres->start);
-	ret = gmac_setup_phy(netdev);
-	if (ret)
-		netdev_info(netdev,
-			    "PHY init failed, deferring to ifup time\n");
 	return 0;
 
 unprepare:
@@ -2529,6 +2518,7 @@ static int gemini_ethernet_port_remove(struct platform_device *pdev)
 	struct gemini_ethernet_port *port = platform_get_drvdata(pdev);
 
 	gemini_port_remove(port);
+
 	return 0;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net-next PATCH v2] net: gemini: Clean up phy registration
  2020-09-05 20:42 [net-next PATCH v2] net: gemini: Clean up phy registration Linus Walleij
@ 2020-09-06 14:39 ` Andrew Lunn
  2020-09-06 17:25 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2020-09-06 14:39 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Hans Ulli Kroll

On Sat, Sep 05, 2020 at 10:42:57PM +0200, Linus Walleij wrote:
> It's nice if the phy is online before we register the netdev
> so try to do that first.
> 
> Stop trying to do "second tried" to register the phy, it
> works perfectly fine the first time.
> 
> Stop remvoving the phy in uninit. Remove it when the
> driver is remove():d, symmetric to where it is added, in
> probe().
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Reported-by: David Miller <davem@davemloft.net>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net-next PATCH v2] net: gemini: Clean up phy registration
  2020-09-05 20:42 [net-next PATCH v2] net: gemini: Clean up phy registration Linus Walleij
  2020-09-06 14:39 ` Andrew Lunn
@ 2020-09-06 17:25 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2020-09-06 17:25 UTC (permalink / raw)
  To: Linus Walleij; +Cc: netdev, David S . Miller, Hans Ulli Kroll, Andrew Lunn

On Sat,  5 Sep 2020 22:42:57 +0200 Linus Walleij wrote:
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index ffec0f3dd957..94707c9dda88 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

> @@ -2505,6 +2491,13 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto unprepare;
>  
> +	ret = gmac_setup_phy(netdev);
> +	if (ret) {
> +		netdev_err(netdev,
> +			   "PHY init failed\n");
> +		return ret;

goto unprepare?

> +	}
> +
>  	ret = register_netdev(netdev);
>  	if (ret)
>  		goto unprepare;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-06 17:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 20:42 [net-next PATCH v2] net: gemini: Clean up phy registration Linus Walleij
2020-09-06 14:39 ` Andrew Lunn
2020-09-06 17:25 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).