From: Michael Baum Date: Wed, 6 Jan 2021 08:19:39 +0000 (+0000) Subject: common/mlx5: share DevX RQ creation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=edb704da80ff6dbe9a309a574c42d1fa1026b276;p=dpdk.git common/mlx5: share DevX RQ creation The RQ object in DevX is used currently only in net driver, but it is shared for future. Add a structure that contains all the resources, and provide creation and release functions for it. Signed-off-by: Michael Baum Acked-by: Matan Azrad --- diff --git a/drivers/common/mlx5/mlx5_common_devx.c b/drivers/common/mlx5/mlx5_common_devx.c index 58b75c318e..d19be122bd 100644 --- a/drivers/common/mlx5/mlx5_common_devx.c +++ b/drivers/common/mlx5/mlx5_common_devx.c @@ -271,4 +271,117 @@ error: return -rte_errno; } +/** + * Destroy DevX Receive Queue. + * + * @param[in] rq + * DevX RQ to destroy. + */ +void +mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq) +{ + if (rq->rq) + claim_zero(mlx5_devx_cmd_destroy(rq->rq)); + if (rq->umem_obj) + claim_zero(mlx5_os_umem_dereg(rq->umem_obj)); + if (rq->umem_buf) + mlx5_free((void *)(uintptr_t)rq->umem_buf); +} + +/** + * Create Receive Queue using DevX API. + * + * Get a pointer to partially initialized attributes structure, and updates the + * following fields: + * wq_umem_valid + * wq_umem_id + * wq_umem_offset + * dbr_umem_valid + * dbr_umem_id + * dbr_addr + * log_wq_pg_sz + * All other fields are updated by caller. + * + * @param[in] ctx + * Context returned from mlx5 open_device() glue function. + * @param[in/out] rq_obj + * Pointer to RQ to create. + * @param[in] wqe_size + * Size of WQE structure. + * @param[in] log_wqbb_n + * Log of number of WQBBs in queue. + * @param[in] attr + * Pointer to RQ attributes structure. + * @param[in] socket + * Socket to use for allocation. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj, uint32_t wqe_size, + uint16_t log_wqbb_n, + struct mlx5_devx_create_rq_attr *attr, int socket) +{ + struct mlx5_devx_obj *rq = NULL; + struct mlx5dv_devx_umem *umem_obj = NULL; + void *umem_buf = NULL; + size_t alignment = MLX5_WQE_BUF_ALIGNMENT; + uint32_t umem_size, umem_dbrec; + uint16_t rq_size = 1 << log_wqbb_n; + int ret; + + if (alignment == (size_t)-1) { + DRV_LOG(ERR, "Failed to get WQE buf alignment."); + rte_errno = ENOMEM; + return -rte_errno; + } + /* Allocate memory buffer for WQEs and doorbell record. */ + umem_size = wqe_size * rq_size; + umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE); + umem_size += MLX5_DBR_SIZE; + umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size, + alignment, socket); + if (!umem_buf) { + DRV_LOG(ERR, "Failed to allocate memory for RQ."); + rte_errno = ENOMEM; + return -rte_errno; + } + /* Register allocated buffer in user space with DevX. */ + umem_obj = mlx5_os_umem_reg(ctx, (void *)(uintptr_t)umem_buf, + umem_size, 0); + if (!umem_obj) { + DRV_LOG(ERR, "Failed to register umem for RQ."); + rte_errno = errno; + goto error; + } + /* Fill attributes for RQ object creation. */ + attr->wq_attr.wq_umem_valid = 1; + attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj); + attr->wq_attr.wq_umem_offset = 0; + attr->wq_attr.dbr_umem_valid = 1; + attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id; + attr->wq_attr.dbr_addr = umem_dbrec; + attr->wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE; + /* Create receive queue object with DevX. */ + rq = mlx5_devx_cmd_create_rq(ctx, attr, socket); + if (!rq) { + DRV_LOG(ERR, "Can't create DevX RQ object."); + rte_errno = ENOMEM; + goto error; + } + rq_obj->umem_buf = umem_buf; + rq_obj->umem_obj = umem_obj; + rq_obj->rq = rq; + rq_obj->db_rec = RTE_PTR_ADD(rq_obj->umem_buf, umem_dbrec); + return 0; +error: + ret = rte_errno; + if (umem_obj) + claim_zero(mlx5_os_umem_dereg(umem_obj)); + if (umem_buf) + mlx5_free((void *)(uintptr_t)umem_buf); + rte_errno = ret; + return -rte_errno; +} diff --git a/drivers/common/mlx5/mlx5_common_devx.h b/drivers/common/mlx5/mlx5_common_devx.h index 992ad8f8f2..aad0184e5a 100644 --- a/drivers/common/mlx5/mlx5_common_devx.h +++ b/drivers/common/mlx5/mlx5_common_devx.h @@ -33,6 +33,13 @@ struct mlx5_devx_sq { volatile uint32_t *db_rec; /* The SQ doorbell record. */ }; +/* DevX Receive Queue structure. */ +struct mlx5_devx_rq { + struct mlx5_devx_obj *rq; /* The RQ DevX object. */ + void *umem_obj; /* The RQ umem object. */ + volatile void *umem_buf; + volatile uint32_t *db_rec; /* The RQ doorbell record. */ +}; /* mlx5_common_devx.c */ @@ -52,4 +59,12 @@ int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n, struct mlx5_devx_create_sq_attr *attr, int socket); +__rte_internal +void mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq); + +__rte_internal +int mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj, + uint32_t wqe_size, uint16_t log_wqbb_n, + struct mlx5_devx_create_rq_attr *attr, int socket); + #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */ diff --git a/drivers/common/mlx5/rte_common_mlx5_exports.def b/drivers/common/mlx5/rte_common_mlx5_exports.def index 68073c9097..19bd4c55ad 100644 --- a/drivers/common/mlx5/rte_common_mlx5_exports.def +++ b/drivers/common/mlx5/rte_common_mlx5_exports.def @@ -37,6 +37,8 @@ EXPORTS mlx5_devx_cq_create mlx5_devx_cq_destroy + mlx5_devx_rq_create + mlx5_devx_rq_destroy mlx5_devx_sq_create mlx5_devx_sq_destroy diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index ea628ebff0..9676e10cfb 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -45,6 +45,8 @@ INTERNAL { mlx5_devx_cq_create; mlx5_devx_cq_destroy; + mlx5_devx_rq_create; + mlx5_devx_rq_destroy; mlx5_devx_sq_create; mlx5_devx_sq_destroy;