X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fdevices%2Fvirtio%2Fdevice.c;h=99157cd6166e57353899ed303690fa3b7624666e;hb=9e2a78564f0fc07f1ea3d15a31fa7ca3a0f6424d;hp=87fd6fdcf5fd489704707c9928a9c9fb15e80d97;hpb=38b09681a0e68b3711206516bc220599f6a73281;p=vpp.git diff --git a/src/vnet/devices/virtio/device.c b/src/vnet/devices/virtio/device.c index 87fd6fdcf5f..99157cd6166 100644 --- a/src/vnet/devices/virtio/device.c +++ b/src/vnet/devices/virtio/device.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -69,10 +70,30 @@ format_virtio_device (u8 * s, va_list * args) return s; } +typedef struct +{ + u32 buffer_index; + u32 sw_if_index; + vlib_buffer_t buffer; + generic_header_offset_t gho; +} virtio_tx_trace_t; + static u8 * -format_virtio_tx_trace (u8 * s, va_list * args) +format_virtio_tx_trace (u8 * s, va_list * va) { - s = format (s, "Unimplemented..."); + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); + virtio_tx_trace_t *t = va_arg (*va, virtio_tx_trace_t *); + u32 indent = format_get_indent (s); + + s = format (s, "%U ", format_generic_header_offset, &t->gho); + s = format (s, "%Ubuffer 0x%x: %U", + format_white_space, indent, + t->buffer_index, format_vnet_buffer, &t->buffer); + + s = format (s, "\n%U%U", format_white_space, indent, + format_ethernet_header_with_length, t->buffer.pre_data, + sizeof (t->buffer.pre_data)); return s; } @@ -482,7 +503,7 @@ 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 csum_offload, int do_gro) { u16 n_left = frame->n_vectors; virtio_vring_t *vring; @@ -493,6 +514,7 @@ virtio_interface_tx_gso_inline (vlib_main_t * vm, vlib_node_runtime_t * node, u16 mask = sz - 1; u16 retry_count = 2; u32 *buffers = vlib_frame_vector_args (frame); + u32 to[GRO_TO_VECTOR_SIZE (n_left)]; clib_spinlock_lock_if_init (&vring->lockp); @@ -500,6 +522,12 @@ virtio_interface_tx_gso_inline (vlib_main_t * vm, vlib_node_runtime_t * node, (vring->last_kick_avail_idx != vring->avail->idx)) virtio_kick (vm, vring, vif); + if (do_gro) + { + n_left = vnet_gro_inline (vm, vring->flow_table, buffers, n_left, to); + buffers = to; + } + retry: /* free consumed buffers */ virtio_free_used_device_desc (vm, vring, node->node_index); @@ -526,6 +554,44 @@ retry: while (n_left && free_desc_count) { u16 n_added = 0; + virtio_tx_trace_t *t; + + vlib_buffer_t *b0 = vlib_get_buffer (vm, buffers[0]); + if (b0->flags & VLIB_BUFFER_IS_TRACED) + { + t = vlib_add_trace (vm, node, b0, sizeof (t[0])); + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; + t->buffer_index = buffers[0]; + if (type == VIRTIO_IF_TYPE_TUN) + { + int is_ip4 = 0, is_ip6 = 0; + + switch (((u8 *) vlib_buffer_get_current (b0))[0] & 0xf0) + { + case 0x40: + is_ip4 = 1; + break; + case 0x60: + is_ip6 = 1; + break; + default: + break; + } + vnet_generic_header_offset_parser (b0, &t->gho, 0, is_ip4, + is_ip6); + } + else + vnet_generic_header_offset_parser (b0, &t->gho, 1, + b0->flags & + VNET_BUFFER_F_IS_IP4, + b0->flags & + VNET_BUFFER_F_IS_IP6); + + clib_memcpy_fast (&t->buffer, b0, + sizeof (*b0) - sizeof (b0->pre_data)); + clib_memcpy_fast (t->buffer.pre_data, vlib_buffer_get_current (b0), + sizeof (t->buffer.pre_data)); + } n_added = add_buffer_to_slot (vm, vif, type, vring, buffers[0], free_desc_count, avail, next, mask, do_gso, csum_offload, @@ -563,7 +629,8 @@ retry: if (retry_count--) goto retry; - virtio_interface_drop_inline (vm, node->node_index, buffers, n_left, + virtio_interface_drop_inline (vm, node->node_index, + buffers, n_left, VIRTIO_TX_ERROR_NO_FREE_SLOTS); } @@ -583,15 +650,18 @@ virtio_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) return virtio_interface_tx_gso_inline (vm, node, frame, vif, type, 1 /* do_gso */ , - 1 /* checksum offload */ ); + 1 /* checksum offload */ , + vif->packet_coalesce); else if (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD) return virtio_interface_tx_gso_inline (vm, node, frame, vif, type, 0 /* no do_gso */ , - 1 /* checksum offload */ ); + 1 /* checksum offload */ , + 0 /* do_gro */ ); else return virtio_interface_tx_gso_inline (vm, node, frame, vif, type, 0 /* no do_gso */ , - 0 /* no checksum offload */ ); + 0 /* no checksum offload */ , + 0 /* do_gro */ ); } VNET_DEVICE_CLASS_TX_FN (virtio_device_class) (vlib_main_t * vm, @@ -659,9 +729,16 @@ virtio_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid, } if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING) - vring->avail->flags |= VIRTIO_RING_FLAG_MASK_INT; + { + /* only enable packet coalesce in poll mode */ + gro_flow_table_set_is_enable (vring->flow_table, 1); + vring->avail->flags |= VIRTIO_RING_FLAG_MASK_INT; + } else - vring->avail->flags &= ~VIRTIO_RING_FLAG_MASK_INT; + { + gro_flow_table_set_is_enable (vring->flow_table, 0); + vring->avail->flags &= ~VIRTIO_RING_FLAG_MASK_INT; + } return 0; }