From patchwork Fri Oct 1 19:34:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 100349 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4E6A6A0032; Fri, 1 Oct 2021 21:35:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA2BC4123C; Fri, 1 Oct 2021 21:34:59 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2075.outbound.protection.outlook.com [40.107.236.75]) by mails.dpdk.org (Postfix) with ESMTP id 3699D4121F for ; Fri, 1 Oct 2021 21:34:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UDu6j0i8UgmPnwRGRC0UCvQfFzXdglzxQE5xyqiLzq7kq+knC4BJdkc2OHZ2tmhXDy5gbffgrqIIBpdaQHazSXlG0Lgft8oKWIV6cRm08LnLKShSXegaigMXUbK7nQQN6GQDwbW8pmmRmUNyOwIxaV4z/8d2OE8T9+guBRJkssbtRF40E4x1jn1yAewqgm1IaUPRCGb8VCWqfRR4eR4Ub3A1EKushJalb6SEMk/vIkDdj9ysE05g9+X2hsx9s+0LMxJAudL59Gdc0t3YDHeX1FDWFPT6i8sIjWJTID3TBmYlNkESCcmeHtnRQqa+4vLfVVaF9B3SJNkGPiSx5HZOEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L9yNKVQyZE42O2m15AVjOk2FbC+C8qH+bHBvicSxoVY=; b=QY5S1DABXvzUJIfq3eqsGWrSHZqA0HQb4095ynFw+7QkNCJRDaaAlrgWAx3o+onN4E7RD08gM6xm+1/rJ6r7wWy22zJBCNmEcNrkCuPYMjvs27w7wf8RlqzwYHvgo+XhG/Ck1HzusTXLVrs+LhInDkq0zmItInBQC9jbUViks7sD1gBLeta1rEjD9d9Ielp0zuf6xzZJXtAespgiO2qGUzkASw5pFaZHPIcq6pqmSzSm5rPzzANbmzXY9xuXR88GCjCfoziadrV6jBAck+Mtr9i6MJcZlNNpEQv9a2yIu03ZEh51SlXrsuwjChDIqC5rhwafzPfwLIvm6Bd68K+fuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L9yNKVQyZE42O2m15AVjOk2FbC+C8qH+bHBvicSxoVY=; b=s/4yiBe287qZm8MHK0fZR8vneclf8zgsT30fk5r3zHJ/VOqDNJB7OWn5sfc6gHl4/HuhaUDopQ7tq6Ltx67FvKypjjh/0MeHgS7ishSDzzrfgj6Tga7oJtp+91N4zn53Q5qsDMFShOpID2xw8YGzRjXtyf75m00NQU8hgiWxTb0FvhdUgo5Yd6jkhpIzCw/Qs561P6IXXQekKGSnwecXWKKxlmxg0m3DH3RR3kRQ+N7HZZNUkiBlH4uPX/FWZJZOfNStEBPDiSotlrHnkiyKYJk+05xUXh0pIv3V2mckOZfWs/7w2YabHEJnmT7izRahhBivu6WN4IheS6DNuC5wLQ== Received: from BN8PR16CA0034.namprd16.prod.outlook.com (2603:10b6:408:4c::47) by CH2PR12MB4150.namprd12.prod.outlook.com (2603:10b6:610:a6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14; Fri, 1 Oct 2021 19:34:55 +0000 Received: from BN8NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:408:4c:cafe::56) by BN8PR16CA0034.outlook.office365.com (2603:10b6:408:4c::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13 via Frontend Transport; Fri, 1 Oct 2021 19:34:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT016.mail.protection.outlook.com (10.13.176.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 19:34:54 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 1 Oct 2021 19:34:52 +0000 From: Viacheslav Ovsiienko To: CC: , , , , , Date: Fri, 1 Oct 2021 22:34:07 +0300 Message-ID: <20211001193415.23288-7-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20211001193415.23288-1-viacheslavo@nvidia.com> References: <20210922180418.20663-1-viacheslavo@nvidia.com> <20211001193415.23288-1-viacheslavo@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 35c9638f-319b-4f1f-1391-08d985128bcf X-MS-TrafficTypeDiagnostic: CH2PR12MB4150: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LCkwx8rxk/YQ9ClUQIkK8NVX19YmCjx7sSZs8hXhluN28Q056AvStBtXLPLqD1OAfWHtpFkosel8nuCa04EIUoRGxlyMUfNDmmvA4BVRJXcAXFaYTe3CsZy3CGi1/0/gA9dKxHo7ZIaANiSNGPyoGjdMxhBQrYNbsN/wruaNZkj8oRgXt6Vk6ATa5YvG+4i7LV/PGDvBqKruQn5pzd9UxwE7pEC8Q6wNMtNLbN8hrj4KvaCXgHGSUXdqFqeGwACJuWKxrOwidxfMCsFVEHhvruOmtz87WHspSGsPuyq+Zak4mHFJ51e9zpOA5TYknPOH0A+I9oUFvvegyt2ro+4yd3+nR0Y7G7vMrY1hs1e2nDgH04NO7tZxZB4LxN1MEz457eWwP19xvxESATiRVI0LIlfmm1IeQNExpWbGTP6udUy7o9ZjKuRKDqGPHbMfMnyQV+DZESYKnoVB6KK2xYBRRINIyExMEfjU5zhLeMKvJ/+ZTpXQRGBi502VQyc/1PlKqg4gB429yawIHJY4AsCxwOQsqf7O/ugSulvJ6gYnsjAuIahwKqGr34JttofKdhTTdqY2fOfg7PwhsLdVkHJKshXpvjJ/egI/9NVCLKZzzoUABlVRfCn5poEDfTWW/ujVF5B8cKYa+WZUXGf5W+30Ef8+DWrerAry0ljA5IHJ+/fwj/++M2Vemy9dpxcQg8yafocldbfMv4egZ2TES/fdDg== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(6666004)(16526019)(36756003)(55016002)(47076005)(54906003)(508600001)(4326008)(186003)(6286002)(36860700001)(86362001)(70586007)(8936002)(82310400003)(5660300002)(2616005)(7696005)(70206006)(7636003)(426003)(356005)(8676002)(2906002)(83380400001)(1076003)(336012)(26005)(316002)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 19:34:54.9286 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35c9638f-319b-4f1f-1391-08d985128bcf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4150 Subject: [dpdk-dev] [PATCH v2 06/14] common/mlx5: refactor HCA attributes query X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" There is the common part of code querying the HCA attributes from the device, and this part can be commoditized as dedicated routine. Signed-off-by: Viacheslav Ovsiienko --- drivers/common/mlx5/mlx5_devx_cmds.c | 173 +++++++++++---------------- 1 file changed, 73 insertions(+), 100 deletions(-) diff --git a/drivers/common/mlx5/mlx5_devx_cmds.c b/drivers/common/mlx5/mlx5_devx_cmds.c index 56407cc332..8273e98146 100644 --- a/drivers/common/mlx5/mlx5_devx_cmds.c +++ b/drivers/common/mlx5/mlx5_devx_cmds.c @@ -13,6 +13,42 @@ #include "mlx5_common_log.h" #include "mlx5_malloc.h" +static void * +mlx5_devx_get_hca_cap(void *ctx, uint32_t *in, uint32_t *out, + int *err, uint32_t flags) +{ + const size_t size_in = MLX5_ST_SZ_DW(query_hca_cap_in) * sizeof(int); + const size_t size_out = MLX5_ST_SZ_DW(query_hca_cap_out) * sizeof(int); + int status, syndrome, rc; + + if (err) + *err = 0; + memset(in, 0, size_in); + memset(out, 0, size_out); + MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP); + MLX5_SET(query_hca_cap_in, in, op_mod, flags); + rc = mlx5_glue->devx_general_cmd(ctx, in, size_in, out, size_out); + if (rc) { + DRV_LOG(ERR, + "Failed to query devx HCA capabilities func %#02x", + flags >> 1); + if (err) + *err = rc > 0 ? -rc : rc; + return NULL; + } + status = MLX5_GET(query_hca_cap_out, out, status); + syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); + if (status) { + DRV_LOG(ERR, + "Failed to query devx HCA capabilities func %#02x status %x, syndrome = %x", + flags >> 1, status, syndrome); + if (err) + *err = -1; + return NULL; + } + return MLX5_ADDR_OF(query_hca_cap_out, out, capability); +} + /** * Perform read access to the registers. Reads data from register * and writes ones to the specified buffer. @@ -472,21 +508,15 @@ static void 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}; - uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)] = {0}; - void *hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); - int status, syndrome, rc; + uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)]; + uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)]; + void *hcattr; - MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP); - MLX5_SET(query_hca_cap_in, in, op_mod, - MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION | - MLX5_HCA_CAP_OPMOD_GET_CUR); - rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out)); - status = MLX5_GET(query_hca_cap_out, out, status); - syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); - if (rc || status) { - RTE_LOG(DEBUG, PMD, "Failed to query devx VDPA capabilities," - " status %x, syndrome = %x", status, syndrome); + hcattr = mlx5_devx_get_hca_cap(ctx, in, out, NULL, + MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) { + RTE_LOG(DEBUG, PMD, "Failed to query devx VDPA capabilities"); vdpa_attr->valid = 0; } else { vdpa_attr->valid = 1; @@ -741,27 +771,15 @@ 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, i; uint64_t general_obj_types_supported = 0; + void *hcattr; + int 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, - MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE | - MLX5_HCA_CAP_OPMOD_GET_CUR); - - rc = mlx5_glue->devx_general_cmd(ctx, - in, sizeof(in), out, sizeof(out)); - if (rc) - goto error; - status = MLX5_GET(query_hca_cap_out, out, status); - syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); - if (status) { - DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, " - "status %x, syndrome = %x", status, syndrome); - return -1; - } - hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); + hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc, + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) + return rc; attr->flow_counter_bulk_alloc_bitmap = MLX5_GET(cmd_hca_cap, hcattr, flow_counter_bulk_alloc); attr->flow_counters_dump = MLX5_GET(cmd_hca_cap, hcattr, @@ -884,19 +902,13 @@ mlx5_devx_cmd_query_hca_attr(void *ctx, general_obj_types) & MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD); if (attr->qos.sup) { - MLX5_SET(query_hca_cap_in, in, op_mod, - MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP | - MLX5_HCA_CAP_OPMOD_GET_CUR); - rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), - out, sizeof(out)); - if (rc) - goto error; - if (status) { - DRV_LOG(DEBUG, "Failed to query devx QOS capabilities," - " status %x, syndrome = %x", status, syndrome); - return -1; + hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc, + MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) { + DRV_LOG(DEBUG, "Failed to query devx QOS capabilities"); + return rc; } - hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); attr->qos.flow_meter_old = MLX5_GET(qos_cap, hcattr, flow_meter_old); attr->qos.log_max_flow_meter = @@ -925,27 +937,14 @@ mlx5_devx_cmd_query_hca_attr(void *ctx, mlx5_devx_cmd_query_hca_vdpa_attr(ctx, &attr->vdpa); if (!attr->eth_net_offloads) return 0; - /* Query Flow Sampler Capability From FLow Table Properties Layout. */ - memset(in, 0, sizeof(in)); - memset(out, 0, sizeof(out)); - MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP); - MLX5_SET(query_hca_cap_in, in, op_mod, - MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | - MLX5_HCA_CAP_OPMOD_GET_CUR); - - rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out)); - if (rc) - goto error; - status = MLX5_GET(query_hca_cap_out, out, status); - syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); - if (status) { - DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, " - "status %x, syndrome = %x", status, syndrome); + hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc, + MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) { attr->log_max_ft_sampler_num = 0; - return -1; + return rc; } - hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); attr->log_max_ft_sampler_num = MLX5_GET (flow_table_nic_cap, hcattr, flow_table_properties_nic_receive.log_max_ft_sampler_num); @@ -960,27 +959,13 @@ mlx5_devx_cmd_query_hca_attr(void *ctx, (flow_table_nic_cap, hcattr, ft_field_support_2_nic_receive.outer_ipv4_ihl); /* Query HCA offloads for Ethernet protocol. */ - memset(in, 0, sizeof(in)); - memset(out, 0, sizeof(out)); - MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP); - MLX5_SET(query_hca_cap_in, in, op_mod, - MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS | - MLX5_HCA_CAP_OPMOD_GET_CUR); - - rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out)); - if (rc) { + mlx5_devx_get_hca_cap(ctx, in, out, &rc, + MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) { attr->eth_net_offloads = 0; - goto error; + return rc; } - status = MLX5_GET(query_hca_cap_out, out, status); - syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); - if (status) { - DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, " - "status %x, syndrome = %x", status, syndrome); - attr->eth_net_offloads = 0; - return -1; - } - hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); attr->wqe_vlan_insert = MLX5_GET(per_protocol_networking_offload_caps, hcattr, wqe_vlan_insert); attr->csum_cap = MLX5_GET(per_protocol_networking_offload_caps, @@ -1017,26 +1002,14 @@ mlx5_devx_cmd_query_hca_attr(void *ctx, hcattr, rss_ind_tbl_cap); /* Query HCA attribute for ROCE. */ if (attr->roce) { - memset(in, 0, sizeof(in)); - memset(out, 0, sizeof(out)); - MLX5_SET(query_hca_cap_in, in, opcode, - MLX5_CMD_OP_QUERY_HCA_CAP); - MLX5_SET(query_hca_cap_in, in, op_mod, - MLX5_GET_HCA_CAP_OP_MOD_ROCE | - MLX5_HCA_CAP_OPMOD_GET_CUR); - rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), - out, sizeof(out)); - if (rc) - goto error; - status = MLX5_GET(query_hca_cap_out, out, status); - syndrome = MLX5_GET(query_hca_cap_out, out, syndrome); - if (status) { + hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc, + MLX5_GET_HCA_CAP_OP_MOD_ROCE | + MLX5_HCA_CAP_OPMOD_GET_CUR); + if (!hcattr) { DRV_LOG(DEBUG, - "Failed to query devx HCA ROCE capabilities, " - "status %x, syndrome = %x", status, syndrome); - return -1; + "Failed to query devx HCA ROCE capabilities"); + return rc; } - hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability); attr->qp_ts_format = MLX5_GET(roce_caps, hcattr, qp_ts_format); } if (attr->eth_virt &&