aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-10-22 13:38:57 +0200
committerDave Barach <openvpp@barachs.net>2018-10-22 16:10:26 +0000
commit2322798bea16ff4092e2361423af6fd451fd1669 (patch)
treebeec5b680365a31c40bb9ff8ea656e8323aca734
parenta26373bda8aa66cebf03ac092c20fdf4b0a0f625 (diff)
vlib: pci improvements
- logging - pass vlib_main_t to all APIs - open vfio container only when needed Change-Id: I897e53e0af3f91c3a99f0c827401d1c0ec2e478a Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/plugins/avf/device.c31
-rw-r--r--src/plugins/avf/format.c3
-rw-r--r--src/plugins/dpdk/device/init.c5
-rw-r--r--src/plugins/ixge/ixge.c26
-rw-r--r--src/plugins/vmxnet3/format.c3
-rw-r--r--src/plugins/vmxnet3/vmxnet3.c28
-rw-r--r--src/vlib/linux/pci.c192
-rw-r--r--src/vlib/linux/vfio.c59
-rw-r--r--src/vlib/linux/vfio.h5
-rw-r--r--src/vlib/pci/pci.c9
-rw-r--r--src/vlib/pci/pci.h82
11 files changed, 252 insertions, 191 deletions
diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c
index c23746be1b2..e71b74ec8fc 100644
--- a/src/plugins/avf/device.c
+++ b/src/plugins/avf/device.c
@@ -1036,11 +1036,10 @@ VLIB_REGISTER_NODE (avf_process_node, static) = {
/* *INDENT-ON* */
static void
-avf_irq_0_handler (vlib_pci_dev_handle_t h, u16 line)
+avf_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
- vlib_main_t *vm = vlib_get_main ();
avf_main_t *am = &avf_main;
- uword pd = vlib_pci_get_private_data (h);
+ uword pd = vlib_pci_get_private_data (vm, h);
avf_device_t *ad = pool_elt_at_index (am->devices, pd);
u32 icr0;
@@ -1075,12 +1074,11 @@ avf_irq_0_handler (vlib_pci_dev_handle_t h, u16 line)
}
static void
-avf_irq_n_handler (vlib_pci_dev_handle_t h, u16 line)
+avf_irq_n_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
avf_main_t *am = &avf_main;
- uword pd = vlib_pci_get_private_data (h);
+ uword pd = vlib_pci_get_private_data (vm, h);
avf_device_t *ad = pool_elt_at_index (am->devices, pd);
u16 qid;
int i;
@@ -1126,7 +1124,7 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad)
ethernet_delete_interface (vnm, ad->hw_if_index);
}
- vlib_pci_device_close (ad->pci_dev_handle);
+ vlib_pci_device_close (vm, ad->pci_dev_handle);
vlib_physmem_free (vm, am->physmem_region, ad->atq);
vlib_physmem_free (vm, am->physmem_region, ad->arq);
@@ -1197,7 +1195,8 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
if (args->enable_elog)
ad->flags |= AVF_DEVICE_F_ELOG;
- if ((error = vlib_pci_device_open (&args->addr, avf_pci_device_ids, &h)))
+ if ((error = vlib_pci_device_open (vm, &args->addr, avf_pci_device_ids,
+ &h)))
{
pool_put (am->devices, ad);
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
@@ -1208,21 +1207,23 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
}
ad->pci_dev_handle = h;
- vlib_pci_set_private_data (h, ad->dev_instance);
+ vlib_pci_set_private_data (vm, h, ad->dev_instance);
- if ((error = vlib_pci_bus_master_enable (h)))
+ if ((error = vlib_pci_bus_master_enable (vm, h)))
goto error;
- if ((error = vlib_pci_map_region (h, 0, &ad->bar0)))
+ if ((error = vlib_pci_map_region (vm, h, 0, &ad->bar0)))
goto error;
- if ((error = vlib_pci_register_msix_handler (h, 0, 1, &avf_irq_0_handler)))
+ if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
+ &avf_irq_0_handler)))
goto error;
- if ((error = vlib_pci_register_msix_handler (h, 1, 1, &avf_irq_n_handler)))
+ if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
+ &avf_irq_n_handler)))
goto error;
- if ((error = vlib_pci_enable_msix_irq (h, 0, 2)))
+ if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
goto error;
if (am->physmem_region_alloc == 0)
@@ -1258,7 +1259,7 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
if (error)
goto error;
- if ((error = vlib_pci_intr_enable (h)))
+ if ((error = vlib_pci_intr_enable (vm, h)))
goto error;
/* FIXME detect */
diff --git a/src/plugins/avf/format.c b/src/plugins/avf/format.c
index 4eab3198766..3a1e1ff7f44 100644
--- a/src/plugins/avf/format.c
+++ b/src/plugins/avf/format.c
@@ -25,10 +25,11 @@
u8 *
format_avf_device_name (u8 * s, va_list * args)
{
+ vlib_main_t *vm = vlib_get_main ();
u32 i = va_arg (*args, u32);
avf_main_t *am = &avf_main;
avf_device_t *ad = vec_elt_at_index (am->devices, i);
- vlib_pci_addr_t *addr = vlib_pci_get_addr (ad->pci_dev_handle);
+ vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, ad->pci_dev_handle);
s = format (s, "avf-%x/%x/%x/%x",
addr->domain, addr->bus, addr->slot, addr->function);
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 58ba6c003c7..7d9ec7e5c80 100644
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -842,6 +842,7 @@ dpdk_lib_init (dpdk_main_t * dm)
static void
dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
{
+ vlib_main_t *vm = vlib_get_main ();
clib_error_t *error;
u8 *pci_addr = 0;
int num_whitelisted = vec_len (conf->dev_confs);
@@ -860,7 +861,7 @@ dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
vlib_pci_free_device_info (d);
d = 0;
}
- d = vlib_pci_get_device_info (addr, &error);
+ d = vlib_pci_get_device_info (vm, addr, &error);
if (error)
{
clib_error_report (error);
@@ -928,7 +929,7 @@ dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
continue;
}
- error = vlib_pci_bind_to_uio (addr, (char *) conf->uio_driver_name);
+ error = vlib_pci_bind_to_uio (vm, addr, (char *) conf->uio_driver_name);
if (error)
{
diff --git a/src/plugins/ixge/ixge.c b/src/plugins/ixge/ixge.c
index 5cf83cfb670..09394ca4fc0 100644
--- a/src/plugins/ixge/ixge.c
+++ b/src/plugins/ixge/ixge.c
@@ -2245,10 +2245,11 @@ CLIB_MULTIARCH_SELECT_FN (ixge_input)
static u8 *
format_ixge_device_name (u8 * s, va_list * args)
{
+ vlib_main_t *vm = vlib_get_main ();
u32 i = va_arg (*args, u32);
ixge_main_t *xm = &ixge_main;
ixge_device_t *xd = vec_elt_at_index (xm->devices, i);
- vlib_pci_addr_t *addr = vlib_pci_get_addr (xd->pci_dev_handle);
+ vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, xd->pci_dev_handle);
return format (s, "TenGigabitEthernet%x/%x/%x/%x",
addr->domain, addr->bus, addr->slot, addr->function);
}
@@ -2337,6 +2338,7 @@ format_ixge_device (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
CLIB_UNUSED (int verbose) = va_arg (*args, int);
+ vlib_main_t *vm = vlib_get_main ();
ixge_main_t *xm = &ixge_main;
ixge_device_t *xd = vec_elt_at_index (xm->devices, dev_instance);
ixge_phy_t *phy = xd->phys + xd->phy_index;
@@ -2351,8 +2353,8 @@ format_ixge_device (u8 * s, va_list * args)
{
- vlib_pci_addr_t *addr = vlib_pci_get_addr (xd->pci_dev_handle);
- vlib_pci_device_info_t *d = vlib_pci_get_device_info (addr, 0);
+ vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, xd->pci_dev_handle);
+ vlib_pci_device_info_t *d = vlib_pci_get_device_info (vm, addr, 0);
if (d)
s = format (s, "\n%UPCIe %U", format_white_space, indent + 2,
@@ -2822,11 +2824,9 @@ VLIB_INIT_FUNCTION (ixge_init);
static void
-ixge_pci_intr_handler (vlib_pci_dev_handle_t h)
+ixge_pci_intr_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
- ixge_main_t *xm = &ixge_main;
- vlib_main_t *vm = xm->vlib_main;
- uword private_data = vlib_pci_get_private_data (h);
+ uword private_data = vlib_pci_get_private_data (vm, h);
vlib_node_set_interrupt_pending (vm, ixge_input_node.index);
@@ -2845,8 +2845,8 @@ ixge_pci_init (vlib_main_t * vm, vlib_pci_dev_handle_t h)
clib_error_t *error = 0;
void *r;
ixge_device_t *xd;
- vlib_pci_addr_t *addr = vlib_pci_get_addr (h);
- vlib_pci_device_info_t *d = vlib_pci_get_device_info (addr, 0);
+ vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, h);
+ vlib_pci_device_info_t *d = vlib_pci_get_device_info (vm, addr, 0);
/* Allocate physmem region for DMA buffers */
if (xm->physmem_region_allocated == 0)
@@ -2859,7 +2859,7 @@ ixge_pci_init (vlib_main_t * vm, vlib_pci_dev_handle_t h)
if (error)
return error;
- error = vlib_pci_map_region (h, 0, &r);
+ error = vlib_pci_map_region (vm, h, 0, &r);
if (error)
return error;
@@ -2877,7 +2877,7 @@ ixge_pci_init (vlib_main_t * vm, vlib_pci_dev_handle_t h)
xd->pci_function = addr->function;
xd->per_interface_next_index = ~0;
- vlib_pci_set_private_data (h, xd->device_index);
+ vlib_pci_set_private_data (vm, h, xd->device_index);
/* Chip found so enable node. */
{
@@ -2895,12 +2895,12 @@ ixge_pci_init (vlib_main_t * vm, vlib_pci_dev_handle_t h)
xm->process_node_index = ixge_process_node.index;
}
- error = vlib_pci_bus_master_enable (h);
+ error = vlib_pci_bus_master_enable (vm, h);
if (error)
return error;
- return vlib_pci_intr_enable (h);
+ return vlib_pci_intr_enable (vm, h);
}
/* *INDENT-OFF* */
diff --git a/src/plugins/vmxnet3/format.c b/src/plugins/vmxnet3/format.c
index 56904652a79..c1a74367436 100644
--- a/src/plugins/vmxnet3/format.c
+++ b/src/plugins/vmxnet3/format.c
@@ -25,10 +25,11 @@
u8 *
format_vmxnet3_device_name (u8 * s, va_list * args)
{
+ vlib_main_t *vm = vlib_get_main ();
u32 i = va_arg (*args, u32);
vmxnet3_main_t *vmxm = &vmxnet3_main;
vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, i);
- vlib_pci_addr_t *addr = vlib_pci_get_addr (vd->pci_dev_handle);
+ vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, vd->pci_dev_handle);
s = format (s, "vmxnet3-%x/%x/%x/%x",
addr->domain, addr->bus, addr->slot, addr->function);
diff --git a/src/plugins/vmxnet3/vmxnet3.c b/src/plugins/vmxnet3/vmxnet3.c
index ac99411a4e2..375224142f9 100644
--- a/src/plugins/vmxnet3/vmxnet3.c
+++ b/src/plugins/vmxnet3/vmxnet3.c
@@ -428,11 +428,11 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
}
static void
-vmxnet3_irq_0_handler (vlib_pci_dev_handle_t h, u16 line)
+vmxnet3_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
vmxnet3_main_t *vmxm = &vmxnet3_main;
- uword pd = vlib_pci_get_private_data (h);
+ uword pd = vlib_pci_get_private_data (vm, h);
vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
u16 qid = line;
@@ -441,11 +441,11 @@ vmxnet3_irq_0_handler (vlib_pci_dev_handle_t h, u16 line)
}
static void
-vmxnet3_irq_1_handler (vlib_pci_dev_handle_t h, u16 line)
+vmxnet3_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
vmxnet3_main_t *vmxm = &vmxnet3_main;
- uword pd = vlib_pci_get_private_data (h);
+ uword pd = vlib_pci_get_private_data (vm, h);
vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
u32 ret;
@@ -521,7 +521,7 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
vd->flags |= VMXNET3_DEVICE_F_ELOG;
if ((error =
- vlib_pci_device_open (&args->addr, vmxnet3_pci_device_ids, &h)))
+ vlib_pci_device_open (vm, &args->addr, vmxnet3_pci_device_ids, &h)))
{
pool_put (vmxm->devices, vd);
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
@@ -532,29 +532,29 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
}
vd->pci_dev_handle = h;
- vlib_pci_set_private_data (h, vd->dev_instance);
+ vlib_pci_set_private_data (vm, h, vd->dev_instance);
- if ((error = vlib_pci_bus_master_enable (h)))
+ if ((error = vlib_pci_bus_master_enable (vm, h)))
goto error;
- if ((error = vlib_pci_map_region (h, 0, (void **) &vd->bar[0])))
+ if ((error = vlib_pci_map_region (vm, h, 0, (void **) &vd->bar[0])))
goto error;
- if ((error = vlib_pci_map_region (h, 1, (void **) &vd->bar[1])))
+ if ((error = vlib_pci_map_region (vm, h, 1, (void **) &vd->bar[1])))
goto error;
- if ((error = vlib_pci_register_msix_handler (h, 0, 1,
+ if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
&vmxnet3_irq_0_handler)))
goto error;
- if ((error = vlib_pci_register_msix_handler (h, 1, 1,
+ if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
&vmxnet3_irq_1_handler)))
goto error;
- if ((error = vlib_pci_enable_msix_irq (h, 0, 2)))
+ if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
goto error;
- if ((error = vlib_pci_intr_enable (h)))
+ if ((error = vlib_pci_intr_enable (vm, h)))
goto error;
if ((error = vmxnet3_device_init (vm, vd, args)))
@@ -611,7 +611,7 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
ethernet_delete_interface (vnm, vd->hw_if_index);
}
- vlib_pci_device_close (vd->pci_dev_handle);
+ vlib_pci_device_close (vm, vd->pci_dev_handle);
/* *INDENT-OFF* */
vec_foreach_index (i, vd->rxqs)
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index 7cadb1378ec..69fca9e6098 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -60,6 +60,13 @@ static const char *sysfs_pci_drv_path = "/sys/bus/pci/drivers";
static char *sysfs_mod_vfio_noiommu =
"/sys/module/vfio/parameters/enable_unsafe_noiommu_mode";
+#define pci_log_debug(vm, dev, f, ...) \
+ vlib_log(VLIB_LOG_LEVEL_DEBUG, pci_main.log_default, "%U: " f, \
+ format_vlib_pci_addr, vlib_pci_get_addr(vm, dev->handle), ## __VA_ARGS__)
+#define pci_log_err(vm, dev, f, ...) \
+ vlib_log(VLIB_LOG_LEVEL_ERR, pci_main.log_default, "%U: " f, \
+ format_vlib_pci_addr, vlib_pci_get_addr(vm, dev->handle), ## __VA_ARGS__)
+
typedef struct
{
int fd;
@@ -111,6 +118,8 @@ typedef struct
/* private data */
uword private_data;
+ u8 supports_va_dma;
+
} linux_pci_device_t;
/* Pool of PCI devices. */
@@ -131,21 +140,22 @@ linux_pci_get_device (vlib_pci_dev_handle_t h)
}
uword
-vlib_pci_get_private_data (vlib_pci_dev_handle_t h)
+vlib_pci_get_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
linux_pci_device_t *d = linux_pci_get_device (h);
return d->private_data;
}
void
-vlib_pci_set_private_data (vlib_pci_dev_handle_t h, uword private_data)
+vlib_pci_set_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ uword private_data)
{
linux_pci_device_t *d = linux_pci_get_device (h);
d->private_data = private_data;
}
vlib_pci_addr_t *
-vlib_pci_get_addr (vlib_pci_dev_handle_t h)
+vlib_pci_get_addr (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
linux_pci_device_t *d = linux_pci_get_device (h);
return &d->addr;
@@ -159,7 +169,8 @@ clib_error_t *pci_bus_init (vlib_main_t * vm);
linux_pci_main_t linux_pci_main;
vlib_pci_device_info_t *
-vlib_pci_get_device_info (vlib_pci_addr_t * addr, clib_error_t ** error)
+vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
+ clib_error_t ** error)
{
linux_vfio_main_t *lvm = &vfio_main;
clib_error_t *err;
@@ -342,7 +353,8 @@ directory_exists (char *path)
}
clib_error_t *
-vlib_pci_bind_to_uio (vlib_pci_addr_t * addr, char *uio_drv_name)
+vlib_pci_bind_to_uio (vlib_main_t * vm, vlib_pci_addr_t * addr,
+ char *uio_drv_name)
{
clib_error_t *error = 0;
u8 *s = 0, *driver_name = 0;
@@ -353,7 +365,7 @@ vlib_pci_bind_to_uio (vlib_pci_addr_t * addr, char *uio_drv_name)
u8 *dev_dir_name = format (0, "%s/%U", sysfs_pci_dev_path,
format_vlib_pci_addr, addr);
- di = vlib_pci_get_device_info (addr, &error);
+ di = vlib_pci_get_device_info (vm, addr, &error);
if (error)
return error;
@@ -536,23 +548,31 @@ scan_uio_dir (void *arg, u8 * path_name, u8 * file_name)
}
static clib_error_t *
-vfio_set_irqs (linux_pci_device_t * p, u32 index, u32 start, u32 count,
- u32 flags, int *efds)
+vfio_set_irqs (vlib_main_t * vm, linux_pci_device_t * p, u32 index, u32 start,
+ u32 count, u32 flags, int *efds)
{
int data_len = efds ? count * sizeof (int) : 0;
u8 buf[sizeof (struct vfio_irq_set) + data_len];
- struct vfio_irq_info irq_info = { 0 };
+ struct vfio_irq_info ii = { 0 };
struct vfio_irq_set *irq_set = (struct vfio_irq_set *) buf;
- irq_info.argsz = sizeof (struct vfio_irq_info);
- irq_info.index = index;
+ ii.argsz = sizeof (struct vfio_irq_info);
+ ii.index = index;
- if (ioctl (p->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info) < 0)
+ if (ioctl (p->fd, VFIO_DEVICE_GET_IRQ_INFO, &ii) < 0)
return clib_error_return_unix (0, "ioctl(VFIO_DEVICE_GET_IRQ_INFO) "
"'%U'", format_vlib_pci_addr, &p->addr);
- if (irq_info.count < start + count)
+ pci_log_debug (vm, p, "%s index:%u count:%u flags: %s%s%s%s(0x%x)",
+ __func__, ii.index, ii.count,
+ ii.flags & VFIO_IRQ_INFO_EVENTFD ? "eventfd " : "",
+ ii.flags & VFIO_IRQ_INFO_MASKABLE ? "maskable " : "",
+ ii.flags & VFIO_IRQ_INFO_AUTOMASKED ? "automasked " : "",
+ ii.flags & VFIO_IRQ_INFO_NORESIZE ? "noresize " : "",
+ ii.flags);
+
+ if (ii.count < start + count)
return clib_error_return_unix (0, "vfio_set_irq: unexistng interrupt on "
"'%U'", format_vlib_pci_addr, &p->addr);
@@ -586,6 +606,7 @@ vfio_set_irqs (linux_pci_device_t * p, u32 index, u32 start, u32 count,
static clib_error_t *
linux_pci_uio_read_ready (clib_file_t * uf)
{
+ vlib_main_t *vm = vlib_get_main ();
int __attribute__ ((unused)) rv;
vlib_pci_dev_handle_t h = uf->private_data;
linux_pci_device_t *p = linux_pci_get_device (h);
@@ -595,17 +616,17 @@ linux_pci_uio_read_ready (clib_file_t * uf)
rv = read (uf->file_descriptor, &icount, 4);
if (irq->intx_handler)
- irq->intx_handler (h);
+ irq->intx_handler (vm, h);
- vlib_pci_intr_enable (h);
+ vlib_pci_intr_enable (vm, h);
return /* no error */ 0;
}
static clib_error_t *
-linux_pci_vfio_unmask_intx (linux_pci_device_t * d)
+linux_pci_vfio_unmask_intx (vlib_main_t * vm, linux_pci_device_t * d)
{
- return vfio_set_irqs (d, VFIO_PCI_INTX_IRQ_INDEX, 0, 1,
+ return vfio_set_irqs (vm, d, VFIO_PCI_INTX_IRQ_INDEX, 0, 1,
VFIO_IRQ_SET_ACTION_UNMASK, 0);
}
@@ -620,6 +641,7 @@ linux_pci_uio_error_ready (clib_file_t * uf)
static clib_error_t *
linux_pci_vfio_msix_read_ready (clib_file_t * uf)
{
+ vlib_main_t *vm = vlib_get_main ();
int __attribute__ ((unused)) rv;
vlib_pci_dev_handle_t h = uf->private_data >> 16;
u16 line = uf->private_data & 0xffff;
@@ -630,7 +652,7 @@ linux_pci_vfio_msix_read_ready (clib_file_t * uf)
rv = read (uf->file_descriptor, &icount, sizeof (icount));
if (irq->msix_handler)
- irq->msix_handler (h, line);
+ irq->msix_handler (vm, h, line);
return /* no error */ 0;
}
@@ -638,6 +660,7 @@ linux_pci_vfio_msix_read_ready (clib_file_t * uf)
static clib_error_t *
linux_pci_vfio_intx_read_ready (clib_file_t * uf)
{
+ vlib_main_t *vm = vlib_get_main ();
int __attribute__ ((unused)) rv;
vlib_pci_dev_handle_t h = uf->private_data;
linux_pci_device_t *p = linux_pci_get_device (h);
@@ -647,9 +670,9 @@ linux_pci_vfio_intx_read_ready (clib_file_t * uf)
rv = read (uf->file_descriptor, &icount, sizeof (icount));
if (irq->intx_handler)
- irq->intx_handler (h);
+ irq->intx_handler (vm, h);
- linux_pci_vfio_unmask_intx (p);
+ linux_pci_vfio_unmask_intx (vm, p);
return /* no error */ 0;
}
@@ -663,14 +686,13 @@ linux_pci_vfio_error_ready (clib_file_t * uf)
}
static clib_error_t *
-add_device_uio (linux_pci_device_t * p, vlib_pci_device_info_t * di,
- pci_device_registration_t * r)
+add_device_uio (vlib_main_t * vm, linux_pci_device_t * p,
+ vlib_pci_device_info_t * di, pci_device_registration_t * r)
{
linux_pci_main_t *lpm = &linux_pci_main;
clib_error_t *err = 0;
u8 *s = 0;
- p->addr.as_u32 = di->addr.as_u32;
p->fd = -1;
p->type = LINUX_PCI_DEVICE_TYPE_UIO;
@@ -702,7 +724,7 @@ add_device_uio (linux_pci_device_t * p, vlib_pci_device_info_t * di,
}
if (r && r->interrupt_handler)
- vlib_pci_register_intx_handler (p->handle, r->interrupt_handler);
+ vlib_pci_register_intx_handler (vm, p->handle, r->interrupt_handler);
if (r && r->init_function)
err = r->init_function (lpm->vlib_main, p->handle);
@@ -720,7 +742,7 @@ error:
}
clib_error_t *
-vlib_pci_register_intx_handler (vlib_pci_dev_handle_t h,
+vlib_pci_register_intx_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h,
pci_intx_handler_function_t * intx_handler)
{
linux_pci_device_t *p = linux_pci_get_device (h);
@@ -730,19 +752,27 @@ vlib_pci_register_intx_handler (vlib_pci_dev_handle_t h,
if (p->type == LINUX_PCI_DEVICE_TYPE_VFIO)
{
- struct vfio_irq_info irq_info = { 0 };
- irq_info.argsz = sizeof (struct vfio_irq_info);
- irq_info.index = VFIO_PCI_INTX_IRQ_INDEX;
- if (ioctl (p->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info) < 0)
+ struct vfio_irq_info ii = { 0 };
+ ii.argsz = sizeof (struct vfio_irq_info);
+ ii.index = VFIO_PCI_INTX_IRQ_INDEX;
+ if (ioctl (p->fd, VFIO_DEVICE_GET_IRQ_INFO, &ii) < 0)
return clib_error_return_unix (0, "ioctl(VFIO_DEVICE_GET_IRQ_INFO) '"
"%U'", format_vlib_pci_addr, &p->addr);
- if (irq_info.count != 1)
+ pci_log_debug (vm, p, "%s index:%u count:%u flags: %s%s%s%s(0x%x)",
+ __func__, ii.index, ii.count,
+ ii.flags & VFIO_IRQ_INFO_EVENTFD ? "eventfd " : "",
+ ii.flags & VFIO_IRQ_INFO_MASKABLE ? "maskable " : "",
+ ii.flags & VFIO_IRQ_INFO_AUTOMASKED ? "automasked " : "",
+ ii.flags & VFIO_IRQ_INFO_NORESIZE ? "noresize " : "",
+ ii.flags);
+ if (ii.count != 1)
return clib_error_return (0, "INTx interrupt does not exist on device"
"'%U'", format_vlib_pci_addr, &p->addr);
irq->fd = eventfd (0, EFD_NONBLOCK);
if (irq->fd == -1)
return clib_error_return_unix (0, "eventfd");
+
t.file_descriptor = irq->fd;
t.read_function = linux_pci_vfio_intx_read_ready;
}
@@ -763,7 +793,8 @@ vlib_pci_register_intx_handler (vlib_pci_dev_handle_t h,
}
clib_error_t *
-vlib_pci_register_msix_handler (vlib_pci_dev_handle_t h, u32 start, u32 count,
+vlib_pci_register_msix_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ u32 start, u32 count,
pci_msix_handler_function_t * msix_handler)
{
clib_error_t *err = 0;
@@ -819,7 +850,8 @@ error:
}
clib_error_t *
-vlib_pci_enable_msix_irq (vlib_pci_dev_handle_t h, u16 start, u16 count)
+vlib_pci_enable_msix_irq (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ u16 start, u16 count)
{
linux_pci_device_t *p = linux_pci_get_device (h);
int fds[count];
@@ -835,12 +867,13 @@ vlib_pci_enable_msix_irq (vlib_pci_dev_handle_t h, u16 start, u16 count)
fds[i] = irq->fd;
}
- return vfio_set_irqs (p, VFIO_PCI_MSIX_IRQ_INDEX, start, count,
+ return vfio_set_irqs (vm, p, VFIO_PCI_MSIX_IRQ_INDEX, start, count,
VFIO_IRQ_SET_ACTION_TRIGGER, fds);
}
clib_error_t *
-vlib_pci_disable_msix_irq (vlib_pci_dev_handle_t h, u16 start, u16 count)
+vlib_pci_disable_msix_irq (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ u16 start, u16 count)
{
linux_pci_device_t *p = linux_pci_get_device (h);
int i, fds[count];
@@ -852,32 +885,29 @@ vlib_pci_disable_msix_irq (vlib_pci_dev_handle_t h, u16 start, u16 count)
for (i = start; i < start + count; i++)
fds[i] = -1;
- return vfio_set_irqs (p, VFIO_PCI_MSIX_IRQ_INDEX, start, count,
+ return vfio_set_irqs (vm, p, VFIO_PCI_MSIX_IRQ_INDEX, start, count,
VFIO_IRQ_SET_ACTION_TRIGGER, fds);
}
static clib_error_t *
-add_device_vfio (linux_pci_device_t * p, vlib_pci_device_info_t * di,
- pci_device_registration_t * r)
+add_device_vfio (vlib_main_t * vm, linux_pci_device_t * p,
+ vlib_pci_device_info_t * di, pci_device_registration_t * r)
{
linux_pci_main_t *lpm = &linux_pci_main;
struct vfio_device_info device_info = { 0 };
struct vfio_region_info reg = { 0 };
clib_error_t *err = 0;
u8 *s = 0;
+ int is_noiommu;
- p->addr.as_u32 = di->addr.as_u32;
p->type = LINUX_PCI_DEVICE_TYPE_VFIO;
- if (di->driver_name == 0 ||
- (strcmp ("vfio-pci", (char *) di->driver_name) != 0))
- return clib_error_return (0, "Device '%U' (iommu group %d) not bound to "
- "vfio-pci", format_vlib_pci_addr, &di->addr,
- di->iommu_group);
-
- if ((err = linux_vfio_group_get_device_fd (&p->addr, &p->fd)))
+ if ((err = linux_vfio_group_get_device_fd (&p->addr, &p->fd, &is_noiommu)))
return err;
+ if (is_noiommu == 0)
+ p->supports_va_dma = 1;
+
device_info.argsz = sizeof (device_info);
if (ioctl (p->fd, VFIO_DEVICE_GET_INFO, &device_info) < 0)
{
@@ -894,6 +924,15 @@ add_device_vfio (linux_pci_device_t * p, vlib_pci_device_info_t * di,
format_vlib_pci_addr, &di->addr);
goto error;
}
+
+ pci_log_debug (vm, p, "%s region_info index:%u size:0x%lx offset:0x%lx "
+ "flags: %s%s%s(0x%x)", __func__,
+ reg.index, reg.size, reg.offset,
+ reg.flags & VFIO_REGION_INFO_FLAG_READ ? "rd " : "",
+ reg.flags & VFIO_REGION_INFO_FLAG_WRITE ? "wr " : "",
+ reg.flags & VFIO_REGION_INFO_FLAG_MMAP ? "mmap " : "",
+ reg.flags);
+
p->config_offset = reg.offset;
p->config_fd = p->fd;
@@ -908,8 +947,8 @@ add_device_vfio (linux_pci_device_t * p, vlib_pci_device_info_t * di,
if (r && r->interrupt_handler)
{
- vlib_pci_register_intx_handler (p->handle, r->interrupt_handler);
- linux_pci_vfio_unmask_intx (p);
+ vlib_pci_register_intx_handler (vm, p->handle, r->interrupt_handler);
+ linux_pci_vfio_unmask_intx (vm, p);
}
if (r && r->init_function)
@@ -930,7 +969,7 @@ error:
/* Configuration space read/write. */
clib_error_t *
-vlib_pci_read_write_config (vlib_pci_dev_handle_t h,
+vlib_pci_read_write_config (vlib_main_t * vm, vlib_pci_dev_handle_t h,
vlib_read_or_write_t read_or_write,
uword address, void *data, u32 n_bytes)
{
@@ -951,7 +990,7 @@ vlib_pci_read_write_config (vlib_pci_dev_handle_t h,
}
static clib_error_t *
-vlib_pci_map_region_int (vlib_pci_dev_handle_t h,
+vlib_pci_map_region_int (vlib_main_t * vm, vlib_pci_dev_handle_t h,
u32 bar, u8 * addr, void **result)
{
linux_pci_device_t *p = linux_pci_get_device (h);
@@ -964,6 +1003,8 @@ vlib_pci_map_region_int (vlib_pci_dev_handle_t h,
error = 0;
+ pci_log_debug (vm, p, "map region %u to va %p", bar, addr);
+
if (p->type == LINUX_PCI_DEVICE_TYPE_UIO)
{
u8 *file_name;
@@ -1005,6 +1046,13 @@ vlib_pci_map_region_int (vlib_pci_dev_handle_t h,
fd = p->fd;
size = reg.size;
offset = reg.offset;
+ pci_log_debug (vm, p, "%s region_info index:%u size:0x%lx offset:0x%lx "
+ "flags: %s%s%s(0x%x)", __func__,
+ reg.index, reg.size, reg.offset,
+ reg.flags & VFIO_REGION_INFO_FLAG_READ ? "rd " : "",
+ reg.flags & VFIO_REGION_INFO_FLAG_WRITE ? "wr " : "",
+ reg.flags & VFIO_REGION_INFO_FLAG_MMAP ? "mmap " : "",
+ reg.flags);
}
else
ASSERT (0);
@@ -1030,20 +1078,21 @@ vlib_pci_map_region_int (vlib_pci_dev_handle_t h,
}
clib_error_t *
-vlib_pci_map_region (vlib_pci_dev_handle_t h, u32 resource, void **result)
+vlib_pci_map_region (vlib_main_t * vm, vlib_pci_dev_handle_t h, u32 resource,
+ void **result)
{
- return (vlib_pci_map_region_int (h, resource, 0 /* addr */ , result));
+ return (vlib_pci_map_region_int (vm, h, resource, 0 /* addr */ , result));
}
clib_error_t *
-vlib_pci_map_region_fixed (vlib_pci_dev_handle_t h, u32 resource, u8 * addr,
- void **result)
+vlib_pci_map_region_fixed (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ u32 resource, u8 * addr, void **result)
{
- return (vlib_pci_map_region_int (h, resource, addr, result));
+ return (vlib_pci_map_region_int (vm, h, resource, addr, result));
}
clib_error_t *
-vlib_pci_device_open (vlib_pci_addr_t * addr,
+vlib_pci_device_open (vlib_main_t * vm, vlib_pci_addr_t * addr,
pci_device_id_t ids[], vlib_pci_dev_handle_t * handle)
{
linux_pci_main_t *lpm = &linux_pci_main;
@@ -1052,7 +1101,7 @@ vlib_pci_device_open (vlib_pci_addr_t * addr,
clib_error_t *err = 0;
pci_device_id_t *i;
- di = vlib_pci_get_device_info (addr, &err);
+ di = vlib_pci_get_device_info (vm, addr, &err);
if (err)
return err;
@@ -1065,12 +1114,20 @@ vlib_pci_device_open (vlib_pci_addr_t * addr,
pool_get (lpm->linux_pci_devices, p);
p->handle = p - lpm->linux_pci_devices;
+ p->addr.as_u32 = di->addr.as_u32;
p->intx_irq.fd = -1;
- if (di->iommu_group != -1)
- err = add_device_vfio (p, di, 0);
+ pci_log_debug (vm, p, "open vid:0x%04x did:0x%04x driver:%s iommu_group:%d",
+ di->vendor_id, di->device_id, di->driver_name,
+ di->iommu_group);
+
+ if (strncmp ("vfio-pci", (char *) di->driver_name, 8) == 0)
+ err = add_device_vfio (vm, p, di, 0);
+ else if (strncmp ("uio_pci_generic", (char *) di->driver_name, 8) == 0)
+ err = add_device_uio (vm, p, di, 0);
else
- err = add_device_uio (p, di, 0);
+ err = clib_error_create ("device not bound to 'vfio-pci' or "
+ "'uio_pci_generic' kernel module");
if (err)
goto error;
@@ -1080,6 +1137,7 @@ error:
vlib_pci_free_device_info (di);
if (err)
{
+ pci_log_err (vm, p, "%U", format_clib_error, err);
memset (p, 0, sizeof (linux_pci_device_t));
pool_put (lpm->linux_pci_devices, p);
}
@@ -1088,7 +1146,7 @@ error:
}
void
-vlib_pci_device_close (vlib_pci_dev_handle_t h)
+vlib_pci_device_close (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
linux_pci_main_t *lpm = &linux_pci_main;
linux_pci_device_t *p = linux_pci_get_device (h);
@@ -1108,7 +1166,7 @@ vlib_pci_device_close (vlib_pci_dev_handle_t h)
/* close INTx irqs */
if (irq->fd != -1)
{
- err = vfio_set_irqs (p, VFIO_PCI_INTX_IRQ_INDEX, 0, 0,
+ err = vfio_set_irqs (vm, p, VFIO_PCI_INTX_IRQ_INDEX, 0, 0,
VFIO_IRQ_SET_ACTION_TRIGGER, 0);
clib_error_free (err);
clib_file_del_by_index (&file_main, irq->clib_file_index);
@@ -1118,7 +1176,7 @@ vlib_pci_device_close (vlib_pci_dev_handle_t h)
/* close MSI-X irqs */
if (vec_len (p->msix_irqs))
{
- err = vfio_set_irqs (p, VFIO_PCI_MSIX_IRQ_INDEX, 0, 0,
+ err = vfio_set_irqs (vm, p, VFIO_PCI_MSIX_IRQ_INDEX, 0, 0,
VFIO_IRQ_SET_ACTION_TRIGGER, 0);
clib_error_free (err);
/* *INDENT-OFF* */
@@ -1152,7 +1210,7 @@ vlib_pci_device_close (vlib_pci_dev_handle_t h)
}
void
-init_device_from_registered (vlib_pci_device_info_t * di)
+init_device_from_registered (vlib_main_t * vm, vlib_pci_device_info_t * di)
{
vlib_pci_main_t *pm = &pci_main;
linux_pci_main_t *lpm = &linux_pci_main;
@@ -1173,9 +1231,9 @@ init_device_from_registered (vlib_pci_device_info_t * di)
if (i->vendor_id == di->vendor_id && i->device_id == di->device_id)
{
if (di->iommu_group != -1)
- err = add_device_vfio (p, di, r);
+ err = add_device_vfio (vm, p, di, r);
else
- err = add_device_uio (p, di, r);
+ err = add_device_uio (vm, p, di, r);
if (err)
clib_error_report (err);
@@ -1275,9 +1333,9 @@ linux_pci_init (vlib_main_t * vm)
vec_foreach (addr, addrs)
{
vlib_pci_device_info_t *d;
- if ((d = vlib_pci_get_device_info (addr, 0)))
+ if ((d = vlib_pci_get_device_info (vm, addr, 0)))
{
- init_device_from_registered (d);
+ init_device_from_registered (vm, d);
vlib_pci_free_device_info (d);
}
}
diff --git a/src/vlib/linux/vfio.c b/src/vlib/linux/vfio.c
index ffc990a61d2..e72f10388ca 100644
--- a/src/vlib/linux/vfio.c
+++ b/src/vlib/linux/vfio.c
@@ -103,6 +103,21 @@ open_vfio_iommu_group (int group, int is_noiommu)
u8 *s = 0;
int fd;
+ if (lvm->container_fd == -1)
+ {
+ if ((fd = open ("/dev/vfio/vfio", O_RDWR)) == -1)
+ return clib_error_return_unix (0, "failed to open VFIO container");
+
+ if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
+ {
+ close (fd);
+ return clib_error_return_unix (0, "incompatible VFIO version");
+ }
+
+ lvm->iommu_pool_index_by_group = hash_create (0, sizeof (uword));
+ lvm->container_fd = fd;
+ }
+
g = get_vfio_iommu_group (group);
if (g)
{
@@ -165,7 +180,8 @@ error:
}
clib_error_t *
-linux_vfio_group_get_device_fd (vlib_pci_addr_t * addr, int *fdp)
+linux_vfio_group_get_device_fd (vlib_pci_addr_t * addr, int *fdp,
+ int *is_noiommu)
{
clib_error_t *err = 0;
linux_pci_vfio_iommu_group_t *g;
@@ -173,8 +189,8 @@ linux_vfio_group_get_device_fd (vlib_pci_addr_t * addr, int *fdp)
int iommu_group;
u8 *tmpstr;
int fd;
- int is_noiommu = 0;
+ *is_noiommu = 0;
s = format (s, "/sys/bus/pci/devices/%U/iommu_group", format_vlib_pci_addr,
addr);
tmpstr = clib_sysfs_link_to_name ((char *) s);
@@ -191,20 +207,20 @@ linux_vfio_group_get_device_fd (vlib_pci_addr_t * addr, int *fdp)
}
vec_reset_length (s);
- s =
- format (s, "/sys/bus/pci/devices/%U/iommu_group/name",
- format_vlib_pci_addr, addr);
+ s = format (s, "/sys/bus/pci/devices/%U/iommu_group/name",
+ format_vlib_pci_addr, addr);
err = clib_sysfs_read ((char *) s, "%s", &tmpstr);
if (err == 0)
{
if (strncmp ((char *) tmpstr, "vfio-noiommu", 12) == 0)
- is_noiommu = 1;
+ *is_noiommu = 1;
+
vec_free (tmpstr);
}
else
clib_error_free (err);
vec_reset_length (s);
- if ((err = open_vfio_iommu_group (iommu_group, is_noiommu)))
+ if ((err = open_vfio_iommu_group (iommu_group, *is_noiommu)))
return err;
g = get_vfio_iommu_group (iommu_group);
@@ -229,37 +245,10 @@ clib_error_t *
linux_vfio_init (vlib_main_t * vm)
{
linux_vfio_main_t *lvm = &vfio_main;
- int fd;
lvm->log_default = vlib_log_register_class ("vfio", 0);
+ lvm->container_fd = -1;
- fd = open ("/dev/vfio/vfio", O_RDWR);
-
- /* check if iommu is available */
- if (fd != -1)
- {
- if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
- {
- close (fd);
- fd = -1;
- }
- else
- {
- if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 1)
- {
- lvm->flags |= LINUX_VFIO_F_HAVE_IOMMU;
- vlib_log_info (lvm->log_default, "type 1 IOMMU mode supported");
- }
- if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_NOIOMMU_IOMMU) == 1)
- {
- lvm->flags |= LINUX_VFIO_F_HAVE_NOIOMMU;
- vlib_log_info (lvm->log_default, "NOIOMMU mode supported");
- }
- }
- }
-
- lvm->iommu_pool_index_by_group = hash_create (0, sizeof (uword));
- lvm->container_fd = fd;
return 0;
}
diff --git a/src/vlib/linux/vfio.h b/src/vlib/linux/vfio.h
index 7fe3ef8dc0e..aae8e3c6ee7 100644
--- a/src/vlib/linux/vfio.h
+++ b/src/vlib/linux/vfio.h
@@ -25,9 +25,6 @@ typedef struct
typedef struct
{
- u32 flags;
-#define LINUX_VFIO_F_HAVE_IOMMU (1 << 0)
-#define LINUX_VFIO_F_HAVE_NOIOMMU (1 << 1)
int container_fd;
/* VFIO */
@@ -48,7 +45,7 @@ extern linux_vfio_main_t vfio_main;
clib_error_t *linux_vfio_init (vlib_main_t * vm);
void linux_vfio_dma_map_regions (vlib_main_t * vm);
clib_error_t *linux_vfio_group_get_device_fd (vlib_pci_addr_t * addr,
- int *fd);
+ int *fd, int *is_noiommu);
#endif /* included_vlib_linux_vfio_h */
diff --git a/src/vlib/pci/pci.c b/src/vlib/pci/pci.c
index f50ae2d9edf..4cd31004586 100644
--- a/src/vlib/pci/pci.c
+++ b/src/vlib/pci/pci.c
@@ -53,7 +53,8 @@
vlib_pci_main_t pci_main;
vlib_pci_device_info_t * __attribute__ ((weak))
-vlib_pci_get_device_info (vlib_pci_addr_t * addr, clib_error_t ** error)
+vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
+ clib_error_t ** error)
{
if (error)
*error = clib_error_return (0, "unsupported");
@@ -91,7 +92,7 @@ show_pci_fn (vlib_main_t * vm,
vec_foreach (addr, addrs)
{
vlib_pci_device_info_t *d;
- d = vlib_pci_get_device_info (addr, 0);
+ d = vlib_pci_get_device_info (vm, addr, 0);
if (!d)
continue;
@@ -250,7 +251,9 @@ VLIB_CLI_COMMAND (show_pci_command, static) = {
clib_error_t *
pci_bus_init (vlib_main_t * vm)
{
- return vlib_call_init_function (vm, pci_bus_init);
+ vlib_pci_main_t *pm = &pci_main;
+ pm->log_default = vlib_log_register_class ("pci", 0);
+ return 0;
}
VLIB_INIT_FUNCTION (pci_bus_init);
diff --git a/src/vlib/pci/pci.h b/src/vlib/pci/pci.h
index a705671d875..3d5cd405c89 100644
--- a/src/vlib/pci/pci.h
+++ b/src/vlib/pci/pci.h
@@ -96,12 +96,15 @@ typedef struct vlib_pci_device_info
typedef u32 vlib_pci_dev_handle_t;
-vlib_pci_device_info_t *vlib_pci_get_device_info (vlib_pci_addr_t * addr,
+vlib_pci_device_info_t *vlib_pci_get_device_info (vlib_main_t * vm,
+ vlib_pci_addr_t * addr,
clib_error_t ** error);
vlib_pci_addr_t *vlib_pci_get_all_dev_addrs ();
-vlib_pci_addr_t *vlib_pci_get_addr (vlib_pci_dev_handle_t h);
-uword vlib_pci_get_private_data (vlib_pci_dev_handle_t h);
-void vlib_pci_set_private_data (vlib_pci_dev_handle_t h, uword private_data);
+vlib_pci_addr_t *vlib_pci_get_addr (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h);
+uword vlib_pci_get_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h);
+void vlib_pci_set_private_data (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ uword private_data);
static inline void
vlib_pci_free_device_info (vlib_pci_device_info_t * di)
@@ -120,8 +123,10 @@ typedef struct
u16 vendor_id, device_id;
} pci_device_id_t;
-typedef void (pci_intx_handler_function_t) (vlib_pci_dev_handle_t handle);
-typedef void (pci_msix_handler_function_t) (vlib_pci_dev_handle_t handle,
+typedef void (pci_intx_handler_function_t) (vlib_main_t * vm,
+ vlib_pci_dev_handle_t handle);
+typedef void (pci_msix_handler_function_t) (vlib_main_t * vm,
+ vlib_pci_dev_handle_t handle,
u16 line);
typedef struct _pci_device_registration
@@ -145,6 +150,8 @@ typedef struct
{
vlib_main_t *vlib_main;
pci_device_registration_t *pci_device_registrations;
+ /* logging */
+ vlib_log_class_t log_default;
} vlib_pci_main_t;
extern vlib_pci_main_t pci_main;
@@ -169,21 +176,22 @@ static void __vlib_rm_pci_device_registration_##x (void) \
} \
__VA_ARGS__ pci_device_registration_t x
-clib_error_t *vlib_pci_bind_to_uio (vlib_pci_addr_t * addr,
+clib_error_t *vlib_pci_bind_to_uio (vlib_main_t * vm, vlib_pci_addr_t * addr,
char *uio_driver_name);
/* Configuration space read/write. */
-clib_error_t *vlib_pci_read_write_config (vlib_pci_dev_handle_t handle,
+clib_error_t *vlib_pci_read_write_config (vlib_main_t * vm,
+ vlib_pci_dev_handle_t handle,
vlib_read_or_write_t read_or_write,
- uword address,
- void *data, u32 n_bytes);
+ uword address, void *data,
+ u32 n_bytes);
#define _(t) \
static inline clib_error_t * \
-vlib_pci_read_config_##t (vlib_pci_dev_handle_t h, \
+vlib_pci_read_config_##t (vlib_main_t *vm, vlib_pci_dev_handle_t h, \
uword address, t * data) \
{ \
- return vlib_pci_read_write_config (h, VLIB_READ,address, data, \
+ return vlib_pci_read_write_config (vm, h, VLIB_READ,address, data, \
sizeof (data[0])); \
}
@@ -195,10 +203,10 @@ _(u8);
#define _(t) \
static inline clib_error_t * \
-vlib_pci_write_config_##t (vlib_pci_dev_handle_t h, uword address, \
- t * data) \
+vlib_pci_write_config_##t (vlib_main_t *vm, vlib_pci_dev_handle_t h, \
+ uword address, t * data) \
{ \
- return vlib_pci_read_write_config (h, VLIB_WRITE, \
+ return vlib_pci_read_write_config (vm, h, VLIB_WRITE, \
address, data, sizeof (data[0])); \
}
@@ -209,45 +217,45 @@ _(u8);
#undef _
static inline clib_error_t *
-vlib_pci_intr_enable (vlib_pci_dev_handle_t h)
+vlib_pci_intr_enable (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
u16 command;
clib_error_t *err;
- err = vlib_pci_read_config_u16 (h, 4, &command);
+ err = vlib_pci_read_config_u16 (vm, h, 4, &command);
if (err)
return err;
command &= ~PCI_COMMAND_INTX_DISABLE;
- return vlib_pci_write_config_u16 (h, 4, &command);
+ return vlib_pci_write_config_u16 (vm, h, 4, &command);
}
static inline clib_error_t *
-vlib_pci_intr_disable (vlib_pci_dev_handle_t h)
+vlib_pci_intr_disable (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
u16 command;
clib_error_t *err;
- err = vlib_pci_read_config_u16 (h, 4, &command);
+ err = vlib_pci_read_config_u16 (vm, h, 4, &command);
if (err)
return err;
command |= PCI_COMMAND_INTX_DISABLE;
- return vlib_pci_write_config_u16 (h, 4, &command);
+ return vlib_pci_write_config_u16 (vm, h, 4, &command);
}
static inline clib_error_t *
-vlib_pci_bus_master_enable (vlib_pci_dev_handle_t h)
+vlib_pci_bus_master_enable (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
clib_error_t *err;
u16 command;
/* Set bus master enable (BME) */
- err = vlib_pci_read_config_u16 (h, 4, &command);
+ err = vlib_pci_read_config_u16 (vm, h, 4, &command);
if (err)
return err;
@@ -257,31 +265,33 @@ vlib_pci_bus_master_enable (vlib_pci_dev_handle_t h)
command |= PCI_COMMAND_BUS_MASTER;
- return vlib_pci_write_config_u16 (h, 4, &command);
+ return vlib_pci_write_config_u16 (vm, h, 4, &command);
}
-clib_error_t *vlib_pci_device_open (vlib_pci_addr_t * addr,
+clib_error_t *vlib_pci_device_open (vlib_main_t * vm, vlib_pci_addr_t * addr,
pci_device_id_t ids[],
vlib_pci_dev_handle_t * handle);
-void vlib_pci_device_close (vlib_pci_dev_handle_t h);
-
-clib_error_t *vlib_pci_map_region (vlib_pci_dev_handle_t h, u32 resource,
- void **result);
-
-clib_error_t *vlib_pci_map_region_fixed (vlib_pci_dev_handle_t h,
+void vlib_pci_device_close (vlib_main_t * vm, vlib_pci_dev_handle_t h);
+clib_error_t *vlib_pci_map_region (vlib_main_t * vm, vlib_pci_dev_handle_t h,
+ u32 resource, void **result);
+clib_error_t *vlib_pci_map_region_fixed (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h,
u32 resource, u8 * addr,
void **result);
-
-clib_error_t *vlib_pci_register_intx_handler (vlib_pci_dev_handle_t h,
+clib_error_t *vlib_pci_register_intx_handler (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h,
pci_intx_handler_function_t *
intx_handler);
-clib_error_t *vlib_pci_register_msix_handler (vlib_pci_dev_handle_t h,
+clib_error_t *vlib_pci_register_msix_handler (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h,
u32 start, u32 count,
pci_msix_handler_function_t *
msix_handler);
-clib_error_t *vlib_pci_enable_msix_irq (vlib_pci_dev_handle_t h, u16 start,
+clib_error_t *vlib_pci_enable_msix_irq (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h, u16 start,
u16 count);
-clib_error_t *vlib_pci_disable_msix_irq (vlib_pci_dev_handle_t h, u16 start,
+clib_error_t *vlib_pci_disable_msix_irq (vlib_main_t * vm,
+ vlib_pci_dev_handle_t h, u16 start,
u16 count);
unformat_function_t unformat_vlib_pci_addr;