From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DC2BF43AD8; Tue, 13 Feb 2024 14:50:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4591642DBD; Tue, 13 Feb 2024 14:50:47 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by mails.dpdk.org (Postfix) with ESMTP id 2FE6B40294 for ; Tue, 13 Feb 2024 14:50:45 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kW/rHTEraig2tABWwJ5utuIrG2qRoiKM+ffViJPYHVleshNUolGWvx/jScTwNkaW9IMjF9o+jeYErbtPlSdq/2MSYUTB3SXRyl6+bJiA3XIcFHcJ1NyM8Wj+9xmo8g9OaidW4pM148hjre68IXekA2y6cU6h4aV/lQJVag55ieLDlsPSYq3PBWdgN/Z326GFISrxVh09e2OuL+pgDptpDTUMnR+Ns7hWHLaLiWkwGxpyuvPRrF9CBMLq8OzsRqkGJDsl19JCs6JWUP7owtNQxJA6CCFJAPYSR3jDEBEwM7f4jFnjmhRo0rJ8zcTOx935VzsL1DqOirfs0be0UDXw/Q== 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=gybTW7nJOzeAuOg2EvJs9FzF9DnRwit6iviwDP7REc4=; b=jQb2sBsR0so4mi03GjeBPJvzcytecL2dgCLATklOKscOa+HCSLKK+6XAFVOJHhtxAhyYBu/01H/QwgsBi6SN4Xk9QTb/U66oNz6ZyCGv/2fz2v6pYxh40K+muYeB1+fi+z8N+4kdQlIv7jp1ioqmT+vffOeJ7KZFcr+1oIwIjSlQaOAW6/J2n0mR/4k0s1zvnHV/YIhXW9D+ObG0leSoO7I//NdvwkVeI6SwTSSpvfM5hitwsZURq7/7xIpMINK04CZgdEPJ8sLFbj2xKgNz7PSOS/AwZSKMDMwzdNv5pc0HFVDr3V1DJasBJTCPonzDpFvHxiFLjkxtWPUsDjCCig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=amd.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=gybTW7nJOzeAuOg2EvJs9FzF9DnRwit6iviwDP7REc4=; b=Mp5gaAKk+M7S8yq8qbWVYMPI3pyBqeivujO+PKAU8C1kR14y+RFhSRuDGJttoASroESr0SrBUfBd2zINf7848UHSuVFLaA8D+bHwlZBdoK96s348kKNvjDrAnDSLSoySfKXyboTMHibGgcO5v+boCL/GdOBhOnGyWxMxdjNeMn9M1RZycxU4HZdcxlNm+cS7gDp6HNmL9fN9u4IU4fdDXxPYSZpT4k3YwJHX6HSgfqPX+bOL3fj4+bZLv2yMyai4VrLM3Vw31gio4TEc7+YzJ45jik7zyyPKD5kiUH+A7LI+Uy0ts41cqtcbYEpZpQ58YVrmzzJsflkYDFcb2LwRbA== Received: from PH8PR07CA0011.namprd07.prod.outlook.com (2603:10b6:510:2cd::19) by CH2PR12MB4263.namprd12.prod.outlook.com (2603:10b6:610:a6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25; Tue, 13 Feb 2024 13:50:42 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::86) by PH8PR07CA0011.outlook.office365.com (2603:10b6:510:2cd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.39 via Frontend Transport; Tue, 13 Feb 2024 13:50:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 13 Feb 2024 13:50:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 13 Feb 2024 05:50:26 -0800 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Tue, 13 Feb 2024 05:50:23 -0800 From: Ori Kam To: , , , , , Viacheslav Ovsiienko , Suanming Mou , Matan Azrad CC: , , , Hamdan Igbaria Subject: [PATCH v3 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Date: Tue, 13 Feb 2024 15:48:31 +0200 Message-ID: <20240213134834.16762-2-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213134834.16762-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240213134834.16762-1-orika@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4B:EE_|CH2PR12MB4263:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a74dfe4-8606-48ee-6783-08dc2c9ac4f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3yGj5JyNK/K63y9LCaHiiDKmwGvbgtzs9u8R3mw/X7qm216kenSglcS2louG9hOVXOPoDGZqGW3ybNInmeeyDHtihkqeesrpf6w3RgFaH6Y0a3t7UE4uQgyDnV++L9B0XTVJHNosFZ8dcmJl3tHtMM7XdsN4zgENdwXtpdk3YtbOoinyohtABzwr03u/SPvFtN2DTZ+68Okq2ni9fSuKksh2qkQSnQc75vaaMxS2Tst0lDR7qRZWSA5Nr9AzEZMstaNx0xPAgm1pz/ASiNvxBo22BpfG4xw6OlkgcFoqqmW6cw74op1/3yxkPpibxBpmI2jYym5nQQPL9Pd+wk6rsnqRFPMM5O9nUQTN/jPb8DiAWXFfgI63aixfQDXYQbJA7qrBfb3xvlj5LjIbl2XG6oO91gVGZExvMyo0j2M6hPC2ksvfOA7MIO+CO3vCKIaD9L+qWg0xtnAGQpfUCYDU8htYRwUyL/UdOf1jfJmQ+56H8n64y4WUU5FzKdFiTaC9/NTGPK2itUXgCoA0NHF/Y2BR2y45w8whRA1/LVlpw+9Jb/L73tjHjnirMpE7+b+c0qC65+sF0r3xmGXeaaBZFUuUbr0CmqH4fEwpT0hvnAQ= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(396003)(39860400002)(376002)(346002)(230922051799003)(64100799003)(186009)(82310400011)(1800799012)(451199024)(36840700001)(46966006)(40470700004)(478600001)(41300700001)(55016003)(5660300002)(8936002)(8676002)(4326008)(2906002)(70586007)(6636002)(54906003)(70206006)(7696005)(6666004)(6286002)(316002)(26005)(83380400001)(336012)(426003)(86362001)(82740400003)(7636003)(356005)(2616005)(110136005)(16526019)(36756003)(107886003)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 13:50:41.9011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a74dfe4-8606-48ee-6783-08dc2c9ac4f2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4263 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 From: Hamdan Igbaria Add new function for encap entropy hash calculation, the function will check the device capability for the entropy hash type used by the device, and will calculate the entropy hash value of the user passed fields according this type. Signed-off-by: Hamdan Igbaria Acked-by: Dariusz Sosnowski --- drivers/common/mlx5/mlx5_prm.h | 8 ++- drivers/net/mlx5/hws/mlx5dr.h | 38 ++++++++++++++ drivers/net/mlx5/hws/mlx5dr_cmd.c | 23 +++++++++ drivers/net/mlx5/hws/mlx5dr_cmd.h | 4 ++ drivers/net/mlx5/hws/mlx5dr_crc32.c | 78 +++++++++++++++++++++++++++++ drivers/net/mlx5/hws/mlx5dr_crc32.h | 5 ++ 6 files changed, 154 insertions(+), 2 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index abff8e4dc3..50c681704a 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -2132,7 +2132,10 @@ struct mlx5_ifc_flow_table_prop_layout_bits { struct mlx5_ifc_roce_caps_bits { u8 reserved_0[0x1e]; u8 qp_ts_format[0x2]; - u8 reserved_at_20[0x7e0]; + u8 reserved_at_20[0xa0]; + u8 r_roce_max_src_udp_port[0x10]; + u8 r_roce_min_src_udp_port[0x10]; + u8 reserved_at_e0[0x720]; }; struct mlx5_ifc_ft_fields_support_bits { @@ -2370,7 +2373,8 @@ struct mlx5_ifc_cmd_hca_cap_2_bits { u8 format_select_dw_gtpu_first_ext_dw_0[0x8]; u8 generate_wqe_type[0x20]; u8 reserved_at_2c0[0x160]; - u8 reserved_at_420[0x1c]; + u8 reserved_at_420[0x18]; + u8 encap_entropy_hash_type[0x4]; u8 flow_table_hash_type[0x4]; u8 reserved_at_440[0x3c0]; }; diff --git a/drivers/net/mlx5/hws/mlx5dr.h b/drivers/net/mlx5/hws/mlx5dr.h index d88f73ab57..321b649f8c 100644 --- a/drivers/net/mlx5/hws/mlx5dr.h +++ b/drivers/net/mlx5/hws/mlx5dr.h @@ -279,6 +279,27 @@ struct mlx5dr_action_dest_attr { } reformat; }; +union mlx5dr_crc_encap_entropy_hash_ip_field { + uint8_t ipv6_addr[16]; + struct { + uint8_t reserved[12]; + rte_be32_t ipv4_addr; + }; +}; + +struct mlx5dr_crc_encap_entropy_hash_fields { + union mlx5dr_crc_encap_entropy_hash_ip_field dst; + union mlx5dr_crc_encap_entropy_hash_ip_field src; + uint8_t next_protocol; + rte_be16_t dst_port; + rte_be16_t src_port; +}__rte_packed; + +enum mlx5dr_crc_encap_entropy_hash_size { + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8, + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16, +}; + /* Open a context used for direct rule insertion using hardware steering. * Each context can contain multiple tables of different types. * @@ -845,4 +866,21 @@ int mlx5dr_send_queue_action(struct mlx5dr_context *ctx, */ int mlx5dr_debug_dump(struct mlx5dr_context *ctx, FILE *f); +/* Calculate encap entropy hash value + * + * @param[in] ctx + * The context to get from it's capabilities the entropy hash type. + * @param[in] data + * The fields for the hash calculation. + * @param[in] entropy_res + * An array to store the hash value to it. + * @param[in] res_size + * The result size. + * @return zero on success non zero otherwise. + */ +int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx, + struct mlx5dr_crc_encap_entropy_hash_fields *data, + uint8_t entropy_res[], + enum mlx5dr_crc_encap_entropy_hash_size res_size); + #endif diff --git a/drivers/net/mlx5/hws/mlx5dr_cmd.c b/drivers/net/mlx5/hws/mlx5dr_cmd.c index 876a47147d..f77b194708 100644 --- a/drivers/net/mlx5/hws/mlx5dr_cmd.c +++ b/drivers/net/mlx5/hws/mlx5dr_cmd.c @@ -1103,6 +1103,8 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, caps->ipsec_offload = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap.ipsec_offload); + caps->roce = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap.roce); + MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 | MLX5_HCA_CAP_OPMOD_GET_CUR); @@ -1158,6 +1160,9 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, caps->flow_table_hash_type = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap_2.flow_table_hash_type); + caps->encap_entropy_hash_type = MLX5_GET(query_hca_cap_out, out, + capability.cmd_hca_cap_2.encap_entropy_hash_type); + MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | MLX5_HCA_CAP_OPMOD_GET_CUR); @@ -1306,6 +1311,24 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, capability.esw_cap.merged_eswitch); } + if (caps->roce) { + MLX5_SET(query_hca_cap_in, in, op_mod, + MLX5_GET_HCA_CAP_OP_MOD_ROCE | + MLX5_HCA_CAP_OPMOD_GET_CUR); + + ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out)); + if (ret) { + DR_LOG(ERR, "Failed to query roce caps"); + rte_errno = errno; + return rte_errno; + } + + caps->roce_max_src_udp_port = MLX5_GET(query_hca_cap_out, out, + capability.roce_caps.r_roce_max_src_udp_port); + caps->roce_min_src_udp_port = MLX5_GET(query_hca_cap_out, out, + capability.roce_caps.r_roce_min_src_udp_port); + } + ret = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex); if (ret) { DR_LOG(ERR, "Failed to query device attributes"); diff --git a/drivers/net/mlx5/hws/mlx5dr_cmd.h b/drivers/net/mlx5/hws/mlx5dr_cmd.h index 18c2b07fc8..694231e08f 100644 --- a/drivers/net/mlx5/hws/mlx5dr_cmd.h +++ b/drivers/net/mlx5/hws/mlx5dr_cmd.h @@ -246,6 +246,10 @@ struct mlx5dr_cmd_query_caps { uint32_t shared_vhca_id; char fw_ver[64]; bool ipsec_offload; + uint8_t encap_entropy_hash_type; + bool roce; + uint16_t roce_max_src_udp_port; + uint16_t roce_min_src_udp_port; }; int mlx5dr_cmd_destroy_obj(struct mlx5dr_devx_obj *devx_obj); diff --git a/drivers/net/mlx5/hws/mlx5dr_crc32.c b/drivers/net/mlx5/hws/mlx5dr_crc32.c index 9c454eda0c..7431462e14 100644 --- a/drivers/net/mlx5/hws/mlx5dr_crc32.c +++ b/drivers/net/mlx5/hws/mlx5dr_crc32.c @@ -50,6 +50,42 @@ uint32_t dr_ste_crc_tab32[] = { 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; +/* CRC table for the CRC-16, the polynome is 0x100b */ +uint16_t dr_crc_inner_crc_tab16[] = { + 0x0000, 0x100B, 0x2016, 0x301D, 0x402C, 0x5027, 0x603A, 0x7031, + 0x8058, 0x9053, 0xA04E, 0xB045, 0xC074, 0xD07F, 0xE062, 0xF069, + 0x10BB, 0x00B0, 0x30AD, 0x20A6, 0x5097, 0x409C, 0x7081, 0x608A, + 0x90E3, 0x80E8, 0xB0F5, 0xA0FE, 0xD0CF, 0xC0C4, 0xF0D9, 0xE0D2, + 0x2176, 0x317D, 0x0160, 0x116B, 0x615A, 0x7151, 0x414C, 0x5147, + 0xA12E, 0xB125, 0x8138, 0x9133, 0xE102, 0xF109, 0xC114, 0xD11F, + 0x31CD, 0x21C6, 0x11DB, 0x01D0, 0x71E1, 0x61EA, 0x51F7, 0x41FC, + 0xB195, 0xA19E, 0x9183, 0x8188, 0xF1B9, 0xE1B2, 0xD1AF, 0xC1A4, + 0x42EC, 0x52E7, 0x62FA, 0x72F1, 0x02C0, 0x12CB, 0x22D6, 0x32DD, + 0xC2B4, 0xD2BF, 0xE2A2, 0xF2A9, 0x8298, 0x9293, 0xA28E, 0xB285, + 0x5257, 0x425C, 0x7241, 0x624A, 0x127B, 0x0270, 0x326D, 0x2266, + 0xD20F, 0xC204, 0xF219, 0xE212, 0x9223, 0x8228, 0xB235, 0xA23E, + 0x639A, 0x7391, 0x438C, 0x5387, 0x23B6, 0x33BD, 0x03A0, 0x13AB, + 0xE3C2, 0xF3C9, 0xC3D4, 0xD3DF, 0xA3EE, 0xB3E5, 0x83F8, 0x93F3, + 0x7321, 0x632A, 0x5337, 0x433C, 0x330D, 0x2306, 0x131B, 0x0310, + 0xF379, 0xE372, 0xD36F, 0xC364, 0xB355, 0xA35E, 0x9343, 0x8348, + 0x85D8, 0x95D3, 0xA5CE, 0xB5C5, 0xC5F4, 0xD5FF, 0xE5E2, 0xF5E9, + 0x0580, 0x158B, 0x2596, 0x359D, 0x45AC, 0x55A7, 0x65BA, 0x75B1, + 0x9563, 0x8568, 0xB575, 0xA57E, 0xD54F, 0xC544, 0xF559, 0xE552, + 0x153B, 0x0530, 0x352D, 0x2526, 0x5517, 0x451C, 0x7501, 0x650A, + 0xA4AE, 0xB4A5, 0x84B8, 0x94B3, 0xE482, 0xF489, 0xC494, 0xD49F, + 0x24F6, 0x34FD, 0x04E0, 0x14EB, 0x64DA, 0x74D1, 0x44CC, 0x54C7, + 0xB415, 0xA41E, 0x9403, 0x8408, 0xF439, 0xE432, 0xD42F, 0xC424, + 0x344D, 0x2446, 0x145B, 0x0450, 0x7461, 0x646A, 0x5477, 0x447C, + 0xC734, 0xD73F, 0xE722, 0xF729, 0x8718, 0x9713, 0xA70E, 0xB705, + 0x476C, 0x5767, 0x677A, 0x7771, 0x0740, 0x174B, 0x2756, 0x375D, + 0xD78F, 0xC784, 0xF799, 0xE792, 0x97A3, 0x87A8, 0xB7B5, 0xA7BE, + 0x57D7, 0x47DC, 0x77C1, 0x67CA, 0x17FB, 0x07F0, 0x37ED, 0x27E6, + 0xE642, 0xF649, 0xC654, 0xD65F, 0xA66E, 0xB665, 0x8678, 0x9673, + 0x661A, 0x7611, 0x460C, 0x5607, 0x2636, 0x363D, 0x0620, 0x162B, + 0xF6F9, 0xE6F2, 0xD6EF, 0xC6E4, 0xB6D5, 0xA6DE, 0x96C3, 0x86C8, + 0x76A1, 0x66AA, 0x56B7, 0x46BC, 0x368D, 0x2686, 0x169B, 0x0690 +}; + uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len) { uint32_t crc = 0; @@ -59,3 +95,45 @@ uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len) return rte_be_to_cpu_32(crc); } + +uint16_t mlx5dr_crc16_calc(uint8_t *p, size_t len, uint16_t crc_tab16[]) +{ + uint16_t crc = 0; + + while (len--) + crc = (crc << 8) ^ crc_tab16[((crc >> 8) ^ *p++) & 0xff]; + + return crc; +} + +int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx, + struct mlx5dr_crc_encap_entropy_hash_fields *data, + uint8_t entropy_res[], + enum mlx5dr_crc_encap_entropy_hash_size res_size) +{ + struct mlx5dr_cmd_query_caps *caps = ctx->caps; + uint16_t max_hash, min_hash, res; + + if (caps->encap_entropy_hash_type) { + DR_LOG(ERR, "calculation of encap_entropy_hash_type 0x%x not supported", + caps->encap_entropy_hash_type); + rte_errno = ENOTSUP; + return rte_errno; + } + + max_hash = caps->roce_max_src_udp_port; + min_hash = caps->roce_min_src_udp_port; + + res = mlx5dr_crc16_calc((uint8_t *)data, sizeof(*data), dr_crc_inner_crc_tab16); + + if (res_size == MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16) { + *(uint16_t *)entropy_res = rte_cpu_to_be_16((min_hash | res) & max_hash); + } else if (res_size == MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8) { + *entropy_res = (uint8_t)(res & 0xff); + } else { + rte_errno = ENOTSUP; + return rte_errno; + } + + return 0; +} diff --git a/drivers/net/mlx5/hws/mlx5dr_crc32.h b/drivers/net/mlx5/hws/mlx5dr_crc32.h index 9aab9e06ca..75b6009a15 100644 --- a/drivers/net/mlx5/hws/mlx5dr_crc32.h +++ b/drivers/net/mlx5/hws/mlx5dr_crc32.h @@ -10,4 +10,9 @@ */ uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len); +/* Standard CRC16 calculation using the crc_tab16 param to indicate + * the pre-calculated polynome hash values. + */ +uint16_t mlx5dr_crc16_calc(uint8_t *p, size_t len, uint16_t crc_tab16[]); + #endif /* MLX5DR_CRC32_C_ */ -- 2.34.1