Re: [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift
From: Daniel Lezcano
Date: Tue Dec 01 2026 - 11:44:29 EST
On 11/25/26 11:17, Manivannan Sadhasivam via B4 Relay wrote:
From: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
Some PCIe PHY instances on SoCs like Glymur benefit from periodic
recalibration to compensate for temperature-related drift and maintain
stable link operation. Otherwise there is a potential for a link drop. The
recalibration is performed by the hardware during a PCIe link speed
switch, which the driver initiates once the temperature change on a
polled sensor exceeds the defined threshold. For this purpose, the driver
needs to know which sensors track the PHY temperature and the drift
temperature.
First, get the list of thermal zones and the drift temperature by parsing
the 'qcom,pcie-recalibration-thermal-zones' DT property. Then record the
current temperature of each zone, which is the reference the drift gets
measured against. Then schedule a delayed worker thread 'recalib_work' for
every 5s to monitor the temperature drift and initiate the recalibration if
the drift happens.
qcom_pcie_recalib_work() does the actual work of reading the sensor
temperatures and performing recalibration when required. The worker
compares every zone against the reference recorded for it, and if none of
them has drifted far enough, it skips the recalibration. Otherwise the
worker performs the link speed switching by scaling down the Target Link
Speed to 2.5 GT/s and then restoring the original Target Link Speed. This
forces the link to run Equalization again, which recalibrates the PHY
against the current temperature, thereby maintaining stable link
operation. Equalization only runs on a speed change to 8.0 GT/s or above.
Finally, the recalibration has to be stopped across system suspend as it
touches config space, which is not reachable once the interconnect paths
are powered down. So cancel the work in the noirq suspend callback and
rearm the recalib worker on resume.
This implementation introduces a separate thermal monitoring mechanism in the PCIe driver, including temperature polling, threshold management and drift detection.
Wouldn't it make more sense to handle the temperature monitoring in the thermal framework and notify the PCIe driver when the temperature deviates from a reference by a given amount?
The PCIe driver would then only be responsible for performing the recalibration and updating the reference temperature upon successful completion.
This would avoid duplicating thermal monitoring across drivers and potentially allow interrupt-driven temperature monitoring instead of periodic polling, whenever supported by the hardware.
Temperature drift monitoring is not necessarily specific to PCIe PHYs and could benefit other devices requiring temperature-dependent recalibration.
Another concern is the thermal zone lifetime management, which is currently a weakness of the thermal framework when thermal zones are accessed by external consumers. What happens if the module providing the thermal zone is unloaded while the PCIe driver still holds a pointer to it? Without proper lifetime management or a mechanism to notify consumers when a thermal zone is unregistered, the recalibration worker could dereference a stale pointer, potentially resulting in a use-after-free.
How is the temperature drift threshold characterized?
The implementation assumes that the PHY electrical drift depends solely on the absolute temperature difference since the last recalibration, regardless of the temperature variation rate, the absolute temperature or the thermal history.
Is this assumption supported by hardware characterization? Could a slow temperature increase or prolonged exposure to a given temperature cause electrical drift that would remain undetected by this mechanism?
Additionally, with a polling interval of five seconds, transient temperature excursions between two consecutive samples may remain undetected. Could such excursions affect the PHY calibration even if the temperature subsequently returns within the acceptable range?
Finally, updating the reference temperature when the recalibration fails could mask an uncompensated drift, allowing it to accumulate over successive failed recalibrations without being detected.