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>
20 #include <vppinfra/linux/sysfs.h>
21 #include <vlib/unix/unix.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/interface/rx_queue_funcs.h>
27 #include <vnet/interface/tx_queue_funcs.h>
28 #include <dpdk/buffer.h>
29 #include <dpdk/device/dpdk.h>
30 #include <dpdk/cryptodev/cryptodev.h>
31 #include <vlib/pci/pci.h>
32 #include <vlib/vmbus/vmbus.h>
41 #include <sys/mount.h>
46 #include <dpdk/device/dpdk_priv.h>
48 dpdk_main_t dpdk_main;
49 dpdk_config_main_t dpdk_config_main;
51 #define LINK_STATE_ELOGS 0
53 /* dev_info.speed_capa -> interface name mapppings */
58 } if_name_prefixes[] = {
59 /* sorted, higher speed first */
60 { RTE_ETH_LINK_SPEED_200G, "TwoHundredGigabitEthernet" },
61 { RTE_ETH_LINK_SPEED_100G, "HundredGigabitEthernet" },
62 { RTE_ETH_LINK_SPEED_56G, "FiftySixGigabitEthernet" },
63 { RTE_ETH_LINK_SPEED_50G, "FiftyGigabitEthernet" },
64 { RTE_ETH_LINK_SPEED_40G, "FortyGigabitEthernet" },
65 { RTE_ETH_LINK_SPEED_25G, "TwentyFiveGigabitEthernet" },
66 { RTE_ETH_LINK_SPEED_20G, "TwentyGigabitEthernet" },
67 { RTE_ETH_LINK_SPEED_10G, "TenGigabitEthernet" },
68 { RTE_ETH_LINK_SPEED_5G, "FiveGigabitEthernet" },
69 { RTE_ETH_LINK_SPEED_2_5G, "TwoDotFiveGigabitEthernet" },
70 { RTE_ETH_LINK_SPEED_1G, "GigabitEthernet" },
74 dpdk_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi,
77 dpdk_main_t *dm = &dpdk_main;
78 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
82 mtu = frame_size - xd->driver_frame_overhead;
84 rv = rte_eth_dev_set_mtu (xd->port_id, mtu);
88 dpdk_log_err ("[%u] rte_eth_dev_set_mtu failed (mtu %u, rv %d)",
89 xd->port_id, mtu, rv);
93 return vnet_error (VNET_ERR_UNSUPPORTED,
94 "dpdk driver doesn't support MTU change");
96 return vnet_error (VNET_ERR_BUSY, "port is running");
98 return vnet_error (VNET_ERR_INVALID_VALUE, "invalid MTU");
100 return vnet_error (VNET_ERR_BUG,
101 "unexpected return value %d returned from "
102 "rte_eth_dev_set_mtu(...)",
107 dpdk_log_debug ("[%u] max_frame_size set to %u by setting MTU to %u",
108 xd->port_id, frame_size, mtu);
114 dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
116 dpdk_main_t *dm = &dpdk_main;
117 dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
118 u32 old = (xd->flags & DPDK_DEVICE_FLAG_PROMISC) != 0;
122 case ETHERNET_INTERFACE_FLAG_DEFAULT_L3:
123 /* set to L3/non-promisc mode */
124 dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_PROMISC, 0);
126 case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
127 dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_PROMISC, 1);
133 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
135 if (xd->flags & DPDK_DEVICE_FLAG_PROMISC)
136 rte_eth_promiscuous_enable (xd->port_id);
138 rte_eth_promiscuous_disable (xd->port_id);
144 /* The function check_l3cache helps check if Level 3 cache exists or not on current CPUs
145 return value 1: exist.
146 return value 0: not exist.
154 const char *sys_cache_dir = "/sys/devices/system/cpu/cpu0/cache";
155 DIR *dir_cache = opendir (sys_cache_dir);
157 if (dir_cache == NULL)
160 while ((dp = readdir (dir_cache)) != NULL)
162 if (dp->d_type == DT_DIR)
165 int level_cache = -1;
167 p = format (p, "%s/%s/%s%c", sys_cache_dir, dp->d_name, "level", 0);
168 if ((err = clib_sysfs_read ((char *) p, "%d", &level_cache)))
169 clib_error_free (err);
171 if (level_cache == 3)
173 closedir (dir_cache);
179 if (dir_cache != NULL)
180 closedir (dir_cache);
185 static dpdk_device_config_t *
186 dpdk_find_startup_config (struct rte_eth_dev_info *di)
188 dpdk_main_t *dm = &dpdk_main;
189 struct rte_pci_device *pci_dev;
190 vlib_pci_addr_t pci_addr;
192 struct rte_vmbus_device *vmbus_dev;
193 vlib_vmbus_addr_t vmbus_addr;
194 #endif /* __linux__ */
197 if ((pci_dev = dpdk_get_pci_device (di)))
199 pci_addr.domain = pci_dev->addr.domain;
200 pci_addr.bus = pci_dev->addr.bus;
201 pci_addr.slot = pci_dev->addr.devid;
202 pci_addr.function = pci_dev->addr.function;
204 hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
208 if ((vmbus_dev = dpdk_get_vmbus_device (di)))
210 unformat_input_t input_vmbus;
211 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0)
212 const char *dev_name = rte_dev_name (di->device);
214 const char *dev_name = di->device->name;
216 unformat_init_string (&input_vmbus, dev_name, strlen (dev_name));
217 if (unformat (&input_vmbus, "%U", unformat_vlib_vmbus_addr, &vmbus_addr))
218 p = mhash_get (&dm->conf->device_config_index_by_vmbus_addr,
220 unformat_free (&input_vmbus);
222 #endif /* __linux__ */
225 return pool_elt_at_index (dm->conf->dev_confs, p[0]);
226 return &dm->conf->default_devconf;
229 static clib_error_t *
230 dpdk_lib_init (dpdk_main_t * dm)
232 vnet_main_t *vnm = vnet_get_main ();
234 vlib_thread_main_t *tm = vlib_get_thread_main ();
235 vnet_device_main_t *vdm = &vnet_device_main;
236 vnet_sw_interface_t *sw;
237 vnet_hw_interface_t *hi;
241 /* vlib_buffer_t template */
242 vec_validate_aligned (dm->per_thread_data, tm->n_vlib_mains - 1,
243 CLIB_CACHE_LINE_BYTES);
244 for (int i = 0; i < tm->n_vlib_mains; i++)
246 dpdk_per_thread_data_t *ptd = vec_elt_at_index (dm->per_thread_data, i);
247 clib_memset (&ptd->buffer_template, 0, sizeof (vlib_buffer_t));
248 vnet_buffer (&ptd->buffer_template)->sw_if_index[VLIB_TX] = (u32) ~ 0;
252 dm->conf->interface_name_format_decimal ? "%d/%d/%d" : "%x/%x/%x";
254 /* device config defaults */
255 dm->default_port_conf.n_rx_desc = DPDK_NB_RX_DESC_DEFAULT;
256 dm->default_port_conf.n_tx_desc = DPDK_NB_TX_DESC_DEFAULT;
257 dm->default_port_conf.n_rx_queues = 1;
258 dm->default_port_conf.n_tx_queues = tm->n_vlib_mains;
259 dm->default_port_conf.rss_hf =
260 RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP;
261 dm->default_port_conf.max_lro_pkt_size = DPDK_MAX_LRO_SIZE_DEFAULT;
263 if ((clib_mem_get_default_hugepage_size () == 2 << 20) &&
264 check_l3cache () == 0)
265 dm->default_port_conf.n_rx_desc = dm->default_port_conf.n_tx_desc = 512;
267 RTE_ETH_FOREACH_DEV (port_id)
271 struct rte_eth_dev_info di;
272 dpdk_device_config_t *devconf = 0;
273 vnet_eth_interface_registration_t eir = {};
277 if (!rte_eth_dev_is_valid_port (port_id))
280 if ((rv = rte_eth_dev_info_get (port_id, &di)) != 0)
282 dpdk_log_warn ("[%u] failed to get device info. skipping device.",
289 dpdk_log_warn ("[%u] missing device info. Skipping '%s' device",
290 port_id, di.driver_name);
294 devconf = dpdk_find_startup_config (&di);
296 /* If device is blacklisted, we should skip it */
297 if (devconf->is_blacklisted)
299 dpdk_log_notice ("[%d] Device %s blacklisted. Skipping...", port_id,
304 vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
305 xd->port_id = port_id;
306 xd->device_index = xd - dm->devices;
307 xd->per_interface_next_index = ~0;
309 clib_memcpy (&xd->conf, &dm->default_port_conf,
310 sizeof (dpdk_port_conf_t));
312 /* find driver datea for this PMD */
313 if ((dr = dpdk_driver_find (di.driver_name, &xd->if_desc)))
316 xd->supported_flow_actions = dr->supported_flow_actions;
317 xd->conf.disable_rss = dr->mq_mode_none;
318 xd->conf.disable_rx_scatter = dr->disable_rx_scatter;
319 xd->conf.enable_rxq_int = dr->enable_rxq_int;
320 if (dr->use_intel_phdr_cksum)
321 dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_INTEL_PHDR_CKSUM, 1);
322 if (dr->int_unmaskable)
323 dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_INT_UNMASKABLE, 1);
326 dpdk_log_warn ("[%u] unknown driver '%s'", port_id, di.driver_name);
330 xd->name = devconf->name;
334 struct rte_pci_device *pci_dev;
335 if (dr && dr->interface_name_prefix)
337 /* prefix override by driver */
338 xd->name = format (xd->name, "%s", dr->interface_name_prefix);
342 /* interface name prefix from speed_capa */
343 u64 mask = ~((if_name_prefixes[0].link_speed << 1) - 1);
345 if (di.speed_capa & mask)
346 dpdk_log_warn ("[%u] unknown speed capability 0x%x reported",
347 xd->port_id, di.speed_capa & mask);
349 for (int i = 0; i < ARRAY_LEN (if_name_prefixes); i++)
350 if (if_name_prefixes[i].link_speed & di.speed_capa)
353 format (xd->name, "%s", if_name_prefixes[i].pfx);
357 xd->name = format (xd->name, "Ethernet");
360 if (dr && dr->interface_number_from_port_id)
361 xd->name = format (xd->name, "%u", port_id);
362 else if ((pci_dev = dpdk_get_pci_device (&di)))
363 xd->name = format (xd->name, if_num_fmt, pci_dev->addr.bus,
364 pci_dev->addr.devid, pci_dev->addr.function);
366 xd->name = format (xd->name, "%u", port_id);
368 /* Handle representor devices that share the same PCI ID */
369 if ((di.switch_info.domain_id !=
370 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) &&
371 (di.switch_info.port_id != (uint16_t) -1))
372 xd->name = format (xd->name, "/%d", di.switch_info.port_id);
375 /* number of RX and TX queues */
376 if (devconf->num_tx_queues > 0)
378 if (di.max_tx_queues < devconf->num_tx_queues)
379 dpdk_log_warn ("[%u] Configured number of TX queues (%u) is "
380 "bigger than maximum supported (%u)",
381 port_id, devconf->num_tx_queues, di.max_tx_queues);
382 xd->conf.n_tx_queues = devconf->num_tx_queues;
385 xd->conf.n_tx_queues = clib_min (di.max_tx_queues, xd->conf.n_tx_queues);
387 if (devconf->num_rx_queues > 1 &&
388 di.max_rx_queues >= devconf->num_rx_queues)
390 xd->conf.n_rx_queues = devconf->num_rx_queues;
393 u64 unsupported_bits;
394 xd->conf.rss_hf = devconf->rss_fn;
395 unsupported_bits = xd->conf.rss_hf;
396 unsupported_bits &= ~di.flow_type_rss_offloads;
397 if (unsupported_bits)
398 dpdk_log_warn ("Unsupported RSS hash functions: %U",
399 format_dpdk_rss_hf_name, unsupported_bits);
401 xd->conf.rss_hf &= di.flow_type_rss_offloads;
402 dpdk_log_debug ("[%u] rss_hf: %U", port_id, format_dpdk_rss_hf_name,
406 #ifndef RTE_VLAN_HLEN
407 #define RTE_VLAN_HLEN 4
409 xd->driver_frame_overhead =
410 RTE_ETHER_HDR_LEN + 2 * RTE_VLAN_HLEN + RTE_ETHER_CRC_LEN;
411 #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
412 q = di.max_rx_pktlen - di.max_mtu;
414 /* attempt to protect from bogus value provided by pmd */
415 if (q < (2 * xd->driver_frame_overhead) && q > 0 &&
416 di.max_mtu != UINT16_MAX)
417 xd->driver_frame_overhead = q;
418 dpdk_log_debug ("[%u] min_mtu: %u, max_mtu: %u, min_rx_bufsize: %u, "
419 "max_rx_pktlen: %u, max_lro_pkt_size: %u",
420 xd->port_id, di.min_mtu, di.max_mtu, di.min_rx_bufsize,
421 di.max_rx_pktlen, di.max_lro_pkt_size);
423 dpdk_log_debug ("[%u] driver frame overhead is %u", port_id,
424 xd->driver_frame_overhead);
426 /* number of RX and TX tescriptors */
427 if (devconf->num_rx_desc)
428 xd->conf.n_rx_desc = devconf->num_rx_desc;
429 else if (dr && dr->n_rx_desc)
430 xd->conf.n_rx_desc = dr->n_rx_desc;
432 if (devconf->num_tx_desc)
433 xd->conf.n_tx_desc = devconf->num_tx_desc;
434 else if (dr && dr->n_tx_desc)
435 xd->conf.n_tx_desc = dr->n_tx_desc;
438 "[%u] n_rx_queues: %u n_tx_queues: %u n_rx_desc: %u n_tx_desc: %u",
439 port_id, xd->conf.n_rx_queues, xd->conf.n_tx_queues,
440 xd->conf.n_rx_desc, xd->conf.n_tx_desc);
442 vec_validate_aligned (xd->rx_queues, xd->conf.n_rx_queues - 1,
443 CLIB_CACHE_LINE_BYTES);
444 vec_validate_aligned (xd->tx_queues, xd->conf.n_tx_queues - 1,
445 CLIB_CACHE_LINE_BYTES);
447 rte_eth_macaddr_get (port_id, (void *) addr);
449 /* create interface */
450 eir.dev_class_index = dpdk_device_class.index;
451 eir.dev_instance = xd->device_index;
453 eir.cb.flag_change = dpdk_flag_change;
454 eir.cb.set_max_frame_size = dpdk_set_max_frame_size;
455 xd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
456 hi = vnet_get_hw_interface (vnm, xd->hw_if_index);
457 numa_node = (i8) rte_eth_dev_socket_id (port_id);
458 if (numa_node == SOCKET_ID_ANY)
459 /* numa_node is not set, default to 0 */
460 hi->numa_node = xd->cpu_socket = 0;
462 hi->numa_node = xd->cpu_socket = numa_node;
463 sw = vnet_get_hw_sw_interface (vnm, xd->hw_if_index);
464 xd->sw_if_index = sw->sw_if_index;
465 dpdk_log_debug ("[%u] interface %v created", port_id, hi->name);
468 vnet_set_sw_interface_tag (vnm, devconf->tag, sw->sw_if_index);
470 ethernet_set_flags (vnm, xd->hw_if_index,
471 ETHERNET_INTERFACE_FLAG_DEFAULT_L3);
473 /* assign worker threads */
474 vnet_hw_if_set_input_node (vnm, xd->hw_if_index, dpdk_input_node.index);
475 if (devconf->workers)
479 clib_bitmap_foreach (j, devconf->workers)
481 dpdk_rx_queue_t *rxq = vec_elt_at_index (xd->rx_queues, q);
482 rxq->queue_index = vnet_hw_if_register_rx_queue (
483 vnm, xd->hw_if_index, q++, vdm->first_worker_thread_index + j);
487 for (q = 0; q < xd->conf.n_rx_queues; q++)
489 dpdk_rx_queue_t *rxq = vec_elt_at_index (xd->rx_queues, q);
490 rxq->queue_index = vnet_hw_if_register_rx_queue (
491 vnm, xd->hw_if_index, q, VNET_HW_IF_RXQ_THREAD_ANY);
494 for (q = 0; q < xd->conf.n_tx_queues; q++)
496 dpdk_tx_queue_t *txq = vec_elt_at_index (xd->tx_queues, q);
498 vnet_hw_if_register_tx_queue (vnm, xd->hw_if_index, q);
501 for (q = 0; q < tm->n_vlib_mains; q++)
503 u32 qi = xd->tx_queues[q % xd->conf.n_tx_queues].queue_index;
504 vnet_hw_if_tx_queue_assign_thread (vnm, qi, q);
507 if (devconf->tso == DPDK_DEVICE_TSO_ON)
509 /*tcp_udp checksum must be enabled*/
510 if (xd->conf.enable_tcp_udp_checksum == 0)
511 dpdk_log_warn ("[%u] TCP/UDP checksum offload must be enabled",
513 else if ((di.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0)
514 dpdk_log_warn ("[%u] TSO not supported by device", xd->port_id);
516 xd->conf.enable_tso = 1;
519 if (devconf->max_lro_pkt_size)
520 xd->conf.max_lro_pkt_size = devconf->max_lro_pkt_size;
522 dpdk_device_setup (xd);
524 /* rss queues should be configured after dpdk_device_setup() */
525 if (devconf->rss_queues)
527 if (vnet_hw_interface_set_rss_queues (vnet_get_main (), hi,
528 devconf->rss_queues))
529 dpdk_log_warn ("[%u] Failed to set rss queues", port_id);
532 if (vec_len (xd->errors))
533 dpdk_log_err ("[%u] setup failed Errors:\n %U", port_id,
534 format_dpdk_device_errors, xd);
537 for (int i = 0; i < vec_len (dm->devices); i++)
538 vnet_hw_if_update_runtime_data (vnm, dm->devices[i].hw_if_index);
544 dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
546 vlib_main_t *vm = vlib_get_main ();
549 int num_whitelisted = vec_len (conf->dev_confs);
550 vlib_pci_device_info_t *d = 0;
551 vlib_pci_addr_t *addr = 0, *addrs;
554 addrs = vlib_pci_get_all_dev_addrs ();
555 vec_foreach (addr, addrs)
557 dpdk_device_config_t * devconf = 0;
558 vec_reset_length (pci_addr);
559 pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, addr, 0);
562 vlib_pci_free_device_info (d);
565 d = vlib_pci_get_device_info (vm, addr, &error);
568 vlib_log_warn (dpdk_main.log_default, "%U", format_clib_error, error);
569 clib_error_free (error);
575 * The defines for the PCI_CLASS_* types are platform specific and differ
578 if (d->device_class != PCI_CLASS_NETWORK &&
579 d->device_class != PCI_CLASS_PROCESSOR_CO)
582 if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && d->device_class != PCI_CLASS_PROCESSOR_CO)
584 #endif /* __FreeBSD__ */
588 uword * p = hash_get (conf->device_config_index_by_pci_addr, addr->as_u32);
596 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
599 /* Enforce Device blacklist by vendor and device */
600 for (i = 0; i < vec_len (conf->blacklist_by_pci_vendor_and_device); i++)
603 vendor = (u16)(conf->blacklist_by_pci_vendor_and_device[i] >> 16);
604 device = (u16)(conf->blacklist_by_pci_vendor_and_device[i] & 0xFFFF);
605 if (d->vendor_id == vendor && d->device_id == device)
608 * Expected case: device isn't whitelisted,
613 /* Device is blacklisted */
614 pool_get (conf->dev_confs, devconf);
615 hash_set (conf->device_config_index_by_pci_addr, addr->as_u32,
616 devconf - conf->dev_confs);
617 devconf->pci_addr.as_u32 = addr->as_u32;
618 devconf->dev_addr_type = VNET_DEV_ADDR_PCI;
619 devconf->is_blacklisted = 1;
622 else /* explicitly whitelisted, ignore the device blacklist */
628 if (d->vendor_id == 0x1af4 &&
629 (d->device_id == VIRTIO_PCI_LEGACY_DEVICEID_NET ||
630 d->device_id == VIRTIO_PCI_MODERN_DEVICEID_NET))
633 else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0)
636 * For vmxnet3 PCI, unless it is explicitly specified in the whitelist,
637 * the default is to put it in the blacklist.
641 pool_get (conf->dev_confs, devconf);
642 hash_set (conf->device_config_index_by_pci_addr, addr->as_u32,
643 devconf - conf->dev_confs);
644 devconf->pci_addr.as_u32 = addr->as_u32;
645 devconf->is_blacklisted = 1;
648 /* all Intel network devices */
649 else if (d->vendor_id == 0x8086 && d->device_class == PCI_CLASS_NETWORK_ETHERNET)
651 /* all Intel QAT devices VFs */
652 else if (d->vendor_id == 0x8086 &&
653 d->device_class == PCI_CLASS_PROCESSOR_CO &&
654 (d->device_id == 0x0443 || d->device_id == 0x18a1 ||
655 d->device_id == 0x19e3 || d->device_id == 0x37c9 ||
656 d->device_id == 0x6f55 || d->device_id == 0x18ef ||
657 d->device_id == 0x4941 || d->device_id == 0x4943 ||
658 d->device_id == 0x4945))
661 else if (d->vendor_id == 0x1137 &&
662 (d->device_id == 0x0043 || d->device_id == 0x0071))
665 else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000)
667 /* Amazon Elastic Network Adapter */
668 else if (d->vendor_id == 0x1d0f && d->device_id >= 0xec20 && d->device_id <= 0xec21)
670 /* Cavium Network Adapter */
671 else if (d->vendor_id == 0x177d && d->device_id == 0x9712)
673 /* Cavium FastlinQ QL41000 Series */
674 else if (d->vendor_id == 0x1077 && d->device_id >= 0x8070 && d->device_id <= 0x8090)
676 /* Mellanox CX3, CX3VF */
677 else if (d->vendor_id == 0x15b3 && d->device_id >= 0x1003 && d->device_id <= 0x1004)
681 /* Mellanox CX4, CX4VF, CX4LX, CX4LXVF, CX5, CX5VF, CX5EX, CX5EXVF */
682 else if (d->vendor_id == 0x15b3 && d->device_id >= 0x1013 && d->device_id <= 0x101a)
686 /* Mellanox CX6, CX6VF, CX6DX, CX6DXVF, CX6LX */
687 else if (d->vendor_id == 0x15b3 &&
688 (d->device_id >= 0x101b && d->device_id <= 0x101f))
693 else if (d->vendor_id == 0x15b3 && d->device_id == 0x1021)
697 /* Mellanox BF, BFVF */
698 else if (d->vendor_id == 0x15b3 &&
699 (d->device_id >= 0xa2d2 && d->device_id <= 0Xa2d3))
703 /* Mellanox BF2, BF3 */
704 else if (d->vendor_id == 0x15b3 &&
705 (d->device_id == 0xa2d6 || d->device_id == 0xa2dc))
709 /* Broadcom NetXtreme S, and E series only */
710 else if (d->vendor_id == 0x14e4 &&
711 ((d->device_id >= 0x16c0 &&
712 d->device_id != 0x16c6 && d->device_id != 0x16c7 &&
713 d->device_id != 0x16dd && d->device_id != 0x16f7 &&
714 d->device_id != 0x16fd && d->device_id != 0x16fe &&
715 d->device_id != 0x170d && d->device_id != 0x170c &&
716 d->device_id != 0x170e && d->device_id != 0x1712 &&
717 d->device_id != 0x1713) ||
718 (d->device_id == 0x1604 || d->device_id == 0x1605 ||
719 d->device_id == 0x1614 || d->device_id == 0x1606 ||
720 d->device_id == 0x1609 || d->device_id == 0x1614)))
723 else if (d->vendor_id == 0x1ae0 && d->device_id == 0x0042)
727 dpdk_log_warn ("Unsupported PCI device 0x%04x:0x%04x found "
728 "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id,
733 error = vlib_pci_bind_to_uio (vm, addr, (char *) conf->uio_driver_name,
734 conf->uio_bind_force);
740 pool_get (conf->dev_confs, devconf);
741 hash_set (conf->device_config_index_by_pci_addr, addr->as_u32,
742 devconf - conf->dev_confs);
743 devconf->pci_addr.as_u32 = addr->as_u32;
745 devconf->dev_addr_type = VNET_DEV_ADDR_PCI;
746 devconf->is_blacklisted = 1;
747 clib_error_report (error);
751 vlib_pci_free_device_info (d);
755 dpdk_bind_vmbus_devices_to_uio (dpdk_config_main_t * conf)
758 vlib_vmbus_addr_t *addrs, *addr = 0;
759 int num_whitelisted = vec_len (conf->dev_confs);
762 addrs = vlib_vmbus_get_all_dev_addrs ();
764 vec_foreach (addr, addrs)
766 dpdk_device_config_t *devconf = 0;
770 mhash_get (&conf->device_config_index_by_vmbus_addr, addr);
773 /* No devices blacklisted, but have whitelisted. blacklist all
775 pool_get (conf->dev_confs, devconf);
776 mhash_set (&conf->device_config_index_by_vmbus_addr, addr,
777 devconf - conf->dev_confs, 0);
778 devconf->vmbus_addr = *addr;
779 devconf->dev_addr_type = VNET_DEV_ADDR_VMBUS;
780 devconf->is_blacklisted = 1;
785 devconf = pool_elt_at_index (conf->dev_confs, p[0]);
788 /* Enforce Device blacklist by vmbus_addr */
789 for (i = 0; i < vec_len (conf->blacklist_by_vmbus_addr); i++)
791 vlib_vmbus_addr_t *a1 = &conf->blacklist_by_vmbus_addr[i];
792 vlib_vmbus_addr_t *a2 = addr;
793 if (memcmp (a1, a2, sizeof (vlib_vmbus_addr_t)) == 0)
797 /* Device not whitelisted */
798 pool_get (conf->dev_confs, devconf);
799 mhash_set (&conf->device_config_index_by_vmbus_addr, addr,
800 devconf - conf->dev_confs, 0);
801 devconf->vmbus_addr = *addr;
802 devconf->dev_addr_type = VNET_DEV_ADDR_VMBUS;
803 devconf->is_blacklisted = 1;
813 error = vlib_vmbus_bind_to_uio (addr);
818 pool_get (conf->dev_confs, devconf);
819 mhash_set (&conf->device_config_index_by_vmbus_addr, addr,
820 devconf - conf->dev_confs, 0);
821 devconf->vmbus_addr = *addr;
823 devconf->dev_addr_type = VNET_DEV_ADDR_VMBUS;
824 devconf->is_blacklisted = 1;
825 clib_error_report (error);
831 unformat_max_simd_bitwidth (unformat_input_t *input, va_list *va)
833 uword *max_simd_bitwidth = va_arg (*va, uword *);
835 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
837 if (!unformat (input, "%u", max_simd_bitwidth))
840 if (*max_simd_bitwidth != DPDK_MAX_SIMD_BITWIDTH_256 &&
841 *max_simd_bitwidth != DPDK_MAX_SIMD_BITWIDTH_512)
849 static clib_error_t *
850 dpdk_device_config (dpdk_config_main_t *conf, void *addr,
851 dpdk_device_addr_type_t addr_type, unformat_input_t *input,
854 clib_error_t *error = 0;
856 dpdk_device_config_t *devconf = 0;
857 unformat_input_t sub_input;
861 devconf = &conf->default_devconf;
863 else if (addr_type == VNET_DEV_ADDR_PCI)
865 p = hash_get (conf->device_config_index_by_pci_addr,
866 ((vlib_pci_addr_t *) (addr))->as_u32);
870 pool_get (conf->dev_confs, devconf);
871 hash_set (conf->device_config_index_by_pci_addr,
872 ((vlib_pci_addr_t *) (addr))->as_u32,
873 devconf - conf->dev_confs);
876 return clib_error_return (0,
877 "duplicate configuration for PCI address %U",
878 format_vlib_pci_addr, addr);
880 else if (addr_type == VNET_DEV_ADDR_VMBUS)
882 p = mhash_get (&conf->device_config_index_by_vmbus_addr,
883 (vlib_vmbus_addr_t *) (addr));
887 pool_get (conf->dev_confs, devconf);
888 mhash_set (&conf->device_config_index_by_vmbus_addr, addr,
889 devconf - conf->dev_confs, 0);
892 return clib_error_return (
893 0, "duplicate configuration for VMBUS address %U",
894 format_vlib_vmbus_addr, addr);
897 if (addr_type == VNET_DEV_ADDR_PCI)
899 devconf->pci_addr.as_u32 = ((vlib_pci_addr_t *) (addr))->as_u32;
900 devconf->tso = DPDK_DEVICE_TSO_DEFAULT;
901 devconf->dev_addr_type = VNET_DEV_ADDR_PCI;
903 else if (addr_type == VNET_DEV_ADDR_VMBUS)
905 devconf->vmbus_addr = *((vlib_vmbus_addr_t *) (addr));
906 devconf->tso = DPDK_DEVICE_TSO_DEFAULT;
907 devconf->dev_addr_type = VNET_DEV_ADDR_VMBUS;
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, "name %v", &devconf->name))
926 else if (unformat (input, "tag %s", &devconf->tag))
928 else if (unformat (input, "workers %U", unformat_bitmap_list,
933 (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input))
935 error = unformat_rss_fn (&sub_input, &devconf->rss_fn);
939 else if (unformat (input, "tso on"))
941 devconf->tso = DPDK_DEVICE_TSO_ON;
943 else if (unformat (input, "tso off"))
945 devconf->tso = DPDK_DEVICE_TSO_OFF;
947 else if (unformat (input, "devargs %s", &devconf->devargs))
949 else if (unformat (input, "rss-queues %U",
950 unformat_bitmap_list, &devconf->rss_queues))
952 else if (unformat (input, "max-lro-pkt-size %u",
953 &devconf->max_lro_pkt_size))
957 error = clib_error_return (0, "unknown input `%U'",
958 format_unformat_error, input);
966 if (devconf->workers && devconf->num_rx_queues == 0)
967 devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers);
968 else if (devconf->workers &&
969 clib_bitmap_count_set_bits (devconf->workers) !=
970 devconf->num_rx_queues)
971 error = clib_error_return (0,
972 "%U: number of worker threads must be "
973 "equal to number of rx queues",
974 format_vlib_pci_addr, addr);
979 static clib_error_t *
980 dpdk_log_read_ready (clib_file_t * uf)
982 unformat_input_t input;
989 uword len = vec_len (s);
990 vec_resize (s, len + n_try);
992 n = read (uf->file_descriptor, s + len, n_try);
993 if (n < 0 && errno != EAGAIN)
994 return clib_error_return_unix (0, "read");
995 vec_set_len (s, len + (n < 0 ? 0 : n));
998 unformat_init_vector (&input, s);
1000 while (unformat_user (&input, unformat_line, &line))
1005 /* unfortunatelly DPDK polutes log with this error messages
1006 * even when we pass --in-memory which means no secondary process */
1007 if (strstr ((char *) line, "WARNING! Base virtual address hint"))
1009 else if (strstr ((char *) line, "This may cause issues with mapping "
1010 "memory into secondary processes"))
1014 dpdk_log_notice ("%v", line);
1018 unformat_free (&input);
1022 static clib_error_t *
1023 dpdk_set_stat_poll_interval (f64 interval)
1025 if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
1026 return clib_error_return (0, "wrong stats-poll-interval value");
1028 dpdk_main.stat_poll_interval = interval;
1032 static clib_error_t *
1033 dpdk_set_link_state_poll_interval (f64 interval)
1035 if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
1036 return clib_error_return (0, "wrong link-state-poll-interval value");
1038 dpdk_main.link_state_poll_interval = interval;
1042 static clib_error_t *
1043 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
1045 dpdk_main_t *dm = &dpdk_main;
1046 clib_error_t *error = 0;
1047 dpdk_config_main_t *conf = &dpdk_config_main;
1048 vlib_thread_main_t *tm = vlib_get_thread_main ();
1049 dpdk_device_config_t *devconf;
1050 vlib_pci_addr_t pci_addr = { 0 };
1051 vlib_vmbus_addr_t vmbus_addr = { 0 };
1052 unformat_input_t sub_input;
1053 uword default_hugepage_sz, x;
1056 int num_whitelisted = 0;
1057 int eal_no_hugetlb = 0;
1062 u32 vendor, device, domain, bus, func;
1067 conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
1068 mhash_init (&conf->device_config_index_by_vmbus_addr, sizeof (uword),
1069 sizeof (vlib_vmbus_addr_t));
1071 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1073 /* Prime the pump */
1074 if (unformat (input, "no-hugetlb"))
1076 vec_add1 (conf->eal_init_args, (u8 *) "--no-huge");
1079 else if (unformat (input, "telemetry"))
1080 conf->enable_telemetry = 1;
1082 else if (unformat (input, "enable-tcp-udp-checksum"))
1084 dm->default_port_conf.enable_tcp_udp_checksum = 1;
1085 if (unformat (input, "enable-outer-checksum-offload"))
1086 dm->default_port_conf.enable_outer_checksum_offload = 1;
1088 else if (unformat (input, "no-tx-checksum-offload"))
1089 dm->default_port_conf.disable_tx_checksum_offload = 1;
1091 else if (unformat (input, "decimal-interface-names"))
1092 conf->interface_name_format_decimal = 1;
1094 else if (unformat (input, "no-multi-seg"))
1095 dm->default_port_conf.disable_multi_seg = 1;
1096 else if (unformat (input, "enable-lro"))
1097 dm->default_port_conf.enable_lro = 1;
1098 else if (unformat (input, "max-simd-bitwidth %U",
1099 unformat_max_simd_bitwidth, &conf->max_simd_bitwidth))
1101 else if (unformat (input, "link-state-poll-interval %f", &poll_interval))
1103 error = dpdk_set_link_state_poll_interval (poll_interval);
1107 else if (unformat (input, "stats-poll-interval %f", &poll_interval))
1109 error = dpdk_set_stat_poll_interval (poll_interval);
1113 else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
1117 dpdk_device_config (conf, 0, VNET_DEV_ADDR_ANY, &sub_input, 1);
1124 (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr,
1125 unformat_vlib_cli_sub_input, &sub_input))
1127 error = dpdk_device_config (conf, &pci_addr, VNET_DEV_ADDR_PCI,
1135 else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr))
1138 dpdk_device_config (conf, &pci_addr, VNET_DEV_ADDR_PCI, 0, 0);
1145 else if (unformat (input, "dev %U %U", unformat_vlib_vmbus_addr,
1146 &vmbus_addr, unformat_vlib_cli_sub_input, &sub_input))
1148 error = dpdk_device_config (conf, &vmbus_addr, VNET_DEV_ADDR_VMBUS,
1156 else if (unformat (input, "dev %U", unformat_vlib_vmbus_addr,
1160 dpdk_device_config (conf, &vmbus_addr, VNET_DEV_ADDR_VMBUS, 0, 0);
1167 else if (unformat (input, "uio-driver %s", &conf->uio_driver_name))
1169 else if (unformat (input, "uio-bind-force"))
1170 conf->uio_bind_force = 1;
1171 else if (unformat (input, "socket-mem %s", &socket_mem))
1173 else if (unformat (input, "no-pci"))
1176 tmp = format (0, "--no-pci%c", 0);
1177 vec_add1 (conf->eal_init_args, tmp);
1179 else if (unformat (input, "blacklist %U", unformat_vlib_vmbus_addr,
1182 vec_add1 (conf->blacklist_by_vmbus_addr, vmbus_addr);
1186 (input, "blacklist %x:%x:%x.%x", &domain, &bus, &device, &func))
1188 tmp = format (0, "-b%c", 0);
1189 vec_add1 (conf->eal_init_args, tmp);
1191 format (0, "%04x:%02x:%02x.%x%c", domain, bus, device, func, 0);
1192 vec_add1 (conf->eal_init_args, tmp);
1194 else if (unformat (input, "blacklist %x:%x", &vendor, &device))
1196 u32 blacklist_entry;
1197 if (vendor > 0xFFFF)
1198 return clib_error_return (0, "blacklist PCI vendor out of range");
1199 if (device > 0xFFFF)
1200 return clib_error_return (0, "blacklist PCI device out of range");
1201 blacklist_entry = (vendor << 16) | (device & 0xffff);
1202 vec_add1 (conf->blacklist_by_pci_vendor_and_device,
1205 else if (unformat (input, "no-vmbus"))
1208 tmp = format (0, "--no-vmbus%c", 0);
1209 vec_add1 (conf->eal_init_args, tmp);
1213 else if (unformat(input, #a)) \
1215 tmp = format (0, "--%s%c", #a, 0); \
1216 vec_add1 (conf->eal_init_args, tmp); \
1218 foreach_eal_double_hyphen_predicate_arg
1221 else if (unformat(input, #a " %s", &s)) \
1223 if (!strncmp(#a, "file-prefix", 11)) \
1225 tmp = format (0, "--%s%c", #a, 0); \
1226 vec_add1 (conf->eal_init_args, tmp); \
1228 if (!strncmp(#a, "vdev", 4)) \
1229 if (strstr((char*)s, "af_packet")) \
1230 clib_warning ("af_packet obsoleted. Use CLI 'create host-interface'."); \
1231 vec_add1 (conf->eal_init_args, s); \
1233 foreach_eal_double_hyphen_arg
1236 else if (unformat(input, #a " %s", &s)) \
1238 tmp = format (0, "-%s%c", #b, 0); \
1239 vec_add1 (conf->eal_init_args, tmp); \
1241 vec_add1 (conf->eal_init_args, s); \
1243 foreach_eal_single_hyphen_arg
1245 else if (unformat (input, "default"))
1248 else if (unformat_skip_white_space (input))
1250 else return clib_error_return (0, "unknown input `%U'",
1251 format_unformat_error, input);
1254 if (!conf->uio_driver_name)
1255 conf->uio_driver_name = format (0, "auto%c", 0);
1257 if (eal_no_hugetlb == 0)
1259 vec_add1 (conf->eal_init_args, (u8 *) "--in-memory");
1261 default_hugepage_sz = clib_mem_get_default_hugepage_size ();
1263 clib_bitmap_foreach (x, tm->cpu_socket_bitmap)
1267 /* preallocate at least 16MB of hugepages per socket,
1268 if more is needed it is up to consumer to preallocate more */
1269 n_pages = round_pow2 ((uword) 16 << 20, default_hugepage_sz);
1270 n_pages /= default_hugepage_sz;
1272 if ((e = clib_sysfs_prealloc_hugepages(x, 0, n_pages)))
1273 clib_error_report (e);
1277 /* on/off dpdk's telemetry thread */
1278 if (conf->enable_telemetry == 0)
1280 vec_add1 (conf->eal_init_args, (u8 *) "--no-telemetry");
1286 tmp = format (0, "--file-prefix%c", 0);
1287 vec_add1 (conf->eal_init_args, tmp);
1288 tmp = format (0, "vpp%c", 0);
1289 vec_add1 (conf->eal_init_args, tmp);
1293 if (no_pci == 0 && geteuid () == 0)
1294 dpdk_bind_devices_to_uio (conf);
1296 if (no_vmbus == 0 && geteuid () == 0)
1297 dpdk_bind_vmbus_devices_to_uio (conf);
1300 if (devconf->x == 0 && conf->default_devconf.x > 0) \
1301 devconf->x = conf->default_devconf.x ;
1303 pool_foreach (devconf, conf->dev_confs) {
1305 /* default per-device config items */
1306 foreach_dpdk_device_config_item
1308 /* copy tso config from default device */
1311 /* copy tso config from default device */
1314 /* copy rss_queues config from default device */
1317 /* assume that default is PCI */
1318 fmt_func = format_vlib_pci_addr;
1319 fmt_addr = &devconf->pci_addr;
1321 if (devconf->dev_addr_type == VNET_DEV_ADDR_VMBUS)
1323 fmt_func = format_vlib_vmbus_addr;
1324 fmt_addr = &devconf->vmbus_addr;
1327 /* add DPDK EAL whitelist/blacklist entry */
1328 if (num_whitelisted > 0 && devconf->is_blacklisted == 0)
1330 tmp = format (0, "-a%c", 0);
1331 vec_add1 (conf->eal_init_args, tmp);
1332 if (devconf->devargs)
1335 format (0, "%U,%s%c", fmt_func, fmt_addr, devconf->devargs, 0);
1339 tmp = format (0, "%U%c", fmt_func, fmt_addr, 0);
1341 vec_add1 (conf->eal_init_args, tmp);
1343 else if (num_whitelisted == 0 && devconf->is_blacklisted != 0)
1345 tmp = format (0, "-b%c", 0);
1346 vec_add1 (conf->eal_init_args, tmp);
1347 tmp = format (0, "%U%c", fmt_func, fmt_addr, 0);
1348 vec_add1 (conf->eal_init_args, tmp);
1355 clib_warning ("socket-mem argument is deprecated");
1357 /* NULL terminate the "argv" vector, in case of stupidity */
1358 vec_add1 (conf->eal_init_args, 0);
1359 vec_dec_len (conf->eal_init_args, 1);
1361 /* Set up DPDK eal and packet mbuf pool early. */
1363 int log_fds[2] = { 0 };
1364 if (pipe (log_fds) == 0)
1366 if (fcntl (log_fds[0], F_SETFL, O_NONBLOCK) == 0 &&
1367 fcntl (log_fds[1], F_SETFL, O_NONBLOCK) == 0)
1369 FILE *f = fdopen (log_fds[1], "a");
1370 if (f && rte_openlog_stream (f) == 0)
1372 clib_file_t t = { 0 };
1373 t.read_function = dpdk_log_read_ready;
1374 t.file_descriptor = log_fds[0];
1375 t.description = format (0, "DPDK logging pipe");
1376 clib_file_add (&file_main, &t);
1386 vm = vlib_get_main ();
1388 /* make copy of args as rte_eal_init tends to mess up with arg array */
1389 for (i = 1; i < vec_len (conf->eal_init_args); i++)
1390 conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ",
1391 conf->eal_init_args[i]);
1393 vec_terminate_c_string (conf->eal_init_args_str);
1395 dpdk_log_notice ("EAL init args: %s", conf->eal_init_args_str);
1396 ret = rte_eal_init (vec_len (conf->eal_init_args),
1397 (char **) conf->eal_init_args);
1399 return clib_error_return (0, "rte_eal_init returned %d", ret);
1401 /* enable the AVX-512 vPMDs in DPDK */
1402 if (clib_cpu_supports_avx512_bitalg () &&
1403 conf->max_simd_bitwidth == DPDK_MAX_SIMD_BITWIDTH_DEFAULT)
1404 rte_vect_set_max_simd_bitwidth (RTE_VECT_SIMD_512);
1405 else if (conf->max_simd_bitwidth != DPDK_MAX_SIMD_BITWIDTH_DEFAULT)
1406 rte_vect_set_max_simd_bitwidth (conf->max_simd_bitwidth ==
1407 DPDK_MAX_SIMD_BITWIDTH_256 ?
1411 /* main thread 1st */
1412 if ((error = dpdk_buffer_pools_create (vm)))
1418 VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk");
1421 dpdk_update_link_state (dpdk_device_t * xd, f64 now)
1423 vnet_main_t *vnm = vnet_get_main ();
1424 struct rte_eth_link prev_link = xd->link;
1426 u8 hw_flags_chg = 0;
1428 xd->time_last_link_update = now ? now : xd->time_last_link_update;
1429 clib_memset (&xd->link, 0, sizeof (xd->link));
1430 rte_eth_link_get_nowait (xd->port_id, &xd->link);
1432 if (LINK_STATE_ELOGS)
1434 ELOG_TYPE_DECLARE (e) =
1437 "update-link-state: sw_if_index %d, admin_up %d,"
1438 "old link_state %d new link_state %d",.format_args = "i4i1i1i1",};
1447 ed = ELOG_DATA (&vlib_global_main.elog_main, e);
1448 ed->sw_if_index = xd->sw_if_index;
1449 ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
1450 ed->old_link_state = (u8)
1451 vnet_hw_interface_is_link_up (vnm, xd->hw_if_index);
1452 ed->new_link_state = (u8) xd->link.link_status;
1455 hw_flags_chg = ((xd->link.link_duplex != prev_link.link_duplex) ||
1456 (xd->link.link_status != prev_link.link_status));
1458 if (xd->link.link_speed != prev_link.link_speed)
1459 vnet_hw_interface_set_link_speed (vnm, xd->hw_if_index,
1460 (xd->link.link_speed == UINT32_MAX) ?
1462 xd->link.link_speed * 1000);
1466 if (xd->link.link_status)
1467 hw_flags |= VNET_HW_INTERFACE_FLAG_LINK_UP;
1469 switch (xd->link.link_duplex)
1471 case RTE_ETH_LINK_HALF_DUPLEX:
1472 hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX;
1474 case RTE_ETH_LINK_FULL_DUPLEX:
1475 hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX;
1481 if (LINK_STATE_ELOGS)
1483 ELOG_TYPE_DECLARE (e) =
1486 "update-link-state: sw_if_index %d, new flags %d",.format_args
1494 ed = ELOG_DATA (&vlib_global_main.elog_main, e);
1495 ed->sw_if_index = xd->sw_if_index;
1496 ed->flags = hw_flags;
1498 vnet_hw_interface_set_flags (vnm, xd->hw_if_index, hw_flags);
1503 dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1505 clib_error_t *error;
1506 dpdk_main_t *dm = &dpdk_main;
1508 vlib_thread_main_t *tm = vlib_get_thread_main ();
1510 vlib_worker_thread_barrier_sync (vm);
1511 error = dpdk_lib_init (dm);
1514 clib_error_report (error);
1516 if (dpdk_cryptodev_init)
1518 error = dpdk_cryptodev_init (vm);
1521 vlib_log_warn (dpdk_main.log_cryptodev, "%U", format_clib_error,
1523 clib_error_free (error);
1527 vlib_worker_thread_barrier_release (vm);
1528 tm->worker_thread_release = 1;
1530 f64 now = vlib_time_now (vm);
1531 vec_foreach (xd, dm->devices)
1533 dpdk_update_link_state (xd, now);
1537 clib_min (dm->link_state_poll_interval, dm->stat_poll_interval);
1541 f64 min_wait = clib_max (timeout, DPDK_MIN_POLL_INTERVAL);
1542 vlib_process_wait_for_event_or_clock (vm, min_wait);
1545 clib_min (dm->link_state_poll_interval, dm->stat_poll_interval);
1547 if (dm->admin_up_down_in_progress)
1548 /* skip the poll if an admin up down is in progress (on any interface) */
1551 vec_foreach (xd, dm->devices)
1553 f64 now = vlib_time_now (vm);
1554 if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval)
1555 dpdk_update_counters (xd, now);
1556 if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval)
1557 dpdk_update_link_state (xd, now);
1561 now = vlib_time_now (vm);
1562 vec_foreach (xd, dm->devices)
1564 timeout = clib_min (timeout, xd->time_last_stats_update +
1565 dm->stat_poll_interval - now);
1566 timeout = clib_min (timeout, xd->time_last_link_update +
1567 dm->link_state_poll_interval - now);
1573 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
1574 .function = dpdk_process,
1575 .type = VLIB_NODE_TYPE_PROCESS,
1576 .name = "dpdk-process",
1577 .process_log2_n_stack_bytes = 17,
1580 static clib_error_t *
1581 dpdk_init (vlib_main_t * vm)
1583 dpdk_main_t *dm = &dpdk_main;
1584 clib_error_t *error = 0;
1586 /* verify that structs are cacheline aligned */
1587 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
1588 "Cache line marker must be 1st element in dpdk_device_t");
1589 STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
1590 CLIB_CACHE_LINE_BYTES,
1591 "Data in cache line 0 is bigger than cache line size");
1592 STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
1593 "Cache line marker must be 1st element in frame_queue_trace_t");
1595 dpdk_cli_reference ();
1597 dm->conf = &dpdk_config_main;
1599 vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet");
1601 dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL;
1602 dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL;
1604 dm->log_default = vlib_log_register_class ("dpdk", 0);
1605 dm->log_cryptodev = vlib_log_register_class ("dpdk", "cryptodev");
1610 VLIB_INIT_FUNCTION (dpdk_init);
1612 static clib_error_t *
1613 dpdk_worker_thread_init (vlib_main_t *vm)
1615 if (rte_thread_register () < 0)
1616 clib_panic ("dpdk: cannot register thread %u - %s", vm->thread_index,
1617 rte_strerror (rte_errno));
1621 VLIB_WORKER_INIT_FUNCTION (dpdk_worker_thread_init);