PERST# debug: an example

This article is part of a three-part series on PCIe PERST#.


Now that we have a clear understanding about how PERST#’s routing on an AIC board as well as an SoC, let us examine some design ideas on SoCs and AIC boards with reference to PERST#

PERST# and SoC Design

  • Method to trigger an interrupt at PERST# state change: An interrupt mechanism that can indicate PERST# state changes (assertion and deassertion) is very useful for accurate handling of required firmware actions
  • Register to read the current value and state changes of PERST#: Pulse width of PERST# is hugely variable (100us minimum, no maximum), it is very helpful for the firmware to read the state changes that caused the interrupt as well as the current state of PERST#
  • Timer: A timer is very helpful to make sure the EP meets various timing requirements imposed by the PCIe specification
  • Programmable APB/DBI/DBI2 register access timeouts: Very helpful in debugging some delayed responses and bus hangs while accessing registers in these domains.

PERST# and PCIe Controller and PHY register access: A caveat

Depending on the power, clock, and reset domain, some registers may not be accessible during the time PERST# is asserted. Worse yet, some registers are readable (reads reset values) but silently discards the written value. SoC designers are strongly recommended to document the correct register file behavior so that firmware access won’t cause surprises later during bring-up phase.

Boot Island

If the SoC is targeted at AIC designs, to meet the AIC timing specification with reference to PERST#, the LTSSM must enter Detect within 20 ms of PERST# deassertion. Since PERST# can deassert as early as 100 ms after power is stable, that leaves roughly 120 ms from power-good in the worst case. This is a very tight timeline to meet for an SoC that has to do LBIST/MBIST as a part of hardware initialization. Please consider a small boot island with minimal subsystems if you are targeting such markets.

PERST# and AIC board design

Connecting PERST# to board reset

For the ease of software implementation a few board designs features PERST# triggering a board reset. This is a BAD design on multiple counts

  • Potential failure to meet specification timing: As described in the first part of this series, the EP’s LTSSM should enter Detect state within 20ms of PERST#’s deassertion. Your AIC SoC needs to run its initializations within this time frame and get the PHY fully initialized.
  • Software state management: PERST# assertion being truly asynchronous, if tied to board reset, can introduce surprise power downs on the AIC. Depending on the software design this can cause major troubles.
  • Although specifications do not mandate it, it is logical to expect PERST# by virtue of being a signal confined to PCIe domain, to leave out other components and subsystems in the AIC which are unrelated to PCIe.

PERST# Delay circuit on board

The spec guarantees a minimum of 100us between stable REFCLK to PERST# deassert. But, if your clock generator (or parts of clock tree) requires more time than that to produce stable clock outputs, a small (often configurable) delay circuit may be introduced. This could help you in avoiding very weird situations like the PHY behaving badly when its brought out of reset without a stable clock … and other very hard to debug component/IP behaviors.

PERST# status on board

If your SoC does not provide a method to generate interrupts (as described previously), it would be a good option to connect PERST# to a GPIO pin that can be configured as an input which can be read by firmware determine the PERST# state. This pin can be configured as an interrupt in the GPIO block, but may entail a few problems because:

  • Firmware needs to determine when PERST# is asserted so that the accesses to register files across different reset/power domains can be facilitated
  • Firmware needs to determine when PERST# is deasserted so that it can program the required components and meet the strict timelines required by the specification

An interrupt source, with the facility to read the current value would be the ideal solution. Otherwise, a polling routine set up at sub-millisecond interval would be sufficient.

PERST# and Firmware Design

The following table lists various initializations the system firmware executes that are typically associated with different types of host’s booting

Action by AIC firmwareHost Cold bootHost Warm boot
OCM initializationYESNO
NOC initializationYESNO
MUX programming (can be several levels of multiplexers)YESNO
SIO/GPIO controller initializationYESNO
PHY reset sequenceYESYES
PHY uC firmware loading and stabilizationYESYES
PCIe controller reset sequenceYESYES
PCIe register configuration (DBI)YESYES
GPIO block initializationYESNO
UART (for debug messages)YESNO

DDR initialization (due to large configuration and training time) and non-essential non-pcie subsystems (ethernet, USB, SPI, I2C/I3C, ...etc) are not carried out before the PCIe initialization. Such actions are executed by either Secondary Boot Loader or the system firmware after PCIe EP init is complete.

A real-world example

This section describes the problems the author and team faced while debugging a knotty problem: The Gen5 AIC failed to link up on several server platforms (Intel, AMD, ARM64) during interoperability testing. After the fixes described below, it interoperates with 9 of the 10 platforms tested. The symptoms were varied – some failed to link up, some showed non-standard device ID/vendor id, some intermittently failed, and some other behaved differently across cold and warm boot cycles.

The SoC featured a well known IP vendor’s PCIe core configured as EP(by firmware, not strapped) and PHY with the following characteristics:

  • No in-IP logic to determine the current PERST# state
  • No custom glue logic to determine the current PERST# state
  • Controller registers were readable and returned the reset values during PERST# assert
  • Controller registers silently discarded DBI2 writes during PERST# assert
  • PHY registers were not readable and caused timeout when APB registers were programmed or caused indefinite delay till PERST# deassert and PCLK stabilized
  • Could generate an interrupt during link down (and PERST# assert caused a link down event) with a sticky interrupt status register readable during PERST# assert

The AIC design was supposed to connect PERST# to a GPIO pin, but this requirement was missed out from the board design and was not noticed until it was too late!

Attempt 1: Tie board reset signal to PERST

As described previously, this was BAD! This worked well in theory, but caused a significant number of unrelated software errors due to flash corruption. Trying to change the file system to more robust ones with journaling did not help much, just delayed the problems. Trying to run the root FS from memory was not feasible as the application required every byte of memory that can be made available, especially with the high cost of DDR now!

The most unexpected side effect was that the EP failed the timing requirement during the PCIe certification. It took about 20ms for the power rails to stabilize after board reset was deasserted. The EP's LTSSM entered Detect about 68 ms after PERST# deassertion, more than three times the 20 ms limit!

Attempt2: Separated PERST and chip resets, Interrupt on Link down event

Since the IP used could generate an interrupt on a link down event (technically two: One for LDE and one for surprise LDE), an interrupt handler was installed for serving both LDEs. The handler reads DID/VID register via DBI (for want of any better method). If read the reset values (that of the vendor), it conveyed to the software that a PERST occurred. This register was safe to access via DBI as long as the core_clk was active and stable. So, after checking the SoC clock tree and making sure that core_clk is driven by an independent clock source, this implementation was tried.

Ordinary link downs

During normal operations, the link down event can be triggered by secondary bus reset from the downstream port, hot resets or normal link down events. These events do not cause the reset of the core and can be differentiated from PERST# assertion by reading DID/VID register contents.

SBR and Hot Reset

Secondary Bus Reset uses Hot Reset to signal the reset and releases hot reset when directed by software on the host. Hot reset causes TS1s with hot reset bit set. The LTSSM leaves the current state (L0) and enter hot reset state for at least 2ms (or till the end of hot reset in case of software triggered SBR) before exiting to Detect state.

Hot reset causes the LDE but not a PERST# event. In addition to LDE, hot reset causes a hot reset interrupt to the upper layer application and is handled gracefully.

Failures of this approach

1. LDE triggers the interrupt handler that infers PERST assertion. But, it is critical to determine if the PERST deassertion. If not, the controller programming during PERST assert would be discarded silently by the PCIe core because the asserted PERST# kept the controller in reset

In order to handle this case, the interrupt handler started a poll routine to infer the PERST# deassert. The poll routine scheduled for 250us interval programmed DID/VID register once and read it back. During PERST# assert, the programmed values were lost and reset values were read. Once the read values matched the programmed values, PERST# deassert was inferred.

2. During inter-op/Compatibility testing we discovered that there are a few servers that issued multiple PERST# assertions during cold boot. This situation exposed a fatal shortcoming in the logic implemented.

During the cold boot, the firmware in the EP determines the PERST deassertion and programs the configuration space, PHY, and other components before installing the LDE interrupt handler. But, when the second PERST assertion by the host comes in, the LDE event does not occur because the link has never been established! Link down event happens only after the link has been up at least once. During the cold boot, the root port did bring its PHY out of reset and started link training only after the second PERST# assertion.

Attempt3: Moving to polling

Since we cannot depend on LDEs during the host boot up state, using a timer interrupt, we implemented a FSM with three states. During cold boot, the FSM would stay in INIT state and infer the PERST# state once every 500us. First run after PERST# deassert, FSM advances to PROGRAMMED state and continue in it. FSM progresses to OPERATIONAL state once the actual link up event occurs. A PERST assert in any state would take the FSM to INIT. An ordinary link down event (or hot-reset/SBR) would cause the FSM to enter PROGRAMMED state and wait for link up event.

Inferring PERST# state: A few other approaches

Using Receiver detect bitfield to check the end of PERST#

The idea behind Receiver Detect bitfield is that, once LTSSM enters the Detect.Active state, it would execute the Electrical Detection procedure and find if a link partner exists. This method turned out to be unreliable in some platforms. There are a few problems associated with this approach.

  1. This method won’t work for some PHYs that require the firmware loaded and running for the LTSSM functionality.
  2. Accessing PHY registers while PERST# is asserted (and PCLK not preset/unstable) can stall. You may have to reprogram APB timeout value and check for APB errors to infer PERST#, thus nullifying this approach.
  3. During warm reboots, the host / RC’s PHY and LTSSM may stay in Detect.Active state. This is possibly an erroneous behavior on the RC’s PHY part, but that possibility eliminated this method as a reliable mechanism.

Using IP specific register PCIEn_LINK_DBG_2::cdm_in_reset

This register bit shows if the CDM is in reset. Whenever the controller state changes to reset (including PERST# assertion), this bit would be 1. Once PERST# is deasserted and the controller gets out of reset, will change to 0. This bit is readable irrespective of PERST and can be used as an indicator if you want to avoid read/write cycles to VID/DID register.

During SBR/Hot Reset, this bit gets asserted even when PERST# remain deasserted. So, additional checks are required to infer correct state of PERST#


Fighting a PCIe bring-up, link-training or PCI-SIG compliance issue? Bluehatsoft helps teams bring up PCIe endpoints and pass compliance. Get in touch with us or email us at contact(at-the-rate)bluehatsoft(dot)com.