mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access
@ 2026-11-08  9:40 Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c Hans Zhang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

Hi,

This series finishes encapsulating the pcie_link_speed[] array by
converting the remaining direct users to pcie_get_link_speed() and
making the array private to probe.c.

The pcie_get_link_speed() helper was introduced and accepted in the
v10 "PCI: of: Remove max-link-speed generation validation" series, but
a few users that were added later still index pcie_link_speed[]
directly.

Changes since v1:
- Rebase onto v7.4-rc1.
- Use pcie_get_link_speed(), which is already exported and
  bounds-checked, instead of introducing a new to_pcie_link_speed()
  helper.
- Split the pci.c change from the other core conversions, mirroring the
  split between v1 patches 1 and 2.
- Convert probe.c's max_bus_speed lookup, which v1 missed.
- Convert the Tegra264 and MediaTek controller drivers, which were
  added after the v10 series and would otherwise fail to build once the
  array is no longer exported.
- Split the two controller conversions into separate patches so each
  driver can be reviewed independently.
- Make pcie_link_speed[] static instead of only removing its extern
  declaration and export.

v1 series: https://patchwork.kernel.org/project/linux-pci/patch/20260315160057.127639-1-18255117159@163.com/

Hans Zhang (5):
  PCI: Use pcie_get_link_speed() in pci.c
  PCI: Convert remaining core pcie_link_speed[] users
  PCI: tegra264: Use pcie_get_link_speed()
  PCI: mediatek: Use pcie_get_link_speed()
  PCI: Make pcie_link_speed[] private to probe.c

 drivers/pci/controller/pcie-mediatek.c | 2 +-
 drivers/pci/controller/pcie-tegra264.c | 6 +++---
 drivers/pci/pci-sysfs.c                | 2 +-
 drivers/pci/pci.c                      | 9 ++-------
 drivers/pci/pci.h                      | 3 +--
 drivers/pci/probe.c                    | 5 ++---
 6 files changed, 10 insertions(+), 17 deletions(-)


base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c
  2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
@ 2026-11-08  9:40 ` Hans Zhang
  2026-11-09 12:03   ` Ilpo Järvinen
  2026-11-08  9:40 ` [PATCH v2 2/5] PCI: Convert remaining core pcie_link_speed[] users Hans Zhang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

Replace the to_pcie_link_speed() wrapper with pcie_get_link_speed() in
pcie_link_bandwidth_mbps() and pcie_bandwidth_available(), and remove
the now-unused wrapper.  pcie_get_link_speed() performs the same lookup
with bounds checking and is already exported.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/pci.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..92ede1768caf 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6025,11 +6025,6 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
 }
 EXPORT_SYMBOL(pcie_set_mps);
 
-static enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
-{
-	return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
-}
-
 /**
  * pcie_link_bandwidth_mbps - get the current bandwidth of a single PCIe link
  * @pdev: PCI device to query
@@ -6048,7 +6043,7 @@ int pcie_link_bandwidth_mbps(struct pci_dev *pdev)
 	if (err)
 		return pcibios_err_to_errno(err);
 
-	speed = pcie_dev_speed_mbps(to_pcie_link_speed(lnksta));
+	speed = pcie_dev_speed_mbps(pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)));
 	if (speed < 0)
 		return speed;
 
@@ -6089,7 +6084,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
 	while (dev) {
 		pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
 
-		next_speed = to_pcie_link_speed(lnksta);
+		next_speed = pcie_get_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);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] PCI: Convert remaining core pcie_link_speed[] users
  2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c Hans Zhang
@ 2026-11-08  9:40 ` Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 3/5] PCI: tegra264: Use pcie_get_link_speed() Hans Zhang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

Convert the remaining direct pcie_link_speed[] accesses in pci-sysfs.c,
the __pcie_update_link_speed() inline helper, and pci_set_bus_speed() in
probe.c to pcie_get_link_speed().  This includes the max_bus_speed
lookup that was missed in v1.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/pci-sysfs.c | 2 +-
 drivers/pci/pci.h       | 2 +-
 drivers/pci/probe.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 6669e9ad5bd3..30db3349a44c 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -234,7 +234,7 @@ static ssize_t current_link_speed_show(struct device *dev,
 	if (err)
 		return -EINVAL;
 
-	speed = pcie_link_speed[linkstat & PCI_EXP_LNKSTA_CLS];
+	speed = pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS, linkstat));
 
 	return sysfs_emit(buf, "%s\n", pci_speed_string(speed));
 }
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..5441741bc330 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -692,7 +692,7 @@ static inline void __pcie_update_link_speed(struct pci_bus *bus,
 					    enum pcie_link_change_reason reason,
 					    u16 linksta, u16 linksta2)
 {
-	bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS];
+	bus->cur_bus_speed = pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS, linksta));
 	bus->flit_mode = (linksta2 & PCI_EXP_LNKSTA2_FLIT) ? 1 : 0;
 
 	trace_pcie_link_event(bus,
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..d0283a8158f2 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -924,7 +924,7 @@ static void pci_set_bus_speed(struct pci_bus *bus)
 		u32 linkcap;
 
 		pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap);
-		bus->max_bus_speed = pcie_link_speed[linkcap & PCI_EXP_LNKCAP_SLS];
+		bus->max_bus_speed = pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKCAP_SLS, linkcap));
 
 		pcie_update_link_speed(bus, PCIE_ADD_BUS);
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] PCI: tegra264: Use pcie_get_link_speed()
  2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 2/5] PCI: Convert remaining core pcie_link_speed[] users Hans Zhang
@ 2026-11-08  9:40 ` Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 4/5] PCI: mediatek: " Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 5/5] PCI: Make pcie_link_speed[] private to probe.c Hans Zhang
  4 siblings, 0 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

Tegra264 was added after pcie_get_link_speed() was introduced and still
indexes pcie_link_speed[] directly.  Convert it to the helper so it does
not depend on the array being exported and cannot go out of bounds on
invalid speed values.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/pcie-tegra264.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/pcie-tegra264.c b/drivers/pci/controller/pcie-tegra264.c
index c97576ab4a31..711b66287681 100644
--- a/drivers/pci/controller/pcie-tegra264.c
+++ b/drivers/pci/controller/pcie-tegra264.c
@@ -126,7 +126,7 @@ static void tegra264_pcie_icc_set(struct tegra264_pcie *pcie)
 		width = FIELD_GET(PCI_EXP_LNKCAP_MLW, value);
 	}
 
-	value = Mbps_to_icc(width * PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]));
+	value = Mbps_to_icc(width * PCIE_SPEED2MBS_ENC(pcie_get_link_speed(speed)));
 
 	/*
 	 * We don't want to error out here because a boot-critical device
@@ -266,8 +266,8 @@ static bool tegra264_pcie_link_up(struct tegra264_pcie *pcie,
 
 	if (value & PCI_EXP_LNKSTA_DLLLA) {
 		if (speed)
-			*speed = pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS,
-							   value)];
+			*speed = pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS,
+							       value));
 
 		return true;
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] PCI: mediatek: Use pcie_get_link_speed()
  2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
                   ` (2 preceding siblings ...)
  2026-11-08  9:40 ` [PATCH v2 3/5] PCI: tegra264: Use pcie_get_link_speed() Hans Zhang
@ 2026-11-08  9:40 ` Hans Zhang
  2026-11-08  9:40 ` [PATCH v2 5/5] PCI: Make pcie_link_speed[] private to probe.c Hans Zhang
  4 siblings, 0 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

MediaTek was added after pcie_get_link_speed() was introduced and still
indexes pcie_link_speed[] directly.  Convert it to the helper so it does
not depend on the array being exported and cannot go out of bounds on
invalid speed values.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/pcie-mediatek.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 3a3e91cd0c21..ffde365c987f 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -888,7 +888,7 @@ static int mtk_pcie_retrain(struct device *dev, struct pci_host_bridge *host)
 		speed = lnksta & PCI_EXP_LNKSTA_CLS;
 
 		pci_info(rp, "link retrained, speed %s\n",
-			 pci_speed_string(pcie_link_speed[speed]));
+			 pci_speed_string(pcie_get_link_speed(speed)));
 
 	}
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] PCI: Make pcie_link_speed[] private to probe.c
  2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
                   ` (3 preceding siblings ...)
  2026-11-08  9:40 ` [PATCH v2 4/5] PCI: mediatek: " Hans Zhang
@ 2026-11-08  9:40 ` Hans Zhang
  4 siblings, 0 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-08  9:40 UTC (permalink / raw)
  To: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh
  Cc: robh, linux-pci, linux-kernel, linux-mediatek, linux-tegra, Hans Zhang

pcie_get_link_speed() is now the only accessor for pcie_link_speed[].
Make the array static and remove its extern declaration and export so no
other code can index it directly.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/pci.h   | 1 -
 drivers/pci/probe.c | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 5441741bc330..04bdf3b86a56 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -118,7 +118,6 @@ struct pcie_tlp_log;
 #define PCI_EXP_AER_FLAGS	(PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | \
 				 PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE)
 
-extern const unsigned char pcie_link_speed[];
 unsigned char pcie_get_link_speed(unsigned int speed);
 
 extern bool pci_early_dump;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index d0283a8158f2..f79b048f45a4 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -756,7 +756,7 @@ static const unsigned char pcix_bus_speed[] = {
 };
 
 /* Indexed by PCI_EXP_LNKCAP_SLS, PCI_EXP_LNKSTA_CLS */
-const unsigned char pcie_link_speed[] = {
+static const unsigned char pcie_link_speed[] = {
 	PCI_SPEED_UNKNOWN,		/* 0 */
 	PCIE_SPEED_2_5GT,		/* 1 */
 	PCIE_SPEED_5_0GT,		/* 2 */
@@ -774,7 +774,6 @@ const unsigned char pcie_link_speed[] = {
 	PCI_SPEED_UNKNOWN,		/* E */
 	PCI_SPEED_UNKNOWN		/* F */
 };
-EXPORT_SYMBOL_GPL(pcie_link_speed);
 
 /**
  * pcie_get_link_speed - Get speed value from PCIe generation number
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c
  2026-11-08  9:40 ` [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c Hans Zhang
@ 2026-11-09 12:03   ` Ilpo Järvinen
  2026-11-09 15:06     ` Hans Zhang
  0 siblings, 1 reply; 8+ messages in thread
From: Ilpo Järvinen @ 2026-11-09 12:03 UTC (permalink / raw)
  To: Hans Zhang
  Cc: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh, robh, linux-pci, LKML, linux-mediatek,
	linux-tegra

On Sun, 8 Nov 2026, Hans Zhang wrote:

> Replace the to_pcie_link_speed() wrapper with pcie_get_link_speed() in
> pcie_link_bandwidth_mbps() and pcie_bandwidth_available(), and remove
> the now-unused wrapper.  pcie_get_link_speed() performs the same lookup
> with bounds checking and is already exported.
> 
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
>  drivers/pci/pci.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 7c6f2aba8144..92ede1768caf 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6025,11 +6025,6 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
>  }
>  EXPORT_SYMBOL(pcie_set_mps);
>  
> -static enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
> -{
> -	return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
> -}
> -
>  /**
>   * pcie_link_bandwidth_mbps - get the current bandwidth of a single PCIe link
>   * @pdev: PCI device to query
> @@ -6048,7 +6043,7 @@ int pcie_link_bandwidth_mbps(struct pci_dev *pdev)
>  	if (err)
>  		return pcibios_err_to_errno(err);
>  
> -	speed = pcie_dev_speed_mbps(to_pcie_link_speed(lnksta));
> +	speed = pcie_dev_speed_mbps(pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)));

Readability seems worse due to cramming everything into a single 
statement.

>  	if (speed < 0)
>  		return speed;
>  
> @@ -6089,7 +6084,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
>  	while (dev) {
>  		pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
>  
> -		next_speed = to_pcie_link_speed(lnksta);
> +		next_speed = pcie_get_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);
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c
  2026-11-09 12:03   ` Ilpo Järvinen
@ 2026-11-09 15:06     ` Hans Zhang
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Zhang @ 2026-11-09 15:06 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: bhelgaas, mani, lpieralisi, kwilczynski, thierry.reding,
	ryder.lee, jonathanh, robh, linux-pci, LKML, linux-mediatek,
	linux-tegra



On 11/9/26 20:03, Ilpo Järvinen wrote:
> On Sun, 8 Nov 2026, Hans Zhang wrote:
> 
>> Replace the to_pcie_link_speed() wrapper with pcie_get_link_speed() in
>> pcie_link_bandwidth_mbps() and pcie_bandwidth_available(), and remove
>> the now-unused wrapper.  pcie_get_link_speed() performs the same lookup
>> with bounds checking and is already exported.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>>   drivers/pci/pci.c | 9 ++-------
>>   1 file changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index 7c6f2aba8144..92ede1768caf 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -6025,11 +6025,6 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
>>   }
>>   EXPORT_SYMBOL(pcie_set_mps);
>>   
>> -static enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
>> -{
>> -	return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
>> -}
>> -
>>   /**
>>    * pcie_link_bandwidth_mbps - get the current bandwidth of a single PCIe link
>>    * @pdev: PCI device to query
>> @@ -6048,7 +6043,7 @@ int pcie_link_bandwidth_mbps(struct pci_dev *pdev)
>>   	if (err)
>>   		return pcibios_err_to_errno(err);
>>   
>> -	speed = pcie_dev_speed_mbps(to_pcie_link_speed(lnksta));
>> +	speed = pcie_dev_speed_mbps(pcie_get_link_speed(FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)));
> 
> Readability seems worse due to cramming everything into a single
> statement.

Hello Ilpo,

Agreed. I'll split the link speed class into a separate local variable
at both call sites, keeping lnksta intact for the link width extraction.

I'll send v3 of the series with this change.


diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..594ee7aa4cad 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6025,11 +6025,6 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
  }
  EXPORT_SYMBOL(pcie_set_mps);

-static enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
-{
-	return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
-}
-
  /**
   * pcie_link_bandwidth_mbps - get the current bandwidth of a single 
PCIe link
   * @pdev: PCI device to query
@@ -6041,14 +6036,15 @@ static enum pci_bus_speed to_pcie_link_speed(u16 
lnksta)
   */
  int pcie_link_bandwidth_mbps(struct pci_dev *pdev)
  {
-	u16 lnksta;
+	u16 lnksta, lnksta_cls;
  	int speed, err;

  	err = pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
  	if (err)
  		return pcibios_err_to_errno(err);

-	speed = pcie_dev_speed_mbps(to_pcie_link_speed(lnksta));
+	lnksta_cls = FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta);
+	speed = pcie_dev_speed_mbps(pcie_get_link_speed(lnksta_cls));
  	if (speed < 0)
  		return speed;

@@ -6074,7 +6070,7 @@ 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;
+	u16 lnksta, lnksta_cls;
  	enum pci_bus_speed next_speed;
  	enum pcie_link_width next_width;
  	u32 bw, next_bw;
@@ -6089,7 +6085,8 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, 
struct pci_dev **limiting_dev,
  	while (dev) {
  		pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);

-		next_speed = to_pcie_link_speed(lnksta);
+		lnksta_cls = FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta);
+		next_speed = pcie_get_link_speed(lnksta_cls);
  		next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);

  		next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);




Best regards,
Hans



> 
>>   	if (speed < 0)
>>   		return speed;
>>   
>> @@ -6089,7 +6084,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
>>   	while (dev) {
>>   		pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
>>   
>> -		next_speed = to_pcie_link_speed(lnksta);
>> +		next_speed = pcie_get_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);
>>
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-09 15:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08  9:40 [PATCH v2 0/5] PCI: Encapsulate pcie_link_speed array access Hans Zhang
2026-11-08  9:40 ` [PATCH v2 1/5] PCI: Use pcie_get_link_speed() in pci.c Hans Zhang
2026-11-09 12:03   ` Ilpo Järvinen
2026-11-09 15:06     ` Hans Zhang
2026-11-08  9:40 ` [PATCH v2 2/5] PCI: Convert remaining core pcie_link_speed[] users Hans Zhang
2026-11-08  9:40 ` [PATCH v2 3/5] PCI: tegra264: Use pcie_get_link_speed() Hans Zhang
2026-11-08  9:40 ` [PATCH v2 4/5] PCI: mediatek: " Hans Zhang
2026-11-08  9:40 ` [PATCH v2 5/5] PCI: Make pcie_link_speed[] private to probe.c Hans Zhang

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®