* [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift
@ 2026-11-25 10:17 Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API Manivannan Sadhasivam via B4 Relay
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-25 10:17 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree,
Manivannan Sadhasivam
Problem Statement
=================
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 PHY gets calibrated when the link trains and it cannot recalibrate
itself while the link is up, so the recalibration has to be driven by
software.
Proposal
========
The PCIe controller driver triggers the recalibration with a PCIe link
speed switch 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. Both of them
vary per platform, so they come from DT.
Once a zone has drifted far enough, the driver 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.
Patch 1 adds a lookup from a DT node to its thermal zone, which the driver
needs for resolving the phandles it is handed. Patch 2 adds the new DT
binding property to specify the tuples of thermal zones and their drift
temperature. Patch 3 adds support for reading those zones on an interval
and recalibrating the PHY once one of them has drifted far enough.
Finally, patch 4 wires up the two Glymur PCIe controllers that use this,
pointing each one at the sensor that tracks the temperature of the PHY it
feeds.
Testing
=======
Tested on the Glymur CRD, on the two controllers patch 4 describes.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
Manivannan Sadhasivam (4):
thermal/of: Add thermal_zone_get_zone_by_node() API
dt-bindings: PCI: qcom,pcie-x1e80100: Add qcom,pcie-recalibration-thermal-zones
PCI: qcom: Recalibrate the PHY on temperature drift
arm64: dts: qcom: glymur: Describe the PCIe thermal inputs
.../bindings/pci/qcom,pcie-x1e80100.yaml | 31 +++
arch/arm64/boot/dts/qcom/glymur.dtsi | 4 +
drivers/pci/controller/dwc/pcie-qcom.c | 224 +++++++++++++++++++++
drivers/thermal/thermal_of.c | 21 ++
include/linux/thermal.h | 8 +
5 files changed, 288 insertions(+)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261013-glymur-thermal-fix-17fdc3a0a762
Best regards,
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:17 ` Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 2/4] dt-bindings: PCI: qcom,pcie-x1e80100: Add qcom,pcie-recalibration-thermal-zones Manivannan Sadhasivam via B4 Relay
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-25 10:17 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree,
Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Add an API to allow the drivers to get a registered thermal zone from OF
node.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
drivers/thermal/thermal_of.c | 21 +++++++++++++++++++++
include/linux/thermal.h | 8 ++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 9e96fb1b033e..e38f67c19c8e 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -530,6 +530,27 @@ void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_dev
}
EXPORT_SYMBOL_GPL(devm_thermal_of_zone_unregister);
+/**
+ * thermal_zone_get_zone_by_node() - get a registered zone from its OF node
+ * @np: device tree node of the thermal zone
+ *
+ * Thermal zones described in the device tree are registered using the name
+ * of their device tree node, so resolve @np to its registered thermal zone
+ * by that name.
+ *
+ * Return: a valid thermal zone on success, an ERR_PTR otherwise (-EINVAL for
+ * an invalid argument, -ENODEV if no zone matches @np and -EEXIST if the name
+ * is not unique).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_node(struct device_node *np)
+{
+ if (!np)
+ return ERR_PTR(-EINVAL);
+
+ return thermal_zone_get_zone_by_name(np->name);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_node);
+
/**
* thermal_of_cooling_device_register() - register an OF thermal cooling device
* @np: a pointer to a device tree node.
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 306ad17aed89..c5278d1ff0ef 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -216,6 +216,8 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,
struct device_node *np,
const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops);
+
+struct thermal_zone_device *thermal_zone_get_zone_by_node(struct device_node *np);
#else
static inline
@@ -254,6 +256,12 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,
{
return ERR_PTR(-ENODEV);
}
+
+static inline struct thermal_zone_device *
+thermal_zone_get_zone_by_node(struct device_node *np)
+{
+ return ERR_PTR(-ENODEV);
+}
#endif
int for_each_thermal_trip(struct thermal_zone_device *tz,
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] dt-bindings: PCI: qcom,pcie-x1e80100: Add qcom,pcie-recalibration-thermal-zones
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:17 ` Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-25 10:17 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree,
Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
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.
So introduce a new property 'qcom,pcie-recalibration-thermal-zones' to
specify the tuples of thermal zone phandle and the drift temperature in
millidegree Celsius to be monitored by the driver, and allow it only for
Glymur, which is the only SoC needing it so far.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
.../bindings/pci/qcom,pcie-x1e80100.yaml | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/Documentation/devicetree/bindings/pci/qcom,pcie-x1e80100.yaml b/Documentation/devicetree/bindings/pci/qcom,pcie-x1e80100.yaml
index 3d3b9f309a73..389a6bbacaa9 100644
--- a/Documentation/devicetree/bindings/pci/qcom,pcie-x1e80100.yaml
+++ b/Documentation/devicetree/bindings/pci/qcom,pcie-x1e80100.yaml
@@ -78,6 +78,26 @@ properties:
- const: pci # PCIe core reset
- const: link_down # PCIe link down reset
+ qcom,pcie-recalibration-thermal-zones:
+ $ref: /schemas/types.yaml#/definitions/phandle-array
+ minItems: 1
+ maxItems: 16
+ items:
+ items:
+ - description:
+ Phandle to a thermal zone corresponding to the sensor used to
+ monitor the PHY temperature drift.
+ - description:
+ Temperature drift this zone is allowed to accumulate before the
+ PHY needs a fresh calibration, in millidegree Celsius.
+ minimum: 1000
+ maximum: 100000
+ description:
+ Thermal zones whose sensors track the PCIe PHY temperature, along with
+ the temperature drift each zone is allowed to accumulate before the PHY
+ needs a fresh calibration. Applies to PCIe instances that rely on
+ periodic PHY recalibration to maintain stable link operation.
+
required:
- power-domains
- resets
@@ -85,6 +105,17 @@ required:
allOf:
- $ref: qcom,pcie-common.yaml#
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: qcom,glymur-pcie
+ then:
+ properties:
+ qcom,pcie-recalibration-thermal-zones: true
+ else:
+ properties:
+ qcom,pcie-recalibration-thermal-zones: false
unevaluatedProperties: false
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 2/4] dt-bindings: PCI: qcom,pcie-x1e80100: Add qcom,pcie-recalibration-thermal-zones Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:17 ` Manivannan Sadhasivam via B4 Relay
2026-11-25 10:45 ` sashiko-bot
2026-11-25 10:17 ` [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs Manivannan Sadhasivam via B4 Relay
2026-11-25 10:45 ` [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift sashiko-bot
4 siblings, 1 reply; 8+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-25 10:17 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree,
Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
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.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
drivers/pci/controller/dwc/pcie-qcom.c | 224 +++++++++++++++++++++++++++++++++
1 file changed, 224 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
index d903f10211c2..fb11718cea39 100644
--- a/drivers/pci/controller/dwc/pcie-qcom.c
+++ b/drivers/pci/controller/dwc/pcie-qcom.c
@@ -8,6 +8,7 @@
* Author: Stanimir Varbanov <svarbanov@mm-sol.com>
*/
+#include <linux/atomic.h>
#include <linux/clk.h>
#include <linux/crc8.h>
#include <linux/debugfs.h>
@@ -34,6 +35,7 @@
#include <linux/regulator/consumer.h>
#include <linux/reset.h>
#include <linux/slab.h>
+#include <linux/thermal.h>
#include <linux/types.h>
#include <linux/units.h>
@@ -314,6 +316,18 @@ struct qcom_pcie_port {
struct list_head perst;
};
+/**
+ * struct qcom_pcie_recalib_zone - thermal zone used for recalibration
+ * @tz: thermal zone whose sensor tracks the PHY temperature
+ * @drift: drift this zone may accumulate before the PHY needs recalibrating
+ * @ref: temperature @tz reported after the last recalibration
+ */
+struct qcom_pcie_recalib_zone {
+ struct thermal_zone_device *tz;
+ int drift;
+ int ref;
+};
+
struct qcom_pcie {
struct dw_pcie *pci;
void __iomem *parf; /* DT parf */
@@ -328,6 +342,11 @@ struct qcom_pcie {
int global_irq;
bool use_pm_opp;
struct mutex reset_lock;
+
+ struct qcom_pcie_recalib_zone *recalib_zones;
+ unsigned int recalib_num_zones;
+ struct workqueue_struct *recalib_wq;
+ struct delayed_work recalib_work;
};
#define to_qcom_pcie(x) dev_get_drvdata((x)->dev)
@@ -1839,6 +1858,197 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
}
}
+static int qcom_pcie_recalib_update_ref_temp(struct qcom_pcie *pcie)
+{
+ unsigned int i;
+ int temp, ret;
+
+ for (i = 0; i < pcie->recalib_num_zones; i++) {
+ struct qcom_pcie_recalib_zone *zone = &pcie->recalib_zones[i];
+
+ ret = thermal_zone_get_temp(zone->tz, &temp);
+ if (ret)
+ return ret;
+
+ zone->ref = temp;
+ }
+
+ return 0;
+}
+
+#define QCOM_PCIE_RECALIB_INTERVAL_MS 5000
+
+static void qcom_pcie_recalib_arm_worker(struct qcom_pcie *pcie)
+{
+ if (!pcie->recalib_wq)
+ return;
+
+ queue_delayed_work(pcie->recalib_wq, &pcie->recalib_work,
+ msecs_to_jiffies(QCOM_PCIE_RECALIB_INTERVAL_MS));
+}
+
+static void qcom_pcie_recalib_work(struct work_struct *work)
+{
+ struct qcom_pcie *pcie = container_of(work, struct qcom_pcie,
+ recalib_work.work);
+ struct dw_pcie_rp *pp = &pcie->pci->pp;
+ struct device *dev = pcie->pci->dev;
+ struct pci_dev *port __free(pci_dev_put) = pci_get_slot(pp->bridge->bus, PCI_DEVFN(0, 0));
+ enum pci_bus_speed speed;
+ bool drifted = false;
+ unsigned int i;
+ u16 lnkctl2;
+ int temp, ret;
+
+ if (!port || !port->subordinate)
+ goto rearm;
+
+ scoped_guard(mutex, &pcie->reset_lock) {
+ for (i = 0; i < pcie->recalib_num_zones; i++) {
+ struct qcom_pcie_recalib_zone *zone = &pcie->recalib_zones[i];
+
+ ret = thermal_zone_get_temp(zone->tz, &temp);
+ if (ret) {
+ dev_err(dev, "Failed to read %s: %d\n",
+ thermal_zone_device_type(zone->tz), ret);
+ continue;
+ }
+
+ if (abs(temp - zone->ref) >= zone->drift)
+ drifted = true;
+ }
+
+ /* No zone has drifted far enough to need a recalibration */
+ if (!drifted)
+ break;
+
+ ret = pcie_capability_read_word(port, PCI_EXP_LNKCTL2, &lnkctl2);
+ if (ret != PCIBIOS_SUCCESSFUL)
+ break;
+
+ speed = PCIE_LNKCTL2_TLS2SPEED(lnkctl2);
+ if (!pcie_valid_speed(speed))
+ break;
+
+ /*
+ * Equalization only runs at 8.0 GT/s and above, so a slower
+ * link has nothing to recalibrate.
+ */
+ if (speed >= PCIE_SPEED_8_0GT) {
+ ret = pcie_set_target_speed(port, PCIE_SPEED_2_5GT, true);
+ if (ret)
+ dev_err(dev, "Failed to step down the link speed: %d\n", ret);
+
+ /*
+ * The device below may not be able to train to the
+ * original Target Link Speed, which is reported as
+ * -EAGAIN even though the speed was restored.
+ */
+ ret = pcie_set_target_speed(port, speed, true);
+ if (ret && ret != -EAGAIN)
+ dev_err(dev, "Failed to restore the link speed: %d\n", ret);
+ }
+
+ /*
+ * Update the reference temperature of every zone and not just
+ * of the one that drifted, so all of them measure their next
+ * drift from the same point in time.
+ */
+ ret = qcom_pcie_recalib_update_ref_temp(pcie);
+ if (ret)
+ dev_err(dev, "Failed to update the reference temperature: %d\n", ret);
+ }
+
+rearm:
+ qcom_pcie_recalib_arm_worker(pcie);
+}
+
+#define QCOM_PCIE_RECALIB_ZONE_CELLS 2
+
+static int qcom_pcie_recalib_get_zones(struct qcom_pcie *pcie)
+{
+ const char *prop = "qcom,pcie-recalibration-thermal-zones";
+ struct device *dev = pcie->pci->dev;
+ struct of_phandle_args args;
+ unsigned int i, num_zones;
+ int ret;
+
+ ret = of_count_phandle_with_args(dev->of_node, prop, NULL);
+ if (ret == -ENOENT)
+ return 0;
+ if (ret < 0)
+ return ret;
+
+ if (!IS_ENABLED(CONFIG_THERMAL_OF))
+ return dev_err_probe(dev, -ENODEV,
+ "%s requires CONFIG_THERMAL_OF\n", prop);
+
+ num_zones = ret / QCOM_PCIE_RECALIB_ZONE_CELLS;
+
+ pcie->recalib_zones = devm_kcalloc(dev, num_zones,
+ sizeof(*pcie->recalib_zones), GFP_KERNEL);
+ if (!pcie->recalib_zones)
+ return -ENOMEM;
+
+ for (i = 0; i < num_zones; i++) {
+ struct qcom_pcie_recalib_zone *zone = &pcie->recalib_zones[i];
+ struct thermal_zone_device *tz;
+
+ ret = of_parse_phandle_with_fixed_args(dev->of_node, prop,
+ QCOM_PCIE_RECALIB_ZONE_CELLS - 1,
+ i, &args);
+ if (ret)
+ return ret;
+
+ tz = thermal_zone_get_zone_by_node(args.np);
+ of_node_put(args.np);
+ if (IS_ERR(tz))
+ return PTR_ERR(tz) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(tz);
+
+ zone->tz = tz;
+ zone->drift = args.args[0];
+ }
+
+ pcie->recalib_num_zones = num_zones;
+
+ return 0;
+}
+
+static void qcom_pcie_recalib_deinit(void *data)
+{
+ struct qcom_pcie *pcie = data;
+
+ cancel_delayed_work_sync(&pcie->recalib_work);
+ destroy_workqueue(pcie->recalib_wq);
+}
+
+static int qcom_pcie_recalib_init(struct qcom_pcie *pcie)
+{
+ struct device *dev = pcie->pci->dev;
+ int ret;
+
+ if (!pcie->recalib_num_zones)
+ return 0;
+
+ pcie->recalib_wq = alloc_workqueue("pcie-recalib/%s",
+ WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM,
+ 0, dev_name(dev));
+ if (!pcie->recalib_wq)
+ return -ENOMEM;
+
+ INIT_DELAYED_WORK(&pcie->recalib_work, qcom_pcie_recalib_work);
+
+ ret = qcom_pcie_recalib_update_ref_temp(pcie);
+ if (ret) {
+ destroy_workqueue(pcie->recalib_wq);
+ return dev_err_probe(dev, ret, "Failed to update the reference temperature\n");
+ }
+
+ qcom_pcie_recalib_arm_worker(pcie);
+
+ return devm_add_action_or_reset(dev, qcom_pcie_recalib_deinit, pcie);
+}
+
static int qcom_pcie_set_max_opp(struct device *dev)
{
unsigned long max_freq = ULONG_MAX;
@@ -2370,6 +2580,10 @@ static int qcom_pcie_probe(struct platform_device *pdev)
goto err_pm_runtime_put;
}
+ ret = qcom_pcie_recalib_get_zones(pcie);
+ if (ret)
+ goto err_pm_runtime_put;
+
ret = pcie->cfg->ops->get_resources(pcie);
if (ret)
goto err_pm_runtime_put;
@@ -2430,6 +2644,10 @@ static int qcom_pcie_probe(struct platform_device *pdev)
qcom_pcie_icc_opp_update(pcie);
+ ret = qcom_pcie_recalib_init(pcie);
+ if (ret)
+ goto err_host_deinit;
+
if (pcie->mhi)
qcom_pcie_init_debugfs(pcie);
@@ -2464,6 +2682,10 @@ static int qcom_pcie_suspend_noirq(struct device *dev)
if (!pcie)
return 0;
+ /* Recalibration touches config space, so it must not run past here */
+ if (pcie->recalib_wq)
+ cancel_delayed_work_sync(&pcie->recalib_work);
+
ret = dw_pcie_suspend_noirq(pcie->pci);
if (ret)
return ret;
@@ -2575,6 +2797,8 @@ static int qcom_pcie_resume_noirq(struct device *dev)
qcom_pcie_icc_opp_update(pcie);
+ qcom_pcie_recalib_arm_worker(pcie);
+
return 0;
disable_icc_mem:
icc_disable(pcie->icc_mem);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
` (2 preceding siblings ...)
2026-11-25 10:17 ` [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:17 ` Manivannan Sadhasivam via B4 Relay
2026-11-25 10:33 ` Konrad Dybcio
2026-11-25 10:45 ` [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift sashiko-bot
4 siblings, 1 reply; 8+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-25 10:17 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree,
Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Some PCIe PHY instances on Glymur benefit from periodic recalibration to
compensate for temperature-related drift and maintain stable link
operation. The controller driver triggers the recalibration with a link
speed switch once the temperature change on a polled sensor exceeds the
defined threshold, but for that it needs to know which sensors track the
PHY temperature and the drift temperature.
So add a property to identify the relevant temperature sensors,
'qcom,pcie-recalibration-thermal-zones', to PCIe domain 5 pointing at the
aoss-6 zone and to PCIe domain 7 pointing at the nsphmx-0 zone, as those
are the zones whose sensors track the respective PHY temperature. Both
zones are allowed a drift temperature of 25 degC.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
arch/arm64/boot/dts/qcom/glymur.dtsi | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/glymur.dtsi b/arch/arm64/boot/dts/qcom/glymur.dtsi
index 65a398c0a992..6fb254abf81a 100644
--- a/arch/arm64/boot/dts/qcom/glymur.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur.dtsi
@@ -3127,6 +3127,8 @@ pcie5: pcie@1b40000 {
operating-points-v2 = <&pcie5_opp_table>;
+ qcom,pcie-recalibration-thermal-zones = <&thermal_aoss_6 25000>;
+
msi-map = <0x0 &gic_its 0xd0000 0x10000>;
iommu-map = <0x0 &pcie_smmu 0x50000 0x10000>;
@@ -3615,6 +3617,8 @@ pcie3b: pcie@1b80000 {
operating-points-v2 = <&pcie3b_opp_table>;
+ qcom,pcie-recalibration-thermal-zones = <&thermal_nsphmx_0 25000>;
+
msi-map = <0x0 &gic_its 0xf0000 0x10000>;
iommu-map = <0x0 &pcie_smmu 0x70000 0x10000>;
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs
2026-11-25 10:17 ` [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:33 ` Konrad Dybcio
0 siblings, 0 replies; 8+ messages in thread
From: Konrad Dybcio @ 2026-11-25 10:33 UTC (permalink / raw)
To: manivannan.sadhasivam, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba, Manivannan Sadhasivam, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Krzysztof Kozlowski, Conor Dooley, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: linux-pm, linux-kernel, linux-arm-msm, linux-pci, devicetree
On 11/25/26 11:17 AM, Manivannan Sadhasivam via B4 Relay wrote:
> From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
>
> Some PCIe PHY instances on Glymur benefit from periodic recalibration to
> compensate for temperature-related drift and maintain stable link
> operation. The controller driver triggers the recalibration with a link
> speed switch once the temperature change on a polled sensor exceeds the
> defined threshold, but for that it needs to know which sensors track the
> PHY temperature and the drift temperature.
>
> So add a property to identify the relevant temperature sensors,
> 'qcom,pcie-recalibration-thermal-zones', to PCIe domain 5 pointing at the
> aoss-6 zone and to PCIe domain 7 pointing at the nsphmx-0 zone, as those
> are the zones whose sensors track the respective PHY temperature. Both
> zones are allowed a drift temperature of 25 degC.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Konrad
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift
2026-11-25 10:17 ` [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:45 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-25 10:45 UTC (permalink / raw)
To: Manivannan Sadhasivam; +Cc: linux-pci, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] PCI: qcom: qcom_pcie_recalib_work() checks target speed
instead of link state
- [Medium] PCI: qcom: qcom_pcie_recalib_work() corrupts TLS and updates
ref temp on error
- [Medium] PCI: qcom: qcom_pcie_suspend_noirq() leaves recalib_work
disarmed on error
- [Medium] PCI: qcom: qcom_pcie_recalib_init() error unwind races with
active global IRQ
- [Medium] PCI: qcom: qcom_pcie_recalib_work() races with Root Port
suspend and D3hot
- [Medium] PCI: qcom: stale recalibration reference temp after resume
and port reset
- [Low] PCI: qcom: missing CONFIG_PCIEPORTBUS dependency for
pcie_set_target_speed()
- [Low] PCI: qcom: remove unused linux/atomic.h header inclusion
--
commit 2b6d79564efc85fd7cf5340b7e493d9126e31fcc
Author: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
PCI: qcom: Recalibrate the PHY on temperature drift
This commit adds periodic thermal zone polling to recalibrate the PCIe PHY on
temperature drift by stepping the Root Port target link speed down to 2.5 GT/s
and restoring it.
> diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
> index d903f10211c23..fb11718cea39b 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom.c
> @@ -8,6 +8,7 @@
> * Author: Stanimir Varbanov <svarbanov@mm-sol.com>
> */
>
> +#include <linux/atomic.h>
[Severity: Low]
linux/atomic.h does not appear to be used in this file.
[ ... ]
> @@ -1839,6 +1858,197 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
> }
> }
>
> +static int qcom_pcie_recalib_update_ref_temp(struct qcom_pcie *pcie)
> +{
> + unsigned int i;
> + int temp, ret;
> +
> + for (i = 0; i < pcie->recalib_num_zones; i++) {
> + struct qcom_pcie_recalib_zone *zone = &pcie->recalib_zones[i];
> +
> + ret = thermal_zone_get_temp(zone->tz, &temp);
> + if (ret)
> + return ret;
> +
> + zone->ref = temp;
> + }
> +
> + return 0;
> +}
> +
> +#define QCOM_PCIE_RECALIB_INTERVAL_MS 5000
> +
> +static void qcom_pcie_recalib_arm_worker(struct qcom_pcie *pcie)
> +{
> + if (!pcie->recalib_wq)
> + return;
> +
> + queue_delayed_work(pcie->recalib_wq, &pcie->recalib_work,
> + msecs_to_jiffies(QCOM_PCIE_RECALIB_INTERVAL_MS));
> +}
> +
> +static void qcom_pcie_recalib_work(struct work_struct *work)
> +{
> + struct qcom_pcie *pcie = container_of(work, struct qcom_pcie,
> + recalib_work.work);
> + struct dw_pcie_rp *pp = &pcie->pci->pp;
> + struct device *dev = pcie->pci->dev;
> + struct pci_dev *port __free(pci_dev_put) = pci_get_slot(pp->bridge->bus, PCI_DEVFN(0, 0));
> + enum pci_bus_speed speed;
> + bool drifted = false;
> + unsigned int i;
> + u16 lnkctl2;
> + int temp, ret;
> +
> + if (!port || !port->subordinate)
> + goto rearm;
> +
> + scoped_guard(mutex, &pcie->reset_lock) {
> + for (i = 0; i < pcie->recalib_num_zones; i++) {
> + struct qcom_pcie_recalib_zone *zone = &pcie->recalib_zones[i];
> +
> + ret = thermal_zone_get_temp(zone->tz, &temp);
> + if (ret) {
> + dev_err(dev, "Failed to read %s: %d\n",
> + thermal_zone_device_type(zone->tz), ret);
> + continue;
> + }
> +
> + if (abs(temp - zone->ref) >= zone->drift)
> + drifted = true;
> + }
> +
> + /* No zone has drifted far enough to need a recalibration */
> + if (!drifted)
> + break;
> +
> + ret = pcie_capability_read_word(port, PCI_EXP_LNKCTL2, &lnkctl2);
> + if (ret != PCIBIOS_SUCCESSFUL)
> + break;
> +
> + speed = PCIE_LNKCTL2_TLS2SPEED(lnkctl2);
> + if (!pcie_valid_speed(speed))
> + break;
> +
> + /*
> + * Equalization only runs at 8.0 GT/s and above, so a slower
> + * link has nothing to recalibrate.
> + */
> + if (speed >= PCIE_SPEED_8_0GT) {
[Severity: Medium]
Can this trigger link retraining when no endpoint is attached, when the link
is down, or when the negotiated link speed is below 8.0 GT/s?
pci_host_probe() enumerates the Root Port and allocates port->subordinate even
when dw_pcie_wait_for_link() fails with -ENODEV, and dw_pcie_setup_rc()
initializes PCI_EXP_LNKCTL2_TLS to the controller's maximum supported speed.
Because this checks the configured target speed in PCI_EXP_LNKCTL2 rather than
whether the link is active and currently operating at 8.0 GT/s or above
(port->subordinate->cur_bus_speed), temperature drift will attempt speed
changes and retrain the link on disconnected slots or Gen 1/Gen 2 endpoints.
In addition, if a Gen 3+ link has downtrained to 2.5 GT/s while TLS remains
>= 8.0 GT/s, pcie_set_target_speed(port, PCIE_SPEED_2_5GT, true) returns 0
early without updating PCI_EXP_LNKCTL2_TLS because bus->cur_bus_speed is
already 2.5 GT/s.
> + ret = pcie_set_target_speed(port, PCIE_SPEED_2_5GT, true);
> + if (ret)
> + dev_err(dev, "Failed to step down the link speed: %d\n", ret);
> +
> + /*
> + * The device below may not be able to train to the
> + * original Target Link Speed, which is reported as
> + * -EAGAIN even though the speed was restored.
> + */
> + ret = pcie_set_target_speed(port, speed, true);
> + if (ret && ret != -EAGAIN)
> + dev_err(dev, "Failed to restore the link speed: %d\n", ret);
> + }
> +
> + /*
> + * Update the reference temperature of every zone and not just
> + * of the one that drifted, so all of them measure their next
> + * drift from the same point in time.
> + */
> + ret = qcom_pcie_recalib_update_ref_temp(pcie);
> + if (ret)
> + dev_err(dev, "Failed to update the reference temperature: %d\n", ret);
> + }
[Severity: Medium]
If stepping down to 2.5 GT/s fails in pcie_retrain_link() after
pcie_bwctrl_change_speed() has written 2.5 GT/s to PCI_EXP_LNKCTL2_TLS, can
PCI_EXP_LNKCTL2_TLS be left stuck at 2.5 GT/s?
When the step-down retrain fails, port->subordinate->cur_bus_speed remains at
the original speed, so the subsequent restore call hits the early return in
pcie_set_target_speed():
drivers/pci/pcie/bwctrl.c:pcie_set_target_speed() {
...
if (bus && bus->cur_bus_speed == speed_req)
return 0;
...
}
That skips writing the original target speed back to PCI_EXP_LNKCTL2, leaving
TLS at 2.5 GT/s so future recalibrations are skipped and any later retrain
drops the link to 2.5 GT/s. Also, qcom_pcie_recalib_update_ref_temp() runs
even when pcie_set_target_speed() fails, advancing zone->ref as if
recalibration succeeded.
> +
> +rearm:
> + qcom_pcie_recalib_arm_worker(pcie);
> +}
> +
> +#define QCOM_PCIE_RECALIB_ZONE_CELLS 2
> +
> +static int qcom_pcie_recalib_get_zones(struct qcom_pcie *pcie)
> +{
> + const char *prop = "qcom,pcie-recalibration-thermal-zones";
> + struct device *dev = pcie->pci->dev;
> + struct of_phandle_args args;
> + unsigned int i, num_zones;
> + int ret;
> +
> + ret = of_count_phandle_with_args(dev->of_node, prop, NULL);
> + if (ret == -ENOENT)
> + return 0;
> + if (ret < 0)
> + return ret;
> +
> + if (!IS_ENABLED(CONFIG_THERMAL_OF))
> + return dev_err_probe(dev, -ENODEV,
> + "%s requires CONFIG_THERMAL_OF\n", prop);
[Severity: Low]
Should this or Kconfig also check for CONFIG_PCIEPORTBUS? When
CONFIG_PCIEPORTBUS is disabled, pcie_set_target_speed() is a stub returning
-EOPNOTSUPP, so qcom_pcie_recalib_work() will fail and log an error on every
temperature drift.
[ ... ]
> +static int qcom_pcie_recalib_init(struct qcom_pcie *pcie)
> +{
> + struct device *dev = pcie->pci->dev;
> + int ret;
> +
> + if (!pcie->recalib_num_zones)
> + return 0;
> +
> + pcie->recalib_wq = alloc_workqueue("pcie-recalib/%s",
> + WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM,
> + 0, dev_name(dev));
[Severity: Medium]
Can qcom_pcie_recalib_work() race with Root Port runtime PM or system suspend
before qcom_pcie_suspend_noirq() cancels it?
Because the platform device is the parent of the PCI host bridge, the Root
Port and downstream devices run pci_pm_suspend_noirq() (saving PCIe state and
entering PCI_D3hot) before qcom_pcie_suspend_noirq() runs, and runtime PM can
also put the Root Port into PCI_D3hot:
CPU0 kworker
pci_pm_suspend_noirq(&port->dev) qcom_pcie_recalib_work()
pcie_set_target_speed(..., 2.5GT)
pci_save_state(port)
pci_save_pcie_state(port)
/* saves 2.5 GT/s in LNKCTL2 */
pci_prepare_to_sleep(port)
/* transitions port to D3hot */
pcie_set_target_speed(..., speed)
/* retrains link in D3hot */
qcom_pcie_suspend_noirq(dev)
cancel_delayed_work_sync(...)
On resume, pci_restore_pcie_state() will restore the saved 2.5 GT/s Target
Link Speed and permanently downgrade the link, or the worker can access
suspended thermal sensors and retrain the link while the port is in PCI_D3hot.
[ ... ]
> @@ -2430,6 +2644,10 @@ static int qcom_pcie_probe(struct platform_device *pdev)
>
> qcom_pcie_icc_opp_update(pcie);
>
> + ret = qcom_pcie_recalib_init(pcie);
> + if (ret)
> + goto err_host_deinit;
[Severity: Medium]
What happens if qcom_pcie_recalib_init() fails after the global IRQ has been
requested and PARF_INT_ALL_LINK_DOWN unmasked?
Jumping to err_host_deinit calls dw_pcie_host_deinit(), which frees
pp->bridge->bus, stops the link, and disables clocks via
qcom_pcie_host_deinit() while the devm-managed qcom_pcie_global_irq_thread()
is still active:
CPU0 <irq/qcom_pcie_global_irq_thread>
qcom_pcie_probe()
qcom_pcie_recalib_init() -> err
dw_pcie_host_deinit(pp)
pci_remove_root_bus(...)
pp->bridge->bus = NULL
dw_pcie_stop_link(pci)
qcom_pcie_host_deinit(pp)
writel_relaxed(..., pcie->parf + ...)
for_each_pci_bridge(port,
pp->bridge->bus)
<-- NULL pointer dereference
In addition, qcom_pcie_host_deinit() only calls
pci_pwrctrl_power_off_devices() and does not destroy the pwrctrl devices
created in qcom_pcie_host_init(), leaking them on probe failure.
> if (pcie->mhi)
> qcom_pcie_init_debugfs(pcie);
>
> @@ -2464,6 +2682,10 @@ static int qcom_pcie_suspend_noirq(struct device *dev)
> if (!pcie)
> return 0;
>
> + /* Recalibration touches config space, so it must not run past here */
> + if (pcie->recalib_wq)
> + cancel_delayed_work_sync(&pcie->recalib_work);
> +
> ret = dw_pcie_suspend_noirq(pcie->pci);
> if (ret)
> return ret;
[Severity: Medium]
If dw_pcie_suspend_noirq() or the subsequent icc_set_bw() call fails in
qcom_pcie_suspend_noirq(), does recalib_work stay permanently cancelled?
When suspend_noirq returns an error, the PM core does not mark the device as
noirq-suspended and skips qcom_pcie_resume_noirq() during rollback, so
qcom_pcie_recalib_arm_worker() is never called again.
> @@ -2575,6 +2797,8 @@ static int qcom_pcie_resume_noirq(struct device *dev)
>
> qcom_pcie_icc_opp_update(pcie);
>
> + qcom_pcie_recalib_arm_worker(pcie);
[Severity: Medium]
Should qcom_pcie_recalib_update_ref_temp() be called when the PHY is
re-initialized and retrained in qcom_pcie_resume_noirq() (when
pcie->pci->suspended is true) and in qcom_pcie_reset_root_port()?
In both paths, qcom_pcie_host_init() and dw_pcie_start_link() power-cycle the
PHY and train the link at the current temperature, but zone->ref is left at
the pre-suspend or pre-reset temperature. If the temperature shifted by less
than zone->drift while suspended and then drifts further in the opposite
direction after resume, the PHY can drift by up to nearly twice zone->drift
from its post-resume calibration temperature without triggering recalibration.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-glymur-thermal-fix-v1-0-b93a9feae156@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
` (3 preceding siblings ...)
2026-11-25 10:17 ` [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs Manivannan Sadhasivam via B4 Relay
@ 2026-11-25 10:45 ` sashiko-bot
4 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-25 10:45 UTC (permalink / raw)
To: Manivannan Sadhasivam; +Cc: linux-pci
Sashiko has finished reviewing this 4-patch series:
- Patches 1, 2, and 4: no issues found.
- Patch 3 ("PCI: qcom: Recalibrate the PHY on temperature drift"): 8
potential issues (6 Medium, 2 Low)
A detailed review has been sent as a separate reply to patch 3.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-glymur-thermal-fix-v1-0-b93a9feae156@oss.qualcomm.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-25 10:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 10:17 [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 2/4] dt-bindings: PCI: qcom,pcie-x1e80100: Add qcom,pcie-recalibration-thermal-zones Manivannan Sadhasivam via B4 Relay
2026-11-25 10:17 ` [PATCH 3/4] PCI: qcom: Recalibrate the PHY on temperature drift Manivannan Sadhasivam via B4 Relay
2026-11-25 10:45 ` sashiko-bot
2026-11-25 10:17 ` [PATCH 4/4] arm64: dts: qcom: glymur: Describe the PCIe thermal inputs Manivannan Sadhasivam via B4 Relay
2026-11-25 10:33 ` Konrad Dybcio
2026-11-25 10:45 ` [PATCH 0/4] PCI: qcom: Recalibrate the PHY on temperature drift sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox