bus/pci: fill bus specific information

For diagnostic, it may be useful to provide the PCI vendor and device
id.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
David Marchand 2022-07-28 17:26:39 +02:00
parent 5b569f2ea8
commit 8f4de2dba9
6 changed files with 75 additions and 23 deletions

View File

@ -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;
}

View File

@ -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 */
};

View File

@ -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;
}

View File

@ -44,6 +44,38 @@ const char *rte_pci_get_sysfs_path(void)
return path;
}
#ifdef RTE_EXEC_ENV_WINDOWS
#define asprintf pci_asprintf
static int
__rte_format_printf(2, 3)
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 +91,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 +112,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 +649,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;
}

View File

@ -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.

View File

@ -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;
}