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 <dpdk/device/dpdk.h>
23 #include <vlib/unix/physmem.h>
24 #include <vlib/pci/pci.h>
30 #include <sys/mount.h>
34 #include <dpdk/device/dpdk_priv.h>
36 dpdk_main_t dpdk_main;
38 #define LINK_STATE_ELOGS 0
40 #define DEFAULT_HUGE_DIR "/run/vpp/hugepages"
41 #define VPP_RUN_DIR "/run/vpp"
43 /* Port configuration, mildly modified Intel app values */
45 static struct rte_eth_conf port_conf_template = {
48 .header_split = 0, /**< Header Split disabled */
49 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
50 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
51 .hw_strip_crc = 0, /**< CRC stripped by hardware */
54 .mq_mode = ETH_MQ_TX_NONE,
59 dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd)
64 ASSERT (vlib_get_thread_index () == 0);
66 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
68 vnet_hw_interface_set_flags (dm->vnet_main, xd->hw_if_index, 0);
69 rte_eth_dev_stop (xd->device_index);
72 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
73 xd->tx_q_used, &xd->port_conf);
76 return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d",
77 xd->device_index, rv);
79 /* Set up one TX-queue per worker thread */
80 for (j = 0; j < xd->tx_q_used; j++)
82 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
83 xd->cpu_socket, &xd->tx_conf);
85 /* retry with any other CPU socket */
87 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
88 SOCKET_ID_ANY, &xd->tx_conf);
94 return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d",
95 xd->device_index, rv);
97 for (j = 0; j < xd->rx_q_used; j++)
99 uword tidx = vnet_get_device_input_thread_index (dm->vnet_main,
101 unsigned lcore = vlib_worker_threads[tidx].lcore_id;
102 u16 socket_id = rte_lcore_to_socket_id (lcore);
104 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
106 dm->pktmbuf_pools[socket_id]);
108 /* retry with any other CPU socket */
110 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
112 dm->pktmbuf_pools[socket_id]);
114 return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d",
115 xd->device_index, rv);
118 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
121 rv = rte_eth_dev_start (xd->device_index);
122 if (!rv && xd->default_mac_address)
123 rv = rte_eth_dev_default_mac_addr_set (xd->device_index,
124 (struct ether_addr *)
125 xd->default_mac_address);
127 clib_warning ("rte_eth_dev_start %d returned %d",
128 xd->device_index, rv);
134 dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
136 dpdk_main_t *dm = &dpdk_main;
137 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
140 if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC (flags))
142 old = (xd->flags & DPDK_DEVICE_FLAG_PROMISC) != 0;
144 if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
145 xd->flags |= DPDK_DEVICE_FLAG_PROMISC;
147 xd->flags &= ~DPDK_DEVICE_FLAG_PROMISC;
149 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
151 if (xd->flags & DPDK_DEVICE_FLAG_PROMISC)
152 rte_eth_promiscuous_enable (xd->device_index);
154 rte_eth_promiscuous_disable (xd->device_index);
157 else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU (flags))
161 xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes;
163 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
164 rte_eth_dev_stop (xd->device_index);
166 rv = rte_eth_dev_configure
167 (xd->device_index, xd->rx_q_used, xd->tx_q_used, &xd->port_conf);
170 vlib_cli_output (vlib_get_main (),
171 "rte_eth_dev_configure[%d]: err %d",
172 xd->device_index, rv);
174 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
176 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
178 int rv = rte_eth_dev_start (xd->device_index);
179 if (!rv && xd->default_mac_address)
180 rv = rte_eth_dev_default_mac_addr_set (xd->device_index,
181 (struct ether_addr *)
182 xd->default_mac_address);
184 clib_warning ("rte_eth_dev_start %d returned %d",
185 xd->device_index, rv);
193 dpdk_device_lock_init (dpdk_device_t * xd)
196 vec_validate (xd->lockp, xd->tx_q_used - 1);
197 for (q = 0; q < xd->tx_q_used; q++)
199 xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
200 CLIB_CACHE_LINE_BYTES);
201 memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES);
205 static clib_error_t *
206 dpdk_lib_init (dpdk_main_t * dm)
212 vlib_main_t *vm = vlib_get_main ();
213 vlib_thread_main_t *tm = vlib_get_thread_main ();
214 vnet_device_main_t *vdm = &vnet_device_main;
215 vnet_sw_interface_t *sw;
216 vnet_hw_interface_t *hi;
218 vlib_pci_addr_t last_pci_addr;
219 u32 last_pci_addr_port = 0;
220 vlib_thread_registration_t *tr_hqos;
223 u32 next_hqos_cpu = 0;
224 u8 af_packet_port_id = 0;
225 u8 bond_ether_port_id = 0;
226 last_pci_addr.as_u32 = ~0;
228 dm->hqos_cpu_first_index = 0;
229 dm->hqos_cpu_count = 0;
231 /* find out which cpus will be used for I/O TX */
232 p_hqos = hash_get_mem (tm->thread_registrations_by_name, "hqos-threads");
233 tr_hqos = p_hqos ? (vlib_thread_registration_t *) p_hqos[0] : 0;
235 if (tr_hqos && tr_hqos->count > 0)
237 dm->hqos_cpu_first_index = tr_hqos->first_index;
238 dm->hqos_cpu_count = tr_hqos->count;
241 vec_validate_aligned (dm->devices_by_hqos_cpu, tm->n_vlib_mains - 1,
242 CLIB_CACHE_LINE_BYTES);
244 nports = rte_eth_dev_count ();
247 clib_warning ("DPDK drivers found no ports...");
251 clib_warning ("DPDK drivers found %d ports...", nports);
254 * All buffers are all allocated from the same rte_mempool.
255 * Thus they all have the same number of data bytes.
257 dm->vlib_buffer_free_list_index =
258 vlib_buffer_get_or_create_free_list (vm,
259 VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
262 if (dm->conf->enable_tcp_udp_checksum)
263 dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT
264 | IP_BUFFER_L4_CHECKSUM_COMPUTED);
266 /* vlib_buffer_t template */
267 vec_validate_aligned (dm->buffer_templates, tm->n_vlib_mains - 1,
268 CLIB_CACHE_LINE_BYTES);
269 for (i = 0; i < tm->n_vlib_mains; i++)
271 vlib_buffer_free_list_t *fl;
272 vlib_buffer_t *bt = vec_elt_at_index (dm->buffer_templates, i);
273 fl = vlib_buffer_get_free_list (vm,
274 VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
275 vlib_buffer_init_for_free_list (bt, fl);
276 bt->flags = dm->buffer_flags_template;
277 bt->current_data = -RTE_PKTMBUF_HEADROOM;
278 vnet_buffer (bt)->sw_if_index[VLIB_TX] = (u32) ~ 0;
281 for (i = 0; i < nports; i++)
286 struct rte_eth_dev_info dev_info;
288 struct rte_eth_link l;
289 dpdk_device_config_t *devconf = 0;
290 vlib_pci_addr_t pci_addr;
293 rte_eth_dev_info_get (i, &dev_info);
294 if (dev_info.pci_dev) /* bonded interface has no pci info */
296 pci_addr.domain = dev_info.pci_dev->addr.domain;
297 pci_addr.bus = dev_info.pci_dev->addr.bus;
298 pci_addr.slot = dev_info.pci_dev->addr.devid;
299 pci_addr.function = dev_info.pci_dev->addr.function;
301 hash_get (dm->conf->device_config_index_by_pci_addr,
306 devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
308 devconf = &dm->conf->default_devconf;
310 /* Create vnet interface */
311 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
312 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
313 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
314 xd->cpu_socket = (i8) rte_eth_dev_socket_id (i);
316 /* Handle interface naming for devices with multiple ports sharing same PCI ID */
317 if (dev_info.pci_dev)
319 struct rte_eth_dev_info di = { 0 };
320 rte_eth_dev_info_get (i + 1, &di);
321 if (di.pci_dev && pci_addr.as_u32 != last_pci_addr.as_u32 &&
322 memcmp (&dev_info.pci_dev->addr, &di.pci_dev->addr,
323 sizeof (struct rte_pci_addr)) == 0)
325 xd->interface_name_suffix = format (0, "0");
326 last_pci_addr.as_u32 = pci_addr.as_u32;
327 last_pci_addr_port = i;
329 else if (pci_addr.as_u32 == last_pci_addr.as_u32)
331 xd->interface_name_suffix =
332 format (0, "%u", i - last_pci_addr_port);
336 last_pci_addr.as_u32 = ~0;
340 last_pci_addr.as_u32 = ~0;
342 clib_memcpy (&xd->tx_conf, &dev_info.default_txconf,
343 sizeof (struct rte_eth_txconf));
344 if (dm->conf->no_multi_seg)
346 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
347 port_conf_template.rxmode.jumbo_frame = 0;
348 port_conf_template.rxmode.enable_scatter = 0;
352 xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
353 port_conf_template.rxmode.jumbo_frame = 1;
354 port_conf_template.rxmode.enable_scatter = 1;
355 xd->flags |= DPDK_DEVICE_FLAG_MAYBE_MULTISEG;
358 clib_memcpy (&xd->port_conf, &port_conf_template,
359 sizeof (struct rte_eth_conf));
361 xd->tx_q_used = clib_min (dev_info.max_tx_queues, tm->n_vlib_mains);
363 if (devconf->num_tx_queues > 0
364 && devconf->num_tx_queues < xd->tx_q_used)
365 xd->tx_q_used = clib_min (xd->tx_q_used, devconf->num_tx_queues);
367 if (devconf->num_rx_queues > 1 && dm->use_rss == 0)
372 if (devconf->num_rx_queues > 1
373 && dev_info.max_rx_queues >= devconf->num_rx_queues)
375 xd->rx_q_used = devconf->num_rx_queues;
376 xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
377 if (devconf->rss_fn == 0)
378 xd->port_conf.rx_adv_conf.rss_conf.rss_hf =
379 ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
381 xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn;
386 xd->flags |= DPDK_DEVICE_FLAG_PMD;
388 /* workaround for drivers not setting driver_name */
389 if ((!dev_info.driver_name) && (dev_info.pci_dev))
390 dev_info.driver_name = dev_info.pci_dev->driver->driver.name;
392 ASSERT (dev_info.driver_name);
398 #define _(s,f) else if (dev_info.driver_name && \
399 !strcmp(dev_info.driver_name, s)) \
400 xd->pmd = VNET_DPDK_PMD_##f;
406 xd->pmd = VNET_DPDK_PMD_UNKNOWN;
408 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
409 xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
410 xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
415 case VNET_DPDK_PMD_E1000EM:
416 case VNET_DPDK_PMD_IGB:
417 case VNET_DPDK_PMD_IGBVF:
418 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
422 case VNET_DPDK_PMD_IXGBE:
423 case VNET_DPDK_PMD_IXGBEVF:
424 case VNET_DPDK_PMD_THUNDERX:
425 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
427 case VNET_DPDK_PMD_DPAA2:
428 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
432 case VNET_DPDK_PMD_ENIC:
433 rte_eth_link_get_nowait (i, &l);
434 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
435 if (l.link_speed == 40000)
436 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
438 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
441 /* Intel Fortville */
442 case VNET_DPDK_PMD_I40E:
443 case VNET_DPDK_PMD_I40EVF:
444 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
445 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
447 if (dev_info.speed_capa & ETH_LINK_SPEED_40G)
448 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
449 else if (dev_info.speed_capa & ETH_LINK_SPEED_25G)
450 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_25G;
451 else if (dev_info.speed_capa & ETH_LINK_SPEED_10G)
452 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
454 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
457 case VNET_DPDK_PMD_CXGBE:
458 switch (dev_info.pci_dev->id.device_id)
460 case 0x540d: /* T580-CR */
461 case 0x5410: /* T580-LP-cr */
462 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
464 case 0x5403: /* T540-CR */
465 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
468 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
472 case VNET_DPDK_PMD_MLX5:
474 char *pn_100g[] = { "MCX415A-CCAT", "MCX416A-CCAT",
475 "MCX556A-ECAT", "MCX556A-EDAT", "MCX555A-ECAT",
476 "MCX515A-CCAT", "MCX516A-CCAT", "MCX516A-CDAT", 0
478 char *pn_40g[] = { "MCX413A-BCAT", "MCX414A-BCAT",
479 "MCX415A-BCAT", "MCX416A-BCAT", "MCX4131A-BCAT", 0
481 char *pn_10g[] = { "MCX4111A-XCAT", "MCX4121A-XCAT", 0 };
483 vlib_pci_device_t *pd = vlib_get_pci_device (&pci_addr);
487 pn = format (0, "%U%c",
488 format_vlib_pci_vpd, pd->vpd_r, "PN", 0);
494 while (!found && c[0])
496 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
498 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_100G;
505 while (!found && c[0])
507 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
509 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
516 while (!found && c[0])
518 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
520 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
530 /* Intel Red Rock Canyon */
531 case VNET_DPDK_PMD_FM10K:
532 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
536 case VNET_DPDK_PMD_VIRTIO:
537 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
538 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
539 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
543 case VNET_DPDK_PMD_VMXNET3:
544 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
545 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
548 case VNET_DPDK_PMD_AF_PACKET:
549 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
550 xd->port_id = af_packet_port_id++;
553 case VNET_DPDK_PMD_BOND:
554 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
555 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
556 xd->port_id = bond_ether_port_id++;
560 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
563 if (devconf->num_rx_desc)
564 xd->nb_rx_desc = devconf->num_rx_desc;
566 if (devconf->num_tx_desc)
567 xd->nb_tx_desc = devconf->num_tx_desc;
571 * Ensure default mtu is not > the mtu read from the hardware.
572 * Otherwise rte_eth_dev_configure() will fail and the port will
575 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
578 * This device does not support the platforms's max frame
579 * size. Use it's advertised mru instead.
581 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
585 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
588 * Some platforms do not account for Ethernet FCS (4 bytes) in
589 * MTU calculations. To interop with them increase mru but only
590 * if the device's settings can support it.
592 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
593 xd->port_conf.rxmode.hw_strip_crc)
596 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
597 * stripped by h/w and so will not consume any buffer memory.
599 xd->port_conf.rxmode.max_rx_pkt_len += 4;
603 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
605 f64 now = vlib_time_now (vm);
607 rnd = (u32) (now * 1e6);
608 rnd = random_u32 (&rnd);
609 clib_memcpy (addr + 2, &rnd, sizeof (rnd));
614 rte_eth_macaddr_get (i, (struct ether_addr *) addr);
616 if (xd->tx_q_used < tm->n_vlib_mains)
617 dpdk_device_lock_init (xd);
619 xd->device_index = xd - dm->devices;
620 ASSERT (i == xd->device_index);
621 xd->per_interface_next_index = ~0;
623 /* assign interface to input thread */
624 dpdk_device_and_queue_t *dq;
627 if (devconf->hqos_enabled)
629 xd->flags |= DPDK_DEVICE_FLAG_HQOS;
631 if (devconf->hqos.hqos_thread_valid)
633 int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread;
635 if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count)
636 return clib_error_return (0, "invalid HQoS thread index");
638 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
639 dq->device = xd->device_index;
644 int cpu = dm->hqos_cpu_first_index + next_hqos_cpu;
646 if (dm->hqos_cpu_count == 0)
647 return clib_error_return (0, "no HQoS threads available");
649 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
650 dq->device = xd->device_index;
654 if (next_hqos_cpu == dm->hqos_cpu_count)
657 devconf->hqos.hqos_thread_valid = 1;
658 devconf->hqos.hqos_thread = cpu;
662 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
663 CLIB_CACHE_LINE_BYTES);
664 for (j = 0; j < tm->n_vlib_mains; j++)
666 vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
667 sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
668 vec_reset_length (xd->tx_vectors[j]);
671 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
672 CLIB_CACHE_LINE_BYTES);
673 for (j = 0; j < xd->rx_q_used; j++)
675 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
676 CLIB_CACHE_LINE_BYTES);
677 vec_reset_length (xd->rx_vectors[j]);
680 vec_validate_aligned (xd->d_trace_buffers, tm->n_vlib_mains,
681 CLIB_CACHE_LINE_BYTES);
684 /* count the number of descriptors used for this device */
685 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
687 error = ethernet_register_interface
688 (dm->vnet_main, dpdk_device_class.index, xd->device_index,
689 /* ethernet address */ addr,
690 &xd->hw_if_index, dpdk_flag_change);
694 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->hw_if_index);
695 xd->vlib_sw_if_index = sw->sw_if_index;
696 vnet_hw_interface_set_input_node (dm->vnet_main, xd->hw_if_index,
697 dpdk_input_node.index);
699 if (devconf->workers)
704 clib_bitmap_foreach (i, devconf->workers, ({
705 vnet_hw_interface_assign_rx_thread (dm->vnet_main, xd->hw_if_index, q++,
706 vdm->first_worker_thread_index + i);
711 for (q = 0; q < xd->rx_q_used; q++)
713 vnet_hw_interface_assign_rx_thread (dm->vnet_main, xd->hw_if_index, q, /* any */
717 hi = vnet_get_hw_interface (dm->vnet_main, xd->hw_if_index);
719 rv = dpdk_port_setup (dm, xd);
724 if (devconf->hqos_enabled)
726 rv = dpdk_port_setup_hqos (xd, &devconf->hqos);
732 * For cisco VIC vNIC, set default to VLAN strip enabled, unless
733 * specified otherwise in the startup config.
734 * For other NICs default to VLAN strip disabled, unless specified
735 * otherwis in the startup config.
737 if (xd->pmd == VNET_DPDK_PMD_ENIC)
739 if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF)
740 vlan_strip = 1; /* remove vlan tag from VIC port by default */
742 clib_warning ("VLAN strip disabled for interface\n");
744 else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON)
750 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
751 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
752 xd->port_conf.rxmode.hw_vlan_strip = vlan_off;
753 if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0)
754 clib_warning ("VLAN strip enabled for interface\n");
756 clib_warning ("VLAN strip cannot be supported by interface\n");
759 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
760 xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t);
762 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
765 if (nb_desc > dm->conf->num_mbufs)
766 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
767 dm->conf->num_mbufs, nb_desc);
773 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
775 vlib_pci_main_t *pm = &pci_main;
777 vlib_pci_device_t *d;
779 int num_whitelisted = vec_len (conf->dev_confs);
782 pool_foreach (d, pm->pci_devs, ({
783 dpdk_device_config_t * devconf = 0;
784 vec_reset_length (pci_addr);
785 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
787 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && d->device_class != PCI_CLASS_PROCESSOR_CO)
792 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
797 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
801 if (d->vendor_id == 0x1af4 && d->device_id == 0x1000)
804 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
806 /* all Intel network devices */
807 else if (d->vendor_id == 0x8086 && d->device_class == PCI_CLASS_NETWORK_ETHERNET)
809 /* all Intel QAT devices VFs */
810 else if (d->vendor_id == 0x8086 && d->device_class == PCI_CLASS_PROCESSOR_CO &&
811 (d->device_id == 0x0443 || d->device_id == 0x37c9 || d->device_id == 0x19e3))
814 else if (d->vendor_id == 0x1137 && d->device_id == 0x0043)
817 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
821 clib_warning ("Unsupported PCI device 0x%04x:0x%04x found "
822 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
827 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
833 pool_get (conf->dev_confs, devconf);
834 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
835 devconf - conf->dev_confs);
836 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
838 devconf->is_blacklisted = 1;
839 clib_error_report (error);
846 static clib_error_t *
847 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
848 unformat_input_t * input, u8 is_default)
850 clib_error_t *error = 0;
852 dpdk_device_config_t *devconf;
853 unformat_input_t sub_input;
857 devconf = &conf->default_devconf;
861 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
865 pool_get (conf->dev_confs, devconf);
866 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32,
867 devconf - conf->dev_confs);
870 return clib_error_return (0,
871 "duplicate configuration for PCI address %U",
872 format_vlib_pci_addr, &pci_addr);
875 devconf->pci_addr.as_u32 = pci_addr.as_u32;
876 devconf->hqos_enabled = 0;
877 dpdk_device_config_hqos_default (&devconf->hqos);
882 unformat_skip_white_space (input);
883 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
885 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
887 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
889 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
891 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
893 else if (unformat (input, "workers %U", unformat_bitmap_list,
898 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
900 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
904 else if (unformat (input, "vlan-strip-offload off"))
905 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF;
906 else if (unformat (input, "vlan-strip-offload on"))
907 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON;
910 (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input))
912 devconf->hqos_enabled = 1;
913 error = unformat_hqos (&sub_input, &devconf->hqos);
917 else if (unformat (input, "hqos"))
919 devconf->hqos_enabled = 1;
923 error = clib_error_return (0, "unknown input `%U'",
924 format_unformat_error, input);
932 if (devconf->workers && devconf->num_rx_queues == 0)
933 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
934 else if (devconf->workers &&
935 clib_bitmap_count_set_bits (devconf->workers) !=
936 devconf->num_rx_queues)
938 clib_error_return (0,
939 "%U: number of worker threadds must be "
940 "equal to number of rx queues", format_vlib_pci_addr,
946 static clib_error_t *
947 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
949 clib_error_t *error = 0;
950 dpdk_main_t *dm = &dpdk_main;
951 dpdk_config_main_t *conf = &dpdk_config_main;
952 vlib_thread_main_t *tm = vlib_get_thread_main ();
953 dpdk_device_config_t *devconf;
954 vlib_pci_addr_t pci_addr;
955 unformat_input_t sub_input;
957 u8 *rte_cmd = 0, *ethname = 0;
960 int num_whitelisted = 0;
967 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
969 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
972 if (unformat (input, "no-hugetlb"))
974 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
978 else if (unformat (input, "enable-tcp-udp-checksum"))
979 conf->enable_tcp_udp_checksum = 1;
981 else if (unformat (input, "decimal-interface-names"))
982 conf->interface_name_format_decimal = 1;
984 else if (unformat (input, "no-multi-seg"))
985 conf->no_multi_seg = 1;
987 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
991 dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input,
999 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1000 unformat_vlib_cli_sub_input, &sub_input))
1002 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
1009 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1011 error = dpdk_device_config (conf, pci_addr, 0, 0);
1018 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1020 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1022 else if (unformat (input, "socket-mem %s", &socket_mem))
1024 else if (unformat (input, "no-pci"))
1027 tmp = format (0, "--no-pci%c", 0);
1028 vec_add1 (conf->eal_init_args, tmp);
1030 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep_usec))
1034 else if (unformat(input, #a)) \
1036 tmp = format (0, "--%s%c", #a, 0); \
1037 vec_add1 (conf->eal_init_args, tmp); \
1039 foreach_eal_double_hyphen_predicate_arg
1042 else if (unformat(input, #a " %s", &s)) \
1044 if (!strncmp(#a, "huge-dir", 8)) \
1046 else if (!strncmp(#a, "file-prefix", 11)) \
1048 tmp = format (0, "--%s%c", #a, 0); \
1049 vec_add1 (conf->eal_init_args, tmp); \
1051 if (!strncmp(#a, "vdev", 4)) \
1052 if (strstr((char*)s, "af_packet")) \
1053 clib_warning ("af_packet obsoleted. Use CLI 'create host-interface'."); \
1054 vec_add1 (conf->eal_init_args, s); \
1056 foreach_eal_double_hyphen_arg
1059 else if (unformat(input, #a " %s", &s)) \
1061 tmp = format (0, "-%s%c", #b, 0); \
1062 vec_add1 (conf->eal_init_args, tmp); \
1064 vec_add1 (conf->eal_init_args, s); \
1066 foreach_eal_single_hyphen_arg
1069 else if (unformat(input, #a " %s", &s)) \
1071 tmp = format (0, "-%s%c", #b, 0); \
1072 vec_add1 (conf->eal_init_args, tmp); \
1074 vec_add1 (conf->eal_init_args, s); \
1075 conf->a##_set_manually = 1; \
1077 foreach_eal_single_hyphen_mandatory_arg
1079 else if (unformat (input, "default"))
1082 else if (unformat_skip_white_space (input))
1086 error = clib_error_return (0, "unknown input `%U'",
1087 format_unformat_error, input);
1092 if (!conf->uio_driver_name)
1093 conf->uio_driver_name = format (0, "uio_pci_generic%c", 0);
1096 * Use 1G huge pages if available.
1098 if (!no_huge && !huge_dir)
1100 u32 x, *mem_by_socket = 0;
1104 u8 less_than_1g = 1;
1107 umount (DEFAULT_HUGE_DIR);
1109 /* Process "socket-mem" parameter value */
1110 if (vec_len (socket_mem))
1112 unformat_input_t in;
1113 unformat_init_vector (&in, socket_mem);
1114 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1116 if (unformat (&in, "%u,", &x))
1118 else if (unformat (&in, "%u", &x))
1120 else if (unformat (&in, ","))
1125 vec_add1 (mem_by_socket, x);
1130 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1131 unformat_free (&in);
1137 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1139 vec_validate(mem_by_socket, c);
1140 mem_by_socket[c] = 256; /* default per-socket mem */
1146 /* check if available enough 1GB pages for each socket */
1148 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1150 int pages_avail, page_size, mem;
1152 vec_validate(mem_by_socket, c);
1153 mem = mem_by_socket[c];
1156 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1158 if (pages_avail < 0 || page_size * pages_avail < mem)
1162 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1164 if (pages_avail < 0 || page_size * pages_avail < mem)
1169 if (mem_by_socket == 0)
1171 error = clib_error_return (0, "mem_by_socket NULL");
1174 _vec_len (mem_by_socket) = c + 1;
1176 /* regenerate socket_mem string */
1177 vec_foreach_index (x, mem_by_socket)
1178 socket_mem = format (socket_mem, "%s%u",
1179 socket_mem ? "," : "", mem_by_socket[x]);
1180 socket_mem = format (socket_mem, "%c", 0);
1182 vec_free (mem_by_socket);
1184 rv = mkdir (VPP_RUN_DIR, 0755);
1185 if (rv && errno != EEXIST)
1187 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1188 VPP_RUN_DIR, errno);
1192 rv = mkdir (DEFAULT_HUGE_DIR, 0755);
1193 if (rv && errno != EEXIST)
1195 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1196 DEFAULT_HUGE_DIR, errno);
1200 if (use_1g && !(less_than_1g && use_2m))
1203 mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1207 rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1211 return clib_error_return (0, "not enough free huge pages");
1216 error = clib_error_return (0, "mount failed %d", errno);
1220 tmp = format (0, "--huge-dir%c", 0);
1221 vec_add1 (conf->eal_init_args, tmp);
1222 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1223 vec_add1 (conf->eal_init_args, tmp);
1226 tmp = format (0, "--file-prefix%c", 0);
1227 vec_add1 (conf->eal_init_args, tmp);
1228 tmp = format (0, "vpp%c", 0);
1229 vec_add1 (conf->eal_init_args, tmp);
1239 /* I'll bet that -c and -n must be the first and second args... */
1240 if (!conf->coremask_set_manually)
1242 vlib_thread_registration_t *tr;
1243 uword *coremask = 0;
1246 /* main thread core */
1247 coremask = clib_bitmap_set (coremask, tm->main_lcore, 1);
1249 for (i = 0; i < vec_len (tm->registrations); i++)
1251 tr = tm->registrations[i];
1252 coremask = clib_bitmap_or (coremask, tr->coremask);
1255 vec_insert (conf->eal_init_args, 2, 1);
1256 conf->eal_init_args[1] = (u8 *) "-c";
1257 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1258 conf->eal_init_args[2] = tmp;
1259 clib_bitmap_free (coremask);
1262 if (!conf->nchannels_set_manually)
1264 vec_insert (conf->eal_init_args, 2, 3);
1265 conf->eal_init_args[3] = (u8 *) "-n";
1266 tmp = format (0, "%d", conf->nchannels);
1267 conf->eal_init_args[4] = tmp;
1270 if (no_pci == 0 && geteuid () == 0)
1271 dpdk_bind_devices_to_uio (conf);
1274 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1275 devconf->x = conf->default_devconf.x ;
1278 pool_foreach (devconf, conf->dev_confs, ({
1280 /* default per-device config items */
1281 foreach_dpdk_device_config_item
1283 /* add DPDK EAL whitelist/blacklist entry */
1284 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1286 tmp = format (0, "-w%c", 0);
1287 vec_add1 (conf->eal_init_args, tmp);
1288 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1289 vec_add1 (conf->eal_init_args, tmp);
1291 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1293 tmp = format (0, "-b%c", 0);
1294 vec_add1 (conf->eal_init_args, tmp);
1295 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1296 vec_add1 (conf->eal_init_args, tmp);
1303 /* set master-lcore */
1304 tmp = format (0, "--master-lcore%c", 0);
1305 vec_add1 (conf->eal_init_args, tmp);
1306 tmp = format (0, "%u%c", tm->main_lcore, 0);
1307 vec_add1 (conf->eal_init_args, tmp);
1309 /* set socket-mem */
1310 tmp = format (0, "--socket-mem%c", 0);
1311 vec_add1 (conf->eal_init_args, tmp);
1312 tmp = format (0, "%s%c", socket_mem, 0);
1313 vec_add1 (conf->eal_init_args, tmp);
1315 /* NULL terminate the "argv" vector, in case of stupidity */
1316 vec_add1 (conf->eal_init_args, 0);
1317 _vec_len (conf->eal_init_args) -= 1;
1319 /* Set up DPDK eal and packet mbuf pool early. */
1321 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1323 rte_set_log_level (log_level);
1325 vm = vlib_get_main ();
1327 /* make copy of args as rte_eal_init tends to mess up with arg array */
1328 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1329 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1330 conf->eal_init_args[i]);
1333 rte_eal_init (vec_len (conf->eal_init_args),
1334 (char **) conf->eal_init_args);
1336 /* lazy umount hugepages */
1337 umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
1340 return clib_error_return (0, "rte_eal_init returned %d", ret);
1342 /* Dump the physical memory layout prior to creating the mbuf_pool */
1343 fprintf (stdout, "DPDK physical memory layout:\n");
1344 rte_dump_physmem_layout (stdout);
1346 /* main thread 1st */
1347 error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ());
1351 for (i = 0; i < RTE_MAX_LCORE; i++)
1353 error = vlib_buffer_pool_create (vm, conf->num_mbufs,
1354 rte_lcore_to_socket_id (i));
1363 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1366 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1368 vnet_main_t *vnm = vnet_get_main ();
1369 struct rte_eth_link prev_link = xd->link;
1371 u8 hw_flags_chg = 0;
1373 /* only update link state for PMD interfaces */
1374 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
1377 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1378 memset (&xd->link, 0, sizeof (xd->link));
1379 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1381 if (LINK_STATE_ELOGS)
1383 vlib_main_t *vm = vlib_get_main ();
1384 ELOG_TYPE_DECLARE (e) =
1387 "update-link-state: sw_if_index %d, admin_up %d,"
1388 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1397 ed = ELOG_DATA (&vm->elog_main, e);
1398 ed->sw_if_index = xd->vlib_sw_if_index;
1399 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1400 ed->old_link_state = (u8)
1401 vnet_hw_interface_is_link_up (vnm, xd->hw_if_index);
1402 ed->new_link_state = (u8) xd->link.link_status;
1405 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) &&
1406 ((xd->link.link_status != 0) ^
1407 vnet_hw_interface_is_link_up (vnm, xd->hw_if_index)))
1410 hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
1413 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1416 switch (xd->link.link_duplex)
1418 case ETH_LINK_HALF_DUPLEX:
1419 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1421 case ETH_LINK_FULL_DUPLEX:
1422 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1428 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1431 switch (xd->link.link_speed)
1433 case ETH_SPEED_NUM_10M:
1434 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1436 case ETH_SPEED_NUM_100M:
1437 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1439 case ETH_SPEED_NUM_1G:
1440 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1442 case ETH_SPEED_NUM_10G:
1443 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1445 case ETH_SPEED_NUM_40G:
1446 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1451 clib_warning ("unknown link speed %d", xd->link.link_speed);
1457 if (LINK_STATE_ELOGS)
1459 vlib_main_t *vm = vlib_get_main ();
1461 ELOG_TYPE_DECLARE (e) =
1464 "update-link-state: sw_if_index %d, new flags %d",.format_args
1472 ed = ELOG_DATA (&vm->elog_main, e);
1473 ed->sw_if_index = xd->vlib_sw_if_index;
1474 ed->flags = hw_flags;
1476 vnet_hw_interface_set_flags (vnm, xd->hw_if_index, hw_flags);
1481 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1483 clib_error_t *error;
1484 vnet_main_t *vnm = vnet_get_main ();
1485 dpdk_main_t *dm = &dpdk_main;
1486 ethernet_main_t *em = ðernet_main;
1488 vlib_thread_main_t *tm = vlib_get_thread_main ();
1491 error = dpdk_lib_init (dm);
1494 clib_error_report (error);
1496 tm->worker_thread_release = 1;
1498 f64 now = vlib_time_now (vm);
1499 vec_foreach (xd, dm->devices)
1501 dpdk_update_link_state (xd, now);
1506 * Extra set up for bond interfaces:
1507 * 1. Setup MACs for bond interfaces and their slave links which was set
1508 * in dpdk_port_setup() but needs to be done again here to take effect.
1509 * 2. Set up info for bond interface related CLI support.
1511 int nports = rte_eth_dev_count ();
1514 for (i = 0; i < nports; i++)
1516 xd = &dm->devices[i];
1517 ASSERT (i == xd->device_index);
1518 if (xd->pmd == VNET_DPDK_PMD_BOND)
1522 int nlink = rte_eth_bond_slaves_get (i, slink, 16);
1525 vnet_hw_interface_t *bhi;
1526 ethernet_interface_t *bei;
1529 /* Get MAC of 1st slave link */
1531 (slink[0], (struct ether_addr *) addr);
1533 /* Set MAC of bounded interface to that of 1st slave link */
1534 clib_warning ("Set MAC for bond dev# %d", i);
1535 rv = rte_eth_bond_mac_address_set
1536 (i, (struct ether_addr *) addr);
1538 clib_warning ("Set MAC addr failure rv=%d", rv);
1540 /* Populate MAC of bonded interface in VPP hw tables */
1541 bhi = vnet_get_hw_interface
1542 (vnm, dm->devices[i].hw_if_index);
1543 bei = pool_elt_at_index
1544 (em->interfaces, bhi->hw_instance);
1545 clib_memcpy (bhi->hw_address, addr, 6);
1546 clib_memcpy (bei->address, addr, 6);
1548 /* Init l3 packet size allowed on bonded interface */
1549 bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
1550 bhi->max_l3_packet_bytes[VLIB_RX] =
1551 bhi->max_l3_packet_bytes[VLIB_TX] =
1552 ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
1554 { /* for all slave links */
1555 int slave = slink[--nlink];
1556 dpdk_device_t *sdev = &dm->devices[slave];
1557 vnet_hw_interface_t *shi;
1558 vnet_sw_interface_t *ssi;
1559 ethernet_interface_t *sei;
1560 /* Add MAC to all slave links except the first one */
1563 clib_warning ("Add MAC for slave dev# %d", slave);
1564 rv = rte_eth_dev_mac_addr_add
1565 (slave, (struct ether_addr *) addr, 0);
1567 clib_warning ("Add MAC addr failure rv=%d", rv);
1569 /* Set slaves bitmap for bonded interface */
1570 bhi->bond_info = clib_bitmap_set
1571 (bhi->bond_info, sdev->hw_if_index, 1);
1572 /* Set slave link flags on slave interface */
1573 shi = vnet_get_hw_interface (vnm, sdev->hw_if_index);
1574 ssi = vnet_get_sw_interface
1575 (vnm, sdev->vlib_sw_if_index);
1576 sei = pool_elt_at_index
1577 (em->interfaces, shi->hw_instance);
1579 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1580 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1581 clib_memcpy (shi->hw_address, addr, 6);
1582 clib_memcpy (sei->address, addr, 6);
1584 /* Set l3 packet size allowed as the lowest of slave */
1585 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1586 shi->max_l3_packet_bytes[VLIB_RX])
1587 bhi->max_l3_packet_bytes[VLIB_RX] =
1588 bhi->max_l3_packet_bytes[VLIB_TX] =
1589 shi->max_l3_packet_bytes[VLIB_RX];
1591 /* Set max packet size allowed as the lowest of slave */
1592 if (bhi->max_packet_bytes > shi->max_packet_bytes)
1593 bhi->max_packet_bytes = shi->max_packet_bytes;
1604 * check each time through the loop in case intervals are changed
1606 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1607 dm->link_state_poll_interval : dm->stat_poll_interval;
1609 vlib_process_wait_for_event_or_clock (vm, min_wait);
1611 if (dm->admin_up_down_in_progress)
1612 /* skip the poll if an admin up down is in progress (on any interface) */
1615 vec_foreach (xd, dm->devices)
1617 f64 now = vlib_time_now (vm);
1618 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1619 dpdk_update_counters (xd, now);
1620 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1621 dpdk_update_link_state (xd, now);
1630 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1631 .function = dpdk_process,
1632 .type = VLIB_NODE_TYPE_PROCESS,
1633 .name = "dpdk-process",
1634 .process_log2_n_stack_bytes = 17,
1638 static clib_error_t *
1639 dpdk_init (vlib_main_t * vm)
1641 dpdk_main_t *dm = &dpdk_main;
1643 clib_error_t *error = 0;
1644 vlib_thread_main_t *tm = vlib_get_thread_main ();
1646 /* verify that structs are cacheline aligned */
1647 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1648 "Cache line marker must be 1st element in dpdk_device_t");
1649 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1650 CLIB_CACHE_LINE_BYTES,
1651 "Data in cache line 0 is bigger than cache line size");
1652 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1653 "Cache line marker must be 1st element in frame_queue_trace_t");
1656 dm->vnet_main = vnet_get_main ();
1657 dm->conf = &dpdk_config_main;
1659 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1661 return clib_error_return (0, "ethernet-input node AWOL");
1663 dm->ethernet_input_node_index = ei->index;
1665 dm->conf->nchannels = 4;
1666 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1667 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1669 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1671 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1672 dm->buffer_flags_template =
1673 (VLIB_BUFFER_TOTAL_LENGTH_VALID | VLIB_BUFFER_EXT_HDR_VALID
1674 | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT);
1676 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1677 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1680 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1686 VLIB_INIT_FUNCTION (dpdk_init);
1690 * fd.io coding-style-patch-verification: ON
1693 * eval: (c-set-style "gnu")