blob: 2063865f8abb549de4d8dd24fd6557040163e89e [file] [log] [blame]
Damjan Marion8389fb92017-10-13 18:29:53 +02001/*
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 Marion8389fb92017-10-13 18:29:53 +020021
22#include <vlib/vlib.h>
23#include <vlib/unix/unix.h>
Mohsin Kazmi206acf82020-04-06 14:19:54 +020024#include <vnet/vnet.h>
Damjan Marion8389fb92017-10-13 18:29:53 +020025#include <vnet/ethernet/ethernet.h>
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +020026#include <vnet/gso/gro_func.h>
Mohsin Kazmi0b042092020-04-17 16:50:56 +000027#include <vnet/gso/hdr_offset_parser.h>
Milan Lenco73e7f422017-12-14 10:04:25 +010028#include <vnet/ip/ip4_packet.h>
29#include <vnet/ip/ip6_packet.h>
Mohsin Kazmif5462362021-02-23 15:55:04 +010030#include <vnet/ip/ip_psh_cksum.h>
Mohsin Kazmi6d4af892020-01-03 15:11:53 +000031#include <vnet/tcp/tcp_packet.h>
32#include <vnet/udp/udp_packet.h>
Damjan Marion8389fb92017-10-13 18:29:53 +020033#include <vnet/devices/virtio/virtio.h>
34
Mohsin Kazmi637c97c2021-05-12 14:51:29 +020035#define VIRTIO_TX_MAX_CHAIN_LEN 127
36
Damjan Marion8389fb92017-10-13 18:29:53 +020037#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 Kazmif50ef402020-04-09 22:11:29 +020041_(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 Marion8389fb92017-10-13 18:29:53 +020045
46typedef enum
47{
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020048#define _(f,s) VIRTIO_TX_ERROR_##f,
Damjan Marion8389fb92017-10-13 18:29:53 +020049 foreach_virtio_tx_func_error
50#undef _
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020051 VIRTIO_TX_N_ERROR,
Damjan Marion8389fb92017-10-13 18:29:53 +020052} virtio_tx_func_error_t;
53
54static char *virtio_tx_func_error_strings[] = {
55#define _(n,s) s,
56 foreach_virtio_tx_func_error
57#undef _
58};
59
Damjan Marion8389fb92017-10-13 18:29:53 +020060static u8 *
61format_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);
Mohsin Kazmidd0144a2022-09-14 11:25:54 +000066 virtio_main_t *vim = &virtio_main;
67 virtio_if_t *vif = vec_elt_at_index (vim->interfaces, dev_instance);
68 vnet_virtio_vring_t *vring = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +020069
70 s = format (s, "VIRTIO interface");
71 if (verbose)
72 {
73 s = format (s, "\n%U instance %u", format_white_space, indent + 2,
74 dev_instance);
Mohsin Kazmidd0144a2022-09-14 11:25:54 +000075 s = format (s, "\n%U RX QUEUE : Total Packets", format_white_space,
76 indent + 4);
77 vec_foreach (vring, vif->rxq_vrings)
78 {
79 s = format (s, "\n%U %8u : %llu", format_white_space, indent + 4,
80 RX_QUEUE_ACCESS (vring->queue_id), vring->total_packets);
81 }
82 s = format (s, "\n%U TX QUEUE : Total Packets", format_white_space,
83 indent + 4);
84 vec_foreach (vring, vif->txq_vrings)
85 {
86 s = format (s, "\n%U %8u : %llu", format_white_space, indent + 4,
87 TX_QUEUE_ACCESS (vring->queue_id), vring->total_packets);
88 }
Damjan Marion8389fb92017-10-13 18:29:53 +020089 }
Mohsin Kazmidd0144a2022-09-14 11:25:54 +000090
Damjan Marion8389fb92017-10-13 18:29:53 +020091 return s;
92}
93
Mohsin Kazmib5ca5592020-06-26 13:48:26 +000094typedef struct
Damjan Marion8389fb92017-10-13 18:29:53 +020095{
Mohsin Kazmib5ca5592020-06-26 13:48:26 +000096 u32 buffer_index;
97 u32 sw_if_index;
Mohsin Kazmib5ca5592020-06-26 13:48:26 +000098 generic_header_offset_t gho;
Damjan Marion8c698872020-10-10 19:17:58 +020099 vlib_buffer_t buffer;
Mohsin Kazmib5ca5592020-06-26 13:48:26 +0000100} virtio_tx_trace_t;
101
102static u8 *
103format_virtio_tx_trace (u8 * s, va_list * va)
104{
105 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
106 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
107 virtio_tx_trace_t *t = va_arg (*va, virtio_tx_trace_t *);
108 u32 indent = format_get_indent (s);
109
BenoƮt Ganne03f2a012021-07-20 16:49:13 +0200110 s = format (s, "%Ubuffer 0x%x: %U\n", format_white_space, indent,
111 t->buffer_index, format_vnet_buffer_no_chain, &t->buffer);
Mohsin Kazmib3a8f4e2020-09-15 16:41:44 +0000112 s =
113 format (s, "%U%U\n", format_white_space, indent,
114 format_generic_header_offset, &t->gho);
115 s =
116 format (s, "%U%U", format_white_space, indent,
117 format_ethernet_header_with_length, t->buffer.pre_data,
118 sizeof (t->buffer.pre_data));
Damjan Marion8389fb92017-10-13 18:29:53 +0200119 return s;
120}
121
Damjan Marion809d5c92021-03-24 12:24:58 +0100122static void
123virtio_tx_trace (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0,
124 u32 bi, int is_tun)
Mohsin Kazmi03b26952020-09-16 16:53:16 +0000125{
126 virtio_tx_trace_t *t;
127 t = vlib_add_trace (vm, node, b0, sizeof (t[0]));
128 t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
129 t->buffer_index = bi;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500130 clib_memset (&t->gho, 0, sizeof (t->gho));
Damjan Mariond4a54712020-10-31 23:40:51 +0100131 if (is_tun)
Mohsin Kazmi03b26952020-09-16 16:53:16 +0000132 {
133 int is_ip4 = 0, is_ip6 = 0;
134
135 switch (((u8 *) vlib_buffer_get_current (b0))[0] & 0xf0)
136 {
137 case 0x40:
138 is_ip4 = 1;
139 break;
140 case 0x60:
141 is_ip6 = 1;
142 break;
143 default:
144 break;
145 }
146 vnet_generic_header_offset_parser (b0, &t->gho, 0, is_ip4, is_ip6);
147 }
148 else
149 vnet_generic_header_offset_parser (b0, &t->gho, 1,
150 b0->flags &
151 VNET_BUFFER_F_IS_IP4,
152 b0->flags & VNET_BUFFER_F_IS_IP6);
153
154 clib_memcpy_fast (&t->buffer, b0, sizeof (*b0) - sizeof (b0->pre_data));
155 clib_memcpy_fast (t->buffer.pre_data, vlib_buffer_get_current (b0),
156 sizeof (t->buffer.pre_data));
157}
158
Damjan Marion809d5c92021-03-24 12:24:58 +0100159static void
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200160virtio_interface_drop_inline (vlib_main_t *vm, virtio_if_t *vif,
161 uword node_index, u32 *buffers, u16 n,
162 virtio_tx_func_error_t error)
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200163{
164 vlib_error_count (vm, node_index, error, n);
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200165 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters +
166 VNET_INTERFACE_COUNTER_DROP,
167 vm->thread_index, vif->sw_if_index, n);
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200168 vlib_buffer_free (vm, buffers, n);
169}
170
Damjan Marion809d5c92021-03-24 12:24:58 +0100171static void
172virtio_memset_ring_u32 (u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100173{
174 ASSERT (n_buffers <= ring_size);
175
176 if (PREDICT_TRUE (start + n_buffers <= ring_size))
177 {
178 clib_memset_u32 (ring + start, ~0, n_buffers);
179 }
180 else
181 {
182 clib_memset_u32 (ring + start, ~0, ring_size - start);
183 clib_memset_u32 (ring, ~0, n_buffers - (ring_size - start));
184 }
185}
186
Damjan Marion809d5c92021-03-24 12:24:58 +0100187static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000188virtio_free_used_device_desc_split (vlib_main_t *vm,
189 vnet_virtio_vring_t *vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100190 uword node_index)
Damjan Marion8389fb92017-10-13 18:29:53 +0200191{
192 u16 used = vring->desc_in_use;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000193 u16 sz = vring->queue_size;
Damjan Marion8389fb92017-10-13 18:29:53 +0200194 u16 mask = sz - 1;
195 u16 last = vring->last_used_idx;
196 u16 n_left = vring->used->idx - last;
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100197 u16 out_of_order_count = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +0200198
199 if (n_left == 0)
200 return;
201
202 while (n_left)
203 {
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000204 vnet_virtio_vring_used_elem_t *e = &vring->used->ring[last & mask];
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200205 u16 slot, n_buffers;
206 slot = n_buffers = e->id;
Damjan Marion8389fb92017-10-13 18:29:53 +0200207
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100208 while (e->id == (n_buffers & mask))
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200209 {
210 n_left--;
211 last++;
212 n_buffers++;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000213 vnet_virtio_vring_desc_t *d = &vring->desc[e->id];
Mohsin Kazmice215992020-04-10 14:57:06 +0000214 u16 next;
215 while (d->flags & VRING_DESC_F_NEXT)
216 {
217 n_buffers++;
218 next = d->next;
219 d = &vring->desc[next];
220 }
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200221 if (n_left == 0)
222 break;
223 e = &vring->used->ring[last & mask];
224 }
225 vlib_buffer_free_from_ring (vm, vring->buffers, slot,
226 sz, (n_buffers - slot));
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100227 virtio_memset_ring_u32 (vring->buffers, slot, sz, (n_buffers - slot));
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200228 used -= (n_buffers - slot);
229
230 if (n_left > 0)
231 {
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100232 vlib_buffer_free (vm, &vring->buffers[e->id], 1);
233 vring->buffers[e->id] = ~0;
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200234 used--;
235 last++;
236 n_left--;
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100237 out_of_order_count++;
238 vring->flags |= VRING_TX_OUT_OF_ORDER;
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200239 }
Damjan Marion8389fb92017-10-13 18:29:53 +0200240 }
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100241
242 /*
243 * Some vhost-backends give buffers back in out-of-order fashion in used ring.
244 * It impacts the overall virtio-performance.
245 */
246 if (out_of_order_count)
247 vlib_error_count (vm, node_index, VIRTIO_TX_ERROR_OUT_OF_ORDER,
248 out_of_order_count);
249
Damjan Marion8389fb92017-10-13 18:29:53 +0200250 vring->desc_in_use = used;
251 vring->last_used_idx = last;
252}
253
Damjan Marion809d5c92021-03-24 12:24:58 +0100254static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000255virtio_free_used_device_desc_packed (vlib_main_t *vm,
256 vnet_virtio_vring_t *vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100257 uword node_index)
258{
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000259 vnet_virtio_vring_packed_desc_t *d;
260 u16 sz = vring->queue_size;
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100261 u16 last = vring->last_used_idx;
262 u16 n_buffers = 0, start;
263 u16 flags;
264
265 if (vring->desc_in_use == 0)
266 return;
267
268 d = &vring->packed_desc[last];
269 flags = d->flags;
270 start = d->id;
271
272 while ((flags & VRING_DESC_F_AVAIL) == (vring->used_wrap_counter << 7) &&
273 (flags & VRING_DESC_F_USED) == (vring->used_wrap_counter << 15))
274 {
275 last++;
276 n_buffers++;
277
278 if (last >= sz)
279 {
280 last = 0;
281 vring->used_wrap_counter ^= 1;
282 }
283 d = &vring->packed_desc[last];
284 flags = d->flags;
285 }
286
287 if (n_buffers)
288 {
289 vlib_buffer_free_from_ring (vm, vring->buffers, start, sz, n_buffers);
290 virtio_memset_ring_u32 (vring->buffers, start, sz, n_buffers);
291 vring->desc_in_use -= n_buffers;
292 vring->last_used_idx = last;
293 }
294}
295
Damjan Marion809d5c92021-03-24 12:24:58 +0100296static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000297virtio_free_used_device_desc (vlib_main_t *vm, vnet_virtio_vring_t *vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100298 uword node_index, int packed)
299{
300 if (packed)
301 virtio_free_used_device_desc_packed (vm, vring, node_index);
302 else
303 virtio_free_used_device_desc_split (vm, vring, node_index);
304
305}
306
Damjan Marion809d5c92021-03-24 12:24:58 +0100307static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000308set_checksum_offsets (vlib_buffer_t *b, vnet_virtio_net_hdr_v1_t *hdr,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100309 const int is_l2)
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000310{
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +0200311 vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags;
Mohsin Kazmi5efc0cd2022-10-25 19:27:08 +0000312 i16 l4_hdr_offset = vnet_buffer (b)->l4_hdr_offset - b->current_data;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000313 if (b->flags & VNET_BUFFER_F_IS_IP4)
314 {
315 ip4_header_t *ip4;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000316 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000317 hdr->csum_start = l4_hdr_offset; // 0x22;
Mohsin Kazmif5462362021-02-23 15:55:04 +0100318
319 /*
320 * virtio devices do not support IP4 checksum offload. So driver takes
321 * care of it while doing tx.
322 */
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000323 ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100324 if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
325 ip4->checksum = ip4_header_checksum (ip4);
326
327 /*
328 * virtio devices assume the l4 header is set to the checksum of the
329 * l3 pseudo-header, so we compute it before tx-ing
330 */
Mohsin Kazmi68095382021-02-10 11:26:24 +0100331 if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000332 {
Mohsin Kazmif5462362021-02-23 15:55:04 +0100333 tcp_header_t *tcp =
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000334 (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100335 tcp->checksum = ip4_pseudo_header_cksum (ip4);
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000336 hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
337 }
Mohsin Kazmi68095382021-02-10 11:26:24 +0100338 else if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000339 {
Mohsin Kazmif5462362021-02-23 15:55:04 +0100340 udp_header_t *udp =
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000341 (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100342 udp->checksum = ip4_pseudo_header_cksum (ip4);
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000343 hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
344 }
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000345 }
346 else if (b->flags & VNET_BUFFER_F_IS_IP6)
347 {
Mohsin Kazmif5462362021-02-23 15:55:04 +0100348 ip6_header_t *ip6;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000349 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000350 hdr->csum_start = l4_hdr_offset; // 0x36;
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000351 ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100352
353 /*
354 * virtio devices assume the l4 header is set to the checksum of the
355 * l3 pseudo-header, so we compute it before tx-ing
356 */
Mohsin Kazmi68095382021-02-10 11:26:24 +0100357 if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000358 {
Mohsin Kazmif5462362021-02-23 15:55:04 +0100359 tcp_header_t *tcp =
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000360 (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100361 tcp->checksum = ip6_pseudo_header_cksum (ip6);
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000362 hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
363 }
Mohsin Kazmi68095382021-02-10 11:26:24 +0100364 else if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000365 {
Mohsin Kazmif5462362021-02-23 15:55:04 +0100366 udp_header_t *udp =
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000367 (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
Mohsin Kazmif5462362021-02-23 15:55:04 +0100368 udp->checksum = ip6_pseudo_header_cksum (ip6);
Mohsin Kazmi0937fdf2020-03-25 20:37:16 +0000369 hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
370 }
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000371 }
372}
373
Damjan Marion809d5c92021-03-24 12:24:58 +0100374static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000375set_gso_offsets (vlib_buffer_t *b, vnet_virtio_net_hdr_v1_t *hdr,
376 const int is_l2)
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200377{
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +0200378 vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags;
Mohsin Kazmi5efc0cd2022-10-25 19:27:08 +0000379 i16 l4_hdr_offset = vnet_buffer (b)->l4_hdr_offset - b->current_data;
Mohsin Kazmi68095382021-02-10 11:26:24 +0100380
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200381 if (b->flags & VNET_BUFFER_F_IS_IP4)
382 {
383 ip4_header_t *ip4;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200384 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
385 hdr->gso_size = vnet_buffer2 (b)->gso_size;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000386 hdr->hdr_len = l4_hdr_offset + vnet_buffer2 (b)->gso_l4_hdr_sz;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200387 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000388 hdr->csum_start = l4_hdr_offset; // 0x22;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200389 hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
Mohsin Kazmi096c8cc2022-05-18 16:51:57 +0000390 ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200391 /*
392 * virtio devices do not support IP4 checksum offload. So driver takes care
393 * of it while doing tx.
394 */
Mohsin Kazmi68095382021-02-10 11:26:24 +0100395 if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200396 ip4->checksum = ip4_header_checksum (ip4);
397 }
398 else if (b->flags & VNET_BUFFER_F_IS_IP6)
399 {
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200400 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
401 hdr->gso_size = vnet_buffer2 (b)->gso_size;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000402 hdr->hdr_len = l4_hdr_offset + vnet_buffer2 (b)->gso_l4_hdr_sz;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200403 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
Mohsin Kazmi1cc592b2022-10-17 18:16:57 +0000404 hdr->csum_start = l4_hdr_offset; // 0x36;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200405 hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
406 }
407}
408
Damjan Marion809d5c92021-03-24 12:24:58 +0100409static u16
410add_buffer_to_slot (vlib_main_t *vm, vlib_node_runtime_t *node,
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000411 virtio_if_t *vif, vnet_virtio_vring_t *vring, u32 bi,
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200412 u16 free_desc_count, u16 avail, u16 next, u16 mask,
413 int hdr_sz, int do_gso, int csum_offload, int is_pci,
414 int is_tun, int is_indirect, int is_any_layout)
Damjan Marion8389fb92017-10-13 18:29:53 +0200415{
416 u16 n_added = 0;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000417 vnet_virtio_vring_desc_t *d;
Damjan Mariond4a54712020-10-31 23:40:51 +0100418 int is_l2 = !is_tun;
Damjan Marion8389fb92017-10-13 18:29:53 +0200419 d = &vring->desc[next];
420 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000421 vnet_virtio_net_hdr_v1_t *hdr = vlib_buffer_get_current (b) - hdr_sz;
Damjan Mariond4a54712020-10-31 23:40:51 +0100422 u32 drop_inline = ~0;
Damjan Marion508cabc2018-02-08 19:49:22 +0100423
Damjan Mariond4a54712020-10-31 23:40:51 +0100424 clib_memset_u8 (hdr, 0, hdr_sz);
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000425
Mohsin Kazmidd0144a2022-09-14 11:25:54 +0000426 vring->total_packets++;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200427 if (b->flags & VNET_BUFFER_F_GSO)
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +0200428 {
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200429 if (do_gso)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200430 set_gso_offsets (b, hdr, is_l2);
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200431 else
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +0200432 {
Damjan Mariond4a54712020-10-31 23:40:51 +0100433 drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP;
434 goto done;
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +0200435 }
436 }
Mohsin Kazmi68095382021-02-10 11:26:24 +0100437 else if (b->flags & VNET_BUFFER_F_OFFLOAD)
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000438 {
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200439 if (csum_offload)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200440 set_checksum_offsets (b, hdr, is_l2);
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200441 else
442 {
Damjan Mariond4a54712020-10-31 23:40:51 +0100443 drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP;
444 goto done;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200445 }
Mohsin Kazmi6d4af892020-01-03 15:11:53 +0000446 }
Damjan Marion8389fb92017-10-13 18:29:53 +0200447
Mohsin Kazmi83143712020-10-07 13:23:55 +0200448 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
449 {
Damjan Mariond4a54712020-10-31 23:40:51 +0100450 virtio_tx_trace (vm, node, b, bi, is_tun);
Mohsin Kazmi83143712020-10-07 13:23:55 +0200451 }
452
Damjan Marion8389fb92017-10-13 18:29:53 +0200453 if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0))
454 {
Damjan Mariond4a54712020-10-31 23:40:51 +0100455 d->addr = ((is_pci) ? vlib_buffer_get_current_pa (vm, b) :
456 pointer_to_uword (vlib_buffer_get_current (b))) - hdr_sz;
Damjan Marion8389fb92017-10-13 18:29:53 +0200457 d->len = b->current_length + hdr_sz;
458 d->flags = 0;
459 }
Damjan Mariond4a54712020-10-31 23:40:51 +0100460 else if (is_indirect)
Damjan Marion8389fb92017-10-13 18:29:53 +0200461 {
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200462 /*
463 * We are using single vlib_buffer_t for indirect descriptor(s)
464 * chain. Single descriptor is 16 bytes and vlib_buffer_t
465 * has 2048 bytes space. So maximum long chain can have 128
466 * (=2048/16) indirect descriptors.
467 * It can easily support 65535 bytes of Jumbo frames with
468 * each data buffer size of 512 bytes minimum.
469 */
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200470 u32 indirect_buffer = 0;
471 if (PREDICT_FALSE (vlib_buffer_alloc (vm, &indirect_buffer, 1) == 0))
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200472 {
Damjan Mariond4a54712020-10-31 23:40:51 +0100473 drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED;
474 goto done;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200475 }
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200476
477 vlib_buffer_t *indirect_desc = vlib_get_buffer (vm, indirect_buffer);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200478 indirect_desc->current_data = 0;
Mohsin Kazmiaea0df32019-05-23 14:32:58 +0200479 indirect_desc->flags |= VLIB_BUFFER_NEXT_PRESENT;
480 indirect_desc->next_buffer = bi;
481 bi = indirect_buffer;
Damjan Marion8389fb92017-10-13 18:29:53 +0200482
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000483 vnet_virtio_vring_desc_t *id =
484 (vnet_virtio_vring_desc_t *) vlib_buffer_get_current (indirect_desc);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200485 u32 count = 1;
Damjan Mariond4a54712020-10-31 23:40:51 +0100486 if (is_pci)
Damjan Marion8389fb92017-10-13 18:29:53 +0200487 {
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200488 d->addr = vlib_physmem_get_pa (vm, id);
489 id->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz;
Damjan Marion8389fb92017-10-13 18:29:53 +0200490
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200491 /*
492 * If VIRTIO_F_ANY_LAYOUT is not negotiated, then virtio_net_hdr
493 * should be presented in separate descriptor and data will start
494 * from next descriptor.
495 */
Damjan Mariond4a54712020-10-31 23:40:51 +0100496 if (is_any_layout)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200497 id->len = b->current_length + hdr_sz;
498 else
499 {
500 id->len = hdr_sz;
501 id->flags = VRING_DESC_F_NEXT;
502 id->next = count;
503 count++;
504 id++;
505 id->addr = vlib_buffer_get_current_pa (vm, b);
506 id->len = b->current_length;
507 }
508 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
509 {
510 id->flags = VRING_DESC_F_NEXT;
511 id->next = count;
512 count++;
513 id++;
514 b = vlib_get_buffer (vm, b->next_buffer);
515 id->addr = vlib_buffer_get_current_pa (vm, b);
516 id->len = b->current_length;
Mohsin Kazmi637c97c2021-05-12 14:51:29 +0200517 if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN))
518 {
519 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
520 vlib_error_count (vm, node->node_index,
521 VIRTIO_TX_ERROR_TRUNC_PACKET, 1);
522 break;
523 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200524 }
525 }
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200526 else /* VIRTIO_IF_TYPE_[TAP | TUN] */
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200527 {
528 d->addr = pointer_to_uword (id);
529 /* first buffer in chain */
530 id->addr = pointer_to_uword (vlib_buffer_get_current (b)) - hdr_sz;
531 id->len = b->current_length + hdr_sz;
532
533 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
534 {
535 id->flags = VRING_DESC_F_NEXT;
536 id->next = count;
537 count++;
538 id++;
539 b = vlib_get_buffer (vm, b->next_buffer);
540 id->addr = pointer_to_uword (vlib_buffer_get_current (b));
541 id->len = b->current_length;
Mohsin Kazmi637c97c2021-05-12 14:51:29 +0200542 if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN))
543 {
544 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
545 vlib_error_count (vm, node->node_index,
546 VIRTIO_TX_ERROR_TRUNC_PACKET, 1);
547 break;
548 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200549 }
550 }
551 id->flags = 0;
552 id->next = 0;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000553 d->len = count * sizeof (vnet_virtio_vring_desc_t);
Damjan Marion8389fb92017-10-13 18:29:53 +0200554 d->flags = VRING_DESC_F_INDIRECT;
555 }
Damjan Mariond4a54712020-10-31 23:40:51 +0100556 else if (is_pci)
Mohsin Kazmice215992020-04-10 14:57:06 +0000557 {
558 u16 count = next;
559 vlib_buffer_t *b_temp = b;
560 u16 n_buffers_in_chain = 1;
561
562 /*
563 * Check the length of the chain for the required number of
564 * descriptors. Return from here, retry to get more descriptors,
565 * if chain length is greater than available descriptors.
566 */
567 while (b_temp->flags & VLIB_BUFFER_NEXT_PRESENT)
568 {
569 n_buffers_in_chain++;
570 b_temp = vlib_get_buffer (vm, b_temp->next_buffer);
571 }
572
573 if (n_buffers_in_chain > free_desc_count)
574 return n_buffers_in_chain;
575
576 d->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz;
577 d->len = b->current_length + hdr_sz;
578
579 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
580 {
581 d->flags = VRING_DESC_F_NEXT;
582 vring->buffers[count] = bi;
583 b->flags &=
584 ~(VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID);
585 bi = b->next_buffer;
586 b->next_buffer = 0;
587 n_added++;
588 count = (count + 1) & mask;
589 d->next = count;
590 d = &vring->desc[count];
591 b = vlib_get_buffer (vm, bi);
592 d->addr = vlib_buffer_get_current_pa (vm, b);
593 d->len = b->current_length;
594 }
595 d->flags = 0;
596 vring->buffers[count] = bi;
597 vring->avail->ring[avail & mask] = next;
598 n_added++;
599 return n_added;
600 }
601 else
602 {
603 ASSERT (0);
604 }
Damjan Marion8389fb92017-10-13 18:29:53 +0200605 vring->buffers[next] = bi;
606 vring->avail->ring[avail & mask] = next;
607 n_added++;
Damjan Mariond4a54712020-10-31 23:40:51 +0100608
609done:
610 if (drop_inline != ~0)
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200611 virtio_interface_drop_inline (vm, vif, node->node_index, &bi, 1,
612 drop_inline);
Damjan Mariond4a54712020-10-31 23:40:51 +0100613
Damjan Marion8389fb92017-10-13 18:29:53 +0200614 return n_added;
615}
616
Damjan Marion809d5c92021-03-24 12:24:58 +0100617static u16
618add_buffer_to_slot_packed (vlib_main_t *vm, vlib_node_runtime_t *node,
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000619 virtio_if_t *vif, vnet_virtio_vring_t *vring,
620 u32 bi, u16 next, int hdr_sz, int do_gso,
621 int csum_offload, int is_pci, int is_tun,
622 int is_indirect, int is_any_layout)
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100623{
624 u16 n_added = 0, flags = 0;
625 int is_l2 = !is_tun;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000626 vnet_virtio_vring_packed_desc_t *d = &vring->packed_desc[next];
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100627 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000628 vnet_virtio_net_hdr_v1_t *hdr = vlib_buffer_get_current (b) - hdr_sz;
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100629 u32 drop_inline = ~0;
630
631 clib_memset (hdr, 0, hdr_sz);
632
Mohsin Kazmidd0144a2022-09-14 11:25:54 +0000633 vring->total_packets++;
634
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100635 if (b->flags & VNET_BUFFER_F_GSO)
636 {
637 if (do_gso)
638 set_gso_offsets (b, hdr, is_l2);
639 else
640 {
641 drop_inline = VIRTIO_TX_ERROR_GSO_PACKET_DROP;
642 goto done;
643 }
644 }
Mohsin Kazmi68095382021-02-10 11:26:24 +0100645 else if (b->flags & VNET_BUFFER_F_OFFLOAD)
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100646 {
647 if (csum_offload)
648 set_checksum_offsets (b, hdr, is_l2);
649 else
650 {
651 drop_inline = VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP;
652 goto done;
653 }
654 }
655 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
656 {
657 virtio_tx_trace (vm, node, b, bi, is_tun);
658 }
659
660 if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0))
661 {
662 d->addr =
663 ((is_pci) ? vlib_buffer_get_current_pa (vm,
664 b) :
665 pointer_to_uword (vlib_buffer_get_current (b))) - hdr_sz;
666 d->len = b->current_length + hdr_sz;
667 }
668 else if (is_indirect)
669 {
670 /*
671 * We are using single vlib_buffer_t for indirect descriptor(s)
672 * chain. Single descriptor is 16 bytes and vlib_buffer_t
673 * has 2048 bytes space. So maximum long chain can have 128
674 * (=2048/16) indirect descriptors.
675 * It can easily support 65535 bytes of Jumbo frames with
676 * each data buffer size of 512 bytes minimum.
677 */
678 u32 indirect_buffer = 0;
679 if (PREDICT_FALSE (vlib_buffer_alloc (vm, &indirect_buffer, 1) == 0))
680 {
681 drop_inline = VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED;
682 goto done;
683 }
684
685 vlib_buffer_t *indirect_desc = vlib_get_buffer (vm, indirect_buffer);
686 indirect_desc->current_data = 0;
687 indirect_desc->flags |= VLIB_BUFFER_NEXT_PRESENT;
688 indirect_desc->next_buffer = bi;
689 bi = indirect_buffer;
690
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000691 vnet_virtio_vring_packed_desc_t *id =
692 (vnet_virtio_vring_packed_desc_t *) vlib_buffer_get_current (
693 indirect_desc);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100694 u32 count = 1;
695 if (is_pci)
696 {
697 d->addr = vlib_physmem_get_pa (vm, id);
698 id->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz;
699
700 /*
701 * If VIRTIO_F_ANY_LAYOUT is not negotiated, then virtio_net_hdr
702 * should be presented in separate descriptor and data will start
703 * from next descriptor.
704 */
705 if (is_any_layout)
706 id->len = b->current_length + hdr_sz;
707 else
708 {
709 id->len = hdr_sz;
710 id->flags = 0;
711 id->id = 0;
712 count++;
713 id++;
714 id->addr = vlib_buffer_get_current_pa (vm, b);
715 id->len = b->current_length;
716 }
717 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
718 {
719 id->flags = 0;
720 id->id = 0;
721 count++;
722 id++;
723 b = vlib_get_buffer (vm, b->next_buffer);
724 id->addr = vlib_buffer_get_current_pa (vm, b);
725 id->len = b->current_length;
Mohsin Kazmi637c97c2021-05-12 14:51:29 +0200726 if (PREDICT_FALSE (count == VIRTIO_TX_MAX_CHAIN_LEN))
727 {
728 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
729 vlib_error_count (vm, node->node_index,
730 VIRTIO_TX_ERROR_TRUNC_PACKET, 1);
731 break;
732 }
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100733 }
734 }
735 id->flags = 0;
736 id->id = 0;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000737 d->len = count * sizeof (vnet_virtio_vring_packed_desc_t);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100738 flags = VRING_DESC_F_INDIRECT;
739 }
740 else
741 {
742 ASSERT (0);
743 }
744 if (vring->avail_wrap_counter)
745 {
746 flags |= VRING_DESC_F_AVAIL;
747 flags &= ~VRING_DESC_F_USED;
748 }
749 else
750 {
751 flags &= ~VRING_DESC_F_AVAIL;
752 flags |= VRING_DESC_F_USED;
753 }
754
755 d->id = next;
756 d->flags = flags;
757 vring->buffers[next] = bi;
758 n_added++;
759
760done:
761 if (drop_inline != ~0)
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200762 virtio_interface_drop_inline (vm, vif, node->node_index, &bi, 1,
763 drop_inline);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100764
765 return n_added;
766}
767
Damjan Marion809d5c92021-03-24 12:24:58 +0100768static uword
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000769virtio_interface_tx_packed_gso_inline (
770 vlib_main_t *vm, vlib_node_runtime_t *node, virtio_if_t *vif,
771 virtio_if_type_t type, vnet_virtio_vring_t *vring, u32 *buffers, u16 n_left,
772 const int do_gso, const int csum_offload)
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100773{
774 int is_pci = (type == VIRTIO_IF_TYPE_PCI);
775 int is_tun = (type == VIRTIO_IF_TYPE_TUN);
776 int is_indirect =
777 ((vif->features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) != 0);
778 int is_any_layout =
779 ((vif->features & VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)) != 0);
780 const int hdr_sz = vif->virtio_net_hdr_sz;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000781 u16 sz = vring->queue_size;
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100782 u16 used, next, n_buffers = 0, n_buffers_left = 0;
783 u16 n_vectors = n_left;
784
785
786 used = vring->desc_in_use;
787 next = vring->desc_next;
788
789 if (vif->packet_buffering)
790 {
791 n_buffers = n_buffers_left = virtio_vring_n_buffers (vring->buffering);
792
793 while (n_buffers_left && used < sz)
794 {
795 u16 n_added = 0;
796
797 u32 bi = virtio_vring_buffering_read_from_front (vring->buffering);
798 if (bi == ~0)
799 break;
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200800 n_added = add_buffer_to_slot_packed (
801 vm, node, vif, vring, bi, next, hdr_sz, do_gso, csum_offload,
802 is_pci, is_tun, is_indirect, is_any_layout);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100803 n_buffers_left--;
804 if (PREDICT_FALSE (n_added == 0))
805 continue;
806
807 used++;
808 next++;
809 if (next >= sz)
810 {
811 next = 0;
812 vring->avail_wrap_counter ^= 1;
813 }
814 }
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +0000815 virtio_txq_clear_scheduled (vring);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100816 }
817
818 while (n_left && used < sz)
819 {
820 u16 n_added = 0;
821
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200822 n_added = add_buffer_to_slot_packed (
823 vm, node, vif, vring, buffers[0], next, hdr_sz, do_gso, csum_offload,
824 is_pci, is_tun, is_indirect, is_any_layout);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100825 buffers++;
826 n_left--;
827 if (PREDICT_FALSE (n_added == 0))
828 continue;
829
830 used++;
831 next++;
832 if (next >= sz)
833 {
834 next = 0;
835 vring->avail_wrap_counter ^= 1;
836 }
837 }
838
839 if (n_left != n_vectors || n_buffers != n_buffers_left)
840 {
841 CLIB_MEMORY_STORE_BARRIER ();
842 vring->desc_next = next;
843 vring->desc_in_use = used;
844 CLIB_MEMORY_BARRIER ();
845 if (vring->device_event->flags != VRING_EVENT_F_DISABLE)
846 virtio_kick (vm, vring, vif);
847 }
848
849 return n_left;
850}
851
Damjan Marion809d5c92021-03-24 12:24:58 +0100852static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000853virtio_find_free_desc (vnet_virtio_vring_t *vring, u16 size, u16 mask, u16 req,
Damjan Marion809d5c92021-03-24 12:24:58 +0100854 u16 next, u32 *first_free_desc_index,
855 u16 *free_desc_count)
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100856{
857 u16 start = 0;
858 /* next is used as hint: from where to start looking */
859 for (u16 i = 0; i < size; i++, next++)
860 {
861 if (vring->buffers[next & mask] == ~0)
862 {
863 if (*first_free_desc_index == ~0)
864 {
865 *first_free_desc_index = (next & mask);
866 start = i;
867 (*free_desc_count)++;
868 req--;
869 if (req == 0)
870 break;
871 }
872 else
873 {
874 if (start + *free_desc_count == i)
875 {
876 (*free_desc_count)++;
877 req--;
878 if (req == 0)
879 break;
880 }
881 else
882 break;
883 }
884 }
885 }
886}
887
Damjan Marion809d5c92021-03-24 12:24:58 +0100888static u16
889virtio_interface_tx_split_gso_inline (vlib_main_t *vm,
890 vlib_node_runtime_t *node,
891 virtio_if_t *vif, virtio_if_type_t type,
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000892 vnet_virtio_vring_t *vring, u32 *buffers,
Damjan Marion809d5c92021-03-24 12:24:58 +0100893 u16 n_left, int do_gso, int csum_offload)
Damjan Marion8389fb92017-10-13 18:29:53 +0200894{
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000895 u16 used, next, avail, n_buffers = 0, n_buffers_left = 0;
Damjan Mariond4a54712020-10-31 23:40:51 +0100896 int is_pci = (type == VIRTIO_IF_TYPE_PCI);
897 int is_tun = (type == VIRTIO_IF_TYPE_TUN);
898 int is_indirect =
899 ((vif->features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) != 0);
900 int is_any_layout =
901 ((vif->features & VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)) != 0);
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +0000902 u16 sz = vring->queue_size;
Damjan Mariond4a54712020-10-31 23:40:51 +0100903 int hdr_sz = vif->virtio_net_hdr_sz;
Damjan Marion8389fb92017-10-13 18:29:53 +0200904 u16 mask = sz - 1;
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +0100905 u16 n_vectors = n_left;
Damjan Marion8389fb92017-10-13 18:29:53 +0200906
907 used = vring->desc_in_use;
908 next = vring->desc_next;
909 avail = vring->avail->idx;
910
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100911 u16 free_desc_count = 0;
912
913 if (PREDICT_FALSE (vring->flags & VRING_TX_OUT_OF_ORDER))
914 {
915 u32 first_free_desc_index = ~0;
916
917 virtio_find_free_desc (vring, sz, mask, n_left, next,
918 &first_free_desc_index, &free_desc_count);
919
920 if (free_desc_count)
921 next = first_free_desc_index;
922 }
923 else
924 free_desc_count = sz - used;
925
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000926 if (vif->packet_buffering)
927 {
928 n_buffers = n_buffers_left = virtio_vring_n_buffers (vring->buffering);
929
930 while (n_buffers_left && free_desc_count)
931 {
932 u16 n_added = 0;
933
934 u32 bi = virtio_vring_buffering_read_from_front (vring->buffering);
935 if (bi == ~0)
936 break;
Mohsin Kazmi83143712020-10-07 13:23:55 +0200937
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200938 n_added = add_buffer_to_slot (vm, node, vif, vring, bi,
939 free_desc_count, avail, next, mask,
940 hdr_sz, do_gso, csum_offload, is_pci,
941 is_tun, is_indirect, is_any_layout);
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000942 if (PREDICT_FALSE (n_added == 0))
943 {
944 n_buffers_left--;
945 continue;
946 }
947 else if (PREDICT_FALSE (n_added > free_desc_count))
948 break;
949
950 avail++;
951 next = (next + n_added) & mask;
952 used += n_added;
953 n_buffers_left--;
954 free_desc_count -= n_added;
955 }
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +0000956 virtio_txq_clear_scheduled (vring);
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000957 }
958
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100959 while (n_left && free_desc_count)
Damjan Marion8389fb92017-10-13 18:29:53 +0200960 {
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200961 u16 n_added = 0;
Mohsin Kazmib5ca5592020-06-26 13:48:26 +0000962
Mohsin Kazmia02ad342021-05-04 16:36:09 +0200963 n_added =
964 add_buffer_to_slot (vm, node, vif, vring, buffers[0], free_desc_count,
965 avail, next, mask, hdr_sz, do_gso, csum_offload,
966 is_pci, is_tun, is_indirect, is_any_layout);
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200967
968 if (PREDICT_FALSE (n_added == 0))
969 {
970 buffers++;
971 n_left--;
972 continue;
973 }
Mohsin Kazmice215992020-04-10 14:57:06 +0000974 else if (PREDICT_FALSE (n_added > free_desc_count))
975 break;
Mohsin Kazmif50ef402020-04-09 22:11:29 +0200976
Mohsin Kazmice215992020-04-10 14:57:06 +0000977 avail++;
Damjan Marion8389fb92017-10-13 18:29:53 +0200978 next = (next + n_added) & mask;
979 used += n_added;
980 buffers++;
981 n_left--;
Mohsin Kazmice215992020-04-10 14:57:06 +0000982 free_desc_count -= n_added;
Damjan Marion8389fb92017-10-13 18:29:53 +0200983 }
984
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +0100985 if (n_left != n_vectors || n_buffers != n_buffers_left)
Damjan Marion8389fb92017-10-13 18:29:53 +0200986 {
Mohsin Kazmid8b7dec2020-12-10 09:49:21 +0000987 clib_atomic_store_seq_cst (&vring->avail->idx, avail);
Damjan Marion8389fb92017-10-13 18:29:53 +0200988 vring->desc_next = next;
989 vring->desc_in_use = used;
Mohsin Kazmid8b7dec2020-12-10 09:49:21 +0000990 if ((clib_atomic_load_seq_cst (&vring->used->flags) &
991 VRING_USED_F_NO_NOTIFY) == 0)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200992 virtio_kick (vm, vring, vif);
Damjan Marion8389fb92017-10-13 18:29:53 +0200993 }
994
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +0100995 return n_left;
Damjan Marion8389fb92017-10-13 18:29:53 +0200996}
997
Damjan Marion809d5c92021-03-24 12:24:58 +0100998static u16
999virtio_interface_tx_gso_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
1000 virtio_if_t *vif, virtio_if_type_t type,
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001001 vnet_virtio_vring_t *vring, u32 *buffers,
Damjan Marion809d5c92021-03-24 12:24:58 +01001002 u16 n_left, int packed, int do_gso,
1003 int csum_offload)
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001004{
1005 if (packed)
1006 return virtio_interface_tx_packed_gso_inline (vm, node, vif, type, vring,
1007 buffers, n_left,
Mohsin Kazmib18b1902020-12-03 16:35:20 +01001008 do_gso, csum_offload);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001009 else
1010 return virtio_interface_tx_split_gso_inline (vm, node, vif, type, vring,
1011 buffers, n_left,
Mohsin Kazmib18b1902020-12-03 16:35:20 +01001012 do_gso, csum_offload);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001013}
1014
Damjan Marion809d5c92021-03-24 12:24:58 +01001015static u16
1016virtio_interface_tx_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001017 virtio_if_t *vif, vnet_virtio_vring_t *vring,
Damjan Marion809d5c92021-03-24 12:24:58 +01001018 virtio_if_type_t type, u32 *buffers, u16 n_left,
1019 int packed)
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001020{
1021 vnet_main_t *vnm = vnet_get_main ();
1022 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
1023
Damjan Mariond4f88cc2022-01-05 01:52:38 +01001024 if (hw->caps & VNET_HW_IF_CAP_TCP_GSO)
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001025 return virtio_interface_tx_gso_inline (vm, node, vif, type, vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001026 buffers, n_left, packed,
1027 1 /* do_gso */ ,
Damjan Mariondc181242020-10-20 12:11:06 +02001028 1 /* checksum offload */ );
Damjan Mariond4f88cc2022-01-05 01:52:38 +01001029 else if (hw->caps & VNET_HW_IF_CAP_L4_TX_CKSUM)
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001030 return virtio_interface_tx_gso_inline (vm, node, vif, type, vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001031 buffers, n_left, packed,
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001032 0 /* no do_gso */ ,
Damjan Mariondc181242020-10-20 12:11:06 +02001033 1 /* checksum offload */ );
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001034 else
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001035 return virtio_interface_tx_gso_inline (vm, node, vif, type, vring,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001036 buffers, n_left, packed,
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001037 0 /* no do_gso */ ,
Damjan Mariondc181242020-10-20 12:11:06 +02001038 0 /* no checksum offload */ );
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001039}
1040
Filip Tehlaraee73642019-03-13 05:50:44 -07001041VNET_DEVICE_CLASS_TX_FN (virtio_device_class) (vlib_main_t * vm,
1042 vlib_node_runtime_t * node,
1043 vlib_frame_t * frame)
Damjan Marion8389fb92017-10-13 18:29:53 +02001044{
1045 virtio_main_t *nm = &virtio_main;
1046 vnet_interface_output_runtime_t *rund = (void *) node->runtime_data;
1047 virtio_if_t *vif = pool_elt_at_index (nm->interfaces, rund->dev_instance);
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +00001048 vnet_hw_if_tx_frame_t *tf = vlib_frame_scalar_args (frame);
1049 u16 qid = tf->queue_id;
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001050 vnet_virtio_vring_t *vring = vec_elt_at_index (vif->txq_vrings, qid);
Mohsin Kazmiee1e30f2020-10-23 11:23:52 +02001051 u16 n_left = frame->n_vectors;
1052 u32 *buffers = vlib_frame_vector_args (frame);
1053 u32 to[GRO_TO_VECTOR_SIZE (n_left)];
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001054 int packed = vif->is_packed;
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001055 u16 n_vectors = frame->n_vectors;
Damjan Mariondc181242020-10-20 12:11:06 +02001056
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +00001057 if (tf->shared_queue)
1058 clib_spinlock_lock (&vring->lockp);
Damjan Mariondc181242020-10-20 12:11:06 +02001059
Mohsin Kazmiee1e30f2020-10-23 11:23:52 +02001060 if (vif->packet_coalesce)
1061 {
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001062 n_vectors = n_left =
1063 vnet_gro_inline (vm, vring->flow_table, buffers, n_left, to);
Mohsin Kazmiee1e30f2020-10-23 11:23:52 +02001064 buffers = to;
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +00001065 virtio_txq_clear_scheduled (vring);
Mohsin Kazmiee1e30f2020-10-23 11:23:52 +02001066 }
1067
Damjan Marion587f9132020-10-31 22:47:01 +01001068 u16 retry_count = 2;
1069
1070retry:
1071 /* free consumed buffers */
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001072 virtio_free_used_device_desc (vm, vring, node->node_index, packed);
Damjan Marion587f9132020-10-31 22:47:01 +01001073
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001074 if (vif->type == VIRTIO_IF_TYPE_TAP)
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001075 n_left = virtio_interface_tx_inline (vm, node, vif, vring,
Mohsin Kazmi81dac062020-11-11 20:28:35 +01001076 VIRTIO_IF_TYPE_TAP,
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001077 &buffers[n_vectors - n_left],
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001078 n_left, packed);
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001079 else if (vif->type == VIRTIO_IF_TYPE_PCI)
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001080 n_left = virtio_interface_tx_inline (vm, node, vif, vring,
Mohsin Kazmi81dac062020-11-11 20:28:35 +01001081 VIRTIO_IF_TYPE_PCI,
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001082 &buffers[n_vectors - n_left],
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001083 n_left, packed);
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001084 else if (vif->type == VIRTIO_IF_TYPE_TUN)
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001085 n_left = virtio_interface_tx_inline (vm, node, vif, vring,
Mohsin Kazmi81dac062020-11-11 20:28:35 +01001086 VIRTIO_IF_TYPE_TUN,
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001087 &buffers[n_vectors - n_left],
Mohsin Kazmib977d3f2020-11-16 16:49:30 +01001088 n_left, packed);
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001089 else
Mohsin Kazmi38b09682020-06-03 18:20:17 +02001090 ASSERT (0);
1091
Damjan Marion587f9132020-10-31 22:47:01 +01001092 if (n_left && retry_count--)
1093 goto retry;
1094
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001095 if (vif->packet_buffering && n_left)
1096 {
Mohsin Kazmi81dac062020-11-11 20:28:35 +01001097 u16 n_buffered = virtio_vring_buffering_store_packets (vring->buffering,
1098 &buffers
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001099 [n_vectors
Mohsin Kazmi81dac062020-11-11 20:28:35 +01001100 - n_left],
1101 n_left);
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001102 n_left -= n_buffered;
1103 }
1104 if (n_left)
Mohsin Kazmia02ad342021-05-04 16:36:09 +02001105 virtio_interface_drop_inline (vm, vif, node->node_index,
Mohsin Kazmie2e9fe52020-12-17 15:54:03 +01001106 &buffers[n_vectors - n_left], n_left,
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001107 VIRTIO_TX_ERROR_NO_FREE_SLOTS);
1108
Mohsin Kazmib7e4e6d2021-12-13 18:32:42 +00001109 if (tf->shared_queue)
1110 clib_spinlock_unlock (&vring->lockp);
Damjan Mariondc181242020-10-20 12:11:06 +02001111
Mohsin Kazmi2e6f6242020-10-26 12:41:41 +01001112 return frame->n_vectors - n_left;
Damjan Marion8389fb92017-10-13 18:29:53 +02001113}
1114
1115static void
1116virtio_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
1117 u32 node_index)
1118{
1119 virtio_main_t *apm = &virtio_main;
1120 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1121 virtio_if_t *vif = pool_elt_at_index (apm->interfaces, hw->dev_instance);
1122
1123 /* Shut off redirection */
1124 if (node_index == ~0)
1125 {
1126 vif->per_interface_next_index = node_index;
1127 return;
1128 }
1129
1130 vif->per_interface_next_index =
1131 vlib_node_add_next (vlib_get_main (), virtio_input_node.index,
1132 node_index);
1133}
1134
1135static void
1136virtio_clear_hw_interface_counters (u32 instance)
1137{
1138 /* Nothing for now */
1139}
1140
Damjan Marion809d5c92021-03-24 12:24:58 +01001141static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001142virtio_set_rx_interrupt (virtio_if_t *vif, vnet_virtio_vring_t *vring)
Mohsin Kazmi24841862020-12-02 16:39:42 +01001143{
1144 if (vif->is_packed)
1145 vring->driver_event->flags &= ~VRING_EVENT_F_DISABLE;
1146 else
1147 vring->avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
1148}
1149
Damjan Marion809d5c92021-03-24 12:24:58 +01001150static void
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001151virtio_set_rx_polling (virtio_if_t *vif, vnet_virtio_vring_t *vring)
Mohsin Kazmi24841862020-12-02 16:39:42 +01001152{
1153 if (vif->is_packed)
1154 vring->driver_event->flags |= VRING_EVENT_F_DISABLE;
1155 else
1156 vring->avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
1157}
1158
Damjan Marion8389fb92017-10-13 18:29:53 +02001159static clib_error_t *
1160virtio_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
Damjan Marioneabd4242020-10-07 20:59:07 +02001161 vnet_hw_if_rx_mode mode)
Damjan Marion8389fb92017-10-13 18:29:53 +02001162{
1163 virtio_main_t *mm = &virtio_main;
1164 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1165 virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
Mohsin Kazmi0f8912f2022-02-01 18:35:59 +00001166 vnet_virtio_vring_t *rx_vring = vec_elt_at_index (vif->rxq_vrings, qid);
Damjan Marion8389fb92017-10-13 18:29:53 +02001167
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001168 if (vif->type == VIRTIO_IF_TYPE_PCI && !(vif->support_int_mode))
1169 {
Mohsin Kazmi24841862020-12-02 16:39:42 +01001170 virtio_set_rx_polling (vif, rx_vring);
Mohsin Kazmib74fe322019-01-31 13:50:56 +00001171 return clib_error_return (0, "interrupt mode is not supported");
1172 }
1173
Damjan Marioneabd4242020-10-07 20:59:07 +02001174 if (mode == VNET_HW_IF_RX_MODE_POLLING)
Mohsin Kazmi24841862020-12-02 16:39:42 +01001175 virtio_set_rx_polling (vif, rx_vring);
Damjan Marion8389fb92017-10-13 18:29:53 +02001176 else
Mohsin Kazmi24841862020-12-02 16:39:42 +01001177 virtio_set_rx_interrupt (vif, rx_vring);
Damjan Marion8389fb92017-10-13 18:29:53 +02001178
Mohsin Kazmia5203b52020-10-12 13:01:24 +02001179 rx_vring->mode = mode;
1180
Damjan Marion8389fb92017-10-13 18:29:53 +02001181 return 0;
1182}
1183
1184static clib_error_t *
1185virtio_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
1186{
1187 virtio_main_t *mm = &virtio_main;
1188 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1189 virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
Damjan Marion8389fb92017-10-13 18:29:53 +02001190
1191 if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
Mohsin Kazmi529f0e92020-03-19 14:03:31 +01001192 {
1193 vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
1194 vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
1195 VNET_HW_INTERFACE_FLAG_LINK_UP);
1196 }
Damjan Marion8389fb92017-10-13 18:29:53 +02001197 else
Mohsin Kazmi529f0e92020-03-19 14:03:31 +01001198 {
1199 vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
1200 vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
1201 }
Damjan Marion8389fb92017-10-13 18:29:53 +02001202 return 0;
1203}
1204
1205static clib_error_t *
1206virtio_subif_add_del_function (vnet_main_t * vnm,
1207 u32 hw_if_index,
1208 struct vnet_sw_interface_t *st, int is_add)
1209{
1210 /* Nothing for now */
1211 return 0;
1212}
1213
1214/* *INDENT-OFF* */
1215VNET_DEVICE_CLASS (virtio_device_class) = {
1216 .name = "virtio",
Damjan Marion8389fb92017-10-13 18:29:53 +02001217 .format_device_name = format_virtio_device_name,
1218 .format_device = format_virtio_device,
1219 .format_tx_trace = format_virtio_tx_trace,
Mohsin Kazmid6c15af2018-10-23 18:00:47 +02001220 .tx_function_n_errors = VIRTIO_TX_N_ERROR,
Damjan Marion8389fb92017-10-13 18:29:53 +02001221 .tx_function_error_strings = virtio_tx_func_error_strings,
1222 .rx_redirect_to_node = virtio_set_interface_next_node,
1223 .clear_counters = virtio_clear_hw_interface_counters,
1224 .admin_up_down_function = virtio_interface_admin_up_down,
1225 .subif_add_del_function = virtio_subif_add_del_function,
1226 .rx_mode_change_function = virtio_interface_rx_mode_change,
1227};
Mohsin Kazmi206acf82020-04-06 14:19:54 +02001228
Damjan Marion8389fb92017-10-13 18:29:53 +02001229/* *INDENT-ON* */
1230
1231/*
1232 * fd.io coding-style-patch-verification: ON
1233 *
1234 * Local Variables:
1235 * eval: (c-set-style "gnu")
1236 * End:
1237 */