怎么写linux网卡驱动程序

怎么写linux网卡驱动程序,第1张

1

方法一:

1:ethtool -i ethx

如:

linux:/mnt # ethtool -i eth1

driver: e1000e

version: 1.0.2-k2

firmware-version: 1.9-0

bus-info: 0000:0b:00.0

linux:/mnt # ethtool -i eth16

driver: igb

version: 2.1.0-k2

firmware-version: 1.4-1

bus-info: 0000:0a:00.0

linux:/mnt #

2:使用 modinfo igb 查看驱动信息

linux:~ # modinfo igb

filename: /lib/modules/2.6.32.12-0.7-default/kernel/drivers/net/igb/igb.ko

version:5.2.5

license:GPL

description:Intel(R) Gigabit Ethernet Network Driver

author: Intel Corporation, <e1000-devel@lists.sourceforge.net>

srcversion: 0E80ABCD0117D822FE8B271

alias: pci:v00008086d000010D6sv*sd*bc*sc*i*

alias: pci:v00008086d000010A9sv*sd*bc*sc*i*

alias: pci:v00008086d000010A7sv*sd*bc*sc*i*

alias: pci:v00008086d000010E8sv*sd*bc*sc*i*

alias: pci:v00008086d00001526sv*sd*bc*sc*i*

alias: pci:v00008086d0000150Dsv*sd*bc*sc*i*

alias: pci:v00008086d000010E7sv*sd*bc*sc*i*

alias: pci:v00008086d000010E6sv*sd*bc*sc*i*

alias: pci:v00008086d00001518sv*sd*bc*sc*i*

alias: pci:v00008086d0000150Asv*sd*bc*sc*i*

alias: pci:v00008086d000010C9sv*sd*bc*sc*i*

alias: pci:v00008086d00000440sv*sd*bc*sc*i*

alias: pci:v00008086d0000043Csv*sd*bc*sc*i*

alias: pci:v00008086d0000043Asv*sd*bc*sc*i*

alias: pci:v00008086d00000438sv*sd*bc*sc*i*

alias: pci:v00008086d00001516sv*sd*bc*sc*i*

alias: pci:v00008086d00001511sv*sd*bc*sc*i*

alias: pci:v00008086d00001510sv*sd*bc*sc*i*

alias: pci:v00008086d00001527sv*sd*bc*sc*i*

alias: pci:v00008086d0000150Fsv*sd*bc*sc*i*

alias: pci:v00008086d0000150Esv*sd*bc*sc*i*

alias: pci:v00008086d00001524sv*sd*bc*sc*i*

alias: pci:v00008086d00001523sv*sd*bc*sc*i*

alias: pci:v00008086d00001522sv*sd*bc*sc*i*

alias: pci:v00008086d00001521sv*sd*bc*sc*i*

alias: pci:v00008086d00001539sv*sd*bc*sc*i*

alias: pci:v00008086d0000157Csv*sd*bc*sc*i*

alias: pci:v00008086d0000157Bsv*sd*bc*sc*i*

alias: pci:v00008086d00001538sv*sd*bc*sc*i*

alias: pci:v00008086d00001537sv*sd*bc*sc*i*

alias: pci:v00008086d00001536sv*sd*bc*sc*i*

alias: pci:v00008086d00001533sv*sd*bc*sc*i*

alias: pci:v00008086d00001F45sv*sd*bc*sc*i*

alias: pci:v00008086d00001F41sv*sd*bc*sc*i*

alias: pci:v00008086d00001F40sv*sd*bc*sc*i*

depends:hwmon,dca

supported: external

vermagic: 2.6.32.12-0.7-default SMP mod_unload modversions

parm: InterruptThrottleRate:Maximum interrupts per second, per vector, (max 100000), default 3=adaptive (array of int)

parm: IntMode:Change Interrupt Mode (0=Legacy, 1=MSI, 2=MSI-X), default 2 (array of int)

parm: Node:set the starting node to allocate memory on, default -1 (array of int)

parm: LLIPort:Low Latency Interrupt TCP Port (0-65535), default 0=off (array of int)

parm: LLIPush:Low Latency Interrupt on TCP Push flag (0,1), default 0=off (array of int)

parm: LLISize:Low Latency Interrupt on Packet Size (0-1500), default 0=off (array of int)

parm: RSS:Number of Receive-Side Scaling Descriptor Queues (0-8), default 1, 0=number of cpus (array of int)

parm: VMDQ:Number of Virtual Machine Device Queues: 0-1 = disable, 2-8 enable, default 0 (array of int)

parm: max_vfs:Number of Virtual Functions: 0 = disable, 1-7 enable, default 0 (array of int)

parm: MDD:Malicious Driver Detection (0/1), default 1 = enabled. Only available when max_vfs is greater than 0 (array of int)

parm: QueuePairs:Enable Tx/Rx queue pairs for interrupt handling (0,1), default 1=on (array of int)

parm: EEE:Enable/disable on parts that support the feature (array of int)

parm: DMAC:Disable or set latency for DMA Coalescing ((0=off, 1000-10000(msec), 250, 500 (usec)) (array of int)

parm: LRO:Large Receive Offload (0,1), default 0=off (array of int)

parm: enable_debug:Set to 1 to enable debug tracing into the syslog (uint)

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

linux:~ #

2

方法二:

1:dmesg | grep ethx

如:

linux:~ # dmesg | grep eth17

[ 30.351872] igb 0000:0a:00.1: eth17: (PCIe:2.5Gb/s:Width x4) 00:0b:ab:52:fb:b3

[ 30.351952] igb 0000:0a:00.1: eth17: PBA No: ffffff-0ff

[429171.548763] device eth17 entered promiscuous mode

[429173.116530] igb: eth17 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

[429173.118867] ADDRCONF(NETDEV_UP): eth17: link is not ready

[429173.121176] ADDRCONF(NETDEV_CHANGE): eth17: link becomes ready

[429183.236266] eth17: no IPv6 routers present

[1641503.272376] igb 0000:0a:00.1: eth17: (PCIe:2.5Gb/s:Width x4) 00:0b:ab:52:fb:b3

[1641503.272460] igb 0000:0a:00.1: eth17: PBA No: ffffff-0ff

[1641598.356110] device eth17 entered promiscuous mode

[1641598.369229] igb: eth17 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

[1641598.372636] ADDRCONF(NETDEV_UP): eth17: link is not ready

[1641598.374978] ADDRCONF(NETDEV_CHANGE): eth17: link becomes ready

[1641608.564181] eth17: no IPv6 routers present

[1701779.787471] igb 0000:0a:00.1: eth17: (PCIe:2.5GT/s:Width x4)

[1701779.787473] igb 0000:0a:00.1: eth17: MAC: 00:0b:ab:52:fb:b3

[1701779.787555] igb 0000:0a:00.1: eth17: PBA No: FFFFFF-0FF

[1702124.805650] device eth17 entered promiscuous mode

[1702141.839131] ADDRCONF(NETDEV_UP): eth17: link is not ready

[1702144.057474] igb: eth17 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None

[1702144.059425] ADDRCONF(NETDEV_CHANGE): eth17: link becomes ready

[1702154.705520] eth17: no IPv6 routers present

[1712008.630151] igb 0000:0a:00.1: eth17: (PCIe:2.5GT/s:Width x4)

[1712008.630153] igb 0000:0a:00.1: eth17: MAC: 00:0b:ab:52:fb:b3

[1712008.630235] igb 0000:0a:00.1: eth17: PBA No: FFFFFF-0FF

[1712100.136186] device eth17 entered promiscuous mode

[1712101.873823] ADDRCONF(NETDEV_UP): eth17: link is not ready

[1712104.159209] igb: eth17 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None

[1712104.161548] ADDRCONF(NETDEV_CHANGE): eth17: link becomes ready

[1712114.854722] eth17: no IPv6 routers present

linux:~ #

2:使用 modinfo igb 查看驱动信息

(结果同方法一中的)

linux的驱动一般有两种格式,分别为:tar和rpm格式。

rpm安装步骤:

1.将驱动程序文件bcm5700-.src.rpm复制到一个临时目录中,并在此目录中运行以下命令

rpm –ivh bcm5700-.src.rpm

2.运行以下命令切换到驱动目录中:

cd /usr/src/redhat/SPECS/

3.此目录中会生成一个名字为bcm5700.spec的文件,运行以下命令对驱动程序进行编译:

rpmbuild –bb bcm5700.spec (对4.x.x版本的RPM适用)或 rpm -bb bcm5700.spec

4.运行以下命令切换到RPM目录中:

cd /usr/src/redhat/RPMS/i386/

5.运行以下命令安装驱动程序:

rpm –ivh bcm5700-.i386.rpm (对于Red Hat 7.2, 7.3, 2.1AS和其他包含老版本驱动的系统需要使用--force的参数,强制用新的驱动替换系统自带的老版本驱动)

6.运行以下命令加载驱动模块:

insmod bcm5700

7.运行kudzu命令,系统会自动搜索到硬件,进行配置即可。

或者重新启动系统,启动过程中系统会自动找到硬件,进行相应配置即可。

tar格式安装步骤:

1. 将驱动程序压缩文件bcm5700-.tar.gz复制到一个临时目录中,并使用以下命令解压缩:

tar xvzf bcm5700-.tar.gz

2.构建驱动程序为运行内核可加载模块

cd bcm5700-/src

make

3.加载测试

insmod bcm5700

4.加载驱动程序

make install

5.重新启动系统,启动过程中找到硬件,进行相应配置。

或者直接运行kudzu命令,系统会自动搜索到硬件,进行配置即可。

Linux下查看网卡驱动和版本信息查看网卡生产厂商和信号查看基本信息:lspci查看详细信息:lspci -vvv # 3个小写的v查看网卡信息:lspci | grep Ethernet查看网卡驱动查看网卡驱动信息:lspci -vvv # 找到网卡设备的详细信息,包括网卡驱动# lsmod列出加载的所有驱动,包括网卡驱动 查看网卡驱动版本 查看模块信息:modifo<module name> # 其中包含version信息 或 # ethtool-i <device name>RHEL 6.3中的网卡驱动版本:# modinfo igbfilename: /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/igb/igb.koversion: 3.2.10-klicense:GPLdescription:Intel(R) Gigabit Ethernet Network Driver# modinfo e1000efilename: /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/e1000e/e1000e.koversion: 1.9.5-klicense:GPLdescription:Intel(R) PRO/1000 Network Driverauthor:Intel Corporation,<linux.nics@intel.com># modinfo e1000filename: /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/e1000/e1000.koversion: 8.0.35-NAPIlicense:GPLdescription:Intel(R) PRO/1000 Network Driver# modinfo ixgbefilename: /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/ixgbe/ixgbe.koversion: 3.6.7-klicense:GPLdescription:Intel(R) 10 Gigabit PCI Express NetworkDriver# modinfo r8169filename: /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/r8169.koversion: 2.3LK-NAPIlicense:GPLdescription:RealTek RTL-8169 Gigabit Ethernet driver查看网络接口队列数 查看网卡接口的中断信息:#cat /proc/interrupts | grep eth0 或 # ethtool-S eth0查看网卡驱动源码的版本号 解压Intel网卡驱动源码,打开解压缩目录下的*.spec文件查看驱动的版本。 例如:解压e1000-8.0.35.tar.gz网卡驱动后,查看e1000.spec文件。Name:e1000Summary:Intel(R) Gigabit Ethernet ConnectionVersion: 8.0.35Release:1Source:%{name}-%{version}.tar.gzVendor:Intel CorporationLicense:GPLExclusiveOS:linuxGroup:System Environment/Kernel 在驱动源码src目录中查找:#grep DRV_VERSION * # forLinux#findstr DRV_VERSION * # for Windows在e1000_main.c中也能找到定义驱动版本的一行:#define DRV_VERSION"8.0.35" DRV_NAPI DRV_DEBUG DRV_HW_PERF在e1000e中src目录下netdev.c文件:#define DRV_VERSION"3.0.4.1" DRV_EXTRAVERSIONigb_main.c:#define MAJ 5#define MIN 2#define BUILD 9.4#define DRV_VERSION__stringify(MAJ) "." __stringify(MIN) "."\ixgbe_main.c:#define DRV_VERSION__stringify(3.22.3) DRIVERIOVDRV_HW_PERF FP GA \


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7226468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存