From: Frank Li <Frank.li@nxp.com>
To: Hans Zhang <18255117159@163.com>
Cc: lpieralisi@kernel.org, bhelgaas@google.com, mani@kernel.org,
kwilczynski@kernel.org, robh@kernel.org, jingoohan1@gmail.com,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 04/13] PCI: dwc: Refactor imx6 to use dw_pcie_clear_and_set_dword()
Date: Wed, 11 Jun 2025 14:45:53 -0400 [thread overview]
Message-ID: <aEnO4QSrAzEHzoAe@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <aEnNFgv08BVVxfOQ@lizhi-Precision-Tower-5810>
On Wed, Jun 11, 2025 at 02:38:14PM -0400, Frank Li wrote:
> On Thu, Jun 12, 2025 at 12:31:21AM +0800, Hans Zhang wrote:
>
> Subject should be
>
> PCI: dwc: imx6: Refactor code by using dw_pcie_clear_and_set_dword()
>
> tag "imx6:" should after "dwc:"
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
I sent out too quick, please don't applied my review tag at next version
because I found a issue, see:
https://lore.kernel.org/linux-pci/aEnONwJUSEMdMAUD@lizhi-Precision-Tower-5810/
Frank
>
> > i.MX6 PCIe driver contains multiple read-modify-write sequences for
> > link training and speed configuration. These operations manually handle
> > bit masking and shifting to update specific fields in control registers,
> > particularly for link capabilities and speed change initiation.
> >
> > Refactor link capability configuration and speed change handling using
> > dw_pcie_clear_and_set_dword(). The helper simplifies LNKCAP modification
> > by encapsulating bit clear/set operations and eliminates intermediate
> > variables. For speed change control, replace explicit bit manipulation
> > with direct register updates through the helper.
> >
> > Adopting the standard interface reduces code complexity in link training
> > paths and ensures consistent handling of speed-related bits. The change
> > also prepares the driver for future enhancements to Gen3 link training
> > by centralizing bit manipulation logic.
> >
> > Signed-off-by: Hans Zhang <18255117159@163.com>
> > ---
> > drivers/pci/controller/dwc/pci-imx6.c | 26 ++++++++++----------------
> > 1 file changed, 10 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> > index 5a38cfaf989b..3004e432f013 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -941,7 +941,6 @@ static int imx_pcie_start_link(struct dw_pcie *pci)
> > struct imx_pcie *imx_pcie = to_imx_pcie(pci);
> > struct device *dev = pci->dev;
> > u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
> > - u32 tmp;
> > int ret;
> >
> > if (!(imx_pcie->drvdata->flags &
> > @@ -956,10 +955,9 @@ static int imx_pcie_start_link(struct dw_pcie *pci)
> > * bus will not be detected at all. This happens with PCIe switches.
> > */
> > dw_pcie_dbi_ro_wr_en(pci);
> > - tmp = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP);
> > - tmp &= ~PCI_EXP_LNKCAP_SLS;
> > - tmp |= PCI_EXP_LNKCAP_SLS_2_5GB;
> > - dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, tmp);
> > + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_LNKCAP,
> > + PCI_EXP_LNKCAP_SLS,
> > + PCI_EXP_LNKCAP_SLS_2_5GB);
> > dw_pcie_dbi_ro_wr_dis(pci);
> >
> > /* Start LTSSM. */
> > @@ -972,18 +970,16 @@ static int imx_pcie_start_link(struct dw_pcie *pci)
> >
> > /* Allow faster modes after the link is up */
> > dw_pcie_dbi_ro_wr_en(pci);
> > - tmp = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP);
> > - tmp &= ~PCI_EXP_LNKCAP_SLS;
> > - tmp |= pci->max_link_speed;
> > - dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, tmp);
> > + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_LNKCAP,
> > + PCI_EXP_LNKCAP_SLS,
> > + pci->max_link_speed);
> >
> > /*
> > * Start Directed Speed Change so the best possible
> > * speed both link partners support can be negotiated.
> > */
> > - tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
> > - tmp |= PORT_LOGIC_SPEED_CHANGE;
> > - dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
> > + dw_pcie_clear_and_set_dword(pci, PCIE_LINK_WIDTH_SPEED_CONTROL,
> > + 0, PORT_LOGIC_SPEED_CHANGE);
> > dw_pcie_dbi_ro_wr_dis(pci);
> >
> > ret = imx_pcie_wait_for_speed_change(imx_pcie);
> > @@ -1295,7 +1291,6 @@ static void imx_pcie_host_post_init(struct dw_pcie_rp *pp)
> > {
> > struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> > struct imx_pcie *imx_pcie = to_imx_pcie(pci);
> > - u32 val;
> >
> > if (imx_pcie->drvdata->flags & IMX_PCIE_FLAG_8GT_ECN_ERR051586) {
> > /*
> > @@ -1310,9 +1305,8 @@ static void imx_pcie_host_post_init(struct dw_pcie_rp *pp)
> > * to 0.
> > */
> > dw_pcie_dbi_ro_wr_en(pci);
> > - val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
> > - val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
> > - dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
> > + dw_pcie_clear_and_set_dword(pci, GEN3_RELATED_OFF,
> > + GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL, 0);
> > dw_pcie_dbi_ro_wr_dis(pci);
> > }
> > }
> > --
> > 2.25.1
> >
next prev parent reply other threads:[~2025-06-11 18:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 16:31 Hans Zhang
2025-06-11 18:38 ` Frank Li
2025-06-11 18:45 ` Frank Li [this message]
2025-06-12 0:50 ` Hans Zhang
2025-06-12 0:46 ` Hans Zhang
2025-06-11 18:43 ` Frank Li
2025-06-12 0:47 ` Hans Zhang
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=aEnO4QSrAzEHzoAe@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=18255117159@163.com \
--cc=bhelgaas@google.com \
--cc=jingoohan1@gmail.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®