xref: /dpdk/drivers/common/mlx5/windows/mlx5_common_os.h (revision 1094dd940ec0cc4e3ce2c5cd94807350855a17f9)
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 #include <sys/types.h>
10 
11 #include <rte_compat.h>
12 #include <rte_errno.h>
13 #include <rte_interrupts.h>
14 
15 #include "mlx5_autoconf.h"
16 #include "mlx5_glue.h"
17 #include "mlx5_malloc.h"
18 #include "mlx5_common_mr.h"
19 #include "mlx5_win_ext.h"
20 
21 #define MLX5_BF_OFFSET 0x800
22 
23 /**
24  * This API allocates aligned or non-aligned memory.  The free can be on either
25  * aligned or nonaligned memory.  To be protected - even though there may be no
26  * alignment - in Windows this API will unconditionally call _aligned_malloc()
27  * with at least a minimal alignment size.
28  *
29  * @param[in] align
30  *    The alignment value, which must be an integer power of 2 (or 0 for
31  *    non-alignment)
32  * @param[in] size
33  *    Size in bytes to allocate
34  *
35  * @return
36  *    Valid pointer to allocated memory, NULL in case of failure
37  */
38 static inline void *
mlx5_os_malloc(size_t align,size_t size)39 mlx5_os_malloc(size_t align, size_t size)
40 {
41 	if (align < MLX5_MALLOC_ALIGNMENT)
42 		align = MLX5_MALLOC_ALIGNMENT;
43 	return _aligned_malloc(size, align);
44 }
45 
46 /**
47  * This API de-allocates a memory that originally could have been allocated
48  * aligned or non-aligned. In Windows since the allocation was with
49  * _aligned_malloc() - it is safe to always call _aligned_free().
50  *
51  * @param[in] addr
52  *    Pointer to address to free
53  *
54  */
55 static inline void
mlx5_os_free(void * addr)56 mlx5_os_free(void *addr)
57 {
58 	_aligned_free(addr);
59 }
60 
61 /**
62  * Get fd. Given a pointer to DevX channel object of type
63  * 'struct mlx5dv_devx_event_channel*' - return its fd.
64  * Under Windows it is a stub.
65  *
66  * @param[in] channel
67  *    Pointer to channel object.
68  *
69  * @return
70  *    0
71  */
72 static inline int
mlx5_os_get_devx_channel_fd(void * channel)73 mlx5_os_get_devx_channel_fd(void *channel)
74 {
75 	if (!channel)
76 		return 0;
77 	return 0;
78 }
79 
80 /**
81  * Get device name. Given a device pointer - return a
82  * pointer to the corresponding device name.
83  *
84  * @param[in] dev
85  *   Pointer to device.
86  *
87  * @return
88  *   Pointer to device name if dev is valid, NULL otherwise.
89  */
90 static inline const char *
mlx5_os_get_dev_device_name(void * dev)91 mlx5_os_get_dev_device_name(void *dev)
92 {
93 	if (!dev)
94 		return NULL;
95 	return ((struct devx_device *)dev)->name;
96 }
97 
98 /**
99  * Get device name. Given a context pointer - return a
100  * pointer to the corresponding device name.
101  *
102  * @param[in] ctx
103  *   Pointer to context.
104  *
105  * @return
106  *   Pointer to device name if ctx is valid, NULL otherwise.
107  */
108 static inline const char *
mlx5_os_get_ctx_device_name(void * ctx)109 mlx5_os_get_ctx_device_name(void *ctx)
110 {
111 	if (!ctx)
112 		return NULL;
113 	return ((mlx5_context_st *)ctx)->mlx5_dev.name;
114 }
115 
116 /**
117  * Get a device path name. Given acontext pointer - return a
118  * pointer to the corresponding device path name.
119  *
120  * @param[in] ctx
121  *   Pointer to context.
122  *
123  * @return
124  *   Pointer to device path name if ctx is valid, NULL otherwise.
125  */
126 
127 static inline const char *
mlx5_os_get_ctx_device_path(void * ctx)128 mlx5_os_get_ctx_device_path(void *ctx)
129 {
130 	if (!ctx)
131 		return NULL;
132 	return ((mlx5_context_st *)ctx)->mlx5_dev.dev_pnp_id;
133 }
134 
135 /**
136  * Get umem id. Given a pointer to umem object of type return its id.
137  *
138  * @param[in] umem
139  *    Pointer to umem object.
140  *
141  * @return
142  *    The umem id if umem is valid, 0 otherwise.
143  */
144 static inline uint32_t
mlx5_os_get_umem_id(void * umem)145 mlx5_os_get_umem_id(void *umem)
146 {
147 	if (!umem)
148 		return 0;
149 	return ((struct mlx5_devx_umem *)umem)->umem_id;
150 }
151 
152 /**
153  * Get mmap offset. Given a pointer to an DevX UAR object of type
154  * 'struct mlx5dv_devx_uar *' - return its mmap offset.
155  * In Windows, mmap_offset is unused.
156  *
157  * @param[in] uar
158  *    Pointer to UAR object.
159  *
160  * @return
161  *    0 as mmap_offset is unused
162  */
163 static inline off_t
mlx5_os_get_devx_uar_mmap_offset(void * uar)164 mlx5_os_get_devx_uar_mmap_offset(void *uar)
165 {
166 	RTE_SET_USED(uar);
167 	return 0;
168 }
169 
170 /**
171  * Get base addr pointer. Given a pointer to an UAR object of type
172  * 'struct mlx5dv_devx_uar *' - return its base address.
173  *
174  * @param[in] uar
175  *    Pointer to an UAR object.
176  *
177  * @return
178  *    The base address if UAR is valid, NULL otherwise.
179  */
180 static inline void *
mlx5_os_get_devx_uar_base_addr(void * uar)181 mlx5_os_get_devx_uar_base_addr(void *uar)
182 {
183 	if (!uar)
184 		return NULL;
185 	return ((devx_uar_handle *)uar)->uar_page;
186 }
187 
188 /**
189  * Get reg addr pointer. Given a pointer to an UAR object of type
190  * 'struct mlx5dv_devx_uar *' - return its reg address.
191  *
192  * @param[in] uar
193  *    Pointer to an UAR object.
194  *
195  * @return
196  *    The reg address if UAR is valid, NULL otherwise.
197  */
198 static inline void *
mlx5_os_get_devx_uar_reg_addr(void * uar)199 mlx5_os_get_devx_uar_reg_addr(void *uar)
200 {
201 	if (!uar)
202 		return NULL;
203 	return ((char *)((devx_uar_handle *)uar)->uar_page) + MLX5_BF_OFFSET;
204 }
205 
206 /**
207  * Get page id. Given a pointer to an UAR object of type
208  * 'struct mlx5dv_devx_uar *' - return its page id.
209  *
210  * @param[in] uar
211  *    Pointer to an UAR object.
212  *
213  * @return
214  *    The page id if UAR is valid, 0 otherwise.
215  */
216 static inline uint32_t
mlx5_os_get_devx_uar_page_id(void * uar)217 mlx5_os_get_devx_uar_page_id(void *uar)
218 {
219 	if (!uar)
220 		return 0;
221 	return ((devx_uar_handle *)uar)->uar_index;
222 }
223 
224 static inline void *
mlx5_os_devx_create_event_channel(void * ctx,int flags)225 mlx5_os_devx_create_event_channel(void *ctx, int flags)
226 {
227 	(void)ctx;
228 	(void)flags;
229 	errno = ENOTSUP;
230 	return NULL;
231 }
232 
233 static inline void
mlx5_os_devx_destroy_event_channel(void * eventc)234 mlx5_os_devx_destroy_event_channel(void *eventc)
235 {
236 	(void)eventc;
237 }
238 
239 static inline int
mlx5_os_devx_subscribe_devx_event(void * eventc,void * obj,uint16_t events_sz,uint16_t events_num[],uint64_t cookie)240 mlx5_os_devx_subscribe_devx_event(void *eventc,
241 				    void *obj,
242 				    uint16_t events_sz, uint16_t events_num[],
243 				    uint64_t cookie)
244 {
245 	(void)eventc;
246 	(void)obj;
247 	(void)events_sz;
248 	(void)events_num;
249 	(void)cookie;
250 	return -ENOTSUP;
251 }
252 
253 __rte_internal
254 void *mlx5_os_umem_reg(void *ctx, void *addr, size_t size, uint32_t access);
255 __rte_internal
256 int mlx5_os_umem_dereg(void *pumem);
257 
258 static inline struct rte_intr_handle *
mlx5_os_interrupt_handler_create(int mode,bool set_fd_nonblock,int fd,rte_intr_callback_fn cb,void * cb_arg)259 mlx5_os_interrupt_handler_create(int mode, bool set_fd_nonblock, int fd,
260 				 rte_intr_callback_fn cb, void *cb_arg)
261 {
262 	(void)mode;
263 	(void)set_fd_nonblock;
264 	(void)fd;
265 	(void)cb;
266 	(void)cb_arg;
267 	rte_errno = ENOTSUP;
268 	return NULL;
269 }
270 
271 static inline void
mlx5_os_interrupt_handler_destroy(struct rte_intr_handle * intr_handle,rte_intr_callback_fn cb,void * cb_arg)272 mlx5_os_interrupt_handler_destroy(struct rte_intr_handle *intr_handle,
273 				  rte_intr_callback_fn cb, void *cb_arg)
274 {
275 	(void)intr_handle;
276 	(void)cb;
277 	(void)cb_arg;
278 }
279 
280 
281 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
282