devtools: forbid variable declaration inside for
[dpdk.git] / drivers / common / mlx5 / mlx5_devx_cmds.c
index e7288c8..2179a83 100644 (file)
@@ -15,7 +15,7 @@
  * Allocate flow counters via devx interface.
  *
  * @param[in] ctx
- *   ibv contexts returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param dcs
  *   Pointer to counters properties structure to be filled by the routine.
  * @param bulk_n_128
@@ -26,7 +26,7 @@
  *   rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_flow_counter_alloc(struct ibv_context *ctx, uint32_t bulk_n_128)
+mlx5_devx_cmd_flow_counter_alloc(void *ctx, uint32_t bulk_n_128)
 {
        struct mlx5_devx_obj *dcs = rte_zmalloc("dcs", sizeof(*dcs), 0);
        uint32_t in[MLX5_ST_SZ_DW(alloc_flow_counter_in)]   = {0};
@@ -81,7 +81,7 @@ mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
                                 int clear, uint32_t n_counters,
                                 uint64_t *pkts, uint64_t *bytes,
                                 uint32_t mkey, void *addr,
-                                struct mlx5dv_devx_cmd_comp *cmd_comp,
+                                void *cmd_comp,
                                 uint64_t async_id)
 {
        int out_len = MLX5_ST_SZ_BYTES(query_flow_counter_out) +
@@ -130,7 +130,7 @@ mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
  * Create a new mkey.
  *
  * @param[in] ctx
- *   ibv contexts returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param[in] attr
  *   Attributes of the requested mkey.
  *
@@ -139,7 +139,7 @@ mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
  *   is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_mkey_create(struct ibv_context *ctx,
+mlx5_devx_cmd_mkey_create(void *ctx,
                          struct mlx5_devx_mkey_attr *attr)
 {
        struct mlx5_klm *klm_array = attr->klm_array;
@@ -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,
@@ -275,7 +279,7 @@ mlx5_devx_cmd_destroy(struct mlx5_devx_obj *obj)
  *   0 on success, a negative value otherwise.
  */
 static int
-mlx5_devx_cmd_query_nic_vport_context(struct ibv_context *ctx,
+mlx5_devx_cmd_query_nic_vport_context(void *ctx,
                                      unsigned int vport,
                                      struct mlx5_hca_attr *attr)
 {
@@ -317,12 +321,12 @@ error:
  * Query NIC vDPA attributes.
  *
  * @param[in] ctx
- *   ibv contexts returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param[out] vdpa_attr
  *   vDPA Attributes structure to fill.
  */
 static void
-mlx5_devx_cmd_query_hca_vdpa_attr(struct ibv_context *ctx,
+mlx5_devx_cmd_query_hca_vdpa_attr(void *ctx,
                                  struct mlx5_hca_vdpa_attr *vdpa_attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {0};
@@ -398,7 +402,7 @@ mlx5_devx_cmd_query_hca_vdpa_attr(struct ibv_context *ctx,
  * is having the required capabilities.
  *
  * @param[in] ctx
- *   ibv contexts returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param[out] attr
  *   Attributes device values.
  *
@@ -406,13 +410,13 @@ mlx5_devx_cmd_query_hca_vdpa_attr(struct ibv_context *ctx,
  *   0 on success, a negative value otherwise.
  */
 int
-mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
+mlx5_devx_cmd_query_hca_attr(void *ctx,
                             struct mlx5_hca_attr *attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {0};
        uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)] = {0};
        void *hcattr;
-       int status, syndrome, rc;
+       int status, syndrome, rc, i;
 
        MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
        MLX5_SET(query_hca_cap_in, in, op_mod,
@@ -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,
@@ -445,6 +451,10 @@ mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
        attr->log_max_hairpin_num_packets = MLX5_GET
                (cmd_hca_cap, hcattr, log_min_hairpin_wq_data_sz);
        attr->vhca_id = MLX5_GET(cmd_hca_cap, hcattr, vhca_id);
+       attr->relaxed_ordering_write = MLX5_GET(cmd_hca_cap, hcattr,
+                       relaxed_ordering_write);
+       attr->relaxed_ordering_read = MLX5_GET(cmd_hca_cap, hcattr,
+                       relaxed_ordering_read);
        attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
                                          eth_net_offloads);
        attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
@@ -454,6 +464,9 @@ mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
        attr->vdpa.valid = !!(MLX5_GET64(cmd_hca_cap, hcattr,
                                         general_obj_types) &
                              MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q);
+       attr->vdpa.queue_counters_valid = !!(MLX5_GET64(cmd_hca_cap, hcattr,
+                                                       general_obj_types) &
+                                 MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_Q_COUNTERS);
        if (attr->qos.sup) {
                MLX5_SET(query_hca_cap_in, in, op_mod,
                         MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
@@ -519,7 +532,7 @@ mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
        attr->lro_max_msg_sz_mode = MLX5_GET
                                        (per_protocol_networking_offload_caps,
                                         hcattr, lro_max_msg_sz_mode);
-       for (int i = 0 ; i < MLX5_LRO_NUM_SUPP_PERIODS ; i++) {
+       for (i = 0 ; i < MLX5_LRO_NUM_SUPP_PERIODS ; i++) {
                attr->lro_timer_supported_periods[i] =
                        MLX5_GET(per_protocol_networking_offload_caps, hcattr,
                                 lro_timer_supported_periods[i]);
@@ -564,9 +577,10 @@ error:
  *   0 on success, a negative value otherwise.
  */
 int
-mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
+mlx5_devx_cmd_qp_query_tis_td(void *qp, uint32_t tis_num,
                              uint32_t *tis_td)
 {
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
        uint32_t in[MLX5_ST_SZ_DW(query_tis_in)] = {0};
        uint32_t out[MLX5_ST_SZ_DW(query_tis_out)] = {0};
        int rc;
@@ -582,6 +596,12 @@ mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
        tis_ctx = MLX5_ADDR_OF(query_tis_out, out, tis_context);
        *tis_td = MLX5_GET(tisc, tis_ctx, transport_domain);
        return 0;
+#else
+       (void)qp;
+       (void)tis_num;
+       (void)tis_td;
+       return -ENOTSUP;
+#endif
 }
 
 /**
@@ -631,7 +651,7 @@ devx_cmd_fill_wq_data(void *wq_ctx, struct mlx5_devx_wq_attr *wq_attr)
  * Create RQ using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] rq_attr
  *   Pointer to create RQ attributes structure.
  * @param [in] socket
@@ -641,7 +661,7 @@ devx_cmd_fill_wq_data(void *wq_ctx, struct mlx5_devx_wq_attr *wq_attr)
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_rq(struct ibv_context *ctx,
+mlx5_devx_cmd_create_rq(void *ctx,
                        struct mlx5_devx_create_rq_attr *rq_attr,
                        int socket)
 {
@@ -740,7 +760,7 @@ mlx5_devx_cmd_modify_rq(struct mlx5_devx_obj *rq,
  * Create TIR using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *  Context returned from mlx5 open_device() glue function.
  * @param [in] tir_attr
  *   Pointer to TIR attributes structure.
  *
@@ -748,14 +768,13 @@ mlx5_devx_cmd_modify_rq(struct mlx5_devx_obj *rq,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_tir(struct ibv_context *ctx,
+mlx5_devx_cmd_create_tir(void *ctx,
                         struct mlx5_devx_tir_attr *tir_attr)
 {
        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 +797,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);
@@ -812,7 +829,7 @@ mlx5_devx_cmd_create_tir(struct ibv_context *ctx,
  * Create RQT using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] rqt_attr
  *   Pointer to RQT attributes structure.
  *
@@ -820,7 +837,7 @@ mlx5_devx_cmd_create_tir(struct ibv_context *ctx,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_rqt(struct ibv_context *ctx,
+mlx5_devx_cmd_create_rqt(void *ctx,
                         struct mlx5_devx_rqt_attr *rqt_attr)
 {
        uint32_t *in = NULL;
@@ -846,6 +863,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,11 +880,58 @@ 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.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] sq_attr
  *   Pointer to SQ attributes structure.
  * @param [in] socket
@@ -876,7 +941,7 @@ mlx5_devx_cmd_create_rqt(struct ibv_context *ctx,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  **/
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_sq(struct ibv_context *ctx,
+mlx5_devx_cmd_create_sq(void *ctx,
                        struct mlx5_devx_create_sq_attr *sq_attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(create_sq_in)] = {0};
@@ -968,7 +1033,7 @@ mlx5_devx_cmd_modify_sq(struct mlx5_devx_obj *sq,
  * Create TIS using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] tis_attr
  *   Pointer to TIS attributes structure.
  *
@@ -976,7 +1041,7 @@ mlx5_devx_cmd_modify_sq(struct mlx5_devx_obj *sq,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_tis(struct ibv_context *ctx,
+mlx5_devx_cmd_create_tis(void *ctx,
                         struct mlx5_devx_tis_attr *tis_attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(create_tis_in)] = {0};
@@ -1015,13 +1080,12 @@ mlx5_devx_cmd_create_tis(struct ibv_context *ctx,
  * Create transport domain using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
- *
+ *   Context returned from mlx5 open_device() glue function.
  * @return
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_td(struct ibv_context *ctx)
+mlx5_devx_cmd_create_td(void *ctx)
 {
        uint32_t in[MLX5_ST_SZ_DW(alloc_transport_domain_in)] = {0};
        uint32_t out[MLX5_ST_SZ_DW(alloc_transport_domain_out)] = {0};
@@ -1076,11 +1140,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;
@@ -1092,7 +1156,7 @@ mlx5_devx_cmd_flow_dump(void *fdb_domain __rte_unused,
  * Create CQ using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] attr
  *   Pointer to CQ attributes structure.
  *
@@ -1100,7 +1164,7 @@ mlx5_devx_cmd_flow_dump(void *fdb_domain __rte_unused,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_cq(struct ibv_context *ctx, struct mlx5_devx_cq_attr *attr)
+mlx5_devx_cmd_create_cq(void *ctx, struct mlx5_devx_cq_attr *attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(create_cq_in)] = {0};
        uint32_t out[MLX5_ST_SZ_DW(create_cq_out)] = {0};
@@ -1150,7 +1214,7 @@ mlx5_devx_cmd_create_cq(struct ibv_context *ctx, struct mlx5_devx_cq_attr *attr)
  * Create VIRTQ using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] attr
  *   Pointer to VIRTQ attributes structure.
  *
@@ -1158,7 +1222,7 @@ mlx5_devx_cmd_create_cq(struct ibv_context *ctx, struct mlx5_devx_cq_attr *attr)
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_virtq(struct ibv_context *ctx,
+mlx5_devx_cmd_create_virtq(void *ctx,
                           struct mlx5_devx_virtq_attr *attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(create_virtq_in)] = {0};
@@ -1204,6 +1268,8 @@ mlx5_devx_cmd_create_virtq(struct ibv_context *ctx,
        MLX5_SET(virtio_q, virtctx, umem_3_id, attr->umems[2].id);
        MLX5_SET(virtio_q, virtctx, umem_3_size, attr->umems[2].size);
        MLX5_SET64(virtio_q, virtctx, umem_3_offset, attr->umems[2].offset);
+       MLX5_SET(virtio_q, virtctx, counter_set_id, attr->counters_obj_id);
+       MLX5_SET(virtio_q, virtctx, pd, attr->pd);
        MLX5_SET(virtio_net_q, virtq, tisn_or_qpn, attr->tis_id);
        virtq_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
                                                    sizeof(out));
@@ -1319,7 +1385,7 @@ mlx5_devx_cmd_query_virtq(struct mlx5_devx_obj *virtq_obj,
  * Create QP using DevX API.
  *
  * @param[in] ctx
- *   ibv_context returned from mlx5dv_open_device.
+ *   Context returned from mlx5 open_device() glue function.
  * @param [in] attr
  *   Pointer to QP attributes structure.
  *
@@ -1327,7 +1393,7 @@ mlx5_devx_cmd_query_virtq(struct mlx5_devx_obj *virtq_obj,
  *   The DevX object created, NULL otherwise and rte_errno is set.
  */
 struct mlx5_devx_obj *
-mlx5_devx_cmd_create_qp(struct ibv_context *ctx,
+mlx5_devx_cmd_create_qp(void *ctx,
                        struct mlx5_devx_qp_attr *attr)
 {
        uint32_t in[MLX5_ST_SZ_DW(create_qp_in)] = {0};
@@ -1350,7 +1416,7 @@ mlx5_devx_cmd_create_qp(struct ibv_context *ctx,
                MLX5_SET(qpc, qpc, log_page_size, attr->log_page_size -
                         MLX5_ADAPTER_PAGE_SHIFT);
                if (attr->sq_size) {
-                       RTE_ASSERT(RTE_IS_POWER_OF_2(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));
@@ -1358,7 +1424,7 @@ mlx5_devx_cmd_create_qp(struct ibv_context *ctx,
                        MLX5_SET(qpc, qpc, no_sq, 1);
                }
                if (attr->rq_size) {
-                       RTE_ASSERT(RTE_IS_POWER_OF_2(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);
@@ -1478,3 +1544,72 @@ mlx5_devx_cmd_modify_qp_state(struct mlx5_devx_obj *qp, uint32_t qp_st_mod_op,
        }
        return ret;
 }
+
+struct mlx5_devx_obj *
+mlx5_devx_cmd_create_virtio_q_counters(void *ctx)
+{
+       uint32_t in[MLX5_ST_SZ_DW(create_virtio_q_counters_in)] = {0};
+       uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
+       struct mlx5_devx_obj *couners_obj = rte_zmalloc(__func__,
+                                                      sizeof(*couners_obj), 0);
+       void *hdr = MLX5_ADDR_OF(create_virtio_q_counters_in, in, hdr);
+
+       if (!couners_obj) {
+               DRV_LOG(ERR, "Failed to allocate virtio queue counters data.");
+               rte_errno = ENOMEM;
+               return NULL;
+       }
+       MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
+                MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
+       MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
+                MLX5_GENERAL_OBJ_TYPE_VIRTIO_Q_COUNTERS);
+       couners_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
+                                                     sizeof(out));
+       if (!couners_obj->obj) {
+               rte_errno = errno;
+               DRV_LOG(ERR, "Failed to create virtio queue counters Obj using"
+                       " DevX.");
+               rte_free(couners_obj);
+               return NULL;
+       }
+       couners_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
+       return couners_obj;
+}
+
+int
+mlx5_devx_cmd_query_virtio_q_counters(struct mlx5_devx_obj *couners_obj,
+                                  struct mlx5_devx_virtio_q_couners_attr *attr)
+{
+       uint32_t in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0};
+       uint32_t out[MLX5_ST_SZ_DW(query_virtio_q_counters_out)] = {0};
+       void *hdr = MLX5_ADDR_OF(query_virtio_q_counters_out, in, hdr);
+       void *virtio_q_counters = MLX5_ADDR_OF(query_virtio_q_counters_out, out,
+                                              virtio_q_counters);
+       int ret;
+
+       MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
+                MLX5_CMD_OP_QUERY_GENERAL_OBJECT);
+       MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
+                MLX5_GENERAL_OBJ_TYPE_VIRTIO_Q_COUNTERS);
+       MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, couners_obj->id);
+       ret = mlx5_glue->devx_obj_query(couners_obj->obj, in, sizeof(in), out,
+                                       sizeof(out));
+       if (ret) {
+               DRV_LOG(ERR, "Failed to query virtio q counters using DevX.");
+               rte_errno = errno;
+               return -errno;
+       }
+       attr->received_desc = MLX5_GET64(virtio_q_counters, virtio_q_counters,
+                                        received_desc);
+       attr->completed_desc = MLX5_GET64(virtio_q_counters, virtio_q_counters,
+                                         completed_desc);
+       attr->error_cqes = MLX5_GET(virtio_q_counters, virtio_q_counters,
+                                   error_cqes);
+       attr->bad_desc_errors = MLX5_GET(virtio_q_counters, virtio_q_counters,
+                                        bad_desc_errors);
+       attr->exceed_max_chain = MLX5_GET(virtio_q_counters, virtio_q_counters,
+                                         exceed_max_chain);
+       attr->invalid_buffer = MLX5_GET(virtio_q_counters, virtio_q_counters,
+                                       invalid_buffer);
+       return ret;
+}