1. 程式人生 > >linux上安裝網絡卡驅動程式

linux上安裝網絡卡驅動程式

               

這篇日誌記錄在linux上安裝網絡卡驅動的過程。使用dell的optiplex 360或者optiplex380機器,broadcom網絡卡,Centos 5.2, Fedora Core 8, Ubuntu9.0.4作業系統。實驗室一直使用這種機器+網絡卡+作業系統的搭配,每次安裝作業系統必定出現網絡卡驅動程式和音效卡驅動程式無法使用的情況。因此,這一過程在實驗室重複做了N遍。

首先看網絡卡是否已經正確連線到計算機。這一步一般是不會有問題的。使用的命令是lspci,在ubuntu下還可以使用lshw命令,輸出如下:
redhat上使用lspci的輸出:
[

[email protected] 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命令的輸出:
[email protected]
:~# lshw -C network
  *-network              
       description: Ethernet interface
       product: NetLink BCM5784M Gigabit Ethernet PCIe
       vendor: Broadcom Corporation
       physical id: 0
       bus info:
[email protected]
: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引數,如下:
[[email protected] 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