Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp296786rdb; Thu, 19 Oct 2023 05:04:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKtO7rb+q3rZW+VdPg7hbpqKmANDbskvs9QJSQ9eNnr01O7370DKif6EWFJuCpB8vNNCOp X-Received: by 2002:a17:90a:6089:b0:27d:97e5:f3fa with SMTP id z9-20020a17090a608900b0027d97e5f3famr1902039pji.29.1697717064241; Thu, 19 Oct 2023 05:04:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697717064; cv=pass; d=google.com; s=arc-20160816; b=OfK0Q3wP3SPjvSr2DF/SFWj01DZPLM7y2Jniv5bd4prWVomXCDxaeySLYY3099UH3r v0PjThg2ng4NKrMPQY6OtgEZXnlkbQ2o2moPJuV+heMZBmO55iTE1kBppEDjiBPNgGp0 P6saZ+NqcAo+btS+B8H32BNL57gVQIl48TnZNn1OVRtlIqr3rVZpc6TGW01Ua841jjw6 L0qMUJfNelOZf2WueUiplj8p3uFKQTdKAJPh13DoDJHniDLQscPIT9V+b4lv19fAm3k9 hm1rkreNgBDX/A9j3vggHUhnH5d0VDAhZMW/M9iHGeROddf97hDFFhDl6D0fNcRwGcNz iMpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=keNHFqYO2lAwgTo0OIDsPObxKQcCS6dG9oAzEZp/wO4=; fh=s+N9zLYkhYW6x0tN5kM/nSX5iVt7LcJWvFt8Uz0wx+Y=; b=ycfRURSSfTYKfPm+VgO8UBiQir7VFnXlVzd7CglNvQbXnvW3NFbOQUbrPp3PElOiK3 olOiPfJFqrdcZb0noxj2JynGxiOisPVFwyHymWuqUWkT1PQlC4hZ29747xoNRV3FzMkK mdUfS4GSnjr1hJIPm7v8tIgP+BxIlYkdCOJhv26VtEMYt+QNnGzyT0eW7hOvPD4tVD83 jgTII/la0qDc2wWT97Le/qfKD8qkp1cjtCuTC4s+Ao91g+oURM8iVMH+7gb5790zT1e8 L6uoBhnrJAOzS2Im3ugENwc96LB1ujfcwi6T1L2iP7f0PrIakvw15odqDrDvuX+xWidq tDXA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b="Ji/sneTp"; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id q11-20020a65624b000000b005accbb92b70si3915815pgv.676.2023.10.19.05.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:04:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b="Ji/sneTp"; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 252FB82B8A57; Thu, 19 Oct 2023 05:04:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235395AbjJSMDl (ORCPT + 99 others); Thu, 19 Oct 2023 08:03:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345647AbjJSMDN (ORCPT ); Thu, 19 Oct 2023 08:03:13 -0400 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> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: VI1PR08CA0236.eurprd08.prod.outlook.com (2603:10a6:802:15::45) To AM9PR04MB8954.eurprd04.prod.outlook.com (2603:10a6:20b:409::7) 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: =?us-ascii?Q?IHE9iKE4jiVb8C/NFqhLFKZyzKPFiWLYELV9V4VytebmHsnwIlYgDWrKl44S?= =?us-ascii?Q?Xx0A0QRdXjBYVgxFR4zPSLAsClAOiteWXIVlftgY78IzJO6PE3Ykc7uTw+k9?= =?us-ascii?Q?inqqFqKbULa7UqVy2ROV1I9Goll+HWC026cU53oDf7JDtO15hAh10a/lkVRT?= =?us-ascii?Q?t3vKPLo0RkcYmncr+jlLJnOh7qFACCzeil+bGS6ud+0b2gUD34f3QpGl2T2C?= =?us-ascii?Q?DpA9MTfGO9siZ/XOQe5baZ60MA8Z3iDAtHB+j7Hgo1afV5GQzVaHrWANhglE?= =?us-ascii?Q?50EbVAQl3cH89I2O69tiKyYtalriE795fjGgGtnOV4CDnbch8cw5SaNLGEBZ?= =?us-ascii?Q?q2+ZppzVkCkgY8hEfkeGZA8xJmRA+7uFUjTUrQkPZU4M7yjQYrTDAExbnEUV?= =?us-ascii?Q?gZg1ZIoP/8diaJF0Wf3BDjZCZs86mss3utwnw0i5qTvpoRpuouoSAhXBiCVz?= =?us-ascii?Q?sWaHmQ4qUFevUvKMtnGpoIRiia1cQvMdo14Ln2KJVL6eR0rebrI5uQbSJn5D?= =?us-ascii?Q?rR3RigeJ8YxHt9PV9yym+JqLCnYUPUrFO6wVKr3HzMzwfgb9I7e1N78vLM73?= =?us-ascii?Q?+x2tdar47XODxBBxZwL7cjXrD+WUZ5/1wZQswyW7PUOxEY708BpJcYfGdPjn?= =?us-ascii?Q?yglz7PUjLIF4IS8DXVQF5b6R13pnkp0NCTIX4IIHXSkJILHmzbftZ13i4cXH?= =?us-ascii?Q?Gkc+nef7TYikmFViAAdipy5D0oirCZCm2rRRJk9Q+cgiUnH85EZjGdwVTLGj?= =?us-ascii?Q?7Fv8mytPkgwGMc7sMeiZe+ASkQQGIrDsT0oRfW0eHzZ4RLsnYM74f6N8E9vs?= =?us-ascii?Q?2Q1w5TWMuhvGiDbOeaWzIhIFiJ6mTNUYJIzML0sTjiMzA9fA5+HVL0FSiotH?= =?us-ascii?Q?pD+jbybjBjfULryua+AjD93lUuox3UQzbPpGPqNBx75C+/b/IcqbjY/TLExV?= =?us-ascii?Q?cRHHaJBdOPsTTXOEPGCGoJ4KmXf2xjUkNSzjbS93C2epo9P8p3iDV4G3FKsf?= =?us-ascii?Q?LEnRlqU4zYZBAsT1yQUhkJ3o2C/lFuTDZTr7oSvnYH3U4Hf0G2mHsH9+wGDB?= =?us-ascii?Q?VrCb4qZffTJqXTJ3XXVK/f0IEu3TSmhLaYXQxDvXHk2xSCkLvWhHqUDNngDb?= =?us-ascii?Q?oBrGZx5TP+QtOWA0+BCdo/d+NDp6asU8/Qjogh+iN8X9iSCh3MvtW109E2AO?= =?us-ascii?Q?WObr5MnuxEDn8JEPiYh4qy2ZnFGAg/D8X0Au/Q9F5QHdtXejlZ0aSRYHGapC?= =?us-ascii?Q?D1AQcA4SKQ7bluY7n8omKs5gwmdWiKdz45IGXGT6pYMSv2521FCSDk8NmYL8?= =?us-ascii?Q?zaqCyR3zYBDYirbRMD4xzImDFYIzImRqkbIKNiSzUwlYVlrTib7Veu092kCc?= =?us-ascii?Q?KtKRAlAvB81v0qO5NZqPSmb22HpEyIaBZG7H1huMyw4HBro2M2QZf2L5ENlX?= =?us-ascii?Q?E/2GbOsGLhDxcAJlZXyMh6UUodXpss72AbeTs9MMs4Yjm49ZspdFG+Iuwy9f?= =?us-ascii?Q?8FAFSFBaphNGb9DWg/i4PucZbpDQ6T0S8PnIdFCp7pLd4JQg7iJqt1tAk7Iw?= =?us-ascii?Q?1sa9fnVMuWeF22f4MGmzQT1fbcOQ4A570Lxul503HSkvf24KQrmCMOrsYWJh?= =?us-ascii?Q?ZQ=3D=3D?= 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:04:21 -0700 (PDT) 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) -- 2.34.1