From patchwork Thu Nov 17 13:21:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13046876 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 05830C433FE for ; Thu, 17 Nov 2022 13:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239951AbiKQNV1 (ORCPT ); Thu, 17 Nov 2022 08:21:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239934AbiKQNVX (ORCPT ); Thu, 17 Nov 2022 08:21:23 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2121.outbound.protection.outlook.com [40.107.223.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D70D259879 for ; Thu, 17 Nov 2022 05:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Arv0rFTSAagBhlNIrd/1RiPds5+hjovHwgE59jrFkhfzrqEw8u66f3x3mkMHFl/KXyqz+fDLvmEcq1/9djGnLMm77gfl2RctKJvLXaA7Gcu2mvZ1NDMQG89vfJQFqPwqHA3RKZrZjk0WAa9Wx1sTKb7tLrGIHY+hWvzmSo87ZUBbNCAgXFucrJ0yuoVj39KFXckH+1x/l8y4iuezXdWKvnqIC772Kg6ZddrMPOR67tP6IMpeMGnroCTTLzTXvoiNvHfry4p+kkVPgIY+MQQZ95wwFb9hKU4tafVWE0phYGwGfC2lkBcZEqvgkj7+2pfa2GFxCOb3bA5Dhfx1zwhR9A== 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=EJ7za6X8cqf0I7KOCsw/Dpu18MZRDovmok34kyE19xs=; b=lJTGr12NxjKiLvCkWpnNarrfVpJ1M57oLek132olo0WqNJCPpfj/Pa6uEDveztTNmezXUI4XnRhYdZubHx1f/ysrrr40hxU8pyNQuuyvWPeW9WZZXglrTkqo9s5Mfo6FEWBy4kYEWIFgBhlEqSCIlql/Z1rqUgai02ALYGeEo8g4acyXhI+vxVP9GNwWhVM4SPHSbiiQF+QXajcqbU1UT4kOuU7g6H6CukVwD9NcqO623vPst8rkFPbeVHM8Fks0yILT0iWXTjqLJSGRqWIOaZoXNAfeeZVJsa2ST1BgaS2QtIM/bdNQobMtPVsDKEcz82CFT9MjJD6Yb9VRzbhmYA== 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=EJ7za6X8cqf0I7KOCsw/Dpu18MZRDovmok34kyE19xs=; b=qe4WNOn4QPIHDHaNEdxeh8mILpItwcwQ1OGpqweTMBLL2YbHUGe8Zgin+R1s+sNg6p/o4WJx+nuhHAwcTixj9kdQg+I+kPswMlPkQGksVV5upbZaTYkTfupGxzoNk0+Y399S7IsYnqKC9OFHeEk/A8dInY6HV+ntnNe9jls9mYI= 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 MN2PR13MB3792.namprd13.prod.outlook.com (2603:10b6:208:1e8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.18; Thu, 17 Nov 2022 13:21:21 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%8]) with mapi id 15.20.5813.018; Thu, 17 Nov 2022 13:21:21 +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 v4 1/3] nfp: extend capability and control words Date: Thu, 17 Nov 2022 14:21:00 +0100 Message-Id: <20221117132102.678708-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221117132102.678708-1-simon.horman@corigine.com> References: <20221117132102.678708-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR03CA0101.eurprd03.prod.outlook.com (2603:10a6:208:69::42) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|MN2PR13MB3792:EE_ X-MS-Office365-Filtering-Correlation-Id: 35a515f7-05d9-436b-c841-08dac89e9e5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a4QxeSVL0ntYEXqbtMeFBewLxtBdClqzO4GAJYOD/mjQGE8IuH3WaFjGASOjaSM96U08Da5KBPvobmW1r/DmRFA58KokIy0funk/QqWxRq74RVIDMM4+NdJZzkWkOw/ZkbeM3B1HMVaHAshABwYvhsMsi4Gy0UUVM3J5/DHR04Qtftn8BBmABrz8PK1emIB37vHe1vyobKSe9pZqNUnOODwx3hQEjwpJXXAsg7tTpi43nA5WUrvBOMiL5GuSJ+tvg/s5n/h4hypKHkT8qIXwj4+wR2qHYWnnlTNe7/GrH5tLea0T5jVs6PMjBE4cNDP2pJqZRa/Ggje9rAIcaEGa46ESTZrMl0jXHlaK/y+7ZbwmtSV5PCizRsnkn4dNLr8y5CmUMV3UcPfJ6FIbOvrziCw6f+muPp+jFGOOk29K64hcHePi7/7sr0TyfX7+yU9HiTqbTee+4RAPaQsfAV7goo6nB4203t1l8bWwvTkK7hObBOxTT9KHqCU7PzZqZn3Iw2tokuY1bunrNQJo+8Udcpu4qXmVMo3HQNoWJXhL/Sux0BzqAY55Iad06JN8gFqvk5qK/EnOMT9k6vXVPxWLZ8+XKyAcInqQU432u9tNqSin2IEuIy+LpyjhsOs8GOiegdCj8RHk3Ui4ZhlLwi6v+w== 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)(396003)(376002)(346002)(39840400004)(136003)(366004)(451199015)(44832011)(2906002)(5660300002)(41300700001)(8676002)(66476007)(66556008)(316002)(66946007)(54906003)(6486002)(110136005)(4326008)(6506007)(6666004)(107886003)(86362001)(478600001)(2616005)(83380400001)(186003)(6512007)(52116002)(1076003)(8936002)(38100700002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UwWlpBoQ1Ljl+v7dr41qC/sHAmyGYyLHyrT/n9i+vUrTN94m20FG4CT2mq0V3Xk/DY5DK0d+ht88jNXTpNAQ7INIKtNRsVJV/KyM6UAfAmHBKrdxFtic7HBUhWduRknSJ59MHjkdIKJu1aUUB/3WwFy6f+Gew6+curUeWtusRXNvKVDmIsWqRv2N6gifBNVOnTwmgGWDZORLLsFvdS9YMdM+9Bh93SPKxptWCCgn8bHRZhcthhzmJ2eJw4T9zCWsh4wv6aHqKU4K9/tqzcoZxL/KWv91Ah50bInAVcnUKWA0CNJsz7xyugfy2YEMFhQArHMB/0tv/mwXSnSboSvOTotPpe2e2GAyGhEGdwBsB/D6pZoO3nSbwmiNASYcaIc7Qn0pu9HJoP4q/TROr+HnFsDSh0CaGcO33x+jSRQ6RwItVxQHd/0/llEdGeE35Dwfvx2If2Uvs+Li5XbIicwVUBQBHdmfsEkjuyg3bUAHWwLv5xZnEMOlVEtoKoMMeywK4hwhuDWjht3yNFllpA2R7qzPvwQT9MzWZW36QHPO+cnd338WgR18CJkvwcG4JJZ5svFp925PgYe3Tub67PB4zaf/oVGbz9fTd5WUvetNk8YdCDTXMxrQ2fNokm7UVRBrN+mPRIi3FSBb5zcIPBtKlEOi1c03x6Cq8xJcJ6kg75EyH0bPIFVihX5KSv3QXjwv+VGYZG9inWLISo/qaAf12R7UrMPZ4GpfWiQkXipB5Rf7HXKRLbJ1jIAvlPs7DNYJt9SDyuUDajm3ptCT/vjyFXLEfLtldBRRQwdgTehORthCjQIEYYUCPCHfNZAEOkI+0hDLn2vKnFxzRpdINU+fhaJSsc4wAjme83679DsoUmcxxr/yHVF6zpvfO0BlG9eX7fN/rmkQbC/GFJ4Y2Bxo5AOqKVUI1KUF+7KHoBCzO4yZoIn2rBZIRfUU5b17BluYZM8hDT3TSAw6vRSEXHbl/RPFgZWUtBAo+eT8SqD/fwudf0XLyxNb7i+57E/s/MzFRTbkQzACe+4pt4saWNcQbwLb64Wh2onqk4iBOr4dIBi+ci+HuZ8aANIG3BBZHy74EW1w4hvaNQL3T00mupc0Pec7ypJ2VVFudEDUDJ6hom6f2U1GrZc8YQOoiyxV57a+xUymKhYNjUJzLyML4UjFH2J+tCIPrax9D5T4nSv6ZWr7bLmUZqsGCnkceLVBrWnyY18diM/3LwactfQH4FNrFFs1Llj2fyzXqQggihQ4uqhubSP6aQ3Co8TS4RK7M6Yunrgi4kpYV1Jyy7O0534Op6x/kxrl+55bMokoXb2RQDCQsnRk6CO+WCefjKaT53GXFfo86cSPk6mmuVeyoM0f38wpgVIADF/41nuDr4jDdfkjEIQ1PJlIwcaq/HR4yPrUAmDppHGKZn/11tIqGT0F7KqszIvlwxLvALkY1F0CH7ONZBAh6jS2tX8EwHt8h4ckxcJBHrlfByv45PD8iSb9DFDh/lzvQJpr3RNKR5AWtySE2LrfLjOgvkxAhnV4rsOyoNYS2I4Q2sw0GIZ8Ysc7EJxwHg3HHw6sSeGrFh0UIM0r/l441X8b4ZAVPTedQTH4kV1oKLptjI3m2Myzwf6lvHMZ1E0t44Piz25QR+nMFZeOZMXxmhqIUfYKZjR2oZ/BU9En7hAXk0o5p4CwxepfSw== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35a515f7-05d9-436b-c841-08dac89e9e5b X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2022 13:21:21.6361 (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: W9IceN50rabC1P9yfSV7V31F/VR4ohJDRCS9Gd+r/TAyOMjQRMuYJ04JlHuNhjM+86xGkqPEa8H62XJKq/ufF+iRuejibNCbsbru3CmfR+A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR13MB3792 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 5620faa63c7e..3b3cad449f7a 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2452,6 +2452,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 Thu Nov 17 13:21:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13046877 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 995B9C433FE for ; Thu, 17 Nov 2022 13:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239973AbiKQNVf (ORCPT ); Thu, 17 Nov 2022 08:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239931AbiKQNV2 (ORCPT ); Thu, 17 Nov 2022 08:21:28 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2093.outbound.protection.outlook.com [40.107.101.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7386B2BB33 for ; Thu, 17 Nov 2022 05:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zr/zBCmaosYK2BEZxxEnD4KSwzTaekMG2LvukXrUWor5L2KAEln9t2sJKPzuejbMv8ZL5cB4PEJ1K2jsNyYfJ2Bx0ghH8eTbHps3y+HqR3fKNrF96DV04/Xw+dgMNKvb02O7OEbVNTogDPQZNh19nDcOs2Wo04/T8bRBGZBEM45soJX4NrlKONxivGAUXiz7xtLhffcGCGm5BSV0c916bgiV5d1FeV2a+QBf/RuPi45h1U6JpDDtvQF5nsIrJoMyiZcOkjxaDS/xHlXToJgm58lSZ0rFnKZJV8SroaxtzP/c+sgNctySbNxcBYfPMa8pAtfq/6/ZDVLD2zN+RE16sQ== 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=arPXmcURno3XJ09pYtgHNRdesoCLW7GFf6c0DXJgaiM=; b=mY72JFhqd9aTLse7iVto9J58CrDA3+dZGhNddrpc5MhPKkh8wZTx7dNq1lh0QzgdipIkhmU49bUnpCAUP+1GJ0AP0qaTwoHbrfdt8UlzRhIh8JV8m4PhXAwSgC2DBFdPAiVJaAEZ0UeZppSmAe59vaaEg/IwFzmb/zTaoHHZGPiA811a5ijKEwq4i0UQN6y4OZku9OJspfVIcIA8WQ7GKsOTAsomqGtllHVT0Oi7mKyczazspt+SqGzLlx/VyZWS4e02nM96ixf6/IFUcT/xL6lywwip0pymnQDlusuFW64/glq8BHWyffzGzMQXBO2LoDEWybNg8+Bg0Qm12Z0zew== 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=arPXmcURno3XJ09pYtgHNRdesoCLW7GFf6c0DXJgaiM=; b=oKFKA2VC3dT3fvVR19t2OrgZpTTXwOGL4R3Rq3AMyG86hB9jClD7jv9fmWeuQFG+yIbSgu+OlrGG87qa3WKlDna93rN93kIA8QE5lqR6Tf3WdnuSJXzD5jxYpOzUmSiq4YFXiPBov+oVJa0+r9l0bcYZ3oc2J5kHXCf3eRta0Lk= 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 MW4PR13MB5839.namprd13.prod.outlook.com (2603:10b6:303:1a7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.20; Thu, 17 Nov 2022 13:21:24 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%8]) with mapi id 15.20.5813.018; Thu, 17 Nov 2022 13:21:24 +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 v4 2/3] nfp: add framework to support ipsec offloading Date: Thu, 17 Nov 2022 14:21:01 +0100 Message-Id: <20221117132102.678708-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221117132102.678708-1-simon.horman@corigine.com> References: <20221117132102.678708-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR03CA0101.eurprd03.prod.outlook.com (2603:10a6:208:69::42) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|MW4PR13MB5839:EE_ X-MS-Office365-Filtering-Correlation-Id: b0461dce-dff5-4da6-24e9-08dac89e9fd7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MWx31iY8yVYUuMXrd5sv7mduPYpUMnw2A8+DmbJu4uQxCPCbs7rMe5cthmTz7//aI6Qm4SQ/70nYzyFGBCcXfjAxBHQNRfQ/yH+5v/Hm7/4G3JFbjIgxoE7dd9Ur0Jre0HgpyuPZxn49GCl9L2MwoCQr5rPYrW5tN/4YU4rBlXEG1NcmXbNadGlDrLQhVt03xTMB2a3UBwnqN6xyQ61Vn7tQcp3D6VFhzwarNfMRgnDiKiJW1lWopzK/JfGkF3XednPbZIHFTQI/3gG+eOcdQDJmCAei9/V3Xl0ZVhuVEMjKdeDQDNCFJv9vUluLNWFgo+08WsRpbo7vuxO4oDWuS0xnec+CApDVzjHYT04u5cT8hTbI/vdJcyiQKi/446CKuXpBdjlxsZvS5lzkR4vsbGbaIs/KU71mmI49gwAlSuFJkccyddhf52KRJEdSmo2PfVsYXMGVjqd1P7MqEw5+w0IV1Jma7WeClRAiADd4sYtEpZUX/o4sm0BGD6vuqfRbWKTUYOaxzIkrtToDND9yw9KUlGknvir3yKs6UPyQb21c/+UvfH1Aqzh6cOC4EGUni1Z08mIO2S6AA5nYnl67hAOFwTpmpjQUOpF7eNhxxIZGD5I0Z7BZO6Q4h1bhfyB6W7nTOcOL0Ka+tyE7GspzYwlPaZT7Grp5bK/zCbcbOG0d2a5mpvRU4dSV6kyFdnMnYofEuyjymMvOANaqjB8Yd1F8lO3pyMbjzWIPo8EHN9t+tB5+8laVA/tOJFEEB3R7 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)(396003)(346002)(136003)(376002)(366004)(39840400004)(451199015)(86362001)(54906003)(66946007)(110136005)(30864003)(5660300002)(41300700001)(316002)(8936002)(2906002)(38100700002)(6486002)(478600001)(83380400001)(6506007)(52116002)(44832011)(107886003)(6666004)(1076003)(186003)(36756003)(2616005)(4326008)(66556008)(66476007)(8676002)(6512007)(309714004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rYPKPINGLONdaYU7BtpqyJ70PerV6+WZpquOlelMijPxx2P+5MsmqaX+l60fDOaID0n+fi5MAwz/ewT542L782rWyrlVdvlUaxkzCCsGh+NellNblxG5OTN7wr5RSR2Rs+vL0F67aG/0t/Xf6rRho1yrcmd5t52kbc9r/cLl/a1obV/kZRcChHg6lx59aTljeqsiXHon75VLD7lWZAi5fG5IB6iO5VDA5VRAVXL8kY86Atyk209sYVtsi6AxTpa/RCpf9qWmyDEgGoTS2xlAKkd1GiOuS2WubraxW3hk8IgciKvLgTaOjCrbEGRMbEN2Y3VhbfPSiK31zB39/ka39rm0nnAcAUdWUgXtD4nSsgqtccT2AB9TKevRYGP/1jAifjYy7RzmmderyVuWJDQssgzTlRoXE8cUQKBFQE6UYnHrE5WqW/Oe41B6qn/7G4CF/a/T3RIDltU1dB+ZNqbqDaXG5XFw8IIsDsJv3GfmDDVCwXy9urRQQr78vCz52qvZwbfYm8LxB0Iff0BkA8W/ora3oA5ENoq8K12ZZpS/KlT08iEXR7cE8pc/LFTPk1d82uqgV6J0QzQxiTKyeByhfnIa6BOZSy1IcuslCZGZ9JEb5F/lamgGghFcmu3JYd9TppTyJD8tYVI2I191XWC0EIPsZcdHHQtaSRVVSAG3em4PT3LYWuW+6JSkQIg5460su0ZndtBPnA76FTX0GU6S9CLU+5NodHhRl6HEO7iV7CoZyl0Yrv4iBhpfpFYYCZmhO73/p+EonYW+YV7LCTJfjWrDUb0HCkMrrB5FmpJBuJv5fO4xVZF0czX8xJrGzFeq/RDY8sYFAzvD7vgxgi0RwxR66rnRAtV+zjujyvoFJ1HTTcRT3UX0wIXkkgViDHN4oZCS6zx/eQy2a6jhjdkhvKWx8k3ms3AX++ftOZZe5aUGwMvECD6Cle7x/cp7Myaa3mZhRsas5vJQ6A6Lsy5eafnD1LBO8g1mM1p6J7YTBBBy3svcQsyPwTNtMIwT8fvkCDdzm+8sbSntWfWYt3VoTFqDB5TGtgInrYkz1P2UXRgFmkUQebhrvN9t9D6y5NwuMpXL7KTA1hYb7sb+s/Kp3Wbbuz9sugBBYLh4AjLpNQqrOQYyNsvb5Nbj166Ojsi37UhfALz9vlxwUTV1b4Rs9Gjc0xw2/yzxBgWyk/wcahnGSKFzlANnPjxhzQHpTiFs0u5p89+9T3aUkgVOYygR7mZOEnbZIVO4B+zo22Cy8sjCMU0jyYUthKSaqcEd3goKwl1ptT8aLUcKPbnfyagI35rreLyHVnz5xXaJc0i0D3YbNIE9ZiC1D1KFR/1Wwz67gTkss4iqNCmOG1xyrhVTAFh1IoU4NtVyXUXLimpTGGeZ5OACJA1CI4+8eUnwampeNOP+/T0MjlY3W18qGG0FTH60DI02Uud2iITpr4s+gkjAkZnMGoXe0BBO/ZQxNJCYRaJO0x0ky5eXbCVFZs4LED5apfec/RYc8xd6Ih/jIpVsAqy/kEzYMw7ilT83O31YeC8fmTwiO+e/b9rDbqbhGreGt+rFH/9WyLi8re5Wg76nvEwfSjiG0LkkOGgS81mG5+FhIzNKEGF71fSp7BNptm5Fr/H/tMCr6yKruJXKDLPDYvadYw6JLmFEH6w6zypmfsJ7Xn57EQmHL1B3E+5tvQ== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0461dce-dff5-4da6-24e9-08dac89e9fd7 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2022 13:21:23.9661 (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: QvUhPqV5+V/7gHxKIdw1v/KOKqqoMZtq2bsIOuV/DwzfnDmGWjsk34zwvxqo+77IA2u1Kv3gzrsWX/zYALLXE92252aj3erADC289dSpqsU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR13MB5839 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 | 107 ++++++++++++++++++ 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, 233 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..154ef841e847 --- /dev/null +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -0,0 +1,107 @@ +// 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; + + WARN_ON(!xa_empty(&nn->xa_ipsec)); + 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 3b3cad449f7a..593df8f8ac8f 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2564,6 +2564,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); @@ -2587,6 +2589,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 Thu Nov 17 13:21:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13046878 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 7FA30C4332F for ; Thu, 17 Nov 2022 13:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239410AbiKQNVg (ORCPT ); Thu, 17 Nov 2022 08:21:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239952AbiKQNVd (ORCPT ); Thu, 17 Nov 2022 08:21:33 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2093.outbound.protection.outlook.com [40.107.101.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43F6F6E541 for ; Thu, 17 Nov 2022 05:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8cCqxKhdn5HJC09/yd5CrYBrfk/yz+dPWWOQzJjdGcazgA2xC2rKEte7U1jH51lapjUkl1k6KgjdTUpVDfg6lp4FEmLe6muARSZxz6/K9ijB8pSb2ldED5iVKseAiDzQDWiVzSkC9Id/hS8+0Rj9i57aRbI74jIHZGnzxtf29CgPXRAZCOUpBnARKy+idZ1g3r4pvkvLXUUZpc4Ns/5zkesgyhaRgsdNCxomjskUfqlC3Ll8h+uzI9/2iJjBTisSl7SJZk/JiTeGNGPBymY8/QFxN+/1jNL6LDGFxi7KxHyVX41GDW9sl1LKYtq03GwHYJqFTB9t2g+dfB4QwIWCg== 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=f+sUtkE8JS2lys7jFxil3Lby4hDJuR3qfJtoQmrTN1Q=; b=G8PUjqeduCaq/VXeZFKt4CXKSv3yerfZuW3fPPs8cNzmItHMXmQ8m1I+sp/8QnqF8ryNWv27/PQXEqqXnATTbWXKjNMt9zMd9mRsmJYr0p9ckoJxfg6mCZc4sJEryd1PB4R4Fe+3wHyYIfXUTSi9J93YKDJGUlRuv6WOI+jQb0Qq7w/HLvSZhVJ2iMcamn5H7jYEIEbTXcHRnFwORrZDk8Orxc5XPOT97M77Yw4oCJr4mbHwbGiUVcqyBYrBYWu/N2E+wdnAX7l5VGz5MFjJDeXyEc7BQcPRQUVIrMl3+SpM4QURZUsPlsETNrR2i/mADlYrwPIk8SFRHib6bQ80Gg== 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=f+sUtkE8JS2lys7jFxil3Lby4hDJuR3qfJtoQmrTN1Q=; b=QysXlLSWuovmMUDGleh1m+8NzURse5LkPpYtz1yOVzZJ9jAOTMyL178WaS8duao1z5dH8PdnW5dXObbjXAZTu41j3hngmlH2xG4ykR0mwcwTgqPsu/xuBeuxosksA/PJATyr79lM3UVDRn1so5BmbS3RpeRQ6sMxXBSWntJJwNE= 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 MW4PR13MB5839.namprd13.prod.outlook.com (2603:10b6:303:1a7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.20; Thu, 17 Nov 2022 13:21:26 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::483b:9e84:fadc:da30%8]) with mapi id 15.20.5813.018; Thu, 17 Nov 2022 13:21:26 +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 v4 3/3] nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer Date: Thu, 17 Nov 2022 14:21:02 +0100 Message-Id: <20221117132102.678708-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221117132102.678708-1-simon.horman@corigine.com> References: <20221117132102.678708-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR03CA0101.eurprd03.prod.outlook.com (2603:10a6:208:69::42) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|MW4PR13MB5839:EE_ X-MS-Office365-Filtering-Correlation-Id: c2108a6a-12d5-4bd3-7cba-08dac89ea13f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: htRUf5x+DQy6R0dBbim9d9Jmqr5iC242mqGnYugpZxryapL1uno+D2IvIU5F+iVrSoKeMXZmH87TWmWaiy8WEYSsJxa6kkMyCjspoVejm21q/41EioHS3JwX5oqeAf15lfMWSaAK0haTUkiRUh/2/Quzr+WCrEkeRW/1YZXFBcbXeWDpB+yyryAcO/HbjEo8Nuk61WvDdgRHf9+PVjr09H209GbhAASPMuBKGm6dnxjp+Q9WsqxKOhJNjyYfJSP+KV5s3HUdZOs2+lc1jjjAjrDZYgyxsEx+W2DhTglkkjiiEXQQWL8Jx18xFw+hwtToQCOMFIx6H6wWA7/wtse4teQIdyQCxsU5X1SBl8hTNoAYY36wq4DCgURyaIziNpwDznsQutaUeP3hvi9cDZdGpxzkrvlgWim9AwNgjOCekZRw0NtBvjuQk2fa2Vkhz+SiaPmm7/yvuvhS+wNOYAoOQZ5/zkXeA42JsLkryk15Yq9Eg+N+CckZdnM92LFN/QYcfucuFTgLO73EYxAYEk4zoRdfo494gt2qx9fe8j01TskAJZVwhKKU46nQvOArktbJ0J4XTIPXX/CHP0WUFfntwX0Di49pdiKKHKj+ZZL3PpbSz6TV24rBgCPpnpvIkfAhSTbHFYAu8LXHEryfWgKWRWDmEWH//X7aGPlwh7NZxGxrxsV/7ptH2tTImrW06oc6 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)(396003)(346002)(136003)(376002)(366004)(39840400004)(451199015)(86362001)(54906003)(66946007)(110136005)(30864003)(5660300002)(41300700001)(316002)(8936002)(2906002)(38100700002)(6486002)(478600001)(83380400001)(6506007)(52116002)(44832011)(107886003)(6666004)(1076003)(186003)(36756003)(2616005)(4326008)(66556008)(66476007)(8676002)(6512007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XuoFITcZx/m47gb/dMnI9YJMsaK1AOFip3eRzNWSMujKCRPH9Z0mz0QkXIbIA8JiRLpN9eBt2jqVCxOj+NJTwsGWFXGtBQNZgzGwWOUrWaB9zo72YmE/bwWXMFW7rQZN2qAOG9ee20ZvZNRarkqgMxy/Vgvbip6fpWA5P4rDN0EGqHI2Uv/tqclUw8QRH1LmYBGkdFhc+CUPJw1vwwnX/xr+bLHDVL4qoQkEUFl00lWt3C8Qj8p/08tKr4AFeViKoCptyoC0mrY8cFP8s4D4HUTUzu9HrGk5gF75zyeZgzA2hspqMXGIC7JSDaLIZSviTwJmUbCGcx4nCtbmcDK/Qho5KO1utcGxO2gMfIbCxIew08K674iw/7QjVdWAzGxsld8WLR49/p246uGTT84ea8+KYr7GWhEdB6j5UIEN1VPBOVgZ5ledJSxH5BCMvHYX8UIQjtpUNQTjXcEFGUHdreinEJ5kTXVZWzyFyFS93WVT6ilMLSS94OmnqHlJB+CbdtSqxN/yzcPExdoKDw7bszcTdbdNw0TBQXNaFVDp2/joAFpk9LMQWywGXThycCBElk9B7e5c5JDbymGoUlCvcKOnZdfH0rqGMYoNaiKC5UBRcSzoarKKIAmpVJ5OHsdnlHoAhiuBb3Q6iNQ0+XcRiXWyEwXZ/f/VcMah5KlUuQK8QbbA/+Fx1XGhKZpZvy1IEra/R5yMBX0n+sD7yxHQ6BMowl/h0euZJpKG/FH06in/ArIFBsn7UDoazAez2w8AqdaZDILfDMYxrcofj1TvfkC0ddsm4fTgK0HJdUG+kyGw939cogLzvaY+n99cHjAU3BsWgXMM71bASTBHDyHOBPWdmj931+qNYKugNXnHHSwPbgBmzH5LHRdpcdO9z6HhdrXZWjxhef5gksCkhNwbCOQgRiyub7SFhyFb1NCI88lSzbLWkEPmXMQ4ZVKXVpngMyiTIXMI8MSUyJe0UO9XTN2xpP3HZd3Ep3VGdGOGD1+NUhcobIinzV/9Fsj3dpTSt7+zqZfVe+7aYb9j3Fs1U+KzGUJnesRW6JjatDNXnT9vWYw1lAYF7+fuM0SiR6LO1r8VDCUW+KDm3c7OA9jtEVqec6k0W0xbPu/u2yBlNlEDa4jIO19eKAHtOPvMMpy5zg4cmr0uGeC64mdECYqiyMxUOTCNEq1mldH6jWy0nbtqQBYq7ULgwznrimr35vMZlA7TyhC2Fgvd85asxih61kuwhNhC54K3HuJEn8od6LaXGIC4W5kEtV5yTsWr5Qd9Eo1U38nBoqYXuMtHc0IH8UYKF+1JhWW5PBd/XD0lzJFkABrd5NXZkMIgKBWBS4+KDHwM5QT7FXJcNYkEe5kg4kECoZk5Pt14KXCBil3Vep3z/jiDPTv9mw7LgV5xu+6OfdPir14ODiXbD/Gr0n8LuUzQxd+adVw5l6lFr5Y1SnC1l46msmB3gzB56QTKOSZLRbQUt25zhhu/gH8IL11H1P16h/oe3OpApvI1msTXVLOip2y10WXTgI0TzXvnlEq9RJSEkEYWBsjxtGmzzozGZnBXMLf2ZFbA+kypNOMvg8OJaZfcys/toE1o7FQt4HckQYi37opaRz1PryOxR6+OjGZDBqbfyOJW6hs55zPjRIitSiOkc7XIxO9ZVLrrVO/vPjUSNxPHzzCxbbsWU/m7+Q== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2108a6a-12d5-4bd3-7cba-08dac89ea13f X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2022 13:21:26.4682 (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: Ju7Cn0aUpOq7MCZukkUFBiI0RCS2xjC3GJZGpscSsujmpfC2tVzNjYzOvCSygNCnCNei5NRmynhqcNM6Xms3etP4XA7/GBEz2lKY939vod0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR13MB5839 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 Acked-by: Steffen Klassert --- .../net/ethernet/netronome/nfp/crypto/ipsec.c | 484 +++++++++++++++++- .../ethernet/netronome/nfp/nfp_net_common.c | 6 + .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 +- 3 files changed, 490 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c index 154ef841e847..3728870d8e9c 100644 --- a/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c +++ b/drivers/net/ethernet/netronome/nfp/crypto/ipsec.c @@ -16,18 +16,498 @@ #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 */ +}; + +/* 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 resv[15]; + } 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 resv0 :12; + uint32_t encap_dsbl:1; /* Encap/Decap disable */ + uint32_t resv1 :2; /* Must be set to 0 */ + } ctrl_word; + u32 spi; /* SPI Value */ + uint32_t pmtu_limit :16; /* PMTU Limit */ + uint32_t resv0 :5; + uint32_t ipv6 :1; /* Outbound IPv6 addr format */ + uint32_t resv1 :10; + u32 resv2[2]; + u32 src_ip[4]; /* Src IP addr */ + u32 dst_ip[4]; /* Dst IP addr */ + u32 resv3[6]; +}; + +/* 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; + struct nfp_ipsec_cfg_add_sa cfg_add_sa; + }; + 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 -EINVAL; + } +} + +static int set_aes_keylen(struct nfp_ipsec_cfg_add_sa *cfg, int alg, int keylen) +{ + bool aes_gmac = (alg == SADB_X_EALG_NULL_AES_GMAC); + + switch (keylen) { + case 128: + cfg->ctrl_word.cipher = aes_gmac ? NFP_IPSEC_CIPHER_AES128_NULL : + NFP_IPSEC_CIPHER_AES128; + break; + case 192: + cfg->ctrl_word.cipher = aes_gmac ? NFP_IPSEC_CIPHER_AES192_NULL : + NFP_IPSEC_CIPHER_AES192; + break; + case 256: + cfg->ctrl_word.cipher = aes_gmac ? NFP_IPSEC_CIPHER_AES256_NULL : + NFP_IPSEC_CIPHER_AES256; + break; + default: + return -EINVAL; + } + + return 0; +} + +static void set_md5hmac(struct nfp_ipsec_cfg_add_sa *cfg, int *trunc_len) +{ + switch (*trunc_len) { + case 96: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_96; + break; + case 128: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_128; + break; + default: + *trunc_len = 0; + } +} + +static void set_sha1hmac(struct nfp_ipsec_cfg_add_sa *cfg, int *trunc_len) +{ + switch (*trunc_len) { + case 96: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_96; + break; + case 80: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_80; + break; + default: + *trunc_len = 0; + } +} + +static void set_sha2_256hmac(struct nfp_ipsec_cfg_add_sa *cfg, int *trunc_len) +{ + switch (*trunc_len) { + case 96: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_96; + break; + case 128: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_128; + break; + default: + *trunc_len = 0; + } +} + +static void set_sha2_384hmac(struct nfp_ipsec_cfg_add_sa *cfg, int *trunc_len) +{ + switch (*trunc_len) { + case 96: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_96; + break; + case 192: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_192; + break; + default: + *trunc_len = 0; + } +} + +static void set_sha2_512hmac(struct nfp_ipsec_cfg_add_sa *cfg, int *trunc_len) +{ + switch (*trunc_len) { + case 96: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_96; + break; + case 256: + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_256; + break; + default: + *trunc_len = 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 = {}; + int i, key_len, trunc_len, err = 0; + struct nfp_ipsec_cfg_add_sa *cfg; + struct nfp_net *nn; + unsigned int saidx; + + 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->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: + set_md5hmac(cfg, &trunc_len); + break; + case SADB_AALG_SHA1HMAC: + set_sha1hmac(cfg, &trunc_len); + break; + case SADB_X_AALG_SHA2_256HMAC: + set_sha2_256hmac(cfg, &trunc_len); + break; + case SADB_X_AALG_SHA2_384HMAC: + set_sha2_384hmac(cfg, &trunc_len); + break; + case SADB_X_AALG_SHA2_512HMAC: + set_sha2_512hmac(cfg, &trunc_len); + 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) { + 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] = get_unaligned_be32(x->aalg->alg_key + + sizeof(cfg->auth_key[0]) * i); + } + + /* 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; + + 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] = get_unaligned_be32(x->aead->alg_key + + sizeof(cfg->ciph_key[0]) * i); + + /* Load up the salt */ + cfg->aesgcm_fields.salt = get_unaligned_be32(x->aead->alg_key + key_len); + } + + if (x->ealg) { + 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] = get_unaligned_be32(x->ealg->alg_key + + sizeof(cfg->ciph_key[0]) * i); + } + + /* 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; + 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 */ + return ip_hdr(skb)->ihl == 5; + + /* Offload with IPv6 extension headers is not support yet */ + return !(ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr)); } 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 593df8f8ac8f..682a9198fb54 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -2371,6 +2371,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