Skip to contentSkip to conversation

net: ethernet: cortina: support deferral

PATCH In review Rosen Penev 3 participants 5 messages Feb 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: ethernet: cortina: support deferral

When using nvmem, it may be necessary to defer probe until the specific nvmem driver is loaded to get the proper MAC.

Rosen Penev (2):
net: ethernet: cortina: use devm to enable clocks
net: ethernet: cortina: fix nvmem mac addresses

 drivers/net/ethernet/cortina/gemini.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

--
2.53.0

#1 lore raw

PATCH 1/2 net: ethernet: cortina: use devm to enable clocks

Avoid manually disabling them. devm can handle this.

---
 drivers/net/ethernet/cortina/gemini.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/net/ethernet/cortina/gemini.c +5 -18
index a55f4b82d1ba..8726e5ffbce7 100644
@@ -2348,7 +2348,6 @@ static void gemini_port_remove(struct gemini_ethernet_port *port)
 		phy_disconnect(port->netdev->phydev);
 		unregister_netdev(port->netdev);
 	}
-	clk_disable_unprepare(port->pclk);
 	geth_cleanup_freeq(port->geth);
 }
 
@@ -2475,14 +2474,11 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	port->irq = irq;
 
 	/* Clock the port */
-	port->pclk = devm_clk_get(dev, "PCLK");
+	port->pclk = devm_clk_get_enabled(dev, "PCLK");
 	if (IS_ERR(port->pclk)) {
 		dev_err(dev, "no PCLK\n");
 		return PTR_ERR(port->pclk);
 	}
-	ret = clk_prepare_enable(port->pclk);
-	if (ret)
-		return ret;
 
 	/* Maybe there is a nice ethernet address we should use */
 	gemini_port_save_mac_addr(port);
@@ -2491,8 +2487,7 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	port->reset = devm_reset_control_get_exclusive(dev, NULL);
 	if (IS_ERR(port->reset)) {
 		dev_err(dev, "no reset\n");
-		ret = PTR_ERR(port->reset);
-		goto unprepare;
+		return PTR_ERR(port->reset);
 	}
 	reset_control_reset(port->reset);
 	usleep_range(100, 500);
@@ -2554,24 +2549,16 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 					port_names[port->id],
 					port);
 	if (ret)
-		goto unprepare;
+		return ret;
 
 	ret = gmac_setup_phy(netdev);
 	if (ret) {
 		netdev_err(netdev,
 			   "PHY init failed\n");
-		goto unprepare;
+		return ret;
 	}
 
-	ret = register_netdev(netdev);
-	if (ret)
-		goto unprepare;
-
-	return 0;
-
-unprepare:
-	clk_disable_unprepare(port->pclk);
-	return ret;
+	return register_netdev(netdev);
 }
 
 static void gemini_ethernet_port_remove(struct platform_device *pdev)
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 net: ethernet: cortina: fix nvmem mac addresses

In reply to Rosen Penev

of_get_mac_address can return EPROBE_DEFER in case an nvmem driver needs to be loaded. Handle to allow nvmem mac address overrides.

---
 drivers/net/ethernet/cortina/gemini.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/cortina/gemini.c +2 -0
index 8726e5ffbce7..4225676662c8 100644
@@ -2525,6 +2525,8 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	netif_napi_add(netdev, &port->napi, gmac_napi_poll);
 
 	ret = of_get_mac_address(np, mac);
+	if (ret == -EPROBE_DEFER)
+		return ret;
 	if (!ret) {
 		dev_info(dev, "Setting macaddr from DT %pM\n", mac);
 		memcpy(port->mac_addr, mac, ETH_ALEN);
Signature · 1 line
2.53.0
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to Rosen Penev
Quoted 6 lines · Rosen Penev

When using nvmem, it may be necessary to defer probe until the specific nvmem driver is loaded to get the proper MAC.

Rosen Penev (2):
net: ethernet: cortina: use devm to enable clocks
net: ethernet: cortina: fix nvmem mac addresses

Net-next is closed so you will have to resend this:
https://netdev.bots.linux.dev/net-next.html

But I like what I see :)

What I actually most of all want to achieve here is to support loading the PHY as module, but I suspect that then the ethernet driver has to be a module as well so modprobe can do its job.

Yours,
Linus Walleij

#4 lore raw
Quoted 3 lines

What I actually most of all want to achieve here is to support loading the PHY as module, but I suspect that then the ethernet driver has to be a module as well so modprobe can do its job.

I don't think that is true. You should be able to have a built in MAC and a modular PHY. phylib will call out to modprobe, passing the ID of the PHY in order to load the driver. There are some interesting race conditions when interface open() is called while the PHY module is still loading, so you end up with genphy. But the race exists independent of built in vs modular MAC.

Andrew