diff mbox series

[net-next,v2] net: gemini: Clean up phy registration

Message ID 20200905204257.51044-1-linus.walleij@linaro.org
State Superseded
Headers show
Series [net-next,v2] net: gemini: Clean up phy registration | expand

Commit Message

Linus Walleij Sept. 5, 2020, 8:42 p.m. UTC
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(-)

-- 
2.26.2

Comments

Andrew Lunn Sept. 6, 2020, 2:39 p.m. UTC | #1
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
Jakub Kicinski Sept. 6, 2020, 5:25 p.m. UTC | #2
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;
diff mbox series

Patch

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;
 }