Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
| 18 | #include <sys/types.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <fcntl.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 21 | |
| 22 | #include <vlib/vlib.h> |
| 23 | #include <vlib/unix/unix.h> |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 24 | #include <vnet/vnet.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 25 | #include <vnet/ethernet/ethernet.h> |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 26 | #include <vnet/gso/gro_func.h> |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 27 | #include <vnet/gso/hdr_offset_parser.h> |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 28 | #include <vnet/ip/ip4_packet.h> |
| 29 | #include <vnet/ip/ip6_packet.h> |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 30 | #include <vnet/ip/ip_psh_cksum.h> |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 31 | #include <vnet/tcp/tcp_packet.h> |
| 32 | #include <vnet/udp/udp_packet.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 33 | #include <vnet/devices/virtio/virtio.h> |
| 34 | |
Mohsin Kazmi | 637c97c | 2021-05-12 14:51:29 +0200 | [diff] [blame] | 35 | #define VIRTIO_TX_MAX_CHAIN_LEN 127 |
| 36 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 37 | #define foreach_virtio_tx_func_error \ |
| 38 | _(NO_FREE_SLOTS, "no free tx slots") \ |
| 39 | _(TRUNC_PACKET, "packet > buffer size -- truncated in tx ring") \ |
| 40 | _(PENDING_MSGS, "pending msgs in tx ring") \ |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 41 | _(INDIRECT_DESC_ALLOC_FAILED, "indirect descriptor allocation failed - packet drop") \ |
| 42 | _(OUT_OF_ORDER, "out-of-order buffers in used ring") \ |
| 43 | _(GSO_PACKET_DROP, "gso disabled on itf -- gso packet drop") \ |
| 44 | _(CSUM_OFFLOAD_PACKET_DROP, "checksum offload disabled on itf -- csum offload packet drop") |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 45 | |
| 46 | typedef enum |
| 47 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 48 | #define _(f,s) VIRTIO_TX_ERROR_##f, |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 49 | foreach_virtio_tx_func_error |
| 50 | #undef _ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 51 | VIRTIO_TX_N_ERROR, |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 52 | } virtio_tx_func_error_t; |
| 53 | |
| 54 | static char *virtio_tx_func_error_strings[] = { |
| 55 | #define _(n,s) s, |
| 56 | foreach_virtio_tx_func_error |
| 57 | #undef _ |
| 58 | }; |
| 59 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 60 | static u8 * |
| 61 | format_virtio_device (u8 * s, va_list * args) |
| 62 | { |
| 63 | u32 dev_instance = va_arg (*args, u32); |
| 64 | int verbose = va_arg (*args, int); |
| 65 | u32 indent = format_get_indent (s); |
| 66 | |
| 67 | s = format (s, "VIRTIO interface"); |
| 68 | if (verbose) |
| 69 | { |
| 70 | s = format (s, "\n%U instance %u", format_white_space, indent + 2, |
| 71 | dev_instance); |
| 72 | } |
| 73 | return s; |
| 74 | } |
| 75 | |
Mohsin Kazmi | b5ca559 | 2020-06-26 13:48:26 +0000 | [diff] [blame] | 76 | typedef struct |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 77 | { |
Mohsin Kazmi | b5ca559 | 2020-06-26 13:48:26 +0000 | [diff] [blame] | 78 | u32 buffer_index; |
| 79 | u32 sw_if_index; |
Mohsin Kazmi | b5ca559 | 2020-06-26 13:48:26 +0000 | [diff] [blame] | 80 | generic_header_offset_t gho; |
Damjan Marion | 8c69887 | 2020-10-10 19:17:58 +0200 | [diff] [blame] | 81 | vlib_buffer_t buffer; |
Mohsin Kazmi | b5ca559 | 2020-06-26 13:48:26 +0000 | [diff] [blame] | 82 | } virtio_tx_trace_t; |
| 83 | |
| 84 | static u8 * |
| 85 | format_virtio_tx_trace (u8 * s, va_list * va) |
| 86 | { |
| 87 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); |
| 88 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); |
| 89 | virtio_tx_trace_t *t = va_arg (*va, virtio_tx_trace_t *); |
| 90 | u32 indent = format_get_indent (s); |
| 91 | |
BenoƮt Ganne | 03f2a01 | 2021-07-20 16:49:13 +0200 | [diff] [blame] | 92 | s = format (s, "%Ubuffer 0x%x: %U\n", format_white_space, indent, |
| 93 | t->buffer_index, format_vnet_buffer_no_chain, &t->buffer); |
Mohsin Kazmi | b3a8f4e | 2020-09-15 16:41:44 +0000 | [diff] [blame] | 94 | s = |
| 95 | format (s, "%U%U\n", format_white_space, indent, |
| 96 | format_generic_header_offset, &t->gho); |
| 97 | s = |
| 98 | format (s, "%U%U", format_white_space, indent, |
| 99 | format_ethernet_header_with_length, t->buffer.pre_data, |
| 100 | sizeof (t->buffer.pre_data)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 101 | return s; |
| 102 | } |
| 103 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 104 | static void |
| 105 | virtio_tx_trace (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0, |
| 106 | u32 bi, int is_tun) |
Mohsin Kazmi | 03b2695 | 2020-09-16 16:53:16 +0000 | [diff] [blame] | 107 | { |
| 108 | virtio_tx_trace_t *t; |
| 109 | t = vlib_add_trace (vm, node, b0, sizeof (t[0])); |
| 110 | t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 111 | t->buffer_index = bi; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 112 | if (is_tun) |
Mohsin Kazmi | 03b2695 | 2020-09-16 16:53:16 +0000 | [diff] [blame] | 113 | { |
| 114 | int is_ip4 = 0, is_ip6 = 0; |
| 115 | |
| 116 | switch (((u8 *) vlib_buffer_get_current (b0))[0] & 0xf0) |
| 117 | { |
| 118 | case 0x40: |
| 119 | is_ip4 = 1; |
| 120 | break; |
| 121 | case 0x60: |
| 122 | is_ip6 = 1; |
| 123 | break; |
| 124 | default: |
| 125 | break; |
| 126 | } |
| 127 | vnet_generic_header_offset_parser (b0, &t->gho, 0, is_ip4, is_ip6); |
| 128 | } |
| 129 | else |
| 130 | vnet_generic_header_offset_parser (b0, &t->gho, 1, |
| 131 | b0->flags & |
| 132 | VNET_BUFFER_F_IS_IP4, |
| 133 | b0->flags & VNET_BUFFER_F_IS_IP6); |
| 134 | |
| 135 | clib_memcpy_fast (&t->buffer, b0, sizeof (*b0) - sizeof (b0->pre_data)); |
| 136 | clib_memcpy_fast (t->buffer.pre_data, vlib_buffer_get_current (b0), |
| 137 | sizeof (t->buffer.pre_data)); |
| 138 | } |
| 139 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 140 | static void |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 141 | virtio_interface_drop_inline (vlib_main_t *vm, virtio_if_t *vif, |
| 142 | uword node_index, u32 *buffers, u16 n, |
| 143 | virtio_tx_func_error_t error) |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 144 | { |
| 145 | vlib_error_count (vm, node_index, error, n); |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 146 | vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters + |
| 147 | VNET_INTERFACE_COUNTER_DROP, |
| 148 | vm->thread_index, vif->sw_if_index, n); |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 149 | vlib_buffer_free (vm, buffers, n); |
| 150 | } |
| 151 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 152 | static void |
| 153 | virtio_memset_ring_u32 (u32 *ring, u32 start, u32 ring_size, u32 n_buffers) |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 154 | { |
| 155 | ASSERT (n_buffers <= ring_size); |
| 156 | |
| 157 | if (PREDICT_TRUE (start + n_buffers <= ring_size)) |
| 158 | { |
| 159 | clib_memset_u32 (ring + start, ~0, n_buffers); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | clib_memset_u32 (ring + start, ~0, ring_size - start); |
| 164 | clib_memset_u32 (ring, ~0, n_buffers - (ring_size - start)); |
| 165 | } |
| 166 | } |
| 167 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 168 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 169 | virtio_free_used_device_desc_split (vlib_main_t *vm, |
| 170 | vnet_virtio_vring_t *vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 171 | uword node_index) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 172 | { |
| 173 | u16 used = vring->desc_in_use; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 174 | u16 sz = vring->queue_size; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 175 | u16 mask = sz - 1; |
| 176 | u16 last = vring->last_used_idx; |
| 177 | u16 n_left = vring->used->idx - last; |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 178 | u16 out_of_order_count = 0; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 179 | |
| 180 | if (n_left == 0) |
| 181 | return; |
| 182 | |
| 183 | while (n_left) |
| 184 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 185 | vnet_virtio_vring_used_elem_t *e = &vring->used->ring[last & mask]; |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 186 | u16 slot, n_buffers; |
| 187 | slot = n_buffers = e->id; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 188 | |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 189 | while (e->id == (n_buffers & mask)) |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 190 | { |
| 191 | n_left--; |
| 192 | last++; |
| 193 | n_buffers++; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 194 | vnet_virtio_vring_desc_t *d = &vring->desc[e->id]; |
Mohsin Kazmi | ce21599 | 2020-04-10 14:57:06 +0000 | [diff] [blame] | 195 | u16 next; |
| 196 | while (d->flags & VRING_DESC_F_NEXT) |
| 197 | { |
| 198 | n_buffers++; |
| 199 | next = d->next; |
| 200 | d = &vring->desc[next]; |
| 201 | } |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 202 | if (n_left == 0) |
| 203 | break; |
| 204 | e = &vring->used->ring[last & mask]; |
| 205 | } |
| 206 | vlib_buffer_free_from_ring (vm, vring->buffers, slot, |
| 207 | sz, (n_buffers - slot)); |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 208 | virtio_memset_ring_u32 (vring->buffers, slot, sz, (n_buffers - slot)); |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 209 | used -= (n_buffers - slot); |
| 210 | |
| 211 | if (n_left > 0) |
| 212 | { |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 213 | vlib_buffer_free (vm, &vring->buffers[e->id], 1); |
| 214 | vring->buffers[e->id] = ~0; |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 215 | used--; |
| 216 | last++; |
| 217 | n_left--; |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 218 | out_of_order_count++; |
| 219 | vring->flags |= VRING_TX_OUT_OF_ORDER; |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 220 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 221 | } |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * Some vhost-backends give buffers back in out-of-order fashion in used ring. |
| 225 | * It impacts the overall virtio-performance. |
| 226 | */ |
| 227 | if (out_of_order_count) |
| 228 | vlib_error_count (vm, node_index, VIRTIO_TX_ERROR_OUT_OF_ORDER, |
| 229 | out_of_order_count); |
| 230 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 231 | vring->desc_in_use = used; |
| 232 | vring->last_used_idx = last; |
| 233 | } |
| 234 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 235 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 236 | virtio_free_used_device_desc_packed (vlib_main_t *vm, |
| 237 | vnet_virtio_vring_t *vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 238 | uword node_index) |
| 239 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 240 | vnet_virtio_vring_packed_desc_t *d; |
| 241 | u16 sz = vring->queue_size; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 242 | u16 last = vring->last_used_idx; |
| 243 | u16 n_buffers = 0, start; |
| 244 | u16 flags; |
| 245 | |
| 246 | if (vring->desc_in_use == 0) |
| 247 | return; |
| 248 | |
| 249 | d = &vring->packed_desc[last]; |
| 250 | flags = d->flags; |
| 251 | start = d->id; |
| 252 | |
| 253 | while ((flags & VRING_DESC_F_AVAIL) == (vring->used_wrap_counter << 7) && |
| 254 | (flags & VRING_DESC_F_USED) == (vring->used_wrap_counter << 15)) |
| 255 | { |
| 256 | last++; |
| 257 | n_buffers++; |
| 258 | |
| 259 | if (last >= sz) |
| 260 | { |
| 261 | last = 0; |
| 262 | vring->used_wrap_counter ^= 1; |
| 263 | } |
| 264 | d = &vring->packed_desc[last]; |
| 265 | flags = d->flags; |
| 266 | } |
| 267 | |
| 268 | if (n_buffers) |
| 269 | { |
| 270 | vlib_buffer_free_from_ring (vm, vring->buffers, start, sz, n_buffers); |
| 271 | virtio_memset_ring_u32 (vring->buffers, start, sz, n_buffers); |
| 272 | vring->desc_in_use -= n_buffers; |
| 273 | vring->last_used_idx = last; |
| 274 | } |
| 275 | } |
| 276 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 277 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 278 | virtio_free_used_device_desc (vlib_main_t *vm, vnet_virtio_vring_t *vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 279 | uword node_index, int packed) |
| 280 | { |
| 281 | if (packed) |
| 282 | virtio_free_used_device_desc_packed (vm, vring, node_index); |
| 283 | else |
| 284 | virtio_free_used_device_desc_split (vm, vring, node_index); |
| 285 | |
| 286 | } |
| 287 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 288 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 289 | set_checksum_offsets (vlib_buffer_t *b, vnet_virtio_net_hdr_v1_t *hdr, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 290 | const int is_l2) |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 291 | { |
Mohsin Kazmi | 36f7a6a | 2021-05-05 14:26:38 +0200 | [diff] [blame] | 292 | vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 293 | |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 294 | if (b->flags & VNET_BUFFER_F_IS_IP4) |
| 295 | { |
| 296 | ip4_header_t *ip4; |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 297 | hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 298 | hdr->csum_start = vnet_buffer (b)->l4_hdr_offset; // 0x22; |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * virtio devices do not support IP4 checksum offload. So driver takes |
| 302 | * care of it while doing tx. |
| 303 | */ |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 304 | ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 305 | if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) |
| 306 | ip4->checksum = ip4_header_checksum (ip4); |
| 307 | |
| 308 | /* |
| 309 | * virtio devices assume the l4 header is set to the checksum of the |
| 310 | * l3 pseudo-header, so we compute it before tx-ing |
| 311 | */ |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 312 | if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM) |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 313 | { |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 314 | tcp_header_t *tcp = |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 315 | (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 316 | tcp->checksum = ip4_pseudo_header_cksum (ip4); |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 317 | hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum); |
| 318 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 319 | else if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM) |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 320 | { |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 321 | udp_header_t *udp = |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 322 | (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 323 | udp->checksum = ip4_pseudo_header_cksum (ip4); |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 324 | hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum); |
| 325 | } |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 326 | } |
| 327 | else if (b->flags & VNET_BUFFER_F_IS_IP6) |
| 328 | { |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 329 | ip6_header_t *ip6; |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 330 | hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 331 | hdr->csum_start = vnet_buffer (b)->l4_hdr_offset; // 0x36; |
| 332 | ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * virtio devices assume the l4 header is set to the checksum of the |
| 336 | * l3 pseudo-header, so we compute it before tx-ing |
| 337 | */ |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 338 | if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM) |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 339 | { |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 340 | tcp_header_t *tcp = |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 341 | (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 342 | tcp->checksum = ip6_pseudo_header_cksum (ip6); |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 343 | hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum); |
| 344 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 345 | else if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM) |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 346 | { |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 347 | udp_header_t *udp = |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 348 | (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
Mohsin Kazmi | f546236 | 2021-02-23 15:55:04 +0100 | [diff] [blame] | 349 | udp->checksum = ip6_pseudo_header_cksum (ip6); |
Mohsin Kazmi | 0937fdf | 2020-03-25 20:37:16 +0000 | [diff] [blame] | 350 | hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum); |
| 351 | } |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 355 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 356 | set_gso_offsets (vlib_buffer_t *b, vnet_virtio_net_hdr_v1_t *hdr, |
| 357 | const int is_l2) |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 358 | { |
Mohsin Kazmi | 36f7a6a | 2021-05-05 14:26:38 +0200 | [diff] [blame] | 359 | vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 360 | |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 361 | if (b->flags & VNET_BUFFER_F_IS_IP4) |
| 362 | { |
| 363 | ip4_header_t *ip4; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 364 | hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; |
| 365 | hdr->gso_size = vnet_buffer2 (b)->gso_size; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 366 | hdr->hdr_len = vnet_buffer (b)->l4_hdr_offset - |
| 367 | vnet_buffer (b)->l2_hdr_offset + |
| 368 | vnet_buffer2 (b)->gso_l4_hdr_sz; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 369 | hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 370 | hdr->csum_start = vnet_buffer (b)->l4_hdr_offset; // 0x22; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 371 | hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum); |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 372 | ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 373 | /* |
| 374 | * virtio devices do not support IP4 checksum offload. So driver takes care |
| 375 | * of it while doing tx. |
| 376 | */ |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 377 | if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 378 | ip4->checksum = ip4_header_checksum (ip4); |
| 379 | } |
| 380 | else if (b->flags & VNET_BUFFER_F_IS_IP6) |
| 381 | { |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 382 | hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; |
| 383 | hdr->gso_size = vnet_buffer2 (b)->gso_size; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 384 | hdr->hdr_len = vnet_buffer (b)->l4_hdr_offset - |
| 385 | vnet_buffer (b)->l2_hdr_offset + |
| 386 | vnet_buffer2 (b)->gso_l4_hdr_sz; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 387 | hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
Mohsin Kazmi | 096c8cc | 2022-05-18 16:51:57 +0000 | [diff] [blame] | 388 | hdr->csum_start = vnet_buffer (b)->l4_hdr_offset; // 0x36; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 389 | hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum); |
| 390 | } |
| 391 | } |
| 392 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 393 | static u16 |
| 394 | add_buffer_to_slot (vlib_main_t *vm, vlib_node_runtime_t *node, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 395 | virtio_if_t *vif, vnet_virtio_vring_t *vring, u32 bi, |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 396 | u16 free_desc_count, u16 avail, u16 next, u16 mask, |
| 397 | int hdr_sz, int do_gso, int csum_offload, int is_pci, |
| 398 | int is_tun, int is_indirect, int is_any_layout) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 399 | { |
| 400 | u16 n_added = 0; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 401 | vnet_virtio_vring_desc_t *d; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 402 | int is_l2 = !is_tun; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 403 | d = &vring->desc[next]; |
| 404 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 405 | vnet_virtio_net_hdr_v1_t *hdr = vlib_buffer_get_current (b) - hdr_sz; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 406 | u32 drop_inline = ~0; |
Damjan Marion | 508cabc | 2018-02-08 19:49:22 +0100 | [diff] [blame] | 407 | |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 408 | clib_memset_u8 (hdr, 0, hdr_sz); |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 409 | |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 410 | if (b->flags & VNET_BUFFER_F_GSO) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 411 | { |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 412 | if (do_gso) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 413 | set_gso_offsets (b, hdr, is_l2); |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 414 | else |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 415 | { |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 416 | drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP; |
| 417 | goto done; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 418 | } |
| 419 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 420 | else if (b->flags & VNET_BUFFER_F_OFFLOAD) |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 421 | { |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 422 | if (csum_offload) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 423 | set_checksum_offsets (b, hdr, is_l2); |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 424 | else |
| 425 | { |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 426 | drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP; |
| 427 | goto done; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 428 | } |
Mohsin Kazmi | 6d4af89 | 2020-01-03 15:11:53 +0000 | [diff] [blame] | 429 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 430 | |
Mohsin Kazmi | 8314371 | 2020-10-07 13:23:55 +0200 | [diff] [blame] | 431 | if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED)) |
| 432 | { |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 433 | virtio_tx_trace (vm, node, b, bi, is_tun); |
Mohsin Kazmi | 8314371 | 2020-10-07 13:23:55 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 436 | if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0)) |
| 437 | { |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 438 | d->addr = ((is_pci) ? vlib_buffer_get_current_pa (vm, b) : |
| 439 | pointer_to_uword (vlib_buffer_get_current (b))) - hdr_sz; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 440 | d->len = b->current_length + hdr_sz; |
| 441 | d->flags = 0; |
| 442 | } |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 443 | else if (is_indirect) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 444 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 445 | /* |
| 446 | * We are using single vlib_buffer_t for indirect descriptor(s) |
| 447 | * chain. Single descriptor is 16 bytes and vlib_buffer_t |
| 448 | * has 2048 bytes space. So maximum long chain can have 128 |
| 449 | * (=2048/16) indirect descriptors. |
| 450 | * It can easily support 65535 bytes of Jumbo frames with |
| 451 | * each data buffer size of 512 bytes minimum. |
| 452 | */ |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 453 | u32 indirect_buffer = 0; |
| 454 | if (PREDICT_FALSE (vlib_buffer_alloc (vm, &indirect_buffer, 1) == 0)) |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 455 | { |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 456 | drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED; |
| 457 | goto done; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 458 | } |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 459 | |
| 460 | vlib_buffer_t *indirect_desc = vlib_get_buffer (vm, indirect_buffer); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 461 | indirect_desc->current_data = 0; |
Mohsin Kazmi | aea0df3 | 2019-05-23 14:32:58 +0200 | [diff] [blame] | 462 | indirect_desc->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 463 | indirect_desc->next_buffer = bi; |
| 464 | bi = indirect_buffer; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 465 | |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 466 | vnet_virtio_vring_desc_t *id = |
| 467 | (vnet_virtio_vring_desc_t *) vlib_buffer_get_current (indirect_desc); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 468 | u32 count = 1; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 469 | if (is_pci) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 470 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 471 | d->addr = vlib_physmem_get_pa (vm, id); |
| 472 | id->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 473 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 474 | /* |
| 475 | * If VIRTIO_F_ANY_LAYOUT is not negotiated, then virtio_net_hdr |
| 476 | * should be presented in separate descriptor and data will start |
| 477 | * from next descriptor. |
| 478 | */ |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 479 | if (is_any_layout) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 480 | id->len = b->current_length + hdr_sz; |
| 481 | else |
| 482 | { |
| 483 | id->len = hdr_sz; |
| 484 | id->flags = VRING_DESC_F_NEXT; |
| 485 | id->next = count; |
| 486 | count++; |
| 487 | id++; |
| 488 | id->addr = vlib_buffer_get_current_pa (vm, b); |
| 489 | id->len = b->current_length; |
| 490 | } |
| 491 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 492 | { |
| 493 | id->flags = VRING_DESC_F_NEXT; |
| 494 | id->next = count; |
| 495 | count++; |
| 496 | id++; |
| 497 | b = vlib_get_buffer (vm, b->next_buffer); |
| 498 | id->addr = vlib_buffer_get_current_pa (vm, b); |
| 499 | id->len = b->current_length; |
Mohsin Kazmi | 637c97c | 2021-05-12 14:51:29 +0200 | [diff] [blame] | 500 | if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN)) |
| 501 | { |
| 502 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 503 | vlib_error_count (vm, node->node_index, |
| 504 | VIRTIO_TX_ERROR_TRUNC_PACKET, 1); |
| 505 | break; |
| 506 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 507 | } |
| 508 | } |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 509 | else /* VIRTIO_IF_TYPE_[TAP | TUN] */ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 510 | { |
| 511 | d->addr = pointer_to_uword (id); |
| 512 | /* first buffer in chain */ |
| 513 | id->addr = pointer_to_uword (vlib_buffer_get_current (b)) - hdr_sz; |
| 514 | id->len = b->current_length + hdr_sz; |
| 515 | |
| 516 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 517 | { |
| 518 | id->flags = VRING_DESC_F_NEXT; |
| 519 | id->next = count; |
| 520 | count++; |
| 521 | id++; |
| 522 | b = vlib_get_buffer (vm, b->next_buffer); |
| 523 | id->addr = pointer_to_uword (vlib_buffer_get_current (b)); |
| 524 | id->len = b->current_length; |
Mohsin Kazmi | 637c97c | 2021-05-12 14:51:29 +0200 | [diff] [blame] | 525 | if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN)) |
| 526 | { |
| 527 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 528 | vlib_error_count (vm, node->node_index, |
| 529 | VIRTIO_TX_ERROR_TRUNC_PACKET, 1); |
| 530 | break; |
| 531 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | id->flags = 0; |
| 535 | id->next = 0; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 536 | d->len = count * sizeof (vnet_virtio_vring_desc_t); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 537 | d->flags = VRING_DESC_F_INDIRECT; |
| 538 | } |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 539 | else if (is_pci) |
Mohsin Kazmi | ce21599 | 2020-04-10 14:57:06 +0000 | [diff] [blame] | 540 | { |
| 541 | u16 count = next; |
| 542 | vlib_buffer_t *b_temp = b; |
| 543 | u16 n_buffers_in_chain = 1; |
| 544 | |
| 545 | /* |
| 546 | * Check the length of the chain for the required number of |
| 547 | * descriptors. Return from here, retry to get more descriptors, |
| 548 | * if chain length is greater than available descriptors. |
| 549 | */ |
| 550 | while (b_temp->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 551 | { |
| 552 | n_buffers_in_chain++; |
| 553 | b_temp = vlib_get_buffer (vm, b_temp->next_buffer); |
| 554 | } |
| 555 | |
| 556 | if (n_buffers_in_chain > free_desc_count) |
| 557 | return n_buffers_in_chain; |
| 558 | |
| 559 | d->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz; |
| 560 | d->len = b->current_length + hdr_sz; |
| 561 | |
| 562 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 563 | { |
| 564 | d->flags = VRING_DESC_F_NEXT; |
| 565 | vring->buffers[count] = bi; |
| 566 | b->flags &= |
| 567 | ~(VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID); |
| 568 | bi = b->next_buffer; |
| 569 | b->next_buffer = 0; |
| 570 | n_added++; |
| 571 | count = (count + 1) & mask; |
| 572 | d->next = count; |
| 573 | d = &vring->desc[count]; |
| 574 | b = vlib_get_buffer (vm, bi); |
| 575 | d->addr = vlib_buffer_get_current_pa (vm, b); |
| 576 | d->len = b->current_length; |
| 577 | } |
| 578 | d->flags = 0; |
| 579 | vring->buffers[count] = bi; |
| 580 | vring->avail->ring[avail & mask] = next; |
| 581 | n_added++; |
| 582 | return n_added; |
| 583 | } |
| 584 | else |
| 585 | { |
| 586 | ASSERT (0); |
| 587 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 588 | vring->buffers[next] = bi; |
| 589 | vring->avail->ring[avail & mask] = next; |
| 590 | n_added++; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 591 | |
| 592 | done: |
| 593 | if (drop_inline != ~0) |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 594 | virtio_interface_drop_inline (vm, vif, node->node_index, &bi, 1, |
| 595 | drop_inline); |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 596 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 597 | return n_added; |
| 598 | } |
| 599 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 600 | static u16 |
| 601 | add_buffer_to_slot_packed (vlib_main_t *vm, vlib_node_runtime_t *node, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 602 | virtio_if_t *vif, vnet_virtio_vring_t *vring, |
| 603 | u32 bi, u16 next, int hdr_sz, int do_gso, |
| 604 | int csum_offload, int is_pci, int is_tun, |
| 605 | int is_indirect, int is_any_layout) |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 606 | { |
| 607 | u16 n_added = 0, flags = 0; |
| 608 | int is_l2 = !is_tun; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 609 | vnet_virtio_vring_packed_desc_t *d = &vring->packed_desc[next]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 610 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 611 | vnet_virtio_net_hdr_v1_t *hdr = vlib_buffer_get_current (b) - hdr_sz; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 612 | u32 drop_inline = ~0; |
| 613 | |
| 614 | clib_memset (hdr, 0, hdr_sz); |
| 615 | |
| 616 | if (b->flags & VNET_BUFFER_F_GSO) |
| 617 | { |
| 618 | if (do_gso) |
| 619 | set_gso_offsets (b, hdr, is_l2); |
| 620 | else |
| 621 | { |
| 622 | drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP; |
| 623 | goto done; |
| 624 | } |
| 625 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 626 | else if (b->flags & VNET_BUFFER_F_OFFLOAD) |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 627 | { |
| 628 | if (csum_offload) |
| 629 | set_checksum_offsets (b, hdr, is_l2); |
| 630 | else |
| 631 | { |
| 632 | drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP; |
| 633 | goto done; |
| 634 | } |
| 635 | } |
| 636 | if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED)) |
| 637 | { |
| 638 | virtio_tx_trace (vm, node, b, bi, is_tun); |
| 639 | } |
| 640 | |
| 641 | if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0)) |
| 642 | { |
| 643 | d->addr = |
| 644 | ((is_pci) ? vlib_buffer_get_current_pa (vm, |
| 645 | b) : |
| 646 | pointer_to_uword (vlib_buffer_get_current (b))) - hdr_sz; |
| 647 | d->len = b->current_length + hdr_sz; |
| 648 | } |
| 649 | else if (is_indirect) |
| 650 | { |
| 651 | /* |
| 652 | * We are using single vlib_buffer_t for indirect descriptor(s) |
| 653 | * chain. Single descriptor is 16 bytes and vlib_buffer_t |
| 654 | * has 2048 bytes space. So maximum long chain can have 128 |
| 655 | * (=2048/16) indirect descriptors. |
| 656 | * It can easily support 65535 bytes of Jumbo frames with |
| 657 | * each data buffer size of 512 bytes minimum. |
| 658 | */ |
| 659 | u32 indirect_buffer = 0; |
| 660 | if (PREDICT_FALSE (vlib_buffer_alloc (vm, &indirect_buffer, 1) == 0)) |
| 661 | { |
| 662 | drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED; |
| 663 | goto done; |
| 664 | } |
| 665 | |
| 666 | vlib_buffer_t *indirect_desc = vlib_get_buffer (vm, indirect_buffer); |
| 667 | indirect_desc->current_data = 0; |
| 668 | indirect_desc->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 669 | indirect_desc->next_buffer = bi; |
| 670 | bi = indirect_buffer; |
| 671 | |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 672 | vnet_virtio_vring_packed_desc_t *id = |
| 673 | (vnet_virtio_vring_packed_desc_t *) vlib_buffer_get_current ( |
| 674 | indirect_desc); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 675 | u32 count = 1; |
| 676 | if (is_pci) |
| 677 | { |
| 678 | d->addr = vlib_physmem_get_pa (vm, id); |
| 679 | id->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz; |
| 680 | |
| 681 | /* |
| 682 | * If VIRTIO_F_ANY_LAYOUT is not negotiated, then virtio_net_hdr |
| 683 | * should be presented in separate descriptor and data will start |
| 684 | * from next descriptor. |
| 685 | */ |
| 686 | if (is_any_layout) |
| 687 | id->len = b->current_length + hdr_sz; |
| 688 | else |
| 689 | { |
| 690 | id->len = hdr_sz; |
| 691 | id->flags = 0; |
| 692 | id->id = 0; |
| 693 | count++; |
| 694 | id++; |
| 695 | id->addr = vlib_buffer_get_current_pa (vm, b); |
| 696 | id->len = b->current_length; |
| 697 | } |
| 698 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 699 | { |
| 700 | id->flags = 0; |
| 701 | id->id = 0; |
| 702 | count++; |
| 703 | id++; |
| 704 | b = vlib_get_buffer (vm, b->next_buffer); |
| 705 | id->addr = vlib_buffer_get_current_pa (vm, b); |
| 706 | id->len = b->current_length; |
Mohsin Kazmi | 637c97c | 2021-05-12 14:51:29 +0200 | [diff] [blame] | 707 | if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN)) |
| 708 | { |
| 709 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 710 | vlib_error_count (vm, node->node_index, |
| 711 | VIRTIO_TX_ERROR_TRUNC_PACKET, 1); |
| 712 | break; |
| 713 | } |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | id->flags = 0; |
| 717 | id->id = 0; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 718 | d->len = count * sizeof (vnet_virtio_vring_packed_desc_t); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 719 | flags = VRING_DESC_F_INDIRECT; |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | ASSERT (0); |
| 724 | } |
| 725 | if (vring->avail_wrap_counter) |
| 726 | { |
| 727 | flags |= VRING_DESC_F_AVAIL; |
| 728 | flags &= ~VRING_DESC_F_USED; |
| 729 | } |
| 730 | else |
| 731 | { |
| 732 | flags &= ~VRING_DESC_F_AVAIL; |
| 733 | flags |= VRING_DESC_F_USED; |
| 734 | } |
| 735 | |
| 736 | d->id = next; |
| 737 | d->flags = flags; |
| 738 | vring->buffers[next] = bi; |
| 739 | n_added++; |
| 740 | |
| 741 | done: |
| 742 | if (drop_inline != ~0) |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 743 | virtio_interface_drop_inline (vm, vif, node->node_index, &bi, 1, |
| 744 | drop_inline); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 745 | |
| 746 | return n_added; |
| 747 | } |
| 748 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 749 | static uword |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 750 | virtio_interface_tx_packed_gso_inline ( |
| 751 | vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif, |
| 752 | virtio_if_type_t type, vnet_virtio_vring_t *vring, u32 *buffers, u16 n_left, |
| 753 | const int do_gso, const int csum_offload) |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 754 | { |
| 755 | int is_pci = (type == VIRTIO_IF_TYPE_PCI); |
| 756 | int is_tun = (type == VIRTIO_IF_TYPE_TUN); |
| 757 | int is_indirect = |
| 758 | ((vif->features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) != 0); |
| 759 | int is_any_layout = |
| 760 | ((vif->features & VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)) != 0); |
| 761 | const int hdr_sz = vif->virtio_net_hdr_sz; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 762 | u16 sz = vring->queue_size; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 763 | u16 used, next, n_buffers = 0, n_buffers_left = 0; |
| 764 | u16 n_vectors = n_left; |
| 765 | |
| 766 | |
| 767 | used = vring->desc_in_use; |
| 768 | next = vring->desc_next; |
| 769 | |
| 770 | if (vif->packet_buffering) |
| 771 | { |
| 772 | n_buffers = n_buffers_left = virtio_vring_n_buffers (vring->buffering); |
| 773 | |
| 774 | while (n_buffers_left && used < sz) |
| 775 | { |
| 776 | u16 n_added = 0; |
| 777 | |
| 778 | u32 bi = virtio_vring_buffering_read_from_front (vring->buffering); |
| 779 | if (bi == ~0) |
| 780 | break; |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 781 | n_added = add_buffer_to_slot_packed ( |
| 782 | vm, node, vif, vring, bi, next, hdr_sz, do_gso, csum_offload, |
| 783 | is_pci, is_tun, is_indirect, is_any_layout); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 784 | n_buffers_left--; |
| 785 | if (PREDICT_FALSE (n_added == 0)) |
| 786 | continue; |
| 787 | |
| 788 | used++; |
| 789 | next++; |
| 790 | if (next >= sz) |
| 791 | { |
| 792 | next = 0; |
| 793 | vring->avail_wrap_counter ^= 1; |
| 794 | } |
| 795 | } |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 796 | virtio_txq_clear_scheduled (vring); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | while (n_left && used < sz) |
| 800 | { |
| 801 | u16 n_added = 0; |
| 802 | |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 803 | n_added = add_buffer_to_slot_packed ( |
| 804 | vm, node, vif, vring, buffers[0], next, hdr_sz, do_gso, csum_offload, |
| 805 | is_pci, is_tun, is_indirect, is_any_layout); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 806 | buffers++; |
| 807 | n_left--; |
| 808 | if (PREDICT_FALSE (n_added == 0)) |
| 809 | continue; |
| 810 | |
| 811 | used++; |
| 812 | next++; |
| 813 | if (next >= sz) |
| 814 | { |
| 815 | next = 0; |
| 816 | vring->avail_wrap_counter ^= 1; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | if (n_left != n_vectors || n_buffers != n_buffers_left) |
| 821 | { |
| 822 | CLIB_MEMORY_STORE_BARRIER (); |
| 823 | vring->desc_next = next; |
| 824 | vring->desc_in_use = used; |
| 825 | CLIB_MEMORY_BARRIER (); |
| 826 | if (vring->device_event->flags != VRING_EVENT_F_DISABLE) |
| 827 | virtio_kick (vm, vring, vif); |
| 828 | } |
| 829 | |
| 830 | return n_left; |
| 831 | } |
| 832 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 833 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 834 | virtio_find_free_desc (vnet_virtio_vring_t *vring, u16 size, u16 mask, u16 req, |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 835 | u16 next, u32 *first_free_desc_index, |
| 836 | u16 *free_desc_count) |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 837 | { |
| 838 | u16 start = 0; |
| 839 | /* next is used as hint: from where to start looking */ |
| 840 | for (u16 i = 0; i < size; i++, next++) |
| 841 | { |
| 842 | if (vring->buffers[next & mask] == ~0) |
| 843 | { |
| 844 | if (*first_free_desc_index == ~0) |
| 845 | { |
| 846 | *first_free_desc_index = (next & mask); |
| 847 | start = i; |
| 848 | (*free_desc_count)++; |
| 849 | req--; |
| 850 | if (req == 0) |
| 851 | break; |
| 852 | } |
| 853 | else |
| 854 | { |
| 855 | if (start + *free_desc_count == i) |
| 856 | { |
| 857 | (*free_desc_count)++; |
| 858 | req--; |
| 859 | if (req == 0) |
| 860 | break; |
| 861 | } |
| 862 | else |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 869 | static u16 |
| 870 | virtio_interface_tx_split_gso_inline (vlib_main_t *vm, |
| 871 | vlib_node_runtime_t *node, |
| 872 | virtio_if_t *vif, virtio_if_type_t type, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 873 | vnet_virtio_vring_t *vring, u32 *buffers, |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 874 | u16 n_left, int do_gso, int csum_offload) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 875 | { |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 876 | u16 used, next, avail, n_buffers = 0, n_buffers_left = 0; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 877 | int is_pci = (type == VIRTIO_IF_TYPE_PCI); |
| 878 | int is_tun = (type == VIRTIO_IF_TYPE_TUN); |
| 879 | int is_indirect = |
| 880 | ((vif->features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) != 0); |
| 881 | int is_any_layout = |
| 882 | ((vif->features & VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)) != 0); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 883 | u16 sz = vring->queue_size; |
Damjan Marion | d4a5471 | 2020-10-31 23:40:51 +0100 | [diff] [blame] | 884 | int hdr_sz = vif->virtio_net_hdr_sz; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 885 | u16 mask = sz - 1; |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 886 | u16 n_vectors = n_left; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 887 | |
| 888 | used = vring->desc_in_use; |
| 889 | next = vring->desc_next; |
| 890 | avail = vring->avail->idx; |
| 891 | |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 892 | u16 free_desc_count = 0; |
| 893 | |
| 894 | if (PREDICT_FALSE (vring->flags & VRING_TX_OUT_OF_ORDER)) |
| 895 | { |
| 896 | u32 first_free_desc_index = ~0; |
| 897 | |
| 898 | virtio_find_free_desc (vring, sz, mask, n_left, next, |
| 899 | &first_free_desc_index, &free_desc_count); |
| 900 | |
| 901 | if (free_desc_count) |
| 902 | next = first_free_desc_index; |
| 903 | } |
| 904 | else |
| 905 | free_desc_count = sz - used; |
| 906 | |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 907 | if (vif->packet_buffering) |
| 908 | { |
| 909 | n_buffers = n_buffers_left = virtio_vring_n_buffers (vring->buffering); |
| 910 | |
| 911 | while (n_buffers_left && free_desc_count) |
| 912 | { |
| 913 | u16 n_added = 0; |
| 914 | |
| 915 | u32 bi = virtio_vring_buffering_read_from_front (vring->buffering); |
| 916 | if (bi == ~0) |
| 917 | break; |
Mohsin Kazmi | 8314371 | 2020-10-07 13:23:55 +0200 | [diff] [blame] | 918 | |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 919 | n_added = add_buffer_to_slot (vm, node, vif, vring, bi, |
| 920 | free_desc_count, avail, next, mask, |
| 921 | hdr_sz, do_gso, csum_offload, is_pci, |
| 922 | is_tun, is_indirect, is_any_layout); |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 923 | if (PREDICT_FALSE (n_added == 0)) |
| 924 | { |
| 925 | n_buffers_left--; |
| 926 | continue; |
| 927 | } |
| 928 | else if (PREDICT_FALSE (n_added > free_desc_count)) |
| 929 | break; |
| 930 | |
| 931 | avail++; |
| 932 | next = (next + n_added) & mask; |
| 933 | used += n_added; |
| 934 | n_buffers_left--; |
| 935 | free_desc_count -= n_added; |
| 936 | } |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 937 | virtio_txq_clear_scheduled (vring); |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 940 | while (n_left && free_desc_count) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 941 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 942 | u16 n_added = 0; |
Mohsin Kazmi | b5ca559 | 2020-06-26 13:48:26 +0000 | [diff] [blame] | 943 | |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 944 | n_added = |
| 945 | add_buffer_to_slot (vm, node, vif, vring, buffers[0], free_desc_count, |
| 946 | avail, next, mask, hdr_sz, do_gso, csum_offload, |
| 947 | is_pci, is_tun, is_indirect, is_any_layout); |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 948 | |
| 949 | if (PREDICT_FALSE (n_added == 0)) |
| 950 | { |
| 951 | buffers++; |
| 952 | n_left--; |
| 953 | continue; |
| 954 | } |
Mohsin Kazmi | ce21599 | 2020-04-10 14:57:06 +0000 | [diff] [blame] | 955 | else if (PREDICT_FALSE (n_added > free_desc_count)) |
| 956 | break; |
Mohsin Kazmi | f50ef40 | 2020-04-09 22:11:29 +0200 | [diff] [blame] | 957 | |
Mohsin Kazmi | ce21599 | 2020-04-10 14:57:06 +0000 | [diff] [blame] | 958 | avail++; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 959 | next = (next + n_added) & mask; |
| 960 | used += n_added; |
| 961 | buffers++; |
| 962 | n_left--; |
Mohsin Kazmi | ce21599 | 2020-04-10 14:57:06 +0000 | [diff] [blame] | 963 | free_desc_count -= n_added; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 964 | } |
| 965 | |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 966 | if (n_left != n_vectors || n_buffers != n_buffers_left) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 967 | { |
Mohsin Kazmi | d8b7dec | 2020-12-10 09:49:21 +0000 | [diff] [blame] | 968 | clib_atomic_store_seq_cst (&vring->avail->idx, avail); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 969 | vring->desc_next = next; |
| 970 | vring->desc_in_use = used; |
Mohsin Kazmi | d8b7dec | 2020-12-10 09:49:21 +0000 | [diff] [blame] | 971 | if ((clib_atomic_load_seq_cst (&vring->used->flags) & |
| 972 | VRING_USED_F_NO_NOTIFY) == 0) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 973 | virtio_kick (vm, vring, vif); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 976 | return n_left; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 977 | } |
| 978 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 979 | static u16 |
| 980 | virtio_interface_tx_gso_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 981 | virtio_if_t *vif, virtio_if_type_t type, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 982 | vnet_virtio_vring_t *vring, u32 *buffers, |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 983 | u16 n_left, int packed, int do_gso, |
| 984 | int csum_offload) |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 985 | { |
| 986 | if (packed) |
| 987 | return virtio_interface_tx_packed_gso_inline (vm, node, vif, type, vring, |
| 988 | buffers, n_left, |
Mohsin Kazmi | b18b190 | 2020-12-03 16:35:20 +0100 | [diff] [blame] | 989 | do_gso, csum_offload); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 990 | else |
| 991 | return virtio_interface_tx_split_gso_inline (vm, node, vif, type, vring, |
| 992 | buffers, n_left, |
Mohsin Kazmi | b18b190 | 2020-12-03 16:35:20 +0100 | [diff] [blame] | 993 | do_gso, csum_offload); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 996 | static u16 |
| 997 | virtio_interface_tx_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 998 | virtio_if_t *vif, vnet_virtio_vring_t *vring, |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 999 | virtio_if_type_t type, u32 *buffers, u16 n_left, |
| 1000 | int packed) |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1001 | { |
| 1002 | vnet_main_t *vnm = vnet_get_main (); |
| 1003 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index); |
| 1004 | |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 1005 | if (hw->caps & VNET_HW_IF_CAP_TCP_GSO) |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1006 | return virtio_interface_tx_gso_inline (vm, node, vif, type, vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1007 | buffers, n_left, packed, |
| 1008 | 1 /* do_gso */ , |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1009 | 1 /* checksum offload */ ); |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 1010 | else if (hw->caps & VNET_HW_IF_CAP_L4_TX_CKSUM) |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1011 | return virtio_interface_tx_gso_inline (vm, node, vif, type, vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1012 | buffers, n_left, packed, |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1013 | 0 /* no do_gso */ , |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1014 | 1 /* checksum offload */ ); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1015 | else |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1016 | return virtio_interface_tx_gso_inline (vm, node, vif, type, vring, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1017 | buffers, n_left, packed, |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1018 | 0 /* no do_gso */ , |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1019 | 0 /* no checksum offload */ ); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
Filip Tehlar | aee7364 | 2019-03-13 05:50:44 -0700 | [diff] [blame] | 1022 | VNET_DEVICE_CLASS_TX_FN (virtio_device_class) (vlib_main_t * vm, |
| 1023 | vlib_node_runtime_t * node, |
| 1024 | vlib_frame_t * frame) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1025 | { |
| 1026 | virtio_main_t *nm = &virtio_main; |
| 1027 | vnet_interface_output_runtime_t *rund = (void *) node->runtime_data; |
| 1028 | virtio_if_t *vif = pool_elt_at_index (nm->interfaces, rund->dev_instance); |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 1029 | vnet_hw_if_tx_frame_t *tf = vlib_frame_scalar_args (frame); |
| 1030 | u16 qid = tf->queue_id; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 1031 | vnet_virtio_vring_t *vring = vec_elt_at_index (vif->txq_vrings, qid); |
Mohsin Kazmi | ee1e30f | 2020-10-23 11:23:52 +0200 | [diff] [blame] | 1032 | u16 n_left = frame->n_vectors; |
| 1033 | u32 *buffers = vlib_frame_vector_args (frame); |
| 1034 | u32 to[GRO_TO_VECTOR_SIZE (n_left)]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1035 | int packed = vif->is_packed; |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1036 | u16 n_vectors = frame->n_vectors; |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1037 | |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 1038 | if (tf->shared_queue) |
| 1039 | clib_spinlock_lock (&vring->lockp); |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1040 | |
Mohsin Kazmi | ee1e30f | 2020-10-23 11:23:52 +0200 | [diff] [blame] | 1041 | if (vif->packet_coalesce) |
| 1042 | { |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1043 | n_vectors = n_left = |
| 1044 | vnet_gro_inline (vm, vring->flow_table, buffers, n_left, to); |
Mohsin Kazmi | ee1e30f | 2020-10-23 11:23:52 +0200 | [diff] [blame] | 1045 | buffers = to; |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 1046 | virtio_txq_clear_scheduled (vring); |
Mohsin Kazmi | ee1e30f | 2020-10-23 11:23:52 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Damjan Marion | 587f913 | 2020-10-31 22:47:01 +0100 | [diff] [blame] | 1049 | u16 retry_count = 2; |
| 1050 | |
| 1051 | retry: |
| 1052 | /* free consumed buffers */ |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1053 | virtio_free_used_device_desc (vm, vring, node->node_index, packed); |
Damjan Marion | 587f913 | 2020-10-31 22:47:01 +0100 | [diff] [blame] | 1054 | |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1055 | if (vif->type == VIRTIO_IF_TYPE_TAP) |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1056 | n_left = virtio_interface_tx_inline (vm, node, vif, vring, |
Mohsin Kazmi | 81dac06 | 2020-11-11 20:28:35 +0100 | [diff] [blame] | 1057 | VIRTIO_IF_TYPE_TAP, |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1058 | &buffers[n_vectors - n_left], |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1059 | n_left, packed); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1060 | else if (vif->type == VIRTIO_IF_TYPE_PCI) |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1061 | n_left = virtio_interface_tx_inline (vm, node, vif, vring, |
Mohsin Kazmi | 81dac06 | 2020-11-11 20:28:35 +0100 | [diff] [blame] | 1062 | VIRTIO_IF_TYPE_PCI, |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1063 | &buffers[n_vectors - n_left], |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1064 | n_left, packed); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1065 | else if (vif->type == VIRTIO_IF_TYPE_TUN) |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1066 | n_left = virtio_interface_tx_inline (vm, node, vif, vring, |
Mohsin Kazmi | 81dac06 | 2020-11-11 20:28:35 +0100 | [diff] [blame] | 1067 | VIRTIO_IF_TYPE_TUN, |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1068 | &buffers[n_vectors - n_left], |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 1069 | n_left, packed); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 1070 | else |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 1071 | ASSERT (0); |
| 1072 | |
Damjan Marion | 587f913 | 2020-10-31 22:47:01 +0100 | [diff] [blame] | 1073 | if (n_left && retry_count--) |
| 1074 | goto retry; |
| 1075 | |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1076 | if (vif->packet_buffering && n_left) |
| 1077 | { |
Mohsin Kazmi | 81dac06 | 2020-11-11 20:28:35 +0100 | [diff] [blame] | 1078 | u16 n_buffered = virtio_vring_buffering_store_packets (vring->buffering, |
| 1079 | &buffers |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1080 | [n_vectors |
Mohsin Kazmi | 81dac06 | 2020-11-11 20:28:35 +0100 | [diff] [blame] | 1081 | - n_left], |
| 1082 | n_left); |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1083 | n_left -= n_buffered; |
| 1084 | } |
| 1085 | if (n_left) |
Mohsin Kazmi | a02ad34 | 2021-05-04 16:36:09 +0200 | [diff] [blame] | 1086 | virtio_interface_drop_inline (vm, vif, node->node_index, |
Mohsin Kazmi | e2e9fe5 | 2020-12-17 15:54:03 +0100 | [diff] [blame] | 1087 | &buffers[n_vectors - n_left], n_left, |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1088 | VIRTIO_TX_ERROR_NO_FREE_SLOTS); |
| 1089 | |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 1090 | if (tf->shared_queue) |
| 1091 | clib_spinlock_unlock (&vring->lockp); |
Damjan Marion | dc18124 | 2020-10-20 12:11:06 +0200 | [diff] [blame] | 1092 | |
Mohsin Kazmi | 2e6f624 | 2020-10-26 12:41:41 +0100 | [diff] [blame] | 1093 | return frame->n_vectors - n_left; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | virtio_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index, |
| 1098 | u32 node_index) |
| 1099 | { |
| 1100 | virtio_main_t *apm = &virtio_main; |
| 1101 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1102 | virtio_if_t *vif = pool_elt_at_index (apm->interfaces, hw->dev_instance); |
| 1103 | |
| 1104 | /* Shut off redirection */ |
| 1105 | if (node_index == ~0) |
| 1106 | { |
| 1107 | vif->per_interface_next_index = node_index; |
| 1108 | return; |
| 1109 | } |
| 1110 | |
| 1111 | vif->per_interface_next_index = |
| 1112 | vlib_node_add_next (vlib_get_main (), virtio_input_node.index, |
| 1113 | node_index); |
| 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | virtio_clear_hw_interface_counters (u32 instance) |
| 1118 | { |
| 1119 | /* Nothing for now */ |
| 1120 | } |
| 1121 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 1122 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 1123 | virtio_set_rx_interrupt (virtio_if_t *vif, vnet_virtio_vring_t *vring) |
Mohsin Kazmi | 2484186 | 2020-12-02 16:39:42 +0100 | [diff] [blame] | 1124 | { |
| 1125 | if (vif->is_packed) |
| 1126 | vring->driver_event->flags &= ~VRING_EVENT_F_DISABLE; |
| 1127 | else |
| 1128 | vring->avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT; |
| 1129 | } |
| 1130 | |
Damjan Marion | 809d5c9 | 2021-03-24 12:24:58 +0100 | [diff] [blame] | 1131 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 1132 | virtio_set_rx_polling (virtio_if_t *vif, vnet_virtio_vring_t *vring) |
Mohsin Kazmi | 2484186 | 2020-12-02 16:39:42 +0100 | [diff] [blame] | 1133 | { |
| 1134 | if (vif->is_packed) |
| 1135 | vring->driver_event->flags |= VRING_EVENT_F_DISABLE; |
| 1136 | else |
| 1137 | vring->avail->flags |= VRING_AVAIL_F_NO_INTERRUPT; |
| 1138 | } |
| 1139 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1140 | static clib_error_t * |
| 1141 | virtio_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid, |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1142 | vnet_hw_if_rx_mode mode) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1143 | { |
| 1144 | virtio_main_t *mm = &virtio_main; |
| 1145 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1146 | virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 1147 | vnet_virtio_vring_t *rx_vring = vec_elt_at_index (vif->rxq_vrings, qid); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1148 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1149 | if (vif->type == VIRTIO_IF_TYPE_PCI && !(vif->support_int_mode)) |
| 1150 | { |
Mohsin Kazmi | 2484186 | 2020-12-02 16:39:42 +0100 | [diff] [blame] | 1151 | virtio_set_rx_polling (vif, rx_vring); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1152 | return clib_error_return (0, "interrupt mode is not supported"); |
| 1153 | } |
| 1154 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1155 | if (mode == VNET_HW_IF_RX_MODE_POLLING) |
Mohsin Kazmi | 2484186 | 2020-12-02 16:39:42 +0100 | [diff] [blame] | 1156 | virtio_set_rx_polling (vif, rx_vring); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1157 | else |
Mohsin Kazmi | 2484186 | 2020-12-02 16:39:42 +0100 | [diff] [blame] | 1158 | virtio_set_rx_interrupt (vif, rx_vring); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1159 | |
Mohsin Kazmi | a5203b5 | 2020-10-12 13:01:24 +0200 | [diff] [blame] | 1160 | rx_vring->mode = mode; |
| 1161 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static clib_error_t * |
| 1166 | virtio_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) |
| 1167 | { |
| 1168 | virtio_main_t *mm = &virtio_main; |
| 1169 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1170 | virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1171 | |
| 1172 | if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) |
Mohsin Kazmi | 529f0e9 | 2020-03-19 14:03:31 +0100 | [diff] [blame] | 1173 | { |
| 1174 | vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; |
| 1175 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, |
| 1176 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 1177 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1178 | else |
Mohsin Kazmi | 529f0e9 | 2020-03-19 14:03:31 +0100 | [diff] [blame] | 1179 | { |
| 1180 | vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP; |
| 1181 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); |
| 1182 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | static clib_error_t * |
| 1187 | virtio_subif_add_del_function (vnet_main_t * vnm, |
| 1188 | u32 hw_if_index, |
| 1189 | struct vnet_sw_interface_t *st, int is_add) |
| 1190 | { |
| 1191 | /* Nothing for now */ |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | /* *INDENT-OFF* */ |
| 1196 | VNET_DEVICE_CLASS (virtio_device_class) = { |
| 1197 | .name = "virtio", |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1198 | .format_device_name = format_virtio_device_name, |
| 1199 | .format_device = format_virtio_device, |
| 1200 | .format_tx_trace = format_virtio_tx_trace, |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1201 | .tx_function_n_errors = VIRTIO_TX_N_ERROR, |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1202 | .tx_function_error_strings = virtio_tx_func_error_strings, |
| 1203 | .rx_redirect_to_node = virtio_set_interface_next_node, |
| 1204 | .clear_counters = virtio_clear_hw_interface_counters, |
| 1205 | .admin_up_down_function = virtio_interface_admin_up_down, |
| 1206 | .subif_add_del_function = virtio_subif_add_del_function, |
| 1207 | .rx_mode_change_function = virtio_interface_rx_mode_change, |
| 1208 | }; |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 1209 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1210 | /* *INDENT-ON* */ |
| 1211 | |
| 1212 | /* |
| 1213 | * fd.io coding-style-patch-verification: ON |
| 1214 | * |
| 1215 | * Local Variables: |
| 1216 | * eval: (c-set-style "gnu") |
| 1217 | * End: |
| 1218 | */ |