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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/format.h>
18 #include <vlib/unix/cj.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
24 #include <dpdk/device/dpdk_priv.h>
25 #include <vppinfra/error.h>
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)")
35 #define _(f,s) DPDK_TX_FUNC_ERROR_##f,
36 foreach_dpdk_tx_func_error
39 } dpdk_tx_func_error_t;
41 #ifndef CLIB_MULTIARCH_VARIANT
42 static char *dpdk_tx_func_error_strings[] = {
44 foreach_dpdk_tx_func_error
49 dpdk_set_mac_address (vnet_hw_interface_t * hi, char *address)
52 dpdk_main_t *dm = &dpdk_main;
53 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
55 error = rte_eth_dev_default_mac_addr_set (xd->device_index,
56 (struct ether_addr *) address);
60 return clib_error_return (0, "mac address set failed: %d", error);
64 vec_reset_length (xd->default_mac_address);
65 vec_add (xd->default_mac_address, address, sizeof (address));
71 static struct rte_mbuf *
72 dpdk_replicate_packet_mb (vlib_buffer_t * b)
74 dpdk_main_t *dm = &dpdk_main;
75 struct rte_mbuf **mbufs = 0, *s, *d;
77 unsigned socket_id = rte_socket_id ();
80 ASSERT (dm->pktmbuf_pools[socket_id]);
81 s = rte_mbuf_from_vlib_buffer (b);
83 vec_validate (mbufs, nb_segs - 1);
85 if (rte_pktmbuf_alloc_bulk (dm->pktmbuf_pools[socket_id], mbufs, nb_segs))
92 d->nb_segs = s->nb_segs;
93 d->data_len = s->data_len;
94 d->pkt_len = s->pkt_len;
95 d->data_off = s->data_off;
96 clib_memcpy (d->buf_addr, s->buf_addr, RTE_PKTMBUF_HEADROOM + s->data_len);
98 for (i = 1; i < nb_segs; i++)
103 d->data_len = s->data_len;
104 clib_memcpy (d->buf_addr, s->buf_addr,
105 RTE_PKTMBUF_HEADROOM + s->data_len);
114 dpdk_tx_trace_buffer (dpdk_main_t * dm,
115 vlib_node_runtime_t * node,
117 u16 queue_id, u32 buffer_index, vlib_buffer_t * buffer)
119 vlib_main_t *vm = vlib_get_main ();
123 mb = rte_mbuf_from_vlib_buffer (buffer);
125 t0 = vlib_add_trace (vm, node, buffer, sizeof (t0[0]));
126 t0->queue_index = queue_id;
127 t0->device_index = xd->device_index;
128 t0->buffer_index = buffer_index;
129 clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
130 clib_memcpy (&t0->buffer, buffer,
131 sizeof (buffer[0]) - sizeof (buffer->pre_data));
132 clib_memcpy (t0->buffer.pre_data, buffer->data + buffer->current_data,
133 sizeof (t0->buffer.pre_data));
134 clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof (t0->data));
137 static_always_inline void
138 dpdk_validate_rte_mbuf (vlib_main_t * vm, vlib_buffer_t * b,
141 struct rte_mbuf *mb, *first_mb, *last_mb;
143 /* buffer is coming from non-dpdk source so we need to init
145 if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_EXT_HDR_VALID) == 0))
147 vlib_buffer_t *b2 = b;
148 last_mb = mb = rte_mbuf_from_vlib_buffer (b2);
149 rte_pktmbuf_reset (mb);
150 while (maybe_multiseg && (b2->flags & VLIB_BUFFER_NEXT_PRESENT))
152 b2 = vlib_get_buffer (vm, b2->next_buffer);
153 mb = rte_mbuf_from_vlib_buffer (b2);
154 rte_pktmbuf_reset (mb);
158 last_mb = first_mb = mb = rte_mbuf_from_vlib_buffer (b);
159 first_mb->nb_segs = 1;
160 mb->data_len = b->current_length;
161 mb->pkt_len = maybe_multiseg ? vlib_buffer_length_in_chain (vm, b) :
163 mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
165 while (maybe_multiseg && (b->flags & VLIB_BUFFER_NEXT_PRESENT))
167 b = vlib_get_buffer (vm, b->next_buffer);
168 mb = rte_mbuf_from_vlib_buffer (b);
171 mb->data_len = b->current_length;
172 mb->pkt_len = b->current_length;
173 mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
175 if (PREDICT_FALSE (b->n_add_refs))
177 rte_mbuf_refcnt_update (mb, b->n_add_refs);
184 * This function calls the dpdk's tx_burst function to transmit the packets
185 * on the tx_vector. It manages a lock per-device if the device does not
186 * support multiple queues. It returns the number of packets untransmitted
187 * on the tx_vector. If all packets are transmitted (the normal case), the
188 * function returns 0.
190 * The function assumes there is at least one packet on the tx_vector.
193 u32 tx_burst_vector_internal (vlib_main_t * vm,
195 struct rte_mbuf **tx_vector)
197 dpdk_main_t *dm = &dpdk_main;
206 ring = vec_header (tx_vector, sizeof (*ring));
208 n_packets = ring->tx_head - ring->tx_tail;
210 tx_head = ring->tx_head % xd->nb_tx_desc;
213 * Ensure rte_eth_tx_burst is not called with 0 packets, which can lead to
214 * unpredictable results.
216 ASSERT (n_packets > 0);
219 * Check for tx_vector overflow. If this fails it is a system configuration
220 * error. The ring should be sized big enough to handle the largest un-flowed
221 * off burst from a traffic manager. A larger size also helps performance
222 * a bit because it decreases the probability of having to issue two tx_burst
223 * calls due to a ring wrap.
225 ASSERT (n_packets < xd->nb_tx_desc);
226 ASSERT (ring->tx_tail == 0);
229 queue_id = vm->thread_index;
233 /* start the burst at the tail */
234 tx_tail = ring->tx_tail % xd->nb_tx_desc;
237 * This device only supports one TX queue,
238 * and we're running multi-threaded...
240 if (PREDICT_FALSE (xd->lockp != 0))
242 queue_id = queue_id % xd->tx_q_used;
243 while (__sync_lock_test_and_set (xd->lockp[queue_id], 1))
245 queue_id = (queue_id + 1) % xd->tx_q_used;
248 if (PREDICT_FALSE (xd->flags & DPDK_DEVICE_FLAG_HQOS)) /* HQoS ON */
250 /* no wrap, transmit in one burst */
251 dpdk_device_hqos_per_worker_thread_t *hqos =
252 &xd->hqos_wt[vm->thread_index];
254 ASSERT (hqos->swq != NULL);
256 dpdk_hqos_metadata_set (hqos,
257 &tx_vector[tx_tail], tx_head - tx_tail);
258 rv = rte_ring_sp_enqueue_burst (hqos->swq,
259 (void **) &tx_vector[tx_tail],
260 (uint16_t) (tx_head - tx_tail), 0);
262 else if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
264 /* no wrap, transmit in one burst */
265 rv = rte_eth_tx_burst (xd->device_index,
268 (uint16_t) (tx_head - tx_tail));
276 if (PREDICT_FALSE (xd->lockp != 0))
277 *xd->lockp[queue_id] = 0;
279 if (PREDICT_FALSE (rv < 0))
281 // emit non-fatal message, bump counter
282 vnet_main_t *vnm = dm->vnet_main;
283 vnet_interface_main_t *im = &vnm->interface_main;
286 node_index = vec_elt_at_index (im->hw_interfaces,
287 xd->hw_if_index)->tx_node_index;
289 vlib_error_count (vm, node_index, DPDK_TX_FUNC_ERROR_BAD_RETVAL, 1);
290 clib_warning ("rte_eth_tx_burst[%d]: error %d", xd->device_index,
292 return n_packets; // untransmitted packets
294 ring->tx_tail += (u16) rv;
295 n_packets -= (uint16_t) rv;
297 while (rv && n_packets && (n_retry > 0));
302 static_always_inline void
303 dpdk_prefetch_buffer_by_index (vlib_main_t * vm, u32 bi)
307 b = vlib_get_buffer (vm, bi);
308 mb = rte_mbuf_from_vlib_buffer (b);
309 CLIB_PREFETCH (mb, 2 * CLIB_CACHE_LINE_BYTES, STORE);
310 CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
313 static_always_inline void
314 dpdk_buffer_recycle (vlib_main_t * vm, vlib_node_runtime_t * node,
315 vlib_buffer_t * b, u32 bi, struct rte_mbuf **mbp)
317 dpdk_main_t *dm = &dpdk_main;
318 u32 my_cpu = vm->thread_index;
319 struct rte_mbuf *mb_new;
321 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_RECYCLE) == 0)
324 mb_new = dpdk_replicate_packet_mb (b);
325 if (PREDICT_FALSE (mb_new == 0))
327 vlib_error_count (vm, node->node_index,
328 DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
329 b->flags |= VLIB_BUFFER_REPL_FAIL;
334 vec_add1 (dm->recycle[my_cpu], bi);
337 static_always_inline void
338 dpdk_buffer_tx_offload (dpdk_device_t * xd, vlib_buffer_t * b,
341 u32 ip_cksum = b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
342 u32 tcp_cksum = b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
343 u32 udp_cksum = b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
344 int is_ip4 = b->flags & VNET_BUFFER_F_IS_IP4;
347 /* Is there any work for us? */
348 if (PREDICT_TRUE ((ip_cksum | tcp_cksum | udp_cksum) == 0))
351 mb->l2_len = vnet_buffer (b)->l3_hdr_offset - b->current_data;
352 mb->l3_len = vnet_buffer (b)->l4_hdr_offset -
353 vnet_buffer (b)->l3_hdr_offset;
354 mb->outer_l3_len = 0;
355 mb->outer_l2_len = 0;
356 ol_flags = is_ip4 ? PKT_TX_IPV4 : PKT_TX_IPV6;
357 ol_flags |= ip_cksum ? PKT_TX_IP_CKSUM : 0;
358 ol_flags |= tcp_cksum ? PKT_TX_TCP_CKSUM : 0;
359 ol_flags |= udp_cksum ? PKT_TX_UDP_CKSUM : 0;
360 mb->ol_flags |= ol_flags;
362 /* we are trying to help compiler here by using local ol_flags with known
363 state of all flags */
364 if (xd->flags & DPDK_DEVICE_FLAG_INTEL_PHDR_CKSUM)
365 rte_net_intel_cksum_flags_prepare (mb, ol_flags);
369 * Transmits the packets on the frame to the interface associated with the
370 * node. It first copies packets on the frame to a tx_vector containing the
371 * rte_mbuf pointers. It then passes this vector to tx_burst_vector_internal
372 * which calls the dpdk tx_burst function.
375 CLIB_MULTIARCH_FN (dpdk_interface_tx) (vlib_main_t * vm,
376 vlib_node_runtime_t * node,
379 dpdk_main_t *dm = &dpdk_main;
380 vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
381 dpdk_device_t *xd = vec_elt_at_index (dm->devices, rd->dev_instance);
382 u32 n_packets = f->n_vectors;
385 struct rte_mbuf **tx_vector;
387 u16 nb_tx_desc = xd->nb_tx_desc;
394 my_cpu = vm->thread_index;
398 tx_vector = xd->tx_vectors[queue_id];
399 ring = vec_header (tx_vector, sizeof (*ring));
401 n_on_ring = ring->tx_head - ring->tx_tail;
402 from = vlib_frame_vector_args (f);
404 ASSERT (n_packets <= VLIB_FRAME_SIZE);
406 if (PREDICT_FALSE (n_on_ring + n_packets > nb_tx_desc))
409 * Overflowing the ring should never happen.
410 * If it does then drop the whole frame.
412 vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_RING_FULL,
417 u32 bi0 = from[n_packets];
418 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
419 struct rte_mbuf *mb0 = rte_mbuf_from_vlib_buffer (b0);
420 rte_pktmbuf_free (mb0);
425 if (PREDICT_FALSE (dm->tx_pcap_enable))
431 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
432 if (dm->pcap_sw_if_index == 0 ||
433 dm->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_TX])
434 pcap_add_buffer (&dm->pcap_main, vm, bi0, 512);
440 from = vlib_frame_vector_args (f);
442 i = ring->tx_head % nb_tx_desc;
446 u32 bi0, bi1, bi2, bi3;
447 struct rte_mbuf *mb0, *mb1, *mb2, *mb3;
448 vlib_buffer_t *b0, *b1, *b2, *b3;
451 dpdk_prefetch_buffer_by_index (vm, from[4]);
452 dpdk_prefetch_buffer_by_index (vm, from[5]);
453 dpdk_prefetch_buffer_by_index (vm, from[6]);
454 dpdk_prefetch_buffer_by_index (vm, from[7]);
462 b0 = vlib_get_buffer (vm, bi0);
463 b1 = vlib_get_buffer (vm, bi1);
464 b2 = vlib_get_buffer (vm, bi2);
465 b3 = vlib_get_buffer (vm, bi3);
467 or_flags = b0->flags | b1->flags | b2->flags | b3->flags;
469 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
470 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1);
471 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b2);
472 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b3);
474 if (or_flags & VLIB_BUFFER_NEXT_PRESENT)
476 dpdk_validate_rte_mbuf (vm, b0, 1);
477 dpdk_validate_rte_mbuf (vm, b1, 1);
478 dpdk_validate_rte_mbuf (vm, b2, 1);
479 dpdk_validate_rte_mbuf (vm, b3, 1);
483 dpdk_validate_rte_mbuf (vm, b0, 0);
484 dpdk_validate_rte_mbuf (vm, b1, 0);
485 dpdk_validate_rte_mbuf (vm, b2, 0);
486 dpdk_validate_rte_mbuf (vm, b3, 0);
489 mb0 = rte_mbuf_from_vlib_buffer (b0);
490 mb1 = rte_mbuf_from_vlib_buffer (b1);
491 mb2 = rte_mbuf_from_vlib_buffer (b2);
492 mb3 = rte_mbuf_from_vlib_buffer (b3);
494 if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_TX_OFFLOAD) &&
496 (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
497 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM
498 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))))
500 dpdk_buffer_tx_offload (xd, b0, mb0);
501 dpdk_buffer_tx_offload (xd, b1, mb1);
502 dpdk_buffer_tx_offload (xd, b2, mb2);
503 dpdk_buffer_tx_offload (xd, b3, mb3);
506 if (PREDICT_FALSE (or_flags & VLIB_BUFFER_RECYCLE))
508 dpdk_buffer_recycle (vm, node, b0, bi0, &mb0);
509 dpdk_buffer_recycle (vm, node, b1, bi1, &mb1);
510 dpdk_buffer_recycle (vm, node, b2, bi2, &mb2);
511 dpdk_buffer_recycle (vm, node, b3, bi3, &mb3);
513 /* dont enqueue packets if replication failed as they must
514 be sent back to recycle */
515 if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
516 tx_vector[i++ % nb_tx_desc] = mb0;
517 if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_REPL_FAIL) == 0))
518 tx_vector[i++ % nb_tx_desc] = mb1;
519 if (PREDICT_TRUE ((b2->flags & VLIB_BUFFER_REPL_FAIL) == 0))
520 tx_vector[i++ % nb_tx_desc] = mb2;
521 if (PREDICT_TRUE ((b3->flags & VLIB_BUFFER_REPL_FAIL) == 0))
522 tx_vector[i++ % nb_tx_desc] = mb3;
526 if (PREDICT_FALSE (i + 3 >= nb_tx_desc))
528 tx_vector[i++ % nb_tx_desc] = mb0;
529 tx_vector[i++ % nb_tx_desc] = mb1;
530 tx_vector[i++ % nb_tx_desc] = mb2;
531 tx_vector[i++ % nb_tx_desc] = mb3;
536 tx_vector[i++] = mb0;
537 tx_vector[i++] = mb1;
538 tx_vector[i++] = mb2;
539 tx_vector[i++] = mb3;
544 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
546 if (b0->flags & VLIB_BUFFER_IS_TRACED)
547 dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
548 if (b1->flags & VLIB_BUFFER_IS_TRACED)
549 dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi1, b1);
550 if (b2->flags & VLIB_BUFFER_IS_TRACED)
551 dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi2, b2);
552 if (b3->flags & VLIB_BUFFER_IS_TRACED)
553 dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi3, b3);
561 struct rte_mbuf *mb0;
567 b0 = vlib_get_buffer (vm, bi0);
568 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
570 dpdk_validate_rte_mbuf (vm, b0, 1);
572 mb0 = rte_mbuf_from_vlib_buffer (b0);
573 dpdk_buffer_tx_offload (xd, b0, mb0);
574 dpdk_buffer_recycle (vm, node, b0, bi0, &mb0);
576 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
577 if (b0->flags & VLIB_BUFFER_IS_TRACED)
578 dpdk_tx_trace_buffer (dm, node, xd, queue_id, bi0, b0);
580 if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_REPL_FAIL) == 0))
582 tx_vector[i % nb_tx_desc] = mb0;
588 /* account for additional packets in the ring */
589 ring->tx_head += n_packets;
590 n_on_ring = ring->tx_head - ring->tx_tail;
592 /* transmit as many packets as possible */
593 n_packets = tx_burst_vector_internal (vm, xd, tx_vector);
596 * tx_pkts is the number of packets successfully transmitted
597 * This is the number originally on ring minus the number remaining on ring
599 tx_pkts = n_on_ring - n_packets;
602 /* If there is no callback then drop any non-transmitted packets */
603 if (PREDICT_FALSE (n_packets))
605 vlib_simple_counter_main_t *cm;
606 vnet_main_t *vnm = vnet_get_main ();
608 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
609 VNET_INTERFACE_COUNTER_TX_ERROR);
611 vlib_increment_simple_counter (cm, my_cpu, xd->sw_if_index,
614 vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_PKT_DROP,
618 rte_pktmbuf_free (tx_vector[ring->tx_tail + n_packets]);
621 /* Reset head/tail to avoid unnecessary wrap */
626 /* Recycle replicated buffers */
627 if (PREDICT_FALSE (vec_len (dm->recycle[my_cpu])))
629 vlib_buffer_free (vm, dm->recycle[my_cpu],
630 vec_len (dm->recycle[my_cpu]));
631 _vec_len (dm->recycle[my_cpu]) = 0;
634 ASSERT (ring->tx_head >= ring->tx_tail);
639 #ifndef CLIB_MULTIARCH_VARIANT
641 dpdk_clear_hw_interface_counters (u32 instance)
643 dpdk_main_t *dm = &dpdk_main;
644 dpdk_device_t *xd = vec_elt_at_index (dm->devices, instance);
647 * Set the "last_cleared_stats" to the current stats, so that
648 * things appear to clear from a display perspective.
650 dpdk_update_counters (xd, vlib_time_now (dm->vlib_main));
652 clib_memcpy (&xd->last_cleared_stats, &xd->stats, sizeof (xd->stats));
653 clib_memcpy (xd->last_cleared_xstats, xd->xstats,
654 vec_len (xd->last_cleared_xstats) *
655 sizeof (xd->last_cleared_xstats[0]));
659 static clib_error_t *
660 dpdk_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
662 vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
663 uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
664 dpdk_main_t *dm = &dpdk_main;
665 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hif->dev_instance);
667 if (xd->flags & DPDK_DEVICE_FLAG_PMD_INIT_FAIL)
668 return clib_error_return (0, "Interface not initialized");
672 vnet_hw_interface_set_flags (vnm, xd->hw_if_index,
673 VNET_HW_INTERFACE_FLAG_LINK_UP);
674 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
675 dpdk_device_start (xd);
676 xd->flags |= DPDK_DEVICE_FLAG_ADMIN_UP;
677 f64 now = vlib_time_now (dm->vlib_main);
678 dpdk_update_counters (xd, now);
679 dpdk_update_link_state (xd, now);
683 vnet_hw_interface_set_flags (vnm, xd->hw_if_index, 0);
684 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0)
685 dpdk_device_stop (xd);
686 xd->flags &= ~DPDK_DEVICE_FLAG_ADMIN_UP;
689 return /* no error */ 0;
693 * Dynamically redirect all pkts from a specific interface
694 * to the specified node
697 dpdk_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
700 dpdk_main_t *xm = &dpdk_main;
701 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
702 dpdk_device_t *xd = vec_elt_at_index (xm->devices, hw->dev_instance);
704 /* Shut off redirection */
705 if (node_index == ~0)
707 xd->per_interface_next_index = node_index;
711 xd->per_interface_next_index =
712 vlib_node_add_next (xm->vlib_main, dpdk_input_node.index, node_index);
716 static clib_error_t *
717 dpdk_subif_add_del_function (vnet_main_t * vnm,
719 struct vnet_sw_interface_t *st, int is_add)
721 dpdk_main_t *xm = &dpdk_main;
722 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
723 dpdk_device_t *xd = vec_elt_at_index (xm->devices, hw->dev_instance);
724 vnet_sw_interface_t *t = (vnet_sw_interface_t *) st;
726 u32 prev_subifs = xd->num_subifs;
727 clib_error_t *err = 0;
731 else if (xd->num_subifs)
734 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
737 /* currently we program VLANS only for IXGBE VF and I40E VF */
738 if ((xd->pmd != VNET_DPDK_PMD_IXGBEVF) && (xd->pmd != VNET_DPDK_PMD_I40EVF))
741 if (t->sub.eth.flags.no_tags == 1)
744 if ((t->sub.eth.flags.one_tag != 1) || (t->sub.eth.flags.exact_match != 1))
746 xd->num_subifs = prev_subifs;
747 err = clib_error_return (0, "unsupported VLAN setup");
751 vlan_offload = rte_eth_dev_get_vlan_offload (xd->device_index);
752 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
754 if ((r = rte_eth_dev_set_vlan_offload (xd->device_index, vlan_offload)))
756 xd->num_subifs = prev_subifs;
757 err = clib_error_return (0, "rte_eth_dev_set_vlan_offload[%d]: err %d",
758 xd->device_index, r);
764 rte_eth_dev_vlan_filter (xd->device_index, t->sub.eth.outer_vlan_id,
767 xd->num_subifs = prev_subifs;
768 err = clib_error_return (0, "rte_eth_dev_vlan_filter[%d]: err %d",
769 xd->device_index, r);
775 xd->flags |= DPDK_DEVICE_FLAG_HAVE_SUBIF;
777 xd->flags &= ~DPDK_DEVICE_FLAG_HAVE_SUBIF;
783 VNET_DEVICE_CLASS (dpdk_device_class) = {
785 .tx_function = dpdk_interface_tx,
786 .tx_function_n_errors = DPDK_TX_FUNC_N_ERROR,
787 .tx_function_error_strings = dpdk_tx_func_error_strings,
788 .format_device_name = format_dpdk_device_name,
789 .format_device = format_dpdk_device,
790 .format_tx_trace = format_dpdk_tx_trace,
791 .clear_counters = dpdk_clear_hw_interface_counters,
792 .admin_up_down_function = dpdk_interface_admin_up_down,
793 .subif_add_del_function = dpdk_subif_add_del_function,
794 .rx_redirect_to_node = dpdk_set_interface_next_node,
795 .mac_addr_change_function = dpdk_set_mac_address,
800 vlib_node_function_t __clib_weak dpdk_interface_tx_avx512;
801 vlib_node_function_t __clib_weak dpdk_interface_tx_avx2;
802 static void __clib_constructor
803 dpdk_interface_tx_multiarch_select (void)
805 if (dpdk_interface_tx_avx512 && clib_cpu_supports_avx512f ())
806 dpdk_device_class.tx_function = dpdk_interface_tx_avx512;
807 else if (dpdk_interface_tx_avx2 && clib_cpu_supports_avx2 ())
808 dpdk_device_class.tx_function = dpdk_interface_tx_avx2;
813 #define UP_DOWN_FLAG_EVENT 1
815 #ifndef CLIB_MULTIARCH_VARIANT
817 admin_up_down_process (vlib_main_t * vm,
818 vlib_node_runtime_t * rt, vlib_frame_t * f)
820 clib_error_t *error = 0;
822 uword *event_data = 0;
828 vlib_process_wait_for_event (vm);
830 event_type = vlib_process_get_events (vm, &event_data);
832 dpdk_main.admin_up_down_in_progress = 1;
836 case UP_DOWN_FLAG_EVENT:
838 if (vec_len (event_data) == 2)
840 sw_if_index = event_data[0];
841 flags = event_data[1];
843 vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index,
845 clib_error_report (error);
851 vec_reset_length (event_data);
853 dpdk_main.admin_up_down_in_progress = 0;
856 return 0; /* or not */
860 VLIB_REGISTER_NODE (admin_up_down_process_node,static) = {
861 .function = admin_up_down_process,
862 .type = VLIB_NODE_TYPE_PROCESS,
863 .name = "admin-up-down-process",
864 .process_log2_n_stack_bytes = 17, // 256KB
870 * fd.io coding-style-patch-verification: ON
873 * eval: (c-set-style "gnu")