21 #include <sys/ioctl.h> 22 #include <sys/socket.h> 25 #include <sys/types.h> 27 #include <netinet/in.h> 30 #include <linux/if_arp.h> 31 #include <linux/if_tun.h> 50 #define VHOST_USER_DOWN_DISCARD_COUNT 256 56 #define VHOST_USER_RX_BUFFER_STARVATION 32 66 #define VHOST_USER_RX_COPY_THRESHOLD 64 70 #define foreach_vhost_user_input_func_error \ 71 _(NO_ERROR, "no error") \ 72 _(NO_BUFFER, "no available buffer") \ 73 _(MMAP_FAIL, "mmap failure") \ 74 _(INDIRECT_OVERFLOW, "indirect descriptor overflows table") \ 75 _(UNDERSIZED_FRAME, "undersized ethernet frame received (< 14 bytes)") \ 76 _(FULL_RX_QUEUE, "full rx queue (possible driver tx drop)") 80 #define _(f,s) VHOST_USER_INPUT_FUNC_ERROR_##f, 100 vring_desc_t *hdr_desc = 0;
101 virtio_net_hdr_mrg_rxbuf_t *hdr;
108 hdr_desc = &txvq->
desc[desc_current];
119 if (!(txvq->
desc[desc_current].flags & VIRTQ_DESC_F_NEXT) &&
120 !(txvq->
desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT))
127 if (!hdr_desc || !(hdr =
map_guest_mem (vui, hdr_desc->addr, &hint)))
134 memcpy (&t->
hdr, hdr, len > hdr_desc->len ? hdr_desc->len : len);
140 u16 copy_len,
u32 * map_hint)
142 void *src0, *src1, *src2, *src3;
196 u32 discarded_packets = 0;
201 while (discarded_packets != discard_max)
203 if (avail_idx == last_avail_idx)
206 u16 desc_chain_head = txvq->
avail->ring[last_avail_idx & mask];
208 txvq->
used->ring[last_used_idx & mask].id = desc_chain_head;
209 txvq->
used->ring[last_used_idx & mask].len = 0;
221 return discarded_packets;
234 b_current->
flags = 0;
235 while (b_current != b_head)
241 b_current->
flags = 0;
255 u16 n_rx_packets = 0;
258 u32 n_left_to_next, *to_next;
265 u32 current_config_index = ~(
u32) 0;
298 txvq->
used->flags = 0;
334 VHOST_USER_INPUT_FUNC_ERROR_FULL_RX_QUEUE, 1);
367 interface_main.sw_if_counters +
373 VHOST_USER_INPUT_FUNC_ERROR_NO_BUFFER, flush);
413 u32 desc_data_offset;
414 vring_desc_t *desc_table = txvq->
desc;
426 desc_current = txvq->
avail->ring[last_avail_idx & mask];
430 to_next[0] = bi_current;
438 txvq->
used->ring[last_used_idx & mask].id = desc_current;
439 txvq->
used->ring[last_used_idx & mask].len = 0;
444 b_head->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
469 VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
483 desc_data_offset = desc_table[desc_current].len;
489 if (desc_data_offset == desc_table[desc_current].
len)
494 desc_current = desc_table[desc_current].next;
495 desc_data_offset = 0;
529 b_current->
flags |= VLIB_BUFFER_NEXT_PRESENT;
530 bi_current = bi_next;
537 u32 desc_data_l = desc_table[desc_current].
len - desc_data_offset;
539 cpy->
len = (cpy->
len > desc_data_l) ? desc_data_l : cpy->
len;
542 cpy->
src = desc_table[desc_current].addr + desc_data_offset;
544 desc_data_offset += cpy->
len;
568 if (current_config_index != ~(
u32) 0)
571 vnet_buffer (b_head)->feature_arc_index = feature_arc_idx;
584 copy_len, &map_hint)))
587 VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
593 txvq->
used->idx = last_used_idx;
608 VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
630 n_rx_packets, n_rx_bytes);
643 uword n_rx_packets = 0;
651 if ((node->state == VLIB_NODE_STATE_POLLING) ||
667 .name =
"vhost-user-input",
668 .sibling_of =
"device-input",
671 .state = VLIB_NODE_STATE_DISABLED,
vnet_config_main_t config_main
static void vnet_device_increment_rx_packets(u32 thread_index, u64 count)
u32 virtio_ring_flags
The device index.
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
vnet_interface_main_t interface_main
#define CLIB_MEMORY_STORE_BARRIER()
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
#define clib_memcpy_fast(a, b, c)
static f64 vlib_time_now(vlib_main_t *vm)
vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]
u32 * config_index_by_sw_if_index
#define VRING_AVAIL_F_NO_INTERRUPT
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
#define VLIB_NODE_FN(node)
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
vnet_hw_interface_rx_mode
#define static_always_inline
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
#define ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX
vlib_combined_counter_main_t * combined_sw_if_counters
static_always_inline void * map_guest_mem(vhost_user_intf_t *vui, uword addr, u32 *hint)
#define VHOST_VRING_IDX_TX(qid)
#define VRING_USED_F_NO_NOTIFY
#define vlib_get_new_next_frame(vm, node, next_index, vectors, n_vectors_left)
#define VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE
static_always_inline u8 * format_vhost_trace(u8 *s, va_list *va)
static vlib_next_frame_t * vlib_node_runtime_get_next_frame(vlib_main_t *vm, vlib_node_runtime_t *n, u32 next_index)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
#define VIRTQ_DESC_F_INDIRECT
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
vhost_user_main_t vhost_user_main
static vlib_frame_t * vlib_get_frame(vlib_main_t *vm, uword frame_index)
u32 node_index
Node index.
vlib_error_t error
Error code for buffers to be enqueued to error handler.
#define VHOST_VRING_IDX_RX(qid)
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
u16 device_index
The interface queue index (Not the virtio vring idx)
vhost_user_intf_t * vhost_user_interfaces
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
static void * vlib_frame_scalar_args(vlib_frame_t *f)
Get pointer to frame scalar data.
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
u16 first_desc_len
Runtime queue flags.
#define VLIB_BUFFER_DATA_SIZE
u32 rx_buffers[VHOST_USER_RX_BUFFERS_N]
#define VHOST_USER_RX_BUFFERS_N
#define clib_atomic_swap_acq_n(a, b)
#define VIRTQ_DESC_F_NEXT
static_always_inline void vhost_user_send_call(vlib_main_t *vm, vhost_user_vring_t *vq)
u32 next_buffer
Next buffer for this linked-list of buffers.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
u8 device_input_feature_arc_index
Feature arc index for device-input.
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
struct _vlib_node_registration vlib_node_registration_t
vhost_user_vring_t vrings[VHOST_VRING_MAX_N]
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
#define vhost_user_log_dirty_ring(vui, vq, member)
vl_api_gbp_vxlan_tunnel_mode_t mode
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
static void vlib_frame_no_append(vlib_frame_t *f)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
vnet_feature_config_main_t * feature_config_mains
feature config main objects
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
vnet_feature_main_t feature_main
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE