1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
12 #include <rte_malloc.h>
14 #include "mlx5_glue.h"
15 #include "../mlx5_common_log.h"
16 #include "mlx5_win_ext.h"
19 * The returned value of this API is an array of pointers to mlx5
20 * devices under Windows. The interesting parameters of a device:
21 * Device PCI parameters: domain, bus, device id, function.
25 mlx5_glue_devx_get_device_list(int *num_devices)
27 struct devx_device_bdf *devx_bdf_devs = NULL;
28 size_t n_devx_devx = 0;
29 int32_t ret = devx_get_device_list(&n_devx_devx, &devx_bdf_devs);
36 *num_devices = (int)n_devx_devx;
41 mlx5_glue_devx_free_device_list(void *list)
47 devx_free_device_list(list);
51 mlx5_glue_devx_close_device(void *ctx)
53 mlx5_context_st *mlx5_ctx;
58 mlx5_ctx = (mlx5_context_st *)ctx;
59 rc = devx_close_device(mlx5_ctx->devx_ctx);
65 mlx5_glue_devx_open_device(void *device)
67 struct mlx5_context *mlx5_ctx;
73 mlx5_ctx = malloc((sizeof(struct mlx5_context)));
78 memset(mlx5_ctx, 0, sizeof(*mlx5_ctx));
79 mlx5_ctx->devx_ctx = devx_open_device(device);
80 if (DEVX_IS_ERR(mlx5_ctx->devx_ctx)) {
81 errno = -DEVX_PTR_ERR(mlx5_ctx->devx_ctx);
89 mlx5_glue_devx_query_device(void *device_bdf, void *dev_inf)
91 struct devx_device_bdf *dev_bdf;
92 struct devx_device *mlx5_dev;
96 dev_bdf = (struct devx_device_bdf *)device_bdf;
97 mlx5_dev = (struct devx_device *)dev_inf;
98 int err = devx_query_device(dev_bdf, mlx5_dev);
105 mlx5_glue_devx_query_hca_iseg_mapping(void *ctx, uint32_t *cb_iseg)
107 struct mlx5_context *mlx5_ctx;
115 mlx5_ctx = (struct mlx5_context *)ctx;
116 err = devx_query_hca_iseg_mapping(mlx5_ctx->devx_ctx,
126 mlx5_glue_devx_obj_create(void *ctx,
127 void *in, size_t inlen,
128 void *out, size_t outlen)
130 mlx5_devx_obj_st *devx_obj;
136 devx_obj = malloc((sizeof(*devx_obj)));
141 memset(devx_obj, 0, sizeof(*devx_obj));
142 devx_obj->devx_ctx = GET_DEVX_CTX(ctx);
143 devx_obj->obj = devx_obj_create(devx_obj->devx_ctx,
144 in, inlen, out, outlen);
145 if (DEVX_IS_ERR(devx_obj->obj)) {
146 errno = -DEVX_PTR_ERR(devx_obj->obj);
154 mlx5_glue_devx_obj_destroy(void *obj)
156 mlx5_devx_obj_st *devx_obj;
161 int rc = devx_obj_destroy(devx_obj->obj);
167 mlx5_glue_devx_general_cmd(void *ctx,
168 void *in, size_t inlen,
169 void *out, size_t outlen)
173 return devx_cmd(GET_DEVX_CTX(ctx), in, inlen, out, outlen);
177 mlx5_glue_devx_obj_query(void *obj,
178 void *in, size_t inlen,
179 void *out, size_t outlen)
181 return devx_cmd(GET_OBJ_CTX(obj), in, inlen, out, outlen);
185 mlx5_glue_devx_obj_modify(void *obj,
186 void *in, size_t inlen,
187 void *out, size_t outlen)
189 return devx_cmd(GET_OBJ_CTX(obj), in, inlen, out, outlen);
193 mlx5_glue_devx_umem_dereg(void *pumem)
195 struct devx_obj_handle *umem;
200 return devx_umem_unreg(umem);
204 mlx5_glue_devx_umem_reg(void *ctx, void *addr, size_t size,
205 uint32_t access, uint32_t *id)
207 struct devx_obj_handle *umem_hdl;
208 int w_access = DEVX_UMEM_ACCESS_READ;
215 w_access |= DEVX_UMEM_ACCESS_WRITE;
217 umem_hdl = devx_umem_reg(GET_DEVX_CTX(ctx), addr,
219 if (DEVX_IS_ERR(umem_hdl)) {
220 errno = -DEVX_PTR_ERR(umem_hdl);
227 mlx5_glue_devx_alloc_uar(void *ctx,
230 devx_uar_handle *uar;
236 uar = devx_alloc_uar(GET_DEVX_CTX(ctx), flags);
237 if (DEVX_IS_ERR(uar)) {
238 errno = -DEVX_PTR_ERR(uar);
245 mlx5_glue_devx_query_eqn(void *ctx,
246 uint32_t cpus, uint32_t *eqn)
250 return devx_query_eqn(GET_DEVX_CTX(ctx), cpus, eqn);
254 mlx5_glue_devx_free_uar(void *uar)
256 devx_free_uar((devx_uar_handle *)uar);
259 static_assert(MLX5_ST_SZ_BYTES(fte_match_param) == 0x200,
260 "PRM size of fte_match_param is broken! cannot compile Windows!");
263 mlx5_glue_devx_fs_rule_add(void *ctx, void *in, uint32_t inlen)
266 struct devx_obj_handle *rule_hdl = NULL;
272 rule_hdl = devx_fs_rule_add(GET_DEVX_CTX(ctx), in, inlen);
273 if (DEVX_IS_ERR(rule_hdl)) {
274 errno = -DEVX_PTR_ERR(rule_hdl);
281 mlx5_glue_devx_fs_rule_del(void *flow)
283 return devx_fs_rule_del(flow);
287 mlx5_glue_query_rt_values(void *ctx, void *devx_clock)
289 struct mlx5_context *mlx5_ctx;
290 struct mlx5_devx_clock *clock;
297 mlx5_ctx = (struct mlx5_context *)ctx;
298 clock = (struct mlx5_devx_clock *)devx_clock;
299 err = devx_hca_clock_query(
301 &clock->p_iseg_internal_timer,
302 &clock->clock_frequency_hz,
303 &clock->is_stable_clock_frequency);
312 mlx5_glue_devx_init_showdown_event(void *ctx)
314 struct mlx5_context *mlx5_ctx;
321 mlx5_ctx = (struct mlx5_context *)ctx;
322 err = devx_query_shutdown_event(mlx5_ctx->devx_ctx,
323 &mlx5_ctx->shutdown_event_obj);
331 alignas(RTE_CACHE_LINE_SIZE)
332 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
333 .version = MLX5_GLUE_VERSION,
334 .get_device_list = mlx5_glue_devx_get_device_list,
335 .free_device_list = mlx5_glue_devx_free_device_list,
336 .open_device = mlx5_glue_devx_open_device,
337 .close_device = mlx5_glue_devx_close_device,
338 .query_device = mlx5_glue_devx_query_device,
339 .query_hca_iseg = mlx5_glue_devx_query_hca_iseg_mapping,
340 .devx_obj_create = mlx5_glue_devx_obj_create,
341 .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
342 .devx_obj_query = mlx5_glue_devx_obj_query,
343 .devx_obj_modify = mlx5_glue_devx_obj_modify,
344 .devx_general_cmd = mlx5_glue_devx_general_cmd,
345 .devx_umem_reg = mlx5_glue_devx_umem_reg,
346 .devx_umem_dereg = mlx5_glue_devx_umem_dereg,
347 .devx_alloc_uar = mlx5_glue_devx_alloc_uar,
348 .devx_free_uar = mlx5_glue_devx_free_uar,
349 .devx_fs_rule_add = mlx5_glue_devx_fs_rule_add,
350 .devx_fs_rule_del = mlx5_glue_devx_fs_rule_del,
351 .devx_query_eqn = mlx5_glue_devx_query_eqn,
352 .query_rt_values = mlx5_glue_query_rt_values,
353 .devx_init_showdown_event = mlx5_glue_devx_init_showdown_event,