55c09027ab170b93b73292c5cc96fa25a098c458
[dpdk.git] / drivers / common / mlx5 / linux / mlx5_common_os.h
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 #include "mlx5_glue.h"
19
20 /**
21  * Get device name. Given an ibv_device pointer - return a
22  * pointer to the corresponding device name.
23  *
24  * @param[in] dev
25  *   Pointer to ibv device.
26  *
27  * @return
28  *   Pointer to device name if dev is valid, NULL otherwise.
29  */
30 static inline const char *
31 mlx5_os_get_dev_device_name(void *dev)
32 {
33         if (!dev)
34                 return NULL;
35         return ((struct ibv_device *)dev)->name;
36 }
37
38 /**
39  * Get ibv device name. Given an ibv_context pointer - return a
40  * pointer to the corresponding device name.
41  *
42  * @param[in] ctx
43  *   Pointer to ibv context.
44  *
45  * @return
46  *   Pointer to device name if ctx is valid, NULL otherwise.
47  */
48 static inline const char *
49 mlx5_os_get_ctx_device_name(void *ctx)
50 {
51         if (!ctx)
52                 return NULL;
53         return ((struct ibv_context *)ctx)->device->name;
54 }
55
56 /**
57  * Get ibv device path name. Given an ibv_context pointer - return a
58  * pointer to the corresponding device path name.
59  *
60  * @param[in] ctx
61  *   Pointer to ibv context.
62  *
63  * @return
64  *   Pointer to device path name if ctx is valid, NULL otherwise.
65  */
66
67 static inline const char *
68 mlx5_os_get_ctx_device_path(void *ctx)
69 {
70         if (!ctx)
71                 return NULL;
72
73         return ((struct ibv_context *)ctx)->device->ibdev_path;
74 }
75
76 /**
77  * Get umem id. Given a pointer to umem object of type
78  * 'struct mlx5dv_devx_umem *' - return its id.
79  *
80  * @param[in] umem
81  *    Pointer to umem object.
82  *
83  * @return
84  *    The umem id if umem is valid, 0 otherwise.
85  */
86 static inline uint32_t
87 mlx5_os_get_umem_id(void *umem)
88 {
89         if (!umem)
90                 return 0;
91         return ((struct mlx5dv_devx_umem *)umem)->umem_id;
92 }
93 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */