pci: handle 32 bit domain values
v3 cover pci: handle 32 bit domain values
Changes to PCI and EAL to handle full width of PCI domain value. It turns out that PCI domain is only 16 bits in ACPI, but some environments use the extra bits in PCI standard to allow encoding of PCI buses that are outside of ACPI.
This version fixes both Mellanox drivers.
Stephen Hemminger (3):
pci: remove unnecessary casts from strtoul
eal: PCI domain should be 32 bits
mlx4,5: handle 32 bit PCI domain
drivers/net/mlx4/mlx4.c | 2 +- drivers/net/mlx5/mlx5_ethdev.c | 2 +- lib/librte_eal/common/include/rte_pci.h | 12 ++++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.11.0
PATCH v3 1/3 pci: remove unnecessary casts from strtoul
The function strtoul returns unsigned long and can be directly assigned to a smaller type. Removing the casts allows easier expansion of PCI domain.
--- lib/librte_eal/linuxapp/eal/eal_pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/librte_eal/linuxapp/eal/eal_pci.c +4 -4
@@ -430,10 +430,10 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr)/* now convert to int values */ errno =0 ; - addr->domain = (uint16_t )strtoul (splitaddr.domain,NULL ,16 ); - addr->bus = (uint8_t )strtoul (splitaddr.bus,NULL ,16 ); - addr->devid = (uint8_t )strtoul (splitaddr.devid,NULL ,16 ); - addr->function = (uint8_t )strtoul (splitaddr.function,NULL ,10 ); + addr->domain =strtoul (splitaddr.domain,NULL ,16 ); + addr->bus =strtoul (splitaddr.bus,NULL ,16 ); + addr->devid =strtoul (splitaddr.devid,NULL ,16 ); + addr->function =strtoul (splitaddr.function,NULL ,10 );if (errno !=0 ) goto error;
Signature · 1 line
2.11.0
PATCH v3 2/3 eal: PCI domain should be 32 bits
In reply to Stephen HemmingerIn some environments, the PCI domain can be larger than 16 bits. For example, a PCI device passed through in Azure gets a synthetic domain id which is internally generated based on GUID. The PCI standard does not restrict domain to be 16 bits.
This change breaks ABI for API's that expose PCI address structure.
The printf format for PCI remains unchanged, so that on most systems (with only 16 bit domain) the output format is unchanged and is 4 characters wide. For example: 0000:00:01.0 Only on sysetms with higher bits will the domain take up more space; example: 12000:00:01.0
--- lib/librte_eal/common/include/rte_pci.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
lib/librte_eal/common/include/rte_pci.h +6 -6
@@ -63,7 +63,7 @@ const char *pci_get_sysfs_path(void);/** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */ #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 -#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X") +#define PCI_PRI_STR_SIZE sizeof("XXXXXXXX:XX:XX.X")/** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */ #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
@@ -112,7 +112,7 @@ struct rte_pci_id {* A structure describing the location of a PCI device. */ struct rte_pci_addr { -uint16_t domain;/**< Device domain */ +uint32_t domain;/**< Device domain */ uint8_t bus;/**< Device bus */ uint8_t devid;/**< Device ID */ uint8_t function;/**< Device function. */
@@ -346,10 +346,10 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,if ((addr ==NULL ) || (addr2 ==NULL ))return -1 ; - dev_addr = (addr->domain <<24 ) | (addr->bus <<16 ) | - (addr->devid <<8 ) | addr->function; - dev_addr2 = (addr2->domain <<24 ) | (addr2->bus <<16 ) | - (addr2->devid <<8 ) | addr2->function; + dev_addr = ((uint64_t )addr->domain <<24 ) | + (addr->bus <<16 ) | (addr->devid <<8 ) | addr->function; + dev_addr2 = ((uint64_t )addr2->domain <<24 ) | + (addr2->bus <<16 ) | (addr2->devid <<8 ) | addr2->function;if (dev_addr > dev_addr2)return 1 ;
Signature · 1 line
2.11.0
PATCH v3 3/3 mlx4,5: handle 32 bit PCI domain
In reply to Stephen HemmingerThe PCI domain in Azure maybe 32 bits. When device is passed through the domain is synthesize from the internal GUID. The code that parses for PCI address in Mellanox drivers needs to use wider scanf format.
---
v3 - add MLX4
drivers/net/mlx4/mlx4.c | 2 +- drivers/net/mlx5/mlx5_ethdev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx4/mlx4.c +1 -1
@@ -5239,7 +5239,7 @@ mlx4_ibv_device_to_pci_addr(const struct ibv_device *device,/* Extract information. */ if (sscanf(line, "PCI_SLOT_NAME=" - "%" SCNx16 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", + "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", &pci_addr->domain, &pci_addr->bus, &pci_addr->devid,
drivers/net/mlx5/mlx5_ethdev.c +1 -1
@@ -1185,7 +1185,7 @@ mlx5_ibv_device_to_pci_addr(const struct ibv_device *device,/* Extract information. */ if (sscanf(line, "PCI_SLOT_NAME=" - "%" SCNx16 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", + "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", &pci_addr->domain, &pci_addr->bus, &pci_addr->devid,
Signature · 1 line
2.11.0
Thomas Monjalon
Applied05/07/2017 18:55, Stephen Hemminger:
Quoted 11 lines
Changes to PCI and EAL to handle full width of PCI domain value. It turns out that PCI domain is only 16 bits in ACPI, but some environments use the extra bits in PCI standard to allow encoding of PCI buses that are outside of ACPI.
This version fixes both Mellanox drivers.
Stephen Hemminger (3):
pci: remove unnecessary casts from strtoul
eal: PCI domain should be 32 bits
mlx4,5: handle 32 bit PCI domain
Patches 2 and 3 have been squashed to avoid breaking compilation in the middle.
Applied, thanks