1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
5 #ifndef RTE_PMD_MLX5_COMMON_OS_H_
6 #define RTE_PMD_MLX5_COMMON_OS_H_
11 #include <rte_debug.h>
12 #include <rte_atomic.h>
14 #include <rte_kvargs.h>
15 #include <rte_devargs.h>
17 #include "mlx5_autoconf.h"
18 #include "mlx5_glue.h"
21 * Get device name. Given an ibv_device pointer - return a
22 * pointer to the corresponding device name.
25 * Pointer to ibv device.
28 * Pointer to device name if dev is valid, NULL otherwise.
30 static inline const char *
31 mlx5_os_get_dev_device_name(void *dev)
35 return ((struct ibv_device *)dev)->name;
39 * Get ibv device name. Given an ibv_context pointer - return a
40 * pointer to the corresponding device name.
43 * Pointer to ibv context.
46 * Pointer to device name if ctx is valid, NULL otherwise.
48 static inline const char *
49 mlx5_os_get_ctx_device_name(void *ctx)
53 return ((struct ibv_context *)ctx)->device->name;
57 * Get ibv device path name. Given an ibv_context pointer - return a
58 * pointer to the corresponding device path name.
61 * Pointer to ibv context.
64 * Pointer to device path name if ctx is valid, NULL otherwise.
67 static inline const char *
68 mlx5_os_get_ctx_device_path(void *ctx)
73 return ((struct ibv_context *)ctx)->device->ibdev_path;
77 * Get umem id. Given a pointer to umem object of type
78 * 'struct mlx5dv_devx_umem *' - return its id.
81 * Pointer to umem object.
84 * The umem id if umem is valid, 0 otherwise.
86 static inline uint32_t
87 mlx5_os_get_umem_id(void *umem)
91 return ((struct mlx5dv_devx_umem *)umem)->umem_id;
95 * Get fd. Given a pointer to DevX channel object of type
96 * 'struct mlx5dv_devx_event_channel*' - return its fd.
99 * Pointer to channel object.
102 * The fd if channel is valid, 0 otherwise.
105 mlx5_os_get_devx_channel_fd(void *channel)
109 return ((struct mlx5dv_devx_event_channel *)channel)->fd;
113 * Get mmap offset. Given a pointer to an DevX UAR object of type
114 * 'struct mlx5dv_devx_uar *' - return its mmap offset.
117 * Pointer to UAR object.
120 * The mmap offset if uar is valid, 0 otherwise.
123 mlx5_os_get_devx_uar_mmap_offset(void *uar)
125 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
128 return ((struct mlx5dv_devx_uar *)uar)->mmap_off;
136 * Get base addr pointer. Given a pointer to an UAR object of type
137 * 'struct mlx5dv_devx_uar *' - return its base address.
140 * Pointer to an UAR object.
143 * The base address if UAR is valid, 0 otherwise.
146 mlx5_os_get_devx_uar_base_addr(void *uar)
148 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
151 return ((struct mlx5dv_devx_uar *)uar)->base_addr;
159 * Get reg addr pointer. Given a pointer to an UAR object of type
160 * 'struct mlx5dv_devx_uar *' - return its reg address.
163 * Pointer to an UAR object.
166 * The reg address if UAR is valid, 0 otherwise.
169 mlx5_os_get_devx_uar_reg_addr(void *uar)
171 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
174 return ((struct mlx5dv_devx_uar *)uar)->reg_addr;
182 * Get page id. Given a pointer to an UAR object of type
183 * 'struct mlx5dv_devx_uar *' - return its page id.
186 * Pointer to an UAR object.
189 * The page id if UAR is valid, 0 otherwise.
191 static inline uint32_t
192 mlx5_os_get_devx_uar_page_id(void *uar)
194 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
197 return ((struct mlx5dv_devx_uar *)uar)->page_id;
204 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */