From patchwork Sun Feb 6 15:36:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12736593 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D60D7C433EF for ; Sun, 6 Feb 2022 15:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239002AbiBFPh3 (ORCPT ); Sun, 6 Feb 2022 10:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242568AbiBFPhZ (ORCPT ); Sun, 6 Feb 2022 10:37:25 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A041CC06173B for ; Sun, 6 Feb 2022 07:37:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EmCab49sD1fnabpMq1wxlavBKMdhFDFSAr+ksQcOkwy98Ne0G1JMFWr2xQM4lUX2HBLUzIOgQ98q2E89kBbLGcF/M9hkWXH6ZpRrwy0TFQz2jCbj9nJ+cH/6bqykMnHydi0bssYMLIfrTlpdKL/FAS3RwyE04vPg2nMe0ID7M6SCLgOBrdj9OlaV6yrBpUsttXYA5VzK0UXbEomKbaFd5qxZbQn+dPshermyNWFmjdidHTSe0VFQqTJz9T1/s3Rk2cX932GAjhKEiOUdN01SXSLFbfFeW0i1DRk2Kc/m3FnGcAPMydITncSis2uJHgBxwdNi0m1FBpR7y/xixUXwkQ== 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=EhFZnaA0UcRkVu/aROFGmCXMJ3mwDyeA1oV8ELcRXNg=; b=OhGgIoI4FFxQJ7QFHxCHDJtdfQJ54xHoIiUoyi8hwLKDJUA1LwPD6QRwHuJm6jrkgGlPuHmNsc8awUBgVfFFonTUjfwJ67ACh4TI/imX/TDcS8wwrRve4wDPJ0dTmAedF5mUYttr0vycCk4oyFYyViJAVoqZl8DFfFtLOCoLBrZDJnyZLv5HDtDX5cO9de2bSyCGkvgYSrina5/YQQVg5VkG+5ZBM+uK3Av2B/SpNCGrKnFLAr1YyETicYRxqBREDC7JzY81q8GTgCUNGPtsIlE484OMomDUNAhdtoOCbWl4sYXeTCo8toVnkfUXSE6vFcMZgzuFGYgUCeJFM0L3ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=EhFZnaA0UcRkVu/aROFGmCXMJ3mwDyeA1oV8ELcRXNg=; b=ivHtCAn1ILq7d0xV4Vg8KURlsG5zI9dSaoTYwDVDzV9P+KBZkESdGXRepoBZahNV2GPWZ5+AqZyMEoUT4CpfvRY4N/871ocRDgkIS2cJD8FwPBB5rvaCp9dLZS3dmc8kVxpZc8SoeuSV5BmDgaF/jMWJowJ7Xg3jGx0ye0mDfDSCTh2vR6+G72PhB6IP6ihuiXsuZmPVqJCAQryN61fakhOiMoUqNiOGvhQ02lE1U6e4F7pMlMJu7xdQkjA/05LJ1McQrTwaSXfgpshaUYey+LcqV6rFftVKdzdnQNIfSpsKd2R2YhwsN14F02TGN59lMqBwV6qZO7OzmpNKTnWnbQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BN8PR12MB3395.namprd12.prod.outlook.com (2603:10b6:408:43::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Sun, 6 Feb 2022 15:37:23 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::5cff:a12b:dfa4:3eff]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::5cff:a12b:dfa4:3eff%3]) with mapi id 15.20.4951.018; Sun, 6 Feb 2022 15:37:23 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 2/4] mlxsw: Support FLOW_ACTION_MANGLE for SIP and DIP IPv4 addresses Date: Sun, 6 Feb 2022 17:36:11 +0200 Message-Id: <20220206153613.763944-3-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220206153613.763944-1-idosch@nvidia.com> References: <20220206153613.763944-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P195CA0072.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::25) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1edae700-e1a0-42aa-28bd-08d9e98691b6 X-MS-TrafficTypeDiagnostic: BN8PR12MB3395:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4DRQjjNLqif4dDcChZ/6cy6olawPIW9FW7f7X/PuzkRlG+seiP+hkCtBALGJRTjrIit3qNbgjaOPE4k9Xg97HMl/B96jMmpY4ltOI0pbODkEP+tkS4Hpun3hHLrHTo9Onj0CoVhiC6tRl9W6U2hVWgXrAlBrGCtKQQGYwowHKcs6gsvrX1voiSSzYu7dZdwbtpNsVfUhXivzf2sTEXqF9zgJs32cF6n+sln/MbjEr4J4hnVaA8ElXFTODedQZuKEPyiHeTqT9x2D+ak4XF7fioRsXvq7L7v8JNrTF7ZhNA4nffJWAxkeh11lSSun4v0KY26sDa8DG5NOh53PekCHuEcHThOngdJ/piyhzAE2mJVp6l20+9wYHf2j+1JDY0M70QeMPDDcCnZdftDFqiQuiZKrSGG5OYv96Jp6kQJbdx+qzTGTrJWllXK/QnqAlswAGlc5dUauyzEhxndV7ubGosHUkt4YGa9A3ZUIhhPYmma9RPsXr3Ihp3esMDUYedgXrRUinsYp22QTcxi86ri56Qzy4jLJW91mItryqqVD7LDggjtBlP/8MUSgEZgkj7J5pBTI4gi2k5/1997BWNpntaY1cK2fVitS04icIKRoSrEykZEBCpz8BGvE6bdVWcHhFIw4s95q4lYtFuMDN+LMzQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6486002)(26005)(186003)(83380400001)(6506007)(6666004)(6512007)(5660300002)(6916009)(316002)(36756003)(8676002)(4326008)(2906002)(66556008)(66476007)(86362001)(8936002)(66946007)(508600001)(107886003)(1076003)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3HVuKdxTYGdl0VhjO/pdYKzt0kHT8txpM8osbxgnHp03QLYfceVp5KMrBfT0aVc+ToVtriNpnKtjMh+Smj7ncLlgL6H/v3smLobxd8tm6TsptP+NqHMY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/pgkumBEuggQpO/NI8/fp0jwORcVHl3OtPUnEvqI6lxgSF7JGC8/jvKxVdDkImamzJ09p8Ah2MOo3kuOMGZEX7l0iIWLCOKmCZR7a8kzs7bj0u+Vg6JSWNKBxyaf4t5WEr8Gf+085HemNqztZRJK5lmXvLOTe7TeARXMiWUUaLj05psLmYlgu5aQbuxi0PCVtOqyHNKjz5srxzonRnEUjqGh2EavTRu4ztRYTq9v5O3mkRo28wqBByuy7Tlc6sbY8mfd4tfZTjk837xe9KiP+nNnRcF2+oegsldnXwjWcTtJc6U5fCYZfWcXRFNDEJ9oxOqlAG+Q02OEyJuwScrWFL5ti0eOLTCF8V6fxcAZ6IWzR5Swya7PaMM/zoVEHCy6ejFkdrNUf5Tjo5BifwVPvrisyTGObwrGnVNUwMpnZYoHXcPGC0zSJAr3Vw0QetWRC5N/o= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1edae700-e1a0-42aa-28bd-08d9e98691b6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2022 15:37:23.0721 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LQhqHcfv0umiepVtMM/OAEIcaeaXYYjnrbL6Z4NdcLYEUdfzplDT3T29cuFpGp0klTrZmYmJiMR1/pCYQADkxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3395 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Danielle Ratson Spectrum-2 supports an ACL action SIP_DIP, which allows IPv4 and IPv6 source and destination addresses change. Offload suitable mangles to the IPv4 address change action. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/core_acl_flex_actions.c | 32 +++++++++++++++++++ .../mellanox/mlxsw/core_acl_flex_actions.h | 3 ++ .../ethernet/mellanox/mlxsw/spectrum_acl.c | 12 +++++++ 3 files changed, 47 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index b6fe26ee488b..fa33caecc91d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c @@ -2002,6 +2002,38 @@ MLXSW_ITEM32(afa, ip, ip_63_32, 0x08, 0, 32); */ MLXSW_ITEM32(afa, ip, ip_31_0, 0x0C, 0, 32); +static void mlxsw_afa_ip_pack(char *payload, enum mlxsw_afa_ip_s_d s_d, + enum mlxsw_afa_ip_m_l m_l, u32 ip_31_0, + u32 ip_63_32) +{ + mlxsw_afa_ip_s_d_set(payload, s_d); + mlxsw_afa_ip_m_l_set(payload, m_l); + mlxsw_afa_ip_ip_31_0_set(payload, ip_31_0); + mlxsw_afa_ip_ip_63_32_set(payload, ip_63_32); +} + +int mlxsw_afa_block_append_ip(struct mlxsw_afa_block *block, bool is_dip, + bool is_lsb, u32 val_31_0, u32 val_63_32, + struct netlink_ext_ack *extack) +{ + enum mlxsw_afa_ip_s_d s_d = is_dip ? MLXSW_AFA_IP_S_D_DIP : + MLXSW_AFA_IP_S_D_SIP; + enum mlxsw_afa_ip_m_l m_l = is_lsb ? MLXSW_AFA_IP_M_L_LSB : + MLXSW_AFA_IP_M_L_MSB; + char *act = mlxsw_afa_block_append_action(block, + MLXSW_AFA_IP_CODE, + MLXSW_AFA_IP_SIZE); + + if (IS_ERR(act)) { + NL_SET_ERR_MSG_MOD(extack, "Cannot append IP action"); + return PTR_ERR(act); + } + + mlxsw_afa_ip_pack(act, s_d, m_l, val_31_0, val_63_32); + return 0; +} +EXPORT_SYMBOL(mlxsw_afa_block_append_ip); + /* L4 Port Action * -------------- * The L4_PORT_ACTION is used for modifying the sport and dport fields of the packet, e.g. for NAT. diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h index 16cbd6acbb01..db58037be46e 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h @@ -92,6 +92,9 @@ int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid, int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block, u16 expected_irif, u16 min_mtu, bool rmid_valid, u32 kvdl_index); +int mlxsw_afa_block_append_ip(struct mlxsw_afa_block *block, bool is_dip, + bool is_lsb, u32 val_31_0, u32 val_63_32, + struct netlink_ext_ack *extack); int mlxsw_afa_block_append_l4port(struct mlxsw_afa_block *block, bool is_dport, u16 l4_port, struct netlink_ext_ack *extack); int mlxsw_afa_block_append_police(struct mlxsw_afa_block *block, diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c index 70c11bfac08f..6e43a6ba09bd 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c @@ -511,6 +511,8 @@ enum mlxsw_sp_acl_mangle_field { MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN, MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT, MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT, + MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP, + MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP, }; struct mlxsw_sp_acl_mangle_action { @@ -561,6 +563,9 @@ static struct mlxsw_sp_acl_mangle_action mlxsw_sp_acl_mangle_actions[] = { MLXSW_SP_ACL_MANGLE_ACTION_UDP(0, 0x0000ffff, 16, IP_SPORT), MLXSW_SP_ACL_MANGLE_ACTION_UDP(0, 0xffff0000, 0, IP_DPORT), + + MLXSW_SP_ACL_MANGLE_ACTION_IP4(12, 0x00000000, 0, IP4_SIP), + MLXSW_SP_ACL_MANGLE_ACTION_IP4(16, 0x00000000, 0, IP4_DIP), }; static int @@ -615,6 +620,13 @@ static int mlxsw_sp2_acl_rulei_act_mangle_field(struct mlxsw_sp *mlxsw_sp, return mlxsw_afa_block_append_l4port(rulei->act_block, false, val, extack); case MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT: return mlxsw_afa_block_append_l4port(rulei->act_block, true, val, extack); + /* IPv4 fields */ + case MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP: + return mlxsw_afa_block_append_ip(rulei->act_block, false, + true, val, 0, extack); + case MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP: + return mlxsw_afa_block_append_ip(rulei->act_block, true, + true, val, 0, extack); default: break; }