Nikita Proshkin [Wed, 27 Dec 2023 09:45:00 +0000 (14:45 +0500)]
pcilmr: Add the ability to pass multiple links to the utility
* Add support for different utility modes;
* Make the default (now --margin) mode capable to accept several
components and run test for all of them;
* Add --full mode for sequential start of the test on all ready links
in the system;
* The complication of the main function is due to the need to pre-read the
parameters of the devices before starting the tests in order to calculate
Total ETA of the utility.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:59 +0000 (14:44 +0500)]
pcilmr: Add support for unique hardware quirks
Make it possible to change receiver margining parameters depending on
current hardware specificity.
In our tests Intel Ice Lake CPUs RC ports reported
MaxVoltageOffset = 50 (RxA), which led to results several times bigger
than the results of the hardware debugger.
Looks like in Intel Sapphire Rapids this was fixed, these CPU RC ports
report MaxVoltageOffset = 12 (RxA). To solve the problem it was decided
to hardcode Volt Offset to 12 (120 mV) for Ice Lake RC ports.
In the case of margining a specific link, only information about
Downstream and Upstream ports should be sufficient to decide whether to
use quirks, so the feature was implemented based on a list of devices
(vendor - device - revision triples), whose problems are known.
Back to Ice Lake ports, according to Integrators List on the pci-sig site,
the list of possible RC ports of Ice Lake Xeon's includes at least three
more options (with ids 347B/C/D) besides the one used in this commit, but
we don't have such processors to check the relevance of the MaxVoltageOffset
problem for these ports.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:57 +0000 (14:44 +0500)]
pcilmr: Add function for default margining results log
Lanes are rated according to the minimum/recommended values.
The minimum values are taken from PCIe Base Spec Rev 5.0 section 8.4.4.
30% UI recommended value for timing is taken from NVIDIA presentation
"PCIe 4.0 Mass Electrical Margins Data Collection".
Receiver lanes are called 'Weird' if all results of all receiver lanes
are equal to the spec minimum value.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:56 +0000 (14:44 +0500)]
pcilmr: Add logging functions for margining
* Implement option to turn on/off logging for margining;
* Support systems with several PCI domains;
* margin_log_margining function prints margining in progress log using
one line messages for each Receiver in the form:
"Margining - <direction> - Lanes [<current simultaneous lanes>] - ETA:
<current direction-lanes margining remaining time> Steps: <current
margining steps done> Total ETA: <utility run total remaining time>".
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:55 +0000 (14:44 +0500)]
pcilmr: Add margining process functions
* Implement the margining flow as described in the section "Example
Software Flow for Lane Margining at Receiver"
of the PCIe Base Spec Rev 5.0;
* Implement margining commands formation and response parsing according
to the PCIe Base Spec Rev 5.0 table 4-26;
* Use Receiver margining parameters as described in the
PCIe Base Spec Rev 5.0 table 8-11;
* Support lane reversal and simultaneous margining of several link lanes.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:54 +0000 (14:44 +0500)]
pcilmr: Add functions for device checking and preparations before main margining processes
Follow the checklist from PCIe Base Spec Rev 5.0 section 4.2.13.3
"Receiver Margin Testing Requirements":
* Verify the Link is at 16 GT/s or higher data rate, in DO PM state;
* Verify that Margining Ready bit of the device is set;
* Disable the ASPM and Autonomous Speed/Width features for the duration
of the test.
Also verify that Upstream Port of the Link is Function 0 of a Device,
according to spec, only it must implement margining registers.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:52 +0000 (14:44 +0500)]
lspci: Add Lane Margining support to the lspci
Gather all the info available without writing to the config space.
Without any commands margining capability exposes only 3 status bits to
read through Margining Port Capabilities and Margining Port Status registers.
It makes sense to show them anyway. For example, Margining Ready bit
indicates whether the device is actually ready for the margining process.
Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com> Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
Nikita Proshkin [Wed, 27 Dec 2023 09:44:50 +0000 (14:44 +0500)]
lspci: Fix unsynchronized caches in lspci struct device and pci struct pci_dev
lspci initializes both caches for the device to the same memory block in
its scan_device function. Latter calls to config_fetch function will
realloc cache in struct device, but not in struct pci_dev leading to
the invalid pointer in the latter. pci_dev cache is used by pci_read_*
functions, what will lead to a possible use-after-free situations.
Pali Rohár [Sun, 8 Oct 2023 13:10:12 +0000 (15:10 +0200)]
lib: Refactor access to x86 I/O ports
On all systems except BeOS and Haiku are x86 I/O ports accessed in the
standard way by the x86 in/out instructions.
On more systems there are wrapper functions for x86 in/out instructions but
under different names and sometimes even for same system those names
depends on user version of toolchain/compiler. And also some systems have
same function names but switched order of arguments.
Simplify this code, define own wrapper functions for x86 in/out
instructions in new header file i386-io-access.h and use it for every
platform except BeOS and Haiku.
This change simplifies Windows port, duplicated code between SunOS and
Windows and also tons of redefined port functions in every port.
To not conlict with possible system functions included from some header
file, add intel_ prefix for every function included from the file
lib/i386-io-access.h into lib/i386-ports.c
Martin Mares [Fri, 29 Dec 2023 14:23:00 +0000 (15:23 +0100)]
Get rid of workarounds for Linux systems without pread/pwrite
Many things have changed since we introduced work-arounds for Linux
systems with missing pread/pwrite in 1999 (if you are curious, it was
in commit bc6346df8d89ece4814be7dff951ec1a7d259938).
I believe that it is supported by all reasonably recent Linux systems
now. After all, pread() was already defined by POSIX.1-2001.
This should also fix problems with musl libc mentioned in GitHub
issue #158.
Martin Mares [Fri, 29 Dec 2023 14:16:03 +0000 (15:16 +0100)]
Constants for CXL capability should not change
When CXL capability decoding was upgraded to revision 2 by commit c0ccce1b4cd5b42b17f2e8f7bae4031c311677ff, the value of PCI_CXL_DEV_LEN
in lib/header.h has changed.
This is probably not a good idea - programs using libpci can depend
on the exact value of this constant.
Let us revert PCI_CXL_DEV_LEN to the original value for revision 1
and add PCI_CXL_DEV_LEN_REV2 for the next revision.
Also, fixed a bug in the decoder which caused it to read past the
end of the buffer for a capability which is declared as revision 2,
but too short.
Pali Rohár [Thu, 18 May 2023 19:36:50 +0000 (21:36 +0200)]
libpci: ecam: Fix big address range mappings
If more buses span continuous address space then there can be up to the
256 MB long address range which ecam backend tries to map.
Such huge space cannot be mapped on some memory limited systems. And also
it is not needed to map whole 256 MB long address range because ecam
backend cache uses mapping only for one bus. One bus has maximal mapping
size just 32*8*4096 bytes.
Pali Rohár [Thu, 17 Aug 2023 20:03:19 +0000 (22:03 +0200)]
libpci: win32-cfgmgr32: Do not use GetWindowsDirectory()
GetWindowsDirectory() function returns HOME user folder if application is
running on the Terminal Server. So this function is not suitable.
Instead of use GetSystemDirectory() which returns path to system32 folder
or GetSystemWindowsDirectory() which returns path to Windows folder (but
this is not available on all Windows versions).
Pali Rohár [Thu, 17 Aug 2023 19:15:02 +0000 (21:15 +0200)]
libpci: win32-kldbg: Fix driver constructing path
Get*Directory() functions have strange API. When called with zero buffer
they return length of the required buffer for storing path including
nul-term in TCHAR units (which is 1 for ANSI builds and 2 for UNICODE
builds). When called with non-zero buffer which can store full path they
return length of the path without nul-term (again in TCHAR units).
GetWindowsDirectory() function returns HOME user folder if application is
running on the Terminal Server. So this function is not suitable.
Fix calculation of path buffer for UNICODE builds and instead of usage
GetWindowsDirectory() function with concatenating "\\system32" string, use
function GetSystemDirectory() which returns path directly to system32
folder and which works correctly also on Terminal Server (per KB281316).
Ilpo Järvinen [Fri, 8 Dec 2023 10:13:07 +0000 (12:13 +0200)]
lspci: Add PCIe 6.0 data rate (64 GT/s) also to LnkCap2
While commit 5bdf63b6b1bc ("lspci: Add PCIe 6.0 data rate (64 GT/s)
support") added 64 GT/s support to some registers, LnkCap2 Supported
Link Speeds Vector was not included.
Add PCIe 6.0 data rate bit check also into
cap_express_link2_speed_cap().
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Ashok Raj [Wed, 18 Oct 2023 21:34:15 +0000 (14:34 -0700)]
Subject: lspci: Display PASID required attribute in Page Status Register.
Display the PASID required attribute in the Page Request Status Register.
When set, the function expects a PASID on Page Group Response (PRG)
messages when the corresponding page request had a PASID.
Decode the PCIe DevCtl2 End-to-End TLP Prefix Blocking bit. The
"EETLPPrefixBlk" format is analogous to the existing "EETLPPrefix" format
used for the corresponding DevCap2 bit.
Martin Mares [Sat, 22 Jul 2023 21:47:13 +0000 (23:47 +0200)]
update-pciids: Re-compress pci.ids if needed
Previously, if pciutils were configured with compression of pci.ids,
update-pciids downloaded the gzipped version. Now, it downloads the
most compressed version for which tools are found installed, and
recompresses it to gzip if needed.
David Edmondson [Wed, 19 Jul 2023 14:16:41 +0000 (15:16 +0100)]
lspci: Use mangled vendor/device ID when examining vendor caps
Given that PCI VFs are expected to have a vendor and device ID of
0xffff, when examining vendor capabilities use the mangled vendor and
device IDs (typically copied from the PF) rather than those read from
the VF configuration space.
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
The error bit is specified by the 2nd (zero indexed) bit
in the status register, so the respective bit value is 4 (PCI Base Spec
6.0.1). Let's fix that up.
ls-tree: Fix parsing devices on multidomain PCI system
Represent each domain as domain bridge under the &host_bridge and put root
bus of each domain under the domain bridge.
With this change lspci in tree view does not show zero bus on domain 0 in
the output if this bus does not exist at all. Root bus in PCIe hierarchy
does not have to be zero and on Freescale PowerPC systems it is common.
Also with this change are separate domain showed in the output separately.
ls-tree: Do not read Primary Bus Number for PCI Bridges from PCI config space
For PCIe devices of PCI Bridge type is Primary Bus Number not used and the
default value is 0. PCIe devices capture their Bus and Device numbers
automatically from PCIe TLP packets.
Instead of Primary Bus Number use Device Number because zero value confuse
tree building algorithm. Existing code already expects that Device Number
of PCI Bridge is already set to Primary Bus Number.
Martin Mares [Sun, 5 Mar 2023 13:56:52 +0000 (14:56 +0100)]
Parameters: Keep the list sorted and remove duplicates
When multiple back-ends use the same option (e.g., "devmem.path"),
they tend to define it each. This is not nice, but before we generalize
these options properly, let us at least remove the duplicate definitions.
Pali Rohár [Sun, 29 Jan 2023 23:39:36 +0000 (00:39 +0100)]
libpci: Add PCIe ECAM access method
This is a new direct hardware access method via PCIe ECAM (Enhanced
Configuration Access Mechanism). It is available on all PCIe-compliant
hardware. Requires root privileges and access to physical memory.
ECAM mapping can be specified manually via a new ecam.addrs parameter or
can be read from ACPI MCFG table. ACPI MCFG table can be located in the
system or read from x86 BIOS memory.
Martin Mares [Sat, 4 Mar 2023 15:33:09 +0000 (16:33 +0100)]
Use "command -v" instead of "which"
Apparently, people started considering "which" obsolete. I still
consider "which" rather useful and definitely more comfortable to type
than "command -v".
Still, "command -v" should be more portable, so let us use it.
I wonder which of the ancient systems which we are still supporting
will be broken by this change...
Pali Rohár [Sun, 29 Jan 2023 22:49:06 +0000 (23:49 +0100)]
libpci: mmio-ports: Fix support for 64-bit non-LLP64 systems
On 64-bit non-LLP64 systems is type long 64-bit. On 32-bit and 64-bit LLP64
systems is type long only 32-bit. But readl() and writel() functions works
with 32-bit PCI word. Fix it for non-LLP64 systems by using type u32.
Pali Rohár [Fri, 30 Dec 2022 20:21:10 +0000 (21:21 +0100)]
libpci: win32-cfgmgr32: Add support for accessing config space via other backend
Extend win32-cfgmgr32 backend and add a new option win32.cfgmethod for
specifying other backend for accessing PCI config space. There are more
config space access methods available on Windows and each is working only
sometimes (either requires special privileges or special setup).
So by default try to choose the first working one via order defined in pci
probe_sequence[] array. If none is available then emulate PCI config space
like before this change.
Function pci_init_v35() is extended and renamed to pci_init_internal() to
optionally do not throw errors and allow to specify one access method which
will be skipped in AUTO mode. This is used to prevent choosing win32-cfgmgr32
as config space access method for win32-cfgmgr32.
Pali Rohár [Fri, 18 Nov 2022 22:40:39 +0000 (23:40 +0100)]
libpci: windows: Handle long paths generated by GetModuleFileName()
C function fopen() implemented by msvcrt.dll requires special prefix
"\\\\?\\" for paths longer than 260 bytes. Because GetModuleFileName()
returns absolute path, it may be longer than 260 bytes. Add fixup to handle
long paths.
Pali Rohár [Fri, 18 Nov 2022 20:57:50 +0000 (21:57 +0100)]
libpci: djgpp: Allow to specify empty IDSDIR=
Like for windows builds this will cause to load pci.ids file from the same
directory where is stored application binary. Code is same as for Windows,
just djgpp uses global symbol __dos_argv0 instead of _pgmptr.
Tested with following compile command:
make CROSS_COMPILE=i586-pc-msdosdjgpp- HOST=i586-djgpp ZLIB=no DNS=no IDSDIR=
Pali Rohár [Fri, 18 Nov 2022 20:54:53 +0000 (21:54 +0100)]
libpci: windows: Fix locating path to pci.ids file for DLL builds
When using shared libpci DLL library, it is expected that pci.ids file is
stored in directory where is also libpci DLL library and not in directory
where is application executable.
Based on the build mode and compile options, choose the appropriate
function for retrieving path to the libpci DLL library or application
executable. Also pass correct module argument to GetModuleFileName() call.
Pali Rohár [Fri, 18 Nov 2022 20:47:04 +0000 (21:47 +0100)]
libpci: windows: Fix usage of GetModuleFileName()
Module file name can have arbitrary length despite all MS examples say
about MAX_PATH upper limit. This limit does not apply for example when
executable is running from network disk with very long UNC paths or
when using "\\??\\" prefix for specifying executable binary path.
So handle buffer truncatenation by retrying GetModuleFileName() call with
larger buffer.
Fixes loading of pci.ids file when lspci.exe binary is running from network
drive with path longer than 260 bytes.
Pali Rohár [Sun, 2 Jan 2022 19:50:41 +0000 (20:50 +0100)]
libpci: mmio-ports: Add Extended PCIe Intel Type 1 access method
Extended method allows to access all PCIe registers, including extended
registers starting at 0x100 offset. This method uses 4 reserved buts above
bus bits for PCIe registers. On ARM platforms it is very common for PCIe
controllers. Like standard method, it needs to be properly configured.