X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fcommon%2Fmlx5%2Fmlx5_devx_cmds.c;h=67c8a8c3a69dc5416437d9252067d79844b27339;hb=770fabcd36ec11d64544e86ed7d2dda9f5c64daf;hp=24255130a3f33574709d1b7c5c50fd199ed9eec2;hpb=8712c80afe548d4f9eef4976f88138b01f89bc3d;p=dpdk.git diff --git a/drivers/common/mlx5/mlx5_devx_cmds.c b/drivers/common/mlx5/mlx5_devx_cmds.c index 24255130a3..67c8a8c3a6 100644 --- a/drivers/common/mlx5/mlx5_devx_cmds.c +++ b/drivers/common/mlx5/mlx5_devx_cmds.c @@ -196,6 +196,10 @@ mlx5_devx_cmd_mkey_create(struct ibv_context *ctx, MLX5_SET(mkc, mkc, pd, attr->pd); MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF); MLX5_SET(mkc, mkc, translations_octword_size, translation_size); + if (attr->relaxed_ordering == 1) { + MLX5_SET(mkc, mkc, relaxed_ordering_write, 0x1); + MLX5_SET(mkc, mkc, relaxed_ordering_read, 0x1); + } MLX5_SET64(mkc, mkc, start_addr, attr->addr); MLX5_SET64(mkc, mkc, len, attr->size); mkey->obj = mlx5_glue->devx_obj_create(ctx, in, in_size_dw * 4, out, @@ -436,6 +440,8 @@ mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx, MLX5_GET(cmd_hca_cap, hcattr, flow_counter_bulk_alloc); attr->flow_counters_dump = MLX5_GET(cmd_hca_cap, hcattr, flow_counters_dump); + attr->log_max_rqt_size = MLX5_GET(cmd_hca_cap, hcattr, + log_max_rqt_size); attr->eswitch_manager = MLX5_GET(cmd_hca_cap, hcattr, eswitch_manager); attr->hairpin = MLX5_GET(cmd_hca_cap, hcattr, hairpin); attr->log_max_hairpin_queues = MLX5_GET(cmd_hca_cap, hcattr, @@ -753,9 +759,8 @@ mlx5_devx_cmd_create_tir(struct ibv_context *ctx, { uint32_t in[MLX5_ST_SZ_DW(create_tir_in)] = {0}; uint32_t out[MLX5_ST_SZ_DW(create_tir_out)] = {0}; - void *tir_ctx, *outer, *inner; + void *tir_ctx, *outer, *inner, *rss_key; struct mlx5_devx_obj *tir = NULL; - int i; tir = rte_calloc(__func__, 1, sizeof(*tir), 0); if (!tir) { @@ -778,10 +783,8 @@ mlx5_devx_cmd_create_tir(struct ibv_context *ctx, MLX5_SET(tirc, tir_ctx, rx_hash_fn, tir_attr->rx_hash_fn); MLX5_SET(tirc, tir_ctx, self_lb_block, tir_attr->self_lb_block); MLX5_SET(tirc, tir_ctx, transport_domain, tir_attr->transport_domain); - for (i = 0; i < 10; i++) { - MLX5_SET(tirc, tir_ctx, rx_hash_toeplitz_key[i], - tir_attr->rx_hash_toeplitz_key[i]); - } + rss_key = MLX5_ADDR_OF(tirc, tir_ctx, rx_hash_toeplitz_key); + memcpy(rss_key, tir_attr->rx_hash_toeplitz_key, MLX5_RSS_HASH_KEY_LEN); outer = MLX5_ADDR_OF(tirc, tir_ctx, rx_hash_field_selector_outer); MLX5_SET(rx_hash_field_select, outer, l3_prot_type, tir_attr->rx_hash_field_selector_outer.l3_prot_type); @@ -846,6 +849,7 @@ mlx5_devx_cmd_create_rqt(struct ibv_context *ctx, } MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT); rqt_ctx = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); + MLX5_SET(rqtc, rqt_ctx, list_q_type, rqt_attr->rq_type); MLX5_SET(rqtc, rqt_ctx, rqt_max_size, rqt_attr->rqt_max_size); MLX5_SET(rqtc, rqt_ctx, rqt_actual_size, rqt_attr->rqt_actual_size); for (i = 0; i < rqt_attr->rqt_actual_size; i++) @@ -862,6 +866,53 @@ mlx5_devx_cmd_create_rqt(struct ibv_context *ctx, return rqt; } +/** + * Modify RQT using DevX API. + * + * @param[in] rqt + * Pointer to RQT DevX object structure. + * @param [in] rqt_attr + * Pointer to RQT attributes structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_devx_cmd_modify_rqt(struct mlx5_devx_obj *rqt, + struct mlx5_devx_rqt_attr *rqt_attr) +{ + uint32_t inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + + rqt_attr->rqt_actual_size * sizeof(uint32_t); + uint32_t out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0}; + uint32_t *in = rte_calloc(__func__, 1, inlen, 0); + void *rqt_ctx; + int i; + int ret; + + if (!in) { + DRV_LOG(ERR, "Failed to allocate RQT modify IN data."); + rte_errno = ENOMEM; + return -ENOMEM; + } + MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT); + MLX5_SET(modify_rqt_in, in, rqtn, rqt->id); + MLX5_SET64(modify_rqt_in, in, modify_bitmask, 0x1); + rqt_ctx = MLX5_ADDR_OF(modify_rqt_in, in, rqt_context); + MLX5_SET(rqtc, rqt_ctx, list_q_type, rqt_attr->rq_type); + MLX5_SET(rqtc, rqt_ctx, rqt_max_size, rqt_attr->rqt_max_size); + MLX5_SET(rqtc, rqt_ctx, rqt_actual_size, rqt_attr->rqt_actual_size); + for (i = 0; i < rqt_attr->rqt_actual_size; i++) + MLX5_SET(rqtc, rqt_ctx, rq_num[i], rqt_attr->rq_list[i]); + ret = mlx5_glue->devx_obj_modify(rqt->obj, in, inlen, out, sizeof(out)); + rte_free(in); + if (ret) { + DRV_LOG(ERR, "Failed to modify RQT using DevX."); + rte_errno = errno; + return -rte_errno; + } + return ret; +} + /** * Create SQ using DevX API. * @@ -1076,11 +1127,11 @@ mlx5_devx_cmd_flow_dump(void *fdb_domain __rte_unused, if (ret) return ret; } - assert(rx_domain); + MLX5_ASSERT(rx_domain); ret = mlx5_glue->dr_dump_domain(file, rx_domain); if (ret) return ret; - assert(tx_domain); + MLX5_ASSERT(tx_domain); ret = mlx5_glue->dr_dump_domain(file, tx_domain); #else ret = ENOTSUP; @@ -1124,7 +1175,8 @@ mlx5_devx_cmd_create_cq(struct ibv_context *ctx, struct mlx5_devx_cq_attr *attr) MLX5_SET(cqc, cqctx, cc, attr->use_first_only); MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore); MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size); - MLX5_SET(cqc, cqctx, log_page_size, attr->log_page_size); + MLX5_SET(cqc, cqctx, log_page_size, attr->log_page_size - + MLX5_ADAPTER_PAGE_SHIFT); MLX5_SET(cqc, cqctx, c_eqn, attr->eqn); MLX5_SET(cqc, cqctx, uar_page, attr->uar_page_id); if (attr->q_umem_valid) { @@ -1313,3 +1365,167 @@ mlx5_devx_cmd_query_virtq(struct mlx5_devx_obj *virtq_obj, attr->hw_used_index = MLX5_GET16(virtio_net_q, virtq, hw_used_index); return ret; } + +/** + * Create QP using DevX API. + * + * @param[in] ctx + * ibv_context returned from mlx5dv_open_device. + * @param [in] attr + * Pointer to QP attributes structure. + * + * @return + * The DevX object created, NULL otherwise and rte_errno is set. + */ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_qp(struct ibv_context *ctx, + struct mlx5_devx_qp_attr *attr) +{ + uint32_t in[MLX5_ST_SZ_DW(create_qp_in)] = {0}; + uint32_t out[MLX5_ST_SZ_DW(create_qp_out)] = {0}; + struct mlx5_devx_obj *qp_obj = rte_zmalloc(__func__, sizeof(*qp_obj), + 0); + void *qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); + + if (!qp_obj) { + DRV_LOG(ERR, "Failed to allocate QP data."); + rte_errno = ENOMEM; + return NULL; + } + MLX5_SET(create_qp_in, in, opcode, MLX5_CMD_OP_CREATE_QP); + MLX5_SET(qpc, qpc, st, MLX5_QP_ST_RC); + MLX5_SET(qpc, qpc, pd, attr->pd); + if (attr->uar_index) { + MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); + MLX5_SET(qpc, qpc, uar_page, attr->uar_index); + MLX5_SET(qpc, qpc, log_page_size, attr->log_page_size - + MLX5_ADAPTER_PAGE_SHIFT); + if (attr->sq_size) { + MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->sq_size)); + MLX5_SET(qpc, qpc, cqn_snd, attr->cqn); + MLX5_SET(qpc, qpc, log_sq_size, + rte_log2_u32(attr->sq_size)); + } else { + MLX5_SET(qpc, qpc, no_sq, 1); + } + if (attr->rq_size) { + MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->rq_size)); + MLX5_SET(qpc, qpc, cqn_rcv, attr->cqn); + MLX5_SET(qpc, qpc, log_rq_stride, attr->log_rq_stride - + MLX5_LOG_RQ_STRIDE_SHIFT); + MLX5_SET(qpc, qpc, log_rq_size, + rte_log2_u32(attr->rq_size)); + MLX5_SET(qpc, qpc, rq_type, MLX5_NON_ZERO_RQ); + } else { + MLX5_SET(qpc, qpc, rq_type, MLX5_ZERO_LEN_RQ); + } + if (attr->dbr_umem_valid) { + MLX5_SET(qpc, qpc, dbr_umem_valid, + attr->dbr_umem_valid); + MLX5_SET(qpc, qpc, dbr_umem_id, attr->dbr_umem_id); + } + MLX5_SET64(qpc, qpc, dbr_addr, attr->dbr_address); + MLX5_SET64(create_qp_in, in, wq_umem_offset, + attr->wq_umem_offset); + MLX5_SET(create_qp_in, in, wq_umem_id, attr->wq_umem_id); + MLX5_SET(create_qp_in, in, wq_umem_valid, 1); + } else { + /* Special QP to be managed by FW - no SQ\RQ\CQ\UAR\DB rec. */ + MLX5_SET(qpc, qpc, rq_type, MLX5_ZERO_LEN_RQ); + MLX5_SET(qpc, qpc, no_sq, 1); + } + qp_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out, + sizeof(out)); + if (!qp_obj->obj) { + rte_errno = errno; + DRV_LOG(ERR, "Failed to create QP Obj using DevX."); + rte_free(qp_obj); + return NULL; + } + qp_obj->id = MLX5_GET(create_qp_out, out, qpn); + return qp_obj; +} + +/** + * Modify QP using DevX API. + * Currently supports only force loop-back QP. + * + * @param[in] qp + * Pointer to QP object structure. + * @param [in] qp_st_mod_op + * The QP state modification operation. + * @param [in] remote_qp_id + * The remote QP ID for MLX5_CMD_OP_INIT2RTR_QP operation. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_devx_cmd_modify_qp_state(struct mlx5_devx_obj *qp, uint32_t qp_st_mod_op, + uint32_t remote_qp_id) +{ + union { + uint32_t rst2init[MLX5_ST_SZ_DW(rst2init_qp_in)]; + uint32_t init2rtr[MLX5_ST_SZ_DW(init2rtr_qp_in)]; + uint32_t rtr2rts[MLX5_ST_SZ_DW(rtr2rts_qp_in)]; + } in; + union { + uint32_t rst2init[MLX5_ST_SZ_DW(rst2init_qp_out)]; + uint32_t init2rtr[MLX5_ST_SZ_DW(init2rtr_qp_out)]; + uint32_t rtr2rts[MLX5_ST_SZ_DW(rtr2rts_qp_out)]; + } out; + void *qpc; + int ret; + unsigned int inlen; + unsigned int outlen; + + memset(&in, 0, sizeof(in)); + memset(&out, 0, sizeof(out)); + MLX5_SET(rst2init_qp_in, &in, opcode, qp_st_mod_op); + switch (qp_st_mod_op) { + case MLX5_CMD_OP_RST2INIT_QP: + MLX5_SET(rst2init_qp_in, &in, qpn, qp->id); + qpc = MLX5_ADDR_OF(rst2init_qp_in, &in, qpc); + MLX5_SET(qpc, qpc, primary_address_path.vhca_port_num, 1); + MLX5_SET(qpc, qpc, rre, 1); + MLX5_SET(qpc, qpc, rwe, 1); + MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); + inlen = sizeof(in.rst2init); + outlen = sizeof(out.rst2init); + break; + case MLX5_CMD_OP_INIT2RTR_QP: + MLX5_SET(init2rtr_qp_in, &in, qpn, qp->id); + qpc = MLX5_ADDR_OF(init2rtr_qp_in, &in, qpc); + MLX5_SET(qpc, qpc, primary_address_path.fl, 1); + MLX5_SET(qpc, qpc, primary_address_path.vhca_port_num, 1); + MLX5_SET(qpc, qpc, mtu, 1); + MLX5_SET(qpc, qpc, log_msg_max, 30); + MLX5_SET(qpc, qpc, remote_qpn, remote_qp_id); + MLX5_SET(qpc, qpc, min_rnr_nak, 0); + inlen = sizeof(in.init2rtr); + outlen = sizeof(out.init2rtr); + break; + case MLX5_CMD_OP_RTR2RTS_QP: + qpc = MLX5_ADDR_OF(rtr2rts_qp_in, &in, qpc); + MLX5_SET(rtr2rts_qp_in, &in, qpn, qp->id); + MLX5_SET(qpc, qpc, primary_address_path.ack_timeout, 14); + MLX5_SET(qpc, qpc, log_ack_req_freq, 0); + MLX5_SET(qpc, qpc, retry_count, 7); + MLX5_SET(qpc, qpc, rnr_retry, 7); + inlen = sizeof(in.rtr2rts); + outlen = sizeof(out.rtr2rts); + break; + default: + DRV_LOG(ERR, "Invalid or unsupported QP modify op %u.", + qp_st_mod_op); + rte_errno = EINVAL; + return -rte_errno; + } + ret = mlx5_glue->devx_obj_modify(qp->obj, &in, inlen, &out, outlen); + if (ret) { + DRV_LOG(ERR, "Failed to modify QP using DevX."); + rte_errno = errno; + return -errno; + } + return ret; +}