linux上安装网卡驱动程序

               

这篇日志记录在linux上安装网卡驱动的过程。使用dell的optiplex 360或者optiplex380机器,broadcom网卡,Centos 5.2, Fedora Core 8, Ubuntu9.0.4操作系统。实验室一直使用这种机器+网卡+操作系统的搭配,每次安装操作系统必定出现网卡驱动程序和声卡驱动程序无法使用的情况。因此,这一过程在实验室重复做了N遍。

首先看网卡是否已经正确连接到计算机。这一步一般是不会有问题的。使用的命令是lspci,在ubuntu下还可以使用lshw命令,输出如下:
redhat上使用lspci的输出:
[root@jcwkyl class]# lspci
00:00.0 Host bridge: Intel Corporation 82G33/G31/P35/P31 Express DRAM Controller (rev 0a)
00:01.0 PCI bridge: Intel Corporation 82G33/G31/P35/P31 Express PCI Express Root Port (rev 0a)
00:1b.0 Audio device: Intel Corporation N10/ICH 7 Family High Definition Audio Controller (rev 01)
00:1c.0 PCI bridge: Intel Corporation N10/ICH 7 Family PCI Express Port 1 (rev 01)
00:1d.0 USB Controller: Intel Corporation N10/ICH 7 Family USB UHCI Controller #1 (rev 01)
00:1d.1 USB Controller: Intel Corporation N10/ICH 7 Family USB UHCI Controller #2 (rev 01)
00:1d.2 USB Controller: Intel Corporation N10/ICH 7 Family USB UHCI Controller #3 (rev 01)
00:1d.3 USB Controller: Intel Corporation N10/ICH 7 Family USB UHCI Controller #4 (rev 01)
00:1d.7 USB Controller: Intel Corporation N10/ICH 7 Family USB2 EHCI Controller (rev 01)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev e1)
00:1f.0 ISA bridge: Intel Corporation 82801GB/GR (ICH7 Family) LPC Interface Bridge (rev 01)
00:1f.1 IDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01)
00:1f.2 IDE interface: Intel Corporation N10/ICH7 Family SATA IDE Controller (rev 01)
00:1f.3 SMBus: Intel Corporation N10/ICH 7 Family SMBus Controller (rev 01)
01:00.0 VGA compatible controller: ATI Technologies Inc RV610 video device [Radeon HD 2400 PRO]
02:00.0 Ethernet controller: Broadcom Corporation NetLink BCM5784M Gigabit Ethernet PCIe (rev 10)
Ubuntu上使用lshw命令的输出:
root@jcwkyl:~# lshw -C network
  *-network              
       description: Ethernet interface
       product: NetLink BCM5784M Gigabit Ethernet PCIe
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: peth0
       version: 10
       serial: 00:e0:4c:3d:aa:ba
       size: 100MB/s
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
      capabilities: pm vpd msi pciexpress bus_master cap_list ethernetphysical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
      configuration: autonegotiation=on broadcast=yes driver=tg3driverversion=3.92.1 duplex=full ip=10.60.59.31 latency=0 link=yesmodule=tg3 multicast=yes port=twisted pair promiscuous=yes speed=100MB/s

以上是网卡已经成功驱动后的输出。如果网卡没有正常驱动,则lshw的输出会有类似于*-network UNCLAIMED字样。
另外在lspci命令的输出中有可能会显示UnknownDevice,这是因为网卡的id没有被操作系统识别,可以运行update-pciids命令从网络上下载最新的pci设备的ID列表。这一步对安装驱动程序来说不是必须。如果计算机因为网卡驱动不能连接网络,手头又有一份最新的PCI设备ID,可以从manlspci中找到PCI设备ID列表文件所在位置,在Redhat下一般是/usr/share/hwdata/pci.ids,Ubuntu下是/usr/share/misc/pci.ids,可以手动替换ID列表文件。

接下来就是找到网卡的驱动程序。首先要把网卡的ID找到,使用lspci-n命令找到网卡ID,如上面的lspci命令所示,输出的第一列格式是bus:slot.func,如上的lspci输出结果,网卡的pcidomain是0000,bus是02,slot是00,func编号是0。这些信息结合起来可以惟一标识计算机上的一个PCI设备。通过这些信息可以找到PCI设备的厂商ID和设备ID,使用lspci -n参数,如下:
[root@jcwkyl class]# lspci -n
00:00.0 0600: 8086:29c0 (rev 0a)
00:01.0 0604: 8086:29c1 (rev 0a)
00:1b.0 0403: 8086:27d8 (rev 01)
00:1c.0 0604: 8086:27d0 (rev 01)
00:1d.0 0c03: 8086:27c8 (rev 01)
00:1d.1 0c03: 8086:27c9 (rev 01)
00:1d.2 0c03: 8086:27ca (rev 01)
00:1d.3 0c03: 8086:27cb (rev 01)
00:1d.7 0c03: 8086:27cc (rev 01)
00:1e.0 0604: 8086:244e (rev e1)
00:1f.0 0601: 8086:27b8 (rev 01)
00:1f.1 0101: 8086:27df (rev 01)
00:1f.2 0101: 8086:27c0 (rev 01)
00:1f.3 0c05: 8086:27da (rev 01)
01:00.0 0300: 1002:94c3
02:00.0 0200: 14e4:1698 (rev 10)
从这个输出中找到02:00.0的一行,从后面可以看到厂商ID是14e4,该厂商生产的这款网卡ID是1698。数字都是十六进制。这个时候就可以在google上搜索broadcom14e4:1698,在http://www.broadcom.com/support/ethernet_nic/determine_driver.php找到驱动程序下载。
到这一步也有另一种方法,在fedora core的bug list中有人提出fedora core不能识别broadcom57780型号的网卡,这个型号的网卡设备ID是1692。有人提出保证broadcom模块在tg3模块之前加载的话可以解决问题,我有一次确实这样把问题解决了,可以试一下这种方法。
在linux安装时的/lib/modules/$(uname-r)目录下有很多模块关系描述文件,比如modules.pcimap文件,这个文件中保存了PCI设备的驱动程序模块名称,厂商ID,设备ID对应表,比如在我的计算机上的这个文件中用可以找到我的网卡对应的驱动程序:
tg3                 0x000014e4 0x00001698 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0
可以看到我的计算机上网卡的驱动程序是tg3。

下载到tg3源代码后解压,进入解压后的Server/Linux/Driver/tg3-3.110g目录,在tg3.h文件中肯定能找到网卡ID的定义,如下:
#define  TG3PCI_DEVICE_TIGON3_57780      0x1692
如果没有的话,肯定是出问题了,必须重新找驱动程序源代码,手动加上不一定管用,自己也没试过。

然后是敲入make命令编译,可能会出错,和gcc版本以及代码都可能有关。出了错误也只是一些编译错误,根据错误修改tg3的源代码,再重新编译过就可以。make成功以后,可以先试一试,顺序敲入rmmod tg3, insmodtg3.ko,用ifconfig看一看是不是有eth0网卡了,如果还是没有eth0网卡,可能和上面说的模块加载顺序有关系,先rmmodtg3,然后modprobe broadcom, insmod tg3.ko,再看看。
最后使用make install命令把tg3.ko安装到/lib/module下面对应的位置。


           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43668159/article/details/86413512