From patchwork Wed Sep 7 09:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12968735 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 56BB6C38145 for ; Wed, 7 Sep 2022 09:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229528AbiIGJsf (ORCPT ); Wed, 7 Sep 2022 05:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbiIGJsd (ORCPT ); Wed, 7 Sep 2022 05:48:33 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2121.outbound.protection.outlook.com [40.107.100.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C969B5178 for ; Wed, 7 Sep 2022 02:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bVcv6sKM1EfdstwbpqmPI4o0BNAbPNT7YhVNrBiZaimCV83gIKmXzelzzC/BeCPAA6XCjoCFktRrDxJF2eAeq6GChbCyhY+Elt83eWC6rKl6qqsFUS0bJpqKdmEQi6w9Nt1Rc9OyxisLyOhlPvbz7KW095F2tcMBsNGLRiofYYU3TtGa+OodmjDyVYcW8lYgxkT11R49ECHGPkgqvh179scL7k30Vz6KLoXINVfNAeHd+IPo24PKuA3IIIDCwCpeHd2N3h/iOK+BTSyuWzX2mtovwpwwY1+iKS45YM98xx60H60Wkx54Ed/aZmXIDTPVJTlz93w0nF3TbmOb/Lz6SA== 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=Qb3kj1NeRXaKQLhqLo1c9EyeIGq8ShY0GE7IYzN0pek=; b=Il2DDrqz0C/Er3jLuNzYtRhSoJp8nEykq1IYn8Fp+z/u6/yQtn8s2CEnMrA6bcuQM8CVDNSZpRAqjWPrDorYhodLFiBv+9qnE0aL+I1XFmdxq/aK5Zz7umi/TlJ+SPFmCMSUHcPQkVJ3gHlXKl1U0LNeBK0JG3anxuxfafTycuYV7cd4Mpj9w4fXiXt3jazjZWNzTSf/jQJrF+pTgz1/9JuKexchgeMtPnNFKaqAxITOyHROdNzfJpXyVursTvBRtylRkPas86FTJbpRcCwteyp+FM98eCn0c25QkyIswajYS2jQO9p4ifySIl6RmVROAwRR4F9UogYfyukM6OYjZA== 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=Qb3kj1NeRXaKQLhqLo1c9EyeIGq8ShY0GE7IYzN0pek=; b=OlDqJ+vLwhexKrBqi1OTyfSSQkKa4N3Bqa+d6/iWrJrEOkKOtaJNde/4BrL/ggoNvHi6DEazmxD2BuJ7Gia4GyRS5IMbyaPNxJGS7G65AdwNOlnaSPwUwrmzlDF3R51QM+oLG01GA34qD9sJ//vSmSCsV/aGHBMst2sLSxeyDiQ= 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 PH7PR13MB5617.namprd13.prod.outlook.com (2603:10b6:510:138::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.9; Wed, 7 Sep 2022 09:48:25 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%9]) with mapi id 15.20.5612.014; Wed, 7 Sep 2022 09:48:25 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 1/3] nfp: extend capability and control words Date: Wed, 7 Sep 2022 11:47:56 +0200 Message-Id: <20220907094758.35571-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907094758.35571-1-simon.horman@corigine.com> References: <20220907094758.35571-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR04CA0093.eurprd04.prod.outlook.com (2603:10a6:208:be::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|PH7PR13MB5617:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b4a42d6-e20f-4ffa-5478-08da90b61b98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nIT1S1dP2LkbACeUdE4+xomyvP8C6TMyeRQiKLxGhsArx0q2yRgyQ46C+9b5FNPd+E0n8CwtorfM7eGrr3azKLY1BAuniQfq6R3z6kcPzXjZH1KVDX9x/SZE9VPH0JEepF7k42mFU0b+ujPY292Kxaei+3FrMXcgw9MAGN7rvwueCZdjtyge0XZd1vujIgpdMo71nBG/GhxVNqEVwHgSgKC14MMyJ7O0vp6vIKKY3zGleDCGVygmkDU3wws1DEuoRoDQvBz2YvkvF2sV/Zfph1Tvs+vpNDqsy87HOp6CIk+idG7VREZrthbzek3mZRQff+oVdZljUYq3OgTduzubcWkQVgigMQQb9ah15v8AwaNWgGfwWRw4sIWpJCamoMszVSntsBxp9LNQhTYBcPIJxd5pByRrU7egFAGY09qiKKQSpb8viD0aKKYs7IQ1nHTYppxHPS6g6lHw9k+Ra5Ak+JopC9a9RzmCoAkegEHKctxq24zLWqRvd73M2n8MD9tWdDJFqlPWWSJ5Exo7H+6vOYt64UTSIYFFLpMjtMkFsMI3nG6R9F8IFHexRsL8ddl+LDfrs2C2Obp8s2Mxhcy2JezE+JJgB2FVGLvEqFVpi56m825G+cWzEW3ROW7UY4Sf2s0MArk3r5j7L7kUAvo8h3S/siIbHZ9fegHBFyrjiGyMlFQaGuvYchEDLgWkw5qqAxFyQ0jOrHDrkirSO8fRpYwUHdpwsk1J2edeRxV1N41rzxcNBXyX0dP4paQtaaGx 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:(13230016)(4636009)(39840400004)(376002)(346002)(136003)(366004)(396003)(186003)(66476007)(38100700002)(478600001)(52116002)(6512007)(6666004)(6506007)(83380400001)(107886003)(1076003)(2616005)(6486002)(41300700001)(5660300002)(86362001)(8936002)(8676002)(44832011)(66556008)(66946007)(2906002)(36756003)(4326008)(316002)(110136005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GBexknM6WL4814CPY8EDNX9lOpURWfVc8MzjQHAvOkjIevFcM2I0KolMj79RmHV4ymCY68LhwIUH+3xI+Ynyo8sHLvtwO9kW5EYFCbl8JHpt/m41os8lBgkh15bCWwUsWO14H5ne+LL0nlN/dqdTE60ucnPHBG9Jnof300155XuAq2EspL/ze9VFroOnCIfGuUssfWhYl6oN5cCbc19gEUcXY2i1/cZM3sc9QSHp4ds8dNARa0QJ5TvPwdk8L93jYAm65TMk6WUH0fgZJLs2dlWClSOlENs1qJ0DVEt9wASimddcLxJAU8t7LYNA+zsjuDB5Vt3jxWbJG0oASLn8/H0hrQMkmUM5Jk0wHI8wuwGh5xMf+ba0IcBul2vUeFqQ71UlHQJE5OIDsMTGxxEVgKxt5Y9itDhO9+SGk3MCcNlr2QZBQdgtyqvEVQ6KbHdJCIr5nvGOGjDQOCvEa5/z4CJcoZ4D+COFBxyBrd3u/01wFthNuhQxcTbQ9tG2BxS1aSCNv5Km2DPLiMkbzCaU1r9wFQHCRp/ea11Shu5FVZ+xJe4h1mPjF9qVz5JuvrHy9znPNRLd9hIDnFkyH6NixpwemsUzrbILkEew8pC2XNYQBTvhIhy/FNQ9a0VWw6SCrvx3lIFjuj21CXFP6hOqk9ufG6tKGixhl+dZRXXPJqpJ+BbI3dKs7ck2kN+g+6UGX8Y9YcJ58bsr599Hrpms07feTah/E9VaWLEXKA4a0P2gbNAsRmSzz5hRdftcdeWDbvd7sy91p22iaHd5Q8EJLXdAms7uG7r10VdMonCZYf7XY3NJCM1Q4yvVGQodyxNEvqST8dLE/Q5LZ9oTa5U05Gstx+n9h2eXaGPzeEDJviB6TtIxpSr0ZtGRR3GBEKbLAtx+ILPxEYZhz7jOlHLm0L+ATeCb1AYoWlsEA7LMMyqaLWL33NR2STCLC6E7pinqJhkcC3LA8m8rFnV7J9fugwzcF7pEmIkt9Y9m4PlcpoBiMyZ6t+YU1v5eGMxDhB2DwlZ/sk4SmrjkSSrIcMZKa+9BxKaVVvvRagAvoJkXXGuNx6DU6+kRzHntgn8QmQGrhx+ihDOfhSFkaxMFZawTxfI87RD79nPAT6HDMZi8pn1uYRy3lCiuv4zdDcKJyyA44ka9Tfd3kgRDEtWIX/ajWCM/YOC+vuB93KsDI1YK3aP0nsAFEu2Q/fjitvVcPKUr+QjLwC+3WLW4m3Jajv7xBFtu6Zoqwgof+RkYu4Nk2zrQUIuWkEwckTdk3KUknmWP2hDCPhLF9EZrLKXfGISUu0on6DwlB4AV7B8iJv9cHi1lJAgJvXMX2qVXLwumqTXZzMpDBKjakdf3mFNYWtOkPC5Q76nhKj/az3jn+4uvhSW0z7MHmKqKlX6ziAcogbrWcXrRWRcZtd4N/joheHhF2tegkdhXCCawrxNTX2B0EKiZ81MiTQvNHpw5FNTINitpHPkkB34Evyn40LqWIVomYWV1Jd9fQNuc6ZUejWen+8O3jIybZ1y42XPJNYzk+Tcqv3w0NrM7dpkhh+LiQxlsq5QlmEBNfTxxgtE39vcC2+64gk6F+GDieVQchpIzwR+nHqNWPQMNT5bPJN8lqIxMY6ItefS2PjfYqJPVqZvnjBdVtduYpiWXensIPGm5RNT23KrOYbdl6EsYzLZHjst3sA== X-OriginatorOrg: corigine.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB5617 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 --- 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 469c3939c306..7e4424d626a6 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2456,6 +2456,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 1d53f721a1c8..80346c1c266b 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -254,10 +254,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 Wed Sep 7 09:47:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12968736 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 6EC3BC54EE9 for ; Wed, 7 Sep 2022 09:48:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbiIGJsg (ORCPT ); Wed, 7 Sep 2022 05:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiIGJsd (ORCPT ); Wed, 7 Sep 2022 05:48:33 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2105.outbound.protection.outlook.com [40.107.237.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C2C29C210 for ; Wed, 7 Sep 2022 02:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AMk8XDeUbG49uGTlcIwhT0SafMIdnWNGfP7cU+v5mi8cck1wV5GNGiMuxU3g4klMyeR+9uVNMuTAJfeeDSdqFz4zJmN87oCkuwk6aRfhR6NcrRIej+cREOvsa164S7o3DbrhxvnqG6GKE60wVEqyAV3CfYTT4P5o/JTph9We4wA7Evkl3XiWCQiwWY+0e2makua8M5+7oeU1/G/58QWesR5R6lSGRab5SxnS4GSTnUoJRKr93l6GeSTTqM26vFdfOtM/3fod9zbk5ZMBarRtf2Tls1xU+Kc/3lr7DwIcreOmmGqyG2fCITZXFkruwSjapb5OxN3B3xtCvf1mfrNhfQ== 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=xlAdpUiLQVJxQmQi30b7N8yuPmyj6yOsax88BqrRaZk=; b=WNLl/P4aUiZsdSuC9/qN7HkmNtxtVqYVPIGR4BEz1/d79YH6T9YBhaNe3N9k2QSXFneHJVS4Y+SS5apiz3O+klJCsdynL+OWG2W9uKZ7XNs5reCvP7wlnTQSw3QDvoaLyNSPl/+AybNU1Ku3GX3IWflGR+rFR6B2uMwUeradGC8Yak8vt+R0i0utqUcRFpsJ+u3nUJXAdd5YJITYADf0caTnHFvca0dkcyhO2UMreeCmLwlOYmB0HbRFXmwknjMk8ycWPQr/XJ5dvFOl89rHyUmsAUm89T2j/odz5ZXz9rMTxH6e8iQVq/L9micDvwkC6Oe/aWcEj94NE6voJuvL9Q== 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=xlAdpUiLQVJxQmQi30b7N8yuPmyj6yOsax88BqrRaZk=; b=Q6tlVrlcnIxRKfzz/AoFlQLkXkMp6Wl1zAXW+QKCbbxh1G08d8kCKLrJGNv/NuQumFp1pjgisoj08TU1Y/QZkurRFIBgPmSrmXkVw5yII+j/Mqy725mYjF76E+6s7tA8uuUs6cUwrOxPHJxhl1pMApk/5Muma7h0C9xWYWe6qxI= 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 PH0PR13MB5876.namprd13.prod.outlook.com (2603:10b6:510:168::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.5; Wed, 7 Sep 2022 09:48:26 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%9]) with mapi id 15.20.5612.014; Wed, 7 Sep 2022 09:48:26 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 2/3] nfp: add framework to support ipsec offloading Date: Wed, 7 Sep 2022 11:47:57 +0200 Message-Id: <20220907094758.35571-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907094758.35571-1-simon.horman@corigine.com> References: <20220907094758.35571-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR04CA0093.eurprd04.prod.outlook.com (2603:10a6:208:be::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|PH0PR13MB5876:EE_ X-MS-Office365-Filtering-Correlation-Id: 4362d212-7139-4f48-9499-08da90b61c59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ccpDzDHXPpX+FY3am1+rrUBU7bnpkmktALUdKExShiNWtYtbesbuo3KIeBCJl+Amborv+6b/avoE5neuJoJZpPR0Xdlet8YlP1zrBpeRRqna9G1Fl/iEXIm3bsTEms1EC5x9nELENaXxWqcY60MLdX5XbKld5mQDxCnkcG6KOC/KDN58k5o5ejhoqu+I1WRXfJ41gZ9E4weHfjwkpMdm81xTIYa0KM1D1PgH2V4md6mwqAE9C+23A5HpXpobdRTweTQH2VAsDT0vpMjoMk7v1VyYW992AXdoPT/F+yzvW/B1ner+eRI0i6mF6zk0AEH4OMoixQaHL7D/lTjaTnQtJz317wiUffeulGhZuLk6i2QLEmgVzc62NQzxbmgrJ84dBa2tfFozlvHZ1GbR0etzZhnPVrfV8WTPdVOCMCMxgpOujJSscA3e2qW2brFjYMDpVVdnxC7VEMT7xty9n3/pHFknq54a6+qOBb38TzEXPqRnn7k4UnPVpefm8cp37y4Q0MhNOfolvHZhIE2qIF1x7/vL8C7fEejQ6KKo11Eq1hRlXE49q/MxJjrqnmuzJsy5bpXFZgrJYZKdKoYnsjgTKxxNQ7k68BwoyRwG3ZYtiYkCnK5Os3FfwoAY0fzMM2aubjSUfOJnFCH/XhowWgnOkvUlmcGk6N6zFUHAouHJG/w/O503mvoDyzeE91oieDTmzkwLp1iNXktvE0n9TW59A80+M/N3bVWpLIyiSNx1+Stxj+ufHFzNIj8IcPmVPVA7LhXB/hPzLWql+XYKSTqdsg== 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:(13230016)(4636009)(396003)(376002)(366004)(346002)(39840400004)(136003)(36756003)(66556008)(66946007)(4326008)(110136005)(316002)(8936002)(8676002)(5660300002)(30864003)(478600001)(44832011)(2906002)(66476007)(6486002)(6506007)(52116002)(1076003)(83380400001)(2616005)(6512007)(6666004)(186003)(107886003)(86362001)(41300700001)(38100700002)(309714004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oLqmTlu3ZSqszz2LEO8tbgbyaujvDeNMv9J2xMTxukv9tzzsQ24LhqafySXS2bWfWZKkhBS/QfEgQcOf9Ehp7ORWqEq043BE+CgK3SOAx9HVZaMyfvLVjIqbCWl3PQzRNiRU5wFT6UHD63CgN5hyA6MJxVdoFm+vMXtcmZk0pguZhb2Y46GcxvwFvWQvbGlF/rPLhppQrcYhq9QkR2o7VCqi5tjS1OS0zYdKGF+Ge2kA5/AEbmoDfWo0Ejy9qxyV0B/FeeYPd10fe9h6fGxI+rUKQ7an3cJVBFMwEspf4bpbJ7agd/HmIdaVwIouo1vLFpYAePZ/cTuXyKb3QoWbDorWxUtdS8m4gkS7JRagxBWBkSPFjmJvjU8OGcwDNjuLMRxyafhzd0GkmYcgJOgiY/bMRCArWhzghli6IHJg8fDDTtTnOFr7BrQ9ggaO4bC42aQj/uQLpB/Gd6tcu219+eFf/Jzy5sHEEKn6WhDqJL1IWlAlwmgffQy3Fd6CuX1/tGEGiRlvLyHZa/gvZPgOfEgbbov71SxunNz9luhzCpDu0MBDpbY0wxg7s9axniADxfA1mbF944HGAxziwS3ysqNlDcBL91vYfXuwq/3xBRLbh/ItgqzfDBEUup5hW/lELSufCMX07l2bJtXXZJCXzZrlghwySPiPJi/1p+j5CpvSuzQo4NsiARkX2txtteGdufhFZS9hPM4g7Ec9kVuwGKS+/TLRq6Tp4vGu44LLLt72SCOvoT3hTueIOctF1FBBj6EiJNEnh0nr1lpQU/x2UnfieREl/nmm5AcV0lLPG8j2hvQMChj374gRFo8OXjuoAXmbrXtvHbRLY7RHQjJiQufjeNy4a6Ugr2G/g5eNY694Z+86aQV8Ulbu8zzHCwJhbiBBXrju2xgm+WZ6O5WxpMLVUSiMRhpA+apDtlO0nKy8T21FNZzzbA6rAXRhYsv+12JT6wbFUYBcHcaNBPc/dF+dcnC5gEi0V1YWAIpcWhZ/Q1Vz7C9sgEx6S0ukkOpdwLGESg/VfwB9cvxcF1eQ5X7VIcROsR0FNfzDE4ucLj9yU4XihFIqDWPCG4+nnmvj3JglOegQxzZyxvCXITJ11Ls6lIRtPySAMAb4DOgJqSp9HLC5DUrU03F3k1FdFlTf3OR4il62+qKHobOzRhuHwZnvsIp9JRqMouwL4nb/aOnsBak9ja3ZKi3i8pwZInM6/VwApLbAnkREMBMtU5CQk7/XKxgd9tHFoXGUc3UDmXKtUsUxi7iXfLFFgADaXe8x8hVMncXOo+VNvz+vK3Ov1nqWqSAC1gOpmTL4Hszu0TTM0l80ClrWZ1TDUzjP2oPclwlZ5v0PmDfrSD+CWqZf2y5x0+SO/mWGnn7CfCI/u0bVlkpBCcZKNBPBbg5V8sTGTlQQI8scbGV3/KSAFyxP03jL2XTgw6IaEoGy8VmIGuvaxeEgTyaPKbuD1Ija7YMtKLtjRUJ0jNdjzO2Myrw++qRYnVReC5+KFViLfrV9EB0uHuRiwnnhbgEZOpH9v3CjUMYlPQXDb39/eCUIXE53Eczgaw98aZb9J17EIcTm61CqjSm+t/s4GOuYiT3YleW7PHNCflTgqFLaoAMPKgzpEXS6bD6Zn8827XJbgkKbFFMmifrWu7Lqqwl1Er//T7XuQab0KoH5GlGNeFjeOLcSjg== X-OriginatorOrg: corigine.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5876 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 --- drivers/net/ethernet/netronome/Kconfig | 11 + drivers/net/ethernet/netronome/nfp/Makefile | 6 + .../ethernet/netronome/nfp/crypto/crypto.h | 35 +++ .../net/ethernet/netronome/nfp/crypto/ipsec.c | 216 ++++++++++++++++++ drivers/net/ethernet/netronome/nfp/nfd3/dp.c | 43 +++- .../net/ethernet/netronome/nfp/nfd3/ipsec.c | 19 ++ .../net/ethernet/netronome/nfp/nfd3/nfd3.h | 8 + drivers/net/ethernet/netronome/nfp/nfp_net.h | 9 + .../ethernet/netronome/nfp/nfp_net_common.c | 10 +- .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 + 10 files changed, 354 insertions(+), 7 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..7f669d39e471 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 offload support" + depends on NFP + depends on XFRM_OFFLOAD + default y + help + Enable driver support Ipsec offload on NFP NIC. Say Y, if + you are planning to make use of Ipsec offload. + NOTE that Ipsec 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..3d33b2838e0d 100644 --- a/drivers/net/ethernet/netronome/nfp/Makefile +++ b/drivers/net/ethernet/netronome/nfp/Makefile @@ -80,4 +80,10 @@ nfp-objs += \ abm/main.o endif +ifeq ($(CONFIG_NFP_NET_IPSEC),y) +nfp-objs += \ + crypto/ipsec.o \ + nfd3/ipsec.o +endif + 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..a27a378e3ebe 100644 --- a/drivers/net/ethernet/netronome/nfp/crypto/crypto.h +++ b/drivers/net/ethernet/netronome/nfp/crypto/crypto.h @@ -39,4 +39,39 @@ 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 int nfp_net_ipsec_init(struct nfp_net *nn) +{ + return 0; +} + +static inline void nfp_net_ipsec_clean(struct nfp_net *nn) +{ +} + +static inline bool nfp_net_ipsec_tx_prep(struct nfp_net_dp *dp, struct sk_buff *skb, + struct nfp_ipsec_offload *offload_info) +{ + return false; +} + +static inline int nfp_net_ipsec_rx(struct nfp_meta_parsed *meta, struct sk_buff *skb) +{ + return 0; +} +#else +int 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..658fcba8e733 --- /dev/null +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -0,0 +1,216 @@ +// 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 */ +#define OFFLOAD_HANDLE_ERROR 0xffffffff + +/* 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 */ +}; + +struct nfp_net_ipsec_sa_data { + struct nfp_ipsec_cfg_add_sa nfp_sa; + struct xfrm_state *x; + int invalidated; +}; + +struct nfp_net_ipsec_data { + struct nfp_net_ipsec_sa_data sa_entries[NFP_NET_IPSEC_MAX_SA_CNT]; + unsigned int sa_free_stack[NFP_NET_IPSEC_MAX_SA_CNT]; + unsigned int sa_free_cnt; + struct mutex lock; /* Protects nfp_net_ipsec_data struct */ +}; + +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 void nfp_net_xfrm_free_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_state_free = nfp_net_xfrm_free_state, + .xdo_dev_offload_ok = nfp_net_ipsec_offload_ok, +}; + +int nfp_net_ipsec_init(struct nfp_net *nn) +{ + if (nn->cap_w1 & NFP_NET_CFG_CTRL_IPSEC) { + struct nfp_net_ipsec_data *ipd; + int i; + + nn->dp.netdev->xfrmdev_ops = &nfp_net_ipsec_xfrmdev_ops; + + ipd = kzalloc(sizeof(*ipd), GFP_KERNEL); + if (!ipd) + return -ENOMEM; + + for (i = 0; i < NFP_NET_IPSEC_MAX_SA_CNT; i++) + ipd->sa_free_stack[i] = NFP_NET_IPSEC_MAX_SA_CNT - i - 1; + + ipd->sa_free_cnt = NFP_NET_IPSEC_MAX_SA_CNT; + mutex_init(&ipd->lock); + nn->ipsec_data = ipd; + } + + return 0; +} + +void nfp_net_ipsec_clean(struct nfp_net *nn) +{ + if (!nn->ipsec_data) + return; + + mutex_destroy(&nn->ipsec_data->lock); + kfree(nn->ipsec_data); + nn->ipsec_data = NULL; +} + +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; + + if (!xo) + return false; + + x = xfrm_input_state(skb); + if (!x) + return false; + + if (x->xso.offload_handle == OFFLOAD_HANDLE_ERROR) { + nn_dp_warn(dp, "Invalid xfrm offload handle\n"); + 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 nfp_net_ipsec_sa_data *sa_data; + struct net_device *netdev = skb->dev; + struct nfp_net_ipsec_data *ipd; + struct xfrm_offload *xo; + struct nfp_net_dp *dp; + struct xfrm_state *x; + struct sec_path *sp; + struct nfp_net *nn; + int saidx; + + nn = netdev_priv(netdev); + ipd = nn->ipsec_data; + dp = &nn->dp; + + if (meta->ipsec_saidx == 0) + return 0; /* No offload took place */ + + saidx = meta->ipsec_saidx - 1; + if (saidx > NFP_NET_IPSEC_MAX_SA_CNT || saidx < 0) { + nn_dp_warn(dp, "Invalid SAIDX from NIC %d\n", saidx); + return -EINVAL; + } + + sa_data = &ipd->sa_entries[saidx]; + if (!sa_data->x) { + nn_dp_warn(dp, "Unused SAIDX from NIC %d\n", saidx); + return -EINVAL; + } + + x = sa_data->x; + xfrm_state_hold(x); + sp = secpath_set(skb); + if (unlikely(!sp)) { + nn_dp_warn(dp, "Failed to alloc secpath for RX offload\n"); + return -ENOMEM; + } + + 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..db53e0392923 100644 --- a/drivers/net/ethernet/netronome/nfp/nfd3/dp.c +++ b/drivers/net/ethernet/netronome/nfp/nfd3/dp.c @@ -167,14 +167,18 @@ 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; + *ipsec = nfp_net_ipsec_tx_prep(dp, skb, &offload_info); + if (unlikely(md_dst || tls_handle)) { if (unlikely(md_dst && md_dst->type != METADATA_HW_PORT_MUX)) md_dst = NULL; @@ -182,13 +186,14 @@ static int nfp_nfd3_prep_tx_meta(struct nfp_net_dp *dp, struct sk_buff *skb, u64 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 metadata */ if (unlikely(skb_cow_head(skb, md_bytes))) return -ENOMEM; @@ -218,6 +223,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) { + /* The ipsec has three consecutive 4-bit ipsec Metadate types + * so 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 +264,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 +292,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 +331,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 +785,12 @@ 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: + meta->ipsec_saidx = get_unaligned_be32(data) + 1; + data += 4; + break; +#endif default: return true; } @@ -876,12 +903,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 +1107,11 @@ static int nfp_nfd3_rx(struct nfp_net_rx_ring *rx_ring, int budget) continue; } + if (unlikely(nfp_net_ipsec_rx(&meta, skb))) { + nfp_nfd3_rx_drop(dp, r_vec, rx_ring, NULL, skb); + continue; + } + 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..f0d74d6b49d0 --- /dev/null +++ b/drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c @@ -0,0 +1,19 @@ +// 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; + + 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..768539f12214 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 + * @ipsec_data: Ipsec 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 nfp_net_ipsec_data *ipsec_data; +#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 7e4424d626a6..040c0c2aad80 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2565,9 +2565,13 @@ int nfp_net_init(struct nfp_net *nn) if (err) return err; - err = nfp_net_tls_init(nn); + err = nfp_net_ipsec_init(nn); if (err) goto err_clean_mbox; + + err = nfp_net_tls_init(nn); + if (err) + goto err_clean_ipsec; } nfp_net_vecs_init(nn); @@ -2576,6 +2580,9 @@ int nfp_net_init(struct nfp_net *nn) return 0; return register_netdev(nn->dp.netdev); +err_clean_ipsec: + nfp_net_ipsec_clean(nn); + err_clean_mbox: nfp_ccm_mbox_clean(nn); return err; @@ -2591,6 +2598,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 80346c1c266b..fff05496152d 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -45,6 +45,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 @@ -52,6 +53,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 @@ -260,6 +263,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 Wed Sep 7 09:47:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12968737 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 6D780C38145 for ; Wed, 7 Sep 2022 09:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbiIGJsq (ORCPT ); Wed, 7 Sep 2022 05:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiIGJsh (ORCPT ); Wed, 7 Sep 2022 05:48:37 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2121.outbound.protection.outlook.com [40.107.100.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2609C233 for ; Wed, 7 Sep 2022 02:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HDjq2Cnyk9Aqthlyj38dMFPTcb/+AnLuQb9RDutETlEbz/fTQP+8dkB6CqiNQIYmKJ4noVrY2OacpmEPYQRGxdRASZ3I0pssr5xZL1xr06JTIw7wfNxz+hDpX8i1nrjfZjLEHNCh4ivT+DZIyHFPZZjafiJ1TppOhu5bWmQucZbSiInPD8ItnuOAgvzkiYjvRsDXpXyMhs4NmTQVCwDG5ML6ZUVu8qm/79ojWsjYUgAZqpjhFm+EWuRH9EjyoaR/Bew8mt888k25sWCuiCFcXTjazNhE9NbbRPZdwCugfkGm7GXvCs91cy2bJaB2W5z6d0KWkQcFGS7sFf9kHVP1ng== 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=C/8yfokQnqMmHWdYrraPyDVZSOqFEDZfupmO8mXxDhI=; b=FcfRR/51V+xgI4Lh/fHxVf7V5uThKfGR0FOUtbP0uZfh4TSTssvA739Z4MmCPbfjU8WpiXP3DNPNXp+CZ14cBbgA8t3XIzb/lmYLEgy7fWiDE2tyaYVB3N8+DnOVZveZXX9n8U7zLGPBS/1gJr/cQwqFVr+HW7+GKJholQBBINiIUrHe8Jfkvlgvi0cVYnGpoGiAxtJjOaCYlAn8XUUqfiLYLwEJl8Jc2/HDiLTT4zgVDMmlqIe3YURQpYxW1uCv2XQ9i/1WdHT52vjQRUMeZSfBOVsWl1NZiebCGgeXXjmFci/VkYg7NR/kVTos31L+qA83ZcBiLdhPqh0meDHbXw== 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=C/8yfokQnqMmHWdYrraPyDVZSOqFEDZfupmO8mXxDhI=; b=ieqPppOcBjwubAJAsfBtezwlP2u1lHseAjsPFs3ReEgb/qjeVqBBAXN5oRmxqyhs5gmM1bsJko5BRx4WScxywgGEzIDrmpzK0OI2hRFgDeebdUGdf6LQBPKrA9h/UoSoEOg9P8vwL4srBeO7fRFqXEsYB8M0a8jS/tctfs4dg44= 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 PH7PR13MB5617.namprd13.prod.outlook.com (2603:10b6:510:138::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.9; Wed, 7 Sep 2022 09:48:27 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a1e6:3e37:b3f3:7576%9]) with mapi id 15.20.5612.014; Wed, 7 Sep 2022 09:48:27 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com Subject: [PATCH net-next 3/3] nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer Date: Wed, 7 Sep 2022 11:47:58 +0200 Message-Id: <20220907094758.35571-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220907094758.35571-1-simon.horman@corigine.com> References: <20220907094758.35571-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR04CA0093.eurprd04.prod.outlook.com (2603:10a6:208:be::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|PH7PR13MB5617:EE_ X-MS-Office365-Filtering-Correlation-Id: e4cf4168-989c-4a0f-a87e-08da90b61d37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dxNZ8e8vrrXsFkF3xthyyodGFhfAFTl3tgtKjTy2lxHXr3UtOV8QlGxWw7WjtbvjCyOqZGYsxbp0BXP2v3s+RYfH3SI+DkUMDAXTGm+dtbMAcV82mEVEtiu1wRycF9VwiSupdtX/YO1dSQ1ccdlav2VrCvuMu+AP89NAuUEpy01H/itEu7X7sxNMUyWZGgabPcfb53uXtpyWA/xr84kTetexcCzMyRIyiroPB0HxNFTIlGH3bq1eM2DO6dNteaFVDtCxD/RH1kc3jMiCoGqSAapWu8KKPEKcUN+mFAuI6HlcTQMdQn3gaRcofKccdKKsjXc8yCeiVZdgzoZjeGOPqANhOnfp/Xy4zUVdVt0c0d+nYOtGqvDmeqR5Ou4ozgCKlt/jxvfdhOb+trpCIL1U3Ap0ZKI7QS0S5f7wIcmwG6K6UUhVnHhV41ZhFT4E5Zoj/TLt3fj9sBxG88h4cDqkrHvn78OZbdaRLmgUZVrfUmJ+BHCjwdHZ0mLmyIrcnf5HzGFoMHWQG0soNvYNJu1r9chqwC5s98yILvUCqMDmaj6UtVX0yEDHZYFLzVr78LB3U3D20RKbXuKTYDaJjeba3fgWl+Q8HLLJ6ILPIgHeLvnVAej11v556a3ke4MG8P9dfIKK/Otynt9ECdh62A/M6pbSBSaKUIXaZTM9ZNsshwILqtEPejAjKz6QxGWRzHIXhxiiQkSu77+kj2A6Q34fBKXq6wWPw62T2MxBXqiWe2es7RG4YRw159OEfSvaJmXB 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:(13230016)(4636009)(39840400004)(376002)(346002)(136003)(366004)(396003)(186003)(66476007)(38100700002)(478600001)(52116002)(6512007)(6666004)(6506007)(83380400001)(107886003)(1076003)(2616005)(6486002)(41300700001)(5660300002)(86362001)(8936002)(8676002)(30864003)(44832011)(66556008)(66946007)(2906002)(36756003)(4326008)(316002)(110136005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yld3/Pcedfzi7TsFXXlov83GbRr5qqGQIIlLC2rNnyyrZwaF3Im6adkQ5vi+oBSsij2eywEURGilOb7oXorG72qsN/q6QseGGDfTScpRm0kT4O8eCrU8mmgCNpMlGU1xToMm0keiTVXu5tYV/zlKhrsTPK7x23TEr/wST46j42Ln54my4XPkW7hPe7wP95YQbk/ipEymstLD+3yf2kTHq8qVF25xqe4NTWfHenFWH28z/C6sHXCXXZuNbqJ7lbRLQ3QMY2z6o7IqHXFS/+DuC+CyESTcUUMrr2zdQOK0DgGuoIOKrN4vffakJa9DMJg+Y2ScykMAkIlhT9Orp8N8tdN4spwxzSicsi9JS14wOvXMejtXxj3FVVoa8vdHUdDEbxcSnJ1Tny6wj1XNezeTAGrRRgKuL4fs9N/0aNy+AZRy1R4n+qDn9/O/2Kx1E8DjhKElkPJ5VJiT9Oz205PxP04da+GEg6Qn+6cxGyY73DzjMwPj1zV2Aq+cO4+KCZCrD6wA76Svrj6s7acs3J2zZ9SsOZ/4VCmSPlvMWaRSoXyUbvlxxfr+TOP8noU9r34S/ZxU+OGvTQcuRAl6N2rEAQwCAa50TNeZYYMouvbeXeq6n1yXhK8HuB79GdUdBinQYsXjx8g3GmQAuh8Mr1UfPXQ9Wo4ldTEvWUKPK6cSSFl07zC9ddF+wFQzxqQSD8aJOKyCggkwej77//79QyM73KIJeUyTZpAq0TqUbyPmMpnN+VsXiNjaqWw4A7g/N48GLo6ioFCAq0yAsUdVo7c16NSlwb9cy0B9hy/EUnTIaMdjUaD5uAW6pRMudUaO/fMprZzVEDRrx7ROOXQ3F0Iqp8AxU+97tlULJQBYHdZ5wU7hRgk61Q5IrJG10+1qYwSyxxPsRmTtlAalbklh6oPV4OgPdSGSVFpvEJMNPr7WaSMo4E6Wc+aNJZQKOH0WR/E9f1b7fiGeDfmRaNGR6XvXt1ktBojtrU4GZ4xpmOoJ7lfah50uw3FPQumkOJnrjyKcGuyR6K45kHjMIddVQh5BxLSMR4eviT5uPAATTubzKVdDEmyoOuNA0DMWVzNwIk/atSkNDl3ZQjSLexD0yKXzWX4ZpZxkGOvcP8IoYPCGeVIZFVXkE4TdKWtXs0VFgGbAFUvhPJefWjzPuj8vu6COYm4C+e9Lt5XHdr8wJUs49TPNVJ4ClsJ/zLqncj00d2YohHQX0A54+VKLb1PQYwMC3pPzRWfPHgKmFc7ibFpFBzWGpjxr+9+pLOqehLdgZsm9g2V9XiAsi7au25X7G3OAT6XGitKWhTZGplu+58KWLGwecJBdOh09CyER4My4wvxmqp4l3eBBRnVvOguStjY/dSFMCS9A8XZ79Zl8IwifiH9BI9dT1Ds6Rk/l0QM+SS+cr+rLR7N2Qu1ECYcpckbZGWtEgDKpWX1ld6Eseduj6dJER2TMj3w98JTLLFY3gQ2FOhD0xjCs9DXVmAP/vN1GDvehewi7C5wI0iYTocrM/rRYx71UH0e4cUCEZJj+FrNYqFNd2ToU09LSmMhPmFQ4yze5dm3r6KW41P1FjTk1miMjk9FadCa/ZVhpLn29LyhNMsjN91NCnd7JQPOqV4MKWWgNPbKXCnQhRwQmiSMZdfRMlbIHVNQyBzJuRKms8g82NjnTiR1vA88bAWvkQPUFUQ== X-OriginatorOrg: corigine.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB5617 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 | 552 +++++++++++++++++- .../ethernet/netronome/nfp/nfp_net_common.c | 6 + .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 +- 3 files changed, 558 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c index 658fcba8e733..4c2e1247e487 100644 --- a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -17,6 +17,77 @@ #define NFP_NET_IPSEC_MAX_SA_CNT (16 * 1024) /* Firmware support a maximum of 16K sa offload */ #define OFFLOAD_HANDLE_ERROR 0xffffffff +/* 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 */ @@ -71,6 +142,73 @@ struct nfp_ipsec_cfg_add_sa { 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]; + }; +}; + struct nfp_net_ipsec_sa_data { struct nfp_ipsec_cfg_add_sa nfp_sa; struct xfrm_state *x; @@ -84,22 +222,432 @@ struct nfp_net_ipsec_data { struct mutex lock; /* Protects nfp_net_ipsec_data struct */ }; +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; + int i, key_len, trunc_len, err = 0, saidx = -1; + struct net_device *netdev = x->xso.dev; + struct nfp_net_ipsec_sa_data *sa_data; + struct nfp_ipsec_cfg_add_sa *cfg; + struct nfp_net_ipsec_data *ipd; + struct nfp_ipsec_cfg_mssg msg; + struct nfp_net *nn; + __be32 *p; + + nn = netdev_priv(netdev); + ipd = nn->ipsec_data; + cfg = &msg.cfg_add_sa; + + nn_dbg(nn, "XFRM add state!\n"); + mutex_lock(&ipd->lock); + + if (ipd->sa_free_cnt == 0) { + nn_err(nn, "No space for xfrm offload\n"); + err = -ENOSPC; + goto error; + } + + saidx = ipd->sa_free_stack[ipd->sa_free_cnt - 1]; + sa_data = &ipd->sa_entries[saidx]; + memset(&msg, 0, sizeof(msg)); + + /* 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"); + err = -EOPNOTSUPP; + goto error; + } + + 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"); + err = -EOPNOTSUPP; + goto error; + } + + if (x->props.flags & XFRM_STATE_ESN) + cfg->ctrl_word.ext_seq = 1; + else + cfg->ctrl_word.ext_seq = 0; + + 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_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"); + err = -EOPNOTSUPP; + goto error; + } + + if (!trunc_len) { + nn_err(nn, "Unsupported authentication algorithm trunc length\n"); + err = -EOPNOTSUPP; + goto error; + } + + 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"); + err = -EINVAL; + goto error; + } + 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"); + err = -EINVAL; + goto error; + } + + if (x->aead->alg_icv_len != 128) { + nn_err(nn, "ICV must be 128bit with SADB_X_EALG_AES_GCM_ICV16\n"); + err = -EINVAL; + goto error; + } + 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); + err = -EOPNOTSUPP; + goto error; + } + 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"); + err = -EINVAL; + goto error; + } + 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); + err = -EOPNOTSUPP; + goto error; + } + break; + default: + nn_err(nn, "Unsupported encryption algorithm for offload\n"); + err = -EOPNOTSUPP; + goto error; + } + + 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, "Insufficient space for offloaded key\n"); + err = -EINVAL; + goto error; + } + + 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, "Insufficient space for offloaded key\n"); + err = -EINVAL; + goto error; + } + 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"); + err = -EOPNOTSUPP; + goto error; + } + + /* 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; + + /* Allocate saidx and commit the Sa */ + ipd->sa_free_cnt -= 1; + sa_data->invalidated = 0; + sa_data->x = x; + x->xso.offload_handle = saidx + 1; + err = nfp_ipsec_cfg_cmd_issue(nn, NFP_IPSEC_CFG_MSSG_ADD_SA, saidx, &msg); + if (err) { + nn_err(nn, "Failed to issue ipsec command err ret=%d\n", err); + goto error; + } + + mutex_unlock(&ipd->lock); + + nn_dbg(nn, "Successfully offload saidx %d\n", saidx); + return 0; +error: + if (saidx < 0) { + ipd->sa_free_stack[ipd->sa_free_cnt] = saidx; + ipd->sa_free_cnt++; + } + mutex_unlock(&ipd->lock); + x->xso.offload_handle = OFFLOAD_HANDLE_ERROR; + return err; +} + +static void xfrm_invalidate(struct nfp_net *nn, unsigned int saidx, int is_del) +{ + struct nfp_net_ipsec_data *ipd = nn->ipsec_data; + struct nfp_net_ipsec_sa_data *sa_data; + struct nfp_ipsec_cfg_mssg msg; + int err; + + sa_data = &ipd->sa_entries[saidx]; + if (!sa_data->invalidated) { + err = nfp_ipsec_cfg_cmd_issue(nn, NFP_IPSEC_CFG_MSSG_INV_SA, saidx, &msg); + if (err) + nn_warn(nn, "Failed to invalidate SA in hardware\n"); + sa_data->invalidated = 1; + } else if (is_del) { + nn_warn(nn, "Unexpected invalidate state for offloaded saidx %d\n", saidx); + } } static void nfp_net_xfrm_del_state(struct xfrm_state *x) { + struct net_device *netdev = x->xso.dev; + struct nfp_net_ipsec_data *ipd; + struct nfp_net *nn; + + nn = netdev_priv(netdev); + ipd = nn->ipsec_data; + + nn_dbg(nn, "XFRM del state!\n"); + + if (x->xso.offload_handle == OFFLOAD_HANDLE_ERROR) { + nn_err(nn, "Invalid xfrm offload handle\n"); + return; + } + + mutex_lock(&ipd->lock); + xfrm_invalidate(nn, x->xso.offload_handle - 1, 1); + mutex_unlock(&ipd->lock); } static void nfp_net_xfrm_free_state(struct xfrm_state *x) { + struct net_device *netdev = x->xso.dev; + struct nfp_net_ipsec_data *ipd; + struct nfp_net *nn; + int saidx; + + nn = netdev_priv(netdev); + ipd = nn->ipsec_data; + + nn_dbg(nn, "XFRM free state!\n"); + + if (x->xso.offload_handle == OFFLOAD_HANDLE_ERROR) { + nn_err(nn, "Invalid xfrm offload handle\n"); + return; + } + + mutex_lock(&ipd->lock); + saidx = x->xso.offload_handle - 1; + xfrm_invalidate(nn, saidx, 0); + ipd->sa_entries[saidx].x = NULL; + /* Return saidx to free list */ + ipd->sa_free_stack[ipd->sa_free_cnt] = saidx; + ipd->sa_free_cnt++; + + mutex_unlock(&ipd->lock); } 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 if (x->props.family == AF_INET6) { + /* Offload with IPv6 extension headers is not support yet */ + if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr)) + return false; + } else { + 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 040c0c2aad80..0e48e2887278 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2375,6 +2375,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 fff05496152d..b7e62d1186ca 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -399,14 +399,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