1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
11 #include <rte_windows.h>
12 #include <ethdev_pci.h>
14 #include <mlx5_glue.h>
15 #include <mlx5_devx_cmds.h>
16 #include <mlx5_common.h>
17 #include <mlx5_common_mp.h>
18 #include <mlx5_common_mr.h>
19 #include <mlx5_malloc.h>
21 #include "mlx5_defs.h"
23 #include "mlx5_common_os.h"
24 #include "mlx5_utils.h"
25 #include "mlx5_rxtx.h"
28 #include "mlx5_autoconf.h"
30 #include "mlx5_flow.h"
31 #include "mlx5_devx.h"
33 static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data";
35 /* Spinlock for mlx5_shared_data allocation. */
36 static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
38 /* rte flow indexed pool configuration. */
39 static struct mlx5_indexed_pool_config icfg[] = {
41 .size = sizeof(struct rte_flow),
45 .malloc = mlx5_malloc,
48 .type = "ctl_flow_ipool",
51 .size = sizeof(struct rte_flow),
57 .malloc = mlx5_malloc,
59 .per_core_cache = 1 << 14,
60 .type = "rte_flow_ipool",
63 .size = sizeof(struct rte_flow),
69 .malloc = mlx5_malloc,
72 .type = "mcp_flow_ipool",
77 * Initialize shared data between primary and secondary process.
79 * A memzone is reserved by primary process and secondary processes attach to
83 * 0 on success, a negative errno value otherwise and rte_errno is set.
86 mlx5_init_shared_data(void)
88 const struct rte_memzone *mz;
91 rte_spinlock_lock(&mlx5_shared_data_lock);
92 if (mlx5_shared_data == NULL) {
93 /* Allocate shared memory. */
94 mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA,
95 sizeof(*mlx5_shared_data),
99 "Cannot allocate mlx5 shared data");
103 mlx5_shared_data = mz->addr;
104 memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data));
105 rte_spinlock_init(&mlx5_shared_data->lock);
108 rte_spinlock_unlock(&mlx5_shared_data_lock);
113 * PMD global initialization.
115 * Independent from individual device, this function initializes global
116 * per-PMD data structures distinguishing primary and secondary processes.
117 * Hence, each initialization is called once per a process.
120 * 0 on success, a negative errno value otherwise and rte_errno is set.
125 if (mlx5_init_shared_data())
131 * Get mlx5 device attributes.
134 * Pointer to device context.
137 * Pointer to mlx5 device attributes.
140 * 0 on success, non zero error number otherwise
143 mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr)
145 struct mlx5_context *mlx5_ctx;
146 struct mlx5_hca_attr hca_attr;
147 void *pv_iseg = NULL;
153 mlx5_ctx = (struct mlx5_context *)ctx;
154 memset(device_attr, 0, sizeof(*device_attr));
155 err = mlx5_devx_cmd_query_hca_attr(mlx5_ctx, &hca_attr);
157 DRV_LOG(ERR, "Failed to get device hca_cap");
160 device_attr->max_cq = 1 << hca_attr.log_max_cq;
161 device_attr->max_qp = 1 << hca_attr.log_max_qp;
162 device_attr->max_qp_wr = 1 << hca_attr.log_max_qp_sz;
163 device_attr->max_cqe = 1 << hca_attr.log_max_cq_sz;
164 device_attr->max_mr = 1 << hca_attr.log_max_mrw_sz;
165 device_attr->max_pd = 1 << hca_attr.log_max_pd;
166 device_attr->max_srq = 1 << hca_attr.log_max_srq;
167 device_attr->max_srq_wr = 1 << hca_attr.log_max_srq_sz;
168 device_attr->max_tso = 1 << hca_attr.max_lso_cap;
169 if (hca_attr.rss_ind_tbl_cap) {
170 device_attr->max_rwq_indirection_table_size =
171 1 << hca_attr.rss_ind_tbl_cap;
173 device_attr->sw_parsing_offloads =
174 mlx5_get_supported_sw_parsing_offloads(&hca_attr);
175 device_attr->tunnel_offloads_caps =
176 mlx5_get_supported_tunneling_offloads(&hca_attr);
177 pv_iseg = mlx5_glue->query_hca_iseg(mlx5_ctx, &cb_iseg);
178 if (pv_iseg == NULL) {
179 DRV_LOG(ERR, "Failed to get device hca_iseg");
183 snprintf(device_attr->fw_ver, 64, "%x.%x.%04x",
184 MLX5_GET(initial_seg, pv_iseg, fw_rev_major),
185 MLX5_GET(initial_seg, pv_iseg, fw_rev_minor),
186 MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor));
192 * Initialize DR related data within private structure.
193 * Routine checks the reference counter and does actual
194 * resources creation/initialization only if counter is zero.
197 * Pointer to the private device data structure.
200 * Zero on success, positive error code otherwise.
203 mlx5_alloc_shared_dr(struct mlx5_priv *priv)
205 struct mlx5_dev_ctx_shared *sh = priv->sh;
209 err = mlx5_alloc_table_hash_list(priv);
211 DRV_LOG(DEBUG, "sh->flow_tbls[%p] already created, reuse",
212 (void *)sh->flow_tbls);
216 * Destroy DR related data within private structure.
219 * Pointer to the private device data structure.
222 mlx5_os_free_shared_dr(struct mlx5_priv *priv)
224 mlx5_free_table_hash_list(priv);
228 * Set the completion channel file descriptor interrupt as non-blocking.
229 * Currently it has no support under Windows.
232 * Pointer to RQ channel object, which includes the channel fd
235 * The file descriptor (representing the intetrrupt) used in this channel.
238 * 0 on successfully setting the fd to non-blocking, non-zero otherwise.
241 mlx5_os_set_nonblock_channel_fd(int fd)
244 DRV_LOG(WARNING, "%s: is not supported", __func__);
249 * Function API open device under Windows
251 * This function calls the Windows glue APIs to open a device.
254 * Pointer to the device attributes (name, port, etc).
256 * Pointer to device configuration structure.
258 * Pointer to shared context structure.
261 * 0 on success, a positive error value otherwise.
264 mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,
265 const struct mlx5_dev_config *config,
266 struct mlx5_dev_ctx_shared *sh)
268 RTE_SET_USED(config);
270 struct mlx5_context *mlx5_ctx;
272 pthread_mutex_init(&sh->txpp.mutex, NULL);
273 /* Set numa node from pci probe */
274 sh->numa_node = spawn->pci_dev->device.numa_node;
276 /* Try to open device with DevX */
278 sh->ctx = mlx5_glue->open_device(spawn->phys_dev);
280 DRV_LOG(ERR, "open_device failed");
285 mlx5_ctx = (struct mlx5_context *)sh->ctx;
286 err = mlx5_glue->query_device(spawn->phys_dev, &mlx5_ctx->mlx5_dev);
288 DRV_LOG(ERR, "Failed to query device context fields.");
293 * DV flow counter mode detect and config.
296 * Pointer to rte_eth_dev structure.
300 mlx5_flow_counter_mode_config(struct rte_eth_dev *dev __rte_unused)
302 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
303 struct mlx5_priv *priv = dev->data->dev_private;
304 struct mlx5_dev_ctx_shared *sh = priv->sh;
307 #ifndef HAVE_IBV_DEVX_ASYNC
311 if (!priv->config.devx || !priv->config.dv_flow_en ||
312 !priv->config.hca_attr.flow_counters_dump ||
313 !(priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4) ||
314 (mlx5_flow_dv_discover_counter_offset_support(dev) == -ENOTSUP))
318 DRV_LOG(INFO, "Use fall-back DV counter management. Flow "
319 "counter dump:%d, bulk_alloc_bitmap:0x%hhx.",
320 priv->config.hca_attr.flow_counters_dump,
321 priv->config.hca_attr.flow_counter_bulk_alloc_bitmap);
322 /* Initialize fallback mode only on the port initializes sh. */
324 sh->cmng.counter_fallback = fallback;
325 else if (fallback != sh->cmng.counter_fallback)
326 DRV_LOG(WARNING, "Port %d in sh has different fallback mode "
327 "with others:%d.", PORT_ID(priv), fallback);
332 * Spawn an Ethernet device from Verbs information.
335 * Backing DPDK device.
337 * Verbs device parameters (name, port, switch_info) to spawn.
339 * Device configuration parameters.
342 * A valid Ethernet device object on success, NULL otherwise and rte_errno
343 * is set. The following errors are defined:
345 * EEXIST: device is already spawned
347 static struct rte_eth_dev *
348 mlx5_dev_spawn(struct rte_device *dpdk_dev,
349 struct mlx5_dev_spawn_data *spawn,
350 struct mlx5_dev_config *config)
352 const struct mlx5_switch_info *switch_info = &spawn->info;
353 struct mlx5_dev_ctx_shared *sh = NULL;
354 struct mlx5_dev_attr device_attr;
355 struct rte_eth_dev *eth_dev = NULL;
356 struct mlx5_priv *priv = NULL;
358 unsigned int cqe_comp;
359 struct rte_ether_addr mac;
360 char name[RTE_ETH_NAME_MAX_LEN];
361 int own_domain_id = 0;
365 /* Build device name. */
366 strlcpy(name, dpdk_dev->name, sizeof(name));
367 /* check if the device is already spawned */
368 if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) {
372 DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name);
374 * Some parameters are needed in advance to create device context. We
375 * process the devargs here to get ones, and later process devargs
376 * again to override some hardware settings.
378 err = mlx5_args(config, dpdk_dev->devargs);
381 DRV_LOG(ERR, "failed to process device arguments: %s",
382 strerror(rte_errno));
385 mlx5_malloc_mem_select(config->sys_mem_en);
386 sh = mlx5_alloc_shared_dev_ctx(spawn, config);
389 config->devx = sh->devx;
390 /* Initialize the shutdown event in mlx5_dev_spawn to
391 * support mlx5_is_removed for Windows.
393 err = mlx5_glue->devx_init_showdown_event(sh->ctx);
395 DRV_LOG(ERR, "failed to init showdown event: %s",
399 DRV_LOG(DEBUG, "MPW isn't supported");
400 mlx5_os_get_dev_attr(sh->ctx, &device_attr);
401 config->swp = device_attr.sw_parsing_offloads &
402 (MLX5_SW_PARSING_CAP | MLX5_SW_PARSING_CSUM_CAP |
403 MLX5_SW_PARSING_TSO_CAP);
404 config->ind_table_max_size =
405 sh->device_attr.max_rwq_indirection_table_size;
407 config->cqe_comp = cqe_comp;
408 config->tunnel_en = device_attr.tunnel_offloads_caps &
409 (MLX5_TUNNELED_OFFLOADS_VXLAN_CAP |
410 MLX5_TUNNELED_OFFLOADS_GRE_CAP |
411 MLX5_TUNNELED_OFFLOADS_GENEVE_CAP);
412 if (config->tunnel_en) {
413 DRV_LOG(DEBUG, "tunnel offloading is supported for %s%s%s",
415 MLX5_TUNNELED_OFFLOADS_VXLAN_CAP ? "[VXLAN]" : "",
417 MLX5_TUNNELED_OFFLOADS_GRE_CAP ? "[GRE]" : "",
419 MLX5_TUNNELED_OFFLOADS_GENEVE_CAP ? "[GENEVE]" : ""
422 DRV_LOG(DEBUG, "tunnel offloading is not supported");
424 DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is no supported");
426 /* Allocate private eth device data. */
427 priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
429 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
431 DRV_LOG(ERR, "priv allocation failure");
436 priv->dev_port = spawn->phys_port;
437 priv->pci_dev = spawn->pci_dev;
438 priv->mtu = RTE_ETHER_MTU;
439 priv->mp_id.port_id = port_id;
440 strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
441 priv->representor = !!switch_info->representor;
442 priv->master = !!switch_info->master;
443 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
444 priv->vport_meta_tag = 0;
445 priv->vport_meta_mask = 0;
446 priv->pf_bond = spawn->pf_bond;
448 /* representor_id field keeps the unmodified VF index. */
449 priv->representor_id = -1;
451 * Look for sibling devices in order to reuse their switch domain
452 * if any, otherwise allocate one.
454 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) {
455 const struct mlx5_priv *opriv =
456 rte_eth_devices[port_id].data->dev_private;
459 opriv->sh != priv->sh ||
461 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
463 priv->domain_id = opriv->domain_id;
466 if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
467 err = rte_eth_switch_domain_alloc(&priv->domain_id);
470 DRV_LOG(ERR, "unable to allocate switch domain: %s",
471 strerror(rte_errno));
476 /* Override some values set by hardware configuration. */
477 mlx5_args(config, dpdk_dev->devargs);
478 err = mlx5_dev_check_sibling_config(priv, config, dpdk_dev);
481 DRV_LOG(DEBUG, "counters are not supported");
482 config->ind_table_max_size =
483 sh->device_attr.max_rwq_indirection_table_size;
485 * Remove this check once DPDK supports larger/variable
486 * indirection tables.
488 if (config->ind_table_max_size > (unsigned int)ETH_RSS_RETA_SIZE_512)
489 config->ind_table_max_size = ETH_RSS_RETA_SIZE_512;
490 DRV_LOG(DEBUG, "maximum Rx indirection table size is %u",
491 config->ind_table_max_size);
492 if (config->hw_padding) {
493 DRV_LOG(DEBUG, "Rx end alignment padding isn't supported");
494 config->hw_padding = 0;
496 config->tso = (sh->device_attr.max_tso > 0);
498 config->tso_max_payload_sz = sh->device_attr.max_tso;
499 DRV_LOG(DEBUG, "%sMPS is %s.",
500 config->mps == MLX5_MPW_ENHANCED ? "enhanced " :
501 config->mps == MLX5_MPW ? "legacy " : "",
502 config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled");
503 if (config->cqe_comp && !cqe_comp) {
504 DRV_LOG(WARNING, "Rx CQE compression isn't supported.");
505 config->cqe_comp = 0;
508 err = mlx5_devx_cmd_query_hca_attr(sh->ctx, &config->hca_attr);
513 /* Check relax ordering support. */
514 sh->cmng.relaxed_ordering_read = 0;
515 sh->cmng.relaxed_ordering_write = 0;
516 if (!haswell_broadwell_cpu) {
517 sh->cmng.relaxed_ordering_write =
518 config->hca_attr.relaxed_ordering_write;
519 sh->cmng.relaxed_ordering_read =
520 config->hca_attr.relaxed_ordering_read;
522 config->hw_csum = config->hca_attr.csum_cap;
523 DRV_LOG(DEBUG, "checksum offloading is %ssupported",
524 (config->hw_csum ? "" : "not "));
525 config->hw_vlan_strip = config->hca_attr.vlan_cap;
526 DRV_LOG(DEBUG, "VLAN stripping is %ssupported",
527 (config->hw_vlan_strip ? "" : "not "));
528 config->hw_fcs_strip = config->hca_attr.scatter_fcs;
531 uint32_t reg[MLX5_ST_SZ_DW(register_mtutc)];
533 err = config->hca_attr.access_register_user ?
534 mlx5_devx_cmd_register_read
535 (sh->ctx, MLX5_REGISTER_ID_MTUTC, 0,
536 reg, MLX5_ST_SZ_DW(register_mtutc)) : ENOTSUP;
540 /* MTUTC register is read successfully. */
541 ts_mode = MLX5_GET(register_mtutc, reg,
543 if (ts_mode == MLX5_MTUTC_TIMESTAMP_MODE_REAL_TIME)
544 config->rt_timestamp = 1;
546 /* Kernel does not support register reading. */
547 if (config->hca_attr.dev_freq_khz ==
548 (NS_PER_S / MS_PER_S))
549 config->rt_timestamp = 1;
551 sh->rq_ts_format = config->hca_attr.rq_ts_format;
552 sh->sq_ts_format = config->hca_attr.sq_ts_format;
553 sh->qp_ts_format = config->hca_attr.qp_ts_format;
555 if (config->mprq.enabled) {
556 DRV_LOG(WARNING, "Multi-Packet RQ isn't supported");
557 config->mprq.enabled = 0;
559 if (config->max_dump_files_num == 0)
560 config->max_dump_files_num = 128;
561 eth_dev = rte_eth_dev_allocate(name);
562 if (eth_dev == NULL) {
563 DRV_LOG(ERR, "can not allocate rte ethdev");
567 if (priv->representor) {
568 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
569 eth_dev->data->representor_id = priv->representor_id;
570 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) {
571 struct mlx5_priv *opriv =
572 rte_eth_devices[port_id].data->dev_private;
575 opriv->domain_id == priv->domain_id &&
576 opriv->sh == priv->sh) {
577 eth_dev->data->backer_port_id = port_id;
581 if (port_id >= RTE_MAX_ETHPORTS)
582 eth_dev->data->backer_port_id = eth_dev->data->port_id;
585 * Store associated network device interface index. This index
586 * is permanent throughout the lifetime of device. So, we may store
587 * the ifindex here and use the cached value further.
589 MLX5_ASSERT(spawn->ifindex);
590 priv->if_index = spawn->ifindex;
591 eth_dev->data->dev_private = priv;
592 priv->dev_data = eth_dev->data;
593 eth_dev->data->mac_addrs = priv->mac;
594 eth_dev->device = dpdk_dev;
595 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
596 /* Configure the first MAC address by default. */
597 if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
599 "port %u cannot get MAC address, is mlx5_en"
600 " loaded? (errno: %s).",
601 eth_dev->data->port_id, strerror(rte_errno));
606 "port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT,
607 eth_dev->data->port_id, RTE_ETHER_ADDR_BYTES(&mac));
608 #ifdef RTE_LIBRTE_MLX5_DEBUG
610 char ifname[MLX5_NAMESIZE];
612 if (mlx5_get_ifname(eth_dev, &ifname) == 0)
613 DRV_LOG(DEBUG, "port %u ifname is \"%s\"",
614 eth_dev->data->port_id, ifname);
616 DRV_LOG(DEBUG, "port %u ifname is unknown.",
617 eth_dev->data->port_id);
620 /* Get actual MTU if possible. */
621 err = mlx5_get_mtu(eth_dev, &priv->mtu);
626 DRV_LOG(DEBUG, "port %u MTU is %u.", eth_dev->data->port_id,
628 /* Initialize burst functions to prevent crashes before link-up. */
629 eth_dev->rx_pkt_burst = removed_rx_burst;
630 eth_dev->tx_pkt_burst = removed_tx_burst;
631 eth_dev->dev_ops = &mlx5_dev_ops;
632 eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
633 eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
634 eth_dev->rx_queue_count = mlx5_rx_queue_count;
635 /* Register MAC address. */
636 claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0));
637 priv->ctrl_flows = 0;
638 TAILQ_INIT(&priv->flow_meters);
639 priv->mtr_profile_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_PTR);
640 if (!priv->mtr_profile_tbl)
642 /* Bring Ethernet device up. */
643 DRV_LOG(DEBUG, "port %u forcing Ethernet interface up.",
644 eth_dev->data->port_id);
645 /* nl calls are unsupported - set to -1 not to fail on release */
646 priv->nl_socket_rdma = -1;
647 priv->nl_socket_route = -1;
648 mlx5_set_link_up(eth_dev);
650 * Even though the interrupt handler is not installed yet,
651 * interrupts will still trigger on the async_fd from
652 * Verbs context returned by ibv_open_device().
654 mlx5_link_update(eth_dev, 0);
655 config->dv_esw_en = 0;
656 /* Detect minimal data bytes to inline. */
657 mlx5_set_min_inline(spawn, config);
658 /* Store device configuration on private structure. */
659 priv->config = *config;
660 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
661 icfg[i].release_mem_en = !!config->reclaim_mode;
662 if (config->reclaim_mode)
663 icfg[i].per_core_cache = 0;
664 priv->flows[i] = mlx5_ipool_create(&icfg[i]);
668 /* Create context for virtual machine VLAN workaround. */
669 priv->vmwa_context = NULL;
670 if (config->dv_flow_en) {
671 err = mlx5_alloc_shared_dr(priv);
675 /* No supported flow priority number detection. */
676 priv->config.flow_prio = -1;
677 if (!priv->config.dv_esw_en &&
678 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
679 DRV_LOG(WARNING, "metadata mode %u is not supported "
680 "(no E-Switch)", priv->config.dv_xmeta_en);
681 priv->config.dv_xmeta_en = MLX5_XMETA_MODE_LEGACY;
683 mlx5_set_metadata_mask(eth_dev);
684 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
685 !priv->sh->dv_regc0_mask) {
686 DRV_LOG(ERR, "metadata mode %u is not supported "
687 "(no metadata reg_c[0] is available).",
688 priv->config.dv_xmeta_en);
692 priv->hrxqs = mlx5_list_create("hrxq", eth_dev, true,
693 mlx5_hrxq_create_cb, mlx5_hrxq_match_cb,
694 mlx5_hrxq_remove_cb, mlx5_hrxq_clone_cb,
695 mlx5_hrxq_clone_free_cb);
696 /* Query availability of metadata reg_c's. */
697 err = mlx5_flow_discover_mreg_c(eth_dev);
702 if (!mlx5_flow_ext_mreg_supported(eth_dev)) {
704 "port %u extensive metadata register is not supported.",
705 eth_dev->data->port_id);
706 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
707 DRV_LOG(ERR, "metadata mode %u is not supported "
708 "(no metadata registers available).",
709 priv->config.dv_xmeta_en);
714 if (config->devx && config->dv_flow_en) {
715 priv->obj_ops = devx_obj_ops;
717 DRV_LOG(ERR, "Flow mode %u is not supported "
718 "(Windows flow must be DevX with DV flow enabled).",
719 priv->config.dv_flow_en);
723 mlx5_flow_counter_mode_config(eth_dev);
727 if (priv->mtr_profile_tbl)
728 mlx5_l3t_destroy(priv->mtr_profile_tbl);
730 claim_zero(rte_eth_switch_domain_free(priv->domain_id));
733 eth_dev->data->dev_private = NULL;
735 if (eth_dev != NULL) {
736 /* mac_addrs must not be freed alone because part of
739 eth_dev->data->mac_addrs = NULL;
740 rte_eth_dev_release_port(eth_dev);
743 mlx5_free_shared_dev_ctx(sh);
744 MLX5_ASSERT(err > 0);
750 * This function should share events between multiple ports of single IB
751 * device. Currently it has no support under Windows.
754 * Pointer to mlx5_dev_ctx_shared object.
757 mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
760 DRV_LOG(WARNING, "%s: is not supported", __func__);
764 * This function should share events between multiple ports of single IB
765 * device. Currently it has no support under Windows.
768 * Pointer to mlx5_dev_ctx_shared object.
771 mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)
774 DRV_LOG(WARNING, "%s: is not supported", __func__);
778 * Read statistics by a named counter.
781 * Pointer to the private device data structure.
782 * @param[in] ctr_name
783 * Pointer to the name of the statistic counter to read
785 * Pointer to read statistic value.
787 * 0 on success and stat is valud, 1 if failed to read the value
792 mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name,
796 RTE_SET_USED(ctr_name);
798 DRV_LOG(WARNING, "%s: is not supported", __func__);
803 * Flush device MAC addresses
804 * Currently it has no support under Windows.
807 * Pointer to Ethernet device structure.
811 mlx5_os_mac_addr_flush(struct rte_eth_dev *dev)
814 DRV_LOG(WARNING, "%s: is not supported", __func__);
818 * Remove a MAC address from device
819 * Currently it has no support under Windows.
822 * Pointer to Ethernet device structure.
827 mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
831 DRV_LOG(WARNING, "%s: is not supported", __func__);
835 * Adds a MAC address to the device
836 * Currently it has no support under Windows.
839 * Pointer to Ethernet device structure.
841 * MAC address to register.
846 * 0 on success, a negative errno value otherwise
849 mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
853 struct rte_ether_addr lmac;
855 if (mlx5_get_mac(dev, &lmac.addr_bytes)) {
857 "port %u cannot get MAC address, is mlx5_en"
858 " loaded? (errno: %s)",
859 dev->data->port_id, strerror(rte_errno));
862 if (!rte_is_same_ether_addr(&lmac, mac)) {
864 "adding new mac address to device is unsupported");
871 * Modify a VF MAC address
872 * Currently it has no support under Windows.
875 * Pointer to device private data.
877 * MAC address to modify into.
879 * Net device interface index
884 * 0 on success, a negative errno value otherwise
887 mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv,
888 unsigned int iface_idx,
889 struct rte_ether_addr *mac_addr,
896 DRV_LOG(WARNING, "%s: is not supported", __func__);
901 * Set device promiscuous mode
902 * Currently it has no support under Windows.
905 * Pointer to Ethernet device structure.
907 * 0 - promiscuous is disabled, otherwise - enabled
910 * 0 on success, a negative error value otherwise
913 mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable)
917 DRV_LOG(WARNING, "%s: is not supported", __func__);
922 * Set device allmulti mode
925 * Pointer to Ethernet device structure.
927 * 0 - all multicase is disabled, otherwise - enabled
930 * 0 on success, a negative error value otherwise
933 mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable)
937 DRV_LOG(WARNING, "%s: is not supported", __func__);
942 * Detect if a devx_device_bdf object has identical DBDF values to the
943 * rte_pci_addr found in bus/pci probing
945 * @param[in] devx_bdf
946 * Pointer to the devx_device_bdf structure.
948 * Pointer to the rte_pci_addr structure.
951 * 1 on Device match, 0 on mismatch.
954 mlx5_match_devx_bdf_to_addr(struct devx_device_bdf *devx_bdf,
955 struct rte_pci_addr *addr)
957 if (addr->domain != (devx_bdf->bus_id >> 8) ||
958 addr->bus != (devx_bdf->bus_id & 0xff) ||
959 addr->devid != devx_bdf->dev_id ||
960 addr->function != devx_bdf->fnc_id) {
967 * Detect if a devx_device_bdf object matches the rte_pci_addr
968 * found in bus/pci probing
969 * Compare both the Native/PF BDF and the raw_bdf representing a VF BDF.
971 * @param[in] devx_bdf
972 * Pointer to the devx_device_bdf structure.
974 * Pointer to the rte_pci_addr structure.
977 * 1 on Device match, 0 on mismatch, rte_errno code on failure.
980 mlx5_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
981 struct rte_pci_addr *addr)
984 struct devx_device mlx5_dev;
986 if (mlx5_match_devx_bdf_to_addr(devx_bdf, addr))
989 * Didn't match on Native/PF BDF, could still
990 * Match a VF BDF, check it next
992 err = mlx5_glue->query_device(devx_bdf, &mlx5_dev);
994 DRV_LOG(ERR, "query_device failed");
998 if (mlx5_match_devx_bdf_to_addr(&mlx5_dev.raw_bdf, addr))
1004 * DPDK callback to register a PCI device.
1006 * This function spawns Ethernet devices out of a given device.
1009 * Pointer to the generic device.
1012 * 0 on success, a negative errno value otherwise and rte_errno is set.
1015 mlx5_os_net_probe(struct rte_device *dev)
1017 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
1018 struct devx_device_bdf *devx_bdf_devs, *orig_devx_bdf_devs;
1020 * Number of found IB Devices matching with requested PCI BDF.
1021 * nd != 1 means there are multiple IB devices over the same
1022 * PCI device and we have representors and master.
1024 unsigned int nd = 0;
1026 * Number of found IB device Ports. nd = 1 and np = 1..n means
1027 * we have the single multiport IB device, and there may be
1028 * representors attached to some of found ports.
1029 * Currently not supported.
1030 * unsigned int np = 0;
1034 * Number of DPDK ethernet devices to Spawn - either over
1035 * multiple IB devices or multiple ports of single IB device.
1036 * Actually this is the number of iterations to spawn.
1038 unsigned int ns = 0;
1041 * < 0 - no bonding device (single one)
1042 * >= 0 - bonding device (value is slave PF index)
1045 struct mlx5_dev_spawn_data *list = NULL;
1046 struct mlx5_dev_config dev_config;
1047 unsigned int dev_config_vf;
1051 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1052 DRV_LOG(ERR, "Secondary process is not supported on Windows.");
1055 ret = mlx5_init_once();
1057 DRV_LOG(ERR, "unable to init PMD global data: %s",
1058 strerror(rte_errno));
1062 devx_bdf_devs = mlx5_glue->get_device_list(&ret);
1063 orig_devx_bdf_devs = devx_bdf_devs;
1064 if (!devx_bdf_devs) {
1065 rte_errno = errno ? errno : ENOSYS;
1066 DRV_LOG(ERR, "cannot list devices, is ib_uverbs loaded?");
1070 * First scan the list of all Infiniband devices to find
1071 * matching ones, gathering into the list.
1073 struct devx_device_bdf *devx_bdf_match[ret + 1];
1076 err = mlx5_match_devx_devices_to_addr(devx_bdf_devs,
1086 devx_bdf_match[nd++] = devx_bdf_devs;
1088 devx_bdf_match[nd] = NULL;
1090 /* No device matches, just complain and bail out. */
1092 "no DevX device matches PCI device " PCI_PRI_FMT ","
1093 " is DevX Configured?",
1094 pci_dev->addr.domain, pci_dev->addr.bus,
1095 pci_dev->addr.devid, pci_dev->addr.function);
1101 * Now we can determine the maximal
1102 * amount of devices to be spawned.
1104 list = mlx5_malloc(MLX5_MEM_ZERO,
1105 sizeof(struct mlx5_dev_spawn_data),
1106 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1108 DRV_LOG(ERR, "spawn data array allocation failure");
1113 memset(&list[ns].info, 0, sizeof(list[ns].info));
1114 list[ns].max_port = 1;
1115 list[ns].phys_port = 1;
1116 list[ns].phys_dev = devx_bdf_match[ns];
1117 list[ns].eth_dev = NULL;
1118 list[ns].pci_dev = pci_dev;
1119 list[ns].pf_bond = bd;
1120 list[ns].ifindex = -1; /* Spawn will assign */
1122 (struct mlx5_switch_info){
1125 .name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK,
1129 /* Device specific configuration. */
1130 switch (pci_dev->id.device_id) {
1131 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
1132 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
1133 case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
1134 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
1135 case PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF:
1136 case PCI_DEVICE_ID_MELLANOX_CONNECTX6VF:
1137 case PCI_DEVICE_ID_MELLANOX_CONNECTXVF:
1144 /* Default configuration. */
1145 memset(&dev_config, 0, sizeof(struct mlx5_dev_config));
1146 dev_config.vf = dev_config_vf;
1148 dev_config.dbnc = MLX5_ARG_UNSET;
1149 dev_config.rx_vec_en = 1;
1150 dev_config.txq_inline_max = MLX5_ARG_UNSET;
1151 dev_config.txq_inline_min = MLX5_ARG_UNSET;
1152 dev_config.txq_inline_mpw = MLX5_ARG_UNSET;
1153 dev_config.txqs_inline = MLX5_ARG_UNSET;
1154 dev_config.vf_nl_en = 0;
1155 dev_config.mr_ext_memseg_en = 1;
1156 dev_config.mr_mempool_reg_en = 1;
1157 dev_config.mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN;
1158 dev_config.mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS;
1159 dev_config.dv_esw_en = 0;
1160 dev_config.dv_flow_en = 1;
1161 dev_config.decap_en = 0;
1162 dev_config.log_hp_size = MLX5_ARG_UNSET;
1163 list[ns].numa_node = pci_dev->device.numa_node;
1164 list[ns].eth_dev = mlx5_dev_spawn(&pci_dev->device,
1167 if (!list[ns].eth_dev)
1169 restore = list[ns].eth_dev->data->dev_flags;
1170 rte_eth_copy_pci_info(list[ns].eth_dev, pci_dev);
1171 /* Restore non-PCI flags cleared by the above call. */
1172 list[ns].eth_dev->data->dev_flags |= restore;
1173 rte_eth_dev_probing_finish(list[ns].eth_dev);
1177 * Do the routine cleanup:
1178 * - free allocated spawn data array
1179 * - free the device list
1183 MLX5_ASSERT(orig_devx_bdf_devs);
1184 mlx5_glue->free_device_list(orig_devx_bdf_devs);
1189 * Set the reg_mr and dereg_mr call backs
1191 * @param reg_mr_cb[out]
1192 * Pointer to reg_mr func
1193 * @param dereg_mr_cb[out]
1194 * Pointer to dereg_mr func
1198 mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
1199 mlx5_dereg_mr_t *dereg_mr_cb)
1201 *reg_mr_cb = mlx5_os_reg_mr;
1202 *dereg_mr_cb = mlx5_os_dereg_mr;
1206 * Extract pdn of PD object using DevX
1209 * Pointer to the DevX PD object.
1211 * Pointer to the PD object number variable.
1214 * 0 on success, error value otherwise.
1217 mlx5_os_get_pdn(void *pd, uint32_t *pdn)
1222 *pdn = ((struct mlx5_pd *)pd)->pdn;
1226 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {0};