realtek r8168 driver compile errors on kernel 5.8.0-50, (On 20.04.1 LTS)

I'm trying to get r8168-dkms to install on a fresh install of 20.04.1, to my new AMD Ryzen pc, but it's getting a compile error.

uname -a output: 
Linux terry-pc 5.8.0-50-generic #56~20.04.1-Ubuntu SMP Mon Apr 12 21:46:35 UTC 
2021 x86_64 x86_64 x86_64 GNU/Linux

dpkg -i r8168-dkms_8.048.00-1_all.deb

make.log:

DKMS make.log for r8168-8.048.00 for kernel 5.8.0-50-generic (x86_64) Fri 23 Apr 2021 12:09:08 PM PDT make: Entering directory '/usr/src/linux-headers-5.8.0-50-generic' AR /var/lib/dkms/r8168/8.048.00/build/built-in.a CC [M] /var/lib/dkms/r8168/8.048.00/build/r8168_n.o CC [M] /var/lib/dkms/r8168/8.048.00/build/r8168_asf.o CC [M] /var/lib/dkms/r8168/8.048.00/build/rtl_eeprom.o CC [M] /var/lib/dkms/r8168/8.048.00/build/rtltool.o /var/lib/dkms/r8168/8.048.00/build/r8168_n.c: In function ‘rtl8168_proc_init’: /var/lib/dkms/r8168/8.048.00/build/r8168_n.c:1670:47: error: passing argument 4 of ‘proc_create_data’ from incompatible pointer type [-Werror=incompatible-pointer-types] 1670 | &rtl8168_proc_fops, f->show)) { | ^~~~~~~~~~~~~~~~~~ | | | const struct file_operations * In file included from /var/lib/dkms/r8168/8.048.00/build/r8168_n.c:92: ./include/linux/proc_fs.h:103:31: note: expected ‘const struct proc_ops *’ but argument is of type ‘const struct file_operations *’ 103 | extern struct proc_dir_entry *proc_create_data(const char , umode_t, | ^~~~~~~~~~~~~~~~ /var/lib/dkms/r8168/8.048.00/build/r8168_n.c: At top level: /var/lib/dkms/r8168/8.048.00/build/r8168_n.c:25825:31: error: initialization of ‘void ()(struct net_device , unsigned int)’ from incompatible pointer type ‘void ()(struct net_device *)’ [-Werror=incompatible-pointer-types] 25825 | .ndo_tx_timeout = rtl8168_tx_timeout, | ^~~~~~~~~~~~~~~~~~ /var/lib/dkms/r8168/8.048.00/build/r8168_n.c:25825:31: note: (near initialization for ‘rtl8168_netdev_ops.ndo_tx_timeout’) cc1: some warnings being treated as errors make[1]: *** [scripts/Makefile.build:284: /var/lib/dkms/r8168/8.048.00/build/r8168_n.o] Error 1 make: *** [Makefile:1783: /var/lib/dkms/r8168/8.048.00/build] Error 2 make: Leaving directory '/usr/src/linux-headers-5.8.0-50-generic'

Has anyone hit this, and fixed it?


Solution 1:

06 Dec 2021: Updating answer for version 8.049.02

Make sure to change your version of the driver and kernel as needed.

Now that you have the r8168-8.049.02 driver installed from Realtek it unfortunately does not contain the DKMS info for the driver to be taken over into new kernel updates.

To resolve this, we are going to create a dkms.conf file for this driver.

Create a folder for the new driver:

sudo mkdir /usr/src/r8168-8.049.02

Then go to the folder with the r8168 driver (or download and extract the driver from here) that was extracted and copy all of its contents to the newly created folder:

sudo cp * /usr/src/r8168-8.049.02/

Then create a new dkms.conf file in the new source folder:

sudo nano /usr/src/r8168-8.049.02/dkms.conf

and add the following lines to the file:

PACKAGE_NAME="r8168"
PACKAGE_VERSION="8.049.02"
BUILT_MODULE_NAME[0]="$PACKAGE_NAME"
DEST_MODULE_LOCATION[0]="/updates/dkms"
AUTOINSTALL="YES"
REMAKE_INITRD="YES"

Then save and close the file.

Now we're going to add the dkms driver to the kernel:

sudo dkms add -m r8168 -v 8.049.02
sudo dkms build -m r8168 -v 8.049.02
sudo dkms install -m r8168 -v 8.049.02

Then check the driver with dkms status. If you see something about the driver that is built being different than the currently installed driver, run the following line to correct it:

sudo dkms uninstall -m r8168 -v 8.049.02 -k 5.8.0-50-generic && sudo dkms install -m r8168 -v 8.049.02 -k 5.8.0-50-generic --force

From now on with new kernel updates and upgrades the driver should now install automatically into the new kernel.

Hope this helps!