[PATCH] net: fsl_enetc: fix all interfaces getting named enetc-0 on LS1028A

Vladimir Oltean <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
enetc_bind() names each interface by calling enetc_dev_id(), which for
LS1028A is supposed to return PCI_FUNC(pci_get_devfn(dev)) - the PCI
function number of each port, giving "enetc-0", "enetc-1", "enetc-2"
(and "enetc-6", if enabled).

The guard that selects this path is enetc_is_ls1028a(), which checks
pplat->vendor == PCI_VENDOR_ID_FREESCALE.  However, pplat->vendor is
not yet populated when enetc_bind() runs. It was thought this extra
check would not introduce a functional change, but it did.

The bind sequence in device_bind() calls uclass_bind_device() first,
which invokes pci_uclass_child_post_bind().  That callback tries to
parse the vendor ID from a "pciVVVV,DDDD"-format compatible string via
ofnode_read_pci_vendev(), but the LS1028A ENETC DT nodes carry
"fsl,enetc", not a PCI compatible - so pplat->vendor stays 0.

The actual PCI config-space read that sets pplat->vendor = 0x1957
happens only after device_bind() returns, when the PCI bus enumerator
processes the scanned BDF.  By that point enetc_bind() has already run
and named all three ports "enetc-0".

pci_get_devfn() is not affected by this ordering problem: it reads the
"reg" property of the DT node directly via ofnode_read_pci_addr(), and
is called by the same pci_uclass_child_post_bind() to populate
pplat->devfn before enetc_bind() is invoked.

Remove the enetc_is_ls1028a() guard from enetc_dev_id() and call
pci_get_devfn() unconditionally for the LS1028A path.  This is safe
because enetc_dev_id() is only reached from the ofnode_valid() branch
of enetc_bind(), and the iMX95 case is already handled above by
enetc_dev_id_imx() (which also reads the "reg" property directly).

Fixes: 4eb5ef73a956 ("net: fsl_enetc: Introduce enetc_dev_id()")
Signed-off-by: Vladimir Oltean <[email protected]>
---
 drivers/net/fsl_enetc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
index f393af40e275..0bff1cca4a6e 100644
--- a/drivers/net/fsl_enetc.c
+++ b/drivers/net/fsl_enetc.c
@@ -105,10 +105,8 @@ static int enetc_dev_id(struct udevice *dev)
 {
 	if (enetc_is_imx95(dev))
 		return enetc_dev_id_imx(dev);
-	if (enetc_is_ls1028a(dev))
-		return PCI_FUNC(pci_get_devfn(dev));
 
-	return 0;
+	return PCI_FUNC(pci_get_devfn(dev));
 }
 
 static void enetc_inval_rxbd(struct udevice *dev)
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.