[rtems-libbsd commit] freebsd/if_cgem: Fail probe for unterminated MII

Joel Sherrill joel at rtems.org
Thu Jul 15 15:07:22 UTC 2021


Module:    rtems-libbsd
Branch:    6-freebsd-12
Commit:    14576608a9477d7a29150a9ba8e73b32ecea9de4
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=14576608a9477d7a29150a9ba8e73b32ecea9de4

Author:    Kinsey Moore <kinsey.moore at oarcorp.com>
Date:      Fri Jul  9 09:47:34 2021 -0500

freebsd/if_cgem: Fail probe for unterminated MII

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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/freebsd/sys/dev/cadence/if_cgem.c b/freebsd/sys/dev/cadence/if_cgem.c
index 34df7ac..3eaaf6b 100644
--- a/freebsd/sys/dev/cadence/if_cgem.c
+++ b/freebsd/sys/dev/cadence/if_cgem.c
@@ -1953,6 +1953,25 @@ cgem_probe(device_t dev)
 
 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
 		return (ENXIO);
+#else /* __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;
 #endif /* __rtems__ */
 
 	device_set_desc(dev, "Cadence CGEM Gigabit Ethernet Interface");



More information about the vc mailing list