devtools: forbid variable declaration inside for
[dpdk.git] / drivers / common / mlx5 / mlx5_devx_cmds.c
index fba485e..2179a83 100644 (file)
@@ -416,7 +416,7 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,
        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,
@@ -464,6 +464,9 @@ mlx5_devx_cmd_query_hca_attr(void *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 |
@@ -529,7 +532,7 @@ mlx5_devx_cmd_query_hca_attr(void *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]);
@@ -577,6 +580,7 @@ int
 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;
@@ -592,6 +596,12 @@ mlx5_devx_cmd_qp_query_tis_td(void *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
 }
 
 /**
@@ -1258,6 +1268,8 @@ mlx5_devx_cmd_create_virtq(void *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));
@@ -1532,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;
+}