I tried to disable power saving on the "network card" in my odroid-mc1 (SBC like Raspberry Pi) which I use as network print server as my 3D printer can be controlled via USB and SD card . Per default powersaving is on and I assume this is cause of various USB-over-IP issues when the system is idle.
# lsusb
Bus 006 Device 002: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
The interface name is enx001e06373d78 and can be found in /sys/class/net/enx001e06373d78 and with the power management setting in power/control:
# cat /sys/class/net/enx001e06373d78/power/control
auto
As usual, settings in sysfs are not persisted and gone after a reboot or reconnect, it's not configurable via sysctl, so the most generic way is in udev and doing so makes it work with other USB ports, other devices, multiple device of the same type, etc.
Either edit an existing udev rule file in /etc/udev/rules.d/ or a create a new one like 99-my-powersettings.rules. The order in which udev rules are processed is sorted by the number in the file name and you want to do this after your network card is configured, so put it at the end.
Udev rules consist of conditions or "filters" and actions. Here are 3 rules that set power/control to on on the odroid-mc1:
# Condition: is network device, actions: write on into its power/control sysfs file (if it exists..)
#SUBSYSTEM=="net", ATTR{power/control}="on"
# Conditions: is network device and has productId 8513, actions: write on into its power/control sysfs file
SUBSYSTEM=="net", ATTRS{idProduct}=="8153" , ATTR{power/control}="on"
# Conditions: is network device and has productId 8513 and power/control is set to auto, then set it to on
#SUBSYSTEM=="net", ATTRS{idProduct}=="8153", ATTR{power/control}=="auto", ATTR{power/control}="on"
Parts with == are one type of conditions and single equal sign set values. You cat get a list of possible conditions with
# udevadm info -a -p /sys/class/net/enx001e06373d78
Be as generic or specific as you like.
Now the funny part and pitfall. It took me some time to get this working, the setting was never applied. Other people had the same issue, sometimes there was a solution provided which did not work.. The issue was that I tried to apply the setting to the "USB device", not the "network device". That does that mean.
In /etc/udev/rules.d/50-usb-realtek-net.rules is a rule (slightly modified for easier reading) for the NIC on the system:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bda", ATTR{idProduct}=="8153", ATTR{bConfigurationValue}!="$env{REALTEK_NIC_MODE}", ATTR{bConfigurationValue}="$env{REALTEK_NIC_MODE}"
which sets some NIC Mode, whatever this means. But this is my network chip, so I just add ATTR{power/control}="on" and it should never ever go into power management mode again?
Wrong. This operates on the USB endpoint:
# readlink -f /sys/class/net/enx001e06373d78/device
/sys/devices/platform/soc/soc:usb3-1/12400000.dwc3/xhci-hcd.8.auto/usb6/6-1/6-1:1.0
or shorter /sys/bus/usb/devices/6-1:1.0 which has the referenced bConfigurationValue:
# ls -al /sys/bus/usb/devices/6-1:1.0/
total 0
drwxr-xr-x 7 root root 0 Jul 15 04:46 .
drwxr-xr-x 6 root root 0 Jul 15 04:46 ..
-rw-r--r-- 1 root root 4096 Jul 15 04:51 authorized
-r--r--r-- 1 root root 4096 Jul 15 04:51 bAlternateSetting
-r--r--r-- 1 root root 4096 Jul 15 04:46 bInterfaceClass
-r--r--r-- 1 root root 4096 Jul 15 04:46 bInterfaceNumber
-r--r--r-- 1 root root 4096 Jul 15 04:51 bInterfaceProtocol
-r--r--r-- 1 root root 4096 Jul 15 04:51 bInterfaceSubClass
-r--r--r-- 1 root root 4096 Jul 15 04:51 bNumEndpoints
...
and it does not even have a power/control setting:
# ls -al /sys/bus/usb/devices/6-1:1.0/power
total 0
drwxr-xr-x 2 root root 0 Jul 15 04:46 .
drwxr-xr-x 7 root root 0 Jul 15 04:46 ..
-rw-r--r-- 1 root root 4096 Jul 15 04:51 async
-r--r--r-- 1 root root 4096 Jul 15 04:51 runtime_active_kids
-r--r--r-- 1 root root 4096 Jul 15 04:51 runtime_enabled
-r--r--r-- 1 root root 4096 Jul 15 04:51 runtime_status
-r--r--r-- 1 root root 4096 Jul 15 04:51 runtime_usage
And it's not even a network card, remember the NIC was in /sys/class/net, but the SUBSYSTEM in the rule is usb.. So my rule worked on the wrong device, on the "usb device" instead of the network device..
A few hours wasted on my first udev adventure & a lesson learned. Always work on the correct device.
Recent comments