- * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
- */
-struct mlx5_rxq_obj *
-mlx5_rxq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
- enum mlx5_rxq_obj_type type)
-{
- struct mlx5_priv *priv = dev->data->dev_private;
- struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
- struct mlx5_rxq_ctrl *rxq_ctrl =
- container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
- struct ibv_wq_attr mod;
- unsigned int cqe_n;
- unsigned int wqe_n = 1 << rxq_data->elts_n;
- struct mlx5_rxq_obj *tmpl = NULL;
- struct mlx5dv_cq cq_info;
- struct mlx5dv_rwq rwq;
- int ret = 0;
- struct mlx5dv_obj obj;
-
- MLX5_ASSERT(rxq_data);
- MLX5_ASSERT(!rxq_ctrl->obj);
- if (type == MLX5_RXQ_OBJ_TYPE_DEVX_HAIRPIN)
- return mlx5_rxq_obj_hairpin_new(dev, idx);
- priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_RX_QUEUE;
- priv->verbs_alloc_ctx.obj = rxq_ctrl;
- tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl), 0,
- rxq_ctrl->socket);
- if (!tmpl) {
- DRV_LOG(ERR,
- "port %u Rx queue %u cannot allocate verbs resources",
- dev->data->port_id, rxq_data->idx);
- rte_errno = ENOMEM;
- goto error;
- }
- tmpl->type = type;
- tmpl->rxq_ctrl = rxq_ctrl;
- if (rxq_ctrl->irq) {
- tmpl->channel = mlx5_glue->create_comp_channel(priv->sh->ctx);
- if (!tmpl->channel) {
- DRV_LOG(ERR, "port %u: comp channel creation failure",
- dev->data->port_id);
- rte_errno = ENOMEM;
- goto error;
- }
- }
- if (mlx5_rxq_mprq_enabled(rxq_data))
- cqe_n = wqe_n * (1 << rxq_data->strd_num_n) - 1;
- else
- cqe_n = wqe_n - 1;
- tmpl->cq = mlx5_ibv_cq_new(dev, priv, rxq_data, cqe_n, tmpl);
- if (!tmpl->cq) {
- DRV_LOG(ERR, "port %u Rx queue %u CQ creation failure",
- dev->data->port_id, idx);
- rte_errno = ENOMEM;
- goto error;
- }
- obj.cq.in = tmpl->cq;
- obj.cq.out = &cq_info;
- ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_CQ);
- if (ret) {
- rte_errno = ret;
- goto error;
- }
- if (cq_info.cqe_size != RTE_CACHE_LINE_SIZE) {
- DRV_LOG(ERR,
- "port %u wrong MLX5_CQE_SIZE environment variable"
- " value: it should be set to %u",
- dev->data->port_id, RTE_CACHE_LINE_SIZE);
- rte_errno = EINVAL;
- goto error;
- }
- DRV_LOG(DEBUG, "port %u device_attr.max_qp_wr is %d",
- dev->data->port_id, priv->sh->device_attr.max_qp_wr);
- DRV_LOG(DEBUG, "port %u device_attr.max_sge is %d",
- dev->data->port_id, priv->sh->device_attr.max_sge);
- /* Allocate door-bell for types created with DevX. */
- if (tmpl->type != MLX5_RXQ_OBJ_TYPE_IBV) {
- struct mlx5_devx_dbr_page *dbr_page;
- int64_t dbr_offset;
-
- dbr_offset = mlx5_get_dbr(priv->sh->ctx, &priv->dbrpgs,
- &dbr_page);
- if (dbr_offset < 0)
- goto error;
- rxq_ctrl->dbr_offset = dbr_offset;
- rxq_ctrl->dbr_umem_id = mlx5_os_get_umem_id(dbr_page->umem);
- rxq_ctrl->dbr_umem_id_valid = 1;
- rxq_data->rq_db = (uint32_t *)((uintptr_t)dbr_page->dbrs +
- (uintptr_t)rxq_ctrl->dbr_offset);
- }
- if (tmpl->type == MLX5_RXQ_OBJ_TYPE_IBV) {
- tmpl->wq = mlx5_ibv_wq_new(dev, priv, rxq_data, idx, wqe_n,
- tmpl);
- if (!tmpl->wq) {
- DRV_LOG(ERR, "port %u Rx queue %u WQ creation failure",
- dev->data->port_id, idx);
- rte_errno = ENOMEM;
- goto error;
- }
- /* Change queue state to ready. */
- mod = (struct ibv_wq_attr){
- .attr_mask = IBV_WQ_ATTR_STATE,
- .wq_state = IBV_WQS_RDY,
- };
- ret = mlx5_glue->modify_wq(tmpl->wq, &mod);
- if (ret) {
- DRV_LOG(ERR,
- "port %u Rx queue %u WQ state to IBV_WQS_RDY"
- " failed", dev->data->port_id, idx);
- rte_errno = ret;
- goto error;
- }
- obj.rwq.in = tmpl->wq;
- obj.rwq.out = &rwq;
- ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_RWQ);
- if (ret) {
- rte_errno = ret;
- goto error;
- }
- rxq_data->wqes = rwq.buf;
- rxq_data->rq_db = rwq.dbrec;
- } else if (tmpl->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ) {
- struct mlx5_devx_modify_rq_attr rq_attr;
-
- memset(&rq_attr, 0, sizeof(rq_attr));
- tmpl->rq = mlx5_devx_rq_new(dev, idx, cq_info.cqn);
- if (!tmpl->rq) {
- DRV_LOG(ERR, "port %u Rx queue %u RQ creation failure",
- dev->data->port_id, idx);
- rte_errno = ENOMEM;
- goto error;
- }
- /* Change queue state to ready. */
- rq_attr.rq_state = MLX5_RQC_STATE_RST;
- rq_attr.state = MLX5_RQC_STATE_RDY;
- ret = mlx5_devx_cmd_modify_rq(tmpl->rq, &rq_attr);
- if (ret)
- goto error;
- }
- /* Fill the rings. */
- rxq_data->cqe_n = log2above(cq_info.cqe_cnt);
- rxq_data->cq_db = cq_info.dbrec;
- rxq_data->cqes = (volatile struct mlx5_cqe (*)[])(uintptr_t)cq_info.buf;
- rxq_data->cq_uar = cq_info.cq_uar;
- rxq_data->cqn = cq_info.cqn;
- rxq_data->cq_arm_sn = 0;
- mlx5_rxq_initialize(rxq_data);
- rxq_data->cq_ci = 0;
- DRV_LOG(DEBUG, "port %u rxq %u updated with %p", dev->data->port_id,
- idx, (void *)&tmpl);
- rte_atomic32_inc(&tmpl->refcnt);
- LIST_INSERT_HEAD(&priv->rxqsobj, tmpl, next);
- priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
- return tmpl;
-error:
- if (tmpl) {
- ret = rte_errno; /* Save rte_errno before cleanup. */
- if (tmpl->type == MLX5_RXQ_OBJ_TYPE_IBV && tmpl->wq)
- claim_zero(mlx5_glue->destroy_wq(tmpl->wq));
- else if (tmpl->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ && tmpl->rq)
- claim_zero(mlx5_devx_cmd_destroy(tmpl->rq));
- if (tmpl->cq)
- claim_zero(mlx5_glue->destroy_cq(tmpl->cq));
- if (tmpl->channel)
- claim_zero(mlx5_glue->destroy_comp_channel
- (tmpl->channel));
- mlx5_free(tmpl);
- rte_errno = ret; /* Restore rte_errno. */
- }
- if (type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ)
- rxq_release_rq_resources(rxq_ctrl);
- priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
- return NULL;
-}
-
-/**
- * Verify the Rx queue objects list is empty
- *
- * @param dev
- * Pointer to Ethernet device.
- *
- * @return
- * The number of objects not released.
- */
-int
-mlx5_rxq_obj_verify(struct rte_eth_dev *dev)
-{
- struct mlx5_priv *priv = dev->data->dev_private;
- int ret = 0;
- struct mlx5_rxq_obj *rxq_obj;
-
- LIST_FOREACH(rxq_obj, &priv->rxqsobj, next) {
- DRV_LOG(DEBUG, "port %u Rx queue %u still referenced",
- dev->data->port_id, rxq_obj->rxq_ctrl->rxq.idx);
- ++ret;
- }
- return ret;
-}
-
-/**
- * Callback function to initialize mbufs for Multi-Packet RQ.
- */
-static inline void
-mlx5_mprq_buf_init(struct rte_mempool *mp, void *opaque_arg,
- void *_m, unsigned int i __rte_unused)
-{
- struct mlx5_mprq_buf *buf = _m;
- struct rte_mbuf_ext_shared_info *shinfo;
- unsigned int strd_n = (unsigned int)(uintptr_t)opaque_arg;
- unsigned int j;
-
- memset(_m, 0, sizeof(*buf));
- buf->mp = mp;
- rte_atomic16_set(&buf->refcnt, 1);
- for (j = 0; j != strd_n; ++j) {
- shinfo = &buf->shinfos[j];
- shinfo->free_cb = mlx5_mprq_buf_free_cb;
- shinfo->fcb_opaque = buf;
- }
-}
-
-/**
- * Free mempool of Multi-Packet RQ.
- *
- * @param dev
- * Pointer to Ethernet device.
- *
- * @return
- * 0 on success, negative errno value on failure.
- */
-int
-mlx5_mprq_free_mp(struct rte_eth_dev *dev)
-{
- struct mlx5_priv *priv = dev->data->dev_private;
- struct rte_mempool *mp = priv->mprq_mp;
- unsigned int i;
-
- if (mp == NULL)
- return 0;
- DRV_LOG(DEBUG, "port %u freeing mempool (%s) for Multi-Packet RQ",
- dev->data->port_id, mp->name);
- /*
- * If a buffer in the pool has been externally attached to a mbuf and it
- * is still in use by application, destroying the Rx queue can spoil
- * the packet. It is unlikely to happen but if application dynamically
- * creates and destroys with holding Rx packets, this can happen.
- *
- * TODO: It is unavoidable for now because the mempool for Multi-Packet
- * RQ isn't provided by application but managed by PMD.
- */
- if (!rte_mempool_full(mp)) {
- DRV_LOG(ERR,
- "port %u mempool for Multi-Packet RQ is still in use",
- dev->data->port_id);
- rte_errno = EBUSY;
- return -rte_errno;
- }
- rte_mempool_free(mp);
- /* Unset mempool for each Rx queue. */
- for (i = 0; i != priv->rxqs_n; ++i) {
- struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
-
- if (rxq == NULL)
- continue;
- rxq->mprq_mp = NULL;
- }
- priv->mprq_mp = NULL;
- return 0;
-}
-
-/**
- * Allocate a mempool for Multi-Packet RQ. All configured Rx queues share the
- * mempool. If already allocated, reuse it if there're enough elements.
- * Otherwise, resize it.
- *
- * @param dev
- * Pointer to Ethernet device.
- *
- * @return
- * 0 on success, negative errno value on failure.