FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
device.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/format.h>
18 #include <vlib/unix/cj.h>
19 #include <assert.h>
20 
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
23 
24 #include <dpdk/device/dpdk_priv.h>
25 #include <vppinfra/error.h>
26 
27 #define foreach_dpdk_tx_func_error \
28  _(BAD_RETVAL, "DPDK tx function returned an error") \
29  _(RING_FULL, "Tx packet drops (ring full)") \
30  _(PKT_DROP, "Tx packet drops (dpdk tx failure)") \
31  _(REPL_FAIL, "Tx packet drops (replication failure)")
32 
33 typedef enum
34 {
35 #define _(f,s) DPDK_TX_FUNC_ERROR_##f,
37 #undef _
40 
41 static char *dpdk_tx_func_error_strings[] = {
42 #define _(n,s) s,
44 #undef _
45 };
46 
47 static clib_error_t *
49 {
50  int error;
51  dpdk_main_t *dm = &dpdk_main;
53 
54  error = rte_eth_dev_default_mac_addr_set (xd->device_index,
55  (struct ether_addr *) address);
56 
57  if (error)
58  {
59  return clib_error_return (0, "mac address set failed: %d", error);
60  }
61  else
62  {
64  vec_add (xd->default_mac_address, address, sizeof (address));
65  return NULL;
66  }
67 }
68 
69 struct rte_mbuf *
71 {
72  dpdk_main_t *dm = &dpdk_main;
73  struct rte_mbuf **mbufs = 0, *s, *d;
74  u8 nb_segs;
75  unsigned socket_id = rte_socket_id ();
76  int i;
77 
78  ASSERT (dm->pktmbuf_pools[socket_id]);
80  nb_segs = s->nb_segs;
81  vec_validate (mbufs, nb_segs - 1);
82 
83  if (rte_pktmbuf_alloc_bulk (dm->pktmbuf_pools[socket_id], mbufs, nb_segs))
84  {
85  vec_free (mbufs);
86  return 0;
87  }
88 
89  d = mbufs[0];
90  d->nb_segs = s->nb_segs;
91  d->data_len = s->data_len;
92  d->pkt_len = s->pkt_len;
93  d->data_off = s->data_off;
94  clib_memcpy (d->buf_addr, s->buf_addr, RTE_PKTMBUF_HEADROOM + s->data_len);
95 
96  for (i = 1; i < nb_segs; i++)
97  {
98  d->next = mbufs[i];
99  d = mbufs[i];
100  s = s->next;
101  d->data_len = s->data_len;
102  clib_memcpy (d->buf_addr, s->buf_addr,
103  RTE_PKTMBUF_HEADROOM + s->data_len);
104  }
105 
106  d = mbufs[0];
107  vec_free (mbufs);
108  return d;
109 }
110 
111 static void
113  vlib_node_runtime_t * node,
114  dpdk_device_t * xd,
115  u16 queue_id, u32 buffer_index, vlib_buffer_t * buffer)
116 {
117  vlib_main_t *vm = vlib_get_main ();
119  struct rte_mbuf *mb;
120 
121  mb = rte_mbuf_from_vlib_buffer (buffer);
122 
123  t0 = vlib_add_trace (vm, node, buffer, sizeof (t0[0]));
124  t0->queue_index = queue_id;
125  t0->device_index = xd->device_index;
126  t0->buffer_index = buffer_index;
127  clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
128  clib_memcpy (&t0->buffer, buffer,
129  sizeof (buffer[0]) - sizeof (buffer->pre_data));
130  clib_memcpy (t0->buffer.pre_data, buffer->data + buffer->current_data,
131  sizeof (t0->buffer.pre_data));
132 }
133 
136  int maybe_multiseg)
137 {
138  struct rte_mbuf *mb, *first_mb, *last_mb;
139 
140  /* buffer is coming from non-dpdk source so we need to init
141  rte_mbuf header */
143  {
144  vlib_buffer_t *b2 = b;
145  last_mb = mb = rte_mbuf_from_vlib_buffer (b2);
146  rte_pktmbuf_reset (mb);
147  while (maybe_multiseg && (b2->flags & VLIB_BUFFER_NEXT_PRESENT))
148  {
149  b2 = vlib_get_buffer (vm, b2->next_buffer);
150  mb = rte_mbuf_from_vlib_buffer (b2);
151  rte_pktmbuf_reset (mb);
152  }
153  }
154 
155  last_mb = first_mb = mb = rte_mbuf_from_vlib_buffer (b);
156  first_mb->nb_segs = 1;
157  mb->data_len = b->current_length;
158  mb->pkt_len = maybe_multiseg ? vlib_buffer_length_in_chain (vm, b) :
159  b->current_length;
160  mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
161 
162  while (maybe_multiseg && (b->flags & VLIB_BUFFER_NEXT_PRESENT))
163  {
164  b = vlib_get_buffer (vm, b->next_buffer);
165  mb = rte_mbuf_from_vlib_buffer (b);
166  last_mb->next = mb;
167  last_mb = mb;
168  mb->data_len = b->current_length;
169  mb->pkt_len = b->current_length;
170  mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
171  first_mb->nb_segs++;
172  if (PREDICT_FALSE (b->n_add_refs))
173  {
174  rte_mbuf_refcnt_update (mb, b->n_add_refs);
175  b->n_add_refs = 0;
176  }
177  }
178 }
179 
180 /*
181  * This function calls the dpdk's tx_burst function to transmit the packets
182  * on the tx_vector. It manages a lock per-device if the device does not
183  * support multiple queues. It returns the number of packets untransmitted
184  * on the tx_vector. If all packets are transmitted (the normal case), the
185  * function returns 0.
186  *
187  * The function assumes there is at least one packet on the tx_vector.
188  */
191  dpdk_device_t * xd,
192  struct rte_mbuf **tx_vector)
193 {
194  dpdk_main_t *dm = &dpdk_main;
195  u32 n_packets;
196  u32 tx_head;
197  u32 tx_tail;
198  u32 n_retry;
199  int rv;
200  int queue_id;
201  tx_ring_hdr_t *ring;
202 
203  ring = vec_header (tx_vector, sizeof (*ring));
204 
205  n_packets = ring->tx_head - ring->tx_tail;
206 
207  tx_head = ring->tx_head % xd->nb_tx_desc;
208 
209  /*
210  * Ensure rte_eth_tx_burst is not called with 0 packets, which can lead to
211  * unpredictable results.
212  */
213  ASSERT (n_packets > 0);
214 
215  /*
216  * Check for tx_vector overflow. If this fails it is a system configuration
217  * error. The ring should be sized big enough to handle the largest un-flowed
218  * off burst from a traffic manager. A larger size also helps performance
219  * a bit because it decreases the probability of having to issue two tx_burst
220  * calls due to a ring wrap.
221  */
222  ASSERT (n_packets < xd->nb_tx_desc);
223  ASSERT (ring->tx_tail == 0);
224 
225  n_retry = 16;
226  queue_id = vm->thread_index;
227 
228  do
229  {
230  /* start the burst at the tail */
231  tx_tail = ring->tx_tail % xd->nb_tx_desc;
232 
233  /*
234  * This device only supports one TX queue,
235  * and we're running multi-threaded...
236  */
237  if (PREDICT_FALSE (xd->lockp != 0))
238  {
239  queue_id = queue_id % xd->tx_q_used;
240  while (__sync_lock_test_and_set (xd->lockp[queue_id], 1))
241  /* zzzz */
242  queue_id = (queue_id + 1) % xd->tx_q_used;
243  }
244 
245  if (PREDICT_FALSE (xd->flags & DPDK_DEVICE_FLAG_HQOS)) /* HQoS ON */
246  {
247  /* no wrap, transmit in one burst */
249  &xd->hqos_wt[vm->thread_index];
250 
251  ASSERT (hqos->swq != NULL);
252 
254  &tx_vector[tx_tail], tx_head - tx_tail);
255  rv = rte_ring_sp_enqueue_burst (hqos->swq,
256  (void **) &tx_vector[tx_tail],
257 #if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0)
258  (uint16_t) (tx_head - tx_tail), 0);
259 #else
260  (uint16_t) (tx_head - tx_tail));
261 #endif
262  }
263  else if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
264  {
265  /* no wrap, transmit in one burst */
266  rv = rte_eth_tx_burst (xd->device_index,
267  (uint16_t) queue_id,
268  &tx_vector[tx_tail],
269  (uint16_t) (tx_head - tx_tail));
270  }
271  else
272  {
273  ASSERT (0);
274  rv = 0;
275  }
276 
277  if (PREDICT_FALSE (xd->lockp != 0))
278  *xd->lockp[queue_id] = 0;
279 
280  if (PREDICT_FALSE (rv < 0))
281  {
282  // emit non-fatal message, bump counter
283  vnet_main_t *vnm = dm->vnet_main;
285  u32 node_index;
286 
287  node_index = vec_elt_at_index (im->hw_interfaces,
288  xd->hw_if_index)->tx_node_index;
289 
290  vlib_error_count (vm, node_index, DPDK_TX_FUNC_ERROR_BAD_RETVAL, 1);
291  clib_warning ("rte_eth_tx_burst[%d]: error %d", xd->device_index,
292  rv);
293  return n_packets; // untransmitted packets
294  }
295  ring->tx_tail += (u16) rv;
296  n_packets -= (uint16_t) rv;
297  }
298  while (rv && n_packets && (n_retry > 0));
299 
300  return n_packets;
301 }
302 
305 {
306  vlib_buffer_t *b;
307  struct rte_mbuf *mb;
308  b = vlib_get_buffer (vm, bi);
309  mb = rte_mbuf_from_vlib_buffer (b);
310  CLIB_PREFETCH (mb, 2 * CLIB_CACHE_LINE_BYTES, STORE);
312 }
313 
316  vlib_buffer_t * b, u32 bi, struct rte_mbuf **mbp)
317 {
318  dpdk_main_t *dm = &dpdk_main;
319  u32 my_cpu = vm->thread_index;
320  struct rte_mbuf *mb_new;
321 
322  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_RECYCLE) == 0)
323  return;
324 
325  mb_new = dpdk_replicate_packet_mb (b);
326  if (PREDICT_FALSE (mb_new == 0))
327  {
328  vlib_error_count (vm, node->node_index,
329  DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
331  }
332  else
333  *mbp = mb_new;
334 
335  vec_add1 (dm->recycle[my_cpu], bi);
336 }
337 
338 /*
339  * Transmits the packets on the frame to the interface associated with the
340  * node. It first copies packets on the frame to a tx_vector containing the
341  * rte_mbuf pointers. It then passes this vector to tx_burst_vector_internal
342  * which calls the dpdk tx_burst function.
343  */
344 static uword
346  vlib_node_runtime_t * node, vlib_frame_t * f)
347 {
348  dpdk_main_t *dm = &dpdk_main;
349  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
351  u32 n_packets = f->n_vectors;
352  u32 n_left;
353  u32 *from;
354  struct rte_mbuf **tx_vector;
355  u16 i;
356  u16 nb_tx_desc = xd->nb_tx_desc;
357  int queue_id;
358  u32 my_cpu;
359  u32 tx_pkts = 0;
360  tx_ring_hdr_t *ring;
361  u32 n_on_ring;
362 
363  my_cpu = vm->thread_index;
364 
365  queue_id = my_cpu;
366 
367  tx_vector = xd->tx_vectors[queue_id];
368  ring = vec_header (tx_vector, sizeof (*ring));
369 
370  n_on_ring = ring->tx_head - ring->tx_tail;
371  from = vlib_frame_vector_args (f);
372 
373  ASSERT (n_packets <= VLIB_FRAME_SIZE);
374 
375  if (PREDICT_FALSE (n_on_ring + n_packets > nb_tx_desc))
376  {
377  /*
378  * Overflowing the ring should never happen.
379  * If it does then drop the whole frame.
380  */
381  vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_RING_FULL,
382  n_packets);
383 
384  while (n_packets--)
385  {
386  u32 bi0 = from[n_packets];
387  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
388  struct rte_mbuf *mb0 = rte_mbuf_from_vlib_buffer (b0);
389  rte_pktmbuf_free (mb0);
390  }
391  return n_on_ring;
392  }
393 
394  if (PREDICT_FALSE (dm->tx_pcap_enable))
395  {
396  n_left = n_packets;
397  while (n_left > 0)
398  {
399  u32 bi0 = from[0];
400  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
401  if (dm->pcap_sw_if_index == 0 ||
402  dm->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_TX])
403  pcap_add_buffer (&dm->pcap_main, vm, bi0, 512);
404  from++;
405  n_left--;
406  }
407  }
408 
409  from = vlib_frame_vector_args (f);
410  n_left = n_packets;
411  i = ring->tx_head % nb_tx_desc;
412 
413  while (n_left >= 8)
414  {
415  u32 bi0, bi1, bi2, bi3;
416  struct rte_mbuf *mb0, *mb1, *mb2, *mb3;
417  vlib_buffer_t *b0, *b1, *b2, *b3;
418  u32 or_flags;
419 
420  dpdk_prefetch_buffer_by_index (vm, from[4]);
421  dpdk_prefetch_buffer_by_index (vm, from[5]);
422  dpdk_prefetch_buffer_by_index (vm, from[6]);
423  dpdk_prefetch_buffer_by_index (vm, from[7]);
424 
425  bi0 = from[0];
426  bi1 = from[1];
427  bi2 = from[2];
428  bi3 = from[3];
429  from += 4;
430 
431  b0 = vlib_get_buffer (vm, bi0);
432  b1 = vlib_get_buffer (vm, bi1);
433  b2 = vlib_get_buffer (vm, bi2);
434  b3 = vlib_get_buffer (vm, bi3);
435 
436  or_flags = b0->flags | b1->flags | b2->flags | b3->flags;
437 
438  if (or_flags & VLIB_BUFFER_NEXT_PRESENT)
439  {
440  dpdk_validate_rte_mbuf (vm, b0, 1);
441  dpdk_validate_rte_mbuf (vm, b1, 1);
442  dpdk_validate_rte_mbuf (vm, b2, 1);
443  dpdk_validate_rte_mbuf (vm, b3, 1);
444  }
445  else
446  {
447  dpdk_validate_rte_mbuf (vm, b0, 0);
448  dpdk_validate_rte_mbuf (vm, b1, 0);
449  dpdk_validate_rte_mbuf (vm, b2, 0);
450  dpdk_validate_rte_mbuf (vm, b3, 0);
451  }
452 
453  mb0 = rte_mbuf_from_vlib_buffer (b0);
454  mb1 = rte_mbuf_from_vlib_buffer (b1);
455  mb2 = rte_mbuf_from_vlib_buffer (b2);
456  mb3 = rte_mbuf_from_vlib_buffer (b3);
457 
458  if (PREDICT_FALSE (or_flags & VLIB_BUFFER_RECYCLE))
459  {
460  dpdk_buffer_recycle (vm, node, b0, bi0, &mb0);
461  dpdk_buffer_recycle (vm, node, b1, bi1, &mb1);
462  dpdk_buffer_recycle (vm, node, b2, bi2, &mb2);
463  dpdk_buffer_recycle (vm, node, b3, bi3, &mb3);
464 
465  /* dont enqueue packets if replication failed as they must
466  be sent back to recycle */
467  if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
468  tx_vector[i++ % nb_tx_desc] = mb0;
469  if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_REPL_FAIL) == 0))
470  tx_vector[i++ % nb_tx_desc] = mb1;
471  if (PREDICT_TRUE ((b2->flags & VLIB_BUFFER_REPL_FAIL) == 0))
472  tx_vector[i++ % nb_tx_desc] = mb2;
473  if (PREDICT_TRUE ((b3->flags & VLIB_BUFFER_REPL_FAIL) == 0))
474  tx_vector[i++ % nb_tx_desc] = mb3;
475  }
476  else
477  {
478  if (PREDICT_FALSE (i + 3 >= nb_tx_desc))
479  {
480  tx_vector[i++ % nb_tx_desc] = mb0;
481  tx_vector[i++ % nb_tx_desc] = mb1;
482  tx_vector[i++ % nb_tx_desc] = mb2;
483  tx_vector[i++ % nb_tx_desc] = mb3;
484  i %= nb_tx_desc;
485  }
486  else
487  {
488  tx_vector[i++] = mb0;
489  tx_vector[i++] = mb1;
490  tx_vector[i++] = mb2;
491  tx_vector[i++] = mb3;
492  }
493  }
494 
495 
497  {
498  if (b0->flags & VLIB_BUFFER_IS_TRACED)
499  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
500  if (b1->flags & VLIB_BUFFER_IS_TRACED)
501  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi1, b1);
502  if (b2->flags & VLIB_BUFFER_IS_TRACED)
503  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi2, b2);
504  if (b3->flags & VLIB_BUFFER_IS_TRACED)
505  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi3, b3);
506  }
507 
508  n_left -= 4;
509  }
510  while (n_left > 0)
511  {
512  u32 bi0;
513  struct rte_mbuf *mb0;
514  vlib_buffer_t *b0;
515 
516  bi0 = from[0];
517  from++;
518 
519  b0 = vlib_get_buffer (vm, bi0);
520 
521  dpdk_validate_rte_mbuf (vm, b0, 1);
522 
523  mb0 = rte_mbuf_from_vlib_buffer (b0);
524  dpdk_buffer_recycle (vm, node, b0, bi0, &mb0);
525 
527  if (b0->flags & VLIB_BUFFER_IS_TRACED)
528  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
529 
530  if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
531  {
532  tx_vector[i % nb_tx_desc] = mb0;
533  i++;
534  }
535  n_left--;
536  }
537 
538  /* account for additional packets in the ring */
539  ring->tx_head += n_packets;
540  n_on_ring = ring->tx_head - ring->tx_tail;
541 
542  /* transmit as many packets as possible */
543  n_packets = tx_burst_vector_internal (vm, xd, tx_vector);
544 
545  /*
546  * tx_pkts is the number of packets successfully transmitted
547  * This is the number originally on ring minus the number remaining on ring
548  */
549  tx_pkts = n_on_ring - n_packets;
550 
551  {
552  /* If there is no callback then drop any non-transmitted packets */
553  if (PREDICT_FALSE (n_packets))
554  {
556  vnet_main_t *vnm = vnet_get_main ();
557 
560 
561  vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
562  n_packets);
563 
564  vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_PKT_DROP,
565  n_packets);
566 
567  while (n_packets--)
568  rte_pktmbuf_free (tx_vector[ring->tx_tail + n_packets]);
569  }
570 
571  /* Reset head/tail to avoid unnecessary wrap */
572  ring->tx_head = 0;
573  ring->tx_tail = 0;
574  }
575 
576  /* Recycle replicated buffers */
577  if (PREDICT_FALSE (vec_len (dm->recycle[my_cpu])))
578  {
579  vlib_buffer_free (vm, dm->recycle[my_cpu],
580  vec_len (dm->recycle[my_cpu]));
581  _vec_len (dm->recycle[my_cpu]) = 0;
582  }
583 
584  ASSERT (ring->tx_head >= ring->tx_tail);
585 
586  return tx_pkts;
587 }
588 
589 static void
591 {
592  dpdk_main_t *dm = &dpdk_main;
593  dpdk_device_t *xd = vec_elt_at_index (dm->devices, instance);
594 
595  /*
596  * Set the "last_cleared_stats" to the current stats, so that
597  * things appear to clear from a display perspective.
598  */
600 
601  clib_memcpy (&xd->last_cleared_stats, &xd->stats, sizeof (xd->stats));
604  sizeof (xd->last_cleared_xstats[0]));
605 
606 }
607 
608 static clib_error_t *
610 {
611  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
612  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
613  dpdk_main_t *dm = &dpdk_main;
615 
617  return clib_error_return (0, "Interface not initialized");
618 
619  if (is_up)
620  {
623  if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
624  dpdk_device_start (xd);
626  f64 now = vlib_time_now (dm->vlib_main);
627  dpdk_update_counters (xd, now);
628  dpdk_update_link_state (xd, now);
629  }
630  else
631  {
633  if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0)
634  dpdk_device_stop (xd);
636  }
637 
638  return /* no error */ 0;
639 }
640 
641 /*
642  * Dynamically redirect all pkts from a specific interface
643  * to the specified node
644  */
645 static void
647  u32 node_index)
648 {
649  dpdk_main_t *xm = &dpdk_main;
650  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
652 
653  /* Shut off redirection */
654  if (node_index == ~0)
655  {
656  xd->per_interface_next_index = node_index;
657  return;
658  }
659 
661  vlib_node_add_next (xm->vlib_main, dpdk_input_node.index, node_index);
662 }
663 
664 
665 static clib_error_t *
667  u32 hw_if_index,
668  struct vnet_sw_interface_t *st, int is_add)
669 {
670  dpdk_main_t *xm = &dpdk_main;
671  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
674  int r, vlan_offload;
675  u32 prev_subifs = xd->num_subifs;
676  clib_error_t *err = 0;
677 
678  if (is_add)
679  xd->num_subifs++;
680  else if (xd->num_subifs)
681  xd->num_subifs--;
682 
683  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
684  goto done;
685 
686  /* currently we program VLANS only for IXGBE VF and I40E VF */
687  if ((xd->pmd != VNET_DPDK_PMD_IXGBEVF) && (xd->pmd != VNET_DPDK_PMD_I40EVF))
688  goto done;
689 
690  if (t->sub.eth.flags.no_tags == 1)
691  goto done;
692 
693  if ((t->sub.eth.flags.one_tag != 1) || (t->sub.eth.flags.exact_match != 1))
694  {
695  xd->num_subifs = prev_subifs;
696  err = clib_error_return (0, "unsupported VLAN setup");
697  goto done;
698  }
699 
700  vlan_offload = rte_eth_dev_get_vlan_offload (xd->device_index);
701  vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
702 
703  if ((r = rte_eth_dev_set_vlan_offload (xd->device_index, vlan_offload)))
704  {
705  xd->num_subifs = prev_subifs;
706  err = clib_error_return (0, "rte_eth_dev_set_vlan_offload[%d]: err %d",
707  xd->device_index, r);
708  goto done;
709  }
710 
711 
712  if ((r =
713  rte_eth_dev_vlan_filter (xd->device_index, t->sub.eth.outer_vlan_id,
714  is_add)))
715  {
716  xd->num_subifs = prev_subifs;
717  err = clib_error_return (0, "rte_eth_dev_vlan_filter[%d]: err %d",
718  xd->device_index, r);
719  goto done;
720  }
721 
722 done:
723  if (xd->num_subifs)
725  else
727 
728  return err;
729 }
730 
731 /* *INDENT-OFF* */
733  .name = "dpdk",
734  .tx_function = dpdk_interface_tx,
735  .tx_function_n_errors = DPDK_TX_FUNC_N_ERROR,
736  .tx_function_error_strings = dpdk_tx_func_error_strings,
737  .format_device_name = format_dpdk_device_name,
738  .format_device = format_dpdk_device,
739  .format_tx_trace = format_dpdk_tx_dma_trace,
740  .clear_counters = dpdk_clear_hw_interface_counters,
741  .admin_up_down_function = dpdk_interface_admin_up_down,
742  .subif_add_del_function = dpdk_subif_add_del_function,
743  .rx_redirect_to_node = dpdk_set_interface_next_node,
744  .mac_addr_change_function = dpdk_set_mac_address,
745 };
746 
748 /* *INDENT-ON* */
749 
750 #define UP_DOWN_FLAG_EVENT 1
751 
752 uword
755 {
756  clib_error_t *error = 0;
757  uword event_type;
758  uword *event_data = 0;
759  u32 sw_if_index;
760  u32 flags;
761 
762  while (1)
763  {
765 
766  event_type = vlib_process_get_events (vm, &event_data);
767 
769 
770  switch (event_type)
771  {
772  case UP_DOWN_FLAG_EVENT:
773  {
774  if (vec_len (event_data) == 2)
775  {
776  sw_if_index = event_data[0];
777  flags = event_data[1];
778  error =
780  flags);
781  clib_error_report (error);
782  }
783  }
784  break;
785  }
786 
787  vec_reset_length (event_data);
788 
790 
791  }
792  return 0; /* or not */
793 }
794 
795 /* *INDENT-OFF* */
797  .function = admin_up_down_process,
798  .type = VLIB_NODE_TYPE_PROCESS,
799  .name = "admin-up-down-process",
800  .process_log2_n_stack_bytes = 17, // 256KB
801 };
802 /* *INDENT-ON* */
803 
804 /*
805  * fd.io coding-style-patch-verification: ON
806  *
807  * Local Variables:
808  * eval: (c-set-style "gnu")
809  * End:
810  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
u8 * default_mac_address
Definition: dpdk.h:219
vmrglw vmrglh hi
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:537
vlib_buffer_t buffer
Definition: dpdk.h:402
#define DPDK_DEVICE_FLAG_PMD_INIT_FAIL
Definition: dpdk.h:173
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:290
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:468
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:619
#define VLIB_BUFFER_RECYCLE
Definition: buffer.h:91
dpdk_main_t dpdk_main
Definition: init.c:36
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vnet_interface_main_t interface_main
Definition: vnet.h:56
vnet_device_class_t dpdk_device_class
#define PREDICT_TRUE(x)
Definition: clib.h:98
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:192
static_always_inline u32 tx_burst_vector_internal(vlib_main_t *vm, dpdk_device_t *xd, struct rte_mbuf **tx_vector)
Definition: device.c:190
static char * dpdk_tx_func_error_strings[]
Definition: device.c:41
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:51
u16 flags
Definition: dpdk.h:169
static void dpdk_tx_trace_buffer(dpdk_main_t *dm, vlib_node_runtime_t *node, dpdk_device_t *xd, u16 queue_id, u32 buffer_index, vlib_buffer_t *buffer)
Definition: device.c:112
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 thread_index
Definition: main.h:159
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
#define DPDK_DEVICE_FLAG_HQOS
Definition: dpdk.h:176
u32 per_interface_next_index
Definition: dpdk.h:157
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:78
u64 tx_tail
Definition: dpdk.h:113
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:397
struct rte_eth_xstat * last_cleared_xstats
Definition: dpdk.h:214
u16 num_subifs
Definition: dpdk.h:186
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:100
format_function_t format_dpdk_tx_dma_trace
Definition: dpdk.h:443
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1081
VNET_DEVICE_CLASS(af_packet_device_class)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define DPDK_DEVICE_FLAG_PMD
Definition: dpdk.h:172
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:599
struct rte_eth_stats stats
Definition: dpdk.h:210
#define VLIB_BUFFER_NEXT_PRESENT
Definition: buffer.h:87
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:67
#define static_always_inline
Definition: clib.h:85
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
#define VLIB_BUFFER_REPL_FAIL
Definition: buffer.h:90
vlib_node_registration_t dpdk_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_input_node)
Definition: node.c:671
static void dpdk_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: device.c:646
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:144
static uword dpdk_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
Definition: device.c:345
static vlib_node_registration_t admin_up_down_process_node
(constructor) VLIB_REGISTER_NODE (admin_up_down_process_node)
Definition: device.c:796
A collection of simple counters.
Definition: counter.h:58
u32 device_index
Definition: dpdk.h:151
dpdk_device_hqos_per_worker_thread_t * hqos_wt
Definition: dpdk.h:197
u32 pcap_sw_if_index
Definition: dpdk.h:359
vnet_hw_interface_t * hw_interfaces
Definition: interface.h:630
#define rte_mbuf_from_vlib_buffer(x)
Definition: dpdk_priv.h:16
void dpdk_device_start(dpdk_device_t *xd)
Definition: common.c:119
vnet_sub_interface_t sub
Definition: interface.h:596
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:71
pcap_main_t pcap_main
Definition: dpdk.h:357
void dpdk_hqos_metadata_set(dpdk_device_hqos_per_worker_thread_t *hqos, struct rte_mbuf **pkts, u32 n_pkts)
Definition: hqos.c:650
struct rte_mbuf mb
Definition: dpdk.h:400
static void pcap_add_buffer(pcap_main_t *pm, vlib_main_t *vm, u32 buffer_index, u32 n_bytes_in_trace)
Add buffer (vlib_buffer_t) to the trace.
Definition: pcap.h:201
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define VLIB_FRAME_SIZE
Definition: node.h:329
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:652
u16 tx_q_used
Definition: dpdk.h:189
u32 node_index
Node index.
Definition: node.h:441
u32 hw_if_index
Definition: dpdk.h:153
dpdk_tx_func_error_t
Definition: device.c:33
struct rte_mbuf * dpdk_replicate_packet_mb(vlib_buffer_t *b)
Definition: device.c:70
#define DPDK_DEVICE_FLAG_ADMIN_UP
Definition: dpdk.h:170
u32 ** recycle
Definition: dpdk.h:341
u16 n_vectors
Definition: node.h:345
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
dpdk_device_t * devices
Definition: dpdk.h:337
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:78
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
volatile u32 ** lockp
Definition: dpdk.h:148
#define clib_warning(format, args...)
Definition: error.h:59
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
#define clib_memcpy(a, b, c)
Definition: string.h:69
dpdk_pmd_t pmd
Definition: dpdk.h:166
format_function_t format_dpdk_device
Definition: dpdk.h:441
static_always_inline void dpdk_validate_rte_mbuf(vlib_main_t *vm, vlib_buffer_t *b, int maybe_multiseg)
Definition: device.c:135
void dpdk_device_stop(dpdk_device_t *xd)
Definition: common.c:163
struct rte_eth_xstat * xstats
Definition: dpdk.h:213
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:560
#define ASSERT(truth)
format_function_t format_dpdk_device_name
Definition: dpdk.h:440
unsigned int u32
Definition: types.h:88
u64 tx_head
Definition: dpdk.h:112
uword admin_up_down_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: device.c:753
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:109
struct rte_mempool ** pktmbuf_pools
Definition: dpdk.h:387
#define DPDK_DEVICE_FLAG_HAVE_SUBIF
Definition: dpdk.h:175
#define clib_error_report(e)
Definition: error.h:113
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:260
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1236
struct vnet_sub_interface_t::@151::@152::@154 flags
u8 n_add_refs
Number of additional references to this buffer.
Definition: buffer.h:124
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
static void dpdk_clear_hw_interface_counters(u32 instance)
Definition: device.c:590
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
#define foreach_dpdk_tx_func_error
Definition: device.c:27
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u8 admin_up_down_in_progress
Definition: dpdk.h:366
static clib_error_t * dpdk_set_mac_address(vnet_hw_interface_t *hi, char *address)
Definition: device.c:48
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:269
#define UP_DOWN_FLAG_EVENT
Definition: device.c:750
struct vnet_sub_interface_t::@151 eth
static clib_error_t * dpdk_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:609
#define VLIB_BUFFER_EXT_HDR_VALID
Definition: buffer.h:93
#define vnet_buffer(b)
Definition: buffer.h:304
static_always_inline void dpdk_prefetch_buffer_by_index(vlib_main_t *vm, u32 bi)
Definition: device.c:304
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:144
static void * vec_header(void *v, uword header_bytes)
Find a user vector header.
Definition: vec_bootstrap.h:92
u8 data[0]
Packet data.
Definition: buffer.h:152
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:545
u16 flags
Copy of main node flags.
Definition: node.h:454
struct rte_eth_stats last_cleared_stats
Definition: dpdk.h:212
static clib_error_t * dpdk_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
Definition: device.c:666
static_always_inline void dpdk_buffer_recycle(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, u32 bi, struct rte_mbuf **mbp)
Definition: device.c:315
u32 flags
Definition: vhost-user.h:76
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
int tx_pcap_enable
Definition: dpdk.h:356
vnet_main_t * vnet_main
Definition: dpdk.h:383
u16 nb_tx_desc
Definition: dpdk.h:180
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
#define VLIB_DEVICE_TX_FUNCTION_MULTIARCH(dev, fn)
Definition: interface.h:235
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
vlib_main_t * vlib_main
Definition: dpdk.h:382