How to compile the Realtek 8169 driver with Linux kernel 3.8

I have a Realtek 8169 Ethernet card in my computer. Since I have been getting dropped frames with the driver that is included in the kernel, I have been compiling and using the one that is available from Realtek’s website for 8169 / 8110 cards.

When I upgraded to kernel 3.8, I discovered that the driver wouldn’t compile anymore. First of all, an include file was missing:

martin@martin-Dell-DXP061:/tmp/r8169-6.017.00$ make
make -C src/ clean
make[1]: Entering directory `/tmp/r8169-6.017.00/src'
make -C /lib/modules/3.8.0-19-generic/build SUBDIRS=/tmp/r8169-6.017.00/src clean
make[2]: Entering directory `/usr/src/linux-headers-3.8.0-19-generic'
make[2]: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic'
make[1]: Leaving directory `/tmp/r8169-6.017.00/src'
make -C src/ modules
make[1]: Entering directory `/tmp/r8169-6.017.00/src'
make -C /lib/modules/3.8.0-19-generic/build SUBDIRS=/tmp/r8169-6.017.00/src modules
make[2]: Entering directory `/usr/src/linux-headers-3.8.0-19-generic'
 CC [M] /tmp/r8169-6.017.00/src/r8169_n.o
/tmp/r8169-6.017.00/src/r8169_n.c:61:24: fatal error: asm/system.h: No such file or directory
compilation terminated.
make[3]: *** [/tmp/r8169-6.017.00/src/r8169_n.o] Error 1
make[2]: *** [_module_/tmp/r8169-6.017.00/src] Error 2
make[2]: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic'
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/tmp/r8169-6.017.00/src'
make: *** [modules] Error 2
martin@martin-Dell-DXP061:/tmp/r8169-6.017.00$

asm/system.h no longer exists in the 3.8 includes. After commenting the include, other errors show up:

martin@martin-Dell-DXP061:/tmp/r8169-6.017.00$ make
make -C src/ clean
make[1]: Entering directory `/tmp/r8169-6.017.00/src'
make -C /lib/modules/3.8.0-19-generic/build SUBDIRS=/tmp/r8169-6.017.00/src clean
make[2]: Entering directory `/usr/src/linux-headers-3.8.0-19-generic'
make[2]: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic'
make[1]: Leaving directory `/tmp/r8169-6.017.00/src'
make -C src/ modules
make[1]: Entering directory `/tmp/r8169-6.017.00/src'
make -C /lib/modules/3.8.0-19-generic/build SUBDIRS=/tmp/r8169-6.017.00/src modules
make[2]: Entering directory `/usr/src/linux-headers-3.8.0-19-generic'
 CC [M] /tmp/r8169-6.017.00/src/r8169_n.o
/tmp/r8169-6.017.00/src/r8169_n.c:2611:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rtl8169_init_one’
/tmp/r8169-6.017.00/src/r8169_n.c:2867:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rtl8169_remove_one’
/tmp/r8169-6.017.00/src/r8169_n.c:4199:12: error: ‘rtl8169_init_one’ undeclared here (not in a function)
/tmp/r8169-6.017.00/src/r8169_n.c:4200:2: error: implicit declaration of function ‘__devexit_p’ [-Werror=implicit-function-declaration]
/tmp/r8169-6.017.00/src/r8169_n.c:4200:25: error: ‘rtl8169_remove_one’ undeclared here (not in a function)
/tmp/r8169-6.017.00/src/r8169_n.c:2464:13: warning: ‘rtl8169_phy_power_up’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:3889:12: warning: ‘rtl8169_poll’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:450:21: warning: ‘rtl8169_xmii_reset_pending’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:465:21: warning: ‘rtl8169_xmii_link_ok’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:480:13: warning: ‘rtl8169_xmii_reset_enable’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:708:12: warning: ‘rtl8169_set_speed_xmii’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1021:13: warning: ‘rtl8169_gset_xmii’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1236:27: warning: ‘rtl8169_ethtool_ops’ defined but not used [-Wunused-variable]
/tmp/r8169-6.017.00/src/r8169_n.c:1271:13: warning: ‘rtl8169_get_mac_version’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1316:13: warning: ‘rtl8169_print_mac_version’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1321:13: warning: ‘rtl8169_get_phy_version’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1343:13: warning: ‘rtl8169_print_phy_version’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1645:13: warning: ‘rtl8169_release_board’ defined but not used [-Wunused-function]
/tmp/r8169-6.017.00/src/r8169_n.c:1732:13: warning: ‘rtl8169_init_phy’ defined but not used [-Wunused-function]
cc1: some warnings being treated as errors
make[3]: *** [/tmp/r8169-6.017.00/src/r8169_n.o] Error 1
make[2]: *** [_module_/tmp/r8169-6.017.00/src] Error 2
make[2]: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic'
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/tmp/r8169-6.017.00/src'
make: *** [modules] Error 2
martin@martin-Dell-DXP061:/tmp/r8169-6.017.00$

It turns out that the macros __devinit and __devexit no longer exist in kernel 3.8 and that’s why the compilation fails. The problem can be solved by removing these macros in file r8169_n.c . I have made a patch with these modifications. You can download it here.

To use it, copy the patch in the src subdirectory of the driver’s source and apply it like this:

martin@martin-Dell-DXP061:/tmp/r8169-6.017.00/src$ patch -p1 < r8169.patch

You should now be able to compile the driver module.

UPDATE: Try this version for newer kernels (tested on 3.10).