From cca052338da5bde6aac735ef7cbc97d3b806ee2a Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Sun, 26 Jul 2026 20:15:57 +0900 Subject: [PATCH] rtl8168d: log link state at end of init() via phys_sts register The existing init() resets the chip, sets up descriptor rings, and enables TX+RX. It does not read phys_sts, so a driver that comes up on bare metal with the link not yet up (autoneg in progress, no cable, or forced-power-down from the BIOS) silently transmits into a dead medium. Add a single phys_sts read at the end of init(). The Realtek part numbers bits as: bit 0 = link up, bit 1 = 100 Mb/s, bit 2 = 1000 Mb/s, bits 4-5 = duplex encoding. When the link is not up, log a warn!() with the raw phys_sts byte so the operator can correlate with the link partner. When the link is up, log the detected speed as info!(). This is a real surface artefact (visible in the dmesg/log) and does NOT introduce any new registers or commands; the chip reports phys_sts on every read regardless of whether the driver queries it. The full PHY access (MII writes to PHY register 0x1F to read the chip version, then BMCR soft-reset + autoneg advertisement) remains [DEFERRED] until we have an MDIO read/write infrastructure exposed in redox-driver-sys or linux-kpi that works with the Redox MII bus scheme. --- drivers/net/rtl8168d/src/device.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/net/rtl8168d/src/device.rs b/drivers/net/rtl8168d/src/device.rs index f140a31243..de3da17bff 100644 --- a/drivers/net/rtl8168d/src/device.rs +++ b/drivers/net/rtl8168d/src/device.rs @@ -342,6 +342,31 @@ impl Rtl8168 { // Lock config self.regs.cmd_9346.write(0); + // Read physical link state. The Realtek part numbers its + // phys_sts bits: bit 0 = link up, bit 1 = speed-100, + // bit 2 = speed-1000, bits 4-5 encode the duplex. This is + // a read-only check; a failed link is not an error but + // produces a warning that helps diagnose a missing + // autonegotiation on bare metal. The driver continues to + // emit TX descriptors regardless; if no cable is present + // the peer simply does not reply. + let phys_sts = self.regs.phys_sts.read(); + if phys_sts & 0x01 == 0 { + log::warn!( + "rtl8168d: link is down at start; check cable / \ + autoneg status (phys_sts = 0x{:02x})", + phys_sts + ); + } else { + let mbps = match (phys_sts >> 4) & 0x03 { + 0b00 => 10, + 0b01 => 100, + 0b10 => 1000, + _ => 0, + }; + log::info!("rtl8168d: link up at {} Mb/s", mbps); + } + log::debug!("Complete!"); Ok(()) }