xref: /dpdk/drivers/common/mlx5/linux/mlx5_common_os.h (revision cd346367f898d619edf53f13628d6e539dbcab40)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4 
5 #ifndef RTE_PMD_MLX5_COMMON_OS_H_
6 #define RTE_PMD_MLX5_COMMON_OS_H_
7 
8 #include <stdio.h>
9 
10 #include <rte_pci.h>
11 #include <rte_debug.h>
12 #include <rte_atomic.h>
13 #include <rte_log.h>
14 #include <rte_kvargs.h>
15 #include <rte_devargs.h>
16 
17 #include "mlx5_autoconf.h"
18 #ifdef HAVE_INFINIBAND_VERBS_H
19 #include <infiniband/verbs.h>
20 #endif
21 #ifdef HAVE_INFINIBAND_MLX5DV_H
22 #include <infiniband/mlx5dv.h>
23 #endif
24 
25 /**
26  * Get device name. Given an ibv_device pointer - return a
27  * pointer to the corresponding device name.
28  *
29  * @param[in] dev
30  *   Pointer to ibv device.
31  *
32  * @return
33  *   Pointer to device name if dev is valid, NULL otherwise.
34  */
35 static inline const char *
36 mlx5_os_get_dev_device_name(void *dev)
37 {
38 	if (!dev)
39 		return NULL;
40 	return ((struct ibv_device *)dev)->name;
41 }
42 
43 /**
44  * Get ibv device name. Given an ibv_context pointer - return a
45  * pointer to the corresponding device name.
46  *
47  * @param[in] ctx
48  *   Pointer to ibv context.
49  *
50  * @return
51  *   Pointer to device name if ctx is valid, NULL otherwise.
52  */
53 static inline const char *
54 mlx5_os_get_ctx_device_name(void *ctx)
55 {
56 	if (!ctx)
57 		return NULL;
58 	return ((struct ibv_context *)ctx)->device->name;
59 }
60 
61 /**
62  * Get ibv device path name. Given an ibv_context pointer - return a
63  * pointer to the corresponding device path name.
64  *
65  * @param[in] ctx
66  *   Pointer to ibv context.
67  *
68  * @return
69  *   Pointer to device path name if ctx is valid, NULL otherwise.
70  */
71 
72 static inline const char *
73 mlx5_os_get_ctx_device_path(void *ctx)
74 {
75 	if (!ctx)
76 		return NULL;
77 
78 	return ((struct ibv_context *)ctx)->device->ibdev_path;
79 }
80 
81 /**
82  * Get umem id. Given a pointer to umem object of type
83  * 'struct mlx5dv_devx_umem *' - return its id.
84  *
85  * @param[in] umem
86  *    Pointer to umem object.
87  *
88  * @return
89  *    The umem id if umem is valid, 0 otherwise.
90  */
91 static inline uint32_t
92 mlx5_os_get_umem_id(void *umem)
93 {
94 	if (!umem)
95 		return 0;
96 	return ((struct mlx5dv_devx_umem *)umem)->umem_id;
97 }
98 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
99