Re: [PATCH v7 1/3] PCI: Add public pcie_valid_speed() for shared validation
From: Bjorn Helgaas
Date: Thu Jun 11 2026 - 13:50:23 EST
On Tue, Apr 07, 2026 at 09:04:48PM +0800, Hans Zhang wrote:
> Extract the PCIe speed validation logic from bwctrl.c's static
> pcie_valid_speed() into a public static inline function in pci.h.
>
> This allows consistent speed range checks (2.5GT/s to 64.0GT/s) across
> multiple drivers and functions, avoiding duplicate code and ensuring
> validation consistency as per PCIe specifications.
>
> Signed-off-by: Hans Zhang <18255117159@xxxxxxx>
> Reviewed-by: Shawn Lin <shawn.lin@xxxxxxxxxxxxxx>
Acked-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Any objection, Ilpo?
It looks like 1/3 and 2/3 are pure moves, and the interesting part is
the use in dwc, which I'd like to be reviewed and applied by Mani.
> ---
> drivers/pci/pci.h | 5 +++++
> drivers/pci/pcie/bwctrl.c | 5 -----
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 4a14f88e543a..f0a082bfd6f1 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -606,6 +606,11 @@ void pci_bus_put(struct pci_bus *bus);
> (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \
> 0)
>
> +static inline bool pcie_valid_speed(enum pci_bus_speed speed)
> +{
> + return (speed >= PCIE_SPEED_2_5GT) && (speed <= PCIE_SPEED_64_0GT);
> +}
> +
> static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed)
> {
> switch (speed) {
> diff --git a/drivers/pci/pcie/bwctrl.c b/drivers/pci/pcie/bwctrl.c
> index c4c8d260bf96..ea82e326f164 100644
> --- a/drivers/pci/pcie/bwctrl.c
> +++ b/drivers/pci/pcie/bwctrl.c
> @@ -48,11 +48,6 @@ struct pcie_bwctrl_data {
> /* Prevent port removal during Link Speed changes. */
> static DECLARE_RWSEM(pcie_bwctrl_setspeed_rwsem);
>
> -static bool pcie_valid_speed(enum pci_bus_speed speed)
> -{
> - return (speed >= PCIE_SPEED_2_5GT) && (speed <= PCIE_SPEED_64_0GT);
> -}
> -
> static u16 pci_bus_speed2lnkctl2(enum pci_bus_speed speed)
> {
> static const u8 speed_conv[] = {
> --
> 2.34.1
>