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 E1E9643251; Tue, 31 Oct 2023 10:43:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C36DE406BA; Tue, 31 Oct 2023 10:43:27 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2053.outbound.protection.outlook.com [40.107.94.53]) by mails.dpdk.org (Postfix) with ESMTP id 098DD406B6 for ; Tue, 31 Oct 2023 10:43:26 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sid9WPoZUkpiCTvGvhjqylNpJ72Y4KSnDTLgpAtq6bi9ZON8bUxLaqqmAj1gRJBiD8gI3LMNN/RfIBRi+XlmDq/csqvGFv6/mHdnPEVTEOhZd6w9Rm7RADj8WHkkL0CMFPN9IsWTmWkcC2Na+B+WDdixP2slF4KCOXGehVu9RwCfb8tk9xp81AdGUEIhD76XsljZUwgawwZx/JcaE1UIkOll0/U6bCGxBJJTMHxU21IFaUOJkKr7DyuT04VQ+axjB8Z+FPeOGjmlIIUE1o/Z19dPwbt+9TVMsHir3KS34CSBJpS99NGSJuKSKtmPbytujcUkCe9ZteE9uNSIyJsMYg== 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=qbL2gDJPnSvQDBZldTSourZTP4QimOkzHnWdS3vEo5o=; b=eEtKS5UCHaJnMwSRvzQgvLu2gTxjAjLLs8sdqURvU9NbHvv1ZS/AO8FxUaRJlXI+IUvgc6uMagvWVPQ06r0bwnOMmzoMa3aMOvlUmQvSy5gpqMe2bmxpKZawP/I0ZFL6uTI7tQW5RApYj4jWe+qUYCSYwi/21T840XfA9bVRKuuhfsQpNoUDP2YQFLdiFK80DQdPAeKkOv1xcQD0Jz54SjicoBIkSpymOH5v0xZ7BQdhxFkBCcb2p0PVGAA3uMmVfb2Gm5LNB8ImaDrzcih1+RFN8Q+j2fJbzx3Qic40Wfnd6CpA8f7Qe+98xx85Fzx6PhgGMYsdPmrqhgEhXeuWUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=qbL2gDJPnSvQDBZldTSourZTP4QimOkzHnWdS3vEo5o=; b=sa11l9jrzATQaHevAOigvGvqjs14svLyM47Wx+KkUDIEL2Il9cpSbXxplSRKn9Y3SHZgvP6Sq4D5W/K6ta+CaRakOL9JQH/W5SYzNiVXxgfZgRCmfjozlJ1TDBzOjv42uIw6ovVWjWY1R5j7q4Gfwh0ojX85OBbEOnVaiWo68b4aTew2qD6b0bpTWMcROnM1SvbMdoLDx4wcjpwGcOh9seN4WFEDADNkoOrueMziFCEuhK+P2s9rsqIEOH7kp4yjnwsqOn5+9J5XQ7ZfNTBYgXKCI6TLK6AKWVbjQGxplwQdahypq3xtn4KZIGk+TmNHda98yje19uy168VIMqO0eg== Received: from DS7PR03CA0255.namprd03.prod.outlook.com (2603:10b6:5:3b3::20) by IA1PR12MB6281.namprd12.prod.outlook.com (2603:10b6:208:3e7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 09:43:23 +0000 Received: from DS2PEPF00003446.namprd04.prod.outlook.com (2603:10b6:5:3b3:cafe::e6) by DS7PR03CA0255.outlook.office365.com (2603:10b6:5:3b3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Tue, 31 Oct 2023 09:43:23 +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 DS2PEPF00003446.mail.protection.outlook.com (10.167.17.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Tue, 31 Oct 2023 09:43:23 +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, 31 Oct 2023 02:43:07 -0700 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.986.41; Tue, 31 Oct 2023 02:43:04 -0700 From: Rongwei Liu To: , , , , , CC: Alex Vesker Subject: [PATCH v2 3/6] net/mlx5/hws: add IPv6 routing extension push remove actions Date: Tue, 31 Oct 2023 11:42:41 +0200 Message-ID: <20231031094244.381557-4-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231031094244.381557-1-rongweil@nvidia.com> References: <20230417092540.2617450-5-rongweil@nvidia.com> <20231031094244.381557-1-rongweil@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: DS2PEPF00003446:EE_|IA1PR12MB6281:EE_ X-MS-Office365-Filtering-Correlation-Id: 992391ad-1745-40cc-6811-08dbd9f5d301 X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nJ6k0jYjf6j1kIt38/pPLcVwekZwn0/dY+z3wdyOjnfS5oKArtCPPpLMRhjye2SR6VGmbjIY7dFvHmu9BaYdIMAz+cf6oqduhz+CKQEtQtrztcQFPGRv5DowSc/81lVzd4CRqnS0yewrtWYPPq7aGwVNIogS5gCKAGQvxJc6zjyKvwqJXJs5jlgDu0au6Yr1gun5OTAN01pghoFC8vnioWzMflRoMPk70WRVLgPiEiI2L45U0R19y9mFe9ChaKXlcSypixBW8+9kL3DDeOeNpyLe+4M8+v6rtUiZ/EK00opcEfjvDeWw7otFoJ86dr9azuLsct3+qRloEsFxpG7hDVtWAW4mQS8azP8E6V0KBZLdvZ6AJACADaSc8+SDRGJweVk+oLb4ynsaJXuT+9lSEZeRZkGphUarIHZQoQoXniTovJLZIn7Ny/7bsUNVP9KAncbRjy/WQbvDksX+Bts+mBCXYbV3tsJoGOPf374GV35R2iTegGopSm+BIO4Jf/Zp4Gof/8rrFf73PU/WLmf2G3X2xnIEpQA36AnNLVjhyZ18kM2tIqfWaXcKCcRV+iRl6+k1LW7CRwuKEF6pOdLWBT9JlXwMiisdCOQRRd4JLAP/cZKPIr6YMnLibymO+h8H7E+hjPEJKGA1sTQuhNsR7vLFDohFQeUA6WFLXd1jgEW67JdX37FNIAYQjjrAsH9TP5XbeqY3PPHvdnshqgNEpSs6JdSRYwzdJJszv6/28EKuBZYrmOeSaFAkqE5aniVO 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)(39860400002)(346002)(396003)(376002)(230922051799003)(64100799003)(1800799009)(82310400011)(451199024)(186009)(40470700004)(36840700001)(46966006)(30864003)(8676002)(8936002)(4326008)(5660300002)(83380400001)(70586007)(70206006)(110136005)(6666004)(478600001)(2906002)(316002)(41300700001)(7696005)(55016003)(26005)(40460700003)(2616005)(16526019)(107886003)(6286002)(1076003)(426003)(336012)(36860700001)(40480700001)(47076005)(82740400003)(36756003)(86362001)(356005)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 09:43:23.1950 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 992391ad-1745-40cc-6811-08dbd9f5d301 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: DS2PEPF00003446.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6281 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 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 e637c98b95..43608e15d2 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -595,6 +595,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. */ @@ -2898,6 +2899,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.27.0