vfio: fix build with Linux < 4.0

Since the older kernel version do not implement the device request
interface for vfio, so when build on the kernel < v4.0.0, which is
the version begin to add the device request interface, it will
throw the error to show “VFIO_PCI_REQ_IRQ_INDEX” is undeclared.
This patch aim to fix this compile issue by add the macro
“HAVE_VFIO_DEV_REQ_INTERFACE” after checking the kernel version.

Fixes: 0eb8a1c4c7 ("vfio: add request notifier interrupt")
Fixes: c115fd000c ("vfio: handle hotplug request notifier")

Signed-off-by: Jeff Guo <jia.guo@intel.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Jeff Guo 2018-10-16 19:42:33 +08:00 committed by Thomas Monjalon
parent c115fd000c
commit cda9441996
4 changed files with 29 additions and 5 deletions

View File

@ -279,6 +279,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
return -1;
}
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
static void
pci_vfio_req_handler(void *param)
{
@ -384,6 +385,7 @@ pci_vfio_disable_notifier(struct rte_pci_device *dev)
return 0;
}
#endif
static int
pci_vfio_is_ioport_bar(int vfio_dev_fd, int bar_index)
@ -625,7 +627,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
struct pci_map *maps;
dev->intr_handle.fd = -1;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
dev->vfio_req_intr_handle.fd = -1;
#endif
/* store PCI address string */
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
@ -736,11 +740,13 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
goto err_vfio_res;
}
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
if (pci_vfio_enable_notifier(dev, vfio_dev_fd) != 0) {
RTE_LOG(ERR, EAL, "Error setting up notifier!\n");
goto err_vfio_res;
}
#endif
TAILQ_INSERT_TAIL(vfio_res_list, vfio_res, next);
return 0;
@ -766,7 +772,9 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
struct pci_map *maps;
dev->intr_handle.fd = -1;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
dev->vfio_req_intr_handle.fd = -1;
#endif
/* store PCI address string */
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
@ -807,7 +815,9 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
/* we need save vfio_dev_fd, so it can be used during release */
dev->intr_handle.vfio_dev_fd = vfio_dev_fd;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
dev->vfio_req_intr_handle.vfio_dev_fd = vfio_dev_fd;
#endif
return 0;
err_vfio_dev_fd:
@ -880,12 +890,14 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
loc->domain, loc->bus, loc->devid, loc->function);
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
ret = pci_vfio_disable_notifier(dev);
if (ret) {
RTE_LOG(ERR, EAL, "fail to disable req notifier.\n");
return -1;
}
#endif
if (close(dev->intr_handle.fd) < 0) {
RTE_LOG(INFO, EAL, "Error when closing eventfd file descriptor for %s\n",
pci_addr);

View File

@ -444,6 +444,7 @@ pci_hot_unplug_handler(struct rte_device *dev)
return -1;
switch (pdev->kdrv) {
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
case RTE_KDRV_VFIO:
/*
* vfio kernel module guaranty the pci device would not be
@ -454,6 +455,7 @@ pci_hot_unplug_handler(struct rte_device *dev)
rte_dev_event_callback_process(dev->name,
RTE_DEV_EVENT_REMOVE);
break;
#endif
case RTE_KDRV_IGB_UIO:
case RTE_KDRV_UIO_GENERIC:
case RTE_KDRV_NIC_UIO:

View File

@ -24,6 +24,9 @@ extern "C" {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
#define VFIO_PRESENT
#endif /* kernel version >= 3.6.0 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
#define HAVE_VFIO_DEV_REQ_INTERFACE
#endif /* kernel version >= 4.0.0 */
#endif /* RTE_EAL_VFIO */
#ifdef VFIO_PRESENT

View File

@ -309,6 +309,7 @@ vfio_disable_msix(const struct rte_intr_handle *intr_handle) {
return ret;
}
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
/* enable req notifier */
static int
vfio_enable_req(const struct rte_intr_handle *intr_handle)
@ -367,6 +368,7 @@ vfio_disable_req(const struct rte_intr_handle *intr_handle)
return ret;
}
#endif
#endif
static int
uio_intx_intr_disable(const struct rte_intr_handle *intr_handle)
@ -614,10 +616,12 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)
if (vfio_enable_intx(intr_handle))
return -1;
break;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
case RTE_INTR_HANDLE_VFIO_REQ:
if (vfio_enable_req(intr_handle))
return -1;
break;
#endif
#endif
/* not used at this moment */
case RTE_INTR_HANDLE_DEV_EVENT:
@ -668,11 +672,12 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)
if (vfio_disable_intx(intr_handle))
return -1;
break;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
case RTE_INTR_HANDLE_VFIO_REQ:
if (vfio_disable_req(intr_handle))
return -1;
break;
#endif
#endif
/* not used at this moment */
case RTE_INTR_HANDLE_DEV_EVENT:
@ -739,6 +744,12 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
case RTE_INTR_HANDLE_VFIO_LEGACY:
bytes_read = sizeof(buf.vfio_intr_count);
break;
#ifdef HAVE_VFIO_DEV_REQ_INTERFACE
case RTE_INTR_HANDLE_VFIO_REQ:
bytes_read = 0;
call = true;
break;
#endif
#endif
case RTE_INTR_HANDLE_VDEV:
case RTE_INTR_HANDLE_EXT:
@ -749,10 +760,6 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
bytes_read = 0;
call = true;
break;
case RTE_INTR_HANDLE_VFIO_REQ:
bytes_read = 0;
call = true;
break;
default:
bytes_read = 1;
break;