net: enetc: Support ethernet aliases in dts.
PATCH 1/1 net: enetc: Support ethernet aliases in dts.
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
--- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +12 -2
@@ -622,10 +622,20 @@ static int enetc4_pf_netdev_create(struct enetc_si *si)struct device *dev = &si->pdev->dev;struct enetc_ndev_priv *priv;struct net_device *ndev; +char ifname[IFNAMSIZ ];int err; - ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), - si->num_tx_rings, si->num_rx_rings); + err =of_alias_get_id (dev->of_node,"ethernet" ); +if (err >=0 ) { +snprintf (ifname,IFNAMSIZ ,"eth%d" , err); + ndev =alloc_netdev_mqs (sizeof (struct enetc_ndev_priv ), + ifname,NET_NAME_PREDICTABLE , ether_setup, + si->num_tx_rings, si->num_rx_rings); + }else { + ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), + si->num_tx_rings, si->num_rx_rings); + } +if (!ndev)return -ENOMEM ;
Signature · 1 line
2.43.0
Quoted 6 lines · Shenwei Wang
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
GregKH and others will tell you this is a user space problem. Ethernet names have never been stable, user space has always had to deal with this problem. Please use a udev rule, systemd naming, etc.
Andrew
Quoted 18 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Wednesday, February 26, 2025 8:58 AM
To: Shenwei Wang <[email protected]>
Cc: Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Wei Fang <[email protected]>; Clark Wang <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH net-next] net: enetc: Support ethernet aliases in dts.Quoted 4 lines · Shenwei Wang
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
Quoted 6 lines
Quoted 2 lines
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
GregKH and others will tell you this is a user space problem. Ethernet names have never been stable, user space has always had to deal with this problem. Please use a udev rule, systemd naming, etc.
Thanks Andrew.
Does it mean the ethernet aliases defined in the dts are no longer recommended or supported?
Thanks,
Shenwei
Quoted 2 lines
Andrew
Vladimir Oltean
maintainerQuoted 23 lines · Shenwei Wang
Quoted 16 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Wednesday, February 26, 2025 8:58 AM
To: Shenwei Wang <[email protected]>
Cc: Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Wei Fang <[email protected]>; Clark Wang <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH net-next] net: enetc: Support ethernet aliases in dts.Quoted 4 lines · Shenwei Wang
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
Quoted 6 lines
Quoted 2 lines
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
GregKH and others will tell you this is a user space problem. Ethernet names have never been stable, user space has always had to deal with this problem. Please use a udev rule, systemd naming, etc.
Quoted 5 lines
Thanks Andrew.
Does it mean the ethernet aliases defined in the dts are no longer recommended or supported?Thanks,
Shenwei
Aliases are recommended at least for U-Boot fixups of any kind (MAC addresses, but not necessarily). You never want to perform a fixup based on a hardcoded node path.
Quoted 29 lines · Shenwei Wang
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
Signed-off-by Shenwei Wang <[email protected]>--- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/net/ethernet/freescale/enetc/enetc4_pf.c +5
-2@@ -622,10 +622,20 @@ static int enetc4_pf_netdev_create(struct enetc_si *si)struct device *dev = &si->pdev->dev;struct enetc_ndev_priv *priv;struct net_device *ndev; +char ifname[IFNAMSIZ ];int err; - ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), - si->num_tx_rings, si->num_rx_rings); + err =of_alias_get_id (dev->of_node,"ethernet" ); +if (err >=0 ) { +snprintf (ifname,IFNAMSIZ ,"eth%d" , err); + ndev = alloc_netdev_mqs(sizeof(struct enetc_ndev_priv),
drivers/net/ethernet/freescale/enetc/enetc4_pf.c static int enetc4_pf_netdev_create(struct enetc_si *si) · line 641
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +7
-0+ ifname,NET_NAME_PREDICTABLE , ether_setup, + si->num_tx_rings, si->num_rx_rings); + }else { + ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), + si->num_tx_rings, si->num_rx_rings); + } +if (!ndev)return -ENOMEM ;
Shenwei, you don't want the kernel to attempt to be very smart about the initial netdev naming. You will inevitably run into the situation where "eth%d" is already the name chosen for the kernel for a different net_device without a predictable name (e.g. e1000e PCIe card) which has been allocated already. Then you'll want to fix that somehow, and the stream of patches will never stop, because the kernel will never be able to fulfill all requirements. Look at the udev naming rules for dpaa2 and enetc on Layerscape and build something like that. DSA switch included - the "label" device tree property is considered legacy.
Quoted 48 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: Wednesday, February 26, 2025 9:48 AM
To: Shenwei Wang <[email protected]>
Cc: Claudiu Manoil <[email protected]>; Wei Fang <[email protected]>; Clark Wang <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; dl- linux-imx <[email protected]>
Subject: Re: [PATCH net-next] net: enetc: Support ethernet aliases in dts.drivers/net/ethernet/freescale/enetc/enetc4_pf.c static int enetc4_pf_netdev_create(struct enetc_si
Quoted 18 lines · Shenwei Wang
Retrieve the "ethernet" alias ID from the DTS and assign it as the interface name (e.g., "eth0", "eth1"). This ensures predictable naming aligned with the DTS's configuration.
If no alias is defined, fall back to the kernel's default enumeration to maintain backward compatibility.
Signed-off-by Shenwei Wang <[email protected]>--- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0
-0@@ -622,10 +622,20 @@ static int enetc4_pf_netdev_create(struct enetc_si*si)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c static int enetc4_pf_netdev_create(struct enetc_si *si)
Quoted 13 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +6
-2struct device *dev = &si->pdev->dev;struct enetc_ndev_priv *priv;struct net_device *ndev; +char ifname[IFNAMSIZ ];int err; - ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), - si->num_tx_rings, si->num_rx_rings); + err =of_alias_get_id (dev->of_node,"ethernet" ); +if (err >=0 ) { +snprintf (ifname,IFNAMSIZ ,"eth%d" , err); + ndev = alloc_netdev_mqs(sizeof(struct enetc_ndev_priv), + ifname, NET_NAME_PREDICTABLE,
ether_setup,
Quoted 14 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c static int enetc4_pf_netdev_create(struct enetc_si *si) · line 641
Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +6
-0+ si->num_tx_rings, si->num_rx_rings); + }else { + ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), + si->num_tx_rings, si->num_rx_rings); + } +if (!ndev)return -ENOMEM ;Shenwei, you don't want the kernel to attempt to be very smart about the initial netdev naming. You will inevitably run into the situation where "eth%d" is already the name chosen for the kernel for a different
net_devicewithout a predictable name (e.g. e1000e PCIe card) which has been allocated already. Then you'll want
The driver just provides an option to configure predictable interface naming. IMO, all those kind of naming conflicts should be managed by the DTS itself.
Quoted 3 lines
to fix that somehow, and the stream of patches will never stop, because the kernel will never be able to fulfill all requirements. Look at the udev naming rules for dpaa2 and enetc on Layerscape and build something like that. DSA switch
Even with the udev/systemd solution, you may still need to resolve the naming conflict sometimes among multiple cards.
Thanks,
Shenwei
Quoted 3 lines
included - the "label" device tree property is considered legacy.
Nacked-by Vladimir Oltean <[email protected]>
Vladimir Oltean
maintainerQuoted 7 lines · Shenwei Wang
Quoted 4 lines
Shenwei, you don't want the kernel to attempt to be very smart about the initial netdev naming. You will inevitably run into the situation where "eth%d" is already the name chosen for the kernel for a different
net_devicewithout a predictable name (e.g. e1000e PCIe card) which has been allocated already. Then you'll wantThe driver just provides an option to configure predictable interface naming. IMO, all those kind of naming conflicts should be managed by the DTS itself.
Good luck adding of_alias_get_id() patches to (and others) PCIe NIC drivers (with a real PCIe link layer, not Enhanced Allocation).
Quoted 6 lines
Quoted 3 lines
to fix that somehow, and the stream of patches will never stop, because the kernel will never be able to fulfill all requirements. Look at the udev naming rules for dpaa2 and enetc on Layerscape and build something like that. DSA switch
Even with the udev/systemd solution, you may still need to resolve the naming conflict sometimes among multiple cards.
Yet, the rootfs seems to be the only place to keep net device names that is sufficiently flexible to cover the variability in use cases. Maybe you're used to your developer position where you can immediately modify the device tree for a board, but one is supposed to be able to configure U-Boot to provide a fixed device tree (its own) to Linux. This is for example used for Arm SystemReady IR compliance with distributions, to my knowledge.
Quoted 36 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: Wednesday, February 26, 2025 11:11 AM
To: Shenwei Wang <[email protected]>
Cc: Claudiu Manoil <[email protected]>; Wei Fang <[email protected]>; Clark Wang <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; dl- linux-imx <[email protected]>
Subject: Re: [PATCH net-next] net: enetc: Support ethernet aliases in dts.Quoted 8 lines · Shenwei Wang
Quoted 5 lines
Shenwei, you don't want the kernel to attempt to be very smart about the initial netdev naming. You will inevitably run into the situation where "eth%d" is already the name chosen for the kernel for a different
net_devicewithout a predictable name (e.g. e1000e PCIe card) which has been allocated already. Then you'll wantThe driver just provides an option to configure predictable interface naming. IMO, all those kind of naming conflicts should be managed by the DTS
itself.
Good luck adding
of_alias_get_id()patches to (and others) PCIe NIC drivers (with a real PCIe link layer, not Enhanced Allocation).Quoted 7 lines
Quoted 4 lines
to fix that somehow, and the stream of patches will never stop, because the kernel will never be able to fulfill all requirements. Look at the udev naming rules for dpaa2 and enetc on Layerscape and build something like that. DSA switch
Even with the udev/systemd solution, you may still need to resolve the naming conflict sometimes among multiple cards.
Quoted 6 lines
Yet, the rootfs seems to be the only place to keep net device names that is sufficiently flexible to cover the variability in use cases. Maybe you're used to your developer position where you can immediately modify the device tree for a board, but one is supposed to be able to configure U-Boot to provide a fixed device tree (its own) to Linux. This is for example used for Arm SystemReady IR compliance with distributions, to my knowledge.
So my understanding here is that the primary purpose of Ethernet aliases in the kernel DTS is simply to provide U-Boot with easier access to specific Ethernet nodes?
Thanks,
Shenwei
Vladimir Oltean
maintainerQuoted 2 lines · Shenwei Wang
So my understanding here is that the primary purpose of Ethernet aliases in the kernel DTS is simply to provide U-Boot with easier access to specific Ethernet nodes?
This is what my limited experience is telling me, yes.