前言
最近排查OpenWrt的一些问题时,在宿主机的内核日志中发现了一些pci相关的错误;需要具体检查下是哪个设备抛出的错误,遂有了这篇流水账记录。
PS:不知道是不是因为年龄的增长还是什么原因,感觉现在越来越开始依赖外部工具了(主要是感觉记忆力没有以前好了;也可能是强迫症/ADHD大发作);为了避免“青年痴呆”找上门,还是得多写写,多记录记录 (:з」∠),留一点赛博记忆在这;没准以后真有用得着的时候(还是希望不要用得上吧.jpg)。
lspci
lspci
: 列出当前的pci设备信息,显示设备名
lspci -n
: 列出当前的pci设备信息,以 vendor_id:product_id 形式显示设备
lspci -nn
: 列出当前的pci设备信息,同时显示设备名和ID
lspci -t
: 以层级/结构化方式显示pci设备信息
lspci -v[v]
: 详细显示pci设备信息
lspci -s
: 通过设备地址过滤显示的设备
lspci -d
: 通过设备id/class来过滤显示的设备
如果要查询某个设备的上级设备,可以通过lspci -t
结构化显示设备层级,在通过lspci -s
过滤显示。
如果要查询某个设备的下级设备(如PCI Host下挂设备),除了通过lspci -t
的方式以外,还以为通过lspci -v -s addr
来显示次级PCI Bus;再通过lspci -s
来过滤显示该次级PCI Bus的设备。
dmidecode
通过 dmidecode -q
或者 dmidecode -t slot
可以获得系统内的PCI插槽信息及Bus Address
手动获取信息
Linux中万物皆文件,我们也可以通过sysfs
中手动获取信息(也包含层级信息),具体可以查看manual
说明,这里放一个debian的链接[2]。
简单来说可以查看下面的文件/文件夹
/proc/bus/pci/devices
/sys/bus/pci
/sys/bus/pci/slots/**slot_num**/address # 有可能文件夹是空的
/sys/devices/pci0000:00
实例
如下示例:
位于00:01
的PCI bridge
提供了01:00
子BUS,该子BUS挂载了01:00.0-3
共记1个设备4个function。
而位于00:1b
的PCI bridge
则提供了02:00
子BUS,挂载了设备02:00.0
。
同理位于00:1c
的PCI bridge
提供了03:00
子BUS,挂载了设备03:00.0
。
root@m720q:~# lspci -t
-[0000:00]-+-00.0
+-01.0-[01]--+-00.0
| +-00.1
| +-00.2
| \-00.3
+-02.0
+-08.0
+-14.0
+-14.2
+-16.0
+-17.0
+-1b.0-[02]----00.0
+-1c.0-[03]----00.0
+-1f.0
+-1f.3
+-1f.4
+-1f.5
\-1f.6
root@m720q:~# lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation 8th Gen Core Processor Host Bridge/DRAM Registers [8086:3ec2] (rev 07)
00:01.0 PCI bridge [0604]: Intel Corporation 6th-10th Gen Core Processor PCIe Controller (x16) [8086:1901] (rev 07)
00:02.0 VGA compatible controller [0300]: Intel Corporation CoffeeLake-S GT2 [UHD Graphics 630] [8086:3e92]
00:08.0 System peripheral [0880]: Intel Corporation Xeon E3-1200 v5/v6 / E3-1500 v5 / 6th/7th/8th Gen Core Processor Gaussian Mixture Model [8086:1911]
00:14.0 USB controller [0c03]: Intel Corporation Cannon Lake PCH USB 3.1 xHCI Host Controller [8086:a36d] (rev 10)
00:14.2 RAM memory [0500]: Intel Corporation Cannon Lake PCH Shared SRAM [8086:a36f] (rev 10)
00:16.0 Communication controller [0780]: Intel Corporation Cannon Lake PCH HECI Controller [8086:a360] (rev 10)
00:17.0 SATA controller [0106]: Intel Corporation Cannon Lake PCH SATA AHCI Controller [8086:a352] (rev 10)
00:1b.0 PCI bridge [0604]: Intel Corporation Cannon Lake PCH PCI Express Root Port #21 [8086:a32c] (rev f0)
00:1c.0 PCI bridge [0604]: Intel Corporation Cannon Lake PCH PCI Express Root Port #6 [8086:a33d] (rev f0)
00:1f.0 ISA bridge [0601]: Intel Corporation Device [8086:a308] (rev 10)
00:1f.3 Audio device [0403]: Intel Corporation Cannon Lake PCH cAVS [8086:a348] (rev 10)
00:1f.4 SMBus [0c05]: Intel Corporation Cannon Lake PCH SMBus Controller [8086:a323] (rev 10)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Cannon Lake PCH SPI Controller [8086:a324] (rev 10)
00:1f.6 Ethernet controller [0200]: Intel Corporation Ethernet Connection (7) I219-V [8086:15bc] (rev 10)
01:00.0 Ethernet controller [0200]: Intel Corporation Ethernet Controller X710 for 10GbE SFP+ [8086:1572] (rev 02)
01:00.1 Ethernet controller [0200]: Intel Corporation Ethernet Controller X710 for 10GbE SFP+ [8086:1572] (rev 02)
01:00.2 Ethernet controller [0200]: Intel Corporation Ethernet Controller X710 for 10GbE SFP+ [8086:1572] (rev 02)
01:00.3 Ethernet controller [0200]: Intel Corporation Ethernet Controller X710 for 10GbE SFP+ [8086:1572] (rev 02)
02:00.0 Non-Volatile memory controller [0108]: Toshiba Corporation BG3 NVMe SSD Controller [1179:0113] (rev 01)
03:00.0 Network controller [0280]: Intel Corporation Dual Band Wireless-AC 3165 Plus Bluetooth [8086:3166] (rev 99)
通过lspci -v
同样可以看出来
root@m720q:~# lspci -v -s 00:01
00:01.0 PCI bridge: Intel Corporation 6th-10th Gen Core Processor PCIe Controller (x16) (rev 07) (prog-if 00 [Normal decode])
Subsystem: Lenovo 6th-10th Gen Core Processor PCIe Controller (x16)
Flags: bus master, fast devsel, latency 0, IRQ 122, IOMMU group 2
**Bus: primary=00, secondary=01, subordinate=01, sec-latency=0**
I/O behind bridge: [disabled] [16-bit]
Memory behind bridge: b4100000-b42fffff [size=2M] [32-bit]
Prefetchable memory behind bridge: b0000000-b2bfffff [size=44M] [32-bit]
Capabilities: [88] Subsystem: Lenovo 6th-10th Gen Core Processor PCIe Controller (x16)
Capabilities: [80] Power Management version 3
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [a0] Express Root Port (Slot+), MSI 00
Capabilities: [100] Virtual Channel
Capabilities: [140] Root Complex Link
Capabilities: [d94] Secondary PCI Express
Kernel driver in use: pcieport
root@m720q:~# lspci -v -s 00:1b
00:1b.0 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #21 (rev f0) (prog-if 00 [Normal decode])
Subsystem: Lenovo Cannon Lake PCH PCI Express Root Port
Flags: bus master, fast devsel, latency 0, IRQ 123, IOMMU group 7
**Bus: primary=00, secondary=02, subordinate=02, sec-latency=0**
I/O behind bridge: [disabled] [16-bit]
Memory behind bridge: b4400000-b44fffff [size=1M] [32-bit]
Prefetchable memory behind bridge: [disabled] [64-bit]
Capabilities: [40] Express Root Port (Slot+), MSI 00
Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [90] Subsystem: Lenovo Cannon Lake PCH PCI Express Root Port
Capabilities: [a0] Power Management version 3
Capabilities: [100] Advanced Error Reporting
Capabilities: [140] Access Control Services
Capabilities: [150] Precision Time Measurement
Capabilities: [200] L1 PM Substates
Capabilities: [220] Secondary PCI Express
Capabilities: [250] Downstream Port Containment
Kernel driver in use: pcieport
root@m720q:~# lspci -v -s 00:1c
00:1c.0 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #6 (rev f0) (prog-if 00 [Normal decode])
Subsystem: Lenovo Cannon Lake PCH PCI Express Root Port
Flags: bus master, fast devsel, latency 0, IRQ 124, IOMMU group 8
**Bus: primary=00, secondary=03, subordinate=03, sec-latency=0**
I/O behind bridge: [disabled] [16-bit]
Memory behind bridge: b4300000-b43fffff [size=1M] [32-bit]
Prefetchable memory behind bridge: [disabled] [64-bit]
Capabilities: [40] Express Root Port (Slot+), MSI 00
Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [90] Subsystem: Lenovo Cannon Lake PCH PCI Express Root Port
Capabilities: [a0] Power Management version 3
Capabilities: [100] Advanced Error Reporting
Capabilities: [140] Access Control Services
Capabilities: [150] Precision Time Measurement
Capabilities: [220] Secondary PCI Express
Capabilities: [250] Downstream Port Containment
Kernel driver in use: pcieport
一个Host还有可能有多个次级Bus地址,如下面示例所示00:1d
设备就提供了04-6e:00
的子Bus地址
$ lspci -t
-[0000:00]-+-00.0
+-02.0
+-08.0
+-14.0
+-14.2
+-16.0
+-17.0
+-1b.0-[01]----00.0
+-1b.4-[02]----00.0
+-1c.0-[03]----00.0
+-1d.0-[04-6e]--
+-1f.0
+-1f.3
+-1f.4
+-1f.5
\-1f.6
通过dmidecode
也可以看出来,但是在我其中两台设备中,其显示的slot不完整,挂载nvme硬盘的总线都没显示出来。查询了下资料说可能是主板没有正确记录信息,只能联系供应商解决?具体情况不太清楚,可能还是lspci
靠谱点。
root@m720q:~# dmidecode -t slot
# dmidecode 3.4
Getting SMBIOS data from sysfs.
SMBIOS 3.2.1 present.
Handle 0x001C, DMI type 9, 17 bytes
System Slot Information
Designation: J6B2
Type: x16 PCI Express
Current Usage: In Use
Length: Long
ID: 0
Characteristics:
3.3 V is provided
Opening is shared
PME signal is supported
Bus Address: 0000:00:01.0
Handle 0x001D, DMI type 9, 17 bytes
System Slot Information
Designation: J6B1
Type: x1 PCI Express
Current Usage: In Use
Length: Short
ID: 1
Characteristics:
3.3 V is provided
Opening is shared
PME signal is supported
Bus Address: 0000:00:1c.3
Handle 0x001E, DMI type 9, 17 bytes
System Slot Information
Designation: J6D1
Type: x1 PCI Express
Current Usage: In Use
Length: Short
ID: 2
Characteristics:
3.3 V is provided
Opening is shared
PME signal is supported
Bus Address: 0000:00:1c.4
Handle 0x001F, DMI type 9, 17 bytes
System Slot Information
Designation: J7B1
Type: x1 PCI Express
Current Usage: In Use
Length: Short
ID: 3
Characteristics:
3.3 V is provided
Opening is shared
PME signal is supported
Bus Address: 0000:00:1c.5
Handle 0x0020, DMI type 9, 17 bytes
System Slot Information
Designation: J8B4
Type: x1 PCI Express
Current Usage: In Use
Length: Short
ID: 4
Characteristics:
3.3 V is provided
Opening is shared
PME signal is supported
Bus Address: 0000:00:1c.6
参考资料
[1] Understand the Primary/Secondary/Subordinate Bus number in PCI/PCIe Bridge - Electrical Engineering Stack Exchange
[2] HowToIdentifyADevice/PCI - Debian Wiki
[3] c - How does lspci find out physical slot number of a PCI(E) device? - Stack Overflow
十三
学习(=゚ω゚)=
正好最近要搞openwrt了 有没有入门的设备推荐呢
Ovear 回复给 十三
先在虚拟机上试试呗,我比较喜欢X86,所以先在直接用的是那种1L小主机跑的。
文中的主机名m720q/m920x就是型号)