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_
12 #include <rte_debug.h>
13 #include <rte_atomic.h>
15 #include <rte_kvargs.h>
16 #include <rte_devargs.h>
18 #include "mlx5_autoconf.h"
19 #include "mlx5_glue.h"
20 #include "mlx5_malloc.h"
23 * Get device name. Given an ibv_device pointer - return a
24 * pointer to the corresponding device name.
27 * Pointer to ibv device.
30 * Pointer to device name if dev is valid, NULL otherwise.
32 static inline const char *
33 mlx5_os_get_dev_device_name(void *dev)
37 return ((struct ibv_device *)dev)->name;
41 * Get ibv device name. Given an ibv_context pointer - return a
42 * pointer to the corresponding device name.
45 * Pointer to ibv context.
48 * Pointer to device name if ctx is valid, NULL otherwise.
50 static inline const char *
51 mlx5_os_get_ctx_device_name(void *ctx)
55 return ((struct ibv_context *)ctx)->device->name;
59 * Get ibv device path name. Given an ibv_context pointer - return a
60 * pointer to the corresponding device path name.
63 * Pointer to ibv context.
66 * Pointer to device path name if ctx is valid, NULL otherwise.
69 static inline const char *
70 mlx5_os_get_ctx_device_path(void *ctx)
75 return ((struct ibv_context *)ctx)->device->ibdev_path;
79 * Get umem id. Given a pointer to umem object of type
80 * 'struct mlx5dv_devx_umem *' - return its id.
83 * Pointer to umem object.
86 * The umem id if umem is valid, 0 otherwise.
88 static inline uint32_t
89 mlx5_os_get_umem_id(void *umem)
93 return ((struct mlx5dv_devx_umem *)umem)->umem_id;
97 * Get fd. Given a pointer to DevX channel object of type
98 * 'struct mlx5dv_devx_event_channel*' - return its fd.
101 * Pointer to channel object.
104 * The fd if channel is valid, 0 otherwise.
107 mlx5_os_get_devx_channel_fd(void *channel)
111 return ((struct mlx5dv_devx_event_channel *)channel)->fd;
115 * Get mmap offset. Given a pointer to an DevX UAR object of type
116 * 'struct mlx5dv_devx_uar *' - return its mmap offset.
119 * Pointer to UAR object.
122 * The mmap offset if uar is valid, 0 otherwise.
125 mlx5_os_get_devx_uar_mmap_offset(void *uar)
127 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
130 return ((struct mlx5dv_devx_uar *)uar)->mmap_off;
138 * Get base addr pointer. Given a pointer to an UAR object of type
139 * 'struct mlx5dv_devx_uar *' - return its base address.
142 * Pointer to an UAR object.
145 * The base address if UAR is valid, 0 otherwise.
148 mlx5_os_get_devx_uar_base_addr(void *uar)
150 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
153 return ((struct mlx5dv_devx_uar *)uar)->base_addr;
161 * Get reg addr pointer. Given a pointer to an UAR object of type
162 * 'struct mlx5dv_devx_uar *' - return its reg address.
165 * Pointer to an UAR object.
168 * The reg address if UAR is valid, 0 otherwise.
171 mlx5_os_get_devx_uar_reg_addr(void *uar)
173 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
176 return ((struct mlx5dv_devx_uar *)uar)->reg_addr;
184 * Get page id. Given a pointer to an UAR object of type
185 * 'struct mlx5dv_devx_uar *' - return its page id.
188 * Pointer to an UAR object.
191 * The page id if UAR is valid, 0 otherwise.
193 static inline uint32_t
194 mlx5_os_get_devx_uar_page_id(void *uar)
196 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
199 return ((struct mlx5dv_devx_uar *)uar)->page_id;
207 mlx5_os_alloc_pd(void *ctx)
209 return mlx5_glue->alloc_pd(ctx);
213 mlx5_os_dealloc_pd(void *pd)
215 return mlx5_glue->dealloc_pd(pd);
219 mlx5_os_umem_reg(void *ctx, void *addr, size_t size, uint32_t access)
221 return mlx5_glue->devx_umem_reg(ctx, addr, size, access);
225 mlx5_os_umem_dereg(void *pumem)
227 return mlx5_glue->devx_umem_dereg(pumem);
231 * Memory allocation optionally with alignment.
234 * Alignment size (may be zero)
236 * Size in bytes to allocate
239 * Valid pointer to allocated memory, NULL in case of failure
242 mlx5_os_malloc(size_t align, size_t size)
246 if (posix_memalign(&buf, align, size))
252 * This API de-allocates a memory that originally could have been
253 * allocated aligned or non-aligned. In Linux it is a wrapper
257 * Pointer to address to free
261 mlx5_os_free(void *addr)
265 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */