1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 Mellanox Technologies, Ltd
5 #ifndef RTE_PMD_MLX5_VDPA_H_
6 #define RTE_PMD_MLX5_VDPA_H_
11 #pragma GCC diagnostic ignored "-Wpedantic"
14 #include <rte_vhost.h>
16 #pragma GCC diagnostic error "-Wpedantic"
18 #include <rte_spinlock.h>
19 #include <rte_interrupts.h>
21 #include <mlx5_glue.h>
22 #include <mlx5_devx_cmds.h>
26 #define MLX5_VDPA_INTR_RETRIES 256
27 #define MLX5_VDPA_INTR_RETRIES_USEC 1000
34 struct mlx5_devx_obj *cq;
35 struct mlx5dv_devx_umem *umem_obj;
37 volatile void *umem_buf;
38 volatile struct mlx5_cqe *cqes;
40 volatile uint32_t *db_rec;
44 struct mlx5_vdpa_event_qp {
45 struct mlx5_vdpa_cq cq;
46 struct mlx5_devx_obj *fw_qp;
47 struct mlx5_devx_obj *sw_qp;
48 struct mlx5dv_devx_umem *umem_obj;
50 volatile uint32_t *db_rec;
53 struct mlx5_vdpa_query_mr {
54 SLIST_ENTRY(mlx5_vdpa_query_mr) next;
57 struct mlx5dv_devx_umem *umem;
58 struct mlx5_devx_obj *mkey;
62 struct mlx5_vdpa_priv {
63 TAILQ_ENTRY(mlx5_vdpa_priv) next;
64 int id; /* vDPA device id. */
65 int vid; /* vhost device id. */
66 struct ibv_context *ctx; /* Device context. */
67 struct rte_vdpa_dev_addr dev_addr;
68 struct mlx5_hca_vdpa_attr caps;
69 uint32_t pdn; /* Protection Domain number. */
71 uint32_t gpa_mkey_index;
72 struct ibv_mr *null_mr;
73 struct rte_vhost_memory *vmem;
75 struct mlx5dv_devx_event_channel *eventc;
76 struct mlx5dv_devx_uar *uar;
77 struct rte_intr_handle intr_handle;
78 SLIST_HEAD(mr_list, mlx5_vdpa_query_mr) mr_list;
82 * Release all the prepared memory regions and all their related resources.
85 * The vdpa driver private structure.
87 void mlx5_vdpa_mem_dereg(struct mlx5_vdpa_priv *priv);
90 * Register all the memory regions of the virtio device to the HW and allocate
91 * all their related resources.
94 * The vdpa driver private structure.
97 * 0 on success, a negative errno value otherwise and rte_errno is set.
99 int mlx5_vdpa_mem_register(struct mlx5_vdpa_priv *priv);
103 * Create an event QP and all its related resources.
106 * The vdpa driver private structure.
108 * Number of descriptors.
110 * The guest notification file descriptor.
112 * Pointer to the event QP structure.
115 * 0 on success, -1 otherwise and rte_errno is set.
117 int mlx5_vdpa_event_qp_create(struct mlx5_vdpa_priv *priv, uint16_t desc_n,
118 int callfd, struct mlx5_vdpa_event_qp *eqp);
121 * Destroy an event QP and all its related resources.
124 * Pointer to the event QP structure.
126 void mlx5_vdpa_event_qp_destroy(struct mlx5_vdpa_event_qp *eqp);
129 * Release all the event global resources.
132 * The vdpa driver private structure.
134 void mlx5_vdpa_event_qp_global_release(struct mlx5_vdpa_priv *priv);
140 * The vdpa driver private structure.
143 * 0 on success, a negative errno value otherwise and rte_errno is set.
145 int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv);
151 * The vdpa driver private structure.
153 void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv);
155 #endif /* RTE_PMD_MLX5_VDPA_H_ */