From patchwork Tue Nov 1 11:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13026874 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 C629FFA373D for ; Tue, 1 Nov 2022 11:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229835AbiKALDX (ORCPT ); Tue, 1 Nov 2022 07:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbiKALDW (ORCPT ); Tue, 1 Nov 2022 07:03:22 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2106.outbound.protection.outlook.com [40.107.92.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5C52B01 for ; Tue, 1 Nov 2022 04:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=niXBrbq/MJ5mouQzUE/4YkMCH+5vE1BZlXLIACx7r8KBCBGmCGZye+OAUOhjW6K0IL2ZZ94qRtzFWea78iQGQ8xDtTE9kSQInR4Vog3PCDhE90dU3ftlupJh6SvSlFOjf0I08vcfFDUcB5A/liRqV1eIfCD6MIud8l7JfIfUDu0nuUXtWhTg+CYMUcWCIuKi4HE+Pt0kSxcSYgqnlxHezyEW+fgUW5ltf13m04RK2tXOKdqs0K8Z7Kp3Cfjl2Xp0e8ygWZv3MisanlorwAw8D+L/nJDtDboSYsiyvv+vfeAaTE27o28Q7I22FyN3NvuhVt3mrVxVB9eOH4MOenKuSw== 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=IB35D36ZIUI2W7b+owjbICMCq3T2QxU/rrMLwLEDSL0=; b=MAkEPuodGbWAA+Wwlj5fZgJFqDIOQUtOXu03zj1maidbGBHMxHfoMEz3iX6zEj6LuO4F6cacqeM/+vCWSaobRPv46p2tPGqAg88Dd8Cr614ALumxE/kBMFZY4mQYYiiIHtwD98kpZApnlaVSttHsDnpkADpCAnnNRmsJe+Vx5i/S9t8p6ZNI04VbJuaJDMHnbemb54UKApzLn6bsLZxzCUvgNCiVSPyYU3Bm+A7rdaewn2H5sOz4QYKDhK09ubz0kgTrerKJtTxr2tcZpU4/qpHDr9faw7hlNnoz0u0Xe8jUC7gL5/pzyYNgUOCQD+hfw1DHfAntKSALgQzoIWk2EA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IB35D36ZIUI2W7b+owjbICMCq3T2QxU/rrMLwLEDSL0=; b=GNf8CrqblkLf+hstmEjG898R3xaeI4mLBHzgxAXPcdcDV6FJk2RtTykZ7B1FSf5ynNMSLL8nkIo7lnycIc2LUcqfGfZngzPN2Kv7s/xPhiZ79j+4YXEBf25Cq2FMgDCu8+44wgBC6iF0i3p/qKdM0e32OQGlegHoHz3WyIMZE1k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BLAPR13MB4578.namprd13.prod.outlook.com (2603:10b6:208:332::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.19; Tue, 1 Nov 2022 11:03:12 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%7]) with mapi id 15.20.5791.017; Tue, 1 Nov 2022 11:03:12 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: Steffen Klassert , Herbert Xu , Leon Romanovsky , Chentian Liu , Huanhuan Wang , Yinjun Zhang , Louis Peens , netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next v3 1/3] nfp: extend capability and control words Date: Tue, 1 Nov 2022 12:02:46 +0100 Message-Id: <20221101110248.423966-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221101110248.423966-1-simon.horman@corigine.com> References: <20221101110248.423966-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR0902CA0007.eurprd09.prod.outlook.com (2603:10a6:200:9b::17) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|BLAPR13MB4578:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b2225de-e75e-48a1-fc79-08dabbf8aafb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E/XH4HipQUbdif2UfoAPcSX5X462mU8NLHqZ1lzeYEE6gfKk4cVJ7cAqQRNhRDzWNYldPnkJwGIx+Lfs5JoSEQmdu+YlrW6inwfx1XWXxVlJ1ds3Xb5v7LR90xfPphlyT1l76Sdoazge1gau13SpT6UJ9ovb2fgiInx9NKUQ3tMK6ZscXPrSRruwFJDq6fy+EdLwBHNcQ+MlJqtCIWF0MsU/L/st6/dicCOH4cW4gUGhRb/6ZzwtKdpNRqMEfo9le03rxcFhEi1axOgjy2WTTQOmSj7X37AqSFztARyPBzXqiKO4+4X8Kht5KxCktA6JQya4G9VLpwlcz9Wc5/ZS/oUCZZw9CAIkOaZc1lItHhqn+8YKSOFRxtU3fPiY/nif0xs061FQt6n8j0ZwQObhqdzLNXVHiTcvFj6gL61P8zcYMKTZyWsP8HA5kq9x1O7vz83KdI8jOLKMmwdq5pTSTQL59v7ifFzleW4nKOoHsyZSL75yT62I3/BEpJlZ/4r3LtwVO/FP8AL602EPA9Jam8f/4uHa187Q9YapnAxraoehvRinejcEw2orH+bufJWD+SKOj1VOdijSLNS7joL7eMfaRq/5/uxIof8KlCzNNHPcOTmslJbdv17khiTTYLZ20meN1RKjUgYjYMpqbsg4vzbmPAkqhzU4BE21qbzY98jgTAXo59sYTJfngMizBnjCsBMgCicSBebAIwpH4jhSqQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(376002)(39830400003)(366004)(396003)(451199015)(41300700001)(2616005)(86362001)(83380400001)(38100700002)(6512007)(316002)(36756003)(5660300002)(6506007)(4326008)(8676002)(66946007)(52116002)(66556008)(66476007)(54906003)(2906002)(186003)(110136005)(6666004)(107886003)(6486002)(44832011)(478600001)(1076003)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tq5br07NLouySpPpvVfLQqgS5qDUG7zLZ3QQpHmFK7pCIr+xRXBMHcbfp+bt7SXBbvnr5Pu4tG9NYP6FZ+kvUWod3CqC5ACFXXBAPss2gV0F8IVxwBjuS6WYTGgqzTDxLFC3yrZSoS0zABJRrpPahVX0IpTnSIy6D7skZtXb5qUKefUNyFvrggnRw+/wvdzb0ZIwXxQT5aKEmU9pZUjE2l6GAQg23A2FimmnvmISaR8PbTB1UVmt5OLQyPU8xpfI7GGy9hGeCobxErvlOA3faZGPVoP24LfYPPuxf7ZqWhxd8/WofSfceWyOow9pLKeI+ibQLTPkXddsL149xu7A6g//ZEpD936SWMO3+6tTnOkzf5I/zpEOR27WnPiX/shdvFiwblfrSqh2Ts7r/aEG8bltuhRtQ7rz1woVn3NGWpfDBVpP6XOTN/LCTskrwckfciRiG7/zdHqT5vE9y6Hg3q/t/wSuDJJCOZo+OalpCRYGHSf1b/KgZ+eCg79fdsxt0000FB+p1Y9po1Z5CRQBRO2h4X0anqUVenFM+ad/pQBTjRShd2Xkd43rb2PZp2y3zbKFkfcDV65vqo/WRCZIy82+fsoMxwd2HFsDk0dXvmNEgm2t5v38rj9Q/FbFPCy4BumSui0F/Hfe682WH9/5F34LHQlBQwh6PdPCQPP2nDcitCgxMphM/ToxInmfqcOvV16zjqqHh5MK0mLj10hMzhZIW7i+OxlBVJ2kVbUDwLod1UFjoU9nBZ+d9YfjnuEcwbsIuvFdPIdgRSMXR2NwibxbS4l9m88eQOI5fBnQ/arkXbAQaPJZRMHNllPxfQqTb+IMyEJFtRH9dBUfdL3FkXJCMRQdIdAeKCgYCrwsYPXmLc9uGBiirwwSpVCL9SJBjth4J3VKNPH8h9Ypr8BZfCbZAcKl2Yr3B0LjGwqCbz3BHTBgXC5m9RwmjhT7VGkQfO8LuRV3yWwkn91/RxYvWL59E0ZJ8cekraMuRuC73q66gvUT4k/mmclbR+8NsPNqnzL4x3vr6UXA8oZuprT4CDfxJ4FdqH1EWFpqNWPddBaQw67opAJn/YDMUgxNypJCsNovspMbQo9NlF5QX7ZSAtZNTnCmFu2Nu2PdpHcx5ASkpzjhms75zjMhiC0hIcO5KL/6SsDNqxlVUTudFCqSIcK0y5q3UDM44oWO9i3OmzMS1vLYksHhNu80sKYjOnzn2OqDcE08Px+iUdxmWAMbmv4Ls/tXGFZHLRs0+x7JAoI7aMsJ1DZdB2D9jjMRYdEfalYaQ8woMqzeWEY1CuMYWZyc1To2nRkB4x69olxIvrIgHYRzbFqCIVSeyBwJVsnP+QB7Ts32CkmhMyOUYPfIVFjtSKZiVF+OyEq1omwQYOu4zLZ3khd9OCG2nvRlgP5mNX1WPOZeylA+IkYXK6ixDl4XYeZz3X4C7XCpLCtPBZZ9li1jgijvK3POOk3OzNXKfnOw7FATmN6RoWwZ1EdawF87flbLClHRjYVVgAa+fWeV08AtT/cDCYqh4WIfKuRanyhUGkN9ux2s5NrWF3a5GjN1u8yg1LRHVNlug8QMPDW/7jr0PBfkJwBkoUFe2lNfMpDe1et+dLg1YGPQhWd0DQB7ngO+8zv2fxBawKVMAvLkWQtZ6VxX/IVaaKT76lqBvdCMXMpsYAAsZR+/HpFAkA== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7b2225de-e75e-48a1-fc79-08dabbf8aafb X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2022 11:03:12.2677 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 62D05I/DkyR5a0rYgJ0tGF3nFy7wgFkMZ48SDMA8L+VCeM+Q+i5Qrok6Ux7yg+7X9FWV1Mb3TMtsfCL7IqMSppmEnlhTNWFCjS5UnzrExqo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR13MB4578 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Yinjun Zhang Currently the 32-bit capability word is almost exhausted, now allocate some more words to support new features, and control word is also extended accordingly. Packet-type offloading is implemented in NIC application firmware, but it's not used in kernel driver, so reserve this bit here in case it's redefined for other use. Signed-off-by: Yinjun Zhang Reviewed-by: Louis Peens Signed-off-by: Simon Horman Reviewed-by: Leon Romanovsky --- drivers/net/ethernet/netronome/nfp/nfp_net.h | 2 ++ .../net/ethernet/netronome/nfp/nfp_net_common.c | 1 + drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h | 14 +++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net.h b/drivers/net/ethernet/netronome/nfp/nfp_net.h index a101ff30a1ae..0c3e7e2f856d 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net.h @@ -541,6 +541,7 @@ struct nfp_net_dp { * @id: vNIC id within the PF (0 for VFs) * @fw_ver: Firmware version * @cap: Capabilities advertised by the Firmware + * @cap_w1: Extended capabilities word advertised by the Firmware * @max_mtu: Maximum support MTU advertised by the Firmware * @rss_hfunc: RSS selected hash function * @rss_cfg: RSS configuration @@ -617,6 +618,7 @@ struct nfp_net { u32 id; u32 cap; + u32 cap_w1; u32 max_mtu; u8 rss_hfunc; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index a5ca5c4a7896..50bc5f5a40f3 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2454,6 +2454,7 @@ static int nfp_net_read_caps(struct nfp_net *nn) { /* Get some of the read-only fields from the BAR */ nn->cap = nn_readl(nn, NFP_NET_CFG_CAP); + nn->cap_w1 = nn_readq(nn, NFP_NET_CFG_CAP_WORD1); nn->max_mtu = nn_readl(nn, NFP_NET_CFG_MAX_MTU); /* ABI 4.x and ctrl vNIC always use chained metadata, in other cases diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index 6714d5e8fdab..bc94d2cf1042 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -257,10 +257,18 @@ #define NFP_NET_CFG_BPF_CFG_MASK 7ULL #define NFP_NET_CFG_BPF_ADDR_MASK (~NFP_NET_CFG_BPF_CFG_MASK) -/* 40B reserved for future use (0x0098 - 0x00c0) +/* 3 words reserved for extended ctrl words (0x0098 - 0x00a4) + * 3 words reserved for extended cap words (0x00a4 - 0x00b0) + * Currently only one word is used, can be extended in future. */ -#define NFP_NET_CFG_RESERVED 0x0098 -#define NFP_NET_CFG_RESERVED_SZ 0x0028 +#define NFP_NET_CFG_CTRL_WORD1 0x0098 +#define NFP_NET_CFG_CTRL_PKT_TYPE (0x1 << 0) /* Pkttype offload */ + +#define NFP_NET_CFG_CAP_WORD1 0x00a4 + +/* 16B reserved for future use (0x00b0 - 0x00c0) */ +#define NFP_NET_CFG_RESERVED 0x00b0 +#define NFP_NET_CFG_RESERVED_SZ 0x0010 /* RSS configuration (0x0100 - 0x01ac): * Used only when NFP_NET_CFG_CTRL_RSS is enabled From patchwork Tue Nov 1 11:02:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13026876 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 9BE81C433FE for ; Tue, 1 Nov 2022 11:03:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbiKALDd (ORCPT ); Tue, 1 Nov 2022 07:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbiKALD1 (ORCPT ); Tue, 1 Nov 2022 07:03:27 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2127.outbound.protection.outlook.com [40.107.95.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CDCB4B4 for ; Tue, 1 Nov 2022 04:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XzIBLWCd23YarWIqaVZH7HzuHPVifC6aTJw692StL+INhNYpSjmgvzSgkXwVkJlwwlk9MD+tp71edKNopZyj9NiRdloy3aGdUP2kerLuivvCLcxbypOJ029BBZiekxPn3SRDR4xJtXE1yH9EChp9vSn/rnH7pEAFF3P232SazF2AxrFMGEARHQNqiIH03EbZKS+7HK4/ejMAbxIBvJXgQqx8+573Jus4LT6iAhCc48AJKHcW1Q8wGD2MgiJyWj9kUu0X9wz0sLCuZBJykkVZLE0MRu5RZVrx3tAtLtndxtWL7Od4WxpzuKt1H25HjxYJqehyUL8Iytj7XCLindyOFw== 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=OvPKBfkGkbnFgPJDK8q1BOfBlh4n7YMzuNyiBClCR94=; b=VUlVik/iKfysyQi7fgHMpw1ygGhqu0F60CK1VykUG7FA8YZ6BrrmaucS2hNSdhnZsSTfxamAiFQqrvoR9Y65rP89EDI+gh3EVkAvgagSTzRz1ZBk+srn8Pw9TB5Mi2ucRiaUWBjQSBTBMDORKAgEHEnBh4it+NyOs3jN2vxlFGwCTf0E655Fhj4STS/dOyDC4FRFKzxz/9r9lzg82sI2Q9SSlRWqH7gzhulgJ8AcWmTBT8Uploiw6C3DhqdahVSxFjGwDet1MCZ+rFbhCdZe8A71vh41EDc5f3FiAGd0bPHoWi8L62UJOmGfkfBYOqPVncko+5ofMJn45hveWCMrKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OvPKBfkGkbnFgPJDK8q1BOfBlh4n7YMzuNyiBClCR94=; b=okm0tUuZB4MDmqla/jI9Gmn4omBmP8Rr0k/GxErpXi/zKJ/maqy2Vkun+qxx6QK233UOoxRanHQAIj37FmioPl0IILpIRDms5F76GmyHr/Rew2jQVP3GrVPP8suudAEUltGIN0z+BY6t/6h88P5uCUu1+xE/9w7QsL+4yPzLzLQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BLAPR13MB4578.namprd13.prod.outlook.com (2603:10b6:208:332::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.19; Tue, 1 Nov 2022 11:03:14 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%7]) with mapi id 15.20.5791.017; Tue, 1 Nov 2022 11:03:14 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: Steffen Klassert , Herbert Xu , Leon Romanovsky , Chentian Liu , Huanhuan Wang , Yinjun Zhang , Louis Peens , netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next v3 2/3] nfp: add framework to support ipsec offloading Date: Tue, 1 Nov 2022 12:02:47 +0100 Message-Id: <20221101110248.423966-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221101110248.423966-1-simon.horman@corigine.com> References: <20221101110248.423966-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR0902CA0007.eurprd09.prod.outlook.com (2603:10a6:200:9b::17) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|BLAPR13MB4578:EE_ X-MS-Office365-Filtering-Correlation-Id: 60fbce20-c0e8-4813-1192-08dabbf8ac6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J6K9on2SsIY7lTlCSp9xmOSSQTXf09P437nuQbgu+uGz0vJbwit1L990sKcDTKqeem/Ys7zyxPZiQue6EiLwwgotV6spYT4r3GQ1WI0giZgT+wkZRV5emucgL+4xRdedK0G2Bp2qnR/2nhhI2GFjGZPyxReRKUNIrUYwrxS5e1mYlCPJ9dJ67wfBVzCisRPO/R9qCfuJXSdurZCcjKT6KLHuoFy8S22MrmopNNbEUcsiLEuOoTdPZ/Z5vnW2xcdzJP8Wcq/G7LmkRIPeH0qcD7M4lqN9DFR6wHxzz5e07KG5G5ls6Bd7EeSrMfBn8X+eepls/KmUGLvQkdrMdGaDhb2tJY6kSM+0dWDfS4Pwl7L6G0JLmnoZpXTtubw5mP9wugkjbeyiWllhu/RZw8veqSNWDSbb0RuGBt1iMnt/q6N87IriEJ47QvNLjvwrN2kcDYgmSfQjTg27V2cB7G4ilfZUjTFczGv8Z4+N7sfng8KVzG6bwSx61CUiVJT2EIWq5S67G7PMRZm2zEBTACy4cD4gD4bvTwtNQvAbkvzg36ZJmu2tvCRhJXm/at370pO9JjjV7x/bKz4JDxKA+w1ge9CTr4Sk5+ROOd0iEnqHMuAoJOaqoOC/cPmWyv/X9ud6Snl7x/IQcmIU9MngQX42AN1QabPjnotMp1OH63hpYYzxvcvGs+6G5Z8QMwJXoPBUXVt1IyM4b2g4qyQqS+qUHYbx6DslUOCMmkFic8/I1O0AzFaTUYS7uTeF4Bnesga+X5n/I2W98lP6F3o/5wl+lQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(376002)(39830400003)(366004)(396003)(451199015)(41300700001)(2616005)(86362001)(83380400001)(38100700002)(6512007)(316002)(36756003)(5660300002)(6506007)(4326008)(8676002)(66946007)(52116002)(66556008)(66476007)(54906003)(2906002)(186003)(110136005)(6666004)(107886003)(6486002)(30864003)(44832011)(478600001)(1076003)(8936002)(309714004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I+coBm9EXGe12AtHLmtOJbO0xHhFb4WRX3ALRk9R9MnToQ4jQ1Rca52sKyhI+ElYI8aQLNd3GmJ8WoRIFQXQyBCkg3ew5kxJovRFCKG2sgsgG20qKsTWTIecsLUtoXQqrF4ChI5+CSQXiUm+EjQ08Yb3hCmqdjjPXH/5juvscTpO6uj59j1BfKr65IFmUTrngrytrB34Su7RCCDeW/iqVBULcoPjyeMsX3AKyP9Hygjj+zh9Ecdnq6UEoYK2v4fs5oOWeXFbuLNsIllhqM/uDmkkx/NSfcN+fJZZV8Nf3HvjS3Edi1ctI6/xkiTJHZelBsGvZZ8bwoHe+wu91wy+67g1I6/UZ1LrVJQ2qY3Jx5/rflt0KEEkgtl0CKIKN75DP02Yf2Iomrz9Zu8xdPodixToNirnPHors51J9biDWz81nDQ3bWftnbbjkoyS3aqr8akOI1+YSVGhNRXUWSfErfXImmh0VRVeqOlEhBNjPEMBNmRVUqPo6LJuNgJIo+8cCTLmJUQivluFuoslvmx6rakCzjX1F0x9Bzk8ZL7hVPT0oDASdAkPOCyiQZx+O5mfYh1cICXp9oT7H7OdQ0Lp8prfOeju9EXZCLTCad0bMgpYdtInNjfG9Hz/bjbwUxi4RmFfeb0/Hv1ia1QPnoq1qxg7hiBllCJS3YWV/ToQrPbKPsypWee3oXOkOM/VHx5pCkpVdSZEtdUdY+TpZeBPB/OkrApv8TfBX2X+1SfrYInF/zZhr9IYHHEnzoFVANydnwcoHB74SvhgcUe9ZvIYwfxSNsSTo3XZ20NTUuzeDkoGpKNNprpO9iYs91bTxIeASiZZ5sASVCBScZThBzF8FSMJuAYtdh0hOoi66BVXL++fmVHr2t8MqqvNMSpQt//9XHeuOfk87Ydt9au0taaHocYAF/DwnZEi2hoUHpPlC2tQB6kgmtF/kvvN7vq3MkXpnM8NntnYhv7HvYA9RxJmNJrJCgtErCKb5b4X+L+NzDcoGxu9qP8GXRgCv6kY7OAXpDnYZDtYxrM+ZQXWSbO4VHdlSY69TnwYtX0VkZnW2MZJX6WXmoXoFgWWc9tXcmviO4X8lug5POkvK07fpP88Iyxr+ncXXnYdnLD37MN+4hTvTdKbdFKqq2eyF+tB/xOU4t2sevkZsz1jKhvSirBj2m116VgU2ncGQecUtzW+pWvH2RkQP2dkwRw6HOmbSkL4VC95Nu4c9H4O00TuV+UUZegZ0+k6NWY1DjJ28gqTSXwsSBY38UUyuYVIKtn8C3LlvpjmuJ1AiuKsyVBsQrkmh5Mdg8ng/PVZ3pfS+QYfs8HjY6QS0agDfg3U5d/ckvNB4ejKrvvir9YrRxBudnS3emqpGvYxpK1u1kAE9rveXsTzmPz2higMdPW2LV1ZBxujnMoGtHQVmRQ94LGTYzbWuH1kD3pIb+8WOgSddAgJ7r6LJ1Su0XFpXUGP77ElzQvKB7qVbci9RBB3lE8W5bxeXJ+pd4DFLysKoFP/fsCaBqc1oDZSpSf2vTajFr6pbUX4OhicVMOATB/83yW1P474TijnhqmI6ftoX0cRzrJ0OaRlXbpZtkZvh9rAKd6ho443q5BVZz4p/VV+yExCh0Fp7JTCkU+Kh1RPoP/VELpBbdRl6YPukZD4CHVn09U2LV0BuJYPJeQe7/UlgdrDTzw5Zw== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60fbce20-c0e8-4813-1192-08dabbf8ac6f X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2022 11:03:14.6996 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YueNYmXCLeLxvw6acOsw1paHgaqu47mEr0U4BqFYjDPxecMXDmMiym1NcwxMm1sK8PEB1UYJdJ/5TLOIQNRqk7UDAj7PnfEQ1cII2s/aSiw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR13MB4578 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Huanhuan Wang A new metadata type and config structure are introduced to interact with firmware to support ipsec offloading. This feature relies on specific firmware that supports ipsec encrypt/decrypt by advertising related capability bit. The xfrm callbacks which interact with upper layer are implemented in the following patch. Based on initial work of Norm Bagley . Signed-off-by: Huanhuan Wang Reviewed-by: Louis Peens Signed-off-by: Simon Horman Reviewed-by: Leon Romanovsky --- drivers/net/ethernet/netronome/Kconfig | 11 ++ drivers/net/ethernet/netronome/nfp/Makefile | 2 + .../ethernet/netronome/nfp/crypto/crypto.h | 23 ++++ .../net/ethernet/netronome/nfp/crypto/ipsec.c | 105 ++++++++++++++++++ drivers/net/ethernet/netronome/nfp/nfd3/dp.c | 58 ++++++++-- .../net/ethernet/netronome/nfp/nfd3/ipsec.c | 18 +++ .../net/ethernet/netronome/nfp/nfd3/nfd3.h | 8 ++ drivers/net/ethernet/netronome/nfp/nfp_net.h | 9 ++ .../ethernet/netronome/nfp/nfp_net_common.c | 3 + .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 + 10 files changed, 231 insertions(+), 10 deletions(-) create mode 100644 drivers/net/ethernet/netronome/nfp/crypto/ipsec.c create mode 100644 drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c diff --git a/drivers/net/ethernet/netronome/Kconfig b/drivers/net/ethernet/netronome/Kconfig index 8844d1ac053a..e785c00b5845 100644 --- a/drivers/net/ethernet/netronome/Kconfig +++ b/drivers/net/ethernet/netronome/Kconfig @@ -54,6 +54,17 @@ config NFP_APP_ABM_NIC functionality. Code will be built into the nfp.ko driver. +config NFP_NET_IPSEC + bool "NFP IPsec crypto offload support" + depends on NFP + depends on XFRM_OFFLOAD + default y + help + Enable driver support IPsec crypto offload on NFP NIC. + Say Y, if you are planning to make use of IPsec crypto + offload. NOTE that IPsec crypto offload on NFP NIC + requires specific FW to work. + config NFP_DEBUG bool "Debug support for Netronome(R) NFP4000/NFP6000 NIC drivers" depends on NFP diff --git a/drivers/net/ethernet/netronome/nfp/Makefile b/drivers/net/ethernet/netronome/nfp/Makefile index 9c0861d03634..8a250214e289 100644 --- a/drivers/net/ethernet/netronome/nfp/Makefile +++ b/drivers/net/ethernet/netronome/nfp/Makefile @@ -80,4 +80,6 @@ nfp-objs += \ abm/main.o endif +nfp-$(CONFIG_NFP_NET_IPSEC) += crypto/ipsec.o nfd3/ipsec.o + nfp-$(CONFIG_NFP_DEBUG) += nfp_net_debugfs.o diff --git a/drivers/net/ethernet/netronome/nfp/crypto/crypto.h b/drivers/net/ethernet/netronome/nfp/crypto/crypto.h index bffe58bb2f27..1df73d658938 100644 --- a/drivers/net/ethernet/netronome/nfp/crypto/crypto.h +++ b/drivers/net/ethernet/netronome/nfp/crypto/crypto.h @@ -39,4 +39,27 @@ nfp_net_tls_rx_resync_req(struct net_device *netdev, } #endif +/* IPsec related structures and functions */ +struct nfp_ipsec_offload { + u32 seq_hi; + u32 seq_low; + u32 handle; +}; + +#ifndef CONFIG_NFP_NET_IPSEC +static inline void nfp_net_ipsec_init(struct nfp_net *nn) +{ +} + +static inline void nfp_net_ipsec_clean(struct nfp_net *nn) +{ +} +#else +void nfp_net_ipsec_init(struct nfp_net *nn); +void nfp_net_ipsec_clean(struct nfp_net *nn); +bool nfp_net_ipsec_tx_prep(struct nfp_net_dp *dp, struct sk_buff *skb, + struct nfp_ipsec_offload *offload_info); +int nfp_net_ipsec_rx(struct nfp_meta_parsed *meta, struct sk_buff *skb); +#endif + #endif diff --git a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c new file mode 100644 index 000000000000..11575a9cb3b0 --- /dev/null +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Copyright (C) 2018 Netronome Systems, Inc */ +/* Copyright (C) 2021 Corigine, Inc */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../nfp_net_ctrl.h" +#include "../nfp_net.h" +#include "crypto.h" + +#define NFP_NET_IPSEC_MAX_SA_CNT (16 * 1024) /* Firmware support a maximum of 16K SA offload */ + +static int nfp_net_xfrm_add_state(struct xfrm_state *x) +{ + return -EOPNOTSUPP; +} + +static void nfp_net_xfrm_del_state(struct xfrm_state *x) +{ +} + +static bool nfp_net_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x) +{ + return false; +} + +static const struct xfrmdev_ops nfp_net_ipsec_xfrmdev_ops = { + .xdo_dev_state_add = nfp_net_xfrm_add_state, + .xdo_dev_state_delete = nfp_net_xfrm_del_state, + .xdo_dev_offload_ok = nfp_net_ipsec_offload_ok, +}; + +void nfp_net_ipsec_init(struct nfp_net *nn) +{ + if (!(nn->cap_w1 & NFP_NET_CFG_CTRL_IPSEC)) + return; + + xa_init_flags(&nn->xa_ipsec, XA_FLAGS_ALLOC); + nn->dp.netdev->xfrmdev_ops = &nfp_net_ipsec_xfrmdev_ops; +} + +void nfp_net_ipsec_clean(struct nfp_net *nn) +{ + if (!(nn->cap_w1 & NFP_NET_CFG_CTRL_IPSEC)) + return; + xa_destroy(&nn->xa_ipsec); +} + +bool nfp_net_ipsec_tx_prep(struct nfp_net_dp *dp, struct sk_buff *skb, + struct nfp_ipsec_offload *offload_info) +{ + struct xfrm_offload *xo = xfrm_offload(skb); + struct xfrm_state *x; + + x = xfrm_input_state(skb); + if (!x) + return false; + + offload_info->seq_hi = xo->seq.hi; + offload_info->seq_low = xo->seq.low; + offload_info->handle = x->xso.offload_handle; + + return true; +} + +int nfp_net_ipsec_rx(struct nfp_meta_parsed *meta, struct sk_buff *skb) +{ + struct net_device *netdev = skb->dev; + struct xfrm_offload *xo; + struct xfrm_state *x; + struct sec_path *sp; + struct nfp_net *nn; + u32 saidx; + + nn = netdev_priv(netdev); + + saidx = meta->ipsec_saidx - 1; + if (saidx >= NFP_NET_IPSEC_MAX_SA_CNT) + return -EINVAL; + + sp = secpath_set(skb); + if (unlikely(!sp)) + return -ENOMEM; + + xa_lock(&nn->xa_ipsec); + x = xa_load(&nn->xa_ipsec, saidx); + xa_unlock(&nn->xa_ipsec); + if (!x) + return -EINVAL; + + xfrm_state_hold(x); + sp->xvec[sp->len++] = x; + sp->olen++; + xo = xfrm_offload(skb); + xo->flags = CRYPTO_DONE; + xo->status = CRYPTO_SUCCESS; + + return 0; +} diff --git a/drivers/net/ethernet/netronome/nfp/nfd3/dp.c b/drivers/net/ethernet/netronome/nfp/nfd3/dp.c index 448c1c1afaee..861082c5dbff 100644 --- a/drivers/net/ethernet/netronome/nfp/nfd3/dp.c +++ b/drivers/net/ethernet/netronome/nfp/nfd3/dp.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "../nfp_app.h" #include "../nfp_net.h" @@ -167,28 +168,34 @@ nfp_nfd3_tx_csum(struct nfp_net_dp *dp, struct nfp_net_r_vector *r_vec, u64_stats_update_end(&r_vec->tx_sync); } -static int nfp_nfd3_prep_tx_meta(struct nfp_net_dp *dp, struct sk_buff *skb, u64 tls_handle) +static int nfp_nfd3_prep_tx_meta(struct nfp_net_dp *dp, struct sk_buff *skb, + u64 tls_handle, bool *ipsec) { struct metadata_dst *md_dst = skb_metadata_dst(skb); + struct nfp_ipsec_offload offload_info; unsigned char *data; bool vlan_insert; u32 meta_id = 0; int md_bytes; - if (unlikely(md_dst || tls_handle)) { - if (unlikely(md_dst && md_dst->type != METADATA_HW_PORT_MUX)) - md_dst = NULL; - } +#ifdef CONFIG_NFP_NET_IPSEC + if (xfrm_offload(skb)) + *ipsec = nfp_net_ipsec_tx_prep(dp, skb, &offload_info); +#endif + + if (unlikely(md_dst && md_dst->type != METADATA_HW_PORT_MUX)) + md_dst = NULL; vlan_insert = skb_vlan_tag_present(skb) && (dp->ctrl & NFP_NET_CFG_CTRL_TXVLAN_V2); - if (!(md_dst || tls_handle || vlan_insert)) + if (!(md_dst || tls_handle || vlan_insert || *ipsec)) return 0; md_bytes = sizeof(meta_id) + !!md_dst * NFP_NET_META_PORTID_SIZE + !!tls_handle * NFP_NET_META_CONN_HANDLE_SIZE + - vlan_insert * NFP_NET_META_VLAN_SIZE; + vlan_insert * NFP_NET_META_VLAN_SIZE + + *ipsec * NFP_NET_META_IPSEC_FIELD_SIZE; /* IPsec has 12 bytes of metadata */ if (unlikely(skb_cow_head(skb, md_bytes))) return -ENOMEM; @@ -218,6 +225,19 @@ static int nfp_nfd3_prep_tx_meta(struct nfp_net_dp *dp, struct sk_buff *skb, u64 meta_id <<= NFP_NET_META_FIELD_SIZE; meta_id |= NFP_NET_META_VLAN; } + if (*ipsec) { + /* IPsec has three consecutive 4-bit IPsec metadata types, + * so in total IPsec has three 4 bytes of metadata. + */ + data -= NFP_NET_META_IPSEC_SIZE; + put_unaligned_be32(offload_info.seq_hi, data); + data -= NFP_NET_META_IPSEC_SIZE; + put_unaligned_be32(offload_info.seq_low, data); + data -= NFP_NET_META_IPSEC_SIZE; + put_unaligned_be32(offload_info.handle - 1, data); + meta_id <<= NFP_NET_META_IPSEC_FIELD_SIZE; + meta_id |= NFP_NET_META_IPSEC << 8 | NFP_NET_META_IPSEC << 4 | NFP_NET_META_IPSEC; + } data -= sizeof(meta_id); put_unaligned_be32(meta_id, data); @@ -246,6 +266,7 @@ netdev_tx_t nfp_nfd3_tx(struct sk_buff *skb, struct net_device *netdev) dma_addr_t dma_addr; unsigned int fsize; u64 tls_handle = 0; + bool ipsec = false; u16 qidx; dp = &nn->dp; @@ -273,7 +294,7 @@ netdev_tx_t nfp_nfd3_tx(struct sk_buff *skb, struct net_device *netdev) return NETDEV_TX_OK; } - md_bytes = nfp_nfd3_prep_tx_meta(dp, skb, tls_handle); + md_bytes = nfp_nfd3_prep_tx_meta(dp, skb, tls_handle, &ipsec); if (unlikely(md_bytes < 0)) goto err_flush; @@ -312,6 +333,8 @@ netdev_tx_t nfp_nfd3_tx(struct sk_buff *skb, struct net_device *netdev) txd->vlan = cpu_to_le16(skb_vlan_tag_get(skb)); } + if (ipsec) + nfp_nfd3_ipsec_tx(txd, skb); /* Gather DMA */ if (nr_frags > 0) { __le64 second_half; @@ -764,6 +787,15 @@ nfp_nfd3_parse_meta(struct net_device *netdev, struct nfp_meta_parsed *meta, return false; data += sizeof(struct nfp_net_tls_resync_req); break; +#ifdef CONFIG_NFP_NET_IPSEC + case NFP_NET_META_IPSEC: + /* Note: IPsec packet will have zero saidx, so need add 1 + * to indicate packet is IPsec packet within driver. + */ + meta->ipsec_saidx = get_unaligned_be32(data) + 1; + data += 4; + break; +#endif default: return true; } @@ -876,12 +908,11 @@ static int nfp_nfd3_rx(struct nfp_net_rx_ring *rx_ring, int budget) struct nfp_net_dp *dp = &r_vec->nfp_net->dp; struct nfp_net_tx_ring *tx_ring; struct bpf_prog *xdp_prog; + int idx, pkts_polled = 0; bool xdp_tx_cmpl = false; unsigned int true_bufsz; struct sk_buff *skb; - int pkts_polled = 0; struct xdp_buff xdp; - int idx; xdp_prog = READ_ONCE(dp->xdp_prog); true_bufsz = xdp_prog ? PAGE_SIZE : dp->fl_bufsz; @@ -1081,6 +1112,13 @@ static int nfp_nfd3_rx(struct nfp_net_rx_ring *rx_ring, int budget) continue; } +#ifdef CONFIG_NFP_NET_IPSEC + if (meta.ipsec_saidx != 0 && unlikely(nfp_net_ipsec_rx(&meta, skb))) { + nfp_nfd3_rx_drop(dp, r_vec, rx_ring, NULL, skb); + continue; + } +#endif + if (meta_len_xdp) skb_metadata_set(skb, meta_len_xdp); diff --git a/drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c b/drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c new file mode 100644 index 000000000000..e90f8c975903 --- /dev/null +++ b/drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Copyright (C) 2018 Netronome Systems, Inc */ +/* Copyright (C) 2021 Corigine, Inc */ + +#include + +#include "../nfp_net.h" +#include "nfd3.h" + +void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb) +{ + struct xfrm_state *x = xfrm_input_state(skb); + + if (x->xso.dev && (x->xso.dev->features & NETIF_F_HW_ESP_TX_CSUM)) { + txd->flags |= NFD3_DESC_TX_CSUM | NFD3_DESC_TX_IP4_CSUM | + NFD3_DESC_TX_TCP_CSUM | NFD3_DESC_TX_UDP_CSUM; + } +} diff --git a/drivers/net/ethernet/netronome/nfp/nfd3/nfd3.h b/drivers/net/ethernet/netronome/nfp/nfd3/nfd3.h index 7a0df9e6c3c4..9c1c10dcbaee 100644 --- a/drivers/net/ethernet/netronome/nfp/nfd3/nfd3.h +++ b/drivers/net/ethernet/netronome/nfp/nfd3/nfd3.h @@ -103,4 +103,12 @@ void nfp_nfd3_rx_ring_fill_freelist(struct nfp_net_dp *dp, void nfp_nfd3_xsk_tx_free(struct nfp_nfd3_tx_buf *txbuf); int nfp_nfd3_xsk_poll(struct napi_struct *napi, int budget); +#ifndef CONFIG_NFP_NET_IPSEC +static inline void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb) +{ +} +#else +void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb); +#endif + #endif diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net.h b/drivers/net/ethernet/netronome/nfp/nfp_net.h index 0c3e7e2f856d..6c83e47d8b3d 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net.h @@ -263,6 +263,10 @@ struct nfp_meta_parsed { u8 tpid; u16 tci; } vlan; + +#ifdef CONFIG_NFP_NET_IPSEC + u32 ipsec_saidx; +#endif }; struct nfp_net_rx_hash { @@ -584,6 +588,7 @@ struct nfp_net_dp { * @qcp_cfg: Pointer to QCP queue used for configuration notification * @tx_bar: Pointer to mapped TX queues * @rx_bar: Pointer to mapped FL/RX queues + * @xa_ipsec: IPsec xarray SA data * @tlv_caps: Parsed TLV capabilities * @ktls_tx_conn_cnt: Number of offloaded kTLS TX connections * @ktls_rx_conn_cnt: Number of offloaded kTLS RX connections @@ -672,6 +677,10 @@ struct nfp_net { u8 __iomem *tx_bar; u8 __iomem *rx_bar; +#ifdef CONFIG_NFP_NET_IPSEC + struct xarray xa_ipsec; +#endif + struct nfp_net_tlv_caps tlv_caps; unsigned int ktls_tx_conn_cnt; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index 50bc5f5a40f3..8e9b34b133f4 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2566,6 +2566,8 @@ int nfp_net_init(struct nfp_net *nn) err = nfp_net_tls_init(nn); if (err) goto err_clean_mbox; + + nfp_net_ipsec_init(nn); } nfp_net_vecs_init(nn); @@ -2589,6 +2591,7 @@ void nfp_net_clean(struct nfp_net *nn) return; unregister_netdev(nn->dp.netdev); + nfp_net_ipsec_clean(nn); nfp_ccm_mbox_clean(nn); nfp_net_reconfig_wait_posted(nn); } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index bc94d2cf1042..8f75efd9e463 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -48,6 +48,7 @@ #define NFP_NET_META_CSUM 6 /* checksum complete type */ #define NFP_NET_META_CONN_HANDLE 7 #define NFP_NET_META_RESYNC_INFO 8 /* RX resync info request */ +#define NFP_NET_META_IPSEC 9 /* IPsec SA index for tx and rx */ #define NFP_META_PORT_ID_CTRL ~0U @@ -55,6 +56,8 @@ #define NFP_NET_META_VLAN_SIZE 4 #define NFP_NET_META_PORTID_SIZE 4 #define NFP_NET_META_CONN_HANDLE_SIZE 8 +#define NFP_NET_META_IPSEC_SIZE 4 +#define NFP_NET_META_IPSEC_FIELD_SIZE 12 /* Hash type pre-pended when a RSS hash was computed */ #define NFP_NET_RSS_NONE 0 #define NFP_NET_RSS_IPV4 1 @@ -263,6 +266,7 @@ */ #define NFP_NET_CFG_CTRL_WORD1 0x0098 #define NFP_NET_CFG_CTRL_PKT_TYPE (0x1 << 0) /* Pkttype offload */ +#define NFP_NET_CFG_CTRL_IPSEC (0x1 << 1) /* IPsec offload */ #define NFP_NET_CFG_CAP_WORD1 0x00a4 From patchwork Tue Nov 1 11:02:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13026875 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 37214C433FE for ; Tue, 1 Nov 2022 11:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230055AbiKALD1 (ORCPT ); Tue, 1 Nov 2022 07:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbiKALDZ (ORCPT ); Tue, 1 Nov 2022 07:03:25 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2127.outbound.protection.outlook.com [40.107.95.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0C319024 for ; Tue, 1 Nov 2022 04:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJS30ubG6S3KXPI2lQVEKEIyxe1mKMpwKrg4IlB6Hh9nkVFTn5s1/iSIQvyS13vTGmk8NQ+flRS3YYNcab3boRGK3DPPr1OCJ6R59r3oBYIZjdTAv6CVxZA5zDOQ+cV/SVVOWyhzs/sov47vjbj2STrgzigzqh0tdObC2YouqHXndQ3QBtR2FsS7K3Z4hAGtE6fR+lOJkSaWLZY8e33B4aDPH/IbMxJMifP2n9J5UA4I/0pTdaKKJtMEjFifGmX7UrwPrV7iqaqCYU3RNwbQ5vDDNVI7qIPWQvjukGyt0pZY8JSzf4OjOyztvH+/6PVOLL49t2ITRlzB96UgKHoWRw== 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=9sX+HboMKruktpSf1d53fzLJaz7GhN1bRQm5SWsppc8=; b=XnuJZSFo8CxaaD519x8JOre01aGPqjBXCLUm8f0qX1MGdOx/lXqAGk2ZOmZRy3Aok4AzPMoZ8zgm10R7I+r3KpC0enfDOHuIIP9RqYJDkk1PdCqAkQm0H1P3QyO1gx0BDGd/EAlAuXwT3VAh8h9rHwIell59cKMwfePMHMTv2E5ybl5K24n8Z+6Sg4VxxubhUjk4u13YDXMQ9bdTDwkEtTiGN3SBjPKXLRT/HLQek32c5u0fYoMZ9VglD46PyD11j9Sw72ftX4vP9dVEsfVYNBCnLsPoJdpOAuVN0K/koqrF2e9+pXkrK27ss4LfhqmK816iOifvevwFKYntU8wR1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9sX+HboMKruktpSf1d53fzLJaz7GhN1bRQm5SWsppc8=; b=i8KjHEwgM5YaqF/0VgMvFvaDNfMjTcB6+PkhyuURmVw4hKjhqEsMsSkp60Ur2LPi+7E7gtRRENVb1/RhJs5o0hR4Eg1tO3YDbYFAxXLLfhWRhj4ROh7d263dKPJCcuZ97bKKEP8uV4P2nzQgrbQZmLwpK1auI3tV0M9Pis0jSqg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BLAPR13MB4578.namprd13.prod.outlook.com (2603:10b6:208:332::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.19; Tue, 1 Nov 2022 11:03:17 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%7]) with mapi id 15.20.5791.017; Tue, 1 Nov 2022 11:03:17 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: Steffen Klassert , Herbert Xu , Leon Romanovsky , Chentian Liu , Huanhuan Wang , Yinjun Zhang , Louis Peens , netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next v3 3/3] nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer Date: Tue, 1 Nov 2022 12:02:48 +0100 Message-Id: <20221101110248.423966-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221101110248.423966-1-simon.horman@corigine.com> References: <20221101110248.423966-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR0902CA0007.eurprd09.prod.outlook.com (2603:10a6:200:9b::17) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|BLAPR13MB4578:EE_ X-MS-Office365-Filtering-Correlation-Id: f59f8bad-d907-4b50-6fa1-08dabbf8ade0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6KtYSgXL5vK+SCB1Kg43dee6aN6Fdu0YQ8Gr2KHl+4XRfXD3RrvYXEy6rZQw132jT6RgGd640QZGaTkeHfbS7NSX+aGX419X32l+aEfVsg2qg067HykrXHVt9cv2vk8HS1xwCWLwW6c9PEbstYeQqpgsp3hD0PGjRXYtJLgdfLF0dwqCUg4fvdZRdK0rmNStZC8xiMzK5nZ2KHC6hMHJb7c429aMrskXGOrTrzgUNY12S6SdfvQgiMcshotZsM+OMGqOTexyNQ9M9y5EHpgf1msoke9Ka71eFcGfV9ZgVyiL8EB+ZFmY5sSqbwrA/Wrnuo2RotmXpzVf9dGW/b4tFvswtfp2Z5rWj5F1ghOxSR4TCZVJtExgiDnU6nVAaYcvPy4CBxiQP5cPNshmzqFcrISxAGBBjgo6t0rcDuJETqT1AxPBvddmE3NGJK1tpDpUDfc+kSAN2dlgnK5DHWf7OcIMiDb/y4PsAf9F/EZScZx0IN7BUBNcDiB5MzCqmjv3zioBkKtDlv+PYihOsFTYxz1cu6BfxhufdPtlGLyXMPbt2ZO6gHe47jy73kfjBa8B3l520JzUec659JoY1D/ufQlsJ2riq4vp7hNewTMEmh0eIEAY9z6w2jHPUUcjBQp5ORpSZolKGv6IgO4kfFih+lURCSMuXbmpTRFn7BNb45g8q1gdOlr/XUExkl57SMLMh4V8yf5AGdNPgkYD/EvAJg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(376002)(39830400003)(366004)(396003)(451199015)(41300700001)(2616005)(86362001)(83380400001)(38100700002)(6512007)(316002)(36756003)(5660300002)(6506007)(4326008)(8676002)(66946007)(52116002)(66556008)(66476007)(54906003)(2906002)(186003)(110136005)(6666004)(107886003)(6486002)(30864003)(44832011)(478600001)(1076003)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RiQfAG9fzqXU3wQAympC18OZ7/5jdtaPi13A1XJYfO8+a8sI3/tQa85dCewjPPjqkCWA52TJLwmvEkUB4Fh2zHfvLuor75FhJZwd4ZB9juCjxzkrD1UkHJP30DXgkV1qMXg3T7NR3QWg4to3Z5HhDpSR5lKirI409BgGGI/e+5M/e6UY3GdlMs3h5lKkoBq9xDE1ldcHMb0LhCULI6CiGER9VscLfisRiodfICWTjr8fCFuZFY+bdn954BbONt5CWHqQg7dX3+I/3xUvVL+cANSGPFlD17BOIXyd8eQX2MXWbflxTrEdwojD3uO7yjOGUZ+fLqoevAoFhOXGF26wCaWkwLqSVFiVAdLz31Ek9PzsRlqGGpYuctCVkq8pgA4wkV8AbJoCBgsgvwtSBeMiEAqQlsJB2Ipr+KvUnwjli7SzsTYPcfXDFdYsyvGPBq9g+kT1BlTRfPoxgKec+YZMIgoO8gkMEwjVPgm6Tp+xUuOsDWjZXCF8x3fdDlMjY1YILwnRxdmVPwPSEvJxoW4TrS53Ci6e8Z/fTgDAMUmi1Lp/Qnwrt8cXEDJTEDU90LN6t5mybDwvUZKMS52lMyl9m/LAypmUrcD79PF+U9w/+Cd6AQ0bb9yEHENOVjYvxlPr3JTjpfI/eKetb48PI9MseSK8wAJuxzISbTFNb9AbAw7sYY5Z67kFi11z1Nlx526nf9Thh5qsA6HVTBxX+R1SUAupOG5AgYLGpe20tyYpaBWg7QIiQoPl1vx+4+8QpAQWeN2AjKr5j5boVXXCsJcezgQlUMgqUxhRJmXsD3QmO4ev3Fd75J+sLUh9dj8l5mMCB27+Lu2GlZWeiJ0+6U7Xh2MzxBpBwkkcyJ9AVBsn9LWcg74UMMyoMDEZUUKz4PtrBhv4XkpCJXMldIwHSTomq4h98vHgHQhl+etAvX5ta6GrTGAZjJaT9RmACR3MTiJjPVFruJTPyRvoLhafBVj/EhHZiudPhYagNrB67SkXNWsClsaeHv8nWmrqJkl61GX0kJXPwogTGYOOtpbik29kvu+McU7ShHdnfRfS7BXxGeQv82MQvtVO3CWH6lMx60aAYHf52vsWBYrXxlCiId6dAV9uL3odksaP7IQRgyxOmy4ELLhHeLnWoVMjJZW8zfWKd6gUzCE6FC6YRh0lW+/NBh44C02nc3SjrYyHE4bFTc1h0UZcZXYGulGrGrV6zhVJAuHUAbuJkb4vQcFuU7am+NdNP0nmObltWSksaUSMoBPZx7Ql/jMadQAqcNSZ6yYCwULeKLY97/Z2QyAOsY8PByP3ghvdq6dPOBYi5ahx/LiHK+ZiP10K6UxtXj/951zORUNKtmjrxxgBNmfk3lZUr3ybdaib3d1Mb3gHWoPBvelsfASeNExJUlhnpkMQVp6sMJ/L5Nt9lTAr+HEwZCm54pNwIZli1OsPO+P0nMOno9Z6Mq02kCYcQSZxDXuOGplhLTLODaEli09cYfu1LOflaSdB3s9/gzyvsLKTE2+PfdPagWuNJMYzXfVvMmJ4uiUb2+6dB2f9/jW8EF1Bodyat8EwJtWWhLrdbHGp1w7KCjVAxdOZt0uGcO+c8iz45oLeYRbmvpvhz2OrM/tMKABFMUawuqTyoqG/rwvJemwi0iCUHzsGu9E5Pu98d7ubpSChHOukPoi12AbwgwKTC6rn3Q== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: f59f8bad-d907-4b50-6fa1-08dabbf8ade0 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2022 11:03:17.1514 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1lqgkyGDSKtyy1L6fhon0NUGQwqyAzJUCs18aHeHOPboYmy/VGled6OGRt0OePTG2bX/Faf/3EClJ1WPR+Cr7xfuIK6b3RRYMrReM+1JfsM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR13MB4578 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Huanhuan Wang Xfrm callbacks are implemented to offload SA info into firmware by mailbox. It supports 16K SA info in total. Expose ipsec offload feature to upper layer, this feature will signal the availability of the offload. Based on initial work of Norm Bagley . Signed-off-by: Huanhuan Wang Reviewed-by: Louis Peens Signed-off-by: Simon Horman --- .../net/ethernet/netronome/nfp/crypto/ipsec.c | 532 +++++++++++++++++- .../ethernet/netronome/nfp/nfp_net_common.c | 6 + .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 +- 3 files changed, 538 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c index 11575a9cb3b0..664a36be60e7 100644 --- a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -16,18 +16,546 @@ #define NFP_NET_IPSEC_MAX_SA_CNT (16 * 1024) /* Firmware support a maximum of 16K SA offload */ +/* IPsec config message cmd codes */ +enum nfp_ipsec_cfg_mssg_cmd_codes { + NFP_IPSEC_CFG_MSSG_ADD_SA, /* Add a new SA */ + NFP_IPSEC_CFG_MSSG_INV_SA, /* Invalidate an existing SA */ + NFP_IPSEC_CFG_MSSG_MODIFY_SA, /* Modify an existing SA */ + NFP_IPSEC_CFG_MSSG_GET_SA_STATS, /* Report SA counters, flags, etc. */ + NFP_IPSEC_CFG_MSSG_GET_SEQ_NUMS, /* Allocate sequence numbers */ + NFP_IPSEC_CFG_MSSG_LAST +}; + +/* IPsec config message response codes */ +enum nfp_ipsec_cfg_mssg_rsp_codes { + NFP_IPSEC_CFG_MSSG_OK, + NFP_IPSEC_CFG_MSSG_FAILED, + NFP_IPSEC_CFG_MSSG_SA_VALID, + NFP_IPSEC_CFG_MSSG_SA_HASH_ADD_FAILED, + NFP_IPSEC_CFG_MSSG_SA_HASH_DEL_FAILED, + NFP_IPSEC_CFG_MSSG_SA_INVALID_CMD +}; + +/* Protocol */ +enum nfp_ipsec_sa_prot { + NFP_IPSEC_PROTOCOL_AH = 0, + NFP_IPSEC_PROTOCOL_ESP = 1 +}; + +/* Mode */ +enum nfp_ipsec_sa_mode { + NFP_IPSEC_PROTMODE_TRANSPORT = 0, + NFP_IPSEC_PROTMODE_TUNNEL = 1 +}; + +/* Cipher types */ +enum nfp_ipsec_sa_cipher { + NFP_IPSEC_CIPHER_NULL, + NFP_IPSEC_CIPHER_3DES, + NFP_IPSEC_CIPHER_AES128, + NFP_IPSEC_CIPHER_AES192, + NFP_IPSEC_CIPHER_AES256, + NFP_IPSEC_CIPHER_AES128_NULL, + NFP_IPSEC_CIPHER_AES192_NULL, + NFP_IPSEC_CIPHER_AES256_NULL, + NFP_IPSEC_CIPHER_CHACHA20 +}; + +/* Cipher modes */ +enum nfp_ipsec_sa_cipher_mode { + NFP_IPSEC_CIMODE_ECB, + NFP_IPSEC_CIMODE_CBC, + NFP_IPSEC_CIMODE_CFB, + NFP_IPSEC_CIMODE_OFB, + NFP_IPSEC_CIMODE_CTR +}; + +/* Hash types */ +enum nfp_ipsec_sa_hash_type { + NFP_IPSEC_HASH_NONE, + NFP_IPSEC_HASH_MD5_96, + NFP_IPSEC_HASH_SHA1_96, + NFP_IPSEC_HASH_SHA256_96, + NFP_IPSEC_HASH_SHA384_96, + NFP_IPSEC_HASH_SHA512_96, + NFP_IPSEC_HASH_MD5_128, + NFP_IPSEC_HASH_SHA1_80, + NFP_IPSEC_HASH_SHA256_128, + NFP_IPSEC_HASH_SHA384_192, + NFP_IPSEC_HASH_SHA512_256, + NFP_IPSEC_HASH_GF128_128, + NFP_IPSEC_HASH_POLY1305_128 +}; + +/* IPSEC_CFG_MSSG_ADD_SA */ +struct nfp_ipsec_cfg_add_sa { + u32 ciph_key[8]; /* Cipher Key */ + union { + u32 auth_key[16]; /* Authentication Key */ + struct nfp_ipsec_aesgcm { /* AES-GCM-ESP fields */ + u32 salt; /* Initialized with SA */ + u32 iv[2]; /* Firmware use only */ + u32 cntr; + u32 zeros[4]; /* Init to 0 with SA */ + u32 len_a[2]; /* Firmware use only */ + u32 len_c[2]; + u32 spare0[4]; + } aesgcm_fields; + }; + struct sa_ctrl_word { + uint32_t hash :4; /* From nfp_ipsec_sa_hash_type */ + uint32_t cimode :4; /* From nfp_ipsec_sa_cipher_mode */ + uint32_t cipher :4; /* From nfp_ipsec_sa_cipher */ + uint32_t mode :2; /* From nfp_ipsec_sa_mode */ + uint32_t proto :2; /* From nfp_ipsec_sa_prot */ + uint32_t dir :1; /* SA direction */ + uint32_t ena_arw:1; /* Anti-Replay Window */ + uint32_t ext_seq:1; /* 64-bit Sequence Num */ + uint32_t ext_arw:1; /* 64b Anti-Replay Window */ + uint32_t spare2 :9; /* Must be set to 0 */ + uint32_t encap_dsbl:1; /* Encap/Decap disable */ + uint32_t gen_seq:1; /* Firmware Generate Seq */ + uint32_t spare8 :1; /* Must be set to 0 */ + } ctrl_word; + u32 spi; /* SPI Value */ + uint32_t pmtu_limit :16; /* PMTU Limit */ + uint32_t spare3 :1; + uint32_t frag_check :1; /* Stateful fragment checking flag */ + uint32_t bypass_DSCP:1; /* Bypass DSCP Flag */ + uint32_t df_ctrl :2; /* DF Control bits */ + uint32_t ipv6 :1; /* Outbound IPv6 addr format */ + uint32_t udp_enable :1; /* Add/Remove UDP header for NAT */ + uint32_t tfc_enable :1; /* Traffic Flow Confidentiality */ + uint32_t spare4 :8; + u32 soft_lifetime_byte_count; + u32 hard_lifetime_byte_count; + u32 src_ip[4]; /* Src IP addr */ + u32 dst_ip[4]; /* Dst IP addr */ + uint32_t natt_dst_port :16; /* NAT-T UDP Header dst port */ + uint32_t natt_src_port :16; /* NAT-T UDP Header src port */ + u32 soft_lifetime_time_limit; + u32 hard_lifetime_time_limit; + u32 sa_creation_time_lo_32; /* Ucode fills this in */ + u32 sa_creation_time_hi_32; /* Ucode fills this in */ + uint32_t reserved0 :16; + uint32_t tfc_padding :16; /* Traffic Flow Confidential Pad */ +}; + +/* IPSEC_CFG_MSSG_INV_SA */ +struct nfp_ipsec_cfg_inv_sa { + u32 spare6; +}; + +/* IPSEC_CFG_MSSG_GET_SA_STATS */ +struct nfp_ipsec_cfg_get_sa_stats { + u32 seq_lo; /* Sequence Number (low 32bits) */ + u32 seq_high; /* Sequence Number (high 32bits) */ + u32 arw_counter_lo; /* Anti-replay wndw cntr */ + u32 arw_counter_high; /* Anti-replay wndw cntr */ + u32 arw_bitmap_lo; /* Anti-replay wndw bitmap */ + u32 arw_bitmap_high; /* Anti-replay wndw bitmap */ + uint32_t reserved1:1; + uint32_t soft_lifetime_byte_cnt_exceeded :1; /* Soft cnt_exceeded */ + uint32_t hard_lifetime_byte_cnt_exceeded :1; /* Hard cnt_exceeded */ + uint32_t soft_lifetime_time_limit_exceeded :1; /* Soft cnt_exceeded */ + uint32_t hard_lifetime_time_limit_exceeded :1; /* Hard cnt_exceeded */ + uint32_t spare7:27; + u32 lifetime_byte_count; + u32 pkt_count; + u32 discards_auth; /* Auth failures */ + u32 discards_unsupported; /* Unsupported crypto mode */ + u32 discards_alignment; /* Alignment error */ + u32 discards_hard_bytelimit; /* Byte Count limit */ + u32 discards_seq_num_wrap; /* Sequ Number wrap */ + u32 discards_pmtu_limit_exceeded; /* PMTU Limit */ + u32 discards_arw_old_seq; /* Anti-Replay seq small */ + u32 discards_arw_replay; /* Anti-Replay seq rcvd */ + u32 discards_ctrl_word; /* Bad SA Control word */ + u32 discards_ip_hdr_len; /* Hdr offset from too high */ + u32 discards_eop_buf; /* No EOP buffer */ + u32 ipv4_id_counter; /* IPv4 ID field counter */ + u32 discards_isl_fail; /* Inbound SPD Lookup failure */ + u32 discards_ext_not_found; /* Ext header end */ + u32 discards_max_ext_hdrs; /* Max ext header */ + u32 discards_non_ext_hdrs; /* Non-extension headers */ + u32 discards_ext_hdr_too_big; /* Ext header chain */ + u32 discards_hard_timelimit; /* Time Limit */ +}; + +/* IPSEC_CFG_MSSG_GET_SEQ_NUMS */ +struct ipsec_cfg_get_seq_nums { + u32 seq_nums; /* Sequence numbers to allocate */ + u32 seq_num_low; /* Rtrn start seq num 31:00 */ + u32 seq_num_hi; /* Rtrn start seq num 63:32 */ +}; + +/* IPSEC_CFG_MSSG */ +struct nfp_ipsec_cfg_mssg { + union { + struct{ + uint32_t cmd:16; /* One of nfp_ipsec_cfg_mssg_cmd_codes */ + uint32_t rsp:16; /* One of nfp_ipsec_cfg_mssg_rsp_codes */ + uint32_t sa_idx:16; /* SA table index */ + uint32_t spare0:16; + union { + struct nfp_ipsec_cfg_add_sa cfg_add_sa; + struct nfp_ipsec_cfg_inv_sa cfg_inv_sa; + struct nfp_ipsec_cfg_get_sa_stats cfg_get_stats; + struct ipsec_cfg_get_seq_nums cfg_get_seq_nums; + }; + }; + u32 raw[64]; + }; +}; + +static int nfp_ipsec_cfg_cmd_issue(struct nfp_net *nn, int type, int saidx, + struct nfp_ipsec_cfg_mssg *msg) +{ + int i, msg_size, ret; + + msg->cmd = type; + msg->sa_idx = saidx; + msg->rsp = 0; + msg_size = ARRAY_SIZE(msg->raw); + + for (i = 0; i < msg_size; i++) + nn_writel(nn, NFP_NET_CFG_MBOX_VAL + 4 * i, msg->raw[i]); + + ret = nfp_net_mbox_reconfig(nn, NFP_NET_CFG_MBOX_CMD_IPSEC); + if (ret < 0) + return ret; + + /* For now we always read the whole message response back */ + for (i = 0; i < msg_size; i++) + msg->raw[i] = nn_readl(nn, NFP_NET_CFG_MBOX_VAL + 4 * i); + + switch (msg->rsp) { + case NFP_IPSEC_CFG_MSSG_OK: + return 0; + case NFP_IPSEC_CFG_MSSG_SA_INVALID_CMD: + return -EINVAL; + case NFP_IPSEC_CFG_MSSG_SA_VALID: + return -EEXIST; + case NFP_IPSEC_CFG_MSSG_FAILED: + case NFP_IPSEC_CFG_MSSG_SA_HASH_ADD_FAILED: + case NFP_IPSEC_CFG_MSSG_SA_HASH_DEL_FAILED: + return -EIO; + default: + return -EDOM; + } +} + +static int set_aes_keylen(struct nfp_ipsec_cfg_add_sa *cfg, int alg, int keylen) +{ + if (alg == SADB_X_EALG_NULL_AES_GMAC) { + if (keylen == 128) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES128_NULL; + else if (keylen == 192) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES192_NULL; + else if (keylen == 256) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES256_NULL; + else + return -EINVAL; + } else { + if (keylen == 128) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES128; + else if (keylen == 192) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES192; + else if (keylen == 256) + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_AES256; + else + return -EINVAL; + } + + return 0; +} + static int nfp_net_xfrm_add_state(struct xfrm_state *x) { - return -EOPNOTSUPP; + struct net_device *netdev = x->xso.dev; + struct nfp_ipsec_cfg_mssg msg = {0}; + int i, key_len, trunc_len, err = 0; + struct nfp_ipsec_cfg_add_sa *cfg; + struct nfp_net *nn; + unsigned int saidx; + __be32 *p; + + nn = netdev_priv(netdev); + cfg = &msg.cfg_add_sa; + + /* General */ + switch (x->props.mode) { + case XFRM_MODE_TUNNEL: + cfg->ctrl_word.mode = NFP_IPSEC_PROTMODE_TUNNEL; + break; + case XFRM_MODE_TRANSPORT: + cfg->ctrl_word.mode = NFP_IPSEC_PROTMODE_TRANSPORT; + break; + default: + nn_err(nn, "Unsupported mode for xfrm offload\n"); + return -EINVAL; + } + + switch (x->id.proto) { + case IPPROTO_ESP: + cfg->ctrl_word.proto = NFP_IPSEC_PROTOCOL_ESP; + break; + case IPPROTO_AH: + cfg->ctrl_word.proto = NFP_IPSEC_PROTOCOL_AH; + break; + default: + nn_err(nn, "Unsupported protocol for xfrm offload\n"); + return -EINVAL; + } + + if (x->props.flags & XFRM_STATE_ESN) { + nn_err(nn, "Unsupported XFRM_REPLAY_MODE_ESN for xfrm offload\n"); + return -EINVAL; + } + + cfg->ctrl_word.ena_arw = 0; + cfg->ctrl_word.ext_arw = 0; + cfg->spi = ntohl(x->id.spi); + + /* Hash/Authentication */ + if (x->aalg) + trunc_len = x->aalg->alg_trunc_len; + else + trunc_len = 0; + + switch (x->props.aalgo) { + case SADB_AALG_NONE: + if (x->aead) { + trunc_len = -1; + } else { + nn_err(nn, "Unsupported authentication algorithm\n"); + return -EINVAL; + } + break; + case SADB_X_AALG_NULL: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_NONE; + trunc_len = -1; + break; + case SADB_AALG_MD5HMAC: + if (trunc_len == 96) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_96; + else if (trunc_len == 128) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_128; + else + trunc_len = 0; + break; + case SADB_AALG_SHA1HMAC: + if (trunc_len == 96) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_96; + else if (trunc_len == 80) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_80; + else + trunc_len = 0; + break; + case SADB_X_AALG_SHA2_256HMAC: + if (trunc_len == 96) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_96; + else if (trunc_len == 128) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_128; + else + trunc_len = 0; + break; + case SADB_X_AALG_SHA2_384HMAC: + if (trunc_len == 96) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_96; + else if (trunc_len == 192) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_192; + else + trunc_len = 0; + break; + case SADB_X_AALG_SHA2_512HMAC: + if (trunc_len == 96) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_96; + else if (trunc_len == 256) + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_256; + else + trunc_len = 0; + break; + default: + nn_err(nn, "Unsupported authentication algorithm\n"); + return -EINVAL; + } + + if (!trunc_len) { + nn_err(nn, "Unsupported authentication algorithm trunc length\n"); + return -EINVAL; + } + + if (x->aalg) { + p = (__be32 *)x->aalg->alg_key; + key_len = DIV_ROUND_UP(x->aalg->alg_key_len, BITS_PER_BYTE); + if (key_len > sizeof(cfg->auth_key)) { + nn_err(nn, "Insufficient space for offloaded auth key\n"); + return -EINVAL; + } + for (i = 0; i < key_len / sizeof(cfg->auth_key[0]) ; i++) + cfg->auth_key[i] = ntohl(*p++); + } + /* Encryption */ + switch (x->props.ealgo) { + case SADB_EALG_NONE: + case SADB_EALG_NULL: + cfg->ctrl_word.cimode = NFP_IPSEC_CIMODE_CBC; + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_NULL; + break; + case SADB_EALG_3DESCBC: + cfg->ctrl_word.cimode = NFP_IPSEC_CIMODE_CBC; + cfg->ctrl_word.cipher = NFP_IPSEC_CIPHER_3DES; + break; + case SADB_X_EALG_AES_GCM_ICV16: + case SADB_X_EALG_NULL_AES_GMAC: + if (!x->aead) { + nn_err(nn, "Invalid AES key data\n"); + return -EINVAL; + } + + if (x->aead->alg_icv_len != 128) { + nn_err(nn, "ICV must be 128bit with SADB_X_EALG_AES_GCM_ICV16\n"); + return -EINVAL; + } + cfg->ctrl_word.cimode = NFP_IPSEC_CIMODE_CTR; + cfg->ctrl_word.hash = NFP_IPSEC_HASH_GF128_128; + + /* Aead->alg_key_len includes 32-bit salt */ + if (set_aes_keylen(cfg, x->props.ealgo, x->aead->alg_key_len - 32)) { + nn_err(nn, "Unsupported AES key length %d\n", x->aead->alg_key_len); + return -EINVAL; + } + break; + case SADB_X_EALG_AESCBC: + cfg->ctrl_word.cimode = NFP_IPSEC_CIMODE_CBC; + if (!x->ealg) { + nn_err(nn, "Invalid AES key data\n"); + return -EINVAL; + } + if (set_aes_keylen(cfg, x->props.ealgo, x->ealg->alg_key_len) < 0) { + nn_err(nn, "Unsupported AES key length %d\n", x->ealg->alg_key_len); + return -EINVAL; + } + break; + default: + nn_err(nn, "Unsupported encryption algorithm for offload\n"); + return -EINVAL; + } + + if (x->aead) { + int salt_len = 4; + + p = (__be32 *)x->aead->alg_key; + key_len = DIV_ROUND_UP(x->aead->alg_key_len, BITS_PER_BYTE); + key_len -= salt_len; + + if (key_len > sizeof(cfg->ciph_key)) { + nn_err(nn, "aead: Insufficient space for offloaded key\n"); + return -EINVAL; + } + + for (i = 0; i < key_len / sizeof(cfg->ciph_key[0]) ; i++) + cfg->ciph_key[i] = ntohl(*p++); + + /* Load up the salt */ + for (i = 0; i < salt_len; i++) + cfg->auth_key[i] = ntohl(*p++); + } + + if (x->ealg) { + p = (__be32 *)x->ealg->alg_key; + key_len = DIV_ROUND_UP(x->ealg->alg_key_len, BITS_PER_BYTE); + + if (key_len > sizeof(cfg->ciph_key)) { + nn_err(nn, "ealg: Insufficient space for offloaded key\n"); + return -EINVAL; + } + for (i = 0; i < key_len / sizeof(cfg->ciph_key[0]) ; i++) + cfg->ciph_key[i] = ntohl(*p++); + } + /* IP related info */ + switch (x->props.family) { + case AF_INET: + cfg->ipv6 = 0; + cfg->src_ip[0] = ntohl(x->props.saddr.a4); + cfg->dst_ip[0] = ntohl(x->id.daddr.a4); + break; + case AF_INET6: + cfg->ipv6 = 1; + for (i = 0; i < 4; i++) { + cfg->src_ip[i] = ntohl(x->props.saddr.a6[i]); + cfg->dst_ip[i] = ntohl(x->id.daddr.a6[i]); + } + break; + default: + nn_err(nn, "Unsupported address family\n"); + return -EINVAL; + } + + /* Maximum nic IPsec code could handle. Other limits may apply. */ + cfg->pmtu_limit = 0xffff; + + /* Host will generate the sequence numbers so that if packets get + * fragmented in host, sequence numbers will stay in sync. + */ + cfg->ctrl_word.gen_seq = 0; + + cfg->ctrl_word.encap_dsbl = 1; + + /* SA direction */ + cfg->ctrl_word.dir = x->xso.dir; + + /* Find unused SA data*/ + err = xa_alloc(&nn->xa_ipsec, &saidx, x, + XA_LIMIT(0, NFP_NET_IPSEC_MAX_SA_CNT - 1), GFP_KERNEL); + if (err < 0) { + nn_err(nn, "Unable to get sa_data number for IPsec\n"); + return err; + } + + /* Allocate saidx and commit the SA */ + err = nfp_ipsec_cfg_cmd_issue(nn, NFP_IPSEC_CFG_MSSG_ADD_SA, saidx, &msg); + if (err) { + xa_erase(&nn->xa_ipsec, saidx); + nn_err(nn, "Failed to issue IPsec command err ret=%d\n", err); + return err; + } + + /* 0 is invalid offload_handle for kernel */ + x->xso.offload_handle = saidx + 1; + return 0; } static void nfp_net_xfrm_del_state(struct xfrm_state *x) { + struct net_device *netdev = x->xso.dev; + struct nfp_ipsec_cfg_mssg msg; + struct nfp_net *nn; + int err; + + nn = netdev_priv(netdev); + err = nfp_ipsec_cfg_cmd_issue(nn, NFP_IPSEC_CFG_MSSG_INV_SA, + x->xso.offload_handle - 1, &msg); + if (err) + nn_warn(nn, "Failed to invalidate SA in hardware\n"); + + xa_erase(&nn->xa_ipsec, x->xso.offload_handle - 1); } static bool nfp_net_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x) { - return false; + if (x->props.family == AF_INET) { + /* Offload with IPv4 options is not supported yet */ + if (ip_hdr(skb)->ihl != 5) + return false; + } else { + /* Offload with IPv6 extension headers is not support yet */ + if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr)) + return false; + } + + return true; } static const struct xfrmdev_ops nfp_net_ipsec_xfrmdev_ops = { diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index 8e9b34b133f4..e83f58590248 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2373,6 +2373,12 @@ static void nfp_net_netdev_init(struct nfp_net *nn) } if (nn->cap & NFP_NET_CFG_CTRL_RSS_ANY) netdev->hw_features |= NETIF_F_RXHASH; + +#ifdef CONFIG_NFP_NET_IPSEC + if (nn->cap_w1 & NFP_NET_CFG_CTRL_IPSEC) + netdev->hw_features |= NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM; +#endif + if (nn->cap & NFP_NET_CFG_CTRL_VXLAN) { if (nn->cap & NFP_NET_CFG_CTRL_LSO) { netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL | diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index 8f75efd9e463..cc11b3dc1252 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -402,14 +402,14 @@ */ #define NFP_NET_CFG_MBOX_BASE 0x1800 #define NFP_NET_CFG_MBOX_VAL_MAX_SZ 0x1F8 - +#define NFP_NET_CFG_MBOX_VAL 0x1808 #define NFP_NET_CFG_MBOX_SIMPLE_CMD 0x0 #define NFP_NET_CFG_MBOX_SIMPLE_RET 0x4 #define NFP_NET_CFG_MBOX_SIMPLE_VAL 0x8 #define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_ADD 1 #define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_KILL 2 - +#define NFP_NET_CFG_MBOX_CMD_IPSEC 3 #define NFP_NET_CFG_MBOX_CMD_PCI_DSCP_PRIOMAP_SET 5 #define NFP_NET_CFG_MBOX_CMD_TLV_CMSG 6