From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 5576EA0524;
	Wed, 14 Apr 2021 04:58:45 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 62CB3161617;
	Wed, 14 Apr 2021 04:57:56 +0200 (CEST)
Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])
 by mails.dpdk.org (Postfix) with ESMTP id 532171615E4
 for <dev@dpdk.org>; Wed, 14 Apr 2021 04:57:50 +0200 (CEST)
Received: from Internal Mail-Server by MTLPINE1 (envelope-from lizh@nvidia.com)
 with SMTP; 14 Apr 2021 05:57:45 +0300
Received: from nvidia.com (c-135-185-1-009.mtl.labs.mlnx [10.135.185.9])
 by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 13E2vh4m010194;
 Wed, 14 Apr 2021 05:57:45 +0300
From: Li Zhang <lizh@nvidia.com>
To: dekelp@nvidia.com, orika@nvidia.com, viacheslavo@nvidia.com,
 matan@nvidia.com, shahafs@nvidia.com, Ray Kinsella <mdr@ashroe.eu>,
 Neil Horman <nhorman@tuxdriver.com>
Cc: dev@dpdk.org, thomas@monjalon.net, rasland@nvidia.com, roniba@nvidia.com
Date: Wed, 14 Apr 2021 05:57:29 +0300
Message-Id: <20210414025736.31142-9-lizh@nvidia.com>
X-Mailer: git-send-email 2.21.0
In-Reply-To: <20210414025736.31142-1-lizh@nvidia.com>
References: <20210331073632.1443011-1-lizh@nvidia.com>
 <20210414025736.31142-1-lizh@nvidia.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v4 08/14] common/mlx5: add DevX API to create ASO
 flow meter object
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Add DevX API to create ASO flow meter object.

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_devx_cmds.c | 54 ++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h | 18 +++++++++-
 drivers/common/mlx5/version.map      |  1 +
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/common/mlx5/mlx5_devx_cmds.c b/drivers/common/mlx5/mlx5_devx_cmds.c
index a878a5c689..c605966184 100644
--- a/drivers/common/mlx5/mlx5_devx_cmds.c
+++ b/drivers/common/mlx5/mlx5_devx_cmds.c
@@ -2159,6 +2159,60 @@ mlx5_devx_cmd_alloc_pd(void *ctx)
 	return ppd;
 }
 
+/**
+ * Create general object of type FLOW_METER_ASO using DevX API.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param [in] pd
+ *   PD value to associate the FLOW_METER_ASO object with.
+ * @param [in] log_obj_size
+ *   log_obj_size define to allocate number of 2 * meters
+ *   in one FLOW_METER_ASO object.
+ *
+ * @return
+ *   The DevX object created, NULL otherwise and rte_errno is set.
+ */
+struct mlx5_devx_obj *
+mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,
+						uint32_t log_obj_size)
+{
+	uint32_t in[MLX5_ST_SZ_DW(create_flow_meter_aso_in)] = {0};
+	uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
+	struct mlx5_devx_obj *flow_meter_aso_obj;
+	void *ptr;
+
+	flow_meter_aso_obj = mlx5_malloc(MLX5_MEM_ZERO,
+						sizeof(*flow_meter_aso_obj),
+						0, SOCKET_ID_ANY);
+	if (!flow_meter_aso_obj) {
+		DRV_LOG(ERR, "Failed to allocate FLOW_METER_ASO object data");
+		rte_errno = ENOMEM;
+		return NULL;
+	}
+	ptr = MLX5_ADDR_OF(create_flow_meter_aso_in, in, hdr);
+	MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
+		MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
+	MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
+		MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO);
+	MLX5_SET(general_obj_in_cmd_hdr, ptr, log_obj_range,
+		log_obj_size);
+	ptr = MLX5_ADDR_OF(create_flow_meter_aso_in, in, flow_meter_aso);
+	MLX5_SET(flow_meter_aso, ptr, access_pd, pd);
+	flow_meter_aso_obj->obj = mlx5_glue->devx_obj_create(
+							ctx, in, sizeof(in),
+							out, sizeof(out));
+	if (!flow_meter_aso_obj->obj) {
+		rte_errno = errno;
+		DRV_LOG(ERR, "Failed to create FLOW_METER_ASO obj using DevX.");
+		mlx5_free(flow_meter_aso_obj);
+		return NULL;
+	}
+	flow_meter_aso_obj->id = MLX5_GET(general_obj_out_cmd_hdr,
+								out, obj_id);
+	return flow_meter_aso_obj;
+}
+
 /**
  * Create general object of type GENEVE TLV option using DevX API.
  *
diff --git a/drivers/common/mlx5/mlx5_devx_cmds.h b/drivers/common/mlx5/mlx5_devx_cmds.h
index 673e41599e..c71d0bf73c 100644
--- a/drivers/common/mlx5/mlx5_devx_cmds.h
+++ b/drivers/common/mlx5/mlx5_devx_cmds.h
@@ -554,7 +554,6 @@ int mlx5_devx_cmd_query_virtio_q_counters(struct mlx5_devx_obj *couners_obj,
 __rte_internal
 struct mlx5_devx_obj *mlx5_devx_cmd_create_flow_hit_aso_obj(void *ctx,
 							    uint32_t pd);
-
 __rte_internal
 struct mlx5_devx_obj *mlx5_devx_cmd_alloc_pd(void *ctx);
 
@@ -566,4 +565,21 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);
 __rte_internal
 int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,
 				      uint32_t *out_of_buffers);
+/**
+ * Create general object of type FLOW_METER_ASO using DevX API..
+ *
+ * @param[in] ctx
+ *   Device context.
+ * @param [in] pd
+ *   PD value to associate the FLOW_METER_ASO object with.
+ * @param [in] log_obj_size
+ *   log_obj_size define to allocate number of 2 * meters
+ *   in one FLOW_METER_ASO object.
+ *
+ * @return
+ *   The DevX object created, NULL otherwise and rte_errno is set.
+ */
+__rte_internal
+struct mlx5_devx_obj *mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx,
+					uint32_t pd, uint32_t log_obj_size);
 #endif /* RTE_PMD_MLX5_DEVX_CMDS_H_ */
diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map
index 8b196a41d2..a409fb21b5 100644
--- a/drivers/common/mlx5/version.map
+++ b/drivers/common/mlx5/version.map
@@ -25,6 +25,7 @@ INTERNAL {
 	mlx5_devx_cmd_create_virtio_q_counters; # WINDOWS_NO_EXPORT
 	mlx5_devx_cmd_create_virtq;
 	mlx5_devx_cmd_create_flow_hit_aso_obj;
+	mlx5_devx_cmd_create_flow_meter_aso_obj;
 	mlx5_devx_cmd_create_geneve_tlv_option;
 	mlx5_devx_cmd_destroy;
 	mlx5_devx_cmd_flow_counter_alloc;
-- 
2.27.0