1f44b09f9SOphir Munk /* SPDX-License-Identifier: BSD-3-Clause 2f44b09f9SOphir Munk * Copyright 2015 6WIND S.A. 3f44b09f9SOphir Munk * Copyright 2020 Mellanox Technologies, Ltd 4f44b09f9SOphir Munk */ 5f44b09f9SOphir Munk 6f44b09f9SOphir Munk #include <stddef.h> 7f44b09f9SOphir Munk #include <unistd.h> 8f44b09f9SOphir Munk #include <string.h> 9f44b09f9SOphir Munk #include <stdint.h> 10f44b09f9SOphir Munk #include <stdlib.h> 11f44b09f9SOphir Munk #include <errno.h> 12f44b09f9SOphir Munk #include <net/if.h> 13f44b09f9SOphir Munk #include <linux/rtnetlink.h> 1473bf9235SOphir Munk #include <linux/sockios.h> 1573bf9235SOphir Munk #include <linux/ethtool.h> 16f44b09f9SOphir Munk #include <fcntl.h> 17f44b09f9SOphir Munk 18f44b09f9SOphir Munk #include <rte_malloc.h> 19df96fd0dSBruce Richardson #include <ethdev_driver.h> 20df96fd0dSBruce Richardson #include <ethdev_pci.h> 21f44b09f9SOphir Munk #include <rte_pci.h> 22f44b09f9SOphir Munk #include <rte_bus_pci.h> 23f44b09f9SOphir Munk #include <rte_common.h> 24f44b09f9SOphir Munk #include <rte_kvargs.h> 25f44b09f9SOphir Munk #include <rte_rwlock.h> 26f44b09f9SOphir Munk #include <rte_spinlock.h> 27f44b09f9SOphir Munk #include <rte_string_fns.h> 28f44b09f9SOphir Munk #include <rte_alarm.h> 292aba9fc7SOphir Munk #include <rte_eal_paging.h> 30f44b09f9SOphir Munk 31f44b09f9SOphir Munk #include <mlx5_glue.h> 32f44b09f9SOphir Munk #include <mlx5_devx_cmds.h> 33f44b09f9SOphir Munk #include <mlx5_common.h> 342eb4d010SOphir Munk #include <mlx5_common_mp.h> 35d5ed8aa9SOphir Munk #include <mlx5_common_mr.h> 365522da6bSSuanming Mou #include <mlx5_malloc.h> 37f44b09f9SOphir Munk 38f44b09f9SOphir Munk #include "mlx5_defs.h" 39f44b09f9SOphir Munk #include "mlx5.h" 40391b8bccSOphir Munk #include "mlx5_common_os.h" 41f44b09f9SOphir Munk #include "mlx5_utils.h" 42f44b09f9SOphir Munk #include "mlx5_rxtx.h" 43f44b09f9SOphir Munk #include "mlx5_autoconf.h" 44f44b09f9SOphir Munk #include "mlx5_mr.h" 45f44b09f9SOphir Munk #include "mlx5_flow.h" 46f44b09f9SOphir Munk #include "rte_pmd_mlx5.h" 474f96d913SOphir Munk #include "mlx5_verbs.h" 48f00f6562SOphir Munk #include "mlx5_nl.h" 496deb19e1SMichael Baum #include "mlx5_devx.h" 50f44b09f9SOphir Munk 512eb4d010SOphir Munk #define MLX5_TAGS_HLIST_ARRAY_SIZE 8192 522eb4d010SOphir Munk 532eb4d010SOphir Munk #ifndef HAVE_IBV_MLX5_MOD_MPW 542eb4d010SOphir Munk #define MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED (1 << 2) 552eb4d010SOphir Munk #define MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW (1 << 3) 562eb4d010SOphir Munk #endif 572eb4d010SOphir Munk 582eb4d010SOphir Munk #ifndef HAVE_IBV_MLX5_MOD_CQE_128B_COMP 592eb4d010SOphir Munk #define MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP (1 << 4) 602eb4d010SOphir Munk #endif 612eb4d010SOphir Munk 622e86c4e5SOphir Munk static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data"; 632e86c4e5SOphir Munk 642e86c4e5SOphir Munk /* Spinlock for mlx5_shared_data allocation. */ 652e86c4e5SOphir Munk static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER; 662e86c4e5SOphir Munk 672e86c4e5SOphir Munk /* Process local data for secondary processes. */ 682e86c4e5SOphir Munk static struct mlx5_local_data mlx5_local_data; 692e86c4e5SOphir Munk 70f44b09f9SOphir Munk /** 7108d1838fSDekel Peled * Set the completion channel file descriptor interrupt as non-blocking. 7208d1838fSDekel Peled * 7308d1838fSDekel Peled * @param[in] rxq_obj 7408d1838fSDekel Peled * Pointer to RQ channel object, which includes the channel fd 7508d1838fSDekel Peled * 7608d1838fSDekel Peled * @param[out] fd 7708d1838fSDekel Peled * The file descriptor (representing the intetrrupt) used in this channel. 7808d1838fSDekel Peled * 7908d1838fSDekel Peled * @return 8008d1838fSDekel Peled * 0 on successfully setting the fd to non-blocking, non-zero otherwise. 8108d1838fSDekel Peled */ 8208d1838fSDekel Peled int 8308d1838fSDekel Peled mlx5_os_set_nonblock_channel_fd(int fd) 8408d1838fSDekel Peled { 8508d1838fSDekel Peled int flags; 8608d1838fSDekel Peled 8708d1838fSDekel Peled flags = fcntl(fd, F_GETFL); 8808d1838fSDekel Peled return fcntl(fd, F_SETFL, flags | O_NONBLOCK); 8908d1838fSDekel Peled } 9008d1838fSDekel Peled 9108d1838fSDekel Peled /** 92e85f623eSOphir Munk * Get mlx5 device attributes. The glue function query_device_ex() is called 93e85f623eSOphir Munk * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5 94e85f623eSOphir Munk * device attributes from the glue out parameter. 95e85f623eSOphir Munk * 96e85f623eSOphir Munk * @param dev 97e85f623eSOphir Munk * Pointer to ibv context. 98e85f623eSOphir Munk * 99e85f623eSOphir Munk * @param device_attr 100e85f623eSOphir Munk * Pointer to mlx5 device attributes. 101e85f623eSOphir Munk * 102e85f623eSOphir Munk * @return 103e85f623eSOphir Munk * 0 on success, non zero error number otherwise 104e85f623eSOphir Munk */ 105e85f623eSOphir Munk int 106e85f623eSOphir Munk mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr) 107e85f623eSOphir Munk { 108e85f623eSOphir Munk int err; 109e85f623eSOphir Munk struct ibv_device_attr_ex attr_ex; 110e85f623eSOphir Munk memset(device_attr, 0, sizeof(*device_attr)); 111e85f623eSOphir Munk err = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex); 112e85f623eSOphir Munk if (err) 113e85f623eSOphir Munk return err; 114e85f623eSOphir Munk 115e85f623eSOphir Munk device_attr->device_cap_flags_ex = attr_ex.device_cap_flags_ex; 116e85f623eSOphir Munk device_attr->max_qp_wr = attr_ex.orig_attr.max_qp_wr; 117e85f623eSOphir Munk device_attr->max_sge = attr_ex.orig_attr.max_sge; 118e85f623eSOphir Munk device_attr->max_cq = attr_ex.orig_attr.max_cq; 1191f29d15eSOphir Munk device_attr->max_cqe = attr_ex.orig_attr.max_cqe; 1201f29d15eSOphir Munk device_attr->max_mr = attr_ex.orig_attr.max_mr; 1211f29d15eSOphir Munk device_attr->max_pd = attr_ex.orig_attr.max_pd; 122e85f623eSOphir Munk device_attr->max_qp = attr_ex.orig_attr.max_qp; 1231f29d15eSOphir Munk device_attr->max_srq = attr_ex.orig_attr.max_srq; 1241f29d15eSOphir Munk device_attr->max_srq_wr = attr_ex.orig_attr.max_srq_wr; 125e85f623eSOphir Munk device_attr->raw_packet_caps = attr_ex.raw_packet_caps; 126e85f623eSOphir Munk device_attr->max_rwq_indirection_table_size = 127e85f623eSOphir Munk attr_ex.rss_caps.max_rwq_indirection_table_size; 128e85f623eSOphir Munk device_attr->max_tso = attr_ex.tso_caps.max_tso; 129e85f623eSOphir Munk device_attr->tso_supported_qpts = attr_ex.tso_caps.supported_qpts; 130e85f623eSOphir Munk 131e85f623eSOphir Munk struct mlx5dv_context dv_attr = { .comp_mask = 0 }; 132e85f623eSOphir Munk err = mlx5_glue->dv_query_device(ctx, &dv_attr); 133e85f623eSOphir Munk if (err) 134e85f623eSOphir Munk return err; 135e85f623eSOphir Munk 136e85f623eSOphir Munk device_attr->flags = dv_attr.flags; 137e85f623eSOphir Munk device_attr->comp_mask = dv_attr.comp_mask; 138e85f623eSOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 139e85f623eSOphir Munk device_attr->sw_parsing_offloads = 140e85f623eSOphir Munk dv_attr.sw_parsing_caps.sw_parsing_offloads; 141e85f623eSOphir Munk #endif 142e85f623eSOphir Munk device_attr->min_single_stride_log_num_of_bytes = 143e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_stride_log_num_of_bytes; 144e85f623eSOphir Munk device_attr->max_single_stride_log_num_of_bytes = 145e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_stride_log_num_of_bytes; 146e85f623eSOphir Munk device_attr->min_single_wqe_log_num_of_strides = 147e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_wqe_log_num_of_strides; 148e85f623eSOphir Munk device_attr->max_single_wqe_log_num_of_strides = 149e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_wqe_log_num_of_strides; 150e85f623eSOphir Munk device_attr->stride_supported_qpts = 151e85f623eSOphir Munk dv_attr.striding_rq_caps.supported_qpts; 152e85f623eSOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 153e85f623eSOphir Munk device_attr->tunnel_offloads_caps = dv_attr.tunnel_offloads_caps; 154e85f623eSOphir Munk #endif 155e85f623eSOphir Munk 156e85f623eSOphir Munk return err; 157e85f623eSOphir Munk } 1582eb4d010SOphir Munk 1592eb4d010SOphir Munk /** 1602eb4d010SOphir Munk * Verbs callback to allocate a memory. This function should allocate the space 1612eb4d010SOphir Munk * according to the size provided residing inside a huge page. 1622eb4d010SOphir Munk * Please note that all allocation must respect the alignment from libmlx5 1632aba9fc7SOphir Munk * (i.e. currently rte_mem_page_size()). 1642eb4d010SOphir Munk * 1652eb4d010SOphir Munk * @param[in] size 1662eb4d010SOphir Munk * The size in bytes of the memory to allocate. 1672eb4d010SOphir Munk * @param[in] data 1682eb4d010SOphir Munk * A pointer to the callback data. 1692eb4d010SOphir Munk * 1702eb4d010SOphir Munk * @return 1712eb4d010SOphir Munk * Allocated buffer, NULL otherwise and rte_errno is set. 1722eb4d010SOphir Munk */ 1732eb4d010SOphir Munk static void * 1742eb4d010SOphir Munk mlx5_alloc_verbs_buf(size_t size, void *data) 1752eb4d010SOphir Munk { 17681c3b977SViacheslav Ovsiienko struct mlx5_dev_ctx_shared *sh = data; 1772eb4d010SOphir Munk void *ret; 1782aba9fc7SOphir Munk size_t alignment = rte_mem_page_size(); 1792aba9fc7SOphir Munk if (alignment == (size_t)-1) { 1802aba9fc7SOphir Munk DRV_LOG(ERR, "Failed to get mem page size"); 1812aba9fc7SOphir Munk rte_errno = ENOMEM; 1822aba9fc7SOphir Munk return NULL; 1832aba9fc7SOphir Munk } 1842eb4d010SOphir Munk 1852eb4d010SOphir Munk MLX5_ASSERT(data != NULL); 18681c3b977SViacheslav Ovsiienko ret = mlx5_malloc(0, size, alignment, sh->numa_node); 1872eb4d010SOphir Munk if (!ret && size) 1882eb4d010SOphir Munk rte_errno = ENOMEM; 1892eb4d010SOphir Munk return ret; 1902eb4d010SOphir Munk } 1912eb4d010SOphir Munk 1922eb4d010SOphir Munk /** 1932eb4d010SOphir Munk * Verbs callback to free a memory. 1942eb4d010SOphir Munk * 1952eb4d010SOphir Munk * @param[in] ptr 1962eb4d010SOphir Munk * A pointer to the memory to free. 1972eb4d010SOphir Munk * @param[in] data 1982eb4d010SOphir Munk * A pointer to the callback data. 1992eb4d010SOphir Munk */ 2002eb4d010SOphir Munk static void 2012eb4d010SOphir Munk mlx5_free_verbs_buf(void *ptr, void *data __rte_unused) 2022eb4d010SOphir Munk { 2032eb4d010SOphir Munk MLX5_ASSERT(data != NULL); 2042175c4dcSSuanming Mou mlx5_free(ptr); 2052eb4d010SOphir Munk } 2062eb4d010SOphir Munk 2072eb4d010SOphir Munk /** 2082eb4d010SOphir Munk * Initialize DR related data within private structure. 2092eb4d010SOphir Munk * Routine checks the reference counter and does actual 2102eb4d010SOphir Munk * resources creation/initialization only if counter is zero. 2112eb4d010SOphir Munk * 2122eb4d010SOphir Munk * @param[in] priv 2132eb4d010SOphir Munk * Pointer to the private device data structure. 2142eb4d010SOphir Munk * 2152eb4d010SOphir Munk * @return 2162eb4d010SOphir Munk * Zero on success, positive error code otherwise. 2172eb4d010SOphir Munk */ 2182eb4d010SOphir Munk static int 2192eb4d010SOphir Munk mlx5_alloc_shared_dr(struct mlx5_priv *priv) 2202eb4d010SOphir Munk { 2212eb4d010SOphir Munk struct mlx5_dev_ctx_shared *sh = priv->sh; 222291140c6SSuanming Mou char s[MLX5_HLIST_NAMESIZE] __rte_unused; 22316dbba25SXueming Li int err; 2242eb4d010SOphir Munk 22516dbba25SXueming Li MLX5_ASSERT(sh && sh->refcnt); 22616dbba25SXueming Li if (sh->refcnt > 1) 22716dbba25SXueming Li return 0; 2282eb4d010SOphir Munk err = mlx5_alloc_table_hash_list(priv); 2292eb4d010SOphir Munk if (err) 230291140c6SSuanming Mou goto error; 231291140c6SSuanming Mou /* The resources below are only valid with DV support. */ 232291140c6SSuanming Mou #ifdef HAVE_IBV_FLOW_DV_SUPPORT 2330fd5f82aSXueming Li /* Init port id action cache list. */ 2340fd5f82aSXueming Li snprintf(s, sizeof(s), "%s_port_id_action_cache", sh->ibdev_name); 2350fd5f82aSXueming Li mlx5_cache_list_init(&sh->port_id_action_list, s, 0, sh, 2360fd5f82aSXueming Li flow_dv_port_id_create_cb, 2370fd5f82aSXueming Li flow_dv_port_id_match_cb, 2380fd5f82aSXueming Li flow_dv_port_id_remove_cb); 2393422af2aSXueming Li /* Init push vlan action cache list. */ 2403422af2aSXueming Li snprintf(s, sizeof(s), "%s_push_vlan_action_cache", sh->ibdev_name); 2413422af2aSXueming Li mlx5_cache_list_init(&sh->push_vlan_action_list, s, 0, sh, 2423422af2aSXueming Li flow_dv_push_vlan_create_cb, 2433422af2aSXueming Li flow_dv_push_vlan_match_cb, 2443422af2aSXueming Li flow_dv_push_vlan_remove_cb); 24519784141SSuanming Mou /* Init sample action cache list. */ 24619784141SSuanming Mou snprintf(s, sizeof(s), "%s_sample_action_cache", sh->ibdev_name); 24701c05ee0SSuanming Mou mlx5_cache_list_init(&sh->sample_action_list, s, 0, sh, 24819784141SSuanming Mou flow_dv_sample_create_cb, 24919784141SSuanming Mou flow_dv_sample_match_cb, 25019784141SSuanming Mou flow_dv_sample_remove_cb); 25119784141SSuanming Mou /* Init dest array action cache list. */ 25219784141SSuanming Mou snprintf(s, sizeof(s), "%s_dest_array_cache", sh->ibdev_name); 25301c05ee0SSuanming Mou mlx5_cache_list_init(&sh->dest_array_list, s, 0, sh, 25419784141SSuanming Mou flow_dv_dest_array_create_cb, 25519784141SSuanming Mou flow_dv_dest_array_match_cb, 25619784141SSuanming Mou flow_dv_dest_array_remove_cb); 2572eb4d010SOphir Munk /* Create tags hash list table. */ 2582eb4d010SOphir Munk snprintf(s, sizeof(s), "%s_tags", sh->ibdev_name); 259e69a5922SXueming Li sh->tag_table = mlx5_hlist_create(s, MLX5_TAGS_HLIST_ARRAY_SIZE, 0, 260fe3f8c52SXueming Li MLX5_HLIST_WRITE_MOST, 261f5b0aed2SSuanming Mou flow_dv_tag_create_cb, 262f5b0aed2SSuanming Mou flow_dv_tag_match_cb, 263fe3f8c52SXueming Li flow_dv_tag_remove_cb); 2642eb4d010SOphir Munk if (!sh->tag_table) { 26563783b01SDavid Marchand DRV_LOG(ERR, "tags with hash creation failed."); 2662eb4d010SOphir Munk err = ENOMEM; 2672eb4d010SOphir Munk goto error; 2682eb4d010SOphir Munk } 269fe3f8c52SXueming Li sh->tag_table->ctx = sh; 2703fe88961SSuanming Mou snprintf(s, sizeof(s), "%s_hdr_modify", sh->ibdev_name); 271e69a5922SXueming Li sh->modify_cmds = mlx5_hlist_create(s, MLX5_FLOW_HDR_MODIFY_HTABLE_SZ, 27216a7dbc4SXueming Li 0, MLX5_HLIST_WRITE_MOST | 27316a7dbc4SXueming Li MLX5_HLIST_DIRECT_KEY, 27416a7dbc4SXueming Li flow_dv_modify_create_cb, 27516a7dbc4SXueming Li flow_dv_modify_match_cb, 27616a7dbc4SXueming Li flow_dv_modify_remove_cb); 2773fe88961SSuanming Mou if (!sh->modify_cmds) { 2783fe88961SSuanming Mou DRV_LOG(ERR, "hdr modify hash creation failed"); 2793fe88961SSuanming Mou err = ENOMEM; 2803fe88961SSuanming Mou goto error; 2813fe88961SSuanming Mou } 28216a7dbc4SXueming Li sh->modify_cmds->ctx = sh; 283bf615b07SSuanming Mou snprintf(s, sizeof(s), "%s_encaps_decaps", sh->ibdev_name); 284bf615b07SSuanming Mou sh->encaps_decaps = mlx5_hlist_create(s, 285e69a5922SXueming Li MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ, 286f961fd49SSuanming Mou 0, MLX5_HLIST_DIRECT_KEY | 287f961fd49SSuanming Mou MLX5_HLIST_WRITE_MOST, 288f961fd49SSuanming Mou flow_dv_encap_decap_create_cb, 289f961fd49SSuanming Mou flow_dv_encap_decap_match_cb, 290f961fd49SSuanming Mou flow_dv_encap_decap_remove_cb); 291bf615b07SSuanming Mou if (!sh->encaps_decaps) { 292bf615b07SSuanming Mou DRV_LOG(ERR, "encap decap hash creation failed"); 293bf615b07SSuanming Mou err = ENOMEM; 294bf615b07SSuanming Mou goto error; 295bf615b07SSuanming Mou } 296f961fd49SSuanming Mou sh->encaps_decaps->ctx = sh; 297291140c6SSuanming Mou #endif 2982eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR 2992eb4d010SOphir Munk void *domain; 3002eb4d010SOphir Munk 3012eb4d010SOphir Munk /* Reference counter is zero, we should initialize structures. */ 3022eb4d010SOphir Munk domain = mlx5_glue->dr_create_domain(sh->ctx, 3032eb4d010SOphir Munk MLX5DV_DR_DOMAIN_TYPE_NIC_RX); 3042eb4d010SOphir Munk if (!domain) { 3052eb4d010SOphir Munk DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed"); 3062eb4d010SOphir Munk err = errno; 3072eb4d010SOphir Munk goto error; 3082eb4d010SOphir Munk } 3092eb4d010SOphir Munk sh->rx_domain = domain; 3102eb4d010SOphir Munk domain = mlx5_glue->dr_create_domain(sh->ctx, 3112eb4d010SOphir Munk MLX5DV_DR_DOMAIN_TYPE_NIC_TX); 3122eb4d010SOphir Munk if (!domain) { 3132eb4d010SOphir Munk DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed"); 3142eb4d010SOphir Munk err = errno; 3152eb4d010SOphir Munk goto error; 3162eb4d010SOphir Munk } 3172eb4d010SOphir Munk sh->tx_domain = domain; 3182eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 3192eb4d010SOphir Munk if (priv->config.dv_esw_en) { 3202eb4d010SOphir Munk domain = mlx5_glue->dr_create_domain 3212eb4d010SOphir Munk (sh->ctx, MLX5DV_DR_DOMAIN_TYPE_FDB); 3222eb4d010SOphir Munk if (!domain) { 3232eb4d010SOphir Munk DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed"); 3242eb4d010SOphir Munk err = errno; 3252eb4d010SOphir Munk goto error; 3262eb4d010SOphir Munk } 3272eb4d010SOphir Munk sh->fdb_domain = domain; 3282eb4d010SOphir Munk sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop(); 3292eb4d010SOphir Munk } 3302eb4d010SOphir Munk #endif 3314ec6360dSGregory Etelson if (!sh->tunnel_hub) 3324ec6360dSGregory Etelson err = mlx5_alloc_tunnel_hub(sh); 3334ec6360dSGregory Etelson if (err) { 3344ec6360dSGregory Etelson DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err); 3354ec6360dSGregory Etelson goto error; 3364ec6360dSGregory Etelson } 3372eb4d010SOphir Munk if (priv->config.reclaim_mode == MLX5_RCM_AGGR) { 3382eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1); 3392eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1); 3402eb4d010SOphir Munk if (sh->fdb_domain) 3412eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1); 3422eb4d010SOphir Munk } 3432eb4d010SOphir Munk sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan(); 3442eb4d010SOphir Munk #endif /* HAVE_MLX5DV_DR */ 345b80726dcSSuanming Mou sh->default_miss_action = 346b80726dcSSuanming Mou mlx5_glue->dr_create_flow_action_default_miss(); 347b80726dcSSuanming Mou if (!sh->default_miss_action) 348b80726dcSSuanming Mou DRV_LOG(WARNING, "Default miss action is not supported."); 3492eb4d010SOphir Munk return 0; 3502eb4d010SOphir Munk error: 3512eb4d010SOphir Munk /* Rollback the created objects. */ 3522eb4d010SOphir Munk if (sh->rx_domain) { 3532eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->rx_domain); 3542eb4d010SOphir Munk sh->rx_domain = NULL; 3552eb4d010SOphir Munk } 3562eb4d010SOphir Munk if (sh->tx_domain) { 3572eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->tx_domain); 3582eb4d010SOphir Munk sh->tx_domain = NULL; 3592eb4d010SOphir Munk } 3602eb4d010SOphir Munk if (sh->fdb_domain) { 3612eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->fdb_domain); 3622eb4d010SOphir Munk sh->fdb_domain = NULL; 3632eb4d010SOphir Munk } 3642eb4d010SOphir Munk if (sh->esw_drop_action) { 3652eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->esw_drop_action); 3662eb4d010SOphir Munk sh->esw_drop_action = NULL; 3672eb4d010SOphir Munk } 3682eb4d010SOphir Munk if (sh->pop_vlan_action) { 3692eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->pop_vlan_action); 3702eb4d010SOphir Munk sh->pop_vlan_action = NULL; 3712eb4d010SOphir Munk } 372bf615b07SSuanming Mou if (sh->encaps_decaps) { 373e69a5922SXueming Li mlx5_hlist_destroy(sh->encaps_decaps); 374bf615b07SSuanming Mou sh->encaps_decaps = NULL; 375bf615b07SSuanming Mou } 3763fe88961SSuanming Mou if (sh->modify_cmds) { 377e69a5922SXueming Li mlx5_hlist_destroy(sh->modify_cmds); 3783fe88961SSuanming Mou sh->modify_cmds = NULL; 3793fe88961SSuanming Mou } 3802eb4d010SOphir Munk if (sh->tag_table) { 3812eb4d010SOphir Munk /* tags should be destroyed with flow before. */ 382e69a5922SXueming Li mlx5_hlist_destroy(sh->tag_table); 3832eb4d010SOphir Munk sh->tag_table = NULL; 3842eb4d010SOphir Munk } 3854ec6360dSGregory Etelson if (sh->tunnel_hub) { 3864ec6360dSGregory Etelson mlx5_release_tunnel_hub(sh, priv->dev_port); 3874ec6360dSGregory Etelson sh->tunnel_hub = NULL; 3884ec6360dSGregory Etelson } 3892eb4d010SOphir Munk mlx5_free_table_hash_list(priv); 3902eb4d010SOphir Munk return err; 3912eb4d010SOphir Munk } 3922eb4d010SOphir Munk 3932eb4d010SOphir Munk /** 3942eb4d010SOphir Munk * Destroy DR related data within private structure. 3952eb4d010SOphir Munk * 3962eb4d010SOphir Munk * @param[in] priv 3972eb4d010SOphir Munk * Pointer to the private device data structure. 3982eb4d010SOphir Munk */ 3992eb4d010SOphir Munk void 4002eb4d010SOphir Munk mlx5_os_free_shared_dr(struct mlx5_priv *priv) 4012eb4d010SOphir Munk { 40216dbba25SXueming Li struct mlx5_dev_ctx_shared *sh = priv->sh; 4032eb4d010SOphir Munk 40416dbba25SXueming Li MLX5_ASSERT(sh && sh->refcnt); 40516dbba25SXueming Li if (sh->refcnt > 1) 4062eb4d010SOphir Munk return; 4072eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR 4082eb4d010SOphir Munk if (sh->rx_domain) { 4092eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->rx_domain); 4102eb4d010SOphir Munk sh->rx_domain = NULL; 4112eb4d010SOphir Munk } 4122eb4d010SOphir Munk if (sh->tx_domain) { 4132eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->tx_domain); 4142eb4d010SOphir Munk sh->tx_domain = NULL; 4152eb4d010SOphir Munk } 4162eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 4172eb4d010SOphir Munk if (sh->fdb_domain) { 4182eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->fdb_domain); 4192eb4d010SOphir Munk sh->fdb_domain = NULL; 4202eb4d010SOphir Munk } 4212eb4d010SOphir Munk if (sh->esw_drop_action) { 4222eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->esw_drop_action); 4232eb4d010SOphir Munk sh->esw_drop_action = NULL; 4242eb4d010SOphir Munk } 4252eb4d010SOphir Munk #endif 4262eb4d010SOphir Munk if (sh->pop_vlan_action) { 4272eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->pop_vlan_action); 4282eb4d010SOphir Munk sh->pop_vlan_action = NULL; 4292eb4d010SOphir Munk } 4302eb4d010SOphir Munk #endif /* HAVE_MLX5DV_DR */ 431b80726dcSSuanming Mou if (sh->default_miss_action) 432b80726dcSSuanming Mou mlx5_glue->destroy_flow_action 433b80726dcSSuanming Mou (sh->default_miss_action); 434bf615b07SSuanming Mou if (sh->encaps_decaps) { 435e69a5922SXueming Li mlx5_hlist_destroy(sh->encaps_decaps); 436bf615b07SSuanming Mou sh->encaps_decaps = NULL; 437bf615b07SSuanming Mou } 4383fe88961SSuanming Mou if (sh->modify_cmds) { 439e69a5922SXueming Li mlx5_hlist_destroy(sh->modify_cmds); 4403fe88961SSuanming Mou sh->modify_cmds = NULL; 4413fe88961SSuanming Mou } 4422eb4d010SOphir Munk if (sh->tag_table) { 4432eb4d010SOphir Munk /* tags should be destroyed with flow before. */ 444e69a5922SXueming Li mlx5_hlist_destroy(sh->tag_table); 4452eb4d010SOphir Munk sh->tag_table = NULL; 4462eb4d010SOphir Munk } 4474ec6360dSGregory Etelson if (sh->tunnel_hub) { 4484ec6360dSGregory Etelson mlx5_release_tunnel_hub(sh, priv->dev_port); 4494ec6360dSGregory Etelson sh->tunnel_hub = NULL; 4504ec6360dSGregory Etelson } 4510fd5f82aSXueming Li mlx5_cache_list_destroy(&sh->port_id_action_list); 4523422af2aSXueming Li mlx5_cache_list_destroy(&sh->push_vlan_action_list); 4532eb4d010SOphir Munk mlx5_free_table_hash_list(priv); 4542eb4d010SOphir Munk } 4552eb4d010SOphir Munk 4562eb4d010SOphir Munk /** 4572e86c4e5SOphir Munk * Initialize shared data between primary and secondary process. 4582e86c4e5SOphir Munk * 4592e86c4e5SOphir Munk * A memzone is reserved by primary process and secondary processes attach to 4602e86c4e5SOphir Munk * the memzone. 4612e86c4e5SOphir Munk * 4622e86c4e5SOphir Munk * @return 4632e86c4e5SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 4642e86c4e5SOphir Munk */ 4652e86c4e5SOphir Munk static int 4662e86c4e5SOphir Munk mlx5_init_shared_data(void) 4672e86c4e5SOphir Munk { 4682e86c4e5SOphir Munk const struct rte_memzone *mz; 4692e86c4e5SOphir Munk int ret = 0; 4702e86c4e5SOphir Munk 4712e86c4e5SOphir Munk rte_spinlock_lock(&mlx5_shared_data_lock); 4722e86c4e5SOphir Munk if (mlx5_shared_data == NULL) { 4732e86c4e5SOphir Munk if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 4742e86c4e5SOphir Munk /* Allocate shared memory. */ 4752e86c4e5SOphir Munk mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA, 4762e86c4e5SOphir Munk sizeof(*mlx5_shared_data), 4772e86c4e5SOphir Munk SOCKET_ID_ANY, 0); 4782e86c4e5SOphir Munk if (mz == NULL) { 4792e86c4e5SOphir Munk DRV_LOG(ERR, 4802e86c4e5SOphir Munk "Cannot allocate mlx5 shared data"); 4812e86c4e5SOphir Munk ret = -rte_errno; 4822e86c4e5SOphir Munk goto error; 4832e86c4e5SOphir Munk } 4842e86c4e5SOphir Munk mlx5_shared_data = mz->addr; 4852e86c4e5SOphir Munk memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data)); 4862e86c4e5SOphir Munk rte_spinlock_init(&mlx5_shared_data->lock); 4872e86c4e5SOphir Munk } else { 4882e86c4e5SOphir Munk /* Lookup allocated shared memory. */ 4892e86c4e5SOphir Munk mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA); 4902e86c4e5SOphir Munk if (mz == NULL) { 4912e86c4e5SOphir Munk DRV_LOG(ERR, 4922e86c4e5SOphir Munk "Cannot attach mlx5 shared data"); 4932e86c4e5SOphir Munk ret = -rte_errno; 4942e86c4e5SOphir Munk goto error; 4952e86c4e5SOphir Munk } 4962e86c4e5SOphir Munk mlx5_shared_data = mz->addr; 4972e86c4e5SOphir Munk memset(&mlx5_local_data, 0, sizeof(mlx5_local_data)); 4982e86c4e5SOphir Munk } 4992e86c4e5SOphir Munk } 5002e86c4e5SOphir Munk error: 5012e86c4e5SOphir Munk rte_spinlock_unlock(&mlx5_shared_data_lock); 5022e86c4e5SOphir Munk return ret; 5032e86c4e5SOphir Munk } 5042e86c4e5SOphir Munk 5052e86c4e5SOphir Munk /** 5062e86c4e5SOphir Munk * PMD global initialization. 5072e86c4e5SOphir Munk * 5082e86c4e5SOphir Munk * Independent from individual device, this function initializes global 5092e86c4e5SOphir Munk * per-PMD data structures distinguishing primary and secondary processes. 5102e86c4e5SOphir Munk * Hence, each initialization is called once per a process. 5112e86c4e5SOphir Munk * 5122e86c4e5SOphir Munk * @return 5132e86c4e5SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 5142e86c4e5SOphir Munk */ 5152e86c4e5SOphir Munk static int 5162e86c4e5SOphir Munk mlx5_init_once(void) 5172e86c4e5SOphir Munk { 5182e86c4e5SOphir Munk struct mlx5_shared_data *sd; 5192e86c4e5SOphir Munk struct mlx5_local_data *ld = &mlx5_local_data; 5202e86c4e5SOphir Munk int ret = 0; 5212e86c4e5SOphir Munk 5222e86c4e5SOphir Munk if (mlx5_init_shared_data()) 5232e86c4e5SOphir Munk return -rte_errno; 5242e86c4e5SOphir Munk sd = mlx5_shared_data; 5252e86c4e5SOphir Munk MLX5_ASSERT(sd); 5262e86c4e5SOphir Munk rte_spinlock_lock(&sd->lock); 5272e86c4e5SOphir Munk switch (rte_eal_process_type()) { 5282e86c4e5SOphir Munk case RTE_PROC_PRIMARY: 5292e86c4e5SOphir Munk if (sd->init_done) 5302e86c4e5SOphir Munk break; 5312e86c4e5SOphir Munk LIST_INIT(&sd->mem_event_cb_list); 5322e86c4e5SOphir Munk rte_rwlock_init(&sd->mem_event_rwlock); 5332e86c4e5SOphir Munk rte_mem_event_callback_register("MLX5_MEM_EVENT_CB", 5342e86c4e5SOphir Munk mlx5_mr_mem_event_cb, NULL); 5352e86c4e5SOphir Munk ret = mlx5_mp_init_primary(MLX5_MP_NAME, 5362e86c4e5SOphir Munk mlx5_mp_os_primary_handle); 5372e86c4e5SOphir Munk if (ret) 5382e86c4e5SOphir Munk goto out; 5392e86c4e5SOphir Munk sd->init_done = true; 5402e86c4e5SOphir Munk break; 5412e86c4e5SOphir Munk case RTE_PROC_SECONDARY: 5422e86c4e5SOphir Munk if (ld->init_done) 5432e86c4e5SOphir Munk break; 5442e86c4e5SOphir Munk ret = mlx5_mp_init_secondary(MLX5_MP_NAME, 5452e86c4e5SOphir Munk mlx5_mp_os_secondary_handle); 5462e86c4e5SOphir Munk if (ret) 5472e86c4e5SOphir Munk goto out; 5482e86c4e5SOphir Munk ++sd->secondary_cnt; 5492e86c4e5SOphir Munk ld->init_done = true; 5502e86c4e5SOphir Munk break; 5512e86c4e5SOphir Munk default: 5522e86c4e5SOphir Munk break; 5532e86c4e5SOphir Munk } 5542e86c4e5SOphir Munk out: 5552e86c4e5SOphir Munk rte_spinlock_unlock(&sd->lock); 5562e86c4e5SOphir Munk return ret; 5572e86c4e5SOphir Munk } 5582e86c4e5SOphir Munk 5592e86c4e5SOphir Munk /** 56086d259ceSMichael Baum * Create the Tx queue DevX/Verbs object. 56186d259ceSMichael Baum * 56286d259ceSMichael Baum * @param dev 56386d259ceSMichael Baum * Pointer to Ethernet device. 56486d259ceSMichael Baum * @param idx 56586d259ceSMichael Baum * Queue index in DPDK Tx queue array. 56686d259ceSMichael Baum * 56786d259ceSMichael Baum * @return 568f49f4483SMichael Baum * 0 on success, a negative errno value otherwise and rte_errno is set. 56986d259ceSMichael Baum */ 570f49f4483SMichael Baum static int 57186d259ceSMichael Baum mlx5_os_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx) 57286d259ceSMichael Baum { 57386d259ceSMichael Baum struct mlx5_priv *priv = dev->data->dev_private; 57486d259ceSMichael Baum struct mlx5_txq_data *txq_data = (*priv->txqs)[idx]; 57586d259ceSMichael Baum struct mlx5_txq_ctrl *txq_ctrl = 57686d259ceSMichael Baum container_of(txq_data, struct mlx5_txq_ctrl, txq); 57786d259ceSMichael Baum 57886d259ceSMichael Baum if (txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) 57986d259ceSMichael Baum return mlx5_txq_devx_obj_new(dev, idx); 58086d259ceSMichael Baum #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET 5813ec73abeSMatan Azrad if (!priv->config.dv_esw_en) 58286d259ceSMichael Baum return mlx5_txq_devx_obj_new(dev, idx); 58386d259ceSMichael Baum #endif 58486d259ceSMichael Baum return mlx5_txq_ibv_obj_new(dev, idx); 58586d259ceSMichael Baum } 58686d259ceSMichael Baum 58786d259ceSMichael Baum /** 58886d259ceSMichael Baum * Release an Tx DevX/verbs queue object. 58986d259ceSMichael Baum * 59086d259ceSMichael Baum * @param txq_obj 59186d259ceSMichael Baum * DevX/Verbs Tx queue object. 59286d259ceSMichael Baum */ 59386d259ceSMichael Baum static void 59486d259ceSMichael Baum mlx5_os_txq_obj_release(struct mlx5_txq_obj *txq_obj) 59586d259ceSMichael Baum { 59686d259ceSMichael Baum if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) { 59786d259ceSMichael Baum mlx5_txq_devx_obj_release(txq_obj); 59886d259ceSMichael Baum return; 59986d259ceSMichael Baum } 6003ec73abeSMatan Azrad #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET 6013ec73abeSMatan Azrad if (!txq_obj->txq_ctrl->priv->config.dv_esw_en) { 6023ec73abeSMatan Azrad mlx5_txq_devx_obj_release(txq_obj); 6033ec73abeSMatan Azrad return; 60486d259ceSMichael Baum } 6053ec73abeSMatan Azrad #endif 60686d259ceSMichael Baum mlx5_txq_ibv_obj_release(txq_obj); 60786d259ceSMichael Baum } 60886d259ceSMichael Baum 60986d259ceSMichael Baum /** 610994829e6SSuanming Mou * DV flow counter mode detect and config. 611994829e6SSuanming Mou * 612994829e6SSuanming Mou * @param dev 613994829e6SSuanming Mou * Pointer to rte_eth_dev structure. 614994829e6SSuanming Mou * 615994829e6SSuanming Mou */ 616994829e6SSuanming Mou static void 617994829e6SSuanming Mou mlx5_flow_counter_mode_config(struct rte_eth_dev *dev __rte_unused) 618994829e6SSuanming Mou { 619994829e6SSuanming Mou #ifdef HAVE_IBV_FLOW_DV_SUPPORT 620994829e6SSuanming Mou struct mlx5_priv *priv = dev->data->dev_private; 6212b5b1aebSSuanming Mou struct mlx5_dev_ctx_shared *sh = priv->sh; 6222b5b1aebSSuanming Mou bool fallback; 623994829e6SSuanming Mou 624994829e6SSuanming Mou #ifndef HAVE_IBV_DEVX_ASYNC 6252b5b1aebSSuanming Mou fallback = true; 626994829e6SSuanming Mou #else 6272b5b1aebSSuanming Mou fallback = false; 6282b5b1aebSSuanming Mou if (!priv->config.devx || !priv->config.dv_flow_en || 6292b5b1aebSSuanming Mou !priv->config.hca_attr.flow_counters_dump || 630994829e6SSuanming Mou !(priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4) || 631994829e6SSuanming Mou (mlx5_flow_dv_discover_counter_offset_support(dev) == -ENOTSUP)) 6322b5b1aebSSuanming Mou fallback = true; 633994829e6SSuanming Mou #endif 6342b5b1aebSSuanming Mou if (fallback) 635994829e6SSuanming Mou DRV_LOG(INFO, "Use fall-back DV counter management. Flow " 636994829e6SSuanming Mou "counter dump:%d, bulk_alloc_bitmap:0x%hhx.", 637994829e6SSuanming Mou priv->config.hca_attr.flow_counters_dump, 638994829e6SSuanming Mou priv->config.hca_attr.flow_counter_bulk_alloc_bitmap); 6392b5b1aebSSuanming Mou /* Initialize fallback mode only on the port initializes sh. */ 6402b5b1aebSSuanming Mou if (sh->refcnt == 1) 6412b5b1aebSSuanming Mou sh->cmng.counter_fallback = fallback; 6422b5b1aebSSuanming Mou else if (fallback != sh->cmng.counter_fallback) 6432b5b1aebSSuanming Mou DRV_LOG(WARNING, "Port %d in sh has different fallback mode " 6442b5b1aebSSuanming Mou "with others:%d.", PORT_ID(priv), fallback); 645994829e6SSuanming Mou #endif 646994829e6SSuanming Mou } 647994829e6SSuanming Mou 648994829e6SSuanming Mou /** 6492eb4d010SOphir Munk * Spawn an Ethernet device from Verbs information. 6502eb4d010SOphir Munk * 6512eb4d010SOphir Munk * @param dpdk_dev 6522eb4d010SOphir Munk * Backing DPDK device. 6532eb4d010SOphir Munk * @param spawn 6542eb4d010SOphir Munk * Verbs device parameters (name, port, switch_info) to spawn. 6552eb4d010SOphir Munk * @param config 6562eb4d010SOphir Munk * Device configuration parameters. 6572eb4d010SOphir Munk * 6582eb4d010SOphir Munk * @return 6592eb4d010SOphir Munk * A valid Ethernet device object on success, NULL otherwise and rte_errno 6602eb4d010SOphir Munk * is set. The following errors are defined: 6612eb4d010SOphir Munk * 6622eb4d010SOphir Munk * EBUSY: device is not supposed to be spawned. 6632eb4d010SOphir Munk * EEXIST: device is already spawned 6642eb4d010SOphir Munk */ 6652eb4d010SOphir Munk static struct rte_eth_dev * 6662eb4d010SOphir Munk mlx5_dev_spawn(struct rte_device *dpdk_dev, 6672eb4d010SOphir Munk struct mlx5_dev_spawn_data *spawn, 668d462a83cSMichael Baum struct mlx5_dev_config *config) 6692eb4d010SOphir Munk { 6702eb4d010SOphir Munk const struct mlx5_switch_info *switch_info = &spawn->info; 6712eb4d010SOphir Munk struct mlx5_dev_ctx_shared *sh = NULL; 6722eb4d010SOphir Munk struct ibv_port_attr port_attr; 6732eb4d010SOphir Munk struct mlx5dv_context dv_attr = { .comp_mask = 0 }; 6742eb4d010SOphir Munk struct rte_eth_dev *eth_dev = NULL; 6752eb4d010SOphir Munk struct mlx5_priv *priv = NULL; 6762eb4d010SOphir Munk int err = 0; 6772eb4d010SOphir Munk unsigned int hw_padding = 0; 6782eb4d010SOphir Munk unsigned int mps; 6792eb4d010SOphir Munk unsigned int cqe_comp; 6802eb4d010SOphir Munk unsigned int tunnel_en = 0; 6812eb4d010SOphir Munk unsigned int mpls_en = 0; 6822eb4d010SOphir Munk unsigned int swp = 0; 6832eb4d010SOphir Munk unsigned int mprq = 0; 6842eb4d010SOphir Munk unsigned int mprq_min_stride_size_n = 0; 6852eb4d010SOphir Munk unsigned int mprq_max_stride_size_n = 0; 6862eb4d010SOphir Munk unsigned int mprq_min_stride_num_n = 0; 6872eb4d010SOphir Munk unsigned int mprq_max_stride_num_n = 0; 6882eb4d010SOphir Munk struct rte_ether_addr mac; 6892eb4d010SOphir Munk char name[RTE_ETH_NAME_MAX_LEN]; 6902eb4d010SOphir Munk int own_domain_id = 0; 6912eb4d010SOphir Munk uint16_t port_id; 6922eb4d010SOphir Munk unsigned int i; 6932eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_DEVX_PORT 6942eb4d010SOphir Munk struct mlx5dv_devx_port devx_port = { .comp_mask = 0 }; 6952eb4d010SOphir Munk #endif 6962eb4d010SOphir Munk 6972eb4d010SOphir Munk /* Determine if this port representor is supposed to be spawned. */ 6982eb4d010SOphir Munk if (switch_info->representor && dpdk_dev->devargs) { 6992eb4d010SOphir Munk struct rte_eth_devargs eth_da; 7002eb4d010SOphir Munk 7012eb4d010SOphir Munk err = rte_eth_devargs_parse(dpdk_dev->devargs->args, ð_da); 7022eb4d010SOphir Munk if (err) { 7032eb4d010SOphir Munk rte_errno = -err; 7042eb4d010SOphir Munk DRV_LOG(ERR, "failed to process device arguments: %s", 7052eb4d010SOphir Munk strerror(rte_errno)); 7062eb4d010SOphir Munk return NULL; 7072eb4d010SOphir Munk } 7082eb4d010SOphir Munk for (i = 0; i < eth_da.nb_representor_ports; ++i) 7092eb4d010SOphir Munk if (eth_da.representor_ports[i] == 7102eb4d010SOphir Munk (uint16_t)switch_info->port_name) 7112eb4d010SOphir Munk break; 7122eb4d010SOphir Munk if (i == eth_da.nb_representor_ports) { 7132eb4d010SOphir Munk rte_errno = EBUSY; 7142eb4d010SOphir Munk return NULL; 7152eb4d010SOphir Munk } 7162eb4d010SOphir Munk } 7172eb4d010SOphir Munk /* Build device name. */ 7182eb4d010SOphir Munk if (spawn->pf_bond < 0) { 7192eb4d010SOphir Munk /* Single device. */ 7202eb4d010SOphir Munk if (!switch_info->representor) 7212eb4d010SOphir Munk strlcpy(name, dpdk_dev->name, sizeof(name)); 7222eb4d010SOphir Munk else 7232eb4d010SOphir Munk snprintf(name, sizeof(name), "%s_representor_%u", 7242eb4d010SOphir Munk dpdk_dev->name, switch_info->port_name); 7252eb4d010SOphir Munk } else { 7262eb4d010SOphir Munk /* Bonding device. */ 7272eb4d010SOphir Munk if (!switch_info->representor) 7282eb4d010SOphir Munk snprintf(name, sizeof(name), "%s_%s", 729834a9019SOphir Munk dpdk_dev->name, 730834a9019SOphir Munk mlx5_os_get_dev_device_name(spawn->phys_dev)); 7312eb4d010SOphir Munk else 7322eb4d010SOphir Munk snprintf(name, sizeof(name), "%s_%s_representor_%u", 733834a9019SOphir Munk dpdk_dev->name, 734834a9019SOphir Munk mlx5_os_get_dev_device_name(spawn->phys_dev), 7352eb4d010SOphir Munk switch_info->port_name); 7362eb4d010SOphir Munk } 7372eb4d010SOphir Munk /* check if the device is already spawned */ 7382eb4d010SOphir Munk if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) { 7392eb4d010SOphir Munk rte_errno = EEXIST; 7402eb4d010SOphir Munk return NULL; 7412eb4d010SOphir Munk } 7422eb4d010SOphir Munk DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name); 7432eb4d010SOphir Munk if (rte_eal_process_type() == RTE_PROC_SECONDARY) { 7442eb4d010SOphir Munk struct mlx5_mp_id mp_id; 7452eb4d010SOphir Munk 7462eb4d010SOphir Munk eth_dev = rte_eth_dev_attach_secondary(name); 7472eb4d010SOphir Munk if (eth_dev == NULL) { 7482eb4d010SOphir Munk DRV_LOG(ERR, "can not attach rte ethdev"); 7492eb4d010SOphir Munk rte_errno = ENOMEM; 7502eb4d010SOphir Munk return NULL; 7512eb4d010SOphir Munk } 752e6818853SXueming Li priv = eth_dev->data->dev_private; 753e6818853SXueming Li if (priv->sh->bond_dev != UINT16_MAX) 754e6818853SXueming Li /* For bonding port, use primary PCI device. */ 755e6818853SXueming Li eth_dev->device = 756e6818853SXueming Li rte_eth_devices[priv->sh->bond_dev].device; 757e6818853SXueming Li else 7582eb4d010SOphir Munk eth_dev->device = dpdk_dev; 759b012b4ceSOphir Munk eth_dev->dev_ops = &mlx5_dev_sec_ops; 760cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 761cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 7622eb4d010SOphir Munk err = mlx5_proc_priv_init(eth_dev); 7632eb4d010SOphir Munk if (err) 7642eb4d010SOphir Munk return NULL; 7652eb4d010SOphir Munk mp_id.port_id = eth_dev->data->port_id; 7662eb4d010SOphir Munk strlcpy(mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN); 7672eb4d010SOphir Munk /* Receive command fd from primary process */ 7682eb4d010SOphir Munk err = mlx5_mp_req_verbs_cmd_fd(&mp_id); 7692eb4d010SOphir Munk if (err < 0) 7702eb4d010SOphir Munk goto err_secondary; 7712eb4d010SOphir Munk /* Remap UAR for Tx queues. */ 7722eb4d010SOphir Munk err = mlx5_tx_uar_init_secondary(eth_dev, err); 7732eb4d010SOphir Munk if (err) 7742eb4d010SOphir Munk goto err_secondary; 7752eb4d010SOphir Munk /* 7762eb4d010SOphir Munk * Ethdev pointer is still required as input since 7772eb4d010SOphir Munk * the primary device is not accessible from the 7782eb4d010SOphir Munk * secondary process. 7792eb4d010SOphir Munk */ 7802eb4d010SOphir Munk eth_dev->rx_pkt_burst = mlx5_select_rx_function(eth_dev); 7812eb4d010SOphir Munk eth_dev->tx_pkt_burst = mlx5_select_tx_function(eth_dev); 7822eb4d010SOphir Munk return eth_dev; 7832eb4d010SOphir Munk err_secondary: 7842eb4d010SOphir Munk mlx5_dev_close(eth_dev); 7852eb4d010SOphir Munk return NULL; 7862eb4d010SOphir Munk } 7872eb4d010SOphir Munk /* 7882eb4d010SOphir Munk * Some parameters ("tx_db_nc" in particularly) are needed in 7892eb4d010SOphir Munk * advance to create dv/verbs device context. We proceed the 7902eb4d010SOphir Munk * devargs here to get ones, and later proceed devargs again 7912eb4d010SOphir Munk * to override some hardware settings. 7922eb4d010SOphir Munk */ 793d462a83cSMichael Baum err = mlx5_args(config, dpdk_dev->devargs); 7942eb4d010SOphir Munk if (err) { 7952eb4d010SOphir Munk err = rte_errno; 7962eb4d010SOphir Munk DRV_LOG(ERR, "failed to process device arguments: %s", 7972eb4d010SOphir Munk strerror(rte_errno)); 7982eb4d010SOphir Munk goto error; 7992eb4d010SOphir Munk } 8004ec6360dSGregory Etelson if (config->dv_miss_info) { 8014ec6360dSGregory Etelson if (switch_info->master || switch_info->representor) 8024ec6360dSGregory Etelson config->dv_xmeta_en = MLX5_XMETA_MODE_META16; 8034ec6360dSGregory Etelson } 804d462a83cSMichael Baum mlx5_malloc_mem_select(config->sys_mem_en); 805d462a83cSMichael Baum sh = mlx5_alloc_shared_dev_ctx(spawn, config); 8062eb4d010SOphir Munk if (!sh) 8072eb4d010SOphir Munk return NULL; 808d462a83cSMichael Baum config->devx = sh->devx; 8092eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ACTION_DEST_DEVX_TIR 810d462a83cSMichael Baum config->dest_tir = 1; 8112eb4d010SOphir Munk #endif 8122eb4d010SOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 8132eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_SWP; 8142eb4d010SOphir Munk #endif 8152eb4d010SOphir Munk /* 8162eb4d010SOphir Munk * Multi-packet send is supported by ConnectX-4 Lx PF as well 8172eb4d010SOphir Munk * as all ConnectX-5 devices. 8182eb4d010SOphir Munk */ 8192eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 8202eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS; 8212eb4d010SOphir Munk #endif 8222eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT 8232eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_STRIDING_RQ; 8242eb4d010SOphir Munk #endif 8252eb4d010SOphir Munk mlx5_glue->dv_query_device(sh->ctx, &dv_attr); 8262eb4d010SOphir Munk if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED) { 8272eb4d010SOphir Munk if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW) { 8282eb4d010SOphir Munk DRV_LOG(DEBUG, "enhanced MPW is supported"); 8292eb4d010SOphir Munk mps = MLX5_MPW_ENHANCED; 8302eb4d010SOphir Munk } else { 8312eb4d010SOphir Munk DRV_LOG(DEBUG, "MPW is supported"); 8322eb4d010SOphir Munk mps = MLX5_MPW; 8332eb4d010SOphir Munk } 8342eb4d010SOphir Munk } else { 8352eb4d010SOphir Munk DRV_LOG(DEBUG, "MPW isn't supported"); 8362eb4d010SOphir Munk mps = MLX5_MPW_DISABLED; 8372eb4d010SOphir Munk } 8382eb4d010SOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 8392eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_SWP) 8402eb4d010SOphir Munk swp = dv_attr.sw_parsing_caps.sw_parsing_offloads; 8412eb4d010SOphir Munk DRV_LOG(DEBUG, "SWP support: %u", swp); 8422eb4d010SOphir Munk #endif 843d462a83cSMichael Baum config->swp = !!swp; 8442eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT 8452eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_STRIDING_RQ) { 8462eb4d010SOphir Munk struct mlx5dv_striding_rq_caps mprq_caps = 8472eb4d010SOphir Munk dv_attr.striding_rq_caps; 8482eb4d010SOphir Munk 8492eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmin_single_stride_log_num_of_bytes: %d", 8502eb4d010SOphir Munk mprq_caps.min_single_stride_log_num_of_bytes); 8512eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmax_single_stride_log_num_of_bytes: %d", 8522eb4d010SOphir Munk mprq_caps.max_single_stride_log_num_of_bytes); 8532eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmin_single_wqe_log_num_of_strides: %d", 8542eb4d010SOphir Munk mprq_caps.min_single_wqe_log_num_of_strides); 8552eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmax_single_wqe_log_num_of_strides: %d", 8562eb4d010SOphir Munk mprq_caps.max_single_wqe_log_num_of_strides); 8572eb4d010SOphir Munk DRV_LOG(DEBUG, "\tsupported_qpts: %d", 8582eb4d010SOphir Munk mprq_caps.supported_qpts); 8592eb4d010SOphir Munk DRV_LOG(DEBUG, "device supports Multi-Packet RQ"); 8602eb4d010SOphir Munk mprq = 1; 8612eb4d010SOphir Munk mprq_min_stride_size_n = 8622eb4d010SOphir Munk mprq_caps.min_single_stride_log_num_of_bytes; 8632eb4d010SOphir Munk mprq_max_stride_size_n = 8642eb4d010SOphir Munk mprq_caps.max_single_stride_log_num_of_bytes; 8652eb4d010SOphir Munk mprq_min_stride_num_n = 8662eb4d010SOphir Munk mprq_caps.min_single_wqe_log_num_of_strides; 8672eb4d010SOphir Munk mprq_max_stride_num_n = 8682eb4d010SOphir Munk mprq_caps.max_single_wqe_log_num_of_strides; 8692eb4d010SOphir Munk } 8702eb4d010SOphir Munk #endif 8712eb4d010SOphir Munk if (RTE_CACHE_LINE_SIZE == 128 && 8722eb4d010SOphir Munk !(dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP)) 8732eb4d010SOphir Munk cqe_comp = 0; 8742eb4d010SOphir Munk else 8752eb4d010SOphir Munk cqe_comp = 1; 876d462a83cSMichael Baum config->cqe_comp = cqe_comp; 8772eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 8782eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS) { 8792eb4d010SOphir Munk tunnel_en = ((dv_attr.tunnel_offloads_caps & 8802eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_VXLAN) && 8812eb4d010SOphir Munk (dv_attr.tunnel_offloads_caps & 8822eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GRE) && 8832eb4d010SOphir Munk (dv_attr.tunnel_offloads_caps & 8842eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GENEVE)); 8852eb4d010SOphir Munk } 8862eb4d010SOphir Munk DRV_LOG(DEBUG, "tunnel offloading is %ssupported", 8872eb4d010SOphir Munk tunnel_en ? "" : "not "); 8882eb4d010SOphir Munk #else 8892eb4d010SOphir Munk DRV_LOG(WARNING, 8902eb4d010SOphir Munk "tunnel offloading disabled due to old OFED/rdma-core version"); 8912eb4d010SOphir Munk #endif 892d462a83cSMichael Baum config->tunnel_en = tunnel_en; 8932eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT 8942eb4d010SOphir Munk mpls_en = ((dv_attr.tunnel_offloads_caps & 8952eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_GRE) && 8962eb4d010SOphir Munk (dv_attr.tunnel_offloads_caps & 8972eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_UDP)); 8982eb4d010SOphir Munk DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is %ssupported", 8992eb4d010SOphir Munk mpls_en ? "" : "not "); 9002eb4d010SOphir Munk #else 9012eb4d010SOphir Munk DRV_LOG(WARNING, "MPLS over GRE/UDP tunnel offloading disabled due to" 9022eb4d010SOphir Munk " old OFED/rdma-core version or firmware configuration"); 9032eb4d010SOphir Munk #endif 904d462a83cSMichael Baum config->mpls_en = mpls_en; 9052eb4d010SOphir Munk /* Check port status. */ 906834a9019SOphir Munk err = mlx5_glue->query_port(sh->ctx, spawn->phys_port, &port_attr); 9072eb4d010SOphir Munk if (err) { 9082eb4d010SOphir Munk DRV_LOG(ERR, "port query failed: %s", strerror(err)); 9092eb4d010SOphir Munk goto error; 9102eb4d010SOphir Munk } 9112eb4d010SOphir Munk if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) { 9122eb4d010SOphir Munk DRV_LOG(ERR, "port is not configured in Ethernet mode"); 9132eb4d010SOphir Munk err = EINVAL; 9142eb4d010SOphir Munk goto error; 9152eb4d010SOphir Munk } 9162eb4d010SOphir Munk if (port_attr.state != IBV_PORT_ACTIVE) 9172eb4d010SOphir Munk DRV_LOG(DEBUG, "port is not active: \"%s\" (%d)", 9182eb4d010SOphir Munk mlx5_glue->port_state_str(port_attr.state), 9192eb4d010SOphir Munk port_attr.state); 9202eb4d010SOphir Munk /* Allocate private eth device data. */ 9212175c4dcSSuanming Mou priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, 9222eb4d010SOphir Munk sizeof(*priv), 9232175c4dcSSuanming Mou RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 9242eb4d010SOphir Munk if (priv == NULL) { 9252eb4d010SOphir Munk DRV_LOG(ERR, "priv allocation failure"); 9262eb4d010SOphir Munk err = ENOMEM; 9272eb4d010SOphir Munk goto error; 9282eb4d010SOphir Munk } 9292eb4d010SOphir Munk priv->sh = sh; 93091389890SOphir Munk priv->dev_port = spawn->phys_port; 9312eb4d010SOphir Munk priv->pci_dev = spawn->pci_dev; 9322eb4d010SOphir Munk priv->mtu = RTE_ETHER_MTU; 9332eb4d010SOphir Munk /* Some internal functions rely on Netlink sockets, open them now. */ 9342eb4d010SOphir Munk priv->nl_socket_rdma = mlx5_nl_init(NETLINK_RDMA); 9352eb4d010SOphir Munk priv->nl_socket_route = mlx5_nl_init(NETLINK_ROUTE); 9362eb4d010SOphir Munk priv->representor = !!switch_info->representor; 9372eb4d010SOphir Munk priv->master = !!switch_info->master; 9382eb4d010SOphir Munk priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 9392eb4d010SOphir Munk priv->vport_meta_tag = 0; 9402eb4d010SOphir Munk priv->vport_meta_mask = 0; 9412eb4d010SOphir Munk priv->pf_bond = spawn->pf_bond; 9422eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_DEVX_PORT 9432eb4d010SOphir Munk /* 9442eb4d010SOphir Munk * The DevX port query API is implemented. E-Switch may use 9452eb4d010SOphir Munk * either vport or reg_c[0] metadata register to match on 9462eb4d010SOphir Munk * vport index. The engaged part of metadata register is 9472eb4d010SOphir Munk * defined by mask. 9482eb4d010SOphir Munk */ 9492eb4d010SOphir Munk if (switch_info->representor || switch_info->master) { 9502eb4d010SOphir Munk devx_port.comp_mask = MLX5DV_DEVX_PORT_VPORT | 9512eb4d010SOphir Munk MLX5DV_DEVX_PORT_MATCH_REG_C_0; 952834a9019SOphir Munk err = mlx5_glue->devx_port_query(sh->ctx, spawn->phys_port, 9532eb4d010SOphir Munk &devx_port); 9542eb4d010SOphir Munk if (err) { 9552eb4d010SOphir Munk DRV_LOG(WARNING, 9562eb4d010SOphir Munk "can't query devx port %d on device %s", 957834a9019SOphir Munk spawn->phys_port, 958834a9019SOphir Munk mlx5_os_get_dev_device_name(spawn->phys_dev)); 9592eb4d010SOphir Munk devx_port.comp_mask = 0; 9602eb4d010SOphir Munk } 9612eb4d010SOphir Munk } 9622eb4d010SOphir Munk if (devx_port.comp_mask & MLX5DV_DEVX_PORT_MATCH_REG_C_0) { 9632eb4d010SOphir Munk priv->vport_meta_tag = devx_port.reg_c_0.value; 9642eb4d010SOphir Munk priv->vport_meta_mask = devx_port.reg_c_0.mask; 9652eb4d010SOphir Munk if (!priv->vport_meta_mask) { 9662eb4d010SOphir Munk DRV_LOG(ERR, "vport zero mask for port %d" 9672eb4d010SOphir Munk " on bonding device %s", 968834a9019SOphir Munk spawn->phys_port, 969834a9019SOphir Munk mlx5_os_get_dev_device_name 970834a9019SOphir Munk (spawn->phys_dev)); 9712eb4d010SOphir Munk err = ENOTSUP; 9722eb4d010SOphir Munk goto error; 9732eb4d010SOphir Munk } 9742eb4d010SOphir Munk if (priv->vport_meta_tag & ~priv->vport_meta_mask) { 9752eb4d010SOphir Munk DRV_LOG(ERR, "invalid vport tag for port %d" 9762eb4d010SOphir Munk " on bonding device %s", 977834a9019SOphir Munk spawn->phys_port, 978834a9019SOphir Munk mlx5_os_get_dev_device_name 979834a9019SOphir Munk (spawn->phys_dev)); 9802eb4d010SOphir Munk err = ENOTSUP; 9812eb4d010SOphir Munk goto error; 9822eb4d010SOphir Munk } 9832eb4d010SOphir Munk } 9842eb4d010SOphir Munk if (devx_port.comp_mask & MLX5DV_DEVX_PORT_VPORT) { 9852eb4d010SOphir Munk priv->vport_id = devx_port.vport_num; 9862eb4d010SOphir Munk } else if (spawn->pf_bond >= 0) { 9872eb4d010SOphir Munk DRV_LOG(ERR, "can't deduce vport index for port %d" 9882eb4d010SOphir Munk " on bonding device %s", 989834a9019SOphir Munk spawn->phys_port, 990834a9019SOphir Munk mlx5_os_get_dev_device_name(spawn->phys_dev)); 9912eb4d010SOphir Munk err = ENOTSUP; 9922eb4d010SOphir Munk goto error; 9932eb4d010SOphir Munk } else { 9942eb4d010SOphir Munk /* Suppose vport index in compatible way. */ 9952eb4d010SOphir Munk priv->vport_id = switch_info->representor ? 9962eb4d010SOphir Munk switch_info->port_name + 1 : -1; 9972eb4d010SOphir Munk } 9982eb4d010SOphir Munk #else 9992eb4d010SOphir Munk /* 10002eb4d010SOphir Munk * Kernel/rdma_core support single E-Switch per PF configurations 10012eb4d010SOphir Munk * only and vport_id field contains the vport index for 10022eb4d010SOphir Munk * associated VF, which is deduced from representor port name. 10032eb4d010SOphir Munk * For example, let's have the IB device port 10, it has 10042eb4d010SOphir Munk * attached network device eth0, which has port name attribute 10052eb4d010SOphir Munk * pf0vf2, we can deduce the VF number as 2, and set vport index 10062eb4d010SOphir Munk * as 3 (2+1). This assigning schema should be changed if the 10072eb4d010SOphir Munk * multiple E-Switch instances per PF configurations or/and PCI 10082eb4d010SOphir Munk * subfunctions are added. 10092eb4d010SOphir Munk */ 10102eb4d010SOphir Munk priv->vport_id = switch_info->representor ? 10112eb4d010SOphir Munk switch_info->port_name + 1 : -1; 10122eb4d010SOphir Munk #endif 10132eb4d010SOphir Munk /* representor_id field keeps the unmodified VF index. */ 10142eb4d010SOphir Munk priv->representor_id = switch_info->representor ? 10152eb4d010SOphir Munk switch_info->port_name : -1; 10162eb4d010SOphir Munk /* 10172eb4d010SOphir Munk * Look for sibling devices in order to reuse their switch domain 10182eb4d010SOphir Munk * if any, otherwise allocate one. 10192eb4d010SOphir Munk */ 10202eb4d010SOphir Munk MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) { 10212eb4d010SOphir Munk const struct mlx5_priv *opriv = 10222eb4d010SOphir Munk rte_eth_devices[port_id].data->dev_private; 10232eb4d010SOphir Munk 10242eb4d010SOphir Munk if (!opriv || 10252eb4d010SOphir Munk opriv->sh != priv->sh || 10262eb4d010SOphir Munk opriv->domain_id == 10272eb4d010SOphir Munk RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) 10282eb4d010SOphir Munk continue; 10292eb4d010SOphir Munk priv->domain_id = opriv->domain_id; 10302eb4d010SOphir Munk break; 10312eb4d010SOphir Munk } 10322eb4d010SOphir Munk if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { 10332eb4d010SOphir Munk err = rte_eth_switch_domain_alloc(&priv->domain_id); 10342eb4d010SOphir Munk if (err) { 10352eb4d010SOphir Munk err = rte_errno; 10362eb4d010SOphir Munk DRV_LOG(ERR, "unable to allocate switch domain: %s", 10372eb4d010SOphir Munk strerror(rte_errno)); 10382eb4d010SOphir Munk goto error; 10392eb4d010SOphir Munk } 10402eb4d010SOphir Munk own_domain_id = 1; 10412eb4d010SOphir Munk } 10422eb4d010SOphir Munk /* Override some values set by hardware configuration. */ 1043d462a83cSMichael Baum mlx5_args(config, dpdk_dev->devargs); 1044d462a83cSMichael Baum err = mlx5_dev_check_sibling_config(priv, config); 10452eb4d010SOphir Munk if (err) 10462eb4d010SOphir Munk goto error; 1047d462a83cSMichael Baum config->hw_csum = !!(sh->device_attr.device_cap_flags_ex & 10482eb4d010SOphir Munk IBV_DEVICE_RAW_IP_CSUM); 10492eb4d010SOphir Munk DRV_LOG(DEBUG, "checksum offloading is %ssupported", 1050d462a83cSMichael Baum (config->hw_csum ? "" : "not ")); 10512eb4d010SOphir Munk #if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \ 10522eb4d010SOphir Munk !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) 10532eb4d010SOphir Munk DRV_LOG(DEBUG, "counters are not supported"); 10542eb4d010SOphir Munk #endif 10552eb4d010SOphir Munk #if !defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_MLX5DV_DR) 1056d462a83cSMichael Baum if (config->dv_flow_en) { 10572eb4d010SOphir Munk DRV_LOG(WARNING, "DV flow is not supported"); 1058d462a83cSMichael Baum config->dv_flow_en = 0; 10592eb4d010SOphir Munk } 10602eb4d010SOphir Munk #endif 1061d462a83cSMichael Baum config->ind_table_max_size = 10622eb4d010SOphir Munk sh->device_attr.max_rwq_indirection_table_size; 10632eb4d010SOphir Munk /* 10642eb4d010SOphir Munk * Remove this check once DPDK supports larger/variable 10652eb4d010SOphir Munk * indirection tables. 10662eb4d010SOphir Munk */ 1067d462a83cSMichael Baum if (config->ind_table_max_size > (unsigned int)ETH_RSS_RETA_SIZE_512) 1068d462a83cSMichael Baum config->ind_table_max_size = ETH_RSS_RETA_SIZE_512; 10692eb4d010SOphir Munk DRV_LOG(DEBUG, "maximum Rx indirection table size is %u", 1070d462a83cSMichael Baum config->ind_table_max_size); 1071d462a83cSMichael Baum config->hw_vlan_strip = !!(sh->device_attr.raw_packet_caps & 10722eb4d010SOphir Munk IBV_RAW_PACKET_CAP_CVLAN_STRIPPING); 10732eb4d010SOphir Munk DRV_LOG(DEBUG, "VLAN stripping is %ssupported", 1074d462a83cSMichael Baum (config->hw_vlan_strip ? "" : "not ")); 1075d462a83cSMichael Baum config->hw_fcs_strip = !!(sh->device_attr.raw_packet_caps & 10762eb4d010SOphir Munk IBV_RAW_PACKET_CAP_SCATTER_FCS); 10772eb4d010SOphir Munk #if defined(HAVE_IBV_WQ_FLAG_RX_END_PADDING) 10782eb4d010SOphir Munk hw_padding = !!sh->device_attr.rx_pad_end_addr_align; 10792eb4d010SOphir Munk #elif defined(HAVE_IBV_WQ_FLAGS_PCI_WRITE_END_PADDING) 10802eb4d010SOphir Munk hw_padding = !!(sh->device_attr.device_cap_flags_ex & 10812eb4d010SOphir Munk IBV_DEVICE_PCI_WRITE_END_PADDING); 10822eb4d010SOphir Munk #endif 1083d462a83cSMichael Baum if (config->hw_padding && !hw_padding) { 10842eb4d010SOphir Munk DRV_LOG(DEBUG, "Rx end alignment padding isn't supported"); 1085d462a83cSMichael Baum config->hw_padding = 0; 1086d462a83cSMichael Baum } else if (config->hw_padding) { 10872eb4d010SOphir Munk DRV_LOG(DEBUG, "Rx end alignment padding is enabled"); 10882eb4d010SOphir Munk } 1089d462a83cSMichael Baum config->tso = (sh->device_attr.max_tso > 0 && 10902eb4d010SOphir Munk (sh->device_attr.tso_supported_qpts & 10912eb4d010SOphir Munk (1 << IBV_QPT_RAW_PACKET))); 1092d462a83cSMichael Baum if (config->tso) 1093d462a83cSMichael Baum config->tso_max_payload_sz = sh->device_attr.max_tso; 10942eb4d010SOphir Munk /* 10952eb4d010SOphir Munk * MPW is disabled by default, while the Enhanced MPW is enabled 10962eb4d010SOphir Munk * by default. 10972eb4d010SOphir Munk */ 1098d462a83cSMichael Baum if (config->mps == MLX5_ARG_UNSET) 1099d462a83cSMichael Baum config->mps = (mps == MLX5_MPW_ENHANCED) ? MLX5_MPW_ENHANCED : 11002eb4d010SOphir Munk MLX5_MPW_DISABLED; 11012eb4d010SOphir Munk else 1102d462a83cSMichael Baum config->mps = config->mps ? mps : MLX5_MPW_DISABLED; 11032eb4d010SOphir Munk DRV_LOG(INFO, "%sMPS is %s", 1104d462a83cSMichael Baum config->mps == MLX5_MPW_ENHANCED ? "enhanced " : 1105d462a83cSMichael Baum config->mps == MLX5_MPW ? "legacy " : "", 1106d462a83cSMichael Baum config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled"); 1107d462a83cSMichael Baum if (config->cqe_comp && !cqe_comp) { 11082eb4d010SOphir Munk DRV_LOG(WARNING, "Rx CQE compression isn't supported"); 1109d462a83cSMichael Baum config->cqe_comp = 0; 11102eb4d010SOphir Munk } 1111d462a83cSMichael Baum if (config->devx) { 1112d462a83cSMichael Baum err = mlx5_devx_cmd_query_hca_attr(sh->ctx, &config->hca_attr); 11132eb4d010SOphir Munk if (err) { 11142eb4d010SOphir Munk err = -err; 11152eb4d010SOphir Munk goto error; 11162eb4d010SOphir Munk } 11173aa27915SSuanming Mou /* Check relax ordering support. */ 1118e82ddd28STal Shnaiderman if (!haswell_broadwell_cpu) { 1119e82ddd28STal Shnaiderman sh->cmng.relaxed_ordering_write = 1120e82ddd28STal Shnaiderman config->hca_attr.relaxed_ordering_write; 1121e82ddd28STal Shnaiderman sh->cmng.relaxed_ordering_read = 1122e82ddd28STal Shnaiderman config->hca_attr.relaxed_ordering_read; 1123e82ddd28STal Shnaiderman } else { 1124e82ddd28STal Shnaiderman sh->cmng.relaxed_ordering_read = 0; 1125e82ddd28STal Shnaiderman sh->cmng.relaxed_ordering_write = 0; 1126e82ddd28STal Shnaiderman } 11272eb4d010SOphir Munk /* Check for LRO support. */ 1128d462a83cSMichael Baum if (config->dest_tir && config->hca_attr.lro_cap && 1129d462a83cSMichael Baum config->dv_flow_en) { 11302eb4d010SOphir Munk /* TBD check tunnel lro caps. */ 1131d462a83cSMichael Baum config->lro.supported = config->hca_attr.lro_cap; 11322eb4d010SOphir Munk DRV_LOG(DEBUG, "Device supports LRO"); 11332eb4d010SOphir Munk /* 11342eb4d010SOphir Munk * If LRO timeout is not configured by application, 11352eb4d010SOphir Munk * use the minimal supported value. 11362eb4d010SOphir Munk */ 1137d462a83cSMichael Baum if (!config->lro.timeout) 1138d462a83cSMichael Baum config->lro.timeout = 1139d462a83cSMichael Baum config->hca_attr.lro_timer_supported_periods[0]; 11402eb4d010SOphir Munk DRV_LOG(DEBUG, "LRO session timeout set to %d usec", 1141d462a83cSMichael Baum config->lro.timeout); 1142613d64e4SDekel Peled DRV_LOG(DEBUG, "LRO minimal size of TCP segment " 1143613d64e4SDekel Peled "required for coalescing is %d bytes", 1144613d64e4SDekel Peled config->hca_attr.lro_min_mss_size); 11452eb4d010SOphir Munk } 11462eb4d010SOphir Munk #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER) 1147d462a83cSMichael Baum if (config->hca_attr.qos.sup && 1148*b6505738SDekel Peled config->hca_attr.qos.flow_meter_old && 1149d462a83cSMichael Baum config->dv_flow_en) { 11502eb4d010SOphir Munk uint8_t reg_c_mask = 1151d462a83cSMichael Baum config->hca_attr.qos.flow_meter_reg_c_ids; 11522eb4d010SOphir Munk /* 11532eb4d010SOphir Munk * Meter needs two REG_C's for color match and pre-sfx 11542eb4d010SOphir Munk * flow match. Here get the REG_C for color match. 11552eb4d010SOphir Munk * REG_C_0 and REG_C_1 is reserved for metadata feature. 11562eb4d010SOphir Munk */ 11572eb4d010SOphir Munk reg_c_mask &= 0xfc; 11582eb4d010SOphir Munk if (__builtin_popcount(reg_c_mask) < 1) { 11592eb4d010SOphir Munk priv->mtr_en = 0; 11602eb4d010SOphir Munk DRV_LOG(WARNING, "No available register for" 11612eb4d010SOphir Munk " meter."); 11622eb4d010SOphir Munk } else { 116331ef2982SDekel Peled /* 116431ef2982SDekel Peled * The meter color register is used by the 116531ef2982SDekel Peled * flow-hit feature as well. 116631ef2982SDekel Peled * The flow-hit feature must use REG_C_3 116731ef2982SDekel Peled * Prefer REG_C_3 if it is available. 116831ef2982SDekel Peled */ 116931ef2982SDekel Peled if (reg_c_mask & (1 << (REG_C_3 - REG_C_0))) 117031ef2982SDekel Peled priv->mtr_color_reg = REG_C_3; 117131ef2982SDekel Peled else 117231ef2982SDekel Peled priv->mtr_color_reg = ffs(reg_c_mask) 117331ef2982SDekel Peled - 1 + REG_C_0; 11742eb4d010SOphir Munk priv->mtr_en = 1; 11752eb4d010SOphir Munk priv->mtr_reg_share = 1176*b6505738SDekel Peled config->hca_attr.qos.flow_meter; 11772eb4d010SOphir Munk DRV_LOG(DEBUG, "The REG_C meter uses is %d", 11782eb4d010SOphir Munk priv->mtr_color_reg); 11792eb4d010SOphir Munk } 11802eb4d010SOphir Munk } 11812eb4d010SOphir Munk #endif 1182a2999c7bSDekel Peled #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO 118331ef2982SDekel Peled if (config->hca_attr.flow_hit_aso && 118431ef2982SDekel Peled priv->mtr_color_reg == REG_C_3) { 118531ef2982SDekel Peled sh->flow_hit_aso_en = 1; 118631ef2982SDekel Peled err = mlx5_flow_aso_age_mng_init(sh); 118731ef2982SDekel Peled if (err) { 118831ef2982SDekel Peled err = -err; 118931ef2982SDekel Peled goto error; 119031ef2982SDekel Peled } 119131ef2982SDekel Peled DRV_LOG(DEBUG, "Flow Hit ASO is supported."); 119231ef2982SDekel Peled } 1193a2999c7bSDekel Peled #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ 119496b1f027SJiawei Wang #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE) 119596b1f027SJiawei Wang if (config->hca_attr.log_max_ft_sampler_num > 0 && 119696b1f027SJiawei Wang config->dv_flow_en) { 119796b1f027SJiawei Wang priv->sampler_en = 1; 119896b1f027SJiawei Wang DRV_LOG(DEBUG, "The Sampler enabled!\n"); 119996b1f027SJiawei Wang } else { 120096b1f027SJiawei Wang priv->sampler_en = 0; 120196b1f027SJiawei Wang if (!config->hca_attr.log_max_ft_sampler_num) 120296b1f027SJiawei Wang DRV_LOG(WARNING, "No available register for" 120396b1f027SJiawei Wang " Sampler."); 120496b1f027SJiawei Wang else 120596b1f027SJiawei Wang DRV_LOG(DEBUG, "DV flow is not supported!\n"); 120696b1f027SJiawei Wang } 120796b1f027SJiawei Wang #endif 12082eb4d010SOphir Munk } 1209d462a83cSMichael Baum if (config->tx_pp) { 12108f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz", 1211d462a83cSMichael Baum config->hca_attr.dev_freq_khz); 12128f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Packet pacing is %ssupported", 1213d462a83cSMichael Baum config->hca_attr.qos.packet_pacing ? "" : "not "); 12148f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Cross channel ops are %ssupported", 1215d462a83cSMichael Baum config->hca_attr.cross_channel ? "" : "not "); 12168f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "WQE index ignore is %ssupported", 1217d462a83cSMichael Baum config->hca_attr.wqe_index_ignore ? "" : "not "); 12188f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Non-wire SQ feature is %ssupported", 1219d462a83cSMichael Baum config->hca_attr.non_wire_sq ? "" : "not "); 12208f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Static WQE SQ feature is %ssupported (%d)", 1221d462a83cSMichael Baum config->hca_attr.log_max_static_sq_wq ? "" : "not ", 1222d462a83cSMichael Baum config->hca_attr.log_max_static_sq_wq); 12238f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "WQE rate PP mode is %ssupported", 1224d462a83cSMichael Baum config->hca_attr.qos.wqe_rate_pp ? "" : "not "); 1225d462a83cSMichael Baum if (!config->devx) { 12268f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "DevX is required for packet pacing"); 12278f848f32SViacheslav Ovsiienko err = ENODEV; 12288f848f32SViacheslav Ovsiienko goto error; 12298f848f32SViacheslav Ovsiienko } 1230d462a83cSMichael Baum if (!config->hca_attr.qos.packet_pacing) { 12318f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Packet pacing is not supported"); 12328f848f32SViacheslav Ovsiienko err = ENODEV; 12338f848f32SViacheslav Ovsiienko goto error; 12348f848f32SViacheslav Ovsiienko } 1235d462a83cSMichael Baum if (!config->hca_attr.cross_channel) { 12368f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Cross channel operations are" 12378f848f32SViacheslav Ovsiienko " required for packet pacing"); 12388f848f32SViacheslav Ovsiienko err = ENODEV; 12398f848f32SViacheslav Ovsiienko goto error; 12408f848f32SViacheslav Ovsiienko } 1241d462a83cSMichael Baum if (!config->hca_attr.wqe_index_ignore) { 12428f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "WQE index ignore feature is" 12438f848f32SViacheslav Ovsiienko " required for packet pacing"); 12448f848f32SViacheslav Ovsiienko err = ENODEV; 12458f848f32SViacheslav Ovsiienko goto error; 12468f848f32SViacheslav Ovsiienko } 1247d462a83cSMichael Baum if (!config->hca_attr.non_wire_sq) { 12488f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Non-wire SQ feature is" 12498f848f32SViacheslav Ovsiienko " required for packet pacing"); 12508f848f32SViacheslav Ovsiienko err = ENODEV; 12518f848f32SViacheslav Ovsiienko goto error; 12528f848f32SViacheslav Ovsiienko } 1253d462a83cSMichael Baum if (!config->hca_attr.log_max_static_sq_wq) { 12548f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Static WQE SQ feature is" 12558f848f32SViacheslav Ovsiienko " required for packet pacing"); 12568f848f32SViacheslav Ovsiienko err = ENODEV; 12578f848f32SViacheslav Ovsiienko goto error; 12588f848f32SViacheslav Ovsiienko } 1259d462a83cSMichael Baum if (!config->hca_attr.qos.wqe_rate_pp) { 12608f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "WQE rate mode is required" 12618f848f32SViacheslav Ovsiienko " for packet pacing"); 12628f848f32SViacheslav Ovsiienko err = ENODEV; 12638f848f32SViacheslav Ovsiienko goto error; 12648f848f32SViacheslav Ovsiienko } 12658f848f32SViacheslav Ovsiienko #ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET 12668f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "DevX does not provide UAR offset," 12678f848f32SViacheslav Ovsiienko " can't create queues for packet pacing"); 12688f848f32SViacheslav Ovsiienko err = ENODEV; 12698f848f32SViacheslav Ovsiienko goto error; 12708f848f32SViacheslav Ovsiienko #endif 12718f848f32SViacheslav Ovsiienko } 1272d462a83cSMichael Baum if (config->devx) { 1273a2854c4dSViacheslav Ovsiienko uint32_t reg[MLX5_ST_SZ_DW(register_mtutc)]; 1274a2854c4dSViacheslav Ovsiienko 1275972a1bf8SViacheslav Ovsiienko err = config->hca_attr.access_register_user ? 1276972a1bf8SViacheslav Ovsiienko mlx5_devx_cmd_register_read 1277a2854c4dSViacheslav Ovsiienko (sh->ctx, MLX5_REGISTER_ID_MTUTC, 0, 1278972a1bf8SViacheslav Ovsiienko reg, MLX5_ST_SZ_DW(register_mtutc)) : ENOTSUP; 1279a2854c4dSViacheslav Ovsiienko if (!err) { 1280a2854c4dSViacheslav Ovsiienko uint32_t ts_mode; 1281a2854c4dSViacheslav Ovsiienko 1282a2854c4dSViacheslav Ovsiienko /* MTUTC register is read successfully. */ 1283a2854c4dSViacheslav Ovsiienko ts_mode = MLX5_GET(register_mtutc, reg, 1284a2854c4dSViacheslav Ovsiienko time_stamp_mode); 1285a2854c4dSViacheslav Ovsiienko if (ts_mode == MLX5_MTUTC_TIMESTAMP_MODE_REAL_TIME) 1286d462a83cSMichael Baum config->rt_timestamp = 1; 1287a2854c4dSViacheslav Ovsiienko } else { 1288a2854c4dSViacheslav Ovsiienko /* Kernel does not support register reading. */ 1289d462a83cSMichael Baum if (config->hca_attr.dev_freq_khz == 1290a2854c4dSViacheslav Ovsiienko (NS_PER_S / MS_PER_S)) 1291d462a83cSMichael Baum config->rt_timestamp = 1; 1292a2854c4dSViacheslav Ovsiienko } 1293a2854c4dSViacheslav Ovsiienko } 129450f95b23SSuanming Mou /* 129550f95b23SSuanming Mou * If HW has bug working with tunnel packet decapsulation and 129650f95b23SSuanming Mou * scatter FCS, and decapsulation is needed, clear the hw_fcs_strip 129750f95b23SSuanming Mou * bit. Then DEV_RX_OFFLOAD_KEEP_CRC bit will not be set anymore. 129850f95b23SSuanming Mou */ 1299d462a83cSMichael Baum if (config->hca_attr.scatter_fcs_w_decap_disable && config->decap_en) 1300d462a83cSMichael Baum config->hw_fcs_strip = 0; 130150f95b23SSuanming Mou DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported", 1302d462a83cSMichael Baum (config->hw_fcs_strip ? "" : "not ")); 1303d462a83cSMichael Baum if (config->mprq.enabled && mprq) { 1304d462a83cSMichael Baum if (config->mprq.stride_num_n && 1305d462a83cSMichael Baum (config->mprq.stride_num_n > mprq_max_stride_num_n || 1306d462a83cSMichael Baum config->mprq.stride_num_n < mprq_min_stride_num_n)) { 1307d462a83cSMichael Baum config->mprq.stride_num_n = 13082eb4d010SOphir Munk RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_NUM_N, 13092eb4d010SOphir Munk mprq_min_stride_num_n), 13102eb4d010SOphir Munk mprq_max_stride_num_n); 13112eb4d010SOphir Munk DRV_LOG(WARNING, 13122eb4d010SOphir Munk "the number of strides" 13132eb4d010SOphir Munk " for Multi-Packet RQ is out of range," 13142eb4d010SOphir Munk " setting default value (%u)", 1315d462a83cSMichael Baum 1 << config->mprq.stride_num_n); 13162eb4d010SOphir Munk } 1317d462a83cSMichael Baum if (config->mprq.stride_size_n && 1318d462a83cSMichael Baum (config->mprq.stride_size_n > mprq_max_stride_size_n || 1319d462a83cSMichael Baum config->mprq.stride_size_n < mprq_min_stride_size_n)) { 1320d462a83cSMichael Baum config->mprq.stride_size_n = 13212eb4d010SOphir Munk RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_SIZE_N, 13222eb4d010SOphir Munk mprq_min_stride_size_n), 13232eb4d010SOphir Munk mprq_max_stride_size_n); 13242eb4d010SOphir Munk DRV_LOG(WARNING, 13252eb4d010SOphir Munk "the size of a stride" 13262eb4d010SOphir Munk " for Multi-Packet RQ is out of range," 13272eb4d010SOphir Munk " setting default value (%u)", 1328d462a83cSMichael Baum 1 << config->mprq.stride_size_n); 13292eb4d010SOphir Munk } 1330d462a83cSMichael Baum config->mprq.min_stride_size_n = mprq_min_stride_size_n; 1331d462a83cSMichael Baum config->mprq.max_stride_size_n = mprq_max_stride_size_n; 1332d462a83cSMichael Baum } else if (config->mprq.enabled && !mprq) { 13332eb4d010SOphir Munk DRV_LOG(WARNING, "Multi-Packet RQ isn't supported"); 1334d462a83cSMichael Baum config->mprq.enabled = 0; 13352eb4d010SOphir Munk } 1336d462a83cSMichael Baum if (config->max_dump_files_num == 0) 1337d462a83cSMichael Baum config->max_dump_files_num = 128; 13382eb4d010SOphir Munk eth_dev = rte_eth_dev_allocate(name); 13392eb4d010SOphir Munk if (eth_dev == NULL) { 13402eb4d010SOphir Munk DRV_LOG(ERR, "can not allocate rte ethdev"); 13412eb4d010SOphir Munk err = ENOMEM; 13422eb4d010SOphir Munk goto error; 13432eb4d010SOphir Munk } 13442eb4d010SOphir Munk if (priv->representor) { 13452eb4d010SOphir Munk eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; 13462eb4d010SOphir Munk eth_dev->data->representor_id = priv->representor_id; 13472eb4d010SOphir Munk } 134839ae7577SSuanming Mou priv->mp_id.port_id = eth_dev->data->port_id; 134939ae7577SSuanming Mou strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN); 13502eb4d010SOphir Munk /* 13512eb4d010SOphir Munk * Store associated network device interface index. This index 13522eb4d010SOphir Munk * is permanent throughout the lifetime of device. So, we may store 13532eb4d010SOphir Munk * the ifindex here and use the cached value further. 13542eb4d010SOphir Munk */ 13552eb4d010SOphir Munk MLX5_ASSERT(spawn->ifindex); 13562eb4d010SOphir Munk priv->if_index = spawn->ifindex; 1357c21e5facSXueming Li if (priv->pf_bond >= 0 && priv->master) { 1358c21e5facSXueming Li /* Get bond interface info */ 1359c21e5facSXueming Li err = mlx5_sysfs_bond_info(priv->if_index, 1360c21e5facSXueming Li &priv->bond_ifindex, 1361c21e5facSXueming Li priv->bond_name); 1362c21e5facSXueming Li if (err) 1363c21e5facSXueming Li DRV_LOG(ERR, "unable to get bond info: %s", 1364c21e5facSXueming Li strerror(rte_errno)); 1365c21e5facSXueming Li else 1366c21e5facSXueming Li DRV_LOG(INFO, "PF device %u, bond device %u(%s)", 1367c21e5facSXueming Li priv->if_index, priv->bond_ifindex, 1368c21e5facSXueming Li priv->bond_name); 1369c21e5facSXueming Li } 13702eb4d010SOphir Munk eth_dev->data->dev_private = priv; 13712eb4d010SOphir Munk priv->dev_data = eth_dev->data; 13722eb4d010SOphir Munk eth_dev->data->mac_addrs = priv->mac; 1373e6818853SXueming Li if (spawn->pf_bond < 0) { 13742eb4d010SOphir Munk eth_dev->device = dpdk_dev; 1375e6818853SXueming Li } else { 1376e6818853SXueming Li /* Use primary bond PCI as device. */ 1377e6818853SXueming Li if (sh->bond_dev == UINT16_MAX) { 1378e6818853SXueming Li sh->bond_dev = eth_dev->data->port_id; 1379e6818853SXueming Li eth_dev->device = dpdk_dev; 1380e6818853SXueming Li } else { 1381e6818853SXueming Li eth_dev->device = rte_eth_devices[sh->bond_dev].device; 1382e6818853SXueming Li } 1383e6818853SXueming Li } 1384f30e69b4SFerruh Yigit eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 13852eb4d010SOphir Munk /* Configure the first MAC address by default. */ 13862eb4d010SOphir Munk if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) { 13872eb4d010SOphir Munk DRV_LOG(ERR, 13882eb4d010SOphir Munk "port %u cannot get MAC address, is mlx5_en" 13892eb4d010SOphir Munk " loaded? (errno: %s)", 13902eb4d010SOphir Munk eth_dev->data->port_id, strerror(rte_errno)); 13912eb4d010SOphir Munk err = ENODEV; 13922eb4d010SOphir Munk goto error; 13932eb4d010SOphir Munk } 13942eb4d010SOphir Munk DRV_LOG(INFO, 13952eb4d010SOphir Munk "port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x", 13962eb4d010SOphir Munk eth_dev->data->port_id, 13972eb4d010SOphir Munk mac.addr_bytes[0], mac.addr_bytes[1], 13982eb4d010SOphir Munk mac.addr_bytes[2], mac.addr_bytes[3], 13992eb4d010SOphir Munk mac.addr_bytes[4], mac.addr_bytes[5]); 14002eb4d010SOphir Munk #ifdef RTE_LIBRTE_MLX5_DEBUG 14012eb4d010SOphir Munk { 140228743807STal Shnaiderman char ifname[MLX5_NAMESIZE]; 14032eb4d010SOphir Munk 14042eb4d010SOphir Munk if (mlx5_get_ifname(eth_dev, &ifname) == 0) 14052eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u ifname is \"%s\"", 14062eb4d010SOphir Munk eth_dev->data->port_id, ifname); 14072eb4d010SOphir Munk else 14082eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u ifname is unknown", 14092eb4d010SOphir Munk eth_dev->data->port_id); 14102eb4d010SOphir Munk } 14112eb4d010SOphir Munk #endif 14122eb4d010SOphir Munk /* Get actual MTU if possible. */ 14132eb4d010SOphir Munk err = mlx5_get_mtu(eth_dev, &priv->mtu); 14142eb4d010SOphir Munk if (err) { 14152eb4d010SOphir Munk err = rte_errno; 14162eb4d010SOphir Munk goto error; 14172eb4d010SOphir Munk } 14182eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u MTU is %u", eth_dev->data->port_id, 14192eb4d010SOphir Munk priv->mtu); 14202eb4d010SOphir Munk /* Initialize burst functions to prevent crashes before link-up. */ 14212eb4d010SOphir Munk eth_dev->rx_pkt_burst = removed_rx_burst; 14222eb4d010SOphir Munk eth_dev->tx_pkt_burst = removed_tx_burst; 1423b012b4ceSOphir Munk eth_dev->dev_ops = &mlx5_dev_ops; 1424cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 1425cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 1426cbfc6111SFerruh Yigit eth_dev->rx_queue_count = mlx5_rx_queue_count; 14272eb4d010SOphir Munk /* Register MAC address. */ 14282eb4d010SOphir Munk claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); 1429d462a83cSMichael Baum if (config->vf && config->vf_nl_en) 14302eb4d010SOphir Munk mlx5_nl_mac_addr_sync(priv->nl_socket_route, 14312eb4d010SOphir Munk mlx5_ifindex(eth_dev), 14322eb4d010SOphir Munk eth_dev->data->mac_addrs, 14332eb4d010SOphir Munk MLX5_MAX_MAC_ADDRESSES); 14342eb4d010SOphir Munk priv->flows = 0; 14352eb4d010SOphir Munk priv->ctrl_flows = 0; 1436d163fc2dSXueming Li rte_spinlock_init(&priv->flow_list_lock); 14372eb4d010SOphir Munk TAILQ_INIT(&priv->flow_meters); 14382eb4d010SOphir Munk TAILQ_INIT(&priv->flow_meter_profiles); 14392eb4d010SOphir Munk /* Hint libmlx5 to use PMD allocator for data plane resources */ 144036dabceaSMichael Baum mlx5_glue->dv_set_context_attr(sh->ctx, 144136dabceaSMichael Baum MLX5DV_CTX_ATTR_BUF_ALLOCATORS, 144236dabceaSMichael Baum (void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){ 14432eb4d010SOphir Munk .alloc = &mlx5_alloc_verbs_buf, 14442eb4d010SOphir Munk .free = &mlx5_free_verbs_buf, 144581c3b977SViacheslav Ovsiienko .data = sh, 144636dabceaSMichael Baum })); 14472eb4d010SOphir Munk /* Bring Ethernet device up. */ 14482eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u forcing Ethernet interface up", 14492eb4d010SOphir Munk eth_dev->data->port_id); 14502eb4d010SOphir Munk mlx5_set_link_up(eth_dev); 14512eb4d010SOphir Munk /* 14522eb4d010SOphir Munk * Even though the interrupt handler is not installed yet, 14532eb4d010SOphir Munk * interrupts will still trigger on the async_fd from 14542eb4d010SOphir Munk * Verbs context returned by ibv_open_device(). 14552eb4d010SOphir Munk */ 14562eb4d010SOphir Munk mlx5_link_update(eth_dev, 0); 14572eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 1458d462a83cSMichael Baum if (!(config->hca_attr.eswitch_manager && config->dv_flow_en && 14592eb4d010SOphir Munk (switch_info->representor || switch_info->master))) 1460d462a83cSMichael Baum config->dv_esw_en = 0; 14612eb4d010SOphir Munk #else 1462d462a83cSMichael Baum config->dv_esw_en = 0; 14632eb4d010SOphir Munk #endif 14642eb4d010SOphir Munk /* Detect minimal data bytes to inline. */ 1465d462a83cSMichael Baum mlx5_set_min_inline(spawn, config); 14662eb4d010SOphir Munk /* Store device configuration on private structure. */ 1467d462a83cSMichael Baum priv->config = *config; 14682eb4d010SOphir Munk /* Create context for virtual machine VLAN workaround. */ 14692eb4d010SOphir Munk priv->vmwa_context = mlx5_vlan_vmwa_init(eth_dev, spawn->ifindex); 1470d462a83cSMichael Baum if (config->dv_flow_en) { 14712eb4d010SOphir Munk err = mlx5_alloc_shared_dr(priv); 14722eb4d010SOphir Munk if (err) 14732eb4d010SOphir Munk goto error; 14742eb4d010SOphir Munk } 14757aa9892fSMichael Baum if (config->devx && config->dv_flow_en && config->dest_tir) { 14765eaf882eSMichael Baum priv->obj_ops = devx_obj_ops; 14770c762e81SMichael Baum priv->obj_ops.drop_action_create = 14780c762e81SMichael Baum ibv_obj_ops.drop_action_create; 14790c762e81SMichael Baum priv->obj_ops.drop_action_destroy = 14800c762e81SMichael Baum ibv_obj_ops.drop_action_destroy; 14815d9f3c3fSMichael Baum #ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET 14825d9f3c3fSMichael Baum priv->obj_ops.txq_obj_modify = ibv_obj_ops.txq_obj_modify; 14835d9f3c3fSMichael Baum #else 14843ec73abeSMatan Azrad if (config->dv_esw_en) 14855d9f3c3fSMichael Baum priv->obj_ops.txq_obj_modify = 14865d9f3c3fSMichael Baum ibv_obj_ops.txq_obj_modify; 14875d9f3c3fSMichael Baum #endif 14883ec73abeSMatan Azrad /* Use specific wrappers for Tx object. */ 14893ec73abeSMatan Azrad priv->obj_ops.txq_obj_new = mlx5_os_txq_obj_new; 14903ec73abeSMatan Azrad priv->obj_ops.txq_obj_release = mlx5_os_txq_obj_release; 14913ec73abeSMatan Azrad 14925eaf882eSMichael Baum } else { 14935eaf882eSMichael Baum priv->obj_ops = ibv_obj_ops; 14945eaf882eSMichael Baum } 149565b3cd0dSSuanming Mou priv->drop_queue.hrxq = mlx5_drop_action_create(eth_dev); 149665b3cd0dSSuanming Mou if (!priv->drop_queue.hrxq) 149765b3cd0dSSuanming Mou goto error; 14982eb4d010SOphir Munk /* Supported Verbs flow priority number detection. */ 14992eb4d010SOphir Munk err = mlx5_flow_discover_priorities(eth_dev); 15002eb4d010SOphir Munk if (err < 0) { 15012eb4d010SOphir Munk err = -err; 15022eb4d010SOphir Munk goto error; 15032eb4d010SOphir Munk } 15042eb4d010SOphir Munk priv->config.flow_prio = err; 15052eb4d010SOphir Munk if (!priv->config.dv_esw_en && 15062eb4d010SOphir Munk priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 15072eb4d010SOphir Munk DRV_LOG(WARNING, "metadata mode %u is not supported " 15082eb4d010SOphir Munk "(no E-Switch)", priv->config.dv_xmeta_en); 15092eb4d010SOphir Munk priv->config.dv_xmeta_en = MLX5_XMETA_MODE_LEGACY; 15102eb4d010SOphir Munk } 15112eb4d010SOphir Munk mlx5_set_metadata_mask(eth_dev); 15122eb4d010SOphir Munk if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 15132eb4d010SOphir Munk !priv->sh->dv_regc0_mask) { 15142eb4d010SOphir Munk DRV_LOG(ERR, "metadata mode %u is not supported " 15152eb4d010SOphir Munk "(no metadata reg_c[0] is available)", 15162eb4d010SOphir Munk priv->config.dv_xmeta_en); 15172eb4d010SOphir Munk err = ENOTSUP; 15182eb4d010SOphir Munk goto error; 15192eb4d010SOphir Munk } 1520e1592b6cSSuanming Mou mlx5_cache_list_init(&priv->hrxqs, "hrxq", 0, eth_dev, 1521e1592b6cSSuanming Mou mlx5_hrxq_create_cb, 1522e1592b6cSSuanming Mou mlx5_hrxq_match_cb, 1523e1592b6cSSuanming Mou mlx5_hrxq_remove_cb); 15242eb4d010SOphir Munk /* Query availability of metadata reg_c's. */ 15252eb4d010SOphir Munk err = mlx5_flow_discover_mreg_c(eth_dev); 15262eb4d010SOphir Munk if (err < 0) { 15272eb4d010SOphir Munk err = -err; 15282eb4d010SOphir Munk goto error; 15292eb4d010SOphir Munk } 15302eb4d010SOphir Munk if (!mlx5_flow_ext_mreg_supported(eth_dev)) { 15312eb4d010SOphir Munk DRV_LOG(DEBUG, 15322eb4d010SOphir Munk "port %u extensive metadata register is not supported", 15332eb4d010SOphir Munk eth_dev->data->port_id); 15342eb4d010SOphir Munk if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 15352eb4d010SOphir Munk DRV_LOG(ERR, "metadata mode %u is not supported " 15362eb4d010SOphir Munk "(no metadata registers available)", 15372eb4d010SOphir Munk priv->config.dv_xmeta_en); 15382eb4d010SOphir Munk err = ENOTSUP; 15392eb4d010SOphir Munk goto error; 15402eb4d010SOphir Munk } 15412eb4d010SOphir Munk } 15422eb4d010SOphir Munk if (priv->config.dv_flow_en && 15432eb4d010SOphir Munk priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 15442eb4d010SOphir Munk mlx5_flow_ext_mreg_supported(eth_dev) && 15452eb4d010SOphir Munk priv->sh->dv_regc0_mask) { 15462eb4d010SOphir Munk priv->mreg_cp_tbl = mlx5_hlist_create(MLX5_FLOW_MREG_HNAME, 1547e69a5922SXueming Li MLX5_FLOW_MREG_HTABLE_SZ, 1548e69a5922SXueming Li 0, 0, 1549f7f73ac1SXueming Li flow_dv_mreg_create_cb, 1550f5b0aed2SSuanming Mou flow_dv_mreg_match_cb, 1551f7f73ac1SXueming Li flow_dv_mreg_remove_cb); 15522eb4d010SOphir Munk if (!priv->mreg_cp_tbl) { 15532eb4d010SOphir Munk err = ENOMEM; 15542eb4d010SOphir Munk goto error; 15552eb4d010SOphir Munk } 1556f7f73ac1SXueming Li priv->mreg_cp_tbl->ctx = eth_dev; 15572eb4d010SOphir Munk } 1558cc608e4dSSuanming Mou rte_spinlock_init(&priv->shared_act_sl); 1559994829e6SSuanming Mou mlx5_flow_counter_mode_config(eth_dev); 15609fbe97f0SXueming Li if (priv->config.dv_flow_en) 15619fbe97f0SXueming Li eth_dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE; 15622eb4d010SOphir Munk return eth_dev; 15632eb4d010SOphir Munk error: 15642eb4d010SOphir Munk if (priv) { 15652eb4d010SOphir Munk if (priv->mreg_cp_tbl) 1566e69a5922SXueming Li mlx5_hlist_destroy(priv->mreg_cp_tbl); 15672eb4d010SOphir Munk if (priv->sh) 15682eb4d010SOphir Munk mlx5_os_free_shared_dr(priv); 15692eb4d010SOphir Munk if (priv->nl_socket_route >= 0) 15702eb4d010SOphir Munk close(priv->nl_socket_route); 15712eb4d010SOphir Munk if (priv->nl_socket_rdma >= 0) 15722eb4d010SOphir Munk close(priv->nl_socket_rdma); 15732eb4d010SOphir Munk if (priv->vmwa_context) 15742eb4d010SOphir Munk mlx5_vlan_vmwa_exit(priv->vmwa_context); 157565b3cd0dSSuanming Mou if (eth_dev && priv->drop_queue.hrxq) 157665b3cd0dSSuanming Mou mlx5_drop_action_destroy(eth_dev); 15772eb4d010SOphir Munk if (own_domain_id) 15782eb4d010SOphir Munk claim_zero(rte_eth_switch_domain_free(priv->domain_id)); 1579e1592b6cSSuanming Mou mlx5_cache_list_destroy(&priv->hrxqs); 15802175c4dcSSuanming Mou mlx5_free(priv); 15812eb4d010SOphir Munk if (eth_dev != NULL) 15822eb4d010SOphir Munk eth_dev->data->dev_private = NULL; 15832eb4d010SOphir Munk } 15842eb4d010SOphir Munk if (eth_dev != NULL) { 15852eb4d010SOphir Munk /* mac_addrs must not be freed alone because part of 15862eb4d010SOphir Munk * dev_private 15872eb4d010SOphir Munk **/ 15882eb4d010SOphir Munk eth_dev->data->mac_addrs = NULL; 15892eb4d010SOphir Munk rte_eth_dev_release_port(eth_dev); 15902eb4d010SOphir Munk } 15912eb4d010SOphir Munk if (sh) 159291389890SOphir Munk mlx5_free_shared_dev_ctx(sh); 15932eb4d010SOphir Munk MLX5_ASSERT(err > 0); 15942eb4d010SOphir Munk rte_errno = err; 15952eb4d010SOphir Munk return NULL; 15962eb4d010SOphir Munk } 15972eb4d010SOphir Munk 15982eb4d010SOphir Munk /** 15992eb4d010SOphir Munk * Comparison callback to sort device data. 16002eb4d010SOphir Munk * 16012eb4d010SOphir Munk * This is meant to be used with qsort(). 16022eb4d010SOphir Munk * 16032eb4d010SOphir Munk * @param a[in] 16042eb4d010SOphir Munk * Pointer to pointer to first data object. 16052eb4d010SOphir Munk * @param b[in] 16062eb4d010SOphir Munk * Pointer to pointer to second data object. 16072eb4d010SOphir Munk * 16082eb4d010SOphir Munk * @return 16092eb4d010SOphir Munk * 0 if both objects are equal, less than 0 if the first argument is less 16102eb4d010SOphir Munk * than the second, greater than 0 otherwise. 16112eb4d010SOphir Munk */ 16122eb4d010SOphir Munk static int 16132eb4d010SOphir Munk mlx5_dev_spawn_data_cmp(const void *a, const void *b) 16142eb4d010SOphir Munk { 16152eb4d010SOphir Munk const struct mlx5_switch_info *si_a = 16162eb4d010SOphir Munk &((const struct mlx5_dev_spawn_data *)a)->info; 16172eb4d010SOphir Munk const struct mlx5_switch_info *si_b = 16182eb4d010SOphir Munk &((const struct mlx5_dev_spawn_data *)b)->info; 16192eb4d010SOphir Munk int ret; 16202eb4d010SOphir Munk 16212eb4d010SOphir Munk /* Master device first. */ 16222eb4d010SOphir Munk ret = si_b->master - si_a->master; 16232eb4d010SOphir Munk if (ret) 16242eb4d010SOphir Munk return ret; 16252eb4d010SOphir Munk /* Then representor devices. */ 16262eb4d010SOphir Munk ret = si_b->representor - si_a->representor; 16272eb4d010SOphir Munk if (ret) 16282eb4d010SOphir Munk return ret; 16292eb4d010SOphir Munk /* Unidentified devices come last in no specific order. */ 16302eb4d010SOphir Munk if (!si_a->representor) 16312eb4d010SOphir Munk return 0; 16322eb4d010SOphir Munk /* Order representors by name. */ 16332eb4d010SOphir Munk return si_a->port_name - si_b->port_name; 16342eb4d010SOphir Munk } 16352eb4d010SOphir Munk 16362eb4d010SOphir Munk /** 16372eb4d010SOphir Munk * Match PCI information for possible slaves of bonding device. 16382eb4d010SOphir Munk * 16392eb4d010SOphir Munk * @param[in] ibv_dev 16402eb4d010SOphir Munk * Pointer to Infiniband device structure. 16412eb4d010SOphir Munk * @param[in] pci_dev 16422eb4d010SOphir Munk * Pointer to PCI device structure to match PCI address. 16432eb4d010SOphir Munk * @param[in] nl_rdma 16442eb4d010SOphir Munk * Netlink RDMA group socket handle. 16452eb4d010SOphir Munk * 16462eb4d010SOphir Munk * @return 16472eb4d010SOphir Munk * negative value if no bonding device found, otherwise 16482eb4d010SOphir Munk * positive index of slave PF in bonding. 16492eb4d010SOphir Munk */ 16502eb4d010SOphir Munk static int 16512eb4d010SOphir Munk mlx5_device_bond_pci_match(const struct ibv_device *ibv_dev, 16522eb4d010SOphir Munk const struct rte_pci_device *pci_dev, 16532eb4d010SOphir Munk int nl_rdma) 16542eb4d010SOphir Munk { 16552eb4d010SOphir Munk char ifname[IF_NAMESIZE + 1]; 16562eb4d010SOphir Munk unsigned int ifindex; 16572eb4d010SOphir Munk unsigned int np, i; 16582eb4d010SOphir Munk FILE *file = NULL; 16592eb4d010SOphir Munk int pf = -1; 16602eb4d010SOphir Munk 16612eb4d010SOphir Munk /* 16622eb4d010SOphir Munk * Try to get master device name. If something goes 16632eb4d010SOphir Munk * wrong suppose the lack of kernel support and no 16642eb4d010SOphir Munk * bonding devices. 16652eb4d010SOphir Munk */ 16662eb4d010SOphir Munk if (nl_rdma < 0) 16672eb4d010SOphir Munk return -1; 16682eb4d010SOphir Munk if (!strstr(ibv_dev->name, "bond")) 16692eb4d010SOphir Munk return -1; 16702eb4d010SOphir Munk np = mlx5_nl_portnum(nl_rdma, ibv_dev->name); 16712eb4d010SOphir Munk if (!np) 16722eb4d010SOphir Munk return -1; 16732eb4d010SOphir Munk /* 16742eb4d010SOphir Munk * The Master device might not be on the predefined 16752eb4d010SOphir Munk * port (not on port index 1, it is not garanted), 16762eb4d010SOphir Munk * we have to scan all Infiniband device port and 16772eb4d010SOphir Munk * find master. 16782eb4d010SOphir Munk */ 16792eb4d010SOphir Munk for (i = 1; i <= np; ++i) { 16802eb4d010SOphir Munk /* Check whether Infiniband port is populated. */ 16812eb4d010SOphir Munk ifindex = mlx5_nl_ifindex(nl_rdma, ibv_dev->name, i); 16822eb4d010SOphir Munk if (!ifindex) 16832eb4d010SOphir Munk continue; 16842eb4d010SOphir Munk if (!if_indextoname(ifindex, ifname)) 16852eb4d010SOphir Munk continue; 16862eb4d010SOphir Munk /* Try to read bonding slave names from sysfs. */ 16872eb4d010SOphir Munk MKSTR(slaves, 16882eb4d010SOphir Munk "/sys/class/net/%s/master/bonding/slaves", ifname); 16892eb4d010SOphir Munk file = fopen(slaves, "r"); 16902eb4d010SOphir Munk if (file) 16912eb4d010SOphir Munk break; 16922eb4d010SOphir Munk } 16932eb4d010SOphir Munk if (!file) 16942eb4d010SOphir Munk return -1; 16952eb4d010SOphir Munk /* Use safe format to check maximal buffer length. */ 16962eb4d010SOphir Munk MLX5_ASSERT(atol(RTE_STR(IF_NAMESIZE)) == IF_NAMESIZE); 16972eb4d010SOphir Munk while (fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", ifname) == 1) { 16982eb4d010SOphir Munk char tmp_str[IF_NAMESIZE + 32]; 16992eb4d010SOphir Munk struct rte_pci_addr pci_addr; 17002eb4d010SOphir Munk struct mlx5_switch_info info; 17012eb4d010SOphir Munk 17022eb4d010SOphir Munk /* Process slave interface names in the loop. */ 17032eb4d010SOphir Munk snprintf(tmp_str, sizeof(tmp_str), 17042eb4d010SOphir Munk "/sys/class/net/%s", ifname); 17052eb4d010SOphir Munk if (mlx5_dev_to_pci_addr(tmp_str, &pci_addr)) { 17062eb4d010SOphir Munk DRV_LOG(WARNING, "can not get PCI address" 17072eb4d010SOphir Munk " for netdev \"%s\"", ifname); 17082eb4d010SOphir Munk continue; 17092eb4d010SOphir Munk } 17102eb4d010SOphir Munk if (pci_dev->addr.domain != pci_addr.domain || 17112eb4d010SOphir Munk pci_dev->addr.bus != pci_addr.bus || 17122eb4d010SOphir Munk pci_dev->addr.devid != pci_addr.devid || 17132eb4d010SOphir Munk pci_dev->addr.function != pci_addr.function) 17142eb4d010SOphir Munk continue; 17152eb4d010SOphir Munk /* Slave interface PCI address match found. */ 17162eb4d010SOphir Munk fclose(file); 17172eb4d010SOphir Munk snprintf(tmp_str, sizeof(tmp_str), 17182eb4d010SOphir Munk "/sys/class/net/%s/phys_port_name", ifname); 17192eb4d010SOphir Munk file = fopen(tmp_str, "rb"); 17202eb4d010SOphir Munk if (!file) 17212eb4d010SOphir Munk break; 17222eb4d010SOphir Munk info.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET; 17232eb4d010SOphir Munk if (fscanf(file, "%32s", tmp_str) == 1) 17242eb4d010SOphir Munk mlx5_translate_port_name(tmp_str, &info); 17252eb4d010SOphir Munk if (info.name_type == MLX5_PHYS_PORT_NAME_TYPE_LEGACY || 17262eb4d010SOphir Munk info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK) 17272eb4d010SOphir Munk pf = info.port_name; 17282eb4d010SOphir Munk break; 17292eb4d010SOphir Munk } 17302eb4d010SOphir Munk if (file) 17312eb4d010SOphir Munk fclose(file); 17322eb4d010SOphir Munk return pf; 17332eb4d010SOphir Munk } 17342eb4d010SOphir Munk 17352eb4d010SOphir Munk /** 17362eb4d010SOphir Munk * DPDK callback to register a PCI device. 17372eb4d010SOphir Munk * 17382eb4d010SOphir Munk * This function spawns Ethernet devices out of a given PCI device. 17392eb4d010SOphir Munk * 17402eb4d010SOphir Munk * @param[in] pci_drv 17412eb4d010SOphir Munk * PCI driver structure (mlx5_driver). 17422eb4d010SOphir Munk * @param[in] pci_dev 17432eb4d010SOphir Munk * PCI device information. 17442eb4d010SOphir Munk * 17452eb4d010SOphir Munk * @return 17462eb4d010SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 17472eb4d010SOphir Munk */ 17482eb4d010SOphir Munk int 17492eb4d010SOphir Munk mlx5_os_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, 17502eb4d010SOphir Munk struct rte_pci_device *pci_dev) 17512eb4d010SOphir Munk { 17522eb4d010SOphir Munk struct ibv_device **ibv_list; 17532eb4d010SOphir Munk /* 17542eb4d010SOphir Munk * Number of found IB Devices matching with requested PCI BDF. 17552eb4d010SOphir Munk * nd != 1 means there are multiple IB devices over the same 17562eb4d010SOphir Munk * PCI device and we have representors and master. 17572eb4d010SOphir Munk */ 17582eb4d010SOphir Munk unsigned int nd = 0; 17592eb4d010SOphir Munk /* 17602eb4d010SOphir Munk * Number of found IB device Ports. nd = 1 and np = 1..n means 17612eb4d010SOphir Munk * we have the single multiport IB device, and there may be 17622eb4d010SOphir Munk * representors attached to some of found ports. 17632eb4d010SOphir Munk */ 17642eb4d010SOphir Munk unsigned int np = 0; 17652eb4d010SOphir Munk /* 17662eb4d010SOphir Munk * Number of DPDK ethernet devices to Spawn - either over 17672eb4d010SOphir Munk * multiple IB devices or multiple ports of single IB device. 17682eb4d010SOphir Munk * Actually this is the number of iterations to spawn. 17692eb4d010SOphir Munk */ 17702eb4d010SOphir Munk unsigned int ns = 0; 17712eb4d010SOphir Munk /* 17722eb4d010SOphir Munk * Bonding device 17732eb4d010SOphir Munk * < 0 - no bonding device (single one) 17742eb4d010SOphir Munk * >= 0 - bonding device (value is slave PF index) 17752eb4d010SOphir Munk */ 17762eb4d010SOphir Munk int bd = -1; 17772eb4d010SOphir Munk struct mlx5_dev_spawn_data *list = NULL; 17782eb4d010SOphir Munk struct mlx5_dev_config dev_config; 1779d462a83cSMichael Baum unsigned int dev_config_vf; 17802eb4d010SOphir Munk int ret; 17812eb4d010SOphir Munk 17822eb4d010SOphir Munk if (rte_eal_process_type() == RTE_PROC_PRIMARY) 17832eb4d010SOphir Munk mlx5_pmd_socket_init(); 17842eb4d010SOphir Munk ret = mlx5_init_once(); 17852eb4d010SOphir Munk if (ret) { 17862eb4d010SOphir Munk DRV_LOG(ERR, "unable to init PMD global data: %s", 17872eb4d010SOphir Munk strerror(rte_errno)); 17882eb4d010SOphir Munk return -rte_errno; 17892eb4d010SOphir Munk } 17902eb4d010SOphir Munk errno = 0; 17912eb4d010SOphir Munk ibv_list = mlx5_glue->get_device_list(&ret); 17922eb4d010SOphir Munk if (!ibv_list) { 17932eb4d010SOphir Munk rte_errno = errno ? errno : ENOSYS; 17942eb4d010SOphir Munk DRV_LOG(ERR, "cannot list devices, is ib_uverbs loaded?"); 17952eb4d010SOphir Munk return -rte_errno; 17962eb4d010SOphir Munk } 17972eb4d010SOphir Munk /* 17982eb4d010SOphir Munk * First scan the list of all Infiniband devices to find 17992eb4d010SOphir Munk * matching ones, gathering into the list. 18002eb4d010SOphir Munk */ 18012eb4d010SOphir Munk struct ibv_device *ibv_match[ret + 1]; 18022eb4d010SOphir Munk int nl_route = mlx5_nl_init(NETLINK_ROUTE); 18032eb4d010SOphir Munk int nl_rdma = mlx5_nl_init(NETLINK_RDMA); 18042eb4d010SOphir Munk unsigned int i; 18052eb4d010SOphir Munk 18062eb4d010SOphir Munk while (ret-- > 0) { 18072eb4d010SOphir Munk struct rte_pci_addr pci_addr; 18082eb4d010SOphir Munk 18092eb4d010SOphir Munk DRV_LOG(DEBUG, "checking device \"%s\"", ibv_list[ret]->name); 18102eb4d010SOphir Munk bd = mlx5_device_bond_pci_match 18112eb4d010SOphir Munk (ibv_list[ret], pci_dev, nl_rdma); 18122eb4d010SOphir Munk if (bd >= 0) { 18132eb4d010SOphir Munk /* 18142eb4d010SOphir Munk * Bonding device detected. Only one match is allowed, 18152eb4d010SOphir Munk * the bonding is supported over multi-port IB device, 18162eb4d010SOphir Munk * there should be no matches on representor PCI 18172eb4d010SOphir Munk * functions or non VF LAG bonding devices with 18182eb4d010SOphir Munk * specified address. 18192eb4d010SOphir Munk */ 18202eb4d010SOphir Munk if (nd) { 18212eb4d010SOphir Munk DRV_LOG(ERR, 18222eb4d010SOphir Munk "multiple PCI match on bonding device" 18232eb4d010SOphir Munk "\"%s\" found", ibv_list[ret]->name); 18242eb4d010SOphir Munk rte_errno = ENOENT; 18252eb4d010SOphir Munk ret = -rte_errno; 18262eb4d010SOphir Munk goto exit; 18272eb4d010SOphir Munk } 18282eb4d010SOphir Munk DRV_LOG(INFO, "PCI information matches for" 18292eb4d010SOphir Munk " slave %d bonding device \"%s\"", 18302eb4d010SOphir Munk bd, ibv_list[ret]->name); 18312eb4d010SOphir Munk ibv_match[nd++] = ibv_list[ret]; 18322eb4d010SOphir Munk break; 18332eb4d010SOphir Munk } 18342eb4d010SOphir Munk if (mlx5_dev_to_pci_addr 18352eb4d010SOphir Munk (ibv_list[ret]->ibdev_path, &pci_addr)) 18362eb4d010SOphir Munk continue; 18372eb4d010SOphir Munk if (pci_dev->addr.domain != pci_addr.domain || 18382eb4d010SOphir Munk pci_dev->addr.bus != pci_addr.bus || 18392eb4d010SOphir Munk pci_dev->addr.devid != pci_addr.devid || 18402eb4d010SOphir Munk pci_dev->addr.function != pci_addr.function) 18412eb4d010SOphir Munk continue; 18422eb4d010SOphir Munk DRV_LOG(INFO, "PCI information matches for device \"%s\"", 18432eb4d010SOphir Munk ibv_list[ret]->name); 18442eb4d010SOphir Munk ibv_match[nd++] = ibv_list[ret]; 18452eb4d010SOphir Munk } 18462eb4d010SOphir Munk ibv_match[nd] = NULL; 18472eb4d010SOphir Munk if (!nd) { 18482eb4d010SOphir Munk /* No device matches, just complain and bail out. */ 18492eb4d010SOphir Munk DRV_LOG(WARNING, 18502eb4d010SOphir Munk "no Verbs device matches PCI device " PCI_PRI_FMT "," 18512eb4d010SOphir Munk " are kernel drivers loaded?", 18522eb4d010SOphir Munk pci_dev->addr.domain, pci_dev->addr.bus, 18532eb4d010SOphir Munk pci_dev->addr.devid, pci_dev->addr.function); 18542eb4d010SOphir Munk rte_errno = ENOENT; 18552eb4d010SOphir Munk ret = -rte_errno; 18562eb4d010SOphir Munk goto exit; 18572eb4d010SOphir Munk } 18582eb4d010SOphir Munk if (nd == 1) { 18592eb4d010SOphir Munk /* 18602eb4d010SOphir Munk * Found single matching device may have multiple ports. 18612eb4d010SOphir Munk * Each port may be representor, we have to check the port 18622eb4d010SOphir Munk * number and check the representors existence. 18632eb4d010SOphir Munk */ 18642eb4d010SOphir Munk if (nl_rdma >= 0) 18652eb4d010SOphir Munk np = mlx5_nl_portnum(nl_rdma, ibv_match[0]->name); 18662eb4d010SOphir Munk if (!np) 18672eb4d010SOphir Munk DRV_LOG(WARNING, "can not get IB device \"%s\"" 18682eb4d010SOphir Munk " ports number", ibv_match[0]->name); 18692eb4d010SOphir Munk if (bd >= 0 && !np) { 18702eb4d010SOphir Munk DRV_LOG(ERR, "can not get ports" 18712eb4d010SOphir Munk " for bonding device"); 18722eb4d010SOphir Munk rte_errno = ENOENT; 18732eb4d010SOphir Munk ret = -rte_errno; 18742eb4d010SOphir Munk goto exit; 18752eb4d010SOphir Munk } 18762eb4d010SOphir Munk } 18772eb4d010SOphir Munk #ifndef HAVE_MLX5DV_DR_DEVX_PORT 18782eb4d010SOphir Munk if (bd >= 0) { 18792eb4d010SOphir Munk /* 18802eb4d010SOphir Munk * This may happen if there is VF LAG kernel support and 18812eb4d010SOphir Munk * application is compiled with older rdma_core library. 18822eb4d010SOphir Munk */ 18832eb4d010SOphir Munk DRV_LOG(ERR, 18842eb4d010SOphir Munk "No kernel/verbs support for VF LAG bonding found."); 18852eb4d010SOphir Munk rte_errno = ENOTSUP; 18862eb4d010SOphir Munk ret = -rte_errno; 18872eb4d010SOphir Munk goto exit; 18882eb4d010SOphir Munk } 18892eb4d010SOphir Munk #endif 18902eb4d010SOphir Munk /* 18912eb4d010SOphir Munk * Now we can determine the maximal 18922eb4d010SOphir Munk * amount of devices to be spawned. 18932eb4d010SOphir Munk */ 18942175c4dcSSuanming Mou list = mlx5_malloc(MLX5_MEM_ZERO, 18952eb4d010SOphir Munk sizeof(struct mlx5_dev_spawn_data) * 18962eb4d010SOphir Munk (np ? np : nd), 18972175c4dcSSuanming Mou RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 18982eb4d010SOphir Munk if (!list) { 18992eb4d010SOphir Munk DRV_LOG(ERR, "spawn data array allocation failure"); 19002eb4d010SOphir Munk rte_errno = ENOMEM; 19012eb4d010SOphir Munk ret = -rte_errno; 19022eb4d010SOphir Munk goto exit; 19032eb4d010SOphir Munk } 19042eb4d010SOphir Munk if (bd >= 0 || np > 1) { 19052eb4d010SOphir Munk /* 19062eb4d010SOphir Munk * Single IB device with multiple ports found, 19072eb4d010SOphir Munk * it may be E-Switch master device and representors. 19082eb4d010SOphir Munk * We have to perform identification through the ports. 19092eb4d010SOphir Munk */ 19102eb4d010SOphir Munk MLX5_ASSERT(nl_rdma >= 0); 19112eb4d010SOphir Munk MLX5_ASSERT(ns == 0); 19122eb4d010SOphir Munk MLX5_ASSERT(nd == 1); 19132eb4d010SOphir Munk MLX5_ASSERT(np); 19142eb4d010SOphir Munk for (i = 1; i <= np; ++i) { 19152eb4d010SOphir Munk list[ns].max_port = np; 1916834a9019SOphir Munk list[ns].phys_port = i; 1917834a9019SOphir Munk list[ns].phys_dev = ibv_match[0]; 19182eb4d010SOphir Munk list[ns].eth_dev = NULL; 19192eb4d010SOphir Munk list[ns].pci_dev = pci_dev; 19202eb4d010SOphir Munk list[ns].pf_bond = bd; 19212eb4d010SOphir Munk list[ns].ifindex = mlx5_nl_ifindex 1922834a9019SOphir Munk (nl_rdma, 1923834a9019SOphir Munk mlx5_os_get_dev_device_name 1924834a9019SOphir Munk (list[ns].phys_dev), i); 19252eb4d010SOphir Munk if (!list[ns].ifindex) { 19262eb4d010SOphir Munk /* 19272eb4d010SOphir Munk * No network interface index found for the 19282eb4d010SOphir Munk * specified port, it means there is no 19292eb4d010SOphir Munk * representor on this port. It's OK, 19302eb4d010SOphir Munk * there can be disabled ports, for example 19312eb4d010SOphir Munk * if sriov_numvfs < sriov_totalvfs. 19322eb4d010SOphir Munk */ 19332eb4d010SOphir Munk continue; 19342eb4d010SOphir Munk } 19352eb4d010SOphir Munk ret = -1; 19362eb4d010SOphir Munk if (nl_route >= 0) 19372eb4d010SOphir Munk ret = mlx5_nl_switch_info 19382eb4d010SOphir Munk (nl_route, 19392eb4d010SOphir Munk list[ns].ifindex, 19402eb4d010SOphir Munk &list[ns].info); 19412eb4d010SOphir Munk if (ret || (!list[ns].info.representor && 19422eb4d010SOphir Munk !list[ns].info.master)) { 19432eb4d010SOphir Munk /* 19442eb4d010SOphir Munk * We failed to recognize representors with 19452eb4d010SOphir Munk * Netlink, let's try to perform the task 19462eb4d010SOphir Munk * with sysfs. 19472eb4d010SOphir Munk */ 19482eb4d010SOphir Munk ret = mlx5_sysfs_switch_info 19492eb4d010SOphir Munk (list[ns].ifindex, 19502eb4d010SOphir Munk &list[ns].info); 19512eb4d010SOphir Munk } 19522a87415cSMichael Baum #ifdef HAVE_MLX5DV_DR_DEVX_PORT 19532eb4d010SOphir Munk if (!ret && bd >= 0) { 19542eb4d010SOphir Munk switch (list[ns].info.name_type) { 19552eb4d010SOphir Munk case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: 19562eb4d010SOphir Munk if (list[ns].info.port_name == bd) 19572eb4d010SOphir Munk ns++; 19582eb4d010SOphir Munk break; 1959420bbdaeSViacheslav Ovsiienko case MLX5_PHYS_PORT_NAME_TYPE_PFHPF: 1960420bbdaeSViacheslav Ovsiienko /* Fallthrough */ 19612eb4d010SOphir Munk case MLX5_PHYS_PORT_NAME_TYPE_PFVF: 19622eb4d010SOphir Munk if (list[ns].info.pf_num == bd) 19632eb4d010SOphir Munk ns++; 19642eb4d010SOphir Munk break; 19652eb4d010SOphir Munk default: 19662eb4d010SOphir Munk break; 19672eb4d010SOphir Munk } 19682eb4d010SOphir Munk continue; 19692eb4d010SOphir Munk } 19702a87415cSMichael Baum #endif 19712eb4d010SOphir Munk if (!ret && (list[ns].info.representor ^ 19722eb4d010SOphir Munk list[ns].info.master)) 19732eb4d010SOphir Munk ns++; 19742eb4d010SOphir Munk } 19752eb4d010SOphir Munk if (!ns) { 19762eb4d010SOphir Munk DRV_LOG(ERR, 19772eb4d010SOphir Munk "unable to recognize master/representors" 19782eb4d010SOphir Munk " on the IB device with multiple ports"); 19792eb4d010SOphir Munk rte_errno = ENOENT; 19802eb4d010SOphir Munk ret = -rte_errno; 19812eb4d010SOphir Munk goto exit; 19822eb4d010SOphir Munk } 19832eb4d010SOphir Munk } else { 19842eb4d010SOphir Munk /* 19852eb4d010SOphir Munk * The existence of several matching entries (nd > 1) means 19862eb4d010SOphir Munk * port representors have been instantiated. No existing Verbs 19872eb4d010SOphir Munk * call nor sysfs entries can tell them apart, this can only 19882eb4d010SOphir Munk * be done through Netlink calls assuming kernel drivers are 19892eb4d010SOphir Munk * recent enough to support them. 19902eb4d010SOphir Munk * 19912eb4d010SOphir Munk * In the event of identification failure through Netlink, 19922eb4d010SOphir Munk * try again through sysfs, then: 19932eb4d010SOphir Munk * 19942eb4d010SOphir Munk * 1. A single IB device matches (nd == 1) with single 19952eb4d010SOphir Munk * port (np=0/1) and is not a representor, assume 19962eb4d010SOphir Munk * no switch support. 19972eb4d010SOphir Munk * 19982eb4d010SOphir Munk * 2. Otherwise no safe assumptions can be made; 19992eb4d010SOphir Munk * complain louder and bail out. 20002eb4d010SOphir Munk */ 20012eb4d010SOphir Munk for (i = 0; i != nd; ++i) { 20022eb4d010SOphir Munk memset(&list[ns].info, 0, sizeof(list[ns].info)); 20032eb4d010SOphir Munk list[ns].max_port = 1; 2004834a9019SOphir Munk list[ns].phys_port = 1; 2005834a9019SOphir Munk list[ns].phys_dev = ibv_match[i]; 20062eb4d010SOphir Munk list[ns].eth_dev = NULL; 20072eb4d010SOphir Munk list[ns].pci_dev = pci_dev; 20082eb4d010SOphir Munk list[ns].pf_bond = -1; 20092eb4d010SOphir Munk list[ns].ifindex = 0; 20102eb4d010SOphir Munk if (nl_rdma >= 0) 20112eb4d010SOphir Munk list[ns].ifindex = mlx5_nl_ifindex 2012834a9019SOphir Munk (nl_rdma, 2013834a9019SOphir Munk mlx5_os_get_dev_device_name 2014834a9019SOphir Munk (list[ns].phys_dev), 1); 20152eb4d010SOphir Munk if (!list[ns].ifindex) { 20162eb4d010SOphir Munk char ifname[IF_NAMESIZE]; 20172eb4d010SOphir Munk 20182eb4d010SOphir Munk /* 20192eb4d010SOphir Munk * Netlink failed, it may happen with old 20202eb4d010SOphir Munk * ib_core kernel driver (before 4.16). 20212eb4d010SOphir Munk * We can assume there is old driver because 20222eb4d010SOphir Munk * here we are processing single ports IB 20232eb4d010SOphir Munk * devices. Let's try sysfs to retrieve 20242eb4d010SOphir Munk * the ifindex. The method works for 20252eb4d010SOphir Munk * master device only. 20262eb4d010SOphir Munk */ 20272eb4d010SOphir Munk if (nd > 1) { 20282eb4d010SOphir Munk /* 20292eb4d010SOphir Munk * Multiple devices found, assume 20302eb4d010SOphir Munk * representors, can not distinguish 20312eb4d010SOphir Munk * master/representor and retrieve 20322eb4d010SOphir Munk * ifindex via sysfs. 20332eb4d010SOphir Munk */ 20342eb4d010SOphir Munk continue; 20352eb4d010SOphir Munk } 2036aec086c9SMatan Azrad ret = mlx5_get_ifname_sysfs 2037aec086c9SMatan Azrad (ibv_match[i]->ibdev_path, ifname); 20382eb4d010SOphir Munk if (!ret) 20392eb4d010SOphir Munk list[ns].ifindex = 20402eb4d010SOphir Munk if_nametoindex(ifname); 20412eb4d010SOphir Munk if (!list[ns].ifindex) { 20422eb4d010SOphir Munk /* 20432eb4d010SOphir Munk * No network interface index found 20442eb4d010SOphir Munk * for the specified device, it means 20452eb4d010SOphir Munk * there it is neither representor 20462eb4d010SOphir Munk * nor master. 20472eb4d010SOphir Munk */ 20482eb4d010SOphir Munk continue; 20492eb4d010SOphir Munk } 20502eb4d010SOphir Munk } 20512eb4d010SOphir Munk ret = -1; 20522eb4d010SOphir Munk if (nl_route >= 0) 20532eb4d010SOphir Munk ret = mlx5_nl_switch_info 20542eb4d010SOphir Munk (nl_route, 20552eb4d010SOphir Munk list[ns].ifindex, 20562eb4d010SOphir Munk &list[ns].info); 20572eb4d010SOphir Munk if (ret || (!list[ns].info.representor && 20582eb4d010SOphir Munk !list[ns].info.master)) { 20592eb4d010SOphir Munk /* 20602eb4d010SOphir Munk * We failed to recognize representors with 20612eb4d010SOphir Munk * Netlink, let's try to perform the task 20622eb4d010SOphir Munk * with sysfs. 20632eb4d010SOphir Munk */ 20642eb4d010SOphir Munk ret = mlx5_sysfs_switch_info 20652eb4d010SOphir Munk (list[ns].ifindex, 20662eb4d010SOphir Munk &list[ns].info); 20672eb4d010SOphir Munk } 20682eb4d010SOphir Munk if (!ret && (list[ns].info.representor ^ 20692eb4d010SOphir Munk list[ns].info.master)) { 20702eb4d010SOphir Munk ns++; 20712eb4d010SOphir Munk } else if ((nd == 1) && 20722eb4d010SOphir Munk !list[ns].info.representor && 20732eb4d010SOphir Munk !list[ns].info.master) { 20742eb4d010SOphir Munk /* 20752eb4d010SOphir Munk * Single IB device with 20762eb4d010SOphir Munk * one physical port and 20772eb4d010SOphir Munk * attached network device. 20782eb4d010SOphir Munk * May be SRIOV is not enabled 20792eb4d010SOphir Munk * or there is no representors. 20802eb4d010SOphir Munk */ 20812eb4d010SOphir Munk DRV_LOG(INFO, "no E-Switch support detected"); 20822eb4d010SOphir Munk ns++; 20832eb4d010SOphir Munk break; 20842eb4d010SOphir Munk } 20852eb4d010SOphir Munk } 20862eb4d010SOphir Munk if (!ns) { 20872eb4d010SOphir Munk DRV_LOG(ERR, 20882eb4d010SOphir Munk "unable to recognize master/representors" 20892eb4d010SOphir Munk " on the multiple IB devices"); 20902eb4d010SOphir Munk rte_errno = ENOENT; 20912eb4d010SOphir Munk ret = -rte_errno; 20922eb4d010SOphir Munk goto exit; 20932eb4d010SOphir Munk } 20942eb4d010SOphir Munk } 20952eb4d010SOphir Munk MLX5_ASSERT(ns); 20962eb4d010SOphir Munk /* 20972eb4d010SOphir Munk * Sort list to probe devices in natural order for users convenience 20982eb4d010SOphir Munk * (i.e. master first, then representors from lowest to highest ID). 20992eb4d010SOphir Munk */ 21002eb4d010SOphir Munk qsort(list, ns, sizeof(*list), mlx5_dev_spawn_data_cmp); 21012eb4d010SOphir Munk /* Device specific configuration. */ 21022eb4d010SOphir Munk switch (pci_dev->id.device_id) { 21032eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF: 21042eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF: 21052eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF: 21062eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF: 21072eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF: 21082eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX6VF: 21093ea12cadSRaslan Darawsheh case PCI_DEVICE_ID_MELLANOX_CONNECTXVF: 2110d462a83cSMichael Baum dev_config_vf = 1; 21112eb4d010SOphir Munk break; 21122eb4d010SOphir Munk default: 2113d462a83cSMichael Baum dev_config_vf = 0; 21142eb4d010SOphir Munk break; 21152eb4d010SOphir Munk } 21162eb4d010SOphir Munk for (i = 0; i != ns; ++i) { 21172eb4d010SOphir Munk uint32_t restore; 21182eb4d010SOphir Munk 2119d462a83cSMichael Baum /* Default configuration. */ 2120d462a83cSMichael Baum memset(&dev_config, 0, sizeof(struct mlx5_dev_config)); 2121d462a83cSMichael Baum dev_config.vf = dev_config_vf; 2122d462a83cSMichael Baum dev_config.mps = MLX5_ARG_UNSET; 2123d462a83cSMichael Baum dev_config.dbnc = MLX5_ARG_UNSET; 2124d462a83cSMichael Baum dev_config.rx_vec_en = 1; 2125d462a83cSMichael Baum dev_config.txq_inline_max = MLX5_ARG_UNSET; 2126d462a83cSMichael Baum dev_config.txq_inline_min = MLX5_ARG_UNSET; 2127d462a83cSMichael Baum dev_config.txq_inline_mpw = MLX5_ARG_UNSET; 2128d462a83cSMichael Baum dev_config.txqs_inline = MLX5_ARG_UNSET; 2129d462a83cSMichael Baum dev_config.vf_nl_en = 1; 2130d462a83cSMichael Baum dev_config.mr_ext_memseg_en = 1; 2131d462a83cSMichael Baum dev_config.mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN; 2132d462a83cSMichael Baum dev_config.mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS; 2133d462a83cSMichael Baum dev_config.dv_esw_en = 1; 2134d462a83cSMichael Baum dev_config.dv_flow_en = 1; 2135d462a83cSMichael Baum dev_config.decap_en = 1; 2136d462a83cSMichael Baum dev_config.log_hp_size = MLX5_ARG_UNSET; 21372eb4d010SOphir Munk list[i].eth_dev = mlx5_dev_spawn(&pci_dev->device, 21382eb4d010SOphir Munk &list[i], 2139d462a83cSMichael Baum &dev_config); 21402eb4d010SOphir Munk if (!list[i].eth_dev) { 21412eb4d010SOphir Munk if (rte_errno != EBUSY && rte_errno != EEXIST) 21422eb4d010SOphir Munk break; 21432eb4d010SOphir Munk /* Device is disabled or already spawned. Ignore it. */ 21442eb4d010SOphir Munk continue; 21452eb4d010SOphir Munk } 21462eb4d010SOphir Munk restore = list[i].eth_dev->data->dev_flags; 21472eb4d010SOphir Munk rte_eth_copy_pci_info(list[i].eth_dev, pci_dev); 21482eb4d010SOphir Munk /* Restore non-PCI flags cleared by the above call. */ 21492eb4d010SOphir Munk list[i].eth_dev->data->dev_flags |= restore; 21502eb4d010SOphir Munk rte_eth_dev_probing_finish(list[i].eth_dev); 21512eb4d010SOphir Munk } 21522eb4d010SOphir Munk if (i != ns) { 21532eb4d010SOphir Munk DRV_LOG(ERR, 21542eb4d010SOphir Munk "probe of PCI device " PCI_PRI_FMT " aborted after" 21552eb4d010SOphir Munk " encountering an error: %s", 21562eb4d010SOphir Munk pci_dev->addr.domain, pci_dev->addr.bus, 21572eb4d010SOphir Munk pci_dev->addr.devid, pci_dev->addr.function, 21582eb4d010SOphir Munk strerror(rte_errno)); 21592eb4d010SOphir Munk ret = -rte_errno; 21602eb4d010SOphir Munk /* Roll back. */ 21612eb4d010SOphir Munk while (i--) { 21622eb4d010SOphir Munk if (!list[i].eth_dev) 21632eb4d010SOphir Munk continue; 21642eb4d010SOphir Munk mlx5_dev_close(list[i].eth_dev); 21652eb4d010SOphir Munk /* mac_addrs must not be freed because in dev_private */ 21662eb4d010SOphir Munk list[i].eth_dev->data->mac_addrs = NULL; 21672eb4d010SOphir Munk claim_zero(rte_eth_dev_release_port(list[i].eth_dev)); 21682eb4d010SOphir Munk } 21692eb4d010SOphir Munk /* Restore original error. */ 21702eb4d010SOphir Munk rte_errno = -ret; 21712eb4d010SOphir Munk } else { 21722eb4d010SOphir Munk ret = 0; 21732eb4d010SOphir Munk } 21742eb4d010SOphir Munk exit: 21752eb4d010SOphir Munk /* 21762eb4d010SOphir Munk * Do the routine cleanup: 21772eb4d010SOphir Munk * - close opened Netlink sockets 21782eb4d010SOphir Munk * - free allocated spawn data array 21792eb4d010SOphir Munk * - free the Infiniband device list 21802eb4d010SOphir Munk */ 21812eb4d010SOphir Munk if (nl_rdma >= 0) 21822eb4d010SOphir Munk close(nl_rdma); 21832eb4d010SOphir Munk if (nl_route >= 0) 21842eb4d010SOphir Munk close(nl_route); 21852eb4d010SOphir Munk if (list) 21862175c4dcSSuanming Mou mlx5_free(list); 21872eb4d010SOphir Munk MLX5_ASSERT(ibv_list); 21882eb4d010SOphir Munk mlx5_glue->free_device_list(ibv_list); 21892eb4d010SOphir Munk return ret; 21902eb4d010SOphir Munk } 21912eb4d010SOphir Munk 21922eb4d010SOphir Munk static int 21932eb4d010SOphir Munk mlx5_config_doorbell_mapping_env(const struct mlx5_dev_config *config) 21942eb4d010SOphir Munk { 21952eb4d010SOphir Munk char *env; 21962eb4d010SOphir Munk int value; 21972eb4d010SOphir Munk 21982eb4d010SOphir Munk MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); 21992eb4d010SOphir Munk /* Get environment variable to store. */ 22002eb4d010SOphir Munk env = getenv(MLX5_SHUT_UP_BF); 22012eb4d010SOphir Munk value = env ? !!strcmp(env, "0") : MLX5_ARG_UNSET; 22022eb4d010SOphir Munk if (config->dbnc == MLX5_ARG_UNSET) 22032eb4d010SOphir Munk setenv(MLX5_SHUT_UP_BF, MLX5_SHUT_UP_BF_DEFAULT, 1); 22042eb4d010SOphir Munk else 22052eb4d010SOphir Munk setenv(MLX5_SHUT_UP_BF, 22062eb4d010SOphir Munk config->dbnc == MLX5_TXDB_NCACHED ? "1" : "0", 1); 22072eb4d010SOphir Munk return value; 22082eb4d010SOphir Munk } 22092eb4d010SOphir Munk 22102eb4d010SOphir Munk static void 22112eb4d010SOphir Munk mlx5_restore_doorbell_mapping_env(int value) 22122eb4d010SOphir Munk { 22132eb4d010SOphir Munk MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); 22142eb4d010SOphir Munk /* Restore the original environment variable state. */ 22152eb4d010SOphir Munk if (value == MLX5_ARG_UNSET) 22162eb4d010SOphir Munk unsetenv(MLX5_SHUT_UP_BF); 22172eb4d010SOphir Munk else 22182eb4d010SOphir Munk setenv(MLX5_SHUT_UP_BF, value ? "1" : "0", 1); 22192eb4d010SOphir Munk } 22202eb4d010SOphir Munk 22212eb4d010SOphir Munk /** 22222eb4d010SOphir Munk * Extract pdn of PD object using DV API. 22232eb4d010SOphir Munk * 22242eb4d010SOphir Munk * @param[in] pd 22252eb4d010SOphir Munk * Pointer to the verbs PD object. 22262eb4d010SOphir Munk * @param[out] pdn 22272eb4d010SOphir Munk * Pointer to the PD object number variable. 22282eb4d010SOphir Munk * 22292eb4d010SOphir Munk * @return 22302eb4d010SOphir Munk * 0 on success, error value otherwise. 22312eb4d010SOphir Munk */ 22322eb4d010SOphir Munk int 22332eb4d010SOphir Munk mlx5_os_get_pdn(void *pd, uint32_t *pdn) 22342eb4d010SOphir Munk { 22352eb4d010SOphir Munk #ifdef HAVE_IBV_FLOW_DV_SUPPORT 22362eb4d010SOphir Munk struct mlx5dv_obj obj; 22372eb4d010SOphir Munk struct mlx5dv_pd pd_info; 22382eb4d010SOphir Munk int ret = 0; 22392eb4d010SOphir Munk 22402eb4d010SOphir Munk obj.pd.in = pd; 22412eb4d010SOphir Munk obj.pd.out = &pd_info; 22422eb4d010SOphir Munk ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD); 22432eb4d010SOphir Munk if (ret) { 22442eb4d010SOphir Munk DRV_LOG(DEBUG, "Fail to get PD object info"); 22452eb4d010SOphir Munk return ret; 22462eb4d010SOphir Munk } 22472eb4d010SOphir Munk *pdn = pd_info.pdn; 22482eb4d010SOphir Munk return 0; 22492eb4d010SOphir Munk #else 22502eb4d010SOphir Munk (void)pd; 22512eb4d010SOphir Munk (void)pdn; 22522eb4d010SOphir Munk return -ENOTSUP; 22532eb4d010SOphir Munk #endif /* HAVE_IBV_FLOW_DV_SUPPORT */ 22542eb4d010SOphir Munk } 22552eb4d010SOphir Munk 22562eb4d010SOphir Munk /** 22572eb4d010SOphir Munk * Function API to open IB device. 22582eb4d010SOphir Munk * 22592eb4d010SOphir Munk * This function calls the Linux glue APIs to open a device. 22602eb4d010SOphir Munk * 22612eb4d010SOphir Munk * @param[in] spawn 22622eb4d010SOphir Munk * Pointer to the IB device attributes (name, port, etc). 22632eb4d010SOphir Munk * @param[out] config 22642eb4d010SOphir Munk * Pointer to device configuration structure. 22652eb4d010SOphir Munk * @param[out] sh 22662eb4d010SOphir Munk * Pointer to shared context structure. 22672eb4d010SOphir Munk * 22682eb4d010SOphir Munk * @return 22692eb4d010SOphir Munk * 0 on success, a positive error value otherwise. 22702eb4d010SOphir Munk */ 22712eb4d010SOphir Munk int 22722eb4d010SOphir Munk mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn, 22732eb4d010SOphir Munk const struct mlx5_dev_config *config, 22742eb4d010SOphir Munk struct mlx5_dev_ctx_shared *sh) 22752eb4d010SOphir Munk { 22762eb4d010SOphir Munk int dbmap_env; 22772eb4d010SOphir Munk int err = 0; 2278d133f4cdSViacheslav Ovsiienko 2279d133f4cdSViacheslav Ovsiienko sh->numa_node = spawn->pci_dev->device.numa_node; 2280d133f4cdSViacheslav Ovsiienko pthread_mutex_init(&sh->txpp.mutex, NULL); 22812eb4d010SOphir Munk /* 22822eb4d010SOphir Munk * Configure environment variable "MLX5_BF_SHUT_UP" 22832eb4d010SOphir Munk * before the device creation. The rdma_core library 22842eb4d010SOphir Munk * checks the variable at device creation and 22852eb4d010SOphir Munk * stores the result internally. 22862eb4d010SOphir Munk */ 22872eb4d010SOphir Munk dbmap_env = mlx5_config_doorbell_mapping_env(config); 22882eb4d010SOphir Munk /* Try to open IB device with DV first, then usual Verbs. */ 22892eb4d010SOphir Munk errno = 0; 2290834a9019SOphir Munk sh->ctx = mlx5_glue->dv_open_device(spawn->phys_dev); 22912eb4d010SOphir Munk if (sh->ctx) { 22922eb4d010SOphir Munk sh->devx = 1; 22932eb4d010SOphir Munk DRV_LOG(DEBUG, "DevX is supported"); 22942eb4d010SOphir Munk /* The device is created, no need for environment. */ 22952eb4d010SOphir Munk mlx5_restore_doorbell_mapping_env(dbmap_env); 22962eb4d010SOphir Munk } else { 22972eb4d010SOphir Munk /* The environment variable is still configured. */ 2298834a9019SOphir Munk sh->ctx = mlx5_glue->open_device(spawn->phys_dev); 22992eb4d010SOphir Munk err = errno ? errno : ENODEV; 23002eb4d010SOphir Munk /* 23012eb4d010SOphir Munk * The environment variable is not needed anymore, 23022eb4d010SOphir Munk * all device creation attempts are completed. 23032eb4d010SOphir Munk */ 23042eb4d010SOphir Munk mlx5_restore_doorbell_mapping_env(dbmap_env); 23052eb4d010SOphir Munk if (!sh->ctx) 23062eb4d010SOphir Munk return err; 23072eb4d010SOphir Munk DRV_LOG(DEBUG, "DevX is NOT supported"); 23082eb4d010SOphir Munk err = 0; 23092eb4d010SOphir Munk } 231081c3b977SViacheslav Ovsiienko if (!err && sh->ctx) { 231181c3b977SViacheslav Ovsiienko /* Hint libmlx5 to use PMD allocator for data plane resources */ 231281c3b977SViacheslav Ovsiienko mlx5_glue->dv_set_context_attr(sh->ctx, 231381c3b977SViacheslav Ovsiienko MLX5DV_CTX_ATTR_BUF_ALLOCATORS, 231481c3b977SViacheslav Ovsiienko (void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){ 231581c3b977SViacheslav Ovsiienko .alloc = &mlx5_alloc_verbs_buf, 231681c3b977SViacheslav Ovsiienko .free = &mlx5_free_verbs_buf, 231781c3b977SViacheslav Ovsiienko .data = sh, 231881c3b977SViacheslav Ovsiienko })); 231981c3b977SViacheslav Ovsiienko } 23202eb4d010SOphir Munk return err; 23212eb4d010SOphir Munk } 23222eb4d010SOphir Munk 23232eb4d010SOphir Munk /** 23242eb4d010SOphir Munk * Install shared asynchronous device events handler. 23252eb4d010SOphir Munk * This function is implemented to support event sharing 23262eb4d010SOphir Munk * between multiple ports of single IB device. 23272eb4d010SOphir Munk * 23282eb4d010SOphir Munk * @param sh 23292eb4d010SOphir Munk * Pointer to mlx5_dev_ctx_shared object. 23302eb4d010SOphir Munk */ 23312eb4d010SOphir Munk void 23322eb4d010SOphir Munk mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) 23332eb4d010SOphir Munk { 23342eb4d010SOphir Munk int ret; 23352eb4d010SOphir Munk int flags; 23362eb4d010SOphir Munk 23372eb4d010SOphir Munk sh->intr_handle.fd = -1; 23382eb4d010SOphir Munk flags = fcntl(((struct ibv_context *)sh->ctx)->async_fd, F_GETFL); 23392eb4d010SOphir Munk ret = fcntl(((struct ibv_context *)sh->ctx)->async_fd, 23402eb4d010SOphir Munk F_SETFL, flags | O_NONBLOCK); 23412eb4d010SOphir Munk if (ret) { 23422eb4d010SOphir Munk DRV_LOG(INFO, "failed to change file descriptor async event" 23432eb4d010SOphir Munk " queue"); 23442eb4d010SOphir Munk } else { 23452eb4d010SOphir Munk sh->intr_handle.fd = ((struct ibv_context *)sh->ctx)->async_fd; 23462eb4d010SOphir Munk sh->intr_handle.type = RTE_INTR_HANDLE_EXT; 23472eb4d010SOphir Munk if (rte_intr_callback_register(&sh->intr_handle, 23482eb4d010SOphir Munk mlx5_dev_interrupt_handler, sh)) { 23492eb4d010SOphir Munk DRV_LOG(INFO, "Fail to install the shared interrupt."); 23502eb4d010SOphir Munk sh->intr_handle.fd = -1; 23512eb4d010SOphir Munk } 23522eb4d010SOphir Munk } 23532eb4d010SOphir Munk if (sh->devx) { 23542eb4d010SOphir Munk #ifdef HAVE_IBV_DEVX_ASYNC 23552eb4d010SOphir Munk sh->intr_handle_devx.fd = -1; 235621b7c452SOphir Munk sh->devx_comp = 235721b7c452SOphir Munk (void *)mlx5_glue->devx_create_cmd_comp(sh->ctx); 235821b7c452SOphir Munk struct mlx5dv_devx_cmd_comp *devx_comp = sh->devx_comp; 235921b7c452SOphir Munk if (!devx_comp) { 23602eb4d010SOphir Munk DRV_LOG(INFO, "failed to allocate devx_comp."); 23612eb4d010SOphir Munk return; 23622eb4d010SOphir Munk } 236321b7c452SOphir Munk flags = fcntl(devx_comp->fd, F_GETFL); 236421b7c452SOphir Munk ret = fcntl(devx_comp->fd, F_SETFL, flags | O_NONBLOCK); 23652eb4d010SOphir Munk if (ret) { 23662eb4d010SOphir Munk DRV_LOG(INFO, "failed to change file descriptor" 23672eb4d010SOphir Munk " devx comp"); 23682eb4d010SOphir Munk return; 23692eb4d010SOphir Munk } 237021b7c452SOphir Munk sh->intr_handle_devx.fd = devx_comp->fd; 23712eb4d010SOphir Munk sh->intr_handle_devx.type = RTE_INTR_HANDLE_EXT; 23722eb4d010SOphir Munk if (rte_intr_callback_register(&sh->intr_handle_devx, 23732eb4d010SOphir Munk mlx5_dev_interrupt_handler_devx, sh)) { 23742eb4d010SOphir Munk DRV_LOG(INFO, "Fail to install the devx shared" 23752eb4d010SOphir Munk " interrupt."); 23762eb4d010SOphir Munk sh->intr_handle_devx.fd = -1; 23772eb4d010SOphir Munk } 23782eb4d010SOphir Munk #endif /* HAVE_IBV_DEVX_ASYNC */ 23792eb4d010SOphir Munk } 23802eb4d010SOphir Munk } 23812eb4d010SOphir Munk 23822eb4d010SOphir Munk /** 23832eb4d010SOphir Munk * Uninstall shared asynchronous device events handler. 23842eb4d010SOphir Munk * This function is implemented to support event sharing 23852eb4d010SOphir Munk * between multiple ports of single IB device. 23862eb4d010SOphir Munk * 23872eb4d010SOphir Munk * @param dev 23882eb4d010SOphir Munk * Pointer to mlx5_dev_ctx_shared object. 23892eb4d010SOphir Munk */ 23902eb4d010SOphir Munk void 23912eb4d010SOphir Munk mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh) 23922eb4d010SOphir Munk { 23932eb4d010SOphir Munk if (sh->intr_handle.fd >= 0) 23942eb4d010SOphir Munk mlx5_intr_callback_unregister(&sh->intr_handle, 23952eb4d010SOphir Munk mlx5_dev_interrupt_handler, sh); 23962eb4d010SOphir Munk #ifdef HAVE_IBV_DEVX_ASYNC 23972eb4d010SOphir Munk if (sh->intr_handle_devx.fd >= 0) 23982eb4d010SOphir Munk rte_intr_callback_unregister(&sh->intr_handle_devx, 23992eb4d010SOphir Munk mlx5_dev_interrupt_handler_devx, sh); 24002eb4d010SOphir Munk if (sh->devx_comp) 24012eb4d010SOphir Munk mlx5_glue->devx_destroy_cmd_comp(sh->devx_comp); 24022eb4d010SOphir Munk #endif 24032eb4d010SOphir Munk } 2404042f5c94SOphir Munk 240573bf9235SOphir Munk /** 240673bf9235SOphir Munk * Read statistics by a named counter. 240773bf9235SOphir Munk * 240873bf9235SOphir Munk * @param[in] priv 240973bf9235SOphir Munk * Pointer to the private device data structure. 241073bf9235SOphir Munk * @param[in] ctr_name 241173bf9235SOphir Munk * Pointer to the name of the statistic counter to read 241273bf9235SOphir Munk * @param[out] stat 241373bf9235SOphir Munk * Pointer to read statistic value. 241473bf9235SOphir Munk * @return 241573bf9235SOphir Munk * 0 on success and stat is valud, 1 if failed to read the value 241673bf9235SOphir Munk * rte_errno is set. 241773bf9235SOphir Munk * 241873bf9235SOphir Munk */ 241973bf9235SOphir Munk int 242073bf9235SOphir Munk mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, 242173bf9235SOphir Munk uint64_t *stat) 242273bf9235SOphir Munk { 242373bf9235SOphir Munk int fd; 242473bf9235SOphir Munk 242573bf9235SOphir Munk if (priv->sh) { 242673bf9235SOphir Munk MKSTR(path, "%s/ports/%d/hw_counters/%s", 242773bf9235SOphir Munk priv->sh->ibdev_path, 242873bf9235SOphir Munk priv->dev_port, 242973bf9235SOphir Munk ctr_name); 243073bf9235SOphir Munk fd = open(path, O_RDONLY); 2431038e7fc0SShy Shyman /* 2432038e7fc0SShy Shyman * in switchdev the file location is not per port 2433038e7fc0SShy Shyman * but rather in <ibdev_path>/hw_counters/<file_name>. 2434038e7fc0SShy Shyman */ 2435038e7fc0SShy Shyman if (fd == -1) { 2436038e7fc0SShy Shyman MKSTR(path1, "%s/hw_counters/%s", 2437038e7fc0SShy Shyman priv->sh->ibdev_path, 2438038e7fc0SShy Shyman ctr_name); 2439038e7fc0SShy Shyman fd = open(path1, O_RDONLY); 2440038e7fc0SShy Shyman } 244173bf9235SOphir Munk if (fd != -1) { 244273bf9235SOphir Munk char buf[21] = {'\0'}; 244373bf9235SOphir Munk ssize_t n = read(fd, buf, sizeof(buf)); 244473bf9235SOphir Munk 244573bf9235SOphir Munk close(fd); 244673bf9235SOphir Munk if (n != -1) { 244773bf9235SOphir Munk *stat = strtoull(buf, NULL, 10); 244873bf9235SOphir Munk return 0; 244973bf9235SOphir Munk } 245073bf9235SOphir Munk } 245173bf9235SOphir Munk } 245273bf9235SOphir Munk *stat = 0; 245373bf9235SOphir Munk return 1; 245473bf9235SOphir Munk } 245573bf9235SOphir Munk 245673bf9235SOphir Munk /** 2457d5ed8aa9SOphir Munk * Set the reg_mr and dereg_mr call backs 2458d5ed8aa9SOphir Munk * 2459d5ed8aa9SOphir Munk * @param reg_mr_cb[out] 2460d5ed8aa9SOphir Munk * Pointer to reg_mr func 2461d5ed8aa9SOphir Munk * @param dereg_mr_cb[out] 2462d5ed8aa9SOphir Munk * Pointer to dereg_mr func 2463d5ed8aa9SOphir Munk * 2464d5ed8aa9SOphir Munk */ 2465d5ed8aa9SOphir Munk void 2466d5ed8aa9SOphir Munk mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, 2467d5ed8aa9SOphir Munk mlx5_dereg_mr_t *dereg_mr_cb) 2468d5ed8aa9SOphir Munk { 2469db12615bSOphir Munk *reg_mr_cb = mlx5_mr_verbs_ops.reg_mr; 2470db12615bSOphir Munk *dereg_mr_cb = mlx5_mr_verbs_ops.dereg_mr; 2471d5ed8aa9SOphir Munk } 2472d5ed8aa9SOphir Munk 2473ab27cdd9SOphir Munk /** 2474ab27cdd9SOphir Munk * Remove a MAC address from device 2475ab27cdd9SOphir Munk * 2476ab27cdd9SOphir Munk * @param dev 2477ab27cdd9SOphir Munk * Pointer to Ethernet device structure. 2478ab27cdd9SOphir Munk * @param index 2479ab27cdd9SOphir Munk * MAC address index. 2480ab27cdd9SOphir Munk */ 2481ab27cdd9SOphir Munk void 2482ab27cdd9SOphir Munk mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 2483ab27cdd9SOphir Munk { 2484ab27cdd9SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 2485ab27cdd9SOphir Munk const int vf = priv->config.vf; 2486ab27cdd9SOphir Munk 2487ab27cdd9SOphir Munk if (vf) 2488ab27cdd9SOphir Munk mlx5_nl_mac_addr_remove(priv->nl_socket_route, 2489ab27cdd9SOphir Munk mlx5_ifindex(dev), priv->mac_own, 2490ab27cdd9SOphir Munk &dev->data->mac_addrs[index], index); 2491ab27cdd9SOphir Munk } 2492ab27cdd9SOphir Munk 2493ab27cdd9SOphir Munk /** 2494ab27cdd9SOphir Munk * Adds a MAC address to the device 2495ab27cdd9SOphir Munk * 2496ab27cdd9SOphir Munk * @param dev 2497ab27cdd9SOphir Munk * Pointer to Ethernet device structure. 2498ab27cdd9SOphir Munk * @param mac_addr 2499ab27cdd9SOphir Munk * MAC address to register. 2500ab27cdd9SOphir Munk * @param index 2501ab27cdd9SOphir Munk * MAC address index. 2502ab27cdd9SOphir Munk * 2503ab27cdd9SOphir Munk * @return 2504ab27cdd9SOphir Munk * 0 on success, a negative errno value otherwise 2505ab27cdd9SOphir Munk */ 2506ab27cdd9SOphir Munk int 2507ab27cdd9SOphir Munk mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 2508ab27cdd9SOphir Munk uint32_t index) 2509ab27cdd9SOphir Munk { 2510ab27cdd9SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 2511ab27cdd9SOphir Munk const int vf = priv->config.vf; 2512ab27cdd9SOphir Munk int ret = 0; 2513ab27cdd9SOphir Munk 2514ab27cdd9SOphir Munk if (vf) 2515ab27cdd9SOphir Munk ret = mlx5_nl_mac_addr_add(priv->nl_socket_route, 2516ab27cdd9SOphir Munk mlx5_ifindex(dev), priv->mac_own, 2517ab27cdd9SOphir Munk mac, index); 2518ab27cdd9SOphir Munk return ret; 2519ab27cdd9SOphir Munk } 2520ab27cdd9SOphir Munk 2521ab27cdd9SOphir Munk /** 2522ab27cdd9SOphir Munk * Modify a VF MAC address 2523ab27cdd9SOphir Munk * 2524ab27cdd9SOphir Munk * @param priv 2525ab27cdd9SOphir Munk * Pointer to device private data. 2526ab27cdd9SOphir Munk * @param mac_addr 2527ab27cdd9SOphir Munk * MAC address to modify into. 2528ab27cdd9SOphir Munk * @param iface_idx 2529ab27cdd9SOphir Munk * Net device interface index 2530ab27cdd9SOphir Munk * @param vf_index 2531ab27cdd9SOphir Munk * VF index 2532ab27cdd9SOphir Munk * 2533ab27cdd9SOphir Munk * @return 2534ab27cdd9SOphir Munk * 0 on success, a negative errno value otherwise 2535ab27cdd9SOphir Munk */ 2536ab27cdd9SOphir Munk int 2537ab27cdd9SOphir Munk mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, 2538ab27cdd9SOphir Munk unsigned int iface_idx, 2539ab27cdd9SOphir Munk struct rte_ether_addr *mac_addr, 2540ab27cdd9SOphir Munk int vf_index) 2541ab27cdd9SOphir Munk { 2542ab27cdd9SOphir Munk return mlx5_nl_vf_mac_addr_modify 2543ab27cdd9SOphir Munk (priv->nl_socket_route, iface_idx, mac_addr, vf_index); 2544ab27cdd9SOphir Munk } 2545ab27cdd9SOphir Munk 25464d18abd1SOphir Munk /** 25474d18abd1SOphir Munk * Set device promiscuous mode 25484d18abd1SOphir Munk * 25494d18abd1SOphir Munk * @param dev 25504d18abd1SOphir Munk * Pointer to Ethernet device structure. 25514d18abd1SOphir Munk * @param enable 25524d18abd1SOphir Munk * 0 - promiscuous is disabled, otherwise - enabled 25534d18abd1SOphir Munk * 25544d18abd1SOphir Munk * @return 25554d18abd1SOphir Munk * 0 on success, a negative error value otherwise 25564d18abd1SOphir Munk */ 25574d18abd1SOphir Munk int 25584d18abd1SOphir Munk mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable) 25594d18abd1SOphir Munk { 25604d18abd1SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 25614d18abd1SOphir Munk 25624d18abd1SOphir Munk return mlx5_nl_promisc(priv->nl_socket_route, 25634d18abd1SOphir Munk mlx5_ifindex(dev), !!enable); 25644d18abd1SOphir Munk } 25654d18abd1SOphir Munk 25664d18abd1SOphir Munk /** 25674d18abd1SOphir Munk * Set device promiscuous mode 25684d18abd1SOphir Munk * 25694d18abd1SOphir Munk * @param dev 25704d18abd1SOphir Munk * Pointer to Ethernet device structure. 25714d18abd1SOphir Munk * @param enable 25724d18abd1SOphir Munk * 0 - all multicase is disabled, otherwise - enabled 25734d18abd1SOphir Munk * 25744d18abd1SOphir Munk * @return 25754d18abd1SOphir Munk * 0 on success, a negative error value otherwise 25764d18abd1SOphir Munk */ 25774d18abd1SOphir Munk int 25784d18abd1SOphir Munk mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable) 25794d18abd1SOphir Munk { 25804d18abd1SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 25814d18abd1SOphir Munk 25824d18abd1SOphir Munk return mlx5_nl_allmulti(priv->nl_socket_route, 25834d18abd1SOphir Munk mlx5_ifindex(dev), !!enable); 25844d18abd1SOphir Munk } 25854d18abd1SOphir Munk 2586f00f6562SOphir Munk /** 2587f00f6562SOphir Munk * Flush device MAC addresses 2588f00f6562SOphir Munk * 2589f00f6562SOphir Munk * @param dev 2590f00f6562SOphir Munk * Pointer to Ethernet device structure. 2591f00f6562SOphir Munk * 2592f00f6562SOphir Munk */ 2593f00f6562SOphir Munk void 2594f00f6562SOphir Munk mlx5_os_mac_addr_flush(struct rte_eth_dev *dev) 2595f00f6562SOphir Munk { 2596f00f6562SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 2597f00f6562SOphir Munk 2598f00f6562SOphir Munk mlx5_nl_mac_addr_flush(priv->nl_socket_route, mlx5_ifindex(dev), 2599f00f6562SOphir Munk dev->data->mac_addrs, 2600f00f6562SOphir Munk MLX5_MAX_MAC_ADDRESSES, priv->mac_own); 2601f00f6562SOphir Munk } 2602