18 #include <sys/types.h> 22 #include <linux/if_tun.h> 23 #include <sys/ioctl.h> 24 #include <linux/virtio_net.h> 25 #include <linux/vhost.h> 26 #include <sys/eventfd.h> 37 #define _IOCTL(fd,a,...) \ 38 if (ioctl (fd, a, __VA_ARGS__) < 0) \ 40 err = clib_error_return_unix (0, "ioctl(" #a ")"); \ 67 struct vhost_vring_state state = { 0 };
68 struct vhost_vring_addr addr = { 0 };
69 struct vhost_vring_file file = { 0 };
85 i =
sizeof (
struct vring_desc) * sz;
90 i =
sizeof (
struct vring_avail) + sz *
sizeof (vring->
avail->ring[0]);
97 i =
sizeof (
struct vring_used) + sz *
sizeof (
struct vring_used_elem);
106 vring->
call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
107 vring->
kick_fd = eventfd (0, EFD_CLOEXEC);
118 _IOCTL (vif->
fd, VHOST_SET_VRING_NUM, &state);
125 _IOCTL (vif->
fd, VHOST_SET_VRING_ADDR, &addr);
129 _IOCTL (vif->
fd, VHOST_SET_VRING_KICK, &file);
131 _IOCTL (vif->
fd, VHOST_SET_VRING_CALL, &file);
133 _IOCTL (vif->
fd, VHOST_NET_SET_BACKEND, &file);
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
vnet_main_t * vnet_get_main(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static heap_elt_t * last(heap_header_t *h)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
static_always_inline void virtio_free_rx_buffers(vlib_main_t *vm, virtio_vring_t *vring)
clib_file_function_t * read_function
struct vring_avail * avail
#define static_always_inline
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
clib_file_main_t file_main
format_function_t format_virtio_device_name
#define VIRTIO_RING_FLAG_MASK_INT
#define vec_free(V)
Free vector's memory (no header).
static uword round_pow2(uword x, uword pow2)
void virtio_free_used_desc(vlib_main_t *vm, virtio_vring_t *vring)
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
static void clib_file_del_by_index(clib_file_main_t *um, uword index)
clib_error_t * virtio_vring_init(vlib_main_t *vm, virtio_if_t *vif, u16 idx, u16 sz)
static void clib_mem_free(void *p)
clib_error_t * virtio_vring_free(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
static uword pointer_to_uword(const void *p)
virtio_main_t virtio_main
static uword is_pow2(uword x)
static void * clib_mem_alloc_aligned(uword size, uword align)
#define CLIB_CACHE_LINE_BYTES
static clib_error_t * call_read_ready(clib_file_t *uf)