PCI/PCIe

From TheBeard Science Project Wiki
Jump to: navigation, search

Updated 8/9/2019


PACKAGES:

	pciutils

	
COMMANDS:

	(run as root to get full data)
	
	lspci [-d <vendor>:<device>:<class>] - PCI bus/device info (/proc/bus/pci/*/* and /sys/bus/pci/devices/pci0000::00/*)
		-v, -vv, -vvv - verbose output levels
		-m - display in different format
		-n, -nn - display vendor/device codes (required to use -d option)
		-t - display a tree view of the PCI bus
		-k - display kernel drivers used by each device
		-x, -xxx, -xxxx - hex dump of PCI configurations (displays little-endian, so every 2 bytes are reversed)
		-d <vendor>:<device> - choose which device to query (use -n to get vendor/device codes)
		-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]] - tell it what device to query
		
	setpci - query and configure PCI devices
		-v - verbose
		--dumpregs - dump all config space registers (including human friendly names)
		-O <param>=<value> - set a parameter of the device (-O is capital "O", not zero)
		-d <vendor>:<device> - tell it what device to query/configure (use "lspci -n" to get vendor/device codes)
		-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]] - tell it what device to query/configure
		-O help - list known parameters that can be configured with "-O <param>=<value>" (-O is capital "O", not zero)
	
	
COMMAND EXAMPLES:

	lspci -vv | less
	lspci -vv -s 00:1c.3 | less
	lspci -vv -d 8086:1e16 | less
	lspci -x -d 8086:1e16
	lspci -n
	setpci --dumpregs | less
	setpci -O help
	
	
PCI BUS NAMING CONVENTION:
	
	BDF notation:
		Bus:Device.Function
	
		Example: 00:1c.3
	
	You will also see them with a "PCI domain" in format:
		Domain:Bus:Device.Function
		
		Example: 0000:00:1c.3
		
	In many situations, you can use "*" as a wild card or omit segments to refer to a group devices:
		Examples:	00:*
					0000:*:1c
	
	The "vendor/device" code is not the same as BDF notation. It refers to the values in the Vendor ID and Device ID registers in the configuration space of the device. Use "lspci -n" to match codes with BDF.
	
	
PCI CONFIGURATIONS AND DATA:

	PCI device config spaces are in:
	/proc/bus/pci/*/*

	These files contains PCI configuration space (in hex). It's everything that is displayed by the "lspci -n" command. The "lspci -vv" command mostly just translates this data into human readable format.
	
	cat /proc/bus/pci/00/00.0 | hd -v
	
	Configuration Space registers (256 bytes):
		0x00-0x01 : Vendor ID
		0x02-0x03 : Device ID
		0x04-0x05 : Command Reg.
		0x06-0x07 : Status Reg.
		0x08      : Revision ID
		0x09-0x0B : Class Code
		0x0C      : Cache Line
		0x0D      : Latency Timer
		0x0E      : Header Type
		0x0F      : Built-In Self Test (BIST)
		0x10-0x13 : Base Address 0
		0x14-0x17 : Base Address 1
		0x18-0x1B : Base Address 2
		0x1C-0x1F : Base Address 3
		0x20-0x23 : Base Address 4
		0x24-0x27 : Base Address 5
		0x28-0x2B : CardBus CIS Pointer
		0x2C-0x2D : System Vendor ID
		0x2E-0x2F : Subsystem Device ID
		0x30-0x33 : Expansion ROM Base Address
		0x34-0x3B : Reserved
		0x3C      : IRQ Line
		0x3D      : IRQ Pin
		0x3E      : Minimum Grant Clocks (min_gnt)
		0x3F      : Maximum Latency Clocks (max_lat)
	
	
	PCI bus/device data:
	/sys/bus/pci/devices/pci0000::00/*
	

EXAMPLE DEVICE CONFIGURATION:

	lcpci -vv -s 00:1c.0

		00:1c.0 PCI bridge: Intel Corporation 7 Series/C216 Chipset Family PCI Express Root Port 1 (rev c4) (prog-if 00 [Normal decode])                        
			Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
			Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
			Latency: 0, Cache Line Size: 64 bytes
			Interrupt: pin A routed to IRQ 24
			Bus: primary=00, secondary=01, subordinate=01, sec-latency=0
			I/O behind bridge: 0000e000-0000efff
			Memory behind bridge: f7b00000-f7bfffff
			Secondary status: 66MHz- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort+ <SERR- <PERR-
			BridgeCtl: Parity- SERR- NoISA- VGA- MAbort- >Reset- FastB2B-
					PriDiscTmr- SecDiscTmr- DiscTmrStat- DiscTmrSERREn-
			Capabilities: [40] Express (v2) Root Port (Slot+), MSI 00
					DevCap: MaxPayload 128 bytes, PhantFunc 0
							ExtTag- RBE+
					DevCtl: Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
							RlxdOrd- ExtTag- PhantFunc- AuxPwr- NoSnoop-
							MaxPayload 128 bytes, MaxReadReq 128 bytes
					DevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr+ TransPend-
					LnkCap: Port #1, Speed 5GT/s, Width x1, ASPM L0s L1, Exit Latency L0s <1us, L1 <4us
							ClockPM- Surprise- LLActRep+ BwNot- ASPMOptComp-
					LnkCtl: ASPM Disabled; RCB 64 bytes Disabled- CommClk-
							ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
					LnkSta: Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive+ BWMgmt+ ABWMgmt-
					SltCap: AttnBtn- PwrCtrl- MRL- AttnInd- PwrInd- HotPlug- Surprise-
							Slot #0, PowerLimit 10.000W; Interlock- NoCompl+
					SltCtl: Enable: AttnBtn- PwrFlt- MRL- PresDet- CmdCplt- HPIrq- LinkChg-
							Control: AttnInd Unknown, PwrInd Unknown, Power- Interlock-
					SltSta: Status: AttnBtn- PowerFlt- MRL- CmdCplt- PresDet+ Interlock-
							Changed: MRL- PresDet- LinkState-
					RootCtl: ErrCorrectable- ErrNon-Fatal- ErrFatal- PMEIntEna+ CRSVisible-
					RootCap: CRSVisible-
					RootSta: PME ReqID 0000, PMEStatus- PMEPending-
					DevCap2: Completion Timeout: Range BC, TimeoutDis+, LTR-, OBFF Not Supported ARIFwd-
					DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled ARIFwd-
					LnkCtl2: Target Link Speed: 5GT/s, EnterCompliance- SpeedDis-
							 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
							 Compliance De-emphasis: -6dB
					LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete-, EqualizationPhase1-
							 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
			Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-
					Address: fee0f00c  Data: 4191
			Capabilities: [90] Subsystem: ASRock Incorporation Motherboard
			Capabilities: [a0] Power Management version 2
					Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
					Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
			Kernel driver in use: pcieport
			Kernel modules: shpchp
		
	lspci -n -s 00:1c.0
	
		00:1c.0 0604: 8086:1e10 (rev c4) 
	
	
	THINGS TO NOTE IN THESE EXAMPLES:
	
		- The BDF notation is 00:1c.3
		- Vendor/device code is 8086:1e10
		- Capability: PCI Express (v2)
		- "LnkCap" means Link Capability (what it's capable of running at)
		- "LnkSta" means Link State (what it's currently running at)
		- "Speed 5GT/s" means 5 giga-transactions per second
		- The LnkCap "Width x1" shows the number of PCI lanes this slot is capable of
		- The LnkSta "Width x1" shows the number of PCI lanes this device is using (sometimes you will see a slot that has something like x16, yet the device only uses x8)
		
	

PCI Configuration Space:

Pci config space.png