For diagnostic, it may be useful to provide the PCI vendor and device id. Signed-off-by: David Marchand <david.march...@redhat.com> Acked-by: Bruce Richardson <bruce.richard...@intel.com> --- Changes since v4: - fixed Windows build issue (missing asprintf implementation),
--- drivers/bus/pci/bsd/pci.c | 8 +++--- drivers/bus/pci/bus_pci_driver.h | 1 + drivers/bus/pci/linux/pci.c | 24 ++++++++-------- drivers/bus/pci/pci_common.c | 48 ++++++++++++++++++++++++++++++-- drivers/bus/pci/private.h | 10 +++++-- drivers/bus/pci/windows/pci.c | 6 ++-- 6 files changed, 74 insertions(+), 23 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index bc560a2a56..844d145fed 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -248,7 +248,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) /* FreeBSD has no NUMA support (yet) */ dev->device.numa_node = 0; - pci_name_set(dev); + pci_common_set(dev); /* FreeBSD has only one pass through driver */ dev->kdrv = RTE_PCI_KDRV_NIC_UIO; @@ -299,11 +299,11 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) } else { /* already registered */ dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; - pci_name_set(dev2); + pci_common_set(dev2); memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); - free(dev); + pci_free(dev); } return 0; } @@ -313,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) return 0; skipdev: - free(dev); + pci_free(dev); return 0; } diff --git a/drivers/bus/pci/bus_pci_driver.h b/drivers/bus/pci/bus_pci_driver.h index 0f2f9b5101..be32263a82 100644 --- a/drivers/bus/pci/bus_pci_driver.h +++ b/drivers/bus/pci/bus_pci_driver.h @@ -43,6 +43,7 @@ struct rte_pci_device { uint16_t max_vfs; /**< sriov enable if not zero */ enum rte_pci_kernel_driver kdrv; /**< Kernel driver passthrough */ char name[PCI_PRI_STR_SIZE+1]; /**< PCI location (ASCII) */ + char *bus_info; /**< PCI bus specific info */ struct rte_intr_handle *vfio_req_intr_handle; /**< Handler of VFIO request interrupt */ }; diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index fa5d5e131d..c8703d52f3 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -226,7 +226,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) /* get vendor id */ snprintf(filename, sizeof(filename), "%s/vendor", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.vendor_id = (uint16_t)tmp; @@ -234,7 +234,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) /* get device id */ snprintf(filename, sizeof(filename), "%s/device", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.device_id = (uint16_t)tmp; @@ -243,7 +243,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/subsystem_vendor", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.subsystem_vendor_id = (uint16_t)tmp; @@ -252,7 +252,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/subsystem_device", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.subsystem_device_id = (uint16_t)tmp; @@ -261,7 +261,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/class", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } /* the least 24 bits are valid: class, subclass, program interface */ @@ -295,13 +295,13 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev->device.numa_node = 0; } - pci_name_set(dev); + pci_common_set(dev); /* parse resources */ snprintf(filename, sizeof(filename), "%s/resource", dirname); if (pci_parse_sysfs_resource(filename, dev) < 0) { RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__); - free(dev); + pci_free(dev); return -1; } @@ -310,7 +310,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) ret = pci_get_kernel_driver_by_path(filename, driver, sizeof(driver)); if (ret < 0) { RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); - free(dev); + pci_free(dev); return -1; } @@ -324,7 +324,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) else dev->kdrv = RTE_PCI_KDRV_UNKNOWN; } else { - free(dev); + pci_free(dev); return 0; } /* device is valid, add in list (sorted) */ @@ -346,7 +346,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; dev2->id = dev->id; - pci_name_set(dev2); + pci_common_set(dev2); memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); @@ -376,10 +376,10 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) else if (dev2->device.devargs != dev->device.devargs) { rte_devargs_remove(dev2->device.devargs); - pci_name_set(dev2); + pci_common_set(dev2); } } - free(dev); + pci_free(dev); } return 0; } diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index c26aacd364..bb6275ee7f 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -44,6 +44,37 @@ const char *rte_pci_get_sysfs_path(void) return path; } +#ifdef RTE_EXEC_ENV_WINDOWS +#define asprintf pci_asprintf + +static int +pci_asprintf(char **buffer, const char *format, ...) +{ + int size, ret; + va_list arg; + + va_start(arg, format); + size = vsnprintf(NULL, 0, format, arg); + va_end(arg); + if (size < 0) + return -1; + size++; + + *buffer = malloc(size); + if (*buffer == NULL) + return -1; + + va_start(arg, format); + ret = vsnprintf(*buffer, size, format, arg); + va_end(arg); + if (ret != size - 1) { + free(*buffer); + return -1; + } + return ret; +} +#endif /* RTE_EXEC_ENV_WINDOWS */ + static struct rte_devargs * pci_devargs_lookup(const struct rte_pci_addr *pci_addr) { @@ -59,7 +90,7 @@ pci_devargs_lookup(const struct rte_pci_addr *pci_addr) } void -pci_name_set(struct rte_pci_device *dev) +pci_common_set(struct rte_pci_device *dev) { struct rte_devargs *devargs; @@ -80,6 +111,19 @@ pci_name_set(struct rte_pci_device *dev) else /* Otherwise, it uses the internal, canonical form. */ dev->device.name = dev->name; + + if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, + dev->id.vendor_id, dev->id.device_id) != -1) + dev->device.bus_info = dev->bus_info; +} + +void +pci_free(struct rte_pci_device *dev) +{ + if (dev == NULL) + return; + free(dev->bus_info); + free(dev); } /* map a particular resource from a file */ @@ -604,7 +648,7 @@ pci_unplug(struct rte_device *dev) if (ret == 0) { rte_pci_remove_device(pdev); rte_devargs_remove(dev->devargs); - free(pdev); + pci_free(pdev); } return ret; } diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index fddf49251d..c8161a1074 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -44,10 +44,16 @@ struct rte_pci_device; int rte_pci_scan(void); /** - * Find the name of a PCI device. + * Set common internal information for a PCI device. */ void -pci_name_set(struct rte_pci_device *dev); +pci_common_set(struct rte_pci_device *dev); + +/** + * Free a PCI device. + */ +void +pci_free(struct rte_pci_device *dev); /** * Validate whether a device with given PCI address should be ignored or not. diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c index f013b743b3..3f7a8b9432 100644 --- a/drivers/bus/pci/windows/pci.c +++ b/drivers/bus/pci/windows/pci.c @@ -382,7 +382,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) dev->id = pci_id; dev->max_vfs = 0; /* TODO: get max_vfs */ - pci_name_set(dev); + pci_common_set(dev); set_kernel_driver_type(device_info_data, dev); @@ -410,7 +410,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) dev2->max_vfs = dev->max_vfs; memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); - free(dev); + pci_free(dev); } return 0; } @@ -419,7 +419,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) return 0; end: - free(dev); + pci_free(dev); return ret; } -- 2.37.2