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/bitmap.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/devices/dpdk/dpdk.h>
23 #include <vlib/unix/physmem.h>
24 #include <vlib/pci/pci.h>
30 #include <sys/mount.h>
34 #include "dpdk_priv.h"
36 dpdk_main_t dpdk_main;
38 /* force linker to link functions used by vlib and declared weak */
39 void *vlib_weakly_linked_functions[] = {
41 &rte_pktmbuf_pool_init,
44 #define LINK_STATE_ELOGS 0
46 #define DEFAULT_HUGE_DIR "/run/vpp/hugepages"
47 #define VPP_RUN_DIR "/run/vpp"
49 /* Port configuration, mildly modified Intel app values */
51 static struct rte_eth_conf port_conf_template = {
54 .header_split = 0, /**< Header Split disabled */
55 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
56 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
57 .hw_strip_crc = 1, /**< CRC stripped by hardware */
60 .mq_mode = ETH_MQ_TX_NONE,
65 dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd)
67 vlib_main_t * vm = vlib_get_main();
68 vlib_buffer_main_t * bm = vm->buffer_main;
72 ASSERT(os_get_cpu_number() == 0);
75 vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0);
76 rte_eth_dev_stop (xd->device_index);
79 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
80 xd->tx_q_used, &xd->port_conf);
83 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
84 xd->device_index, rv);
86 /* Set up one TX-queue per worker thread */
87 for (j = 0; j < xd->tx_q_used; j++)
89 rv = rte_eth_tx_queue_setup(xd->device_index, j, xd->nb_tx_desc,
90 xd->cpu_socket, &xd->tx_conf);
92 /* retry with any other CPU socket */
94 rv = rte_eth_tx_queue_setup(xd->device_index, j, xd->nb_tx_desc,
95 SOCKET_ID_ANY, &xd->tx_conf);
101 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
102 xd->device_index, rv);
104 for (j = 0; j < xd->rx_q_used; j++)
107 rv = rte_eth_rx_queue_setup(xd->device_index, j, xd->nb_rx_desc,
109 bm->pktmbuf_pools[xd->cpu_socket_id_by_queue[j]]);
111 /* retry with any other CPU socket */
113 rv = rte_eth_rx_queue_setup(xd->device_index, j, xd->nb_rx_desc,
115 bm->pktmbuf_pools[xd->cpu_socket_id_by_queue[j]]);
117 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
118 xd->device_index, rv);
122 rte_eth_dev_start (xd->device_index);
127 static u32 dpdk_flag_change (vnet_main_t * vnm,
128 vnet_hw_interface_t * hi,
131 dpdk_main_t * dm = &dpdk_main;
132 dpdk_device_t * xd = vec_elt_at_index (dm->devices, hi->dev_instance);
135 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC(flags))
138 xd->promisc = flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
143 rte_eth_promiscuous_enable(xd->device_index);
145 rte_eth_promiscuous_disable(xd->device_index);
148 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU(flags))
151 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
152 * driver to dynamically change the mtu. If/when the
153 * VIC firmware gets fixed, then this should be removed.
155 if (xd->pmd == VNET_DPDK_PMD_VICE ||
156 xd->pmd == VNET_DPDK_PMD_ENIC)
158 struct rte_eth_dev_info dev_info;
161 * Restore mtu to what has been set by CIMC in the firmware cfg.
163 rte_eth_dev_info_get(xd->device_index, &dev_info);
164 hi->max_packet_bytes = dev_info.max_rx_pktlen;
166 vlib_cli_output (vlib_get_main(),
167 "Cisco VIC mtu can only be changed "
168 "using CIMC then rebooting the server!");
174 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
177 rte_eth_dev_stop (xd->device_index);
179 rv = rte_eth_dev_configure
186 vlib_cli_output (vlib_get_main(),
187 "rte_eth_dev_configure[%d]: err %d",
188 xd->device_index, rv);
190 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
193 rte_eth_dev_start (xd->device_index);
200 extern int rte_netmap_probe(void);
204 dpdk_device_lock_init(dpdk_device_t * xd)
207 vec_validate(xd->lockp, xd->tx_q_used - 1);
208 for (q = 0; q < xd->tx_q_used; q++)
210 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
211 CLIB_CACHE_LINE_BYTES);
212 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
218 dpdk_device_lock_free(dpdk_device_t * xd)
222 for (q = 0; q < vec_len(xd->lockp); q++)
223 clib_mem_free((void *) xd->lockp[q]);
229 static clib_error_t *
230 dpdk_lib_init (dpdk_main_t * dm)
235 clib_error_t * error;
236 vlib_main_t * vm = vlib_get_main();
237 vlib_thread_main_t * tm = vlib_get_thread_main();
238 vnet_sw_interface_t * sw;
239 vnet_hw_interface_t * hi;
241 vlib_thread_registration_t * tr;
245 u8 af_packet_port_id = 0;
247 dm->input_cpu_first_index = 0;
248 dm->input_cpu_count = 1;
250 /* find out which cpus will be used for input */
251 p = hash_get_mem (tm->thread_registrations_by_name, "io");
252 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
254 if (!tr || tr->count == 0)
256 /* no io threads, workers doing input */
257 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
258 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
262 dm->have_io_threads = 1;
265 if (tr && tr->count > 0)
267 dm->input_cpu_first_index = tr->first_index;
268 dm->input_cpu_count = tr->count;
271 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
272 CLIB_CACHE_LINE_BYTES);
274 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
275 CLIB_CACHE_LINE_BYTES);
278 if(rte_netmap_probe() < 0)
279 return clib_error_return (0, "rte netmap probe failed");
282 nports = rte_eth_dev_count();
285 clib_warning ("DPDK drivers found no ports...");
289 clib_warning ("DPDK drivers found %d ports...", nports);
292 * All buffers are all allocated from the same rte_mempool.
293 * Thus they all have the same number of data bytes.
295 dm->vlib_buffer_free_list_index =
296 vlib_buffer_get_or_create_free_list (
297 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
299 if (dm->conf->enable_tcp_udp_checksum)
300 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
301 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
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 clib_memcpy(&xd->tx_conf, &dev_info.default_txconf,
319 sizeof(struct rte_eth_txconf));
320 if (dm->conf->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 clib_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->conf->max_tx_queues)
336 xd->tx_q_used = clib_min(xd->tx_q_used, dm->conf->max_tx_queues);
338 if (dm->conf->use_rss > 1 && dev_info.max_rx_queues >= dm->conf->use_rss)
340 xd->rx_q_used = dm->conf->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 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
495 * This device does not support the platforms's max frame
496 * size. Use it's advertised mru instead.
498 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
502 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
505 * Some platforms do not account for Ethernet FCS (4 bytes) in
506 * MTU calculations. To interop with them increase mru but only
507 * if the device's settings can support it.
509 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
510 xd->port_conf.rxmode.hw_strip_crc)
513 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
514 * stripped by h/w and so will not consume any buffer memory.
516 xd->port_conf.rxmode.max_rx_pkt_len += 4;
520 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
522 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
524 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
526 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
527 xd->port_conf.rxmode.jumbo_frame = 0;
531 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
533 f64 now = vlib_time_now(vm);
535 rnd = (u32) (now * 1e6);
536 rnd = random_u32 (&rnd);
537 clib_memcpy (addr+2, &rnd, sizeof(rnd));
542 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
544 if (xd->tx_q_used < tm->n_vlib_mains)
545 dpdk_device_lock_init(xd);
547 xd->device_index = xd - dm->devices;
548 ASSERT(i == xd->device_index);
549 xd->per_interface_next_index = ~0;
551 /* assign interface to input thread */
552 dpdk_device_and_queue_t * dq;
555 for (q = 0; q < xd->rx_q_used; q++)
557 int cpu = dm->input_cpu_first_index + next_cpu;
558 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
561 * numa node for worker thread handling this queue
562 * needed for taking buffers from the right mempool
564 vec_validate(xd->cpu_socket_id_by_queue, q);
565 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
568 * construct vector of (device,queue) pairs for each worker thread
570 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
571 dq->device = xd->device_index;
575 if (next_cpu == dm->input_cpu_count)
579 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
580 CLIB_CACHE_LINE_BYTES);
581 for (j = 0; j < tm->n_vlib_mains; j++)
583 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
584 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
585 vec_reset_length (xd->tx_vectors[j]);
588 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
589 CLIB_CACHE_LINE_BYTES);
590 for (j = 0; j< xd->rx_q_used; j++)
592 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
593 CLIB_CACHE_LINE_BYTES);
594 vec_reset_length (xd->rx_vectors[j]);
597 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
598 CLIB_CACHE_LINE_BYTES);
600 rv = dpdk_port_setup(dm, xd);
605 /* count the number of descriptors used for this device */
606 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
608 error = ethernet_register_interface
610 dpdk_device_class.index,
612 /* ethernet address */ addr,
613 &xd->vlib_hw_if_index,
618 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
619 xd->vlib_sw_if_index = sw->sw_if_index;
620 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
623 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
624 * driver to dynamically change the mtu. If/when the
625 * VIC firmware gets fixed, then this should be removed.
627 if (xd->pmd == VNET_DPDK_PMD_VICE ||
628 xd->pmd == VNET_DPDK_PMD_ENIC)
631 * Initialize mtu to what has been set by CIMC in the firmware cfg.
633 hi->max_packet_bytes = dev_info.max_rx_pktlen;
635 * remove vlan tag from VIC port to fix VLAN0 issue.
636 * TODO Handle VLAN tagged traffic
639 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
640 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
641 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
644 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
646 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
648 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
649 hi->max_packet_bytes = 1518;
652 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
653 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
655 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
658 #ifdef RTE_LIBRTE_KNI
659 if (dm->conf->num_kni) {
660 clib_warning("Initializing KNI interfaces...");
661 rte_kni_init(dm->conf->num_kni);
662 for (i = 0; i < dm->conf->num_kni; i++)
667 /* Create vnet interface */
668 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
669 xd->dev_type = VNET_DPDK_DEV_KNI;
671 xd->device_index = xd - dm->devices;
672 ASSERT(nports + i == xd->device_index);
673 xd->per_interface_next_index = ~0;
676 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
679 /* assign interface to input thread */
680 dpdk_device_and_queue_t * dq;
681 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
682 dq->device = xd->device_index;
685 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
686 CLIB_CACHE_LINE_BYTES);
687 for (j = 0; j < tm->n_vlib_mains; j++)
689 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
690 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
691 vec_reset_length (xd->tx_vectors[j]);
694 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
695 CLIB_CACHE_LINE_BYTES);
696 for (j = 0; j< xd->rx_q_used; j++)
698 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
699 CLIB_CACHE_LINE_BYTES);
700 vec_reset_length (xd->rx_vectors[j]);
703 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
704 CLIB_CACHE_LINE_BYTES);
706 /* FIXME Set up one TX-queue per worker thread */
709 f64 now = vlib_time_now(vm);
711 rnd = (u32) (now * 1e6);
712 rnd = random_u32 (&rnd);
714 clib_memcpy (addr+2, &rnd, sizeof(rnd));
719 error = ethernet_register_interface
721 dpdk_device_class.index,
723 /* ethernet address */ addr,
724 &xd->vlib_hw_if_index,
730 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
731 xd->vlib_sw_if_index = sw->sw_if_index;
732 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
737 if (nb_desc > dm->conf->num_mbufs)
738 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
739 dm->conf->num_mbufs, nb_desc);
741 /* init next vhost-user if index */
742 dm->next_vu_if_id = 0;
748 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
750 vlib_pci_main_t * pm = &pci_main;
751 clib_error_t * error;
752 vlib_pci_device_t * d;
753 pci_config_header_t * c;
756 pool_foreach (d, pm->pci_devs, ({
757 c = &d->config0.header;
758 vec_reset_length (pci_addr);
759 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
761 if (c->device_class != PCI_CLASS_NETWORK_ETHERNET)
764 /* if whitelist exists process only whitelisted devices */
765 if (conf->eth_if_whitelist &&
766 !strstr ((char *) conf->eth_if_whitelist, (char *) pci_addr))
770 if (c->vendor_id == 0x1af4 && c->device_id == 0x1000)
773 else if (c->vendor_id == 0x15ad && c->device_id == 0x07b0)
775 /* all Intel devices */
776 else if (c->vendor_id == 0x8086)
779 else if (c->vendor_id == 0x1137 && c->device_id == 0x0043)
782 else if (c->vendor_id == 0x1425 && (c->device_id & 0xe000) == 0x4000)
786 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
787 "at PCI address %s\n", (u16) c->vendor_id, (u16) c->device_id,
792 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
796 if (!conf->eth_if_whitelist)
797 conf->eth_if_blacklist = format (conf->eth_if_blacklist, "%U ",
798 format_vlib_pci_addr, &d->bus_address);
799 clib_error_report (error);
805 static clib_error_t *
806 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
808 clib_error_t * error = 0;
809 dpdk_config_main_t * conf = &dpdk_config_main;
810 vlib_thread_main_t * tm = vlib_get_thread_main();
811 vlib_node_runtime_t * rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
814 u8 * rte_cmd = 0, * ethname = 0;
819 int rxrings, txrings, rxslots, txslots, txburst;
822 unformat_input_t _in;
823 unformat_input_t * in = &_in;
830 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
831 conf->use_virtio_vhost = 1;
833 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
836 if (unformat (input, "no-hugetlb"))
838 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
842 else if (unformat (input, "enable-tcp-udp-checksum"))
843 conf->enable_tcp_udp_checksum = 1;
845 else if (unformat (input, "decimal-interface-names"))
846 conf->interface_name_format_decimal = 1;
848 else if (unformat (input, "no-multi-seg"))
849 conf->no_multi_seg = 1;
851 else if (unformat (input, "dev %s", &pci_dev_id))
853 if (conf->eth_if_whitelist)
856 * Don't add duplicate device id's.
858 if (strstr ((char *)conf->eth_if_whitelist, (char *)pci_dev_id))
861 _vec_len (conf->eth_if_whitelist) -= 1; // chomp trailing NULL.
862 conf->eth_if_whitelist = format (conf->eth_if_whitelist, " %s%c",
866 conf->eth_if_whitelist = format (0, "%s%c", pci_dev_id, 0);
870 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
871 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
874 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
876 error = clib_error_return (0, "%s", rv);
879 }else if (unformat(input, "netmap %s", &nmname)) {
882 eth_nm_args(nmname, 0, 0, 0, 0, 0);
884 error = clib_error_return (0, "%s", rv);
890 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
892 else if (unformat (input, "max-tx-queues %d", &conf->max_tx_queues))
894 else if (unformat (input, "kni %d", &conf->num_kni))
896 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
898 else if (unformat (input, "socket-mem %s", &socket_mem))
900 else if (unformat (input, "vhost-user-coalesce-frames %d", &conf->vhost_coalesce_frames))
902 else if (unformat (input, "vhost-user-coalesce-time %f", &conf->vhost_coalesce_time))
904 else if (unformat (input, "enable-vhost-user"))
905 conf->use_virtio_vhost = 0;
906 else if (unformat (input, "rss %d", &conf->use_rss))
910 else if (unformat(input, #a)) \
912 if (!strncmp(#a, "no-pci", 6)) \
914 tmp = format (0, "--%s%c", #a, 0); \
915 vec_add1 (conf->eal_init_args, tmp); \
917 foreach_eal_double_hyphen_predicate_arg
921 else if (unformat(input, #a " %s", &s)) \
923 if (!strncmp(#a, "huge-dir", 8)) \
925 else if (!strncmp(#a, "file-prefix", 11)) \
927 tmp = format (0, "--%s%c", #a, 0); \
928 vec_add1 (conf->eal_init_args, tmp); \
930 vec_add1 (conf->eal_init_args, s); \
932 foreach_eal_double_hyphen_arg
936 else if (unformat(input, #a " %s", &s)) \
938 tmp = format (0, "-%s%c", #b, 0); \
939 vec_add1 (conf->eal_init_args, tmp); \
941 vec_add1 (conf->eal_init_args, s); \
943 foreach_eal_single_hyphen_arg
947 else if (unformat(input, #a " %s", &s)) \
949 tmp = format (0, "-%s%c", #b, 0); \
950 vec_add1 (conf->eal_init_args, tmp); \
952 vec_add1 (conf->eal_init_args, s); \
953 conf->a##_set_manually = 1; \
955 foreach_eal_single_hyphen_mandatory_arg
958 else if (unformat(input, "default"))
963 error = clib_error_return (0, "unknown input `%U'",
964 format_unformat_error, input);
969 if (!conf->uio_driver_name)
970 conf->uio_driver_name = format (0, "igb_uio%c", 0);
973 * Use 1G huge pages if available.
975 if (!no_huge && !huge_dir)
977 u32 x, * mem_by_socket = 0;
984 umount(DEFAULT_HUGE_DIR);
986 /* Process "socket-mem" parameter value */
987 if (vec_len (socket_mem))
990 unformat_init_vector(&in, socket_mem);
991 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
993 if (unformat (&in, "%u,", &x))
995 else if (unformat (&in, "%u", &x))
997 else if (unformat (&in, ","))
1002 vec_add1(mem_by_socket, x);
1007 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1013 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1015 vec_validate(mem_by_socket, c);
1016 mem_by_socket[c] = 512; /* default per-socket mem */
1021 /* check if available enough 1GB pages for each socket */
1022 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1024 u32 pages_avail, page_size, mem;
1027 char * numa_path = "/sys/devices/system/node/node%u/";
1028 char * nonnuma_path = "/sys/kernel/mm/";
1029 char * suffix = "hugepages/hugepages-%ukB/free_hugepages%c";
1031 struct stat sb_numa, sb_nonnuma;
1033 p = format(p, numa_path, c);
1034 stat(numa_path, &sb_numa);
1035 stat(nonnuma_path, &sb_nonnuma);
1037 if (S_ISDIR(sb_numa.st_mode)) {
1038 path = (char*)format((u8*)path, "%s%s", p, suffix);
1039 } else if (S_ISDIR(sb_nonnuma.st_mode)) {
1040 path = (char*)format((u8*)path, "%s%s", nonnuma_path, suffix);
1048 vec_validate(mem_by_socket, c);
1049 mem = mem_by_socket[c];
1053 s = format (s, path, page_size * 1024, 0);
1054 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1055 vec_reset_length (s);
1057 if (page_size * pages_avail < mem)
1062 s = format (s, path, page_size * 1024, 0);
1063 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1064 vec_reset_length (s);
1066 if (page_size * pages_avail < mem)
1073 _vec_len (mem_by_socket) = c + 1;
1075 /* regenerate socket_mem string */
1076 vec_foreach_index (x, mem_by_socket)
1077 socket_mem = format (socket_mem, "%s%u",
1078 socket_mem ? "," : "",
1080 socket_mem = format (socket_mem, "%c", 0);
1082 vec_free (mem_by_socket);
1084 rv = mkdir(VPP_RUN_DIR, 0755);
1085 if (rv && errno != EEXIST)
1087 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1088 VPP_RUN_DIR, errno);
1092 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1093 if (rv && errno != EEXIST)
1095 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1096 DEFAULT_HUGE_DIR, errno);
1100 if (use_1g && !(less_than_1g && use_2m))
1102 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1106 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1110 return clib_error_return (0, "not enough free huge pages");
1115 error = clib_error_return (0, "mount failed %d", errno);
1119 tmp = format (0, "--huge-dir%c", 0);
1120 vec_add1 (conf->eal_init_args, tmp);
1121 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1122 vec_add1 (conf->eal_init_args, tmp);
1125 tmp = format (0, "--file-prefix%c", 0);
1126 vec_add1 (conf->eal_init_args, tmp);
1127 tmp = format (0, "vpp%c", 0);
1128 vec_add1 (conf->eal_init_args, tmp);
1138 /* I'll bet that -c and -n must be the first and second args... */
1139 if (!conf->coremask_set_manually)
1141 vlib_thread_registration_t * tr;
1142 uword * coremask = 0;
1145 /* main thread core */
1146 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1148 for (i = 0; i < vec_len (tm->registrations); i++)
1150 tr = tm->registrations[i];
1151 coremask = clib_bitmap_or(coremask, tr->coremask);
1154 vec_insert (conf->eal_init_args, 2, 1);
1155 conf->eal_init_args[1] = (u8 *) "-c";
1156 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1157 conf->eal_init_args[2] = tmp;
1158 clib_bitmap_free(coremask);
1161 if (!conf->nchannels_set_manually)
1163 vec_insert (conf->eal_init_args, 2, 3);
1164 conf->eal_init_args[3] = (u8 *) "-n";
1165 tmp = format (0, "%d", conf->nchannels);
1166 conf->eal_init_args[4] = tmp;
1169 if (no_pci == 0 && geteuid() == 0)
1170 dpdk_bind_devices_to_uio(conf);
1173 * If there are whitelisted devices,
1174 * add the whitelist option & device list to the dpdk arg list...
1176 if (conf->eth_if_whitelist)
1178 unformat_init_string (in, (char *) conf->eth_if_whitelist,
1179 vec_len (conf->eth_if_whitelist) - 1);
1184 * Otherwise add the blacklisted devices to the dpdk arg list.
1188 unformat_init_string (in, (char *)conf->eth_if_blacklist,
1189 vec_len(conf->eth_if_blacklist) - 1);
1193 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
1195 tmp = format (0, fmt, 0);
1196 vec_add1 (conf->eal_init_args, tmp);
1197 unformat (in, "%s", &pci_dev_id);
1198 vec_add1 (conf->eal_init_args, pci_dev_id);
1201 /* set master-lcore */
1202 tmp = format (0, "--master-lcore%c", 0);
1203 vec_add1 (conf->eal_init_args, tmp);
1204 tmp = format (0, "%u%c", tm->main_lcore, 0);
1205 vec_add1 (conf->eal_init_args, tmp);
1207 /* set socket-mem */
1208 tmp = format (0, "--socket-mem%c", 0);
1209 vec_add1 (conf->eal_init_args, tmp);
1210 tmp = format (0, "%s%c", socket_mem, 0);
1211 vec_add1 (conf->eal_init_args, tmp);
1213 /* NULL terminate the "argv" vector, in case of stupidity */
1214 vec_add1 (conf->eal_init_args, 0);
1215 _vec_len(conf->eal_init_args) -= 1;
1217 /* Set up DPDK eal and packet mbuf pool early. */
1219 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1221 rte_set_log_level (log_level);
1223 vm = vlib_get_main ();
1225 /* make copy of args as rte_eal_init tends to mess up with arg array */
1226 for (i = 1; i < vec_len(conf->eal_init_args); i++)
1227 conf->eal_init_args_str = format(conf->eal_init_args_str, "%s ",
1228 conf->eal_init_args[i]);
1230 ret = rte_eal_init(vec_len(conf->eal_init_args), (char **) conf->eal_init_args);
1232 /* lazy umount hugepages */
1233 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1236 return clib_error_return (0, "rte_eal_init returned %d", ret);
1238 /* Dump the physical memory layout prior to creating the mbuf_pool */
1239 fprintf(stdout, "DPDK physical memory layout:\n");
1240 rte_dump_physmem_layout(stdout);
1242 /* main thread 1st */
1243 error = vlib_buffer_pool_create(vm, conf->num_mbufs, rte_socket_id());
1247 for (i = 0; i < RTE_MAX_LCORE; i++)
1249 error = vlib_buffer_pool_create(vm, conf->num_mbufs,
1250 rte_lcore_to_socket_id(i));
1256 rt->function = dpdk_input_rss_multiarch_select();
1258 rt->function = dpdk_input_multiarch_select();
1263 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1265 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1267 vnet_main_t * vnm = vnet_get_main();
1268 struct rte_eth_link prev_link = xd->link;
1270 u8 hw_flags_chg = 0;
1272 /* only update link state for PMD interfaces */
1273 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1276 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1277 memset(&xd->link, 0, sizeof(xd->link));
1278 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1280 if (LINK_STATE_ELOGS)
1282 vlib_main_t * vm = vlib_get_main();
1283 ELOG_TYPE_DECLARE(e) = {
1285 "update-link-state: sw_if_index %d, admin_up %d,"
1286 "old link_state %d new link_state %d",
1287 .format_args = "i4i1i1i1",
1290 struct { u32 sw_if_index; u8 admin_up;
1291 u8 old_link_state; u8 new_link_state;} *ed;
1292 ed = ELOG_DATA (&vm->elog_main, e);
1293 ed->sw_if_index = xd->vlib_sw_if_index;
1294 ed->admin_up = xd->admin_up;
1295 ed->old_link_state = (u8)
1296 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1297 ed->new_link_state = (u8) xd->link.link_status;
1300 if ((xd->admin_up == 1) &&
1301 ((xd->link.link_status != 0) ^
1302 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1305 hw_flags |= (xd->link.link_status ?
1306 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1309 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1312 switch (xd->link.link_duplex)
1314 case ETH_LINK_HALF_DUPLEX:
1315 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1317 case ETH_LINK_FULL_DUPLEX:
1318 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1324 #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
1325 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1328 switch (xd->link.link_speed)
1330 case ETH_SPEED_NUM_10M:
1331 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1333 case ETH_SPEED_NUM_100M:
1334 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1336 case ETH_SPEED_NUM_1G:
1337 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1339 case ETH_SPEED_NUM_10G:
1340 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1342 case ETH_SPEED_NUM_40G:
1343 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1348 clib_warning("unknown link speed %d", xd->link.link_speed);
1353 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1356 switch (xd->link.link_speed)
1358 case ETH_LINK_SPEED_10:
1359 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1361 case ETH_LINK_SPEED_100:
1362 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1364 case ETH_LINK_SPEED_1000:
1365 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1367 case ETH_LINK_SPEED_10000:
1368 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1370 case ETH_LINK_SPEED_40G:
1371 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1376 clib_warning("unknown link speed %d", xd->link.link_speed);
1383 if (LINK_STATE_ELOGS)
1385 vlib_main_t * vm = vlib_get_main();
1387 ELOG_TYPE_DECLARE(e) = {
1388 .format = "update-link-state: sw_if_index %d, new flags %d",
1389 .format_args = "i4i4",
1392 struct { u32 sw_if_index; u32 flags; } *ed;
1393 ed = ELOG_DATA (&vm->elog_main, e);
1394 ed->sw_if_index = xd->vlib_sw_if_index;
1395 ed->flags = hw_flags;
1397 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1402 dpdk_process (vlib_main_t * vm,
1403 vlib_node_runtime_t * rt,
1406 clib_error_t * error;
1407 vnet_main_t * vnm = vnet_get_main();
1408 dpdk_main_t * dm = &dpdk_main;
1409 ethernet_main_t * em = ðernet_main;
1411 vlib_thread_main_t * tm = vlib_get_thread_main();
1415 error = dpdk_lib_init (dm);
1418 * Turn on the input node if we found some devices to drive
1419 * and we're not running worker threads or i/o threads
1422 if (error == 0 && vec_len(dm->devices) > 0)
1424 if (tm->n_vlib_mains == 1)
1425 vlib_node_set_state (vm, dpdk_input_node.index,
1426 VLIB_NODE_STATE_POLLING);
1427 else if (tm->main_thread_is_io_node)
1428 vlib_node_set_state (vm, dpdk_io_input_node.index,
1429 VLIB_NODE_STATE_POLLING);
1430 else if (!dm->have_io_threads)
1431 for (i=0; i < tm->n_vlib_mains; i++)
1432 if (vec_len(dm->devices_by_cpu[i]) > 0)
1433 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1434 VLIB_NODE_STATE_POLLING);
1438 clib_error_report (error);
1440 dpdk_vhost_user_process_init(&vu_state);
1442 dm->io_thread_release = 1;
1444 f64 now = vlib_time_now (vm);
1445 vec_foreach (xd, dm->devices)
1447 dpdk_update_link_state (xd, now);
1450 { // Extra set up for bond interfaces:
1451 // 1. Setup MACs for bond interfaces and their slave links which was set
1452 // in dpdk_port_setup() but needs to be done again here to take effect.
1453 // 2. Set max L3 packet size of each bond interface to the lowerst value of
1455 // 3. Set up info for bond interface related CLI support.
1456 int nports = rte_eth_dev_count();
1458 for (i = 0; i < nports; i++) {
1459 struct rte_eth_dev_info dev_info;
1460 rte_eth_dev_info_get(i, &dev_info);
1461 if (!dev_info.driver_name)
1462 dev_info.driver_name = dev_info.pci_dev->driver->name;
1463 ASSERT(dev_info.driver_name);
1464 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1467 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1469 vnet_hw_interface_t * bhi;
1470 ethernet_interface_t * bei;
1471 /* Get MAC of 1st slave link */
1472 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1473 /* Set MAC of bounded interface to that of 1st slave link */
1474 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1475 /* Populate MAC of bonded interface in VPP hw tables */
1476 bhi = vnet_get_hw_interface(
1477 vnm, dm->devices[i].vlib_hw_if_index);
1478 bei = pool_elt_at_index(em->interfaces, bhi->hw_instance);
1479 clib_memcpy(bhi->hw_address, addr, 6);
1480 clib_memcpy(bei->address, addr, 6);
1481 /* Init l3 packet size allowed on bonded interface */
1482 bhi->max_l3_packet_bytes[VLIB_RX] =
1483 bhi->max_l3_packet_bytes[VLIB_TX] =
1484 ETHERNET_MAX_PACKET_BYTES - sizeof(ethernet_header_t);
1485 while (nlink >= 1) { /* for all slave links */
1486 int slave = slink[--nlink];
1487 dpdk_device_t * sdev = &dm->devices[slave];
1488 vnet_hw_interface_t * shi;
1489 vnet_sw_interface_t * ssi;
1490 /* Add MAC to all slave links except the first one */
1491 if (nlink) rte_eth_dev_mac_addr_add(
1492 slave, (struct ether_addr *)addr, 0);
1493 /* Set slaves bitmap for bonded interface */
1494 bhi->bond_info = clib_bitmap_set(
1495 bhi->bond_info, sdev->vlib_hw_if_index, 1);
1496 /* Set slave link flags on slave interface */
1497 shi = vnet_get_hw_interface(vnm, sdev->vlib_hw_if_index);
1498 ssi = vnet_get_sw_interface(vnm, sdev->vlib_sw_if_index);
1499 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1500 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1501 /* Set l3 packet size allowed as the lowest of slave */
1502 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1503 shi->max_l3_packet_bytes[VLIB_RX])
1504 bhi->max_l3_packet_bytes[VLIB_RX] =
1505 bhi->max_l3_packet_bytes[VLIB_TX] =
1506 shi->max_l3_packet_bytes[VLIB_RX];
1517 * check each time through the loop in case intervals are changed
1519 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1520 dm->link_state_poll_interval : dm->stat_poll_interval;
1522 vlib_process_wait_for_event_or_clock (vm, min_wait);
1524 if (dpdk_get_admin_up_down_in_progress())
1525 /* skip the poll if an admin up down is in progress (on any interface) */
1528 vec_foreach (xd, dm->devices)
1530 f64 now = vlib_time_now (vm);
1531 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1532 dpdk_update_counters (xd, now);
1533 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1534 dpdk_update_link_state (xd, now);
1536 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1537 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1542 dpdk_vhost_user_process_cleanup(vu_state);
1547 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1548 .function = dpdk_process,
1549 .type = VLIB_NODE_TYPE_PROCESS,
1550 .name = "dpdk-process",
1551 .process_log2_n_stack_bytes = 17,
1554 int dpdk_set_stat_poll_interval (f64 interval)
1556 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1557 return (VNET_API_ERROR_INVALID_VALUE);
1559 dpdk_main.stat_poll_interval = interval;
1564 int dpdk_set_link_state_poll_interval (f64 interval)
1566 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1567 return (VNET_API_ERROR_INVALID_VALUE);
1569 dpdk_main.link_state_poll_interval = interval;
1575 dpdk_init (vlib_main_t * vm)
1577 dpdk_main_t * dm = &dpdk_main;
1579 clib_error_t * error = 0;
1580 vlib_thread_main_t * tm = vlib_get_thread_main();
1582 /* verify that structs are cacheline aligned */
1583 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1584 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1585 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1586 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1589 dm->vnet_main = vnet_get_main();
1590 dm->conf = &dpdk_config_main;
1592 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1594 return clib_error_return (0, "ethernet-input node AWOL");
1596 dm->ethernet_input_node_index = ei->index;
1598 dm->conf->nchannels = 4;
1599 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1600 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1602 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1603 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1604 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1606 /* $$$ use n_thread_stacks since it's known-good at this point */
1607 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1609 /* initialize EFD (early fast discard) default settings */
1610 dm->efd.enabled = DPDK_EFD_DISABLED;
1611 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1612 DPDK_NB_RX_DESC_10GE)/100);
1613 dm->efd.consec_full_frames_hi_thresh =
1614 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1616 /* vhost-user coalescence frames defaults */
1617 dm->conf->vhost_coalesce_frames = 32;
1618 dm->conf->vhost_coalesce_time = 1e-3;
1620 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1621 dm->buffer_flags_template =
1622 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1623 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1624 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1626 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1627 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1630 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1636 VLIB_INIT_FUNCTION (dpdk_init);