1*f44b09f9SOphir Munk /* SPDX-License-Identifier: BSD-3-Clause 2*f44b09f9SOphir Munk * Copyright 2015 6WIND S.A. 3*f44b09f9SOphir Munk * Copyright 2020 Mellanox Technologies, Ltd 4*f44b09f9SOphir Munk */ 5*f44b09f9SOphir Munk 6*f44b09f9SOphir Munk #include <stddef.h> 7*f44b09f9SOphir Munk #include <unistd.h> 8*f44b09f9SOphir Munk #include <string.h> 9*f44b09f9SOphir Munk #include <stdint.h> 10*f44b09f9SOphir Munk #include <stdlib.h> 11*f44b09f9SOphir Munk #include <errno.h> 12*f44b09f9SOphir Munk #include <net/if.h> 13*f44b09f9SOphir Munk #include <sys/mman.h> 14*f44b09f9SOphir Munk #include <linux/rtnetlink.h> 15*f44b09f9SOphir Munk #include <fcntl.h> 16*f44b09f9SOphir Munk 17*f44b09f9SOphir Munk /* Verbs header. */ 18*f44b09f9SOphir Munk /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */ 19*f44b09f9SOphir Munk #ifdef PEDANTIC 20*f44b09f9SOphir Munk #pragma GCC diagnostic ignored "-Wpedantic" 21*f44b09f9SOphir Munk #endif 22*f44b09f9SOphir Munk #include <infiniband/verbs.h> 23*f44b09f9SOphir Munk #ifdef PEDANTIC 24*f44b09f9SOphir Munk #pragma GCC diagnostic error "-Wpedantic" 25*f44b09f9SOphir Munk #endif 26*f44b09f9SOphir Munk 27*f44b09f9SOphir Munk #include <rte_malloc.h> 28*f44b09f9SOphir Munk #include <rte_ethdev_driver.h> 29*f44b09f9SOphir Munk #include <rte_ethdev_pci.h> 30*f44b09f9SOphir Munk #include <rte_pci.h> 31*f44b09f9SOphir Munk #include <rte_bus_pci.h> 32*f44b09f9SOphir Munk #include <rte_common.h> 33*f44b09f9SOphir Munk #include <rte_kvargs.h> 34*f44b09f9SOphir Munk #include <rte_rwlock.h> 35*f44b09f9SOphir Munk #include <rte_spinlock.h> 36*f44b09f9SOphir Munk #include <rte_string_fns.h> 37*f44b09f9SOphir Munk #include <rte_alarm.h> 38*f44b09f9SOphir Munk 39*f44b09f9SOphir Munk #include <mlx5_glue.h> 40*f44b09f9SOphir Munk #include <mlx5_devx_cmds.h> 41*f44b09f9SOphir Munk #include <mlx5_common.h> 42*f44b09f9SOphir Munk 43*f44b09f9SOphir Munk #include "mlx5_defs.h" 44*f44b09f9SOphir Munk #include "mlx5.h" 45*f44b09f9SOphir Munk #include "mlx5_utils.h" 46*f44b09f9SOphir Munk #include "mlx5_rxtx.h" 47*f44b09f9SOphir Munk #include "mlx5_autoconf.h" 48*f44b09f9SOphir Munk #include "mlx5_mr.h" 49*f44b09f9SOphir Munk #include "mlx5_flow.h" 50*f44b09f9SOphir Munk #include "rte_pmd_mlx5.h" 51*f44b09f9SOphir Munk 52*f44b09f9SOphir Munk /** 53*f44b09f9SOphir Munk * Get ibv device name. Given an ibv_context pointer - return a 54*f44b09f9SOphir Munk * pointer to the corresponding device name. 55*f44b09f9SOphir Munk * 56*f44b09f9SOphir Munk * @param[in] ctx 57*f44b09f9SOphir Munk * Pointer to ibv context. 58*f44b09f9SOphir Munk * 59*f44b09f9SOphir Munk * @return 60*f44b09f9SOphir Munk * Pointer to device name if ctx is valid, NULL otherwise. 61*f44b09f9SOphir Munk */ 62*f44b09f9SOphir Munk const char * 63*f44b09f9SOphir Munk mlx5_os_get_ctx_device_name(void *ctx) 64*f44b09f9SOphir Munk { 65*f44b09f9SOphir Munk if (!ctx) 66*f44b09f9SOphir Munk return NULL; 67*f44b09f9SOphir Munk return ((struct ibv_context *)ctx)->device->name; 68*f44b09f9SOphir Munk } 69*f44b09f9SOphir Munk 70*f44b09f9SOphir Munk /** 71*f44b09f9SOphir Munk * Get ibv device path name. Given an ibv_context pointer - return a 72*f44b09f9SOphir Munk * pointer to the corresponding device path name. 73*f44b09f9SOphir Munk * 74*f44b09f9SOphir Munk * @param[in] ctx 75*f44b09f9SOphir Munk * Pointer to ibv context. 76*f44b09f9SOphir Munk * 77*f44b09f9SOphir Munk * @return 78*f44b09f9SOphir Munk * Pointer to device path name if ctx is valid, NULL otherwise. 79*f44b09f9SOphir Munk */ 80*f44b09f9SOphir Munk const char * 81*f44b09f9SOphir Munk mlx5_os_get_ctx_device_path(void *ctx) 82*f44b09f9SOphir Munk { 83*f44b09f9SOphir Munk if (!ctx) 84*f44b09f9SOphir Munk return NULL; 85*f44b09f9SOphir Munk 86*f44b09f9SOphir Munk return ((struct ibv_context *)ctx)->device->ibdev_path; 87*f44b09f9SOphir Munk } 88