No spam. Not selling anything. Max 1-2 newsletters a month.

Kaveh's Blog logo

Personal blog

Kaveh Tehrani

Fixing Realtek drivers in Ubuntu

Published on
2 mins read

Recently I got a new laptop (Legion Pro 5) and installed my favorite Linux distro, Ubuntu, on it. Everything worked like a charm more or less out of the box, even with the Nvidia drivers! One small problem however floored me for a good day until I figured out the root cause.

Wifi not functioning after system wakeup from sleep

I tried every fix I could find. Restarted network services, tried to manually force the wifi drivers back up, disabled power savings, look in BIOS settings extensively for anything suspicious. Nothing worked. After wasting a couple hours I looked at the output of dmesg and right there I saw the problem. I could see the wifi being up but the driver could not wake up from sleep.

rtw89_8852ce 0000:01:00.0: can't change power state from D3hot to D0 (config space inaccessible)

After some search engine gymnastics found out a thread very similar to my issue. The only possible explanation is that the BIOS and Realtek drivers cannot communicate properly that the system has woken up from sleep. This explains why the driver works upon a system reboot but not waking up from sleep.

The solution is to take down the Realtek wifi drivers before the laptop goes to sleep and bring them back upon resuming.

Bash Script

Make a file in the folder /usr/lib/systemd/system-sleep. Put the bash script below in it:

#!/bin/sh

case "$1" in
    pre)
	modprobe -r rtw89_8852ce
	echo "we are suspending at $(date)..." > /tmp/systemd_suspend_rtw_driver
   	;;
    post)
        modprobe rtw89_8852ce
        ;;
esac

Replace rtw89_8852ce with your own driver if you're using a different one.

And there you have it. Hope this helps someone else given the popularity of Legion laptops. I am using Ubuntu 23.04 with 6.2.0-34 kernel.