#include <fcntl.h>
#include <sys/ioctl.h>
-#include <linux/virtio_net.h>
-#include <linux/virtio_ring.h>
-#include <linux/vhost.h>
-#include <sys/eventfd.h>
-#if defined(__x86_64__)
-#include <sys/io.h>
-#endif
#include <vppinfra/types.h>
#include <vlib/vlib.h>
#include <vlib/pci/pci.h>
#include <vnet/ethernet/ethernet.h>
-#include <vpp/app/version.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/ip6_packet.h>
#include <vnet/devices/virtio/virtio.h>
virtio_pci_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
- virtio_main_t *vmxm = &virtio_main;
+ virtio_main_t *vim = &virtio_main;
uword pd = vlib_pci_get_private_data (vm, h);
- virtio_if_t *vif = pool_elt_at_index (vmxm->interfaces, pd);
+ virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
u16 qid = line;
vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index, qid);
virtio_pci_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
- virtio_main_t *vmxm = &virtio_main;
+ virtio_main_t *vim = &virtio_main;
uword pd = vlib_pci_get_private_data (vm, h);
- virtio_if_t *vif = pool_elt_at_index (vmxm->interfaces, pd);
+ virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
{
static void
virtio_pci_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h)
{
- virtio_main_t *vmxm = &virtio_main;
+ virtio_main_t *vim = &virtio_main;
uword pd = vlib_pci_get_private_data (vm, h);
- virtio_if_t *vif = pool_elt_at_index (vmxm->interfaces, pd);
+ virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd);
u8 isr = 0;
u16 line = 0;
virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
{
clib_error_t *error = 0;
+ virtio_main_t *vim = &virtio_main;
struct virtio_pci_cap cap;
- u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0;
+ u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
vlib_pci_dev_handle_t h = vif->pci_dev_handle;
if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos)))
if (cap.cap_vndr != PCI_CAP_ID_VNDR)
{
- clib_warning ("[%2x] skipping non VNDR cap id: %2x", pos,
- cap.cap_vndr);
+ virtio_log_debug (vim, vif, "[%2x] %s %2x ", pos,
+ "skipping non VNDR cap id:", cap.cap_vndr);
goto next;
}
case VIRTIO_PCI_CAP_ISR_CFG:
isr = 1;
break;
+ case VIRTIO_PCI_CAP_PCI_CFG:
+ if (cap.bar == 0)
+ pci_cfg = 1;
+ break;
}
next:
pos = cap.cap_next;
if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0)
{
- clib_warning ("no modern virtio pci device found");
+ virtio_log_debug (vim, vif, "legacy virtio pci device found");
return error;
}
- return clib_error_return (error, "modern virtio pci device found");
+ if (!pci_cfg)
+ clib_error_return (error, "modern virtio pci device found");
+
+ virtio_log_debug (vim, vif, "transitional virtio pci device found");
+ return error;
}
static clib_error_t *
clib_error_t *error = 0;
u8 status = 0;
- virtio_pci_read_caps (vm, vif);
+ if ((error = virtio_pci_read_caps (vm, vif)))
+ clib_error_return (error, "Device not supported");
if (virtio_pci_reset_device (vm, vif) < 0)
clib_error_return (error, "Failed to reset the device");
virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
{
vnet_main_t *vnm = vnet_get_main ();
- virtio_main_t *vmxm = &virtio_main;
+ virtio_main_t *vim = &virtio_main;
virtio_if_t *vif;
vlib_pci_dev_handle_t h;
clib_error_t *error = 0;
clib_error_return (error,
"queue size must be <= 4096, >= 64, "
"and multiples of 64");
+ vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
+ format_vlib_pci_addr, &args->addr,
+ "queue size must be <= 4096, >= 64, and multiples of 64");
return;
}
/* *INDENT-OFF* */
- pool_foreach (vif, vmxm->interfaces, ({
+ pool_foreach (vif, vim->interfaces, ({
if (vif->pci_addr.as_u32 == args->addr)
{
args->rv = VNET_API_ERROR_INVALID_VALUE;
args->error =
clib_error_return (error, "PCI address in use");
+ vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
+ format_vlib_pci_addr, &args->addr,
+ " PCI address in use");
return;
}
}));
/* *INDENT-ON* */
- pool_get (vmxm->interfaces, vif);
- vif->dev_instance = vif - vmxm->interfaces;
+ pool_get (vim->interfaces, vif);
+ vif->dev_instance = vif - vim->interfaces;
vif->per_interface_next_index = ~0;
vif->pci_addr.as_u32 = args->addr;
vlib_pci_device_open (vm, (vlib_pci_addr_t *) & vif->pci_addr,
virtio_pci_device_ids, &h)))
{
- pool_put (vmxm->interfaces, vif);
+ pool_put (vim->interfaces, vif);
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error =
clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
&vif->pci_addr);
+ vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
+ format_vlib_pci_addr, &vif->pci_addr,
+ "error encountered on pci device open");
return;
}
vif->pci_dev_handle = h;
vlib_pci_set_private_data (vm, h, vif->dev_instance);
if ((error = vlib_pci_bus_master_enable (vm, h)))
- goto error;
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on pci bus master enable");
+ goto error;
+ }
if ((error = vlib_pci_io_region (vm, h, 0)))
- goto error;
+ {
+ virtio_log_error (vim, vif, "error encountered on pci io region");
+ goto error;
+ }
if ((error = virtio_pci_device_init (vm, vif, args)))
- goto error;
+ {
+ virtio_log_error (vim, vif, "error encountered on device init");
+ goto error;
+ }
if (msix_enabled == VIRTIO_MSIX_ENABLED)
{
if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
&virtio_pci_irq_0_handler)))
- goto error;
-
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on pci register msix handler 0");
+ goto error;
+ }
if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
&virtio_pci_irq_1_handler)))
- goto error;
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on pci register msix handler 1");
+ goto error;
+ }
if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
- goto error;
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on pci enable msix irq");
+ goto error;
+ }
}
else
{
}
if ((error = vlib_pci_intr_enable (vm, h)))
- goto error;
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on pci interrupt enable");
+ goto error;
+ }
vif->type = VIRTIO_IF_TYPE_PCI;
/* create interface */
virtio_pci_flag_change);
if (error)
- goto error;
+ {
+ virtio_log_error (vim, vif,
+ "error encountered on ethernet register interface");
+ goto error;
+ }
vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
vif->sw_if_index = sw->sw_if_index;
vnet_hw_interface_set_input_node (vnm, vif->hw_if_index,
virtio_input_node.index);
vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, 0, ~0);
+ virtio_vring_set_numa_node (vm, vif, 0);
if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
{
virtio_pci_delete_if (vlib_main_t * vm, virtio_if_t * vif)
{
vnet_main_t *vnm = vnet_get_main ();
- virtio_main_t *vmxm = &virtio_main;
+ virtio_main_t *vim = &virtio_main;
u32 i = 0;
if (vif->type != VIRTIO_IF_TYPE_PCI)
vif->tap_fd = -1;
clib_error_free (vif->error);
memset (vif, 0, sizeof (*vif));
- pool_put (vmxm->interfaces, vif);
+ pool_put (vim->interfaces, vif);
return 0;
}