|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
22 #include <sys/ioctl.h>
23 #include <sys/socket.h>
26 #include <sys/types.h>
28 #include <netinet/in.h>
31 #include <linux/if_arp.h>
32 #include <linux/if_tun.h>
57 #define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 200)
61 #define foreach_vhost_user_tx_func_error \
63 _(NOT_READY, "vhost vring not ready") \
64 _(DOWN, "vhost interface is down") \
65 _(PKT_DROP_NOBUF, "tx packet drops (no available descriptors)") \
66 _(PKT_DROP_NOMRG, "tx packet drops (cannot merge descriptors)") \
67 _(MMAP_FAIL, "mmap failure") \
68 _(INDIRECT_OVERFLOW, "indirect descriptor table overflow")
72 #define _(f,s) VHOST_USER_TX_FUNC_ERROR_##f,
84 static __clib_unused
u8 *
88 u32 show_dev_instance = ~0;
94 if (show_dev_instance != ~0)
95 i = show_dev_instance;
97 s =
format (s,
"VirtualEthernet0/0/%d",
i);
101 static __clib_unused
int
110 hi->dev_instance, ~0);
115 vu_log_debug (vui,
"renumbered vhost-user interface dev_instance %d to %d",
116 hi->dev_instance, new_dev_instance);
154 hdr_desc = &rxvq->
desc[desc_current];
176 u16 copy_len,
u32 * map_hint)
178 void *dst0, *dst1, *dst2, *dst3;
223 virtio_net_hdr_t * hdr)
226 int is_ip4 =
b->
flags & VNET_BUFFER_F_IS_IP4;
232 if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
242 if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)
248 else if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
256 if (
b->
flags & VNET_BUFFER_F_GSO)
258 if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
274 (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM))
285 u16 * n_descs_processed,
u8 chained,
289 vring_packed_desc_t *desc_table = rxvq->
packed_desc;
304 for (desc_idx = 1; desc_idx < *n_descs_processed; desc_idx++)
317 *n_descs_processed = 0;
321 vring_packed_desc_t *desc_table = rxvq->
packed_desc;
333 (rxvq->
avail_event->flags != VRING_EVENT_F_DISABLE))
350 u32 desc_current = last_avail_idx & rxvq->
qsz_mask;
351 vring_packed_desc_t *hdr_desc = 0;
398 vring_packed_desc_t *desc_table;
400 u16 desc_head, desc_index, desc_len;
401 u16 n_descs_processed;
402 u8 indirect, chained;
406 rxvq = &vui->vrings[qid];
409 error = VHOST_USER_TX_FUNC_ERROR_NONE;
412 n_descs_processed = 0;
417 uword buffer_map_addr;
420 u32 total_desc_len = 0;
441 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
452 sizeof (vring_packed_desc_t)))
454 error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
457 n_entries = desc_table[desc_head].len >> 4;
462 error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
470 desc_len = vui->virtio_net_hdr_sz;
471 buffer_map_addr = desc_table[desc_index].addr;
472 buffer_len = desc_table[desc_index].len;
475 virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->
tx_headers[tx_headers_len];
479 hdr->num_buffers = 1;
481 or_flags = (b0->
flags & VNET_BUFFER_F_OFFLOAD);
492 cpy->
len = vui->virtio_net_hdr_sz;
493 cpy->
dst = buffer_map_addr;
496 buffer_map_addr += vui->virtio_net_hdr_sz;
497 buffer_len -= vui->virtio_net_hdr_sz;
520 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
526 buffer_map_addr = desc_table[desc_index].addr;
527 buffer_len = desc_table[desc_index].len;
528 total_desc_len += desc_len;
544 error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
547 total_desc_len += desc_len;
548 desc_index = (desc_index + 1) & rxvq->
qsz_mask;
549 buffer_map_addr = desc_table[desc_index].addr;
550 buffer_len = desc_table[desc_index].len;
553 else if (vui->virtio_net_hdr_sz == 12)
559 virtio_net_hdr_mrg_rxbuf_t *hdr =
562 desc_table[desc_index].len = desc_len;
564 desc_head = desc_index =
576 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
580 buffer_map_addr = desc_table[desc_index].addr;
581 buffer_len = desc_table[desc_index].len;
585 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
593 cpy->
len = bytes_left;
594 cpy->
len = (cpy->
len > buffer_len) ? buffer_len : cpy->
len;
595 cpy->
dst = buffer_map_addr;
599 bytes_left -= cpy->
len;
600 buffer_len -= cpy->
len;
601 buffer_map_addr += cpy->
len;
602 desc_len += cpy->
len;
610 (current_b0->
flags & VLIB_BUFFER_NEXT_PRESENT))
624 total_desc_len += desc_len;
644 VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
661 VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
679 if (
n_left && (
error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
696 return frame->n_vectors;
722 error = VHOST_USER_TX_FUNC_ERROR_DOWN;
728 error = VHOST_USER_TX_FUNC_ERROR_NOT_READY;
734 rxvq = &vui->vrings[qid];
737 error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
748 error = VHOST_USER_TX_FUNC_ERROR_NONE;
754 u16 desc_head, desc_index, desc_len;
756 uword buffer_map_addr;
774 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
778 desc_table = rxvq->
desc;
779 desc_head = desc_index =
789 error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
797 error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
803 desc_len = vui->virtio_net_hdr_sz;
804 buffer_map_addr = desc_table[desc_index].
addr;
805 buffer_len = desc_table[desc_index].
len;
809 virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->
tx_headers[tx_headers_len];
813 hdr->num_buffers = 1;
815 or_flags = (b0->
flags & VNET_BUFFER_F_OFFLOAD);
826 cpy->
len = vui->virtio_net_hdr_sz;
827 cpy->
dst = buffer_map_addr;
831 buffer_map_addr += vui->virtio_net_hdr_sz;
832 buffer_len -= vui->virtio_net_hdr_sz;
842 desc_index = desc_table[desc_index].
next;
843 buffer_map_addr = desc_table[desc_index].
addr;
844 buffer_len = desc_table[desc_index].
len;
846 else if (vui->virtio_net_hdr_sz == 12)
848 virtio_net_hdr_mrg_rxbuf_t *hdr =
871 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
875 desc_table = rxvq->
desc;
876 desc_head = desc_index =
886 error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
895 error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
900 buffer_map_addr = desc_table[desc_index].
addr;
901 buffer_len = desc_table[desc_index].
len;
905 error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
914 cpy->
len = bytes_left;
915 cpy->
len = (cpy->
len > buffer_len) ? buffer_len : cpy->
len;
916 cpy->
dst = buffer_map_addr;
920 bytes_left -= cpy->
len;
921 buffer_len -= cpy->
len;
922 buffer_map_addr += cpy->
len;
923 desc_len += cpy->
len;
932 (current_b0->
flags & VLIB_BUFFER_NEXT_PRESENT))
970 VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
988 VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
1007 if (
n_left && (
error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
1036 return frame->n_vectors;
1093 vu_log_err (vui,
"unhandled mode %d changed for if %d queue %d",
mode,
1109 u8 link_old, link_new;
1117 if (link_old != link_new)
1126 .name =
"vhost-user",
u32 next_buffer
Next buffer for this linked-list of buffers.
static_always_inline void vhost_user_send_call(vlib_main_t *vm, vhost_user_intf_t *vui, vhost_user_vring_t *vq)
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_GSO_NONE
static_always_inline u8 vui_is_link_up(vhost_user_intf_t *vui)
@ VNET_HW_IF_RX_MODE_ADAPTIVE
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
struct _vnet_device_class vnet_device_class_t
vnet_device_class_t vhost_user_device_class
static_always_inline void vhost_user_log_dirty_pages_2(vhost_user_intf_t *vui, u64 addr, u64 len, u8 is_host_address)
static_always_inline void vhost_user_vring_unlock(vhost_user_intf_t *vui, u32 qid)
Unlock the vring lock.
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.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
struct _tcp_header tcp_header_t
VNET_DEVICE_CLASS(vhost_user_device_class)
static __clib_unused clib_error_t * vhost_user_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_if_rx_mode mode)
vlib_main_t vlib_node_runtime_t * node
#define clib_error_return(e, args...)
static __clib_unused u8 * format_vhost_user_interface_name(u8 *s, va_list *args)
u16 device_index
The interface queue index (Not the virtio vring idx)
vl_api_tunnel_mode_t mode
#define VHOST_USER_TX_COPY_THRESHOLD
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_HW_IF_RX_MODE_POLLING
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]
static_always_inline void vhost_user_advance_last_avail_table_idx(vhost_user_intf_t *vui, vhost_user_vring_t *vring, u8 chained)
#define VRING_DESC_F_USED
@ VNET_HW_INTERFACE_FLAG_LINK_UP
#define VIRTIO_FEATURE(X)
vlib_simple_counter_main_t * sw_if_counters
vring_desc_event_t * avail_event
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
#define vhost_user_log_dirty_ring(vui, vq, member)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static __clib_unused char * vhost_user_tx_func_error_strings[]
static_always_inline u8 vhost_user_packed_desc_available(vhost_user_vring_t *vring, u16 idx)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
static_always_inline uword vhost_user_device_class_packed(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
@ VHOST_USER_TX_FUNC_N_ERROR
#define VHOST_VRING_IDX_RX(qid)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline u64 vhost_user_is_packed_ring_supported(vhost_user_intf_t *vui)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
#define VIRTIO_NET_HDR_GSO_TCPV4
vhost_user_tx_func_error_t
static_always_inline void vhost_user_advance_last_used_idx(vhost_user_vring_t *vring)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static_always_inline void vhost_user_handle_tx_offload(vhost_user_intf_t *vui, vlib_buffer_t *b, virtio_net_hdr_t *hdr)
static_always_inline void vhost_user_tx_trace(vhost_trace_t *t, vhost_user_intf_t *vui, u16 qid, vlib_buffer_t *b, vhost_user_vring_t *rxvq)
#define VHOST_USER_EVENT_STOP_TIMER
#define VRING_DESC_F_AVAIL
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u32 virtio_ring_flags
The device index.
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
static __clib_unused clib_error_t * vhost_user_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define static_always_inline
#define VRING_DESC_F_INDIRECT
#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 vu_log_err(dev, f,...)
#define VIRTIO_NET_HDR_GSO_UDP
vhost_trace_t * current_trace
@ VNET_HW_IF_RX_MODE_INTERRUPT
#define VRING_DESC_F_NEXT
sll srl srl sll sra u16x4 i
vring_packed_desc_t * packed_desc
vhost_user_vring_t * vrings
#define VRING_AVAIL_F_NO_INTERRUPT
#define CLIB_MEMORY_BARRIER()
#define VHOST_VRING_IDX_TX(qid)
static_always_inline u32 vhost_user_tx_copy(vhost_user_intf_t *vui, vhost_copy_t *cpy, u16 copy_len, u32 *map_hint)
#define VRING_USED_F_NO_NOTIFY
#define CLIB_CACHE_LINE_BYTES
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
u16 current_length
Nbytes between current data and the end of this buffer.
static_always_inline void vhost_user_dequeue_descs(vhost_user_vring_t *rxvq, virtio_net_hdr_mrg_rxbuf_t *hdr, u16 *n_descs_processed)
static __clib_unused int vhost_user_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
#define VHOST_USER_COPY_ARRAY_N
static_always_inline void vhost_user_dequeue_chained_descs(vhost_user_vring_t *rxvq, u16 *n_descs_processed)
#define VHOST_USER_EVENT_START_TIMER
static_always_inline void vhost_user_vring_lock(vhost_user_intf_t *vui, u32 qid)
Spin until the vring is successfully locked.
description fragment has unexpected format
#define foreach_vhost_user_tx_func_error
u32 * show_dev_instance_by_real_dev_instance
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
vhost_user_main_t vhost_user_main
#define VIRTIO_NET_HDR_GSO_TCPV6
static_always_inline void vhost_user_mark_desc_available(vlib_main_t *vm, vhost_user_intf_t *vui, vhost_user_vring_t *rxvq, u16 *n_descs_processed, u8 chained, vlib_frame_t *frame, u32 n_left)
#define VIRTIO_NET_HDR_F_NEEDS_CSUM
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static_always_inline u8 * format_vhost_trace(u8 *s, va_list *va)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
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 void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u16 ip4_header_checksum(ip4_header_t *i)
vring_used_elem_t ring[0]
static_always_inline void * map_guest_mem(vhost_user_intf_t *vui, uword addr, u32 *hint)
clib_spinlock_t vring_lock
#define vu_log_debug(dev, f,...)
vhost_user_intf_t * vhost_user_interfaces
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
u16 first_desc_len
Runtime queue flags
vlib_node_registration_t vhost_user_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (vhost_user_send_interrupt_node)
@ VNET_INTERFACE_COUNTER_DROP
static_always_inline void vhost_user_advance_last_avail_idx(vhost_user_vring_t *vring)
vnet_interface_main_t interface_main
virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE]
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
VLIB buffer representation.
static_always_inline void vhost_user_tx_trace_packed(vhost_trace_t *t, vhost_user_intf_t *vui, u16 qid, vlib_buffer_t *b, vhost_user_vring_t *rxvq)
vl_api_wireguard_peer_flags_t flags