[PATCH 03/13] net: fsl_enetc: Fold DT MAC address update into enetc_set_ierb_primary_mac()

Marek Vasut marex at denx.de
Thu Jan 16 05:03:20 CET 2025


The entire content of the loop can be folded into enetc_set_ierb_primary_mac(),
do it. This changes the behavior slightly such that the DT is only updated in
case of a LS1028A, which is the only SoC with ethernet MAC path in DT matching
"/soc/pcie at 1f0000000/ethernet@%x,%x" anyway, so this slight change should have
no impact.

Signed-off-by: Marek Vasut <marex at denx.de>
---
Cc: Alice Guo <alice.guo at nxp.com>
Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
Cc: Jerome Forissier <jerome.forissier at linaro.org>
Cc: Joe Hershberger <joe.hershberger at ni.com>
Cc: Markus Gothe <markus.gothe at genexis.eu>
Cc: Peng Fan <peng.fan at nxp.com>
Cc: Ramon Fried <rfried.dev at gmail.com>
Cc: Robert Marko <robert.marko at sartura.hr>
Cc: Romain Naour <romain.naour at smile.fr>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tim Harvey <tharvey at gateworks.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Ye Li <ye.li at nxp.com>
Cc: u-boot at lists.denx.de
---
 drivers/net/fsl_enetc.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
index fc51647257e..826b1971bb0 100644
--- a/drivers/net/fsl_enetc.c
+++ b/drivers/net/fsl_enetc.c
@@ -40,12 +40,16 @@ static int enetc_is_ls1028a(struct udevice *dev)
 #define IERB_PFMAC(pf, vf, n)	(IERB_BASE + 0x8000 + (pf) * 0x100 + (vf) * 8 \
 				 + (n) * 4)
 
-static void enetc_set_ierb_primary_mac(struct udevice *dev, int devfn,
-				       const u8 *enetaddr)
+static void enetc_set_ierb_primary_mac(struct udevice *dev, void *blob)
 {
-	static int ierb_fn_to_pf[] = {0, 1, 2, -1, -1, -1, 3};
+	static int ierb_fn_to_pf[] = { 0, 1, 2, -1, -1, -1, 3 };
+	struct pci_child_plat *ppdata = dev_get_parent_plat(dev);
+	struct eth_pdata *pdata = dev_get_plat(dev);
+	const u8 *enetaddr = pdata->enetaddr;
 	u16 lower = *(const u16 *)(enetaddr + 4);
 	u32 upper = *(const u32 *)enetaddr;
+	int devfn, offset;
+	char path[256];
 
 	if (enetc_is_ls1028a(dev)) {
 		/*
@@ -53,24 +57,30 @@ static void enetc_set_ierb_primary_mac(struct udevice *dev, int devfn,
 		 * there are plans to change its structure, keep this
 		 * LS1028A specific for now.
 		 */
+		devfn = PCI_FUNC(ppdata->devfn);
+
 		if (ierb_fn_to_pf[devfn] < 0)
 			return;
 
 		out_le32(IERB_PFMAC(ierb_fn_to_pf[devfn], 0, 0), upper);
 		out_le32(IERB_PFMAC(ierb_fn_to_pf[devfn], 0, 1), (u32)lower);
+
+		snprintf(path, 256, "/soc/pcie at 1f0000000/ethernet@%x,%x",
+			 PCI_DEV(ppdata->devfn), PCI_FUNC(ppdata->devfn));
+	} else {
+		return;
 	}
+
+	offset = fdt_path_offset(blob, path);
+	if (offset >= 0)
+		fdt_setprop(blob, offset, "mac-address", pdata->enetaddr, 6);
 }
 
 /* sets up primary MAC addresses in DT/IERB */
 void fdt_fixup_enetc_mac(void *blob)
 {
-	struct pci_child_plat *ppdata;
-	struct eth_pdata *pdata;
 	struct udevice *dev;
 	struct uclass *uc;
-	char path[256];
-	int offset;
-	int devfn;
 
 	uclass_get(UCLASS_ETH, &uc);
 	uclass_foreach_dev(dev, uc) {
@@ -78,18 +88,7 @@ void fdt_fixup_enetc_mac(void *blob)
 		    strcmp(dev->driver->name, ENETC_DRIVER_NAME))
 			continue;
 
-		pdata = dev_get_plat(dev);
-		ppdata = dev_get_parent_plat(dev);
-		devfn = PCI_FUNC(ppdata->devfn);
-
-		enetc_set_ierb_primary_mac(dev, devfn, pdata->enetaddr);
-
-		snprintf(path, 256, "/soc/pcie at 1f0000000/ethernet@%x,%x",
-			 PCI_DEV(ppdata->devfn), PCI_FUNC(ppdata->devfn));
-		offset = fdt_path_offset(blob, path);
-		if (offset < 0)
-			continue;
-		fdt_setprop(blob, offset, "mac-address", pdata->enetaddr, 6);
+		enetc_set_ierb_primary_mac(dev, blob);
 	}
 }
 
-- 
2.45.2



More information about the U-Boot mailing list