Skip to contentSkip to conversation

net: Use dev APIs

PATCH In review Peng Fan (OSS) 3 participants 9 messages May 28 – Jun 3 Network drivers

lore
Share & tools
lore
#0 lore raw

v2 cover net: Use dev APIs

This series converts several Ethernet drivers to use the generic device model APIs for device tree access, replacing devfdt_* and fdtdec/fdt_* interfaces.

The goal is to improve compatibility with both live device tree and flat device tree backends, and to reduce direct dependencies on low-level FDT helpers.

Patches 1–5 perform straightforward replacements:
- devfdt_get_addr() → dev_read_addr()
- devfdt_get_addr_index() → dev_read_addr_index()
- devfdt_get_addr_index_ptr() → dev_read_addr_index_ptr()
- map_physmem(devfdt_get_addr()) → dev_remap_addr()

These changes are mechanical and introduce no functional change.

Patch 6 converts the mvpp2 driver from legacy fdtdec/fdt_* APIs to ofnode-based interfaces. This removes dependencies on gd->fdt_blob and updates phandle parsing, subnode iteration, property access, and device lookup.

No intended functional changes.

I not have the platforms to test, just best practice for this work.

---
Changes in v2:
- Add R-b from Simon
- In patch 6:
- drop unused variables,
- drop error return code which not follows "No functional changes". This patchset is mainly for API updating, not indended to do functional change.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Peng Fan (6):
net: ethoc: Use dev_read_addr_index()
net: qe: dm_qe_uec: Use dev_read_addr()
net: calxedaxgmac: Use dev_read_addr()
net: dc2114x: Use dev_remap_addr()
net: mvpp2: Use dev_read_addr_index_ptr()
net: mvpp2: convert FDT access to ofnode API

 drivers/net/calxedaxgmac.c |  2 +-
 drivers/net/dc2114x.c      |  2 +-
 drivers/net/ethoc.c        |  2 +-
 drivers/net/mvpp2.c        | 56 +++++++++++++++++++++-------------------------
 drivers/net/qe/dm_qe_uec.c |  2 +-
 5 files changed, 29 insertions(+), 35 deletions(-)

---
base-commit: bb354d04459f5425318aeb8a70bae995ee573f1d
change-id: 20260526-devfdt-net-a0fe75cd7f49

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
#1 lore raw

PATCH v2 1/6 net: ethoc: Use dev_read_addr_index()

From: Peng Fan <[email protected]>

Use dev_read_addr_index() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

No functional changes.

---
 drivers/net/ethoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethoc.c +1 -1
index dc7e6f1929f..87b2b3426c8 100644
@@ -686,7 +686,7 @@ static int ethoc_of_to_plat(struct udevice *dev)
 	fdt_addr_t addr;
 
 	pdata->eth_pdata.iobase = dev_read_addr(dev);
-	addr = devfdt_get_addr_index(dev, 1);
+	addr = dev_read_addr_index(dev, 1);
 	if (addr != FDT_ADDR_T_NONE)
 		pdata->packet_base = addr;
 	return 0;
Signature · 1 line
2.51.0
#2 lore raw

PATCH v2 2/6 net: qe: dm_qe_uec: Use dev_read_addr()

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Use dev_read_addr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

No functional changes.

---
 drivers/net/qe/dm_qe_uec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/qe/dm_qe_uec.c +1 -1
index ac3aedd8b49..f9bc5d49c8f 100644
@@ -1133,7 +1133,7 @@ static int qe_uec_of_to_plat(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
 
-	pdata->iobase = (phys_addr_t)devfdt_get_addr(dev);
+	pdata->iobase = (phys_addr_t)dev_read_addr(dev);
 
 	pdata->phy_interface = dev_read_phy_mode(dev);
 	if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
Signature · 1 line
2.51.0
Reviewed-by on v2 2/6
#3 lore raw

Re: [PATCH v2 2/6] net: qe: dm_qe_uec: Use dev_read_addr()

Hello Peng,

Quoted 5 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

Use dev_read_addr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

Quoted 7 lines

No functional changes.

---
  drivers/net/qe/dm_qe_uec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

bye,
Heiko

Signature · 5 lines
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
#4 lore raw

PATCH v2 3/6 net: calxedaxgmac: Use dev_read_addr()

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Use dev_read_addr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

No functional changes.

---
 drivers/net/calxedaxgmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/calxedaxgmac.c +1 -1
index 92990fa6d47..df0ed820e06 100644
@@ -555,7 +555,7 @@ static int xgmac_ofdata_to_platdata(struct udevice *dev)
 		return -ENOMEM;
 	dev_set_priv(dev, priv);
 
-	pdata->iobase = devfdt_get_addr(dev);
+	pdata->iobase = dev_read_addr(dev);
 	if (pdata->iobase == FDT_ADDR_T_NONE) {
 		printf("%s: Cannot find XGMAC base address\n", __func__);
 		return -EINVAL;
Signature · 1 line
2.51.0
#5 lore raw

PATCH v2 4/6 net: dc2114x: Use dev_remap_addr()

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Use dev_remap_addr() to simplify code.

dev_remap_addr() does same thing as dev_read_addr() + map_physmem(). And it supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

No functional changes.

---
 drivers/net/dc2114x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dc2114x.c +1 -1
index 8fa549280aa..2a21eceac57 100644
@@ -653,7 +653,7 @@ static int dc2114x_of_to_plat(struct udevice *dev)
 	struct eth_pdata *plat = dev_get_plat(dev);
 	struct dc2114x_priv *priv = dev_get_priv(dev);
 
-	plat->iobase = (phys_addr_t)map_physmem((phys_addr_t)devfdt_get_addr(dev), 0, MAP_NOCACHE);
+	plat->iobase = (phys_addr_t)dev_remap_addr(dev);
 	priv->iobase = (void *)plat->iobase;
 
 	return 0;
Signature · 1 line
2.51.0
#6 lore raw

PATCH v2 5/6 net: mvpp2: Use dev_read_addr_index_ptr()

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Use dev_read_addr_index_ptr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.

No functional changes.

---
 drivers/net/mvpp2.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/mvpp2.c +4 -5
index f9e979c4d58..193f82ea07d 100644
@@ -5296,16 +5296,16 @@ static int mvpp2_base_probe(struct udevice *dev)
 	}
 
 	/* Save base addresses for later use */
-	priv->base = devfdt_get_addr_index_ptr(dev, 0);
+	priv->base = dev_read_addr_index_ptr(dev, 0);
 	if (!priv->base)
 		return -EINVAL;
 
 	if (priv->hw_version == MVPP21) {
-		priv->lms_base = devfdt_get_addr_index_ptr(dev, 1);
+		priv->lms_base = dev_read_addr_index_ptr(dev, 1);
 		if (!priv->lms_base)
 			return -EINVAL;
 	} else {
-		priv->iface_base = devfdt_get_addr_index_ptr(dev, 1);
+		priv->iface_base = dev_read_addr_index_ptr(dev, 1);
 		if (!priv->iface_base)
 			return -EINVAL;
 
@@ -5346,8 +5346,7 @@ static int mvpp2_probe(struct udevice *dev)
 	if (priv->hw_version == MVPP21) {
 		int priv_common_regs_num = 2;
 
-		port->base = devfdt_get_addr_index_ptr(
-			dev->parent, priv_common_regs_num + port->id);
+		port->base = dev_read_addr_index_ptr(dev->parent, priv_common_regs_num + port->id);
 		if (!port->base)
 			return -EINVAL;
 	} else {
Signature · 1 line
2.51.0
#7 lore raw

PATCH v2 6/6 net: mvpp2: convert FDT access to ofnode API

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Convert mvpp2 driver from legacy fdtdec/fdt_* APIs to the ofnode-based interfaces.

Replace usage of dev_of_offset(), fdtdec_lookup_phandle(), fdtdec_get_int(), fdt_parent_offset(), and related helpers with their ofnode equivalents, including dev_ofnode(), ofnode_parse_phandle(), ofnode_read_s32_default(), ofnode_get_parent(), and ofnode_for_each_subnode().

Remove direct dependencies on gd->fdt_blob.

Main changes:
- Use ofnode_valid() instead of integer checks for node presence
- Switch fixed-link detection to ofnode_find_subnode()
- Replace uclass_get_device_by_of_offset() with uclass_get_device_by_ofnode()
- Update subnode iteration and device binding to use ofnode

No functional changes.

---
 drivers/net/mvpp2.c | 47 +++++++++++++++++++++--------------------------
 1 file changed, 21 insertions(+), 26 deletions(-)
drivers/net/mvpp2.c +21 -26
index 193f82ea07d..fc137df14c4 100644
@@ -4731,33 +4731,32 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
 
 static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
 {
-	int port_node = dev_of_offset(dev);
-	int phy_node;
+	ofnode port_node = dev_ofnode(dev);
+	ofnode phy_node;
 	u32 id;
 	int phyaddr = 0;
-	int fixed_link = 0;
+	ofnode fixed_link;
 	int ret;
 
-	phy_node = fdtdec_lookup_phandle(gd->fdt_blob, port_node, "phy");
-	fixed_link = fdt_subnode_offset(gd->fdt_blob, port_node, "fixed-link");
+	phy_node = ofnode_parse_phandle(port_node, "phy", 0);
+	fixed_link = ofnode_find_subnode(port_node, "fixed-link");
 
-	if (phy_node > 0) {
-		int parent;
+	if (ofnode_valid(phy_node)) {
+		ofnode parent;
 
-		if (fixed_link != -FDT_ERR_NOTFOUND) {
+		if (ofnode_valid(fixed_link)) {
 			/* phy_addr is set to invalid value for fixed links */
 			phyaddr = PHY_MAX_ADDR;
 		} else {
-			phyaddr = fdtdec_get_int(gd->fdt_blob, phy_node,
-						 "reg", 0);
+			phyaddr = ofnode_read_s32_default(phy_node, "reg", 0);
 			if (phyaddr < 0) {
 				dev_err(dev, "could not find phy address\n");
 				return -1;
 			}
 		}
-		parent = fdt_parent_offset(gd->fdt_blob, phy_node);
-		ret = uclass_get_device_by_of_offset(UCLASS_MDIO, parent,
-						     &port->mdio_dev);
+		parent = ofnode_get_parent(phy_node);
+		ret = uclass_get_device_by_ofnode(UCLASS_MDIO, parent,
+						  &port->mdio_dev);
 		if (ret)
 			return ret;
 	} else {
@@ -4771,7 +4770,7 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
 		return -EINVAL;
 	}
 
-	id = fdtdec_get_int(gd->fdt_blob, port_node, "port-id", -1);
+	id = dev_read_s32_default(dev, "port-id", -1);
 	if (id == -1) {
 		dev_err(dev, "missing port-id value\n");
 		return -EINVAL;
@@ -4812,7 +4811,7 @@ static void mvpp2_gpio_init(struct mvpp2_port *port)
 /* Ports initialization */
 static int mvpp2_port_probe(struct udevice *dev,
 			    struct mvpp2_port *port,
-			    int port_node,
+			    ofnode port_node,
 			    struct mvpp2 *priv)
 {
 	int err;
@@ -5350,8 +5349,7 @@ static int mvpp2_probe(struct udevice *dev)
 		if (!port->base)
 			return -EINVAL;
 	} else {
-		port->gop_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-					      "gop-port-id", -1);
+		port->gop_id = ofnode_read_s32_default(dev_ofnode(dev), "gop-port-id", -1);
 		if (port->gop_id == -1) {
 			dev_err(dev, "missing gop-port-id value\n");
 			return -EINVAL;
@@ -5375,7 +5373,7 @@ static int mvpp2_probe(struct udevice *dev)
 		priv->probe_done = 1;
 	}
 
-	err = mvpp2_port_probe(dev, port, dev_of_offset(dev), priv);
+	err = mvpp2_port_probe(dev, port, dev_ofnode(dev), priv);
 	if (err)
 		return err;
 
@@ -5436,13 +5434,11 @@ static struct driver mvpp2_driver = {
  */
 static int mvpp2_base_bind(struct udevice *parent)
 {
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(parent);
 	struct uclass_driver *drv;
 	struct udevice *dev;
 	struct eth_pdata *plat;
 	char *name;
-	int subnode;
+	ofnode subnode;
 	u32 id;
 	int base_id_add;
 
@@ -5455,19 +5451,19 @@ static int mvpp2_base_bind(struct udevice *parent)
 
 	base_id_add = base_id;
 
-	fdt_for_each_subnode(subnode, blob, node) {
+	dev_for_each_subnode(subnode, parent) {
 		/* Increment base_id for all subnodes, also the disabled ones */
 		base_id++;
 
 		/* Skip disabled ports */
-		if (!fdtdec_get_is_enabled(blob, subnode))
+		if (!ofnode_is_enabled(subnode))
 			continue;
 
 		plat = calloc(1, sizeof(*plat));
 		if (!plat)
 			return -ENOMEM;
 
-		id = fdtdec_get_int(blob, subnode, "port-id", -1);
+		id = ofnode_read_s32_default(subnode, "port-id", -1);
 		id += base_id_add;
 
 		name = calloc(1, 16);
@@ -5478,8 +5474,7 @@ static int mvpp2_base_bind(struct udevice *parent)
 		sprintf(name, "mvpp2-%d", id);
 
 		/* Create child device UCLASS_ETH and bind it */
-		device_bind(parent, &mvpp2_driver, name, plat,
-			    offset_to_ofnode(subnode), &dev);
+		device_bind(parent, &mvpp2_driver, name, plat, subnode, &dev);
 	}
 
 	return 0;
Signature · 1 line
2.51.0
#8 lore raw
In reply to Peng Fan (OSS)
Quoted 51 lines · Peng Fan (OSS)

This series converts several Ethernet drivers to use the generic device model APIs for device tree access, replacing devfdt_* and fdtdec/fdt_* interfaces.

The goal is to improve compatibility with both live device tree and flat device tree backends, and to reduce direct dependencies on low-level FDT helpers.

Patches 1–5 perform straightforward replacements:
- devfdt_get_addr() → dev_read_addr()
- devfdt_get_addr_index() → dev_read_addr_index()
- devfdt_get_addr_index_ptr() → dev_read_addr_index_ptr()
- map_physmem(devfdt_get_addr()) → dev_remap_addr()

These changes are mechanical and introduce no functional change.

Patch 6 converts the mvpp2 driver from legacy fdtdec/fdt_* APIs to ofnode-based interfaces. This removes dependencies on gd->fdt_blob and updates phandle parsing, subnode iteration, property access, and device lookup.

No intended functional changes.

I not have the platforms to test, just best practice for this work.

---
Changes in v2:
- Add R-b from Simon
- In patch 6:
- drop unused variables,
- drop error return code which not follows "No functional changes". This patchset is mainly for API updating, not indended to do functional change.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Peng Fan (6):
net: ethoc: Use dev_read_addr_index()
net: qe: dm_qe_uec: Use dev_read_addr()
net: calxedaxgmac: Use dev_read_addr()
net: dc2114x: Use dev_remap_addr()
net: mvpp2: Use dev_read_addr_index_ptr()
net: mvpp2: convert FDT access to ofnode API

 drivers/net/calxedaxgmac.c |  2 +-
 drivers/net/dc2114x.c      |  2 +-
 drivers/net/ethoc.c        |  2 +-
 drivers/net/mvpp2.c        | 56 +++++++++++++++++++++-------------------------
 drivers/net/qe/dm_qe_uec.c |  2 +-
 5 files changed, 29 insertions(+), 35 deletions(-)
Quoted 5 lines

---
base-commit: bb354d04459f5425318aeb8a70bae995ee573f1d
change-id: 20260526-devfdt-net-a0fe75cd7f49

Best regards,

Series added to net-next, thanks!

Signature · 1 line
Jerome