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)