[PATCH 1/3] PCI: Add PCIE_SPEED2LNKCTL2_TLS_ENC conversion macro

Hans Zhang posted 3 patches 7 months ago
There is a newer version of this series
[PATCH 1/3] PCI: Add PCIE_SPEED2LNKCTL2_TLS_ENC conversion macro
Posted by Hans Zhang 7 months ago
Introduce PCIE_SPEED2LNKCTL2_TLS_ENC macro to standardize the conversion
between PCIe speed enumerations and LNKCTL2_TLS register values. This
centralizes speed-to-register mapping logic, eliminating duplicated
conversion code across multiple drivers.

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

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index f92928dadc6a..b7e2d08825c6 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -415,6 +415,15 @@ void pci_bus_put(struct pci_bus *bus);
 	 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
 	 PCI_SPEED_UNKNOWN)
 
+#define PCIE_SPEED2LNKCTL2_TLS_ENC(speed) \
+	((speed) == PCIE_SPEED_2_5GT ? PCI_EXP_LNKCTL2_TLS_2_5GT : \
+	 (speed) == PCIE_SPEED_5_0GT ? PCI_EXP_LNKCTL2_TLS_5_0GT : \
+	 (speed) == PCIE_SPEED_8_0GT ? PCI_EXP_LNKCTL2_TLS_8_0GT : \
+	 (speed) == PCIE_SPEED_16_0GT ? PCI_EXP_LNKCTL2_TLS_16_0GT : \
+	 (speed) == PCIE_SPEED_32_0GT ? PCI_EXP_LNKCTL2_TLS_32_0GT : \
+	 (speed) == PCIE_SPEED_64_0GT ? PCI_EXP_LNKCTL2_TLS_64_0GT : \
+	 0)
+
 /* PCIe speed to Mb/s reduced by encoding overhead */
 #define PCIE_SPEED2MBS_ENC(speed) \
 	((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
-- 
2.25.1
Re: [PATCH 1/3] PCI: Add PCIE_SPEED2LNKCTL2_TLS_ENC conversion macro
Posted by Ilpo Järvinen 6 months, 2 weeks ago
On Tue, 20 May 2025, Hans Zhang wrote:

> Introduce PCIE_SPEED2LNKCTL2_TLS_ENC macro to standardize the conversion

Use () parenthesis like you'd use them in C so functions and macros in 
changelog should have them appended.

> between PCIe speed enumerations and LNKCTL2_TLS register values. This
> centralizes speed-to-register mapping logic, eliminating duplicated
> conversion code across multiple drivers.
> 
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
>  drivers/pci/pci.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index f92928dadc6a..b7e2d08825c6 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -415,6 +415,15 @@ void pci_bus_put(struct pci_bus *bus);
>  	 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
>  	 PCI_SPEED_UNKNOWN)
>  
> +#define PCIE_SPEED2LNKCTL2_TLS_ENC(speed) \

I'm not a big fan of including that _ENC there, it just makes the long 
name even longer and doesn't really provide added value, IMO.

Other than those, this change logs fine.

> +	((speed) == PCIE_SPEED_2_5GT ? PCI_EXP_LNKCTL2_TLS_2_5GT : \
> +	 (speed) == PCIE_SPEED_5_0GT ? PCI_EXP_LNKCTL2_TLS_5_0GT : \
> +	 (speed) == PCIE_SPEED_8_0GT ? PCI_EXP_LNKCTL2_TLS_8_0GT : \
> +	 (speed) == PCIE_SPEED_16_0GT ? PCI_EXP_LNKCTL2_TLS_16_0GT : \
> +	 (speed) == PCIE_SPEED_32_0GT ? PCI_EXP_LNKCTL2_TLS_32_0GT : \
> +	 (speed) == PCIE_SPEED_64_0GT ? PCI_EXP_LNKCTL2_TLS_64_0GT : \
> +	 0)
> +
>  /* PCIe speed to Mb/s reduced by encoding overhead */
>  #define PCIE_SPEED2MBS_ENC(speed) \
>  	((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
> 

-- 
 i.
Re: [PATCH 1/3] PCI: Add PCIE_SPEED2LNKCTL2_TLS_ENC conversion macro
Posted by Hans Zhang 6 months, 2 weeks ago

On 2025/6/3 17:08, Ilpo Järvinen wrote:
> On Tue, 20 May 2025, Hans Zhang wrote:
> 
>> Introduce PCIE_SPEED2LNKCTL2_TLS_ENC macro to standardize the conversion
> 
> Use () parenthesis like you'd use them in C so functions and macros in
> changelog should have them appended.
> 

Dear Ilpo,

Thank you very much for your reply and reminder. Will change.

>> between PCIe speed enumerations and LNKCTL2_TLS register values. This
>> centralizes speed-to-register mapping logic, eliminating duplicated
>> conversion code across multiple drivers.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>>   drivers/pci/pci.h | 9 +++++++++
>>   1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>> index f92928dadc6a..b7e2d08825c6 100644
>> --- a/drivers/pci/pci.h
>> +++ b/drivers/pci/pci.h
>> @@ -415,6 +415,15 @@ void pci_bus_put(struct pci_bus *bus);
>>   	 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
>>   	 PCI_SPEED_UNKNOWN)
>>   
>> +#define PCIE_SPEED2LNKCTL2_TLS_ENC(speed) \
> 
> I'm not a big fan of including that _ENC there, it just makes the long
> name even longer and doesn't really provide added value, IMO.
> 

Will delete _ENC.

Best regards,
Hans

> Other than those, this change logs fine.
> 
>> +	((speed) == PCIE_SPEED_2_5GT ? PCI_EXP_LNKCTL2_TLS_2_5GT : \
>> +	 (speed) == PCIE_SPEED_5_0GT ? PCI_EXP_LNKCTL2_TLS_5_0GT : \
>> +	 (speed) == PCIE_SPEED_8_0GT ? PCI_EXP_LNKCTL2_TLS_8_0GT : \
>> +	 (speed) == PCIE_SPEED_16_0GT ? PCI_EXP_LNKCTL2_TLS_16_0GT : \
>> +	 (speed) == PCIE_SPEED_32_0GT ? PCI_EXP_LNKCTL2_TLS_32_0GT : \
>> +	 (speed) == PCIE_SPEED_64_0GT ? PCI_EXP_LNKCTL2_TLS_64_0GT : \
>> +	 0)
>> +
>>   /* PCIe speed to Mb/s reduced by encoding overhead */
>>   #define PCIE_SPEED2MBS_ENC(speed) \
>>   	((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
>>
>