All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Alex Elder <elder@riscstar.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	bhelgaas@google.com, lpieralisi@kernel.org,
	kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org,
	kishon@kernel.org, dlan@gentoo.org, guodong@riscstar.com,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, p.zabel@pengutronix.de,
	christian.bruel@foss.st.com, shradha.t@samsung.com,
	krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com,
	namcao@linutronix.de, thippeswamy.havalige@amd.com,
	inochiama@gmail.com, devicetree@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-phy@lists.infradead.org,
	spacemit@lists.linux.dev, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Junzhong Pan <panjunzhong@linux.spacemit.com>
Subject: Re: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY
Date: Wed, 15 Oct 2025 23:51:02 +0200	[thread overview]
Message-ID: <aPAXRiGA8aTZCNTm@aurel32.net> (raw)
In-Reply-To: <20251013153526.2276556-5-elder@riscstar.com>

Hi,

On 2025-10-13 10:35, Alex Elder wrote:
> Introduce a driver that supports three PHYs found on the SpacemiT
> K1 SoC.  The first PHY is a combo PHY that can be configured for
> use for either USB 3 or PCIe.  The other two PHYs support PCIe
> only.
> 
> All three PHYs must be programmed with an 8 bit receiver termination
> value, which must be determined dynamically.  Only the combo PHY is
> able to determine this value.  The combo PHY performs a special
> calibration step at probe time to discover this, and that value is
> used to program each PHY that operates in PCIe mode.  The combo
> PHY must therefore be probed before either of the PCIe-only PHYs
> will be used.
> 
> Each PHY has an internal PLL driven from an external oscillator.
> This PLL started when the PHY is first initialized, and stays
> on thereafter.
> 
> During normal operation, the USB or PCIe driver using the PHY must
> ensure (other) clocks and resets are set up properly.
> 
> However PCIe mode clocks are enabled and resets are de-asserted
> temporarily by this driver to perform the calibration step on the
> combo PHY.
> 
> Tested-by: Junzhong Pan <panjunzhong@linux.spacemit.com>
> Signed-off-by: Alex Elder <elder@riscstar.com>

Thanks for this new version. I have tried it on top of v6.18-rc1 + 
spacemit DTS commits from next on a BPI-F3, and it fails calibrating the 
PHY with:

[    2.748405] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: calibration failed
[    2.755300] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: error probing combo phy
[    2.763088] spacemit-k1-pcie-phy c0b10000.phy: probe with driver spacemit-k1-pcie-phy failed with error -2
[   14.309031] platform c0d10000.phy: deferred probe pending: (reason unknown)
[   14.313426] platform c0c10000.phy: deferred probe pending: (reason unknown)
[   14.320347] platform ca400000.pcie: deferred probe pending: platform: supplier c0c10000.phy not ready
[   14.329542] platform ca800000.pcie: deferred probe pending: platform: supplier c0d10000.phy not ready

Note that version 1 was working fine on the same board.

[ snip ]

> diff --git a/drivers/phy/phy-spacemit-k1-pcie.c b/drivers/phy/phy-spacemit-k1-pcie.c
> new file mode 100644
> index 0000000000000..81bc05823d080
> --- /dev/null
> +++ b/drivers/phy/phy-spacemit-k1-pcie.c

[ snip ]

> +static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy)
> +{
> +	struct reset_control_bulk_data resets[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct clk_bulk_data clocks[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct device *dev = k1_phy->dev;
> +	struct reset_control *phy_reset;
> +	int ret = 0;
> +	int val;
> +
> +	/* Nothing to do if we already set the receiver termination value */
> +	if (k1_phy_rterm_valid())
> +		return 0;
> +
> +	/* De-assert the PHY (global) reset and leave it that way for USB */
> +	phy_reset = devm_reset_control_get_exclusive_deasserted(dev, "phy");
> +	if (IS_ERR(phy_reset))
> +		return PTR_ERR(phy_reset);
> +
> +	/*
> +	 * We also guarantee the APP_HOLD_PHY_RESET bit is clear.  We can
> +	 * leave this bit clear even if an error happens below.
> +	 */
> +	regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL,
> +			   PCIE_APP_HOLD_PHY_RST, false);
> +
> +	/* If the calibration already completed (e.g. by U-Boot), we're done */
> +	val = readl(k1_phy->regs + PCIE_RCAL_RESULT);
> +	if (val & R_TUNE_DONE)
> +		goto out_tune_done;
> +
> +	/* Put the PHY into PCIe mode */
> +	k1_combo_phy_sel(k1_phy, false);
> +
> +	/* Get and enable the PCIe app clocks */
> +	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
> +	if (ret <= 0) {
> +		if (!ret)
> +			ret = -ENOENT;
> +		goto out_tune_done;
> +	}

This part doesn't look correct. The documentation says this function 
"returns 0 if all clocks specified in clk_bulk_data table are obtained
successfully, or valid IS_ERR() condition containing errno."

To me, it seems the code should only be:

	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
	if (ret)
		goto out_tune_done;

[snip]

> +out_put_clocks:
> +	clk_bulk_put_all(ARRAY_SIZE(clocks), clocks);

When fixing the above bug, this then crashes with:

[    2.776109] Unable to handle kernel paging request at virtual address ffffffc41a0110c8
[    2.783958] Current kworker/u36:0 pgtable: 4K pagesize, 39-bit VAs, pgdp=0x00000000022a7000
[    2.792302] [ffffffc41a0110c8] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[    2.800980] Oops [#1]
[    2.803217] Modules linked in:
[    2.806261] CPU: 3 UID: 0 PID: 58 Comm: kworker/u36:0 Not tainted 6.18.0-rc1+ #4 PREEMPTLAZY 
[    2.814763] Hardware name: Banana Pi BPI-F3 (DT)
[    2.819366] Workqueue: events_unbound deferred_probe_work_func
[    2.825180] epc : virt_to_folio+0x5e/0xb8
[    2.829172]  ra : kfree+0x3a/0x528
[    2.832558] epc : ffffffff8034e12e ra : ffffffff8035557a sp : ffffffc600243980
[    2.839762]  gp : ffffffff82074258 tp : ffffffd700994d80 t0 : ffffffff80021540
[    2.846967]  t1 : 0000000000000018 t2 : 2d74696d65636170 s0 : ffffffc600243990
[    2.854172]  s1 : ffffffc600243ab8 a0 : 03ffffc41a0110c0 a1 : ffffffff82123bd0
[    2.861377]  a2 : 7c137c69131cec36 a3 : ffffffff816606d8 a4 : 0000000000000000
[    2.868583]  a5 : ffffffc500000000 a6 : 0000000000000004 a7 : 0000000000000004
[    2.875787]  s2 : ffffffd700b98410 s3 : ffffffc600243ab8 s4 : 0000000000000000
[    2.882991]  s5 : ffffffff80828f1c s6 : 0000000000008437 s7 : ffffffd700b98410
[    2.890197]  s8 : ffffffd700b98410 s9 : ffffffd700900240 s10: ffffffff81fc4100
[    2.897401]  s11: ffffffd700987400 t3 : 0000000000000004 t4 : 0000000000000001
[    2.904607]  t5 : 000000000000001f t6 : 0000000000000003
[    2.909902] status: 0000000200000120 badaddr: ffffffc41a0110c8 cause: 000000000000000d
[    2.917802] [<ffffffff8034e12e>] virt_to_folio+0x5e/0xb8
[    2.923097] [<ffffffff8035557a>] kfree+0x3a/0x528
[    2.927784] [<ffffffff80828f1c>] clk_bulk_put_all+0x64/0x78
[    2.933340] [<ffffffff807249d6>] k1_pcie_phy_probe+0x4ee/0x618
[    2.939155] [<ffffffff808e35e6>] platform_probe+0x56/0x98
[    2.944538] [<ffffffff808e0328>] really_probe+0xa0/0x348
[    2.949832] [<ffffffff808e064c>] __driver_probe_device+0x7c/0x140
[    2.955909] [<ffffffff808e07f8>] driver_probe_device+0x38/0xd0
[    2.961724] [<ffffffff808e0912>] __device_attach_driver+0x82/0xf0
[    2.967801] [<ffffffff808dde6a>] bus_for_each_drv+0x72/0xd0
[    2.973356] [<ffffffff808e0cac>] __device_attach+0x94/0x198
[    2.978912] [<ffffffff808e0fca>] device_initial_probe+0x1a/0x30
[    2.984815] [<ffffffff808defee>] bus_probe_device+0x96/0xa0
[    2.990370] [<ffffffff808dff0e>] deferred_probe_work_func+0xa6/0x110
[    2.996707] [<ffffffff8005cb66>] process_one_work+0x15e/0x340
[    3.002436] [<ffffffff8005d58c>] worker_thread+0x22c/0x348
[    3.007905] [<ffffffff80066b7c>] kthread+0x10c/0x208
[    3.012853] [<ffffffff80014de0>] ret_from_fork_kernel+0x18/0x1c0
[    3.018843] [<ffffffff80c917d6>] ret_from_fork_kernel_asm+0x16/0x18
[    3.025098] Code: 7a98 8d19 2717 0131 3703 5fa7 8131 8d19 051a 953e (651c) f713 
[    3.032497] ---[ end trace 0000000000000000 ]---

It seems that we want clk_bulk_put() and not clk_bulk_put_all(). The 
latter free the clocks, while they have been allocated on the stack.

Regards,
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

WARNING: multiple messages have this Message-ID (diff)
From: Aurelien Jarno <aurelien@aurel32.net>
To: Alex Elder <elder@riscstar.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	bhelgaas@google.com, lpieralisi@kernel.org,
	kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org,
	kishon@kernel.org, dlan@gentoo.org, guodong@riscstar.com,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, p.zabel@pengutronix.de,
	christian.bruel@foss.st.com, shradha.t@samsung.com,
	krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com,
	namcao@linutronix.de, thippeswamy.havalige@amd.com,
	inochiama@gmail.com, devicetree@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-phy@lists.infradead.org,
	spacemit@lists.linux.dev, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Junzhong Pan <panjunzhong@linux.spacemit.com>
Subject: Re: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY
Date: Wed, 15 Oct 2025 23:51:02 +0200	[thread overview]
Message-ID: <aPAXRiGA8aTZCNTm@aurel32.net> (raw)
In-Reply-To: <20251013153526.2276556-5-elder@riscstar.com>

Hi,

On 2025-10-13 10:35, Alex Elder wrote:
> Introduce a driver that supports three PHYs found on the SpacemiT
> K1 SoC.  The first PHY is a combo PHY that can be configured for
> use for either USB 3 or PCIe.  The other two PHYs support PCIe
> only.
> 
> All three PHYs must be programmed with an 8 bit receiver termination
> value, which must be determined dynamically.  Only the combo PHY is
> able to determine this value.  The combo PHY performs a special
> calibration step at probe time to discover this, and that value is
> used to program each PHY that operates in PCIe mode.  The combo
> PHY must therefore be probed before either of the PCIe-only PHYs
> will be used.
> 
> Each PHY has an internal PLL driven from an external oscillator.
> This PLL started when the PHY is first initialized, and stays
> on thereafter.
> 
> During normal operation, the USB or PCIe driver using the PHY must
> ensure (other) clocks and resets are set up properly.
> 
> However PCIe mode clocks are enabled and resets are de-asserted
> temporarily by this driver to perform the calibration step on the
> combo PHY.
> 
> Tested-by: Junzhong Pan <panjunzhong@linux.spacemit.com>
> Signed-off-by: Alex Elder <elder@riscstar.com>

Thanks for this new version. I have tried it on top of v6.18-rc1 + 
spacemit DTS commits from next on a BPI-F3, and it fails calibrating the 
PHY with:

[    2.748405] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: calibration failed
[    2.755300] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: error probing combo phy
[    2.763088] spacemit-k1-pcie-phy c0b10000.phy: probe with driver spacemit-k1-pcie-phy failed with error -2
[   14.309031] platform c0d10000.phy: deferred probe pending: (reason unknown)
[   14.313426] platform c0c10000.phy: deferred probe pending: (reason unknown)
[   14.320347] platform ca400000.pcie: deferred probe pending: platform: supplier c0c10000.phy not ready
[   14.329542] platform ca800000.pcie: deferred probe pending: platform: supplier c0d10000.phy not ready

Note that version 1 was working fine on the same board.

[ snip ]

> diff --git a/drivers/phy/phy-spacemit-k1-pcie.c b/drivers/phy/phy-spacemit-k1-pcie.c
> new file mode 100644
> index 0000000000000..81bc05823d080
> --- /dev/null
> +++ b/drivers/phy/phy-spacemit-k1-pcie.c

[ snip ]

> +static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy)
> +{
> +	struct reset_control_bulk_data resets[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct clk_bulk_data clocks[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct device *dev = k1_phy->dev;
> +	struct reset_control *phy_reset;
> +	int ret = 0;
> +	int val;
> +
> +	/* Nothing to do if we already set the receiver termination value */
> +	if (k1_phy_rterm_valid())
> +		return 0;
> +
> +	/* De-assert the PHY (global) reset and leave it that way for USB */
> +	phy_reset = devm_reset_control_get_exclusive_deasserted(dev, "phy");
> +	if (IS_ERR(phy_reset))
> +		return PTR_ERR(phy_reset);
> +
> +	/*
> +	 * We also guarantee the APP_HOLD_PHY_RESET bit is clear.  We can
> +	 * leave this bit clear even if an error happens below.
> +	 */
> +	regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL,
> +			   PCIE_APP_HOLD_PHY_RST, false);
> +
> +	/* If the calibration already completed (e.g. by U-Boot), we're done */
> +	val = readl(k1_phy->regs + PCIE_RCAL_RESULT);
> +	if (val & R_TUNE_DONE)
> +		goto out_tune_done;
> +
> +	/* Put the PHY into PCIe mode */
> +	k1_combo_phy_sel(k1_phy, false);
> +
> +	/* Get and enable the PCIe app clocks */
> +	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
> +	if (ret <= 0) {
> +		if (!ret)
> +			ret = -ENOENT;
> +		goto out_tune_done;
> +	}

This part doesn't look correct. The documentation says this function 
"returns 0 if all clocks specified in clk_bulk_data table are obtained
successfully, or valid IS_ERR() condition containing errno."

To me, it seems the code should only be:

	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
	if (ret)
		goto out_tune_done;

[snip]

> +out_put_clocks:
> +	clk_bulk_put_all(ARRAY_SIZE(clocks), clocks);

When fixing the above bug, this then crashes with:

[    2.776109] Unable to handle kernel paging request at virtual address ffffffc41a0110c8
[    2.783958] Current kworker/u36:0 pgtable: 4K pagesize, 39-bit VAs, pgdp=0x00000000022a7000
[    2.792302] [ffffffc41a0110c8] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[    2.800980] Oops [#1]
[    2.803217] Modules linked in:
[    2.806261] CPU: 3 UID: 0 PID: 58 Comm: kworker/u36:0 Not tainted 6.18.0-rc1+ #4 PREEMPTLAZY 
[    2.814763] Hardware name: Banana Pi BPI-F3 (DT)
[    2.819366] Workqueue: events_unbound deferred_probe_work_func
[    2.825180] epc : virt_to_folio+0x5e/0xb8
[    2.829172]  ra : kfree+0x3a/0x528
[    2.832558] epc : ffffffff8034e12e ra : ffffffff8035557a sp : ffffffc600243980
[    2.839762]  gp : ffffffff82074258 tp : ffffffd700994d80 t0 : ffffffff80021540
[    2.846967]  t1 : 0000000000000018 t2 : 2d74696d65636170 s0 : ffffffc600243990
[    2.854172]  s1 : ffffffc600243ab8 a0 : 03ffffc41a0110c0 a1 : ffffffff82123bd0
[    2.861377]  a2 : 7c137c69131cec36 a3 : ffffffff816606d8 a4 : 0000000000000000
[    2.868583]  a5 : ffffffc500000000 a6 : 0000000000000004 a7 : 0000000000000004
[    2.875787]  s2 : ffffffd700b98410 s3 : ffffffc600243ab8 s4 : 0000000000000000
[    2.882991]  s5 : ffffffff80828f1c s6 : 0000000000008437 s7 : ffffffd700b98410
[    2.890197]  s8 : ffffffd700b98410 s9 : ffffffd700900240 s10: ffffffff81fc4100
[    2.897401]  s11: ffffffd700987400 t3 : 0000000000000004 t4 : 0000000000000001
[    2.904607]  t5 : 000000000000001f t6 : 0000000000000003
[    2.909902] status: 0000000200000120 badaddr: ffffffc41a0110c8 cause: 000000000000000d
[    2.917802] [<ffffffff8034e12e>] virt_to_folio+0x5e/0xb8
[    2.923097] [<ffffffff8035557a>] kfree+0x3a/0x528
[    2.927784] [<ffffffff80828f1c>] clk_bulk_put_all+0x64/0x78
[    2.933340] [<ffffffff807249d6>] k1_pcie_phy_probe+0x4ee/0x618
[    2.939155] [<ffffffff808e35e6>] platform_probe+0x56/0x98
[    2.944538] [<ffffffff808e0328>] really_probe+0xa0/0x348
[    2.949832] [<ffffffff808e064c>] __driver_probe_device+0x7c/0x140
[    2.955909] [<ffffffff808e07f8>] driver_probe_device+0x38/0xd0
[    2.961724] [<ffffffff808e0912>] __device_attach_driver+0x82/0xf0
[    2.967801] [<ffffffff808dde6a>] bus_for_each_drv+0x72/0xd0
[    2.973356] [<ffffffff808e0cac>] __device_attach+0x94/0x198
[    2.978912] [<ffffffff808e0fca>] device_initial_probe+0x1a/0x30
[    2.984815] [<ffffffff808defee>] bus_probe_device+0x96/0xa0
[    2.990370] [<ffffffff808dff0e>] deferred_probe_work_func+0xa6/0x110
[    2.996707] [<ffffffff8005cb66>] process_one_work+0x15e/0x340
[    3.002436] [<ffffffff8005d58c>] worker_thread+0x22c/0x348
[    3.007905] [<ffffffff80066b7c>] kthread+0x10c/0x208
[    3.012853] [<ffffffff80014de0>] ret_from_fork_kernel+0x18/0x1c0
[    3.018843] [<ffffffff80c917d6>] ret_from_fork_kernel_asm+0x16/0x18
[    3.025098] Code: 7a98 8d19 2717 0131 3703 5fa7 8131 8d19 051a 953e (651c) f713 
[    3.032497] ---[ end trace 0000000000000000 ]---

It seems that we want clk_bulk_put() and not clk_bulk_put_all(). The 
latter free the clocks, while they have been allocated on the stack.

Regards,
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

WARNING: multiple messages have this Message-ID (diff)
From: Aurelien Jarno <aurelien@aurel32.net>
To: Alex Elder <elder@riscstar.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	bhelgaas@google.com, lpieralisi@kernel.org,
	kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org,
	kishon@kernel.org, dlan@gentoo.org, guodong@riscstar.com,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, p.zabel@pengutronix.de,
	christian.bruel@foss.st.com, shradha.t@samsung.com,
	krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com,
	namcao@linutronix.de, thippeswamy.havalige@amd.com,
	inochiama@gmail.com, devicetree@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-phy@lists.infradead.org,
	spacemit@lists.linux.dev, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Junzhong Pan <panjunzhong@linux.spacemit.com>
Subject: Re: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY
Date: Wed, 15 Oct 2025 23:51:02 +0200	[thread overview]
Message-ID: <aPAXRiGA8aTZCNTm@aurel32.net> (raw)
In-Reply-To: <20251013153526.2276556-5-elder@riscstar.com>

Hi,

On 2025-10-13 10:35, Alex Elder wrote:
> Introduce a driver that supports three PHYs found on the SpacemiT
> K1 SoC.  The first PHY is a combo PHY that can be configured for
> use for either USB 3 or PCIe.  The other two PHYs support PCIe
> only.
> 
> All three PHYs must be programmed with an 8 bit receiver termination
> value, which must be determined dynamically.  Only the combo PHY is
> able to determine this value.  The combo PHY performs a special
> calibration step at probe time to discover this, and that value is
> used to program each PHY that operates in PCIe mode.  The combo
> PHY must therefore be probed before either of the PCIe-only PHYs
> will be used.
> 
> Each PHY has an internal PLL driven from an external oscillator.
> This PLL started when the PHY is first initialized, and stays
> on thereafter.
> 
> During normal operation, the USB or PCIe driver using the PHY must
> ensure (other) clocks and resets are set up properly.
> 
> However PCIe mode clocks are enabled and resets are de-asserted
> temporarily by this driver to perform the calibration step on the
> combo PHY.
> 
> Tested-by: Junzhong Pan <panjunzhong@linux.spacemit.com>
> Signed-off-by: Alex Elder <elder@riscstar.com>

Thanks for this new version. I have tried it on top of v6.18-rc1 + 
spacemit DTS commits from next on a BPI-F3, and it fails calibrating the 
PHY with:

[    2.748405] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: calibration failed
[    2.755300] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: error probing combo phy
[    2.763088] spacemit-k1-pcie-phy c0b10000.phy: probe with driver spacemit-k1-pcie-phy failed with error -2
[   14.309031] platform c0d10000.phy: deferred probe pending: (reason unknown)
[   14.313426] platform c0c10000.phy: deferred probe pending: (reason unknown)
[   14.320347] platform ca400000.pcie: deferred probe pending: platform: supplier c0c10000.phy not ready
[   14.329542] platform ca800000.pcie: deferred probe pending: platform: supplier c0d10000.phy not ready

Note that version 1 was working fine on the same board.

[ snip ]

> diff --git a/drivers/phy/phy-spacemit-k1-pcie.c b/drivers/phy/phy-spacemit-k1-pcie.c
> new file mode 100644
> index 0000000000000..81bc05823d080
> --- /dev/null
> +++ b/drivers/phy/phy-spacemit-k1-pcie.c

[ snip ]

> +static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy)
> +{
> +	struct reset_control_bulk_data resets[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct clk_bulk_data clocks[] = {
> +		{ .id = "dbi", },
> +		{ .id = "mstr", },
> +		{ .id = "slv", },
> +	};
> +	struct device *dev = k1_phy->dev;
> +	struct reset_control *phy_reset;
> +	int ret = 0;
> +	int val;
> +
> +	/* Nothing to do if we already set the receiver termination value */
> +	if (k1_phy_rterm_valid())
> +		return 0;
> +
> +	/* De-assert the PHY (global) reset and leave it that way for USB */
> +	phy_reset = devm_reset_control_get_exclusive_deasserted(dev, "phy");
> +	if (IS_ERR(phy_reset))
> +		return PTR_ERR(phy_reset);
> +
> +	/*
> +	 * We also guarantee the APP_HOLD_PHY_RESET bit is clear.  We can
> +	 * leave this bit clear even if an error happens below.
> +	 */
> +	regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL,
> +			   PCIE_APP_HOLD_PHY_RST, false);
> +
> +	/* If the calibration already completed (e.g. by U-Boot), we're done */
> +	val = readl(k1_phy->regs + PCIE_RCAL_RESULT);
> +	if (val & R_TUNE_DONE)
> +		goto out_tune_done;
> +
> +	/* Put the PHY into PCIe mode */
> +	k1_combo_phy_sel(k1_phy, false);
> +
> +	/* Get and enable the PCIe app clocks */
> +	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
> +	if (ret <= 0) {
> +		if (!ret)
> +			ret = -ENOENT;
> +		goto out_tune_done;
> +	}

This part doesn't look correct. The documentation says this function 
"returns 0 if all clocks specified in clk_bulk_data table are obtained
successfully, or valid IS_ERR() condition containing errno."

To me, it seems the code should only be:

	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
	if (ret)
		goto out_tune_done;

[snip]

> +out_put_clocks:
> +	clk_bulk_put_all(ARRAY_SIZE(clocks), clocks);

When fixing the above bug, this then crashes with:

[    2.776109] Unable to handle kernel paging request at virtual address ffffffc41a0110c8
[    2.783958] Current kworker/u36:0 pgtable: 4K pagesize, 39-bit VAs, pgdp=0x00000000022a7000
[    2.792302] [ffffffc41a0110c8] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[    2.800980] Oops [#1]
[    2.803217] Modules linked in:
[    2.806261] CPU: 3 UID: 0 PID: 58 Comm: kworker/u36:0 Not tainted 6.18.0-rc1+ #4 PREEMPTLAZY 
[    2.814763] Hardware name: Banana Pi BPI-F3 (DT)
[    2.819366] Workqueue: events_unbound deferred_probe_work_func
[    2.825180] epc : virt_to_folio+0x5e/0xb8
[    2.829172]  ra : kfree+0x3a/0x528
[    2.832558] epc : ffffffff8034e12e ra : ffffffff8035557a sp : ffffffc600243980
[    2.839762]  gp : ffffffff82074258 tp : ffffffd700994d80 t0 : ffffffff80021540
[    2.846967]  t1 : 0000000000000018 t2 : 2d74696d65636170 s0 : ffffffc600243990
[    2.854172]  s1 : ffffffc600243ab8 a0 : 03ffffc41a0110c0 a1 : ffffffff82123bd0
[    2.861377]  a2 : 7c137c69131cec36 a3 : ffffffff816606d8 a4 : 0000000000000000
[    2.868583]  a5 : ffffffc500000000 a6 : 0000000000000004 a7 : 0000000000000004
[    2.875787]  s2 : ffffffd700b98410 s3 : ffffffc600243ab8 s4 : 0000000000000000
[    2.882991]  s5 : ffffffff80828f1c s6 : 0000000000008437 s7 : ffffffd700b98410
[    2.890197]  s8 : ffffffd700b98410 s9 : ffffffd700900240 s10: ffffffff81fc4100
[    2.897401]  s11: ffffffd700987400 t3 : 0000000000000004 t4 : 0000000000000001
[    2.904607]  t5 : 000000000000001f t6 : 0000000000000003
[    2.909902] status: 0000000200000120 badaddr: ffffffc41a0110c8 cause: 000000000000000d
[    2.917802] [<ffffffff8034e12e>] virt_to_folio+0x5e/0xb8
[    2.923097] [<ffffffff8035557a>] kfree+0x3a/0x528
[    2.927784] [<ffffffff80828f1c>] clk_bulk_put_all+0x64/0x78
[    2.933340] [<ffffffff807249d6>] k1_pcie_phy_probe+0x4ee/0x618
[    2.939155] [<ffffffff808e35e6>] platform_probe+0x56/0x98
[    2.944538] [<ffffffff808e0328>] really_probe+0xa0/0x348
[    2.949832] [<ffffffff808e064c>] __driver_probe_device+0x7c/0x140
[    2.955909] [<ffffffff808e07f8>] driver_probe_device+0x38/0xd0
[    2.961724] [<ffffffff808e0912>] __device_attach_driver+0x82/0xf0
[    2.967801] [<ffffffff808dde6a>] bus_for_each_drv+0x72/0xd0
[    2.973356] [<ffffffff808e0cac>] __device_attach+0x94/0x198
[    2.978912] [<ffffffff808e0fca>] device_initial_probe+0x1a/0x30
[    2.984815] [<ffffffff808defee>] bus_probe_device+0x96/0xa0
[    2.990370] [<ffffffff808dff0e>] deferred_probe_work_func+0xa6/0x110
[    2.996707] [<ffffffff8005cb66>] process_one_work+0x15e/0x340
[    3.002436] [<ffffffff8005d58c>] worker_thread+0x22c/0x348
[    3.007905] [<ffffffff80066b7c>] kthread+0x10c/0x208
[    3.012853] [<ffffffff80014de0>] ret_from_fork_kernel+0x18/0x1c0
[    3.018843] [<ffffffff80c917d6>] ret_from_fork_kernel_asm+0x16/0x18
[    3.025098] Code: 7a98 8d19 2717 0131 3703 5fa7 8131 8d19 051a 953e (651c) f713 
[    3.032497] ---[ end trace 0000000000000000 ]---

It seems that we want clk_bulk_put() and not clk_bulk_put_all(). The 
latter free the clocks, while they have been allocated on the stack.

Regards,
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-10-15 21:52 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13 15:35 [PATCH v2 0/7] Introduce SpacemiT K1 PCIe phy and host controller Alex Elder
2025-10-13 15:35 ` Alex Elder
2025-10-13 15:35 ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 1/7] dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-15 14:52   ` Rob Herring
2025-10-15 14:52     ` Rob Herring
2025-10-15 14:52     ` Rob Herring
2025-10-17 16:20     ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 2/7] dt-bindings: phy: spacemit: introduce PCIe PHY Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-15 16:41   ` Rob Herring (Arm)
2025-10-15 16:41     ` Rob Herring (Arm)
2025-10-15 16:41     ` Rob Herring (Arm)
2025-10-17 16:20     ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-14  1:55   ` Yao Zi
2025-10-14  1:55     ` Yao Zi
2025-10-14  1:55     ` Yao Zi
2025-10-14  1:57     ` Alex Elder
2025-10-14  1:57       ` Alex Elder
2025-10-14  1:57       ` Alex Elder
2025-10-15 16:47   ` Rob Herring
2025-10-15 16:47     ` Rob Herring
2025-10-15 16:47     ` Rob Herring
2025-10-17 16:20     ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-17 16:20       ` Alex Elder
2025-10-26 16:38   ` Manivannan Sadhasivam
2025-10-26 16:38     ` Manivannan Sadhasivam
2025-10-26 16:38     ` Manivannan Sadhasivam
2025-10-27 22:24     ` Alex Elder
2025-10-27 22:24       ` Alex Elder
2025-10-27 22:24       ` Alex Elder
2025-10-28  5:58       ` Manivannan Sadhasivam
2025-10-28  5:58         ` Manivannan Sadhasivam
2025-10-28  5:58         ` Manivannan Sadhasivam
2025-10-30  0:10         ` Alex Elder
2025-10-30  0:10           ` Alex Elder
2025-10-30  0:10           ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-15 21:51   ` Aurelien Jarno [this message]
2025-10-15 21:51     ` Aurelien Jarno
2025-10-15 21:51     ` Aurelien Jarno
2025-10-17 16:21     ` Alex Elder
2025-10-17 16:21       ` Alex Elder
2025-10-17 16:21       ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-26 16:55   ` Manivannan Sadhasivam
2025-10-26 16:55     ` Manivannan Sadhasivam
2025-10-26 16:55     ` Manivannan Sadhasivam
2025-10-27 22:24     ` Alex Elder
2025-10-27 22:24       ` Alex Elder
2025-10-27 22:24       ` Alex Elder
2025-10-28  7:06       ` Manivannan Sadhasivam
2025-10-28  7:06         ` Manivannan Sadhasivam
2025-10-28  7:06         ` Manivannan Sadhasivam
2025-10-30  0:10         ` Alex Elder
2025-10-30  0:10           ` Alex Elder
2025-10-30  0:10           ` Alex Elder
2025-10-31  6:05           ` Manivannan Sadhasivam
2025-10-31  6:05             ` Manivannan Sadhasivam
2025-10-31  6:05             ` Manivannan Sadhasivam
2025-10-31 13:38             ` Alex Elder
2025-10-31 13:38               ` Alex Elder
2025-10-31 13:38               ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 6/7] riscv: dts: spacemit: add a PCIe regulator Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35 ` [PATCH v2 7/7] riscv: dts: spacemit: PCIe and PHY-related updates Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-13 15:35   ` Alex Elder
2025-10-16 16:47 ` [PATCH v2 0/7] Introduce SpacemiT K1 PCIe phy and host controller Aurelien Jarno
2025-10-16 16:47   ` Aurelien Jarno
2025-10-16 16:47   ` Aurelien Jarno
2025-10-17 16:21   ` Alex Elder
2025-10-17 16:21     ` Alex Elder
2025-10-17 16:21     ` Alex Elder
2025-10-28 17:59     ` Aurelien Jarno
2025-10-28 17:59       ` Aurelien Jarno
2025-10-28 17:59       ` Aurelien Jarno
2025-10-28 18:42       ` Johannes Erdfelt
2025-10-28 18:42         ` Johannes Erdfelt
2025-10-28 18:42         ` Johannes Erdfelt
2025-10-28 19:10         ` Alex Elder
2025-10-28 19:10           ` Alex Elder
2025-10-28 19:10           ` Alex Elder
2025-10-28 20:48           ` Johannes Erdfelt
2025-10-28 20:48             ` Johannes Erdfelt
2025-10-28 20:48             ` Johannes Erdfelt
2025-10-28 20:49             ` Alex Elder
2025-10-28 20:49               ` Alex Elder
2025-10-28 20:49               ` Alex Elder
2025-10-30 16:41             ` Manivannan Sadhasivam
2025-10-30 16:41               ` Manivannan Sadhasivam
2025-10-30 16:41               ` Manivannan Sadhasivam
2025-10-30 17:49               ` Aurelien Jarno
2025-10-30 17:49                 ` Aurelien Jarno
2025-10-30 17:49                 ` Aurelien Jarno
2025-10-31  6:10                 ` Manivannan Sadhasivam
2025-10-31  6:10                   ` Manivannan Sadhasivam
2025-10-31  6:10                   ` Manivannan Sadhasivam
2025-11-03 16:42                   ` Alex Elder
2025-11-03 16:42                     ` Alex Elder
2025-11-03 16:42                     ` Alex Elder
2025-10-28 21:08           ` Aurelien Jarno
2025-10-28 21:08             ` Aurelien Jarno
2025-10-28 21:08             ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aPAXRiGA8aTZCNTm@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=bhelgaas@google.com \
    --cc=christian.bruel@foss.st.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@gentoo.org \
    --cc=elder@riscstar.com \
    --cc=guodong@riscstar.com \
    --cc=inochiama@gmail.com \
    --cc=kishon@kernel.org \
    --cc=krishna.chundru@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=namcao@linutronix.de \
    --cc=p.zabel@pengutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=panjunzhong@linux.spacemit.com \
    --cc=pjw@kernel.org \
    --cc=qiang.yu@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=shradha.t@samsung.com \
    --cc=spacemit@lists.linux.dev \
    --cc=thippeswamy.havalige@amd.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.