public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: enetc: Support ethernet aliases in dts.
@ 2025-02-25 21:44 Shenwei Wang
  2025-02-26 14:57 ` Andrew Lunn
  2025-02-26 15:47 ` Vladimir Oltean
  0 siblings, 2 replies; 9+ messages in thread
From: Shenwei Wang @ 2025-02-25 21:44 UTC (permalink / raw)
  To: Claudiu Manoil, Vladimir Oltean, Wei Fang, Clark Wang,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: imx, netdev, linux-imx, 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 <shenwei.wang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
index fc41078c4f5d..5ec8dc59e809 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
@@ -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;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-26 20:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 21:44 [PATCH net-next] net: enetc: Support ethernet aliases in dts Shenwei Wang
2025-02-26 14:57 ` Andrew Lunn
2025-02-26 15:07   ` Shenwei Wang
2025-02-26 15:10     ` Vladimir Oltean
2025-02-26 15:47 ` Vladimir Oltean
2025-02-26 16:46   ` Shenwei Wang
2025-02-26 17:10     ` Vladimir Oltean
2025-02-26 17:43       ` Shenwei Wang
2025-02-26 20:02         ` Vladimir Oltean

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox