# Kernel panic with Realtek r8169 and 5.3+ (SOLVED - Info

## depontius

This is solved, or at least a workaround, but I'm putting it here for information, in case it helps anyone.

My main system refused to boot kernel 5.3+, issuing a panic when it went to start the ethernet device. (Realtek that uses the r8169.ko kernel driver) To make a long story short, I found this: https://bugzilla.kernel.org/show_bug.cgi?id=204343 While this isn't really a fix, the workaround is to make sure the Realtek PHY driver (realtek.ko) is loaded before trying to start the ethernet device.  In my case, I added it to "/etc/conf.d/modules".

I'm happily running 5.4.1 now.

----------

## Tony0945

I've never had a problem.

```
tony@MSI ~ $ zgrep REALTEK /proc/config.gz

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_REALTEK_PHY=m

# CONFIG_WLAN_VENDOR_REALTEK is not set

CONFIG_SND_HDA_CODEC_REALTEK=m

# CONFIG_USB_STORAGE_REALTEK is not set

tony@MSI ~ $ zgrep R8169 /proc/config.gz

CONFIG_R8169=m

tony@MSI ~ $ uname -a

Linux MSI 5.3.14-gentoo-r1 #1 SMP Sun Dec 1 09:59:00 CST 2019 x86_64 AMD Ryzen 7 2700X Eight-Core Processor AuthenticAMD GNU/Linux
```

I think the difference is that I'm running gentoo-sources, not vanilla-sources.

----------

## depontius

 *Tony0945 wrote:*   

> I've never had a problem.
> 
> ```
> tony@MSI ~ $ zgrep REALTEK /proc/config.gz
> 
> ...

 

I'm running gentoo-sources, too.  Neither 5.3.x nor 5.4.x booted for me until I manually loaded the Realtek PHY module.  On the kernel bug report there was mention of needing kmod 26, but I've had that all along, too.

```
 $ zgrep REALTEK /proc/config.gz 

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_REALTEK_PHY=m

CONFIG_SND_HDA_CODEC_REALTEK=m

CONFIG_USB_STORAGE_REALTEK=m

CONFIG_REALTEK_AUTOPM=y

 $ zgrep R8169 /proc/config.gz 

CONFIG_R8169=m
```

----------

## Tony0945

 *depontius wrote:*   

> I'm running gentoo-sources, too.  Neither 5.3.x nor 5.4.x booted for me until I manually loaded the Realtek PHY module.

 

systemd, openrc or other? if openrc. which version?

----------

## Anon-E-moose

I have CONFIG_REALTEK_PHY=y with CONFIG_R8169=m but I'm only running 5.0.13, never had any problems though

----------

## Tony0945

 *Anon-E-moose wrote:*   

> I have CONFIG_REALTEK_PHY=y with CONFIG_R8169=m but I'm only running 5.0.13, never had any problems though

 

I believe you are running old OpenRC as am I. I specify in /etc/init.d/modules which modules to load.

I'm guessing that later OpenRC that loads all modules first loads them in the wrong order. Of course if you have =y instead of =m on PHY, it doesn't matter.

Or is my theory all wet?  I don't consciously load PHY at all. I surmise that R8169 loads it.

----------

## Anon-E-moose

CONFIG_REALTEK_PHY=y builds it in, not a module. 

But if it's a modules R8169 should load it, if not, then I would consider that a bug.

lsmod should show (if it's loaded and who caused it to be loaded)

Edit to add: I specifically made PHY be built in, it does get triggered if r8169 is selected, but it probably creates it as a module (or mirrors r8169 selection)

```
config R8169

    tristate "Realtek 8169 gigabit ethernet support"

    depends on PCI

    select FW_LOADER

    select CRC32

    select PHYLIB

    select REALTEK_PHY
```

----------

## depontius

I'm running current OpenRC.

I have always been building REALTEK_PHY, LIBPHY, and R8169 as modules, it just began failing as of 5.13.x, as someone else mentioned in the kernel bugzilla.  According to another posting, the realtek phy module should be getting autoloaded by r8169, but it's not.  Someone blamed in on kmod < 26, but I have kmod 26 and it's still a problem for me - until putting it in /etc/conf.d/modules.

The other trick about /etc/conf.d/modules is that it gets done in the boot runlevel - well before net.eth0, where it's really needed.  This presumes some other mechanism isn't trying to load everything it can, and loads them in the wrong order.

----------

## Anon-E-moose

 *depontius wrote:*   

> I'm running current OpenRC.
> 
> ...
> 
> This presumes some other mechanism isn't trying to load everything it can, and loads them in the wrong order.

 

Perhaps the current version of openrc is the culprit or openrc in conjunction with something in the newer kernels *shrugs*

----------

## Tony0945

Way old OpenRC here: 0.11

----------

## pdraganov

I had the same problem when upgraded from kernel 4.19.97 to 5.4.28. After reading this bug I changed the following kernel options in order to move modules to kernel:

```
# diff /boot/config-5.4.28-gentoo /boot/config-5.4.28-gentoo.old 

2241,2242c2241,2242

< CONFIG_MDIO_DEVICE=y

< CONFIG_MDIO_BUS=y

---

> CONFIG_MDIO_DEVICE=m

> CONFIG_MDIO_BUS=m

2247c2247

< CONFIG_PHYLIB=y

---

> CONFIG_PHYLIB=m

2283c2283

< CONFIG_REALTEK_PHY=y

---

> CONFIG_REALTEK_PHY=m
```

and created this file:

```
# cat /etc/modprobe.d/r8169.conf 

softdep r8169 pre: realtek
```

This fixed the problem in May 2020 but I upgraded now the kernel to 5.4.72 with "make syncconfig" and these changes no longer work for me. I tried also the following without success:

```
# diff /boot/config-5.4.72-gentoo /boot/config-5.4.72-gentoo.old 

2192c2192

< CONFIG_R8169=y

---

> CONFIG_R8169=m

# grep CONFIG_GENERIC_PHY= /boot/config-5.4.72-gentoo

CONFIG_GENERIC_PHY=y

# grep REALTEK /boot/config-5.4.28-gentoo

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_REALTEK_PHY=y

# CONFIG_WLAN_VENDOR_REALTEK is not set

CONFIG_SND_HDA_CODEC_REALTEK=m

# CONFIG_USB_STORAGE_REALTEK is not set
```

dmesg:

```
[    2.597007] r8169 0000:03:00.0: can't disable ASPM; OS doesn't have ASPM control

[    2.603467] libphy: r8169: probed

[    2.604862] r8169 0000:03:00.0: realtek.ko not loaded, maybe it needs to be added to initramfs?

[    2.606372] r8169: probe of 0000:03:00.0 failed with error -49
```

dmesg of working kernel 5.4.28:

```
[    3.537325] r8169 0000:03:00.0: can't disable ASPM; OS doesn't have ASPM control

[    3.547687] libphy: r8169: probed

[    3.551848] r8169 0000:03:00.0 eth0: RTL8168d/8111d, 1c:6f:65:43:f8:a0, XID 283, IRQ 29

[    3.554657] r8169 0000:03:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko]

[   23.212981] r8169 0000:03:00.0: Direct firmware load for rtl_nic/rtl8168d-2.fw failed with error -2

[   23.212992] r8169 0000:03:00.0: Unable to load firmware rtl_nic/rtl8168d-2.fw (-2)

[   23.213370] Generic PHY r8169-300:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=r8169-300:00, irq=IGNORE)

[   23.358023] r8169 0000:03:00.0 eth0: Link is Down

[   25.338479] r8169 0000:03:00.0 eth0: Link is Up - 100Mbps/Full - flow control off

# lspci

03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 03)

# lspci -n|grep 03:00.0

03:00.0 0200: 10ec:8168 (rev 03)

# depmod -V

kmod version 27

+XZ +ZLIB -LIBCRYPTO -EXPERIMENTAL
```

I generate initramfs with following command:

```
#genkernel --install initramfs
```

I have sys-apps/openrc-0.42.1:0::gentoo

Any idea how to make kernel 5.4.72 to use my Ethernet interface?

----------

## NeddySeagoon

pdraganov,

I have 

```
$ grep -e REALTEK -e 8169 /usr/src/linux/.config

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_R8169=y

CONFIG_REALTEK_PHY=y

```

Your card would like some firmware. 

```
[   23.212992] r8169 0000:03:00.0: Unable to load firmware rtl_nic/rtl8168d-2.fw (-2) 
```

Not providing it costs a 20 sec timeout.

Make everything built in, including the firmware, or make everything modular.  The firmware will be loaded from /lib/firmware if you install linux-firmware.

----------

## pdraganov

I have the same:

```
# grep -e REALTEK -e 8169 /usr/src/linux/.config

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_R8169=y

CONFIG_REALTEK_PHY=y
```

so everything is built in. I cannot install linux-firmware because it conflicts with sys-firmware/radeon-ucode-20161005:0/0::gentoo used for

```
CONFIG_EXTRA_FIRMWARE="radeon/R600_rlc.bin radeon/RS780_uvd.bin radeon/RS780_pfp.bin radeon/RS780_me.bin"
```

Probably I have to uninstall it? Will linux-firmware provide the same files? Anyway I rarely reboot Linux, so 20 seconds are not a big problem. But having network is obviously a must.  :Smile: 

----------

## Tony0945

Sounds like your system is similar to one of mine, but a bit newer.

```
 $ zgrep -e REALTEK -e 8169 /proc/config.gz

CONFIG_NET_VENDOR_REALTEK=y

CONFIG_R8169=m

CONFIG_REALTEK_PHY=m

CONFIG_SND_HDA_CODEC_REALTEK=m

# CONFIG_USB_STORAGE_REALTEK is not set

```

and

```
~ $ zgrep -e FIRMWARE /proc/config.gz |grep -v ^#

CONFIG_FIRMWARE_MEMMAP=y

CONFIG_PREVENT_FIRMWARE_BUILD=y

CONFIG_EXTRA_FIRMWARE="v4l-cx23418-enc.fw  radeon/R600_rlc.bin radeon/R600_uvd.bin radeon/RS780_pfp.bin radeon/RS780_me.bin"

CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"

CONFIG_FIRMWARE_EDID=y

```

 Ignore the v4l* firmware. It's for a TV card, totally unconnected to the radeon APU.   

I recall a conflict between the radeon _ucode ebuild and linux_ firmware as you say. I had to drop the radeon firmware ebuild.

```
~ $ grep firmware /var/lib/portage/world

sys-firmware/ivtv-firmware

sys-firmware/vgabios

sys-kernel/linux-firmware

[~ $ equery b radeon/R600_rlc.bin

 * Searching for radeon/R600_rlc.bin ... 

sys-kernel/linux-firmware-20201022-r2 (/lib/firmware/radeon/R600_rlc.bin)
```

 If your radeon chip is newer than what's in linux_firmware the you indeed have a conflict. 

EDIT:

Your radeon firmware is indeed in linux_firmware. I got suspicious when I noticed that your firmware was four years old.

```
 $ equery b  radeon/RS780_uvd.bin

 * Searching for radeon/RS780_uvd.bin ... 

sys-kernel/linux-firmware-20201022-r2 (/lib/firmware/radeon/RS780_uvd.bin)
```

----------

## NeddySeagoon

pdraganov,

Your radeon firmware is included in linux-firmware. I recall that it wasn't always like this.

You should be able to have both. The idea is that you install linux-firmware first, so there are no conflicts.

Edit its file in /etc/portage/savedconfig/sys-kernel/linux-firmware to remove the files that will be installed by sys-firmware/radeon-ucode.

Reinstall linux-firmware, so that it uses in new config.

Install sys-firmware/radeon-ucode.

Well behaved firmware packages are allowed to install together with linux-firmware if they detect the config file.

They only check for the existance of the file, not that it does what you want it to.

== Edit ==

The network firmware is a bug fix or enhancement. Its not required for the NIC to work.

----------

## pdraganov

Yes, I backed up /lib/firmware/radeon, removed radeon-ucode and installed linux-firmware, then compared my needed files - all were the same size and with same modification date, so I have fixed errors in 5.4.28:

```
[    3.556932] r8169 0000:03:00.0: can't disable ASPM; OS doesn't have ASPM control

[    3.571340] libphy: r8169: probed

[    3.573665] r8169 0000:03:00.0 eth0: RTL8168d/8111d, 1c:6f:65:43:f8:a0, XID 283, IRQ 29

[    3.576352] r8169 0000:03:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko]

[   26.368215] Generic PHY r8169-300:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=r8169-300:00, irq=IGNORE)

[   26.548014] r8169 0000:03:00.0 eth0: Link is Down

[   28.671235] r8169 0000:03:00.0 eth0: Link is Up - 100Mbps/Full - flow control off
```

As expected, this did not fix the problem with kernel 5.4.72

----------

## Anon-E-moose

what does modinfo r8169 return

 *pdraganov wrote:*   

> As expected, this did not fix the problem with kernel 5.4.72

 

What problem are you having with 5.4.72 and realtek?

Edit to add: have you also tried with a later version than 5.4.72, it may have had problems thus the reason it's not the last release.

----------

## Tony0945

5.4.80-r1 is now stable.

----------

## pdraganov

 *Quote:*   

> 5.4.80-r1 is now stable.

 

I installed 5.4.80-r1 now. I also removed genkernel-next (it is not available anymore) and installed genkernel.

 *Quote:*   

> what does modinfo r8169 return
> 
> What problem are you having with 5.4.72 and realtek?

 

```
# uname -a

Linux PC-L 5.4.80-gentoo-r1 #1 SMP Tue Dec 1 17:29:27 EET 2020 x86_64 AMD Phenom(tm) II X4 910e Processor AuthenticAMD GNU/Linux

# modinfo r8169

name:           r8169

filename:       (builtin)

firmware:       rtl_nic/rtl8125a-3.fw

firmware:       rtl_nic/rtl8107e-2.fw

firmware:       rtl_nic/rtl8107e-1.fw

firmware:       rtl_nic/rtl8168h-2.fw

firmware:       rtl_nic/rtl8168h-1.fw

firmware:       rtl_nic/rtl8168g-3.fw

firmware:       rtl_nic/rtl8168g-2.fw

firmware:       rtl_nic/rtl8106e-2.fw

firmware:       rtl_nic/rtl8106e-1.fw

firmware:       rtl_nic/rtl8411-2.fw

firmware:       rtl_nic/rtl8411-1.fw

firmware:       rtl_nic/rtl8402-1.fw

firmware:       rtl_nic/rtl8168f-2.fw

firmware:       rtl_nic/rtl8168f-1.fw

firmware:       rtl_nic/rtl8105e-1.fw

firmware:       rtl_nic/rtl8168e-3.fw

firmware:       rtl_nic/rtl8168e-2.fw

firmware:       rtl_nic/rtl8168e-1.fw

firmware:       rtl_nic/rtl8168d-2.fw

firmware:       rtl_nic/rtl8168d-1.fw

license:        GPL

softdep:        pre: realtek

description:    RealTek RTL-8169 Gigabit Ethernet driver

author:         Realtek and the Linux r8169 crew <netdev@vger.kernel.org>

parm:           debug:Debug verbosity level (0=none, ..., 16=all) (int)

# modinfo realtek

name:           realtek

filename:       (builtin)

license:        GPL

author:         Johnson Leung

description:    Realtek PHY driver

# dmesg

[    2.771066] r8169 0000:03:00.0: can't disable ASPM; OS doesn't have ASPM control

[    2.772937] libphy: r8169: probed

[    2.774300] r8169 0000:03:00.0: realtek.ko not loaded, maybe it needs to be added to initramfs?

[    2.775764] r8169: probe of 0000:03:00.0 failed with error -49
```

In https://bugzilla.kernel.org/show_bug.cgi?id=204343 Heiner Kallweit advised me to update BIOS or enable network boot ROM in BIOS. I will try second advise first, but I wonder why I had no problems for 10 years with this BIOS and kernel 4 and why after moving modules MDIO_DEVICE, MDIO_BUS, PHYLIB and REALTEK_PHY to kernel 5.4.28 it is also working.

----------

## Anon-E-moose

Highly unlikely that it has anything to do with network boot ROM, maybe a bios upgrade might make it work, but that wouldn't explain why it works with an older kernel.

Have you tried it with just the r8169 as a module? (I don't mean phylib or anything else supporting it, just the r8169 itself)

There may be a timing issue with something else it needs in the kernel not being ready when it's builtin.

----------

## pdraganov

Yes, r8169 is a module in working 5.4.28 and same configuration is the first I tried when I upgraded to 5.4.72. When it didn't work I tried to move it built in. I didn't try 5.4.80-r1 yet - probably this is next to try.

I tried all 4 combinations of old/new BIOS (F3 - F7, my motherboard is revision 2.1) and disabled/enabled boot ROM without success.

----------

## Anon-E-moose

These are what I have set for my 8169

```
CONFIG_NET_VENDOR_REALTEK=y

CONFIG_R8169=m

CONFIG_MDIO_DEVICE=y

CONFIG_MDIO_BUS=y

CONFIG_PHYLIB=y

CONFIG_REALTEK_PHY=y
```

If you use an initram, then you'll need the kernel module and the associated firmware files.

If it doesn't work on the latest 4 series, then I don't know where else to point you.

----------

## pdraganov

Returning R8169 as a module fixed the problem! 

```
CONFIG_R8169=m
```

Obviously this is the only working configuration and genkernel should be used instead of genkernel-next

----------

## Tony0945

I've read (here on the forum) that anything that runs as a module can be built-in, but it's never worked for me on video cards and a few other things.

----------

## Hu

I routinely run kernels without support for loadable modules, and have working video and network on them.  I will acknowledge though that it sometimes requires extra configuration, such as embedding relevant firmware in the kernel image.

----------

## Tony0945

 *Hu wrote:*   

> such as embedding relevant firmware in the kernel image.

 

That's probably the problem.

----------

