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 switch (dev_info.pci_dev->id.device_id)
449 case I40E_DEV_ID_10G_BASE_T:
450 case I40E_DEV_ID_SFP_XL710:
451 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
453 case I40E_DEV_ID_QSFP_A:
454 case I40E_DEV_ID_QSFP_B:
455 case I40E_DEV_ID_QSFP_C:
456 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
459 rte_eth_link_get_nowait (i, &l);
460 xd->port_type = l.link_speed == 10000 ?
461 VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G;
464 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
468 case VNET_DPDK_PMD_CXGBE:
469 switch (dev_info.pci_dev->id.device_id)
471 case 0x540d: /* T580-CR */
472 case 0x5410: /* T580-LP-cr */
473 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G;
475 case 0x5403: /* T540-CR */
476 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
479 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
483 case VNET_DPDK_PMD_MLX5:
485 char *pn_100g[] = { "MCX415A-CCAT", "MCX416A-CCAT",
486 "MCX556A-ECAT", "MCX556A-EDAT", "MCX555A-ECAT",
487 "MCX515A-CCAT", "MCX516A-CCAT", "MCX516A-CDAT", 0
489 char *pn_40g[] = { "MCX413A-BCAT", "MCX414A-BCAT",
490 "MCX415A-BCAT", "MCX416A-BCAT", "MCX4131A-BCAT", 0
492 char *pn_10g[] = { "MCX4111A-XCAT", "MCX4121A-XCAT", 0 };
494 vlib_pci_device_t *pd = vlib_get_pci_device (&pci_addr);
498 pn = format (0, "%U%c",
499 format_vlib_pci_vpd, pd->vpd_r, "PN", 0);
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_100G;
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_40G;
527 while (!found && c[0])
529 if (strncmp ((char *) pn, c[0], strlen (c[0])) == 0)
531 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G;
541 /* Intel Red Rock Canyon */
542 case VNET_DPDK_PMD_FM10K:
543 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH;
547 case VNET_DPDK_PMD_VIRTIO:
548 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
549 xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO;
550 xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO;
554 case VNET_DPDK_PMD_VMXNET3:
555 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G;
556 xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
559 case VNET_DPDK_PMD_AF_PACKET:
560 xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
561 xd->port_id = af_packet_port_id++;
564 case VNET_DPDK_PMD_BOND:
565 xd->flags |= DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE;
566 xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND;
567 xd->port_id = bond_ether_port_id++;
571 xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN;
574 if (devconf->num_rx_desc)
575 xd->nb_rx_desc = devconf->num_rx_desc;
577 if (devconf->num_tx_desc)
578 xd->nb_tx_desc = devconf->num_tx_desc;
582 * Ensure default mtu is not > the mtu read from the hardware.
583 * Otherwise rte_eth_dev_configure() will fail and the port will
586 if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen)
589 * This device does not support the platforms's max frame
590 * size. Use it's advertised mru instead.
592 xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen;
596 xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES;
599 * Some platforms do not account for Ethernet FCS (4 bytes) in
600 * MTU calculations. To interop with them increase mru but only
601 * if the device's settings can support it.
603 if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) &&
604 xd->port_conf.rxmode.hw_strip_crc)
607 * Allow additional 4 bytes (for Ethernet FCS). These bytes are
608 * stripped by h/w and so will not consume any buffer memory.
610 xd->port_conf.rxmode.max_rx_pkt_len += 4;
614 if (xd->pmd == VNET_DPDK_PMD_AF_PACKET)
616 f64 now = vlib_time_now (vm);
618 rnd = (u32) (now * 1e6);
619 rnd = random_u32 (&rnd);
620 clib_memcpy (addr + 2, &rnd, sizeof (rnd));
625 rte_eth_macaddr_get (i, (struct ether_addr *) addr);
627 if (xd->tx_q_used < tm->n_vlib_mains)
628 dpdk_device_lock_init (xd);
630 xd->device_index = xd - dm->devices;
631 ASSERT (i == xd->device_index);
632 xd->per_interface_next_index = ~0;
634 /* assign interface to input thread */
635 dpdk_device_and_queue_t *dq;
638 if (devconf->hqos_enabled)
640 xd->flags |= DPDK_DEVICE_FLAG_HQOS;
642 if (devconf->hqos.hqos_thread_valid)
644 int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread;
646 if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count)
647 return clib_error_return (0, "invalid HQoS thread index");
649 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
650 dq->device = xd->device_index;
655 int cpu = dm->hqos_cpu_first_index + next_hqos_cpu;
657 if (dm->hqos_cpu_count == 0)
658 return clib_error_return (0, "no HQoS threads available");
660 vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
661 dq->device = xd->device_index;
665 if (next_hqos_cpu == dm->hqos_cpu_count)
668 devconf->hqos.hqos_thread_valid = 1;
669 devconf->hqos.hqos_thread = cpu;
673 vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains,
674 CLIB_CACHE_LINE_BYTES);
675 for (j = 0; j < tm->n_vlib_mains; j++)
677 vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
678 sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
679 vec_reset_length (xd->tx_vectors[j]);
682 vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
683 CLIB_CACHE_LINE_BYTES);
684 for (j = 0; j < xd->rx_q_used; j++)
686 vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
687 CLIB_CACHE_LINE_BYTES);
688 vec_reset_length (xd->rx_vectors[j]);
691 vec_validate_aligned (xd->d_trace_buffers, tm->n_vlib_mains,
692 CLIB_CACHE_LINE_BYTES);
695 /* count the number of descriptors used for this device */
696 nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
698 error = ethernet_register_interface
699 (dm->vnet_main, dpdk_device_class.index, xd->device_index,
700 /* ethernet address */ addr,
701 &xd->hw_if_index, dpdk_flag_change);
705 sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->hw_if_index);
706 xd->vlib_sw_if_index = sw->sw_if_index;
707 vnet_set_device_input_node (dm->vnet_main, xd->hw_if_index,
708 dpdk_input_node.index);
710 if (devconf->workers)
715 clib_bitmap_foreach (i, devconf->workers, ({
716 vnet_device_input_assign_thread (dm->vnet_main, xd->hw_if_index, q++,
717 vdm->first_worker_thread_index + i);
722 for (q = 0; q < xd->rx_q_used; q++)
724 vnet_device_input_assign_thread (dm->vnet_main, xd->hw_if_index, q, /* any */
728 hi = vnet_get_hw_interface (dm->vnet_main, xd->hw_if_index);
730 rv = dpdk_port_setup (dm, xd);
735 if (devconf->hqos_enabled)
737 rv = dpdk_port_setup_hqos (xd, &devconf->hqos);
743 * For cisco VIC vNIC, set default to VLAN strip enabled, unless
744 * specified otherwise in the startup config.
745 * For other NICs default to VLAN strip disabled, unless specified
746 * otherwis in the startup config.
748 if (xd->pmd == VNET_DPDK_PMD_ENIC)
750 if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF)
751 vlan_strip = 1; /* remove vlan tag from VIC port by default */
753 clib_warning ("VLAN strip disabled for interface\n");
755 else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON)
761 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
762 vlan_off |= ETH_VLAN_STRIP_OFFLOAD;
763 xd->port_conf.rxmode.hw_vlan_strip = vlan_off;
764 if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0)
765 clib_warning ("VLAN strip enabled for interface\n");
767 clib_warning ("VLAN strip cannot be supported by interface\n");
770 hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] =
771 xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t);
773 rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes);
776 if (nb_desc > dm->conf->num_mbufs)
777 clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n",
778 dm->conf->num_mbufs, nb_desc);
784 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
786 vlib_pci_main_t *pm = &pci_main;
788 vlib_pci_device_t *d;
790 int num_whitelisted = vec_len (conf->dev_confs);
793 pool_foreach (d, pm->pci_devs, ({
794 dpdk_device_config_t * devconf = 0;
795 vec_reset_length (pci_addr);
796 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0);
798 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && d->device_class != PCI_CLASS_PROCESSOR_CO)
803 uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32);
808 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
812 if (d->vendor_id == 0x1af4 && d->device_id == 0x1000)
815 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
817 /* all Intel network devices */
818 else if (d->vendor_id == 0x8086 && d->device_class == PCI_CLASS_NETWORK_ETHERNET)
820 /* all Intel QAT devices VFs */
821 else if (d->vendor_id == 0x8086 && d->device_class == PCI_CLASS_PROCESSOR_CO &&
822 (d->device_id == 0x0443 || d->device_id == 0x37c9 || d->device_id == 0x19e3))
825 else if (d->vendor_id == 0x1137 && d->device_id == 0x0043)
828 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
832 clib_warning ("Unsupported PCI device 0x%04x:0x%04x found "
833 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
838 error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name);
844 pool_get (conf->dev_confs, devconf);
845 hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32,
846 devconf - conf->dev_confs);
847 devconf->pci_addr.as_u32 = d->bus_address.as_u32;
849 devconf->is_blacklisted = 1;
850 clib_error_report (error);
857 static clib_error_t *
858 dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
859 unformat_input_t * input, u8 is_default)
861 clib_error_t *error = 0;
863 dpdk_device_config_t *devconf;
864 unformat_input_t sub_input;
868 devconf = &conf->default_devconf;
872 p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32);
876 pool_get (conf->dev_confs, devconf);
877 hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32,
878 devconf - conf->dev_confs);
881 return clib_error_return (0,
882 "duplicate configuration for PCI address %U",
883 format_vlib_pci_addr, &pci_addr);
886 devconf->pci_addr.as_u32 = pci_addr.as_u32;
887 devconf->hqos_enabled = 0;
888 dpdk_device_config_hqos_default (&devconf->hqos);
893 unformat_skip_white_space (input);
894 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
896 if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues))
898 else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues))
900 else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc))
902 else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
904 else if (unformat (input, "workers %U", unformat_bitmap_list,
909 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
911 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
915 else if (unformat (input, "vlan-strip-offload off"))
916 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF;
917 else if (unformat (input, "vlan-strip-offload on"))
918 devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON;
921 (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input))
923 devconf->hqos_enabled = 1;
924 error = unformat_hqos (&sub_input, &devconf->hqos);
928 else if (unformat (input, "hqos"))
930 devconf->hqos_enabled = 1;
934 error = clib_error_return (0, "unknown input `%U'",
935 format_unformat_error, input);
943 if (devconf->workers && devconf->num_rx_queues == 0)
944 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
945 else if (devconf->workers &&
946 clib_bitmap_count_set_bits (devconf->workers) !=
947 devconf->num_rx_queues)
949 clib_error_return (0,
950 "%U: number of worker threadds must be "
951 "equal to number of rx queues", format_vlib_pci_addr,
957 static clib_error_t *
958 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
960 clib_error_t *error = 0;
961 dpdk_main_t *dm = &dpdk_main;
962 dpdk_config_main_t *conf = &dpdk_config_main;
963 vlib_thread_main_t *tm = vlib_get_thread_main ();
964 dpdk_device_config_t *devconf;
965 vlib_pci_addr_t pci_addr;
966 unformat_input_t sub_input;
968 u8 *rte_cmd = 0, *ethname = 0;
971 int num_whitelisted = 0;
978 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
980 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
983 if (unformat (input, "no-hugetlb"))
985 vec_add1 (conf->eal_init_args, (u8 *) "no-huge");
989 else if (unformat (input, "enable-tcp-udp-checksum"))
990 conf->enable_tcp_udp_checksum = 1;
992 else if (unformat (input, "decimal-interface-names"))
993 conf->interface_name_format_decimal = 1;
995 else if (unformat (input, "no-multi-seg"))
996 conf->no_multi_seg = 1;
998 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
1002 dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input,
1010 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1011 unformat_vlib_cli_sub_input, &sub_input))
1013 error = dpdk_device_config (conf, pci_addr, &sub_input, 0);
1020 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1022 error = dpdk_device_config (conf, pci_addr, 0, 0);
1029 else if (unformat (input, "num-mbufs %d", &conf->num_mbufs))
1031 else if (unformat (input, "kni %d", &conf->num_kni))
1033 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1035 else if (unformat (input, "socket-mem %s", &socket_mem))
1037 else if (unformat (input, "no-pci"))
1040 tmp = format (0, "--no-pci%c", 0);
1041 vec_add1 (conf->eal_init_args, tmp);
1043 else if (unformat (input, "poll-sleep %d", &dm->poll_sleep_usec))
1047 else if (unformat(input, #a)) \
1049 tmp = format (0, "--%s%c", #a, 0); \
1050 vec_add1 (conf->eal_init_args, tmp); \
1052 foreach_eal_double_hyphen_predicate_arg
1055 else if (unformat(input, #a " %s", &s)) \
1057 if (!strncmp(#a, "huge-dir", 8)) \
1059 else if (!strncmp(#a, "file-prefix", 11)) \
1061 tmp = format (0, "--%s%c", #a, 0); \
1062 vec_add1 (conf->eal_init_args, tmp); \
1064 if (!strncmp(#a, "vdev", 4)) \
1065 if (strstr((char*)s, "af_packet")) \
1066 clib_warning ("af_packet obsoleted. Use CLI 'create host-interface'."); \
1067 vec_add1 (conf->eal_init_args, s); \
1069 foreach_eal_double_hyphen_arg
1072 else if (unformat(input, #a " %s", &s)) \
1074 tmp = format (0, "-%s%c", #b, 0); \
1075 vec_add1 (conf->eal_init_args, tmp); \
1077 vec_add1 (conf->eal_init_args, s); \
1079 foreach_eal_single_hyphen_arg
1082 else if (unformat(input, #a " %s", &s)) \
1084 tmp = format (0, "-%s%c", #b, 0); \
1085 vec_add1 (conf->eal_init_args, tmp); \
1087 vec_add1 (conf->eal_init_args, s); \
1088 conf->a##_set_manually = 1; \
1090 foreach_eal_single_hyphen_mandatory_arg
1092 else if (unformat (input, "default"))
1095 else if (unformat_skip_white_space (input))
1099 error = clib_error_return (0, "unknown input `%U'",
1100 format_unformat_error, input);
1105 if (!conf->uio_driver_name)
1106 conf->uio_driver_name = format (0, "uio_pci_generic%c", 0);
1109 * Use 1G huge pages if available.
1111 if (!no_huge && !huge_dir)
1113 u32 x, *mem_by_socket = 0;
1117 u8 less_than_1g = 1;
1120 umount (DEFAULT_HUGE_DIR);
1122 /* Process "socket-mem" parameter value */
1123 if (vec_len (socket_mem))
1125 unformat_input_t in;
1126 unformat_init_vector (&in, socket_mem);
1127 while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT)
1129 if (unformat (&in, "%u,", &x))
1131 else if (unformat (&in, "%u", &x))
1133 else if (unformat (&in, ","))
1138 vec_add1 (mem_by_socket, x);
1143 /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */
1144 unformat_free (&in);
1150 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1152 vec_validate(mem_by_socket, c);
1153 mem_by_socket[c] = 256; /* default per-socket mem */
1159 /* check if available enough 1GB pages for each socket */
1161 clib_bitmap_foreach (c, tm->cpu_socket_bitmap, (
1163 int pages_avail, page_size, mem;
1165 vec_validate(mem_by_socket, c);
1166 mem = mem_by_socket[c];
1169 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1171 if (pages_avail < 0 || page_size * pages_avail < mem)
1175 pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024);
1177 if (pages_avail < 0 || page_size * pages_avail < mem)
1182 if (mem_by_socket == 0)
1184 error = clib_error_return (0, "mem_by_socket NULL");
1187 _vec_len (mem_by_socket) = c + 1;
1189 /* regenerate socket_mem string */
1190 vec_foreach_index (x, mem_by_socket)
1191 socket_mem = format (socket_mem, "%s%u",
1192 socket_mem ? "," : "", mem_by_socket[x]);
1193 socket_mem = format (socket_mem, "%c", 0);
1195 vec_free (mem_by_socket);
1197 rv = mkdir (VPP_RUN_DIR, 0755);
1198 if (rv && errno != EEXIST)
1200 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1201 VPP_RUN_DIR, errno);
1205 rv = mkdir (DEFAULT_HUGE_DIR, 0755);
1206 if (rv && errno != EEXIST)
1208 error = clib_error_return (0, "mkdir '%s' failed errno %d",
1209 DEFAULT_HUGE_DIR, errno);
1213 if (use_1g && !(less_than_1g && use_2m))
1216 mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
1220 rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
1224 return clib_error_return (0, "not enough free huge pages");
1229 error = clib_error_return (0, "mount failed %d", errno);
1233 tmp = format (0, "--huge-dir%c", 0);
1234 vec_add1 (conf->eal_init_args, tmp);
1235 tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
1236 vec_add1 (conf->eal_init_args, tmp);
1239 tmp = format (0, "--file-prefix%c", 0);
1240 vec_add1 (conf->eal_init_args, tmp);
1241 tmp = format (0, "vpp%c", 0);
1242 vec_add1 (conf->eal_init_args, tmp);
1252 /* I'll bet that -c and -n must be the first and second args... */
1253 if (!conf->coremask_set_manually)
1255 vlib_thread_registration_t *tr;
1256 uword *coremask = 0;
1259 /* main thread core */
1260 coremask = clib_bitmap_set (coremask, tm->main_lcore, 1);
1262 for (i = 0; i < vec_len (tm->registrations); i++)
1264 tr = tm->registrations[i];
1265 coremask = clib_bitmap_or (coremask, tr->coremask);
1268 vec_insert (conf->eal_init_args, 2, 1);
1269 conf->eal_init_args[1] = (u8 *) "-c";
1270 tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0);
1271 conf->eal_init_args[2] = tmp;
1272 clib_bitmap_free (coremask);
1275 if (!conf->nchannels_set_manually)
1277 vec_insert (conf->eal_init_args, 2, 3);
1278 conf->eal_init_args[3] = (u8 *) "-n";
1279 tmp = format (0, "%d", conf->nchannels);
1280 conf->eal_init_args[4] = tmp;
1283 if (no_pci == 0 && geteuid () == 0)
1284 dpdk_bind_devices_to_uio (conf);
1287 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1288 devconf->x = conf->default_devconf.x ;
1291 pool_foreach (devconf, conf->dev_confs, ({
1293 /* default per-device config items */
1294 foreach_dpdk_device_config_item
1296 /* add DPDK EAL whitelist/blacklist entry */
1297 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1299 tmp = format (0, "-w%c", 0);
1300 vec_add1 (conf->eal_init_args, tmp);
1301 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1302 vec_add1 (conf->eal_init_args, tmp);
1304 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1306 tmp = format (0, "-b%c", 0);
1307 vec_add1 (conf->eal_init_args, tmp);
1308 tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0);
1309 vec_add1 (conf->eal_init_args, tmp);
1316 /* set master-lcore */
1317 tmp = format (0, "--master-lcore%c", 0);
1318 vec_add1 (conf->eal_init_args, tmp);
1319 tmp = format (0, "%u%c", tm->main_lcore, 0);
1320 vec_add1 (conf->eal_init_args, tmp);
1322 /* set socket-mem */
1323 tmp = format (0, "--socket-mem%c", 0);
1324 vec_add1 (conf->eal_init_args, tmp);
1325 tmp = format (0, "%s%c", socket_mem, 0);
1326 vec_add1 (conf->eal_init_args, tmp);
1328 /* NULL terminate the "argv" vector, in case of stupidity */
1329 vec_add1 (conf->eal_init_args, 0);
1330 _vec_len (conf->eal_init_args) -= 1;
1332 /* Set up DPDK eal and packet mbuf pool early. */
1334 log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE;
1336 rte_set_log_level (log_level);
1338 vm = vlib_get_main ();
1340 /* make copy of args as rte_eal_init tends to mess up with arg array */
1341 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1342 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1343 conf->eal_init_args[i]);
1346 rte_eal_init (vec_len (conf->eal_init_args),
1347 (char **) conf->eal_init_args);
1349 /* lazy umount hugepages */
1350 umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
1353 return clib_error_return (0, "rte_eal_init returned %d", ret);
1355 /* Dump the physical memory layout prior to creating the mbuf_pool */
1356 fprintf (stdout, "DPDK physical memory layout:\n");
1357 rte_dump_physmem_layout (stdout);
1359 /* main thread 1st */
1360 error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ());
1364 for (i = 0; i < RTE_MAX_LCORE; i++)
1366 error = vlib_buffer_pool_create (vm, conf->num_mbufs,
1367 rte_lcore_to_socket_id (i));
1376 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1379 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1381 vnet_main_t *vnm = vnet_get_main ();
1382 struct rte_eth_link prev_link = xd->link;
1384 u8 hw_flags_chg = 0;
1386 /* only update link state for PMD interfaces */
1387 if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
1390 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1391 memset (&xd->link, 0, sizeof (xd->link));
1392 rte_eth_link_get_nowait (xd->device_index, &xd->link);
1394 if (LINK_STATE_ELOGS)
1396 vlib_main_t *vm = vlib_get_main ();
1397 ELOG_TYPE_DECLARE (e) =
1400 "update-link-state: sw_if_index %d, admin_up %d,"
1401 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1410 ed = ELOG_DATA (&vm->elog_main, e);
1411 ed->sw_if_index = xd->vlib_sw_if_index;
1412 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1413 ed->old_link_state = (u8)
1414 vnet_hw_interface_is_link_up (vnm, xd->hw_if_index);
1415 ed->new_link_state = (u8) xd->link.link_status;
1418 if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) &&
1419 ((xd->link.link_status != 0) ^
1420 vnet_hw_interface_is_link_up (vnm, xd->hw_if_index)))
1423 hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
1426 if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex))
1429 switch (xd->link.link_duplex)
1431 case ETH_LINK_HALF_DUPLEX:
1432 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1434 case ETH_LINK_FULL_DUPLEX:
1435 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1441 if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed))
1444 switch (xd->link.link_speed)
1446 case ETH_SPEED_NUM_10M:
1447 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M;
1449 case ETH_SPEED_NUM_100M:
1450 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M;
1452 case ETH_SPEED_NUM_1G:
1453 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G;
1455 case ETH_SPEED_NUM_10G:
1456 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G;
1458 case ETH_SPEED_NUM_40G:
1459 hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G;
1464 clib_warning ("unknown link speed %d", xd->link.link_speed);
1470 if (LINK_STATE_ELOGS)
1472 vlib_main_t *vm = vlib_get_main ();
1474 ELOG_TYPE_DECLARE (e) =
1477 "update-link-state: sw_if_index %d, new flags %d",.format_args
1485 ed = ELOG_DATA (&vm->elog_main, e);
1486 ed->sw_if_index = xd->vlib_sw_if_index;
1487 ed->flags = hw_flags;
1489 vnet_hw_interface_set_flags (vnm, xd->hw_if_index, hw_flags);
1494 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1496 clib_error_t *error;
1497 vnet_main_t *vnm = vnet_get_main ();
1498 dpdk_main_t *dm = &dpdk_main;
1499 ethernet_main_t *em = ðernet_main;
1501 vlib_thread_main_t *tm = vlib_get_thread_main ();
1504 error = dpdk_lib_init (dm);
1507 clib_error_report (error);
1509 tm->worker_thread_release = 1;
1511 f64 now = vlib_time_now (vm);
1512 vec_foreach (xd, dm->devices)
1514 dpdk_update_link_state (xd, now);
1519 * Extra set up for bond interfaces:
1520 * 1. Setup MACs for bond interfaces and their slave links which was set
1521 * in dpdk_port_setup() but needs to be done again here to take effect.
1522 * 2. Set up info for bond interface related CLI support.
1524 int nports = rte_eth_dev_count ();
1527 for (i = 0; i < nports; i++)
1529 xd = &dm->devices[i];
1530 ASSERT (i == xd->device_index);
1531 if (xd->pmd == VNET_DPDK_PMD_BOND)
1535 int nlink = rte_eth_bond_slaves_get (i, slink, 16);
1538 vnet_hw_interface_t *bhi;
1539 ethernet_interface_t *bei;
1542 /* Get MAC of 1st slave link */
1544 (slink[0], (struct ether_addr *) addr);
1546 /* Set MAC of bounded interface to that of 1st slave link */
1547 clib_warning ("Set MAC for bond dev# %d", i);
1548 rv = rte_eth_bond_mac_address_set
1549 (i, (struct ether_addr *) addr);
1551 clib_warning ("Set MAC addr failure rv=%d", rv);
1553 /* Populate MAC of bonded interface in VPP hw tables */
1554 bhi = vnet_get_hw_interface
1555 (vnm, dm->devices[i].hw_if_index);
1556 bei = pool_elt_at_index
1557 (em->interfaces, bhi->hw_instance);
1558 clib_memcpy (bhi->hw_address, addr, 6);
1559 clib_memcpy (bei->address, addr, 6);
1561 /* Init l3 packet size allowed on bonded interface */
1562 bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
1563 bhi->max_l3_packet_bytes[VLIB_RX] =
1564 bhi->max_l3_packet_bytes[VLIB_TX] =
1565 ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
1567 { /* for all slave links */
1568 int slave = slink[--nlink];
1569 dpdk_device_t *sdev = &dm->devices[slave];
1570 vnet_hw_interface_t *shi;
1571 vnet_sw_interface_t *ssi;
1572 ethernet_interface_t *sei;
1573 /* Add MAC to all slave links except the first one */
1576 clib_warning ("Add MAC for slave dev# %d", slave);
1577 rv = rte_eth_dev_mac_addr_add
1578 (slave, (struct ether_addr *) addr, 0);
1580 clib_warning ("Add MAC addr failure rv=%d", rv);
1582 /* Set slaves bitmap for bonded interface */
1583 bhi->bond_info = clib_bitmap_set
1584 (bhi->bond_info, sdev->hw_if_index, 1);
1585 /* Set slave link flags on slave interface */
1586 shi = vnet_get_hw_interface (vnm, sdev->hw_if_index);
1587 ssi = vnet_get_sw_interface
1588 (vnm, sdev->vlib_sw_if_index);
1589 sei = pool_elt_at_index
1590 (em->interfaces, shi->hw_instance);
1592 shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
1593 ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
1594 clib_memcpy (shi->hw_address, addr, 6);
1595 clib_memcpy (sei->address, addr, 6);
1597 /* Set l3 packet size allowed as the lowest of slave */
1598 if (bhi->max_l3_packet_bytes[VLIB_RX] >
1599 shi->max_l3_packet_bytes[VLIB_RX])
1600 bhi->max_l3_packet_bytes[VLIB_RX] =
1601 bhi->max_l3_packet_bytes[VLIB_TX] =
1602 shi->max_l3_packet_bytes[VLIB_RX];
1604 /* Set max packet size allowed as the lowest of slave */
1605 if (bhi->max_packet_bytes > shi->max_packet_bytes)
1606 bhi->max_packet_bytes = shi->max_packet_bytes;
1617 * check each time through the loop in case intervals are changed
1619 f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
1620 dm->link_state_poll_interval : dm->stat_poll_interval;
1622 vlib_process_wait_for_event_or_clock (vm, min_wait);
1624 if (dm->admin_up_down_in_progress)
1625 /* skip the poll if an admin up down is in progress (on any interface) */
1628 vec_foreach (xd, dm->devices)
1630 f64 now = vlib_time_now (vm);
1631 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1632 dpdk_update_counters (xd, now);
1633 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1634 dpdk_update_link_state (xd, now);
1643 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1644 .function = dpdk_process,
1645 .type = VLIB_NODE_TYPE_PROCESS,
1646 .name = "dpdk-process",
1647 .process_log2_n_stack_bytes = 17,
1651 static clib_error_t *
1652 dpdk_init (vlib_main_t * vm)
1654 dpdk_main_t *dm = &dpdk_main;
1656 clib_error_t *error = 0;
1657 vlib_thread_main_t *tm = vlib_get_thread_main ();
1659 /* verify that structs are cacheline aligned */
1660 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1661 "Cache line marker must be 1st element in dpdk_device_t");
1662 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1663 CLIB_CACHE_LINE_BYTES,
1664 "Data in cache line 0 is bigger than cache line size");
1665 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1666 "Cache line marker must be 1st element in frame_queue_trace_t");
1669 dm->vnet_main = vnet_get_main ();
1670 dm->conf = &dpdk_config_main;
1672 ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
1674 return clib_error_return (0, "ethernet-input node AWOL");
1676 dm->ethernet_input_node_index = ei->index;
1678 dm->conf->nchannels = 4;
1679 dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF;
1680 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1682 dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword));
1683 dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword));
1684 dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword));
1686 /* $$$ use n_thread_stacks since it's known-good at this point */
1687 vec_validate (dm->recycle, tm->n_thread_stacks - 1);
1689 /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */
1690 dm->buffer_flags_template =
1691 (VLIB_BUFFER_TOTAL_LENGTH_VALID | VLIB_BUFFER_EXT_HDR_VALID
1692 | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT);
1694 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1695 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1698 if ((error = vlib_call_init_function (vm, dpdk_cli_init)))
1704 VLIB_INIT_FUNCTION (dpdk_init);
1708 * fd.io coding-style-patch-verification: ON
1711 * eval: (c-set-style "gnu")