From 36fbaf137edf379ab8f8754aba04a765697459e9 Mon Sep 17 00:00:00 2001 From: Andreas Schaafsma Date: Sat, 17 Oct 2026 10:04:48 +0200 Subject: [PATCH] Harden RTL8125 recovery checks and reapply EEE settings --- modules/nixos/rtl8125-recovery/recover.sh | 13 +++++++++++-- .../hardware/hardware-configuration.nix | 11 ----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/nixos/rtl8125-recovery/recover.sh b/modules/nixos/rtl8125-recovery/recover.sh index d1a257e..b651423 100644 --- a/modules/nixos/rtl8125-recovery/recover.sh +++ b/modules/nixos/rtl8125-recovery/recover.sh @@ -3,6 +3,13 @@ set -euo pipefail nic="/sys/bus/pci/devices/$NIC_PCI" bridge="/sys/bus/pci/devices/$NIC_BRIDGE" log() { echo "rtl8125-recovery: $*"; } +disable_eee() { + local netdir + for netdir in "$nic"/net/*; do + [[ -e "$netdir/ifindex" ]] || continue + ethtool --set-eee "$(basename "$netdir")" eee off + done +} # Let normal PCI and network resume finish before diagnosing anything. sleep 10 @@ -28,9 +35,10 @@ if [[ -d "$nic" ]]; then command=$(timeout 5 setpci -s "$NIC_PCI" COMMAND 2>/dev/null || true) # Both memory decoding and bus mastering should be enabled on this host. # Disconnected cables do not disable these PCI command bits. - if [[ "$power" != D3cold && "$command" =~ ^[[:xdigit:]]{4}$ ]] && + if [[ "$power" == D0 && "$command" =~ ^[[:xdigit:]]{4}$ && "${command,,}" != ffff ]] && (( (16#$command & 6) == 6 )); then log "PCI state healthy ($power, COMMAND=$command); no recovery needed." + disable_eee exit 0 fi # An administratively disabled NIC should not be automatically reset. @@ -70,11 +78,12 @@ for ((attempt=0; attempt<20; attempt++)); do iface=$(basename "${netdirs[0]}") power=$(cat "$nic/power_state") command=$(timeout 5 setpci -s "$NIC_PCI" COMMAND 2>/dev/null || true) - if [[ "$power" == D0 && "$command" =~ ^[[:xdigit:]]{4}$ ]] && + if [[ "$power" == D0 && "$command" =~ ^[[:xdigit:]]{4}$ && "${command,,}" != ffff ]] && (( (16#$command & 6) == 6 )); then # NetworkManager also reapplies the saved profile. Explicitly # restore WoL here so recovery does not depend on its timing. ethtool -s "$iface" wol g + disable_eee if ! ethtool "$iface" | grep -Eq '^[[:space:]]*Wake-on: g$'; then log "PCI recovered, but magic-packet WoL could not be confirmed." exit 1 diff --git a/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix b/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix index d6f6ada..45a5945 100644 --- a/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix +++ b/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix @@ -22,17 +22,6 @@ boot.supportedFilesystems = [ "ntfs" ]; boot.blacklistedKernelModules = [ "r8169" ]; - systemd.services.disable-realtek-eee = { - description = "Disable Realtek Energy Efficient Ethernet"; - wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; - - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.ethtool}/bin/ethtool --set-eee enp10s0 eee off"; - RemainAfterExit = true; - }; - }; fileSystems."/" =