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 = 0, /**< CRC stripped by hardware */
60 .mq_mode = ETH_MQ_TX_NONE,
65 dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd)
70 ASSERT (os_get_cpu_number () == 0);
72 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
74 vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0);
75 rte_eth_dev_stop (xd->device_index);
78 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
79 xd->tx_q_used, &xd->port_conf);
82 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
83 xd->device_index, rv);
85 /* Set up one TX-queue per worker thread */
86 for (j = 0; j < xd->tx_q_used; j++)
88 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
89 xd->cpu_socket, &xd->tx_conf);
91 /* retry with any other CPU socket */
93 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
94 SOCKET_ID_ANY, &xd->tx_conf);
100 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
101 xd->device_index, rv);
103 for (j = 0; j < xd->rx_q_used; j++)
106 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
109 pktmbuf_pools[xd->cpu_socket_id_by_queue
112 /* retry with any other CPU socket */
114 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
117 pktmbuf_pools[xd->cpu_socket_id_by_queue
120 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
121 xd->device_index, rv);
124 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
127 rv = rte_eth_dev_start (xd->device_index);
129 clib_warning ("rte_eth_dev_start %d returned %d",
130 xd->device_index, rv);
136 dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
138 dpdk_main_t *dm = &dpdk_main;
139 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
142 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC (flags))
144 old = (xd->flags & DPDK_DEVICE_FLAG_PROMISC) != 0;
146 if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
147 xd->flags |= DPDK_DEVICE_FLAG_PROMISC;
149 xd->flags &= ~DPDK_DEVICE_FLAG_PROMISC;
151 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
153 if (xd->flags & DPDK_DEVICE_FLAG_PROMISC)
154 rte_eth_promiscuous_enable (xd->device_index);
156 rte_eth_promiscuous_disable (xd->device_index);
159 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU (flags))
162 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
163 * driver to dynamically change the mtu. If/when the
164 * VIC firmware gets fixed, then this should be removed.
166 if (xd->pmd == VNET_DPDK_PMD_ENIC)
168 struct rte_eth_dev_info dev_info;
171 * Restore mtu to what has been set by CIMC in the firmware cfg.
173 rte_eth_dev_info_get (xd->device_index, &dev_info);
174 hi->max_packet_bytes = dev_info.max_rx_pktlen;
176 vlib_cli_output (vlib_get_main (),
177 "Cisco VIC mtu can only be changed "
178 "using CIMC then rebooting the server!");
184 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
186 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
187 rte_eth_dev_stop (xd->device_index);
189 rv = rte_eth_dev_configure
190 (xd->device_index, xd->rx_q_used, xd->tx_q_used, &xd->port_conf);
193 vlib_cli_output (vlib_get_main (),
194 "rte_eth_dev_configure[%d]: err %d",
195 xd->device_index, rv);
197 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
199 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
201 int rv = rte_eth_dev_start (xd->device_index);
203 clib_warning ("rte_eth_dev_start %d returned %d",
204 xd->device_index, rv);
212 dpdk_device_lock_init (dpdk_device_t * xd)
215 vec_validate (xd->lockp, xd->tx_q_used - 1);
216 for (q = 0; q < xd->tx_q_used; q++)
218 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
219 CLIB_CACHE_LINE_BYTES);
220 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
225 dpdk_device_lock_free (dpdk_device_t * xd)
229 for (q = 0; q < vec_len (xd->lockp); q++)
230 clib_mem_free ((void *) xd->lockp[q]);
231 vec_free (xd->lockp);
235 static clib_error_t *
236 dpdk_lib_init (dpdk_main_t * dm)
242 vlib_main_t *vm = vlib_get_main ();
243 vlib_thread_main_t *tm = vlib_get_thread_main ();
244 vnet_sw_interface_t *sw;
245 vnet_hw_interface_t *hi;
247 vlib_pci_addr_t last_pci_addr;
248 u32 last_pci_addr_port = 0;
249 vlib_thread_registration_t *tr, *tr_hqos;
252 u32 next_cpu = 0, next_hqos_cpu = 0;
253 u8 af_packet_port_id = 0;
254 last_pci_addr.as_u32 = ~0;
256 dm->input_cpu_first_index = 0;
257 dm->input_cpu_count = 1;
259 /* find out which cpus will be used for input */
260 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
261 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
263 if (tr && tr->count > 0)
265 dm->input_cpu_first_index = tr->first_index;
266 dm->input_cpu_count = tr->count;
269 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
270 CLIB_CACHE_LINE_BYTES);
272 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
273 CLIB_CACHE_LINE_BYTES);
275 dm->hqos_cpu_first_index = 0;
276 dm->hqos_cpu_count = 0;
278 /* find out which cpus will be used for I/O TX */
279 p_hqos = hash_get_mem (tm->thread_registrations_by_name, "hqos-threads");
280 tr_hqos = p_hqos ? (vlib_thread_registration_t *) p_hqos[0] : 0;
282 if (tr_hqos && tr_hqos->count > 0)
284 dm->hqos_cpu_first_index = tr_hqos->first_index;
285 dm->hqos_cpu_count = tr_hqos->count;
288 vec_validate_aligned (dm->devices_by_hqos_cpu, tm->n_vlib_mains - 1,
289 CLIB_CACHE_LINE_BYTES);
291 vec_validate_aligned (dm->hqos_threads, tm->n_vlib_mains - 1,
292 CLIB_CACHE_LINE_BYTES);
294 nports = rte_eth_dev_count ();
297 clib_warning ("DPDK drivers found no ports...");
301 clib_warning ("DPDK drivers found %d ports...", nports);
304 * All buffers are all allocated from the same rte_mempool.
305 * Thus they all have the same number of data bytes.
307 dm->vlib_buffer_free_list_index =
308 vlib_buffer_get_or_create_free_list (vm,
309 VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
312 if (dm->conf->enable_tcp_udp_checksum)
313 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
314 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
316 for (i = 0; i < nports; i++)
321 struct rte_eth_dev_info dev_info;
323 struct rte_eth_link l;
324 dpdk_device_config_t *devconf = 0;
325 vlib_pci_addr_t pci_addr;
328 rte_eth_dev_info_get (i, &dev_info);
329 if (dev_info.pci_dev) /* bonded interface has no pci info */
331 pci_addr.domain = dev_info.pci_dev->addr.domain;
332 pci_addr.bus = dev_info.pci_dev->addr.bus;
333 pci_addr.slot = dev_info.pci_dev->addr.devid;
334 pci_addr.function = dev_info.pci_dev->addr.function;
336 hash_get (dm->conf->device_config_index_by_pci_addr,
341 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
343 devconf = &dm->conf->default_devconf;
345 /* Create vnet interface */
346 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
347 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
348 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
349 xd->cpu_socket = (i8) rte_eth_dev_socket_id (i);
351 /* Handle interface naming for devices with multiple ports sharing same PCI ID */
352 if (dev_info.pci_dev)
354 struct rte_eth_dev_info di = { 0 };
355 rte_eth_dev_info_get (i + 1, &di);
356 if (di.pci_dev && pci_addr.as_u32 != last_pci_addr.as_u32 &&
357 memcmp (&dev_info.pci_dev->addr, &di.pci_dev->addr,
358 sizeof (struct rte_pci_addr)) == 0)
360 xd->interface_name_suffix = format (0, "0");
361 last_pci_addr.as_u32 = pci_addr.as_u32;
362 last_pci_addr_port = i;
364 else if (pci_addr.as_u32 == last_pci_addr.as_u32)
366 xd->interface_name_suffix =
367 format (0, "%u", i - last_pci_addr_port);
371 last_pci_addr.as_u32 = ~0;
375 last_pci_addr.as_u32 = ~0;
377 clib_memcpy (&xd->tx_conf, &dev_info.default_txconf,
378 sizeof (struct rte_eth_txconf));
379 if (dm->conf->no_multi_seg)
381 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
382 port_conf_template.rxmode.jumbo_frame = 0;
386 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
387 port_conf_template.rxmode.jumbo_frame = 1;
388 xd->flags |= DPDK_DEVICE_FLAG_MAYBE_MULTISEG;
391 clib_memcpy (&xd->port_conf, &port_conf_template,
392 sizeof (struct rte_eth_conf));
394 xd->tx_q_used = clib_min (dev_info.max_tx_queues, tm->n_vlib_mains);
396 if (devconf->num_tx_queues > 0
397 && devconf->num_tx_queues < xd->tx_q_used)
398 xd->tx_q_used = clib_min (xd->tx_q_used, devconf->num_tx_queues);
400 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
405 if (devconf->num_rx_queues > 1
406 && dev_info.max_rx_queues >= devconf->num_rx_queues)
408 xd->rx_q_used = devconf->num_rx_queues;
409 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
410 if (devconf->rss_fn == 0)
411 xd->port_conf.rx_adv_conf.rss_conf.rss_hf =
412 ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
414 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn;
419 xd->flags |= DPDK_DEVICE_FLAG_PMD;
421 /* workaround for drivers not setting driver_name */
422 if ((!dev_info.driver_name) && (dev_info.pci_dev))
423 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
424 dev_info.driver_name = dev_info.pci_dev->driver->name;
426 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
428 ASSERT (dev_info.driver_name);
434 #define _(s,f) else if (dev_info.driver_name && \
435 !strcmp(dev_info.driver_name, s)) \
436 xd->pmd = VNET_DPDK_PMD_##f;
442 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
444 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
445 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
446 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
451 case VNET_DPDK_PMD_E1000EM:
452 case VNET_DPDK_PMD_IGB:
453 case VNET_DPDK_PMD_IGBVF:
454 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
458 case VNET_DPDK_PMD_IXGBE:
459 case VNET_DPDK_PMD_IXGBEVF:
460 case VNET_DPDK_PMD_THUNDERX:
461 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
463 case VNET_DPDK_PMD_DPAA2:
464 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
468 case VNET_DPDK_PMD_ENIC:
469 rte_eth_link_get_nowait (i, &l);
470 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
471 if (l.link_speed == 40000)
472 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
474 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
477 /* Intel Fortville */
478 case VNET_DPDK_PMD_I40E:
479 case VNET_DPDK_PMD_I40EVF:
480 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
481 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
483 switch (dev_info.pci_dev->id.device_id)
485 case I40E_DEV_ID_10G_BASE_T:
486 case I40E_DEV_ID_SFP_XL710:
487 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
489 case I40E_DEV_ID_QSFP_A:
490 case I40E_DEV_ID_QSFP_B:
491 case I40E_DEV_ID_QSFP_C:
492 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
495 rte_eth_link_get_nowait (i, &l);
496 xd->port_type = l.link_speed == 10000 ?
497 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
500 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
504 case VNET_DPDK_PMD_CXGBE:
505 switch (dev_info.pci_dev->id.device_id)
507 case 0x540d: /* T580-CR */
508 case 0x5410: /* T580-LP-cr */
509 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
511 case 0x5403: /* T540-CR */
512 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
515 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
519 case VNET_DPDK_PMD_MLX5:
521 char *pn_100g[] = { "MCX415A-CCAT", "MCX416A-CCAT", 0 };
522 char *pn_40g[] = { "MCX413A-BCAT", "MCX414A-BCAT",
523 "MCX415A-BCAT", "MCX416A-BCAT", "MCX4131A-BCAT", 0
525 char *pn_10g[] = { "MCX4111A-XCAT", "MCX4121A-XCAT", 0 };
527 vlib_pci_device_t *pd = vlib_get_pci_device (&pci_addr);
531 pn = format (0, "%U%c",
532 format_vlib_pci_vpd, pd->vpd_r, "PN", 0);
538 while (!found && c[0])
540 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
542 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_100G;
549 while (!found && c[0])
551 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
553 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
560 while (!found && c[0])
562 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
564 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
574 /* Intel Red Rock Canyon */
575 case VNET_DPDK_PMD_FM10K:
576 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
580 case VNET_DPDK_PMD_VIRTIO:
581 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
582 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
583 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
587 case VNET_DPDK_PMD_VMXNET3:
588 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
589 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
592 case VNET_DPDK_PMD_AF_PACKET:
593 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
594 xd->af_packet_port_id = af_packet_port_id++;
597 case VNET_DPDK_PMD_BOND:
598 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
599 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
603 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
606 if (devconf->num_rx_desc)
607 xd->nb_rx_desc = devconf->num_rx_desc;
609 if (devconf->num_tx_desc)
610 xd->nb_tx_desc = devconf->num_tx_desc;
614 * Ensure default mtu is not > the mtu read from the hardware.
615 * Otherwise rte_eth_dev_configure() will fail and the port will
618 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
621 * This device does not support the platforms's max frame
622 * size. Use it's advertised mru instead.
624 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
628 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
631 * Some platforms do not account for Ethernet FCS (4 bytes) in
632 * MTU calculations. To interop with them increase mru but only
633 * if the device's settings can support it.
635 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
636 xd->port_conf.rxmode.hw_strip_crc)
639 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
640 * stripped by h/w and so will not consume any buffer memory.
642 xd->port_conf.rxmode.max_rx_pkt_len += 4;
646 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
648 f64 now = vlib_time_now (vm);
650 rnd = (u32) (now * 1e6);
651 rnd = random_u32 (&rnd);
652 clib_memcpy (addr + 2, &rnd, sizeof (rnd));
657 rte_eth_macaddr_get (i, (struct ether_addr *) addr);
659 if (xd->tx_q_used < tm->n_vlib_mains)
660 dpdk_device_lock_init (xd);
662 xd->device_index = xd - dm->devices;
663 ASSERT (i == xd->device_index);
664 xd->per_interface_next_index = ~0;
666 /* assign interface to input thread */
667 dpdk_device_and_queue_t *dq;
670 if (devconf->workers)
675 clib_bitmap_foreach (i, devconf->workers, ({
676 int cpu = dm->input_cpu_first_index + i;
677 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
678 vec_validate(xd->cpu_socket_id_by_queue, q);
679 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
680 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
681 dq->device = xd->device_index;
687 for (q = 0; q < xd->rx_q_used; q++)
689 int cpu = dm->input_cpu_first_index + next_cpu;
690 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
693 * numa node for worker thread handling this queue
694 * needed for taking buffers from the right mempool
696 vec_validate (xd->cpu_socket_id_by_queue, q);
697 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id (lcore);
700 * construct vector of (device,queue) pairs for each worker thread
702 vec_add2 (dm->devices_by_cpu[cpu], dq, 1);
703 dq->device = xd->device_index;
707 if (next_cpu == dm->input_cpu_count)
712 if (devconf->hqos_enabled)
714 xd->flags |= DPDK_DEVICE_FLAG_HQOS;
716 if (devconf->hqos.hqos_thread_valid)
718 int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread;
720 if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count)
721 return clib_error_return (0, "invalid HQoS thread index");
723 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
724 dq->device = xd->device_index;
729 int cpu = dm->hqos_cpu_first_index + next_hqos_cpu;
731 if (dm->hqos_cpu_count == 0)
732 return clib_error_return (0, "no HQoS threads available");
734 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
735 dq->device = xd->device_index;
739 if (next_hqos_cpu == dm->hqos_cpu_count)
742 devconf->hqos.hqos_thread_valid = 1;
743 devconf->hqos.hqos_thread = cpu;
747 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
748 CLIB_CACHE_LINE_BYTES);
749 for (j = 0; j < tm->n_vlib_mains; j++)
751 vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
752 sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
753 vec_reset_length (xd->tx_vectors[j]);
756 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
757 CLIB_CACHE_LINE_BYTES);
758 for (j = 0; j < xd->rx_q_used; j++)
760 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
761 CLIB_CACHE_LINE_BYTES);
762 vec_reset_length (xd->rx_vectors[j]);
765 vec_validate_aligned (xd->d_trace_buffers, tm->n_vlib_mains,
766 CLIB_CACHE_LINE_BYTES);
768 rv = dpdk_port_setup (dm, xd);
773 if (devconf->hqos_enabled)
775 rv = dpdk_port_setup_hqos (xd, &devconf->hqos);
780 /* count the number of descriptors used for this device */
781 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
783 error = ethernet_register_interface
784 (dm->vnet_main, dpdk_device_class.index, xd->device_index,
785 /* ethernet address */ addr,
786 &xd->vlib_hw_if_index, dpdk_flag_change);
790 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
791 xd->vlib_sw_if_index = sw->sw_if_index;
792 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
795 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
796 * driver to dynamically change the mtu. If/when the
797 * VIC firmware gets fixed, then this should be removed.
799 if (xd->pmd == VNET_DPDK_PMD_ENIC)
802 * Initialize mtu to what has been set by CIMC in the firmware cfg.
804 hi->max_packet_bytes = dev_info.max_rx_pktlen;
805 if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF)
806 vlan_strip = 1; /* remove vlan tag from VIC port by default */
808 clib_warning ("VLAN strip disabled for interface\n");
810 else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON)
816 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
817 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
818 xd->port_conf.rxmode.hw_vlan_strip = vlan_off;
819 if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0)
820 clib_warning ("VLAN strip enabled for interface\n");
822 clib_warning ("VLAN strip cannot be supported by interface\n");
825 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
826 xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t);
828 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
831 if (nb_desc > dm->conf->num_mbufs)
832 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
833 dm->conf->num_mbufs, nb_desc);
839 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
841 vlib_pci_main_t *pm = &pci_main;
843 vlib_pci_device_t *d;
845 int num_whitelisted = vec_len (conf->dev_confs);
848 pool_foreach (d, pm->pci_devs, ({
849 dpdk_device_config_t * devconf = 0;
850 vec_reset_length (pci_addr);
851 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
853 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET)
858 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
863 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
867 if (d->vendor_id == 0x1af4 && d->device_id == 0x1000)
870 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
872 /* all Intel devices */
873 else if (d->vendor_id == 0x8086)
876 else if (d->vendor_id == 0x1137 && d->device_id == 0x0043)
879 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
883 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
884 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
889 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
895 pool_get (conf->dev_confs, devconf);
896 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
897 devconf - conf->dev_confs);
898 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
900 devconf->is_blacklisted = 1;
901 clib_error_report (error);
908 static clib_error_t *
909 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
910 unformat_input_t * input, u8 is_default)
912 clib_error_t *error = 0;
914 dpdk_device_config_t *devconf;
915 unformat_input_t sub_input;
919 devconf = &conf->default_devconf;
923 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
927 pool_get (conf->dev_confs, devconf);
928 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32,
929 devconf - conf->dev_confs);
932 return clib_error_return (0,
933 "duplicate configuration for PCI address %U",
934 format_vlib_pci_addr, &pci_addr);
937 devconf->pci_addr.as_u32 = pci_addr.as_u32;
938 devconf->hqos_enabled = 0;
939 dpdk_device_config_hqos_default (&devconf->hqos);
944 unformat_skip_white_space (input);
945 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
947 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
949 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
951 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
953 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
955 else if (unformat (input, "workers %U", unformat_bitmap_list,
960 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
962 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
966 else if (unformat (input, "vlan-strip-offload off"))
967 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF;
968 else if (unformat (input, "vlan-strip-offload on"))
969 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON;
972 (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input))
974 devconf->hqos_enabled = 1;
975 error = unformat_hqos (&sub_input, &devconf->hqos);
979 else if (unformat (input, "hqos"))
981 devconf->hqos_enabled = 1;
985 error = clib_error_return (0, "unknown input `%U'",
986 format_unformat_error, input);
994 if (devconf->workers && devconf->num_rx_queues == 0)
995 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
996 else if (devconf->workers &&
997 clib_bitmap_count_set_bits (devconf->workers) !=
998 devconf->num_rx_queues)
1000 clib_error_return (0,
1001 "%U: number of worker threadds must be "
1002 "equal to number of rx queues", format_vlib_pci_addr,
1008 static clib_error_t *
1009 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
1011 clib_error_t *error = 0;
1012 dpdk_main_t *dm = &dpdk_main;
1013 dpdk_config_main_t *conf = &dpdk_config_main;
1014 vlib_thread_main_t *tm = vlib_get_thread_main ();
1015 dpdk_device_config_t *devconf;
1016 vlib_pci_addr_t pci_addr;
1017 unformat_input_t sub_input;
1019 u8 *rte_cmd = 0, *ethname = 0;
1022 int num_whitelisted = 0;
1029 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
1031 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1033 /* Prime the pump */
1034 if (unformat (input, "no-hugetlb"))
1036 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
1040 else if (unformat (input, "enable-tcp-udp-checksum"))
1041 conf->enable_tcp_udp_checksum = 1;
1043 else if (unformat (input, "decimal-interface-names"))
1044 conf->interface_name_format_decimal = 1;
1046 else if (unformat (input, "no-multi-seg"))
1047 conf->no_multi_seg = 1;
1049 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
1053 dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input,
1061 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1062 unformat_vlib_cli_sub_input, &sub_input))
1064 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
1071 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1073 error = dpdk_device_config (conf, pci_addr, 0, 0);
1080 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1082 else if (unformat (input, "kni %d", &conf->num_kni))
1084 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1086 else if (unformat (input, "socket-mem %s", &socket_mem))
1088 else if (unformat (input, "no-pci"))
1091 tmp = format (0, "--no-pci%c", 0);
1092 vec_add1 (conf->eal_init_args, tmp);
1094 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep))
1098 else if (unformat(input, #a)) \
1100 tmp = format (0, "--%s%c", #a, 0); \
1101 vec_add1 (conf->eal_init_args, tmp); \
1103 foreach_eal_double_hyphen_predicate_arg
1106 else if (unformat(input, #a " %s", &s)) \
1108 if (!strncmp(#a, "huge-dir", 8)) \
1110 else if (!strncmp(#a, "file-prefix", 11)) \
1112 tmp = format (0, "--%s%c", #a, 0); \
1113 vec_add1 (conf->eal_init_args, tmp); \
1115 if (!strncmp(#a, "vdev", 4)) \
1116 if (strstr((char*)s, "af_packet")) \
1117 clib_warning ("af_packet obsoleted. Use CLI 'create host-interface'."); \
1118 vec_add1 (conf->eal_init_args, s); \
1120 foreach_eal_double_hyphen_arg
1123 else if (unformat(input, #a " %s", &s)) \
1125 tmp = format (0, "-%s%c", #b, 0); \
1126 vec_add1 (conf->eal_init_args, tmp); \
1128 vec_add1 (conf->eal_init_args, s); \
1130 foreach_eal_single_hyphen_arg
1133 else if (unformat(input, #a " %s", &s)) \
1135 tmp = format (0, "-%s%c", #b, 0); \
1136 vec_add1 (conf->eal_init_args, tmp); \
1138 vec_add1 (conf->eal_init_args, s); \
1139 conf->a##_set_manually = 1; \
1141 foreach_eal_single_hyphen_mandatory_arg
1143 else if (unformat (input, "default"))
1146 else if (unformat_skip_white_space (input))
1150 error = clib_error_return (0, "unknown input `%U'",
1151 format_unformat_error, input);
1156 if (!conf->uio_driver_name)
1157 conf->uio_driver_name = format (0, "igb_uio%c", 0);
1160 * Use 1G huge pages if available.
1162 if (!no_huge && !huge_dir)
1164 u32 x, *mem_by_socket = 0;
1168 u8 less_than_1g = 1;
1171 umount (DEFAULT_HUGE_DIR);
1173 /* Process "socket-mem" parameter value */
1174 if (vec_len (socket_mem))
1176 unformat_input_t in;
1177 unformat_init_vector (&in, socket_mem);
1178 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1180 if (unformat (&in, "%u,", &x))
1182 else if (unformat (&in, "%u", &x))
1184 else if (unformat (&in, ","))
1189 vec_add1 (mem_by_socket, x);
1194 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1195 unformat_free (&in);
1201 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1203 vec_validate(mem_by_socket, c);
1204 mem_by_socket[c] = 256; /* default per-socket mem */
1210 /* check if available enough 1GB pages for each socket */
1212 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1214 int pages_avail, page_size, mem;
1216 vec_validate(mem_by_socket, c);
1217 mem = mem_by_socket[c];
1220 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1222 if (pages_avail < 0 || page_size * pages_avail < mem)
1226 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1228 if (pages_avail < 0 || page_size * pages_avail < mem)
1233 if (mem_by_socket == 0)
1235 error = clib_error_return (0, "mem_by_socket NULL");
1238 _vec_len (mem_by_socket) = c + 1;
1240 /* regenerate socket_mem string */
1241 vec_foreach_index (x, mem_by_socket)
1242 socket_mem = format (socket_mem, "%s%u",
1243 socket_mem ? "," : "", mem_by_socket[x]);
1244 socket_mem = format (socket_mem, "%c", 0);
1246 vec_free (mem_by_socket);
1248 rv = mkdir (VPP_RUN_DIR, 0755);
1249 if (rv && errno != EEXIST)
1251 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1252 VPP_RUN_DIR, errno);
1256 rv = mkdir (DEFAULT_HUGE_DIR, 0755);
1257 if (rv && errno != EEXIST)
1259 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1260 DEFAULT_HUGE_DIR, errno);
1264 if (use_1g && !(less_than_1g && use_2m))
1267 mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1271 rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1275 return clib_error_return (0, "not enough free huge pages");
1280 error = clib_error_return (0, "mount failed %d", errno);
1284 tmp = format (0, "--huge-dir%c", 0);
1285 vec_add1 (conf->eal_init_args, tmp);
1286 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1287 vec_add1 (conf->eal_init_args, tmp);
1290 tmp = format (0, "--file-prefix%c", 0);
1291 vec_add1 (conf->eal_init_args, tmp);
1292 tmp = format (0, "vpp%c", 0);
1293 vec_add1 (conf->eal_init_args, tmp);
1303 /* I'll bet that -c and -n must be the first and second args... */
1304 if (!conf->coremask_set_manually)
1306 vlib_thread_registration_t *tr;
1307 uword *coremask = 0;
1310 /* main thread core */
1311 coremask = clib_bitmap_set (coremask, tm->main_lcore, 1);
1313 for (i = 0; i < vec_len (tm->registrations); i++)
1315 tr = tm->registrations[i];
1316 coremask = clib_bitmap_or (coremask, tr->coremask);
1319 vec_insert (conf->eal_init_args, 2, 1);
1320 conf->eal_init_args[1] = (u8 *) "-c";
1321 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1322 conf->eal_init_args[2] = tmp;
1323 clib_bitmap_free (coremask);
1326 if (!conf->nchannels_set_manually)
1328 vec_insert (conf->eal_init_args, 2, 3);
1329 conf->eal_init_args[3] = (u8 *) "-n";
1330 tmp = format (0, "%d", conf->nchannels);
1331 conf->eal_init_args[4] = tmp;
1334 if (no_pci == 0 && geteuid () == 0)
1335 dpdk_bind_devices_to_uio (conf);
1338 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1339 devconf->x = conf->default_devconf.x ;
1342 pool_foreach (devconf, conf->dev_confs, ({
1344 /* default per-device config items */
1345 foreach_dpdk_device_config_item
1347 /* add DPDK EAL whitelist/blacklist entry */
1348 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1350 tmp = format (0, "-w%c", 0);
1351 vec_add1 (conf->eal_init_args, tmp);
1352 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1353 vec_add1 (conf->eal_init_args, tmp);
1355 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1357 tmp = format (0, "-b%c", 0);
1358 vec_add1 (conf->eal_init_args, tmp);
1359 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1360 vec_add1 (conf->eal_init_args, tmp);
1367 /* set master-lcore */
1368 tmp = format (0, "--master-lcore%c", 0);
1369 vec_add1 (conf->eal_init_args, tmp);
1370 tmp = format (0, "%u%c", tm->main_lcore, 0);
1371 vec_add1 (conf->eal_init_args, tmp);
1373 /* set socket-mem */
1374 tmp = format (0, "--socket-mem%c", 0);
1375 vec_add1 (conf->eal_init_args, tmp);
1376 tmp = format (0, "%s%c", socket_mem, 0);
1377 vec_add1 (conf->eal_init_args, tmp);
1379 /* NULL terminate the "argv" vector, in case of stupidity */
1380 vec_add1 (conf->eal_init_args, 0);
1381 _vec_len (conf->eal_init_args) -= 1;
1383 /* Set up DPDK eal and packet mbuf pool early. */
1385 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1387 rte_set_log_level (log_level);
1389 vm = vlib_get_main ();
1391 /* make copy of args as rte_eal_init tends to mess up with arg array */
1392 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1393 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1394 conf->eal_init_args[i]);
1397 rte_eal_init (vec_len (conf->eal_init_args),
1398 (char **) conf->eal_init_args);
1400 /* lazy umount hugepages */
1401 umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
1404 return clib_error_return (0, "rte_eal_init returned %d", ret);
1406 /* Dump the physical memory layout prior to creating the mbuf_pool */
1407 fprintf (stdout, "DPDK physical memory layout:\n");
1408 rte_dump_physmem_layout (stdout);
1410 /* main thread 1st */
1411 error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ());
1415 for (i = 0; i < RTE_MAX_LCORE; i++)
1417 error = vlib_buffer_pool_create (vm, conf->num_mbufs,
1418 rte_lcore_to_socket_id (i));
1427 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1430 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1432 vnet_main_t *vnm = vnet_get_main ();
1433 struct rte_eth_link prev_link = xd->link;
1435 u8 hw_flags_chg = 0;
1437 /* only update link state for PMD interfaces */
1438 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
1441 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1442 memset (&xd->link, 0, sizeof (xd->link));
1443 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1445 if (LINK_STATE_ELOGS)
1447 vlib_main_t *vm = vlib_get_main ();
1448 ELOG_TYPE_DECLARE (e) =
1451 "update-link-state: sw_if_index %d, admin_up %d,"
1452 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1461 ed = ELOG_DATA (&vm->elog_main, e);
1462 ed->sw_if_index = xd->vlib_sw_if_index;
1463 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1464 ed->old_link_state = (u8)
1465 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1466 ed->new_link_state = (u8) xd->link.link_status;
1469 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) &&
1470 ((xd->link.link_status != 0) ^
1471 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1474 hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
1477 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1480 switch (xd->link.link_duplex)
1482 case ETH_LINK_HALF_DUPLEX:
1483 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1485 case ETH_LINK_FULL_DUPLEX:
1486 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1492 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1495 switch (xd->link.link_speed)
1497 case ETH_SPEED_NUM_10M:
1498 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1500 case ETH_SPEED_NUM_100M:
1501 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1503 case ETH_SPEED_NUM_1G:
1504 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1506 case ETH_SPEED_NUM_10G:
1507 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1509 case ETH_SPEED_NUM_40G:
1510 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1515 clib_warning ("unknown link speed %d", xd->link.link_speed);
1521 if (LINK_STATE_ELOGS)
1523 vlib_main_t *vm = vlib_get_main ();
1525 ELOG_TYPE_DECLARE (e) =
1528 "update-link-state: sw_if_index %d, new flags %d",.format_args
1536 ed = ELOG_DATA (&vm->elog_main, e);
1537 ed->sw_if_index = xd->vlib_sw_if_index;
1538 ed->flags = hw_flags;
1540 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1545 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1547 clib_error_t *error;
1548 vnet_main_t *vnm = vnet_get_main ();
1549 dpdk_main_t *dm = &dpdk_main;
1550 ethernet_main_t *em = ðernet_main;
1552 vlib_thread_main_t *tm = vlib_get_thread_main ();
1555 error = dpdk_lib_init (dm);
1558 * Turn on the input node if we found some devices to drive
1559 * and we're not running worker threads or i/o threads
1562 if (error == 0 && vec_len (dm->devices) > 0)
1564 if (tm->n_vlib_mains == 1)
1565 vlib_node_set_state (vm, dpdk_input_node.index,
1566 VLIB_NODE_STATE_POLLING);
1568 for (i = 0; i < tm->n_vlib_mains; i++)
1569 if (vec_len (dm->devices_by_cpu[i]) > 0)
1570 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1571 VLIB_NODE_STATE_POLLING);
1575 clib_error_report (error);
1577 tm->worker_thread_release = 1;
1579 f64 now = vlib_time_now (vm);
1580 vec_foreach (xd, dm->devices)
1582 dpdk_update_link_state (xd, now);
1587 * Extra set up for bond interfaces:
1588 * 1. Setup MACs for bond interfaces and their slave links which was set
1589 * in dpdk_port_setup() but needs to be done again here to take effect.
1590 * 2. Set up info for bond interface related CLI support.
1592 int nports = rte_eth_dev_count ();
1595 for (i = 0; i < nports; i++)
1597 struct rte_eth_dev_info dev_info;
1598 rte_eth_dev_info_get (i, &dev_info);
1599 if (!dev_info.driver_name)
1600 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
1601 dev_info.driver_name = dev_info.pci_dev->driver->name;
1603 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
1605 ASSERT (dev_info.driver_name);
1606 if (strncmp (dev_info.driver_name, "rte_bond_pmd", 12) == 0)
1610 int nlink = rte_eth_bond_slaves_get (i, slink, 16);
1613 vnet_hw_interface_t *bhi;
1614 ethernet_interface_t *bei;
1617 /* Get MAC of 1st slave link */
1618 rte_eth_macaddr_get (slink[0],
1619 (struct ether_addr *) addr);
1620 /* Set MAC of bounded interface to that of 1st slave link */
1622 rte_eth_bond_mac_address_set (i,
1623 (struct ether_addr *)
1626 clib_warning ("Failed to set MAC address");
1628 /* Populate MAC of bonded interface in VPP hw tables */
1630 vnet_get_hw_interface (vnm,
1631 dm->devices[i].vlib_hw_if_index);
1633 pool_elt_at_index (em->interfaces, bhi->hw_instance);
1634 clib_memcpy (bhi->hw_address, addr, 6);
1635 clib_memcpy (bei->address, addr, 6);
1636 /* Init l3 packet size allowed on bonded interface */
1637 bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
1638 bhi->max_l3_packet_bytes[VLIB_RX] =
1639 bhi->max_l3_packet_bytes[VLIB_TX] =
1640 ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
1642 { /* for all slave links */
1643 int slave = slink[--nlink];
1644 dpdk_device_t *sdev = &dm->devices[slave];
1645 vnet_hw_interface_t *shi;
1646 vnet_sw_interface_t *ssi;
1647 /* Add MAC to all slave links except the first one */
1649 rte_eth_dev_mac_addr_add (slave,
1650 (struct ether_addr *)
1652 /* Set slaves bitmap for bonded interface */
1654 clib_bitmap_set (bhi->bond_info,
1655 sdev->vlib_hw_if_index, 1);
1656 /* Set slave link flags on slave interface */
1658 vnet_get_hw_interface (vnm, sdev->vlib_hw_if_index);
1660 vnet_get_sw_interface (vnm, sdev->vlib_sw_if_index);
1661 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1662 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1664 /* Set l3 packet size allowed as the lowest of slave */
1665 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1666 shi->max_l3_packet_bytes[VLIB_RX])
1667 bhi->max_l3_packet_bytes[VLIB_RX] =
1668 bhi->max_l3_packet_bytes[VLIB_TX] =
1669 shi->max_l3_packet_bytes[VLIB_RX];
1671 /* Set max packet size allowed as the lowest of slave */
1672 if (bhi->max_packet_bytes > shi->max_packet_bytes)
1673 bhi->max_packet_bytes = shi->max_packet_bytes;
1684 * check each time through the loop in case intervals are changed
1686 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1687 dm->link_state_poll_interval : dm->stat_poll_interval;
1689 vlib_process_wait_for_event_or_clock (vm, min_wait);
1691 if (dm->admin_up_down_in_progress)
1692 /* skip the poll if an admin up down is in progress (on any interface) */
1695 vec_foreach (xd, dm->devices)
1697 f64 now = vlib_time_now (vm);
1698 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1699 dpdk_update_counters (xd, now);
1700 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1701 dpdk_update_link_state (xd, now);
1710 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1711 .function = dpdk_process,
1712 .type = VLIB_NODE_TYPE_PROCESS,
1713 .name = "dpdk-process",
1714 .process_log2_n_stack_bytes = 17,
1719 dpdk_set_stat_poll_interval (f64 interval)
1721 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1722 return (VNET_API_ERROR_INVALID_VALUE);
1724 dpdk_main.stat_poll_interval = interval;
1730 dpdk_set_link_state_poll_interval (f64 interval)
1732 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1733 return (VNET_API_ERROR_INVALID_VALUE);
1735 dpdk_main.link_state_poll_interval = interval;
1741 dpdk_init (vlib_main_t * vm)
1743 dpdk_main_t *dm = &dpdk_main;
1745 clib_error_t *error = 0;
1746 vlib_thread_main_t *tm = vlib_get_thread_main ();
1748 /* verify that structs are cacheline aligned */
1749 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1750 "Cache line marker must be 1st element in dpdk_device_t");
1751 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1752 CLIB_CACHE_LINE_BYTES,
1753 "Data in cache line 0 is bigger than cache line size");
1754 STATIC_ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0,
1755 "Cache line marker must be 1st element in dpdk_worker_t");
1756 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1757 "Cache line marker must be 1st element in frame_queue_trace_t");
1760 dm->vnet_main = vnet_get_main ();
1761 dm->conf = &dpdk_config_main;
1763 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1765 return clib_error_return (0, "ethernet-input node AWOL");
1767 dm->ethernet_input_node_index = ei->index;
1769 dm->conf->nchannels = 4;
1770 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1771 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1773 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1774 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1775 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1777 /* $$$ use n_thread_stacks since it's known-good at this point */
1778 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1780 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1781 dm->buffer_flags_template =
1782 (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_RTE_MBUF_VALID
1783 | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT);
1785 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1786 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1789 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1795 VLIB_INIT_FUNCTION (dpdk_init);
1799 * fd.io coding-style-patch-verification: ON
1802 * eval: (c-set-style "gnu")