common/mlx5: add reg/dereg MR on Windows
[dpdk.git] / drivers / common / mlx5 / windows / 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_errno.h>
11
12 #include "mlx5_autoconf.h"
13 #include "mlx5_glue.h"
14 #include "mlx5_malloc.h"
15 #include "mlx5_common_mr.h"
16 #include "mlx5_win_ext.h"
17
18 /**
19  * This API allocates aligned or non-aligned memory.  The free can be on either
20  * aligned or nonaligned memory.  To be protected - even though there may be no
21  * alignment - in Windows this API will unconditioanlly call _aligned_malloc()
22  * with at least a minimal alignment size.
23  *
24  * @param[in] align
25  *    The alignment value, which must be an integer power of 2 (or 0 for
26  *    non-alignment)
27  * @param[in] size
28  *    Size in bytes to allocate
29  *
30  * @return
31  *    Valid pointer to allocated memory, NULL in case of failure
32  */
33 static inline void *
34 mlx5_os_malloc(size_t align, size_t size)
35 {
36         if (align < MLX5_MALLOC_ALIGNMENT)
37                 align = MLX5_MALLOC_ALIGNMENT;
38         return _aligned_malloc(size, align);
39 }
40
41 /**
42  * This API de-allocates a memory that originally could have been allocated
43  * aligned or non-aligned. In Windows since the allocation was with
44  * _aligned_malloc() - it is safe to always call _aligned_free().
45  *
46  * @param[in] addr
47  *    Pointer to address to free
48  *
49  */
50 static inline void
51 mlx5_os_free(void *addr)
52 {
53         _aligned_free(addr);
54 }
55
56 /**
57  * Get fd. Given a pointer to DevX channel object of type
58  * 'struct mlx5dv_devx_event_channel*' - return its fd.
59  * Under Windows it is a stub.
60  *
61  * @param[in] channel
62  *    Pointer to channel object.
63  *
64  * @return
65  *    0
66  */
67 static inline int
68 mlx5_os_get_devx_channel_fd(void *channel)
69 {
70         if (!channel)
71                 return 0;
72         return 0;
73 }
74
75 /**
76  * Get device name. Given a device pointer - return a
77  * pointer to the corresponding device name.
78  *
79  * @param[in] dev
80  *   Pointer to device.
81  *
82  * @return
83  *   Pointer to device name if dev is valid, NULL otherwise.
84  */
85 static inline const char *
86 mlx5_os_get_dev_device_name(void *dev)
87 {
88         if (!dev)
89                 return NULL;
90         return ((struct devx_device *)dev)->name;
91 }
92
93 /**
94  * Get device name. Given a context pointer - return a
95  * pointer to the corresponding device name.
96  *
97  * @param[in] ctx
98  *   Pointer to context.
99  *
100  * @return
101  *   Pointer to device name if ctx is valid, NULL otherwise.
102  */
103 static inline const char *
104 mlx5_os_get_ctx_device_name(void *ctx)
105 {
106         if (!ctx)
107                 return NULL;
108         return ((mlx5_context_st *)ctx)->mlx5_dev.name;
109 }
110
111 /**
112  * Get a device path name. Given acontext pointer - return a
113  * pointer to the corresponding device path name.
114  *
115  * @param[in] ctx
116  *   Pointer to context.
117  *
118  * @return
119  *   Pointer to device path name if ctx is valid, NULL otherwise.
120  */
121
122 static inline const char *
123 mlx5_os_get_ctx_device_path(void *ctx)
124 {
125         if (!ctx)
126                 return NULL;
127         return ((mlx5_context_st *)ctx)->mlx5_dev.dev_pnp_id;
128 }
129
130 /**
131  * Get umem id. Given a pointer to umem object of type return its id.
132  *
133  * @param[in] umem
134  *    Pointer to umem object.
135  *
136  * @return
137  *    The umem id if umem is valid, 0 otherwise.
138  */
139 static inline uint32_t
140 mlx5_os_get_umem_id(void *umem)
141 {
142         if (!umem)
143                 return 0;
144         return ((struct mlx5_devx_umem *)umem)->umem_id;
145 }
146
147 void *mlx5_os_alloc_pd(void *ctx);
148 int mlx5_os_dealloc_pd(void *pd);
149 void *mlx5_os_umem_reg(void *ctx, void *addr, size_t size, uint32_t access);
150 int mlx5_os_umem_dereg(void *pumem);
151 int mlx5_os_reg_mr(void *pd,
152                    void *addr, size_t length, struct mlx5_pmd_mr *pmd_mr);
153 void mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
154 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */