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 2584543238; Sun, 29 Oct 2023 17:36:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A565640A67; Sun, 29 Oct 2023 17:34:17 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2050.outbound.protection.outlook.com [40.107.94.50]) by mails.dpdk.org (Postfix) with ESMTP id DCAC442DE0 for ; Sun, 29 Oct 2023 17:33:55 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=La10lPSr5EateqHXqBYcBmKEY/z0MoKQAGNDQ1brLL/YuhrzOK94/ALztiT1eB4XHi8mNX3CeJubFjeQ87YQZE5ejr1X4fpf1LizJhDuGULiYwHuEaaTI3sMphVEg9pMrMZFuM9HV5jQIGLzRBFqS49zgnwSRx8eOpUFNZlEFRS4PX5S8i6TDIOU4oW4YKoA4CnRqzlkk+U2DS1kG5D3F74o1DTsskaIvWCbE7n5GUJYgy40KsiYbAAcfbLmTvDn2MSmwH5E27yZyhNCMyyRBF+ftfTusxsoB1W5D7thOTesoyqXae+B+LLjWcNdhK2ExuBmOiHPVVdyf0S8GwpKGw== 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=2BkKAhs7b/8lipODGG7K1J3DfeQvWPPRVEmyReRNXOg=; b=eWGBeYo1rm9wZ8DMGMtZ69iYIN8mvOHEFvvlLMkkuY69CV3kZHHnBUvOqI2AlOW8FEcFD04CM5Ewpp98cutvFfdbRh3qC/hOTunnC/yo0U3iAS92i1C6s7z5ShavwINqsmaTtVptOqPBpk7Q/iCEN8ddIqG0hLurclTjqb0Cz9XOeMbTOHTc6eZeVOP8O/lMbkhBkJdOPr/zJVwBIqvRzjqBz541gzgCipUezV1BErM4o96ov9k8yMNB0luUOIJ4fHtDjSwtXXMeW1pktZ+TcEJUU4+7nWATsUKi9YxK25R2/EbavbQdWcKGtBgjCnZLQIeRL+ZwIig9ROfJOOm15g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=dpdk.org 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=2BkKAhs7b/8lipODGG7K1J3DfeQvWPPRVEmyReRNXOg=; b=DN+JelA9nmjA4l95jzPCFdhxOay4rnjH9bcuViXcNBGhO4Jzu37bO1F3Z5uSBRJ3tm4oElQfo/0aPdlo5aCXFT5qHkwE/xxgeEbu8MG4UrFVgIz+4M3Kdkul7IifUuaPlQS+q/AmES7UEYMQUhwB5DeqRAHJ/WgTwLhPjxb7OpffwivHk53cKOagp/XiIZMGCi2AvOWkI+MQ8WIYNWG9iZSbHVM/+sOYqUoEz8+e5kipZ5ps1AQviAPMTXFLknFs+8idIujssQo0jk9QeZ+mzYajr+6FS1M8+mhxgVf8yJRsJNkEzyTFsukbxWsaHbaaAcn3k33CUz7/Umu9Rj1xXQ== Received: from BL1PR13CA0104.namprd13.prod.outlook.com (2603:10b6:208:2b9::19) by DM4PR12MB5135.namprd12.prod.outlook.com (2603:10b6:5:392::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.26; Sun, 29 Oct 2023 16:33:53 +0000 Received: from BL02EPF0001A0FF.namprd03.prod.outlook.com (2603:10b6:208:2b9:cafe::db) by BL1PR13CA0104.outlook.office365.com (2603:10b6:208:2b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.15 via Frontend Transport; Sun, 29 Oct 2023 16:33:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF0001A0FF.mail.protection.outlook.com (10.167.242.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.15 via Frontend Transport; Sun, 29 Oct 2023 16:33:53 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 29 Oct 2023 09:33:45 -0700 Received: from nvidia.com (10.126.231.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.986.41; Sun, 29 Oct 2023 09:33:42 -0700 From: Gregory Etelson To: CC: , , , Rongwei Liu , Alex Vesker , Ori Kam , Matan Azrad , Viacheslav Ovsiienko , Suanming Mou Subject: [PATCH 27/30] net/mlx5/hws: add IPv6 routing extension push remove actions Date: Sun, 29 Oct 2023 18:31:59 +0200 Message-ID: <20231029163202.216450-27-getelson@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231029163202.216450-1-getelson@nvidia.com> References: <20231029163202.216450-1-getelson@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.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: BL02EPF0001A0FF:EE_|DM4PR12MB5135:EE_ X-MS-Office365-Filtering-Correlation-Id: 02cc05f7-93ef-400c-3024-08dbd89cd6d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RNgoI7Kz2oPK633SBJ/2hf8RGn/A6VlnMj9ZFp3Amfat8auHLdkH+HnYIuzTpLRrco8xKBVkTiJKtqGxQF8v3tJt3k3/Zw33A6li2qjtYeKJpA5C8eBMo0B44VqFKR4PvQSNRkxsF228U1bMVjdmQN34HXjWk3owUYqwznANqI1ak9U7rw62UTaPvBBKNVHePhVSccY5xhJCWkCqlF9jwtBgjuHy7bcrflocQF3KUP44zZ05iB6cAy4MSY+ZT6gU1AFEL8Vq7WZ8MPk1Xk5cRGHSVWySEGB37a2JwxSLrAaMrOZtVvRg7EG1MuJYfD9Ni4q0bTF3Z9MI7d4KZdmcIdQ8+s3BEXqyFgCkiNZV9jU2JEkOn1USaQimlzMK2BWPEPNFgyqUdgguaiyy2fOlAb54hmOssVaOYhZBTNxmrnuJH7pR5oj/FwjdOOrtskVF4TwFLPQrB8KsdusgOa2RkHECq5MME9ozNe55lDG3oX8rL1zhIjKh/RR1E61zftdDnkFWdlJTbJ1UlELseQ1qftc3Y486kenmGmJvIBNtgyUnpuAIw26OqOZTmna01A2GVFj+7ejfLoz3T8fwxt94VaBTvzXAgm3RU0adSziyzTutKLIqAmTyq1DhCUk2HUZK5Jsk9xNcy8IZANIW/1R7wzp8MZyPUmyj6RCtapqleHLZ4BES0SUeYbNWfK/v+t1W9hsE0P6GFyvkT6dgepsPiWsF8AiRykiGybKSpRnMRgjf68jywzHXKQ3SC+ZUJFb2 X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(346002)(39860400002)(376002)(396003)(136003)(230922051799003)(1800799009)(186009)(82310400011)(64100799003)(451199024)(40470700004)(46966006)(36840700001)(7696005)(6666004)(478600001)(83380400001)(30864003)(6286002)(47076005)(26005)(16526019)(2616005)(107886003)(1076003)(336012)(426003)(2906002)(5660300002)(54906003)(41300700001)(6916009)(70586007)(316002)(70206006)(8936002)(8676002)(4326008)(36860700001)(86362001)(36756003)(356005)(7636003)(82740400003)(40460700003)(40480700001)(55016003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2023 16:33:53.0866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02cc05f7-93ef-400c-3024-08dbd89cd6d0 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0FF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5135 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: Rongwei Liu Add two dr_actions to implement IPv6 routing extension push and remove, the new actions are multiple actions combination instead of new types. Basically, there are two modify headers plus one reformat action. Action order is the same as encap and decap actions. Signed-off-by: Rongwei Liu Reviewed-by: Alex Vesker Acked-by: Ori Kam --- drivers/common/mlx5/mlx5_prm.h | 1 + drivers/net/mlx5/hws/mlx5dr.h | 29 +++ drivers/net/mlx5/hws/mlx5dr_action.c | 358 ++++++++++++++++++++++++++- drivers/net/mlx5/hws/mlx5dr_action.h | 7 + drivers/net/mlx5/hws/mlx5dr_debug.c | 2 + drivers/net/mlx5/mlx5_flow.h | 44 ++++ 6 files changed, 438 insertions(+), 3 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index a5ecce98e9..32ec3df7ef 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -3586,6 +3586,7 @@ enum mlx5_ifc_header_anchors { MLX5_HEADER_ANCHOR_PACKET_START = 0x0, MLX5_HEADER_ANCHOR_FIRST_VLAN_START = 0x2, MLX5_HEADER_ANCHOR_IPV6_IPV4 = 0x07, + MLX5_HEADER_ANCHOR_TCP_UDP = 0x09, MLX5_HEADER_ANCHOR_INNER_MAC = 0x13, MLX5_HEADER_ANCHOR_INNER_IPV6_IPV4 = 0x19, }; diff --git a/drivers/net/mlx5/hws/mlx5dr.h b/drivers/net/mlx5/hws/mlx5dr.h index 2e692f76c3..9e7dd9c429 100644 --- a/drivers/net/mlx5/hws/mlx5dr.h +++ b/drivers/net/mlx5/hws/mlx5dr.h @@ -54,6 +54,8 @@ enum mlx5dr_action_type { MLX5DR_ACTION_TYP_REMOVE_HEADER, MLX5DR_ACTION_TYP_DEST_ROOT, MLX5DR_ACTION_TYP_DEST_ARRAY, + MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT, + MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT, MLX5DR_ACTION_TYP_MAX, }; @@ -278,6 +280,11 @@ struct mlx5dr_rule_action { uint8_t *data; } reformat; + struct { + uint32_t offset; + uint8_t *header; + } ipv6_ext; + struct { rte_be32_t vlan_hdr; } push_vlan; @@ -889,6 +896,28 @@ mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx, struct mlx5dr_action_remove_header_attr *attr, uint32_t flags); +/* Create action to push or remove IPv6 extension header. + * + * @param[in] ctx + * The context in which the new action will be created. + * @param[in] type + * Type of direct rule action: MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT or + * MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT. + * @param[in] hdr + * Header for packet reformat. + * @param[in] log_bulk_size + * Number of unique values used with this pattern. + * @param[in] flags + * Action creation flags. (enum mlx5dr_action_flags) + * @return pointer to mlx5dr_action on success NULL otherwise. + */ +struct mlx5dr_action * +mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx, + enum mlx5dr_action_type type, + struct mlx5dr_action_reformat_header *hdr, + uint32_t log_bulk_size, + uint32_t flags); + /* Destroy direct rule action. * * @param[in] action diff --git a/drivers/net/mlx5/hws/mlx5dr_action.c b/drivers/net/mlx5/hws/mlx5dr_action.c index 76ca57d302..6ac3c2f782 100644 --- a/drivers/net/mlx5/hws/mlx5dr_action.c +++ b/drivers/net/mlx5/hws/mlx5dr_action.c @@ -26,7 +26,8 @@ static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_ BIT(MLX5DR_ACTION_TYP_REFORMAT_TRAILER), BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) | BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) | - BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2), + BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) | + BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT), BIT(MLX5DR_ACTION_TYP_POP_VLAN), BIT(MLX5DR_ACTION_TYP_POP_VLAN), BIT(MLX5DR_ACTION_TYP_CTR), @@ -39,6 +40,7 @@ static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_ BIT(MLX5DR_ACTION_TYP_PUSH_VLAN), BIT(MLX5DR_ACTION_TYP_MODIFY_HDR), BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) | + BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3), BIT(MLX5DR_ACTION_TYP_TBL) | @@ -61,6 +63,7 @@ static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_ BIT(MLX5DR_ACTION_TYP_PUSH_VLAN), BIT(MLX5DR_ACTION_TYP_MODIFY_HDR), BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) | + BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3), BIT(MLX5DR_ACTION_TYP_REFORMAT_TRAILER), @@ -75,7 +78,8 @@ static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_ BIT(MLX5DR_ACTION_TYP_REFORMAT_TRAILER), BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) | BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) | - BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2), + BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) | + BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT), BIT(MLX5DR_ACTION_TYP_POP_VLAN), BIT(MLX5DR_ACTION_TYP_POP_VLAN), BIT(MLX5DR_ACTION_TYP_CTR), @@ -88,6 +92,7 @@ static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_ BIT(MLX5DR_ACTION_TYP_PUSH_VLAN), BIT(MLX5DR_ACTION_TYP_MODIFY_HDR), BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) | + BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) | BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3), BIT(MLX5DR_ACTION_TYP_REFORMAT_TRAILER), @@ -1710,7 +1715,7 @@ mlx5dr_action_create_reformat(struct mlx5dr_context *ctx, if (!mlx5dr_action_is_hws_flags(flags) || ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) { - DR_LOG(ERR, "Reformat flags don't fit HWS (flags: %x0x)", flags); + DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags); rte_errno = EINVAL; goto free_action; } @@ -2382,6 +2387,347 @@ mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx, return NULL; } +static void * +mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(struct mlx5dr_action *action) +{ + struct mlx5dr_action_mh_pattern pattern; + __be64 cmd[3] = {0}; + uint16_t mod_id; + + mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0); + if (!mod_id) { + rte_errno = EINVAL; + return NULL; + } + + /* + * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left. + * Next_hdr will be copied to ipv6.protocol after pop done. + */ + MLX5_SET(copy_action_in, &cmd[0], action_type, MLX5_MODIFICATION_TYPE_COPY); + MLX5_SET(copy_action_in, &cmd[0], length, 8); + MLX5_SET(copy_action_in, &cmd[0], src_offset, 24); + MLX5_SET(copy_action_in, &cmd[0], src_field, mod_id); + MLX5_SET(copy_action_in, &cmd[0], dst_field, mod_id); + + /* Add nop between the continuous same modify field id */ + MLX5_SET(copy_action_in, &cmd[1], action_type, MLX5_MODIFICATION_TYPE_NOP); + + /* Clear next_hdr for right checksum */ + MLX5_SET(set_action_in, &cmd[2], action_type, MLX5_MODIFICATION_TYPE_SET); + MLX5_SET(set_action_in, &cmd[2], length, 8); + MLX5_SET(set_action_in, &cmd[2], offset, 24); + MLX5_SET(set_action_in, &cmd[2], field, mod_id); + + pattern.data = cmd; + pattern.sz = sizeof(cmd); + + return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, + 0, action->flags); +} + +static void * +mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(struct mlx5dr_action *action) +{ + enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = { + MLX5_MODI_OUT_DIPV6_127_96, + MLX5_MODI_OUT_DIPV6_95_64, + MLX5_MODI_OUT_DIPV6_63_32, + MLX5_MODI_OUT_DIPV6_31_0 + }; + struct mlx5dr_action_mh_pattern pattern; + __be64 cmd[5] = {0}; + uint16_t mod_id; + uint32_t i; + + /* Copy ipv6_route_ext[first_segment].dst_addr by flex parser to ipv6.dst_addr */ + for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) { + mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, i + 1); + if (!mod_id) { + rte_errno = EINVAL; + return NULL; + } + + MLX5_SET(copy_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_COPY); + MLX5_SET(copy_action_in, &cmd[i], dst_field, field[i]); + MLX5_SET(copy_action_in, &cmd[i], src_field, mod_id); + } + + mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0); + if (!mod_id) { + rte_errno = EINVAL; + return NULL; + } + + /* Restore next_hdr from seg_left for flex parser identifying */ + MLX5_SET(copy_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_COPY); + MLX5_SET(copy_action_in, &cmd[4], length, 8); + MLX5_SET(copy_action_in, &cmd[4], dst_offset, 24); + MLX5_SET(copy_action_in, &cmd[4], src_field, mod_id); + MLX5_SET(copy_action_in, &cmd[4], dst_field, mod_id); + + pattern.data = cmd; + pattern.sz = sizeof(cmd); + + return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, + 0, action->flags); +} + +static void * +mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(struct mlx5dr_action *action) +{ + uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0}; + struct mlx5dr_action_mh_pattern pattern; + uint16_t mod_id; + + mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0); + if (!mod_id) { + rte_errno = EINVAL; + return NULL; + } + + /* Copy ipv6_route_ext.next_hdr to ipv6.protocol */ + MLX5_SET(copy_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_COPY); + MLX5_SET(copy_action_in, cmd, length, 8); + MLX5_SET(copy_action_in, cmd, src_offset, 24); + MLX5_SET(copy_action_in, cmd, src_field, mod_id); + MLX5_SET(copy_action_in, cmd, dst_field, MLX5_MODI_OUT_IPV6_NEXT_HDR); + + pattern.data = (__be64 *)cmd; + pattern.sz = sizeof(cmd); + + return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, + 0, action->flags); +} + +static int +mlx5dr_action_create_pop_ipv6_route_ext(struct mlx5dr_action *action) +{ + uint8_t anchor_id = flow_hw_get_ipv6_route_ext_anchor_from_ctx(action->ctx); + struct mlx5dr_action_remove_header_attr hdr_attr; + uint32_t i; + + if (!anchor_id) { + rte_errno = EINVAL; + return rte_errno; + } + + action->ipv6_route_ext.action[0] = + mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(action); + action->ipv6_route_ext.action[1] = + mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(action); + action->ipv6_route_ext.action[2] = + mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(action); + + hdr_attr.by_anchor.decap = 1; + hdr_attr.by_anchor.start_anchor = anchor_id; + hdr_attr.by_anchor.end_anchor = MLX5_HEADER_ANCHOR_TCP_UDP; + hdr_attr.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER; + action->ipv6_route_ext.action[3] = + mlx5dr_action_create_remove_header(action->ctx, &hdr_attr, action->flags); + + if (!action->ipv6_route_ext.action[0] || !action->ipv6_route_ext.action[1] || + !action->ipv6_route_ext.action[2] || !action->ipv6_route_ext.action[3]) { + DR_LOG(ERR, "Failed to create ipv6_route_ext pop subaction"); + goto err; + } + + return 0; + +err: + for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++) + if (action->ipv6_route_ext.action[i]) + mlx5dr_action_destroy(action->ipv6_route_ext.action[i]); + + return rte_errno; +} + +static void * +mlx5dr_action_create_push_ipv6_route_ext_mhdr1(struct mlx5dr_action *action) +{ + uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0}; + struct mlx5dr_action_mh_pattern pattern; + + /* Set ipv6.protocol to IPPROTO_ROUTING */ + MLX5_SET(set_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_SET); + MLX5_SET(set_action_in, cmd, length, 8); + MLX5_SET(set_action_in, cmd, field, MLX5_MODI_OUT_IPV6_NEXT_HDR); + MLX5_SET(set_action_in, cmd, data, IPPROTO_ROUTING); + + pattern.data = (__be64 *)cmd; + pattern.sz = sizeof(cmd); + + return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, 0, + action->flags | MLX5DR_ACTION_FLAG_SHARED); +} + +static void * +mlx5dr_action_create_push_ipv6_route_ext_mhdr2(struct mlx5dr_action *action, + uint32_t bulk_size, + uint8_t *data) +{ + enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = { + MLX5_MODI_OUT_DIPV6_127_96, + MLX5_MODI_OUT_DIPV6_95_64, + MLX5_MODI_OUT_DIPV6_63_32, + MLX5_MODI_OUT_DIPV6_31_0 + }; + struct mlx5dr_action_mh_pattern pattern; + uint32_t *ipv6_dst_addr = NULL; + uint8_t seg_left, next_hdr; + __be64 cmd[5] = {0}; + uint16_t mod_id; + uint32_t i; + + /* Fetch the last IPv6 address in the segment list */ + if (action->flags & MLX5DR_ACTION_FLAG_SHARED) { + seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1; + ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext) + + seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr); + } + + /* Copy IPv6 destination address from ipv6_route_ext.last_segment */ + for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) { + MLX5_SET(set_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_SET); + MLX5_SET(set_action_in, &cmd[i], field, field[i]); + if (action->flags & MLX5DR_ACTION_FLAG_SHARED) + MLX5_SET(set_action_in, &cmd[i], data, be32toh(*ipv6_dst_addr++)); + } + + mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0); + if (!mod_id) { + rte_errno = EINVAL; + return NULL; + } + + /* Set ipv6_route_ext.next_hdr since initially pushed as 0 for right checksum */ + MLX5_SET(set_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_SET); + MLX5_SET(set_action_in, &cmd[4], length, 8); + MLX5_SET(set_action_in, &cmd[4], offset, 24); + MLX5_SET(set_action_in, &cmd[4], field, mod_id); + if (action->flags & MLX5DR_ACTION_FLAG_SHARED) { + next_hdr = MLX5_GET(header_ipv6_routing_ext, data, next_hdr); + MLX5_SET(set_action_in, &cmd[4], data, next_hdr); + } + + pattern.data = cmd; + pattern.sz = sizeof(cmd); + + return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, + bulk_size, action->flags); +} + +static int +mlx5dr_action_create_push_ipv6_route_ext(struct mlx5dr_action *action, + struct mlx5dr_action_reformat_header *hdr, + uint32_t bulk_size) +{ + struct mlx5dr_action_insert_header insert_hdr = { {0} }; + uint8_t header[MLX5_PUSH_MAX_LEN]; + uint32_t i; + + if (!hdr || !hdr->sz || hdr->sz > MLX5_PUSH_MAX_LEN || + ((action->flags & MLX5DR_ACTION_FLAG_SHARED) && !hdr->data)) { + DR_LOG(ERR, "Invalid ipv6_route_ext header"); + rte_errno = EINVAL; + return rte_errno; + } + + if (action->flags & MLX5DR_ACTION_FLAG_SHARED) { + memcpy(header, hdr->data, hdr->sz); + /* Clear ipv6_route_ext.next_hdr for right checksum */ + MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0); + } + + insert_hdr.anchor = MLX5_HEADER_ANCHOR_TCP_UDP; + insert_hdr.encap = 1; + insert_hdr.hdr.sz = hdr->sz; + insert_hdr.hdr.data = header; + action->ipv6_route_ext.action[0] = + mlx5dr_action_create_insert_header(action->ctx, 1, &insert_hdr, + bulk_size, action->flags); + action->ipv6_route_ext.action[1] = + mlx5dr_action_create_push_ipv6_route_ext_mhdr1(action); + action->ipv6_route_ext.action[2] = + mlx5dr_action_create_push_ipv6_route_ext_mhdr2(action, bulk_size, hdr->data); + + if (!action->ipv6_route_ext.action[0] || + !action->ipv6_route_ext.action[1] || + !action->ipv6_route_ext.action[2]) { + DR_LOG(ERR, "Failed to create ipv6_route_ext push subaction"); + goto err; + } + + return 0; + +err: + for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++) + if (action->ipv6_route_ext.action[i]) + mlx5dr_action_destroy(action->ipv6_route_ext.action[i]); + + return rte_errno; +} + +struct mlx5dr_action * +mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx, + enum mlx5dr_action_type action_type, + struct mlx5dr_action_reformat_header *hdr, + uint32_t log_bulk_size, + uint32_t flags) +{ + struct mlx5dr_action *action; + int ret; + + if (mlx5dr_context_cap_dynamic_reparse(ctx)) { + DR_LOG(ERR, "IPv6 extension actions is not supported"); + rte_errno = ENOTSUP; + return NULL; + } + + if (!mlx5dr_action_is_hws_flags(flags) || + ((flags & MLX5DR_ACTION_FLAG_SHARED) && log_bulk_size)) { + DR_LOG(ERR, "IPv6 extension flags don't fit HWS (flags: 0x%x)", flags); + rte_errno = EINVAL; + return NULL; + } + + action = mlx5dr_action_create_generic(ctx, flags, action_type); + if (!action) { + rte_errno = ENOMEM; + return NULL; + } + + switch (action_type) { + case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT: + if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) { + DR_LOG(ERR, "Pop ipv6_route_ext must be shared"); + rte_errno = EINVAL; + goto free_action; + } + + ret = mlx5dr_action_create_pop_ipv6_route_ext(action); + break; + case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT: + ret = mlx5dr_action_create_push_ipv6_route_ext(action, hdr, log_bulk_size); + break; + default: + DR_LOG(ERR, "Unsupported action type %d\n", action_type); + rte_errno = ENOTSUP; + goto free_action; + } + + if (ret) { + DR_LOG(ERR, "Failed to create IPv6 extension reformat action"); + goto free_action; + } + + return action; + +free_action: + simple_free(action); + return NULL; +} + static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action) { struct mlx5dr_devx_obj *obj = NULL; @@ -2455,6 +2801,12 @@ static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action) mlx5dr_action_destroy_stcs(&action[i]); mlx5dr_cmd_destroy_obj(action->reformat.arg_obj); break; + case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT: + case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT: + for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++) + if (action->ipv6_route_ext.action[i]) + mlx5dr_action_destroy(action->ipv6_route_ext.action[i]); + break; } } diff --git a/drivers/net/mlx5/hws/mlx5dr_action.h b/drivers/net/mlx5/hws/mlx5dr_action.h index e56f5b59c7..d0152dde3b 100644 --- a/drivers/net/mlx5/hws/mlx5dr_action.h +++ b/drivers/net/mlx5/hws/mlx5dr_action.h @@ -8,6 +8,9 @@ /* Max number of STEs needed for a rule (including match) */ #define MLX5DR_ACTION_MAX_STE 10 +/* Max number of internal subactions of ipv6_ext */ +#define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4 + enum mlx5dr_action_stc_idx { MLX5DR_ACTION_STC_IDX_CTRL = 0, MLX5DR_ACTION_STC_IDX_HIT = 1, @@ -143,6 +146,10 @@ struct mlx5dr_action { uint8_t offset; bool encap; } reformat; + struct { + struct mlx5dr_action + *action[MLX5DR_ACTION_IPV6_EXT_MAX_SA]; + } ipv6_route_ext; struct { struct mlx5dr_devx_obj *devx_obj; uint8_t return_reg_id; diff --git a/drivers/net/mlx5/hws/mlx5dr_debug.c b/drivers/net/mlx5/hws/mlx5dr_debug.c index 5111f41648..1e5ef9cf67 100644 --- a/drivers/net/mlx5/hws/mlx5dr_debug.c +++ b/drivers/net/mlx5/hws/mlx5dr_debug.c @@ -31,6 +31,8 @@ const char *mlx5dr_debug_action_type_str[] = { [MLX5DR_ACTION_TYP_CRYPTO_DECRYPT] = "CRYPTO_DECRYPT", [MLX5DR_ACTION_TYP_INSERT_HEADER] = "INSERT_HEADER", [MLX5DR_ACTION_TYP_REMOVE_HEADER] = "REMOVE_HEADER", + [MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT] = "POP_IPV6_ROUTE_EXT", + [MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT] = "PUSH_IPV6_ROUTE_EXT", }; static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX, diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index ddb3b7b6fd..8174c03d50 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -589,6 +589,7 @@ struct mlx5_flow_dv_matcher { struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */ }; +#define MLX5_PUSH_MAX_LEN 128 #define MLX5_ENCAP_MAX_LEN 132 /* Encap/decap resource structure. */ @@ -2872,6 +2873,49 @@ flow_hw_get_srh_flex_parser_byte_off_from_ctx(void *dr_ctx __rte_unused) #endif return UINT32_MAX; } + +static __rte_always_inline uint8_t +flow_hw_get_ipv6_route_ext_anchor_from_ctx(void *dr_ctx) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + uint16_t port; + struct mlx5_priv *priv; + + MLX5_ETH_FOREACH_DEV(port, NULL) { + priv = rte_eth_devices[port].data->dev_private; + if (priv->dr_ctx == dr_ctx) + return priv->sh->srh_flex_parser.flex.devx_fp->anchor_id; + } +#else + RTE_SET_USED(dr_ctx); +#endif + return 0; +} + +static __rte_always_inline uint16_t +flow_hw_get_ipv6_route_ext_mod_id_from_ctx(void *dr_ctx, uint8_t idx) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + uint16_t port; + struct mlx5_priv *priv; + struct mlx5_flex_parser_devx *fp; + + if (idx >= MLX5_GRAPH_NODE_SAMPLE_NUM || idx >= MLX5_SRV6_SAMPLE_NUM) + return 0; + MLX5_ETH_FOREACH_DEV(port, NULL) { + priv = rte_eth_devices[port].data->dev_private; + if (priv->dr_ctx == dr_ctx) { + fp = priv->sh->srh_flex_parser.flex.devx_fp; + return fp->sample_info[idx].modify_field_id; + } + } +#else + RTE_SET_USED(dr_ctx); + RTE_SET_USED(idx); +#endif + return 0; +} + void mlx5_indirect_list_handles_release(struct rte_eth_dev *dev); void -- 2.39.2