From patchwork Thu Oct 19 12:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428729 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 658881DFE9 for ; Thu, 19 Oct 2023 12:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="R51RL0TH" Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2070.outbound.protection.outlook.com [40.107.13.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7401D7E; Thu, 19 Oct 2023 05:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HeSCWbi0Vyv9qvv7nmGDL4bu3vg2HUdNpWj8cC5vyHBjH1tNz2c5w3cu3b2UMEMZ8OfLUtXjRKJvp1MKNeYopl/SC9/EYbpbMGOHrPb112/TGmtAtlKflLgOW3/xdsNQagF8o7sqh9H57Vv1dA886sOaaZGMsNE+SixrlSJVVtimKinwCRKk4+DKiNNFo51l940L21624H+T582ALRKh+ehEJ86+d/kAttJQoBw2qXdwa7plZZ6CERGF0d+/pvgg8PHXcKxa49Eg1MaU5B01O76vztklFkZ/iN2+GyyPIJEY494tsRdNPz1daFombjc5CCzSCMpXFHNerFuyNwLQ8Q== 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=kVTjvywGyE+WahoRPuXm2GE9qSgNqGXev8RZwK3DWtw=; b=cS+2qBz2Wp0pqQmOzpkrIgqoo+VF8cvHIV0dwACuKleTjTguArqFto0l2zfIAppQKdPChaViGJgf1zuPyMjVsjT6hrEdrOfZ4A2VROX0HhOjqWDqZwCojwhzmcOINW9ysNLLtPFhipwknP/nQkNYwnylHJa7ZVeDvMVO1KdsYrsdq2sjPjvAn6OewDsylnrwAFzmaI+hmC5MYdnUA4a46zEXiZxjMyPCCVXdlxqnswDWmG0ghLuq4SawDBx2kHn1a7wk3Rwh86LoNBCm7BirzMdp8zrboIhYeeWaUK0z43ZodcbyZHJ6Wj9HoJkwb5U9s0CbskOtWWZqTwjYFWEKvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kVTjvywGyE+WahoRPuXm2GE9qSgNqGXev8RZwK3DWtw=; b=R51RL0THC2UrIvM2rmc4enZE3shGVSLUaOh9j4Zn5gnB26y/BYVRGCs1AoJPqNhde6tadfpr5htX3VZIYK0wMFaAGs3e2jjfsL5N/dzfBRhIqv4wL71LhZhvyufjfAy6HFjlQy1tOHidoYCkueKF65IACD56kgBk/8W+pFdzhZo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by DBBPR04MB7961.eurprd04.prod.outlook.com (2603:10a6:10:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Thu, 19 Oct 2023 12:02:53 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:53 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 1/7] net: macsec: move sci_to_cpu to macsec header Date: Thu, 19 Oct 2023 15:02:03 +0300 Message-Id: <20231019120209.290480-2-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|DBBPR04MB7961:EE_ X-MS-Office365-Filtering-Correlation-Id: d60bfeff-ce7e-402f-9ea6-08dbd09b530e X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wzwu0iujySulF5dAvd79EIGooPsfOMwGJUnfrB12Sj/ab4viLPNRxGZLOwlP2Xs8vBvVvFbuhnljtU++knabQIW14Y4niU6qnFrJQ5wUhMr8kFE5bPZnpAXtH3v35rQFDkgWTF/Uyph8R71ltgt45iz552/tR2h/1P/siIMcW68uP8PrNq0S08DM+rEaQlNsw4SE8UKu528wv3mVz1lwzeFixT5o405QBQ1YEQjHPUVO+Q1w6SUj1F579E12hM+V6QItGj56MCP3A1gVOgcSZp7CgY2hrLcldF9FOaveubVgY4Uq8gn6aA/KJjhdAdYAt9Pn8ET9s0LBhXZygFqBBhBu62fSB/A0gef2oXElOWLkA94hLOc18EvgIYDRHLYKzE2TPlFic3vaQeBENVF7tgAZbtjfjCAEo++St94Vy2gQV7OEN5DNe9Jb0bDSUSNKLDys++QIwBwYoAOCLpqs1OqdeYlvh1/N8ZjTlGhG1am6tSi9GRTFWQGwgbMcpCLItqFA42MHyK/gBuZkHBBM2qF16RMfpz0i8qIrGv01Ojp8eKIe/dHSPHEcz3P+JTNCrJImN3rn6F3Pb/8oN2hMZsm22OZ9ZlzrHwUpxUsVnwRIxU1z2hQYWJHNKNhX32b5 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(38350700005)(41300700001)(6506007)(38100700002)(4326008)(8676002)(2906002)(7416002)(86362001)(83380400001)(1076003)(26005)(6512007)(2616005)(52116002)(5660300002)(6486002)(6666004)(478600001)(8936002)(316002)(66476007)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z5alaXonu19BknTzB+Kzp2OAuqLgsN83InRON7eKG57Lr7TVqBEUgUBFexVZ05/wohG1HcNdMjaOqRrz7PRc6m70TZX6iWTFh9ASsplC2bczXUppAwckyzTzXkcO5OAN6xE4HpVLW3JtMnarCL6uTvlMlFFG1e5tseLxTuu7/coK8/piogpuxxO8c8syy83zMNj2fEkBMqGQdldOiHNhLjRHMvyHOIm6BoX8q4xjYWFO/y45CqAlTIu0uYASFR/JhVm7vTZcCKqD9QE9/Fta5OIvJIZSQJMik2qWZtphj2AeSIY+wkd100R7Crh0luEmX3PbGlIxNifkK2Xa4RHYhcdtam+JolQKbu7fPSzlcBMFFNN1nWmD5Pj62Wb2VovttZAx+INuPBcn8JGArX1MMNd/ZAuaeZdHOE3NqOiYJhij37h60MbCXCdB7DQdW3PbEzC4F388aGoPTqdYAHcuFhncLPUVkTbOuxaGes7bczRmbzyn2EWylMb+UO98C4S2es060edGugcL8pXiD4ZZDTYjtzJ1HzJOl1sglGa4/6UD0RcKlzaVfSWE2O5avJ+jjow1EwcMvqaHBKOhFLPLzOSE8LgDqdELhEBseFR1gYuM9ESqRBFe1opgXENuervCPSQK99riztdbB5RscxdV/5N+/8g2ba0X7DvGP51I7P4uU6cW88XjqWEWzCwSYO6qq8A5C56s4uil7qv2jCsIv2OBI/4NuWPoS3h+fib0F8CKE6lT5T6zw4yndtl2iE1BcPHfrPL1M4F2qw+vC3PQPskrSUOL85an24aKd5GxBOLD0enOAptn6tvR/l/XNE1att/jIFt+8LUNSPLIVZ5fwGmW4jvMSlPke0n8/Doo5immb6Zf32+P3S50YR67DqX0+S6bea9Wvu7iQQBUCYK3Hoo9cO43bBoTXDGlWJHcH5Rc3oy+lYh7+0TJMXquKkGeQrEh/+y/jWWXMkLtP5uoF3Vh9tmbdVcVxn0NLadS4SnJALC/TtvBEAFmz1ebt4XjEdZSNQzsGIgarxutv+Qs4E0AbZlkiwLYFJBfi4xlY4eaTHqBToOLqhsFd1ZP8E7f8ttiT42HWKtkGufukgRAD0sc4TCT2Cx9l31tb3aYdpQintl7lPnXtF6Lh7U3PueZlGpSPmiVbYd274IU/sultHMg56IZzkXc3jEy5Nny7yIMM5VrW/D5gdHfq4R3j5BESHMgXfNmywCUbkWJam4xs4tRatme9d83uc+ZsGf+I+EYTetsEt1sTZfl6P+rdms2Qdw5TRVEtyVCcxTR73Cv13YSnZhfnCprpoWOeiB64tSo68WcNja3PfrfNg4yhpl5fYoM3tDSfKgbORbcROTimowiK/ZksSPBWyHPcpvmmW9CmseIKqpRsXes0BOyLrxwtQ5F7cS7uFZ51laYWYFMOIx1CTzm+OtTb09ghIAU4mQd3eID2GiuEEKI3HRTXgDGSfOxF/XUn7B59CA6WpE8xBWzAhdJKPV5K+cOjTOx0VrHUqHrMVS6PL0xhtHxar4nU6ablLpolmH4xJJdQuY7vWzzezjv2ephu2Wo75auXWCjub/rv8Bjv/yzLjsoxk1k6dDRfTMiSHXUy1eNH48P3A== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d60bfeff-ce7e-402f-9ea6-08dbd09b530e X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:53.6818 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w/MERyQpUjbQDVfnwvJmiwZNiEa/H1GviJPTUvynd4L1N9nOGzhjzZeWVBO3386WhNVA48OG/4/N0AW1ap6wsKReXH9f79vlWCCusdvygD8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7961 X-Patchwork-Delegate: kuba@kernel.org Move sci_to_cpu to the MACsec header to use it in drivers. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v4-v7: - none Changes in v3: - patch added in v3 drivers/net/netdevsim/macsec.c | 5 ----- include/net/macsec.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/netdevsim/macsec.c b/drivers/net/netdevsim/macsec.c index 0d5f50430dd3..aa007b1e4b78 100644 --- a/drivers/net/netdevsim/macsec.c +++ b/drivers/net/netdevsim/macsec.c @@ -3,11 +3,6 @@ #include #include "netdevsim.h" -static inline u64 sci_to_cpu(sci_t sci) -{ - return be64_to_cpu((__force __be64)sci); -} - static int nsim_macsec_find_secy(struct netdevsim *ns, sci_t sci) { int i; diff --git a/include/net/macsec.h b/include/net/macsec.h index ebf9bc54036a..a5665e9623f2 100644 --- a/include/net/macsec.h +++ b/include/net/macsec.h @@ -325,4 +325,9 @@ static inline void *macsec_netdev_priv(const struct net_device *dev) return netdev_priv(dev); } +static inline u64 sci_to_cpu(sci_t sci) +{ + return be64_to_cpu((__force __be64)sci); +} + #endif /* _NET_MACSEC_H_ */ From patchwork Thu Oct 19 12:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428730 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E07F1DFE3 for ; Thu, 19 Oct 2023 12:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="CnvwUIGU" Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2070.outbound.protection.outlook.com [40.107.13.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 833BE1A5; Thu, 19 Oct 2023 05:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fmb4RyS7QzOztt3XbR/5Az1rwCoV1lI/+aHZB6ScQUR0M3pmyT5UxCzFlx287FOa0KkLGgjJ9gikjYUzEHwyeh6PQQIRlKlvyfb/HLM/lUP8miwo5XHyDM+TWIS7D+JpOwANgj+Y8PP/sPk/YOWikeeN2t/cmwHOLy+ZHre0eb4Tg2unApMzq9cMiWE+FVOqDzuqWGCfaf9SibDLOix/ENtWAah8S+v66FeUa8zqGXe4KC1Vv1IFy2eynRTODo57X0gzb7pLG1Do8vrBb1Hhui8ETVW+zwUi7xjTHBrTUY616T+S6G8kyhbHsmNZsyzCViHZT1wL0YZjJCKUljHGIw== 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=Rzzf97LsmU+lWqSsOyQlrJY54xVth6Jr1ark7Dz4Xr4=; b=E96vCIp1Hb+eH2njUpONQVROTr8Gw6C9NR0n5q9zAXI0agdOFJVZcwKPWPJbviBPSZQDT6/0PG8SIx2wYW9WVBNwjuPKVHpRVjQGZWZT8adTZEq/7JW9xbIJSKyq5K0pidzl07mSfuKK4T1r1ajYIdJbwyjQgYURkD96R3LuZcDKgBmL0RW7PJ+jz8Ryl2iXb9Mcxe14iD3avRBQLyLEPEwu6kQRRaMmu8ZyBRFoJsV3LMeBmaMLko3pWdgtSYMBBslz05qYpvgAQIsrgylQF2tGdSQcIO2FHkZgjnAnGJKmR2vcYeLZGIFWpyd44tV34WBBfilNIm041FrAzsYfag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rzzf97LsmU+lWqSsOyQlrJY54xVth6Jr1ark7Dz4Xr4=; b=CnvwUIGU+G1aeMKlkRKqZF8BI8Bz2sUJnlVmoqWpXLXnXUDM1r9HdGzyb7rvUGsHI6ZSYjUJLO1dO2ZzRCTo+o247142fOME4Y30SaFru7PbaPu4N2pGgzTZwL4ERWYJZhTpJSabbJLt3jCBSSe69cZ1Gk2p8WTOR3jBWFtfYPs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by DBBPR04MB7961.eurprd04.prod.outlook.com (2603:10a6:10:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Thu, 19 Oct 2023 12:02:54 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:54 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 2/7] net: macsec: documentation for macsec_context and macsec_ops Date: Thu, 19 Oct 2023 15:02:04 +0300 Message-Id: <20231019120209.290480-3-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|DBBPR04MB7961:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c869b69-0d86-4c25-8453-08dbd09b53b5 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GL5LrQl1xA5AYYpCHilSQHWv7eibXh0XMCgcrDCulfxx5TRONQ9vKVgbc8HJH1ZUO3iHMAnliCJEakQsdHnnEwmXjkmL/KICHmsK2kiBsYtFRr6MP/1KtKGOf1ritUDPTNuJcn4u2McG9aadT2Q+PQ/Co+MkBDCjfSd+Gh6Pi5tqZ/vXU5jYOF/l/rw236HGwQUtr3mxdOYIFby6bJZeTNpj4oW5k658hO9Ztn6dhTOzn8wCqgtKUDT/VH4PH2vLhaScX8TOzqhZQXHAVrhj5HXIU83KWb4arPXPzLGxN1o+JC6nFh4qNvHfTZ8VpytFbIe0bqmE+uO1OiSMuMyW7zG61h/XRLFLLdSQFgxyNhMnXPI1Kmokc2w9lIn1TQPCix/aHTce7Y94yv2HYumDrchGQOnKTuitKJslIarP6DsOP3ANlHtCTwGuclK5SvWBzEcjS/OU+B3kCCYSFKj1t08NS14jeAZPoPkglW4Psp+VVaTbUdLlbmxkvW1XwDiKSDyrxIrcSGMhxGOeA56YkJ3QTqSh6IqFSue/HC/oGT3dfqqSuFfm/l/B4FWX5m2xw950ewJqKpEq9OC+71+VEj7cQzedN8SI8QtvXNErfq6gmxtj7JL6nUsS4s7YzsXq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(38350700005)(41300700001)(6506007)(38100700002)(4326008)(8676002)(2906002)(7416002)(86362001)(83380400001)(1076003)(26005)(6512007)(2616005)(52116002)(5660300002)(6486002)(6666004)(478600001)(8936002)(316002)(66476007)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /gyz/BvqYgo45mKTjl1GkR9KPORYAxMltipwQmLC5Mqn54Bn4lQk6PXuCiv+Zwst+HUPMbW1SKQsScHBE5wpYRPZFEzEY9C0ghId7CmuWCs64mawX6cYZzWVaBKUtR7amC+dHD7UtY4IU3WAK17yJTGwbRDDTBgCWS1/anFis9BNXSBOynw+Zqq0/bHrmasdK/0ahgJwPEa9qg0uYUPpnldLa9yHhM+QRRrWLniOc4xa3BPc0fGC27i5QbBU4cUzkPst1A0X68Qdga7h/qOgbM5RFYWVG5kmVFntECRqCOb6lCSft3qPmiZrcSp2OdSPGmE7zo1OBTmX8etnkLfI8yIggU/0OUzcLqeQGsWYx03I4NaN/JR1mPga5LmXlRV/p6vWYrxdmKltrMR4GWGqouVx2dxXNOpz+XKdBFrEo/zAn0zl7iqMPDIwausnxrE+0x3HnLL565WrCE6B6c1i4rjydwEL0LZ8OoAjvIEYwpVjK+1ZH3/iA5BnFKJiLL8kAPJfKJAZLEBO94X73TuNPD4Do/k4M//wjzhDIWjaRu0aW1aOSU6JEXWomxPsRju9lo60p00ygOM/k7zHCnk+ELDdt0iEhvYKYHCJpokWkeKhc1186sYabsIAlZQwtKuPecwMnD0i75USJkbqwVnqa+BczRVlLmKxP7yIhWBVvFcwzb2skHTmWU9Eek15HlIeME0Yz8WuLGU2butP0vP/DwchCX57lMU//teuDTL+SdbT4MKP+0spn0Nx8+PeA4f3Dqf/SEQNx++z/PTWT9ZLSerHWUh6pvJYz6HSKSzCfHX787G+fKaFa9PG2DHWZI0blGTrz9cgx4zX8VaaCBwp1nawxiUgyeiifGRKwZfvakLksVSOM+fijaj0ytmLxbQLJRWiRyNZpsHQ5Ko/CpJrk+bhb9m/rS7alC/ULo+1Apg5Kn/NFteJeJbp1B1EGofPH+ozh6+Fq7i2UKymKHqElx7feakDg+Jh3aDhGHA7SI69v0tuzwIbrOrkDa+CngQyeAOuG/Wk0/gc4X16UtVXmTW03ra+yPmr4Lx4o0H4lV2NppCVlQLcnps2W4qov5Ibx9mBAuXUYx45lw4CtnR5AKg6chZlEVLCaOUm0olPtn0LHjDuvrYROwR2NgMvRAAJRr85UVOWpY7g8ebj3ARlAV8K3FL+ZIq87kmTG4TqSofM79ilOx7V6iyP+ZRlYCdb6lV5kOJKeagWX35aO2xs/zs11qFB25WKH/LHYH9eiaCosnpIe0WYuYcjauNRyZsQG2PL2RA7fjv/ouNgmAJIjzLa6EjdoEK35vqPpCTiGoVKKZDp86Y18naZedMQzh6mKCljnxmjzeMRqB8ZEtl9wTOxp3Ue4bqjXz7pL9qdP4BAlzSdjbZICIHlHfUt+rFgUDgzp+9pnJ1ERsMn3zwWzeRe0CBKMUna/4Yf/HnF2kThmpDIlvgwX+o+Umuo4aeYj9zcjkF4kvqBiMtI4gZ0BN45w4+fqTsgg2n66Gi3H/AlrvnEqSEnvPp0wcJXv/iWpWhcmApNLVyUWT5c9ISSu8oPjCDcnzx04W77AgjS95Ybce6bL9OKFk6m4nvZ7qzNP9iSZr3yl1AGjAt9J3MQKg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c869b69-0d86-4c25-8453-08dbd09b53b5 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:54.7492 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ETvSnFqGmKXv9MgVgVu4rzzNjhNWZd9qq1RoPPGCdga5vSm0Wwx0CCoVHcHHVa0m9FQ3KJW+p2uv4AciX24IAps3nHLvxeCbrVkrWT4+wNc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7961 X-Patchwork-Delegate: kuba@kernel.org Add description for fields of struct macsec_context and struct macsec_ops. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v7: - added update_pn description Changes in v4-v6: - none Changes in v3: - improved description for the netdev and phydev fields - fixed typo in mdo_get_rx_sc_stats description Changes in v2: - patch added in v2 include/net/macsec.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/net/macsec.h b/include/net/macsec.h index a5665e9623f2..0821fa5088c0 100644 --- a/include/net/macsec.h +++ b/include/net/macsec.h @@ -247,6 +247,23 @@ struct macsec_secy { /** * struct macsec_context - MACsec context for hardware offloading + * @netdev: a valid pointer to a struct net_device if @offload == + * MACSEC_OFFLOAD_MAC + * @phydev: a valid pointer to a struct phy_device if @offload == + * MACSEC_OFFLOAD_PHY + * @offload: MACsec offload status + * @secy: pointer to a MACsec SecY + * @rx_sc: pointer to a RX SC + * @update_pn: when updating the SA, update the next PN + * @assoc_num: association number of the target SA + * @key: key of the target SA + * @rx_sa: pointer to an RX SA if a RX SA is added/updated/removed + * @tx_sa: pointer to an TX SA if a TX SA is added/updated/removed + * @tx_sc_stats: pointer to TX SC stats structure + * @tx_sa_stats: pointer to TX SA stats structure + * @rx_sc_stats: pointer to RX SC stats structure + * @rx_sa_stats: pointer to RX SA stats structure + * @dev_stats: pointer to dev stats structure */ struct macsec_context { union { @@ -277,6 +294,28 @@ struct macsec_context { /** * struct macsec_ops - MACsec offloading operations + * @mdo_dev_open: called when the MACsec interface transitions to the up state + * @mdo_dev_stop: called when the MACsec interface transitions to the down + * state + * @mdo_add_secy: called when a new SecY is added + * @mdo_upd_secy: called when the SecY flags are changed or the MAC address of + * the MACsec interface is changed + * @mdo_del_secy: called when the hw offload is disabled or the MACsec + * interface is removed + * @mdo_add_rxsc: called when a new RX SC is added + * @mdo_upd_rxsc: called when a certain RX SC is updated + * @mdo_del_rxsc: called when a certain RX SC is removed + * @mdo_add_rxsa: called when a new RX SA is added + * @mdo_upd_rxsa: called when a certain RX SA is updated + * @mdo_del_rxsa: called when a certain RX SA is removed + * @mdo_add_txsa: called when a new TX SA is added + * @mdo_upd_txsa: called when a certain TX SA is updated + * @mdo_del_txsa: called when a certain TX SA is removed + * @mdo_get_dev_stats: called when dev stats are read + * @mdo_get_tx_sc_stats: called when TX SC stats are read + * @mdo_get_tx_sa_stats: called when TX SA stats are read + * @mdo_get_rx_sc_stats: called when RX SC stats are read + * @mdo_get_rx_sa_stats: called when RX SA stats are read */ struct macsec_ops { /* Device wide */ From patchwork Thu Oct 19 12:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428732 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 415A61DFE3 for ; Thu, 19 Oct 2023 12:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="FMOf6LVU" Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2070.outbound.protection.outlook.com [40.107.13.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8192C1B2; Thu, 19 Oct 2023 05:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yv/mJHs/1e00WHFykGSW0SRYpS5kkZvOSZ9URdOQMDcsoMRPvtO6aLIuajOJz9+E8X3WfbvPDE5g5HubcYBoWO6M/0PvBzb6b8tUuzcM4ZrNLYvaCho/o1s/kTnunN5YveeQ3cndcHjgDGlm3raJ188ojHnijnStGr8J3B+5x6onCPL9iZM2dzpP/naoq0l+CVTfDAUOkIHFOulOcGk8/S9HXH+FKO52JDHBDQrjWNsbGKLiXAhS/NYgYG5QoiDV+3Wl9o6l1Vf7O2X5GcilDer/ojMJz31WsMuY8mmtKl1fqLVUerwSefUS2k/jkGBbTohWcli6UamOMDpLk3yA6A== 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=gFzavl0orK5XVqqdIgXQrzWPIl2tiW61OVoFktSbHI8=; b=W1boAkbuucCyJ3Xh8F39bayUAoZtlFOE8TLz1ZyGMmkAV7LInfZZwpfjptBp26ZaboR9qR6x4YidmYWJpoFPMDim7427piGfS1+vWFk/DzoJgb1J7TjAgpQX/4+N6Vl+shozDObol5ugObFiJg8+cwyhu5RxWdCluwpRBEIZbOkOu3unblGVmDpJ/U/LrkNaUMOW4lgpPZmsqFIslNyuefq9Er/Lh8iqxjP1ndoRBYRDqBBCDfuki/7sNbYEk9Fp650onMcz9gX1JhGIAMA7hcMKO7oDPIvyFLEInfGAeUt5vXJRVTCr6P4Q5NQ7P2/YOi2a7ka7w5P5DC466GHDtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gFzavl0orK5XVqqdIgXQrzWPIl2tiW61OVoFktSbHI8=; b=FMOf6LVUDm6M+PIWNl2QliESKuyHpuqk5skbgYEnOg4p+qjlJ6k+WK5NOtc22zIJvfMNPLPHcc+pzZ0KlWgZyZC8XMjlmSJvVaAw6XvirA13oXyyLUFS1DDW6r67+U3ZC35C6xUK+Smc8OFEFLJy6qwDM+BGCIAhSq0xLTChskE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by DBBPR04MB7961.eurprd04.prod.outlook.com (2603:10a6:10:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Thu, 19 Oct 2023 12:02:56 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:56 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 3/7] net: macsec: revert the MAC address if mdo_upd_secy fails Date: Thu, 19 Oct 2023 15:02:05 +0300 Message-Id: <20231019120209.290480-4-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|DBBPR04MB7961:EE_ X-MS-Office365-Filtering-Correlation-Id: 6961ba36-a888-467c-0790-08dbd09b545a X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DLGwqU4IZ9aN7SoYBZFV3/KL7BW/Oa6mDGOBRCikQ+zAJwYHhHmQ+rJ1E+2VBKRaw2FYKgjLKL6XKqHcW0Tv74WRPSoji6z24t2BV5trdXKhoKj/+N4C+h22MUlXR1LpelGDmneuHyixVCdu1M0KYTjdYNMjFEblpbdwkkXP/Jb9qpATCbPKa+zDSbrGv4FkwNpVssr2A3pOyv3to5b0nwj4PEh543VIGiy5oVqNkD2dpSyf/a5cSi4WDrRrQ8XfkGKc3MuzlRcLdNEFeA0C5nS8D+sL9xqtkgHxFRvmvTlYXSSb2c+Z6zRGpOHa82ewq5UdAR+zY4BzfeHStMlvOmdEoRUu97xSxGKzR6Tr464HK/9ersO1Nt9NU4QO9P3yZeIFqQamepD5yYgNt1AlAKfOwWGhtZ31zrJdX+9VWlRSae4MrpwQiz8tXZNaUfRYKaxwcMD+6g9GrkvmjZA0yhFcuwqTi4eDPbAW2YP8hFC8m5Z3RCMSkmdA2zcl3aBKi8Bp9yFzoV6RElli7DUn7AlQ4i2CW1d6wYPL68OYZ3+B2a3LdFJVmqguMdvGwa0hjposrdUOu4Mo2S4oe8QuOgq9a/p8vV8kGSfCi8WqktmMLMxmKy+ERAfS1cFFx45n X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(38350700005)(41300700001)(6506007)(38100700002)(4326008)(8676002)(2906002)(7416002)(86362001)(83380400001)(1076003)(26005)(6512007)(2616005)(52116002)(5660300002)(6486002)(6666004)(478600001)(8936002)(316002)(66476007)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U1pGS95IwChuz1UdcQ6BmfaR/pHrx1cYp1E5CwABY+/i68stBqjs48uQtmfezlvzxjNyAYTEr5dcKjvPfHwlYSqtV4ffUDzByb5Bld9GA51Ost5fcUZqm6PvGZ951h7Jl0zKG+S8ejheyZqW5bvq3Of9V9VPzYU5qNEx5TYMbd4Yg/F1e9AtbOAc9auFMWSknVUPAuN1oVdV84U05bCZPf+SK7gWwcGEUMUj+HH2eGkhX2c8jXA4M3pDAPLvxihrFUon/jUjwtbhyCnEtPgHIItSLHL+Z1uJQzm9w9Mbz6cblSmQ+N92VeWfLifS2Uf0SGeAgnOF5fJd5FVsG6DQ7fz2/fYhSUXGRrDlzTda1Qt4Ae7szUWU/KVQOatYSztmUiWTR8XSAdrPsWY6Gm4LEp7rcuijMkoWzAMVjjy+5eIxVxv+UrDx4lWiP/WwbKzWmM/G0hB+p0dcLOQbcDSH5tG6c/4FD+P6Wv/2vqBx5eNu28U98tbilGacXfHDOmVyeN55U8eVjATvl1DrtyTrPtomc9iRqWORK2ExbWbMaB1prE48m4UXTh+DZq5kDBUja/yILaO7wSNRpJmJOQ9BwvzqgUENkSQPrg4IO8i4e6nsSHfokivx79IiuJkvnPoNwrzCw/sIMV0RJhqntFMZgaHzsJO9jEzGrcHrbLArtTjffqBQRZfYUQV36cL39wHMHglEvTubAxMFo1rwio0LLwAvJMxBBwk0nYs5f17rLyWMuzkqiKsmzkOkVbMl1hu46lZC/HppWs77JEoONOL3pa8/IlT4mpDHpd9ZSsnO3+DzimOE77c4fagnsnjaczlHojiE0rlC6iWtLOYFqJB6ODmabyu4M70SC0Zcg23eDZ0MD2l6xABZwGVwSMFne2SxYwLK9Zkn0BpTcwVuqgwtZdnWLdfh5P2dr0jFAT0XH8eGphJum6RG81+9mnyz++ojJXQWcDkQBdDSXTlWqIJ9H/4YJd3YpJVKiZ0TXwqw7dApBHMyLHOlXSyTYz4q4KAlym5Hs5g05u02+Zuc4MERJaTz/bKZm+a5LYE86Bq33f96UpzFvj5tugnRrAuynYkNK+wuaw2lbuTuQWd7NQO4O6OS6rNwE2HxQZY8wu5zYvSkw5ms404xzNaTiblTomcEop8Y/wpGwjFTm17KbNrtafndQiL3psTxxU1OAmC87Zvj292ukMCUTD72LnSerNnRbfRpAxV5snHJGwJDjj6XMsEgesXREK+HPqt8b6nRF2Vc75iFZxcd3OgeKA048eG0ZmfRnz/vQWpkuqGVK7hBcvyGVL6PFKKgn8MPQ6J85bOqDyoKLrvRvhcUfY+Ffggw/nsAJhj3kw8f2E6/RBOKsAbOG7Qm4zfhEsZ9JL24Q/5kURRlmqIFwacwBig0tgh1d3BQcq1B0kTSTgkgHb2rU4XVfsx5iwhWdsk2ZFzdeTXIiGvPzVXj/bFH6uFvcMXKt8R1ULOhPPNtK6zniYVdDKwlO++u5ZcU4C/w3xS3fVY09bOIMCfgKTkNgX3HAqzndYc02shq5diSlVY6MYYi5AC1TKA90r8sd7gxbzBGwMBiKrwX8ZrqUEySVv0HpOMUDGeazyO18/j0atqox9H19Q== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6961ba36-a888-467c-0790-08dbd09b545a X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:55.8056 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SgpPX/mHUlNH5NJZc9q0/5MLlFwRzhkL7ZBz+BzDZ+OvSTXZRr1sXLAFEg42DfwzJ47SSUwv7wOHW5I6qqRFnx6ZEcs/J/b1+R99sWzk4x0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7961 X-Patchwork-Delegate: kuba@kernel.org Revert the MAC address if mdo_upd_secy fails. Offloaded MACsec device might be left in an inconsistent state. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v7: - patch added in v7 drivers/net/macsec.c | 52 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 9663050a852d..569b27b2e276 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -3599,11 +3599,27 @@ static void macsec_dev_set_rx_mode(struct net_device *dev) dev_uc_sync(real_dev, dev); } -static int macsec_set_mac_address(struct net_device *dev, void *p) +static int macsec_dev_uc_update(struct net_device *dev, u8 *new_addr) { struct macsec_dev *macsec = macsec_priv(dev); struct net_device *real_dev = macsec->real_dev; + int err; + + err = dev_uc_add(real_dev, new_addr); + if (err < 0) + return err; + + dev_uc_del(real_dev, dev->dev_addr); + + return 0; +} + +static int macsec_set_mac_address(struct net_device *dev, void *p) +{ + struct macsec_dev *macsec = macsec_priv(dev); + bool offloaded = macsec_is_offloaded(macsec); struct sockaddr *addr = p; + u8 old_addr[ETH_ALEN]; int err; if (!is_valid_ether_addr(addr->sa_data)) @@ -3612,28 +3628,46 @@ static int macsec_set_mac_address(struct net_device *dev, void *p) if (!(dev->flags & IFF_UP)) goto out; - err = dev_uc_add(real_dev, addr->sa_data); - if (err < 0) + err = macsec_dev_uc_update(dev, addr->sa_data); + if (err) return err; - dev_uc_del(real_dev, dev->dev_addr); - out: + if (offloaded) + ether_addr_copy(old_addr, dev->dev_addr); eth_hw_addr_set(dev, addr->sa_data); /* If h/w offloading is available, propagate to the device */ - if (macsec_is_offloaded(macsec)) { + if (offloaded) { const struct macsec_ops *ops; struct macsec_context ctx; ops = macsec_get_ops(macsec, &ctx); - if (ops) { - ctx.secy = &macsec->secy; - macsec_offload(ops->mdo_upd_secy, &ctx); + if (!ops) { + err = -EINVAL; + goto restore_old_addr; } + + ctx.secy = &macsec->secy; + err = macsec_offload(ops->mdo_upd_secy, &ctx); + if (err) + goto restore_old_addr; } return 0; + +restore_old_addr: + if (dev->flags & IFF_UP) { + int err; + + err = macsec_dev_uc_update(dev, old_addr); + if (err) + return err; + } + + eth_hw_addr_set(dev, old_addr); + + return err; } static int macsec_change_mtu(struct net_device *dev, int new_mtu) From patchwork Thu Oct 19 12:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428734 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58DB21DFDA for ; Thu, 19 Oct 2023 12:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="flgfNy2x" Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2070.outbound.protection.outlook.com [40.107.13.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5308110FE; Thu, 19 Oct 2023 05:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYvNO7fT7KU80/DyZPBhj3h5oOddZul50o37CEY1AVvHUgrvoO4+ILNYtIuGeqehm4j2rdrM7ci2A0jq2QZfOf9jItK1qR8ONLdm1Fj+54Odr+xxI+q+i1Plsj9J8E7HJgZHtC4vEJu69jIeUUMtPYwEH/ONYnBJayTsoSq4My/abvuSh6nSYiiES8EPF3WQTah1blzX8EKQ40ypWMk24F8zRhT4z/0dns2Dtbq0MOx7EvVsv/POGbE2Jgq8OIE/kXUx+fW/j/Ip03DwgDnz3z4C+Qd8TLzDAtTgCf7UXq8u58K9TKcre7uuOWU7sVEfV02aFBxyq89E2gCdfvwhfw== 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=07+UITJkCos34l0ZZDPSxIy8XokMSdr4WhkcskSbtMo=; b=cD27C5u9vm8cQIhHqOIqDEbw1t7uJjVNeoghXBJfTIRCox8ebldcsOq7tGtfZflslm/+JmPaItK8+3fAgsohgWO9ewx9kvMTdmskTYZM1NzZEy/fIA2a8SwDCtUfXjHbRsDB+KoltkHmW60dxsIiVN604rFyZ0SznT2J59fVkle4krNukNO5Hla69KaWIzNfkDGNdekvUOyYfZHtg0D8vhM4S+pxYbgtmB/CRVKr/q3XGY+XFnyhKqwx8W9x9fi/fDPST2ug3lHM4t6My8TtiCvG3ggna+PMlzGe1MF0QVWz8eEAGQOHSofLHRW53C0a8aYmIuqCCMwxL6yuWSgD9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=07+UITJkCos34l0ZZDPSxIy8XokMSdr4WhkcskSbtMo=; b=flgfNy2xhXnOxqDPDdBVt6wqF//ECFSj3Yi2RZG0Xv3rIH472OjFrwc7HkwHAfXi2m4t4tB+NTrltqOqXb/qwZRkkZ7kji7zFTy5xkui4K3s6p6XKPQpC37tcQlZ6nEmhPq+P/o1hHZ7XXVwlhMuKx7TvOhnHnArm9ywNpW3pCE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by DBBPR04MB7961.eurprd04.prod.outlook.com (2603:10a6:10:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Thu, 19 Oct 2023 12:02:57 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:57 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 4/7] net: macsec: introduce mdo_insert_tx_tag Date: Thu, 19 Oct 2023 15:02:06 +0300 Message-Id: <20231019120209.290480-5-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|DBBPR04MB7961:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c1ebaf0-6756-4003-c87f-08dbd09b54f9 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: plY1p2wHBo2nZYxcpwwsctUTIgnaR2Jc7V2yjQIg6abvlpWBi7wZRRB5Sqyw6Mlbry59ejca6q1XNyqbLAtt13YVrIjrhO3GZh3JTe45uEEZYwFG1MYREw1nvRsRmicGQr2eoy517w6ceYaMmqdtYHRxnSBYpddOCjpP0jLYI9kxuTcSgZaikWjHzmcLxxJ8fV/nreovwal5s5WCu27MjQj0lEqD8E8T0V4IBC9RINEH9H3Tl9N/1vqmFnaieal++JswpAjBymspXl7b9THPFBL6goTE1JcWU+ytTwrWG6VZoiVkP5Pe53E2sfXGJXbQjI5lYjS2YjiHAYVQRo5a6IXCopOjFoyB93FPWT7oqLyZR0TXBGnjz00ryVM1KOtq0HTnfSMGx5UfxLfkIBm7lKCUh1O3FwuCUwHqh5J2TaInzRW2Mz97aV0oVsn0RvI/wkTjiZMCcD5B0VvmIK2mXPLmpQgqqej2fHcMxLSDK+uzKen4d8JSI9YZHFMc/d9iN7A0PRcA+NAENxAmjRBxLYp7v/yaEfIAzoAi3XCFL79vqdVW8FdrAkmHlYJfpr20zzpObZnlTD3ynK8g8QUV85VumXqBf8vbfXcHrVdNqyHNuP6MaU0TIVzk5r6C/tkD X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(38350700005)(41300700001)(6506007)(38100700002)(4326008)(8676002)(2906002)(7416002)(86362001)(83380400001)(1076003)(26005)(6512007)(2616005)(52116002)(5660300002)(66899024)(6486002)(6666004)(478600001)(8936002)(316002)(66476007)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sL1GYSMduGDGHpbfOBnyK4XVabR+N34zz/7QDDoX3rJATy/5zkfcu/wnF6kMDZhKm3Ec/2V0Jh3XXVhsPmMqmbWc/qy02iI2+AA2ZATxC7MJzvxjc9aA+SVk2RbKeiRzaIEjrWWVrTeoqoAzpmO7Ibx5y4De50TQmcClFsx6Ez5xaO6+lROOUgFBjDVSWIPHJe6NxPab7KPSGV13BIRDRMUxJeSUADz02lYVCre1awowgS6wZlejJmejLV7NffYTImpZH6yZaCQoPdh4m4wLoHST5jTL488caezZou2flYrUtGsXR2mWqugAddTJalA1HdHWJlXuIT/As2+WDIvdYardnITsWfisw4YGp/UOB2OMtioGe30QeXgwzh1W2H/JOkMOncU87JLVNsr58fD5b39Zcy7FHMX41agdgwaYQicsjUVzCPVVSVglIkosIG+0asvCdcY8sQUwyvonlC3H5jiUaY66NFEL5WAXNsU2oSCNc2JUVA54XHW99Vy2UOe3Oyo08bRlJLV+e1TJU2CjuLnB6rCHaJkp4yIrDLDddh7NLmwaEXaWfjuINijrXqxQuxrkzRJ3GFK5SormcpgjtGDFvHUTuKE+iItnNnCNSwQpveRj5GldvoNkPXFPRW4uPcEBzLMXR0QLStnvVHwfsHsRwqVoXmsKtJ8RGeKxS0Nb8RwpdMluFrgivw3oVQJ4i6WixRLNPWtK62qcT91sNd4KtutL3MwXZEokBeXkBos2fKbzzQz0v9ZS1zjAFY57itmJ5ufIKuhb9YQi8Tv13kwIDLzUfRzJxbBV+Udho21DwH3MBAEaTthMKir4FQLUPXkcyV1zEFB67XbjPDena+P5QAyhrou6GYw352HPJo5NZtclMivDo6Xop+4TZUktkNBurqVvnQgGxDQM8pQKQFgAXXdv1t2pYhwgXX3vJxCwbssezA30DuVWfKGBdoog2h2Qimgr9xqRQ7Pmq/hkm17nyyh2oi2awgkRBPFj+8qw7ymt9K0ZIfw5g3hRR4KTfs4FhgWPisErtns7qewoNLijmmq1l2E6iYE6NmQ4xyLFNA9+9Ray2WGtX9TYW6zWfgJbMkyrnYQGXT0fqx0twpYaLOv4yAOSOp5Pu0xrU37QCpUoAjZqu+BFem0NTjT7w8MHxtuw8P88kH/6tTkbCN0Pq/rcJEyJ/fgxZTm4k8xCSmJhzBPVHOcwh0KBoYlKvdQ35CGUuauMI700I6a5h7BMJOqOAKL5YWfYCPTX+YNWRH0eTfvObNc7Sy2c4TXTmLSkS7nYwK0/IfuaFboSyAEuThGtYqypfuXIa3fcrZCrWigHOHHn5pdPZIMcMudr3WmerE2zNfzsy5903IkJJ2zTNnKKGD84KkIcu6UokixgOv0V7bfbK0yAwdVNLhodCmDc9tJieOJUaVOKX74aWvWYUhc74fYMY1VToWgG3JuwlFpgF5r+PNNlbcokgjQV9Y+ambOeayLsWuSGxFnmjdX/Ijc8uGYbrH5lsG842b1VtxEaQ5svWu1WXNiugWi7bAmhcG/ybeNCSe1/4XjRRXWBzd+F+fvPyhBaGqKLw3nJR20/gPKRJ4+8vl9YDGtHZJJd9MUVbp05k8Pi3fXbQQ== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c1ebaf0-6756-4003-c87f-08dbd09b54f9 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:56.8486 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7IXGDv81Lv81jvzzboTfwro9NhZpQ/8aCYhLu8pMy2h+1DmGGthrITSecFWPQsdpQql6I+zMmDoP6BpZQQwU+/XTD9dwuMD0wFjA8nXNEAM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7961 X-Patchwork-Delegate: kuba@kernel.org Offloading MACsec in PHYs requires inserting the SecTAG and the ICV in the ethernet frame. This operation will increase the frame size with up to 32 bytes. If the frames are sent at line rate, the PHY will not have enough room to insert the SecTAG and the ICV. Some PHYs use a hardware buffer to store a number of ethernet frames and, if it fills up, a pause frame is sent to the MAC to control the flow. This HW implementation does not need any modification in the stack. Other PHYs might offer to use a specific ethertype with some padding bytes present in the ethernet frame. This ethertype and its associated bytes will be replaced by the SecTAG and ICV. mdo_insert_tx_tag allows the PHY drivers to add any specific tag in the skb. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v4-v7: - none Changes in v3: - improved insert_tx_tag flag description - macsec_adjust_room uses the difference between MACsec room and device room to adjust the macsec netdev room. - macsec_update_offload return error instead of goto - macsec_can_insert_tx_tag renamed to macsec_needs_tx_tag - insert_tx_tag flag is checked in macsec_start_xmit - "TX offload tag" replaced with "TX tag" Changes in v2: - added new fields documentation - removed unnecesary checks in insert_tx_tag - adjusted mdo_insert_tx_tag parameters. macsec_context replaced with phy_device and sk_buff - statistiscs incremented with DEV_STATS_INC - improved patch description drivers/net/macsec.c | 92 +++++++++++++++++++++++++++++++++++++++++++- include/net/macsec.h | 10 +++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 569b27b2e276..57c7d34dcc13 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -93,6 +93,8 @@ struct pcpu_secy_stats { * @secys: linked list of SecY's on the underlying device * @gro_cells: pointer to the Generic Receive Offload cell * @offload: status of offloading on the MACsec device + * @insert_tx_tag: when offloading, device requires to insert an + * additional tag */ struct macsec_dev { struct macsec_secy secy; @@ -102,6 +104,7 @@ struct macsec_dev { struct list_head secys; struct gro_cells gro_cells; enum macsec_offload offload; + bool insert_tx_tag; }; /** @@ -2583,6 +2586,29 @@ static bool macsec_is_configured(struct macsec_dev *macsec) return false; } +static bool macsec_needs_tx_tag(struct macsec_dev *macsec, + const struct macsec_ops *ops) +{ + return macsec->offload == MACSEC_OFFLOAD_PHY && + ops->mdo_insert_tx_tag; +} + +static void macsec_adjust_room(struct net_device *dev, + const struct macsec_ops *ops) +{ + int diff_headroom = MACSEC_NEEDED_HEADROOM - ops->needed_headroom; + int diff_tailroom = MACSEC_NEEDED_TAILROOM - ops->needed_tailroom; + struct macsec_dev *macsec = macsec_priv(dev); + + if (macsec_is_offloaded(macsec)) { + dev->needed_headroom -= diff_headroom; + dev->needed_tailroom -= diff_tailroom; + } else { + dev->needed_headroom += diff_headroom; + dev->needed_tailroom += diff_tailroom; + } +} + static int macsec_update_offload(struct net_device *dev, enum macsec_offload offload) { enum macsec_offload prev_offload; @@ -2620,8 +2646,13 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off ctx.secy = &macsec->secy; ret = offload == MACSEC_OFFLOAD_OFF ? macsec_offload(ops->mdo_del_secy, &ctx) : macsec_offload(ops->mdo_add_secy, &ctx); - if (ret) + if (ret) { macsec->offload = prev_offload; + return ret; + } + + macsec_adjust_room(dev, ops); + macsec->insert_tx_tag = macsec_needs_tx_tag(macsec, ops); return ret; } @@ -3379,6 +3410,52 @@ static struct genl_family macsec_fam __ro_after_init = { .resv_start_op = MACSEC_CMD_UPD_OFFLOAD + 1, }; +static struct sk_buff *macsec_insert_tx_tag(struct sk_buff *skb, + struct net_device *dev) +{ + struct macsec_dev *macsec = macsec_priv(dev); + const struct macsec_ops *ops; + struct phy_device *phydev; + struct macsec_context ctx; + int err; + + ops = macsec_get_ops(macsec, &ctx); + phydev = macsec->real_dev->phydev; + + if (unlikely(skb_headroom(skb) < ops->needed_headroom || + skb_tailroom(skb) < ops->needed_tailroom)) { + struct sk_buff *nskb = skb_copy_expand(skb, + ops->needed_headroom, + ops->needed_tailroom, + GFP_ATOMIC); + if (likely(nskb)) { + consume_skb(skb); + skb = nskb; + } else { + err = -ENOMEM; + goto cleanup; + } + } else { + skb = skb_unshare(skb, GFP_ATOMIC); + if (!skb) + return ERR_PTR(-ENOMEM); + } + + err = ops->mdo_insert_tx_tag(phydev, skb); + if (unlikely(err)) + goto cleanup; + + if (unlikely(skb->len - ETH_HLEN > macsec_priv(dev)->real_dev->mtu)) { + err = -EINVAL; + goto cleanup; + } + + return skb; +cleanup: + kfree_skb(skb); + return ERR_PTR(err); +} + static netdev_tx_t macsec_start_xmit(struct sk_buff *skb, struct net_device *dev) { @@ -3393,6 +3470,15 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb, skb_dst_drop(skb); dst_hold(&md_dst->dst); skb_dst_set(skb, &md_dst->dst); + + if (macsec->insert_tx_tag) { + skb = macsec_insert_tx_tag(skb, dev); + if (IS_ERR(skb)) { + DEV_STATS_INC(dev, tx_dropped); + return NETDEV_TX_OK; + } + } + skb->dev = macsec->real_dev; return dev_queue_xmit(skb); } @@ -4160,6 +4246,10 @@ static int macsec_newlink(struct net *net, struct net_device *dev, err = macsec_offload(ops->mdo_add_secy, &ctx); if (err) goto del_dev; + + macsec_adjust_room(dev, ops); + macsec->insert_tx_tag = + macsec_needs_tx_tag(macsec, ops); } } diff --git a/include/net/macsec.h b/include/net/macsec.h index 0821fa5088c0..dbd22180cc5c 100644 --- a/include/net/macsec.h +++ b/include/net/macsec.h @@ -316,6 +316,11 @@ struct macsec_context { * @mdo_get_tx_sa_stats: called when TX SA stats are read * @mdo_get_rx_sc_stats: called when RX SC stats are read * @mdo_get_rx_sa_stats: called when RX SA stats are read + * @mdo_insert_tx_tag: called to insert the TX tag + * @needed_headroom: number of bytes reserved at the beginning of the sk_buff + * for the TX tag + * @needed_tailroom: number of bytes reserved at the end of the sk_buff for the + * TX tag */ struct macsec_ops { /* Device wide */ @@ -342,6 +347,11 @@ struct macsec_ops { int (*mdo_get_tx_sa_stats)(struct macsec_context *ctx); int (*mdo_get_rx_sc_stats)(struct macsec_context *ctx); int (*mdo_get_rx_sa_stats)(struct macsec_context *ctx); + /* Offload tag */ + int (*mdo_insert_tx_tag)(struct phy_device *phydev, + struct sk_buff *skb); + unsigned int needed_headroom; + unsigned int needed_tailroom; }; void macsec_pn_wrapped(struct macsec_secy *secy, struct macsec_tx_sa *tx_sa); From patchwork Thu Oct 19 12:02:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428735 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 584F71DFE3 for ; Thu, 19 Oct 2023 12:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="TP5TFK94" Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2070.outbound.protection.outlook.com [40.107.13.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B2A61711; Thu, 19 Oct 2023 05:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WC3dbMpqxa2rdv1KPRUTSxKKSewjDEsKgvh7FEESR6braIUvedZhnJXUyCecS8iS2LuPh/t/rckMgB9g2W9fpX971AkQtEFdhYI+1+MYPOR8i35paS+9Ltgmv6Ss1nSgEBpeG2eE48V+NIAsATyNlyWJfkUMDhzLuJ6GnoxWdjL105ylxzA18A1CBOE4gJk6uQzVjfPiXSzqQDnef1avU+tjrRL0Dz94YY+jR3mfmXa6rqCO2RBFSFNTR3AxI+8wn3akxr3ofr7cgvuEdPN0DEtgwX+m81BIGVfU1mOxrvWxRYcEZ4RX1DcBieJuJ76pW9Z/mu1RNgQRWxZ1avpAFA== 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=27aMOuofqPSD5Tf/QoBPFyB98FyZBWJbDRskcRmgKJg=; b=FDDq8fxqpJtSeXz/8gGNstVeXLbNL4JxUc9K0Fr/umJTsUzp3giL6Hu3Grsp3+pabui/8xH6m6QI1frZS6ASQ7jD6e8VWkBXLT56z4LQGkgdpvPtcu7EjrSlkkWQN7wY0CCpgHW2l/EXTMQMhFBMG9TE3hE/idxp9DgNt4qMnUnZFq7Gl2IqOADXnwrwz/zekrPPmBwxiCA/fE6+cNHML6auuIzyD1JLO96D5DMeAw1FvMO3WeIN/XcGPIURyLeZNr0EsJfXUl5+Kb/We6m8oGIqT4GXScbl09fhoXYYYt00H4OJI3f9e38v8Zt4My3wQd5ql0x7d4r5yaQMYp0vbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=27aMOuofqPSD5Tf/QoBPFyB98FyZBWJbDRskcRmgKJg=; b=TP5TFK94E0d1j1ZmNswbzmzxX7ceNWJ2mEAiNxAjFbjXChoW2iPCF5bDizDnoeZX3Z3KToxpwODUeiqeuTc0CEKfG6qkmoyRVs86F+DD1hlA6VFEzNBxF/evWv2Y9GwNBtAWFpOpLQzmDVkFx0If7mjqrTqRMQmxi4iuBSGEed8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by DBBPR04MB7961.eurprd04.prod.outlook.com (2603:10a6:10:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Thu, 19 Oct 2023 12:02:58 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:58 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 5/7] net: phy: nxp-c45-tja11xx: add MACsec support Date: Thu, 19 Oct 2023 15:02:07 +0300 Message-Id: <20231019120209.290480-6-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|DBBPR04MB7961:EE_ X-MS-Office365-Filtering-Correlation-Id: d41cac46-915a-4b79-495b-08dbd09b559e X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QfCNGQNPzXRiKOA/G5a1eONPNP8uCDrA9zmxjMj/6GhJbBPDS02KLNGjOSniWN9UFxCnHPX7aUJAquPClLHN7eS3LxWRvI4nB6aWsaweObVZQo9R5qUbpF4Oa0jl40GhmMWgr1ExB4F2Vl5tWyUS9SGVLTjCwckgQft4GmbKEwHzBVnQZjmkpD0hfXCVLi2Xc8HwNITbq+Gtv4fehSQjQwnLcHmqSBJDHAV2259fKo3UnagaIu2TZ+0+0wAOTzJEuKxiQELL4JLTM8xb59kRgkqq8JYtJDuiiw3RSSjkZvDmo8ggK4Xcpr/mJ7Eqgv65koBYS7Pl7RhzPAMUlk/eMtke8dNvCl59Ljc2FCrIpQoAlh1kymWG5fHG2uGbtHRgTkGRCzVnAWQBzaRr9bX25ZQne/q4uaNYk3rXIfrOts9l9Bb0u2UKyBRMwr+LKbntvg5TbedWCl7pPQTWbqJiqQHtdTWzSA7yik7H1FTNmEjpqACtQrvXebnKjUHJ/Gw7frwBPqFdAiZW7OS9iuegavLVeZdz39Hm5giYXXyfmlT2Su37OrfT2kjSTlPqlIGtVrRyCZbZQWcLz5fk1INhfccw40K/osvtkh9mmI3leW6+S7/VjBYzFgccDVqokr60 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(38350700005)(41300700001)(6506007)(38100700002)(4326008)(8676002)(2906002)(7416002)(86362001)(83380400001)(1076003)(30864003)(26005)(6512007)(2616005)(52116002)(5660300002)(6486002)(6666004)(478600001)(8936002)(316002)(66476007)(66556008)(66946007)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eBBMGl1JBYfoCXqONi194ucs+VIuz4V5zZt5kf8yukDS43L4an2hyjIXYuBCcuPLi+j5rR45j1IqOuQH0QyxUeNZC3VvRG/vSL+NVEQczlOX3GNu1CRGHnNzzomOPyufAFj2CQA43EdzovXckM2VtJ4pfKn7FYLm60WOPvD9kUFfo/14t5KHrjYE06L+y5IgRVf7ygNsevPqm0wpD04DbrXULlyKEcvm/py1ZYLtp56eTbzPljI+uF8V+A2CtEwvshvHVUyOIIou+zT8ZmUh5QhTwbIMvva5Bjav/8KdWKpnR9DbxiTuYs0EDzHA50jgSMbbqdLARXoB8hEuPckE+2Q9jD7vG83bUpWtHE4VcHXcojq5xG+hlL+AJntsgG3dIfoEj1E6z4tFTTtxoRtJ5CBWjbK95faTxeVLbyLCbkS2meacWUQwziyN8WHA0+6bIWiAON2G8XunZbx/Ya1x+W6xbmVVzAczdZ+4ny/3HoSIhw1MfMts4tWm50Ier28a3p0pF89GlZsPLQXIZ62k7ekjDjDbBHv6oeG3h53ndBIssEMkt8dpNN+H3G8ihAwZdkB56drefn5V+b8Ev96IEqlZVe/H67ZsRCBhJlJau7+05ZymTZUuUeeSJKY4ZwfjTFj3ORWJ/0eieF7Y38Mf+hvmL0cdwvHBNFnOHqvlWCQxOJlPamotdBsNeBOPyFlW8Ay2UK0+8T8e6A42GjHflncE6S7AP9/nXXBwxjAWLJvdBQqa5QufY86C/TOEMqFSaORV9ccwnLbtcJno6M1xNlBu1a0X+lG4U/BJRil4ZFadl2x4fxaNuif1WSIssfnbs+Xc7IQ8rFCYidKnp+YxIBfAJpX5wBkA9+11yfTxp5tgEhAyX33Fy5B9OCNOtN8JuqDRKhhWn4lfFUYuA1R3mue+C4oIEKYxg7+JeaLf47OFzu19ykRzrIFGcTzv4+ZJomwQucbwbL3r1Go2zLZ2jpzeX/HqSaXis1hgsg6aBHIenZQ9/zYXGRjeXr8mrEobgAyhu7ACoIpP+9UhE/l9cbstqrxRbk+a/x69BPJEoK5fpwfCj5oYQtQR0+vA+FhQ1ExndVDSkuxG1SPTeFHyhtj1cdvae5+JlXYzIRcxLIuq5h3jJA8lBM06lpJliJ4kxH8cJhIVOvk5sgZQ6ZAbenXMtjTmfKm30FDwsy3/RVMoHJBviWPD5FGGz2nwaVmeUzMq/bdEAGZPOF7SbdBJcyDGQZwauqdyD4VwStfBU+X2n6sYQckzEj8Db4tdv5IvKGPpXbUS+WcZDJITrtrpMMTGmf6v+Qywyq/KOvXbOrOoEXwQY6VZB2i/K6D75DVZeYxuqjCV9mVuKS1kRSkmVxQgODxGYyzvLG5reLFePhILIgor/D+Z2UmQ4z5QPSHGN3rRN27fURymesqNtULu9G1I8lRWrw3/z+xbRTtcnPRglfRvWa5+nXKmdz1Gx7PNQOl7y7Z648A5hajKl1F5FeSpToSggkS+EORXm6hMEbR02fHFZfK+vw05VJ/nZVPK+A5vwxbqlX0ZVnlNhOfo+zhtsDFamarzBDKY2aSBzI2GZz4EKftxgZyilIqEWcc4i4lkXbFO2SwrwfLAkW9t3w== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d41cac46-915a-4b79-495b-08dbd09b559e X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:57.9706 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3WQ812i0/0qFJXlZgi2lmffh8jkkSNfIIOQELoB7E9j/S2j4KkJ8O7KAzkdMvMPjAAsZdYBAQJyRUBtTsbo+suZb5oQEL3NkEyzyOiEY1pU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7961 X-Patchwork-Delegate: kuba@kernel.org Add MACsec support. The MACsec block has four TX SCs and four RX SCs. The driver supports up to four SecY. Each SecY with one TX SC and one RX SC. The RX SCs can have two keys, key A and key B, written in hardware and enabled at the same time. The TX SCs can have two keys written in hardware, but only one can be active at a given time. On TX, the SC is selected using the MAC source address. Due of this selection mechanism, each offloaded netdev must have a unique MAC address. On RX, the SC is selected by SCI(found in SecTAG or calculated using MAC SA), or using RX SC 0 as implicit. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v6-v7: - none Changes in V5: - added nxp_c45_secy_irq_en helper to enable and disable the irqs and replaced the irq enable/disable sequence from nxp_c45_mdo_add_secy/nxp_c45_mdo_del_secy with it - changed nxp_c45_tx_sc_set_flt parameters. macsec_context and secy_id replaced with phy_device and nxp_c45_secy pointers. - nxp_c45_mdo_dev_open/nxp_c45_mdo_dev_stop - priv is get from phydev->priv instead of ctx->phydev->priv - nxp_c45_sa_set_key - nxp_c45_macsec_write call uses phydev(local variable) instead of ctx->phydev Changes in V4: - Added nxp_c45_secy_free. - Added nxp_c45_macsec_en. - Added nxp_c45_macsec_remove. - nxp_c45_sa_set_pn does if the pn is 0. validate_upd_sa checks this. - check ctx->sa.update_pn flag before updating next_pn. - nxp_c45_macsec_config_init and nxp_c45_handle_macsec_interrupt are checking priv->macsec instead of phydev->macsec_ops to check if macsec is offloaded. - nxp_c45_handle_macsec_interrupt - replaced WARN_ON(!sa) with WARN_ON(1). sa is either -err_value or a valid pointer and WARN_ON was doing nothing. - nxp_c45_tx_sa_update does not check if (sa->an != encoding_sa). encoding_sa removed from parameters list. - nxp_c45_mdo_upd/del_txsa updates the sa status only if sa->an == encoding_sa - nxp_c45_mdo_add_rxsc - apply RX SCI restrictions only if end_station is true Changes in v3: - removed struct nxp_c45_rx_sc - replaced struct nxp_c45_tx_sa with struct nxp_c45_sa - reworked the implementation around struct nxp_c45_sa - various renamings - tried to better group the functions by SA type/SC type - no key is stored in the driver - TX SAs limited to 2 insted of 4(no key in the driver consequence) - used sci_to_cpu where in various functions - improved debug information - nxp_c45_secy_valid function reworked - merged TX/RX SA set key functions - merged TX/RX SA set pn functions - tried to stick to tx_sa/rx_sa/rx_sc/tx_sc function naming. - nxp_c45_macsec_config_init will return an error if a write fails. - MACSEC_TXSC_CFG_SCI renamed to MACSEC_TXSC_CFG_SCB - return -ENOSPC if no SC/SA available in the hardware - phydev->macsec allocated using devm_kzalloc - changed name of the driver object file Changes in v2: - WARN_ON_ONCE if reg address is not properly aligned - improved patch description MAINTAINERS | 2 +- drivers/net/phy/Kconfig | 2 +- drivers/net/phy/Makefile | 6 +- drivers/net/phy/nxp-c45-tja11xx-macsec.c | 1338 ++++++++++++++++++++++ drivers/net/phy/nxp-c45-tja11xx.c | 77 +- drivers/net/phy/nxp-c45-tja11xx.h | 62 + 6 files changed, 1454 insertions(+), 33 deletions(-) create mode 100644 drivers/net/phy/nxp-c45-tja11xx-macsec.c create mode 100644 drivers/net/phy/nxp-c45-tja11xx.h diff --git a/MAINTAINERS b/MAINTAINERS index ed33b9df8b3d..e9483df80dc4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15302,7 +15302,7 @@ NXP C45 TJA11XX PHY DRIVER M: Radu Pirea L: netdev@vger.kernel.org S: Maintained -F: drivers/net/phy/nxp-c45-tja11xx.c +F: drivers/net/phy/nxp-c45-tja11xx* NXP FSPI DRIVER M: Han Xu diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 421d2b62918f..a0044681d28c 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -306,7 +306,7 @@ config NXP_C45_TJA11XX_PHY depends on PTP_1588_CLOCK_OPTIONAL help Enable support for NXP C45 TJA11XX PHYs. - Currently supports the TJA1103 and TJA1120 PHYs. + Currently supports the TJA1103, TJA1104 and TJA1120 PHYs. config NXP_TJA11XX_PHY tristate "NXP TJA11xx PHYs support" diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index c945ed9bd14b..62b42f0d6a85 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -83,7 +83,11 @@ obj-$(CONFIG_MICROSEMI_PHY) += mscc/ obj-$(CONFIG_MOTORCOMM_PHY) += motorcomm.o obj-$(CONFIG_NATIONAL_PHY) += national.o obj-$(CONFIG_NCN26000_PHY) += ncn26000.o -obj-$(CONFIG_NXP_C45_TJA11XX_PHY) += nxp-c45-tja11xx.o +nxp-c45-tja-objs += nxp-c45-tja11xx.o +ifdef CONFIG_MACSEC +nxp-c45-tja-objs += nxp-c45-tja11xx-macsec.o +endif +obj-$(CONFIG_NXP_C45_TJA11XX_PHY) += nxp-c45-tja.o obj-$(CONFIG_NXP_CBTX_PHY) += nxp-cbtx.o obj-$(CONFIG_NXP_TJA11XX_PHY) += nxp-tja11xx.o obj-$(CONFIG_QSEMI_PHY) += qsemi.o diff --git a/drivers/net/phy/nxp-c45-tja11xx-macsec.c b/drivers/net/phy/nxp-c45-tja11xx-macsec.c new file mode 100644 index 000000000000..821f8926f7f2 --- /dev/null +++ b/drivers/net/phy/nxp-c45-tja11xx-macsec.c @@ -0,0 +1,1338 @@ +// SPDX-License-Identifier: GPL-2.0 +/* NXP C45 PTP PHY driver interface + * Copyright 2023 NXP + * Author: Radu Pirea + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nxp-c45-tja11xx.h" + +#define MACSEC_REG_SIZE 32 +#define TX_SC_MAX 4 + +#define TX_SC_BIT(secy_id) BIT(MACSEC_REG_SIZE - (secy_id) - 1) + +#define VEND1_MACSEC_BASE 0x9000 + +#define MACSEC_CFG 0x0000 +#define MACSEC_CFG_BYPASS BIT(1) +#define MACSEC_CFG_S0I BIT(0) + +#define MACSEC_TPNET 0x0044 +#define PN_WRAP_THRESHOLD 0xffffffff + +#define MACSEC_RXSCA 0x0080 +#define MACSEC_RXSCKA 0x0084 + +#define MACSEC_TXSCA 0x00C0 +#define MACSEC_TXSCKA 0x00C4 + +#define MACSEC_RXSC_SCI_1H 0x0100 + +#define MACSEC_RXSC_CFG 0x0128 +#define MACSEC_RXSC_CFG_XPN BIT(25) +#define MACSEC_RXSC_CFG_AES_256 BIT(24) +#define MACSEC_RXSC_CFG_SCI_EN BIT(11) +#define MACSEC_RXSC_CFG_RP BIT(10) +#define MACSEC_RXSC_CFG_VF_MASK GENMASK(9, 8) +#define MACSEC_RXSC_CFG_VF_OFF 8 + +#define MACSEC_RPW 0x012C + +#define MACSEC_RXSA_A_CS 0x0180 +#define MACSEC_RXSA_A_NPN 0x0184 +#define MACSEC_RXSA_A_XNPN 0x0188 +#define MACSEC_RXSA_A_LNPN 0x018C +#define MACSEC_RXSA_A_LXNPN 0x0190 + +#define MACSEC_RXSA_B_CS 0x01C0 +#define MACSEC_RXSA_B_NPN 0x01C4 +#define MACSEC_RXSA_B_XNPN 0x01C8 +#define MACSEC_RXSA_B_LNPN 0x01CC +#define MACSEC_RXSA_B_LXNPN 0x01D0 + +#define MACSEC_RXSA_CS_AN_OFF 1 +#define MACSEC_RXSA_CS_EN BIT(0) + +#define MACSEC_TXSC_SCI_1H 0x0200 +#define MACSEC_TXSC_CFG 0x0228 +#define MACSEC_TXSC_CFG_XPN BIT(25) +#define MACSEC_TXSC_CFG_AES_256 BIT(24) +#define MACSEC_TXSC_CFG_AN_MASK GENMASK(19, 18) +#define MACSEC_TXSC_CFG_AN_OFF 18 +#define MACSEC_TXSC_CFG_ASA BIT(17) +#define MACSEC_TXSC_CFG_SCE BIT(16) +#define MACSEC_TXSC_CFG_ENCRYPT BIT(4) +#define MACSEC_TXSC_CFG_PROTECT BIT(3) +#define MACSEC_TXSC_CFG_SEND_SCI BIT(2) +#define MACSEC_TXSC_CFG_END_STATION BIT(1) +#define MACSEC_TXSC_CFG_SCB BIT(0) + +#define MACSEC_TXSA_A_CS 0x0280 +#define MACSEC_TXSA_A_NPN 0x0284 +#define MACSEC_TXSA_A_XNPN 0x0288 + +#define MACSEC_TXSA_B_CS 0x02C0 +#define MACSEC_TXSA_B_NPN 0x02C4 +#define MACSEC_TXSA_B_XNPN 0x02C8 + +#define MACSEC_SA_CS_A BIT(31) + +#define MACSEC_EVR 0x0400 +#define MACSEC_EVER 0x0404 + +#define MACSEC_RXSA_A_KA 0x0700 +#define MACSEC_RXSA_A_SSCI 0x0720 +#define MACSEC_RXSA_A_SALT 0x0724 + +#define MACSEC_RXSA_B_KA 0x0740 +#define MACSEC_RXSA_B_SSCI 0x0760 +#define MACSEC_RXSA_B_SALT 0x0764 + +#define MACSEC_TXSA_A_KA 0x0780 +#define MACSEC_TXSA_A_SSCI 0x07A0 +#define MACSEC_TXSA_A_SALT 0x07A4 + +#define MACSEC_TXSA_B_KA 0x07C0 +#define MACSEC_TXSA_B_SSCI 0x07E0 +#define MACSEC_TXSA_B_SALT 0x07E4 + +#define MACSEC_UPFR0D2 0x0A08 +#define MACSEC_UPFR0M1 0x0A10 +#define MACSEC_OVP BIT(12) + +#define MACSEC_UPFR0M2 0x0A14 +#define ETYPE_MASK 0xffff + +#define MACSEC_UPFR0R 0x0A18 +#define MACSEC_UPFR_EN BIT(0) + +#define ADPTR_CNTRL 0x0F00 +#define ADPTR_CNTRL_CONFIG_EN BIT(14) +#define ADPTR_CNTRL_ADPTR_EN BIT(12) + +#define TX_SC_FLT_BASE 0x800 +#define TX_SC_FLT_SIZE 0x10 +#define TX_FLT_BASE(flt_id) (TX_SC_FLT_BASE + \ + TX_SC_FLT_SIZE * (flt_id)) + +#define TX_SC_FLT_OFF_MAC_DA_SA 0x04 +#define TX_SC_FLT_OFF_MAC_SA 0x08 +#define TX_SC_FLT_OFF_MAC_CFG 0x0C +#define TX_SC_FLT_BY_SA BIT(14) +#define TX_SC_FLT_EN BIT(8) + +#define TX_SC_FLT_MAC_DA_SA(base) ((base) + TX_SC_FLT_OFF_MAC_DA_SA) +#define TX_SC_FLT_MAC_SA(base) ((base) + TX_SC_FLT_OFF_MAC_SA) +#define TX_SC_FLT_MAC_CFG(base) ((base) + TX_SC_FLT_OFF_MAC_CFG) + +#define ADAPTER_EN BIT(6) +#define MACSEC_EN BIT(5) + +enum nxp_c45_sa_type { + TX_SA, + RX_SA, +}; + +struct nxp_c45_sa { + void *sa; + const struct nxp_c45_sa_regs *regs; + enum nxp_c45_sa_type type; + bool is_key_a; + u8 an; + struct list_head list; +}; + +struct nxp_c45_secy { + struct macsec_secy *secy; + struct macsec_rx_sc *rx_sc; + struct list_head sa_list; + int secy_id; + bool rx_sc0_impl; + struct list_head list; +}; + +struct nxp_c45_macsec { + struct list_head secy_list; + DECLARE_BITMAP(secy_bitmap, TX_SC_MAX); + DECLARE_BITMAP(tx_sc_bitmap, TX_SC_MAX); +}; + +struct nxp_c45_sa_regs { + u16 cs; + u16 npn; + u16 xnpn; + u16 lnpn; + u16 lxnpn; + u16 ka; + u16 ssci; + u16 salt; +}; + +static const struct nxp_c45_sa_regs rx_sa_a_regs = { + .cs = MACSEC_RXSA_A_CS, + .npn = MACSEC_RXSA_A_NPN, + .xnpn = MACSEC_RXSA_A_XNPN, + .lnpn = MACSEC_RXSA_A_LNPN, + .lxnpn = MACSEC_RXSA_A_LXNPN, + .ka = MACSEC_RXSA_A_KA, + .ssci = MACSEC_RXSA_A_SSCI, + .salt = MACSEC_RXSA_A_SALT, +}; + +static const struct nxp_c45_sa_regs rx_sa_b_regs = { + .cs = MACSEC_RXSA_B_CS, + .npn = MACSEC_RXSA_B_NPN, + .xnpn = MACSEC_RXSA_B_XNPN, + .lnpn = MACSEC_RXSA_B_LNPN, + .lxnpn = MACSEC_RXSA_B_LXNPN, + .ka = MACSEC_RXSA_B_KA, + .ssci = MACSEC_RXSA_B_SSCI, + .salt = MACSEC_RXSA_B_SALT, +}; + +static const struct nxp_c45_sa_regs tx_sa_a_regs = { + .cs = MACSEC_TXSA_A_CS, + .npn = MACSEC_TXSA_A_NPN, + .xnpn = MACSEC_TXSA_A_XNPN, + .ka = MACSEC_TXSA_A_KA, + .ssci = MACSEC_TXSA_A_SSCI, + .salt = MACSEC_TXSA_A_SALT, +}; + +static const struct nxp_c45_sa_regs tx_sa_b_regs = { + .cs = MACSEC_TXSA_B_CS, + .npn = MACSEC_TXSA_B_NPN, + .xnpn = MACSEC_TXSA_B_XNPN, + .ka = MACSEC_TXSA_B_KA, + .ssci = MACSEC_TXSA_B_SSCI, + .salt = MACSEC_TXSA_B_SALT, +}; + +static const +struct nxp_c45_sa_regs *nxp_c45_sa_regs_get(enum nxp_c45_sa_type sa_type, + bool key_a) +{ + if (sa_type == RX_SA) + if (key_a) + return &rx_sa_a_regs; + else + return &rx_sa_b_regs; + else if (sa_type == TX_SA) + if (key_a) + return &tx_sa_a_regs; + else + return &tx_sa_b_regs; + else + return NULL; +} + +static int nxp_c45_macsec_write(struct phy_device *phydev, u16 addr, u32 value) +{ + u32 lvalue = value; + u16 laddr; + int ret; + + WARN_ON_ONCE(addr % 4); + + phydev_dbg(phydev, "write addr 0x%x value 0x%x\n", addr, value); + + laddr = VEND1_MACSEC_BASE + addr / 2; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, laddr, lvalue); + if (ret) + return ret; + + laddr += 1; + lvalue >>= 16; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, laddr, lvalue); + + return ret; +} + +static int nxp_c45_macsec_read(struct phy_device *phydev, u16 addr, u32 *value) +{ + u32 lvalue; + u16 laddr; + int ret; + + WARN_ON_ONCE(addr % 4); + + laddr = VEND1_MACSEC_BASE + addr / 2; + ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, laddr); + if (ret < 0) + return ret; + + laddr += 1; + lvalue = (u32)ret & 0xffff; + ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, laddr); + if (ret < 0) + return ret; + + lvalue |= (u32)ret << 16; + *value = lvalue; + + phydev_dbg(phydev, "read addr 0x%x value 0x%x\n", addr, *value); + + return 0; +} + +static void nxp_c45_secy_irq_en(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy, bool en) +{ + u32 reg; + + nxp_c45_macsec_read(phydev, MACSEC_EVER, ®); + if (en) + reg |= TX_SC_BIT(phy_secy->secy_id); + else + reg &= ~TX_SC_BIT(phy_secy->secy_id); + nxp_c45_macsec_write(phydev, MACSEC_EVER, reg); +} + +static struct nxp_c45_secy *nxp_c45_find_secy(struct list_head *secy_list, + sci_t sci) +{ + struct nxp_c45_secy *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, secy_list, list) + if (pos->secy->sci == sci) + return pos; + + return ERR_PTR(-EINVAL); +} + +static void nxp_c45_secy_free(struct nxp_c45_secy *phy_secy) +{ + list_del(&phy_secy->list); + kfree(phy_secy); +} + +static struct nxp_c45_sa *nxp_c45_find_sa(struct list_head *sa_list, + enum nxp_c45_sa_type sa_type, u8 an) +{ + struct nxp_c45_sa *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, sa_list, list) + if (pos->an == an && pos->type == sa_type) + return pos; + + return ERR_PTR(-EINVAL); +} + +static struct nxp_c45_sa *nxp_c45_sa_alloc(struct list_head *sa_list, void *sa, + enum nxp_c45_sa_type sa_type, u8 an) +{ + struct nxp_c45_sa *first = NULL, *pos, *tmp; + int ocurences = 0; + + list_for_each_entry_safe(pos, tmp, sa_list, list) { + if (pos->type != sa_type) + continue; + + if (pos->an == an) + return ERR_PTR(-EINVAL); + + first = pos; + ocurences++; + if (ocurences >= 2) + return ERR_PTR(-ENOSPC); + } + + tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); + if (!tmp) + return ERR_PTR(-ENOMEM); + + if (first) + tmp->is_key_a = !first->is_key_a; + else + tmp->is_key_a = true; + + tmp->sa = sa; + tmp->type = sa_type; + tmp->an = an; + tmp->regs = nxp_c45_sa_regs_get(tmp->type, tmp->is_key_a); + list_add_tail(&tmp->list, sa_list); + + return tmp; +} + +static void nxp_c45_sa_free(struct nxp_c45_sa *sa) +{ + list_del(&sa->list); + kfree_sensitive(sa); +} + +static void nxp_c45_sa_list_free(struct list_head *sa_list) +{ + struct nxp_c45_sa *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, sa_list, list) + nxp_c45_sa_free(pos); +} + +static void nxp_c45_sa_set_pn(struct phy_device *phydev, + struct nxp_c45_sa *sa, u64 pn, + u32 replay_window) +{ + const struct nxp_c45_sa_regs *sa_regs = sa->regs; + pn_t npn = {.full64 = pn}; + pn_t lnpn; + + nxp_c45_macsec_write(phydev, sa_regs->npn, npn.lower); + nxp_c45_macsec_write(phydev, sa_regs->xnpn, npn.upper); + if (sa->type != RX_SA) + return; + + if (pn > replay_window) + lnpn.full64 = pn - replay_window; + else + lnpn.full64 = 1; + + nxp_c45_macsec_write(phydev, sa_regs->lnpn, lnpn.lower); + nxp_c45_macsec_write(phydev, sa_regs->lxnpn, lnpn.upper); +} + +static void nxp_c45_sa_set_key(struct macsec_context *ctx, + const struct nxp_c45_sa_regs *sa_regs, + u8 *salt, ssci_t ssci) +{ + struct phy_device *phydev = ctx->phydev; + u32 key_size = ctx->secy->key_len / 4; + u32 salt_size = MACSEC_SALT_LEN / 4; + u32 *key_u32 = (u32 *)ctx->sa.key; + u32 *salt_u32 = (u32 *)salt; + u32 reg, value; + int i; + + for (i = 0; i < key_size; i++) { + reg = sa_regs->ka + i * 4; + value = (__force u32)cpu_to_be32(key_u32[i]); + nxp_c45_macsec_write(phydev, reg, value); + } + + if (ctx->secy->xpn) { + for (i = 0; i < salt_size; i++) { + reg = sa_regs->salt + (2 - i) * 4; + value = (__force u32)cpu_to_be32(salt_u32[i]); + nxp_c45_macsec_write(phydev, reg, value); + } + + value = (__force u32)cpu_to_be32((__force u32)ssci); + nxp_c45_macsec_write(phydev, sa_regs->ssci, value); + } + + nxp_c45_macsec_write(phydev, sa_regs->cs, MACSEC_SA_CS_A); +} + +static void nxp_c45_rx_sa_update(struct phy_device *phydev, + struct nxp_c45_sa *sa, bool en) +{ + const struct nxp_c45_sa_regs *sa_regs = sa->regs; + u32 cfg; + + cfg = sa->an << MACSEC_RXSA_CS_AN_OFF; + cfg |= en ? MACSEC_RXSA_CS_EN : 0; + nxp_c45_macsec_write(phydev, sa_regs->cs, cfg); +} + +static void nxp_c45_tx_sa_update(struct phy_device *phydev, + struct nxp_c45_sa *sa, bool en) +{ + u32 cfg = 0; + + nxp_c45_macsec_read(phydev, MACSEC_TXSC_CFG, &cfg); + + cfg &= ~MACSEC_TXSC_CFG_AN_MASK; + cfg |= sa->an << MACSEC_TXSC_CFG_AN_OFF; + + if (sa->is_key_a) + cfg &= ~MACSEC_TXSC_CFG_ASA; + else + cfg |= MACSEC_TXSC_CFG_ASA; + + if (en) + cfg |= MACSEC_TXSC_CFG_SCE; + else + cfg &= ~MACSEC_TXSC_CFG_SCE; + + nxp_c45_macsec_write(phydev, MACSEC_TXSC_CFG, cfg); +} + +static void nxp_c45_set_sci(struct phy_device *phydev, u16 sci_base_addr, + sci_t sci) +{ + u64 lsci = sci_to_cpu(sci); + + nxp_c45_macsec_write(phydev, sci_base_addr, lsci >> 32); + nxp_c45_macsec_write(phydev, sci_base_addr + 4, lsci); +} + +static bool nxp_c45_sci_valid(sci_t sci, bool scb) +{ + u16 port = sci_to_cpu(sci); + + if (scb && port != 0) + return false; + if (!scb && port != 1) + return false; + + return true; +} + +static void nxp_c45_select_secy(struct phy_device *phydev, u8 id) +{ + nxp_c45_macsec_write(phydev, MACSEC_RXSCA, id); + nxp_c45_macsec_write(phydev, MACSEC_RXSCKA, id); + nxp_c45_macsec_write(phydev, MACSEC_TXSCA, id); + nxp_c45_macsec_write(phydev, MACSEC_TXSCKA, id); +} + +static bool nxp_c45_secy_valid(struct nxp_c45_secy *phy_secy, + bool can_rx_sc0_impl) +{ + bool end_station = phy_secy->secy->tx_sc.end_station; + bool send_sci = phy_secy->secy->tx_sc.send_sci; + bool scb = phy_secy->secy->tx_sc.scb; + bool rx_sci_valid, tx_sci_valid; + sci_t sci = phy_secy->secy->sci; + + phy_secy->rx_sc0_impl = false; + + if (send_sci) { + if (end_station || scb) + return false; + else + return true; + } + + if (end_station) { + tx_sci_valid = nxp_c45_sci_valid(sci, scb); + if (phy_secy->rx_sc) { + sci = phy_secy->rx_sc->sci; + rx_sci_valid = nxp_c45_sci_valid(sci, scb); + } else { + rx_sci_valid = true; + } + + return tx_sci_valid && rx_sci_valid; + } + + if (scb) + return false; + + if (!can_rx_sc0_impl) + return false; + + if (phy_secy->secy_id != 0) + return false; + + phy_secy->rx_sc0_impl = true; + + return true; +} + +static bool nxp_c45_mac_addr_free(struct macsec_context *ctx) +{ + struct nxp_c45_phy *priv = ctx->phydev->priv; + struct nxp_c45_secy *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, &priv->macsec->secy_list, list) { + if (pos->secy == ctx->secy) + continue; + + if (memcmp(pos->secy->netdev->dev_addr, + ctx->secy->netdev->dev_addr, ETH_ALEN) == 0) + return false; + } + + return true; +} + +static void nxp_c45_tx_sc_en_flt(struct phy_device *phydev, int secy_id, + bool en) +{ + u32 tx_flt_base = TX_FLT_BASE(secy_id); + u32 reg = 0; + + nxp_c45_macsec_read(phydev, TX_SC_FLT_MAC_CFG(tx_flt_base), ®); + if (en) + reg |= TX_SC_FLT_EN; + else + reg &= ~TX_SC_FLT_EN; + nxp_c45_macsec_write(phydev, TX_SC_FLT_MAC_CFG(tx_flt_base), reg); +} + +static void nxp_c45_tx_sc_set_flt(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + const u8 *dev_addr = phy_secy->secy->netdev->dev_addr; + u32 tx_flt_base = TX_FLT_BASE(phy_secy->secy_id); + u32 reg; + + reg = dev_addr[0] << 8 | dev_addr[1]; + nxp_c45_macsec_write(phydev, TX_SC_FLT_MAC_DA_SA(tx_flt_base), reg); + reg = dev_addr[5] | dev_addr[4] << 8 | dev_addr[3] << 16 | + dev_addr[2] << 24; + + nxp_c45_macsec_write(phydev, TX_SC_FLT_MAC_SA(tx_flt_base), reg); + nxp_c45_macsec_read(phydev, TX_SC_FLT_MAC_CFG(tx_flt_base), ®); + reg &= TX_SC_FLT_EN; + reg |= TX_SC_FLT_BY_SA | phy_secy->secy_id; + nxp_c45_macsec_write(phydev, TX_SC_FLT_MAC_CFG(tx_flt_base), reg); +} + +static void nxp_c45_tx_sc_update(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + u32 cfg = 0; + + nxp_c45_macsec_read(phydev, MACSEC_TXSC_CFG, &cfg); + + phydev_dbg(phydev, "XPN %s\n", phy_secy->secy->xpn ? "on" : "off"); + if (phy_secy->secy->xpn) + cfg |= MACSEC_TXSC_CFG_XPN; + else + cfg &= ~MACSEC_TXSC_CFG_XPN; + + phydev_dbg(phydev, "key len %u\n", phy_secy->secy->key_len); + if (phy_secy->secy->key_len == 32) + cfg |= MACSEC_TXSC_CFG_AES_256; + else + cfg &= ~MACSEC_TXSC_CFG_AES_256; + + phydev_dbg(phydev, "encryption %s\n", + phy_secy->secy->tx_sc.encrypt ? "on" : "off"); + if (phy_secy->secy->tx_sc.encrypt) + cfg |= MACSEC_TXSC_CFG_ENCRYPT; + else + cfg &= ~MACSEC_TXSC_CFG_ENCRYPT; + + phydev_dbg(phydev, "protect frames %s\n", + phy_secy->secy->protect_frames ? "on" : "off"); + if (phy_secy->secy->protect_frames) + cfg |= MACSEC_TXSC_CFG_PROTECT; + else + cfg &= ~MACSEC_TXSC_CFG_PROTECT; + + phydev_dbg(phydev, "send sci %s\n", + phy_secy->secy->tx_sc.send_sci ? "on" : "off"); + if (phy_secy->secy->tx_sc.send_sci) + cfg |= MACSEC_TXSC_CFG_SEND_SCI; + else + cfg &= ~MACSEC_TXSC_CFG_SEND_SCI; + + phydev_dbg(phydev, "end station %s\n", + phy_secy->secy->tx_sc.end_station ? "on" : "off"); + if (phy_secy->secy->tx_sc.end_station) + cfg |= MACSEC_TXSC_CFG_END_STATION; + else + cfg &= ~MACSEC_TXSC_CFG_END_STATION; + + phydev_dbg(phydev, "scb %s\n", + phy_secy->secy->tx_sc.scb ? "on" : "off"); + if (phy_secy->secy->tx_sc.scb) + cfg |= MACSEC_TXSC_CFG_SCB; + else + cfg &= ~MACSEC_TXSC_CFG_SCB; + + nxp_c45_macsec_write(phydev, MACSEC_TXSC_CFG, cfg); +} + +static void nxp_c45_set_rx_sc0_impl(struct phy_device *phydev, + bool enable) +{ + u32 reg = 0; + + nxp_c45_macsec_read(phydev, MACSEC_CFG, ®); + if (enable) + reg |= MACSEC_CFG_S0I; + else + reg &= ~MACSEC_CFG_S0I; + nxp_c45_macsec_write(phydev, MACSEC_CFG, reg); +} + +static bool nxp_c45_is_rx_sc0_impl(struct list_head *secy_list) +{ + struct nxp_c45_secy *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, secy_list, list) + if (pos->rx_sc0_impl) + return pos->rx_sc0_impl; + + return false; +} + +static void nxp_c45_rx_sc_en(struct phy_device *phydev, + struct macsec_rx_sc *rx_sc, bool en) +{ + u32 reg = 0; + + nxp_c45_macsec_read(phydev, MACSEC_RXSC_CFG, ®); + if (rx_sc->active && en) + reg |= MACSEC_RXSC_CFG_SCI_EN; + else + reg &= ~MACSEC_RXSC_CFG_SCI_EN; + nxp_c45_macsec_write(phydev, MACSEC_RXSC_CFG, reg); +} + +static void nxp_c45_rx_sc_update(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + struct macsec_rx_sc *rx_sc = phy_secy->rx_sc; + struct nxp_c45_phy *priv = phydev->priv; + u32 cfg = 0; + + nxp_c45_macsec_read(phydev, MACSEC_RXSC_CFG, &cfg); + cfg &= ~MACSEC_RXSC_CFG_VF_MASK; + cfg = phy_secy->secy->validate_frames << MACSEC_RXSC_CFG_VF_OFF; + + phydev_dbg(phydev, "validate frames %u\n", + phy_secy->secy->validate_frames); + phydev_dbg(phydev, "replay_protect %s window %u\n", + phy_secy->secy->replay_protect ? "on" : "off", + phy_secy->secy->replay_window); + if (phy_secy->secy->replay_protect) { + cfg |= MACSEC_RXSC_CFG_RP; + if (cfg & MACSEC_RXSC_CFG_SCI_EN) { + phydev_dbg(phydev, "RX SC enabled, window will not be updated\n"); + } else { + phydev_dbg(phydev, "RX SC disabled, window will be updated\n"); + nxp_c45_macsec_write(phydev, MACSEC_RPW, + phy_secy->secy->replay_window); + } + } else { + cfg &= ~MACSEC_RXSC_CFG_RP; + } + + phydev_dbg(phydev, "rx_sc->active %s\n", + rx_sc->active ? "on" : "off"); + if (rx_sc->active && + test_bit(phy_secy->secy_id, priv->macsec->secy_bitmap)) + cfg |= MACSEC_RXSC_CFG_SCI_EN; + else + cfg &= ~MACSEC_RXSC_CFG_SCI_EN; + + phydev_dbg(phydev, "key len %u\n", phy_secy->secy->key_len); + if (phy_secy->secy->key_len == 32) + cfg |= MACSEC_RXSC_CFG_AES_256; + else + cfg &= ~MACSEC_RXSC_CFG_AES_256; + + phydev_dbg(phydev, "XPN %s\n", phy_secy->secy->xpn ? "on" : "off"); + if (phy_secy->secy->xpn) + cfg |= MACSEC_RXSC_CFG_XPN; + else + cfg &= ~MACSEC_RXSC_CFG_XPN; + + nxp_c45_macsec_write(phydev, MACSEC_RXSC_CFG, cfg); +} + +static void nxp_c45_rx_sc_del(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + struct nxp_c45_sa *pos, *tmp; + + nxp_c45_macsec_write(phydev, MACSEC_RXSC_CFG, 0); + nxp_c45_macsec_write(phydev, MACSEC_RPW, 0); + nxp_c45_set_sci(phydev, MACSEC_RXSC_SCI_1H, 0); + + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) + if (pos->type == RX_SA) + nxp_c45_rx_sa_update(phydev, pos, false); +} + +static void nxp_c45_macsec_en(struct phy_device *phydev, bool en) +{ + u32 reg; + + nxp_c45_macsec_read(phydev, MACSEC_CFG, ®); + if (en) + reg |= MACSEC_CFG_BYPASS; + else + reg &= ~MACSEC_CFG_BYPASS; + nxp_c45_macsec_write(phydev, MACSEC_CFG, reg); +} + +static int nxp_c45_mdo_dev_open(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + int any_bit_set; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_tx_sc_en_flt(phydev, phy_secy->secy_id, true); + nxp_c45_set_rx_sc0_impl(phydev, phy_secy->rx_sc0_impl); + if (phy_secy->rx_sc) + nxp_c45_rx_sc_en(phydev, phy_secy->rx_sc, true); + + any_bit_set = find_first_bit(priv->macsec->secy_bitmap, TX_SC_MAX); + if (any_bit_set == TX_SC_MAX) + nxp_c45_macsec_en(phydev, true); + + set_bit(phy_secy->secy_id, priv->macsec->secy_bitmap); + + return 0; +} + +static int nxp_c45_mdo_dev_stop(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + int any_bit_set; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_tx_sc_en_flt(phydev, phy_secy->secy_id, false); + if (phy_secy->rx_sc) + nxp_c45_rx_sc_en(phydev, phy_secy->rx_sc, false); + nxp_c45_set_rx_sc0_impl(phydev, false); + + clear_bit(phy_secy->secy_id, priv->macsec->secy_bitmap); + any_bit_set = find_first_bit(priv->macsec->secy_bitmap, TX_SC_MAX); + if (any_bit_set == TX_SC_MAX) + nxp_c45_macsec_en(phydev, false); + + return 0; +} + +static int nxp_c45_mdo_add_secy(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + bool can_rx_sc0_impl; + int idx; + + phydev_dbg(phydev, "add SecY SCI %016llx\n", + sci_to_cpu(ctx->secy->sci)); + + if (!nxp_c45_mac_addr_free(ctx)) + return -EBUSY; + + if (nxp_c45_is_rx_sc0_impl(&priv->macsec->secy_list)) + return -EBUSY; + + idx = find_first_zero_bit(priv->macsec->tx_sc_bitmap, TX_SC_MAX); + if (idx == TX_SC_MAX) + return -ENOSPC; + + phy_secy = kzalloc(sizeof(*phy_secy), GFP_KERNEL); + if (!phy_secy) + return -ENOMEM; + + INIT_LIST_HEAD(&phy_secy->sa_list); + phy_secy->secy = ctx->secy; + phy_secy->secy_id = idx; + + /* If the point to point mode should be enabled, we should have only + * one SecY enabled, respectively the new one. + */ + can_rx_sc0_impl = list_count_nodes(&priv->macsec->secy_list) == 0; + if (!nxp_c45_secy_valid(phy_secy, can_rx_sc0_impl)) { + kfree_sensitive(phy_secy); + return -EINVAL; + } + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_set_sci(phydev, MACSEC_TXSC_SCI_1H, ctx->secy->sci); + nxp_c45_tx_sc_set_flt(phydev, phy_secy); + nxp_c45_tx_sc_update(phydev, phy_secy); + if (phy_interrupt_is_valid(phydev)) + nxp_c45_secy_irq_en(phydev, phy_secy, true); + + set_bit(idx, priv->macsec->tx_sc_bitmap); + list_add_tail(&phy_secy->list, &priv->macsec->secy_list); + + return 0; +} + +static void nxp_c45_tx_sa_next(struct nxp_c45_secy *phy_secy, + struct nxp_c45_sa *next_sa, u8 encoding_sa) +{ + struct nxp_c45_sa *sa; + + sa = nxp_c45_find_sa(&phy_secy->sa_list, TX_SA, encoding_sa); + if (!IS_ERR(sa)) { + memcpy(next_sa, sa, sizeof(*sa)); + } else { + next_sa->is_key_a = true; + next_sa->an = encoding_sa; + } +} + +static int nxp_c45_mdo_upd_secy(struct macsec_context *ctx) +{ + u8 encoding_sa = ctx->secy->tx_sc.encoding_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + struct nxp_c45_sa next_sa; + bool can_rx_sc0_impl; + + phydev_dbg(phydev, "update SecY SCI %016llx\n", + sci_to_cpu(ctx->secy->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + if (!nxp_c45_mac_addr_free(ctx)) + return -EBUSY; + + /* If the point to point mode should be enabled, we should have only + * one SecY enabled, respectively the new one. + */ + can_rx_sc0_impl = list_count_nodes(&priv->macsec->secy_list) == 1; + if (!nxp_c45_secy_valid(phy_secy, can_rx_sc0_impl)) + return -EINVAL; + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_tx_sc_set_flt(phydev, phy_secy); + nxp_c45_tx_sc_update(phydev, phy_secy); + + nxp_c45_tx_sa_next(phy_secy, &next_sa, encoding_sa); + nxp_c45_tx_sa_update(phydev, &next_sa, ctx->secy->operational); + + nxp_c45_set_rx_sc0_impl(phydev, phy_secy->rx_sc0_impl); + if (phy_secy->rx_sc) + nxp_c45_rx_sc_update(phydev, phy_secy); + + return 0; +} + +static int nxp_c45_mdo_del_secy(struct macsec_context *ctx) +{ + u8 encoding_sa = ctx->secy->tx_sc.encoding_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + struct nxp_c45_sa next_sa; + + phydev_dbg(phydev, "delete SecY SCI %016llx\n", + sci_to_cpu(ctx->secy->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_mdo_dev_stop(ctx); + nxp_c45_tx_sa_next(phy_secy, &next_sa, encoding_sa); + nxp_c45_tx_sa_update(phydev, &next_sa, false); + if (phy_secy->rx_sc) + nxp_c45_rx_sc_del(phydev, phy_secy); + + nxp_c45_sa_list_free(&phy_secy->sa_list); + if (phy_interrupt_is_valid(phydev)) + nxp_c45_secy_irq_en(phydev, phy_secy, false); + + clear_bit(phy_secy->secy_id, priv->macsec->tx_sc_bitmap); + nxp_c45_secy_free(phy_secy); + + return 0; +} + +static int nxp_c45_mdo_add_rxsc(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + + phydev_dbg(phydev, "add RX SC SCI %016llx %s\n", + sci_to_cpu(ctx->rx_sc->sci), + ctx->rx_sc->active ? "enabled" : "disabled"); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + if (phy_secy->rx_sc) + return -ENOSPC; + + if (phy_secy->secy->tx_sc.end_station && + !nxp_c45_sci_valid(ctx->rx_sc->sci, ctx->secy->tx_sc.scb)) + return -EINVAL; + + phy_secy->rx_sc = ctx->rx_sc; + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_set_sci(phydev, MACSEC_RXSC_SCI_1H, ctx->rx_sc->sci); + nxp_c45_rx_sc_update(phydev, phy_secy); + + return 0; +} + +static int nxp_c45_mdo_upd_rxsc(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + + phydev_dbg(phydev, "update RX SC SCI %016llx %s\n", + sci_to_cpu(ctx->rx_sc->sci), + ctx->rx_sc->active ? "enabled" : "disabled"); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_rx_sc_update(phydev, phy_secy); + + return 0; +} + +static int nxp_c45_mdo_del_rxsc(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + + phydev_dbg(phydev, "delete RX SC SCI %016llx %s\n", + sci_to_cpu(ctx->rx_sc->sci), + ctx->rx_sc->active ? "enabled" : "disabled"); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_rx_sc_del(phydev, phy_secy); + phy_secy->rx_sc = NULL; + + return 0; +} + +static int nxp_c45_mdo_add_rxsa(struct macsec_context *ctx) +{ + struct macsec_rx_sa *rx_sa = ctx->sa.rx_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "add RX SA %u %s to RX SC SCI %016llx\n", + an, rx_sa->active ? "enabled" : "disabled", + sci_to_cpu(rx_sa->sc->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_sa_alloc(&phy_secy->sa_list, rx_sa, RX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_sa_set_pn(phydev, sa, rx_sa->next_pn, + ctx->secy->replay_window); + nxp_c45_sa_set_key(ctx, sa->regs, rx_sa->key.salt.bytes, rx_sa->ssci); + nxp_c45_rx_sa_update(phydev, sa, rx_sa->active); + + return 0; +} + +static int nxp_c45_mdo_upd_rxsa(struct macsec_context *ctx) +{ + struct macsec_rx_sa *rx_sa = ctx->sa.rx_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "update RX SA %u %s to RX SC SCI %016llx\n", + an, rx_sa->active ? "enabled" : "disabled", + sci_to_cpu(rx_sa->sc->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, RX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + if (ctx->sa.update_pn) + nxp_c45_sa_set_pn(phydev, sa, rx_sa->next_pn, + ctx->secy->replay_window); + nxp_c45_rx_sa_update(phydev, sa, rx_sa->active); + + return 0; +} + +static int nxp_c45_mdo_del_rxsa(struct macsec_context *ctx) +{ + struct macsec_rx_sa *rx_sa = ctx->sa.rx_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "delete RX SA %u %s to RX SC SCI %016llx\n", + an, rx_sa->active ? "enabled" : "disabled", + sci_to_cpu(rx_sa->sc->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, RX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_rx_sa_update(phydev, sa, false); + + nxp_c45_sa_free(sa); + + return 0; +} + +static int nxp_c45_mdo_add_txsa(struct macsec_context *ctx) +{ + struct macsec_tx_sa *tx_sa = ctx->sa.tx_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "add TX SA %u %s to TX SC %016llx\n", + an, ctx->sa.tx_sa->active ? "enabled" : "disabled", + sci_to_cpu(ctx->secy->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_sa_alloc(&phy_secy->sa_list, tx_sa, TX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_sa_set_pn(phydev, sa, tx_sa->next_pn, 0); + nxp_c45_sa_set_key(ctx, sa->regs, tx_sa->key.salt.bytes, tx_sa->ssci); + if (ctx->secy->tx_sc.encoding_sa == sa->an) + nxp_c45_tx_sa_update(phydev, sa, tx_sa->active); + + return 0; +} + +static int nxp_c45_mdo_upd_txsa(struct macsec_context *ctx) +{ + struct macsec_tx_sa *tx_sa = ctx->sa.tx_sa; + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "update TX SA %u %s to TX SC %016llx\n", + an, ctx->sa.tx_sa->active ? "enabled" : "disabled", + sci_to_cpu(ctx->secy->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, TX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + if (ctx->sa.update_pn) + nxp_c45_sa_set_pn(phydev, sa, tx_sa->next_pn, 0); + if (ctx->secy->tx_sc.encoding_sa == sa->an) + nxp_c45_tx_sa_update(phydev, sa, tx_sa->active); + + return 0; +} + +static int nxp_c45_mdo_del_txsa(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phydev_dbg(phydev, "delete TX SA %u %s to TX SC %016llx\n", + an, ctx->sa.tx_sa->active ? "enabled" : "disabled", + sci_to_cpu(ctx->secy->sci)); + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, TX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + nxp_c45_select_secy(phydev, phy_secy->secy_id); + if (ctx->secy->tx_sc.encoding_sa == sa->an) + nxp_c45_tx_sa_update(phydev, sa, false); + + nxp_c45_sa_free(sa); + + return 0; +} + +static const struct macsec_ops nxp_c45_macsec_ops = { + .mdo_dev_open = nxp_c45_mdo_dev_open, + .mdo_dev_stop = nxp_c45_mdo_dev_stop, + .mdo_add_secy = nxp_c45_mdo_add_secy, + .mdo_upd_secy = nxp_c45_mdo_upd_secy, + .mdo_del_secy = nxp_c45_mdo_del_secy, + .mdo_add_rxsc = nxp_c45_mdo_add_rxsc, + .mdo_upd_rxsc = nxp_c45_mdo_upd_rxsc, + .mdo_del_rxsc = nxp_c45_mdo_del_rxsc, + .mdo_add_rxsa = nxp_c45_mdo_add_rxsa, + .mdo_upd_rxsa = nxp_c45_mdo_upd_rxsa, + .mdo_del_rxsa = nxp_c45_mdo_del_rxsa, + .mdo_add_txsa = nxp_c45_mdo_add_txsa, + .mdo_upd_txsa = nxp_c45_mdo_upd_txsa, + .mdo_del_txsa = nxp_c45_mdo_del_txsa, +}; + +int nxp_c45_macsec_config_init(struct phy_device *phydev) +{ + struct nxp_c45_phy *priv = phydev->priv; + int ret; + + if (!priv->macsec) + return 0; + + ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, VEND1_PORT_FUNC_ENABLES, + MACSEC_EN | ADAPTER_EN); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, ADPTR_CNTRL, ADPTR_CNTRL_CONFIG_EN | + ADPTR_CNTRL_ADPTR_EN); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, ADPTR_CNTRL, ADPTR_CNTRL_ADPTR_EN); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, MACSEC_TPNET, PN_WRAP_THRESHOLD); + if (ret) + return ret; + + /* Set MKA filter. */ + ret = nxp_c45_macsec_write(phydev, MACSEC_UPFR0D2, ETH_P_PAE); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, MACSEC_UPFR0M1, MACSEC_OVP); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, MACSEC_UPFR0M2, ETYPE_MASK); + if (ret) + return ret; + + ret = nxp_c45_macsec_write(phydev, MACSEC_UPFR0R, MACSEC_UPFR_EN); + + return ret; +} + +int nxp_c45_macsec_probe(struct phy_device *phydev) +{ + struct nxp_c45_phy *priv = phydev->priv; + struct device *dev = &phydev->mdio.dev; + + priv->macsec = devm_kzalloc(dev, sizeof(*priv->macsec), GFP_KERNEL); + if (!priv->macsec) + return -ENOMEM; + + INIT_LIST_HEAD(&priv->macsec->secy_list); + phydev->macsec_ops = &nxp_c45_macsec_ops; + + return 0; +} + +void nxp_c45_macsec_remove(struct phy_device *phydev) +{ + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *secy_p, *secy_t; + struct nxp_c45_sa *sa_p, *sa_t; + struct list_head *secy_list; + + if (!priv->macsec) + return; + + secy_list = &priv->macsec->secy_list; + nxp_c45_macsec_en(phydev, false); + + list_for_each_entry_safe(secy_p, secy_t, secy_list, list) { + list_for_each_entry_safe(sa_p, sa_t, &secy_p->sa_list, list) + nxp_c45_sa_free(sa_p); + nxp_c45_secy_free(secy_p); + } +} + +void nxp_c45_handle_macsec_interrupt(struct phy_device *phydev, + irqreturn_t *ret) +{ + struct nxp_c45_phy *priv = phydev->priv; + struct nxp_c45_secy *pos, *tmp; + struct nxp_c45_sa *sa; + u8 encoding_sa; + int secy_id; + u32 reg = 0; + + if (!priv->macsec) + return; + + do { + nxp_c45_macsec_read(phydev, MACSEC_EVR, ®); + if (!reg) + return; + + secy_id = MACSEC_REG_SIZE - ffs(reg); + list_for_each_entry_safe(pos, tmp, &priv->macsec->secy_list, + list) + if (pos->secy_id == secy_id) + break; + + encoding_sa = pos->secy->tx_sc.encoding_sa; + phydev_dbg(phydev, "pn_wrapped: TX SC %d, encoding_sa %u\n", + pos->secy_id, encoding_sa); + + sa = nxp_c45_find_sa(&pos->sa_list, TX_SA, encoding_sa); + if (!IS_ERR(sa)) + macsec_pn_wrapped(pos->secy, sa->sa); + else + WARN_ON(1); + + nxp_c45_macsec_write(phydev, MACSEC_EVR, + TX_SC_BIT(pos->secy_id)); + *ret = IRQ_HANDLED; + } while (reg); +} diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 7ab080ff02df..72d1499e52e4 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* NXP C45 PHY driver - * Copyright (C) 2021 NXP + * Copyright 2021-2023 NXP * Author: Radu Pirea */ @@ -14,9 +14,10 @@ #include #include #include -#include #include +#include "nxp-c45-tja11xx.h" + #define PHY_ID_TJA_1103 0x001BB010 #define PHY_ID_TJA_1120 0x001BB031 @@ -75,9 +76,11 @@ #define PORT_CONTROL_EN BIT(14) #define VEND1_PORT_ABILITIES 0x8046 +#define MACSEC_ABILITY BIT(5) #define PTP_ABILITY BIT(3) #define VEND1_PORT_FUNC_IRQ_EN 0x807A +#define MACSEC_IRQS BIT(5) #define PTP_IRQS BIT(3) #define VEND1_PTP_IRQ_ACK 0x9008 @@ -148,7 +151,6 @@ #define TS_SEC_MASK GENMASK(1, 0) -#define VEND1_PORT_FUNC_ENABLES 0x8048 #define PTP_ENABLE BIT(3) #define PHY_TEST_ENABLE BIT(0) @@ -281,25 +283,6 @@ struct nxp_c45_phy_data { irqreturn_t *irq_status); }; -struct nxp_c45_phy { - const struct nxp_c45_phy_data *phy_data; - struct phy_device *phydev; - struct mii_timestamper mii_ts; - struct ptp_clock *ptp_clock; - struct ptp_clock_info caps; - struct sk_buff_head tx_queue; - struct sk_buff_head rx_queue; - /* used to access the PTP registers atomic */ - struct mutex ptp_lock; - int hwts_tx; - int hwts_rx; - u32 tx_delay; - u32 rx_delay; - struct timespec64 extts_ts; - int extts_index; - bool extts; -}; - static const struct nxp_c45_phy_data *nxp_c45_get_data(struct phy_device *phydev) { @@ -1218,12 +1201,25 @@ static int nxp_c45_start_op(struct phy_device *phydev) static int nxp_c45_config_intr(struct phy_device *phydev) { - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) + int ret; + + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { + ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, + VEND1_PORT_FUNC_IRQ_EN, MACSEC_IRQS); + if (ret) + return ret; + return phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT); - else - return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, - VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT); + } + + ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, + VEND1_PORT_FUNC_IRQ_EN, MACSEC_IRQS); + if (ret) + return ret; + + return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, + VEND1_PHY_IRQ_EN, PHY_IRQ_LINK_EVENT); } static int tja1103_config_intr(struct phy_device *phydev) @@ -1289,6 +1285,7 @@ static irqreturn_t nxp_c45_handle_interrupt(struct phy_device *phydev) } data->nmi_handler(phydev, &ret); + nxp_c45_handle_macsec_interrupt(phydev, &ret); return ret; } @@ -1614,6 +1611,9 @@ static int nxp_c45_config_init(struct phy_device *phydev) nxp_c45_counters_enable(phydev); nxp_c45_ptp_init(phydev); + ret = nxp_c45_macsec_config_init(phydev); + if (ret) + return ret; return nxp_c45_start_op(phydev); } @@ -1629,7 +1629,9 @@ static int nxp_c45_get_features(struct phy_device *phydev) static int nxp_c45_probe(struct phy_device *phydev) { struct nxp_c45_phy *priv; - int ptp_ability; + bool macsec_ability; + int phy_abilities; + bool ptp_ability; int ret = 0; priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); @@ -1645,9 +1647,9 @@ static int nxp_c45_probe(struct phy_device *phydev) mutex_init(&priv->ptp_lock); - ptp_ability = phy_read_mmd(phydev, MDIO_MMD_VEND1, - VEND1_PORT_ABILITIES); - ptp_ability = !!(ptp_ability & PTP_ABILITY); + phy_abilities = phy_read_mmd(phydev, MDIO_MMD_VEND1, + VEND1_PORT_ABILITIES); + ptp_ability = !!(phy_abilities & PTP_ABILITY); if (!ptp_ability) { phydev_dbg(phydev, "the phy does not support PTP"); goto no_ptp_support; @@ -1666,6 +1668,20 @@ static int nxp_c45_probe(struct phy_device *phydev) } no_ptp_support: + macsec_ability = !!(phy_abilities & MACSEC_ABILITY); + if (!macsec_ability) { + phydev_info(phydev, "the phy does not support MACsec\n"); + goto no_macsec_support; + } + + if (IS_ENABLED(CONFIG_MACSEC)) { + ret = nxp_c45_macsec_probe(phydev); + phydev_dbg(phydev, "MACsec support enabled."); + } else { + phydev_dbg(phydev, "MACsec support not enabled even if the phy supports it"); + } + +no_macsec_support: return ret; } @@ -1679,6 +1695,7 @@ static void nxp_c45_remove(struct phy_device *phydev) skb_queue_purge(&priv->tx_queue); skb_queue_purge(&priv->rx_queue); + nxp_c45_macsec_remove(phydev); } static void tja1103_counters_enable(struct phy_device *phydev) diff --git a/drivers/net/phy/nxp-c45-tja11xx.h b/drivers/net/phy/nxp-c45-tja11xx.h new file mode 100644 index 000000000000..f364fca68f0b --- /dev/null +++ b/drivers/net/phy/nxp-c45-tja11xx.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* NXP C45 PHY driver header file + * Copyright 2023 NXP + * Author: Radu Pirea + */ + +#include + +#define VEND1_PORT_FUNC_ENABLES 0x8048 + +struct nxp_c45_macsec; + +struct nxp_c45_phy { + const struct nxp_c45_phy_data *phy_data; + struct phy_device *phydev; + struct mii_timestamper mii_ts; + struct ptp_clock *ptp_clock; + struct ptp_clock_info caps; + struct sk_buff_head tx_queue; + struct sk_buff_head rx_queue; + /* used to access the PTP registers atomic */ + struct mutex ptp_lock; + int hwts_tx; + int hwts_rx; + u32 tx_delay; + u32 rx_delay; + struct timespec64 extts_ts; + int extts_index; + bool extts; + struct nxp_c45_macsec *macsec; +}; + +#if IS_ENABLED(CONFIG_MACSEC) +int nxp_c45_macsec_config_init(struct phy_device *phydev); +int nxp_c45_macsec_probe(struct phy_device *phydev); +void nxp_c45_macsec_remove(struct phy_device *phydev); +void nxp_c45_handle_macsec_interrupt(struct phy_device *phydev, + irqreturn_t *ret); +#else +static inline +int nxp_c45_macsec_config_init(struct phy_device *phydev) +{ + return 0; +} + +static inline +int nxp_c45_macsec_probe(struct phy_device *phydev) +{ + return 0; +} + +static inline +void nxp_c45_macsec_remove(struct phy_device *phydev) +{ +} + +static inline +void nxp_c45_handle_macsec_interrupt(struct phy_device *phydev, + irqreturn_t *ret) +{ +} +#endif From patchwork Thu Oct 19 12:02:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428731 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 048B41DFE4 for ; Thu, 19 Oct 2023 12:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="Ji/sneTp" Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2089.outbound.protection.outlook.com [40.107.6.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A1C71B8; Thu, 19 Oct 2023 05:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mtDUKVNOblY66JeIlgylMUKomfmmK4NFrwQtoGsznJ1415S1caKTymHLdkSRv9Z7lGeQuTs0hIF9mjtK3vFAMiXlikUsduG3BqBB+HzzY1wWRn8DmtECQSH6CL2LdHSkOtnXYQY06mWNSstRM56x3BCkzm2QrxM089ZP11WdjJjes8y1HVxk7Jy24tuC+Wc7u2VEgARQjMdPJBPv683co1qYBGZM+82F1G1tnaZmTNG2pUOEOpU9O9M09L9b9s20PCJgP4ufgX+hAw8BIJ9xTrU+h54pmelwWm8gjw770V4JU0RA0WsRSzOXiMh+KeIswTHKiogKJl8iipDJJGXgEQ== 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=keNHFqYO2lAwgTo0OIDsPObxKQcCS6dG9oAzEZp/wO4=; b=CSu6wBnvu81A7OsisuIppgEvTWGmhW6vP1PyaJE8HV79Ikbj5qIhJn9OATl3saZQ8AiZLf+h20fWe1yNjjmZSqmmeKA3jTESM4H+L8ZoHRslUz84xyM8EjNYVEg9WSXpmHNzg5dqInoYL0BLQhhrbtqUFB02DUJ8z/SWyJ3Fl4UJt+1kIiUVt4tJ3RX1ziNM/2Db3n0+UQdFrnFH0RZI1NFgZ3e9939+7iUzdkmZ+ubsedczBo3z27z4K/HEI/X9qrVdwXXDdZHt2501X3Gu5DiZPATZDoYvkQOx7c5h6JEG6PJmIwFJ3LqdPgAQ4ErUQvZM+sCYieOR/ERUhkD00Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=keNHFqYO2lAwgTo0OIDsPObxKQcCS6dG9oAzEZp/wO4=; b=Ji/sneTprlXouZt0rHHXGiNwRge8H+Efl3U081QjCHx9UgeZJOb1urYrTOsewr+C3oKIvoUM6b/gHcmEXBjlKebIrldG6pRv8cNMdwtSElfPssEomvloA20hvxidfmzkLwDEAIV4uRl2bsF+tVsQbJv0KngTL2DIf+i6jLKQYMM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by PR3PR04MB7436.eurprd04.prod.outlook.com (2603:10a6:102:87::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.8; Thu, 19 Oct 2023 12:02:59 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:02:59 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 6/7] net: phy: nxp-c45-tja11xx: add MACsec statistics Date: Thu, 19 Oct 2023 15:02:08 +0300 Message-Id: <20231019120209.290480-7-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|PR3PR04MB7436:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ec9de73-e0c8-4aeb-2f26-08dbd09b5645 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NFoSbenk6dmXoJdPIvUEHsuz2UFMoiSO43vIBNe/13HCeoqIqbnOFAYqsX6dId/hV1q8pHuUgEF6UY/ls4nsjzda41VX1aNZVRIAiF4X4pEIGewy0b0arRiYBThevjezZ7HO2QqbKVRv0naG8LQtlK5VV4tGO5ySbJBncQ/4TdP1//3RtgpaxIwLb+N0FfSApUy8tJHYcrK8QSyKVj/E4HBpsLJA0wNHlHFOs3TEUNch+6Hr+fOGNLd2eUqHKvQnX9MDuF82phVyM7/l7Gc9icNa6ecNVjajOffwMOosFoUckZgLqfa48BKXYSzoj5jmiV+s3ffJyAFBqLijLAxozecG1FrCxzSk7dSahMVZOfZPiDe7+fNL8DD/gYGOpDRKuvnSXlLp1DdfNKtl5Tb5nMUzBibJW4apuXhngANGrEGy2SvDFxF22EC5bnxbPpn2K+vkwyY6HFBPw4o3GgY0wNpZEUTk70A3gHVbR3DlYHARRcy5ji7EPjXB4dsCsLTswEVGAh2BJmIjTh0w+2edU8uZlmuMY/8CNXgvHhv3bOIMD0EQG87N6TFmnXvX6fV4nf/9LEUGv411hQgn/V1dEjv4RLZATJ3bPHpAFsqUCMk61e/1VMn+pc0DF66vJRdu X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799009)(64100799003)(2906002)(5660300002)(4326008)(30864003)(66476007)(66946007)(8936002)(66556008)(316002)(6666004)(478600001)(6486002)(8676002)(41300700001)(7416002)(86362001)(38100700002)(52116002)(2616005)(6506007)(83380400001)(1076003)(26005)(6512007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IHE9iKE4jiVb8C/NFqhLFKZyzKPFiWLYELV9V4VytebmHsnwIlYgDWrKl44SXx0A0QRdXjBYVgxFR4zPSLAsClAOiteWXIVlftgY78IzJO6PE3Ykc7uTw+k9inqqFqKbULa7UqVy2ROV1I9Goll+HWC026cU53oDf7JDtO15hAh10a/lkVRTt3vKPLo0RkcYmncr+jlLJnOh7qFACCzeil+bGS6ud+0b2gUD34f3QpGl2T2CDpA9MTfGO9siZ/XOQe5baZ60MA8Z3iDAtHB+j7Hgo1afV5GQzVaHrWANhglE50EbVAQl3cH89I2O69tiKyYtalriE795fjGgGtnOV4CDnbch8cw5SaNLGEBZq2+ZppzVkCkgY8hEfkeGZA8xJmRA+7uFUjTUrQkPZU4M7yjQYrTDAExbnEUVgZg1ZIoP/8diaJF0Wf3BDjZCZs86mss3utwnw0i5qTvpoRpuouoSAhXBiCVzsWaHmQ4qUFevUvKMtnGpoIRiia1cQvMdo14Ln2KJVL6eR0rebrI5uQbSJn5DrR3RigeJ8YxHt9PV9yym+JqLCnYUPUrFO6wVKr3HzMzwfgb9I7e1N78vLM73+x2tdar47XODxBBxZwL7cjXrD+WUZ5/1wZQswyW7PUOxEY708BpJcYfGdPjnyglz7PUjLIF4IS8DXVQF5b6R13pnkp0NCTIX4IIHXSkJILHmzbftZ13i4cXHGkc+nef7TYikmFViAAdipy5D0oirCZCm2rRRJk9Q+cgiUnH85EZjGdwVTLGj7Fv8mytPkgwGMc7sMeiZe+ASkQQGIrDsT0oRfW0eHzZ4RLsnYM74f6N8E9vs2Q1w5TWMuhvGiDbOeaWzIhIFiJ6mTNUYJIzML0sTjiMzA9fA5+HVL0FSiotHpD+jbybjBjfULryua+AjD93lUuox3UQzbPpGPqNBx75C+/b/IcqbjY/TLExVcRHHaJBdOPsTTXOEPGCGoJ4KmXf2xjUkNSzjbS93C2epo9P8p3iDV4G3FKsfLEnRlqU4zYZBAsT1yQUhkJ3o2C/lFuTDZTr7oSvnYH3U4Hf0G2mHsH9+wGDBVrCb4qZffTJqXTJ3XXVK/f0IEu3TSmhLaYXQxDvXHk2xSCkLvWhHqUDNngDboBrGZx5TP+QtOWA0+BCdo/d+NDp6asU8/Qjogh+iN8X9iSCh3MvtW109E2AOWObr5MnuxEDn8JEPiYh4qy2ZnFGAg/D8X0Au/Q9F5QHdtXejlZ0aSRYHGapCD1AQcA4SKQ7bluY7n8omKs5gwmdWiKdz45IGXGT6pYMSv2521FCSDk8NmYL8zaqCyR3zYBDYirbRMD4xzImDFYIzImRqkbIKNiSzUwlYVlrTib7Veu092kCcKtKRAlAvB81v0qO5NZqPSmb22HpEyIaBZG7H1huMyw4HBro2M2QZf2L5ENlXE/2GbOsGLhDxcAJlZXyMh6UUodXpss72AbeTs9MMs4Yjm49ZspdFG+Iuwy9f8FAFSFBaphNGb9DWg/i4PucZbpDQ6T0S8PnIdFCp7pLd4JQg7iJqt1tAk7Iw1sa9fnVMuWeF22f4MGmzQT1fbcOQ4A570Lxul503HSkvf24KQrmCMOrsYWJhZQ== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ec9de73-e0c8-4aeb-2f26-08dbd09b5645 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:02:59.0263 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qsNcwPB3cnqPDxrfyJmQS3Yt6V7QcqEsCPZ33+u9YHTAuksrWYpf7PVaFoLmXIp1ZW2qIclhMNVJQyfV5a1Q2psIYF5er6S6954zp5qo/WI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7436 X-Patchwork-Delegate: kuba@kernel.org Add MACsec statistics callbacks. The statistic registers must be set to 0 if the SC/SA is deleted to read relevant values next time when the SC/SA is used. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v5-v7: - none Changes in v4: - Added nxp_c45_macsec_read32_64 function to read 32b counters into u64 variables. - Added nxp_c45_macsec_read64 function to read 64b counters. Changes in v3: - reworked the implementation around struct nxp_c45_sa - changed the way how OutOctetsEncrypted are propagated to the userspace - changed the way how OutOctetsProtected are propagated to the userspace - read and clear OutOctetsProtected Changes in v2: - split the patch from "net: phy: nxp-c45-tja11xx: add MACsec support" drivers/net/phy/nxp-c45-tja11xx-macsec.c | 345 +++++++++++++++++++++++ 1 file changed, 345 insertions(+) diff --git a/drivers/net/phy/nxp-c45-tja11xx-macsec.c b/drivers/net/phy/nxp-c45-tja11xx-macsec.c index 821f8926f7f2..4dd10ea6e06c 100644 --- a/drivers/net/phy/nxp-c45-tja11xx-macsec.c +++ b/drivers/net/phy/nxp-c45-tja11xx-macsec.c @@ -137,6 +137,35 @@ #define ADAPTER_EN BIT(6) #define MACSEC_EN BIT(5) +#define MACSEC_INOV1HS 0x0140 +#define MACSEC_INOV2HS 0x0144 +#define MACSEC_INOD1HS 0x0148 +#define MACSEC_INOD2HS 0x014C +#define MACSEC_RXSCIPUS 0x0150 +#define MACSEC_RXSCIPDS 0x0154 +#define MACSEC_RXSCIPLS 0x0158 +#define MACSEC_RXAN0INUSS 0x0160 +#define MACSEC_RXAN0IPUSS 0x0170 +#define MACSEC_RXSA_A_IPOS 0x0194 +#define MACSEC_RXSA_A_IPIS 0x01B0 +#define MACSEC_RXSA_A_IPNVS 0x01B4 +#define MACSEC_RXSA_B_IPOS 0x01D4 +#define MACSEC_RXSA_B_IPIS 0x01F0 +#define MACSEC_RXSA_B_IPNVS 0x01F4 +#define MACSEC_OPUS 0x021C +#define MACSEC_OPTLS 0x022C +#define MACSEC_OOP1HS 0x0240 +#define MACSEC_OOP2HS 0x0244 +#define MACSEC_OOE1HS 0x0248 +#define MACSEC_OOE2HS 0x024C +#define MACSEC_TXSA_A_OPPS 0x028C +#define MACSEC_TXSA_A_OPES 0x0290 +#define MACSEC_TXSA_B_OPPS 0x02CC +#define MACSEC_TXSA_B_OPES 0x02D0 +#define MACSEC_INPWTS 0x0630 +#define MACSEC_INPBTS 0x0638 +#define MACSEC_IPSNFS 0x063C + enum nxp_c45_sa_type { TX_SA, RX_SA, @@ -175,6 +204,11 @@ struct nxp_c45_sa_regs { u16 ka; u16 ssci; u16 salt; + u16 ipis; + u16 ipnvs; + u16 ipos; + u16 opps; + u16 opes; }; static const struct nxp_c45_sa_regs rx_sa_a_regs = { @@ -186,6 +220,9 @@ static const struct nxp_c45_sa_regs rx_sa_a_regs = { .ka = MACSEC_RXSA_A_KA, .ssci = MACSEC_RXSA_A_SSCI, .salt = MACSEC_RXSA_A_SALT, + .ipis = MACSEC_RXSA_A_IPIS, + .ipnvs = MACSEC_RXSA_A_IPNVS, + .ipos = MACSEC_RXSA_A_IPOS, }; static const struct nxp_c45_sa_regs rx_sa_b_regs = { @@ -197,6 +234,9 @@ static const struct nxp_c45_sa_regs rx_sa_b_regs = { .ka = MACSEC_RXSA_B_KA, .ssci = MACSEC_RXSA_B_SSCI, .salt = MACSEC_RXSA_B_SALT, + .ipis = MACSEC_RXSA_B_IPIS, + .ipnvs = MACSEC_RXSA_B_IPNVS, + .ipos = MACSEC_RXSA_B_IPOS, }; static const struct nxp_c45_sa_regs tx_sa_a_regs = { @@ -206,6 +246,8 @@ static const struct nxp_c45_sa_regs tx_sa_a_regs = { .ka = MACSEC_TXSA_A_KA, .ssci = MACSEC_TXSA_A_SSCI, .salt = MACSEC_TXSA_A_SALT, + .opps = MACSEC_TXSA_A_OPPS, + .opes = MACSEC_TXSA_A_OPES, }; static const struct nxp_c45_sa_regs tx_sa_b_regs = { @@ -215,6 +257,8 @@ static const struct nxp_c45_sa_regs tx_sa_b_regs = { .ka = MACSEC_TXSA_B_KA, .ssci = MACSEC_TXSA_B_SSCI, .salt = MACSEC_TXSA_B_SALT, + .opps = MACSEC_TXSA_B_OPPS, + .opes = MACSEC_TXSA_B_OPES, }; static const @@ -284,6 +328,26 @@ static int nxp_c45_macsec_read(struct phy_device *phydev, u16 addr, u32 *value) return 0; } +static void nxp_c45_macsec_read32_64(struct phy_device *phydev, u16 addr, + u64 *value) +{ + u32 lvalue; + + nxp_c45_macsec_read(phydev, addr, &lvalue); + *value = lvalue; +} + +static void nxp_c45_macsec_read64(struct phy_device *phydev, u16 addr, + u64 *value) +{ + u32 lvalue; + + nxp_c45_macsec_read(phydev, addr, &lvalue); + *value = (u64)lvalue << 32; + nxp_c45_macsec_read(phydev, addr + 4, &lvalue); + *value |= lvalue; +} + static void nxp_c45_secy_irq_en(struct phy_device *phydev, struct nxp_c45_secy *phy_secy, bool en) { @@ -432,6 +496,41 @@ static void nxp_c45_sa_set_key(struct macsec_context *ctx, nxp_c45_macsec_write(phydev, sa_regs->cs, MACSEC_SA_CS_A); } +static void nxp_c45_rx_sa_clear_stats(struct phy_device *phydev, + struct nxp_c45_sa *sa) +{ + nxp_c45_macsec_write(phydev, sa->regs->ipis, 0); + nxp_c45_macsec_write(phydev, sa->regs->ipnvs, 0); + nxp_c45_macsec_write(phydev, sa->regs->ipos, 0); + + nxp_c45_macsec_write(phydev, MACSEC_RXAN0INUSS + sa->an * 4, 0); + nxp_c45_macsec_write(phydev, MACSEC_RXAN0IPUSS + sa->an * 4, 0); +} + +static void nxp_c45_rx_sa_read_stats(struct phy_device *phydev, + struct nxp_c45_sa *sa, + struct macsec_rx_sa_stats *stats) +{ + nxp_c45_macsec_read(phydev, sa->regs->ipis, &stats->InPktsInvalid); + nxp_c45_macsec_read(phydev, sa->regs->ipnvs, &stats->InPktsNotValid); + nxp_c45_macsec_read(phydev, sa->regs->ipos, &stats->InPktsOK); +} + +static void nxp_c45_tx_sa_clear_stats(struct phy_device *phydev, + struct nxp_c45_sa *sa) +{ + nxp_c45_macsec_write(phydev, sa->regs->opps, 0); + nxp_c45_macsec_write(phydev, sa->regs->opes, 0); +} + +static void nxp_c45_tx_sa_read_stats(struct phy_device *phydev, + struct nxp_c45_sa *sa, + struct macsec_tx_sa_stats *stats) +{ + nxp_c45_macsec_read(phydev, sa->regs->opps, &stats->OutPktsProtected); + nxp_c45_macsec_read(phydev, sa->regs->opes, &stats->OutPktsEncrypted); +} + static void nxp_c45_rx_sa_update(struct phy_device *phydev, struct nxp_c45_sa *sa, bool en) { @@ -646,6 +745,23 @@ static void nxp_c45_tx_sc_update(struct phy_device *phydev, nxp_c45_macsec_write(phydev, MACSEC_TXSC_CFG, cfg); } +static void nxp_c45_tx_sc_clear_stats(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + struct nxp_c45_sa *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) + if (pos->type == TX_SA) + nxp_c45_tx_sa_clear_stats(phydev, pos); + + nxp_c45_macsec_write(phydev, MACSEC_OPUS, 0); + nxp_c45_macsec_write(phydev, MACSEC_OPTLS, 0); + nxp_c45_macsec_write(phydev, MACSEC_OOP1HS, 0); + nxp_c45_macsec_write(phydev, MACSEC_OOP2HS, 0); + nxp_c45_macsec_write(phydev, MACSEC_OOE1HS, 0); + nxp_c45_macsec_write(phydev, MACSEC_OOE2HS, 0); +} + static void nxp_c45_set_rx_sc0_impl(struct phy_device *phydev, bool enable) { @@ -735,6 +851,32 @@ static void nxp_c45_rx_sc_update(struct phy_device *phydev, nxp_c45_macsec_write(phydev, MACSEC_RXSC_CFG, cfg); } +static void nxp_c45_rx_sc_clear_stats(struct phy_device *phydev, + struct nxp_c45_secy *phy_secy) +{ + struct nxp_c45_sa *pos, *tmp; + int i; + + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) + if (pos->type == RX_SA) + nxp_c45_rx_sa_clear_stats(phydev, pos); + + nxp_c45_macsec_write(phydev, MACSEC_INOD1HS, 0); + nxp_c45_macsec_write(phydev, MACSEC_INOD2HS, 0); + + nxp_c45_macsec_write(phydev, MACSEC_INOV1HS, 0); + nxp_c45_macsec_write(phydev, MACSEC_INOV2HS, 0); + + nxp_c45_macsec_write(phydev, MACSEC_RXSCIPDS, 0); + nxp_c45_macsec_write(phydev, MACSEC_RXSCIPLS, 0); + nxp_c45_macsec_write(phydev, MACSEC_RXSCIPUS, 0); + + for (i = 0; i < MACSEC_NUM_AN; i++) { + nxp_c45_macsec_write(phydev, MACSEC_RXAN0INUSS + i * 4, 0); + nxp_c45_macsec_write(phydev, MACSEC_RXAN0IPUSS + i * 4, 0); + } +} + static void nxp_c45_rx_sc_del(struct phy_device *phydev, struct nxp_c45_secy *phy_secy) { @@ -744,11 +886,20 @@ static void nxp_c45_rx_sc_del(struct phy_device *phydev, nxp_c45_macsec_write(phydev, MACSEC_RPW, 0); nxp_c45_set_sci(phydev, MACSEC_RXSC_SCI_1H, 0); + nxp_c45_rx_sc_clear_stats(phydev, phy_secy); + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) if (pos->type == RX_SA) nxp_c45_rx_sa_update(phydev, pos, false); } +static void nxp_c45_clear_global_stats(struct phy_device *phydev) +{ + nxp_c45_macsec_write(phydev, MACSEC_INPBTS, 0); + nxp_c45_macsec_write(phydev, MACSEC_INPWTS, 0); + nxp_c45_macsec_write(phydev, MACSEC_IPSNFS, 0); +} + static void nxp_c45_macsec_en(struct phy_device *phydev, bool en) { u32 reg; @@ -939,6 +1090,7 @@ static int nxp_c45_mdo_del_secy(struct macsec_context *ctx) nxp_c45_mdo_dev_stop(ctx); nxp_c45_tx_sa_next(phy_secy, &next_sa, encoding_sa); nxp_c45_tx_sa_update(phydev, &next_sa, false); + nxp_c45_tx_sc_clear_stats(phydev, phy_secy); if (phy_secy->rx_sc) nxp_c45_rx_sc_del(phydev, phy_secy); @@ -949,6 +1101,9 @@ static int nxp_c45_mdo_del_secy(struct macsec_context *ctx) clear_bit(phy_secy->secy_id, priv->macsec->tx_sc_bitmap); nxp_c45_secy_free(phy_secy); + if (list_empty(&priv->macsec->secy_list)) + nxp_c45_clear_global_stats(phydev); + return 0; } @@ -1106,6 +1261,7 @@ static int nxp_c45_mdo_del_rxsa(struct macsec_context *ctx) nxp_c45_select_secy(phydev, phy_secy->secy_id); nxp_c45_rx_sa_update(phydev, sa, false); + nxp_c45_rx_sa_clear_stats(phydev, sa); nxp_c45_sa_free(sa); @@ -1195,12 +1351,196 @@ static int nxp_c45_mdo_del_txsa(struct macsec_context *ctx) nxp_c45_select_secy(phydev, phy_secy->secy_id); if (ctx->secy->tx_sc.encoding_sa == sa->an) nxp_c45_tx_sa_update(phydev, sa, false); + nxp_c45_tx_sa_clear_stats(phydev, sa); nxp_c45_sa_free(sa); return 0; } +static int nxp_c45_mdo_get_dev_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_dev_stats *dev_stats; + struct nxp_c45_secy *phy_secy; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + dev_stats = ctx->stats.dev_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_macsec_read32_64(phydev, MACSEC_OPUS, + &dev_stats->OutPktsUntagged); + nxp_c45_macsec_read32_64(phydev, MACSEC_OPTLS, + &dev_stats->OutPktsTooLong); + nxp_c45_macsec_read32_64(phydev, MACSEC_INPBTS, + &dev_stats->InPktsBadTag); + + if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT) + nxp_c45_macsec_read32_64(phydev, MACSEC_INPWTS, + &dev_stats->InPktsNoTag); + else + nxp_c45_macsec_read32_64(phydev, MACSEC_INPWTS, + &dev_stats->InPktsUntagged); + + if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT) + nxp_c45_macsec_read32_64(phydev, MACSEC_IPSNFS, + &dev_stats->InPktsNoSCI); + else + nxp_c45_macsec_read32_64(phydev, MACSEC_IPSNFS, + &dev_stats->InPktsUnknownSCI); + + /* Always 0. */ + dev_stats->InPktsOverrun = 0; + + return 0; +} + +static int nxp_c45_mdo_get_tx_sc_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_tx_sa_stats tx_sa_stats; + struct macsec_tx_sc_stats *stats; + struct nxp_c45_secy *phy_secy; + struct nxp_c45_sa *pos, *tmp; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + stats = ctx->stats.tx_sc_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_macsec_read64(phydev, MACSEC_OOE1HS, + &stats->OutOctetsEncrypted); + nxp_c45_macsec_read64(phydev, MACSEC_OOP1HS, + &stats->OutOctetsProtected); + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) { + if (pos->type != TX_SA) + continue; + + memset(&tx_sa_stats, 0, sizeof(tx_sa_stats)); + nxp_c45_tx_sa_read_stats(phydev, pos, &tx_sa_stats); + + stats->OutPktsEncrypted += tx_sa_stats.OutPktsEncrypted; + stats->OutPktsProtected += tx_sa_stats.OutPktsProtected; + } + + return 0; +} + +static int nxp_c45_mdo_get_tx_sa_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_tx_sa_stats *stats; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, TX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + stats = ctx->stats.tx_sa_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + nxp_c45_tx_sa_read_stats(phydev, sa, stats); + + return 0; +} + +static int nxp_c45_mdo_get_rx_sc_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_rx_sa_stats rx_sa_stats; + struct macsec_rx_sc_stats *stats; + struct nxp_c45_secy *phy_secy; + struct nxp_c45_sa *pos, *tmp; + u32 reg = 0; + int i; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + if (phy_secy->rx_sc != ctx->rx_sc) + return -EINVAL; + + stats = ctx->stats.rx_sc_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + list_for_each_entry_safe(pos, tmp, &phy_secy->sa_list, list) { + if (pos->type != RX_SA) + continue; + + memset(&rx_sa_stats, 0, sizeof(rx_sa_stats)); + nxp_c45_rx_sa_read_stats(phydev, pos, &rx_sa_stats); + + stats->InPktsInvalid += rx_sa_stats.InPktsInvalid; + stats->InPktsNotValid += rx_sa_stats.InPktsNotValid; + stats->InPktsOK += rx_sa_stats.InPktsOK; + } + + for (i = 0; i < MACSEC_NUM_AN; i++) { + nxp_c45_macsec_read(phydev, MACSEC_RXAN0INUSS + i * 4, ®); + stats->InPktsNotUsingSA += reg; + nxp_c45_macsec_read(phydev, MACSEC_RXAN0IPUSS + i * 4, ®); + stats->InPktsUnusedSA += reg; + } + + nxp_c45_macsec_read64(phydev, MACSEC_INOD1HS, + &stats->InOctetsDecrypted); + nxp_c45_macsec_read64(phydev, MACSEC_INOV1HS, + &stats->InOctetsValidated); + + nxp_c45_macsec_read32_64(phydev, MACSEC_RXSCIPDS, + &stats->InPktsDelayed); + nxp_c45_macsec_read32_64(phydev, MACSEC_RXSCIPLS, + &stats->InPktsLate); + nxp_c45_macsec_read32_64(phydev, MACSEC_RXSCIPUS, + &stats->InPktsUnchecked); + + return 0; +} + +static int nxp_c45_mdo_get_rx_sa_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_rx_sa_stats *stats; + struct nxp_c45_secy *phy_secy; + u8 an = ctx->sa.assoc_num; + struct nxp_c45_sa *sa; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + sa = nxp_c45_find_sa(&phy_secy->sa_list, RX_SA, an); + if (IS_ERR(sa)) + return PTR_ERR(sa); + + stats = ctx->stats.rx_sa_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_rx_sa_read_stats(phydev, sa, stats); + nxp_c45_macsec_read(phydev, MACSEC_RXAN0INUSS + an * 4, + &stats->InPktsNotUsingSA); + nxp_c45_macsec_read(phydev, MACSEC_RXAN0IPUSS + an * 4, + &stats->InPktsUnusedSA); + + return 0; +} + static const struct macsec_ops nxp_c45_macsec_ops = { .mdo_dev_open = nxp_c45_mdo_dev_open, .mdo_dev_stop = nxp_c45_mdo_dev_stop, @@ -1216,6 +1556,11 @@ static const struct macsec_ops nxp_c45_macsec_ops = { .mdo_add_txsa = nxp_c45_mdo_add_txsa, .mdo_upd_txsa = nxp_c45_mdo_upd_txsa, .mdo_del_txsa = nxp_c45_mdo_del_txsa, + .mdo_get_dev_stats = nxp_c45_mdo_get_dev_stats, + .mdo_get_tx_sc_stats = nxp_c45_mdo_get_tx_sc_stats, + .mdo_get_tx_sa_stats = nxp_c45_mdo_get_tx_sa_stats, + .mdo_get_rx_sc_stats = nxp_c45_mdo_get_rx_sc_stats, + .mdo_get_rx_sa_stats = nxp_c45_mdo_get_rx_sa_stats, }; int nxp_c45_macsec_config_init(struct phy_device *phydev) From patchwork Thu Oct 19 12:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Radu Pirea (NXP OSS)" X-Patchwork-Id: 13428733 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFC531DFE3 for ; Thu, 19 Oct 2023 12:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="hZr7CrpC" Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2089.outbound.protection.outlook.com [40.107.6.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD18D68; Thu, 19 Oct 2023 05:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NCvNh7ZjV9Ntjk39MI7C9kQgBfrFwZp+quWRe34BEK64RGJzJ2u24Skr0r6kLXzT9HXmS9nMzNHOOAz2V6gJS1qI77OecbLOdydSwURcbhcE8CheKzqox/C76Bxzb7yygWzmYTLM3mS4Tl09Sm2izvpyJk5L5bO4jQYYNKlV7SuXWdlWlDZ3w4YmuWVeYDVbQX1bRsAJ1K7+lUJ/zaJ7ZLMWYlRgvM7e2BDI1VKYYn3+N+mNaAaqrwUw++tiJtEok1j6EaVAacGnJ8Q4Tdsm7J+6AJ9SGOwA/rHM0L8ZGELcOemxqo1d9rd+rQa8NUeC9iw0yp5I98BkSW2dYsyjpg== 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=rlCaEwzLJwJQhM2FHF/4VqTXShcY7qSgVY2gyqriqQ8=; b=bvn4yQdgDJJNJrKBICYwNuV/T/Yats1XwMY71ArO5wA40/zCQCxQO2dt/AmmkCyK1bI02qe0rpGy1UKMYmhT0qe3bYbrL/deOCTgEbulWIqjc+YTLoT8R0LsftZXumG31BJgUbFsv28IS2e+yNXYJV5bUyDSiJjihmkFeG2vb6ybpPvecUBst/+kx6/QI7aAG9f1/0Tn4wPCIwbBhkp/xxl4AyWQ5eXLV7PQ5g8ndHNK3Fo9AtlNFyn2nof7IQiZOZth5EnerjXhu3pRWBHIfUp1+/hE7Px4l2T0v4pHtIw3Vaosn4sFA6DzrWeMR4a8rrbeh+EH0sOcdn96Ooxg6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rlCaEwzLJwJQhM2FHF/4VqTXShcY7qSgVY2gyqriqQ8=; b=hZr7CrpCqNlCsToiOYc4jm/C+aNlxFLEu6br24oi40dyaIsal1Nz4gicY7iNu7wEyO28Ux2zJAf1vgSNyaPEkA73+CTvhyHiqdXvQwp0tU0OulgFdMjYgvGFaqyr9S7kfDKZ9ikJBEF3ipXfQkYBq+gNWWnajG85T1ykKSluiRE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) by PR3PR04MB7436.eurprd04.prod.outlook.com (2603:10a6:102:87::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.8; Thu, 19 Oct 2023 12:03:00 +0000 Received: from AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617]) by AM9PR04MB8954.eurprd04.prod.outlook.com ([fe80::e109:7026:7d76:5617%7]) with mapi id 15.20.6933.008; Thu, 19 Oct 2023 12:03:00 +0000 From: "Radu Pirea (NXP OSS)" To: sd@queasysnail.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, sebastian.tobuschat@oss.nxp.com, "Radu Pirea (NXP OSS)" Subject: [PATCH net-next v7 7/7] net: phy: nxp-c45-tja11xx: implement mdo_insert_tx_tag Date: Thu, 19 Oct 2023 15:02:09 +0300 Message-Id: <20231019120209.290480-8-radu-nicolae.pirea@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> References: <20231019120209.290480-1-radu-nicolae.pirea@oss.nxp.com> X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8954:EE_|PR3PR04MB7436:EE_ X-MS-Office365-Filtering-Correlation-Id: 5486d272-a9b2-4715-f002-08dbd09b56e4 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bH3BudLxkRuHtb2Zk+669GM+o5AykQM6Rx24hFdfZcEV9BJVJF6ap6He3UqIZVygoe2axsgyfy90uUkKZRtDxKveAK35JFZ3y4hyWLhaA/vbZB7Y+Ls2QKAELDv70XCR3dlSYgwLjoiCA41m9wx13vNX2OTaD/86/yvSnts2p363B2ninoYLfAj2Db9+JUFG4z8lw0d1ZiZWmrEfnqexqMf9ok/lH0i88mIupNxXl9WLwQDRgLhmfFTeO8a8/oMstGNHcqBB2BFhyMGvxwJeUVKG9uczPLKGgA1aPWyNXeVIoykYZ7phygtN+Bqvq1SnIkwr7g+orFKOnpijITDbyIfdPtqjJJ2uAhFMIrPKwEwkAyoOFHOlYkEg3E9+k3e3R7OiocxcG0/qMXy8ocCnPlbQ38EyWJs1r1DGSqnyN3gP2Jx6b72U9XoUQBlfr+7t2ScY0XpPRzXxJ4mNogKjfleVJZlyZtKt2vtxgVK3PravIonjq/H0Cc4vZvLzmgv05QwULXRE1X7rzN31j8e2DyWiqvaSpz5aEXZTnRI8hPprV0IpXH1DI8JCehG7vvburw08luotumBUdbLuicAPsBfWWQSgmMY4Pa+o50yGsgUULGgP5Ck6OvLUPYixLqcd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8954.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799009)(64100799003)(2906002)(5660300002)(4326008)(66476007)(66946007)(8936002)(66556008)(316002)(478600001)(6486002)(8676002)(41300700001)(7416002)(86362001)(38100700002)(52116002)(2616005)(6506007)(1076003)(26005)(6512007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X6eZVmfo4esN4uar1bsba5qddUw104tcmaOYh/RguJcwvZYMRPjFwxcYSwAn3sPjuDKYlIZB8I77t38nAqtTCURCy3tDdQtKGoS26p3EyXOeczI+acVQ86GtPLFtmfH7QkOlt6tcGpVRYHARBS7meKvFKMq2htvO7WnoY06Bsr9CnJDTkPmxXmhDPuG9bR4rLlTkNRMbXQCHc+kLPkHTJfVUbpUK1lTpZHo/ZZAbtCt4Kje+5CWZ3GXPIGYoJBK/TDPgZHb0C6MABIsDIpHHrnbXnkBAAMJZZxqkWaxz6VuC2xpkU30xnTECHcq+dQRGr4ypJ1NcnCiHIwFOidZ8sirbZrTvY1WmDB1LOX3EvfNFpdlx8ZPmlyLGlTIN2LDoTAyxzwQOA5KdSkwFdvDiF2knoSQ/93PBb2boRLouIpW3T63hfuiOXHAS9vk+OjbMJPlazotbRwRIPiqcD8uGVJAqr0EnJug8uZq9ulZggsw4x9Kd9P+0RI17K2a3+Bs20Iwv9MNrTtupER9TPAv0wd3Hd00T4ACWV3XBZLL6SGAzkAF0MbAl8Om4z78FPi09Cn+oo7/sHuZEx7D9ZBjR6nBV0cnlbt6WWDx7Ks1j3ytiu7+X6pLrGOcB33/ThPhX+uUjS8iZQwPwaoU2/PMESzgbRdvLKw1gon3ChO8ZlV01yPD1UGgewk3j1igQLiE8YGGQ+1zDDS2Y8WcTCNctxv819yFsZz9aQZtb3XWuoJeKbX58R2H9wcocH518ZoRI2hYmJ5y2PwNwJi1Thno0VIP49Bzo6agBHPlXI+Kkx5OQthO19sKk5XOakzez6hIIH+FbrIzzThrqhB4/972zix7Bh0wUWn/vWpOvIbCNu6VzlpiPmD+U1PJeOMxlR4iPIPz5Fd+S+Md8ZT1M1RSz33nJKqOenuyyQr+tvfGpvsSs7lZfKWiS/+I9SgUwhw06xVRzO45aAoHmyJFowVV6O46y7IGQeIYX1pLECJbOLNqgy42xN8YsAzS44k3uWfkiRrCZNP2+2ahGqh0zK5CsT44or3WzSwVe4lpEjuIZkv97LtW2yDH6gh8vFZsg7pxQUh/66y1ESK07H4P2cWToWVlNbmxfl1XKNIT2Mnb0zv9c2Dlr6PZrjbxFOUG6ynDdKrPfEaD+DuTYMoZ6mm/a5coSMXtstDtnNR0VzkNzbXo3CIfHjcP7lBXs680WhrXVgC9f6/kY4Iw2WXhxCGYCtmu+ajD/581kUJmLG8EFScDJ6A5rawSNoG+xeoucUR9YqGTqmL5ThjgEDSyTTFkMHbj7zYnbaTIM3JisW7a56v/4vC3adDdGVyA8nGm0Y+cnEe7zeqockT/wOMhBCnbAW3qN0WQXbRbs3nOhd68S3vt/PmEHyk5kIsfiCfXSq1mgQd+GoqQbo8YHIuM7dx2Gv69521PSQ5vQt9odYRDUrXiiNd2s20g1VDSWqutq0BCL6odv6j5UG/tHIkm54wx238zvVgv2cSxPy3NYeuCtVA/m95Ozf3NWeT/Oi7tRyYRo4IxupZNKn9MldRIk4Cp1fKGsSY961gop/lCcOvWqz6tiZlzoqSI/OPtjRxKKD4aZdG2J41e1jqB2EznKSpDa6Q== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5486d272-a9b2-4715-f002-08dbd09b56e4 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8954.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 12:03:00.0736 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4JsAdDWIvO/9VB0KvGycKN6h6GbQpJDld5GVZO34ERfqhr7tOLvJ+/qzTLoiLzj4IOTCvTKSlm4t4oswruVuF8WqP5pP2bK+J1EGorJZbdw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7436 X-Patchwork-Delegate: kuba@kernel.org Implement mdo_insert_tx_tag to insert the TLV header in the ethernet frame. Signed-off-by: Radu Pirea (NXP OSS) --- Changes in v6-v7: - none Changes in V5: - removed unused defines MACSEC_TLV_CP and MACSEC_TLV_SC_ID_OFF Changes in V4: - removed macsec_extscs parameter Changes in V3: - extscs parameter renamed to macsec_extscs and improved description Changes in V2: - added extscs parameter to choose the TX SC selection mechanism between and MAC SA based selection and TLV header based selection drivers/net/phy/nxp-c45-tja11xx-macsec.c | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/net/phy/nxp-c45-tja11xx-macsec.c b/drivers/net/phy/nxp-c45-tja11xx-macsec.c index 4dd10ea6e06c..6ff0ceeeecd1 100644 --- a/drivers/net/phy/nxp-c45-tja11xx-macsec.c +++ b/drivers/net/phy/nxp-c45-tja11xx-macsec.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "nxp-c45-tja11xx.h" @@ -118,6 +119,8 @@ #define ADPTR_CNTRL 0x0F00 #define ADPTR_CNTRL_CONFIG_EN BIT(14) #define ADPTR_CNTRL_ADPTR_EN BIT(12) +#define ADPTR_TX_TAG_CNTRL 0x0F0C +#define ADPTR_TX_TAG_CNTRL_ENA BIT(31) #define TX_SC_FLT_BASE 0x800 #define TX_SC_FLT_SIZE 0x10 @@ -166,6 +169,11 @@ #define MACSEC_INPBTS 0x0638 #define MACSEC_IPSNFS 0x063C +#define TJA11XX_TLV_TX_NEEDED_HEADROOM (32) +#define TJA11XX_TLV_NEEDED_TAILROOM (0) + +#define ETH_P_TJA11XX_TLV (0x4e58) + enum nxp_c45_sa_type { TX_SA, RX_SA, @@ -1541,6 +1549,31 @@ static int nxp_c45_mdo_get_rx_sa_stats(struct macsec_context *ctx) return 0; } +struct tja11xx_tlv_header { + struct ethhdr eth; + u8 subtype; + u8 len; + u8 payload[28]; +}; + +static int nxp_c45_mdo_insert_tx_tag(struct phy_device *phydev, + struct sk_buff *skb) +{ + struct tja11xx_tlv_header *tlv; + struct ethhdr *eth; + + eth = eth_hdr(skb); + tlv = skb_push(skb, TJA11XX_TLV_TX_NEEDED_HEADROOM); + memmove(tlv, eth, sizeof(*eth)); + skb_reset_mac_header(skb); + tlv->eth.h_proto = htons(ETH_P_TJA11XX_TLV); + tlv->subtype = 1; + tlv->len = sizeof(tlv->payload); + memset(tlv->payload, 0, sizeof(tlv->payload)); + + return 0; +} + static const struct macsec_ops nxp_c45_macsec_ops = { .mdo_dev_open = nxp_c45_mdo_dev_open, .mdo_dev_stop = nxp_c45_mdo_dev_stop, @@ -1561,6 +1594,9 @@ static const struct macsec_ops nxp_c45_macsec_ops = { .mdo_get_tx_sa_stats = nxp_c45_mdo_get_tx_sa_stats, .mdo_get_rx_sc_stats = nxp_c45_mdo_get_rx_sc_stats, .mdo_get_rx_sa_stats = nxp_c45_mdo_get_rx_sa_stats, + .mdo_insert_tx_tag = nxp_c45_mdo_insert_tx_tag, + .needed_headroom = TJA11XX_TLV_TX_NEEDED_HEADROOM, + .needed_tailroom = TJA11XX_TLV_NEEDED_TAILROOM, }; int nxp_c45_macsec_config_init(struct phy_device *phydev) @@ -1581,6 +1617,11 @@ int nxp_c45_macsec_config_init(struct phy_device *phydev) if (ret) return ret; + ret = nxp_c45_macsec_write(phydev, ADPTR_TX_TAG_CNTRL, + ADPTR_TX_TAG_CNTRL_ENA); + if (ret) + return ret; + ret = nxp_c45_macsec_write(phydev, ADPTR_CNTRL, ADPTR_CNTRL_ADPTR_EN); if (ret) return ret;