2022-06-13 09:26:30

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation

This series patches refine pci-imx6 driver and do the following main changes.
- Encapsulate the clock enable into one standalone function
- Add the error propagation from host_init and resume
- Turn off regulator when the system is in suspend mode
- Let the probe successfully when link never comes up
- Do not hide the phy driver callbacks in core reset and clk_enable.
BTW, this series are verified on i.MX8MM EVK board when one NVME is used.

Main changes from v9 to v10:
- Add the "Reviewed-by: Lucas Stach <[email protected]>" tag into #3
and #4 patches.
Refer to Bjorn's comments:
- refine the commit of the first patch
- keep alignment of the message format in the second patch
- More specific commit and subject of the #5 and #7 patches.
Refer to Lucas' comments:
- Move the regualtor_disable into suspend, turn off the regulator when bus
is powered off and system in suspend mode.
- Let the driver probe successfully, return zero in imx6_pcie_start_link()
when PCIe link is down.
In this link down scenario, only start the PCIe link training in resume
when the link is up before system suspend to avoid the long latency in
the link training period.
- Don't hide phy driver callbacks in core reset and clk_enable, and refine
the error handling accordingly.
- Drop the #8 patch of v9 series, since the clocks and powers are not gated
off anymore when link is down.

Main changes from v8 to v9:
- Don't change pcie-designware codes, and do the error exit process only in
pci-imx6 driver internally.
- Move the phy driver callbacks to the proper places

Main changes from v7 to v8:
Regarding Bjorn's review comments.
- Align the format of the dev_info message and refine commit log of
#6/7/8 patches.
- Rename the err_reset_phy label, since there is no PHY reset in the out

Main changes from v6 to v7:
- Keep the regulator usage counter balance in the #5 patch of v6 series.

Main changes from v5 to v6:
- Refer to the following discussion with Fabio, fix the dump by his patch.
https://patchwork.kernel.org/project/linux-pci/patch/[email protected]/
Refine and rebase this patch-set after Fabio' dump fix patch is merged.
- Add one new #4 patch to disable i.MX6QDL REF clock too when disable clocks
- Split the regulator refine codes into one standalone patch #5 in this version.

Main changes from v4 to v5:
- Since i.MX8MM PCIe support had been merged. Based on Lorenzo's git repos,
resend the patch-set after rebase.

Main changes from v3 to v4:
- Regarding Mark's comments, delete the regulator_is_enabled() check.
- Squash #3 and #6 of v3 patch into #5 patch of v4 set.

Main changes from v2 to v3:
- Add "Reviewed-by: Lucas Stach <[email protected]>" tag into
first two patches.
- Add a Fixes tag into #3 patch.
- Split the #4 of v2 to two patches, one is clock disable codes move,
the other one is the acutal clock unbalance fix.
- Add a new host_exit() callback into dw_pcie_host_ops, then it could be
invoked to handle the unbalance issue in the error handling after
host_init() function when link is down.
- Add a new host_exit() callback for i.MX PCIe driver to handle this case
in the error handling after host_init.

Main changes from v1 to v2:
Regarding Lucas' comments.
- Move the placement of the new imx6_pcie_clk_enable() to avoid the
forward declarition.
- Seperate the second patch of v1 patch-set to three patches.
- Use the module_param to replace the kernel command line.
Regarding Bjorn's comments:
- Use the cover-letter for a multi-patch series.
- Correct the subject line, and refine the commit logs. For example,
remove the timestamp of the logs.

drivers/pci/controller/dwc/pci-imx6.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 157 insertions(+), 84 deletions(-)

[PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one
[PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
[PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
[PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when
[PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in
[PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
[PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and


2022-06-13 09:43:15

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling

- Move the phy_power_on() to host_init and resume functions from
imx6_pcie_clk_enable().
- Move the phy_init() to host_init and resume functions from
imx6_pcie_deassert_core_reset().

Refine the error handling in imx6_pcie_host_init() and
imx6_pcie_resume_noirq() functions accordingly.

Signed-off-by: Richard Zhu <[email protected]>
---
drivers/pci/controller/dwc/pci-imx6.c | 69 +++++++++++++++++++++------
1 file changed, 55 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index ac6ec2d691a0..61d9fa0120b4 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -498,14 +498,6 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)
goto err_ref_clk;
}

- switch (imx6_pcie->drvdata->variant) {
- case IMX8MM:
- if (phy_power_on(imx6_pcie->phy))
- dev_err(dev, "unable to power on PHY\n");
- break;
- default:
- break;
- }
/* allow the clocks to stabilize */
usleep_range(200, 500);
return 0;
@@ -599,10 +591,6 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
case IMX8MQ:
reset_control_deassert(imx6_pcie->pciephy_reset);
break;
- case IMX8MM:
- if (phy_init(imx6_pcie->phy))
- dev_err(dev, "waiting for phy ready timeout!\n");
- break;
case IMX7D:
reset_control_deassert(imx6_pcie->pciephy_reset);

@@ -638,6 +626,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
usleep_range(200, 500);
break;
case IMX6Q: /* Nothing to do */
+ case IMX8MM:
break;
}

@@ -913,15 +902,39 @@ static int imx6_pcie_host_init(struct pcie_port *pp)

imx6_pcie_assert_core_reset(imx6_pcie);
imx6_pcie_init_phy(imx6_pcie);
+ if (imx6_pcie->phy) {
+ ret = phy_power_on(imx6_pcie->phy);
+ if (ret) {
+ dev_err(dev, "pcie phy power up failed.\n");
+ return ret;
+ }
+ }
+
ret = imx6_pcie_deassert_core_reset(imx6_pcie);
if (ret < 0) {
dev_err(dev, "pcie host init failed: %d\n", ret);
- return ret;
+ goto err_phy_off;
+ }
+ if (imx6_pcie->phy) {
+ ret = phy_init(imx6_pcie->phy);
+ if (ret) {
+ dev_err(dev, "waiting for phy ready timeout!\n");
+ goto err_phy_init;
+ }
}

imx6_setup_phy_mpll(imx6_pcie);

return 0;
+
+err_phy_init:
+ imx6_pcie_clk_disable(imx6_pcie);
+ if (imx6_pcie->vpcie)
+ regulator_disable(imx6_pcie->vpcie);
+err_phy_off:
+ if (imx6_pcie->phy)
+ phy_power_off(imx6_pcie->phy);
+ return ret;
}

static const struct dw_pcie_host_ops imx6_pcie_host_ops = {
@@ -1026,12 +1039,40 @@ static int imx6_pcie_resume_noirq(struct device *dev)

imx6_pcie_assert_core_reset(imx6_pcie);
imx6_pcie_init_phy(imx6_pcie);
- imx6_pcie_deassert_core_reset(imx6_pcie);
+ if (imx6_pcie->phy) {
+ ret = phy_power_on(imx6_pcie->phy);
+ if (ret) {
+ dev_err(dev, "pcie phy power up failed.\n");
+ return ret;
+ }
+ }
+
+ ret = imx6_pcie_deassert_core_reset(imx6_pcie);
+ if (ret < 0) {
+ dev_err(dev, "pcie deassert core reset failed: %d.\n", ret);
+ goto err_phy_off;
+ } else if (imx6_pcie->phy) {
+ ret = phy_init(imx6_pcie->phy);
+ if (ret) {
+ dev_err(dev, "pcie phy init failed.\n");
+ goto err_phy_init;
+ }
+ }
+
dw_pcie_setup_rc(pp);
if (imx6_pcie->link_is_up)
imx6_pcie_start_link(imx6_pcie->pci);

return 0;
+
+err_phy_init:
+ imx6_pcie_clk_disable(imx6_pcie);
+ if (imx6_pcie->vpcie)
+ regulator_disable(imx6_pcie->vpcie);
+err_phy_off:
+ if (imx6_pcie->phy)
+ phy_power_off(imx6_pcie->phy);
+ return ret;
}
#endif

--
2.25.1

2022-06-13 09:45:23

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init

Since there is error return check of the host_init callback, add error
check to imx6_pcie_deassert_core_reset() function, and change the
function type accordingly.

Signed-off-by: Richard Zhu <[email protected]>
Reviewed-by: Lucas Stach <[email protected]>
---
drivers/pci/controller/dwc/pci-imx6.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index d3ef0e94ab26..e1420409b47f 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -542,24 +542,24 @@ static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
dev_err(dev, "PCIe PLL lock timeout\n");
}

-static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
+static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
{
struct dw_pcie *pci = imx6_pcie->pci;
struct device *dev = pci->dev;
- int ret;
+ int ret, err;

if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) {
ret = regulator_enable(imx6_pcie->vpcie);
if (ret) {
dev_err(dev, "failed to enable vpcie regulator: %d\n",
ret);
- return;
+ return ret;
}
}

- ret = imx6_pcie_clk_enable(imx6_pcie);
- if (ret) {
- dev_err(dev, "unable to enable pcie clocks\n");
+ err = imx6_pcie_clk_enable(imx6_pcie);
+ if (err) {
+ dev_err(dev, "unable to enable pcie clocks: %d\n", err);
goto err_clks;
}

@@ -618,7 +618,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
break;
}

- return;
+ return 0;

err_clks:
if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
@@ -627,6 +627,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
dev_err(dev, "failed to disable vpcie regulator: %d\n",
ret);
}
+ return err;
}

static void imx6_pcie_configure_type(struct imx6_pcie *imx6_pcie)
@@ -878,11 +879,18 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
static int imx6_pcie_host_init(struct pcie_port *pp)
{
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+ struct device *dev = pci->dev;
struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
+ int ret;

imx6_pcie_assert_core_reset(imx6_pcie);
imx6_pcie_init_phy(imx6_pcie);
- imx6_pcie_deassert_core_reset(imx6_pcie);
+ ret = imx6_pcie_deassert_core_reset(imx6_pcie);
+ if (ret < 0) {
+ dev_err(dev, "pcie host init failed: %d\n", ret);
+ return ret;
+ }
+
imx6_setup_phy_mpll(imx6_pcie);

return 0;
--
2.25.1

2022-06-13 21:19:58

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation

On Mon, Jun 13, 2022 at 04:55:31PM +0800, Richard Zhu wrote:
> This series patches refine pci-imx6 driver and do the following main changes.
> - Encapsulate the clock enable into one standalone function
> - Add the error propagation from host_init and resume
> - Turn off regulator when the system is in suspend mode
> - Let the probe successfully when link never comes up
> - Do not hide the phy driver callbacks in core reset and clk_enable.

This doesn't apply on v5.19-rc1 for me. Am I missing something:

03:38:06 ~/linux (main)$ git checkout -b wip/richard-imx6-power-v10 v5.19-rc1
Switched to a new branch 'wip/richard-imx6-power-v10'
03:38:14 ~/linux (wip/richard-imx6-power-v10)$ b4 am -om/ https://lore.kernel.org/r/[email protected]
Looking up https://lore.kernel.org/r/1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.com
Analyzing 9 messages in the thread
Checking attestation on all messages, may take a moment...
---
[PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function
[PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
[PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
[PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks
[PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode
[PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
[PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling
---
Total patches: 7
---
Cover: m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.cover
Link: https://lore.kernel.org/r/[email protected]
Base: not specified
git am m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.mbx
03:38:27 ~/linux (wip/richard-imx6-power-v10)$ git am m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.mbx
Applying: PCI: imx6: Encapsulate the clock enable into one standalone function
error: patch failed: drivers/pci/controller/dwc/pci-imx6.c:539
error: drivers/pci/controller/dwc/pci-imx6.c: patch does not apply
Patch failed at 0001 PCI: imx6: Encapsulate the clock enable into one standalone function
hint: Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

2022-06-14 01:29:46

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation

> -----Original Message-----
> From: Bjorn Helgaas <[email protected]>
> Sent: 2022??6??14?? 4:41
> To: Hongxing Zhu <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; dl-linux-imx <[email protected]>
> Subject: Re: [PATCH v10 0/7] PCI: imx6: refine codes and add the error
> propagation
>
> On Mon, Jun 13, 2022 at 04:55:31PM +0800, Richard Zhu wrote:
> > This series patches refine pci-imx6 driver and do the following main changes.
> > - Encapsulate the clock enable into one standalone function
> > - Add the error propagation from host_init and resume
> > - Turn off regulator when the system is in suspend mode
> > - Let the probe successfully when link never comes up
> > - Do not hide the phy driver callbacks in core reset and clk_enable.
>
> This doesn't apply on v5.19-rc1 for me. Am I missing something:
Hi Bjorn:
The V10 patch based on Shawn's for-next branch.
I would rebased them on v5.19-rc1 later.

Best Regards
Richard Zhu

>
> 03:38:06 ~/linux (main)$ git checkout -b wip/richard-imx6-power-v10
> v5.19-rc1
> Switched to a new branch 'wip/richard-imx6-power-v10'
> 03:38:14 ~/linux (wip/richard-imx6-power-v10)$ b4 am -om/
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.co
> m&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f90
> 919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%
> 7C&amp;sdata=bCMhbBxRNV8D0lnVBxURUFRbtMNADUxZJq4wZz47rKY%3D&
> amp;reserved=0
> Looking up
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%2540nxp.
> com&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f
> 90919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7
> C%7C&amp;sdata=s3FVLiwJneQlQPV1KKj4cPJ2jD%2FtKudkqP4wd0LACgI%3D
> &amp;reserved=0
> Analyzing 9 messages in the thread
> Checking attestation on all messages, may take a moment...
> ---
> [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one
> standalone function
> [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
> [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
> [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable
> PCIe clocks
> [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in
> suspend mode
> [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
> [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the
> error handling
> ---
> Total patches: 7
> ---
> Cover:
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.cover
> Link:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.co
> m&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f90
> 919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%
> 7C&amp;sdata=bCMhbBxRNV8D0lnVBxURUFRbtMNADUxZJq4wZz47rKY%3D&
> amp;reserved=0
> Base: not specified
> git am
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.mbx
> 03:38:27 ~/linux (wip/richard-imx6-power-v10)$ git am
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.mbx
> Applying: PCI: imx6: Encapsulate the clock enable into one standalone
> function
> error: patch failed: drivers/pci/controller/dwc/pci-imx6.c:539
> error: drivers/pci/controller/dwc/pci-imx6.c: patch does not apply
> Patch failed at 0001 PCI: imx6: Encapsulate the clock enable into one
> standalone function
> hint: Use 'git am --show-current-patch' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".