Harden RTL8125 recovery checks and reapply EEE settings

This commit is contained in:
2026-10-17 10:04:48 +02:00
parent 8c2dbe4775
commit 36fbaf137e
2 changed files with 11 additions and 13 deletions
+11 -2
View File
@@ -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
@@ -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."/" =