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> 23919488fbSXueming Li #include <rte_bus_auxiliary.h> 24f44b09f9SOphir Munk #include <rte_common.h> 25f44b09f9SOphir Munk #include <rte_kvargs.h> 26f44b09f9SOphir Munk #include <rte_rwlock.h> 27f44b09f9SOphir Munk #include <rte_spinlock.h> 28f44b09f9SOphir Munk #include <rte_string_fns.h> 29f44b09f9SOphir Munk #include <rte_alarm.h> 302aba9fc7SOphir Munk #include <rte_eal_paging.h> 31f44b09f9SOphir Munk 32f44b09f9SOphir Munk #include <mlx5_glue.h> 33f44b09f9SOphir Munk #include <mlx5_devx_cmds.h> 34f44b09f9SOphir Munk #include <mlx5_common.h> 352eb4d010SOphir Munk #include <mlx5_common_mp.h> 36d5ed8aa9SOphir Munk #include <mlx5_common_mr.h> 375522da6bSSuanming Mou #include <mlx5_malloc.h> 38f44b09f9SOphir Munk 39f44b09f9SOphir Munk #include "mlx5_defs.h" 40f44b09f9SOphir Munk #include "mlx5.h" 41391b8bccSOphir Munk #include "mlx5_common_os.h" 42f44b09f9SOphir Munk #include "mlx5_utils.h" 43f44b09f9SOphir Munk #include "mlx5_rxtx.h" 44151cbe3aSMichael Baum #include "mlx5_rx.h" 45377b69fbSMichael Baum #include "mlx5_tx.h" 46f44b09f9SOphir Munk #include "mlx5_autoconf.h" 47f44b09f9SOphir Munk #include "mlx5_flow.h" 48f44b09f9SOphir Munk #include "rte_pmd_mlx5.h" 494f96d913SOphir Munk #include "mlx5_verbs.h" 50f00f6562SOphir Munk #include "mlx5_nl.h" 516deb19e1SMichael Baum #include "mlx5_devx.h" 52f44b09f9SOphir 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 70b4edeaf3SSuanming Mou /* rte flow indexed pool configuration. */ 71b4edeaf3SSuanming Mou static struct mlx5_indexed_pool_config icfg[] = { 72b4edeaf3SSuanming Mou { 73b4edeaf3SSuanming Mou .size = sizeof(struct rte_flow), 74b4edeaf3SSuanming Mou .trunk_size = 64, 75b4edeaf3SSuanming Mou .need_lock = 1, 76b4edeaf3SSuanming Mou .release_mem_en = 0, 77b4edeaf3SSuanming Mou .malloc = mlx5_malloc, 78b4edeaf3SSuanming Mou .free = mlx5_free, 79b4edeaf3SSuanming Mou .per_core_cache = 0, 80b4edeaf3SSuanming Mou .type = "ctl_flow_ipool", 81b4edeaf3SSuanming Mou }, 82b4edeaf3SSuanming Mou { 83b4edeaf3SSuanming Mou .size = sizeof(struct rte_flow), 84b4edeaf3SSuanming Mou .trunk_size = 64, 85b4edeaf3SSuanming Mou .grow_trunk = 3, 86b4edeaf3SSuanming Mou .grow_shift = 2, 87b4edeaf3SSuanming Mou .need_lock = 1, 88b4edeaf3SSuanming Mou .release_mem_en = 0, 89b4edeaf3SSuanming Mou .malloc = mlx5_malloc, 90b4edeaf3SSuanming Mou .free = mlx5_free, 91b4edeaf3SSuanming Mou .per_core_cache = 1 << 14, 92b4edeaf3SSuanming Mou .type = "rte_flow_ipool", 93b4edeaf3SSuanming Mou }, 94b4edeaf3SSuanming Mou { 95b4edeaf3SSuanming Mou .size = sizeof(struct rte_flow), 96b4edeaf3SSuanming Mou .trunk_size = 64, 97b4edeaf3SSuanming Mou .grow_trunk = 3, 98b4edeaf3SSuanming Mou .grow_shift = 2, 99b4edeaf3SSuanming Mou .need_lock = 1, 100b4edeaf3SSuanming Mou .release_mem_en = 0, 101b4edeaf3SSuanming Mou .malloc = mlx5_malloc, 102b4edeaf3SSuanming Mou .free = mlx5_free, 103b4edeaf3SSuanming Mou .per_core_cache = 0, 104b4edeaf3SSuanming Mou .type = "mcp_flow_ipool", 105b4edeaf3SSuanming Mou }, 106b4edeaf3SSuanming Mou }; 107b4edeaf3SSuanming Mou 108f44b09f9SOphir Munk /** 10908d1838fSDekel Peled * Set the completion channel file descriptor interrupt as non-blocking. 11008d1838fSDekel Peled * 11108d1838fSDekel Peled * @param[in] rxq_obj 11208d1838fSDekel Peled * Pointer to RQ channel object, which includes the channel fd 11308d1838fSDekel Peled * 11408d1838fSDekel Peled * @param[out] fd 11508d1838fSDekel Peled * The file descriptor (representing the intetrrupt) used in this channel. 11608d1838fSDekel Peled * 11708d1838fSDekel Peled * @return 11808d1838fSDekel Peled * 0 on successfully setting the fd to non-blocking, non-zero otherwise. 11908d1838fSDekel Peled */ 12008d1838fSDekel Peled int 12108d1838fSDekel Peled mlx5_os_set_nonblock_channel_fd(int fd) 12208d1838fSDekel Peled { 12308d1838fSDekel Peled int flags; 12408d1838fSDekel Peled 12508d1838fSDekel Peled flags = fcntl(fd, F_GETFL); 12608d1838fSDekel Peled return fcntl(fd, F_SETFL, flags | O_NONBLOCK); 12708d1838fSDekel Peled } 12808d1838fSDekel Peled 12908d1838fSDekel Peled /** 130e85f623eSOphir Munk * Get mlx5 device attributes. The glue function query_device_ex() is called 131e85f623eSOphir Munk * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5 132e85f623eSOphir Munk * device attributes from the glue out parameter. 133e85f623eSOphir Munk * 134fe46b20cSMichael Baum * @param cdev 135fe46b20cSMichael Baum * Pointer to mlx5 device. 136e85f623eSOphir Munk * 137e85f623eSOphir Munk * @param device_attr 138e85f623eSOphir Munk * Pointer to mlx5 device attributes. 139e85f623eSOphir Munk * 140e85f623eSOphir Munk * @return 141e85f623eSOphir Munk * 0 on success, non zero error number otherwise 142e85f623eSOphir Munk */ 143e85f623eSOphir Munk int 144fe46b20cSMichael Baum mlx5_os_get_dev_attr(struct mlx5_common_device *cdev, 145fe46b20cSMichael Baum struct mlx5_dev_attr *device_attr) 146e85f623eSOphir Munk { 147e85f623eSOphir Munk int err; 148fe46b20cSMichael Baum struct ibv_context *ctx = cdev->ctx; 149e85f623eSOphir Munk struct ibv_device_attr_ex attr_ex; 150fe46b20cSMichael Baum 151e85f623eSOphir Munk memset(device_attr, 0, sizeof(*device_attr)); 152e85f623eSOphir Munk err = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex); 153e85f623eSOphir Munk if (err) 154e85f623eSOphir Munk return err; 155e85f623eSOphir Munk device_attr->device_cap_flags_ex = attr_ex.device_cap_flags_ex; 156e85f623eSOphir Munk device_attr->max_qp_wr = attr_ex.orig_attr.max_qp_wr; 157e85f623eSOphir Munk device_attr->max_sge = attr_ex.orig_attr.max_sge; 158e85f623eSOphir Munk device_attr->max_cq = attr_ex.orig_attr.max_cq; 1591f29d15eSOphir Munk device_attr->max_cqe = attr_ex.orig_attr.max_cqe; 1601f29d15eSOphir Munk device_attr->max_mr = attr_ex.orig_attr.max_mr; 1611f29d15eSOphir Munk device_attr->max_pd = attr_ex.orig_attr.max_pd; 162e85f623eSOphir Munk device_attr->max_qp = attr_ex.orig_attr.max_qp; 1631f29d15eSOphir Munk device_attr->max_srq = attr_ex.orig_attr.max_srq; 1641f29d15eSOphir Munk device_attr->max_srq_wr = attr_ex.orig_attr.max_srq_wr; 165e85f623eSOphir Munk device_attr->raw_packet_caps = attr_ex.raw_packet_caps; 166e85f623eSOphir Munk device_attr->max_rwq_indirection_table_size = 167e85f623eSOphir Munk attr_ex.rss_caps.max_rwq_indirection_table_size; 168e85f623eSOphir Munk device_attr->max_tso = attr_ex.tso_caps.max_tso; 169e85f623eSOphir Munk device_attr->tso_supported_qpts = attr_ex.tso_caps.supported_qpts; 170e85f623eSOphir Munk 171e85f623eSOphir Munk struct mlx5dv_context dv_attr = { .comp_mask = 0 }; 172e85f623eSOphir Munk err = mlx5_glue->dv_query_device(ctx, &dv_attr); 173e85f623eSOphir Munk if (err) 174e85f623eSOphir Munk return err; 175e85f623eSOphir Munk 176e85f623eSOphir Munk device_attr->flags = dv_attr.flags; 177e85f623eSOphir Munk device_attr->comp_mask = dv_attr.comp_mask; 178e85f623eSOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 179e85f623eSOphir Munk device_attr->sw_parsing_offloads = 180e85f623eSOphir Munk dv_attr.sw_parsing_caps.sw_parsing_offloads; 181e85f623eSOphir Munk #endif 182e85f623eSOphir Munk device_attr->min_single_stride_log_num_of_bytes = 183e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_stride_log_num_of_bytes; 184e85f623eSOphir Munk device_attr->max_single_stride_log_num_of_bytes = 185e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_stride_log_num_of_bytes; 186e85f623eSOphir Munk device_attr->min_single_wqe_log_num_of_strides = 187e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_wqe_log_num_of_strides; 188e85f623eSOphir Munk device_attr->max_single_wqe_log_num_of_strides = 189e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_wqe_log_num_of_strides; 190e85f623eSOphir Munk device_attr->stride_supported_qpts = 191e85f623eSOphir Munk dv_attr.striding_rq_caps.supported_qpts; 192e85f623eSOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 193e85f623eSOphir Munk device_attr->tunnel_offloads_caps = dv_attr.tunnel_offloads_caps; 194e85f623eSOphir Munk #endif 195520e3f48SKamil Vojanec strlcpy(device_attr->fw_ver, attr_ex.orig_attr.fw_ver, 196520e3f48SKamil Vojanec sizeof(device_attr->fw_ver)); 197e85f623eSOphir Munk 198e85f623eSOphir Munk return err; 199e85f623eSOphir Munk } 2002eb4d010SOphir Munk 2012eb4d010SOphir Munk /** 202630a587bSRongwei Liu * Detect misc5 support or not 203630a587bSRongwei Liu * 204630a587bSRongwei Liu * @param[in] priv 205630a587bSRongwei Liu * Device private data pointer 206630a587bSRongwei Liu */ 207630a587bSRongwei Liu #ifdef HAVE_MLX5DV_DR 208630a587bSRongwei Liu static void 209630a587bSRongwei Liu __mlx5_discovery_misc5_cap(struct mlx5_priv *priv) 210630a587bSRongwei Liu { 211630a587bSRongwei Liu #ifdef HAVE_IBV_FLOW_DV_SUPPORT 212630a587bSRongwei Liu /* Dummy VxLAN matcher to detect rdma-core misc5 cap 213630a587bSRongwei Liu * Case: IPv4--->UDP--->VxLAN--->vni 214630a587bSRongwei Liu */ 215630a587bSRongwei Liu void *tbl; 216630a587bSRongwei Liu struct mlx5_flow_dv_match_params matcher_mask; 217630a587bSRongwei Liu void *match_m; 218630a587bSRongwei Liu void *matcher; 219630a587bSRongwei Liu void *headers_m; 220630a587bSRongwei Liu void *misc5_m; 221630a587bSRongwei Liu uint32_t *tunnel_header_m; 222630a587bSRongwei Liu struct mlx5dv_flow_matcher_attr dv_attr; 223630a587bSRongwei Liu 224630a587bSRongwei Liu memset(&matcher_mask, 0, sizeof(matcher_mask)); 225630a587bSRongwei Liu matcher_mask.size = sizeof(matcher_mask.buf); 226630a587bSRongwei Liu match_m = matcher_mask.buf; 227630a587bSRongwei Liu headers_m = MLX5_ADDR_OF(fte_match_param, match_m, outer_headers); 228630a587bSRongwei Liu misc5_m = MLX5_ADDR_OF(fte_match_param, 229630a587bSRongwei Liu match_m, misc_parameters_5); 230630a587bSRongwei Liu tunnel_header_m = (uint32_t *) 231630a587bSRongwei Liu MLX5_ADDR_OF(fte_match_set_misc5, 232630a587bSRongwei Liu misc5_m, tunnel_header_1); 233630a587bSRongwei Liu MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff); 234630a587bSRongwei Liu MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 4); 235630a587bSRongwei Liu MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff); 236630a587bSRongwei Liu *tunnel_header_m = 0xffffff; 237630a587bSRongwei Liu 238630a587bSRongwei Liu tbl = mlx5_glue->dr_create_flow_tbl(priv->sh->rx_domain, 1); 239630a587bSRongwei Liu if (!tbl) { 240630a587bSRongwei Liu DRV_LOG(INFO, "No SW steering support"); 241630a587bSRongwei Liu return; 242630a587bSRongwei Liu } 243630a587bSRongwei Liu dv_attr.type = IBV_FLOW_ATTR_NORMAL, 244630a587bSRongwei Liu dv_attr.match_mask = (void *)&matcher_mask, 245630a587bSRongwei Liu dv_attr.match_criteria_enable = 246630a587bSRongwei Liu (1 << MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT) | 247630a587bSRongwei Liu (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT); 248630a587bSRongwei Liu dv_attr.priority = 3; 249630a587bSRongwei Liu #ifdef HAVE_MLX5DV_DR_ESWITCH 250630a587bSRongwei Liu void *misc2_m; 251630a587bSRongwei Liu if (priv->config.dv_esw_en) { 252630a587bSRongwei Liu /* FDB enabled reg_c_0 */ 253630a587bSRongwei Liu dv_attr.match_criteria_enable |= 254630a587bSRongwei Liu (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT); 255630a587bSRongwei Liu misc2_m = MLX5_ADDR_OF(fte_match_param, 256630a587bSRongwei Liu match_m, misc_parameters_2); 257630a587bSRongwei Liu MLX5_SET(fte_match_set_misc2, misc2_m, 258630a587bSRongwei Liu metadata_reg_c_0, 0xffff); 259630a587bSRongwei Liu } 260630a587bSRongwei Liu #endif 261ca1418ceSMichael Baum matcher = mlx5_glue->dv_create_flow_matcher(priv->sh->cdev->ctx, 262630a587bSRongwei Liu &dv_attr, tbl); 263630a587bSRongwei Liu if (matcher) { 264630a587bSRongwei Liu priv->sh->misc5_cap = 1; 265630a587bSRongwei Liu mlx5_glue->dv_destroy_flow_matcher(matcher); 266630a587bSRongwei Liu } 267630a587bSRongwei Liu mlx5_glue->dr_destroy_flow_tbl(tbl); 268630a587bSRongwei Liu #else 269630a587bSRongwei Liu RTE_SET_USED(priv); 270630a587bSRongwei Liu #endif 271630a587bSRongwei Liu } 272630a587bSRongwei Liu #endif 273630a587bSRongwei Liu 274630a587bSRongwei Liu /** 2752eb4d010SOphir Munk * Initialize DR related data within private structure. 2762eb4d010SOphir Munk * Routine checks the reference counter and does actual 2772eb4d010SOphir Munk * resources creation/initialization only if counter is zero. 2782eb4d010SOphir Munk * 2792eb4d010SOphir Munk * @param[in] priv 2802eb4d010SOphir Munk * Pointer to the private device data structure. 2812eb4d010SOphir Munk * 2822eb4d010SOphir Munk * @return 2832eb4d010SOphir Munk * Zero on success, positive error code otherwise. 2842eb4d010SOphir Munk */ 2852eb4d010SOphir Munk static int 2862eb4d010SOphir Munk mlx5_alloc_shared_dr(struct mlx5_priv *priv) 2872eb4d010SOphir Munk { 2882eb4d010SOphir Munk struct mlx5_dev_ctx_shared *sh = priv->sh; 289961b6774SMatan Azrad char s[MLX5_NAME_SIZE] __rte_unused; 29016dbba25SXueming Li int err; 2912eb4d010SOphir Munk 29216dbba25SXueming Li MLX5_ASSERT(sh && sh->refcnt); 29316dbba25SXueming Li if (sh->refcnt > 1) 29416dbba25SXueming Li return 0; 2952eb4d010SOphir Munk err = mlx5_alloc_table_hash_list(priv); 2962eb4d010SOphir Munk if (err) 297291140c6SSuanming Mou goto error; 298291140c6SSuanming Mou /* The resources below are only valid with DV support. */ 299291140c6SSuanming Mou #ifdef HAVE_IBV_FLOW_DV_SUPPORT 300491b7137SMatan Azrad /* Init port id action list. */ 301e78e5408SMatan Azrad snprintf(s, sizeof(s), "%s_port_id_action_list", sh->ibdev_name); 302d03b7860SSuanming Mou sh->port_id_action_list = mlx5_list_create(s, sh, true, 3030fd5f82aSXueming Li flow_dv_port_id_create_cb, 3040fd5f82aSXueming Li flow_dv_port_id_match_cb, 305491b7137SMatan Azrad flow_dv_port_id_remove_cb, 306491b7137SMatan Azrad flow_dv_port_id_clone_cb, 307491b7137SMatan Azrad flow_dv_port_id_clone_free_cb); 308679f46c7SMatan Azrad if (!sh->port_id_action_list) 309679f46c7SMatan Azrad goto error; 310491b7137SMatan Azrad /* Init push vlan action list. */ 311e78e5408SMatan Azrad snprintf(s, sizeof(s), "%s_push_vlan_action_list", sh->ibdev_name); 312d03b7860SSuanming Mou sh->push_vlan_action_list = mlx5_list_create(s, sh, true, 3133422af2aSXueming Li flow_dv_push_vlan_create_cb, 3143422af2aSXueming Li flow_dv_push_vlan_match_cb, 315491b7137SMatan Azrad flow_dv_push_vlan_remove_cb, 316491b7137SMatan Azrad flow_dv_push_vlan_clone_cb, 317491b7137SMatan Azrad flow_dv_push_vlan_clone_free_cb); 318679f46c7SMatan Azrad if (!sh->push_vlan_action_list) 319679f46c7SMatan Azrad goto error; 320491b7137SMatan Azrad /* Init sample action list. */ 321e78e5408SMatan Azrad snprintf(s, sizeof(s), "%s_sample_action_list", sh->ibdev_name); 322d03b7860SSuanming Mou sh->sample_action_list = mlx5_list_create(s, sh, true, 32319784141SSuanming Mou flow_dv_sample_create_cb, 32419784141SSuanming Mou flow_dv_sample_match_cb, 325491b7137SMatan Azrad flow_dv_sample_remove_cb, 326491b7137SMatan Azrad flow_dv_sample_clone_cb, 327491b7137SMatan Azrad flow_dv_sample_clone_free_cb); 328679f46c7SMatan Azrad if (!sh->sample_action_list) 329679f46c7SMatan Azrad goto error; 330491b7137SMatan Azrad /* Init dest array action list. */ 331e78e5408SMatan Azrad snprintf(s, sizeof(s), "%s_dest_array_list", sh->ibdev_name); 332d03b7860SSuanming Mou sh->dest_array_list = mlx5_list_create(s, sh, true, 33319784141SSuanming Mou flow_dv_dest_array_create_cb, 33419784141SSuanming Mou flow_dv_dest_array_match_cb, 335491b7137SMatan Azrad flow_dv_dest_array_remove_cb, 336491b7137SMatan Azrad flow_dv_dest_array_clone_cb, 337491b7137SMatan Azrad flow_dv_dest_array_clone_free_cb); 338679f46c7SMatan Azrad if (!sh->dest_array_list) 339679f46c7SMatan Azrad goto error; 340*9086ac09SGregory Etelson /* Init shared flex parsers list, no need lcore_share */ 341*9086ac09SGregory Etelson snprintf(s, sizeof(s), "%s_flex_parsers_list", sh->ibdev_name); 342*9086ac09SGregory Etelson sh->flex_parsers_dv = mlx5_list_create(s, sh, false, 343*9086ac09SGregory Etelson mlx5_flex_parser_create_cb, 344*9086ac09SGregory Etelson mlx5_flex_parser_match_cb, 345*9086ac09SGregory Etelson mlx5_flex_parser_remove_cb, 346*9086ac09SGregory Etelson mlx5_flex_parser_clone_cb, 347*9086ac09SGregory Etelson mlx5_flex_parser_clone_free_cb); 348*9086ac09SGregory Etelson if (!sh->flex_parsers_dv) 349*9086ac09SGregory Etelson goto error; 350291140c6SSuanming Mou #endif 3512eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR 3522eb4d010SOphir Munk void *domain; 3532eb4d010SOphir Munk 3542eb4d010SOphir Munk /* Reference counter is zero, we should initialize structures. */ 355ca1418ceSMichael Baum domain = mlx5_glue->dr_create_domain(sh->cdev->ctx, 3562eb4d010SOphir Munk MLX5DV_DR_DOMAIN_TYPE_NIC_RX); 3572eb4d010SOphir Munk if (!domain) { 3582eb4d010SOphir Munk DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed"); 3592eb4d010SOphir Munk err = errno; 3602eb4d010SOphir Munk goto error; 3612eb4d010SOphir Munk } 3622eb4d010SOphir Munk sh->rx_domain = domain; 363ca1418ceSMichael Baum domain = mlx5_glue->dr_create_domain(sh->cdev->ctx, 3642eb4d010SOphir Munk MLX5DV_DR_DOMAIN_TYPE_NIC_TX); 3652eb4d010SOphir Munk if (!domain) { 3662eb4d010SOphir Munk DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed"); 3672eb4d010SOphir Munk err = errno; 3682eb4d010SOphir Munk goto error; 3692eb4d010SOphir Munk } 3702eb4d010SOphir Munk sh->tx_domain = domain; 3712eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 3722eb4d010SOphir Munk if (priv->config.dv_esw_en) { 373ca1418ceSMichael Baum domain = mlx5_glue->dr_create_domain(sh->cdev->ctx, 374ca1418ceSMichael Baum MLX5DV_DR_DOMAIN_TYPE_FDB); 3752eb4d010SOphir Munk if (!domain) { 3762eb4d010SOphir Munk DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed"); 3772eb4d010SOphir Munk err = errno; 3782eb4d010SOphir Munk goto error; 3792eb4d010SOphir Munk } 3802eb4d010SOphir Munk sh->fdb_domain = domain; 381da845ae9SViacheslav Ovsiienko } 382da845ae9SViacheslav Ovsiienko /* 383da845ae9SViacheslav Ovsiienko * The drop action is just some dummy placeholder in rdma-core. It 384da845ae9SViacheslav Ovsiienko * does not belong to domains and has no any attributes, and, can be 385da845ae9SViacheslav Ovsiienko * shared by the entire device. 386da845ae9SViacheslav Ovsiienko */ 387da845ae9SViacheslav Ovsiienko sh->dr_drop_action = mlx5_glue->dr_create_flow_action_drop(); 388da845ae9SViacheslav Ovsiienko if (!sh->dr_drop_action) { 389da845ae9SViacheslav Ovsiienko DRV_LOG(ERR, "FDB mlx5dv_dr_create_flow_action_drop"); 390da845ae9SViacheslav Ovsiienko err = errno; 391da845ae9SViacheslav Ovsiienko goto error; 3922eb4d010SOphir Munk } 3932eb4d010SOphir Munk #endif 394f3020a33SSuanming Mou if (!sh->tunnel_hub && priv->config.dv_miss_info) 3954ec6360dSGregory Etelson err = mlx5_alloc_tunnel_hub(sh); 3964ec6360dSGregory Etelson if (err) { 3974ec6360dSGregory Etelson DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err); 3984ec6360dSGregory Etelson goto error; 3994ec6360dSGregory Etelson } 4002eb4d010SOphir Munk if (priv->config.reclaim_mode == MLX5_RCM_AGGR) { 4012eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1); 4022eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1); 4032eb4d010SOphir Munk if (sh->fdb_domain) 4042eb4d010SOphir Munk mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1); 4052eb4d010SOphir Munk } 4062eb4d010SOphir Munk sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan(); 407e39226bdSJiawei Wang if (!priv->config.allow_duplicate_pattern) { 408e39226bdSJiawei Wang #ifndef HAVE_MLX5_DR_ALLOW_DUPLICATE 409e39226bdSJiawei Wang DRV_LOG(WARNING, "Disallow duplicate pattern is not supported - maybe old rdma-core version?"); 410e39226bdSJiawei Wang #endif 411e39226bdSJiawei Wang mlx5_glue->dr_allow_duplicate_rules(sh->rx_domain, 0); 412e39226bdSJiawei Wang mlx5_glue->dr_allow_duplicate_rules(sh->tx_domain, 0); 413e39226bdSJiawei Wang if (sh->fdb_domain) 414e39226bdSJiawei Wang mlx5_glue->dr_allow_duplicate_rules(sh->fdb_domain, 0); 415e39226bdSJiawei Wang } 416630a587bSRongwei Liu 417630a587bSRongwei Liu __mlx5_discovery_misc5_cap(priv); 4182eb4d010SOphir Munk #endif /* HAVE_MLX5DV_DR */ 419b80726dcSSuanming Mou sh->default_miss_action = 420b80726dcSSuanming Mou mlx5_glue->dr_create_flow_action_default_miss(); 421b80726dcSSuanming Mou if (!sh->default_miss_action) 422b80726dcSSuanming Mou DRV_LOG(WARNING, "Default miss action is not supported."); 4232eb4d010SOphir Munk return 0; 4242eb4d010SOphir Munk error: 4252eb4d010SOphir Munk /* Rollback the created objects. */ 4262eb4d010SOphir Munk if (sh->rx_domain) { 4272eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->rx_domain); 4282eb4d010SOphir Munk sh->rx_domain = NULL; 4292eb4d010SOphir Munk } 4302eb4d010SOphir Munk if (sh->tx_domain) { 4312eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->tx_domain); 4322eb4d010SOphir Munk sh->tx_domain = NULL; 4332eb4d010SOphir Munk } 4342eb4d010SOphir Munk if (sh->fdb_domain) { 4352eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->fdb_domain); 4362eb4d010SOphir Munk sh->fdb_domain = NULL; 4372eb4d010SOphir Munk } 438da845ae9SViacheslav Ovsiienko if (sh->dr_drop_action) { 439da845ae9SViacheslav Ovsiienko mlx5_glue->destroy_flow_action(sh->dr_drop_action); 440da845ae9SViacheslav Ovsiienko sh->dr_drop_action = NULL; 4412eb4d010SOphir Munk } 4422eb4d010SOphir Munk if (sh->pop_vlan_action) { 4432eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->pop_vlan_action); 4442eb4d010SOphir Munk sh->pop_vlan_action = NULL; 4452eb4d010SOphir Munk } 446bf615b07SSuanming Mou if (sh->encaps_decaps) { 447e69a5922SXueming Li mlx5_hlist_destroy(sh->encaps_decaps); 448bf615b07SSuanming Mou sh->encaps_decaps = NULL; 449bf615b07SSuanming Mou } 4503fe88961SSuanming Mou if (sh->modify_cmds) { 451e69a5922SXueming Li mlx5_hlist_destroy(sh->modify_cmds); 4523fe88961SSuanming Mou sh->modify_cmds = NULL; 4533fe88961SSuanming Mou } 4542eb4d010SOphir Munk if (sh->tag_table) { 4552eb4d010SOphir Munk /* tags should be destroyed with flow before. */ 456e69a5922SXueming Li mlx5_hlist_destroy(sh->tag_table); 4572eb4d010SOphir Munk sh->tag_table = NULL; 4582eb4d010SOphir Munk } 4594ec6360dSGregory Etelson if (sh->tunnel_hub) { 4604ec6360dSGregory Etelson mlx5_release_tunnel_hub(sh, priv->dev_port); 4614ec6360dSGregory Etelson sh->tunnel_hub = NULL; 4624ec6360dSGregory Etelson } 4632eb4d010SOphir Munk mlx5_free_table_hash_list(priv); 464679f46c7SMatan Azrad if (sh->port_id_action_list) { 465679f46c7SMatan Azrad mlx5_list_destroy(sh->port_id_action_list); 466679f46c7SMatan Azrad sh->port_id_action_list = NULL; 467679f46c7SMatan Azrad } 468679f46c7SMatan Azrad if (sh->push_vlan_action_list) { 469679f46c7SMatan Azrad mlx5_list_destroy(sh->push_vlan_action_list); 470679f46c7SMatan Azrad sh->push_vlan_action_list = NULL; 471679f46c7SMatan Azrad } 472679f46c7SMatan Azrad if (sh->sample_action_list) { 473679f46c7SMatan Azrad mlx5_list_destroy(sh->sample_action_list); 474679f46c7SMatan Azrad sh->sample_action_list = NULL; 475679f46c7SMatan Azrad } 476679f46c7SMatan Azrad if (sh->dest_array_list) { 477679f46c7SMatan Azrad mlx5_list_destroy(sh->dest_array_list); 478679f46c7SMatan Azrad sh->dest_array_list = NULL; 479679f46c7SMatan Azrad } 4802eb4d010SOphir Munk return err; 4812eb4d010SOphir Munk } 4822eb4d010SOphir Munk 4832eb4d010SOphir Munk /** 4842eb4d010SOphir Munk * Destroy DR related data within private structure. 4852eb4d010SOphir Munk * 4862eb4d010SOphir Munk * @param[in] priv 4872eb4d010SOphir Munk * Pointer to the private device data structure. 4882eb4d010SOphir Munk */ 4892eb4d010SOphir Munk void 4902eb4d010SOphir Munk mlx5_os_free_shared_dr(struct mlx5_priv *priv) 4912eb4d010SOphir Munk { 49216dbba25SXueming Li struct mlx5_dev_ctx_shared *sh = priv->sh; 4932eb4d010SOphir Munk 49416dbba25SXueming Li MLX5_ASSERT(sh && sh->refcnt); 49516dbba25SXueming Li if (sh->refcnt > 1) 4962eb4d010SOphir Munk return; 4972eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR 4982eb4d010SOphir Munk if (sh->rx_domain) { 4992eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->rx_domain); 5002eb4d010SOphir Munk sh->rx_domain = NULL; 5012eb4d010SOphir Munk } 5022eb4d010SOphir Munk if (sh->tx_domain) { 5032eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->tx_domain); 5042eb4d010SOphir Munk sh->tx_domain = NULL; 5052eb4d010SOphir Munk } 5062eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 5072eb4d010SOphir Munk if (sh->fdb_domain) { 5082eb4d010SOphir Munk mlx5_glue->dr_destroy_domain(sh->fdb_domain); 5092eb4d010SOphir Munk sh->fdb_domain = NULL; 5102eb4d010SOphir Munk } 511da845ae9SViacheslav Ovsiienko if (sh->dr_drop_action) { 512da845ae9SViacheslav Ovsiienko mlx5_glue->destroy_flow_action(sh->dr_drop_action); 513da845ae9SViacheslav Ovsiienko sh->dr_drop_action = NULL; 5142eb4d010SOphir Munk } 5152eb4d010SOphir Munk #endif 5162eb4d010SOphir Munk if (sh->pop_vlan_action) { 5172eb4d010SOphir Munk mlx5_glue->destroy_flow_action(sh->pop_vlan_action); 5182eb4d010SOphir Munk sh->pop_vlan_action = NULL; 5192eb4d010SOphir Munk } 5202eb4d010SOphir Munk #endif /* HAVE_MLX5DV_DR */ 521b80726dcSSuanming Mou if (sh->default_miss_action) 522b80726dcSSuanming Mou mlx5_glue->destroy_flow_action 523b80726dcSSuanming Mou (sh->default_miss_action); 524bf615b07SSuanming Mou if (sh->encaps_decaps) { 525e69a5922SXueming Li mlx5_hlist_destroy(sh->encaps_decaps); 526bf615b07SSuanming Mou sh->encaps_decaps = NULL; 527bf615b07SSuanming Mou } 5283fe88961SSuanming Mou if (sh->modify_cmds) { 529e69a5922SXueming Li mlx5_hlist_destroy(sh->modify_cmds); 5303fe88961SSuanming Mou sh->modify_cmds = NULL; 5313fe88961SSuanming Mou } 5322eb4d010SOphir Munk if (sh->tag_table) { 5332eb4d010SOphir Munk /* tags should be destroyed with flow before. */ 534e69a5922SXueming Li mlx5_hlist_destroy(sh->tag_table); 5352eb4d010SOphir Munk sh->tag_table = NULL; 5362eb4d010SOphir Munk } 5374ec6360dSGregory Etelson if (sh->tunnel_hub) { 5384ec6360dSGregory Etelson mlx5_release_tunnel_hub(sh, priv->dev_port); 5394ec6360dSGregory Etelson sh->tunnel_hub = NULL; 5404ec6360dSGregory Etelson } 5412eb4d010SOphir Munk mlx5_free_table_hash_list(priv); 542679f46c7SMatan Azrad if (sh->port_id_action_list) { 543679f46c7SMatan Azrad mlx5_list_destroy(sh->port_id_action_list); 544679f46c7SMatan Azrad sh->port_id_action_list = NULL; 545679f46c7SMatan Azrad } 546679f46c7SMatan Azrad if (sh->push_vlan_action_list) { 547679f46c7SMatan Azrad mlx5_list_destroy(sh->push_vlan_action_list); 548679f46c7SMatan Azrad sh->push_vlan_action_list = NULL; 549679f46c7SMatan Azrad } 550679f46c7SMatan Azrad if (sh->sample_action_list) { 551679f46c7SMatan Azrad mlx5_list_destroy(sh->sample_action_list); 552679f46c7SMatan Azrad sh->sample_action_list = NULL; 553679f46c7SMatan Azrad } 554679f46c7SMatan Azrad if (sh->dest_array_list) { 555679f46c7SMatan Azrad mlx5_list_destroy(sh->dest_array_list); 556679f46c7SMatan Azrad sh->dest_array_list = NULL; 557679f46c7SMatan Azrad } 5582eb4d010SOphir Munk } 5592eb4d010SOphir Munk 5602eb4d010SOphir Munk /** 5612e86c4e5SOphir Munk * Initialize shared data between primary and secondary process. 5622e86c4e5SOphir Munk * 5632e86c4e5SOphir Munk * A memzone is reserved by primary process and secondary processes attach to 5642e86c4e5SOphir Munk * the memzone. 5652e86c4e5SOphir Munk * 5662e86c4e5SOphir Munk * @return 5672e86c4e5SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 5682e86c4e5SOphir Munk */ 5692e86c4e5SOphir Munk static int 5702e86c4e5SOphir Munk mlx5_init_shared_data(void) 5712e86c4e5SOphir Munk { 5722e86c4e5SOphir Munk const struct rte_memzone *mz; 5732e86c4e5SOphir Munk int ret = 0; 5742e86c4e5SOphir Munk 5752e86c4e5SOphir Munk rte_spinlock_lock(&mlx5_shared_data_lock); 5762e86c4e5SOphir Munk if (mlx5_shared_data == NULL) { 5772e86c4e5SOphir Munk if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 5782e86c4e5SOphir Munk /* Allocate shared memory. */ 5792e86c4e5SOphir Munk mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA, 5802e86c4e5SOphir Munk sizeof(*mlx5_shared_data), 5812e86c4e5SOphir Munk SOCKET_ID_ANY, 0); 5822e86c4e5SOphir Munk if (mz == NULL) { 5832e86c4e5SOphir Munk DRV_LOG(ERR, 5842e86c4e5SOphir Munk "Cannot allocate mlx5 shared data"); 5852e86c4e5SOphir Munk ret = -rte_errno; 5862e86c4e5SOphir Munk goto error; 5872e86c4e5SOphir Munk } 5882e86c4e5SOphir Munk mlx5_shared_data = mz->addr; 5892e86c4e5SOphir Munk memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data)); 5902e86c4e5SOphir Munk rte_spinlock_init(&mlx5_shared_data->lock); 5912e86c4e5SOphir Munk } else { 5922e86c4e5SOphir Munk /* Lookup allocated shared memory. */ 5932e86c4e5SOphir Munk mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA); 5942e86c4e5SOphir Munk if (mz == NULL) { 5952e86c4e5SOphir Munk DRV_LOG(ERR, 5962e86c4e5SOphir Munk "Cannot attach mlx5 shared data"); 5972e86c4e5SOphir Munk ret = -rte_errno; 5982e86c4e5SOphir Munk goto error; 5992e86c4e5SOphir Munk } 6002e86c4e5SOphir Munk mlx5_shared_data = mz->addr; 6012e86c4e5SOphir Munk memset(&mlx5_local_data, 0, sizeof(mlx5_local_data)); 6022e86c4e5SOphir Munk } 6032e86c4e5SOphir Munk } 6042e86c4e5SOphir Munk error: 6052e86c4e5SOphir Munk rte_spinlock_unlock(&mlx5_shared_data_lock); 6062e86c4e5SOphir Munk return ret; 6072e86c4e5SOphir Munk } 6082e86c4e5SOphir Munk 6092e86c4e5SOphir Munk /** 6102e86c4e5SOphir Munk * PMD global initialization. 6112e86c4e5SOphir Munk * 6122e86c4e5SOphir Munk * Independent from individual device, this function initializes global 6132e86c4e5SOphir Munk * per-PMD data structures distinguishing primary and secondary processes. 6142e86c4e5SOphir Munk * Hence, each initialization is called once per a process. 6152e86c4e5SOphir Munk * 6162e86c4e5SOphir Munk * @return 6172e86c4e5SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 6182e86c4e5SOphir Munk */ 6192e86c4e5SOphir Munk static int 6202e86c4e5SOphir Munk mlx5_init_once(void) 6212e86c4e5SOphir Munk { 6222e86c4e5SOphir Munk struct mlx5_shared_data *sd; 6232e86c4e5SOphir Munk struct mlx5_local_data *ld = &mlx5_local_data; 6242e86c4e5SOphir Munk int ret = 0; 6252e86c4e5SOphir Munk 6262e86c4e5SOphir Munk if (mlx5_init_shared_data()) 6272e86c4e5SOphir Munk return -rte_errno; 6282e86c4e5SOphir Munk sd = mlx5_shared_data; 6292e86c4e5SOphir Munk MLX5_ASSERT(sd); 6302e86c4e5SOphir Munk rte_spinlock_lock(&sd->lock); 6312e86c4e5SOphir Munk switch (rte_eal_process_type()) { 6322e86c4e5SOphir Munk case RTE_PROC_PRIMARY: 6332e86c4e5SOphir Munk if (sd->init_done) 6342e86c4e5SOphir Munk break; 6352e86c4e5SOphir Munk ret = mlx5_mp_init_primary(MLX5_MP_NAME, 6362e86c4e5SOphir Munk mlx5_mp_os_primary_handle); 6372e86c4e5SOphir Munk if (ret) 6382e86c4e5SOphir Munk goto out; 6392e86c4e5SOphir Munk sd->init_done = true; 6402e86c4e5SOphir Munk break; 6412e86c4e5SOphir Munk case RTE_PROC_SECONDARY: 6422e86c4e5SOphir Munk if (ld->init_done) 6432e86c4e5SOphir Munk break; 6442e86c4e5SOphir Munk ret = mlx5_mp_init_secondary(MLX5_MP_NAME, 6452e86c4e5SOphir Munk mlx5_mp_os_secondary_handle); 6462e86c4e5SOphir Munk if (ret) 6472e86c4e5SOphir Munk goto out; 6482e86c4e5SOphir Munk ++sd->secondary_cnt; 6492e86c4e5SOphir Munk ld->init_done = true; 6502e86c4e5SOphir Munk break; 6512e86c4e5SOphir Munk default: 6522e86c4e5SOphir Munk break; 6532e86c4e5SOphir Munk } 6542e86c4e5SOphir Munk out: 6552e86c4e5SOphir Munk rte_spinlock_unlock(&sd->lock); 6562e86c4e5SOphir Munk return ret; 6572e86c4e5SOphir Munk } 6582e86c4e5SOphir Munk 6592e86c4e5SOphir Munk /** 660994829e6SSuanming Mou * DV flow counter mode detect and config. 661994829e6SSuanming Mou * 662994829e6SSuanming Mou * @param dev 663994829e6SSuanming Mou * Pointer to rte_eth_dev structure. 664994829e6SSuanming Mou * 665994829e6SSuanming Mou */ 666994829e6SSuanming Mou static void 667994829e6SSuanming Mou mlx5_flow_counter_mode_config(struct rte_eth_dev *dev __rte_unused) 668994829e6SSuanming Mou { 669994829e6SSuanming Mou #ifdef HAVE_IBV_FLOW_DV_SUPPORT 670994829e6SSuanming Mou struct mlx5_priv *priv = dev->data->dev_private; 6712b5b1aebSSuanming Mou struct mlx5_dev_ctx_shared *sh = priv->sh; 6722b5b1aebSSuanming Mou bool fallback; 673994829e6SSuanming Mou 674994829e6SSuanming Mou #ifndef HAVE_IBV_DEVX_ASYNC 6752b5b1aebSSuanming Mou fallback = true; 676994829e6SSuanming Mou #else 6772b5b1aebSSuanming Mou fallback = false; 6785bc38358SMichael Baum if (!sh->devx || !priv->config.dv_flow_en || 6792b5b1aebSSuanming Mou !priv->config.hca_attr.flow_counters_dump || 680994829e6SSuanming Mou !(priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4) || 681994829e6SSuanming Mou (mlx5_flow_dv_discover_counter_offset_support(dev) == -ENOTSUP)) 6822b5b1aebSSuanming Mou fallback = true; 683994829e6SSuanming Mou #endif 6842b5b1aebSSuanming Mou if (fallback) 685994829e6SSuanming Mou DRV_LOG(INFO, "Use fall-back DV counter management. Flow " 686994829e6SSuanming Mou "counter dump:%d, bulk_alloc_bitmap:0x%hhx.", 687994829e6SSuanming Mou priv->config.hca_attr.flow_counters_dump, 688994829e6SSuanming Mou priv->config.hca_attr.flow_counter_bulk_alloc_bitmap); 6892b5b1aebSSuanming Mou /* Initialize fallback mode only on the port initializes sh. */ 6902b5b1aebSSuanming Mou if (sh->refcnt == 1) 6912b5b1aebSSuanming Mou sh->cmng.counter_fallback = fallback; 6922b5b1aebSSuanming Mou else if (fallback != sh->cmng.counter_fallback) 6932b5b1aebSSuanming Mou DRV_LOG(WARNING, "Port %d in sh has different fallback mode " 6942b5b1aebSSuanming Mou "with others:%d.", PORT_ID(priv), fallback); 695994829e6SSuanming Mou #endif 696994829e6SSuanming Mou } 697994829e6SSuanming Mou 69845633c46SSuanming Mou /** 69945633c46SSuanming Mou * DR flow drop action support detect. 70045633c46SSuanming Mou * 70145633c46SSuanming Mou * @param dev 70245633c46SSuanming Mou * Pointer to rte_eth_dev structure. 70345633c46SSuanming Mou * 70445633c46SSuanming Mou */ 70545633c46SSuanming Mou static void 70645633c46SSuanming Mou mlx5_flow_drop_action_config(struct rte_eth_dev *dev __rte_unused) 70745633c46SSuanming Mou { 70845633c46SSuanming Mou #ifdef HAVE_MLX5DV_DR 70945633c46SSuanming Mou struct mlx5_priv *priv = dev->data->dev_private; 71045633c46SSuanming Mou 71145633c46SSuanming Mou if (!priv->config.dv_flow_en || !priv->sh->dr_drop_action) 71245633c46SSuanming Mou return; 71345633c46SSuanming Mou /** 71445633c46SSuanming Mou * DR supports drop action placeholder when it is supported; 71545633c46SSuanming Mou * otherwise, use the queue drop action. 71645633c46SSuanming Mou */ 7173c4338a4SJiawei Wang if (!priv->sh->drop_action_check_flag) { 7183c4338a4SJiawei Wang if (!mlx5_flow_discover_dr_action_support(dev)) 7193c4338a4SJiawei Wang priv->sh->dr_drop_action_en = 1; 7203c4338a4SJiawei Wang priv->sh->drop_action_check_flag = 1; 7213c4338a4SJiawei Wang } 7223c4338a4SJiawei Wang if (priv->sh->dr_drop_action_en) 72345633c46SSuanming Mou priv->root_drop_action = priv->sh->dr_drop_action; 7243c4338a4SJiawei Wang else 7253c4338a4SJiawei Wang priv->root_drop_action = priv->drop_queue.hrxq->action; 72645633c46SSuanming Mou #endif 72745633c46SSuanming Mou } 72845633c46SSuanming Mou 729e6988afdSMatan Azrad static void 730e6988afdSMatan Azrad mlx5_queue_counter_id_prepare(struct rte_eth_dev *dev) 731e6988afdSMatan Azrad { 732e6988afdSMatan Azrad struct mlx5_priv *priv = dev->data->dev_private; 733ca1418ceSMichael Baum void *ctx = priv->sh->cdev->ctx; 734e6988afdSMatan Azrad 735e6988afdSMatan Azrad priv->q_counters = mlx5_devx_cmd_queue_counter_alloc(ctx); 736e6988afdSMatan Azrad if (!priv->q_counters) { 737e6988afdSMatan Azrad struct ibv_cq *cq = mlx5_glue->create_cq(ctx, 1, NULL, NULL, 0); 738e6988afdSMatan Azrad struct ibv_wq *wq; 739e6988afdSMatan Azrad 740e6988afdSMatan Azrad DRV_LOG(DEBUG, "Port %d queue counter object cannot be created " 741e6988afdSMatan Azrad "by DevX - fall-back to use the kernel driver global " 742e6988afdSMatan Azrad "queue counter.", dev->data->port_id); 743e6988afdSMatan Azrad /* Create WQ by kernel and query its queue counter ID. */ 744e6988afdSMatan Azrad if (cq) { 745e6988afdSMatan Azrad wq = mlx5_glue->create_wq(ctx, 746e6988afdSMatan Azrad &(struct ibv_wq_init_attr){ 747e6988afdSMatan Azrad .wq_type = IBV_WQT_RQ, 748e6988afdSMatan Azrad .max_wr = 1, 749e6988afdSMatan Azrad .max_sge = 1, 750e35ccf24SMichael Baum .pd = priv->sh->cdev->pd, 751e6988afdSMatan Azrad .cq = cq, 752e6988afdSMatan Azrad }); 753e6988afdSMatan Azrad if (wq) { 754e6988afdSMatan Azrad /* Counter is assigned only on RDY state. */ 755e6988afdSMatan Azrad int ret = mlx5_glue->modify_wq(wq, 756e6988afdSMatan Azrad &(struct ibv_wq_attr){ 757e6988afdSMatan Azrad .attr_mask = IBV_WQ_ATTR_STATE, 758e6988afdSMatan Azrad .wq_state = IBV_WQS_RDY, 759e6988afdSMatan Azrad }); 760e6988afdSMatan Azrad 761e6988afdSMatan Azrad if (ret == 0) 762e6988afdSMatan Azrad mlx5_devx_cmd_wq_query(wq, 763e6988afdSMatan Azrad &priv->counter_set_id); 764e6988afdSMatan Azrad claim_zero(mlx5_glue->destroy_wq(wq)); 765e6988afdSMatan Azrad } 766e6988afdSMatan Azrad claim_zero(mlx5_glue->destroy_cq(cq)); 767e6988afdSMatan Azrad } 768e6988afdSMatan Azrad } else { 769e6988afdSMatan Azrad priv->counter_set_id = priv->q_counters->id; 770e6988afdSMatan Azrad } 771e6988afdSMatan Azrad if (priv->counter_set_id == 0) 772e6988afdSMatan Azrad DRV_LOG(INFO, "Part of the port %d statistics will not be " 773e6988afdSMatan Azrad "available.", dev->data->port_id); 774e6988afdSMatan Azrad } 775e6988afdSMatan Azrad 776994829e6SSuanming Mou /** 777f926cce3SXueming Li * Check if representor spawn info match devargs. 778f926cce3SXueming Li * 779f926cce3SXueming Li * @param spawn 780f926cce3SXueming Li * Verbs device parameters (name, port, switch_info) to spawn. 781f926cce3SXueming Li * @param eth_da 782f926cce3SXueming Li * Device devargs to probe. 783f926cce3SXueming Li * 784f926cce3SXueming Li * @return 785f926cce3SXueming Li * Match result. 786f926cce3SXueming Li */ 787f926cce3SXueming Li static bool 788f926cce3SXueming Li mlx5_representor_match(struct mlx5_dev_spawn_data *spawn, 789f926cce3SXueming Li struct rte_eth_devargs *eth_da) 790f926cce3SXueming Li { 791f926cce3SXueming Li struct mlx5_switch_info *switch_info = &spawn->info; 792f926cce3SXueming Li unsigned int p, f; 793f926cce3SXueming Li uint16_t id; 79491766faeSXueming Li uint16_t repr_id = mlx5_representor_id_encode(switch_info, 79591766faeSXueming Li eth_da->type); 796f926cce3SXueming Li 797f926cce3SXueming Li switch (eth_da->type) { 798f926cce3SXueming Li case RTE_ETH_REPRESENTOR_SF: 79991766faeSXueming Li if (!(spawn->info.port_name == -1 && 80091766faeSXueming Li switch_info->name_type == 80191766faeSXueming Li MLX5_PHYS_PORT_NAME_TYPE_PFHPF) && 80291766faeSXueming Li switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_PFSF) { 803f926cce3SXueming Li rte_errno = EBUSY; 804f926cce3SXueming Li return false; 805f926cce3SXueming Li } 806f926cce3SXueming Li break; 807f926cce3SXueming Li case RTE_ETH_REPRESENTOR_VF: 808f926cce3SXueming Li /* Allows HPF representor index -1 as exception. */ 809f926cce3SXueming Li if (!(spawn->info.port_name == -1 && 810f926cce3SXueming Li switch_info->name_type == 811f926cce3SXueming Li MLX5_PHYS_PORT_NAME_TYPE_PFHPF) && 812f926cce3SXueming Li switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_PFVF) { 813f926cce3SXueming Li rte_errno = EBUSY; 814f926cce3SXueming Li return false; 815f926cce3SXueming Li } 816f926cce3SXueming Li break; 817f926cce3SXueming Li case RTE_ETH_REPRESENTOR_NONE: 818f926cce3SXueming Li rte_errno = EBUSY; 819f926cce3SXueming Li return false; 820f926cce3SXueming Li default: 821f926cce3SXueming Li rte_errno = ENOTSUP; 822f926cce3SXueming Li DRV_LOG(ERR, "unsupported representor type"); 823f926cce3SXueming Li return false; 824f926cce3SXueming Li } 825f926cce3SXueming Li /* Check representor ID: */ 826f926cce3SXueming Li for (p = 0; p < eth_da->nb_ports; ++p) { 827f926cce3SXueming Li if (spawn->pf_bond < 0) { 828f926cce3SXueming Li /* For non-LAG mode, allow and ignore pf. */ 829f926cce3SXueming Li switch_info->pf_num = eth_da->ports[p]; 83091766faeSXueming Li repr_id = mlx5_representor_id_encode(switch_info, 83191766faeSXueming Li eth_da->type); 832f926cce3SXueming Li } 833f926cce3SXueming Li for (f = 0; f < eth_da->nb_representor_ports; ++f) { 834f926cce3SXueming Li id = MLX5_REPRESENTOR_ID 835f926cce3SXueming Li (eth_da->ports[p], eth_da->type, 836f926cce3SXueming Li eth_da->representor_ports[f]); 837f926cce3SXueming Li if (repr_id == id) 838f926cce3SXueming Li return true; 839f926cce3SXueming Li } 840f926cce3SXueming Li } 841f926cce3SXueming Li rte_errno = EBUSY; 842f926cce3SXueming Li return false; 843f926cce3SXueming Li } 844f926cce3SXueming Li 845f926cce3SXueming Li /** 8462eb4d010SOphir Munk * Spawn an Ethernet device from Verbs information. 8472eb4d010SOphir Munk * 8482eb4d010SOphir Munk * @param dpdk_dev 8492eb4d010SOphir Munk * Backing DPDK device. 8502eb4d010SOphir Munk * @param spawn 8512eb4d010SOphir Munk * Verbs device parameters (name, port, switch_info) to spawn. 8522eb4d010SOphir Munk * @param config 8532eb4d010SOphir Munk * Device configuration parameters. 854887183efSMichael Baum * @param eth_da 855cb95feefSXueming Li * Device arguments. 8562eb4d010SOphir Munk * 8572eb4d010SOphir Munk * @return 8582eb4d010SOphir Munk * A valid Ethernet device object on success, NULL otherwise and rte_errno 8592eb4d010SOphir Munk * is set. The following errors are defined: 8602eb4d010SOphir Munk * 8612eb4d010SOphir Munk * EBUSY: device is not supposed to be spawned. 8622eb4d010SOphir Munk * EEXIST: device is already spawned 8632eb4d010SOphir Munk */ 8642eb4d010SOphir Munk static struct rte_eth_dev * 8652eb4d010SOphir Munk mlx5_dev_spawn(struct rte_device *dpdk_dev, 8662eb4d010SOphir Munk struct mlx5_dev_spawn_data *spawn, 867cb95feefSXueming Li struct mlx5_dev_config *config, 868cb95feefSXueming Li struct rte_eth_devargs *eth_da) 8692eb4d010SOphir Munk { 8702eb4d010SOphir Munk const struct mlx5_switch_info *switch_info = &spawn->info; 8712eb4d010SOphir Munk struct mlx5_dev_ctx_shared *sh = NULL; 8723fd2961eSXueming Li struct ibv_port_attr port_attr = { .state = IBV_PORT_NOP }; 8732eb4d010SOphir Munk struct mlx5dv_context dv_attr = { .comp_mask = 0 }; 8742eb4d010SOphir Munk struct rte_eth_dev *eth_dev = NULL; 8752eb4d010SOphir Munk struct mlx5_priv *priv = NULL; 8762eb4d010SOphir Munk int err = 0; 8772eb4d010SOphir Munk unsigned int hw_padding = 0; 8782eb4d010SOphir Munk unsigned int mps; 8792eb4d010SOphir Munk unsigned int mpls_en = 0; 8802eb4d010SOphir Munk unsigned int swp = 0; 8812eb4d010SOphir Munk unsigned int mprq = 0; 8822eb4d010SOphir Munk unsigned int mprq_min_stride_size_n = 0; 8832eb4d010SOphir Munk unsigned int mprq_max_stride_size_n = 0; 8842eb4d010SOphir Munk unsigned int mprq_min_stride_num_n = 0; 8852eb4d010SOphir Munk unsigned int mprq_max_stride_num_n = 0; 8862eb4d010SOphir Munk struct rte_ether_addr mac; 8872eb4d010SOphir Munk char name[RTE_ETH_NAME_MAX_LEN]; 8882eb4d010SOphir Munk int own_domain_id = 0; 8892eb4d010SOphir Munk uint16_t port_id; 890d0cf77e8SViacheslav Ovsiienko struct mlx5_port_info vport_info = { .query_flags = 0 }; 8913fd2961eSXueming Li int nl_rdma = -1; 892b4edeaf3SSuanming Mou int i; 8932eb4d010SOphir Munk 8942eb4d010SOphir Munk /* Determine if this port representor is supposed to be spawned. */ 895f926cce3SXueming Li if (switch_info->representor && dpdk_dev->devargs && 896f926cce3SXueming Li !mlx5_representor_match(spawn, eth_da)) 897d6541676SXueming Li return NULL; 8982eb4d010SOphir Munk /* Build device name. */ 8992eb4d010SOphir Munk if (spawn->pf_bond < 0) { 9002eb4d010SOphir Munk /* Single device. */ 9012eb4d010SOphir Munk if (!switch_info->representor) 9022eb4d010SOphir Munk strlcpy(name, dpdk_dev->name, sizeof(name)); 9032eb4d010SOphir Munk else 904f926cce3SXueming Li err = snprintf(name, sizeof(name), "%s_representor_%s%u", 905cb95feefSXueming Li dpdk_dev->name, 906cb95feefSXueming Li switch_info->name_type == 907cb95feefSXueming Li MLX5_PHYS_PORT_NAME_TYPE_PFSF ? "sf" : "vf", 908cb95feefSXueming Li switch_info->port_name); 9092eb4d010SOphir Munk } else { 9102eb4d010SOphir Munk /* Bonding device. */ 911f926cce3SXueming Li if (!switch_info->representor) { 912f926cce3SXueming Li err = snprintf(name, sizeof(name), "%s_%s", 913887183efSMichael Baum dpdk_dev->name, spawn->phys_dev_name); 914f926cce3SXueming Li } else { 915f926cce3SXueming Li err = snprintf(name, sizeof(name), "%s_%s_representor_c%dpf%d%s%u", 916887183efSMichael Baum dpdk_dev->name, spawn->phys_dev_name, 917f926cce3SXueming Li switch_info->ctrl_num, 918f926cce3SXueming Li switch_info->pf_num, 919cb95feefSXueming Li switch_info->name_type == 920cb95feefSXueming Li MLX5_PHYS_PORT_NAME_TYPE_PFSF ? "sf" : "vf", 9212eb4d010SOphir Munk switch_info->port_name); 9222eb4d010SOphir Munk } 923f926cce3SXueming Li } 924f926cce3SXueming Li if (err >= (int)sizeof(name)) 925f926cce3SXueming Li DRV_LOG(WARNING, "device name overflow %s", name); 9262eb4d010SOphir Munk /* check if the device is already spawned */ 9272eb4d010SOphir Munk if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) { 9282eb4d010SOphir Munk rte_errno = EEXIST; 9292eb4d010SOphir Munk return NULL; 9302eb4d010SOphir Munk } 9312eb4d010SOphir Munk DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name); 9322eb4d010SOphir Munk if (rte_eal_process_type() == RTE_PROC_SECONDARY) { 9332eb4d010SOphir Munk struct mlx5_mp_id mp_id; 9342eb4d010SOphir Munk 9352eb4d010SOphir Munk eth_dev = rte_eth_dev_attach_secondary(name); 9362eb4d010SOphir Munk if (eth_dev == NULL) { 9372eb4d010SOphir Munk DRV_LOG(ERR, "can not attach rte ethdev"); 9382eb4d010SOphir Munk rte_errno = ENOMEM; 9392eb4d010SOphir Munk return NULL; 9402eb4d010SOphir Munk } 9412eb4d010SOphir Munk eth_dev->device = dpdk_dev; 942b012b4ceSOphir Munk eth_dev->dev_ops = &mlx5_dev_sec_ops; 943cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 944cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 9452eb4d010SOphir Munk err = mlx5_proc_priv_init(eth_dev); 9462eb4d010SOphir Munk if (err) 9472eb4d010SOphir Munk return NULL; 948fec28ca0SDmitry Kozlyuk mlx5_mp_id_init(&mp_id, eth_dev->data->port_id); 9492eb4d010SOphir Munk /* Receive command fd from primary process */ 9502eb4d010SOphir Munk err = mlx5_mp_req_verbs_cmd_fd(&mp_id); 9512eb4d010SOphir Munk if (err < 0) 9522eb4d010SOphir Munk goto err_secondary; 9532eb4d010SOphir Munk /* Remap UAR for Tx queues. */ 9542eb4d010SOphir Munk err = mlx5_tx_uar_init_secondary(eth_dev, err); 9552eb4d010SOphir Munk if (err) 9562eb4d010SOphir Munk goto err_secondary; 9572eb4d010SOphir Munk /* 9582eb4d010SOphir Munk * Ethdev pointer is still required as input since 9592eb4d010SOphir Munk * the primary device is not accessible from the 9602eb4d010SOphir Munk * secondary process. 9612eb4d010SOphir Munk */ 9622eb4d010SOphir Munk eth_dev->rx_pkt_burst = mlx5_select_rx_function(eth_dev); 9632eb4d010SOphir Munk eth_dev->tx_pkt_burst = mlx5_select_tx_function(eth_dev); 9642eb4d010SOphir Munk return eth_dev; 9652eb4d010SOphir Munk err_secondary: 9662eb4d010SOphir Munk mlx5_dev_close(eth_dev); 9672eb4d010SOphir Munk return NULL; 9682eb4d010SOphir Munk } 9692eb4d010SOphir Munk /* 9702eb4d010SOphir Munk * Some parameters ("tx_db_nc" in particularly) are needed in 9712eb4d010SOphir Munk * advance to create dv/verbs device context. We proceed the 9722eb4d010SOphir Munk * devargs here to get ones, and later proceed devargs again 9732eb4d010SOphir Munk * to override some hardware settings. 9742eb4d010SOphir Munk */ 975d462a83cSMichael Baum err = mlx5_args(config, dpdk_dev->devargs); 9762eb4d010SOphir Munk if (err) { 9772eb4d010SOphir Munk err = rte_errno; 9782eb4d010SOphir Munk DRV_LOG(ERR, "failed to process device arguments: %s", 9792eb4d010SOphir Munk strerror(rte_errno)); 9802eb4d010SOphir Munk goto error; 9812eb4d010SOphir Munk } 9824ec6360dSGregory Etelson if (config->dv_miss_info) { 9834ec6360dSGregory Etelson if (switch_info->master || switch_info->representor) 9844ec6360dSGregory Etelson config->dv_xmeta_en = MLX5_XMETA_MODE_META16; 9854ec6360dSGregory Etelson } 986d462a83cSMichael Baum sh = mlx5_alloc_shared_dev_ctx(spawn, config); 9872eb4d010SOphir Munk if (!sh) 9882eb4d010SOphir Munk return NULL; 9892eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ACTION_DEST_DEVX_TIR 990d462a83cSMichael Baum config->dest_tir = 1; 9912eb4d010SOphir Munk #endif 9922eb4d010SOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 9932eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_SWP; 9942eb4d010SOphir Munk #endif 9952eb4d010SOphir Munk /* 9962eb4d010SOphir Munk * Multi-packet send is supported by ConnectX-4 Lx PF as well 9972eb4d010SOphir Munk * as all ConnectX-5 devices. 9982eb4d010SOphir Munk */ 9992eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 10002eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS; 10012eb4d010SOphir Munk #endif 10022eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT 10032eb4d010SOphir Munk dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_STRIDING_RQ; 10042eb4d010SOphir Munk #endif 1005ca1418ceSMichael Baum mlx5_glue->dv_query_device(sh->cdev->ctx, &dv_attr); 10062eb4d010SOphir Munk if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED) { 10072eb4d010SOphir Munk if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW) { 10082eb4d010SOphir Munk DRV_LOG(DEBUG, "enhanced MPW is supported"); 10092eb4d010SOphir Munk mps = MLX5_MPW_ENHANCED; 10102eb4d010SOphir Munk } else { 10112eb4d010SOphir Munk DRV_LOG(DEBUG, "MPW is supported"); 10122eb4d010SOphir Munk mps = MLX5_MPW; 10132eb4d010SOphir Munk } 10142eb4d010SOphir Munk } else { 10152eb4d010SOphir Munk DRV_LOG(DEBUG, "MPW isn't supported"); 10162eb4d010SOphir Munk mps = MLX5_MPW_DISABLED; 10172eb4d010SOphir Munk } 10182eb4d010SOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 10192eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_SWP) 10202eb4d010SOphir Munk swp = dv_attr.sw_parsing_caps.sw_parsing_offloads; 10212eb4d010SOphir Munk DRV_LOG(DEBUG, "SWP support: %u", swp); 10222eb4d010SOphir Munk #endif 1023accf3cfcSTal Shnaiderman config->swp = swp & (MLX5_SW_PARSING_CAP | MLX5_SW_PARSING_CSUM_CAP | 1024accf3cfcSTal Shnaiderman MLX5_SW_PARSING_TSO_CAP); 10252eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT 10262eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_STRIDING_RQ) { 10272eb4d010SOphir Munk struct mlx5dv_striding_rq_caps mprq_caps = 10282eb4d010SOphir Munk dv_attr.striding_rq_caps; 10292eb4d010SOphir Munk 10302eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmin_single_stride_log_num_of_bytes: %d", 10312eb4d010SOphir Munk mprq_caps.min_single_stride_log_num_of_bytes); 10322eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmax_single_stride_log_num_of_bytes: %d", 10332eb4d010SOphir Munk mprq_caps.max_single_stride_log_num_of_bytes); 10342eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmin_single_wqe_log_num_of_strides: %d", 10352eb4d010SOphir Munk mprq_caps.min_single_wqe_log_num_of_strides); 10362eb4d010SOphir Munk DRV_LOG(DEBUG, "\tmax_single_wqe_log_num_of_strides: %d", 10372eb4d010SOphir Munk mprq_caps.max_single_wqe_log_num_of_strides); 10382eb4d010SOphir Munk DRV_LOG(DEBUG, "\tsupported_qpts: %d", 10392eb4d010SOphir Munk mprq_caps.supported_qpts); 10402eb4d010SOphir Munk DRV_LOG(DEBUG, "device supports Multi-Packet RQ"); 10412eb4d010SOphir Munk mprq = 1; 10422eb4d010SOphir Munk mprq_min_stride_size_n = 10432eb4d010SOphir Munk mprq_caps.min_single_stride_log_num_of_bytes; 10442eb4d010SOphir Munk mprq_max_stride_size_n = 10452eb4d010SOphir Munk mprq_caps.max_single_stride_log_num_of_bytes; 10462eb4d010SOphir Munk mprq_min_stride_num_n = 10472eb4d010SOphir Munk mprq_caps.min_single_wqe_log_num_of_strides; 10482eb4d010SOphir Munk mprq_max_stride_num_n = 10492eb4d010SOphir Munk mprq_caps.max_single_wqe_log_num_of_strides; 10502eb4d010SOphir Munk } 10512eb4d010SOphir Munk #endif 10523d3f4e6dSAlexander Kozyrev /* Rx CQE compression is enabled by default. */ 10533d3f4e6dSAlexander Kozyrev config->cqe_comp = 1; 10542eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 10552eb4d010SOphir Munk if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS) { 1056c1a320bfSTal Shnaiderman config->tunnel_en = dv_attr.tunnel_offloads_caps & 1057c1a320bfSTal Shnaiderman (MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_VXLAN | 1058c1a320bfSTal Shnaiderman MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GRE | 1059c1a320bfSTal Shnaiderman MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GENEVE); 10602eb4d010SOphir Munk } 1061c1a320bfSTal Shnaiderman if (config->tunnel_en) { 1062c1a320bfSTal Shnaiderman DRV_LOG(DEBUG, "tunnel offloading is supported for %s%s%s", 1063c1a320bfSTal Shnaiderman config->tunnel_en & 1064c1a320bfSTal Shnaiderman MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_VXLAN ? "[VXLAN]" : "", 1065c1a320bfSTal Shnaiderman config->tunnel_en & 1066c1a320bfSTal Shnaiderman MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GRE ? "[GRE]" : "", 1067c1a320bfSTal Shnaiderman config->tunnel_en & 1068c1a320bfSTal Shnaiderman MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GENEVE ? "[GENEVE]" : "" 1069c1a320bfSTal Shnaiderman ); 1070c1a320bfSTal Shnaiderman } else { 1071c1a320bfSTal Shnaiderman DRV_LOG(DEBUG, "tunnel offloading is not supported"); 1072c1a320bfSTal Shnaiderman } 10732eb4d010SOphir Munk #else 10742eb4d010SOphir Munk DRV_LOG(WARNING, 10752eb4d010SOphir Munk "tunnel offloading disabled due to old OFED/rdma-core version"); 10762eb4d010SOphir Munk #endif 10772eb4d010SOphir Munk #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT 10782eb4d010SOphir Munk mpls_en = ((dv_attr.tunnel_offloads_caps & 10792eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_GRE) && 10802eb4d010SOphir Munk (dv_attr.tunnel_offloads_caps & 10812eb4d010SOphir Munk MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_UDP)); 10822eb4d010SOphir Munk DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is %ssupported", 10832eb4d010SOphir Munk mpls_en ? "" : "not "); 10842eb4d010SOphir Munk #else 10852eb4d010SOphir Munk DRV_LOG(WARNING, "MPLS over GRE/UDP tunnel offloading disabled due to" 10862eb4d010SOphir Munk " old OFED/rdma-core version or firmware configuration"); 10872eb4d010SOphir Munk #endif 1088d462a83cSMichael Baum config->mpls_en = mpls_en; 10893fd2961eSXueming Li nl_rdma = mlx5_nl_init(NETLINK_RDMA); 10902eb4d010SOphir Munk /* Check port status. */ 10913fd2961eSXueming Li if (spawn->phys_port <= UINT8_MAX) { 10923fd2961eSXueming Li /* Legacy Verbs api only support u8 port number. */ 1093ca1418ceSMichael Baum err = mlx5_glue->query_port(sh->cdev->ctx, spawn->phys_port, 1094ca1418ceSMichael Baum &port_attr); 10952eb4d010SOphir Munk if (err) { 10962eb4d010SOphir Munk DRV_LOG(ERR, "port query failed: %s", strerror(err)); 10972eb4d010SOphir Munk goto error; 10982eb4d010SOphir Munk } 10992eb4d010SOphir Munk if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) { 11002eb4d010SOphir Munk DRV_LOG(ERR, "port is not configured in Ethernet mode"); 11012eb4d010SOphir Munk err = EINVAL; 11022eb4d010SOphir Munk goto error; 11032eb4d010SOphir Munk } 11043fd2961eSXueming Li } else if (nl_rdma >= 0) { 11053fd2961eSXueming Li /* IB doesn't allow more than 255 ports, must be Ethernet. */ 11063fd2961eSXueming Li err = mlx5_nl_port_state(nl_rdma, 11073fd2961eSXueming Li spawn->phys_dev_name, 11083fd2961eSXueming Li spawn->phys_port); 11093fd2961eSXueming Li if (err < 0) { 11103fd2961eSXueming Li DRV_LOG(INFO, "Failed to get netlink port state: %s", 11113fd2961eSXueming Li strerror(rte_errno)); 11123fd2961eSXueming Li err = -rte_errno; 11133fd2961eSXueming Li goto error; 11143fd2961eSXueming Li } 11153fd2961eSXueming Li port_attr.state = (enum ibv_port_state)err; 11163fd2961eSXueming Li } 11172eb4d010SOphir Munk if (port_attr.state != IBV_PORT_ACTIVE) 11183fd2961eSXueming Li DRV_LOG(INFO, "port is not active: \"%s\" (%d)", 11192eb4d010SOphir Munk mlx5_glue->port_state_str(port_attr.state), 11202eb4d010SOphir Munk port_attr.state); 11212eb4d010SOphir Munk /* Allocate private eth device data. */ 11222175c4dcSSuanming Mou priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, 11232eb4d010SOphir Munk sizeof(*priv), 11242175c4dcSSuanming Mou RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 11252eb4d010SOphir Munk if (priv == NULL) { 11262eb4d010SOphir Munk DRV_LOG(ERR, "priv allocation failure"); 11272eb4d010SOphir Munk err = ENOMEM; 11282eb4d010SOphir Munk goto error; 11292eb4d010SOphir Munk } 11302eb4d010SOphir Munk priv->sh = sh; 113191389890SOphir Munk priv->dev_port = spawn->phys_port; 11322eb4d010SOphir Munk priv->pci_dev = spawn->pci_dev; 11332eb4d010SOphir Munk priv->mtu = RTE_ETHER_MTU; 11342eb4d010SOphir Munk /* Some internal functions rely on Netlink sockets, open them now. */ 11353fd2961eSXueming Li priv->nl_socket_rdma = nl_rdma; 11362eb4d010SOphir Munk priv->nl_socket_route = mlx5_nl_init(NETLINK_ROUTE); 11372eb4d010SOphir Munk priv->representor = !!switch_info->representor; 11382eb4d010SOphir Munk priv->master = !!switch_info->master; 11392eb4d010SOphir Munk priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 11402eb4d010SOphir Munk priv->vport_meta_tag = 0; 11412eb4d010SOphir Munk priv->vport_meta_mask = 0; 11422eb4d010SOphir Munk priv->pf_bond = spawn->pf_bond; 1143ce4062cbSGregory Etelson 1144ce4062cbSGregory Etelson DRV_LOG(DEBUG, 1145ce4062cbSGregory Etelson "dev_port=%u bus=%s pci=%s master=%d representor=%d pf_bond=%d\n", 1146ce4062cbSGregory Etelson priv->dev_port, dpdk_dev->bus->name, 1147ce4062cbSGregory Etelson priv->pci_dev ? priv->pci_dev->name : "NONE", 1148ce4062cbSGregory Etelson priv->master, priv->representor, priv->pf_bond); 1149ce4062cbSGregory Etelson 11502eb4d010SOphir Munk /* 1151d0cf77e8SViacheslav Ovsiienko * If we have E-Switch we should determine the vport attributes. 1152d0cf77e8SViacheslav Ovsiienko * E-Switch may use either source vport field or reg_c[0] metadata 1153d0cf77e8SViacheslav Ovsiienko * register to match on vport index. The engaged part of metadata 1154d0cf77e8SViacheslav Ovsiienko * register is defined by mask. 11552eb4d010SOphir Munk */ 11562eb4d010SOphir Munk if (switch_info->representor || switch_info->master) { 1157ca1418ceSMichael Baum err = mlx5_glue->devx_port_query(sh->cdev->ctx, 1158d0cf77e8SViacheslav Ovsiienko spawn->phys_port, 1159d0cf77e8SViacheslav Ovsiienko &vport_info); 11602eb4d010SOphir Munk if (err) { 11612eb4d010SOphir Munk DRV_LOG(WARNING, 1162887183efSMichael Baum "Cannot query devx port %d on device %s", 1163887183efSMichael Baum spawn->phys_port, spawn->phys_dev_name); 1164d0cf77e8SViacheslav Ovsiienko vport_info.query_flags = 0; 11652eb4d010SOphir Munk } 11662eb4d010SOphir Munk } 1167d0cf77e8SViacheslav Ovsiienko if (vport_info.query_flags & MLX5_PORT_QUERY_REG_C0) { 1168d0cf77e8SViacheslav Ovsiienko priv->vport_meta_tag = vport_info.vport_meta_tag; 1169d0cf77e8SViacheslav Ovsiienko priv->vport_meta_mask = vport_info.vport_meta_mask; 11702eb4d010SOphir Munk if (!priv->vport_meta_mask) { 1171887183efSMichael Baum DRV_LOG(ERR, 1172887183efSMichael Baum "vport zero mask for port %d on bonding device %s", 1173887183efSMichael Baum spawn->phys_port, spawn->phys_dev_name); 11742eb4d010SOphir Munk err = ENOTSUP; 11752eb4d010SOphir Munk goto error; 11762eb4d010SOphir Munk } 11772eb4d010SOphir Munk if (priv->vport_meta_tag & ~priv->vport_meta_mask) { 1178887183efSMichael Baum DRV_LOG(ERR, 1179887183efSMichael Baum "Invalid vport tag for port %d on bonding device %s", 1180887183efSMichael Baum spawn->phys_port, spawn->phys_dev_name); 11812eb4d010SOphir Munk err = ENOTSUP; 11822eb4d010SOphir Munk goto error; 11832eb4d010SOphir Munk } 11842eb4d010SOphir Munk } 1185d0cf77e8SViacheslav Ovsiienko if (vport_info.query_flags & MLX5_PORT_QUERY_VPORT) { 1186d0cf77e8SViacheslav Ovsiienko priv->vport_id = vport_info.vport_id; 1187ecaee305SViacheslav Ovsiienko } else if (spawn->pf_bond >= 0 && 1188ecaee305SViacheslav Ovsiienko (switch_info->representor || switch_info->master)) { 1189887183efSMichael Baum DRV_LOG(ERR, 1190887183efSMichael Baum "Cannot deduce vport index for port %d on bonding device %s", 1191887183efSMichael Baum spawn->phys_port, spawn->phys_dev_name); 11922eb4d010SOphir Munk err = ENOTSUP; 11932eb4d010SOphir Munk goto error; 11942eb4d010SOphir Munk } else { 11952eb4d010SOphir Munk /* 1196d0cf77e8SViacheslav Ovsiienko * Suppose vport index in compatible way. Kernel/rdma_core 1197d0cf77e8SViacheslav Ovsiienko * support single E-Switch per PF configurations only and 1198d0cf77e8SViacheslav Ovsiienko * vport_id field contains the vport index for associated VF, 1199d0cf77e8SViacheslav Ovsiienko * which is deduced from representor port name. 12002eb4d010SOphir Munk * For example, let's have the IB device port 10, it has 12012eb4d010SOphir Munk * attached network device eth0, which has port name attribute 12022eb4d010SOphir Munk * pf0vf2, we can deduce the VF number as 2, and set vport index 12032eb4d010SOphir Munk * as 3 (2+1). This assigning schema should be changed if the 12042eb4d010SOphir Munk * multiple E-Switch instances per PF configurations or/and PCI 12052eb4d010SOphir Munk * subfunctions are added. 12062eb4d010SOphir Munk */ 12072eb4d010SOphir Munk priv->vport_id = switch_info->representor ? 12082eb4d010SOphir Munk switch_info->port_name + 1 : -1; 1209d0cf77e8SViacheslav Ovsiienko } 121091766faeSXueming Li priv->representor_id = mlx5_representor_id_encode(switch_info, 121191766faeSXueming Li eth_da->type); 12122eb4d010SOphir Munk /* 12132eb4d010SOphir Munk * Look for sibling devices in order to reuse their switch domain 12142eb4d010SOphir Munk * if any, otherwise allocate one. 12152eb4d010SOphir Munk */ 1216ce4062cbSGregory Etelson MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 12172eb4d010SOphir Munk const struct mlx5_priv *opriv = 12182eb4d010SOphir Munk rte_eth_devices[port_id].data->dev_private; 12192eb4d010SOphir Munk 12202eb4d010SOphir Munk if (!opriv || 12212eb4d010SOphir Munk opriv->sh != priv->sh || 12222eb4d010SOphir Munk opriv->domain_id == 12232eb4d010SOphir Munk RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) 12242eb4d010SOphir Munk continue; 12252eb4d010SOphir Munk priv->domain_id = opriv->domain_id; 1226ce4062cbSGregory Etelson DRV_LOG(DEBUG, "dev_port-%u inherit domain_id=%u\n", 1227ce4062cbSGregory Etelson priv->dev_port, priv->domain_id); 12282eb4d010SOphir Munk break; 12292eb4d010SOphir Munk } 12302eb4d010SOphir Munk if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { 12312eb4d010SOphir Munk err = rte_eth_switch_domain_alloc(&priv->domain_id); 12322eb4d010SOphir Munk if (err) { 12332eb4d010SOphir Munk err = rte_errno; 12342eb4d010SOphir Munk DRV_LOG(ERR, "unable to allocate switch domain: %s", 12352eb4d010SOphir Munk strerror(rte_errno)); 12362eb4d010SOphir Munk goto error; 12372eb4d010SOphir Munk } 12382eb4d010SOphir Munk own_domain_id = 1; 1239ce4062cbSGregory Etelson DRV_LOG(DEBUG, "dev_port-%u new domain_id=%u\n", 1240ce4062cbSGregory Etelson priv->dev_port, priv->domain_id); 12412eb4d010SOphir Munk } 12422eb4d010SOphir Munk /* Override some values set by hardware configuration. */ 1243d462a83cSMichael Baum mlx5_args(config, dpdk_dev->devargs); 1244e9d420dfSGregory Etelson err = mlx5_dev_check_sibling_config(priv, config, dpdk_dev); 12452eb4d010SOphir Munk if (err) 12462eb4d010SOphir Munk goto error; 1247d462a83cSMichael Baum config->hw_csum = !!(sh->device_attr.device_cap_flags_ex & 12482eb4d010SOphir Munk IBV_DEVICE_RAW_IP_CSUM); 12492eb4d010SOphir Munk DRV_LOG(DEBUG, "checksum offloading is %ssupported", 1250d462a83cSMichael Baum (config->hw_csum ? "" : "not ")); 12512eb4d010SOphir Munk #if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \ 12522eb4d010SOphir Munk !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) 12532eb4d010SOphir Munk DRV_LOG(DEBUG, "counters are not supported"); 12542eb4d010SOphir Munk #endif 12552eb4d010SOphir Munk #if !defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_MLX5DV_DR) 1256d462a83cSMichael Baum if (config->dv_flow_en) { 12572eb4d010SOphir Munk DRV_LOG(WARNING, "DV flow is not supported"); 1258d462a83cSMichael Baum config->dv_flow_en = 0; 12592eb4d010SOphir Munk } 12602eb4d010SOphir Munk #endif 1261d462a83cSMichael Baum config->ind_table_max_size = 12622eb4d010SOphir Munk sh->device_attr.max_rwq_indirection_table_size; 12632eb4d010SOphir Munk /* 12642eb4d010SOphir Munk * Remove this check once DPDK supports larger/variable 12652eb4d010SOphir Munk * indirection tables. 12662eb4d010SOphir Munk */ 1267295968d1SFerruh Yigit if (config->ind_table_max_size > (unsigned int)RTE_ETH_RSS_RETA_SIZE_512) 1268295968d1SFerruh Yigit config->ind_table_max_size = RTE_ETH_RSS_RETA_SIZE_512; 12692eb4d010SOphir Munk DRV_LOG(DEBUG, "maximum Rx indirection table size is %u", 1270d462a83cSMichael Baum config->ind_table_max_size); 1271d462a83cSMichael Baum config->hw_vlan_strip = !!(sh->device_attr.raw_packet_caps & 12722eb4d010SOphir Munk IBV_RAW_PACKET_CAP_CVLAN_STRIPPING); 12732eb4d010SOphir Munk DRV_LOG(DEBUG, "VLAN stripping is %ssupported", 1274d462a83cSMichael Baum (config->hw_vlan_strip ? "" : "not ")); 1275d462a83cSMichael Baum config->hw_fcs_strip = !!(sh->device_attr.raw_packet_caps & 12762eb4d010SOphir Munk IBV_RAW_PACKET_CAP_SCATTER_FCS); 12772eb4d010SOphir Munk #if defined(HAVE_IBV_WQ_FLAG_RX_END_PADDING) 12782eb4d010SOphir Munk hw_padding = !!sh->device_attr.rx_pad_end_addr_align; 12792eb4d010SOphir Munk #elif defined(HAVE_IBV_WQ_FLAGS_PCI_WRITE_END_PADDING) 12802eb4d010SOphir Munk hw_padding = !!(sh->device_attr.device_cap_flags_ex & 12812eb4d010SOphir Munk IBV_DEVICE_PCI_WRITE_END_PADDING); 12822eb4d010SOphir Munk #endif 1283d462a83cSMichael Baum if (config->hw_padding && !hw_padding) { 12842eb4d010SOphir Munk DRV_LOG(DEBUG, "Rx end alignment padding isn't supported"); 1285d462a83cSMichael Baum config->hw_padding = 0; 1286d462a83cSMichael Baum } else if (config->hw_padding) { 12872eb4d010SOphir Munk DRV_LOG(DEBUG, "Rx end alignment padding is enabled"); 12882eb4d010SOphir Munk } 1289d462a83cSMichael Baum config->tso = (sh->device_attr.max_tso > 0 && 12902eb4d010SOphir Munk (sh->device_attr.tso_supported_qpts & 12912eb4d010SOphir Munk (1 << IBV_QPT_RAW_PACKET))); 1292d462a83cSMichael Baum if (config->tso) 1293d462a83cSMichael Baum config->tso_max_payload_sz = sh->device_attr.max_tso; 12942eb4d010SOphir Munk /* 12952eb4d010SOphir Munk * MPW is disabled by default, while the Enhanced MPW is enabled 12962eb4d010SOphir Munk * by default. 12972eb4d010SOphir Munk */ 1298d462a83cSMichael Baum if (config->mps == MLX5_ARG_UNSET) 1299d462a83cSMichael Baum config->mps = (mps == MLX5_MPW_ENHANCED) ? MLX5_MPW_ENHANCED : 13002eb4d010SOphir Munk MLX5_MPW_DISABLED; 13012eb4d010SOphir Munk else 1302d462a83cSMichael Baum config->mps = config->mps ? mps : MLX5_MPW_DISABLED; 13032eb4d010SOphir Munk DRV_LOG(INFO, "%sMPS is %s", 1304d462a83cSMichael Baum config->mps == MLX5_MPW_ENHANCED ? "enhanced " : 1305d462a83cSMichael Baum config->mps == MLX5_MPW ? "legacy " : "", 1306d462a83cSMichael Baum config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled"); 13075bc38358SMichael Baum if (sh->devx) { 1308fe46b20cSMichael Baum config->hca_attr = sh->cdev->config.hca_attr; 130996f85ec4SDong Zhou sh->steering_format_version = 131096f85ec4SDong Zhou config->hca_attr.steering_format_version; 13112eb4d010SOphir Munk /* Check for LRO support. */ 1312d462a83cSMichael Baum if (config->dest_tir && config->hca_attr.lro_cap && 1313d462a83cSMichael Baum config->dv_flow_en) { 13142eb4d010SOphir Munk /* TBD check tunnel lro caps. */ 1315d462a83cSMichael Baum config->lro.supported = config->hca_attr.lro_cap; 13162eb4d010SOphir Munk DRV_LOG(DEBUG, "Device supports LRO"); 13172eb4d010SOphir Munk /* 13182eb4d010SOphir Munk * If LRO timeout is not configured by application, 13192eb4d010SOphir Munk * use the minimal supported value. 13202eb4d010SOphir Munk */ 1321d462a83cSMichael Baum if (!config->lro.timeout) 1322d462a83cSMichael Baum config->lro.timeout = 1323d462a83cSMichael Baum config->hca_attr.lro_timer_supported_periods[0]; 13242eb4d010SOphir Munk DRV_LOG(DEBUG, "LRO session timeout set to %d usec", 1325d462a83cSMichael Baum config->lro.timeout); 1326613d64e4SDekel Peled DRV_LOG(DEBUG, "LRO minimal size of TCP segment " 1327613d64e4SDekel Peled "required for coalescing is %d bytes", 1328613d64e4SDekel Peled config->hca_attr.lro_min_mss_size); 13292eb4d010SOphir Munk } 1330c99b4f8bSLi Zhang #if defined(HAVE_MLX5DV_DR) && \ 1331c99b4f8bSLi Zhang (defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER) || \ 1332c99b4f8bSLi Zhang defined(HAVE_MLX5_DR_CREATE_ACTION_ASO)) 1333d462a83cSMichael Baum if (config->hca_attr.qos.sup && 1334b6505738SDekel Peled config->hca_attr.qos.flow_meter_old && 1335d462a83cSMichael Baum config->dv_flow_en) { 13362eb4d010SOphir Munk uint8_t reg_c_mask = 1337d462a83cSMichael Baum config->hca_attr.qos.flow_meter_reg_c_ids; 13382eb4d010SOphir Munk /* 13392eb4d010SOphir Munk * Meter needs two REG_C's for color match and pre-sfx 13402eb4d010SOphir Munk * flow match. Here get the REG_C for color match. 13412eb4d010SOphir Munk * REG_C_0 and REG_C_1 is reserved for metadata feature. 13422eb4d010SOphir Munk */ 13432eb4d010SOphir Munk reg_c_mask &= 0xfc; 13442eb4d010SOphir Munk if (__builtin_popcount(reg_c_mask) < 1) { 13452eb4d010SOphir Munk priv->mtr_en = 0; 13462eb4d010SOphir Munk DRV_LOG(WARNING, "No available register for" 13472eb4d010SOphir Munk " meter."); 13482eb4d010SOphir Munk } else { 134931ef2982SDekel Peled /* 135031ef2982SDekel Peled * The meter color register is used by the 135131ef2982SDekel Peled * flow-hit feature as well. 135231ef2982SDekel Peled * The flow-hit feature must use REG_C_3 135331ef2982SDekel Peled * Prefer REG_C_3 if it is available. 135431ef2982SDekel Peled */ 135531ef2982SDekel Peled if (reg_c_mask & (1 << (REG_C_3 - REG_C_0))) 135631ef2982SDekel Peled priv->mtr_color_reg = REG_C_3; 135731ef2982SDekel Peled else 135831ef2982SDekel Peled priv->mtr_color_reg = ffs(reg_c_mask) 135931ef2982SDekel Peled - 1 + REG_C_0; 13602eb4d010SOphir Munk priv->mtr_en = 1; 13612eb4d010SOphir Munk priv->mtr_reg_share = 1362b6505738SDekel Peled config->hca_attr.qos.flow_meter; 13632eb4d010SOphir Munk DRV_LOG(DEBUG, "The REG_C meter uses is %d", 13642eb4d010SOphir Munk priv->mtr_color_reg); 13652eb4d010SOphir Munk } 13662eb4d010SOphir Munk } 136729efa63aSLi Zhang if (config->hca_attr.qos.sup && 136829efa63aSLi Zhang config->hca_attr.qos.flow_meter_aso_sup) { 136929efa63aSLi Zhang uint32_t log_obj_size = 137029efa63aSLi Zhang rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1); 137129efa63aSLi Zhang if (log_obj_size >= 137229efa63aSLi Zhang config->hca_attr.qos.log_meter_aso_granularity && 137329efa63aSLi Zhang log_obj_size <= 137444432018SLi Zhang config->hca_attr.qos.log_meter_aso_max_alloc) 137529efa63aSLi Zhang sh->meter_aso_en = 1; 137644432018SLi Zhang } 137744432018SLi Zhang if (priv->mtr_en) { 1378afb4aa4fSLi Zhang err = mlx5_aso_flow_mtrs_mng_init(priv->sh); 137929efa63aSLi Zhang if (err) { 138029efa63aSLi Zhang err = -err; 138129efa63aSLi Zhang goto error; 138229efa63aSLi Zhang } 138329efa63aSLi Zhang } 1384630a587bSRongwei Liu if (config->hca_attr.flow.tunnel_header_0_1) 1385630a587bSRongwei Liu sh->tunnel_header_0_1 = 1; 13862eb4d010SOphir Munk #endif 1387a2999c7bSDekel Peled #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO 138831ef2982SDekel Peled if (config->hca_attr.flow_hit_aso && 138931ef2982SDekel Peled priv->mtr_color_reg == REG_C_3) { 139031ef2982SDekel Peled sh->flow_hit_aso_en = 1; 139131ef2982SDekel Peled err = mlx5_flow_aso_age_mng_init(sh); 139231ef2982SDekel Peled if (err) { 139331ef2982SDekel Peled err = -err; 139431ef2982SDekel Peled goto error; 139531ef2982SDekel Peled } 139631ef2982SDekel Peled DRV_LOG(DEBUG, "Flow Hit ASO is supported."); 139731ef2982SDekel Peled } 1398a2999c7bSDekel Peled #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ 1399ee9e5fadSBing Zhao #if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO) && \ 1400ee9e5fadSBing Zhao defined(HAVE_MLX5_DR_ACTION_ASO_CT) 1401ee9e5fadSBing Zhao if (config->hca_attr.ct_offload && 1402ee9e5fadSBing Zhao priv->mtr_color_reg == REG_C_3) { 1403ee9e5fadSBing Zhao err = mlx5_flow_aso_ct_mng_init(sh); 1404ee9e5fadSBing Zhao if (err) { 1405ee9e5fadSBing Zhao err = -err; 1406ee9e5fadSBing Zhao goto error; 1407ee9e5fadSBing Zhao } 1408ee9e5fadSBing Zhao DRV_LOG(DEBUG, "CT ASO is supported."); 1409ee9e5fadSBing Zhao sh->ct_aso_en = 1; 1410ee9e5fadSBing Zhao } 1411ee9e5fadSBing Zhao #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ 141296b1f027SJiawei Wang #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE) 141396b1f027SJiawei Wang if (config->hca_attr.log_max_ft_sampler_num > 0 && 141496b1f027SJiawei Wang config->dv_flow_en) { 141596b1f027SJiawei Wang priv->sampler_en = 1; 14161b9e9826SThomas Monjalon DRV_LOG(DEBUG, "Sampler enabled!"); 141796b1f027SJiawei Wang } else { 141896b1f027SJiawei Wang priv->sampler_en = 0; 141996b1f027SJiawei Wang if (!config->hca_attr.log_max_ft_sampler_num) 14201b9e9826SThomas Monjalon DRV_LOG(WARNING, 14211b9e9826SThomas Monjalon "No available register for sampler."); 142296b1f027SJiawei Wang else 14231b9e9826SThomas Monjalon DRV_LOG(DEBUG, "DV flow is not supported!"); 142496b1f027SJiawei Wang } 142596b1f027SJiawei Wang #endif 14262eb4d010SOphir Munk } 14273d3f4e6dSAlexander Kozyrev if (config->cqe_comp && RTE_CACHE_LINE_SIZE == 128 && 14283d3f4e6dSAlexander Kozyrev !(dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP)) { 14293d3f4e6dSAlexander Kozyrev DRV_LOG(WARNING, "Rx CQE 128B compression is not supported"); 14303d3f4e6dSAlexander Kozyrev config->cqe_comp = 0; 14313d3f4e6dSAlexander Kozyrev } 14323d3f4e6dSAlexander Kozyrev if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_FTAG_STRIDX && 14335bc38358SMichael Baum (!sh->devx || !config->hca_attr.mini_cqe_resp_flow_tag)) { 14343d3f4e6dSAlexander Kozyrev DRV_LOG(WARNING, "Flow Tag CQE compression" 14353d3f4e6dSAlexander Kozyrev " format isn't supported."); 14363d3f4e6dSAlexander Kozyrev config->cqe_comp = 0; 14373d3f4e6dSAlexander Kozyrev } 14383d3f4e6dSAlexander Kozyrev if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_L34H_STRIDX && 14395bc38358SMichael Baum (!sh->devx || !config->hca_attr.mini_cqe_resp_l3_l4_tag)) { 14403d3f4e6dSAlexander Kozyrev DRV_LOG(WARNING, "L3/L4 Header CQE compression" 14413d3f4e6dSAlexander Kozyrev " format isn't supported."); 14423d3f4e6dSAlexander Kozyrev config->cqe_comp = 0; 14433d3f4e6dSAlexander Kozyrev } 14443d3f4e6dSAlexander Kozyrev DRV_LOG(DEBUG, "Rx CQE compression is %ssupported", 14453d3f4e6dSAlexander Kozyrev config->cqe_comp ? "" : "not "); 1446d462a83cSMichael Baum if (config->tx_pp) { 14478f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz", 1448d462a83cSMichael Baum config->hca_attr.dev_freq_khz); 14498f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Packet pacing is %ssupported", 1450d462a83cSMichael Baum config->hca_attr.qos.packet_pacing ? "" : "not "); 14518f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Cross channel ops are %ssupported", 1452d462a83cSMichael Baum config->hca_attr.cross_channel ? "" : "not "); 14538f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "WQE index ignore is %ssupported", 1454d462a83cSMichael Baum config->hca_attr.wqe_index_ignore ? "" : "not "); 14558f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Non-wire SQ feature is %ssupported", 1456d462a83cSMichael Baum config->hca_attr.non_wire_sq ? "" : "not "); 14578f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "Static WQE SQ feature is %ssupported (%d)", 1458d462a83cSMichael Baum config->hca_attr.log_max_static_sq_wq ? "" : "not ", 1459d462a83cSMichael Baum config->hca_attr.log_max_static_sq_wq); 14608f848f32SViacheslav Ovsiienko DRV_LOG(DEBUG, "WQE rate PP mode is %ssupported", 1461d462a83cSMichael Baum config->hca_attr.qos.wqe_rate_pp ? "" : "not "); 14625bc38358SMichael Baum if (!sh->devx) { 14638f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "DevX is required for packet pacing"); 14648f848f32SViacheslav Ovsiienko err = ENODEV; 14658f848f32SViacheslav Ovsiienko goto error; 14668f848f32SViacheslav Ovsiienko } 1467d462a83cSMichael Baum if (!config->hca_attr.qos.packet_pacing) { 14688f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Packet pacing is not supported"); 14698f848f32SViacheslav Ovsiienko err = ENODEV; 14708f848f32SViacheslav Ovsiienko goto error; 14718f848f32SViacheslav Ovsiienko } 1472d462a83cSMichael Baum if (!config->hca_attr.cross_channel) { 14738f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Cross channel operations are" 14748f848f32SViacheslav Ovsiienko " required for packet pacing"); 14758f848f32SViacheslav Ovsiienko err = ENODEV; 14768f848f32SViacheslav Ovsiienko goto error; 14778f848f32SViacheslav Ovsiienko } 1478d462a83cSMichael Baum if (!config->hca_attr.wqe_index_ignore) { 14798f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "WQE index ignore feature is" 14808f848f32SViacheslav Ovsiienko " required for packet pacing"); 14818f848f32SViacheslav Ovsiienko err = ENODEV; 14828f848f32SViacheslav Ovsiienko goto error; 14838f848f32SViacheslav Ovsiienko } 1484d462a83cSMichael Baum if (!config->hca_attr.non_wire_sq) { 14858f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Non-wire SQ feature is" 14868f848f32SViacheslav Ovsiienko " required for packet pacing"); 14878f848f32SViacheslav Ovsiienko err = ENODEV; 14888f848f32SViacheslav Ovsiienko goto error; 14898f848f32SViacheslav Ovsiienko } 1490d462a83cSMichael Baum if (!config->hca_attr.log_max_static_sq_wq) { 14918f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "Static WQE SQ feature is" 14928f848f32SViacheslav Ovsiienko " required for packet pacing"); 14938f848f32SViacheslav Ovsiienko err = ENODEV; 14948f848f32SViacheslav Ovsiienko goto error; 14958f848f32SViacheslav Ovsiienko } 1496d462a83cSMichael Baum if (!config->hca_attr.qos.wqe_rate_pp) { 14978f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "WQE rate mode is required" 14988f848f32SViacheslav Ovsiienko " for packet pacing"); 14998f848f32SViacheslav Ovsiienko err = ENODEV; 15008f848f32SViacheslav Ovsiienko goto error; 15018f848f32SViacheslav Ovsiienko } 15028f848f32SViacheslav Ovsiienko #ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET 15038f848f32SViacheslav Ovsiienko DRV_LOG(ERR, "DevX does not provide UAR offset," 15048f848f32SViacheslav Ovsiienko " can't create queues for packet pacing"); 15058f848f32SViacheslav Ovsiienko err = ENODEV; 15068f848f32SViacheslav Ovsiienko goto error; 15078f848f32SViacheslav Ovsiienko #endif 15088f848f32SViacheslav Ovsiienko } 15095bc38358SMichael Baum if (sh->devx) { 1510a2854c4dSViacheslav Ovsiienko uint32_t reg[MLX5_ST_SZ_DW(register_mtutc)]; 1511a2854c4dSViacheslav Ovsiienko 1512972a1bf8SViacheslav Ovsiienko err = config->hca_attr.access_register_user ? 1513972a1bf8SViacheslav Ovsiienko mlx5_devx_cmd_register_read 1514ca1418ceSMichael Baum (sh->cdev->ctx, MLX5_REGISTER_ID_MTUTC, 0, 1515972a1bf8SViacheslav Ovsiienko reg, MLX5_ST_SZ_DW(register_mtutc)) : ENOTSUP; 1516a2854c4dSViacheslav Ovsiienko if (!err) { 1517a2854c4dSViacheslav Ovsiienko uint32_t ts_mode; 1518a2854c4dSViacheslav Ovsiienko 1519a2854c4dSViacheslav Ovsiienko /* MTUTC register is read successfully. */ 1520a2854c4dSViacheslav Ovsiienko ts_mode = MLX5_GET(register_mtutc, reg, 1521a2854c4dSViacheslav Ovsiienko time_stamp_mode); 1522a2854c4dSViacheslav Ovsiienko if (ts_mode == MLX5_MTUTC_TIMESTAMP_MODE_REAL_TIME) 1523d462a83cSMichael Baum config->rt_timestamp = 1; 1524a2854c4dSViacheslav Ovsiienko } else { 1525a2854c4dSViacheslav Ovsiienko /* Kernel does not support register reading. */ 1526d462a83cSMichael Baum if (config->hca_attr.dev_freq_khz == 1527a2854c4dSViacheslav Ovsiienko (NS_PER_S / MS_PER_S)) 1528d462a83cSMichael Baum config->rt_timestamp = 1; 1529a2854c4dSViacheslav Ovsiienko } 1530a2854c4dSViacheslav Ovsiienko } 153150f95b23SSuanming Mou /* 153250f95b23SSuanming Mou * If HW has bug working with tunnel packet decapsulation and 153350f95b23SSuanming Mou * scatter FCS, and decapsulation is needed, clear the hw_fcs_strip 1534295968d1SFerruh Yigit * bit. Then RTE_ETH_RX_OFFLOAD_KEEP_CRC bit will not be set anymore. 153550f95b23SSuanming Mou */ 1536d462a83cSMichael Baum if (config->hca_attr.scatter_fcs_w_decap_disable && config->decap_en) 1537d462a83cSMichael Baum config->hw_fcs_strip = 0; 153850f95b23SSuanming Mou DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported", 1539d462a83cSMichael Baum (config->hw_fcs_strip ? "" : "not ")); 1540d462a83cSMichael Baum if (config->mprq.enabled && mprq) { 1541d462a83cSMichael Baum if (config->mprq.stride_num_n && 1542d462a83cSMichael Baum (config->mprq.stride_num_n > mprq_max_stride_num_n || 1543d462a83cSMichael Baum config->mprq.stride_num_n < mprq_min_stride_num_n)) { 1544d462a83cSMichael Baum config->mprq.stride_num_n = 15452eb4d010SOphir Munk RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_NUM_N, 15462eb4d010SOphir Munk mprq_min_stride_num_n), 15472eb4d010SOphir Munk mprq_max_stride_num_n); 15482eb4d010SOphir Munk DRV_LOG(WARNING, 15492eb4d010SOphir Munk "the number of strides" 15502eb4d010SOphir Munk " for Multi-Packet RQ is out of range," 15512eb4d010SOphir Munk " setting default value (%u)", 1552d462a83cSMichael Baum 1 << config->mprq.stride_num_n); 15532eb4d010SOphir Munk } 1554d462a83cSMichael Baum if (config->mprq.stride_size_n && 1555d462a83cSMichael Baum (config->mprq.stride_size_n > mprq_max_stride_size_n || 1556d462a83cSMichael Baum config->mprq.stride_size_n < mprq_min_stride_size_n)) { 1557d462a83cSMichael Baum config->mprq.stride_size_n = 15582eb4d010SOphir Munk RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_SIZE_N, 15592eb4d010SOphir Munk mprq_min_stride_size_n), 15602eb4d010SOphir Munk mprq_max_stride_size_n); 15612eb4d010SOphir Munk DRV_LOG(WARNING, 15622eb4d010SOphir Munk "the size of a stride" 15632eb4d010SOphir Munk " for Multi-Packet RQ is out of range," 15642eb4d010SOphir Munk " setting default value (%u)", 1565d462a83cSMichael Baum 1 << config->mprq.stride_size_n); 15662eb4d010SOphir Munk } 1567d462a83cSMichael Baum config->mprq.min_stride_size_n = mprq_min_stride_size_n; 1568d462a83cSMichael Baum config->mprq.max_stride_size_n = mprq_max_stride_size_n; 1569d462a83cSMichael Baum } else if (config->mprq.enabled && !mprq) { 15702eb4d010SOphir Munk DRV_LOG(WARNING, "Multi-Packet RQ isn't supported"); 1571d462a83cSMichael Baum config->mprq.enabled = 0; 15722eb4d010SOphir Munk } 1573d462a83cSMichael Baum if (config->max_dump_files_num == 0) 1574d462a83cSMichael Baum config->max_dump_files_num = 128; 15752eb4d010SOphir Munk eth_dev = rte_eth_dev_allocate(name); 15762eb4d010SOphir Munk if (eth_dev == NULL) { 15772eb4d010SOphir Munk DRV_LOG(ERR, "can not allocate rte ethdev"); 15782eb4d010SOphir Munk err = ENOMEM; 15792eb4d010SOphir Munk goto error; 15802eb4d010SOphir Munk } 15812eb4d010SOphir Munk if (priv->representor) { 15822eb4d010SOphir Munk eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; 15832eb4d010SOphir Munk eth_dev->data->representor_id = priv->representor_id; 1584ff4e52efSViacheslav Galaktionov MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 1585ff4e52efSViacheslav Galaktionov struct mlx5_priv *opriv = 1586ff4e52efSViacheslav Galaktionov rte_eth_devices[port_id].data->dev_private; 1587ff4e52efSViacheslav Galaktionov if (opriv && 1588ff4e52efSViacheslav Galaktionov opriv->master && 1589ff4e52efSViacheslav Galaktionov opriv->domain_id == priv->domain_id && 1590ff4e52efSViacheslav Galaktionov opriv->sh == priv->sh) { 1591ff4e52efSViacheslav Galaktionov eth_dev->data->backer_port_id = port_id; 1592ff4e52efSViacheslav Galaktionov break; 1593ff4e52efSViacheslav Galaktionov } 1594ff4e52efSViacheslav Galaktionov } 1595ff4e52efSViacheslav Galaktionov if (port_id >= RTE_MAX_ETHPORTS) 1596ff4e52efSViacheslav Galaktionov eth_dev->data->backer_port_id = eth_dev->data->port_id; 15972eb4d010SOphir Munk } 159839ae7577SSuanming Mou priv->mp_id.port_id = eth_dev->data->port_id; 159939ae7577SSuanming Mou strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN); 16002eb4d010SOphir Munk /* 16012eb4d010SOphir Munk * Store associated network device interface index. This index 16022eb4d010SOphir Munk * is permanent throughout the lifetime of device. So, we may store 16032eb4d010SOphir Munk * the ifindex here and use the cached value further. 16042eb4d010SOphir Munk */ 16052eb4d010SOphir Munk MLX5_ASSERT(spawn->ifindex); 16062eb4d010SOphir Munk priv->if_index = spawn->ifindex; 1607a89f6433SRongwei Liu priv->lag_affinity_idx = sh->refcnt - 1; 16082eb4d010SOphir Munk eth_dev->data->dev_private = priv; 16092eb4d010SOphir Munk priv->dev_data = eth_dev->data; 16102eb4d010SOphir Munk eth_dev->data->mac_addrs = priv->mac; 16112eb4d010SOphir Munk eth_dev->device = dpdk_dev; 1612f30e69b4SFerruh Yigit eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 16132eb4d010SOphir Munk /* Configure the first MAC address by default. */ 16142eb4d010SOphir Munk if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) { 16152eb4d010SOphir Munk DRV_LOG(ERR, 16162eb4d010SOphir Munk "port %u cannot get MAC address, is mlx5_en" 16172eb4d010SOphir Munk " loaded? (errno: %s)", 16182eb4d010SOphir Munk eth_dev->data->port_id, strerror(rte_errno)); 16192eb4d010SOphir Munk err = ENODEV; 16202eb4d010SOphir Munk goto error; 16212eb4d010SOphir Munk } 16222eb4d010SOphir Munk DRV_LOG(INFO, 1623c2c4f87bSAman Deep Singh "port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT, 1624a7db3afcSAman Deep Singh eth_dev->data->port_id, RTE_ETHER_ADDR_BYTES(&mac)); 16252eb4d010SOphir Munk #ifdef RTE_LIBRTE_MLX5_DEBUG 16262eb4d010SOphir Munk { 162728743807STal Shnaiderman char ifname[MLX5_NAMESIZE]; 16282eb4d010SOphir Munk 16292eb4d010SOphir Munk if (mlx5_get_ifname(eth_dev, &ifname) == 0) 16302eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u ifname is \"%s\"", 16312eb4d010SOphir Munk eth_dev->data->port_id, ifname); 16322eb4d010SOphir Munk else 16332eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u ifname is unknown", 16342eb4d010SOphir Munk eth_dev->data->port_id); 16352eb4d010SOphir Munk } 16362eb4d010SOphir Munk #endif 16372eb4d010SOphir Munk /* Get actual MTU if possible. */ 16382eb4d010SOphir Munk err = mlx5_get_mtu(eth_dev, &priv->mtu); 16392eb4d010SOphir Munk if (err) { 16402eb4d010SOphir Munk err = rte_errno; 16412eb4d010SOphir Munk goto error; 16422eb4d010SOphir Munk } 16432eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u MTU is %u", eth_dev->data->port_id, 16442eb4d010SOphir Munk priv->mtu); 16452eb4d010SOphir Munk /* Initialize burst functions to prevent crashes before link-up. */ 16462eb4d010SOphir Munk eth_dev->rx_pkt_burst = removed_rx_burst; 16472eb4d010SOphir Munk eth_dev->tx_pkt_burst = removed_tx_burst; 1648b012b4ceSOphir Munk eth_dev->dev_ops = &mlx5_dev_ops; 1649cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 1650cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 1651cbfc6111SFerruh Yigit eth_dev->rx_queue_count = mlx5_rx_queue_count; 16522eb4d010SOphir Munk /* Register MAC address. */ 16532eb4d010SOphir Munk claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); 1654d462a83cSMichael Baum if (config->vf && config->vf_nl_en) 16552eb4d010SOphir Munk mlx5_nl_mac_addr_sync(priv->nl_socket_route, 16562eb4d010SOphir Munk mlx5_ifindex(eth_dev), 16572eb4d010SOphir Munk eth_dev->data->mac_addrs, 16582eb4d010SOphir Munk MLX5_MAX_MAC_ADDRESSES); 16592eb4d010SOphir Munk priv->ctrl_flows = 0; 1660d163fc2dSXueming Li rte_spinlock_init(&priv->flow_list_lock); 16612eb4d010SOphir Munk TAILQ_INIT(&priv->flow_meters); 1662a295c69aSShun Hao priv->mtr_profile_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_PTR); 1663a295c69aSShun Hao if (!priv->mtr_profile_tbl) 1664a295c69aSShun Hao goto error; 16652eb4d010SOphir Munk /* Bring Ethernet device up. */ 16662eb4d010SOphir Munk DRV_LOG(DEBUG, "port %u forcing Ethernet interface up", 16672eb4d010SOphir Munk eth_dev->data->port_id); 16682eb4d010SOphir Munk mlx5_set_link_up(eth_dev); 16692eb4d010SOphir Munk /* 16702eb4d010SOphir Munk * Even though the interrupt handler is not installed yet, 16712eb4d010SOphir Munk * interrupts will still trigger on the async_fd from 16722eb4d010SOphir Munk * Verbs context returned by ibv_open_device(). 16732eb4d010SOphir Munk */ 16742eb4d010SOphir Munk mlx5_link_update(eth_dev, 0); 16752eb4d010SOphir Munk #ifdef HAVE_MLX5DV_DR_ESWITCH 1676d462a83cSMichael Baum if (!(config->hca_attr.eswitch_manager && config->dv_flow_en && 16772eb4d010SOphir Munk (switch_info->representor || switch_info->master))) 1678d462a83cSMichael Baum config->dv_esw_en = 0; 16792eb4d010SOphir Munk #else 1680d462a83cSMichael Baum config->dv_esw_en = 0; 16812eb4d010SOphir Munk #endif 16822eb4d010SOphir Munk /* Detect minimal data bytes to inline. */ 1683d462a83cSMichael Baum mlx5_set_min_inline(spawn, config); 16842eb4d010SOphir Munk /* Store device configuration on private structure. */ 1685d462a83cSMichael Baum priv->config = *config; 1686b4edeaf3SSuanming Mou for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) { 1687b4edeaf3SSuanming Mou icfg[i].release_mem_en = !!config->reclaim_mode; 1688b4edeaf3SSuanming Mou if (config->reclaim_mode) 1689b4edeaf3SSuanming Mou icfg[i].per_core_cache = 0; 1690b4edeaf3SSuanming Mou priv->flows[i] = mlx5_ipool_create(&icfg[i]); 1691b4edeaf3SSuanming Mou if (!priv->flows[i]) 1692b4edeaf3SSuanming Mou goto error; 1693b4edeaf3SSuanming Mou } 16942eb4d010SOphir Munk /* Create context for virtual machine VLAN workaround. */ 16952eb4d010SOphir Munk priv->vmwa_context = mlx5_vlan_vmwa_init(eth_dev, spawn->ifindex); 1696d462a83cSMichael Baum if (config->dv_flow_en) { 16972eb4d010SOphir Munk err = mlx5_alloc_shared_dr(priv); 16982eb4d010SOphir Munk if (err) 16992eb4d010SOphir Munk goto error; 1700db25cadcSViacheslav Ovsiienko if (mlx5_flex_item_port_init(eth_dev) < 0) 1701db25cadcSViacheslav Ovsiienko goto error; 17022eb4d010SOphir Munk } 17035bc38358SMichael Baum if (sh->devx && config->dv_flow_en && config->dest_tir) { 17045eaf882eSMichael Baum priv->obj_ops = devx_obj_ops; 1705e6988afdSMatan Azrad mlx5_queue_counter_id_prepare(eth_dev); 170623233fd6SBing Zhao priv->obj_ops.lb_dummy_queue_create = 170723233fd6SBing Zhao mlx5_rxq_ibv_obj_dummy_lb_create; 170823233fd6SBing Zhao priv->obj_ops.lb_dummy_queue_release = 170923233fd6SBing Zhao mlx5_rxq_ibv_obj_dummy_lb_release; 1710614966c2SXueming Li } else if (spawn->max_port > UINT8_MAX) { 1711614966c2SXueming Li /* Verbs can't support ports larger than 255 by design. */ 1712614966c2SXueming Li DRV_LOG(ERR, "must enable DV and ESW when RDMA link ports > 255"); 1713614966c2SXueming Li err = ENOTSUP; 1714614966c2SXueming Li goto error; 17155eaf882eSMichael Baum } else { 17165eaf882eSMichael Baum priv->obj_ops = ibv_obj_ops; 17175eaf882eSMichael Baum } 1718f17e4b4fSViacheslav Ovsiienko if (config->tx_pp && 1719f17e4b4fSViacheslav Ovsiienko (priv->config.dv_esw_en || 1720686d05b6SXueming Li priv->obj_ops.txq_obj_new != mlx5_txq_devx_obj_new)) { 1721f17e4b4fSViacheslav Ovsiienko /* 1722f17e4b4fSViacheslav Ovsiienko * HAVE_MLX5DV_DEVX_UAR_OFFSET is required to support 1723f17e4b4fSViacheslav Ovsiienko * packet pacing and already checked above. 1724f17e4b4fSViacheslav Ovsiienko * Hence, we should only make sure the SQs will be created 1725f17e4b4fSViacheslav Ovsiienko * with DevX, not with Verbs. 1726f17e4b4fSViacheslav Ovsiienko * Verbs allocates the SQ UAR on its own and it can't be shared 1727f17e4b4fSViacheslav Ovsiienko * with Clock Queue UAR as required for Tx scheduling. 1728f17e4b4fSViacheslav Ovsiienko */ 1729f17e4b4fSViacheslav Ovsiienko DRV_LOG(ERR, "Verbs SQs, UAR can't be shared as required for packet pacing"); 1730f17e4b4fSViacheslav Ovsiienko err = ENODEV; 1731f17e4b4fSViacheslav Ovsiienko goto error; 1732f17e4b4fSViacheslav Ovsiienko } 173365b3cd0dSSuanming Mou priv->drop_queue.hrxq = mlx5_drop_action_create(eth_dev); 173465b3cd0dSSuanming Mou if (!priv->drop_queue.hrxq) 173565b3cd0dSSuanming Mou goto error; 17363c4338a4SJiawei Wang /* Port representor shares the same max prioirity with pf port. */ 17373c4338a4SJiawei Wang if (!priv->sh->flow_priority_check_flag) { 17382eb4d010SOphir Munk /* Supported Verbs flow priority number detection. */ 17392eb4d010SOphir Munk err = mlx5_flow_discover_priorities(eth_dev); 17403c4338a4SJiawei Wang priv->sh->flow_max_priority = err; 17413c4338a4SJiawei Wang priv->sh->flow_priority_check_flag = 1; 17423c4338a4SJiawei Wang } else { 17433c4338a4SJiawei Wang err = priv->sh->flow_max_priority; 17443c4338a4SJiawei Wang } 17452eb4d010SOphir Munk if (err < 0) { 17462eb4d010SOphir Munk err = -err; 17472eb4d010SOphir Munk goto error; 17482eb4d010SOphir Munk } 17492eb4d010SOphir Munk if (!priv->config.dv_esw_en && 17502eb4d010SOphir Munk priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 17512eb4d010SOphir Munk DRV_LOG(WARNING, "metadata mode %u is not supported " 17522eb4d010SOphir Munk "(no E-Switch)", priv->config.dv_xmeta_en); 17532eb4d010SOphir Munk priv->config.dv_xmeta_en = MLX5_XMETA_MODE_LEGACY; 17542eb4d010SOphir Munk } 17552eb4d010SOphir Munk mlx5_set_metadata_mask(eth_dev); 17562eb4d010SOphir Munk if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 17572eb4d010SOphir Munk !priv->sh->dv_regc0_mask) { 17582eb4d010SOphir Munk DRV_LOG(ERR, "metadata mode %u is not supported " 17592eb4d010SOphir Munk "(no metadata reg_c[0] is available)", 17602eb4d010SOphir Munk priv->config.dv_xmeta_en); 17612eb4d010SOphir Munk err = ENOTSUP; 17622eb4d010SOphir Munk goto error; 17632eb4d010SOphir Munk } 1764d03b7860SSuanming Mou priv->hrxqs = mlx5_list_create("hrxq", eth_dev, true, 1765d03b7860SSuanming Mou mlx5_hrxq_create_cb, 1766e1592b6cSSuanming Mou mlx5_hrxq_match_cb, 1767491b7137SMatan Azrad mlx5_hrxq_remove_cb, 1768491b7137SMatan Azrad mlx5_hrxq_clone_cb, 1769491b7137SMatan Azrad mlx5_hrxq_clone_free_cb); 1770679f46c7SMatan Azrad if (!priv->hrxqs) 1771679f46c7SMatan Azrad goto error; 1772491b7137SMatan Azrad rte_rwlock_init(&priv->ind_tbls_lock); 17732eb4d010SOphir Munk /* Query availability of metadata reg_c's. */ 17743c4338a4SJiawei Wang if (!priv->sh->metadata_regc_check_flag) { 17752eb4d010SOphir Munk err = mlx5_flow_discover_mreg_c(eth_dev); 17762eb4d010SOphir Munk if (err < 0) { 17772eb4d010SOphir Munk err = -err; 17782eb4d010SOphir Munk goto error; 17792eb4d010SOphir Munk } 17803c4338a4SJiawei Wang } 17812eb4d010SOphir Munk if (!mlx5_flow_ext_mreg_supported(eth_dev)) { 17822eb4d010SOphir Munk DRV_LOG(DEBUG, 17832eb4d010SOphir Munk "port %u extensive metadata register is not supported", 17842eb4d010SOphir Munk eth_dev->data->port_id); 17852eb4d010SOphir Munk if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 17862eb4d010SOphir Munk DRV_LOG(ERR, "metadata mode %u is not supported " 17872eb4d010SOphir Munk "(no metadata registers available)", 17882eb4d010SOphir Munk priv->config.dv_xmeta_en); 17892eb4d010SOphir Munk err = ENOTSUP; 17902eb4d010SOphir Munk goto error; 17912eb4d010SOphir Munk } 17922eb4d010SOphir Munk } 17932eb4d010SOphir Munk if (priv->config.dv_flow_en && 17942eb4d010SOphir Munk priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 17952eb4d010SOphir Munk mlx5_flow_ext_mreg_supported(eth_dev) && 17962eb4d010SOphir Munk priv->sh->dv_regc0_mask) { 17972eb4d010SOphir Munk priv->mreg_cp_tbl = mlx5_hlist_create(MLX5_FLOW_MREG_HNAME, 1798e69a5922SXueming Li MLX5_FLOW_MREG_HTABLE_SZ, 1799961b6774SMatan Azrad false, true, eth_dev, 1800f7f73ac1SXueming Li flow_dv_mreg_create_cb, 1801f5b0aed2SSuanming Mou flow_dv_mreg_match_cb, 1802961b6774SMatan Azrad flow_dv_mreg_remove_cb, 1803961b6774SMatan Azrad flow_dv_mreg_clone_cb, 1804961b6774SMatan Azrad flow_dv_mreg_clone_free_cb); 18052eb4d010SOphir Munk if (!priv->mreg_cp_tbl) { 18062eb4d010SOphir Munk err = ENOMEM; 18072eb4d010SOphir Munk goto error; 18082eb4d010SOphir Munk } 18092eb4d010SOphir Munk } 1810cc608e4dSSuanming Mou rte_spinlock_init(&priv->shared_act_sl); 1811994829e6SSuanming Mou mlx5_flow_counter_mode_config(eth_dev); 181245633c46SSuanming Mou mlx5_flow_drop_action_config(eth_dev); 18139fbe97f0SXueming Li if (priv->config.dv_flow_en) 18149fbe97f0SXueming Li eth_dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE; 18152eb4d010SOphir Munk return eth_dev; 18162eb4d010SOphir Munk error: 18172eb4d010SOphir Munk if (priv) { 18182eb4d010SOphir Munk if (priv->mreg_cp_tbl) 1819e69a5922SXueming Li mlx5_hlist_destroy(priv->mreg_cp_tbl); 18202eb4d010SOphir Munk if (priv->sh) 18212eb4d010SOphir Munk mlx5_os_free_shared_dr(priv); 18222eb4d010SOphir Munk if (priv->nl_socket_route >= 0) 18232eb4d010SOphir Munk close(priv->nl_socket_route); 18242eb4d010SOphir Munk if (priv->vmwa_context) 18252eb4d010SOphir Munk mlx5_vlan_vmwa_exit(priv->vmwa_context); 182665b3cd0dSSuanming Mou if (eth_dev && priv->drop_queue.hrxq) 182765b3cd0dSSuanming Mou mlx5_drop_action_destroy(eth_dev); 1828a295c69aSShun Hao if (priv->mtr_profile_tbl) 1829a295c69aSShun Hao mlx5_l3t_destroy(priv->mtr_profile_tbl); 18302eb4d010SOphir Munk if (own_domain_id) 18312eb4d010SOphir Munk claim_zero(rte_eth_switch_domain_free(priv->domain_id)); 1832679f46c7SMatan Azrad if (priv->hrxqs) 1833679f46c7SMatan Azrad mlx5_list_destroy(priv->hrxqs); 1834db25cadcSViacheslav Ovsiienko if (eth_dev && priv->flex_item_map) 1835db25cadcSViacheslav Ovsiienko mlx5_flex_item_port_cleanup(eth_dev); 18362175c4dcSSuanming Mou mlx5_free(priv); 18372eb4d010SOphir Munk if (eth_dev != NULL) 18382eb4d010SOphir Munk eth_dev->data->dev_private = NULL; 18392eb4d010SOphir Munk } 18402eb4d010SOphir Munk if (eth_dev != NULL) { 18412eb4d010SOphir Munk /* mac_addrs must not be freed alone because part of 18422eb4d010SOphir Munk * dev_private 18432eb4d010SOphir Munk **/ 18442eb4d010SOphir Munk eth_dev->data->mac_addrs = NULL; 18452eb4d010SOphir Munk rte_eth_dev_release_port(eth_dev); 18462eb4d010SOphir Munk } 18472eb4d010SOphir Munk if (sh) 184891389890SOphir Munk mlx5_free_shared_dev_ctx(sh); 18493fd2961eSXueming Li if (nl_rdma >= 0) 18503fd2961eSXueming Li close(nl_rdma); 18512eb4d010SOphir Munk MLX5_ASSERT(err > 0); 18522eb4d010SOphir Munk rte_errno = err; 18532eb4d010SOphir Munk return NULL; 18542eb4d010SOphir Munk } 18552eb4d010SOphir Munk 18562eb4d010SOphir Munk /** 18572eb4d010SOphir Munk * Comparison callback to sort device data. 18582eb4d010SOphir Munk * 18592eb4d010SOphir Munk * This is meant to be used with qsort(). 18602eb4d010SOphir Munk * 18612eb4d010SOphir Munk * @param a[in] 18622eb4d010SOphir Munk * Pointer to pointer to first data object. 18632eb4d010SOphir Munk * @param b[in] 18642eb4d010SOphir Munk * Pointer to pointer to second data object. 18652eb4d010SOphir Munk * 18662eb4d010SOphir Munk * @return 18672eb4d010SOphir Munk * 0 if both objects are equal, less than 0 if the first argument is less 18682eb4d010SOphir Munk * than the second, greater than 0 otherwise. 18692eb4d010SOphir Munk */ 18702eb4d010SOphir Munk static int 18712eb4d010SOphir Munk mlx5_dev_spawn_data_cmp(const void *a, const void *b) 18722eb4d010SOphir Munk { 18732eb4d010SOphir Munk const struct mlx5_switch_info *si_a = 18742eb4d010SOphir Munk &((const struct mlx5_dev_spawn_data *)a)->info; 18752eb4d010SOphir Munk const struct mlx5_switch_info *si_b = 18762eb4d010SOphir Munk &((const struct mlx5_dev_spawn_data *)b)->info; 18772eb4d010SOphir Munk int ret; 18782eb4d010SOphir Munk 18792eb4d010SOphir Munk /* Master device first. */ 18802eb4d010SOphir Munk ret = si_b->master - si_a->master; 18812eb4d010SOphir Munk if (ret) 18822eb4d010SOphir Munk return ret; 18832eb4d010SOphir Munk /* Then representor devices. */ 18842eb4d010SOphir Munk ret = si_b->representor - si_a->representor; 18852eb4d010SOphir Munk if (ret) 18862eb4d010SOphir Munk return ret; 18872eb4d010SOphir Munk /* Unidentified devices come last in no specific order. */ 18882eb4d010SOphir Munk if (!si_a->representor) 18892eb4d010SOphir Munk return 0; 18902eb4d010SOphir Munk /* Order representors by name. */ 18912eb4d010SOphir Munk return si_a->port_name - si_b->port_name; 18922eb4d010SOphir Munk } 18932eb4d010SOphir Munk 18942eb4d010SOphir Munk /** 18952eb4d010SOphir Munk * Match PCI information for possible slaves of bonding device. 18962eb4d010SOphir Munk * 1897ca1418ceSMichael Baum * @param[in] ibdev_name 1898ca1418ceSMichael Baum * Name of Infiniband device. 18992eb4d010SOphir Munk * @param[in] pci_dev 1900f926cce3SXueming Li * Pointer to primary PCI address structure to match. 19012eb4d010SOphir Munk * @param[in] nl_rdma 19022eb4d010SOphir Munk * Netlink RDMA group socket handle. 1903f926cce3SXueming Li * @param[in] owner 1904ca1418ceSMichael Baum * Representor owner PF index. 1905f5f4c482SXueming Li * @param[out] bond_info 1906f5f4c482SXueming Li * Pointer to bonding information. 19072eb4d010SOphir Munk * 19082eb4d010SOphir Munk * @return 19092eb4d010SOphir Munk * negative value if no bonding device found, otherwise 19102eb4d010SOphir Munk * positive index of slave PF in bonding. 19112eb4d010SOphir Munk */ 19122eb4d010SOphir Munk static int 1913ca1418ceSMichael Baum mlx5_device_bond_pci_match(const char *ibdev_name, 1914f926cce3SXueming Li const struct rte_pci_addr *pci_dev, 1915f5f4c482SXueming Li int nl_rdma, uint16_t owner, 1916f5f4c482SXueming Li struct mlx5_bond_info *bond_info) 19172eb4d010SOphir Munk { 19182eb4d010SOphir Munk char ifname[IF_NAMESIZE + 1]; 19192eb4d010SOphir Munk unsigned int ifindex; 19202eb4d010SOphir Munk unsigned int np, i; 1921f5f4c482SXueming Li FILE *bond_file = NULL, *file; 19222eb4d010SOphir Munk int pf = -1; 1923f5f4c482SXueming Li int ret; 19247299ab68SRongwei Liu uint8_t cur_guid[32] = {0}; 19257299ab68SRongwei Liu uint8_t guid[32] = {0}; 19262eb4d010SOphir Munk 19272eb4d010SOphir Munk /* 1928ca1418ceSMichael Baum * Try to get master device name. If something goes wrong suppose 1929ca1418ceSMichael Baum * the lack of kernel support and no bonding devices. 19302eb4d010SOphir Munk */ 1931f5f4c482SXueming Li memset(bond_info, 0, sizeof(*bond_info)); 19322eb4d010SOphir Munk if (nl_rdma < 0) 19332eb4d010SOphir Munk return -1; 1934ca1418ceSMichael Baum if (!strstr(ibdev_name, "bond")) 19352eb4d010SOphir Munk return -1; 1936ca1418ceSMichael Baum np = mlx5_nl_portnum(nl_rdma, ibdev_name); 19372eb4d010SOphir Munk if (!np) 19382eb4d010SOphir Munk return -1; 19397299ab68SRongwei Liu if (mlx5_get_device_guid(pci_dev, cur_guid, sizeof(cur_guid)) < 0) 19407299ab68SRongwei Liu return -1; 19412eb4d010SOphir Munk /* 1942ca1418ceSMichael Baum * The master device might not be on the predefined port(not on port 1943ca1418ceSMichael Baum * index 1, it is not guaranteed), we have to scan all Infiniband 1944ca1418ceSMichael Baum * device ports and find master. 19452eb4d010SOphir Munk */ 19462eb4d010SOphir Munk for (i = 1; i <= np; ++i) { 19472eb4d010SOphir Munk /* Check whether Infiniband port is populated. */ 1948ca1418ceSMichael Baum ifindex = mlx5_nl_ifindex(nl_rdma, ibdev_name, i); 19492eb4d010SOphir Munk if (!ifindex) 19502eb4d010SOphir Munk continue; 19512eb4d010SOphir Munk if (!if_indextoname(ifindex, ifname)) 19522eb4d010SOphir Munk continue; 19532eb4d010SOphir Munk /* Try to read bonding slave names from sysfs. */ 19542eb4d010SOphir Munk MKSTR(slaves, 19552eb4d010SOphir Munk "/sys/class/net/%s/master/bonding/slaves", ifname); 1956f5f4c482SXueming Li bond_file = fopen(slaves, "r"); 1957f5f4c482SXueming Li if (bond_file) 19582eb4d010SOphir Munk break; 19592eb4d010SOphir Munk } 1960f5f4c482SXueming Li if (!bond_file) 19612eb4d010SOphir Munk return -1; 19622eb4d010SOphir Munk /* Use safe format to check maximal buffer length. */ 19632eb4d010SOphir Munk MLX5_ASSERT(atol(RTE_STR(IF_NAMESIZE)) == IF_NAMESIZE); 1964f5f4c482SXueming Li while (fscanf(bond_file, "%" RTE_STR(IF_NAMESIZE) "s", ifname) == 1) { 19652eb4d010SOphir Munk char tmp_str[IF_NAMESIZE + 32]; 19662eb4d010SOphir Munk struct rte_pci_addr pci_addr; 19672eb4d010SOphir Munk struct mlx5_switch_info info; 19687299ab68SRongwei Liu int ret; 19692eb4d010SOphir Munk 19702eb4d010SOphir Munk /* Process slave interface names in the loop. */ 19712eb4d010SOphir Munk snprintf(tmp_str, sizeof(tmp_str), 19722eb4d010SOphir Munk "/sys/class/net/%s", ifname); 19734d567938SThomas Monjalon if (mlx5_get_pci_addr(tmp_str, &pci_addr)) { 1974ca1418ceSMichael Baum DRV_LOG(WARNING, 1975ca1418ceSMichael Baum "Cannot get PCI address for netdev \"%s\".", 1976ca1418ceSMichael Baum ifname); 19772eb4d010SOphir Munk continue; 19782eb4d010SOphir Munk } 19792eb4d010SOphir Munk /* Slave interface PCI address match found. */ 19802eb4d010SOphir Munk snprintf(tmp_str, sizeof(tmp_str), 19812eb4d010SOphir Munk "/sys/class/net/%s/phys_port_name", ifname); 19822eb4d010SOphir Munk file = fopen(tmp_str, "rb"); 19832eb4d010SOphir Munk if (!file) 19842eb4d010SOphir Munk break; 19852eb4d010SOphir Munk info.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET; 19862eb4d010SOphir Munk if (fscanf(file, "%32s", tmp_str) == 1) 19872eb4d010SOphir Munk mlx5_translate_port_name(tmp_str, &info); 1988f5f4c482SXueming Li fclose(file); 1989f5f4c482SXueming Li /* Only process PF ports. */ 1990f5f4c482SXueming Li if (info.name_type != MLX5_PHYS_PORT_NAME_TYPE_LEGACY && 1991f5f4c482SXueming Li info.name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK) 1992f5f4c482SXueming Li continue; 1993f5f4c482SXueming Li /* Check max bonding member. */ 1994f5f4c482SXueming Li if (info.port_name >= MLX5_BOND_MAX_PORTS) { 1995f5f4c482SXueming Li DRV_LOG(WARNING, "bonding index out of range, " 1996f5f4c482SXueming Li "please increase MLX5_BOND_MAX_PORTS: %s", 1997f5f4c482SXueming Li tmp_str); 19982eb4d010SOphir Munk break; 19992eb4d010SOphir Munk } 2000f5f4c482SXueming Li /* Get ifindex. */ 2001f5f4c482SXueming Li snprintf(tmp_str, sizeof(tmp_str), 2002f5f4c482SXueming Li "/sys/class/net/%s/ifindex", ifname); 2003f5f4c482SXueming Li file = fopen(tmp_str, "rb"); 2004f5f4c482SXueming Li if (!file) 2005f5f4c482SXueming Li break; 2006f5f4c482SXueming Li ret = fscanf(file, "%u", &ifindex); 20072eb4d010SOphir Munk fclose(file); 2008f5f4c482SXueming Li if (ret != 1) 2009f5f4c482SXueming Li break; 2010f5f4c482SXueming Li /* Save bonding info. */ 2011f5f4c482SXueming Li strncpy(bond_info->ports[info.port_name].ifname, ifname, 2012f5f4c482SXueming Li sizeof(bond_info->ports[0].ifname)); 2013f5f4c482SXueming Li bond_info->ports[info.port_name].pci_addr = pci_addr; 2014f5f4c482SXueming Li bond_info->ports[info.port_name].ifindex = ifindex; 2015f5f4c482SXueming Li bond_info->n_port++; 20167299ab68SRongwei Liu /* 20177299ab68SRongwei Liu * Under socket direct mode, bonding will use 20187299ab68SRongwei Liu * system_image_guid as identification. 20197299ab68SRongwei Liu * After OFED 5.4, guid is readable (ret >= 0) under sysfs. 20207299ab68SRongwei Liu * All bonding members should have the same guid even if driver 20217299ab68SRongwei Liu * is using PCIe BDF. 20227299ab68SRongwei Liu */ 20237299ab68SRongwei Liu ret = mlx5_get_device_guid(&pci_addr, guid, sizeof(guid)); 20247299ab68SRongwei Liu if (ret < 0) 20257299ab68SRongwei Liu break; 20267299ab68SRongwei Liu else if (ret > 0) { 20277299ab68SRongwei Liu if (!memcmp(guid, cur_guid, sizeof(guid)) && 20287299ab68SRongwei Liu owner == info.port_name && 20297299ab68SRongwei Liu (owner != 0 || (owner == 0 && 20307299ab68SRongwei Liu !rte_pci_addr_cmp(pci_dev, &pci_addr)))) 20317299ab68SRongwei Liu pf = info.port_name; 20327299ab68SRongwei Liu } else if (pci_dev->domain == pci_addr.domain && 20337299ab68SRongwei Liu pci_dev->bus == pci_addr.bus && 20347299ab68SRongwei Liu pci_dev->devid == pci_addr.devid && 20357299ab68SRongwei Liu ((pci_dev->function == 0 && 20367299ab68SRongwei Liu pci_dev->function + owner == pci_addr.function) || 20377299ab68SRongwei Liu (pci_dev->function == owner && 20387299ab68SRongwei Liu pci_addr.function == owner))) 20397299ab68SRongwei Liu pf = info.port_name; 2040f5f4c482SXueming Li } 2041f5f4c482SXueming Li if (pf >= 0) { 2042f5f4c482SXueming Li /* Get bond interface info */ 2043f5f4c482SXueming Li ret = mlx5_sysfs_bond_info(ifindex, &bond_info->ifindex, 2044f5f4c482SXueming Li bond_info->ifname); 2045f5f4c482SXueming Li if (ret) 2046f5f4c482SXueming Li DRV_LOG(ERR, "unable to get bond info: %s", 2047f5f4c482SXueming Li strerror(rte_errno)); 2048f5f4c482SXueming Li else 2049f5f4c482SXueming Li DRV_LOG(INFO, "PF device %u, bond device %u(%s)", 2050f5f4c482SXueming Li ifindex, bond_info->ifindex, bond_info->ifname); 2051f5f4c482SXueming Li } 20527299ab68SRongwei Liu if (owner == 0 && pf != 0) { 20537299ab68SRongwei Liu DRV_LOG(INFO, "PCIe instance %04x:%02x:%02x.%x isn't bonding owner", 20547299ab68SRongwei Liu pci_dev->domain, pci_dev->bus, pci_dev->devid, 20557299ab68SRongwei Liu pci_dev->function); 20567299ab68SRongwei Liu } 20572eb4d010SOphir Munk return pf; 20582eb4d010SOphir Munk } 20592eb4d010SOphir Munk 2060919488fbSXueming Li static void 2061919488fbSXueming Li mlx5_os_config_default(struct mlx5_dev_config *config) 2062919488fbSXueming Li { 2063919488fbSXueming Li memset(config, 0, sizeof(*config)); 2064919488fbSXueming Li config->mps = MLX5_ARG_UNSET; 2065919488fbSXueming Li config->rx_vec_en = 1; 2066919488fbSXueming Li config->txq_inline_max = MLX5_ARG_UNSET; 2067919488fbSXueming Li config->txq_inline_min = MLX5_ARG_UNSET; 2068919488fbSXueming Li config->txq_inline_mpw = MLX5_ARG_UNSET; 2069919488fbSXueming Li config->txqs_inline = MLX5_ARG_UNSET; 2070919488fbSXueming Li config->vf_nl_en = 1; 2071919488fbSXueming Li config->mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN; 2072919488fbSXueming Li config->mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS; 2073919488fbSXueming Li config->dv_esw_en = 1; 2074919488fbSXueming Li config->dv_flow_en = 1; 2075919488fbSXueming Li config->decap_en = 1; 2076919488fbSXueming Li config->log_hp_size = MLX5_ARG_UNSET; 207797c9b0aaSMichael Baum config->allow_duplicate_pattern = 1; 2078919488fbSXueming Li } 2079919488fbSXueming Li 20802eb4d010SOphir Munk /** 208108c2772fSXueming Li * Register a PCI device within bonding. 20822eb4d010SOphir Munk * 208308c2772fSXueming Li * This function spawns Ethernet devices out of a given PCI device and 208408c2772fSXueming Li * bonding owner PF index. 20852eb4d010SOphir Munk * 20867af08c8fSMichael Baum * @param[in] cdev 20877af08c8fSMichael Baum * Pointer to common mlx5 device structure. 208808c2772fSXueming Li * @param[in] req_eth_da 208908c2772fSXueming Li * Requested ethdev device argument. 209008c2772fSXueming Li * @param[in] owner_id 209108c2772fSXueming Li * Requested owner PF port ID within bonding device, default to 0. 20922eb4d010SOphir Munk * 20932eb4d010SOphir Munk * @return 20942eb4d010SOphir Munk * 0 on success, a negative errno value otherwise and rte_errno is set. 20952eb4d010SOphir Munk */ 209608c2772fSXueming Li static int 2097ca1418ceSMichael Baum mlx5_os_pci_probe_pf(struct mlx5_common_device *cdev, 209808c2772fSXueming Li struct rte_eth_devargs *req_eth_da, 209908c2772fSXueming Li uint16_t owner_id) 21002eb4d010SOphir Munk { 21012eb4d010SOphir Munk struct ibv_device **ibv_list; 21022eb4d010SOphir Munk /* 21032eb4d010SOphir Munk * Number of found IB Devices matching with requested PCI BDF. 21042eb4d010SOphir Munk * nd != 1 means there are multiple IB devices over the same 21052eb4d010SOphir Munk * PCI device and we have representors and master. 21062eb4d010SOphir Munk */ 21072eb4d010SOphir Munk unsigned int nd = 0; 21082eb4d010SOphir Munk /* 21092eb4d010SOphir Munk * Number of found IB device Ports. nd = 1 and np = 1..n means 21102eb4d010SOphir Munk * we have the single multiport IB device, and there may be 21112eb4d010SOphir Munk * representors attached to some of found ports. 21122eb4d010SOphir Munk */ 21132eb4d010SOphir Munk unsigned int np = 0; 21142eb4d010SOphir Munk /* 21152eb4d010SOphir Munk * Number of DPDK ethernet devices to Spawn - either over 21162eb4d010SOphir Munk * multiple IB devices or multiple ports of single IB device. 21172eb4d010SOphir Munk * Actually this is the number of iterations to spawn. 21182eb4d010SOphir Munk */ 21192eb4d010SOphir Munk unsigned int ns = 0; 21202eb4d010SOphir Munk /* 21212eb4d010SOphir Munk * Bonding device 21222eb4d010SOphir Munk * < 0 - no bonding device (single one) 21232eb4d010SOphir Munk * >= 0 - bonding device (value is slave PF index) 21242eb4d010SOphir Munk */ 21252eb4d010SOphir Munk int bd = -1; 21267af08c8fSMichael Baum struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev); 21272eb4d010SOphir Munk struct mlx5_dev_spawn_data *list = NULL; 21282eb4d010SOphir Munk struct mlx5_dev_config dev_config; 2129d462a83cSMichael Baum unsigned int dev_config_vf; 213008c2772fSXueming Li struct rte_eth_devargs eth_da = *req_eth_da; 2131f926cce3SXueming Li struct rte_pci_addr owner_pci = pci_dev->addr; /* Owner PF. */ 2132f5f4c482SXueming Li struct mlx5_bond_info bond_info; 2133f926cce3SXueming Li int ret = -1; 21342eb4d010SOphir Munk 21352eb4d010SOphir Munk errno = 0; 21362eb4d010SOphir Munk ibv_list = mlx5_glue->get_device_list(&ret); 21372eb4d010SOphir Munk if (!ibv_list) { 21382eb4d010SOphir Munk rte_errno = errno ? errno : ENOSYS; 2139887183efSMichael Baum DRV_LOG(ERR, "Cannot list devices, is ib_uverbs loaded?"); 21402eb4d010SOphir Munk return -rte_errno; 21412eb4d010SOphir Munk } 21422eb4d010SOphir Munk /* 21432eb4d010SOphir Munk * First scan the list of all Infiniband devices to find 21442eb4d010SOphir Munk * matching ones, gathering into the list. 21452eb4d010SOphir Munk */ 21462eb4d010SOphir Munk struct ibv_device *ibv_match[ret + 1]; 21472eb4d010SOphir Munk int nl_route = mlx5_nl_init(NETLINK_ROUTE); 21482eb4d010SOphir Munk int nl_rdma = mlx5_nl_init(NETLINK_RDMA); 21492eb4d010SOphir Munk unsigned int i; 21502eb4d010SOphir Munk 21512eb4d010SOphir Munk while (ret-- > 0) { 21522eb4d010SOphir Munk struct rte_pci_addr pci_addr; 21532eb4d010SOphir Munk 2154887183efSMichael Baum DRV_LOG(DEBUG, "Checking device \"%s\"", ibv_list[ret]->name); 2155ca1418ceSMichael Baum bd = mlx5_device_bond_pci_match(ibv_list[ret]->name, &owner_pci, 2156ca1418ceSMichael Baum nl_rdma, owner_id, &bond_info); 21572eb4d010SOphir Munk if (bd >= 0) { 21582eb4d010SOphir Munk /* 21592eb4d010SOphir Munk * Bonding device detected. Only one match is allowed, 21602eb4d010SOphir Munk * the bonding is supported over multi-port IB device, 21612eb4d010SOphir Munk * there should be no matches on representor PCI 21622eb4d010SOphir Munk * functions or non VF LAG bonding devices with 21632eb4d010SOphir Munk * specified address. 21642eb4d010SOphir Munk */ 21652eb4d010SOphir Munk if (nd) { 21662eb4d010SOphir Munk DRV_LOG(ERR, 21672eb4d010SOphir Munk "multiple PCI match on bonding device" 21682eb4d010SOphir Munk "\"%s\" found", ibv_list[ret]->name); 21692eb4d010SOphir Munk rte_errno = ENOENT; 21702eb4d010SOphir Munk ret = -rte_errno; 21712eb4d010SOphir Munk goto exit; 21722eb4d010SOphir Munk } 2173f926cce3SXueming Li /* Amend owner pci address if owner PF ID specified. */ 2174f926cce3SXueming Li if (eth_da.nb_representor_ports) 217508c2772fSXueming Li owner_pci.function += owner_id; 2176ca1418ceSMichael Baum DRV_LOG(INFO, 2177ca1418ceSMichael Baum "PCI information matches for slave %d bonding device \"%s\"", 21782eb4d010SOphir Munk bd, ibv_list[ret]->name); 21792eb4d010SOphir Munk ibv_match[nd++] = ibv_list[ret]; 21802eb4d010SOphir Munk break; 2181f926cce3SXueming Li } else { 2182f926cce3SXueming Li /* Bonding device not found. */ 21834d567938SThomas Monjalon if (mlx5_get_pci_addr(ibv_list[ret]->ibdev_path, 21844d567938SThomas Monjalon &pci_addr)) 21852eb4d010SOphir Munk continue; 2186f926cce3SXueming Li if (owner_pci.domain != pci_addr.domain || 2187f926cce3SXueming Li owner_pci.bus != pci_addr.bus || 2188f926cce3SXueming Li owner_pci.devid != pci_addr.devid || 2189f926cce3SXueming Li owner_pci.function != pci_addr.function) 21902eb4d010SOphir Munk continue; 21912eb4d010SOphir Munk DRV_LOG(INFO, "PCI information matches for device \"%s\"", 21922eb4d010SOphir Munk ibv_list[ret]->name); 21932eb4d010SOphir Munk ibv_match[nd++] = ibv_list[ret]; 21942eb4d010SOphir Munk } 2195f926cce3SXueming Li } 21962eb4d010SOphir Munk ibv_match[nd] = NULL; 21972eb4d010SOphir Munk if (!nd) { 21982eb4d010SOphir Munk /* No device matches, just complain and bail out. */ 21992eb4d010SOphir Munk DRV_LOG(WARNING, 2200887183efSMichael Baum "No Verbs device matches PCI device " PCI_PRI_FMT "," 22012eb4d010SOphir Munk " are kernel drivers loaded?", 2202f926cce3SXueming Li owner_pci.domain, owner_pci.bus, 2203f926cce3SXueming Li owner_pci.devid, owner_pci.function); 22042eb4d010SOphir Munk rte_errno = ENOENT; 22052eb4d010SOphir Munk ret = -rte_errno; 22062eb4d010SOphir Munk goto exit; 22072eb4d010SOphir Munk } 22082eb4d010SOphir Munk if (nd == 1) { 22092eb4d010SOphir Munk /* 22102eb4d010SOphir Munk * Found single matching device may have multiple ports. 22112eb4d010SOphir Munk * Each port may be representor, we have to check the port 22122eb4d010SOphir Munk * number and check the representors existence. 22132eb4d010SOphir Munk */ 22142eb4d010SOphir Munk if (nl_rdma >= 0) 22152eb4d010SOphir Munk np = mlx5_nl_portnum(nl_rdma, ibv_match[0]->name); 22162eb4d010SOphir Munk if (!np) 2217887183efSMichael Baum DRV_LOG(WARNING, 2218887183efSMichael Baum "Cannot get IB device \"%s\" ports number.", 2219887183efSMichael Baum ibv_match[0]->name); 22202eb4d010SOphir Munk if (bd >= 0 && !np) { 2221887183efSMichael Baum DRV_LOG(ERR, "Cannot get ports for bonding device."); 22222eb4d010SOphir Munk rte_errno = ENOENT; 22232eb4d010SOphir Munk ret = -rte_errno; 22242eb4d010SOphir Munk goto exit; 22252eb4d010SOphir Munk } 22262eb4d010SOphir Munk } 2227887183efSMichael Baum /* Now we can determine the maximal amount of devices to be spawned. */ 22282175c4dcSSuanming Mou list = mlx5_malloc(MLX5_MEM_ZERO, 2229887183efSMichael Baum sizeof(struct mlx5_dev_spawn_data) * (np ? np : nd), 22302175c4dcSSuanming Mou RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 22312eb4d010SOphir Munk if (!list) { 2232887183efSMichael Baum DRV_LOG(ERR, "Spawn data array allocation failure."); 22332eb4d010SOphir Munk rte_errno = ENOMEM; 22342eb4d010SOphir Munk ret = -rte_errno; 22352eb4d010SOphir Munk goto exit; 22362eb4d010SOphir Munk } 22372eb4d010SOphir Munk if (bd >= 0 || np > 1) { 22382eb4d010SOphir Munk /* 22392eb4d010SOphir Munk * Single IB device with multiple ports found, 22402eb4d010SOphir Munk * it may be E-Switch master device and representors. 22412eb4d010SOphir Munk * We have to perform identification through the ports. 22422eb4d010SOphir Munk */ 22432eb4d010SOphir Munk MLX5_ASSERT(nl_rdma >= 0); 22442eb4d010SOphir Munk MLX5_ASSERT(ns == 0); 22452eb4d010SOphir Munk MLX5_ASSERT(nd == 1); 22462eb4d010SOphir Munk MLX5_ASSERT(np); 22472eb4d010SOphir Munk for (i = 1; i <= np; ++i) { 2248f5f4c482SXueming Li list[ns].bond_info = &bond_info; 22492eb4d010SOphir Munk list[ns].max_port = np; 2250834a9019SOphir Munk list[ns].phys_port = i; 2251887183efSMichael Baum list[ns].phys_dev_name = ibv_match[0]->name; 22522eb4d010SOphir Munk list[ns].eth_dev = NULL; 22532eb4d010SOphir Munk list[ns].pci_dev = pci_dev; 22547af08c8fSMichael Baum list[ns].cdev = cdev; 22552eb4d010SOphir Munk list[ns].pf_bond = bd; 2256887183efSMichael Baum list[ns].ifindex = mlx5_nl_ifindex(nl_rdma, 2257887183efSMichael Baum ibv_match[0]->name, 2258887183efSMichael Baum i); 22592eb4d010SOphir Munk if (!list[ns].ifindex) { 22602eb4d010SOphir Munk /* 22612eb4d010SOphir Munk * No network interface index found for the 22622eb4d010SOphir Munk * specified port, it means there is no 22632eb4d010SOphir Munk * representor on this port. It's OK, 22642eb4d010SOphir Munk * there can be disabled ports, for example 22652eb4d010SOphir Munk * if sriov_numvfs < sriov_totalvfs. 22662eb4d010SOphir Munk */ 22672eb4d010SOphir Munk continue; 22682eb4d010SOphir Munk } 22692eb4d010SOphir Munk ret = -1; 22702eb4d010SOphir Munk if (nl_route >= 0) 2271887183efSMichael Baum ret = mlx5_nl_switch_info(nl_route, 22722eb4d010SOphir Munk list[ns].ifindex, 22732eb4d010SOphir Munk &list[ns].info); 22742eb4d010SOphir Munk if (ret || (!list[ns].info.representor && 22752eb4d010SOphir Munk !list[ns].info.master)) { 22762eb4d010SOphir Munk /* 22772eb4d010SOphir Munk * We failed to recognize representors with 22782eb4d010SOphir Munk * Netlink, let's try to perform the task 22792eb4d010SOphir Munk * with sysfs. 22802eb4d010SOphir Munk */ 2281887183efSMichael Baum ret = mlx5_sysfs_switch_info(list[ns].ifindex, 22822eb4d010SOphir Munk &list[ns].info); 22832eb4d010SOphir Munk } 22842eb4d010SOphir Munk if (!ret && bd >= 0) { 22852eb4d010SOphir Munk switch (list[ns].info.name_type) { 22862eb4d010SOphir Munk case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: 22879f430dd7SViacheslav Ovsiienko if (np == 1) { 22889f430dd7SViacheslav Ovsiienko /* 22899f430dd7SViacheslav Ovsiienko * Force standalone bonding 22909f430dd7SViacheslav Ovsiienko * device for ROCE LAG 22919f430dd7SViacheslav Ovsiienko * confgiurations. 22929f430dd7SViacheslav Ovsiienko */ 22939f430dd7SViacheslav Ovsiienko list[ns].info.master = 0; 22949f430dd7SViacheslav Ovsiienko list[ns].info.representor = 0; 22959f430dd7SViacheslav Ovsiienko } 22962eb4d010SOphir Munk if (list[ns].info.port_name == bd) 22972eb4d010SOphir Munk ns++; 22982eb4d010SOphir Munk break; 2299420bbdaeSViacheslav Ovsiienko case MLX5_PHYS_PORT_NAME_TYPE_PFHPF: 2300420bbdaeSViacheslav Ovsiienko /* Fallthrough */ 23012eb4d010SOphir Munk case MLX5_PHYS_PORT_NAME_TYPE_PFVF: 2302cb95feefSXueming Li /* Fallthrough */ 2303cb95feefSXueming Li case MLX5_PHYS_PORT_NAME_TYPE_PFSF: 23042eb4d010SOphir Munk if (list[ns].info.pf_num == bd) 23052eb4d010SOphir Munk ns++; 23062eb4d010SOphir Munk break; 23072eb4d010SOphir Munk default: 23082eb4d010SOphir Munk break; 23092eb4d010SOphir Munk } 23102eb4d010SOphir Munk continue; 23112eb4d010SOphir Munk } 23122eb4d010SOphir Munk if (!ret && (list[ns].info.representor ^ 23132eb4d010SOphir Munk list[ns].info.master)) 23142eb4d010SOphir Munk ns++; 23152eb4d010SOphir Munk } 23162eb4d010SOphir Munk if (!ns) { 23172eb4d010SOphir Munk DRV_LOG(ERR, 2318887183efSMichael Baum "Unable to recognize master/representors on the IB device with multiple ports."); 23192eb4d010SOphir Munk rte_errno = ENOENT; 23202eb4d010SOphir Munk ret = -rte_errno; 23212eb4d010SOphir Munk goto exit; 23222eb4d010SOphir Munk } 23232eb4d010SOphir Munk } else { 23242eb4d010SOphir Munk /* 23252eb4d010SOphir Munk * The existence of several matching entries (nd > 1) means 23262eb4d010SOphir Munk * port representors have been instantiated. No existing Verbs 23272eb4d010SOphir Munk * call nor sysfs entries can tell them apart, this can only 23282eb4d010SOphir Munk * be done through Netlink calls assuming kernel drivers are 23292eb4d010SOphir Munk * recent enough to support them. 23302eb4d010SOphir Munk * 23312eb4d010SOphir Munk * In the event of identification failure through Netlink, 23322eb4d010SOphir Munk * try again through sysfs, then: 23332eb4d010SOphir Munk * 23342eb4d010SOphir Munk * 1. A single IB device matches (nd == 1) with single 23352eb4d010SOphir Munk * port (np=0/1) and is not a representor, assume 23362eb4d010SOphir Munk * no switch support. 23372eb4d010SOphir Munk * 23382eb4d010SOphir Munk * 2. Otherwise no safe assumptions can be made; 23392eb4d010SOphir Munk * complain louder and bail out. 23402eb4d010SOphir Munk */ 23412eb4d010SOphir Munk for (i = 0; i != nd; ++i) { 23422eb4d010SOphir Munk memset(&list[ns].info, 0, sizeof(list[ns].info)); 2343f5f4c482SXueming Li list[ns].bond_info = NULL; 23442eb4d010SOphir Munk list[ns].max_port = 1; 2345834a9019SOphir Munk list[ns].phys_port = 1; 2346887183efSMichael Baum list[ns].phys_dev_name = ibv_match[i]->name; 23472eb4d010SOphir Munk list[ns].eth_dev = NULL; 23482eb4d010SOphir Munk list[ns].pci_dev = pci_dev; 23497af08c8fSMichael Baum list[ns].cdev = cdev; 23502eb4d010SOphir Munk list[ns].pf_bond = -1; 23512eb4d010SOphir Munk list[ns].ifindex = 0; 23522eb4d010SOphir Munk if (nl_rdma >= 0) 23532eb4d010SOphir Munk list[ns].ifindex = mlx5_nl_ifindex 2354834a9019SOphir Munk (nl_rdma, 2355887183efSMichael Baum ibv_match[i]->name, 2356887183efSMichael Baum 1); 23572eb4d010SOphir Munk if (!list[ns].ifindex) { 23582eb4d010SOphir Munk char ifname[IF_NAMESIZE]; 23592eb4d010SOphir Munk 23602eb4d010SOphir Munk /* 23612eb4d010SOphir Munk * Netlink failed, it may happen with old 23622eb4d010SOphir Munk * ib_core kernel driver (before 4.16). 23632eb4d010SOphir Munk * We can assume there is old driver because 23642eb4d010SOphir Munk * here we are processing single ports IB 23652eb4d010SOphir Munk * devices. Let's try sysfs to retrieve 23662eb4d010SOphir Munk * the ifindex. The method works for 23672eb4d010SOphir Munk * master device only. 23682eb4d010SOphir Munk */ 23692eb4d010SOphir Munk if (nd > 1) { 23702eb4d010SOphir Munk /* 23712eb4d010SOphir Munk * Multiple devices found, assume 23722eb4d010SOphir Munk * representors, can not distinguish 23732eb4d010SOphir Munk * master/representor and retrieve 23742eb4d010SOphir Munk * ifindex via sysfs. 23752eb4d010SOphir Munk */ 23762eb4d010SOphir Munk continue; 23772eb4d010SOphir Munk } 2378aec086c9SMatan Azrad ret = mlx5_get_ifname_sysfs 2379aec086c9SMatan Azrad (ibv_match[i]->ibdev_path, ifname); 23802eb4d010SOphir Munk if (!ret) 23812eb4d010SOphir Munk list[ns].ifindex = 23822eb4d010SOphir Munk if_nametoindex(ifname); 23832eb4d010SOphir Munk if (!list[ns].ifindex) { 23842eb4d010SOphir Munk /* 23852eb4d010SOphir Munk * No network interface index found 23862eb4d010SOphir Munk * for the specified device, it means 23872eb4d010SOphir Munk * there it is neither representor 23882eb4d010SOphir Munk * nor master. 23892eb4d010SOphir Munk */ 23902eb4d010SOphir Munk continue; 23912eb4d010SOphir Munk } 23922eb4d010SOphir Munk } 23932eb4d010SOphir Munk ret = -1; 23942eb4d010SOphir Munk if (nl_route >= 0) 2395ca1418ceSMichael Baum ret = mlx5_nl_switch_info(nl_route, 23962eb4d010SOphir Munk list[ns].ifindex, 23972eb4d010SOphir Munk &list[ns].info); 23982eb4d010SOphir Munk if (ret || (!list[ns].info.representor && 23992eb4d010SOphir Munk !list[ns].info.master)) { 24002eb4d010SOphir Munk /* 24012eb4d010SOphir Munk * We failed to recognize representors with 24022eb4d010SOphir Munk * Netlink, let's try to perform the task 24032eb4d010SOphir Munk * with sysfs. 24042eb4d010SOphir Munk */ 2405887183efSMichael Baum ret = mlx5_sysfs_switch_info(list[ns].ifindex, 24062eb4d010SOphir Munk &list[ns].info); 24072eb4d010SOphir Munk } 24082eb4d010SOphir Munk if (!ret && (list[ns].info.representor ^ 24092eb4d010SOphir Munk list[ns].info.master)) { 24102eb4d010SOphir Munk ns++; 24112eb4d010SOphir Munk } else if ((nd == 1) && 24122eb4d010SOphir Munk !list[ns].info.representor && 24132eb4d010SOphir Munk !list[ns].info.master) { 24142eb4d010SOphir Munk /* 2415887183efSMichael Baum * Single IB device with one physical port and 24162eb4d010SOphir Munk * attached network device. 2417887183efSMichael Baum * May be SRIOV is not enabled or there is no 2418887183efSMichael Baum * representors. 24192eb4d010SOphir Munk */ 2420887183efSMichael Baum DRV_LOG(INFO, "No E-Switch support detected."); 24212eb4d010SOphir Munk ns++; 24222eb4d010SOphir Munk break; 24232eb4d010SOphir Munk } 24242eb4d010SOphir Munk } 24252eb4d010SOphir Munk if (!ns) { 24262eb4d010SOphir Munk DRV_LOG(ERR, 2427887183efSMichael Baum "Unable to recognize master/representors on the multiple IB devices."); 24282eb4d010SOphir Munk rte_errno = ENOENT; 24292eb4d010SOphir Munk ret = -rte_errno; 24302eb4d010SOphir Munk goto exit; 24312eb4d010SOphir Munk } 24326b157f3bSViacheslav Ovsiienko /* 24336b157f3bSViacheslav Ovsiienko * New kernels may add the switch_id attribute for the case 2434ca1418ceSMichael Baum * there is no E-Switch and we wrongly recognized the only 2435ca1418ceSMichael Baum * device as master. Override this if there is the single 2436ca1418ceSMichael Baum * device with single port and new device name format present. 24376b157f3bSViacheslav Ovsiienko */ 24386b157f3bSViacheslav Ovsiienko if (nd == 1 && 24396b157f3bSViacheslav Ovsiienko list[0].info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK) { 24406b157f3bSViacheslav Ovsiienko list[0].info.master = 0; 24416b157f3bSViacheslav Ovsiienko list[0].info.representor = 0; 24426b157f3bSViacheslav Ovsiienko } 24432eb4d010SOphir Munk } 24442eb4d010SOphir Munk MLX5_ASSERT(ns); 24452eb4d010SOphir Munk /* 24462eb4d010SOphir Munk * Sort list to probe devices in natural order for users convenience 24472eb4d010SOphir Munk * (i.e. master first, then representors from lowest to highest ID). 24482eb4d010SOphir Munk */ 24492eb4d010SOphir Munk qsort(list, ns, sizeof(*list), mlx5_dev_spawn_data_cmp); 24502eb4d010SOphir Munk /* Device specific configuration. */ 24512eb4d010SOphir Munk switch (pci_dev->id.device_id) { 24522eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF: 24532eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF: 24542eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF: 24552eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF: 24562eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF: 24572eb4d010SOphir Munk case PCI_DEVICE_ID_MELLANOX_CONNECTX6VF: 24583ea12cadSRaslan Darawsheh case PCI_DEVICE_ID_MELLANOX_CONNECTXVF: 2459d462a83cSMichael Baum dev_config_vf = 1; 24602eb4d010SOphir Munk break; 24612eb4d010SOphir Munk default: 2462d462a83cSMichael Baum dev_config_vf = 0; 24632eb4d010SOphir Munk break; 24642eb4d010SOphir Munk } 2465f926cce3SXueming Li if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) { 2466f926cce3SXueming Li /* Set devargs default values. */ 2467f926cce3SXueming Li if (eth_da.nb_mh_controllers == 0) { 2468f926cce3SXueming Li eth_da.nb_mh_controllers = 1; 2469f926cce3SXueming Li eth_da.mh_controllers[0] = 0; 2470f926cce3SXueming Li } 2471f926cce3SXueming Li if (eth_da.nb_ports == 0 && ns > 0) { 2472f926cce3SXueming Li if (list[0].pf_bond >= 0 && list[0].info.representor) 2473f926cce3SXueming Li DRV_LOG(WARNING, "Representor on Bonding device should use pf#vf# syntax: %s", 2474f926cce3SXueming Li pci_dev->device.devargs->args); 2475f926cce3SXueming Li eth_da.nb_ports = 1; 2476f926cce3SXueming Li eth_da.ports[0] = list[0].info.pf_num; 2477f926cce3SXueming Li } 2478f926cce3SXueming Li if (eth_da.nb_representor_ports == 0) { 2479f926cce3SXueming Li eth_da.nb_representor_ports = 1; 2480f926cce3SXueming Li eth_da.representor_ports[0] = 0; 2481f926cce3SXueming Li } 2482f926cce3SXueming Li } 24832eb4d010SOphir Munk for (i = 0; i != ns; ++i) { 24842eb4d010SOphir Munk uint32_t restore; 24852eb4d010SOphir Munk 2486d462a83cSMichael Baum /* Default configuration. */ 2487919488fbSXueming Li mlx5_os_config_default(&dev_config); 2488d462a83cSMichael Baum dev_config.vf = dev_config_vf; 24897af08c8fSMichael Baum list[i].eth_dev = mlx5_dev_spawn(cdev->dev, &list[i], 24907af08c8fSMichael Baum &dev_config, ð_da); 24912eb4d010SOphir Munk if (!list[i].eth_dev) { 24922eb4d010SOphir Munk if (rte_errno != EBUSY && rte_errno != EEXIST) 24932eb4d010SOphir Munk break; 24942eb4d010SOphir Munk /* Device is disabled or already spawned. Ignore it. */ 24952eb4d010SOphir Munk continue; 24962eb4d010SOphir Munk } 24972eb4d010SOphir Munk restore = list[i].eth_dev->data->dev_flags; 24982eb4d010SOphir Munk rte_eth_copy_pci_info(list[i].eth_dev, pci_dev); 2499494d6863SGregory Etelson /** 2500494d6863SGregory Etelson * Each representor has a dedicated interrupts vector. 2501494d6863SGregory Etelson * rte_eth_copy_pci_info() assigns PF interrupts handle to 2502494d6863SGregory Etelson * representor eth_dev object because representor and PF 2503494d6863SGregory Etelson * share the same PCI address. 2504494d6863SGregory Etelson * Override representor device with a dedicated 2505494d6863SGregory Etelson * interrupts handle here. 2506494d6863SGregory Etelson * Representor interrupts handle is released in mlx5_dev_stop(). 2507494d6863SGregory Etelson */ 2508494d6863SGregory Etelson if (list[i].info.representor) { 2509d61138d4SHarman Kalra struct rte_intr_handle *intr_handle = 2510d61138d4SHarman Kalra rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED); 2511d61138d4SHarman Kalra if (intr_handle == NULL) { 2512494d6863SGregory Etelson DRV_LOG(ERR, 2513494d6863SGregory Etelson "port %u failed to allocate memory for interrupt handler " 2514494d6863SGregory Etelson "Rx interrupts will not be supported", 2515494d6863SGregory Etelson i); 2516494d6863SGregory Etelson rte_errno = ENOMEM; 2517494d6863SGregory Etelson ret = -rte_errno; 2518494d6863SGregory Etelson goto exit; 2519494d6863SGregory Etelson } 2520494d6863SGregory Etelson list[i].eth_dev->intr_handle = intr_handle; 2521494d6863SGregory Etelson } 25222eb4d010SOphir Munk /* Restore non-PCI flags cleared by the above call. */ 25232eb4d010SOphir Munk list[i].eth_dev->data->dev_flags |= restore; 25242eb4d010SOphir Munk rte_eth_dev_probing_finish(list[i].eth_dev); 25252eb4d010SOphir Munk } 25262eb4d010SOphir Munk if (i != ns) { 25272eb4d010SOphir Munk DRV_LOG(ERR, 25282eb4d010SOphir Munk "probe of PCI device " PCI_PRI_FMT " aborted after" 25292eb4d010SOphir Munk " encountering an error: %s", 2530f926cce3SXueming Li owner_pci.domain, owner_pci.bus, 2531f926cce3SXueming Li owner_pci.devid, owner_pci.function, 25322eb4d010SOphir Munk strerror(rte_errno)); 25332eb4d010SOphir Munk ret = -rte_errno; 25342eb4d010SOphir Munk /* Roll back. */ 25352eb4d010SOphir Munk while (i--) { 25362eb4d010SOphir Munk if (!list[i].eth_dev) 25372eb4d010SOphir Munk continue; 25382eb4d010SOphir Munk mlx5_dev_close(list[i].eth_dev); 25392eb4d010SOphir Munk /* mac_addrs must not be freed because in dev_private */ 25402eb4d010SOphir Munk list[i].eth_dev->data->mac_addrs = NULL; 25412eb4d010SOphir Munk claim_zero(rte_eth_dev_release_port(list[i].eth_dev)); 25422eb4d010SOphir Munk } 25432eb4d010SOphir Munk /* Restore original error. */ 25442eb4d010SOphir Munk rte_errno = -ret; 25452eb4d010SOphir Munk } else { 25462eb4d010SOphir Munk ret = 0; 25472eb4d010SOphir Munk } 25482eb4d010SOphir Munk exit: 25492eb4d010SOphir Munk /* 25502eb4d010SOphir Munk * Do the routine cleanup: 25512eb4d010SOphir Munk * - close opened Netlink sockets 25522eb4d010SOphir Munk * - free allocated spawn data array 25532eb4d010SOphir Munk * - free the Infiniband device list 25542eb4d010SOphir Munk */ 25552eb4d010SOphir Munk if (nl_rdma >= 0) 25562eb4d010SOphir Munk close(nl_rdma); 25572eb4d010SOphir Munk if (nl_route >= 0) 25582eb4d010SOphir Munk close(nl_route); 25592eb4d010SOphir Munk if (list) 25602175c4dcSSuanming Mou mlx5_free(list); 25612eb4d010SOphir Munk MLX5_ASSERT(ibv_list); 25622eb4d010SOphir Munk mlx5_glue->free_device_list(ibv_list); 25632eb4d010SOphir Munk return ret; 25642eb4d010SOphir Munk } 25652eb4d010SOphir Munk 2566919488fbSXueming Li static int 2567919488fbSXueming Li mlx5_os_parse_eth_devargs(struct rte_device *dev, 2568919488fbSXueming Li struct rte_eth_devargs *eth_da) 2569919488fbSXueming Li { 2570919488fbSXueming Li int ret = 0; 2571919488fbSXueming Li 2572919488fbSXueming Li if (dev->devargs == NULL) 2573919488fbSXueming Li return 0; 2574919488fbSXueming Li memset(eth_da, 0, sizeof(*eth_da)); 2575919488fbSXueming Li /* Parse representor information first from class argument. */ 2576919488fbSXueming Li if (dev->devargs->cls_str) 2577919488fbSXueming Li ret = rte_eth_devargs_parse(dev->devargs->cls_str, eth_da); 2578919488fbSXueming Li if (ret != 0) { 2579919488fbSXueming Li DRV_LOG(ERR, "failed to parse device arguments: %s", 2580919488fbSXueming Li dev->devargs->cls_str); 2581919488fbSXueming Li return -rte_errno; 2582919488fbSXueming Li } 2583919488fbSXueming Li if (eth_da->type == RTE_ETH_REPRESENTOR_NONE) { 2584919488fbSXueming Li /* Parse legacy device argument */ 2585919488fbSXueming Li ret = rte_eth_devargs_parse(dev->devargs->args, eth_da); 2586919488fbSXueming Li if (ret) { 2587919488fbSXueming Li DRV_LOG(ERR, "failed to parse device arguments: %s", 2588919488fbSXueming Li dev->devargs->args); 2589919488fbSXueming Li return -rte_errno; 2590919488fbSXueming Li } 2591919488fbSXueming Li } 2592919488fbSXueming Li return 0; 2593919488fbSXueming Li } 2594919488fbSXueming Li 259508c2772fSXueming Li /** 2596a7f34989SXueming Li * Callback to register a PCI device. 259708c2772fSXueming Li * 259808c2772fSXueming Li * This function spawns Ethernet devices out of a given PCI device. 259908c2772fSXueming Li * 26007af08c8fSMichael Baum * @param[in] cdev 26017af08c8fSMichael Baum * Pointer to common mlx5 device structure. 260208c2772fSXueming Li * 260308c2772fSXueming Li * @return 260408c2772fSXueming Li * 0 on success, a negative errno value otherwise and rte_errno is set. 260508c2772fSXueming Li */ 2606a7f34989SXueming Li static int 2607ca1418ceSMichael Baum mlx5_os_pci_probe(struct mlx5_common_device *cdev) 260808c2772fSXueming Li { 26097af08c8fSMichael Baum struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev); 2610919488fbSXueming Li struct rte_eth_devargs eth_da = { .nb_ports = 0 }; 261108c2772fSXueming Li int ret = 0; 261208c2772fSXueming Li uint16_t p; 261308c2772fSXueming Li 26147af08c8fSMichael Baum ret = mlx5_os_parse_eth_devargs(cdev->dev, ð_da); 2615919488fbSXueming Li if (ret != 0) 2616919488fbSXueming Li return ret; 261708c2772fSXueming Li 261808c2772fSXueming Li if (eth_da.nb_ports > 0) { 261908c2772fSXueming Li /* Iterate all port if devargs pf is range: "pf[0-1]vf[...]". */ 26206856efa5SMichael Baum for (p = 0; p < eth_da.nb_ports; p++) { 2621ca1418ceSMichael Baum ret = mlx5_os_pci_probe_pf(cdev, ð_da, 262208c2772fSXueming Li eth_da.ports[p]); 26236856efa5SMichael Baum if (ret) 26246856efa5SMichael Baum break; 26256856efa5SMichael Baum } 26266856efa5SMichael Baum if (ret) { 26276856efa5SMichael Baum DRV_LOG(ERR, "Probe of PCI device " PCI_PRI_FMT " " 26286856efa5SMichael Baum "aborted due to proding failure of PF %u", 26296856efa5SMichael Baum pci_dev->addr.domain, pci_dev->addr.bus, 26306856efa5SMichael Baum pci_dev->addr.devid, pci_dev->addr.function, 26316856efa5SMichael Baum eth_da.ports[p]); 26327af08c8fSMichael Baum mlx5_net_remove(cdev); 26336856efa5SMichael Baum } 263408c2772fSXueming Li } else { 2635ca1418ceSMichael Baum ret = mlx5_os_pci_probe_pf(cdev, ð_da, 0); 263608c2772fSXueming Li } 263708c2772fSXueming Li return ret; 263808c2772fSXueming Li } 263908c2772fSXueming Li 2640919488fbSXueming Li /* Probe a single SF device on auxiliary bus, no representor support. */ 2641919488fbSXueming Li static int 2642ca1418ceSMichael Baum mlx5_os_auxiliary_probe(struct mlx5_common_device *cdev) 2643919488fbSXueming Li { 2644919488fbSXueming Li struct rte_eth_devargs eth_da = { .nb_ports = 0 }; 2645919488fbSXueming Li struct mlx5_dev_config config; 2646919488fbSXueming Li struct mlx5_dev_spawn_data spawn = { .pf_bond = -1 }; 26477af08c8fSMichael Baum struct rte_device *dev = cdev->dev; 2648919488fbSXueming Li struct rte_auxiliary_device *adev = RTE_DEV_TO_AUXILIARY(dev); 2649919488fbSXueming Li struct rte_eth_dev *eth_dev; 2650919488fbSXueming Li int ret = 0; 2651919488fbSXueming Li 2652919488fbSXueming Li /* Parse ethdev devargs. */ 2653919488fbSXueming Li ret = mlx5_os_parse_eth_devargs(dev, ð_da); 2654919488fbSXueming Li if (ret != 0) 2655919488fbSXueming Li return ret; 2656919488fbSXueming Li /* Set default config data. */ 2657919488fbSXueming Li mlx5_os_config_default(&config); 2658919488fbSXueming Li config.sf = 1; 2659919488fbSXueming Li /* Init spawn data. */ 2660919488fbSXueming Li spawn.max_port = 1; 2661919488fbSXueming Li spawn.phys_port = 1; 2662ca1418ceSMichael Baum spawn.phys_dev_name = mlx5_os_get_ctx_device_name(cdev->ctx); 2663919488fbSXueming Li ret = mlx5_auxiliary_get_ifindex(dev->name); 2664919488fbSXueming Li if (ret < 0) { 2665919488fbSXueming Li DRV_LOG(ERR, "failed to get ethdev ifindex: %s", dev->name); 2666919488fbSXueming Li return ret; 2667919488fbSXueming Li } 2668919488fbSXueming Li spawn.ifindex = ret; 26697af08c8fSMichael Baum spawn.cdev = cdev; 2670919488fbSXueming Li /* Spawn device. */ 2671919488fbSXueming Li eth_dev = mlx5_dev_spawn(dev, &spawn, &config, ð_da); 2672919488fbSXueming Li if (eth_dev == NULL) 2673919488fbSXueming Li return -rte_errno; 2674919488fbSXueming Li /* Post create. */ 2675d61138d4SHarman Kalra eth_dev->intr_handle = adev->intr_handle; 2676919488fbSXueming Li if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 2677919488fbSXueming Li eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC; 2678919488fbSXueming Li eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_RMV; 2679919488fbSXueming Li eth_dev->data->numa_node = dev->numa_node; 2680919488fbSXueming Li } 2681919488fbSXueming Li rte_eth_dev_probing_finish(eth_dev); 2682919488fbSXueming Li return 0; 2683919488fbSXueming Li } 2684919488fbSXueming Li 2685a7f34989SXueming Li /** 2686a7f34989SXueming Li * Net class driver callback to probe a device. 2687a7f34989SXueming Li * 2688919488fbSXueming Li * This function probe PCI bus device(s) or a single SF on auxiliary bus. 2689a7f34989SXueming Li * 26907af08c8fSMichael Baum * @param[in] cdev 26917af08c8fSMichael Baum * Pointer to the common mlx5 device. 2692a7f34989SXueming Li * 2693a7f34989SXueming Li * @return 26947af08c8fSMichael Baum * 0 on success, a negative errno value otherwise and rte_errno is set. 2695a7f34989SXueming Li */ 2696a7f34989SXueming Li int 26977af08c8fSMichael Baum mlx5_os_net_probe(struct mlx5_common_device *cdev) 2698a7f34989SXueming Li { 2699a7f34989SXueming Li int ret; 2700a7f34989SXueming Li 2701ca1418ceSMichael Baum if (rte_eal_process_type() == RTE_PROC_PRIMARY) 2702a7f34989SXueming Li mlx5_pmd_socket_init(); 2703a7f34989SXueming Li ret = mlx5_init_once(); 2704a7f34989SXueming Li if (ret) { 27057af08c8fSMichael Baum DRV_LOG(ERR, "Unable to init PMD global data: %s", 2706a7f34989SXueming Li strerror(rte_errno)); 2707a7f34989SXueming Li return -rte_errno; 2708a7f34989SXueming Li } 27097af08c8fSMichael Baum if (mlx5_dev_is_pci(cdev->dev)) 2710ca1418ceSMichael Baum return mlx5_os_pci_probe(cdev); 2711919488fbSXueming Li else 2712ca1418ceSMichael Baum return mlx5_os_auxiliary_probe(cdev); 27132eb4d010SOphir Munk } 27142eb4d010SOphir Munk 27152eb4d010SOphir Munk /** 2716ea823b2cSDmitry Kozlyuk * Cleanup resources when the last device is closed. 2717ea823b2cSDmitry Kozlyuk */ 2718ea823b2cSDmitry Kozlyuk void 2719ea823b2cSDmitry Kozlyuk mlx5_os_net_cleanup(void) 2720ea823b2cSDmitry Kozlyuk { 2721ea823b2cSDmitry Kozlyuk mlx5_pmd_socket_uninit(); 2722ea823b2cSDmitry Kozlyuk } 2723ea823b2cSDmitry Kozlyuk 2724ea823b2cSDmitry Kozlyuk /** 27252eb4d010SOphir Munk * Install shared asynchronous device events handler. 27262eb4d010SOphir Munk * This function is implemented to support event sharing 27272eb4d010SOphir Munk * between multiple ports of single IB device. 27282eb4d010SOphir Munk * 27292eb4d010SOphir Munk * @param sh 27302eb4d010SOphir Munk * Pointer to mlx5_dev_ctx_shared object. 27312eb4d010SOphir Munk */ 27322eb4d010SOphir Munk void 27332eb4d010SOphir Munk mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) 27342eb4d010SOphir Munk { 27352eb4d010SOphir Munk int ret; 27362eb4d010SOphir Munk int flags; 2737ca1418ceSMichael Baum struct ibv_context *ctx = sh->cdev->ctx; 27382eb4d010SOphir Munk 2739d61138d4SHarman Kalra sh->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED); 2740d61138d4SHarman Kalra if (sh->intr_handle == NULL) { 2741d61138d4SHarman Kalra DRV_LOG(ERR, "Fail to allocate intr_handle"); 2742d61138d4SHarman Kalra rte_errno = ENOMEM; 2743d61138d4SHarman Kalra return; 2744d61138d4SHarman Kalra } 2745d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle, -1); 2746d61138d4SHarman Kalra 2747ca1418ceSMichael Baum flags = fcntl(ctx->async_fd, F_GETFL); 2748ca1418ceSMichael Baum ret = fcntl(ctx->async_fd, F_SETFL, flags | O_NONBLOCK); 27492eb4d010SOphir Munk if (ret) { 27502eb4d010SOphir Munk DRV_LOG(INFO, "failed to change file descriptor async event" 27512eb4d010SOphir Munk " queue"); 27522eb4d010SOphir Munk } else { 2753d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle, ctx->async_fd); 2754d61138d4SHarman Kalra rte_intr_type_set(sh->intr_handle, RTE_INTR_HANDLE_EXT); 2755d61138d4SHarman Kalra if (rte_intr_callback_register(sh->intr_handle, 27562eb4d010SOphir Munk mlx5_dev_interrupt_handler, sh)) { 27572eb4d010SOphir Munk DRV_LOG(INFO, "Fail to install the shared interrupt."); 2758d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle, -1); 27592eb4d010SOphir Munk } 27602eb4d010SOphir Munk } 27612eb4d010SOphir Munk if (sh->devx) { 27622eb4d010SOphir Munk #ifdef HAVE_IBV_DEVX_ASYNC 2763d61138d4SHarman Kalra sh->intr_handle_devx = 2764d61138d4SHarman Kalra rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED); 2765d61138d4SHarman Kalra if (!sh->intr_handle_devx) { 2766d61138d4SHarman Kalra DRV_LOG(ERR, "Fail to allocate intr_handle"); 2767d61138d4SHarman Kalra rte_errno = ENOMEM; 2768d61138d4SHarman Kalra return; 2769d61138d4SHarman Kalra } 2770d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle_devx, -1); 2771ca1418ceSMichael Baum sh->devx_comp = (void *)mlx5_glue->devx_create_cmd_comp(ctx); 277221b7c452SOphir Munk struct mlx5dv_devx_cmd_comp *devx_comp = sh->devx_comp; 277321b7c452SOphir Munk if (!devx_comp) { 27742eb4d010SOphir Munk DRV_LOG(INFO, "failed to allocate devx_comp."); 27752eb4d010SOphir Munk return; 27762eb4d010SOphir Munk } 277721b7c452SOphir Munk flags = fcntl(devx_comp->fd, F_GETFL); 277821b7c452SOphir Munk ret = fcntl(devx_comp->fd, F_SETFL, flags | O_NONBLOCK); 27792eb4d010SOphir Munk if (ret) { 27802eb4d010SOphir Munk DRV_LOG(INFO, "failed to change file descriptor" 27812eb4d010SOphir Munk " devx comp"); 27822eb4d010SOphir Munk return; 27832eb4d010SOphir Munk } 2784d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle_devx, devx_comp->fd); 2785d61138d4SHarman Kalra rte_intr_type_set(sh->intr_handle_devx, 2786d61138d4SHarman Kalra RTE_INTR_HANDLE_EXT); 2787d61138d4SHarman Kalra if (rte_intr_callback_register(sh->intr_handle_devx, 27882eb4d010SOphir Munk mlx5_dev_interrupt_handler_devx, sh)) { 27892eb4d010SOphir Munk DRV_LOG(INFO, "Fail to install the devx shared" 27902eb4d010SOphir Munk " interrupt."); 2791d61138d4SHarman Kalra rte_intr_fd_set(sh->intr_handle_devx, -1); 27922eb4d010SOphir Munk } 27932eb4d010SOphir Munk #endif /* HAVE_IBV_DEVX_ASYNC */ 27942eb4d010SOphir Munk } 27952eb4d010SOphir Munk } 27962eb4d010SOphir Munk 27972eb4d010SOphir Munk /** 27982eb4d010SOphir Munk * Uninstall shared asynchronous device events handler. 27992eb4d010SOphir Munk * This function is implemented to support event sharing 28002eb4d010SOphir Munk * between multiple ports of single IB device. 28012eb4d010SOphir Munk * 28022eb4d010SOphir Munk * @param dev 28032eb4d010SOphir Munk * Pointer to mlx5_dev_ctx_shared object. 28042eb4d010SOphir Munk */ 28052eb4d010SOphir Munk void 28062eb4d010SOphir Munk mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh) 28072eb4d010SOphir Munk { 2808d61138d4SHarman Kalra if (rte_intr_fd_get(sh->intr_handle) >= 0) 2809d61138d4SHarman Kalra mlx5_intr_callback_unregister(sh->intr_handle, 28102eb4d010SOphir Munk mlx5_dev_interrupt_handler, sh); 2811d61138d4SHarman Kalra rte_intr_instance_free(sh->intr_handle); 28122eb4d010SOphir Munk #ifdef HAVE_IBV_DEVX_ASYNC 2813d61138d4SHarman Kalra if (rte_intr_fd_get(sh->intr_handle_devx) >= 0) 2814d61138d4SHarman Kalra rte_intr_callback_unregister(sh->intr_handle_devx, 28152eb4d010SOphir Munk mlx5_dev_interrupt_handler_devx, sh); 2816d61138d4SHarman Kalra rte_intr_instance_free(sh->intr_handle_devx); 28172eb4d010SOphir Munk if (sh->devx_comp) 28182eb4d010SOphir Munk mlx5_glue->devx_destroy_cmd_comp(sh->devx_comp); 28192eb4d010SOphir Munk #endif 28202eb4d010SOphir Munk } 2821042f5c94SOphir Munk 282273bf9235SOphir Munk /** 282373bf9235SOphir Munk * Read statistics by a named counter. 282473bf9235SOphir Munk * 282573bf9235SOphir Munk * @param[in] priv 282673bf9235SOphir Munk * Pointer to the private device data structure. 282773bf9235SOphir Munk * @param[in] ctr_name 282873bf9235SOphir Munk * Pointer to the name of the statistic counter to read 282973bf9235SOphir Munk * @param[out] stat 283073bf9235SOphir Munk * Pointer to read statistic value. 283173bf9235SOphir Munk * @return 283273bf9235SOphir Munk * 0 on success and stat is valud, 1 if failed to read the value 283373bf9235SOphir Munk * rte_errno is set. 283473bf9235SOphir Munk * 283573bf9235SOphir Munk */ 283673bf9235SOphir Munk int 283773bf9235SOphir Munk mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, 283873bf9235SOphir Munk uint64_t *stat) 283973bf9235SOphir Munk { 284073bf9235SOphir Munk int fd; 284173bf9235SOphir Munk 284273bf9235SOphir Munk if (priv->sh) { 2843e6988afdSMatan Azrad if (priv->q_counters != NULL && 2844e6988afdSMatan Azrad strcmp(ctr_name, "out_of_buffer") == 0) 2845978a0303SViacheslav Ovsiienko return mlx5_devx_cmd_queue_counter_query 2846978a0303SViacheslav Ovsiienko (priv->q_counters, 0, (uint32_t *)stat); 284773bf9235SOphir Munk MKSTR(path, "%s/ports/%d/hw_counters/%s", 284873bf9235SOphir Munk priv->sh->ibdev_path, 284973bf9235SOphir Munk priv->dev_port, 285073bf9235SOphir Munk ctr_name); 285173bf9235SOphir Munk fd = open(path, O_RDONLY); 2852038e7fc0SShy Shyman /* 2853038e7fc0SShy Shyman * in switchdev the file location is not per port 2854038e7fc0SShy Shyman * but rather in <ibdev_path>/hw_counters/<file_name>. 2855038e7fc0SShy Shyman */ 2856038e7fc0SShy Shyman if (fd == -1) { 2857038e7fc0SShy Shyman MKSTR(path1, "%s/hw_counters/%s", 2858038e7fc0SShy Shyman priv->sh->ibdev_path, 2859038e7fc0SShy Shyman ctr_name); 2860038e7fc0SShy Shyman fd = open(path1, O_RDONLY); 2861038e7fc0SShy Shyman } 286273bf9235SOphir Munk if (fd != -1) { 286373bf9235SOphir Munk char buf[21] = {'\0'}; 286473bf9235SOphir Munk ssize_t n = read(fd, buf, sizeof(buf)); 286573bf9235SOphir Munk 286673bf9235SOphir Munk close(fd); 286773bf9235SOphir Munk if (n != -1) { 286873bf9235SOphir Munk *stat = strtoull(buf, NULL, 10); 286973bf9235SOphir Munk return 0; 287073bf9235SOphir Munk } 287173bf9235SOphir Munk } 287273bf9235SOphir Munk } 287373bf9235SOphir Munk *stat = 0; 287473bf9235SOphir Munk return 1; 287573bf9235SOphir Munk } 287673bf9235SOphir Munk 287773bf9235SOphir Munk /** 2878ab27cdd9SOphir Munk * Remove a MAC address from device 2879ab27cdd9SOphir Munk * 2880ab27cdd9SOphir Munk * @param dev 2881ab27cdd9SOphir Munk * Pointer to Ethernet device structure. 2882ab27cdd9SOphir Munk * @param index 2883ab27cdd9SOphir Munk * MAC address index. 2884ab27cdd9SOphir Munk */ 2885ab27cdd9SOphir Munk void 2886ab27cdd9SOphir Munk mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 2887ab27cdd9SOphir Munk { 2888ab27cdd9SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 2889ab27cdd9SOphir Munk const int vf = priv->config.vf; 2890ab27cdd9SOphir Munk 2891ab27cdd9SOphir Munk if (vf) 2892ab27cdd9SOphir Munk mlx5_nl_mac_addr_remove(priv->nl_socket_route, 2893ab27cdd9SOphir Munk mlx5_ifindex(dev), priv->mac_own, 2894ab27cdd9SOphir Munk &dev->data->mac_addrs[index], index); 2895ab27cdd9SOphir Munk } 2896ab27cdd9SOphir Munk 2897ab27cdd9SOphir Munk /** 2898ab27cdd9SOphir Munk * Adds a MAC address to the device 2899ab27cdd9SOphir Munk * 2900ab27cdd9SOphir Munk * @param dev 2901ab27cdd9SOphir Munk * Pointer to Ethernet device structure. 2902ab27cdd9SOphir Munk * @param mac_addr 2903ab27cdd9SOphir Munk * MAC address to register. 2904ab27cdd9SOphir Munk * @param index 2905ab27cdd9SOphir Munk * MAC address index. 2906ab27cdd9SOphir Munk * 2907ab27cdd9SOphir Munk * @return 2908ab27cdd9SOphir Munk * 0 on success, a negative errno value otherwise 2909ab27cdd9SOphir Munk */ 2910ab27cdd9SOphir Munk int 2911ab27cdd9SOphir Munk mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 2912ab27cdd9SOphir Munk uint32_t index) 2913ab27cdd9SOphir Munk { 2914ab27cdd9SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 2915ab27cdd9SOphir Munk const int vf = priv->config.vf; 2916ab27cdd9SOphir Munk int ret = 0; 2917ab27cdd9SOphir Munk 2918ab27cdd9SOphir Munk if (vf) 2919ab27cdd9SOphir Munk ret = mlx5_nl_mac_addr_add(priv->nl_socket_route, 2920ab27cdd9SOphir Munk mlx5_ifindex(dev), priv->mac_own, 2921ab27cdd9SOphir Munk mac, index); 2922ab27cdd9SOphir Munk return ret; 2923ab27cdd9SOphir Munk } 2924ab27cdd9SOphir Munk 2925ab27cdd9SOphir Munk /** 2926ab27cdd9SOphir Munk * Modify a VF MAC address 2927ab27cdd9SOphir Munk * 2928ab27cdd9SOphir Munk * @param priv 2929ab27cdd9SOphir Munk * Pointer to device private data. 2930ab27cdd9SOphir Munk * @param mac_addr 2931ab27cdd9SOphir Munk * MAC address to modify into. 2932ab27cdd9SOphir Munk * @param iface_idx 2933ab27cdd9SOphir Munk * Net device interface index 2934ab27cdd9SOphir Munk * @param vf_index 2935ab27cdd9SOphir Munk * VF index 2936ab27cdd9SOphir Munk * 2937ab27cdd9SOphir Munk * @return 2938ab27cdd9SOphir Munk * 0 on success, a negative errno value otherwise 2939ab27cdd9SOphir Munk */ 2940ab27cdd9SOphir Munk int 2941ab27cdd9SOphir Munk mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, 2942ab27cdd9SOphir Munk unsigned int iface_idx, 2943ab27cdd9SOphir Munk struct rte_ether_addr *mac_addr, 2944ab27cdd9SOphir Munk int vf_index) 2945ab27cdd9SOphir Munk { 2946ab27cdd9SOphir Munk return mlx5_nl_vf_mac_addr_modify 2947ab27cdd9SOphir Munk (priv->nl_socket_route, iface_idx, mac_addr, vf_index); 2948ab27cdd9SOphir Munk } 2949ab27cdd9SOphir Munk 29504d18abd1SOphir Munk /** 29514d18abd1SOphir Munk * Set device promiscuous mode 29524d18abd1SOphir Munk * 29534d18abd1SOphir Munk * @param dev 29544d18abd1SOphir Munk * Pointer to Ethernet device structure. 29554d18abd1SOphir Munk * @param enable 29564d18abd1SOphir Munk * 0 - promiscuous is disabled, otherwise - enabled 29574d18abd1SOphir Munk * 29584d18abd1SOphir Munk * @return 29594d18abd1SOphir Munk * 0 on success, a negative error value otherwise 29604d18abd1SOphir Munk */ 29614d18abd1SOphir Munk int 29624d18abd1SOphir Munk mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable) 29634d18abd1SOphir Munk { 29644d18abd1SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 29654d18abd1SOphir Munk 29664d18abd1SOphir Munk return mlx5_nl_promisc(priv->nl_socket_route, 29674d18abd1SOphir Munk mlx5_ifindex(dev), !!enable); 29684d18abd1SOphir Munk } 29694d18abd1SOphir Munk 29704d18abd1SOphir Munk /** 29714d18abd1SOphir Munk * Set device promiscuous mode 29724d18abd1SOphir Munk * 29734d18abd1SOphir Munk * @param dev 29744d18abd1SOphir Munk * Pointer to Ethernet device structure. 29754d18abd1SOphir Munk * @param enable 29764d18abd1SOphir Munk * 0 - all multicase is disabled, otherwise - enabled 29774d18abd1SOphir Munk * 29784d18abd1SOphir Munk * @return 29794d18abd1SOphir Munk * 0 on success, a negative error value otherwise 29804d18abd1SOphir Munk */ 29814d18abd1SOphir Munk int 29824d18abd1SOphir Munk mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable) 29834d18abd1SOphir Munk { 29844d18abd1SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 29854d18abd1SOphir Munk 29864d18abd1SOphir Munk return mlx5_nl_allmulti(priv->nl_socket_route, 29874d18abd1SOphir Munk mlx5_ifindex(dev), !!enable); 29884d18abd1SOphir Munk } 29894d18abd1SOphir Munk 2990f00f6562SOphir Munk /** 2991f00f6562SOphir Munk * Flush device MAC addresses 2992f00f6562SOphir Munk * 2993f00f6562SOphir Munk * @param dev 2994f00f6562SOphir Munk * Pointer to Ethernet device structure. 2995f00f6562SOphir Munk * 2996f00f6562SOphir Munk */ 2997f00f6562SOphir Munk void 2998f00f6562SOphir Munk mlx5_os_mac_addr_flush(struct rte_eth_dev *dev) 2999f00f6562SOphir Munk { 3000f00f6562SOphir Munk struct mlx5_priv *priv = dev->data->dev_private; 3001f00f6562SOphir Munk 3002f00f6562SOphir Munk mlx5_nl_mac_addr_flush(priv->nl_socket_route, mlx5_ifindex(dev), 3003f00f6562SOphir Munk dev->data->mac_addrs, 3004f00f6562SOphir Munk MLX5_MAX_MAC_ADDRESSES, priv->mac_own); 3005f00f6562SOphir Munk } 3006