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");
89 s =
format (s,
"%Ubuffer 0x%x: %U\n",
112 int is_ip4 = 0,
is_ip6 = 0;
130 VNET_BUFFER_F_IS_IP4,
131 b0->
flags & VNET_BUFFER_F_IS_IP6);
150 ASSERT (n_buffers <= ring_size);
172 u16 out_of_order_count = 0;
181 slot = n_buffers = e->
id;
183 while (e->
id == (n_buffers & mask))
194 d = &vring->
desc[next];
201 sz, (n_buffers - slot));
203 used -= (n_buffers -
slot);
212 out_of_order_count++;
221 if (out_of_order_count)
233 vring_packed_desc_t *d;
236 u16 n_buffers = 0, start;
272 uword node_index,
int packed)
285 if (b->
flags & VNET_BUFFER_F_IS_IP4)
293 if (b->
flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
297 else if (b->
flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
308 if (b->
flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
311 else if (b->
flags & VNET_BUFFER_F_IS_IP6)
318 if (b->
flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
322 else if (b->
flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
333 if (b->
flags & VNET_BUFFER_F_IS_IP4)
341 hdr->hdr_len = gho.
hdr_sz;
351 if (b->
flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
354 else if (b->
flags & VNET_BUFFER_F_IS_IP6)
361 hdr->hdr_len = gho.
hdr_sz;
372 int csum_offload,
int is_pci,
int is_tun,
int is_indirect,
378 d = &vring->
desc[next];
381 u32 drop_inline = ~0;
385 if (b->
flags & VNET_BUFFER_F_GSO)
391 drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP;
395 else if (b->
flags & (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
396 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
402 drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP;
419 else if (is_indirect)
429 u32 indirect_buffer = 0;
432 drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED;
438 indirect_desc->
flags |= VLIB_BUFFER_NEXT_PRESENT;
440 bi = indirect_buffer;
467 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
485 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
505 u16 n_buffers_in_chain = 1;
512 while (b_temp->
flags & VLIB_BUFFER_NEXT_PRESENT)
514 n_buffers_in_chain++;
518 if (n_buffers_in_chain > free_desc_count)
519 return n_buffers_in_chain;
524 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
529 ~(VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID);
533 count = (count + 1) & mask;
555 if (drop_inline != ~0)
564 int hdr_sz,
int do_gso,
int csum_offload,
565 int is_pci,
int is_tun,
int is_indirect,
570 vring_packed_desc_t *d = &vring->
packed_desc[next];
573 u32 drop_inline = ~0;
577 if (b->
flags & VNET_BUFFER_F_GSO)
583 drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP;
587 else if (b->
flags & (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
588 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
594 drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP;
611 else if (is_indirect)
621 u32 indirect_buffer = 0;
624 drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED;
630 indirect_desc->
flags |= VLIB_BUFFER_NEXT_PRESENT;
632 bi = indirect_buffer;
634 vring_packed_desc_t *
id =
659 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
672 d->len = count *
sizeof (vring_packed_desc_t);
696 if (drop_inline != ~0)
708 u32 * buffers,
u16 n_left,
710 const int csum_offload)
712 int is_pci = (type == VIRTIO_IF_TYPE_PCI);
713 int is_tun = (type == VIRTIO_IF_TYPE_TUN);
720 u16 used, next, n_buffers = 0, n_buffers_left = 0;
721 u16 n_vectors = n_left;
731 while (n_buffers_left && used < sz)
740 hdr_sz, do_gso, csum_offload,
741 is_pci, is_tun, is_indirect,
757 while (n_left && used < sz)
762 vring, buffers[0], next,
763 hdr_sz, do_gso, csum_offload,
764 is_pci, is_tun, is_indirect,
780 if (n_left != n_vectors || n_buffers != n_buffers_left)
795 u16 req,
u16 next,
u32 * first_free_desc_index,
796 u16 * free_desc_count)
802 if (vring->
buffers[next & mask] == ~0)
804 if (*first_free_desc_index == ~0)
806 *first_free_desc_index = (next &
mask);
808 (*free_desc_count)++;
815 if (start + *free_desc_count ==
i)
817 (*free_desc_count)++;
835 u16 n_left,
int do_gso,
838 u16 used, next, avail, n_buffers = 0, n_buffers_left = 0;
839 int is_pci = (type == VIRTIO_IF_TYPE_PCI);
840 int is_tun = (type == VIRTIO_IF_TYPE_TUN);
848 u16 n_vectors = n_left;
854 u16 free_desc_count = 0;
858 u32 first_free_desc_index = ~0;
861 &first_free_desc_index, &free_desc_count);
864 next = first_free_desc_index;
867 free_desc_count = sz - used;
873 while (n_buffers_left && free_desc_count)
882 avail, next, mask, hdr_sz, do_gso,
883 csum_offload, is_pci, is_tun,
884 is_indirect, is_any_layout);
894 next = (next + n_added) & mask;
897 free_desc_count -= n_added;
901 while (n_left && free_desc_count)
906 free_desc_count, avail, next, mask,
907 hdr_sz, do_gso, csum_offload, is_pci,
908 is_tun, is_indirect, is_any_layout);
920 next = (next + n_added) & mask;
924 free_desc_count -= n_added;
927 if (n_left != n_vectors || n_buffers != n_buffers_left)
944 u32 * buffers,
u16 n_left,
int packed,
945 int do_gso,
int csum_offload)
950 do_gso, csum_offload);
954 do_gso, csum_offload);
961 u32 * buffers,
u16 n_left,
int packed)
968 buffers, n_left, packed,
973 buffers, n_left, packed,
978 buffers, n_left, packed,
995 int packed = vif->is_packed;
1005 if (vif->packet_coalesce)
1011 u16 retry_count = 2;
1017 if (vif->type == VIRTIO_IF_TYPE_TAP)
1020 &buffers[
frame->n_vectors - n_left],
1022 else if (vif->type == VIRTIO_IF_TYPE_PCI)
1025 &buffers[
frame->n_vectors - n_left],
1027 else if (vif->type == VIRTIO_IF_TYPE_TUN)
1030 &buffers[
frame->n_vectors - n_left],
1035 if (n_left && retry_count--)
1038 if (vif->packet_buffering && n_left)
1045 n_left -= n_buffered;
1049 &buffers[
frame->n_vectors - n_left], n_left,
1050 VIRTIO_TX_ERROR_NO_FREE_SLOTS);
1054 return frame->n_vectors - n_left;
1066 if (node_index == ~0)
1157 vif->
flags |= VIRTIO_IF_FLAG_ADMIN_UP;
1163 vif->
flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
u32 per_interface_next_index
gro_flow_table_t * flow_table
static_always_inline u16 virtio_interface_tx_split_gso_inline(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, u32 *buffers, u16 n_left, int do_gso, int csum_offload)
#define VRING_EVENT_F_DISABLE
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)
static_always_inline u16 virtio_vring_n_buffers(virtio_vring_buffering_t *buffering)
VNET_DEVICE_CLASS_TX_FN() virtio_device_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vring_desc_event_t * device_event
static_always_inline void virtio_set_rx_interrupt(virtio_if_t *vif, virtio_vring_t *vring)
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)
static clib_error_t * virtio_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_if_rx_mode mode)
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_always_inline void virtio_free_used_device_desc_packed(vlib_main_t *vm, virtio_vring_t *vring, uword node_index)
static heap_elt_t * last(heap_header_t *h)
#define VIRTIO_EVENT_START_TIMER
#define STRUCT_OFFSET_OF(t, f)
static_always_inline u32 virtio_vring_buffering_read_from_front(virtio_vring_buffering_t *buffering)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
struct _tcp_header tcp_header_t
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
#define VIRTIO_FEATURE(X)
static_always_inline u16 add_buffer_to_slot_packed(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_vring_t *vring, u32 bi, u16 next, int hdr_sz, int do_gso, int csum_offload, int is_pci, int is_tun, int is_indirect, int is_any_layout)
#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_packed_gso_inline(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, u32 *buffers, u16 n_left, const int do_gso, const int csum_offload)
description fragment has unexpected format
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 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.
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 set_gso_offsets(vlib_buffer_t *b, virtio_net_hdr_v1_t *hdr, const int is_l2)
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_always_inline u16 virtio_interface_tx_inline(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif, virtio_vring_t *vring, virtio_if_type_t type, u32 *buffers, u16 n_left, int packed)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static_always_inline void virtio_free_used_device_desc_split(vlib_main_t *vm, virtio_vring_t *vring, uword node_index)
vring_desc_event_t * driver_event
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.
u32 interrupt_queues_count
#define VIRTIO_NET_HDR_GSO_TCPV4
static_always_inline void virtio_free_used_device_desc(vlib_main_t *vm, virtio_vring_t *vring, uword node_index, int packed)
static_always_inline void set_checksum_offsets(vlib_buffer_t *b, virtio_net_hdr_v1_t *hdr, const 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
vlib_node_registration_t virtio_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (virtio_send_interrupt_node)
sll srl srl sll sra u16x4 i
vlib_main_t vlib_node_runtime_t * node
vring_packed_desc_t * packed_desc
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_always_inline void clib_memset_u8(void *p, u8 val, uword count)
static uword pointer_to_uword(const void *p)
#define VRING_DESC_F_NEXT
static_always_inline void virtio_tx_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0, u32 bi, int is_tun)
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)
virtio_vring_buffering_t * buffering
static_always_inline u16 virtio_interface_tx_gso_inline(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, u32 *buffers, u16 n_left, int packed, int do_gso, int csum_offload)
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)
#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)
static_always_inline u16 add_buffer_to_slot(vlib_main_t *vm, vlib_node_runtime_t *node, virtio_vring_t *vring, u32 bi, u16 free_desc_count, u16 avail, u16 next, u16 mask, int hdr_sz, int do_gso, int csum_offload, int is_pci, int is_tun, int is_indirect, int is_any_layout)
static_always_inline u16 virtio_vring_buffering_store_packets(virtio_vring_buffering_t *buffering, u32 *bi, u16 n_store)
#define VRING_DESC_F_USED
generic_header_offset_t gho
#define VIRTIO_EVENT_STOP_TIMER
#define CLIB_MEMORY_BARRIER()
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 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)
#define VRING_DESC_F_INDIRECT
static char * virtio_tx_func_error_strings[]
#define VIRTIO_NET_HDR_GSO_TCPV6
#define VRING_DESC_F_AVAIL
static_always_inline void virtio_set_rx_polling(virtio_if_t *vif, virtio_vring_t *vring)
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)