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 vlib_node_runtime_t * rt;
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 rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
252 rt->function = dpdk_input_multiarch_select();
254 /* find out which cpus will be used for input */
255 p = hash_get_mem (tm->thread_registrations_by_name, "io");
256 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
258 if (!tr || tr->count == 0)
260 /* no io threads, workers doing input */
261 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
262 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
266 dm->have_io_threads = 1;
269 if (tr && tr->count > 0)
271 dm->input_cpu_first_index = tr->first_index;
272 dm->input_cpu_count = tr->count;
275 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
276 CLIB_CACHE_LINE_BYTES);
278 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
279 CLIB_CACHE_LINE_BYTES);
282 if(rte_netmap_probe() < 0)
283 return clib_error_return (0, "rte netmap probe failed");
286 nports = rte_eth_dev_count();
289 clib_warning ("DPDK drivers found no ports...");
293 clib_warning ("DPDK drivers found %d ports...", nports);
296 * All buffers are all allocated from the same rte_mempool.
297 * Thus they all have the same number of data bytes.
299 dm->vlib_buffer_free_list_index =
300 vlib_buffer_get_or_create_free_list (
301 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
303 if (dm->conf->enable_tcp_udp_checksum)
304 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
305 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
307 for (i = 0; i < nports; i++)
311 struct rte_eth_dev_info dev_info;
313 struct rte_eth_link l;
314 dpdk_device_config_t * devconf = 0;
315 vlib_pci_addr_t pci_addr;
318 rte_eth_dev_info_get(i, &dev_info);
319 pci_addr.domain = dev_info.pci_dev->addr.domain;
320 pci_addr.bus = dev_info.pci_dev->addr.bus;
321 pci_addr.slot = dev_info.pci_dev->addr.devid;
322 pci_addr.function = dev_info.pci_dev->addr.function;
323 p = hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
326 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
328 devconf = &dm->conf->default_devconf;
330 /* Create vnet interface */
331 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
332 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
333 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
334 xd->cpu_socket = (i8) rte_eth_dev_socket_id(i);
336 clib_memcpy(&xd->tx_conf, &dev_info.default_txconf,
337 sizeof(struct rte_eth_txconf));
338 if (dm->conf->no_multi_seg)
340 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
341 port_conf_template.rxmode.jumbo_frame = 0;
345 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
346 port_conf_template.rxmode.jumbo_frame = 1;
349 clib_memcpy(&xd->port_conf, &port_conf_template, sizeof(struct rte_eth_conf));
351 xd->tx_q_used = clib_min(dev_info.max_tx_queues, tm->n_vlib_mains);
353 if (devconf->num_tx_queues > 0 && devconf->num_tx_queues < xd->tx_q_used)
354 xd->tx_q_used = clib_min(xd->tx_q_used, devconf->num_tx_queues);
356 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
358 rt->function = dpdk_input_rss_multiarch_select();
362 if (devconf->num_rx_queues > 1 && dev_info.max_rx_queues >= devconf->num_rx_queues)
364 xd->rx_q_used = devconf->num_rx_queues;
365 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
366 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
371 xd->dev_type = VNET_DPDK_DEV_ETH;
373 /* workaround for drivers not setting driver_name */
374 if (!dev_info.driver_name)
375 dev_info.driver_name = dev_info.pci_dev->driver->name;
376 ASSERT(dev_info.driver_name);
381 #define _(s,f) else if (!strcmp(dev_info.driver_name, s)) \
382 xd->pmd = VNET_DPDK_PMD_##f;
388 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
393 case VNET_DPDK_PMD_E1000EM:
394 case VNET_DPDK_PMD_IGB:
395 case VNET_DPDK_PMD_IGBVF:
396 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
400 case VNET_DPDK_PMD_IXGBE:
401 case VNET_DPDK_PMD_IXGBEVF:
402 case VNET_DPDK_PMD_THUNDERX:
403 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
404 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
405 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
409 case VNET_DPDK_PMD_VICE:
410 case VNET_DPDK_PMD_ENIC:
411 rte_eth_link_get_nowait(i, &l);
412 xd->nb_rx_desc = DPDK_NB_RX_DESC_ENIC;
413 if (l.link_speed == 40000)
415 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
416 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
420 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
421 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
425 /* Intel Fortville */
426 case VNET_DPDK_PMD_I40E:
427 case VNET_DPDK_PMD_I40EVF:
428 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
429 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
430 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
432 switch (dev_info.pci_dev->id.device_id) {
433 case I40E_DEV_ID_10G_BASE_T:
434 case I40E_DEV_ID_SFP_XL710:
435 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
437 case I40E_DEV_ID_QSFP_A:
438 case I40E_DEV_ID_QSFP_B:
439 case I40E_DEV_ID_QSFP_C:
440 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
443 rte_eth_link_get_nowait(i, &l);
444 xd->port_type = l.link_speed == 10000 ?
445 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
448 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
452 case VNET_DPDK_PMD_CXGBE:
453 switch (dev_info.pci_dev->id.device_id) {
454 case 0x5410: /* T580-LP-cr */
455 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
456 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
457 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
460 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
461 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
462 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
466 /* Intel Red Rock Canyon */
467 case VNET_DPDK_PMD_FM10K:
468 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
469 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
470 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
474 case VNET_DPDK_PMD_VIRTIO:
475 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
476 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
477 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
481 case VNET_DPDK_PMD_VMXNET3:
482 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
483 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
486 case VNET_DPDK_PMD_AF_PACKET:
487 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
488 xd->af_packet_port_id = af_packet_port_id++;
491 case VNET_DPDK_PMD_BOND:
492 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
496 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
500 if(strncmp(dev_info.driver_name, "vale", 4) == 0
501 || strncmp(dev_info.driver_name, "netmap", 6) == 0)
503 xd->pmd = VNET_DPDK_PMD_NETMAP;
504 xd->port_type = VNET_DPDK_PORT_TYPE_NETMAP;
511 * Ensure default mtu is not > the mtu read from the hardware.
512 * Otherwise rte_eth_dev_configure() will fail and the port will
515 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
518 * This device does not support the platforms's max frame
519 * size. Use it's advertised mru instead.
521 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
525 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
528 * Some platforms do not account for Ethernet FCS (4 bytes) in
529 * MTU calculations. To interop with them increase mru but only
530 * if the device's settings can support it.
532 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
533 xd->port_conf.rxmode.hw_strip_crc)
536 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
537 * stripped by h/w and so will not consume any buffer memory.
539 xd->port_conf.rxmode.max_rx_pkt_len += 4;
543 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
545 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
547 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
549 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
550 xd->port_conf.rxmode.jumbo_frame = 0;
554 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
556 f64 now = vlib_time_now(vm);
558 rnd = (u32) (now * 1e6);
559 rnd = random_u32 (&rnd);
560 clib_memcpy (addr+2, &rnd, sizeof(rnd));
565 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
567 if (xd->tx_q_used < tm->n_vlib_mains)
568 dpdk_device_lock_init(xd);
570 xd->device_index = xd - dm->devices;
571 ASSERT(i == xd->device_index);
572 xd->per_interface_next_index = ~0;
574 /* assign interface to input thread */
575 dpdk_device_and_queue_t * dq;
578 for (q = 0; q < xd->rx_q_used; q++)
580 int cpu = dm->input_cpu_first_index + next_cpu;
581 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
584 * numa node for worker thread handling this queue
585 * needed for taking buffers from the right mempool
587 vec_validate(xd->cpu_socket_id_by_queue, q);
588 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
591 * construct vector of (device,queue) pairs for each worker thread
593 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
594 dq->device = xd->device_index;
598 if (next_cpu == dm->input_cpu_count)
602 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
603 CLIB_CACHE_LINE_BYTES);
604 for (j = 0; j < tm->n_vlib_mains; j++)
606 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
607 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
608 vec_reset_length (xd->tx_vectors[j]);
611 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
612 CLIB_CACHE_LINE_BYTES);
613 for (j = 0; j< xd->rx_q_used; j++)
615 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
616 CLIB_CACHE_LINE_BYTES);
617 vec_reset_length (xd->rx_vectors[j]);
620 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
621 CLIB_CACHE_LINE_BYTES);
623 rv = dpdk_port_setup(dm, xd);
628 /* count the number of descriptors used for this device */
629 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
631 error = ethernet_register_interface
633 dpdk_device_class.index,
635 /* ethernet address */ addr,
636 &xd->vlib_hw_if_index,
641 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
642 xd->vlib_sw_if_index = sw->sw_if_index;
643 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
646 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
647 * driver to dynamically change the mtu. If/when the
648 * VIC firmware gets fixed, then this should be removed.
650 if (xd->pmd == VNET_DPDK_PMD_VICE ||
651 xd->pmd == VNET_DPDK_PMD_ENIC)
654 * Initialize mtu to what has been set by CIMC in the firmware cfg.
656 hi->max_packet_bytes = dev_info.max_rx_pktlen;
658 * remove vlan tag from VIC port to fix VLAN0 issue.
659 * TODO Handle VLAN tagged traffic
662 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
663 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
664 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
667 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
669 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
671 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
672 hi->max_packet_bytes = 1518;
675 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
676 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
678 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
681 #ifdef RTE_LIBRTE_KNI
682 if (dm->conf->num_kni) {
683 clib_warning("Initializing KNI interfaces...");
684 rte_kni_init(dm->conf->num_kni);
685 for (i = 0; i < dm->conf->num_kni; i++)
690 /* Create vnet interface */
691 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
692 xd->dev_type = VNET_DPDK_DEV_KNI;
694 xd->device_index = xd - dm->devices;
695 ASSERT(nports + i == xd->device_index);
696 xd->per_interface_next_index = ~0;
699 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
702 /* assign interface to input thread */
703 dpdk_device_and_queue_t * dq;
704 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
705 dq->device = xd->device_index;
708 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
709 CLIB_CACHE_LINE_BYTES);
710 for (j = 0; j < tm->n_vlib_mains; j++)
712 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
713 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
714 vec_reset_length (xd->tx_vectors[j]);
717 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
718 CLIB_CACHE_LINE_BYTES);
719 for (j = 0; j< xd->rx_q_used; j++)
721 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
722 CLIB_CACHE_LINE_BYTES);
723 vec_reset_length (xd->rx_vectors[j]);
726 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
727 CLIB_CACHE_LINE_BYTES);
729 /* FIXME Set up one TX-queue per worker thread */
732 f64 now = vlib_time_now(vm);
734 rnd = (u32) (now * 1e6);
735 rnd = random_u32 (&rnd);
737 clib_memcpy (addr+2, &rnd, sizeof(rnd));
742 error = ethernet_register_interface
744 dpdk_device_class.index,
746 /* ethernet address */ addr,
747 &xd->vlib_hw_if_index,
753 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
754 xd->vlib_sw_if_index = sw->sw_if_index;
755 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
760 if (nb_desc > dm->conf->num_mbufs)
761 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
762 dm->conf->num_mbufs, nb_desc);
764 /* init next vhost-user if index */
765 dm->next_vu_if_id = 0;
771 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
773 vlib_pci_main_t * pm = &pci_main;
774 clib_error_t * error;
775 vlib_pci_device_t * d;
776 pci_config_header_t * c;
778 int num_whitelisted = vec_len (conf->dev_confs);
780 pool_foreach (d, pm->pci_devs, ({
781 dpdk_device_config_t * devconf = 0;
782 c = &d->config0.header;
783 vec_reset_length (pci_addr);
784 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
786 if (c->device_class != PCI_CLASS_NETWORK_ETHERNET)
791 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
796 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
800 if (c->vendor_id == 0x1af4 && c->device_id == 0x1000)
803 else if (c->vendor_id == 0x15ad && c->device_id == 0x07b0)
805 /* all Intel devices */
806 else if (c->vendor_id == 0x8086)
809 else if (c->vendor_id == 0x1137 && c->device_id == 0x0043)
812 else if (c->vendor_id == 0x1425 && (c->device_id & 0xe000) == 0x4000)
816 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
817 "at PCI address %s\n", (u16) c->vendor_id, (u16) c->device_id,
822 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
828 pool_get (conf->dev_confs, devconf);
829 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
830 devconf - conf->dev_confs);
831 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
833 devconf->is_blacklisted = 1;
834 clib_error_report (error);
840 static clib_error_t *
841 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr, unformat_input_t * input, u8 is_default)
843 clib_error_t * error = 0;
845 dpdk_device_config_t * devconf;
849 devconf = &conf->default_devconf;
853 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
857 pool_get (conf->dev_confs, devconf);
858 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32, devconf - conf->dev_confs);
861 return clib_error_return(0, "duplicate configuration for PCI address %U",
862 format_vlib_pci_addr, &pci_addr);
865 devconf->pci_addr.as_u32 = pci_addr.as_u32;
870 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
872 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
874 if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
878 error = clib_error_return (0, "unknown input `%U'",
879 format_unformat_error, input);
886 static clib_error_t *
887 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
889 clib_error_t * error = 0;
890 dpdk_main_t * dm = &dpdk_main;
891 dpdk_config_main_t * conf = &dpdk_config_main;
892 vlib_thread_main_t * tm = vlib_get_thread_main();
893 dpdk_device_config_t * devconf;
894 vlib_pci_addr_t pci_addr;
895 unformat_input_t sub_input;
897 u8 * rte_cmd = 0, * ethname = 0;
900 int num_whitelisted = 0;
902 int rxrings, txrings, rxslots, txslots, txburst;
911 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
913 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
914 conf->use_virtio_vhost = 1;
916 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
919 if (unformat (input, "no-hugetlb"))
921 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
925 else if (unformat (input, "enable-tcp-udp-checksum"))
926 conf->enable_tcp_udp_checksum = 1;
928 else if (unformat (input, "decimal-interface-names"))
929 conf->interface_name_format_decimal = 1;
931 else if (unformat (input, "no-multi-seg"))
932 conf->no_multi_seg = 1;
934 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
937 error = dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~1, &sub_input, 1);
942 else if (unformat (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
943 unformat_vlib_cli_sub_input, &sub_input))
945 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
952 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
954 error = dpdk_device_config (conf, pci_addr, 0, 0);
963 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
964 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
967 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
969 error = clib_error_return (0, "%s", rv);
972 }else if (unformat(input, "netmap %s", &nmname)) {
975 eth_nm_args(nmname, 0, 0, 0, 0, 0);
977 error = clib_error_return (0, "%s", rv);
983 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
985 else if (unformat (input, "kni %d", &conf->num_kni))
987 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
989 else if (unformat (input, "socket-mem %s", &socket_mem))
991 else if (unformat (input, "vhost-user-coalesce-frames %d", &conf->vhost_coalesce_frames))
993 else if (unformat (input, "vhost-user-coalesce-time %f", &conf->vhost_coalesce_time))
995 else if (unformat (input, "enable-vhost-user"))
996 conf->use_virtio_vhost = 0;
997 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep))
1001 else if (unformat(input, #a)) \
1003 if (!strncmp(#a, "no-pci", 6)) \
1005 tmp = format (0, "--%s%c", #a, 0); \
1006 vec_add1 (conf->eal_init_args, tmp); \
1008 foreach_eal_double_hyphen_predicate_arg
1012 else if (unformat(input, #a " %s", &s)) \
1014 if (!strncmp(#a, "huge-dir", 8)) \
1016 else if (!strncmp(#a, "file-prefix", 11)) \
1018 tmp = format (0, "--%s%c", #a, 0); \
1019 vec_add1 (conf->eal_init_args, tmp); \
1021 vec_add1 (conf->eal_init_args, s); \
1023 foreach_eal_double_hyphen_arg
1027 else if (unformat(input, #a " %s", &s)) \
1029 tmp = format (0, "-%s%c", #b, 0); \
1030 vec_add1 (conf->eal_init_args, tmp); \
1032 vec_add1 (conf->eal_init_args, s); \
1034 foreach_eal_single_hyphen_arg
1038 else if (unformat(input, #a " %s", &s)) \
1040 tmp = format (0, "-%s%c", #b, 0); \
1041 vec_add1 (conf->eal_init_args, tmp); \
1043 vec_add1 (conf->eal_init_args, s); \
1044 conf->a##_set_manually = 1; \
1046 foreach_eal_single_hyphen_mandatory_arg
1049 else if (unformat(input, "default"))
1054 error = clib_error_return (0, "unknown input `%U'",
1055 format_unformat_error, input);
1060 if (!conf->uio_driver_name)
1061 conf->uio_driver_name = format (0, "igb_uio%c", 0);
1064 * Use 1G huge pages if available.
1066 if (!no_huge && !huge_dir)
1068 u32 x, * mem_by_socket = 0;
1072 u8 less_than_1g = 1;
1075 umount(DEFAULT_HUGE_DIR);
1077 /* Process "socket-mem" parameter value */
1078 if (vec_len (socket_mem))
1080 unformat_input_t in;
1081 unformat_init_vector(&in, socket_mem);
1082 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1084 if (unformat (&in, "%u,", &x))
1086 else if (unformat (&in, "%u", &x))
1088 else if (unformat (&in, ","))
1093 vec_add1(mem_by_socket, x);
1098 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1104 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1106 vec_validate(mem_by_socket, c);
1107 mem_by_socket[c] = 512; /* default per-socket mem */
1112 /* check if available enough 1GB pages for each socket */
1113 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1115 u32 pages_avail, page_size, mem;
1118 char * numa_path = "/sys/devices/system/node/node%u/";
1119 char * nonnuma_path = "/sys/kernel/mm/";
1120 char * suffix = "hugepages/hugepages-%ukB/free_hugepages%c";
1122 struct stat sb_numa, sb_nonnuma;
1124 p = format(p, numa_path, c);
1125 stat(numa_path, &sb_numa);
1126 stat(nonnuma_path, &sb_nonnuma);
1128 if (S_ISDIR(sb_numa.st_mode)) {
1129 path = (char*)format((u8*)path, "%s%s", p, suffix);
1130 } else if (S_ISDIR(sb_nonnuma.st_mode)) {
1131 path = (char*)format((u8*)path, "%s%s", nonnuma_path, suffix);
1139 vec_validate(mem_by_socket, c);
1140 mem = mem_by_socket[c];
1144 s = format (s, path, page_size * 1024, 0);
1145 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1146 vec_reset_length (s);
1148 if (page_size * pages_avail < mem)
1153 s = format (s, path, page_size * 1024, 0);
1154 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1155 vec_reset_length (s);
1157 if (page_size * pages_avail < mem)
1164 _vec_len (mem_by_socket) = c + 1;
1166 /* regenerate socket_mem string */
1167 vec_foreach_index (x, mem_by_socket)
1168 socket_mem = format (socket_mem, "%s%u",
1169 socket_mem ? "," : "",
1171 socket_mem = format (socket_mem, "%c", 0);
1173 vec_free (mem_by_socket);
1175 rv = mkdir(VPP_RUN_DIR, 0755);
1176 if (rv && errno != EEXIST)
1178 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1179 VPP_RUN_DIR, errno);
1183 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1184 if (rv && errno != EEXIST)
1186 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1187 DEFAULT_HUGE_DIR, errno);
1191 if (use_1g && !(less_than_1g && use_2m))
1193 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1197 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1201 return clib_error_return (0, "not enough free huge pages");
1206 error = clib_error_return (0, "mount failed %d", errno);
1210 tmp = format (0, "--huge-dir%c", 0);
1211 vec_add1 (conf->eal_init_args, tmp);
1212 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1213 vec_add1 (conf->eal_init_args, tmp);
1216 tmp = format (0, "--file-prefix%c", 0);
1217 vec_add1 (conf->eal_init_args, tmp);
1218 tmp = format (0, "vpp%c", 0);
1219 vec_add1 (conf->eal_init_args, tmp);
1229 /* I'll bet that -c and -n must be the first and second args... */
1230 if (!conf->coremask_set_manually)
1232 vlib_thread_registration_t * tr;
1233 uword * coremask = 0;
1236 /* main thread core */
1237 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1239 for (i = 0; i < vec_len (tm->registrations); i++)
1241 tr = tm->registrations[i];
1242 coremask = clib_bitmap_or(coremask, tr->coremask);
1245 vec_insert (conf->eal_init_args, 2, 1);
1246 conf->eal_init_args[1] = (u8 *) "-c";
1247 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1248 conf->eal_init_args[2] = tmp;
1249 clib_bitmap_free(coremask);
1252 if (!conf->nchannels_set_manually)
1254 vec_insert (conf->eal_init_args, 2, 3);
1255 conf->eal_init_args[3] = (u8 *) "-n";
1256 tmp = format (0, "%d", conf->nchannels);
1257 conf->eal_init_args[4] = tmp;
1260 if (no_pci == 0 && geteuid() == 0)
1261 dpdk_bind_devices_to_uio(conf);
1264 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1265 devconf->x = conf->default_devconf.x ;
1267 pool_foreach (devconf, conf->dev_confs, ({
1269 /* default per-device config items */
1270 foreach_dpdk_device_config_item
1272 /* add DPDK EAL whitelist/blacklist entry */
1273 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1275 tmp = format (0, "-w%c", 0);
1276 vec_add1 (conf->eal_init_args, tmp);
1277 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr);
1278 vec_add1 (conf->eal_init_args, tmp);
1280 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1282 tmp = format (0, "-b%c", 0);
1283 vec_add1 (conf->eal_init_args, tmp);
1284 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr);
1285 vec_add1 (conf->eal_init_args, tmp);
1291 /* set master-lcore */
1292 tmp = format (0, "--master-lcore%c", 0);
1293 vec_add1 (conf->eal_init_args, tmp);
1294 tmp = format (0, "%u%c", tm->main_lcore, 0);
1295 vec_add1 (conf->eal_init_args, tmp);
1297 /* set socket-mem */
1298 tmp = format (0, "--socket-mem%c", 0);
1299 vec_add1 (conf->eal_init_args, tmp);
1300 tmp = format (0, "%s%c", socket_mem, 0);
1301 vec_add1 (conf->eal_init_args, tmp);
1303 /* NULL terminate the "argv" vector, in case of stupidity */
1304 vec_add1 (conf->eal_init_args, 0);
1305 _vec_len(conf->eal_init_args) -= 1;
1307 /* Set up DPDK eal and packet mbuf pool early. */
1309 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1311 rte_set_log_level (log_level);
1313 vm = vlib_get_main ();
1315 /* make copy of args as rte_eal_init tends to mess up with arg array */
1316 for (i = 1; i < vec_len(conf->eal_init_args); i++)
1317 conf->eal_init_args_str = format(conf->eal_init_args_str, "%s ",
1318 conf->eal_init_args[i]);
1320 ret = rte_eal_init(vec_len(conf->eal_init_args), (char **) conf->eal_init_args);
1322 /* lazy umount hugepages */
1323 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1326 return clib_error_return (0, "rte_eal_init returned %d", ret);
1328 /* Dump the physical memory layout prior to creating the mbuf_pool */
1329 fprintf(stdout, "DPDK physical memory layout:\n");
1330 rte_dump_physmem_layout(stdout);
1332 /* main thread 1st */
1333 error = vlib_buffer_pool_create(vm, conf->num_mbufs, rte_socket_id());
1337 for (i = 0; i < RTE_MAX_LCORE; i++)
1339 error = vlib_buffer_pool_create(vm, conf->num_mbufs,
1340 rte_lcore_to_socket_id(i));
1349 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1351 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1353 vnet_main_t * vnm = vnet_get_main();
1354 struct rte_eth_link prev_link = xd->link;
1356 u8 hw_flags_chg = 0;
1358 /* only update link state for PMD interfaces */
1359 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1362 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1363 memset(&xd->link, 0, sizeof(xd->link));
1364 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1366 if (LINK_STATE_ELOGS)
1368 vlib_main_t * vm = vlib_get_main();
1369 ELOG_TYPE_DECLARE(e) = {
1371 "update-link-state: sw_if_index %d, admin_up %d,"
1372 "old link_state %d new link_state %d",
1373 .format_args = "i4i1i1i1",
1376 struct { u32 sw_if_index; u8 admin_up;
1377 u8 old_link_state; u8 new_link_state;} *ed;
1378 ed = ELOG_DATA (&vm->elog_main, e);
1379 ed->sw_if_index = xd->vlib_sw_if_index;
1380 ed->admin_up = xd->admin_up;
1381 ed->old_link_state = (u8)
1382 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1383 ed->new_link_state = (u8) xd->link.link_status;
1386 if ((xd->admin_up == 1) &&
1387 ((xd->link.link_status != 0) ^
1388 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1391 hw_flags |= (xd->link.link_status ?
1392 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1395 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1398 switch (xd->link.link_duplex)
1400 case ETH_LINK_HALF_DUPLEX:
1401 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1403 case ETH_LINK_FULL_DUPLEX:
1404 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1410 #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
1411 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1414 switch (xd->link.link_speed)
1416 case ETH_SPEED_NUM_10M:
1417 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1419 case ETH_SPEED_NUM_100M:
1420 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1422 case ETH_SPEED_NUM_1G:
1423 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1425 case ETH_SPEED_NUM_10G:
1426 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1428 case ETH_SPEED_NUM_40G:
1429 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1434 clib_warning("unknown link speed %d", xd->link.link_speed);
1439 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1442 switch (xd->link.link_speed)
1444 case ETH_LINK_SPEED_10:
1445 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1447 case ETH_LINK_SPEED_100:
1448 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1450 case ETH_LINK_SPEED_1000:
1451 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1453 case ETH_LINK_SPEED_10000:
1454 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1456 case ETH_LINK_SPEED_40G:
1457 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1462 clib_warning("unknown link speed %d", xd->link.link_speed);
1469 if (LINK_STATE_ELOGS)
1471 vlib_main_t * vm = vlib_get_main();
1473 ELOG_TYPE_DECLARE(e) = {
1474 .format = "update-link-state: sw_if_index %d, new flags %d",
1475 .format_args = "i4i4",
1478 struct { u32 sw_if_index; u32 flags; } *ed;
1479 ed = ELOG_DATA (&vm->elog_main, e);
1480 ed->sw_if_index = xd->vlib_sw_if_index;
1481 ed->flags = hw_flags;
1483 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1488 dpdk_process (vlib_main_t * vm,
1489 vlib_node_runtime_t * rt,
1492 clib_error_t * error;
1493 vnet_main_t * vnm = vnet_get_main();
1494 dpdk_main_t * dm = &dpdk_main;
1495 ethernet_main_t * em = ðernet_main;
1497 vlib_thread_main_t * tm = vlib_get_thread_main();
1501 error = dpdk_lib_init (dm);
1504 * Turn on the input node if we found some devices to drive
1505 * and we're not running worker threads or i/o threads
1508 if (error == 0 && vec_len(dm->devices) > 0)
1510 if (tm->n_vlib_mains == 1)
1511 vlib_node_set_state (vm, dpdk_input_node.index,
1512 VLIB_NODE_STATE_POLLING);
1513 else if (tm->main_thread_is_io_node)
1514 vlib_node_set_state (vm, dpdk_io_input_node.index,
1515 VLIB_NODE_STATE_POLLING);
1516 else if (!dm->have_io_threads)
1517 for (i=0; i < tm->n_vlib_mains; i++)
1518 if (vec_len(dm->devices_by_cpu[i]) > 0)
1519 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1520 VLIB_NODE_STATE_POLLING);
1524 clib_error_report (error);
1526 dpdk_vhost_user_process_init(&vu_state);
1528 dm->io_thread_release = 1;
1530 f64 now = vlib_time_now (vm);
1531 vec_foreach (xd, dm->devices)
1533 dpdk_update_link_state (xd, now);
1536 { // Extra set up for bond interfaces:
1537 // 1. Setup MACs for bond interfaces and their slave links which was set
1538 // in dpdk_port_setup() but needs to be done again here to take effect.
1539 // 2. Set max L3 packet size of each bond interface to the lowerst value of
1541 // 3. Set up info for bond interface related CLI support.
1542 int nports = rte_eth_dev_count();
1544 for (i = 0; i < nports; i++) {
1545 struct rte_eth_dev_info dev_info;
1546 rte_eth_dev_info_get(i, &dev_info);
1547 if (!dev_info.driver_name)
1548 dev_info.driver_name = dev_info.pci_dev->driver->name;
1549 ASSERT(dev_info.driver_name);
1550 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1553 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1555 vnet_hw_interface_t * bhi;
1556 ethernet_interface_t * bei;
1557 /* Get MAC of 1st slave link */
1558 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1559 /* Set MAC of bounded interface to that of 1st slave link */
1560 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1561 /* Populate MAC of bonded interface in VPP hw tables */
1562 bhi = vnet_get_hw_interface(
1563 vnm, dm->devices[i].vlib_hw_if_index);
1564 bei = pool_elt_at_index(em->interfaces, bhi->hw_instance);
1565 clib_memcpy(bhi->hw_address, addr, 6);
1566 clib_memcpy(bei->address, addr, 6);
1567 /* Init l3 packet size allowed on bonded interface */
1568 bhi->max_l3_packet_bytes[VLIB_RX] =
1569 bhi->max_l3_packet_bytes[VLIB_TX] =
1570 ETHERNET_MAX_PACKET_BYTES - sizeof(ethernet_header_t);
1571 while (nlink >= 1) { /* for all slave links */
1572 int slave = slink[--nlink];
1573 dpdk_device_t * sdev = &dm->devices[slave];
1574 vnet_hw_interface_t * shi;
1575 vnet_sw_interface_t * ssi;
1576 /* Add MAC to all slave links except the first one */
1577 if (nlink) rte_eth_dev_mac_addr_add(
1578 slave, (struct ether_addr *)addr, 0);
1579 /* Set slaves bitmap for bonded interface */
1580 bhi->bond_info = clib_bitmap_set(
1581 bhi->bond_info, sdev->vlib_hw_if_index, 1);
1582 /* Set slave link flags on slave interface */
1583 shi = vnet_get_hw_interface(vnm, sdev->vlib_hw_if_index);
1584 ssi = vnet_get_sw_interface(vnm, sdev->vlib_sw_if_index);
1585 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1586 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1587 /* Set l3 packet size allowed as the lowest of slave */
1588 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1589 shi->max_l3_packet_bytes[VLIB_RX])
1590 bhi->max_l3_packet_bytes[VLIB_RX] =
1591 bhi->max_l3_packet_bytes[VLIB_TX] =
1592 shi->max_l3_packet_bytes[VLIB_RX];
1603 * check each time through the loop in case intervals are changed
1605 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1606 dm->link_state_poll_interval : dm->stat_poll_interval;
1608 vlib_process_wait_for_event_or_clock (vm, min_wait);
1610 if (dpdk_get_admin_up_down_in_progress())
1611 /* skip the poll if an admin up down is in progress (on any interface) */
1614 vec_foreach (xd, dm->devices)
1616 f64 now = vlib_time_now (vm);
1617 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1618 dpdk_update_counters (xd, now);
1619 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1620 dpdk_update_link_state (xd, now);
1622 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1623 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1628 dpdk_vhost_user_process_cleanup(vu_state);
1633 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1634 .function = dpdk_process,
1635 .type = VLIB_NODE_TYPE_PROCESS,
1636 .name = "dpdk-process",
1637 .process_log2_n_stack_bytes = 17,
1640 int dpdk_set_stat_poll_interval (f64 interval)
1642 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1643 return (VNET_API_ERROR_INVALID_VALUE);
1645 dpdk_main.stat_poll_interval = interval;
1650 int dpdk_set_link_state_poll_interval (f64 interval)
1652 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1653 return (VNET_API_ERROR_INVALID_VALUE);
1655 dpdk_main.link_state_poll_interval = interval;
1661 dpdk_init (vlib_main_t * vm)
1663 dpdk_main_t * dm = &dpdk_main;
1665 clib_error_t * error = 0;
1666 vlib_thread_main_t * tm = vlib_get_thread_main();
1668 /* verify that structs are cacheline aligned */
1669 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1670 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1671 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1672 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1675 dm->vnet_main = vnet_get_main();
1676 dm->conf = &dpdk_config_main;
1678 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1680 return clib_error_return (0, "ethernet-input node AWOL");
1682 dm->ethernet_input_node_index = ei->index;
1684 dm->conf->nchannels = 4;
1685 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1686 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1688 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1689 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1690 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1692 /* $$$ use n_thread_stacks since it's known-good at this point */
1693 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1695 /* initialize EFD (early fast discard) default settings */
1696 dm->efd.enabled = DPDK_EFD_DISABLED;
1697 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1698 DPDK_NB_RX_DESC_10GE)/100);
1699 dm->efd.consec_full_frames_hi_thresh =
1700 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1702 /* vhost-user coalescence frames defaults */
1703 dm->conf->vhost_coalesce_frames = 32;
1704 dm->conf->vhost_coalesce_time = 1e-3;
1706 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1707 dm->buffer_flags_template =
1708 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1709 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1710 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1712 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1713 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1716 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1722 VLIB_INIT_FUNCTION (dpdk_init);