Command-lspci详解

Pci number

在PCI或者说PCIe里,每个设备有三个编号:总线编号(Bus Number)、设备编号(Device Number)和功能编号(Function Number)

那么对应上面的00:19.0来说:这个设备的BusNumber是00,DeviceNumber是19,FunctionNumber是0,需要说明的是这三个都是16进制表示,有些配置里需要填十进制数的,需要做下转换。

在linux里还有一个编号,叫做DomainNumber,不过上面的输出中没有,因为都是0,所以就忽略了,理论上,一个Segment可以有256个Bus,每个Bus可以有32个Device,每个Device可以有8个Function,在一些场景下,比如设备特别多,是会有多个Domain的,在硬件层面对应多个PCI Segment,在这种情况下,或者使用lspci -D命令,输出就会带上DomainNumber,比如我们一台服务器的输出:

Pci File

[root@localhost~]# lspci -s 08:00.0 -nn

08:00.0 Ethernet controller [0200]: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ [8086:37d3] (rev 09)

lspci命令是怎么能知道08:00.0这个设备就是个Ethernet controller,并且是Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)的呢?

前面的[0200]表示了当前设备的DeviceClass,也就是设备类型,而后面的[8086:37d3]代表的就是设备的VendorID和DeviceID,lspci命令会默认尝试读取/usr/share/hwdata/pci.ids.gz和/usr/share/hwdata/pci.ids文件,利用DeviceClass、VendorID:DeviceID去匹配相应的设备,这个设备清单是由https://pci-ids.ucw.cz/维护的,我们也可以直接去网站上去查询。

Linux lspci Command Examples to Get PCI Bus Hardware Device Info

lspci stands for list pci. Think of this command as “ls” + “pci”.

This will display information about all the PCI bus in your server.

Apart from displaying information about the bus, it will also display information about all the hardware devices that are connected to your PCI and PCIe bus.

lspci utility is part of the pciutils package.

[root@localhost ~]# yum provides lspci

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

* base: mirrors.tuna.tsinghua.edu.cn

* extras: mirrors.tuna.tsinghua.edu.cn

* updates: mirrors.tuna.tsinghua.edu.cn

pciutils-3.5.1-3.el7.x86_64 : PCI bus related utilities

Repo        : base

Matched from:

Filename    : /usr/sbin/lspci

pciutils-3.5.1-3.el7.x86_64 : PCI bus related utilities

Repo        : @anaconda

Matched from:

Filename    : /usr/sbin/lspci

Default Usage

By default it will display all the device information as shown below. The first field is the slot information in this format: [domain:]bus:device.function

In this example, since all the domain are 0, lspci will not display the domain.

[root@localhost ~]# lspci

00:00.0 Host bridge: Intel Corporation Sky Lake-E DMI3 Registers (rev 07)

00:04.0 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.1 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)    bus:device:function

00:04.2 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.3 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.4 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.5 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.6 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

00:04.7 System peripheral: Intel Corporation Sky Lake-E CBDMA Registers (rev 07)

Output in Tree Format

The -t option will display the output in tree format with information about bus, and how devices are connected to those buses as shown below. The output will be only using the numerical ids.

[root@localhost ~]# lspci -t|more

-+-[0000:d7]-+-00.0-[d8]--

|          +-01.0-[d9]--

|          +-02.0-[da]--

|          +-03.0-[db]--

|          +-05.0

|          +-05.2

|          +-05.4

|          +-0e.0

Detailed Device Information

If you want to look into details of a particular device, use -v to get more information. This will display information about all the devices. The output of this command will be very long, and you need to scroll down and view the appropriate section.

For additional level for verbosity, you can use -vv or -vvv.

[root@localhost ~]# lspci -v|more

00:14.0 USB controller: Intel Corporation C620 Series Chipset Family USB 3.0 xHCI Controller (rev 09) (prog-if 30 [XHCI])

        Subsystem: Lenovo Device 7800

        Flags: bus master, medium devsel, latency 0, IRQ 35, NUMA node 0

        Memory at 20ffff00000 (64-bit, non-prefetchable) [size=64K]

        Capabilities: [70] Power Management version 2

        Capabilities: [80] MSI: Enable+ Count=1/8 Maskable- 64bit+

        Kernel driver in use: xhci_hcd

Display Device Codes in the Output

Resolving of device ID's to names:

-n              Show numeric ID's

-nn            Show both textual and numeric ID's (names & numbers

If you want to display the PCI vendor code, and the device code only as the numbers, use -n option. This will not lookup the PCI file to get the corresponding values for the numbers.

[root@localhost ~]# lspci -n|more

00:00.0 0600: 8086:2020 (rev 07)

00:04.0 0880: 8086:2021 (rev 07)

00:04.1 0880: 8086:2021 (rev 07)

00:04.2 0880: 8086:2021 (rev 07)

00:04.3 0880: 8086:2021 (rev 07)

If you want to display both the description and the number, use the option -nn as shown below.

[root@localhost ~]# lspci -nn|grep -i net

08:00.0 Ethernet controller [0200]: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ [8086:37d3] (rev 09)

08:00.1 Ethernet controller [0200]: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ [8086:37d3] (rev 09)

08:00.2 Ethernet controller [0200]: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ [8086:37d3] (rev 09)

08:00.3 Ethernet controller [0200]: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ [8086:37d3] (rev 09)

                                                                    device class                                                                                                                                            vendorid:deviceid

Lookup a Specific Device

When you know the slot number in the domain:bus:slot.func format, you can query for a particular device as shown below. In the following example, we didn’t specify the domain number, as it is 0, which can be left out.

[root@localhost ~]# lspci -s 08:00.2

08:00.2 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

[root@localhost~]# lspci -s 08:00.2 -v

08:00.2 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

        Subsystem: Lenovo Ethernet Connection X722 for 10GbE SFP+

        Flags: bus master, fast devsel, latency 0, IRQ 54, NUMA node 0

        Memory at 21ffb000000 (64-bit, prefetchable) [size=16M]

        Memory at 21fff008000 (64-bit, prefetchable) [size=32K]

        Expansion ROM at d9c80000 [disabled] [size=512K]

        Capabilities: [40] Power Management version 3

        Capabilities: [50] MSI: Enable- Count=1/1 Maskable+ 64bit+

        Capabilities: [70] MSI-X: Enable+ Count=129 Masked-

        Capabilities: [a0] Express Endpoint, MSI 00

        Capabilities: [e0] Vital Product Data

        Capabilities: [100] Advanced Error Reporting

        Capabilities: [150] Alternative Routing-ID Interpretation (ARI)

        Capabilities: [160] Single Root I/O Virtualization (SR-IOV)

        Capabilities: [1a0] Transaction Processing Hints

        Capabilities: [1b0] Access Control Services

        Kernel driver in use: i40e

        Kernel modules: i40e

When you know the device number in the vendor:device format, you can query for a particular device as shown below.

[root@localhost ~]# lspci -d 8086:37d3

08:00.0 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

08:00.1 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

08:00.2 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

08:00.3 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

Display Kernel Drivers

This is very helpful when you like to know the name of the kernel module that will be handling the operations of a particular device. Please note that this option will work only on Kernel 2.6 version and above.

[root@localhost ~]# lspci -s 08:00.2 -k

08:00.2 Ethernet controller: Intel Corporation Ethernet Connection X722 for 10GbE SFP+ (rev 09)

        Subsystem: Lenovo Ethernet Connection X722 for 10GbE SFP+

        Kernel driver in use: i40e

        Kernel modules: i40e

The lspci command lists out all the pci buses and details about the devices connected to them.The vga adapter, graphics card, network adapter, usb ports, sata controllers, etc all fall under this category.

[root@localhost~]# lspci -v |grep -i "vga" -A 12

02:00.0 VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) (rev 42) (prog-if 00 [VGA controller])

        Subsystem: Emulex Corporation Device 0101

        Flags: bus master, fast devsel, latency 0, IRQ 16, NUMA node 0

        Memory at d0000000 (32-bit, non-prefetchable) [size=16M]

        Memory at d1a10000 (32-bit, non-prefetchable) [size=16K]

        Memory at d1000000 (32-bit, non-prefetchable) [size=8M]

        Expansion ROM at d1a00000 [disabled] [size=64K]

        Capabilities: [dc] Power Management version 2

        Capabilities: [54] MSI: Enable- Count=1/1 Maskable- 64bit-

        Kernel driver in use: mgag200

        Kernel modules: mgag200

05:00.0 PCI bridge: Intel Corporation Sky Lake-E PCI Express Root Port A (rev 04) (prog-if 00 [Normal decode])

Display detailed information

“lspci –xxx –s 3C:00.0”命令来列出该设备的PCIe详细信息(技术发烧友或数字控请关注该部分)。这些内容存储在PCIe配置空间,它们描述的是PCIe本身的特性。

如下图所示(低位地址0x00在最左边),可以看到这是一个非易失性存储控制器,0x00起始地址是PCIe的Vendor ID和Device ID。Class code 0x010802表示这是一个NVMe存储设备。0x40是第一组capability的指针,如果你需要查看PCIe的特性,就需要从这个位置开始去查询,在每组特征的头字段都会给出下一组特性的起始地址。从0x40地址开始依次是power management,MSI中断,链路控制与状态,MSI-X中断等特性组。这儿特别列出了链路特征中的一个0x43字段,表示STAR1000设备是一个x4lane的链接,支持PCIe Gen3速率(8Gbps)。


举例:

[root@localhost ~]# lspci -xxx -s 58:00.0

58:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID Tri-Mode SAS3516 (rev 01)

00: 00 10 14 00 47 01 10 00 01 00 04 01 08 00 00 00

10: 0c 00 f0 ff 3f 02 00 00 0c 00 e0 ff 3f 02 00 00

20: 00 00 e0 e3 01 80 00 00 00 00 00 00 49 1d 07 06

30: 00 00 d0 e3 40 00 00 00 00 00 00 00 0b 01 00 00

40: 01 50 03 06 08 00 00 00 00 00 00 00 00 00 00 00

50: 05 70 80 01 00 00 00 00 00 00 00 00 00 00 00 00

60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

70: 10 b0 02 00 23 80 00 10 36 59 09 00 83 74 43 00

80: 40 00 83 10 00 00 00 00 00 00 00 00 00 00 00 00

90: 00 00 00 00 1f 10 00 00 00 00 00 00 0e 00 00 00

a0: 03 00 1f 00 00 00 00 00 00 00 00 00 00 00 00 00

b0: 11 00 10 80 00 20 00 00 00 48 00 00 00 00 00 00

c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

d0: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

[root@localhost ~]# lspci -nn |grep -i raid

58:00.0 RAID bus controller [0104]: LSI Logic / Symbios Logic MegaRAID Tri-Mode SAS3516 [1000:0014] (rev 01)

[root@localhost ~]# lspci -s 58:00.0 -nn

58:00.0 RAID bus controller [0104]: LSI Logic / Symbios Logic MegaRAID Tri-Mode SAS3516 [1000:0014] (rev 01)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,772评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,458评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,610评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,640评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,657评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,590评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,962评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,631评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,870评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,611评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,704评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,386评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,969评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,944评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,179评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,742评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,440评论 2 342

推荐阅读更多精彩内容