From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Hans Zhang <18255117159@163.com>
Cc: bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com,
kwilczynski@kernel.org, mani@kernel.org, jingoohan1@gmail.com,
robh@kernel.org, linux-pci@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 3/3] PCI: dwc: Use common speed conversion function
Date: Tue, 7 Apr 2026 15:29:59 +0300 (EEST) [thread overview]
Message-ID: <2af36546-5c33-caf8-b15d-fbf8fec4417e@linux.intel.com> (raw)
In-Reply-To: <70f81184-4900-499b-a6ee-fbe18367bd0a@163.com>
[-- Attachment #1: Type: text/plain, Size: 5398 bytes --]
On Tue, 7 Apr 2026, Hans Zhang wrote:
> On 4/7/26 16:25, Ilpo Järvinen wrote:
> > On Mon, 6 Apr 2026, Hans Zhang wrote:
> >
> > > Replace the private switch-based speed conversion in
> > > dw_pcie_link_set_max_speed() with the public pci_bus_speed2lnkctl2()
> > > function.
> > >
> > > This eliminates duplicate conversion logic and ensures consistency with
> > > other PCIe drivers, while handling invalid speeds by falling back to
> > > hardware capabilities.
> > >
> > > Signed-off-by: Hans Zhang <18255117159@163.com>
> > > Acked-by: Manivannan Sadhasivam <mani@kernel.org>
> > > ---
> > > drivers/pci/controller/dwc/pcie-designware.c | 18 +++---------------
> > > 1 file changed, 3 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c
> > > b/drivers/pci/controller/dwc/pcie-designware.c
> > > index 06792ba92aa7..ab8dee5d6c7a 100644
> > > --- a/drivers/pci/controller/dwc/pcie-designware.c
> > > +++ b/drivers/pci/controller/dwc/pcie-designware.c
> > > @@ -861,24 +861,12 @@ static void dw_pcie_link_set_max_speed(struct
> > > dw_pcie *pci)
> > > ctrl2 = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCTL2);
> > > ctrl2 &= ~PCI_EXP_LNKCTL2_TLS;
> > > - switch (pcie_get_link_speed(pci->max_link_speed)) {
> > > - case PCIE_SPEED_2_5GT:
> > > - link_speed = PCI_EXP_LNKCTL2_TLS_2_5GT;
> > > - break;
> > > - case PCIE_SPEED_5_0GT:
> > > - link_speed = PCI_EXP_LNKCTL2_TLS_5_0GT;
> > > - break;
> > > - case PCIE_SPEED_8_0GT:
> > > - link_speed = PCI_EXP_LNKCTL2_TLS_8_0GT;
> > > - break;
> > > - case PCIE_SPEED_16_0GT:
> > > - link_speed = PCI_EXP_LNKCTL2_TLS_16_0GT;
> > > - break;
> > > - default:
> > > + link_speed = pcie_get_link_speed(pci->max_link_speed);
> > > + link_speed = pci_bus_speed2lnkctl2(link_speed);
> >
> > Its signature is:
> >
> > u16 pci_bus_speed2lnkctl2(enum pci_bus_speed speed)
> >
> > Using link_speed variable both for in and out does contradict with the
> > expected typing.
> >
> > Maybe it would be beneficial to rename the current 'link_speed' to
> > 'ctrl2_speed' (or something along those lines) to differentiate Link
> > Control 2 speed representation from PCI core's internal link speed
> > representation. And then reintroduce link_speed variable as the
> > pci_bus_speed. ...But this is just my suggestion, there may be better ways
> > to untangle this type abuse.
>
> Hi Ilpo,
>
>
> Thank you for your review comments. This way it will be clearer. Here are my
> revisions. If there are no issues, I will send the next version.
>
>
> diff --git a/drivers/pci/controller/dwc/pcie-designware.c
> b/drivers/pci/controller/dwc/pcie-designware.c
> index 06792ba92aa7..21a709a47e82 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.c
> +++ b/drivers/pci/controller/dwc/pcie-designware.c
> @@ -843,8 +843,9 @@ EXPORT_SYMBOL_GPL(dw_pcie_upconfig_setup);
>
> static void dw_pcie_link_set_max_speed(struct dw_pcie *pci)
> {
> - u32 cap, ctrl2, link_speed;
> + u32 cap, ctrl2, pci_bus_speed;
I meant something like this (instead of introducing variable named
"pci_bus_speed"):
enum pci_bus_speed link_speed;
> u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
> + u16 ctrl2_speed;
...And keep this like you have it now.
--
i.
> cap = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP);
>
> @@ -861,30 +862,18 @@ static void dw_pcie_link_set_max_speed(struct dw_pcie
> *pci)
> ctrl2 = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCTL2);
> ctrl2 &= ~PCI_EXP_LNKCTL2_TLS;
>
> - switch (pcie_get_link_speed(pci->max_link_speed)) {
> - case PCIE_SPEED_2_5GT:
> - link_speed = PCI_EXP_LNKCTL2_TLS_2_5GT;
> - break;
> - case PCIE_SPEED_5_0GT:
> - link_speed = PCI_EXP_LNKCTL2_TLS_5_0GT;
> - break;
> - case PCIE_SPEED_8_0GT:
> - link_speed = PCI_EXP_LNKCTL2_TLS_8_0GT;
> - break;
> - case PCIE_SPEED_16_0GT:
> - link_speed = PCI_EXP_LNKCTL2_TLS_16_0GT;
> - break;
> - default:
> + pci_bus_speed = pcie_get_link_speed(pci->max_link_speed);
> + ctrl2_speed = pci_bus_speed2lnkctl2(pci_bus_speed);
> + if (ctrl2_speed == 0) {
> /* Use hardware capability */
> - link_speed = FIELD_GET(PCI_EXP_LNKCAP_SLS, cap);
> + ctrl2_speed = FIELD_GET(PCI_EXP_LNKCAP_SLS, cap);
> ctrl2 &= ~PCI_EXP_LNKCTL2_HASD;
> - break;
> }
>
> - dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCTL2, ctrl2 | link_speed);
> + dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCTL2, ctrl2 |
> ctrl2_speed);
>
> cap &= ~((u32)PCI_EXP_LNKCAP_SLS);
> - dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, cap | link_speed);
> + dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, cap | ctrl2_speed);
>
>
> Best regards,
> Hans
>
> >
> > > + if (link_speed == 0) {
> > > /* Use hardware capability */
> > > link_speed = FIELD_GET(PCI_EXP_LNKCAP_SLS, cap);
> > > ctrl2 &= ~PCI_EXP_LNKCTL2_HASD;
> > > - break;
> > > }
> > > dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCTL2, ctrl2 |
> > > link_speed);
> > >
> >
>
next prev parent reply other threads:[~2026-04-07 12:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 10:56 [PATCH v6 0/3] PCI: Refactor PCIe speed validation and conversion functions Hans Zhang
2026-04-06 10:56 ` [PATCH v6 1/3] PCI: Add public pcie_valid_speed() for shared validation Hans Zhang
2026-04-06 10:56 ` [PATCH v6 2/3] PCI: Move pci_bus_speed2lnkctl2() to public header Hans Zhang
2026-04-06 10:56 ` [PATCH v6 3/3] PCI: dwc: Use common speed conversion function Hans Zhang
2026-04-07 8:25 ` Ilpo Järvinen
2026-04-07 12:19 ` Hans Zhang
2026-04-07 12:29 ` Ilpo Järvinen [this message]
2026-04-07 12:32 ` Hans Zhang
2026-04-07 0:36 ` [PATCH v6 0/3] PCI: Refactor PCIe speed validation and conversion functions Shawn Lin
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=2af36546-5c33-caf8-b15d-fbf8fec4417e@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=18255117159@163.com \
--cc=bhelgaas@google.com \
--cc=jingoohan1@gmail.com \
--cc=kw@linux.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®