Skip to contentSkip to conversation

PCI: rzg3s-host: Fixes

PATCH In review Claudiu Beznea 3 participants 16 messages Dec 3

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

cover PCI: rzg3s-host: Fixes

From: Claudiu Beznea <[email protected]>

Hi,

This series adds fixes for the Renesas rzg3s-host PCIe controller driver, identified while working on support for handling link up/down events [1].

The patches were previously part of [1]. Following the discussion there, they were split out into this series.

This series also includes Ovidiu's patch, as suggested by him, since it is needed for our testing.

Please let me know your feedback.

Thank you,
Claudiu

[1] https://lore.kernel.org/all/[email protected]

Claudiu Beznea (5):
PCI: rzg3s-host: Follow hardware manual clock/reset initialization
order
PCI: rzg3s-host: Fix runtime PM handling in the NOIRQ suspend/resume
phase
PCI: rzg3s-host: Create the INTx IRQ domain before setting the chained
handlers
PCI: rzg3s-host: Initialize the IRQ domains after the IRQs are masked
PCI: rzg3s-host: Drop read-modify-write approach for the R/W1C
registers

Ovidiu Panait (1):
PCI: rzg3s-host: Fix NVMe resume errors after s2idle

 drivers/pci/controller/pcie-rzg3s-host.c | 122 +++++++++++++----------
 1 file changed, 68 insertions(+), 54 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 PCI: rzg3s-host: Follow hardware manual clock/reset initialization order

From: Claudiu Beznea <[email protected]>

The RZ/G3S PCIe hardware manual specifies that the clocks must be enabled before the reset signals are deasserted during initialization.

Follow this sequence in the probe(), suspend(), and resume() paths to match the hardware requirements and avoid potential issues.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

---

Changes since [1]:
- collected tags

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 40 +++++++++++++-----------
 1 file changed, 21 insertions(+), 19 deletions(-)
drivers/pci/controller/pcie-rzg3s-host.c +21 -19
index 2c2ee9d4d324..1dbe2a2a4bf1 100644
@@ -1884,10 +1884,6 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 	if (ret)
 		goto sysc_signal_restore;
 
-	ret = rzg3s_pcie_power_resets_deassert(host);
-	if (ret)
-		goto sysc_signal_restore;
-
 	pm_runtime_enable(dev);
 
 	/*
@@ -1898,12 +1894,16 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 	if (ret)
 		goto rpm_disable;
 
+	ret = rzg3s_pcie_power_resets_deassert(host);
+	if (ret)
+		goto rpm_put;
+
 	raw_spin_lock_init(&host->hw_lock);
 
 	ret = rzg3s_pcie_host_setup(host, rzg3s_pcie_init_irqdomain,
 				    rzg3s_pcie_teardown_irqdomain);
 	if (ret)
-		goto rpm_put;
+		goto power_resets_assert;
 
 	bridge->sysdata = host;
 	bridge->ops = &rzg3s_pcie_root_ops;
@@ -1918,12 +1918,13 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 	clk_disable_unprepare(host->port.refclk);
 	rzg3s_pcie_teardown_irqdomain(host);
 	host->data->config_deinit(host);
+power_resets_assert:
+	reset_control_bulk_assert(host->data->num_power_resets,
+				  host->power_resets);
 rpm_put:
 	pm_runtime_put_sync(dev);
 rpm_disable:
 	pm_runtime_disable(dev);
-	reset_control_bulk_assert(host->data->num_power_resets,
-				  host->power_resets);
 sysc_signal_restore:
 	/*
 	 * SYSC RST_RSM_B signal need to be asserted before turning off the
@@ -1944,10 +1945,6 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	struct rzg3s_sysc *sysc = host->sysc;
 	int ret;
 
-	ret = pm_runtime_put_sync(dev);
-	if (ret)
-		return ret;
-
 	clk_disable_unprepare(port->refclk);
 
 	/* SoC-specific de-initialization */
@@ -1960,13 +1957,19 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	if (ret)
 		goto config_reinit;
 
-	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
+	ret = pm_runtime_put_sync(dev);
 	if (ret)
 		goto power_resets_restore;
 
+	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
+	if (ret)
+		goto rpm_resume;
+
 	return 0;
 
 	/* Restore the previous state if any error happens */
+rpm_resume:
+	pm_runtime_resume_and_get(dev);
 power_resets_restore:
 	reset_control_bulk_deassert(data->num_power_resets,
 				    host->power_resets);
@@ -1976,7 +1979,6 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	data->config_post_init(host);
 refclk_restore:
 	clk_prepare_enable(port->refclk);
-	pm_runtime_resume_and_get(dev);
 	return ret;
 }
 
@@ -2005,18 +2007,18 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 			goto assert_rst_rsm_b;
 	}
 
-	ret = rzg3s_pcie_power_resets_deassert(host);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret)
 		goto assert_rst_rsm_b;
 
-	ret = pm_runtime_resume_and_get(dev);
+	ret = rzg3s_pcie_power_resets_deassert(host);
 	if (ret)
-		goto assert_power_resets;
+		goto rpm_put;
 
 	ret = rzg3s_pcie_host_setup(host, rzg3s_pcie_msi_hw_setup,
 				    rzg3s_pcie_msi_hw_teardown);
 	if (ret)
-		goto rpm_put;
+		goto assert_power_resets;
 
 	return 0;
 
@@ -2024,11 +2026,11 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 	 * If any error happens there is no way to recover the IP. Put it in the
 	 * lowest possible power state.
 	 */
-rpm_put:
-	pm_runtime_put_sync(dev);
 assert_power_resets:
 	reset_control_bulk_assert(data->num_power_resets,
 				  host->power_resets);
+rpm_put:
+	pm_runtime_put_sync(dev);
 assert_rst_rsm_b:
 	rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
 	return ret;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/6] PCI: rzg3s-host: Follow hardware manual clock/reset initialization order

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] PCI: rzg3s: strict runtime PM error…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] PCI: rzg3s: strict runtime PM error checking in noirq callbacks
[1]
--

commit 5b64ad6c833b947759b6bca40ab7aaa39c6c7bce
Author: Claudiu Beznea <[email protected]>

PCI: rzg3s-host: Follow hardware manual clock/reset initialization order

This commit reorders runtime PM clock enablement and power reset deassertion in the RZ/G3S PCIe host controller probe, suspend, and resume paths so clocks are enabled before resets are deasserted.

Quoted 4 lines
drivers/pci/controller/pcie-rzg3s-host.c +0 -0
index 2c2ee9d4d3244..1dbe2a2a4bf1c 100644

[ ... ]

Quoted 8 lines
drivers/pci/controller/pcie-rzg3s-host.c +1 -1
@@ -1960,13 +1957,19 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	if (ret)
 		goto config_reinit;
 
-	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
+	ret = pm_runtime_put_sync(dev);
 	if (ret)
 		goto power_resets_restore;

[ ... ]

drivers/pci/controller/pcie-rzg3s-host.c static int rzg3s_pcie_resume_noirq(struct device *dev) · line 2012

Quoted 8 lines
drivers/pci/controller/pcie-rzg3s-host.c +1 -1
@@ -2005,18 +2007,18 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 			goto assert_rst_rsm_b;
 	}
 
-	ret = rzg3s_pcie_power_resets_deassert(host);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret)
 		goto assert_rst_rsm_b;

[Severity: High]
This problem wasn't introduced by this patch, but do these runtime PM calls [1] unconditionally abort system suspend and resume?

During the noirq sleep phases, the PM core disables runtime PM. In rzg3s_pcie_suspend_noirq(), pm_runtime_put_sync() then returns 1 or a negative error such as -EACCES, causing the if (ret) check to abort suspend.

In rzg3s_pcie_resume_noirq(), pm_runtime_resume_and_get() similarly fails while runtime PM is disabled and aborts resume.

[1] https://sashiko.dev/#/bug/linux-53a16ad9-4c25-4208-9722-ccbc2f6de282

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/6 PCI: rzg3s-host: Fix runtime PM handling in the NOIRQ suspend/resume phase

In reply to Claudiu Beznea

From: Claudiu Beznea <[email protected]>

The runtime PM documentation states the following:
- During system suspend, pm_runtime_get_noresume() is called for every device right before executing the subsystem-level .prepare() callback (in device_prepare()). In addition, the PM core disables runtime PM for every device right before executing the subsystem-level .suspend_late() callback (in device_suspend_late()).
- During system resume, pm_runtime_enable() is called for every device right after executing the subsystem-level .resume_early() callback (in device_resume_early()), and pm_runtime_put() is called right after executing the subsystem-level .complete() callback (in device_complete()).

The driver's .suspend_noirq() callback is invoked after .suspend_late(), while .resume_noirq() is invoked before .resume_early().

If:
- the device is not part of the wake-up path, and
- its runtime PM status is not RPM_SUSPENDED,
the generic power domain .suspend_noirq()/.resume_noirq() callbacks (genpd_suspend_noirq()/genpd_resume_noirq()) invoke the driver's .suspend_noirq()/.resume_noirq() callbacks and call genpd_stop_dev()/genpd_start_dev() before and after them, respectively.

Calling genpd_stop_dev()/genpd_start_dev() allows devices whose power is controlled by generic power domains to be powered off and on during system suspend and resume, even though their runtime PM usage count does not reach zero.

Since the runtime PM usage count is incremented in device_prepare() and decremented in device_complete(), runtime PM operations performed from the driver's .suspend_noirq()/.resume_noirq() callbacks are no-ops. The actual power transitions are handled by the generic power domain .suspend_noirq()/.resume_noirq() callbacks.

Moreover, attempting to runtime resume a device while runtime PM is disabled may return -EACCES. This may cause system resume to fail when resuming after a failed Root Port reset, as described in a subsequent patch adding hot-plug support.

Remove the runtime PM calls from the driver's .suspend_noirq()/.resume_noirq() callbacks and rely on the generic power domain callbacks to power the device off and on.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

---

Changes since [1]:
- collected tags

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/pci/controller/pcie-rzg3s-host.c +10 -12
index 1dbe2a2a4bf1..66a5adf9db7e 100644
@@ -1957,19 +1957,18 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	if (ret)
 		goto config_reinit;
 
-	ret = pm_runtime_put_sync(dev);
-	if (ret)
-		goto power_resets_restore;
+	/*
+	 * Since the power domain's genpd_suspend_noirq() will disable clocks,
+	 * there is no need to manually invoke runtime PM API here.
+	 */
 
 	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
 	if (ret)
-		goto rpm_resume;
+		goto power_resets_restore;
 
 	return 0;
 
 	/* Restore the previous state if any error happens */
-rpm_resume:
-	pm_runtime_resume_and_get(dev);
 power_resets_restore:
 	reset_control_bulk_deassert(data->num_power_resets,
 				    host->power_resets);
@@ -2007,13 +2006,14 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 			goto assert_rst_rsm_b;
 	}
 
-	ret = pm_runtime_resume_and_get(dev);
-	if (ret)
-		goto assert_rst_rsm_b;
+	/*
+	 * Since the power domain's genpd_resume_noirq() will enable clocks,
+	 * there is no need to manually invoke runtime PM API here.
+	 */
 
 	ret = rzg3s_pcie_power_resets_deassert(host);
 	if (ret)
-		goto rpm_put;
+		goto assert_rst_rsm_b;
 
 	ret = rzg3s_pcie_host_setup(host, rzg3s_pcie_msi_hw_setup,
 				    rzg3s_pcie_msi_hw_teardown);
@@ -2029,8 +2029,6 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 assert_power_resets:
 	reset_control_bulk_assert(data->num_power_resets,
 				  host->power_resets);
-rpm_put:
-	pm_runtime_put_sync(dev);
 assert_rst_rsm_b:
 	rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
 	return ret;
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH 2/6] PCI: rzg3s-host: Fix runtime PM handling in the NOIRQ suspend/resume phase

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] PCI: rzg3s-host: second suspend after failed resume underflows clk/resets - [Low] PCI: rzg3s-host…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] PCI: rzg3s-host: second suspend after failed resume underflows clk/resets
- [Low] PCI: rzg3s-host: inverted genpd stop/start order in changelog and comment
--

commit d950b9cde70f06d5719f83c5c0372210d7beeeeb
Author: Claudiu Beznea <[email protected]>

PCI: rzg3s-host: Fix runtime PM handling in the NOIRQ suspend/resume phase

This commit removes the pm_runtime_put_sync() and pm_runtime_resume_and_get() calls from rzg3s_pcie_suspend_noirq() and rzg3s_pcie_resume_noirq(), relying on the generic power domain noirq callbacks to power the device off and on.

Quoted 4 lines

the generic power domain .suspend_noirq()/.resume_noirq() callbacks (genpd_suspend_noirq()/genpd_resume_noirq()) invoke the driver's .suspend_noirq()/.resume_noirq() callbacks and call genpd_stop_dev()/genpd_start_dev() before and after them, respectively.

[Severity: Low]
Is the genpd_stop_dev()/genpd_start_dev() order inverted here?

In drivers/pmdomain/core.c, genpd_finish_suspend() calls suspend_noirq() first and genpd_stop_dev() after it, while genpd_finish_resume() calls genpd_start_dev() before pm_generic_resume_noirq().

The new comment in rzg3s_pcie_resume_noirq() has the same issue: it says genpd_resume_noirq() "will enable clocks" mid-function, even though genpd_start_dev() has already enabled them before rzg3s_pcie_resume_noirq() is entered.

Quoted 10 lines
drivers/pci/controller/pcie-rzg3s-host.c +0 -2
index 1dbe2a2a4bf1c..66a5adf9db7ec 100644
@@ -1957,19 +1957,18 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	if (ret)
 		goto config_reinit;
 
-	ret = pm_runtime_put_sync(dev);
-	if (ret)

drivers/pci/controller/pcie-rzg3s-host.c static int rzg3s_pcie_suspend_noirq(struct device *dev) · line 1967

Quoted 10 lines
drivers/pci/controller/pcie-rzg3s-host.c +5 -2
-		goto power_resets_restore;
+	/*
+	 * Since the power domain's genpd_suspend_noirq() will disable clocks,
+	 * there is no need to manually invoke runtime PM API here.
+	 */
 
 	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
 	if (ret)
-		goto rpm_resume;
+		goto power_resets_restore;

[Severity: Medium]
Can a second system suspend after a failed rzg3s_pcie_resume_noirq() now underflow port->refclk and double-assert host->power_resets?

When rzg3s_pcie_resume_noirq() fails (for example on a link-up timeout in rzg3s_pcie_host_init()), it re-asserts host->power_resets and leaves port->refclk disabled, while device_resume_noirq() still clears is_noirq_suspended and completes system resume.

On the next suspend, rzg3s_pcie_suspend_noirq() runs again on the already-deinitialized controller. It disables port->refclk again, writes host->axi + RZG3S_PCI_RESET in rzg3e_pcie_config_deinit() under reset, and calls reset_control_bulk_assert() a second time on shared power_resets.

On single-controller SoCs this hits WARN_ON() in __reset_control_assert() and aborts suspend with -EINVAL; on dual-controller RZ/V2H where pcie0 and pcie1 share aresetn, it drops the sibling's count to zero and resets it.

Tracking whether the controller is already suspended and returning early in rzg3s_pcie_suspend_noirq() would avoid tearing it down twice.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH 3/6 PCI: rzg3s-host: Create the INTx IRQ domain before setting the chained handlers

In reply to Claudiu Beznea

From: Claudiu Beznea <[email protected]>

rzg3s_pcie_init_irqdomain() installs the chained INTx handlers before creating the INTx IRQ domain. Since irq_set_chained_handler_and_data() also enables the interrupt, an INTx interrupt arriving in between is handled by rzg3s_pcie_intx_irq_handler() while host->intx_domain is still NULL, which could lead to a NULL pointer dereference. This was identified by code inspection.

Move the IRQ domain creation before the loop that installs the chained handlers.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

---

Changes since [1]:
- collected tags
- adjusted the patch description as suggested in the review process

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/pci/controller/pcie-rzg3s-host.c +10 -12
index 66a5adf9db7e..201888f1f525 100644
@@ -1024,6 +1024,16 @@ static int rzg3s_pcie_init_irqdomain(struct rzg3s_pcie_host *host)
 	struct platform_device *pdev = to_platform_device(dev);
 	int i, ret;
 
+	host->intx_domain = irq_domain_create_linear(dev_fwnode(dev),
+						     PCI_NUM_INTX,
+						     &rzg3s_pcie_intx_domain_ops,
+						     host);
+	if (!host->intx_domain) {
+		return dev_err_probe(dev, -EINVAL,
+				     "Failed to add irq domain for INTx IRQs\n");
+	}
+	irq_domain_update_bus_token(host->intx_domain, DOMAIN_BUS_WIRED);
+
 	for (i = 0; i < PCI_NUM_INTX; i++) {
 		char irq_name[5] = {0};
 		int irq;
@@ -1045,18 +1055,6 @@ static int rzg3s_pcie_init_irqdomain(struct rzg3s_pcie_host *host)
 						 host);
 	}
 
-	host->intx_domain = irq_domain_create_linear(dev_fwnode(dev),
-						     PCI_NUM_INTX,
-						     &rzg3s_pcie_intx_domain_ops,
-						     host);
-	if (!host->intx_domain) {
-		ret = -EINVAL;
-		dev_err_probe(dev, ret,
-			      "Failed to add irq domain for INTx IRQs\n");
-		goto teardown_intx;
-	}
-	irq_domain_update_bus_token(host->intx_domain, DOMAIN_BUS_WIRED);
-
 	if (IS_ENABLED(CONFIG_PCI_MSI)) {
 		ret = rzg3s_pcie_init_msi(host);
 
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 3/6] PCI: rzg3s-host: Create the INTx IRQ domain before setting the chained handlers

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] PCI: rzg3s-host: commit message inaccurately claims NULL pointer dereference --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] PCI: rzg3s-host: commit message inaccurately claims NULL pointer dereference
--

commit 8c172626e9a84925ccbde1ae471b365b192d36ff
Author: Claudiu Beznea <[email protected]>

PCI: rzg3s-host: Create the INTx IRQ domain before setting the chained handlers

This commit moves the INTx IRQ domain creation ahead of installing the chained INTx handlers in rzg3s_pcie_init_irqdomain().

Quoted 6 lines

rzg3s_pcie_init_irqdomain() installs the chained INTx handlers before creating the INTx IRQ domain. Since irq_set_chained_handler_and_data() also enables the interrupt, an INTx interrupt arriving in between is handled by rzg3s_pcie_intx_irq_handler() while host->intx_domain is still NULL, which could lead to a NULL pointer dereference. This was identified by code inspection.

[Severity: Low]
Is the commit message accurate about a NULL pointer dereference here?

rzg3s_pcie_intx_irq_handler() only passes host->intx_domain to generic_handle_domain_irq(). In that path, __irq_resolve_mapping() falls back to irq_default_domain when domain is NULL, and handle_irq_desc() returns -EINVAL if no irq_desc is found.

So before this patch, an early INTx interrupt either fails with -EINVAL or gets dispatched through an unrelated irq_default_domain, rather than triggering a NULL pointer dereference.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH 4/6 PCI: rzg3s-host: Initialize the IRQ domains after the IRQs are masked

In reply to Claudiu Beznea

From: Claudiu Beznea <[email protected]>

The IRQ domain initialization requests the interrupts and installs the chained handlers before rzg3s_pcie_irq_init() masks the controller interrupt sources. An interrupt left enabled (e.g. by the bootloader, or latched from a previous controller state) could therefore fire before the controller initialization is complete and be handled on half-initialized state.

Move the IRQ domain initialization after rzg3s_pcie_irq_init(), so that all the interrupt sources are masked by the time the handlers are installed.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

---

Changes since [1]:
- collected tags

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 31 ++++++++++++------------
 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/pci/controller/pcie-rzg3s-host.c +15 -16
index 201888f1f525..cbe25615eb96 100644
@@ -1414,7 +1414,10 @@ static int rzg3s_pcie_host_init_port(struct rzg3s_pcie_host *host)
 	return ret;
 }
 
-static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
+static int
+rzg3s_pcie_host_init(struct rzg3s_pcie_host *host,
+		     int (*init_irqdomain)(struct rzg3s_pcie_host *host),
+		     void (*teardown_irqdomain)(struct rzg3s_pcie_host *host))
 {
 	u32 val;
 	int ret;
@@ -1441,10 +1444,14 @@ static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
 	/* Initialize the interrupts */
 	rzg3s_pcie_irq_init(host);
 
+	ret = init_irqdomain(host);
+	if (ret)
+		goto config_deinit_and_refclk;
+
 	/* SoC-specific post-configuration */
 	ret = host->data->config_post_init(host);
 	if (ret)
-		goto config_deinit_and_refclk;
+		goto teardown_irqdomain;
 
 	/* Wait for link up */
 	ret = readl_poll_timeout(host->axi + RZG3S_PCI_PCSTAT1, val,
@@ -1462,6 +1469,8 @@ static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
 
 config_deinit_post:
 	host->data->config_deinit(host);
+teardown_irqdomain:
+	teardown_irqdomain(host);
 config_deinit_and_refclk:
 	clk_disable_unprepare(host->port.refclk);
 config_deinit:
@@ -1717,15 +1726,10 @@ rzg3s_pcie_host_setup(struct rzg3s_pcie_host *host,
 		return dev_err_probe(dev, ret,
 				     "Failed to set outbound windows!\n");
 
-	ret = init_irqdomain(host);
+	ret = rzg3s_pcie_host_init(host, init_irqdomain, teardown_irqdomain);
 	if (ret)
-		return dev_err_probe(dev, ret, "Failed to init IRQ domain\n");
-
-	ret = rzg3s_pcie_host_init(host);
-	if (ret) {
-		dev_err_probe(dev, ret, "Failed to initialize the HW!\n");
-		goto teardown_irqdomain;
-	}
+		return dev_err_probe(dev, ret,
+				     "Failed to initialize the HW!\n");
 
 	ret = rzg3s_pcie_set_max_link_speed(host);
 	if (ret)
@@ -1734,11 +1738,6 @@ rzg3s_pcie_host_setup(struct rzg3s_pcie_host *host,
 	pci_host_common_link_train_delay(host->max_link_speed);
 
 	return 0;
-
-teardown_irqdomain:
-	teardown_irqdomain(host);
-
-	return ret;
 }
 
 static int rzg3s_pcie_get_controller_id(struct rzg3s_pcie_host *host)
@@ -1913,8 +1912,8 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 	return 0;
 
 host_probe_teardown:
-	clk_disable_unprepare(host->port.refclk);
 	rzg3s_pcie_teardown_irqdomain(host);
+	clk_disable_unprepare(host->port.refclk);
 	host->data->config_deinit(host);
 power_resets_assert:
 	reset_control_bulk_assert(host->data->num_power_resets,
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 4/6] PCI: rzg3s-host: Initialize the IRQ domains after the IRQs are masked

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] PCI: rzg3s-host: rzg3s_pcie_irq_init() fails to mask INTx and MSI sources --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] PCI: rzg3s-host: rzg3s_pcie_irq_init() fails to mask INTx and MSI sources
--

commit 235fc1f6b07ca2eb04e5a0e74470c01037910a31
Author: Claudiu Beznea <[email protected]>

PCI: rzg3s-host: Initialize the IRQ domains after the IRQs are masked

This commit moves init_irqdomain() from rzg3s_pcie_host_setup() into rzg3s_pcie_host_init() after rzg3s_pcie_irq_init(), and updates the error-handling teardown order accordingly.

Quoted 4 lines
drivers/pci/controller/pcie-rzg3s-host.c +0 -0
index 201888f1f5250..cbe25615eb967 100644

[ ... ]

drivers/pci/controller/pcie-rzg3s-host.c static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host) · line 1449

Quoted 7 lines
drivers/pci/controller/pcie-rzg3s-host.c +3 -0
@@ -1441,10 +1444,14 @@ static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
 	/* Initialize the interrupts */
 	rzg3s_pcie_irq_init(host);
 
+	ret = init_irqdomain(host);
+	if (ret)
+		goto config_deinit_and_refclk;

[Severity: Medium]
Does rzg3s_pcie_irq_init() actually mask the INTx and MSI sources whose handlers init_irqdomain() installs?

rzg3s_pcie_irq_init() only clears and disables the PCIe event and error registers (PEIE0/1, PEIS0/1, AMEIS, ASEIS1, MSGRCVIS). It leaves the INTx and MSI registers (RZG3S_PCI_PINTRCVIE, RZG3S_PCI_PINTRCVIS, RZG3S_PCI_MSGRCVIE, MSIRE/MSIRM/MSIRS, RZG3S_PCI_MSIRCVWADRL) untouched.

Since power_resets are shared and only deasserted on probe without being asserted first, bootloader or prior controller state in those registers persists across rzg3s_pcie_irq_init().

If a level-triggered INTx is latched when irq_set_chained_handler_and_data() runs before any child virq is mapped, generic_handle_domain_irq() returns -EINVAL without acking or masking the line, causing an infinite chained-IRQ storm.

Similarly, rzg3s_pcie_init_msi() calls request_irq() before rzg3s_pcie_msi_setup(), so a left-enabled MSI can still fire on half-initialized state.

Masking and clearing the INTx and MSI registers in rzg3s_pcie_irq_init() (with a readback barrier after the writel_relaxed() writes) before init_irqdomain() would ensure the handlers are installed safely.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH 5/6 PCI: rzg3s-host: Drop read-modify-write approach for the R/W1C registers

In reply to Claudiu Beznea

From: Claudiu Beznea <[email protected]>

The AXI registers PCI_PINTRCVIS and PCI_PINTRCVIS_MSI are R/W1C. According to the RZ/G3S HW manual, Rev. 1.30, R/W1C means "it can be cleared to 0b by writing 1b. Writing 0b does not change anything."

Drop the read-modify-write approach and make use of this hardware capability. This avoids clearing unwanted interrupts.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

---

Changes since [1]:
- collected tags

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/pci/controller/pcie-rzg3s-host.c +7 -8
index cbe25615eb96..ad75e6895259 100644
@@ -82,6 +82,7 @@
 #define RZG3S_PCI_MSGRCVIE			0x120
 #define RZG3S_PCI_MSGRCVIE_MSG_RCV		BIT(24)
 
+/* Register is R/W1C, it doesn't require locking. */
 #define RZG3S_PCI_MSGRCVIS			0x124
 #define RZG3S_PCI_MSGRCVIS_MRI			BIT(24)
 
@@ -591,11 +592,10 @@ static irqreturn_t rzg3s_pcie_msi_irq(int irq, void *data)
 		return IRQ_NONE;
 
 	/* Clear the MSI */
-	rzg3s_pcie_update_bits(host->axi, RZG3S_PCI_PINTRCVIS,
-			       RZG3S_PCI_PINTRCVIS_MSI,
-			       RZG3S_PCI_PINTRCVIS_MSI);
-	rzg3s_pcie_update_bits(host->axi, RZG3S_PCI_MSGRCVIS,
-			       RZG3S_PCI_MSGRCVIS_MRI, RZG3S_PCI_MSGRCVIS_MRI);
+	writel_relaxed(RZG3S_PCI_PINTRCVIS_MSI,
+		       host->axi + RZG3S_PCI_PINTRCVIS);
+	writel_relaxed(RZG3S_PCI_MSGRCVIS_MRI,
+		       host->axi + RZG3S_PCI_MSGRCVIS);
 
 	for (u8 reg_id = 0; reg_id < regs; reg_id++) {
 		status = readl_relaxed(host->axi + RZG3S_PCI_MSIRS(reg_id));
@@ -958,9 +958,8 @@ static void rzg3s_pcie_intx_irq_ack(struct irq_data *d)
 {
 	struct rzg3s_pcie_host *host = irq_data_get_irq_chip_data(d);
 
-	rzg3s_pcie_update_bits(host->axi, RZG3S_PCI_PINTRCVIS,
-			       RZG3S_PCI_PINTRCVIS_INTX(d->hwirq),
-			       RZG3S_PCI_PINTRCVIS_INTX(d->hwirq));
+	writel_relaxed(RZG3S_PCI_PINTRCVIS_INTX(d->hwirq),
+		       host->axi + RZG3S_PCI_PINTRCVIS);
 }
 
 static void rzg3s_pcie_intx_irq_mask(struct irq_data *d)
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 5/6] PCI: rzg3s-host: Drop read-modify-write approach for the R/W1C registers

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] PCI: rzg3s-host: commit log names PCI_PINTRCVIS_MSI instead of PCI_MSGRCVIS --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] PCI: rzg3s-host: commit log names PCI_PINTRCVIS_MSI instead of PCI_MSGRCVIS
--

commit bd4d2cfb8f9c8205f623ac50bc5c3221bd8dcdbe
Author: Claudiu Beznea <[email protected]>

PCI: rzg3s-host: Drop read-modify-write approach for the R/W1C registers

This commit replaces read-modify-write updates with direct writel_relaxed() writes when clearing the RZG3S_PCI_PINTRCVIS and RZG3S_PCI_MSGRCVIS R/W1C interrupt status registers.

Quoted 1 line

The AXI registers PCI_PINTRCVIS and PCI_PINTRCVIS_MSI are R/W1C.

[Severity: Low]
Should this refer to PCI_PINTRCVIS and PCI_MSGRCVIS instead? RZG3S_PCI_PINTRCVIS_MSI is a bit within RZG3S_PCI_PINTRCVIS, while the second register switched to writel_relaxed() in rzg3s_pcie_msi_irq() is RZG3S_PCI_MSGRCVIS.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

PATCH 6/6 PCI: rzg3s-host: Fix NVMe resume errors after s2idle

In reply to Claudiu Beznea

From: Ovidiu Panait <[email protected]>

On the Renesas RZ/V2H platform, when ASPM is enabled, resuming from s2idle with an NVMe SSD connected fails with:

nvme nvme0: I/O tag 27 (001b) opcode 0x9 (Admin Cmd) QID 0 timeout, reset controller nvme nvme0: Disabling device after reset failure: -19

This happens because during s2idle, when ASPM is enabled, nvme_suspend() does not shut the drive down. It leaves it in D0, puts it in its lowest NVMe power state, so that resume only has to restore the previous power state instead of a full reinitialization. This assumes the drive keeps its context over the suspend.

However, rzg3s_pcie_suspend_noirq() doesn't take this into account and it always powers down the controller and asserts the controller resets, including PERST#. That resets the drive, and the command the NVMe driver sends on resume never completes.

To fix this, similar to the dwc driver, use pci_host_common_d3cold_possible() to check if the controller should be powered down and keep the controller running otherwise. To keep the controller running, also call device_set_awake_path(), so that the PM domain does not turn off the controller clocks.

Do this only for s2idle. In s2ram the SoC could be powered off, and neither the PM domain nor the driver would restore the controller clocks and resets on resume. In hibernation, the controller must be reinitialized on restore.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

[claudiu.beznea:
- added "#include <linux/suspend.h>"
- added the suspended flag so that resume_noirq() does not re-initialize a controller that was not suspended, which would break it]

---

Changes since [1]:
- rebased on top of the fixes patches
- added suspended flags so that resume_noirq() does not re-initialize a controller that was not suspended, which could break it

[1] https://lore.kernel.org/all/[email protected]

 drivers/pci/controller/pcie-rzg3s-host.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/pci/controller/pcie-rzg3s-host.c +18 -0
index ad75e6895259..67a338cece3e 100644
@@ -33,6 +33,7 @@
 #include <linux/reset.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/units.h>
 
 #include "pci-host-common.h"
@@ -327,6 +328,7 @@ struct rzg3s_pcie_port {
  * @intx_irqs: INTx interrupts
  * @max_link_speed: maximum supported link speed
  * @controller_id: PCIe controller identifier, used for System Controller access
+ * @suspended: true if the controller was suspended in suspend_noirq()
  * @num_lanes: The number of lanes
  */
 struct rzg3s_pcie_host {
@@ -344,6 +346,7 @@ struct rzg3s_pcie_host {
 	int intx_irqs[PCI_NUM_INTX];
 	int max_link_speed;
 	enum rzg3s_pcie_controller_id controller_id;
+	bool suspended;
 	u8 num_lanes;
 };
 
@@ -1936,11 +1939,19 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 static int rzg3s_pcie_suspend_noirq(struct device *dev)
 {
 	struct rzg3s_pcie_host *host = dev_get_drvdata(dev);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
 	const struct rzg3s_pcie_soc_data *data = host->data;
 	struct rzg3s_pcie_port *port = &host->port;
 	struct rzg3s_sysc *sysc = host->sysc;
+	bool pme_capable;
 	int ret;
 
+	if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
+	    !pci_host_common_d3cold_possible(bridge, &pme_capable)) {
+		device_set_awake_path(dev);
+		return 0;
+	}
+
 	clk_disable_unprepare(port->refclk);
 
 	/* SoC-specific de-initialization */
@@ -1962,6 +1973,8 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
 	if (ret)
 		goto power_resets_restore;
 
+	host->suspended = true;
+
 	return 0;
 
 	/* Restore the previous state if any error happens */
@@ -1984,6 +1997,9 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 	struct rzg3s_sysc *sysc = host->sysc;
 	int ret;
 
+	if (!host->suspended)
+		return 0;
+
 	ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_MODE, 1);
 	if (ret)
 		return ret;
@@ -2016,6 +2032,8 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 	if (ret)
 		goto assert_power_resets;
 
+	host->suspended = false;
+
 	return 0;
 
 	/*
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH 6/6] PCI: rzg3s-host: Fix NVMe resume errors after s2idle

Quoted 2 lines

+ * @suspended: true if the controller was suspended in suspend_noirq()

Then, maybe 'suspended_in_noirq' would be a better variable name?

#13 lore raw

Re: [PATCH 6/6] PCI: rzg3s-host: Fix NVMe resume errors after s2idle

Quoted 4 lines · Wolfram Sang
Quoted 2 lines

+ * @suspended: true if the controller was suspended in suspend_noirq()

Then, maybe 'suspended_in_noirq' would be a better variable name?

Hm... I have nothing against it. Just that, I tried to keep it simple taking into account that this will eventually be removed by the https://lore.kernel.org/all/[email protected]

Thank you,
Claudiu

#14 lore raw

Re: [PATCH 6/6] PCI: rzg3s-host: Fix NVMe resume errors after s2idle

Quoted 3 lines

Hm... I have nothing against it. Just that, I tried to keep it simple taking into account that this will eventually be removed

Ah, okay. I don't mind then. Thanks for the heads up!

#15 lore raw

Re: [PATCH 6/6] PCI: rzg3s-host: Fix NVMe resume errors after s2idle

In reply to Claudiu Beznea
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] PCI: rzg3s-host: missing select PCI_HOST_COMMON causes link failure - [High] PCI: rzg3s-host: s2idle…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] PCI: rzg3s-host: missing select PCI_HOST_COMMON causes link failure
- [High] PCI: rzg3s-host: s2idle awake path triggers MSTOP via rzg2l_cpg_resume()
--

commit 7fbedf2fb7e05ca948fe32fe8ee79c121d940a34
Author: Ovidiu Panait <[email protected]>

PCI: rzg3s-host: Fix NVMe resume errors after s2idle

This commit skips powering down and reinitializing the PCIe host controller across s2idle when D3cold is not possible, keeping its PM domain clocks active via device_set_awake_path() and tracking the suspend state in host->suspended.

Quoted 4 lines
drivers/pci/controller/pcie-rzg3s-host.c +0 -0
index ad75e68952590..67a338cece3e2 100644

[ ... ]

Quoted 6 lines
drivers/pci/controller/pcie-rzg3s-host.c +1 -0
@@ -1936,11 +1939,19 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
 static int rzg3s_pcie_suspend_noirq(struct device *dev)
 {
 	struct rzg3s_pcie_host *host = dev_get_drvdata(dev);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
 	const struct rzg3s_pcie_soc_data *data = host->data;

drivers/pci/controller/pcie-rzg3s-host.c static int rzg3s_pcie_probe(struct platform_device *pdev) · line 1953

Quoted 10 lines
drivers/pci/controller/pcie-rzg3s-host.c +6 -0
 	struct rzg3s_pcie_port *port = &host->port;
 	struct rzg3s_sysc *sysc = host->sysc;
+	bool pme_capable;
 	int ret;
 
+	if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
+	    !pci_host_common_d3cold_possible(bridge, &pme_capable)) {
+		device_set_awake_path(dev);
+		return 0;
+	}

[Severity: High]
Does this fail to link vmlinux when CONFIG_PCI_HOST_COMMON is not built in?

pci_host_common_d3cold_possible() is a non-inline function in drivers/pci/controller/pci-host-common.c, while CONFIG_PCIE_RENESAS_RZG3S_HOST is bool and does not select PCI_HOST_COMMON.

When CONFIG_PCI_HOST_COMMON is n or m (for example when CONFIG_PCI_HOST_GENERIC=m is the only selector), linking fails with an undefined reference to pci_host_common_d3cold_possible(). Adding "select PCI_HOST_COMMON" to PCIE_RENESAS_RZG3S_HOST would fix this.

[ ... ]

drivers/pci/controller/pcie-rzg3s-host.c static int rzg3s_pcie_resume_noirq(struct device *dev) · line 2001

Quoted 6 lines
drivers/pci/controller/pcie-rzg3s-host.c +2 -0
@@ -1984,6 +1997,9 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
 	struct rzg3s_sysc *sysc = host->sysc;
 	int ret;
 
+	if (!host->suspended)
+		return 0;

[Severity: High]
Can skipping suspend on s2idle leave the PCIe controller hardware-stopped in MSTOP after resume on RZ/G3S and RZ/G3L?

On RZ/G3S and RZ/G3L (rzg2l-cpg.c), pci_aclk shares its MSTOP bit with pci_clkl1pm, which is in no_pm_mod_clks and remains disabled. With device_set_awake_path(dev) set, genpd_finish_suspend() skips pm_clk_suspend(), leaving pci_aclk enabled and mstop->usecnt nonzero.

On s2idle resume, rzg2l_cpg_resume() calls rzg2l_mod_enable_crit_clock_init_mstop() -> rzg2l_mod_clock_init_mstop_helper() for every module clock. Seeing the disabled pci_clkl1pm, it calls rzg2l_mod_clock_module_set_state(clk, true):

drivers/clk/renesas/rzg2l-cpg.c:rzg2l_mod_clock_module_set_state() {
    ...
		/* Allow updates on probe when usecnt = 0. */
		if (!atomic_read(&mstop->usecnt))
			update = true;
		else
			update = atomic_dec_and_test(&mstop->usecnt);
    ...
}

This decrements the shared mstop->usecnt to 0 (on the first s2idle resume on RZ/G3S, or the second on RZ/G3L) and asserts MSTOP. Because genpd_finish_resume() skips pm_clk_resume() and rzg3s_pcie_resume_noirq() returns early, the controller stays stopped when NVMe resumes.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6