udev: net_id: improve device tree naming scheme to support 'ethernet-ports'
The 'names_devicetree' function previously only searched for 'ethernet' nodes in the device tree and compared them with aliases. This approach fails when 'ethernet-ports' nodes are used, as seen in the AM62 SoC from TI. This SoC uses a 3-port Gigabit Ethernet switch with one internal port and two external ports. As result, two ethernet ports are nested within the 'ethernet' node on the device tree, and aliases point to the specific 'ethernet-ports' rather than the 'ethernet' node itself.
For instance, in AM62 SoC:
cat /sys/firmware/devicetree/base/aliases/ethernet0 /bus@f0000/ethernet@8000000/ethernet-ports/port@1 cat /sys/firmware/devicetree/base/aliases/ethernet1 /bus@f0000/ethernet@8000000/ethernet-ports/port@2
This commit updates 'names_devicetree' to iterate through the child nodes of 'ethernet' and check for the usage of 'ethernet-ports.' This update aligns with the definition of 'ethernet-ports' in the Linux kernel's dsa.yml file.
Please add example path or value in code.
Added inside the Example paths comment, thank you.
I also updated the commit title to include net_id.
codewise looks ok'ish to me. I'll leave final review to @yuwata who is more at home with this than i am I guess.
Original dt support for this was added in 65c2ad985a8debdf6d7d11fee5b466f280260f4b (#24265)
hey, @sean-anderson-seco any chance you can weigh in on this? does this make sense?
(you did the original devicetree support for udev interface naming, and you might have a tak on this too?)
@hiagofranco Any news on this?
I guess all K3 TI SoCs (possibly others) have the same issues.
@pfiser you can try sean-anderson-seco/linux@39a211426a9021b446189afebc06bfdffc0afa20. It should create the of_node necessary for systemd to determine the aliases.
@sean-anderson-seco I applied your patch and used latest yocto scarthgap build based on 6.6 LTS kernel.
However, systemd doesn't find the correct device-tree alias indexes:
# udevadm test /sys/class/net/eth0
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
Trying to open "/etc/systemd/hwdb/hwdb.bin"...
Trying to open "/etc/udev/hwdb.bin"...
Trying to open "/usr/lib/systemd/hwdb/hwdb.bin"...
Trying to open "/usr/lib/udev/hwdb.bin"...
hwdb.bin does not exist, please run 'systemd-hwdb update'
Loading kernel module index.
Found cgroup2 on /sys/fs/cgroup/unified, unified hierarchy for systemd controller
Found container virtualization none.
Using default interface naming scheme 'v255'.
Parsed configuration file "/usr/lib/systemd/network/99-default.link"
Parsed configuration file "/usr/lib/systemd/network/10-eth2.link"
Parsed configuration file "/usr/lib/systemd/network/10-eth1.link"
Parsed configuration file "/usr/lib/systemd/network/10-eth0.link"
Created link configuration context.
Reading rules file: /etc/udev/rules.d/37-can-ti-soc.rules
Reading rules file: /usr/lib/udev/rules.d/50-udev-default.rules
Reading rules file: /usr/lib/udev/rules.d/60-autosuspend.rules
Reading rules file: /usr/lib/udev/rules.d/60-block.rules
Reading rules file: /usr/lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /usr/lib/udev/rules.d/60-dmi-id.rules
Reading rules file: /usr/lib/udev/rules.d/60-drm.rules
Reading rules file: /usr/lib/udev/rules.d/60-evdev.rules
Reading rules file: /usr/lib/udev/rules.d/60-fido-id.rules
Reading rules file: /usr/lib/udev/rules.d/60-infiniband.rules
Reading rules file: /usr/lib/udev/rules.d/60-input-id.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-storage-mtd.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /usr/lib/udev/rules.d/60-sensor.rules
Reading rules file: /usr/lib/udev/rules.d/60-serial.rules
Reading rules file: /usr/lib/udev/rules.d/64-btrfs.rules
Reading rules file: /usr/lib/udev/rules.d/70-camera.rules
Reading rules file: /usr/lib/udev/rules.d/70-joystick.rules
Reading rules file: /usr/lib/udev/rules.d/70-memory.rules
Reading rules file: /usr/lib/udev/rules.d/70-mouse.rules
Reading rules file: /usr/lib/udev/rules.d/70-power-switch.rules
Reading rules file: /usr/lib/udev/rules.d/70-touchpad.rules
Reading rules file: /usr/lib/udev/rules.d/71-seat.rules
Reading rules file: /usr/lib/udev/rules.d/73-seat-late.rules
Reading rules file: /usr/lib/udev/rules.d/75-net-description.rules
Reading rules file: /usr/lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /usr/lib/udev/rules.d/78-sound-card.rules
Reading rules file: /usr/lib/udev/rules.d/80-drivers.rules
Reading rules file: /usr/lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /usr/lib/udev/rules.d/81-net-dhcp.rules
Reading rules file: /usr/lib/udev/rules.d/90-alsa-restore.rules
Reading rules file: /usr/lib/udev/rules.d/90-iocost.rules
Reading rules file: /usr/lib/udev/rules.d/90-pulseaudio.rules
Reading rules file: /usr/lib/udev/rules.d/99-systemd.rules
Reading rules file: /etc/udev/rules.d/touchscreen.rules
eth0: /usr/lib/udev/rules.d/50-udev-default.rules:31 Importing properties from results of builtin command 'net_driver'
eth0: /usr/lib/udev/rules.d/75-net-description.rules:6 Importing properties from results of builtin command 'net_id'
eth0: MAC address identifier: hw_addr=28:b5:e8:e2:54:16 -> x28b5e8e25416
eth0: Parent device is in the platform subsystem.
eth0: Could not find usb parent device: No such file or directory
eth0: Could not get bcma parent device: No such file or directory
eth0: /usr/lib/udev/rules.d/80-net-setup-link.rules:5 Importing properties from results of builtin command 'path_id'
eth0: /usr/lib/udev/rules.d/80-net-setup-link.rules:9 Importing properties from results of builtin command 'net_setup_link'
eth0: Device has name_assign_type=1
eth0: Device has addr_assign_type=0
eth0: Config file /usr/lib/systemd/network/10-eth0.link is applied to device based on potentially unpredictable interface name.
eth0: Using static MAC address.
eth0: Policies didn't yield a name and Name= is not given, not renaming.
eth0: /usr/lib/udev/rules.d/80-net-setup-link.rules:11 NAME 'eth0'
eth0: /usr/lib/udev/rules.d/99-systemd.rules:70 RUN '/usr/lib/systemd/systemd-sysctl --prefix=/net/ipv4/conf/$name --prefix=/net/ipv4/neigh/$name --prefix=/net/ipv6/conf/$name --prefix=/net/ipv6/neigh/$name'
eth0: sd-device: Created db file '/run/udev/data/n2' for '/devices/platform/bus@f0000/8000000.ethernet/net/eth0'
DEVPATH=/devices/platform/bus@f0000/8000000.ethernet/net/eth0
OF_NAME=port
OF_FULLNAME=/bus@f0000/ethernet@8000000/ethernet-ports/port@1
OF_COMPATIBLE_N=0
OF_ALIAS_0=ethernet0
INTERFACE=eth0
IFINDEX=2
ACTION=add
SUBSYSTEM=net
TAGS=:systemd:
ID_NET_DRIVER=am65-cpsw-nuss
ID_NET_NAMING_SCHEME=v255
ID_NET_NAME_MAC=enx28b5e8e25416
ID_PATH=platform-8000000.ethernet
ID_PATH_TAG=platform-8000000_ethernet
ID_NET_LINK_FILE=/usr/lib/systemd/network/10-eth0.link
ID_NET_NAME=eth0
CURRENT_TAGS=:systemd:
SYSTEMD_ALIAS=/sys/subsystem/net/devices/eth0
USEC_INITIALIZED=6031726
run: '/usr/lib/systemd/systemd-sysctl --prefix=/net/ipv4/conf/eth0 --prefix=/net/ipv4/neigh/eth0 --prefix=/net/ipv6/conf/eth0 --prefix=/net/ipv6/neigh/eth0'
Unload kernel module index.
Unloaded link configuration context
Should I use your commit with or without changes in this PR?
Hi all, sorry, I was working in a different task and I could not get back to it yet. I will also test @sean-anderson-seco patch. Thanks!
@sean-anderson-seco I applied your patch and used latest yocto scarthgap build based on 6.6 LTS kernel.
However, systemd doesn't find the correct device-tree alias indexes:
OK, looks like the of_node gets created properly.
Should I use your commit with or without changes in this PR?
I think the current code needs to be extended to check for aliases in the node itself as well as in its parent. And ideally we would just use OF_ALIAS_0 directly instead of parsing the firmware again. I think this should be a straightforward cleanup. I will try to have a crack at it at some point, but don't let me stop you :)
I've come across the same issue on the TI AM62x, but I don't believe teaching systemd about the ethernet-ports OF nodes is the right approach, as it is too hardware/driver-specific. With recent enough kernels, I was able to make the naming work with a much simpler change: #33958
Hi @schiffermtq, great news. If this gets merged and solves the issue, I am fine with closing this PR.
I can also test your patch with the real hardware next week. Thank you!
Hi @schiffermtq, great news. If this gets merged and solves the issue, I am fine with closing this PR.
I can also test your patch with the real hardware next week. Thank you!
Sounds good! Note that the required kernel patch is only in 6.11-rc1+ at the moment.