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, "workers");
256 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
258 if (tr && tr->count > 0)
260 dm->input_cpu_first_index = tr->first_index;
261 dm->input_cpu_count = tr->count;
264 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
265 CLIB_CACHE_LINE_BYTES);
267 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
268 CLIB_CACHE_LINE_BYTES);
271 if(rte_netmap_probe() < 0)
272 return clib_error_return (0, "rte netmap probe failed");
275 nports = rte_eth_dev_count();
278 clib_warning ("DPDK drivers found no ports...");
282 clib_warning ("DPDK drivers found %d ports...", nports);
285 * All buffers are all allocated from the same rte_mempool.
286 * Thus they all have the same number of data bytes.
288 dm->vlib_buffer_free_list_index =
289 vlib_buffer_get_or_create_free_list (
290 vm, VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, "dpdk rx");
292 if (dm->conf->enable_tcp_udp_checksum)
293 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
294 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
296 for (i = 0; i < nports; i++)
300 struct rte_eth_dev_info dev_info;
302 struct rte_eth_link l;
303 dpdk_device_config_t * devconf = 0;
304 vlib_pci_addr_t pci_addr;
307 rte_eth_dev_info_get(i, &dev_info);
308 if (dev_info.pci_dev) /* bonded interface has no pci info */
310 pci_addr.domain = dev_info.pci_dev->addr.domain;
311 pci_addr.bus = dev_info.pci_dev->addr.bus;
312 pci_addr.slot = dev_info.pci_dev->addr.devid;
313 pci_addr.function = dev_info.pci_dev->addr.function;
314 p = hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
318 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
320 devconf = &dm->conf->default_devconf;
322 /* Create vnet interface */
323 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
324 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
325 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
326 xd->cpu_socket = (i8) rte_eth_dev_socket_id(i);
328 clib_memcpy(&xd->tx_conf, &dev_info.default_txconf,
329 sizeof(struct rte_eth_txconf));
330 if (dm->conf->no_multi_seg)
332 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
333 port_conf_template.rxmode.jumbo_frame = 0;
337 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
338 port_conf_template.rxmode.jumbo_frame = 1;
341 clib_memcpy(&xd->port_conf, &port_conf_template, sizeof(struct rte_eth_conf));
343 xd->tx_q_used = clib_min(dev_info.max_tx_queues, tm->n_vlib_mains);
345 if (devconf->num_tx_queues > 0 && devconf->num_tx_queues < xd->tx_q_used)
346 xd->tx_q_used = clib_min(xd->tx_q_used, devconf->num_tx_queues);
348 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
350 rt->function = dpdk_input_rss_multiarch_select();
354 if (devconf->num_rx_queues > 1 && dev_info.max_rx_queues >= devconf->num_rx_queues)
356 xd->rx_q_used = devconf->num_rx_queues;
357 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
358 if (devconf->rss_fn == 0)
359 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
361 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn;
366 xd->dev_type = VNET_DPDK_DEV_ETH;
368 /* workaround for drivers not setting driver_name */
369 if ((!dev_info.driver_name) && (dev_info.pci_dev))
370 dev_info.driver_name = dev_info.pci_dev->driver->name;
371 ASSERT(dev_info.driver_name);
376 #define _(s,f) else if (!strcmp(dev_info.driver_name, s)) \
377 xd->pmd = VNET_DPDK_PMD_##f;
383 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
388 case VNET_DPDK_PMD_E1000EM:
389 case VNET_DPDK_PMD_IGB:
390 case VNET_DPDK_PMD_IGBVF:
391 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
395 case VNET_DPDK_PMD_IXGBE:
396 case VNET_DPDK_PMD_IXGBEVF:
397 case VNET_DPDK_PMD_THUNDERX:
398 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
399 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
400 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
404 case VNET_DPDK_PMD_VICE:
405 case VNET_DPDK_PMD_ENIC:
406 rte_eth_link_get_nowait(i, &l);
407 xd->nb_rx_desc = DPDK_NB_RX_DESC_ENIC;
408 if (l.link_speed == 40000)
410 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
411 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
415 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
416 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
420 /* Intel Fortville */
421 case VNET_DPDK_PMD_I40E:
422 case VNET_DPDK_PMD_I40EVF:
423 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
424 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
425 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
427 switch (dev_info.pci_dev->id.device_id) {
428 case I40E_DEV_ID_10G_BASE_T:
429 case I40E_DEV_ID_SFP_XL710:
430 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
432 case I40E_DEV_ID_QSFP_A:
433 case I40E_DEV_ID_QSFP_B:
434 case I40E_DEV_ID_QSFP_C:
435 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
438 rte_eth_link_get_nowait(i, &l);
439 xd->port_type = l.link_speed == 10000 ?
440 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
443 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
447 case VNET_DPDK_PMD_CXGBE:
448 switch (dev_info.pci_dev->id.device_id) {
449 case 0x5410: /* T580-LP-cr */
450 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
451 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
452 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
455 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
456 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
457 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
461 /* Intel Red Rock Canyon */
462 case VNET_DPDK_PMD_FM10K:
463 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
464 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
465 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
469 case VNET_DPDK_PMD_VIRTIO:
470 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
471 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
472 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
476 case VNET_DPDK_PMD_VMXNET3:
477 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
478 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
481 case VNET_DPDK_PMD_AF_PACKET:
482 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
483 xd->af_packet_port_id = af_packet_port_id++;
486 case VNET_DPDK_PMD_BOND:
487 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
491 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
495 if(strncmp(dev_info.driver_name, "vale", 4) == 0
496 || strncmp(dev_info.driver_name, "netmap", 6) == 0)
498 xd->pmd = VNET_DPDK_PMD_NETMAP;
499 xd->port_type = VNET_DPDK_PORT_TYPE_NETMAP;
502 if (devconf->num_rx_desc)
503 xd->nb_rx_desc = devconf->num_rx_desc;
505 if (devconf->num_tx_desc)
506 xd->nb_tx_desc = devconf->num_tx_desc;
510 * Ensure default mtu is not > the mtu read from the hardware.
511 * Otherwise rte_eth_dev_configure() will fail and the port will
514 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
517 * This device does not support the platforms's max frame
518 * size. Use it's advertised mru instead.
520 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
524 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
527 * Some platforms do not account for Ethernet FCS (4 bytes) in
528 * MTU calculations. To interop with them increase mru but only
529 * if the device's settings can support it.
531 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
532 xd->port_conf.rxmode.hw_strip_crc)
535 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
536 * stripped by h/w and so will not consume any buffer memory.
538 xd->port_conf.rxmode.max_rx_pkt_len += 4;
542 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
544 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
546 if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
548 xd->port_conf.rxmode.max_rx_pkt_len = 1518;
549 xd->port_conf.rxmode.jumbo_frame = 0;
553 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
555 f64 now = vlib_time_now(vm);
557 rnd = (u32) (now * 1e6);
558 rnd = random_u32 (&rnd);
559 clib_memcpy (addr+2, &rnd, sizeof(rnd));
564 rte_eth_macaddr_get(i,(struct ether_addr *)addr);
566 if (xd->tx_q_used < tm->n_vlib_mains)
567 dpdk_device_lock_init(xd);
569 xd->device_index = xd - dm->devices;
570 ASSERT(i == xd->device_index);
571 xd->per_interface_next_index = ~0;
573 /* assign interface to input thread */
574 dpdk_device_and_queue_t * dq;
577 if (devconf->workers)
581 clib_bitmap_foreach (i, devconf->workers, ({
582 int cpu = dm->input_cpu_first_index + i;
583 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
584 vec_validate(xd->cpu_socket_id_by_queue, q);
585 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
586 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
587 dq->device = xd->device_index;
592 for (q = 0; q < xd->rx_q_used; q++)
594 int cpu = dm->input_cpu_first_index + next_cpu;
595 unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
598 * numa node for worker thread handling this queue
599 * needed for taking buffers from the right mempool
601 vec_validate(xd->cpu_socket_id_by_queue, q);
602 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
605 * construct vector of (device,queue) pairs for each worker thread
607 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
608 dq->device = xd->device_index;
612 if (next_cpu == dm->input_cpu_count)
616 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
617 CLIB_CACHE_LINE_BYTES);
618 for (j = 0; j < tm->n_vlib_mains; j++)
620 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
621 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
622 vec_reset_length (xd->tx_vectors[j]);
625 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
626 CLIB_CACHE_LINE_BYTES);
627 for (j = 0; j< xd->rx_q_used; j++)
629 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
630 CLIB_CACHE_LINE_BYTES);
631 vec_reset_length (xd->rx_vectors[j]);
634 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
635 CLIB_CACHE_LINE_BYTES);
637 rv = dpdk_port_setup(dm, xd);
642 /* count the number of descriptors used for this device */
643 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
645 error = ethernet_register_interface
647 dpdk_device_class.index,
649 /* ethernet address */ addr,
650 &xd->vlib_hw_if_index,
655 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
656 xd->vlib_sw_if_index = sw->sw_if_index;
657 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
660 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
661 * driver to dynamically change the mtu. If/when the
662 * VIC firmware gets fixed, then this should be removed.
664 if (xd->pmd == VNET_DPDK_PMD_VICE ||
665 xd->pmd == VNET_DPDK_PMD_ENIC)
668 * Initialize mtu to what has been set by CIMC in the firmware cfg.
670 hi->max_packet_bytes = dev_info.max_rx_pktlen;
672 * remove vlan tag from VIC port to fix VLAN0 issue.
673 * TODO Handle VLAN tagged traffic
676 vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
677 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
678 rte_eth_dev_set_vlan_offload(xd->device_index, vlan_off);
681 #if RTE_VERSION < RTE_VERSION_NUM(16, 4, 0, 0)
683 * Older VMXNET3 driver doesn't support jumbo / multi-buffer pkts
685 else if (xd->pmd == VNET_DPDK_PMD_VMXNET3)
686 hi->max_packet_bytes = 1518;
689 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
690 xd->port_conf.rxmode.max_rx_pkt_len - sizeof(ethernet_header_t);
692 rte_eth_dev_set_mtu(xd->device_index, hi->max_packet_bytes);
695 #ifdef RTE_LIBRTE_KNI
696 if (dm->conf->num_kni) {
697 clib_warning("Initializing KNI interfaces...");
698 rte_kni_init(dm->conf->num_kni);
699 for (i = 0; i < dm->conf->num_kni; i++)
704 /* Create vnet interface */
705 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
706 xd->dev_type = VNET_DPDK_DEV_KNI;
708 xd->device_index = xd - dm->devices;
709 ASSERT(nports + i == xd->device_index);
710 xd->per_interface_next_index = ~0;
713 hash_set (dm->dpdk_device_by_kni_port_id, i, xd - dm->devices);
716 /* assign interface to input thread */
717 dpdk_device_and_queue_t * dq;
718 vec_add2(dm->devices_by_cpu[dm->input_cpu_first_index], dq, 1);
719 dq->device = xd->device_index;
722 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
723 CLIB_CACHE_LINE_BYTES);
724 for (j = 0; j < tm->n_vlib_mains; j++)
726 vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
727 sizeof(tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
728 vec_reset_length (xd->tx_vectors[j]);
731 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
732 CLIB_CACHE_LINE_BYTES);
733 for (j = 0; j< xd->rx_q_used; j++)
735 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE-1,
736 CLIB_CACHE_LINE_BYTES);
737 vec_reset_length (xd->rx_vectors[j]);
740 vec_validate_aligned (xd->frames, tm->n_vlib_mains,
741 CLIB_CACHE_LINE_BYTES);
743 /* FIXME Set up one TX-queue per worker thread */
746 f64 now = vlib_time_now(vm);
748 rnd = (u32) (now * 1e6);
749 rnd = random_u32 (&rnd);
751 clib_memcpy (addr+2, &rnd, sizeof(rnd));
756 error = ethernet_register_interface
758 dpdk_device_class.index,
760 /* ethernet address */ addr,
761 &xd->vlib_hw_if_index,
767 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
768 xd->vlib_sw_if_index = sw->sw_if_index;
769 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
774 if (nb_desc > dm->conf->num_mbufs)
775 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
776 dm->conf->num_mbufs, nb_desc);
778 /* init next vhost-user if index */
779 dm->next_vu_if_id = 0;
785 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
787 vlib_pci_main_t * pm = &pci_main;
788 clib_error_t * error;
789 vlib_pci_device_t * d;
790 pci_config_header_t * c;
792 int num_whitelisted = vec_len (conf->dev_confs);
794 pool_foreach (d, pm->pci_devs, ({
795 dpdk_device_config_t * devconf = 0;
796 c = &d->config0.header;
797 vec_reset_length (pci_addr);
798 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
800 if (c->device_class != PCI_CLASS_NETWORK_ETHERNET)
805 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
810 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
814 if (c->vendor_id == 0x1af4 && c->device_id == 0x1000)
817 else if (c->vendor_id == 0x15ad && c->device_id == 0x07b0)
819 /* all Intel devices */
820 else if (c->vendor_id == 0x8086)
823 else if (c->vendor_id == 0x1137 && c->device_id == 0x0043)
826 else if (c->vendor_id == 0x1425 && (c->device_id & 0xe000) == 0x4000)
830 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
831 "at PCI address %s\n", (u16) c->vendor_id, (u16) c->device_id,
836 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
842 pool_get (conf->dev_confs, devconf);
843 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
844 devconf - conf->dev_confs);
845 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
847 devconf->is_blacklisted = 1;
848 clib_error_report (error);
854 static clib_error_t *
855 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr, unformat_input_t * input, u8 is_default)
857 clib_error_t * error = 0;
859 dpdk_device_config_t * devconf;
860 unformat_input_t sub_input;
864 devconf = &conf->default_devconf;
868 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
872 pool_get (conf->dev_confs, devconf);
873 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32, devconf - conf->dev_confs);
876 return clib_error_return(0, "duplicate configuration for PCI address %U",
877 format_vlib_pci_addr, &pci_addr);
880 devconf->pci_addr.as_u32 = pci_addr.as_u32;
885 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
887 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
889 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
891 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
893 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
895 else if (unformat (input, "workers %U", unformat_bitmap_list,
898 else if (unformat (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
900 error = unformat_rss_fn(&sub_input, &devconf->rss_fn);
906 error = clib_error_return (0, "unknown input `%U'",
907 format_unformat_error, input);
915 if (devconf->workers && devconf->num_rx_queues == 0)
916 devconf->num_rx_queues = clib_bitmap_count_set_bits(devconf->workers);
917 else if (devconf->workers &&
918 clib_bitmap_count_set_bits(devconf->workers) != devconf->num_rx_queues)
919 error = clib_error_return (0, "%U: number of worker threadds must be "
920 "equal to number of rx queues",
921 format_vlib_pci_addr, &pci_addr);
926 static clib_error_t *
927 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
929 clib_error_t * error = 0;
930 dpdk_main_t * dm = &dpdk_main;
931 dpdk_config_main_t * conf = &dpdk_config_main;
932 vlib_thread_main_t * tm = vlib_get_thread_main();
933 dpdk_device_config_t * devconf;
934 vlib_pci_addr_t pci_addr;
935 unformat_input_t sub_input;
937 u8 * rte_cmd = 0, * ethname = 0;
940 int num_whitelisted = 0;
942 int rxrings, txrings, rxslots, txslots, txburst;
951 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
953 // MATT-FIXME: inverted virtio-vhost logic to use virtio by default
954 conf->use_virtio_vhost = 1;
956 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
959 if (unformat (input, "no-hugetlb"))
961 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
965 else if (unformat (input, "enable-tcp-udp-checksum"))
966 conf->enable_tcp_udp_checksum = 1;
968 else if (unformat (input, "decimal-interface-names"))
969 conf->interface_name_format_decimal = 1;
971 else if (unformat (input, "no-multi-seg"))
972 conf->no_multi_seg = 1;
974 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
977 error = dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~1, &sub_input, 1);
982 else if (unformat (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
983 unformat_vlib_cli_sub_input, &sub_input))
985 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
992 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
994 error = dpdk_device_config (conf, pci_addr, 0, 0);
1003 else if (unformat(input, "netmap %s/%d:%d/%d:%d/%d",
1004 &nmname, &rxrings, &rxslots, &txrings, &txslots, &txburst)) {
1007 eth_nm_args(nmname, rxrings, rxslots, txrings, txslots, txburst);
1009 error = clib_error_return (0, "%s", rv);
1012 }else if (unformat(input, "netmap %s", &nmname)) {
1015 eth_nm_args(nmname, 0, 0, 0, 0, 0);
1017 error = clib_error_return (0, "%s", rv);
1023 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1025 else if (unformat (input, "kni %d", &conf->num_kni))
1027 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1029 else if (unformat (input, "socket-mem %s", &socket_mem))
1031 else if (unformat (input, "vhost-user-coalesce-frames %d", &conf->vhost_coalesce_frames))
1033 else if (unformat (input, "vhost-user-coalesce-time %f", &conf->vhost_coalesce_time))
1035 else if (unformat (input, "enable-vhost-user"))
1036 conf->use_virtio_vhost = 0;
1037 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep))
1041 else if (unformat(input, #a)) \
1043 if (!strncmp(#a, "no-pci", 6)) \
1045 tmp = format (0, "--%s%c", #a, 0); \
1046 vec_add1 (conf->eal_init_args, tmp); \
1048 foreach_eal_double_hyphen_predicate_arg
1052 else if (unformat(input, #a " %s", &s)) \
1054 if (!strncmp(#a, "huge-dir", 8)) \
1056 else if (!strncmp(#a, "file-prefix", 11)) \
1058 tmp = format (0, "--%s%c", #a, 0); \
1059 vec_add1 (conf->eal_init_args, tmp); \
1061 vec_add1 (conf->eal_init_args, s); \
1063 foreach_eal_double_hyphen_arg
1067 else if (unformat(input, #a " %s", &s)) \
1069 tmp = format (0, "-%s%c", #b, 0); \
1070 vec_add1 (conf->eal_init_args, tmp); \
1072 vec_add1 (conf->eal_init_args, s); \
1074 foreach_eal_single_hyphen_arg
1078 else if (unformat(input, #a " %s", &s)) \
1080 tmp = format (0, "-%s%c", #b, 0); \
1081 vec_add1 (conf->eal_init_args, tmp); \
1083 vec_add1 (conf->eal_init_args, s); \
1084 conf->a##_set_manually = 1; \
1086 foreach_eal_single_hyphen_mandatory_arg
1089 else if (unformat(input, "default"))
1094 error = clib_error_return (0, "unknown input `%U'",
1095 format_unformat_error, input);
1100 if (!conf->uio_driver_name)
1101 conf->uio_driver_name = format (0, "igb_uio%c", 0);
1104 * Use 1G huge pages if available.
1106 if (!no_huge && !huge_dir)
1108 u32 x, * mem_by_socket = 0;
1112 u8 less_than_1g = 1;
1115 umount(DEFAULT_HUGE_DIR);
1117 /* Process "socket-mem" parameter value */
1118 if (vec_len (socket_mem))
1120 unformat_input_t in;
1121 unformat_init_vector(&in, socket_mem);
1122 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1124 if (unformat (&in, "%u,", &x))
1126 else if (unformat (&in, "%u", &x))
1128 else if (unformat (&in, ","))
1133 vec_add1(mem_by_socket, x);
1138 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1144 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1146 vec_validate(mem_by_socket, c);
1147 mem_by_socket[c] = 512; /* default per-socket mem */
1152 /* check if available enough 1GB pages for each socket */
1153 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1155 u32 pages_avail, page_size, mem;
1158 char * numa_path = "/sys/devices/system/node/node%u/";
1159 char * nonnuma_path = "/sys/kernel/mm/";
1160 char * suffix = "hugepages/hugepages-%ukB/free_hugepages%c";
1162 struct stat sb_numa, sb_nonnuma;
1164 p = format(p, numa_path, c);
1165 stat(numa_path, &sb_numa);
1166 stat(nonnuma_path, &sb_nonnuma);
1168 if (S_ISDIR(sb_numa.st_mode)) {
1169 path = (char*)format((u8*)path, "%s%s", p, suffix);
1170 } else if (S_ISDIR(sb_nonnuma.st_mode)) {
1171 path = (char*)format((u8*)path, "%s%s", nonnuma_path, suffix);
1179 vec_validate(mem_by_socket, c);
1180 mem = mem_by_socket[c];
1184 s = format (s, path, page_size * 1024, 0);
1185 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1186 vec_reset_length (s);
1188 if (page_size * pages_avail < mem)
1193 s = format (s, path, page_size * 1024, 0);
1194 vlib_sysfs_read ((char *) s, "%u", &pages_avail);
1195 vec_reset_length (s);
1197 if (page_size * pages_avail < mem)
1204 _vec_len (mem_by_socket) = c + 1;
1206 /* regenerate socket_mem string */
1207 vec_foreach_index (x, mem_by_socket)
1208 socket_mem = format (socket_mem, "%s%u",
1209 socket_mem ? "," : "",
1211 socket_mem = format (socket_mem, "%c", 0);
1213 vec_free (mem_by_socket);
1215 rv = mkdir(VPP_RUN_DIR, 0755);
1216 if (rv && errno != EEXIST)
1218 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1219 VPP_RUN_DIR, errno);
1223 rv = mkdir(DEFAULT_HUGE_DIR, 0755);
1224 if (rv && errno != EEXIST)
1226 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1227 DEFAULT_HUGE_DIR, errno);
1231 if (use_1g && !(less_than_1g && use_2m))
1233 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1237 rv = mount("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1241 return clib_error_return (0, "not enough free huge pages");
1246 error = clib_error_return (0, "mount failed %d", errno);
1250 tmp = format (0, "--huge-dir%c", 0);
1251 vec_add1 (conf->eal_init_args, tmp);
1252 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1253 vec_add1 (conf->eal_init_args, tmp);
1256 tmp = format (0, "--file-prefix%c", 0);
1257 vec_add1 (conf->eal_init_args, tmp);
1258 tmp = format (0, "vpp%c", 0);
1259 vec_add1 (conf->eal_init_args, tmp);
1269 /* I'll bet that -c and -n must be the first and second args... */
1270 if (!conf->coremask_set_manually)
1272 vlib_thread_registration_t * tr;
1273 uword * coremask = 0;
1276 /* main thread core */
1277 coremask = clib_bitmap_set(coremask, tm->main_lcore, 1);
1279 for (i = 0; i < vec_len (tm->registrations); i++)
1281 tr = tm->registrations[i];
1282 coremask = clib_bitmap_or(coremask, tr->coremask);
1285 vec_insert (conf->eal_init_args, 2, 1);
1286 conf->eal_init_args[1] = (u8 *) "-c";
1287 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1288 conf->eal_init_args[2] = tmp;
1289 clib_bitmap_free(coremask);
1292 if (!conf->nchannels_set_manually)
1294 vec_insert (conf->eal_init_args, 2, 3);
1295 conf->eal_init_args[3] = (u8 *) "-n";
1296 tmp = format (0, "%d", conf->nchannels);
1297 conf->eal_init_args[4] = tmp;
1300 if (no_pci == 0 && geteuid() == 0)
1301 dpdk_bind_devices_to_uio(conf);
1304 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1305 devconf->x = conf->default_devconf.x ;
1307 pool_foreach (devconf, conf->dev_confs, ({
1309 /* default per-device config items */
1310 foreach_dpdk_device_config_item
1312 /* add DPDK EAL whitelist/blacklist entry */
1313 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1315 tmp = format (0, "-w%c", 0);
1316 vec_add1 (conf->eal_init_args, tmp);
1317 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1318 vec_add1 (conf->eal_init_args, tmp);
1320 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1322 tmp = format (0, "-b%c", 0);
1323 vec_add1 (conf->eal_init_args, tmp);
1324 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1325 vec_add1 (conf->eal_init_args, tmp);
1331 /* set master-lcore */
1332 tmp = format (0, "--master-lcore%c", 0);
1333 vec_add1 (conf->eal_init_args, tmp);
1334 tmp = format (0, "%u%c", tm->main_lcore, 0);
1335 vec_add1 (conf->eal_init_args, tmp);
1337 /* set socket-mem */
1338 tmp = format (0, "--socket-mem%c", 0);
1339 vec_add1 (conf->eal_init_args, tmp);
1340 tmp = format (0, "%s%c", socket_mem, 0);
1341 vec_add1 (conf->eal_init_args, tmp);
1343 /* NULL terminate the "argv" vector, in case of stupidity */
1344 vec_add1 (conf->eal_init_args, 0);
1345 _vec_len(conf->eal_init_args) -= 1;
1347 /* Set up DPDK eal and packet mbuf pool early. */
1349 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1351 rte_set_log_level (log_level);
1353 vm = vlib_get_main ();
1355 /* make copy of args as rte_eal_init tends to mess up with arg array */
1356 for (i = 1; i < vec_len(conf->eal_init_args); i++)
1357 conf->eal_init_args_str = format(conf->eal_init_args_str, "%s ",
1358 conf->eal_init_args[i]);
1360 ret = rte_eal_init(vec_len(conf->eal_init_args), (char **) conf->eal_init_args);
1362 /* lazy umount hugepages */
1363 umount2(DEFAULT_HUGE_DIR, MNT_DETACH);
1366 return clib_error_return (0, "rte_eal_init returned %d", ret);
1368 /* Dump the physical memory layout prior to creating the mbuf_pool */
1369 fprintf(stdout, "DPDK physical memory layout:\n");
1370 rte_dump_physmem_layout(stdout);
1372 /* main thread 1st */
1373 error = vlib_buffer_pool_create(vm, conf->num_mbufs, rte_socket_id());
1377 for (i = 0; i < RTE_MAX_LCORE; i++)
1379 error = vlib_buffer_pool_create(vm, conf->num_mbufs,
1380 rte_lcore_to_socket_id(i));
1389 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1391 void dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1393 vnet_main_t * vnm = vnet_get_main();
1394 struct rte_eth_link prev_link = xd->link;
1396 u8 hw_flags_chg = 0;
1398 /* only update link state for PMD interfaces */
1399 if (xd->dev_type != VNET_DPDK_DEV_ETH)
1402 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1403 memset(&xd->link, 0, sizeof(xd->link));
1404 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1406 if (LINK_STATE_ELOGS)
1408 vlib_main_t * vm = vlib_get_main();
1409 ELOG_TYPE_DECLARE(e) = {
1411 "update-link-state: sw_if_index %d, admin_up %d,"
1412 "old link_state %d new link_state %d",
1413 .format_args = "i4i1i1i1",
1416 struct { u32 sw_if_index; u8 admin_up;
1417 u8 old_link_state; u8 new_link_state;} *ed;
1418 ed = ELOG_DATA (&vm->elog_main, e);
1419 ed->sw_if_index = xd->vlib_sw_if_index;
1420 ed->admin_up = xd->admin_up;
1421 ed->old_link_state = (u8)
1422 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1423 ed->new_link_state = (u8) xd->link.link_status;
1426 if ((xd->admin_up == 1) &&
1427 ((xd->link.link_status != 0) ^
1428 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1431 hw_flags |= (xd->link.link_status ?
1432 VNET_HW_INTERFACE_FLAG_LINK_UP: 0);
1435 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1438 switch (xd->link.link_duplex)
1440 case ETH_LINK_HALF_DUPLEX:
1441 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1443 case ETH_LINK_FULL_DUPLEX:
1444 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1450 #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
1451 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1454 switch (xd->link.link_speed)
1456 case ETH_SPEED_NUM_10M:
1457 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1459 case ETH_SPEED_NUM_100M:
1460 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1462 case ETH_SPEED_NUM_1G:
1463 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1465 case ETH_SPEED_NUM_10G:
1466 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1468 case ETH_SPEED_NUM_40G:
1469 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1474 clib_warning("unknown link speed %d", xd->link.link_speed);
1479 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1482 switch (xd->link.link_speed)
1484 case ETH_LINK_SPEED_10:
1485 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1487 case ETH_LINK_SPEED_100:
1488 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1490 case ETH_LINK_SPEED_1000:
1491 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1493 case ETH_LINK_SPEED_10000:
1494 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1496 case ETH_LINK_SPEED_40G:
1497 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1502 clib_warning("unknown link speed %d", xd->link.link_speed);
1509 if (LINK_STATE_ELOGS)
1511 vlib_main_t * vm = vlib_get_main();
1513 ELOG_TYPE_DECLARE(e) = {
1514 .format = "update-link-state: sw_if_index %d, new flags %d",
1515 .format_args = "i4i4",
1518 struct { u32 sw_if_index; u32 flags; } *ed;
1519 ed = ELOG_DATA (&vm->elog_main, e);
1520 ed->sw_if_index = xd->vlib_sw_if_index;
1521 ed->flags = hw_flags;
1523 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1528 dpdk_process (vlib_main_t * vm,
1529 vlib_node_runtime_t * rt,
1532 clib_error_t * error;
1533 vnet_main_t * vnm = vnet_get_main();
1534 dpdk_main_t * dm = &dpdk_main;
1535 ethernet_main_t * em = ðernet_main;
1537 vlib_thread_main_t * tm = vlib_get_thread_main();
1541 error = dpdk_lib_init (dm);
1544 * Turn on the input node if we found some devices to drive
1545 * and we're not running worker threads or i/o threads
1548 if (error == 0 && vec_len(dm->devices) > 0)
1550 if (tm->n_vlib_mains == 1)
1551 vlib_node_set_state (vm, dpdk_input_node.index,
1552 VLIB_NODE_STATE_POLLING);
1554 for (i=0; i < tm->n_vlib_mains; i++)
1555 if (vec_len(dm->devices_by_cpu[i]) > 0)
1556 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1557 VLIB_NODE_STATE_POLLING);
1561 clib_error_report (error);
1563 dpdk_vhost_user_process_init(&vu_state);
1565 dm->worker_thread_release = 1;
1567 f64 now = vlib_time_now (vm);
1568 vec_foreach (xd, dm->devices)
1570 dpdk_update_link_state (xd, now);
1573 { // Extra set up for bond interfaces:
1574 // 1. Setup MACs for bond interfaces and their slave links which was set
1575 // in dpdk_port_setup() but needs to be done again here to take effect.
1576 // 2. Set max L3 packet size of each bond interface to the lowerst value of
1578 // 3. Set up info for bond interface related CLI support.
1579 int nports = rte_eth_dev_count();
1581 for (i = 0; i < nports; i++) {
1582 struct rte_eth_dev_info dev_info;
1583 rte_eth_dev_info_get(i, &dev_info);
1584 if (!dev_info.driver_name)
1585 dev_info.driver_name = dev_info.pci_dev->driver->name;
1586 ASSERT(dev_info.driver_name);
1587 if (strncmp(dev_info.driver_name, "rte_bond_pmd", 12) == 0) {
1590 int nlink = rte_eth_bond_slaves_get(i, slink, 16);
1592 vnet_hw_interface_t * bhi;
1593 ethernet_interface_t * bei;
1594 /* Get MAC of 1st slave link */
1595 rte_eth_macaddr_get(slink[0], (struct ether_addr *)addr);
1596 /* Set MAC of bounded interface to that of 1st slave link */
1597 rte_eth_bond_mac_address_set(i, (struct ether_addr *)addr);
1598 /* Populate MAC of bonded interface in VPP hw tables */
1599 bhi = vnet_get_hw_interface(
1600 vnm, dm->devices[i].vlib_hw_if_index);
1601 bei = pool_elt_at_index(em->interfaces, bhi->hw_instance);
1602 clib_memcpy(bhi->hw_address, addr, 6);
1603 clib_memcpy(bei->address, addr, 6);
1604 /* Init l3 packet size allowed on bonded interface */
1605 bhi->max_l3_packet_bytes[VLIB_RX] =
1606 bhi->max_l3_packet_bytes[VLIB_TX] =
1607 ETHERNET_MAX_PACKET_BYTES - sizeof(ethernet_header_t);
1608 while (nlink >= 1) { /* for all slave links */
1609 int slave = slink[--nlink];
1610 dpdk_device_t * sdev = &dm->devices[slave];
1611 vnet_hw_interface_t * shi;
1612 vnet_sw_interface_t * ssi;
1613 /* Add MAC to all slave links except the first one */
1614 if (nlink) rte_eth_dev_mac_addr_add(
1615 slave, (struct ether_addr *)addr, 0);
1616 /* Set slaves bitmap for bonded interface */
1617 bhi->bond_info = clib_bitmap_set(
1618 bhi->bond_info, sdev->vlib_hw_if_index, 1);
1619 /* Set slave link flags on slave interface */
1620 shi = vnet_get_hw_interface(vnm, sdev->vlib_hw_if_index);
1621 ssi = vnet_get_sw_interface(vnm, sdev->vlib_sw_if_index);
1622 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1623 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1624 /* Set l3 packet size allowed as the lowest of slave */
1625 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1626 shi->max_l3_packet_bytes[VLIB_RX])
1627 bhi->max_l3_packet_bytes[VLIB_RX] =
1628 bhi->max_l3_packet_bytes[VLIB_TX] =
1629 shi->max_l3_packet_bytes[VLIB_RX];
1640 * check each time through the loop in case intervals are changed
1642 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1643 dm->link_state_poll_interval : dm->stat_poll_interval;
1645 vlib_process_wait_for_event_or_clock (vm, min_wait);
1647 if (dpdk_get_admin_up_down_in_progress())
1648 /* skip the poll if an admin up down is in progress (on any interface) */
1651 vec_foreach (xd, dm->devices)
1653 f64 now = vlib_time_now (vm);
1654 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1655 dpdk_update_counters (xd, now);
1656 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1657 dpdk_update_link_state (xd, now);
1659 if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
1660 if (dpdk_vhost_user_process_if(vm, xd, vu_state) != 0)
1665 dpdk_vhost_user_process_cleanup(vu_state);
1670 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1671 .function = dpdk_process,
1672 .type = VLIB_NODE_TYPE_PROCESS,
1673 .name = "dpdk-process",
1674 .process_log2_n_stack_bytes = 17,
1677 int dpdk_set_stat_poll_interval (f64 interval)
1679 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1680 return (VNET_API_ERROR_INVALID_VALUE);
1682 dpdk_main.stat_poll_interval = interval;
1687 int dpdk_set_link_state_poll_interval (f64 interval)
1689 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1690 return (VNET_API_ERROR_INVALID_VALUE);
1692 dpdk_main.link_state_poll_interval = interval;
1698 dpdk_init (vlib_main_t * vm)
1700 dpdk_main_t * dm = &dpdk_main;
1702 clib_error_t * error = 0;
1703 vlib_thread_main_t * tm = vlib_get_thread_main();
1705 /* verify that structs are cacheline aligned */
1706 ASSERT(offsetof(dpdk_device_t, cacheline0) == 0);
1707 ASSERT(offsetof(dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
1708 ASSERT(offsetof(dpdk_worker_t, cacheline0) == 0);
1709 ASSERT(offsetof(frame_queue_trace_t, cacheline0) == 0);
1712 dm->vnet_main = vnet_get_main();
1713 dm->conf = &dpdk_config_main;
1715 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1717 return clib_error_return (0, "ethernet-input node AWOL");
1719 dm->ethernet_input_node_index = ei->index;
1721 dm->conf->nchannels = 4;
1722 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1723 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1725 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1726 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1727 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1729 /* $$$ use n_thread_stacks since it's known-good at this point */
1730 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1732 /* initialize EFD (early fast discard) default settings */
1733 dm->efd.enabled = DPDK_EFD_DISABLED;
1734 dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT *
1735 DPDK_NB_RX_DESC_10GE)/100);
1736 dm->efd.consec_full_frames_hi_thresh =
1737 DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH;
1739 /* vhost-user coalescence frames defaults */
1740 dm->conf->vhost_coalesce_frames = 32;
1741 dm->conf->vhost_coalesce_time = 1e-3;
1743 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1744 dm->buffer_flags_template =
1745 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1746 | IP_BUFFER_L4_CHECKSUM_COMPUTED
1747 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1749 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1750 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1753 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1759 VLIB_INIT_FUNCTION (dpdk_init);