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!");
161 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
164 rte_eth_dev_stop (xd->device_index);
166 rv = rte_eth_dev_configure
173 vlib_cli_output (vlib_get_main(),
174 "rte_eth_dev_configure[%d]: err %d",
175 xd->device_index, rv);
177 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
180 rte_eth_dev_start (xd->device_index);
187 extern int rte_netmap_probe(void);
191 dpdk_device_lock_init(dpdk_device_t * xd)
194 vec_validate(xd->lockp, xd->tx_q_used - 1);
195 for (q = 0; q < xd->tx_q_used; q++)
197 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
198 CLIB_CACHE_LINE_BYTES);
199 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
205 dpdk_device_lock_free(dpdk_device_t * xd)
209 for (q = 0; q < vec_len(xd->lockp); q++)
210 clib_mem_free((void *) xd->lockp[q]);
216 static clib_error_t *
217 dpdk_lib_init (dpdk_main_t * dm)
222 clib_error_t * error;
223 vlib_main_t * vm = vlib_get_main();
224 vlib_thread_main_t * tm = vlib_get_thread_main();
225 vnet_sw_interface_t * sw;
226 vnet_hw_interface_t * hi;
228 vlib_thread_registration_t * tr;
232 u8 af_packet_port_id = 0;
234 dm->input_cpu_first_index = 0;
235 dm->input_cpu_count = 1;
237 /* find out which cpus will be used for input */
238 p = hash_get_mem (tm->thread_registrations_by_name, "io");
239 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
241 if (!tr || tr->count == 0)
243 /* no io threads, workers doing input */
244 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
245 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
249 dm->have_io_threads = 1;
252 if (tr && tr->count > 0)
254 dm->input_cpu_first_index = tr->first_index;
255 dm->input_cpu_count = tr->count;
258 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
259 CLIB_CACHE_LINE_BYTES);
261 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
262 CLIB_CACHE_LINE_BYTES);
265 if(rte_netmap_probe() < 0)
266 return clib_error_return (0, "rte netmap probe failed");
269 nports = rte_eth_dev_count();
272 clib_warning ("DPDK drivers found no ports...");
276 clib_warning ("DPDK drivers found %d ports...", nports);
279 * All buffers are all allocated from the same rte_mempool.
280 * Thus they all have the same number of data bytes.
282 dm->vlib_buffer_free_list_index =
283 vlib_buffer_get_or_create_free_list (
284 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
286 for (i = 0; i < nports; i++)
290 struct rte_eth_dev_info dev_info;
292 struct rte_eth_link l;
294 /* Create vnet interface */
295 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
296 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
297 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
298 xd->cpu_socket = (i8) rte_eth_dev_socket_id(i);
299 rte_eth_dev_info_get(i, &dev_info);
301 memcpy(&xd->tx_conf, &dev_info.default_txconf,
302 sizeof(struct rte_eth_txconf));
303 if (dm->no_multi_seg)
305 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
306 port_conf_template.rxmode.jumbo_frame = 0;
310 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
311 port_conf_template.rxmode.jumbo_frame = 1;
314 memcpy(&xd->port_conf, &port_conf_template, sizeof(struct rte_eth_conf));
316 xd->tx_q_used = clib_min(dev_info.max_tx_queues, tm->n_vlib_mains);
318 if (dm->max_tx_queues)
319 xd->tx_q_used = clib_min(xd->tx_q_used, dm->max_tx_queues);
321 if (dm->use_rss > 1 && dev_info.max_rx_queues >= dm->use_rss)
323 xd->rx_q_used = dm->use_rss;
324 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
325 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
330 xd->dev_type = VNET_DPDK_DEV_ETH;
332 /* workaround for drivers not setting driver_name */
333 if (!dev_info.driver_name)
334 dev_info.driver_name = dev_info.pci_dev->driver->name;
335 ASSERT(dev_info.driver_name);
340 #define _(s,f) else if (!strcmp(dev_info.driver_name, s)) \
341 xd->pmd = VNET_DPDK_PMD_##f;
347 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
352 case VNET_DPDK_PMD_E1000EM:
353 case VNET_DPDK_PMD_IGB:
354 case VNET_DPDK_PMD_IGBVF:
355 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
359 case VNET_DPDK_PMD_IXGBE:
360 case VNET_DPDK_PMD_IXGBEVF:
361 case VNET_DPDK_PMD_THUNDERX:
362 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
363 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
364 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
368 case VNET_DPDK_PMD_VICE:
369 case VNET_DPDK_PMD_ENIC:
370 rte_eth_link_get_nowait(i, &l);
371 if (l.link_speed == 40000)
373 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
374 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
375 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
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 /* Intel Fortville */
386 case VNET_DPDK_PMD_I40E:
387 case VNET_DPDK_PMD_I40EVF:
388 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
389 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
390 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
392 switch (dev_info.pci_dev->id.device_id) {
393 case I40E_DEV_ID_10G_BASE_T:
394 case I40E_DEV_ID_SFP_XL710:
395 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
397 case I40E_DEV_ID_QSFP_A:
398 case I40E_DEV_ID_QSFP_B:
399 case I40E_DEV_ID_QSFP_C:
400 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
403 rte_eth_link_get_nowait(i, &l);
404 xd->port_type = l.link_speed == 10000 ?
405 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
408 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
412 case VNET_DPDK_PMD_CXGBE:
413 switch (dev_info.pci_dev->id.device_id) {
414 case 0x5410: /* T580-LP-cr */
415 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
416 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
417 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
420 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
421 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
422 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
426 /* Intel Red Rock Canyon */
427 case VNET_DPDK_PMD_FM10K:
428 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
429 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
430 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
434 case VNET_DPDK_PMD_VIRTIO:
435 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
436 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
437 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
441 case VNET_DPDK_PMD_VMXNET3:
442 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
443 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
446 case VNET_DPDK_PMD_AF_PACKET:
447 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
448 xd->af_packet_port_id = af_packet_port_id++;
451 case VNET_DPDK_PMD_BOND:
452 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
456 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
460 if(strncmp(dev_info.driver_name, "vale", 4) == 0
461 || strncmp(dev_info.driver_name, "netmap", 6) == 0)
463 xd->pmd = VNET_DPDK_PMD_NETMAP;
464 xd->port_type = VNET_DPDK_PORT_TYPE_NETMAP;
471 * Ensure default mtu is not > the mtu read from the hardware.
472 * Otherwise rte_eth_dev_configure() will fail and the port will
475 xd->port_conf.rxmode.max_rx_pkt_len =
476 (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen) ?
477 dev_info.max_rx_pktlen : ETHERNET_MAX_PACKET_BYTES;
480 * DAW-FIXME: VMXNET3 driver doesn't support jumbo / multi-buffer pkts
482 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
484 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
485 xd->port_conf.rxmode.jumbo_frame = 0;
488 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
490 f64 now = vlib_time_now(vm);
492 rnd = (u32) (now * 1e6);
493 rnd = random_u32 (&rnd);
494 memcpy (addr+2, &rnd, sizeof(rnd));
499 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
501 if (xd->tx_q_used < tm->n_vlib_mains)
502 dpdk_device_lock_init(xd);
504 xd->device_index = xd - dm->devices;
505 ASSERT(i == xd->device_index);
506 xd->per_interface_next_index = ~0;
508 /* assign interface to input thread */
509 dpdk_device_and_queue_t * dq;
512 for (q = 0; q < xd->rx_q_used; q++)
514 int cpu = dm->input_cpu_first_index + next_cpu;
515 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
518 * numa node for worker thread handling this queue
519 * needed for taking buffers from the right mempool
521 vec_validate(xd->cpu_socket_id_by_queue, q);
522 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
525 * construct vector of (device,queue) pairs for each worker thread
527 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
528 dq->device = xd->device_index;
532 if (next_cpu == dm->input_cpu_count)
536 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
537 CLIB_CACHE_LINE_BYTES);
538 for (j = 0; j < tm->n_vlib_mains; j++)
540 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
541 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
542 vec_reset_length (xd->tx_vectors[j]);
545 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
546 CLIB_CACHE_LINE_BYTES);
547 for (j = 0; j< xd->rx_q_used; j++)
549 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
550 CLIB_CACHE_LINE_BYTES);
551 vec_reset_length (xd->rx_vectors[j]);
554 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
555 CLIB_CACHE_LINE_BYTES);
557 rv = dpdk_port_setup(dm, xd);
562 /* count the number of descriptors used for this device */
563 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
565 error = ethernet_register_interface
567 dpdk_device_class.index,
569 /* ethernet address */ addr,
570 &xd->vlib_hw_if_index,
575 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
576 xd->vlib_sw_if_index = sw->sw_if_index;
577 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
580 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
581 * driver to dynamically change the mtu. If/when the
582 * VIC firmware gets fixed, then this should be removed.
584 if (xd->pmd == VNET_DPDK_PMD_VICE ||
585 xd->pmd == VNET_DPDK_PMD_ENIC)
588 * Initialize mtu to what has been set by CIMC in the firmware cfg.
590 hi->max_packet_bytes = dev_info.max_rx_pktlen;
592 * remove vlan tag from VIC port to fix VLAN0 issue.
593 * TODO Handle VLAN tagged traffic
596 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
597 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
598 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
601 * DAW-FIXME: VMXNET3 driver doesn't support jumbo / multi-buffer pkts
603 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
604 hi->max_packet_bytes = 1518;
606 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
607 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
609 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
612 #ifdef RTE_LIBRTE_KNI
614 clib_warning("Initializing KNI interfaces...");
615 rte_kni_init(dm->num_kni);
616 for (i = 0; i < dm->num_kni; i++)
621 /* Create vnet interface */
622 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
623 xd->dev_type = VNET_DPDK_DEV_KNI;
625 xd->device_index = xd - dm->devices;
626 ASSERT(nports + i == xd->device_index);
627 xd->per_interface_next_index = ~0;
630 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
633 /* assign interface to input thread */
634 dpdk_device_and_queue_t * dq;
635 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
636 dq->device = xd->device_index;
639 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
640 CLIB_CACHE_LINE_BYTES);
641 for (j = 0; j < tm->n_vlib_mains; j++)
643 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
644 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
645 vec_reset_length (xd->tx_vectors[j]);
648 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
649 CLIB_CACHE_LINE_BYTES);
650 for (j = 0; j< xd->rx_q_used; j++)
652 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
653 CLIB_CACHE_LINE_BYTES);
654 vec_reset_length (xd->rx_vectors[j]);
657 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
658 CLIB_CACHE_LINE_BYTES);
660 /* FIXME Set up one TX-queue per worker thread */
663 f64 now = vlib_time_now(vm);
665 rnd = (u32) (now * 1e6);
666 rnd = random_u32 (&rnd);
668 memcpy (addr+2, &rnd, sizeof(rnd));
673 error = ethernet_register_interface
675 dpdk_device_class.index,
677 /* ethernet address */ addr,
678 &xd->vlib_hw_if_index,
684 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
685 xd->vlib_sw_if_index = sw->sw_if_index;
686 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
691 if (nb_desc > dm->num_mbufs)
692 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
693 dm->num_mbufs, nb_desc);
695 /* init next vhost-user if index */
696 dm->next_vu_if_id = 0;
701 static clib_error_t *
702 write_sys_fs (char * file_name, char * fmt, ...)
707 fd = open (file_name, O_WRONLY);
709 return clib_error_return_unix (0, "open `%s'", file_name);
713 s = va_format (0, fmt, &va);
715 vec_add1 (s, 0); // terminate c string
717 if (write (fd, s, vec_len (s)) < 0)
718 return clib_error_return_unix (0, "write '%s' to '%s'", s, file_name);
725 #define VIRTIO_PCI_NAME "virtio-pci"
727 static clib_error_t * dpdk_bind_eth_kernel_drivers (vlib_main_t * vm,
729 char * kernel_driver)
731 dpdk_main_t * dm = &dpdk_main;
732 unformat_input_t _in;
733 unformat_input_t * in = &_in;
734 clib_error_t * error = 0;
735 u8 * line = 0, * modcmd = 0, * path = 0;
736 u8 * pci_vid = 0, *pci_did = 0, * devname = 0;
737 char *driver_name = kernel_driver;
741 * Bail out now if we're not running as root.
742 * This allows non-privileged use of the packet generator, etc.
748 * Get all ethernet pci device numbers for the device type specified.
750 modcmd = format (0, "lspci -nDd %s | grep 0200 | "
751 "awk '{ print $1, $3 }'%c", pci_dev_id, 0);
752 if ((fp = popen ((const char *)modcmd, "r")) == NULL)
754 error = clib_error_return_unix (0,
755 "Unable to get %s ethernet pci devices.",
760 vec_validate (line, BUFSIZ);
761 vec_validate (path, BUFSIZ);
762 while (fgets ((char *)line, BUFSIZ, fp) != NULL)
766 line[strlen ((char *)line) - 1] = 0; // chomp trailing newline.
768 unformat_init_string (in, (char *)line, strlen((char *)line) + 1);
769 unformat(in, "%s %s:%s", &devname, &pci_vid, &pci_did);
773 * Blacklist all ethernet interfaces in the
774 * linux IP routing tables (route --inet --inet6)
776 if (strstr ((char *)dm->eth_if_blacklist, (char *)devname))
780 * If there are any devices whitelisted, then blacklist all devices
781 * which are not explicitly whitelisted.
783 if (dm->eth_if_whitelist &&
784 !strstr ((char *)dm->eth_if_whitelist, (char *)devname))
789 * Optimistically open the device as a netmap device.
791 if (eth_nm_open((char *)devname))
796 path = format (path, "/sys/bus/pci/devices/%s/driver/unbind%c",
800 * If the device is bound to a driver...
802 if (stat ((const char *)path, &st) == 0)
807 * If the interface is not a virtio...
809 if (!driver_name || strcmp(driver_name, VIRTIO_PCI_NAME))
812 * If it is already bound to driver, don't unbind/bind it.
814 device_path = format (0, "/sys/bus/pci/drivers/%s/%s/device%c",
815 driver_name, devname, 0);
816 if (stat ((const char *)device_path, &st) == 0)
819 vec_free (device_path);
823 * unbind it from the current driver
827 _vec_len (path) -= 1;
828 path = format (path, "%c", 0);
829 error = write_sys_fs ((char *)path, "%s", devname);
836 * DAW-FIXME: The following bind/unbind dance is necessary for the dpdk
837 * virtio poll-mode driver to work.
840 if (driver_name && !strcmp(driver_name, VIRTIO_PCI_NAME))
843 * bind interface to the native kernel module
846 path = format (path, "/sys/bus/pci/drivers/%s/bind%c",
848 error = write_sys_fs ((char *)path, "%s", devname);
853 * unbind interface from the native kernel module
855 _vec_len (path) -= 5;
856 path = format (path, "unbind%c", 0);
857 error = write_sys_fs ((char *)path, "%s", devname);
863 * bind the interface to igb_uio
868 path = format (path, "/sys/bus/pci/drivers/%s/new_id%c", driver_name, 0);
869 error = write_sys_fs ((char *) path, "%s %s", pci_vid, pci_did);
872 path = format (path, "/sys/bus/pci/drivers/%s/bind%c", driver_name, 0);
873 error = write_sys_fs ((char *) path, "%s", devname);
894 get_node_free_hugepages_num (u32 node, u32 page_size)
899 tmp = format (0, "/sys/devices/system/node/node%u/hugepages/hugepages-%ukB/"
900 "free_hugepages%c", node, page_size, 0);
901 fp = fopen ((char *) tmp, "r");
909 vec_validate (buffer, 256-1);
910 if (fgets ((char *)buffer, 256, fp))
913 unformat_init_string (&in, (char *) buffer, strlen ((char *) buffer));
914 unformat(&in, "%u", &pages_avail);
925 static clib_error_t *
926 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
928 clib_error_t * error = 0;
929 dpdk_main_t * dm = &dpdk_main;
930 vlib_thread_main_t * tm = vlib_get_thread_main();
933 u8 * rte_cmd = 0, * ethname = 0;
939 int rxrings, txrings, rxslots, txslots, txburst;
942 unformat_input_t _in;
943 unformat_input_t * in = &_in;
950 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
951 dm->use_virtio_vhost = 1;
953 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
956 if (unformat (input, "no-hugetlb"))
958 vec_add1 (dm->eal_init_args, (u8 *) "no-huge");
962 else if (unformat (input, "enable-tcp-udp-checksum"))
964 dm->buffer_flags_template &=
965 ~(IP_BUFFER_L4_CHECKSUM_CORRECT | IP_BUFFER_L4_CHECKSUM_COMPUTED);
968 else if (unformat (input, "decimal-interface-names"))
969 dm->interface_name_format_decimal = 1;
971 else if (unformat (input, "no-multi-seg"))
972 dm->no_multi_seg = 1;
974 else if (unformat (input, "dev %s", &pci_dev_id))
976 if (dm->eth_if_whitelist)
979 * Don't add duplicate device id's.
981 if (strstr ((char *)dm->eth_if_whitelist, (char *)pci_dev_id))
984 _vec_len (dm->eth_if_whitelist) -= 1; // chomp trailing NULL.
985 dm->eth_if_whitelist = format (dm->eth_if_whitelist, " %s%c",
989 dm->eth_if_whitelist = format (0, "%s%c", pci_dev_id, 0);
993 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
994 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
997 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
999 error = clib_error_return (0, "%s", rv);
1002 }else if (unformat(input, "netmap %s", &nmname)) {
1005 eth_nm_args(nmname, 0, 0, 0, 0, 0);
1007 error = clib_error_return (0, "%s", rv);
1013 else if (unformat (input, "num-mbufs %d", &dm->num_mbufs))
1015 else if (unformat (input, "max-tx-queues %d", &dm->max_tx_queues))
1017 else if (unformat (input, "kni %d", &dm->num_kni))
1019 else if (unformat (input, "uio-driver %s", &dm->uio_driver_name))
1021 else if (unformat (input, "vhost-user-coalesce-frames %d", &dm->vhost_coalesce_frames))
1023 else if (unformat (input, "vhost-user-coalesce-time %f", &dm->vhost_coalesce_time))
1025 else if (unformat (input, "enable-vhost-user"))
1026 dm->use_virtio_vhost = 0;
1027 else if (unformat (input, "rss %d", &dm->use_rss))
1031 else if (unformat(input, #a)) \
1033 if (!strncmp(#a, "no-pci", 6)) \
1035 tmp = format (0, "--%s%c", #a, 0); \
1036 vec_add1 (dm->eal_init_args, tmp); \
1038 foreach_eal_double_hyphen_predicate_arg
1042 else if (unformat(input, #a " %s", &s)) \
1044 if (!strncmp(#a, "huge-dir", 8)) \
1046 else if (!strncmp(#a, "file-prefix", 11)) \
1048 else if (!strncmp(#a, "socket-mem", 10)) \
1049 socket_mem = vec_dup (s); \
1050 tmp = format (0, "--%s%c", #a, 0); \
1051 vec_add1 (dm->eal_init_args, tmp); \
1053 vec_add1 (dm->eal_init_args, s); \
1055 foreach_eal_double_hyphen_arg
1059 else if (unformat(input, #a " %s", &s)) \
1061 tmp = format (0, "-%s%c", #b, 0); \
1062 vec_add1 (dm->eal_init_args, tmp); \
1064 vec_add1 (dm->eal_init_args, s); \
1066 foreach_eal_single_hyphen_arg
1070 else if (unformat(input, #a " %s", &s)) \
1072 tmp = format (0, "-%s%c", #b, 0); \
1073 vec_add1 (dm->eal_init_args, tmp); \
1075 vec_add1 (dm->eal_init_args, s); \
1076 dm->a##_set_manually = 1; \
1078 foreach_eal_single_hyphen_mandatory_arg
1081 else if (unformat(input, "default"))
1086 error = clib_error_return (0, "unknown input `%U'",
1087 format_unformat_error, input);
1092 if (!dm->uio_driver_name)
1093 dm->uio_driver_name = format (0, "igb_uio");
1096 * Use 1G huge pages if available.
1098 if (!no_huge && !huge_dir)
1100 uword * mem_by_socket = hash_create (0, sizeof (uword));
1106 umount(DEFAULT_HUGE_DIR);
1108 /* Process "socket-mem" parameter value */
1109 if (vec_len (socket_mem))
1111 unformat_input_t in;
1112 unformat_init_vector(&in, socket_mem);
1113 unformat(&in, "%U", unformat_socket_mem, &mem_by_socket);
1119 /* check if available enough 1GB pages for each socket */
1120 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, ({
1121 uword * p = hash_get (mem_by_socket, c);
1127 u32 pages_num_1g = mem / 1024;
1128 u32 pages_num_2m = mem / 2;
1131 pages_avail = get_node_free_hugepages_num(c, 1048576);
1132 if (!pages_avail || !(pages_avail >= pages_num_1g))
1135 pages_avail = get_node_free_hugepages_num(c, 2048);
1136 if (!pages_avail || !(pages_avail >= pages_num_2m))
1142 hash_free (mem_by_socket);
1144 rv = mkdir(VPP_RUN_DIR, 0755);
1145 if (rv && errno != EEXIST)
1147 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1148 VPP_RUN_DIR, errno);
1152 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1153 if (rv && errno != EEXIST)
1155 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1156 DEFAULT_HUGE_DIR, errno);
1162 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1166 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1170 return clib_error_return (0, "not enough free huge pages");
1175 error = clib_error_return (0, "mount failed %d", errno);
1179 tmp = format (0, "--huge-dir%c", 0);
1180 vec_add1 (dm->eal_init_args, tmp);
1181 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1182 vec_add1 (dm->eal_init_args, tmp);
1185 tmp = format (0, "--file-prefix%c", 0);
1186 vec_add1 (dm->eal_init_args, tmp);
1187 tmp = format (0, "vpp%c", 0);
1188 vec_add1 (dm->eal_init_args, tmp);
1193 * Blacklist all ethernet interfaces in the linux IP routing tables.
1195 dm->eth_if_blacklist = format (0, "%c", 0);
1196 rte_cmd = format (0, "route --inet --inet6 -n|awk '{print $7}'|sort -u|"
1197 "egrep $(echo $(ls -1d /sys/class/net/*/device|"
1198 "cut -d/ -f5)|sed -s 's/ /|/g')%c", 0);
1199 if ((rte_fp = popen ((const char *)rte_cmd, "r")) == NULL)
1201 error = clib_error_return_unix (0, "Unable to find blacklist ethernet"
1202 " interface(s) in linux routing tables.");
1207 vec_validate (ethname, BUFSIZ);
1208 while (fgets ((char *)ethname, BUFSIZ, rte_fp) != NULL)
1211 u8 * rlnk_cmd = 0, * devname = 0;
1213 ethname[strlen ((char *)ethname) - 1] = 0; // chomp trailing newline.
1215 rlnk_cmd = format (0, "readlink /sys/class/net/%s%c",
1218 if ((rlnk_fp = popen ((const char *)rlnk_cmd, "r")) == NULL)
1220 error = clib_error_return_unix (0, "Unable to read %s link.",
1225 vec_validate (devname, BUFSIZ);
1226 while (fgets ((char *)devname, BUFSIZ, rlnk_fp) != NULL)
1231 * Extract the device PCI ID name from the link. It is the first
1232 * PCI ID searching backwards from the end of the link pathname.
1234 * readlink /sys/class/net/eth0
1235 * ../../devices/pci0000:00/0000:00:0a.0/virtio4/net/eth0
1237 for (pci_id = (char *)((devname + strlen((char *)devname)));
1238 ((u8 *)pci_id > devname) && *pci_id != '.'; pci_id--)
1242 * Verify that the field found is a valid PCI ID.
1244 if ((*(pci_id - 1) == '.') || ((u8 *)(pci_id - 11) < devname) ||
1245 (*(pci_id - 11) != '/') || (*(pci_id - 3) != ':') ||
1246 (*(pci_id - 6) != ':'))
1248 devname[strlen ((char *)devname) - 1] = 0; // chomp trailing newline.
1249 clib_warning ("Unable to extract %s PCI ID (0x%llx \"%s\") "
1250 "from 0x%llx \"%s\"", ethname, pci_id, pci_id,
1258 /* Don't blacklist any interfaces which have been whitelisted.
1260 if (dm->eth_if_whitelist &&
1261 strstr ((char *)dm->eth_if_whitelist, (char *)pci_id))
1264 _vec_len (dm->eth_if_blacklist) -= 1; // chomp trailing NULL.
1265 dm->eth_if_blacklist = format (dm->eth_if_blacklist, " %s%c",
1271 vec_free (rlnk_cmd);
1283 /* I'll bet that -c and -n must be the first and second args... */
1284 if (!dm->coremask_set_manually)
1286 vlib_thread_registration_t * tr;
1287 uword * coremask = 0;
1290 /* main thread core */
1291 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1293 for (i = 0; i < vec_len (tm->registrations); i++)
1295 tr = tm->registrations[i];
1296 coremask = clib_bitmap_or(coremask, tr->coremask);
1299 vec_insert (dm->eal_init_args, 2, 1);
1300 dm->eal_init_args[1] = (u8 *) "-c";
1301 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1302 dm->eal_init_args[2] = tmp;
1303 clib_bitmap_free(coremask);
1306 if (!dm->nchannels_set_manually)
1308 vec_insert (dm->eal_init_args, 2, 3);
1309 dm->eal_init_args[3] = (u8 *) "-n";
1310 tmp = format (0, "%d", dm->nchannels);
1311 dm->eal_init_args[4] = tmp;
1315 * If there are whitelisted devices,
1316 * add the whitelist option & device list to the dpdk arg list...
1318 if (dm->eth_if_whitelist)
1320 unformat_init_string (in, (char *)dm->eth_if_whitelist,
1321 vec_len(dm->eth_if_whitelist) - 1);
1326 * Otherwise add the blacklisted devices to the dpdk arg list.
1330 unformat_init_string (in, (char *)dm->eth_if_blacklist,
1331 vec_len(dm->eth_if_blacklist) - 1);
1335 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
1337 tmp = format (0, fmt, 0);
1338 vec_add1 (dm->eal_init_args, tmp);
1339 unformat (in, "%s", &pci_dev_id);
1340 vec_add1 (dm->eal_init_args, pci_dev_id);
1346 * Bind Virtio pci devices to the igb_uio kernel driver.
1348 error = dpdk_bind_eth_kernel_drivers (vm, "1af4:1000", VIRTIO_PCI_NAME);
1353 * Bind vmxnet3 pci devices to the igb_uio kernel driver.
1355 error = dpdk_bind_eth_kernel_drivers (vm, "15ad:07b0",
1356 (char *) dm->uio_driver_name);
1361 * Bind Intel ethernet pci devices to igb_uio kernel driver.
1363 error = dpdk_bind_eth_kernel_drivers (vm, "8086:",
1364 (char *) dm->uio_driver_name);
1366 * Bind Cisco VIC ethernet pci devices to igb_uio kernel driver.
1368 error = dpdk_bind_eth_kernel_drivers (vm, "1137:0043",
1369 (char *) dm->uio_driver_name);
1372 /* set master-lcore */
1373 tmp = format (0, "--master-lcore%c", 0);
1374 vec_add1 (dm->eal_init_args, tmp);
1375 tmp = format (0, "%u%c", tm->main_lcore, 0);
1376 vec_add1 (dm->eal_init_args, tmp);
1378 /* NULL terminate the "argv" vector, in case of stupidity */
1379 vec_add1 (dm->eal_init_args, 0);
1380 _vec_len(dm->eal_init_args) -= 1;
1382 /* Set up DPDK eal and packet mbuf pool early. */
1384 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1386 rte_set_log_level (log_level);
1390 /* make copy of args as rte_eal_init tends to mess up with arg array */
1391 for (i = 1; i < vec_len(dm->eal_init_args); i++)
1392 dm->eal_init_args_str = format(dm->eal_init_args_str, "%s ",
1393 dm->eal_init_args[i]);
1395 ret = rte_eal_init(vec_len(dm->eal_init_args), (char **) dm->eal_init_args);
1397 /* lazy umount hugepages */
1398 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1401 return clib_error_return (0, "rte_eal_init returned %d", ret);
1403 /* Dump the physical memory layout prior to creating the mbuf_pool */
1404 fprintf(stdout, "DPDK physical memory layout:\n");
1405 rte_dump_physmem_layout(stdout);
1407 /* main thread 1st */
1408 error = vlib_buffer_pool_create(vm, dm->num_mbufs, MBUF_SIZE, rte_socket_id());
1412 for (i = 0; i < RTE_MAX_LCORE; i++)
1414 error = vlib_buffer_pool_create(vm, dm->num_mbufs, MBUF_SIZE,
1415 rte_lcore_to_socket_id(i));
1422 vlib_node_runtime_t * rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
1423 rt->function = dpdk_input_rss;
1429 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1431 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1433 vnet_main_t * vnm = vnet_get_main();
1434 struct rte_eth_link prev_link = xd->link;
1436 u8 hw_flags_chg = 0;
1438 /* only update link state for PMD interfaces */
1439 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1442 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1443 memset(&xd->link, 0, sizeof(xd->link));
1444 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1446 if (LINK_STATE_ELOGS)
1448 vlib_main_t * vm = vlib_get_main();
1449 ELOG_TYPE_DECLARE(e) = {
1451 "update-link-state: sw_if_index %d, admin_up %d,"
1452 "old link_state %d new link_state %d",
1453 .format_args = "i4i1i1i1",
1456 struct { u32 sw_if_index; u8 admin_up;
1457 u8 old_link_state; u8 new_link_state;} *ed;
1458 ed = ELOG_DATA (&vm->elog_main, e);
1459 ed->sw_if_index = xd->vlib_sw_if_index;
1460 ed->admin_up = xd->admin_up;
1461 ed->old_link_state = (u8)
1462 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1463 ed->new_link_state = (u8) xd->link.link_status;
1466 if ((xd->admin_up == 1) &&
1467 ((xd->link.link_status != 0) ^
1468 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1471 hw_flags |= (xd->link.link_status ?
1472 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1475 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1478 switch (xd->link.link_duplex)
1480 case ETH_LINK_HALF_DUPLEX:
1481 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1483 case ETH_LINK_FULL_DUPLEX:
1484 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1490 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1493 switch (xd->link.link_speed)
1495 case ETH_LINK_SPEED_10:
1496 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1498 case ETH_LINK_SPEED_100:
1499 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1501 case ETH_LINK_SPEED_1000:
1502 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1504 case ETH_LINK_SPEED_10000:
1505 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1507 case ETH_LINK_SPEED_40G:
1508 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1513 clib_warning("unknown link speed %d", xd->link.link_speed);
1519 if (LINK_STATE_ELOGS)
1521 vlib_main_t * vm = vlib_get_main();
1523 ELOG_TYPE_DECLARE(e) = {
1524 .format = "update-link-state: sw_if_index %d, new flags %d",
1525 .format_args = "i4i4",
1528 struct { u32 sw_if_index; u32 flags; } *ed;
1529 ed = ELOG_DATA (&vm->elog_main, e);
1530 ed->sw_if_index = xd->vlib_sw_if_index;
1531 ed->flags = hw_flags;
1533 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1538 dpdk_process (vlib_main_t * vm,
1539 vlib_node_runtime_t * rt,
1542 clib_error_t * error;
1543 vnet_main_t * vnm = vnet_get_main();
1544 dpdk_main_t * dm = &dpdk_main;
1545 ethernet_main_t * em = ðernet_main;
1547 vlib_thread_main_t * tm = vlib_get_thread_main();
1551 error = dpdk_lib_init (dm);
1554 * Turn on the input node if we found some devices to drive
1555 * and we're not running worker threads or i/o threads
1558 if (error == 0 && vec_len(dm->devices) > 0)
1560 if (tm->n_vlib_mains == 1)
1561 vlib_node_set_state (vm, dpdk_input_node.index,
1562 VLIB_NODE_STATE_POLLING);
1563 else if (tm->main_thread_is_io_node)
1564 vlib_node_set_state (vm, dpdk_io_input_node.index,
1565 VLIB_NODE_STATE_POLLING);
1566 else if (!dm->have_io_threads)
1567 for (i=0; i < tm->n_vlib_mains; i++)
1568 if (vec_len(dm->devices_by_cpu[i]) > 0)
1569 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1570 VLIB_NODE_STATE_POLLING);
1574 clib_error_report (error);
1576 dpdk_vhost_user_process_init(&vu_state);
1578 dm->io_thread_release = 1;
1580 f64 now = vlib_time_now (vm);
1581 vec_foreach (xd, dm->devices)
1583 dpdk_update_link_state (xd, now);
1586 { // Setup MACs for bond interfaces and their links which was initialized in
1587 // dpdk_port_setup() but needs to be done again here to take effect.
1588 int nports = rte_eth_dev_count();
1590 for (i = 0; i < nports; i++) {
1591 struct rte_eth_dev_info dev_info;
1592 rte_eth_dev_info_get(i, &dev_info);
1593 if (!dev_info.driver_name)
1594 dev_info.driver_name = dev_info.pci_dev->driver->name;
1595 ASSERT(dev_info.driver_name);
1596 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1599 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1601 vnet_hw_interface_t * hi;
1602 ethernet_interface_t * ei;
1603 /* Get MAC of 1st slave link */
1604 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1605 /* Set MAC of bounded interface to that of 1st slave link */
1606 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1607 /* Populate MAC of bonded interface in VPP hw tables */
1608 hi = vnet_get_hw_interface (
1609 vnm, dm->devices[i].vlib_hw_if_index);
1610 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
1611 memcpy (hi->hw_address, addr, 6);
1612 memcpy (ei->address, addr, 6);
1613 /* Add MAC to other slave links */
1616 rte_eth_dev_mac_addr_add(
1617 slink[nlink], (struct ether_addr *)addr, 0);
1628 * check each time through the loop in case intervals are changed
1630 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1631 dm->link_state_poll_interval : dm->stat_poll_interval;
1633 vlib_process_wait_for_event_or_clock (vm, min_wait);
1635 if (dpdk_get_admin_up_down_in_progress())
1636 /* skip the poll if an admin up down is in progress (on any interface) */
1639 vec_foreach (xd, dm->devices)
1641 f64 now = vlib_time_now (vm);
1642 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1643 dpdk_update_counters (xd, now);
1644 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1645 dpdk_update_link_state (xd, now);
1647 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1648 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1653 dpdk_vhost_user_process_cleanup(vu_state);
1658 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1659 .function = dpdk_process,
1660 .type = VLIB_NODE_TYPE_PROCESS,
1661 .name = "dpdk-process",
1662 .process_log2_n_stack_bytes = 17,
1665 int dpdk_set_stat_poll_interval (f64 interval)
1667 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1668 return (VNET_API_ERROR_INVALID_VALUE);
1670 dpdk_main.stat_poll_interval = interval;
1675 int dpdk_set_link_state_poll_interval (f64 interval)
1677 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1678 return (VNET_API_ERROR_INVALID_VALUE);
1680 dpdk_main.link_state_poll_interval = interval;
1686 dpdk_init (vlib_main_t * vm)
1688 dpdk_main_t * dm = &dpdk_main;
1690 clib_error_t * error = 0;
1691 vlib_thread_main_t * tm = vlib_get_thread_main();
1693 /* verify that structs are cacheline aligned */
1694 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1695 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1696 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1697 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1699 /* Add references to DPDK Driver Constructor functions to get the dynamic
1700 * loader to pull in the driver library & run the constructors.
1704 void devinitfn_ ##d(void); \
1705 __attribute__((unused)) void (* volatile pf)(void); \
1706 pf = devinitfn_ ##d; \
1709 #ifdef RTE_LIBRTE_EM_PMD
1713 #ifdef RTE_LIBRTE_IGB_PMD
1717 #ifdef RTE_LIBRTE_IXGBE_PMD
1721 #ifdef RTE_LIBRTE_I40E_PMD
1723 _(rte_i40evf_driver)
1726 #ifdef RTE_LIBRTE_FM10K_PMD
1730 #ifdef RTE_LIBRTE_VIRTIO_PMD
1731 _(rte_virtio_driver)
1734 #ifdef RTE_LIBRTE_VMXNET3_PMD
1735 _(rte_vmxnet3_driver)
1738 #ifdef RTE_LIBRTE_VICE_PMD
1742 #ifdef RTE_LIBRTE_ENIC_PMD
1746 #ifdef RTE_LIBRTE_PMD_AF_PACKET
1747 _(pmd_af_packet_drv)
1750 #ifdef RTE_LIBRTE_CXGBE_PMD
1754 #ifdef RTE_LIBRTE_PMD_BOND
1761 * At the moment, the ThunderX NIC driver doesn't have
1762 * an entry point named "devinitfn_rte_xxx_driver"
1767 __attribute__((unused)) void (* volatile pf)(void); \
1771 #ifdef RTE_LIBRTE_THUNDERVNIC_PMD
1772 _(rte_nicvf_pmd_init)
1777 dm->vnet_main = vnet_get_main();
1779 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1781 return clib_error_return (0, "ethernet-input node AWOL");
1783 dm->ethernet_input_node_index = ei->index;
1786 dm->num_mbufs = dm->num_mbufs ? dm->num_mbufs : NB_MBUF;
1787 vec_add1 (dm->eal_init_args, (u8 *) "vnet");
1789 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1790 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1791 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1793 /* $$$ use n_thread_stacks since it's known-good at this point */
1794 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1796 /* initialize EFD (early fast discard) default settings */
1797 dm->efd.enabled = DPDK_EFD_DISABLED;
1798 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1799 DPDK_NB_RX_DESC_10GE)/100);
1800 dm->efd.consec_full_frames_hi_thresh =
1801 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1803 /* vhost-user coalescence frames defaults */
1804 dm->vhost_coalesce_frames = 32;
1805 dm->vhost_coalesce_time = 1e-3;
1807 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1808 dm->buffer_flags_template =
1809 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1810 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1811 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1813 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1814 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1817 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1823 VLIB_INIT_FUNCTION (dpdk_init);