centos7.8降级网卡驱动r8168

概述

在外地集中开发临时租赁的window机器,临时组装成centos7.8系统的开发测试机器发现机器很不稳定,时不时宕机根据日志分析是驱动版本太高
因此,降级驱动版本保持和固件版本一致

r8168

fix(修复好的代码传到github)

问题

//01 队列传输超时
Oct 9 07:55:14 fatboy kernel: NETDEV WATCHDOG: p1p1 (bnx2): transmit queue 0 timed out

Oct 31 15:13:27 sy01 systemd: Started Session 83 of user weblogic.
Oct 31 15:25:06 sy01 kernel: ------------[ cut here ]------------
Oct 31 15:25:06 sy01 kernel: WARNING: CPU: 11 PID: 0 at net/sched/sch_generic.c:356 dev_watchdog+0x248/0x260
Oct 31 15:25:06 sy01 kernel: NETDEV WATCHDOG: enp1s0 (r8169): transmit queue 0 timed out
Oct 31 15:25:06 sy01 kernel: Modules linked in: tcp_diag inet_diag hp_wmi sparse_keymap rfkill intel_powerclamp coretemp kvm_intel snd_hda_codec_gen
eric kvm snd_hda_intel snd_hda_codec vfat irqbypass crc32_pclmul fat ghash_clmulni_intel snd_hda_core aesni_intel snd_hwdep lrw gf128mul glue_helper
 snd_seq ablk_helper cryptd snd_seq_device pcspkr snd_pcm snd_timer snd soundcore joydev wmi video tpm_crb intel_th_acpi intel_th acpi_pad ip_tables
 ext4 mbcache jbd2 ahci libahci libata crct10dif_pclmul crct10dif_common crc32c_intel serio_raw nvme r8169 nvme_core i2c_hid
Oct 31 15:25:06 sy01 kernel: CPU: 11 PID: 0 Comm: swapper/11 Kdump: loaded Not tainted 3.10.0-1127.el7.x86_64 #1
Oct 31 15:25:06 sy01 kernel: Hardware name: HP HP Pro SFF 280 G9 Desktop PC/89B4, BIOS F.02 05/05/2022
Oct 31 15:25:06 sy01 kernel: Call Trace:
Oct 31 15:25:06 sy01 kernel: <IRQ>  [<ffffffff8637ff85>] dump_stack+0x19/0x1b
Oct 31 15:25:06 sy01 kernel: [<ffffffff85c9bd18>] __warn+0xd8/0x100
Oct 31 15:25:06 sy01 kernel: [<ffffffff85c9bd9f>] warn_slowpath_fmt+0x5f/0x80
Oct 31 15:25:06 sy01 kernel: [<ffffffff862811e8>] dev_watchdog+0x248/0x260
Oct 31 15:25:06 sy01 kernel: [<ffffffff86280fa0>] ? dev_deactivate_queue.constprop.27+0x60/0x60
Oct 31 15:25:06 sy01 kernel: [<ffffffff85cac7c8>] call_timer_fn+0x38/0x110
Oct 31 15:25:06 sy01 kernel: [<ffffffff86280fa0>] ? dev_deactivate_queue.constprop.27+0x60/0x60
Oct 31 15:25:06 sy01 kernel: [<ffffffff85caec5d>] run_timer_softirq+0x24d/0x300
Oct 31 15:25:06 sy01 kernel: [<ffffffff85ca5695>] __do_softirq+0xf5/0x280
Oct 31 15:25:06 sy01 kernel: [<ffffffff8639642c>] call_softirq+0x1c/0x30
Oct 31 15:25:06 sy01 kernel: [<ffffffff85c2f715>] do_softirq+0x65/0xa0
Oct 31 15:25:06 sy01 kernel: [<ffffffff85ca5a15>] irq_exit+0x105/0x110
Oct 31 15:25:06 sy01 kernel: [<ffffffff863979c8>] smp_apic_timer_interrupt+0x48/0x60
Oct 31 15:25:06 sy01 kernel: [<ffffffff86393efa>] apic_timer_interrupt+0x16a/0x170
Oct 31 15:25:06 sy01 kernel: <EOI>  [<ffffffff861c6027>] ? cpuidle_enter_state+0x57/0xd0
Oct 31 15:25:06 sy01 kernel: [<ffffffff861c617e>] cpuidle_idle_call+0xde/0x230
Oct 31 15:25:06 sy01 kernel: [<ffffffff85c37c6e>] arch_cpu_idle+0xe/0xc0
Oct 31 15:25:06 sy01 kernel: [<ffffffff85d01c2a>] cpu_startup_entry+0x14a/0x1e0

//
For the "PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug", this is just a kernel information message, which suggests user to file a bug if the current setting doesn't work and boot option "pci=nocrs" is needed.

//查看异常日志
dmesg | grep bug
dmesg | grep fail

env

  • centos7.8 x86_64
//当前网卡驱动版本
[root@sy01 ~]# lsmod |grep -e '^r8169'
r8169                  84623  0 

modinfo r8169 |grep filename

[root@sy01 ~]# ethtool -i enp1s0
driver: r8169   //驱动版本高一个版本,需要降级下来
version: 
firmware-version: rtl8168h-2_0.0.2 02/26/15   //固件版本 r8168
expansion-rom-version: 
bus-info: 0000:01:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no

//查看网卡信息
[root@sy01 ~]# yum whatprovides */lspci
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
pciutils-3.5.1-3.el7.x86_64 : PCI bus related utilities
Repo        : yum_repos_iso
Matched from:
Filename    : /usr/sbin/lspci

yum install -y pciutils

[root@sy01 ~]# lspci
00:00.0 Host bridge: Intel Corporation Device 4650 (rev 05)
00:02.0 VGA compatible controller: Intel Corporation Device 4690 (rev 0c)
00:08.0 System peripheral: Intel Corporation Device 464f (rev 05)
00:0a.0 Signal processing controller: Intel Corporation Device 467d (rev 01)
00:14.0 USB controller: Intel Corporation Device 7ae0 (rev 11)
00:14.2 RAM memory: Intel Corporation Device 7aa7 (rev 11)
00:15.0 Serial bus controller [0c80]: Intel Corporation Device 7acc (rev 11)
00:16.0 Communication controller: Intel Corporation Device 7ae8 (rev 11)
00:17.0 SATA controller: Intel Corporation Device 7ae2 (rev 11)
00:1c.0 PCI bridge: Intel Corporation Device 7abe (rev 11)
00:1d.0 PCI bridge: Intel Corporation Device 7ab4 (rev 11)
00:1f.0 ISA bridge: Intel Corporation Device 7a85 (rev 11)
00:1f.3 Audio device: Intel Corporation Device 7ad0 (rev 11)
00:1f.4 SMBus: Intel Corporation Device 7aa3 (rev 11)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Device 7aa4 (rev 11)
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)  //型号
02:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd Device a809

01 reuirement

yum install -y gcc gcc-c++ kernel-devel

02 download

03 compiler

r8168-8.050.03.tar.gz

[root@sy03 r8168-8.050.03]# make modules 
make -C src/ modules
make[1]: Entering directory `/root/tmp/r8168-8.050.03/src'
make -C /lib/modules/3.10.0-1127.el7.x86_64/build M=/root/tmp/r8168-8.050.03/src modules
make[2]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
  CC [M]  /root/tmp/r8168-8.050.03/src/r8168_n.o
In file included from /root/tmp/r8168-8.050.03/src/r8168_n.c:87:0:
/root/tmp/r8168-8.050.03/src/r8168.h:53:20: error: redefinition of ‘ether_addr_copy’
 static inline void ether_addr_copy(u8 *dst, const u8 *src)
                    ^
In file included from /root/tmp/r8168-8.050.03/src/r8168_n.c:47:0:
include/linux/etherdevice.h:246:20: note: previous definition of ‘ether_addr_copy’ was here
 static inline void ether_addr_copy(u8 *dst, const u8 *src)
                    ^
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: error: unknown field ‘ndo_change_mtu’ specified in initializer
         .ndo_change_mtu     = rtl8168_change_mtu,
         ^
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: warning: missing braces around initializer [-Wmissing-braces]
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: warning: (near initialization for ‘rtl8168_netdev_ops.<anonymous>’) [-Wmissing-braces]
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: warning: initialization from incompatible pointer type [enabled by default]
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: warning: (near initialization for ‘rtl8168_netdev_ops.<anonymous>.ndo_get_stats64’) [enabled by default]
/root/tmp/r8168-8.050.03/src/r8168_n.c: In function ‘rtl8168_rx_interrupt’:
/root/tmp/r8168-8.050.03/src/r8168_n.c:29487:28: error: ‘struct net_device’ has no member named ‘last_rx’
                         dev->last_rx = jiffies;
                            ^
make[3]: *** [/root/tmp/r8168-8.050.03/src/r8168_n.o] Error 1
make[2]: *** [_module_/root/tmp/r8168-8.050.03/src] Error 2
make[2]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/root/tmp/r8168-8.050.03/src'
make: *** [modules] Error 2

04 resolve makeing error

//01
/root/tmp/r8168-8.050.03/src/r8168.h:53:20: error: redefinition of ‘ether_addr_copy’

vim +53 src/r8168.h

#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
// 改为 
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)

//02
/root/tmp/r8168-8.050.03/src/r8168_n.c:26768:9: error: unknown field ‘ndo_change_mtu’ specified in initializer

grep "ndo_change_mtu"  src/r8168_n.c

vim +26768  src/r8168_n.c
ndo_change_mtu  ->  ndo_change_mtu_rh74

// 解决方案
cat /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/netdevice.h | grep ndo_change_mtu
// 这个文件里面 ndo_change_mtu 定义的是什么名称,centos7.8是 ndo_change_mtu_rh74
// 在r8125_n.c的26768行保持和内核一致ndo_change_mtu  ->  ndo_change_mtu_rh74

//03
/root/tmp/r8168-8.050.03/src/r8168_n.c:29487:28: error: ‘struct net_device’ has no member named ‘last_rx’

vim +29487 src/r8168_n.c     //注释掉
    //dev->last_rx = jiffies;

make modules //编译,src/r8168.ko 内核驱动文件
make clean  //清理再次编译

05 install ko

//01 mv r8169
[root@sy03 r8168-8.050.03]# find  /lib/modules/3.10.0-1127.el7.x86_64/kernel/   -name "*r8169*"
/lib/modules/3.10.0-1127.el7.x86_64/kernel/drivers/net/ethernet/realtek/r8169.ko.xz

mv /lib/modules/3.10.0-1127.el7.x86_64/kernel/drivers/net/ethernet/realtek/r8169.ko.xz{,_bak}

//02 cp install
cp src/r8168.ko /lib/modules/3.10.0-1127.el7.x86_64/kernel/drivers/net/ethernet/realtek/
depmod -a  //刷新内核依赖
modprobe  r8168  //加载内核驱动r8168.ko

//03 view  current support Ethernet ko
[root@sy03 ~]# lspci -v
....
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06)
	Subsystem: Acer Incorporated [ALI] Device 102a
	Flags: bus master, fast devsel, latency 0, IRQ 18
	I/O ports at e000 [size=256]
	Memory at ef000000 (64-bit, non-prefetchable) [size=4K]
	Memory at e0000000 (64-bit, prefetchable) [size=16K]
	Capabilities: [40] Power Management version 3
	Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
	Capabilities: [70] Express Endpoint, MSI 01
	Capabilities: [b0] MSI-X: Enable+ Count=4 Masked-
	Capabilities: [d0] Vital Product Data
	Capabilities: [100] Advanced Error Reporting
	Capabilities: [140] Virtual Channel
	Capabilities: [160] Device Serial Number 01-00-00-00-68-4c-e0-00
	Kernel driver in use: r8169    //当前使用的ko
	Kernel modules: r8169, r8168  //内核中运行的ko

[root@sy03 ~]# 
[root@sy03 ~]# lspci -v |grep r81
	Kernel driver in use: r8169
	Kernel modules: r8169, r8168

//04 renew img
cp /boot/initramfs-3.10.0-1127.el7.x86_64.img{,_bak}
dracut -f /boot/initramfs-3.10.0-1127.el7.x86_64.img $(uname -r)
reboot

//05 check again
[root@sy03 ~]# ethtool -i enp1s0
driver: r8168   //网卡驱动已切换
version: 8.050.03-NAPI
firmware-version: 
expansion-rom-version: 
bus-info: 0000:01:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no
posted @ 2023-01-12 22:58  mvpbang  阅读(873)  评论(0编辑  收藏  举报