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>
25 #include <vlib/unix/pci.h>
31 #include <sys/mount.h>
35 #include "dpdk_priv.h"
37 dpdk_main_t dpdk_main;
39 /* force linker to link functions used by vlib and declared weak */
40 void *vlib_weakly_linked_functions[] = {
42 &rte_pktmbuf_pool_init,
45 #define LINK_STATE_ELOGS 0
47 #define DEFAULT_HUGE_DIR "/run/vpp/hugepages"
48 #define VPP_RUN_DIR "/run/vpp"
50 /* Port configuration, mildly modified Intel app values */
52 static struct rte_eth_conf port_conf_template = {
55 .header_split = 0, /**< Header Split disabled */
56 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
57 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
58 .hw_strip_crc = 1, /**< CRC stripped by hardware */
61 .mq_mode = ETH_MQ_TX_NONE,
66 dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd)
68 vlib_main_t * vm = vlib_get_main();
69 vlib_buffer_main_t * bm = vm->buffer_main;
73 ASSERT(os_get_cpu_number() == 0);
76 vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0);
77 rte_eth_dev_stop (xd->device_index);
80 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
81 xd->tx_q_used, &xd->port_conf);
84 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
85 xd->device_index, rv);
87 /* Set up one TX-queue per worker thread */
88 for (j = 0; j < xd->tx_q_used; j++)
90 rv = rte_eth_tx_queue_setup(xd->device_index, j, xd->nb_tx_desc,
91 xd->cpu_socket, &xd->tx_conf);
93 /* retry with any other CPU socket */
95 rv = rte_eth_tx_queue_setup(xd->device_index, j, xd->nb_tx_desc,
96 SOCKET_ID_ANY, &xd->tx_conf);
102 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
103 xd->device_index, rv);
105 for (j = 0; j < xd->rx_q_used; j++)
108 rv = rte_eth_rx_queue_setup(xd->device_index, j, xd->nb_rx_desc,
110 bm->pktmbuf_pools[xd->cpu_socket_id_by_queue[j]]);
112 /* retry with any other CPU socket */
114 rv = rte_eth_rx_queue_setup(xd->device_index, j, xd->nb_rx_desc,
116 bm->pktmbuf_pools[xd->cpu_socket_id_by_queue[j]]);
118 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
119 xd->device_index, rv);
123 rte_eth_dev_start (xd->device_index);
128 static u32 dpdk_flag_change (vnet_main_t * vnm,
129 vnet_hw_interface_t * hi,
132 dpdk_main_t * dm = &dpdk_main;
133 dpdk_device_t * xd = vec_elt_at_index (dm->devices, hi->dev_instance);
136 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC(flags))
139 xd->promisc = flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
144 rte_eth_promiscuous_enable(xd->device_index);
146 rte_eth_promiscuous_disable(xd->device_index);
149 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU(flags))
152 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
153 * driver to dynamically change the mtu. If/when the
154 * VIC firmware gets fixed, then this should be removed.
156 if (xd->pmd == VNET_DPDK_PMD_VICE ||
157 xd->pmd == VNET_DPDK_PMD_ENIC)
159 struct rte_eth_dev_info dev_info;
162 * Restore mtu to what has been set by CIMC in the firmware cfg.
164 rte_eth_dev_info_get(xd->device_index, &dev_info);
165 hi->max_packet_bytes = dev_info.max_rx_pktlen;
167 vlib_cli_output (vlib_get_main(),
168 "Cisco VIC mtu can only be changed "
169 "using CIMC then rebooting the server!");
175 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
178 rte_eth_dev_stop (xd->device_index);
180 rv = rte_eth_dev_configure
187 vlib_cli_output (vlib_get_main(),
188 "rte_eth_dev_configure[%d]: err %d",
189 xd->device_index, rv);
191 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
194 rte_eth_dev_start (xd->device_index);
201 extern int rte_netmap_probe(void);
205 dpdk_device_lock_init(dpdk_device_t * xd)
208 vec_validate(xd->lockp, xd->tx_q_used - 1);
209 for (q = 0; q < xd->tx_q_used; q++)
211 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
212 CLIB_CACHE_LINE_BYTES);
213 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
219 dpdk_device_lock_free(dpdk_device_t * xd)
223 for (q = 0; q < vec_len(xd->lockp); q++)
224 clib_mem_free((void *) xd->lockp[q]);
230 static clib_error_t *
231 dpdk_lib_init (dpdk_main_t * dm)
236 clib_error_t * error;
237 vlib_main_t * vm = vlib_get_main();
238 vlib_thread_main_t * tm = vlib_get_thread_main();
239 vnet_sw_interface_t * sw;
240 vnet_hw_interface_t * hi;
242 vlib_thread_registration_t * tr;
246 u8 af_packet_port_id = 0;
248 dm->input_cpu_first_index = 0;
249 dm->input_cpu_count = 1;
251 /* find out which cpus will be used for input */
252 p = hash_get_mem (tm->thread_registrations_by_name, "io");
253 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
255 if (!tr || tr->count == 0)
257 /* no io threads, workers doing input */
258 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
259 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
263 dm->have_io_threads = 1;
266 if (tr && tr->count > 0)
268 dm->input_cpu_first_index = tr->first_index;
269 dm->input_cpu_count = tr->count;
272 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
273 CLIB_CACHE_LINE_BYTES);
275 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
276 CLIB_CACHE_LINE_BYTES);
279 if(rte_netmap_probe() < 0)
280 return clib_error_return (0, "rte netmap probe failed");
283 nports = rte_eth_dev_count();
286 clib_warning ("DPDK drivers found no ports...");
290 clib_warning ("DPDK drivers found %d ports...", nports);
293 * All buffers are all allocated from the same rte_mempool.
294 * Thus they all have the same number of data bytes.
296 dm->vlib_buffer_free_list_index =
297 vlib_buffer_get_or_create_free_list (
298 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
300 for (i = 0; i < nports; i++)
304 struct rte_eth_dev_info dev_info;
306 struct rte_eth_link l;
308 /* Create vnet interface */
309 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
310 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
311 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
312 xd->cpu_socket = (i8) rte_eth_dev_socket_id(i);
313 rte_eth_dev_info_get(i, &dev_info);
315 clib_memcpy(&xd->tx_conf, &dev_info.default_txconf,
316 sizeof(struct rte_eth_txconf));
317 if (dm->no_multi_seg)
319 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
320 port_conf_template.rxmode.jumbo_frame = 0;
324 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
325 port_conf_template.rxmode.jumbo_frame = 1;
328 clib_memcpy(&xd->port_conf, &port_conf_template, sizeof(struct rte_eth_conf));
330 xd->tx_q_used = clib_min(dev_info.max_tx_queues, tm->n_vlib_mains);
332 if (dm->max_tx_queues)
333 xd->tx_q_used = clib_min(xd->tx_q_used, dm->max_tx_queues);
335 if (dm->use_rss > 1 && dev_info.max_rx_queues >= dm->use_rss)
337 xd->rx_q_used = dm->use_rss;
338 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
339 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
344 xd->dev_type = VNET_DPDK_DEV_ETH;
346 /* workaround for drivers not setting driver_name */
347 if (!dev_info.driver_name)
348 dev_info.driver_name = dev_info.pci_dev->driver->name;
349 ASSERT(dev_info.driver_name);
354 #define _(s,f) else if (!strcmp(dev_info.driver_name, s)) \
355 xd->pmd = VNET_DPDK_PMD_##f;
361 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
366 case VNET_DPDK_PMD_E1000EM:
367 case VNET_DPDK_PMD_IGB:
368 case VNET_DPDK_PMD_IGBVF:
369 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
373 case VNET_DPDK_PMD_IXGBE:
374 case VNET_DPDK_PMD_IXGBEVF:
375 case VNET_DPDK_PMD_THUNDERX:
376 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
377 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
378 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
382 case VNET_DPDK_PMD_VICE:
383 case VNET_DPDK_PMD_ENIC:
384 rte_eth_link_get_nowait(i, &l);
385 if (l.link_speed == 40000)
387 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
388 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
389 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
393 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
394 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
395 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
399 /* Intel Fortville */
400 case VNET_DPDK_PMD_I40E:
401 case VNET_DPDK_PMD_I40EVF:
402 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
403 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
404 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
406 switch (dev_info.pci_dev->id.device_id) {
407 case I40E_DEV_ID_10G_BASE_T:
408 case I40E_DEV_ID_SFP_XL710:
409 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
411 case I40E_DEV_ID_QSFP_A:
412 case I40E_DEV_ID_QSFP_B:
413 case I40E_DEV_ID_QSFP_C:
414 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
417 rte_eth_link_get_nowait(i, &l);
418 xd->port_type = l.link_speed == 10000 ?
419 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
422 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
426 case VNET_DPDK_PMD_CXGBE:
427 switch (dev_info.pci_dev->id.device_id) {
428 case 0x5410: /* T580-LP-cr */
429 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
430 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
431 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
434 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
435 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
436 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
440 /* Intel Red Rock Canyon */
441 case VNET_DPDK_PMD_FM10K:
442 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
443 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
444 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
448 case VNET_DPDK_PMD_VIRTIO:
449 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
450 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
451 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
455 case VNET_DPDK_PMD_VMXNET3:
456 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
457 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
460 case VNET_DPDK_PMD_AF_PACKET:
461 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
462 xd->af_packet_port_id = af_packet_port_id++;
465 case VNET_DPDK_PMD_BOND:
466 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
470 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
474 if(strncmp(dev_info.driver_name, "vale", 4) == 0
475 || strncmp(dev_info.driver_name, "netmap", 6) == 0)
477 xd->pmd = VNET_DPDK_PMD_NETMAP;
478 xd->port_type = VNET_DPDK_PORT_TYPE_NETMAP;
485 * Ensure default mtu is not > the mtu read from the hardware.
486 * Otherwise rte_eth_dev_configure() will fail and the port will
489 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
492 * This device does not support the platforms's max frame
493 * size. Use it's advertised mru instead.
495 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
499 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
502 * Some platforms do not account for Ethernet FCS (4 bytes) in
503 * MTU calculations. To interop with them increase mru but only
504 * if the device's settings can support it.
506 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
507 xd->port_conf.rxmode.hw_strip_crc)
510 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
511 * stripped by h/w and so will not consume any buffer memory.
513 xd->port_conf.rxmode.max_rx_pkt_len += 4;
517 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
519 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
521 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
523 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
524 xd->port_conf.rxmode.jumbo_frame = 0;
528 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
530 f64 now = vlib_time_now(vm);
532 rnd = (u32) (now * 1e6);
533 rnd = random_u32 (&rnd);
534 clib_memcpy (addr+2, &rnd, sizeof(rnd));
539 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
541 if (xd->tx_q_used < tm->n_vlib_mains)
542 dpdk_device_lock_init(xd);
544 xd->device_index = xd - dm->devices;
545 ASSERT(i == xd->device_index);
546 xd->per_interface_next_index = ~0;
548 /* assign interface to input thread */
549 dpdk_device_and_queue_t * dq;
552 for (q = 0; q < xd->rx_q_used; q++)
554 int cpu = dm->input_cpu_first_index + next_cpu;
555 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
558 * numa node for worker thread handling this queue
559 * needed for taking buffers from the right mempool
561 vec_validate(xd->cpu_socket_id_by_queue, q);
562 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
565 * construct vector of (device,queue) pairs for each worker thread
567 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
568 dq->device = xd->device_index;
572 if (next_cpu == dm->input_cpu_count)
576 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
577 CLIB_CACHE_LINE_BYTES);
578 for (j = 0; j < tm->n_vlib_mains; j++)
580 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
581 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
582 vec_reset_length (xd->tx_vectors[j]);
585 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
586 CLIB_CACHE_LINE_BYTES);
587 for (j = 0; j< xd->rx_q_used; j++)
589 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
590 CLIB_CACHE_LINE_BYTES);
591 vec_reset_length (xd->rx_vectors[j]);
594 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
595 CLIB_CACHE_LINE_BYTES);
597 rv = dpdk_port_setup(dm, xd);
602 /* count the number of descriptors used for this device */
603 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
605 error = ethernet_register_interface
607 dpdk_device_class.index,
609 /* ethernet address */ addr,
610 &xd->vlib_hw_if_index,
615 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
616 xd->vlib_sw_if_index = sw->sw_if_index;
617 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
620 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
621 * driver to dynamically change the mtu. If/when the
622 * VIC firmware gets fixed, then this should be removed.
624 if (xd->pmd == VNET_DPDK_PMD_VICE ||
625 xd->pmd == VNET_DPDK_PMD_ENIC)
628 * Initialize mtu to what has been set by CIMC in the firmware cfg.
630 hi->max_packet_bytes = dev_info.max_rx_pktlen;
632 * remove vlan tag from VIC port to fix VLAN0 issue.
633 * TODO Handle VLAN tagged traffic
636 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
637 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
638 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
641 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
643 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
645 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
646 hi->max_packet_bytes = 1518;
649 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
650 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
652 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
655 #ifdef RTE_LIBRTE_KNI
657 clib_warning("Initializing KNI interfaces...");
658 rte_kni_init(dm->num_kni);
659 for (i = 0; i < dm->num_kni; i++)
664 /* Create vnet interface */
665 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
666 xd->dev_type = VNET_DPDK_DEV_KNI;
668 xd->device_index = xd - dm->devices;
669 ASSERT(nports + i == xd->device_index);
670 xd->per_interface_next_index = ~0;
673 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
676 /* assign interface to input thread */
677 dpdk_device_and_queue_t * dq;
678 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
679 dq->device = xd->device_index;
682 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
683 CLIB_CACHE_LINE_BYTES);
684 for (j = 0; j < tm->n_vlib_mains; j++)
686 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
687 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
688 vec_reset_length (xd->tx_vectors[j]);
691 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
692 CLIB_CACHE_LINE_BYTES);
693 for (j = 0; j< xd->rx_q_used; j++)
695 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
696 CLIB_CACHE_LINE_BYTES);
697 vec_reset_length (xd->rx_vectors[j]);
700 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
701 CLIB_CACHE_LINE_BYTES);
703 /* FIXME Set up one TX-queue per worker thread */
706 f64 now = vlib_time_now(vm);
708 rnd = (u32) (now * 1e6);
709 rnd = random_u32 (&rnd);
711 clib_memcpy (addr+2, &rnd, sizeof(rnd));
716 error = ethernet_register_interface
718 dpdk_device_class.index,
720 /* ethernet address */ addr,
721 &xd->vlib_hw_if_index,
727 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
728 xd->vlib_sw_if_index = sw->sw_if_index;
729 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
734 if (nb_desc > dm->num_mbufs)
735 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
736 dm->num_mbufs, nb_desc);
738 /* init next vhost-user if index */
739 dm->next_vu_if_id = 0;
745 dpdk_bind_devices_to_uio (dpdk_main_t * dm)
747 linux_pci_main_t * pm = &linux_pci_main;
748 clib_error_t * error;
749 vlib_pci_device_t * d;
750 pci_config_header_t * c;
753 pool_foreach (d, pm->pci_devs, ({
754 c = &d->config0.header;
755 vec_reset_length (pci_addr);
756 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
758 if (c->device_class != PCI_CLASS_NETWORK_ETHERNET)
761 /* if whitelist exists process only whitelisted devices */
762 if (dm->eth_if_whitelist &&
763 !strstr ((char *) dm->eth_if_whitelist, (char *) pci_addr))
767 if (c->vendor_id == 0x1af4 && c->device_id == 0x1000)
770 else if (c->vendor_id == 0x15ad && c->device_id == 0x07b0)
772 /* all Intel devices */
773 else if (c->vendor_id == 0x8086)
776 else if (c->vendor_id == 0x1137 && c->device_id == 0x0043)
779 else if (c->vendor_id == 0x1425 && (c->device_id & 0xe000) == 0x4000)
783 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
784 "at PCI address %s\n", (u16) c->vendor_id, (u16) c->device_id,
789 error = vlib_pci_bind_to_uio (d, (char *) dm->uio_driver_name);
793 if (!dm->eth_if_whitelist)
794 dm->eth_if_blacklist = format (dm->eth_if_blacklist, "%U ",
795 format_vlib_pci_addr, &d->bus_address);
796 clib_error_report (error);
802 static clib_error_t *
803 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
805 clib_error_t * error = 0;
806 dpdk_main_t * dm = &dpdk_main;
807 vlib_thread_main_t * tm = vlib_get_thread_main();
810 u8 * rte_cmd = 0, * ethname = 0;
815 int rxrings, txrings, rxslots, txslots, txburst;
818 unformat_input_t _in;
819 unformat_input_t * in = &_in;
826 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
827 dm->use_virtio_vhost = 1;
829 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
832 if (unformat (input, "no-hugetlb"))
834 vec_add1 (dm->eal_init_args, (u8 *) "no-huge");
838 else if (unformat (input, "enable-tcp-udp-checksum"))
840 dm->buffer_flags_template &=
841 ~(IP_BUFFER_L4_CHECKSUM_CORRECT | IP_BUFFER_L4_CHECKSUM_COMPUTED);
844 else if (unformat (input, "decimal-interface-names"))
845 dm->interface_name_format_decimal = 1;
847 else if (unformat (input, "no-multi-seg"))
848 dm->no_multi_seg = 1;
850 else if (unformat (input, "dev %s", &pci_dev_id))
852 if (dm->eth_if_whitelist)
855 * Don't add duplicate device id's.
857 if (strstr ((char *)dm->eth_if_whitelist, (char *)pci_dev_id))
860 _vec_len (dm->eth_if_whitelist) -= 1; // chomp trailing NULL.
861 dm->eth_if_whitelist = format (dm->eth_if_whitelist, " %s%c",
865 dm->eth_if_whitelist = format (0, "%s%c", pci_dev_id, 0);
869 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
870 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
873 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
875 error = clib_error_return (0, "%s", rv);
878 }else if (unformat(input, "netmap %s", &nmname)) {
881 eth_nm_args(nmname, 0, 0, 0, 0, 0);
883 error = clib_error_return (0, "%s", rv);
889 else if (unformat (input, "num-mbufs %d", &dm->num_mbufs))
891 else if (unformat (input, "max-tx-queues %d", &dm->max_tx_queues))
893 else if (unformat (input, "kni %d", &dm->num_kni))
895 else if (unformat (input, "uio-driver %s", &dm->uio_driver_name))
897 else if (unformat (input, "socket-mem %s", &socket_mem))
899 else if (unformat (input, "vhost-user-coalesce-frames %d", &dm->vhost_coalesce_frames))
901 else if (unformat (input, "vhost-user-coalesce-time %f", &dm->vhost_coalesce_time))
903 else if (unformat (input, "enable-vhost-user"))
904 dm->use_virtio_vhost = 0;
905 else if (unformat (input, "rss %d", &dm->use_rss))
909 else if (unformat(input, #a)) \
911 if (!strncmp(#a, "no-pci", 6)) \
913 tmp = format (0, "--%s%c", #a, 0); \
914 vec_add1 (dm->eal_init_args, tmp); \
916 foreach_eal_double_hyphen_predicate_arg
920 else if (unformat(input, #a " %s", &s)) \
922 if (!strncmp(#a, "huge-dir", 8)) \
924 else if (!strncmp(#a, "file-prefix", 11)) \
926 tmp = format (0, "--%s%c", #a, 0); \
927 vec_add1 (dm->eal_init_args, tmp); \
929 vec_add1 (dm->eal_init_args, s); \
931 foreach_eal_double_hyphen_arg
935 else if (unformat(input, #a " %s", &s)) \
937 tmp = format (0, "-%s%c", #b, 0); \
938 vec_add1 (dm->eal_init_args, tmp); \
940 vec_add1 (dm->eal_init_args, s); \
942 foreach_eal_single_hyphen_arg
946 else if (unformat(input, #a " %s", &s)) \
948 tmp = format (0, "-%s%c", #b, 0); \
949 vec_add1 (dm->eal_init_args, tmp); \
951 vec_add1 (dm->eal_init_args, s); \
952 dm->a##_set_manually = 1; \
954 foreach_eal_single_hyphen_mandatory_arg
957 else if (unformat(input, "default"))
962 error = clib_error_return (0, "unknown input `%U'",
963 format_unformat_error, input);
968 if (!dm->uio_driver_name)
969 dm->uio_driver_name = format (0, "igb_uio%c", 0);
972 * Use 1G huge pages if available.
974 if (!no_huge && !huge_dir)
976 u32 x, * mem_by_socket = 0;
983 umount(DEFAULT_HUGE_DIR);
985 /* Process "socket-mem" parameter value */
986 if (vec_len (socket_mem))
989 unformat_init_vector(&in, socket_mem);
990 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
992 if (unformat (&in, "%u,", &x))
994 else if (unformat (&in, "%u", &x))
996 else if (unformat (&in, ","))
1001 vec_add1(mem_by_socket, x);
1006 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1012 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1014 vec_validate(mem_by_socket, c);
1015 mem_by_socket[c] = 512; /* default per-socket mem */
1020 /* check if available enough 1GB pages for each socket */
1021 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1023 u32 pages_avail, page_size, mem;
1025 char * path = "/sys/devices/system/node/node%u/hugepages/"
1026 "hugepages-%ukB/free_hugepages%c";
1028 vec_validate(mem_by_socket, c);
1029 mem = mem_by_socket[c];
1033 s = format (s, path, c, page_size * 1024, 0);
1034 read_sys_fs ((char *) s, "%u", &pages_avail);
1035 vec_reset_length (s);
1037 if (page_size * pages_avail < mem)
1042 s = format (s, path, c, page_size * 1024, 0);
1043 read_sys_fs ((char *) s, "%u", &pages_avail);
1044 vec_reset_length (s);
1046 if (page_size * pages_avail < mem)
1051 _vec_len (mem_by_socket) = c + 1;
1053 /* regenerate socket_mem string */
1054 vec_foreach_index (x, mem_by_socket)
1055 socket_mem = format (socket_mem, "%s%u",
1056 socket_mem ? "," : "",
1058 socket_mem = format (socket_mem, "%c", 0);
1060 vec_free (mem_by_socket);
1062 rv = mkdir(VPP_RUN_DIR, 0755);
1063 if (rv && errno != EEXIST)
1065 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1066 VPP_RUN_DIR, errno);
1070 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1071 if (rv && errno != EEXIST)
1073 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1074 DEFAULT_HUGE_DIR, errno);
1078 if (use_1g && !(less_than_1g && use_2m))
1080 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1084 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1088 return clib_error_return (0, "not enough free huge pages");
1093 error = clib_error_return (0, "mount failed %d", errno);
1097 tmp = format (0, "--huge-dir%c", 0);
1098 vec_add1 (dm->eal_init_args, tmp);
1099 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1100 vec_add1 (dm->eal_init_args, tmp);
1103 tmp = format (0, "--file-prefix%c", 0);
1104 vec_add1 (dm->eal_init_args, tmp);
1105 tmp = format (0, "vpp%c", 0);
1106 vec_add1 (dm->eal_init_args, tmp);
1116 /* I'll bet that -c and -n must be the first and second args... */
1117 if (!dm->coremask_set_manually)
1119 vlib_thread_registration_t * tr;
1120 uword * coremask = 0;
1123 /* main thread core */
1124 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1126 for (i = 0; i < vec_len (tm->registrations); i++)
1128 tr = tm->registrations[i];
1129 coremask = clib_bitmap_or(coremask, tr->coremask);
1132 vec_insert (dm->eal_init_args, 2, 1);
1133 dm->eal_init_args[1] = (u8 *) "-c";
1134 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1135 dm->eal_init_args[2] = tmp;
1136 clib_bitmap_free(coremask);
1139 if (!dm->nchannels_set_manually)
1141 vec_insert (dm->eal_init_args, 2, 3);
1142 dm->eal_init_args[3] = (u8 *) "-n";
1143 tmp = format (0, "%d", dm->nchannels);
1144 dm->eal_init_args[4] = tmp;
1147 if (no_pci == 0 && geteuid() == 0)
1148 dpdk_bind_devices_to_uio(dm);
1151 * If there are whitelisted devices,
1152 * add the whitelist option & device list to the dpdk arg list...
1154 if (dm->eth_if_whitelist)
1156 unformat_init_string (in, (char *)dm->eth_if_whitelist,
1157 vec_len(dm->eth_if_whitelist) - 1);
1162 * Otherwise add the blacklisted devices to the dpdk arg list.
1166 unformat_init_string (in, (char *)dm->eth_if_blacklist,
1167 vec_len(dm->eth_if_blacklist) - 1);
1171 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
1173 tmp = format (0, fmt, 0);
1174 vec_add1 (dm->eal_init_args, tmp);
1175 unformat (in, "%s", &pci_dev_id);
1176 vec_add1 (dm->eal_init_args, pci_dev_id);
1179 /* set master-lcore */
1180 tmp = format (0, "--master-lcore%c", 0);
1181 vec_add1 (dm->eal_init_args, tmp);
1182 tmp = format (0, "%u%c", tm->main_lcore, 0);
1183 vec_add1 (dm->eal_init_args, tmp);
1185 /* set socket-mem */
1186 tmp = format (0, "--socket-mem%c", 0);
1187 vec_add1 (dm->eal_init_args, tmp);
1188 tmp = format (0, "%s%c", socket_mem, 0);
1189 vec_add1 (dm->eal_init_args, tmp);
1191 /* NULL terminate the "argv" vector, in case of stupidity */
1192 vec_add1 (dm->eal_init_args, 0);
1193 _vec_len(dm->eal_init_args) -= 1;
1195 /* Set up DPDK eal and packet mbuf pool early. */
1197 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1199 rte_set_log_level (log_level);
1203 /* make copy of args as rte_eal_init tends to mess up with arg array */
1204 for (i = 1; i < vec_len(dm->eal_init_args); i++)
1205 dm->eal_init_args_str = format(dm->eal_init_args_str, "%s ",
1206 dm->eal_init_args[i]);
1208 ret = rte_eal_init(vec_len(dm->eal_init_args), (char **) dm->eal_init_args);
1210 /* lazy umount hugepages */
1211 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1214 return clib_error_return (0, "rte_eal_init returned %d", ret);
1216 /* Dump the physical memory layout prior to creating the mbuf_pool */
1217 fprintf(stdout, "DPDK physical memory layout:\n");
1218 rte_dump_physmem_layout(stdout);
1220 /* main thread 1st */
1221 error = vlib_buffer_pool_create(vm, dm->num_mbufs, rte_socket_id());
1225 for (i = 0; i < RTE_MAX_LCORE; i++)
1227 error = vlib_buffer_pool_create(vm, dm->num_mbufs,
1228 rte_lcore_to_socket_id(i));
1235 vlib_node_runtime_t * rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
1236 rt->function = dpdk_input_rss;
1242 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1244 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1246 vnet_main_t * vnm = vnet_get_main();
1247 struct rte_eth_link prev_link = xd->link;
1249 u8 hw_flags_chg = 0;
1251 /* only update link state for PMD interfaces */
1252 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1255 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1256 memset(&xd->link, 0, sizeof(xd->link));
1257 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1259 if (LINK_STATE_ELOGS)
1261 vlib_main_t * vm = vlib_get_main();
1262 ELOG_TYPE_DECLARE(e) = {
1264 "update-link-state: sw_if_index %d, admin_up %d,"
1265 "old link_state %d new link_state %d",
1266 .format_args = "i4i1i1i1",
1269 struct { u32 sw_if_index; u8 admin_up;
1270 u8 old_link_state; u8 new_link_state;} *ed;
1271 ed = ELOG_DATA (&vm->elog_main, e);
1272 ed->sw_if_index = xd->vlib_sw_if_index;
1273 ed->admin_up = xd->admin_up;
1274 ed->old_link_state = (u8)
1275 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1276 ed->new_link_state = (u8) xd->link.link_status;
1279 if ((xd->admin_up == 1) &&
1280 ((xd->link.link_status != 0) ^
1281 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1284 hw_flags |= (xd->link.link_status ?
1285 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1288 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1291 switch (xd->link.link_duplex)
1293 case ETH_LINK_HALF_DUPLEX:
1294 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1296 case ETH_LINK_FULL_DUPLEX:
1297 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1303 #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
1304 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1307 switch (xd->link.link_speed)
1309 case ETH_SPEED_NUM_10M:
1310 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1312 case ETH_SPEED_NUM_100M:
1313 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1315 case ETH_SPEED_NUM_1G:
1316 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1318 case ETH_SPEED_NUM_10G:
1319 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1321 case ETH_SPEED_NUM_40G:
1322 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1327 clib_warning("unknown link speed %d", xd->link.link_speed);
1332 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1335 switch (xd->link.link_speed)
1337 case ETH_LINK_SPEED_10:
1338 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1340 case ETH_LINK_SPEED_100:
1341 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1343 case ETH_LINK_SPEED_1000:
1344 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1346 case ETH_LINK_SPEED_10000:
1347 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1349 case ETH_LINK_SPEED_40G:
1350 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1355 clib_warning("unknown link speed %d", xd->link.link_speed);
1362 if (LINK_STATE_ELOGS)
1364 vlib_main_t * vm = vlib_get_main();
1366 ELOG_TYPE_DECLARE(e) = {
1367 .format = "update-link-state: sw_if_index %d, new flags %d",
1368 .format_args = "i4i4",
1371 struct { u32 sw_if_index; u32 flags; } *ed;
1372 ed = ELOG_DATA (&vm->elog_main, e);
1373 ed->sw_if_index = xd->vlib_sw_if_index;
1374 ed->flags = hw_flags;
1376 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1381 dpdk_process (vlib_main_t * vm,
1382 vlib_node_runtime_t * rt,
1385 clib_error_t * error;
1386 vnet_main_t * vnm = vnet_get_main();
1387 dpdk_main_t * dm = &dpdk_main;
1388 ethernet_main_t * em = ðernet_main;
1390 vlib_thread_main_t * tm = vlib_get_thread_main();
1394 error = dpdk_lib_init (dm);
1397 * Turn on the input node if we found some devices to drive
1398 * and we're not running worker threads or i/o threads
1401 if (error == 0 && vec_len(dm->devices) > 0)
1403 if (tm->n_vlib_mains == 1)
1404 vlib_node_set_state (vm, dpdk_input_node.index,
1405 VLIB_NODE_STATE_POLLING);
1406 else if (tm->main_thread_is_io_node)
1407 vlib_node_set_state (vm, dpdk_io_input_node.index,
1408 VLIB_NODE_STATE_POLLING);
1409 else if (!dm->have_io_threads)
1410 for (i=0; i < tm->n_vlib_mains; i++)
1411 if (vec_len(dm->devices_by_cpu[i]) > 0)
1412 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1413 VLIB_NODE_STATE_POLLING);
1417 clib_error_report (error);
1419 dpdk_vhost_user_process_init(&vu_state);
1421 dm->io_thread_release = 1;
1423 f64 now = vlib_time_now (vm);
1424 vec_foreach (xd, dm->devices)
1426 dpdk_update_link_state (xd, now);
1429 { // Extra set up for bond interfaces:
1430 // 1. Setup MACs for bond interfaces and their slave links which was set
1431 // in dpdk_port_setup() but needs to be done again here to take effect.
1432 // 2. Set max L3 packet size of each bond interface to the lowerst value of
1434 // 3. Set up info for bond interface related CLI support.
1435 int nports = rte_eth_dev_count();
1437 for (i = 0; i < nports; i++) {
1438 struct rte_eth_dev_info dev_info;
1439 rte_eth_dev_info_get(i, &dev_info);
1440 if (!dev_info.driver_name)
1441 dev_info.driver_name = dev_info.pci_dev->driver->name;
1442 ASSERT(dev_info.driver_name);
1443 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1446 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1448 vnet_hw_interface_t * bhi;
1449 ethernet_interface_t * bei;
1450 /* Get MAC of 1st slave link */
1451 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1452 /* Set MAC of bounded interface to that of 1st slave link */
1453 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1454 /* Populate MAC of bonded interface in VPP hw tables */
1455 bhi = vnet_get_hw_interface(
1456 vnm, dm->devices[i].vlib_hw_if_index);
1457 bei = pool_elt_at_index(em->interfaces, bhi->hw_instance);
1458 clib_memcpy(bhi->hw_address, addr, 6);
1459 clib_memcpy(bei->address, addr, 6);
1460 /* Init l3 packet size allowed on bonded interface */
1461 bhi->max_l3_packet_bytes[VLIB_RX] =
1462 bhi->max_l3_packet_bytes[VLIB_TX] =
1463 ETHERNET_MAX_PACKET_BYTES - sizeof(ethernet_header_t);
1464 while (nlink >= 1) { /* for all slave links */
1465 int slave = slink[--nlink];
1466 dpdk_device_t * sdev = &dm->devices[slave];
1467 vnet_hw_interface_t * shi;
1468 vnet_sw_interface_t * ssi;
1469 /* Add MAC to all slave links except the first one */
1470 if (nlink) rte_eth_dev_mac_addr_add(
1471 slave, (struct ether_addr *)addr, 0);
1472 /* Set slaves bitmap for bonded interface */
1473 bhi->bond_info = clib_bitmap_set(
1474 bhi->bond_info, sdev->vlib_hw_if_index, 1);
1475 /* Set slave link flags on slave interface */
1476 shi = vnet_get_hw_interface(vnm, sdev->vlib_hw_if_index);
1477 ssi = vnet_get_sw_interface(vnm, sdev->vlib_sw_if_index);
1478 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1479 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1480 /* Set l3 packet size allowed as the lowest of slave */
1481 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1482 shi->max_l3_packet_bytes[VLIB_RX])
1483 bhi->max_l3_packet_bytes[VLIB_RX] =
1484 bhi->max_l3_packet_bytes[VLIB_TX] =
1485 shi->max_l3_packet_bytes[VLIB_RX];
1496 * check each time through the loop in case intervals are changed
1498 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1499 dm->link_state_poll_interval : dm->stat_poll_interval;
1501 vlib_process_wait_for_event_or_clock (vm, min_wait);
1503 if (dpdk_get_admin_up_down_in_progress())
1504 /* skip the poll if an admin up down is in progress (on any interface) */
1507 vec_foreach (xd, dm->devices)
1509 f64 now = vlib_time_now (vm);
1510 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1511 dpdk_update_counters (xd, now);
1512 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1513 dpdk_update_link_state (xd, now);
1515 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1516 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1521 dpdk_vhost_user_process_cleanup(vu_state);
1526 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1527 .function = dpdk_process,
1528 .type = VLIB_NODE_TYPE_PROCESS,
1529 .name = "dpdk-process",
1530 .process_log2_n_stack_bytes = 17,
1533 int dpdk_set_stat_poll_interval (f64 interval)
1535 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1536 return (VNET_API_ERROR_INVALID_VALUE);
1538 dpdk_main.stat_poll_interval = interval;
1543 int dpdk_set_link_state_poll_interval (f64 interval)
1545 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1546 return (VNET_API_ERROR_INVALID_VALUE);
1548 dpdk_main.link_state_poll_interval = interval;
1554 dpdk_init (vlib_main_t * vm)
1556 dpdk_main_t * dm = &dpdk_main;
1558 clib_error_t * error = 0;
1559 vlib_thread_main_t * tm = vlib_get_thread_main();
1561 /* verify that structs are cacheline aligned */
1562 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1563 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1564 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1565 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1568 dm->vnet_main = vnet_get_main();
1570 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1572 return clib_error_return (0, "ethernet-input node AWOL");
1574 dm->ethernet_input_node_index = ei->index;
1577 dm->num_mbufs = dm->num_mbufs ? dm->num_mbufs : NB_MBUF;
1578 vec_add1 (dm->eal_init_args, (u8 *) "vnet");
1580 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1581 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1582 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1584 /* $$$ use n_thread_stacks since it's known-good at this point */
1585 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1587 /* initialize EFD (early fast discard) default settings */
1588 dm->efd.enabled = DPDK_EFD_DISABLED;
1589 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1590 DPDK_NB_RX_DESC_10GE)/100);
1591 dm->efd.consec_full_frames_hi_thresh =
1592 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1594 /* vhost-user coalescence frames defaults */
1595 dm->vhost_coalesce_frames = 32;
1596 dm->vhost_coalesce_time = 1e-3;
1598 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1599 dm->buffer_flags_template =
1600 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1601 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1602 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1604 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1605 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1608 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1614 VLIB_INIT_FUNCTION (dpdk_init);