Currently, if `rte_vfio_get_device_info` is called with fd == 0, the device
will be automatically set up. This seems like a counter-intuitive function,
and the only purpose for it seems to be code golf, and the only user for it
only calls rte_vfio_get_device_info when fd is in fact zero, meaning they
could've just called device setup instead of calling device info.
Decouple device info function from device setup, change its API, and adjust
all usages of this API.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
drivers/bus/pci/linux/pci_vfio.c | 4 ++--
lib/eal/freebsd/eal.c | 9 +++++++++
lib/eal/include/rte_vfio.h | 9 +--------
lib/eal/linux/eal_vfio.c | 23 ++++++-----------------
4 files changed, 18 insertions(+), 27 deletions(-)
@@ -1194,8 +1194,8 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,
if (vfio_dev_fd < 0) {
return -1;
} else if (vfio_dev_fd == 0) {
- if (rte_vfio_get_device_info(rte_pci_get_sysfs_path(), pci_addr,
- &vfio_dev_fd, &device_info) != 0)
+ if (rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
+ &vfio_dev_fd, &device_info) != 0)
return -1;
/* save vfio_dev_fd so it can be used during release */
if (rte_intr_dev_fd_set(dev->intr_handle, vfio_dev_fd) != 0)
@@ -947,3 +947,12 @@ rte_vfio_container_assign_device(__rte_unused int vfio_container_fd,
rte_errno = ENOTSUP;
return -1;
}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_vfio_get_device_info, 26.02)
+int
+rte_vfio_get_device_info(__rte_unused int vfio_dev_fd,
+ __rte_unused struct vfio_device_info *device_info)
+{
+ rte_errno = ENOTSUP;
+ return -1;
+}
@@ -170,12 +170,6 @@ rte_vfio_get_group_num(const char *sysfs_base,
*
* This function is only relevant to Linux and will return an error on BSD.
*
- * @param sysfs_base
- * sysfs path prefix.
- *
- * @param dev_addr
- * device location.
- *
* @param vfio_dev_fd
* VFIO fd.
*
@@ -188,8 +182,7 @@ rte_vfio_get_group_num(const char *sysfs_base,
*/
__rte_experimental
int
-rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info);
+rte_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info);
/**
* Open a new VFIO container fd
@@ -1243,28 +1243,17 @@ vfio_set_iommu_type(int vfio_container_fd)
return NULL;
}
-RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_vfio_get_device_info, 24.03)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_vfio_get_device_info, 26.02)
int
-rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info)
+rte_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info)
{
int ret;
- if (device_info == NULL || *vfio_dev_fd < 0)
+ ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
+ if (ret) {
+ EAL_LOG(ERR, "Cannot get device info, error %i (%s)",
+ errno, strerror(errno));
return -1;
-
- if (*vfio_dev_fd == 0) {
- ret = rte_vfio_setup_device(sysfs_base, dev_addr,
- vfio_dev_fd, device_info);
- if (ret)
- return -1;
- } else {
- ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
- if (ret) {
- EAL_LOG(ERR, "%s cannot get device info, error %i (%s)",
- dev_addr, errno, strerror(errno));
- return -1;
- }
}
return 0;