FD.io VPP  v16.09
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 <vnet/devices/dpdk/dpdk.h>
23 
24 #include "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 
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  {
63  return NULL;
64  }
65 }
66 
69  struct ether_addr mc_addr_vec[], int naddr)
70 {
71  int error;
72  dpdk_main_t *dm = &dpdk_main;
74 
75  error = rte_eth_dev_set_mc_addr_list (xd->device_index, mc_addr_vec, naddr);
76 
77  if (error)
78  {
79  return clib_error_return (0, "mc addr list failed: %d", error);
80  }
81  else
82  {
83  return NULL;
84  }
85 }
86 
87 struct rte_mbuf *
89 {
90  vlib_main_t *vm = vlib_get_main ();
92  struct rte_mbuf *first_mb = 0, *new_mb, *pkt_mb, **prev_mb_next = 0;
93  u8 nb_segs, nb_segs_left;
94  u32 copy_bytes;
95  unsigned socket_id = rte_socket_id ();
96 
97  ASSERT (bm->pktmbuf_pools[socket_id]);
98  pkt_mb = rte_mbuf_from_vlib_buffer (b);
99  nb_segs = pkt_mb->nb_segs;
100  for (nb_segs_left = nb_segs; nb_segs_left; nb_segs_left--)
101  {
102  if (PREDICT_FALSE (pkt_mb == 0))
103  {
104  clib_warning ("Missing %d mbuf chain segment(s): "
105  "(nb_segs = %d, nb_segs_left = %d)!",
106  nb_segs - nb_segs_left, nb_segs, nb_segs_left);
107  if (first_mb)
108  rte_pktmbuf_free (first_mb);
109  return NULL;
110  }
111  new_mb = rte_pktmbuf_alloc (bm->pktmbuf_pools[socket_id]);
112  if (PREDICT_FALSE (new_mb == 0))
113  {
114  if (first_mb)
115  rte_pktmbuf_free (first_mb);
116  return NULL;
117  }
118 
119  /*
120  * Copy packet info into 1st segment.
121  */
122  if (first_mb == 0)
123  {
124  first_mb = new_mb;
125  rte_pktmbuf_pkt_len (first_mb) = pkt_mb->pkt_len;
126  first_mb->nb_segs = pkt_mb->nb_segs;
127  first_mb->port = pkt_mb->port;
128 #ifdef DAW_FIXME // TX Offload support TBD
129  first_mb->vlan_macip = pkt_mb->vlan_macip;
130  first_mb->hash = pkt_mb->hash;
131  first_mb->ol_flags = pkt_mb->ol_flags
132 #endif
133  }
134  else
135  {
136  ASSERT (prev_mb_next != 0);
137  *prev_mb_next = new_mb;
138  }
139 
140  /*
141  * Copy packet segment data into new mbuf segment.
142  */
143  rte_pktmbuf_data_len (new_mb) = pkt_mb->data_len;
144  copy_bytes = pkt_mb->data_len + RTE_PKTMBUF_HEADROOM;
145  ASSERT (copy_bytes <= pkt_mb->buf_len);
146  clib_memcpy (new_mb->buf_addr, pkt_mb->buf_addr, copy_bytes);
147 
148  prev_mb_next = &new_mb->next;
149  pkt_mb = pkt_mb->next;
150  }
151 
152  ASSERT (pkt_mb == 0);
153  __rte_mbuf_sanity_check (first_mb, 1);
154 
155  return first_mb;
156 }
157 
158 struct rte_mbuf *
160 {
161  vlib_main_t *vm = vlib_get_main ();
163  struct rte_mbuf *first_mb = 0, *new_mb, *pkt_mb, **prev_mb_next = 0;
164  u8 nb_segs, nb_segs_left;
165  unsigned socket_id = rte_socket_id ();
166 
167  ASSERT (bm->pktmbuf_pools[socket_id]);
168  pkt_mb = rte_mbuf_from_vlib_buffer (b);
169  nb_segs = pkt_mb->nb_segs;
170  for (nb_segs_left = nb_segs; nb_segs_left; nb_segs_left--)
171  {
172  if (PREDICT_FALSE (pkt_mb == 0))
173  {
174  clib_warning ("Missing %d mbuf chain segment(s): "
175  "(nb_segs = %d, nb_segs_left = %d)!",
176  nb_segs - nb_segs_left, nb_segs, nb_segs_left);
177  if (first_mb)
178  rte_pktmbuf_free (first_mb);
179  return NULL;
180  }
181  new_mb = rte_pktmbuf_clone (pkt_mb, bm->pktmbuf_pools[socket_id]);
182  if (PREDICT_FALSE (new_mb == 0))
183  {
184  if (first_mb)
185  rte_pktmbuf_free (first_mb);
186  return NULL;
187  }
188 
189  /*
190  * Copy packet info into 1st segment.
191  */
192  if (first_mb == 0)
193  {
194  first_mb = new_mb;
195  rte_pktmbuf_pkt_len (first_mb) = pkt_mb->pkt_len;
196  first_mb->nb_segs = pkt_mb->nb_segs;
197  first_mb->port = pkt_mb->port;
198 #ifdef DAW_FIXME // TX Offload support TBD
199  first_mb->vlan_macip = pkt_mb->vlan_macip;
200  first_mb->hash = pkt_mb->hash;
201  first_mb->ol_flags = pkt_mb->ol_flags
202 #endif
203  }
204  else
205  {
206  ASSERT (prev_mb_next != 0);
207  *prev_mb_next = new_mb;
208  }
209 
210  /*
211  * Copy packet segment data into new mbuf segment.
212  */
213  rte_pktmbuf_data_len (new_mb) = pkt_mb->data_len;
214 
215  prev_mb_next = &new_mb->next;
216  pkt_mb = pkt_mb->next;
217  }
218 
219  ASSERT (pkt_mb == 0);
220  __rte_mbuf_sanity_check (first_mb, 1);
221 
222  return first_mb;
223 
224 
225 }
226 
227 static void
229  vlib_node_runtime_t * node,
230  dpdk_device_t * xd,
231  u16 queue_id, u32 buffer_index, vlib_buffer_t * buffer)
232 {
233  vlib_main_t *vm = vlib_get_main ();
235  struct rte_mbuf *mb;
236 
237  mb = rte_mbuf_from_vlib_buffer (buffer);
238 
239  t0 = vlib_add_trace (vm, node, buffer, sizeof (t0[0]));
240  t0->queue_index = queue_id;
241  t0->device_index = xd->device_index;
242  t0->buffer_index = buffer_index;
243  clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
244  clib_memcpy (&t0->buffer, buffer,
245  sizeof (buffer[0]) - sizeof (buffer->pre_data));
246  clib_memcpy (t0->buffer.pre_data, buffer->data + buffer->current_data,
247  sizeof (t0->buffer.pre_data));
248 }
249 
250 /*
251  * This function calls the dpdk's tx_burst function to transmit the packets
252  * on the tx_vector. It manages a lock per-device if the device does not
253  * support multiple queues. It returns the number of packets untransmitted
254  * on the tx_vector. If all packets are transmitted (the normal case), the
255  * function returns 0.
256  *
257  * The tx_burst function may not be able to transmit all packets because the
258  * dpdk ring is full. If a flowcontrol callback function has been configured
259  * then the function simply returns. If no callback has been configured, the
260  * function will retry calling tx_burst with the remaining packets. This will
261  * continue until all packets are transmitted or tx_burst indicates no packets
262  * could be transmitted. (The caller can drop the remaining packets.)
263  *
264  * The function assumes there is at least one packet on the tx_vector.
265  */
268  dpdk_device_t * xd,
269  struct rte_mbuf **tx_vector)
270 {
271  dpdk_main_t *dm = &dpdk_main;
272  u32 n_packets;
273  u32 tx_head;
274  u32 tx_tail;
275  u32 n_retry;
276  int rv;
277  int queue_id;
278  tx_ring_hdr_t *ring;
279 
280  ring = vec_header (tx_vector, sizeof (*ring));
281 
282  n_packets = ring->tx_head - ring->tx_tail;
283 
284  tx_head = ring->tx_head % DPDK_TX_RING_SIZE;
285 
286  /*
287  * Ensure rte_eth_tx_burst is not called with 0 packets, which can lead to
288  * unpredictable results.
289  */
290  ASSERT (n_packets > 0);
291 
292  /*
293  * Check for tx_vector overflow. If this fails it is a system configuration
294  * error. The ring should be sized big enough to handle the largest un-flowed
295  * off burst from a traffic manager. A larger size also helps performance
296  * a bit because it decreases the probability of having to issue two tx_burst
297  * calls due to a ring wrap.
298  */
299  ASSERT (n_packets < DPDK_TX_RING_SIZE);
300 
301  /*
302  * If there is no flowcontrol callback, there is only temporary buffering
303  * on the tx_vector and so the tail should always be 0.
304  */
305  ASSERT (dm->flowcontrol_callback || ring->tx_tail == 0);
306 
307  /*
308  * If there is a flowcontrol callback, don't retry any incomplete tx_bursts.
309  * Apply backpressure instead. If there is no callback, keep retrying until
310  * a tx_burst sends no packets. n_retry of 255 essentially means no retry
311  * limit.
312  */
313  n_retry = dm->flowcontrol_callback ? 0 : 255;
314 
315  queue_id = vm->cpu_index;
316 
317  do
318  {
319  /* start the burst at the tail */
320  tx_tail = ring->tx_tail % DPDK_TX_RING_SIZE;
321 
322  /*
323  * This device only supports one TX queue,
324  * and we're running multi-threaded...
325  */
327  xd->lockp != 0))
328  {
329  queue_id = queue_id % xd->tx_q_used;
330  while (__sync_lock_test_and_set (xd->lockp[queue_id], 1))
331  /* zzzz */
332  queue_id = (queue_id + 1) % xd->tx_q_used;
333  }
334 
336  {
337  if (PREDICT_TRUE (tx_head > tx_tail))
338  {
339  /* no wrap, transmit in one burst */
340  rv = rte_eth_tx_burst (xd->device_index,
341  (uint16_t) queue_id,
342  &tx_vector[tx_tail],
343  (uint16_t) (tx_head - tx_tail));
344  }
345  else
346  {
347  /*
348  * This can only happen if there is a flowcontrol callback.
349  * We need to split the transmit into two calls: one for
350  * the packets up to the wrap point, and one to continue
351  * at the start of the ring.
352  * Transmit pkts up to the wrap point.
353  */
354  rv = rte_eth_tx_burst (xd->device_index,
355  (uint16_t) queue_id,
356  &tx_vector[tx_tail],
358  tx_tail));
359 
360  /*
361  * If we transmitted everything we wanted, then allow 1 retry
362  * so we can try to transmit the rest. If we didn't transmit
363  * everything, stop now.
364  */
365  n_retry = (rv == DPDK_TX_RING_SIZE - tx_tail) ? 1 : 0;
366  }
367  }
368 #if DPDK_VHOST_USER
369  else if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
370  {
371  u32 offset = 0;
372  if (xd->need_txlock)
373  {
374  queue_id = 0;
375  while (__sync_lock_test_and_set (xd->lockp[queue_id], 1));
376  }
377  else
378  {
380  vec_foreach (dq, dm->devices_by_cpu[vm->cpu_index])
381  {
382  if (xd->device_index == dq->device)
383  break;
384  }
385  assert (dq);
386  offset = dq->queue_id * VIRTIO_QNUM;
387  }
388  if (PREDICT_TRUE (tx_head > tx_tail))
389  {
390  int i;
391  u32 bytes = 0;
392  struct rte_mbuf **pkts = &tx_vector[tx_tail];
393  for (i = 0; i < (tx_head - tx_tail); i++)
394  {
395  struct rte_mbuf *buff = pkts[i];
396  bytes += rte_pktmbuf_data_len (buff);
397  }
398 
399  /* no wrap, transmit in one burst */
400  rv =
401  rte_vhost_enqueue_burst (&xd->vu_vhost_dev,
402  offset + VIRTIO_RXQ,
403  &tx_vector[tx_tail],
404  (uint16_t) (tx_head - tx_tail));
405  if (PREDICT_TRUE (rv > 0))
406  {
407  dpdk_vu_vring *vring =
408  &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
409  vring->packets += rv;
410  vring->bytes += bytes;
411 
412  if (dpdk_vhost_user_want_interrupt
413  (xd, offset + VIRTIO_RXQ))
414  {
415  vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
416  vring->n_since_last_int += rv;
417 
418  f64 now = vlib_time_now (vm);
419  if (vring->int_deadline < now ||
420  vring->n_since_last_int >
422  dpdk_vhost_user_send_interrupt (vm, xd,
423  offset + VIRTIO_RXQ);
424  }
425 
426  int c = rv;
427  while (c--)
428  rte_pktmbuf_free (tx_vector[tx_tail + c]);
429  }
430  }
431  else
432  {
433  /*
434  * If we transmitted everything we wanted, then allow 1 retry
435  * so we can try to transmit the rest. If we didn't transmit
436  * everything, stop now.
437  */
438  int i;
439  u32 bytes = 0;
440  struct rte_mbuf **pkts = &tx_vector[tx_tail];
441  for (i = 0; i < (DPDK_TX_RING_SIZE - tx_tail); i++)
442  {
443  struct rte_mbuf *buff = pkts[i];
444  bytes += rte_pktmbuf_data_len (buff);
445  }
446  rv =
447  rte_vhost_enqueue_burst (&xd->vu_vhost_dev,
448  offset + VIRTIO_RXQ,
449  &tx_vector[tx_tail],
451  tx_tail));
452 
453  if (PREDICT_TRUE (rv > 0))
454  {
455  dpdk_vu_vring *vring =
456  &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
457  vring->packets += rv;
458  vring->bytes += bytes;
459 
460  if (dpdk_vhost_user_want_interrupt
461  (xd, offset + VIRTIO_RXQ))
462  {
463  vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
464  vring->n_since_last_int += rv;
465 
466  f64 now = vlib_time_now (vm);
467  if (vring->int_deadline < now ||
468  vring->n_since_last_int >
470  dpdk_vhost_user_send_interrupt (vm, xd,
471  offset + VIRTIO_RXQ);
472  }
473 
474  int c = rv;
475  while (c--)
476  rte_pktmbuf_free (tx_vector[tx_tail + c]);
477  }
478 
479  n_retry = (rv == DPDK_TX_RING_SIZE - tx_tail) ? 1 : 0;
480  }
481 
482  if (xd->need_txlock)
483  *xd->lockp[queue_id] = 0;
484  }
485 #endif
486 #if RTE_LIBRTE_KNI
487  else if (xd->dev_type == VNET_DPDK_DEV_KNI)
488  {
489  if (PREDICT_TRUE (tx_head > tx_tail))
490  {
491  /* no wrap, transmit in one burst */
492  rv = rte_kni_tx_burst (xd->kni,
493  &tx_vector[tx_tail],
494  (uint16_t) (tx_head - tx_tail));
495  }
496  else
497  {
498  /*
499  * This can only happen if there is a flowcontrol callback.
500  * We need to split the transmit into two calls: one for
501  * the packets up to the wrap point, and one to continue
502  * at the start of the ring.
503  * Transmit pkts up to the wrap point.
504  */
505  rv = rte_kni_tx_burst (xd->kni,
506  &tx_vector[tx_tail],
508  tx_tail));
509 
510  /*
511  * If we transmitted everything we wanted, then allow 1 retry
512  * so we can try to transmit the rest. If we didn't transmit
513  * everything, stop now.
514  */
515  n_retry = (rv == DPDK_TX_RING_SIZE - tx_tail) ? 1 : 0;
516  }
517  }
518 #endif
519  else
520  {
521  ASSERT (0);
522  rv = 0;
523  }
524 
526  xd->lockp != 0))
527  *xd->lockp[queue_id] = 0;
528 
529  if (PREDICT_FALSE (rv < 0))
530  {
531  // emit non-fatal message, bump counter
532  vnet_main_t *vnm = dm->vnet_main;
534  u32 node_index;
535 
536  node_index = vec_elt_at_index (im->hw_interfaces,
537  xd->vlib_hw_if_index)->tx_node_index;
538 
539  vlib_error_count (vm, node_index, DPDK_TX_FUNC_ERROR_BAD_RETVAL, 1);
540  clib_warning ("rte_eth_tx_burst[%d]: error %d", xd->device_index,
541  rv);
542  return n_packets; // untransmitted packets
543  }
544  ring->tx_tail += (u16) rv;
545  n_packets -= (uint16_t) rv;
546  }
547  while (rv && n_packets && (n_retry > 0));
548 
549  return n_packets;
550 }
551 
552 
553 /*
554  * This function transmits any packets on the interface's tx_vector and returns
555  * the number of packets untransmitted on the tx_vector. If the tx_vector is
556  * empty the function simply returns 0.
557  *
558  * It is intended to be called by a traffic manager which has flowed-off an
559  * interface to see if the interface can be flowed-on again.
560  */
561 u32
563 {
564  dpdk_main_t *dm = &dpdk_main;
565  dpdk_device_t *xd;
566  int queue_id;
567  struct rte_mbuf **tx_vector;
568  tx_ring_hdr_t *ring;
569 
570  /* param is dev_instance and not hw_if_index to save another lookup */
571  xd = vec_elt_at_index (dm->devices, dev_instance);
572 
573  queue_id = vm->cpu_index;
574  tx_vector = xd->tx_vectors[queue_id];
575 
576  /* If no packets on the ring, don't bother calling tx function */
577  ring = vec_header (tx_vector, sizeof (*ring));
578  if (ring->tx_head == ring->tx_tail)
579  {
580  return 0;
581  }
582 
583  return tx_burst_vector_internal (vm, xd, tx_vector);
584 }
585 
586 /*
587  * Transmits the packets on the frame to the interface associated with the
588  * node. It first copies packets on the frame to a tx_vector containing the
589  * rte_mbuf pointers. It then passes this vector to tx_burst_vector_internal
590  * which calls the dpdk tx_burst function.
591  *
592  * The tx_vector is treated slightly differently depending on whether or
593  * not a flowcontrol callback function has been configured. If there is no
594  * callback, the tx_vector is a temporary array of rte_mbuf packet pointers.
595  * Its entries are written and consumed before the function exits.
596  *
597  * If there is a callback then the transmit is being invoked in the presence
598  * of a traffic manager. Here the tx_vector is treated like a ring of rte_mbuf
599  * pointers. If not all packets can be transmitted, the untransmitted packets
600  * stay on the tx_vector until the next call. The callback allows the traffic
601  * manager to flow-off dequeues to the interface. The companion function
602  * dpdk_interface_tx_vector() allows the traffic manager to detect when
603  * it should flow-on the interface again.
604  */
605 static uword
607  vlib_node_runtime_t * node, vlib_frame_t * f)
608 {
609  dpdk_main_t *dm = &dpdk_main;
610  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
612  u32 n_packets = f->n_vectors;
613  u32 n_left;
614  u32 *from;
615  struct rte_mbuf **tx_vector;
616  int i;
617  int queue_id;
618  u32 my_cpu;
619  u32 tx_pkts = 0;
620  tx_ring_hdr_t *ring;
621  u32 n_on_ring;
622 
623  my_cpu = vm->cpu_index;
624 
625  queue_id = my_cpu;
626 
627  tx_vector = xd->tx_vectors[queue_id];
628  ring = vec_header (tx_vector, sizeof (*ring));
629 
630  n_on_ring = ring->tx_head - ring->tx_tail;
631  from = vlib_frame_vector_args (f);
632 
633  ASSERT (n_packets <= VLIB_FRAME_SIZE);
634 
635  if (PREDICT_FALSE (n_on_ring + n_packets > DPDK_TX_RING_SIZE))
636  {
637  /*
638  * Overflowing the ring should never happen.
639  * If it does then drop the whole frame.
640  */
641  vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_RING_FULL,
642  n_packets);
643 
644  while (n_packets--)
645  {
646  u32 bi0 = from[n_packets];
647  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
648  struct rte_mbuf *mb0 = rte_mbuf_from_vlib_buffer (b0);
649  rte_pktmbuf_free (mb0);
650  }
651  return n_on_ring;
652  }
653 
654  if (PREDICT_FALSE (dm->tx_pcap_enable))
655  {
656  n_left = n_packets;
657  while (n_left > 0)
658  {
659  u32 bi0 = from[0];
660  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
661  if (dm->pcap_sw_if_index == 0 ||
662  dm->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_TX])
663  pcap_add_buffer (&dm->pcap_main, vm, bi0, 512);
664  from++;
665  n_left--;
666  }
667  }
668 
669  from = vlib_frame_vector_args (f);
670  n_left = n_packets;
671  i = ring->tx_head % DPDK_TX_RING_SIZE;
672 
673  while (n_left >= 4)
674  {
675  u32 bi0, bi1;
676  u32 pi0, pi1;
677  struct rte_mbuf *mb0, *mb1;
678  struct rte_mbuf *prefmb0, *prefmb1;
679  vlib_buffer_t *b0, *b1;
680  vlib_buffer_t *pref0, *pref1;
681  i16 delta0, delta1;
682  u16 new_data_len0, new_data_len1;
683  u16 new_pkt_len0, new_pkt_len1;
684  u32 any_clone;
685 
686  pi0 = from[2];
687  pi1 = from[3];
688  pref0 = vlib_get_buffer (vm, pi0);
689  pref1 = vlib_get_buffer (vm, pi1);
690 
691  prefmb0 = rte_mbuf_from_vlib_buffer (pref0);
692  prefmb1 = rte_mbuf_from_vlib_buffer (pref1);
693 
694  CLIB_PREFETCH (prefmb0, CLIB_CACHE_LINE_BYTES, LOAD);
695  CLIB_PREFETCH (pref0, CLIB_CACHE_LINE_BYTES, LOAD);
696  CLIB_PREFETCH (prefmb1, CLIB_CACHE_LINE_BYTES, LOAD);
697  CLIB_PREFETCH (pref1, CLIB_CACHE_LINE_BYTES, LOAD);
698 
699  bi0 = from[0];
700  bi1 = from[1];
701  from += 2;
702 
703  b0 = vlib_get_buffer (vm, bi0);
704  b1 = vlib_get_buffer (vm, bi1);
705 
706  mb0 = rte_mbuf_from_vlib_buffer (b0);
707  mb1 = rte_mbuf_from_vlib_buffer (b1);
708 
709  any_clone = (b0->flags & VLIB_BUFFER_RECYCLE)
710  | (b1->flags & VLIB_BUFFER_RECYCLE);
711  if (PREDICT_FALSE (any_clone != 0))
712  {
713  if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_RECYCLE) != 0))
714  {
715  struct rte_mbuf *mb0_new = dpdk_replicate_packet_mb (b0);
716  if (PREDICT_FALSE (mb0_new == 0))
717  {
718  vlib_error_count (vm, node->node_index,
719  DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
721  }
722  else
723  mb0 = mb0_new;
724  vec_add1 (dm->recycle[my_cpu], bi0);
725  }
726  if (PREDICT_FALSE ((b1->flags & VLIB_BUFFER_RECYCLE) != 0))
727  {
728  struct rte_mbuf *mb1_new = dpdk_replicate_packet_mb (b1);
729  if (PREDICT_FALSE (mb1_new == 0))
730  {
731  vlib_error_count (vm, node->node_index,
732  DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
734  }
735  else
736  mb1 = mb1_new;
737  vec_add1 (dm->recycle[my_cpu], bi1);
738  }
739  }
740 
741  delta0 = PREDICT_FALSE (b0->flags & VLIB_BUFFER_REPL_FAIL) ? 0 :
742  vlib_buffer_length_in_chain (vm, b0) - (i16) mb0->pkt_len;
743  delta1 = PREDICT_FALSE (b1->flags & VLIB_BUFFER_REPL_FAIL) ? 0 :
744  vlib_buffer_length_in_chain (vm, b1) - (i16) mb1->pkt_len;
745 
746  new_data_len0 = (u16) ((i16) mb0->data_len + delta0);
747  new_data_len1 = (u16) ((i16) mb1->data_len + delta1);
748  new_pkt_len0 = (u16) ((i16) mb0->pkt_len + delta0);
749  new_pkt_len1 = (u16) ((i16) mb1->pkt_len + delta1);
750 
751  b0->current_length = new_data_len0;
752  b1->current_length = new_data_len1;
753  mb0->data_len = new_data_len0;
754  mb1->data_len = new_data_len1;
755  mb0->pkt_len = new_pkt_len0;
756  mb1->pkt_len = new_pkt_len1;
757 
758  mb0->data_off = (PREDICT_FALSE (b0->flags & VLIB_BUFFER_REPL_FAIL)) ?
759  mb0->data_off : (u16) (RTE_PKTMBUF_HEADROOM + b0->current_data);
760  mb1->data_off = (PREDICT_FALSE (b1->flags & VLIB_BUFFER_REPL_FAIL)) ?
761  mb1->data_off : (u16) (RTE_PKTMBUF_HEADROOM + b1->current_data);
762 
764  {
765  if (b0->flags & VLIB_BUFFER_IS_TRACED)
766  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
767  if (b1->flags & VLIB_BUFFER_IS_TRACED)
768  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi1, b1);
769  }
770 
771  if (PREDICT_TRUE (any_clone == 0))
772  {
773  tx_vector[i % DPDK_TX_RING_SIZE] = mb0;
774  i++;
775  tx_vector[i % DPDK_TX_RING_SIZE] = mb1;
776  i++;
777  }
778  else
779  {
780  /* cloning was done, need to check for failure */
781  if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
782  {
783  tx_vector[i % DPDK_TX_RING_SIZE] = mb0;
784  i++;
785  }
786  if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_REPL_FAIL) == 0))
787  {
788  tx_vector[i % DPDK_TX_RING_SIZE] = mb1;
789  i++;
790  }
791  }
792 
793  n_left -= 2;
794  }
795  while (n_left > 0)
796  {
797  u32 bi0;
798  struct rte_mbuf *mb0;
799  vlib_buffer_t *b0;
800  i16 delta0;
801  u16 new_data_len0;
802  u16 new_pkt_len0;
803 
804  bi0 = from[0];
805  from++;
806 
807  b0 = vlib_get_buffer (vm, bi0);
808 
809  mb0 = rte_mbuf_from_vlib_buffer (b0);
810  if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_RECYCLE) != 0))
811  {
812  struct rte_mbuf *mb0_new = dpdk_replicate_packet_mb (b0);
813  if (PREDICT_FALSE (mb0_new == 0))
814  {
815  vlib_error_count (vm, node->node_index,
816  DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
818  }
819  else
820  mb0 = mb0_new;
821  vec_add1 (dm->recycle[my_cpu], bi0);
822  }
823 
824  delta0 = PREDICT_FALSE (b0->flags & VLIB_BUFFER_REPL_FAIL) ? 0 :
825  vlib_buffer_length_in_chain (vm, b0) - (i16) mb0->pkt_len;
826 
827  new_data_len0 = (u16) ((i16) mb0->data_len + delta0);
828  new_pkt_len0 = (u16) ((i16) mb0->pkt_len + delta0);
829 
830  b0->current_length = new_data_len0;
831  mb0->data_len = new_data_len0;
832  mb0->pkt_len = new_pkt_len0;
833  mb0->data_off = (PREDICT_FALSE (b0->flags & VLIB_BUFFER_REPL_FAIL)) ?
834  mb0->data_off : (u16) (RTE_PKTMBUF_HEADROOM + b0->current_data);
835 
837  if (b0->flags & VLIB_BUFFER_IS_TRACED)
838  dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
839 
840  if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
841  {
842  tx_vector[i % DPDK_TX_RING_SIZE] = mb0;
843  i++;
844  }
845  n_left--;
846  }
847 
848  /* account for additional packets in the ring */
849  ring->tx_head += n_packets;
850  n_on_ring = ring->tx_head - ring->tx_tail;
851 
852  /* transmit as many packets as possible */
853  n_packets = tx_burst_vector_internal (vm, xd, tx_vector);
854 
855  /*
856  * tx_pkts is the number of packets successfully transmitted
857  * This is the number originally on ring minus the number remaining on ring
858  */
859  tx_pkts = n_on_ring - n_packets;
860 
861  if (PREDICT_FALSE (dm->flowcontrol_callback != 0))
862  {
863  if (PREDICT_FALSE (n_packets))
864  {
865  /* Callback may want to enable flowcontrol */
866  dm->flowcontrol_callback (vm, xd->vlib_hw_if_index,
867  ring->tx_head - ring->tx_tail);
868  }
869  else
870  {
871  /* Reset head/tail to avoid unnecessary wrap */
872  ring->tx_head = 0;
873  ring->tx_tail = 0;
874  }
875  }
876  else
877  {
878  /* If there is no callback then drop any non-transmitted packets */
879  if (PREDICT_FALSE (n_packets))
880  {
882  vnet_main_t *vnm = vnet_get_main ();
883 
886 
887  vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
888  n_packets);
889 
890  vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_PKT_DROP,
891  n_packets);
892 
893  while (n_packets--)
894  rte_pktmbuf_free (tx_vector[ring->tx_tail + n_packets]);
895  }
896 
897  /* Reset head/tail to avoid unnecessary wrap */
898  ring->tx_head = 0;
899  ring->tx_tail = 0;
900  }
901 
902  /* Recycle replicated buffers */
903  if (PREDICT_FALSE (vec_len (dm->recycle[my_cpu])))
904  {
905  vlib_buffer_free (vm, dm->recycle[my_cpu],
906  vec_len (dm->recycle[my_cpu]));
907  _vec_len (dm->recycle[my_cpu]) = 0;
908  }
909 
910  ASSERT (ring->tx_head >= ring->tx_tail);
911 
912  return tx_pkts;
913 }
914 
915 static int
917 {
918 #if DPDK_VHOST_USER
919  dpdk_main_t *dm = &dpdk_main;
921 
922  if (!xd || xd->dev_type != VNET_DPDK_DEV_VHOST_USER)
923  {
925  ("cannot renumber non-vhost-user interface (sw_if_index: %d)",
926  hi->sw_if_index);
927  return 0;
928  }
929 
930  xd->vu_if_id = new_dev_instance;
931 #endif
932  return 0;
933 }
934 
935 static void
937 {
938  dpdk_main_t *dm = &dpdk_main;
939  dpdk_device_t *xd = vec_elt_at_index (dm->devices, instance);
940 
941  /*
942  * DAW-FIXME: VMXNET3 device stop/start doesn't work,
943  * therefore fake the stop in the dpdk driver by
944  * silently dropping all of the incoming pkts instead of
945  * stopping the driver / hardware.
946  */
947  if (xd->admin_up != 0xff)
948  {
949  /*
950  * Set the "last_cleared_stats" to the current stats, so that
951  * things appear to clear from a display perspective.
952  */
954 
955  clib_memcpy (&xd->last_cleared_stats, &xd->stats, sizeof (xd->stats));
958  sizeof (xd->last_cleared_xstats[0]));
959  }
960  else
961  {
962  /*
963  * Internally rte_eth_xstats_reset() is calling rte_eth_stats_reset(),
964  * so we're only calling xstats_reset() here.
965  */
966  rte_eth_xstats_reset (xd->device_index);
967  memset (&xd->stats, 0, sizeof (xd->stats));
968  memset (&xd->last_stats, 0, sizeof (xd->last_stats));
969  }
970 
971 #if DPDK_VHOST_USER
973  {
974  int i;
975  for (i = 0; i < xd->rx_q_used * VIRTIO_QNUM; i++)
976  {
977  xd->vu_intf->vrings[i].packets = 0;
978  xd->vu_intf->vrings[i].bytes = 0;
979  }
980  }
981 #endif
982 }
983 
984 #ifdef RTE_LIBRTE_KNI
985 static int
986 kni_config_network_if (u8 port_id, u8 if_up)
987 {
988  vnet_main_t *vnm = vnet_get_main ();
989  dpdk_main_t *dm = &dpdk_main;
990  dpdk_device_t *xd;
991  uword *p;
992 
993  p = hash_get (dm->dpdk_device_by_kni_port_id, port_id);
994  if (p == 0)
995  {
996  clib_warning ("unknown interface");
997  return 0;
998  }
999  else
1000  {
1001  xd = vec_elt_at_index (dm->devices, p[0]);
1002  }
1003 
1006  ETH_LINK_FULL_DUPLEX : 0);
1007  return 0;
1008 }
1009 
1010 static int
1011 kni_change_mtu (u8 port_id, unsigned new_mtu)
1012 {
1013  vnet_main_t *vnm = vnet_get_main ();
1014  dpdk_main_t *dm = &dpdk_main;
1015  dpdk_device_t *xd;
1016  uword *p;
1017  vnet_hw_interface_t *hif;
1018 
1019  p = hash_get (dm->dpdk_device_by_kni_port_id, port_id);
1020  if (p == 0)
1021  {
1022  clib_warning ("unknown interface");
1023  return 0;
1024  }
1025  else
1026  {
1027  xd = vec_elt_at_index (dm->devices, p[0]);
1028  }
1029  hif = vnet_get_hw_interface (vnm, xd->vlib_hw_if_index);
1030 
1031  hif->max_packet_bytes = new_mtu;
1032 
1033  return 0;
1034 }
1035 #endif
1036 
1037 static clib_error_t *
1039 {
1040  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
1041  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
1042  dpdk_main_t *dm = &dpdk_main;
1044  int rv = 0;
1045 
1046 #ifdef RTE_LIBRTE_KNI
1047  if (xd->dev_type == VNET_DPDK_DEV_KNI)
1048  {
1049  if (is_up)
1050  {
1051  struct rte_kni_conf conf;
1052  struct rte_kni_ops ops;
1053  vlib_main_t *vm = vlib_get_main ();
1054  vlib_buffer_main_t *bm = vm->buffer_main;
1055  memset (&conf, 0, sizeof (conf));
1056  snprintf (conf.name, RTE_KNI_NAMESIZE, "vpp%u", xd->kni_port_id);
1057  conf.mbuf_size = VLIB_BUFFER_DATA_SIZE;
1058  memset (&ops, 0, sizeof (ops));
1059  ops.port_id = xd->kni_port_id;
1060  ops.change_mtu = kni_change_mtu;
1061  ops.config_network_if = kni_config_network_if;
1062 
1063  xd->kni =
1064  rte_kni_alloc (bm->pktmbuf_pools[rte_socket_id ()], &conf, &ops);
1065  if (!xd->kni)
1066  {
1067  clib_warning ("failed to allocate kni interface");
1068  }
1069  else
1070  {
1071  hif->max_packet_bytes = 1500; /* kni interface default value */
1072  xd->admin_up = 1;
1073  }
1074  }
1075  else
1076  {
1077  xd->admin_up = 0;
1078  int kni_rv;
1079 
1080  kni_rv = rte_kni_release (xd->kni);
1081  if (kni_rv < 0)
1082  clib_warning ("rte_kni_release returned %d", kni_rv);
1083  }
1084  return 0;
1085  }
1086 #endif
1087 #if DPDK_VHOST_USER
1089  {
1090  if (is_up)
1091  {
1092  if (xd->vu_is_running)
1095  ETH_LINK_FULL_DUPLEX);
1096  xd->admin_up = 1;
1097  }
1098  else
1099  {
1101  xd->admin_up = 0;
1102  }
1103 
1104  return 0;
1105  }
1106 #endif
1107 
1108 
1109  if (is_up)
1110  {
1111  f64 now = vlib_time_now (dm->vlib_main);
1112 
1113  /*
1114  * DAW-FIXME: VMXNET3 device stop/start doesn't work,
1115  * therefore fake the stop in the dpdk driver by
1116  * silently dropping all of the incoming pkts instead of
1117  * stopping the driver / hardware.
1118  */
1119  if (xd->admin_up == 0)
1120  rv = rte_eth_dev_start (xd->device_index);
1121 
1122  if (xd->promisc)
1123  rte_eth_promiscuous_enable (xd->device_index);
1124  else
1125  rte_eth_promiscuous_disable (xd->device_index);
1126 
1127  rte_eth_allmulticast_enable (xd->device_index);
1128  xd->admin_up = 1;
1129  dpdk_update_counters (xd, now);
1130  dpdk_update_link_state (xd, now);
1131  }
1132  else
1133  {
1134  /*
1135  * DAW-FIXME: VMXNET3 device stop/start doesn't work,
1136  * therefore fake the stop in the dpdk driver by
1137  * silently dropping all of the incoming pkts instead of
1138  * stopping the driver / hardware.
1139  */
1140  if (xd->pmd != VNET_DPDK_PMD_VMXNET3)
1141  xd->admin_up = 0;
1142  else
1143  xd->admin_up = ~0;
1144 
1145  rte_eth_allmulticast_disable (xd->device_index);
1147 
1148  /*
1149  * DAW-FIXME: VMXNET3 device stop/start doesn't work,
1150  * therefore fake the stop in the dpdk driver by
1151  * silently dropping all of the incoming pkts instead of
1152  * stopping the driver / hardware.
1153  */
1154  if (xd->pmd != VNET_DPDK_PMD_VMXNET3)
1155  rte_eth_dev_stop (xd->device_index);
1156 
1157  /* For bonded interface, stop slave links */
1158  if (xd->pmd == VNET_DPDK_PMD_BOND)
1159  {
1160  u8 slink[16];
1161  int nlink = rte_eth_bond_slaves_get (xd->device_index, slink, 16);
1162  while (nlink >= 1)
1163  {
1164  u8 dpdk_port = slink[--nlink];
1165  rte_eth_dev_stop (dpdk_port);
1166  }
1167  }
1168  }
1169 
1170  if (rv < 0)
1171  clib_warning ("rte_eth_dev_%s error: %d", is_up ? "start" : "stop", rv);
1172 
1173  return /* no error */ 0;
1174 }
1175 
1176 /*
1177  * Dynamically redirect all pkts from a specific interface
1178  * to the specified node
1179  */
1180 static void
1182  u32 node_index)
1183 {
1184  dpdk_main_t *xm = &dpdk_main;
1185  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1187 
1188  /* Shut off redirection */
1189  if (node_index == ~0)
1190  {
1191  xd->per_interface_next_index = node_index;
1192  return;
1193  }
1194 
1196  vlib_node_add_next (xm->vlib_main, dpdk_input_node.index, node_index);
1197 }
1198 
1199 
1200 static clib_error_t *
1202  u32 hw_if_index,
1203  struct vnet_sw_interface_t *st, int is_add)
1204 {
1205  dpdk_main_t *xm = &dpdk_main;
1206  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1209  int r, vlan_offload;
1210  u32 prev_subifs = xd->vlan_subifs;
1211 
1212  if (is_add)
1213  xd->vlan_subifs++;
1214  else if (xd->vlan_subifs)
1215  xd->vlan_subifs--;
1216 
1217  if (xd->dev_type != VNET_DPDK_DEV_ETH)
1218  return 0;
1219 
1220  /* currently we program VLANS only for IXGBE VF and I40E VF */
1221  if ((xd->pmd != VNET_DPDK_PMD_IXGBEVF) && (xd->pmd != VNET_DPDK_PMD_I40EVF))
1222  return 0;
1223 
1224  if (t->sub.eth.flags.no_tags == 1)
1225  return 0;
1226 
1227  if ((t->sub.eth.flags.one_tag != 1) || (t->sub.eth.flags.exact_match != 1))
1228  {
1229  xd->vlan_subifs = prev_subifs;
1230  return clib_error_return (0, "unsupported VLAN setup");
1231  }
1232 
1233  vlan_offload = rte_eth_dev_get_vlan_offload (xd->device_index);
1234  vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1235 
1236  if ((r = rte_eth_dev_set_vlan_offload (xd->device_index, vlan_offload)))
1237  {
1238  xd->vlan_subifs = prev_subifs;
1239  return clib_error_return (0, "rte_eth_dev_set_vlan_offload[%d]: err %d",
1240  xd->device_index, r);
1241  }
1242 
1243 
1244  if ((r =
1245  rte_eth_dev_vlan_filter (xd->device_index, t->sub.eth.outer_vlan_id,
1246  is_add)))
1247  {
1248  xd->vlan_subifs = prev_subifs;
1249  return clib_error_return (0, "rte_eth_dev_vlan_filter[%d]: err %d",
1250  xd->device_index, r);
1251  }
1252 
1253  return 0;
1254 }
1255 
1256 /* *INDENT-OFF* */
1258  .name = "dpdk",
1259  .tx_function = dpdk_interface_tx,
1260  .tx_function_n_errors = DPDK_TX_FUNC_N_ERROR,
1261  .tx_function_error_strings = dpdk_tx_func_error_strings,
1262  .format_device_name = format_dpdk_device_name,
1263  .format_device = format_dpdk_device,
1264  .format_tx_trace = format_dpdk_tx_dma_trace,
1265  .clear_counters = dpdk_clear_hw_interface_counters,
1266  .admin_up_down_function = dpdk_interface_admin_up_down,
1267  .subif_add_del_function = dpdk_subif_add_del_function,
1268  .rx_redirect_to_node = dpdk_set_interface_next_node,
1269  .no_flatten_output_chains = 1,
1270  .name_renumber = dpdk_device_renumber,
1271 };
1272 
1274 /* *INDENT-ON* */
1275 
1276 void
1278  dpdk_flowcontrol_callback_t callback)
1279 {
1280  dpdk_main.flowcontrol_callback = callback;
1281 }
1282 
1283 #define UP_DOWN_FLAG_EVENT 1
1284 
1285 
1286 u32
1288 {
1290 }
1291 
1292 uword
1295 {
1296  clib_error_t *error = 0;
1297  uword event_type;
1298  uword *event_data = 0;
1299  u32 sw_if_index;
1300  u32 flags;
1301 
1302  while (1)
1303  {
1305 
1306  event_type = vlib_process_get_events (vm, &event_data);
1307 
1309 
1310  switch (event_type)
1311  {
1312  case UP_DOWN_FLAG_EVENT:
1313  {
1314  if (vec_len (event_data) == 2)
1315  {
1316  sw_if_index = event_data[0];
1317  flags = event_data[1];
1318  error =
1319  vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index,
1320  flags);
1321  clib_error_report (error);
1322  }
1323  }
1324  break;
1325  }
1326 
1327  vec_reset_length (event_data);
1328 
1330 
1331  }
1332  return 0; /* or not */
1333 }
1334 
1335 /* *INDENT-OFF* */
1337  .function = admin_up_down_process,
1338  .type = VLIB_NODE_TYPE_PROCESS,
1339  .name = "admin-up-down-process",
1340  .process_log2_n_stack_bytes = 17, // 256KB
1341 };
1342 /* *INDENT-ON* */
1343 
1344 /*
1345  * Asynchronously invoke vnet_sw_interface_set_flags via the admin_up_down
1346  * process. Useful for avoiding long blocking delays (>150ms) in the dpdk
1347  * drivers.
1348  * WARNING: when posting this event, no other interface-related calls should
1349  * be made (e.g. vnet_create_sw_interface()) while the event is being
1350  * processed (admin_up_down_in_progress). This is required in order to avoid
1351  * race conditions in manipulating interface data structures.
1352  */
1353 void
1355 {
1357  (vm, admin_up_down_process_node.index,
1358  UP_DOWN_FLAG_EVENT, 2, sizeof (u32));
1359  d[0] = sw_if_index;
1360  d[1] = flags;
1361 }
1362 
1363 /*
1364  * Return a copy of the DPDK port stats in dest.
1365  */
1366 clib_error_t *
1367 dpdk_get_hw_interface_stats (u32 hw_if_index, struct rte_eth_stats *dest)
1368 {
1369  dpdk_main_t *dm = &dpdk_main;
1370  vnet_main_t *vnm = vnet_get_main ();
1371  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1373 
1374  if (!dest)
1375  {
1376  return clib_error_return (0, "Missing or NULL argument");
1377  }
1378  if (!xd)
1379  {
1380  return clib_error_return (0,
1381  "Unable to get DPDK device from HW interface");
1382  }
1383 
1385 
1386  clib_memcpy (dest, &xd->stats, sizeof (xd->stats));
1387  return (0);
1388 }
1389 
1390 /*
1391  * Return the number of dpdk mbufs
1392  */
1393 u32
1395 {
1396  dpdk_main_t *dm = &dpdk_main;
1397 
1398  return dm->conf->num_mbufs;
1399 }
1400 
1401 /*
1402  * Return the pmd type for a given hardware interface
1403  */
1404 dpdk_pmd_t
1406 {
1407  dpdk_main_t *dm = &dpdk_main;
1408  dpdk_device_t *xd;
1409 
1410  assert (hi);
1411 
1412  xd = vec_elt_at_index (dm->devices, hi->dev_instance);
1413 
1414  assert (xd);
1415 
1416  return xd->pmd;
1417 }
1418 
1419 /*
1420  * Return the cpu socket for a given hardware interface
1421  */
1422 i8
1424 {
1425  dpdk_main_t *dm = &dpdk_main;
1426  dpdk_device_t *xd;
1427 
1428  assert (hi);
1429 
1430  xd = vec_elt_at_index (dm->devices, hi->dev_instance);
1431 
1432  assert (xd);
1433 
1434  return xd->cpu_socket;
1435 }
1436 
1437 /*
1438  * fd.io coding-style-patch-verification: ON
1439  *
1440  * Local Variables:
1441  * eval: (c-set-style "gnu")
1442  * End:
1443  */
void(* dpdk_flowcontrol_callback_t)(vlib_main_t *vm, u32 hw_if_index, u32 n_packets)
Definition: dpdk.h:179
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u32 increment)
Increment a simple counter.
Definition: counter.h:78
vmrglw vmrglh hi
i8 dpdk_get_cpu_socket(vnet_hw_interface_t *hi)
Definition: device.c:1423
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
#define rte_mbuf_from_vlib_buffer(x)
Definition: buffer.h:382
u8 promisc
Definition: dpdk.h:222
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:513
vlib_buffer_t buffer
Definition: dpdk.h:462
#define UP_DOWN_FLAG_EVENT
Definition: device.c:1283
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:602
dpdk_main_t dpdk_main
Definition: dpdk.h:443
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
struct rte_eth_stats last_stats
Definition: dpdk.h:256
vnet_interface_main_t interface_main
Definition: vnet.h:64
clib_error_t * dpdk_set_mac_address(vnet_hw_interface_t *hi, char *address)
Definition: device.c:48
vnet_device_class_t dpdk_device_class
static int dpdk_device_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
Definition: device.c:916
#define PREDICT_TRUE(x)
Definition: clib.h:98
u32 vhost_coalesce_frames
Definition: dpdk.h:362
u8 need_txlock
Definition: dpdk.h:269
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:55
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
unsigned rte_socket_id()
struct vnet_sub_interface_t::@120::@121::@123 flags
vlib_buffer_main_t * buffer_main
Definition: main.h:104
u32 per_interface_next_index
Definition: dpdk.h:205
u64 tx_tail
Definition: dpdk.h:190
#define clib_error_report(e)
Definition: error.h:125
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:273
struct rte_eth_xstat * last_cleared_xstats
Definition: dpdk.h:260
struct rte_mbuf * dpdk_zerocopy_replicate_packet_mb(vlib_buffer_t *b)
Definition: device.c:159
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:112
format_function_t format_dpdk_tx_dma_trace
Definition: dpdk.h:622
uword admin_up_down_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: device.c:1293
static clib_error_t * dpdk_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:1038
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1061
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u8 admin_up
Definition: dpdk.h:221
struct rte_eth_stats stats
Definition: dpdk.h:255
VNET_DEVICE_CLASS(af_packet_device_class)
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
struct rte_mbuf *** tx_vectors
Definition: dpdk.h:208
static_always_inline u32 tx_burst_vector_internal(vlib_main_t *vm, dpdk_device_t *xd, struct rte_mbuf **tx_vector)
Definition: device.c:267
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:78
#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:525
vlib_node_registration_t dpdk_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_input_node)
Definition: node.c:787
char i8
Definition: types.h:45
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u16 rx_q_used
Definition: dpdk.h:230
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:143
u32 cpu_index
Definition: main.h:159
#define clib_warning(format, args...)
Definition: error.h:59
A collection of simple counters.
Definition: counter.h:59
u32 device_index
Definition: dpdk.h:199
u32 dpdk_num_mbufs(void)
Definition: device.c:1394
u32 pcap_sw_if_index
Definition: dpdk.h:404
struct rte_mbuf * dpdk_replicate_packet_mb(vlib_buffer_t *b)
Definition: device.c:88
vnet_hw_interface_t * hw_interfaces
Definition: interface.h:478
#define hash_get(h, key)
Definition: hash.h:248
vnet_sub_interface_t sub
Definition: interface.h:447
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:1201
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:82
dpdk_device_and_queue_t ** devices_by_cpu
Definition: dpdk.h:379
u32 vlib_hw_if_index
Definition: dpdk.h:201
dpdk_flowcontrol_callback_t flowcontrol_callback
Definition: dpdk.h:388
static char * dpdk_tx_func_error_strings[]
Definition: device.c:41
pcap_main_t pcap_main
Definition: dpdk.h:402
unsigned short int uint16_t
Definition: fix_types.h:28
struct rte_mbuf mb
Definition: dpdk.h:460
static void * vlib_process_signal_event_data(vlib_main_t *vm, uword node_index, uword type_opaque, uword n_data_elts, uword n_data_elt_bytes)
Definition: node_funcs.h:827
u16 vlan_subifs
Definition: dpdk.h:215
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
static void dpdk_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: device.c:1181
#define VLIB_FRAME_SIZE
Definition: node.h:328
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:500
u16 tx_q_used
Definition: dpdk.h:229
void dpdk_set_flowcontrol_callback(vlib_main_t *vm, dpdk_flowcontrol_callback_t callback)
Definition: device.c:1277
static uword dpdk_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
Definition: device.c:606
u32 ** recycle
Definition: dpdk.h:382
struct rte_mempool ** pktmbuf_pools
Definition: buffer.h:321
svmdb_client_t * c
u16 n_vectors
Definition: node.h:344
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
dpdk_device_t * devices
Definition: dpdk.h:378
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:83
struct rte_kni * kni
Definition: dpdk.h:238
volatile u32 ** lockp
Definition: dpdk.h:196
#define clib_memcpy(a, b, c)
Definition: string.h:63
dpdk_pmd_t pmd
Definition: dpdk.h:218
#define VLIB_BUFFER_RECYCLE
Definition: buffer.h:99
dpdk_pmd_t
Definition: dpdk.h:104
format_function_t format_dpdk_device
Definition: dpdk.h:621
struct vnet_sub_interface_t::@120 eth
struct rte_eth_xstat * xstats
Definition: dpdk.h:259
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:415
#define DPDK_TX_RING_SIZE
Definition: dpdk.h:273
#define ASSERT(truth)
format_function_t format_dpdk_device_name
Definition: dpdk.h:620
#define VLIB_BUFFER_REPL_FAIL
Definition: buffer.h:98
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:335
u64 tx_head
Definition: dpdk.h:189
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: dpdk_buffer.c:766
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:259
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1449
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:93
dpdk_pmd_t dpdk_get_pmd_type(vnet_hw_interface_t *hi)
Definition: device.c:1405
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:936
static vlib_node_registration_t admin_up_down_process_node
(constructor) VLIB_REGISTER_NODE (admin_up_down_process_node)
Definition: device.c:1336
template key/value backing page structure
Definition: bihash_doc.h:44
u8 kni_port_id
Definition: dpdk.h:239
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
dpdk_device_type_t dev_type
Definition: dpdk.h:217
unsigned char u8
Definition: types.h:56
#define foreach_dpdk_tx_func_error
Definition: device.c:27
u8 admin_up_down_in_progress
Definition: dpdk.h:422
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:251
#define VLIB_BUFFER_DATA_SIZE
Definition: buffer.h:51
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:228
u32 dpdk_interface_tx_vector(vlib_main_t *vm, u32 dev_instance)
Definition: device.c:562
short i16
Definition: types.h:46
void post_sw_interface_set_flags(vlib_main_t *vm, u32 sw_if_index, u32 flags)
Definition: device.c:1354
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u32 dpdk_get_admin_up_down_in_progress(void)
Definition: device.c:1287
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:151
#define vec_foreach(var, vec)
Vector iterator.
i8 cpu_socket
Definition: dpdk.h:219
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:521
struct rte_eth_stats last_cleared_stats
Definition: dpdk.h:257
#define clib_error_return(e, args...)
Definition: error.h:111
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:85
clib_error_t * dpdk_get_hw_interface_stats(u32 hw_if_index, struct rte_eth_stats *dest)
Definition: device.c:1367
int tx_pcap_enable
Definition: dpdk.h:401
vnet_main_t * vnet_main
Definition: dpdk.h:439
uword runtime_data[(128-1 *sizeof(vlib_node_function_t *)-1 *sizeof(vlib_error_t *)-11 *sizeof(u32)-5 *sizeof(u16))/sizeof(uword)]
Definition: node.h:472
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
dpdk_tx_func_error_t
Definition: device.c:33
#define VLIB_DEVICE_TX_FUNCTION_MULTIARCH(dev, fn)
Definition: interface.h:183
clib_error_t * dpdk_set_mc_filter(vnet_hw_interface_t *hi, struct ether_addr mc_addr_vec[], int naddr)
Definition: device.c:68
uword * dpdk_device_by_kni_port_id
Definition: dpdk.h:408
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
dpdk_config_main_t * conf
Definition: dpdk.h:440
vlib_main_t * vlib_main
Definition: dpdk.h:438