Wednesday, March 19, 2014

lspci



Linux: lspci

lspci linux command displays the PCI devices present (detected actually) in the system. PCI devices usually do not have any problems getting discovered by the BIOS/UEFI, if however, your new device does not get detected it could be because of one of the following two reasons:
1. Too many HW errors - could be the PCI slot or the PCI device. It could even be your CPU's root port.
2. Your device requires a resource that cannot be allocated (example: some BIOS'es cannot map large amount of memory addresses, so if your device requires 4GiB of address space then your BIOS could fail to initialize it.)

On a linux system, you can get a list of PCI devices by issuing the lspci command. The following is an example:

[root@hades ~]# lspci
00:00.0 Host bridge: Intel Corporation 5520 I/O Hub to ESI Port (rev 13)
00:01.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 1 (rev 13)
00:03.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 3 (rev 13)
00:04.0 PCI bridge: Intel Corporation 5520/X58 I/O Hub PCI Express Root Port 4 (rev 13)
00:05.0 PCI bridge: Intel Corporation 5520/X58 I/O Hub PCI Express Root Port 5 (rev 13)
00:06.0 PCI bridge: Intel Corporation 5520/X58 I/O Hub PCI Express Root Port 6 (rev 13)
00:07.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 7 (rev 13)
00:09.0 PCI bridge: Intel Corporation 7500/5520/5500/X58 I/O Hub PCI Express Root Port 9 (rev 13)
00:14.0 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub System Management Registers (rev 13)
00:14.1 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub GPIO and Scratch Pad Registers (rev 13)
00:14.2 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub Control Status and RAS Registers (rev 13)
00:1a.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 02)
00:1a.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 02)
00:1a.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 02)
00:1d.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 02)
00:1d.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 02)
00:1d.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 92)
00:1f.0 ISA bridge: Intel Corporation 82801IB (ICH9) LPC Interface Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801IB (ICH9) 2 port SATA Controller [IDE mode] (rev 02)
01:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
01:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
<snip>
0a:00.0 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
0a:00.1 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
0b:00.0 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
0b:00.1 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)

Take for example the following device:
0b:00.1 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)

Here the PCI bus is 0xb. PCI device is 0x0, and PCI function is 0x1. Some devices can have multiple PCI functions. This device has multiple PCI functions because this PCI device has multiple ports - each port has its own PCI function. This device happens to be a Qlogic FC adapter.

PCI devices can be identified by their vendor and device id. So, what is Qlogic's vendor id? If you pass in the '-n' switch, lspci will display the raw output, and not translate the vendor and device information.

[root@hades ~]# lspci  -n -s 0b:00.1
0b:00.1 0c04: 1077:2532 (rev 02)

Here 1077 is the QLogic vendor id. Vendor id's are globally unique, assigned by the appropriate authority (PCI Special Interest Group). 2532  is the QLogic 8G chip id.

Perhaps a more interesting (to me at least) example is an Intel device:
[root@hades ~]# lspci  -n -s 00:00.0
00:00.0 0600: 8086:3406 (rev 13)

It is more interesting because my first PC was a "8086".

Rarely some devices can be mislabelled in the lspci output. That is not something to be worried about. Linux has a list of PCI devices and their human readable names, i.e. vendor_id:device_id followed by the device description. The description can be incorrect sometimes. Even if it is, that does not matter because hardware drivers identify the devices using their numeric ids which is read from the PCI device itself.

On my Fedora system global pci device list is stored as an ASCII file at the following location:
/usr/share/hwdata/pci.ids

If need be, you can use update-pciids to update this list. You may or may not have this script installed on your system. Is you do not have update-pciids, you can just use wget (or a web browser, or curl etc) to get the list:
wget http://pciids.sourceforge.net/pci.ids

You can also see the PCI device hierarchy (the PCI tree) by using the "-t" switch. The "-v" switch is for verbosity.

[root@hades ~]# lspci -tv
-[0000:00]-+-00.0  Intel Corporation 5520 I/O Hub to ESI Port
           +-01.0-[01]--+-00.0  Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
           |            \-00.1  Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
           +-03.0-[02]--+-00.0  Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
           |            \-00.1  Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
           +-04.0-[03]----00.0  LSI Logic / Symbios Logic MegaRAID SAS 1078
           +-05.0-[04-07]----00.0-[05-07]--+-02.0-[06]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               |            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               \-03.0-[07]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                                            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           +-06.0-[08-0b]----00.0-[09-0b]--+-02.0-[0a]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               |            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               \-03.0-[0b]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                                            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           +-07.0-[0c-0f]----00.0-[0d-0f]--+-02.0-[0e]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               |            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               \-03.0-[0f]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                                            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           +-09.0-[10-13]----00.0-[11-13]--+-02.0-[12]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               |            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               \-03.0-[13]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                                            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           +-14.0  Intel Corporation 7500/5520/5500/X58 I/O Hub System Management Registers
           +-14.1  Intel Corporation 7500/5520/5500/X58 I/O Hub GPIO and Scratch Pad Registers
           +-14.2  Intel Corporation 7500/5520/5500/X58 I/O Hub Control Status and RAS Registers
           +-1a.0  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4
           +-1a.1  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5
           +-1a.7  Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2
           +-1d.0  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1
           +-1d.1  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2
           +-1d.7  Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1
           +-1e.0-[14]----03.0  Matrox Electronics Systems Ltd. MGA G200eW WPCM450
           +-1f.0  Intel Corporation 82801IB (ICH9) LPC Interface Controller
           \-1f.2  Intel Corporation 82801IB (ICH9) 2 port SATA Controller [IDE mode]
In this example, 00:01:0, 00:03.0, 00:04.0 are all PCI root ports directly connected to your IOH. Modern Intel CPU's have integrated IOH's, i.e. the IOH is on the processor core.

Let's further analyse the following output:
+-05.0-[04-07]----00.0-[05-07]--+-02.0-[06]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               |            \-00.1  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA
           |                               \-03.0-[07]--+-00.0  QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA

This shows that these QLogic devices are connected to the root port 00:05.0. Here [04-07] signifies that buses [04-07] are connected to this root port (buses are below the port in the hierarchy). The 00.0-[05-07] means that there is another device in between the root port and the Qlogic devices - possibly a PCI switch/bridge. Further buses 05-07 are below that bridge. Hence 5:2.0 is a downstream port of that bridge, to which QLogic ports 6:0.0 and 6:0.1 are connected.