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> 39 #define _IOCTL(fd,a,...) \ 40 if (ioctl (fd, a, __VA_ARGS__) < 0) \ 42 err = clib_error_return_unix (0, "ioctl(" #a ")"); \ 70 struct vhost_vring_state state = { 0 };
71 struct vhost_vring_addr addr = { 0 };
72 struct vhost_vring_file file = { 0 };
100 i =
sizeof (
struct vring_desc) * sz;
105 i =
sizeof (
struct vring_avail) + sz *
sizeof (vring->
avail->ring[0]);
112 i =
sizeof (
struct vring_used) + sz *
sizeof (
struct vring_used_elem);
127 vring->
call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
128 vring->
kick_fd = eventfd (0, EFD_CLOEXEC);
139 _IOCTL (vif->
fd, VHOST_SET_VRING_NUM, &state);
146 _IOCTL (vif->
fd, VHOST_SET_VRING_ADDR, &addr);
150 _IOCTL (vif->
fd, VHOST_SET_VRING_KICK, &file);
152 _IOCTL (vif->
fd, VHOST_SET_VRING_CALL, &file);
154 _IOCTL (vif->
fd, VHOST_NET_SET_BACKEND, &file);
211 struct vring_used_elem *e = &vring->
used->ring[last & mask];
259 [thread_index]->numa_node);
275 u32 i, j, hw_if_index;
285 struct feat_struct *feat_entry;
287 static struct feat_struct feat_array[] = {
288 #define _(s,b) { .str = #s, .bit = b, }, 294 struct feat_struct *flag_entry;
295 static struct feat_struct flags_array[] = {
296 #define _(b,e,s) { .bit = b, .str = s, }, 305 for (hw_if_index = 0; hw_if_index <
vec_len (hw_if_indices); hw_if_index++)
310 if (vif->
type != type)
339 flag_entry = (
struct feat_struct *) &flags_array;
340 while (flag_entry->str)
342 if (vif->
flags & (1ULL << flag_entry->bit))
352 feat_entry = (
struct feat_struct *) &feat_array;
353 while (feat_entry->str)
355 if (vif->
features & (1ULL << feat_entry->bit))
361 feat_entry = (
struct feat_struct *) &feat_array;
362 while (feat_entry->str)
379 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
383 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
385 vring->
used->flags, vring->
used->idx);
395 " id addr len flags next user_addr\n");
397 " ===== ================== ===== ====== ===== ==================\n");
398 for (j = 0; j < vring->
size; j++)
400 struct vring_desc *desc = &vring->
desc[j];
402 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
405 desc->flags, desc->next, desc->addr);
414 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
418 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
420 vring->
used->flags, vring->
used->idx);
430 " id addr len flags next user_addr\n");
432 " ===== ================== ===== ====== ===== ==================\n");
433 for (j = 0; j < vring->
size; j++)
435 struct vring_desc *desc = &vring->
desc[j];
437 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
440 desc->flags, desc->next, desc->addr);
450 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
454 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
456 vring->
used->flags, vring->
used->idx);
466 " id addr len flags next user_addr\n");
468 " ===== ================== ===== ====== ===== ==================\n");
469 for (j = 0; j < vring->
size; j++)
471 struct vring_desc *desc = &vring->
desc[j];
473 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
476 desc->flags, desc->next, desc->addr);
#define vec_foreach_index(var, v)
Iterate over vector indices.
format_function_t format_vnet_hw_if_index_name
void virtio_set_net_hdr_size(virtio_if_t *vif)
void virtio_show(vlib_main_t *vm, u32 *hw_if_indices, u8 show_descr, u32 type)
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)
#define foreach_virtio_net_features
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static heap_elt_t * last(heap_header_t *h)
void virtio_vring_set_numa_node(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
vlib_main_t ** vlib_mains
clib_error_t * virtio_vring_free_tx(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
clib_file_function_t * read_function
static void clib_spinlock_free(clib_spinlock_t *p)
struct vring_avail * avail
u8 * format_ethernet_address(u8 *s, va_list *args)
#define TX_QUEUE_ACCESS(X)
void device_status(vlib_main_t *vm, virtio_if_t *vif)
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
void virtio_free_rx_buffers(vlib_main_t *vm, virtio_vring_t *vring)
#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
static void clib_spinlock_init(clib_spinlock_t *p)
vl_api_fib_path_type_t type
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static_always_inline uword vnet_get_device_input_thread_index(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
virtio_vring_t * rxq_vrings
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)
#define VIRTIO_FEATURE(X)
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)
static uword pointer_to_uword(const void *p)
virtio_main_t virtio_main
static uword is_pow2(uword x)
#define RX_QUEUE_ACCESS(X)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * clib_mem_alloc_aligned(uword size, uword align)
virtio_vring_t * cxq_vring
clib_error_t * virtio_vring_free_rx(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
static vlib_thread_main_t * vlib_get_thread_main()
#define CLIB_CACHE_LINE_BYTES
static u8 vlib_buffer_pool_get_default_for_numa(vlib_main_t *vm, u32 numa_node)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
format_function_t format_vlib_pci_addr
virtio_vring_t * txq_vrings
static clib_error_t * call_read_ready(clib_file_t *uf)
static_always_inline void clib_memset_u32(void *p, u32 val, uword count)