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>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/devices/dpdk/dpdk.h>
22 #include <vlib/unix/physmem.h>
28 #include <sys/mount.h>
32 #include "dpdk_priv.h"
34 dpdk_main_t dpdk_main;
36 /* force linker to link functions used by vlib and declared weak */
37 void *vlib_weakly_linked_functions[] = {
39 &rte_pktmbuf_pool_init,
42 #define LINK_STATE_ELOGS 0
44 #define DEFAULT_HUGE_DIR "/run/vpp/hugepages"
45 #define VPP_RUN_DIR "/run/vpp"
47 /* Port configuration, mildly modified Intel app values */
49 static struct rte_eth_conf port_conf_template = {
52 .header_split = 0, /**< Header Split disabled */
53 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
54 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
55 .hw_strip_crc = 1, /**< CRC stripped by hardware */
58 .mq_mode = ETH_MQ_TX_NONE,
63 dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd)
65 vlib_main_t * vm = vlib_get_main();
66 vlib_buffer_main_t * bm = vm->buffer_main;
70 ASSERT(os_get_cpu_number() == 0);
73 vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0);
74 rte_eth_dev_stop (xd->device_index);
77 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
78 xd->tx_q_used, &xd->port_conf);
81 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
82 xd->device_index, rv);
84 /* Set up one TX-queue per worker thread */
85 for (j = 0; j < xd->tx_q_used; j++)
87 rv = rte_eth_tx_queue_setup(xd->device_index, j, xd->nb_tx_desc,
88 xd->cpu_socket, &xd->tx_conf);
94 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
95 xd->device_index, rv);
97 for (j = 0; j < xd->rx_q_used; j++)
100 rv = rte_eth_rx_queue_setup(xd->device_index, j, xd->nb_rx_desc,
102 bm->pktmbuf_pools[xd->cpu_socket_id_by_queue[j]]);
104 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
105 xd->device_index, rv);
109 rte_eth_dev_start (xd->device_index);
114 static u32 dpdk_flag_change (vnet_main_t * vnm,
115 vnet_hw_interface_t * hi,
118 dpdk_main_t * dm = &dpdk_main;
119 dpdk_device_t * xd = vec_elt_at_index (dm->devices, hi->dev_instance);
122 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC(flags))
125 xd->promisc = flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
130 rte_eth_promiscuous_enable(xd->device_index);
132 rte_eth_promiscuous_disable(xd->device_index);
135 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU(flags))
138 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
139 * driver to dynamically change the mtu. If/when the
140 * VIC firmware gets fixed, then this should be removed.
142 if (xd->pmd == VNET_DPDK_PMD_VICE ||
143 xd->pmd == VNET_DPDK_PMD_ENIC)
145 struct rte_eth_dev_info dev_info;
148 * Restore mtu to what has been set by CIMC in the firmware cfg.
150 rte_eth_dev_info_get(xd->device_index, &dev_info);
151 hi->max_packet_bytes = dev_info.max_rx_pktlen;
153 vlib_cli_output (vlib_get_main(),
154 "Cisco VIC mtu can only be changed "
155 "using CIMC then rebooting the server!");
162 * DAW-FIXME: The DPDK VMXNET3 driver does not currently support
163 * multi-buffer packets. Max out at 1518 bytes for now.
165 * If/when the driver gets fixed, then this should be
168 if ((xd->pmd == VNET_DPDK_PMD_VMXNET3) &&
169 (hi->max_packet_bytes > 1518))
171 hi->max_packet_bytes = 1518;
173 vlib_cli_output (vlib_get_main(),
174 "VMXNET3 driver does not support jumbo frames "
175 "yet -- setting mtu to 1518!");
178 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
181 rte_eth_dev_stop (xd->device_index);
183 rv = rte_eth_dev_configure
190 vlib_cli_output (vlib_get_main(),
191 "rte_eth_dev_configure[%d]: err %d",
192 xd->device_index, rv);
194 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
197 rte_eth_dev_start (xd->device_index);
204 extern int rte_netmap_probe(void);
208 dpdk_device_lock_init(dpdk_device_t * xd)
211 vec_validate(xd->lockp, xd->tx_q_used - 1);
212 for (q = 0; q < xd->tx_q_used; q++)
214 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
215 CLIB_CACHE_LINE_BYTES);
216 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
222 dpdk_device_lock_free(dpdk_device_t * xd)
226 for (q = 0; q < vec_len(xd->lockp); q++)
227 clib_mem_free((void *) xd->lockp[q]);
233 static clib_error_t *
234 dpdk_lib_init (dpdk_main_t * dm)
239 clib_error_t * error;
240 vlib_main_t * vm = vlib_get_main();
241 vlib_thread_main_t * tm = vlib_get_thread_main();
242 vnet_sw_interface_t * sw;
243 vnet_hw_interface_t * hi;
245 vlib_thread_registration_t * tr;
249 u8 af_packet_port_id = 0;
251 dm->input_cpu_first_index = 0;
252 dm->input_cpu_count = 1;
254 /* find out which cpus will be used for input */
255 p = hash_get_mem (tm->thread_registrations_by_name, "io");
256 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
258 if (!tr || tr->count == 0)
260 /* no io threads, workers doing input */
261 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
262 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
266 dm->have_io_threads = 1;
269 if (tr && tr->count > 0)
271 dm->input_cpu_first_index = tr->first_index;
272 dm->input_cpu_count = tr->count;
275 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
276 CLIB_CACHE_LINE_BYTES);
278 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
279 CLIB_CACHE_LINE_BYTES);
282 if(rte_netmap_probe() < 0)
283 return clib_error_return (0, "rte netmap probe failed");
286 nports = rte_eth_dev_count();
289 clib_warning ("DPDK drivers found no ports...");
293 clib_warning ("DPDK drivers found %d ports...", nports);
296 * All buffers are all allocated from the same rte_mempool.
297 * Thus they all have the same number of data bytes.
299 dm->vlib_buffer_free_list_index =
300 vlib_buffer_get_or_create_free_list (
301 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
303 for (i = 0; i < nports; i++)
307 struct rte_eth_dev_info dev_info;
309 struct rte_eth_link l;
311 /* Create vnet interface */
312 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
313 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
314 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
315 xd->cpu_socket = (i8) rte_eth_dev_socket_id(i);
316 rte_eth_dev_info_get(i, &dev_info);
318 memcpy(&xd->tx_conf, &dev_info.default_txconf,
319 sizeof(struct rte_eth_txconf));
320 if (dm->no_multi_seg)
322 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
323 port_conf_template.rxmode.jumbo_frame = 0;
327 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
328 port_conf_template.rxmode.jumbo_frame = 1;
331 memcpy(&xd->port_conf, &port_conf_template, sizeof(struct rte_eth_conf));
333 xd->tx_q_used = clib_min(dev_info.max_tx_queues, tm->n_vlib_mains);
335 if (dm->max_tx_queues)
336 xd->tx_q_used = clib_min(xd->tx_q_used, dm->max_tx_queues);
338 if (dm->use_rss > 1 && dev_info.max_rx_queues >= dm->use_rss)
340 xd->rx_q_used = dm->use_rss;
341 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
342 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
347 xd->dev_type = VNET_DPDK_DEV_ETH;
349 /* workaround for drivers not setting driver_name */
350 if (!dev_info.driver_name)
351 dev_info.driver_name = dev_info.pci_dev->driver->name;
352 ASSERT(dev_info.driver_name);
357 #define _(s,f) else if (!strcmp(dev_info.driver_name, s)) \
358 xd->pmd = VNET_DPDK_PMD_##f;
364 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
369 case VNET_DPDK_PMD_E1000EM:
370 case VNET_DPDK_PMD_IGB:
371 case VNET_DPDK_PMD_IGBVF:
372 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
376 case VNET_DPDK_PMD_IXGBE:
377 case VNET_DPDK_PMD_IXGBEVF:
378 case VNET_DPDK_PMD_THUNDERX:
379 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
380 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
381 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
385 case VNET_DPDK_PMD_VICE:
386 case VNET_DPDK_PMD_ENIC:
387 rte_eth_link_get_nowait(i, &l);
388 if (l.link_speed == 40000)
390 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
391 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
392 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
396 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
397 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
398 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
402 /* Intel Fortville */
403 case VNET_DPDK_PMD_I40E:
404 case VNET_DPDK_PMD_I40EVF:
405 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
406 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
407 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
409 switch (dev_info.pci_dev->id.device_id) {
410 case I40E_DEV_ID_10G_BASE_T:
411 case I40E_DEV_ID_SFP_XL710:
412 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
414 case I40E_DEV_ID_QSFP_A:
415 case I40E_DEV_ID_QSFP_B:
416 case I40E_DEV_ID_QSFP_C:
417 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
420 rte_eth_link_get_nowait(i, &l);
421 xd->port_type = l.link_speed == 10000 ?
422 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
425 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
429 case VNET_DPDK_PMD_CXGBE:
430 switch (dev_info.pci_dev->id.device_id) {
431 case 0x5410: /* T580-LP-cr */
432 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
433 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
434 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
437 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
438 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
439 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
443 /* Intel Red Rock Canyon */
444 case VNET_DPDK_PMD_FM10K:
445 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
446 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
447 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
451 case VNET_DPDK_PMD_VIRTIO:
452 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
453 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
454 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
458 case VNET_DPDK_PMD_VMXNET3:
459 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
460 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
463 case VNET_DPDK_PMD_AF_PACKET:
464 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
465 xd->af_packet_port_id = af_packet_port_id++;
468 case VNET_DPDK_PMD_BOND:
469 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
473 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
477 if(strncmp(dev_info.driver_name, "vale", 4) == 0
478 || strncmp(dev_info.driver_name, "netmap", 6) == 0)
480 xd->pmd = VNET_DPDK_PMD_NETMAP;
481 xd->port_type = VNET_DPDK_PORT_TYPE_NETMAP;
488 * Ensure default mtu is not > the mtu read from the hardware.
489 * Otherwise rte_eth_dev_configure() will fail and the port will
492 xd->port_conf.rxmode.max_rx_pkt_len =
493 (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen) ?
494 dev_info.max_rx_pktlen : ETHERNET_MAX_PACKET_BYTES;
497 * DAW-FIXME: VMXNET3 driver doesn't support jumbo / multi-buffer pkts
499 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
501 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
502 xd->port_conf.rxmode.jumbo_frame = 0;
505 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
507 f64 now = vlib_time_now(vm);
509 rnd = (u32) (now * 1e6);
510 rnd = random_u32 (&rnd);
511 memcpy (addr+2, &rnd, sizeof(rnd));
516 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
518 if (xd->tx_q_used < tm->n_vlib_mains)
519 dpdk_device_lock_init(xd);
521 xd->device_index = xd - dm->devices;
522 ASSERT(i == xd->device_index);
523 xd->per_interface_next_index = ~0;
525 /* assign interface to input thread */
526 dpdk_device_and_queue_t * dq;
529 for (q = 0; q < xd->rx_q_used; q++)
531 int cpu = dm->input_cpu_first_index + next_cpu;
532 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
535 * numa node for worker thread handling this queue
536 * needed for taking buffers from the right mempool
538 vec_validate(xd->cpu_socket_id_by_queue, q);
539 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
542 * construct vector of (device,queue) pairs for each worker thread
544 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
545 dq->device = xd->device_index;
549 if (next_cpu == dm->input_cpu_count)
553 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
554 CLIB_CACHE_LINE_BYTES);
555 for (j = 0; j < tm->n_vlib_mains; j++)
557 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
558 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
559 vec_reset_length (xd->tx_vectors[j]);
562 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
563 CLIB_CACHE_LINE_BYTES);
564 for (j = 0; j< xd->rx_q_used; j++)
566 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
567 CLIB_CACHE_LINE_BYTES);
568 vec_reset_length (xd->rx_vectors[j]);
571 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
572 CLIB_CACHE_LINE_BYTES);
574 rv = dpdk_port_setup(dm, xd);
579 /* count the number of descriptors used for this device */
580 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
582 error = ethernet_register_interface
584 dpdk_device_class.index,
586 /* ethernet address */ addr,
587 &xd->vlib_hw_if_index,
592 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
593 xd->vlib_sw_if_index = sw->sw_if_index;
594 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
597 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
598 * driver to dynamically change the mtu. If/when the
599 * VIC firmware gets fixed, then this should be removed.
601 if (xd->pmd == VNET_DPDK_PMD_VICE ||
602 xd->pmd == VNET_DPDK_PMD_ENIC)
605 * Initialize mtu to what has been set by CIMC in the firmware cfg.
607 hi->max_packet_bytes = dev_info.max_rx_pktlen;
609 * remove vlan tag from VIC port to fix VLAN0 issue.
610 * TODO Handle VLAN tagged traffic
613 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
614 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
615 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
618 * DAW-FIXME: VMXNET3 driver doesn't support jumbo / multi-buffer pkts
620 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
621 hi->max_packet_bytes = 1518;
623 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
624 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
626 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
629 #ifdef RTE_LIBRTE_KNI
631 clib_warning("Initializing KNI interfaces...");
632 rte_kni_init(dm->num_kni);
633 for (i = 0; i < dm->num_kni; i++)
638 /* Create vnet interface */
639 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
640 xd->dev_type = VNET_DPDK_DEV_KNI;
642 xd->device_index = xd - dm->devices;
643 ASSERT(nports + i == xd->device_index);
644 xd->per_interface_next_index = ~0;
647 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
650 /* assign interface to input thread */
651 dpdk_device_and_queue_t * dq;
652 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
653 dq->device = xd->device_index;
656 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
657 CLIB_CACHE_LINE_BYTES);
658 for (j = 0; j < tm->n_vlib_mains; j++)
660 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
661 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
662 vec_reset_length (xd->tx_vectors[j]);
665 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
666 CLIB_CACHE_LINE_BYTES);
667 for (j = 0; j< xd->rx_q_used; j++)
669 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
670 CLIB_CACHE_LINE_BYTES);
671 vec_reset_length (xd->rx_vectors[j]);
674 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
675 CLIB_CACHE_LINE_BYTES);
677 /* FIXME Set up one TX-queue per worker thread */
680 f64 now = vlib_time_now(vm);
682 rnd = (u32) (now * 1e6);
683 rnd = random_u32 (&rnd);
685 memcpy (addr+2, &rnd, sizeof(rnd));
690 error = ethernet_register_interface
692 dpdk_device_class.index,
694 /* ethernet address */ addr,
695 &xd->vlib_hw_if_index,
701 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
702 xd->vlib_sw_if_index = sw->sw_if_index;
703 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
708 if (nb_desc > dm->num_mbufs)
709 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
710 dm->num_mbufs, nb_desc);
712 /* init next vhost-user if index */
713 dm->next_vu_if_id = 0;
718 static clib_error_t *
719 write_sys_fs (char * file_name, char * fmt, ...)
724 fd = open (file_name, O_WRONLY);
726 return clib_error_return_unix (0, "open `%s'", file_name);
730 s = va_format (0, fmt, &va);
732 vec_add1 (s, 0); // terminate c string
734 if (write (fd, s, vec_len (s)) < 0)
735 return clib_error_return_unix (0, "write '%s' to '%s'", s, file_name);
742 #define VIRTIO_PCI_NAME "virtio-pci"
744 static clib_error_t * dpdk_bind_eth_kernel_drivers (vlib_main_t * vm,
746 char * kernel_driver)
748 dpdk_main_t * dm = &dpdk_main;
749 unformat_input_t _in;
750 unformat_input_t * in = &_in;
751 clib_error_t * error = 0;
752 u8 * line = 0, * modcmd = 0, * path = 0;
753 u8 * pci_vid = 0, *pci_did = 0, * devname = 0;
754 char *driver_name = kernel_driver;
758 * Bail out now if we're not running as root.
759 * This allows non-privileged use of the packet generator, etc.
765 * Get all ethernet pci device numbers for the device type specified.
767 modcmd = format (0, "lspci -nDd %s | grep 0200 | "
768 "awk '{ print $1, $3 }'%c", pci_dev_id, 0);
769 if ((fp = popen ((const char *)modcmd, "r")) == NULL)
771 error = clib_error_return_unix (0,
772 "Unable to get %s ethernet pci devices.",
777 vec_validate (line, BUFSIZ);
778 vec_validate (path, BUFSIZ);
779 while (fgets ((char *)line, BUFSIZ, fp) != NULL)
783 line[strlen ((char *)line) - 1] = 0; // chomp trailing newline.
785 unformat_init_string (in, (char *)line, strlen((char *)line) + 1);
786 unformat(in, "%s %s:%s", &devname, &pci_vid, &pci_did);
790 * Blacklist all ethernet interfaces in the
791 * linux IP routing tables (route --inet --inet6)
793 if (strstr ((char *)dm->eth_if_blacklist, (char *)devname))
797 * If there are any devices whitelisted, then blacklist all devices
798 * which are not explicitly whitelisted.
800 if (dm->eth_if_whitelist &&
801 !strstr ((char *)dm->eth_if_whitelist, (char *)devname))
806 * Optimistically open the device as a netmap device.
808 if (eth_nm_open((char *)devname))
813 path = format (path, "/sys/bus/pci/devices/%s/driver/unbind%c",
817 * If the device is bound to a driver...
819 if (stat ((const char *)path, &st) == 0)
824 * If the interface is not a virtio...
826 if (!driver_name || strcmp(driver_name, VIRTIO_PCI_NAME))
829 * If it is already bound to driver, don't unbind/bind it.
831 device_path = format (0, "/sys/bus/pci/drivers/%s/%s/device%c",
832 driver_name, devname, 0);
833 if (stat ((const char *)device_path, &st) == 0)
836 vec_free (device_path);
840 * unbind it from the current driver
844 _vec_len (path) -= 1;
845 path = format (path, "%c", 0);
846 error = write_sys_fs ((char *)path, "%s", devname);
853 * DAW-FIXME: The following bind/unbind dance is necessary for the dpdk
854 * virtio poll-mode driver to work.
857 if (driver_name && !strcmp(driver_name, VIRTIO_PCI_NAME))
860 * bind interface to the native kernel module
863 path = format (path, "/sys/bus/pci/drivers/%s/bind%c",
865 error = write_sys_fs ((char *)path, "%s", devname);
870 * unbind interface from the native kernel module
872 _vec_len (path) -= 5;
873 path = format (path, "unbind%c", 0);
874 error = write_sys_fs ((char *)path, "%s", devname);
880 * bind the interface to igb_uio
885 path = format (path, "/sys/bus/pci/drivers/%s/new_id%c", driver_name, 0);
886 error = write_sys_fs ((char *) path, "%s %s", pci_vid, pci_did);
891 path = format (path, "/sys/bus/pci/drivers/%s/bind%c", driver_name, 0);
892 error = write_sys_fs ((char *) path, "%s", devname);
913 get_node_free_hugepages_num (u32 node, u32 page_size)
918 tmp = format (0, "/sys/devices/system/node/node%u/hugepages/hugepages-%ukB/"
919 "free_hugepages%c", node, page_size, 0);
920 fp = fopen ((char *) tmp, "r");
928 vec_validate (buffer, 256-1);
929 if (fgets ((char *)buffer, 256, fp))
932 unformat_init_string (&in, (char *) buffer, strlen ((char *) buffer));
933 unformat(&in, "%u", &pages_avail);
944 static clib_error_t *
945 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
947 clib_error_t * error = 0;
948 dpdk_main_t * dm = &dpdk_main;
949 vlib_thread_main_t * tm = vlib_get_thread_main();
952 u8 * rte_cmd = 0, * ethname = 0;
958 int rxrings, txrings, rxslots, txslots, txburst;
961 unformat_input_t _in;
962 unformat_input_t * in = &_in;
970 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
971 dm->use_virtio_vhost = 1;
973 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
976 if (unformat (input, "no-hugetlb"))
978 vec_add1 (dm->eal_init_args, (u8 *) "no-huge");
982 else if (unformat (input, "enable-tcp-udp-checksum"))
984 dm->buffer_flags_template &=
985 ~(IP_BUFFER_L4_CHECKSUM_CORRECT | IP_BUFFER_L4_CHECKSUM_COMPUTED);
988 else if (unformat (input, "decimal-interface-names"))
989 dm->interface_name_format_decimal = 1;
991 else if (unformat (input, "no-multi-seg"))
992 dm->no_multi_seg = 1;
994 else if (unformat (input, "dev %s", &pci_dev_id))
996 if (dm->eth_if_whitelist)
999 * Don't add duplicate device id's.
1001 if (strstr ((char *)dm->eth_if_whitelist, (char *)pci_dev_id))
1004 _vec_len (dm->eth_if_whitelist) -= 1; // chomp trailing NULL.
1005 dm->eth_if_whitelist = format (dm->eth_if_whitelist, " %s%c",
1009 dm->eth_if_whitelist = format (0, "%s%c", pci_dev_id, 0);
1013 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
1014 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
1017 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
1019 error = clib_error_return (0, "%s", rv);
1022 }else if (unformat(input, "netmap %s", &nmname)) {
1025 eth_nm_args(nmname, 0, 0, 0, 0, 0);
1027 error = clib_error_return (0, "%s", rv);
1033 else if (unformat (input, "dump-physmem"))
1035 else if (unformat (input, "num-mbufs %d", &dm->num_mbufs))
1037 else if (unformat (input, "max-tx-queues %d", &dm->max_tx_queues))
1039 else if (unformat (input, "kni %d", &dm->num_kni))
1041 else if (unformat (input, "uio-driver %s", &dm->uio_driver_name))
1043 else if (unformat (input, "vhost-user-coalesce-frames %d", &dm->vhost_coalesce_frames))
1045 else if (unformat (input, "vhost-user-coalesce-time %f", &dm->vhost_coalesce_time))
1047 else if (unformat (input, "enable-vhost-user"))
1048 dm->use_virtio_vhost = 0;
1049 else if (unformat (input, "rss %d", &dm->use_rss))
1053 else if (unformat(input, #a)) \
1055 if (!strncmp(#a, "no-pci", 6)) \
1057 tmp = format (0, "--%s%c", #a, 0); \
1058 vec_add1 (dm->eal_init_args, tmp); \
1060 foreach_eal_double_hyphen_predicate_arg
1064 else if (unformat(input, #a " %s", &s)) \
1066 if (!strncmp(#a, "huge-dir", 8)) \
1068 else if (!strncmp(#a, "file-prefix", 11)) \
1070 else if (!strncmp(#a, "socket-mem", 10)) \
1071 socket_mem = vec_dup (s); \
1072 tmp = format (0, "--%s%c", #a, 0); \
1073 vec_add1 (dm->eal_init_args, tmp); \
1075 vec_add1 (dm->eal_init_args, s); \
1077 foreach_eal_double_hyphen_arg
1081 else if (unformat(input, #a " %s", &s)) \
1083 tmp = format (0, "-%s%c", #b, 0); \
1084 vec_add1 (dm->eal_init_args, tmp); \
1086 vec_add1 (dm->eal_init_args, s); \
1088 foreach_eal_single_hyphen_arg
1092 else if (unformat(input, #a " %s", &s)) \
1094 tmp = format (0, "-%s%c", #b, 0); \
1095 vec_add1 (dm->eal_init_args, tmp); \
1097 vec_add1 (dm->eal_init_args, s); \
1098 dm->a##_set_manually = 1; \
1100 foreach_eal_single_hyphen_mandatory_arg
1103 else if (unformat(input, "default"))
1108 error = clib_error_return (0, "unknown input `%U'",
1109 format_unformat_error, input);
1114 if (!dm->uio_driver_name)
1115 dm->uio_driver_name = format (0, "igb_uio");
1118 * Use 1G huge pages if available.
1120 if (!no_huge && !huge_dir)
1122 uword * mem_by_socket = hash_create (0, sizeof (uword));
1128 umount(DEFAULT_HUGE_DIR);
1130 /* Process "socket-mem" parameter value */
1131 if (vec_len (socket_mem))
1133 unformat_input_t in;
1134 unformat_init_vector(&in, socket_mem);
1135 unformat(&in, "%U", unformat_socket_mem, &mem_by_socket);
1141 /* check if available enough 1GB pages for each socket */
1142 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, ({
1143 uword * p = hash_get (mem_by_socket, c);
1149 u32 pages_num_1g = mem / 1024;
1150 u32 pages_num_2m = mem / 2;
1153 pages_avail = get_node_free_hugepages_num(c, 1048576);
1154 if (!(pages_avail >= pages_num_1g))
1157 pages_avail = get_node_free_hugepages_num(c, 2048);
1158 if (!(pages_avail >= pages_num_2m))
1164 hash_free (mem_by_socket);
1166 rv = mkdir(VPP_RUN_DIR, 0755);
1167 if (rv && errno != EEXIST)
1169 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1170 VPP_RUN_DIR, errno);
1174 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1175 if (rv && errno != EEXIST)
1177 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1178 DEFAULT_HUGE_DIR, errno);
1184 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1188 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1192 return clib_error_return (0, "not enough free huge pages");
1197 error = clib_error_return (0, "mount failed %d", errno);
1201 tmp = format (0, "--huge-dir%c", 0);
1202 vec_add1 (dm->eal_init_args, tmp);
1203 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1204 vec_add1 (dm->eal_init_args, tmp);
1207 tmp = format (0, "--file-prefix%c", 0);
1208 vec_add1 (dm->eal_init_args, tmp);
1209 tmp = format (0, "vpp%c", 0);
1210 vec_add1 (dm->eal_init_args, tmp);
1215 * Blacklist all ethernet interfaces in the linux IP routing tables.
1217 dm->eth_if_blacklist = format (0, "%c", 0);
1218 rte_cmd = format (0, "route --inet --inet6 -n|awk '{print $7}'|sort -u|"
1219 "egrep $(echo $(ls -1d /sys/class/net/*/device|"
1220 "cut -d/ -f5)|sed -s 's/ /|/g')%c", 0);
1221 if ((rte_fp = popen ((const char *)rte_cmd, "r")) == NULL)
1223 error = clib_error_return_unix (0, "Unable to find blacklist ethernet"
1224 " interface(s) in linux routing tables.");
1229 vec_validate (ethname, BUFSIZ);
1230 while (fgets ((char *)ethname, BUFSIZ, rte_fp) != NULL)
1233 u8 * rlnk_cmd = 0, * devname = 0;
1235 ethname[strlen ((char *)ethname) - 1] = 0; // chomp trailing newline.
1237 rlnk_cmd = format (0, "readlink /sys/class/net/%s%c",
1240 if ((rlnk_fp = popen ((const char *)rlnk_cmd, "r")) == NULL)
1242 error = clib_error_return_unix (0, "Unable to read %s link.",
1247 vec_validate (devname, BUFSIZ);
1248 while (fgets ((char *)devname, BUFSIZ, rlnk_fp) != NULL)
1253 * Extract the device PCI ID name from the link. It is the first
1254 * PCI ID searching backwards from the end of the link pathname.
1256 * readlink /sys/class/net/eth0
1257 * ../../devices/pci0000:00/0000:00:0a.0/virtio4/net/eth0
1259 for (pci_id = (char *)((devname + strlen((char *)devname)));
1260 ((u8 *)pci_id > devname) && *pci_id != '.'; pci_id--)
1264 * Verify that the field found is a valid PCI ID.
1266 if ((*(pci_id - 1) == '.') || ((u8 *)(pci_id - 11) < devname) ||
1267 (*(pci_id - 11) != '/') || (*(pci_id - 3) != ':') ||
1268 (*(pci_id - 6) != ':'))
1270 devname[strlen ((char *)devname) - 1] = 0; // chomp trailing newline.
1271 clib_warning ("Unable to extract %s PCI ID (0x%llx \"%s\") "
1272 "from 0x%llx \"%s\"", ethname, pci_id, pci_id,
1280 /* Don't blacklist any interfaces which have been whitelisted.
1282 if (dm->eth_if_whitelist &&
1283 strstr ((char *)dm->eth_if_whitelist, (char *)pci_id))
1286 _vec_len (dm->eth_if_blacklist) -= 1; // chomp trailing NULL.
1287 dm->eth_if_blacklist = format (dm->eth_if_blacklist, " %s%c",
1293 vec_free (rlnk_cmd);
1305 /* I'll bet that -c and -n must be the first and second args... */
1306 if (!dm->coremask_set_manually)
1308 vlib_thread_registration_t * tr;
1309 uword * coremask = 0;
1312 /* main thread core */
1313 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1315 for (i = 0; i < vec_len (tm->registrations); i++)
1317 tr = tm->registrations[i];
1318 coremask = clib_bitmap_or(coremask, tr->coremask);
1321 vec_insert (dm->eal_init_args, 2, 1);
1322 dm->eal_init_args[1] = (u8 *) "-c";
1323 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1324 dm->eal_init_args[2] = tmp;
1325 clib_bitmap_free(coremask);
1328 if (!dm->nchannels_set_manually)
1330 vec_insert (dm->eal_init_args, 2, 3);
1331 dm->eal_init_args[3] = (u8 *) "-n";
1332 tmp = format (0, "%d", dm->nchannels);
1333 dm->eal_init_args[4] = tmp;
1337 * If there are whitelisted devices,
1338 * add the whitelist option & device list to the dpdk arg list...
1340 if (dm->eth_if_whitelist)
1342 unformat_init_string (in, (char *)dm->eth_if_whitelist,
1343 vec_len(dm->eth_if_whitelist) - 1);
1348 * Otherwise add the blacklisted devices to the dpdk arg list.
1352 unformat_init_string (in, (char *)dm->eth_if_blacklist,
1353 vec_len(dm->eth_if_blacklist) - 1);
1357 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
1359 tmp = format (0, fmt, 0);
1360 vec_add1 (dm->eal_init_args, tmp);
1361 unformat (in, "%s", &pci_dev_id);
1362 vec_add1 (dm->eal_init_args, pci_dev_id);
1368 * Bind Virtio pci devices to the igb_uio kernel driver.
1370 error = dpdk_bind_eth_kernel_drivers (vm, "1af4:1000", VIRTIO_PCI_NAME);
1375 * Bind vmxnet3 pci devices to the igb_uio kernel driver.
1377 error = dpdk_bind_eth_kernel_drivers (vm, "15ad:07b0",
1378 (char *) dm->uio_driver_name);
1383 * Bind Intel ethernet pci devices to igb_uio kernel driver.
1385 error = dpdk_bind_eth_kernel_drivers (vm, "8086:",
1386 (char *) dm->uio_driver_name);
1388 * Bind Cisco VIC ethernet pci devices to igb_uio kernel driver.
1390 error = dpdk_bind_eth_kernel_drivers (vm, "1137:0043",
1391 (char *) dm->uio_driver_name);
1394 /* set master-lcore */
1395 tmp = format (0, "--master-lcore%c", 0);
1396 vec_add1 (dm->eal_init_args, tmp);
1397 tmp = format (0, "%u%c", tm->main_lcore, 0);
1398 vec_add1 (dm->eal_init_args, tmp);
1400 /* NULL terminate the "argv" vector, in case of stupidity */
1401 vec_add1 (dm->eal_init_args, 0);
1402 _vec_len(dm->eal_init_args) -= 1;
1404 /* Set up DPDK eal and packet mbuf pool early. */
1406 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1408 rte_set_log_level (log_level);
1412 /* make copy of args as rte_eal_init tends to mess up with arg array */
1413 for (i = 1; i < vec_len(dm->eal_init_args); i++)
1414 dm->eal_init_args_str = format(dm->eal_init_args_str, "%s ",
1415 dm->eal_init_args[i]);
1421 clib_warning ("DPDK eal init args:\n");
1422 for (ix=0; ix<vec_len(dm->eal_init_args); ix++) {
1423 clib_warning (" %s\n", dm->eal_init_args[ix]);
1427 ret = rte_eal_init(vec_len(dm->eal_init_args), (char **) dm->eal_init_args);
1429 /* lazy umount hugepages */
1430 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1433 return clib_error_return (0, "rte_eal_init returned %d", ret);
1435 /* Dump the physical memory layout prior to creating the mbuf_pool */
1437 fprintf(stdout, "DPDK physical memory layout:\n");
1438 rte_dump_physmem_layout(stdout);
1441 /* main thread 1st */
1442 error = vlib_buffer_pool_create(vm, dm->num_mbufs, MBUF_SIZE, rte_socket_id());
1446 for (i = 0; i < RTE_MAX_LCORE; i++)
1448 error = vlib_buffer_pool_create(vm, dm->num_mbufs, MBUF_SIZE,
1449 rte_lcore_to_socket_id(i));
1456 vlib_node_runtime_t * rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
1457 rt->function = dpdk_input_rss;
1463 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1465 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1467 vnet_main_t * vnm = vnet_get_main();
1468 struct rte_eth_link prev_link = xd->link;
1470 u8 hw_flags_chg = 0;
1472 /* only update link state for PMD interfaces */
1473 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1476 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1477 memset(&xd->link, 0, sizeof(xd->link));
1478 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1480 if (LINK_STATE_ELOGS)
1482 vlib_main_t * vm = vlib_get_main();
1483 ELOG_TYPE_DECLARE(e) = {
1485 "update-link-state: sw_if_index %d, admin_up %d,"
1486 "old link_state %d new link_state %d",
1487 .format_args = "i4i1i1i1",
1490 struct { u32 sw_if_index; u8 admin_up;
1491 u8 old_link_state; u8 new_link_state;} *ed;
1492 ed = ELOG_DATA (&vm->elog_main, e);
1493 ed->sw_if_index = xd->vlib_sw_if_index;
1494 ed->admin_up = xd->admin_up;
1495 ed->old_link_state = (u8)
1496 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1497 ed->new_link_state = (u8) xd->link.link_status;
1500 if ((xd->admin_up == 1) &&
1501 ((xd->link.link_status != 0) ^
1502 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1505 hw_flags |= (xd->link.link_status ?
1506 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1509 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1512 switch (xd->link.link_duplex)
1514 case ETH_LINK_HALF_DUPLEX:
1515 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1517 case ETH_LINK_FULL_DUPLEX:
1518 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1524 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1527 switch (xd->link.link_speed)
1529 case ETH_LINK_SPEED_10:
1530 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1532 case ETH_LINK_SPEED_100:
1533 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1535 case ETH_LINK_SPEED_1000:
1536 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1538 case ETH_LINK_SPEED_10000:
1539 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1541 case ETH_LINK_SPEED_40G:
1542 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1547 clib_warning("unknown link speed %d", xd->link.link_speed);
1553 if (LINK_STATE_ELOGS)
1555 vlib_main_t * vm = vlib_get_main();
1557 ELOG_TYPE_DECLARE(e) = {
1558 .format = "update-link-state: sw_if_index %d, new flags %d",
1559 .format_args = "i4i4",
1562 struct { u32 sw_if_index; u32 flags; } *ed;
1563 ed = ELOG_DATA (&vm->elog_main, e);
1564 ed->sw_if_index = xd->vlib_sw_if_index;
1565 ed->flags = hw_flags;
1567 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1572 dpdk_process (vlib_main_t * vm,
1573 vlib_node_runtime_t * rt,
1576 clib_error_t * error;
1577 vnet_main_t * vnm = vnet_get_main();
1578 dpdk_main_t * dm = &dpdk_main;
1579 ethernet_main_t * em = ðernet_main;
1581 vlib_thread_main_t * tm = vlib_get_thread_main();
1585 error = dpdk_lib_init (dm);
1588 * Turn on the input node if we found some devices to drive
1589 * and we're not running worker threads or i/o threads
1592 if (error == 0 && vec_len(dm->devices) > 0)
1594 if (tm->n_vlib_mains == 1)
1595 vlib_node_set_state (vm, dpdk_input_node.index,
1596 VLIB_NODE_STATE_POLLING);
1597 else if (tm->main_thread_is_io_node)
1598 vlib_node_set_state (vm, dpdk_io_input_node.index,
1599 VLIB_NODE_STATE_POLLING);
1600 else if (!dm->have_io_threads)
1601 for (i=0; i < tm->n_vlib_mains; i++)
1602 if (vec_len(dm->devices_by_cpu[i]) > 0)
1603 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1604 VLIB_NODE_STATE_POLLING);
1608 clib_error_report (error);
1610 dpdk_vhost_user_process_init(&vu_state);
1612 dm->io_thread_release = 1;
1614 f64 now = vlib_time_now (vm);
1615 vec_foreach (xd, dm->devices)
1617 dpdk_update_link_state (xd, now);
1620 { // Setup MACs for bond interfaces and their links which was initialized in
1621 // dpdk_port_setup() but needs to be done again here to take effect.
1622 int nports = rte_eth_dev_count();
1624 for (i = 0; i < nports; i++) {
1625 struct rte_eth_dev_info dev_info;
1626 rte_eth_dev_info_get(i, &dev_info);
1627 if (!dev_info.driver_name)
1628 dev_info.driver_name = dev_info.pci_dev->driver->name;
1629 ASSERT(dev_info.driver_name);
1630 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1633 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1635 vnet_hw_interface_t * hi;
1636 ethernet_interface_t * ei;
1637 /* Get MAC of 1st slave link */
1638 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1639 /* Set MAC of bounded interface to that of 1st slave link */
1640 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1641 /* Populate MAC of bonded interface in VPP hw tables */
1642 hi = vnet_get_hw_interface (
1643 vnm, dm->devices[i].vlib_hw_if_index);
1644 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
1645 memcpy (hi->hw_address, addr, 6);
1646 memcpy (ei->address, addr, 6);
1647 /* Add MAC to other slave links */
1650 rte_eth_dev_mac_addr_add(
1651 slink[nlink], (struct ether_addr *)addr, 0);
1661 vlib_process_wait_for_event_or_clock (vm, 5.0);
1663 if (dpdk_get_admin_up_down_in_progress())
1664 /* skip the poll if an admin up down is in progress (on any interface) */
1667 vec_foreach (xd, dm->devices)
1669 f64 now = vlib_time_now (vm);
1670 if ((now - xd->time_last_stats_update) >= DPDK_STATS_POLL_INTERVAL)
1671 dpdk_update_counters (xd, now);
1672 if ((now - xd->time_last_link_update) >= DPDK_LINK_POLL_INTERVAL)
1673 dpdk_update_link_state (xd, now);
1675 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1676 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1681 dpdk_vhost_user_process_cleanup(vu_state);
1686 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1687 .function = dpdk_process,
1688 .type = VLIB_NODE_TYPE_PROCESS,
1689 .name = "dpdk-process",
1690 .process_log2_n_stack_bytes = 17,
1694 dpdk_init (vlib_main_t * vm)
1696 dpdk_main_t * dm = &dpdk_main;
1698 clib_error_t * error = 0;
1699 vlib_thread_main_t * tm = vlib_get_thread_main();
1701 /* verify that structs are cacheline aligned */
1702 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1703 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1704 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1705 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1707 /* Add references to DPDK Driver Constructor functions to get the dynamic
1708 * loader to pull in the driver library & run the constructors.
1712 void devinitfn_ ##d(void); \
1713 __attribute__((unused)) void (* volatile pf)(void); \
1714 pf = devinitfn_ ##d; \
1717 #ifdef RTE_LIBRTE_EM_PMD
1721 #ifdef RTE_LIBRTE_IGB_PMD
1725 #ifdef RTE_LIBRTE_IXGBE_PMD
1729 #ifdef RTE_LIBRTE_I40E_PMD
1731 _(rte_i40evf_driver)
1734 #ifdef RTE_LIBRTE_FM10K_PMD
1738 #ifdef RTE_LIBRTE_VIRTIO_PMD
1739 _(rte_virtio_driver)
1742 #ifdef RTE_LIBRTE_VMXNET3_PMD
1743 _(rte_vmxnet3_driver)
1746 #ifdef RTE_LIBRTE_VICE_PMD
1750 #ifdef RTE_LIBRTE_ENIC_PMD
1754 #ifdef RTE_LIBRTE_PMD_AF_PACKET
1755 _(pmd_af_packet_drv)
1758 #ifdef RTE_LIBRTE_CXGBE_PMD
1762 #ifdef RTE_LIBRTE_PMD_BOND
1769 * At the moment, the ThunderX NIC driver doesn't have
1770 * an entry point named "devinitfn_rte_xxx_driver"
1775 __attribute__((unused)) void (* volatile pf)(void); \
1779 #ifdef RTE_LIBRTE_THUNDERVNIC_PMD
1780 _(rte_nicvf_pmd_init)
1785 dm->vnet_main = vnet_get_main();
1787 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1789 return clib_error_return (0, "ethernet-input node AWOL");
1791 dm->ethernet_input_node_index = ei->index;
1794 dm->num_mbufs = dm->num_mbufs ? dm->num_mbufs : NB_MBUF;
1795 vec_add1 (dm->eal_init_args, (u8 *) "vnet");
1797 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1798 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1799 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1801 /* $$$ use n_thread_stacks since it's known-good at this point */
1802 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1804 /* initialize EFD (early fast discard) default settings */
1805 dm->efd.enabled = DPDK_EFD_DISABLED;
1806 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1807 DPDK_NB_RX_DESC_10GE)/100);
1808 dm->efd.consec_full_frames_hi_thresh =
1809 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1811 /* vhost-user coalescence frames defaults */
1812 dm->vhost_coalesce_frames = 32;
1813 dm->vhost_coalesce_time = 1e-3;
1815 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1816 dm->buffer_flags_template =
1817 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1818 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1819 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1822 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1828 VLIB_INIT_FUNCTION (dpdk_init);