Skip to contentSkip to conversation

PCI: imx6: Improve PERST# fallback logic

PATCH Applied Sherry Sun (OSS) 6 participants 9 messages May 25 – Jun 30

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover PCI: imx6: Improve PERST# fallback logic

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't decide whether to fall back to the legacy RC-level binding by checking for "reset-gpios/reset-gpio" properties on the RC node and returning -ENODEV. That's a policy decision belongs to the caller, not this common helper.

This patch set improves the PERST# (PCIe reset) GPIO fallback logic across the generic PCI host bridge helper and the i.MX6 PCIe driver.

---
Changes in V2:
1. Improved the commit messages as Richard suggested.
2. Collected Reviewed-by tags.
---
Sherry Sun (2):
PCI: host-generic: Simplify return value handling in
pci_host_common_parse_port(s)
PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result

 drivers/pci/controller/dwc/pci-imx6.c    | 25 +++++++++++++-------
 drivers/pci/controller/pci-host-common.c | 29 ++++--------------------
 2 files changed, 22 insertions(+), 32 deletions(-)

base-commit: c1ecb239fa3456529a32255359fc78b69eb9d847

Signature · 1 line
2.37.1
#1 lore raw

PATCH v2 1/2 PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't check the RC-level binding. That's a policy decision that belongs to the caller, not this common helper.

Simplify pci_host_common_parse_port() to only parse properties from the Root Port (and its children) without checking the RC node. Also change pci_host_common_parse_ports() to return 0 when no ports are found, since it is not an error.

So now both functions won't return failure for "property not found" or "port not found", they purely return 0 on success and a negative error code on real failures.

---
 drivers/pci/controller/pci-host-common.c | 29 ++++--------------------
 1 file changed, 5 insertions(+), 24 deletions(-)
drivers/pci/controller/pci-host-common.c +5 -24
index 2ce6f4b66133..c93de5a10758 100644
@@ -108,8 +108,7 @@ static int pci_host_common_parse_perst(struct device *dev,
  * dependencies and the driver may fail to operate if required resources
  * are missing.
  *
- * Return: 0 on success, -ENODEV if PERST# found in RC node (legacy binding
- * should be used), Other negative error codes on failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 static int pci_host_common_parse_port(struct device *dev,
 				      struct pci_host_bridge *bridge,
@@ -128,22 +127,6 @@ static int pci_host_common_parse_port(struct device *dev,
 	if (ret)
 		return ret;
 
-	/*
-	 * 1. PERST# found in RP or its child nodes - list is not empty,
-	 *    continue
-	 *
-	 * 2. PERST# not found in RP/children, but found in RC node -
-	 *    return -ENODEV to fallback legacy binding
-	 *
-	 * 3. PERST# not found anywhere - list is empty, continue (optional
-	 *    PERST#)
-	 */
-	if (list_empty(&port->perst)) {
-		if (of_property_present(dev->of_node, "reset-gpios") ||
-		    of_property_present(dev->of_node, "reset-gpio"))
-			return -ENODEV;
-	}
-
 	INIT_LIST_HEAD(&port->list);
 	list_add_tail(&port->list, &bridge->ports);
 
@@ -158,13 +141,11 @@ static int pci_host_common_parse_port(struct device *dev,
  * Iterate through child nodes of the host bridge and parse Root Port
  * properties (currently only reset GPIOs).
  *
- * Return: 0 on success, -ENODEV if no ports found or PERST# found in RC
- * node (legacy binding should be used), Other negative error codes on
- * failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge)
 {
-	int ret = -ENODEV;
+	int ret = 0;
 
 	for_each_available_child_of_node_scoped(dev->of_node, of_port) {
 		if (!of_node_is_type(of_port, "pci"))
@@ -174,8 +155,8 @@ int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *brid
 			goto err_cleanup;
 	}
 
-	if (ret)
-		return ret;
+	if (list_empty(&bridge->ports))
+		return 0;
 
 	return devm_add_action_or_reset(dev, pci_host_common_delete_ports,
 					&bridge->ports);
Signature · 1 line
2.37.1
#2 lore raw

Re: [PATCH V2 1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch changes the return value semantics of `pci_host_common_parse_ports()` from `-ENODEV` to…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch changes the return value semantics of pci_host_common_parse_ports() from -ENODEV to 0, silently breaking legacy device tree backward compatibility for i.MX6 PCIe. --

commit dd3d8b79463f9da53267b3bb06dcedefaa9d7673
Author: Sherry Sun <[email protected]>

PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

This commit simplifies pci_host_common_parse_port and pci_host_common_parse_ports to return 0 when no ports are found instead of returning -ENODEV. It also removes the RC-level binding check, delegating that policy decision to the caller.

Quoted 4 lines
drivers/pci/controller/pci-host-common.c +0 -0
index 2ce6f4b661334..c93de5a107581 100644

[ ... ]

Quoted 17 lines
drivers/pci/controller/pci-host-common.c +2 -4
@@ -158,13 +141,11 @@ static int pci_host_common_parse_port(struct device *dev,
  * Iterate through child nodes of the host bridge and parse Root Port
  * properties (currently only reset GPIOs).
  *
- * Return: 0 on success, -ENODEV if no ports found or PERST# found in RC
- * node (legacy binding should be used), Other negative error codes on
- * failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge)
 {
-	int ret = -ENODEV;
+	int ret = 0;
 
 	for_each_available_child_of_node_scoped(dev->of_node, of_port) {
 		if (!of_node_is_type(of_port, "pci"))

drivers/pci/controller/pci-host-common.c int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *brid · line 159

Quoted 7 lines
drivers/pci/controller/pci-host-common.c +2 -2
@@ -174,8 +155,8 @@ int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *brid
 			goto err_cleanup;
 	}
 
-	if (ret)
-		return ret;
+	if (list_empty(&bridge->ports))
+		return 0;

[Severity: High]
Does returning 0 instead of -ENODEV here break bisectability for legacy device trees on i.MX6?

Looking at the caller imx_pcie_host_init() in drivers/pci/controller/dwc/pci-imx6.c, it relies on this exact -ENODEV return value to detect the absence of Root Port nodes and fall back to parsing legacy bindings:

imx_pcie_host_init()

    ret = pci_host_common_parse_ports(dev, bridge);
    if (ret == -ENODEV)
        ret = imx_pcie_parse_legacy_binding(imx_pcie);
    if (ret)
        return ret;

Since this helper now returns 0 when no ports are found, the caller bypasses its error-handling and legacy fallback block entirely, leaving the bridge->ports list empty. Consequently, imx_pcie_assert_perst() will do nothing, and the PERST# GPIO will never be parsed or asserted.

I see that this issue is fixed later in the series by commit 0dd88230fe087b9c6a87eed08edc4d3be7f1fe1a (PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result), but updating the API without updating the caller in the same commit could break bisection.

Quoted 2 lines
drivers/pci/controller/pci-host-common.c +0 -0
 	return devm_add_action_or_reset(dev, pci_host_common_delete_ports,
 					&bridge->ports);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/2
#3 lore raw

RE: [PATCH V2 1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

In reply to Sherry Sun (OSS)
Quoted 25 lines

-----Original Message-----
From: Sherry Sun (OSS) <[email protected]>
Sent: Monday, May 25, 2026 2:55 PM
To: Hongxing Zhu <[email protected]>; [email protected]; Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; Sherry Sun <[email protected]>
Subject: [PATCH V2 1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't check the RC-level binding. That's a policy decision that belongs to the caller, not this common helper.

Simplify pci_host_common_parse_port() to only parse properties from the Root Port (and its children) without checking the RC node. Also change pci_host_common_parse_ports() to return 0 when no ports are found, since it is not an error.

Quoted 4 lines

So now both functions won't return failure for "property not found" or "port not found", they purely return 0 on success and a negative error code on real failures.

Best Regards
Richard Zhu

Quoted 73 lines
---
 drivers/pci/controller/pci-host-common.c | 29 ++++--------------------
 1 file changed, 5 insertions(+), 24 deletions(-)
drivers/pci/controller/pci- renamed from drivers/pci/controller/pci-host-common.c +0 -0

host-common.c
index 2ce6f4b66133..c93de5a10758 100644

drivers/pci/controller/pci-host-common.c +1 -2
@@ -108,8 +108,7 @@ static int pci_host_common_parse_perst(struct device
 *dev,
  * dependencies and the driver may fail to operate if required resources
  * are missing.
  *
- * Return: 0 on success, -ENODEV if PERST# found in RC node (legacy binding
- * should be used), Other negative error codes on failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 static int pci_host_common_parse_port(struct device *dev,
drivers/pci/controller/pci-host-common.c +3 -20
 				      struct pci_host_bridge *bridge, @@ -128,22
+127,6 @@ static int pci_host_common_parse_port(struct device *dev,
 	if (ret)
 		return ret;
 
-	/*
-	 * 1. PERST# found in RP or its child nodes - list is not empty,
-	 *    continue
-	 *
-	 * 2. PERST# not found in RP/children, but found in RC node -
-	 *    return -ENODEV to fallback legacy binding
-	 *
-	 * 3. PERST# not found anywhere - list is empty, continue (optional
-	 *    PERST#)
-	 */
-	if (list_empty(&port->perst)) {
-		if (of_property_present(dev->of_node, "reset-gpios") ||
-		    of_property_present(dev->of_node, "reset-gpio"))
-			return -ENODEV;
-	}
-
 	INIT_LIST_HEAD(&port->list);
 	list_add_tail(&port->list, &bridge->ports);
@@ -158,13 +141,11 @@ static int pci_host_common_parse_port(struct device
 *dev,
  * Iterate through child nodes of the host bridge and parse Root Port
  * properties (currently only reset GPIOs).
  *
- * Return: 0 on success, -ENODEV if no ports found or PERST# found in RC
- * node (legacy binding should be used), Other negative error codes on
- * failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge
 *bridge)  {
-	int ret = -ENODEV;
+	int ret = 0;
 
 	for_each_available_child_of_node_scoped(dev->of_node, of_port) {

if (!of_node_is_type(of_port, "pci")) @@ -174,8 +155,8 @@ int
pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *brid

drivers/pci/controller/pci-host-common.c +2 -3
 			goto err_cleanup;
 	}
 
-	if (ret)
-		return ret;
+	if (list_empty(&bridge->ports))
+		return 0;
 
 	return devm_add_action_or_reset(dev, pci_host_common_delete_ports,
 					&bridge->ports);
--

2.37.1

maintainer Reviewed-by on v2 1/2
#4 lore raw

RE: [PATCH V2 1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

In reply to Sherry Sun (OSS)
Quoted 24 lines

-----Original Message-----
From: Sherry Sun (OSS) <[email protected]>
Sent: Monday, May 25, 2026 2:55 PM
To: Hongxing Zhu <[email protected]>; [email protected]; Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; Sherry Sun <[email protected]>
Subject: [PATCH V2 1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't check the RC-level binding. That's a policy decision that belongs to the caller, not this common helper.

Simplify pci_host_common_parse_port() to only parse properties from the Root Port (and its children) without checking the RC node. Also change pci_host_common_parse_ports() to return 0 when no ports are found, since it is not an error.

Quoted 4 lines

So now both functions won't return failure for "property not found" or "port not found", they purely return 0 on success and a negative error code on real failures.

Best Regards
Richard Zhu

Quoted 73 lines
---
 drivers/pci/controller/pci-host-common.c | 29 ++++--------------------
 1 file changed, 5 insertions(+), 24 deletions(-)
drivers/pci/controller/pci- renamed from drivers/pci/controller/pci-host-common.c +0 -0

host-common.c
index 2ce6f4b66133..c93de5a10758 100644

drivers/pci/controller/pci-host-common.c +1 -2
@@ -108,8 +108,7 @@ static int pci_host_common_parse_perst(struct device
 *dev,
  * dependencies and the driver may fail to operate if required resources
  * are missing.
  *
- * Return: 0 on success, -ENODEV if PERST# found in RC node (legacy binding
- * should be used), Other negative error codes on failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 static int pci_host_common_parse_port(struct device *dev,
drivers/pci/controller/pci-host-common.c +3 -20
 				      struct pci_host_bridge *bridge, @@ -128,22
+127,6 @@ static int pci_host_common_parse_port(struct device *dev,
 	if (ret)
 		return ret;
 
-	/*
-	 * 1. PERST# found in RP or its child nodes - list is not empty,
-	 *    continue
-	 *
-	 * 2. PERST# not found in RP/children, but found in RC node -
-	 *    return -ENODEV to fallback legacy binding
-	 *
-	 * 3. PERST# not found anywhere - list is empty, continue (optional
-	 *    PERST#)
-	 */
-	if (list_empty(&port->perst)) {
-		if (of_property_present(dev->of_node, "reset-gpios") ||
-		    of_property_present(dev->of_node, "reset-gpio"))
-			return -ENODEV;
-	}
-
 	INIT_LIST_HEAD(&port->list);
 	list_add_tail(&port->list, &bridge->ports);
@@ -158,13 +141,11 @@ static int pci_host_common_parse_port(struct device
 *dev,
  * Iterate through child nodes of the host bridge and parse Root Port
  * properties (currently only reset GPIOs).
  *
- * Return: 0 on success, -ENODEV if no ports found or PERST# found in RC
- * node (legacy binding should be used), Other negative error codes on
- * failure.
+ * Return: 0 on success, negative error codes on failure.
  */
 int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge
 *bridge)  {
-	int ret = -ENODEV;
+	int ret = 0;
 
 	for_each_available_child_of_node_scoped(dev->of_node, of_port) {

if (!of_node_is_type(of_port, "pci")) @@ -174,8 +155,8 @@ int
pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *brid

drivers/pci/controller/pci-host-common.c +2 -3
 			goto err_cleanup;
 	}
 
-	if (ret)
-		return ret;
+	if (list_empty(&bridge->ports))
+		return 0;
 
 	return devm_add_action_or_reset(dev, pci_host_common_delete_ports,
 					&bridge->ports);
--

2.37.1

#5 lore raw

PATCH v2 2/2 PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result

In reply to Sherry Sun (OSS)

From: Sherry Sun <[email protected]>

Since pci_host_common_parse_port() doesn't return failure for "property not found" (-ENODEV), the caller should inspect the parsed result and decide whether to fall back to the legacy binding.
Add imx_pcie_perst_found() to inspect the parsed result.

---
 drivers/pci/controller/dwc/pci-imx6.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +17 -8
index b137551871fc..34756f28fcc6 100644
@@ -1287,6 +1287,18 @@ static void imx_pcie_assert_perst(struct imx_pcie *imx_pcie, bool assert)
 	}
 }
 
+static bool imx_pcie_perst_found(struct pci_host_bridge *bridge)
+{
+	struct pci_host_port *port;
+
+	list_for_each_entry(port, &bridge->ports, list) {
+		if (!list_empty(&port->perst))
+			return true;
+	}
+
+	return false;
+}
+
 static int imx_pcie_host_init(struct dw_pcie_rp *pp)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
@@ -1299,15 +1311,12 @@ static int imx_pcie_host_init(struct dw_pcie_rp *pp)
 		/* Parse Root Port nodes if present */
 		ret = pci_host_common_parse_ports(dev, bridge);
 		if (ret) {
-			if (ret != -ENODEV) {
-				dev_err(dev, "Failed to parse Root Port nodes: %d\n", ret);
-				return ret;
-			}
+			dev_err(dev, "Failed to parse Root Port nodes: %d\n", ret);
+			return ret;
+		}
 
-			/*
-			 * Fall back to legacy binding for DT backwards
-			 * compatibility
-			 */
+		/* Fallback to legacy binding for DT backwards compatibility. */
+		if (!imx_pcie_perst_found(bridge)) {
 			ret = imx_pcie_parse_legacy_binding(imx_pcie);
 			if (ret)
 				return ret;
Signature · 1 line
2.37.1
#6 lore raw
In reply to Sherry Sun (OSS)
Quoted 8 lines · Sherry Sun (OSS)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't decide whether to fall back to the legacy RC-level binding by checking for "reset-gpios/reset-gpio" properties on the RC node and returning -ENODEV. That's a policy decision belongs to the caller, not this common helper.

[...]

Applied, thanks!

[1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

      commit: 4b523544008aa70cda4b34c0589bbe47172c2637

[2/2] PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result
(no commit info)

Best regards,

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#7 lore raw
Quoted 9 lines · Manivannan Sadhasivam
Quoted 7 lines · Sherry Sun (OSS)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't decide whether to fall back to the legacy RC-level binding by checking for "reset-gpios/reset-gpio" properties on the RC node and returning -ENODEV. That's a policy decision belongs to the caller, not this common helper.

Quoted 9 lines
Quoted 1 line

[...]

Applied, thanks!

[1/2] PCI: host-generic: Simplify return value handling in pci_host_common_parse_port(s)

      commit: 4b523544008aa70cda4b34c0589bbe47172c2637

[2/2] PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result
(no commit info)

I've squashed patch 2 with 1 to avoid bisectability issue pointed out by Sashiko and rewrote the subject/description as well.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#8 lore raw
Quoted 18 lines

Subject: Re: [PATCH V2 0/2] PCI: imx6: Improve PERST# fallback logic

Quoted 6 lines · Manivannan Sadhasivam
Quoted 4 lines · Sherry Sun (OSS)

From: Sherry Sun <[email protected]>

The pci_host_common_parse_port() shouldn't decide whether to fall back to the legacy RC-level binding by checking for "reset-gpios/reset-

gpio"

Quoted 8 lines
Quoted 4 lines

properties on the RC node and returning -ENODEV. That's a policy decision belongs to the caller, not this common helper.

[...]

Applied, thanks!

[1/2] PCI: host-generic: Simplify return value handling in

Quoted 9 lines

pci_host_common_parse_port(s)

Quoted 4 lines
      commit: 4b523544008aa70cda4b34c0589bbe47172c2637

[2/2] PCI: imx6: Add imx_pcie_perst_found() to inspect the parsed result
(no commit info)

I've squashed patch 2 with 1 to avoid bisectability issue pointed out by Sashiko and rewrote the subject/description as well.

Sure, thanks!

Best Regards
Sherry