[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <671f5c3b-fd24-7d24-c848-1ae31cea82ff@linux.intel.com>
Date: Thu, 16 Nov 2023 15:02:11 +0200 (EET)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: Mario Limonciello <mario.limonciello@....com>
cc: Karol Herbst <kherbst@...hat.com>, Lyude Paul <lyude@...hat.com>,
Alex Deucher <alexander.deucher@....com>,
Christian König <christian.koenig@....com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
Lukas Wunner <lukas@...ner.de>,
Danilo Krummrich <dakr@...hat.com>,
David Airlie <airlied@...il.com>,
Daniel Vetter <daniel@...ll.ch>,
Xinhui Pan <Xinhui.Pan@....com>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Pali Rohár <pali@...nel.org>,
Marek Behún <kabel@...nel.org>,
"Maciej W . Rozycki" <macro@...am.me.uk>,
Manivannan Sadhasivam <mani@...nel.org>,
"open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS"
<dri-devel@...ts.freedesktop.org>,
"open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS"
<nouveau@...ts.freedesktop.org>,
open list <linux-kernel@...r.kernel.org>,
"open list:RADEON and AMDGPU DRM DRIVERS"
<amd-gfx@...ts.freedesktop.org>,
"open list:PCI SUBSYSTEM" <linux-pci@...r.kernel.org>,
"open list:ACPI" <linux-acpi@...r.kernel.org>
Subject: Re: [PATCH v3 6/7] PCI: Split up some logic in pcie_bandwidth_available()
to separate function
On Tue, 14 Nov 2023, Mario Limonciello wrote:
> The logic to calculate bandwidth limits may be used at multiple call sites
> so split it up into its own static function instead.
>
> No intended functional changes.
>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@....com>
> ---
> v2->v3:
> * Split from previous patch version
> ---
> drivers/pci/pci.c | 60 +++++++++++++++++++++++++++--------------------
> 1 file changed, 34 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 55bc3576a985..0ff7883cc774 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6224,6 +6224,38 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
> }
> EXPORT_SYMBOL(pcie_set_mps);
>
> +static u32 pcie_calc_bw_limits(struct pci_dev *dev, u32 bw,
> + struct pci_dev **limiting_dev,
> + enum pci_bus_speed *speed,
> + enum pcie_link_width *width)
> +{
> + enum pcie_link_width next_width;
> + enum pci_bus_speed next_speed;
> + u32 next_bw;
> + u16 lnksta;
> +
> + pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
> +
> + next_speed = pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
> + next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
> +
> + next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
> +
> + /* Check if current device limits the total bandwidth */
I'd make this a function comment instead and say:
/* Check if @dev limits the total bandwidth. */
Other than that,
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
--
i.
> + if (!bw || next_bw <= bw) {
> + bw = next_bw;
> +
> + if (limiting_dev)
> + *limiting_dev = dev;
> + if (speed)
> + *speed = next_speed;
> + if (width)
> + *width = next_width;
> + }
> +
> + return bw;
> +}
> +
> /**
> * pcie_bandwidth_available - determine minimum link settings of a PCIe
> * device and its bandwidth limitation
> @@ -6242,39 +6274,15 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
> enum pci_bus_speed *speed,
> enum pcie_link_width *width)
> {
> - u16 lnksta;
> - enum pci_bus_speed next_speed;
> - enum pcie_link_width next_width;
> - u32 bw, next_bw;
> + u32 bw = 0;
>
> if (speed)
> *speed = PCI_SPEED_UNKNOWN;
> if (width)
> *width = PCIE_LNK_WIDTH_UNKNOWN;
>
> - bw = 0;
> -
> while (dev) {
> - pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
> -
> - next_speed = pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS,
> - lnksta)];
> - next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
> -
> - next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
> -
> - /* Check if current device limits the total bandwidth */
> - if (!bw || next_bw <= bw) {
> - bw = next_bw;
> -
> - if (limiting_dev)
> - *limiting_dev = dev;
> - if (speed)
> - *speed = next_speed;
> - if (width)
> - *width = next_width;
> - }
> -
> + bw = pcie_calc_bw_limits(dev, bw, limiting_dev, speed, width);
> dev = pci_upstream_bridge(dev);
> }
>
>
Powered by blists - more mailing lists