diff mbox series

net: ethernet: ti: am65-cpsw-nuss: create platform device for port nodes

Message ID 20240503200038.573669-1-hiagofranco@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: ti: am65-cpsw-nuss: create platform device for port nodes | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: rogerq@kernel.org jpanis@baylibre.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-05--03-00 (tests: 1003)

Commit Message

Hiago De Franco May 3, 2024, 8 p.m. UTC
From: Hiago De Franco <hiago.franco@toradex.com>

After this change, an 'of_node' link from '/sys/devices/platform' to
'/sys/firmware/devicetree' will be created. The 'ethernet-ports' device
allows multiple netdevs to have the exact same parent device, e.g. port@x
netdevs are child nodes of ethernet-ports.

When ethernet aliases are used (e.g. 'ethernet0 = &cpsw_port1' and
'ethernet1 = &cpsw_port2') in the device tree, without an of_node
device exposed to the userspace, it is not possible to determine where
exactly the alias is pointing to.

As an example, this is essential for applications like systemd, which rely
on the of_node information to identify and manage Ethernet devices
using device tree aliases introduced in the v251 naming scheme.

Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

João Paulo Gonçalves May 3, 2024, 11:24 p.m. UTC | #1
On Fri, May 03, 2024 at 05:00:38PM -0300, Hiago De Franco wrote:
> From: Hiago De Franco <hiago.franco@toradex.com>
> 
> After this change, an 'of_node' link from '/sys/devices/platform' to
> '/sys/firmware/devicetree' will be created. The 'ethernet-ports' device
> allows multiple netdevs to have the exact same parent device, e.g. port@x
> netdevs are child nodes of ethernet-ports.
> 
> When ethernet aliases are used (e.g. 'ethernet0 = &cpsw_port1' and
> 'ethernet1 = &cpsw_port2') in the device tree, without an of_node
> device exposed to the userspace, it is not possible to determine where
> exactly the alias is pointing to.
> 
> As an example, this is essential for applications like systemd, which rely
> on the of_node information to identify and manage Ethernet devices
> using device tree aliases introduced in the v251 naming scheme.
> 
> Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
> ---
>  drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index 1d00e21808c1..f74915f56fa2 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -2091,6 +2091,13 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
>  		if (strcmp(port_np->name, "port"))
>  			continue;
>  
> +		if (!of_platform_device_create(port_np, NULL, NULL)) {
> +			dev_err(dev, "%pOF error creating port platform device\n",
> +				port_np);
> +			ret = -ENODEV;
> +			goto of_node_put;
> +		}
> +
>  		ret = of_property_read_u32(port_np, "reg", &port_id);
>  		if (ret < 0) {
>  			dev_err(dev, "%pOF error reading port_id %d\n",
> -- 
> 2.43.0
> 
> 

Reviewed-by: Joao Paulo Goncalves <joao.goncalves@toradex.com>

Regards,
João Paulo Gonçalves
Hiago De Franco May 6, 2024, 5:52 p.m. UTC | #2
Dear Maintainers,

On Fri, May 03, 2024 at 05:00:38PM -0300, Hiago De Franco wrote:
> From: Hiago De Franco <hiago.franco@toradex.com>
> 
> After this change, an 'of_node' link from '/sys/devices/platform' to
> '/sys/firmware/devicetree' will be created. The 'ethernet-ports' device
> allows multiple netdevs to have the exact same parent device, e.g. port@x
> netdevs are child nodes of ethernet-ports.
> 
> When ethernet aliases are used (e.g. 'ethernet0 = &cpsw_port1' and
> 'ethernet1 = &cpsw_port2') in the device tree, without an of_node
> device exposed to the userspace, it is not possible to determine where
> exactly the alias is pointing to.
> 
> As an example, this is essential for applications like systemd, which rely
> on the of_node information to identify and manage Ethernet devices
> using device tree aliases introduced in the v251 naming scheme.
> 
> Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
> ---
>  drivers/net/ethernet/ti/am65-cpsw-nuss.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index 1d00e21808c1..f74915f56fa2 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -2091,6 +2091,13 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
>  		if (strcmp(port_np->name, "port"))
>  			continue;
>  
> +		if (!of_platform_device_create(port_np, NULL, NULL)) {
> +			dev_err(dev, "%pOF error creating port platform device\n",
> +				port_np);
> +			ret = -ENODEV;
> +			goto of_node_put;
> +		}
> +
>  		ret = of_property_read_u32(port_np, "reg", &port_id);
>  		if (ret < 0) {
>  			dev_err(dev, "%pOF error reading port_id %d\n",
> -- 
> 2.43.0
> 

Apologies, I believe this patch is not 100% complete, there might be
something missing. Please keep this on hold, there is something not
working as expected that I am currently investigating.

My goal was to create an of_node device for the switch ports, which did
create under the /sys/devices/platform:

ls /sys/devices/platform/8000000.ethernet:ethernet-ports:port@1/
driver_override               power                         uevent
modalias                      subsystem                     waiting_for_supplier
of_node                       supplier:platform:104044.phy

However it is still missing under

find /sys/devices/platform/bus@f0000/8000000.ethernet/net/eth0/ -name *of_node*

I will figure out how to do that and propose a new version.

Regards,

Hiago.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 1d00e21808c1..f74915f56fa2 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -2091,6 +2091,13 @@  static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
 		if (strcmp(port_np->name, "port"))
 			continue;
 
+		if (!of_platform_device_create(port_np, NULL, NULL)) {
+			dev_err(dev, "%pOF error creating port platform device\n",
+				port_np);
+			ret = -ENODEV;
+			goto of_node_put;
+		}
+
 		ret = of_property_read_u32(port_np, "reg", &port_id);
 		if (ret < 0) {
 			dev_err(dev, "%pOF error reading port_id %d\n",