From 14576608a9477d7a29150a9ba8e73b32ecea9de4 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Fri, 9 Jul 2021 09:47:34 -0500 Subject: 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 34df7ac7..3eaaf6b2 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"); -- cgit v1.2.3