网卡驱动编译
realtek 8125
1.查看网卡型号
lspci |grep -i eth
# 查看主板上识别到的网卡型号
如果没有lspci此命令,此命令对应包名为pciutils
2.下载对应驱动
https://www.realtek.com/zh-tw/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-pci-express-software
# 官网地址
3.编译环境准备
编译需要gcc kernel-headers以及kernel-devel包
yum -y install gcc kernel-headers kernel-devel
注:安装时选择对应内核版本的herads以及devel包 否则构建时会报错
[root@localhost opt]# yum list|grep kernel
kernel.x86_64 3.10.0-1160.el7 @anaconda
kernel-tools.x86_64 3.10.0-1160.el7 @anaconda
kernel-tools-libs.x86_64 3.10.0-1160.el7 @anaconda
abrt-addon-kerneloops.x86_64 2.1.11-60.el7.centos base
erlang-kernel.x86_64 R16B-03.18.el7 epel
kernel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-abi-whitelists.noarch 3.10.0-1160.62.1.el7 updates
kernel-debug.x86_64 3.10.0-1160.62.1.el7 updates
kernel-debug-devel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-devel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-doc.noarch 3.10.0-1160.62.1.el7 updates
kernel-headers.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs-devel.x86_64 3.10.0-1160.62.1.el7 updates
# 如在这个源中有updates源 下载会下载update源的包对应内核为3.10.0-1160.62.1而不是
3.10.0-1160。将源中的update源enabled=0。
4.编译
进入/root/r8125-9.008.00执行脚本./autorun.sh
Check old driver and unload it.
Build the module and install
In file included from /root/r8125-9.008.00/src/r8125_n.c:83:0:
/root/r8125-9.008.00/src/r8125.h:69:20: error: redefinition of ‘ether_addr_copy’
static inline void ether_addr_copy(u8 *dst, const u8 *src)
^
In file included from /root/r8125-9.008.00/src/r8125_n.c:43: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/r8125-9.008.00/src/r8125_n.c:12245:9: error: unknown field ‘ndo_change_mtu’ specified in initializer
.ndo_change_mtu = rtl8125_change_mtu,
^
/root/r8125-9.008.00/src/r8125_n.c:12245:9: warning: missing braces around initializer [-Wmissing-braces]
/root/r8125-9.008.00/src/r8125_n.c:12245:9: warning: (near initialization for ‘rtl8125_netdev_ops.<anonymous>’) [-Wmissing-braces]
/root/r8125-9.008.00/src/r8125_n.c:12245:9: warning: initialization from incompatible pointer type [enabled by default]
/root/r8125-9.008.00/src/r8125_n.c:12245:9: warning: (near initialization for ‘rtl8125_netdev_ops.<anonymous>.ndo_get_stats64’) [enabled by default]
/root/r8125-9.008.00/src/r8125_n.c: In function ‘rtl8125_poll_msix_other’:
/root/r8125-9.008.00/src/r8125_n.c:12395:22: warning: unused variable ‘work_to_do’ [-Wunused-variable]
unsigned int work_to_do = RTL_NAPI_QUOTA(budget, dev);
^
/root/r8125-9.008.00/src/r8125_n.c: In function ‘rtl8125_rx_interrupt’:
/root/r8125-9.008.00/src/r8125_n.c:15124:28: error: ‘struct net_device’ has no member named ‘last_rx’
dev->last_rx = jiffies;
^
make[3]: *** [/root/r8125-9.008.00/src/r8125_n.o] Error 1
make[2]: *** [_module_/root/r8125-9.008.00/src] Error 2
make[1]: *** [modules] Error 2
make: *** [modules] Error 2
#warming的可忽略,处理error即可
4.1 错误1
/root/r8125-9.008.00/src/r8125.h:69:20: error: redefinition of ‘ether_addr_copy’
打开对应头文件
vi +69 /root/r8125-9.008.00/src/r8125.h
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
static inline void ether_addr_copy(u8 *dst, const u8 *src)
{
将14修改为10
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
static inline void ether_addr_copy(u8 *dst, const u8 *src)
{
4.2 错误2
/root/r8125-9.008.00/src/r8125_n.c:12245:9: error: unknown field ‘ndo_change_mtu’ specified in initializer
使用cat /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/netdevice.h | grep ndo_change_mtu查看ndo_change_mtu对应为什么,此处为ndo_change_mtu_rh74
打开vi +12245 /root/r8125-9.008.00/src/r8125_n.c
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
static const struct net_device_ops rtl8125_netdev_ops = {
.ndo_open = rtl8125_open,
.ndo_stop = rtl8125_close,
.ndo_get_stats = rtl8125_get_stats,
.ndo_start_xmit = rtl8125_start_xmit,
.ndo_tx_timeout = rtl8125_tx_timeout,
.ndo_change_mtu = rtl8125_change_mtu,
.ndo_set_mac_address = rtl8125_set_mac_address,
.ndo_do_ioctl = rtl8125_do_ioctl,
修改为
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
static const struct net_device_ops rtl8125_netdev_ops = {
.ndo_open = rtl8125_open,
.ndo_stop = rtl8125_close,
.ndo_get_stats = rtl8125_get_stats,
.ndo_start_xmit = rtl8125_start_xmit,
.ndo_tx_timeout = rtl8125_tx_timeout,
.ndo_change_mtu_rh74 = rtl8125_change_mtu,
.ndo_set_mac_address = rtl8125_set_mac_address,
.ndo_do_ioctl = rtl8125_do_ioctl
4.3 错误3
/root/r8125-9.008.00/src/r8125_n.c:15124:28: error: ‘struct net_device’ has no member named ‘last_rx’
vi +15124 /root/r8125-9.008.00/src/r8125_n.c
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
dev->last_rx = jiffies;
修改为
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
//dev->last_rx = jiffies;
即注释即可
4.4 错误解决 再次执行编译脚本
./autorun.sh
5.驱动模块加载
modprobe r8125
# 此命令进行加载模块 如不使用此命令重启也可 重启会自动加载此模块
验证
[root@localhost r8125-9.008.00]# lsmod |grep 8125
r8125 168669 0
# 模块加载成功
WX1860A4
1.查看网卡型号
lspci |grep -i eth
# 查看主板上识别到的网卡型号
如果没有lspci此命令,此命令对应包名为pciutils
2.下载对应驱动
# 此为国产网卡,生产厂家为网讯
3.编译环境准备
编译需要gcc kernel-headers以及kernel-devel包
yum -y install gcc kernel-headers kernel-devel
注:安装时选择对应内核版本的herads以及devel包 否则构建时会报错
[root@localhost opt]# yum list|grep kernel
kernel.x86_64 3.10.0-1160.el7 @anaconda
kernel-tools.x86_64 3.10.0-1160.el7 @anaconda
kernel-tools-libs.x86_64 3.10.0-1160.el7 @anaconda
abrt-addon-kerneloops.x86_64 2.1.11-60.el7.centos base
erlang-kernel.x86_64 R16B-03.18.el7 epel
kernel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-abi-whitelists.noarch 3.10.0-1160.62.1.el7 updates
kernel-debug.x86_64 3.10.0-1160.62.1.el7 updates
kernel-debug-devel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-devel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-doc.noarch 3.10.0-1160.62.1.el7 updates
kernel-headers.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs-devel.x86_64 3.10.0-1160.62.1.el7 updates
# 如在这个源中有updates源 下载会下载update源的包对应内核为3.10.0-1160.62.1而不是
3.10.0-1160。将源中的update源enabled=0。
4.编译
4.1 make
cd ngbe-1.2.2rc1-220401/src
make
4.2 make install
make install
5.驱动模块加载
modprobe ngbe
# 此命令进行加载模块 如不使用此命令重启也可 重启会自动加载此模块
验证
[root@localhost src]# lsmod |grep ngbe
ngbe 168669 0
# 模块加载成功