18 #include <sys/types.h> 29 #define foreach_virtio_tx_func_error \ 30 _(NO_FREE_SLOTS, "no free tx slots") \ 31 _(TRUNC_PACKET, "packet > buffer size -- truncated in tx ring") \ 32 _(PENDING_MSGS, "pending msgs in tx ring") \ 33 _(NO_TX_QUEUES, "no tx queues") \ 34 _(OUT_OF_ORDER, "out-of-order buffers in used ring") 38 #define _(f,s) VIRTIO_TX_ERROR_##f, 50 #ifndef CLIB_MARCH_VARIANT 54 u32 dev_instance = va_arg (*args,
u32);
74 u32 dev_instance = va_arg (*args,
u32);
75 int verbose = va_arg (*args,
int);
78 s =
format (s,
"VIRTIO interface");
90 s =
format (s,
"Unimplemented...");
97 ASSERT (n_buffers <= ring_size);
119 u16 out_of_order_count = 0;
126 struct vring_used_elem *e = &vring->
used->ring[last & mask];
128 slot = n_buffers = e->id;
130 while (e->id == (n_buffers & mask))
137 e = &vring->
used->ring[last & mask];
140 sz, (n_buffers - slot));
142 used -= (n_buffers - slot);
151 out_of_order_count++;
160 if (out_of_order_count)
171 u16 mask,
int do_gso)
175 struct vring_desc *d;
176 d = &vring->
desc[next];
181 if (do_gso && (b->
flags & VNET_BUFFER_F_GSO))
183 if (b->
flags & VNET_BUFFER_F_IS_IP4)
185 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
187 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
189 hdr->csum_offset = 0x10;
193 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
195 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
197 hdr->csum_offset = 0x10;
220 u32 indirect_buffer = 0;
226 indirect_desc->
flags |= VLIB_BUFFER_NEXT_PRESENT;
228 bi = indirect_buffer;
230 struct vring_desc *
id =
249 id->flags = VRING_DESC_F_NEXT;
256 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
258 id->flags = VRING_DESC_F_NEXT;
274 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
276 id->flags = VRING_DESC_F_NEXT;
287 d->len = count *
sizeof (
struct vring_desc);
288 d->flags = VRING_DESC_F_INDIRECT;
291 vring->
avail->ring[avail & mask] = next;
298 u16 req,
u16 next,
u32 * first_free_desc_index,
299 u16 * free_desc_count)
305 if (vring->
buffers[next & mask] == ~0)
307 if (*first_free_desc_index == ~0)
309 *first_free_desc_index = (next & mask);
311 (*free_desc_count)++;
318 if (start + *free_desc_count ==
i)
320 (*free_desc_count)++;
330 return *first_free_desc_index;
342 u16 used, next, avail;
360 avail = vring->
avail->idx;
362 u16 free_desc_count = 0;
366 u32 first_free_desc_index = ~0;
369 &first_free_desc_index, &free_desc_count);
372 next = first_free_desc_index;
375 free_desc_count = sz - used;
377 while (n_left && free_desc_count)
386 next = (next + n_added) & mask;
396 vring->
avail->idx = avail;
443 if (node_index == ~0)
492 vif->
flags |= VIRTIO_IF_FLAG_ADMIN_UP;
498 vif->
flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
u32 per_interface_next_index
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 uword vlib_buffer_get_current_pa(vlib_main_t *vm, vlib_buffer_t *b)
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
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 foreach_virtio_tx_func_error
vnet_main_t * vnet_get_main(void)
vnet_interface_main_t interface_main
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)
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)
static_always_inline u32 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 uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
static char * virtio_tx_func_error_strings[]
vnet_hw_interface_rx_mode
struct vring_avail * avail
#define static_always_inline
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, int do_gso)
VNET_DEVICE_CLASS_TX_FN() virtio_device_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void virtio_clear_hw_interface_counters(u32 instance)
#define clib_error_return(e, args...)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
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 void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static_always_inline void virtio_memset_ring_u32(u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
u32 node_index
Node index.
static u8 * format_virtio_device(u8 *s, va_list *args)
static void virtio_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
virtio_vring_t * rxq_vrings
static u8 * format_virtio_tx_trace(u8 *s, va_list *args)
#define VIRTIO_RING_FLAG_MASK_INT
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 clib_error_t * virtio_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
vl_api_vxlan_gbp_api_tunnel_mode_t mode
#define VIRTIO_FEATURE(X)
VNET_DEVICE_CLASS(bond_dev_class)
static uword pointer_to_uword(const void *p)
virtio_main_t virtio_main
static vlib_main_t * vlib_get_main(void)
#define VRING_TX_OUT_OF_ORDER
static_always_inline u16 add_buffer_to_slot(vlib_main_t *vm, virtio_if_t *vif, virtio_vring_t *vring, u32 bi, u16 avail, u16 next, u16 mask, int do_gso)
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
u32 next_buffer
Next buffer for this linked-list of buffers.
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
VLIB buffer representation.
static_always_inline void virtio_free_used_device_desc(vlib_main_t *vm, virtio_vring_t *vring, uword node_index)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
u8 * format_virtio_device_name(u8 *s, va_list *args)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
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.
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)