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-gre/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->vlan_subifs || (mb_flags & PKT_RX_VLAN_PKT)))
125 n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
128 if (PREDICT_TRUE (dpdk_mbuf_is_ip4 (mb)))
129 n0 = DPDK_RX_NEXT_IP4_INPUT;
130 else if (PREDICT_TRUE (dpdk_mbuf_is_ip6 (mb)))
131 n0 = DPDK_RX_NEXT_IP6_INPUT;
132 else if (PREDICT_TRUE (vlib_buffer_is_mpls (b0)))
133 n0 = DPDK_RX_NEXT_MPLS_INPUT;
135 n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
142 dpdk_rx_trace (dpdk_main_t * dm,
143 vlib_node_runtime_t * node,
145 u16 queue_id, u32 * buffers, uword n_buffers)
147 vlib_main_t *vm = vlib_get_main ();
158 dpdk_rx_dma_trace_t *t0;
165 b0 = vlib_get_buffer (vm, bi0);
166 mb = rte_mbuf_from_vlib_buffer (b0);
167 dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0, &next0, &error0);
168 vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ 0);
169 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
170 t0->queue_index = queue_id;
171 t0->device_index = xd->device_index;
172 t0->buffer_index = bi0;
174 clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
175 clib_memcpy (&t0->buffer, b0, sizeof (b0[0]) - sizeof (b0->pre_data));
176 clib_memcpy (t0->buffer.pre_data, b0->data,
177 sizeof (t0->buffer.pre_data));
178 clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof (t0->data));
180 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
182 * Clear overloaded TX offload flags when a DPDK driver
183 * is using them for RX flags (e.g. Cisco VIC Ethernet driver)
185 mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
186 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
193 * dpdk_efd_update_counters()
194 * Update EFD (early-fast-discard) counters
197 dpdk_efd_update_counters (dpdk_device_t * xd, u32 n_buffers, u16 enabled)
199 if (enabled & DPDK_EFD_MONITOR_ENABLED)
201 u64 now = clib_cpu_time_now ();
202 if (xd->efd_agent.last_poll_time > 0)
204 u64 elapsed_time = (now - xd->efd_agent.last_poll_time);
205 if (elapsed_time > xd->efd_agent.max_poll_delay)
206 xd->efd_agent.max_poll_delay = elapsed_time;
208 xd->efd_agent.last_poll_time = now;
211 xd->efd_agent.total_packet_cnt += n_buffers;
212 xd->efd_agent.last_burst_sz = n_buffers;
214 if (n_buffers > xd->efd_agent.max_burst_sz)
215 xd->efd_agent.max_burst_sz = n_buffers;
217 if (PREDICT_FALSE (n_buffers == VLIB_FRAME_SIZE))
219 xd->efd_agent.full_frames_cnt++;
220 xd->efd_agent.consec_full_frames_cnt++;
224 xd->efd_agent.consec_full_frames_cnt = 0;
228 /* is_efd_discardable()
229 * returns non zero DPDK error if packet meets early-fast-discard criteria,
233 is_efd_discardable (vlib_thread_main_t * tm,
234 vlib_buffer_t * b0, struct rte_mbuf *mb)
236 ethernet_header_t *eh = (ethernet_header_t *) b0->data;
238 if (eh->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP4))
241 (ip4_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
242 u8 pkt_prec = (ipv4->tos >> 5);
244 return (tm->efd.ip_prec_bitmap & (1 << pkt_prec) ?
245 DPDK_ERROR_IPV4_EFD_DROP_PKTS : DPDK_ERROR_NONE);
247 else if (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_IP6))
250 (ip6_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
252 ((ipv6->ip_version_traffic_class_and_flow_label >> 20) & 0xff);
254 return (tm->efd.ip_prec_bitmap & (1 << pkt_tclass) ?
255 DPDK_ERROR_IPV6_EFD_DROP_PKTS : DPDK_ERROR_NONE);
257 else if (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_MPLS_UNICAST))
259 mpls_unicast_header_t *mpls =
260 (mpls_unicast_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
261 u8 pkt_exp = ((mpls->label_exp_s_ttl >> 9) & 0x07);
263 return (tm->efd.mpls_exp_bitmap & (1 << pkt_exp) ?
264 DPDK_ERROR_MPLS_EFD_DROP_PKTS : DPDK_ERROR_NONE);
266 else if ((eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_VLAN)) ||
267 (eh->type == clib_net_to_host_u16 (ETHERNET_TYPE_DOT1AD)))
269 ethernet_vlan_header_t *vlan =
270 (ethernet_vlan_header_t *) & (b0->data[sizeof (ethernet_header_t)]);
271 u8 pkt_cos = ((vlan->priority_cfi_and_id >> 13) & 0x07);
273 return (tm->efd.vlan_cos_bitmap & (1 << pkt_cos) ?
274 DPDK_ERROR_VLAN_EFD_DROP_PKTS : DPDK_ERROR_NONE);
277 return DPDK_ERROR_NONE;
281 dpdk_rx_burst (dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
287 n_left = VLIB_FRAME_SIZE;
290 if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
294 n_this_chunk = rte_eth_rx_burst (xd->device_index, queue_id,
295 xd->rx_vectors[queue_id] +
297 n_buffers += n_this_chunk;
298 n_left -= n_this_chunk;
300 /* Empirically, DPDK r1.8 produces vectors w/ 32 or fewer elts */
301 if (n_this_chunk < 32)
306 else if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
308 vlib_main_t *vm = vlib_get_main ();
309 vlib_buffer_main_t *bm = vm->buffer_main;
310 unsigned socket_id = rte_socket_id ();
313 offset = queue_id * VIRTIO_QNUM;
315 struct vhost_virtqueue *vq =
316 xd->vu_vhost_dev.virtqueue[offset + VIRTIO_TXQ];
318 if (PREDICT_FALSE (!vq->enabled))
321 struct rte_mbuf **pkts = xd->rx_vectors[queue_id];
324 n_this_chunk = rte_vhost_dequeue_burst (&xd->vu_vhost_dev,
328 pkts + n_buffers, n_left);
329 n_buffers += n_this_chunk;
330 n_left -= n_this_chunk;
331 if (n_this_chunk == 0)
337 for (i = 0; i < n_buffers; i++)
339 struct rte_mbuf *buff = pkts[i];
340 bytes += rte_pktmbuf_data_len (buff);
343 f64 now = vlib_time_now (vm);
345 dpdk_vu_vring *vring = NULL;
346 /* send pending interrupts if needed */
347 if (dpdk_vhost_user_want_interrupt (xd, offset + VIRTIO_TXQ))
349 vring = &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
350 vring->n_since_last_int += n_buffers;
352 if ((vring->n_since_last_int && (vring->int_deadline < now))
353 || (vring->n_since_last_int > dm->conf->vhost_coalesce_frames))
354 dpdk_vhost_user_send_interrupt (vm, xd, offset + VIRTIO_TXQ);
357 vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
358 vring->packets += n_buffers;
359 vring->bytes += bytes;
361 if (dpdk_vhost_user_want_interrupt (xd, offset + VIRTIO_RXQ))
363 if (vring->n_since_last_int && (vring->int_deadline < now))
364 dpdk_vhost_user_send_interrupt (vm, xd, offset + VIRTIO_RXQ);
369 #ifdef RTE_LIBRTE_KNI
370 else if (xd->flags & DPDK_DEVICE_FLAG_KNI)
373 rte_kni_rx_burst (xd->kni, xd->rx_vectors[queue_id], VLIB_FRAME_SIZE);
374 rte_kni_handle_request (xd->kni);
386 * This function is used when there are no worker threads.
387 * The main thread performs IO and forwards the packets.
390 dpdk_device_input (dpdk_main_t * dm,
392 vlib_node_runtime_t * node,
393 u32 cpu_index, u16 queue_id, int use_efd)
396 u32 next_index = DPDK_RX_NEXT_ETHERNET_INPUT;
397 u32 n_left_to_next, *to_next;
399 vlib_main_t *vm = vlib_get_main ();
400 uword n_rx_bytes = 0;
401 u32 n_trace, trace_cnt __attribute__ ((unused));
402 vlib_buffer_free_list_t *fl;
403 u8 efd_discard_burst = 0;
404 u32 buffer_flags_template;
406 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
409 n_buffers = dpdk_rx_burst (dm, xd, queue_id);
413 /* check if EFD (dpdk) is enabled */
414 if (PREDICT_FALSE (use_efd && dm->efd.enabled))
416 /* reset a few stats */
417 xd->efd_agent.last_poll_time = 0;
418 xd->efd_agent.last_burst_sz = 0;
423 buffer_flags_template = dm->buffer_flags_template;
425 vec_reset_length (xd->d_trace_buffers);
426 trace_cnt = n_trace = vlib_get_trace_count (vm, node);
428 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
430 /* Check for congestion if EFD (Early-Fast-Discard) is enabled
431 * in any mode (e.g. dpdk, monitor, or drop_all)
433 if (PREDICT_FALSE (use_efd && dm->efd.enabled))
435 /* update EFD counters */
436 dpdk_efd_update_counters (xd, n_buffers, dm->efd.enabled);
438 if (PREDICT_FALSE (dm->efd.enabled & DPDK_EFD_DROPALL_ENABLED))
440 /* discard all received packets */
441 for (mb_index = 0; mb_index < n_buffers; mb_index++)
442 rte_pktmbuf_free (xd->rx_vectors[queue_id][mb_index]);
444 xd->efd_agent.discard_cnt += n_buffers;
445 increment_efd_drop_counter (vm,
446 DPDK_ERROR_VLAN_EFD_DROP_PKTS,
452 if (PREDICT_FALSE (xd->efd_agent.consec_full_frames_cnt >=
453 dm->efd.consec_full_frames_hi_thresh))
455 u32 device_queue_sz = rte_eth_rx_queue_count (xd->device_index,
457 if (device_queue_sz >= dm->efd.queue_hi_thresh)
459 /* dpdk device queue has reached the critical threshold */
460 xd->efd_agent.congestion_cnt++;
462 /* apply EFD to packets from the burst */
463 efd_discard_burst = 1;
470 while (n_buffers > 0)
475 vlib_buffer_t *b0, *b_seg, *b_chain = 0;
478 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
480 while (n_buffers > 0 && n_left_to_next > 0)
483 struct rte_mbuf *mb = xd->rx_vectors[queue_id][mb_index];
484 struct rte_mbuf *mb_seg = mb->next;
486 if (PREDICT_TRUE (n_buffers > 2))
488 struct rte_mbuf *pfmb = xd->rx_vectors[queue_id][mb_index + 2];
489 vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf (pfmb);
490 CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, STORE);
491 CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
496 b0 = vlib_buffer_from_rte_mbuf (mb);
498 /* check whether EFD is looking for packets to discard */
499 if (PREDICT_FALSE (efd_discard_burst))
501 vlib_thread_main_t *tm = vlib_get_thread_main ();
503 if (PREDICT_TRUE (cntr_type = is_efd_discardable (tm, b0, mb)))
505 rte_pktmbuf_free (mb);
506 xd->efd_agent.discard_cnt++;
507 increment_efd_drop_counter (vm, cntr_type, 1);
514 /* Prefetch one next segment if it exists. */
515 if (PREDICT_FALSE (mb->nb_segs > 1))
517 struct rte_mbuf *pfmb = mb->next;
518 vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf (pfmb);
519 CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, LOAD);
520 CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
524 vlib_buffer_init_for_free_list (b0, fl);
526 bi0 = vlib_get_buffer_index (vm, b0);
532 dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0,
534 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
536 * Clear overloaded TX offload flags when a DPDK driver
537 * is using them for RX flags (e.g. Cisco VIC Ethernet driver)
540 if (PREDICT_TRUE (trace_cnt == 0))
541 mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
544 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
546 b0->error = node->errors[error0];
548 l3_offset0 = ((next0 == DPDK_RX_NEXT_IP4_INPUT ||
549 next0 == DPDK_RX_NEXT_IP6_INPUT ||
550 next0 == DPDK_RX_NEXT_MPLS_INPUT) ?
551 sizeof (ethernet_header_t) : 0);
553 b0->current_data = l3_offset0;
554 /* Some drivers like fm10k receive frames with
555 mb->data_off > RTE_PKTMBUF_HEADROOM */
556 b0->current_data += mb->data_off - RTE_PKTMBUF_HEADROOM;
557 b0->current_length = mb->data_len - l3_offset0;
559 b0->flags = buffer_flags_template;
561 if (VMWARE_LENGTH_BUG_WORKAROUND)
562 b0->current_length -= 4;
564 vnet_buffer (b0)->sw_if_index[VLIB_RX] = xd->vlib_sw_if_index;
565 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
566 n_rx_bytes += mb->pkt_len;
568 /* Process subsequent segments of multi-segment packets */
569 while ((mb->nb_segs > 1) && (nb_seg < mb->nb_segs))
571 ASSERT (mb_seg != 0);
573 b_seg = vlib_buffer_from_rte_mbuf (mb_seg);
574 vlib_buffer_init_for_free_list (b_seg, fl);
576 ASSERT ((b_seg->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
577 ASSERT (b_seg->current_data == 0);
580 * The driver (e.g. virtio) may not put the packet data at the start
581 * of the segment, so don't assume b_seg->current_data == 0 is correct.
583 b_seg->current_data =
584 (mb_seg->buf_addr + mb_seg->data_off) - (void *) b_seg->data;
586 b_seg->current_length = mb_seg->data_len;
587 b0->total_length_not_including_first_buffer += mb_seg->data_len;
589 b_chain->flags |= VLIB_BUFFER_NEXT_PRESENT;
590 b_chain->next_buffer = vlib_get_buffer_index (vm, b_seg);
593 mb_seg = mb_seg->next;
598 * Turn this on if you run into
599 * "bad monkey" contexts, and you want to know exactly
600 * which nodes they've visited... See main.c...
602 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
604 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
605 to_next, n_left_to_next,
607 if (PREDICT_FALSE (n_trace > mb_index))
608 vec_add1 (xd->d_trace_buffers, bi0);
612 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
615 if (PREDICT_FALSE (vec_len (xd->d_trace_buffers) > 0))
617 dpdk_rx_trace (dm, node, xd, queue_id, xd->d_trace_buffers,
618 vec_len (xd->d_trace_buffers));
619 vlib_set_trace_count (vm, node,
620 n_trace - vec_len (xd->d_trace_buffers));
623 vlib_increment_combined_counter
624 (vnet_get_main ()->interface_main.combined_sw_if_counters
625 + VNET_INTERFACE_COUNTER_RX,
626 cpu_index, xd->vlib_sw_if_index, mb_index, n_rx_bytes);
628 dpdk_worker_t *dw = vec_elt_at_index (dm->workers, cpu_index);
629 dw->aggregate_rx_packets += mb_index;
635 poll_rate_limit (dpdk_main_t * dm)
637 /* Limit the poll rate by sleeping for N msec between polls */
638 if (PREDICT_FALSE (dm->poll_sleep != 0))
640 struct timespec ts, tsrem;
643 ts.tv_nsec = 1000 * 1000 * dm->poll_sleep; /* 1ms */
645 while (nanosleep (&ts, &tsrem) < 0)
652 /** \brief Main DPDK input node
655 This is the main DPDK input node: across each assigned interface,
656 call rte_eth_rx_burst(...) or similar to obtain a vector of
657 packets to process. Handle early packet discard. Derive @c
658 vlib_buffer_t metadata from <code>struct rte_mbuf</code> metadata,
659 Depending on the resulting metadata: adjust <code>b->current_data,
660 b->current_length </code> and dispatch directly to
661 ip4-input-no-checksum, or ip6-input. Trace the packet if required.
663 @param vm vlib_main_t corresponding to the current thread
664 @param node vlib_node_runtime_t
665 @param f vlib_frame_t input-node, not used.
667 @par Graph mechanics: buffer metadata, next index usage
670 - <code>struct rte_mbuf mb->ol_flags</code>
671 - PKT_EXT_RX_PKT_ERROR, PKT_EXT_RX_BAD_FCS
672 PKT_RX_IP_CKSUM_BAD, PKT_RX_L4_CKSUM_BAD
673 - <code> RTE_ETH_IS_xxx_HDR(mb->packet_type) </code>
674 - packet classification result
677 - <code>b->error</code> if the packet is to be dropped immediately
678 - <code>b->current_data, b->current_length</code>
679 - adjusted as needed to skip the L2 header in direct-dispatch cases
680 - <code>vnet_buffer(b)->sw_if_index[VLIB_RX]</code>
681 - rx interface sw_if_index
682 - <code>vnet_buffer(b)->sw_if_index[VLIB_TX] = ~0</code>
683 - required by ipX-lookup
684 - <code>b->flags</code>
685 - to indicate multi-segment pkts (VLIB_BUFFER_NEXT_PRESENT), etc.
688 - Static arcs to: error-drop, ethernet-input,
689 ip4-input-no-checksum, ip6-input, mpls-gre-input
690 - per-interface redirection, controlled by
691 <code>xd->per_interface_next_index</code>
695 dpdk_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f)
697 dpdk_main_t *dm = &dpdk_main;
699 uword n_rx_packets = 0;
700 dpdk_device_and_queue_t *dq;
701 u32 cpu_index = os_get_cpu_number ();
704 * Poll all devices on this cpu for input/interrupts.
707 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
709 xd = vec_elt_at_index(dm->devices, dq->device);
710 ASSERT(dq->queue_id == 0);
711 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, 0, 0);
715 poll_rate_limit (dm);
721 dpdk_input_rss (vlib_main_t * vm,
722 vlib_node_runtime_t * node, vlib_frame_t * f)
724 dpdk_main_t *dm = &dpdk_main;
726 uword n_rx_packets = 0;
727 dpdk_device_and_queue_t *dq;
728 u32 cpu_index = os_get_cpu_number ();
731 * Poll all devices on this cpu for input/interrupts.
734 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
736 xd = vec_elt_at_index(dm->devices, dq->device);
737 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 0);
741 poll_rate_limit (dm);
747 dpdk_input_efd (vlib_main_t * vm,
748 vlib_node_runtime_t * node, vlib_frame_t * f)
750 dpdk_main_t *dm = &dpdk_main;
752 uword n_rx_packets = 0;
753 dpdk_device_and_queue_t *dq;
754 u32 cpu_index = os_get_cpu_number ();
757 * Poll all devices on this cpu for input/interrupts.
760 vec_foreach (dq, dm->devices_by_cpu[cpu_index])
762 xd = vec_elt_at_index(dm->devices, dq->device);
763 n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 1);
767 poll_rate_limit (dm);
773 VLIB_REGISTER_NODE (dpdk_input_node) = {
774 .function = dpdk_input,
775 .type = VLIB_NODE_TYPE_INPUT,
776 .name = "dpdk-input",
778 /* Will be enabled if/when hardware is detected. */
779 .state = VLIB_NODE_STATE_DISABLED,
781 .format_buffer = format_ethernet_header_with_length,
782 .format_trace = format_dpdk_rx_dma_trace,
784 .n_errors = DPDK_N_ERROR,
785 .error_strings = dpdk_error_strings,
787 .n_next_nodes = DPDK_RX_N_NEXT,
789 [DPDK_RX_NEXT_DROP] = "error-drop",
790 [DPDK_RX_NEXT_ETHERNET_INPUT] = "ethernet-input",
791 [DPDK_RX_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
792 [DPDK_RX_NEXT_IP6_INPUT] = "ip6-input",
793 [DPDK_RX_NEXT_MPLS_INPUT] = "mpls-gre-input",
798 /* handle dpdk_input_rss alternative function */
799 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input)
800 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_rss)
801 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_efd)
803 /* this macro defines dpdk_input_rss_multiarch_select() */
804 CLIB_MULTIARCH_SELECT_FN(dpdk_input);
805 CLIB_MULTIARCH_SELECT_FN(dpdk_input_rss);
806 CLIB_MULTIARCH_SELECT_FN(dpdk_input_efd);
810 * Override the next nodes for the dpdk input nodes.
811 * Must be invoked prior to VLIB_INIT_FUNCTION calls.
814 dpdk_set_next_node (dpdk_rx_next_t next, char *name)
816 vlib_node_registration_t *r = &dpdk_input_node;
817 vlib_node_registration_t *r_handoff = &handoff_dispatch_node;
821 case DPDK_RX_NEXT_IP4_INPUT:
822 case DPDK_RX_NEXT_IP6_INPUT:
823 case DPDK_RX_NEXT_MPLS_INPUT:
824 case DPDK_RX_NEXT_ETHERNET_INPUT:
825 r->next_nodes[next] = name;
826 r_handoff->next_nodes[next] = name;
830 clib_warning ("%s: illegal next %d\n", __FUNCTION__, next);
837 * Based on the operation type, set lower/upper bits for the given index value
840 set_efd_bitmap (u8 * bitmap, u32 value, u32 op)
845 for (ix = 0; ix < 8; ix++)
847 if (((op == EFD_OPERATION_LESS_THAN) && (ix < value)) ||
848 ((op == EFD_OPERATION_GREATER_OR_EQUAL) && (ix >= value)))
850 (*bitmap) |= (1 << ix);
856 efd_config (u32 enabled,
857 u32 ip_prec, u32 ip_op,
858 u32 mpls_exp, u32 mpls_op, u32 vlan_cos, u32 vlan_op)
860 vlib_thread_main_t *tm = vlib_get_thread_main ();
861 dpdk_main_t *dm = &dpdk_main;
865 tm->efd.enabled |= VLIB_EFD_DISCARD_ENABLED;
866 dm->efd.enabled |= DPDK_EFD_DISCARD_ENABLED;
870 tm->efd.enabled &= ~VLIB_EFD_DISCARD_ENABLED;
871 dm->efd.enabled &= ~DPDK_EFD_DISCARD_ENABLED;
874 set_efd_bitmap (&tm->efd.ip_prec_bitmap, ip_prec, ip_op);
875 set_efd_bitmap (&tm->efd.mpls_exp_bitmap, mpls_exp, mpls_op);
876 set_efd_bitmap (&tm->efd.vlan_cos_bitmap, vlan_cos, vlan_op);
880 * fd.io coding-style-patch-verification: ON
883 * eval: (c-set-style "gnu")