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/error.h>
18 #include <vppinfra/format.h>
19 #include <vppinfra/xxhash.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/devices/dpdk/dpdk.h>
23 #include <vnet/classify/vnet_classify.h>
24 #include <vnet/mpls/packet.h>
25 #include <vnet/handoff.h>
27 #include "dpdk_priv.h"
30 #define MAX(a,b) ((a) < (b) ? (b) : (a))
34 #define MIN(a,b) ((a) < (b) ? (a) : (b))
38 * At least in certain versions of ESXi, vmware e1000's don't honor the
39 * "strip rx CRC" bit. Set this flag to work around that bug FOR UNIT TEST ONLY.
41 * If wireshark complains like so:
43 * "Frame check sequence: 0x00000000 [incorrect, should be <hex-num>]"
44 * and you're using ESXi emulated e1000's, set this flag FOR UNIT TEST ONLY.
46 * Note: do NOT check in this file with this workaround enabled! You'll lose
47 * actual data from e.g. 10xGE interfaces. The extra 4 bytes annoy
48 * wireshark, but they're harmless...
50 #define VMWARE_LENGTH_BUG_WORKAROUND 0
52 static char *dpdk_error_strings[] = {
59 dpdk_mbuf_is_ip4 (struct rte_mbuf *mb)
61 return RTE_ETH_IS_IPV4_HDR (mb->packet_type) != 0;
65 dpdk_mbuf_is_ip6 (struct rte_mbuf *mb)
67 return RTE_ETH_IS_IPV6_HDR (mb->packet_type) != 0;
71 vlib_buffer_is_mpls (vlib_buffer_t * b)
73 ethernet_header_t *h = (ethernet_header_t *) b->data;
74 return (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS_UNICAST));
78 dpdk_rx_next_and_error_from_mb_flags_x1 (dpdk_device_t * xd,
80 vlib_buffer_t * b0, u8 * next0,
84 uint16_t mb_flags = mb->ol_flags;
86 if (PREDICT_FALSE (mb_flags & (
87 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
88 PKT_EXT_RX_PKT_ERROR | PKT_EXT_RX_BAD_FCS |
89 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
90 PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD)))
92 /* some error was flagged. determine the drop reason */
93 n0 = DPDK_RX_NEXT_DROP;
95 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
96 (mb_flags & PKT_EXT_RX_PKT_ERROR) ? DPDK_ERROR_RX_PACKET_ERROR :
97 (mb_flags & PKT_EXT_RX_BAD_FCS) ? DPDK_ERROR_RX_BAD_FCS :
98 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
99 (mb_flags & PKT_RX_IP_CKSUM_BAD) ? DPDK_ERROR_IP_CHECKSUM_ERROR :
100 (mb_flags & PKT_RX_L4_CKSUM_BAD) ? DPDK_ERROR_L4_CHECKSUM_ERROR :
105 *error0 = DPDK_ERROR_NONE;
106 if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
108 n0 = xd->per_interface_next_index;
109 b0->flags |= BUFFER_HANDOFF_NEXT_VALID;
110 if (PREDICT_TRUE (dpdk_mbuf_is_ip4 (mb)))
111 vnet_buffer (b0)->handoff.next_index =
112 HANDOFF_DISPATCH_NEXT_IP4_INPUT;
113 else if (PREDICT_TRUE (dpdk_mbuf_is_ip6 (mb)))
114 vnet_buffer (b0)->handoff.next_index =
115 HANDOFF_DISPATCH_NEXT_IP6_INPUT;
116 else if (PREDICT_TRUE (vlib_buffer_is_mpls (b0)))
117 vnet_buffer (b0)->handoff.next_index =
118 HANDOFF_DISPATCH_NEXT_MPLS_INPUT;
120 vnet_buffer (b0)->handoff.next_index =
121 HANDOFF_DISPATCH_NEXT_ETHERNET_INPUT;
124 if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_HAVE_SUBIF) ||
125 (mb_flags & PKT_RX_VLAN_PKT)))
126 n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
129 if (PREDICT_TRUE (dpdk_mbuf_is_ip4 (mb)))
130 n0 = DPDK_RX_NEXT_IP4_INPUT;
131 else if (PREDICT_TRUE (dpdk_mbuf_is_ip6 (mb)))
132 n0 = DPDK_RX_NEXT_IP6_INPUT;
133 else if (PREDICT_TRUE (vlib_buffer_is_mpls (b0)))
134 n0 = DPDK_RX_NEXT_MPLS_INPUT;
136 n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
143 dpdk_rx_trace (dpdk_main_t * dm,
144 vlib_node_runtime_t * node,
146 u16 queue_id, u32 * buffers, uword n_buffers)
148 vlib_main_t *vm = vlib_get_main ();
159 dpdk_rx_dma_trace_t *t0;
166 b0 = vlib_get_buffer (vm, bi0);
167 mb = rte_mbuf_from_vlib_buffer (b0);
168 dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0, &next0, &error0);
169 vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ 0);
170 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
171 t0->queue_index = queue_id;
172 t0->device_index = xd->device_index;
173 t0->buffer_index = bi0;
175 clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
176 clib_memcpy (&t0->buffer, b0, sizeof (b0[0]) - sizeof (b0->pre_data));
177 clib_memcpy (t0->buffer.pre_data, b0->data,
178 sizeof (t0->buffer.pre_data));
179 clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof (t0->data));
181 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
183 * Clear overloaded TX offload flags when a DPDK driver
184 * is using them for RX flags (e.g. Cisco VIC Ethernet driver)
186 mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
187 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
194 * dpdk_efd_update_counters()
195 * Update EFD (early-fast-discard) counters
198 dpdk_efd_update_counters (dpdk_device_t * xd, u32 n_buffers, u16 enabled)
200 if (enabled & DPDK_EFD_MONITOR_ENABLED)
202 u64 now = clib_cpu_time_now ();
203 if (xd->efd_agent.last_poll_time > 0)
205 u64 elapsed_time = (now - xd->efd_agent.last_poll_time);
206 if (elapsed_time > xd->efd_agent.max_poll_delay)
207 xd->efd_agent.max_poll_delay = elapsed_time;
209 xd->efd_agent.last_poll_time = now;
212 xd->efd_agent.total_packet_cnt += n_buffers;
213 xd->efd_agent.last_burst_sz = n_buffers;
215 if (n_buffers > xd->efd_agent.max_burst_sz)
216 xd->efd_agent.max_burst_sz = n_buffers;
218 if (PREDICT_FALSE (n_buffers == VLIB_FRAME_SIZE))
220 xd->efd_agent.full_frames_cnt++;
221 xd->efd_agent.consec_full_frames_cnt++;
225 xd->efd_agent.consec_full_frames_cnt = 0;
229 /* is_efd_discardable()
230 * returns non zero DPDK error if packet meets early-fast-discard criteria,
234 is_efd_discardable (vlib_thread_main_t * tm,
235 vlib_buffer_t * b0, struct rte_mbuf *mb)
237 ethernet_header_t *eh = (ethernet_header_t *) b0->data;
239 if (eh->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP4))
242 (ip4_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
243 u8 pkt_prec = (ipv4->tos >> 5);
245 return (tm->efd.ip_prec_bitmap & (1 << pkt_prec) ?
246 DPDK_ERROR_IPV4_EFD_DROP_PKTS : DPDK_ERROR_NONE);
248 else if (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_IP6))
251 (ip6_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
253 ((ipv6->ip_version_traffic_class_and_flow_label >> 20) & 0xff);
255 return (tm->efd.ip_prec_bitmap & (1 << pkt_tclass) ?
256 DPDK_ERROR_IPV6_EFD_DROP_PKTS : DPDK_ERROR_NONE);
258 else if (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_MPLS_UNICAST))
260 mpls_unicast_header_t *mpls =
261 (mpls_unicast_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
262 u8 pkt_exp = ((mpls->label_exp_s_ttl >> 9) & 0x07);
264 return (tm->efd.mpls_exp_bitmap & (1 << pkt_exp) ?
265 DPDK_ERROR_MPLS_EFD_DROP_PKTS : DPDK_ERROR_NONE);
267 else if ((eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_VLAN)) ||
268 (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_DOT1AD)))
270 ethernet_vlan_header_t *vlan =
271 (ethernet_vlan_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
272 u8 pkt_cos = ((vlan->priority_cfi_and_id >> 13) & 0x07);
274 return (tm->efd.vlan_cos_bitmap & (1 << pkt_cos) ?
275 DPDK_ERROR_VLAN_EFD_DROP_PKTS : DPDK_ERROR_NONE);
278 return DPDK_ERROR_NONE;
282 dpdk_rx_burst (dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
288 n_left = VLIB_FRAME_SIZE;
291 if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
295 n_this_chunk = rte_eth_rx_burst (xd->device_index, queue_id,
296 xd->rx_vectors[queue_id] +
298 n_buffers += n_this_chunk;
299 n_left -= n_this_chunk;
301 /* Empirically, DPDK r1.8 produces vectors w/ 32 or fewer elts */
302 if (n_this_chunk < 32)
315 * This function is used when there are no worker threads.
316 * The main thread performs IO and forwards the packets.
319 dpdk_device_input (dpdk_main_t * dm,
321 vlib_node_runtime_t * node,
322 u32 cpu_index, u16 queue_id, int use_efd)
325 u32 next_index = DPDK_RX_NEXT_ETHERNET_INPUT;
326 u32 n_left_to_next, *to_next;
328 vlib_main_t *vm = vlib_get_main ();
329 uword n_rx_bytes = 0;
330 u32 n_trace, trace_cnt __attribute__ ((unused));
331 vlib_buffer_free_list_t *fl;
332 u8 efd_discard_burst = 0;
333 u32 buffer_flags_template;
335 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
338 n_buffers = dpdk_rx_burst (dm, xd, queue_id);
342 /* check if EFD (dpdk) is enabled */
343 if (PREDICT_FALSE (use_efd && dm->efd.enabled))
345 /* reset a few stats */
346 xd->efd_agent.last_poll_time = 0;
347 xd->efd_agent.last_burst_sz = 0;
352 buffer_flags_template = dm->buffer_flags_template;
354 vec_reset_length (xd->d_trace_buffers);
355 trace_cnt = n_trace = vlib_get_trace_count (vm, node);
357 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
359 /* Check for congestion if EFD (Early-Fast-Discard) is enabled
360 * in any mode (e.g. dpdk, monitor, or drop_all)
362 if (PREDICT_FALSE (use_efd && dm->efd.enabled))
364 /* update EFD counters */
365 dpdk_efd_update_counters (xd, n_buffers, dm->efd.enabled);
367 if (PREDICT_FALSE (dm->efd.enabled & DPDK_EFD_DROPALL_ENABLED))
369 /* discard all received packets */
370 for (mb_index = 0; mb_index < n_buffers; mb_index++)
371 rte_pktmbuf_free (xd->rx_vectors[queue_id][mb_index]);
373 xd->efd_agent.discard_cnt += n_buffers;
374 increment_efd_drop_counter (vm,
375 DPDK_ERROR_VLAN_EFD_DROP_PKTS,
381 if (PREDICT_FALSE (xd->efd_agent.consec_full_frames_cnt >=
382 dm->efd.consec_full_frames_hi_thresh))
384 u32 device_queue_sz = rte_eth_rx_queue_count (xd->device_index,
386 if (device_queue_sz >= dm->efd.queue_hi_thresh)
388 /* dpdk device queue has reached the critical threshold */
389 xd->efd_agent.congestion_cnt++;
391 /* apply EFD to packets from the burst */
392 efd_discard_burst = 1;
399 while (n_buffers > 0)
404 vlib_buffer_t *b0, *b_seg, *b_chain = 0;
407 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
409 while (n_buffers > 0 && n_left_to_next > 0)
412 struct rte_mbuf *mb = xd->rx_vectors[queue_id][mb_index];
413 struct rte_mbuf *mb_seg = mb->next;
415 if (PREDICT_TRUE (n_buffers > 2))
417 struct rte_mbuf *pfmb = xd->rx_vectors[queue_id][mb_index + 2];
418 vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf (pfmb);
419 CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, STORE);
420 CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
425 b0 = vlib_buffer_from_rte_mbuf (mb);
427 /* check whether EFD is looking for packets to discard */
428 if (PREDICT_FALSE (efd_discard_burst))
430 vlib_thread_main_t *tm = vlib_get_thread_main ();
432 if (PREDICT_TRUE (cntr_type = is_efd_discardable (tm, b0, mb)))
434 rte_pktmbuf_free (mb);
435 xd->efd_agent.discard_cnt++;
436 increment_efd_drop_counter (vm, cntr_type, 1);
443 /* Prefetch one next segment if it exists. */
444 if (PREDICT_FALSE (mb->nb_segs > 1))
446 struct rte_mbuf *pfmb = mb->next;
447 vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf (pfmb);
448 CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, LOAD);
449 CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
453 vlib_buffer_init_for_free_list (b0, fl);
455 bi0 = vlib_get_buffer_index (vm, b0);
461 dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0,
463 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
465 * Clear overloaded TX offload flags when a DPDK driver
466 * is using them for RX flags (e.g. Cisco VIC Ethernet driver)
469 if (PREDICT_TRUE (trace_cnt == 0))
470 mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
473 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
475 b0->error = node->errors[error0];
477 l3_offset0 = ((next0 == DPDK_RX_NEXT_IP4_INPUT ||
478 next0 == DPDK_RX_NEXT_IP6_INPUT ||
479 next0 == DPDK_RX_NEXT_MPLS_INPUT) ?
480 sizeof (ethernet_header_t) : 0);
482 b0->current_data = l3_offset0;
483 /* Some drivers like fm10k receive frames with
484 mb->data_off > RTE_PKTMBUF_HEADROOM */
485 b0->current_data += mb->data_off - RTE_PKTMBUF_HEADROOM;
486 b0->current_length = mb->data_len - l3_offset0;
488 b0->flags = buffer_flags_template;
490 if (VMWARE_LENGTH_BUG_WORKAROUND)
491 b0->current_length -= 4;
493 vnet_buffer (b0)->sw_if_index[VLIB_RX] = xd->vlib_sw_if_index;
494 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
495 n_rx_bytes += mb->pkt_len;
497 /* Process subsequent segments of multi-segment packets */
498 while ((mb->nb_segs > 1) && (nb_seg < mb->nb_segs))
500 ASSERT (mb_seg != 0);
502 b_seg = vlib_buffer_from_rte_mbuf (mb_seg);
503 vlib_buffer_init_for_free_list (b_seg, fl);
505 ASSERT ((b_seg->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
506 ASSERT (b_seg->current_data == 0);
509 * The driver (e.g. virtio) may not put the packet data at the start
510 * of the segment, so don't assume b_seg->current_data == 0 is correct.
512 b_seg->current_data =
513 (mb_seg->buf_addr + mb_seg->data_off) - (void *) b_seg->data;
515 b_seg->current_length = mb_seg->data_len;
516 b0->total_length_not_including_first_buffer += mb_seg->data_len;
518 b_chain->flags |= VLIB_BUFFER_NEXT_PRESENT;
519 b_chain->next_buffer = vlib_get_buffer_index (vm, b_seg);
522 mb_seg = mb_seg->next;
527 * Turn this on if you run into
528 * "bad monkey" contexts, and you want to know exactly
529 * which nodes they've visited... See main.c...
531 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
533 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
534 to_next, n_left_to_next,
536 if (PREDICT_FALSE (n_trace > mb_index))
537 vec_add1 (xd->d_trace_buffers, bi0);
541 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
544 if (PREDICT_FALSE (vec_len (xd->d_trace_buffers) > 0))
546 dpdk_rx_trace (dm, node, xd, queue_id, xd->d_trace_buffers,
547 vec_len (xd->d_trace_buffers));
548 vlib_set_trace_count (vm, node,
549 n_trace - vec_len (xd->d_trace_buffers));
552 vlib_increment_combined_counter
553 (vnet_get_main ()->interface_main.combined_sw_if_counters
554 + VNET_INTERFACE_COUNTER_RX,
555 cpu_index, xd->vlib_sw_if_index, mb_index, n_rx_bytes);
557 dpdk_worker_t *dw = vec_elt_at_index (dm->workers, cpu_index);
558 dw->aggregate_rx_packets += mb_index;
564 poll_rate_limit (dpdk_main_t * dm)
566 /* Limit the poll rate by sleeping for N msec between polls */
567 if (PREDICT_FALSE (dm->poll_sleep != 0))
569 struct timespec ts, tsrem;
572 ts.tv_nsec = 1000 * 1000 * dm->poll_sleep; /* 1ms */
574 while (nanosleep (&ts, &tsrem) < 0)
581 /** \brief Main DPDK input node
584 This is the main DPDK input node: across each assigned interface,
585 call rte_eth_rx_burst(...) or similar to obtain a vector of
586 packets to process. Handle early packet discard. Derive @c
587 vlib_buffer_t metadata from <code>struct rte_mbuf</code> metadata,
588 Depending on the resulting metadata: adjust <code>b->current_data,
589 b->current_length </code> and dispatch directly to
590 ip4-input-no-checksum, or ip6-input. Trace the packet if required.
592 @param vm vlib_main_t corresponding to the current thread
593 @param node vlib_node_runtime_t
594 @param f vlib_frame_t input-node, not used.
596 @par Graph mechanics: buffer metadata, next index usage
599 - <code>struct rte_mbuf mb->ol_flags</code>
600 - PKT_EXT_RX_PKT_ERROR, PKT_EXT_RX_BAD_FCS
601 PKT_RX_IP_CKSUM_BAD, PKT_RX_L4_CKSUM_BAD
602 - <code> RTE_ETH_IS_xxx_HDR(mb->packet_type) </code>
603 - packet classification result
606 - <code>b->error</code> if the packet is to be dropped immediately
607 - <code>b->current_data, b->current_length</code>
608 - adjusted as needed to skip the L2 header in direct-dispatch cases
609 - <code>vnet_buffer(b)->sw_if_index[VLIB_RX]</code>
610 - rx interface sw_if_index
611 - <code>vnet_buffer(b)->sw_if_index[VLIB_TX] = ~0</code>
612 - required by ipX-lookup
613 - <code>b->flags</code>
614 - to indicate multi-segment pkts (VLIB_BUFFER_NEXT_PRESENT), etc.
617 - Static arcs to: error-drop, ethernet-input,
618 ip4-input-no-checksum, ip6-input, mpls-input
619 - per-interface redirection, controlled by
620 <code>xd->per_interface_next_index</code>
624 dpdk_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f)
626 dpdk_main_t *dm = &dpdk_main;
628 uword n_rx_packets = 0;
629 dpdk_device_and_queue_t *dq;
630 u32 cpu_index = os_get_cpu_number ();
633 * Poll all devices on this cpu for input/interrupts.
636 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
638 xd = vec_elt_at_index(dm->devices, dq->device);
639 ASSERT(dq->queue_id == 0);
640 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, 0, 0);
644 poll_rate_limit (dm);
650 dpdk_input_rss (vlib_main_t * vm,
651 vlib_node_runtime_t * node, vlib_frame_t * f)
653 dpdk_main_t *dm = &dpdk_main;
655 uword n_rx_packets = 0;
656 dpdk_device_and_queue_t *dq;
657 u32 cpu_index = os_get_cpu_number ();
660 * Poll all devices on this cpu for input/interrupts.
663 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
665 xd = vec_elt_at_index(dm->devices, dq->device);
666 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 0);
670 poll_rate_limit (dm);
676 dpdk_input_efd (vlib_main_t * vm,
677 vlib_node_runtime_t * node, vlib_frame_t * f)
679 dpdk_main_t *dm = &dpdk_main;
681 uword n_rx_packets = 0;
682 dpdk_device_and_queue_t *dq;
683 u32 cpu_index = os_get_cpu_number ();
686 * Poll all devices on this cpu for input/interrupts.
689 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
691 xd = vec_elt_at_index(dm->devices, dq->device);
692 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 1);
696 poll_rate_limit (dm);
702 VLIB_REGISTER_NODE (dpdk_input_node) = {
703 .function = dpdk_input,
704 .type = VLIB_NODE_TYPE_INPUT,
705 .name = "dpdk-input",
707 /* Will be enabled if/when hardware is detected. */
708 .state = VLIB_NODE_STATE_DISABLED,
710 .format_buffer = format_ethernet_header_with_length,
711 .format_trace = format_dpdk_rx_dma_trace,
713 .n_errors = DPDK_N_ERROR,
714 .error_strings = dpdk_error_strings,
716 .n_next_nodes = DPDK_RX_N_NEXT,
718 [DPDK_RX_NEXT_DROP] = "error-drop",
719 [DPDK_RX_NEXT_ETHERNET_INPUT] = "ethernet-input",
720 [DPDK_RX_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
721 [DPDK_RX_NEXT_IP6_INPUT] = "ip6-input",
722 [DPDK_RX_NEXT_MPLS_INPUT] = "mpls-input",
727 /* handle dpdk_input_rss alternative function */
728 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input)
729 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_rss)
730 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_efd)
732 /* this macro defines dpdk_input_rss_multiarch_select() */
733 CLIB_MULTIARCH_SELECT_FN(dpdk_input);
734 CLIB_MULTIARCH_SELECT_FN(dpdk_input_rss);
735 CLIB_MULTIARCH_SELECT_FN(dpdk_input_efd);
738 * Override the next nodes for the dpdk input nodes.
739 * Must be invoked prior to VLIB_INIT_FUNCTION calls.
742 dpdk_set_next_node (dpdk_rx_next_t next, char *name)
744 vlib_node_registration_t *r = &dpdk_input_node;
745 vlib_node_registration_t *r_handoff = &handoff_dispatch_node;
749 case DPDK_RX_NEXT_IP4_INPUT:
750 case DPDK_RX_NEXT_IP6_INPUT:
751 case DPDK_RX_NEXT_MPLS_INPUT:
752 case DPDK_RX_NEXT_ETHERNET_INPUT:
753 r->next_nodes[next] = name;
754 r_handoff->next_nodes[next] = name;
758 clib_warning ("%s: illegal next %d\n", __FUNCTION__, next);
765 * Based on the operation type, set lower/upper bits for the given index value
768 set_efd_bitmap (u8 * bitmap, u32 value, u32 op)
773 for (ix = 0; ix < 8; ix++)
775 if (((op == EFD_OPERATION_LESS_THAN) && (ix < value)) ||
776 ((op == EFD_OPERATION_GREATER_OR_EQUAL) && (ix >= value)))
778 (*bitmap) |= (1 << ix);
784 efd_config (u32 enabled,
785 u32 ip_prec, u32 ip_op,
786 u32 mpls_exp, u32 mpls_op, u32 vlan_cos, u32 vlan_op)
788 vlib_thread_main_t *tm = vlib_get_thread_main ();
789 dpdk_main_t *dm = &dpdk_main;
793 tm->efd.enabled |= VLIB_EFD_DISCARD_ENABLED;
794 dm->efd.enabled |= DPDK_EFD_DISCARD_ENABLED;
798 tm->efd.enabled &= ~VLIB_EFD_DISCARD_ENABLED;
799 dm->efd.enabled &= ~DPDK_EFD_DISCARD_ENABLED;
802 set_efd_bitmap (&tm->efd.ip_prec_bitmap, ip_prec, ip_op);
803 set_efd_bitmap (&tm->efd.mpls_exp_bitmap, mpls_exp, mpls_op);
804 set_efd_bitmap (&tm->efd.vlan_cos_bitmap, vlan_cos, vlan_op);