[PATCH rtems-libbsd v2 1/2] freebsd/if_cgem: Fail probe for unterminated MII

Kinsey Moore kinsey.moore at oarcorp.com
Fri Jul 9 14:53:58 UTC 2021


When the MII bus is unterminated on unused interfaces, it results in PHY
read timeouts which manifest as spurious PHYs during the attach call.
Detect these timeouts during the probe so the device can be ignored.
---
 freebsd/sys/dev/cadence/if_cgem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/freebsd/sys/dev/cadence/if_cgem.c b/freebsd/sys/dev/cadence/if_cgem.c
index 34df7ac7..51e0bd6d 100644
--- a/freebsd/sys/dev/cadence/if_cgem.c
+++ b/freebsd/sys/dev/cadence/if_cgem.c
@@ -1955,6 +1955,24 @@ cgem_probe(device_t dev)
 		return (ENXIO);
 #endif /* __rtems__ */
 
+	struct cgem_softc *sc = device_get_softc(dev);
+	int val, rid = 0;
+
+	/* Check for PHY read timeouts which indicate an unterminated MII bus */
+	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
+					     RF_ACTIVE);
+
+	val = cgem_miibus_readreg(dev, 0, MII_BMSR);
+	if (val == -1) {
+		bus_release_resource(dev, SYS_RES_MEMORY, &rid,
+				     sc->mem_res);
+		sc->mem_res = NULL;
+		return (ENXIO);
+	}
+	bus_release_resource(dev, SYS_RES_MEMORY, &rid,
+			     sc->mem_res);
+	sc->mem_res = NULL;
+
 	device_set_desc(dev, "Cadence CGEM Gigabit Ethernet Interface");
 	return (0);
 }
-- 
2.20.1



More information about the devel mailing list