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 <sys/mman.h> 14f44b09f9SOphir Munk #include <linux/rtnetlink.h> 15f44b09f9SOphir Munk #include <fcntl.h> 16f44b09f9SOphir Munk 17f44b09f9SOphir Munk /* Verbs header. */ 18f44b09f9SOphir Munk /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */ 19f44b09f9SOphir Munk #ifdef PEDANTIC 20f44b09f9SOphir Munk #pragma GCC diagnostic ignored "-Wpedantic" 21f44b09f9SOphir Munk #endif 22f44b09f9SOphir Munk #include <infiniband/verbs.h> 23f44b09f9SOphir Munk #ifdef PEDANTIC 24f44b09f9SOphir Munk #pragma GCC diagnostic error "-Wpedantic" 25f44b09f9SOphir Munk #endif 26f44b09f9SOphir Munk 27f44b09f9SOphir Munk #include <rte_malloc.h> 28f44b09f9SOphir Munk #include <rte_ethdev_driver.h> 29f44b09f9SOphir Munk #include <rte_ethdev_pci.h> 30f44b09f9SOphir Munk #include <rte_pci.h> 31f44b09f9SOphir Munk #include <rte_bus_pci.h> 32f44b09f9SOphir Munk #include <rte_common.h> 33f44b09f9SOphir Munk #include <rte_kvargs.h> 34f44b09f9SOphir Munk #include <rte_rwlock.h> 35f44b09f9SOphir Munk #include <rte_spinlock.h> 36f44b09f9SOphir Munk #include <rte_string_fns.h> 37f44b09f9SOphir Munk #include <rte_alarm.h> 38f44b09f9SOphir Munk 39f44b09f9SOphir Munk #include <mlx5_glue.h> 40f44b09f9SOphir Munk #include <mlx5_devx_cmds.h> 41f44b09f9SOphir Munk #include <mlx5_common.h> 42f44b09f9SOphir Munk 43f44b09f9SOphir Munk #include "mlx5_defs.h" 44f44b09f9SOphir Munk #include "mlx5.h" 45f44b09f9SOphir Munk #include "mlx5_utils.h" 46f44b09f9SOphir Munk #include "mlx5_rxtx.h" 47f44b09f9SOphir Munk #include "mlx5_autoconf.h" 48f44b09f9SOphir Munk #include "mlx5_mr.h" 49f44b09f9SOphir Munk #include "mlx5_flow.h" 50f44b09f9SOphir Munk #include "rte_pmd_mlx5.h" 51f44b09f9SOphir Munk 52f44b09f9SOphir Munk /** 53f44b09f9SOphir Munk * Get ibv device name. Given an ibv_context pointer - return a 54f44b09f9SOphir Munk * pointer to the corresponding device name. 55f44b09f9SOphir Munk * 56f44b09f9SOphir Munk * @param[in] ctx 57f44b09f9SOphir Munk * Pointer to ibv context. 58f44b09f9SOphir Munk * 59f44b09f9SOphir Munk * @return 60f44b09f9SOphir Munk * Pointer to device name if ctx is valid, NULL otherwise. 61f44b09f9SOphir Munk */ 62f44b09f9SOphir Munk const char * 63f44b09f9SOphir Munk mlx5_os_get_ctx_device_name(void *ctx) 64f44b09f9SOphir Munk { 65f44b09f9SOphir Munk if (!ctx) 66f44b09f9SOphir Munk return NULL; 67f44b09f9SOphir Munk return ((struct ibv_context *)ctx)->device->name; 68f44b09f9SOphir Munk } 69f44b09f9SOphir Munk 70f44b09f9SOphir Munk /** 71f44b09f9SOphir Munk * Get ibv device path name. Given an ibv_context pointer - return a 72f44b09f9SOphir Munk * pointer to the corresponding device path name. 73f44b09f9SOphir Munk * 74f44b09f9SOphir Munk * @param[in] ctx 75f44b09f9SOphir Munk * Pointer to ibv context. 76f44b09f9SOphir Munk * 77f44b09f9SOphir Munk * @return 78f44b09f9SOphir Munk * Pointer to device path name if ctx is valid, NULL otherwise. 79f44b09f9SOphir Munk */ 80f44b09f9SOphir Munk const char * 81f44b09f9SOphir Munk mlx5_os_get_ctx_device_path(void *ctx) 82f44b09f9SOphir Munk { 83f44b09f9SOphir Munk if (!ctx) 84f44b09f9SOphir Munk return NULL; 85f44b09f9SOphir Munk 86f44b09f9SOphir Munk return ((struct ibv_context *)ctx)->device->ibdev_path; 87f44b09f9SOphir Munk } 88*e85f623eSOphir Munk 89*e85f623eSOphir Munk /** 90*e85f623eSOphir Munk * Get mlx5 device attributes. The glue function query_device_ex() is called 91*e85f623eSOphir Munk * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5 92*e85f623eSOphir Munk * device attributes from the glue out parameter. 93*e85f623eSOphir Munk * 94*e85f623eSOphir Munk * @param dev 95*e85f623eSOphir Munk * Pointer to ibv context. 96*e85f623eSOphir Munk * 97*e85f623eSOphir Munk * @param device_attr 98*e85f623eSOphir Munk * Pointer to mlx5 device attributes. 99*e85f623eSOphir Munk * 100*e85f623eSOphir Munk * @return 101*e85f623eSOphir Munk * 0 on success, non zero error number otherwise 102*e85f623eSOphir Munk */ 103*e85f623eSOphir Munk int 104*e85f623eSOphir Munk mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr) 105*e85f623eSOphir Munk { 106*e85f623eSOphir Munk int err; 107*e85f623eSOphir Munk struct ibv_device_attr_ex attr_ex; 108*e85f623eSOphir Munk memset(device_attr, 0, sizeof(*device_attr)); 109*e85f623eSOphir Munk err = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex); 110*e85f623eSOphir Munk if (err) 111*e85f623eSOphir Munk return err; 112*e85f623eSOphir Munk 113*e85f623eSOphir Munk device_attr->device_cap_flags_ex = attr_ex.device_cap_flags_ex; 114*e85f623eSOphir Munk device_attr->max_qp_wr = attr_ex.orig_attr.max_qp_wr; 115*e85f623eSOphir Munk device_attr->max_sge = attr_ex.orig_attr.max_sge; 116*e85f623eSOphir Munk device_attr->max_cq = attr_ex.orig_attr.max_cq; 117*e85f623eSOphir Munk device_attr->max_qp = attr_ex.orig_attr.max_qp; 118*e85f623eSOphir Munk device_attr->raw_packet_caps = attr_ex.raw_packet_caps; 119*e85f623eSOphir Munk device_attr->max_rwq_indirection_table_size = 120*e85f623eSOphir Munk attr_ex.rss_caps.max_rwq_indirection_table_size; 121*e85f623eSOphir Munk device_attr->max_tso = attr_ex.tso_caps.max_tso; 122*e85f623eSOphir Munk device_attr->tso_supported_qpts = attr_ex.tso_caps.supported_qpts; 123*e85f623eSOphir Munk 124*e85f623eSOphir Munk struct mlx5dv_context dv_attr = { .comp_mask = 0 }; 125*e85f623eSOphir Munk err = mlx5_glue->dv_query_device(ctx, &dv_attr); 126*e85f623eSOphir Munk if (err) 127*e85f623eSOphir Munk return err; 128*e85f623eSOphir Munk 129*e85f623eSOphir Munk device_attr->flags = dv_attr.flags; 130*e85f623eSOphir Munk device_attr->comp_mask = dv_attr.comp_mask; 131*e85f623eSOphir Munk #ifdef HAVE_IBV_MLX5_MOD_SWP 132*e85f623eSOphir Munk device_attr->sw_parsing_offloads = 133*e85f623eSOphir Munk dv_attr.sw_parsing_caps.sw_parsing_offloads; 134*e85f623eSOphir Munk #endif 135*e85f623eSOphir Munk device_attr->min_single_stride_log_num_of_bytes = 136*e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_stride_log_num_of_bytes; 137*e85f623eSOphir Munk device_attr->max_single_stride_log_num_of_bytes = 138*e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_stride_log_num_of_bytes; 139*e85f623eSOphir Munk device_attr->min_single_wqe_log_num_of_strides = 140*e85f623eSOphir Munk dv_attr.striding_rq_caps.min_single_wqe_log_num_of_strides; 141*e85f623eSOphir Munk device_attr->max_single_wqe_log_num_of_strides = 142*e85f623eSOphir Munk dv_attr.striding_rq_caps.max_single_wqe_log_num_of_strides; 143*e85f623eSOphir Munk device_attr->stride_supported_qpts = 144*e85f623eSOphir Munk dv_attr.striding_rq_caps.supported_qpts; 145*e85f623eSOphir Munk #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 146*e85f623eSOphir Munk device_attr->tunnel_offloads_caps = dv_attr.tunnel_offloads_caps; 147*e85f623eSOphir Munk #endif 148*e85f623eSOphir Munk 149*e85f623eSOphir Munk return err; 150*e85f623eSOphir Munk } 151