diff mbox series

[v2,6/6] nfp: Use pci_get_dsn()

Message ID 20200303022506.1792776-7-jacob.e.keller@intel.com
State New
Headers show
Series PCI: Implement function to read Device Serial Number | expand

Commit Message

Jacob Keller March 3, 2020, 2:25 a.m. UTC
Use the newly added pci_get_dsn() function for obtaining the 64-bit
Device Serial Number in the nfp6000_read_serial and
nfp_6000_get_interface functions.

pci_get_dsn() reports the Device Serial number as a u64 value created by
combining two pci_read_config_dword functions. The lower 16 bits
represent the device interface value, and the next 48 bits represent the
serial value. Use put_unaligned_be32 and put_unaligned_be16 to convert
the serial value portion into a Big Endian formatted serial u8 array.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jakub Kicinski <kuba@kernel.org>
---
 .../netronome/nfp/nfpcore/nfp6000_pcie.c      | 24 +++++++------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Comments

Jakub Kicinski March 3, 2020, 3:40 a.m. UTC | #1
On Mon,  2 Mar 2020 18:25:05 -0800 Jacob Keller wrote:
> Use the newly added pci_get_dsn() function for obtaining the 64-bit
> Device Serial Number in the nfp6000_read_serial and
> nfp_6000_get_interface functions.
> 
> pci_get_dsn() reports the Device Serial number as a u64 value created by
> combining two pci_read_config_dword functions. The lower 16 bits
> represent the device interface value, and the next 48 bits represent the
> serial value. Use put_unaligned_be32 and put_unaligned_be16 to convert
> the serial value portion into a Big Endian formatted serial u8 array.
> 
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

Thanks!

> -	pci_read_config_dword(pdev, pos + 4, &reg);
> -	put_unaligned_be16(reg >> 16, serial + 4);
> -	pci_read_config_dword(pdev, pos + 8, &reg);
> -	put_unaligned_be32(reg, serial);
> +	put_unaligned_be32((u32)(dsn >> 32), serial);
> +	put_unaligned_be16((u16)(dsn >> 16), serial + 4);

nit: the casts and extra brackets should be unnecessary, in case
     you're respinning..
Jacob Keller March 3, 2020, 5:36 p.m. UTC | #2
On 3/2/2020 7:40 PM, Jakub Kicinski wrote:
> On Mon,  2 Mar 2020 18:25:05 -0800 Jacob Keller wrote:
>> Use the newly added pci_get_dsn() function for obtaining the 64-bit
>> Device Serial Number in the nfp6000_read_serial and
>> nfp_6000_get_interface functions.
>>
>> pci_get_dsn() reports the Device Serial number as a u64 value created by
>> combining two pci_read_config_dword functions. The lower 16 bits
>> represent the device interface value, and the next 48 bits represent the
>> serial value. Use put_unaligned_be32 and put_unaligned_be16 to convert
>> the serial value portion into a Big Endian formatted serial u8 array.
>>
>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
>> Cc: Jakub Kicinski <kuba@kernel.org>
> 
> Reviewed-by: Jakub Kicinski <kuba@kernel.org>
> 
> Thanks!
> 
>> -	pci_read_config_dword(pdev, pos + 4, &reg);
>> -	put_unaligned_be16(reg >> 16, serial + 4);
>> -	pci_read_config_dword(pdev, pos + 8, &reg);
>> -	put_unaligned_be32(reg, serial);
>> +	put_unaligned_be32((u32)(dsn >> 32), serial);
>> +	put_unaligned_be16((u16)(dsn >> 16), serial + 4);
> 
> nit: the casts and extra brackets should be unnecessary, in case
>      you're respinning..
> 

Ah, yea because the argument will get converted properly by the
function. It's a bit of a habit since we use one of the -W warnings that
warns about implicit conversions that use truncation. I can remove them
if I need to respin.

It looks like this got picked up by one of the kbuild bots but got
applied without the main PCI patch that implemented pci_get_dsn.

Thanks,
Jake
diff mbox series

Patch

diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
index b454db283aef..8fde6c1f681b 100644
--- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
@@ -1247,19 +1247,16 @@  static void nfp6000_free(struct nfp_cpp *cpp)
 static int nfp6000_read_serial(struct device *dev, u8 *serial)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	int pos;
-	u32 reg;
+	u64 dsn;
 
-	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
-	if (!pos) {
+	dsn = pci_get_dsn(pdev);
+	if (!dsn) {
 		dev_err(dev, "can't find PCIe Serial Number Capability\n");
 		return -EINVAL;
 	}
 
-	pci_read_config_dword(pdev, pos + 4, &reg);
-	put_unaligned_be16(reg >> 16, serial + 4);
-	pci_read_config_dword(pdev, pos + 8, &reg);
-	put_unaligned_be32(reg, serial);
+	put_unaligned_be32((u32)(dsn >> 32), serial);
+	put_unaligned_be16((u16)(dsn >> 16), serial + 4);
 
 	return 0;
 }
@@ -1267,18 +1264,15 @@  static int nfp6000_read_serial(struct device *dev, u8 *serial)
 static int nfp6000_get_interface(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	int pos;
-	u32 reg;
+	u64 dsn;
 
-	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
-	if (!pos) {
+	dsn = pci_get_dsn(pdev);
+	if (!dsn) {
 		dev_err(dev, "can't find PCIe Serial Number Capability\n");
 		return -EINVAL;
 	}
 
-	pci_read_config_dword(pdev, pos + 4, &reg);
-
-	return reg & 0xffff;
+	return dsn & 0xffff;
 }
 
 static const struct nfp_cpp_operations nfp6000_pcie_ops = {