Skip to contentSkip to conversation

net: lan966x: some OF cleanups

PATCH In review Rosen Penev 3 participants 7 messages Sep 1, 2025 – Sep 4, 2025

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

v2 cover net: lan966x: some OF cleanups

First commit basically adds NVMEM support and second one removes a lot of fwnode usage.

v2: change signature of lan966x_probe_port

Rosen Penev (2):
net: lan966x: use of_get_mac_address
net: lan966x: convert fwnode to of

 .../ethernet/microchip/lan966x/lan966x_main.c | 43 ++++++++++---------
 .../ethernet/microchip/lan966x/lan966x_main.h |  2 +-
 2 files changed, 24 insertions(+), 21 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/2 net: lan966x: use of_get_mac_address

As lan966x is an OF driver, switching to the OF version allows usage of NVMEM to override the MAC address of the interface.

Handle EPROBE_DEFER in the case that NVMEM loads after lan966x.

---
 drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +5 -4
index 7001584f1b7a..8bf28915c030 100644
@@ -1083,7 +1083,6 @@ static int lan966x_probe(struct platform_device *pdev)
 {
 	struct fwnode_handle *ports, *portnp;
 	struct lan966x *lan966x;
-	u8 mac_addr[ETH_ALEN];
 	int err;
 
 	lan966x = devm_kzalloc(&pdev->dev, sizeof(*lan966x), GFP_KERNEL);
@@ -1093,9 +1092,11 @@ static int lan966x_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, lan966x);
 	lan966x->dev = &pdev->dev;
 
-	if (!device_get_mac_address(&pdev->dev, mac_addr)) {
-		ether_addr_copy(lan966x->base_mac, mac_addr);
-	} else {
+	err = of_get_mac_address(pdev->dev.of_node, lan966x->base_mac);
+	if (err == -EPROBE_DEFER)
+		return err;
+
+	if (err) {
 		pr_info("MAC addr was not set, use random MAC\n");
 		eth_random_addr(lan966x->base_mac);
 		lan966x->base_mac[5] &= 0xf0;
Signature · 1 line
2.51.0
#2 lore raw

PATCH v2 2/2 net: lan966x: convert fwnode to of

In reply to Rosen Penev

This is a purely OF driver. There's no need for fwnode to handle any of this, with the exception being phylik_create. Use of_fwnode_handle for that.

---
 .../ethernet/microchip/lan966x/lan966x_main.c | 34 ++++++++++---------
 .../ethernet/microchip/lan966x/lan966x_main.h |  2 +-
 2 files changed, 19 insertions(+), 17 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +18 -16
index 8bf28915c030..98937830e74b 100644
@@ -183,7 +183,7 @@ static int lan966x_port_open(struct net_device *dev)
 		ANA_PORT_CFG_PORTID_VAL,
 		lan966x, ANA_PORT_CFG(port->chip_port));
 
-	err = phylink_fwnode_phy_connect(port->phylink, port->fwnode, 0);
+	err = phylink_of_phy_connect(port->phylink, port->dnode, 0);
 	if (err) {
 		netdev_err(dev, "Could not attach to PHY\n");
 		return err;
@@ -767,8 +767,8 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x)
 			port->phylink = NULL;
 		}
 
-		if (port->fwnode)
-			fwnode_handle_put(port->fwnode);
+		if (port->dnode)
+			of_node_put(port->dnode);
 	}
 
 	disable_irq(lan966x->xtr_irq);
@@ -791,7 +791,7 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x)
 
 static int lan966x_probe_port(struct lan966x *lan966x, u32 p,
 			      phy_interface_t phy_mode,
-			      struct fwnode_handle *portnp)
+			      struct device_node *portnp)
 {
 	struct lan966x_port *port;
 	struct phylink *phylink;
@@ -855,7 +855,7 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p,
 		  port->phylink_config.supported_interfaces);
 
 	phylink = phylink_create(&port->phylink_config,
-				 portnp,
+				 of_fwnode_handle(portnp),
 				 phy_mode,
 				 &lan966x_phylink_mac_ops);
 	if (IS_ERR(phylink)) {
@@ -1081,7 +1081,7 @@ static int lan966x_reset_switch(struct lan966x *lan966x)
 
 static int lan966x_probe(struct platform_device *pdev)
 {
-	struct fwnode_handle *ports, *portnp;
+	struct device_node *ports, *portnp;
 	struct lan966x *lan966x;
 	int err;
 
@@ -1179,7 +1179,7 @@ static int lan966x_probe(struct platform_device *pdev)
 		}
 	}
 
-	ports = device_get_named_child_node(&pdev->dev, "ethernet-ports");
+	ports = of_get_child_by_name(pdev->dev.of_node, "ethernet-ports");
 	if (!ports)
 		return dev_err_probe(&pdev->dev, -ENODEV,
 				     "no ethernet-ports child found\n");
@@ -1191,25 +1191,27 @@ static int lan966x_probe(struct platform_device *pdev)
 	lan966x_stats_init(lan966x);
 
 	/* go over the child nodes */
-	fwnode_for_each_available_child_node(ports, portnp) {
+	for_each_available_child_of_node(ports, portnp) {
 		phy_interface_t phy_mode;
 		struct phy *serdes;
 		u32 p;
 
-		if (fwnode_property_read_u32(portnp, "reg", &p))
+		if (of_property_read_u32(portnp, "reg", &p))
 			continue;
 
-		phy_mode = fwnode_get_phy_mode(portnp);
+		err = of_get_phy_mode(portnp, &phy_mode);
+		if (err)
+			goto cleanup_ports;
+
 		err = lan966x_probe_port(lan966x, p, phy_mode, portnp);
 		if (err)
 			goto cleanup_ports;
 
 		/* Read needed configuration */
 		lan966x->ports[p]->config.portmode = phy_mode;
-		lan966x->ports[p]->fwnode = fwnode_handle_get(portnp);
+		lan966x->ports[p]->dnode = of_node_get(portnp);
 
-		serdes = devm_of_phy_optional_get(lan966x->dev,
-						  to_of_node(portnp), NULL);
+		serdes = devm_of_phy_optional_get(lan966x->dev, portnp, NULL);
 		if (IS_ERR(serdes)) {
 			err = PTR_ERR(serdes);
 			goto cleanup_ports;
@@ -1222,7 +1224,7 @@ static int lan966x_probe(struct platform_device *pdev)
 			goto cleanup_ports;
 	}
 
-	fwnode_handle_put(ports);
+	of_node_put(ports);
 
 	lan966x_mdb_init(lan966x);
 	err = lan966x_fdb_init(lan966x);
@@ -1255,8 +1257,8 @@ static int lan966x_probe(struct platform_device *pdev)
 	lan966x_fdb_deinit(lan966x);
 
 cleanup_ports:
-	fwnode_handle_put(ports);
-	fwnode_handle_put(portnp);
+	of_node_put(ports);
+	of_node_put(portnp);
 
 	lan966x_cleanup_ports(lan966x);
 
drivers/net/ethernet/microchip/lan966x/lan966x_main.h +1 -1
index 4f75f0688369..bafb8f5ee64d 100644
@@ -407,7 +407,7 @@ struct lan966x_port {
 	struct lan966x_port_config config;
 	struct phylink *phylink;
 	struct phy *serdes;
-	struct fwnode_handle *fwnode;
+	struct device_node *dnode;
 
 	u8 ptp_tx_cmd;
 	bool ptp_rx_cmd;
Signature · 1 line
2.51.0
maintainer
#3 lore raw

Re: [PATCHv2 net-next 2/2] net: lan966x: convert fwnode to of

Quoted 3 lines · On Mon, 1 Sep 2025 13:20:01 -0700 Rosen Penev wrote:

This is a purely OF driver. There's no need for fwnode to handle any of this, with the exception being phylik_create. Use of_fwnode_handle for that.

Not sure this is worth cleaning up, but I'm not an OF API expert. It's pretty odd that you're sneaking in an extra error check in such a cleanup patch without even mentioning it.

Signature · 1 line
pw-bot: cr
#4 lore raw

Re: [PATCHv2 net-next 2/2] net: lan966x: convert fwnode to of

Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 1 Sep 2025 13:20:01 -0700 Rosen Penev wrote:

This is a purely OF driver. There's no need for fwnode to handle any of this, with the exception being phylik_create. Use of_fwnode_handle for that.

Not sure this is worth cleaning up, but I'm not an OF API expert. It's pretty odd that you're sneaking in an extra error check in such a cleanup patch without even mentioning it.

git grep shows most drivers handling the error.

git grep of_get_phy_mode drivers/ | grep -v = | wc -l 7
git grep \ =\ of_get_phy_mode drivers/ | wc -l 48

I don't see why it should be different here.

Actually without handling the error, phy_mode gets used unassigned in lan966x_probe_port

The fwnode API is different as it conflates int and phy_connection_t as the same thing.

Quoted 2 lines

--
pw-bot: cr

#5 lore raw

Re: [PATCHv2 net-next 2/2] net: lan966x: convert fwnode to of

Quoted 17 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 1 Sep 2025 13:20:01 -0700 Rosen Penev wrote:
Quoted 3 lines

This is a purely OF driver. There's no need for fwnode to handle any of this, with the exception being phylik_create. Use of_fwnode_handle for that.

Not sure this is worth cleaning up, but I'm not an OF API expert. It's pretty odd that you're sneaking in an extra error check in such a cleanup patch without even mentioning it.

git grep shows most drivers handling the error.

git grep of_get_phy_mode drivers/ | grep -v = | wc -l 7
git grep \ =\ of_get_phy_mode drivers/ | wc -l 48

Quoted 9 lines

I don't see why it should be different here.

Actually without handling the error, phy_mode gets used unassigned in lan966x_probe_port

The fwnode API is different as it conflates int and phy_connection_t as the same thing.

Quoted 2 lines

--
pw-bot: cr

About the added error check - I agree with Jakub that this deserves to be mentioned, and should be a patch on its own.

I did some testing on lan966x, and before the added error check, it was actually possible to omit phy-mode from the DT, and still have a valid port configuration - but then again, the bindings documents phy-mode as a required property.. maybe this should be enforced in the code.

As for the fwnode -> of changes, those looks good to me.

/Daniel

#6 lore raw

Re: [PATCHv2 net-next 2/2] net: lan966x: convert fwnode to of

Quoted 23 lines · Daniel Machon
Quoted 23 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 1 Sep 2025 13:20:01 -0700 Rosen Penev wrote:
Quoted 3 lines

This is a purely OF driver. There's no need for fwnode to handle any of this, with the exception being phylik_create. Use of_fwnode_handle for that.

Not sure this is worth cleaning up, but I'm not an OF API expert. It's pretty odd that you're sneaking in an extra error check in such a cleanup patch without even mentioning it.

git grep shows most drivers handling the error.

git grep of_get_phy_mode drivers/ | grep -v = | wc -l 7
git grep \ =\ of_get_phy_mode drivers/ | wc -l 48

I don't see why it should be different here.

Actually without handling the error, phy_mode gets used unassigned in lan966x_probe_port

Quoted 7 lines
Quoted 4 lines

The fwnode API is different as it conflates int and phy_connection_t as the same thing.

Quoted 2 lines

--
pw-bot: cr

About the added error check - I agree with Jakub that this deserves to be mentioned, and should be a patch on its own.

Sounds like a fix for net instead of net-next. Not sure how that would work as both patches would conflict.

Quoted 5 lines

I did some testing on lan966x, and before the added error check, it was actually possible to omit phy-mode from the DT, and still have a valid port configuration - but then again, the bindings documents phy-mode as a required property.. maybe this should be enforced in the code.

Absolutely.

Quoted 5 lines

As for the fwnode -> of changes, those looks good to me.

/Daniel