18 #include <sys/types.h> 34 #define foreach_virtio_tx_func_error \ 35 _(NO_FREE_SLOTS, "no free tx slots") \ 36 _(TRUNC_PACKET, "packet > buffer size -- truncated in tx ring") \ 37 _(PENDING_MSGS, "pending msgs in tx ring") \ 38 _(INDIRECT_DESC_ALLOC_FAILED, "indirect descriptor allocation failed - packet drop") \ 39 _(OUT_OF_ORDER, "out-of-order buffers in used ring") \ 40 _(GSO_PACKET_DROP, "gso disabled on itf -- gso packet drop") \ 41 _(CSUM_OFFLOAD_PACKET_DROP, "checksum offload disabled on itf -- csum offload packet drop") 45 #define _(f,s) VIRTIO_TX_ERROR_##f, 60 u32 dev_instance = va_arg (*args,
u32);
61 int verbose = va_arg (*args,
int);
64 s =
format (s,
"VIRTIO interface");
90 s =
format (s,
"%Ubuffer 0x%x: %U",
112 ASSERT (n_buffers <= ring_size);
134 u16 out_of_order_count = 0;
143 slot = n_buffers = e->
id;
145 while (e->
id == (n_buffers & mask))
156 d = &vring->
desc[next];
163 sz, (n_buffers - slot));
165 used -= (n_buffers -
slot);
174 out_of_order_count++;
183 if (out_of_order_count)
194 if (b->
flags & VNET_BUFFER_F_IS_IP4)
202 if (b->
flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
206 else if (b->
flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
217 if (b->
flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
220 else if (b->
flags & VNET_BUFFER_F_IS_IP6)
227 if (b->
flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
231 else if (b->
flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
241 if (b->
flags & VNET_BUFFER_F_IS_IP4)
249 hdr->hdr_len = gho.
hdr_sz;
259 if (b->
flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
262 else if (b->
flags & VNET_BUFFER_F_IS_IP6)
269 hdr->hdr_len = gho.
hdr_sz;
279 u32 bi,
u16 free_desc_count,
281 int csum_offload,
uword node_index)
286 d = &vring->
desc[next];
289 int is_l2 = (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI));
293 if (b->
flags & VNET_BUFFER_F_GSO)
300 VIRTIO_TX_ERROR_GSO_PACKET_DROP);
304 else if (b->
flags & (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
305 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
312 VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP);
336 u32 indirect_buffer = 0;
340 VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED);
346 indirect_desc->
flags |= VLIB_BUFFER_NEXT_PRESENT;
348 bi = indirect_buffer;
353 if (type == VIRTIO_IF_TYPE_PCI)
376 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
394 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
410 else if (type == VIRTIO_IF_TYPE_PCI)
414 u16 n_buffers_in_chain = 1;
421 while (b_temp->
flags & VLIB_BUFFER_NEXT_PRESENT)
423 n_buffers_in_chain++;
427 if (n_buffers_in_chain > free_desc_count)
428 return n_buffers_in_chain;
433 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
438 ~(VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID);
442 count = (count + 1) & mask;
467 u16 req,
u16 next,
u32 * first_free_desc_index,
468 u16 * free_desc_count)
474 if (vring->
buffers[next & mask] == ~0)
476 if (*first_free_desc_index == ~0)
478 *first_free_desc_index = (next &
mask);
480 (*free_desc_count)++;
487 if (start + *free_desc_count ==
i)
489 (*free_desc_count)++;
505 int csum_offload,
int do_gro)
511 u16 used, next, avail;
538 u16 free_desc_count = 0;
542 u32 first_free_desc_index = ~0;
545 &first_free_desc_index, &free_desc_count);
548 next = first_free_desc_index;
551 free_desc_count = sz - used;
553 while (n_left && free_desc_count)
559 if (b0->
flags & VLIB_BUFFER_IS_TRACED)
564 if (type == VIRTIO_IF_TYPE_TUN)
566 int is_ip4 = 0,
is_ip6 = 0;
585 VNET_BUFFER_F_IS_IP4,
587 VNET_BUFFER_F_IS_IP6);
590 sizeof (*b0) -
sizeof (b0->
pre_data));
596 avail, next, mask, do_gso, csum_offload,
609 next = (next + n_added) & mask;
613 free_desc_count -= n_added;
633 VIRTIO_TX_ERROR_NO_FREE_SLOTS);
674 if (vif->type == VIRTIO_IF_TYPE_TAP)
677 else if (vif->type == VIRTIO_IF_TYPE_PCI)
680 else if (vif->type == VIRTIO_IF_TYPE_TUN)
698 if (node_index == ~0)
745 "interface %U is in interrupt mode, disabling packet coalescing",
768 vif->
flags |= VIRTIO_IF_FLAG_ADMIN_UP;
774 vif->
flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
u32 per_interface_next_index
gro_flow_table_t * flow_table
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
static uword vlib_buffer_get_current_pa(vlib_main_t *vm, vlib_buffer_t *b)
VNET_DEVICE_CLASS_TX_FN() virtio_device_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static clib_error_t * virtio_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
vl_api_wireguard_peer_flags_t flags
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
#define VIRTIO_NET_HDR_F_NEEDS_CSUM
vnet_main_t * vnet_get_main(void)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#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)
vring_used_elem_t ring[0]
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u16 current_length
Nbytes between current data and the end of this buffer.
static heap_elt_t * last(heap_header_t *h)
#define STRUCT_OFFSET_OF(t, f)
struct _tcp_header tcp_header_t
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
#define VIRTIO_FEATURE(X)
static_always_inline void set_gso_offsets(vlib_buffer_t *b, virtio_net_hdr_v1_t *hdr, int is_l2)
vnet_hw_interface_rx_mode
#define VRING_AVAIL_F_NO_INTERRUPT
#define static_always_inline
VNET_DEVICE_CLASS(af_xdp_device_class)
static clib_error_t * virtio_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
static_always_inline uword virtio_interface_tx_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, virtio_if_t *vif, virtio_if_type_t type)
vnet_hw_interface_flags_t flags
#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...)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
#define virtio_log_warning(vif, f,...)
#define foreach_virtio_tx_func_error
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
static_always_inline u16 add_buffer_to_slot(vlib_main_t *vm, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, u32 bi, u16 free_desc_count, u16 avail, u16 next, u16 mask, int do_gso, int csum_offload, uword node_index)
vl_api_fib_path_type_t type
#define VRING_USED_F_NO_NOTIFY
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
format_function_t format_vnet_buffer
static_always_inline void virtio_find_free_desc(virtio_vring_t *vring, u16 size, u16 mask, u16 req, u16 next, u32 *first_free_desc_index, u16 *free_desc_count)
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static u8 * format_virtio_tx_trace(u8 *s, va_list *va)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u8 * format_virtio_device(u8 *s, va_list *args)
u32 node_index
Node index.
#define VIRTIO_NET_HDR_GSO_TCPV4
static_always_inline void set_checksum_offsets(vlib_buffer_t *b, virtio_net_hdr_v1_t *hdr, int is_l2)
vl_api_tunnel_mode_t mode
static void virtio_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
static_always_inline void virtio_interface_drop_inline(vlib_main_t *vm, uword node_index, u32 *buffers, u16 n, virtio_tx_func_error_t error)
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
virtio_vring_t * rxq_vrings
format_function_t format_virtio_device_name
sll srl srl sll sra u16x4 i
vlib_main_t vlib_node_runtime_t * node
static_always_inline u32 vnet_gro_inline(vlib_main_t *vm, gro_flow_table_t *flow_table, u32 *from, u16 n_left_from, u32 *to)
coalesce buffers with flow tables
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
static uword pointer_to_uword(const void *p)
#define VRING_DESC_F_NEXT
virtio_main_t virtio_main
static vlib_main_t * vlib_get_main(void)
#define VRING_TX_OUT_OF_ORDER
static_always_inline void vnet_generic_header_offset_parser(vlib_buffer_t *b0, generic_header_offset_t *gho, int is_l2, int is_ip4, int is_ip6)
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
u32 next_buffer
Next buffer for this linked-list of buffers.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
static void virtio_clear_hw_interface_counters(u32 instance)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
#define GRO_TO_VECTOR_SIZE(X)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static_always_inline u8 * format_generic_header_offset(u8 *s, va_list *args)
generic_header_offset_t gho
#define vec_foreach(var, vec)
Vector iterator.
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static_always_inline void virtio_free_used_device_desc(vlib_main_t *vm, virtio_vring_t *vring, uword node_index)
static clib_error_t * virtio_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_interface_rx_mode mode)
static_always_inline void gro_flow_table_set_is_enable(gro_flow_table_t *flow_table, u8 is_enable)
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
static_always_inline void virtio_memset_ring_u32(u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
static_always_inline uword virtio_interface_tx_gso_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, virtio_if_t *vif, virtio_if_type_t type, int do_gso, int csum_offload, int do_gro)
#define VRING_DESC_F_INDIRECT
static char * virtio_tx_func_error_strings[]
#define VIRTIO_NET_HDR_GSO_TCPV6
virtio_vring_t * txq_vrings
static_always_inline void virtio_kick(vlib_main_t *vm, virtio_vring_t *vring, virtio_if_t *vif)
static_always_inline void clib_memset_u32(void *p, u32 val, uword count)