FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
device.c
Go to the documentation of this file.
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>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ethernet/ethernet.h>
27 #include <vnet/ip/ip4_packet.h>
28 #include <vnet/ip/ip6_packet.h>
29 #include <vnet/tcp/tcp_packet.h>
30 #include <vnet/udp/udp_packet.h>
32 
33 #define foreach_virtio_tx_func_error \
34 _(NO_FREE_SLOTS, "no free tx slots") \
35 _(TRUNC_PACKET, "packet > buffer size -- truncated in tx ring") \
36 _(PENDING_MSGS, "pending msgs in tx ring") \
37 _(INDIRECT_DESC_ALLOC_FAILED, "indirect descriptor allocation failed - packet drop") \
38 _(OUT_OF_ORDER, "out-of-order buffers in used ring") \
39 _(GSO_PACKET_DROP, "gso disabled on itf -- gso packet drop") \
40 _(CSUM_OFFLOAD_PACKET_DROP, "checksum offload disabled on itf -- csum offload packet drop")
41 
42 typedef enum
43 {
44 #define _(f,s) VIRTIO_TX_ERROR_##f,
46 #undef _
49 
50 static char *virtio_tx_func_error_strings[] = {
51 #define _(n,s) s,
53 #undef _
54 };
55 
56 static u8 *
57 format_virtio_device (u8 * s, va_list * args)
58 {
59  u32 dev_instance = va_arg (*args, u32);
60  int verbose = va_arg (*args, int);
61  u32 indent = format_get_indent (s);
62 
63  s = format (s, "VIRTIO interface");
64  if (verbose)
65  {
66  s = format (s, "\n%U instance %u", format_white_space, indent + 2,
67  dev_instance);
68  }
69  return s;
70 }
71 
72 static u8 *
73 format_virtio_tx_trace (u8 * s, va_list * args)
74 {
75  s = format (s, "Unimplemented...");
76  return s;
77 }
78 
81  u32 * buffers, u16 n,
83 {
84  vlib_error_count (vm, node_index, error, n);
85  vlib_buffer_free (vm, buffers, n);
86 }
87 
89 virtio_memset_ring_u32 (u32 * ring, u32 start, u32 ring_size, u32 n_buffers)
90 {
91  ASSERT (n_buffers <= ring_size);
92 
93  if (PREDICT_TRUE (start + n_buffers <= ring_size))
94  {
95  clib_memset_u32 (ring + start, ~0, n_buffers);
96  }
97  else
98  {
99  clib_memset_u32 (ring + start, ~0, ring_size - start);
100  clib_memset_u32 (ring, ~0, n_buffers - (ring_size - start));
101  }
102 }
103 
106  uword node_index)
107 {
108  u16 used = vring->desc_in_use;
109  u16 sz = vring->size;
110  u16 mask = sz - 1;
111  u16 last = vring->last_used_idx;
112  u16 n_left = vring->used->idx - last;
113  u16 out_of_order_count = 0;
114 
115  if (n_left == 0)
116  return;
117 
118  while (n_left)
119  {
120  struct vring_used_elem *e = &vring->used->ring[last & mask];
121  u16 slot, n_buffers;
122  slot = n_buffers = e->id;
123 
124  while (e->id == (n_buffers & mask))
125  {
126  n_left--;
127  last++;
128  n_buffers++;
129  struct vring_desc *d = &vring->desc[e->id];
130  u16 next;
131  while (d->flags & VRING_DESC_F_NEXT)
132  {
133  n_buffers++;
134  next = d->next;
135  d = &vring->desc[next];
136  }
137  if (n_left == 0)
138  break;
139  e = &vring->used->ring[last & mask];
140  }
141  vlib_buffer_free_from_ring (vm, vring->buffers, slot,
142  sz, (n_buffers - slot));
143  virtio_memset_ring_u32 (vring->buffers, slot, sz, (n_buffers - slot));
144  used -= (n_buffers - slot);
145 
146  if (n_left > 0)
147  {
148  vlib_buffer_free (vm, &vring->buffers[e->id], 1);
149  vring->buffers[e->id] = ~0;
150  used--;
151  last++;
152  n_left--;
153  out_of_order_count++;
154  vring->flags |= VRING_TX_OUT_OF_ORDER;
155  }
156  }
157 
158  /*
159  * Some vhost-backends give buffers back in out-of-order fashion in used ring.
160  * It impacts the overall virtio-performance.
161  */
162  if (out_of_order_count)
163  vlib_error_count (vm, node_index, VIRTIO_TX_ERROR_OUT_OF_ORDER,
164  out_of_order_count);
165 
166  vring->desc_in_use = used;
167  vring->last_used_idx = last;
168 }
169 
171 set_checksum_offsets (vlib_buffer_t * b, struct virtio_net_hdr_v1 *hdr,
172  int is_l2)
173 {
174  if (b->flags & VNET_BUFFER_F_IS_IP4)
175  {
176  ip4_header_t *ip4;
177  generic_header_offset_t gho = { 0 };
178  vnet_generic_header_offset_parser (b, &gho, is_l2, 1 /* ip4 */ ,
179  0 /* ip6 */ );
180  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
181  hdr->csum_start = gho.l4_hdr_offset; // 0x22;
182  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
183  {
184  hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
185  }
186  else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
187  {
188  hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
189  }
190 
191  /*
192  * virtio devices do not support IP4 checksum offload. So driver takes care
193  * of it while doing tx.
194  */
195  ip4 =
197  if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
198  ip4->checksum = ip4_header_checksum (ip4);
199  }
200  else if (b->flags & VNET_BUFFER_F_IS_IP6)
201  {
202  generic_header_offset_t gho = { 0 };
203  vnet_generic_header_offset_parser (b, &gho, is_l2, 0 /* ip4 */ ,
204  1 /* ip6 */ );
205  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
206  hdr->csum_start = gho.l4_hdr_offset; // 0x36;
207  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
208  {
209  hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
210  }
211  else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
212  {
213  hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
214  }
215  }
216 }
217 
219 set_gso_offsets (vlib_buffer_t * b, struct virtio_net_hdr_v1 *hdr, int is_l2)
220 {
221  if (b->flags & VNET_BUFFER_F_IS_IP4)
222  {
223  ip4_header_t *ip4;
224  generic_header_offset_t gho = { 0 };
225  vnet_generic_header_offset_parser (b, &gho, is_l2, 1 /* ip4 */ ,
226  0 /* ip6 */ );
227  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
228  hdr->gso_size = vnet_buffer2 (b)->gso_size;
229  hdr->hdr_len = gho.hdr_sz;
230  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
231  hdr->csum_start = gho.l4_hdr_offset; // 0x22;
232  hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
233  ip4 =
235  /*
236  * virtio devices do not support IP4 checksum offload. So driver takes care
237  * of it while doing tx.
238  */
239  if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
240  ip4->checksum = ip4_header_checksum (ip4);
241  }
242  else if (b->flags & VNET_BUFFER_F_IS_IP6)
243  {
244  generic_header_offset_t gho = { 0 };
245  vnet_generic_header_offset_parser (b, &gho, is_l2, 0 /* ip4 */ ,
246  1 /* ip6 */ );
247  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
248  hdr->gso_size = vnet_buffer2 (b)->gso_size;
249  hdr->hdr_len = gho.hdr_sz;
250  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
251  hdr->csum_start = gho.l4_hdr_offset; // 0x36;
252  hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
253  }
254 }
255 
258  virtio_vring_t * vring, u32 bi, u16 free_desc_count,
259  u16 avail, u16 next, u16 mask, int do_gso,
260  int csum_offload, uword node_index)
261 {
262  u16 n_added = 0;
263  int hdr_sz = vif->virtio_net_hdr_sz;
264  struct vring_desc *d;
265  d = &vring->desc[next];
266  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
267  struct virtio_net_hdr_v1 *hdr = vlib_buffer_get_current (b) - hdr_sz;
268  int is_l2 = (vif->type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI));
269 
270  clib_memset (hdr, 0, hdr_sz);
271 
272  if (b->flags & VNET_BUFFER_F_GSO)
273  {
274  if (do_gso)
275  set_gso_offsets (b, hdr, is_l2);
276  else
277  {
278  virtio_interface_drop_inline (vm, node_index, &bi, 1,
279  VIRTIO_TX_ERROR_GSO_PACKET_DROP);
280  return n_added;
281  }
282  }
283  else if (b->flags & (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
284  VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
285  {
286  if (csum_offload)
287  set_checksum_offsets (b, hdr, is_l2);
288  else
289  {
290  virtio_interface_drop_inline (vm, node_index, &bi, 1,
291  VIRTIO_TX_ERROR_CSUM_OFFLOAD_PACKET_DROP);
292  return n_added;
293  }
294  }
295 
296  if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0))
297  {
298  d->addr =
299  ((vif->type == VIRTIO_IF_TYPE_PCI) ? vlib_buffer_get_current_pa (vm,
300  b) :
302  d->len = b->current_length + hdr_sz;
303  d->flags = 0;
304  }
305  else if (vif->features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC))
306  {
307  /*
308  * We are using single vlib_buffer_t for indirect descriptor(s)
309  * chain. Single descriptor is 16 bytes and vlib_buffer_t
310  * has 2048 bytes space. So maximum long chain can have 128
311  * (=2048/16) indirect descriptors.
312  * It can easily support 65535 bytes of Jumbo frames with
313  * each data buffer size of 512 bytes minimum.
314  */
315  u32 indirect_buffer = 0;
316  if (PREDICT_FALSE (vlib_buffer_alloc (vm, &indirect_buffer, 1) == 0))
317  {
318  virtio_interface_drop_inline (vm, node_index, &bi, 1,
319  VIRTIO_TX_ERROR_INDIRECT_DESC_ALLOC_FAILED);
320  return n_added;
321  }
322 
323  vlib_buffer_t *indirect_desc = vlib_get_buffer (vm, indirect_buffer);
324  indirect_desc->current_data = 0;
325  indirect_desc->flags |= VLIB_BUFFER_NEXT_PRESENT;
326  indirect_desc->next_buffer = bi;
327  bi = indirect_buffer;
328 
329  struct vring_desc *id =
330  (struct vring_desc *) vlib_buffer_get_current (indirect_desc);
331  u32 count = 1;
332  if (vif->type == VIRTIO_IF_TYPE_PCI)
333  {
334  d->addr = vlib_physmem_get_pa (vm, id);
335  id->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz;
336 
337  /*
338  * If VIRTIO_F_ANY_LAYOUT is not negotiated, then virtio_net_hdr
339  * should be presented in separate descriptor and data will start
340  * from next descriptor.
341  */
342  if (PREDICT_TRUE
343  (vif->features & VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT)))
344  id->len = b->current_length + hdr_sz;
345  else
346  {
347  id->len = hdr_sz;
348  id->flags = VRING_DESC_F_NEXT;
349  id->next = count;
350  count++;
351  id++;
352  id->addr = vlib_buffer_get_current_pa (vm, b);
353  id->len = b->current_length;
354  }
355  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
356  {
357  id->flags = VRING_DESC_F_NEXT;
358  id->next = count;
359  count++;
360  id++;
361  b = vlib_get_buffer (vm, b->next_buffer);
362  id->addr = vlib_buffer_get_current_pa (vm, b);
363  id->len = b->current_length;
364  }
365  }
366  else /* VIRTIO_IF_TYPE_[TAP | TUN] */
367  {
368  d->addr = pointer_to_uword (id);
369  /* first buffer in chain */
370  id->addr = pointer_to_uword (vlib_buffer_get_current (b)) - hdr_sz;
371  id->len = b->current_length + hdr_sz;
372 
373  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
374  {
375  id->flags = VRING_DESC_F_NEXT;
376  id->next = count;
377  count++;
378  id++;
379  b = vlib_get_buffer (vm, b->next_buffer);
380  id->addr = pointer_to_uword (vlib_buffer_get_current (b));
381  id->len = b->current_length;
382  }
383  }
384  id->flags = 0;
385  id->next = 0;
386  d->len = count * sizeof (struct vring_desc);
387  d->flags = VRING_DESC_F_INDIRECT;
388  }
389  else if (vif->type == VIRTIO_IF_TYPE_PCI)
390  {
391  u16 count = next;
392  vlib_buffer_t *b_temp = b;
393  u16 n_buffers_in_chain = 1;
394 
395  /*
396  * Check the length of the chain for the required number of
397  * descriptors. Return from here, retry to get more descriptors,
398  * if chain length is greater than available descriptors.
399  */
400  while (b_temp->flags & VLIB_BUFFER_NEXT_PRESENT)
401  {
402  n_buffers_in_chain++;
403  b_temp = vlib_get_buffer (vm, b_temp->next_buffer);
404  }
405 
406  if (n_buffers_in_chain > free_desc_count)
407  return n_buffers_in_chain;
408 
409  d->addr = vlib_buffer_get_current_pa (vm, b) - hdr_sz;
410  d->len = b->current_length + hdr_sz;
411 
412  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
413  {
414  d->flags = VRING_DESC_F_NEXT;
415  vring->buffers[count] = bi;
416  b->flags &=
417  ~(VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID);
418  bi = b->next_buffer;
419  b->next_buffer = 0;
420  n_added++;
421  count = (count + 1) & mask;
422  d->next = count;
423  d = &vring->desc[count];
424  b = vlib_get_buffer (vm, bi);
425  d->addr = vlib_buffer_get_current_pa (vm, b);
426  d->len = b->current_length;
427  }
428  d->flags = 0;
429  vring->buffers[count] = bi;
430  vring->avail->ring[avail & mask] = next;
431  n_added++;
432  return n_added;
433  }
434  else
435  {
436  ASSERT (0);
437  }
438  vring->buffers[next] = bi;
439  vring->avail->ring[avail & mask] = next;
440  n_added++;
441  return n_added;
442 }
443 
446  u16 req, u16 next, u32 * first_free_desc_index,
447  u16 * free_desc_count)
448 {
449  u16 start = 0;
450  /* next is used as hint: from where to start looking */
451  for (u16 i = 0; i < size; i++, next++)
452  {
453  if (vring->buffers[next & mask] == ~0)
454  {
455  if (*first_free_desc_index == ~0)
456  {
457  *first_free_desc_index = (next & mask);
458  start = i;
459  (*free_desc_count)++;
460  req--;
461  if (req == 0)
462  break;
463  }
464  else
465  {
466  if (start + *free_desc_count == i)
467  {
468  (*free_desc_count)++;
469  req--;
470  if (req == 0)
471  break;
472  }
473  else
474  break;
475  }
476  }
477  }
478 }
479 
482  vlib_frame_t * frame, virtio_if_t * vif,
483  int do_gso, int csum_offload)
484 {
485  u16 n_left = frame->n_vectors;
486  virtio_vring_t *vring;
487  u16 qid = vm->thread_index % vif->num_txqs;
488  vring = vec_elt_at_index (vif->txq_vrings, qid);
489  u16 used, next, avail;
490  u16 sz = vring->size;
491  u16 mask = sz - 1;
492  u16 retry_count = 2;
493  u32 *buffers = vlib_frame_vector_args (frame);
494 
496 
497  if ((vring->used->flags & VIRTIO_RING_FLAG_MASK_INT) == 0 &&
498  (vring->last_kick_avail_idx != vring->avail->idx))
499  virtio_kick (vm, vring, vif);
500 
501 retry:
502  /* free consumed buffers */
503  virtio_free_used_device_desc (vm, vring, node->node_index);
504 
505  used = vring->desc_in_use;
506  next = vring->desc_next;
507  avail = vring->avail->idx;
508 
509  u16 free_desc_count = 0;
510 
512  {
513  u32 first_free_desc_index = ~0;
514 
515  virtio_find_free_desc (vring, sz, mask, n_left, next,
516  &first_free_desc_index, &free_desc_count);
517 
518  if (free_desc_count)
519  next = first_free_desc_index;
520  }
521  else
522  free_desc_count = sz - used;
523 
524  while (n_left && free_desc_count)
525  {
526  u16 n_added = 0;
527  n_added =
528  add_buffer_to_slot (vm, vif, vring, buffers[0], free_desc_count,
529  avail, next, mask, do_gso, csum_offload,
530  node->node_index);
531 
532  if (PREDICT_FALSE (n_added == 0))
533  {
534  buffers++;
535  n_left--;
536  continue;
537  }
538  else if (PREDICT_FALSE (n_added > free_desc_count))
539  break;
540 
541  avail++;
542  next = (next + n_added) & mask;
543  used += n_added;
544  buffers++;
545  n_left--;
546  free_desc_count -= n_added;
547  }
548 
549  if (n_left != frame->n_vectors)
550  {
552  vring->avail->idx = avail;
553  vring->desc_next = next;
554  vring->desc_in_use = used;
555  if ((vring->used->flags & VIRTIO_RING_FLAG_MASK_INT) == 0)
556  virtio_kick (vm, vring, vif);
557  }
558 
559  if (n_left)
560  {
561  if (retry_count--)
562  goto retry;
563 
564  virtio_interface_drop_inline (vm, node->node_index, buffers, n_left,
565  VIRTIO_TX_ERROR_NO_FREE_SLOTS);
566  }
567 
569 
570  return frame->n_vectors - n_left;
571 }
572 
576 {
577  vnet_main_t *vnm = vnet_get_main ();
578  virtio_main_t *nm = &virtio_main;
579  vnet_interface_output_runtime_t *rund = (void *) node->runtime_data;
581  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
582 
584  return virtio_interface_tx_inline (vm, node, frame, vif, 1 /* do_gso */ ,
585  1);
587  return virtio_interface_tx_inline (vm, node, frame, vif,
588  0 /* no do_gso */ , 1);
589  else
590  return virtio_interface_tx_inline (vm, node, frame, vif,
591  0 /* no do_gso */ , 0);
592 }
593 
594 static void
596  u32 node_index)
597 {
598  virtio_main_t *apm = &virtio_main;
599  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
601 
602  /* Shut off redirection */
603  if (node_index == ~0)
604  {
605  vif->per_interface_next_index = node_index;
606  return;
607  }
608 
611  node_index);
612 }
613 
614 static void
616 {
617  /* Nothing for now */
618 }
619 
620 static clib_error_t *
623 {
624  virtio_main_t *mm = &virtio_main;
625  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
627  virtio_vring_t *vring = vec_elt_at_index (vif->rxq_vrings, qid);
628 
629  if (vif->type == VIRTIO_IF_TYPE_PCI && !(vif->support_int_mode))
630  {
631  vring->avail->flags |= VIRTIO_RING_FLAG_MASK_INT;
632  return clib_error_return (0, "interrupt mode is not supported");
633  }
634 
636  vring->avail->flags |= VIRTIO_RING_FLAG_MASK_INT;
637  else
638  vring->avail->flags &= ~VIRTIO_RING_FLAG_MASK_INT;
639 
640  return 0;
641 }
642 
643 static clib_error_t *
645 {
646  virtio_main_t *mm = &virtio_main;
647  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
649 
651  {
652  vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
655  }
656  else
657  {
658  vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
660  }
661  return 0;
662 }
663 
664 static clib_error_t *
666  u32 hw_if_index,
667  struct vnet_sw_interface_t *st, int is_add)
668 {
669  /* Nothing for now */
670  return 0;
671 }
672 
673 /* *INDENT-OFF* */
675  .name = "virtio",
676  .format_device_name = format_virtio_device_name,
677  .format_device = format_virtio_device,
678  .format_tx_trace = format_virtio_tx_trace,
679  .tx_function_n_errors = VIRTIO_TX_N_ERROR,
680  .tx_function_error_strings = virtio_tx_func_error_strings,
681  .rx_redirect_to_node = virtio_set_interface_next_node,
682  .clear_counters = virtio_clear_hw_interface_counters,
683  .admin_up_down_function = virtio_interface_admin_up_down,
684  .subif_add_del_function = virtio_subif_add_del_function,
685  .rx_mode_change_function = virtio_interface_rx_mode_change,
686 };
687 
688 /* *INDENT-ON* */
689 
690 /*
691  * fd.io coding-style-patch-verification: ON
692  *
693  * Local Variables:
694  * eval: (c-set-style "gnu")
695  * End:
696  */
u32 per_interface_next_index
Definition: virtio.h:156
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
u8 count
Definition: dhcp.api:208
struct vring_used * used
Definition: virtio.h:110
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
Definition: node.c:442
static uword vlib_buffer_get_current_pa(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:463
VNET_DEVICE_CLASS_TX_FN() virtio_device_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: device.c:573
virtio_if_t * interfaces
Definition: virtio.h:195
static clib_error_t * virtio_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:644
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:937
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define vnet_buffer2(b)
Definition: buffer.h:482
#define PREDICT_TRUE(x)
Definition: clib.h:119
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
#define CLIB_MEMORY_STORE_BARRIER()
Definition: clib.h:133
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:110
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 thread_index
Definition: main.h:218
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
static u32 format_get_indent(u8 *s)
Definition: format.h:72
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:69
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
struct _tcp_header tcp_header_t
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
vnet_hw_interface_rx_mode
Definition: interface.h:53
struct vring_avail * avail
Definition: virtio.h:111
u64 features
Definition: virtio.h:163
#define static_always_inline
Definition: clib.h:106
u32 hw_if_index
Definition: virtio.h:146
static clib_error_t * virtio_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
Definition: device.c:665
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
u8 support_int_mode
Definition: virtio.h:167
vnet_hw_interface_flags_t flags
Definition: interface.h:526
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
clib_spinlock_t lockp
Definition: virtio.h:112
#define clib_error_return(e, args...)
Definition: error.h:99
#define VNET_DEVICE_CLASS_TX_FN(devclass)
Definition: interface.h:305
unsigned int u32
Definition: types.h:88
#define foreach_virtio_tx_func_error
Definition: device.c:33
u16 num_txqs
Definition: virtio.h:170
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
Definition: buffer_funcs.h:984
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
static_always_inline void virtio_find_free_desc(virtio_vring_t *vring, u16 size, u16 mask, u16 req, u16 next, u32 *first_free_desc_index, u16 *free_desc_count)
Definition: device.c:445
unsigned short u16
Definition: types.h:57
static u8 * format_virtio_tx_trace(u8 *s, va_list *args)
Definition: device.c:73
u64 size
Definition: vhost_user.h:150
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
static u8 * format_virtio_device(u8 *s, va_list *args)
Definition: device.c:57
#define PREDICT_FALSE(x)
Definition: clib.h:118
vl_api_ip4_address_t ip4
Definition: one.api:376
u32 node_index
Node index.
Definition: node.h:498
vlib_main_t * vm
Definition: in2out_ed.c:1599
vl_api_tunnel_mode_t mode
Definition: gre.api:48
static void virtio_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: device.c:595
static_always_inline void virtio_interface_drop_inline(vlib_main_t *vm, uword node_index, u32 *buffers, u16 n, virtio_tx_func_error_t error)
Definition: device.c:80
u16 desc_next
Definition: virtio.h:114
u16 virtio_net_hdr_sz
Definition: virtio.h:149
u8 slot
Definition: pci_types.api:22
virtio_vring_t * rxq_vrings
Definition: virtio.h:161
format_function_t format_virtio_device_name
Definition: virtio.h:217
u16 last_used_idx
Definition: virtio.h:124
u32 flags
Definition: vhost_user.h:248
u16 n_vectors
Definition: node.h:399
#define VIRTIO_RING_FLAG_MASK_INT
Definition: virtio.h:104
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
static_always_inline uword virtio_interface_tx_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, virtio_if_t *vif, int do_gso, int csum_offload)
Definition: device.c:481
static_always_inline void set_gso_offsets(vlib_buffer_t *b, struct virtio_net_hdr_v1 *hdr, int is_l2)
Definition: device.c:219
u32 flags
Definition: virtio.h:143
u16 last_kick_avail_idx
Definition: virtio.h:125
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
virtio_if_type_t type
Definition: virtio.h:150
#define ASSERT(truth)
VNET_DEVICE_CLASS(avf_device_class,)
#define VIRTIO_FEATURE(X)
Definition: virtio.h:75
virtio_tx_func_error_t
Definition: device.c:42
static uword pointer_to_uword(const void *p)
Definition: types.h:131
virtio_main_t virtio_main
Definition: virtio.c:37
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
#define VRING_TX_OUT_OF_ORDER
Definition: virtio.h:120
static_always_inline void vnet_generic_header_offset_parser(vlib_buffer_t *b0, generic_header_offset_t *gho, int is_l2, int is_ip4, int is_ip6)
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
u32 instance
Definition: gre.api:51
static void virtio_clear_hw_interface_counters(u32 instance)
Definition: device.c:615
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:498
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
static_always_inline void set_checksum_offsets(vlib_buffer_t *b, struct virtio_net_hdr_v1 *hdr, int is_l2)
Definition: device.c:171
u32 * buffers
Definition: virtio.h:123
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: in2out_ed.c:1600
struct vring_desc * desc
Definition: virtio.h:109
static_always_inline u16 add_buffer_to_slot(vlib_main_t *vm, virtio_if_t *vif, virtio_vring_t *vring, u32 bi, u16 free_desc_count, u16 avail, u16 next, u16 mask, int do_gso, int csum_offload, uword node_index)
Definition: device.c:257
static_always_inline void virtio_free_used_device_desc(vlib_main_t *vm, virtio_vring_t *vring, uword node_index)
Definition: device.c:105
static clib_error_t * virtio_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_interface_rx_mode mode)
Definition: device.c:621
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:677
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:95
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
static_always_inline void virtio_memset_ring_u32(u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Definition: device.c:89
u16 desc_in_use
Definition: virtio.h:113
static char * virtio_tx_func_error_strings[]
Definition: device.c:50
virtio_vring_t * txq_vrings
Definition: virtio.h:162
static_always_inline void virtio_kick(vlib_main_t *vm, virtio_vring_t *vring, virtio_if_t *vif)
Definition: virtio.h:221
static_always_inline void clib_memset_u32(void *p, u32 val, uword count)
Definition: string.h:332