From patchwork Wed Jun 19 12:17:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703771 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2044.outbound.protection.outlook.com [40.107.96.44]) (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 EF39D14372C; Wed, 19 Jun 2024 12:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799488; cv=fail; b=ANfNFo7MQTEVvU9PIiFQcBpgoo70lJRkbjNdc7lsAIvMQKh/n0xbc5tFEDGpC9vVptjTAmvcRtki1Jpopb/zIRYAgaBXskT2wTlPPbYbZ8buiVXJFt9lRihGQuztsg/xUZ+ulL7FF5yVHT7MNTx6v+vD9pUqW03AkyiC1UeY/m4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799488; c=relaxed/simple; bh=4ck3w7VM+1Kxpcl2D5+3CgPPGLJkcar1wVWrPkbHjF0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IPeBjAh1OTbPeFfQw9DHD135IStS4spZDUxqbbXIGcYm5OcEJzgRSjdtMrTnlYyRVivZ+MTYET2WADjlSvoy1Ploa/Cb+h8cdCYSErpHlJOTE5KD99W4Ewen4BkW63jJLo5rBOZzz7xqKBMueJOVjVgWbQoHN7GF5/p+5XpR8pE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RR6tVAfv; arc=fail smtp.client-ip=40.107.96.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RR6tVAfv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jH4sMffxqIbl9UZQYgb66JF4ZQfX0yorx2GQzq0VBZE5mzS2K4ynGEqxZkY6mXlS01lqokv+686A5cBPmLl/hoNmdv/QldV6lKXbEYrot4X8KS5hrTaHq6dv9/Njpg7S3ofSUSj7aWi9IFtswzfvMPPSefQcNl0jodhMT5haqmpWQFTbyOV3IAgZsno4nK+upphe390Uuqyt/mjw6935EB1Cu9mwcHyk3djw+OWBowu/KEpFXfOHgvrPtsTyt3w7/hXssJB7o+31bvTu1vo4uAWPnusz4XPJaFUEUBnpq0mUlKy4eWFtbY0VX7kIAOtqFluGcBG8sQv4MKVKw6fJzg== 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=ErS8hdpJoxO4q0KydJ7PQ2tO81x/w5HONh4RKs9DBpA=; b=Ve5s70Bci4suP0MlbuMi7ef3/Puu/QDvXlDwaX8TksEDSV1BmpPdJ6M94AhygParVrCosDOs+2M+/9nFC/jJfeuCieaiZ5bUIyfEUMba0di6xsYW84gCIy88Ho3QxXolsh7vAQJr4wC8lm+ggEPm+TSmJJ46MSDbyw9dPImrK1MO3RsXwjLV44ZLMkmPvnWB94ia7482w1wgodUtx8s6PJA4yWSXKMaJ2+hWYkv0abWFsGBiLJh9pjwUNfIWCiqmIC0WbfHAv7cf0yQKsNnZxGFWVnvPmgs906b+b1Q5wwPdVtGfO0j2oktehf7f+88DzsUPePhtRhPQi/cyRNtjfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ErS8hdpJoxO4q0KydJ7PQ2tO81x/w5HONh4RKs9DBpA=; b=RR6tVAfvYfzyInzHwEEFTht7Lyi3AwdDMVnXu0lkiLzlpOEh/YOjbVcTppB43fSY0eZbNwO1Z7yX8k8qSlxCZu2W6BCEjR6zliyqjn7fT7Rw5EyzkST+7YvbGaIx28iJk9s7tgWKqwB4YCw9GmkRdjfWL8sXGpAdd07k+YkWJT3fC+U3KxI6FrJRkC6GO1k1xEakktq1d9IxEtJ3XB0//bghX2WG5W+0T5KqiWsH+3m23teZJqvqDCS6lkrVCsvPpCftjBfx/BXYhuBxT/4JwfCjYX3DKEruEmutwDPE/sMrOxEpSAUiwaJfQmGDKE0WHcMTkE+9gsNvmpVKBG3UEA== Received: from SJ0PR13CA0040.namprd13.prod.outlook.com (2603:10b6:a03:2c2::15) by CYYPR12MB8937.namprd12.prod.outlook.com (2603:10b6:930:cb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.20; Wed, 19 Jun 2024 12:18:03 +0000 Received: from SJ1PEPF0000231F.namprd03.prod.outlook.com (2603:10b6:a03:2c2:cafe::d5) by SJ0PR13CA0040.outlook.office365.com (2603:10b6:a03:2c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31 via Frontend Transport; Wed, 19 Jun 2024 12:18:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF0000231F.mail.protection.outlook.com (10.167.242.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:03 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:17:52 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:17:46 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 1/9] ethtool: Add ethtool operation to write to a transceiver module EEPROM Date: Wed, 19 Jun 2024 15:17:19 +0300 Message-ID: <20240619121727.3643161-2-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231F:EE_|CYYPR12MB8937:EE_ X-MS-Office365-Filtering-Correlation-Id: 24c88b5c-8a69-4623-955f-08dc9059de6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|82310400023|1800799021|7416011|376011|36860700010; X-Microsoft-Antispam-Message-Info: HguY/kvWo59CxhGBIC4eLRPcvULkyJgc/fg5zEjpO+bwM6LdMqkHWG3661LGhZyyRZKamFx6nlvB+nUutgcOTrtzD3p5Gx82qWxFq+xImvqUwQ6nHTG8nbTdKdMJkomnj52iHijAvY9LTHwVJSboyjd6NKtExCBo0OCaqS0IgZaSmQwJ54QH4DvTmVoUrWVTionjIQmnaG89cOd8jqKV13lsbiOK3FXSA4zZaVkJYR/x5+TY0DP1IKPWEAntIliY5cpxM2NUC4Kx/GUP7TOy6HH2uHy0MWpgBScN0tG3N2Cte+GPTO+GRURPOqiiDDePehVgFyZGaux16WNSGvd02wQ27f7FM1ZS0oLCLpcYCdDnvuOm0rBoTY0sSFtU1xFEUMwngOsrhXmuONJIDwG7DhAN5jHKJHwhqOJ6TY79jbk8TmViPwk8Adb/wfhh/xogjmWRCiCACQeKZYW5MxHO96BKsdvASCfbr6qRynfHSbCEXddQZDYNOSFl8j4/7cb8WiopJsUnuBceuN618D/uojz4X5i7BQXkejJ72OmKGIy/KrPkOgmo9YHulTuhb9IV72o2hBqboBRyp8GrO5YHwGCbaw1fFNf4GdFlwQMiNcA5UfL59ue3WuCX0yOTgXrf+Ps9bQOL7YU3S2zx5EvZXo6V49wMGg45bP8lm06h2SQ7FQ55OkYT2zhweG/Igqyw8E2qWYSw8MCsjbrYnF7CXBjoeVQnFzNwi3m1K5tsIsHc8P4rETS1SmCHXAytLALPTiJEiSCUCRjI6FIGYwblvc5RJhTTVH0lrAljyo0cjwPgOrx84DeJcpY85OLnmI0jFO2v1bYQpSTFeUGr8Jas0L1gxrjqUoDENok4d4Fln/ZiTQ21kKTub2QUMD2AaUErASH5Z4c2RvGGYogDuC2S5Hc64gzk/CSoeCfheC8xnfydffJIv8uIE6GWPlRYUwWyH1Y1VYick9k3P3z320sMIiqao2Nzg7T42gNElljgj8/7E3PMqfZljgxNB7h0YijRjz4ILSaRScFcdL5D5w3L4Am7lhbVdvkrQG1v3nkJiqBDZJTVRc049IIzIwXESpc8MNHqnBtCeG4PPG8NKCvB3xI5xmzQkNIJ+9jkGjKK+60zh9Itu27ihdaG4I8QAGxo97Uu7iSx96tjuUn42gk3MDGceXRdJF8I8SSi/ky18X0BWJU51rJwLGwtAsyaGNwKsp7c3Yjn7hwyXGyx8w34LOf34jjtUMbZrzH79yyLxBnJpAxt4VJrS3shMzV/3CskDfRPhmG47nFTMxQILUpcaEEIYwxCD5EquPew5FvkfVOJ0JlQzJhyGd0vGTJq3AjnY13i4MHo4ypzktbAgRj2NmqTUsARl95Kjcgj0Hg4DzHXzZgPCEbuvDq27ULWZcM7hpXB1QJFdeS/SqJg0DvmrQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230037)(82310400023)(1800799021)(7416011)(376011)(36860700010);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:03.7889 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24c88b5c-8a69-4623-955f-08dc9059de6e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8937 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Ethtool can already retrieve information from a transceiver module EEPROM by invoking the ethtool_ops::get_module_eeprom_by_page operation. Add a corresponding operation that allows ethtool to write to a transceiver module EEPROM. The new write operation is purely an in-kernel API and is not exposed to user space. The purpose of this operation is not to enable arbitrary read / write access, but to allow the kernel to write to specific addresses as part of transceiver module firmware flashing. In the future, more functionality can be implemented on top of these read / write operations. Adjust the comments of the 'ethtool_module_eeprom' structure as it is no longer used only for read access. Signed-off-by: Ido Schimmel Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- include/linux/ethtool.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 6fd9107d3cc0..fa1a5d0e3213 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -504,17 +504,16 @@ struct ethtool_ts_stats { #define ETH_MODULE_MAX_I2C_ADDRESS 0x7f /** - * struct ethtool_module_eeprom - EEPROM dump from specified page - * @offset: Offset within the specified EEPROM page to begin read, in bytes. - * @length: Number of bytes to read. - * @page: Page number to read from. - * @bank: Page bank number to read from, if applicable by EEPROM spec. + * struct ethtool_module_eeprom - plug-in module EEPROM read / write parameters + * @offset: When @offset is 0-127, it is used as an address to the Lower Memory + * (@page must be 0). Otherwise, it is used as an address to the + * Upper Memory. + * @length: Number of bytes to read / write. + * @page: Page number. + * @bank: Bank number, if supported by EEPROM spec. * @i2c_address: I2C address of a page. Value less than 0x7f expected. Most * EEPROMs use 0x50 or 0x51. * @data: Pointer to buffer with EEPROM data of @length size. - * - * This can be used to manage pages during EEPROM dump in ethtool and pass - * required information to the driver. */ struct ethtool_module_eeprom { u32 offset; @@ -822,6 +821,8 @@ struct ethtool_rxfh_param { * @get_module_eeprom_by_page: Get a region of plug-in module EEPROM data from * specified page. Returns a negative error code or the amount of bytes * read. + * @set_module_eeprom_by_page: Write to a region of plug-in module EEPROM, + * from kernel space only. Returns a negative error code or zero. * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics. * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics. * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics. @@ -956,6 +957,9 @@ struct ethtool_ops { int (*get_module_eeprom_by_page)(struct net_device *dev, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack); + int (*set_module_eeprom_by_page)(struct net_device *dev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); void (*get_eth_phy_stats)(struct net_device *dev, struct ethtool_eth_phy_stats *phy_stats); void (*get_eth_mac_stats)(struct net_device *dev, From patchwork Wed Jun 19 12:17:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703772 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) (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 C081014372C; Wed, 19 Jun 2024 12:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799498; cv=fail; b=nDtllq3ek8LoVAe1cew8/i6TzvFQDEH9xWjFohQnQqb7XueycBVntDzOqNCE+vmogCrpbv0fLAWerasWoPvBsKcAeB8Upmd/y2Tk2Oe34tNrhu4nmgUcmLHayvFrBYLt/VPwLf3aqMe5FrYMKBWl406YMifY27EpTVrz8ZoGLY0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799498; c=relaxed/simple; bh=aTxRNMM1hRQggbP0Fr1hy+tstbDZJhg5+DMlYebEga4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rijd+l79DpTwt4cayCQbCCRBhOA2UQQVnTL49uRrNuDoYdyCi5nbIJrV94JEwaUwVkEmrCjtbLLcdB/JVGHmF/pY7mWPo7+ODIcEa4zwBquk/akeVO+MX8on+6DbgylPdxHM9y7/yu+tGSEAY9wKNWJsBf0jdKYmb95+9Z6YVQ8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=j8fRVYgc; arc=fail smtp.client-ip=40.107.94.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="j8fRVYgc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aG6o82j3ysMg4qwk0xxPL3+nPAp6Sf94b+MNEGkamMWsIPvmP3onsAEtfMvvGO6SqZVWHndtlmBeGztfiq8uZFy7vunbs2zx2iGRyMuXdDvaE7N/RcoHLg8dHjHz/eofvJ217YYygNlnrt4F/rjnqBMSQDeCJfhxp9O+mIPSBzuC2CETDSeyUMjculUrY7Be2eabgPIi2Bz+Lek2rvDj9GQse/4fpHpZRRCsN9GvUg8cu0uFSaC4wAa53XwUhm6ZVEdDBG3qVv4RjgGnD6epb8091KHZNXM9DREAVK/Vn25bzwAKdEOdv1HS9g9Sjub6pRFvf+J27tVSoyEu/O2sXg== 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=anWgWMEJrRNgLT/UmgYVrL+gM3k+NEPUfpKvFmqdBNA=; b=Jnkw14wHh7hLmU3/OGtnBuc9/cjPW161I1+F15rYPvu9BoAtAJBpIwThb07Cf+wXto4WQadIwpoEniYbozE5rENmbwPYyV8yL8z8cvo+azW1GhMueKIXOJn3fM0H4LhW7r0NPW68dl0V263B/gN+Cw/ki5BojbCmPWPkHb2OCWD8hsPq9HiKUv1PHi31cMW6gvunCe+aHDBuG0v89RSaD9dnXw9JKbT6LWKqOoYQVJb0yCQ+XPjFTfo7quPM/ZjlWwnEKaHYYfIEsUQoHmHWKvpOFakqUdKzebJb5T3+48eyITVxAAxLD2kFIKWr2vf27xCgPFa+/ZACzPnrfb9rbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=anWgWMEJrRNgLT/UmgYVrL+gM3k+NEPUfpKvFmqdBNA=; b=j8fRVYgcIFmBNdXnssY/bJYYVTSoRPJxOxckkc9J7iKAIy9N+GX8pCAHHb/WjnkMSnkqdCtsqJpoXRzk9bbnV2fD+Kd+ihgCqbhzXOx3YRgcXy99xj8vlQZJu1mGTKWEAR0phzO7OrkitPR1TikRmj9wvklRUW4ZZ/aC9H401exYLaYHL/nsaUshTsRWN62Zdbe8A0dI5DRBlPeu9VeaOsxi12xkqJhCbg9ex+m7hbWzRd+FXdW/J+8NdR0zgTIudIIM2s2s0fn+hJ6gqvw1FGl+JNv0CG9UHhs+Vmv35sUBa7ke8jLOng9Gh02Bl4JMhWgsdxcg8TCHANR1tbMYAw== Received: from BN9PR03CA0983.namprd03.prod.outlook.com (2603:10b6:408:109::28) by IA0PR12MB8894.namprd12.prod.outlook.com (2603:10b6:208:483::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Wed, 19 Jun 2024 12:18:12 +0000 Received: from BN2PEPF000044A4.namprd02.prod.outlook.com (2603:10b6:408:109:cafe::ab) by BN9PR03CA0983.outlook.office365.com (2603:10b6:408:109::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A4.mail.protection.outlook.com (10.167.243.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:12 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:17:58 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:17:52 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next v6 2/9] mlxsw: Implement ethtool operation to write to a transceiver module EEPROM Date: Wed, 19 Jun 2024 15:17:20 +0300 Message-ID: <20240619121727.3643161-3-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A4:EE_|IA0PR12MB8894:EE_ X-MS-Office365-Filtering-Correlation-Id: f26cc1d8-bb1f-48c6-7549-08dc9059e396 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|36860700010|82310400023|1800799021; X-Microsoft-Antispam-Message-Info: xJkCJ/Tbe0eSFIz73jed0LirbEt2CA+cCSx3oEkculAyvJNSRLL7te6phx69j1D+9PHa6/FsNvcDfVNyzYybqM5rv7nl3g1tn1l8xCarClfwDKhg9ebTUjPqIbDUsOoIkL1Cwx6DPdLEBscBEzLEUWv1uI1T2qci5WO/l/0rIQZAmUxuBS69biAggzrNz+nUZMPOIUvPkh87fYLwW48Rj98yc86ZgDLwUt0y5zKRr7C2IY6yWSioGpLARupu8y3FDnrcTNrZokUURpZmD1pGbSLnWTvumqe5WNTE8E4guvBZ6SGJvvSFipFDLGO7hIZDjwaLTzI+xbVYB2FQiw3cDlUiUMwgpbSPhDIpOenNsuh6fjRkJ+7yG8AqBv2CCP0EjrZbxBPX2el/h2n193FTwjcKTjKAo6aNPRa9uETGriT6YjdPg9ujTBSO48BpRq4DsqguvEr1znuM9kV9zgANu/8vXrpXV4MayKaASwU+EvCXrbg0Lk2VeDqeJTYv4DZmVjnGkPxQ77hSZS7MpwVwO1UrX9NRfH7FJL1LrpXQA9JIylxE5IHvPxuiuWXRezsYNq4tifXuO94SkcOc9YAD/XCXA0t9x/nkRWhGP8ctrHgKc//I6nYQr+lnskY1nXGDVMJrXpCaj1hwKC55CRQTGMLeEVWofl/nlVs9cteEesSZeZbtT5qu5MG52x4YPUDDKRwWKXiN4A5d2SlhIKYVF4bJwwxmCQyus21QzVhA1/pB6QLmUbjhisxlP0wJ2s9NEwkHKHDuCZFAvGBQdBfkAlhgnxfcjDuN4+KHtWMXZKLs4ku7hUcot+MKlLOElmsd2kj9r3oqf62KHfS/o7esqzG5NNVhZIr1YqyojLm1p4ReqrPcHkBFNxa/u2s2+HiJg0481Fk7mGuNLQOx10pObsY11APW7sg+S5cDlhV55PlddCECH1aNSS38Kv+JluwIZvHjY4KyZ9q+loB4KiyFckxFIWxE3DnwMJgGUgVbrbcD66HGJZgPN1S9XiDe/066WMfq+4U30H6ZunT9GSYj0IQ/aLzvsObh9BBmeNOVSuHCJ9P1RxMRxYnCCYAIz8gXP2KVty7y6KGRpefCXBg3nGQXUwynRaIS/qvllStM/PhH1UegI2zSQJyW8BtEs2tJb7uJBcnQuoMFEqdEoGVsGgKfAxh0qPyeh7+bDqlVCwKW6QlWp8Mmb2Ba6iGSIUtjNPdjL6p9lBL3a8ZqvHPBy4dD6XmsATvpCHssNd1cpCGqv97LuvPN2got7DoFkJ2Gi6HnL2r7mWVEMiMDOcekBJJyJ8OXBVWhfeD1SmF7UD4qVyzUR/CNXYEhvl0yMdLlN8E4uyDYh9J4frE46xUuQUH9QGf2qeB71uyUjX5JCGskxcT6RqDcNY1kX25A4edZeb//XI2hlYEphiNio7AjOQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(376011)(7416011)(36860700010)(82310400023)(1800799021);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:12.2514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f26cc1d8-bb1f-48c6-7549-08dc9059e396 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8894 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Implement the ethtool_ops::set_module_eeprom_by_page operation to allow ethtool to write to a transceiver module EEPROM, in a similar fashion to the ethtool_ops::get_module_eeprom_by_page operation. Signed-off-by: Ido Schimmel Reviewed-by: Petr Machata --- .../net/ethernet/mellanox/mlxsw/core_env.c | 57 +++++++++++++++++++ .../net/ethernet/mellanox/mlxsw/core_env.h | 6 ++ drivers/net/ethernet/mellanox/mlxsw/minimal.c | 15 +++++ .../mellanox/mlxsw/spectrum_ethtool.c | 15 +++++ 4 files changed, 93 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index 6c06b0592760..294e758f1067 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -513,6 +513,63 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, } EXPORT_SYMBOL(mlxsw_env_get_module_eeprom_by_page); +int +mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, + u8 slot_index, u8 module, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); + u32 bytes_written = 0; + u16 device_addr; + int err; + + if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot write to EEPROM of a module on an inactive line card"); + return -EIO; + } + + err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type"); + return err; + } + + device_addr = page->offset; + + while (bytes_written < page->length) { + char mcia_pl[MLXSW_REG_MCIA_LEN]; + char eeprom_tmp[128] = {}; + u8 size; + + size = min_t(u8, page->length - bytes_written, + mlxsw_env->max_eeprom_len); + + mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, page->page, + device_addr + bytes_written, size, + page->i2c_address); + mlxsw_reg_mcia_bank_number_set(mcia_pl, page->bank); + memcpy(eeprom_tmp, page->data + bytes_written, size); + mlxsw_reg_mcia_eeprom_memcpy_to(mcia_pl, eeprom_tmp); + + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mcia), mcia_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to access module's EEPROM"); + return err; + } + + err = mlxsw_env_mcia_status_process(mcia_pl, extack); + if (err) + return err; + + bytes_written += size; + } + + return 0; +} +EXPORT_SYMBOL(mlxsw_env_set_module_eeprom_by_page); + static int mlxsw_env_module_reset(struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module) { diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.h b/drivers/net/ethernet/mellanox/mlxsw/core_env.h index a197e3ae069c..e4ff17869400 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.h @@ -28,6 +28,12 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, const struct ethtool_module_eeprom *page, struct netlink_ext_ack *extack); +int +mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, + u8 slot_index, u8 module, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack); + int mlxsw_env_reset_module(struct net_device *netdev, struct mlxsw_core *mlxsw_core, u8 slot_index, u8 module, u32 *flags); diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c index f0ceb196a6ce..448263423e36 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c @@ -140,6 +140,20 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev, page, extack); } +static int +mlxsw_m_set_module_eeprom_by_page(struct net_device *netdev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); + struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; + + return mlxsw_env_set_module_eeprom_by_page(core, + mlxsw_m_port->slot_index, + mlxsw_m_port->module, + page, extack); +} + static int mlxsw_m_reset(struct net_device *netdev, u32 *flags) { struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); @@ -181,6 +195,7 @@ static const struct ethtool_ops mlxsw_m_port_ethtool_ops = { .get_module_info = mlxsw_m_get_module_info, .get_module_eeprom = mlxsw_m_get_module_eeprom, .get_module_eeprom_by_page = mlxsw_m_get_module_eeprom_by_page, + .set_module_eeprom_by_page = mlxsw_m_set_module_eeprom_by_page, .reset = mlxsw_m_reset, .get_module_power_mode = mlxsw_m_get_module_power_mode, .set_module_power_mode = mlxsw_m_set_module_power_mode, diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c index a755b0a901d3..c79da1411d33 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c @@ -1067,6 +1067,20 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev, module, page, extack); } +static int +mlxsw_sp_set_module_eeprom_by_page(struct net_device *dev, + const struct ethtool_module_eeprom *page, + struct netlink_ext_ack *extack) +{ + struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); + struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; + u8 module = mlxsw_sp_port->mapping.module; + + return mlxsw_env_set_module_eeprom_by_page(mlxsw_sp->core, slot_index, + module, page, extack); +} + static int mlxsw_sp_get_ts_info(struct net_device *netdev, struct ethtool_ts_info *info) { @@ -1256,6 +1270,7 @@ const struct ethtool_ops mlxsw_sp_port_ethtool_ops = { .get_module_info = mlxsw_sp_get_module_info, .get_module_eeprom = mlxsw_sp_get_module_eeprom, .get_module_eeprom_by_page = mlxsw_sp_get_module_eeprom_by_page, + .set_module_eeprom_by_page = mlxsw_sp_set_module_eeprom_by_page, .get_ts_info = mlxsw_sp_get_ts_info, .get_eth_phy_stats = mlxsw_sp_get_eth_phy_stats, .get_eth_mac_stats = mlxsw_sp_get_eth_mac_stats, From patchwork Wed Jun 19 12:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703774 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2064.outbound.protection.outlook.com [40.107.92.64]) (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 91EF814D2A3; Wed, 19 Jun 2024 12:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799503; cv=fail; b=O68/qbtY6ZWLxMZWgUUfsM+JhHKu8OphL9IXuWDwji6WT48DhIS27dZvFrpeowg3hzErJDk4Ld7jNN/v8KLVUXoW/u9lInHqOa/lCgdnLINpxdQIo95TgWJkgLUIOH9LYzeLKPo4KjnyHh8oJHjTPcRAbkdpL+ovDpDQ9p5BIQc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799503; c=relaxed/simple; bh=/9auGPgHc348Aag4gLWWS9stNitcDk8YzaKsBPsVq8U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sWT2o7vL+Ur6ifLVZXKGNP1ebiNrNtp/kV41r3zcC18yJ2MXzCkeYJ7/bQs0X4pP2T9pwEO5HxmRv3/qgqRDiYliYoIsNL4BxDn6h5o3+jftpXMBZa9EifksHyV/GWehDkPhhyJyaDQ43j4R+nHbCrgGazSuyXRZmNq1v882HW4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gIlyJkim; arc=fail smtp.client-ip=40.107.92.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gIlyJkim" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jnjXtRk8bRQByyjy3NKQ6vLbWo4G3fPb5os8Xe6x6bs4qaxOmn/nho3YWemEi5w0ulOvNqKKlu5zHDMq2SOGvVP+hqsqK1nQsPjBFUV16yKVb4d+mVKGXSr8eSgzjfYw7X+sWSXmDoA6L9+4f0cwmOyYPS0TvCTyIKqzFi3uE2BAu7xsP2PzZDsWl2gYQ+Bhsnak/VBi6W2hf0rxlth+9cx9HtG6Eat2aBiGX+ef/IfqM/ozHYbalFCmdN0NUl1BM7IbyoUVCaT8SVZWw8C4i4Q0e/1FYRV6XYXXLdjK1f+jb/J6QabbI8SeSXN9xMRMdGxz6KZq+De+AyQIub66Hw== 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=50crNkk2tUbJ26WNWwrar1INxg6W3LhnEN5u5oLgdIE=; b=UFAuIDRFh4sWDBxrkmRgh/q+4VmTz/2DMRJmTd8f02yoJpeEXgkDlq/awH+uI2qOS38WeF8FJcQoAtPgfcU6LH95KblC0o+FwIshEUaOKApWkE/yt2U17QcW4TOy8iiZy1W0OYZH0BCvF7SV94sK2e4suAqC9NOue8Eza+UHaVocVX1LHwAI5X+9nGKxf8PopAT+NKzZZ0qf/jdxuDdyyugeE9RLdi8fvxZqW0DX9RbJ+DyJ6pOU8OD+KIQSI5yp7MplUxjONpgvqVCQ94KM/Xa8vmSb7aMsbdu/o76SLYnNHaOmSPHd1iBNOrzwF8njPcS6reexQn74ZMfvvtMo4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=50crNkk2tUbJ26WNWwrar1INxg6W3LhnEN5u5oLgdIE=; b=gIlyJkimYcN6qHFD7lVWYa3nEgwcxbBHA6Zny0aY8h+wmurbT584BJEGkWXL2XGtk4sTRRZYCAJRlHgWwvGgeNJqAvXVlbju09JuusPNm9UCpqHZRUmZfzBtys3Ku98Xh+BOtfPxGT85seUgfVfzmX7sbr8vdZlG/vLpvIB+bUakmomQtsKmnLGyZ2PlDa6YDPLz26grOKtwgpVdWfGuD7uN/FJ8l6Sm4McB3mO14DiYnlFubiEnfWtogab69E0s+wiohQCCEZeUBGAVuapIxdaxLFNTaXZQTVeXFNO7ptUEjr4cDNcnp2Ns6hNHmkCrvsFpk62YXYVSXhTKCPPbSw== Received: from BN8PR03CA0015.namprd03.prod.outlook.com (2603:10b6:408:94::28) by PH7PR12MB6810.namprd12.prod.outlook.com (2603:10b6:510:1b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Wed, 19 Jun 2024 12:18:17 +0000 Received: from BN2PEPF0000449F.namprd02.prod.outlook.com (2603:10b6:408:94:cafe::c0) by BN8PR03CA0015.outlook.office365.com (2603:10b6:408:94::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF0000449F.mail.protection.outlook.com (10.167.243.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:17 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:04 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:17:58 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 3/9] ethtool: Add an interface for flashing transceiver modules' firmware Date: Wed, 19 Jun 2024 15:17:21 +0300 Message-ID: <20240619121727.3643161-4-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449F:EE_|PH7PR12MB6810:EE_ X-MS-Office365-Filtering-Correlation-Id: d405f612-1c2e-4b99-9b83-08dc9059e673 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|36860700010|7416011|376011|82310400023; X-Microsoft-Antispam-Message-Info: WmNE66vUh7pObubxFK3W7jCubI1Ru0pfBilT5/h+UjQHg0GCZRErr1G9lUzMeTgUM72ELPaSxFd9q18GTxYZFRgs89zU2qvpiZ1M5Sv6W0ZzvM1VdVgjYwhLw0qB/fXgUWdTUEClEpUfmHXDylY9sXfR0md9Bb/Symzm2olg+TaB55O/UQwSwa9SfJkuopjPzyiaCiYkk9ONTcktvFHsf5PlMxOWj/2x5A/n0LmDe/kVWeOxm3KCqfV3iBVngeSQo/nB9ucbOC1vREXptUmYvpk3W/O+w0S86BeOIBItwOYwDW2O1LM+QLVu7d3nKyO/VAZepfxt0Pfk9Ufl47+vkcpenGaO3ptFMjiLM5ifDcu4EGq8SiSltObEPntHcYUNJsqQSh1pKguq+2PD+w0sHoChylGxJF1oA7P2TPChUrIwrUA29fPuZ9j687Eyuc6nMhwd0H/iAPtHVRVdqHh7vJyhQ0AIfryTQM4yrHiPvfpBohqHochuMcurUH8zLJmFYHnIBSPIeEk4Gt6W6taHhPowqR+1OpdHOrFIvwND/pypvzEV5ahUTqqyU+i+sELox9jzYLLLaOy4UlIZhH8m67VDeRUcfvi0a798R7DCD6N6gejwW1/Z8k12eAA3ekhzK2sR+qjjL9ZIcb6OQbCYLfkk3OQTQg2jeBQU2MugHtLAeCDDJLyZ3CO8gko5fqf2VqdCDA0Eog6py7ViZcAwzCvvWAF9Q39OGTIN7SDdx65il5LKJ0QjMx6gZgwnMkiVuD0gycpEMxaUpc2Sd7Pr2ysqjvwygTRiG1FLgiDIdZ52c8Oxjn/kXN/twFbnCDLoWUWoh5spYu7uFLJBDPQnyeAy6aQK08EdwjupJMbydsA9aZr9OLMZQ9jxwjlA+lKfa8UujOFoHWDVMaGp/mDtrVw/Hzvxvqf/Sbh+rQ1Zk6kG7QpSGQCbWveReQJll3UHyY2NuE91WwNDe94MoXvVtxFdUBuApNvVhGR6yKeazX/MvWdcMQ9PaXwjVcF+8DmtXBgGFE0mh1dU29QsmTa9DXo2CD3p6hBvZHNPEOBU64DuM2J2PBkOygnEesNyuvambae4M0JRX98LS2W5PxX1k0F+HO7L31oohtoBBSBZDvQaWdh38KCXQ8W0OZHPeKuPnmCQjwiO0E1XRKQZkZT2bJU9wHnWnvTXY4QEoQmepyIALevOJ8PrszLWhk96O/lJTvS8gnsX0Incxo62EikbVlt8e2BMVTed7JAQhtqPTDYUevnSUxqkTKo7ZjAe08ki2uGmIx8tKDUewIhMuI+XRxCaiqYDVgn6pI6LAvsXapU8sdv82MPX9Wttlk2bPPkf6Li5ErHR9RzXOAllrIY7UGFhfUkCPgf70DBsmnZJ/PgAIJiiJJ4/Fu+519MQ7Z6L5J6odtQnTXQI46Ds4OoqQQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(1800799021)(36860700010)(7416011)(376011)(82310400023);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:17.0718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d405f612-1c2e-4b99-9b83-08dc9059e673 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6810 X-Patchwork-Delegate: kuba@kernel.org CMIS compliant modules such as QSFP-DD might be running a firmware that can be updated in a vendor-neutral way by exchanging messages between the host and the module as described in section 7.3.1 of revision 5.2 of the CMIS standard. Add a pair of new ethtool messages that allow: * User space to trigger firmware update of transceiver modules * The kernel to notify user space about the progress of the process The user interface is designed to be asynchronous in order to avoid RTNL being held for too long and to allow several modules to be updated simultaneously. The interface is designed with CMIS compliant modules in mind, but kept generic enough to accommodate future use cases, if these arise. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * Add paragraph in .rst file. v5: * Modify tools/net/ynl/Makefile.deps so the ynl file will include the ethtool.h changes. * u64>uint for 'total' and 'done' attrs. * Translate the enum from ethtool_netlink.h to YAML. v4: * s/is composed from/consists of/. Documentation/netlink/specs/ethtool.yaml | 55 +++++++++++++++ Documentation/networking/ethtool-netlink.rst | 70 ++++++++++++++++++++ include/uapi/linux/ethtool.h | 18 +++++ include/uapi/linux/ethtool_netlink.h | 19 ++++++ tools/net/ynl/Makefile.deps | 3 +- 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 00dc61358be8..43c5f21e6096 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -20,6 +20,10 @@ definitions: name: header-flags type: flags entries: [ compact-bitsets, omit-reply, stats ] + - + name: module-fw-flash-status + type: enum + entries: [ started, in_progress, completed, error ] attribute-sets: - @@ -975,6 +979,32 @@ attribute-sets: - name: burst-tmr type: u32 + - + name: module-fw-flash + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: file-name + type: string + - + name: password + type: u32 + - + name: status + type: u32 + enum: module-fw-flash-status + - + name: status-msg + type: string + - + name: done + type: uint + - + name: total + type: uint operations: enum-model: directional @@ -1730,3 +1760,28 @@ operations: name: mm-ntf doc: Notification for change in MAC Merge configuration. notify: mm-get + - + name: module-fw-flash-act + doc: Flash transceiver module firmware. + + attribute-set: module-fw-flash + + do: + request: + attributes: + - header + - file-name + - password + - + name: module-fw-flash-ntf + doc: Notification for firmware flashing progress and status. + + attribute-set: module-fw-flash + + event: + attributes: + - header + - status + - status-msg + - done + - total diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 160bfb0ae8ba..b73082d2bd52 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -228,6 +228,7 @@ Userspace to kernel: ``ETHTOOL_MSG_PLCA_GET_STATUS`` get PLCA RS status ``ETHTOOL_MSG_MM_GET`` get MAC merge layer state ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters + ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT`` flash transceiver module firmware ===================================== ================================= Kernel to userspace: @@ -274,6 +275,7 @@ Kernel to userspace: ``ETHTOOL_MSG_PLCA_GET_STATUS_REPLY`` PLCA RS status ``ETHTOOL_MSG_PLCA_NTF`` PLCA RS parameters ``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status + ``ETHTOOL_MSG_MODULE_FW_FLASH_NTF`` transceiver module flash updates ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -2033,6 +2035,73 @@ The attributes are propagated to the driver through the following structure: .. kernel-doc:: include/linux/ethtool.h :identifiers: ethtool_mm_cfg +MODULE_FW_FLASH_ACT +=================== + +Flashes transceiver module firmware. + +Request contents: + + ======================================= ====== =========================== + ``ETHTOOL_A_MODULE_FW_FLASH_HEADER`` nested request header + ``ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME`` string firmware image file name + ``ETHTOOL_A_MODULE_FW_FLASH_PASSWORD`` u32 transceiver module password + ======================================= ====== =========================== + +The firmware update process consists of three logical steps: + +1. Downloading a firmware image to the transceiver module and validating it. +2. Running the firmware image. +3. Committing the firmware image so that it is run upon reset. + +When flash command is given, those three steps are taken in that order. + +This message merely schedules the update process and returns immediately +without blocking. The process then runs asynchronously. +Since it can take several minutes to complete, during the update process +notifications are emitted from the kernel to user space updating it about +the status and progress. + +The ``ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME`` attribute encodes the firmware +image file name. The firmware image is downloaded to the transceiver module, +validated, run and committed. + +The optional ``ETHTOOL_A_MODULE_FW_FLASH_PASSWORD`` attribute encodes a password +that might be required as part of the transceiver module firmware update +process. + +The firmware update process can take several minutes to complete. Therefore, +during the update process notifications are emitted from the kernel to user +space updating it about the status and progress. + + + +Notification contents: + + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_HEADER`` | nested | reply header | + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_STATUS`` | u32 | status | + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG`` | string | status message | + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_DONE`` | uint | progress | + +---------------------------------------------------+--------+----------------+ + | ``ETHTOOL_A_MODULE_FW_FLASH_TOTAL`` | uint | total | + +---------------------------------------------------+--------+----------------+ + +The ``ETHTOOL_A_MODULE_FW_FLASH_STATUS`` attribute encodes the current status +of the firmware update process. Possible values are: + +.. kernel-doc:: include/uapi/linux/ethtool.h + :identifiers: ethtool_module_fw_flash_status + +The ``ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG`` attribute encodes a status message +string. + +The ``ETHTOOL_A_MODULE_FW_FLASH_DONE`` and ``ETHTOOL_A_MODULE_FW_FLASH_TOTAL`` +attributes encode the completed and total amount of work, respectively. + Request translation =================== @@ -2139,4 +2208,5 @@ are netlink only. n/a ``ETHTOOL_MSG_PLCA_GET_STATUS`` n/a ``ETHTOOL_MSG_MM_GET`` n/a ``ETHTOOL_MSG_MM_SET`` + n/a ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT`` =================================== ===================================== diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 8733a3117902..e011384c915c 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -877,6 +877,24 @@ enum ethtool_mm_verify_status { ETHTOOL_MM_VERIFY_STATUS_DISABLED, }; +/** + * enum ethtool_module_fw_flash_status - plug-in module firmware flashing status + * @ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED: The firmware flashing process has + * started. + * @ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS: The firmware flashing process + * is in progress. + * @ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED: The firmware flashing process was + * completed successfully. + * @ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR: The firmware flashing process was + * stopped due to an error. + */ +enum ethtool_module_fw_flash_status { + ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED = 1, + ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS, + ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED, + ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR, +}; + /** * struct ethtool_gstrings - string set for data tagging * @cmd: Command number = %ETHTOOL_GSTRINGS diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index b49b804b9495..3748f018b985 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -57,6 +57,7 @@ enum { ETHTOOL_MSG_PLCA_GET_STATUS, ETHTOOL_MSG_MM_GET, ETHTOOL_MSG_MM_SET, + ETHTOOL_MSG_MODULE_FW_FLASH_ACT, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -109,6 +110,7 @@ enum { ETHTOOL_MSG_PLCA_NTF, ETHTOOL_MSG_MM_GET_REPLY, ETHTOOL_MSG_MM_NTF, + ETHTOOL_MSG_MODULE_FW_FLASH_NTF, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -996,6 +998,23 @@ enum { ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1) }; +/* MODULE_FW_FLASH */ + +enum { + ETHTOOL_A_MODULE_FW_FLASH_UNSPEC, + ETHTOOL_A_MODULE_FW_FLASH_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME, /* string */ + ETHTOOL_A_MODULE_FW_FLASH_PASSWORD, /* u32 */ + ETHTOOL_A_MODULE_FW_FLASH_STATUS, /* u32 */ + ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, /* string */ + ETHTOOL_A_MODULE_FW_FLASH_DONE, /* uint */ + ETHTOOL_A_MODULE_FW_FLASH_TOTAL, /* uint */ + + /* add new constants above here */ + __ETHTOOL_A_MODULE_FW_FLASH_CNT, + ETHTOOL_A_MODULE_FW_FLASH_MAX = (__ETHTOOL_A_MODULE_FW_FLASH_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps index f4e8eb79c1b8..dbdca32a1c61 100644 --- a/tools/net/ynl/Makefile.deps +++ b/tools/net/ynl/Makefile.deps @@ -16,7 +16,8 @@ get_hdr_inc=-D$(1) -include $(UAPI_PATH)/linux/$(2) CFLAGS_devlink:=$(call get_hdr_inc,_LINUX_DEVLINK_H_,devlink.h) CFLAGS_dpll:=$(call get_hdr_inc,_LINUX_DPLL_H,dpll.h) -CFLAGS_ethtool:=$(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h) +CFLAGS_ethtool:=$(call get_hdr_inc,_LINUX_ETHTOOL_H,ethtool.h) \ + $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h) CFLAGS_handshake:=$(call get_hdr_inc,_LINUX_HANDSHAKE_H,handshake.h) CFLAGS_mptcp_pm:=$(call get_hdr_inc,_LINUX_MPTCP_PM_H,mptcp_pm.h) CFLAGS_netdev:=$(call get_hdr_inc,_LINUX_NETDEV_H,netdev.h) From patchwork Wed Jun 19 12:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703773 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2063.outbound.protection.outlook.com [40.107.102.63]) (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 C5C7714C584; Wed, 19 Jun 2024 12:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799501; cv=fail; b=YI4m1B1TWSnAU9ixN7LCAljpk1QthBLO8iyX2IoTMQ6gfJeGJvXPF7T5RU1j8QRnEBcxHHE6e0RAvDsM0zW2DpD0IlpWCY61p1qO6O1iQksZ1aCAfdiMXn70KlnP8PbaW/D3zUBjMm1zaatnfiI8BnppX/1wFp6DqqQw4Y/v1yY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799501; c=relaxed/simple; bh=vEJ0cHPwb/e+yK8ajINYHlqInwybPhqjO5TOD3lF5Hc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hXHoeIsTtwVpDZTB0ePwm0MdV2FtVm5ppajVROJAeJo4pGeq+TBu8Arly0eG4A93kEN0b2t0DK2JxNxtdgp5KEXvQeioUDvXe8QTR30ZQqPmjCMEjYNoAAaDjUaIlQDVkcdc6gI2eCZqjYPh/AJ/bWBTVHTGAwk6pDEf/dzHiGM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=WsHaaITK; arc=fail smtp.client-ip=40.107.102.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="WsHaaITK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ILv7htKBIErZPgyRc2kVkwWgQAGP41JiDxj5k50ySSdxEYGmpyDNLtY1XC+1QdXnVwksnb0vDBqbeteQHN4SNcIAoGCmBtjEkLVkz26QT6CUDFAOqRL1w2VdKG53zLERmGKNQ9tI8YboXfKaE1VJrgZlhBaSqbmURLLQtIFRkNpJDcIWUMpHkuWsC4n+gF7iGzTshvPHkdvJ4t3YPR6wY3aDjyAjFmC2F4A+MhgdyR+eTXqAo2ugaFkTPDLJpbRBK8SidIkeJBBSJgjlsjdhm3ldJ5HlysNSmIBc2DGYKr8wpZfBuR8nn95tBOh0DsLBtfvMj8ixDT8SdHCcrkVGEw== 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=fH3p/KzwSk9Fu+AWpOXUSDR2tS4/eobAh9DJgknkP4E=; b=MTNKf5K5DdQgFitVmiolSipDt3Oa9wuCZu24F8TQvsJ9KgMovEZqDts3TFrJYl1OL/XInUFjDZ68LJjHvBXfsRax1ez+76i+9dbklEhEARIgr2zqudxvDglOqy3HvXzeIKjRhnF/L+nKMyU81KTx86TYXBoABYERvVCj5kFnljAvCXXKliGYepLIV0DaG1pOwdgfe3Rfa7BRDTW/ribN/B6GX/52/66P4mh91kjlF7gRgPBZt4dz5O1OWmbZRQfXcyizBOUoP37r8PmR/2vsRiQIMGhVMgSUy9D9vss12PQl18P73qXZsvY2t4hBjKCeflNTiel7u+1ozLtTXbuv/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fH3p/KzwSk9Fu+AWpOXUSDR2tS4/eobAh9DJgknkP4E=; b=WsHaaITKZ0RaPPnCewMOUup4GJTxBK4zWACarepwBrTaFqU3O4yMrDOtc+eTzWpRBlbpF18dZcFlXpodQhj7M82U2ZZl0iDZulpm9+fTMwbPGpKKy2CSgHHvg3KkcTwQO5rqghnIjD6WIGPrH+wqEmnIT2XpiDPCPysnXlpuh1pkJcIK/XwaFpNZ63v48oaXRUfIKvU5zj5EhoRrQUMs3JL6fCuku9QzvJuArFiLjLYrDM5IGepFfDfKJMkIwhZfabX+dlnjAsbxZaATz7pMRWzzWbBkY8aRubW8FLtg3BlxZ13xCyX2ouv23+rxZB9fJ/1TfAtTz8AlZXwklMwKFQ== Received: from BYAPR04CA0019.namprd04.prod.outlook.com (2603:10b6:a03:40::32) by PH0PR12MB7862.namprd12.prod.outlook.com (2603:10b6:510:26d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Wed, 19 Jun 2024 12:18:16 +0000 Received: from SJ1PEPF0000231D.namprd03.prod.outlook.com (2603:10b6:a03:40:cafe::af) by BYAPR04CA0019.outlook.office365.com (2603:10b6:a03:40::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.32 via Frontend Transport; Wed, 19 Jun 2024 12:18:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF0000231D.mail.protection.outlook.com (10.167.242.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:10 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:04 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 4/9] ethtool: Add flashing transceiver modules' firmware notifications ability Date: Wed, 19 Jun 2024 15:17:22 +0300 Message-ID: <20240619121727.3643161-5-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231D:EE_|PH0PR12MB7862:EE_ X-MS-Office365-Filtering-Correlation-Id: d4cf7c59-14c8-49c6-e268-08dc9059e5a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|36860700010|7416011|376011|82310400023|1800799021; X-Microsoft-Antispam-Message-Info: kSePOF2oIq5RZjgpLJWDJAgzklrziE4maROSEcfeGO4XtxLylNx1sRfTff/I6siWPpy51AORgWbu5JiKC2lL/Xja8aerbLqKYFLaEjrdm2Kxowe0XSqVakTTdvv+NI/jx7FAFj0kIS8Wfw8onCVE3sAcSBxb0TpYWX8vKwf3nXSoTJtRtSoU3xcBffyKN01n/pMK9fP0dTqWmzJhcoT1YN20sWvk2POgglQEJTOnD7Y6eFqGSnN2AAVuW4iozz4RSh5873qAb4Z9xxBxWlLmJTa5zbAradgXaE0g/3ga8RbUCpNsiLaQaxxQVNzQh9UOK0wDpmefY2/i6JxZcsd8TY7fPGgWnps/kdH9qirWUjt+hG1f8MhsfaVWiv7Dgu/KaUUa0qSD86VWykOox/NJDB49oawS/IgX1tcCPSF1BXBT+u/3N899DU6tx5b91gHSEJ76cFtD8spmRT1NS4EowK/KK3nzCIFpV//Wcb+l7CzWze+AqHnMqc0S2jhH+2BJ7obUxEUO6o+lLJoOfBsR+uxe+o4YIJimIxTsZVDDHIXqVVQ6cVCZB0qRhvDEXoje7fXTDbrDJx+w5JWHTY+Mjjvp5UTo0x+Qtmm4a9bYYWp7VkgJN+UIBSHrD6hEUK8spbPyAXc7j1vUERrqGCsyurzPov3lQrrsVBSqzwAyjar1K+uvLmmUcf+qRjUyz3oOT7UtFoMT3MzRXRbI2z4iBOJsqaPmapIip6nFK6MZml2H4y8kDO0DV2h2CTLM5LfwNCQXCL+R03OYhaG4QDCxZdmXS5VmaVA8aibAQ4A8uzpK3p5n5VIWBg43ptKBaeQxJuuySIVNLU3qJ2obHMNESiCM/OaZ/ITA4fZPF1rRQmIh3CuVuhqCWZbfbukN0RsZPWkdNASmfbYAbKHYPDEocjRBEoDPTsA62VXqOcTVtU7vJIwHhBVQH0JPbyB4ZAbqfck1gibI/rcsUVAPaCOR8MLJ94zc+PpD6kRz93dXc2jqYfABnNb2YObV0DtXcjuGBAA9pp2c2dpv69oQYgmrvE1T5d1wnT+ndPBHcnoFeJivaK1NnG9p1RW7dP1Wx9AyhXMTHrbFYEFX90a4y/rpOxeNeYznsFH09N+Kg93Vj/j0hFDPIwztnOINOyvOMM8ymFEZqzd5VI6LuJhvJkgDiqKh3U8EE2G1dW8497+cMhBuE14TQWemFgdimxs2rd7EuosEOlsaBEWV8cjP629JUjkVVINl0vHK1nbRV91Jl11GlXV8WmkbLyA6b24BMZmHohUkxVP0XQZQI2gaenJ+9IzoB/asvMeNrq3SJkWJbRWQeS+cWaTDZ+8fsk+yjlff+b5oKol+GVSO3V1moAubs5viqNquNq1pP99gUeSL4aD9gtqc7ii0kVpEBliZIJqqLw5wdMts1LE6Ack/CI4LYw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230037)(36860700010)(7416011)(376011)(82310400023)(1800799021);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:15.8757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4cf7c59-14c8-49c6-e268-08dc9059e5a2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7862 X-Patchwork-Delegate: kuba@kernel.org Add progress notifications ability to user space while flashing modules' firmware by implementing the interface between the user space and the kernel. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * Reserve '1' more place on SKB for NUL terminator in the error message string. * Add more prints on error flow, re-write the printing function and add ethnl_module_fw_flash_ntf_put_err(). * Change the communication method so notification will be sent in unicast instead of multicast. * Add new 'struct ethnl_module_fw_flash_ntf_params' that holds the relevant info for unicast communication and use it to send notification to the specific socket. * s/nla_put_u64_64bit/nla_put_uint/ v2: * Increase err_msg length. net/ethtool/module.c | 117 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 31 +++++++++++ net/ethtool/netlink.c | 5 ++ net/ethtool/netlink.h | 1 + 4 files changed, 154 insertions(+) create mode 100644 net/ethtool/module_fw.h diff --git a/net/ethtool/module.c b/net/ethtool/module.c index ceb575efc290..932415bd44c6 100644 --- a/net/ethtool/module.c +++ b/net/ethtool/module.c @@ -5,6 +5,7 @@ #include "netlink.h" #include "common.h" #include "bitset.h" +#include "module_fw.h" struct module_req_info { struct ethnl_req_info base; @@ -158,3 +159,119 @@ const struct ethnl_request_ops ethnl_module_request_ops = { .set = ethnl_set_module, .set_ntf_cmd = ETHTOOL_MSG_MODULE_NTF, }; + +/* MODULE_FW_FLASH_NTF */ + +static int +ethnl_module_fw_flash_ntf_put_err(struct sk_buff *skb, char *err_msg, + char *sub_err_msg) +{ + int err_msg_len, sub_err_msg_len, total_len; + struct nlattr *attr; + + if (!err_msg) + return 0; + + err_msg_len = strlen(err_msg); + total_len = err_msg_len + 2; /* For period and NUL. */ + + if (sub_err_msg) { + sub_err_msg_len = strlen(sub_err_msg); + total_len += sub_err_msg_len + 2; /* For ", ". */ + } + + attr = nla_reserve(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, + total_len); + if (!attr) + return PTR_ERR(attr); + + if (sub_err_msg) + sprintf(nla_data(attr), "%s, %s.", err_msg, sub_err_msg); + else + sprintf(nla_data(attr), "%s.", err_msg); + + return 0; +} + +static void +ethnl_module_fw_flash_ntf(struct net_device *dev, + enum ethtool_module_fw_flash_status status, + struct ethnl_module_fw_flash_ntf_params *ntf_params, + char *err_msg, char *sub_err_msg, + u64 done, u64 total) +{ + struct sk_buff *skb; + void *hdr; + int ret; + + if (ntf_params->closed_sock) + return; + + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb) + return; + + hdr = ethnl_unicast_put(skb, ntf_params->portid, ntf_params->seq, + ETHTOOL_MSG_MODULE_FW_FLASH_NTF); + if (!hdr) + goto err_skb; + + ret = ethnl_fill_reply_header(skb, dev, + ETHTOOL_A_MODULE_FW_FLASH_HEADER); + if (ret < 0) + goto err_skb; + + if (nla_put_u32(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS, status)) + goto err_skb; + + ret = ethnl_module_fw_flash_ntf_put_err(skb, err_msg, sub_err_msg); + if (ret < 0) + goto err_skb; + + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_DONE, done)) + goto err_skb; + + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_TOTAL, total)) + goto err_skb; + + genlmsg_end(skb, hdr); + genlmsg_unicast(dev_net(dev), skb, ntf_params->portid); + return; + +err_skb: + nlmsg_free(skb); +} + +void ethnl_module_fw_flash_ntf_err(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + char *err_msg, char *sub_err_msg) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR, + params, err_msg, sub_err_msg, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_start(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED, + params, NULL, NULL, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_complete(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params) +{ + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED, + params, NULL, NULL, 0, 0); +} + +void +ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + u64 done, u64 total) +{ + ethnl_module_fw_flash_ntf(dev, + ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS, + params, NULL, NULL, done, total); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h new file mode 100644 index 000000000000..ee4a291ac1d4 --- /dev/null +++ b/net/ethtool/module_fw.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +/** + * struct ethnl_module_fw_flash_ntf_params - module firmware flashing + * notifications parameters + * @portid: Netlink portid of sender. + * @seq: Sequence number of sender. + * @closed_sock: Indicates whether the socket was closed from user space. + */ +struct ethnl_module_fw_flash_ntf_params { + u32 portid; + u32 seq; + bool closed_sock; +}; + +void +ethnl_module_fw_flash_ntf_err(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + char *err_msg, char *sub_err_msg); +void +ethnl_module_fw_flash_ntf_start(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params); +void +ethnl_module_fw_flash_ntf_complete(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params); +void +ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *params, + u64 done, u64 total); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index bd04f28d5cf4..393ce668fb04 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -239,6 +239,11 @@ void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) cmd); } +void *ethnl_unicast_put(struct sk_buff *skb, u32 portid, u32 seq, u8 cmd) +{ + return genlmsg_put(skb, portid, seq, ðtool_genl_family, 0, cmd); +} + int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) { return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 9a333a8d04c1..5e6c6a7b7adc 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -21,6 +21,7 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, void **ehdrp); void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd); void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd); +void *ethnl_unicast_put(struct sk_buff *skb, u32 portid, u32 seq, u8 cmd); int ethnl_multicast(struct sk_buff *skb, struct net_device *dev); /** From patchwork Wed Jun 19 12:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703775 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2058.outbound.protection.outlook.com [40.107.94.58]) (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 13309145352; Wed, 19 Jun 2024 12:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799516; cv=fail; b=b8u7v6MHWuX0sLn1mXPPQ/n7JYaYLiOk3D7IEdSe8Gn22eCsGGc+nOgdEuNv955kXgdz2UGMoVbf5Eh+KyVXzvPSwGyTw/QDnWIdMLEKSbUCr4yYDkpc/hkd7zY7B9PF0FUQZ1z676RbV4VPAshj/m6ZUPOxn7FeO46R1llRYMQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799516; c=relaxed/simple; bh=LiM6FI3aPU5AENZAzmZY2RXjQ1QEzSTefeg3Z8ZTYFk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r9blWvlWQ5p0vatn8S7BVA6zNkYZWvc9whrvaltSJniI0Ji/TBKh7H75Jl9Sgc6L7ukSL3FvlDCU2BWKmSgmP09RsWsOby5VWyRRmgi3V7G9TuITQheUQetyv2chbVxD1Fa5hZsdvbklQ1RqB6YzrqSdpJw37r/zI3M+QcqX0bg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=sPw1jV5h; arc=fail smtp.client-ip=40.107.94.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="sPw1jV5h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fxLBH3c/DF6pX7lnQFMD0lRQnzPgIzJsFXxL1LRkuPB4kBtITRLx2SRyKVJDGMZKgfzWpaDDIfgmNbg9malXfQY+zoVzBIkyPA/ayqQcr5DblWxG9fMf0j2tB7O7tW8zHsSF+QUpXrn+dfAUUwpofMATQJ/X6BiDZe4/z2Rs2PY1MU1JYRW16f4zcWAt4FpIchmLzqLlKyPGjJS2sKiFMb1RPWNdNPcUgjfbLKEiHI5tiZLJGEjVhYyJ7PbcpAHXQ1I+6KZ/tpmC++klbCRPwJ2N9bZTwtqkU19mBSkp8jWYp/14D+TGujBNofn4QYOk4g5fMr0ORa0JIW7g/pfkjQ== 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=vqz3R0tPPOWZl/n+Avi0lgJyF400COPcQrtB82HLOys=; b=SsINisZLxl75mcrfvs0SNjWt0sqoa7Q+/edmu8EUyk//OMg1OuQCRzNI2nShbhr9oTZ4vLvjYawrccbbjoaZDBrVp2B2826uy6fRmH4hKs5GcjMVxU+k8Zm6aBf44/NBLbKJgwE7+ov6S5d/60bUByYFc/vmmGiQtFb3qpjIiVh5tB6tcy1RU7xeAOu4URNFUYV55GgWjiwz7mWB8UfKlsSImbkr08So2XbIukqWFbm2HUunW9JqXR4Yfz0M20YB17yPG3S3yLczZjxny+cSqk35aBLgFInbpQOzbBvzOCYWVcPHGaQHkG7CZ3WT++81apSVjzekMn+horhsZJCdog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vqz3R0tPPOWZl/n+Avi0lgJyF400COPcQrtB82HLOys=; b=sPw1jV5hsy00acN0BuWXGRee/nkbKnt/7/S8zLgWBKZPEKZyeB4nGf/S/inJH1EbqZdZ04xZFMc7JcLsoo2SM3+CKwxmiLml1u77T3Rv8EseiEcMVD4LsqW6jzA0ac/rKepUZlOktnFkQr+M7u7w7MPTjLJtUyUE6O0K9ARaWSKTXOxa1jOzV9dSSGksMGd6yu3p/WhnIC3WikIrnBNWikVWocIN82jpKHP+mu08kzV0IJUi3e7Xpe0UrF/9ssE4WoSMO/TJdt5EgRywpLJilhU4gNVTaTxMa0GjfK3vKM8oBteovX5VpQOciK3bpinGhL3g2hGrIU01hIAQh4W7Bw== Received: from BN0PR04CA0052.namprd04.prod.outlook.com (2603:10b6:408:e8::27) by MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Wed, 19 Jun 2024 12:18:30 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:408:e8:cafe::82) by BN0PR04CA0052.outlook.office365.com (2603:10b6:408:e8::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A1.mail.protection.outlook.com (10.167.243.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:30 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:16 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:10 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 5/9] ethtool: Veto some operations during firmware flashing process Date: Wed, 19 Jun 2024 15:17:23 +0300 Message-ID: <20240619121727.3643161-6-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|MN2PR12MB4373:EE_ X-MS-Office365-Filtering-Correlation-Id: 952902d5-2edb-4faf-4d17-08dc9059ee75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|376011|1800799021|82310400023|36860700010; X-Microsoft-Antispam-Message-Info: JI67lGsEOECnGrA7tYU17Vzq+X7vGgtLvHOdcwdP7g64EHowinbxe+C1QmAYRRRPNxvCipL61BvOgKsAPi1db9mJZA+jPLl4OyWnzMILqNwX0lQ/5PnBps8Mu4ZTDG6tfGYTex9TH0EoSvJVzn43T6U5AFWnO00+GrAOUxzizG3ofzifhx3e1Qdk5QsaazPIPXt//ejfUY5/SPUXoqZtce7PFGbs53RTy9TjE1h0LmV4IbtMXQbv95FR+qEnpA7PHkxJGOyt94f1QD31lZtm2pnJQJFhAwYFbV42RIHwlxNMHZ2tnpgcUzfW2GSpzzk74cFccE77R/KvHdLOvgM7RhQtIQv9Z9w9sc453STb7pEDV3aB5dzXMJuQr5VMP8LkItwZ3e8svlfOX1lWedony0f99C1pGUbLhFtH9MSuAdchMAhQTPUofxBooOKXRICgG5AFCVdHTmWrg5iI/F9nsu0+LSoJX2KrdoujNW42QY7vJOVE67pBrXAvAe8UJklpBANBs0YXT+udfMsqhg/wZmAOpOpTrGHrjAV3pmovy2SUfQ4O+buG2T+y13VkpomvkM0YMbq9NzV6pK5Nr8WpdGqSGpTX9ivUwpWcPNWNOyk/1v6hB77djOImHR4A0LjyhBbrE0FeNUaVPo934vAw4cPJnHNSXj4iJEqW31NqIKAssUn4uC2YEjoZEGg0jTgrURAxwvtA1yEwK584AeqdX85gJgrzQUC+aDeEAXcZgydp1i3GI8fLM2/vOR7PtHWcZ7SPYZW4uGRyrgIpnq7jI3PDbp/Nw6NyPZjqAfF1c4O6QgHX3Ok9S98RXzewZQBBZGrpnq3KrdxZcqZ/EVDmEKv864OhnMRH3s27oJ5N+4QAMfW8aGNgb2SxhrA6I696g8hnVn/fKS1226/uY43yupn8IWXTf8xWq0r25Lk0mVZwdltkTSSMeAp/EWOEPwXqaGv8OYYLGezPMHOiGtjV0Lt7E0Jss5xKWatrFFEhH1seQdkBn0/IqWIT89nnA1F/4ucsu5jF4Sx8LjifIoPagJpK03fyD/YTk9RfZMaG2J3rzIwHf3AdRQ6dskE4GTGdUaqgMeTDVgP7AUGOIrYrP5o7u7OeKHX3Eg/X1Q7pfMCoaQU7mixY7kPFLzbe6bXkKLx+2EnMDd4PzB4TIv+Fk4aGBEX0MmIYR+pNojmnrBKMjLFbiNqWxMQC/Kx8vWYZxpBUcEMBoqaw2mbz3A/OOLgjvs3X5SJnz0irDK5lldPYgTv1n8aRNBkjlLAhOTw9jmAXOau/rsKHEa1tkQRt9PNG/R658j+CptBNDf/cc77YaXO8fSCZFXcAj9RJbIhuBo8hfK+AlAr+qKI7F47FhJz9k169vah83Elknvzi4dVRqE1E2I+hs7ZF38Op8QAKd8pjY6F6lccQdSup43NhSQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(7416011)(376011)(1800799021)(82310400023)(36860700010);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:30.4890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 952902d5-2edb-4faf-4d17-08dc9059ee75 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4373 X-Patchwork-Delegate: kuba@kernel.org Some operations cannot be performed during the firmware flashing process. For example: - Port must be down during the whole flashing process to avoid packet loss while committing reset for example. - Writing to EEPROM interrupts the flashing process, so operations like ethtool dump, module reset, get and set power mode should be vetoed. - Split port firmware flashing should be vetoed. In order to veto those scenarios, add a flag in 'struct net_device' that indicates when a firmware flash is taking place on the module and use it to prevent interruptions during the process. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * Squash some of the vetoes from the last patch to this patch. include/linux/netdevice.h | 4 +++- net/ethtool/eeprom.c | 6 ++++++ net/ethtool/ioctl.c | 12 ++++++++++++ net/ethtool/netlink.c | 12 ++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f148a01dd1d1..43ec53fc0128 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1989,6 +1989,8 @@ enum netdev_reg_state { * * @threaded: napi threaded mode is enabled * + * @module_fw_flash_in_progress: Module firmware flashing is in progress. + * * @net_notifier_list: List of per-net netdev notifier block * that follow this device when it is moved * to another network namespace. @@ -2373,7 +2375,7 @@ struct net_device { bool proto_down; bool threaded; unsigned wol_enabled:1; - + unsigned module_fw_flash_in_progress:1; struct list_head net_notifier_list; #if IS_ENABLED(CONFIG_MACSEC) diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c index 6209c3a9c8f7..f36811b3ecf1 100644 --- a/net/ethtool/eeprom.c +++ b/net/ethtool/eeprom.c @@ -91,6 +91,12 @@ static int get_module_eeprom_by_page(struct net_device *dev, { const struct ethtool_ops *ops = dev->ethtool_ops; + if (dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(extack, + "Module firmware flashing is in progress"); + return -EBUSY; + } + if (dev->sfp_bus) return sfp_get_module_eeprom_by_page(dev->sfp_bus, page_data, extack); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index e645d751a5e8..1cca372c0d80 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -658,6 +658,9 @@ static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) if (!dev->ethtool_ops->get_link_ksettings) return -EOPNOTSUPP; + if (dev->module_fw_flash_in_progress) + return -EBUSY; + memset(&link_ksettings, 0, sizeof(link_ksettings)); err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings); if (err < 0) @@ -1449,6 +1452,9 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr) if (!dev->ethtool_ops->reset) return -EOPNOTSUPP; + if (dev->module_fw_flash_in_progress) + return -EBUSY; + if (copy_from_user(&reset, useraddr, sizeof(reset))) return -EFAULT; @@ -2462,6 +2468,9 @@ int ethtool_get_module_info_call(struct net_device *dev, const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; + if (dev->module_fw_flash_in_progress) + return -EBUSY; + if (dev->sfp_bus) return sfp_get_module_info(dev->sfp_bus, modinfo); @@ -2499,6 +2508,9 @@ int ethtool_get_module_eeprom_call(struct net_device *dev, const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; + if (dev->module_fw_flash_in_progress) + return -EBUSY; + if (dev->sfp_bus) return sfp_get_module_eeprom(dev->sfp_bus, ee, data); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 393ce668fb04..a5907bbde427 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -765,10 +765,22 @@ static void ethnl_notify_features(struct netdev_notifier_info *info) static int ethnl_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { + struct netdev_notifier_info *info = ptr; + struct netlink_ext_ack *extack; + struct net_device *dev; + + dev = netdev_notifier_info_to_dev(info); + extack = netdev_notifier_info_to_extack(info); + switch (event) { case NETDEV_FEAT_CHANGE: ethnl_notify_features(ptr); break; + case NETDEV_PRE_UP: + if (dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(extack, "Can't set port up while flashing module firmware"); + return NOTIFY_BAD; + } } return NOTIFY_DONE; From patchwork Wed Jun 19 12:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703776 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) (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 7A7ED15099D; Wed, 19 Jun 2024 12:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799521; cv=fail; b=lbtNpAw42gShiGTCQxMG6WjNjKLRR4lq7zWbT1szzy14/97ZTZWo09XXH5AMoKSSKD47jigBnP0LZWjx1IUz6bBZEfZM+9s5zKlMcMuWvKewt7Xi1Pb+LWrsgurVZoO8uWtGa3ILahswY5Z7H9l5MJYPNMGSTeikz9MZwIjdAlc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799521; c=relaxed/simple; bh=ch0pfnApHsCdyjFizpjfxLpKh7QsAGNl9XyZat8Eg8w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hfWHnQ/st3YO54cZCacKy4fXDCzy9MqULnVpxCDi7Opy98UKedb1s5lroqZo0ndUo8Tk+I9Xq23rtEkYPLQ8liVhHYXbfJlM1FvG8aU6Z5ZzMqnGcOi1LZ5WYv5YkWOPDSxGOniQNfWaqzuT7Qs9jbNZaDMp4/AQDe67OC43LHo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=HC+l0v1j; arc=fail smtp.client-ip=40.107.92.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="HC+l0v1j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FDl8DSq8uQQpGXBzGWKS/Ma1R/ZIjLTjwu9ZbyMEPVs1jsuN4xk13okGAYWNE2YRCBe9NJJpxZm6a+rRPfq41J3h1TYQVgCG2FujHV7lKGC2WhPKWYP+NdxeIQKy0IDsnUqrPBWyfeoVCOMY/5sjaxjUn8s1W5k57kbCI7iU4JPeyRH+v3s0PRfhqTHLo7aS/vePpNsHbu1zsgdSPRtjHwognS/93JgTXLNCttuzVDKhNBAF9NgS4m5FIpXFCQFyTzdFRkgvYT+1pu1RSh1uT3iPmjqPrqPDom17nm9FKQN95DJbCBKkOhtzT2bOnXqWQUANDFuyrfMBkFjnEgBeaw== 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=06WPm5E8GS3BBZLDc7SOcTeDtmfJIjTTCgpSJUVW46g=; b=iewcd5rT07UI2Jh7B0Xo4+csKeFLDeYViAfx32mXSRbLw4MVr0JiQ7exxBcNtCW/k2aTEqBQGkRp9APYgsvKbzOsb2XquXlsctZxgOZQcj0cBv9E50D2dVnG7uQaGW28BuJgejSdw8kH9bE3Pi5eJgJy+SpkmSPqvDbAP/Ngh3HJm8eZWb3Ut4rrYp7CDX0NJOHH0vUIwlSjtXTRnlZe8r4mODM1zs8Eetod/fpLl4omlMr/p6tEiuQ94LXJTzpw09Zc+8kwehAhX0nVq78JlLqCpztPD0C3UGju758wHPnSMvw42tc7f7cUyBpo/XNWUOZjIe2Hv2rVtmlYElOgBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=06WPm5E8GS3BBZLDc7SOcTeDtmfJIjTTCgpSJUVW46g=; b=HC+l0v1jnXP4eNdE2CuhXRDKM5DJ27cPGEOXVEZ7rz1CJ6jQVcYc441V3oxVzduHCJj/crIuE3h4OrwMcpEfumBjOn0OSW95mk7cjupZra87JIkL/zvetgo8NN7igZWzKsT7uFAS4eKRmbm9P/bZiQ9Op2654WSn0jXKtXXR9mJz3PXf0qIqB9fGCixdbeSoK/RoT4Snnd2JdAKa0ni8/yl9g6aJ8K8zFFYyDKU1Njz5OIhRCZs3n/ZQWktPAOIE16jIX8oB4u5ibO8iQ5eN1ZeNbJfKdcnMTVno0OSoXnj7s2I7MOMcdwUBTA5TVzlsRkUgLh4WTu4KLcRuJ+2O4w== Received: from BN9PR03CA0964.namprd03.prod.outlook.com (2603:10b6:408:109::9) by IA1PR12MB8222.namprd12.prod.outlook.com (2603:10b6:208:3f2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Wed, 19 Jun 2024 12:18:37 +0000 Received: from BN2PEPF000044A4.namprd02.prod.outlook.com (2603:10b6:408:109:cafe::81) by BN9PR03CA0964.outlook.office365.com (2603:10b6:408:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A4.mail.protection.outlook.com (10.167.243.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:23 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:16 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 6/9] net: sfp: Add more extended compliance codes Date: Wed, 19 Jun 2024 15:17:24 +0300 Message-ID: <20240619121727.3643161-7-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A4:EE_|IA1PR12MB8222:EE_ X-MS-Office365-Filtering-Correlation-Id: 531f1a59-0229-4780-6bf5-08dc9059f259 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|376011|82310400023|1800799021|36860700010; X-Microsoft-Antispam-Message-Info: joZd1/lIYOVIUKXAfcHNdvnm99IejXhU5gxsZ8gLaebN3wqLhRJd7/BDaR7UjK1w1YMc0DV/rd8AGHtUSetkl6m9/0n8jlwegaFiI93htV2iqcfslT7YUBfowkl1quIP/tF9LDe09k6Pi2+cA1ANxcf0/Y7MHmsT9yUBeiFx58CT3fl82V4Sw7puff5FjBeEGVoouk8Vsh1QYZXySvtb+GlZAtGi2GDvZpLHFCQDn542mrL6r32gHEnYI0WRvCCYzMQMv4qQm79rHGTTGz29o4myRR3IUAKrqefGboPrY8lvK3ZHeBwzWyq7r+ZsLqFX8JHTQhJK51o6OSqap3A+raZs03pKkj1reHLSx58NsPvz5WH/r5YRTIPL1ZJe3SVC6T06z0cV7T6DaZa4JjkwIVD+mEyOCPwrwk7r7yFgXV16J54Ok7yfal76DMTwHYpV8/cuis2phKndyunF6VeIcEEGzjAKpHUT/KBpTMsFcLGAJNfzKEvKqzMPJ3QFyddQuoGjqalxmHjz2ghkzfl+VBZQz5x4AdYp0AFwITf4L7KnsujgHzxQWQQSaBQY01clTvMCrZa5XwjBIcPgTruzdfGpDlAmhQdvspOXI6ZhGFup2bleg/mgEu+EEv77cELycwZ0CS77LA+Fya3hjMGUV4L44QxhcKdkjJ1FqtylNFiMKMqog24HR/TYOgveU7OXq2mqTsTKD5Dn1dxZdctAoBuKXlrbOU8L/M+eDnlOQA3In1GPW6wMo/SXm5UtUuFTr0QjX/XoLp+A3bclaisoLgepf1DgZjWo427HfbQJKabcf6ukR4QxajNAxX3ZnB+JSqL4dqdIFzPvUfLgDfkQ4xVGG+y03NRIi5plGrgeCtPju3iB8sSOoBjgLoLEOlMC6o3ALe9W7MUvnaGhJXQB6pXzNVwaNBzyU31o4dqeis7TsXDwtzSiKtX8IdGvzDYnebVBvsPAYIOs7of6pKV+TKdD390dVOpHGKmH0spefgE85TlB7Mr2057ejSDJs7mQ/qIOWnRXHakfHv1mlB6W1celGA5gepCdmaoyXJXas75bpzRR09O7Wqzf4s2wONMrbboKJWsoe9bNDyN9x7ZQHFBcdu7FJbUZ0YUcOetChcnMJGUPI72SrlQkTaNHwTYlPWyhibIl12Gzlx/KcCYvuviME5VfwH8/MlI6st+Elobi04b9N4n5cQHYYtjgYpvdVEdbMl8QSFpHDNYka3+2JoPnMnQCzzUnCaE2NZEjmEV6WYd5F/ZGHRGBr71osLgMuCO97E8wUtfSau4gwUuU4nBpxArnvuPG/m3W9DBc1r5b0yRbwTcxDOnSA1HUQtdsKjtZmL8z8eRwgKV3BMwOS1NXBFphbPJuRsUHiWY2x5MzJ28SzTkmBFcUMOVCWe83dP3iwuWSrB+y9guwoS72DA== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(7416011)(376011)(82310400023)(1800799021)(36860700010);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:37.0328 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 531f1a59-0229-4780-6bf5-08dc9059f259 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8222 X-Patchwork-Delegate: kuba@kernel.org SFF-8024 is used to define various constants re-used in several SFF SFP-related specifications. Add SFF-8024 extended compliance code definitions for CMIS compliant modules and use them in the next patch to determine the firmware flashing work. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata Reviewed-by: Russell King (Oracle) --- include/linux/sfp.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/sfp.h b/include/linux/sfp.h index a45da7eef9a2..b14be59550e3 100644 --- a/include/linux/sfp.h +++ b/include/linux/sfp.h @@ -284,6 +284,12 @@ enum { SFF8024_ID_QSFP_8438 = 0x0c, SFF8024_ID_QSFP_8436_8636 = 0x0d, SFF8024_ID_QSFP28_8636 = 0x11, + SFF8024_ID_QSFP_DD = 0x18, + SFF8024_ID_OSFP = 0x19, + SFF8024_ID_DSFP = 0x1B, + SFF8024_ID_QSFP_PLUS_CMIS = 0x1E, + SFF8024_ID_SFP_DD_CMIS = 0x1F, + SFF8024_ID_SFP_PLUS_CMIS = 0x20, SFF8024_ENCODING_UNSPEC = 0x00, SFF8024_ENCODING_8B10B = 0x01, From patchwork Wed Jun 19 12:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703777 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2088.outbound.protection.outlook.com [40.107.92.88]) (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 7FC691422C5; Wed, 19 Jun 2024 12:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799530; cv=fail; b=pl/aPzaH0QrH41U19xzdMExDwqryn4UecJhuFqhpH5pfLFk66kS2AEAQSRRP49ncInIY7WadZuY6uqukTkRASczzUnmQpLg8VzWvsk3aifkkTKbcro063GOk9/n2Z7EABcdmO5dwLksxdivVeZIt6/c7eFVQMRj9VChfsRfn2rU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799530; c=relaxed/simple; bh=MEZuAKmWVeQ852kQAkk9TfEnJoz/vR0YOBXHndHudZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jdny2fJ6FerMLlHgCmReVNj0pGdT1jpfbT/2OtDtn9UqLYzNrqqB6yvEJiJh+AhdyApiwuzHvrWrTcaVeUODJbhs43BJcv4i6q53FTUejZungN2+3oC4U1Vzy3q8eh0Q5IsZXAhdwdpkx3WFxf+fgg7x4a2qwUwyIJGHIB95SGc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=DQLEBVN+; arc=fail smtp.client-ip=40.107.92.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="DQLEBVN+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=etIVvktUrX5hoG2KqVHuqeYdN5OCCZAw+9CPgFNUvXl6ZC18jOXoKoZ/dWPfQBzPoR526XeM4P/VwilCTm3HD0A6RfnojUTk2O7sqVuQWyeQ0y68CxL42XU6qwYwRtotkMhuEVfxhOsbZ3nJkVBPcHZAhY+BzcoICEQsNVbyIblGPGwp4vztwHDXYekVRAbZ32i4nGgnmr/2KvCBO3h9ODjDSEz6BcDiewtKrvkaOnhNf0tMVRuf5dmweuhWZwQHSqhuIiYsYk+P0mFD3/YvvZQKyht97PPYt2K7XYj8kwQ9lrVEqCVUyMQHa2UuZyiSwaJCCF3/N2Mq1rTGAraolw== 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=XKIskuL2+9kGuoxfvfJaPCZ2FUsgMCbNT4Bo51GYu/0=; b=Wdt45g6wbg/NZE48Mu/s12J1xhrdGL0BC9uavDNTRktCdZR8TJQOE5AfjfJ1ZZlDLrpPJUhyYXlFh1zdIaJMWCsFC/RA3YdwP+vTupWT2BF/c/HdwnpQ9ByJDuioUd5jya8Ku68OGNfQ5LMSjrmX2FrnkG1ngmXGZjEoMJ3I2s2QAY1hEwd4fYKDAInT6MYQRiXSPDPfXGYvIkqM+PPdiIEZi3h0ToMr1GPGnW9LOLv86SKxJiap2Ufq3HJKWE127K+zhWRaXZbIpPy9vvkIXLcr/Q7hgb0l6sisfGpmHb3Agz128b4/CRPpWv6U2A2EbkDz+9EgmRsPwC+W0b9alQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XKIskuL2+9kGuoxfvfJaPCZ2FUsgMCbNT4Bo51GYu/0=; b=DQLEBVN+y5Q7BpsHvpAv2q+t7k4AfFAMJIFm55MIxN9GGwzD9uZNX8YJAho6n/ys49h6yV8a532wUSM9y1Pz7hAGFnl0mM6TQdTBabRDq6bfjE3wqIb9mHbAfrlbzQJYLvmLNUD5SgfOF48lFriE3l2ogK7kvtBJh/7DtygxN+8P8nhITODwpoErbqxxlp/TMfiM5aUzDyVvx6OwCdQsaXeMOuqWa38fUCb5o2jkNDlY50Iy+ocLO2Qfa/Q2IBZvGYTA11TxbZIkFmCAwnfD0RalfMVVvFetzgCXRVUCA3FYqZOD7Ww/N90UHtMNk7gFZvOyWGZm9/FKDQCYNAoUVA== Received: from SA1PR04CA0006.namprd04.prod.outlook.com (2603:10b6:806:2ce::6) by SA1PR12MB8724.namprd12.prod.outlook.com (2603:10b6:806:38b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Wed, 19 Jun 2024 12:18:41 +0000 Received: from SA2PEPF00001504.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::85) by SA1PR04CA0006.outlook.office365.com (2603:10b6:806:2ce::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SA2PEPF00001504.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:29 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:23 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 7/9] ethtool: cmis_cdb: Add a layer for supporting CDB commands Date: Wed, 19 Jun 2024 15:17:25 +0300 Message-ID: <20240619121727.3643161-8-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001504:EE_|SA1PR12MB8724:EE_ X-MS-Office365-Filtering-Correlation-Id: 52f46cea-9652-4d41-a27e-08dc9059f51f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|82310400023|7416011|376011|36860700010; X-Microsoft-Antispam-Message-Info: WpB/ksrYBUq+nPD64bTvNoqeXncNUWnmQb4W5L2v0o2gEGo9yWmacVzSij+aYPSaIEPnnkoJkvpvdTQBsbCx2kuZGM2768P/zE8eJPVCAxdFHwAnjkHlshrrVaNf1A/bVlShcGfHeza2+eu7eYnHxHYNTsVWDFlXyZQ4Lp0bR4ziyarLHyy/aPnVOkKT6adjQBhGy31lZ5djkcEtOCga3CRWuWc2F7TdjxY6Wb449l9UO5Q403mTFIP1j922joVjJIXPgN9YiSJTO/G7WRc7xtceqgZeLc+KJdOha7n6diFqWybSplNX+iuELisAAat502ouN1LgnecCOyBdNo3c/SqMDLj4C+J+Qv79/bCG/G66R1KNwfMCYnpI5mqcjiUZ/o/2O/3/jeAlSXtKyTR1N/DwcH9ovvLyHcn0zcyvO/0IbD0F+NwpnErQ18PlbOd5hsxA/ECljp5OZZ8VrC2e3btVJF7FUPx0yWAQ0uNwwzSEaU+ESL3kJwd7Ha8gGzGgN1OSHcdViZ9xKDmCYwJS9EF+h47tY6NsvBqhsx6cZ9SAGnvwwZd5A7/zPD5usVho5z7aYDnmdiUhCml9DFoKhW1R0ZeBD7qHl/G7FQTMM8px94aSJzT8imdoZVdaYHb0dYbyRN0VZ9UTUwOSE3T95BWn9d2cnPj/moNdDQm6CQEDEMsU6T017JJKbR964lh+rqJc0mE8yfzGywmoMD1JRmabjUaUOIzJfMAQncng3fMkzALuz4N62K8WI30uJjQagq7pkvE1DZ4bjT202Bo4fBVAhwdfkCQgJN4ZmjUDdj020JRjf7dYC+Jkl/1Ropvk+cLTxS6sWgVETjsGkjqUlWHuR3KjwTn8HEEWl35ZC9Oysx/EJBwoW2pb/9NDpGIHUHuJ2Ynz8dHVptN0rNxhmxQe7mKrU2bq88Dt1FanPSJL2iLwv94FalMm0JHhnazR9FuTb+W/xFMwYzGSBSRMxma8b+KtgYiniqSoxdfRMI77iradHmv4OgAbE+CS/4ig+HKy1ujwCFiepO1ywiPlMDubeeGMI+/U5kubnmkOUtH7j+B05KTjGAx01+DtJQwM83LQ2yfXNJU4zkyJVafU249PbzE5nDAjzkr7XHEBQ390iGewABoCFCSxl8gIAtr6ZhQt+2btvjoBxHgswIlRWjdbsJHWjT/dHXiylDxI/tBjT/Mu4XnqLCMBNk2LMbqgADDGNEs9mTfhwS9tUpNfPCS+ftSKlRf4MYTYvQYiV9YBqOMX57KjoZK9GBSlWmaX6UyJ5uMPNLBqQ+njIT5cRkL+Bqm5Lhwv5e6kLarNBTnAEQpVTiFYt+MDAgluM+y0KUeu+Opy68/BQ/FMJjZrSv+fFy57tzxSik0oZqt9Tq4UhFR4Tl1GD0YQo1e7jhGfjCNajlK2YdVDE64dySLTdA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230037)(1800799021)(82310400023)(7416011)(376011)(36860700010);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:41.7185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52f46cea-9652-4d41-a27e-08dc9059f51f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001504.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8724 X-Patchwork-Delegate: kuba@kernel.org CDB (Command Data Block Message Communication) reads and writes are performed on memory map pages 9Fh-AFh according to the CMIS standard, section 8.20 of revision 5.2. Page 9Fh is used to specify the CDB command to be executed and also provides an area for a local payload (LPL). According to the CMIS standard, the firmware update process is done using a CDB commands sequence that will be implemented in the next patch. The kernel interface that will implement the firmware update using CDB command will include 2 layers that will be added under ethtool: * The upper layer that will be triggered from the module layer, is cmis_fw_update. * The lower one is cmis_cdb. In the future there might be more operations to implement using CDB commands. Therefore, the idea is to keep the CDB interface clean and the cmis_fw_update specific to the CDB commands handling it. These two layers will communicate using the API the consists of three functions: - struct ethtool_cmis_cdb * ethtool_cmis_cdb_init(struct net_device *dev, struct ethtool_module_fw_flash_params *params); - void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb *cdb); - int ethtool_cmis_cdb_execute_cmd(struct net_device *dev, struct ethtool_cmis_cdb_cmd_args *args); Add the CDB layer to support initializing, finishing and executing CDB commands: * The initialization process will include creating of an ethtool_cmis_cdb instance, querying the module CDB support, entering and validating the password from user space (CMD 0x0000) and querying the module features (CMD 0x0040). * The finishing API will simply free the ethtool_cmis_cdb instance. * The executing process will write the CDB command to EEPROM using set_module_eeprom_by_page() that was presented earlier, and will process the reply from EEPROM. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * In ethtool_cmis_cdb_init(), Use 'const' for the params parameter. v5: * Drop all the inline in cmis_cdb.c. v4: * Add kernel-doc for msleep_pre_rpl and err_msg. v3: * Use kmemdup() instead of kmalloc+memcpy. v2: * Define ethtool_cmis_cdb_request::epl_len to be __be16 instead of u16. net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 117 ++++++++ net/ethtool/cmis_cdb.c | 581 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 10 + 4 files changed, 709 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/cmis.h create mode 100644 net/ethtool/cmis_cdb.c diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 504f954a1b28..38806b3ecf83 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -8,4 +8,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \ - module.o pse-pd.o plca.o mm.o + module.o cmis_cdb.o pse-pd.o plca.o mm.o diff --git a/net/ethtool/cmis.h b/net/ethtool/cmis.h new file mode 100644 index 000000000000..295f5d0df915 --- /dev/null +++ b/net/ethtool/cmis.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#define ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH 120 +#define ETHTOOL_CMIS_CDB_CMD_PAGE 0x9F +#define ETHTOOL_CMIS_CDB_PAGE_I2C_ADDR 0x50 + +/** + * struct ethtool_cmis_cdb - CDB commands parameters + * @cmis_rev: CMIS revision major. + * @read_write_len_ext: Allowable additional number of byte octets to the LPL + * in a READ or a WRITE CDB commands. + * @max_completion_time: Maximum CDB command completion time in msec. + */ +struct ethtool_cmis_cdb { + u8 cmis_rev; + u8 read_write_len_ext; + u16 max_completion_time; +}; + +enum ethtool_cmis_cdb_cmd_id { + ETHTOOL_CMIS_CDB_CMD_QUERY_STATUS = 0x0000, + ETHTOOL_CMIS_CDB_CMD_MODULE_FEATURES = 0x0040, +}; + +/** + * struct ethtool_cmis_cdb_request - CDB commands request fields as decribed in + * the CMIS standard + * @id: Command ID. + * @epl_len: EPL memory length. + * @lpl_len: LPL memory length. + * @chk_code: Check code for the previous field and the payload. + * @resv1: Added to match the CMIS standard request continuity. + * @resv2: Added to match the CMIS standard request continuity. + * @payload: Payload for the CDB commands. + */ +struct ethtool_cmis_cdb_request { + __be16 id; + struct_group(body, + __be16 epl_len; + u8 lpl_len; + u8 chk_code; + u8 resv1; + u8 resv2; + u8 payload[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH]; + ); +}; + +#define CDB_F_COMPLETION_VALID BIT(0) +#define CDB_F_STATUS_VALID BIT(1) + +/** + * struct ethtool_cmis_cdb_cmd_args - CDB commands execution arguments + * @req: CDB command fields as described in the CMIS standard. + * @max_duration: Maximum duration time for command completion in msec. + * @read_write_len_ext: Allowable additional number of byte octets to the LPL + * in a READ or a WRITE commands. + * @msleep_pre_rpl: Waiting time before checking reply in msec. + * @rpl_exp_len: Expected reply length in bytes. + * @flags: Validation flags for CDB commands. + * @err_msg: Error message to be sent to user space. + */ +struct ethtool_cmis_cdb_cmd_args { + struct ethtool_cmis_cdb_request req; + u16 max_duration; + u8 read_write_len_ext; + u8 msleep_pre_rpl; + u8 rpl_exp_len; + u8 flags; + char *err_msg; +}; + +/** + * struct ethtool_cmis_cdb_rpl_hdr - CDB commands reply header arguments + * @rpl_len: Reply length. + * @rpl_chk_code: Reply check code. + */ +struct ethtool_cmis_cdb_rpl_hdr { + u8 rpl_len; + u8 rpl_chk_code; +}; + +/** + * struct ethtool_cmis_cdb_rpl - CDB commands reply arguments + * @hdr: CDB commands reply header arguments. + * @payload: Payload for the CDB commands reply. + */ +struct ethtool_cmis_cdb_rpl { + struct ethtool_cmis_cdb_rpl_hdr hdr; + u8 payload[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH]; +}; + +u32 ethtool_cmis_get_max_payload_size(u8 num_of_byte_octs); + +void ethtool_cmis_cdb_compose_args(struct ethtool_cmis_cdb_cmd_args *args, + enum ethtool_cmis_cdb_cmd_id cmd, u8 *pl, + u8 lpl_len, u16 max_duration, + u8 read_write_len_ext, u16 msleep_pre_rpl, + u8 rpl_exp_len, u8 flags); + +void ethtool_cmis_cdb_check_completion_flag(u8 cmis_rev, u8 *flags); + +void ethtool_cmis_page_init(struct ethtool_module_eeprom *page_data, + u8 page, u32 offset, u32 length); +void ethtool_cmis_page_fini(struct ethtool_module_eeprom *page_data); + +struct ethtool_cmis_cdb * +ethtool_cmis_cdb_init(struct net_device *dev, + const struct ethtool_module_fw_flash_params *params, + struct ethnl_module_fw_flash_ntf_params *ntf_params); +void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb *cdb); + +int ethtool_cmis_wait_for_cond(struct net_device *dev, u8 flags, u8 flag, + u16 max_duration, u32 offset, + bool (*cond_success)(u8), bool (*cond_fail)(u8), u8 *state); + +int ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args); diff --git a/net/ethtool/cmis_cdb.c b/net/ethtool/cmis_cdb.c new file mode 100644 index 000000000000..ad7ac41bf679 --- /dev/null +++ b/net/ethtool/cmis_cdb.c @@ -0,0 +1,581 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "common.h" +#include "module_fw.h" +#include "cmis.h" + +/* For accessing the LPL field on page 9Fh, the allowable length extension is + * min(i, 15) byte octets where i specifies the allowable additional number of + * byte octets in a READ or a WRITE. + */ +u32 ethtool_cmis_get_max_payload_size(u8 num_of_byte_octs) +{ + return 8 * (1 + min_t(u8, num_of_byte_octs, 15)); +} + +void ethtool_cmis_cdb_compose_args(struct ethtool_cmis_cdb_cmd_args *args, + enum ethtool_cmis_cdb_cmd_id cmd, u8 *pl, + u8 lpl_len, u16 max_duration, + u8 read_write_len_ext, u16 msleep_pre_rpl, + u8 rpl_exp_len, u8 flags) +{ + args->req.id = cpu_to_be16(cmd); + args->req.lpl_len = lpl_len; + if (pl) + memcpy(args->req.payload, pl, args->req.lpl_len); + + args->max_duration = max_duration; + args->read_write_len_ext = + ethtool_cmis_get_max_payload_size(read_write_len_ext); + args->msleep_pre_rpl = msleep_pre_rpl; + args->rpl_exp_len = rpl_exp_len; + args->flags = flags; + args->err_msg = NULL; +} + +void ethtool_cmis_page_init(struct ethtool_module_eeprom *page_data, + u8 page, u32 offset, u32 length) +{ + page_data->page = page; + page_data->offset = offset; + page_data->length = length; + page_data->i2c_address = ETHTOOL_CMIS_CDB_PAGE_I2C_ADDR; +} + +#define CMIS_REVISION_PAGE 0x00 +#define CMIS_REVISION_OFFSET 0x01 + +struct cmis_rev_rpl { + u8 rev; +}; + +static u8 cmis_rev_rpl_major(struct cmis_rev_rpl *rpl) +{ + return rpl->rev >> 4; +} + +static int cmis_rev_major_get(struct net_device *dev, u8 *rev_major) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {0}; + struct netlink_ext_ack extack = {}; + struct cmis_rev_rpl rpl = {}; + int err; + + ethtool_cmis_page_init(&page_data, CMIS_REVISION_PAGE, + CMIS_REVISION_OFFSET, sizeof(rpl)); + page_data.data = (u8 *)&rpl; + + err = ops->get_module_eeprom_by_page(dev, &page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + return err; + } + + *rev_major = cmis_rev_rpl_major(&rpl); + + return 0; +} + +#define CMIS_CDB_ADVERTISEMENT_PAGE 0x01 +#define CMIS_CDB_ADVERTISEMENT_OFFSET 0xA3 + +/* Based on section 8.4.11 "CDB Messaging Support Advertisement" in CMIS + * standard revision 5.2. + */ +struct cmis_cdb_advert_rpl { + u8 inst_supported; + u8 read_write_len_ext; + u8 resv1; + u8 resv2; +}; + +static u8 cmis_cdb_advert_rpl_inst_supported(struct cmis_cdb_advert_rpl *rpl) +{ + return rpl->inst_supported >> 6; +} + +static int cmis_cdb_advertisement_get(struct ethtool_cmis_cdb *cdb, + struct net_device *dev) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {}; + struct cmis_cdb_advert_rpl rpl = {}; + struct netlink_ext_ack extack = {}; + int err; + + ethtool_cmis_page_init(&page_data, CMIS_CDB_ADVERTISEMENT_PAGE, + CMIS_CDB_ADVERTISEMENT_OFFSET, sizeof(rpl)); + page_data.data = (u8 *)&rpl; + + err = ops->get_module_eeprom_by_page(dev, &page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + return err; + } + + if (!cmis_cdb_advert_rpl_inst_supported(&rpl)) + return -EOPNOTSUPP; + + cdb->read_write_len_ext = rpl.read_write_len_ext; + + return 0; +} + +#define CMIS_PASSWORD_ENTRY_PAGE 0x00 +#define CMIS_PASSWORD_ENTRY_OFFSET 0x7A + +struct cmis_password_entry_pl { + __be32 password; +}; + +/* See section 9.3.1 "CMD 0000h: Query Status" in CMIS standard revision 5.2. + * struct cmis_cdb_query_status_pl and struct cmis_cdb_query_status_rpl are + * structured layouts of the flat arrays, + * struct ethtool_cmis_cdb_request::payload and + * struct ethtool_cmis_cdb_rpl::payload respectively. + */ +struct cmis_cdb_query_status_pl { + u16 response_delay; +}; + +struct cmis_cdb_query_status_rpl { + u8 length; + u8 status; +}; + +static int +cmis_cdb_validate_password(struct ethtool_cmis_cdb *cdb, + struct net_device *dev, + const struct ethtool_module_fw_flash_params *params, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct cmis_cdb_query_status_pl qs_pl = {0}; + struct ethtool_module_eeprom page_data = {}; + struct ethtool_cmis_cdb_cmd_args args = {}; + struct cmis_password_entry_pl pe_pl = {}; + struct cmis_cdb_query_status_rpl *rpl; + struct netlink_ext_ack extack = {}; + int err; + + ethtool_cmis_page_init(&page_data, CMIS_PASSWORD_ENTRY_PAGE, + CMIS_PASSWORD_ENTRY_OFFSET, sizeof(pe_pl)); + page_data.data = (u8 *)&pe_pl; + + pe_pl = *((struct cmis_password_entry_pl *)page_data.data); + pe_pl.password = params->password; + err = ops->set_module_eeprom_by_page(dev, &page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + return err; + } + + ethtool_cmis_cdb_compose_args(&args, ETHTOOL_CMIS_CDB_CMD_QUERY_STATUS, + (u8 *)&qs_pl, sizeof(qs_pl), 0, + cdb->read_write_len_ext, 1000, + sizeof(*rpl), + CDB_F_COMPLETION_VALID | CDB_F_STATUS_VALID); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Query Status command failed", + args.err_msg); + return err; + } + + rpl = (struct cmis_cdb_query_status_rpl *)args.req.payload; + if (!rpl->length || !rpl->status) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Password was not accepted", + NULL); + return -EINVAL; + } + + return 0; +} + +/* Some CDB commands asserts the CDB completion flag only from CMIS + * revision 5. Therefore, check the relevant validity flag only when + * the revision supports it. + */ +void ethtool_cmis_cdb_check_completion_flag(u8 cmis_rev, u8 *flags) +{ + *flags |= cmis_rev >= 5 ? CDB_F_COMPLETION_VALID : 0; +} + +#define CMIS_CDB_MODULE_FEATURES_RESV_DATA 34 + +/* See section 9.4.1 "CMD 0040h: Module Features" in CMIS standard revision 5.2. + * struct cmis_cdb_module_features_rpl is structured layout of the flat + * array, ethtool_cmis_cdb_rpl::payload. + */ +struct cmis_cdb_module_features_rpl { + u8 resv1[CMIS_CDB_MODULE_FEATURES_RESV_DATA]; + __be16 max_completion_time; +}; + +static u16 +cmis_cdb_module_features_completion_time(struct cmis_cdb_module_features_rpl *rpl) +{ + return be16_to_cpu(rpl->max_completion_time); +} + +static int cmis_cdb_module_features_get(struct ethtool_cmis_cdb *cdb, + struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb_cmd_args args = {}; + struct cmis_cdb_module_features_rpl *rpl; + u8 flags = CDB_F_STATUS_VALID; + int err; + + ethtool_cmis_cdb_check_completion_flag(cdb->cmis_rev, &flags); + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_MODULE_FEATURES, + NULL, 0, 0, cdb->read_write_len_ext, + 1000, sizeof(*rpl), flags); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Module Features command failed", + args.err_msg); + return err; + } + + rpl = (struct cmis_cdb_module_features_rpl *)args.req.payload; + cdb->max_completion_time = + cmis_cdb_module_features_completion_time(rpl); + + return 0; +} + +struct ethtool_cmis_cdb * +ethtool_cmis_cdb_init(struct net_device *dev, + const struct ethtool_module_fw_flash_params *params, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb *cdb; + int err; + + cdb = kzalloc(sizeof(*cdb), GFP_KERNEL); + if (!cdb) + return ERR_PTR(-ENOMEM); + + err = cmis_rev_major_get(dev, &cdb->cmis_rev); + if (err < 0) + goto err; + + if (cdb->cmis_rev < 4) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "CMIS revision doesn't support module firmware flashing", + NULL); + err = -EOPNOTSUPP; + goto err; + } + + err = cmis_cdb_advertisement_get(cdb, dev); + if (err < 0) + goto err; + + if (params->password_valid) { + err = cmis_cdb_validate_password(cdb, dev, params, ntf_params); + if (err < 0) + goto err; + } + + err = cmis_cdb_module_features_get(cdb, dev, ntf_params); + if (err < 0) + goto err; + + return cdb; + +err: + ethtool_cmis_cdb_fini(cdb); + return ERR_PTR(err); +} + +void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb *cdb) +{ + kfree(cdb); +} + +static bool is_completed(u8 data) +{ + return !!(data & 0x40); +} + +#define CMIS_CDB_STATUS_SUCCESS 0x01 + +static bool status_success(u8 data) +{ + return data == CMIS_CDB_STATUS_SUCCESS; +} + +#define CMIS_CDB_STATUS_FAIL 0x40 + +static bool status_fail(u8 data) +{ + return data & CMIS_CDB_STATUS_FAIL; +} + +struct cmis_wait_for_cond_rpl { + u8 state; +}; + +int ethtool_cmis_wait_for_cond(struct net_device *dev, u8 flags, u8 flag, + u16 max_duration, u32 offset, + bool (*cond_success)(u8), bool (*cond_fail)(u8), + u8 *state) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {0}; + struct cmis_wait_for_cond_rpl rpl = {}; + struct netlink_ext_ack extack = {}; + unsigned long end; + int err; + + if (!(flags & flag)) + return 0; + + if (max_duration == 0) + max_duration = U16_MAX; + + end = jiffies + msecs_to_jiffies(max_duration); + do { + ethtool_cmis_page_init(&page_data, 0, offset, sizeof(rpl)); + page_data.data = (u8 *)&rpl; + + err = ops->get_module_eeprom_by_page(dev, &page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + continue; + } + + if ((*cond_success)(rpl.state)) + return 0; + + if (*cond_fail && (*cond_fail)(rpl.state)) + break; + + msleep(20); + } while (time_before(jiffies, end)); + + *state = rpl.state; + return -EBUSY; +} + +#define CMIS_CDB_COMPLETION_FLAG_OFFSET 0x08 + +static int cmis_cdb_wait_for_completion(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 flag; + int err; + + /* Some vendors demand waiting time before checking completion flag + * in some CDB commands. + */ + msleep(args->msleep_pre_rpl); + + err = ethtool_cmis_wait_for_cond(dev, args->flags, + CDB_F_COMPLETION_VALID, + args->max_duration, + CMIS_CDB_COMPLETION_FLAG_OFFSET, + is_completed, NULL, &flag); + if (err < 0) + args->err_msg = "Completion Flag did not set on time"; + + return err; +} + +#define CMIS_CDB_STATUS_OFFSET 0x25 + +static void cmis_cdb_status_fail_msg_get(u8 status, char **err_msg) +{ + switch (status) { + case 0b10000001: + *err_msg = "CDB Status is in progress: Busy capturing command"; + break; + case 0b10000010: + *err_msg = + "CDB Status is in progress: Busy checking/validating command"; + break; + case 0b10000011: + *err_msg = "CDB Status is in progress: Busy executing"; + break; + case 0b01000000: + *err_msg = "CDB status failed: no specific failure"; + break; + case 0b01000010: + *err_msg = + "CDB status failed: Parameter range error or parameter not supported"; + break; + case 0b01000101: + *err_msg = "CDB status failed: CdbChkCode error"; + break; + default: + *err_msg = "Unknown failure reason"; + } +}; + +static int cmis_cdb_wait_for_status(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 status; + int err; + + /* Some vendors demand waiting time before checking status in some + * CDB commands. + */ + msleep(args->msleep_pre_rpl); + + err = ethtool_cmis_wait_for_cond(dev, args->flags, CDB_F_STATUS_VALID, + args->max_duration, + CMIS_CDB_STATUS_OFFSET, + status_success, status_fail, &status); + if (err < 0 && !args->err_msg) + cmis_cdb_status_fail_msg_get(status, &args->err_msg); + + return err; +} + +#define CMIS_CDB_REPLY_OFFSET 0x86 + +static int cmis_cdb_process_reply(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + struct ethtool_cmis_cdb_cmd_args *args) +{ + u8 rpl_hdr_len = sizeof(struct ethtool_cmis_cdb_rpl_hdr); + u8 rpl_exp_len = args->rpl_exp_len + rpl_hdr_len; + const struct ethtool_ops *ops = dev->ethtool_ops; + struct netlink_ext_ack extack = {}; + struct ethtool_cmis_cdb_rpl *rpl; + int err; + + if (!args->rpl_exp_len) + return 0; + + ethtool_cmis_page_init(page_data, ETHTOOL_CMIS_CDB_CMD_PAGE, + CMIS_CDB_REPLY_OFFSET, rpl_exp_len); + page_data->data = kmalloc(page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + err = ops->get_module_eeprom_by_page(dev, page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + goto out; + } + + rpl = (struct ethtool_cmis_cdb_rpl *)page_data->data; + if ((args->rpl_exp_len > rpl->hdr.rpl_len + rpl_hdr_len) || + !rpl->hdr.rpl_chk_code) { + err = -EIO; + goto out; + } + + args->req.lpl_len = rpl->hdr.rpl_len; + memcpy(args->req.payload, rpl->payload, args->req.lpl_len); + +out: + kfree(page_data->data); + return err; +} + +static int +__ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_module_eeprom *page_data, + u8 page, u32 offset, u32 length, void *data) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct netlink_ext_ack extack = {}; + int err; + + ethtool_cmis_page_init(page_data, page, offset, length); + page_data->data = kmemdup(data, page_data->length, GFP_KERNEL); + if (!page_data->data) + return -ENOMEM; + + err = ops->set_module_eeprom_by_page(dev, page_data, &extack); + if (err < 0) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + } + + kfree(page_data->data); + return err; +} + +static u8 cmis_cdb_calc_checksum(const void *data, size_t size) +{ + const u8 *bytes = (const u8 *)data; + u8 checksum = 0; + + for (size_t i = 0; i < size; i++) + checksum += bytes[i]; + + return ~checksum; +} + +#define CMIS_CDB_CMD_ID_OFFSET 0x80 + +int ethtool_cmis_cdb_execute_cmd(struct net_device *dev, + struct ethtool_cmis_cdb_cmd_args *args) +{ + struct ethtool_module_eeprom page_data = {}; + u32 offset; + int err; + + args->req.chk_code = + cmis_cdb_calc_checksum(&args->req, sizeof(args->req)); + + if (args->req.lpl_len > args->read_write_len_ext) { + args->err_msg = "LPL length is longer than CDB read write length extension allows"; + return -EINVAL; + } + + /* According to the CMIS standard, there are two options to trigger the + * CDB commands. The default option is triggering the command by writing + * the CMDID bytes. Therefore, the command will be split to 2 calls: + * First, with everything except the CMDID field and then the CMDID + * field. + */ + offset = CMIS_CDB_CMD_ID_OFFSET + + offsetof(struct ethtool_cmis_cdb_request, body); + err = __ethtool_cmis_cdb_execute_cmd(dev, &page_data, + ETHTOOL_CMIS_CDB_CMD_PAGE, offset, + sizeof(args->req.body), + &args->req.body); + if (err < 0) + return err; + + offset = CMIS_CDB_CMD_ID_OFFSET + + offsetof(struct ethtool_cmis_cdb_request, id); + err = __ethtool_cmis_cdb_execute_cmd(dev, &page_data, + ETHTOOL_CMIS_CDB_CMD_PAGE, offset, + sizeof(args->req.id), + &args->req.id); + if (err < 0) + return err; + + err = cmis_cdb_wait_for_completion(dev, args); + if (err < 0) + return err; + + err = cmis_cdb_wait_for_status(dev, args); + if (err < 0) + return err; + + return cmis_cdb_process_reply(dev, &page_data, args); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index ee4a291ac1d4..6c86d05ab6cf 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -15,6 +15,16 @@ struct ethnl_module_fw_flash_ntf_params { bool closed_sock; }; +/** + * struct ethtool_module_fw_flash_params - module firmware flashing parameters + * @password: Module password. Only valid when @pass_valid is set. + * @password_valid: Whether the module password is valid or not. + */ +struct ethtool_module_fw_flash_params { + __be32 password; + u8 password_valid:1; +}; + void ethnl_module_fw_flash_ntf_err(struct net_device *dev, struct ethnl_module_fw_flash_ntf_params *params, From patchwork Wed Jun 19 12:17:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703778 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2073.outbound.protection.outlook.com [40.107.236.73]) (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 DE667152526; Wed, 19 Jun 2024 12:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799541; cv=fail; b=OiSIV//acDu7siw2e3MED1zGCdupgxvtu+Lkf6x85P3QanzrbIT+9HU5EgK8w5Y3eRYNmcJru7zt1iaL8QsFShBlp+seygZvZCVn5sOXkGXp5iSE7nLElVlnr+FjQR9E+LfBdtTg34UvqNNMT9ROs5CcXNGlFJSBSYm7ZAY8AI0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799541; c=relaxed/simple; bh=RqZrtF9hzPPydnCat2CKUJoLjAR3aJkQL8WArZqek3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dtPZ3a8ZVYZDfMDZ2/y+wT7yTiMVbZVhw0GI/wTmgnyPuw/v7/T/KaOm8B3VjoK4HItnib0GfJofZ/u2mgbuOUd4/1EugWba5xhidv24A2qeiLoCfiiQ/TJAGUqMPCWSyDVDbovPYUekbTPNWvsKuIP4KulIhlQXul8cBAI5QfU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gQnLB8BS; arc=fail smtp.client-ip=40.107.236.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gQnLB8BS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hOYeK/TIHqZrBymcqoK2TNcjuUjIcdmCJc4KJM4s0/Tpj8acrhAeukvXyGMewNMnEZXqW82SDBm5/xOxcWaj10Q2dgbIHwqH84pWfE24U5NkvEpxykkRnB6dcQk0npExa/5GQIOveuump9bwIEuFLKtQ7g9s93vJCwCrtxHDlNkp5dEohylPJUTt62JU7eIR7mKHczJaNhNKcn9fR+yb2dm2jx0g9BT7+5eQe9Jc6pKv74/NZ4i0QB0fmLf3/s047TL77q+FYmeFgW/xd4BfDA1Ljj8j7bXsAYq1R8vmiUk525us9e7zAuKK5+ArQdHRSCyXMqsyTDyhKHe6/0T63g== 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=q4khK5DkuVZdWTbZsjigRzdxqODND9aPqXhMDUBlsPI=; b=ay1BlaMDNAVfSbnH6RyUCCzyfZE4wFht9mZbecjMBg3MGD2MdY2BN+cMcnYkZMXe5exPJZtAaPeB8TnBg4NgnqAYBud50HyKrpThG2LhoxrRgwyrcqV+sfn8n3vENO3rCRFqEqZimis8hY9llqTlonFCjlHbvfrg0UveHRtvZGKnWQS4yjIDm7P6CJr5LdavJryPyDWz5BI6XfW6Ew0br9VJdOYBYj/HP6gQLgkl7n5ZrR4wDr8L/n7lELC4+4YFidHNQavMQuCKe2AIpWRW4yXfAI2uSYfsbXIp6B2gAg9AcBhw95MIzq+fc+hkV1ECHGnNXsWGyP8/8BK6eYimiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q4khK5DkuVZdWTbZsjigRzdxqODND9aPqXhMDUBlsPI=; b=gQnLB8BSSOiLC9LmoLO32ko51vPHz0aqlVs3G3uLky9ZdzT8IF4gb+mH7LUlYfTMiGcwtYzoTbQXbj4SPnFo2wdlBPiD0iFbEeVo7ngMNpNx4nPh7sV6dPskM7B5BVEFS4zR8suNhKpIHFZupOqJlbRKbWNN1FfftMuSHgXcQsMQJUhkCVWrKn66NFPFZoVnsAAcBeCgLsn+a0/SK6M1pzJNFmoXPRqZnaI/cJ5CR0L9u21GA96+W/teB03Nb0mvQwj7wsGLQ8sSbNE2dKOoO4vvy9TauFCvfhxCYO4ShfyLLTLX1ir+Q5Z/P8qP7ZPRnR+h1LljwfriPg1ePAZMFA== Received: from BN0PR04CA0051.namprd04.prod.outlook.com (2603:10b6:408:e8::26) by MW4PR12MB6850.namprd12.prod.outlook.com (2603:10b6:303:1ed::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.29; Wed, 19 Jun 2024 12:18:52 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:408:e8:cafe::a) by BN0PR04CA0051.outlook.office365.com (2603:10b6:408:e8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Wed, 19 Jun 2024 12:18:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A1.mail.protection.outlook.com (10.167.243.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:51 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:35 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:29 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 8/9] ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB Date: Wed, 19 Jun 2024 15:17:26 +0300 Message-ID: <20240619121727.3643161-9-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|MW4PR12MB6850:EE_ X-MS-Office365-Filtering-Correlation-Id: 15f1ba26-f2f8-42d9-6c99-08dc9059fb1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|36860700010|1800799021|82310400023; X-Microsoft-Antispam-Message-Info: 77tLiLWvVLtcd1SVg7ko5nf/ZWCZDwKNXw0tsjDJT7mDhaZlF7Up7AEaiaD4tJe2zusn1AsFMTKbXLuyFCpksGfixwk5veWBpYvZpCMUjoMvf1BWcRfY1Hn1u1aU3l6+BiN7JNrDE402cV/D1idnwDoryB8Znw+pv0ByPHx6pORBVaI3cQmv4I93JMBcVTW6WXj4427e5WgPB7UNtx+AsqDOnrDIefw7wAHN4L+OI/NnKguEgj38p65lDlmCOp4+Gvu//wxue/aghcbmnk2WeVi1Q54PwT2Wu4fOhsa73QxdCoJWvJNUnY3ZstT0xL8eKrvz+MsEazBUTTYRUwn8AU8gSlcdp5gDnOWYewuIwmPGYgdZsfuqEIYE79dWg7u8ziffkaoOUqTZs+BCZl8vXldUzImtkyc575WeHUuDKRNIeuR/k6Kbbj0iv7ugSjoL0YMHD9GJ2KG1I+ieM7tbIrzM/1yj+4gEgO1kHADvFsFElRp/OqyLmSe5g8JB1ZhSJ+CJw0X20Xiew2oYdRx8tc5ghCLZH1rxYpUXHHRyDvqZGZfKLR2JM4cBThkUIXqVJaMedhhDVsciHqvaGPYbTeDM1wm3+j1PfVsd2AOQ8qx3JQT3od7J1WNurTS2cH+HqWvrn32qhKAaeP7J8Q1QUvLMv7vXWQ4/tyBpbI+0FNFbsklVUCabX7RpuhE6MZaA8E+WnrjiJ7tl2l2JOXzZ8YxRsXJTq0CvsqoApo5br/3CD+EWQPQlVdWi08NxuITVjlPlGA+0Ah1QGOOrHEsgLNjdQxSyzuV7z1IwhM6UNX3oCdu5xBO5Q1OSxv+XXVlCQSHLALcTRPzMIIWNOOE5ZeP+xlVEjDfjaVVn4WpFeDTTrieQco5S2TwSCk1i1y+Ryt4iF98rDPlsg3fxnfOe0uy4i/Dhkta+NxuWVSXM557B9OFZhWJyNDVNVyN+nvFJp9ESWu9fHjEIWoZiF6i8Re+bSuN/dsKkwsX05oncym+FDEDl5BSBLjupwFfHjHsxbctwysVvXJQWf8tlL/vB6cpwXvGfcWDJiqgj61+NQ+hbs90HMbeIsh31W/F2lhLlEalk3Sed2HMTXC6nPrKqLCYF5L6EKQVTDXgbq8czn2LoqxuuKGsbzvN/ZoK9tM/8V9ppkaHAE7Rr4+NEiO0DZLgo0Rl7E7Zbd5INBjcgIALqjHBz3zWCuJbQtjTketOHEU/ODo+B9L5678ecE1Q0t+VHrDl4IpxOmTPlTbOfNy5uVPljRah67VEXmO4xlG7ga9GUjpjTtIzreQ3ujiN3pP67VeGeXnae1lghHMC1/UDgLWBNCiUUxoFfuSXkLic21LkJ+6VVUi+LKkEqbRRp8Zp/igKyQyNMCd/5v5JVRaFcg+LciBZWOYElzS6+9AQZvfUI8CszkFgiLeem/+y26g== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(376011)(7416011)(36860700010)(1800799021)(82310400023);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:51.7078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15f1ba26-f2f8-42d9-6c99-08dc9059fb1d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6850 X-Patchwork-Delegate: kuba@kernel.org According to the CMIS standard, the firmware update process is done using a CDB commands sequence. Implement a work that will be triggered from the module layer in the next patch the will initiate and execute all the CDB commands in order, to eventually complete the firmware update process. This flashing process includes, writing the firmware image, running the new firmware image and committing it after testing, so that it will run upon reset. This work will also notify user space about the progress of the firmware update process. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * Add a list field to struct ethtool_module_fw_flash for module_fw_flash_work_list that will be presented in the next patch. * Move ethtool_cmis_fw_update() cleaning to a new function that will be represented in the next patch. * Move some of the fields in struct ethtool_module_fw_flash to a separate struct, so ethtool_cmis_fw_update() will get only the relevant parameters for it. * Edit the relevant functions to get the relevant params for them. * s/CMIS_MODULE_READY_MAX_DURATION_USEC/CMIS_MODULE_READY_MAX_DURATION_MSEC. v2: * Decrease msleep before querying completion flag in Write FW Image command. * Change the condition for failing when LPL is not supported. * Re-write cmis_fw_update_write_image(). net/ethtool/Makefile | 2 +- net/ethtool/cmis.h | 7 + net/ethtool/cmis_fw_update.c | 399 +++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 31 +++ 4 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/cmis_fw_update.c diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 38806b3ecf83..9a190635fe95 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -8,4 +8,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \ - module.o cmis_cdb.o pse-pd.o plca.o mm.o + module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o diff --git a/net/ethtool/cmis.h b/net/ethtool/cmis.h index 295f5d0df915..e71cc3e1b7eb 100644 --- a/net/ethtool/cmis.h +++ b/net/ethtool/cmis.h @@ -20,6 +20,12 @@ struct ethtool_cmis_cdb { enum ethtool_cmis_cdb_cmd_id { ETHTOOL_CMIS_CDB_CMD_QUERY_STATUS = 0x0000, ETHTOOL_CMIS_CDB_CMD_MODULE_FEATURES = 0x0040, + ETHTOOL_CMIS_CDB_CMD_FW_MANAGMENT_FEATURES = 0x0041, + ETHTOOL_CMIS_CDB_CMD_START_FW_DOWNLOAD = 0x0101, + ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_LPL = 0x0103, + ETHTOOL_CMIS_CDB_CMD_COMPLETE_FW_DOWNLOAD = 0x0107, + ETHTOOL_CMIS_CDB_CMD_RUN_FW_IMAGE = 0x0109, + ETHTOOL_CMIS_CDB_CMD_COMMIT_FW_IMAGE = 0x010A, }; /** @@ -47,6 +53,7 @@ struct ethtool_cmis_cdb_request { #define CDB_F_COMPLETION_VALID BIT(0) #define CDB_F_STATUS_VALID BIT(1) +#define CDB_F_MODULE_STATE_VALID BIT(2) /** * struct ethtool_cmis_cdb_cmd_args - CDB commands execution arguments diff --git a/net/ethtool/cmis_fw_update.c b/net/ethtool/cmis_fw_update.c new file mode 100644 index 000000000000..ae4b4b28a601 --- /dev/null +++ b/net/ethtool/cmis_fw_update.c @@ -0,0 +1,399 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "common.h" +#include "module_fw.h" +#include "cmis.h" + +struct cmis_fw_update_fw_mng_features { + u8 start_cmd_payload_size; + u16 max_duration_start; + u16 max_duration_write; + u16 max_duration_complete; +}; + +/* See section 9.4.2 "CMD 0041h: Firmware Management Features" in CMIS standard + * revision 5.2. + * struct cmis_cdb_fw_mng_features_rpl is a structured layout of the flat + * array, ethtool_cmis_cdb_rpl::payload. + */ +struct cmis_cdb_fw_mng_features_rpl { + u8 resv1; + u8 resv2; + u8 start_cmd_payload_size; + u8 resv3; + u8 read_write_len_ext; + u8 write_mechanism; + u8 resv4; + u8 resv5; + __be16 max_duration_start; + __be16 resv6; + __be16 max_duration_write; + __be16 max_duration_complete; + __be16 resv7; +}; + +#define CMIS_CDB_FW_WRITE_MECHANISM_LPL 0x01 + +static int +cmis_fw_update_fw_mng_features_get(struct ethtool_cmis_cdb *cdb, + struct net_device *dev, + struct cmis_fw_update_fw_mng_features *fw_mng, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb_cmd_args args = {}; + struct cmis_cdb_fw_mng_features_rpl *rpl; + u8 flags = CDB_F_STATUS_VALID; + int err; + + ethtool_cmis_cdb_check_completion_flag(cdb->cmis_rev, &flags); + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_FW_MANAGMENT_FEATURES, + NULL, 0, cdb->max_completion_time, + cdb->read_write_len_ext, 1000, + sizeof(*rpl), flags); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "FW Management Features command failed", + args.err_msg); + return err; + } + + rpl = (struct cmis_cdb_fw_mng_features_rpl *)args.req.payload; + if (!(rpl->write_mechanism == CMIS_CDB_FW_WRITE_MECHANISM_LPL)) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Write LPL is not supported", + NULL); + return -EOPNOTSUPP; + } + + /* Above, we used read_write_len_ext that we got from CDB + * advertisement. Update it with the value that we got from module + * features query, which is specific for Firmware Management Commands + * (IDs 0100h-01FFh). + */ + cdb->read_write_len_ext = rpl->read_write_len_ext; + fw_mng->start_cmd_payload_size = rpl->start_cmd_payload_size; + fw_mng->max_duration_start = be16_to_cpu(rpl->max_duration_start); + fw_mng->max_duration_write = be16_to_cpu(rpl->max_duration_write); + fw_mng->max_duration_complete = be16_to_cpu(rpl->max_duration_complete); + + return 0; +} + +/* See section 9.7.2 "CMD 0101h: Start Firmware Download" in CMIS standard + * revision 5.2. + * struct cmis_cdb_start_fw_download_pl is a structured layout of the + * flat array, ethtool_cmis_cdb_request::payload. + */ +struct cmis_cdb_start_fw_download_pl { + __struct_group(cmis_cdb_start_fw_download_pl_h, head, /* no attrs */, + __be32 image_size; + __be32 resv1; + ); + u8 vendor_data[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH - + sizeof(struct cmis_cdb_start_fw_download_pl_h)]; +}; + +static int +cmis_fw_update_start_download(struct ethtool_cmis_cdb *cdb, + struct ethtool_cmis_fw_update_params *fw_update, + struct cmis_fw_update_fw_mng_features *fw_mng) +{ + u8 vendor_data_size = fw_mng->start_cmd_payload_size; + struct cmis_cdb_start_fw_download_pl pl = {}; + struct ethtool_cmis_cdb_cmd_args args = {}; + u8 lpl_len; + int err; + + pl.image_size = cpu_to_be32(fw_update->fw->size); + memcpy(pl.vendor_data, fw_update->fw->data, vendor_data_size); + + lpl_len = offsetof(struct cmis_cdb_start_fw_download_pl, + vendor_data[vendor_data_size]); + + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_START_FW_DOWNLOAD, + (u8 *)&pl, lpl_len, + fw_mng->max_duration_start, + cdb->read_write_len_ext, 1000, 0, + CDB_F_COMPLETION_VALID | CDB_F_STATUS_VALID); + + err = ethtool_cmis_cdb_execute_cmd(fw_update->dev, &args); + if (err < 0) + ethnl_module_fw_flash_ntf_err(fw_update->dev, + &fw_update->ntf_params, + "Start FW download command failed", + args.err_msg); + + return err; +} + +/* See section 9.7.4 "CMD 0103h: Write Firmware Block LPL" in CMIS standard + * revision 5.2. + * struct cmis_cdb_write_fw_block_lpl_pl is a structured layout of the + * flat array, ethtool_cmis_cdb_request::payload. + */ +struct cmis_cdb_write_fw_block_lpl_pl { + __be32 block_address; + u8 fw_block[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH - sizeof(__be32)]; +}; + +static int +cmis_fw_update_write_image(struct ethtool_cmis_cdb *cdb, + struct ethtool_cmis_fw_update_params *fw_update, + struct cmis_fw_update_fw_mng_features *fw_mng) +{ + u8 start = fw_mng->start_cmd_payload_size; + u32 offset, max_block_size, max_lpl_len; + u32 image_size = fw_update->fw->size; + int err; + + max_lpl_len = min_t(u32, + ethtool_cmis_get_max_payload_size(cdb->read_write_len_ext), + ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH); + max_block_size = + max_lpl_len - sizeof_field(struct cmis_cdb_write_fw_block_lpl_pl, + block_address); + + for (offset = start; offset < image_size; offset += max_block_size) { + struct cmis_cdb_write_fw_block_lpl_pl pl = { + .block_address = cpu_to_be32(offset - start), + }; + struct ethtool_cmis_cdb_cmd_args args = {}; + u32 block_size, lpl_len; + + ethnl_module_fw_flash_ntf_in_progress(fw_update->dev, + &fw_update->ntf_params, + offset - start, + image_size); + block_size = min_t(u32, max_block_size, image_size - offset); + memcpy(pl.fw_block, &fw_update->fw->data[offset], block_size); + lpl_len = block_size + + sizeof_field(struct cmis_cdb_write_fw_block_lpl_pl, + block_address); + + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_LPL, + (u8 *)&pl, lpl_len, + fw_mng->max_duration_write, + cdb->read_write_len_ext, 1, 0, + CDB_F_COMPLETION_VALID | CDB_F_STATUS_VALID); + + err = ethtool_cmis_cdb_execute_cmd(fw_update->dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(fw_update->dev, + &fw_update->ntf_params, + "Write FW block LPL command failed", + args.err_msg); + return err; + } + } + + return 0; +} + +static int +cmis_fw_update_complete_download(struct ethtool_cmis_cdb *cdb, + struct net_device *dev, + struct cmis_fw_update_fw_mng_features *fw_mng, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb_cmd_args args = {}; + int err; + + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_COMPLETE_FW_DOWNLOAD, + NULL, 0, fw_mng->max_duration_complete, + cdb->read_write_len_ext, 1000, 0, + CDB_F_COMPLETION_VALID | CDB_F_STATUS_VALID); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Complete FW download command failed", + args.err_msg); + + return err; +} + +static int +cmis_fw_update_download_image(struct ethtool_cmis_cdb *cdb, + struct ethtool_cmis_fw_update_params *fw_update, + struct cmis_fw_update_fw_mng_features *fw_mng) +{ + int err; + + err = cmis_fw_update_start_download(cdb, fw_update, fw_mng); + if (err < 0) + return err; + + err = cmis_fw_update_write_image(cdb, fw_update, fw_mng); + if (err < 0) + return err; + + err = cmis_fw_update_complete_download(cdb, fw_update->dev, fw_mng, + &fw_update->ntf_params); + if (err < 0) + return err; + + return 0; +} + +enum { + CMIS_MODULE_LOW_PWR = 1, + CMIS_MODULE_READY = 3, +}; + +static bool module_is_ready(u8 data) +{ + u8 state = (data >> 1) & 7; + + return state == CMIS_MODULE_READY || state == CMIS_MODULE_LOW_PWR; +} + +#define CMIS_MODULE_READY_MAX_DURATION_MSEC 1000 +#define CMIS_MODULE_STATE_OFFSET 3 + +static int +cmis_fw_update_wait_for_module_state(struct net_device *dev, u8 flags) +{ + u8 state; + + return ethtool_cmis_wait_for_cond(dev, flags, CDB_F_MODULE_STATE_VALID, + CMIS_MODULE_READY_MAX_DURATION_MSEC, + CMIS_MODULE_STATE_OFFSET, + module_is_ready, NULL, &state); +} + +/* See section 9.7.10 "CMD 0109h: Run Firmware Image" in CMIS standard + * revision 5.2. + * struct cmis_cdb_run_fw_image_pl is a structured layout of the flat + * array, ethtool_cmis_cdb_request::payload. + */ +struct cmis_cdb_run_fw_image_pl { + u8 resv1; + u8 image_to_run; + u16 delay_to_reset; +}; + +static int +cmis_fw_update_run_image(struct ethtool_cmis_cdb *cdb, struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb_cmd_args args = {}; + struct cmis_cdb_run_fw_image_pl pl = {0}; + int err; + + ethtool_cmis_cdb_compose_args(&args, ETHTOOL_CMIS_CDB_CMD_RUN_FW_IMAGE, + (u8 *)&pl, sizeof(pl), + cdb->max_completion_time, + cdb->read_write_len_ext, 1000, 0, + CDB_F_MODULE_STATE_VALID); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) { + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Run image command failed", + args.err_msg); + return err; + } + + err = cmis_fw_update_wait_for_module_state(dev, args.flags); + if (err < 0) + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Module is not ready on time after reset", + NULL); + + return err; +} + +static int +cmis_fw_update_commit_image(struct ethtool_cmis_cdb *cdb, + struct net_device *dev, + struct ethnl_module_fw_flash_ntf_params *ntf_params) +{ + struct ethtool_cmis_cdb_cmd_args args = {}; + int err; + + ethtool_cmis_cdb_compose_args(&args, + ETHTOOL_CMIS_CDB_CMD_COMMIT_FW_IMAGE, + NULL, 0, cdb->max_completion_time, + cdb->read_write_len_ext, 1000, 0, + CDB_F_COMPLETION_VALID | CDB_F_STATUS_VALID); + + err = ethtool_cmis_cdb_execute_cmd(dev, &args); + if (err < 0) + ethnl_module_fw_flash_ntf_err(dev, ntf_params, + "Commit image command failed", + args.err_msg); + + return err; +} + +static int cmis_fw_update_reset(struct net_device *dev) +{ + __u32 reset_data = ETH_RESET_PHY; + + return dev->ethtool_ops->reset(dev, &reset_data); +} + +void +ethtool_cmis_fw_update(struct ethtool_cmis_fw_update_params *fw_update) +{ + struct ethnl_module_fw_flash_ntf_params *ntf_params = + &fw_update->ntf_params; + struct cmis_fw_update_fw_mng_features fw_mng = {0}; + struct net_device *dev = fw_update->dev; + struct ethtool_cmis_cdb *cdb; + int err; + + cdb = ethtool_cmis_cdb_init(dev, &fw_update->params, ntf_params); + if (IS_ERR(cdb)) + goto err_send_ntf; + + ethnl_module_fw_flash_ntf_start(dev, ntf_params); + + err = cmis_fw_update_fw_mng_features_get(cdb, dev, &fw_mng, ntf_params); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_download_image(cdb, fw_update, &fw_mng); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_run_image(cdb, dev, ntf_params); + if (err < 0) + goto err_cdb_fini; + + /* The CDB command "Run Firmware Image" resets the firmware, so the new + * one might have different settings. + * Free the old CDB instance, and init a new one. + */ + ethtool_cmis_cdb_fini(cdb); + + cdb = ethtool_cmis_cdb_init(dev, &fw_update->params, ntf_params); + if (IS_ERR(cdb)) + goto err_send_ntf; + + err = cmis_fw_update_commit_image(cdb, dev, ntf_params); + if (err < 0) + goto err_cdb_fini; + + err = cmis_fw_update_reset(dev); + if (err < 0) + goto err_cdb_fini; + + ethnl_module_fw_flash_ntf_complete(dev, ntf_params); + ethtool_cmis_cdb_fini(cdb); + return; + +err_cdb_fini: + ethtool_cmis_cdb_fini(cdb); +err_send_ntf: + ethnl_module_fw_flash_ntf_err(dev, ntf_params, NULL, NULL); +} diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index 6c86d05ab6cf..d0fc2529b60e 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -25,6 +25,35 @@ struct ethtool_module_fw_flash_params { u8 password_valid:1; }; +/** + * struct ethtool_cmis_fw_update_params - CMIS firmware update specific + * parameters + * @dev: Pointer to the net_device to be flashed. + * @params: Module firmware flashing parameters. + * @ntf_params: Module firmware flashing notification parameters. + * @fw: Firmware to flash. + */ +struct ethtool_cmis_fw_update_params { + struct net_device *dev; + struct ethtool_module_fw_flash_params params; + struct ethnl_module_fw_flash_ntf_params ntf_params; + const struct firmware *fw; +}; + +/** + * struct ethtool_module_fw_flash - module firmware flashing + * @list: List node for &module_fw_flash_work_list. + * @dev_tracker: Refcount tracker for @dev. + * @work: The flashing firmware work. + * @fw_update: CMIS firmware update specific parameters. + */ +struct ethtool_module_fw_flash { + struct list_head list; + netdevice_tracker dev_tracker; + struct work_struct work; + struct ethtool_cmis_fw_update_params fw_update; +}; + void ethnl_module_fw_flash_ntf_err(struct net_device *dev, struct ethnl_module_fw_flash_ntf_params *params, @@ -39,3 +68,5 @@ void ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, struct ethnl_module_fw_flash_ntf_params *params, u64 done, u64 total); + +void ethtool_cmis_fw_update(struct ethtool_cmis_fw_update_params *params); From patchwork Wed Jun 19 12:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13703779 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) (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 40F14152792; Wed, 19 Jun 2024 12:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799548; cv=fail; b=LuCtnLx/0xOqSJS4UAaTwT9DCqdH58oC9q9gui3igrbOxni2I+wW4XRLELulyNidFRFqB5FfkGCcmZ7hh4Ew1Rw2q8zuIrIp6rZ+G3fsQHbW/Syjq7/Cd6fXxAkeQw6Z3j7ySiOSm1/2ucNtrSLVijrsIE2TmXasWyPFU8QZaAY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718799548; c=relaxed/simple; bh=uoXpX6tRkz6V1Wn2AJoaLhCvHbSgnM2LWXXfd+Jj6Ec=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=chrrsoH4YgzbztV5TsSoj6aUGJto1OyOTfmmOFBzC2WQhiGrp6MIp5BJ2mE5iZvvlQDxO4k/fRBN8OTTTCfgLPgOhFNW1ag4qp5zsfQmSSY02Ibvt0v5Sai+9W++ibq+T/+wMiYx5FvQVxsWvJhb5RBmE1rwkOZfyQbZhE0QGCc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=pZzPJHCV; arc=fail smtp.client-ip=40.107.94.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="pZzPJHCV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lKE6gXz6wlLJHpoX3o9itAEqc1KAtuuI8UeCBaIDUux+cVdA3W4kkC0AsEFbPJpDgQMRyTHo37kfAvv28ehKv2Ig7FJtbmZEin2V9P+ZbEyV3vzsLYMbzkOdiEbwhNIq4Ah/YfQO8NpL2CM4vZdIrCYHRAZUeUQY2NDU3V4CMVfzVVmYWvWeK+Xy/Yrojj9fyRmCDa/Fzrs45bviiYvUO4J0uX14MWT8PCrDKcQ3DYAy2OvV7OBoTgMxCpy8OmRoKOi9KLAdV7JOTLR1q6M5wty20dYh3oHAZi66wv7UYIF0dcCoz9HZlhOmfWul0hdgsVzsuLaIHZsrTSIIgaYdLw== 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=tkjEu4Z8QFvXfS4DKt+D6mUYKtVVG+CCr21CCkHvvhk=; b=Tqk0anyTvUerdwYDVuEZabGJS8lkBWrAzwBCwpv68pzs4uroZQAdt7/yRO7C2SHG8CX6D/WzlQAiNiRnHXSu7WrHa+kR9LqBZTvs0UmhXosL4Y/hwnCmWJDb505TSlME+A+FADRKnW+a/buLWBVVcZMPDc3kvWQRWidsBj8UBPAX6durnwEyazEm/TEUOscDKEP+f/QZvd9qGwQ1hIRPH5Q6aNNB2ScnH3xxaUNleazoCIu+I9BcIHLYi7Q2CKNtH4+xU3DJToo81SDktcEa7oTWkazG/gJIG0zzKnuKdOifA3Xe87qv5c/ghVKyhX7bKIKyGdjz6SZgaplKGQkBmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tkjEu4Z8QFvXfS4DKt+D6mUYKtVVG+CCr21CCkHvvhk=; b=pZzPJHCVLXBXUkEISqAW0FGyN99llpj4Vi8PN69ffgbwC9kFsIiapFA5nP5t8WvNS6/bYKLIRXvyGfspjhjmAEnNxP15u4zPSkTX0lZm13KDhNowGhY7c8AIDqwc10/AIjPywuz81A6peWON8svj+BNa1/8ktpv3CRl2dDQeZeGAOKmivmpj0d/iFE45oY4gePA2rM1dHplQfGANLi/pGW8dNU5nKpKLYsR1VBBlqDO55FEL+4xco5T8khwxh/rNZAd5CDZ5+Y0LhwDf/SkK5uz5+d4i8R9cNxAsBALw6p+klaiCDKNqKosJ8YERb7ffqvkNx3g2Fl39A6qRqvVeoQ== Received: from BN0PR04CA0064.namprd04.prod.outlook.com (2603:10b6:408:ea::9) by IA1PR12MB6434.namprd12.prod.outlook.com (2603:10b6:208:3ae::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Wed, 19 Jun 2024 12:18:57 +0000 Received: from BN2PEPF000044A3.namprd02.prod.outlook.com (2603:10b6:408:ea:cafe::27) by BN0PR04CA0064.outlook.office365.com (2603:10b6:408:ea::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.32 via Frontend Transport; Wed, 19 Jun 2024 12:18:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A3.mail.protection.outlook.com (10.167.243.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 19 Jun 2024 12:18:57 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:41 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 19 Jun 2024 05:18:35 -0700 From: Danielle Ratson To: CC: , , , , , , , , , , , , , , , , , , , , , Danielle Ratson Subject: [PATCH net-next v6 9/9] ethtool: Add ability to flash transceiver modules' firmware Date: Wed, 19 Jun 2024 15:17:27 +0300 Message-ID: <20240619121727.3643161-10-danieller@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240619121727.3643161-1-danieller@nvidia.com> References: <20240619121727.3643161-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A3:EE_|IA1PR12MB6434:EE_ X-MS-Office365-Filtering-Correlation-Id: 235fe76d-01a3-4a21-ef64-08dc9059fe8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|376011|1800799021|82310400023|36860700010; X-Microsoft-Antispam-Message-Info: qNLeY+9MRKnRaXHTBPeDfSHQ7GB+50zYYkQeuBh8PaJGyhknFPLwVWd3tRl56b+qzEk/AO+BF04EG349RZb7hZf5f1la8WNq4TGmBm8mJGY1joZ6aQy0g6j6dxkYiUEab98gOBidpDt9IEnXR1usg8FyzuHDGQ41WesXwH0GykZugPy/JX0o9uOGKUBhwrOTEDmew6mMhOZlkPFKIXCtRHmn6e9do/pfKXX9HAX54PTI1zKdyFC4wTcrs2o9Bx8YGBoPutBnf5KP81s3SzJrxQ6PDJ08occGZjPPQwAZS1a3Cr5i60B6bZuaGXoFRE0XaQ8E+1RPpW8B8692zoyT0fIl51NxVJlVYVJa/1hHR09wg8matMqxdIUGmnGxU0NBlJWl9yZGS5tY2JidvpxTs9IpzPrGdJOToZ2s9j1tshgPybr0Rfy3wWqVIBFd8amGKL2iIehRfjbDWHR3IJNYoWp9LvzhpvHCMHMsrXgniPDIcq/sl8ryUj3Z1Z4szv4wsvDPAMuQBPCRhW5j3gDM6sLJp8Hw6HH9V4EuK7HcASDeCo1joctqSJ/Ncj6saaaPOmVmwio0RKi7MyG2xKyACOzeLCi3tnpCInlcOU+yRe+oL8WAB4qok4cyeTXyL3yfeSZ1nHEiCBeCndGlxWNrpgFyfxk1mOWPvKiNcdAfpVlddrHjRFH4BSwTRbSF1HzErxWhXHGXf/fealw3nmBXV+6frfGX7dfby3U7rm7uxjk25BC+uCpk89UeDdfWfhxlOsFLODrXME5vEogCSvONBnZVZWJMTQQqXCeER2dMiqxwk0FiK/7QxkjOvvx29AX4GiH7VoKacY7QHt8B3v72yuKsq52/ekAN7asr135fr0FBx3wucKjKhgHtbYywDEuKWLbhBRX44i+oi9+rGbiDTS1NA92wwVgaCC4upZ6K8vRGTQYQpGr6M8CIwGyjJr1u0RjL6HDM6lk/h0fcIajGGU9anzc2wLl9mgbkABIaf902osht2fw88IEFHmORk9wD8nfrEB/e5giFoGq+3MnkIrPdVjATEfQD0fmDb+PeRp7uUlMLpICZ1exD8QktmgwsalY1/eAXF4sccHhqHrpw6hbVoqYYl2Hfa17cZA/UVC5/uXgolwxPk29b2pfXkQOoaP/a5HLjj1uMn2ql6RmVzNIbo5seodtJ1JhDvh29fvU4hGuBRx4H+u1pGB/X5NqUwpXKLxie4hn+d3WL+RAWgegHSFYE4PJgDTYuUAz/Dp7Tn5W3OJ+tAwK+n+W/939+TtMpE7AlT2FeGiDTje0kP+wKq0aO4bh0mkS8K4Kw6NRdY8IzjXyicZYIoEdAAq+og7+Sry9/tFr+Y+P1NV44oSapG7Lkv85l+S+cz9yKmcDemAAhpFUtmTNOn48q73DnCn/VywA7pXvyBmREUuUnlQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(7416011)(376011)(1800799021)(82310400023)(36860700010);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2024 12:18:57.4899 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 235fe76d-01a3-4a21-ef64-08dc9059fe8a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A3.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6434 X-Patchwork-Delegate: kuba@kernel.org Add the ability to flash the modules' firmware by implementing the interface between the user space and the kernel. Example from a succeeding implementation: # ethtool --flash-module-firmware swp40 file test.bin Transceiver module firmware flashing started for device swp40 Transceiver module firmware flashing in progress for device swp40 Progress: 99% Transceiver module firmware flashing completed for device swp40 In addition, add infrastructure that allows modules to set socket-specific private data. This ensures that when a socket is closed from user space during the flashing process, the right socket halts sending notifications to user space until the work item is completed. Signed-off-by: Danielle Ratson Reviewed-by: Petr Machata --- Notes: v6: * Add a paragraph in the commit message. * Rename labels in module_flash_fw_schedule(). * Add info to genl_sk_priv_*() and implement the relevant callbacks, in order to handle properly a scenario of closing the socket from user space before the work item was ended. * Add a list the holds all the ethtool_module_fw_flash struct that corresponds to the in progress work items. * Add a new enum for the socket types. * Use both above to identify a flashing socket, add it to the list and when closing socket affect only the flashing type. * Create a new function that will get the work item instead of ethtool_cmis_fw_update(). * Edit the relevant functions to get the relevant params for them. * The new function will call the old ethtool_cmis_fw_update(), and do the cleaning, so the existence of the list should be completely isolated in module.c. net/ethtool/module.c | 275 ++++++++++++++++++++++++++++++++++++++++ net/ethtool/module_fw.h | 3 + net/ethtool/netlink.c | 38 ++++++ net/ethtool/netlink.h | 15 +++ 4 files changed, 331 insertions(+) diff --git a/net/ethtool/module.c b/net/ethtool/module.c index 932415bd44c6..7e4ea0596508 100644 --- a/net/ethtool/module.c +++ b/net/ethtool/module.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include +#include +#include #include "netlink.h" #include "common.h" @@ -34,6 +37,12 @@ static int module_get_power_mode(struct net_device *dev, if (!ops->get_module_power_mode) return 0; + if (dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(extack, + "Module firmware flashing is in progress"); + return -EBUSY; + } + return ops->get_module_power_mode(dev, &data->power, extack); } @@ -110,6 +119,12 @@ ethnl_set_module_validate(struct ethnl_req_info *req_info, if (!tb[ETHTOOL_A_MODULE_POWER_MODE_POLICY]) return 0; + if (req_info->dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(info->extack, + "Module firmware flashing is in progress"); + return -EBUSY; + } + if (!ops->get_module_power_mode || !ops->set_module_power_mode) { NL_SET_ERR_MSG_ATTR(info->extack, tb[ETHTOOL_A_MODULE_POWER_MODE_POLICY], @@ -160,6 +175,266 @@ const struct ethnl_request_ops ethnl_module_request_ops = { .set_ntf_cmd = ETHTOOL_MSG_MODULE_NTF, }; +/* MODULE_FW_FLASH_ACT */ + +const struct nla_policy +ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1] = { + [ETHTOOL_A_MODULE_FW_FLASH_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME] = { .type = NLA_NUL_STRING }, + [ETHTOOL_A_MODULE_FW_FLASH_PASSWORD] = { .type = NLA_U32 }, +}; + +static LIST_HEAD(module_fw_flash_work_list); +static DEFINE_SPINLOCK(module_fw_flash_work_list_lock); + +static int +module_flash_fw_work_list_add(struct ethtool_module_fw_flash *module_fw, + struct genl_info *info) +{ + struct ethtool_module_fw_flash *work; + + /* First, check if already registered. */ + spin_lock(&module_fw_flash_work_list_lock); + list_for_each_entry(work, &module_fw_flash_work_list, list) { + if (work->fw_update.ntf_params.portid == info->snd_portid && + work->fw_update.dev == module_fw->fw_update.dev) + return -EALREADY; + } + + list_add_tail(&module_fw->list, &module_fw_flash_work_list); + spin_unlock(&module_fw_flash_work_list_lock); + + return 0; +} + +static void module_flash_fw_work_list_del(struct list_head *list) +{ + spin_lock(&module_fw_flash_work_list_lock); + list_del(list); + spin_unlock(&module_fw_flash_work_list_lock); +} + +static void module_flash_fw_work(struct work_struct *work) +{ + struct ethtool_module_fw_flash *module_fw; + + module_fw = container_of(work, struct ethtool_module_fw_flash, work); + + ethtool_cmis_fw_update(&module_fw->fw_update); + + module_flash_fw_work_list_del(&module_fw->list); + module_fw->fw_update.dev->module_fw_flash_in_progress = false; + netdev_put(module_fw->fw_update.dev, &module_fw->dev_tracker); + release_firmware(module_fw->fw_update.fw); + kfree(module_fw); +} + +#define MODULE_EEPROM_PHYS_ID_PAGE 0 +#define MODULE_EEPROM_PHYS_ID_I2C_ADDR 0x50 + +static int module_flash_fw_work_init(struct ethtool_module_fw_flash *module_fw, + struct net_device *dev, + struct netlink_ext_ack *extack) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_module_eeprom page_data = {}; + u8 phys_id; + int err; + + /* Fetch the SFF-8024 Identifier Value. For all supported standards, it + * is located at I2C address 0x50, byte 0. See section 4.1 in SFF-8024, + * revision 4.9. + */ + page_data.page = MODULE_EEPROM_PHYS_ID_PAGE; + page_data.offset = SFP_PHYS_ID; + page_data.length = sizeof(phys_id); + page_data.i2c_address = MODULE_EEPROM_PHYS_ID_I2C_ADDR; + page_data.data = &phys_id; + + err = ops->get_module_eeprom_by_page(dev, &page_data, extack); + if (err < 0) + return err; + + switch (phys_id) { + case SFF8024_ID_QSFP_DD: + case SFF8024_ID_OSFP: + case SFF8024_ID_DSFP: + case SFF8024_ID_QSFP_PLUS_CMIS: + case SFF8024_ID_SFP_DD_CMIS: + case SFF8024_ID_SFP_PLUS_CMIS: + INIT_WORK(&module_fw->work, module_flash_fw_work); + break; + default: + NL_SET_ERR_MSG(extack, + "Module type does not support firmware flashing"); + return -EOPNOTSUPP; + } + + return 0; +} + +void ethnl_module_fw_flash_sock_destroy(struct ethnl_sock_priv *sk_priv) +{ + struct ethtool_module_fw_flash *work; + + spin_lock(&module_fw_flash_work_list_lock); + list_for_each_entry(work, &module_fw_flash_work_list, list) { + if (work->fw_update.dev == sk_priv->dev && + work->fw_update.ntf_params.portid == sk_priv->portid) { + work->fw_update.ntf_params.closed_sock = true; + break; + } + } + spin_unlock(&module_fw_flash_work_list_lock); +} + +static int +module_flash_fw_schedule(struct net_device *dev, const char *file_name, + struct ethtool_module_fw_flash_params *params, + struct sk_buff *skb, struct genl_info *info) +{ + struct ethtool_cmis_fw_update_params *fw_update; + struct ethtool_module_fw_flash *module_fw; + int err; + + module_fw = kzalloc(sizeof(*module_fw), GFP_KERNEL); + if (!module_fw) + return -ENOMEM; + + fw_update = &module_fw->fw_update; + fw_update->params = *params; + err = request_firmware_direct(&fw_update->fw, + file_name, &dev->dev); + if (err) { + NL_SET_ERR_MSG(info->extack, + "Failed to request module firmware image"); + goto err_free; + } + + err = module_flash_fw_work_init(module_fw, dev, info->extack); + if (err < 0) + goto err_release_firmware; + + dev->module_fw_flash_in_progress = true; + netdev_hold(dev, &module_fw->dev_tracker, GFP_KERNEL); + fw_update->dev = dev; + fw_update->ntf_params.portid = info->snd_portid; + fw_update->ntf_params.seq = info->snd_seq; + fw_update->ntf_params.closed_sock = false; + + err = ethnl_sock_priv_set(skb, dev, fw_update->ntf_params.portid, + ETHTOOL_SOCK_TYPE_MODULE_FW_FLASH); + if (err < 0) + goto err_release_firmware; + + err = module_flash_fw_work_list_add(module_fw, info); + if (err < 0) + goto err_release_firmware; + + schedule_work(&module_fw->work); + + return 0; + +err_release_firmware: + release_firmware(fw_update->fw); +err_free: + kfree(module_fw); + return err; +} + +static int module_flash_fw(struct net_device *dev, struct nlattr **tb, + struct sk_buff *skb, struct genl_info *info) +{ + struct ethtool_module_fw_flash_params params = {}; + const char *file_name; + struct nlattr *attr; + + if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME)) + return -EINVAL; + + file_name = nla_data(tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]); + + attr = tb[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD]; + if (attr) { + params.password = cpu_to_be32(nla_get_u32(attr)); + params.password_valid = true; + } + + return module_flash_fw_schedule(dev, file_name, ¶ms, skb, info); +} + +static int ethnl_module_fw_flash_validate(struct net_device *dev, + struct netlink_ext_ack *extack) +{ + struct devlink_port *devlink_port = dev->devlink_port; + const struct ethtool_ops *ops = dev->ethtool_ops; + + if (!ops->set_module_eeprom_by_page || + !ops->get_module_eeprom_by_page) { + NL_SET_ERR_MSG(extack, + "Flashing module firmware is not supported by this device"); + return -EOPNOTSUPP; + } + + if (!ops->reset) { + NL_SET_ERR_MSG(extack, + "Reset module is not supported by this device, so flashing is not permitted"); + return -EOPNOTSUPP; + } + + if (dev->module_fw_flash_in_progress) { + NL_SET_ERR_MSG(extack, "Module firmware flashing already in progress"); + return -EBUSY; + } + + if (dev->flags & IFF_UP) { + NL_SET_ERR_MSG(extack, "Netdevice is up, so flashing is not permitted"); + return -EBUSY; + } + + if (devlink_port && devlink_port->attrs.split) { + NL_SET_ERR_MSG(extack, "Can't perform firmware flashing on a split port"); + return -EOPNOTSUPP; + } + + return 0; +} + +int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info) +{ + struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; + struct net_device *dev; + int ret; + + ret = ethnl_parse_header_dev_get(&req_info, + tb[ETHTOOL_A_MODULE_FW_FLASH_HEADER], + genl_info_net(info), info->extack, + true); + if (ret < 0) + return ret; + dev = req_info.dev; + + rtnl_lock(); + ret = ethnl_ops_begin(dev); + if (ret < 0) + goto out_rtnl; + + ret = ethnl_module_fw_flash_validate(dev, info->extack); + if (ret < 0) + goto out_rtnl; + + ret = module_flash_fw(dev, tb, skb, info); + + ethnl_ops_complete(dev); + +out_rtnl: + rtnl_unlock(); + ethnl_parse_header_dev_put(&req_info); + return ret; +} + /* MODULE_FW_FLASH_NTF */ static int diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h index d0fc2529b60e..634543a12d0c 100644 --- a/net/ethtool/module_fw.h +++ b/net/ethtool/module_fw.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include "netlink.h" /** * struct ethnl_module_fw_flash_ntf_params - module firmware flashing @@ -54,6 +55,8 @@ struct ethtool_module_fw_flash { struct ethtool_cmis_fw_update_params fw_update; }; +void ethnl_module_fw_flash_sock_destroy(struct ethnl_sock_priv *sk_priv); + void ethnl_module_fw_flash_ntf_err(struct net_device *dev, struct ethnl_module_fw_flash_ntf_params *params, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index a5907bbde427..a5e6f341e4b9 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -4,6 +4,7 @@ #include #include #include "netlink.h" +#include "module_fw.h" static struct genl_family ethtool_genl_family; @@ -30,6 +31,34 @@ const struct nla_policy ethnl_header_policy_stats[] = { ETHTOOL_FLAGS_STATS), }; +int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, u32 portid, + enum ethnl_sock_type type) +{ + struct ethnl_sock_priv *sk_priv; + + sk_priv = genl_sk_priv_get(ðtool_genl_family, NETLINK_CB(skb).sk); + if (IS_ERR(sk_priv)) + return PTR_ERR(sk_priv); + + sk_priv->dev = dev; + sk_priv->portid = portid; + sk_priv->type = type; + + return 0; +} + +static void ethnl_sock_priv_destroy(void *priv) +{ + struct ethnl_sock_priv *sk_priv = priv; + + switch (sk_priv->type) { + case ETHTOOL_SOCK_TYPE_MODULE_FW_FLASH: + ethnl_module_fw_flash_sock_destroy(sk_priv); + default: + break; + } +} + int ethnl_ops_begin(struct net_device *dev) { int ret; @@ -1142,6 +1171,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_mm_set_policy, .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_MODULE_FW_FLASH_ACT, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_act_module_fw_flash, + .policy = ethnl_module_fw_flash_act_policy, + .maxattr = ARRAY_SIZE(ethnl_module_fw_flash_act_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { @@ -1158,6 +1194,8 @@ static struct genl_family ethtool_genl_family __ro_after_init = { .resv_start_op = ETHTOOL_MSG_MODULE_GET + 1, .mcgrps = ethtool_nl_mcgrps, .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), + .sock_priv_size = sizeof(struct ethnl_sock_priv), + .sock_priv_destroy = ethnl_sock_priv_destroy, }; /* module setup */ diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 5e6c6a7b7adc..46ec273a87c5 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -284,6 +284,19 @@ struct ethnl_reply_data { int ethnl_ops_begin(struct net_device *dev); void ethnl_ops_complete(struct net_device *dev); +enum ethnl_sock_type { + ETHTOOL_SOCK_TYPE_MODULE_FW_FLASH, +}; + +struct ethnl_sock_priv { + struct net_device *dev; + u32 portid; + enum ethnl_sock_type type; +}; + +int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, u32 portid, + enum ethnl_sock_type type); + /** * struct ethnl_request_ops - unified handling of GET and SET requests * @request_cmd: command id for request (GET) @@ -442,6 +455,7 @@ extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX + 1] extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER + 1]; extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1]; extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1]; +extern const struct nla_policy ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); @@ -449,6 +463,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info); int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info); int ethnl_tunnel_info_start(struct netlink_callback *cb); int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info); extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN]; extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];