diff mbox series

[net-next] net: enetc: Support ethernet aliases in dts.

Message ID 20250225214458.658993-1-shenwei.wang@nxp.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: enetc: Support ethernet aliases in dts. | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for 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: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
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 fail net-next-2025-02-26--00-00 (tests: 658)

Commit Message

Shenwei Wang Feb. 25, 2025, 9:44 p.m. UTC
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 mbox series

Patch

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;