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 vlib_node_runtime_t *rt;
247 vnet_sw_interface_t *sw;
248 vnet_hw_interface_t *hi;
250 vlib_pci_addr_t last_pci_addr;
251 u32 last_pci_addr_port = 0;
252 vlib_thread_registration_t *tr, *tr_hqos;
255 u32 next_cpu = 0, next_hqos_cpu = 0;
256 u8 af_packet_port_id = 0;
257 last_pci_addr.as_u32 = ~0;
259 dm->input_cpu_first_index = 0;
260 dm->input_cpu_count = 1;
262 rt = vlib_node_get_runtime (vm, dpdk_input_node.index);
263 rt->function = dpdk_input_multiarch_select ();
265 /* find out which cpus will be used for input */
266 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
267 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
269 if (tr && tr->count > 0)
271 dm->input_cpu_first_index = tr->first_index;
272 dm->input_cpu_count = tr->count;
275 vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1,
276 CLIB_CACHE_LINE_BYTES);
278 vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1,
279 CLIB_CACHE_LINE_BYTES);
281 dm->hqos_cpu_first_index = 0;
282 dm->hqos_cpu_count = 0;
284 /* find out which cpus will be used for I/O TX */
285 p_hqos = hash_get_mem (tm->thread_registrations_by_name, "hqos-threads");
286 tr_hqos = p_hqos ? (vlib_thread_registration_t *) p_hqos[0] : 0;
288 if (tr_hqos && tr_hqos->count > 0)
290 dm->hqos_cpu_first_index = tr_hqos->first_index;
291 dm->hqos_cpu_count = tr_hqos->count;
294 vec_validate_aligned (dm->devices_by_hqos_cpu, tm->n_vlib_mains - 1,
295 CLIB_CACHE_LINE_BYTES);
297 vec_validate_aligned (dm->hqos_threads, tm->n_vlib_mains - 1,
298 CLIB_CACHE_LINE_BYTES);
301 if (rte_netmap_probe () < 0)
302 return clib_error_return (0, "rte netmap probe failed");
305 nports = rte_eth_dev_count ();
308 clib_warning ("DPDK drivers found no ports...");
312 clib_warning ("DPDK drivers found %d ports...", nports);
315 * All buffers are all allocated from the same rte_mempool.
316 * Thus they all have the same number of data bytes.
318 dm->vlib_buffer_free_list_index =
319 vlib_buffer_get_or_create_free_list (vm,
320 VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
323 if (dm->conf->enable_tcp_udp_checksum)
324 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
325 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
327 for (i = 0; i < nports; i++)
332 struct rte_eth_dev_info dev_info;
334 struct rte_eth_link l;
335 dpdk_device_config_t *devconf = 0;
336 vlib_pci_addr_t pci_addr;
339 rte_eth_dev_info_get (i, &dev_info);
340 if (dev_info.pci_dev) /* bonded interface has no pci info */
342 pci_addr.domain = dev_info.pci_dev->addr.domain;
343 pci_addr.bus = dev_info.pci_dev->addr.bus;
344 pci_addr.slot = dev_info.pci_dev->addr.devid;
345 pci_addr.function = dev_info.pci_dev->addr.function;
347 hash_get (dm->conf->device_config_index_by_pci_addr,
352 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
354 devconf = &dm->conf->default_devconf;
356 /* Create vnet interface */
357 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
358 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
359 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
360 xd->cpu_socket = (i8) rte_eth_dev_socket_id (i);
362 /* Handle interface naming for devices with multiple ports sharing same PCI ID */
363 if (dev_info.pci_dev)
365 struct rte_eth_dev_info di = { 0 };
366 rte_eth_dev_info_get (i + 1, &di);
367 if (di.pci_dev && pci_addr.as_u32 != last_pci_addr.as_u32 &&
368 memcmp (&dev_info.pci_dev->addr, &di.pci_dev->addr,
369 sizeof (struct rte_pci_addr)) == 0)
371 xd->interface_name_suffix = format (0, "0");
372 last_pci_addr.as_u32 = pci_addr.as_u32;
373 last_pci_addr_port = i;
375 else if (pci_addr.as_u32 == last_pci_addr.as_u32)
377 xd->interface_name_suffix =
378 format (0, "%u", i - last_pci_addr_port);
382 last_pci_addr.as_u32 = ~0;
386 last_pci_addr.as_u32 = ~0;
388 clib_memcpy (&xd->tx_conf, &dev_info.default_txconf,
389 sizeof (struct rte_eth_txconf));
390 if (dm->conf->no_multi_seg)
392 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
393 port_conf_template.rxmode.jumbo_frame = 0;
397 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
398 port_conf_template.rxmode.jumbo_frame = 1;
401 clib_memcpy (&xd->port_conf, &port_conf_template,
402 sizeof (struct rte_eth_conf));
404 xd->tx_q_used = clib_min (dev_info.max_tx_queues, tm->n_vlib_mains);
406 if (devconf->num_tx_queues > 0
407 && devconf->num_tx_queues < xd->tx_q_used)
408 xd->tx_q_used = clib_min (xd->tx_q_used, devconf->num_tx_queues);
410 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
412 rt->function = dpdk_input_rss_multiarch_select ();
416 if (devconf->num_rx_queues > 1
417 && dev_info.max_rx_queues >= devconf->num_rx_queues)
419 xd->rx_q_used = devconf->num_rx_queues;
420 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
421 if (devconf->rss_fn == 0)
422 xd->port_conf.rx_adv_conf.rss_conf.rss_hf =
423 ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
425 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn;
430 xd->flags |= DPDK_DEVICE_FLAG_PMD;
432 /* workaround for drivers not setting driver_name */
433 if ((!dev_info.driver_name) && (dev_info.pci_dev))
434 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
435 dev_info.driver_name = dev_info.pci_dev->driver->name;
437 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
439 ASSERT (dev_info.driver_name);
445 #define _(s,f) else if (dev_info.driver_name && \
446 !strcmp(dev_info.driver_name, s)) \
447 xd->pmd = VNET_DPDK_PMD_##f;
453 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
459 case VNET_DPDK_PMD_E1000EM:
460 case VNET_DPDK_PMD_IGB:
461 case VNET_DPDK_PMD_IGBVF:
462 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
466 case VNET_DPDK_PMD_IXGBE:
467 case VNET_DPDK_PMD_IXGBEVF:
468 case VNET_DPDK_PMD_THUNDERX:
469 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
470 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
471 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
473 case VNET_DPDK_PMD_DPAA2:
474 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
478 case VNET_DPDK_PMD_ENIC:
479 rte_eth_link_get_nowait (i, &l);
480 xd->nb_rx_desc = DPDK_NB_RX_DESC_ENIC;
481 if (l.link_speed == 40000)
483 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
484 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
488 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
489 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
493 /* Intel Fortville */
494 case VNET_DPDK_PMD_I40E:
495 case VNET_DPDK_PMD_I40EVF:
496 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
497 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
498 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
500 switch (dev_info.pci_dev->id.device_id)
502 case I40E_DEV_ID_10G_BASE_T:
503 case I40E_DEV_ID_SFP_XL710:
504 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
506 case I40E_DEV_ID_QSFP_A:
507 case I40E_DEV_ID_QSFP_B:
508 case I40E_DEV_ID_QSFP_C:
509 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
512 rte_eth_link_get_nowait (i, &l);
513 xd->port_type = l.link_speed == 10000 ?
514 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
517 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
521 case VNET_DPDK_PMD_CXGBE:
522 switch (dev_info.pci_dev->id.device_id)
524 case 0x540d: /* T580-CR */
525 case 0x5410: /* T580-LP-cr */
526 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
527 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
528 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
530 case 0x5403: /* T540-CR */
531 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
532 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
533 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
536 xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE;
537 xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE;
538 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
542 /* Intel Red Rock Canyon */
543 case VNET_DPDK_PMD_FM10K:
544 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
545 xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE;
546 xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE;
550 case VNET_DPDK_PMD_VIRTIO:
551 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
552 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
553 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
557 case VNET_DPDK_PMD_VMXNET3:
558 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
559 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
562 case VNET_DPDK_PMD_AF_PACKET:
563 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
564 xd->af_packet_port_id = af_packet_port_id++;
567 case VNET_DPDK_PMD_BOND:
568 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
572 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
575 if (devconf->num_rx_desc)
576 xd->nb_rx_desc = devconf->num_rx_desc;
578 if (devconf->num_tx_desc)
579 xd->nb_tx_desc = devconf->num_tx_desc;
583 * Ensure default mtu is not > the mtu read from the hardware.
584 * Otherwise rte_eth_dev_configure() will fail and the port will
587 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
590 * This device does not support the platforms's max frame
591 * size. Use it's advertised mru instead.
593 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
597 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
600 * Some platforms do not account for Ethernet FCS (4 bytes) in
601 * MTU calculations. To interop with them increase mru but only
602 * if the device's settings can support it.
604 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
605 xd->port_conf.rxmode.hw_strip_crc)
608 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
609 * stripped by h/w and so will not consume any buffer memory.
611 xd->port_conf.rxmode.max_rx_pkt_len += 4;
615 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
617 f64 now = vlib_time_now (vm);
619 rnd = (u32) (now * 1e6);
620 rnd = random_u32 (&rnd);
621 clib_memcpy (addr + 2, &rnd, sizeof (rnd));
626 rte_eth_macaddr_get (i, (struct ether_addr *) addr);
628 if (xd->tx_q_used < tm->n_vlib_mains)
629 dpdk_device_lock_init (xd);
631 xd->device_index = xd - dm->devices;
632 ASSERT (i == xd->device_index);
633 xd->per_interface_next_index = ~0;
635 /* assign interface to input thread */
636 dpdk_device_and_queue_t *dq;
639 if (devconf->workers)
644 clib_bitmap_foreach (i, devconf->workers, ({
645 int cpu = dm->input_cpu_first_index + i;
646 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
647 vec_validate(xd->cpu_socket_id_by_queue, q);
648 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore);
649 vec_add2(dm->devices_by_cpu[cpu], dq, 1);
650 dq->device = xd->device_index;
656 for (q = 0; q < xd->rx_q_used; q++)
658 int cpu = dm->input_cpu_first_index + next_cpu;
659 unsigned lcore = vlib_worker_threads[cpu].lcore_id;
662 * numa node for worker thread handling this queue
663 * needed for taking buffers from the right mempool
665 vec_validate (xd->cpu_socket_id_by_queue, q);
666 xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id (lcore);
669 * construct vector of (device,queue) pairs for each worker thread
671 vec_add2 (dm->devices_by_cpu[cpu], dq, 1);
672 dq->device = xd->device_index;
676 if (next_cpu == dm->input_cpu_count)
681 if (devconf->hqos_enabled)
683 xd->flags |= DPDK_DEVICE_FLAG_HQOS;
685 if (devconf->hqos.hqos_thread_valid)
687 int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread;
689 if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count)
690 return clib_error_return (0, "invalid HQoS thread index");
692 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
693 dq->device = xd->device_index;
698 int cpu = dm->hqos_cpu_first_index + next_hqos_cpu;
700 if (dm->hqos_cpu_count == 0)
701 return clib_error_return (0, "no HQoS threads available");
703 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
704 dq->device = xd->device_index;
708 if (next_hqos_cpu == dm->hqos_cpu_count)
711 devconf->hqos.hqos_thread_valid = 1;
712 devconf->hqos.hqos_thread = cpu;
716 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
717 CLIB_CACHE_LINE_BYTES);
718 for (j = 0; j < tm->n_vlib_mains; j++)
720 vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
721 sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
722 vec_reset_length (xd->tx_vectors[j]);
725 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
726 CLIB_CACHE_LINE_BYTES);
727 for (j = 0; j < xd->rx_q_used; j++)
729 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
730 CLIB_CACHE_LINE_BYTES);
731 vec_reset_length (xd->rx_vectors[j]);
734 vec_validate_aligned (xd->d_trace_buffers, tm->n_vlib_mains,
735 CLIB_CACHE_LINE_BYTES);
737 rv = dpdk_port_setup (dm, xd);
742 if (devconf->hqos_enabled)
744 rv = dpdk_port_setup_hqos (xd, &devconf->hqos);
749 /* count the number of descriptors used for this device */
750 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
752 error = ethernet_register_interface
753 (dm->vnet_main, dpdk_device_class.index, xd->device_index,
754 /* ethernet address */ addr,
755 &xd->vlib_hw_if_index, dpdk_flag_change);
759 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
760 xd->vlib_sw_if_index = sw->sw_if_index;
761 hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index);
764 * DAW-FIXME: The Cisco VIC firmware does not provide an api for a
765 * driver to dynamically change the mtu. If/when the
766 * VIC firmware gets fixed, then this should be removed.
768 if (xd->pmd == VNET_DPDK_PMD_ENIC)
771 * Initialize mtu to what has been set by CIMC in the firmware cfg.
773 hi->max_packet_bytes = dev_info.max_rx_pktlen;
774 if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF)
775 vlan_strip = 1; /* remove vlan tag from VIC port by default */
777 clib_warning ("VLAN strip disabled for interface\n");
779 else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON)
785 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
786 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
787 xd->port_conf.rxmode.hw_vlan_strip = vlan_off;
788 if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0)
789 clib_warning ("VLAN strip enabled for interface\n");
791 clib_warning ("VLAN strip cannot be supported by interface\n");
794 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
795 xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t);
797 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
800 if (nb_desc > dm->conf->num_mbufs)
801 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
802 dm->conf->num_mbufs, nb_desc);
808 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
810 vlib_pci_main_t *pm = &pci_main;
812 vlib_pci_device_t *d;
814 int num_whitelisted = vec_len (conf->dev_confs);
817 pool_foreach (d, pm->pci_devs, ({
818 dpdk_device_config_t * devconf = 0;
819 vec_reset_length (pci_addr);
820 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
822 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET)
827 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
832 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
836 if (d->vendor_id == 0x1af4 && d->device_id == 0x1000)
839 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
841 /* all Intel devices */
842 else if (d->vendor_id == 0x8086)
845 else if (d->vendor_id == 0x1137 && d->device_id == 0x0043)
848 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
852 clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found "
853 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
858 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
864 pool_get (conf->dev_confs, devconf);
865 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
866 devconf - conf->dev_confs);
867 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
869 devconf->is_blacklisted = 1;
870 clib_error_report (error);
877 static clib_error_t *
878 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
879 unformat_input_t * input, u8 is_default)
881 clib_error_t *error = 0;
883 dpdk_device_config_t *devconf;
884 unformat_input_t sub_input;
888 devconf = &conf->default_devconf;
892 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
896 pool_get (conf->dev_confs, devconf);
897 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32,
898 devconf - conf->dev_confs);
901 return clib_error_return (0,
902 "duplicate configuration for PCI address %U",
903 format_vlib_pci_addr, &pci_addr);
906 devconf->pci_addr.as_u32 = pci_addr.as_u32;
907 devconf->hqos_enabled = 0;
908 dpdk_device_config_hqos_default (&devconf->hqos);
913 unformat_skip_white_space (input);
914 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
916 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
918 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
920 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
922 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
924 else if (unformat (input, "workers %U", unformat_bitmap_list,
929 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
931 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
935 else if (unformat (input, "vlan-strip-offload off"))
936 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF;
937 else if (unformat (input, "vlan-strip-offload on"))
938 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON;
941 (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input))
943 devconf->hqos_enabled = 1;
944 error = unformat_hqos (&sub_input, &devconf->hqos);
948 else if (unformat (input, "hqos"))
950 devconf->hqos_enabled = 1;
954 error = clib_error_return (0, "unknown input `%U'",
955 format_unformat_error, input);
963 if (devconf->workers && devconf->num_rx_queues == 0)
964 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
965 else if (devconf->workers &&
966 clib_bitmap_count_set_bits (devconf->workers) !=
967 devconf->num_rx_queues)
969 clib_error_return (0,
970 "%U: number of worker threadds must be "
971 "equal to number of rx queues", format_vlib_pci_addr,
977 static clib_error_t *
978 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
980 clib_error_t *error = 0;
981 dpdk_main_t *dm = &dpdk_main;
982 dpdk_config_main_t *conf = &dpdk_config_main;
983 vlib_thread_main_t *tm = vlib_get_thread_main ();
984 dpdk_device_config_t *devconf;
985 vlib_pci_addr_t pci_addr;
986 unformat_input_t sub_input;
988 u8 *rte_cmd = 0, *ethname = 0;
991 int num_whitelisted = 0;
998 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
1000 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1002 /* Prime the pump */
1003 if (unformat (input, "no-hugetlb"))
1005 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
1009 else if (unformat (input, "enable-tcp-udp-checksum"))
1010 conf->enable_tcp_udp_checksum = 1;
1012 else if (unformat (input, "decimal-interface-names"))
1013 conf->interface_name_format_decimal = 1;
1015 else if (unformat (input, "no-multi-seg"))
1016 conf->no_multi_seg = 1;
1018 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
1022 dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input,
1030 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1031 unformat_vlib_cli_sub_input, &sub_input))
1033 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
1040 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1042 error = dpdk_device_config (conf, pci_addr, 0, 0);
1049 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1051 else if (unformat (input, "kni %d", &conf->num_kni))
1053 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1055 else if (unformat (input, "socket-mem %s", &socket_mem))
1057 else if (unformat (input, "no-pci"))
1060 tmp = format (0, "--no-pci%c", 0);
1061 vec_add1 (conf->eal_init_args, tmp);
1063 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep))
1067 else if (unformat(input, #a)) \
1069 tmp = format (0, "--%s%c", #a, 0); \
1070 vec_add1 (conf->eal_init_args, tmp); \
1072 foreach_eal_double_hyphen_predicate_arg
1075 else if (unformat(input, #a " %s", &s)) \
1077 if (!strncmp(#a, "huge-dir", 8)) \
1079 else if (!strncmp(#a, "file-prefix", 11)) \
1081 tmp = format (0, "--%s%c", #a, 0); \
1082 vec_add1 (conf->eal_init_args, tmp); \
1084 vec_add1 (conf->eal_init_args, s); \
1086 foreach_eal_double_hyphen_arg
1089 else if (unformat(input, #a " %s", &s)) \
1091 tmp = format (0, "-%s%c", #b, 0); \
1092 vec_add1 (conf->eal_init_args, tmp); \
1094 vec_add1 (conf->eal_init_args, s); \
1096 foreach_eal_single_hyphen_arg
1099 else if (unformat(input, #a " %s", &s)) \
1101 tmp = format (0, "-%s%c", #b, 0); \
1102 vec_add1 (conf->eal_init_args, tmp); \
1104 vec_add1 (conf->eal_init_args, s); \
1105 conf->a##_set_manually = 1; \
1107 foreach_eal_single_hyphen_mandatory_arg
1109 else if (unformat (input, "default"))
1112 else if (unformat_skip_white_space (input))
1116 error = clib_error_return (0, "unknown input `%U'",
1117 format_unformat_error, input);
1122 if (!conf->uio_driver_name)
1123 conf->uio_driver_name = format (0, "igb_uio%c", 0);
1126 * Use 1G huge pages if available.
1128 if (!no_huge && !huge_dir)
1130 u32 x, *mem_by_socket = 0;
1134 u8 less_than_1g = 1;
1137 umount (DEFAULT_HUGE_DIR);
1139 /* Process "socket-mem" parameter value */
1140 if (vec_len (socket_mem))
1142 unformat_input_t in;
1143 unformat_init_vector (&in, socket_mem);
1144 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1146 if (unformat (&in, "%u,", &x))
1148 else if (unformat (&in, "%u", &x))
1150 else if (unformat (&in, ","))
1155 vec_add1 (mem_by_socket, x);
1160 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1161 unformat_free (&in);
1167 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1169 vec_validate(mem_by_socket, c);
1170 mem_by_socket[c] = 256; /* default per-socket mem */
1176 /* check if available enough 1GB pages for each socket */
1178 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1180 int pages_avail, page_size, mem;
1182 vec_validate(mem_by_socket, c);
1183 mem = mem_by_socket[c];
1186 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1188 if (pages_avail < 0 || page_size * pages_avail < mem)
1192 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1194 if (pages_avail < 0 || page_size * pages_avail < mem)
1199 if (mem_by_socket == 0)
1201 error = clib_error_return (0, "mem_by_socket NULL");
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 ? "," : "", mem_by_socket[x]);
1210 socket_mem = format (socket_mem, "%c", 0);
1212 vec_free (mem_by_socket);
1214 rv = mkdir (VPP_RUN_DIR, 0755);
1215 if (rv && errno != EEXIST)
1217 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1218 VPP_RUN_DIR, errno);
1222 rv = mkdir (DEFAULT_HUGE_DIR, 0755);
1223 if (rv && errno != EEXIST)
1225 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1226 DEFAULT_HUGE_DIR, errno);
1230 if (use_1g && !(less_than_1g && use_2m))
1233 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 ;
1308 pool_foreach (devconf, conf->dev_confs, ({
1310 /* default per-device config items */
1311 foreach_dpdk_device_config_item
1313 /* add DPDK EAL whitelist/blacklist entry */
1314 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1316 tmp = format (0, "-w%c", 0);
1317 vec_add1 (conf->eal_init_args, tmp);
1318 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1319 vec_add1 (conf->eal_init_args, tmp);
1321 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1323 tmp = format (0, "-b%c", 0);
1324 vec_add1 (conf->eal_init_args, tmp);
1325 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1326 vec_add1 (conf->eal_init_args, tmp);
1333 /* set master-lcore */
1334 tmp = format (0, "--master-lcore%c", 0);
1335 vec_add1 (conf->eal_init_args, tmp);
1336 tmp = format (0, "%u%c", tm->main_lcore, 0);
1337 vec_add1 (conf->eal_init_args, tmp);
1339 /* set socket-mem */
1340 tmp = format (0, "--socket-mem%c", 0);
1341 vec_add1 (conf->eal_init_args, tmp);
1342 tmp = format (0, "%s%c", socket_mem, 0);
1343 vec_add1 (conf->eal_init_args, tmp);
1345 /* NULL terminate the "argv" vector, in case of stupidity */
1346 vec_add1 (conf->eal_init_args, 0);
1347 _vec_len (conf->eal_init_args) -= 1;
1349 /* Set up DPDK eal and packet mbuf pool early. */
1351 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1353 rte_set_log_level (log_level);
1355 vm = vlib_get_main ();
1357 /* make copy of args as rte_eal_init tends to mess up with arg array */
1358 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1359 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1360 conf->eal_init_args[i]);
1363 rte_eal_init (vec_len (conf->eal_init_args),
1364 (char **) conf->eal_init_args);
1366 /* lazy umount hugepages */
1367 umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
1370 return clib_error_return (0, "rte_eal_init returned %d", ret);
1372 /* Dump the physical memory layout prior to creating the mbuf_pool */
1373 fprintf (stdout, "DPDK physical memory layout:\n");
1374 rte_dump_physmem_layout (stdout);
1376 /* main thread 1st */
1377 error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ());
1381 for (i = 0; i < RTE_MAX_LCORE; i++)
1383 error = vlib_buffer_pool_create (vm, conf->num_mbufs,
1384 rte_lcore_to_socket_id (i));
1393 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1396 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1398 vnet_main_t *vnm = vnet_get_main ();
1399 struct rte_eth_link prev_link = xd->link;
1401 u8 hw_flags_chg = 0;
1403 /* only update link state for PMD interfaces */
1404 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
1407 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1408 memset (&xd->link, 0, sizeof (xd->link));
1409 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1411 if (LINK_STATE_ELOGS)
1413 vlib_main_t *vm = vlib_get_main ();
1414 ELOG_TYPE_DECLARE (e) =
1417 "update-link-state: sw_if_index %d, admin_up %d,"
1418 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1427 ed = ELOG_DATA (&vm->elog_main, e);
1428 ed->sw_if_index = xd->vlib_sw_if_index;
1429 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1430 ed->old_link_state = (u8)
1431 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index);
1432 ed->new_link_state = (u8) xd->link.link_status;
1435 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) &&
1436 ((xd->link.link_status != 0) ^
1437 vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index)))
1440 hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
1443 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1446 switch (xd->link.link_duplex)
1448 case ETH_LINK_HALF_DUPLEX:
1449 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1451 case ETH_LINK_FULL_DUPLEX:
1452 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1458 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1461 switch (xd->link.link_speed)
1463 case ETH_SPEED_NUM_10M:
1464 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1466 case ETH_SPEED_NUM_100M:
1467 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1469 case ETH_SPEED_NUM_1G:
1470 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1472 case ETH_SPEED_NUM_10G:
1473 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1475 case ETH_SPEED_NUM_40G:
1476 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1481 clib_warning ("unknown link speed %d", xd->link.link_speed);
1487 if (LINK_STATE_ELOGS)
1489 vlib_main_t *vm = vlib_get_main ();
1491 ELOG_TYPE_DECLARE (e) =
1494 "update-link-state: sw_if_index %d, new flags %d",.format_args
1502 ed = ELOG_DATA (&vm->elog_main, e);
1503 ed->sw_if_index = xd->vlib_sw_if_index;
1504 ed->flags = hw_flags;
1506 vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags);
1511 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1513 clib_error_t *error;
1514 vnet_main_t *vnm = vnet_get_main ();
1515 dpdk_main_t *dm = &dpdk_main;
1516 ethernet_main_t *em = ðernet_main;
1518 vlib_thread_main_t *tm = vlib_get_thread_main ();
1521 error = dpdk_lib_init (dm);
1524 * Turn on the input node if we found some devices to drive
1525 * and we're not running worker threads or i/o threads
1528 if (error == 0 && vec_len (dm->devices) > 0)
1530 if (tm->n_vlib_mains == 1)
1531 vlib_node_set_state (vm, dpdk_input_node.index,
1532 VLIB_NODE_STATE_POLLING);
1534 for (i = 0; i < tm->n_vlib_mains; i++)
1535 if (vec_len (dm->devices_by_cpu[i]) > 0)
1536 vlib_node_set_state (vlib_mains[i], dpdk_input_node.index,
1537 VLIB_NODE_STATE_POLLING);
1541 clib_error_report (error);
1543 tm->worker_thread_release = 1;
1545 f64 now = vlib_time_now (vm);
1546 vec_foreach (xd, dm->devices)
1548 dpdk_update_link_state (xd, now);
1553 * Extra set up for bond interfaces:
1554 * 1. Setup MACs for bond interfaces and their slave links which was set
1555 * in dpdk_port_setup() but needs to be done again here to take effect.
1556 * 2. Set up info for bond interface related CLI support.
1558 int nports = rte_eth_dev_count ();
1561 for (i = 0; i < nports; i++)
1563 struct rte_eth_dev_info dev_info;
1564 rte_eth_dev_info_get (i, &dev_info);
1565 if (!dev_info.driver_name)
1566 #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
1567 dev_info.driver_name = dev_info.pci_dev->driver->name;
1569 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
1571 ASSERT (dev_info.driver_name);
1572 if (strncmp (dev_info.driver_name, "rte_bond_pmd", 12) == 0)
1576 int nlink = rte_eth_bond_slaves_get (i, slink, 16);
1579 vnet_hw_interface_t *bhi;
1580 ethernet_interface_t *bei;
1583 /* Get MAC of 1st slave link */
1584 rte_eth_macaddr_get (slink[0],
1585 (struct ether_addr *) addr);
1586 /* Set MAC of bounded interface to that of 1st slave link */
1588 rte_eth_bond_mac_address_set (i,
1589 (struct ether_addr *)
1592 clib_warning ("Failed to set MAC address");
1594 /* Populate MAC of bonded interface in VPP hw tables */
1596 vnet_get_hw_interface (vnm,
1597 dm->devices[i].vlib_hw_if_index);
1599 pool_elt_at_index (em->interfaces, bhi->hw_instance);
1600 clib_memcpy (bhi->hw_address, addr, 6);
1601 clib_memcpy (bei->address, addr, 6);
1602 /* Init l3 packet size allowed on bonded interface */
1603 bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
1604 bhi->max_l3_packet_bytes[VLIB_RX] =
1605 bhi->max_l3_packet_bytes[VLIB_TX] =
1606 ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
1608 { /* 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 */
1615 rte_eth_dev_mac_addr_add (slave,
1616 (struct ether_addr *)
1618 /* Set slaves bitmap for bonded interface */
1620 clib_bitmap_set (bhi->bond_info,
1621 sdev->vlib_hw_if_index, 1);
1622 /* Set slave link flags on slave interface */
1624 vnet_get_hw_interface (vnm, sdev->vlib_hw_if_index);
1626 vnet_get_sw_interface (vnm, sdev->vlib_sw_if_index);
1627 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1628 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1630 /* Set l3 packet size allowed as the lowest of slave */
1631 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1632 shi->max_l3_packet_bytes[VLIB_RX])
1633 bhi->max_l3_packet_bytes[VLIB_RX] =
1634 bhi->max_l3_packet_bytes[VLIB_TX] =
1635 shi->max_l3_packet_bytes[VLIB_RX];
1637 /* Set max packet size allowed as the lowest of slave */
1638 if (bhi->max_packet_bytes > shi->max_packet_bytes)
1639 bhi->max_packet_bytes = shi->max_packet_bytes;
1650 * check each time through the loop in case intervals are changed
1652 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1653 dm->link_state_poll_interval : dm->stat_poll_interval;
1655 vlib_process_wait_for_event_or_clock (vm, min_wait);
1657 if (dm->admin_up_down_in_progress)
1658 /* skip the poll if an admin up down is in progress (on any interface) */
1661 vec_foreach (xd, dm->devices)
1663 f64 now = vlib_time_now (vm);
1664 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1665 dpdk_update_counters (xd, now);
1666 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1667 dpdk_update_link_state (xd, now);
1676 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1677 .function = dpdk_process,
1678 .type = VLIB_NODE_TYPE_PROCESS,
1679 .name = "dpdk-process",
1680 .process_log2_n_stack_bytes = 17,
1685 dpdk_set_stat_poll_interval (f64 interval)
1687 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1688 return (VNET_API_ERROR_INVALID_VALUE);
1690 dpdk_main.stat_poll_interval = interval;
1696 dpdk_set_link_state_poll_interval (f64 interval)
1698 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1699 return (VNET_API_ERROR_INVALID_VALUE);
1701 dpdk_main.link_state_poll_interval = interval;
1707 dpdk_init (vlib_main_t * vm)
1709 dpdk_main_t *dm = &dpdk_main;
1711 clib_error_t *error = 0;
1712 vlib_thread_main_t *tm = vlib_get_thread_main ();
1714 /* verify that structs are cacheline aligned */
1715 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1716 "Cache line marker must be 1st element in dpdk_device_t");
1717 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1718 CLIB_CACHE_LINE_BYTES,
1719 "Data in cache line 0 is bigger than cache line size");
1720 STATIC_ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0,
1721 "Cache line marker must be 1st element in dpdk_worker_t");
1722 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1723 "Cache line marker must be 1st element in frame_queue_trace_t");
1726 dm->vnet_main = vnet_get_main ();
1727 dm->conf = &dpdk_config_main;
1729 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1731 return clib_error_return (0, "ethernet-input node AWOL");
1733 dm->ethernet_input_node_index = ei->index;
1735 dm->conf->nchannels = 4;
1736 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1737 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1739 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1740 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1741 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1743 /* $$$ use n_thread_stacks since it's known-good at this point */
1744 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1746 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1747 dm->buffer_flags_template =
1748 (VLIB_BUFFER_TOTAL_LENGTH_VALID
1749 | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT);
1751 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1752 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1755 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1761 VLIB_INIT_FUNCTION (dpdk_init);
1765 * fd.io coding-style-patch-verification: ON
1768 * eval: (c-set-style "gnu")