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)
67 vlib_main_t *vm = vlib_get_main ();
68 vlib_buffer_main_t *bm = vm->buffer_main;
72 ASSERT (os_get_cpu_number () == 0);
74 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
76 vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0);
77 rte_eth_dev_stop (xd->device_index);
80 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
81 xd->tx_q_used, &xd->port_conf);
84 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
85 xd->device_index, rv);
87 /* Set up one TX-queue per worker thread */
88 for (j = 0; j < xd->tx_q_used; j++)
90 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
91 xd->cpu_socket, &xd->tx_conf);
93 /* retry with any other CPU socket */
95 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
96 SOCKET_ID_ANY, &xd->tx_conf);
102 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
103 xd->device_index, rv);
105 for (j = 0; j < xd->rx_q_used; j++)
108 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
111 pktmbuf_pools[xd->cpu_socket_id_by_queue
114 /* retry with any other CPU socket */
116 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
119 pktmbuf_pools[xd->cpu_socket_id_by_queue
122 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
123 xd->device_index, rv);
126 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
129 rv = rte_eth_dev_start (xd->device_index);
131 clib_warning ("rte_eth_dev_start %d returned %d",
132 xd->device_index, rv);
138 dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
140 dpdk_main_t *dm = &dpdk_main;
141 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
144 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC (flags))
146 old = (xd->flags & DPDK_DEVICE_FLAG_PROMISC) != 0;
148 if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
149 xd->flags |= DPDK_DEVICE_FLAG_PROMISC;
151 xd->flags &= ~DPDK_DEVICE_FLAG_PROMISC;
153 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
155 if (xd->flags & DPDK_DEVICE_FLAG_PROMISC)
156 rte_eth_promiscuous_enable (xd->device_index);
158 rte_eth_promiscuous_disable (xd->device_index);
161 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU (flags))
164 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
165 * driver to dynamically change the mtu. If/when the
166 * VIC firmware gets fixed, then this should be removed.
168 if (xd->pmd == VNET_DPDK_PMD_ENIC)
170 struct rte_eth_dev_info dev_info;
173 * Restore mtu to what has been set by CIMC in the firmware cfg.
175 rte_eth_dev_info_get (xd->device_index, &dev_info);
176 hi->max_packet_bytes = dev_info.max_rx_pktlen;
178 vlib_cli_output (vlib_get_main (),
179 "Cisco VIC mtu can only be changed "
180 "using CIMC then rebooting the server!");
186 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
188 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
189 rte_eth_dev_stop (xd->device_index);
191 rv = rte_eth_dev_configure
192 (xd->device_index, xd->rx_q_used, xd->tx_q_used, &xd->port_conf);
195 vlib_cli_output (vlib_get_main (),
196 "rte_eth_dev_configure[%d]: err %d",
197 xd->device_index, rv);
199 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
201 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
203 int rv = rte_eth_dev_start (xd->device_index);
205 clib_warning ("rte_eth_dev_start %d returned %d",
206 xd->device_index, rv);
214 dpdk_device_lock_init (dpdk_device_t * xd)
217 vec_validate (xd->lockp, xd->tx_q_used - 1);
218 for (q = 0; q < xd->tx_q_used; q++)
220 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
221 CLIB_CACHE_LINE_BYTES);
222 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
227 dpdk_device_lock_free (dpdk_device_t * xd)
231 for (q = 0; q < vec_len (xd->lockp); q++)
232 clib_mem_free ((void *) xd->lockp[q]);
233 vec_free (xd->lockp);
237 static clib_error_t *
238 dpdk_lib_init (dpdk_main_t * dm)
244 vlib_main_t *vm = vlib_get_main ();
245 vlib_thread_main_t *tm = vlib_get_thread_main ();
246 vnet_sw_interface_t *sw;
247 vnet_hw_interface_t *hi;
249 vlib_pci_addr_t last_pci_addr;
250 u32 last_pci_addr_port = 0;
251 vlib_thread_registration_t *tr, *tr_hqos;
254 u32 next_cpu = 0, next_hqos_cpu = 0;
255 u8 af_packet_port_id = 0;
256 last_pci_addr.as_u32 = ~0;
258 dm->input_cpu_first_index = 0;
259 dm->input_cpu_count = 1;
261 /* find out which cpus will be used for input */
262 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
263 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
265 if (tr && tr->count > 0)
267 dm->input_cpu_first_index = tr->first_index;
268 dm->input_cpu_count = tr->count;
271 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
272 CLIB_CACHE_LINE_BYTES);
274 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
275 CLIB_CACHE_LINE_BYTES);
277 dm->hqos_cpu_first_index = 0;
278 dm->hqos_cpu_count = 0;
280 /* find out which cpus will be used for I/O TX */
281 p_hqos = hash_get_mem (tm->thread_registrations_by_name, "hqos-threads");
282 tr_hqos = p_hqos ? (vlib_thread_registration_t *) p_hqos[0] : 0;
284 if (tr_hqos && tr_hqos->count > 0)
286 dm->hqos_cpu_first_index = tr_hqos->first_index;
287 dm->hqos_cpu_count = tr_hqos->count;
290 vec_validate_aligned (dm->devices_by_hqos_cpu, tm->n_vlib_mains - 1,
291 CLIB_CACHE_LINE_BYTES);
293 vec_validate_aligned (dm->hqos_threads, tm->n_vlib_mains - 1,
294 CLIB_CACHE_LINE_BYTES);
296 nports = rte_eth_dev_count ();
299 clib_warning ("DPDK drivers found no ports...");
303 clib_warning ("DPDK drivers found %d ports...", nports);
306 * All buffers are all allocated from the same rte_mempool.
307 * Thus they all have the same number of data bytes.
309 dm->vlib_buffer_free_list_index =
310 vlib_buffer_get_or_create_free_list (vm,
311 VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
314 if (dm->conf->enable_tcp_udp_checksum)
315 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
316 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
318 for (i = 0; i < nports; i++)
323 struct rte_eth_dev_info dev_info;
325 struct rte_eth_link l;
326 dpdk_device_config_t *devconf = 0;
327 vlib_pci_addr_t pci_addr;
330 rte_eth_dev_info_get (i, &dev_info);
331 if (dev_info.pci_dev) /* bonded interface has no pci info */
333 pci_addr.domain = dev_info.pci_dev->addr.domain;
334 pci_addr.bus = dev_info.pci_dev->addr.bus;
335 pci_addr.slot = dev_info.pci_dev->addr.devid;
336 pci_addr.function = dev_info.pci_dev->addr.function;
338 hash_get (dm->conf->device_config_index_by_pci_addr,
343 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
345 devconf = &dm->conf->default_devconf;
347 /* Create vnet interface */
348 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
349 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
350 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
351 xd->cpu_socket = (i8) rte_eth_dev_socket_id (i);
353 /* Handle interface naming for devices with multiple ports sharing same PCI ID */
354 if (dev_info.pci_dev)
356 struct rte_eth_dev_info di = { 0 };
357 rte_eth_dev_info_get (i + 1, &di);
358 if (di.pci_dev && pci_addr.as_u32 != last_pci_addr.as_u32 &&
359 memcmp (&dev_info.pci_dev->addr, &di.pci_dev->addr,
360 sizeof (struct rte_pci_addr)) == 0)
362 xd->interface_name_suffix = format (0, "0");
363 last_pci_addr.as_u32 = pci_addr.as_u32;
364 last_pci_addr_port = i;
366 else if (pci_addr.as_u32 == last_pci_addr.as_u32)
368 xd->interface_name_suffix =
369 format (0, "%u", i - last_pci_addr_port);
373 last_pci_addr.as_u32 = ~0;
377 last_pci_addr.as_u32 = ~0;
379 clib_memcpy (&xd->tx_conf, &dev_info.default_txconf,
380 sizeof (struct rte_eth_txconf));
381 if (dm->conf->no_multi_seg)
383 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
384 port_conf_template.rxmode.jumbo_frame = 0;
388 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
389 port_conf_template.rxmode.jumbo_frame = 1;
390 xd->flags |= DPDK_DEVICE_FLAG_MAYBE_MULTISEG;
393 clib_memcpy (&xd->port_conf, &port_conf_template,
394 sizeof (struct rte_eth_conf));
396 xd->tx_q_used = clib_min (dev_info.max_tx_queues, tm->n_vlib_mains);
398 if (devconf->num_tx_queues > 0
399 && devconf->num_tx_queues < xd->tx_q_used)
400 xd->tx_q_used = clib_min (xd->tx_q_used, devconf->num_tx_queues);
402 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
407 if (devconf->num_rx_queues > 1
408 && dev_info.max_rx_queues >= devconf->num_rx_queues)
410 xd->rx_q_used = devconf->num_rx_queues;
411 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
412 if (devconf->rss_fn == 0)
413 xd->port_conf.rx_adv_conf.rss_conf.rss_hf =
414 ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
416 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn;
421 xd->flags |= DPDK_DEVICE_FLAG_PMD;
423 /* workaround for drivers not setting driver_name */
424 if ((!dev_info.driver_name) && (dev_info.pci_dev))
425 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
426 dev_info.driver_name = dev_info.pci_dev->driver->name;
428 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
430 ASSERT (dev_info.driver_name);
436 #define _(s,f) else if (dev_info.driver_name && \
437 !strcmp(dev_info.driver_name, s)) \
438 xd->pmd = VNET_DPDK_PMD_##f;
444 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
446 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
447 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
448 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
453 case VNET_DPDK_PMD_E1000EM:
454 case VNET_DPDK_PMD_IGB:
455 case VNET_DPDK_PMD_IGBVF:
456 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
460 case VNET_DPDK_PMD_IXGBE:
461 case VNET_DPDK_PMD_IXGBEVF:
462 case VNET_DPDK_PMD_THUNDERX:
463 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
465 case VNET_DPDK_PMD_DPAA2:
466 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
470 case VNET_DPDK_PMD_ENIC:
471 rte_eth_link_get_nowait (i, &l);
472 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
473 if (l.link_speed == 40000)
474 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
476 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
479 /* Intel Fortville */
480 case VNET_DPDK_PMD_I40E:
481 case VNET_DPDK_PMD_I40EVF:
482 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
483 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
485 switch (dev_info.pci_dev->id.device_id)
487 case I40E_DEV_ID_10G_BASE_T:
488 case I40E_DEV_ID_SFP_XL710:
489 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
491 case I40E_DEV_ID_QSFP_A:
492 case I40E_DEV_ID_QSFP_B:
493 case I40E_DEV_ID_QSFP_C:
494 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
497 rte_eth_link_get_nowait (i, &l);
498 xd->port_type = l.link_speed == 10000 ?
499 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
502 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
506 case VNET_DPDK_PMD_CXGBE:
507 switch (dev_info.pci_dev->id.device_id)
509 case 0x540d: /* T580-CR */
510 case 0x5410: /* T580-LP-cr */
511 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
513 case 0x5403: /* T540-CR */
514 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
517 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
521 case VNET_DPDK_PMD_MLX5:
523 char *pn_100g[] = { "MCX415A-CCAT", "MCX416A-CCAT", 0 };
524 char *pn_40g[] = { "MCX413A-BCAT", "MCX414A-BCAT",
525 "MCX415A-BCAT", "MCX416A-BCAT", "MCX4131A-BCAT", 0
527 char *pn_10g[] = { "MCX4111A-XCAT", "MCX4121A-XCAT", 0 };
529 vlib_pci_device_t *pd = vlib_get_pci_device (&pci_addr);
533 pn = format (0, "%U%c",
534 format_vlib_pci_vpd, pd->vpd_r, "PN", 0);
540 while (!found && c[0])
542 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
544 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_100G;
551 while (!found && c[0])
553 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
555 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
562 while (!found && c[0])
564 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
566 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
576 /* Intel Red Rock Canyon */
577 case VNET_DPDK_PMD_FM10K:
578 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
582 case VNET_DPDK_PMD_VIRTIO:
583 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
584 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
585 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
589 case VNET_DPDK_PMD_VMXNET3:
590 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
591 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
594 case VNET_DPDK_PMD_AF_PACKET:
595 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
596 xd->af_packet_port_id = af_packet_port_id++;
599 case VNET_DPDK_PMD_BOND:
600 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
601 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
605 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
608 if (devconf->num_rx_desc)
609 xd->nb_rx_desc = devconf->num_rx_desc;
611 if (devconf->num_tx_desc)
612 xd->nb_tx_desc = devconf->num_tx_desc;
616 * Ensure default mtu is not > the mtu read from the hardware.
617 * Otherwise rte_eth_dev_configure() will fail and the port will
620 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
623 * This device does not support the platforms's max frame
624 * size. Use it's advertised mru instead.
626 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
630 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
633 * Some platforms do not account for Ethernet FCS (4 bytes) in
634 * MTU calculations. To interop with them increase mru but only
635 * if the device's settings can support it.
637 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
638 xd->port_conf.rxmode.hw_strip_crc)
641 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
642 * stripped by h/w and so will not consume any buffer memory.
644 xd->port_conf.rxmode.max_rx_pkt_len += 4;
648 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
650 f64 now = vlib_time_now (vm);
652 rnd = (u32) (now * 1e6);
653 rnd = random_u32 (&rnd);
654 clib_memcpy (addr + 2, &rnd, sizeof (rnd));
659 rte_eth_macaddr_get (i, (struct ether_addr *) addr);
661 if (xd->tx_q_used < tm->n_vlib_mains)
662 dpdk_device_lock_init (xd);
664 xd->device_index = xd - dm->devices;
665 ASSERT (i == xd->device_index);
666 xd->per_interface_next_index = ~0;
668 /* assign interface to input thread */
669 dpdk_device_and_queue_t *dq;
672 if (devconf->workers)
677 clib_bitmap_foreach (i, devconf->workers, ({
678 int cpu = dm->input_cpu_first_index + i;
679 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
680 vec_validate(xd->cpu_socket_id_by_queue, q);
681 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
682 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
683 dq->device = xd->device_index;
689 for (q = 0; q < xd->rx_q_used; q++)
691 int cpu = dm->input_cpu_first_index + next_cpu;
692 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
695 * numa node for worker thread handling this queue
696 * needed for taking buffers from the right mempool
698 vec_validate (xd->cpu_socket_id_by_queue, q);
699 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id (lcore);
702 * construct vector of (device,queue) pairs for each worker thread
704 vec_add2 (dm->devices_by_cpu[cpu], dq, 1);
705 dq->device = xd->device_index;
709 if (next_cpu == dm->input_cpu_count)
714 if (devconf->hqos_enabled)
716 xd->flags |= DPDK_DEVICE_FLAG_HQOS;
718 if (devconf->hqos.hqos_thread_valid)
720 int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread;
722 if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count)
723 return clib_error_return (0, "invalid HQoS thread index");
725 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
726 dq->device = xd->device_index;
731 int cpu = dm->hqos_cpu_first_index + next_hqos_cpu;
733 if (dm->hqos_cpu_count == 0)
734 return clib_error_return (0, "no HQoS threads available");
736 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
737 dq->device = xd->device_index;
741 if (next_hqos_cpu == dm->hqos_cpu_count)
744 devconf->hqos.hqos_thread_valid = 1;
745 devconf->hqos.hqos_thread = cpu;
749 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
750 CLIB_CACHE_LINE_BYTES);
751 for (j = 0; j < tm->n_vlib_mains; j++)
753 vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
754 sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
755 vec_reset_length (xd->tx_vectors[j]);
758 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
759 CLIB_CACHE_LINE_BYTES);
760 for (j = 0; j < xd->rx_q_used; j++)
762 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
763 CLIB_CACHE_LINE_BYTES);
764 vec_reset_length (xd->rx_vectors[j]);
767 vec_validate_aligned (xd->d_trace_buffers, tm->n_vlib_mains,
768 CLIB_CACHE_LINE_BYTES);
770 rv = dpdk_port_setup (dm, xd);
775 if (devconf->hqos_enabled)
777 rv = dpdk_port_setup_hqos (xd, &devconf->hqos);
782 /* count the number of descriptors used for this device */
783 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
785 error = ethernet_register_interface
786 (dm->vnet_main, dpdk_device_class.index, xd->device_index,
787 /* ethernet address */ addr,
788 &xd->vlib_hw_if_index, dpdk_flag_change);
792 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
793 xd->vlib_sw_if_index = sw->sw_if_index;
794 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
797 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
798 * driver to dynamically change the mtu. If/when the
799 * VIC firmware gets fixed, then this should be removed.
801 if (xd->pmd == VNET_DPDK_PMD_ENIC)
804 * Initialize mtu to what has been set by CIMC in the firmware cfg.
806 hi->max_packet_bytes = dev_info.max_rx_pktlen;
807 if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF)
808 vlan_strip = 1; /* remove vlan tag from VIC port by default */
810 clib_warning ("VLAN strip disabled for interface\n");
812 else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON)
818 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
819 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
820 xd->port_conf.rxmode.hw_vlan_strip = vlan_off;
821 if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0)
822 clib_warning ("VLAN strip enabled for interface\n");
824 clib_warning ("VLAN strip cannot be supported by interface\n");
827 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
828 xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t);
830 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
833 if (nb_desc > dm->conf->num_mbufs)
834 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
835 dm->conf->num_mbufs, nb_desc);
841 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
843 vlib_pci_main_t *pm = &pci_main;
845 vlib_pci_device_t *d;
847 int num_whitelisted = vec_len (conf->dev_confs);
850 pool_foreach (d, pm->pci_devs, ({
851 dpdk_device_config_t * devconf = 0;
852 vec_reset_length (pci_addr);
853 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
855 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET)
860 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
865 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
869 if (d->vendor_id == 0x1af4 && d->device_id == 0x1000)
872 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
874 /* all Intel devices */
875 else if (d->vendor_id == 0x8086)
878 else if (d->vendor_id == 0x1137 && d->device_id == 0x0043)
881 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
885 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
886 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
891 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
897 pool_get (conf->dev_confs, devconf);
898 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
899 devconf - conf->dev_confs);
900 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
902 devconf->is_blacklisted = 1;
903 clib_error_report (error);
910 static clib_error_t *
911 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
912 unformat_input_t * input, u8 is_default)
914 clib_error_t *error = 0;
916 dpdk_device_config_t *devconf;
917 unformat_input_t sub_input;
921 devconf = &conf->default_devconf;
925 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
929 pool_get (conf->dev_confs, devconf);
930 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32,
931 devconf - conf->dev_confs);
934 return clib_error_return (0,
935 "duplicate configuration for PCI address %U",
936 format_vlib_pci_addr, &pci_addr);
939 devconf->pci_addr.as_u32 = pci_addr.as_u32;
940 devconf->hqos_enabled = 0;
941 dpdk_device_config_hqos_default (&devconf->hqos);
946 unformat_skip_white_space (input);
947 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
949 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
951 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
953 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
955 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
957 else if (unformat (input, "workers %U", unformat_bitmap_list,
962 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
964 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
968 else if (unformat (input, "vlan-strip-offload off"))
969 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF;
970 else if (unformat (input, "vlan-strip-offload on"))
971 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON;
974 (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input))
976 devconf->hqos_enabled = 1;
977 error = unformat_hqos (&sub_input, &devconf->hqos);
981 else if (unformat (input, "hqos"))
983 devconf->hqos_enabled = 1;
987 error = clib_error_return (0, "unknown input `%U'",
988 format_unformat_error, input);
996 if (devconf->workers && devconf->num_rx_queues == 0)
997 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
998 else if (devconf->workers &&
999 clib_bitmap_count_set_bits (devconf->workers) !=
1000 devconf->num_rx_queues)
1002 clib_error_return (0,
1003 "%U: number of worker threadds must be "
1004 "equal to number of rx queues", format_vlib_pci_addr,
1010 static clib_error_t *
1011 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
1013 clib_error_t *error = 0;
1014 dpdk_main_t *dm = &dpdk_main;
1015 dpdk_config_main_t *conf = &dpdk_config_main;
1016 vlib_thread_main_t *tm = vlib_get_thread_main ();
1017 dpdk_device_config_t *devconf;
1018 vlib_pci_addr_t pci_addr;
1019 unformat_input_t sub_input;
1021 u8 *rte_cmd = 0, *ethname = 0;
1024 int num_whitelisted = 0;
1031 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
1033 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1035 /* Prime the pump */
1036 if (unformat (input, "no-hugetlb"))
1038 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
1042 else if (unformat (input, "enable-tcp-udp-checksum"))
1043 conf->enable_tcp_udp_checksum = 1;
1045 else if (unformat (input, "decimal-interface-names"))
1046 conf->interface_name_format_decimal = 1;
1048 else if (unformat (input, "no-multi-seg"))
1049 conf->no_multi_seg = 1;
1051 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
1055 dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input,
1063 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1064 unformat_vlib_cli_sub_input, &sub_input))
1066 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
1073 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1075 error = dpdk_device_config (conf, pci_addr, 0, 0);
1082 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1084 else if (unformat (input, "kni %d", &conf->num_kni))
1086 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1088 else if (unformat (input, "socket-mem %s", &socket_mem))
1090 else if (unformat (input, "no-pci"))
1093 tmp = format (0, "--no-pci%c", 0);
1094 vec_add1 (conf->eal_init_args, tmp);
1096 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep))
1100 else if (unformat(input, #a)) \
1102 tmp = format (0, "--%s%c", #a, 0); \
1103 vec_add1 (conf->eal_init_args, tmp); \
1105 foreach_eal_double_hyphen_predicate_arg
1108 else if (unformat(input, #a " %s", &s)) \
1110 if (!strncmp(#a, "huge-dir", 8)) \
1112 else if (!strncmp(#a, "file-prefix", 11)) \
1114 tmp = format (0, "--%s%c", #a, 0); \
1115 vec_add1 (conf->eal_init_args, tmp); \
1117 vec_add1 (conf->eal_init_args, s); \
1119 foreach_eal_double_hyphen_arg
1122 else if (unformat(input, #a " %s", &s)) \
1124 tmp = format (0, "-%s%c", #b, 0); \
1125 vec_add1 (conf->eal_init_args, tmp); \
1127 vec_add1 (conf->eal_init_args, s); \
1129 foreach_eal_single_hyphen_arg
1132 else if (unformat(input, #a " %s", &s)) \
1134 tmp = format (0, "-%s%c", #b, 0); \
1135 vec_add1 (conf->eal_init_args, tmp); \
1137 vec_add1 (conf->eal_init_args, s); \
1138 conf->a##_set_manually = 1; \
1140 foreach_eal_single_hyphen_mandatory_arg
1142 else if (unformat (input, "default"))
1145 else if (unformat_skip_white_space (input))
1149 error = clib_error_return (0, "unknown input `%U'",
1150 format_unformat_error, input);
1155 if (!conf->uio_driver_name)
1156 conf->uio_driver_name = format (0, "igb_uio%c", 0);
1159 * Use 1G huge pages if available.
1161 if (!no_huge && !huge_dir)
1163 u32 x, *mem_by_socket = 0;
1167 u8 less_than_1g = 1;
1170 umount (DEFAULT_HUGE_DIR);
1172 /* Process "socket-mem" parameter value */
1173 if (vec_len (socket_mem))
1175 unformat_input_t in;
1176 unformat_init_vector (&in, socket_mem);
1177 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1179 if (unformat (&in, "%u,", &x))
1181 else if (unformat (&in, "%u", &x))
1183 else if (unformat (&in, ","))
1188 vec_add1 (mem_by_socket, x);
1193 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1194 unformat_free (&in);
1200 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1202 vec_validate(mem_by_socket, c);
1203 mem_by_socket[c] = 256; /* default per-socket mem */
1209 /* check if available enough 1GB pages for each socket */
1211 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1213 int pages_avail, page_size, mem;
1215 vec_validate(mem_by_socket, c);
1216 mem = mem_by_socket[c];
1219 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1221 if (pages_avail < 0 || page_size * pages_avail < mem)
1225 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1227 if (pages_avail < 0 || page_size * pages_avail < mem)
1232 if (mem_by_socket == 0)
1234 error = clib_error_return (0, "mem_by_socket NULL");
1237 _vec_len (mem_by_socket) = c + 1;
1239 /* regenerate socket_mem string */
1240 vec_foreach_index (x, mem_by_socket)
1241 socket_mem = format (socket_mem, "%s%u",
1242 socket_mem ? "," : "", mem_by_socket[x]);
1243 socket_mem = format (socket_mem, "%c", 0);
1245 vec_free (mem_by_socket);
1247 rv = mkdir (VPP_RUN_DIR, 0755);
1248 if (rv && errno != EEXIST)
1250 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1251 VPP_RUN_DIR, errno);
1255 rv = mkdir (DEFAULT_HUGE_DIR, 0755);
1256 if (rv && errno != EEXIST)
1258 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1259 DEFAULT_HUGE_DIR, errno);
1263 if (use_1g && !(less_than_1g && use_2m))
1266 mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1270 rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1274 return clib_error_return (0, "not enough free huge pages");
1279 error = clib_error_return (0, "mount failed %d", errno);
1283 tmp = format (0, "--huge-dir%c", 0);
1284 vec_add1 (conf->eal_init_args, tmp);
1285 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1286 vec_add1 (conf->eal_init_args, tmp);
1289 tmp = format (0, "--file-prefix%c", 0);
1290 vec_add1 (conf->eal_init_args, tmp);
1291 tmp = format (0, "vpp%c", 0);
1292 vec_add1 (conf->eal_init_args, tmp);
1302 /* I'll bet that -c and -n must be the first and second args... */
1303 if (!conf->coremask_set_manually)
1305 vlib_thread_registration_t *tr;
1306 uword *coremask = 0;
1309 /* main thread core */
1310 coremask = clib_bitmap_set (coremask, tm->main_lcore, 1);
1312 for (i = 0; i < vec_len (tm->registrations); i++)
1314 tr = tm->registrations[i];
1315 coremask = clib_bitmap_or (coremask, tr->coremask);
1318 vec_insert (conf->eal_init_args, 2, 1);
1319 conf->eal_init_args[1] = (u8 *) "-c";
1320 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1321 conf->eal_init_args[2] = tmp;
1322 clib_bitmap_free (coremask);
1325 if (!conf->nchannels_set_manually)
1327 vec_insert (conf->eal_init_args, 2, 3);
1328 conf->eal_init_args[3] = (u8 *) "-n";
1329 tmp = format (0, "%d", conf->nchannels);
1330 conf->eal_init_args[4] = tmp;
1333 if (no_pci == 0 && geteuid () == 0)
1334 dpdk_bind_devices_to_uio (conf);
1337 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1338 devconf->x = conf->default_devconf.x ;
1341 pool_foreach (devconf, conf->dev_confs, ({
1343 /* default per-device config items */
1344 foreach_dpdk_device_config_item
1346 /* add DPDK EAL whitelist/blacklist entry */
1347 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1349 tmp = format (0, "-w%c", 0);
1350 vec_add1 (conf->eal_init_args, tmp);
1351 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1352 vec_add1 (conf->eal_init_args, tmp);
1354 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1356 tmp = format (0, "-b%c", 0);
1357 vec_add1 (conf->eal_init_args, tmp);
1358 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1359 vec_add1 (conf->eal_init_args, tmp);
1366 /* set master-lcore */
1367 tmp = format (0, "--master-lcore%c", 0);
1368 vec_add1 (conf->eal_init_args, tmp);
1369 tmp = format (0, "%u%c", tm->main_lcore, 0);
1370 vec_add1 (conf->eal_init_args, tmp);
1372 /* set socket-mem */
1373 tmp = format (0, "--socket-mem%c", 0);
1374 vec_add1 (conf->eal_init_args, tmp);
1375 tmp = format (0, "%s%c", socket_mem, 0);
1376 vec_add1 (conf->eal_init_args, tmp);
1378 /* NULL terminate the "argv" vector, in case of stupidity */
1379 vec_add1 (conf->eal_init_args, 0);
1380 _vec_len (conf->eal_init_args) -= 1;
1382 /* Set up DPDK eal and packet mbuf pool early. */
1384 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1386 rte_set_log_level (log_level);
1388 vm = vlib_get_main ();
1390 /* make copy of args as rte_eal_init tends to mess up with arg array */
1391 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1392 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1393 conf->eal_init_args[i]);
1396 rte_eal_init (vec_len (conf->eal_init_args),
1397 (char **) conf->eal_init_args);
1399 /* lazy umount hugepages */
1400 umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
1403 return clib_error_return (0, "rte_eal_init returned %d", ret);
1405 /* Dump the physical memory layout prior to creating the mbuf_pool */
1406 fprintf (stdout, "DPDK physical memory layout:\n");
1407 rte_dump_physmem_layout (stdout);
1409 /* main thread 1st */
1410 error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ());
1414 for (i = 0; i < RTE_MAX_LCORE; i++)
1416 error = vlib_buffer_pool_create (vm, conf->num_mbufs,
1417 rte_lcore_to_socket_id (i));
1426 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1429 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1431 vnet_main_t *vnm = vnet_get_main ();
1432 struct rte_eth_link prev_link = xd->link;
1434 u8 hw_flags_chg = 0;
1436 /* only update link state for PMD interfaces */
1437 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
1440 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1441 memset (&xd->link, 0, sizeof (xd->link));
1442 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1444 if (LINK_STATE_ELOGS)
1446 vlib_main_t *vm = vlib_get_main ();
1447 ELOG_TYPE_DECLARE (e) =
1450 "update-link-state: sw_if_index %d, admin_up %d,"
1451 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1460 ed = ELOG_DATA (&vm->elog_main, e);
1461 ed->sw_if_index = xd->vlib_sw_if_index;
1462 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1463 ed->old_link_state = (u8)
1464 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1465 ed->new_link_state = (u8) xd->link.link_status;
1468 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) &&
1469 ((xd->link.link_status != 0) ^
1470 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1473 hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
1476 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1479 switch (xd->link.link_duplex)
1481 case ETH_LINK_HALF_DUPLEX:
1482 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1484 case ETH_LINK_FULL_DUPLEX:
1485 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1491 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1494 switch (xd->link.link_speed)
1496 case ETH_SPEED_NUM_10M:
1497 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1499 case ETH_SPEED_NUM_100M:
1500 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1502 case ETH_SPEED_NUM_1G:
1503 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1505 case ETH_SPEED_NUM_10G:
1506 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1508 case ETH_SPEED_NUM_40G:
1509 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1514 clib_warning ("unknown link speed %d", xd->link.link_speed);
1520 if (LINK_STATE_ELOGS)
1522 vlib_main_t *vm = vlib_get_main ();
1524 ELOG_TYPE_DECLARE (e) =
1527 "update-link-state: sw_if_index %d, new flags %d",.format_args
1535 ed = ELOG_DATA (&vm->elog_main, e);
1536 ed->sw_if_index = xd->vlib_sw_if_index;
1537 ed->flags = hw_flags;
1539 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1544 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1546 clib_error_t *error;
1547 vnet_main_t *vnm = vnet_get_main ();
1548 dpdk_main_t *dm = &dpdk_main;
1549 ethernet_main_t *em = ðernet_main;
1551 vlib_thread_main_t *tm = vlib_get_thread_main ();
1554 error = dpdk_lib_init (dm);
1557 * Turn on the input node if we found some devices to drive
1558 * and we're not running worker threads or i/o threads
1561 if (error == 0 && vec_len (dm->devices) > 0)
1563 if (tm->n_vlib_mains == 1)
1564 vlib_node_set_state (vm, dpdk_input_node.index,
1565 VLIB_NODE_STATE_POLLING);
1567 for (i = 0; i < tm->n_vlib_mains; i++)
1568 if (vec_len (dm->devices_by_cpu[i]) > 0)
1569 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1570 VLIB_NODE_STATE_POLLING);
1574 clib_error_report (error);
1576 tm->worker_thread_release = 1;
1578 f64 now = vlib_time_now (vm);
1579 vec_foreach (xd, dm->devices)
1581 dpdk_update_link_state (xd, now);
1586 * Extra set up for bond interfaces:
1587 * 1. Setup MACs for bond interfaces and their slave links which was set
1588 * in dpdk_port_setup() but needs to be done again here to take effect.
1589 * 2. Set up info for bond interface related CLI support.
1591 int nports = rte_eth_dev_count ();
1594 for (i = 0; i < nports; i++)
1596 struct rte_eth_dev_info dev_info;
1597 rte_eth_dev_info_get (i, &dev_info);
1598 if (!dev_info.driver_name)
1599 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
1600 dev_info.driver_name = dev_info.pci_dev->driver->name;
1602 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
1604 ASSERT (dev_info.driver_name);
1605 if (strncmp (dev_info.driver_name, "rte_bond_pmd", 12) == 0)
1609 int nlink = rte_eth_bond_slaves_get (i, slink, 16);
1612 vnet_hw_interface_t *bhi;
1613 ethernet_interface_t *bei;
1616 /* Get MAC of 1st slave link */
1617 rte_eth_macaddr_get (slink[0],
1618 (struct ether_addr *) addr);
1619 /* Set MAC of bounded interface to that of 1st slave link */
1621 rte_eth_bond_mac_address_set (i,
1622 (struct ether_addr *)
1625 clib_warning ("Failed to set MAC address");
1627 /* Populate MAC of bonded interface in VPP hw tables */
1629 vnet_get_hw_interface (vnm,
1630 dm->devices[i].vlib_hw_if_index);
1632 pool_elt_at_index (em->interfaces, bhi->hw_instance);
1633 clib_memcpy (bhi->hw_address, addr, 6);
1634 clib_memcpy (bei->address, addr, 6);
1635 /* Init l3 packet size allowed on bonded interface */
1636 bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
1637 bhi->max_l3_packet_bytes[VLIB_RX] =
1638 bhi->max_l3_packet_bytes[VLIB_TX] =
1639 ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
1641 { /* for all slave links */
1642 int slave = slink[--nlink];
1643 dpdk_device_t *sdev = &dm->devices[slave];
1644 vnet_hw_interface_t *shi;
1645 vnet_sw_interface_t *ssi;
1646 /* Add MAC to all slave links except the first one */
1648 rte_eth_dev_mac_addr_add (slave,
1649 (struct ether_addr *)
1651 /* Set slaves bitmap for bonded interface */
1653 clib_bitmap_set (bhi->bond_info,
1654 sdev->vlib_hw_if_index, 1);
1655 /* Set slave link flags on slave interface */
1657 vnet_get_hw_interface (vnm, sdev->vlib_hw_if_index);
1659 vnet_get_sw_interface (vnm, sdev->vlib_sw_if_index);
1660 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1661 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1663 /* Set l3 packet size allowed as the lowest of slave */
1664 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1665 shi->max_l3_packet_bytes[VLIB_RX])
1666 bhi->max_l3_packet_bytes[VLIB_RX] =
1667 bhi->max_l3_packet_bytes[VLIB_TX] =
1668 shi->max_l3_packet_bytes[VLIB_RX];
1670 /* Set max packet size allowed as the lowest of slave */
1671 if (bhi->max_packet_bytes > shi->max_packet_bytes)
1672 bhi->max_packet_bytes = shi->max_packet_bytes;
1683 * check each time through the loop in case intervals are changed
1685 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1686 dm->link_state_poll_interval : dm->stat_poll_interval;
1688 vlib_process_wait_for_event_or_clock (vm, min_wait);
1690 if (dm->admin_up_down_in_progress)
1691 /* skip the poll if an admin up down is in progress (on any interface) */
1694 vec_foreach (xd, dm->devices)
1696 f64 now = vlib_time_now (vm);
1697 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1698 dpdk_update_counters (xd, now);
1699 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1700 dpdk_update_link_state (xd, now);
1709 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1710 .function = dpdk_process,
1711 .type = VLIB_NODE_TYPE_PROCESS,
1712 .name = "dpdk-process",
1713 .process_log2_n_stack_bytes = 17,
1718 dpdk_set_stat_poll_interval (f64 interval)
1720 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1721 return (VNET_API_ERROR_INVALID_VALUE);
1723 dpdk_main.stat_poll_interval = interval;
1729 dpdk_set_link_state_poll_interval (f64 interval)
1731 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1732 return (VNET_API_ERROR_INVALID_VALUE);
1734 dpdk_main.link_state_poll_interval = interval;
1740 dpdk_init (vlib_main_t * vm)
1742 dpdk_main_t *dm = &dpdk_main;
1744 clib_error_t *error = 0;
1745 vlib_thread_main_t *tm = vlib_get_thread_main ();
1747 /* verify that structs are cacheline aligned */
1748 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1749 "Cache line marker must be 1st element in dpdk_device_t");
1750 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1751 CLIB_CACHE_LINE_BYTES,
1752 "Data in cache line 0 is bigger than cache line size");
1753 STATIC_ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0,
1754 "Cache line marker must be 1st element in dpdk_worker_t");
1755 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1756 "Cache line marker must be 1st element in frame_queue_trace_t");
1759 dm->vnet_main = vnet_get_main ();
1760 dm->conf = &dpdk_config_main;
1762 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1764 return clib_error_return (0, "ethernet-input node AWOL");
1766 dm->ethernet_input_node_index = ei->index;
1768 dm->conf->nchannels = 4;
1769 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1770 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1772 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1773 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1774 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1776 /* $$$ use n_thread_stacks since it's known-good at this point */
1777 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1779 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1780 dm->buffer_flags_template =
1781 (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_RTE_MBUF_VALID
1782 | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT);
1784 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1785 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1788 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1794 VLIB_INIT_FUNCTION (dpdk_init);
1798 * fd.io coding-style-patch-verification: ON
1801 * eval: (c-set-style "gnu")